| 1 |
(function(_elementor_editor_v1_adapters, _elementor_session, _elementor_editor_props, _wordpress_i18n, _elementor_utils, _elementor_editor_styles) { |
| 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/libs/editor-elements/src/sync/get-container.ts |
| 26 |
function getContainer(id) { |
| 27 |
return window.elementor?.getContainer?.(id) ?? null; |
| 28 |
} |
| 29 |
var selectElement = (elementId) => { |
| 30 |
try { |
| 31 |
(0, _elementor_editor_v1_adapters.__privateRunCommand)("document/elements/select", { container: getContainer(elementId) }); |
| 32 |
} catch {} |
| 33 |
}; |
| 34 |
|
| 35 |
//#endregion |
| 36 |
//#region packages/packages/libs/editor-elements/src/sync/resolve-element.ts |
| 37 |
function isConnected(container) { |
| 38 |
if (!container) return false; |
| 39 |
if (!container.view?.el) return true; |
| 40 |
return container.view.el.isConnected; |
| 41 |
} |
| 42 |
function resolveContainer(container, id) { |
| 43 |
const looked = container.lookup?.(); |
| 44 |
if (isConnected(looked)) return looked; |
| 45 |
const byId = getContainer(id); |
| 46 |
if (isConnected(byId)) return byId; |
| 47 |
return null; |
| 48 |
} |
| 49 |
function getDocumentUtils() { |
| 50 |
return window.$e?.components?.get?.("document")?.utils; |
| 51 |
} |
| 52 |
function findModelInDocument(id) { |
| 53 |
return getDocumentUtils()?.findModelById?.(id) ?? null; |
| 54 |
} |
| 55 |
function addModelToParent(parentId, childData, options) { |
| 56 |
return getDocumentUtils()?.addModelToParent?.(parentId, childData, options) ?? false; |
| 57 |
} |
| 58 |
function removeModelFromParent(parentId, childId) { |
| 59 |
return getDocumentUtils()?.removeModelFromParent?.(parentId, childId) ?? false; |
| 60 |
} |
| 61 |
|
| 62 |
//#endregion |
| 63 |
//#region packages/packages/libs/editor-elements/src/sync/resolve-insert-index.ts |
| 64 |
function resolveInsertIndex(position, elements) { |
| 65 |
const lastIndex = elements.length; |
| 66 |
switch (position.kind) { |
| 67 |
case "first": return 0; |
| 68 |
case "last": return lastIndex; |
| 69 |
case "index": { |
| 70 |
const index = typeof position.value === "number" ? position.value : lastIndex; |
| 71 |
return Math.max(0, Math.min(index, lastIndex)); |
| 72 |
} |
| 73 |
case "after_type": { |
| 74 |
const anchor = elements.findIndex((element) => element.elType === position.value); |
| 75 |
return anchor >= 0 ? anchor + 1 : lastIndex; |
| 76 |
} |
| 77 |
case "before_type": { |
| 78 |
const anchor = elements.findIndex((element) => element.elType === position.value); |
| 79 |
return anchor >= 0 ? anchor : lastIndex; |
| 80 |
} |
| 81 |
default: return lastIndex; |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
//#endregion |
| 86 |
//#region packages/packages/libs/editor-elements/src/children-dependencies/stash.ts |
| 87 |
var STASH_KEY_PREFIX = "elementor/editor-state"; |
| 88 |
var STASH_KEY_SEGMENT = "children-deps"; |
| 89 |
function createChildrenStash() { |
| 90 |
return { |
| 91 |
get(elementId, childType) { |
| 92 |
return (0, _elementor_session.getSessionStorageItem)(buildStashKey(elementId, childType)); |
| 93 |
}, |
| 94 |
save(elementId, childType, data) { |
| 95 |
(0, _elementor_session.setSessionStorageItem)(buildStashKey(elementId, childType), data); |
| 96 |
}, |
| 97 |
clear(elementId, childType) { |
| 98 |
(0, _elementor_session.removeSessionStorageItem)(buildStashKey(elementId, childType)); |
| 99 |
}, |
| 100 |
clearAllForElement(elementId) { |
| 101 |
const prefix = buildElementStashPrefix(elementId); |
| 102 |
for (let index = sessionStorage.length - 1; index >= 0; index--) { |
| 103 |
const key = sessionStorage.key(index); |
| 104 |
if (key?.startsWith(prefix)) (0, _elementor_session.removeSessionStorageItem)(key); |
| 105 |
} |
| 106 |
} |
| 107 |
}; |
| 108 |
} |
| 109 |
function buildStashKey(elementId, childType) { |
| 110 |
return `${STASH_KEY_PREFIX}/${elementId}/${STASH_KEY_SEGMENT}/${childType}`; |
| 111 |
} |
| 112 |
function buildElementStashPrefix(elementId) { |
| 113 |
return `${STASH_KEY_PREFIX}/${elementId}/${STASH_KEY_SEGMENT}/`; |
| 114 |
} |
| 115 |
|
| 116 |
//#endregion |
| 117 |
//#region packages/packages/libs/editor-elements/src/sync/generate-element-id.ts |
| 118 |
var generateElementId = () => { |
| 119 |
return window.elementorCommon?.helpers?.getUniqueId?.() ?? `el-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`; |
| 120 |
}; |
| 121 |
|
| 122 |
//#endregion |
| 123 |
//#region packages/packages/libs/editor-elements/src/children-dependencies/utils.ts |
| 124 |
function evaluateWhen(when, settings) { |
| 125 |
return (0, _elementor_editor_props.isDependencyMet)(when, settings).isMet; |
| 126 |
} |
| 127 |
function ensureModelId(model) { |
| 128 |
const { skipDefaultChildren: _skipDefaultChildren, ...rest } = model; |
| 129 |
return rest.id ? rest : { |
| 130 |
...rest, |
| 131 |
id: generateElementId() |
| 132 |
}; |
| 133 |
} |
| 134 |
function resolveChildModelData(elementId, rule, stash) { |
| 135 |
const stashed = rule.stash ? stash.get(elementId, rule.child_type) : void 0; |
| 136 |
return { |
| 137 |
modelData: ensureModelId(stashed ?? rule.default_model ?? { elType: rule.child_type }), |
| 138 |
wasStashed: Boolean(stashed) |
| 139 |
}; |
| 140 |
} |
| 141 |
|
| 142 |
//#endregion |
| 143 |
//#region packages/packages/libs/editor-elements/src/children-dependencies/bind-settings-reconcile.ts |
| 144 |
function bindSettingsReconcile({ model, elementConfig }) { |
| 145 |
const stash = createChildrenStash(); |
| 146 |
const rules = elementConfig?.children_dependencies; |
| 147 |
if (!rules?.length) return () => {}; |
| 148 |
const settingsModel = model.get("settings"); |
| 149 |
const elementId = model.get("id"); |
| 150 |
if (!settingsModel?.on || !settingsModel?.off || !elementId) return () => {}; |
| 151 |
const lastMet = /* @__PURE__ */ new Map(); |
| 152 |
rules.forEach((rule) => { |
| 153 |
lastMet.set(rule.child_type, evaluateWhen(rule.when, settingsModel.toJSON())); |
| 154 |
}); |
| 155 |
const onChange = () => { |
| 156 |
const currentSettings = settingsModel.toJSON(); |
| 157 |
rules.forEach((rule) => { |
| 158 |
const previous = lastMet.get(rule.child_type) ?? false; |
| 159 |
const current = evaluateWhen(rule.when, currentSettings); |
| 160 |
if (previous === current) return; |
| 161 |
lastMet.set(rule.child_type, current); |
| 162 |
if (current) attachChildFromRule(elementId, rule, stash); |
| 163 |
else detachChildFromRule(elementId, rule, stash); |
| 164 |
}); |
| 165 |
}; |
| 166 |
settingsModel.on("change", onChange); |
| 167 |
return () => { |
| 168 |
settingsModel.off?.("change", onChange); |
| 169 |
stash.clearAllForElement(elementId); |
| 170 |
}; |
| 171 |
} |
| 172 |
function attachChildFromRule(parentId, rule, stash) { |
| 173 |
const currentChildren = getDirectChildData(getContainer(parentId) ?? void 0); |
| 174 |
if (currentChildren.some((child) => child.elType === rule.child_type)) return; |
| 175 |
const { modelData, wasStashed } = resolveChildModelData(parentId, rule, stash); |
| 176 |
if (!addModelToParent(parentId, modelData, { at: resolveInsertIndex(rule.position, currentChildren) })) return; |
| 177 |
if (wasStashed) stash.clear(parentId, rule.child_type); |
| 178 |
requestNavigatorRefresh(parentId); |
| 179 |
} |
| 180 |
function detachChildFromRule(parentId, rule, stash) { |
| 181 |
const child = (getContainer(parentId) ?? void 0)?.children?.find((candidate) => candidate.model.get("elType") === rule.child_type); |
| 182 |
if (!child) return; |
| 183 |
const childSnapshot = child.model.toJSON(); |
| 184 |
if (!removeModelFromParent(parentId, child.id)) return; |
| 185 |
if (rule.stash) stash.save(parentId, rule.child_type, childSnapshot); |
| 186 |
requestNavigatorRefresh(parentId); |
| 187 |
} |
| 188 |
function requestNavigatorRefresh(parentId) { |
| 189 |
if (typeof window === "undefined" || typeof window.dispatchEvent !== "function") return; |
| 190 |
window.dispatchEvent(new CustomEvent("elementor/navigator/refresh-children", { detail: { elementId: parentId } })); |
| 191 |
} |
| 192 |
function getDirectChildData(parent) { |
| 193 |
return (parent?.children ?? []).map((child) => child.model.toJSON()); |
| 194 |
} |
| 195 |
|
| 196 |
//#endregion |
| 197 |
//#region packages/packages/libs/editor-elements/src/children-dependencies/reconcile-initial-children.ts |
| 198 |
function reconcileInitialChildren({ elementId, elementConfig, attributes }) { |
| 199 |
const stash = createChildrenStash(); |
| 200 |
const rules = elementConfig?.children_dependencies; |
| 201 |
if (!rules?.length) return; |
| 202 |
const elements = [...attributes.elements ?? []]; |
| 203 |
const settings = attributes.settings ?? {}; |
| 204 |
rules.forEach((rule) => { |
| 205 |
const isMet = evaluateWhen(rule.when, settings); |
| 206 |
const existingIndex = elements.findIndex((element) => element.elType === rule.child_type); |
| 207 |
const isPresent = existingIndex >= 0; |
| 208 |
if (isMet && !isPresent) { |
| 209 |
const { modelData, wasStashed } = resolveChildModelData(elementId, rule, stash); |
| 210 |
const insertAt = resolveInsertIndex(rule.position, elements); |
| 211 |
elements.splice(insertAt, 0, modelData); |
| 212 |
if (wasStashed) stash.clear(elementId, rule.child_type); |
| 213 |
return; |
| 214 |
} |
| 215 |
if (!isMet && isPresent) { |
| 216 |
const [removed] = elements.splice(existingIndex, 1); |
| 217 |
if (rule.stash && removed) stash.save(elementId, rule.child_type, removed); |
| 218 |
} |
| 219 |
}); |
| 220 |
attributes.elements = elements; |
| 221 |
} |
| 222 |
|
| 223 |
//#endregion |
| 224 |
//#region packages/packages/libs/editor-elements/src/sync/model-utils.ts |
| 225 |
function findChildRecursive(model, predicate) { |
| 226 |
const childModels = model.get("elements") ?? []; |
| 227 |
for (const childModel of childModels) { |
| 228 |
if (predicate(childModel)) return { model: childModel }; |
| 229 |
const found = findChildRecursive(childModel, predicate); |
| 230 |
if (found) return found; |
| 231 |
} |
| 232 |
return null; |
| 233 |
} |
| 234 |
function getElementChildren(model, predicate) { |
| 235 |
return (model.get("elements") ?? []).filter((childModel) => !predicate || predicate(childModel)).map((childModel) => ({ model: childModel })); |
| 236 |
} |
| 237 |
|
| 238 |
//#endregion |
| 239 |
//#region packages/packages/libs/editor-elements/src/hooks/use-element-children.ts |
| 240 |
function toElementModel({ model }) { |
| 241 |
return { |
| 242 |
id: model.get("id"), |
| 243 |
editorSettings: model.get("editor_settings") ?? {} |
| 244 |
}; |
| 245 |
} |
| 246 |
function useElementChildren(elementId, childrenTypes, { includeSelfAsParent = false } = {}) { |
| 247 |
return (0, _elementor_editor_v1_adapters.__privateUseListenTo)([ |
| 248 |
(0, _elementor_editor_v1_adapters.v1ReadyEvent)(), |
| 249 |
(0, _elementor_editor_v1_adapters.commandEndEvent)("document/elements/create"), |
| 250 |
(0, _elementor_editor_v1_adapters.commandEndEvent)("document/elements/delete"), |
| 251 |
(0, _elementor_editor_v1_adapters.commandEndEvent)("document/elements/update"), |
| 252 |
(0, _elementor_editor_v1_adapters.commandEndEvent)("document/elements/set-settings") |
| 253 |
], () => { |
| 254 |
const model = getContainer(elementId)?.model; |
| 255 |
if (!model) return {}; |
| 256 |
return Object.entries(childrenTypes).reduce((acc, [parentType, childType]) => { |
| 257 |
const parent = includeSelfAsParent && model.get("elType") === parentType ? { model } : findChildRecursive(model, (m) => m.get("elType") === parentType); |
| 258 |
if (!parent) { |
| 259 |
acc[childType] = []; |
| 260 |
return acc; |
| 261 |
} |
| 262 |
acc[childType] = getElementChildren(parent.model, (m) => m.get("elType") === childType).map(toElementModel); |
| 263 |
return acc; |
| 264 |
}, {}); |
| 265 |
}, [elementId]); |
| 266 |
} |
| 267 |
|
| 268 |
//#endregion |
| 269 |
//#region packages/packages/libs/editor-elements/src/sync/get-element-editor-settings.ts |
| 270 |
function getElementEditorSettings(elementId) { |
| 271 |
return getContainer(elementId)?.model.get("editor_settings") ?? {}; |
| 272 |
} |
| 273 |
|
| 274 |
//#endregion |
| 275 |
//#region packages/packages/libs/editor-elements/src/hooks/use-element-editor-settings.ts |
| 276 |
var useElementEditorSettings = (elementId) => { |
| 277 |
return (0, _elementor_editor_v1_adapters.__privateUseListenTo)((0, _elementor_editor_v1_adapters.windowEvent)("elementor/element/update_editor_settings"), () => getElementEditorSettings(elementId), [elementId]); |
| 278 |
}; |
| 279 |
|
| 280 |
//#endregion |
| 281 |
//#region packages/packages/libs/editor-elements/src/hooks/use-parent-element.ts |
| 282 |
function useParentElement(elementId) { |
| 283 |
return (0, _elementor_editor_v1_adapters.__privateUseListenTo)([(0, _elementor_editor_v1_adapters.commandEndEvent)("document/elements/create")], () => { |
| 284 |
if (!elementId) return null; |
| 285 |
const element = window?.elementor?.getContainer?.(elementId); |
| 286 |
if (!element) return null; |
| 287 |
return element.parent; |
| 288 |
}, [elementId]); |
| 289 |
} |
| 290 |
|
| 291 |
//#endregion |
| 292 |
//#region packages/packages/libs/editor-elements/src/sync/get-widgets-cache.ts |
| 293 |
function getWidgetsCache() { |
| 294 |
return window?.elementor?.widgetsCache || null; |
| 295 |
} |
| 296 |
|
| 297 |
//#endregion |
| 298 |
//#region packages/packages/libs/editor-elements/src/sync/get-element-type.ts |
| 299 |
function getElementType(type) { |
| 300 |
if (!type) return null; |
| 301 |
const elementType = getWidgetsCache()?.[type]; |
| 302 |
if (!elementType?.atomic_controls) return null; |
| 303 |
if (!elementType?.atomic_props_schema) return null; |
| 304 |
return { |
| 305 |
key: type, |
| 306 |
controls: elementType.atomic_controls, |
| 307 |
propsSchema: elementType.atomic_props_schema, |
| 308 |
dependenciesPerTargetMapping: elementType.dependencies_per_target_mapping ?? {}, |
| 309 |
title: elementType.title, |
| 310 |
styleStates: elementType.atomic_style_states ?? [], |
| 311 |
pseudoStates: elementType.atomic_pseudo_states ?? [] |
| 312 |
}; |
| 313 |
} |
| 314 |
|
| 315 |
//#endregion |
| 316 |
//#region packages/packages/libs/editor-elements/src/sync/get-selected-elements.ts |
| 317 |
function getSelectedElements() { |
| 318 |
return (window.elementor?.selection?.getElements?.() ?? []).reduce((acc, el) => { |
| 319 |
const type = el.model.get("widgetType") || el.model.get("elType"); |
| 320 |
if (type) acc.push({ |
| 321 |
id: el.model.get("id"), |
| 322 |
type |
| 323 |
}); |
| 324 |
return acc; |
| 325 |
}, []); |
| 326 |
} |
| 327 |
function getSelectedElement() { |
| 328 |
const elements = getSelectedElements(); |
| 329 |
const [element] = elements; |
| 330 |
const elementType = getElementType(element?.type); |
| 331 |
if (elements.length !== 1 || !elementType || !element) return { |
| 332 |
element: null, |
| 333 |
elementType: null |
| 334 |
}; |
| 335 |
return { |
| 336 |
element, |
| 337 |
elementType |
| 338 |
}; |
| 339 |
} |
| 340 |
|
| 341 |
//#endregion |
| 342 |
//#region packages/packages/libs/editor-elements/src/hooks/use-selected-element.ts |
| 343 |
function useSelectedElement() { |
| 344 |
return (0, _elementor_editor_v1_adapters.__privateUseListenTo)([ |
| 345 |
(0, _elementor_editor_v1_adapters.commandEndEvent)("document/elements/select"), |
| 346 |
(0, _elementor_editor_v1_adapters.commandEndEvent)("document/elements/deselect"), |
| 347 |
(0, _elementor_editor_v1_adapters.commandEndEvent)("document/elements/select-all"), |
| 348 |
(0, _elementor_editor_v1_adapters.commandEndEvent)("document/elements/deselect-all") |
| 349 |
], getSelectedElement); |
| 350 |
} |
| 351 |
|
| 352 |
//#endregion |
| 353 |
//#region packages/packages/libs/editor-elements/src/sync/get-element-setting.ts |
| 354 |
var getElementSetting = (elementId, settingKey) => { |
| 355 |
return getContainer(elementId)?.settings?.get(settingKey) ?? null; |
| 356 |
}; |
| 357 |
var getElementSettings = (elementId, settingKey) => { |
| 358 |
return Object.fromEntries(settingKey.map((key) => [key, getElementSetting(elementId, key)])); |
| 359 |
}; |
| 360 |
|
| 361 |
//#endregion |
| 362 |
//#region packages/packages/libs/editor-elements/src/hooks/use-selected-element-settings.ts |
| 363 |
function useSelectedElementSettings() { |
| 364 |
return (0, _elementor_editor_v1_adapters.__privateUseListenTo)([ |
| 365 |
(0, _elementor_editor_v1_adapters.commandEndEvent)("document/elements/select"), |
| 366 |
(0, _elementor_editor_v1_adapters.commandEndEvent)("document/elements/deselect"), |
| 367 |
(0, _elementor_editor_v1_adapters.commandEndEvent)("document/elements/select-all"), |
| 368 |
(0, _elementor_editor_v1_adapters.commandEndEvent)("document/elements/deselect-all"), |
| 369 |
(0, _elementor_editor_v1_adapters.commandEndEvent)("document/elements/set-settings") |
| 370 |
], () => { |
| 371 |
const { element, elementType } = getSelectedElement(); |
| 372 |
if (!element || !elementType) return { |
| 373 |
element: null, |
| 374 |
elementType: null, |
| 375 |
settings: null |
| 376 |
}; |
| 377 |
return { |
| 378 |
element, |
| 379 |
elementType, |
| 380 |
settings: getElementSettings(element.id, Object.keys(elementType.propsSchema)) |
| 381 |
}; |
| 382 |
}); |
| 383 |
} |
| 384 |
|
| 385 |
//#endregion |
| 386 |
//#region packages/packages/libs/editor-elements/src/sync/create-element.ts |
| 387 |
function createElement({ container, model, options }) { |
| 388 |
return (0, _elementor_editor_v1_adapters.__privateRunCommandSync)("document/elements/create", { |
| 389 |
container, |
| 390 |
model, |
| 391 |
options: { |
| 392 |
edit: false, |
| 393 |
...options |
| 394 |
} |
| 395 |
}); |
| 396 |
} |
| 397 |
|
| 398 |
//#endregion |
| 399 |
//#region packages/packages/libs/editor-elements/src/sync/delete-element.ts |
| 400 |
function deleteElement({ container, options = {} }) { |
| 401 |
(0, _elementor_editor_v1_adapters.__privateRunCommandSync)("document/elements/delete", { |
| 402 |
container, |
| 403 |
options |
| 404 |
}); |
| 405 |
} |
| 406 |
|
| 407 |
//#endregion |
| 408 |
//#region packages/packages/libs/editor-elements/src/sync/create-elements.ts |
| 409 |
var createElements = ({ elements, title, subtitle = (0, _wordpress_i18n.__)("Item added", "elementor") }) => { |
| 410 |
return (0, _elementor_editor_v1_adapters.undoable)({ |
| 411 |
do: ({ elements: elementsParam }) => { |
| 412 |
const createdElements = []; |
| 413 |
elementsParam.forEach(({ container, options, ...elementParams }) => { |
| 414 |
const parentContainer = container.lookup?.() ?? container; |
| 415 |
if (!parentContainer) throw new Error("Parent container not found"); |
| 416 |
const element = createElement({ |
| 417 |
container: parentContainer, |
| 418 |
...elementParams, |
| 419 |
options: { |
| 420 |
...options, |
| 421 |
useHistory: false |
| 422 |
} |
| 423 |
}); |
| 424 |
createdElements.push({ |
| 425 |
container: element, |
| 426 |
parentContainer, |
| 427 |
model: element.model?.toJSON() || {}, |
| 428 |
options, |
| 429 |
containerId: element.id, |
| 430 |
parentContainerId: parentContainer.id |
| 431 |
}); |
| 432 |
}); |
| 433 |
return { createdElements }; |
| 434 |
}, |
| 435 |
undo: (_, { createdElements }) => { |
| 436 |
[...createdElements].reverse().forEach(({ container, containerId, parentContainerId }) => { |
| 437 |
const freshContainer = resolveContainer(container, containerId); |
| 438 |
if (freshContainer) { |
| 439 |
deleteElement({ |
| 440 |
container: freshContainer, |
| 441 |
options: { useHistory: false } |
| 442 |
}); |
| 443 |
return; |
| 444 |
} |
| 445 |
removeModelFromParent(parentContainerId, containerId); |
| 446 |
}); |
| 447 |
}, |
| 448 |
redo: (_, { createdElements }) => { |
| 449 |
const newElements = []; |
| 450 |
createdElements.forEach(({ parentContainer, parentContainerId, model, options }) => { |
| 451 |
const freshParent = resolveContainer(parentContainer, parentContainerId); |
| 452 |
if (freshParent) { |
| 453 |
const element = createElement({ |
| 454 |
container: freshParent, |
| 455 |
model, |
| 456 |
options: { |
| 457 |
...options, |
| 458 |
useHistory: false |
| 459 |
} |
| 460 |
}); |
| 461 |
newElements.push({ |
| 462 |
container: element, |
| 463 |
parentContainer: freshParent, |
| 464 |
model: element.model.toJSON(), |
| 465 |
options, |
| 466 |
containerId: element.id, |
| 467 |
parentContainerId: freshParent.id |
| 468 |
}); |
| 469 |
return; |
| 470 |
} |
| 471 |
addModelToParent(parentContainerId, model); |
| 472 |
newElements.push({ |
| 473 |
container: parentContainer, |
| 474 |
parentContainer, |
| 475 |
model, |
| 476 |
options, |
| 477 |
containerId: model.id ?? "", |
| 478 |
parentContainerId |
| 479 |
}); |
| 480 |
}); |
| 481 |
return { createdElements: newElements }; |
| 482 |
} |
| 483 |
}, { |
| 484 |
title, |
| 485 |
subtitle |
| 486 |
})({ elements }); |
| 487 |
}; |
| 488 |
|
| 489 |
//#endregion |
| 490 |
//#region packages/packages/libs/editor-elements/src/sync/drop-element.ts |
| 491 |
function dropElement({ containerId, model, options }) { |
| 492 |
const container = getContainer(containerId); |
| 493 |
if (!container) throw new Error(`Container with ID "${containerId}" not found`); |
| 494 |
return (0, _elementor_editor_v1_adapters.__privateRunCommandSync)("preview/drop", { |
| 495 |
container, |
| 496 |
model, |
| 497 |
options |
| 498 |
}); |
| 499 |
} |
| 500 |
|
| 501 |
//#endregion |
| 502 |
//#region packages/packages/libs/editor-elements/src/sync/duplicate-element.ts |
| 503 |
function duplicateElement({ element, options = {} }) { |
| 504 |
const currentIndex = element.view?._index ?? 0; |
| 505 |
return (0, _elementor_editor_v1_adapters.__privateRunCommandSync)("document/elements/duplicate", { |
| 506 |
container: element, |
| 507 |
options: { |
| 508 |
at: options.clone !== false ? currentIndex + 1 : void 0, |
| 509 |
edit: false, |
| 510 |
...options |
| 511 |
} |
| 512 |
}); |
| 513 |
} |
| 514 |
|
| 515 |
//#endregion |
| 516 |
//#region packages/packages/libs/editor-elements/src/sync/duplicate-elements.ts |
| 517 |
var duplicateElements = ({ elementIds, title, subtitle = (0, _wordpress_i18n.__)("Item duplicated", "elementor"), onDuplicateElements, onRestoreElements }) => { |
| 518 |
return (0, _elementor_editor_v1_adapters.undoable)({ |
| 519 |
do: ({ elementIds: elementIdsToDuplicate }) => { |
| 520 |
onDuplicateElements?.(); |
| 521 |
const duplicatedElements = []; |
| 522 |
elementIdsToDuplicate.forEach((elementId) => { |
| 523 |
const originalContainer = getContainer(elementId); |
| 524 |
if (!originalContainer?.parent) return; |
| 525 |
const duplicatedElement = duplicateElement({ |
| 526 |
element: originalContainer, |
| 527 |
options: { useHistory: false } |
| 528 |
}); |
| 529 |
if (!duplicatedElement.parent) return; |
| 530 |
duplicatedElements.push({ |
| 531 |
container: duplicatedElement, |
| 532 |
parentContainer: duplicatedElement.parent, |
| 533 |
model: duplicatedElement.model.toJSON(), |
| 534 |
at: duplicatedElement.view?._index, |
| 535 |
containerId: duplicatedElement.id, |
| 536 |
parentContainerId: duplicatedElement.parent.id |
| 537 |
}); |
| 538 |
}); |
| 539 |
return { duplicatedElements }; |
| 540 |
}, |
| 541 |
undo: (_, { duplicatedElements }) => { |
| 542 |
onRestoreElements?.(); |
| 543 |
[...duplicatedElements].reverse().forEach(({ container, containerId, parentContainerId }) => { |
| 544 |
const freshContainer = resolveContainer(container, containerId); |
| 545 |
if (freshContainer) { |
| 546 |
deleteElement({ |
| 547 |
container: freshContainer, |
| 548 |
options: { useHistory: false } |
| 549 |
}); |
| 550 |
return; |
| 551 |
} |
| 552 |
removeModelFromParent(parentContainerId, containerId); |
| 553 |
}); |
| 554 |
}, |
| 555 |
redo: (_, { duplicatedElements: previousElements }) => { |
| 556 |
onDuplicateElements?.(); |
| 557 |
const duplicatedElements = []; |
| 558 |
previousElements.forEach(({ parentContainer, parentContainerId, model, at }) => { |
| 559 |
const freshParent = resolveContainer(parentContainer, parentContainerId); |
| 560 |
if (freshParent) { |
| 561 |
const createdElement = createElement({ |
| 562 |
container: freshParent, |
| 563 |
model, |
| 564 |
options: { |
| 565 |
useHistory: false, |
| 566 |
clone: false, |
| 567 |
at |
| 568 |
} |
| 569 |
}); |
| 570 |
duplicatedElements.push({ |
| 571 |
container: createdElement, |
| 572 |
parentContainer: freshParent, |
| 573 |
model, |
| 574 |
at, |
| 575 |
containerId: createdElement.id, |
| 576 |
parentContainerId: freshParent.id |
| 577 |
}); |
| 578 |
return; |
| 579 |
} |
| 580 |
addModelToParent(parentContainerId, model, { at }); |
| 581 |
duplicatedElements.push({ |
| 582 |
container: parentContainer, |
| 583 |
parentContainer, |
| 584 |
model, |
| 585 |
at, |
| 586 |
containerId: model.id ?? "", |
| 587 |
parentContainerId |
| 588 |
}); |
| 589 |
}); |
| 590 |
return { duplicatedElements }; |
| 591 |
} |
| 592 |
}, { |
| 593 |
title, |
| 594 |
subtitle |
| 595 |
})({ elementIds }); |
| 596 |
}; |
| 597 |
|
| 598 |
//#endregion |
| 599 |
//#region packages/packages/libs/editor-elements/src/sync/get-preview-element-dom.ts |
| 600 |
function getPreviewElementDOM(id) { |
| 601 |
try { |
| 602 |
const fromContainer = getContainer(id)?.view?.el; |
| 603 |
if (fromContainer) return fromContainer; |
| 604 |
return queryPreviewDOMByElementId(id); |
| 605 |
} catch { |
| 606 |
return null; |
| 607 |
} |
| 608 |
} |
| 609 |
function queryPreviewDOMByElementId(id) { |
| 610 |
const previewDocument = window.elementor?.getPreviewContainer?.()?.view?.el?.ownerDocument; |
| 611 |
if (!previewDocument) return null; |
| 612 |
return previewDocument.querySelector(`[data-id="${id}"]`); |
| 613 |
} |
| 614 |
|
| 615 |
//#endregion |
| 616 |
//#region packages/packages/libs/editor-elements/src/sync/get-current-document-container.ts |
| 617 |
function getCurrentDocumentContainer() { |
| 618 |
return window.elementor?.documents?.getCurrent?.()?.container ?? null; |
| 619 |
} |
| 620 |
|
| 621 |
//#endregion |
| 622 |
//#region packages/packages/libs/editor-elements/src/sync/get-current-document-id.ts |
| 623 |
function getCurrentDocumentId() { |
| 624 |
const extendedWindow = window; |
| 625 |
try { |
| 626 |
return extendedWindow.elementor?.documents?.getCurrentId?.() ?? null; |
| 627 |
} catch { |
| 628 |
return null; |
| 629 |
} |
| 630 |
} |
| 631 |
|
| 632 |
//#endregion |
| 633 |
//#region packages/packages/libs/editor-elements/src/sync/get-element-icon.ts |
| 634 |
function getElementIcon(elementId) { |
| 635 |
const container = getContainer(elementId); |
| 636 |
const type = container?.model.get("widgetType") || container?.model.get("elType"); |
| 637 |
if (!type) return null; |
| 638 |
return getWidgetsCache()?.[type]?.icon ?? null; |
| 639 |
} |
| 640 |
|
| 641 |
//#endregion |
| 642 |
//#region packages/packages/libs/editor-elements/src/errors.ts |
| 643 |
var ElementNotFoundError = (0, _elementor_utils.createError)({ |
| 644 |
code: "element_not_found", |
| 645 |
message: "Element not found." |
| 646 |
}); |
| 647 |
var StyleNotFoundError = (0, _elementor_utils.createError)({ |
| 648 |
code: "style_not_found", |
| 649 |
message: "Style not found." |
| 650 |
}); |
| 651 |
var ElementTypeNotExistsError = (0, _elementor_utils.createError)({ |
| 652 |
code: "element_type_not_exists", |
| 653 |
message: "Element type does not exist." |
| 654 |
}); |
| 655 |
var ElementLabelNotExistsError = (0, _elementor_utils.createError)({ |
| 656 |
code: "element_label_not_exists", |
| 657 |
message: "Element label does not exist." |
| 658 |
}); |
| 659 |
var ElementParentNotFoundError = (0, _elementor_utils.createError)({ |
| 660 |
code: "element_parent_not_found", |
| 661 |
message: "Element parent not found." |
| 662 |
}); |
| 663 |
var ElementIndexNotFoundError = (0, _elementor_utils.createError)({ |
| 664 |
code: "element_index_not_found", |
| 665 |
message: "Element index not found." |
| 666 |
}); |
| 667 |
|
| 668 |
//#endregion |
| 669 |
//#region packages/packages/libs/editor-elements/src/sync/get-element-label.ts |
| 670 |
function getElementLabel(elementId) { |
| 671 |
if (!elementId) elementId = getSelectedElements()?.[0]?.id; |
| 672 |
const container = getContainer(elementId); |
| 673 |
const type = container?.model.get("widgetType") || container?.model.get("elType"); |
| 674 |
if (!type) throw new ElementTypeNotExistsError({ context: { elementId } }); |
| 675 |
const label = getWidgetsCache()?.[type]?.title; |
| 676 |
if (!label) throw new ElementLabelNotExistsError({ context: { elementType: type } }); |
| 677 |
return label; |
| 678 |
} |
| 679 |
|
| 680 |
//#endregion |
| 681 |
//#region packages/packages/libs/editor-elements/src/sync/get-element-title.ts |
| 682 |
function extractString(value) { |
| 683 |
if (typeof value === "string") return value || null; |
| 684 |
if (value && typeof value === "object" && "value" in value && typeof value.value === "string") return value.value || null; |
| 685 |
return null; |
| 686 |
} |
| 687 |
function getElementTitle(elementId) { |
| 688 |
const editorTitle = extractString(getElementEditorSettings(elementId)?.title); |
| 689 |
if (editorTitle) return editorTitle; |
| 690 |
const legacyTitle = extractString(getElementSetting(elementId, "_title")); |
| 691 |
if (legacyTitle) return legacyTitle; |
| 692 |
const presetTitle = extractString(getElementSetting(elementId, "presetTitle")); |
| 693 |
if (presetTitle) return presetTitle; |
| 694 |
try { |
| 695 |
return getElementLabel(elementId); |
| 696 |
} catch { |
| 697 |
return null; |
| 698 |
} |
| 699 |
} |
| 700 |
|
| 701 |
//#endregion |
| 702 |
//#region packages/packages/libs/editor-elements/src/sync/get-element-styles.ts |
| 703 |
var getElementStyles = (elementID) => { |
| 704 |
return getContainer(elementID)?.model.get("styles") || null; |
| 705 |
}; |
| 706 |
|
| 707 |
//#endregion |
| 708 |
//#region packages/packages/libs/editor-elements/src/sync/get-all-descendants.ts |
| 709 |
function getAllDescendants(container) { |
| 710 |
return [container, ...(container.children ?? []).flatMap((child) => getAllDescendants(child))]; |
| 711 |
} |
| 712 |
|
| 713 |
//#endregion |
| 714 |
//#region packages/packages/libs/editor-elements/src/sync/get-elements.ts |
| 715 |
function getElements(root) { |
| 716 |
const container = root ? getContainer(root) : getCurrentDocumentContainer(); |
| 717 |
if (!container) return []; |
| 718 |
return [container, ...[...container.model.get("elements") ?? []].flatMap((childModel) => getElements(childModel.get("id")))]; |
| 719 |
} |
| 720 |
|
| 721 |
//#endregion |
| 722 |
//#region packages/packages/libs/editor-elements/src/sync/move-element.ts |
| 723 |
function moveElement({ element, targetContainer, options = {} }) { |
| 724 |
const resolvedElement = element.lookup?.(); |
| 725 |
const resolvedTarget = targetContainer.lookup?.(); |
| 726 |
if (!resolvedElement) throw new Error(`Element not found: ${element.id}`); |
| 727 |
if (!resolvedTarget) throw new Error(`Target container not found: ${targetContainer.id}`); |
| 728 |
const modelToRecreate = resolvedElement.model.toJSON(); |
| 729 |
deleteElement({ |
| 730 |
container: resolvedElement, |
| 731 |
options: { |
| 732 |
...options, |
| 733 |
useHistory: false |
| 734 |
} |
| 735 |
}); |
| 736 |
return createElement({ |
| 737 |
container: resolvedTarget, |
| 738 |
model: modelToRecreate, |
| 739 |
options: { |
| 740 |
edit: false, |
| 741 |
...options, |
| 742 |
useHistory: false |
| 743 |
} |
| 744 |
}); |
| 745 |
} |
| 746 |
|
| 747 |
//#endregion |
| 748 |
//#region packages/packages/libs/editor-elements/src/sync/move-elements.ts |
| 749 |
var moveElements = ({ moves: movesToMake, title, subtitle = (0, _wordpress_i18n.__)("Elements moved", "elementor"), onMoveElements, onRestoreElements }) => { |
| 750 |
return (0, _elementor_editor_v1_adapters.undoable)({ |
| 751 |
do: ({ moves }) => { |
| 752 |
const movedElements = []; |
| 753 |
onMoveElements?.(); |
| 754 |
moves.forEach(({ element, targetContainer, options }) => { |
| 755 |
const sourceElement = element.lookup?.() ?? element; |
| 756 |
const target = targetContainer.lookup?.() ?? targetContainer; |
| 757 |
if (!sourceElement) throw new Error("Element not found"); |
| 758 |
if (!target) throw new Error("Target container not found"); |
| 759 |
if (!sourceElement.parent) throw new Error("Element has no parent container"); |
| 760 |
const originalContainer = sourceElement.parent; |
| 761 |
const originalIndex = originalContainer.children?.indexOf(sourceElement) ?? -1; |
| 762 |
const newElement = moveElement({ |
| 763 |
element: sourceElement, |
| 764 |
targetContainer: target, |
| 765 |
options: { |
| 766 |
...options, |
| 767 |
useHistory: false |
| 768 |
} |
| 769 |
}); |
| 770 |
movedElements.push({ |
| 771 |
element: newElement, |
| 772 |
originalContainer, |
| 773 |
originalIndex, |
| 774 |
targetContainer: target, |
| 775 |
options, |
| 776 |
elementId: newElement.id, |
| 777 |
originalContainerId: originalContainer.id, |
| 778 |
targetContainerId: target.id |
| 779 |
}); |
| 780 |
}); |
| 781 |
return { movedElements }; |
| 782 |
}, |
| 783 |
undo: (_, { movedElements }) => { |
| 784 |
onRestoreElements?.(); |
| 785 |
[...movedElements].reverse().forEach(({ element, elementId, originalContainer, originalContainerId, originalIndex }) => { |
| 786 |
const freshElement = resolveContainer(element, elementId); |
| 787 |
const freshOriginalContainer = resolveContainer(originalContainer, originalContainerId); |
| 788 |
if (!freshElement || !freshOriginalContainer) return; |
| 789 |
moveElement({ |
| 790 |
element: freshElement, |
| 791 |
targetContainer: freshOriginalContainer, |
| 792 |
options: { |
| 793 |
useHistory: false, |
| 794 |
at: originalIndex >= 0 ? originalIndex : void 0 |
| 795 |
} |
| 796 |
}); |
| 797 |
}); |
| 798 |
}, |
| 799 |
redo: (_, { movedElements }) => { |
| 800 |
const newMovedElements = []; |
| 801 |
onMoveElements?.(); |
| 802 |
movedElements.forEach(({ element, elementId, originalContainer, originalContainerId, originalIndex, targetContainer, targetContainerId, options }) => { |
| 803 |
const freshElement = resolveContainer(element, elementId); |
| 804 |
const freshOriginalContainer = resolveContainer(originalContainer, originalContainerId); |
| 805 |
const freshTarget = resolveContainer(targetContainer, targetContainerId); |
| 806 |
if (!freshElement || !freshOriginalContainer || !freshTarget) return; |
| 807 |
const newElement = moveElement({ |
| 808 |
element: freshElement, |
| 809 |
targetContainer: freshTarget, |
| 810 |
options: { |
| 811 |
...options, |
| 812 |
useHistory: false |
| 813 |
} |
| 814 |
}); |
| 815 |
newMovedElements.push({ |
| 816 |
element: newElement, |
| 817 |
originalContainer: freshOriginalContainer, |
| 818 |
originalIndex, |
| 819 |
targetContainer: freshTarget, |
| 820 |
options, |
| 821 |
elementId: newElement.id, |
| 822 |
originalContainerId: freshOriginalContainer.id, |
| 823 |
targetContainerId: freshTarget.id |
| 824 |
}); |
| 825 |
}); |
| 826 |
return { movedElements: newMovedElements }; |
| 827 |
} |
| 828 |
}, { |
| 829 |
title, |
| 830 |
subtitle |
| 831 |
})({ moves: movesToMake }); |
| 832 |
}; |
| 833 |
|
| 834 |
//#endregion |
| 835 |
//#region packages/packages/libs/editor-elements/src/sync/remove-elements.ts |
| 836 |
var removeElements = ({ elementIds, title, subtitle = (0, _wordpress_i18n.__)("Item removed", "elementor"), onRemoveElements, onRestoreElements }) => { |
| 837 |
return (0, _elementor_editor_v1_adapters.undoable)({ |
| 838 |
do: ({ elementIds: elementIdsParam }) => { |
| 839 |
const removedElements = []; |
| 840 |
elementIdsParam.forEach((elementId) => { |
| 841 |
const container = getContainer(elementId); |
| 842 |
if (container?.parent) removedElements.push({ |
| 843 |
container, |
| 844 |
parent: container.parent, |
| 845 |
model: container.model.toJSON(), |
| 846 |
at: container.view?._index ?? 0, |
| 847 |
containerId: container.id, |
| 848 |
parentId: container.parent.id |
| 849 |
}); |
| 850 |
}); |
| 851 |
onRemoveElements?.(); |
| 852 |
removedElements.forEach(({ container }) => { |
| 853 |
deleteElement({ |
| 854 |
container, |
| 855 |
options: { useHistory: false } |
| 856 |
}); |
| 857 |
}); |
| 858 |
return { removedElements }; |
| 859 |
}, |
| 860 |
undo: (_, { removedElements }) => { |
| 861 |
onRestoreElements?.(); |
| 862 |
[...removedElements].reverse().forEach(({ parent, parentId, model, at }) => { |
| 863 |
const freshParent = resolveContainer(parent, parentId); |
| 864 |
if (freshParent) { |
| 865 |
createElement({ |
| 866 |
container: freshParent, |
| 867 |
model, |
| 868 |
options: { |
| 869 |
useHistory: false, |
| 870 |
at |
| 871 |
} |
| 872 |
}); |
| 873 |
return; |
| 874 |
} |
| 875 |
addModelToParent(parentId, model, { at }); |
| 876 |
}); |
| 877 |
}, |
| 878 |
redo: (_, { removedElements }) => { |
| 879 |
onRemoveElements?.(); |
| 880 |
const newRemovedElements = []; |
| 881 |
removedElements.forEach(({ container, parent, model, at, containerId, parentId }) => { |
| 882 |
const freshContainer = resolveContainer(container, containerId); |
| 883 |
const freshParent = resolveContainer(parent, parentId); |
| 884 |
if (freshContainer && freshParent) { |
| 885 |
deleteElement({ |
| 886 |
container: freshContainer, |
| 887 |
options: { useHistory: false } |
| 888 |
}); |
| 889 |
newRemovedElements.push({ |
| 890 |
container: freshContainer, |
| 891 |
parent: freshParent, |
| 892 |
model, |
| 893 |
at, |
| 894 |
containerId, |
| 895 |
parentId |
| 896 |
}); |
| 897 |
return; |
| 898 |
} |
| 899 |
removeModelFromParent(parentId, containerId); |
| 900 |
newRemovedElements.push({ |
| 901 |
container, |
| 902 |
parent, |
| 903 |
model, |
| 904 |
at, |
| 905 |
containerId, |
| 906 |
parentId |
| 907 |
}); |
| 908 |
}); |
| 909 |
return { removedElements: newRemovedElements }; |
| 910 |
} |
| 911 |
}, { |
| 912 |
title, |
| 913 |
subtitle |
| 914 |
})({ elementIds }); |
| 915 |
}; |
| 916 |
|
| 917 |
//#endregion |
| 918 |
//#region packages/packages/libs/editor-elements/src/sync/replace-element.ts |
| 919 |
var replaceElement = ({ currentElementId, newElement, withHistory = true }) => { |
| 920 |
const currentElementContainer = getContainer(currentElementId); |
| 921 |
if (!currentElementContainer) throw new ElementNotFoundError({ context: { elementId: currentElementId } }); |
| 922 |
const { container, index } = getNewElementContainer(currentElementContainer, newElement); |
| 923 |
const newElementInstance = createElement({ |
| 924 |
container, |
| 925 |
model: newElement, |
| 926 |
options: { |
| 927 |
at: index, |
| 928 |
useHistory: withHistory |
| 929 |
} |
| 930 |
}); |
| 931 |
deleteElement({ |
| 932 |
container: currentElementContainer, |
| 933 |
options: { useHistory: withHistory } |
| 934 |
}); |
| 935 |
return newElementInstance; |
| 936 |
}; |
| 937 |
function getNewElementContainer(currentElementContainer, newElement) { |
| 938 |
const { parent } = currentElementContainer; |
| 939 |
if (!parent) throw new ElementParentNotFoundError({ context: { elementId: currentElementContainer.id } }); |
| 940 |
const elementIndex = currentElementContainer.view?._index ?? 0; |
| 941 |
if (elementIndex === -1) throw new ElementIndexNotFoundError({ context: { elementId: currentElementContainer.id } }); |
| 942 |
let location = { |
| 943 |
container: parent, |
| 944 |
index: elementIndex |
| 945 |
}; |
| 946 |
if (parent.id === "document" && newElement.elType === "widget") location = createWrapperForWidget(parent, elementIndex); |
| 947 |
return location; |
| 948 |
} |
| 949 |
var DEFAULT_CONTAINER_TYPE = "e-flexbox"; |
| 950 |
function createWrapperForWidget(parent, elementIndex) { |
| 951 |
return { |
| 952 |
container: createElement({ |
| 953 |
container: parent, |
| 954 |
model: { elType: DEFAULT_CONTAINER_TYPE }, |
| 955 |
options: { |
| 956 |
at: elementIndex, |
| 957 |
useHistory: false |
| 958 |
} |
| 959 |
}), |
| 960 |
index: 0 |
| 961 |
}; |
| 962 |
} |
| 963 |
|
| 964 |
//#endregion |
| 965 |
//#region packages/packages/libs/editor-elements/src/sync/update-element-editor-settings.ts |
| 966 |
var updateElementEditorSettings = ({ elementId, settings }) => { |
| 967 |
const element = getContainer(elementId); |
| 968 |
if (!element) throw new Error(`Element with id ${elementId} not found`); |
| 969 |
const editorSettings = element.model.get("editor_settings") ?? {}; |
| 970 |
element.model.set("editor_settings", { |
| 971 |
...editorSettings, |
| 972 |
...settings |
| 973 |
}); |
| 974 |
(0, _elementor_editor_v1_adapters.__privateRunCommandSync)("document/save/set-is-modified", { status: true }, { internal: true }); |
| 975 |
}; |
| 976 |
|
| 977 |
//#endregion |
| 978 |
//#region packages/packages/libs/editor-elements/src/sync/update-element-settings.ts |
| 979 |
var updateElementSettings = ({ id, props, withHistory = true }) => { |
| 980 |
const container = getContainer(id); |
| 981 |
if (!container) return; |
| 982 |
const args = { |
| 983 |
container, |
| 984 |
settings: { ...props } |
| 985 |
}; |
| 986 |
if (withHistory) (0, _elementor_editor_v1_adapters.__privateRunCommandSync)("document/elements/settings", args); |
| 987 |
else (0, _elementor_editor_v1_adapters.__privateRunCommandSync)("document/elements/set-settings", args, { internal: true }); |
| 988 |
}; |
| 989 |
|
| 990 |
//#endregion |
| 991 |
//#region packages/packages/libs/editor-elements/src/link-restriction.ts |
| 992 |
var ANCHOR_SELECTOR = "a, [data-action-link]"; |
| 993 |
function getLinkInLinkRestriction(elementId, resolvedValue) { |
| 994 |
const anchoredDescendantId = getAnchoredDescendantId(elementId); |
| 995 |
if (anchoredDescendantId) return { |
| 996 |
shouldRestrict: true, |
| 997 |
reason: "descendant", |
| 998 |
elementId: anchoredDescendantId |
| 999 |
}; |
| 1000 |
if (checkForInlineLink(elementId, resolvedValue)) return { |
| 1001 |
shouldRestrict: true, |
| 1002 |
reason: "descendant", |
| 1003 |
elementId |
| 1004 |
}; |
| 1005 |
const ancestor = getAnchoredAncestorId(elementId); |
| 1006 |
if (ancestor) return { |
| 1007 |
shouldRestrict: true, |
| 1008 |
reason: "ancestor", |
| 1009 |
elementId: ancestor |
| 1010 |
}; |
| 1011 |
return { shouldRestrict: false }; |
| 1012 |
} |
| 1013 |
function getAnchoredDescendantId(elementId) { |
| 1014 |
const element = getElementDOM(elementId); |
| 1015 |
if (!element) return null; |
| 1016 |
for (const childAnchorElement of Array.from(element.querySelectorAll(ANCHOR_SELECTOR))) { |
| 1017 |
const childElementId = findElementIdOf(childAnchorElement); |
| 1018 |
if (childElementId !== elementId) return childElementId; |
| 1019 |
} |
| 1020 |
return null; |
| 1021 |
} |
| 1022 |
function getAnchoredAncestorId(elementId) { |
| 1023 |
const element = getElementDOM(elementId); |
| 1024 |
if (!element || element.parentElement === null) return null; |
| 1025 |
const parentAnchor = element.parentElement.closest(ANCHOR_SELECTOR); |
| 1026 |
return parentAnchor ? findElementIdOf(parentAnchor) : null; |
| 1027 |
} |
| 1028 |
function isElementAnchored(elementId) { |
| 1029 |
const element = getElementDOM(elementId); |
| 1030 |
if (!element) return false; |
| 1031 |
if (element.matches(ANCHOR_SELECTOR)) return true; |
| 1032 |
return doesElementContainAnchor(element); |
| 1033 |
} |
| 1034 |
function doesElementContainAnchor(element) { |
| 1035 |
for (const child of Array.from(element.children)) { |
| 1036 |
if (isElementorElement(child)) continue; |
| 1037 |
if (child.matches(ANCHOR_SELECTOR)) return true; |
| 1038 |
if (doesElementContainAnchor(child)) return true; |
| 1039 |
} |
| 1040 |
return false; |
| 1041 |
} |
| 1042 |
function findElementIdOf(element) { |
| 1043 |
return element.closest("[data-id]")?.dataset.id || null; |
| 1044 |
} |
| 1045 |
function checkForInlineLink(elementId, resolvedValue) { |
| 1046 |
const element = getElementDOM(elementId); |
| 1047 |
if (!element) return false; |
| 1048 |
if (element.matches(ANCHOR_SELECTOR)) return false; |
| 1049 |
if ((resolvedValue ?? getElementSetting(elementId, "link")?.value)?.destination) return false; |
| 1050 |
return element.querySelector(ANCHOR_SELECTOR) !== null; |
| 1051 |
} |
| 1052 |
function getElementDOM(id) { |
| 1053 |
return getPreviewElementDOM(id); |
| 1054 |
} |
| 1055 |
function isElementorElement(element) { |
| 1056 |
return element.hasAttribute("data-id"); |
| 1057 |
} |
| 1058 |
|
| 1059 |
//#endregion |
| 1060 |
//#region packages/packages/libs/editor-elements/src/styles/consts.ts |
| 1061 |
var ELEMENT_STYLE_CHANGE_EVENT = "elementor/editor-v2/editor-elements/style"; |
| 1062 |
var styleRerenderEvents = [ |
| 1063 |
(0, _elementor_editor_v1_adapters.commandEndEvent)("document/elements/create"), |
| 1064 |
(0, _elementor_editor_v1_adapters.commandEndEvent)("document/elements/duplicate"), |
| 1065 |
(0, _elementor_editor_v1_adapters.commandEndEvent)("document/elements/import"), |
| 1066 |
(0, _elementor_editor_v1_adapters.commandEndEvent)("document/elements/paste"), |
| 1067 |
(0, _elementor_editor_v1_adapters.windowEvent)(ELEMENT_STYLE_CHANGE_EVENT) |
| 1068 |
]; |
| 1069 |
|
| 1070 |
//#endregion |
| 1071 |
//#region packages/packages/libs/editor-elements/src/styles/mutate-element-styles.ts |
| 1072 |
function mutateElementStyles(elementId, mutator) { |
| 1073 |
const container = getContainer(elementId); |
| 1074 |
if (!container) throw new ElementNotFoundError({ context: { elementId } }); |
| 1075 |
const oldIds = Object.keys(container.model.get("styles") ?? {}); |
| 1076 |
const styles = mutateStyles(container, mutator); |
| 1077 |
clearRemovedClasses(container, { |
| 1078 |
oldIds, |
| 1079 |
newIds: Object.keys(styles) |
| 1080 |
}); |
| 1081 |
notifyChanges(); |
| 1082 |
return styles; |
| 1083 |
} |
| 1084 |
function mutateStyles(container, mutator) { |
| 1085 |
const styles = structuredClone(container.model.get("styles")) ?? {}; |
| 1086 |
const entries = Object.entries(mutator(styles)).map(([styleId, style]) => { |
| 1087 |
style.variants = removeEmptyVariants(style); |
| 1088 |
return [styleId, style]; |
| 1089 |
}).filter(([, style]) => { |
| 1090 |
return !isStyleEmpty(style); |
| 1091 |
}); |
| 1092 |
const mutatedStyles = Object.fromEntries(entries); |
| 1093 |
container.model.set("styles", mutatedStyles); |
| 1094 |
return mutatedStyles; |
| 1095 |
} |
| 1096 |
function removeEmptyVariants(style) { |
| 1097 |
return style.variants.filter(({ props, custom_css: customCss }) => Object.keys(props).length > 0 || customCss?.raw); |
| 1098 |
} |
| 1099 |
function isStyleEmpty(style) { |
| 1100 |
return style.variants.length === 0; |
| 1101 |
} |
| 1102 |
function clearRemovedClasses(container, { oldIds, newIds }) { |
| 1103 |
const removedIds = oldIds.filter((id) => !newIds.includes(id)); |
| 1104 |
if (!removedIds.length) return; |
| 1105 |
const classesProps = structuredClone(getClassesProps(container)); |
| 1106 |
classesProps.forEach(([, prop]) => { |
| 1107 |
prop.value = prop.value.filter((value) => !removedIds.includes(value)); |
| 1108 |
}); |
| 1109 |
updateElementSettings({ |
| 1110 |
id: container.id, |
| 1111 |
props: Object.fromEntries(classesProps), |
| 1112 |
withHistory: false |
| 1113 |
}); |
| 1114 |
} |
| 1115 |
function getClassesProps(container) { |
| 1116 |
return Object.entries(container.settings.toJSON()).filter((prop) => { |
| 1117 |
const [, value] = prop; |
| 1118 |
return _elementor_editor_props.classesPropTypeUtil.isValid(value); |
| 1119 |
}); |
| 1120 |
} |
| 1121 |
function notifyChanges() { |
| 1122 |
dispatchChangeEvent(); |
| 1123 |
(0, _elementor_editor_v1_adapters.__privateRunCommandSync)("document/save/set-is-modified", { status: true }, { internal: true }); |
| 1124 |
} |
| 1125 |
function dispatchChangeEvent() { |
| 1126 |
window.dispatchEvent(new CustomEvent(ELEMENT_STYLE_CHANGE_EVENT)); |
| 1127 |
} |
| 1128 |
|
| 1129 |
//#endregion |
| 1130 |
//#region packages/packages/libs/editor-elements/src/styles/create-element-style.ts |
| 1131 |
function createElementStyle({ styleId, elementId, classesProp, label, meta, props, custom_css: customCss = null, additionalVariants = [] }) { |
| 1132 |
let id = styleId; |
| 1133 |
mutateElementStyles(elementId, (styles) => { |
| 1134 |
id ?? (id = (0, _elementor_editor_styles.generateId)(`e-${elementId}-`, Object.keys(styles))); |
| 1135 |
const variants = [{ |
| 1136 |
meta, |
| 1137 |
props, |
| 1138 |
custom_css: customCss |
| 1139 |
}, ...additionalVariants]; |
| 1140 |
styles[id] = { |
| 1141 |
id, |
| 1142 |
label, |
| 1143 |
type: "class", |
| 1144 |
variants |
| 1145 |
}; |
| 1146 |
addStyleToClassesProp(elementId, classesProp, id); |
| 1147 |
return styles; |
| 1148 |
}); |
| 1149 |
return id; |
| 1150 |
} |
| 1151 |
function addStyleToClassesProp(elementId, classesProp, styleId) { |
| 1152 |
const base = getElementSetting(elementId, classesProp); |
| 1153 |
const classesPropValue = _elementor_editor_props.classesPropTypeUtil.create((prev) => { |
| 1154 |
return [...prev ?? [], styleId]; |
| 1155 |
}, { base }); |
| 1156 |
updateElementSettings({ |
| 1157 |
id: elementId, |
| 1158 |
props: { [classesProp]: classesPropValue }, |
| 1159 |
withHistory: false |
| 1160 |
}); |
| 1161 |
} |
| 1162 |
function shouldCreateNewLocalStyle(payload) { |
| 1163 |
return !payload?.styleId && !payload?.provider; |
| 1164 |
} |
| 1165 |
|
| 1166 |
//#endregion |
| 1167 |
//#region packages/packages/libs/editor-elements/src/styles/delete-element-style.ts |
| 1168 |
function deleteElementStyle(elementId, styleId) { |
| 1169 |
mutateElementStyles(elementId, (styles) => { |
| 1170 |
delete styles[styleId]; |
| 1171 |
return styles; |
| 1172 |
}); |
| 1173 |
} |
| 1174 |
|
| 1175 |
//#endregion |
| 1176 |
//#region packages/packages/libs/editor-elements/src/styles/update-element-style.ts |
| 1177 |
function updateElementStyle(args) { |
| 1178 |
mutateElementStyles(args.elementId, (styles) => { |
| 1179 |
const style = styles[args.styleId]; |
| 1180 |
if (!style) throw new StyleNotFoundError({ context: { styleId: args.styleId } }); |
| 1181 |
const variant = (0, _elementor_editor_styles.getVariantByMeta)(style, args.meta); |
| 1182 |
const customCss = ("custom_css" in args ? args.custom_css : variant?.custom_css) ?? null; |
| 1183 |
if (variant) { |
| 1184 |
variant.props = (0, _elementor_editor_props.mergeProps)(variant.props, args.props); |
| 1185 |
variant.custom_css = customCss?.raw ? customCss : null; |
| 1186 |
} else style.variants.push({ |
| 1187 |
meta: args.meta, |
| 1188 |
props: args.props, |
| 1189 |
custom_css: customCss |
| 1190 |
}); |
| 1191 |
return styles; |
| 1192 |
}); |
| 1193 |
} |
| 1194 |
|
| 1195 |
//#endregion |
| 1196 |
//#region packages/packages/libs/editor-elements/src/sync/get-element-interactions.ts |
| 1197 |
function getElementInteractions(elementId) { |
| 1198 |
const interactions = getContainer(elementId)?.model?.get("interactions"); |
| 1199 |
if (typeof interactions === "string") return JSON.parse(interactions); |
| 1200 |
return interactions; |
| 1201 |
} |
| 1202 |
|
| 1203 |
//#endregion |
| 1204 |
//#region packages/packages/libs/editor-elements/src/utils/get-default-style-tag-from-preview.ts |
| 1205 |
var DEFAULT_STYLE_CLASS_PREFIX = "e-default-"; |
| 1206 |
function parseDefaultStyleTagFromClassList(classList) { |
| 1207 |
for (const className of classList) if (className.startsWith("e-default-")) return className.slice(10); |
| 1208 |
return null; |
| 1209 |
} |
| 1210 |
function getDefaultStyleTagFromPreviewElement(elementId) { |
| 1211 |
const renderRoot = getAtomicElementRenderRoot(elementId); |
| 1212 |
if (!renderRoot) return null; |
| 1213 |
return parseDefaultStyleTagFromClassList(renderRoot.classList); |
| 1214 |
} |
| 1215 |
function getAtomicElementRenderRoot(elementId) { |
| 1216 |
const view = getContainerView(elementId); |
| 1217 |
if (view?.getDomElement) { |
| 1218 |
const domElement = view.getDomElement().get?.(0); |
| 1219 |
if (domElement) return domElement; |
| 1220 |
} |
| 1221 |
const wrapper = view?.el ?? getPreviewElementDOM(elementId); |
| 1222 |
if (!wrapper) return null; |
| 1223 |
if (wrapper.hasAttribute("data-id")) return wrapper; |
| 1224 |
const firstChild = wrapper.firstElementChild; |
| 1225 |
if (firstChild instanceof HTMLElement) return firstChild; |
| 1226 |
return wrapper; |
| 1227 |
} |
| 1228 |
function getContainerView(elementId) { |
| 1229 |
return getContainer(elementId)?.view ?? null; |
| 1230 |
} |
| 1231 |
|
| 1232 |
//#endregion |
| 1233 |
//#region packages/packages/libs/editor-elements/src/sync/update-element-interactions.ts |
| 1234 |
var updateElementInteractions = ({ elementId, interactions }) => { |
| 1235 |
const element = getContainer(elementId); |
| 1236 |
if (!element) throw new Error(`Element with id ${elementId} not found`); |
| 1237 |
element.model.set("interactions", interactions); |
| 1238 |
window.dispatchEvent(new CustomEvent("elementor/element/update_interactions")); |
| 1239 |
(0, _elementor_editor_v1_adapters.__privateRunCommandSync)("document/save/set-is-modified", { status: true }, { internal: true }); |
| 1240 |
}; |
| 1241 |
var playElementInteractions = (elementId, interactionId) => { |
| 1242 |
window.top?.dispatchEvent(new CustomEvent("atomic/play_interactions", { detail: { |
| 1243 |
elementId, |
| 1244 |
interactionId |
| 1245 |
} })); |
| 1246 |
}; |
| 1247 |
|
| 1248 |
//#endregion |
| 1249 |
//#region packages/packages/libs/editor-elements/src/index.ts |
| 1250 |
var src_exports = /* @__PURE__ */ __exportAll({ |
| 1251 |
DEFAULT_STYLE_CLASS_PREFIX: () => DEFAULT_STYLE_CLASS_PREFIX, |
| 1252 |
ELEMENT_STYLE_CHANGE_EVENT: () => ELEMENT_STYLE_CHANGE_EVENT, |
| 1253 |
addModelToParent: () => addModelToParent, |
| 1254 |
bindSettingsReconcile: () => bindSettingsReconcile, |
| 1255 |
createElement: () => createElement, |
| 1256 |
createElementStyle: () => createElementStyle, |
| 1257 |
createElements: () => createElements, |
| 1258 |
deleteElement: () => deleteElement, |
| 1259 |
deleteElementStyle: () => deleteElementStyle, |
| 1260 |
dropElement: () => dropElement, |
| 1261 |
duplicateElement: () => duplicateElement, |
| 1262 |
duplicateElements: () => duplicateElements, |
| 1263 |
evaluateWhen: () => evaluateWhen, |
| 1264 |
findChildRecursive: () => findChildRecursive, |
| 1265 |
findModelInDocument: () => findModelInDocument, |
| 1266 |
generateElementId: () => generateElementId, |
| 1267 |
getAllDescendants: () => getAllDescendants, |
| 1268 |
getAnchoredAncestorId: () => getAnchoredAncestorId, |
| 1269 |
getAnchoredDescendantId: () => getAnchoredDescendantId, |
| 1270 |
getContainer: () => getContainer, |
| 1271 |
getCurrentDocumentContainer: () => getCurrentDocumentContainer, |
| 1272 |
getCurrentDocumentId: () => getCurrentDocumentId, |
| 1273 |
getDefaultStyleTagFromPreviewElement: () => getDefaultStyleTagFromPreviewElement, |
| 1274 |
getElementChildrenWithFallback: () => getElementChildren, |
| 1275 |
getElementEditorSettings: () => getElementEditorSettings, |
| 1276 |
getElementIcon: () => getElementIcon, |
| 1277 |
getElementInteractions: () => getElementInteractions, |
| 1278 |
getElementLabel: () => getElementLabel, |
| 1279 |
getElementSetting: () => getElementSetting, |
| 1280 |
getElementSettings: () => getElementSettings, |
| 1281 |
getElementStyles: () => getElementStyles, |
| 1282 |
getElementTitle: () => getElementTitle, |
| 1283 |
getElementType: () => getElementType, |
| 1284 |
getElements: () => getElements, |
| 1285 |
getLinkInLinkRestriction: () => getLinkInLinkRestriction, |
| 1286 |
getPreviewElementDOM: () => getPreviewElementDOM, |
| 1287 |
getSelectedElements: () => getSelectedElements, |
| 1288 |
getWidgetsCache: () => getWidgetsCache, |
| 1289 |
isElementAnchored: () => isElementAnchored, |
| 1290 |
moveElement: () => moveElement, |
| 1291 |
moveElements: () => moveElements, |
| 1292 |
parseDefaultStyleTagFromClassList: () => parseDefaultStyleTagFromClassList, |
| 1293 |
playElementInteractions: () => playElementInteractions, |
| 1294 |
reconcileInitialChildren: () => reconcileInitialChildren, |
| 1295 |
removeElements: () => removeElements, |
| 1296 |
removeModelFromParent: () => removeModelFromParent, |
| 1297 |
replaceElement: () => replaceElement, |
| 1298 |
resolveContainer: () => resolveContainer, |
| 1299 |
resolveInsertIndex: () => resolveInsertIndex, |
| 1300 |
selectElement: () => selectElement, |
| 1301 |
shouldCreateNewLocalStyle: () => shouldCreateNewLocalStyle, |
| 1302 |
styleRerenderEvents: () => styleRerenderEvents, |
| 1303 |
updateElementEditorSettings: () => updateElementEditorSettings, |
| 1304 |
updateElementInteractions: () => updateElementInteractions, |
| 1305 |
updateElementSettings: () => updateElementSettings, |
| 1306 |
updateElementStyle: () => updateElementStyle, |
| 1307 |
useElementChildren: () => useElementChildren, |
| 1308 |
useElementEditorSettings: () => useElementEditorSettings, |
| 1309 |
useParentElement: () => useParentElement, |
| 1310 |
useSelectedElement: () => useSelectedElement, |
| 1311 |
useSelectedElementSettings: () => useSelectedElementSettings |
| 1312 |
}); |
| 1313 |
|
| 1314 |
//#endregion |
| 1315 |
//#region \0elementor-package-library-entry |
| 1316 |
(window.elementorV2 = window.elementorV2 || {}).editorElements = src_exports; |
| 1317 |
|
| 1318 |
//#endregion |
| 1319 |
})(elementorV2.editorV1Adapters, elementorV2.session, elementorV2.editorProps, wp.i18n, elementorV2.utils, elementorV2.editorStyles); |
| 1320 |
window.elementorV2.editorElements?.init?.(); |
| 1321 |
//# sourceMappingURL=editor-elements.js.map |