@remkoj/optimizely-cms-react 2.1.0 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (150) hide show
  1. package/README.md +38 -2
  2. package/dist/components/client.d.ts +42 -0
  3. package/dist/components/client.js +52 -0
  4. package/dist/components/client.js.map +1 -0
  5. package/dist/components/cms-content/client.d.ts +11 -0
  6. package/dist/components/cms-content/client.js +72 -0
  7. package/dist/components/cms-content/client.js.map +1 -0
  8. package/dist/components/cms-content/get-content-type.d.ts +13 -0
  9. package/dist/components/cms-content/get-content-type.js +70 -0
  10. package/dist/components/cms-content/get-content-type.js.map +1 -0
  11. package/dist/components/cms-content/get-content.d.ts +4 -0
  12. package/dist/components/cms-content/get-content.js +91 -0
  13. package/dist/components/cms-content/get-content.js.map +1 -0
  14. package/dist/components/cms-content/resolve-component.d.ts +18 -0
  15. package/dist/components/cms-content/resolve-component.js +53 -0
  16. package/dist/components/cms-content/resolve-component.js.map +1 -0
  17. package/dist/components/cms-content/resolve-content-type.d.ts +15 -0
  18. package/dist/components/cms-content/resolve-content-type.js +29 -0
  19. package/dist/components/cms-content/resolve-content-type.js.map +1 -0
  20. package/dist/components/cms-content/rsc.d.ts +11 -0
  21. package/dist/components/cms-content/rsc.js +50 -0
  22. package/dist/components/cms-content/rsc.js.map +1 -0
  23. package/dist/components/cms-content/types.d.ts +59 -0
  24. package/dist/components/cms-content/types.js +2 -0
  25. package/dist/components/cms-content/types.js.map +1 -0
  26. package/dist/components/cms-content/utils.d.ts +3 -0
  27. package/dist/components/cms-content/utils.js +6 -0
  28. package/dist/components/cms-content/utils.js.map +1 -0
  29. package/dist/components/cms-content-area/index.d.ts +17 -0
  30. package/dist/{server/components/cms-content-area.js → components/cms-content-area/index.js} +43 -43
  31. package/dist/components/cms-content-area/index.js.map +1 -0
  32. package/dist/{server/components → components/cms-content-area}/types.d.ts +31 -94
  33. package/dist/components/cms-content-area/types.js.map +1 -0
  34. package/dist/{server/components/cms-editable.d.ts → components/cms-editable/index.d.ts} +5 -3
  35. package/dist/components/cms-editable/index.js +15 -0
  36. package/dist/components/cms-editable/index.js.map +1 -0
  37. package/dist/components/{cms-styles.js → cms-styles/index.js} +1 -1
  38. package/dist/components/cms-styles/index.js.map +1 -0
  39. package/dist/components/rich-text/components.d.ts +14 -0
  40. package/dist/components/rich-text/components.js +63 -0
  41. package/dist/components/rich-text/components.js.map +1 -0
  42. package/dist/components/rich-text/index.d.ts +4 -0
  43. package/dist/components/rich-text/index.js +47 -0
  44. package/dist/components/rich-text/index.js.map +1 -0
  45. package/dist/components/{rich-text.d.ts → rich-text/types.d.ts} +13 -18
  46. package/dist/components/rich-text/types.js +2 -0
  47. package/dist/components/rich-text/types.js.map +1 -0
  48. package/dist/components/rich-text/utils.d.ts +5 -0
  49. package/dist/components/rich-text/utils.js +24 -0
  50. package/dist/components/rich-text/utils.js.map +1 -0
  51. package/dist/components/rsc.d.ts +47 -0
  52. package/dist/components/rsc.js +55 -0
  53. package/dist/components/rsc.js.map +1 -0
  54. package/dist/{server → components}/type-utils.js.map +1 -1
  55. package/dist/{server/components → components}/visual-builder/functions.d.ts +7 -2
  56. package/dist/{server/components → components}/visual-builder/functions.js +8 -3
  57. package/dist/components/visual-builder/functions.js.map +1 -0
  58. package/dist/{server/components/visual-builder/Composition.d.ts → components/visual-builder/index.d.ts} +4 -3
  59. package/dist/{server/components/visual-builder/Composition.js → components/visual-builder/index.js} +9 -18
  60. package/dist/components/visual-builder/index.js.map +1 -0
  61. package/dist/{server/components → components}/visual-builder/types.d.ts +6 -1
  62. package/dist/components/visual-builder/types.js.map +1 -0
  63. package/dist/components.d.ts +27 -0
  64. package/dist/components.js +20 -0
  65. package/dist/components.js.map +1 -0
  66. package/dist/context/client.d.ts +70 -0
  67. package/dist/context/client.js +78 -0
  68. package/dist/context/client.js.map +1 -0
  69. package/dist/context/rsc.d.ts +33 -0
  70. package/dist/context/rsc.js +75 -0
  71. package/dist/context/rsc.js.map +1 -0
  72. package/dist/context/types.d.ts +15 -0
  73. package/dist/context/types.js +2 -0
  74. package/dist/{server/components → context}/types.js.map +1 -1
  75. package/dist/{server/components → data}/queries.js +121 -121
  76. package/dist/data/queries.js.map +1 -0
  77. package/dist/{factory.d.ts → factory/default.d.ts} +1 -18
  78. package/dist/{factory.js → factory/default.js} +2 -34
  79. package/dist/factory/default.js.map +1 -0
  80. package/dist/factory/index.d.ts +17 -0
  81. package/dist/factory/index.js +21 -0
  82. package/dist/factory/index.js.map +1 -0
  83. package/dist/factory/types.d.ts +51 -0
  84. package/dist/factory/types.js +2 -0
  85. package/dist/factory/types.js.map +1 -0
  86. package/dist/factory/undef.d.ts +9 -0
  87. package/dist/factory/undef.js +19 -0
  88. package/dist/factory/undef.js.map +1 -0
  89. package/dist/index.d.ts +4 -2
  90. package/dist/index.js +4 -2
  91. package/dist/index.js.map +1 -1
  92. package/dist/{server/is-debug.d.ts → rsc-utilities.d.ts} +0 -1
  93. package/dist/{server/is-debug.js → rsc-utilities.js} +1 -2
  94. package/dist/{server/is-debug.js.map → rsc-utilities.js.map} +1 -1
  95. package/dist/rsc.d.ts +11 -0
  96. package/dist/rsc.js +14 -0
  97. package/dist/rsc.js.map +1 -0
  98. package/dist/types.d.ts +10 -56
  99. package/dist/utilities.d.ts +23 -9
  100. package/dist/utilities.js +22 -1
  101. package/dist/utilities.js.map +1 -1
  102. package/package.json +12 -24
  103. package/dist/browser/context.d.ts +0 -6
  104. package/dist/browser/context.js +0 -15
  105. package/dist/browser/context.js.map +0 -1
  106. package/dist/browser/index.d.ts +0 -1
  107. package/dist/browser/index.js +0 -2
  108. package/dist/browser/index.js.map +0 -1
  109. package/dist/components/cms-styles.js.map +0 -1
  110. package/dist/components/index.d.ts +0 -2
  111. package/dist/components/index.js +0 -3
  112. package/dist/components/index.js.map +0 -1
  113. package/dist/components/rich-text.js +0 -138
  114. package/dist/components/rich-text.js.map +0 -1
  115. package/dist/factory.js.map +0 -1
  116. package/dist/server/components/cms-content-area.d.ts +0 -13
  117. package/dist/server/components/cms-content-area.js.map +0 -1
  118. package/dist/server/components/cms-content.d.ts +0 -11
  119. package/dist/server/components/cms-content.js +0 -154
  120. package/dist/server/components/cms-content.js.map +0 -1
  121. package/dist/server/components/cms-editable.js +0 -18
  122. package/dist/server/components/cms-editable.js.map +0 -1
  123. package/dist/server/components/get-content-type.d.ts +0 -12
  124. package/dist/server/components/get-content-type.js +0 -51
  125. package/dist/server/components/get-content-type.js.map +0 -1
  126. package/dist/server/components/index.d.ts +0 -4
  127. package/dist/server/components/index.js +0 -5
  128. package/dist/server/components/index.js.map +0 -1
  129. package/dist/server/components/queries.js.map +0 -1
  130. package/dist/server/components/visual-builder/Composition.js.map +0 -1
  131. package/dist/server/components/visual-builder/functions.js.map +0 -1
  132. package/dist/server/components/visual-builder/index.d.ts +0 -4
  133. package/dist/server/components/visual-builder/index.js +0 -4
  134. package/dist/server/components/visual-builder/index.js.map +0 -1
  135. package/dist/server/components/visual-builder/types.js.map +0 -1
  136. package/dist/server/context.d.ts +0 -22
  137. package/dist/server/context.js +0 -81
  138. package/dist/server/context.js.map +0 -1
  139. package/dist/server/factory.d.ts +0 -10
  140. package/dist/server/factory.js +0 -18
  141. package/dist/server/factory.js.map +0 -1
  142. package/dist/server/index.d.ts +0 -6
  143. package/dist/server/index.js +0 -6
  144. package/dist/server/index.js.map +0 -1
  145. /package/dist/{server/components → components/cms-content-area}/types.js +0 -0
  146. /package/dist/components/{cms-styles.d.ts → cms-styles/index.d.ts} +0 -0
  147. /package/dist/{server → components}/type-utils.d.ts +0 -0
  148. /package/dist/{server → components}/type-utils.js +0 -0
  149. /package/dist/{server/components → components}/visual-builder/types.js +0 -0
  150. /package/dist/{server/components → data}/queries.d.ts +0 -0
