@remkoj/optimizely-cms-react 2.0.4 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (147) hide show
  1. package/README.md +36 -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 +54 -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} +27 -36
  31. package/dist/components/cms-content-area/index.js.map +1 -0
  32. package/dist/{server/components → components/cms-content-area}/types.d.ts +7 -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} +0 -18
  78. package/dist/{factory.js → factory/default.js} +1 -33
  79. package/dist/factory/default.js.map +1 -0
  80. package/dist/factory/index.d.ts +12 -0
  81. package/dist/factory/index.js +16 -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/package.json +12 -24
  100. package/dist/browser/context.d.ts +0 -6
  101. package/dist/browser/context.js +0 -15
  102. package/dist/browser/context.js.map +0 -1
  103. package/dist/browser/index.d.ts +0 -1
  104. package/dist/browser/index.js +0 -2
  105. package/dist/browser/index.js.map +0 -1
  106. package/dist/components/cms-styles.js.map +0 -1
  107. package/dist/components/index.d.ts +0 -2
  108. package/dist/components/index.js +0 -3
  109. package/dist/components/index.js.map +0 -1
  110. package/dist/components/rich-text.js +0 -138
  111. package/dist/components/rich-text.js.map +0 -1
  112. package/dist/factory.js.map +0 -1
  113. package/dist/server/components/cms-content-area.d.ts +0 -13
  114. package/dist/server/components/cms-content-area.js.map +0 -1
  115. package/dist/server/components/cms-content.d.ts +0 -11
  116. package/dist/server/components/cms-content.js +0 -125
  117. package/dist/server/components/cms-content.js.map +0 -1
  118. package/dist/server/components/cms-editable.js +0 -18
  119. package/dist/server/components/cms-editable.js.map +0 -1
  120. package/dist/server/components/get-content-type.d.ts +0 -12
  121. package/dist/server/components/get-content-type.js +0 -51
  122. package/dist/server/components/get-content-type.js.map +0 -1
  123. package/dist/server/components/index.d.ts +0 -4
  124. package/dist/server/components/index.js +0 -5
  125. package/dist/server/components/index.js.map +0 -1
  126. package/dist/server/components/queries.js.map +0 -1
  127. package/dist/server/components/visual-builder/Composition.js.map +0 -1
  128. package/dist/server/components/visual-builder/functions.js.map +0 -1
  129. package/dist/server/components/visual-builder/index.d.ts +0 -4
  130. package/dist/server/components/visual-builder/index.js +0 -4
  131. package/dist/server/components/visual-builder/index.js.map +0 -1
  132. package/dist/server/components/visual-builder/types.js.map +0 -1
  133. package/dist/server/context.d.ts +0 -22
  134. package/dist/server/context.js +0 -81
  135. package/dist/server/context.js.map +0 -1
  136. package/dist/server/factory.d.ts +0 -10
  137. package/dist/server/factory.js +0 -18
  138. package/dist/server/factory.js.map +0 -1
  139. package/dist/server/index.d.ts +0 -6
  140. package/dist/server/index.js +0 -6
  141. package/dist/server/index.js.map +0 -1
  142. /package/dist/{server/components → components/cms-content-area}/types.js +0 -0
  143. /package/dist/components/{cms-styles.d.ts → cms-styles/index.d.ts} +0 -0
  144. /package/dist/{server → components}/type-utils.d.ts +0 -0
  145. /package/dist/{server → components}/type-utils.js +0 -0
  146. /package/dist/{server/components → components}/visual-builder/types.js +0 -0
  147. /package/dist/{server/components → data}/queries.d.ts +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rsc.js","sourceRoot":"","sources":["../../../src/components/cms-content/rsc.tsx"],"names":[],"mappings":";AAEA,OAAO,cAAc,MAAM,uBAAuB,CAAA;AAClD,OAAO,UAAU,MAAM,kBAAkB,CAAA;AACzC,OAAO,EAAE,QAAQ,EAAE,oBAAoB,E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AS,EAAE,CAAC,CAAA;QACjK,IAAI,CAAC,GAAG,CAAC,UAAU,IAAI,GAAG,CAAC,aAAa,CAAC,IAAI,WAAW,CAAC,eAAe,IAAI,QAAQ,CAAC,MAAM;YACvF,OAAO,CAAC,IAAI,CAAC,mBAAoB,IAAK,iIAAiI,CAAC,CAAA;IAChL,CAAC;IAED,kDAAkD;IAClD,MAAM,SAAS,GAAG,gBAAgB,CAAC,aAAa,EAAE,iBAAiB,EAAE,GAAG,CAAC,CAAA;IACzE,IAAI,2BAA2B,CAAC,SAAS,CAAC;QACtC,OAAO,KAAC,SAAS,KAAG,CAAA;IAExB,kDAAkD;IAClD,MAAM,IAAI,GAAG,MAAM,UAAU,CAAC,WAAW,EAAE,WAAW,EAAE,SAAS,EAAE,YAAY,EAAE,UAAU,CAAC,CAAA;IAE5F,8BAA8B;IAC9B,OAAO,KAAC,SAAS,IAAC,WAAW,EAAG,WAA0B,EAAG,IAAI,EAAG,IAAI,EAAG,UAAU,EAAG,GAAG,CAAC,UAAU,EAAG,WAAW,EAAG,WAAW,YAAK,QAAQ,GAAa,CAAA;AAChK,CAAC;AAED,eAAe,UAAU,CAAA"}
