PluginProbe
Elementor Website Builder – more than just a page builder / 3.17.2
Elementor Website Builder – more than just a page builder v3.17.2
4.3.2 4.3.1 4.3.0 4.3.0-beta3 4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 All 455 releases
← All changes | assets/js/packages/editor-documents/editor-documents.js +384 -369 4.3.1 → 3.17.2 View file →
@@ -1,389 +1,404 @@
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 +/***/ "react":
6 +/*!**************************!*\
7 + !*** external ["React"] ***!
8 + \**************************/
9 +/***/ (function(module) {
22 10
23 -//#endregion
11 +module.exports = window["React"];
24 12
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);
13 +/***/ }),
31 14
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 - }
15 +/***/ "@elementor/editor-v1-adapters":
16 +/*!***************************************************!*\
17 + !*** external ["elementorV2","editorV1Adapters"] ***!
18 + \***************************************************/
19 +/***/ (function(module) {
37 20
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 - }
21 +module.exports = window["elementorV2"]["editorV1Adapters"];
43 22
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 - }
23 +/***/ }),
56 24
57 -//#endregion
58 -//#region packages/packages/core/editor-documents/src/components/logic-hooks.tsx
59 - function LogicHooks() {
60 - useSyncDocumentTitle();
61 - return null;
62 - }
25 +/***/ "@elementor/store":
26 +/*!****************************************!*\
27 + !*** external ["elementorV2","store"] ***!
28 + \****************************************/
29 +/***/ (function(module) {
63 30
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 - });
31 +module.exports = window["elementorV2"]["store"];
122 32
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 - }
33 +/***/ })
128 34
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 - }
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
211 108
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 - }
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 +});
300 179
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 - }
180 +// src/sync/sync-store.ts
314 181
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 182
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 - };
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 +}
337 215
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 - }
216 +// src/sync/sync-store.ts
347 217
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 - }
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__.__privateListenTo)(
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__.__privateListenTo)(
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__.__privateListenTo)(
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__.__privateListenTo)(
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__.__privateListenTo)(
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__.__privateListenTo)(
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 +}
356 326
357 -//#endregion
358 -//#region packages/packages/core/editor-documents/src/consts.ts
359 - var COMPONENT_DOCUMENT_TYPE = "elementor_component";
327 +// src/init.ts
360 328
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 - });
329 +function init() {
330 + initStore();
331 +}
332 +function initStore() {
333 + (0,_elementor_store__WEBPACK_IMPORTED_MODULE_0__.__registerSlice)(slice);
334 + syncStore();
335 +}
381 336
382 -//#endregion
383 -//#region \0elementor-package-library-entry
384 - (window.elementorV2 = window.elementorV2 || {}).editorDocuments = src_exports;
337 +// src/hooks/use-active-document.ts
385 338
386 -//#endregion
387 -})(elementorV2.editor, elementorV2.store, React, wp.i18n, elementorV2.editorV1Adapters, elementorV2.utils);
388 -window.elementorV2.editorDocuments?.init?.();
389 -//# sourceMappingURL=editor-documents.js.map
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__.__privateRunCommand)("document/save/default"), []);
366 + const saveDraft = (0,react__WEBPACK_IMPORTED_MODULE_2__.useCallback)(() => (0,_elementor_editor_v1_adapters__WEBPACK_IMPORTED_MODULE_1__.__privateRunCommand)("document/save/draft"), []);
367 + const saveTemplate = (0,react__WEBPACK_IMPORTED_MODULE_2__.useCallback)(() => (0,_elementor_editor_v1_adapters__WEBPACK_IMPORTED_MODULE_1__.__privateOpenRoute)("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__.__privateRunCommand)("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 +;