| 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?.(); |
| 389 |
//# sourceMappingURL=editor-documents.js.map |