@@ -0,0 +1,47 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import * as Utils from './utils.js';
3
+ import { DefaultComponentFactory } from "../../factory/default.js";
4
+ import { DefaultComponents, DefaultTextNode, createHtmlComponent } from "./components.js";
5
+ export * from "./types.js";
6
+ export const RichText = ({ factory, text, className = 'rich-text', as: Wrapper = "div", debug, ...props }) => {
7
+ const id = Utils.getRandomId("rich-text");
8
+ const richTextFactory = factory ?? new DefaultComponentFactory(DefaultComponents);
9
+ try {
10
+ const data = Utils.processNodeInput(text);
11
+ return _jsx(Wrapper, { className: className, ...props, children: (data?.children || []).map((child, idx) => {
12
+ const elementId = id + '::' + idx;
13
+ return _jsx(RichTextElement, { factory: richTextFactory, node: child, idPrefix: elementId + '::' }, elementId);
14
+ }) });
15
+ }
16
+ catch {
17
+ if (debug)
18
+ console.warn('🟠 [Rich Text] Invalid rich text received: ', text);
19
+ return Object.getOwnPropertyNames(props).length > 0 ? _jsx("div", { className: className, ...props }) : null;
20
+ }
21
+ };
22
+ //#region Supportive React components
23
+ const RichTextElement = ({ factory, node, idPrefix, debug }) => {
24
+ if (Utils.isText(node)) {
25
+ if (node.text.length == 0)
26
+ return null;
27
+ const TextComponent = factory?.resolve(`RichText/text`) ?? DefaultTextNode;
28
+ return _jsx(TextComponent, { node: node });
29
+ }
30
+ if (!Utils.isTypedNode(node)) {
31
+ if (debug)
32
+ console.warn('🟠 [Rich Text] Invalid rich text element data received:', node);
33
+ return null;
34
+ }
35
+ const childData = node.children?.map((child, idx) => {
36
+ const elementId = idPrefix + idx;
37
+ return _jsx(RichTextElement, { factory: factory, node: child, idPrefix: elementId + '::' }, elementId);
38
+ });
39
+ if (!factory?.has(`RichText/${node.type}`)) {
40
+ console.warn('🟠 [Rich Text] No renderer for node type, falling back to "div":', `RichText/${node.type}`);
41
+ const DivComponent = createHtmlComponent("div", false, { "data-type": node.type });
42
+ return _jsx(DivComponent, { node: node, children: childData });
43
+ }
44
+ const Component = factory?.resolve(`RichText/${node.type}`) ?? 'div';
45
+ return _jsx(Component, { node: node, children: childData });
46
+ };
47
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../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AE,EAAE,WAAW,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CAAA;QAClF,OAAO,KAAC,YAAY,IAAC,IAAI,EAAG,IAAI,YAAK,SAAS,GAAiB,CAAA;IACnE,CAAC;IACD,MAAM,SAAS,GAAG,OAAO,EAAE,OAAO,CAAC,YAAa,IAAI,CAAC,IAAK,EAAE,CAAC,IAAI,KAAK,CAAA;IACtE,OAAO,KAAC,SAAS,IAAC,IAAI,EAAG,IAAI,YAAK,SAAS,GAAc,CAAA;AAC7D,CAAC,CAAA"}
@@ -1,5 +1,5 @@
1
- import type { ComponentFactory, ComponentType, ComponentTypeDictionary } from "../types.js";
2
- import { type FunctionComponent, type PropsWithChildren } from "react";
1
+ import type { ComponentType as ReactComponentType } from "react";
2
+ import type { ComponentFactory, ComponentType } from "../../factory/types.js";
3
3
  export type RichTextProps = {
4
4
  /**
5
5
  * The component factory used for this rich text content
@@ -19,6 +19,10 @@ export type RichTextProps = {
19
19
  * element when not defined
20
20
  */
21
21
  as?: ComponentType;
22
+ /**
23
+ * Control the debugging output
24
+ */
25
+ debug?: boolean;
22
26
  } & ({
23
27
  /**
24
28
  * The fieldname of this Rich Text, when it is used as part of a block
@@ -38,6 +42,13 @@ export type RichTextProps = {
38
42
  */
39
43
  cmsId?: never;
40
44
  });
