PluginProbe
Elementor Website Builder – more than just a page builder / 3.14.0-beta5
Elementor Website Builder – more than just a page builder v3.14.0-beta5
4.3.3 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 All 456 releases
elementor / assets / js / packages / editor-documents.js

editor-documents.js in Elementor Website Builder – more than just a page builder 3.14.0-beta5, at assets/js/packages/editor-documents.js

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