PluginProbe
Elementor Website Builder – more than just a page builder / 4.3.1
Elementor Website Builder – more than just a page builder v4.3.1
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 +388 -2 4.1.0-dev2 → 4.3.1 View file →
@@ -1,3 +1,389 @@
1 -/*! For license information please see editor-documents.js.LICENSE.txt */
2 -!function(){"use strict";var e={"./packages/packages/core/editor-documents/src/components/logic-hooks.tsx":function(e,t,n){n.r(t),n.d(t,{LogicHooks:function(){return LogicHooks}});var o=n("./packages/packages/core/editor-documents/src/hooks/use-sync-document-title.ts");function LogicHooks(){return(0,o.default)(),null}},"./packages/packages/core/editor-documents/src/consts.ts":function(e,t,n){n.r(t),n.d(t,{COMPONENT_DOCUMENT_TYPE:function(){return o}});const o="elementor_component"},"./packages/packages/core/editor-documents/src/hooks/index.ts":function(e,t,n){n.r(t),n.d(t,{useActiveDocument:function(){return o.default},useActiveDocumentActions:function(){return c.default},useHostDocument:function(){return s.default},useNavigateToDocument:function(){return r.default},useOpenDocumentInNewTab:function(){return i.default}});var o=n("./packages/packages/core/editor-documents/src/hooks/use-active-document.ts"),c=n("./packages/packages/core/editor-documents/src/hooks/use-active-document-actions.ts"),s=n("./packages/packages/core/editor-documents/src/hooks/use-host-document.ts"),r=n("./packages/packages/core/editor-documents/src/hooks/use-navigate-to-document.ts"),i=n("./packages/packages/core/editor-documents/src/hooks/use-open-document-in-new-tab.ts")},"./packages/packages/core/editor-documents/src/hooks/use-active-document-actions.ts":function(e,t,n){n.r(t),n.d(t,{default:function(){return useActiveDocumentActions}});var o=n("react"),c=n("@elementor/editor-v1-adapters"),s=n("./packages/packages/core/editor-documents/src/hooks/use-active-document.ts");function useActiveDocumentActions(){const e=(0,s.default)(),t=e?.links?.permalink??"";return{save:(0,o.useCallback)(()=>(0,c.__privateRunCommand)("document/save/default"),[]),saveDraft:(0,o.useCallback)(()=>(0,c.__privateRunCommand)("document/save/draft"),[]),saveTemplate:(0,o.useCallback)(()=>(0,c.__privateOpenRoute)("library/save-template"),[]),copyAndShare:(0,o.useCallback)(()=>{navigator.clipboard.writeText(t)},[t])}}},"./packages/packages/core/editor-documents/src/hooks/use-active-document.ts":function(e,t,n){n.r(t),n.d(t,{default:function(){return useActiveDocument}});var o=n("@elementor/store"),c=n("./packages/packages/core/editor-documents/src/store/selectors.ts");function useActiveDocument(){return(0,o.__useSelector)(c.selectActiveDocument)}},"./packages/packages/core/editor-documents/src/hooks/use-host-document.ts":function(e,t,n){n.r(t),n.d(t,{default:function(){return useHostDocument}});var o=n("@elementor/store"),c=n("./packages/packages/core/editor-documents/src/store/selectors.ts");function useHostDocument(){return(0,o.__useSelector)(c.selectHostDocument)}},"./packages/packages/core/editor-documents/src/hooks/use-navigate-to-document.ts":function(e,t,n){n.r(t),n.d(t,{default:function(){return useNavigateToDocument}});var o=n("react"),c=n("./packages/packages/core/editor-documents/src/sync/utils.ts"),s=n("./packages/packages/core/editor-documents/src/hooks/utils.ts");function useNavigateToDocument(){return(0,o.useCallback)(async e=>{const t=(0,s.getUpdateUrl)(e);await(0,c.switchToDocument)(e,{setAsInitial:!0}),history.replaceState({},"",t)},[])}},"./packages/packages/core/editor-documents/src/hooks/use-open-document-in-new-tab.ts":function(e,t,n){n.r(t),n.d(t,{default:function(){return useOpenDocumentInNewTab}});var o=n("react"),c=n("./packages/packages/core/editor-documents/src/hooks/utils.ts");function useOpenDocumentInNewTab(){return(0,o.useCallback)(e=>{const t=(0,c.getUpdateUrl)(e);window.open(t.href)},[])}},"./packages/packages/core/editor-documents/src/hooks/use-sync-document-title.ts":function(e,t,n){n.r(t),n.d(t,{default:function(){return useSyncDocumentTitle}});var o=n("react"),c=n("@wordpress/i18n"),s=n("./packages/packages/core/editor-documents/src/hooks/use-active-document.ts"),r=n("./packages/packages/core/editor-documents/src/hooks/use-host-document.ts");function useSyncDocumentTitle(){const e=(0,s.default)(),t=(0,r.default)(),n=e&&"kit"!==e.type.value?e:t;(0,o.useEffect)(()=>{if(void 0===n?.title)return;const e=(0,c.__)('Edit "%s" with Elementor',"elementor").replace("%s",n.title);window.document.title=e},[n?.title])}},"./packages/packages/core/editor-documents/src/hooks/utils.ts":function(e,t,n){n.r(t),n.d(t,{getUpdateUrl:function(){return getUpdateUrl}});const getUpdateUrl=e=>{const t=new URL(window.location.href);return t.searchParams.set("post",e.toString()),t.searchParams.delete("active-document"),t}},"./packages/packages/core/editor-documents/src/init.ts":function(e,t,n){n.r(t),n.d(t,{init:function(){return init}});var o=n("@elementor/editor"),c=n("@elementor/store"),s=n("./packages/packages/core/editor-documents/src/components/logic-hooks.tsx"),r=n("./packages/packages/core/editor-documents/src/store/index.ts"),i=n("./packages/packages/core/editor-documents/src/sync/index.ts");function init(){!function initStore(){(0,c.__registerSlice)(r.slice),(0,i.syncStore)()}(),(0,o.injectIntoLogic)({id:"documents-hooks",component:s.LogicHooks})}},"./packages/packages/core/editor-documents/src/store/get-current-document.ts":function(e,t,n){n.r(t),n.d(t,{getCurrentDocument:function(){return getCurrentDocument}});var o=n("@elementor/store"),c=n("./packages/packages/core/editor-documents/src/store/selectors.ts");function getCurrentDocument(){return(0,c.selectActiveDocument)((0,o.__getState)())}},"./packages/packages/core/editor-documents/src/store/index.ts":function(e,t,n){n.r(t),n.d(t,{slice:function(){return c}});var o=n("@elementor/store");function hasActiveEntity(e){return!(!e.activeId||!e.entities[e.activeId])}const c=(0,o.__createSlice)({name:"documents",initialState:{entities:{},activeId:null,hostId:null},reducers:{init(e,{payload:t}){e.entities=t.entities,e.hostId=t.hostId,e.activeId=t.activeId},activateDocument(e,t){e.entities[t.payload.id]=t.payload,e.activeId=t.payload.id},setAsHost(e,t){e.hostId=t.payload},updateActiveDocument(e,t){hasActiveEntity(e)&&(e.entities[e.activeId]={...e.entities[e.activeId],...t.payload})},startSaving(e){hasActiveEntity(e)&&(e.entities[e.activeId].isSaving=!0)},endSaving(e,t){hasActiveEntity(e)&&(e.entities[e.activeId]={...t.payload,isSaving:!1})},startSavingDraft:e=>{hasActiveEntity(e)&&(e.entities[e.activeId].isSavingDraft=!0)},endSavingDraft(e,t){hasActiveEntity(e)&&(e.entities[e.activeId]={...t.payload,isSavingDraft:!1})},markAsDirty(e){hasActiveEntity(e)&&(e.entities[e.activeId].isDirty=!0)},markAsPristine(e){hasActiveEntity(e)&&(e.entities[e.activeId].isDirty=!1)}}})},"./packages/packages/core/editor-documents/src/store/selectors.ts":function(e,t,n){n.r(t),n.d(t,{selectActiveDocument:function(){return c},selectHostDocument:function(){return s}});var o=n("@elementor/store");const selectEntities=e=>e.documents.entities,c=(0,o.__createSelector)(selectEntities,e=>e.documents.activeId,(e,t)=>t&&e[t]?e[t]:null),s=(0,o.__createSelector)(selectEntities,e=>e.documents.hostId,(e,t)=>t&&e[t]?e[t]:null)},"./packages/packages/core/editor-documents/src/sync/index.ts":function(e,t,n){n.r(t),n.d(t,{syncStore:function(){return o.syncStore}});var o=n("./packages/packages/core/editor-documents/src/sync/sync-store.ts")},"./packages/packages/core/editor-documents/src/sync/sync-store.ts":function(e,t,n){n.r(t),n.d(t,{syncStore:function(){return syncStore}});var o=n("@elementor/editor-v1-adapters"),c=n("@elementor/store"),s=n("@elementor/utils"),r=n("./packages/packages/core/editor-documents/src/store/index.ts"),i=n("./packages/packages/core/editor-documents/src/store/selectors.ts"),a=n("./packages/packages/core/editor-documents/src/sync/utils.ts");function syncStore(){!function syncInitialization(){const{init:e}=r.slice.actions;(0,o.__privateListenTo)((0,o.v1ReadyEvent)(),()=>{const t=(0,a.getV1DocumentsManager)(),n=Object.entries(t.documents).reduce((e,[t,n])=>(e[t]=(0,a.normalizeV1Document)(n),e),{});(0,c.__dispatch)(e({entities:n,hostId:t.getInitialId(),activeId:t.getCurrentId()}))})}(),function syncActiveDocument(){const{activateDocument:e,setAsHost:t}=r.slice.actions;(0,o.__privateListenTo)((0,o.commandEndEvent)("editor/documents/open"),()=>{const n=(0,a.getV1DocumentsManager)(),o=(0,a.normalizeV1Document)(n.getCurrent());(0,c.__dispatch)(e(o)),n.getInitialId()===o.id&&(0,c.__dispatch)(t(o.id))})}(),function syncOnDocumentSave(){const{startSaving:e,endSaving:t,startSavingDraft:n,endSavingDraft:s}=r.slice.actions,isDraft=e=>{const t=e;return"autosave"===t.args?.status};(0,o.__privateListenTo)((0,o.commandStartEvent)("document/save/save"),t=>{isDraft(t)?(0,c.__dispatch)(n()):(0,c.__dispatch)(e())}),(0,o.__privateListenTo)((0,o.commandEndEvent)("document/save/save"),e=>{const n=(0,a.normalizeV1Document)((0,a.getV1DocumentsManager)().getCurrent());isDraft(e)?(0,c.__dispatch)(s(n)):(0,c.__dispatch)(t(n))})}(),function syncOnTitleChange(){const{updateActiveDocument:e}=r.slice.actions,t=(0,s.debounce)(t=>{const n=t;if(!("post_title"in n.args?.settings))return;const o=(0,a.getV1DocumentsManager)().getCurrent().container.settings.get("post_title");(0,c.__dispatch)(e({title:o}))},400);(0,o.__privateListenTo)((0,o.commandEndEvent)("document/elements/settings"),t)}(),function syncOnDocumentChange(){const{markAsDirty:e,markAsPristine:t}=r.slice.actions;(0,o.__privateListenTo)((0,o.commandEndEvent)("document/save/set-is-modified"),()=>{const n=(0,i.selectActiveDocument)((0,c.__getState)())?.isSaving;if(n)return;(0,a.getV1DocumentsManager)().getCurrent().editor.isChanged?(0,c.__dispatch)(e()):(0,c.__dispatch)(t())})}(),function syncOnExitToChange(){const{updateActiveDocument:e}=r.slice.actions,t=(0,s.debounce)(t=>{const n=t;if(!("exit_to"in n.args?.settings))return;const o=(0,a.getV1DocumentsManager)().getCurrent(),s=(0,a.getV1DocumentsExitTo)(o),r=(0,a.getV1DocumentPermalink)(o),i=(0,a.getV1DocumentWpPreview)(o);(0,c.__dispatch)(e({links:{platformEdit:s,permalink:r,wpPreview:i}}))},400);(0,o.__privateListenTo)((0,o.commandEndEvent)("document/elements/settings"),t)}()}},"./packages/packages/core/editor-documents/src/sync/utils.ts":function(e,t,n){n.r(t),n.d(t,{getV1CurrentDocument:function(){return getV1CurrentDocument},getV1DocumentPermalink:function(){return getV1DocumentPermalink},getV1DocumentWpPreview:function(){return getV1DocumentWpPreview},getV1DocumentsExitTo:function(){return getV1DocumentsExitTo},getV1DocumentsManager:function(){return getV1DocumentsManager},invalidateDocumentData:function(){return invalidateDocumentData},isDocumentDirty:function(){return isDocumentDirty},normalizeV1Document:function(){return normalizeV1Document},reloadCurrentDocument:function(){return reloadCurrentDocument},setDocumentModifiedStatus:function(){return setDocumentModifiedStatus},switchToDocument:function(){return switchToDocument}});var o=n("@elementor/editor-v1-adapters"),c=n("./packages/packages/core/editor-documents/src/store/get-current-document.ts");function getV1DocumentsManager(){const e=window.elementor?.documents;if(!e)throw new Error("Elementor Editor V1 documents manager not found");return e}function getV1DocumentsExitTo(e){switch(window.elementor?.getPreferences?.("exit_to")||"this_post"){case"dashboard":return e.config.urls.main_dashboard;case"all_posts":return e.config.urls.all_post_type;default:return e.config.urls.exit_to_dashboard}}function getV1DocumentShowCopyAndShare(e){return e?.config?.panel?.show_copy_and_share??!1}function getV1DocumentPermalink(e){return e.config.urls.permalink??""}function getV1DocumentWpPreview(e){return e.config.urls.wp_preview??""}function normalizeV1Document(e){const t=e.config.revisions.current_id!==e.id,n=getV1DocumentsExitTo(e);return{id:e.id,title:e.container.settings.get("post_title"),type:{value:e.config.type,label:e.config.panel.title},status:{value:e.config.status.value,label:e.config.status.label},links:{permalink:getV1DocumentPermalink(e),wpPreview:getV1DocumentWpPreview(e),platformEdit:n},isDirty:e.editor.isChanged||t,isSaving:e.editor.isSaving,isSavingDraft:!1,permissions:{allowAddingWidgets:e.config.panel?.allow_adding_widgets??!0,showCopyAndShare:getV1DocumentShowCopyAndShare(e)},userCan:{publish:e.config.user.can_publish}}}function setDocumentModifiedStatus(e){(0,o.__privateRunCommandSync)("document/save/set-is-modified",{status:e},{internal:!0})}function getV1CurrentDocument(){return window.elementor?.documents?.getCurrent()}function isDocumentDirty(e){const t="draft"===e.status.value,n=e.revisions?.current_id!==e.id;return t||n}function invalidateDocumentData(e){getV1DocumentsManager().invalidateCache(e)}function reloadCurrentDocument(){const e=(0,c.getCurrentDocument)();return e?.id?(getV1DocumentsManager().invalidateCache(),(0,o.__privateRunCommand)("editor/documents/switch",{id:e.id,shouldScroll:!1,shouldNavigateToDefaultRoute:!1})):Promise.resolve()}function switchToDocument(e,t){return(0,o.__privateRunCommand)("editor/documents/switch",{id:e,...t})}},"./packages/packages/core/editor-documents/src/types.ts":function(e,t,n){n.r(t)},"@elementor/editor":function(e){e.exports=window.elementorV2.editor},"@elementor/editor-v1-adapters":function(e){e.exports=window.elementorV2.editorV1Adapters},"@elementor/store":function(e){e.exports=window.elementorV2.store},"@elementor/utils":function(e){e.exports=window.elementorV2.utils},"@wordpress/i18n":function(e){e.exports=window.wp.i18n},react:function(e){e.exports=window.React}},t={};function __webpack_require__(n){var o=t[n];if(void 0!==o)return o.exports;var c=t[n]={exports:{}};return e[n](c,c.exports,__webpack_require__),c.exports}__webpack_require__.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return __webpack_require__.d(t,{a:t}),t},__webpack_require__.d=function(e,t){for(var n in t)__webpack_require__.o(t,n)&&!__webpack_require__.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},__webpack_require__.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},__webpack_require__.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var n={};!function(){__webpack_require__.r(n),__webpack_require__.d(n,{COMPONENT_DOCUMENT_TYPE:function(){return r.COMPONENT_DOCUMENT_TYPE},__useActiveDocument:function(){return t.useActiveDocument},__useActiveDocumentActions:function(){return t.useActiveDocumentActions},__useHostDocument:function(){return t.useHostDocument},__useNavigateToDocument:function(){return t.useNavigateToDocument},__useOpenDocumentInNewTab:function(){return t.useOpenDocumentInNewTab},getCurrentDocument:function(){return c.getCurrentDocument},getV1CurrentDocument:function(){return s.getV1CurrentDocument},getV1DocumentsManager:function(){return s.getV1DocumentsManager},init:function(){return e.init},invalidateDocumentData:function(){return s.invalidateDocumentData},isDocumentDirty:function(){return s.isDocumentDirty},reloadCurrentDocument:function(){return s.reloadCurrentDocument},setDocumentModifiedStatus:function(){return s.setDocumentModifiedStatus},slice:function(){return o.slice},switchToDocument:function(){return s.switchToDocument}});var e=__webpack_require__("./packages/packages/core/editor-documents/src/init.ts"),t=__webpack_require__("./packages/packages/core/editor-documents/src/hooks/index.ts"),o=__webpack_require__("./packages/packages/core/editor-documents/src/store/index.ts"),c=__webpack_require__("./packages/packages/core/editor-documents/src/store/get-current-document.ts"),s=__webpack_require__("./packages/packages/core/editor-documents/src/sync/utils.ts"),r=__webpack_require__("./packages/packages/core/editor-documents/src/consts.ts");__webpack_require__("./packages/packages/core/editor-documents/src/types.ts")}(),(window.elementorV2=window.elementorV2||{}).editorDocuments=n}(),window.elementorV2.editorDocuments?.init?.();
1 +(function(_elementor_editor, _elementor_store, react, _wordpress_i18n, _elementor_editor_v1_adapters, _elementor_utils) {
2 +
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 + };
22 +
23 +//#endregion
24 +
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);
31 +
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 + }
37 +
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 + }
43 +
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 + }
56 +
57 +//#endregion
58 +//#region packages/packages/core/editor-documents/src/components/logic-hooks.tsx
59 + function LogicHooks() {
60 + useSyncDocumentTitle();
61 + return null;
62 + }
63 +
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 + });
122 +
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 + }
128 +
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 +
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 +
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 +
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 +
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 +
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 + }
347 +
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 + }
356 +
357 +//#endregion
358 +//#region packages/packages/core/editor-documents/src/consts.ts
359 + var COMPONENT_DOCUMENT_TYPE = "elementor_component";
360 +
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 +
382 +//#endregion
383 +//#region \0elementor-package-library-entry
384 + (window.elementorV2 = window.elementorV2 || {}).editorDocuments = src_exports;
385 +
386 +//#endregion
387 +})(elementorV2.editor, elementorV2.store, React, wp.i18n, elementorV2.editorV1Adapters, elementorV2.utils);
388 +window.elementorV2.editorDocuments?.init?.();
3 389 //# sourceMappingURL=editor-documents.js.map