@remkoj/optimizely-cms-react 4.3.1 → 5.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-content/get-content.js +23 -21
- package/dist/components/cms-content/get-content.js.map +1 -1
- package/dist/components/cms-content/resolve-component.d.ts +4 -4
- package/dist/components/cms-content/resolve-component.js +14 -14
- package/dist/components/cms-content/resolve-component.js.map +1 -1
- package/dist/components/cms-content/rsc.d.ts +2 -2
- package/dist/components/cms-content/rsc.js +14 -7
- package/dist/components/cms-content/rsc.js.map +1 -1
- package/dist/components/cms-content/types.d.ts +11 -4
- package/dist/components/cms-content-area/index.d.ts +3 -10
- package/dist/components/cms-content-area/index.js +35 -51
- package/dist/components/cms-content-area/index.js.map +1 -1
- package/dist/components/cms-content-area/types.d.ts +49 -57
- package/dist/components/cms-editable/index.d.ts +48 -13
- package/dist/components/cms-editable/index.js +41 -5
- package/dist/components/cms-editable/index.js.map +1 -1
- package/dist/components/rich-text/components.d.ts +8 -7
- package/dist/components/rich-text/components.js +27 -22
- package/dist/components/rich-text/components.js.map +1 -1
- package/dist/components/rich-text/index.d.ts +4 -4
- package/dist/components/rich-text/index.js +19 -20
- package/dist/components/rich-text/index.js.map +1 -1
- package/dist/components/rich-text/types.d.ts +7 -15
- package/dist/components/rsc.d.ts +12 -12
- package/dist/components/rsc.js +17 -16
- package/dist/components/rsc.js.map +1 -1
- package/dist/components/type-utils.d.ts +13 -0
- package/dist/components/visual-builder/functions.js +1 -1
- package/dist/components/visual-builder/functions.js.map +1 -1
- package/dist/components/visual-builder/index.d.ts +1 -1
- package/dist/components/visual-builder/index.js +11 -9
- package/dist/components/visual-builder/index.js.map +1 -1
- package/dist/components/visual-builder/types.d.ts +3 -3
- package/dist/components/visual-builder/types.js.map +1 -1
- package/dist/components.d.ts +1 -1
- package/dist/context/client.d.ts +16 -4
- package/dist/context/client.js +38 -12
- package/dist/context/client.js.map +1 -1
- package/dist/context/rsc.d.ts +26 -9
- package/dist/context/rsc.js +84 -18
- package/dist/context/rsc.js.map +1 -1
- package/dist/context/shared.d.ts +3 -0
- package/dist/context/shared.js +7 -0
- package/dist/context/shared.js.map +1 -0
- package/dist/context/types.d.ts +24 -2
- package/dist/factory/default.js +16 -16
- package/dist/factory/default.js.map +1 -1
- package/dist/index.d.ts +4 -5
- package/dist/index.js +6 -2
- package/dist/index.js.map +1 -1
- package/dist/rsc.d.ts +2 -4
- package/dist/rsc.js +3 -1
- package/dist/rsc.js.map +1 -1
- package/dist/types.d.ts +5 -0
- package/dist/version.json +3 -0
- package/package.json +7 -7
package/dist/components/rsc.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import
|
|
1
|
+
import 'server-only';
|
|
2
2
|
import { type ReactNode, type ComponentType } from 'react';
|
|
3
|
-
import { type PropsWithContext } from '../context/types.js';
|
|
3
|
+
import { type PropsWithContext, type PropsWithOptionalContext } from '../context/types.js';
|
|
4
4
|
import { type CmsContentAreaComponent } from './cms-content-area/index.js';
|
|
5
5
|
import { type CmsEditableComponent } from './cms-editable/index.js';
|
|
6
6
|
import { type CmsContentComponent } from './cms-content/rsc.js';
|
|
7
7
|
import { type OptimizelyCompositionComponent } from './visual-builder/index.js';
|
|
8
8
|
import { type RichTextComponent } from './rich-text/index.js';
|
|
9
|
-
export type { BaseStyleDefinition, ElementStyleDefinition, LayoutProps, LayoutPropsSetting, LayoutPropsSettingChoices, LayoutPropsSettingKeys, LayoutPropsSettingValues, NodeStyleDefinition, StyleDefinition, StyleSetting } from
|
|
10
|
-
export { extractSettings, readSetting } from
|
|
11
|
-
export * from
|
|
12
|
-
export { isNode, isComponentNode, isComponentNodeOfType, isStructureNode, isElementNode } from
|
|
9
|
+
export type { BaseStyleDefinition, ElementStyleDefinition, LayoutProps, LayoutPropsSetting, LayoutPropsSettingChoices, LayoutPropsSettingKeys, LayoutPropsSettingValues, NodeStyleDefinition, StyleDefinition, StyleSetting, } from './cms-styles/index.js';
|
|
10
|
+
export { extractSettings, readSetting } from './cms-styles/index.js';
|
|
11
|
+
export * from './cms-styles/index.js';
|
|
12
|
+
export { isNode, isComponentNode, isComponentNodeOfType, isStructureNode, isElementNode, } from './visual-builder/functions.js';
|
|
13
13
|
/**
|
|
14
14
|
* Fallback while RSC hasn't been moved from Canary to Main
|
|
15
15
|
*/
|
|
@@ -21,7 +21,7 @@ type ReactServerComponentType<P = any> = ComponentType<P> | ((props: P) => Promi
|
|
|
21
21
|
* @param component The component where the `ctx` parameter must be fulfilled
|
|
22
22
|
* @returns The component, without CTX parameter
|
|
23
23
|
*/
|
|
24
|
-
export declare function serverContextAware<P
|
|
24
|
+
export declare function serverContextAware<P extends PropsWithContext>(component: ReactServerComponentType<P>): ComponentType<PropsWithOptionalContext<Omit<P, 'ctx'>>>;
|
|
25
25
|
/**
|
|
26
26
|
* Client side Optimizely CMS Editable
|
|
27
27
|
*/
|
|
@@ -31,13 +31,13 @@ export declare const CmsEditable: CmsEditableComponent;
|
|
|
31
31
|
* content type and content data when needed
|
|
32
32
|
*/
|
|
33
33
|
export declare const CmsContent: CmsContentComponent;
|
|
34
|
-
export type { CmsContentComponent, CmsContentProps } from
|
|
34
|
+
export type { CmsContentComponent, CmsContentProps } from './cms-content/rsc.js';
|
|
35
35
|
/**
|
|
36
36
|
* Client side Optimizely CMS Content Area, leveraging the CMS Context to infer
|
|
37
37
|
* the connection to Optimizely Graph and component dictionary.
|
|
38
38
|
*/
|
|
39
39
|
export declare const CmsContentArea: CmsContentAreaComponent;
|
|
40
|
-
export type { CmsContentAreaClassMapper, CmsContentAreaComponent, CmsContentAreaProps, ContentAreaItemDefinition } from
|
|
40
|
+
export type { CmsContentAreaClassMapper, CmsContentAreaComponent, CmsContentAreaProps, ContentAreaItemDefinition, } from './cms-content-area/index.js';
|
|
41
41
|
/**
|
|
42
42
|
* Client side Optimizely Composition (e.g. Visual Builder), leveraging the CMS
|
|
43
43
|
* Context to infer the connection to Optimizely Graph and component
|
|
@@ -48,6 +48,6 @@ export declare const OptimizelyComposition: OptimizelyCompositionComponent;
|
|
|
48
48
|
* Client side renderer for Rich Text
|
|
49
49
|
*/
|
|
50
50
|
export declare const RichText: RichTextComponent;
|
|
51
|
-
export type { RichTextComponent, RichTextProps, RichTextNode, StringNode, TypedNode, NodeInput } from
|
|
52
|
-
export { DefaultComponents as RichTextComponentDictionary, createHtmlComponent } from './rich-text/components.js';
|
|
53
|
-
export { isNodeInput, isNonEmptyString, isRichTextNode, isStringNode, isText, isTypedNode } from
|
|
51
|
+
export type { RichTextComponent, RichTextProps, RichTextNode, StringNode, TypedNode, NodeInput, } from './rich-text/index.js';
|
|
52
|
+
export { DefaultComponents as RichTextComponentDictionary, createHtmlComponent, } from './rich-text/components.js';
|
|
53
|
+
export { isNodeInput, isNonEmptyString, isRichTextNode, isStringNode, isText, isTypedNode, } from './rich-text/utils.js';
|
package/dist/components/rsc.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import
|
|
2
|
+
import 'server-only';
|
|
3
3
|
import { getServerContext } from '../context/rsc.js';
|
|
4
4
|
import { cmsContentAware } from './cms-content/utils.js';
|
|
5
|
-
import { CmsContentArea as BaseContentArea } from './cms-content-area/index.js'; // Both RSC & Client capable
|
|
6
|
-
import { CmsEditable as BaseEditable } from './cms-editable/index.js'; // Both RSC & Client capable
|
|
7
|
-
import { CmsContent as BaseCmsContent } from './cms-content/rsc.js'; // Different components for RSC & Client
|
|
8
|
-
import { OptimizelyComposition as BaseOptimizelyComposition } from './visual-builder/index.js'; // Both RSC & Client capable
|
|
9
|
-
import { RichText as BaseRichText } from './rich-text/index.js';
|
|
10
|
-
export { extractSettings, readSetting } from
|
|
11
|
-
export * from
|
|
5
|
+
import { CmsContentArea as BaseContentArea, } from './cms-content-area/index.js'; // Both RSC & Client capable
|
|
6
|
+
import { CmsEditable as BaseEditable, } from './cms-editable/index.js'; // Both RSC & Client capable
|
|
7
|
+
import { CmsContent as BaseCmsContent, } from './cms-content/rsc.js'; // Different components for RSC & Client
|
|
8
|
+
import { OptimizelyComposition as BaseOptimizelyComposition, } from './visual-builder/index.js'; // Both RSC & Client capable
|
|
9
|
+
import { RichText as BaseRichText, } from './rich-text/index.js';
|
|
10
|
+
export { extractSettings, readSetting } from './cms-styles/index.js';
|
|
11
|
+
export * from './cms-styles/index.js';
|
|
12
12
|
// Visual Builder items
|
|
13
|
-
export { isNode, isComponentNode, isComponentNodeOfType, isStructureNode, isElementNode } from
|
|
13
|
+
export { isNode, isComponentNode, isComponentNodeOfType, isStructureNode, isElementNode, } from './visual-builder/functions.js';
|
|
14
14
|
/**
|
|
15
15
|
* Wrapper function to turn context dependant components into easy to use
|
|
16
16
|
* server components
|
|
@@ -20,13 +20,14 @@ export { isNode, isComponentNode, isComponentNodeOfType, isStructureNode, isElem
|
|
|
20
20
|
*/
|
|
21
21
|
export function serverContextAware(component) {
|
|
22
22
|
const BaseComponent = component;
|
|
23
|
-
const ServerContextInjector = (props) => {
|
|
24
|
-
const ctx = getServerContext();
|
|
23
|
+
const ServerContextInjector = ({ ctx, ...props }) => {
|
|
25
24
|
if (!ctx)
|
|
26
|
-
console.
|
|
27
|
-
|
|
25
|
+
console.error(`🔴 [ServerContextAware] Context for context aware component ${BaseComponent.displayName ?? BaseComponent.name ?? '[ANONYMOUS]'} is not defined!`);
|
|
26
|
+
const cmpCtx = ctx || getServerContext();
|
|
27
|
+
const componentProps = { ...props, ctx: cmpCtx };
|
|
28
|
+
return _jsx(BaseComponent, { ...componentProps });
|
|
28
29
|
};
|
|
29
|
-
ServerContextInjector.displayName =
|
|
30
|
+
ServerContextInjector.displayName = 'Server Context Injector';
|
|
30
31
|
return ServerContextInjector;
|
|
31
32
|
}
|
|
32
33
|
/**
|
|
@@ -53,6 +54,6 @@ export const OptimizelyComposition = cmsContentAware(serverContextAware(BaseOpti
|
|
|
53
54
|
* Client side renderer for Rich Text
|
|
54
55
|
*/
|
|
55
56
|
export const RichText = serverContextAware(BaseRichText);
|
|
56
|
-
export { DefaultComponents as RichTextComponentDictionary, createHtmlComponent } from './rich-text/components.js';
|
|
57
|
-
export { isNodeInput, isNonEmptyString, isRichTextNode, isStringNode, isText, isTypedNode } from
|
|
57
|
+
export { DefaultComponents as RichTextComponentDictionary, createHtmlComponent, } from './rich-text/components.js';
|
|
58
|
+
export { isNodeInput, isNonEmptyString, isRichTextNode, isStringNode, isText, isTypedNode, } from './rich-text/utils.js';
|
|
58
59
|
//# sourceMappingURL=rsc.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rsc.js","sourceRoot":"","sources":["../../src/components/rsc.tsx"],"names":[],"mappings":";AAAA,OAAO,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"rsc.js","sourceRoot":"","sources":["../../src/components/rsc.tsx"],"names":[],"mappings":";AAAA,OAAO,aAAa,CAAA;AAMpB,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAExD,OAAO,EACL,cAAc,IAAI,eAAe,GAElC,MAAM,6BAA6B,CAAA,CAAC,4BAA4B;AACjE,OAAO,EACL,WAAW,IAAI,YAAY,GAE5B,MAAM,yBAAyB,CAAA,CAAC,4BAA4B;AAC7D,OAAO,EACL,UAAU,IAAI,cAAc,GAG7B,MAAM,sBAAsB,CAAA,CAAC,wCAAwC;AACtE,OAAO,EACL,qBAAqB,IAAI,yBAAyB,GAEnD,MAAM,2BAA2B,CAAA,CAAC,4BAA4B;AAC/D,OAAO,EACL,QAAQ,IAAI,YAAY,GAEzB,MAAM,sBAAsB,CAAA;AAe7B,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AACpE,cAAc,uBAAuB,CAAA;AAErC,uBAAuB;AACvB,OAAO,EACL,MAAM,EACN,eAAe,EACf,qBAAqB,EACrB,eAAe,EACf,aAAa,GACd,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cAAc,EACd,YAAY,EACZ,MAAM,EACN,WAAW,GACZ,MAAM,sBAAsB,CAAA"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { GenericContext } from "../rsc.js";
|
|
1
2
|
/**
|
|
2
3
|
* Tests if K is a property of T - if so: it is the type of
|
|
3
4
|
* T[K]; if not: it is equal to never
|
|
@@ -22,9 +23,21 @@ export type ElementProps<T extends ElementType> = T extends keyof JSX.IntrinsicE
|
|
|
22
23
|
export type ElementChildrenProps<T extends ElementType> = keyof {
|
|
23
24
|
[P in keyof ElementProps<T> as React.ReactElement[] extends ElementProps<T>[P] ? P : never]: ElementProps<T>[P];
|
|
24
25
|
};
|
|
26
|
+
export type GenericContextProps<T extends ElementType> = keyof {
|
|
27
|
+
[P in keyof ElementProps<T> as GenericContext extends ElementProps<T>[P] ? P : never]: ElementProps<T>[P];
|
|
28
|
+
};
|
|
25
29
|
/**
|
|
26
30
|
* Define an element as a React Component, React ExoticComponent or string name
|
|
27
31
|
* representing a HTML Element (e.g. "div", "a", etc...), this value can be used
|
|
28
32
|
* as first argument of React.createElement()
|
|
29
33
|
*/
|
|
30
34
|
export type ElementType = (React.ComponentType<any>) | (React.ExoticComponent<any>) | (keyof JSX.IntrinsicElements);
|
|
35
|
+
/**
|
|
36
|
+
* Reserved Element properties that may not be passed to CmsContentArea wrappers, as these are auto-injected
|
|
37
|
+
*/
|
|
38
|
+
export type ReservedKeys = "data-epi-edit" | "data-epi-property-name" | "data-epi-property-render" | "data-epi-property-edittype" | "data-epi-block-id" | "data-displayoption" | "data-tag" | "data-component";
|
|
39
|
+
export type WithAs<Base, CT extends ElementType> = Base & {
|
|
40
|
+
as?: CT;
|
|
41
|
+
children?: PropTypeIfPropExists<CT, 'children'>;
|
|
42
|
+
key: PropTypeIfPropExists<CT, 'key'>;
|
|
43
|
+
} & Omit<ElementProps<CT>, keyof Base>;
|
|
@@ -47,7 +47,7 @@ export const defaultPropsFactory = (node) => {
|
|
|
47
47
|
if (!isContentType(contentType))
|
|
48
48
|
throw new Error("Invalid content type: " + JSON.stringify(contentType));
|
|
49
49
|
const contentLink = {
|
|
50
|
-
key: node.
|
|
50
|
+
key: node.key || node.component?._metadata?.key || undefined,
|
|
51
51
|
version: node.component?._metadata?.version,
|
|
52
52
|
locale: node.component?._metadata?.locale
|
|
53
53
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"functions.js","sourceRoot":"","sources":["../../../src/components/visual-builder/functions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,EAAE,aAAa,EAAyB,mBAAmB,EAAE,MAAM,iCAAiC,CAAA;AAG3G;;;;;;GAMG;AACH,MAAM,UAAU,aAAa,CAAC,IAAyC;IAEnE,OAAO,eAAe,CAAC,IAAI,CAAC,CAAA;AAChC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,IAAyC;IAErE,OAAO,IAAI,CAAC,UAAU,IAAI,WAAW,CAAA;AACzC,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAgC,IAAyC,EAAE,IAA8C;IAE1J,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC;QACtB,OAAO,KAAK,CAAA;IAChB,OAAO,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;AAC/B,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,IAAyC;IAErE,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC,CAAA;AACjC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,MAAM,CAAC,MAAW;IAE9B,IAAI,OAAM,CAAC,MAAM,CAAC,IAAI,QAAQ,IAAI,MAAM,IAAI,IAAI;QAC5C,OAAO,KAAK,CAAA;IAEhB,MAAM,SAAS,GAAG,CAAC,YAAY,EAAE,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE,WAAW,CAAC,CAAA;IACzE,MAAM,YAAY,GAAG,CAAC,OAAQ,MAA0B,C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f,UAAU,EAAE,IAAI,CAAC,UAAU;QAC3B,QAAQ,EAAE,IAAI,CAAC,QAAQ;QACvB,QAAQ,EAAE,IAAI,CAAC,QAAQ;KAC1B,CAAA;IAED,IAAI,CAAC,CAAC,aAAa,CAAC,WAAW,CAAC,IAAI,mBAAmB,CAAC,WAAW,CAAC,CAAC;QACjE,MAAM,IAAI,KAAK,CAAC,2CAA2C,GAAC,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,GAAE,WAAW,GAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAA;IAE/H,OAAO,CAAE,WAAW,EAAE,cAAc,EAAE,aAAa,EAAE,UAAU,CAAE,CAAA;AACrE,CAAC,CAAA;AAED,MAAM,UAAU,OAAO,CAAC,KAAgC;IAEpD,IAAI,OAAM,CAAC,KAAK,CAAC,IAAI,QAAQ,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC;QAC7C,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAA;IACtD,OAAO,IAAI,CAAA;AACf,CAAC"}
|
|
@@ -7,5 +7,5 @@ export type * from './types.js';
|
|
|
7
7
|
* @param param0
|
|
8
8
|
* @returns The
|
|
9
9
|
*/
|
|
10
|
-
export declare function OptimizelyComposition({ node, leafPropsFactory, nodePropsFactory, ctx, cmsContent: CmsContent }: BaseOptimizelyCompositionProps): ReactNode;
|
|
10
|
+
export declare function OptimizelyComposition({ node, leafPropsFactory, nodePropsFactory, ctx, cmsContent: CmsContent, }: BaseOptimizelyCompositionProps): ReactNode;
|
|
11
11
|
export default OptimizelyComposition;
|
|
@@ -1,35 +1,37 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { isComponentNode, defaultNodePropsFactory, defaultPropsFactory } from './functions.js';
|
|
2
|
+
import { isComponentNode, defaultNodePropsFactory, defaultPropsFactory, } from './functions.js';
|
|
3
3
|
/**
|
|
4
4
|
* Render the composition as made available through Optimizely Graph for Visual Builder
|
|
5
5
|
*
|
|
6
6
|
* @param param0
|
|
7
7
|
* @returns The
|
|
8
8
|
*/
|
|
9
|
-
export function OptimizelyComposition({ node, leafPropsFactory = defaultPropsFactory, nodePropsFactory = defaultNodePropsFactory, ctx, cmsContent: CmsContent }) {
|
|
9
|
+
export function OptimizelyComposition({ node, leafPropsFactory = defaultPropsFactory, nodePropsFactory = defaultNodePropsFactory, ctx, cmsContent: CmsContent, }) {
|
|
10
10
|
const { factory, isDebug } = ctx;
|
|
11
11
|
// Render the element
|
|
12
12
|
if (isComponentNode(node)) {
|
|
13
13
|
if (isDebug)
|
|
14
14
|
console.log(`⚪ [VisualBuilder] Rendering element node ${JSON.stringify(node)}`);
|
|
15
15
|
const [contentLink, contentType, fragmentData, layoutProps] = leafPropsFactory(node);
|
|
16
|
-
return _jsx(CmsContent, { contentLink: contentLink, contentType: contentType, fragmentData: fragmentData, layoutProps: layoutProps });
|
|
16
|
+
return (_jsx(CmsContent, { contentLink: contentLink, contentType: contentType, fragmentData: fragmentData, layoutProps: layoutProps, ctx: ctx }));
|
|
17
17
|
}
|
|
18
18
|
// Debug
|
|
19
19
|
if (isDebug)
|
|
20
20
|
console.log(`⚪ [VisualBuilder] Rendering structure node ${JSON.stringify(node)}`);
|
|
21
21
|
// Ensure we've got a factory
|
|
22
22
|
if (!factory)
|
|
23
|
-
throw new Error(
|
|
23
|
+
throw new Error('🟡 [VisualBuilder] [OptimizelyComposition] The factory must be defined within the serverContext');
|
|
24
24
|
const [contentLink, contentTypes, fragmentData, layoutProps] = nodePropsFactory(node);
|
|
25
|
-
const firstExistingType = contentTypes
|
|
25
|
+
const firstExistingType = contentTypes
|
|
26
|
+
.map((ct) => factory.has([...ct].reverse()))
|
|
27
|
+
.indexOf(true);
|
|
26
28
|
const contentType = contentTypes[firstExistingType];
|
|
27
29
|
if (!contentType)
|
|
28
|
-
throw new Error(`🟡 [VisualBuilder] [OptimizelyComposition] The factory must have a definition for one of these types: ${contentTypes.map(x => x.join('/')).join(', ')}`);
|
|
29
|
-
return _jsx(CmsContent, { contentType: contentType, contentLink: contentLink, fragmentData: fragmentData, layoutProps: layoutProps, noDataLoad: true, children: (node.nodes ?? []).map((child) => {
|
|
30
|
+
throw new Error(`🟡 [VisualBuilder] [OptimizelyComposition] The factory must have a definition for one of these types: ${contentTypes.map((x) => x.join('/')).join(', ')}`);
|
|
31
|
+
return (_jsx(CmsContent, { contentType: contentType, contentLink: contentLink, fragmentData: fragmentData, layoutProps: layoutProps, noDataLoad: true, ctx: ctx, children: (node.nodes ?? []).map((child) => {
|
|
30
32
|
const childKey = child.key ? child.key : `vb::${JSON.stringify(child)}`;
|
|
31
|
-
return _jsx(OptimizelyComposition, { node: child, leafPropsFactory: leafPropsFactory, nodePropsFactory: nodePropsFactory, ctx: ctx, cmsContent: CmsContent }, childKey);
|
|
32
|
-
}) });
|
|
33
|
+
return (_jsx(OptimizelyComposition, { node: child, leafPropsFactory: leafPropsFactory, nodePropsFactory: nodePropsFactory, ctx: ctx, cmsContent: CmsContent }, childKey));
|
|
34
|
+
}) }));
|
|
33
35
|
}
|
|
34
36
|
export default OptimizelyComposition;
|
|
35
37
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/visual-builder/index.tsx"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/visual-builder/index.tsx"],"names":[],"mappings":";AACA,OAAO,EACL,eAAe,EACf,uBAAuB,EACvB,mBAAmB,GACpB,MAAM,gBAAgB,CAAA;AAIvB;;;;;GAKG;AACH,MAAM,UAAU,qBAAqB,CAAC,EACpC,IAAI,EACJ,gBAAgB,GAAG,mBAAmB,EACtC,gBAAgB,GAAG,uBAAuB,EAC1C,GAAG,EACH,UAAU,EAAE,UAAU,GACS;IAC/B,MAAM,EAAE,OAAO,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I,CAAC,EAAE,CAC3J,CAAA;IAEH,OAAO,CACL,KAAC,UAAU,IACT,WAAW,EAAE,WAAW,EACxB,WAAW,EAAE,WAAW,EACxB,YAAY,EAAE,YAAY,EAC1B,WAAW,EAAE,WAAW,EACxB,UAAU,QACV,GAAG,EAAE,GAAG,YAEP,CAAC,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;YAChC,MAAM,QAAQ,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAA;YACvE,OAAO,CACL,KAAC,qBAAqB,IAEpB,IAAI,EAAE,KAAK,EACX,gBAAgB,EAAE,gBAAgB,EAClC,gBAAgB,EAAE,gBAAgB,EAClC,GAAG,EAAE,GAAG,EACR,UAAU,EAAE,UAAU,IALjB,QAAQ,CAMb,CACH,CAAA;QACH,CAAC,CAAC,GACS,CACd,CAAA;AACH,CAAC;AAED,eAAe,qBAAqB,CAAA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type ComponentType, type PropsWithChildren } from "react";
|
|
2
2
|
import { type InlineContentLinkWithLocale, type ContentLinkWithLocale } from "@remkoj/optimizely-graph-client";
|
|
3
3
|
import { type ContentType } from "../../types.js";
|
|
4
|
-
import { type PropsWithContext } from "../../context/types.js";
|
|
4
|
+
import { type PropsWithContext, type PropsWithOptionalContext } from "../../context/types.js";
|
|
5
5
|
import { type PropsWithCmsContent } from "../cms-content/types.js";
|
|
6
6
|
export declare enum StructureNodeTypes {
|
|
7
7
|
Experience = "experience",
|
|
@@ -36,7 +36,7 @@ export type CompositionComponentType<NT extends CompositionNode> = ComponentType
|
|
|
36
36
|
}>>;
|
|
37
37
|
export type LeafPropsFactory = <ET extends Record<string, any>, LT = string>(node: CompositionComponentNode<ET>) => [ContentLinkWithLocale<LT> | InlineContentLinkWithLocale<LT>, ContentType, ET] | [ContentLinkWithLocale<LT> | InlineContentLinkWithLocale<LT>, ContentType, ET, Record<string, any>];
|
|
38
38
|
export type NodePropsFactory = <ET extends Record<string, any>, LT = string>(node: CompositionStructureNode) => [ContentLinkWithLocale<LT> | InlineContentLinkWithLocale<LT>, Array<ContentType>, ET] | [ContentLinkWithLocale<LT> | InlineContentLinkWithLocale<LT>, Array<ContentType>, ET, Record<string, any>];
|
|
39
|
-
export type OptimizelyCompositionProps = JSX.IntrinsicAttributes & {
|
|
39
|
+
export type OptimizelyCompositionProps = PropsWithOptionalContext<JSX.IntrinsicAttributes & {
|
|
40
40
|
/**
|
|
41
41
|
* The Visual Builder node to start rendering from
|
|
42
42
|
*/
|
|
@@ -51,7 +51,7 @@ export type OptimizelyCompositionProps = JSX.IntrinsicAttributes & {
|
|
|
51
51
|
* Optimizely Graph into properties for a structure node.
|
|
52
52
|
*/
|
|
53
53
|
nodePropsFactory?: NodePropsFactory;
|
|
54
|
-
}
|
|
54
|
+
}>;
|
|
55
55
|
export type BaseOptimizelyCompositionProps = PropsWithCmsContent<PropsWithContext<OptimizelyCompositionProps>>;
|
|
56
56
|
export type OptimizelyCompositionComponent = ComponentType<OptimizelyCompositionProps>;
|
|
57
57
|
export type OptimizelyCompositionBaseComponent = ComponentType<BaseOptimizelyCompositionProps>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/components/visual-builder/types.ts"],"names":[],"mappings":"AAMA,MAAM,CAAN,IAAY,kBAKX;AALD,WAAY,kBAAkB;
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/components/visual-builder/types.ts"],"names":[],"mappings":"AAMA,MAAM,CAAN,IAAY,kBAKX;AALD,WAAY,kBAAkB;IAC5B,+CAAyB,CAAA;IACzB,yCAAmB,CAAA;IACnB,iCAAW,CAAA;IACX,uCAAiB,CAAA;AACnB,CAAC,EALW,kBAAkB,KAAlB,kBAAkB,QAK7B"}
|
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").RichTextProps
|
|
9
|
+
export declare const RichText: import("react").ComponentType<import("./rsc.js").PropsWithOptionalContext<Omit<import("./rsc.js").PropsWithContext<import("./rsc.js").RichTextProps>, "ctx">>>;
|
|
10
10
|
/**
|
|
11
11
|
* @deprecated The `@remkoj/optimizely-cms-react/components` export has been deprecated
|
|
12
12
|
*/
|
package/dist/context/client.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { type FunctionComponent, type PropsWithChildren, type Dispatch, type SetStateAction } from
|
|
2
|
-
import { type OptimizelyGraphConfig, type IOptiGraphClient } from
|
|
3
|
-
import { type GenericContext } from
|
|
4
|
-
import { type ComponentTypeDictionary, type ComponentFactory } from
|
|
1
|
+
import { type FunctionComponent, type PropsWithChildren, type Dispatch, type SetStateAction } from 'react';
|
|
2
|
+
import { type OptimizelyGraphConfig, type IOptiGraphClient } from '@remkoj/optimizely-graph-client';
|
|
3
|
+
import { type GenericContext, type TransferrableContext } from './types.js';
|
|
4
|
+
import { type ComponentTypeDictionary, type ComponentFactory } from '../factory/index.js';
|
|
5
5
|
export declare const enum OptimizelyCmsMode {
|
|
6
6
|
default = "default",
|
|
7
7
|
edit = "edit",
|
|
@@ -11,6 +11,17 @@ export interface ClientContext extends GenericContext {
|
|
|
11
11
|
setLocale: Dispatch<SetStateAction<string | undefined>>;
|
|
12
12
|
setMode: Dispatch<SetStateAction<OptimizelyCmsMode>>;
|
|
13
13
|
}
|
|
14
|
+
export declare class ClientContextInstance implements GenericContext {
|
|
15
|
+
readonly client?: IOptiGraphClient | undefined;
|
|
16
|
+
readonly factory: ComponentFactory;
|
|
17
|
+
readonly locale?: string | undefined;
|
|
18
|
+
readonly inEditMode: boolean;
|
|
19
|
+
readonly inPreviewMode: boolean;
|
|
20
|
+
readonly isDevelopment: boolean;
|
|
21
|
+
readonly isDebug: boolean;
|
|
22
|
+
readonly isDebugOrDevelopment: boolean;
|
|
23
|
+
constructor(cfg: TransferrableContext, components: ComponentTypeDictionary);
|
|
24
|
+
}
|
|
14
25
|
export type OptimizelyCmsProps = {
|
|
15
26
|
/**
|
|
16
27
|
* The Optimizely Graph Client to use, provide either an instance of the
|
|
@@ -68,3 +79,4 @@ export type OptimizelyCmsProps = {
|
|
|
68
79
|
});
|
|
69
80
|
export declare const OptimizelyCms: FunctionComponent<PropsWithChildren<OptimizelyCmsProps>>;
|
|
70
81
|
export declare const useOptimizelyCms: () => ClientContext;
|
|
82
|
+
export declare function fromTransferrableContext(serialized: TransferrableContext, components: ComponentTypeDictionary): GenericContext;
|
package/dist/context/client.js
CHANGED
|
@@ -1,15 +1,28 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import { createContext, useContext, useState, useMemo } from
|
|
4
|
-
import { isOptiGraphClient, isOptiGraphConfig, createClient } from
|
|
5
|
-
import { getFactory } from
|
|
6
|
-
import { UndefinedComponentFactory } from
|
|
3
|
+
import { createContext, useContext, useState, useMemo, } from 'react';
|
|
4
|
+
import { isOptiGraphClient, isOptiGraphConfig, createClient, } from '@remkoj/optimizely-graph-client';
|
|
5
|
+
import { getFactory, DefaultComponentFactory, } from '../factory/index.js';
|
|
6
|
+
import { UndefinedComponentFactory } from '../factory/undef.js';
|
|
7
|
+
import { isTransferrableContext } from './shared.js';
|
|
7
8
|
export var OptimizelyCmsMode;
|
|
8
9
|
(function (OptimizelyCmsMode) {
|
|
9
10
|
OptimizelyCmsMode["default"] = "default";
|
|
10
11
|
OptimizelyCmsMode["edit"] = "edit";
|
|
11
12
|
OptimizelyCmsMode["preview"] = "preview";
|
|
12
13
|
})(OptimizelyCmsMode || (OptimizelyCmsMode = {}));
|
|
14
|
+
export class ClientContextInstance {
|
|
15
|
+
constructor(cfg, components) {
|
|
16
|
+
if (cfg.clientConfig)
|
|
17
|
+
this.client = createClient(cfg.clientConfig);
|
|
18
|
+
this.factory = new DefaultComponentFactory(components);
|
|
19
|
+
this.inEditMode = cfg.inEditMode;
|
|
20
|
+
this.inPreviewMode = cfg.inPreviewMode;
|
|
21
|
+
this.isDebug = cfg.isDebug;
|
|
22
|
+
this.isDebugOrDevelopment = cfg.isDebugOrDevelopment;
|
|
23
|
+
this.isDevelopment = cfg.isDevelopment;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
13
26
|
const _clientContext = createContext({
|
|
14
27
|
factory: new UndefinedComponentFactory(),
|
|
15
28
|
inEditMode: false,
|
|
@@ -17,11 +30,15 @@ const _clientContext = createContext({
|
|
|
17
30
|
isDebug: false,
|
|
18
31
|
isDebugOrDevelopment: false,
|
|
19
32
|
isDevelopment: false,
|
|
20
|
-
setLocale: () => {
|
|
21
|
-
|
|
33
|
+
setLocale: () => {
|
|
34
|
+
throw new Error('Not implemented');
|
|
35
|
+
},
|
|
36
|
+
setMode: () => {
|
|
37
|
+
throw new Error('Not implemented');
|
|
38
|
+
},
|
|
22
39
|
});
|
|
23
|
-
_clientContext.displayName =
|
|
24
|
-
export const OptimizelyCms = ({ factory, client, clientToken, children, isDebug, isDevelopment, initialMode = OptimizelyCmsMode.default, initialComponents = [] }) => {
|
|
40
|
+
_clientContext.displayName = 'Optimizely CMS Provider';
|
|
41
|
+
export const OptimizelyCms = ({ factory, client, clientToken, children, isDebug, isDevelopment, initialMode = OptimizelyCmsMode.default, initialComponents = [], }) => {
|
|
25
42
|
const CtxProvider = _clientContext.Provider;
|
|
26
43
|
//#region React State
|
|
27
44
|
const [locale, setLocale] = useState();
|
|
@@ -29,15 +46,19 @@ export const OptimizelyCms = ({ factory, client, clientToken, children, isDebug,
|
|
|
29
46
|
//#endregion
|
|
30
47
|
//#region Memoized Optimizely Graph Client
|
|
31
48
|
const graphClient = useMemo(() => {
|
|
32
|
-
const gc = isOptiGraphClient(client)
|
|
49
|
+
const gc = isOptiGraphClient(client)
|
|
50
|
+
? client
|
|
51
|
+
: createClient(isOptiGraphConfig(client) ? client : undefined);
|
|
33
52
|
if (clientToken)
|
|
34
53
|
gc.updateAuthentication(clientToken);
|
|
35
54
|
return gc;
|
|
36
55
|
}, [client, clientToken]);
|
|
37
56
|
//#endregion
|
|
38
57
|
//#region Memoized Debug and Development flags
|
|
39
|
-
const isDev = useMemo(() => isDevelopment == undefined
|
|
40
|
-
|
|
58
|
+
const isDev = useMemo(() => isDevelopment == undefined
|
|
59
|
+
? getNodeEnv() == 'development'
|
|
60
|
+
: isDevelopment, [isDevelopment]);
|
|
61
|
+
const isDbg = useMemo(() => (isDebug == undefined ? graphClient.debug : isDebug), [isDebug, graphClient]);
|
|
41
62
|
//#endregion
|
|
42
63
|
//#region Memoized Component Factory
|
|
43
64
|
const ctxFactory = useMemo(() => {
|
|
@@ -58,13 +79,18 @@ export const OptimizelyCms = ({ factory, client, clientToken, children, isDebug,
|
|
|
58
79
|
inPreviewMode: mode == OptimizelyCmsMode.preview,
|
|
59
80
|
locale,
|
|
60
81
|
setLocale,
|
|
61
|
-
setMode
|
|
82
|
+
setMode,
|
|
62
83
|
};
|
|
63
84
|
return _jsx(CtxProvider, { value: ctxValue, children: children });
|
|
64
85
|
};
|
|
65
86
|
export const useOptimizelyCms = () => {
|
|
66
87
|
return useContext(_clientContext);
|
|
67
88
|
};
|
|
89
|
+
export function fromTransferrableContext(serialized, components) {
|
|
90
|
+
if (!isTransferrableContext(serialized))
|
|
91
|
+
throw new Error('Unable to restore from serialized data');
|
|
92
|
+
return new ClientContextInstance(serialized, components);
|
|
93
|
+
}
|
|
68
94
|
function getNodeEnv() {
|
|
69
95
|
let env;
|
|
70
96
|
try {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/context/client.tsx"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C,sBAAsB,CAAC,UAAU,CAAC;QACrC,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAA;IAC3D,OAAO,IAAI,qBAAqB,CAAC,UAAU,EAAE,UAAU,CAAC,CAAA;AAC1D,CAAC;AAED,SAAS,UAAU;IACjB,IAAI,GAAuB,CAAA;IAC3B,IAAI,CAAC;QACH,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAA;IAC5B,CAAC;IAAC,MAAM,CAAC;QACP,qBAAqB;IACvB,CAAC;IACD,OAAO,GAAG,IAAI,YAAY,CAAA;AAC5B,CAAC"}
|
package/dist/context/rsc.d.ts
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import 'server-only';
|
|
2
2
|
import { type IOptiGraphClient, type ContentLink } from '@remkoj/optimizely-graph-client';
|
|
3
|
-
import { type GenericContext } from './types.js';
|
|
4
|
-
import { type ComponentFactory } from '../factory/index.js';
|
|
5
|
-
export * from
|
|
6
|
-
type ServerContextArgs = {
|
|
7
|
-
factory?: ComponentFactory;
|
|
3
|
+
import { type GenericContext, type RenderMode, type TransferrableContext } from './types.js';
|
|
4
|
+
import { type ComponentFactory, type ComponentTypeDictionary } from '../factory/index.js';
|
|
5
|
+
export * from './types.js';
|
|
6
|
+
export type ServerContextArgs = {
|
|
7
|
+
factory?: ComponentFactory | ComponentTypeDictionary;
|
|
8
8
|
client?: IOptiGraphClient;
|
|
9
9
|
locale?: string;
|
|
10
|
+
mode?: RenderMode;
|
|
11
|
+
editableContent?: ContentLink;
|
|
10
12
|
};
|
|
11
|
-
declare class ServerContext implements GenericContext {
|
|
13
|
+
export declare class ServerContext implements GenericContext {
|
|
12
14
|
private _mode;
|
|
13
15
|
private _locale;
|
|
14
16
|
private _client;
|
|
@@ -22,13 +24,14 @@ declare class ServerContext implements GenericContext {
|
|
|
22
24
|
get isDevelopment(): boolean;
|
|
23
25
|
get isDebug(): boolean;
|
|
24
26
|
get isDebugOrDevelopment(): boolean;
|
|
25
|
-
get editableContent():
|
|
26
|
-
constructor({ factory, client, locale }: ServerContextArgs);
|
|
27
|
+
get editableContent(): GenericContext['editableContent'];
|
|
28
|
+
constructor({ factory, client, locale, mode, editableContent, }: ServerContextArgs);
|
|
27
29
|
setMode(mode: 'edit' | 'preview' | 'public'): ServerContext;
|
|
28
30
|
setLocale(locale: string): ServerContext;
|
|
29
31
|
setOptimizelyGraphClient(client: IOptiGraphClient | ((currentClient: IOptiGraphClient | undefined) => IOptiGraphClient | undefined)): void;
|
|
30
32
|
setComponentFactory(factory: ComponentFactory | ((currentClient: ComponentFactory | undefined) => ComponentFactory)): void;
|
|
31
|
-
setEditableContentId(link:
|
|
33
|
+
setEditableContentId(link: GenericContext['editableContent']): void;
|
|
34
|
+
toJSON(key?: string): TransferrableContext;
|
|
32
35
|
}
|
|
33
36
|
/**
|
|
34
37
|
* Obtain an instance of the servercontext, this either uses `React.cache`,
|
|
@@ -37,5 +40,19 @@ declare class ServerContext implements GenericContext {
|
|
|
37
40
|
*
|
|
38
41
|
* It the cache fallback will notify in development or debug mode when it is in
|
|
39
42
|
* use.
|
|
43
|
+
*
|
|
44
|
+
* @deprecated Use the context handed down through the CmsContentArea and CmsContent
|
|
45
|
+
* components
|
|
40
46
|
*/
|
|
41
47
|
export declare const getServerContext: () => ServerContext;
|
|
48
|
+
/**
|
|
49
|
+
* Update the shared server context from the provided context. This is compatibility
|
|
50
|
+
* method to ensure that the value returned by `getServerContext` can be retrieved and
|
|
51
|
+
* updated.
|
|
52
|
+
*
|
|
53
|
+
* @deprecated Use the context handed down through the CmsContentArea and CmsContent
|
|
54
|
+
* components
|
|
55
|
+
* @param currentCtx The current context to apply to the server context
|
|
56
|
+
* @returns The updated shared server context
|
|
57
|
+
*/
|
|
58
|
+
export declare function updateSharedServerContext(currentCtx: GenericContext): ServerContext;
|