@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,45 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { CANVAS_LOCALIZATION_TYPE } from '@uniformdev/canvas';
|
|
3
|
+
const wrapperStyles = {
|
|
4
|
+
display: 'flex',
|
|
5
|
+
flexDirection: 'column',
|
|
6
|
+
gap: '0.5rem',
|
|
7
|
+
borderLeft: '4px solid #e42535',
|
|
8
|
+
padding: '16px',
|
|
9
|
+
fontSize: '16px',
|
|
10
|
+
borderRadius: '0 8px 8px 0',
|
|
11
|
+
margin: '8px',
|
|
12
|
+
backgroundColor: 'rgba(255, 255, 255, 0.45)',
|
|
13
|
+
color: '#1d3557',
|
|
14
|
+
};
|
|
15
|
+
export function DefaultNotImplementedComponent(props) {
|
|
16
|
+
var _a, _b, _c;
|
|
17
|
+
const componentType = (_a = props.component) === null || _a === void 0 ? void 0 : _a.type;
|
|
18
|
+
if (!componentType) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
if (componentType === CANVAS_LOCALIZATION_TYPE) {
|
|
22
|
+
return (_jsx("div", { style: wrapperStyles, children: _jsxs("p", { children: ["Seems like localization is not enabled in your application. Please read our documentation on how to", ' ', _jsx("a", { href: "https://docs.uniform.app/guides/composition/localization#activate-front-end", target: "_blank", style: { fontWeight: 'bolder', textDecoration: 'underline' }, rel: "noreferrer", children: "enable localization in your front-end application." })] }) }));
|
|
23
|
+
}
|
|
24
|
+
const proposedFileName = `${componentType[0].toUpperCase()}${componentType.substring(1)}`;
|
|
25
|
+
const probableProps = Object.keys((_b = props.component.parameters) !== null && _b !== void 0 ? _b : {});
|
|
26
|
+
const probableSlots = Object.keys((_c = props.component.slots) !== null && _c !== void 0 ? _c : {});
|
|
27
|
+
return (_jsxs("div", { style: wrapperStyles, children: [_jsx("h2", { style: { fontSize: '1.2rem' }, children: "Unknown Component" }), _jsxs("p", { children: ["Received request from Uniform to render a component with the public ID: ", _jsx("code", { children: componentType }), "."] }), _jsxs("p", { children: [_jsx("code", { children: "<UniformComposition />" }), " does not have ", _jsx("code", { children: componentType }), " mapped to a React component yet."] }), _jsx("p", { children: "To teach your app how to render this component:" }), ' ', _jsxs("ul", { style: {
|
|
28
|
+
listStyleType: 'disc',
|
|
29
|
+
marginLeft: '1rem',
|
|
30
|
+
display: 'flex',
|
|
31
|
+
flexDirection: 'column',
|
|
32
|
+
gap: '0.5rem',
|
|
33
|
+
}, children: [_jsxs("li", { children: ["Create a React component and register it with Uniform, for example", _jsx("pre", { children: `function ${proposedFileName}(${probableProps.length > 0 ? `{ ${probableProps.join(', ')} }` : ''}) {
|
|
34
|
+
return (
|
|
35
|
+
<div>
|
|
36
|
+
${proposedFileName}!
|
|
37
|
+
${probableSlots.length > 0
|
|
38
|
+
? probableSlots.map((slot) => `<UniformSlot name="${slot}" />`).join('\n ')
|
|
39
|
+
: ''}
|
|
40
|
+
</div>
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
registerUniformComponent({ type: "${componentType}", component: ${proposedFileName} })` }), _jsxs("details", { children: [_jsx("summary", { style: { cursor: 'pointer' }, children: "Props that your React component will receive" }), _jsx("pre", { children: JSON.stringify(props, null, 2) })] })] }), _jsxs("li", { children: ["Import the component into the file where ", _jsx("code", { children: "<UniformComposition />" }), " is defined, for example ", _jsx("pre", { children: `import "../components/${proposedFileName}.tsx"` })] })] }), ' ', _jsxs("p", { children: ["Need more help?", ' ', _jsx("a", { href: "https://docs.uniform.app/docs/guides/composition/rendering", target: "_blank", rel: "noreferrer", style: { textDecoration: 'underline' }, children: "Check out the documentation." })] })] }));
|
|
45
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import Script from 'next/script';
|
|
4
|
+
import { useEffect } from 'react';
|
|
5
|
+
import { useUniformContext } from '../hooks/useUniformContext';
|
|
6
|
+
const isGtagConfigured = () => {
|
|
7
|
+
return typeof window !== 'undefined' && typeof window.gtag === 'function';
|
|
8
|
+
};
|
|
9
|
+
export const GoogleTagManagerAnalytics = (props) => {
|
|
10
|
+
const { seenComponents } = useUniformContext();
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
if (!(seenComponents === null || seenComponents === void 0 ? void 0 : seenComponents.length)) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
if (!isGtagConfigured()) {
|
|
16
|
+
// eslint-disable-next-line no-console
|
|
17
|
+
console.warn('Google Tag Manager is not configured. Please add the gtag script to your site.');
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
seenComponents.forEach((component) => {
|
|
21
|
+
var _a, _b, _c, _d, _e;
|
|
22
|
+
if (component.type === 'personalization') {
|
|
23
|
+
(_b = (_a = window).gtag) === null || _b === void 0 ? void 0 : _b.call(_a, 'event', component.id, {
|
|
24
|
+
event_category: 'Uniform Personalization',
|
|
25
|
+
event_label: component.variants.join(', '),
|
|
26
|
+
is_control_group: component.control ? 1 : 0,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
else if (component.type === 'test') {
|
|
30
|
+
(_d = (_c = window).gtag) === null || _d === void 0 ? void 0 : _d.call(_c, 'event', component.id, {
|
|
31
|
+
event_category: 'Uniform AB Testing',
|
|
32
|
+
event_label: (_e = component.variant) !== null && _e !== void 0 ? _e : 'No Variant',
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}, [seenComponents]);
|
|
37
|
+
return (_jsx(_Fragment, { children: Boolean(props === null || props === void 0 ? void 0 : props.measurementId) && (_jsxs(_Fragment, { children: [_jsx(Script, { src: `https://www.googletagmanager.com/gtag/js?id=${props.measurementId}`, strategy: "afterInteractive" }), _jsx(Script, { id: "google-analytics", strategy: "afterInteractive", children: `
|
|
38
|
+
window.dataLayer = window.dataLayer || [];
|
|
39
|
+
function gtag(){window.dataLayer.push(arguments);}
|
|
40
|
+
gtag('js', new Date());
|
|
41
|
+
|
|
42
|
+
gtag('config', '${props.measurementId}');
|
|
43
|
+
` })] })) }));
|
|
44
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type ComponentInstance,
|
|
3
|
+
type RootComponentInstance,
|
|
4
|
+
RouteGetResponseComposition,
|
|
5
|
+
} from '@uniformdev/canvas';
|
|
6
|
+
import { ReactNode } from 'react';
|
|
7
|
+
export type CompositionContext = Omit<RouteGetResponseComposition, 'compositionApiResponse'> & {
|
|
8
|
+
composition: RootComponentInstance;
|
|
9
|
+
path: string;
|
|
10
|
+
state?: number;
|
|
11
|
+
searchParams:
|
|
12
|
+
| {
|
|
13
|
+
[key: string]: string | undefined;
|
|
14
|
+
}
|
|
15
|
+
| undefined;
|
|
16
|
+
cookieValue: string | undefined;
|
|
17
|
+
isDraftMode: boolean;
|
|
18
|
+
isContextualEditing: boolean;
|
|
19
|
+
};
|
|
20
|
+
export type ComponentProps<TProps = unknown> = TProps & {
|
|
21
|
+
component: ComponentInstance;
|
|
22
|
+
context: CompositionContext;
|
|
23
|
+
};
|
|
24
|
+
export type UniformComponentProps<TRenderProps = unknown> = {
|
|
25
|
+
data: ComponentInstance;
|
|
26
|
+
context: CompositionContext;
|
|
27
|
+
children?: ReactNode | ((props: ComponentProps<TRenderProps>) => JSX.Element);
|
|
28
|
+
};
|
|
29
|
+
export declare function UniformComponent({
|
|
30
|
+
data,
|
|
31
|
+
children,
|
|
32
|
+
context,
|
|
33
|
+
}: UniformComponentProps): import('react').FunctionComponentElement<{
|
|
34
|
+
children?: ReactNode;
|
|
35
|
+
}>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { createElement, Fragment } from 'react';
|
|
2
|
+
import { componentStoreResolver } from '../register/componentStoreResolver';
|
|
3
|
+
import { resolveChildren } from '../resolve/resolveChildren';
|
|
4
|
+
export function UniformComponent({ data, children, context }) {
|
|
5
|
+
const resolvedChildren = resolveChildren({
|
|
6
|
+
children,
|
|
7
|
+
data,
|
|
8
|
+
context,
|
|
9
|
+
hasParentLayout: false,
|
|
10
|
+
resolveRenderer: componentStoreResolver,
|
|
11
|
+
});
|
|
12
|
+
const childrenToRender = [resolvedChildren];
|
|
13
|
+
return createElement(Fragment, {}, childrenToRender);
|
|
14
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { ContextState } from '@uniformdev/context';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
export type SuspenseOptions =
|
|
4
|
+
| {
|
|
5
|
+
mode: 'off';
|
|
6
|
+
}
|
|
7
|
+
| {
|
|
8
|
+
mode: 'fallback';
|
|
9
|
+
fallback: React.ReactNode;
|
|
10
|
+
};
|
|
11
|
+
export type UniformCompositionProps = {
|
|
12
|
+
/**
|
|
13
|
+
* The params object from Next.js router. Used to resolve a composition.
|
|
14
|
+
*/
|
|
15
|
+
params: {
|
|
16
|
+
slug: string | string[];
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* The searchParams object from Next.js router. Used for signal evaluation.
|
|
20
|
+
*/
|
|
21
|
+
searchParams?: {
|
|
22
|
+
[key: string]: string | undefined;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Behavior of root Suspense component.
|
|
26
|
+
*/
|
|
27
|
+
suspense?:
|
|
28
|
+
| {
|
|
29
|
+
mode: 'off';
|
|
30
|
+
}
|
|
31
|
+
| {
|
|
32
|
+
mode: 'fallback';
|
|
33
|
+
fallback: ReactNode;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Update state that should be added to the call to update before composition evaluation
|
|
37
|
+
*/
|
|
38
|
+
update?: Partial<ContextState>;
|
|
39
|
+
/**
|
|
40
|
+
* The children of the UniformComposition component.
|
|
41
|
+
*/
|
|
42
|
+
children?: ReactNode;
|
|
43
|
+
};
|
|
44
|
+
export declare const UniformComposition: ({
|
|
45
|
+
suspense,
|
|
46
|
+
...props
|
|
47
|
+
}: UniformCompositionProps) => import('react/jsx-runtime').JSX.Element;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Suspense } from 'react';
|
|
3
|
+
import { isDraftModeEnabled, isIncontextEditingEnabled } from '../utils/draft';
|
|
4
|
+
import { resolveComposition } from './retrieveRoute';
|
|
5
|
+
import { UniformComponent } from './UniformComponent';
|
|
6
|
+
import { UniformProvider } from './UniformContext';
|
|
7
|
+
import { UniformScript } from './UniformScript';
|
|
8
|
+
export const UniformComposition = ({ suspense = {
|
|
9
|
+
mode: 'off',
|
|
10
|
+
}, ...props }) => (_jsx(ConditionalWrapper, { options: suspense, children: _jsx(UniformCompositionInner, { ...props }) }));
|
|
11
|
+
const ConditionalWrapper = ({ children, options }) => {
|
|
12
|
+
if (options.mode === 'off') {
|
|
13
|
+
return _jsx(_Fragment, { children: children });
|
|
14
|
+
}
|
|
15
|
+
return _jsx(Suspense, { fallback: options.fallback, children: children });
|
|
16
|
+
};
|
|
17
|
+
const UniformCompositionInner = async ({ params, searchParams, update, children, }) => {
|
|
18
|
+
const { composition: evaluatedComposition, cookieValue, path, searchParams: evaluatedSearchParams, seenComponents, isCanvasEditing, ...rest } = await resolveComposition({
|
|
19
|
+
params,
|
|
20
|
+
searchParams,
|
|
21
|
+
update,
|
|
22
|
+
});
|
|
23
|
+
const context = {
|
|
24
|
+
composition: evaluatedComposition,
|
|
25
|
+
path,
|
|
26
|
+
searchParams,
|
|
27
|
+
cookieValue,
|
|
28
|
+
isDraftMode: isDraftModeEnabled({ searchParams }),
|
|
29
|
+
isContextualEditing: isIncontextEditingEnabled({
|
|
30
|
+
searchParams,
|
|
31
|
+
}),
|
|
32
|
+
...rest,
|
|
33
|
+
};
|
|
34
|
+
return (_jsxs(UniformProvider, { cookieValue: cookieValue, seenComponents: seenComponents, children: [_jsx(UniformScript, { enabled: isCanvasEditing }), _jsx(UniformComponent, { data: evaluatedComposition, context: context }), Boolean(children) && children] }));
|
|
35
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { PropsWithChildren } from 'react';
|
|
2
|
+
|
|
3
|
+
import { SeenUniformComponent } from '../models';
|
|
4
|
+
export type UniformContextProps = {
|
|
5
|
+
cookieValue: string | undefined;
|
|
6
|
+
seenComponents: SeenUniformComponent[] | undefined;
|
|
7
|
+
};
|
|
8
|
+
export declare const UniformContext: import('react').Context<UniformContextProps>;
|
|
9
|
+
export declare const UniformProvider: ({
|
|
10
|
+
children,
|
|
11
|
+
cookieValue,
|
|
12
|
+
seenComponents,
|
|
13
|
+
}: PropsWithChildren<UniformContextProps>) => import('react/jsx-runtime').JSX.Element;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { createContext, useEffect } from 'react';
|
|
4
|
+
import { removeUniformCookie, setUniformCookie } from '../cookie';
|
|
5
|
+
export const UniformContext = createContext({
|
|
6
|
+
cookieValue: undefined,
|
|
7
|
+
seenComponents: undefined,
|
|
8
|
+
});
|
|
9
|
+
export const UniformProvider = ({ children, cookieValue, seenComponents, }) => {
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
if (cookieValue) {
|
|
12
|
+
setUniformCookie(cookieValue);
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
removeUniformCookie();
|
|
16
|
+
}
|
|
17
|
+
}, [cookieValue]);
|
|
18
|
+
return (_jsx(UniformContext.Provider, { value: { cookieValue, seenComponents }, children: children }));
|
|
19
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { ComponentInstance } from '@uniformdev/canvas';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
|
|
4
|
+
import { RenderRichTextComponentResolver } from './types';
|
|
5
|
+
export type UniformRichTextProps = {
|
|
6
|
+
/**
|
|
7
|
+
* The name of the HTML tag to render.
|
|
8
|
+
* @default "div"
|
|
9
|
+
*/
|
|
10
|
+
as?: React.ElementType;
|
|
11
|
+
/** The ID of the parameter. */
|
|
12
|
+
parameterId: string;
|
|
13
|
+
/**
|
|
14
|
+
* A function which can provide a custom react component
|
|
15
|
+
* for rendering a rich text node
|
|
16
|
+
*/
|
|
17
|
+
resolveRichTextRenderer?: RenderRichTextComponentResolver;
|
|
18
|
+
/** The component instance. */
|
|
19
|
+
component: ComponentInstance;
|
|
20
|
+
} & Omit<React.HTMLAttributes<HTMLDivElement>, 'children'>;
|
|
21
|
+
/**
|
|
22
|
+
* Adds rendering support for Uniform Rich Text parameters
|
|
23
|
+
*/
|
|
24
|
+
export declare const UniformRichText: React.ForwardRefExoticComponent<
|
|
25
|
+
{
|
|
26
|
+
/**
|
|
27
|
+
* The name of the HTML tag to render.
|
|
28
|
+
* @default "div"
|
|
29
|
+
*/
|
|
30
|
+
as?: React.ElementType<any> | undefined;
|
|
31
|
+
/** The ID of the parameter. */
|
|
32
|
+
parameterId: string;
|
|
33
|
+
/**
|
|
34
|
+
* A function which can provide a custom react component
|
|
35
|
+
* for rendering a rich text node
|
|
36
|
+
*/
|
|
37
|
+
resolveRichTextRenderer?: RenderRichTextComponentResolver | undefined;
|
|
38
|
+
/** The component instance. */
|
|
39
|
+
component: ComponentInstance;
|
|
40
|
+
} & Omit<React.HTMLAttributes<HTMLDivElement>, 'children'> &
|
|
41
|
+
React.RefAttributes<unknown>
|
|
42
|
+
>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { isRichTextValue, isRichTextValueConsideredEmpty, } from '@uniformdev/richtext';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { UniformRichTextNode } from './UniformRichTextNode';
|
|
5
|
+
/**
|
|
6
|
+
* Adds rendering support for Uniform Rich Text parameters
|
|
7
|
+
*/
|
|
8
|
+
export const UniformRichText = React.forwardRef(function UniformRichText({ parameterId, component, resolveRichTextRenderer, as: Tag = 'div', ...props }, ref) {
|
|
9
|
+
var _a;
|
|
10
|
+
const parameter = (_a = component === null || component === void 0 ? void 0 : component.parameters) === null || _a === void 0 ? void 0 : _a[parameterId];
|
|
11
|
+
const value = parameter === null || parameter === void 0 ? void 0 : parameter.value;
|
|
12
|
+
if (!value || !isRichTextValue(value) || isRichTextValueConsideredEmpty(value))
|
|
13
|
+
return null;
|
|
14
|
+
return Tag === null ? (_jsx(UniformRichTextNode, { node: value.root, resolveRichTextRenderer: resolveRichTextRenderer })) : (_jsx(Tag, { ref: ref, ...props, children: _jsx(UniformRichTextNode, { node: value.root, resolveRichTextRenderer: resolveRichTextRenderer }) }));
|
|
15
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { RichTextNode } from '@uniformdev/richtext';
|
|
2
|
+
|
|
3
|
+
import { RenderRichTextComponentResolver } from './types';
|
|
4
|
+
export type UniformRichTextNodeProps = {
|
|
5
|
+
node: RichTextNode;
|
|
6
|
+
resolveRichTextRenderer?: RenderRichTextComponentResolver;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Render a single RichText node
|
|
10
|
+
*/
|
|
11
|
+
export declare function UniformRichTextNode({
|
|
12
|
+
node,
|
|
13
|
+
...props
|
|
14
|
+
}: UniformRichTextNodeProps): import('react/jsx-runtime').JSX.Element | null;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { createElement as _createElement } from "react";
|
|
3
|
+
import { isRichTextNode } from '@uniformdev/richtext';
|
|
4
|
+
import { HeadingRichTextNode } from './nodes/HeadingRichTextNode';
|
|
5
|
+
import { LinebreakRichTextNode } from './nodes/LinebreakRichTextNode';
|
|
6
|
+
import { LinkRichTextNode } from './nodes/LinkRichTextNode';
|
|
7
|
+
import { ListItemRichTextNode } from './nodes/ListItemRichTextNode';
|
|
8
|
+
import { ListRichTextNode } from './nodes/ListRichTextNode';
|
|
9
|
+
import { ParagraphRichTextNode } from './nodes/ParagraphRichTextNode';
|
|
10
|
+
import { TabRichTextNode } from './nodes/TabRichTextNode';
|
|
11
|
+
import { TextRichTextNode } from './nodes/TextRichTextNode';
|
|
12
|
+
/**
|
|
13
|
+
* Render a single RichText node
|
|
14
|
+
*/
|
|
15
|
+
export function UniformRichTextNode({ node, ...props }) {
|
|
16
|
+
var _a;
|
|
17
|
+
if (!isRichTextNode(node))
|
|
18
|
+
return null;
|
|
19
|
+
let NodeRenderer = (_a = props.resolveRichTextRenderer) === null || _a === void 0 ? void 0 : _a.call(props, node);
|
|
20
|
+
if (typeof NodeRenderer === 'undefined') {
|
|
21
|
+
NodeRenderer = resolveRichTextDefaultRenderer(node);
|
|
22
|
+
}
|
|
23
|
+
if (!NodeRenderer) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
const children = node.children
|
|
27
|
+
? node.children.map((childNode, i) => _createElement(UniformRichTextNode, { ...props, key: i, node: childNode }))
|
|
28
|
+
: null;
|
|
29
|
+
return _jsx(NodeRenderer, { node: node, children: children });
|
|
30
|
+
}
|
|
31
|
+
const rendererMap = new Map([
|
|
32
|
+
['heading', HeadingRichTextNode],
|
|
33
|
+
['linebreak', LinebreakRichTextNode],
|
|
34
|
+
['link', LinkRichTextNode],
|
|
35
|
+
['list', ListRichTextNode],
|
|
36
|
+
['listitem', ListItemRichTextNode],
|
|
37
|
+
['paragraph', ParagraphRichTextNode],
|
|
38
|
+
['quote', ({ children }) => _jsx("blockquote", { children: children })],
|
|
39
|
+
[
|
|
40
|
+
'code',
|
|
41
|
+
({ children }) => (_jsx("pre", { children: _jsx("code", { children: children }) })),
|
|
42
|
+
],
|
|
43
|
+
['root', ({ children }) => _jsx(_Fragment, { children: children })],
|
|
44
|
+
['text', TextRichTextNode],
|
|
45
|
+
['tab', TabRichTextNode],
|
|
46
|
+
]);
|
|
47
|
+
const resolveRichTextDefaultRenderer = (node) => {
|
|
48
|
+
return rendererMap.get(node.type);
|
|
49
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { createCanvasChannel } from '@uniformdev/canvas';
|
|
4
|
+
import { useRouter } from 'next/navigation';
|
|
5
|
+
import { useEffect, useMemo } from 'react';
|
|
6
|
+
export const UniformScript = ({ enabled }) => {
|
|
7
|
+
const router = useRouter();
|
|
8
|
+
const channel = useMemo(() => {
|
|
9
|
+
var _a;
|
|
10
|
+
if (typeof window === 'undefined') {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const instance = createCanvasChannel({
|
|
14
|
+
broadcastTo: [(_a = window.opener) !== null && _a !== void 0 ? _a : window.top],
|
|
15
|
+
listenTo: [window],
|
|
16
|
+
});
|
|
17
|
+
return instance;
|
|
18
|
+
}, []);
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
if (!channel) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const unsubscribeFromEditorUpdates = channel.on('editor-state-updated', () => {
|
|
24
|
+
router.refresh();
|
|
25
|
+
});
|
|
26
|
+
return () => {
|
|
27
|
+
unsubscribeFromEditorUpdates();
|
|
28
|
+
};
|
|
29
|
+
}, [channel, router]);
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
if (typeof window === 'undefined') {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const existing = document.getElementById('uniform-script');
|
|
35
|
+
if (enabled) {
|
|
36
|
+
if (!existing) {
|
|
37
|
+
const script = document.createElement('script');
|
|
38
|
+
script.id = 'uniform-script';
|
|
39
|
+
script.src = `https://uniform.app/files/canvas-in-context-embed/index.js`;
|
|
40
|
+
script.async = true;
|
|
41
|
+
document.head.appendChild(script);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
else if (existing) {
|
|
45
|
+
existing.remove();
|
|
46
|
+
}
|
|
47
|
+
}, [enabled]);
|
|
48
|
+
return _jsx(_Fragment, {});
|
|
49
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { ComponentInstance } from '@uniformdev/canvas';
|
|
2
|
+
import React, { Key, ReactNode } from 'react';
|
|
3
|
+
|
|
4
|
+
import { CompositionContext } from './UniformComponent';
|
|
5
|
+
export type CustomSlotChildRenderFunc = (options: {
|
|
6
|
+
child: ReactNode;
|
|
7
|
+
component: ComponentInstance;
|
|
8
|
+
key: Key;
|
|
9
|
+
}) => JSX.Element;
|
|
10
|
+
export type UniformSlotWrapperComponentProps = {
|
|
11
|
+
items: ReactNode[];
|
|
12
|
+
slotName: string;
|
|
13
|
+
};
|
|
14
|
+
export type UniformSlotProps<TSlotNames extends string> = {
|
|
15
|
+
/** Name of the slot to render */
|
|
16
|
+
name: TSlotNames;
|
|
17
|
+
/** The composition that is being rendered */
|
|
18
|
+
data: ComponentInstance;
|
|
19
|
+
/** The context of the composition that is being rendered */
|
|
20
|
+
context: CompositionContext;
|
|
21
|
+
/**
|
|
22
|
+
* Optional render props enables wrapping all child components in the slot with some markup
|
|
23
|
+
*
|
|
24
|
+
* @deprecated Use `wrapperComponent` instead and define wrapping component for slot children inside.
|
|
25
|
+
*/
|
|
26
|
+
children?: CustomSlotChildRenderFunc;
|
|
27
|
+
/**
|
|
28
|
+
* Optional wrapper component around list of slot items that allows to control
|
|
29
|
+
* exactly how to render slot items, otherwise React.Fragment is being used
|
|
30
|
+
*/
|
|
31
|
+
wrapperComponent?: React.ComponentType<UniformSlotWrapperComponentProps>;
|
|
32
|
+
/**
|
|
33
|
+
* Optional ReactNode to use as a placeholder in Canvas editor when the slot is empty.
|
|
34
|
+
* The node is used to render a placeholder with realistic dimensions and it's never shown to users.
|
|
35
|
+
* Pass `null` to disable the placeholder.
|
|
36
|
+
*/
|
|
37
|
+
emptyPlaceholder?: ReactNode;
|
|
38
|
+
};
|
|
39
|
+
export declare function UniformSlot<TSlotNames extends string = string>({
|
|
40
|
+
name,
|
|
41
|
+
children,
|
|
42
|
+
emptyPlaceholder,
|
|
43
|
+
data: parentData,
|
|
44
|
+
wrapperComponent,
|
|
45
|
+
context,
|
|
46
|
+
}: UniformSlotProps<TSlotNames> & {
|
|
47
|
+
data: ComponentInstance;
|
|
48
|
+
}): JSX.Element | null;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import React, { createElement, Fragment } from 'react';
|
|
3
|
+
import { renderComponent } from './renderComponent';
|
|
4
|
+
export function UniformSlot({ name, children, emptyPlaceholder, data: parentData, wrapperComponent, context, }) {
|
|
5
|
+
var _a;
|
|
6
|
+
const slot = (_a = parentData.slots) === null || _a === void 0 ? void 0 : _a[name];
|
|
7
|
+
if (!slot || !Array.isArray(slot)) {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
const finalChildren = slot.map((component, index) => {
|
|
11
|
+
const child = renderComponent({
|
|
12
|
+
component,
|
|
13
|
+
context,
|
|
14
|
+
resolveSystem: {
|
|
15
|
+
test: () => {
|
|
16
|
+
// https://www.youtube.com/watch?v=G3AfIvJBcGo
|
|
17
|
+
return null;
|
|
18
|
+
},
|
|
19
|
+
personalization: () => {
|
|
20
|
+
return null;
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
key: `inner-${index}`,
|
|
24
|
+
indexInSlot: index,
|
|
25
|
+
slotName: name,
|
|
26
|
+
parentComponent: parentData,
|
|
27
|
+
slotChildrenCount: slot.length,
|
|
28
|
+
emptyPlaceholder,
|
|
29
|
+
});
|
|
30
|
+
const elements = children ? children({ child, component, key: `wrapped-inner-${index}` }) : child;
|
|
31
|
+
return createElement(Fragment, { key: `wrapped-${index}` }, elements);
|
|
32
|
+
});
|
|
33
|
+
if (!wrapperComponent) {
|
|
34
|
+
return React.createElement(React.Fragment, undefined, finalChildren);
|
|
35
|
+
}
|
|
36
|
+
const Wrapper = wrapperComponent;
|
|
37
|
+
return _jsx(Wrapper, { items: finalChildren, slotName: name });
|
|
38
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type PureUniformTextProps } from '@uniformdev/canvas-react/core';
|
|
2
|
+
|
|
3
|
+
import { CompositionContext } from './UniformComponent';
|
|
4
|
+
export type UniformTextProps = {
|
|
5
|
+
context: CompositionContext;
|
|
6
|
+
} & Omit<PureUniformTextProps, 'skipCustomRendering' | 'isContextualEditing'>;
|
|
7
|
+
export declare const UniformText: ({
|
|
8
|
+
context,
|
|
9
|
+
...rest
|
|
10
|
+
}: UniformTextProps) => import('react/jsx-runtime').JSX.Element;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { PureUniformText } from '@uniformdev/canvas-react/core';
|
|
3
|
+
export const UniformText = ({ context, ...rest }) => {
|
|
4
|
+
return (_jsx(PureUniformText, { ...rest, isContextualEditing: context.isContextualEditing, skipCustomRendering: context.isContextualEditing }));
|
|
5
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { CANVAS_LOCALE_TAG_PARAM, CANVAS_LOCALIZATION_SLOT, CANVAS_LOCALIZATION_TYPE, } from '@uniformdev/canvas';
|
|
2
|
+
import { Context } from '@uniformdev/context';
|
|
3
|
+
import { evaluateComposition } from '../evaluateComposition';
|
|
4
|
+
jest.mock('../getUniformContext', () => ({
|
|
5
|
+
getUniformContext: () => {
|
|
6
|
+
return new Context({
|
|
7
|
+
manifest: {
|
|
8
|
+
project: {},
|
|
9
|
+
},
|
|
10
|
+
});
|
|
11
|
+
},
|
|
12
|
+
}));
|
|
13
|
+
describe('evaluateComposition', () => {
|
|
14
|
+
it('should localize a composition when dynmaic inputs include locale token', async () => {
|
|
15
|
+
var _a, _b;
|
|
16
|
+
const root = {
|
|
17
|
+
_id: 'root',
|
|
18
|
+
_name: 'root',
|
|
19
|
+
type: 'root',
|
|
20
|
+
slots: {
|
|
21
|
+
content: [
|
|
22
|
+
{
|
|
23
|
+
type: CANVAS_LOCALIZATION_TYPE,
|
|
24
|
+
slots: {
|
|
25
|
+
[CANVAS_LOCALIZATION_SLOT]: [
|
|
26
|
+
{
|
|
27
|
+
type: 'hero',
|
|
28
|
+
parameters: {
|
|
29
|
+
[CANVAS_LOCALE_TAG_PARAM]: {
|
|
30
|
+
type: CANVAS_LOCALE_TAG_PARAM,
|
|
31
|
+
value: 'fr',
|
|
32
|
+
},
|
|
33
|
+
title: {
|
|
34
|
+
type: 'text',
|
|
35
|
+
value: 'This is the french title!',
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
type: 'hero',
|
|
41
|
+
parameters: {
|
|
42
|
+
[CANVAS_LOCALE_TAG_PARAM]: {
|
|
43
|
+
type: CANVAS_LOCALE_TAG_PARAM,
|
|
44
|
+
value: 'en',
|
|
45
|
+
},
|
|
46
|
+
title: {
|
|
47
|
+
type: 'text',
|
|
48
|
+
value: 'This is the english title!',
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
],
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
await evaluateComposition({
|
|
59
|
+
root,
|
|
60
|
+
dynamicInputs: {
|
|
61
|
+
lang: 'en',
|
|
62
|
+
},
|
|
63
|
+
cookies: {},
|
|
64
|
+
headers: new Headers(),
|
|
65
|
+
params: {
|
|
66
|
+
slug: 'whatever',
|
|
67
|
+
},
|
|
68
|
+
searchParams: {},
|
|
69
|
+
config: {
|
|
70
|
+
experimental: {
|
|
71
|
+
localeDynamicInputs: ['lang'],
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
update: undefined,
|
|
75
|
+
});
|
|
76
|
+
const localizedHero = (_a = root.slots) === null || _a === void 0 ? void 0 : _a['content'][0];
|
|
77
|
+
expect(localizedHero).toBeDefined();
|
|
78
|
+
expect((_b = localizedHero === null || localizedHero === void 0 ? void 0 : localizedHero.parameters) === null || _b === void 0 ? void 0 : _b[CANVAS_LOCALE_TAG_PARAM].value).toBe('en');
|
|
79
|
+
});
|
|
80
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ComponentInstance } from '@uniformdev/canvas';
|
|
2
|
+
|
|
3
|
+
import { ComponentProps, CompositionContext } from './UniformComponent';
|
|
4
|
+
/**
|
|
5
|
+
* Extracts parameters from a component instance and returns them as a props object.
|
|
6
|
+
*
|
|
7
|
+
* @param component The component instance to extract parameters from.
|
|
8
|
+
*
|
|
9
|
+
* @returns The parameters as a props object.
|
|
10
|
+
*
|
|
11
|
+
*/
|
|
12
|
+
export declare function convertComponentToProps<T = unknown>({
|
|
13
|
+
component,
|
|
14
|
+
context,
|
|
15
|
+
}: {
|
|
16
|
+
component: ComponentInstance;
|
|
17
|
+
context: CompositionContext;
|
|
18
|
+
}): ComponentProps<T>;
|