| 1 |
/******/ (function() { // webpackBootstrap |
| 2 |
/******/ "use strict"; |
| 3 |
/******/ // The require scope |
| 4 |
/******/ var __webpack_require__ = {}; |
| 5 |
/******/ |
| 6 |
/************************************************************************/ |
| 7 |
/******/ /* webpack/runtime/define property getters */ |
| 8 |
/******/ !function() { |
| 9 |
/******/ // define getter functions for harmony exports |
| 10 |
/******/ __webpack_require__.d = function(exports, definition) { |
| 11 |
/******/ for(var key in definition) { |
| 12 |
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { |
| 13 |
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); |
| 14 |
/******/ } |
| 15 |
/******/ } |
| 16 |
/******/ }; |
| 17 |
/******/ }(); |
| 18 |
/******/ |
| 19 |
/******/ /* webpack/runtime/hasOwnProperty shorthand */ |
| 20 |
/******/ !function() { |
| 21 |
/******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); } |
| 22 |
/******/ }(); |
| 23 |
/******/ |
| 24 |
/******/ /* webpack/runtime/make namespace object */ |
| 25 |
/******/ !function() { |
| 26 |
/******/ // define __esModule on exports |
| 27 |
/******/ __webpack_require__.r = function(exports) { |
| 28 |
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { |
| 29 |
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); |
| 30 |
/******/ } |
| 31 |
/******/ Object.defineProperty(exports, '__esModule', { value: true }); |
| 32 |
/******/ }; |
| 33 |
/******/ }(); |
| 34 |
/******/ |
| 35 |
/************************************************************************/ |
| 36 |
var __webpack_exports__ = {}; |
| 37 |
// ESM COMPAT FLAG |
| 38 |
__webpack_require__.r(__webpack_exports__); |
| 39 |
|
| 40 |
// EXPORTS |
| 41 |
__webpack_require__.d(__webpack_exports__, { |
| 42 |
"useActiveDocument": function() { return /* reexport */ useActiveDocument; }, |
| 43 |
"useActiveDocumentActions": function() { return /* reexport */ useActiveDocumentActions; }, |
| 44 |
"useHostDocument": function() { return /* reexport */ useHostDocument; } |
| 45 |
}); |
| 46 |
|
| 47 |
;// CONCATENATED MODULE: external "__UNSTABLE__elementorPackages.store" |
| 48 |
var external_UNSTABLE_elementorPackages_store_namespaceObject = __UNSTABLE__elementorPackages.store; |
| 49 |
;// CONCATENATED MODULE: ./packages/documents/src/sync/utils.ts |
| 50 |
function getV1DocumentsManager() { |
| 51 |
const documentsManager = window.elementor?.documents; |
| 52 |
if (!documentsManager) { |
| 53 |
throw new Error('Elementor Editor V1 documents manager not found'); |
| 54 |
} |
| 55 |
return documentsManager; |
| 56 |
} |
| 57 |
function normalizeV1Document(documentData) { |
| 58 |
// Draft or autosave. |
| 59 |
const isUnpublishedRevision = documentData.config.revisions.current_id !== documentData.id; |
| 60 |
return { |
| 61 |
id: documentData.id, |
| 62 |
title: documentData.container.settings.get('post_title'), |
| 63 |
type: { |
| 64 |
value: documentData.config.type, |
| 65 |
label: documentData.config.panel.title |
| 66 |
}, |
| 67 |
status: { |
| 68 |
value: documentData.config.status.value, |
| 69 |
label: documentData.config.status.label |
| 70 |
}, |
| 71 |
isDirty: documentData.editor.isChanged || isUnpublishedRevision, |
| 72 |
isSaving: documentData.editor.isSaving, |
| 73 |
isSavingDraft: false, |
| 74 |
userCan: { |
| 75 |
publish: documentData.config.user.can_publish |
| 76 |
} |
| 77 |
}; |
| 78 |
} |
| 79 |
;// CONCATENATED MODULE: external "__UNSTABLE__elementorPackages.v1Adapters" |
| 80 |
var external_UNSTABLE_elementorPackages_v1Adapters_namespaceObject = __UNSTABLE__elementorPackages.v1Adapters; |
| 81 |
;// CONCATENATED MODULE: ./packages/documents/src/sync/sync-store.ts |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
function syncStore(slice) { |
| 86 |
syncInitialization(slice); |
| 87 |
syncActiveDocument(slice); |
| 88 |
syncOnDocumentSave(slice); |
| 89 |
syncOnDocumentChange(slice); |
| 90 |
} |
| 91 |
function syncInitialization(slice) { |
| 92 |
const { |
| 93 |
init |
| 94 |
} = slice.actions; |
| 95 |
(0,external_UNSTABLE_elementorPackages_v1Adapters_namespaceObject.listenTo)((0,external_UNSTABLE_elementorPackages_v1Adapters_namespaceObject.v1ReadyEvent)(), () => { |
| 96 |
const documentsManager = getV1DocumentsManager(); |
| 97 |
const entities = Object.entries(documentsManager.documents).reduce((acc, [id, document]) => { |
| 98 |
acc[id] = normalizeV1Document(document); |
| 99 |
return acc; |
| 100 |
}, {}); |
| 101 |
(0,external_UNSTABLE_elementorPackages_store_namespaceObject.dispatch)(init({ |
| 102 |
entities, |
| 103 |
hostId: documentsManager.getInitialId(), |
| 104 |
activeId: documentsManager.getCurrentId() |
| 105 |
})); |
| 106 |
}); |
| 107 |
} |
| 108 |
function syncActiveDocument(slice) { |
| 109 |
const { |
| 110 |
activateDocument |
| 111 |
} = slice.actions; |
| 112 |
(0,external_UNSTABLE_elementorPackages_v1Adapters_namespaceObject.listenTo)((0,external_UNSTABLE_elementorPackages_v1Adapters_namespaceObject.commandEndEvent)('editor/documents/open'), () => { |
| 113 |
const documentsManager = getV1DocumentsManager(); |
| 114 |
const currentDocument = normalizeV1Document(documentsManager.getCurrent()); |
| 115 |
(0,external_UNSTABLE_elementorPackages_store_namespaceObject.dispatch)(activateDocument(currentDocument)); |
| 116 |
}); |
| 117 |
} |
| 118 |
function syncOnDocumentSave(slice) { |
| 119 |
const { |
| 120 |
startSaving, |
| 121 |
endSaving, |
| 122 |
startSavingDraft, |
| 123 |
endSavingDraft |
| 124 |
} = slice.actions; |
| 125 |
const isDraft = e => { |
| 126 |
const event = e; |
| 127 |
|
| 128 |
/** |
| 129 |
* @see https://github.com/elementor/elementor/blob/5f815d40a/assets/dev/js/editor/document/save/hooks/ui/save/before.js#L18-L22 |
| 130 |
*/ |
| 131 |
return event.args?.status === 'autosave'; |
| 132 |
}; |
| 133 |
(0,external_UNSTABLE_elementorPackages_v1Adapters_namespaceObject.listenTo)((0,external_UNSTABLE_elementorPackages_v1Adapters_namespaceObject.commandStartEvent)('document/save/save'), e => { |
| 134 |
if (isDraft(e)) { |
| 135 |
(0,external_UNSTABLE_elementorPackages_store_namespaceObject.dispatch)(startSavingDraft()); |
| 136 |
return; |
| 137 |
} |
| 138 |
(0,external_UNSTABLE_elementorPackages_store_namespaceObject.dispatch)(startSaving()); |
| 139 |
}); |
| 140 |
(0,external_UNSTABLE_elementorPackages_v1Adapters_namespaceObject.listenTo)((0,external_UNSTABLE_elementorPackages_v1Adapters_namespaceObject.commandEndEvent)('document/save/save'), e => { |
| 141 |
const activeDocument = normalizeV1Document(getV1DocumentsManager().getCurrent()); |
| 142 |
if (isDraft(e)) { |
| 143 |
(0,external_UNSTABLE_elementorPackages_store_namespaceObject.dispatch)(endSavingDraft(activeDocument)); |
| 144 |
} else { |
| 145 |
(0,external_UNSTABLE_elementorPackages_store_namespaceObject.dispatch)(endSaving(activeDocument)); |
| 146 |
} |
| 147 |
}); |
| 148 |
} |
| 149 |
function syncOnDocumentChange(slice) { |
| 150 |
const { |
| 151 |
markAsDirty, |
| 152 |
markAsPristine |
| 153 |
} = slice.actions; |
| 154 |
(0,external_UNSTABLE_elementorPackages_v1Adapters_namespaceObject.listenTo)((0,external_UNSTABLE_elementorPackages_v1Adapters_namespaceObject.commandEndEvent)('document/save/set-is-modified'), () => { |
| 155 |
const currentDocument = getV1DocumentsManager().getCurrent(); |
| 156 |
if (currentDocument.editor.isChanged) { |
| 157 |
(0,external_UNSTABLE_elementorPackages_store_namespaceObject.dispatch)(markAsDirty()); |
| 158 |
return; |
| 159 |
} |
| 160 |
(0,external_UNSTABLE_elementorPackages_store_namespaceObject.dispatch)(markAsPristine()); |
| 161 |
}); |
| 162 |
} |
| 163 |
;// CONCATENATED MODULE: ./packages/documents/src/sync/index.ts |
| 164 |
|
| 165 |
;// CONCATENATED MODULE: ./packages/documents/src/store/index.ts |
| 166 |
|
| 167 |
const initialState = { |
| 168 |
entities: {}, |
| 169 |
activeId: null, |
| 170 |
hostId: null |
| 171 |
}; |
| 172 |
function hasActiveEntity(state) { |
| 173 |
return !!(state.activeId && state.entities[state.activeId]); |
| 174 |
} |
| 175 |
function createSlice() { |
| 176 |
return (0,external_UNSTABLE_elementorPackages_store_namespaceObject.addSlice)({ |
| 177 |
name: 'documents', |
| 178 |
initialState, |
| 179 |
reducers: { |
| 180 |
init(state, { |
| 181 |
payload |
| 182 |
}) { |
| 183 |
state.entities = payload.entities; |
| 184 |
state.hostId = payload.hostId; |
| 185 |
state.activeId = payload.activeId; |
| 186 |
}, |
| 187 |
activateDocument(state, action) { |
| 188 |
state.entities[action.payload.id] = action.payload; |
| 189 |
state.activeId = action.payload.id; |
| 190 |
}, |
| 191 |
startSaving(state) { |
| 192 |
if (hasActiveEntity(state)) { |
| 193 |
state.entities[state.activeId].isSaving = true; |
| 194 |
} |
| 195 |
}, |
| 196 |
endSaving(state, action) { |
| 197 |
if (hasActiveEntity(state)) { |
| 198 |
state.entities[state.activeId] = { |
| 199 |
...action.payload, |
| 200 |
isSaving: false |
| 201 |
}; |
| 202 |
} |
| 203 |
}, |
| 204 |
startSavingDraft: state => { |
| 205 |
if (hasActiveEntity(state)) { |
| 206 |
state.entities[state.activeId].isSavingDraft = true; |
| 207 |
} |
| 208 |
}, |
| 209 |
endSavingDraft(state, action) { |
| 210 |
if (hasActiveEntity(state)) { |
| 211 |
state.entities[state.activeId] = { |
| 212 |
...action.payload, |
| 213 |
isSavingDraft: false |
| 214 |
}; |
| 215 |
} |
| 216 |
}, |
| 217 |
markAsDirty(state) { |
| 218 |
if (hasActiveEntity(state)) { |
| 219 |
state.entities[state.activeId].isDirty = true; |
| 220 |
} |
| 221 |
}, |
| 222 |
markAsPristine(state) { |
| 223 |
if (hasActiveEntity(state)) { |
| 224 |
state.entities[state.activeId].isDirty = false; |
| 225 |
} |
| 226 |
} |
| 227 |
} |
| 228 |
}); |
| 229 |
} |
| 230 |
;// CONCATENATED MODULE: ./packages/documents/src/init.ts |
| 231 |
|
| 232 |
|
| 233 |
function init() { |
| 234 |
initStore(); |
| 235 |
} |
| 236 |
function initStore() { |
| 237 |
const slice = createSlice(); |
| 238 |
syncStore(slice); |
| 239 |
} |
| 240 |
;// CONCATENATED MODULE: ./packages/documents/src/store/selectors.ts |
| 241 |
|
| 242 |
const selectEntities = state => state.documents.entities; |
| 243 |
const selectActiveId = state => state.documents.activeId; |
| 244 |
const selectHostId = state => state.documents.hostId; |
| 245 |
const selectActiveDocument = (0,external_UNSTABLE_elementorPackages_store_namespaceObject.createSelector)(selectEntities, selectActiveId, (entities, activeId) => activeId && entities[activeId] ? entities[activeId] : null); |
| 246 |
const selectHostDocument = (0,external_UNSTABLE_elementorPackages_store_namespaceObject.createSelector)(selectEntities, selectHostId, (entities, hostId) => hostId && entities[hostId] ? entities[hostId] : null); |
| 247 |
;// CONCATENATED MODULE: ./packages/documents/src/hooks/use-active-document.ts |
| 248 |
|
| 249 |
|
| 250 |
function useActiveDocument() { |
| 251 |
return (0,external_UNSTABLE_elementorPackages_store_namespaceObject.useSelector)(selectActiveDocument); |
| 252 |
} |
| 253 |
;// CONCATENATED MODULE: external "React" |
| 254 |
var external_React_namespaceObject = React; |
| 255 |
;// CONCATENATED MODULE: ./packages/documents/src/hooks/use-active-document-actions.ts |
| 256 |
|
| 257 |
|
| 258 |
function useActiveDocumentActions() { |
| 259 |
const save = (0,external_React_namespaceObject.useCallback)(() => (0,external_UNSTABLE_elementorPackages_v1Adapters_namespaceObject.runCommand)('document/save/default'), []); |
| 260 |
const saveDraft = (0,external_React_namespaceObject.useCallback)(() => (0,external_UNSTABLE_elementorPackages_v1Adapters_namespaceObject.runCommand)('document/save/draft'), []); |
| 261 |
const saveTemplate = (0,external_React_namespaceObject.useCallback)(() => (0,external_UNSTABLE_elementorPackages_v1Adapters_namespaceObject.openRoute)('library/save-template'), []); |
| 262 |
return { |
| 263 |
save, |
| 264 |
saveDraft, |
| 265 |
saveTemplate |
| 266 |
}; |
| 267 |
} |
| 268 |
;// CONCATENATED MODULE: ./packages/documents/src/hooks/use-host-document.ts |
| 269 |
|
| 270 |
|
| 271 |
function useHostDocument() { |
| 272 |
return (0,external_UNSTABLE_elementorPackages_store_namespaceObject.useSelector)(selectHostDocument); |
| 273 |
} |
| 274 |
;// CONCATENATED MODULE: ./packages/documents/src/hooks/index.ts |
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
;// CONCATENATED MODULE: ./packages/documents/src/index.ts |
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
init(); |
| 283 |
(window.__UNSTABLE__elementorPackages = window.__UNSTABLE__elementorPackages || {}).documents = __webpack_exports__; |
| 284 |
/******/ })() |
| 285 |
; |