| 1 |
/******/ (function() { // webpackBootstrap |
| 2 |
/******/ "use strict"; |
| 3 |
/******/ var __webpack_modules__ = ({ |
| 4 |
|
| 5 |
/***/ "react": |
| 6 |
/*!**************************!*\ |
| 7 |
!*** external ["React"] ***! |
| 8 |
\**************************/ |
| 9 |
/***/ (function(module) { |
| 10 |
|
| 11 |
module.exports = window["React"]; |
| 12 |
|
| 13 |
/***/ }), |
| 14 |
|
| 15 |
/***/ "@elementor/editor-v1-adapters": |
| 16 |
/*!***************************************************!*\ |
| 17 |
!*** external ["elementorV2","editorV1Adapters"] ***! |
| 18 |
\***************************************************/ |
| 19 |
/***/ (function(module) { |
| 20 |
|
| 21 |
module.exports = window["elementorV2"]["editorV1Adapters"]; |
| 22 |
|
| 23 |
/***/ }), |
| 24 |
|
| 25 |
/***/ "@elementor/store": |
| 26 |
/*!****************************************!*\ |
| 27 |
!*** external ["elementorV2","store"] ***! |
| 28 |
\****************************************/ |
| 29 |
/***/ (function(module) { |
| 30 |
|
| 31 |
module.exports = window["elementorV2"]["store"]; |
| 32 |
|
| 33 |
/***/ }) |
| 34 |
|
| 35 |
/******/ }); |
| 36 |
/************************************************************************/ |
| 37 |
/******/ // The module cache |
| 38 |
/******/ var __webpack_module_cache__ = {}; |
| 39 |
/******/ |
| 40 |
/******/ // The require function |
| 41 |
/******/ function __webpack_require__(moduleId) { |
| 42 |
/******/ // Check if module is in cache |
| 43 |
/******/ var cachedModule = __webpack_module_cache__[moduleId]; |
| 44 |
/******/ if (cachedModule !== undefined) { |
| 45 |
/******/ return cachedModule.exports; |
| 46 |
/******/ } |
| 47 |
/******/ // Create a new module (and put it into the cache) |
| 48 |
/******/ var module = __webpack_module_cache__[moduleId] = { |
| 49 |
/******/ // no module.id needed |
| 50 |
/******/ // no module.loaded needed |
| 51 |
/******/ exports: {} |
| 52 |
/******/ }; |
| 53 |
/******/ |
| 54 |
/******/ // Execute the module function |
| 55 |
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__); |
| 56 |
/******/ |
| 57 |
/******/ // Return the exports of the module |
| 58 |
/******/ return module.exports; |
| 59 |
/******/ } |
| 60 |
/******/ |
| 61 |
/************************************************************************/ |
| 62 |
/******/ /* webpack/runtime/define property getters */ |
| 63 |
/******/ !function() { |
| 64 |
/******/ // define getter functions for harmony exports |
| 65 |
/******/ __webpack_require__.d = function(exports, definition) { |
| 66 |
/******/ for(var key in definition) { |
| 67 |
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { |
| 68 |
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); |
| 69 |
/******/ } |
| 70 |
/******/ } |
| 71 |
/******/ }; |
| 72 |
/******/ }(); |
| 73 |
/******/ |
| 74 |
/******/ /* webpack/runtime/hasOwnProperty shorthand */ |
| 75 |
/******/ !function() { |
| 76 |
/******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); } |
| 77 |
/******/ }(); |
| 78 |
/******/ |
| 79 |
/******/ /* webpack/runtime/make namespace object */ |
| 80 |
/******/ !function() { |
| 81 |
/******/ // define __esModule on exports |
| 82 |
/******/ __webpack_require__.r = function(exports) { |
| 83 |
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { |
| 84 |
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); |
| 85 |
/******/ } |
| 86 |
/******/ Object.defineProperty(exports, '__esModule', { value: true }); |
| 87 |
/******/ }; |
| 88 |
/******/ }(); |
| 89 |
/******/ |
| 90 |
/************************************************************************/ |
| 91 |
var __webpack_exports__ = {}; |
| 92 |
// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk. |
| 93 |
!function() { |
| 94 |
/*!*****************************************************************!*\ |
| 95 |
!*** ./node_modules/@elementor/editor-documents/dist/index.mjs ***! |
| 96 |
\*****************************************************************/ |
| 97 |
__webpack_require__.r(__webpack_exports__); |
| 98 |
/* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 99 |
/* harmony export */ useActiveDocument: function() { return /* binding */ useActiveDocument; }, |
| 100 |
/* harmony export */ useActiveDocumentActions: function() { return /* binding */ useActiveDocumentActions; }, |
| 101 |
/* harmony export */ useHostDocument: function() { return /* binding */ useHostDocument; }, |
| 102 |
/* harmony export */ useNavigateToDocument: function() { return /* binding */ useNavigateToDocument; } |
| 103 |
/* harmony export */ }); |
| 104 |
/* harmony import */ var _elementor_store__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @elementor/store */ "@elementor/store"); |
| 105 |
/* harmony import */ var _elementor_editor_v1_adapters__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @elementor/editor-v1-adapters */ "@elementor/editor-v1-adapters"); |
| 106 |
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! react */ "react"); |
| 107 |
// src/store/index.ts |
| 108 |
|
| 109 |
var initialState = { |
| 110 |
entities: {}, |
| 111 |
activeId: null, |
| 112 |
hostId: null |
| 113 |
}; |
| 114 |
function hasActiveEntity(state) { |
| 115 |
return !!(state.activeId && state.entities[state.activeId]); |
| 116 |
} |
| 117 |
var slice = (0,_elementor_store__WEBPACK_IMPORTED_MODULE_0__.createSlice)({ |
| 118 |
name: "documents", |
| 119 |
initialState, |
| 120 |
reducers: { |
| 121 |
init(state, { payload }) { |
| 122 |
state.entities = payload.entities; |
| 123 |
state.hostId = payload.hostId; |
| 124 |
state.activeId = payload.activeId; |
| 125 |
}, |
| 126 |
activateDocument(state, action) { |
| 127 |
state.entities[action.payload.id] = action.payload; |
| 128 |
state.activeId = action.payload.id; |
| 129 |
}, |
| 130 |
setAsHost(state, action) { |
| 131 |
state.hostId = action.payload; |
| 132 |
}, |
| 133 |
updateActiveDocument(state, action) { |
| 134 |
if (hasActiveEntity(state)) { |
| 135 |
state.entities[state.activeId] = { |
| 136 |
...state.entities[state.activeId], |
| 137 |
...action.payload |
| 138 |
}; |
| 139 |
} |
| 140 |
}, |
| 141 |
startSaving(state) { |
| 142 |
if (hasActiveEntity(state)) { |
| 143 |
state.entities[state.activeId].isSaving = true; |
| 144 |
} |
| 145 |
}, |
| 146 |
endSaving(state, action) { |
| 147 |
if (hasActiveEntity(state)) { |
| 148 |
state.entities[state.activeId] = { |
| 149 |
...action.payload, |
| 150 |
isSaving: false |
| 151 |
}; |
| 152 |
} |
| 153 |
}, |
| 154 |
startSavingDraft: (state) => { |
| 155 |
if (hasActiveEntity(state)) { |
| 156 |
state.entities[state.activeId].isSavingDraft = true; |
| 157 |
} |
| 158 |
}, |
| 159 |
endSavingDraft(state, action) { |
| 160 |
if (hasActiveEntity(state)) { |
| 161 |
state.entities[state.activeId] = { |
| 162 |
...action.payload, |
| 163 |
isSavingDraft: false |
| 164 |
}; |
| 165 |
} |
| 166 |
}, |
| 167 |
markAsDirty(state) { |
| 168 |
if (hasActiveEntity(state)) { |
| 169 |
state.entities[state.activeId].isDirty = true; |
| 170 |
} |
| 171 |
}, |
| 172 |
markAsPristine(state) { |
| 173 |
if (hasActiveEntity(state)) { |
| 174 |
state.entities[state.activeId].isDirty = false; |
| 175 |
} |
| 176 |
} |
| 177 |
} |
| 178 |
}); |
| 179 |
|
| 180 |
// src/sync/sync-store.ts |
| 181 |
|
| 182 |
|
| 183 |
// src/sync/utils.ts |
| 184 |
function getV1DocumentsManager() { |
| 185 |
const documentsManager = window.elementor?.documents; |
| 186 |
if (!documentsManager) { |
| 187 |
throw new Error("Elementor Editor V1 documents manager not found"); |
| 188 |
} |
| 189 |
return documentsManager; |
| 190 |
} |
| 191 |
function normalizeV1Document(documentData) { |
| 192 |
const isUnpublishedRevision = documentData.config.revisions.current_id !== documentData.id; |
| 193 |
return { |
| 194 |
id: documentData.id, |
| 195 |
title: documentData.container.settings.get("post_title"), |
| 196 |
type: { |
| 197 |
value: documentData.config.type, |
| 198 |
label: documentData.config.panel.title |
| 199 |
}, |
| 200 |
status: { |
| 201 |
value: documentData.config.status.value, |
| 202 |
label: documentData.config.status.label |
| 203 |
}, |
| 204 |
links: { |
| 205 |
platformEdit: documentData.config.urls.exit_to_dashboard |
| 206 |
}, |
| 207 |
isDirty: documentData.editor.isChanged || isUnpublishedRevision, |
| 208 |
isSaving: documentData.editor.isSaving, |
| 209 |
isSavingDraft: false, |
| 210 |
userCan: { |
| 211 |
publish: documentData.config.user.can_publish |
| 212 |
} |
| 213 |
}; |
| 214 |
} |
| 215 |
|
| 216 |
// src/sync/sync-store.ts |
| 217 |
|
| 218 |
function syncStore() { |
| 219 |
syncInitialization(); |
| 220 |
syncActiveDocument(); |
| 221 |
syncOnDocumentSave(); |
| 222 |
syncOnTitleChange(); |
| 223 |
syncOnDocumentChange(); |
| 224 |
} |
| 225 |
function syncInitialization() { |
| 226 |
const { init: init2 } = slice.actions; |
| 227 |
(0,_elementor_editor_v1_adapters__WEBPACK_IMPORTED_MODULE_1__.listenTo)( |
| 228 |
(0,_elementor_editor_v1_adapters__WEBPACK_IMPORTED_MODULE_1__.v1ReadyEvent)(), |
| 229 |
() => { |
| 230 |
const documentsManager = getV1DocumentsManager(); |
| 231 |
const entities = Object.entries(documentsManager.documents).reduce((acc, [id, document]) => { |
| 232 |
acc[id] = normalizeV1Document(document); |
| 233 |
return acc; |
| 234 |
}, {}); |
| 235 |
(0,_elementor_store__WEBPACK_IMPORTED_MODULE_0__.dispatch)(init2({ |
| 236 |
entities, |
| 237 |
hostId: documentsManager.getInitialId(), |
| 238 |
activeId: documentsManager.getCurrentId() |
| 239 |
})); |
| 240 |
} |
| 241 |
); |
| 242 |
} |
| 243 |
function syncActiveDocument() { |
| 244 |
const { activateDocument, setAsHost } = slice.actions; |
| 245 |
(0,_elementor_editor_v1_adapters__WEBPACK_IMPORTED_MODULE_1__.listenTo)( |
| 246 |
(0,_elementor_editor_v1_adapters__WEBPACK_IMPORTED_MODULE_1__.commandEndEvent)("editor/documents/open"), |
| 247 |
() => { |
| 248 |
const documentsManager = getV1DocumentsManager(); |
| 249 |
const currentDocument = normalizeV1Document(documentsManager.getCurrent()); |
| 250 |
(0,_elementor_store__WEBPACK_IMPORTED_MODULE_0__.dispatch)(activateDocument(currentDocument)); |
| 251 |
if (documentsManager.getInitialId() === currentDocument.id) { |
| 252 |
(0,_elementor_store__WEBPACK_IMPORTED_MODULE_0__.dispatch)(setAsHost(currentDocument.id)); |
| 253 |
} |
| 254 |
} |
| 255 |
); |
| 256 |
} |
| 257 |
function syncOnDocumentSave() { |
| 258 |
const { startSaving, endSaving, startSavingDraft, endSavingDraft } = slice.actions; |
| 259 |
const isDraft = (e) => { |
| 260 |
const event = e; |
| 261 |
return event.args?.status === "autosave"; |
| 262 |
}; |
| 263 |
(0,_elementor_editor_v1_adapters__WEBPACK_IMPORTED_MODULE_1__.listenTo)( |
| 264 |
(0,_elementor_editor_v1_adapters__WEBPACK_IMPORTED_MODULE_1__.commandStartEvent)("document/save/save"), |
| 265 |
(e) => { |
| 266 |
if (isDraft(e)) { |
| 267 |
(0,_elementor_store__WEBPACK_IMPORTED_MODULE_0__.dispatch)(startSavingDraft()); |
| 268 |
return; |
| 269 |
} |
| 270 |
(0,_elementor_store__WEBPACK_IMPORTED_MODULE_0__.dispatch)(startSaving()); |
| 271 |
} |
| 272 |
); |
| 273 |
(0,_elementor_editor_v1_adapters__WEBPACK_IMPORTED_MODULE_1__.listenTo)( |
| 274 |
(0,_elementor_editor_v1_adapters__WEBPACK_IMPORTED_MODULE_1__.commandEndEvent)("document/save/save"), |
| 275 |
(e) => { |
| 276 |
const activeDocument = normalizeV1Document( |
| 277 |
getV1DocumentsManager().getCurrent() |
| 278 |
); |
| 279 |
if (isDraft(e)) { |
| 280 |
(0,_elementor_store__WEBPACK_IMPORTED_MODULE_0__.dispatch)(endSavingDraft(activeDocument)); |
| 281 |
} else { |
| 282 |
(0,_elementor_store__WEBPACK_IMPORTED_MODULE_0__.dispatch)(endSaving(activeDocument)); |
| 283 |
} |
| 284 |
} |
| 285 |
); |
| 286 |
} |
| 287 |
function syncOnTitleChange() { |
| 288 |
const { updateActiveDocument } = slice.actions; |
| 289 |
const updateTitle = debounce((e) => { |
| 290 |
const event = e; |
| 291 |
if (!("post_title" in event.args?.settings)) { |
| 292 |
return; |
| 293 |
} |
| 294 |
const currentDocument = getV1DocumentsManager().getCurrent(); |
| 295 |
const newTitle = currentDocument.container.settings.get("post_title"); |
| 296 |
(0,_elementor_store__WEBPACK_IMPORTED_MODULE_0__.dispatch)(updateActiveDocument({ title: newTitle })); |
| 297 |
}, 400); |
| 298 |
(0,_elementor_editor_v1_adapters__WEBPACK_IMPORTED_MODULE_1__.listenTo)( |
| 299 |
(0,_elementor_editor_v1_adapters__WEBPACK_IMPORTED_MODULE_1__.commandEndEvent)("document/elements/settings"), |
| 300 |
updateTitle |
| 301 |
); |
| 302 |
} |
| 303 |
function syncOnDocumentChange() { |
| 304 |
const { markAsDirty, markAsPristine } = slice.actions; |
| 305 |
(0,_elementor_editor_v1_adapters__WEBPACK_IMPORTED_MODULE_1__.listenTo)( |
| 306 |
(0,_elementor_editor_v1_adapters__WEBPACK_IMPORTED_MODULE_1__.commandEndEvent)("document/save/set-is-modified"), |
| 307 |
() => { |
| 308 |
const currentDocument = getV1DocumentsManager().getCurrent(); |
| 309 |
if (currentDocument.editor.isChanged) { |
| 310 |
(0,_elementor_store__WEBPACK_IMPORTED_MODULE_0__.dispatch)(markAsDirty()); |
| 311 |
return; |
| 312 |
} |
| 313 |
(0,_elementor_store__WEBPACK_IMPORTED_MODULE_0__.dispatch)(markAsPristine()); |
| 314 |
} |
| 315 |
); |
| 316 |
} |
| 317 |
function debounce(fn, timeout) { |
| 318 |
let timer; |
| 319 |
return (...args) => { |
| 320 |
clearTimeout(timer); |
| 321 |
timer = setTimeout(() => { |
| 322 |
fn(...args); |
| 323 |
}, timeout); |
| 324 |
}; |
| 325 |
} |
| 326 |
|
| 327 |
// src/init.ts |
| 328 |
|
| 329 |
function init() { |
| 330 |
initStore(); |
| 331 |
} |
| 332 |
function initStore() { |
| 333 |
(0,_elementor_store__WEBPACK_IMPORTED_MODULE_0__.registerSlice)(slice); |
| 334 |
syncStore(); |
| 335 |
} |
| 336 |
|
| 337 |
// src/hooks/use-active-document.ts |
| 338 |
|
| 339 |
|
| 340 |
// src/store/selectors.ts |
| 341 |
|
| 342 |
var selectEntities = (state) => state.documents.entities; |
| 343 |
var selectActiveId = (state) => state.documents.activeId; |
| 344 |
var selectHostId = (state) => state.documents.hostId; |
| 345 |
var selectActiveDocument = (0,_elementor_store__WEBPACK_IMPORTED_MODULE_0__.createSelector)( |
| 346 |
selectEntities, |
| 347 |
selectActiveId, |
| 348 |
(entities, activeId) => activeId && entities[activeId] ? entities[activeId] : null |
| 349 |
); |
| 350 |
var selectHostDocument = (0,_elementor_store__WEBPACK_IMPORTED_MODULE_0__.createSelector)( |
| 351 |
selectEntities, |
| 352 |
selectHostId, |
| 353 |
(entities, hostId) => hostId && entities[hostId] ? entities[hostId] : null |
| 354 |
); |
| 355 |
|
| 356 |
// src/hooks/use-active-document.ts |
| 357 |
function useActiveDocument() { |
| 358 |
return (0,_elementor_store__WEBPACK_IMPORTED_MODULE_0__.useSelector)(selectActiveDocument); |
| 359 |
} |
| 360 |
|
| 361 |
// src/hooks/use-active-document-actions.ts |
| 362 |
|
| 363 |
|
| 364 |
function useActiveDocumentActions() { |
| 365 |
const save = (0,react__WEBPACK_IMPORTED_MODULE_2__.useCallback)(() => (0,_elementor_editor_v1_adapters__WEBPACK_IMPORTED_MODULE_1__.runCommand)("document/save/default"), []); |
| 366 |
const saveDraft = (0,react__WEBPACK_IMPORTED_MODULE_2__.useCallback)(() => (0,_elementor_editor_v1_adapters__WEBPACK_IMPORTED_MODULE_1__.runCommand)("document/save/draft"), []); |
| 367 |
const saveTemplate = (0,react__WEBPACK_IMPORTED_MODULE_2__.useCallback)(() => (0,_elementor_editor_v1_adapters__WEBPACK_IMPORTED_MODULE_1__.openRoute)("library/save-template"), []); |
| 368 |
return { |
| 369 |
save, |
| 370 |
saveDraft, |
| 371 |
saveTemplate |
| 372 |
}; |
| 373 |
} |
| 374 |
|
| 375 |
// src/hooks/use-host-document.ts |
| 376 |
|
| 377 |
function useHostDocument() { |
| 378 |
return (0,_elementor_store__WEBPACK_IMPORTED_MODULE_0__.useSelector)(selectHostDocument); |
| 379 |
} |
| 380 |
|
| 381 |
// src/hooks/use-navigate-to-document.ts |
| 382 |
|
| 383 |
|
| 384 |
function useNavigateToDocument() { |
| 385 |
return (0,react__WEBPACK_IMPORTED_MODULE_2__.useCallback)(async (id) => { |
| 386 |
await (0,_elementor_editor_v1_adapters__WEBPACK_IMPORTED_MODULE_1__.runCommand)("editor/documents/switch", { |
| 387 |
id, |
| 388 |
setAsInitial: true |
| 389 |
}); |
| 390 |
const url = new URL(window.location.href); |
| 391 |
url.searchParams.set("post", id.toString()); |
| 392 |
url.searchParams.delete("active-document"); |
| 393 |
history.replaceState({}, "", url); |
| 394 |
}, []); |
| 395 |
} |
| 396 |
|
| 397 |
// src/index.ts |
| 398 |
init(); |
| 399 |
|
| 400 |
//# sourceMappingURL=index.mjs.map |
| 401 |
}(); |
| 402 |
(window.elementorV2 = window.elementorV2 || {}).editorDocuments = __webpack_exports__; |
| 403 |
/******/ })() |
| 404 |
; |