@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.
- 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.mts +67 -0
- package/dist/UniformComposition-B-Z17dUt.d.ts +80 -0
- 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-IWWzoI_H.d.mts +82 -0
- package/dist/UniformComposition-IWWzoI_H.d.ts +82 -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/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/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/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.esm.js +17 -26
- package/dist/index.js +17 -26
- package/dist/index.mjs +17 -26
- 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 +14 -14
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extracts parameters from a component instance and returns them as a props object.
|
|
3
|
+
*
|
|
4
|
+
* @param component The component instance to extract parameters from.
|
|
5
|
+
*
|
|
6
|
+
* @returns The parameters as a props object.
|
|
7
|
+
*
|
|
8
|
+
*/
|
|
9
|
+
export function convertComponentToProps({ component, context, }) {
|
|
10
|
+
var _a;
|
|
11
|
+
const parameters = (_a = component.parameters) !== null && _a !== void 0 ? _a : {};
|
|
12
|
+
const renderComponentProps = {
|
|
13
|
+
...Object.keys(parameters).reduce((acc, cur) => {
|
|
14
|
+
acc[cur] = parameters[cur].value;
|
|
15
|
+
return acc;
|
|
16
|
+
}, {}),
|
|
17
|
+
...component.data,
|
|
18
|
+
component,
|
|
19
|
+
context,
|
|
20
|
+
};
|
|
21
|
+
return renderComponentProps;
|
|
22
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { RootComponentInstance, RouteGetResponseComposition } from '@uniformdev/canvas';
|
|
2
|
+
import { ContextState } from '@uniformdev/context';
|
|
3
|
+
|
|
4
|
+
import { UniformServerConfig } from '../config';
|
|
5
|
+
import { SeenUniformComponent } from '../models';
|
|
6
|
+
export declare const evaluateComposition: ({
|
|
7
|
+
root,
|
|
8
|
+
params,
|
|
9
|
+
searchParams,
|
|
10
|
+
dynamicInputs,
|
|
11
|
+
headers,
|
|
12
|
+
cookies,
|
|
13
|
+
update,
|
|
14
|
+
config,
|
|
15
|
+
}: {
|
|
16
|
+
root: RootComponentInstance;
|
|
17
|
+
params: {
|
|
18
|
+
slug: string | string[];
|
|
19
|
+
};
|
|
20
|
+
searchParams: {
|
|
21
|
+
[key: string]: string | undefined;
|
|
22
|
+
};
|
|
23
|
+
dynamicInputs: RouteGetResponseComposition['dynamicInputs'];
|
|
24
|
+
headers: Headers;
|
|
25
|
+
cookies: Record<string, string>;
|
|
26
|
+
update: Partial<ContextState> | undefined;
|
|
27
|
+
config?: UniformServerConfig | undefined;
|
|
28
|
+
}) => Promise<{
|
|
29
|
+
composition: RootComponentInstance;
|
|
30
|
+
cookieValue: string | undefined;
|
|
31
|
+
seenComponents: SeenUniformComponent[];
|
|
32
|
+
}>;
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import { CANVAS_PERSONALIZATION_PARAM, CANVAS_PERSONALIZE_TYPE, CANVAS_TEST_TYPE, localize, mapSlotToPersonalizedVariations, mapSlotToTestVariations, walkNodeTree, } from '@uniformdev/canvas';
|
|
2
|
+
import { UNIFORM_DEFAULT_COOKIE_NAME } from '@uniformdev/context';
|
|
3
|
+
import { getServerConfig } from '../config/helpers';
|
|
4
|
+
import { serializeCookie } from '../score';
|
|
5
|
+
import { isIncontextEditingEnabled } from '../utils/draft';
|
|
6
|
+
import { getBaseUrl } from '../utils/url';
|
|
7
|
+
import { getEnrichmentTags } from './getEnrichmentTags';
|
|
8
|
+
import { getUniformContext } from './getUniformContext';
|
|
9
|
+
import { resolvePath } from './resolvePath';
|
|
10
|
+
export const evaluateComposition = async ({ root, params, searchParams, dynamicInputs, headers, cookies, update, config = getServerConfig(), }) => {
|
|
11
|
+
// resolve the path from route params
|
|
12
|
+
const path = resolvePath({
|
|
13
|
+
params,
|
|
14
|
+
});
|
|
15
|
+
const context = await getUniformContext({
|
|
16
|
+
searchParams,
|
|
17
|
+
cookieValue: cookies[UNIFORM_DEFAULT_COOKIE_NAME] || undefined,
|
|
18
|
+
});
|
|
19
|
+
// generate the current URL for the request
|
|
20
|
+
const url = new URL(`${getBaseUrl()}${path}`);
|
|
21
|
+
for (const [key, value] of Object.entries(searchParams)) {
|
|
22
|
+
if (value) {
|
|
23
|
+
url.searchParams.set(key, value);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const missingQuirkValue = 'unknown';
|
|
27
|
+
const { cookies: updateCookies, quirks: updateQuirks, ...restOfUpdate } = update || {};
|
|
28
|
+
// update context to update scores
|
|
29
|
+
await context.update({
|
|
30
|
+
cookies: {
|
|
31
|
+
...cookies,
|
|
32
|
+
...(updateCookies || {}),
|
|
33
|
+
},
|
|
34
|
+
url,
|
|
35
|
+
quirks: {
|
|
36
|
+
'vc-country': headers.get('x-vercel-ip-country') || missingQuirkValue,
|
|
37
|
+
'vc-region': headers.get('x-vercel-ip-country-region') || missingQuirkValue,
|
|
38
|
+
'vc-city': headers.get('x-vercel-ip-city') || missingQuirkValue,
|
|
39
|
+
...(updateQuirks || {}),
|
|
40
|
+
},
|
|
41
|
+
...restOfUpdate,
|
|
42
|
+
});
|
|
43
|
+
const composition = root;
|
|
44
|
+
const resolvedLocaleKey = Object.keys(dynamicInputs || {}).find((key) => {
|
|
45
|
+
var _a, _b;
|
|
46
|
+
return (_b = (_a = config.experimental) === null || _a === void 0 ? void 0 : _a.localeDynamicInputs) === null || _b === void 0 ? void 0 : _b.includes(key);
|
|
47
|
+
});
|
|
48
|
+
const resolvedLocale = resolvedLocaleKey
|
|
49
|
+
? dynamicInputs[resolvedLocaleKey]
|
|
50
|
+
: undefined;
|
|
51
|
+
if (typeof resolvedLocale !== 'undefined') {
|
|
52
|
+
localize({
|
|
53
|
+
composition,
|
|
54
|
+
locale: resolvedLocale,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
const enrichmentTags = [];
|
|
58
|
+
const seenComponents = [];
|
|
59
|
+
walkNodeTree(composition, ({ type, node: component, actions }) => {
|
|
60
|
+
var _a, _b, _c, _d, _e, _f;
|
|
61
|
+
if (type !== 'component') {
|
|
62
|
+
// we ignore blocks for now
|
|
63
|
+
actions.stopProcessingDescendants();
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
let replacementComponents;
|
|
67
|
+
// evaluate personalization components
|
|
68
|
+
if (component.type === CANVAS_PERSONALIZE_TYPE) {
|
|
69
|
+
const pzComponent = component;
|
|
70
|
+
// extract the personalized variations from the pz component slot
|
|
71
|
+
const processedVariants = mapSlotToPersonalizedVariations((_a = pzComponent === null || pzComponent === void 0 ? void 0 : pzComponent.slots) === null || _a === void 0 ? void 0 : _a.pz);
|
|
72
|
+
// extract the number of variations to take from the pz component, defaulting to 1
|
|
73
|
+
const take = Number((_b = pzComponent.parameters.count) === null || _b === void 0 ? void 0 : _b.value) || 1;
|
|
74
|
+
// determine the personalization name
|
|
75
|
+
const personalizationName = ((_c = pzComponent.parameters.trackingEventName) === null || _c === void 0 ? void 0 : _c.value) || 'Unknown';
|
|
76
|
+
// personalize the component
|
|
77
|
+
const { variations: personalized } = context.personalize({
|
|
78
|
+
name: personalizationName,
|
|
79
|
+
variations: processedVariants,
|
|
80
|
+
take,
|
|
81
|
+
});
|
|
82
|
+
// if personalized variations were returned, remove the the criteria parameter
|
|
83
|
+
if (personalized) {
|
|
84
|
+
for (let i = 0; i < personalized.length; i++) {
|
|
85
|
+
(_d = personalized[i].parameters) === null || _d === void 0 ? true : delete _d[CANVAS_PERSONALIZATION_PARAM];
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
// record that we have selected these variations for this personalization
|
|
89
|
+
seenComponents.push({
|
|
90
|
+
id: personalizationName,
|
|
91
|
+
type: 'personalization',
|
|
92
|
+
variants: personalized.map((p) => p.id),
|
|
93
|
+
control: context.storage.data.controlGroup || false,
|
|
94
|
+
});
|
|
95
|
+
// set the replacement components to the personalized variations
|
|
96
|
+
replacementComponents = personalized;
|
|
97
|
+
}
|
|
98
|
+
// evaluate test component
|
|
99
|
+
if (component.type === CANVAS_TEST_TYPE) {
|
|
100
|
+
const testComponent = component;
|
|
101
|
+
// extract the test variations from the test component slot
|
|
102
|
+
const processedVariants = mapSlotToTestVariations((_e = testComponent === null || testComponent === void 0 ? void 0 : testComponent.slots) === null || _e === void 0 ? void 0 : _e.test);
|
|
103
|
+
const testName = ((_f = testComponent.parameters.test) === null || _f === void 0 ? void 0 : _f.value) || 'Unknown';
|
|
104
|
+
// evaluate the test
|
|
105
|
+
const testResult = context.test({
|
|
106
|
+
name: testName,
|
|
107
|
+
variations: processedVariants,
|
|
108
|
+
});
|
|
109
|
+
// record that we have selected this variation for this test
|
|
110
|
+
seenComponents.push({
|
|
111
|
+
id: testName,
|
|
112
|
+
type: 'test',
|
|
113
|
+
variant: testResult.result ? testResult.result.id : undefined,
|
|
114
|
+
});
|
|
115
|
+
// set the replacement components to the test variation
|
|
116
|
+
if (testResult.result) {
|
|
117
|
+
replacementComponents = [testResult.result];
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
replacementComponents = [];
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
// if we replacement components is defined, process replacements
|
|
124
|
+
if (typeof replacementComponents !== 'undefined') {
|
|
125
|
+
// if no variants were selected, just remove the current component. no matches.
|
|
126
|
+
if (replacementComponents.length === 0) {
|
|
127
|
+
actions.remove();
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
const [first, ...rest] = replacementComponents;
|
|
131
|
+
// replace the first component
|
|
132
|
+
actions.replace(first);
|
|
133
|
+
// if there are other components, insert them after the first
|
|
134
|
+
if (rest.length) {
|
|
135
|
+
actions.insertAfter(rest);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
// check to see if this component has any enrichment tags assigned
|
|
141
|
+
const tags = getEnrichmentTags(component);
|
|
142
|
+
// if so, add them to the enrichment tags
|
|
143
|
+
if (tags === null || tags === void 0 ? void 0 : tags.length) {
|
|
144
|
+
enrichmentTags.push(...tags);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
// when we post compositions to CANVAS_EDITOR_STATE, we have to remove all
|
|
149
|
+
// contextual editing objects that have been attached to parameters in order
|
|
150
|
+
// to pass API validation. walk the composition and add them back in, assume
|
|
151
|
+
// everything is editable.
|
|
152
|
+
if (isIncontextEditingEnabled({ searchParams })) {
|
|
153
|
+
walkNodeTree(composition, ({ node: component, actions, type }) => {
|
|
154
|
+
if (type !== 'component') {
|
|
155
|
+
actions.stopProcessingDescendants();
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
if (component.parameters) {
|
|
159
|
+
const params = Object.keys(component.parameters);
|
|
160
|
+
params.forEach((key) => {
|
|
161
|
+
const param = component.parameters[key];
|
|
162
|
+
if (param.type === 'text' && typeof param._contextualEditing === 'undefined') {
|
|
163
|
+
param._contextualEditing = {
|
|
164
|
+
isEditable: true,
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
// if we've seen any enrichment tags, update the context with them
|
|
172
|
+
if (enrichmentTags.length) {
|
|
173
|
+
await context.update({
|
|
174
|
+
enrichments: enrichmentTags,
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
// return the updated cookie value and any seen components
|
|
178
|
+
return {
|
|
179
|
+
cookieValue: context.storage.data.consent ? serializeCookie(context.storage.data) : undefined,
|
|
180
|
+
composition,
|
|
181
|
+
seenComponents,
|
|
182
|
+
};
|
|
183
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { CANVAS_ENRICHMENT_TAG_PARAM } from '@uniformdev/canvas';
|
|
2
|
+
export const getEnrichmentTags = (targets) => {
|
|
3
|
+
const targetsArray = Array.isArray(targets) ? targets : [targets];
|
|
4
|
+
const tags = [];
|
|
5
|
+
targetsArray.forEach((target) => {
|
|
6
|
+
var _a, _b;
|
|
7
|
+
const enrichmentTags = (_b = (_a = target.parameters) === null || _a === void 0 ? void 0 : _a[CANVAS_ENRICHMENT_TAG_PARAM]) === null || _b === void 0 ? void 0 : _b.value;
|
|
8
|
+
if (enrichmentTags) {
|
|
9
|
+
tags.push(...enrichmentTags);
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
return tags;
|
|
13
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Context } from '@uniformdev/context';
|
|
2
|
+
|
|
3
|
+
import { UniformCompositionProps } from './UniformComposition';
|
|
4
|
+
export declare const getUniformContext: ({
|
|
5
|
+
searchParams,
|
|
6
|
+
cookieValue,
|
|
7
|
+
}: {
|
|
8
|
+
searchParams?: UniformCompositionProps['searchParams'];
|
|
9
|
+
cookieValue: string | undefined;
|
|
10
|
+
}) => Promise<Context>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Context, CookieTransitionDataStore } from '@uniformdev/context';
|
|
2
|
+
import { getManifestFromApi } from '../client/manifestClient';
|
|
3
|
+
import { getServerConfig } from '../config/helpers';
|
|
4
|
+
export const getUniformContext = async ({ searchParams, cookieValue, }) => {
|
|
5
|
+
const manifest = await getManifestFromApi({
|
|
6
|
+
searchParams,
|
|
7
|
+
});
|
|
8
|
+
const config = getServerConfig();
|
|
9
|
+
const context = new Context({
|
|
10
|
+
manifest,
|
|
11
|
+
defaultConsent: config.defaultConsent,
|
|
12
|
+
transitionStore: new CookieTransitionDataStore({
|
|
13
|
+
serverCookieValue: cookieValue,
|
|
14
|
+
}),
|
|
15
|
+
});
|
|
16
|
+
return context;
|
|
17
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { linkParamValueToHref } from '@uniformdev/richtext';
|
|
3
|
+
export const LinkRichTextNode = ({ children, node }) => {
|
|
4
|
+
const { link } = node;
|
|
5
|
+
return _jsx("a", { href: linkParamValueToHref(link), children: children });
|
|
6
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
export const ListRichTextNode = ({ children, node }) => {
|
|
3
|
+
const { tag, start } = node;
|
|
4
|
+
const ListTag = (tag !== null && tag !== void 0 ? tag : 'ul');
|
|
5
|
+
return _jsx(ListTag, { start: Number.isFinite(start) && start > 0 ? start : undefined, children: children });
|
|
6
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { isPureDirection, isPureTextAlign } from '@uniformdev/richtext';
|
|
3
|
+
export const ParagraphRichTextNode = ({ children, node }) => {
|
|
4
|
+
const { format, direction } = node;
|
|
5
|
+
return (_jsx("p", { dir: isPureDirection(direction) ? direction : undefined, style: isPureTextAlign(format) ? { textAlign: format } : undefined, children: children }));
|
|
6
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { getRichTextTagsFromTextFormat } from '@uniformdev/richtext';
|
|
3
|
+
export const TextRichTextNode = ({ node }) => {
|
|
4
|
+
const { text, format } = node;
|
|
5
|
+
const tags = getRichTextTagsFromTextFormat(format);
|
|
6
|
+
return (_jsx(_Fragment, { children: tags.length > 0
|
|
7
|
+
? tags.reduceRight((children, Tag) => _jsx(Tag, { children: children }), text)
|
|
8
|
+
: text }));
|
|
9
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ComponentInstance } from '@uniformdev/canvas';
|
|
2
|
+
import { SystemRenderConfig, UniformSlotProps } from '@uniformdev/canvas-react';
|
|
3
|
+
import { Key } from 'react';
|
|
4
|
+
|
|
5
|
+
import { CompositionContext } from './UniformComponent';
|
|
6
|
+
export declare function renderComponent({
|
|
7
|
+
component,
|
|
8
|
+
context,
|
|
9
|
+
resolveSystem,
|
|
10
|
+
key,
|
|
11
|
+
indexInSlot,
|
|
12
|
+
slotName,
|
|
13
|
+
parentComponent,
|
|
14
|
+
slotChildrenCount,
|
|
15
|
+
emptyPlaceholder,
|
|
16
|
+
}: {
|
|
17
|
+
component: ComponentInstance;
|
|
18
|
+
context: CompositionContext;
|
|
19
|
+
resolveSystem: SystemRenderConfig;
|
|
20
|
+
key?: Key;
|
|
21
|
+
indexInSlot?: number;
|
|
22
|
+
slotName?: string;
|
|
23
|
+
parentComponent?: ComponentInstance;
|
|
24
|
+
slotChildrenCount?: number;
|
|
25
|
+
emptyPlaceholder?: UniformSlotProps<any>['emptyPlaceholder'];
|
|
26
|
+
}): JSX.Element | null;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { CANVAS_LOCALE_TAG_PARAM, CANVAS_PERSONALIZE_SLOT, CANVAS_PERSONALIZE_TYPE, CANVAS_TEST_SLOT, CANVAS_TEST_TYPE, IN_CONTEXT_EDITOR_COMPONENT_START_ROLE, isComponentPlaceholderId, } from '@uniformdev/canvas';
|
|
3
|
+
import { componentStoreResolver } from '../register/componentStoreResolver';
|
|
4
|
+
import { isIncontextEditingEnabled } from '../utils/draft';
|
|
5
|
+
import { convertComponentToProps } from './convertComponentToProps';
|
|
6
|
+
import { UniformComponent } from './UniformComponent';
|
|
7
|
+
export function renderComponent({ component, context, resolveSystem, key = 0, indexInSlot, slotName, parentComponent, slotChildrenCount, emptyPlaceholder, }) {
|
|
8
|
+
var _a, _b, _c, _d;
|
|
9
|
+
const RenderComponent = componentStoreResolver(component);
|
|
10
|
+
// custom handling for tests and personalizes
|
|
11
|
+
if (component.type === CANVAS_TEST_TYPE) {
|
|
12
|
+
return resolveSystem.test(component, key, (variantComponent, key) => {
|
|
13
|
+
var _a, _b;
|
|
14
|
+
return renderComponent({
|
|
15
|
+
component: variantComponent,
|
|
16
|
+
context,
|
|
17
|
+
resolveSystem,
|
|
18
|
+
key,
|
|
19
|
+
parentComponent: component,
|
|
20
|
+
slotName: CANVAS_TEST_SLOT,
|
|
21
|
+
slotChildrenCount: (_a = component === null || component === void 0 ? void 0 : component.slots) === null || _a === void 0 ? void 0 : _a[CANVAS_TEST_SLOT].length,
|
|
22
|
+
indexInSlot: (_b = component === null || component === void 0 ? void 0 : component.slots) === null || _b === void 0 ? void 0 : _b[CANVAS_TEST_SLOT].findIndex(({ _id }) => variantComponent._id === _id),
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
else if (component.type === CANVAS_PERSONALIZE_TYPE) {
|
|
27
|
+
return resolveSystem.personalization(component, key, (variantComponent, key) => {
|
|
28
|
+
var _a, _b;
|
|
29
|
+
return renderComponent({
|
|
30
|
+
component: variantComponent,
|
|
31
|
+
context,
|
|
32
|
+
resolveSystem,
|
|
33
|
+
key,
|
|
34
|
+
parentComponent: component,
|
|
35
|
+
slotName: CANVAS_PERSONALIZE_SLOT,
|
|
36
|
+
slotChildrenCount: (_a = component === null || component === void 0 ? void 0 : component.slots) === null || _a === void 0 ? void 0 : _a[CANVAS_PERSONALIZE_SLOT].length,
|
|
37
|
+
indexInSlot: (_b = component === null || component === void 0 ? void 0 : component.slots) === null || _b === void 0 ? void 0 : _b[CANVAS_PERSONALIZE_SLOT].findIndex(({ _id }) => variantComponent._id === _id),
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
else if (RenderComponent) {
|
|
42
|
+
const props = convertComponentToProps({
|
|
43
|
+
component,
|
|
44
|
+
context,
|
|
45
|
+
});
|
|
46
|
+
const shouldRenderContextualEditingTags = Boolean(component._id) && isIncontextEditingEnabled(context);
|
|
47
|
+
const isPlaceholder = isComponentPlaceholderId(component._id);
|
|
48
|
+
const isReadOnly = false;
|
|
49
|
+
return (_jsx(UniformComponent, { data: component, context: context, children: _jsxs(_Fragment, { children: [!shouldRenderContextualEditingTags ? null : (_jsx("script", { "data-role": IN_CONTEXT_EDITOR_COMPONENT_START_ROLE, "data-parent-id": parentComponent === null || parentComponent === void 0 ? void 0 : parentComponent._id, "data-parent-type": parentComponent === null || parentComponent === void 0 ? void 0 : parentComponent.type, "data-component-id": component._id, "data-slot-name": slotName !== null && slotName !== void 0 ? slotName : '', "data-component-index": indexInSlot !== null && indexInSlot !== void 0 ? indexInSlot : '', "data-total-components": slotChildrenCount !== null && slotChildrenCount !== void 0 ? slotChildrenCount : '', "data-component-name": component.type, "data-is-placeholder": isPlaceholder ? 'true' : undefined, "data-is-localized": ((_a = component.parameters) === null || _a === void 0 ? void 0 : _a[CANVAS_LOCALE_TAG_PARAM]) ? 'true' : undefined, "data-component-title": (_d = (_c = (_b = component.parameters) === null || _b === void 0 ? void 0 : _b.title) === null || _c === void 0 ? void 0 : _c.value) !== null && _d !== void 0 ? _d : '', "data-is-readonly": isReadOnly }, key)), isPlaceholder && emptyPlaceholder !== undefined ? (emptyPlaceholder) : (_jsx(RenderComponent, { ...props })), !shouldRenderContextualEditingTags ? null : _jsx("script", { "data-role": "component-end" })] }) }, key));
|
|
50
|
+
}
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const resolveSlugFromString = (originalSlug) => {
|
|
2
|
+
if (!originalSlug) {
|
|
3
|
+
return [''];
|
|
4
|
+
}
|
|
5
|
+
const slug = decodeURIComponent(originalSlug);
|
|
6
|
+
if (slug.includes('/')) {
|
|
7
|
+
return slug.split('/');
|
|
8
|
+
}
|
|
9
|
+
return [slug || ''];
|
|
10
|
+
};
|
|
11
|
+
const resolveSlugFromArray = (slug) => {
|
|
12
|
+
const slugPieces = [];
|
|
13
|
+
for (let i = 0; i < slug.length; i++) {
|
|
14
|
+
const decoded = decodeURIComponent(slug[i]);
|
|
15
|
+
if (decoded.includes('/')) {
|
|
16
|
+
slugPieces.push(...decoded.split('/'));
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
slugPieces.push(decoded);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return slugPieces;
|
|
23
|
+
};
|
|
24
|
+
export const resolvePath = (options) => {
|
|
25
|
+
const { params: { slug }, } = options;
|
|
26
|
+
const definedSlug = !Array.isArray(slug)
|
|
27
|
+
? resolveSlugFromString(slug)
|
|
28
|
+
: resolveSlugFromArray(slug);
|
|
29
|
+
let joined = `/${Array.isArray(definedSlug) ? definedSlug.join('/') : definedSlug}`;
|
|
30
|
+
if (joined === '/index') {
|
|
31
|
+
joined = '/';
|
|
32
|
+
}
|
|
33
|
+
return joined;
|
|
34
|
+
};
|