@remkoj/optimizely-cms-react 6.0.0-pre8 → 6.0.0-rc.1
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/LICENSE +12 -12
- package/README.md +3 -4
- package/dist/components/cms-content/get-content-type.js +8 -17
- package/dist/components/cms-content/get-content-type.js.map +1 -1
- package/dist/components/cms-content/get-content.js +46 -50
- package/dist/components/cms-content/get-content.js.map +1 -1
- package/dist/components/cms-content/resolve-component.js +8 -9
- package/dist/components/cms-content/resolve-component.js.map +1 -1
- package/dist/components/cms-content/rsc.d.ts +1 -1
- package/dist/components/cms-content/rsc.js +9 -7
- package/dist/components/cms-content/rsc.js.map +1 -1
- package/dist/components/cms-content/types.d.ts +46 -2
- package/dist/components/cms-content-area/index.js +3 -3
- package/dist/components/cms-content-area/index.js.map +1 -1
- package/dist/components/cms-content-area/types.d.ts +51 -10
- package/dist/components/cms-editable/index.d.ts +86 -17
- package/dist/components/cms-editable/index.js +20 -10
- package/dist/components/cms-editable/index.js.map +1 -1
- package/dist/components/rich-text/index.d.ts +2 -1
- package/dist/components/rich-text/index.js +6 -3
- package/dist/components/rich-text/index.js.map +1 -1
- package/dist/components/rsc-components.d.ts +154 -5
- package/dist/components/rsc-components.js +153 -5
- package/dist/components/rsc-components.js.map +1 -1
- package/dist/components/rsc.d.ts +2 -0
- package/dist/components/rsc.js +1 -0
- package/dist/components/rsc.js.map +1 -1
- package/dist/components/visual-builder/functions.js +10 -17
- package/dist/components/visual-builder/functions.js.map +1 -1
- package/dist/components/visual-builder/index.d.ts +3 -1
- package/dist/components/visual-builder/index.js +19 -16
- package/dist/components/visual-builder/index.js.map +1 -1
- package/dist/components/visual-builder/types.d.ts +8 -2
- package/dist/context/client.js +5 -2
- package/dist/context/client.js.map +1 -1
- package/dist/context/rsc.d.ts +1 -1
- package/dist/context/rsc.js +11 -42
- package/dist/context/rsc.js.map +1 -1
- package/dist/context/shared.js +2 -1
- package/dist/context/shared.js.map +1 -1
- package/dist/context/types.d.ts +3 -11
- package/dist/factory/default.d.ts +20 -3
- package/dist/factory/default.js +41 -27
- package/dist/factory/default.js.map +1 -1
- package/dist/factory/types.d.ts +24 -4
- package/dist/factory/undef.d.ts +7 -5
- package/dist/factory/undef.js +10 -4
- package/dist/factory/undef.js.map +1 -1
- package/dist/rsc.d.ts +24 -0
- package/dist/rsc.js +24 -0
- package/dist/rsc.js.map +1 -1
- package/dist/types.d.ts +37 -6
- package/dist/utilities.d.ts +56 -6
- package/dist/utilities.js +112 -14
- package/dist/utilities.js.map +1 -1
- package/package.json +19 -15
|
@@ -27,17 +27,165 @@ function serverContextAware(component) {
|
|
|
27
27
|
return ServerContextInjector;
|
|
28
28
|
}
|
|
29
29
|
/**
|
|
30
|
-
*
|
|
30
|
+
* Optimizely CMS editable marker wrapper for React Server Components.
|
|
31
|
+
*
|
|
32
|
+
* `CmsEditable` renders an element (default `div`) and conditionally injects
|
|
33
|
+
* Optimizely edit-mode attributes (`data-epi-*`) based on the current CMS
|
|
34
|
+
* context. In non-edit mode it behaves like a transparent wrapper.
|
|
35
|
+
*
|
|
36
|
+
* Key behavior:
|
|
37
|
+
* - Uses `ctx` from props when provided, otherwise resolves server context.
|
|
38
|
+
* - Injects edit attributes only when rendering in edit mode.
|
|
39
|
+
* - Supports custom wrapper elements/components via `as`.
|
|
40
|
+
* - Can forward `ctx` to custom components via `forwardCtx`.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```tsx
|
|
44
|
+
* import { CmsEditable } from '@remkoj/optimizely-cms-react/rsc'
|
|
45
|
+
*
|
|
46
|
+
* export function PageTitle({ title, id }: { title: string, id: string }) {
|
|
47
|
+
* return (
|
|
48
|
+
* <CmsEditable as="h1" cmsId={id} cmsFieldName="Title">
|
|
49
|
+
* {title}
|
|
50
|
+
* </CmsEditable>
|
|
51
|
+
* )
|
|
52
|
+
* }
|
|
53
|
+
* ```
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```tsx
|
|
57
|
+
* import { CmsEditable } from '@remkoj/optimizely-cms-react/rsc'
|
|
58
|
+
*
|
|
59
|
+
* function Heading(props: { children: React.ReactNode, cmsCtx?: unknown }) {
|
|
60
|
+
* return <h2>{props.children}</h2>
|
|
61
|
+
* }
|
|
62
|
+
*
|
|
63
|
+
* export function Teaser({ id, title }: { id: string, title: string }) {
|
|
64
|
+
* return (
|
|
65
|
+
* <CmsEditable
|
|
66
|
+
* as={Heading}
|
|
67
|
+
* cmsId={id}
|
|
68
|
+
* cmsFieldName="Heading"
|
|
69
|
+
* forwardCtx="cmsCtx"
|
|
70
|
+
* >
|
|
71
|
+
* {title}
|
|
72
|
+
* </CmsEditable>
|
|
73
|
+
* )
|
|
74
|
+
* }
|
|
75
|
+
* ```
|
|
76
|
+
*
|
|
77
|
+
* @remarks
|
|
78
|
+
* For a full prop reference, see `CmsEditableProps`.
|
|
31
79
|
*/
|
|
32
80
|
export const CmsEditable = serverContextAware(BaseEditable);
|
|
33
81
|
/**
|
|
34
|
-
*
|
|
35
|
-
*
|
|
82
|
+
* Optimizely CMS content renderer for React Server Components.
|
|
83
|
+
*
|
|
84
|
+
* `CmsContent` resolves the component template for a content item and provides
|
|
85
|
+
* that template with loaded data and edit metadata.
|
|
86
|
+
*
|
|
87
|
+
* Key behavior:
|
|
88
|
+
* - Resolves content type from `contentType`, `fragmentData`, or Graph lookup.
|
|
89
|
+
* - Resolves template using context component dictionary and optional
|
|
90
|
+
* `contentTypePrefix` / `variant`.
|
|
91
|
+
* - Loads content data unless `noDataLoad` is set.
|
|
92
|
+
* - Passes `editProps` to resolved CMS templates for in-context editing.
|
|
93
|
+
*
|
|
94
|
+
* Required props:
|
|
95
|
+
* - `contentLink`
|
|
96
|
+
*
|
|
97
|
+
* Optional props:
|
|
98
|
+
* - `contentType`, `contentTypePrefix`, `variant`, `fragmentData`, `layoutProps`,
|
|
99
|
+
* `noDataLoad`, `editorComponentId`, `ctx`
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```tsx
|
|
103
|
+
* import { CmsContent } from '@remkoj/optimizely-cms-react/rsc'
|
|
104
|
+
*
|
|
105
|
+
* export default async function Slot({ contentLink }: { contentLink: { key: string, locale?: string } }) {
|
|
106
|
+
* return (
|
|
107
|
+
* <CmsContent
|
|
108
|
+
* contentLink={contentLink}
|
|
109
|
+
* contentTypePrefix="Page"
|
|
110
|
+
* variant="default"
|
|
111
|
+
* />
|
|
112
|
+
* )
|
|
113
|
+
* }
|
|
114
|
+
* ```
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* ```tsx
|
|
118
|
+
* import { CmsContent } from '@remkoj/optimizely-cms-react/rsc'
|
|
119
|
+
*
|
|
120
|
+
* export function PreloadedBlock({ contentLink, fragmentData }: { contentLink: { key: string }, fragmentData: Record<string, any> }) {
|
|
121
|
+
* return (
|
|
122
|
+
* <CmsContent
|
|
123
|
+
* contentLink={contentLink}
|
|
124
|
+
* fragmentData={fragmentData}
|
|
125
|
+
* contentType={["Component", "TeaserBlock"]}
|
|
126
|
+
* />
|
|
127
|
+
* )
|
|
128
|
+
* }
|
|
129
|
+
* ```
|
|
130
|
+
*
|
|
131
|
+
* @remarks
|
|
132
|
+
* For a full prop reference, see `CmsContentProps`.
|
|
36
133
|
*/
|
|
37
134
|
export const CmsContent = serverContextAware(BaseCmsContent);
|
|
38
135
|
/**
|
|
39
|
-
*
|
|
40
|
-
*
|
|
136
|
+
* Optimizely CMS Content Area renderer for React Server Components.
|
|
137
|
+
*
|
|
138
|
+
* `CmsContentArea` renders a list of content area items by delegating each item
|
|
139
|
+
* to `CmsContent`, with optional container and item-wrapper customization.
|
|
140
|
+
*
|
|
141
|
+
* Key behavior:
|
|
142
|
+
* - Renders each item as `CmsContent` with normalized content link and type.
|
|
143
|
+
* - Adds edit markers for the content area in edit mode when `fieldName` is set.
|
|
144
|
+
* - Supports optional wrappers (`as`, `itemWrapper`) or no wrappers.
|
|
145
|
+
* - Supports per-item suspense boundaries (`useSuspense`, `fallback`).
|
|
146
|
+
*
|
|
147
|
+
* Required props:
|
|
148
|
+
* - `items`
|
|
149
|
+
*
|
|
150
|
+
* Optional props:
|
|
151
|
+
* - `fieldName`, `variant`, `as`, `itemsProperty`, `className`, `classMapper`,
|
|
152
|
+
* `itemWrapper`, `noWrapper`, `useSuspense`, `fallback`, `ctx`
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* ```tsx
|
|
156
|
+
* import { CmsContentArea } from '@remkoj/optimizely-cms-react/rsc'
|
|
157
|
+
*
|
|
158
|
+
* export function MainArea({ items }: { items: any[] }) {
|
|
159
|
+
* return (
|
|
160
|
+
* <CmsContentArea
|
|
161
|
+
* items={items}
|
|
162
|
+
* fieldName="MainContentArea"
|
|
163
|
+
* as="section"
|
|
164
|
+
* className="main-content-area"
|
|
165
|
+
* />
|
|
166
|
+
* )
|
|
167
|
+
* }
|
|
168
|
+
* ```
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
* ```tsx
|
|
172
|
+
* import { CmsContentArea } from '@remkoj/optimizely-cms-react/rsc'
|
|
173
|
+
*
|
|
174
|
+
* export function GridArea({ items }: { items: any[] }) {
|
|
175
|
+
* return (
|
|
176
|
+
* <CmsContentArea
|
|
177
|
+
* items={items}
|
|
178
|
+
* itemWrapper={{ as: 'article', className: 'grid-item' }}
|
|
179
|
+
* classMapper={(displayOption) => `display-${displayOption}`}
|
|
180
|
+
* useSuspense
|
|
181
|
+
* fallback={<div>Loading component…</div>}
|
|
182
|
+
* />
|
|
183
|
+
* )
|
|
184
|
+
* }
|
|
185
|
+
* ```
|
|
186
|
+
*
|
|
187
|
+
* @remarks
|
|
188
|
+
* For a full prop reference, see `CmsContentAreaProps`.
|
|
41
189
|
*/
|
|
42
190
|
export const CmsContentArea = cmsContentAware(serverContextAware(BaseContentArea), CmsContent);
|
|
43
191
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rsc-components.js","sourceRoot":"","sources":["../../src/components/rsc-components.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAMZ,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;AAS7B;;;;;;GAMG;AACH,SAAS,kBAAkB,CACzB,SAAsC;IAEtC,MAAM,aAAa,GAAG,SAA6B,CAAA;IAEnD,MAAM,qBAAqB,GAEvB,CAAC,EAAE,GAAG,EAAE,GAAG,KAAK,EAAE,EAAE,EAAE;QACxB,IAAI,CAAC,GAAG;YACN,OAAO,CAAC,KAAK,CACX,+DAA+D,aAAa,CAAC,WAAW,IAAI,aAAa,CAAC,IAAI,IAAI,aAAa,kBAAkB,CAClJ,CAAA;QACH,MAAM,MAAM,GAAG,GAAG,IAAI,gBAAgB,EAAE,CAAA;QACxC,MAAM,cAAc,GAAG,EAAE,GAAG,KAAK,EAAE,GAAG,EAAE,MAAM,EAAO,CAAA;QACrD,OAAO,KAAC,aAAa,OAAK,cAAc,GAAI,CAAA;IAC9C,CAAC,CAAA;IACD,qBAAqB,CAAC,WAAW,GAAG,yBAAyB,CAAA;IAC7D,OAAO,qBAAqB,CAAA;AAC9B,CAAC;AAED
|
|
1
|
+
{"version":3,"file":"rsc-components.js","sourceRoot":"","sources":["../../src/components/rsc-components.tsx"],"names":[],"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CACW,CAAA;AAGzB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoDG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,kBAAkB,CAC1C,cAAoD,CAC9B,CAAA;AAGxB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,eAAe,CAC3C,kBAAkB,CAAC,eAAe,CAAC,EACnC,UAAU,CACgB,CAAA;AAQ5B;;;;GAIG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,eAAe,CAClD,kBAAkB,CAAC,yBAAyB,CAAC,EAC7C,UAAU,CACuB,CAAA;AAEnC;;GAEG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,kBAAkB,CAAC,YAAY,CAAsB,CAAA"}
|
package/dist/components/rsc.d.ts
CHANGED
|
@@ -3,6 +3,8 @@ export type { BaseStyleDefinition, ElementStyleDefinition, LayoutProps, LayoutPr
|
|
|
3
3
|
export { extractSettings, readSetting } from './cms-styles/index.js';
|
|
4
4
|
export * from './cms-styles/index.js';
|
|
5
5
|
export { isNode, isComponentNode, isComponentNodeOfType, isStructureNode, isElementNode, } from './visual-builder/functions.js';
|
|
6
|
+
export type { CompositionNode, CompositionNodeBase, CompositionComponentNode, CompositionStructureNode, CompositionComponentType, LeafPropsFactory, NodePropsFactory, } from './visual-builder/types.js';
|
|
7
|
+
export { StructureNodeTypes, } from './visual-builder/types.js';
|
|
6
8
|
export type { RichTextComponent, RichTextProps, RichTextNode, StringNode, TypedNode, NodeInput, } from './rich-text/index.js';
|
|
7
9
|
export { DefaultComponents as RichTextComponentDictionary, createHtmlComponent, } from './rich-text/components.js';
|
|
8
10
|
export { isNodeInput, isNonEmptyString, isRichTextNode, isStringNode, isText, isTypedNode, } from './rich-text/utils.js';
|
package/dist/components/rsc.js
CHANGED
|
@@ -3,6 +3,7 @@ export { extractSettings, readSetting } from './cms-styles/index.js';
|
|
|
3
3
|
export * from './cms-styles/index.js';
|
|
4
4
|
// Visual Builder items
|
|
5
5
|
export { isNode, isComponentNode, isComponentNodeOfType, isStructureNode, isElementNode, } from './visual-builder/functions.js';
|
|
6
|
+
export { StructureNodeTypes, } from './visual-builder/types.js';
|
|
6
7
|
export { DefaultComponents as RichTextComponentDictionary, createHtmlComponent, } from './rich-text/components.js';
|
|
7
8
|
export { isNodeInput, isNonEmptyString, isRichTextNode, isStringNode, isText, isTypedNode, } from './rich-text/utils.js';
|
|
8
9
|
//# sourceMappingURL=rsc.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rsc.js","sourceRoot":"","sources":["../../src/components/rsc.tsx"],"names":[],"mappings":"AAAA,OAAO,aAAa,CAAA;AAepB,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,MAAM,+BAA+B,CAAA;
|
|
1
|
+
{"version":3,"file":"rsc.js","sourceRoot":"","sources":["../../src/components/rsc.tsx"],"names":[],"mappings":"AAAA,OAAO,aAAa,CAAA;AAepB,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,MAAM,+BAA+B,CAAA;AAYtC,OAAO,EACL,kBAAkB,GACnB,MAAM,2BAA2B,CAAA;AAUlC,OAAO,EACL,iBAAiB,IAAI,2BAA2B,EAChD,mBAAmB,GACpB,MAAM,2BAA2B,CAAA;AAClC,OAAO,EACL,WAAW,EACX,gBAAgB,EAChB,cAAc,EACd,YAAY,EACZ,MAAM,EACN,WAAW,GACZ,MAAM,sBAAsB,CAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isContentType } from '../../utilities.js';
|
|
1
|
+
import { isContentType, isNotNullOrUndefined } from '../../utilities.js';
|
|
2
2
|
import { isContentLink, isInlineContentLink } from '@remkoj/optimizely-graph-client';
|
|
3
3
|
/**
|
|
4
4
|
* Test if the Node within VisualBuilder is an Element
|
|
@@ -60,25 +60,18 @@ export const defaultPropsFactory = (node) => {
|
|
|
60
60
|
template: node.template,
|
|
61
61
|
settings: node.settings,
|
|
62
62
|
};
|
|
63
|
-
return [contentLink, contentType, node.component, layoutData];
|
|
63
|
+
return [contentLink, contentType, node.key || undefined, node.component, layoutData];
|
|
64
64
|
};
|
|
65
65
|
export const defaultNodePropsFactory = (node) => {
|
|
66
|
+
const componentMainName = node.type ? (node.layoutType === 'experience' ? node.type + "Node" : node.type) : undefined;
|
|
66
67
|
const componentTypes = [
|
|
67
|
-
|
|
68
|
-
node.template
|
|
69
|
-
[ucFirst(node.
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
node.template && [node.template, ucFirst(node.layoutType), "Nodes", "Content"].filter(x => x),
|
|
73
|
-
// Old style logic
|
|
74
|
-
[node.template, ucFirst(node.type), ucFirst(node.layoutType), "Component", "Content"].filter(x => x),
|
|
75
|
-
(node.template && node.type) ? [node.type ? ucFirst(node.type) : null, ucFirst(node.layoutType), "Component", "Content"].filter(x => x) : null,
|
|
76
|
-
// Fallback
|
|
77
|
-
["Node", "Content"],
|
|
78
|
-
["Node", "Component", "Content"]
|
|
79
|
-
].filter(x => x);
|
|
68
|
+
componentMainName ? [componentMainName] : undefined,
|
|
69
|
+
node.template ? [node.template] : undefined,
|
|
70
|
+
[ucFirst(node.layoutType) + 'Node'],
|
|
71
|
+
['Node']
|
|
72
|
+
].filter(isNotNullOrUndefined);
|
|
80
73
|
const contentLink = { key: node.key ?? '', isInline: true };
|
|
81
|
-
const componentData = { __name: node.name };
|
|
74
|
+
const componentData = { __name: node.name, ...node.component };
|
|
82
75
|
const layoutData = {
|
|
83
76
|
type: node.type,
|
|
84
77
|
layoutType: node.layoutType,
|
|
@@ -87,7 +80,7 @@ export const defaultNodePropsFactory = (node) => {
|
|
|
87
80
|
};
|
|
88
81
|
if (!(isContentLink(contentLink) || isInlineContentLink(contentLink)))
|
|
89
82
|
throw new Error("🔴 [VisualBuilder] Invalid content link: " + JSON.stringify(contentLink) + " - Node: " + JSON.stringify(node));
|
|
90
|
-
return [contentLink, componentTypes, componentData, layoutData];
|
|
83
|
+
return [contentLink, componentTypes, node.key || undefined, componentData, layoutData];
|
|
91
84
|
};
|
|
92
85
|
export function ucFirst(input) {
|
|
93
86
|
if (typeof (input) == 'string' && input.length > 0)
|
|
@@ -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;
|
|
1
|
+
{"version":3,"file":"functions.js","sourceRoot":"","sources":["../../../src/components/visual-builder/functions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAA;AACxE,OAAO,EAAE,aAAa,EAAyB,mBAAmB,EAAE,MAAM,iCAAiC,CAAA;AAG3G;;;;;;GAMG;AACH,MAAM,UAAU,aAAa,CAAC,IAA0C;IACtE,OAAO,eAAe,CAAC,IAAI,CAAC,CAAA;AAC9B,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,IAA0C;IACxE,OAAO,IAAI,CAAC,UAAU,IAAI,WAAW,CAAA;AACvC,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAiC,IAA0C,EAAE,IAA+C;IAC/J,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC;QACxB,OAAO,KAAK,CAAA;IACd,OAAO,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;AAC7B,CAAC;AAED,MAAM,UAAU,eAAe,CAA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AW,GAA8B,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,IAAI,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAA;IACtF,MAAM,aAAa,GAAO,EAAE,MAAM,EAAE,IAAI,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,SAAS,EAAmB,CAAA;IACnF,MAAM,UAAU,GAAG;QACjB,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,UAAU,EAAE,IAAI,CAAC,UAAU;QAC3B,QAAQ,EAAE,IAAI,CAAC,QAAQ;QACvB,QAAQ,EAAE,IAAI,CAAC,QAAQ;KACxB,CAAA;IAED,IAAI,CAAC,CAAC,aAAa,CAAC,WAAW,CAAC,IAAI,mBAAmB,CAAC,WAAW,CAAC,CAAC;QACnE,MAAM,IAAI,KAAK,CAAC,2CAA2C,GAAG,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,GAAG,WAAW,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAA;IAEjI,OAAO,CAAC,WAAW,EAAE,cAAc,EAAE,IAAI,CAAC,GAAG,IAAI,SAAS,EAAE,aAAa,EAAE,UAAU,CAAC,CAAA;AACxF,CAAC,CAAA;AAED,MAAM,UAAU,OAAO,CAAC,KAAgC;IACtD,IAAI,OAAO,CAAC,KAAK,CAAC,IAAI,QAAQ,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC;QAChD,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAA;IACpD,OAAO,IAAI,CAAA;AACb,CAAC"}
|
|
@@ -7,5 +7,7 @@ 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
|
|
10
|
+
export declare function OptimizelyComposition({ node, leafPropsFactory, nodePropsFactory, ctx, cmsContent: CmsContent, isMaster }: BaseOptimizelyCompositionProps & {
|
|
11
|
+
isMaster: boolean;
|
|
12
|
+
}): ReactNode;
|
|
11
13
|
export default OptimizelyComposition;
|
|
@@ -1,36 +1,39 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { isComponentNode, defaultNodePropsFactory, defaultPropsFactory, } from './functions.js';
|
|
2
|
+
import { isComponentNode, isStructureNode, 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, }) {
|
|
10
|
-
const { factory
|
|
9
|
+
export function OptimizelyComposition({ node, leafPropsFactory = defaultPropsFactory, nodePropsFactory = defaultNodePropsFactory, ctx, cmsContent: CmsContent, isMaster = true }) {
|
|
10
|
+
const { factory } = ctx;
|
|
11
|
+
// If this is the master composition and the node is a structure node with children, render
|
|
12
|
+
// the children directly to avoid unnecessary nesting
|
|
13
|
+
if (isMaster && isStructureNode(node) && Array.isArray(node.nodes) && node.nodes.length > 0) {
|
|
14
|
+
return node.nodes.map((child) => {
|
|
15
|
+
const childKey = child.key ? child.key : `vb::${JSON.stringify(child)}`;
|
|
16
|
+
return (_jsx(OptimizelyComposition, { node: child, leafPropsFactory: leafPropsFactory, nodePropsFactory: nodePropsFactory, ctx: ctx, cmsContent: CmsContent, isMaster: false }, childKey));
|
|
17
|
+
});
|
|
18
|
+
}
|
|
11
19
|
// Render the element
|
|
12
20
|
if (isComponentNode(node)) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const [contentLink, contentType, fragmentData, layoutProps] = leafPropsFactory(node);
|
|
16
|
-
return (_jsx(CmsContent, { contentLink: contentLink, contentType: contentType, fragmentData: fragmentData, layoutProps: layoutProps, ctx: ctx }));
|
|
21
|
+
const [contentLink, contentType, nodeId, fragmentData, layoutProps] = leafPropsFactory(node);
|
|
22
|
+
return (_jsx(CmsContent, { contentLink: contentLink, contentType: contentType, fragmentData: fragmentData, layoutProps: layoutProps, editorComponentId: nodeId || contentLink.key || undefined, ctx: ctx }));
|
|
17
23
|
}
|
|
18
|
-
// Debug
|
|
19
|
-
if (isDebug)
|
|
20
|
-
console.log(`⚪ [VisualBuilder] Rendering structure node ${JSON.stringify(node)}`);
|
|
21
24
|
// Ensure we've got a factory
|
|
22
25
|
if (!factory)
|
|
23
|
-
throw new Error('🟡 [VisualBuilder] [OptimizelyComposition] The factory must be defined within the
|
|
24
|
-
const [contentLink, contentTypes, fragmentData, layoutProps] = nodePropsFactory(node);
|
|
26
|
+
throw new Error('🟡 [VisualBuilder] [OptimizelyComposition] The factory must be defined within the Context');
|
|
27
|
+
const [contentLink, contentTypes, nodeId, fragmentData, layoutProps] = nodePropsFactory(node);
|
|
25
28
|
const firstExistingType = contentTypes
|
|
26
|
-
.map((ct) => factory.has([...ct].reverse()))
|
|
29
|
+
.map((ct) => factory.has(Array.isArray(ct) ? [...ct].reverse() : ct))
|
|
27
30
|
.indexOf(true);
|
|
28
31
|
const contentType = contentTypes[firstExistingType];
|
|
29
32
|
if (!contentType)
|
|
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) => {
|
|
33
|
+
throw new Error(`🟡 [VisualBuilder] [OptimizelyComposition] The factory must have a definition for one of these types: ${contentTypes.map((x) => Array.isArray(x) ? x.join('/') : x).join(', ')}`);
|
|
34
|
+
return (_jsx(CmsContent, { contentType: contentType, contentLink: contentLink, fragmentData: fragmentData, layoutProps: layoutProps, editorComponentId: nodeId || contentLink.key || undefined, noDataLoad: true, ctx: ctx, children: (node.nodes ?? []).map((child) => {
|
|
32
35
|
const childKey = child.key ? child.key : `vb::${JSON.stringify(child)}`;
|
|
33
|
-
return (_jsx(OptimizelyComposition, { node: child, leafPropsFactory: leafPropsFactory, nodePropsFactory: nodePropsFactory, ctx: ctx, cmsContent: CmsContent }, childKey));
|
|
36
|
+
return (_jsx(OptimizelyComposition, { node: child, leafPropsFactory: leafPropsFactory, nodePropsFactory: nodePropsFactory, ctx: ctx, cmsContent: CmsContent, isMaster: false }, childKey));
|
|
34
37
|
}) }));
|
|
35
38
|
}
|
|
36
39
|
export default OptimizelyComposition;
|
|
@@ -1 +1 @@
|
|
|
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,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/visual-builder/index.tsx"],"names":[],"mappings":";AACA,OAAO,EACL,eAAe,EACf,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,EACtB,QAAQ,GAAG,IAAI,EACwC;IACvD,MAAM,EAAE,OAAO,EAAE,GAAG,GAAG,CAAA;IAEvB,4FAA4F;IAC5F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C,GAAG,EAAE,GAAG,EACR,UAAU,EAAE,UAAU,EACtB,QAAQ,EAAE,KAAK,IANV,QAAQ,CAOb,CACH,CAAA;QACH,CAAC,CAAC,GACS,CACd,CAAA;AACH,CAAC;AAED,eAAe,qBAAqB,CAAA"}
|
|
@@ -22,6 +22,7 @@ export type CompositionNodeBase = {
|
|
|
22
22
|
export type CompositionStructureNode = CompositionNodeBase & {
|
|
23
23
|
layoutType: "experience" | "section" | "row" | "column";
|
|
24
24
|
nodes?: Array<CompositionNode>;
|
|
25
|
+
component?: Record<string, any>;
|
|
25
26
|
};
|
|
26
27
|
export type CompositionComponentNode<E extends Record<string, any> = Record<string, any>> = CompositionNodeBase & {
|
|
27
28
|
layoutType: "component";
|
|
@@ -34,8 +35,13 @@ export type CompositionComponentType<NT extends CompositionNode> = ComponentType
|
|
|
34
35
|
} : PropsWithChildren<{
|
|
35
36
|
node: Omit<NT, 'nodes'>;
|
|
36
37
|
}>>;
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
/**
|
|
39
|
+
* Get the props to render a leaf inside an experience
|
|
40
|
+
*
|
|
41
|
+
* @returns An array with the contentLink, Content Type, Node ID, Loaded Data & Layout Properties
|
|
42
|
+
*/
|
|
43
|
+
export type LeafPropsFactory = <ET extends Record<string, any>, LT = string>(node: CompositionComponentNode<ET>) => [ContentLinkWithLocale<LT> | InlineContentLinkWithLocale<LT>, ContentType, string | undefined, ET] | [ContentLinkWithLocale<LT> | InlineContentLinkWithLocale<LT>, ContentType, string | undefined, ET, Record<string, any>];
|
|
44
|
+
export type NodePropsFactory = <ET extends Record<string, any>, LT = string>(node: CompositionStructureNode) => [ContentLinkWithLocale<LT> | InlineContentLinkWithLocale<LT>, Array<ContentType>, string | undefined, ET] | [ContentLinkWithLocale<LT> | InlineContentLinkWithLocale<LT>, Array<ContentType>, string | undefined, ET, Record<string, any>];
|
|
39
45
|
export type OptimizelyCompositionProps = PropsWithOptionalContext<JSX.IntrinsicAttributes & {
|
|
40
46
|
/**
|
|
41
47
|
* The Visual Builder node to start rendering from
|
package/dist/context/client.js
CHANGED
|
@@ -13,8 +13,11 @@ export var OptimizelyCmsMode;
|
|
|
13
13
|
})(OptimizelyCmsMode || (OptimizelyCmsMode = {}));
|
|
14
14
|
export class ClientContextInstance {
|
|
15
15
|
constructor(cfg, components) {
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
this.client = isOptiGraphClient(cfg.client)
|
|
17
|
+
? cfg.client
|
|
18
|
+
: isOptiGraphConfig(cfg.client)
|
|
19
|
+
? createClient(cfg.client)
|
|
20
|
+
: createClient();
|
|
18
21
|
this.factory = new DefaultComponentFactory(components);
|
|
19
22
|
this.inEditMode = cfg.inEditMode;
|
|
20
23
|
this.inPreviewMode = cfg.inPreviewMode;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/context/client.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AACZ,OAAO,EACL,aAAa,EACb,UAAU,EACV,QAAQ,EACR,OAAO,GAKR,MAAM,OAAO,CAAA;AACd,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EACjB,YAAY,GAGb,MAAM,iCAAiC,CAAA;AAExC,OAAO,EACL,UAAU,EAGV,uBAAuB,GACxB,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAA;AAC/D,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AAEpD,MAAM,CAAN,IAAkB,iBAIjB;AAJD,WAAkB,iBAAiB;IACjC,wCAAmB,CAAA;IACnB,kCAAa,CAAA;IACb,wCAAmB,CAAA;AACrB,CAAC,EAJiB,iBAAiB,KAAjB,iBAAiB,QAIlC;AAQD,MAAM,OAAO,qBAAqB;IAUhC,YACE,GAAyB,EACzB,UAAmC;QAEnC,IAAI,GAAG,CAAC,
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/context/client.tsx"],"names":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AAC;QACD,IAAI,2BAA2B,CAAC,QAAiB;YAC/C,8BAA8B,CAAC,QAAQ,CAAC,CAAA;QAC1C,CAAC;QACD,SAAS;QACT,OAAO;QACP,8BAA8B;KAC/B,CAAA;IAED,OAAO,KAAC,WAAW,IAAC,KAAK,EAAE,QAAQ,YAAG,QAAQ,GAAe,CAAA;AAC/D,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAG,EAAE;IACnC,OAAO,UAAU,CAAC,cAAc,CAAC,CAAA;AACnC,CAAC,CAAA;AAED,MAAM,UAAU,wBAAwB,CACtC,UAAgC,EAChC,UAAmC;IAEnC,IAAI,CAAC,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
|
@@ -48,7 +48,7 @@ export declare class ServerContext implements GenericContext {
|
|
|
48
48
|
* @deprecated Use the context handed down through the CmsContentArea and CmsContent
|
|
49
49
|
* components
|
|
50
50
|
*/
|
|
51
|
-
export declare const getServerContext: () =>
|
|
51
|
+
export declare const getServerContext: () => never;
|
|
52
52
|
/**
|
|
53
53
|
* Update the shared server context from the provided context. This is compatibility
|
|
54
54
|
* method to ensure that the value returned by `getServerContext` can be retrieved and
|
package/dist/context/rsc.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import 'server-only';
|
|
2
2
|
import { createClient, isOptiGraphClient, } from '@remkoj/optimizely-graph-client';
|
|
3
|
-
import React from 'react';
|
|
4
3
|
import { DefaultComponentFactory, } from '../factory/index.js';
|
|
5
4
|
import { isDebug, isDevelopment } from '../rsc-utilities.js';
|
|
6
5
|
export * from './types.js';
|
|
@@ -90,22 +89,25 @@ export class ServerContext {
|
|
|
90
89
|
setEditableContentIsExperience(isExperience) {
|
|
91
90
|
this._editableIsExperience = isExperience;
|
|
92
91
|
}
|
|
92
|
+
//private _hasWarned: boolean = false;
|
|
93
93
|
toJSON(key) {
|
|
94
94
|
/*if (this.isDebugOrDevelopment) {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
95
|
+
if (!this._hasWarned || this.isDebug) {
|
|
96
|
+
console.warn(
|
|
97
|
+
'🦺 [ServerContext] Converting Context to JSON, this is typically a side effect of the context being passed between Server & Client components', key
|
|
98
|
+
)
|
|
99
|
+
this._hasWarned = true
|
|
100
100
|
}
|
|
101
|
+
if (this.isDebug)
|
|
102
|
+
console.trace()
|
|
101
103
|
}*/
|
|
102
104
|
return {
|
|
105
|
+
client: this.client?.toJSON(),
|
|
103
106
|
inEditMode: this.inEditMode,
|
|
104
107
|
inPreviewMode: this.inPreviewMode,
|
|
105
108
|
isDebug: this.isDebug,
|
|
106
109
|
isDebugOrDevelopment: this.isDebugOrDevelopment,
|
|
107
110
|
isDevelopment: this.isDevelopment,
|
|
108
|
-
clientConfig: this.client?.toJSON(),
|
|
109
111
|
locale: this.locale,
|
|
110
112
|
};
|
|
111
113
|
}
|
|
@@ -123,9 +125,7 @@ export class ServerContext {
|
|
|
123
125
|
* components
|
|
124
126
|
*/
|
|
125
127
|
export const getServerContext = () => {
|
|
126
|
-
|
|
127
|
-
console.debug('🦺 [ServerContext] getServerContext has been deprecated, this provides an instance of the Server Context that is potentially shared between requests');
|
|
128
|
-
return internalGetServerContext();
|
|
128
|
+
throw new Error('🦺 [ServerContext] getServerContext has been removed, due to potential leakage across requests');
|
|
129
129
|
};
|
|
130
130
|
/**
|
|
131
131
|
* Update the shared server context from the provided context. This is compatibility
|
|
@@ -138,38 +138,7 @@ export const getServerContext = () => {
|
|
|
138
138
|
* @returns The updated shared server context
|
|
139
139
|
*/
|
|
140
140
|
export function updateSharedServerContext(currentCtx) {
|
|
141
|
-
|
|
142
|
-
// Update component factory
|
|
143
|
-
serverCtx.setComponentFactory(currentCtx.factory);
|
|
144
|
-
// Update Optimizely Graph Client
|
|
145
|
-
if (currentCtx.client)
|
|
146
|
-
serverCtx.setOptimizelyGraphClient(currentCtx.client);
|
|
147
|
-
// Update locale
|
|
148
|
-
if (currentCtx.locale)
|
|
149
|
-
serverCtx.setLocale(currentCtx.locale);
|
|
150
|
-
// Update mode
|
|
151
|
-
if (currentCtx.inEditMode)
|
|
152
|
-
serverCtx.setMode('edit');
|
|
153
|
-
else if (currentCtx.inPreviewMode)
|
|
154
|
-
serverCtx.setMode('preview');
|
|
155
|
-
else if (!currentCtx.inEditMode && !currentCtx.inPreviewMode)
|
|
156
|
-
serverCtx.setMode('public');
|
|
157
|
-
// Update editable content
|
|
158
|
-
serverCtx.setEditableContentId(currentCtx.editableContent);
|
|
159
|
-
return serverCtx;
|
|
141
|
+
throw new Error('🦺 [ServerContext] getServerContext has been removed, due to potential leakage across requests');
|
|
160
142
|
}
|
|
161
|
-
const cachePlaceholder = (factory) => {
|
|
162
|
-
if (isDebug() || isDevelopment())
|
|
163
|
-
console.warn('🚧 [React Context] Running client/server react code instead of server context, no cache() available.');
|
|
164
|
-
return factory;
|
|
165
|
-
};
|
|
166
|
-
//@ts-ignore React.cache is only available in the react-server context
|
|
167
|
-
const cache = (React.cache || cachePlaceholder);
|
|
168
|
-
const internalGetServerContext = cache(() => {
|
|
169
|
-
const ctx = new ServerContext({});
|
|
170
|
-
if (ctx.isDebug)
|
|
171
|
-
console.log('🦺 [ServerContext] Created new context');
|
|
172
|
-
return ctx;
|
|
173
|
-
});
|
|
174
143
|
//#endregion
|
|
175
144
|
//# sourceMappingURL=rsc.js.map
|
package/dist/context/rsc.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rsc.js","sourceRoot":"","sources":["../../src/context/rsc.tsx"],"names":[],"mappings":"AAAA,OAAO,aAAa,CAAA;AACpB,OAAO,EACL,YAAY,EACZ,iBAAiB,GAGlB,MAAM,iCAAiC,CAAA;
|
|
1
|
+
{"version":3,"file":"rsc.js","sourceRoot":"","sources":["../../src/context/rsc.tsx"],"names":[],"mappings":"AAAA,OAAO,aAAa,CAAA;AACpB,OAAO,EACL,YAAY,EACZ,iBAAiB,GAGlB,MAAM,iCAAiC,CAAA;AAMxC,OAAO,EAGL,uBAAuB,GACxB,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAE5D,cAAc,YAAY,CAAA;AAU1B,MAAM,OAAO,aAAa;IAQxB,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,OAAO,CAAA;IACrB,CAAC;IACD,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,QAAQ,CAAA;IACtB,CAAC;IAED,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,OAAO,CAAA;IACrB,CAAC;IACD,IAAI,UAAU;QACZ,OAAO,IAAI,CAAC,KAAK,IAAI,MAAM,CAAA;IAC7B,CAAC;IACD,IAAI,aAAa;QACf,OAAO,IAAI,CAAC,KAAK,IAAI,SAAS,CAAA;IAChC,CAAC;IACD,IAAI,aAAa;QACf,OAAO,aAAa,EAAE,CAAA;IACxB,CAAC;IACD,IAAI,OAAO;QACT,OAAO,OAAO,EAAE,CAAA;IAClB,CAAC;IACD,IAAI,oBAAoB;QACtB,OAAO,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,aAAa,CAAA;IAC3C,CAAC;IACD,IAAI,eAAe;QACjB,OAAO,IAAI,CAAC,SAAS,CAAA;IACvB,CAAC;IACD,IAAI,2BAA2B;QAC7B,OAAO,IAAI,CAAC,qBAAqB,CAAA;IACnC,CAAC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,EAAE,IAAI,CAAC,MAAM;SACpB,CAAA;IACH,CAAC;CACF;AAED,+FAA+F;AAC/F;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAG,EAAE;IACjC,MAAM,IAAI,KAAK,CACb,gGAAgG,CACjG,CAAA;AACL,CAAC,CAAA;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,yBAAyB,CACvC,UAA0B;IAE1B,MAAM,IAAI,KAAK,CACX,gGAAgG,CACjG,CAAA;AACL,CAAC;AACD,YAAY"}
|
package/dist/context/shared.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { isOptiGraphConfig } from "@remkoj/optimizely-graph-client";
|
|
1
2
|
export function isTransferrableContext(ctxIn) {
|
|
2
|
-
return typeof (ctxIn) == 'object' && ctxIn != null && ctxIn.factory === undefined;
|
|
3
|
+
return typeof (ctxIn) == 'object' && ctxIn != null && ctxIn.factory === undefined && isOptiGraphConfig(ctxIn.client);
|
|
3
4
|
}
|
|
4
5
|
export function isGenericContext(ctxIn) {
|
|
5
6
|
return typeof (ctxIn) == 'object' && ctxIn != null && typeof ctxIn.factory == 'object' && ctxIn.factory != null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../../src/context/shared.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../../src/context/shared.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AAEpE,MAAM,UAAU,sBAAsB,CAAC,KAA0B;IAC/D,OAAO,OAAO,CAAC,KAAK,CAAC,IAAI,QAAQ,IAAI,KAAK,IAAI,IAAI,IAAK,KAAwB,CAAC,OAAO,KAAK,SAAS,IAAI,iBAAiB,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;AAC1I,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,KAA0B;IACzD,OAAO,OAAO,CAAC,KAAK,CAAC,IAAI,QAAQ,IAAI,KAAK,IAAI,IAAI,IAAI,OAAQ,KAAwB,CAAC,OAAO,IAAI,QAAQ,IAAK,KAAwB,CAAC,OAAO,IAAI,IAAI,CAAA;AACzJ,CAAC"}
|
package/dist/context/types.d.ts
CHANGED
|
@@ -16,17 +16,9 @@ export interface GenericContext {
|
|
|
16
16
|
/**
|
|
17
17
|
* The context information that can cross the React Server/Client boundary
|
|
18
18
|
*/
|
|
19
|
-
export
|
|
20
|
-
readonly
|
|
21
|
-
|
|
22
|
-
readonly inEditMode: boolean;
|
|
23
|
-
readonly inPreviewMode: boolean;
|
|
24
|
-
readonly isDevelopment: boolean;
|
|
25
|
-
readonly isDebug: boolean;
|
|
26
|
-
readonly isDebugOrDevelopment: boolean;
|
|
27
|
-
readonly editableContent?: ContentLink | null;
|
|
28
|
-
readonly editableContentIsExperience?: boolean;
|
|
29
|
-
}
|
|
19
|
+
export type TransferrableContext = {
|
|
20
|
+
readonly client?: OptimizelyGraphConfig;
|
|
21
|
+
} & Readonly<Omit<GenericContext, 'client' | 'factory'>>;
|
|
30
22
|
export type BaseContext = TransferrableContext | GenericContext;
|
|
31
23
|
export type PropsWithContext<P = {}> = P & {
|
|
32
24
|
ctx: GenericContext;
|
|
@@ -8,6 +8,15 @@ export declare const EmptyComponentHandle = "$$fragment$$";
|
|
|
8
8
|
export declare class DefaultComponentFactory implements ComponentFactory {
|
|
9
9
|
private registry;
|
|
10
10
|
private dbg;
|
|
11
|
+
/**
|
|
12
|
+
* A list of interfaces to ignore when resolving components. Adjust this
|
|
13
|
+
* list if you're experiencing issues with resolving components due to
|
|
14
|
+
* contracts. Values **must be** provided lowercase and without leading
|
|
15
|
+
* underscore. For example `_Item` must be provided as `item`.
|
|
16
|
+
*
|
|
17
|
+
* The default value includes the common ones for SaaS CMS.
|
|
18
|
+
*/
|
|
19
|
+
ignoredContracts: string[];
|
|
11
20
|
/**
|
|
12
21
|
* Create a new instance of the DefaultComponentFactory
|
|
13
22
|
*
|
|
@@ -15,10 +24,18 @@ export declare class DefaultComponentFactory implements ComponentFactory {
|
|
|
15
24
|
* with the factory.
|
|
16
25
|
*/
|
|
17
26
|
constructor(initialComponents?: ComponentTypeDictionary);
|
|
18
|
-
register(type: ComponentTypeHandle, component: ComponentType, useSuspense?: boolean, loader?: ComponentType): void;
|
|
27
|
+
register(type: ComponentTypeHandle, component: ComponentType, useSuspense?: boolean, loader?: ComponentType, variant?: string): void;
|
|
19
28
|
registerAll(components: ComponentTypeDictionary): void;
|
|
20
|
-
has(type: ComponentTypeHandle): boolean;
|
|
21
|
-
resolve(type: ComponentTypeHandle): undefined | ComponentType;
|
|
29
|
+
has(type: ComponentTypeHandle, variant?: string): boolean;
|
|
30
|
+
resolve(type: ComponentTypeHandle, variant?: string): undefined | ComponentType;
|
|
22
31
|
extract(): ComponentTypeDictionary;
|
|
23
32
|
remove(type: ComponentTypeHandle): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Process the component variant handle into
|
|
35
|
+
*
|
|
36
|
+
* @param handle
|
|
37
|
+
* @param variant
|
|
38
|
+
* @returns
|
|
39
|
+
*/
|
|
40
|
+
private processComponentTypeHandle;
|
|
24
41
|
}
|