@uniformdev/canvas-next-rsc 19.173.1-alpha.17 → 19.173.2-alpha.258
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/dist/UniformComposition-0pvEHduc.d.mts +64 -0
- package/dist/UniformComposition-0pvEHduc.d.ts +77 -0
- package/dist/UniformComposition-38e22896.d.ts +74 -0
- package/dist/UniformComposition-B-Z17dUt.d.ts +56 -43
- package/dist/UniformComposition-D4tBQ2U4.d.mts +64 -0
- package/dist/UniformComposition-D4tBQ2U4.d.ts +77 -0
- package/dist/UniformComposition-Dw55RFP6.d.mts +67 -0
- package/dist/UniformComposition-Dw55RFP6.d.ts +67 -0
- package/dist/UniformComposition-d178d865.d.ts +77 -0
- package/dist/actions/updateContext.d.ts +2 -0
- package/dist/actions/updateContext.js +17 -0
- package/dist/client/canvasClient.d.ts +5 -0
- package/dist/client/canvasClient.js +53 -0
- package/dist/client/manifestClient.d.ts +209 -0
- package/dist/client/manifestClient.js +33 -0
- package/dist/client/projectMapClient.d.ts +5 -0
- package/dist/client/projectMapClient.js +17 -0
- package/dist/client/routeClient.d.ts +5 -0
- package/dist/client/routeClient.js +68 -0
- package/dist/component.d.mts +23 -5
- package/dist/component.d.ts +23 -5
- package/dist/component.js +94 -37
- package/dist/component.mjs +93 -35
- package/dist/components/DefaultNotImplementedComponent.d.ts +4 -0
- package/dist/components/DefaultNotImplementedComponent.js +45 -0
- package/dist/components/GoogleTagManagerAnalytics.d.ts +3 -0
- package/dist/components/GoogleTagManagerAnalytics.js +44 -0
- package/dist/components/UniformComponent.d.ts +35 -0
- package/dist/components/UniformComponent.js +14 -0
- package/dist/components/UniformComposition.d.ts +47 -0
- package/dist/components/UniformComposition.js +35 -0
- package/dist/components/UniformContext.d.ts +13 -0
- package/dist/components/UniformContext.js +19 -0
- package/dist/components/UniformRichText.d.ts +42 -0
- package/dist/components/UniformRichText.js +15 -0
- package/dist/components/UniformRichTextNode.d.ts +14 -0
- package/dist/components/UniformRichTextNode.js +49 -0
- package/dist/components/UniformScript.d.ts +5 -0
- package/dist/components/UniformScript.js +49 -0
- package/dist/components/UniformSlot.d.ts +48 -0
- package/dist/components/UniformSlot.js +38 -0
- package/dist/components/UniformText.d.ts +10 -0
- package/dist/components/UniformText.js +5 -0
- package/dist/components/__tests__/evaluateComposition.spec.d.ts +1 -0
- package/dist/components/__tests__/evaluateComposition.spec.js +80 -0
- package/dist/components/convertComponentToProps.d.ts +18 -0
- package/dist/components/convertComponentToProps.js +22 -0
- package/dist/components/evaluateComposition.d.ts +32 -0
- package/dist/components/evaluateComposition.js +183 -0
- package/dist/components/getEnrichmentTags.d.ts +5 -0
- package/dist/components/getEnrichmentTags.js +13 -0
- package/dist/components/getUniformContext.d.ts +10 -0
- package/dist/components/getUniformContext.js +17 -0
- package/dist/components/nodes/HeadingRichTextNode.d.ts +2 -0
- package/dist/components/nodes/HeadingRichTextNode.js +6 -0
- package/dist/components/nodes/LinebreakRichTextNode.d.ts +2 -0
- package/dist/components/nodes/LinebreakRichTextNode.js +4 -0
- package/dist/components/nodes/LinkRichTextNode.d.ts +2 -0
- package/dist/components/nodes/LinkRichTextNode.js +6 -0
- package/dist/components/nodes/ListItemRichTextNode.d.ts +2 -0
- package/dist/components/nodes/ListItemRichTextNode.js +5 -0
- package/dist/components/nodes/ListRichTextNode.d.ts +2 -0
- package/dist/components/nodes/ListRichTextNode.js +6 -0
- package/dist/components/nodes/ParagraphRichTextNode.d.ts +2 -0
- package/dist/components/nodes/ParagraphRichTextNode.js +6 -0
- package/dist/components/nodes/TabRichTextNode.d.ts +2 -0
- package/dist/components/nodes/TabRichTextNode.js +4 -0
- package/dist/components/nodes/TextRichTextNode.d.ts +2 -0
- package/dist/components/nodes/TextRichTextNode.js +9 -0
- package/dist/components/renderComponent.d.ts +26 -0
- package/dist/components/renderComponent.js +52 -0
- package/dist/components/resolvePath.d.ts +5 -0
- package/dist/components/resolvePath.js +34 -0
- package/dist/components/retrieveRoute.d.ts +198 -0
- package/dist/components/retrieveRoute.js +146 -0
- package/dist/components/types.d.ts +15 -0
- package/dist/components/types.js +1 -0
- package/dist/config/helpers.d.ts +23 -0
- package/dist/config/helpers.js +34 -0
- package/dist/config/models.d.ts +51 -0
- package/dist/config/models.js +1 -0
- package/dist/config/uniform.server.config.d.ts +3 -0
- package/dist/config/uniform.server.config.js +4 -0
- package/dist/config.js +11 -17
- package/dist/config.mjs +11 -14
- package/dist/cookie/index.d.ts +12 -0
- package/dist/cookie/index.js +21 -0
- package/dist/handler/createPreviewGETRouteHandler.d.ts +1 -0
- package/dist/handler/createPreviewGETRouteHandler.js +43 -0
- package/dist/handler/createPreviewPOSTRouteHandler.d.ts +1 -0
- package/dist/handler/createPreviewPOSTRouteHandler.js +88 -0
- package/dist/handler/createUniformRouteHandler.d.ts +4 -0
- package/dist/handler/createUniformRouteHandler.js +10 -0
- package/dist/handler/helpers.d.ts +17 -0
- package/dist/handler/helpers.js +148 -0
- package/dist/handler/messages/handleCompositionChanged.d.ts +2 -0
- package/dist/handler/messages/handleCompositionChanged.js +9 -0
- package/dist/handler/messages/handleCompositionDeleted.d.ts +2 -0
- package/dist/handler/messages/handleCompositionDeleted.js +9 -0
- package/dist/handler/messages/handleCompositionPublished.d.ts +2 -0
- package/dist/handler/messages/handleCompositionPublished.js +9 -0
- package/dist/handler/messages/handleManifestPublished.d.ts +2 -0
- package/dist/handler/messages/handleManifestPublished.js +10 -0
- package/dist/handler/messages/handleProjectMapNodeDelete.d.ts +2 -0
- package/dist/handler/messages/handleProjectMapNodeDelete.js +21 -0
- package/dist/handler/messages/handleProjectMapNodeInsert.d.ts +2 -0
- package/dist/handler/messages/handleProjectMapNodeInsert.js +21 -0
- package/dist/handler/messages/handleProjectMapNodeUpdate.d.ts +2 -0
- package/dist/handler/messages/handleProjectMapNodeUpdate.js +22 -0
- package/dist/handler/messages/handleRedirectDelete.d.ts +2 -0
- package/dist/handler/messages/handleRedirectDelete.js +15 -0
- package/dist/handler/messages/handleRedirectInsert.d.ts +2 -0
- package/dist/handler/messages/handleRedirectInsert.js +15 -0
- package/dist/handler/messages/handleRedirectUpdate.d.ts +2 -0
- package/dist/handler/messages/handleRedirectUpdate.js +15 -0
- package/dist/handler.js +14 -10
- package/dist/handler.mjs +3 -16
- package/dist/hooks/useForgetMe.d.ts +4 -0
- package/dist/hooks/useForgetMe.js +10 -0
- package/dist/hooks/useToggleConsent.d.ts +7 -0
- package/dist/hooks/useToggleConsent.js +22 -0
- package/dist/hooks/useUniformContext.d.ts +1 -0
- package/dist/hooks/useUniformContext.js +3 -0
- package/dist/index.d.mts +38 -38
- package/dist/index.d.ts +38 -38
- package/dist/index.esm.js +57 -37
- package/dist/index.js +85 -62
- package/dist/index.mjs +57 -37
- package/dist/models/index.d.ts +30 -0
- package/dist/models/index.js +1 -0
- package/dist/register/componentStore.d.ts +1 -0
- package/dist/register/componentStore.js +2 -0
- package/dist/register/componentStoreResolver.d.ts +4 -0
- package/dist/register/componentStoreResolver.js +5 -0
- package/dist/register/createComponentStore.d.ts +12 -0
- package/dist/register/createComponentStore.js +13 -0
- package/dist/register/createComponentStoreResolver.d.ts +12 -0
- package/dist/register/createComponentStoreResolver.js +9 -0
- package/dist/register/getTypeWithVariant.d.ts +1 -0
- package/dist/register/getTypeWithVariant.js +1 -0
- package/dist/register/registerUniformComponent.d.ts +10 -0
- package/dist/register/registerUniformComponent.js +8 -0
- package/dist/resolve/resolveChildren.d.ts +17 -0
- package/dist/resolve/resolveChildren.js +20 -0
- package/dist/score/index.d.ts +3 -0
- package/dist/score/index.js +114 -0
- package/dist/utils/__tests__/apply.spec.d.ts +1 -0
- package/dist/utils/__tests__/apply.spec.js +358 -0
- package/dist/utils/__tests__/diff.spec.d.ts +1 -0
- package/dist/utils/__tests__/diff.spec.js +394 -0
- package/dist/utils/apply.d.ts +10 -0
- package/dist/utils/apply.js +124 -0
- package/dist/utils/comp.d.ts +25 -0
- package/dist/utils/comp.js +65 -0
- package/dist/utils/diff.d.ts +58 -0
- package/dist/utils/diff.js +144 -0
- package/dist/utils/draft.d.ts +20 -0
- package/dist/utils/draft.js +22 -0
- package/dist/utils/tag.d.ts +2 -0
- package/dist/utils/tag.js +7 -0
- package/dist/utils/url.d.ts +1 -0
- package/dist/utils/url.js +10 -0
- package/package.json +21 -21
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { RenderComponentResolver } from '@uniformdev/canvas-react';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
|
|
4
|
+
import { CompositionContext, UniformComponentProps } from '../components/UniformComponent';
|
|
5
|
+
export declare function resolveChildren<TRenderProps = unknown>({
|
|
6
|
+
children,
|
|
7
|
+
data,
|
|
8
|
+
context,
|
|
9
|
+
hasParentLayout,
|
|
10
|
+
resolveRenderer,
|
|
11
|
+
}: {
|
|
12
|
+
children: UniformComponentProps<TRenderProps>['children'];
|
|
13
|
+
data: Required<UniformComponentProps<TRenderProps>>['data'];
|
|
14
|
+
context: CompositionContext;
|
|
15
|
+
hasParentLayout: boolean;
|
|
16
|
+
resolveRenderer: RenderComponentResolver;
|
|
17
|
+
}): ReactNode;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createElement } from 'react';
|
|
3
|
+
import { convertComponentToProps } from '../components/convertComponentToProps';
|
|
4
|
+
import { UniformSlot } from '../components/UniformSlot';
|
|
5
|
+
export function resolveChildren({ children, data, context, hasParentLayout, resolveRenderer, }) {
|
|
6
|
+
// attempt to resolve the top level component if we're at the root and children were not provided
|
|
7
|
+
if (!children && !hasParentLayout) {
|
|
8
|
+
const topLevelComponent = resolveRenderer({ type: data.type });
|
|
9
|
+
if (topLevelComponent) {
|
|
10
|
+
children = createElement(topLevelComponent, convertComponentToProps({ component: data, context }));
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
children = Object.keys(data.slots || {}).map((slotName) => (_jsx(UniformSlot, { name: slotName, data: data, context: context }, slotName)));
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
const renderChildren = typeof children === 'function'
|
|
17
|
+
? children(convertComponentToProps({ component: data, context }))
|
|
18
|
+
: children;
|
|
19
|
+
return renderChildren;
|
|
20
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
const TYPE_SEP = '~';
|
|
2
|
+
const PAIR_SEP = '!';
|
|
3
|
+
const KV_SEP = '-';
|
|
4
|
+
// the cookie format is thus:
|
|
5
|
+
// <ab-test-data>~<session-scores>~<visitor-scores>
|
|
6
|
+
// where each type is subdivided into key-value pairs:
|
|
7
|
+
// <k>-<v>!<k>-<v>!...
|
|
8
|
+
// score data is further encoded into base64, so the scores themselves are compressed
|
|
9
|
+
// example:
|
|
10
|
+
// mytest-var1!mytest2-var2~ses1-x!ses2-1~vis1-fa~vis2-10
|
|
11
|
+
// means:
|
|
12
|
+
// mytest test: var1 variant
|
|
13
|
+
// mytest2 test: var2 variant
|
|
14
|
+
// ses1 session signal: bton(x) score
|
|
15
|
+
// ses2 session signal: bton(1) score
|
|
16
|
+
// vis1 visitor signal: bton(fa) score
|
|
17
|
+
// vis2 visitor signal: bton(10) score;
|
|
18
|
+
export function parseScoreCookie(cookieValue) {
|
|
19
|
+
if (!cookieValue)
|
|
20
|
+
return;
|
|
21
|
+
const types = cookieValue.split(TYPE_SEP);
|
|
22
|
+
if (types.length > 3)
|
|
23
|
+
return;
|
|
24
|
+
const [abTestData, sessionScores, visitorScores] = types;
|
|
25
|
+
return {
|
|
26
|
+
// this is true since we're reading a cookie, which wouldn't exist if consent wasn't given
|
|
27
|
+
consent: true,
|
|
28
|
+
sessionScores: decodeCookieType(parseCookieType(sessionScores)),
|
|
29
|
+
scores: decodeCookieType(parseCookieType(visitorScores)),
|
|
30
|
+
tests: parseCookieType(abTestData),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
function parseCookieType(type) {
|
|
34
|
+
if (!type) {
|
|
35
|
+
return {};
|
|
36
|
+
}
|
|
37
|
+
const pairs = type.split(PAIR_SEP).map((pair) => pair.split(KV_SEP));
|
|
38
|
+
return pairs.reduce((acc, cur) => {
|
|
39
|
+
if (cur.length < 2)
|
|
40
|
+
return acc;
|
|
41
|
+
// join handles the case when there is a pair separator in the value,
|
|
42
|
+
// i.e. testname-testid-with-hyphens
|
|
43
|
+
acc[cur[0]] = cur.slice(1).join('-');
|
|
44
|
+
return acc;
|
|
45
|
+
}, {});
|
|
46
|
+
}
|
|
47
|
+
function decodeCookieType(type) {
|
|
48
|
+
return Object.entries(type).reduce((acc, [key, value]) => {
|
|
49
|
+
acc[key] = bton(value);
|
|
50
|
+
return acc;
|
|
51
|
+
}, {});
|
|
52
|
+
}
|
|
53
|
+
export function serializeCookie(data) {
|
|
54
|
+
return [
|
|
55
|
+
serializeCookieType(data.tests),
|
|
56
|
+
serializeCookieType(encodeCookieType(data.sessionScores)),
|
|
57
|
+
serializeCookieType(encodeCookieType(data.scores)),
|
|
58
|
+
].join(TYPE_SEP);
|
|
59
|
+
}
|
|
60
|
+
function encodeCookieType(type) {
|
|
61
|
+
return Object.entries(type).reduce((acc, [key, value]) => {
|
|
62
|
+
acc[key] = ntob(value);
|
|
63
|
+
return acc;
|
|
64
|
+
}, {});
|
|
65
|
+
}
|
|
66
|
+
function serializeCookieType(type) {
|
|
67
|
+
return Object.entries(type)
|
|
68
|
+
.map((kv) => kv.join(KV_SEP))
|
|
69
|
+
.join(PAIR_SEP);
|
|
70
|
+
}
|
|
71
|
+
const alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
72
|
+
// binary to string lookup table
|
|
73
|
+
const b2s = alphabet.split('');
|
|
74
|
+
// string to binary lookup table
|
|
75
|
+
// 123 == 'z'.charCodeAt(0) + 1
|
|
76
|
+
const s2b = new Array(123);
|
|
77
|
+
for (let i = 0; i < alphabet.length; i++) {
|
|
78
|
+
s2b[alphabet.charCodeAt(i)] = i;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Converts a number to a base64 string of its representation.
|
|
82
|
+
* Compresses the number if it is to be transferred in a string representation.
|
|
83
|
+
*/
|
|
84
|
+
const ntob = (number) => {
|
|
85
|
+
if (number < 0)
|
|
86
|
+
return `-${ntob(-number)}`;
|
|
87
|
+
let lo = number >>> 0;
|
|
88
|
+
let hi = (number / 4294967296) >>> 0;
|
|
89
|
+
let right = '';
|
|
90
|
+
while (hi > 0) {
|
|
91
|
+
right = b2s[0x3f & lo] + right;
|
|
92
|
+
lo >>>= 6;
|
|
93
|
+
lo |= (0x3f & hi) << 26;
|
|
94
|
+
hi >>>= 6;
|
|
95
|
+
}
|
|
96
|
+
let left = '';
|
|
97
|
+
do {
|
|
98
|
+
left = b2s[0x3f & lo] + left;
|
|
99
|
+
lo >>>= 6;
|
|
100
|
+
} while (lo > 0);
|
|
101
|
+
return left + right;
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* Converts a base64 string to an equivalent number _represented as a string in base64_.
|
|
105
|
+
* Decompresses a number from the compressed base64 string.
|
|
106
|
+
*/
|
|
107
|
+
const bton = (base64) => {
|
|
108
|
+
let number = 0;
|
|
109
|
+
const sign = base64.charAt(0) === '-' ? 1 : 0;
|
|
110
|
+
for (let i = sign; i < base64.length; i++) {
|
|
111
|
+
number = number * 64 + s2b[base64.charCodeAt(i)];
|
|
112
|
+
}
|
|
113
|
+
return sign ? -number : number;
|
|
114
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
import { applyDiff } from '../apply';
|
|
2
|
+
import { ComponentDiffType } from '../diff';
|
|
3
|
+
describe('apply', () => {
|
|
4
|
+
it('should leave a composition alone if the diff is blank', () => {
|
|
5
|
+
const result = applyDiff({
|
|
6
|
+
composition: {
|
|
7
|
+
_id: 'root',
|
|
8
|
+
_name: 'root',
|
|
9
|
+
type: 'root',
|
|
10
|
+
},
|
|
11
|
+
diff: [],
|
|
12
|
+
});
|
|
13
|
+
expect(result).toEqual({
|
|
14
|
+
_id: 'root',
|
|
15
|
+
_name: 'root',
|
|
16
|
+
type: 'root',
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
it('should add a slot component if diff specifies one', () => {
|
|
20
|
+
const result = applyDiff({
|
|
21
|
+
composition: {
|
|
22
|
+
_id: 'root',
|
|
23
|
+
_name: 'root',
|
|
24
|
+
type: 'root',
|
|
25
|
+
slots: {
|
|
26
|
+
content: [],
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
diff: [
|
|
30
|
+
{
|
|
31
|
+
type: ComponentDiffType.ComponentAdded,
|
|
32
|
+
id: 'child',
|
|
33
|
+
parentId: 'root',
|
|
34
|
+
slot: 'content',
|
|
35
|
+
slotIndex: 0,
|
|
36
|
+
component: {
|
|
37
|
+
type: 'child',
|
|
38
|
+
_id: 'child',
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
});
|
|
43
|
+
expect(result).toEqual({
|
|
44
|
+
_id: 'root',
|
|
45
|
+
_name: 'root',
|
|
46
|
+
type: 'root',
|
|
47
|
+
slots: {
|
|
48
|
+
content: [
|
|
49
|
+
{
|
|
50
|
+
_id: 'child',
|
|
51
|
+
type: 'child',
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
it('should remove a slot component if diff specifies one', () => {
|
|
58
|
+
const result = applyDiff({
|
|
59
|
+
composition: {
|
|
60
|
+
_id: 'root',
|
|
61
|
+
_name: 'root',
|
|
62
|
+
type: 'root',
|
|
63
|
+
slots: {
|
|
64
|
+
content: [
|
|
65
|
+
{
|
|
66
|
+
type: 'child1',
|
|
67
|
+
_id: 'child',
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
type: 'child',
|
|
71
|
+
_id: 'child2',
|
|
72
|
+
},
|
|
73
|
+
],
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
diff: [
|
|
77
|
+
{
|
|
78
|
+
type: ComponentDiffType.ComponentRemoved,
|
|
79
|
+
id: 'child',
|
|
80
|
+
},
|
|
81
|
+
],
|
|
82
|
+
});
|
|
83
|
+
expect(result).toEqual({
|
|
84
|
+
_id: 'root',
|
|
85
|
+
_name: 'root',
|
|
86
|
+
type: 'root',
|
|
87
|
+
slots: {
|
|
88
|
+
content: [
|
|
89
|
+
{
|
|
90
|
+
type: 'child',
|
|
91
|
+
_id: 'child2',
|
|
92
|
+
},
|
|
93
|
+
],
|
|
94
|
+
},
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
it('should move a slot component if diff specifies one', () => {
|
|
98
|
+
const result = applyDiff({
|
|
99
|
+
composition: {
|
|
100
|
+
_id: 'root',
|
|
101
|
+
_name: 'root',
|
|
102
|
+
type: 'root',
|
|
103
|
+
slots: {
|
|
104
|
+
content: [
|
|
105
|
+
{
|
|
106
|
+
type: 'child',
|
|
107
|
+
_id: 'child1',
|
|
108
|
+
slots: {
|
|
109
|
+
content: [],
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
type: 'child',
|
|
114
|
+
_id: 'child2',
|
|
115
|
+
},
|
|
116
|
+
],
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
diff: [
|
|
120
|
+
{
|
|
121
|
+
type: ComponentDiffType.ComponentMoved,
|
|
122
|
+
id: 'child2',
|
|
123
|
+
parentId: 'child1',
|
|
124
|
+
slot: 'content',
|
|
125
|
+
slotIndex: 0,
|
|
126
|
+
},
|
|
127
|
+
],
|
|
128
|
+
});
|
|
129
|
+
expect(result).toEqual({
|
|
130
|
+
_id: 'root',
|
|
131
|
+
_name: 'root',
|
|
132
|
+
type: 'root',
|
|
133
|
+
slots: {
|
|
134
|
+
content: [
|
|
135
|
+
{
|
|
136
|
+
type: 'child',
|
|
137
|
+
_id: 'child1',
|
|
138
|
+
slots: {
|
|
139
|
+
content: [
|
|
140
|
+
{
|
|
141
|
+
type: 'child',
|
|
142
|
+
_id: 'child2',
|
|
143
|
+
},
|
|
144
|
+
],
|
|
145
|
+
},
|
|
146
|
+
},
|
|
147
|
+
],
|
|
148
|
+
},
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
it('should move a slot component if diff specifies one, even if target does not define slot', () => {
|
|
152
|
+
const result = applyDiff({
|
|
153
|
+
composition: {
|
|
154
|
+
_id: 'root',
|
|
155
|
+
_name: 'root',
|
|
156
|
+
type: 'root',
|
|
157
|
+
slots: {
|
|
158
|
+
content: [
|
|
159
|
+
{
|
|
160
|
+
type: 'child',
|
|
161
|
+
_id: 'child1',
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
type: 'child',
|
|
165
|
+
_id: 'child2',
|
|
166
|
+
},
|
|
167
|
+
],
|
|
168
|
+
},
|
|
169
|
+
},
|
|
170
|
+
diff: [
|
|
171
|
+
{
|
|
172
|
+
type: ComponentDiffType.ComponentMoved,
|
|
173
|
+
id: 'child2',
|
|
174
|
+
parentId: 'child1',
|
|
175
|
+
slot: 'content',
|
|
176
|
+
slotIndex: 0,
|
|
177
|
+
},
|
|
178
|
+
],
|
|
179
|
+
});
|
|
180
|
+
expect(result).toEqual({
|
|
181
|
+
_id: 'root',
|
|
182
|
+
_name: 'root',
|
|
183
|
+
type: 'root',
|
|
184
|
+
slots: {
|
|
185
|
+
content: [
|
|
186
|
+
{
|
|
187
|
+
type: 'child',
|
|
188
|
+
_id: 'child1',
|
|
189
|
+
slots: {
|
|
190
|
+
content: [
|
|
191
|
+
{
|
|
192
|
+
type: 'child',
|
|
193
|
+
_id: 'child2',
|
|
194
|
+
},
|
|
195
|
+
],
|
|
196
|
+
},
|
|
197
|
+
},
|
|
198
|
+
],
|
|
199
|
+
},
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
it('should change a parameter if diff specifies one', () => {
|
|
203
|
+
const result = applyDiff({
|
|
204
|
+
composition: {
|
|
205
|
+
_id: 'root',
|
|
206
|
+
_name: 'root',
|
|
207
|
+
type: 'root',
|
|
208
|
+
parameters: {
|
|
209
|
+
title: {
|
|
210
|
+
type: 'text',
|
|
211
|
+
value: 'Hello',
|
|
212
|
+
},
|
|
213
|
+
},
|
|
214
|
+
},
|
|
215
|
+
diff: [
|
|
216
|
+
{
|
|
217
|
+
type: ComponentDiffType.ParameterChanged,
|
|
218
|
+
componentId: 'root',
|
|
219
|
+
parameterName: 'title',
|
|
220
|
+
value: 'Goodbye',
|
|
221
|
+
},
|
|
222
|
+
],
|
|
223
|
+
});
|
|
224
|
+
expect(result).toEqual({
|
|
225
|
+
_id: 'root',
|
|
226
|
+
_name: 'root',
|
|
227
|
+
type: 'root',
|
|
228
|
+
parameters: {
|
|
229
|
+
title: {
|
|
230
|
+
type: 'text',
|
|
231
|
+
value: 'Goodbye',
|
|
232
|
+
},
|
|
233
|
+
},
|
|
234
|
+
});
|
|
235
|
+
});
|
|
236
|
+
it('should delete a parameter if diff specifies one', () => {
|
|
237
|
+
const result = applyDiff({
|
|
238
|
+
composition: {
|
|
239
|
+
_id: 'root',
|
|
240
|
+
_name: 'root',
|
|
241
|
+
type: 'root',
|
|
242
|
+
parameters: {
|
|
243
|
+
title: {
|
|
244
|
+
type: 'text',
|
|
245
|
+
value: 'Hello',
|
|
246
|
+
},
|
|
247
|
+
},
|
|
248
|
+
},
|
|
249
|
+
diff: [
|
|
250
|
+
{
|
|
251
|
+
type: ComponentDiffType.ParameterRemoved,
|
|
252
|
+
componentId: 'root',
|
|
253
|
+
parameterName: 'title',
|
|
254
|
+
},
|
|
255
|
+
],
|
|
256
|
+
});
|
|
257
|
+
expect(result).toEqual({
|
|
258
|
+
_id: 'root',
|
|
259
|
+
_name: 'root',
|
|
260
|
+
type: 'root',
|
|
261
|
+
parameters: {},
|
|
262
|
+
});
|
|
263
|
+
});
|
|
264
|
+
it('should handle a component and move in a slot', () => {
|
|
265
|
+
const result = applyDiff({
|
|
266
|
+
composition: {
|
|
267
|
+
_id: 'root',
|
|
268
|
+
_name: 'root',
|
|
269
|
+
type: 'root',
|
|
270
|
+
slots: {
|
|
271
|
+
pageContent: [
|
|
272
|
+
{
|
|
273
|
+
type: 'hero',
|
|
274
|
+
_id: '1f352a25-7acb-4893-a11c-f06bd45f27ab',
|
|
275
|
+
},
|
|
276
|
+
{
|
|
277
|
+
type: 'hero',
|
|
278
|
+
_id: '93e9fa20-d86e-4543-9ca7-927ffeab6d54',
|
|
279
|
+
},
|
|
280
|
+
],
|
|
281
|
+
},
|
|
282
|
+
},
|
|
283
|
+
diff: [
|
|
284
|
+
{
|
|
285
|
+
type: ComponentDiffType.ComponentRemoved,
|
|
286
|
+
id: '1f352a25-7acb-4893-a11c-f06bd45f27ab',
|
|
287
|
+
},
|
|
288
|
+
{
|
|
289
|
+
type: ComponentDiffType.ComponentMoved,
|
|
290
|
+
id: '93e9fa20-d86e-4543-9ca7-927ffeab6d54',
|
|
291
|
+
slotIndex: 0,
|
|
292
|
+
parentId: undefined,
|
|
293
|
+
slot: undefined,
|
|
294
|
+
},
|
|
295
|
+
],
|
|
296
|
+
});
|
|
297
|
+
expect(result).toEqual({
|
|
298
|
+
_id: 'root',
|
|
299
|
+
_name: 'root',
|
|
300
|
+
type: 'root',
|
|
301
|
+
slots: {
|
|
302
|
+
pageContent: [
|
|
303
|
+
{
|
|
304
|
+
type: 'hero',
|
|
305
|
+
_id: '93e9fa20-d86e-4543-9ca7-927ffeab6d54',
|
|
306
|
+
},
|
|
307
|
+
],
|
|
308
|
+
},
|
|
309
|
+
});
|
|
310
|
+
});
|
|
311
|
+
it('should put components back into the correct position', () => {
|
|
312
|
+
const result = applyDiff({
|
|
313
|
+
composition: {
|
|
314
|
+
_id: 'root',
|
|
315
|
+
_name: 'root',
|
|
316
|
+
type: 'root',
|
|
317
|
+
slots: {
|
|
318
|
+
content: [
|
|
319
|
+
{
|
|
320
|
+
type: 'child',
|
|
321
|
+
_id: 'existing',
|
|
322
|
+
},
|
|
323
|
+
],
|
|
324
|
+
},
|
|
325
|
+
},
|
|
326
|
+
diff: [
|
|
327
|
+
{
|
|
328
|
+
type: ComponentDiffType.ComponentAdded,
|
|
329
|
+
id: 'child',
|
|
330
|
+
parentId: 'root',
|
|
331
|
+
slot: 'content',
|
|
332
|
+
slotIndex: 0,
|
|
333
|
+
component: {
|
|
334
|
+
type: 'child',
|
|
335
|
+
_id: 'child',
|
|
336
|
+
},
|
|
337
|
+
},
|
|
338
|
+
],
|
|
339
|
+
});
|
|
340
|
+
expect(result).toEqual({
|
|
341
|
+
_id: 'root',
|
|
342
|
+
_name: 'root',
|
|
343
|
+
type: 'root',
|
|
344
|
+
slots: {
|
|
345
|
+
content: [
|
|
346
|
+
{
|
|
347
|
+
_id: 'child',
|
|
348
|
+
type: 'child',
|
|
349
|
+
},
|
|
350
|
+
{
|
|
351
|
+
type: 'child',
|
|
352
|
+
_id: 'existing',
|
|
353
|
+
},
|
|
354
|
+
],
|
|
355
|
+
},
|
|
356
|
+
});
|
|
357
|
+
});
|
|
358
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|