@uniformdev/canvas-next-rsc 19.96.1-alpha.13 → 19.99.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/package.json +11 -11
- package/dist/UniformComposition-38e22896.d.ts +0 -74
- package/dist/UniformComposition-d178d865.d.ts +0 -77
- package/dist/actions/updateContext.d.ts +0 -2
- package/dist/actions/updateContext.js +0 -17
- package/dist/client/canvasClient.d.ts +0 -5
- package/dist/client/canvasClient.js +0 -53
- package/dist/client/manifestClient.d.ts +0 -209
- package/dist/client/manifestClient.js +0 -33
- package/dist/client/projectMapClient.d.ts +0 -5
- package/dist/client/projectMapClient.js +0 -17
- package/dist/client/routeClient.d.ts +0 -5
- package/dist/client/routeClient.js +0 -68
- package/dist/components/DefaultNotImplementedComponent.d.ts +0 -4
- package/dist/components/DefaultNotImplementedComponent.js +0 -45
- package/dist/components/GoogleTagManagerAnalytics.d.ts +0 -3
- package/dist/components/GoogleTagManagerAnalytics.js +0 -44
- package/dist/components/UniformComponent.d.ts +0 -35
- package/dist/components/UniformComponent.js +0 -14
- package/dist/components/UniformComposition.d.ts +0 -47
- package/dist/components/UniformComposition.js +0 -35
- package/dist/components/UniformContext.d.ts +0 -13
- package/dist/components/UniformContext.js +0 -19
- package/dist/components/UniformRichText.d.ts +0 -42
- package/dist/components/UniformRichText.js +0 -15
- package/dist/components/UniformRichTextNode.d.ts +0 -14
- package/dist/components/UniformRichTextNode.js +0 -49
- package/dist/components/UniformScript.d.ts +0 -5
- package/dist/components/UniformScript.js +0 -49
- package/dist/components/UniformSlot.d.ts +0 -48
- package/dist/components/UniformSlot.js +0 -38
- package/dist/components/UniformText.d.ts +0 -10
- package/dist/components/UniformText.js +0 -5
- package/dist/components/__tests__/evaluateComposition.spec.d.ts +0 -1
- package/dist/components/__tests__/evaluateComposition.spec.js +0 -80
- package/dist/components/convertComponentToProps.d.ts +0 -18
- package/dist/components/convertComponentToProps.js +0 -22
- package/dist/components/evaluateComposition.d.ts +0 -32
- package/dist/components/evaluateComposition.js +0 -183
- package/dist/components/getEnrichmentTags.d.ts +0 -5
- package/dist/components/getEnrichmentTags.js +0 -13
- package/dist/components/getUniformContext.d.ts +0 -10
- package/dist/components/getUniformContext.js +0 -17
- package/dist/components/nodes/HeadingRichTextNode.d.ts +0 -2
- package/dist/components/nodes/HeadingRichTextNode.js +0 -6
- package/dist/components/nodes/LinebreakRichTextNode.d.ts +0 -2
- package/dist/components/nodes/LinebreakRichTextNode.js +0 -4
- package/dist/components/nodes/LinkRichTextNode.d.ts +0 -2
- package/dist/components/nodes/LinkRichTextNode.js +0 -6
- package/dist/components/nodes/ListItemRichTextNode.d.ts +0 -2
- package/dist/components/nodes/ListItemRichTextNode.js +0 -5
- package/dist/components/nodes/ListRichTextNode.d.ts +0 -2
- package/dist/components/nodes/ListRichTextNode.js +0 -6
- package/dist/components/nodes/ParagraphRichTextNode.d.ts +0 -2
- package/dist/components/nodes/ParagraphRichTextNode.js +0 -6
- package/dist/components/nodes/TabRichTextNode.d.ts +0 -2
- package/dist/components/nodes/TabRichTextNode.js +0 -4
- package/dist/components/nodes/TextRichTextNode.d.ts +0 -2
- package/dist/components/nodes/TextRichTextNode.js +0 -9
- package/dist/components/renderComponent.d.ts +0 -26
- package/dist/components/renderComponent.js +0 -52
- package/dist/components/resolvePath.d.ts +0 -5
- package/dist/components/resolvePath.js +0 -34
- package/dist/components/retrieveRoute.d.ts +0 -198
- package/dist/components/retrieveRoute.js +0 -146
- package/dist/components/types.d.ts +0 -15
- package/dist/components/types.js +0 -1
- package/dist/config/helpers.d.ts +0 -23
- package/dist/config/helpers.js +0 -34
- package/dist/config/models.d.ts +0 -51
- package/dist/config/models.js +0 -1
- package/dist/cookie/index.d.ts +0 -12
- package/dist/cookie/index.js +0 -21
- package/dist/handler/createPreviewGETRouteHandler.d.ts +0 -1
- package/dist/handler/createPreviewGETRouteHandler.js +0 -43
- package/dist/handler/createPreviewPOSTRouteHandler.d.ts +0 -1
- package/dist/handler/createPreviewPOSTRouteHandler.js +0 -88
- package/dist/handler/createUniformRouteHandler.d.ts +0 -4
- package/dist/handler/createUniformRouteHandler.js +0 -10
- package/dist/handler/helpers.d.ts +0 -17
- package/dist/handler/helpers.js +0 -148
- package/dist/handler/messages/handleCompositionChanged.d.ts +0 -2
- package/dist/handler/messages/handleCompositionChanged.js +0 -9
- package/dist/handler/messages/handleCompositionDeleted.d.ts +0 -2
- package/dist/handler/messages/handleCompositionDeleted.js +0 -9
- package/dist/handler/messages/handleCompositionPublished.d.ts +0 -2
- package/dist/handler/messages/handleCompositionPublished.js +0 -9
- package/dist/handler/messages/handleManifestPublished.d.ts +0 -2
- package/dist/handler/messages/handleManifestPublished.js +0 -10
- package/dist/handler/messages/handleProjectMapNodeDelete.d.ts +0 -2
- package/dist/handler/messages/handleProjectMapNodeDelete.js +0 -21
- package/dist/handler/messages/handleProjectMapNodeInsert.d.ts +0 -2
- package/dist/handler/messages/handleProjectMapNodeInsert.js +0 -21
- package/dist/handler/messages/handleProjectMapNodeUpdate.d.ts +0 -2
- package/dist/handler/messages/handleProjectMapNodeUpdate.js +0 -22
- package/dist/handler/messages/handleRedirectDelete.d.ts +0 -2
- package/dist/handler/messages/handleRedirectDelete.js +0 -15
- package/dist/handler/messages/handleRedirectInsert.d.ts +0 -2
- package/dist/handler/messages/handleRedirectInsert.js +0 -15
- package/dist/handler/messages/handleRedirectUpdate.d.ts +0 -2
- package/dist/handler/messages/handleRedirectUpdate.js +0 -15
- package/dist/hooks/useForgetMe.d.ts +0 -4
- package/dist/hooks/useForgetMe.js +0 -10
- package/dist/hooks/useToggleConsent.d.ts +0 -7
- package/dist/hooks/useToggleConsent.js +0 -22
- package/dist/hooks/useUniformContext.d.ts +0 -1
- package/dist/hooks/useUniformContext.js +0 -3
- package/dist/models/index.d.ts +0 -30
- package/dist/models/index.js +0 -1
- package/dist/register/componentStore.d.ts +0 -1
- package/dist/register/componentStore.js +0 -2
- package/dist/register/componentStoreResolver.d.ts +0 -4
- package/dist/register/componentStoreResolver.js +0 -5
- package/dist/register/createComponentStore.d.ts +0 -12
- package/dist/register/createComponentStore.js +0 -13
- package/dist/register/createComponentStoreResolver.d.ts +0 -12
- package/dist/register/createComponentStoreResolver.js +0 -9
- package/dist/register/getTypeWithVariant.d.ts +0 -1
- package/dist/register/getTypeWithVariant.js +0 -1
- package/dist/register/registerUniformComponent.d.ts +0 -10
- package/dist/register/registerUniformComponent.js +0 -8
- package/dist/resolve/resolveChildren.d.ts +0 -17
- package/dist/resolve/resolveChildren.js +0 -20
- package/dist/score/index.d.ts +0 -3
- package/dist/score/index.js +0 -114
- package/dist/utils/__tests__/apply.spec.d.ts +0 -1
- package/dist/utils/__tests__/apply.spec.js +0 -358
- package/dist/utils/__tests__/diff.spec.d.ts +0 -1
- package/dist/utils/__tests__/diff.spec.js +0 -394
- package/dist/utils/apply.d.ts +0 -10
- package/dist/utils/apply.js +0 -124
- package/dist/utils/comp.d.ts +0 -25
- package/dist/utils/comp.js +0 -65
- package/dist/utils/diff.d.ts +0 -58
- package/dist/utils/diff.js +0 -144
- package/dist/utils/draft.d.ts +0 -20
- package/dist/utils/draft.js +0 -22
- package/dist/utils/tag.d.ts +0 -2
- package/dist/utils/tag.js +0 -7
- package/dist/utils/url.d.ts +0 -1
- package/dist/utils/url.js +0 -10
|
@@ -1,394 +0,0 @@
|
|
|
1
|
-
import { ComponentDiffType, diff, } from '../diff';
|
|
2
|
-
describe('diff', () => {
|
|
3
|
-
it('should report removed event when slot component is removed', () => {
|
|
4
|
-
const existingComposition = {
|
|
5
|
-
_id: 'root',
|
|
6
|
-
_name: 'root',
|
|
7
|
-
type: 'root',
|
|
8
|
-
slots: {
|
|
9
|
-
content: [
|
|
10
|
-
{
|
|
11
|
-
_id: 'child',
|
|
12
|
-
type: 'child',
|
|
13
|
-
},
|
|
14
|
-
{
|
|
15
|
-
_id: 'child2',
|
|
16
|
-
type: 'child',
|
|
17
|
-
},
|
|
18
|
-
],
|
|
19
|
-
},
|
|
20
|
-
};
|
|
21
|
-
const composition = {
|
|
22
|
-
_id: 'root',
|
|
23
|
-
_name: 'root',
|
|
24
|
-
type: 'root',
|
|
25
|
-
slots: {
|
|
26
|
-
content: [
|
|
27
|
-
{
|
|
28
|
-
_id: 'child2',
|
|
29
|
-
type: 'child',
|
|
30
|
-
},
|
|
31
|
-
],
|
|
32
|
-
},
|
|
33
|
-
};
|
|
34
|
-
const [result] = diff(existingComposition, composition);
|
|
35
|
-
expect(result).toEqual({
|
|
36
|
-
type: ComponentDiffType.ComponentRemoved,
|
|
37
|
-
id: 'child',
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
it('should report added event when slot component is added', () => {
|
|
41
|
-
const existingComposition = {
|
|
42
|
-
_id: 'root',
|
|
43
|
-
_name: 'root',
|
|
44
|
-
type: 'root',
|
|
45
|
-
slots: {
|
|
46
|
-
content: [],
|
|
47
|
-
},
|
|
48
|
-
};
|
|
49
|
-
const composition = {
|
|
50
|
-
_id: 'root',
|
|
51
|
-
_name: 'root',
|
|
52
|
-
type: 'root',
|
|
53
|
-
slots: {
|
|
54
|
-
content: [
|
|
55
|
-
{
|
|
56
|
-
_id: 'child',
|
|
57
|
-
type: 'child',
|
|
58
|
-
},
|
|
59
|
-
],
|
|
60
|
-
},
|
|
61
|
-
};
|
|
62
|
-
const [result] = diff(existingComposition, composition);
|
|
63
|
-
expect(result).toEqual({
|
|
64
|
-
type: ComponentDiffType.ComponentAdded,
|
|
65
|
-
parentId: 'root',
|
|
66
|
-
slot: 'content',
|
|
67
|
-
slotIndex: 0,
|
|
68
|
-
id: 'child',
|
|
69
|
-
component: {
|
|
70
|
-
_id: 'child',
|
|
71
|
-
type: 'child',
|
|
72
|
-
},
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
it('should report when existing component has moved within the same slot', () => {
|
|
76
|
-
const existingComposition = {
|
|
77
|
-
_id: 'root',
|
|
78
|
-
_name: 'root',
|
|
79
|
-
type: 'root',
|
|
80
|
-
slots: {
|
|
81
|
-
content: [
|
|
82
|
-
{
|
|
83
|
-
_id: 'child2',
|
|
84
|
-
type: 'child',
|
|
85
|
-
},
|
|
86
|
-
{
|
|
87
|
-
_id: 'child1',
|
|
88
|
-
type: 'child',
|
|
89
|
-
},
|
|
90
|
-
{
|
|
91
|
-
_id: 'child3',
|
|
92
|
-
type: 'child',
|
|
93
|
-
},
|
|
94
|
-
],
|
|
95
|
-
},
|
|
96
|
-
};
|
|
97
|
-
const composition = {
|
|
98
|
-
_id: 'root',
|
|
99
|
-
_name: 'root',
|
|
100
|
-
type: 'root',
|
|
101
|
-
slots: {
|
|
102
|
-
content: [
|
|
103
|
-
{
|
|
104
|
-
_id: 'child1',
|
|
105
|
-
type: 'child',
|
|
106
|
-
},
|
|
107
|
-
{
|
|
108
|
-
_id: 'child2',
|
|
109
|
-
type: 'child',
|
|
110
|
-
},
|
|
111
|
-
{
|
|
112
|
-
_id: 'child3',
|
|
113
|
-
type: 'child',
|
|
114
|
-
},
|
|
115
|
-
],
|
|
116
|
-
},
|
|
117
|
-
};
|
|
118
|
-
const [firstResult, secondResult] = diff(existingComposition, composition);
|
|
119
|
-
expect(firstResult).toEqual({
|
|
120
|
-
type: ComponentDiffType.ComponentMoved,
|
|
121
|
-
id: 'child1',
|
|
122
|
-
parentId: undefined,
|
|
123
|
-
slot: undefined,
|
|
124
|
-
slotIndex: 0,
|
|
125
|
-
});
|
|
126
|
-
expect(secondResult).toEqual({
|
|
127
|
-
type: ComponentDiffType.ComponentMoved,
|
|
128
|
-
id: 'child2',
|
|
129
|
-
parentId: undefined,
|
|
130
|
-
slot: undefined,
|
|
131
|
-
slotIndex: 1,
|
|
132
|
-
});
|
|
133
|
-
});
|
|
134
|
-
it('should report when existing component has a new parent', () => {
|
|
135
|
-
const existingComposition = {
|
|
136
|
-
_id: 'root',
|
|
137
|
-
_name: 'root',
|
|
138
|
-
type: 'root',
|
|
139
|
-
slots: {
|
|
140
|
-
content: [
|
|
141
|
-
{
|
|
142
|
-
_id: 'child2',
|
|
143
|
-
type: 'child',
|
|
144
|
-
},
|
|
145
|
-
{
|
|
146
|
-
_id: 'child1',
|
|
147
|
-
type: 'child',
|
|
148
|
-
},
|
|
149
|
-
{
|
|
150
|
-
_id: 'child3',
|
|
151
|
-
type: 'child',
|
|
152
|
-
},
|
|
153
|
-
],
|
|
154
|
-
},
|
|
155
|
-
};
|
|
156
|
-
const composition = {
|
|
157
|
-
_id: 'root',
|
|
158
|
-
_name: 'root',
|
|
159
|
-
type: 'root',
|
|
160
|
-
slots: {
|
|
161
|
-
content: [
|
|
162
|
-
{
|
|
163
|
-
_id: 'child1',
|
|
164
|
-
type: 'child',
|
|
165
|
-
slots: {
|
|
166
|
-
cool: [
|
|
167
|
-
{
|
|
168
|
-
_id: 'child2',
|
|
169
|
-
type: 'child',
|
|
170
|
-
},
|
|
171
|
-
],
|
|
172
|
-
},
|
|
173
|
-
},
|
|
174
|
-
{
|
|
175
|
-
_id: 'child3',
|
|
176
|
-
type: 'child',
|
|
177
|
-
},
|
|
178
|
-
],
|
|
179
|
-
},
|
|
180
|
-
};
|
|
181
|
-
const [firstResult] = diff(existingComposition, composition);
|
|
182
|
-
expect(firstResult).toEqual({
|
|
183
|
-
type: ComponentDiffType.ComponentMoved,
|
|
184
|
-
id: 'child2',
|
|
185
|
-
parentId: 'child1',
|
|
186
|
-
slot: 'cool',
|
|
187
|
-
slotIndex: undefined,
|
|
188
|
-
});
|
|
189
|
-
});
|
|
190
|
-
it('should report when a parameter has changed', () => {
|
|
191
|
-
const existingComposition = {
|
|
192
|
-
_id: 'root',
|
|
193
|
-
_name: 'root',
|
|
194
|
-
type: 'root',
|
|
195
|
-
parameters: {
|
|
196
|
-
title: {
|
|
197
|
-
type: 'text',
|
|
198
|
-
value: 'Hello',
|
|
199
|
-
},
|
|
200
|
-
},
|
|
201
|
-
};
|
|
202
|
-
const composition = {
|
|
203
|
-
_id: 'root',
|
|
204
|
-
_name: 'root',
|
|
205
|
-
type: 'root',
|
|
206
|
-
parameters: {
|
|
207
|
-
title: {
|
|
208
|
-
type: 'text',
|
|
209
|
-
value: 'Hello to you',
|
|
210
|
-
},
|
|
211
|
-
},
|
|
212
|
-
};
|
|
213
|
-
const [result] = diff(existingComposition, composition);
|
|
214
|
-
expect(result).toEqual({
|
|
215
|
-
type: ComponentDiffType.ParameterChanged,
|
|
216
|
-
componentId: 'root',
|
|
217
|
-
parameterName: 'title',
|
|
218
|
-
value: 'Hello to you',
|
|
219
|
-
});
|
|
220
|
-
});
|
|
221
|
-
it('should report when a parameter has been added', () => {
|
|
222
|
-
const existingComposition = {
|
|
223
|
-
_id: 'root',
|
|
224
|
-
_name: 'root',
|
|
225
|
-
type: 'root',
|
|
226
|
-
};
|
|
227
|
-
const composition = {
|
|
228
|
-
_id: 'root',
|
|
229
|
-
_name: 'root',
|
|
230
|
-
type: 'root',
|
|
231
|
-
parameters: {
|
|
232
|
-
title: {
|
|
233
|
-
type: 'text',
|
|
234
|
-
value: 'Hello to you',
|
|
235
|
-
},
|
|
236
|
-
},
|
|
237
|
-
};
|
|
238
|
-
const [result] = diff(existingComposition, composition);
|
|
239
|
-
expect(result).toEqual({
|
|
240
|
-
type: ComponentDiffType.ParameterChanged,
|
|
241
|
-
componentId: 'root',
|
|
242
|
-
parameterName: 'title',
|
|
243
|
-
value: 'Hello to you',
|
|
244
|
-
});
|
|
245
|
-
});
|
|
246
|
-
it('should report when a parameter has been removed', () => {
|
|
247
|
-
const existingComposition = {
|
|
248
|
-
_id: 'root',
|
|
249
|
-
_name: 'root',
|
|
250
|
-
type: 'root',
|
|
251
|
-
parameters: {
|
|
252
|
-
title: {
|
|
253
|
-
type: 'text',
|
|
254
|
-
value: 'Hello to you',
|
|
255
|
-
},
|
|
256
|
-
},
|
|
257
|
-
};
|
|
258
|
-
const composition = {
|
|
259
|
-
_id: 'root',
|
|
260
|
-
_name: 'root',
|
|
261
|
-
type: 'root',
|
|
262
|
-
};
|
|
263
|
-
const [result] = diff(existingComposition, composition);
|
|
264
|
-
expect(result).toEqual({
|
|
265
|
-
componentId: 'root',
|
|
266
|
-
parameterName: 'title',
|
|
267
|
-
type: ComponentDiffType.ParameterRemoved,
|
|
268
|
-
});
|
|
269
|
-
});
|
|
270
|
-
it('should only report a move when it matters', () => {
|
|
271
|
-
const existingComposition = {
|
|
272
|
-
_id: 'root',
|
|
273
|
-
_name: 'root',
|
|
274
|
-
type: 'root',
|
|
275
|
-
slots: {
|
|
276
|
-
content: [
|
|
277
|
-
{
|
|
278
|
-
_id: 'child1',
|
|
279
|
-
type: 'child',
|
|
280
|
-
},
|
|
281
|
-
{
|
|
282
|
-
_id: 'child2',
|
|
283
|
-
type: 'child',
|
|
284
|
-
},
|
|
285
|
-
{
|
|
286
|
-
_id: 'child3',
|
|
287
|
-
type: 'child',
|
|
288
|
-
},
|
|
289
|
-
],
|
|
290
|
-
other: [],
|
|
291
|
-
},
|
|
292
|
-
};
|
|
293
|
-
const composition = {
|
|
294
|
-
_id: 'root',
|
|
295
|
-
_name: 'root',
|
|
296
|
-
type: 'root',
|
|
297
|
-
slots: {
|
|
298
|
-
content: [
|
|
299
|
-
{
|
|
300
|
-
_id: 'child1',
|
|
301
|
-
type: 'child',
|
|
302
|
-
},
|
|
303
|
-
{
|
|
304
|
-
_id: 'child3',
|
|
305
|
-
type: 'child',
|
|
306
|
-
},
|
|
307
|
-
],
|
|
308
|
-
other: [
|
|
309
|
-
{
|
|
310
|
-
_id: 'child2',
|
|
311
|
-
type: 'child',
|
|
312
|
-
},
|
|
313
|
-
],
|
|
314
|
-
},
|
|
315
|
-
};
|
|
316
|
-
const [result, ...rest] = diff(existingComposition, composition);
|
|
317
|
-
expect(result).toEqual({
|
|
318
|
-
type: ComponentDiffType.ComponentMoved,
|
|
319
|
-
id: 'child2',
|
|
320
|
-
parentId: undefined,
|
|
321
|
-
slot: 'other',
|
|
322
|
-
slotIndex: 0,
|
|
323
|
-
});
|
|
324
|
-
expect(rest.length).toBe(0);
|
|
325
|
-
});
|
|
326
|
-
it('should not nest slots in a component add diff entry', () => {
|
|
327
|
-
const existingComposition = {
|
|
328
|
-
_id: 'root',
|
|
329
|
-
_name: 'root',
|
|
330
|
-
type: 'root',
|
|
331
|
-
slots: {
|
|
332
|
-
content: [],
|
|
333
|
-
},
|
|
334
|
-
};
|
|
335
|
-
const composition = {
|
|
336
|
-
_id: 'root',
|
|
337
|
-
_name: 'root',
|
|
338
|
-
type: 'root',
|
|
339
|
-
slots: {
|
|
340
|
-
content: [
|
|
341
|
-
{
|
|
342
|
-
_id: 'p13n',
|
|
343
|
-
type: 'p13n',
|
|
344
|
-
parameters: {
|
|
345
|
-
name: {
|
|
346
|
-
type: 'text',
|
|
347
|
-
value: 'Hero',
|
|
348
|
-
},
|
|
349
|
-
},
|
|
350
|
-
slots: {
|
|
351
|
-
pz: [
|
|
352
|
-
{
|
|
353
|
-
_id: 'hero',
|
|
354
|
-
type: 'hero',
|
|
355
|
-
},
|
|
356
|
-
],
|
|
357
|
-
},
|
|
358
|
-
},
|
|
359
|
-
],
|
|
360
|
-
},
|
|
361
|
-
};
|
|
362
|
-
const result = diff(existingComposition, composition);
|
|
363
|
-
expect(result).toEqual([
|
|
364
|
-
{
|
|
365
|
-
type: ComponentDiffType.ComponentAdded,
|
|
366
|
-
id: 'p13n',
|
|
367
|
-
parentId: 'root',
|
|
368
|
-
slot: 'content',
|
|
369
|
-
slotIndex: 0,
|
|
370
|
-
component: {
|
|
371
|
-
_id: 'p13n',
|
|
372
|
-
type: 'p13n',
|
|
373
|
-
parameters: {
|
|
374
|
-
name: {
|
|
375
|
-
type: 'text',
|
|
376
|
-
value: 'Hero',
|
|
377
|
-
},
|
|
378
|
-
},
|
|
379
|
-
},
|
|
380
|
-
},
|
|
381
|
-
{
|
|
382
|
-
type: ComponentDiffType.ComponentAdded,
|
|
383
|
-
id: 'hero',
|
|
384
|
-
parentId: 'p13n',
|
|
385
|
-
slot: 'pz',
|
|
386
|
-
slotIndex: 0,
|
|
387
|
-
component: {
|
|
388
|
-
_id: 'hero',
|
|
389
|
-
type: 'hero',
|
|
390
|
-
},
|
|
391
|
-
},
|
|
392
|
-
]);
|
|
393
|
-
});
|
|
394
|
-
});
|
package/dist/utils/apply.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { RootComponentInstance } from '@uniformdev/canvas';
|
|
2
|
-
|
|
3
|
-
import { ComponentDiff } from './diff';
|
|
4
|
-
export declare const applyDiff: ({
|
|
5
|
-
composition,
|
|
6
|
-
diff,
|
|
7
|
-
}: {
|
|
8
|
-
composition: RootComponentInstance;
|
|
9
|
-
diff: ComponentDiff[];
|
|
10
|
-
}) => RootComponentInstance;
|
package/dist/utils/apply.js
DELETED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import { getAllComponents, getSlotComponents } from './comp';
|
|
2
|
-
import { ComponentDiffType } from './diff';
|
|
3
|
-
export const applyDiff = ({ composition, diff, }) => {
|
|
4
|
-
const existingComponents = getAllComponents(composition);
|
|
5
|
-
const movedComponents = [];
|
|
6
|
-
diff.forEach((item) => {
|
|
7
|
-
var _a, _b, _c;
|
|
8
|
-
if (item.type === ComponentDiffType.ComponentRemoved) {
|
|
9
|
-
// remove item from existing components
|
|
10
|
-
delete existingComponents[item.id];
|
|
11
|
-
}
|
|
12
|
-
else if (item.type === ComponentDiffType.ComponentAdded) {
|
|
13
|
-
existingComponents[item.id] = item;
|
|
14
|
-
movedComponents.push(item.id);
|
|
15
|
-
}
|
|
16
|
-
else if (item.type === ComponentDiffType.ComponentMoved) {
|
|
17
|
-
const component = existingComponents[item.id];
|
|
18
|
-
if (component) {
|
|
19
|
-
if (item.parentId) {
|
|
20
|
-
component.parentId = item.parentId;
|
|
21
|
-
}
|
|
22
|
-
if (item.slot) {
|
|
23
|
-
component.slot = item.slot;
|
|
24
|
-
}
|
|
25
|
-
if (typeof item.slotIndex === 'number') {
|
|
26
|
-
component.slotIndex = item.slotIndex;
|
|
27
|
-
}
|
|
28
|
-
movedComponents.push(item.id);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
else if (item.type === ComponentDiffType.ParameterChanged) {
|
|
32
|
-
existingComponents[item.componentId].component.parameters = {
|
|
33
|
-
...existingComponents[item.componentId].component.parameters,
|
|
34
|
-
[item.parameterName]: {
|
|
35
|
-
...(((_a = existingComponents[item.componentId].component.parameters) === null || _a === void 0 ? void 0 : _a[item.parameterName]) || {
|
|
36
|
-
type: 'text',
|
|
37
|
-
}),
|
|
38
|
-
value: item.value,
|
|
39
|
-
},
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
else if (item.type === ComponentDiffType.ParameterRemoved) {
|
|
43
|
-
if ((_b = existingComponents[item.componentId].component.parameters) === null || _b === void 0 ? void 0 : _b[item.parameterName]) {
|
|
44
|
-
(_c = existingComponents[item.componentId].component.parameters) === null || _c === void 0 ? true : delete _c[item.parameterName];
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
// moving components will insert conflicting ids, so we need to do a little
|
|
49
|
-
// conflict resolution
|
|
50
|
-
movedComponents.forEach((movedComponentId) => {
|
|
51
|
-
const movedComponent = existingComponents[movedComponentId];
|
|
52
|
-
const slotComponents = getSlotComponents({
|
|
53
|
-
slot: movedComponent.slot,
|
|
54
|
-
components: existingComponents,
|
|
55
|
-
parentId: movedComponent.parentId,
|
|
56
|
-
});
|
|
57
|
-
for (let i = 0; i < slotComponents.length; i++) {
|
|
58
|
-
const currentComponent = slotComponents[i];
|
|
59
|
-
const nextComponent = slotComponents[i + 1];
|
|
60
|
-
const currentIsMoved = movedComponents.indexOf(currentComponent.id) > -1;
|
|
61
|
-
if (currentComponent.slotIndex === (nextComponent === null || nextComponent === void 0 ? void 0 : nextComponent.slotIndex) && !currentIsMoved) {
|
|
62
|
-
slotComponents[i] = nextComponent;
|
|
63
|
-
slotComponents[i + 1] = currentComponent;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
for (let i = 0; i < slotComponents.length; i++) {
|
|
67
|
-
const c = slotComponents[i];
|
|
68
|
-
existingComponents[c.id].slotIndex = i;
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
const processedRoot = processNode({
|
|
72
|
-
id: composition._id,
|
|
73
|
-
components: existingComponents,
|
|
74
|
-
source: composition,
|
|
75
|
-
});
|
|
76
|
-
const { slots, ...rest } = composition;
|
|
77
|
-
const root = {
|
|
78
|
-
...rest,
|
|
79
|
-
...processedRoot,
|
|
80
|
-
};
|
|
81
|
-
return root;
|
|
82
|
-
};
|
|
83
|
-
const processNode = ({ id, components, source, }) => {
|
|
84
|
-
const componentReference = components[id];
|
|
85
|
-
if (!componentReference) {
|
|
86
|
-
return undefined;
|
|
87
|
-
}
|
|
88
|
-
const { component } = componentReference;
|
|
89
|
-
const { slots, ...rest } = component;
|
|
90
|
-
const instance = {
|
|
91
|
-
...rest,
|
|
92
|
-
};
|
|
93
|
-
const slotNames = Object.keys(slots || {});
|
|
94
|
-
Object.keys(components).forEach((cid) => {
|
|
95
|
-
if (components[cid].slot &&
|
|
96
|
-
components[cid].parentId === id &&
|
|
97
|
-
!slotNames.includes(components[cid].slot)) {
|
|
98
|
-
slotNames.push(components[cid].slot);
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
slotNames.forEach((slotName) => {
|
|
102
|
-
const slotComponents = getSlotComponents({
|
|
103
|
-
slot: slotName,
|
|
104
|
-
components,
|
|
105
|
-
parentId: id,
|
|
106
|
-
});
|
|
107
|
-
const processedSlotComponents = [];
|
|
108
|
-
slotComponents.forEach((slotComponent) => {
|
|
109
|
-
const processedSlotComponent = processNode({
|
|
110
|
-
id: slotComponent.id,
|
|
111
|
-
components,
|
|
112
|
-
source,
|
|
113
|
-
});
|
|
114
|
-
if (processedSlotComponent) {
|
|
115
|
-
processedSlotComponents.push(processedSlotComponent);
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
|
-
if (processedSlotComponents.length || (slots && slots[slotName])) {
|
|
119
|
-
instance.slots = instance.slots || {};
|
|
120
|
-
instance.slots[slotName] = processedSlotComponents;
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
return instance;
|
|
124
|
-
};
|
package/dist/utils/comp.d.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { ComponentInstance, RootComponentInstance } from '@uniformdev/canvas';
|
|
2
|
-
export type ComponentReference = {
|
|
3
|
-
parentId: string | undefined;
|
|
4
|
-
slot: string | undefined;
|
|
5
|
-
slotIndex: number | undefined;
|
|
6
|
-
component: ComponentInstance;
|
|
7
|
-
};
|
|
8
|
-
export declare const getAllComponents: (
|
|
9
|
-
composition: RootComponentInstance
|
|
10
|
-
) => Record<string, ComponentReference>;
|
|
11
|
-
export declare const getComponent: (
|
|
12
|
-
composition: RootComponentInstance,
|
|
13
|
-
id: string
|
|
14
|
-
) => ComponentInstance | undefined;
|
|
15
|
-
export declare const getSlotComponents: ({
|
|
16
|
-
components,
|
|
17
|
-
slot,
|
|
18
|
-
parentId,
|
|
19
|
-
}: {
|
|
20
|
-
components: Record<string, ComponentReference>;
|
|
21
|
-
slot: string | undefined;
|
|
22
|
-
parentId: string | undefined;
|
|
23
|
-
}) => (ComponentReference & {
|
|
24
|
-
id: string;
|
|
25
|
-
})[];
|
package/dist/utils/comp.js
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { walkNodeTree } from '@uniformdev/canvas';
|
|
2
|
-
export const getAllComponents = (composition) => {
|
|
3
|
-
const ids = {};
|
|
4
|
-
walkNodeTree(composition, ({ type, actions, node, ancestorsAndSelf }) => {
|
|
5
|
-
if (type !== 'component') {
|
|
6
|
-
// don't want blocks here
|
|
7
|
-
actions.stopProcessingDescendants();
|
|
8
|
-
return;
|
|
9
|
-
}
|
|
10
|
-
if (node._id) {
|
|
11
|
-
const [self, parent] = ancestorsAndSelf;
|
|
12
|
-
if (self.type === 'block') {
|
|
13
|
-
// just to make TS happy, we already know this is true due to the preceding type-prop check
|
|
14
|
-
return;
|
|
15
|
-
}
|
|
16
|
-
const slotIndex = self.type === 'root' ? undefined : self.parentSlotIndex;
|
|
17
|
-
const slot = self.type === 'root' ? undefined : self.parentSlot;
|
|
18
|
-
ids[node._id] = {
|
|
19
|
-
parentId: parent === null || parent === void 0 ? void 0 : parent.node._id,
|
|
20
|
-
slot,
|
|
21
|
-
slotIndex,
|
|
22
|
-
component: node,
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
return ids;
|
|
27
|
-
};
|
|
28
|
-
export const getComponent = (composition, id) => {
|
|
29
|
-
let result;
|
|
30
|
-
walkNodeTree(composition, ({ type, node, actions }) => {
|
|
31
|
-
// note: does not work on blocks because it didn't before - so leaving that for back compat
|
|
32
|
-
// no technical reason I know of why we can't let it find blocks by ID
|
|
33
|
-
if (type !== 'component') {
|
|
34
|
-
actions.stopProcessingDescendants();
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
if (node._id === id) {
|
|
38
|
-
result = node;
|
|
39
|
-
actions.stopProcessingDescendants();
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
return result;
|
|
43
|
-
};
|
|
44
|
-
export const getSlotComponents = ({ components, slot, parentId, }) => {
|
|
45
|
-
const slotComponents = [];
|
|
46
|
-
Object.keys(components).forEach((cid) => {
|
|
47
|
-
if (components[cid].parentId === parentId && components[cid].slot === slot) {
|
|
48
|
-
slotComponents.push({
|
|
49
|
-
...components[cid],
|
|
50
|
-
id: cid,
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
// sort by slot index
|
|
55
|
-
slotComponents.sort((a, b) => {
|
|
56
|
-
if (a.slotIndex === b.slotIndex) {
|
|
57
|
-
return 0;
|
|
58
|
-
}
|
|
59
|
-
if (typeof a.slotIndex === 'number' && typeof b.slotIndex === 'number') {
|
|
60
|
-
return a.slotIndex - b.slotIndex;
|
|
61
|
-
}
|
|
62
|
-
return 0;
|
|
63
|
-
});
|
|
64
|
-
return slotComponents;
|
|
65
|
-
};
|
package/dist/utils/diff.d.ts
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { ComponentInstance, RootComponentInstance } from '@uniformdev/canvas';
|
|
2
|
-
|
|
3
|
-
import { ComponentReference } from './comp';
|
|
4
|
-
export type ComponentDiff =
|
|
5
|
-
| ComponentRemovedDiff
|
|
6
|
-
| ComponentAddedDiff
|
|
7
|
-
| ParameterChangedDiff
|
|
8
|
-
| ParameterRemovedDiff
|
|
9
|
-
| ComponentMovedDiff;
|
|
10
|
-
export declare enum ComponentDiffType {
|
|
11
|
-
ComponentRemoved = 'cr',
|
|
12
|
-
ComponentAdded = 'ca',
|
|
13
|
-
ComponentMoved = 'cm',
|
|
14
|
-
ParameterChanged = 'pc',
|
|
15
|
-
ParameterRemoved = 'pr',
|
|
16
|
-
}
|
|
17
|
-
export type ComponentRemovedDiff = {
|
|
18
|
-
type: ComponentDiffType.ComponentRemoved;
|
|
19
|
-
id: string;
|
|
20
|
-
};
|
|
21
|
-
export type ComponentAddedDiff = ComponentReference & {
|
|
22
|
-
type: ComponentDiffType.ComponentAdded;
|
|
23
|
-
id: string;
|
|
24
|
-
component: ComponentInstance;
|
|
25
|
-
};
|
|
26
|
-
export type ComponentMovedDiff = {
|
|
27
|
-
type: ComponentDiffType.ComponentMoved;
|
|
28
|
-
id: string;
|
|
29
|
-
parentId: string | undefined;
|
|
30
|
-
slot: string | undefined;
|
|
31
|
-
slotIndex: number | undefined;
|
|
32
|
-
};
|
|
33
|
-
export type ParameterChangedDiff = {
|
|
34
|
-
type: ComponentDiffType.ParameterChanged;
|
|
35
|
-
componentId: string;
|
|
36
|
-
parameterName: string;
|
|
37
|
-
value: any;
|
|
38
|
-
};
|
|
39
|
-
export type ParameterRemovedDiff = {
|
|
40
|
-
type: ComponentDiffType.ParameterRemoved;
|
|
41
|
-
componentId: string;
|
|
42
|
-
parameterName: string;
|
|
43
|
-
};
|
|
44
|
-
export declare const diff: (
|
|
45
|
-
existingComposition: RootComponentInstance,
|
|
46
|
-
composition: RootComponentInstance
|
|
47
|
-
) => ComponentDiff[];
|
|
48
|
-
export declare const isSlotTheSame: ({
|
|
49
|
-
existingComposition,
|
|
50
|
-
components,
|
|
51
|
-
slot,
|
|
52
|
-
parentId,
|
|
53
|
-
}: {
|
|
54
|
-
existingComposition: Record<string, ComponentReference>;
|
|
55
|
-
components: Record<string, ComponentReference>;
|
|
56
|
-
slot: string | undefined;
|
|
57
|
-
parentId: string | undefined;
|
|
58
|
-
}) => boolean;
|