@@ -0,0 +1,54 @@
1
+ import { type PropsWithChildren, type ComponentType, type ComponentProps, type ReactNode } from 'react';
2
+ import type { CmsComponent } from '../../types.js';
3
+ import type { PropsWithContext } from "../../context/types.js";
4
+ import type { ContentLinkWithLocale, InlineContentLinkWithLocale } from "@remkoj/optimizely-graph-client";
5
+ export type CmsContentProps<LocalesType = string> = PropsWithChildren<{
6
+ /**
7
+ * The content type to render
8
+ */
9
+ contentType?: string[];
10
+ /**
11
+ * The content link to render
12
+ */
13
+ contentLink: ContentLinkWithLocale<LocalesType> | InlineContentLinkWithLocale<LocalesType>;
14
+ /**
15
+ * The initial, pre-loaded data. If set this will be used instead of having the
16
+ * component fetching its' own data. So be sure that this leverages the fragment
17
+ * specified by the component.
18
+ *
19
+ * It will filter out the fiels from the IContentData fragment, to determine if
20
+ * data has been provided.
21
+ */
22
+ fragmentData?: {
23
+ [fieldname: string]: any;
24
+ };
25
+ /**
26
+ * The native key to use when the element is part of an array
27
+ */
28
+ key?: string;
29
+ /**
30
+ * The prefix to apply to the content type, to allow loading of different templates based
31
+ * upon location of usage. If set and the content type already starts with this prefix,
32
+ * it will not be applied.
33
+ */
34
+ contentTypePrefix?: string;
35
+ /**
36
+ * Any layout properties inferred from the context
37
+ */
38
+ layoutProps?: Record<string, any>;
39
+ /**
40
+ * When set to true, this will prevent the CmsContent component to try loading content from
41
+ * the store
42
+ */
43
+ noDataLoad?: boolean;
44
+ }>;
45
+ export type PropsWithCmsContent<T = any> = T & {
46
+ cmsContent: CmsContentComponent;
47
+ };
48
+ export type BaseCmsContentProps<LocalesType = string> = PropsWithContext<CmsContentProps<LocalesType>>;
49
+ export type CmsContentComponent = <LocalesType = string>(props: CmsContentProps<LocalesType>) => ReactNode;
50
+ export type CmsContentBaseComponent = <LocalesType = string>(props: BaseCmsContentProps<LocalesType>) => ReactNode;
51
+ export type CmsComponentProps = ComponentProps<CmsComponent> & {
52
+ [key: string]: any;
53
+ };
54
+ export type EnhancedCmsComponent = ComponentType<CmsComponentProps>;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/components/cms-content/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ import { type ComponentType } from "react";
2
+ import { type CmsContentComponent, type PropsWithCmsContent } from "./types.js";
3
+ export declare function cmsContentAware<P = any>(component: ComponentType<PropsWithCmsContent<P>>, cmsContentComponent: CmsContentComponent): ComponentType<P>;
@@ -0,0 +1,6 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ export function cmsContentAware(component, cmsContentComponent) {
3
+ const BaseComponent = component;
4
+ return (props) => _jsx(BaseComponent, { cmsContent: cmsContentComponent, ...props });
5
+ }
6
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/components/cms-content/utils.tsx"],"names":[],"mappings":";AAGA,MAAM,UAAU,eAAe,CAAU,SAAgD,EAAE,mBAAwC;IAE/H,MAAM,aAAa,GAAG,SAAS,CAAA;IAC/B,OAAO,CAAC,KAAQ,EAAE,EAAE,CAAC,KAAC,aAAa,IAAC,UAAU,EAAE,mBAAmB,KAAO,KAAK,GAAK,CAAA;AACxF,CAAC"}
@@ -0,0 +1,17 @@
1
+ import type { ElementType } from '../type-utils.js';
2
+ import type { BaseCmsContentAreaProps } from './types.js';
3
+ export type { CmsContentAreaClassMapper, CmsContentAreaProps, ContentAreaItemDefinition, CmsContentAreaComponent } from './types.js';
4
+ /**
5
+ * React server component to render a content area
6
+ *
7
+ * @param param0 The content area information for rendering
8
+ * @returns
9
+ */
10
+ export declare const CmsContentArea: <T extends ElementType = "div", I extends ElementType = "div">({ items, classMapper, className, fieldName, as: elementType, itemsProperty, itemWrapper, ctx, cmsContent: CmsContent, ...additionalProps }: BaseCmsContentAreaProps<T, I>) => JSX.Element;
11
+ /**
12
+ *
13
+ * @param items
14
+ * @param locale
15
+ * @returns
16
+ */
17
+ export default CmsContentArea;
@@ -1,11 +1,7 @@
1
- import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
2
- import 'server-only';
3
- import CmsContent from './cms-content.js';
1
+ import { jsx as _jsx } from "react/jsx-runtime";
4
2
  import * as Utils from '../../utilities.js';
