@webiny/website-builder-sdk 6.3.0 → 6.4.0-beta.0
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/BindingsApi.js +29 -36
- package/BindingsApi.js.map +1 -1
- package/BindingsProcessor.js +34 -43
- package/BindingsProcessor.js.map +1 -1
- package/BindingsProcessor.test.js +82 -78
- package/BindingsProcessor.test.js.map +1 -1
- package/BindingsResolver.js +92 -119
- package/BindingsResolver.js.map +1 -1
- package/BindingsResolver.test.js +399 -363
- package/BindingsResolver.test.js.map +1 -1
- package/ComponentInputTraverser.js +28 -49
- package/ComponentInputTraverser.js.map +1 -1
- package/ComponentManifestToAstConverter.js +20 -21
- package/ComponentManifestToAstConverter.js.map +1 -1
- package/ComponentRegistry.js +26 -45
- package/ComponentRegistry.js.map +1 -1
- package/ComponentResolver.js +25 -29
- package/ComponentResolver.js.map +1 -1
- package/ConstraintEvaluator.js +246 -353
- package/ConstraintEvaluator.js.map +1 -1
- package/ConstraintEvaluator.test.js +1616 -1438
- package/ConstraintEvaluator.test.js.map +1 -1
- package/ContentSdk.js +83 -90
- package/ContentSdk.js.map +1 -1
- package/DocumentStore.js +47 -59
- package/DocumentStore.js.map +1 -1
- package/DocumentStoreManager.js +17 -16
- package/DocumentStoreManager.js.map +1 -1
- package/EditingSdk.js +87 -121
- package/EditingSdk.js.map +1 -1
- package/ElementFactory.js +126 -174
- package/ElementFactory.js.map +1 -1
- package/ElementFactory.test.js +234 -263
- package/ElementFactory.test.js.map +1 -1
- package/Environment.js +18 -19
- package/Environment.js.map +1 -1
- package/FunctionConverter.js +8 -7
- package/FunctionConverter.js.map +1 -1
- package/HashObject.js +11 -26
- package/HashObject.js.map +1 -1
- package/HotkeyManager.js +40 -47
- package/HotkeyManager.js.map +1 -1
- package/IBindingsUpdater.js +0 -3
- package/IRedirects.js +0 -3
- package/InheritanceProcessor.js +99 -139
- package/InheritanceProcessor.js.map +1 -1
- package/InheritanceProcessor.test.js +178 -179
- package/InheritanceProcessor.test.js.map +1 -1
- package/InheritedValueResolver.js +15 -20
- package/InheritedValueResolver.js.map +1 -1
- package/InputBindingsProcessor.js +187 -307
- package/InputBindingsProcessor.js.map +1 -1
- package/InputsBindingsProcessor.test.js +334 -315
- package/InputsBindingsProcessor.test.js.map +1 -1
- package/InputsUpdater.js +23 -26
- package/InputsUpdater.js.map +1 -1
- package/LiveSdk.js +12 -13
- package/LiveSdk.js.map +1 -1
- package/Logger.js +9 -8
- package/Logger.js.map +1 -1
- package/MouseTracker.js +77 -83
- package/MouseTracker.js.map +1 -1
- package/NullSdk.js +22 -21
- package/NullSdk.js.map +1 -1
- package/PreviewDocument.js +27 -30
- package/PreviewDocument.js.map +1 -1
- package/PreviewSdk.js +16 -17
- package/PreviewSdk.js.map +1 -1
- package/PreviewViewport.js +51 -63
- package/PreviewViewport.js.map +1 -1
- package/ResizeObserver.js +24 -31
- package/ResizeObserver.js.map +1 -1
- package/StylesBindingsProcessor.js +40 -79
- package/StylesBindingsProcessor.js.map +1 -1
- package/StylesUpdater.js +20 -25
- package/StylesUpdater.js.map +1 -1
- package/Theme.js +28 -25
- package/Theme.js.map +1 -1
- package/ViewportManager.js +89 -101
- package/ViewportManager.js.map +1 -1
- package/constants.js +7 -6
- package/constants.js.map +1 -1
- package/createElement.js +5 -6
- package/createElement.js.map +1 -1
- package/createInput.js +85 -143
- package/createInput.js.map +1 -1
- package/createTheme.js +2 -3
- package/createTheme.js.map +1 -1
- package/dataProviders/ApiClient.js +40 -49
- package/dataProviders/ApiClient.js.map +1 -1
- package/dataProviders/DefaultDataProvider.js +56 -58
- package/dataProviders/DefaultDataProvider.js.map +1 -1
- package/dataProviders/GET_PAGE_BY_ID.js +2 -1
- package/dataProviders/GET_PAGE_BY_ID.js.map +1 -1
- package/dataProviders/GET_PAGE_BY_PATH.js +2 -1
- package/dataProviders/GET_PAGE_BY_PATH.js.map +1 -1
- package/dataProviders/LIST_PUBLISHED_PAGES.js +2 -1
- package/dataProviders/LIST_PUBLISHED_PAGES.js.map +1 -1
- package/dataProviders/NullDataProvider.js +21 -20
- package/dataProviders/NullDataProvider.js.map +1 -1
- package/dataProviders/RedirectsProvider.js +24 -27
- package/dataProviders/RedirectsProvider.js.map +1 -1
- package/defaultBreakpoints.js +23 -22
- package/defaultBreakpoints.js.map +1 -1
- package/documentOperations/$addElementReferenceToParent.js +29 -32
- package/documentOperations/$addElementReferenceToParent.js.map +1 -1
- package/documentOperations/AddElement.js +8 -7
- package/documentOperations/AddElement.js.map +1 -1
- package/documentOperations/AddToParent.js +14 -13
- package/documentOperations/AddToParent.js.map +1 -1
- package/documentOperations/IDocumentOperation.js +0 -3
- package/documentOperations/RemoveElement.js +9 -15
- package/documentOperations/RemoveElement.js.map +1 -1
- package/documentOperations/SetGlobalInputBinding.js +23 -22
- package/documentOperations/SetGlobalInputBinding.js.map +1 -1
- package/documentOperations/SetGlobalStyleBinding.js +23 -23
- package/documentOperations/SetGlobalStyleBinding.js.map +1 -1
- package/documentOperations/SetInputBindingOverride.js +30 -29
- package/documentOperations/SetInputBindingOverride.js.map +1 -1
- package/documentOperations/SetStyleBindingOverride.js +30 -31
- package/documentOperations/SetStyleBindingOverride.js.map +1 -1
- package/documentOperations/index.js +9 -8
- package/documentOperations/index.js.map +1 -1
- package/findMatchingAstNode.js +11 -13
- package/findMatchingAstNode.js.map +1 -1
- package/generateElementId.js +2 -1
- package/generateElementId.js.map +1 -1
- package/headersProvider.js +4 -3
- package/headersProvider.js.map +1 -1
- package/index.js +0 -2
- package/jsonPatch.js +5 -9
- package/jsonPatch.js.map +1 -1
- package/messages.js +12 -11
- package/messages.js.map +1 -1
- package/messenger/MessageOrigin.js +12 -11
- package/messenger/MessageOrigin.js.map +1 -1
- package/messenger/Messenger.js +58 -69
- package/messenger/Messenger.js.map +1 -1
- package/messenger/index.js +0 -2
- package/package.json +5 -5
- package/registerComponentGroup.js +5 -6
- package/registerComponentGroup.js.map +1 -1
- package/types/ShorthandCssProperties.js +0 -3
- package/types/WebsiteBuilderTheme.js +0 -3
- package/types.d.ts +3 -0
- package/types.js +0 -3
- package/IBindingsUpdater.js.map +0 -1
- package/IRedirects.js.map +0 -1
- package/documentOperations/IDocumentOperation.js.map +0 -1
- package/index.js.map +0 -1
- package/messenger/index.js.map +0 -1
- package/types/ShorthandCssProperties.js.map +0 -1
- package/types/WebsiteBuilderTheme.js.map +0 -1
- package/types.js.map +0 -1
|
@@ -1,324 +1,204 @@
|
|
|
1
|
-
import
|
|
1
|
+
import deep_equal from "deep-equal";
|
|
2
2
|
import set from "lodash/set.js";
|
|
3
3
|
import { InheritedValueResolver } from "./InheritedValueResolver.js";
|
|
4
4
|
import { DocumentOperations } from "./documentOperations/index.js";
|
|
5
5
|
import { InputsUpdater } from "./InputsUpdater.js";
|
|
6
6
|
import { generateElementId } from "./generateElementId.js";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
this.breakpoints = breakpoints;
|
|
16
|
-
this.rawBindings = rawBindings;
|
|
17
|
-
this.elementFactory = elementFactory;
|
|
18
|
-
this.elementReferences = this.getElementReferences(rawBindings.inputs);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Converts flat input bindings into deep inputs object (removes `.static` wrappers).
|
|
23
|
-
*/
|
|
24
|
-
toDeepInputs(flat) {
|
|
25
|
-
const result = {};
|
|
26
|
-
|
|
27
|
-
// Assigns a value to a nested path within the result object, creating arrays/objects as needed.
|
|
28
|
-
const assignValue = (path, value) => {
|
|
29
|
-
let current = result;
|
|
30
|
-
for (let i = 0; i < path.length - 1; i++) {
|
|
31
|
-
const key = path[i];
|
|
32
|
-
const nextKey = path[i + 1];
|
|
33
|
-
const isNextIndex = typeof nextKey === "number";
|
|
34
|
-
if (typeof key === "number") {
|
|
35
|
-
if (!Array.isArray(current)) {
|
|
36
|
-
throw new Error("Expected array in path assignment.");
|
|
37
|
-
}
|
|
38
|
-
while (current.length <= key) {
|
|
39
|
-
current.push(isNextIndex ? [] : {});
|
|
40
|
-
}
|
|
41
|
-
if (typeof current[key] !== "object") {
|
|
42
|
-
current[key] = isNextIndex ? [] : {};
|
|
43
|
-
}
|
|
44
|
-
current = current[key];
|
|
45
|
-
} else {
|
|
46
|
-
if (!(key in current) || typeof current[key] !== "object") {
|
|
47
|
-
current[key] = isNextIndex ? [] : {};
|
|
48
|
-
}
|
|
49
|
-
current = current[key];
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
current[path[path.length - 1]] = value;
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
// Recursively walks the AST and assigns values from flat bindings to the nested result.
|
|
56
|
-
const walk = (nodes, prefix) => {
|
|
57
|
-
for (const node of nodes) {
|
|
58
|
-
const pathParts = [...prefix, node.name];
|
|
59
|
-
const flatKey = pathParts.join("/");
|
|
60
|
-
const entry = flat[flatKey];
|
|
61
|
-
const staticValue = entry?.static;
|
|
62
|
-
if (node.children.length > 0) {
|
|
63
|
-
if (node.list) {
|
|
64
|
-
const pattern = new RegExp(`^${flatKey}\\/(\\d+)\\/`);
|
|
65
|
-
const indexes = Object.keys(flat).reduce((acc, key) => {
|
|
66
|
-
const match = key.match(pattern);
|
|
67
|
-
if (match) {
|
|
68
|
-
acc.push(parseInt(match[1], 10));
|
|
69
|
-
}
|
|
70
|
-
return acc;
|
|
71
|
-
}, []);
|
|
72
|
-
const uniqueIndexes = Array.from(new Set(indexes)).sort((a, b) => a - b);
|
|
73
|
-
for (const i of uniqueIndexes) {
|
|
74
|
-
walk(node.children, [...prefix, `${node.name}/${i}`]);
|
|
75
|
-
}
|
|
76
|
-
} else {
|
|
77
|
-
walk(node.children, pathParts);
|
|
78
|
-
}
|
|
79
|
-
} else if (staticValue !== undefined) {
|
|
80
|
-
const path = pathParts.reduce((acc, part) => {
|
|
81
|
-
const match = part.match(/(.*?)\/(\d+)/);
|
|
82
|
-
if (match) {
|
|
83
|
-
acc.push(match[1], Number(match[2]));
|
|
84
|
-
} else {
|
|
85
|
-
acc.push(part);
|
|
86
|
-
}
|
|
87
|
-
return acc;
|
|
88
|
-
}, []);
|
|
89
|
-
assignValue(path, staticValue);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
walk(this.inputsAst, []);
|
|
94
|
-
return result;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Flattens deep inputs object into flat bindings with `.static` wrappers,
|
|
99
|
-
* skipping overrides that match inherited parent breakpoint values.
|
|
100
|
-
*/
|
|
101
|
-
createUpdate(inputs, breakpoint) {
|
|
102
|
-
const operations = [];
|
|
103
|
-
const originalInputs = this.rawBindings.inputs ?? {};
|
|
104
|
-
const rebuilt = {
|
|
105
|
-
inputs: {},
|
|
106
|
-
overrides: {}
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
// Clone existing overrides if present, to avoid losing breakpoint overrides
|
|
110
|
-
if (this.rawBindings.overrides) {
|
|
111
|
-
for (const [bp, overrides] of Object.entries(this.rawBindings.overrides)) {
|
|
112
|
-
if (overrides.inputs) {
|
|
113
|
-
set(rebuilt, `overrides.${bp}.inputs`, structuredClone(this.rawBindings.overrides[bp].inputs));
|
|
114
|
-
}
|
|
115
|
-
}
|
|
7
|
+
class InputsBindingsProcessor {
|
|
8
|
+
constructor(elementId, inputsAst, breakpoints, rawBindings, elementFactory){
|
|
9
|
+
this.elementId = elementId;
|
|
10
|
+
this.inputsAst = inputsAst;
|
|
11
|
+
this.breakpoints = breakpoints;
|
|
12
|
+
this.rawBindings = rawBindings;
|
|
13
|
+
this.elementFactory = elementFactory;
|
|
14
|
+
this.elementReferences = this.getElementReferences(rawBindings.inputs);
|
|
116
15
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
return /^\d+$/.test(part) ? parseInt(part, 10) : part;
|
|
134
|
-
});
|
|
135
|
-
});
|
|
136
|
-
return keys.reduce((acc, key) => acc ? acc[key] : undefined, obj);
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
// Recursively traverses the AST nodes, comparing new input values with original bindings.
|
|
140
|
-
// Collects changed values into 'rebuilt' and generates operations for new elements.
|
|
141
|
-
const compareAndCollect = (nodes, prefix) => {
|
|
142
|
-
for (const node of nodes) {
|
|
143
|
-
const pathParts = [...prefix, node.name];
|
|
144
|
-
const flatKey = pathParts.join("/");
|
|
145
|
-
|
|
146
|
-
// Mark this path as seen
|
|
147
|
-
seenPaths.add(flatKey);
|
|
148
|
-
if (node.children.length) {
|
|
149
|
-
if (node.list) {
|
|
150
|
-
// For list nodes, process each indexed item separately
|
|
151
|
-
const list = getValue(inputs, flatKey);
|
|
152
|
-
if (Array.isArray(list)) {
|
|
153
|
-
for (let i = 0; i < list.length; i++) {
|
|
154
|
-
// Recurse with indexed path like 'rows[0]', 'rows[1]'
|
|
155
|
-
compareAndCollect(node.children, [...pathParts.slice(0, -1), `${node.name}/${i}`]);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
} else {
|
|
159
|
-
// For single object nodes, recurse normally
|
|
160
|
-
compareAndCollect(node.children, pathParts);
|
|
161
|
-
}
|
|
162
|
-
} else {
|
|
163
|
-
// Leaf node (primitive or slot) processing
|
|
164
|
-
|
|
165
|
-
// Get current new value from deep inputs
|
|
166
|
-
let newValue = getValue(inputs, flatKey);
|
|
167
|
-
|
|
168
|
-
// Get original binding entry for this path
|
|
169
|
-
const originalEntry = originalInputs[flatKey];
|
|
170
|
-
|
|
171
|
-
// Skip if newValue is undefined and no original entry
|
|
172
|
-
if (newValue === undefined && !originalEntry) {
|
|
173
|
-
continue;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
// For list slots, process CreateElement items within the array.
|
|
177
|
-
if (node.list && Array.isArray(newValue)) {
|
|
178
|
-
newValue = newValue.map(item => {
|
|
179
|
-
if (typeof item === "object" && item !== null && item.action === "CreateElement") {
|
|
180
|
-
const newElement = this.elementFactory.createElementFromComponent({
|
|
181
|
-
componentName: item.params.component,
|
|
182
|
-
parentId: this.elementId,
|
|
183
|
-
slot: flatKey,
|
|
184
|
-
bindings: item.params
|
|
185
|
-
});
|
|
186
|
-
// Skip AddToParent — this processor manages the binding array.
|
|
187
|
-
operations.push(...newElement.operations.filter(op => !(op instanceof DocumentOperations.AddToParent)));
|
|
188
|
-
return newElement.element.id;
|
|
189
|
-
}
|
|
190
|
-
return item;
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
if (!Array.isArray(newValue) && typeof newValue === "object" && newValue?.action === "CreateElement") {
|
|
194
|
-
// Handle single (non-list) CreateElement action
|
|
195
|
-
const newElement = this.elementFactory.createElementFromComponent({
|
|
196
|
-
componentName: newValue.params.component,
|
|
197
|
-
parentId: this.elementId,
|
|
198
|
-
slot: flatKey,
|
|
199
|
-
index: -1,
|
|
200
|
-
bindings: newValue.params
|
|
201
|
-
});
|
|
202
|
-
const createdId = newElement.element.id;
|
|
203
|
-
|
|
204
|
-
// Assign or generate a stable unique id for the binding
|
|
205
|
-
const existingId = originalEntry?.id;
|
|
206
|
-
const idToUse = existingId ?? generateElementId();
|
|
207
|
-
|
|
208
|
-
// Build binding for the new element id(s)
|
|
209
|
-
const binding = {
|
|
210
|
-
static: createdId,
|
|
211
|
-
type: node.type,
|
|
212
|
-
list: node.list,
|
|
213
|
-
id: idToUse
|
|
214
|
-
};
|
|
215
|
-
if (node.input?.responsive && !this.isBaseBreakpoint(breakpoint)) {
|
|
216
|
-
const inheritedValue = valueResolver.getInheritedValue(flatKey, breakpoint);
|
|
217
|
-
if (binding.static === undefined) {
|
|
218
|
-
// Unset override
|
|
219
|
-
if (rebuilt.overrides[breakpoint]?.inputs?.[flatKey]) {
|
|
220
|
-
delete rebuilt.overrides[breakpoint].inputs[flatKey];
|
|
221
|
-
}
|
|
222
|
-
} else if (inheritedValue === undefined || !deepEqual(inheritedValue, binding.static)) {
|
|
223
|
-
if (!rebuilt.overrides[breakpoint]) {
|
|
224
|
-
rebuilt.overrides[breakpoint] = {
|
|
225
|
-
inputs: {}
|
|
226
|
-
};
|
|
227
|
-
}
|
|
228
|
-
rebuilt.overrides[breakpoint].inputs[flatKey] = binding;
|
|
229
|
-
} else {
|
|
230
|
-
if (rebuilt.overrides[breakpoint]?.inputs?.[flatKey]) {
|
|
231
|
-
delete rebuilt.overrides[breakpoint].inputs[flatKey];
|
|
16
|
+
toDeepInputs(flat) {
|
|
17
|
+
const result = {};
|
|
18
|
+
const assignValue = (path, value)=>{
|
|
19
|
+
let current = result;
|
|
20
|
+
for(let i = 0; i < path.length - 1; i++){
|
|
21
|
+
const key = path[i];
|
|
22
|
+
const nextKey = path[i + 1];
|
|
23
|
+
const isNextIndex = "number" == typeof nextKey;
|
|
24
|
+
if ("number" == typeof key) {
|
|
25
|
+
if (!Array.isArray(current)) throw new Error("Expected array in path assignment.");
|
|
26
|
+
while(current.length <= key)current.push(isNextIndex ? [] : {});
|
|
27
|
+
if ("object" != typeof current[key]) current[key] = isNextIndex ? [] : {};
|
|
28
|
+
current = current[key];
|
|
29
|
+
} else {
|
|
30
|
+
if (!(key in current) || "object" != typeof current[key]) current[key] = isNextIndex ? [] : {};
|
|
31
|
+
current = current[key];
|
|
232
32
|
}
|
|
233
|
-
}
|
|
234
|
-
if (originalEntry) {
|
|
235
|
-
rebuilt.inputs[flatKey] = originalEntry;
|
|
236
|
-
}
|
|
237
|
-
} else {
|
|
238
|
-
// Normal case: update base inputs
|
|
239
|
-
rebuilt.inputs[flatKey] = binding;
|
|
240
33
|
}
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
34
|
+
current[path[path.length - 1]] = value;
|
|
35
|
+
};
|
|
36
|
+
const walk = (nodes, prefix)=>{
|
|
37
|
+
for (const node of nodes){
|
|
38
|
+
const pathParts = [
|
|
39
|
+
...prefix,
|
|
40
|
+
node.name
|
|
41
|
+
];
|
|
42
|
+
const flatKey = pathParts.join("/");
|
|
43
|
+
const entry = flat[flatKey];
|
|
44
|
+
const staticValue = entry?.static;
|
|
45
|
+
if (node.children.length > 0) if (node.list) {
|
|
46
|
+
const pattern = new RegExp(`^${flatKey}\\/(\\d+)\\/`);
|
|
47
|
+
const indexes = Object.keys(flat).reduce((acc, key)=>{
|
|
48
|
+
const match = key.match(pattern);
|
|
49
|
+
if (match) acc.push(parseInt(match[1], 10));
|
|
50
|
+
return acc;
|
|
51
|
+
}, []);
|
|
52
|
+
const uniqueIndexes = Array.from(new Set(indexes)).sort((a, b)=>a - b);
|
|
53
|
+
for (const i of uniqueIndexes)walk(node.children, [
|
|
54
|
+
...prefix,
|
|
55
|
+
`${node.name}/${i}`
|
|
56
|
+
]);
|
|
57
|
+
} else walk(node.children, pathParts);
|
|
58
|
+
else if (void 0 !== staticValue) {
|
|
59
|
+
const path = pathParts.reduce((acc, part)=>{
|
|
60
|
+
const match = part.match(/(.*?)\/(\d+)/);
|
|
61
|
+
if (match) acc.push(match[1], Number(match[2]));
|
|
62
|
+
else acc.push(part);
|
|
63
|
+
return acc;
|
|
64
|
+
}, []);
|
|
65
|
+
assignValue(path, staticValue);
|
|
272
66
|
}
|
|
273
|
-
rebuilt.overrides[breakpoint].inputs[flatKey] = binding;
|
|
274
|
-
} else {
|
|
275
|
-
if (rebuilt.overrides[breakpoint]?.inputs?.[flatKey]) {
|
|
276
|
-
delete rebuilt.overrides[breakpoint].inputs[flatKey];
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
if (originalEntry) {
|
|
280
|
-
rebuilt.inputs[flatKey] = originalEntry;
|
|
281
|
-
}
|
|
282
|
-
} else {
|
|
283
|
-
// Base binding update
|
|
284
|
-
rebuilt.inputs[flatKey] = binding;
|
|
285
67
|
}
|
|
286
|
-
|
|
68
|
+
};
|
|
69
|
+
walk(this.inputsAst, []);
|
|
70
|
+
return result;
|
|
71
|
+
}
|
|
72
|
+
createUpdate(inputs, breakpoint) {
|
|
73
|
+
const operations = [];
|
|
74
|
+
const originalInputs = this.rawBindings.inputs ?? {};
|
|
75
|
+
const rebuilt = {
|
|
76
|
+
inputs: {},
|
|
77
|
+
overrides: {}
|
|
78
|
+
};
|
|
79
|
+
if (this.rawBindings.overrides) {
|
|
80
|
+
for (const [bp, overrides] of Object.entries(this.rawBindings.overrides))if (overrides.inputs) set(rebuilt, `overrides.${bp}.inputs`, structuredClone(this.rawBindings.overrides[bp].inputs));
|
|
287
81
|
}
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
82
|
+
const seenPaths = new Set();
|
|
83
|
+
const valueResolver = new InheritedValueResolver(this.breakpoints, (bp)=>{
|
|
84
|
+
if (this.isBaseBreakpoint(bp)) return this.rawBindings.inputs;
|
|
85
|
+
return this.rawBindings.overrides?.[bp]?.inputs;
|
|
86
|
+
});
|
|
87
|
+
const getValue = (obj, path)=>{
|
|
88
|
+
const segments = path.split("/");
|
|
89
|
+
const keys = segments.flatMap((segment)=>segment.split(".").map((part)=>/^\d+$/.test(part) ? parseInt(part, 10) : part));
|
|
90
|
+
return keys.reduce((acc, key)=>acc ? acc[key] : void 0, obj);
|
|
91
|
+
};
|
|
92
|
+
const compareAndCollect = (nodes, prefix)=>{
|
|
93
|
+
for (const node of nodes){
|
|
94
|
+
const pathParts = [
|
|
95
|
+
...prefix,
|
|
96
|
+
node.name
|
|
97
|
+
];
|
|
98
|
+
const flatKey = pathParts.join("/");
|
|
99
|
+
seenPaths.add(flatKey);
|
|
100
|
+
if (node.children.length) if (node.list) {
|
|
101
|
+
const list = getValue(inputs, flatKey);
|
|
102
|
+
if (Array.isArray(list)) for(let i = 0; i < list.length; i++)compareAndCollect(node.children, [
|
|
103
|
+
...pathParts.slice(0, -1),
|
|
104
|
+
`${node.name}/${i}`
|
|
105
|
+
]);
|
|
106
|
+
} else compareAndCollect(node.children, pathParts);
|
|
107
|
+
else {
|
|
108
|
+
let newValue = getValue(inputs, flatKey);
|
|
109
|
+
const originalEntry = originalInputs[flatKey];
|
|
110
|
+
if (void 0 === newValue && !originalEntry) continue;
|
|
111
|
+
if (node.list && Array.isArray(newValue)) newValue = newValue.map((item)=>{
|
|
112
|
+
if ("object" == typeof item && null !== item && "CreateElement" === item.action) {
|
|
113
|
+
const newElement = this.elementFactory.createElementFromComponent({
|
|
114
|
+
componentName: item.params.component,
|
|
115
|
+
parentId: this.elementId,
|
|
116
|
+
slot: flatKey,
|
|
117
|
+
bindings: item.params
|
|
118
|
+
});
|
|
119
|
+
operations.push(...newElement.operations.filter((op)=>!(op instanceof DocumentOperations.AddToParent)));
|
|
120
|
+
return newElement.element.id;
|
|
121
|
+
}
|
|
122
|
+
return item;
|
|
123
|
+
});
|
|
124
|
+
if (Array.isArray(newValue) || "object" != typeof newValue || newValue?.action !== "CreateElement") {
|
|
125
|
+
const isResponsive = node.input?.responsive && !this.isBaseBreakpoint(breakpoint);
|
|
126
|
+
const existingId = originalEntry?.id;
|
|
127
|
+
const idToUse = existingId ?? generateElementId();
|
|
128
|
+
const binding = {
|
|
129
|
+
...originalEntry ?? {},
|
|
130
|
+
static: newValue,
|
|
131
|
+
type: node.type,
|
|
132
|
+
list: node.list,
|
|
133
|
+
id: idToUse
|
|
134
|
+
};
|
|
135
|
+
if (isResponsive) {
|
|
136
|
+
const inheritedValue = valueResolver.getInheritedValue(flatKey, breakpoint);
|
|
137
|
+
if (void 0 === binding.static) {
|
|
138
|
+
if (rebuilt.overrides[breakpoint]?.inputs?.[flatKey]) delete rebuilt.overrides[breakpoint].inputs[flatKey];
|
|
139
|
+
} else if (void 0 !== inheritedValue && deep_equal(inheritedValue, binding.static)) {
|
|
140
|
+
if (rebuilt.overrides[breakpoint]?.inputs?.[flatKey]) delete rebuilt.overrides[breakpoint].inputs[flatKey];
|
|
141
|
+
} else {
|
|
142
|
+
if (!rebuilt.overrides[breakpoint]) rebuilt.overrides[breakpoint] = {
|
|
143
|
+
inputs: {}
|
|
144
|
+
};
|
|
145
|
+
rebuilt.overrides[breakpoint].inputs[flatKey] = binding;
|
|
146
|
+
}
|
|
147
|
+
if (originalEntry) rebuilt.inputs[flatKey] = originalEntry;
|
|
148
|
+
} else rebuilt.inputs[flatKey] = binding;
|
|
149
|
+
} else {
|
|
150
|
+
const newElement = this.elementFactory.createElementFromComponent({
|
|
151
|
+
componentName: newValue.params.component,
|
|
152
|
+
parentId: this.elementId,
|
|
153
|
+
slot: flatKey,
|
|
154
|
+
index: -1,
|
|
155
|
+
bindings: newValue.params
|
|
156
|
+
});
|
|
157
|
+
const createdId = newElement.element.id;
|
|
158
|
+
const existingId = originalEntry?.id;
|
|
159
|
+
const idToUse = existingId ?? generateElementId();
|
|
160
|
+
const binding = {
|
|
161
|
+
static: createdId,
|
|
162
|
+
type: node.type,
|
|
163
|
+
list: node.list,
|
|
164
|
+
id: idToUse
|
|
165
|
+
};
|
|
166
|
+
if (node.input?.responsive && !this.isBaseBreakpoint(breakpoint)) {
|
|
167
|
+
const inheritedValue = valueResolver.getInheritedValue(flatKey, breakpoint);
|
|
168
|
+
if (void 0 === binding.static) {
|
|
169
|
+
if (rebuilt.overrides[breakpoint]?.inputs?.[flatKey]) delete rebuilt.overrides[breakpoint].inputs[flatKey];
|
|
170
|
+
} else if (void 0 !== inheritedValue && deep_equal(inheritedValue, binding.static)) {
|
|
171
|
+
if (rebuilt.overrides[breakpoint]?.inputs?.[flatKey]) delete rebuilt.overrides[breakpoint].inputs[flatKey];
|
|
172
|
+
} else {
|
|
173
|
+
if (!rebuilt.overrides[breakpoint]) rebuilt.overrides[breakpoint] = {
|
|
174
|
+
inputs: {}
|
|
175
|
+
};
|
|
176
|
+
rebuilt.overrides[breakpoint].inputs[flatKey] = binding;
|
|
177
|
+
}
|
|
178
|
+
if (originalEntry) rebuilt.inputs[flatKey] = originalEntry;
|
|
179
|
+
} else rebuilt.inputs[flatKey] = binding;
|
|
180
|
+
operations.push(...newElement.operations.filter((op)=>!(op instanceof DocumentOperations.AddToParent)));
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
compareAndCollect(this.inputsAst, []);
|
|
186
|
+
const usedSlotIds = this.getElementReferences(rebuilt.inputs);
|
|
187
|
+
for (const id of this.elementReferences)if (!usedSlotIds.has(id)) operations.push(new DocumentOperations.RemoveElement(id));
|
|
188
|
+
return new InputsUpdater(this.elementId, rebuilt, operations);
|
|
301
189
|
}
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
const references = new Set();
|
|
308
|
-
for (const [, binding] of Object.entries(inputs)) {
|
|
309
|
-
if (binding.type === "slot") {
|
|
310
|
-
if (Array.isArray(binding.static)) {
|
|
311
|
-
(binding.static ?? []).forEach(id => references.add(id));
|
|
312
|
-
} else if (typeof binding.static === "string") {
|
|
313
|
-
references.add(binding.static);
|
|
190
|
+
getElementReferences(inputs = {}) {
|
|
191
|
+
const references = new Set();
|
|
192
|
+
for (const [, binding] of Object.entries(inputs))if ("slot" === binding.type) {
|
|
193
|
+
if (Array.isArray(binding.static)) (binding.static ?? []).forEach((id)=>references.add(id));
|
|
194
|
+
else if ("string" == typeof binding.static) references.add(binding.static);
|
|
314
195
|
}
|
|
315
|
-
|
|
196
|
+
return references;
|
|
197
|
+
}
|
|
198
|
+
isBaseBreakpoint(name) {
|
|
199
|
+
return 0 === this.breakpoints.indexOf(name);
|
|
316
200
|
}
|
|
317
|
-
return references;
|
|
318
|
-
}
|
|
319
|
-
isBaseBreakpoint(name) {
|
|
320
|
-
return this.breakpoints.indexOf(name) === 0;
|
|
321
|
-
}
|
|
322
201
|
}
|
|
202
|
+
export { InputsBindingsProcessor };
|
|
323
203
|
|
|
324
204
|
//# sourceMappingURL=InputBindingsProcessor.js.map
|