@webiny/website-builder-sdk 6.3.0 → 6.4.0-beta.1
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,329 +1,348 @@
|
|
|
1
|
-
import { describe,
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
2
|
import { InputsBindingsProcessor } from "./InputBindingsProcessor.js";
|
|
3
3
|
import { ElementFactory } from "./ElementFactory.js";
|
|
4
|
-
describe("InputsBindingsProcessor", ()
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}, {
|
|
18
|
-
name: "items",
|
|
19
|
-
type: "object",
|
|
20
|
-
list: true,
|
|
21
|
-
path: "items",
|
|
22
|
-
children: [{
|
|
23
|
-
name: "label",
|
|
24
|
-
type: "text",
|
|
25
|
-
list: false,
|
|
26
|
-
path: "items.label",
|
|
27
|
-
children: [],
|
|
28
|
-
input: {
|
|
29
|
-
type: "text",
|
|
30
|
-
name: "label",
|
|
31
|
-
label: "Label"
|
|
32
|
-
}
|
|
33
|
-
}],
|
|
34
|
-
input: {
|
|
35
|
-
type: "object",
|
|
36
|
-
name: "items",
|
|
37
|
-
list: true,
|
|
38
|
-
fields: [{
|
|
39
|
-
type: "text",
|
|
40
|
-
name: "label",
|
|
41
|
-
label: "Label"
|
|
42
|
-
}]
|
|
43
|
-
}
|
|
44
|
-
}];
|
|
45
|
-
const withSlotAst = [{
|
|
46
|
-
path: "children",
|
|
47
|
-
children: [],
|
|
48
|
-
name: "children",
|
|
49
|
-
type: "slot",
|
|
50
|
-
list: false,
|
|
51
|
-
input: {
|
|
52
|
-
type: "slot",
|
|
53
|
-
name: "children",
|
|
54
|
-
label: "Children"
|
|
55
|
-
}
|
|
56
|
-
}];
|
|
57
|
-
const breakpoints = ["desktop", "tablet", "mobile"];
|
|
58
|
-
const baseBindings = {
|
|
59
|
-
inputs: {
|
|
60
|
-
title: {
|
|
61
|
-
id: "title",
|
|
62
|
-
static: "Base Title",
|
|
63
|
-
type: "text"
|
|
64
|
-
},
|
|
65
|
-
"items/0/label": {
|
|
66
|
-
id: "label0",
|
|
67
|
-
static: "Base Label 1",
|
|
68
|
-
type: "text"
|
|
69
|
-
},
|
|
70
|
-
"items/1/label": {
|
|
71
|
-
id: "label1",
|
|
72
|
-
static: "Base Label 2",
|
|
73
|
-
type: "text"
|
|
74
|
-
}
|
|
75
|
-
},
|
|
76
|
-
styles: {}
|
|
77
|
-
};
|
|
78
|
-
const overrides = {
|
|
79
|
-
tablet: {
|
|
80
|
-
inputs: {
|
|
81
|
-
title: {
|
|
82
|
-
id: "title",
|
|
83
|
-
static: "Tablet Title",
|
|
84
|
-
type: "text"
|
|
4
|
+
describe("InputsBindingsProcessor", ()=>{
|
|
5
|
+
const simpleAst = [
|
|
6
|
+
{
|
|
7
|
+
name: "title",
|
|
8
|
+
type: "text",
|
|
9
|
+
list: false,
|
|
10
|
+
path: "title",
|
|
11
|
+
children: [],
|
|
12
|
+
input: {
|
|
13
|
+
type: "text",
|
|
14
|
+
name: "title",
|
|
15
|
+
label: "Title"
|
|
16
|
+
}
|
|
85
17
|
},
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
18
|
+
{
|
|
19
|
+
name: "items",
|
|
20
|
+
type: "object",
|
|
21
|
+
list: true,
|
|
22
|
+
path: "items",
|
|
23
|
+
children: [
|
|
24
|
+
{
|
|
25
|
+
name: "label",
|
|
26
|
+
type: "text",
|
|
27
|
+
list: false,
|
|
28
|
+
path: "items.label",
|
|
29
|
+
children: [],
|
|
30
|
+
input: {
|
|
31
|
+
type: "text",
|
|
32
|
+
name: "label",
|
|
33
|
+
label: "Label"
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
],
|
|
37
|
+
input: {
|
|
38
|
+
type: "object",
|
|
39
|
+
name: "items",
|
|
40
|
+
list: true,
|
|
41
|
+
fields: [
|
|
42
|
+
{
|
|
43
|
+
type: "text",
|
|
44
|
+
name: "label",
|
|
45
|
+
label: "Label"
|
|
46
|
+
}
|
|
47
|
+
]
|
|
48
|
+
}
|
|
90
49
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
50
|
+
];
|
|
51
|
+
const withSlotAst = [
|
|
52
|
+
{
|
|
53
|
+
path: "children",
|
|
54
|
+
children: [],
|
|
55
|
+
name: "children",
|
|
56
|
+
type: "slot",
|
|
57
|
+
list: false,
|
|
58
|
+
input: {
|
|
59
|
+
type: "slot",
|
|
60
|
+
name: "children",
|
|
61
|
+
label: "Children"
|
|
62
|
+
}
|
|
99
63
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
it("toDeep should convert flat bindings to nested object", () => {
|
|
126
|
-
const {
|
|
127
|
-
processor
|
|
128
|
-
} = getInputsBindingsProcessor();
|
|
129
|
-
const deep = processor.toDeepInputs(baseBindings.inputs ?? {});
|
|
130
|
-
expect(deep).toEqual({
|
|
131
|
-
title: "Base Title",
|
|
132
|
-
items: [{
|
|
133
|
-
label: "Base Label 1"
|
|
134
|
-
}, {
|
|
135
|
-
label: "Base Label 2"
|
|
136
|
-
}]
|
|
137
|
-
});
|
|
138
|
-
});
|
|
139
|
-
it("applyInputs should assign base breakpoint inputs correctly", () => {
|
|
140
|
-
const {
|
|
141
|
-
processor
|
|
142
|
-
} = getInputsBindingsProcessor();
|
|
143
|
-
const newInputs = {
|
|
144
|
-
title: "New Base Title",
|
|
145
|
-
items: [{
|
|
146
|
-
label: "New Label 1"
|
|
147
|
-
}, {
|
|
148
|
-
label: "New Label 2"
|
|
149
|
-
}]
|
|
150
|
-
};
|
|
151
|
-
const updater = processor.createUpdate(newInputs, "mobile");
|
|
152
|
-
const rebuilt = {
|
|
153
|
-
bindings: {
|
|
154
|
-
elementId: {
|
|
155
|
-
inputs: {},
|
|
156
|
-
styles: {}
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
};
|
|
160
|
-
updater.applyToDocument(rebuilt);
|
|
161
|
-
const elementBindings = rebuilt.bindings.elementId;
|
|
162
|
-
expect(elementBindings.inputs.title.static).toBe("New Base Title");
|
|
163
|
-
expect(elementBindings.inputs["items/0/label"].static).toBe("New Label 1");
|
|
164
|
-
expect(elementBindings.inputs["items/1/label"].static).toBe("New Label 2");
|
|
165
|
-
expect(elementBindings.overrides).toBeUndefined();
|
|
166
|
-
});
|
|
167
|
-
it("applyInputs should assign overrides correctly, skipping inherited values", () => {
|
|
168
|
-
const rawBindings = {
|
|
169
|
-
inputs: baseBindings.inputs,
|
|
170
|
-
overrides,
|
|
171
|
-
styles: {}
|
|
172
|
-
};
|
|
173
|
-
const {
|
|
174
|
-
processor
|
|
175
|
-
} = getInputsBindingsProcessor(rawBindings);
|
|
176
|
-
const newInputs = {
|
|
177
|
-
title: "Mobile Title",
|
|
178
|
-
items: [{
|
|
179
|
-
label: "Base Label 1"
|
|
180
|
-
}, {
|
|
181
|
-
label: "Base Label 2"
|
|
182
|
-
}]
|
|
183
|
-
};
|
|
184
|
-
const updater = processor.createUpdate(newInputs, "mobile");
|
|
185
|
-
const rebuilt = {
|
|
186
|
-
bindings: {
|
|
187
|
-
elementId: {
|
|
188
|
-
inputs: {},
|
|
189
|
-
styles: {}
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
};
|
|
193
|
-
updater.applyToDocument(rebuilt);
|
|
194
|
-
const elementBindings = rebuilt.bindings.elementId;
|
|
195
|
-
expect(elementBindings.inputs.title.static).toBe("Mobile Title");
|
|
196
|
-
// Items are same as base, so should not be in overrides
|
|
197
|
-
expect(elementBindings.overrides?.mobile.inputs?.["items/0/label"]).toBeUndefined();
|
|
198
|
-
});
|
|
199
|
-
it("createPatch should create correct json patch for input changes", () => {
|
|
200
|
-
const rawBindings = {
|
|
201
|
-
inputs: baseBindings.inputs,
|
|
202
|
-
overrides,
|
|
203
|
-
styles: {}
|
|
204
|
-
};
|
|
205
|
-
const {
|
|
206
|
-
processor,
|
|
207
|
-
bindings
|
|
208
|
-
} = getInputsBindingsProcessor(rawBindings);
|
|
209
|
-
const newInputs = {
|
|
210
|
-
title: "Changed Title",
|
|
211
|
-
items: [{
|
|
212
|
-
label: "Changed Label 1"
|
|
213
|
-
}]
|
|
214
|
-
};
|
|
215
|
-
const updater = processor.createUpdate(newInputs, "mobile");
|
|
216
|
-
const patch = updater.createJsonPatch(bindings);
|
|
217
|
-
|
|
218
|
-
// You're seeing the weird `~1` delimiter because that's what fast-json-patch does with indexes.
|
|
219
|
-
expect(patch).toEqual(expect.arrayContaining([expect.objectContaining({
|
|
220
|
-
op: "remove",
|
|
221
|
-
path: "/inputs/items~11~1label"
|
|
222
|
-
}), expect.objectContaining({
|
|
223
|
-
op: "replace",
|
|
224
|
-
path: "/inputs/title/static",
|
|
225
|
-
value: "Changed Title"
|
|
226
|
-
}), expect.objectContaining({
|
|
227
|
-
op: "replace",
|
|
228
|
-
path: "/inputs/items~10~1label/static",
|
|
229
|
-
value: "Changed Label 1"
|
|
230
|
-
})]));
|
|
231
|
-
});
|
|
232
|
-
it("applyInputs removes keys missing in new inputs", () => {
|
|
233
|
-
const rawBindings = {
|
|
234
|
-
inputs: {
|
|
235
|
-
...baseBindings.inputs,
|
|
236
|
-
"some/key": {
|
|
237
|
-
id: "someKey",
|
|
238
|
-
static: "toRemove",
|
|
239
|
-
type: "text"
|
|
240
|
-
}
|
|
241
|
-
},
|
|
242
|
-
overrides,
|
|
243
|
-
styles: {}
|
|
244
|
-
};
|
|
245
|
-
const {
|
|
246
|
-
processor
|
|
247
|
-
} = getInputsBindingsProcessor(rawBindings);
|
|
248
|
-
const newInputs = {
|
|
249
|
-
title: "Base Title",
|
|
250
|
-
items: [{
|
|
251
|
-
label: "Base Label 1"
|
|
252
|
-
}, {
|
|
253
|
-
label: "Base Label 2"
|
|
254
|
-
}]
|
|
64
|
+
];
|
|
65
|
+
const breakpoints = [
|
|
66
|
+
"desktop",
|
|
67
|
+
"tablet",
|
|
68
|
+
"mobile"
|
|
69
|
+
];
|
|
70
|
+
const baseBindings = {
|
|
71
|
+
inputs: {
|
|
72
|
+
title: {
|
|
73
|
+
id: "title",
|
|
74
|
+
static: "Base Title",
|
|
75
|
+
type: "text"
|
|
76
|
+
},
|
|
77
|
+
"items/0/label": {
|
|
78
|
+
id: "label0",
|
|
79
|
+
static: "Base Label 1",
|
|
80
|
+
type: "text"
|
|
81
|
+
},
|
|
82
|
+
"items/1/label": {
|
|
83
|
+
id: "label1",
|
|
84
|
+
static: "Base Label 2",
|
|
85
|
+
type: "text"
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
styles: {}
|
|
255
89
|
};
|
|
256
|
-
const
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
90
|
+
const overrides = {
|
|
91
|
+
tablet: {
|
|
92
|
+
inputs: {
|
|
93
|
+
title: {
|
|
94
|
+
id: "title",
|
|
95
|
+
static: "Tablet Title",
|
|
96
|
+
type: "text"
|
|
97
|
+
},
|
|
98
|
+
"items/0/label": {
|
|
99
|
+
id: "label0",
|
|
100
|
+
static: "Tablet Label 1",
|
|
101
|
+
type: "text"
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
mobile: {
|
|
106
|
+
inputs: {
|
|
107
|
+
title: {
|
|
108
|
+
id: "title",
|
|
109
|
+
static: "Mobile Title",
|
|
110
|
+
type: "text"
|
|
111
|
+
}
|
|
112
|
+
}
|
|
262
113
|
}
|
|
263
|
-
}
|
|
264
114
|
};
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
115
|
+
const getInputsBindingsProcessor = (bindings = baseBindings, ast = simpleAst)=>{
|
|
116
|
+
const elementFactory = new ElementFactory({
|
|
117
|
+
"Webiny/GridColumn": {
|
|
118
|
+
name: "Webiny/GridColumn",
|
|
119
|
+
label: "Column",
|
|
120
|
+
tags: [],
|
|
121
|
+
acceptsChildren: true,
|
|
122
|
+
inputs: [
|
|
123
|
+
{
|
|
124
|
+
type: "slot",
|
|
125
|
+
list: true,
|
|
126
|
+
renderer: "Webiny/Slot",
|
|
127
|
+
name: "children",
|
|
128
|
+
defaultValue: []
|
|
129
|
+
}
|
|
130
|
+
]
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
const processor = new InputsBindingsProcessor("elementId", ast, breakpoints, bindings, elementFactory);
|
|
134
|
+
return {
|
|
135
|
+
processor,
|
|
136
|
+
bindings
|
|
137
|
+
};
|
|
274
138
|
};
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
139
|
+
it("toDeep should convert flat bindings to nested object", ()=>{
|
|
140
|
+
const { processor } = getInputsBindingsProcessor();
|
|
141
|
+
const deep = processor.toDeepInputs(baseBindings.inputs ?? {});
|
|
142
|
+
expect(deep).toEqual({
|
|
143
|
+
title: "Base Title",
|
|
144
|
+
items: [
|
|
145
|
+
{
|
|
146
|
+
label: "Base Label 1"
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
label: "Base Label 2"
|
|
150
|
+
}
|
|
151
|
+
]
|
|
152
|
+
});
|
|
281
153
|
});
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
static
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
154
|
+
it("applyInputs should assign base breakpoint inputs correctly", ()=>{
|
|
155
|
+
const { processor } = getInputsBindingsProcessor();
|
|
156
|
+
const newInputs = {
|
|
157
|
+
title: "New Base Title",
|
|
158
|
+
items: [
|
|
159
|
+
{
|
|
160
|
+
label: "New Label 1"
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
label: "New Label 2"
|
|
164
|
+
}
|
|
165
|
+
]
|
|
166
|
+
};
|
|
167
|
+
const updater = processor.createUpdate(newInputs, "mobile");
|
|
168
|
+
const rebuilt = {
|
|
169
|
+
bindings: {
|
|
170
|
+
elementId: {
|
|
171
|
+
inputs: {},
|
|
172
|
+
styles: {}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
updater.applyToDocument(rebuilt);
|
|
177
|
+
const elementBindings = rebuilt.bindings.elementId;
|
|
178
|
+
expect(elementBindings.inputs.title.static).toBe("New Base Title");
|
|
179
|
+
expect(elementBindings.inputs["items/0/label"].static).toBe("New Label 1");
|
|
180
|
+
expect(elementBindings.inputs["items/1/label"].static).toBe("New Label 2");
|
|
181
|
+
expect(elementBindings.overrides).toBeUndefined();
|
|
182
|
+
});
|
|
183
|
+
it("applyInputs should assign overrides correctly, skipping inherited values", ()=>{
|
|
184
|
+
const rawBindings = {
|
|
185
|
+
inputs: baseBindings.inputs,
|
|
186
|
+
overrides,
|
|
187
|
+
styles: {}
|
|
188
|
+
};
|
|
189
|
+
const { processor } = getInputsBindingsProcessor(rawBindings);
|
|
190
|
+
const newInputs = {
|
|
191
|
+
title: "Mobile Title",
|
|
192
|
+
items: [
|
|
193
|
+
{
|
|
194
|
+
label: "Base Label 1"
|
|
195
|
+
},
|
|
196
|
+
{
|
|
197
|
+
label: "Base Label 2"
|
|
198
|
+
}
|
|
199
|
+
]
|
|
200
|
+
};
|
|
201
|
+
const updater = processor.createUpdate(newInputs, "mobile");
|
|
202
|
+
const rebuilt = {
|
|
203
|
+
bindings: {
|
|
204
|
+
elementId: {
|
|
205
|
+
inputs: {},
|
|
206
|
+
styles: {}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
updater.applyToDocument(rebuilt);
|
|
211
|
+
const elementBindings = rebuilt.bindings.elementId;
|
|
212
|
+
expect(elementBindings.inputs.title.static).toBe("Mobile Title");
|
|
213
|
+
expect(elementBindings.overrides?.mobile.inputs?.["items/0/label"]).toBeUndefined();
|
|
214
|
+
});
|
|
215
|
+
it("createPatch should create correct json patch for input changes", ()=>{
|
|
216
|
+
const rawBindings = {
|
|
217
|
+
inputs: baseBindings.inputs,
|
|
218
|
+
overrides,
|
|
219
|
+
styles: {}
|
|
220
|
+
};
|
|
221
|
+
const { processor, bindings } = getInputsBindingsProcessor(rawBindings);
|
|
222
|
+
const newInputs = {
|
|
223
|
+
title: "Changed Title",
|
|
224
|
+
items: [
|
|
225
|
+
{
|
|
226
|
+
label: "Changed Label 1"
|
|
227
|
+
}
|
|
228
|
+
]
|
|
229
|
+
};
|
|
230
|
+
const updater = processor.createUpdate(newInputs, "mobile");
|
|
231
|
+
const patch = updater.createJsonPatch(bindings);
|
|
232
|
+
expect(patch).toEqual(expect.arrayContaining([
|
|
233
|
+
expect.objectContaining({
|
|
234
|
+
op: "remove",
|
|
235
|
+
path: "/inputs/items~11~1label"
|
|
236
|
+
}),
|
|
237
|
+
expect.objectContaining({
|
|
238
|
+
op: "replace",
|
|
239
|
+
path: "/inputs/title/static",
|
|
240
|
+
value: "Changed Title"
|
|
241
|
+
}),
|
|
242
|
+
expect.objectContaining({
|
|
243
|
+
op: "replace",
|
|
244
|
+
path: "/inputs/items~10~1label/static",
|
|
245
|
+
value: "Changed Label 1"
|
|
246
|
+
})
|
|
247
|
+
]));
|
|
248
|
+
});
|
|
249
|
+
it("applyInputs removes keys missing in new inputs", ()=>{
|
|
250
|
+
const rawBindings = {
|
|
251
|
+
inputs: {
|
|
252
|
+
...baseBindings.inputs,
|
|
253
|
+
"some/key": {
|
|
254
|
+
id: "someKey",
|
|
255
|
+
static: "toRemove",
|
|
256
|
+
type: "text"
|
|
257
|
+
}
|
|
258
|
+
},
|
|
259
|
+
overrides,
|
|
260
|
+
styles: {}
|
|
261
|
+
};
|
|
262
|
+
const { processor } = getInputsBindingsProcessor(rawBindings);
|
|
263
|
+
const newInputs = {
|
|
264
|
+
title: "Base Title",
|
|
265
|
+
items: [
|
|
266
|
+
{
|
|
267
|
+
label: "Base Label 1"
|
|
268
|
+
},
|
|
269
|
+
{
|
|
270
|
+
label: "Base Label 2"
|
|
271
|
+
}
|
|
272
|
+
]
|
|
273
|
+
};
|
|
274
|
+
const updater = processor.createUpdate(newInputs, "mobile");
|
|
275
|
+
const rebuilt = {
|
|
276
|
+
bindings: {
|
|
277
|
+
elementId: {
|
|
278
|
+
inputs: {},
|
|
279
|
+
styles: {}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
};
|
|
283
|
+
updater.applyToDocument(rebuilt);
|
|
284
|
+
const elementBindings = rebuilt.bindings.elementId;
|
|
285
|
+
expect(elementBindings.inputs["some/key"]).toBeUndefined();
|
|
286
|
+
});
|
|
287
|
+
it("createUpdate should apply correct changes to the document", ()=>{
|
|
288
|
+
const rawBindings = {
|
|
289
|
+
inputs: baseBindings.inputs,
|
|
290
|
+
overrides,
|
|
291
|
+
styles: {}
|
|
292
|
+
};
|
|
293
|
+
const { processor } = getInputsBindingsProcessor(rawBindings, [
|
|
294
|
+
...simpleAst,
|
|
295
|
+
...withSlotAst
|
|
296
|
+
]);
|
|
297
|
+
const deepInputs = processor.toDeepInputs(rawBindings.inputs);
|
|
298
|
+
deepInputs.items.push({
|
|
299
|
+
label: "New Label 1"
|
|
300
|
+
});
|
|
301
|
+
deepInputs.children = {
|
|
302
|
+
action: "CreateElement",
|
|
303
|
+
params: {
|
|
304
|
+
component: "Webiny/GridColumn"
|
|
305
|
+
}
|
|
306
|
+
};
|
|
307
|
+
const updater = processor.createUpdate(deepInputs, "mobile");
|
|
308
|
+
const rebuilt = {
|
|
309
|
+
bindings: {
|
|
310
|
+
elementId: {
|
|
311
|
+
inputs: {},
|
|
312
|
+
styles: {}
|
|
313
|
+
}
|
|
314
|
+
},
|
|
315
|
+
elements: {}
|
|
316
|
+
};
|
|
317
|
+
updater.applyToDocument(rebuilt);
|
|
318
|
+
expect(rebuilt.bindings.elementId.inputs).toMatchObject({
|
|
319
|
+
title: {
|
|
320
|
+
id: "title",
|
|
321
|
+
static: "Base Title",
|
|
322
|
+
type: "text"
|
|
323
|
+
},
|
|
324
|
+
"items/0/label": {
|
|
325
|
+
id: "label0",
|
|
326
|
+
static: "Base Label 1",
|
|
327
|
+
type: "text"
|
|
328
|
+
},
|
|
329
|
+
"items/1/label": {
|
|
330
|
+
id: "label1",
|
|
331
|
+
static: "Base Label 2",
|
|
332
|
+
type: "text"
|
|
333
|
+
},
|
|
334
|
+
"items/2/label": {
|
|
335
|
+
id: expect.any(String),
|
|
336
|
+
static: "New Label 1",
|
|
337
|
+
type: "text"
|
|
338
|
+
},
|
|
339
|
+
children: {
|
|
340
|
+
id: expect.any(String),
|
|
341
|
+
static: expect.any(String),
|
|
342
|
+
type: "slot"
|
|
343
|
+
}
|
|
344
|
+
});
|
|
325
345
|
});
|
|
326
|
-
});
|
|
327
346
|
});
|
|
328
347
|
|
|
329
348
|
//# sourceMappingURL=InputsBindingsProcessor.test.js.map
|