@remkoj/optimizely-cms-react 6.0.0-pre9 → 6.0.0-rc.3
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/AGENTS.md +168 -0
- package/README.md +3 -4
- package/dist/components/client.js.map +1 -1
- package/dist/components/cms-content/get-content-type.js +1 -1
- package/dist/components/cms-content/get-content-type.js.map +1 -1
- package/dist/components/cms-content/get-content.js +1 -1
- package/dist/components/cms-content/get-content.js.map +1 -1
- package/dist/components/cms-content/resolve-component.js +3 -9
- package/dist/components/cms-content/resolve-component.js.map +1 -1
- package/dist/components/cms-content/resolve-content-type.js.map +1 -1
- package/dist/components/cms-content/types.d.ts +38 -2
- package/dist/components/cms-content-area/types.d.ts +51 -10
- package/dist/components/cms-editable/index.d.ts +82 -19
- package/dist/components/cms-editable/index.js +10 -6
- package/dist/components/cms-editable/index.js.map +1 -1
- package/dist/components/cms-styles/index.js.map +1 -1
- package/dist/components/rich-text/components.d.ts +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/rich-text/utils.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/visual-builder/functions.js +7 -14
- 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 +15 -16
- package/dist/components/visual-builder/index.js.map +1 -1
- package/dist/context/client.d.ts +12 -12
- package/dist/context/client.js +8 -0
- package/dist/context/client.js.map +1 -1
- package/dist/context/rsc.js +6 -1
- package/dist/context/rsc.js.map +1 -1
- package/dist/data/queries.js.map +1 -1
- package/dist/errors.js +1 -0
- package/dist/errors.js.map +1 -1
- package/dist/factory/default.d.ts +20 -3
- package/dist/factory/default.js +45 -25
- package/dist/factory/default.js.map +1 -1
- package/dist/factory/index.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-utilities.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/utilities.d.ts +2 -2
- package/dist/utilities.js +12 -7
- package/dist/utilities.js.map +1 -1
- package/package.json +22 -15
package/AGENTS.md
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
# @remkoj/optimizely-cms-react — usage
|
|
2
|
+
|
|
3
|
+
React and React Server Component (RSC) integration library for Optimizely CMS.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @remkoj/optimizely-cms-react
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Subpath exports
|
|
12
|
+
|
|
13
|
+
| Import path | Contents |
|
|
14
|
+
| --- | --- |
|
|
15
|
+
| `@remkoj/optimizely-cms-react` | Client components, factory, core types |
|
|
16
|
+
| `@remkoj/optimizely-cms-react/rsc` | Server Components: `CmsContent`, `CmsContentArea`, `CmsEditable`, `ServerContext`, `OptimizelyComposition`, node helpers |
|
|
17
|
+
| `@remkoj/optimizely-cms-react/utils` | Shared utilities |
|
|
18
|
+
|
|
19
|
+
## Key types
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
import type { CmsComponent, CmsComponentProps, ContentType, ComponentTypeDictionary } from '@remkoj/optimizely-cms-react'
|
|
23
|
+
|
|
24
|
+
// A CMS-aware React component
|
|
25
|
+
type CmsComponent<TData, TLayoutProps = Record<string, any>> =
|
|
26
|
+
React.ComponentType<CmsComponentProps<TData, TLayoutProps>>
|
|
27
|
+
|
|
28
|
+
// Props injected into every CMS component
|
|
29
|
+
type CmsComponentProps<TData, TLayoutProps> = {
|
|
30
|
+
contentLink: ContentLinkWithLocale
|
|
31
|
+
data: TData
|
|
32
|
+
inEditMode?: boolean // true when rendering inside On-Page Editor
|
|
33
|
+
layoutProps?: TLayoutProps
|
|
34
|
+
editProps?: ComponentCmsEditableProps
|
|
35
|
+
ctx?: GenericContext
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// For Section/layout components that receive child nodes from Visual Builder
|
|
39
|
+
// children is also available on CmsComponentProps
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Component factory
|
|
43
|
+
|
|
44
|
+
```typescript
|
|
45
|
+
import { DefaultComponentFactory, RichTextComponentDictionary } from '@remkoj/optimizely-cms-react/rsc'
|
|
46
|
+
import type { ComponentTypeDictionary } from '@remkoj/optimizely-cms-react'
|
|
47
|
+
|
|
48
|
+
// Build a flat dictionary to pass to registerAll
|
|
49
|
+
export const myComponents: ComponentTypeDictionary = [
|
|
50
|
+
{ type: 'HeroBlock', component: HeroBlockComponent },
|
|
51
|
+
// ...
|
|
52
|
+
]
|
|
53
|
+
|
|
54
|
+
// Create and populate the factory (server-only — wrap in 'server-only' import)
|
|
55
|
+
const factory = new DefaultComponentFactory()
|
|
56
|
+
factory.registerAll(RichTextComponentDictionary) // register built-in rich text nodes
|
|
57
|
+
factory.registerAll(myComponents)
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## RSC components (import from `./rsc`)
|
|
61
|
+
|
|
62
|
+
```typescript
|
|
63
|
+
import {
|
|
64
|
+
CmsContent,
|
|
65
|
+
CmsContentArea,
|
|
66
|
+
CmsEditable,
|
|
67
|
+
RichText,
|
|
68
|
+
ServerContext,
|
|
69
|
+
OptimizelyComposition,
|
|
70
|
+
isNode,
|
|
71
|
+
isComponentNode,
|
|
72
|
+
isStructureNode,
|
|
73
|
+
} from '@remkoj/optimizely-cms-react/rsc'
|
|
74
|
+
|
|
75
|
+
// Render a single content item by content link
|
|
76
|
+
<CmsContent contentLink={{ key: content._metadata.key, locale: 'en' }} ctx={ctx} />
|
|
77
|
+
|
|
78
|
+
// Render a content area (list of content items)
|
|
79
|
+
<CmsContentArea fieldName="MainContentArea" items={content.MainContentArea} ctx={ctx} />
|
|
80
|
+
|
|
81
|
+
// Wrap editable regions in OPE — cmsId marks the content item, cmsFieldName marks individual fields
|
|
82
|
+
<CmsEditable as="section" cmsId={contentLink.key} ctx={ctx}>...</CmsEditable>
|
|
83
|
+
<CmsEditable as="h1" cmsFieldName="Heading" ctx={ctx}>{heading}</CmsEditable>
|
|
84
|
+
|
|
85
|
+
// Render Visual Builder experience compositions
|
|
86
|
+
const composition = getFragmentData(ExperienceDataFragmentDoc, data).composition
|
|
87
|
+
if (composition && isNode(composition))
|
|
88
|
+
return <OptimizelyComposition node={composition} ctx={ctx} />
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## ServerContext
|
|
92
|
+
|
|
93
|
+
Create once per request (e.g. in the root layout) and pass as `ctx` to all CMS components.
|
|
94
|
+
|
|
95
|
+
```typescript
|
|
96
|
+
import 'server-only'
|
|
97
|
+
import { ServerContext } from '@remkoj/optimizely-cms-react/rsc'
|
|
98
|
+
import { createClient } from '@remkoj/optimizely-graph-client'
|
|
99
|
+
|
|
100
|
+
const client = createClient(undefined, undefined, { nextJsFetchDirectives: true, cache: true, queryCache: true })
|
|
101
|
+
const ctx = new ServerContext({ locale: 'en', factory, client })
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
`ServerContext` exposes `client`, `factory`, `locale`, `inEditMode`, `inPreviewMode`, `isDevelopment`, `isDebug`.
|
|
105
|
+
|
|
106
|
+
## Component patterns
|
|
107
|
+
|
|
108
|
+
### Block / Component
|
|
109
|
+
|
|
110
|
+
```typescript
|
|
111
|
+
import { type CmsComponent } from '@remkoj/optimizely-cms-react'
|
|
112
|
+
import { CmsEditable } from '@remkoj/optimizely-cms-react/rsc'
|
|
113
|
+
import { MyBlockDataFragmentDoc, type MyBlockDataFragment } from '@/gql/graphql'
|
|
114
|
+
|
|
115
|
+
export const MyBlock: CmsComponent<MyBlockDataFragment> = ({ data, contentLink, inEditMode, ctx }) => {
|
|
116
|
+
return <CmsEditable as="section" cmsId={contentLink.key} ctx={ctx}>...</CmsEditable>
|
|
117
|
+
}
|
|
118
|
+
MyBlock.displayName = 'My Block (Component/MyBlock)'
|
|
119
|
+
MyBlock.getDataFragment = () => ['MyBlockData', MyBlockDataFragmentDoc]
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### Page
|
|
123
|
+
|
|
124
|
+
```typescript
|
|
125
|
+
import { type OptimizelyNextPage } from '@remkoj/optimizely-cms-nextjs'
|
|
126
|
+
import { MyPageDataFragmentDoc, type MyPageDataFragment } from '@/gql/graphql'
|
|
127
|
+
|
|
128
|
+
export const MyPage: OptimizelyNextPage<MyPageDataFragment> = ({ data, ctx }) => { ... }
|
|
129
|
+
MyPage.getDataFragment = () => ['MyPageData', MyPageDataFragmentDoc]
|
|
130
|
+
MyPage.getMetaData = async (contentLink, locale, client) => ({ title: '...' })
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### Section (Visual Builder layout node)
|
|
134
|
+
|
|
135
|
+
Section components receive `children` (rendered child nodes) and `layoutProps` (display template data).
|
|
136
|
+
|
|
137
|
+
```typescript
|
|
138
|
+
import { type CmsComponent } from '@remkoj/optimizely-cms-react'
|
|
139
|
+
import { CmsEditable } from '@remkoj/optimizely-cms-react/rsc'
|
|
140
|
+
|
|
141
|
+
export const MySection: CmsComponent<MySectionDataFragment, MyLayoutProps> = ({ contentLink, layoutProps, children, ctx }) => {
|
|
142
|
+
return <CmsEditable as="div" cmsId={contentLink.key} ctx={ctx}>{children}</CmsEditable>
|
|
143
|
+
}
|
|
144
|
+
MySection.getDataFragment = () => ['MySectionData', MySectionDataFragmentDoc]
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### Experience
|
|
148
|
+
|
|
149
|
+
```typescript
|
|
150
|
+
if (ctx) ctx.editableContentIsExperience = true
|
|
151
|
+
const composition = getFragmentData(ExperienceDataFragmentDoc, data).composition
|
|
152
|
+
return <div>{composition && isNode(composition) && <OptimizelyComposition node={composition} ctx={ctx} />}</div>
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## Utilities (import from `./utils`)
|
|
156
|
+
|
|
157
|
+
```typescript
|
|
158
|
+
import { Utils } from '@remkoj/optimizely-cms-react'
|
|
159
|
+
// or
|
|
160
|
+
import { isNonEmptyString, slugify } from '@remkoj/optimizely-cms-react/utils'
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
## Constraints
|
|
164
|
+
|
|
165
|
+
- RSC components (`./rsc`) are server-only; do not import in client components.
|
|
166
|
+
- Always pass `ctx` down from layout to leaf components; components warn at runtime when `ctx` is missing.
|
|
167
|
+
- `ContentLink` and `ContentLinkWithLocale` are re-exported from `@remkoj/optimizely-graph-client` (direct import preferred).
|
|
168
|
+
- `RichTextComponentDictionary` must be registered on the factory before passing it to `ServerContext`.
|
package/README.md
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
# Optimizely SaaS CMS React Components
|
|
2
|
+
|
|
2
3
|
> [!WARNING]
|
|
3
|
-
>
|
|
4
|
-
>
|
|
5
|
-
> For some of the commonly used old exports it still contains placeholders, however those are deprecated and will be removed in a future version
|
|
4
|
+
> There'll be an update of Optimizely SaaS CMS that is incompatible with all SDK versions prior to 5.1.6. If you don't upgrade, you will see empty pages (main website) and "Component not found" messages (preview).
|
|
6
5
|
|
|
7
6
|
This package provides two main entry points, depending on your build environment:
|
|
8
7
|
- `@remkoj/optimizely-cms-react` This export contains the library, whith React components that use a client side context
|
|
@@ -46,4 +45,4 @@ An entry within the factory consists of the following fields:
|
|
|
46
45
|
- ***type:*** The identifier of the content type, can either be an array of strings or a string. The implementation *should* normalize the type. The `DefaultComponentFactory` normalized to a string, using `/` as item separator.
|
|
47
46
|
- ***component:*** The component to do the actual rendering of the data. *The factory is indifferent to the actual type, so this could be the output of `next/dynamic` to trigger bundle splitting in Next.js.*
|
|
48
47
|
- ***useSuspense:*** When set to `true` the component will be wrapped in the `<Suspense></Suspense>` from React. Optional, the default value is `false`.
|
|
49
|
-
- ***loader:*** The component to show while Suspense is awaiting the actual component. This component is given to the `fallback` property of `<Suspense>`. Optional, the default value is `undefined`.
|
|
48
|
+
- ***loader:*** The component to show while Suspense is awaiting the actual component. This component is given to the `fallback` property of `<Suspense>`. Optional, the default value is `undefined`.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/components/client.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAGZ,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AAEvD,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,EAA4B,MAAM,yBAAyB,CAAA,CAAC,wCAAwC;AACzI,OAAO,EAAE,qBAAqB,IAAI,yBAAyB,EAAuC,MAAM,2BAA2B,CAAA,CAAC,4BAA4B;AAChK,OAAO,EAAE,QAAQ,IAAI,YAAY,EAA0B,MAAM,sBAAsB,CAAA;AAIvF,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,eAAe,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AAC9H,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAEpE;;GAEG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,kBAAkB,CAAC,YAAY,CAAsB,CAAA;AAE7E,OAAO,EAAE,iBAAiB,IAAI,2BAA2B,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAA;AACjH,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,EAAE,WAAW,EAAG,MAAM,s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Q,EAAE,EAAE;QACzC,MAAM,GAAG,GAAG,gBAAgB,EAAE,CAAA;QAC9B,OAAO,KAAC,aAAa,IAAC,GAAG,EAAE,GAAG,KAAO,KAAK,GAAK,CAAA;IACjD,CAAC,CAAA;IACD,OAAO,qBAAqB,CAAA;AAC9B,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,kBAAkB,CAAC,YAAY,CAAyB,CAAA;AAGnF;;;GAGG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,kBAAkB,CAAC,cAAc,CAAwB,CAAA;AAGnF;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,eAAe,CAAC,kBAAkB,CAAC,eAAe,CAAC,EAAE,UAAU,CAA4B,CAAA;AAGzH;;;;GAIG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,eAAe,CAAC,kBAAkB,CAAC,yBAAyB,CAAC,EAAE,UAAU,CAAmC,CAAA"}
|
|
@@ -34,7 +34,7 @@ export async function getContentType(link, gqlClient) {
|
|
|
34
34
|
console.error(`🔴 [CmsContent][getContentType] Expected exactly one type, received ${gqlResponse.Content?.total ?? 0} types for`, gqlQueryVars);
|
|
35
35
|
return undefined;
|
|
36
36
|
}
|
|
37
|
-
const contentType = normalizeContentType(gqlResponse.Content?.item?.
|
|
37
|
+
const contentType = normalizeContentType(gqlResponse.Content?.item?.metadata?.types);
|
|
38
38
|
if (!contentType) {
|
|
39
39
|
console.error(`🔴 [CmsContent][getContentType] The item did not contain type information! (${contentLinkToString(link)})`);
|
|
40
40
|
throw new Error("The item did not contain type information");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-content-type.js","sourceRoot":"","sources":["../../../src/components/cms-content/get-content-type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,mBAAmB,EAAmE,MAAM,iCAAiC,CAAA;AAE1K,OAAO,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAA;AACr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J,OAAO,SAAS,CAAA;IAClB,CAAC;IAED,MAAM,WAAW,GAAG,oBAAoB,CAAC,WAAW,CAAC,OAAO,EAAE,IAAI,EAAE,
|
|
1
|
+
{"version":3,"file":"get-content-type.js","sourceRoot":"","sources":["../../../src/components/cms-content/get-content-type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,mBAAmB,EAAmE,MAAM,iCAAiC,CAAA;AAE1K,OAAO,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAA;AACrC,OAAO,EAAE,6BAA6B,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAA;AAIxF,MAAM,UAAU,kBAAkB,CAAI,KAAQ;IAC5C,MAAM,EAAE,GAAmB;QACzB,IAAI,EAAE,CAAe,WAAiF,EAAE,EAAE;YACxG,IAAI,CAAC,WAAW;gBACd,OAAO,KAAyC,CAAA;YAClD,OAAO,WAAW,CAAC,KAAK,CAA0B,CAAA;QACpD,CAAC;KACF,CAAA;IACD,OAAO,EAAE,CAAA;AACX,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,IAAqC,EAAE,SAA2B;IACrG,IAAI,mBAAmB,CAAC,IAAI,CAAC,EAAE,CAAC;QAC9B,OAAO,CAAC,KAAK,CAAC,4GAA4G,mBAAmB,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;QACtJ,MAAM,IAAI,KAAK,CAAC,4EAA4E,mBAAmB,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;IAC1H,CAAC;IAED,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE,CAAC;QACzB,OAAO,CAAC,KAAK,CAAC,kFAAkF,mBAAmB,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;QAC5H,MAAM,IAAI,KAAK,CAAC,kDAAkD,mBAAmB,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;IAChG,CAAC;IAED,MAAM,YAAY,GAAG,6BAA6B,CAAC,IAAI,EAAE,SAAS,CAAC,CAAA;IACnE,MAAM,WAAW,GAAG,MAAM,SAAS,CAAC,OAAO,CAAyB,mBAAmB,EAAE,YAAY,CAAC,CAAA;IACtG,IAAI,WAAW,CAAC,OAAO,EAAE,KAAK,IAAI,CAAC,EAAE,CAAC;QACpC,IAAI,SAAS,CAAC,KAAK;YACjB,OAAO,CAAC,KAAK,CAAC,uEAAuE,WAAW,CAAC,OAAO,EAAE,KAAK,IAAI,CAAC,YAAY,EAAE,YAAY,CAAC,CAAA;QACjJ,OAAO,SAAS,CAAA;IAClB,CAAC;IAED,MAAM,WAAW,GAAG,oBAAoB,CAAC,WAAW,CAAC,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAA;IACpF,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,OAAO,CAAC,KAAK,CAAC,+EAA+E,mBAAmB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;QAC1H,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAA;IAC9D,CAAC;IAED,OAAO,WAAW,CAAA;AACpB,CAAC;AAED,eAAe,cAAc,CAAA;AAa7B,MAAM,mBAAmB,GAAG,GAAG,CAAA;;;;;;;;;;;;;;;EAe7B,CAAA"}
|
|
@@ -17,7 +17,7 @@ export function getContent(client, contentLink, Component, fragmentData, noDataL
|
|
|
17
17
|
}
|
|
18
18
|
else if (client?.isPreviewEnabled() && isContentLink(contentLink) && !isInlineContentLink(contentLink)) {
|
|
19
19
|
if (debug)
|
|
20
|
-
console.warn(
|
|
20
|
+
console.warn(`🔴 [CmsContent][getContent] Rendering shared instance (${JSON.stringify(contentLink)}), while in preview mode, falling back to loading for ${componentLabel}`);
|
|
21
21
|
contentLink.version = null;
|
|
22
22
|
// Default mode, use fragment
|
|
23
23
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-content.js","sourceRoot":"","sources":["../../../src/components/cms-content/get-content.ts"],"names":[],"mappings":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2B;IAC3B,IAAI,MAAM,CAAC,oBAAoB,IAAI,aAAa,CAAC,KAAK,EAAE,CAAC;QACvD,gBAAgB,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,MAAM,GAAG,gBAAgB,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,MAAM,IAAI,gBAAgB,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,IAAI,CAAA;QACtK,IAAI,gBAAgB,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO;YAC/C,OAAO,gBAAgB,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAA;IACxD,CAAC;IAED,kBAAkB;IAClB,OAAO,gBAAgB,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;AAC9C,CAAC;AAED,MAAM,eAAe,GAAG,CAAC,IAAY,EAAE,QAA0B,EAAE,EAAE,CAAC,8UAA8U,IAAI,SAAS,OAAO,CAAC,QAAQ,CAAC,IAAI,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAA;AAC7d,MAAM,eAAe,GAAG,CAAC,IAAY,EAAE,QAA0B,EAAE,EAAE,CAAC;;;;;;;;;;;;;;;;;;WAkB3D,IAAI;;;;EAIb,OAAO,CAAC,QAAQ,CAAC,IAAI,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAA"}
|
|
@@ -24,22 +24,16 @@ export function resolveComponent(contentType, prefix, variant, ctx) {
|
|
|
24
24
|
console.error(`🔴 [CmsContent][resolveComponent] No content type factory registered in the context`);
|
|
25
25
|
throw new Error('Empty factory on the context');
|
|
26
26
|
}
|
|
27
|
-
//
|
|
28
|
-
const myContentType =
|
|
29
|
-
? Utils.normalizeAndPrefixContentType(Array.isArray(contentType) ? [...contentType].reverse() : contentType, prefix)
|
|
30
|
-
: Utils.normalizeContentType(Array.isArray(contentType) ? [...contentType].reverse() : contentType, true);
|
|
27
|
+
// Make sure that we normalize the input from graph into a string array
|
|
28
|
+
const myContentType = Utils.normalizeContentType(contentType, false);
|
|
31
29
|
// Validate that we have a value to ask the factory a component for
|
|
32
30
|
if (!myContentType || myContentType.length == 0) {
|
|
33
31
|
if (isDebug)
|
|
34
32
|
console.error(`🔴 [CmsContent][resolveComponent] The content type ${JSON.stringify(contentType)}, with prefix ${JSON.stringify(prefix)} yielded an empty normalized type`);
|
|
35
33
|
throw new Error(`The content type ${JSON.stringify(contentType)}, with prefix ${JSON.stringify(prefix)} yielded an empty normalized type`);
|
|
36
34
|
}
|
|
37
|
-
/*if (isDebug)
|
|
38
|
-
console.log(
|
|
39
|
-
`⚪ [CmsContent][resolveComponent] Normalized content type ${JSON.stringify(contentType)} to ${myContentType}`
|
|
40
|
-
)*/
|
|
41
35
|
// Resolve component
|
|
42
|
-
const Component = Utils.resolveComponentType(factory, myContentType,
|
|
36
|
+
const Component = Utils.resolveComponentType(factory, myContentType, [variant, prefix].filter(Utils.isNotNullOrUndefined));
|
|
43
37
|
// Handle component not found in factory
|
|
44
38
|
if (!Component) {
|
|
45
39
|
const contentTypeDisplay = Array.isArray(myContentType)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve-component.js","sourceRoot":"","sources":["../../../src/components/cms-content/resolve-component.tsx"],"names":[],"mappings":";AAEA,OAAO,KAAK,KAAK,MAAM,oBAAoB,CAAA;AAS3C,MAAM,UAAU,iBAAiB,CAAC,iBAAwC;IACxE,IAAI,CAAC,iBAAiB;QAAE,OAAO,KAAK,CAAA;IACpC,IAAI,iBAAiB,CAAC,WAAW;QAAE,OAAO,iBAAiB,CAAC,WAAW,CAAA;IACvE,IAAI,OAAO,iBAAiB,IAAI,UAAU,IAAI,iBAAiB,CAAC,IAAI;QAClE,OAAO,iBAAiB,CAAC,IAAI,CAAA;IAC/B,OAAO,iBAAiB,CAAC,QAAQ,EAAE,CAAA;AACrC,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,gBAAgB,CAC9B,WAAmD,EACnD,MAAiC,EACjC,OAAkC,EAClC,GAAmB;IAEnB,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,GAAG,GAAG,CAAA;IAE5C,sFAAsF;IACtF,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,CAAC,KAAK,CACX,qFAAqF,CACtF,CAAA;QACD,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAA;IACjD,CAAC;IAED,
|
|
1
|
+
{"version":3,"file":"resolve-component.js","sourceRoot":"","sources":["../../../src/components/cms-content/resolve-component.tsx"],"names":[],"mappings":";AAEA,OAAO,KAAK,KAAK,MAAM,oBAAoB,CAAA;AAS3C,MAAM,UAAU,iBAAiB,CAAC,iBAAwC;IACxE,IAAI,CAAC,iBAAiB;QAAE,OAAO,KAAK,CAAA;IACpC,IAAI,iBAAiB,CAAC,WAAW;QAAE,OAAO,iBAAiB,CAAC,WAAW,CAAA;IACvE,IAAI,OAAO,iBAAiB,IAAI,UAAU,IAAI,iBAAiB,CAAC,IAAI;QAClE,OAAO,iBAAiB,CAAC,IAAI,CAAA;IAC/B,OAAO,iBAAiB,CAAC,QAAQ,EAAE,CAAA;AACrC,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,gBAAgB,CAC9B,WAAmD,EACnD,MAAiC,EACjC,OAAkC,EAClC,GAAmB;IAEnB,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,GAAG,GAAG,CAAA;IAE5C,sFAAsF;IACtF,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,CAAC,KAAK,CACX,qFAAqF,CACtF,CAAA;QACD,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAA;IACjD,CAAC;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YACD,cAAc,CAAC,WAAW,GAAG,wBAAwB,CAAA;YACrD,OAAO,cAAc,CAAA;QACvB,CAAC;QACD,MAAM,cAAc,GAA8B,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAA;QAC3E,cAAc,CAAC,WAAW,GAAG,wBAAwB,CAAA;QACrD,OAAO,cAAc,CAAA;IACvB,CAAC;IAED,uBAAuB;IACvB;;;;SAIK;IACL,OAAO,SAAS,CAAA;AAClB,CAAC;AAED,eAAe,gBAAgB,CAAA;AAQ/B,MAAM,UAAU,2BAA2B,CACzC,MAA6C;IAE7C,OAAO,MAAM,EAAE,WAAW,IAAI,wBAAwB,CAAA;AACxD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve-content-type.js","sourceRoot":"","sources":["../../../src/components/cms-content/resolve-content-type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAErD;;;;;;;;;;GAUG;AACH,MAAM,UAAU,kBAAkB,CAAC,WAA0D,EAAE,YAAyC;
|
|
1
|
+
{"version":3,"file":"resolve-content-type.js","sourceRoot":"","sources":["../../../src/components/cms-content/resolve-content-type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAErD;;;;;;;;;;GAUG;AACH,MAAM,UAAU,kBAAkB,CAAC,WAA0D,EAAE,YAAyC;IAEtI,IAAI,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,CAAC;QAC/B,MAAM,QAAQ,GAAG,WAAW,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAA;QACrD,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC;YACrB,OAAO,QAAQ,CAAA;IACnB,CAAC;SAAM,IAAI,OAAM,CAAC,WAAW,CAAC,IAAI,QAAQ,IAAI,WAAW,CAAC,MAAM,GAAG,CAAC;QAClE,OAAO,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAE/B,IAAI,YAAY,EAAE,CAAC;QACjB,MAAM,SAAS,GAAG,YAAY,CAAC,SAAS,EAAE,KAAK,CAAA;QAC/C,IAAI,SAAS,IAAI,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC;YACvC,OAAO,kBAAkB,CAAC,SAAS,CAAC,CAAA;IACxC,CAAC;IAED,OAAO,SAAS,CAAA;AAClB,CAAC;AAED,eAAe,kBAAkB,CAAA"}
|
|
@@ -2,6 +2,42 @@ import { type PropsWithChildren, type ComponentType, type ComponentProps, type R
|
|
|
2
2
|
import type { CmsComponent } from '../../types.js';
|
|
3
3
|
import type { PropsWithContext, PropsWithOptionalContext } from "../../context/types.js";
|
|
4
4
|
import type { ContentLinkWithLocale, InlineContentLinkWithLocale } from "@remkoj/optimizely-graph-client";
|
|
5
|
+
/**
|
|
6
|
+
* Properties for `CmsContent`.
|
|
7
|
+
*
|
|
8
|
+
* `CmsContent` resolves and renders a CMS template component for the item
|
|
9
|
+
* identified by `contentLink`.
|
|
10
|
+
*
|
|
11
|
+
* Property overview:
|
|
12
|
+
* - `contentLink` (required): content identity (`key` + optional locale).
|
|
13
|
+
* - `contentType`: explicit content type array; skips content-type lookup when set.
|
|
14
|
+
* - `contentTypePrefix`: template prefix (for example `Page`, `Component`).
|
|
15
|
+
* - `variant`: template variant suffix.
|
|
16
|
+
* - `fragmentData`: preloaded data for rendering.
|
|
17
|
+
* - `noDataLoad`: skip loading data from Graph.
|
|
18
|
+
* - `layoutProps`: layout metadata forwarded to resolved component.
|
|
19
|
+
* - `editorComponentId`: explicit editor id override for `editProps.cmsId`.
|
|
20
|
+
* - `ctx`: explicit CMS context override.
|
|
21
|
+
* - `children`: nested content passed through to resolved component.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```tsx
|
|
25
|
+
* <CmsContent
|
|
26
|
+
* contentLink={{ key: 'b9f76fd06f5d4e2e8d2cc3f010f7abf9', locale: 'en' }}
|
|
27
|
+
* contentTypePrefix="Page"
|
|
28
|
+
* />
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```tsx
|
|
33
|
+
* <CmsContent
|
|
34
|
+
* contentLink={{ key: '4f9ac0f95ed147b6956c9f6bd4151f38' }}
|
|
35
|
+
* contentType={["Component", "HeroBlock"]}
|
|
36
|
+
* fragmentData={heroData}
|
|
37
|
+
* noDataLoad
|
|
38
|
+
* />
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
5
41
|
export type CmsContentProps<LocalesType = string> = PropsWithChildren<PropsWithOptionalContext<{
|
|
6
42
|
/**
|
|
7
43
|
* The content type to render
|
|
@@ -31,7 +67,7 @@ export type CmsContentProps<LocalesType = string> = PropsWithChildren<PropsWithO
|
|
|
31
67
|
[fieldname: string]: any;
|
|
32
68
|
};
|
|
33
69
|
/**
|
|
34
|
-
|
|
70
|
+
* React key to use when the component is rendered in a list.
|
|
35
71
|
*/
|
|
36
72
|
key?: string;
|
|
37
73
|
/**
|
|
@@ -46,7 +82,7 @@ export type CmsContentProps<LocalesType = string> = PropsWithChildren<PropsWithO
|
|
|
46
82
|
*/
|
|
47
83
|
variant?: string;
|
|
48
84
|
/**
|
|
49
|
-
|
|
85
|
+
* Additional layout properties forwarded to the resolved CMS template.
|
|
50
86
|
*/
|
|
51
87
|
layoutProps?: Record<string, any>;
|
|
52
88
|
/**
|
|
@@ -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,51 +2,114 @@ 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.
|
|
40
95
|
*/
|
|
41
96
|
forceId?: boolean;
|
|
42
97
|
/**
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
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.
|
|
46
103
|
*/
|
|
47
104
|
currentContent?: ContentLink;
|
|
48
105
|
/**
|
|
49
|
-
* 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.
|
|
50
113
|
*/
|
|
51
114
|
editType?: 'floating' | 'inline' | null;
|
|
52
115
|
} & Omit<ElementProps<FT>, 'as' | 'cmsId' | 'cmsFieldName' | 'ctx' | 'forwardCtx' | 'forceBlockId' | 'forceId' | 'currentContent' | 'editType'>>;
|
|
@@ -24,17 +24,21 @@ export const CmsEditable = ({ ctx, forwardCtx = false, as, cmsId = null, cmsFiel
|
|
|
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 =
|
|
37
|
-
|
|
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));
|
|
38
42
|
const itemProps = addEditProps
|
|
39
43
|
? {
|
|
40
44
|
...props,
|
|
@@ -43,9 +47,9 @@ export const CmsEditable = ({ ctx, forwardCtx = false, as, cmsId = null, cmsFiel
|
|
|
43
47
|
// We assume GUIDs are represented as 32 char long strings
|
|
44
48
|
'data-epi-content-id': showContentId ? cmsId : undefined,
|
|
45
49
|
// We pass through the property name if provided
|
|
46
|
-
'data-epi-property-name': dataEpiPropertyName,
|
|
50
|
+
'data-epi-property-name': editType ? dataEpiPropertyName : undefined,
|
|
47
51
|
// We pass through the property name if provided
|
|
48
|
-
'data-epi-edit': dataEpiPropertyName,
|
|
52
|
+
'data-epi-edit': editType ? undefined : dataEpiPropertyName,
|
|
49
53
|
// Configure the rendition of the property editor
|
|
50
54
|
'data-epi-property-edittype': editType ?? undefined,
|
|
51
55
|
}
|