@elementor/editor-elements 4.3.0-981 → 4.3.0-983

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.
@@ -6,7 +6,7 @@ import { resolveInsertIndex } from '../sync/resolve-insert-index';
6
6
  import { type V1Element, type V1ElementConfig, type V1ElementData, type V1ElementModelProps } from '../sync/types';
7
7
  import { createChildrenStash } from './stash';
8
8
  import { type ChildDependencyRule, type ChildrenStash } from './types';
9
- import { evaluateWhen } from './utils';
9
+ import { evaluateWhen, resolveChildModelData } from './utils';
10
10
 
11
11
  type SettingsChangeSource = {
12
12
  get: ( key: string ) => unknown;
@@ -85,8 +85,7 @@ function attachChildFromRule( parentId: string, rule: ChildDependencyRule, stash
85
85
  return;
86
86
  }
87
87
 
88
- const stashed = rule.stash ? stash.get( parentId, rule.child_type ) : undefined;
89
- const modelData = stashed ?? rule.default_model ?? ( { elType: rule.child_type } as V1ElementData );
88
+ const { modelData, wasStashed } = resolveChildModelData( parentId, rule, stash );
90
89
  const insertAt = resolveInsertIndex( rule.position, currentChildren );
91
90
 
92
91
  const attached = addModelToParent( parentId, modelData as unknown as V1ElementModelProps, { at: insertAt } );
@@ -95,7 +94,7 @@ function attachChildFromRule( parentId: string, rule: ChildDependencyRule, stash
95
94
  return;
96
95
  }
97
96
 
98
- if ( stashed ) {
97
+ if ( wasStashed ) {
99
98
  stash.clear( parentId, rule.child_type );
100
99
  }
101
100
 
@@ -2,7 +2,7 @@ import { resolveInsertIndex } from '../sync/resolve-insert-index';
2
2
  import { type V1ElementConfig, type V1ElementData, type V1ElementSettingsProps } from '../sync/types';
3
3
  import { createChildrenStash } from './stash';
4
4
  import { type ChildDependencyRule } from './types';
5
- import { evaluateWhen } from './utils';
5
+ import { evaluateWhen, resolveChildModelData } from './utils';
6
6
 
7
7
  type ReconcileInitialChildrenArgs = {
8
8
  elementId: string;
@@ -34,13 +34,12 @@ export function reconcileInitialChildren( {
34
34
  const isPresent = existingIndex >= 0;
35
35
 
36
36
  if ( isMet && ! isPresent ) {
37
- const stashed = rule.stash ? stash.get( elementId, rule.child_type ) : undefined;
38
- const modelData = stashed ?? rule.default_model ?? ( { elType: rule.child_type } as V1ElementData );
37
+ const { modelData, wasStashed } = resolveChildModelData( elementId, rule, stash );
39
38
  const insertAt = resolveInsertIndex( rule.position, elements );
40
39
 
41
40
  elements.splice( insertAt, 0, modelData );
42
41
 
43
- if ( stashed ) {
42
+ if ( wasStashed ) {
44
43
  stash.clear( elementId, rule.child_type );
45
44
  }
46
45
 
@@ -1,5 +1,44 @@
1
1
  import { type Dependency, isDependencyMet, type PropValue } from '@elementor/editor-props';
2
2
 
3
+ import { generateElementId } from '../sync/generate-element-id';
4
+ import { type V1ElementData } from '../sync/types';
5
+ import { type ChildDependencyRule, type ChildrenStash } from './types';
6
+
3
7
  export function evaluateWhen( when: Dependency | undefined, settings: Record< string, PropValue > ): boolean {
4
8
  return isDependencyMet( when, settings ).isMet;
5
9
  }
10
+
11
+ export function ensureModelId( model: V1ElementData ): V1ElementData {
12
+ const { skipDefaultChildren: _skipDefaultChildren, ...rest } = model;
13
+
14
+ return rest.id ? rest : { ...rest, id: generateElementId() };
15
+ }
16
+
17
+ type ResolvedChildModel = {
18
+ modelData: V1ElementData;
19
+ wasStashed: boolean;
20
+ };
21
+
22
+ /**
23
+ * Resolve the model to attach for a child-dependency rule, preferring a previously-stashed
24
+ * (user-customized) model, then the rule's default, else a bare element.
25
+ *
26
+ * `default_model` and the bare fallback never carry an id, so they're run through
27
+ * `ensureModelId` before the model reaches Backbone.
28
+ *
29
+ * @param elementId Parent element id, used as the stash lookup key.
30
+ * @param rule The child-dependency rule being resolved.
31
+ * @param stash Session-backed stash for previously-detached child models.
32
+ */
33
+ export function resolveChildModelData(
34
+ elementId: string,
35
+ rule: ChildDependencyRule,
36
+ stash: ChildrenStash
37
+ ): ResolvedChildModel {
38
+ const stashed = rule.stash ? stash.get( elementId, rule.child_type ) : undefined;
39
+ const modelData = ensureModelId(
40
+ stashed ?? rule.default_model ?? ( { elType: rule.child_type } as V1ElementData )
41
+ );
42
+
43
+ return { modelData, wasStashed: Boolean( stashed ) };
44
+ }
package/src/sync/types.ts CHANGED
@@ -163,6 +163,7 @@ export type V1ElementModelProps = {
163
163
  interactions?: string | ElementInteractions;
164
164
  isGlobal?: boolean;
165
165
  skipDefaultChildren?: boolean;
166
+ hydrateDefaultChildren?: boolean;
166
167
  };
167
168
 
168
169
  export type V1ElementData = Omit< V1ElementModelProps, 'elements' > & {