@uniformdev/canvas-next-rsc 19.35.2 → 19.36.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/canvasClient.js +28 -0
- package/dist/client/routeClient.js +9 -1
- package/dist/components/UniformComponent.d.ts +12 -2
- package/dist/components/UniformComponent.js +2 -1
- package/dist/components/UniformComposition.js +6 -1
- package/dist/components/UniformRichText.d.ts +38 -0
- package/dist/components/UniformRichText.js +15 -0
- package/dist/components/UniformRichTextNode.d.ts +10 -0
- package/dist/components/UniformRichTextNode.js +49 -0
- package/dist/components/UniformSlot.d.ts +4 -1
- package/dist/components/UniformSlot.js +2 -1
- package/dist/components/convertComponentToProps.d.ts +5 -2
- package/dist/components/convertComponentToProps.js +2 -1
- 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 +3 -1
- package/dist/components/renderComponent.js +8 -3
- package/dist/components/types.d.ts +11 -0
- package/dist/components/types.js +1 -0
- package/dist/handler/createPreviewPOSTRouteHandler.js +1 -0
- package/dist/handler/helpers.d.ts +1 -0
- package/dist/handler/helpers.js +24 -2
- package/dist/handler/messages/handleProjectMapNodeDelete.js +2 -3
- package/dist/handler/messages/handleProjectMapNodeInsert.js +2 -3
- package/dist/handler/messages/handleProjectMapNodeUpdate.js +3 -4
- package/dist/index.d.ts +5 -1
- package/dist/index.js +4 -0
- package/dist/resolve/resolveChildren.d.ts +3 -2
- package/dist/resolve/resolveChildren.js +6 -4
- package/dist/utils/tag.d.ts +1 -0
- package/dist/utils/tag.js +4 -1
- package/package.json +10 -9
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CanvasClient } from '@uniformdev/canvas';
|
|
2
|
+
import { buildCompositionTag } from '../utils/tag';
|
|
2
3
|
export const getCanvasClient = (options) => {
|
|
3
4
|
return new CanvasClient({
|
|
4
5
|
projectId: process.env.UNIFORM_PROJECT_ID,
|
|
@@ -6,6 +7,33 @@ export const getCanvasClient = (options) => {
|
|
|
6
7
|
apiKey: process.env.UNIFORM_API_KEY,
|
|
7
8
|
edgeApiHost: process.env.UNIFORM_EDGE_API_HOST,
|
|
8
9
|
fetch: (req, init) => {
|
|
10
|
+
let requestedUrl;
|
|
11
|
+
if (typeof req === 'string') {
|
|
12
|
+
requestedUrl = new URL(req);
|
|
13
|
+
}
|
|
14
|
+
else if (req instanceof URL) {
|
|
15
|
+
requestedUrl = req;
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
requestedUrl = new URL(req.url);
|
|
19
|
+
}
|
|
20
|
+
const tags = [];
|
|
21
|
+
if (requestedUrl) {
|
|
22
|
+
// this is here so this code breaks if parameters change here
|
|
23
|
+
const compositionIdKey = 'compositionId';
|
|
24
|
+
const compositionIdsKey = 'compositionIDs';
|
|
25
|
+
const compositionId = requestedUrl.searchParams.get(compositionIdKey);
|
|
26
|
+
const compositionIds = requestedUrl.searchParams.get(compositionIdsKey);
|
|
27
|
+
if (compositionId) {
|
|
28
|
+
tags.push(buildCompositionTag(compositionId));
|
|
29
|
+
}
|
|
30
|
+
if (compositionIds) {
|
|
31
|
+
const ids = compositionIds.split(',');
|
|
32
|
+
for (let i = 0; i < ids.length; i++) {
|
|
33
|
+
tags.push(buildCompositionTag(ids[i]));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
9
37
|
let revalidate = options === null || options === void 0 ? void 0 : options.revalidate;
|
|
10
38
|
let noCache = false;
|
|
11
39
|
if (revalidate === -1) {
|
|
@@ -22,7 +22,15 @@ export const getRouteClient = (options) => {
|
|
|
22
22
|
const pathKey = 'path';
|
|
23
23
|
const path = requestedUrl.searchParams.get(pathKey);
|
|
24
24
|
if (path) {
|
|
25
|
-
|
|
25
|
+
// at this point, we do not know if this path is dynamic or not
|
|
26
|
+
// so apply each segment as a tag so we can clear any segment, ie:
|
|
27
|
+
// /authors/alex would add /authors and /authors/alex as tags
|
|
28
|
+
const pieces = path.split('/');
|
|
29
|
+
for (let i = 0; i < pieces.length; i++) {
|
|
30
|
+
const segmentPieces = pieces.slice(0, i + 1);
|
|
31
|
+
const segment = segmentPieces.join('/');
|
|
32
|
+
tags.push(buildPathTag(segment));
|
|
33
|
+
}
|
|
26
34
|
}
|
|
27
35
|
}
|
|
28
36
|
let revalidate;
|
|
@@ -1,12 +1,22 @@
|
|
|
1
|
-
import { type ComponentInstance } from '@uniformdev/canvas';
|
|
1
|
+
import { type ComponentInstance, type RootComponentInstance } from '@uniformdev/canvas';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
|
+
export type CompositionContext = {
|
|
4
|
+
composition: RootComponentInstance;
|
|
5
|
+
path: string;
|
|
6
|
+
state?: number;
|
|
7
|
+
searchParams: {
|
|
8
|
+
[key: string]: string | undefined;
|
|
9
|
+
} | undefined;
|
|
10
|
+
};
|
|
3
11
|
export type ComponentProps<TProps = unknown> = TProps & {
|
|
4
12
|
component: ComponentInstance;
|
|
13
|
+
context: CompositionContext;
|
|
5
14
|
};
|
|
6
15
|
export type UniformComponentProps<TRenderProps = unknown> = {
|
|
7
16
|
data: ComponentInstance;
|
|
17
|
+
context: CompositionContext;
|
|
8
18
|
children?: ReactNode | ((props: ComponentProps<TRenderProps>) => JSX.Element);
|
|
9
19
|
};
|
|
10
|
-
export declare function UniformComponent({ data, children }: UniformComponentProps): import("react").FunctionComponentElement<{
|
|
20
|
+
export declare function UniformComponent({ data, children, context }: UniformComponentProps): import("react").FunctionComponentElement<{
|
|
11
21
|
children?: ReactNode;
|
|
12
22
|
}>;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { createElement, Fragment } from 'react';
|
|
2
2
|
import { componentStoreResolver } from '../register/componentStoreResolver';
|
|
3
3
|
import { resolveChildren } from '../resolve/resolveChildren';
|
|
4
|
-
export function UniformComponent({ data, children }) {
|
|
4
|
+
export function UniformComponent({ data, children, context }) {
|
|
5
5
|
const resolvedChildren = resolveChildren({
|
|
6
6
|
children,
|
|
7
7
|
data,
|
|
8
|
+
context,
|
|
8
9
|
hasParentLayout: false,
|
|
9
10
|
resolveRenderer: componentStoreResolver,
|
|
10
11
|
});
|
|
@@ -51,5 +51,10 @@ const UniformCompositionInner = async ({ params, searchParams, children }) => {
|
|
|
51
51
|
params,
|
|
52
52
|
searchParams: searchParams !== null && searchParams !== void 0 ? searchParams : {},
|
|
53
53
|
});
|
|
54
|
-
|
|
54
|
+
const context = {
|
|
55
|
+
composition: evaluatedComposition,
|
|
56
|
+
path,
|
|
57
|
+
searchParams,
|
|
58
|
+
};
|
|
59
|
+
return (_jsxs(UniformProvider, { cookieValue: cookieValue, seenComponents: seenComponents, children: [_jsx(UniformScript, { enabled: draftMode }), _jsx(UniformComponent, { data: evaluatedComposition, context: context }), Boolean(children) && children] }));
|
|
55
60
|
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { ComponentInstance } from '@uniformdev/canvas';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { RenderRichTextComponentResolver } from './types';
|
|
4
|
+
export type UniformRichTextProps = {
|
|
5
|
+
/**
|
|
6
|
+
* The name of the HTML tag to render.
|
|
7
|
+
* @default "div"
|
|
8
|
+
*/
|
|
9
|
+
as?: React.ElementType;
|
|
10
|
+
/** The ID of the parameter. */
|
|
11
|
+
parameterId: string;
|
|
12
|
+
/**
|
|
13
|
+
* A function which can provide a custom react component
|
|
14
|
+
* for rendering a rich text node
|
|
15
|
+
*/
|
|
16
|
+
resolveRichTextRenderer?: RenderRichTextComponentResolver;
|
|
17
|
+
/** The component instance. */
|
|
18
|
+
component: ComponentInstance;
|
|
19
|
+
} & Omit<React.HTMLAttributes<HTMLDivElement>, 'children'>;
|
|
20
|
+
/**
|
|
21
|
+
* Adds rendering support for Uniform Rich Text parameters
|
|
22
|
+
*/
|
|
23
|
+
export declare const UniformRichText: React.ForwardRefExoticComponent<{
|
|
24
|
+
/**
|
|
25
|
+
* The name of the HTML tag to render.
|
|
26
|
+
* @default "div"
|
|
27
|
+
*/
|
|
28
|
+
as?: React.ElementType<any> | undefined;
|
|
29
|
+
/** The ID of the parameter. */
|
|
30
|
+
parameterId: string;
|
|
31
|
+
/**
|
|
32
|
+
* A function which can provide a custom react component
|
|
33
|
+
* for rendering a rich text node
|
|
34
|
+
*/
|
|
35
|
+
resolveRichTextRenderer?: RenderRichTextComponentResolver | undefined;
|
|
36
|
+
/** The component instance. */
|
|
37
|
+
component: ComponentInstance;
|
|
38
|
+
} & Omit<React.HTMLAttributes<HTMLDivElement>, "children"> & React.RefAttributes<unknown>>;
|
|
@@ -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,10 @@
|
|
|
1
|
+
import { RichTextNode } from '@uniformdev/richtext';
|
|
2
|
+
import { RenderRichTextComponentResolver } from './types';
|
|
3
|
+
export type UniformRichTextNodeProps = {
|
|
4
|
+
node: RichTextNode;
|
|
5
|
+
resolveRichTextRenderer?: RenderRichTextComponentResolver;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Render a single RichText node
|
|
9
|
+
*/
|
|
10
|
+
export declare function UniformRichTextNode({ node, ...props }: UniformRichTextNodeProps): 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
|
+
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ComponentInstance } from '@uniformdev/canvas';
|
|
2
2
|
import { Key, ReactNode } from 'react';
|
|
3
|
+
import { CompositionContext } from './UniformComponent';
|
|
3
4
|
export type CustomSlotChildRenderFunc = (options: {
|
|
4
5
|
child: ReactNode;
|
|
5
6
|
component: ComponentInstance;
|
|
@@ -10,6 +11,8 @@ export type UniformSlotProps<TSlotNames extends string> = {
|
|
|
10
11
|
name: TSlotNames;
|
|
11
12
|
/** The composition that is being rendered */
|
|
12
13
|
data: ComponentInstance;
|
|
14
|
+
/** The context of the composition that is being rendered */
|
|
15
|
+
context: CompositionContext;
|
|
13
16
|
/** Optional render props enables wrapping all child components in the slot with some markup */
|
|
14
17
|
children?: CustomSlotChildRenderFunc;
|
|
15
18
|
/**
|
|
@@ -19,6 +22,6 @@ export type UniformSlotProps<TSlotNames extends string> = {
|
|
|
19
22
|
*/
|
|
20
23
|
emptyPlaceholder?: ReactNode;
|
|
21
24
|
};
|
|
22
|
-
export declare function UniformSlot<TSlotNames extends string = string>({ name, children, emptyPlaceholder, data: parentData, }: UniformSlotProps<TSlotNames> & {
|
|
25
|
+
export declare function UniformSlot<TSlotNames extends string = string>({ name, children, emptyPlaceholder, data: parentData, context, }: UniformSlotProps<TSlotNames> & {
|
|
23
26
|
data: ComponentInstance;
|
|
24
27
|
}): JSX.Element | null;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createElement, Fragment } from 'react';
|
|
2
2
|
import { renderComponent } from './renderComponent';
|
|
3
|
-
export function UniformSlot({ name, children, emptyPlaceholder, data: parentData, }) {
|
|
3
|
+
export function UniformSlot({ name, children, emptyPlaceholder, data: parentData, context, }) {
|
|
4
4
|
var _a;
|
|
5
5
|
const slot = (_a = parentData.slots) === null || _a === void 0 ? void 0 : _a[name];
|
|
6
6
|
if (!slot || !Array.isArray(slot)) {
|
|
@@ -9,6 +9,7 @@ export function UniformSlot({ name, children, emptyPlaceholder, data: parentData
|
|
|
9
9
|
const finalChildren = slot.map((component, index) => {
|
|
10
10
|
const child = renderComponent({
|
|
11
11
|
component,
|
|
12
|
+
context,
|
|
12
13
|
resolveSystem: {
|
|
13
14
|
test: () => {
|
|
14
15
|
// https://www.youtube.com/watch?v=G3AfIvJBcGo
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ComponentInstance } from '@uniformdev/canvas';
|
|
2
|
-
import { ComponentProps } from './UniformComponent';
|
|
2
|
+
import { ComponentProps, CompositionContext } from './UniformComponent';
|
|
3
3
|
/**
|
|
4
4
|
* Extracts parameters from a component instance and returns them as a props object.
|
|
5
5
|
*
|
|
@@ -8,4 +8,7 @@ import { ComponentProps } from './UniformComponent';
|
|
|
8
8
|
* @returns The parameters as a props object.
|
|
9
9
|
*
|
|
10
10
|
*/
|
|
11
|
-
export declare function convertComponentToProps<T = unknown>(component
|
|
11
|
+
export declare function convertComponentToProps<T = unknown>({ component, context, }: {
|
|
12
|
+
component: ComponentInstance;
|
|
13
|
+
context: CompositionContext;
|
|
14
|
+
}): ComponentProps<T>;
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* @returns The parameters as a props object.
|
|
7
7
|
*
|
|
8
8
|
*/
|
|
9
|
-
export function convertComponentToProps(component) {
|
|
9
|
+
export function convertComponentToProps({ component, context, }) {
|
|
10
10
|
var _a;
|
|
11
11
|
const parameters = (_a = component.parameters) !== null && _a !== void 0 ? _a : {};
|
|
12
12
|
const renderComponentProps = {
|
|
@@ -16,6 +16,7 @@ export function convertComponentToProps(component) {
|
|
|
16
16
|
}, {}),
|
|
17
17
|
...component.data,
|
|
18
18
|
component,
|
|
19
|
+
context,
|
|
19
20
|
};
|
|
20
21
|
return renderComponentProps;
|
|
21
22
|
}
|
|
@@ -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
|
+
};
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { ComponentInstance } from '@uniformdev/canvas';
|
|
2
2
|
import { SystemRenderConfig, UniformSlotProps } from '@uniformdev/canvas-react';
|
|
3
3
|
import { Key } from 'react';
|
|
4
|
-
|
|
4
|
+
import { CompositionContext } from './UniformComponent';
|
|
5
|
+
export declare function renderComponent({ component, context, resolveSystem, key, indexInSlot, slotName, parentComponent, slotChildrenCount, emptyPlaceholder, }: {
|
|
5
6
|
component: ComponentInstance;
|
|
7
|
+
context: CompositionContext;
|
|
6
8
|
resolveSystem: SystemRenderConfig;
|
|
7
9
|
key?: Key;
|
|
8
10
|
indexInSlot?: number;
|
|
@@ -3,7 +3,7 @@ import { CANVAS_LOCALE_TAG_PARAM, CANVAS_PERSONALIZE_SLOT, CANVAS_PERSONALIZE_TY
|
|
|
3
3
|
import { componentStoreResolver } from '../register/componentStoreResolver';
|
|
4
4
|
import { convertComponentToProps } from './convertComponentToProps';
|
|
5
5
|
import { UniformComponent } from './UniformComponent';
|
|
6
|
-
export function renderComponent({ component, resolveSystem, key = 0, indexInSlot, slotName, parentComponent, slotChildrenCount, emptyPlaceholder, }) {
|
|
6
|
+
export function renderComponent({ component, context, resolveSystem, key = 0, indexInSlot, slotName, parentComponent, slotChildrenCount, emptyPlaceholder, }) {
|
|
7
7
|
var _a, _b, _c, _d;
|
|
8
8
|
const RenderComponent = componentStoreResolver(component);
|
|
9
9
|
// custom handling for tests and personalizes
|
|
@@ -12,6 +12,7 @@ export function renderComponent({ component, resolveSystem, key = 0, indexInSlot
|
|
|
12
12
|
var _a, _b;
|
|
13
13
|
return renderComponent({
|
|
14
14
|
component: variantComponent,
|
|
15
|
+
context,
|
|
15
16
|
resolveSystem,
|
|
16
17
|
key,
|
|
17
18
|
parentComponent: component,
|
|
@@ -26,6 +27,7 @@ export function renderComponent({ component, resolveSystem, key = 0, indexInSlot
|
|
|
26
27
|
var _a, _b;
|
|
27
28
|
return renderComponent({
|
|
28
29
|
component: variantComponent,
|
|
30
|
+
context,
|
|
29
31
|
resolveSystem,
|
|
30
32
|
key,
|
|
31
33
|
parentComponent: component,
|
|
@@ -36,10 +38,13 @@ export function renderComponent({ component, resolveSystem, key = 0, indexInSlot
|
|
|
36
38
|
});
|
|
37
39
|
}
|
|
38
40
|
else if (RenderComponent) {
|
|
39
|
-
const props = convertComponentToProps(
|
|
41
|
+
const props = convertComponentToProps({
|
|
42
|
+
component,
|
|
43
|
+
context,
|
|
44
|
+
});
|
|
40
45
|
const shouldRenderContextualEditingTags = Boolean(component._id);
|
|
41
46
|
const isPlaceholder = component._id === PLACEHOLDER_ID;
|
|
42
|
-
return (_jsx(UniformComponent, { data: component, 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 : '' }, key)), isPlaceholder && emptyPlaceholder !== undefined ? (emptyPlaceholder) : (_jsx(RenderComponent, { ...props })), !shouldRenderContextualEditingTags ? null : _jsx("script", { "data-role": "component-end" })] }) }, key));
|
|
47
|
+
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 : '' }, key)), isPlaceholder && emptyPlaceholder !== undefined ? (emptyPlaceholder) : (_jsx(RenderComponent, { ...props })), !shouldRenderContextualEditingTags ? null : _jsx("script", { "data-role": "component-end" })] }) }, key));
|
|
43
48
|
}
|
|
44
49
|
return null;
|
|
45
50
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { RichTextNode } from '@uniformdev/richtext';
|
|
2
|
+
import React, { PropsWithChildren } from 'react';
|
|
3
|
+
export type RichTextComponentProps<TNode extends RichTextNode = RichTextNode> = {
|
|
4
|
+
node: TNode;
|
|
5
|
+
};
|
|
6
|
+
export type RichTextRendererComponent<TNode extends RichTextNode = RichTextNode> = React.ComponentType<PropsWithChildren<RichTextComponentProps<TNode>>>;
|
|
7
|
+
/**
|
|
8
|
+
* Function that maps a Rich Text node instance to its React component to render it.
|
|
9
|
+
* The resolver would commonly inspect the `type` of the component to decide.
|
|
10
|
+
*/
|
|
11
|
+
export type RenderRichTextComponentResolver = (node: RichTextNode) => RichTextRendererComponent | null | undefined;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -5,6 +5,7 @@ export declare const isSvixMessage: (request: Request) => Promise<{
|
|
|
5
5
|
export declare const processCompositionChange: (compositionId: string) => Promise<{
|
|
6
6
|
tags: string[];
|
|
7
7
|
}>;
|
|
8
|
+
export declare const buildProjectMapNodePaths: (path: string) => string[];
|
|
8
9
|
export declare const getPathName: (url: string) => string;
|
|
9
10
|
export declare const processRedirectChange: (sourceUrl: string) => Promise<{
|
|
10
11
|
tags: string[];
|
package/dist/handler/helpers.js
CHANGED
|
@@ -3,7 +3,7 @@ import { Webhook } from 'svix';
|
|
|
3
3
|
import { getProjectMapClient } from '../client/projectMapClient';
|
|
4
4
|
import { getRouteClient } from '../client/routeClient';
|
|
5
5
|
import config from '../config/uniform.server.config';
|
|
6
|
-
import { buildPathTag } from '../utils/tag';
|
|
6
|
+
import { buildCompositionTag, buildPathTag } from '../utils/tag';
|
|
7
7
|
export const isSvixMessage = async (request) => {
|
|
8
8
|
const requiredHeaders = ['svix-id', 'svix-timestamp', 'svix-signature'];
|
|
9
9
|
const hasAllRequiredHeaders = requiredHeaders.every((header) => request.headers.has(header));
|
|
@@ -47,13 +47,35 @@ export const processCompositionChange = async (compositionId) => {
|
|
|
47
47
|
await processEdgeConfigChange({
|
|
48
48
|
source_url: node.path,
|
|
49
49
|
});
|
|
50
|
-
tags.push(
|
|
50
|
+
tags.push(...buildProjectMapNodePaths(node.path));
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
|
+
tags.push(buildCompositionTag(compositionId));
|
|
53
54
|
return {
|
|
54
55
|
tags,
|
|
55
56
|
};
|
|
56
57
|
};
|
|
58
|
+
export const buildProjectMapNodePaths = (path) => {
|
|
59
|
+
const tags = [];
|
|
60
|
+
const isDynamic = path.includes(':');
|
|
61
|
+
if (!isDynamic) {
|
|
62
|
+
tags.push(buildPathTag(path));
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
const pieces = path.split('/');
|
|
66
|
+
const invalidatePieces = [];
|
|
67
|
+
for (let j = 0; j < pieces.length; j++) {
|
|
68
|
+
const piece = pieces[j];
|
|
69
|
+
if (piece.startsWith(':')) {
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
invalidatePieces.push(piece);
|
|
73
|
+
}
|
|
74
|
+
const toInvalidate = invalidatePieces.join('/');
|
|
75
|
+
tags.push(buildPathTag(toInvalidate));
|
|
76
|
+
}
|
|
77
|
+
return tags;
|
|
78
|
+
};
|
|
57
79
|
export const getPathName = (url) => {
|
|
58
80
|
try {
|
|
59
81
|
const { pathname } = new URL(url);
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { ProjectMapNodeDeleteDefinition } from '@uniformdev/webhooks';
|
|
2
2
|
import config from '../../config/uniform.server.config';
|
|
3
|
-
import {
|
|
4
|
-
import { processEdgeConfigChange } from '../helpers';
|
|
3
|
+
import { buildProjectMapNodePaths, processEdgeConfigChange } from '../helpers';
|
|
5
4
|
export const handleProjectMapNodeDelete = async (body) => {
|
|
6
5
|
var _a;
|
|
7
6
|
const parsed = ProjectMapNodeDeleteDefinition.schema.safeParse(body);
|
|
@@ -9,7 +8,7 @@ export const handleProjectMapNodeDelete = async (body) => {
|
|
|
9
8
|
return undefined;
|
|
10
9
|
}
|
|
11
10
|
const tags = [];
|
|
12
|
-
tags.push(
|
|
11
|
+
tags.push(...buildProjectMapNodePaths(parsed.data.path));
|
|
13
12
|
if ((_a = config.experimental) === null || _a === void 0 ? void 0 : _a.edgeCompositions) {
|
|
14
13
|
await processEdgeConfigChange({
|
|
15
14
|
source_url: parsed.data.path,
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { ProjectMapNodeInsertDefinition } from '@uniformdev/webhooks';
|
|
2
2
|
import config from '../../config/uniform.server.config';
|
|
3
|
-
import {
|
|
4
|
-
import { processEdgeConfigChange } from '../helpers';
|
|
3
|
+
import { buildProjectMapNodePaths, processEdgeConfigChange } from '../helpers';
|
|
5
4
|
export const handleProjectMapNodeInsert = async (body) => {
|
|
6
5
|
var _a;
|
|
7
6
|
const parsed = ProjectMapNodeInsertDefinition.schema.safeParse(body);
|
|
@@ -9,7 +8,7 @@ export const handleProjectMapNodeInsert = async (body) => {
|
|
|
9
8
|
return undefined;
|
|
10
9
|
}
|
|
11
10
|
const tags = [];
|
|
12
|
-
tags.push(
|
|
11
|
+
tags.push(...buildProjectMapNodePaths(parsed.data.path));
|
|
13
12
|
if ((_a = config.experimental) === null || _a === void 0 ? void 0 : _a.edgeCompositions) {
|
|
14
13
|
await processEdgeConfigChange({
|
|
15
14
|
source_url: parsed.data.path,
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { ProjectMapNodeUpdateDefinition } from '@uniformdev/webhooks';
|
|
2
2
|
import config from '../../config/uniform.server.config';
|
|
3
|
-
import {
|
|
4
|
-
import { processEdgeConfigChange } from '../helpers';
|
|
3
|
+
import { buildProjectMapNodePaths, processEdgeConfigChange } from '../helpers';
|
|
5
4
|
export const handleProjectMapNodeUpdate = async (body) => {
|
|
6
5
|
var _a;
|
|
7
6
|
const parsed = ProjectMapNodeUpdateDefinition.schema.safeParse(body);
|
|
@@ -9,8 +8,8 @@ export const handleProjectMapNodeUpdate = async (body) => {
|
|
|
9
8
|
return undefined;
|
|
10
9
|
}
|
|
11
10
|
const tags = [];
|
|
12
|
-
tags.push(
|
|
13
|
-
tags.push(
|
|
11
|
+
tags.push(...buildProjectMapNodePaths(parsed.data.path));
|
|
12
|
+
tags.push(...buildProjectMapNodePaths(parsed.data.previous_path));
|
|
14
13
|
if ((_a = config.experimental) === null || _a === void 0 ? void 0 : _a.edgeCompositions) {
|
|
15
14
|
await processEdgeConfigChange({
|
|
16
15
|
source_url: parsed.data.path,
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { UniformCompositionProps as BaseUniformCompositionProps } from './components/UniformComposition';
|
|
2
2
|
export { GoogleTagManagerAnalytics } from './components/GoogleTagManagerAnalytics';
|
|
3
|
-
export { type ComponentProps } from './components/UniformComponent';
|
|
3
|
+
export { type ComponentProps, type CompositionContext } from './components/UniformComponent';
|
|
4
4
|
export { type UniformCompositionProps } from './components/UniformComposition';
|
|
5
5
|
export { UniformSlot, type UniformSlotProps } from './components/UniformSlot';
|
|
6
6
|
export { UniformText, type UniformTextProps } from './components/UniformText';
|
|
@@ -11,6 +11,10 @@ export { componentStore } from './register/componentStore';
|
|
|
11
11
|
export { registerUniformComponent } from './register/registerUniformComponent';
|
|
12
12
|
export { getCanvasClient } from './client/canvasClient';
|
|
13
13
|
export { getManifestClient } from './client/manifestClient';
|
|
14
|
+
export { getProjectMapClient } from './client/projectMapClient';
|
|
14
15
|
export { getRouteClient } from './client/routeClient';
|
|
15
16
|
export declare const UniformComposition: (props: Omit<BaseUniformCompositionProps, 'suspense' | 'children'>) => JSX.Element;
|
|
16
17
|
export declare const UniformCompositionCustom: (props: BaseUniformCompositionProps) => JSX.Element;
|
|
18
|
+
export { UniformRichText } from './components/UniformRichText';
|
|
19
|
+
export { isDraftModeEnabled, isIncontextEditingEnabled, isOnVercelPreviewEnvironment } from './utils/draft';
|
|
20
|
+
export { CANVAS_DRAFT_STATE, CANVAS_PUBLISHED_STATE, IN_CONTEXT_EDITOR_QUERY_STRING_PARAM, } from '@uniformdev/canvas';
|
package/dist/index.js
CHANGED
|
@@ -15,6 +15,10 @@ export { registerUniformComponent } from './register/registerUniformComponent';
|
|
|
15
15
|
// Clients
|
|
16
16
|
export { getCanvasClient } from './client/canvasClient';
|
|
17
17
|
export { getManifestClient } from './client/manifestClient';
|
|
18
|
+
export { getProjectMapClient } from './client/projectMapClient';
|
|
18
19
|
export { getRouteClient } from './client/routeClient';
|
|
19
20
|
export const UniformComposition = (props) => (_jsx(BaseUniformComposition, { ...props }));
|
|
20
21
|
export const UniformCompositionCustom = (props) => (_jsx(BaseUniformComposition, { ...props }));
|
|
22
|
+
export { UniformRichText } from './components/UniformRichText';
|
|
23
|
+
export { isDraftModeEnabled, isIncontextEditingEnabled, isOnVercelPreviewEnvironment } from './utils/draft';
|
|
24
|
+
export { CANVAS_DRAFT_STATE, CANVAS_PUBLISHED_STATE, IN_CONTEXT_EDITOR_QUERY_STRING_PARAM, } from '@uniformdev/canvas';
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { RenderComponentResolver } from '@uniformdev/canvas-react';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
|
-
import { UniformComponentProps } from '../components/UniformComponent';
|
|
4
|
-
export declare function resolveChildren<TRenderProps = unknown>({ children, data, hasParentLayout, resolveRenderer, }: {
|
|
3
|
+
import { CompositionContext, UniformComponentProps } from '../components/UniformComponent';
|
|
4
|
+
export declare function resolveChildren<TRenderProps = unknown>({ children, data, context, hasParentLayout, resolveRenderer, }: {
|
|
5
5
|
children: UniformComponentProps<TRenderProps>['children'];
|
|
6
6
|
data: Required<UniformComponentProps<TRenderProps>>['data'];
|
|
7
|
+
context: CompositionContext;
|
|
7
8
|
hasParentLayout: boolean;
|
|
8
9
|
resolveRenderer: RenderComponentResolver;
|
|
9
10
|
}): ReactNode;
|
|
@@ -2,17 +2,19 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import { createElement } from 'react';
|
|
3
3
|
import { convertComponentToProps } from '../components/convertComponentToProps';
|
|
4
4
|
import { UniformSlot } from '../components/UniformSlot';
|
|
5
|
-
export function resolveChildren({ children, data, hasParentLayout, resolveRenderer, }) {
|
|
5
|
+
export function resolveChildren({ children, data, context, hasParentLayout, resolveRenderer, }) {
|
|
6
6
|
// attempt to resolve the top level component if we're at the root and children were not provided
|
|
7
7
|
if (!children && !hasParentLayout) {
|
|
8
8
|
const topLevelComponent = resolveRenderer({ type: data.type });
|
|
9
9
|
if (topLevelComponent) {
|
|
10
|
-
children = createElement(topLevelComponent, convertComponentToProps(data));
|
|
10
|
+
children = createElement(topLevelComponent, convertComponentToProps({ component: data, context }));
|
|
11
11
|
}
|
|
12
12
|
else {
|
|
13
|
-
children = Object.keys(data.slots || {}).map((slotName) => (_jsx(UniformSlot, { name: slotName, data: data }, slotName)));
|
|
13
|
+
children = Object.keys(data.slots || {}).map((slotName) => (_jsx(UniformSlot, { name: slotName, data: data, context: context }, slotName)));
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
|
-
const renderChildren = typeof children === 'function'
|
|
16
|
+
const renderChildren = typeof children === 'function'
|
|
17
|
+
? children(convertComponentToProps({ component: data, context }))
|
|
18
|
+
: children;
|
|
17
19
|
return renderChildren;
|
|
18
20
|
}
|
package/dist/utils/tag.d.ts
CHANGED
package/dist/utils/tag.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
export const buildPathTag = (path) => {
|
|
2
2
|
const actualPath = path.startsWith('/') ? path : `/${path}`;
|
|
3
|
-
return `path:${actualPath}
|
|
3
|
+
return `path:${actualPath}`.toLowerCase();
|
|
4
|
+
};
|
|
5
|
+
export const buildCompositionTag = (compositionId) => {
|
|
6
|
+
return `composition:${compositionId}`.toLowerCase();
|
|
4
7
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniformdev/canvas-next-rsc",
|
|
3
|
-
"version": "19.
|
|
3
|
+
"version": "19.36.0",
|
|
4
4
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"dev": "pnpm build --watch",
|
|
@@ -56,13 +56,14 @@
|
|
|
56
56
|
"typescript": "^5.0.4"
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
|
-
"@uniformdev/canvas": "
|
|
60
|
-
"@uniformdev/canvas-react": "
|
|
61
|
-
"@uniformdev/context": "
|
|
62
|
-
"@uniformdev/project-map": "
|
|
63
|
-
"@uniformdev/redirect": "
|
|
64
|
-
"@uniformdev/
|
|
65
|
-
"@
|
|
59
|
+
"@uniformdev/canvas": "19.36.0",
|
|
60
|
+
"@uniformdev/canvas-react": "19.36.0",
|
|
61
|
+
"@uniformdev/context": "19.36.0",
|
|
62
|
+
"@uniformdev/project-map": "19.36.0",
|
|
63
|
+
"@uniformdev/redirect": "19.36.0",
|
|
64
|
+
"@uniformdev/richtext": "19.36.0",
|
|
65
|
+
"@uniformdev/webhooks": "19.36.0",
|
|
66
|
+
"@vercel/edge-config": "^0.2.0",
|
|
66
67
|
"dequal": "^2.0.3",
|
|
67
68
|
"js-cookie": "^3.0.5",
|
|
68
69
|
"svix": "^1.5.0"
|
|
@@ -75,5 +76,5 @@
|
|
|
75
76
|
"publishConfig": {
|
|
76
77
|
"access": "public"
|
|
77
78
|
},
|
|
78
|
-
"gitHead": "
|
|
79
|
+
"gitHead": "3ae246a7f0f39adeaf04ecba4c7e48c478c019ad"
|
|
79
80
|
}
|