@remkoj/optimizely-cms-react 2.1.0 → 3.1.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/README.md +38 -2
- package/dist/components/client.d.ts +42 -0
- package/dist/components/client.js +52 -0
- package/dist/components/client.js.map +1 -0
- package/dist/components/cms-content/client.d.ts +11 -0
- package/dist/components/cms-content/client.js +72 -0
- package/dist/components/cms-content/client.js.map +1 -0
- package/dist/components/cms-content/get-content-type.d.ts +13 -0
- package/dist/components/cms-content/get-content-type.js +70 -0
- package/dist/components/cms-content/get-content-type.js.map +1 -0
- package/dist/components/cms-content/get-content.d.ts +4 -0
- package/dist/components/cms-content/get-content.js +91 -0
- package/dist/components/cms-content/get-content.js.map +1 -0
- package/dist/components/cms-content/resolve-component.d.ts +18 -0
- package/dist/components/cms-content/resolve-component.js +53 -0
- package/dist/components/cms-content/resolve-component.js.map +1 -0
- package/dist/components/cms-content/resolve-content-type.d.ts +15 -0
- package/dist/components/cms-content/resolve-content-type.js +29 -0
- package/dist/components/cms-content/resolve-content-type.js.map +1 -0
- package/dist/components/cms-content/rsc.d.ts +11 -0
- package/dist/components/cms-content/rsc.js +50 -0
- package/dist/components/cms-content/rsc.js.map +1 -0
- package/dist/components/cms-content/types.d.ts +59 -0
- package/dist/components/cms-content/types.js +2 -0
- package/dist/components/cms-content/types.js.map +1 -0
- package/dist/components/cms-content/utils.d.ts +3 -0
- package/dist/components/cms-content/utils.js +6 -0
- package/dist/components/cms-content/utils.js.map +1 -0
- package/dist/components/cms-content-area/index.d.ts +17 -0
- package/dist/{server/components/cms-content-area.js → components/cms-content-area/index.js} +43 -43
- package/dist/components/cms-content-area/index.js.map +1 -0
- package/dist/{server/components → components/cms-content-area}/types.d.ts +31 -94
- package/dist/components/cms-content-area/types.js.map +1 -0
- package/dist/{server/components/cms-editable.d.ts → components/cms-editable/index.d.ts} +5 -3
- package/dist/components/cms-editable/index.js +15 -0
- package/dist/components/cms-editable/index.js.map +1 -0
- package/dist/components/{cms-styles.js → cms-styles/index.js} +1 -1
- package/dist/components/cms-styles/index.js.map +1 -0
- package/dist/components/rich-text/components.d.ts +14 -0
- package/dist/components/rich-text/components.js +63 -0
- package/dist/components/rich-text/components.js.map +1 -0
- package/dist/components/rich-text/index.d.ts +4 -0
- package/dist/components/rich-text/index.js +47 -0
- package/dist/components/rich-text/index.js.map +1 -0
- package/dist/components/{rich-text.d.ts → rich-text/types.d.ts} +13 -18
- package/dist/components/rich-text/types.js +2 -0
- package/dist/components/rich-text/types.js.map +1 -0
- package/dist/components/rich-text/utils.d.ts +5 -0
- package/dist/components/rich-text/utils.js +24 -0
- package/dist/components/rich-text/utils.js.map +1 -0
- package/dist/components/rsc.d.ts +47 -0
- package/dist/components/rsc.js +55 -0
- package/dist/components/rsc.js.map +1 -0
- package/dist/{server → components}/type-utils.js.map +1 -1
- package/dist/{server/components → components}/visual-builder/functions.d.ts +7 -2
- package/dist/{server/components → components}/visual-builder/functions.js +8 -3
- package/dist/components/visual-builder/functions.js.map +1 -0
- package/dist/{server/components/visual-builder/Composition.d.ts → components/visual-builder/index.d.ts} +4 -3
- package/dist/{server/components/visual-builder/Composition.js → components/visual-builder/index.js} +9 -18
- package/dist/components/visual-builder/index.js.map +1 -0
- package/dist/{server/components → components}/visual-builder/types.d.ts +6 -1
- package/dist/components/visual-builder/types.js.map +1 -0
- package/dist/components.d.ts +27 -0
- package/dist/components.js +20 -0
- package/dist/components.js.map +1 -0
- package/dist/context/client.d.ts +70 -0
- package/dist/context/client.js +78 -0
- package/dist/context/client.js.map +1 -0
- package/dist/context/rsc.d.ts +33 -0
- package/dist/context/rsc.js +75 -0
- package/dist/context/rsc.js.map +1 -0
- package/dist/context/types.d.ts +15 -0
- package/dist/context/types.js +2 -0
- package/dist/{server/components → context}/types.js.map +1 -1
- package/dist/{server/components → data}/queries.js +121 -121
- package/dist/data/queries.js.map +1 -0
- package/dist/{factory.d.ts → factory/default.d.ts} +1 -18
- package/dist/{factory.js → factory/default.js} +2 -34
- package/dist/factory/default.js.map +1 -0
- package/dist/factory/index.d.ts +17 -0
- package/dist/factory/index.js +21 -0
- package/dist/factory/index.js.map +1 -0
- package/dist/factory/types.d.ts +51 -0
- package/dist/factory/types.js +2 -0
- package/dist/factory/types.js.map +1 -0
- package/dist/factory/undef.d.ts +9 -0
- package/dist/factory/undef.js +19 -0
- package/dist/factory/undef.js.map +1 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/dist/{server/is-debug.d.ts → rsc-utilities.d.ts} +0 -1
- package/dist/{server/is-debug.js → rsc-utilities.js} +1 -2
- package/dist/{server/is-debug.js.map → rsc-utilities.js.map} +1 -1
- package/dist/rsc.d.ts +11 -0
- package/dist/rsc.js +14 -0
- package/dist/rsc.js.map +1 -0
- package/dist/types.d.ts +10 -56
- package/dist/utilities.d.ts +23 -9
- package/dist/utilities.js +22 -1
- package/dist/utilities.js.map +1 -1
- package/package.json +12 -24
- package/dist/browser/context.d.ts +0 -6
- package/dist/browser/context.js +0 -15
- package/dist/browser/context.js.map +0 -1
- package/dist/browser/index.d.ts +0 -1
- package/dist/browser/index.js +0 -2
- package/dist/browser/index.js.map +0 -1
- package/dist/components/cms-styles.js.map +0 -1
- package/dist/components/index.d.ts +0 -2
- package/dist/components/index.js +0 -3
- package/dist/components/index.js.map +0 -1
- package/dist/components/rich-text.js +0 -138
- package/dist/components/rich-text.js.map +0 -1
- package/dist/factory.js.map +0 -1
- package/dist/server/components/cms-content-area.d.ts +0 -13
- package/dist/server/components/cms-content-area.js.map +0 -1
- package/dist/server/components/cms-content.d.ts +0 -11
- package/dist/server/components/cms-content.js +0 -154
- package/dist/server/components/cms-content.js.map +0 -1
- package/dist/server/components/cms-editable.js +0 -18
- package/dist/server/components/cms-editable.js.map +0 -1
- package/dist/server/components/get-content-type.d.ts +0 -12
- package/dist/server/components/get-content-type.js +0 -51
- package/dist/server/components/get-content-type.js.map +0 -1
- package/dist/server/components/index.d.ts +0 -4
- package/dist/server/components/index.js +0 -5
- package/dist/server/components/index.js.map +0 -1
- package/dist/server/components/queries.js.map +0 -1
- package/dist/server/components/visual-builder/Composition.js.map +0 -1
- package/dist/server/components/visual-builder/functions.js.map +0 -1
- package/dist/server/components/visual-builder/index.d.ts +0 -4
- package/dist/server/components/visual-builder/index.js +0 -4
- package/dist/server/components/visual-builder/index.js.map +0 -1
- package/dist/server/components/visual-builder/types.js.map +0 -1
- package/dist/server/context.d.ts +0 -22
- package/dist/server/context.js +0 -81
- package/dist/server/context.js.map +0 -1
- package/dist/server/factory.d.ts +0 -10
- package/dist/server/factory.js +0 -18
- package/dist/server/factory.js.map +0 -1
- package/dist/server/index.d.ts +0 -6
- package/dist/server/index.js +0 -6
- package/dist/server/index.js.map +0 -1
- /package/dist/{server/components → components/cms-content-area}/types.js +0 -0
- /package/dist/components/{cms-styles.d.ts → cms-styles/index.d.ts} +0 -0
- /package/dist/{server → components}/type-utils.d.ts +0 -0
- /package/dist/{server → components}/type-utils.js +0 -0
- /package/dist/{server/components → components}/visual-builder/types.js +0 -0
- /package/dist/{server/components → data}/queries.d.ts +0 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import getContentType from './get-content-type.js';
|
|
3
|
+
import getContent from './get-content.js';
|
|
4
|
+
import { AuthMode, normalizeContentLink, contentLinkToString } from '@remkoj/optimizely-graph-client';
|
|
5
|
+
import resolveComponent, { isComponentMissingComponent } from './resolve-component.js';
|
|
6
|
+
import resolveContentType from './resolve-content-type.js';
|
|
7
|
+
/**
|
|
8
|
+
* React Server Side component for the CmsContent
|
|
9
|
+
*
|
|
10
|
+
* @param param0
|
|
11
|
+
* @returns
|
|
12
|
+
*/
|
|
13
|
+
export async function CmsContent({
|
|
14
|
+
// Own properties
|
|
15
|
+
contentType, contentTypePrefix, contentLink: rawContentLink, children, fragmentData, layoutProps, noDataLoad, variant, ctx }) {
|
|
16
|
+
// Prepare context
|
|
17
|
+
const graphClient = ctx.client;
|
|
18
|
+
// Normalize the ContentLink
|
|
19
|
+
const contentLink = normalizeContentLink(rawContentLink);
|
|
20
|
+
// Ensure we have the contentType
|
|
21
|
+
let myContentType = resolveContentType(contentType, fragmentData);
|
|
22
|
+
if (!myContentType) {
|
|
23
|
+
if (!graphClient) {
|
|
24
|
+
console.error(`🔴 [CmsContent] Unable to load content type - no Optimizely Graph client present`);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
if (!contentLink) {
|
|
28
|
+
console.error(`🔴 [CmsContent] Unable to load content type - no content link present`);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
myContentType = await getContentType(contentLink, graphClient);
|
|
32
|
+
}
|
|
33
|
+
// Provide a bit of debugging context
|
|
34
|
+
if (graphClient?.debug) {
|
|
35
|
+
const mode = ctx.inEditMode ? "Edit" : ctx.inPreviewMode ? "Preview" : "Public";
|
|
36
|
+
console.log(`👔 [CmsContent] ${mode} mode active for content with id: ${contentLinkToString(contentLink)} of type ${myContentType?.join("/") ?? "unknown"}`);
|
|
37
|
+
if ((ctx.inEditMode || ctx.inPreviewMode) && graphClient.currentAuthMode == AuthMode.Public)
|
|
38
|
+
console.warn(`🟠 [CmsContent] ${mode} mode active without an authenticated graphClient, this will cause problems. Make sure the context has an authenticated client.`);
|
|
39
|
+
}
|
|
40
|
+
// Retrieve the Component used to render this item
|
|
41
|
+
const Component = resolveComponent(myContentType, contentTypePrefix, variant, ctx);
|
|
42
|
+
if (isComponentMissingComponent(Component))
|
|
43
|
+
return _jsx(Component, {});
|
|
44
|
+
// Ensure we have the data the Component requested
|
|
45
|
+
const data = await getContent(graphClient, contentLink, Component, fragmentData, noDataLoad);
|
|
46
|
+
// Output the actual component
|
|
47
|
+
return _jsx(Component, { contentLink: contentLink, data: data, inEditMode: ctx.inEditMode, layoutProps: layoutProps, children: children });
|
|
48
|
+
}
|
|
49
|
+
export default CmsContent;
|
|
50
|
+
//# sourceMappingURL=rsc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rsc.js","sourceRoot":"","sources":["../../../src/components/cms-content/rsc.tsx"],"names":[],"mappings":";AAEA,OAAO,cAAc,MAAM,uBAAuB,CAAA;AAClD,OAAO,UAAU,MAAM,kBAAkB,CAAA;AACzC,OAAO,EAAE,QAAQ,EAAE,oBAAoB,EAAE,mBAAmB,EAAoB,MAAM,iCAAiC,CAAA;AACvH,OAAO,gBAAgB,EAAE,EAAE,2BAA2B,EAAE,MAAM,wBAAwB,CAAA;AACtF,OAAO,kBAAkB,MAAM,2BAA2B,CAAA;AAI1D;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAAuB;AACnD,iBAAiB;AACjB,WAAW,EACX,iBAAiB,EACjB,WAAW,EAAE,cAAc,EAC3B,QAAQ,EACR,YAAY,EACZ,WAAW,EACX,UAAU,EACV,OAAO,EACP,GAAG,EAC6B;IAEhC,kBAAkB;IAClB,MAAM,WAAW,GAAG,GAAG,CAAC,MAAM,CAAA;IAE9B,4BAA4B;IAC5B,MAAM,WAAW,GAAG,oBAAoB,CAAC,cAAc,CAAC,CAAA;IAExD,iCAAiC;IACjC,IAAI,aAAa,GAAG,kBAAkB,CAAC,WAAW,EAAE,YAAY,CAAC,CAAA;IACjE,IAAI,CAAC,aAAa,EAAE,CAAC;QACjB,IAAI,CAAC,WAAW,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,kFAAkF,CAAC,CAAA;YACjG,OAAM;QACV,CAAC;QACD,IAAI,CAAC,WAAW,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,uEAAuE,CAAC,CAAA;YACtF,OAAM;QACV,CAAC;QACD,aAAa,GAAG,MAAM,cAAc,CAAC,WAAW,EAAE,WAAW,CAAC,CAAA;IAClE,CAAC;IAED,qCAAqC;IACrC,IAAI,WAAW,EAAE,KAAK,EAAE,CAAC;QACrB,MAAM,IAAI,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAA;QAC/E,OAAO,CAAC,GAAG,CAAC,mBAAoB,IAAK,qCAAsC,mBAAmB,CAAC,WAAW,CAAE,YAAa,aAAa,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,SAAS,EAAE,CAAC,CAAA;QACjK,IAAI,CAAC,GAAG,CAAC,UAAU,IAAI,GAAG,CAAC,aAAa,CAAC,IAAI,WAAW,CAAC,eAAe,IAAI,QAAQ,CAAC,MAAM;YACvF,OAAO,CAAC,IAAI,CAAC,mBAAoB,IAAK,iIAAiI,CAAC,CAAA;IAChL,CAAC;IAED,kDAAkD;IAClD,MAAM,SAAS,GAAG,gBAAgB,CAAC,aAAa,EAAE,iBAAiB,EAAE,OAAO,EAAE,GAAG,CAAC,CAAA;IAClF,IAAI,2BAA2B,CAAC,SAAS,CAAC;QACtC,OAAO,KAAC,SAAS,KAAG,CAAA;IAExB,kDAAkD;IAClD,MAAM,IAAI,GAAG,MAAM,UAAU,CAAC,WAAW,EAAE,WAAW,EAAE,SAAS,EAAE,YAAY,EAAE,UAAU,CAAC,CAAA;IAE5F,8BAA8B;IAC9B,OAAO,KAAC,SAAS,IAAC,WAAW,EAAG,WAA0B,EAAG,IAAI,EAAG,IAAI,EAAG,UAAU,EAAG,GAAG,CAAC,UAAU,EAAG,WAAW,EAAG,WAAW,YAAK,QAAQ,GAAa,CAAA;AAChK,CAAC;AAED,eAAe,UAAU,CAAA"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { type PropsWithChildren, type ComponentType, type ComponentProps, type ReactNode } from 'react';
|
|
2
|
+
import type { CmsComponent } from '../../types.js';
|
|
3
|
+
import type { PropsWithContext } from "../../context/types.js";
|
|
4
|
+
import type { ContentLinkWithLocale, InlineContentLinkWithLocale } from "@remkoj/optimizely-graph-client";
|
|
5
|
+
export type CmsContentProps<LocalesType = string> = PropsWithChildren<{
|
|
6
|
+
/**
|
|
7
|
+
* The content type to render
|
|
8
|
+
*/
|
|
9
|
+
contentType?: string[];
|
|
10
|
+
/**
|
|
11
|
+
* The content link to render
|
|
12
|
+
*/
|
|
13
|
+
contentLink: ContentLinkWithLocale<LocalesType> | InlineContentLinkWithLocale<LocalesType>;
|
|
14
|
+
/**
|
|
15
|
+
* The initial, pre-loaded data. If set this will be used instead of having the
|
|
16
|
+
* component fetching its' own data. So be sure that this leverages the fragment
|
|
17
|
+
* specified by the component.
|
|
18
|
+
*
|
|
19
|
+
* It will filter out the fiels from the IContentData fragment, to determine if
|
|
20
|
+
* data has been provided.
|
|
21
|
+
*/
|
|
22
|
+
fragmentData?: {
|
|
23
|
+
[fieldname: string]: any;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* The native key to use when the element is part of an array
|
|
27
|
+
*/
|
|
28
|
+
key?: string;
|
|
29
|
+
/**
|
|
30
|
+
* The prefix to apply to the content type, to allow loading of different templates based
|
|
31
|
+
* upon location of usage. If set and the content type already starts with this prefix,
|
|
32
|
+
* it will not be applied.
|
|
33
|
+
*/
|
|
34
|
+
contentTypePrefix?: string;
|
|
35
|
+
/**
|
|
36
|
+
* The content type variant to load. This allows the loading of a variant (e.g. postfix) of
|
|
37
|
+
* the content type
|
|
38
|
+
*/
|
|
39
|
+
variant?: string;
|
|
40
|
+
/**
|
|
41
|
+
* Any layout properties inferred from the context
|
|
42
|
+
*/
|
|
43
|
+
layoutProps?: Record<string, any>;
|
|
44
|
+
/**
|
|
45
|
+
* When set to true, this will prevent the CmsContent component to try loading content from
|
|
46
|
+
* the store
|
|
47
|
+
*/
|
|
48
|
+
noDataLoad?: boolean;
|
|
49
|
+
}>;
|
|
50
|
+
export type PropsWithCmsContent<T = any> = T & {
|
|
51
|
+
cmsContent: CmsContentComponent;
|
|
52
|
+
};
|
|
53
|
+
export type BaseCmsContentProps<LocalesType = string> = PropsWithContext<CmsContentProps<LocalesType>>;
|
|
54
|
+
export type CmsContentComponent = <LocalesType = string>(props: CmsContentProps<LocalesType>) => ReactNode;
|
|
55
|
+
export type CmsContentBaseComponent = <LocalesType = string>(props: BaseCmsContentProps<LocalesType>) => ReactNode;
|
|
56
|
+
export type CmsComponentProps = ComponentProps<CmsComponent> & {
|
|
57
|
+
[key: string]: any;
|
|
58
|
+
};
|
|
59
|
+
export type EnhancedCmsComponent = ComponentType<CmsComponentProps>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/components/cms-content/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { type ComponentType } from "react";
|
|
2
|
+
import { type CmsContentComponent, type PropsWithCmsContent } from "./types.js";
|
|
3
|
+
export declare function cmsContentAware<P = any>(component: ComponentType<PropsWithCmsContent<P>>, cmsContentComponent: CmsContentComponent): ComponentType<P>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
export function cmsContentAware(component, cmsContentComponent) {
|
|
3
|
+
const BaseComponent = component;
|
|
4
|
+
return (props) => _jsx(BaseComponent, { cmsContent: cmsContentComponent, ...props });
|
|
5
|
+
}
|
|
6
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/components/cms-content/utils.tsx"],"names":[],"mappings":";AAGA,MAAM,UAAU,eAAe,CAAU,SAAgD,EAAE,mBAAwC;IAE/H,MAAM,aAAa,GAAG,SAAS,CAAA;IAC/B,OAAO,CAAC,KAAQ,EAAE,EAAE,CAAC,KAAC,aAAa,IAAC,UAAU,EAAE,mBAAmB,KAAO,KAAK,GAAK,CAAA;AACxF,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ElementType } from '../type-utils.js';
|
|
2
|
+
import type { BaseCmsContentAreaProps } from './types.js';
|
|
3
|
+
export type { CmsContentAreaClassMapper, CmsContentAreaProps, ContentAreaItemDefinition, CmsContentAreaComponent } from './types.js';
|
|
4
|
+
/**
|
|
5
|
+
* React server component to render a content area
|
|
6
|
+
*
|
|
7
|
+
* @param param0 The content area information for rendering
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
10
|
+
export declare const CmsContentArea: <T extends ElementType = "div", I extends ElementType = "div">({ items, classMapper, className, fieldName, as: elementType, itemsProperty, itemWrapper, useSuspense, fallback, noWrapper: noContentAreaContainer, variant, ctx, cmsContent: CmsContent, ...additionalProps }: BaseCmsContentAreaProps<T, I>) => JSX.Element;
|
|
11
|
+
/**
|
|
12
|
+
*
|
|
13
|
+
* @param items
|
|
14
|
+
* @param locale
|
|
15
|
+
* @returns
|
|
16
|
+
*/
|
|
17
|
+
export default CmsContentArea;
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import 'server-only';
|
|
3
|
-
import CmsContent from './cms-content.js';
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
4
2
|
import * as Utils from '../../utilities.js';
|
|
5
3
|
import * as Errors from '../../errors.js';
|
|
6
|
-
import createClient from '@remkoj/optimizely-graph-client';
|
|
7
4
|
import { normalizeContentLinkWithLocale, contentLinkToString } from '@remkoj/optimizely-graph-client/utils';
|
|
8
|
-
import
|
|
5
|
+
import { Suspense } from 'react';
|
|
9
6
|
//#endregion
|
|
10
7
|
/**
|
|
11
8
|
* React server component to render a content area
|
|
@@ -13,25 +10,10 @@ import getServerContext from '../context.js';
|
|
|
13
10
|
* @param param0 The content area information for rendering
|
|
14
11
|
* @returns
|
|
15
12
|
*/
|
|
16
|
-
export const CmsContentArea =
|
|
17
|
-
const
|
|
18
|
-
if (context.isDebugOrDevelopment && !context.client)
|
|
19
|
-
console.warn(`🟠 [CmsContentArea] No Content Graph client provided for ${fieldName ?? 'CmsContentArea'}, this will cause problems with edit mode!`);
|
|
20
|
-
// Parse & prepare props
|
|
21
|
-
const { inEditMode, factory, locale: ctxLocale } = context;
|
|
22
|
-
const gqlClient = context.client ?? createClient();
|
|
23
|
-
// Determine locale
|
|
24
|
-
const locale = _locale ?? ctxLocale;
|
|
25
|
-
if (context.isDebug && locale == _locale && locale != ctxLocale) {
|
|
26
|
-
console.warn(`🟠 [CmsContentArea] The Context Locale for ContentArea ${fieldName ?? 'CmsContentArea'}, was overridden. Context Locale ${ctxLocale}, current locale ${locale}`);
|
|
27
|
-
}
|
|
28
|
-
if (!locale) {
|
|
29
|
-
console.error(`🔴 [CmsContentArea] No locale set on the ServerContext, which is required to make the ContentArea${fieldName ? ' ' + fieldName : ''} render its content`);
|
|
30
|
-
return _jsx(_Fragment, {});
|
|
31
|
-
}
|
|
13
|
+
export const CmsContentArea = ({ items = [], classMapper, className, fieldName, as: elementType, itemsProperty, itemWrapper, useSuspense = false, fallback, noWrapper: noContentAreaContainer = false, variant, ctx, cmsContent: CmsContent, ...additionalProps }) => {
|
|
14
|
+
const { inEditMode = false } = ctx;
|
|
32
15
|
// Convert the items to a list of enriched content types and filter out items cannot be loaded
|
|
33
|
-
const
|
|
34
|
-
const componentData = await Promise.all(actualItems.map(async (item, idx) => {
|
|
16
|
+
const componentData = (items || []).filter(forValidContentAreaItems).map((item, idx) => {
|
|
35
17
|
// Prepare data from received content area format
|
|
36
18
|
const contentLink = normalizeContentLinkWithLocale(item._metadata);
|
|
37
19
|
if (!contentLink)
|
|
@@ -39,31 +21,40 @@ export const CmsContentArea = async ({ items, classMapper, className, fieldName,
|
|
|
39
21
|
const contentType = Utils.normalizeContentType(item._metadata.types);
|
|
40
22
|
const fragmentData = item;
|
|
41
23
|
// Read element wrapper configuration
|
|
42
|
-
const { as:
|
|
43
|
-
|
|
44
|
-
|
|
24
|
+
const { as: ContentAreaItemContainer = "div", className: contentItemBaseClassName, itemsProperty: childrenTarget = "children", noWrapper: noContentAreaItemContainer = false, ...contentItemElementProps } = itemWrapper ?? {};
|
|
25
|
+
const contentAreaItemKey = `ContentAreaItem-${idx}-${contentLinkToString(contentLink)}`;
|
|
26
|
+
// Output if no wrapper is required
|
|
27
|
+
if (noContentAreaItemContainer)
|
|
28
|
+
return useSuspense ?
|
|
29
|
+
_jsx(Suspense, { fallback: fallback, children: _jsx(CmsContent, { contentLink: contentLink, contentType: contentType, fragmentData: fragmentData, contentTypePrefix: "Component", variant: variant }) }, contentAreaItemKey) :
|
|
30
|
+
_jsx(CmsContent, { contentLink: contentLink, contentType: contentType, fragmentData: fragmentData, contentTypePrefix: "Component", variant: variant }, contentAreaItemKey);
|
|
31
|
+
// Buld wrapper configuration
|
|
45
32
|
const contentAreaItemContainerProps = {
|
|
46
33
|
className: `opti-content-area-item opti-content-area-item-${idx}${contentItemBaseClassName ? ' ' + contentItemBaseClassName : ''} ${classMapper ? classMapper(item.displayOption ?? 'default', contentType ?? null, idx) : ""}`,
|
|
47
34
|
"data-epi-block-id": inEditMode && fieldName ? Utils.getContentEditId(contentLink) || undefined : undefined,
|
|
48
35
|
"data-displayoption": item.displayOption || undefined,
|
|
49
36
|
"data-tag": item.tag || undefined,
|
|
37
|
+
"data-component": contentType?.at(0),
|
|
50
38
|
...contentItemElementProps
|
|
51
39
|
};
|
|
52
|
-
const contentAraeItemContent =
|
|
40
|
+
const contentAraeItemContent = useSuspense ?
|
|
41
|
+
_jsx(Suspense, { fallback: fallback, children: _jsx(CmsContent, { contentLink: contentLink, contentType: contentType, fragmentData: fragmentData, contentTypePrefix: "Component", variant: variant }) }) :
|
|
42
|
+
_jsx(CmsContent, { contentLink: contentLink, contentType: contentType, fragmentData: fragmentData, contentTypePrefix: "Component", variant: variant });
|
|
53
43
|
// Inject the element into the wrapper
|
|
54
|
-
const childrenTarget = contentItemTarget || "children";
|
|
55
44
|
let contentAreaItemContainerChildren = undefined;
|
|
56
45
|
if (childrenTarget == "children")
|
|
57
46
|
contentAreaItemContainerChildren = contentAraeItemContent;
|
|
58
47
|
else
|
|
59
48
|
contentAreaItemContainerProps[childrenTarget] = contentAraeItemContent;
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
49
|
+
return _jsx(ContentAreaItemContainer, { ...contentAreaItemContainerProps, children: contentAreaItemContainerChildren }, contentAreaItemKey);
|
|
50
|
+
});
|
|
51
|
+
if (noContentAreaContainer)
|
|
52
|
+
return _jsx(_Fragment, { children: componentData });
|
|
63
53
|
// Build container element
|
|
64
54
|
const contentAreaContainerProps = {
|
|
65
55
|
className: `opti-content-area ${Array.isArray(className) ? className.join(' ') : (className ?? '')}`.trim(),
|
|
66
56
|
"data-epi-edit": inEditMode && fieldName ? fieldName : undefined,
|
|
57
|
+
"data-component": "ContentArea",
|
|
67
58
|
...additionalProps
|
|
68
59
|
};
|
|
69
60
|
const contentAreaContainerChildrenTarget = itemsProperty ?? "children";
|
|
@@ -78,19 +69,28 @@ export const CmsContentArea = async ({ items, classMapper, className, fieldName,
|
|
|
78
69
|
function forValidContentAreaItems(itm) {
|
|
79
70
|
return typeof (itm) == 'object' && itm != null && typeof (itm._metadata) == 'object' && itm._metadata != null;
|
|
80
71
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
72
|
+
/**
|
|
73
|
+
*
|
|
74
|
+
* @param items
|
|
75
|
+
* @param locale
|
|
76
|
+
* @returns
|
|
77
|
+
*/
|
|
78
|
+
/*export function processContentAreaItems( items?: (ContentAreaItemDefinition | null)[] | null, locale?: string) : JSX.Element[]
|
|
79
|
+
{
|
|
80
|
+
const actualItems = (items ?? []).filter(Utils.isNotNullOrUndefined)
|
|
81
|
+
return actualItems.map((item, idx) => {
|
|
84
82
|
// Prepare data from received content area format
|
|
85
|
-
const contentLink = normalizeContentLinkWithLocale({ ...item.item, locale: locale })
|
|
83
|
+
const contentLink = normalizeContentLinkWithLocale({ ...item.item, locale: locale })
|
|
86
84
|
if (!contentLink)
|
|
87
|
-
throw new Errors.InvalidContentLinkError({ ...item.item, locale: locale })
|
|
88
|
-
const contentType = Utils.normalizeContentType(item.item?.data?.contentType)
|
|
89
|
-
const fragmentData = item.item?.data || undefined
|
|
90
|
-
const guidValue = (item.item?.guidValue ?? "00000000-0000-0000-0000-000000000000")
|
|
85
|
+
throw new Errors.InvalidContentLinkError({ ...item.item, locale: locale })
|
|
86
|
+
const contentType = Utils.normalizeContentType(item.item?.data?.contentType)
|
|
87
|
+
const fragmentData = item.item?.data || undefined
|
|
88
|
+
const guidValue = (item.item?.guidValue ?? "00000000-0000-0000-0000-000000000000")+"::"+idx
|
|
89
|
+
|
|
91
90
|
// Build output
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}
|
|
91
|
+
const content : JSX.Element = <CmsContent contentLink={ contentLink } contentType={ contentType } fragmentData={ fragmentData } key={ guidValue } />
|
|
92
|
+
return content
|
|
93
|
+
})
|
|
94
|
+
}*/
|
|
95
95
|
export default CmsContentArea;
|
|
96
|
-
//# sourceMappingURL=
|
|
96
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/cms-content-area/index.tsx"],"names":[],"mappings":";AACA,OAAO,KAAK,KAAK,MAAM,oBAAoB,CAAA;AAC3C,OAAO,KAAK,MAAM,MAAM,iBAAiB,CAAA;AACzC,OAAO,EAAE,8BAA8B,EAAE,mBAAmB,EAAE,MAAM,uCAAuC,CAAA;AAE3G,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAIhC,YAAY;AAEZ;;;;;GAKG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAA+D,EACzF,KAAK,GAAG,EAAE,EACV,WAAW,EACX,SAAS,EACT,SAAS,EACT,EAAE,EAAE,WAAW,EACf,aAAa,EACb,WAAW,EACX,WAAW,GAAG,KAAK,EACnB,QAAQ,EACR,SAAS,EAAE,sBAAsB,GAAG,KAAK,EACzC,OAAO,EAEP,GAAG,EACH,UAAU,EAAE,UAAU,E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;GAgBG;AAEH,eAAe,cAAc,CAAA"}
|
|
@@ -1,74 +1,8 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
1
|
+
import type { ReactNode, SuspenseProps } from "react";
|
|
2
|
+
import type { PropsWithContext } from "../../context/types.js";
|
|
3
|
+
import type { PropsWithCmsContent } from "../cms-content/types.js";
|
|
4
|
+
import type { ContentType } from "../../types.js";
|
|
3
5
|
import type { ElementChildrenProps, ElementProps, ElementType, PropTypeIfPropExists, MayBeArray, TypeIfPropExists } from '../type-utils.js';
|
|
4
|
-
import type { IOptiGraphClient, ContentLinkWithLocale, InlineContentLinkWithLocale } from "@remkoj/optimizely-graph-client";
|
|
5
|
-
export type CmsContentProps<LocalesType = string> = PropsWithChildren<{
|
|
6
|
-
/**
|
|
7
|
-
* The content type to render
|
|
8
|
-
*/
|
|
9
|
-
contentType?: string[];
|
|
10
|
-
/**
|
|
11
|
-
* The content link to render
|
|
12
|
-
*/
|
|
13
|
-
contentLink: ContentLinkWithLocale<LocalesType> | InlineContentLinkWithLocale<LocalesType>;
|
|
14
|
-
/**
|
|
15
|
-
* The initial, pre-loaded data. If set this will be used instead of having the
|
|
16
|
-
* component fetching its' own data. So be sure that this leverages the fragment
|
|
17
|
-
* specified by the component.
|
|
18
|
-
*
|
|
19
|
-
* It will filter out the fiels from the IContentData fragment, to determine if
|
|
20
|
-
* data has been provided.
|
|
21
|
-
*/
|
|
22
|
-
fragmentData?: {
|
|
23
|
-
[fieldname: string]: any;
|
|
24
|
-
};
|
|
25
|
-
/**
|
|
26
|
-
* The native key to use when the element is part of an array
|
|
27
|
-
*/
|
|
28
|
-
key?: string;
|
|
29
|
-
/**
|
|
30
|
-
* If enabled, it will flag all rendering to be inclusive of the Optimizely Edit mode
|
|
31
|
-
* attributes for On Page Editing
|
|
32
|
-
*
|
|
33
|
-
* @deprecated Will be retrieved from the ServerContext
|
|
34
|
-
*/
|
|
35
|
-
inEditMode?: boolean;
|
|
36
|
-
/**
|
|
37
|
-
* The Optimizely Graph client to use, it will use a new instance if none is provided,
|
|
38
|
-
* the new instance will always use the SingleKey i.e. thus not load edit mode content
|
|
39
|
-
*
|
|
40
|
-
* @deprecated Will be retrieved from the ServerContext
|
|
41
|
-
*/
|
|
42
|
-
client?: IOptiGraphClient;
|
|
43
|
-
/**
|
|
44
|
-
* The component factory to use, it will use the default instance if not provided
|
|
45
|
-
*
|
|
46
|
-
* @deprecated Will be retrieved from the ServerContext
|
|
47
|
-
*/
|
|
48
|
-
factory?: ComponentFactory;
|
|
49
|
-
/**
|
|
50
|
-
* If enabled any warnings intended for an editor will be shown, even if "inEditMode"
|
|
51
|
-
* is false.
|
|
52
|
-
*
|
|
53
|
-
* @deprecated Will be retrieved from the ServerContext
|
|
54
|
-
*/
|
|
55
|
-
outputEditorWarning?: boolean;
|
|
56
|
-
/**
|
|
57
|
-
* The prefix to apply to the content type, to allow loading of different templates based
|
|
58
|
-
* upon location of usage. If set and the content type already starts with this prefix,
|
|
59
|
-
* it will not be applied.
|
|
60
|
-
*/
|
|
61
|
-
contentTypePrefix?: string;
|
|
62
|
-
/**
|
|
63
|
-
* Any layout properties inferred from the context
|
|
64
|
-
*/
|
|
65
|
-
layoutProps?: Record<string, any>;
|
|
66
|
-
/**
|
|
67
|
-
* When set to true, this will prevent the CmsContent component to try loading content from
|
|
68
|
-
* the store
|
|
69
|
-
*/
|
|
70
|
-
noDataLoad?: boolean;
|
|
71
|
-
}>;
|
|
72
6
|
export type ContentAreaItemDefinition = {
|
|
73
7
|
__typename?: string | null;
|
|
74
8
|
_type?: string | null;
|
|
@@ -116,6 +50,11 @@ export type CmsContentAreaProps<T extends ElementType, CT extends ElementType> =
|
|
|
116
50
|
* The CSS Class to apply to the content area container
|
|
117
51
|
*/
|
|
118
52
|
className?: MayBeArray<PropTypeIfPropExists<T, "className">>;
|
|
53
|
+
/**
|
|
54
|
+
* Whether or not a suspense must be applied around each item of the
|
|
55
|
+
* ContentArea to allow dynamic content within the ContentArea items.
|
|
56
|
+
*/
|
|
57
|
+
useSuspense?: boolean;
|
|
119
58
|
/**
|
|
120
59
|
* The fallback component to use as suspense boundary
|
|
121
60
|
*/
|
|
@@ -129,11 +68,30 @@ export type CmsContentAreaProps<T extends ElementType, CT extends ElementType> =
|
|
|
129
68
|
* The HTML element, or React Component to use to render the Content Area Container
|
|
130
69
|
*/
|
|
131
70
|
as?: T;
|
|
71
|
+
/**
|
|
72
|
+
* If set to true, there will be no wrapping element around the
|
|
73
|
+
* items in the Content Area. Setting this to `true` ignores
|
|
74
|
+
*/
|
|
75
|
+
noWrapper?: boolean;
|
|
76
|
+
/**
|
|
77
|
+
* Allows requesting of specific template variant, to accomodate different
|
|
78
|
+
* renditions, without changing the main path of the component.
|
|
79
|
+
*/
|
|
80
|
+
variant?: string;
|
|
81
|
+
/**
|
|
82
|
+
* Configure the wrapper around each item within the ContentArea
|
|
83
|
+
*/
|
|
132
84
|
itemWrapper?: ({
|
|
133
85
|
/**
|
|
134
86
|
* Override the element type used to wrap the CMS Content Item
|
|
135
87
|
*/
|
|
136
88
|
as?: CT;
|
|
89
|
+
/**
|
|
90
|
+
* If set to true, there will be no wrapping element around the
|
|
91
|
+
* CmsContent used to render the item. Setting this to `true`
|
|
92
|
+
* ignores all other `itemWrapper` properties.
|
|
93
|
+
*/
|
|
94
|
+
noWrapper?: boolean;
|
|
137
95
|
/**
|
|
138
96
|
* The CSS Class to apply to the content area item wrapper
|
|
139
97
|
*/
|
|
@@ -153,30 +111,6 @@ export type CmsContentAreaProps<T extends ElementType, CT extends ElementType> =
|
|
|
153
111
|
*/
|
|
154
112
|
itemsProperty: ElementChildrenProps<CT>;
|
|
155
113
|
}) & Omit<Omit<ElementProps<CT>, "className" | "data-epi-block-id" | "data-displayoption" | "data-tag">, ElementChildrenProps<CT>>);
|
|
156
|
-
/**
|
|
157
|
-
* Ignored if provided
|
|
158
|
-
*
|
|
159
|
-
* @deprecated The ServerContext is used to access the current locale
|
|
160
|
-
*/
|
|
161
|
-
locale?: string;
|
|
162
|
-
/**
|
|
163
|
-
* Ignored if provided
|
|
164
|
-
*
|
|
165
|
-
* @deprecated The ServerContext is used to access the current edit mode status
|
|
166
|
-
*/
|
|
167
|
-
inEditMode?: boolean;
|
|
168
|
-
/**
|
|
169
|
-
* Ignored if provided
|
|
170
|
-
*
|
|
171
|
-
* @deprecated The ServerContext is used to access the current Optimizely Graph Client
|
|
172
|
-
*/
|
|
173
|
-
client?: IOptiGraphClient;
|
|
174
|
-
/**
|
|
175
|
-
* Ignored if provided
|
|
176
|
-
*
|
|
177
|
-
* @deprecated The ServerContext is used to access the current Component Factory
|
|
178
|
-
*/
|
|
179
|
-
factory?: ComponentFactory;
|
|
180
114
|
} & Omit<Omit<ElementProps<T>, "className" | "data-epi-edit">, ElementChildrenProps<T>> & ("children" extends ElementChildrenProps<T> ? {
|
|
181
115
|
/**
|
|
182
116
|
* The property of the component set for the "as" property of the Content Area which
|
|
@@ -193,3 +127,6 @@ export type CmsContentAreaProps<T extends ElementType, CT extends ElementType> =
|
|
|
193
127
|
itemsProperty: ElementChildrenProps<T>;
|
|
194
128
|
});
|
|
195
129
|
export type CmsContentAreaClassMapper = (displayOption: string, contentType: ContentType | null, index: number) => string;
|
|
130
|
+
export type BaseCmsContentAreaProps<T extends ElementType, CT extends ElementType> = PropsWithCmsContent<PropsWithContext<CmsContentAreaProps<T, CT>>>;
|
|
131
|
+
export type CmsContentAreaBaseComponent = <T extends ElementType, CT extends ElementType>(props: BaseCmsContentAreaProps<T, CT>) => ReactNode;
|
|
132
|
+
export type CmsContentAreaComponent = <T extends ElementType, CT extends ElementType>(props: CmsContentAreaProps<T, CT>) => ReactNode;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/components/cms-content-area/types.ts"],"names":[],"mappings":""}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import '
|
|
2
|
-
import {
|
|
1
|
+
import { type ComponentProps, type ComponentType as ReactComponentType, type ExoticComponent as ReactExoticComponent, type ReactNode } from 'react';
|
|
2
|
+
import { PropsWithContext } from '../../context/types.js';
|
|
3
3
|
export type EditableComponentType = (ReactComponentType<any>) | (ReactExoticComponent<any>) | (keyof JSX.IntrinsicElements);
|
|
4
4
|
export type EditableComponentProps<FT extends EditableComponentType> = FT extends keyof JSX.IntrinsicElements ? JSX.IntrinsicElements[FT] : ComponentProps<FT>;
|
|
5
5
|
export type CmsEditableProps<FT extends EditableComponentType> = {
|
|
@@ -11,6 +11,8 @@ export type CmsEditableProps<FT extends EditableComponentType> = {
|
|
|
11
11
|
cmsId?: never;
|
|
12
12
|
cmsFieldName?: string | null;
|
|
13
13
|
}) & EditableComponentProps<FT>;
|
|
14
|
+
export type CmsEditableComponent = <CT extends EditableComponentType>(props: CmsEditableProps<CT>) => ReactNode;
|
|
15
|
+
export type CmsEditableBaseComponent = <CT extends EditableComponentType>(props: PropsWithContext<CmsEditableProps<CT>>) => ReactNode;
|
|
14
16
|
/**
|
|
15
17
|
* Server side wrapper to create HTML elements that include the needed
|
|
16
18
|
* data-epi- properties to render the edit mode markers
|
|
@@ -18,5 +20,5 @@ export type CmsEditableProps<FT extends EditableComponentType> = {
|
|
|
18
20
|
* @param param0 The HTML element with the simple properties
|
|
19
21
|
* @returns
|
|
20
22
|
*/
|
|
21
|
-
export declare const CmsEditable:
|
|
23
|
+
export declare const CmsEditable: CmsEditableBaseComponent;
|
|
22
24
|
export default CmsEditable;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* Server side wrapper to create HTML elements that include the needed
|
|
4
|
+
* data-epi- properties to render the edit mode markers
|
|
5
|
+
*
|
|
6
|
+
* @param param0 The HTML element with the simple properties
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
//@ts-expect-error Typescript doesn't understand the property type :'(
|
|
10
|
+
export const CmsEditable = ({ ctx, as: DefaultElement = 'div', cmsId, cmsFieldName, children, key, ...props }) => {
|
|
11
|
+
const { inEditMode } = ctx;
|
|
12
|
+
return _jsx(DefaultElement, { ...props, "data-epi-block-id": inEditMode ? cmsId ?? undefined : undefined, "data-epi-property-name": inEditMode ? cmsFieldName ?? undefined : undefined, children: children });
|
|
13
|
+
};
|
|
14
|
+
export default CmsEditable;
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/cms-editable/index.tsx"],"names":[],"mappings":";AAiBA;;;;;;GAMG;AACH,sEAAsE;AACtE,MAAM,CAAC,MAAM,WAAW,GAA8B,CAA2C,EAAE,GAAG,EAAE,EAAE,EAAE,cAAc,GAAG,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,KAAK,EAA0C,EAAE,EAAE;IAE1N,MAAM,EAAE,UAAU,EAAE,GAAG,GAAG,CAAA;IAC1B,OAAO,KAAC,cAAc,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,GAAmB,CAAA;AACnN,CAAC,CAAA;AAED,eAAe,WAAW,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/cms-styles/index.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"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type FunctionComponent, type PropsWithChildren } from "react";
|
|
2
|
+
import { ComponentTypeDictionary } from "../../factory/types.js";
|
|
3
|
+
import type { TextNode, TypedNode } from "./types.js";
|
|
4
|
+
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] & {
|
|
5
|
+
node: TypedNode;
|
|
6
|
+
}>) => import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
export declare const DefaultTextNode: FunctionComponent<{
|
|
8
|
+
node: TextNode;
|
|
9
|
+
}>;
|
|
10
|
+
/**
|
|
11
|
+
* A default component dictionary that allows to serialize the structured HTML
|
|
12
|
+
* into React, using the component library shared across the react SDK.
|
|
13
|
+
*/
|
|
14
|
+
export declare const DefaultComponents: ComponentTypeDictionary;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { decodeHTML } from 'entities';
|
|
3
|
+
//#region HTML Components
|
|
4
|
+
export function createHtmlComponent(element, ignoreChildren = false, defaultProps) {
|
|
5
|
+
const HtmlElement = element;
|
|
6
|
+
const reservedProps = ['url', 'class', 'children', 'type'];
|
|
7
|
+
const component = ({ children, node, ...props }) => {
|
|
8
|
+
const nodeProps = {};
|
|
9
|
+
const renderProps = Object.getOwnPropertyNames(node);
|
|
10
|
+
renderProps.filter(x => !reservedProps.includes(x)).forEach(x => nodeProps[x] = node[x]);
|
|
11
|
+
if (renderProps.includes('class'))
|
|
12
|
+
nodeProps['className'] = node['class'];
|
|
13
|
+
if (renderProps.includes('url')) {
|
|
14
|
+
switch (node.type) {
|
|
15
|
+
case 'link':
|
|
16
|
+
nodeProps['href'] = node['url'];
|
|
17
|
+
break;
|
|
18
|
+
case 'image':
|
|
19
|
+
nodeProps['src'] = node['url'];
|
|
20
|
+
break;
|
|
21
|
+
default:
|
|
22
|
+
nodeProps['data-url'] = node['url'];
|
|
23
|
+
break;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return ignoreChildren ? _jsx(HtmlElement, { ...defaultProps, ...nodeProps, ...props }) : _jsx(HtmlElement, { ...defaultProps, ...nodeProps, ...props, children: children });
|
|
27
|
+
};
|
|
28
|
+
return component;
|
|
29
|
+
}
|
|
30
|
+
export const DefaultTextNode = ({ node }) => {
|
|
31
|
+
if (node.bold)
|
|
32
|
+
return _jsx("strong", { children: decodeHTML(node.text) });
|
|
33
|
+
if (node.italic)
|
|
34
|
+
return _jsx("em", { children: decodeHTML(node.text) });
|
|
35
|
+
const unsupportedProps = Object.getOwnPropertyNames(node).filter(x => x != 'text');
|
|
36
|
+
if (unsupportedProps.length > 0 && process.env.NODE_ENV != 'production')
|
|
37
|
+
console.warn('🟠 [Rich Text] Text node with unsupported additional properties:', unsupportedProps.join(', '));
|
|
38
|
+
return decodeHTML(node.text);
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* A default component dictionary that allows to serialize the structured HTML
|
|
42
|
+
* into React, using the component library shared across the react SDK.
|
|
43
|
+
*/
|
|
44
|
+
export const DefaultComponents = [
|
|
45
|
+
{ type: 'RichText/richText', component: createHtmlComponent("div", false, { className: "cms:rich-text" }) },
|
|
46
|
+
{ type: 'RichText/paragraph', component: createHtmlComponent("p") },
|
|
47
|
+
{ type: 'RichText/span', component: createHtmlComponent("span") },
|
|
48
|
+
{ type: 'RichText/div', component: createHtmlComponent("div") },
|
|
49
|
+
{ type: 'RichText/heading-one', component: createHtmlComponent("h1") },
|
|
50
|
+
{ type: 'RichText/heading-two', component: createHtmlComponent("h2") },
|
|
51
|
+
{ type: 'RichText/heading-three', component: createHtmlComponent("h3") },
|
|
52
|
+
{ type: 'RichText/heading-four', component: createHtmlComponent("h4") },
|
|
53
|
+
{ type: 'RichText/heading-five', component: createHtmlComponent("h5") },
|
|
54
|
+
{ type: 'RichText/heading-six', component: createHtmlComponent("h6") },
|
|
55
|
+
{ type: 'RichText/link', component: createHtmlComponent("a") },
|
|
56
|
+
{ type: 'RichText/image', component: createHtmlComponent("img", true) },
|
|
57
|
+
{ type: 'RichText/text', component: DefaultTextNode },
|
|
58
|
+
{ type: 'RichText/br', component: createHtmlComponent("br", true) },
|
|
59
|
+
{ type: 'RichText/bulleted-list', component: createHtmlComponent("ul") },
|
|
60
|
+
{ type: 'RichText/numbered-list', component: createHtmlComponent("ol") },
|
|
61
|
+
{ type: 'RichText/list-item', component: createHtmlComponent("li") }
|
|
62
|
+
];
|
|
63
|
+
//# sourceMappingURL=components.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"components.js","sourceRoot":"","sources":["../../../src/components/rich-text/components.tsx"],"names":[],"mappings":";AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEtC,yBAAyB;AACzB,MAAM,UAAU,mBAAmB,CAAwC,OAAU,EAAE,iBAA0B,KAAK,EAAE,YAA+D;IAEnL,MAAM,WAAW,GAAG,OAAiB,CAAA;IACrC,MAAM,aAAa,GAAG,CAAC,KAAK,EAAC,OAAO,EAAC,UAAU,EAAC,MAAM,CAAC,CAAA;IACvD,MAAM,SAAS,GAAG,CAAC,EAAE,QAAQ,EAAE,I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