@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.
Files changed (154) hide show
  1. package/BindingsApi.js +29 -36
  2. package/BindingsApi.js.map +1 -1
  3. package/BindingsProcessor.js +34 -43
  4. package/BindingsProcessor.js.map +1 -1
  5. package/BindingsProcessor.test.js +82 -78
  6. package/BindingsProcessor.test.js.map +1 -1
  7. package/BindingsResolver.js +92 -119
  8. package/BindingsResolver.js.map +1 -1
  9. package/BindingsResolver.test.js +399 -363
  10. package/BindingsResolver.test.js.map +1 -1
  11. package/ComponentInputTraverser.js +28 -49
  12. package/ComponentInputTraverser.js.map +1 -1
  13. package/ComponentManifestToAstConverter.js +20 -21
  14. package/ComponentManifestToAstConverter.js.map +1 -1
  15. package/ComponentRegistry.js +26 -45
  16. package/ComponentRegistry.js.map +1 -1
  17. package/ComponentResolver.js +25 -29
  18. package/ComponentResolver.js.map +1 -1
  19. package/ConstraintEvaluator.js +246 -353
  20. package/ConstraintEvaluator.js.map +1 -1
  21. package/ConstraintEvaluator.test.js +1616 -1438
  22. package/ConstraintEvaluator.test.js.map +1 -1
  23. package/ContentSdk.js +83 -90
  24. package/ContentSdk.js.map +1 -1
  25. package/DocumentStore.js +47 -59
  26. package/DocumentStore.js.map +1 -1
  27. package/DocumentStoreManager.js +17 -16
  28. package/DocumentStoreManager.js.map +1 -1
  29. package/EditingSdk.js +87 -121
  30. package/EditingSdk.js.map +1 -1
  31. package/ElementFactory.js +126 -174
  32. package/ElementFactory.js.map +1 -1
  33. package/ElementFactory.test.js +234 -263
  34. package/ElementFactory.test.js.map +1 -1
  35. package/Environment.js +18 -19
  36. package/Environment.js.map +1 -1
  37. package/FunctionConverter.js +8 -7
  38. package/FunctionConverter.js.map +1 -1
  39. package/HashObject.js +11 -26
  40. package/HashObject.js.map +1 -1
  41. package/HotkeyManager.js +40 -47
  42. package/HotkeyManager.js.map +1 -1
  43. package/IBindingsUpdater.js +0 -3
  44. package/IRedirects.js +0 -3
  45. package/InheritanceProcessor.js +99 -139
  46. package/InheritanceProcessor.js.map +1 -1
  47. package/InheritanceProcessor.test.js +178 -179
  48. package/InheritanceProcessor.test.js.map +1 -1
  49. package/InheritedValueResolver.js +15 -20
  50. package/InheritedValueResolver.js.map +1 -1
  51. package/InputBindingsProcessor.js +187 -307
  52. package/InputBindingsProcessor.js.map +1 -1
  53. package/InputsBindingsProcessor.test.js +334 -315
  54. package/InputsBindingsProcessor.test.js.map +1 -1
  55. package/InputsUpdater.js +23 -26
  56. package/InputsUpdater.js.map +1 -1
  57. package/LiveSdk.js +12 -13
  58. package/LiveSdk.js.map +1 -1
  59. package/Logger.js +9 -8
  60. package/Logger.js.map +1 -1
  61. package/MouseTracker.js +77 -83
  62. package/MouseTracker.js.map +1 -1
  63. package/NullSdk.js +22 -21
  64. package/NullSdk.js.map +1 -1
  65. package/PreviewDocument.js +27 -30
  66. package/PreviewDocument.js.map +1 -1
  67. package/PreviewSdk.js +16 -17
  68. package/PreviewSdk.js.map +1 -1
  69. package/PreviewViewport.js +51 -63
  70. package/PreviewViewport.js.map +1 -1
  71. package/ResizeObserver.js +24 -31
  72. package/ResizeObserver.js.map +1 -1
  73. package/StylesBindingsProcessor.js +40 -79
  74. package/StylesBindingsProcessor.js.map +1 -1
  75. package/StylesUpdater.js +20 -25
  76. package/StylesUpdater.js.map +1 -1
  77. package/Theme.js +28 -25
  78. package/Theme.js.map +1 -1
  79. package/ViewportManager.js +89 -101
  80. package/ViewportManager.js.map +1 -1
  81. package/constants.js +7 -6
  82. package/constants.js.map +1 -1
  83. package/createElement.js +5 -6
  84. package/createElement.js.map +1 -1
  85. package/createInput.js +85 -143
  86. package/createInput.js.map +1 -1
  87. package/createTheme.js +2 -3
  88. package/createTheme.js.map +1 -1
  89. package/dataProviders/ApiClient.js +40 -49
  90. package/dataProviders/ApiClient.js.map +1 -1
  91. package/dataProviders/DefaultDataProvider.js +56 -58
  92. package/dataProviders/DefaultDataProvider.js.map +1 -1
  93. package/dataProviders/GET_PAGE_BY_ID.js +2 -1
  94. package/dataProviders/GET_PAGE_BY_ID.js.map +1 -1
  95. package/dataProviders/GET_PAGE_BY_PATH.js +2 -1
  96. package/dataProviders/GET_PAGE_BY_PATH.js.map +1 -1
  97. package/dataProviders/LIST_PUBLISHED_PAGES.js +2 -1
  98. package/dataProviders/LIST_PUBLISHED_PAGES.js.map +1 -1
  99. package/dataProviders/NullDataProvider.js +21 -20
  100. package/dataProviders/NullDataProvider.js.map +1 -1
  101. package/dataProviders/RedirectsProvider.js +24 -27
  102. package/dataProviders/RedirectsProvider.js.map +1 -1
  103. package/defaultBreakpoints.js +23 -22
  104. package/defaultBreakpoints.js.map +1 -1
  105. package/documentOperations/$addElementReferenceToParent.js +29 -32
  106. package/documentOperations/$addElementReferenceToParent.js.map +1 -1
  107. package/documentOperations/AddElement.js +8 -7
  108. package/documentOperations/AddElement.js.map +1 -1
  109. package/documentOperations/AddToParent.js +14 -13
  110. package/documentOperations/AddToParent.js.map +1 -1
  111. package/documentOperations/IDocumentOperation.js +0 -3
  112. package/documentOperations/RemoveElement.js +9 -15
  113. package/documentOperations/RemoveElement.js.map +1 -1
  114. package/documentOperations/SetGlobalInputBinding.js +23 -22
  115. package/documentOperations/SetGlobalInputBinding.js.map +1 -1
  116. package/documentOperations/SetGlobalStyleBinding.js +23 -23
  117. package/documentOperations/SetGlobalStyleBinding.js.map +1 -1
  118. package/documentOperations/SetInputBindingOverride.js +30 -29
  119. package/documentOperations/SetInputBindingOverride.js.map +1 -1
  120. package/documentOperations/SetStyleBindingOverride.js +30 -31
  121. package/documentOperations/SetStyleBindingOverride.js.map +1 -1
  122. package/documentOperations/index.js +9 -8
  123. package/documentOperations/index.js.map +1 -1
  124. package/findMatchingAstNode.js +11 -13
  125. package/findMatchingAstNode.js.map +1 -1
  126. package/generateElementId.js +2 -1
  127. package/generateElementId.js.map +1 -1
  128. package/headersProvider.js +4 -3
  129. package/headersProvider.js.map +1 -1
  130. package/index.js +0 -2
  131. package/jsonPatch.js +5 -9
  132. package/jsonPatch.js.map +1 -1
  133. package/messages.js +12 -11
  134. package/messages.js.map +1 -1
  135. package/messenger/MessageOrigin.js +12 -11
  136. package/messenger/MessageOrigin.js.map +1 -1
  137. package/messenger/Messenger.js +58 -69
  138. package/messenger/Messenger.js.map +1 -1
  139. package/messenger/index.js +0 -2
  140. package/package.json +5 -5
  141. package/registerComponentGroup.js +5 -6
  142. package/registerComponentGroup.js.map +1 -1
  143. package/types/ShorthandCssProperties.js +0 -3
  144. package/types/WebsiteBuilderTheme.js +0 -3
  145. package/types.d.ts +3 -0
  146. package/types.js +0 -3
  147. package/IBindingsUpdater.js.map +0 -1
  148. package/IRedirects.js.map +0 -1
  149. package/documentOperations/IDocumentOperation.js.map +0 -1
  150. package/index.js.map +0 -1
  151. package/messenger/index.js.map +0 -1
  152. package/types/ShorthandCssProperties.js.map +0 -1
  153. package/types/WebsiteBuilderTheme.js.map +0 -1
  154. package/types.js.map +0 -1
