← All changes
|
assets/js/packages/editor-documents/editor-documents.js
+884
-367
4.3.0
→
4.2.1
View file →
| @@ -1,389 +1,906 @@ | ||
| 1 | -(function(_elementor_editor, _elementor_store, react, _wordpress_i18n, _elementor_editor_v1_adapters, _elementor_utils) { | |
| 1 | +/******/ (function() { // webpackBootstrap | |
| 2 | +/******/ "use strict"; | |
| 3 | +/******/ var __webpack_modules__ = ({ | |
| 2 | 4 | |
| 3 | -//#region \0rolldown/runtime.js | |
| 4 | - var __defProp = Object.defineProperty; | |
| 5 | - var __name = (target, value) => __defProp(target, "name", { | |
| 6 | - value, | |
| 7 | - configurable: true | |
| 8 | - }); | |
| 9 | - var __exportAll = (all, no_symbols) => { | |
| 10 | - let target = {}; | |
| 11 | - for (var name in all) { | |
| 12 | - __defProp(target, name, { | |
| 13 | - get: all[name], | |
| 14 | - enumerable: true | |
| 15 | - }); | |
| 16 | - } | |
| 17 | - if (!no_symbols) { | |
| 18 | - __defProp(target, Symbol.toStringTag, { value: "Module" }); | |
| 19 | - } | |
| 20 | - return target; | |
| 21 | - }; | |
| 5 | +/***/ "./packages/packages/core/editor-documents/src/components/logic-hooks.tsx": | |
| 6 | +/*!********************************************************************************!*\ | |
| 7 | + !*** ./packages/packages/core/editor-documents/src/components/logic-hooks.tsx ***! | |
| 8 | + \********************************************************************************/ | |
| 9 | +/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) { | |
| 22 | 10 | |
| 23 | -//#endregion | |
| 11 | +__webpack_require__.r(__webpack_exports__); | |
| 12 | +/* harmony export */ __webpack_require__.d(__webpack_exports__, { | |
| 13 | +/* harmony export */ LogicHooks: function() { return /* binding */ LogicHooks; } | |
| 14 | +/* harmony export */ }); | |
| 15 | +/* harmony import */ var _hooks_use_sync_document_title__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../hooks/use-sync-document-title */ "./packages/packages/core/editor-documents/src/hooks/use-sync-document-title.ts"); | |
| 24 | 16 | |
| 25 | -//#region packages/packages/core/editor-documents/src/store/selectors.ts | |
| 26 | - var selectEntities = (state) => state.documents.entities; | |
| 27 | - var selectActiveId = (state) => state.documents.activeId; | |
| 28 | - var selectHostId = (state) => state.documents.hostId; | |
| 29 | - var selectActiveDocument = (0, _elementor_store.__createSelector)(selectEntities, selectActiveId, (entities, activeId) => activeId && entities[activeId] ? entities[activeId] : null); | |
| 30 | - var selectHostDocument = (0, _elementor_store.__createSelector)(selectEntities, selectHostId, (entities, hostId) => hostId && entities[hostId] ? entities[hostId] : null); | |
| 17 | +function LogicHooks() { | |
| 18 | + (0,_hooks_use_sync_document_title__WEBPACK_IMPORTED_MODULE_0__["default"])(); | |
| 19 | + return null; | |
| 20 | +} | |
| 31 | 21 | |
| 32 | -//#endregion | |
| 33 | -//#region packages/packages/core/editor-documents/src/hooks/use-active-document.ts | |
| 34 | - function useActiveDocument() { | |
| 35 | - return (0, _elementor_store.__useSelector)(selectActiveDocument); | |
| 36 | - } | |
| 22 | +/***/ }), | |
| 37 | 23 | |
| 38 | -//#endregion | |
| 39 | -//#region packages/packages/core/editor-documents/src/hooks/use-host-document.ts | |
| 40 | - function useHostDocument() { | |
| 41 | - return (0, _elementor_store.__useSelector)(selectHostDocument); | |
| 42 | - } | |
| 24 | +/***/ "./packages/packages/core/editor-documents/src/consts.ts": | |
| 25 | +/*!***************************************************************!*\ | |
| 26 | + !*** ./packages/packages/core/editor-documents/src/consts.ts ***! | |
| 27 | + \***************************************************************/ | |
| 28 | +/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) { | |
| 43 | 29 | |
| 44 | -//#endregion | |
| 45 | -//#region packages/packages/core/editor-documents/src/hooks/use-sync-document-title.ts | |
| 46 | - function useSyncDocumentTitle() { | |
| 47 | - const activeDocument = useActiveDocument(); | |
| 48 | - const hostDocument = useHostDocument(); | |
| 49 | - const document = activeDocument && activeDocument.type.value !== "kit" ? activeDocument : hostDocument; | |
| 50 | - (0, react.useEffect)(() => { | |
| 51 | - if (document?.title === void 0) return; | |
| 52 | - const title = (0, _wordpress_i18n.__)("Edit \"%s\" with Elementor", "elementor").replace("%s", document.title); | |
| 53 | - window.document.title = title; | |
| 54 | - }, [document?.title]); | |
| 55 | - } | |
| 30 | +__webpack_require__.r(__webpack_exports__); | |
| 31 | +/* harmony export */ __webpack_require__.d(__webpack_exports__, { | |
| 32 | +/* harmony export */ COMPONENT_DOCUMENT_TYPE: function() { return /* binding */ COMPONENT_DOCUMENT_TYPE; } | |
| 33 | +/* harmony export */ }); | |
| 34 | +const COMPONENT_DOCUMENT_TYPE = 'elementor_component'; | |
| 56 | 35 | |
| 57 | -//#endregion | |
| 58 | -//#region packages/packages/core/editor-documents/src/components/logic-hooks.tsx | |
| 59 | - function LogicHooks() { | |
| 60 | - useSyncDocumentTitle(); | |
| 61 | - return null; | |
| 62 | - } | |
| 36 | +/***/ }), | |
| 63 | 37 | |
| 64 | -//#endregion | |
| 65 | -//#region packages/packages/core/editor-documents/src/store/index.ts | |
| 66 | - var initialState = { | |
| 67 | - entities: {}, | |
| 68 | - activeId: null, | |
| 69 | - hostId: null | |
| 70 | - }; | |
| 71 | - function hasActiveEntity(state) { | |
| 72 | - return !!(state.activeId && state.entities[state.activeId]); | |
| 73 | - } | |
| 74 | - var slice = (0, _elementor_store.__createSlice)({ | |
| 75 | - name: "documents", | |
| 76 | - initialState, | |
| 77 | - reducers: { | |
| 78 | - init(state, { payload }) { | |
| 79 | - state.entities = payload.entities; | |
| 80 | - state.hostId = payload.hostId; | |
| 81 | - state.activeId = payload.activeId; | |
| 82 | - }, | |
| 83 | - activateDocument(state, action) { | |
| 84 | - state.entities[action.payload.id] = action.payload; | |
| 85 | - state.activeId = action.payload.id; | |
| 86 | - }, | |
| 87 | - setAsHost(state, action) { | |
| 88 | - state.hostId = action.payload; | |
| 89 | - }, | |
| 90 | - updateActiveDocument(state, action) { | |
| 91 | - if (hasActiveEntity(state)) state.entities[state.activeId] = { | |
| 92 | - ...state.entities[state.activeId], | |
| 93 | - ...action.payload | |
| 94 | - }; | |
| 95 | - }, | |
| 96 | - startSaving(state) { | |
| 97 | - if (hasActiveEntity(state)) state.entities[state.activeId].isSaving = true; | |
| 98 | - }, | |
| 99 | - endSaving(state, action) { | |
| 100 | - if (hasActiveEntity(state)) state.entities[state.activeId] = { | |
| 101 | - ...action.payload, | |
| 102 | - isSaving: false | |
| 103 | - }; | |
| 104 | - }, | |
| 105 | - startSavingDraft: (state) => { | |
| 106 | - if (hasActiveEntity(state)) state.entities[state.activeId].isSavingDraft = true; | |
| 107 | - }, | |
| 108 | - endSavingDraft(state, action) { | |
| 109 | - if (hasActiveEntity(state)) state.entities[state.activeId] = { | |
| 110 | - ...action.payload, | |
| 111 | - isSavingDraft: false | |
| 112 | - }; | |
| 113 | - }, | |
| 114 | - markAsDirty(state) { | |
| 115 | - if (hasActiveEntity(state)) state.entities[state.activeId].isDirty = true; | |
| 116 | - }, | |
| 117 | - markAsPristine(state) { | |
| 118 | - if (hasActiveEntity(state)) state.entities[state.activeId].isDirty = false; | |
| 119 | - } | |
| 120 | - } | |
| 121 | - }); | |
| 38 | +/***/ "./packages/packages/core/editor-documents/src/hooks/index.ts": | |
| 39 | +/*!********************************************************************!*\ | |
| 40 | + !*** ./packages/packages/core/editor-documents/src/hooks/index.ts ***! | |
| 41 | + \********************************************************************/ | |
| 42 | +/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) { | |
| 122 | 43 | |
| 123 | -//#endregion | |
| 124 | -//#region packages/packages/core/editor-documents/src/store/get-current-document.ts | |
| 125 | - function getCurrentDocument() { | |
| 126 | - return selectActiveDocument((0, _elementor_store.__getState)()); | |
| 127 | - } | |
| 44 | +__webpack_require__.r(__webpack_exports__); | |
| 45 | +/* harmony export */ __webpack_require__.d(__webpack_exports__, { | |
| 46 | +/* harmony export */ useActiveDocument: function() { return /* reexport safe */ _use_active_document__WEBPACK_IMPORTED_MODULE_0__["default"]; }, | |
| 47 | +/* harmony export */ useActiveDocumentActions: function() { return /* reexport safe */ _use_active_document_actions__WEBPACK_IMPORTED_MODULE_1__["default"]; }, | |
| 48 | +/* harmony export */ useHostDocument: function() { return /* reexport safe */ _use_host_document__WEBPACK_IMPORTED_MODULE_2__["default"]; }, | |
| 49 | +/* harmony export */ useNavigateToDocument: function() { return /* reexport safe */ _use_navigate_to_document__WEBPACK_IMPORTED_MODULE_3__["default"]; }, | |
| 50 | +/* harmony export */ useOpenDocumentInNewTab: function() { return /* reexport safe */ _use_open_document_in_new_tab__WEBPACK_IMPORTED_MODULE_4__["default"]; } | |
| 51 | +/* harmony export */ }); | |
| 52 | +/* harmony import */ var _use_active_document__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./use-active-document */ "./packages/packages/core/editor-documents/src/hooks/use-active-document.ts"); | |
| 53 | +/* harmony import */ var _use_active_document_actions__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./use-active-document-actions */ "./packages/packages/core/editor-documents/src/hooks/use-active-document-actions.ts"); | |
| 54 | +/* harmony import */ var _use_host_document__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./use-host-document */ "./packages/packages/core/editor-documents/src/hooks/use-host-document.ts"); | |
| 55 | +/* harmony import */ var _use_navigate_to_document__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./use-navigate-to-document */ "./packages/packages/core/editor-documents/src/hooks/use-navigate-to-document.ts"); | |
| 56 | +/* harmony import */ var _use_open_document_in_new_tab__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./use-open-document-in-new-tab */ "./packages/packages/core/editor-documents/src/hooks/use-open-document-in-new-tab.ts"); | |
| 128 | 57 | |
| 129 | -//#endregion | |
| 130 | -//#region packages/packages/core/editor-documents/src/sync/utils.ts | |
| 131 | - function getV1DocumentsManager() { | |
| 132 | - const documentsManager = window.elementor?.documents; | |
| 133 | - if (!documentsManager) throw new Error("Elementor Editor V1 documents manager not found"); | |
| 134 | - return documentsManager; | |
| 135 | - } | |
| 136 | - function getV1DocumentsExitTo(documentData) { | |
| 137 | - switch (window.elementor?.getPreferences?.("exit_to") || "this_post") { | |
| 138 | - case "dashboard": return documentData.config.urls.main_dashboard; | |
| 139 | - case "all_posts": return documentData.config.urls.all_post_type; | |
| 140 | - default: return documentData.config.urls.exit_to_dashboard; | |
| 141 | - } | |
| 142 | - } | |
| 143 | - function getV1DocumentShowCopyAndShare(documentData) { | |
| 144 | - return documentData?.config?.panel?.show_copy_and_share ?? false; | |
| 145 | - } | |
| 146 | - function getV1DocumentPermalink(documentData) { | |
| 147 | - return documentData.config.urls.permalink ?? ""; | |
| 148 | - } | |
| 149 | - function getV1DocumentWpPreview(documentData) { | |
| 150 | - return documentData.config.urls.wp_preview ?? ""; | |
| 151 | - } | |
| 152 | - function normalizeV1Document(documentData) { | |
| 153 | - const isUnpublishedRevision = documentData.config.revisions.current_id !== documentData.id; | |
| 154 | - const exitToUrl = getV1DocumentsExitTo(documentData); | |
| 155 | - return { | |
| 156 | - id: documentData.id, | |
| 157 | - title: documentData.container.settings.get("post_title"), | |
| 158 | - type: { | |
| 159 | - value: documentData.config.type, | |
| 160 | - label: documentData.config.panel.title | |
| 161 | - }, | |
| 162 | - status: { | |
| 163 | - value: documentData.config.status.value, | |
| 164 | - label: documentData.config.status.label | |
| 165 | - }, | |
| 166 | - links: { | |
| 167 | - permalink: getV1DocumentPermalink(documentData), | |
| 168 | - wpPreview: getV1DocumentWpPreview(documentData), | |
| 169 | - platformEdit: exitToUrl | |
| 170 | - }, | |
| 171 | - isDirty: documentData.editor.isChanged || isUnpublishedRevision, | |
| 172 | - isSaving: documentData.editor.isSaving, | |
| 173 | - isSavingDraft: false, | |
| 174 | - permissions: { | |
| 175 | - allowAddingWidgets: documentData.config.panel?.allow_adding_widgets ?? true, | |
| 176 | - showCopyAndShare: getV1DocumentShowCopyAndShare(documentData) | |
| 177 | - }, | |
| 178 | - userCan: { publish: documentData.config.user.can_publish } | |
| 179 | - }; | |
| 180 | - } | |
| 181 | - function setDocumentModifiedStatus(status) { | |
| 182 | - (0, _elementor_editor_v1_adapters.__privateRunCommandSync)("document/save/set-is-modified", { status }, { internal: true }); | |
| 183 | - } | |
| 184 | - function getV1CurrentDocument() { | |
| 185 | - return window.elementor?.documents?.getCurrent(); | |
| 186 | - } | |
| 187 | - function isDocumentDirty(document) { | |
| 188 | - const isDraft = document.status.value === "draft"; | |
| 189 | - const hasAutosave = document.revisions?.current_id !== document.id; | |
| 190 | - return isDraft || hasAutosave; | |
| 191 | - } | |
| 192 | - function invalidateDocumentData(documentId) { | |
| 193 | - getV1DocumentsManager().invalidateCache(documentId); | |
| 194 | - } | |
| 195 | - function reloadCurrentDocument() { | |
| 196 | - const currentDocument = getCurrentDocument(); | |
| 197 | - if (!currentDocument?.id) return Promise.resolve(); | |
| 198 | - getV1DocumentsManager().invalidateCache(); | |
| 199 | - return (0, _elementor_editor_v1_adapters.__privateRunCommand)("editor/documents/switch", { | |
| 200 | - id: currentDocument.id, | |
| 201 | - shouldScroll: false, | |
| 202 | - shouldNavigateToDefaultRoute: false | |
| 203 | - }); | |
| 204 | - } | |
| 205 | - function switchToDocument(documentId, options) { | |
| 206 | - return (0, _elementor_editor_v1_adapters.__privateRunCommand)("editor/documents/switch", { | |
| 207 | - id: documentId, | |
| 208 | - ...options | |
| 209 | - }); | |
| 210 | - } | |
| 211 | 58 | |
| 212 | -//#endregion | |
| 213 | -//#region packages/packages/core/editor-documents/src/sync/sync-store.ts | |
| 214 | - function syncStore() { | |
| 215 | - syncInitialization(); | |
| 216 | - syncActiveDocument(); | |
| 217 | - syncOnDocumentSave(); | |
| 218 | - syncOnTitleChange(); | |
| 219 | - syncOnDocumentChange(); | |
| 220 | - syncOnExitToChange(); | |
| 221 | - } | |
| 222 | - function syncInitialization() { | |
| 223 | - const { init } = slice.actions; | |
| 224 | - (0, _elementor_editor_v1_adapters.__privateListenTo)((0, _elementor_editor_v1_adapters.v1ReadyEvent)(), () => { | |
| 225 | - const documentsManager = getV1DocumentsManager(); | |
| 226 | - const entities = Object.entries(documentsManager.documents).reduce((acc, [id, document]) => { | |
| 227 | - acc[id] = normalizeV1Document(document); | |
| 228 | - return acc; | |
| 229 | - }, {}); | |
| 230 | - (0, _elementor_store.__dispatch)(init({ | |
| 231 | - entities, | |
| 232 | - hostId: documentsManager.getInitialId(), | |
| 233 | - activeId: documentsManager.getCurrentId() | |
| 234 | - })); | |
| 235 | - }); | |
| 236 | - } | |
| 237 | - function syncActiveDocument() { | |
| 238 | - const { activateDocument, setAsHost } = slice.actions; | |
| 239 | - (0, _elementor_editor_v1_adapters.__privateListenTo)((0, _elementor_editor_v1_adapters.commandEndEvent)("editor/documents/open"), () => { | |
| 240 | - const documentsManager = getV1DocumentsManager(); | |
| 241 | - const currentDocument = normalizeV1Document(documentsManager.getCurrent()); | |
| 242 | - (0, _elementor_store.__dispatch)(activateDocument(currentDocument)); | |
| 243 | - if (documentsManager.getInitialId() === currentDocument.id) (0, _elementor_store.__dispatch)(setAsHost(currentDocument.id)); | |
| 244 | - }); | |
| 245 | - } | |
| 246 | - function syncOnDocumentSave() { | |
| 247 | - const { startSaving, endSaving, startSavingDraft, endSavingDraft } = slice.actions; | |
| 248 | - const isDraft = (e) => { | |
| 249 | - return e.args?.status === "autosave"; | |
| 250 | - }; | |
| 251 | - (0, _elementor_editor_v1_adapters.__privateListenTo)((0, _elementor_editor_v1_adapters.commandStartEvent)("document/save/save"), (e) => { | |
| 252 | - if (isDraft(e)) { | |
| 253 | - (0, _elementor_store.__dispatch)(startSavingDraft()); | |
| 254 | - return; | |
| 255 | - } | |
| 256 | - (0, _elementor_store.__dispatch)(startSaving()); | |
| 257 | - }); | |
| 258 | - (0, _elementor_editor_v1_adapters.__privateListenTo)((0, _elementor_editor_v1_adapters.commandEndEvent)("document/save/save"), (e) => { | |
| 259 | - const activeDocument = normalizeV1Document(getV1DocumentsManager().getCurrent()); | |
| 260 | - if (isDraft(e)) (0, _elementor_store.__dispatch)(endSavingDraft(activeDocument)); | |
| 261 | - else (0, _elementor_store.__dispatch)(endSaving(activeDocument)); | |
| 262 | - }); | |
| 263 | - } | |
| 264 | - function syncOnTitleChange() { | |
| 265 | - const { updateActiveDocument } = slice.actions; | |
| 266 | - const updateTitle = (0, _elementor_utils.debounce)((e) => { | |
| 267 | - if (!("post_title" in e.args?.settings)) return; | |
| 268 | - const newTitle = getV1DocumentsManager().getCurrent().container.settings.get("post_title"); | |
| 269 | - (0, _elementor_store.__dispatch)(updateActiveDocument({ title: newTitle })); | |
| 270 | - }, 400); | |
| 271 | - (0, _elementor_editor_v1_adapters.__privateListenTo)((0, _elementor_editor_v1_adapters.commandEndEvent)("document/elements/settings"), updateTitle); | |
| 272 | - } | |
| 273 | - function syncOnExitToChange() { | |
| 274 | - const { updateActiveDocument } = slice.actions; | |
| 275 | - const updateExitTo = (0, _elementor_utils.debounce)((e) => { | |
| 276 | - if (!("exit_to" in e.args?.settings)) return; | |
| 277 | - const currentDocument = getV1DocumentsManager().getCurrent(); | |
| 278 | - const newExitTo = getV1DocumentsExitTo(currentDocument); | |
| 279 | - const permalink = getV1DocumentPermalink(currentDocument); | |
| 280 | - const wpPreview = getV1DocumentWpPreview(currentDocument); | |
| 281 | - (0, _elementor_store.__dispatch)(updateActiveDocument({ links: { | |
| 282 | - platformEdit: newExitTo, | |
| 283 | - permalink, | |
| 284 | - wpPreview | |
| 285 | - } })); | |
| 286 | - }, 400); | |
| 287 | - (0, _elementor_editor_v1_adapters.__privateListenTo)((0, _elementor_editor_v1_adapters.commandEndEvent)("document/elements/settings"), updateExitTo); | |
| 288 | - } | |
| 289 | - function syncOnDocumentChange() { | |
| 290 | - const { markAsDirty, markAsPristine } = slice.actions; | |
| 291 | - (0, _elementor_editor_v1_adapters.__privateListenTo)((0, _elementor_editor_v1_adapters.commandEndEvent)("document/save/set-is-modified"), () => { | |
| 292 | - if (selectActiveDocument((0, _elementor_store.__getState)())?.isSaving) return; | |
| 293 | - if (getV1DocumentsManager().getCurrent().editor.isChanged) { | |
| 294 | - (0, _elementor_store.__dispatch)(markAsDirty()); | |
| 295 | - return; | |
| 296 | - } | |
| 297 | - (0, _elementor_store.__dispatch)(markAsPristine()); | |
| 298 | - }); | |
| 299 | - } | |
| 300 | 59 | |
| 301 | -//#endregion | |
| 302 | -//#region packages/packages/core/editor-documents/src/init.ts | |
| 303 | - function init() { | |
| 304 | - initStore(); | |
| 305 | - (0, _elementor_editor.injectIntoLogic)({ | |
| 306 | - id: "documents-hooks", | |
| 307 | - component: LogicHooks | |
| 308 | - }); | |
| 309 | - } | |
| 310 | - function initStore() { | |
| 311 | - (0, _elementor_store.__registerSlice)(slice); | |
| 312 | - syncStore(); | |
| 313 | - } | |
| 314 | 60 | |
| 315 | -//#endregion | |
| 316 | -//#region packages/packages/core/editor-documents/src/hooks/use-active-document-actions.ts | |
| 317 | - function useActiveDocumentActions() { | |
| 318 | - const permalink = useActiveDocument()?.links?.permalink ?? ""; | |
| 319 | - return { | |
| 320 | - save: (0, react.useCallback)(() => (0, _elementor_editor_v1_adapters.__privateRunCommand)("document/save/default"), []), | |
| 321 | - saveDraft: (0, react.useCallback)(() => (0, _elementor_editor_v1_adapters.__privateRunCommand)("document/save/draft"), []), | |
| 322 | - saveTemplate: (0, react.useCallback)(() => (0, _elementor_editor_v1_adapters.__privateOpenRoute)("library/save-template"), []), | |
| 323 | - copyAndShare: (0, react.useCallback)(() => { | |
| 324 | - navigator.clipboard.writeText(permalink); | |
| 325 | - }, [permalink]) | |
| 326 | - }; | |
| 327 | - } | |
| 328 | 61 | |
| 329 | -//#endregion | |
| 330 | -//#region packages/packages/core/editor-documents/src/hooks/utils.ts | |
| 331 | - var getUpdateUrl = (id) => { | |
| 332 | - const url = new URL(window.location.href); | |
| 333 | - url.searchParams.set("post", id.toString()); | |
| 334 | - url.searchParams.delete("active-document"); | |
| 335 | - return url; | |
| 336 | - }; | |
| 337 | 62 | |
| 338 | -//#endregion | |
| 339 | -//#region packages/packages/core/editor-documents/src/hooks/use-navigate-to-document.ts | |
| 340 | - function useNavigateToDocument() { | |
| 341 | - return (0, react.useCallback)(async (id) => { | |
| 342 | - const url = getUpdateUrl(id); | |
| 343 | - await switchToDocument(id, { setAsInitial: true }); | |
| 344 | - history.replaceState({}, "", url); | |
| 345 | - }, []); | |
| 346 | - } | |
| 63 | +/***/ }), | |
| 347 | 64 | |
| 348 | -//#endregion | |
| 349 | -//#region packages/packages/core/editor-documents/src/hooks/use-open-document-in-new-tab.ts | |
| 350 | - function useOpenDocumentInNewTab() { | |
| 351 | - return (0, react.useCallback)((id) => { | |
| 352 | - const url = getUpdateUrl(id); | |
| 353 | - window.open(url.href); | |
| 354 | - }, []); | |
| 355 | - } | |
| 65 | +/***/ "./packages/packages/core/editor-documents/src/hooks/use-active-document-actions.ts": | |
| 66 | +/*!******************************************************************************************!*\ | |
| 67 | + !*** ./packages/packages/core/editor-documents/src/hooks/use-active-document-actions.ts ***! | |
| 68 | + \******************************************************************************************/ | |
| 69 | +/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) { | |
| 356 | 70 | |
| 357 | -//#endregion | |
| 358 | -//#region packages/packages/core/editor-documents/src/consts.ts | |
| 359 | - var COMPONENT_DOCUMENT_TYPE = "elementor_component"; | |
| 71 | +__webpack_require__.r(__webpack_exports__); | |
| 72 | +/* harmony export */ __webpack_require__.d(__webpack_exports__, { | |
| 73 | +/* harmony export */ "default": function() { return /* binding */ useActiveDocumentActions; } | |
| 74 | +/* harmony export */ }); | |
| 75 | +/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react"); | |
| 76 | +/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__); | |
| 77 | +/* harmony import */ var _elementor_editor_v1_adapters__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @elementor/editor-v1-adapters */ "@elementor/editor-v1-adapters"); | |
| 78 | +/* harmony import */ var _elementor_editor_v1_adapters__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_elementor_editor_v1_adapters__WEBPACK_IMPORTED_MODULE_1__); | |
| 79 | +/* harmony import */ var _use_active_document__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./use-active-document */ "./packages/packages/core/editor-documents/src/hooks/use-active-document.ts"); | |
| 360 | 80 | |
| 361 | -//#endregion | |
| 362 | -//#region packages/packages/core/editor-documents/src/index.ts | |
| 363 | - var src_exports = /* @__PURE__ */ __exportAll({ | |
| 364 | - COMPONENT_DOCUMENT_TYPE: () => COMPONENT_DOCUMENT_TYPE, | |
| 365 | - __useActiveDocument: () => useActiveDocument, | |
| 366 | - __useActiveDocumentActions: () => useActiveDocumentActions, | |
| 367 | - __useHostDocument: () => useHostDocument, | |
| 368 | - __useNavigateToDocument: () => useNavigateToDocument, | |
| 369 | - __useOpenDocumentInNewTab: () => useOpenDocumentInNewTab, | |
| 370 | - getCurrentDocument: () => getCurrentDocument, | |
| 371 | - getV1CurrentDocument: () => getV1CurrentDocument, | |
| 372 | - getV1DocumentsManager: () => getV1DocumentsManager, | |
| 373 | - init: () => init, | |
| 374 | - invalidateDocumentData: () => invalidateDocumentData, | |
| 375 | - isDocumentDirty: () => isDocumentDirty, | |
| 376 | - reloadCurrentDocument: () => reloadCurrentDocument, | |
| 377 | - setDocumentModifiedStatus: () => setDocumentModifiedStatus, | |
| 378 | - slice: () => slice, | |
| 379 | - switchToDocument: () => switchToDocument | |
| 380 | - }); | |
| 381 | 81 | |
| 382 | -//#endregion | |
| 383 | -//#region \0elementor-package-library-entry | |
| 384 | - (window.elementorV2 = window.elementorV2 || {}).editorDocuments = src_exports; | |
| 385 | 82 | |
| 386 | -//#endregion | |
| 387 | -})(elementorV2.editor, elementorV2.store, React, wp.i18n, elementorV2.editorV1Adapters, elementorV2.utils); | |
| 83 | +function useActiveDocumentActions() { | |
| 84 | + const document = (0,_use_active_document__WEBPACK_IMPORTED_MODULE_2__["default"])(); | |
| 85 | + const permalink = document?.links?.permalink ?? ''; | |
| 86 | + const save = (0,react__WEBPACK_IMPORTED_MODULE_0__.useCallback)(() => (0,_elementor_editor_v1_adapters__WEBPACK_IMPORTED_MODULE_1__.__privateRunCommand)('document/save/default'), []); | |
| 87 | + const saveDraft = (0,react__WEBPACK_IMPORTED_MODULE_0__.useCallback)(() => (0,_elementor_editor_v1_adapters__WEBPACK_IMPORTED_MODULE_1__.__privateRunCommand)('document/save/draft'), []); | |
| 88 | + const saveTemplate = (0,react__WEBPACK_IMPORTED_MODULE_0__.useCallback)(() => (0,_elementor_editor_v1_adapters__WEBPACK_IMPORTED_MODULE_1__.__privateOpenRoute)('library/save-template'), []); | |
| 89 | + const copyAndShare = (0,react__WEBPACK_IMPORTED_MODULE_0__.useCallback)(() => { | |
| 90 | + navigator.clipboard.writeText(permalink); | |
| 91 | + }, [permalink]); | |
| 92 | + return { | |
| 93 | + save, | |
| 94 | + saveDraft, | |
| 95 | + saveTemplate, | |
| 96 | + copyAndShare | |
| 97 | + }; | |
| 98 | +} | |
| 99 | + | |
| 100 | +/***/ }), | |
| 101 | + | |
| 102 | +/***/ "./packages/packages/core/editor-documents/src/hooks/use-active-document.ts": | |
| 103 | +/*!**********************************************************************************!*\ | |
| 104 | + !*** ./packages/packages/core/editor-documents/src/hooks/use-active-document.ts ***! | |
| 105 | + \**********************************************************************************/ | |
| 106 | +/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) { | |
| 107 | + | |
| 108 | +__webpack_require__.r(__webpack_exports__); | |
| 109 | +/* harmony export */ __webpack_require__.d(__webpack_exports__, { | |
| 110 | +/* harmony export */ "default": function() { return /* binding */ useActiveDocument; } | |
| 111 | +/* harmony export */ }); | |
| 112 | +/* harmony import */ var _elementor_store__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @elementor/store */ "@elementor/store"); | |
| 113 | +/* harmony import */ var _elementor_store__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_elementor_store__WEBPACK_IMPORTED_MODULE_0__); | |
| 114 | +/* harmony import */ var _store_selectors__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../store/selectors */ "./packages/packages/core/editor-documents/src/store/selectors.ts"); | |
| 115 | + | |
| 116 | + | |
| 117 | +function useActiveDocument() { | |
| 118 | + return (0,_elementor_store__WEBPACK_IMPORTED_MODULE_0__.__useSelector)(_store_selectors__WEBPACK_IMPORTED_MODULE_1__.selectActiveDocument); | |
| 119 | +} | |
| 120 | + | |
| 121 | +/***/ }), | |
| 122 | + | |
| 123 | +/***/ "./packages/packages/core/editor-documents/src/hooks/use-host-document.ts": | |
| 124 | +/*!********************************************************************************!*\ | |
| 125 | + !*** ./packages/packages/core/editor-documents/src/hooks/use-host-document.ts ***! | |
| 126 | + \********************************************************************************/ | |
| 127 | +/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) { | |
| 128 | + | |
| 129 | +__webpack_require__.r(__webpack_exports__); | |
| 130 | +/* harmony export */ __webpack_require__.d(__webpack_exports__, { | |
| 131 | +/* harmony export */ "default": function() { return /* binding */ useHostDocument; } | |
| 132 | +/* harmony export */ }); | |
| 133 | +/* harmony import */ var _elementor_store__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @elementor/store */ "@elementor/store"); | |
| 134 | +/* harmony import */ var _elementor_store__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_elementor_store__WEBPACK_IMPORTED_MODULE_0__); | |
| 135 | +/* harmony import */ var _store_selectors__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../store/selectors */ "./packages/packages/core/editor-documents/src/store/selectors.ts"); | |
| 136 | + | |
| 137 | + | |
| 138 | +function useHostDocument() { | |
| 139 | + return (0,_elementor_store__WEBPACK_IMPORTED_MODULE_0__.__useSelector)(_store_selectors__WEBPACK_IMPORTED_MODULE_1__.selectHostDocument); | |
| 140 | +} | |
| 141 | + | |
| 142 | +/***/ }), | |
| 143 | + | |
| 144 | +/***/ "./packages/packages/core/editor-documents/src/hooks/use-navigate-to-document.ts": | |
| 145 | +/*!***************************************************************************************!*\ | |
| 146 | + !*** ./packages/packages/core/editor-documents/src/hooks/use-navigate-to-document.ts ***! | |
| 147 | + \***************************************************************************************/ | |
| 148 | +/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) { | |
| 149 | + | |
| 150 | +__webpack_require__.r(__webpack_exports__); | |
| 151 | +/* harmony export */ __webpack_require__.d(__webpack_exports__, { | |
| 152 | +/* harmony export */ "default": function() { return /* binding */ useNavigateToDocument; } | |
| 153 | +/* harmony export */ }); | |
| 154 | +/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react"); | |
| 155 | +/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__); | |
| 156 | +/* harmony import */ var _sync_utils__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../sync/utils */ "./packages/packages/core/editor-documents/src/sync/utils.ts"); | |
| 157 | +/* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./utils */ "./packages/packages/core/editor-documents/src/hooks/utils.ts"); | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | +function useNavigateToDocument() { | |
| 162 | + return (0,react__WEBPACK_IMPORTED_MODULE_0__.useCallback)(async id => { | |
| 163 | + const url = (0,_utils__WEBPACK_IMPORTED_MODULE_2__.getUpdateUrl)(id); | |
| 164 | + await (0,_sync_utils__WEBPACK_IMPORTED_MODULE_1__.switchToDocument)(id, { | |
| 165 | + setAsInitial: true | |
| 166 | + }); | |
| 167 | + history.replaceState({}, '', url); | |
| 168 | + }, []); | |
| 169 | +} | |
| 170 | + | |
| 171 | +/***/ }), | |
| 172 | + | |
| 173 | +/***/ "./packages/packages/core/editor-documents/src/hooks/use-open-document-in-new-tab.ts": | |
| 174 | +/*!*******************************************************************************************!*\ | |
| 175 | + !*** ./packages/packages/core/editor-documents/src/hooks/use-open-document-in-new-tab.ts ***! | |
| 176 | + \*******************************************************************************************/ | |
| 177 | +/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) { | |
| 178 | + | |
| 179 | +__webpack_require__.r(__webpack_exports__); | |
| 180 | +/* harmony export */ __webpack_require__.d(__webpack_exports__, { | |
| 181 | +/* harmony export */ "default": function() { return /* binding */ useOpenDocumentInNewTab; } | |
| 182 | +/* harmony export */ }); | |
| 183 | +/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react"); | |
| 184 | +/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__); | |
| 185 | +/* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./utils */ "./packages/packages/core/editor-documents/src/hooks/utils.ts"); | |
| 186 | + | |
| 187 | + | |
| 188 | +function useOpenDocumentInNewTab() { | |
| 189 | + return (0,react__WEBPACK_IMPORTED_MODULE_0__.useCallback)(id => { | |
| 190 | + const url = (0,_utils__WEBPACK_IMPORTED_MODULE_1__.getUpdateUrl)(id); | |
| 191 | + window.open(url.href); | |
| 192 | + }, []); | |
| 193 | +} | |
| 194 | + | |
| 195 | +/***/ }), | |
| 196 | + | |
| 197 | +/***/ "./packages/packages/core/editor-documents/src/hooks/use-sync-document-title.ts": | |
| 198 | +/*!**************************************************************************************!*\ | |
| 199 | + !*** ./packages/packages/core/editor-documents/src/hooks/use-sync-document-title.ts ***! | |
| 200 | + \**************************************************************************************/ | |
| 201 | +/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) { | |
| 202 | + | |
| 203 | +__webpack_require__.r(__webpack_exports__); | |
| 204 | +/* harmony export */ __webpack_require__.d(__webpack_exports__, { | |
| 205 | +/* harmony export */ "default": function() { return /* binding */ useSyncDocumentTitle; } | |
| 206 | +/* harmony export */ }); | |
| 207 | +/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react"); | |
| 208 | +/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__); | |
| 209 | +/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @wordpress/i18n */ "@wordpress/i18n"); | |
| 210 | +/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__); | |
| 211 | +/* harmony import */ var _use_active_document__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./use-active-document */ "./packages/packages/core/editor-documents/src/hooks/use-active-document.ts"); | |
| 212 | +/* harmony import */ var _use_host_document__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./use-host-document */ "./packages/packages/core/editor-documents/src/hooks/use-host-document.ts"); | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | +function useSyncDocumentTitle() { | |
| 218 | + const activeDocument = (0,_use_active_document__WEBPACK_IMPORTED_MODULE_2__["default"])(); | |
| 219 | + const hostDocument = (0,_use_host_document__WEBPACK_IMPORTED_MODULE_3__["default"])(); | |
| 220 | + const document = activeDocument && activeDocument.type.value !== 'kit' ? activeDocument : hostDocument; | |
| 221 | + (0,react__WEBPACK_IMPORTED_MODULE_0__.useEffect)(() => { | |
| 222 | + // Allow empty string as title. | |
| 223 | + if (document?.title === undefined) { | |
| 224 | + return; | |
| 225 | + } | |
| 226 | + | |
| 227 | + // translators: %s: Document title. | |
| 228 | + const title = (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__.__)('Edit "%s" with Elementor', 'elementor').replace('%s', document.title); | |
| 229 | + window.document.title = title; | |
| 230 | + }, [document?.title]); | |
| 231 | +} | |
| 232 | + | |
| 233 | +/***/ }), | |
| 234 | + | |
| 235 | +/***/ "./packages/packages/core/editor-documents/src/hooks/utils.ts": | |
| 236 | +/*!********************************************************************!*\ | |
| 237 | + !*** ./packages/packages/core/editor-documents/src/hooks/utils.ts ***! | |
| 238 | + \********************************************************************/ | |
| 239 | +/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) { | |
| 240 | + | |
| 241 | +__webpack_require__.r(__webpack_exports__); | |
| 242 | +/* harmony export */ __webpack_require__.d(__webpack_exports__, { | |
| 243 | +/* harmony export */ getUpdateUrl: function() { return /* binding */ getUpdateUrl; } | |
| 244 | +/* harmony export */ }); | |
| 245 | +const getUpdateUrl = id => { | |
| 246 | + const url = new URL(window.location.href); | |
| 247 | + url.searchParams.set('post', id.toString()); | |
| 248 | + url.searchParams.delete('active-document'); | |
| 249 | + return url; | |
| 250 | +}; | |
| 251 | + | |
| 252 | +/***/ }), | |
| 253 | + | |
| 254 | +/***/ "./packages/packages/core/editor-documents/src/init.ts": | |
| 255 | +/*!*************************************************************!*\ | |
| 256 | + !*** ./packages/packages/core/editor-documents/src/init.ts ***! | |
| 257 | + \*************************************************************/ | |
| 258 | +/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) { | |
| 259 | + | |
| 260 | +__webpack_require__.r(__webpack_exports__); | |
| 261 | +/* harmony export */ __webpack_require__.d(__webpack_exports__, { | |
| 262 | +/* harmony export */ init: function() { return /* binding */ init; } | |
| 263 | +/* harmony export */ }); | |
| 264 | +/* harmony import */ var _elementor_editor__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @elementor/editor */ "@elementor/editor"); | |
| 265 | +/* harmony import */ var _elementor_editor__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_elementor_editor__WEBPACK_IMPORTED_MODULE_0__); | |
| 266 | +/* harmony import */ var _elementor_store__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @elementor/store */ "@elementor/store"); | |
| 267 | +/* harmony import */ var _elementor_store__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_elementor_store__WEBPACK_IMPORTED_MODULE_1__); | |
| 268 | +/* harmony import */ var _components_logic_hooks__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./components/logic-hooks */ "./packages/packages/core/editor-documents/src/components/logic-hooks.tsx"); | |
| 269 | +/* harmony import */ var _store__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./store */ "./packages/packages/core/editor-documents/src/store/index.ts"); | |
| 270 | +/* harmony import */ var _sync__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./sync */ "./packages/packages/core/editor-documents/src/sync/index.ts"); | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | +function init() { | |
| 277 | + initStore(); | |
| 278 | + (0,_elementor_editor__WEBPACK_IMPORTED_MODULE_0__.injectIntoLogic)({ | |
| 279 | + id: 'documents-hooks', | |
| 280 | + component: _components_logic_hooks__WEBPACK_IMPORTED_MODULE_2__.LogicHooks | |
| 281 | + }); | |
| 282 | +} | |
| 283 | +function initStore() { | |
| 284 | + (0,_elementor_store__WEBPACK_IMPORTED_MODULE_1__.__registerSlice)(_store__WEBPACK_IMPORTED_MODULE_3__.slice); | |
| 285 | + (0,_sync__WEBPACK_IMPORTED_MODULE_4__.syncStore)(); | |
| 286 | +} | |
| 287 | + | |
| 288 | +/***/ }), | |
| 289 | + | |
| 290 | +/***/ "./packages/packages/core/editor-documents/src/store/get-current-document.ts": | |
| 291 | +/*!***********************************************************************************!*\ | |
| 292 | + !*** ./packages/packages/core/editor-documents/src/store/get-current-document.ts ***! | |
| 293 | + \***********************************************************************************/ | |
| 294 | +/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) { | |
| 295 | + | |
| 296 | +__webpack_require__.r(__webpack_exports__); | |
| 297 | +/* harmony export */ __webpack_require__.d(__webpack_exports__, { | |
| 298 | +/* harmony export */ getCurrentDocument: function() { return /* binding */ getCurrentDocument; } | |
| 299 | +/* harmony export */ }); | |
| 300 | +/* harmony import */ var _elementor_store__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @elementor/store */ "@elementor/store"); | |
| 301 | +/* harmony import */ var _elementor_store__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_elementor_store__WEBPACK_IMPORTED_MODULE_0__); | |
| 302 | +/* harmony import */ var _store_selectors__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../store/selectors */ "./packages/packages/core/editor-documents/src/store/selectors.ts"); | |
| 303 | + | |
| 304 | + | |
| 305 | +function getCurrentDocument() { | |
| 306 | + return (0,_store_selectors__WEBPACK_IMPORTED_MODULE_1__.selectActiveDocument)((0,_elementor_store__WEBPACK_IMPORTED_MODULE_0__.__getState)()); | |
| 307 | +} | |
| 308 | + | |
| 309 | +/***/ }), | |
| 310 | + | |
| 311 | +/***/ "./packages/packages/core/editor-documents/src/store/index.ts": | |
| 312 | +/*!********************************************************************!*\ | |
| 313 | + !*** ./packages/packages/core/editor-documents/src/store/index.ts ***! | |
| 314 | + \********************************************************************/ | |
| 315 | +/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) { | |
| 316 | + | |
| 317 | +__webpack_require__.r(__webpack_exports__); | |
| 318 | +/* harmony export */ __webpack_require__.d(__webpack_exports__, { | |
| 319 | +/* harmony export */ slice: function() { return /* binding */ slice; } | |
| 320 | +/* harmony export */ }); | |
| 321 | +/* harmony import */ var _elementor_store__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @elementor/store */ "@elementor/store"); | |
| 322 | +/* harmony import */ var _elementor_store__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_elementor_store__WEBPACK_IMPORTED_MODULE_0__); | |
| 323 | + | |
| 324 | +const initialState = { | |
| 325 | + entities: {}, | |
| 326 | + activeId: null, | |
| 327 | + hostId: null | |
| 328 | +}; | |
| 329 | +function hasActiveEntity(state) { | |
| 330 | + return !!(state.activeId && state.entities[state.activeId]); | |
| 331 | +} | |
| 332 | +const slice = (0,_elementor_store__WEBPACK_IMPORTED_MODULE_0__.__createSlice)({ | |
| 333 | + name: 'documents', | |
| 334 | + initialState, | |
| 335 | + reducers: { | |
| 336 | + init(state, { | |
| 337 | + payload | |
| 338 | + }) { | |
| 339 | + state.entities = payload.entities; | |
| 340 | + state.hostId = payload.hostId; | |
| 341 | + state.activeId = payload.activeId; | |
| 342 | + }, | |
| 343 | + activateDocument(state, action) { | |
| 344 | + state.entities[action.payload.id] = action.payload; | |
| 345 | + state.activeId = action.payload.id; | |
| 346 | + }, | |
| 347 | + setAsHost(state, action) { | |
| 348 | + state.hostId = action.payload; | |
| 349 | + }, | |
| 350 | + updateActiveDocument(state, action) { | |
| 351 | + if (hasActiveEntity(state)) { | |
| 352 | + state.entities[state.activeId] = { | |
| 353 | + ...state.entities[state.activeId], | |
| 354 | + ...action.payload | |
| 355 | + }; | |
| 356 | + } | |
| 357 | + }, | |
| 358 | + startSaving(state) { | |
| 359 | + if (hasActiveEntity(state)) { | |
| 360 | + state.entities[state.activeId].isSaving = true; | |
| 361 | + } | |
| 362 | + }, | |
| 363 | + endSaving(state, action) { | |
| 364 | + if (hasActiveEntity(state)) { | |
| 365 | + state.entities[state.activeId] = { | |
| 366 | + ...action.payload, | |
| 367 | + isSaving: false | |
| 368 | + }; | |
| 369 | + } | |
| 370 | + }, | |
| 371 | + startSavingDraft: state => { | |
| 372 | + if (hasActiveEntity(state)) { | |
| 373 | + state.entities[state.activeId].isSavingDraft = true; | |
| 374 | + } | |
| 375 | + }, | |
| 376 | + endSavingDraft(state, action) { | |
| 377 | + if (hasActiveEntity(state)) { | |
| 378 | + state.entities[state.activeId] = { | |
| 379 | + ...action.payload, | |
| 380 | + isSavingDraft: false | |
| 381 | + }; | |
| 382 | + } | |
| 383 | + }, | |
| 384 | + markAsDirty(state) { | |
| 385 | + if (hasActiveEntity(state)) { | |
| 386 | + state.entities[state.activeId].isDirty = true; | |
| 387 | + } | |
| 388 | + }, | |
| 389 | + markAsPristine(state) { | |
| 390 | + if (hasActiveEntity(state)) { | |
| 391 | + state.entities[state.activeId].isDirty = false; | |
| 392 | + } | |
| 393 | + } | |
| 394 | + } | |
| 395 | +}); | |
| 396 | + | |
| 397 | +/***/ }), | |
| 398 | + | |
| 399 | +/***/ "./packages/packages/core/editor-documents/src/store/selectors.ts": | |
| 400 | +/*!************************************************************************!*\ | |
| 401 | + !*** ./packages/packages/core/editor-documents/src/store/selectors.ts ***! | |
| 402 | + \************************************************************************/ | |
| 403 | +/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) { | |
| 404 | + | |
| 405 | +__webpack_require__.r(__webpack_exports__); | |
| 406 | +/* harmony export */ __webpack_require__.d(__webpack_exports__, { | |
| 407 | +/* harmony export */ selectActiveDocument: function() { return /* binding */ selectActiveDocument; }, | |
| 408 | +/* harmony export */ selectHostDocument: function() { return /* binding */ selectHostDocument; } | |
| 409 | +/* harmony export */ }); | |
| 410 | +/* harmony import */ var _elementor_store__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @elementor/store */ "@elementor/store"); | |
| 411 | +/* harmony import */ var _elementor_store__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_elementor_store__WEBPACK_IMPORTED_MODULE_0__); | |
| 412 | + | |
| 413 | +const selectEntities = state => state.documents.entities; | |
| 414 | +const selectActiveId = state => state.documents.activeId; | |
| 415 | +const selectHostId = state => state.documents.hostId; | |
| 416 | +const selectActiveDocument = (0,_elementor_store__WEBPACK_IMPORTED_MODULE_0__.__createSelector)(selectEntities, selectActiveId, (entities, activeId) => activeId && entities[activeId] ? entities[activeId] : null); | |
| 417 | +const selectHostDocument = (0,_elementor_store__WEBPACK_IMPORTED_MODULE_0__.__createSelector)(selectEntities, selectHostId, (entities, hostId) => hostId && entities[hostId] ? entities[hostId] : null); | |
| 418 | + | |
| 419 | +/***/ }), | |
| 420 | + | |
| 421 | +/***/ "./packages/packages/core/editor-documents/src/sync/index.ts": | |
| 422 | +/*!*******************************************************************!*\ | |
| 423 | + !*** ./packages/packages/core/editor-documents/src/sync/index.ts ***! | |
| 424 | + \*******************************************************************/ | |
| 425 | +/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) { | |
| 426 | + | |
| 427 | +__webpack_require__.r(__webpack_exports__); | |
| 428 | +/* harmony export */ __webpack_require__.d(__webpack_exports__, { | |
| 429 | +/* harmony export */ syncStore: function() { return /* reexport safe */ _sync_store__WEBPACK_IMPORTED_MODULE_0__.syncStore; } | |
| 430 | +/* harmony export */ }); | |
| 431 | +/* harmony import */ var _sync_store__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./sync-store */ "./packages/packages/core/editor-documents/src/sync/sync-store.ts"); | |
| 432 | + | |
| 433 | + | |
| 434 | +/***/ }), | |
| 435 | + | |
| 436 | +/***/ "./packages/packages/core/editor-documents/src/sync/sync-store.ts": | |
| 437 | +/*!************************************************************************!*\ | |
| 438 | + !*** ./packages/packages/core/editor-documents/src/sync/sync-store.ts ***! | |
| 439 | + \************************************************************************/ | |
| 440 | +/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) { | |
| 441 | + | |
| 442 | +__webpack_require__.r(__webpack_exports__); | |
| 443 | +/* harmony export */ __webpack_require__.d(__webpack_exports__, { | |
| 444 | +/* harmony export */ syncStore: function() { return /* binding */ syncStore; } | |
| 445 | +/* harmony export */ }); | |
| 446 | +/* harmony import */ var _elementor_editor_v1_adapters__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @elementor/editor-v1-adapters */ "@elementor/editor-v1-adapters"); | |
| 447 | +/* harmony import */ var _elementor_editor_v1_adapters__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_elementor_editor_v1_adapters__WEBPACK_IMPORTED_MODULE_0__); | |
| 448 | +/* harmony import */ var _elementor_store__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @elementor/store */ "@elementor/store"); | |
| 449 | +/* harmony import */ var _elementor_store__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_elementor_store__WEBPACK_IMPORTED_MODULE_1__); | |
| 450 | +/* harmony import */ var _elementor_utils__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @elementor/utils */ "@elementor/utils"); | |
| 451 | +/* harmony import */ var _elementor_utils__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_elementor_utils__WEBPACK_IMPORTED_MODULE_2__); | |
| 452 | +/* harmony import */ var _store__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../store */ "./packages/packages/core/editor-documents/src/store/index.ts"); | |
| 453 | +/* harmony import */ var _store_selectors__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../store/selectors */ "./packages/packages/core/editor-documents/src/store/selectors.ts"); | |
| 454 | +/* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./utils */ "./packages/packages/core/editor-documents/src/sync/utils.ts"); | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | +function syncStore() { | |
| 462 | + syncInitialization(); | |
| 463 | + syncActiveDocument(); | |
| 464 | + syncOnDocumentSave(); | |
| 465 | + syncOnTitleChange(); | |
| 466 | + syncOnDocumentChange(); | |
| 467 | + syncOnExitToChange(); | |
| 468 | +} | |
| 469 | +function syncInitialization() { | |
| 470 | + const { | |
| 471 | + init | |
| 472 | + } = _store__WEBPACK_IMPORTED_MODULE_3__.slice.actions; | |
| 473 | + (0,_elementor_editor_v1_adapters__WEBPACK_IMPORTED_MODULE_0__.__privateListenTo)((0,_elementor_editor_v1_adapters__WEBPACK_IMPORTED_MODULE_0__.v1ReadyEvent)(), () => { | |
| 474 | + const documentsManager = (0,_utils__WEBPACK_IMPORTED_MODULE_5__.getV1DocumentsManager)(); | |
| 475 | + const entities = Object.entries(documentsManager.documents).reduce((acc, [id, document]) => { | |
| 476 | + acc[id] = (0,_utils__WEBPACK_IMPORTED_MODULE_5__.normalizeV1Document)(document); | |
| 477 | + return acc; | |
| 478 | + }, {}); | |
| 479 | + (0,_elementor_store__WEBPACK_IMPORTED_MODULE_1__.__dispatch)(init({ | |
| 480 | + entities, | |
| 481 | + hostId: documentsManager.getInitialId(), | |
| 482 | + activeId: documentsManager.getCurrentId() | |
| 483 | + })); | |
| 484 | + }); | |
| 485 | +} | |
| 486 | +function syncActiveDocument() { | |
| 487 | + const { | |
| 488 | + activateDocument, | |
| 489 | + setAsHost | |
| 490 | + } = _store__WEBPACK_IMPORTED_MODULE_3__.slice.actions; | |
| 491 | + (0,_elementor_editor_v1_adapters__WEBPACK_IMPORTED_MODULE_0__.__privateListenTo)((0,_elementor_editor_v1_adapters__WEBPACK_IMPORTED_MODULE_0__.commandEndEvent)('editor/documents/open'), () => { | |
| 492 | + const documentsManager = (0,_utils__WEBPACK_IMPORTED_MODULE_5__.getV1DocumentsManager)(); | |
| 493 | + const currentDocument = (0,_utils__WEBPACK_IMPORTED_MODULE_5__.normalizeV1Document)(documentsManager.getCurrent()); | |
| 494 | + (0,_elementor_store__WEBPACK_IMPORTED_MODULE_1__.__dispatch)(activateDocument(currentDocument)); | |
| 495 | + if (documentsManager.getInitialId() === currentDocument.id) { | |
| 496 | + (0,_elementor_store__WEBPACK_IMPORTED_MODULE_1__.__dispatch)(setAsHost(currentDocument.id)); | |
| 497 | + } | |
| 498 | + }); | |
| 499 | +} | |
| 500 | +function syncOnDocumentSave() { | |
| 501 | + const { | |
| 502 | + startSaving, | |
| 503 | + endSaving, | |
| 504 | + startSavingDraft, | |
| 505 | + endSavingDraft | |
| 506 | + } = _store__WEBPACK_IMPORTED_MODULE_3__.slice.actions; | |
| 507 | + const isDraft = e => { | |
| 508 | + const event = e; | |
| 509 | + | |
| 510 | + /** | |
| 511 | + * @see https://github.com/elementor/elementor/blob/5f815d40a/assets/dev/js/editor/document/save/hooks/ui/save/before.js#L18-L22 | |
| 512 | + */ | |
| 513 | + return event.args?.status === 'autosave'; | |
| 514 | + }; | |
| 515 | + (0,_elementor_editor_v1_adapters__WEBPACK_IMPORTED_MODULE_0__.__privateListenTo)((0,_elementor_editor_v1_adapters__WEBPACK_IMPORTED_MODULE_0__.commandStartEvent)('document/save/save'), e => { | |
| 516 | + if (isDraft(e)) { | |
| 517 | + (0,_elementor_store__WEBPACK_IMPORTED_MODULE_1__.__dispatch)(startSavingDraft()); | |
| 518 | + return; | |
| 519 | + } | |
| 520 | + (0,_elementor_store__WEBPACK_IMPORTED_MODULE_1__.__dispatch)(startSaving()); | |
| 521 | + }); | |
| 522 | + (0,_elementor_editor_v1_adapters__WEBPACK_IMPORTED_MODULE_0__.__privateListenTo)((0,_elementor_editor_v1_adapters__WEBPACK_IMPORTED_MODULE_0__.commandEndEvent)('document/save/save'), e => { | |
| 523 | + const activeDocument = (0,_utils__WEBPACK_IMPORTED_MODULE_5__.normalizeV1Document)((0,_utils__WEBPACK_IMPORTED_MODULE_5__.getV1DocumentsManager)().getCurrent()); | |
| 524 | + if (isDraft(e)) { | |
| 525 | + (0,_elementor_store__WEBPACK_IMPORTED_MODULE_1__.__dispatch)(endSavingDraft(activeDocument)); | |
| 526 | + } else { | |
| 527 | + (0,_elementor_store__WEBPACK_IMPORTED_MODULE_1__.__dispatch)(endSaving(activeDocument)); | |
| 528 | + } | |
| 529 | + }); | |
| 530 | +} | |
| 531 | +function syncOnTitleChange() { | |
| 532 | + const { | |
| 533 | + updateActiveDocument | |
| 534 | + } = _store__WEBPACK_IMPORTED_MODULE_3__.slice.actions; | |
| 535 | + const updateTitle = (0,_elementor_utils__WEBPACK_IMPORTED_MODULE_2__.debounce)(e => { | |
| 536 | + const event = e; | |
| 537 | + if (!('post_title' in event.args?.settings)) { | |
| 538 | + return; | |
| 539 | + } | |
| 540 | + const currentDocument = (0,_utils__WEBPACK_IMPORTED_MODULE_5__.getV1DocumentsManager)().getCurrent(); | |
| 541 | + const newTitle = currentDocument.container.settings.get('post_title'); | |
| 542 | + (0,_elementor_store__WEBPACK_IMPORTED_MODULE_1__.__dispatch)(updateActiveDocument({ | |
| 543 | + title: newTitle | |
| 544 | + })); | |
| 545 | + }, 400); | |
| 546 | + (0,_elementor_editor_v1_adapters__WEBPACK_IMPORTED_MODULE_0__.__privateListenTo)((0,_elementor_editor_v1_adapters__WEBPACK_IMPORTED_MODULE_0__.commandEndEvent)('document/elements/settings'), updateTitle); | |
| 547 | +} | |
| 548 | +function syncOnExitToChange() { | |
| 549 | + const { | |
| 550 | + updateActiveDocument | |
| 551 | + } = _store__WEBPACK_IMPORTED_MODULE_3__.slice.actions; | |
| 552 | + const updateExitTo = (0,_elementor_utils__WEBPACK_IMPORTED_MODULE_2__.debounce)(e => { | |
| 553 | + const event = e; | |
| 554 | + if (!('exit_to' in event.args?.settings)) { | |
| 555 | + return; | |
| 556 | + } | |
| 557 | + const currentDocument = (0,_utils__WEBPACK_IMPORTED_MODULE_5__.getV1DocumentsManager)().getCurrent(); | |
| 558 | + const newExitTo = (0,_utils__WEBPACK_IMPORTED_MODULE_5__.getV1DocumentsExitTo)(currentDocument); | |
| 559 | + const permalink = (0,_utils__WEBPACK_IMPORTED_MODULE_5__.getV1DocumentPermalink)(currentDocument); | |
| 560 | + const wpPreview = (0,_utils__WEBPACK_IMPORTED_MODULE_5__.getV1DocumentWpPreview)(currentDocument); | |
| 561 | + (0,_elementor_store__WEBPACK_IMPORTED_MODULE_1__.__dispatch)(updateActiveDocument({ | |
| 562 | + links: { | |
| 563 | + platformEdit: newExitTo, | |
| 564 | + permalink, | |
| 565 | + wpPreview | |
| 566 | + } | |
| 567 | + })); | |
| 568 | + }, 400); | |
| 569 | + (0,_elementor_editor_v1_adapters__WEBPACK_IMPORTED_MODULE_0__.__privateListenTo)((0,_elementor_editor_v1_adapters__WEBPACK_IMPORTED_MODULE_0__.commandEndEvent)('document/elements/settings'), updateExitTo); | |
| 570 | +} | |
| 571 | +function syncOnDocumentChange() { | |
| 572 | + const { | |
| 573 | + markAsDirty, | |
| 574 | + markAsPristine | |
| 575 | + } = _store__WEBPACK_IMPORTED_MODULE_3__.slice.actions; | |
| 576 | + (0,_elementor_editor_v1_adapters__WEBPACK_IMPORTED_MODULE_0__.__privateListenTo)((0,_elementor_editor_v1_adapters__WEBPACK_IMPORTED_MODULE_0__.commandEndEvent)('document/save/set-is-modified'), () => { | |
| 577 | + // Skip the dirtiness check if the document is currently being saved, to prevent the UI | |
| 578 | + // from showing a disabled publish button while there is a save process. The state will | |
| 579 | + // be updated when the save process ends and the whole document state it normalized | |
| 580 | + // (see `syncOnDocumentSave`) | |
| 581 | + const isSaving = (0,_store_selectors__WEBPACK_IMPORTED_MODULE_4__.selectActiveDocument)((0,_elementor_store__WEBPACK_IMPORTED_MODULE_1__.__getState)())?.isSaving; | |
| 582 | + if (isSaving) { | |
| 583 | + return; | |
| 584 | + } | |
| 585 | + const currentDocument = (0,_utils__WEBPACK_IMPORTED_MODULE_5__.getV1DocumentsManager)().getCurrent(); | |
| 586 | + if (currentDocument.editor.isChanged) { | |
| 587 | + (0,_elementor_store__WEBPACK_IMPORTED_MODULE_1__.__dispatch)(markAsDirty()); | |
| 588 | + return; | |
| 589 | + } | |
| 590 | + (0,_elementor_store__WEBPACK_IMPORTED_MODULE_1__.__dispatch)(markAsPristine()); | |
| 591 | + }); | |
| 592 | +} | |
| 593 | + | |
| 594 | +/***/ }), | |
| 595 | + | |
| 596 | +/***/ "./packages/packages/core/editor-documents/src/sync/utils.ts": | |
| 597 | +/*!*******************************************************************!*\ | |
| 598 | + !*** ./packages/packages/core/editor-documents/src/sync/utils.ts ***! | |
| 599 | + \*******************************************************************/ | |
| 600 | +/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) { | |
| 601 | + | |
| 602 | +__webpack_require__.r(__webpack_exports__); | |
| 603 | +/* harmony export */ __webpack_require__.d(__webpack_exports__, { | |
| 604 | +/* harmony export */ getV1CurrentDocument: function() { return /* binding */ getV1CurrentDocument; }, | |
| 605 | +/* harmony export */ getV1DocumentPermalink: function() { return /* binding */ getV1DocumentPermalink; }, | |
| 606 | +/* harmony export */ getV1DocumentWpPreview: function() { return /* binding */ getV1DocumentWpPreview; }, | |
| 607 | +/* harmony export */ getV1DocumentsExitTo: function() { return /* binding */ getV1DocumentsExitTo; }, | |
| 608 | +/* harmony export */ getV1DocumentsManager: function() { return /* binding */ getV1DocumentsManager; }, | |
| 609 | +/* harmony export */ invalidateDocumentData: function() { return /* binding */ invalidateDocumentData; }, | |
| 610 | +/* harmony export */ isDocumentDirty: function() { return /* binding */ isDocumentDirty; }, | |
| 611 | +/* harmony export */ normalizeV1Document: function() { return /* binding */ normalizeV1Document; }, | |
| 612 | +/* harmony export */ reloadCurrentDocument: function() { return /* binding */ reloadCurrentDocument; }, | |
| 613 | +/* harmony export */ setDocumentModifiedStatus: function() { return /* binding */ setDocumentModifiedStatus; }, | |
| 614 | +/* harmony export */ switchToDocument: function() { return /* binding */ switchToDocument; } | |
| 615 | +/* harmony export */ }); | |
| 616 | +/* harmony import */ var _elementor_editor_v1_adapters__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @elementor/editor-v1-adapters */ "@elementor/editor-v1-adapters"); | |
| 617 | +/* harmony import */ var _elementor_editor_v1_adapters__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_elementor_editor_v1_adapters__WEBPACK_IMPORTED_MODULE_0__); | |
| 618 | +/* harmony import */ var _store_get_current_document__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../store/get-current-document */ "./packages/packages/core/editor-documents/src/store/get-current-document.ts"); | |
| 619 | + | |
| 620 | + | |
| 621 | +function getV1DocumentsManager() { | |
| 622 | + const documentsManager = window.elementor?.documents; | |
| 623 | + if (!documentsManager) { | |
| 624 | + throw new Error('Elementor Editor V1 documents manager not found'); | |
| 625 | + } | |
| 626 | + return documentsManager; | |
| 627 | +} | |
| 628 | +function getV1DocumentsExitTo(documentData) { | |
| 629 | + const exitPreference = window.elementor?.getPreferences?.('exit_to') || 'this_post'; | |
| 630 | + switch (exitPreference) { | |
| 631 | + case 'dashboard': | |
| 632 | + return documentData.config.urls.main_dashboard; | |
| 633 | + case 'all_posts': | |
| 634 | + return documentData.config.urls.all_post_type; | |
| 635 | + case 'this_post': | |
| 636 | + default: | |
| 637 | + return documentData.config.urls.exit_to_dashboard; | |
| 638 | + } | |
| 639 | +} | |
| 640 | +function getV1DocumentShowCopyAndShare(documentData) { | |
| 641 | + return documentData?.config?.panel?.show_copy_and_share ?? false; | |
| 642 | +} | |
| 643 | +function getV1DocumentPermalink(documentData) { | |
| 644 | + return documentData.config.urls.permalink ?? ''; | |
| 645 | +} | |
| 646 | +function getV1DocumentWpPreview(documentData) { | |
| 647 | + return documentData.config.urls.wp_preview ?? ''; | |
| 648 | +} | |
| 649 | +function normalizeV1Document(documentData) { | |
| 650 | + // Draft or autosave. | |
| 651 | + const isUnpublishedRevision = documentData.config.revisions.current_id !== documentData.id; | |
| 652 | + const exitToUrl = getV1DocumentsExitTo(documentData); | |
| 653 | + return { | |
| 654 | + id: documentData.id, | |
| 655 | + title: documentData.container.settings.get('post_title'), | |
| 656 | + type: { | |
| 657 | + value: documentData.config.type, | |
| 658 | + label: documentData.config.panel.title | |
| 659 | + }, | |
| 660 | + status: { | |
| 661 | + value: documentData.config.status.value, | |
| 662 | + label: documentData.config.status.label | |
| 663 | + }, | |
| 664 | + links: { | |
| 665 | + permalink: getV1DocumentPermalink(documentData), | |
| 666 | + wpPreview: getV1DocumentWpPreview(documentData), | |
| 667 | + platformEdit: exitToUrl | |
| 668 | + }, | |
| 669 | + isDirty: documentData.editor.isChanged || isUnpublishedRevision, | |
| 670 | + isSaving: documentData.editor.isSaving, | |
| 671 | + isSavingDraft: false, | |
| 672 | + permissions: { | |
| 673 | + allowAddingWidgets: documentData.config.panel?.allow_adding_widgets ?? true, | |
| 674 | + showCopyAndShare: getV1DocumentShowCopyAndShare(documentData) | |
| 675 | + }, | |
| 676 | + userCan: { | |
| 677 | + publish: documentData.config.user.can_publish | |
| 678 | + } | |
| 679 | + }; | |
| 680 | +} | |
| 681 | +function setDocumentModifiedStatus(status) { | |
| 682 | + (0,_elementor_editor_v1_adapters__WEBPACK_IMPORTED_MODULE_0__.__privateRunCommandSync)('document/save/set-is-modified', { | |
| 683 | + status | |
| 684 | + }, { | |
| 685 | + internal: true | |
| 686 | + }); | |
| 687 | +} | |
| 688 | +function getV1CurrentDocument() { | |
| 689 | + return window.elementor?.documents?.getCurrent(); | |
| 690 | +} | |
| 691 | +function isDocumentDirty(document) { | |
| 692 | + const isDraft = document.status.value === 'draft'; | |
| 693 | + | |
| 694 | + // When the document is published, but have draft version. | |
| 695 | + const hasAutosave = document.revisions?.current_id !== document.id; | |
| 696 | + return isDraft || hasAutosave; | |
| 697 | +} | |
| 698 | +function invalidateDocumentData(documentId) { | |
| 699 | + const documentsManager = getV1DocumentsManager(); | |
| 700 | + documentsManager.invalidateCache(documentId); | |
| 701 | +} | |
| 702 | +function reloadCurrentDocument() { | |
| 703 | + const currentDocument = (0,_store_get_current_document__WEBPACK_IMPORTED_MODULE_1__.getCurrentDocument)(); | |
| 704 | + if (!currentDocument?.id) { | |
| 705 | + return Promise.resolve(); | |
| 706 | + } | |
| 707 | + getV1DocumentsManager().invalidateCache(); | |
| 708 | + return (0,_elementor_editor_v1_adapters__WEBPACK_IMPORTED_MODULE_0__.__privateRunCommand)('editor/documents/switch', { | |
| 709 | + id: currentDocument.id, | |
| 710 | + shouldScroll: false, | |
| 711 | + shouldNavigateToDefaultRoute: false | |
| 712 | + }); | |
| 713 | +} | |
| 714 | +function switchToDocument(documentId, options) { | |
| 715 | + return (0,_elementor_editor_v1_adapters__WEBPACK_IMPORTED_MODULE_0__.__privateRunCommand)('editor/documents/switch', { | |
| 716 | + id: documentId, | |
| 717 | + ...options | |
| 718 | + }); | |
| 719 | +} | |
| 720 | + | |
| 721 | +/***/ }), | |
| 722 | + | |
| 723 | +/***/ "./packages/packages/core/editor-documents/src/types.ts": | |
| 724 | +/*!**************************************************************!*\ | |
| 725 | + !*** ./packages/packages/core/editor-documents/src/types.ts ***! | |
| 726 | + \**************************************************************/ | |
| 727 | +/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) { | |
| 728 | + | |
| 729 | +__webpack_require__.r(__webpack_exports__); | |
| 730 | + | |
| 731 | + | |
| 732 | +/***/ }), | |
| 733 | + | |
| 734 | +/***/ "@elementor/editor": | |
| 735 | +/*!*****************************************!*\ | |
| 736 | + !*** external ["elementorV2","editor"] ***! | |
| 737 | + \*****************************************/ | |
| 738 | +/***/ (function(module) { | |
| 739 | + | |
| 740 | +module.exports = window["elementorV2"]["editor"]; | |
| 741 | + | |
| 742 | +/***/ }), | |
| 743 | + | |
| 744 | +/***/ "@elementor/editor-v1-adapters": | |
| 745 | +/*!***************************************************!*\ | |
| 746 | + !*** external ["elementorV2","editorV1Adapters"] ***! | |
| 747 | + \***************************************************/ | |
| 748 | +/***/ (function(module) { | |
| 749 | + | |
| 750 | +module.exports = window["elementorV2"]["editorV1Adapters"]; | |
| 751 | + | |
| 752 | +/***/ }), | |
| 753 | + | |
| 754 | +/***/ "@elementor/store": | |
| 755 | +/*!****************************************!*\ | |
| 756 | + !*** external ["elementorV2","store"] ***! | |
| 757 | + \****************************************/ | |
| 758 | +/***/ (function(module) { | |
| 759 | + | |
| 760 | +module.exports = window["elementorV2"]["store"]; | |
| 761 | + | |
| 762 | +/***/ }), | |
| 763 | + | |
| 764 | +/***/ "@elementor/utils": | |
| 765 | +/*!****************************************!*\ | |
| 766 | + !*** external ["elementorV2","utils"] ***! | |
| 767 | + \****************************************/ | |
| 768 | +/***/ (function(module) { | |
| 769 | + | |
| 770 | +module.exports = window["elementorV2"]["utils"]; | |
| 771 | + | |
| 772 | +/***/ }), | |
| 773 | + | |
| 774 | +/***/ "@wordpress/i18n": | |
| 775 | +/*!******************************!*\ | |
| 776 | + !*** external ["wp","i18n"] ***! | |
| 777 | + \******************************/ | |
| 778 | +/***/ (function(module) { | |
| 779 | + | |
| 780 | +module.exports = window["wp"]["i18n"]; | |
| 781 | + | |
| 782 | +/***/ }), | |
| 783 | + | |
| 784 | +/***/ "react": | |
| 785 | +/*!**************************!*\ | |
| 786 | + !*** external ["React"] ***! | |
| 787 | + \**************************/ | |
| 788 | +/***/ (function(module) { | |
| 789 | + | |
| 790 | +module.exports = window["React"]; | |
| 791 | + | |
| 792 | +/***/ }) | |
| 793 | + | |
| 794 | +/******/ }); | |
| 795 | +/************************************************************************/ | |
| 796 | +/******/ // The module cache | |
| 797 | +/******/ var __webpack_module_cache__ = {}; | |
| 798 | +/******/ | |
| 799 | +/******/ // The require function | |
| 800 | +/******/ function __webpack_require__(moduleId) { | |
| 801 | +/******/ // Check if module is in cache | |
| 802 | +/******/ var cachedModule = __webpack_module_cache__[moduleId]; | |
| 803 | +/******/ if (cachedModule !== undefined) { | |
| 804 | +/******/ return cachedModule.exports; | |
| 805 | +/******/ } | |
| 806 | +/******/ // Create a new module (and put it into the cache) | |
| 807 | +/******/ var module = __webpack_module_cache__[moduleId] = { | |
| 808 | +/******/ // no module.id needed | |
| 809 | +/******/ // no module.loaded needed | |
| 810 | +/******/ exports: {} | |
| 811 | +/******/ }; | |
| 812 | +/******/ | |
| 813 | +/******/ // Execute the module function | |
| 814 | +/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__); | |
| 815 | +/******/ | |
| 816 | +/******/ // Return the exports of the module | |
| 817 | +/******/ return module.exports; | |
| 818 | +/******/ } | |
| 819 | +/******/ | |
| 820 | +/************************************************************************/ | |
| 821 | +/******/ /* webpack/runtime/compat get default export */ | |
| 822 | +/******/ !function() { | |
| 823 | +/******/ // getDefaultExport function for compatibility with non-harmony modules | |
| 824 | +/******/ __webpack_require__.n = function(module) { | |
| 825 | +/******/ var getter = module && module.__esModule ? | |
| 826 | +/******/ function() { return module['default']; } : | |
| 827 | +/******/ function() { return module; }; | |
| 828 | +/******/ __webpack_require__.d(getter, { a: getter }); | |
| 829 | +/******/ return getter; | |
| 830 | +/******/ }; | |
| 831 | +/******/ }(); | |
| 832 | +/******/ | |
| 833 | +/******/ /* webpack/runtime/define property getters */ | |
| 834 | +/******/ !function() { | |
| 835 | +/******/ // define getter functions for harmony exports | |
| 836 | +/******/ __webpack_require__.d = function(exports, definition) { | |
| 837 | +/******/ for(var key in definition) { | |
| 838 | +/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { | |
| 839 | +/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); | |
| 840 | +/******/ } | |
| 841 | +/******/ } | |
| 842 | +/******/ }; | |
| 843 | +/******/ }(); | |
| 844 | +/******/ | |
| 845 | +/******/ /* webpack/runtime/hasOwnProperty shorthand */ | |
| 846 | +/******/ !function() { | |
| 847 | +/******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); } | |
| 848 | +/******/ }(); | |
| 849 | +/******/ | |
| 850 | +/******/ /* webpack/runtime/make namespace object */ | |
| 851 | +/******/ !function() { | |
| 852 | +/******/ // define __esModule on exports | |
| 853 | +/******/ __webpack_require__.r = function(exports) { | |
| 854 | +/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { | |
| 855 | +/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); | |
| 856 | +/******/ } | |
| 857 | +/******/ Object.defineProperty(exports, '__esModule', { value: true }); | |
| 858 | +/******/ }; | |
| 859 | +/******/ }(); | |
| 860 | +/******/ | |
| 861 | +/************************************************************************/ | |
| 862 | +var __webpack_exports__ = {}; | |
| 863 | +// This entry needs to be wrapped in an IIFE because it needs to be isolated against other modules in the chunk. | |
| 864 | +!function() { | |
| 865 | +/*!**************************************************************!*\ | |
| 866 | + !*** ./packages/packages/core/editor-documents/src/index.ts ***! | |
| 867 | + \**************************************************************/ | |
| 868 | +__webpack_require__.r(__webpack_exports__); | |
| 869 | +/* harmony export */ __webpack_require__.d(__webpack_exports__, { | |
| 870 | +/* harmony export */ COMPONENT_DOCUMENT_TYPE: function() { return /* reexport safe */ _consts__WEBPACK_IMPORTED_MODULE_5__.COMPONENT_DOCUMENT_TYPE; }, | |
| 871 | +/* harmony export */ __useActiveDocument: function() { return /* reexport safe */ _hooks__WEBPACK_IMPORTED_MODULE_1__.useActiveDocument; }, | |
| 872 | +/* harmony export */ __useActiveDocumentActions: function() { return /* reexport safe */ _hooks__WEBPACK_IMPORTED_MODULE_1__.useActiveDocumentActions; }, | |
| 873 | +/* harmony export */ __useHostDocument: function() { return /* reexport safe */ _hooks__WEBPACK_IMPORTED_MODULE_1__.useHostDocument; }, | |
| 874 | +/* harmony export */ __useNavigateToDocument: function() { return /* reexport safe */ _hooks__WEBPACK_IMPORTED_MODULE_1__.useNavigateToDocument; }, | |
| 875 | +/* harmony export */ __useOpenDocumentInNewTab: function() { return /* reexport safe */ _hooks__WEBPACK_IMPORTED_MODULE_1__.useOpenDocumentInNewTab; }, | |
| 876 | +/* harmony export */ getCurrentDocument: function() { return /* reexport safe */ _store_get_current_document__WEBPACK_IMPORTED_MODULE_3__.getCurrentDocument; }, | |
| 877 | +/* harmony export */ getV1CurrentDocument: function() { return /* reexport safe */ _sync_utils__WEBPACK_IMPORTED_MODULE_4__.getV1CurrentDocument; }, | |
| 878 | +/* harmony export */ getV1DocumentsManager: function() { return /* reexport safe */ _sync_utils__WEBPACK_IMPORTED_MODULE_4__.getV1DocumentsManager; }, | |
| 879 | +/* harmony export */ init: function() { return /* reexport safe */ _init__WEBPACK_IMPORTED_MODULE_0__.init; }, | |
| 880 | +/* harmony export */ invalidateDocumentData: function() { return /* reexport safe */ _sync_utils__WEBPACK_IMPORTED_MODULE_4__.invalidateDocumentData; }, | |
| 881 | +/* harmony export */ isDocumentDirty: function() { return /* reexport safe */ _sync_utils__WEBPACK_IMPORTED_MODULE_4__.isDocumentDirty; }, | |
| 882 | +/* harmony export */ reloadCurrentDocument: function() { return /* reexport safe */ _sync_utils__WEBPACK_IMPORTED_MODULE_4__.reloadCurrentDocument; }, | |
| 883 | +/* harmony export */ setDocumentModifiedStatus: function() { return /* reexport safe */ _sync_utils__WEBPACK_IMPORTED_MODULE_4__.setDocumentModifiedStatus; }, | |
| 884 | +/* harmony export */ slice: function() { return /* reexport safe */ _store__WEBPACK_IMPORTED_MODULE_2__.slice; }, | |
| 885 | +/* harmony export */ switchToDocument: function() { return /* reexport safe */ _sync_utils__WEBPACK_IMPORTED_MODULE_4__.switchToDocument; } | |
| 886 | +/* harmony export */ }); | |
| 887 | +/* harmony import */ var _init__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./init */ "./packages/packages/core/editor-documents/src/init.ts"); | |
| 888 | +/* harmony import */ var _hooks__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./hooks */ "./packages/packages/core/editor-documents/src/hooks/index.ts"); | |
| 889 | +/* harmony import */ var _store__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./store */ "./packages/packages/core/editor-documents/src/store/index.ts"); | |
| 890 | +/* harmony import */ var _store_get_current_document__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./store/get-current-document */ "./packages/packages/core/editor-documents/src/store/get-current-document.ts"); | |
| 891 | +/* harmony import */ var _sync_utils__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./sync/utils */ "./packages/packages/core/editor-documents/src/sync/utils.ts"); | |
| 892 | +/* harmony import */ var _consts__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./consts */ "./packages/packages/core/editor-documents/src/consts.ts"); | |
| 893 | +/* harmony import */ var _types__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./types */ "./packages/packages/core/editor-documents/src/types.ts"); | |
| 894 | + | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
| 901 | +}(); | |
| 902 | +(window.elementorV2 = window.elementorV2 || {}).editorDocuments = __webpack_exports__; | |
| 903 | +/******/ })() | |
| 904 | +; | |
| 388 | 905 | window.elementorV2.editorDocuments?.init?.(); |
| 389 | 906 | //# sourceMappingURL=editor-documents.js.map |