@remkoj/optimizely-cms-react 5.0.1 → 5.0.2
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/rich-text/components.d.ts +10 -0
- package/dist/components/rich-text/components.js +19 -0
- package/dist/components/rich-text/components.js.map +1 -1
- package/dist/components/rich-text/index.d.ts +3 -4
- package/dist/components/rich-text/index.js +15 -9
- package/dist/components/rich-text/index.js.map +1 -1
- package/dist/components/rich-text/types.d.ts +9 -6
- package/dist/components/type-utils.d.ts +20 -11
- package/dist/components.d.ts +1 -1
- package/package.json +6 -6
|
@@ -23,6 +23,16 @@ export declare function createHtmlComponent<E extends keyof JSX.IntrinsicElement
|
|
|
23
23
|
export declare const DefaultTextNode: FunctionComponent<PropsWithOptionalContext<{
|
|
24
24
|
node: TextNode;
|
|
25
25
|
}>>;
|
|
26
|
+
/**
|
|
27
|
+
* Default component for Rich Text elements that should not be part of the HTML fragment
|
|
28
|
+
* and should not be rendered if they are.
|
|
29
|
+
*
|
|
30
|
+
* @param param0 The component parameters
|
|
31
|
+
* @returns The children, if any
|
|
32
|
+
*/
|
|
33
|
+
export declare const DefaultNoRenderNode: FunctionComponent<PropsWithOptionalContext<PropsWithChildren<{
|
|
34
|
+
node: TypedNode;
|
|
35
|
+
}>>>;
|
|
26
36
|
/**
|
|
27
37
|
* A default component dictionary that allows to serialize the structured HTML
|
|
28
38
|
* into React, using the component library shared across the react SDK.
|
|
@@ -60,6 +60,19 @@ export const DefaultTextNode = ({ ctx, node }) => {
|
|
|
60
60
|
console.warn('🟠 [Rich Text] Text node with unsupported additional properties:', unsupportedProps.join(', '));
|
|
61
61
|
return decodeHTML(node.text);
|
|
62
62
|
};
|
|
63
|
+
/**
|
|
64
|
+
* Default component for Rich Text elements that should not be part of the HTML fragment
|
|
65
|
+
* and should not be rendered if they are.
|
|
66
|
+
*
|
|
67
|
+
* @param param0 The component parameters
|
|
68
|
+
* @returns The children, if any
|
|
69
|
+
*/
|
|
70
|
+
export const DefaultNoRenderNode = ({ children, ctx, node }) => {
|
|
71
|
+
if (ctx?.isDebugOrDevelopment) {
|
|
72
|
+
console.warn(`🟠 [Rich Text] Not rendering ${node.type} to prevent React/JSX errors`);
|
|
73
|
+
}
|
|
74
|
+
return children;
|
|
75
|
+
};
|
|
63
76
|
/**
|
|
64
77
|
* A default component dictionary that allows to serialize the structured HTML
|
|
65
78
|
* into React, using the component library shared across the react SDK.
|
|
@@ -73,6 +86,12 @@ export const DefaultComponents = [
|
|
|
73
86
|
}),
|
|
74
87
|
},
|
|
75
88
|
{ type: 'RichText/text', component: DefaultTextNode },
|
|
89
|
+
// Catch elements that should not be in the content
|
|
90
|
+
{ type: 'RichText/html', component: DefaultNoRenderNode },
|
|
91
|
+
{ type: 'RichText/head', component: DefaultNoRenderNode },
|
|
92
|
+
{ type: 'RichText/meta', component: DefaultNoRenderNode },
|
|
93
|
+
{ type: 'RichText/title', component: DefaultNoRenderNode },
|
|
94
|
+
{ type: 'RichText/body', component: DefaultNoRenderNode },
|
|
76
95
|
// Aliased tags
|
|
77
96
|
{ type: 'RichText/paragraph', component: createHtmlComponent('p') },
|
|
78
97
|
{ type: 'RichText/heading-one', component: createHtmlComponent('h1') },
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"components.js","sourceRoot":"","sources":["../../../src/components/rich-text/components.tsx"],"names":[],"mappings":";AAIA,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAErC,mBAAmB;AACnB,MAAM,aAAa,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,CAAC,CAAA;AAE9E,yBAAyB;AACzB;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,mBAAmB,CACjC,OAAU,EACV,iBAA0B,KAAK,EAC/B,YAAgE;IAEhE,MAAM,WAAW,GAAG,OAAiB,CAAA;IACrC,MAAM,SAAS,GAAG,CAAC,EACjB,QA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AAC,EAAE;IACxE,EAAE,IAAI,EAAE,oBAAoB,EAAE,SAAS,EAAE,mBAAmB,CAAC,IAAI,CAAC,EAAE;IACpE,EAAE,IAAI,EAAE,gBAAgB,EAAE,SAAS,EAAE,mBAAmB,CAAC,KAAK,EAAE,IAAI,CAAC,EAAE;IAEvE,oBAAoB;IACpB,EAAE,IAAI,EAAE,aAAa,EAAE,SAAS,EAAE,mBAAmB,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE;CACpE,CAAA"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type {
|
|
3
|
-
import { type PropsWithContext } from '../../context/types.js';
|
|
1
|
+
import type { RichTextImplProps } from './types.js';
|
|
2
|
+
import type { ElementWithChildrenType } from '../type-utils.js';
|
|
4
3
|
export * from './types.js';
|
|
5
|
-
export declare const RichText:
|
|
4
|
+
export declare const RichText: <ET extends ElementWithChildrenType>({ factory, text, className, as: Wrapper, debug, noWrapper, cmsFieldName, cmsId, ctx, children, ...props }: RichTextImplProps<ET>) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -4,27 +4,33 @@ import { DefaultComponentFactory } from '../../factory/default.js';
|
|
|
4
4
|
import { DefaultComponents, DefaultTextNode, createHtmlComponent, } from './components.js';
|
|
5
5
|
import { CmsEditable } from '../cms-editable/index.js';
|
|
6
6
|
export * from './types.js';
|
|
7
|
-
export const RichText = ({ factory, text = '{ "type": "richText" }', className = 'rich-text', as: Wrapper = 'div', debug = false, noWrapper = false, cmsFieldName = null, cmsId = null, ctx, ...props }) => {
|
|
7
|
+
export const RichText = ({ factory, text = '{ "type": "richText" }', className = 'rich-text', as: Wrapper = 'div', debug = false, noWrapper = false, cmsFieldName = null, cmsId = null, ctx, children, ...props }) => {
|
|
8
8
|
const id = Utils.getRandomId('rich-text');
|
|
9
9
|
const richTextFactory = ctx.factory ?? factory ?? new DefaultComponentFactory(DefaultComponents);
|
|
10
|
+
const isDebug = ctx.isDebug || debug;
|
|
10
11
|
try {
|
|
11
12
|
const data = Utils.processNodeInput(text);
|
|
12
|
-
const textContent =
|
|
13
|
+
const textContent = data?.children?.map((child, idx) => {
|
|
13
14
|
const elementId = id + '::' + idx;
|
|
14
15
|
return (_jsx(RichTextElement, { factory: richTextFactory, node: child, idPrefix: elementId + '::', ctx: ctx }, elementId));
|
|
15
|
-
});
|
|
16
|
-
if (
|
|
16
|
+
}) || children;
|
|
17
|
+
if (cmsId || cmsFieldName)
|
|
18
|
+
return (_jsx(CmsEditable, { as: (Wrapper ?? 'div'), className: className, cmsId: cmsId || undefined, cmsFieldName: cmsFieldName || undefined, ctx: ctx, ...props, children: textContent }));
|
|
19
|
+
if (noWrapper || !Wrapper)
|
|
17
20
|
return _jsx(_Fragment, { children: textContent });
|
|
18
|
-
return (
|
|
21
|
+
return (
|
|
22
|
+
//@ts-expect-error
|
|
23
|
+
_jsx(Wrapper, { className: className, ...props, children: textContent }));
|
|
19
24
|
}
|
|
20
25
|
catch {
|
|
21
|
-
if (
|
|
26
|
+
if (isDebug)
|
|
22
27
|
console.warn('🟠 [Rich Text] Invalid rich text received: ', text);
|
|
23
|
-
return Object.getOwnPropertyNames(props).length > 0 ? (_jsx("div", { className: className, ...props })) :
|
|
28
|
+
return Object.getOwnPropertyNames(props).length > 0 ? (_jsx("div", { className: className, ...props, children: children })) : (_jsx(_Fragment, { children: children }));
|
|
24
29
|
}
|
|
25
30
|
};
|
|
26
31
|
//#region Supportive React components
|
|
27
32
|
const RichTextElement = ({ factory, node, idPrefix, debug, ctx }) => {
|
|
33
|
+
const isDebug = ctx.isDebug || debug;
|
|
28
34
|
// Render text
|
|
29
35
|
if (Utils.isText(node)) {
|
|
30
36
|
if (node.text.length == 0)
|
|
@@ -34,7 +40,7 @@ const RichTextElement = ({ factory, node, idPrefix, debug, ctx }) => {
|
|
|
34
40
|
}
|
|
35
41
|
// Ignore incorrect data
|
|
36
42
|
if (!Utils.isTypedNode(node)) {
|
|
37
|
-
if (
|
|
43
|
+
if (isDebug)
|
|
38
44
|
console.warn('🟠 [Rich Text] Invalid rich text element data received:', node);
|
|
39
45
|
return null;
|
|
40
46
|
}
|
|
@@ -48,7 +54,7 @@ const RichTextElement = ({ factory, node, idPrefix, debug, ctx }) => {
|
|
|
48
54
|
// Resolve component (and add to factory if not yet present)
|
|
49
55
|
let Component = factory?.resolve(`RichText/${node.type}`);
|
|
50
56
|
if (!Component) {
|
|
51
|
-
if (
|
|
57
|
+
if (isDebug)
|
|
52
58
|
console.warn(`🟠 [Rich Text] No renderer for node type, using and registering HtmlComponent for "${node.type}": RichText/${node.type}`);
|
|
53
59
|
Component = createHtmlComponent(node.type);
|
|
54
60
|
factory?.register(`RichText/${node.type}`, Component);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/rich-text/index.tsx"],"names":[],"mappings":";AAEA,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AACnC,OAAO,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAA;AAClE,OAAO,EACL,iBAAiB,EACjB,eAAe,EACf,mBAAmB,GACpB,MAAM,iBAAiB,CAAA;AAExB,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/rich-text/index.tsx"],"names":[],"mappings":";AAEA,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AACnC,OAAO,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAA;AAClE,OAAO,EACL,iBAAiB,EACjB,eAAe,EACf,mBAAmB,GACpB,MAAM,iBAAiB,CAAA;AAExB,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AAGtD,cAAc,YAAY,CAAA;AAE1B,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAqC,EAC3D,OAAO,EACP,IAAI,GAAG,wBAAwB,EAC/B,SAAS,GAAG,WAAW,EACvB,EAAE,EAAE,OAAO,GAAG,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CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;YAC/B,MAAM,SAAS,GAAG,QAAQ,GAAG,GAAG,CAAA;YAChC,OAAO,CACL,KAAC,eAAe,IAEd,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,KAAK,EACX,QAAQ,EAAE,SAAS,GAAG,IAAI,EAC1B,GAAG,EAAE,GAAG,IAJH,SAAS,CAKd,CACH,CAAA;QACH,CAAC,CAAC;QACJ,CAAC,CAAC,SAAS,CAAA;IAEf,4DAA4D;IAC5D,IAAI,SAAS,GAAG,OAAO,EAAE,OAAO,CAAC,YAAY,IAAI,CAAC,IAAI,EAAE,CAAC,CAAA;IACzD,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,IAAI,OAAO;YACT,OAAO,CAAC,IAAI,CACV,sFAAsF,IAAI,CAAC,IAAI,eAAe,IAAI,CAAC,IAAI,EAAE,CAC1H,CAAA;QACH,SAAS,GAAG,mBAAmB,CAAC,IAAI,CAAC,IAAmC,CAAC,CAAA;QACzE,OAAO,EAAE,QAAQ,CAAC,YAAY,IAAI,CAAC,IAAI,EAAE,EAAE,SAAS,CAAC,CAAA;IACvD,CAAC;IAED,mBAAmB;IACnB,OAAO,CACL,KAAC,SAAS,IAAC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,YAC5B,SAAS,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,GAChD,CACb,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { FunctionComponent } from "react";
|
|
2
2
|
import type { ComponentFactory } from "../../factory/types.js";
|
|
3
|
-
import type { PropsWithOptionalContext } from "../../context/types.js";
|
|
4
|
-
import type {
|
|
5
|
-
export type RichTextProps = {
|
|
3
|
+
import type { PropsWithOptionalContext, PropsWithContext } from "../../context/types.js";
|
|
4
|
+
import type { ElementProps, ElementWithChildrenType } from "../type-utils.js";
|
|
5
|
+
export type RichTextProps<ET extends ElementWithChildrenType> = {
|
|
6
6
|
/**
|
|
7
7
|
* The component factory used for this rich text content
|
|
8
8
|
*
|
|
@@ -22,9 +22,11 @@ export type RichTextProps = {
|
|
|
22
22
|
* Set the component type of the wrapper to use, defaults to a 'div'
|
|
23
23
|
* element when not defined
|
|
24
24
|
*/
|
|
25
|
-
as?:
|
|
25
|
+
as?: ET | null;
|
|
26
26
|
/**
|
|
27
27
|
* Control the debugging output
|
|
28
|
+
*
|
|
29
|
+
* @deprecated The debug value from the context will be used
|
|
28
30
|
*/
|
|
29
31
|
debug?: boolean;
|
|
30
32
|
/**
|
|
@@ -41,7 +43,8 @@ export type RichTextProps = {
|
|
|
41
43
|
*/
|
|
42
44
|
cmsId?: string | null;
|
|
43
45
|
};
|
|
44
|
-
export type RichTextComponent =
|
|
46
|
+
export type RichTextComponent = <ET extends ElementWithChildrenType>(props: PropsWithOptionalContext<RichTextProps<ET>>) => ReturnType<FunctionComponent>;
|
|
47
|
+
export type RichTextImplProps<ET extends ElementWithChildrenType> = PropsWithContext<RichTextProps<ET> & Omit<ElementProps<ET>, keyof RichTextProps<ET>>>;
|
|
45
48
|
export type RichTextElementProps = Readonly<{
|
|
46
49
|
debug?: boolean;
|
|
47
50
|
factory?: ComponentFactory;
|
|
@@ -1,4 +1,23 @@
|
|
|
1
|
-
import { GenericContext } from "../rsc.js";
|
|
1
|
+
import type { GenericContext } from "../rsc.js";
|
|
2
|
+
import type { PropsWithChildren } from "react";
|
|
3
|
+
/**
|
|
4
|
+
* Define an element as a React Component, React ExoticComponent or string name
|
|
5
|
+
* representing a HTML Element (e.g. "div", "a", etc...), this value can be used
|
|
6
|
+
* as first argument of React.createElement()
|
|
7
|
+
*/
|
|
8
|
+
export type ElementType = (React.ComponentType<any>) | (React.ExoticComponent<any>) | (keyof JSX.IntrinsicElements);
|
|
9
|
+
/**
|
|
10
|
+
* Define an element as a React Component, React ExoticComponent or string name
|
|
11
|
+
* representing a HTML Element (e.g. "div", "a", etc...), this value can be used
|
|
12
|
+
* as first argument of React.createElement()
|
|
13
|
+
*
|
|
14
|
+
* The type must support children
|
|
15
|
+
*/
|
|
16
|
+
export type ElementWithChildrenType = React.ComponentType<PropsWithChildren> | React.ExoticComponent<PropsWithChildren> | keyof Omit<JSX.IntrinsicElements, 'meta' | 'img' | 'video' | 'audio'>;
|
|
17
|
+
/**
|
|
18
|
+
* The properties type of an ElementType
|
|
19
|
+
*/
|
|
20
|
+
export type ElementProps<T extends ElementType> = T extends keyof JSX.IntrinsicElements ? React.HTMLProps<JSX.IntrinsicElements[T]> : React.ComponentProps<T>;
|
|
2
21
|
/**
|
|
3
22
|
* Tests if K is a property of T - if so: it is the type of
|
|
4
23
|
* T[K]; if not: it is equal to never
|
|
@@ -13,10 +32,6 @@ export type TypeIfPropExists<T extends ElementType, K, U> = K extends keyof Elem
|
|
|
13
32
|
* Defines the type to be T or an array of T
|
|
14
33
|
*/
|
|
15
34
|
export type MayBeArray<T> = T | T[];
|
|
16
|
-
/**
|
|
17
|
-
* The properties type of an ElementType
|
|
18
|
-
*/
|
|
19
|
-
export type ElementProps<T extends ElementType> = T extends keyof JSX.IntrinsicElements ? React.HTMLProps<JSX.IntrinsicElements[T]> : React.ComponentProps<T>;
|
|
20
35
|
/**
|
|
21
36
|
* The union of property names of an Element that may receive child elements
|
|
22
37
|
*/
|
|
@@ -26,12 +41,6 @@ export type ElementChildrenProps<T extends ElementType> = keyof {
|
|
|
26
41
|
export type GenericContextProps<T extends ElementType> = keyof {
|
|
27
42
|
[P in keyof ElementProps<T> as GenericContext extends ElementProps<T>[P] ? P : never]: ElementProps<T>[P];
|
|
28
43
|
};
|
|
29
|
-
/**
|
|
30
|
-
* Define an element as a React Component, React ExoticComponent or string name
|
|
31
|
-
* representing a HTML Element (e.g. "div", "a", etc...), this value can be used
|
|
32
|
-
* as first argument of React.createElement()
|
|
33
|
-
*/
|
|
34
|
-
export type ElementType = (React.ComponentType<any>) | (React.ExoticComponent<any>) | (keyof JSX.IntrinsicElements);
|
|
35
44
|
/**
|
|
36
45
|
* Reserved Element properties that may not be passed to CmsContentArea wrappers, as these are auto-injected
|
|
37
46
|
*/
|
package/dist/components.d.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* deprecated, use either `@remkoj/optimizely-cms-react` or
|
|
7
7
|
* `@remkoj/optimizely-cms-react/rsc`, dependingn on your context
|
|
8
8
|
*/
|
|
9
|
-
export declare const RichText: import("react").ComponentType<import("./rsc.js").PropsWithOptionalContext<Omit<import("./
|
|
9
|
+
export declare const RichText: import("react").ComponentType<import("./rsc.js").PropsWithOptionalContext<Omit<import("./components/rich-text/types.js").RichTextImplProps<import("./components/type-utils.js").ElementWithChildrenType>, "ctx">>>;
|
|
10
10
|
/**
|
|
11
11
|
* @deprecated The `@remkoj/optimizely-cms-react/components` export has been deprecated
|
|
12
12
|
*/
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@remkoj/optimizely-cms-react",
|
|
3
3
|
"license": "Apache-2.0",
|
|
4
|
-
"version": "5.0.
|
|
4
|
+
"version": "5.0.2",
|
|
5
5
|
"repository": "https://github.com/remkoj/optimizely-dxp-clients.git",
|
|
6
6
|
"author": "Remko Jantzen <693172+remkoj@users.noreply.github.com>",
|
|
7
7
|
"homepage": "https://github.com/remkoj/optimizely-dxp-clients/tree/main/packages/optimizely-cms-react",
|
|
@@ -27,13 +27,13 @@
|
|
|
27
27
|
}
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@remkoj/optimizely-graph-client": "5.0.
|
|
30
|
+
"@remkoj/optimizely-graph-client": "5.0.2",
|
|
31
31
|
"@types/crypto-js": "^4.2.2",
|
|
32
|
-
"@types/node": "^22.
|
|
33
|
-
"@types/react": "^18.3.
|
|
34
|
-
"@types/react-dom": "18.3.
|
|
32
|
+
"@types/node": "^22.15.17",
|
|
33
|
+
"@types/react": "^18.3.21",
|
|
34
|
+
"@types/react-dom": "18.3.7",
|
|
35
35
|
"entities": "^6.0.0",
|
|
36
|
-
"graphql": "^16.
|
|
36
|
+
"graphql": "^16.11.0",
|
|
37
37
|
"graphql-request": "^6.1.0",
|
|
38
38
|
"prop-types": "^15.8.1",
|
|
39
39
|
"react": "^18.3.1",
|