@remkoj/optimizely-cms-react 2.0.0-pre4 → 2.0.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/components/cms-styles.d.ts +53 -0
- package/dist/components/cms-styles.js +23 -0
- package/dist/components/cms-styles.js.map +1 -0
- package/dist/components/index.d.ts +2 -1
- package/dist/components/index.js +2 -1
- package/dist/components/index.js.map +1 -1
- package/dist/components/rich-text.d.ts +75 -0
- package/dist/components/rich-text.js +136 -0
- package/dist/components/rich-text.js.map +1 -0
- package/dist/factory.d.ts +10 -2
- package/dist/factory.js +26 -3
- package/dist/factory.js.map +1 -1
- package/dist/server/components/cms-content-area.d.ts +0 -1
- package/dist/server/components/cms-content.d.ts +0 -1
- package/dist/server/components/cms-content.js +16 -19
- package/dist/server/components/cms-content.js.map +1 -1
- package/dist/server/components/cms-editable.d.ts +22 -0
- package/dist/server/components/cms-editable.js +18 -0
- package/dist/server/components/cms-editable.js.map +1 -0
- package/dist/server/components/get-content-type.js +9 -14
- package/dist/server/components/get-content-type.js.map +1 -1
- package/dist/server/components/index.d.ts +1 -0
- package/dist/server/components/index.js +1 -0
- package/dist/server/components/index.js.map +1 -1
- package/dist/server/components/queries.js +12 -12
- package/dist/server/components/visual-builder/Composition.d.ts +6 -1
- package/dist/server/components/visual-builder/Composition.js +24 -66
- package/dist/server/components/visual-builder/Composition.js.map +1 -1
- package/dist/server/components/visual-builder/functions.d.ts +6 -1
- package/dist/server/components/visual-builder/functions.js +46 -0
- package/dist/server/components/visual-builder/functions.js.map +1 -1
- package/dist/server/components/visual-builder/types.d.ts +12 -2
- package/dist/server/type-utils.d.ts +0 -1
- package/dist/types.d.ts +44 -13
- package/dist/utilities.d.ts +22 -1
- package/dist/utilities.js +33 -3
- package/dist/utilities.js.map +1 -1
- package/package.json +9 -8
- package/dist/components/rich-text/index.d.ts +0 -32
- package/dist/components/rich-text/index.js +0 -43
- package/dist/components/rich-text/index.js.map +0 -1
- package/dist/server/components/utils.d.ts +0 -10
- package/dist/server/components/utils.js +0 -28
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export type StyleDefinition<TN extends string = string> = {
|
|
2
|
+
key: string;
|
|
3
|
+
displayName: string;
|
|
4
|
+
isDefault: boolean;
|
|
5
|
+
settings: Record<string, StyleSetting>;
|
|
6
|
+
} & (ElementStyleDefinition<TN> | BaseStyleDefinition<TN> | NodeStyleDefinition<TN>);
|
|
7
|
+
export type ElementStyleDefinition<TN extends string> = {
|
|
8
|
+
contentType: TN;
|
|
9
|
+
};
|
|
10
|
+
export type BaseStyleDefinition<TN extends string> = {
|
|
11
|
+
baseType: TN;
|
|
12
|
+
};
|
|
13
|
+
export type NodeStyleDefinition<TN extends string> = {
|
|
14
|
+
nodeType: TN;
|
|
15
|
+
};
|
|
16
|
+
export type StyleSetting = {
|
|
17
|
+
displayName: string;
|
|
18
|
+
sortOrder: number;
|
|
19
|
+
editor?: string;
|
|
20
|
+
choices: Record<string, {
|
|
21
|
+
displayName: string;
|
|
22
|
+
sortOrder: number;
|
|
23
|
+
}>;
|
|
24
|
+
};
|
|
25
|
+
export type LayoutProps<T extends StyleDefinition<string>> = {
|
|
26
|
+
type: T extends ElementStyleDefinition<infer TN> ? TN : (T extends BaseStyleDefinition<infer TN> ? TN : (T extends NodeStyleDefinition<infer TN> ? TN : null));
|
|
27
|
+
layoutType: string;
|
|
28
|
+
template: T['key'] | null;
|
|
29
|
+
settings: LayoutPropsSetting<T['settings']>[];
|
|
30
|
+
};
|
|
31
|
+
export type LayoutPropsSetting<T extends Record<string, StyleSetting>, K extends keyof T = keyof T> = LayoutPropsSettingChoices<T>[K];
|
|
32
|
+
export type LayoutPropsSettingChoices<T extends Record<string, StyleSetting>> = {
|
|
33
|
+
[K in keyof T]: {
|
|
34
|
+
key: K;
|
|
35
|
+
value: keyof T[K]['choices'];
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
export type LayoutPropsSettingKeys<CL extends LayoutProps<any>> = CL['settings'][number]['key'];
|
|
39
|
+
export type LayoutPropsSettingValues<CL extends LayoutProps<any>, K extends LayoutPropsSettingKeys<CL>> = Extract<CL['settings'][number], {
|
|
40
|
+
key: K;
|
|
41
|
+
}>['value'];
|
|
42
|
+
/**
|
|
43
|
+
* Read a configured layout setting from Style properties retrieved through Optimizely Graph
|
|
44
|
+
*
|
|
45
|
+
* @param from The Layout Settings as provided for Visual Builder rendered elements
|
|
46
|
+
* @param settingName The name of the setting to retrieve the value for
|
|
47
|
+
* @param defaultValue THe default value for when the setting is missing or not set
|
|
48
|
+
* @returns The setting value
|
|
49
|
+
*/
|
|
50
|
+
export declare function readSetting<T extends LayoutProps<any>, F extends LayoutPropsSettingKeys<T>, DV extends LayoutPropsSettingValues<T, F> | undefined>(from: T | undefined, settingName: F, defaultValue?: DV): DV extends undefined ? (LayoutPropsSettingValues<T, F> | undefined) : Exclude<LayoutPropsSettingValues<T, F>, undefined>;
|
|
51
|
+
export declare function extractSettings<T extends LayoutProps<any>>(from: T | undefined): Partial<{
|
|
52
|
+
[K in LayoutPropsSettingKeys<T>]: LayoutPropsSettingValues<T, K>;
|
|
53
|
+
}>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Read a configured layout setting from Style properties retrieved through Optimizely Graph
|
|
3
|
+
*
|
|
4
|
+
* @param from The Layout Settings as provided for Visual Builder rendered elements
|
|
5
|
+
* @param settingName The name of the setting to retrieve the value for
|
|
6
|
+
* @param defaultValue THe default value for when the setting is missing or not set
|
|
7
|
+
* @returns The setting value
|
|
8
|
+
*/
|
|
9
|
+
export function readSetting(from, settingName, defaultValue) {
|
|
10
|
+
const rv = from?.settings?.filter(x => x.key == settingName)[0]?.value;
|
|
11
|
+
return (rv || defaultValue);
|
|
12
|
+
}
|
|
13
|
+
export function extractSettings(from) {
|
|
14
|
+
if (!from)
|
|
15
|
+
return {};
|
|
16
|
+
const extracted = {};
|
|
17
|
+
from?.settings?.forEach((itm) => {
|
|
18
|
+
if (itm.value)
|
|
19
|
+
extracted[itm.key] = itm.value;
|
|
20
|
+
});
|
|
21
|
+
return extracted;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=cms-styles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cms-styles.js","sourceRoot":"","sources":["../../src/components/cms-styles.tsx"],"names":[],"mappings":"AA0CA;;;;;;;GAOG;AACH,MAAM,UAAU,WAAW,CAIzB,IAAmB,EAAE,WAAc,EAAE,YAAiB;IAGpD,MAAM,EAAE,GAAG,IAAI,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,IAAI,WAAW,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,CAAA;IACtE,OAAO,CAAC,EAAE,IAAI,YAAY,CAAO,CAAA;AACrC,CAAC;AAED,MAAM,UAAU,eAAe,CAA6B,IAAmB;IAG3E,IAAI,CAAC,IAAI;QACL,OAAO,EAAQ,CAAA;IACnB,MAAM,SAAS,GAAiB,EAAE,CAAA;IAClC,IAAI,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;QAC5B,IAAI,GAAG,CAAC,KAAK;YACT,SAAS,CAAC,GAAG,CAAC,GAAe,CAAC,GAAG,GAAG,CAAC,KAAqB,CAAA;IAClE,CAAC,CAAC,CAAA;IACF,OAAO,SAAe,CAAA;AAC1B,CAAC"}
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export * from './rich-text
|
|
1
|
+
export * from './rich-text.js';
|
|
2
|
+
export * from './cms-styles.js';
|
package/dist/components/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA;AAC9B,cAAc,iBAAiB,CAAA"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { ComponentFactory, ComponentType, ComponentTypeDictionary } from "../types.js";
|
|
2
|
+
import { type FunctionComponent, type PropsWithChildren } from "react";
|
|
3
|
+
export type RichTextProps = {
|
|
4
|
+
/**
|
|
5
|
+
* The component factory used for this rich text content
|
|
6
|
+
*/
|
|
7
|
+
factory?: ComponentFactory;
|
|
8
|
+
/**
|
|
9
|
+
* The rich text to render, provided as either a HTML string or JSON encoded
|
|
10
|
+
* structured data.
|
|
11
|
+
*/
|
|
12
|
+
text: NodeInput | null | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* The CSS Class to apply to the text container
|
|
15
|
+
*/
|
|
16
|
+
className?: string;
|
|
17
|
+
/**
|
|
18
|
+
* Set the component type of the wrapper to use, defaults to a 'div'
|
|
19
|
+
* element when not defined
|
|
20
|
+
*/
|
|
21
|
+
as?: ComponentType;
|
|
22
|
+
} & ({
|
|
23
|
+
/**
|
|
24
|
+
* The fieldname of this Rich Text, when it is used as part of a block
|
|
25
|
+
*/
|
|
26
|
+
cmsFieldName?: never;
|
|
27
|
+
/**
|
|
28
|
+
* The Element ID if this is the sole output of a Visual Builder element
|
|
29
|
+
*/
|
|
30
|
+
cmsId?: string | null;
|
|
31
|
+
} | {
|
|
32
|
+
/**
|
|
33
|
+
* The fieldname of this Rich Text, when it is used as part of a block
|
|
34
|
+
*/
|
|
35
|
+
cmsFieldName?: string | null;
|
|
36
|
+
/**
|
|
37
|
+
* The Element ID if this is the sole output of a Visual Builder element
|
|
38
|
+
*/
|
|
39
|
+
cmsId?: never;
|
|
40
|
+
});
|
|
41
|
+
export type Node = {};
|
|
42
|
+
export type TextNode = Node & {
|
|
43
|
+
text: string;
|
|
44
|
+
} & Record<string, string | number | boolean>;
|
|
45
|
+
export type RichTextNode = Node & {
|
|
46
|
+
type: "richText";
|
|
47
|
+
children: Array<Node>;
|
|
48
|
+
};
|
|
49
|
+
export type StringNode = Node & {
|
|
50
|
+
type: "string";
|
|
51
|
+
children: Array<Node>;
|
|
52
|
+
};
|
|
53
|
+
export type TypedNode = NodeWithChildren<Node & {
|
|
54
|
+
type: string;
|
|
55
|
+
} & Record<string, string | number | boolean>>;
|
|
56
|
+
export type NodeWithChildren<T extends Node> = T & {
|
|
57
|
+
children?: Array<Node>;
|
|
58
|
+
};
|
|
59
|
+
export type NodeInput = string | RichTextNode | StringNode;
|
|
60
|
+
export declare const Utils: {
|
|
61
|
+
isText(toTest: Node | null | undefined): toTest is TextNode;
|
|
62
|
+
isTypedNode(toTest: Node | null | undefined): toTest is TypedNode;
|
|
63
|
+
processNodeInput(input: NodeInput | null | undefined): RichTextNode | StringNode | undefined;
|
|
64
|
+
getRandomId(scope?: string): string;
|
|
65
|
+
};
|
|
66
|
+
export declare const RichText: FunctionComponent<RichTextProps>;
|
|
67
|
+
export declare function createHtmlComponent<E extends keyof JSX.IntrinsicElements>(element: E, ignoreChildren?: boolean, defaultProps?: JSX.IntrinsicElements[E] & Record<string, string>): ({ children, node, ...props }: PropsWithChildren<JSX.IntrinsicElements[E] & {
|
|
68
|
+
node: TypedNode;
|
|
69
|
+
}>) => import("react/jsx-runtime").JSX.Element;
|
|
70
|
+
/**
|
|
71
|
+
* A default component dictionary that allows to serialize the structured HTML
|
|
72
|
+
* into React, using the component library shared across the react SDK.
|
|
73
|
+
*/
|
|
74
|
+
export declare const DefaultComponents: ComponentTypeDictionary;
|
|
75
|
+
export default RichText;
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { DefaultComponentFactory } from "../factory.js";
|
|
3
|
+
import { decodeHTML } from 'entities';
|
|
4
|
+
//#endregion
|
|
5
|
+
//#region Utils & Supports
|
|
6
|
+
export const Utils = {
|
|
7
|
+
isText(toTest) {
|
|
8
|
+
return (typeof toTest == 'object' &&
|
|
9
|
+
toTest != null &&
|
|
10
|
+
(typeof toTest.text) == 'string' &&
|
|
11
|
+
toTest.text.length >= 0);
|
|
12
|
+
},
|
|
13
|
+
isTypedNode(toTest) {
|
|
14
|
+
return (typeof toTest == 'object' &&
|
|
15
|
+
toTest != null &&
|
|
16
|
+
(typeof toTest.type) == 'string' &&
|
|
17
|
+
toTest.type.length > 0);
|
|
18
|
+
},
|
|
19
|
+
processNodeInput(input) {
|
|
20
|
+
if (!input)
|
|
21
|
+
return undefined;
|
|
22
|
+
const textObject = typeof input == "string" ? JSON.parse(input) : input;
|
|
23
|
+
if (textObject?.type != "richText" && textObject?.type != "string")
|
|
24
|
+
throw new Error('Structured rich text requires a "richText" root node');
|
|
25
|
+
return textObject;
|
|
26
|
+
},
|
|
27
|
+
getRandomId(scope = "richText") {
|
|
28
|
+
return `${scope}::${Math.round(Math.random() * 100000)}`;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
//#endregion
|
|
32
|
+
export const RichText = ({ factory, text, className = 'rich-text', as: Wrapper = "div", ...props }) => {
|
|
33
|
+
const debug = process.env.NODE_ENV != 'production';
|
|
34
|
+
const id = Utils.getRandomId("rich-text");
|
|
35
|
+
const richTextFactory = factory ?? new DefaultComponentFactory(DefaultComponents);
|
|
36
|
+
try {
|
|
37
|
+
const data = Utils.processNodeInput(text);
|
|
38
|
+
return _jsx(Wrapper, { className: className, ...props, children: (data?.children || []).map((child, idx) => {
|
|
39
|
+
const elementId = id + '::' + idx;
|
|
40
|
+
return _jsx(RichTextElement, { factory: richTextFactory, node: child, idPrefix: elementId + '::' }, elementId);
|
|
41
|
+
}) });
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
if (debug)
|
|
45
|
+
console.warn('🟠 [Rich Text] Invalid rich text received: ', text);
|
|
46
|
+
return Object.getOwnPropertyNames(props).length > 0 ? _jsx("div", { className: className, ...props }) : null;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
//#region Supportive React components
|
|
50
|
+
const RichTextElement = ({ factory, node, idPrefix }) => {
|
|
51
|
+
const debug = process.env.NODE_ENV != 'production';
|
|
52
|
+
if (Utils.isText(node)) {
|
|
53
|
+
if (node.text.length == 0)
|
|
54
|
+
return null;
|
|
55
|
+
const TextComponent = factory?.resolve(`RichText/text`) ?? DefaultTextNode;
|
|
56
|
+
return _jsx(TextComponent, { node: node });
|
|
57
|
+
}
|
|
58
|
+
if (!Utils.isTypedNode(node)) {
|
|
59
|
+
if (debug)
|
|
60
|
+
console.warn('🟠 [Rich Text] Invalid rich text element data received:', node);
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
const childData = node.children?.map((child, idx) => {
|
|
64
|
+
const elementId = idPrefix + idx;
|
|
65
|
+
return _jsx(RichTextElement, { factory: factory, node: child, idPrefix: elementId + '::' }, elementId);
|
|
66
|
+
});
|
|
67
|
+
if (!factory?.has(`RichText/${node.type}`)) {
|
|
68
|
+
console.warn('🟠 [Rich Text] No renderer for node type, falling back to "div":', `RichText/${node.type}`);
|
|
69
|
+
const DivComponent = createHtmlComponent("div", false, { "data-type": node.type });
|
|
70
|
+
return _jsx(DivComponent, { node: node, children: childData });
|
|
71
|
+
}
|
|
72
|
+
const Component = factory?.resolve(`RichText/${node.type}`) ?? 'div';
|
|
73
|
+
return _jsx(Component, { node: node, children: childData });
|
|
74
|
+
};
|
|
75
|
+
//#endregion
|
|
76
|
+
//#region HTML Components
|
|
77
|
+
export function createHtmlComponent(element, ignoreChildren = false, defaultProps) {
|
|
78
|
+
const HtmlElement = element;
|
|
79
|
+
const reservedProps = ['url', 'class', 'children', 'type'];
|
|
80
|
+
const component = ({ children, node, ...props }) => {
|
|
81
|
+
const nodeProps = {};
|
|
82
|
+
const renderProps = Object.getOwnPropertyNames(node);
|
|
83
|
+
renderProps.filter(x => !reservedProps.includes(x)).forEach(x => nodeProps[x] = node[x]);
|
|
84
|
+
if (renderProps.includes('class'))
|
|
85
|
+
nodeProps['className'] = node['class'];
|
|
86
|
+
if (renderProps.includes('url')) {
|
|
87
|
+
switch (node.type) {
|
|
88
|
+
case 'link':
|
|
89
|
+
nodeProps['href'] = node['url'];
|
|
90
|
+
break;
|
|
91
|
+
case 'image':
|
|
92
|
+
nodeProps['src'] = node['url'];
|
|
93
|
+
break;
|
|
94
|
+
default:
|
|
95
|
+
nodeProps['data-url'] = node['url'];
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return ignoreChildren ? _jsx(HtmlElement, { ...defaultProps, ...nodeProps, ...props }) : _jsx(HtmlElement, { ...defaultProps, ...nodeProps, ...props, children: children });
|
|
100
|
+
};
|
|
101
|
+
return component;
|
|
102
|
+
}
|
|
103
|
+
const DefaultTextNode = ({ node }) => {
|
|
104
|
+
if (node.bold)
|
|
105
|
+
return _jsx("strong", { children: decodeHTML(node.text) });
|
|
106
|
+
const unsupportedProps = Object.getOwnPropertyNames(node).filter(x => x != 'text');
|
|
107
|
+
if (unsupportedProps.length > 0 && process.env.NODE_ENV != 'production')
|
|
108
|
+
console.warn('🟠 [Rich Text] Text node with unsupported additional properties:', unsupportedProps.join(', '));
|
|
109
|
+
return decodeHTML(node.text);
|
|
110
|
+
};
|
|
111
|
+
/**
|
|
112
|
+
* A default component dictionary that allows to serialize the structured HTML
|
|
113
|
+
* into React, using the component library shared across the react SDK.
|
|
114
|
+
*/
|
|
115
|
+
export const DefaultComponents = [
|
|
116
|
+
{ type: 'RichText/richText', component: createHtmlComponent("div", false, { className: "cms:rich-text" }) },
|
|
117
|
+
{ type: 'RichText/paragraph', component: createHtmlComponent("p") },
|
|
118
|
+
{ type: 'RichText/span', component: createHtmlComponent("span") },
|
|
119
|
+
{ type: 'RichText/div', component: createHtmlComponent("div") },
|
|
120
|
+
{ type: 'RichText/heading-one', component: createHtmlComponent("h1") },
|
|
121
|
+
{ type: 'RichText/heading-two', component: createHtmlComponent("h2") },
|
|
122
|
+
{ type: 'RichText/heading-three', component: createHtmlComponent("h3") },
|
|
123
|
+
{ type: 'RichText/heading-four', component: createHtmlComponent("h4") },
|
|
124
|
+
{ type: 'RichText/heading-five', component: createHtmlComponent("h5") },
|
|
125
|
+
{ type: 'RichText/heading-six', component: createHtmlComponent("h6") },
|
|
126
|
+
{ type: 'RichText/link', component: createHtmlComponent("a") },
|
|
127
|
+
{ type: 'RichText/image', component: createHtmlComponent("img", true) },
|
|
128
|
+
{ type: 'RichText/text', component: DefaultTextNode },
|
|
129
|
+
{ type: 'RichText/br', component: createHtmlComponent("br", true) },
|
|
130
|
+
{ type: 'RichText/bulleted-list', component: createHtmlComponent("ul") },
|
|
131
|
+
{ type: 'RichText/numbered-list', component: createHtmlComponent("ol") },
|
|
132
|
+
{ type: 'RichText/list-item', component: createHtmlComponent("li") }
|
|
133
|
+
];
|
|
134
|
+
//#endregion
|
|
135
|
+
export default RichText;
|
|
136
|
+
//# sourceMappingURL=rich-text.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rich-text.js","sourceRoot":"","sources":["../../src/components/rich-text.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAA;AAEvD,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AA8ErC,YAAY;AAEZ,0BAA0B;AAC1B,MAAM,CAAC,MAAM,KAAK,GAAG;IACjB,MAAM,CAAC,MAA+B;QAElC,OAAO,CACH,OAAO,MAAM,IAAI,QAAQ;YACzB,MAAM,IAAI,IAAI;YACd,CAAC,OAAQ,MAAmB,CAAC,IAAI,CAAC,IAAI,QAAQ;YAC7C,MAAmB,CAAC,IAAI,CAAC,MAAM,IAAI,CAAC,CACxC,CAAA;IACL,CAAC;IAED,WAAW,CAAC,MAA+B;QAEvC,OAAO,CACH,OAAO,MAAM,IAAI,QAAQ;YACzB,MAAM,IAAI,IAAI;YACd,CAAC,OAAQ,MAAoB,CAAC,IAAI,CAAC,IAAI,QAAQ;YAC9C,MAAoB,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CACxC,CAAA;IACL,CAAC;IAED,gB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AE,mBAAmB,CAAC,GAAG,CAAC,EAAC;IAC7D,EAAE,IAAI,EAAE,gBAAgB,EAAE,SAAS,EAAE,mBAAmB,CAAC,KAAK,EAAE,IAAI,CAAC,EAAC;IACtE,EAAE,IAAI,EAAE,eAAe,EAAE,SAAS,EAAE,eAAe,EAAC;IACpD,EAAE,IAAI,EAAE,aAAa,EAAE,SAAS,EAAE,mBAAmB,CAAC,IAAI,EAAE,IAAI,CAAC,EAAC;IAClE,EAAE,IAAI,EAAE,wBAAwB,EAAE,SAAS,EAAE,mBAAmB,CAAC,IAAI,CAAC,EAAC;IACvE,EAAE,IAAI,EAAE,wBAAwB,EAAE,SAAS,EAAE,mBAAmB,CAAC,IAAI,CAAC,EAAC;IACvE,EAAE,IAAI,EAAE,oBAAoB,EAAE,SAAS,EAAE,mBAAmB,CAAC,IAAI,CAAC,EAAC;CACtE,CAAA;AACD,YAAY;AAEZ,eAAe,QAAQ,CAAA"}
|
package/dist/factory.d.ts
CHANGED
|
@@ -1,16 +1,24 @@
|
|
|
1
1
|
import type { ComponentFactory, ComponentType, ComponentTypeHandle, ComponentTypeDictionary } from './types.js';
|
|
2
2
|
export declare const EmptyComponentHandle = "$$fragment$$";
|
|
3
3
|
/**
|
|
4
|
-
* The default implementation of the ComponentFactory
|
|
4
|
+
* The default implementation of the ComponentFactory interface, which works both
|
|
5
|
+
* client and server side.
|
|
5
6
|
*/
|
|
6
7
|
export declare class DefaultComponentFactory implements ComponentFactory {
|
|
7
8
|
private registry;
|
|
8
9
|
private dbg;
|
|
9
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Create a new instance of the DefaultComponentFactory
|
|
12
|
+
*
|
|
13
|
+
* @param initialComponents If provided, this dictionary will be registered
|
|
14
|
+
* with the factory.
|
|
15
|
+
*/
|
|
16
|
+
constructor(initialComponents?: ComponentTypeDictionary);
|
|
10
17
|
register(type: ComponentTypeHandle, component: ComponentType): void;
|
|
11
18
|
registerAll(components: ComponentTypeDictionary): void;
|
|
12
19
|
has(type: ComponentTypeHandle): boolean;
|
|
13
20
|
resolve(type: ComponentTypeHandle): undefined | ComponentType;
|
|
21
|
+
extract(): ComponentTypeDictionary;
|
|
14
22
|
}
|
|
15
23
|
/**
|
|
16
24
|
* Retrieve the currently staticly cached ComponentFactory instance, if there's no
|
package/dist/factory.js
CHANGED
|
@@ -1,12 +1,21 @@
|
|
|
1
1
|
const MERGE_SYMBOL = '/';
|
|
2
2
|
export const EmptyComponentHandle = '$$fragment$$';
|
|
3
3
|
/**
|
|
4
|
-
* The default implementation of the ComponentFactory
|
|
4
|
+
* The default implementation of the ComponentFactory interface, which works both
|
|
5
|
+
* client and server side.
|
|
5
6
|
*/
|
|
6
7
|
export class DefaultComponentFactory {
|
|
7
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Create a new instance of the DefaultComponentFactory
|
|
10
|
+
*
|
|
11
|
+
* @param initialComponents If provided, this dictionary will be registered
|
|
12
|
+
* with the factory.
|
|
13
|
+
*/
|
|
14
|
+
constructor(initialComponents) {
|
|
8
15
|
this.registry = {};
|
|
9
16
|
this.dbg = process.env.OPTIMIZELY_DEBUG == '1';
|
|
17
|
+
if (initialComponents)
|
|
18
|
+
this.registerAll(initialComponents);
|
|
10
19
|
}
|
|
11
20
|
register(type, component) {
|
|
12
21
|
type = processComponentTypeHandle(type);
|
|
@@ -31,12 +40,26 @@ export class DefaultComponentFactory {
|
|
|
31
40
|
return this.registry[type];
|
|
32
41
|
return undefined;
|
|
33
42
|
}
|
|
43
|
+
extract() {
|
|
44
|
+
const extracted = [];
|
|
45
|
+
Object.getOwnPropertyNames(this.registry).map(typeKey => {
|
|
46
|
+
extracted.push({
|
|
47
|
+
type: typeKey,
|
|
48
|
+
component: this.registry[typeKey]
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
return extracted;
|
|
52
|
+
}
|
|
34
53
|
}
|
|
35
54
|
function processComponentTypeHandle(handle) {
|
|
36
55
|
if (typeof (handle) == 'string')
|
|
37
56
|
return handle == "" ? EmptyComponentHandle : handle;
|
|
38
57
|
if (Array.isArray(handle) && handle.every(s => typeof (s) == 'string'))
|
|
39
|
-
return handle
|
|
58
|
+
return handle
|
|
59
|
+
.map(s => s.startsWith("_") ? s.substring(1) : s) // Remove all leading underscores
|
|
60
|
+
.filter(s => s.toLowerCase() != 'content') // Remove the "Content" base type
|
|
61
|
+
.map(s => s == "" ? EmptyComponentHandle : s) // Fall back to a fragment
|
|
62
|
+
.join(MERGE_SYMBOL); // Types are processed as a string
|
|
40
63
|
throw new Error(`Invalid component type handle: ${typeof (handle)}`);
|
|
41
64
|
}
|
|
42
65
|
const _static = {};
|
package/dist/factory.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../src/factory.ts"],"names":[],"mappings":"AACA,MAAM,YAAY,GAAG,GAAG,CAAA;AAExB,MAAM,CAAC,MAAM,oBAAoB,GAAI,cAAc,CAAA;AAEnD
|
|
1
|
+
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../src/factory.ts"],"names":[],"mappings":"AACA,MAAM,YAAY,GAAG,GAAG,CAAA;AAExB,MAAM,CAAC,MAAM,oBAAoB,GAAI,cAAc,CAAA;AAEnD;;;GAGG;AACH,MAAM,OAAO,uBAAuB;IAIhC;;;;;OAKG;IACH,YAAmB,iBAA2C;QATtD,aAAQ,GAA2C,EAAE,CAAA;QAWzD,IAAI,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,gBAAgB,IAAI,GAAG,CAAA;QAC9C,IAAI,iBAAiB;YACjB,IAAI,CAAC,WAAW,CAAC,iBAAiB,CAAC,CAAA;IAC3C,CAAC;IAED,QAAQ,CAAC,IAAyB,EAAE,SAAwB;QAExD,IAAI,GAAG,0BAA0B,CAAC,IAAI,CAAC,CAAA;QACvC,IAAI,IAAI,CAAC,GAAG;YAAE,OAAO,CAAC,GAAG,CAAC,sCAAuC,IAAK,EAAE,CAAC,CAAA;QACzE,IAAI,CAAC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M,CAAC;QACJ,IAAI,GAAG;YAAE,OAAO,CAAC,GAAG,CAAC,yDAAyD,CAAC,CAAA;IACnF,CAAC;IACD,OAAO,OAAO,CAAC,OAAO,CAAA;AAC1B,CAAC,CAAA;AACD;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,UAAU,GAA4C,CAAC,UAA4B,EAAE,EAAE;IAChG,OAAO,CAAC,OAAO,GAAG,UAAU,CAAA;AAChC,CAAC,CAAA;AACD,eAAe,UAAU,EAAE,CAAA"}
|
|
@@ -13,6 +13,7 @@ import * as Queries from './queries.js';
|
|
|
13
13
|
* @returns
|
|
14
14
|
*/
|
|
15
15
|
export const CmsContent = async ({ contentType, contentTypePrefix, contentLink: rawContentLink, children, fragmentData, layoutProps }) => {
|
|
16
|
+
let myContentType = contentType ? [...contentType] : undefined;
|
|
16
17
|
const context = getServerContext();
|
|
17
18
|
const contentLink = normalizeContentLink(rawContentLink);
|
|
18
19
|
if (!contentLink) {
|
|
@@ -37,34 +38,30 @@ export const CmsContent = async ({ contentType, contentTypePrefix, contentLink:
|
|
|
37
38
|
console.warn(`🟠 [CmsContent] Edit mode active without an authenticated client, this will cause problems`);
|
|
38
39
|
// DEBUG Tracing
|
|
39
40
|
if (context.isDebug)
|
|
40
|
-
console.log("⚪ [CmsContent] Rendering CMS Content for:", JSON.stringify(
|
|
41
|
+
console.log("⚪ [CmsContent] Rendering CMS Content for:", JSON.stringify(myContentType), contentLinkToString(contentLink), context.inEditMode ? "edit-mode" : "published");
|
|
41
42
|
// Ensure we have a content type to work with
|
|
42
|
-
if (!
|
|
43
|
+
if (!myContentType) {
|
|
43
44
|
if (isInline) {
|
|
44
45
|
console.error(`🔴 [CmsContent] No content type provided for content ${contentLinkToString(contentLink)}, content types cannot be resolved for inline content`);
|
|
45
46
|
throw new Error("Unable to render Inline CMS Content without Content Type information");
|
|
46
47
|
}
|
|
47
48
|
if (context.isDebugOrDevelopment)
|
|
48
|
-
console.warn(`🟠 [CmsContent] No content type provided for content ${contentLinkToString(contentLink)}, this causes an additional GraphQL query to resolve the
|
|
49
|
-
|
|
49
|
+
console.warn(`🟠 [CmsContent] No content type provided for content ${contentLinkToString(contentLink)}, this causes an additional GraphQL query to resolve the myContentType`);
|
|
50
|
+
myContentType = await getContentType(contentLink, client);
|
|
50
51
|
}
|
|
51
52
|
// Optimizely Graph stores the type in Most Significant first order, we need least significant first, also we're stripping out the common "Content" item from it
|
|
52
|
-
if (Array.isArray(
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
if (context.isDebug)
|
|
57
|
-
console.info(`⚪ [CmsContent] Component type [${contentType.join('/')}] doesn't have the configured prefix, adding ${contentTypePrefix} as prefix`);
|
|
58
|
-
contentType.unshift(contentTypePrefix);
|
|
59
|
-
}
|
|
53
|
+
if (Array.isArray(myContentType))
|
|
54
|
+
myContentType = contentTypePrefix ?
|
|
55
|
+
Utils.normalizeAndPrefixContentType(myContentType.reverse(), contentTypePrefix) :
|
|
56
|
+
Utils.normalizeContentType(myContentType.reverse(), true);
|
|
60
57
|
// Resolve component
|
|
61
|
-
const Component = factory.resolve(
|
|
58
|
+
const Component = factory.resolve(myContentType ?? "");
|
|
62
59
|
if (!Component) {
|
|
63
60
|
if (context.isDebugOrDevelopment) {
|
|
64
|
-
console.warn(`🟠 [CmsContent] Component of type "${
|
|
61
|
+
console.warn(`🟠 [CmsContent] Component of type "${myContentType?.join('/') ?? ""}" not resolved by factory`);
|
|
65
62
|
}
|
|
66
63
|
if (context.isDebug || context.inEditMode || outputEditorWarning) {
|
|
67
|
-
const errorMsg = _jsxs("div", { className: 'opti-error', children: ["Component of type \"",
|
|
64
|
+
const errorMsg = _jsxs("div", { className: 'opti-error', children: ["Component of type \"", myContentType?.join('/') ?? "", "\" not resolved by factory"] });
|
|
68
65
|
return children ? _jsxs(_Fragment, { children: [errorMsg, children] }) : errorMsg;
|
|
69
66
|
}
|
|
70
67
|
return _jsx(_Fragment, { children: children ? children : undefined });
|
|
@@ -77,14 +74,14 @@ export const CmsContent = async ({ contentType, contentTypePrefix, contentLink:
|
|
|
77
74
|
if (context.isDebug)
|
|
78
75
|
console.log("⚪ [CmsContent] Rendering CMS Component using fragment information", fragmentProps);
|
|
79
76
|
if (Utils.validatesFragment(Component) && !Component.validateFragment(fragmentData)) {
|
|
80
|
-
console.error("🔴 [CmsContent] Invalid fragment data received for ", Component.displayName ??
|
|
77
|
+
console.error("🔴 [CmsContent] Invalid fragment data received for ", Component.displayName ?? myContentType?.join("/") ?? "[Undetermined component]");
|
|
81
78
|
return _jsx(_Fragment, {});
|
|
82
79
|
}
|
|
83
80
|
return _jsx(Component, { contentLink: contentLink, data: fragmentData || {}, inEditMode: context.inEditMode, layoutProps: layoutProps, children: children });
|
|
84
81
|
}
|
|
85
82
|
if (isInline) {
|
|
86
83
|
console.error(`🔴 [CmsContent] No data for content ${contentLinkToString(contentLink)}, data cannot be resolved for inline content`);
|
|
87
|
-
throw new Error(`Unable to render Inline CMS Content without data. (Content Type: ${Component?.displayName ??
|
|
84
|
+
throw new Error(`Unable to render Inline CMS Content without data. (Content Type: ${Component?.displayName ?? myContentType?.join('/') ?? "Unknown"}; Content Link: ${contentLinkToString(contentLink)}; Data keys: ${Object.getOwnPropertyNames(fragmentData ?? {}).join(", ")})`);
|
|
88
85
|
}
|
|
89
86
|
// Render using included query
|
|
90
87
|
if (Utils.isCmsComponentWithDataQuery(Component)) {
|
|
@@ -102,7 +99,7 @@ export const CmsContent = async ({ contentType, contentTypePrefix, contentLink:
|
|
|
102
99
|
const [name, fragment] = Component.getDataFragment();
|
|
103
100
|
if (context.isDebug)
|
|
104
101
|
console.log(`⚪ [CmsContent] Component data fetching using fragment: ${name}`);
|
|
105
|
-
const fragmentQuery = `query getContentFragmentById($key: String!, $version: String, $locale: [Locales!]) {contentById:
|
|
102
|
+
const fragmentQuery = `query getContentFragmentById($key: String!, $version: String, $locale: [Locales!]) {contentById: _Content(where: {_metadata: {key: { eq: $key }, version: { eq: $version }}} locale: $locale) { total, items { _type: __typename, _metadata { key, version, locale } ...${name} }}} ${print(fragment)}`;
|
|
106
103
|
const fragmentVariables = Utils.contentLinkToRequestVariables(contentLink);
|
|
107
104
|
if (context.isDebug)
|
|
108
105
|
console.log(`⚪ [CmsContent] Component data fetching using variables: ${JSON.stringify(fragmentVariables)}`);
|
|
@@ -116,7 +113,7 @@ export const CmsContent = async ({ contentType, contentTypePrefix, contentLink:
|
|
|
116
113
|
}
|
|
117
114
|
// Assume there's no server side prepared data needed for the component
|
|
118
115
|
if (context.isDebug)
|
|
119
|
-
console.log(`⚪ [CmsContent] Component of type "${
|
|
116
|
+
console.log(`⚪ [CmsContent] Component of type "${myContentType?.join('/') ?? Component.displayName ?? '?'}" did not request pre-loading of data`);
|
|
120
117
|
return _jsx(Component, { contentLink: contentLink, data: fragmentData || {}, inEditMode: context.inEditMode, layoutProps: layoutProps, children: children });
|
|
121
118
|
};
|
|
122
119
|
export default CmsContent;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cms-content.js","sourceRoot":"","sources":["../../../src/server/components/cms-content.tsx"],"names":[],"mappings":";AAAA,OAAO,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"cms-content.js","sourceRoot":"","sources":["../../../src/server/components/cms-content.tsx"],"names":[],"mappings":";AAAA,OAAO,aAAa,CAAA;AAKpB,OAAO,cAAc,MAAM,uBAAuB,CAAA;AAClD,OAAO,gBAAgB,MAAM,eAAe,CAAA;AAC5C,OAAO,YAAY,EAAE,EAAE,QAAQ,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,mBAAmB,EAAoB,MAAM,iCAAiC,CAAA;AAC1J,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAC/B,OAAO,KAAK,KAAK,MAAM,oBAAoB,CAAA;AAC3C,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AASvC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,KAAK,EAAwB,EAAC,WAAW,EAAE,i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AAO,CAAC,OAAO;QACf,OAAO,CAAC,GAAG,CAAC,qCAAsC,aAAa,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,SAAS,CAAC,WAAW,IAAI,GAAG,uCAAuC,CAAC,CAAA;IACtJ,OAAO,KAAC,SAAS,IAAC,WAAW,EAAG,WAA0B,EAAG,IAAI,EAAG,YAAY,IAAI,EAAE,EAAG,UAAU,EAAG,OAAO,CAAC,UAAU,EAAG,WAAW,EAAG,WAAW,YAAK,QAAQ,GAAa,CAAA;AAClL,CAAC,CAAA;AAED,eAAe,UAAU,CAAA"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import 'server-only';
|
|
2
|
+
import { type ComponentProps, type ComponentType as ReactComponentType, type ExoticComponent as ReactExoticComponent } from 'react';
|
|
3
|
+
export type EditableComponentType = (ReactComponentType<any>) | (ReactExoticComponent<any>) | (keyof JSX.IntrinsicElements);
|
|
4
|
+
export type EditableComponentProps<FT extends EditableComponentType> = FT extends keyof JSX.IntrinsicElements ? JSX.IntrinsicElements[FT] : ComponentProps<FT>;
|
|
5
|
+
export type CmsEditableProps<FT extends EditableComponentType> = {
|
|
6
|
+
as?: FT;
|
|
7
|
+
} & ({
|
|
8
|
+
cmsId?: string | null;
|
|
9
|
+
cmsFieldName?: never;
|
|
10
|
+
} | {
|
|
11
|
+
cmsId?: never;
|
|
12
|
+
cmsFieldName?: string | null;
|
|
13
|
+
}) & EditableComponentProps<FT>;
|
|
14
|
+
/**
|
|
15
|
+
* Server side wrapper to create HTML elements that include the needed
|
|
16
|
+
* data-epi- properties to render the edit mode markers
|
|
17
|
+
*
|
|
18
|
+
* @param param0 The HTML element with the simple properties
|
|
19
|
+
* @returns
|
|
20
|
+
*/
|
|
21
|
+
export declare const CmsEditable: <CT extends EditableComponentType = "div">({ as: DefaultElement, cmsId, cmsFieldName, children, key, ...props }: CmsEditableProps<CT>) => import("react/jsx-runtime").JSX.Element;
|
|
22
|
+
export default CmsEditable;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import 'server-only';
|
|
3
|
+
import { getServerContext } from '@remkoj/optimizely-cms-react/rsc';
|
|
4
|
+
/**
|
|
5
|
+
* Server side wrapper to create HTML elements that include the needed
|
|
6
|
+
* data-epi- properties to render the edit mode markers
|
|
7
|
+
*
|
|
8
|
+
* @param param0 The HTML element with the simple properties
|
|
9
|
+
* @returns
|
|
10
|
+
*/
|
|
11
|
+
//@ts-expect-error TypeScript just doesn't understand....
|
|
12
|
+
export const CmsEditable = ({ as: DefaultElement, cmsId, cmsFieldName, children, key, ...props }) => {
|
|
13
|
+
const HtmlElement = DefaultElement ?? 'div';
|
|
14
|
+
const { inEditMode } = getServerContext();
|
|
15
|
+
return _jsx(HtmlElement, { ...props, "data-epi-block-id": inEditMode ? cmsId ?? undefined : undefined, "data-epi-property-name": inEditMode ? cmsFieldName ?? undefined : undefined, children: children });
|
|
16
|
+
};
|
|
17
|
+
export default CmsEditable;
|
|
18
|
+
//# sourceMappingURL=cms-editable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cms-editable.js","sourceRoot":"","sources":["../../../src/server/components/cms-editable.tsx"],"names":[],"mappings":";AAAA,OAAO,aAAa,CAAA;AAEpB,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAA;AAenE;;;;;;GAMG;AACH,yDAAyD;AACzD,MAAM,CAAC,MAAM,WAAW,GAAG,CAA2C,EAAE,EAAE,EAAG,cAAc,EAAE,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,KAAK,EAAwB,EAAE,EAAE;IAEjK,MAAM,WAAW,GAAG,cAAc,IAAI,KAAW,CAAA;IACjD,MAAM,EAAE,UAAU,EAAE,GAAG,gBAAgB,EAAE,CAAA;IACzC,OAAO,KAAC,WAAW,OAAK,KAAK,uBAAsB,UAAU,CAAC,CAAC,CAAC,KAAK,IAAI,SAAS,CAAC,CAAC,CAAC,SAAS,4BAA4B,UAAU,CAAC,CAAC,CAAC,YAAY,IAAI,SAAS,CAAC,CAAC,CAAC,SAAS,YAAK,QAAQ,GAAgB,CAAA;AAC7M,CAAC,CAAA;AAED,eAAe,WAAW,CAAA"}
|