@remkoj/optimizely-cms-react 6.0.0-pre8 → 6.0.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +12 -12
- package/README.md +3 -4
- package/dist/components/cms-content/get-content-type.js +8 -17
- package/dist/components/cms-content/get-content-type.js.map +1 -1
- package/dist/components/cms-content/get-content.js +46 -50
- package/dist/components/cms-content/get-content.js.map +1 -1
- package/dist/components/cms-content/resolve-component.js +8 -9
- package/dist/components/cms-content/resolve-component.js.map +1 -1
- package/dist/components/cms-content/rsc.d.ts +1 -1
- package/dist/components/cms-content/rsc.js +9 -7
- package/dist/components/cms-content/rsc.js.map +1 -1
- package/dist/components/cms-content/types.d.ts +46 -2
- package/dist/components/cms-content-area/index.js +3 -3
- package/dist/components/cms-content-area/index.js.map +1 -1
- package/dist/components/cms-content-area/types.d.ts +51 -10
- package/dist/components/cms-editable/index.d.ts +86 -17
- package/dist/components/cms-editable/index.js +20 -10
- package/dist/components/cms-editable/index.js.map +1 -1
- package/dist/components/rich-text/index.d.ts +2 -1
- package/dist/components/rich-text/index.js +6 -3
- package/dist/components/rich-text/index.js.map +1 -1
- package/dist/components/rsc-components.d.ts +154 -5
- package/dist/components/rsc-components.js +153 -5
- package/dist/components/rsc-components.js.map +1 -1
- package/dist/components/rsc.d.ts +2 -0
- package/dist/components/rsc.js +1 -0
- package/dist/components/rsc.js.map +1 -1
- package/dist/components/visual-builder/functions.js +10 -17
- package/dist/components/visual-builder/functions.js.map +1 -1
- package/dist/components/visual-builder/index.d.ts +3 -1
- package/dist/components/visual-builder/index.js +19 -16
- package/dist/components/visual-builder/index.js.map +1 -1
- package/dist/components/visual-builder/types.d.ts +8 -2
- package/dist/context/client.js +5 -2
- package/dist/context/client.js.map +1 -1
- package/dist/context/rsc.d.ts +1 -1
- package/dist/context/rsc.js +11 -42
- package/dist/context/rsc.js.map +1 -1
- package/dist/context/shared.js +2 -1
- package/dist/context/shared.js.map +1 -1
- package/dist/context/types.d.ts +3 -11
- package/dist/factory/default.d.ts +20 -3
- package/dist/factory/default.js +41 -27
- package/dist/factory/default.js.map +1 -1
- package/dist/factory/types.d.ts +24 -4
- package/dist/factory/undef.d.ts +7 -5
- package/dist/factory/undef.js +10 -4
- package/dist/factory/undef.js.map +1 -1
- package/dist/rsc.d.ts +24 -0
- package/dist/rsc.js +24 -0
- package/dist/rsc.js.map +1 -1
- package/dist/types.d.ts +37 -6
- package/dist/utilities.d.ts +56 -6
- package/dist/utilities.js +112 -14
- package/dist/utilities.js.map +1 -1
- package/package.json +19 -15
|
@@ -53,31 +53,31 @@ export type ItemsProperty<T extends ElementType> = "children" extends ElementChi
|
|
|
53
53
|
export type PassthroughProps<T extends ElementType, ParentKeys extends string | number | symbol> = Omit<ElementProps<T>, ParentKeys | ReservedKeys | ElementChildrenProps<T>>;
|
|
54
54
|
export type CmsContentAreaCoreProps = PropsWithOptionalContext<{
|
|
55
55
|
/**
|
|
56
|
-
|
|
56
|
+
* Content area items to render.
|
|
57
|
+
*
|
|
58
|
+
* Each item should contain `_metadata` with at least a key and content type data.
|
|
57
59
|
*/
|
|
58
60
|
items: (ContentAreaItemDefinition | null | undefined)[] | undefined | null;
|
|
59
61
|
/**
|
|
60
|
-
|
|
61
|
-
* ContentArea to allow dynamic content within the ContentArea items.
|
|
62
|
+
* Whether a suspense boundary is applied around each rendered content area item.
|
|
62
63
|
*/
|
|
63
64
|
useSuspense?: boolean;
|
|
64
65
|
/**
|
|
65
|
-
|
|
66
|
+
* Fallback UI rendered while suspense-wrapped items are loading.
|
|
66
67
|
*/
|
|
67
68
|
fallback?: SuspenseProps['fallback'];
|
|
68
69
|
/**
|
|
69
|
-
|
|
70
|
-
|
|
70
|
+
* Name of the CMS field represented by this content area.
|
|
71
|
+
*
|
|
72
|
+
* Set this to enable in-context edit markers for the content area container.
|
|
71
73
|
*/
|
|
72
74
|
fieldName?: string;
|
|
73
75
|
/**
|
|
74
|
-
|
|
75
|
-
* items in the Content Area. Setting this to `true` ignores
|
|
76
|
+
* If `true`, no container wrapper is rendered around the full list of items.
|
|
76
77
|
*/
|
|
77
78
|
noWrapper?: boolean;
|
|
78
79
|
/**
|
|
79
|
-
*
|
|
80
|
-
* renditions, without changing the main path of the component.
|
|
80
|
+
* Optional template variant forwarded to each `CmsContent` item render.
|
|
81
81
|
*/
|
|
82
82
|
variant?: string;
|
|
83
83
|
}>;
|
|
@@ -117,6 +117,47 @@ export type CmsContentAreaItemWrapperProps<CT extends ElementType> = ({
|
|
|
117
117
|
*/
|
|
118
118
|
className?: MayBeArray<PropTypeIfPropExists<CT, "className">>;
|
|
119
119
|
} & ItemsProperty<CT> & PassthroughProps<CT, "as" | "noWrapper" | "className">);
|
|
120
|
+
/**
|
|
121
|
+
* Properties for `CmsContentArea`.
|
|
122
|
+
*
|
|
123
|
+
* Combines core rendering options and wrapper customization options.
|
|
124
|
+
*
|
|
125
|
+
* Property overview:
|
|
126
|
+
* - `items` (required): content area items to render.
|
|
127
|
+
* - `fieldName`: enables edit marker output for the content area.
|
|
128
|
+
* - `variant`: template variant for all rendered items.
|
|
129
|
+
* - `useSuspense` + `fallback`: per-item suspense rendering.
|
|
130
|
+
* - `noWrapper`: disables outer content area container.
|
|
131
|
+
* - `as`: outer container element/component.
|
|
132
|
+
* - `itemsProperty`: target prop on `as` component to inject item list.
|
|
133
|
+
* - `className`: classes for outer container.
|
|
134
|
+
* - `classMapper`: computes per-item wrapper classes from display option/type/index.
|
|
135
|
+
* - `itemWrapper`: configures per-item wrapper element, classes and prop target.
|
|
136
|
+
* - `ctx`: optional CMS context override.
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* ```tsx
|
|
140
|
+
* <CmsContentArea
|
|
141
|
+
* items={content.MainContentArea}
|
|
142
|
+
* fieldName="MainContentArea"
|
|
143
|
+
* as="section"
|
|
144
|
+
* className="main-content"
|
|
145
|
+
* />
|
|
146
|
+
* ```
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* ```tsx
|
|
150
|
+
* <CmsContentArea
|
|
151
|
+
* items={content.SidebarContentArea}
|
|
152
|
+
* itemWrapper={{ as: 'aside', className: 'sidebar-item' }}
|
|
153
|
+
* classMapper={(displayOption, contentType, index) =>
|
|
154
|
+
* `item-${index} display-${displayOption} type-${contentType?.join('-') ?? 'unknown'}`
|
|
155
|
+
* }
|
|
156
|
+
* useSuspense
|
|
157
|
+
* fallback={<div>Loading…</div>}
|
|
158
|
+
* />
|
|
159
|
+
* ```
|
|
160
|
+
*/
|
|
120
161
|
export type CmsContentAreaProps<T extends ElementType, CT extends ElementType> = CmsContentAreaCoreProps & CmsContentAreaWrapperProps<T, CT>;
|
|
121
162
|
export type CmsContentAreaClassMapper = (displayOption: string, contentType: ContentType | null, index: number) => string;
|
|
122
163
|
export type BaseCmsContentAreaProps<T extends ElementType, CT extends ElementType> = PropsWithCmsContent<PropsWithContext<CmsContentAreaProps<T, CT>>>;
|
|
@@ -2,48 +2,117 @@ import { PropsWithChildren, type ReactNode } from 'react';
|
|
|
2
2
|
import { GenericContext, PropsWithContext } from '../../context/types.js';
|
|
3
3
|
import type { ElementType, GenericContextProps, ElementProps } from '../type-utils.js';
|
|
4
4
|
import { type ContentLink } from '@remkoj/optimizely-graph-client';
|
|
5
|
+
/**
|
|
6
|
+
* Properties for `CmsEditable`.
|
|
7
|
+
*
|
|
8
|
+
* `CmsEditable` wraps output with Optimizely edit markers so fields and blocks can be
|
|
9
|
+
* selected in edit mode.
|
|
10
|
+
*
|
|
11
|
+
* Quick start:
|
|
12
|
+
* - Provide `cmsId` for block/content identification.
|
|
13
|
+
* - Provide `cmsFieldName` when you want field-level editing.
|
|
14
|
+
* - Choose wrapper element with `as` (defaults to `div`).
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```tsx
|
|
18
|
+
* <CmsEditable as="section" cmsId={content._metadata.key} cmsFieldName="MainBody">
|
|
19
|
+
* <p>{content.MainBody}</p>
|
|
20
|
+
* </CmsEditable>
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```tsx
|
|
25
|
+
* <CmsEditable
|
|
26
|
+
* as="h2"
|
|
27
|
+
* cmsId={content._metadata.key}
|
|
28
|
+
* cmsFieldName="Heading"
|
|
29
|
+
* editType="inline"
|
|
30
|
+
* >
|
|
31
|
+
* {content.Heading}
|
|
32
|
+
* </CmsEditable>
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
5
35
|
export type CmsEditableProps<FT extends ElementType> = PropsWithChildren<{
|
|
6
36
|
/**
|
|
7
|
-
*
|
|
8
|
-
*
|
|
37
|
+
* Wrapper element or component used for rendering.
|
|
38
|
+
*
|
|
39
|
+
* Defaults to `div`.
|
|
40
|
+
* Accepts intrinsic elements (for example `"span"`, `"section"`) or custom
|
|
41
|
+
* React components.
|
|
9
42
|
*/
|
|
10
43
|
as?: FT;
|
|
11
44
|
/**
|
|
12
|
-
*
|
|
13
|
-
*
|
|
45
|
+
* Identifier of the rendered CMS content item.
|
|
46
|
+
*
|
|
47
|
+
* When edit attributes are active, this is written to `data-epi-block-id` and/or
|
|
48
|
+
* `data-epi-content-id`.
|
|
49
|
+
*
|
|
50
|
+
* Recommended value: content key from your model metadata.
|
|
14
51
|
*/
|
|
15
52
|
cmsId?: string | null;
|
|
16
53
|
/**
|
|
17
|
-
*
|
|
18
|
-
*
|
|
54
|
+
* Field name to mark as editable (for example `"Heading"`, `"MainBody"`).
|
|
55
|
+
*
|
|
56
|
+
* In edit mode this enables field-level highlighting/editing metadata.
|
|
19
57
|
*/
|
|
20
58
|
cmsFieldName?: string | null;
|
|
21
59
|
/**
|
|
22
|
-
*
|
|
23
|
-
*
|
|
60
|
+
* Optional CMS context override.
|
|
61
|
+
*
|
|
62
|
+
* Use this when you need to provide context explicitly; otherwise context is resolved
|
|
63
|
+
* by the caller/wrapper.
|
|
24
64
|
*/
|
|
25
65
|
ctx?: GenericContext;
|
|
26
66
|
/**
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
|
|
67
|
+
* Forward `ctx` to the custom `as` component.
|
|
68
|
+
*
|
|
69
|
+
* - `true` (default): forward as prop name `ctx`.
|
|
70
|
+
* - `false`: do not forward context.
|
|
71
|
+
* - `"propName"`: forward using custom prop name.
|
|
72
|
+
*
|
|
73
|
+
* Ignored for intrinsic HTML elements.
|
|
74
|
+
*
|
|
75
|
+
* If the component passed through `as` is on the opposite rendering side,
|
|
76
|
+
* set this to `false` to prevent boundary issues:
|
|
77
|
+
* - `CmsEditable` on client + `as` server component -> use `forwardCtx={false}`
|
|
78
|
+
* - `CmsEditable` on server + `as` client component -> use `forwardCtx={false}`
|
|
30
79
|
*/
|
|
31
80
|
forwardCtx?: boolean | GenericContextProps<FT>;
|
|
32
81
|
/**
|
|
33
|
-
*
|
|
34
|
-
*
|
|
82
|
+
* Force adding `data-epi-block-id` when `cmsId` is present.
|
|
83
|
+
*
|
|
84
|
+
* Useful when you need block-level markers even if the default filtering logic would
|
|
85
|
+
* otherwise suppress them.
|
|
35
86
|
*/
|
|
36
87
|
forceBlockId?: boolean;
|
|
37
88
|
/**
|
|
38
|
-
*
|
|
39
|
-
*
|
|
89
|
+
* Reserved compatibility flag.
|
|
90
|
+
*
|
|
91
|
+
* This property is currently accepted for API compatibility but is not used by the
|
|
92
|
+
* current implementation.
|
|
93
|
+
*
|
|
94
|
+
* @deprecated This property is preserved for historical use and should not be used in new code.
|
|
95
|
+
*/
|
|
96
|
+
forceId?: boolean;
|
|
97
|
+
/**
|
|
98
|
+
* Content identity check used to conditionally output field-level edit markers.
|
|
99
|
+
*
|
|
100
|
+
* When provided, field attributes are added only if
|
|
101
|
+
* `currentContent.key === editableContent.key`.
|
|
102
|
+
* This condition affects field-level markers, not `cmsId` output.
|
|
40
103
|
*/
|
|
41
104
|
currentContent?: ContentLink;
|
|
42
105
|
/**
|
|
43
|
-
* Override
|
|
106
|
+
* Override edit rendering mode.
|
|
107
|
+
*
|
|
108
|
+
* - `"floating"`: floating editor UI.
|
|
109
|
+
* - `"inline"`: inline editor UI.
|
|
110
|
+
* - `null`/`undefined`: default behavior via `data-epi-edit`.
|
|
111
|
+
*
|
|
112
|
+
* @deprecated The `editType` property is deprecated and should not be used in new code. Future versions may remove support for this property.
|
|
44
113
|
*/
|
|
45
114
|
editType?: 'floating' | 'inline' | null;
|
|
46
|
-
} & Omit<ElementProps<FT>, 'as' | 'cmsId' | 'cmsFieldName' | 'ctx' | 'forwardCtx'>>;
|
|
115
|
+
} & Omit<ElementProps<FT>, 'as' | 'cmsId' | 'cmsFieldName' | 'ctx' | 'forwardCtx' | 'forceBlockId' | 'forceId' | 'currentContent' | 'editType'>>;
|
|
47
116
|
export type CmsEditableComponent = <CT extends ElementType>(props: CmsEditableProps<CT>) => ReactNode;
|
|
48
117
|
export type CmsEditableBaseComponent = <CT extends ElementType>(props: PropsWithContext<CmsEditableProps<CT>>) => ReactNode;
|
|
49
118
|
/**
|
|
@@ -8,7 +8,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
8
8
|
* @param param0 The HTML element with the simple properties
|
|
9
9
|
* @returns
|
|
10
10
|
*/
|
|
11
|
-
export const CmsEditable = ({ ctx, forwardCtx, as, cmsId, cmsFieldName, children, key, forceBlockId, currentContent, editType, ...props }) => {
|
|
11
|
+
export const CmsEditable = ({ ctx, forwardCtx = false, as, cmsId = null, cmsFieldName = null, children, key, forceBlockId = false, forceId = true, currentContent, editType = null, ...props }) => {
|
|
12
12
|
const { inEditMode, isDebugOrDevelopment, isDebug, editableContent, editableContentIsExperience, } = ctx || {
|
|
13
13
|
inEditMode: false,
|
|
14
14
|
isDebug: true,
|
|
@@ -24,34 +24,44 @@ export const CmsEditable = ({ ctx, forwardCtx, as, cmsId, cmsFieldName, children
|
|
|
24
24
|
}
|
|
25
25
|
const addEditProps = inEditMode
|
|
26
26
|
? currentContent
|
|
27
|
-
? editableContent?.key
|
|
27
|
+
? editableContent?.key === currentContent.key
|
|
28
28
|
: true
|
|
29
29
|
: false;
|
|
30
30
|
// If we're rendering for an experience, we don't need to inject property names, as the
|
|
31
31
|
// experience editor only deals with property ids - injecting property names will cause
|
|
32
32
|
// it to outline incorrect items.
|
|
33
|
-
const dataEpiPropertyName = editableContentIsExperience
|
|
33
|
+
const dataEpiPropertyName = false && editableContentIsExperience
|
|
34
34
|
? undefined
|
|
35
35
|
: (cmsFieldName ?? undefined);
|
|
36
|
+
const showBlockId = forceBlockId || (cmsId && editableContent?.key ?
|
|
37
|
+
editableContent.key !== cmsId :
|
|
38
|
+
true);
|
|
39
|
+
const showContentId = forceBlockId || (cmsId?.length == 32 && (cmsId && editableContent?.key ?
|
|
40
|
+
editableContent.key !== cmsId :
|
|
41
|
+
true));
|
|
36
42
|
const itemProps = addEditProps
|
|
37
43
|
? {
|
|
38
44
|
...props,
|
|
39
45
|
// We assume GUIDs are represented as 32 char long strings, all other values are IDs
|
|
40
|
-
'data-epi-block-id':
|
|
46
|
+
'data-epi-block-id': showBlockId ? cmsId : undefined,
|
|
41
47
|
// We assume GUIDs are represented as 32 char long strings
|
|
42
|
-
'data-epi-content-id':
|
|
48
|
+
'data-epi-content-id': showContentId ? cmsId : undefined,
|
|
43
49
|
// We pass through the property name if provided
|
|
44
|
-
'data-epi-property-name': dataEpiPropertyName,
|
|
50
|
+
'data-epi-property-name': editType ? dataEpiPropertyName : undefined,
|
|
51
|
+
// We pass through the property name if provided
|
|
52
|
+
'data-epi-edit': editType ? undefined : dataEpiPropertyName,
|
|
45
53
|
// Configure the rendition of the property editor
|
|
46
54
|
'data-epi-property-edittype': editType ?? undefined,
|
|
47
55
|
}
|
|
48
56
|
: {
|
|
49
57
|
...props,
|
|
50
58
|
};
|
|
51
|
-
if (
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
59
|
+
if (typeof DefaultElement !== 'string') {
|
|
60
|
+
if (forwardCtx === true)
|
|
61
|
+
itemProps['ctx'] = ctx;
|
|
62
|
+
if (typeof forwardCtx === 'string' && forwardCtx.length > 0)
|
|
63
|
+
itemProps[forwardCtx] = ctx;
|
|
64
|
+
}
|
|
55
65
|
return _jsx(DefaultElement, { ...itemProps, children: children });
|
|
56
66
|
};
|
|
57
67
|
export default CmsEditable;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/cms-editable/index.tsx"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/cms-editable/index.tsx"],"names":[],"mappings":";AAqJA;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,WAAW,GAA6B,CAAyB,EAC5E,GAAG,EACH,UAAU,GAAG,KAAK,EAClB,EAAE,EACF,KAAK,GAAG,IAAI,EACZ,YAAY,GAAG,IAAI,EACnB,QAAQ,EACR,GAAG,EACH,YAAY,GAAG,KAAK,EACpB,OAAO,GAAG,IAAI,EACd,cAAc,EACd,QAAQ,GAAG,IAAI,EACf,GAAG,KAAK,EAC+B,EAAE,EAAE;IAC3C,MAAM,EACJ,UAAU,EACV,oBAAoB,EACpB,OAAO,EACP,eAAe,EACf,2BAA2B,GAC5B,GAAG,GAAG,IAAI;QACT,UAAU,EAAE,KAAK;QACjB,OAAO,EAAE,IAAI;QACb,oBAAoB,EAAE,IAAI;QAC1B,2BAA2B,EAAE,KAAK;KACnC,CAAA;IACD,MAAM,cAAc,GAAG,EAAE,IAAI,KAAK,CAAA;IAElC,IAAI,oBAAoB,IAAI,UAAU,IAAI,CAAC,YAAY,IAAI,CAAC,KAAK,EAAE,CAAC;QAClE,OAAO,CAAC,IAAI,CACV,4FAA4F,CAC7F,CAAA;QACD,IAAI,OAAO,EAAE,CAAC;YACZ,OAAO,CAAC,KAAK,CAAC,oBAAoB,CAAC,CAAA;QACrC,CAAC;IACH,CAAC;IAED,MAAM,YAAY,GAAG,UAAU;QAC7B,CAAC,CAAC,cAAc;YACd,CAAC,CAAC,eAAe,EAAE,GAAG,KAAK,cAAc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K,CAAC,GAAG,GAAG,CAAA;QAC/C,IAAI,OAAO,UAAU,KAAK,QAAQ,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC;YACzD,SAAS,CAAC,UAAU,CAAC,GAAG,GAAG,CAAA;IAC/B,CAAC;IAED,OAAO,KAAC,cAAc,OAAK,SAAS,YAAG,QAAQ,GAAkB,CAAA;AACnE,CAAC,CAAA;AAED,eAAe,WAAW,CAAA"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
1
2
|
import type { RichTextImplProps } from './types.js';
|
|
2
3
|
import type { ElementWithChildrenType } from '../type-utils.js';
|
|
3
4
|
export * from './types.js';
|
|
4
|
-
export declare const RichText: <ET extends ElementWithChildrenType>({ factory, text, className, as: Wrapper, debug, noWrapper, cmsFieldName, cmsId, ctx, children, ...props }: RichTextImplProps<ET>) => import("react/jsx-runtime").JSX.Element;
|
|
5
|
+
export declare const RichText: <ET extends ElementWithChildrenType>({ factory, text, className, as: Wrapper, debug, noWrapper, cmsFieldName, cmsId, ctx, children, ...props }: RichTextImplProps<ET>) => string | number | bigint | boolean | import("react/jsx-runtime").JSX.Element | Iterable<ReactNode> | Promise<string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined> | null | undefined;
|
|
@@ -14,10 +14,13 @@ export const RichText = ({ factory, text = '{ "type": "richText" }', className =
|
|
|
14
14
|
const elementId = id + '::' + idx;
|
|
15
15
|
return (_jsx(RichTextElement, { factory: richTextFactory, node: child, idPrefix: elementId + '::', ctx: ctx }, elementId));
|
|
16
16
|
}) || children;
|
|
17
|
+
if (noWrapper || !Wrapper) {
|
|
18
|
+
if (isDebug)
|
|
19
|
+
console.warn('🟠 [Rich Text] Text without wrapper, make sure you add your own `CmsEditable` as one of the parents of this component');
|
|
20
|
+
return textContent;
|
|
21
|
+
}
|
|
17
22
|
if (cmsId || cmsFieldName)
|
|
18
|
-
return (_jsx(CmsEditable, { as:
|
|
19
|
-
if (noWrapper || !Wrapper)
|
|
20
|
-
return _jsx(_Fragment, { children: textContent });
|
|
23
|
+
return (_jsx(CmsEditable, { as: Wrapper, className: className, cmsId: cmsId || undefined, cmsFieldName: cmsFieldName || undefined, ctx: ctx, ...props, children: textContent }));
|
|
21
24
|
return (
|
|
22
25
|
//@ts-expect-error
|
|
23
26
|
_jsx(Wrapper, { className: className, ...props, children: textContent }));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/rich-text/index.tsx"],"names":[],"mappings":";AAEA,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AACnC,OAAO,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAA;AAClE,OAAO,EACL,iBAAiB,EACjB,eAAe,EACf,mBAAmB,GACpB,MAAM,iBAAiB,CAAA;AAExB,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AAGtD,cAAc,YAAY,CAAA;AAE1B,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAqC,EAC3D,OAAO,EACP,IAAI,GAAG,wBAAwB,EAC/B,SAAS,GAAG,WAAW,EACvB,EAAE,EAAE,OAAO,GAAG,KAAW,EACzB,KAAK,GAAG,KAAK,EACb,SAAS,GAAG,KAAK,EACjB,YAAY,GAAG,IAAI,EACnB,KAAK,GAAG,IAAI,EACZ,GAAG,EACH,QAAQ,EACR,GAAG,KAAK,EACc,EAAE,EAAE;IAC1B,MAAM,EAAE,GAAG,KAAK,CAAC,WAAW,CAAC,WAAW,CAAC,CAAA;IACzC,MAAM,eAAe,GACnB,GAAG,CAAC,OAAO,IAAI,OAAO,IAAI,IAAI,uBAAuB,CAAC,iBAAiB,CAAC,CAAA;IAC1E,MAAM,OAAO,GAAG,GAAG,CAAC,OAAO,IAAI,KAAK,CAAA;IAEpC,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,KAAK,CAAC,gBAAgB,CAAC,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G,IAJH,SAAS,CAKd,CACH,CAAA;QACH,CAAC,CAAC;QACJ,CAAC,CAAC,SAAS,CAAA;IAEf,4DAA4D;IAC5D,IAAI,SAAS,GAAG,OAAO,EAAE,OAAO,CAAC,YAAY,IAAI,CAAC,IAAI,EAAE,CAAC,CAAA;IACzD,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,IAAI,OAAO;YACT,OAAO,CAAC,IAAI,CACV,sFAAsF,IAAI,CAAC,IAAI,eAAe,IAAI,CAAC,IAAI,EAAE,CAC1H,CAAA;QACH,SAAS,GAAG,mBAAmB,CAAC,IAAI,CAAC,IAAmC,CAAC,CAAA;QACzE,OAAO,EAAE,QAAQ,CAAC,YAAY,IAAI,CAAC,IAAI,EAAE,EAAE,SAAS,CAAC,CAAA;IACvD,CAAC;IAED,mBAAmB;IACnB,OAAO,CACL,KAAC,SAAS,IAAC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,YAC5B,SAAS,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,GAChD,CACb,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -4,18 +4,167 @@ import { type CmsContentComponent } from './cms-content/rsc.js';
|
|
|
4
4
|
import { type OptimizelyCompositionComponent } from './visual-builder/index.js';
|
|
5
5
|
import { type RichTextComponent } from './rich-text/index.js';
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* Optimizely CMS editable marker wrapper for React Server Components.
|
|
8
|
+
*
|
|
9
|
+
* `CmsEditable` renders an element (default `div`) and conditionally injects
|
|
10
|
+
* Optimizely edit-mode attributes (`data-epi-*`) based on the current CMS
|
|
11
|
+
* context. In non-edit mode it behaves like a transparent wrapper.
|
|
12
|
+
*
|
|
13
|
+
* Key behavior:
|
|
14
|
+
* - Uses `ctx` from props when provided, otherwise resolves server context.
|
|
15
|
+
* - Injects edit attributes only when rendering in edit mode.
|
|
16
|
+
* - Supports custom wrapper elements/components via `as`.
|
|
17
|
+
* - Can forward `ctx` to custom components via `forwardCtx`.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```tsx
|
|
21
|
+
* import { CmsEditable } from '@remkoj/optimizely-cms-react/rsc'
|
|
22
|
+
*
|
|
23
|
+
* export function PageTitle({ title, id }: { title: string, id: string }) {
|
|
24
|
+
* return (
|
|
25
|
+
* <CmsEditable as="h1" cmsId={id} cmsFieldName="Title">
|
|
26
|
+
* {title}
|
|
27
|
+
* </CmsEditable>
|
|
28
|
+
* )
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```tsx
|
|
34
|
+
* import { CmsEditable } from '@remkoj/optimizely-cms-react/rsc'
|
|
35
|
+
*
|
|
36
|
+
* function Heading(props: { children: React.ReactNode, cmsCtx?: unknown }) {
|
|
37
|
+
* return <h2>{props.children}</h2>
|
|
38
|
+
* }
|
|
39
|
+
*
|
|
40
|
+
* export function Teaser({ id, title }: { id: string, title: string }) {
|
|
41
|
+
* return (
|
|
42
|
+
* <CmsEditable
|
|
43
|
+
* as={Heading}
|
|
44
|
+
* cmsId={id}
|
|
45
|
+
* cmsFieldName="Heading"
|
|
46
|
+
* forwardCtx="cmsCtx"
|
|
47
|
+
* >
|
|
48
|
+
* {title}
|
|
49
|
+
* </CmsEditable>
|
|
50
|
+
* )
|
|
51
|
+
* }
|
|
52
|
+
* ```
|
|
53
|
+
*
|
|
54
|
+
* @remarks
|
|
55
|
+
* For a full prop reference, see `CmsEditableProps`.
|
|
8
56
|
*/
|
|
9
57
|
export declare const CmsEditable: CmsEditableComponent;
|
|
58
|
+
export type { CmsEditableComponent, CmsEditableProps } from './cms-editable/index.js';
|
|
10
59
|
/**
|
|
11
|
-
*
|
|
12
|
-
*
|
|
60
|
+
* Optimizely CMS content renderer for React Server Components.
|
|
61
|
+
*
|
|
62
|
+
* `CmsContent` resolves the component template for a content item and provides
|
|
63
|
+
* that template with loaded data and edit metadata.
|
|
64
|
+
*
|
|
65
|
+
* Key behavior:
|
|
66
|
+
* - Resolves content type from `contentType`, `fragmentData`, or Graph lookup.
|
|
67
|
+
* - Resolves template using context component dictionary and optional
|
|
68
|
+
* `contentTypePrefix` / `variant`.
|
|
69
|
+
* - Loads content data unless `noDataLoad` is set.
|
|
70
|
+
* - Passes `editProps` to resolved CMS templates for in-context editing.
|
|
71
|
+
*
|
|
72
|
+
* Required props:
|
|
73
|
+
* - `contentLink`
|
|
74
|
+
*
|
|
75
|
+
* Optional props:
|
|
76
|
+
* - `contentType`, `contentTypePrefix`, `variant`, `fragmentData`, `layoutProps`,
|
|
77
|
+
* `noDataLoad`, `editorComponentId`, `ctx`
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```tsx
|
|
81
|
+
* import { CmsContent } from '@remkoj/optimizely-cms-react/rsc'
|
|
82
|
+
*
|
|
83
|
+
* export default async function Slot({ contentLink }: { contentLink: { key: string, locale?: string } }) {
|
|
84
|
+
* return (
|
|
85
|
+
* <CmsContent
|
|
86
|
+
* contentLink={contentLink}
|
|
87
|
+
* contentTypePrefix="Page"
|
|
88
|
+
* variant="default"
|
|
89
|
+
* />
|
|
90
|
+
* )
|
|
91
|
+
* }
|
|
92
|
+
* ```
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```tsx
|
|
96
|
+
* import { CmsContent } from '@remkoj/optimizely-cms-react/rsc'
|
|
97
|
+
*
|
|
98
|
+
* export function PreloadedBlock({ contentLink, fragmentData }: { contentLink: { key: string }, fragmentData: Record<string, any> }) {
|
|
99
|
+
* return (
|
|
100
|
+
* <CmsContent
|
|
101
|
+
* contentLink={contentLink}
|
|
102
|
+
* fragmentData={fragmentData}
|
|
103
|
+
* contentType={["Component", "TeaserBlock"]}
|
|
104
|
+
* />
|
|
105
|
+
* )
|
|
106
|
+
* }
|
|
107
|
+
* ```
|
|
108
|
+
*
|
|
109
|
+
* @remarks
|
|
110
|
+
* For a full prop reference, see `CmsContentProps`.
|
|
13
111
|
*/
|
|
14
112
|
export declare const CmsContent: CmsContentComponent;
|
|
15
113
|
export type { CmsContentComponent, CmsContentProps } from './cms-content/rsc.js';
|
|
16
114
|
/**
|
|
17
|
-
*
|
|
18
|
-
*
|
|
115
|
+
* Optimizely CMS Content Area renderer for React Server Components.
|
|
116
|
+
*
|
|
117
|
+
* `CmsContentArea` renders a list of content area items by delegating each item
|
|
118
|
+
* to `CmsContent`, with optional container and item-wrapper customization.
|
|
119
|
+
*
|
|
120
|
+
* Key behavior:
|
|
121
|
+
* - Renders each item as `CmsContent` with normalized content link and type.
|
|
122
|
+
* - Adds edit markers for the content area in edit mode when `fieldName` is set.
|
|
123
|
+
* - Supports optional wrappers (`as`, `itemWrapper`) or no wrappers.
|
|
124
|
+
* - Supports per-item suspense boundaries (`useSuspense`, `fallback`).
|
|
125
|
+
*
|
|
126
|
+
* Required props:
|
|
127
|
+
* - `items`
|
|
128
|
+
*
|
|
129
|
+
* Optional props:
|
|
130
|
+
* - `fieldName`, `variant`, `as`, `itemsProperty`, `className`, `classMapper`,
|
|
131
|
+
* `itemWrapper`, `noWrapper`, `useSuspense`, `fallback`, `ctx`
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* ```tsx
|
|
135
|
+
* import { CmsContentArea } from '@remkoj/optimizely-cms-react/rsc'
|
|
136
|
+
*
|
|
137
|
+
* export function MainArea({ items }: { items: any[] }) {
|
|
138
|
+
* return (
|
|
139
|
+
* <CmsContentArea
|
|
140
|
+
* items={items}
|
|
141
|
+
* fieldName="MainContentArea"
|
|
142
|
+
* as="section"
|
|
143
|
+
* className="main-content-area"
|
|
144
|
+
* />
|
|
145
|
+
* )
|
|
146
|
+
* }
|
|
147
|
+
* ```
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* ```tsx
|
|
151
|
+
* import { CmsContentArea } from '@remkoj/optimizely-cms-react/rsc'
|
|
152
|
+
*
|
|
153
|
+
* export function GridArea({ items }: { items: any[] }) {
|
|
154
|
+
* return (
|
|
155
|
+
* <CmsContentArea
|
|
156
|
+
* items={items}
|
|
157
|
+
* itemWrapper={{ as: 'article', className: 'grid-item' }}
|
|
158
|
+
* classMapper={(displayOption) => `display-${displayOption}`}
|
|
159
|
+
* useSuspense
|
|
160
|
+
* fallback={<div>Loading component…</div>}
|
|
161
|
+
* />
|
|
162
|
+
* )
|
|
163
|
+
* }
|
|
164
|
+
* ```
|
|
165
|
+
*
|
|
166
|
+
* @remarks
|
|
167
|
+
* For a full prop reference, see `CmsContentAreaProps`.
|
|
19
168
|
*/
|
|
20
169
|
export declare const CmsContentArea: CmsContentAreaComponent;
|
|
21
170
|
export type { CmsContentAreaClassMapper, CmsContentAreaComponent, CmsContentAreaProps, ContentAreaItemDefinition, } from './cms-content-area/index.js';
|