@webiny/website-builder-sdk 0.0.0-unstable.6f45466a1d → 0.0.0-unstable.7be00a75a9

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