@remkoj/optimizely-cms-react 6.0.0-pre8 → 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.
Files changed (39) hide show
  1. package/LICENSE +12 -12
  2. package/dist/components/cms-content/get-content-type.js +8 -17
  3. package/dist/components/cms-content/get-content-type.js.map +1 -1
  4. package/dist/components/cms-content/get-content.js +45 -49
  5. package/dist/components/cms-content/get-content.js.map +1 -1
  6. package/dist/components/cms-content/resolve-component.js +9 -4
  7. package/dist/components/cms-content/resolve-component.js.map +1 -1
  8. package/dist/components/cms-content/rsc.d.ts +1 -1
  9. package/dist/components/cms-content/rsc.js +9 -7
  10. package/dist/components/cms-content/rsc.js.map +1 -1
  11. package/dist/components/cms-content/types.d.ts +8 -0
  12. package/dist/components/cms-content-area/index.js +3 -3
  13. package/dist/components/cms-content-area/index.js.map +1 -1
  14. package/dist/components/cms-editable/index.d.ts +8 -2
  15. package/dist/components/cms-editable/index.js +13 -7
  16. package/dist/components/cms-editable/index.js.map +1 -1
  17. package/dist/components/rsc.d.ts +2 -0
  18. package/dist/components/rsc.js +1 -0
  19. package/dist/components/rsc.js.map +1 -1
  20. package/dist/components/visual-builder/functions.js +3 -3
  21. package/dist/components/visual-builder/functions.js.map +1 -1
  22. package/dist/components/visual-builder/index.js +12 -8
  23. package/dist/components/visual-builder/index.js.map +1 -1
  24. package/dist/components/visual-builder/types.d.ts +8 -2
  25. package/dist/context/client.js +5 -2
  26. package/dist/context/client.js.map +1 -1
  27. package/dist/context/rsc.d.ts +1 -1
  28. package/dist/context/rsc.js +11 -42
  29. package/dist/context/rsc.js.map +1 -1
  30. package/dist/context/shared.js +2 -1
  31. package/dist/context/shared.js.map +1 -1
  32. package/dist/context/types.d.ts +3 -11
  33. package/dist/factory/default.js +0 -5
  34. package/dist/factory/default.js.map +1 -1
  35. package/dist/types.d.ts +37 -6
  36. package/dist/utilities.d.ts +54 -4
  37. package/dist/utilities.js +100 -7
  38. package/dist/utilities.js.map +1 -1
  39. package/package.json +16 -12
@@ -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
- console.log(`⚪ [VisualBuilder] Rendering element node ${JSON.stringify(node)}`);
15
- const [contentLink, contentType, fragmentData, layoutProps] = leafPropsFactory(node);
16
- return (_jsx(CmsContent, { contentLink: contentLink, contentType: contentType, fragmentData: fragmentData, layoutProps: layoutProps, ctx: ctx }));
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
- console.log(`⚪ [VisualBuilder] Rendering structure node ${JSON.stringify(node)}`);
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,IAAI,OAAO;YACT,OAAO,CAAC,GAAG,CACT,4CAA4C,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CACnE,CAAA;QACH,MAAM,CAAC,WAAW,EAAE,WAAW,EAAE,YAAY,EAAE,WAAW,CAAC,GACzD,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,GAAG,EAAE,GAAG,GACR,CACH,CAAA;IACH,CAAC;IAED,QAA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B,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
+ {"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;IACx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ureNode = 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
- 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
- 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>];
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
@@ -13,8 +13,11 @@ export var OptimizelyCmsMode;
13
13
  })(OptimizelyCmsMode || (OptimizelyCmsMode = {}));
