@remkoj/optimizely-cms-react 6.0.0-pre7 → 6.0.0-pre9
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/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 +45 -49
- package/dist/components/cms-content/get-content.js.map +1 -1
- package/dist/components/cms-content/resolve-component.js +9 -4
- 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 +8 -0
- 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-editable/index.d.ts +9 -3
- package/dist/components/cms-editable/index.js +13 -7
- package/dist/components/cms-editable/index.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 +3 -3
- package/dist/components/visual-builder/functions.js.map +1 -1
- package/dist/components/visual-builder/index.js +12 -8
- 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.js +0 -5
- package/dist/factory/default.js.map +1 -1
- package/dist/types.d.ts +37 -6
- package/dist/utilities.d.ts +54 -4
- package/dist/utilities.js +100 -7
- package/dist/utilities.js.map +1 -1
- package/package.json +16 -12
|
@@ -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,
|
|
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,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,CAAC,IAA0C;IACxE,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC,CAAA;AAC/B,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,MAAM,CAAC,MAAW;IAChC,IAAI,OAAO,CAAC,MAAM,CAAC,IAAI,QAAQ,IAAI,MAAM,IAAI,IAAI;QAC/C,OAAO,KAAK,CAAA;IAEd,MAAM,SAAS,GAAG,CAAC,YAAY,EAAE,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE,WAAW,CAAC,CAAA;IACzE,MAAM,YAAY,GAAG,CAAC,OAAQ,MAA0B,CAAC,IAAI,IAAI,QAAQ,IAAI,CAAE,MAA0B,CAAC,IAAI,EAAE,MAAM,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC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AC,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"}
|
|
@@ -10,25 +10,29 @@ export function OptimizelyComposition({ node, leafPropsFactory = defaultPropsFac
|
|
|
10
10
|
const { factory, isDebug } = ctx;
|
|
11
11
|
// Render the element
|
|
12
12
|
if (isComponentNode(node)) {
|
|
13
|
-
if (isDebug)
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
/*if (isDebug)
|
|
14
|
+
console.log(
|
|
15
|
+
`⚪ [VisualBuilder] Rendering element node ${JSON.stringify(node)}`
|
|
16
|
+
)*/
|
|
17
|
+
const [contentLink, contentType, nodeId, fragmentData, layoutProps] = leafPropsFactory(node);
|
|
18
|
+
return (_jsx(CmsContent, { contentLink: contentLink, contentType: contentType, fragmentData: fragmentData, layoutProps: layoutProps, editorComponentId: nodeId || contentLink.key || undefined, ctx: ctx }));
|
|
17
19
|
}
|
|
18
20
|
// Debug
|
|
19
|
-
if (isDebug)
|
|
20
|
-
|
|
21
|
+
/*if (isDebug)
|
|
22
|
+
console.log(
|
|
23
|
+
`⚪ [VisualBuilder] Rendering structure node ${JSON.stringify(node)}`
|
|
24
|
+
)*/
|
|
21
25
|
// Ensure we've got a factory
|
|
22
26
|
if (!factory)
|
|
23
27
|
throw new Error('🟡 [VisualBuilder] [OptimizelyComposition] The factory must be defined within the serverContext');
|
|
24
|
-
const [contentLink, contentTypes, fragmentData, layoutProps] = nodePropsFactory(node);
|
|
28
|
+
const [contentLink, contentTypes, nodeId, fragmentData, layoutProps] = nodePropsFactory(node);
|
|
25
29
|
const firstExistingType = contentTypes
|
|
26
30
|
.map((ct) => factory.has([...ct].reverse()))
|
|
27
31
|
.indexOf(true);
|
|
28
32
|
const contentType = contentTypes[firstExistingType];
|
|
29
33
|
if (!contentType)
|
|
30
34
|
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) => {
|
|
35
|
+
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
36
|
const childKey = child.key ? child.key : `vb::${JSON.stringify(child)}`;
|
|
33
37
|
return (_jsx(OptimizelyComposition, { node: child, leafPropsFactory: leafPropsFactory, nodePropsFactory: nodePropsFactory, ctx: ctx, cmsContent: CmsContent }, childKey));
|
|
34
38
|
}) }));
|
|
@@ -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,GACS;IAC/B,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,GAAG,CAAA;IAEhC,qBAAqB;IACrB,IAAI,eAAe,CAAC,IAAI,CAAC,EAAE,CAAC;QAC1B
|
|
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,EAAE,OAAO,EAAE,GAAG,GAAG,CAAA;IAEhC,qBAAqB;IACrB,IAAI,eAAe,CAAC,IAAI,CAAC,EAAE,CAAC;QAC1B;;;aAGK;QACL,MAAM,CAAC,WAAW,EAAE,WAAW,EAAE,MAAM,EAAE,YAAY,EAAE,WAAW,CAAC,GACjE,gBAAgB,CAAC,IAAI,CAAC,CAAA;QACxB,OAAO,CACL,KAAC,UAAU,IACT,WAAW,EAAE,WAAW,EACxB,WAAW,EAAE,WAAW,EACxB,YAAY,EAAE,YAAY,EAC1B,WAAW,EAAE,WAAW,EACxB,iBAAiB,EAAE,MAAM,IAAI,WAAW,CAAC,GAAG,IAAI,SAAS,EACzD,GAAG,EAAE,GAAG,GACR,CACH,CAAA;IACH,CAAC;IAED,QAAQ;IACR;;;SAGK;IAEL,6BAA6B;IAC7B,IAAI,CAAC,OAAO;QACV,MAAM,IAAI,KAAK,CACb,iGAAiG,CAClG,CAAA;IAEH,MAAM,CAAC,WAAW,EAAE,YAAY,EAAE,MAAM,EAAE,YAAY,EAAE,WAAW,CAAC,GAClE,gBAAgB,CAAC,IAAI,CAAC,CAAA;IACxB,MAAM,iBAAiB,GAAG,YAAY;SACnC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;SAC3C,OAAO,CAAC,IAAI,CAAC,CAAA;IAChB,MAAM,WAAW,GAAG,YAAY,CAAC,iBAAiB,CAAC,CAAA;IACnD,IAAI,CAAC,WAAW;QACd,MAAM,IAAI,KAAK,CACb,yGAAyG,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,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,iBAAiB,EAAE,MAAM,IAAI,WAAW,CAAC,GAAG,IAAI,SAAS,EACzD,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"}
|
|
@@ -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":[],"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,M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B,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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@@ -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;
|
package/dist/factory/default.js
CHANGED
|
@@ -28,21 +28,16 @@ export class DefaultComponentFactory {
|
|
|
28
28
|
}
|
|
29
29
|
register(type, component, useSuspense = false, loader) {
|
|
30
30
|
const registryKey = processComponentTypeHandle(type);
|
|
31
|
-
if (this.dbg)
|
|
32
|
-
console.log(`➕ [DefaultComponentFactory] Registering ${registryKey}`);
|
|
33
31
|
this.registry.set(registryKey, { type, component, useSuspense, loader });
|
|
34
32
|
}
|
|
35
33
|
registerAll(components) {
|
|
36
34
|
components.forEach((c) => {
|
|
37
35
|
const registryKey = processComponentTypeHandle(c.type);
|
|
38
|
-
if (this.dbg)
|
|
39
|
-
console.log(`➕ [DefaultComponentFactory] Registering ${registryKey}`);
|
|
40
36
|
this.registry.set(registryKey, c);
|
|
41
37
|
});
|
|
42
38
|
}
|
|
43
39
|
has(type) {
|
|
44
40
|
const registryKey = processComponentTypeHandle(type);
|
|
45
|
-
//if (this.dbg) console.log(`🔎 [DefaultComponentFactory] Checking for ${ registryKey }`)
|
|
46
41
|
return this.registry.has(registryKey);
|
|
47
42
|
}
|
|
48
43
|
resolve(type) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"default.js","sourceRoot":"","sources":["../../src/factory/default.tsx"],"names":[],"mappings":";AAOA,OAAO,EAAE,QAAQ,E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MAAM;aACV,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,iCAAiC;aACtF,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,IAAI,SAAS,CAAC,CAAC,iCAAiC;aAC7E,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,0BAA0B;aAC3E,IAAI,CAAC,YAAY,CAAC,CAAA,CAAC,kCAAkC;IAC1D,MAAM,IAAI,KAAK,CAAC,kCAAkC,OAAO,MAAM,EAAE,CAAC,CAAA;AACpE,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -3,6 +3,9 @@ import type { DocumentNode } from "graphql";
|
|
|
3
3
|
import type { TypedDocumentNode } from '@graphql-typed-document-node/core';
|
|
4
4
|
import type { ContentLinkWithLocale, ContentLink, InlineContentLinkWithLocale } from "@remkoj/optimizely-graph-client";
|
|
5
5
|
import type { GenericContext } from "./context/types.js";
|
|
6
|
+
import type { CmsEditableProps } from "./components/cms-editable/index.js";
|
|
7
|
+
import type { VariationInput } from "@remkoj/optimizely-graph-client/router";
|
|
8
|
+
export type { VariationInput } from "@remkoj/optimizely-graph-client/router";
|
|
6
9
|
export type ContentType = string[];
|
|
7
10
|
export type {
|
|
8
11
|
/**
|
|
@@ -13,9 +16,10 @@ ContentLink,
|
|
|
13
16
|
* @deprecated Use the export from `@remkoj/optimizely-graph-client` directly
|
|
14
17
|
*/
|
|
15
18
|
ContentLinkWithLocale } from "@remkoj/optimizely-graph-client";
|
|
19
|
+
export type ComponentCmsEditableProps = Pick<CmsEditableProps<'div'>, 'cmsId' | 'ctx' | 'currentContent'>;
|
|
16
20
|
export type CmsComponentProps<T, L extends Record<string, any> = Record<string, any>> = PropsWithChildren<{
|
|
17
21
|
/**
|
|
18
|
-
* The identifier of the content item
|
|
22
|
+
* The identifier of the content item.
|
|
19
23
|
*/
|
|
20
24
|
contentLink: ContentLinkWithLocale | InlineContentLinkWithLocale;
|
|
21
25
|
/**
|
|
@@ -24,22 +28,30 @@ export type CmsComponentProps<T, L extends Record<string, any> = Record<string,
|
|
|
24
28
|
data: T;
|
|
25
29
|
/**
|
|
26
30
|
* Use the Server/Client context instead if you need this information
|
|
31
|
+
*
|
|
32
|
+
* @deprecated
|
|
27
33
|
*/
|
|
28
34
|
inEditMode?: boolean;
|
|
29
35
|
/**
|
|
30
|
-
* Contextual layout data
|
|
36
|
+
* Contextual layout data from an Experience. This will be `undefined` if
|
|
37
|
+
* there's no layout data attached.
|
|
31
38
|
*/
|
|
32
39
|
layoutProps?: L;
|
|
40
|
+
/**
|
|
41
|
+
* The minimal properties needed to render a CmsEditable inside the
|
|
42
|
+
* component.
|
|
43
|
+
*/
|
|
44
|
+
editProps?: ComponentCmsEditableProps;
|
|
33
45
|
/**
|
|
34
46
|
* The context in which this component will be rendered
|
|
35
47
|
*/
|
|
36
48
|
ctx?: GenericContext;
|
|
37
49
|
}>;
|
|
38
|
-
export type ContentQueryProps<LocaleType = string> = ContentLink & {
|
|
50
|
+
export type ContentQueryProps<LocaleType = string> = Omit<ContentLink, 'isInline' | 'variation'> & {
|
|
39
51
|
locale?: Array<LocaleType> | LocaleType | null;
|
|
40
52
|
path?: string | null;
|
|
41
53
|
domain?: string | null;
|
|
42
|
-
|
|
54
|
+
variation?: VariationInput | null;
|
|
43
55
|
};
|
|
44
56
|
/**
|
|
45
57
|
* Extract the data type from a GraphQL Query
|
|
@@ -47,7 +59,22 @@ export type ContentQueryProps<LocaleType = string> = ContentLink & {
|
|
|
47
59
|
export type ResponseDataType<T extends DocumentNode> = T extends TypedDocumentNode<infer DataType> ? DataType : {
|
|
48
60
|
[key: string]: any;
|
|
49
61
|
};
|
|
50
|
-
export type
|
|
62
|
+
export type GetDataQueryResponseTemplate = {
|
|
63
|
+
__typename?: 'Query' | null;
|
|
64
|
+
data?: {
|
|
65
|
+
__typename?: string | null;
|
|
66
|
+
item?: {
|
|
67
|
+
__typename?: string | null;
|
|
68
|
+
_metadata?: {
|
|
69
|
+
key?: string | null;
|
|
70
|
+
locale?: any | null;
|
|
71
|
+
} | null;
|
|
72
|
+
[key: string]: any;
|
|
73
|
+
} | null;
|
|
74
|
+
} | null;
|
|
75
|
+
};
|
|
76
|
+
export type ProcessQueryResponse<T> = T extends GetDataQueryResponseTemplate ? NonNullable<NonNullable<Required<T>['data']>['item']> : T;
|
|
77
|
+
export type GetDataQuery<T> = () => TypedDocumentNode<T, Omit<ContentQueryProps, 'path' | 'domain'>> | DocumentNode;
|
|
51
78
|
export type GetDataFragment<T> = () => [string, TypedDocumentNode<T, never> | DocumentNode | string];
|
|
52
79
|
export type WithGqlFragment<BaseComponent, DataType> = BaseComponent & {
|
|
53
80
|
getDataFragment: GetDataFragment<DataType>;
|
|
@@ -56,7 +83,7 @@ export type WithGqlFragment<BaseComponent, DataType> = BaseComponent & {
|
|
|
56
83
|
export type WithGqlQuery<B, T> = B & {
|
|
57
84
|
getDataQuery: GetDataQuery<T>;
|
|
58
85
|
};
|
|
59
|
-
export type BaseCmsComponent<T = {}, L extends Record<string, any> = Record<string, any>> = T extends never | TypedDocumentNode | DocumentNode ? DynamicCmsComponent<T
|
|
86
|
+
export type BaseCmsComponent<T = {}, L extends Record<string, any> = Record<string, any>> = T extends never | TypedDocumentNode | DocumentNode ? DynamicCmsComponent<ProcessQueryResponse<T>> : ReactComponentType<CmsComponentProps<ProcessQueryResponse<T>, L>>;
|
|
60
87
|
export type DynamicCmsComponent<T extends TypedDocumentNode | DocumentNode = DocumentNode, L extends Record<string, any> = Record<string, any>> = ReactComponentType<CmsComponentProps<ResponseDataType<T>, L>>;
|
|
61
88
|
export type GraphQLFragmentBase = {
|
|
62
89
|
' $fragmentName'?: string;
|
|
@@ -79,4 +106,8 @@ export type CmsComponentWithOptionalQuery<T = DocumentNode, L extends Record<str
|
|
|
79
106
|
export type CmsComponent<T = DocumentNode, L extends Record<string, any> = Record<string, any>> = T extends TypedDocumentNode<infer R, any> ? CmsComponentWithQuery<R, L> : T extends DocumentNode ? CmsComponentWithQuery<{
|
|
80
107
|
[key: string]: any;
|
|
81
108
|
}, L> : T extends GraphQLFragmentBase ? CmsComponentWithFragment<T, L> : T extends GraphQLQueryBase ? CmsComponentWithQuery<T, L> : CmsComponentWithOptionalQuery<T, L>;
|
|
109
|
+
/**
|
|
110
|
+
* A generic Optimizely CMS Component used to render a layout node from an experience, which cannot
|
|
111
|
+
* be loaded directly as independent Content Item from Optimizely Graph
|
|
112
|
+
*/
|
|
82
113
|
export type CmsLayoutComponent<L extends Record<string, any> = Record<string, any>, T = never> = ReactComponentType<CmsComponentProps<T, L>>;
|
package/dist/utilities.d.ts
CHANGED
|
@@ -1,9 +1,24 @@
|
|
|
1
1
|
import type { ComponentType } from 'react';
|
|
2
2
|
import type { DocumentNode } from 'graphql';
|
|
3
|
-
import type { ContentLinkWithLocale, ContentLink } from '@remkoj/optimizely-graph-client';
|
|
4
|
-
import type { ContentType, BaseCmsComponent, CmsComponentWithQuery, CmsComponentWithFragment, WithGqlFragment, ContentQueryProps } from './types.js';
|
|
3
|
+
import type { ContentLinkWithLocale, ContentLink, IOptiGraphClient, InlineContentLink } from '@remkoj/optimizely-graph-client';
|
|
4
|
+
import type { ContentType, BaseCmsComponent, CmsComponentWithQuery, CmsComponentWithFragment, WithGqlFragment, ContentQueryProps, CmsComponentProps } from './types.js';
|
|
5
5
|
import type { ComponentFactory, ComponentTypeHandle } from './factory/types.js';
|
|
6
6
|
export * from './components/rich-text/utils.js';
|
|
7
|
+
/**
|
|
8
|
+
* Safeguard filter to remove default properties from the CmsComponent, intended
|
|
9
|
+
* to prevent these properties to be passed to client components. It will also
|
|
10
|
+
* remove all properties where the name starts with a `_`.
|
|
11
|
+
*
|
|
12
|
+
* @param toFilter The object to filter the
|
|
13
|
+
* @returns W
|
|
14
|
+
*/
|
|
15
|
+
export declare function filterCmsComponentProps<T extends object>(toFilter: T): Omit<T, keyof CmsComponentProps<any>>;
|
|
16
|
+
/**
|
|
17
|
+
*
|
|
18
|
+
*
|
|
19
|
+
* @param toTest
|
|
20
|
+
* @returns
|
|
21
|
+
*/
|
|
7
22
|
export declare function isNonEmptyString(toTest: any): toTest is string;
|
|
8
23
|
export declare function isNotNullOrUndefined<T>(toTest?: T | null): toTest is T;
|
|
9
24
|
export declare function isContentType(toTest: any): toTest is ContentType;
|
|
@@ -44,10 +59,36 @@ export declare function resolveComponentType(factory: ComponentFactory, type: Co
|
|
|
44
59
|
export declare function isCmsComponentWithDataQuery<T = DocumentNode>(toTest?: BaseCmsComponent<T>): toTest is CmsComponentWithQuery<T>;
|
|
45
60
|
export declare function isCmsComponentWithFragment<T = DocumentNode>(toTest?: BaseCmsComponent<T>): toTest is CmsComponentWithFragment<T>;
|
|
46
61
|
export declare function validatesFragment<T extends ComponentType<any>>(toTest?: T): toTest is T & Pick<Required<WithGqlFragment<T, any>>, "validateFragment">;
|
|
47
|
-
|
|
62
|
+
/**
|
|
63
|
+
* Take a ContentLink and transform it into the normalized set of request variables used query for content across
|
|
64
|
+
* multiple components.
|
|
65
|
+
*
|
|
66
|
+
* @param contentLink The contentlink to transform
|
|
67
|
+
* @param client If provided, the the configuration of the client is applied to the variables
|
|
68
|
+
* @returns The request variables to use for querying Optimizely Graph
|
|
69
|
+
*/
|
|
70
|
+
export declare function contentLinkToRequestVariables(contentLink: ContentLinkWithLocale, client: IOptiGraphClient): ContentQueryProps;
|
|
71
|
+
/**
|
|
72
|
+
* Normalizes a string|null|undefined input to a non-empty string or undefined. This ensures that a
|
|
73
|
+
* non-empty string is considered insignificant and will not yield an empty result. When provided,
|
|
74
|
+
* the transformer function is applied *after* the non-empty check and the outcome of the transformer
|
|
75
|
+
* is returned.
|
|
76
|
+
*
|
|
77
|
+
* @param inputValue The current value to check
|
|
78
|
+
* @param transformer The transformer to apply to a non-empty string value
|
|
79
|
+
* @returns The output of the transformer when the input is a non-empty string, `undefined` otherwise
|
|
80
|
+
*/
|
|
81
|
+
export declare function ifNonEmptyString<T = string>(inputValue?: string | null, transformer?: (iv: string) => T): T | undefined;
|
|
48
82
|
export declare function toUniqueValues<R extends any>(value: R, index: number, array: Array<R>): value is R;
|
|
49
83
|
export declare function trim<T extends string | null | undefined>(valueToTrim: T): T;
|
|
50
|
-
|
|
84
|
+
/**
|
|
85
|
+
* Extract the identifier needed for the edit HTML properties from the contentLink. This will ensure
|
|
86
|
+
* that inline content links don't output an identifier.
|
|
87
|
+
*
|
|
88
|
+
* @param contentLink
|
|
89
|
+
* @returns
|
|
90
|
+
*/
|
|
91
|
+
export declare function getContentEditId(contentLink?: ContentLink | InlineContentLink | null): string | undefined;
|
|
51
92
|
/**
|
|
52
93
|
* Generate a pseudo-random identifier usable to satisfy the unique key
|
|
53
94
|
* requirement for children within a React node. However this effectively will
|
|
@@ -61,3 +102,12 @@ export declare function getContentEditId(contentLink: ContentLink): string;
|
|
|
61
102
|
* @returns The unique key
|
|
62
103
|
*/
|
|
63
104
|
export declare function getRandomKey(prefix?: string): string;
|
|
105
|
+
/**
|
|
106
|
+
* Parse the provided string to determine if it's a valid positive (i.e. larger then 0) number,
|
|
107
|
+
* return the number if it is, `undefined` or the `defaultValue` otherwise.
|
|
108
|
+
*
|
|
109
|
+
* @param value
|
|
110
|
+
* @param defaultValue
|
|
111
|
+
* @returns
|
|
112
|
+
*/
|
|
113
|
+
export declare function tryParsePositiveInt(value: string | undefined | null, defaultValue?: number): number | undefined;
|