45
+ export type RichTextComponent = ReactComponentType<RichTextProps>;
46
+ export type RichTextElementProps = Readonly<{
47
+ debug?: boolean;
48
+ factory?: ComponentFactory;
49
+ node: Readonly<Node>;
50
+ idPrefix: string;
51
+ }>;
41
52
  export type Node = {};
42
53
  export type TextNode = Node & {
43
54
  text: string;
@@ -57,19 +68,3 @@ export type NodeWithChildren<T extends Node> = T & {
57
68
  children?: Array<Node>;
58
69
  };
59
70
  export type NodeInput = string | RichTextNode | StringNode;
60
- export declare const Utils: {
61
- isText(toTest: Node | null | undefined): toTest is TextNode;
62
- isTypedNode(toTest: Node | null | undefined): toTest is TypedNode;
63
- processNodeInput(input: NodeInput | null | undefined): RichTextNode | StringNode | undefined;
64
- getRandomId(scope?: string): string;
65
- };
66
- export declare const RichText: FunctionComponent<RichTextProps>;
67
- export declare function createHtmlComponent<E extends keyof JSX.IntrinsicElements>(element: E, ignoreChildren?: boolean, defaultProps?: JSX.IntrinsicElements[E] & Record<string, string>): ({ children, node, ...props }: PropsWithChildren<JSX.IntrinsicElements[E] & {
68
- node: TypedNode;
69
- }>) => import("react/jsx-runtime").JSX.Element;
70
- /**
71
- * A default component dictionary that allows to serialize the structured HTML
72
- * into React, using the component library shared across the react SDK.
73
- */
74
- export declare const DefaultComponents: ComponentTypeDictionary;
75
- export default RichText;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/components/rich-text/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ import type { TextNode, TypedNode, Node, NodeInput, RichTextNode, StringNode } from './types.js';
2
+ export declare function isText(toTest: Node | null | undefined): toTest is TextNode;
3
+ export declare function isTypedNode(toTest: Node | null | undefined): toTest is TypedNode;
4
+ export declare function processNodeInput(input: NodeInput | null | undefined): RichTextNode | StringNode | undefined;
5
+ export declare function getRandomId(scope?: string): string;
@@ -0,0 +1,24 @@
1
+ export function isText(toTest) {
2
+ return (typeof toTest == 'object' &&
3
+ toTest != null &&
4
+ (typeof toTest.text) == 'string' &&
5
+ toTest.text.length >= 0);
6
+ }
7
+ export function isTypedNode(toTest) {
8
+ return (typeof toTest == 'object' &&
9
+ toTest != null &&
10
+ (typeof toTest.type) == 'string' &&
11
+ toTest.type.length > 0);
12
+ }
13
+ export function processNodeInput(input) {
14
+ if (!input)
15
+ return undefined;
16
+ const textObject = typeof input == "string" ? JSON.parse(input) : input;
17
+ if (textObject?.type != "richText" && textObject?.type != "string")
18
+ throw new Error('Structured rich text requires a "richText" root node');
19
+ return textObject;
20
+ }
21
+ export function getRandomId(scope = "richText") {
22
+ return `${scope}::${Math.round(Math.random() * 100000)}`;
23
+ }
24
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/components/rich-text/utils.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,MAAM,CAAC,MAA+B;IAElD,OAAO,CACH,OAAO,MAAM,IAAI,QAAQ;QACzB,MAAM,IAAI,IAAI;QACd,CAAC,OAAQ,MAAmB,CAAC,IAAI,CAAC,IAAI,QAAQ;QAC7C,MAAmB,CAAC,IAAI,CAAC,MAAM,IAAI,CAAC,CACxC,CAAA;AACL,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,MAA+B;IAEvD,OAAO,CACH,OAAO,MAAM,IAAI,QAAQ;QACzB,MAAM,IAAI,IAAI;QACd,CAAC,OAAQ,MAAoB,CAAC,IAAI,CAAC,IAAI,QAAQ;QAC9C,MAAoB,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CACxC,CAAA;AACL,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,KAAmC;IAEhE,IAAI,CAAC,KAAK;QACN,OAAO,SAAS,CAAA;IACpB,MAAM,UAAU,GAAG,OAAO,KAAK,IAAI,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAA8B,CAAC,CAAC,CAAC,KAAK,CAAA;IACpG,IAAI,UAAU,EAAE,IAAI,IAAI,UAAU,IAAI,UAAU,EAAE,IAAI,IAAI,QAAQ;QAC9D,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAA;IAC3E,OAAO,UAAU,CAAA;AACrB,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,QAAgB,UAAU;IAElD,OAAO,GAAG,KAAK,KAAM,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,MAAM,CAAE,EAAE,CAAA;AAC9D,CAAC"}
@@ -0,0 +1,47 @@
1
+ import "server-only";
2
+ import { type ReactNode, type ComponentType } from 'react';
3
+ import { type PropsWithContext } from '../context/types.js';
4
+ import { type CmsContentAreaComponent } from './cms-content-area/index.js';
5
+ import { type CmsEditableComponent } from './cms-editable/index.js';
6
+ import { type CmsContentComponent } from './cms-content/rsc.js';
7
+ import { type OptimizelyCompositionComponent } from './visual-builder/index.js';
8
+ import { type RichTextComponent } from './rich-text/index.js';
9
+ export * from "./cms-styles/index.js";
10
+ export { isNode, isElementNode, isElementNodeOfType, isStructureNode } from "./visual-builder/functions.js";
11
+ export { DefaultComponents as RichTextComponentDictionary } from './rich-text/components.js';
12
+ /**
13
+ * Fallback while RSC hasn't been moved from Canary to Main
14
+ */
15
+ type ReactServerComponentType<P = any> = ComponentType<P> | ((props: P) => Promise<ReactNode>);
16
+ /**
17
+ * Wrapper function to turn context dependant components into easy to use
18
+ * server components
19
+ *
20
+ * @param component The component where the `ctx` parameter must be fulfilled
21
+ * @returns The component, without CTX parameter
22
+ */
23
+ export declare function serverContextAware<P = any>(component: ReactServerComponentType<PropsWithContext<P>>): ComponentType<P>;
24
+ /**
25
+ * Client side Optimizely CMS Editable
26
+ */
27
+ export declare const CmsEditable: CmsEditableComponent;
28
+ /**
29
+ * Client side Optimizely CMS Content, leveraging the CMS Context to load the
30
+ * content type and content data when needed
31
+ */
32
+ export declare const CmsContent: CmsContentComponent;
33
+ /**
34
+ * Client side Optimizely CMS Content Area, leveraging the CMS Context to infer
35
+ * the connection to Optimizely Graph and component dictionary.
36
+ */
37
+ export declare const CmsContentArea: CmsContentAreaComponent;
38
+ /**
39
+ * Client side Optimizely Composition (e.g. Visual Builder), leveraging the CMS
40
+ * Context to infer the connection to Optimizely Graph and component
41
+ * dictionary.
42
+ */
43
+ export declare const OptimizelyComposition: OptimizelyCompositionComponent;
44
+ /**
45
+ * Client side renderer for Rich Text
46
+ */
47
+ export declare const RichText: RichTextComponent;
@@ -0,0 +1,55 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import "server-only";
3
+ import { getServerContext } from '../context/rsc.js';
4
+ import { cmsContentAware } from './cms-content/utils.js';
5
+ import { CmsContentArea as BaseContentArea } from './cms-content-area/index.js'; // Both RSC & Client capable
6
+ import { CmsEditable as BaseEditable } from './cms-editable/index.js'; // Both RSC & Client capable
7
+ import { CmsContent as BaseCmsContent } from './cms-content/rsc.js'; // Different components for RSC & Client
8
+ import { OptimizelyComposition as BaseOptimizelyComposition } from './visual-builder/index.js'; // Both RSC & Client capable
9
+ import { RichText as BaseRichText } from './rich-text/index.js';
10
+ // Pass through Style functions types
11
+ export * from "./cms-styles/index.js";
12
+ export { isNode, isElementNode, isElementNodeOfType, isStructureNode } from "./visual-builder/functions.js";
13
+ // Export dictionary
14
+ export { DefaultComponents as RichTextComponentDictionary } from './rich-text/components.js';
15
+ /**
16
+ * Wrapper function to turn context dependant components into easy to use
17
+ * server components
18
+ *
19
+ * @param component The component where the `ctx` parameter must be fulfilled
20
+ * @returns The component, without CTX parameter
21
+ */
22
+ export function serverContextAware(component) {
23
+ const BaseComponent = component;
24
+ const ServerContextInjector = (props) => {
25
+ const ctx = getServerContext();
26
+ return _jsx(BaseComponent, { ctx: ctx, ...props });
27
+ };
28
+ ServerContextInjector.displayName = "Server Context Injector";
29
+ return ServerContextInjector;
30
+ }
31
+ /**
32
+ * Client side Optimizely CMS Editable
33
+ */
34
+ export const CmsEditable = serverContextAware(BaseEditable);
35
+ /**
36
+ * Client side Optimizely CMS Content, leveraging the CMS Context to load the
37
+ * content type and content data when needed
38
+ */
39
+ export const CmsContent = serverContextAware(BaseCmsContent);
40
+ /**
41
+ * Client side Optimizely CMS Content Area, leveraging the CMS Context to infer
42
+ * the connection to Optimizely Graph and component dictionary.
43
+ */
44
+ export const CmsContentArea = cmsContentAware(serverContextAware(BaseContentArea), CmsContent);
45
+ /**
46
+ * Client side Optimizely Composition (e.g. Visual Builder), leveraging the CMS
47
+ * Context to infer the connection to Optimizely Graph and component
48
+ * dictionary.
49
+ */
50
+ export const OptimizelyComposition = cmsContentAware(serverContextAware(BaseOptimizelyComposition), CmsContent);
51
+ /**
52
+ * Client side renderer for Rich Text
53
+ */
54
+ export const RichText = BaseRichText;
55
+ //# sourceMappingURL=rsc.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rsc.js","sourceRoot":"","sources":["../../src/components/rsc.tsx"],"names":[],"mappings":";AAAA,OAAO,aAAa,CAAA;AAGpB,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAExD,OAAO,EAAE,cAAc,IAAI,eAAe,EAAgC,MAAM,6BAA6B,CAAA,CAAC,4BAA4B;AAC1I,OAAO,EAAE,WAAW,IAAI,YAAY,EAA6B,MAAM,yBAAyB,CAAA,CAAC,4BAA4B;AAC7H,OAAO,EAAE,UAAU,IAAI,cAAc,EAA0D,MAAM,sBAAsB,CAAA,CAAC,wCAAwC;AACpK,OAAO,EAAE,qBAAqB,IAAI,yBAAyB,EAAuC,MAAM,2BAA2B,CAAA,CAAC,4BAA4B;AAChK,OAAO,EAAE,QAAQ,IAAI,YAAY,EAA0B,MAAM,sBAAsB,CAAA;AAEvF,qCAAqC;AACrC,cAAc,uBAAuB,CAAA;AACrC,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AAE3G,oBAAoB;AACpB,OAAO,EAAE,iBAAiB,IAAI,2BAA2B,EAAE,MAAM,2BAA2B,CAAA;AAO5F;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB,CAAU,SAAwD;IAEhG,MAAM,aAAa,GAAG,SAA+C,CAAA;IACrE,MAAM,qBAAqB,GAAsB,CAAC,KAAQ,EAAE,EAAE;QAC1D,MAAM,GAAG,GAAG,gBAAgB,EAAE,CAAA;QAC9B,OAAO,KAAC,aAAa,IAAC,GAAG,EAAE,GAAG,KAAO,KAAK,GAAK,CAAA;IACnD,CAAC,CAAA;IACD,qBAAqB,CAAC,WAAW,GAAG,yBAAyB,CAAA;IAC7D,OAAO,qBAAqB,CAAA;AAChC,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,kBAAkB,CAAC,YAAY,CAAyB,CAAA;AAGnF;;;GAGG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,kBAAkB,CAAC,cAAoD,CAAwB,CAAA;AAEzH;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,eAAe,CAAC,kBAAkB,CAAC,eAAe,CAAC,EAAE,UAAU,CAA4B,CAAA;AAEzH;;;;GAIG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,eAAe,CAAC,kBAAkB,CAAC,yBAAyB,CAAC,EAAE,UAAU,CAAmC,CAAA;AAEjJ;;GAEG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,YAAiC,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"type-utils.js","sourceRoot":"","sources":["../../src/server/type-utils.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"type-utils.js","sourceRoot":"","sources":["../../src/components/type-utils.ts"],"names":[],"mappings":""}
@@ -1,10 +1,15 @@
1
- import type { ContentType } from '../../../types.js';
2
1
  import type { CompositionNode, LeafPropsFactory, CompositionElementNode, NodePropsFactory, CompositionStructureNode } from './types.js';
3
2
  export declare function isElementNode(node: CompositionNode<Record<string, any>>): node is CompositionElementNode<Record<string, any>>;
4
3
  export declare function isElementNodeOfType<ET extends Record<string, any>>(node: CompositionNode<Record<string, any>>, test: (data: Record<string, any>) => data is ET): node is CompositionElementNode<ET>;
5
4
  export declare function isStructureNode(node: CompositionNode<Record<string, any>>): node is CompositionStructureNode;
5
+ /**
6
+ * Test if the provided value is a Visual Builder node
7
+ *
8
+ * @param toTest The value to test
9
+ * @returns `true` when the value is a Visual Builder node, `false`
10
+ * otherwise
11
+ */
6
12
  export declare function isNode(toTest: any): toTest is CompositionNode;
7
- export declare function isContentType(toTest: any): toTest is ContentType;
8
13
  export declare const defaultPropsFactory: LeafPropsFactory;
9
14
  export declare const defaultNodePropsFactory: NodePropsFactory;
10
15
  export declare function ucFirst(input: string | undefined | null): string | null;
@@ -1,3 +1,4 @@
1
+ import { isContentType } from '../../utilities.js';
1
2
  import { isContentLink, isInlineContentLink } from '@remkoj/optimizely-graph-client';
2
3
  export function isElementNode(node) {
3
4
  return node.layoutType == "element";
@@ -10,6 +11,13 @@ export function isElementNodeOfType(node, test) {
10
11
  export function isStructureNode(node) {
11
12
  return !isElementNode(node);
12
13
  }
14
+ /**
15
+ * Test if the provided value is a Visual Builder node
16
+ *
17
+ * @param toTest The value to test
18
+ * @returns `true` when the value is a Visual Builder node, `false`
19
+ * otherwise
20
+ */
13
21
  export function isNode(toTest) {
14
22
  if (typeof (toTest) != 'object' || toTest == null)
15
23
  return false;
@@ -18,9 +26,6 @@ export function isNode(toTest) {
18
26
  const hasValidType = typeof toTest.layoutType == 'string' && nodeTypes.includes(toTest.layoutType);
19
27
  return hasValidName && hasValidType;
20
28
  }
21
- export function isContentType(toTest) {
22
- return Array.isArray(toTest) && toTest.every(x => typeof (x) == 'string' && x.length > 0);
23
- }
24
29
  export const defaultPropsFactory = (node) => {
25
30
  const contentType = node.element?._metadata?.types;
26
31
  if (!isContentType(contentType))
@@ -0,0 +1 @@
1
+ {"version":3,"file":"functions.js","sourceRoot":"","sources":["../../../src/components/visual-builder/functions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,EAAE,aAAa,EAAyB,mBAAmB,EAAE,MAAM,iCAAiC,CAAA;AAG3G,MAAM,UAAU,aAAa,CAAC,IAAyC;IAEnE,OAAO,IAAI,CAAC,UAAU,IAAI,SAAS,CAAA;AACvC,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAgC,IAAyC,EAAE,IAA8C;IAExJ,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC;QACpB,OAAO,KAAK,CAAA;IAChB,OAAO,IAAI,CAAC,IAAI,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;QAC3B,QAAQ,EAAE,IAAI,CAAC,QAAQ;QACvB,QAAQ,EAAE,IAAI,CAAC,QAAQ;KAC1B,CAAA;IAED,IAAI,CAAC,CAAC,aAAa,CAAC,WAAW,CAAC,IAAI,mBAAmB,CAAC,WAAW,CAAC,CAAC;QACjE,MAAM,IAAI,KAAK,CAAC,2CAA2C,GAAC,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,GAAE,WAAW,GAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAA;IAE/H,OAAO,CAAE,WAAW,EAAE,cAAc,EAAE,aAAa,EAAE,UAAU,CAAE,CAAA;AACrE,CAAC,CAAA;AAED,MAAM,UAAU,OAAO,CAAC,KAAgC;IAEpD,IAAI,OAAM,CAAC,KAAK,CAAC,IAAI,QAAQ,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC;QAC7C,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAA;IACtD,OAAO,IAAI,CAAA;AACf,CAAC"}
@@ -1,10 +1,11 @@
1
- import 'server-only';
2
- import type { OptimizelyCompositionProps } from './types.js';
1
+ import { ReactNode } from 'react';
2
+ import type { BaseOptimizelyCompositionProps } from './types.js';
3
+ export type * from './types.js';
3
4
  /**
4
5
  * Render the composition as made available through Optimizely Graph for Visual Builder
5
6
  *
6
7
  * @param param0
7
8
  * @returns The
8
9
  */
9
- export declare function OptimizelyComposition({ node, leafPropsFactory, nodePropsFactory }: OptimizelyCompositionProps): Promise<JSX.Element>;
10
+ export declare function OptimizelyComposition({ node, leafPropsFactory, nodePropsFactory, ctx, cmsContent: CmsContent }: BaseOptimizelyCompositionProps): ReactNode;
10
11
  export default OptimizelyComposition;
@@ -1,44 +1,35 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import 'server-only';
3
2
  import { isElementNode, defaultNodePropsFactory, defaultPropsFactory } from './functions.js';
4
- import { CmsContent } from '../cms-content.js';
5
- import getServerContext from '../../context.js';
6
3
  /**
7
4
  * Render the composition as made available through Optimizely Graph for Visual Builder
8
5
  *
9
6
  * @param param0
10
7
  * @returns The
11
8
  */
12
- export async function OptimizelyComposition({ node, leafPropsFactory = defaultPropsFactory, nodePropsFactory = defaultNodePropsFactory }) {
13
- const { factory, isDebug } = getServerContext();
9
+ export function OptimizelyComposition({ node, leafPropsFactory = defaultPropsFactory, nodePropsFactory = defaultNodePropsFactory, ctx, cmsContent: CmsContent }) {
10
+ const { factory, isDebug } = ctx;
11
+ // Render the element
14
12
  if (isElementNode(node)) {
15
13
  if (isDebug)
16
14
  console.log(`⚪ [VisualBuilder] Rendering element node ${JSON.stringify(node)}`);
17
15
  const [contentLink, contentType, fragmentData, layoutProps] = leafPropsFactory(node);
18
- //@ts-expect-error CmsContent is an Asynchronous server component, which isn't supported by the generic React Typings
19
16
  return _jsx(CmsContent, { contentLink: contentLink, contentType: contentType, fragmentData: fragmentData, layoutProps: layoutProps });
20
17
  }
18
+ // Debug
21
19
  if (isDebug)
22
20
  console.log(`⚪ [VisualBuilder] Rendering structure node ${JSON.stringify(node)}`);
21
+ // Ensure we've got a factory
23
22
  if (!factory)
24
23
  throw new Error("🟡 [VisualBuilder] [OptimizelyComposition] The factory must be defined within the serverContext");
25
24
  const [contentLink, contentTypes, fragmentData, layoutProps] = nodePropsFactory(node);
26
- const firstExistingType = contentTypes.map(ct => {
27
- const reversed = [...ct].reverse();
28
- const hasType = factory.has(reversed);
29
- if (!hasType && isDebug)
30
- console.log(`🟡 [VisualBuilder] [OptimizelyComposition] Content type ${reversed.join('/')} not found within factory`);
31
- return hasType;
32
- }).indexOf(true);
25
+ const firstExistingType = contentTypes.map(ct => factory.has([...ct].reverse())).indexOf(true);
33
26
  const contentType = contentTypes[firstExistingType];
34
27
  if (!contentType)
35
- throw new Error("🟡 [VisualBuilder] [OptimizelyComposition] The factory must have a definition for Component/Node");
36
- //@ts-expect-error CmsContent is an Asynchronous server component, which isn't supported by the generic React Typings
28
+ throw new Error(`🟡 [VisualBuilder] [OptimizelyComposition] The factory must have a definition for one of these types: ${contentTypes.map(x => x.join('/')).join(', ')}`);
37
29
  return _jsx(CmsContent, { contentType: contentType, contentLink: contentLink, fragmentData: fragmentData, layoutProps: layoutProps, noDataLoad: true, children: (node.nodes ?? []).map((child) => {
38
30
  const childKey = child.key ? child.key : `vb::${JSON.stringify(child)}`;
39
- //@ts-expect-error OptimizelyComposition is an Asynchronous server component, which isn't supported by the generic React Typings
40
- return _jsx(OptimizelyComposition, { node: child, leafPropsFactory: leafPropsFactory, nodePropsFactory: nodePropsFactory }, childKey);
31
+ return _jsx(OptimizelyComposition, { node: child, leafPropsFactory: leafPropsFactory, nodePropsFactory: nodePropsFactory, ctx: ctx, cmsContent: CmsContent }, childKey);
41
32
  }) });
42
33
  }
43
34
  export default OptimizelyComposition;
44
- //# sourceMappingURL=Composition.js.map
35
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/visual-builder/index.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAE,aAAa,EAAE,uBAAuB,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AAI5F;;;;;GAKG;AACH,MAAM,UAAU,qBAAqB,CAAC,EAAE,IAAI,EAAE,gBAAgB,GAAG,mBAAmB,EAAE,gBAAgB,GAAG,uBAAuB,EAAE,GAAG,EAAE,UAAU,EAAE,UAAU,EAAkC;IAE3L,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,GAAG,CAAA;IAEhC,qBAAqB;IACrB,IAAI,aAAa,CAAC,IAAI,CAAC,EAAE,CAAC;QACtB,IAAI,OAAO;YACP,OAAO,CAAC,GAAG,CAAC,4CAA6C,IAAI,CAAC,SAAS,CAAC,IAAI,CAAE,EAAE,CAAC,CAAA;QACrF,MAAM,CAAE,WAAW,EAAE,WAAW,EAAE,YAAY,EAAE,WAAW,CAAE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AAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,OAAQ,IAAI,CAAC,SAAS,CAAE,KAAK,CAAE,EAAE,CAAA;YAC1E,OAAO,KAAC,qBAAqB,IAAkB,IAAI,EAAG,KAAK,EAAG,gBAAgB,EAAG,gBAAgB,EAAG,gBAAgB,EAAG,gBAAgB,EAAG,GAAG,EAAG,GAAG,EAAG,UAAU,EAAG,UAAU,IAAzI,QAAQ,CAAqI,CAAA;QACrL,CAAC,CAAC,GACO,CAAA;AACjB,CAAC;AAED,eAAe,qBAAqB,CAAA"}
@@ -1,6 +1,8 @@
1
1
  import { type ComponentType, type PropsWithChildren } from "react";
2
- import { type ContentType } from "../../../types.js";
3
2
  import { type InlineContentLinkWithLocale, type ContentLinkWithLocale } from "@remkoj/optimizely-graph-client";
3
+ import { type ContentType } from "../../types.js";
4
+ import { type PropsWithContext } from "../../context/types.js";
5
+ import { type PropsWithCmsContent } from "../cms-content/types.js";
4
6
  export declare enum StructureNodeTypes {
5
7
  Experience = "experience",
6
8
  Section = "section",
@@ -50,3 +52,6 @@ export type OptimizelyCompositionProps = JSX.IntrinsicAttributes & {
50
52
  */
51
53
  nodePropsFactory?: NodePropsFactory;
52
54
  };
55
+ export type BaseOptimizelyCompositionProps = PropsWithCmsContent<PropsWithContext<OptimizelyCompositionProps>>;
56
+ export type OptimizelyCompositionComponent = ComponentType<OptimizelyCompositionProps>;
57
+ export type OptimizelyCompositionBaseComponent = ComponentType<BaseOptimizelyCompositionProps>;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/components/visual-builder/types.ts"],"names":[],"mappings":"AAMA,MAAM,CAAN,IAAY,kBAKX;AALD,WAAY,kBAAkB;IAC1B,+CAAyB,CAAA;IACzB,yCAAmB,CAAA;IACnB,iCAAW,CAAA;IACX,uCAAiB,CAAA;AACrB,CAAC,EALW,kBAAkB,KAAlB,kBAAkB,QAK7B"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * @deprecated The `@remkoj/optimizely-cms-react/components` export has been deprecated
3
+ */
4
+ /**
5
+ * @deprecated The `@remkoj/optimizely-cms-react/components` export has been deprecated
6
+ */
7
+ export { RichText } from "./components/rich-text/index.js";
8
+ /**
9
+ * @deprecated The `@remkoj/optimizely-cms-react/components` export has been deprecated
10
+ */
11
+ export { DefaultComponents, DefaultTextNode, createHtmlComponent } from "./components/rich-text/components.js";
12
+ /**
13
+ * @deprecated The `@remkoj/optimizely-cms-react/components` export has been deprecated
14
+ */
15
+ export * as Utils from "./components/rich-text/utils.js";
16
+ /**
17
+ * @deprecated The `@remkoj/optimizely-cms-react/components` export has been deprecated
18
+ */
19
+ export type * from "./components/rich-text/types.js";
20
+ /**
21
+ * @deprecated The `@remkoj/optimizely-cms-react/components` export has been deprecated
22
+ */
23
+ export type { BaseStyleDefinition, ElementStyleDefinition, LayoutProps, LayoutPropsSetting, LayoutPropsSettingChoices, LayoutPropsSettingKeys, LayoutPropsSettingValues, NodeStyleDefinition, StyleDefinition, StyleSetting } from "./components/cms-styles/index.js";
24
+ /**
25
+ * @deprecated The `@remkoj/optimizely-cms-react/components` export has been deprecated
26
+ */
27
+ export { extractSettings, readSetting } from "./components/cms-styles/index.js";
@@ -0,0 +1,20 @@
1
+ /**
2
+ * @deprecated The `@remkoj/optimizely-cms-react/components` export has been deprecated
3
+ */
4
+ /**
5
+ * @deprecated The `@remkoj/optimizely-cms-react/components` export has been deprecated
6
+ */
7
+ export { RichText } from "./components/rich-text/index.js";
8
+ /**
9
+ * @deprecated The `@remkoj/optimizely-cms-react/components` export has been deprecated
10
+ */
11
+ export { DefaultComponents, DefaultTextNode, createHtmlComponent } from "./components/rich-text/components.js";
12
+ /**
13
+ * @deprecated The `@remkoj/optimizely-cms-react/components` export has been deprecated
14
+ */
15
+ export * as Utils from "./components/rich-text/utils.js";
16
+ /**
17
+ * @deprecated The `@remkoj/optimizely-cms-react/components` export has been deprecated
18
+ */
19
+ export { extractSettings, readSetting } from "./components/cms-styles/index.js";
20
+ //# sourceMappingURL=components.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"components.js","sourceRoot":"","sources":["../src/components.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH;;GAEG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAA;AAC1D;;GAEG;AACH,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,sCAAsC,CAAA;AAC9G;;GAEG;AACH,OAAO,KAAK,KAAK,MAAM,iCAAiC,CAAA;AASxD;;GAEG;AACH,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAA"}
@@ -0,0 +1,70 @@
1
+ import { type FunctionComponent, type PropsWithChildren, type Dispatch, type SetStateAction } from "react";
2
+ import { type OptimizelyGraphConfig, type IOptiGraphClient } from "@remkoj/optimizely-graph-client";
3
+ import { type GenericContext } from "./types.js";
4
+ import { type ComponentTypeDictionary, type ComponentFactory } from "../factory/index.js";
5
+ export declare const enum OptimizelyCmsMode {
6
+ default = "default",
7
+ edit = "edit",
8
+ preview = "preview"
9
+ }
10
+ export interface ClientContext extends GenericContext {
11
+ setLocale: Dispatch<SetStateAction<string | undefined>>;
12
+ setMode: Dispatch<SetStateAction<OptimizelyCmsMode>>;
13
+ }
14
+ export type OptimizelyCmsProps = {
15
+ /**
16
+ * The Optimizely Graph Client to use, provide either an instance of the
17
+ * client, or the configuration used to create the instance. In case you
18
+ * provide no parameters, the Client will try to infer the configuration
19
+ * from the environment variables.
20
+ */
21
+ client?: null | OptimizelyGraphConfig | IOptiGraphClient;
22
+ /**
23
+ * The authentication token to use for the Optimizely Graph Client. This
24
+ * token will be applied to the client after it has been resolved from the
25
+ * `client` property. If not provided the current authentication data of
26
+ * the client will not be affected.
27
+ */
28
+ clientToken?: string;
29
+ /**
30
+ * Marker to indicate if the debug mode should be activated. If not provided
31
+ * it will be read from the Optimizely Graph Client, inferred by the `client`
32
+ * property.
33
+ */
34
+ isDebug?: boolean;
35
+ /**
36
+ * Marker to indicate if the development mode should be activated. If not
37
+ * provided, it will be read from the `process.env.NODE_ENV` variable. If
38
+ * this variable is not set it assumes it to be "production".
39
+ */
40
+ isDevelopment?: boolean;
41
+ /**
42
+ * The default mode to initialize the context with, after initialization the
43
+ * current mode will be state managed using `useState`.
44
+ */
45
+ initialMode?: OptimizelyCmsMode;
46
+ } & ({
47
+ /**
48
+ * The component factory to be used to resolve content within the scope
49
+ * of this provider.
50
+ */
51
+ factory: ComponentFactory;
52
+ /**
53
+ * The defaults components to apply when there's no factory provided. If a
54
+ * factory is provided, these components will not be added to the factory.
55
+ */
56
+ initialComponents?: never;
57
+ } | {
58
+ /**
59
+ * The component factory to be used to resolve content within the scope
60
+ * of this provider.
61
+ */
62
+ factory?: never;
63
+ /**
64
+ * The defaults components to apply when there's no factory provided. If a
65
+ * factory is provided, these components will not be added to the factory.
66
+ */
67
+ initialComponents: ComponentTypeDictionary;
68
+ });
69
+ export declare const OptimizelyCms: FunctionComponent<PropsWithChildren<OptimizelyCmsProps>>;
70
+ export declare const useOptimizelyCms: () => ClientContext;
@@ -0,0 +1,78 @@
1
+ 'use client';
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { createContext, useContext, useState, useMemo } from "react";
4
+ import { isOptiGraphClient, isOptiGraphConfig, createClient } from "@remkoj/optimizely-graph-client";
5
+ import { getFactory } from "../factory/index.js";
6
+ import { UndefinedComponentFactory } from "../factory/undef.js";
7
+ export var OptimizelyCmsMode;
8
+ (function (OptimizelyCmsMode) {
9
+ OptimizelyCmsMode["default"] = "default";
10
+ OptimizelyCmsMode["edit"] = "edit";
11
+ OptimizelyCmsMode["preview"] = "preview";
12
+ })(OptimizelyCmsMode || (OptimizelyCmsMode = {}));
13
+ const _clientContext = createContext({
14
+ factory: new UndefinedComponentFactory(),
15
+ inEditMode: false,
16
+ inPreviewMode: false,
17
+ isDebug: false,
18
+ isDebugOrDevelopment: false,
19
+ isDevelopment: false,
20
+ setLocale: () => { throw new Error("Not implemented"); },
21
+ setMode: () => { throw new Error("Not implemented"); }
22
+ });
23
+ _clientContext.displayName = "Optimizely CMS Provider";
24
+ export const OptimizelyCms = ({ factory, client, clientToken, children, isDebug, isDevelopment, initialMode = OptimizelyCmsMode.default, initialComponents = [] }) => {
25
+ const CtxProvider = _clientContext.Provider;
26
+ //#region React State
27
+ const [locale, setLocale] = useState();
28
+ const [mode, setMode] = useState(initialMode);
29
+ //#endregion
30
+ //#region Memoized Optimizely Graph Client
31
+ const graphClient = useMemo(() => {
32
+ const gc = isOptiGraphClient(client) ? client : createClient(isOptiGraphConfig(client) ? client : undefined);
33
+ if (clientToken)
34
+ gc.updateAuthentication(clientToken);
35
+ return gc;
36
+ }, [client, clientToken]);
37
+ //#endregion
38
+ //#region Memoized Debug and Development flags
39
+ const isDev = useMemo(() => isDevelopment == undefined ? getNodeEnv() == 'development' : isDevelopment, [isDevelopment]);
40
+ const isDbg = useMemo(() => isDebug == undefined ? graphClient.debug : isDebug, [isDebug, graphClient]);
41
+ //#endregion
42
+ //#region Memoized Component Factory
43
+ const ctxFactory = useMemo(() => {
44
+ if (factory)
45
+ return factory;
46
+ const newFactory = getFactory();
47
+ newFactory.registerAll(initialComponents);
48
+ return newFactory;
49
+ }, [factory]);
50
+ //#endregion
51
+ const ctxValue = {
52
+ client: graphClient,
53
+ factory: ctxFactory,
54
+ isDebug: isDbg,
55
+ isDevelopment: isDev,
56
+ isDebugOrDevelopment: isDbg || isDev,
57
+ inEditMode: mode == OptimizelyCmsMode.edit,
58
+ inPreviewMode: mode == OptimizelyCmsMode.preview,
59
+ locale,
60
+ setLocale,
61
+ setMode
62
+ };
63
+ return _jsx(CtxProvider, { value: ctxValue, children: children });
64
+ };
65
+ export const useOptimizelyCms = () => {
66
+ return useContext(_clientContext);
67
+ };
68
+ function getNodeEnv() {
69
+ let env;
70
+ try {
71
+ env = process.env.NODE_ENV;
72
+ }
73
+ catch {
74
+ // Ignored on purpose
75
+ }
76
+ return env || 'production';
77
+ }
78
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/context/client.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AACZ,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAsF,MAAM,OAAO,CAAC;AACzJ,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,YAAY,EAAqD,MAAM,iCAAiC,CAAC;AAExJ,OAAO,EAAE,UAAU,EAAuD,MAAM,qBAAqB,CAAC;AACtG,OAAO,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAA;AAE/D,MAAM,CAAN,IAAkB,iBAIjB;AAJD,WAAkB,iBAAiB;IAC/B,wCAAmB,CAAA;IACnB,kCAAa,CAAA;IACb,wCAAmB,CAAA;AACvB,CAAC,EAJiB,iBAAiB,KAAjB,iBAAiB,QAIlC;AAQD,MAAM,cAAc,GAAG,aAAa,CAAgB;IAChD,OAAO,EAAE,IAAI,yBAAyB,EAAE;IACxC,UAAU,EAAE,KAAK;IACjB,aAAa,EAAE,KAAK;IACpB,OAAO,EAAE,KAAK;IACd,oBAAoB,EAAE,KAAK;IAC3B,aAAa,EAAE,KAAK;IACpB,SAAS,EAAE,GAAG,EAAE,GAAG,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAA,CAAA,CAAC;IACtD,OAAO,EAAE,GAAG,EAAE,GAAG,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAA,CAAA,CAAC;CACvD,CAAC,CAAA;AACF,cAAc,CAAC,WAAW,GAAG,yBAAyB,CAAA;AAiEtD,MAAM,CAAC,MAAM,aAAa,GAA8D,CAAC,EACrF,OAAO,EACP,MAAM,EACN,WAAW,EACX,QAAQ,EACR,OAAO,EACP,aAAa,EACb,WAAW,GAAG,iBAAiB,CAAC,OAAO,EACvC,iBAAiB,GAAG,EAAE,EACzB,EAAE,EAAE;IAED,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