@uniformdev/canvas-next-rsc 20.31.1-alpha.1 → 20.31.1-alpha.185

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 (156) hide show
  1. package/dist/UniformComposition-0pvEHduc.d.mts +64 -0
  2. package/dist/UniformComposition-0pvEHduc.d.ts +77 -0
  3. package/dist/UniformComposition-38e22896.d.ts +74 -0
  4. package/dist/UniformComposition-B-Z17dUt.d.mts +67 -0
  5. package/dist/UniformComposition-B-Z17dUt.d.ts +80 -0
  6. package/dist/UniformComposition-D4tBQ2U4.d.mts +64 -0
  7. package/dist/UniformComposition-D4tBQ2U4.d.ts +77 -0
  8. package/dist/UniformComposition-Dw55RFP6.d.mts +67 -0
  9. package/dist/UniformComposition-Dw55RFP6.d.ts +67 -0
  10. package/dist/UniformComposition-IWWzoI_H.d.mts +82 -0
  11. package/dist/UniformComposition-IWWzoI_H.d.ts +82 -0
  12. package/dist/UniformComposition-d178d865.d.ts +77 -0
  13. package/dist/actions/updateContext.d.ts +2 -0
  14. package/dist/actions/updateContext.js +17 -0
  15. package/dist/client/canvasClient.d.ts +5 -0
  16. package/dist/client/canvasClient.js +53 -0
  17. package/dist/client/manifestClient.d.ts +209 -0
  18. package/dist/client/manifestClient.js +33 -0
  19. package/dist/client/projectMapClient.d.ts +5 -0
  20. package/dist/client/projectMapClient.js +17 -0
  21. package/dist/client/routeClient.d.ts +5 -0
  22. package/dist/client/routeClient.js +68 -0
  23. package/dist/components/DefaultNotImplementedComponent.d.ts +4 -0
  24. package/dist/components/DefaultNotImplementedComponent.js +45 -0
  25. package/dist/components/GoogleTagManagerAnalytics.d.ts +3 -0
  26. package/dist/components/GoogleTagManagerAnalytics.js +44 -0
  27. package/dist/components/UniformComponent.d.ts +35 -0
  28. package/dist/components/UniformComponent.js +14 -0
  29. package/dist/components/UniformComposition.d.ts +47 -0
  30. package/dist/components/UniformComposition.js +35 -0
  31. package/dist/components/UniformContext.d.ts +13 -0
  32. package/dist/components/UniformContext.js +19 -0
  33. package/dist/components/UniformRichText.d.ts +42 -0
  34. package/dist/components/UniformRichText.js +15 -0
  35. package/dist/components/UniformRichTextNode.d.ts +14 -0
  36. package/dist/components/UniformRichTextNode.js +49 -0
  37. package/dist/components/UniformScript.d.ts +5 -0
  38. package/dist/components/UniformScript.js +49 -0
  39. package/dist/components/UniformSlot.d.ts +48 -0
  40. package/dist/components/UniformSlot.js +38 -0
  41. package/dist/components/UniformText.d.ts +10 -0
  42. package/dist/components/UniformText.js +5 -0
  43. package/dist/components/__tests__/evaluateComposition.spec.d.ts +1 -0
  44. package/dist/components/__tests__/evaluateComposition.spec.js +80 -0
  45. package/dist/components/convertComponentToProps.d.ts +18 -0
  46. package/dist/components/convertComponentToProps.js +22 -0
  47. package/dist/components/evaluateComposition.d.ts +32 -0
  48. package/dist/components/evaluateComposition.js +183 -0
  49. package/dist/components/getEnrichmentTags.d.ts +5 -0
  50. package/dist/components/getEnrichmentTags.js +13 -0
  51. package/dist/components/getUniformContext.d.ts +10 -0
  52. package/dist/components/getUniformContext.js +17 -0
  53. package/dist/components/nodes/HeadingRichTextNode.d.ts +2 -0
  54. package/dist/components/nodes/HeadingRichTextNode.js +6 -0
  55. package/dist/components/nodes/LinebreakRichTextNode.d.ts +2 -0
  56. package/dist/components/nodes/LinebreakRichTextNode.js +4 -0
  57. package/dist/components/nodes/LinkRichTextNode.d.ts +2 -0
  58. package/dist/components/nodes/LinkRichTextNode.js +6 -0
  59. package/dist/components/nodes/ListItemRichTextNode.d.ts +2 -0
  60. package/dist/components/nodes/ListItemRichTextNode.js +5 -0
  61. package/dist/components/nodes/ListRichTextNode.d.ts +2 -0
  62. package/dist/components/nodes/ListRichTextNode.js +6 -0
  63. package/dist/components/nodes/ParagraphRichTextNode.d.ts +2 -0
  64. package/dist/components/nodes/ParagraphRichTextNode.js +6 -0
  65. package/dist/components/nodes/TabRichTextNode.d.ts +2 -0
  66. package/dist/components/nodes/TabRichTextNode.js +4 -0
  67. package/dist/components/nodes/TextRichTextNode.d.ts +2 -0
  68. package/dist/components/nodes/TextRichTextNode.js +9 -0
  69. package/dist/components/renderComponent.d.ts +26 -0
  70. package/dist/components/renderComponent.js +52 -0
  71. package/dist/components/resolvePath.d.ts +5 -0
  72. package/dist/components/resolvePath.js +34 -0
  73. package/dist/components/retrieveRoute.d.ts +198 -0
  74. package/dist/components/retrieveRoute.js +146 -0
  75. package/dist/components/types.d.ts +15 -0
  76. package/dist/components/types.js +1 -0
  77. package/dist/config/helpers.d.ts +23 -0
  78. package/dist/config/helpers.js +34 -0
  79. package/dist/config/models.d.ts +51 -0
  80. package/dist/config/models.js +1 -0
  81. package/dist/config/uniform.server.config.d.ts +3 -0
  82. package/dist/config/uniform.server.config.js +4 -0
  83. package/dist/cookie/index.d.ts +12 -0
  84. package/dist/cookie/index.js +21 -0
  85. package/dist/handler/createPreviewGETRouteHandler.d.ts +1 -0
  86. package/dist/handler/createPreviewGETRouteHandler.js +43 -0
  87. package/dist/handler/createPreviewPOSTRouteHandler.d.ts +1 -0
  88. package/dist/handler/createPreviewPOSTRouteHandler.js +88 -0
  89. package/dist/handler/createUniformRouteHandler.d.ts +4 -0
  90. package/dist/handler/createUniformRouteHandler.js +10 -0
  91. package/dist/handler/helpers.d.ts +17 -0
  92. package/dist/handler/helpers.js +148 -0
  93. package/dist/handler/messages/handleCompositionChanged.d.ts +2 -0
  94. package/dist/handler/messages/handleCompositionChanged.js +9 -0
  95. package/dist/handler/messages/handleCompositionDeleted.d.ts +2 -0
  96. package/dist/handler/messages/handleCompositionDeleted.js +9 -0
  97. package/dist/handler/messages/handleCompositionPublished.d.ts +2 -0
  98. package/dist/handler/messages/handleCompositionPublished.js +9 -0
  99. package/dist/handler/messages/handleManifestPublished.d.ts +2 -0
  100. package/dist/handler/messages/handleManifestPublished.js +10 -0
  101. package/dist/handler/messages/handleProjectMapNodeDelete.d.ts +2 -0
  102. package/dist/handler/messages/handleProjectMapNodeDelete.js +21 -0
  103. package/dist/handler/messages/handleProjectMapNodeInsert.d.ts +2 -0
  104. package/dist/handler/messages/handleProjectMapNodeInsert.js +21 -0
  105. package/dist/handler/messages/handleProjectMapNodeUpdate.d.ts +2 -0
  106. package/dist/handler/messages/handleProjectMapNodeUpdate.js +22 -0
  107. package/dist/handler/messages/handleRedirectDelete.d.ts +2 -0
  108. package/dist/handler/messages/handleRedirectDelete.js +15 -0
  109. package/dist/handler/messages/handleRedirectInsert.d.ts +2 -0
  110. package/dist/handler/messages/handleRedirectInsert.js +15 -0
  111. package/dist/handler/messages/handleRedirectUpdate.d.ts +2 -0
  112. package/dist/handler/messages/handleRedirectUpdate.js +15 -0
  113. package/dist/hooks/useForgetMe.d.ts +4 -0
  114. package/dist/hooks/useForgetMe.js +10 -0
  115. package/dist/hooks/useToggleConsent.d.ts +7 -0
  116. package/dist/hooks/useToggleConsent.js +22 -0
  117. package/dist/hooks/useUniformContext.d.ts +1 -0
  118. package/dist/hooks/useUniformContext.js +3 -0
  119. package/dist/index.esm.js +17 -26
  120. package/dist/index.js +17 -26
  121. package/dist/index.mjs +17 -26
  122. package/dist/models/index.d.ts +30 -0
  123. package/dist/models/index.js +1 -0
  124. package/dist/register/componentStore.d.ts +1 -0
  125. package/dist/register/componentStore.js +2 -0
  126. package/dist/register/componentStoreResolver.d.ts +4 -0
  127. package/dist/register/componentStoreResolver.js +5 -0
  128. package/dist/register/createComponentStore.d.ts +12 -0
  129. package/dist/register/createComponentStore.js +13 -0
  130. package/dist/register/createComponentStoreResolver.d.ts +12 -0
  131. package/dist/register/createComponentStoreResolver.js +9 -0
  132. package/dist/register/getTypeWithVariant.d.ts +1 -0
  133. package/dist/register/getTypeWithVariant.js +1 -0
  134. package/dist/register/registerUniformComponent.d.ts +10 -0
  135. package/dist/register/registerUniformComponent.js +8 -0
  136. package/dist/resolve/resolveChildren.d.ts +17 -0
  137. package/dist/resolve/resolveChildren.js +20 -0
  138. package/dist/score/index.d.ts +3 -0
  139. package/dist/score/index.js +114 -0
  140. package/dist/utils/__tests__/apply.spec.d.ts +1 -0
  141. package/dist/utils/__tests__/apply.spec.js +358 -0
  142. package/dist/utils/__tests__/diff.spec.d.ts +1 -0
  143. package/dist/utils/__tests__/diff.spec.js +394 -0
  144. package/dist/utils/apply.d.ts +10 -0
  145. package/dist/utils/apply.js +124 -0
  146. package/dist/utils/comp.d.ts +25 -0
  147. package/dist/utils/comp.js +65 -0
  148. package/dist/utils/diff.d.ts +58 -0
  149. package/dist/utils/diff.js +144 -0
  150. package/dist/utils/draft.d.ts +20 -0
  151. package/dist/utils/draft.js +22 -0
  152. package/dist/utils/tag.d.ts +2 -0
  153. package/dist/utils/tag.js +7 -0
  154. package/dist/utils/url.d.ts +1 -0
  155. package/dist/utils/url.js +10 -0
  156. package/package.json +14 -14
