@elementor/editor-elements 4.3.0-973 → 4.3.0-975

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { PropsSchema, PropValue, SizePropValue, AnyTransformable, Props, LinkPropValue } from '@elementor/editor-props';
1
+ import { PropsSchema, Dependency, PropValue, SizePropValue, AnyTransformable, Props, LinkPropValue } from '@elementor/editor-props';
2
2
  import { ClassState, StyleDefinitionID, StyleDefinition, StyleDefinitionVariant } from '@elementor/editor-styles';
3
3
  import * as _elementor_editor_v1_adapters from '@elementor/editor-v1-adapters';
4
4
 
@@ -58,6 +58,15 @@ type ElementControl = {
58
58
  type ControlItem = ControlsSection | Control | ElementControl;
59
59
  type ControlLayout = 'full' | 'two-columns' | 'custom';
60
60
 
61
+ type ChildDependencyRule = {
62
+ child_type: string;
63
+ when: Dependency;
64
+ position: ElementPosition;
65
+ stash: boolean;
66
+ default_model: V1ElementData | null;
67
+ };
68
+ type ChildDependenciesConfig = ChildDependencyRule[];
69
+
61
70
  type ExtendedWindow = Window & {
62
71
  $e?: {
63
72
  components?: {
@@ -207,6 +216,11 @@ type V1ElementModelProps = {
207
216
  type V1ElementData = Omit<V1ElementModelProps, 'elements'> & {
208
217
  elements?: V1ElementData[];
209
218
  };
219
+ type ElementPositionKind = 'last' | 'first' | 'index' | 'after_type' | 'before_type';
220
+ type ElementPosition = {
221
+ kind: ElementPositionKind;
222
+ value: number | string | null;
223
+ };
210
224
  type V1ElementEditorSettingsProps = {
211
225
  title?: string;
212
226
  initial_position?: number;
@@ -234,6 +248,7 @@ type V1ElementConfig<T = object, TChild = unknown> = {
234
248
  show_in_panel?: boolean;
235
249
  allowed_child_types?: string[];
236
250
  default_children?: Array<Record<string, TChild>>;
251
+ children_dependencies?: ChildDependencyRule[];
237
252
  meta?: {
238
253
  [key: string]: string | number | boolean | null | NonNullable<V1ElementConfig['meta']>;
239
254
  };
@@ -245,7 +260,31 @@ type V1Model$1<T> = {
245
260
  remove?: string[];
246
261
  }) => T;
247
262
  trigger?: (event: string, ...args: unknown[]) => void;
263
+ on?: (event: string, callback: (...args: unknown[]) => void, context?: unknown) => void;
264
+ off?: (event: string, callback?: (...args: unknown[]) => void, context?: unknown) => void;
265
+ };
266
+
267
+ type ReactiveModel = {
268
+ get: (key: string) => unknown;
269
+ };
270
+ type BindSettingsReconcileArgs = {
271
+ model: ReactiveModel;
272
+ elementConfig: V1ElementConfig | undefined;
248
273
  };
274
+ type Detach = () => void;
275
+ declare function bindSettingsReconcile({ model, elementConfig }: BindSettingsReconcileArgs): Detach;
276
+
277
+ declare function evaluateWhen(when: Dependency | undefined, settings: Record<string, PropValue>): boolean;
278
+
279
+ type ReconcileInitialChildrenArgs = {
280
+ elementId: string;
281
+ elementConfig: V1ElementConfig | undefined;
282
+ attributes: {
283
+ elements?: V1ElementData[];
284
+ settings?: V1ElementSettingsProps;
285
+ };
286
+ };
287
+ declare function reconcileInitialChildren({ elementId, elementConfig, attributes, }: ReconcileInitialChildrenArgs): void;
249
288
 
250
289
  type ElementModel = {
251
290
  id: string;
@@ -487,6 +526,8 @@ type ReplaceElementArgs = {
487
526
  };
488
527
  declare const replaceElement: ({ currentElementId, newElement, withHistory }: ReplaceElementArgs) => V1Element;
489
528
 
529
+ declare function resolveInsertIndex(position: ElementPosition, elements: V1ElementData[]): number;
530
+
490
531
  declare const updateElementEditorSettings: ({ elementId, settings, }: {
491
532
  elementId: string;
492
533
  settings: V1ElementModelProps["editor_settings"];
@@ -552,4 +593,4 @@ declare const updateElementInteractions: ({ elementId, interactions, }: {
552
593
  }) => void;
553
594
  declare const playElementInteractions: (elementId: string, interactionId: string) => void;
554
595
 
555
- export { type AnimationPresetPropValue, type BackboneCollection, type BackboneModel, type BooleanPropValue, type ConfigPropValue, type Control, type ControlItem, type ControlLayout, type ControlsSection, type CreateElementParams, type CreateElementStyleArgs, type DropElementParams, type DuplicateElementParams, type DuplicateElementsParams, type DuplicatedElement, type DuplicatedElementsResult, ELEMENT_STYLE_CHANGE_EVENT, type Element, type ElementChildren, type ElementControl, type ElementID, type ElementInteractions, type ElementModel, type ElementType, type ExcludedBreakpointsPropValue, type ExtendedWindow, type InteractionBreakpointsPropValue, type InteractionItemPropValue, type LinkInLinkRestriction, type ModelResult, type MoveElementParams, type NumberPropValue, type PseudoState, type StringPropValue, type TimingConfigPropValue, type UpdateElementSettingsArgs, type UpdateElementStyleArgs, type V1Element, type V1ElementConfig, type V1ElementData, type V1ElementEditorSettingsProps, type V1ElementModelProps, type V1ElementSettingsProps, addModelToParent, createElement, createElementStyle, createElements, deleteElement, deleteElementStyle, dropElement, duplicateElement, duplicateElements, findChildRecursive, findModelInDocument, generateElementId, getAllDescendants, getAnchoredAncestorId, getAnchoredDescendantId, getContainer, getCurrentDocumentContainer, getCurrentDocumentId, getElementChildren as getElementChildrenWithFallback, getElementEditorSettings, getElementIcon, getElementInteractions, getElementLabel, getElementSetting, getElementSettings, getElementStyles, getElementTitle, getElementType, getElements, getLinkInLinkRestriction, getSelectedElements, getWidgetsCache, isElementAnchored, moveElement, moveElements, playElementInteractions, removeElements, removeModelFromParent, replaceElement, resolveContainer, selectElement, shouldCreateNewLocalStyle, styleRerenderEvents, updateElementEditorSettings, updateElementInteractions, updateElementSettings, updateElementStyle, useElementChildren, useElementEditorSettings, useParentElement, useSelectedElement, useSelectedElementSettings };
596
+ export { type AnimationPresetPropValue, type BackboneCollection, type BackboneModel, type BooleanPropValue, type ChildDependenciesConfig, type ChildDependencyRule, type ConfigPropValue, type Control, type ControlItem, type ControlLayout, type ControlsSection, type CreateElementParams, type CreateElementStyleArgs, type DropElementParams, type DuplicateElementParams, type DuplicateElementsParams, type DuplicatedElement, type DuplicatedElementsResult, ELEMENT_STYLE_CHANGE_EVENT, type Element, type ElementChildren, type ElementControl, type ElementID, type ElementInteractions, type ElementModel, type ElementPosition, type ElementPositionKind, type ElementType, type ExcludedBreakpointsPropValue, type ExtendedWindow, type InteractionBreakpointsPropValue, type InteractionItemPropValue, type LinkInLinkRestriction, type ModelResult, type MoveElementParams, type NumberPropValue, type PseudoState, type StringPropValue, type TimingConfigPropValue, type UpdateElementSettingsArgs, type UpdateElementStyleArgs, type V1Element, type V1ElementConfig, type V1ElementData, type V1ElementEditorSettingsProps, type V1ElementModelProps, type V1ElementSettingsProps, addModelToParent, bindSettingsReconcile, createElement, createElementStyle, createElements, deleteElement, deleteElementStyle, dropElement, duplicateElement, duplicateElements, evaluateWhen, findChildRecursive, findModelInDocument, generateElementId, getAllDescendants, getAnchoredAncestorId, getAnchoredDescendantId, getContainer, getCurrentDocumentContainer, getCurrentDocumentId, getElementChildren as getElementChildrenWithFallback, getElementEditorSettings, getElementIcon, getElementInteractions, getElementLabel, getElementSetting, getElementSettings, getElementStyles, getElementTitle, getElementType, getElements, getLinkInLinkRestriction, getSelectedElements, getWidgetsCache, isElementAnchored, moveElement, moveElements, playElementInteractions, reconcileInitialChildren, removeElements, removeModelFromParent, replaceElement, resolveContainer, resolveInsertIndex, selectElement, shouldCreateNewLocalStyle, styleRerenderEvents, updateElementEditorSettings, updateElementInteractions, updateElementSettings, updateElementStyle, useElementChildren, useElementEditorSettings, useParentElement, useSelectedElement, useSelectedElementSettings };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { PropsSchema, PropValue, SizePropValue, AnyTransformable, Props, LinkPropValue } from '@elementor/editor-props';
1
+ import { PropsSchema, Dependency, PropValue, SizePropValue, AnyTransformable, Props, LinkPropValue } from '@elementor/editor-props';
2
2
  import { ClassState, StyleDefinitionID, StyleDefinition, StyleDefinitionVariant } from '@elementor/editor-styles';
3
3
  import * as _elementor_editor_v1_adapters from '@elementor/editor-v1-adapters';
4
4
 
@@ -58,6 +58,15 @@ type ElementControl = {
58
58
  type ControlItem = ControlsSection | Control | ElementControl;
59
59
  type ControlLayout = 'full' | 'two-columns' | 'custom';
60
60
 
61
+ type ChildDependencyRule = {
62
+ child_type: string;
63
+ when: Dependency;
64
+ position: ElementPosition;
65
+ stash: boolean;
66
+ default_model: V1ElementData | null;
67
+ };
68
+ type ChildDependenciesConfig = ChildDependencyRule[];
69
+
61
70
  type ExtendedWindow = Window & {
62
71
  $e?: {
63
72
  components?: {
@@ -207,6 +216,11 @@ type V1ElementModelProps = {
207
216
  type V1ElementData = Omit<V1ElementModelProps, 'elements'> & {
208
217
  elements?: V1ElementData[];
209
218
  };
219
+ type ElementPositionKind = 'last' | 'first' | 'index' | 'after_type' | 'before_type';
220
+ type ElementPosition = {
221
+ kind: ElementPositionKind;
222
+ value: number | string | null;
223
+ };
210
224
  type V1ElementEditorSettingsProps = {
211
225
  title?: string;
212
226
  initial_position?: number;
@@ -234,6 +248,7 @@ type V1ElementConfig<T = object, TChild = unknown> = {
234
248
  show_in_panel?: boolean;
235
249
  allowed_child_types?: string[];
236
250
  default_children?: Array<Record<string, TChild>>;
251
+ children_dependencies?: ChildDependencyRule[];
237
252
  meta?: {
238
253
  [key: string]: string | number | boolean | null | NonNullable<V1ElementConfig['meta']>;
239
254
  };
@@ -245,7 +260,31 @@ type V1Model$1<T> = {
245
260
  remove?: string[];
246
261
  }) => T;
247
262
  trigger?: (event: string, ...args: unknown[]) => void;
263
+ on?: (event: string, callback: (...args: unknown[]) => void, context?: unknown) => void;
264
+ off?: (event: string, callback?: (...args: unknown[]) => void, context?: unknown) => void;
265
+ };
266
+
267
+ type ReactiveModel = {
268
+ get: (key: string) => unknown;
269
+ };
270
+ type BindSettingsReconcileArgs = {
271
+ model: ReactiveModel;
272
+ elementConfig: V1ElementConfig | undefined;
248
273
  };
274
+ type Detach = () => void;
275
+ declare function bindSettingsReconcile({ model, elementConfig }: BindSettingsReconcileArgs): Detach;
276
+
277
+ declare function evaluateWhen(when: Dependency | undefined, settings: Record<string, PropValue>): boolean;
278
+
279
+ type ReconcileInitialChildrenArgs = {
280
+ elementId: string;
281
+ elementConfig: V1ElementConfig | undefined;
282
+ attributes: {
283
+ elements?: V1ElementData[];
284
+ settings?: V1ElementSettingsProps;
285
+ };
286
+ };
287
+ declare function reconcileInitialChildren({ elementId, elementConfig, attributes, }: ReconcileInitialChildrenArgs): void;
249
288
 
250
289
  type ElementModel = {
251
290
  id: string;
@@ -487,6 +526,8 @@ type ReplaceElementArgs = {
487
526
  };
488
527
  declare const replaceElement: ({ currentElementId, newElement, withHistory }: ReplaceElementArgs) => V1Element;
489
528
 
529
+ declare function resolveInsertIndex(position: ElementPosition, elements: V1ElementData[]): number;
530
+
490
531
  declare const updateElementEditorSettings: ({ elementId, settings, }: {
491
532
  elementId: string;
492
533
  settings: V1ElementModelProps["editor_settings"];
@@ -552,4 +593,4 @@ declare const updateElementInteractions: ({ elementId, interactions, }: {
552
593
  }) => void;
553
594
  declare const playElementInteractions: (elementId: string, interactionId: string) => void;
554
595
 
555
- export { type AnimationPresetPropValue, type BackboneCollection, type BackboneModel, type BooleanPropValue, type ConfigPropValue, type Control, type ControlItem, type ControlLayout, type ControlsSection, type CreateElementParams, type CreateElementStyleArgs, type DropElementParams, type DuplicateElementParams, type DuplicateElementsParams, type DuplicatedElement, type DuplicatedElementsResult, ELEMENT_STYLE_CHANGE_EVENT, type Element, type ElementChildren, type ElementControl, type ElementID, type ElementInteractions, type ElementModel, type ElementType, type ExcludedBreakpointsPropValue, type ExtendedWindow, type InteractionBreakpointsPropValue, type InteractionItemPropValue, type LinkInLinkRestriction, type ModelResult, type MoveElementParams, type NumberPropValue, type PseudoState, type StringPropValue, type TimingConfigPropValue, type UpdateElementSettingsArgs, type UpdateElementStyleArgs, type V1Element, type V1ElementConfig, type V1ElementData, type V1ElementEditorSettingsProps, type V1ElementModelProps, type V1ElementSettingsProps, addModelToParent, createElement, createElementStyle, createElements, deleteElement, deleteElementStyle, dropElement, duplicateElement, duplicateElements, findChildRecursive, findModelInDocument, generateElementId, getAllDescendants, getAnchoredAncestorId, getAnchoredDescendantId, getContainer, getCurrentDocumentContainer, getCurrentDocumentId, getElementChildren as getElementChildrenWithFallback, getElementEditorSettings, getElementIcon, getElementInteractions, getElementLabel, getElementSetting, getElementSettings, getElementStyles, getElementTitle, getElementType, getElements, getLinkInLinkRestriction, getSelectedElements, getWidgetsCache, isElementAnchored, moveElement, moveElements, playElementInteractions, removeElements, removeModelFromParent, replaceElement, resolveContainer, selectElement, shouldCreateNewLocalStyle, styleRerenderEvents, updateElementEditorSettings, updateElementInteractions, updateElementSettings, updateElementStyle, useElementChildren, useElementEditorSettings, useParentElement, useSelectedElement, useSelectedElementSettings };
596
+ export { type AnimationPresetPropValue, type BackboneCollection, type BackboneModel, type BooleanPropValue, type ChildDependenciesConfig, type ChildDependencyRule, type ConfigPropValue, type Control, type ControlItem, type ControlLayout, type ControlsSection, type CreateElementParams, type CreateElementStyleArgs, type DropElementParams, type DuplicateElementParams, type DuplicateElementsParams, type DuplicatedElement, type DuplicatedElementsResult, ELEMENT_STYLE_CHANGE_EVENT, type Element, type ElementChildren, type ElementControl, type ElementID, type ElementInteractions, type ElementModel, type ElementPosition, type ElementPositionKind, type ElementType, type ExcludedBreakpointsPropValue, type ExtendedWindow, type InteractionBreakpointsPropValue, type InteractionItemPropValue, type LinkInLinkRestriction, type ModelResult, type MoveElementParams, type NumberPropValue, type PseudoState, type StringPropValue, type TimingConfigPropValue, type UpdateElementSettingsArgs, type UpdateElementStyleArgs, type V1Element, type V1ElementConfig, type V1ElementData, type V1ElementEditorSettingsProps, type V1ElementModelProps, type V1ElementSettingsProps, addModelToParent, bindSettingsReconcile, createElement, createElementStyle, createElements, deleteElement, deleteElementStyle, dropElement, duplicateElement, duplicateElements, evaluateWhen, findChildRecursive, findModelInDocument, generateElementId, getAllDescendants, getAnchoredAncestorId, getAnchoredDescendantId, getContainer, getCurrentDocumentContainer, getCurrentDocumentId, getElementChildren as getElementChildrenWithFallback, getElementEditorSettings, getElementIcon, getElementInteractions, getElementLabel, getElementSetting, getElementSettings, getElementStyles, getElementTitle, getElementType, getElements, getLinkInLinkRestriction, getSelectedElements, getWidgetsCache, isElementAnchored, moveElement, moveElements, playElementInteractions, reconcileInitialChildren, removeElements, removeModelFromParent, replaceElement, resolveContainer, resolveInsertIndex, selectElement, shouldCreateNewLocalStyle, styleRerenderEvents, updateElementEditorSettings, updateElementInteractions, updateElementSettings, updateElementStyle, useElementChildren, useElementEditorSettings, useParentElement, useSelectedElement, useSelectedElementSettings };
package/dist/index.js CHANGED
@@ -22,6 +22,7 @@ var index_exports = {};
22
22
  __export(index_exports, {
23
23
  ELEMENT_STYLE_CHANGE_EVENT: () => ELEMENT_STYLE_CHANGE_EVENT,
24
24
  addModelToParent: () => addModelToParent,
25
+ bindSettingsReconcile: () => bindSettingsReconcile,
25
26
  createElement: () => createElement,
26
27
  createElementStyle: () => createElementStyle,
27
28
  createElements: () => createElements,
@@ -30,6 +31,7 @@ __export(index_exports, {
30
31
  dropElement: () => dropElement,
31
32
  duplicateElement: () => duplicateElement,
32
33
  duplicateElements: () => duplicateElements,
34
+ evaluateWhen: () => evaluateWhen,
33
35
  findChildRecursive: () => findChildRecursive,
34
36
  findModelInDocument: () => findModelInDocument,
35
37
  generateElementId: () => generateElementId,
@@ -57,10 +59,12 @@ __export(index_exports, {
57
59
  moveElement: () => moveElement,
58
60
  moveElements: () => moveElements,
59
61
  playElementInteractions: () => playElementInteractions,
62
+ reconcileInitialChildren: () => reconcileInitialChildren,
60
63
  removeElements: () => removeElements,
61
64
  removeModelFromParent: () => removeModelFromParent,
62
65
  replaceElement: () => replaceElement,
63
66
  resolveContainer: () => resolveContainer,
67
+ resolveInsertIndex: () => resolveInsertIndex,
64
68
  selectElement: () => selectElement,
65
69
  shouldCreateNewLocalStyle: () => shouldCreateNewLocalStyle,
66
70
  styleRerenderEvents: () => styleRerenderEvents,
@@ -76,9 +80,6 @@ __export(index_exports, {
76
80
  });
77
81
  module.exports = __toCommonJS(index_exports);
78
82
 
79
- // src/hooks/use-element-children.ts
80
- var import_editor_v1_adapters2 = require("@elementor/editor-v1-adapters");
81
-
82
83
  // src/sync/get-container.ts
83
84
  var import_editor_v1_adapters = require("@elementor/editor-v1-adapters");
84
85
  function getContainer(id) {
@@ -94,6 +95,233 @@ var selectElement = (elementId) => {
94
95
  }
95
96
  };
96
97
 
98
+ // src/sync/resolve-element.ts
99
+ function isConnected(container) {
100
+ if (!container) {
101
+ return false;
102
+ }
103
+ if (!container.view?.el) {
104
+ return true;
105
+ }
106
+ return container.view.el.isConnected;
107
+ }
108
+ function resolveContainer(container, id) {
109
+ const looked = container.lookup?.();
110
+ if (isConnected(looked)) {
111
+ return looked;
112
+ }
113
+ const byId = getContainer(id);
114
+ if (isConnected(byId)) {
115
+ return byId;
116
+ }
117
+ return null;
118
+ }
119
+ function getDocumentUtils() {
120
+ return window.$e?.components?.get?.("document")?.utils;
121
+ }
122
+ function findModelInDocument(id) {
123
+ return getDocumentUtils()?.findModelById?.(id) ?? null;
124
+ }
125
+ function addModelToParent(parentId, childData, options) {
126
+ return getDocumentUtils()?.addModelToParent?.(parentId, childData, options) ?? false;
127
+ }
128
+ function removeModelFromParent(parentId, childId) {
129
+ return getDocumentUtils()?.removeModelFromParent?.(parentId, childId) ?? false;
130
+ }
131
+
132
+ // src/sync/resolve-insert-index.ts
133
+ function resolveInsertIndex(position, elements) {
134
+ const lastIndex = elements.length;
135
+ switch (position.kind) {
136
+ case "first":
137
+ return 0;
138
+ case "last":
139
+ return lastIndex;
140
+ case "index": {
141
+ const index = typeof position.value === "number" ? position.value : lastIndex;
142
+ return Math.max(0, Math.min(index, lastIndex));
143
+ }
144
+ case "after_type": {
145
+ const anchor = elements.findIndex((element) => element.elType === position.value);
146
+ return anchor >= 0 ? anchor + 1 : lastIndex;
147
+ }
148
+ case "before_type": {
149
+ const anchor = elements.findIndex((element) => element.elType === position.value);
150
+ return anchor >= 0 ? anchor : lastIndex;
151
+ }
152
+ default:
153
+ return lastIndex;
154
+ }
155
+ }
156
+
157
+ // src/children-dependencies/stash.ts
158
+ var import_session = require("@elementor/session");
159
+ var STASH_KEY_PREFIX = "elementor/editor-state";
160
+ var STASH_KEY_SEGMENT = "children-deps";
161
+ function createChildrenStash() {
162
+ return {
163
+ get(elementId, childType) {
164
+ return (0, import_session.getSessionStorageItem)(buildStashKey(elementId, childType));
165
+ },
166
+ save(elementId, childType, data) {
167
+ (0, import_session.setSessionStorageItem)(buildStashKey(elementId, childType), data);
168
+ },
169
+ clear(elementId, childType) {
170
+ (0, import_session.removeSessionStorageItem)(buildStashKey(elementId, childType));
171
+ },
172
+ clearAllForElement(elementId) {
173
+ const prefix = buildElementStashPrefix(elementId);
174
+ for (let index = sessionStorage.length - 1; index >= 0; index--) {
175
+ const key = sessionStorage.key(index);
176
+ if (key?.startsWith(prefix)) {
177
+ (0, import_session.removeSessionStorageItem)(key);
178
+ }
179
+ }
180
+ }
181
+ };
182
+ }
183
+ function buildStashKey(elementId, childType) {
184
+ return `${STASH_KEY_PREFIX}/${elementId}/${STASH_KEY_SEGMENT}/${childType}`;
185
+ }
186
+ function buildElementStashPrefix(elementId) {
187
+ return `${STASH_KEY_PREFIX}/${elementId}/${STASH_KEY_SEGMENT}/`;
188
+ }
189
+
190
+ // src/children-dependencies/utils.ts
191
+ var import_editor_props = require("@elementor/editor-props");
192
+ function evaluateWhen(when, settings) {
193
+ return (0, import_editor_props.isDependencyMet)(when, settings).isMet;
194
+ }
195
+
196
+ // src/children-dependencies/bind-settings-reconcile.ts
197
+ function bindSettingsReconcile({ model, elementConfig }) {
198
+ const stash = createChildrenStash();
199
+ const rules = elementConfig?.children_dependencies;
200
+ if (!rules?.length) {
201
+ return () => {
202
+ };
203
+ }
204
+ const settingsModel = model.get("settings");
205
+ const elementId = model.get("id");
206
+ if (!settingsModel?.on || !settingsModel?.off || !elementId) {
207
+ return () => {
208
+ };
209
+ }
210
+ const lastMet = /* @__PURE__ */ new Map();
211
+ rules.forEach((rule) => {
212
+ lastMet.set(rule.child_type, evaluateWhen(rule.when, settingsModel.toJSON()));
213
+ });
214
+ const onChange = () => {
215
+ const currentSettings = settingsModel.toJSON();
216
+ rules.forEach((rule) => {
217
+ const previous = lastMet.get(rule.child_type) ?? false;
218
+ const current = evaluateWhen(rule.when, currentSettings);
219
+ if (previous === current) {
220
+ return;
221
+ }
222
+ lastMet.set(rule.child_type, current);
223
+ if (current) {
224
+ attachChildFromRule(elementId, rule, stash);
225
+ } else {
226
+ detachChildFromRule(elementId, rule, stash);
227
+ }
228
+ });
229
+ };
230
+ settingsModel.on("change", onChange);
231
+ return () => {
232
+ settingsModel.off?.("change", onChange);
233
+ stash.clearAllForElement(elementId);
234
+ };
235
+ }
236
+ function attachChildFromRule(parentId, rule, stash) {
237
+ const parent = getContainer(parentId) ?? void 0;
238
+ const currentChildren = getDirectChildData(parent);
239
+ const alreadyPresent = currentChildren.some((child) => child.elType === rule.child_type);
240
+ if (alreadyPresent) {
241
+ return;
242
+ }
243
+ const stashed = rule.stash ? stash.get(parentId, rule.child_type) : void 0;
244
+ const modelData = stashed ?? rule.default_model ?? { elType: rule.child_type };
245
+ const insertAt = resolveInsertIndex(rule.position, currentChildren);
246
+ const attached = addModelToParent(parentId, modelData, { at: insertAt });
247
+ if (!attached) {
248
+ return;
249
+ }
250
+ if (stashed) {
251
+ stash.clear(parentId, rule.child_type);
252
+ }
253
+ requestNavigatorRefresh(parentId);
254
+ }
255
+ function detachChildFromRule(parentId, rule, stash) {
256
+ const parent = getContainer(parentId) ?? void 0;
257
+ const child = parent?.children?.find((candidate) => candidate.model.get("elType") === rule.child_type);
258
+ if (!child) {
259
+ return;
260
+ }
261
+ const childSnapshot = child.model.toJSON();
262
+ const removed = removeModelFromParent(parentId, child.id);
263
+ if (!removed) {
264
+ return;
265
+ }
266
+ if (rule.stash) {
267
+ stash.save(parentId, rule.child_type, childSnapshot);
268
+ }
269
+ requestNavigatorRefresh(parentId);
270
+ }
271
+ function requestNavigatorRefresh(parentId) {
272
+ if (typeof window === "undefined" || typeof window.dispatchEvent !== "function") {
273
+ return;
274
+ }
275
+ window.dispatchEvent(
276
+ new CustomEvent("elementor/navigator/refresh-children", {
277
+ detail: { elementId: parentId }
278
+ })
279
+ );
280
+ }
281
+ function getDirectChildData(parent) {
282
+ return (parent?.children ?? []).map((child) => child.model.toJSON());
283
+ }
284
+
285
+ // src/children-dependencies/reconcile-initial-children.ts
286
+ function reconcileInitialChildren({
287
+ elementId,
288
+ elementConfig,
289
+ attributes
290
+ }) {
291
+ const stash = createChildrenStash();
292
+ const rules = elementConfig?.children_dependencies;
293
+ if (!rules?.length) {
294
+ return;
295
+ }
296
+ const elements = [...attributes.elements ?? []];
297
+ const settings = attributes.settings ?? {};
298
+ rules.forEach((rule) => {
299
+ const isMet = evaluateWhen(rule.when, settings);
300
+ const existingIndex = elements.findIndex((element) => element.elType === rule.child_type);
301
+ const isPresent = existingIndex >= 0;
302
+ if (isMet && !isPresent) {
303
+ const stashed = rule.stash ? stash.get(elementId, rule.child_type) : void 0;
304
+ const modelData = stashed ?? rule.default_model ?? { elType: rule.child_type };
305
+ const insertAt = resolveInsertIndex(rule.position, elements);
306
+ elements.splice(insertAt, 0, modelData);
307
+ if (stashed) {
308
+ stash.clear(elementId, rule.child_type);
309
+ }
310
+ return;
311
+ }
312
+ if (!isMet && isPresent) {
313
+ const [removed] = elements.splice(existingIndex, 1);
314
+ if (rule.stash && removed) {
315
+ stash.save(elementId, rule.child_type, removed);
316
+ }
317
+ }
318
+ });
319
+ attributes.elements = elements;
320
+ }
321
+
322
+ // src/hooks/use-element-children.ts
323
+ var import_editor_v1_adapters2 = require("@elementor/editor-v1-adapters");
324
+
97
325
  // src/sync/model-utils.ts
98
326
  function findChildRecursive(model, predicate) {
99
327
  const childModels = model.get("elements") ?? [];
@@ -320,40 +548,6 @@ function deleteElement({ container, options = {} }) {
320
548
  });
321
549
  }
322
550
 
323
- // src/sync/resolve-element.ts
324
- function isConnected(container) {
325
- if (!container) {
326
- return false;
327
- }
328
- if (!container.view?.el) {
329
- return true;
330
- }
331
- return container.view.el.isConnected;
332
- }
333
- function resolveContainer(container, id) {
334
- const looked = container.lookup?.();
335
- if (isConnected(looked)) {
336
- return looked;
337
- }
338
- const byId = getContainer(id);
339
- if (isConnected(byId)) {
340
- return byId;
341
- }
342
- return null;
343
- }
344
- function getDocumentUtils() {
345
- return window.$e?.components?.get?.("document")?.utils;
346
- }
347
- function findModelInDocument(id) {
348
- return getDocumentUtils()?.findModelById?.(id) ?? null;
349
- }
350
- function addModelToParent(parentId, childData, options) {
351
- return getDocumentUtils()?.addModelToParent?.(parentId, childData, options) ?? false;
352
- }
353
- function removeModelFromParent(parentId, childId) {
354
- return getDocumentUtils()?.removeModelFromParent?.(parentId, childId) ?? false;
355
- }
356
-
357
551
  // src/sync/create-elements.ts
358
552
  var createElements = ({
359
553
  elements,
@@ -591,28 +785,28 @@ function getElementIcon(elementId) {
591
785
  }
592
786
 
593
787
  // src/errors.ts
594
- var import_utils = require("@elementor/utils");
595
- var ElementNotFoundError = (0, import_utils.createError)({
788
+ var import_utils4 = require("@elementor/utils");
789
+ var ElementNotFoundError = (0, import_utils4.createError)({
596
790
  code: "element_not_found",
597
791
  message: "Element not found."
598
792
  });
599
- var StyleNotFoundError = (0, import_utils.createError)({
793
+ var StyleNotFoundError = (0, import_utils4.createError)({
600
794
  code: "style_not_found",
601
795
  message: "Style not found."
602
796
  });
603
- var ElementTypeNotExistsError = (0, import_utils.createError)({
797
+ var ElementTypeNotExistsError = (0, import_utils4.createError)({
604
798
  code: "element_type_not_exists",
605
799
  message: "Element type does not exist."
606
800
  });
607
- var ElementLabelNotExistsError = (0, import_utils.createError)({
801
+ var ElementLabelNotExistsError = (0, import_utils4.createError)({
608
802
  code: "element_label_not_exists",
609
803
  message: "Element label does not exist."
610
804
  });
611
- var ElementParentNotFoundError = (0, import_utils.createError)({
805
+ var ElementParentNotFoundError = (0, import_utils4.createError)({
612
806
  code: "element_parent_not_found",
613
807
  message: "Element parent not found."
614
808
  });
615
- var ElementIndexNotFoundError = (0, import_utils.createError)({
809
+ var ElementIndexNotFoundError = (0, import_utils4.createError)({
616
810
  code: "element_index_not_found",
617
811
  message: "Element index not found."
618
812
  });
@@ -1118,11 +1312,11 @@ var styleRerenderEvents = [
1118
1312
  ];
1119
1313
 
1120
1314
  // src/styles/create-element-style.ts
1121
- var import_editor_props2 = require("@elementor/editor-props");
1315
+ var import_editor_props3 = require("@elementor/editor-props");
1122
1316
  var import_editor_styles = require("@elementor/editor-styles");
1123
1317
 
1124
1318
  // src/styles/mutate-element-styles.ts
1125
- var import_editor_props = require("@elementor/editor-props");
1319
+ var import_editor_props2 = require("@elementor/editor-props");
1126
1320
  var import_editor_v1_adapters18 = require("@elementor/editor-v1-adapters");
1127
1321
  function mutateElementStyles(elementId, mutator) {
1128
1322
  const container = getContainer(elementId);
@@ -1174,7 +1368,7 @@ function clearRemovedClasses(container, { oldIds, newIds }) {
1174
1368
  function getClassesProps(container) {
1175
1369
  return Object.entries(container.settings.toJSON()).filter((prop) => {
1176
1370
  const [, value] = prop;
1177
- return import_editor_props.classesPropTypeUtil.isValid(value);
1371
+ return import_editor_props2.classesPropTypeUtil.isValid(value);
1178
1372
  });
1179
1373
  }
1180
1374
  function notifyChanges() {
@@ -1213,7 +1407,7 @@ function createElementStyle({
1213
1407
  }
1214
1408
  function addStyleToClassesProp(elementId, classesProp, styleId) {
1215
1409
  const base = getElementSetting(elementId, classesProp);
1216
- const classesPropValue = import_editor_props2.classesPropTypeUtil.create(
1410
+ const classesPropValue = import_editor_props3.classesPropTypeUtil.create(
1217
1411
  (prev) => {
1218
1412
  return [...prev ?? [], styleId];
1219
1413
  },
@@ -1240,7 +1434,7 @@ function deleteElementStyle(elementId, styleId) {
1240
1434
  }
1241
1435
 
1242
1436
  // src/styles/update-element-style.ts
1243
- var import_editor_props3 = require("@elementor/editor-props");
1437
+ var import_editor_props4 = require("@elementor/editor-props");
1244
1438
  var import_editor_styles2 = require("@elementor/editor-styles");
1245
1439
  function updateElementStyle(args) {
1246
1440
  mutateElementStyles(args.elementId, (styles) => {
@@ -1251,7 +1445,7 @@ function updateElementStyle(args) {
1251
1445
  const variant = (0, import_editor_styles2.getVariantByMeta)(style, args.meta);
1252
1446
  const customCss = ("custom_css" in args ? args.custom_css : variant?.custom_css) ?? null;
1253
1447
  if (variant) {
1254
- variant.props = (0, import_editor_props3.mergeProps)(variant.props, args.props);
1448
+ variant.props = (0, import_editor_props4.mergeProps)(variant.props, args.props);
1255
1449
  variant.custom_css = customCss?.raw ? customCss : null;
1256
1450
  } else {
1257
1451
  style.variants.push({ meta: args.meta, props: args.props, custom_css: customCss });
@@ -1293,6 +1487,7 @@ var playElementInteractions = (elementId, interactionId) => {
1293
1487
  0 && (module.exports = {
1294
1488
  ELEMENT_STYLE_CHANGE_EVENT,
1295
1489
  addModelToParent,
1490
+ bindSettingsReconcile,
1296
1491
  createElement,
1297
1492
  createElementStyle,
1298
1493
  createElements,
@@ -1301,6 +1496,7 @@ var playElementInteractions = (elementId, interactionId) => {
1301
1496
  dropElement,
1302
1497
  duplicateElement,
1303
1498
  duplicateElements,
1499
+ evaluateWhen,
1304
1500
  findChildRecursive,
1305
1501
  findModelInDocument,
1306
1502
  generateElementId,
@@ -1328,10 +1524,12 @@ var playElementInteractions = (elementId, interactionId) => {
1328
1524
  moveElement,
1329
1525
  moveElements,
1330
1526
  playElementInteractions,
1527
+ reconcileInitialChildren,
1331
1528
  removeElements,
1332
1529
  removeModelFromParent,
1333
1530
  replaceElement,
1334
1531
  resolveContainer,
1532
+ resolveInsertIndex,
1335
1533
  selectElement,
1336
1534
  shouldCreateNewLocalStyle,
1337
1535
  styleRerenderEvents,