@@ -1,329 +1,348 @@
1
- import { describe, it, expect } from "vitest";
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
- // Example simple AST (you can expand as needed)
6
- const simpleAst = [{
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
- }
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
- "items/0/label": {
87
- id: "label0",
88
- static: "Tablet Label 1",
89
- type: "text"
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
- mobile: {
94
- inputs: {
95
- title: {
96
- id: "title",
97
- static: "Mobile Title",
98
- type: "text"
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
- const getInputsBindingsProcessor = (bindings = baseBindings, ast = simpleAst) => {
104
- const elementFactory = new ElementFactory({
105
- "Webiny/GridColumn": {
106
- name: "Webiny/GridColumn",
107
- label: "Column",
108
- tags: [],
109
- acceptsChildren: true,
110
- inputs: [{
111
- type: "slot",
112
- list: true,
113
- renderer: "Webiny/Slot",
114
- name: "children",
115
- defaultValue: []
116
- }]
117
- }
118
- });
119
- const processor = new InputsBindingsProcessor("elementId", ast, breakpoints, bindings, elementFactory);
120
- return {
121
- processor,
122
- bindings
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 updater = processor.createUpdate(newInputs, "mobile");
257
- const rebuilt = {
258
- bindings: {
259
- elementId: {
260
- inputs: {},
261
- styles: {}
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
- updater.applyToDocument(rebuilt);
266
- const elementBindings = rebuilt.bindings.elementId;
267
- expect(elementBindings.inputs["some/key"]).toBeUndefined();
268
- });
269
- it("createUpdate should apply correct changes to the document", () => {
270
- const rawBindings = {
271
- inputs: baseBindings.inputs,
272
- overrides,
273
- styles: {}
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
- const {
276
- processor
277
- } = getInputsBindingsProcessor(rawBindings, [...simpleAst, ...withSlotAst]);
278
- const deepInputs = processor.toDeepInputs(rawBindings.inputs);
279
- deepInputs.items.push({
280
- label: "New Label 1"
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
- deepInputs.children = {
283
- action: "CreateElement",
284
- params: {
285
- component: "Webiny/GridColumn"
286
- }
287
- };
288
- const updater = processor.createUpdate(deepInputs, "mobile");
289
- const rebuilt = {
290
- bindings: {
291
- elementId: {
292
- inputs: {},
293
- styles: {}
294
- }
295
- },
296
- elements: {}
297
- };
298
- updater.applyToDocument(rebuilt);
299
- expect(rebuilt.bindings.elementId.inputs).toMatchObject({
300
- title: {
301
- id: "title",
302
- static: "Base Title",
303
- type: "text"
304
- },
305
- "items/0/label": {
306
- id: "label0",
307
- static: "Base Label 1",
308
- type: "text"
309
- },
310
- "items/1/label": {
311
- id: "label1",
312
- static: "Base Label 2",
313
- type: "text"
314
- },
315
- "items/2/label": {
316
- id: expect.any(String),
317
- static: "New Label 1",
318
- type: "text"
319
- },
320
- children: {
321
- id: expect.any(String),
322
- static: expect.any(String),
323
- type: "slot"
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