@@ -0,0 +1,30 @@
1
+ import { ComponentInstance, ComponentParameter } from '@uniformdev/canvas';
2
+ export interface TestComponent {
3
+ slots?: {
4
+ test?: ComponentInstance[];
5
+ };
6
+ parameters: {
7
+ test?: ComponentParameter<string | undefined>;
8
+ };
9
+ }
10
+ export interface PersonalizeComponent {
11
+ slots?: {
12
+ pz?: ComponentInstance[];
13
+ };
14
+ parameters: {
15
+ trackingEventName?: ComponentParameter<string>;
16
+ count?: ComponentParameter<string | number>;
17
+ };
18
+ }
19
+ export type SeenUniformComponent = SeenPersonalizationComponent | SeenTestComponent;
20
+ export interface SeenPersonalizationComponent {
21
+ id: string;
22
+ type: 'personalization';
23
+ variants: string[];
24
+ control: boolean;
25
+ }
26
+ export interface SeenTestComponent {
27
+ id: string;
28
+ type: 'test';
29
+ variant: string | undefined;
30
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export declare const componentStore: import('./createComponentStore').ComponentStore;
@@ -0,0 +1,2 @@
1
+ import { createComponentStore } from './createComponentStore';
2
+ export const componentStore = createComponentStore();
@@ -0,0 +1,4 @@
1
+ /// <reference types="react" />
2
+ export declare const componentStoreResolver: (
3
+ component: import('@uniformdev/canvas').ComponentInstance
4
+ ) => import('react').ComponentType<any> | null;
@@ -0,0 +1,5 @@
1
+ import { componentStore } from './componentStore';
2
+ import { createComponentStoreResolver } from './createComponentStoreResolver';
3
+ export const componentStoreResolver = createComponentStoreResolver({
4
+ store: componentStore,
5
+ });
@@ -0,0 +1,12 @@
1
+ /// <reference types="react" />
2
+ import { ComponentProps } from '../components/UniformComponent';
3
+ export declare const NOT_IMPLEMENTED_COMPONENT = '__not_implemented__';
4
+ export declare const createComponentStore: () => ComponentStore;
5
+ export type ComponentStore = {
6
+ register: (options: {
7
+ type: string;
8
+ variantId?: string;
9
+ component: React.ComponentType<ComponentProps<any>>;
10
+ }) => void;
11
+ get: (type: string, variantId?: string) => React.ComponentType<ComponentProps<any>> | undefined;
12
+ };
@@ -0,0 +1,13 @@
1
+ import { getTypeWithVariant } from './getTypeWithVariant';
2
+ export const NOT_IMPLEMENTED_COMPONENT = '__not_implemented__';
3
+ export const createComponentStore = () => {
4
+ const components = new Map();
5
+ return {
6
+ register: ({ type, component, variantId }) => {
7
+ components.set(getTypeWithVariant(type, variantId), component);
8
+ },
9
+ get: (type, variantId) => {
10
+ return components.get(getTypeWithVariant(type, variantId));
11
+ },
12
+ };
13
+ };
@@ -0,0 +1,12 @@
1
+ /// <reference types="react" />
2
+ import { type ComponentInstance } from '@uniformdev/canvas';
3
+
4
+ import { ComponentProps } from '../components/UniformComponent';
5
+ import { ComponentStore } from './createComponentStore';
6
+ type RenderComponentResolver = (
7
+ component: ComponentInstance
8
+ ) => React.ComponentType<ComponentProps<any>> | null;
9
+ export declare const createComponentStoreResolver: (options: {
10
+ store: ComponentStore;
11
+ }) => RenderComponentResolver;
12
+ export {};
@@ -0,0 +1,9 @@
1
+ import { DefaultNotImplementedComponent } from '../components/DefaultNotImplementedComponent';
2
+ import { getTypeWithVariant } from './getTypeWithVariant';
3
+ export const createComponentStoreResolver = ({ store }) => {
4
+ return (component) => {
5
+ var _a;
6
+ const resolved = (_a = store.get(getTypeWithVariant(component.type, component.variant))) !== null && _a !== void 0 ? _a : store.get(getTypeWithVariant(component.type));
7
+ return resolved || DefaultNotImplementedComponent;
8
+ };
9
+ };
@@ -0,0 +1 @@
1
+ export declare const getTypeWithVariant: (type: string, variantId?: string) => string;
@@ -0,0 +1 @@
1
+ export const getTypeWithVariant = (type, variantId) => `${type}${variantId ? `__${variantId}` : ''}`;
@@ -0,0 +1,10 @@
1
+ import { ComponentProps } from '../components/UniformComponent';
2
+ export declare const registerUniformComponent: ({
3
+ type,
4
+ variantId,
5
+ component,
6
+ }: {
7
+ type: string;
8
+ variantId?: string | undefined;
9
+ component: React.ComponentType<ComponentProps<any>>;
10
+ }) => void;
@@ -0,0 +1,8 @@
1
+ import { componentStore } from './componentStore';
2
+ export const registerUniformComponent = ({ type, variantId, component, }) => {
3
+ componentStore.register({
4
+ type,
5
+ variantId,
6
+ component,
7
+ });
8
+ };
@@ -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,3 @@
1
+ import { VisitorData } from '@uniformdev/context';
2
+ export declare function parseScoreCookie(cookieValue: string | undefined): Partial<VisitorData> | undefined;
3
+ export declare function serializeCookie(data: VisitorData): string;
@@ -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 {};