14
14
  export class ClientContextInstance {
15
15
  constructor(cfg, components) {
16
- if (cfg.clientConfig)
17
- this.client = createClient(cfg.clientConfig);
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,YAAY;YAAE,IAAI,CAAC,MAAM,GAAG,YAAY,CAAC,GAAG,CAAC,YAAY,CAAC,CAAA;QAClE,IAAI,CAAC,OAAO,GAAG,IAAI,uBAAuB,CAAC,UAAU,CAAC,CAAA;QACtD,IAAI,CAAC,UAAU,GAAG,GAAG,CAAC,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ACT,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"}
@@ -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: () => ServerContext;
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
@@ -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
- console.warn(
96
- '🦺 [ServerContext] Converting Context to JSON, this is typically a side effect of the context being passed between Server & Client components'
97
- )
98
- if (this.isDebug) {
99
- console.trace('The conversion happened here')
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
- if (isDebug())
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
- const serverCtx = internalGetServerContext();
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
@@ -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;AACxC,OAAO,KAAK,MAAM,OAAO,CAAA;AAMzB,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,aA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SAAS,GAAG,IAAI,CAAA;IACvB,CAAC;IACM,8BAA8B,CAAC,YAAqB;QACzD,IAAI,CAAC,qBAAqB,GAAG,YAAY,CAAA;IAC3C,CAAC;IAED,sCAAsC;IAC/B,MAAM,CAAC,GAAY;QACxB;;;;;;;;;WASG;QAEH,OAAO;YACL,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE;YAC7B,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,aAAa,EAAE,IAAI,CAAC,aAAa;YACjC,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,oBAAoB,EAAE,IAAI,CAAC,oBAAoB;YAC/C,aAAa,EAAE,IAAI,CAAC,aAAa;YACjC,MAAM,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"}
@@ -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":"AAEA,MAAM,UAAU,sBAAsB,CAAC,KAA0B;IAC/D,OAAO,OAAO,CAAC,KAAK,CAAC,IAAI,QAAQ,IAAI,KAAK,IAAI,IAAI,IAAK,KAAwB,CAAC,OAAO,KAAK,SAAS,CAAA;AACvG,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"}
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"}
@@ -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 interface TransferrableContext {
20
- readonly clientConfig?: OptimizelyGraphConfig;
21
- readonly locale?: string;
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;
@@ -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,EAAE,MAAM,OAAO,CAAA;AAEhC,MAAM,CAAC,MAAM,YAAY,GAAG,GAAG,CAAA;AAE/B,MAAM,CAAC,MAAM,oBAAoB,GAAG,cAAc,CAAA;AAElD;;;GAGG;AACH,MAAM,OAAO,uBAAuB;IAIlC;;;;;OAKG;IACH,YAAmB,iBAA2C;QATtD,aAAQ,GAAG,IAAI,GAAG,EAAwC,CAAA;QAUhE,qBAAqB;QACrB,IAAI,CAAC;YACH,IAAI,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,gBAAgB,IAAI,GAAG,CAAA;QAChD,CAAC;QAAC,MAAM,CAAC;YACP,IAAI,CAAC,GAAG,GAAG,KAAK,CAAA;QAClB,CAAC;QAED,kCAAkC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M,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,QAAQ,CAAC;QACpE,OAAO,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, if any
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
- changeset?: string | null;
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 GetDataQuery<T> = () => TypedDocumentNode<T, ContentQueryProps> | DocumentNode;
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> : ReactComponentType<CmsComponentProps<T, L>>;
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>>;
@@ -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
- export declare function contentLinkToRequestVariables(contentLink: ContentLinkWithLocale): ContentQueryProps;
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
- export declare function getContentEditId(contentLink: ContentLink): string;
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;
package/dist/utilities.js CHANGED
@@ -1,7 +1,37 @@
1
+ import { OptiCmsSchema } from '@remkoj/optimizely-graph-client';
1
2
  import { TYPE_MERGE_SYMBOL } from './factory/index.js';
2
3
  import { localeToGraphLocale } from '@remkoj/optimizely-graph-client/utils';
3
4
  //Export the Rich-Text utilities
4
5
  export * from './components/rich-text/utils.js';
6
+ /**
7
+ * Safeguard filter to remove default properties from the CmsComponent, intended
8
+ * to prevent these properties to be passed to client components. It will also
9
+ * remove all properties where the name starts with a `_`.
10
+ *
11
+ * @param toFilter The object to filter the
12
+ * @returns W
13
+ */
14
+ export function filterCmsComponentProps(toFilter) {
15
+ const _CmsComponentProps = ['children', 'contentLink', 'ctx', 'data', 'editProps', 'inEditMode', 'layoutProps'];
16
+ function shouldKeep(currentPropName) {
17
+ if (typeof currentPropName === 'string' && currentPropName.startsWith('_'))
18
+ return false;
19
+ if (_CmsComponentProps.includes(currentPropName))
20
+ return false;
21
+ return true;
22
+ }
23
+ return Object.getOwnPropertyNames(toFilter).reduce((newProps, currentPropName) => {
24
+ if (shouldKeep(currentPropName))
25
+ newProps[currentPropName] = toFilter[currentPropName];
26
+ return newProps;
27
+ }, {});
28
+ }
29
+ /**
30
+ *
31
+ *
32
+ * @param toTest
33
+ * @returns
34
+ */
5
35
  export function isNonEmptyString(toTest) {
6
36
  return typeof (toTest) == 'string' && toTest.length > 0;
7
37
  }
@@ -88,15 +118,50 @@ export function validatesFragment(toTest) {
88
118
  return toTest.validateFragment && typeof (toTest.validateFragment) == 'function' ? true : false;
89
119
  return false;
90
120
  }
91
- export function contentLinkToRequestVariables(contentLink) {
92
- const variables = {
121
+ /**
122
+ * Take a ContentLink and transform it into the normalized set of request variables used query for content across
123
+ * multiple components.
124
+ *
125
+ * @param contentLink The contentlink to transform
126
+ * @param client If provided, the the configuration of the client is applied to the variables
127
+ * @returns The request variables to use for querying Optimizely Graph
128
+ */
129
+ export function contentLinkToRequestVariables(contentLink, client) {
130
+ const gqlVariables = {
93
131
  key: contentLink.key ?? '-no-content-selected-',
94
- locale: contentLink.locale ? localeToGraphLocale(contentLink.locale) : undefined,
95
- version: contentLink.version
132
+ locale: ifNonEmptyString(contentLink.locale, localeToGraphLocale),
133
+ version: ifNonEmptyString(contentLink.version),
134
+ changeset: ifNonEmptyString(contentLink.changeset),
135
+ variation: ifNonEmptyString(contentLink.variation, (variation) => { return { include: "SOME", value: [variation] }; })
96
136
  };
97
- if (variables.version == undefined || variables.version == '')
98
- variables.version = null;
99
- return variables;
137
+ // CMS 12 Requires the version number to be an Int
138
+ if (client && client.currentOptiCmsSchema == OptiCmsSchema.CMS12)
139
+ gqlVariables.version = tryParsePositiveInt(gqlVariables.version);
140
+ // If the CMS Preview mode has been enabled, make sure we include that specific
141
+ // changeset in the query. This overrides the changeset that my be inferred from
142
+ // the contentLink
143
+ if (client && client.isPreviewEnabled())
144
+ gqlVariables.changeset = client.getChangeset();
145
+ // Make sure we can load any version by releasing access to any variation when a
146
+ // version has been explicitly requested. If no version has been requested, the
147
+ // variation will not be modified from the contentLink.
148
+ if (gqlVariables.version)
149
+ gqlVariables.variation = { include: "ALL" };
150
+ // Return the processed outcome
151
+ return gqlVariables;
152
+ }
153
+ /**
154
+ * Normalizes a string|null|undefined input to a non-empty string or undefined. This ensures that a
155
+ * non-empty string is considered insignificant and will not yield an empty result. When provided,
156
+ * the transformer function is applied *after* the non-empty check and the outcome of the transformer
157
+ * is returned.
158
+ *
159
+ * @param inputValue The current value to check
160
+ * @param transformer The transformer to apply to a non-empty string value
161
+ * @returns The output of the transformer when the input is a non-empty string, `undefined` otherwise
162
+ */
163
+ export function ifNonEmptyString(inputValue, transformer = (iv) => iv) {
164
+ return inputValue && typeof (inputValue) == 'string' && inputValue.length > 0 ? transformer(inputValue) : undefined;
100
165
  }
101
166
  export function toUniqueValues(value, index, array) {
102
167
  return array.indexOf(value) == index;
@@ -106,7 +171,16 @@ export function trim(valueToTrim) {
106
171
  return valueToTrim.trim();
107
172
  return valueToTrim;
108
173
  }
174
+ /**
175
+ * Extract the identifier needed for the edit HTML properties from the contentLink. This will ensure
176
+ * that inline content links don't output an identifier.
177
+ *
178
+ * @param contentLink
179
+ * @returns
180
+ */
109
181
  export function getContentEditId(contentLink) {
182
+ if (!contentLink?.key || contentLink.key.length == 0)
183
+ return undefined;
110
184
  return contentLink.key;
111
185
  }
112
186
  /**
@@ -129,4 +203,23 @@ export function getRandomKey(prefix = "rnd") {
129
203
  return `${prefix}::${Math.round(Math.random() * 10000)}::${Math.round(Math.random() * 10000)}`;
130
204
  }
131
205
  }
206
+ /**
207
+ * Parse the provided string to determine if it's a valid positive (i.e. larger then 0) number,
208
+ * return the number if it is, `undefined` or the `defaultValue` otherwise.
209
+ *
210
+ * @param value
211
+ * @param defaultValue
212
+ * @returns
213
+ */
214
+ export function tryParsePositiveInt(value, defaultValue) {
215
+ try {
216
+ const versionNr = value ? Number.parseInt(value) : 0;
217
+ if (!isNaN(versionNr) && versionNr > 0)
218
+ return versionNr;
219
+ }
220
+ catch {
221
+ // Ignore
222
+ }
223
+ return defaultValue;
224
+ }
132
225
  //# sourceMappingURL=utilities.js.map