5
3
  import * as Errors from '../../errors.js';
6
- import createClient from '@remkoj/optimizely-graph-client';
7
4
  import { normalizeContentLinkWithLocale, contentLinkToString } from '@remkoj/optimizely-graph-client/utils';
8
- import getServerContext from '../context.js';
9
5
  //#endregion
10
6
  /**
11
7
  * React server component to render a content area
@@ -13,25 +9,11 @@ import getServerContext from '../context.js';
13
9
  * @param param0 The content area information for rendering
14
10
  * @returns
15
11
  */
16
- export const CmsContentArea = async ({ items, classMapper, className, fieldName, as: elementType, itemsProperty, itemWrapper, locale: _locale, client: _client, factory: _factory, inEditMode: _inEditMode, ...additionalProps }) => {
17
- const context = getServerContext();
18
- if (context.isDebugOrDevelopment && !context.client)
19
- console.warn(`🟠 [CmsContentArea] No Content Graph client provided for ${fieldName ?? 'CmsContentArea'}, this will cause problems with edit mode!`);
20
- // Parse & prepare props
21
- const { inEditMode, factory, locale: ctxLocale } = context;
22
- const gqlClient = context.client ?? createClient();
23
- // Determine locale
24
- const locale = _locale ?? ctxLocale;
25
- if (context.isDebug && locale == _locale && locale != ctxLocale) {
26
- console.warn(`🟠 [CmsContentArea] The Context Locale for ContentArea ${fieldName ?? 'CmsContentArea'}, was overridden. Context Locale ${ctxLocale}, current locale ${locale}`);
27
- }
28
- if (!locale) {
29
- console.error(`🔴 [CmsContentArea] No locale set on the ServerContext, which is required to make the ContentArea${fieldName ? ' ' + fieldName : ''} render its content`);
30
- return _jsx(_Fragment, {});
31
- }
12
+ export const CmsContentArea = ({ items, classMapper, className, fieldName, as: elementType, itemsProperty, itemWrapper, ctx, cmsContent: CmsContent, ...additionalProps }) => {
13
+ const { inEditMode = false } = ctx;
32
14
  // Convert the items to a list of enriched content types and filter out items cannot be loaded
33
15
  const actualItems = (items || []).filter(forValidContentAreaItems);
34
- const componentData = await Promise.all(actualItems.map(async (item, idx) => {
16
+ const componentData = actualItems.map((item, idx) => {
35
17
  // Prepare data from received content area format
36
18
  const contentLink = normalizeContentLinkWithLocale(item._metadata);
37
19
  if (!contentLink)
@@ -49,7 +31,7 @@ export const CmsContentArea = async ({ items, classMapper, className, fieldName,
49
31
  "data-tag": item.tag || undefined,
50
32
  ...contentItemElementProps
51
33
  };
52
- const contentAraeItemContent = await CmsContent({ contentLink, contentType, fragmentData, client: gqlClient, factory, outputEditorWarning: inEditMode, contentTypePrefix: "Component" });
34
+ const contentAraeItemContent = _jsx(CmsContent, { contentLink: contentLink, contentType: contentType, fragmentData: fragmentData, contentTypePrefix: "Component" });
53
35
  // Inject the element into the wrapper
54
36
  const childrenTarget = contentItemTarget || "children";
55
37
  let contentAreaItemContainerChildren = undefined;
@@ -59,7 +41,7 @@ export const CmsContentArea = async ({ items, classMapper, className, fieldName,
59
41
  contentAreaItemContainerProps[childrenTarget] = contentAraeItemContent;
60
42
  const ContentAreaItemContainer = contentItemElement || "div";
61
43
  return _jsx(ContentAreaItemContainer, { ...contentAreaItemContainerProps, children: contentAreaItemContainerChildren }, contentAreaItemContainerKey);
62
- }));
44
+ });
63
45
  // Build container element
64
46
  const contentAreaContainerProps = {
65
47
  className: `opti-content-area ${Array.isArray(className) ? className.join(' ') : (className ?? '')}`.trim(),
@@ -78,19 +60,28 @@ export const CmsContentArea = async ({ items, classMapper, className, fieldName,
78
60
  function forValidContentAreaItems(itm) {
79
61
  return typeof (itm) == 'object' && itm != null && typeof (itm._metadata) == 'object' && itm._metadata != null;
80
62
  }
81
- export async function processContentAreaItems(items, locale) {
82
- const actualItems = (items ?? []).filter(Utils.isNotNullOrUndefined);
83
- return Promise.all(actualItems.map(async (item, idx) => {
63
+ /**
64
+ *
65
+ * @param items
66
+ * @param locale
67
+ * @returns
68
+ */
69
+ /*export function processContentAreaItems( items?: (ContentAreaItemDefinition | null)[] | null, locale?: string) : JSX.Element[]
70
+ {
71
+ const actualItems = (items ?? []).filter(Utils.isNotNullOrUndefined)
72
+ return actualItems.map((item, idx) => {
84
73
  // Prepare data from received content area format
85
- const contentLink = normalizeContentLinkWithLocale({ ...item.item, locale: locale });
74
+ const contentLink = normalizeContentLinkWithLocale({ ...item.item, locale: locale })
86
75
  if (!contentLink)
87
- throw new Errors.InvalidContentLinkError({ ...item.item, locale: locale });
88
- const contentType = Utils.normalizeContentType(item.item?.data?.contentType);
89
- const fragmentData = item.item?.data || undefined;
90
- const guidValue = (item.item?.guidValue ?? "00000000-0000-0000-0000-000000000000") + "::" + idx;
76
+ throw new Errors.InvalidContentLinkError({ ...item.item, locale: locale })
77
+ const contentType = Utils.normalizeContentType(item.item?.data?.contentType)
78
+ const fragmentData = item.item?.data || undefined
79
+ const guidValue = (item.item?.guidValue ?? "00000000-0000-0000-0000-000000000000")+"::"+idx
80
+
91
81
  // Build output
92
- return await CmsContent({ contentLink, contentType, fragmentData, key: guidValue });
93
- }));
94
- }
82
+ const content : JSX.Element = <CmsContent contentLink={ contentLink } contentType={ contentType } fragmentData={ fragmentData } key={ guidValue } />
83
+ return content
84
+ })
85
+ }*/
95
86
  export default CmsContentArea;
96
- //# sourceMappingURL=cms-content-area.js.map
87
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/cms-content-area/index.tsx"],"names":[],"mappings":";AACA,OAAO,KAAK,KAAK,MAAM,oBAAoB,CAAA;AAC3C,OAAO,KAAK,MAAM,MAAM,iBAAiB,CAAA;AACzC,OAAO,EAAE,8BAA8B,EAAE,mBAAmB,EAAE,MAAM,uCAAuC,CAAA;AAK3G,YAAY;AAEZ;;;;;GAKG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAA+D,EACzF,KAAK,EACL,WAAW,EACX,SAAS,EACT,SAAS,EACT,EAAE,EAAE,WAAW,EACf,aAAa,EACb,WAAW,EAEX,GAAG,EACH,UAAU,EAAE,UAAU,EAEtB,GAAG,eAAe,EACS,EAAgB,EAAE;IAC7C,MAAM,EAAE,UAAU,GAAG,KAAK,EAAE,GAAG,GAAG,CAAA;IAElC,8FAA8F;IAC9F,MAAM,WAAW,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,wBAAwB,CAAC,CAAA;IAClE,MAAM,aAAa,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE;QAChD,iDAAiD;QACjD,MAAM,WAAW,GAAG,8BAA8B,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;QAClE,IAAI,CAAC,WAAW;YACZ,MAAM,IAAI,MAAM,CAAC,uBAAuB,CAAC,IAAI,CAAC,SAAS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c,CAAA"}
@@ -1,74 +1,8 @@
1
- import type { SuspenseProps, PropsWithChildren } from "react";
2
- import type { ComponentFactory, ContentType } from "../../types.js";
1
+ import type { ReactNode, SuspenseProps } from "react";
2
+ import type { PropsWithContext } from "../../context/types.js";
3
+ import type { PropsWithCmsContent } from "../cms-content/types.js";
4
+ import type { ContentType } from "../../types.js";
3
5
  import type { ElementChildrenProps, ElementProps, ElementType, PropTypeIfPropExists, MayBeArray, TypeIfPropExists } from '../type-utils.js';
4
- import type { IOptiGraphClient, ContentLinkWithLocale, InlineContentLinkWithLocale } from "@remkoj/optimizely-graph-client";
5
- export type CmsContentProps<LocalesType = string> = PropsWithChildren<{
6
- /**
7
- * The content type to render
8
- */
9
- contentType?: string[];
10
- /**
11
- * The content link to render
12
- */
13
- contentLink: ContentLinkWithLocale<LocalesType> | InlineContentLinkWithLocale<LocalesType>;
14
- /**
15
- * The initial, pre-loaded data. If set this will be used instead of having the
16
- * component fetching its' own data. So be sure that this leverages the fragment
17
- * specified by the component.
18
- *
19
- * It will filter out the fiels from the IContentData fragment, to determine if
20
- * data has been provided.
21
- */
22
- fragmentData?: {
23
- [fieldname: string]: any;
24
- };
25
- /**
26
- * The native key to use when the element is part of an array
27
- */
28
- key?: string;
29
- /**
30
- * If enabled, it will flag all rendering to be inclusive of the Optimizely Edit mode
31
- * attributes for On Page Editing
32
- *
33
- * @deprecated Will be retrieved from the ServerContext
34
- */
35
- inEditMode?: boolean;
36
- /**
37
- * The Optimizely Graph client to use, it will use a new instance if none is provided,
38
- * the new instance will always use the SingleKey i.e. thus not load edit mode content
39
- *
40
- * @deprecated Will be retrieved from the ServerContext
41
- */
42
- client?: IOptiGraphClient;
43
- /**
44
- * The component factory to use, it will use the default instance if not provided
45
- *
46
- * @deprecated Will be retrieved from the ServerContext
47
- */
48
- factory?: ComponentFactory;
49
- /**
50
- * If enabled any warnings intended for an editor will be shown, even if "inEditMode"
51
- * is false.
52
- *
53
- * @deprecated Will be retrieved from the ServerContext
54
- */
55
- outputEditorWarning?: boolean;
56
- /**
57
- * The prefix to apply to the content type, to allow loading of different templates based
58
- * upon location of usage. If set and the content type already starts with this prefix,
59
- * it will not be applied.
60
- */
61
- contentTypePrefix?: string;
62
- /**
63
- * Any layout properties inferred from the context
64
- */
65
- layoutProps?: Record<string, any>;
66
- /**
67
- * When set to true, this will prevent the CmsContent component to try loading content from
68
- * the store
69
- */
70
- noDataLoad?: boolean;
71
- }>;
72
6
  export type ContentAreaItemDefinition = {
73
7
  __typename?: string | null;
74
8
  _type?: string | null;
@@ -153,30 +87,6 @@ export type CmsContentAreaProps<T extends ElementType, CT extends ElementType> =
153
87
  */
154
88
  itemsProperty: ElementChildrenProps<CT>;
155
89
  }) & Omit<Omit<ElementProps<CT>, "className" | "data-epi-block-id" | "data-displayoption" | "data-tag">, ElementChildrenProps<CT>>);
156
- /**
157
- * Ignored if provided
158
- *
159
- * @deprecated The ServerContext is used to access the current locale
160
- */
161
- locale?: string;
162
- /**
163
- * Ignored if provided
164
- *
165
- * @deprecated The ServerContext is used to access the current edit mode status
166
- */
167
- inEditMode?: boolean;
168
- /**
169
- * Ignored if provided
170
- *
171
- * @deprecated The ServerContext is used to access the current Optimizely Graph Client
172
- */
173
- client?: IOptiGraphClient;
174
- /**
175
- * Ignored if provided
176
- *
177
- * @deprecated The ServerContext is used to access the current Component Factory
178
- */
179
- factory?: ComponentFactory;
180
90
  } & Omit<Omit<ElementProps<T>, "className" | "data-epi-edit">, ElementChildrenProps<T>> & ("children" extends ElementChildrenProps<T> ? {
181
91
  /**
182
92
  * The property of the component set for the "as" property of the Content Area which
@@ -193,3 +103,6 @@ export type CmsContentAreaProps<T extends ElementType, CT extends ElementType> =
193
103
  itemsProperty: ElementChildrenProps<T>;
194
104
  });
195
105
  export type CmsContentAreaClassMapper = (displayOption: string, contentType: ContentType | null, index: number) => string;
106
+ export type BaseCmsContentAreaProps<T extends ElementType, CT extends ElementType> = PropsWithCmsContent<PropsWithContext<CmsContentAreaProps<T, CT>>>;
107
+ export type CmsContentAreaBaseComponent = <T extends ElementType, CT extends ElementType>(props: BaseCmsContentAreaProps<T, CT>) => ReactNode;
108
+ export type CmsContentAreaComponent = <T extends ElementType, CT extends ElementType>(props: CmsContentAreaProps<T, CT>) => ReactNode;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/components/cms-content-area/types.ts"],"names":[],"mappings":""}
@@ -1,5 +1,5 @@
1
- import 'server-only';
2
- import { type ComponentProps, type ComponentType as ReactComponentType, type ExoticComponent as ReactExoticComponent } from 'react';
1
+ import { type ComponentProps, type ComponentType as ReactComponentType, type ExoticComponent as ReactExoticComponent, type ReactNode } from 'react';
2
+ import { PropsWithContext } from '../../context/types.js';
3
3
  export type EditableComponentType = (ReactComponentType<any>) | (ReactExoticComponent<any>) | (keyof JSX.IntrinsicElements);
4
4
  export type EditableComponentProps<FT extends EditableComponentType> = FT extends keyof JSX.IntrinsicElements ? JSX.IntrinsicElements[FT] : ComponentProps<FT>;
5
5
  export type CmsEditableProps<FT extends EditableComponentType> = {
@@ -11,6 +11,8 @@ export type CmsEditableProps<FT extends EditableComponentType> = {
11
11
  cmsId?: never;
12
12
  cmsFieldName?: string | null;
13
13
  }) & EditableComponentProps<FT>;
14
+ export type CmsEditableComponent = <CT extends EditableComponentType>(props: CmsEditableProps<CT>) => ReactNode;
15
+ export type CmsEditableBaseComponent = <CT extends EditableComponentType>(props: PropsWithContext<CmsEditableProps<CT>>) => ReactNode;
14
16
  /**
15
17
  * Server side wrapper to create HTML elements that include the needed
16
18
  * data-epi- properties to render the edit mode markers
@@ -18,5 +20,5 @@ export type CmsEditableProps<FT extends EditableComponentType> = {
18
20
  * @param param0 The HTML element with the simple properties
19
21
  * @returns
20
22
  */
21
- export declare const CmsEditable: <CT extends EditableComponentType = "div">({ as: DefaultElement, cmsId, cmsFieldName, children, key, ...props }: CmsEditableProps<CT>) => import("react/jsx-runtime").JSX.Element;
23
+ export declare const CmsEditable: CmsEditableBaseComponent;
22
24
  export default CmsEditable;
@@ -0,0 +1,15 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ /**
3
+ * Server side wrapper to create HTML elements that include the needed
4
+ * data-epi- properties to render the edit mode markers
5
+ *
6
+ * @param param0 The HTML element with the simple properties
7
+ * @returns
8
+ */
9
+ //@ts-expect-error Typescript doesn't understand the property type :'(
10
+ export const CmsEditable = ({ ctx, as: DefaultElement = 'div', cmsId, cmsFieldName, children, key, ...props }) => {
11
+ const { inEditMode } = ctx;
12
+ return _jsx(DefaultElement, { ...props, "data-epi-block-id": inEditMode ? cmsId ?? undefined : undefined, "data-epi-property-name": inEditMode ? cmsFieldName ?? undefined : undefined, children: children });
13
+ };
14
+ export default CmsEditable;
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/cms-editable/index.tsx"],"names":[],"mappings":";AAiBA;;;;;;GAMG;AACH,sEAAsE;AACtE,MAAM,CAAC,MAAM,WAAW,GAA8B,CAA2C,EAAE,GAAG,EAAE,EAAE,EAAE,cAAc,GAAG,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,KAAK,EAA0C,EAAE,EAAE;IAE1N,MAAM,EAAE,UAAU,EAAE,GAAG,GAAG,CAAA;IAC1B,OAAO,KAAC,cAAc,OAAK,KAAK,uBAAsB,UAAU,CAAC,CAAC,CAAC,KAAK,IAAI,SAAS,CAAC,CAAC,CAAC,SAAS,4BAA4B,UAAU,CAAC,CAAC,CAAC,YAAY,IAAI,SAAS,CAAC,CAAC,CAAC,SAAS,YAAK,QAAQ,GAAmB,CAAA;AACnN,CAAC,CAAA;AAED,eAAe,WAAW,CAAA"}
@@ -20,4 +20,4 @@ export function extractSettings(from) {
20
20
  });
21
21
  return extracted;
22
22
  }
23
- //# sourceMappingURL=cms-styles.js.map
23
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/cms-styles/index.tsx"],"names":[],"mappings":"AA0CA;;;;;;;GAOG;AACH,MAAM,UAAU,WAAW,CAIzB,IAAmB,EAAE,WAAc,EAAE,YAAiB;IAGpD,MAAM,EAAE,GAAG,IAAI,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,IAAI,WAAW,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,CAAA;IACtE,OAAO,CAAC,EAAE,IAAI,YAAY,CAAO,CAAA;AACrC,CAAC;AAED,MAAM,UAAU,eAAe,CAA6B,IAAmB;IAG3E,IAAI,CAAC,IAAI;QACL,OAAO,EAAQ,CAAA;IACnB,MAAM,SAAS,GAAiB,EAAE,CAAA;IAClC,IAAI,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;QAC5B,IAAI,GAAG,CAAC,KAAK;YACT,SAAS,CAAC,GAAG,CAAC,GAAe,CAAC,GAAG,GAAG,CAAC,KAAqB,CAAA;IAClE,CAAC,CAAC,CAAA;IACF,OAAO,SAAe,CAAA;AAC1B,CAAC"}
@@ -0,0 +1,14 @@
1
+ import { type FunctionComponent, type PropsWithChildren } from "react";
2
+ import { ComponentTypeDictionary } from "../../factory/types.js";
3
+ import type { TextNode, TypedNode } from "./types.js";
4
+ 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] & {
5
+ node: TypedNode;
6
+ }>) => import("react/jsx-runtime").JSX.Element;
7
+ export declare const DefaultTextNode: FunctionComponent<{
8
+ node: TextNode;
9
+ }>;
10
+ /**
11
+ * A default component dictionary that allows to serialize the structured HTML
12
+ * into React, using the component library shared across the react SDK.
13
+ */
14
+ export declare const DefaultComponents: ComponentTypeDictionary;
@@ -0,0 +1,63 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { decodeHTML } from 'entities';
3
+ //#region HTML Components
4
+ export function createHtmlComponent(element, ignoreChildren = false, defaultProps) {
5
+ const HtmlElement = element;
6
+ const reservedProps = ['url', 'class', 'children', 'type'];
7
+ const component = ({ children, node, ...props }) => {
8
+ const nodeProps = {};
9
+ const renderProps = Object.getOwnPropertyNames(node);
10
+ renderProps.filter(x => !reservedProps.includes(x)).forEach(x => nodeProps[x] = node[x]);
11
+ if (renderProps.includes('class'))
12
+ nodeProps['className'] = node['class'];
13
+ if (renderProps.includes('url')) {
14
+ switch (node.type) {
15
+ case 'link':
16
+ nodeProps['href'] = node['url'];
17
+ break;
18
+ case 'image':
19
+ nodeProps['src'] = node['url'];
20
+ break;
21
+ default:
22
+ nodeProps['data-url'] = node['url'];
23
+ break;
24
+ }
25
+ }
26
+ return ignoreChildren ? _jsx(HtmlElement, { ...defaultProps, ...nodeProps, ...props }) : _jsx(HtmlElement, { ...defaultProps, ...nodeProps, ...props, children: children });
27
+ };
28
+ return component;
29
+ }
30
+ export const DefaultTextNode = ({ node }) => {
31
+ if (node.bold)
32
+ return _jsx("strong", { children: decodeHTML(node.text) });
33
+ if (node.italic)
34
+ return _jsx("em", { children: decodeHTML(node.text) });
35
+ const unsupportedProps = Object.getOwnPropertyNames(node).filter(x => x != 'text');
36
+ if (unsupportedProps.length > 0 && process.env.NODE_ENV != 'production')
37
+ console.warn('🟠 [Rich Text] Text node with unsupported additional properties:', unsupportedProps.join(', '));
38
+ return decodeHTML(node.text);
39
+ };
40
+ /**
41
+ * A default component dictionary that allows to serialize the structured HTML
42
+ * into React, using the component library shared across the react SDK.
43
+ */
44
+ export const DefaultComponents = [
45
+ { type: 'RichText/richText', component: createHtmlComponent("div", false, { className: "cms:rich-text" }) },
46
+ { type: 'RichText/paragraph', component: createHtmlComponent("p") },
47
+ { type: 'RichText/span', component: createHtmlComponent("span") },
48
+ { type: 'RichText/div', component: createHtmlComponent("div") },
49
+ { type: 'RichText/heading-one', component: createHtmlComponent("h1") },
50
+ { type: 'RichText/heading-two', component: createHtmlComponent("h2") },
51
+ { type: 'RichText/heading-three', component: createHtmlComponent("h3") },
52
+ { type: 'RichText/heading-four', component: createHtmlComponent("h4") },
53
+ { type: 'RichText/heading-five', component: createHtmlComponent("h5") },
54
+ { type: 'RichText/heading-six', component: createHtmlComponent("h6") },
55
+ { type: 'RichText/link', component: createHtmlComponent("a") },
56
+ { type: 'RichText/image', component: createHtmlComponent("img", true) },
57
+ { type: 'RichText/text', component: DefaultTextNode },
58
+ { type: 'RichText/br', component: createHtmlComponent("br", true) },
59
+ { type: 'RichText/bulleted-list', component: createHtmlComponent("ul") },
60
+ { type: 'RichText/numbered-list', component: createHtmlComponent("ol") },
61
+ { type: 'RichText/list-item', component: createHtmlComponent("li") }
62
+ ];
63
+ //# sourceMappingURL=components.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"components.js","sourceRoot":"","sources":["../../../src/components/rich-text/components.tsx"],"names":[],"mappings":";AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEtC,yBAAyB;AACzB,MAAM,UAAU,mBAAmB,CAAwC,OAAU,EAAE,iBAA0B,KAAK,EAAE,YAA+D;IAEnL,MAAM,WAAW,GAAG,OAAiB,CAAA;IACrC,MAAM,aAAa,GAAG,CAAC,KAAK,EAAC,OAAO,EAAC,UAAU,EAAC,MAAM,CAAC,CAAA;IACvD,MAAM,SAAS,GAAG,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,KAAK,EAAsE,EAAE,EAAE;QACnH,MAAM,SAAS,GAA8C,EAAE,CAAA;QAC/D,MAAM,WAAW,GAAG,MAAM,CAAC,mBAAmB,CAAC,IAAI,CAA2B,CAAA;QAC9E,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAA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eAAe,EAAE,SAAS,EAAE,mBAAmB,CAAC,GAAG,CAAC,EAAC;IAC7D,EAAE,IAAI,EAAE,gBAAgB,EAAE,SAAS,EAAE,mBAAmB,CAAC,KAAK,EAAE,IAAI,CAAC,EAAC;IACtE,EAAE,IAAI,EAAE,eAAe,EAAE,SAAS,EAAE,eAAe,EAAC;IACpD,EAAE,IAAI,EAAE,aAAa,EAAE,SAAS,EAAE,mBAAmB,CAAC,IAAI,EAAE,IAAI,CAAC,EAAC;IAClE,EAAE,IAAI,EAAE,wBAAwB,EAAE,SAAS,EAAE,mBAAmB,CAAC,IAAI,CAAC,EAAC;IACvE,EAAE,IAAI,EAAE,wBAAwB,EAAE,SAAS,EAAE,mBAAmB,CAAC,IAAI,CAAC,EAAC;IACvE,EAAE,IAAI,EAAE,oBAAoB,EAAE,SAAS,EAAE,mBAAmB,CAAC,IAAI,CAAC,EAAC;CACtE,CAAA"}
@@ -0,0 +1,4 @@
1
+ import { type FunctionComponent } from "react";
2
+ import type { RichTextProps } from "./types.js";
3
+ export * from "./types.js";
4
+ export declare const RichText: FunctionComponent<RichTextProps>;
@@ -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":["../../../src/components/rich-text/index.tsx"],"names":[],"mappings":";AAEA,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AACnE,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AAEzF,cAAc,YAAY,CAAA;AAE1B,MAAM,CAAC,MAAM,QAAQ,GAAsC,CAAC,EACxD,OAAO,EACP,IAAI,EACJ,SAAS,GAAG,WAAW,EACvB,EAAE,EAAG,OAAO,GAAG,KAAK,EACpB,KAAK,EACL,GAAG,KAAK,EACX,EAAE,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";
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