@remkoj/optimizely-cms-react 4.3.0 → 4.4.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.
- package/dist/components/cms-content/client.d.ts +2 -2
- package/dist/components/cms-content/client.js +20 -12
- package/dist/components/cms-content/client.js.map +1 -1
- package/dist/components/cms-content/get-content.js +61 -21
- package/dist/components/cms-content/get-content.js.map +1 -1
- package/dist/components/cms-content/resolve-component.d.ts +9 -5
- package/dist/components/cms-content/resolve-component.js +20 -9
- package/dist/components/cms-content/resolve-component.js.map +1 -1
- package/dist/components/cms-content/rsc.d.ts +2 -2
- package/dist/components/cms-content/rsc.js +13 -8
- package/dist/components/cms-content/rsc.js.map +1 -1
- package/dist/components/cms-content/utils.d.ts +2 -2
- package/dist/components/cms-content/utils.js +1 -1
- package/dist/components/cms-content/utils.js.map +1 -1
- package/dist/components/visual-builder/functions.js +5 -4
- package/dist/components/visual-builder/functions.js.map +1 -1
- package/dist/components/visual-builder/index.d.ts +1 -1
- package/dist/components/visual-builder/index.js +9 -10
- package/dist/components/visual-builder/index.js.map +1 -1
- package/dist/types.d.ts +2 -1
- package/package.json +2 -2
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { type ReactNode } from 'react';
|
|
2
2
|
import type { BaseCmsContentProps } from './types.js';
|
|
3
|
-
export type * from
|
|
3
|
+
export type * from './types.js';
|
|
4
4
|
/**
|
|
5
5
|
* React Server Side component for the CmsContent
|
|
6
6
|
*
|
|
7
7
|
* @param param0
|
|
8
8
|
* @returns
|
|
9
9
|
*/
|
|
10
|
-
export declare function CmsContent<LocalesType = string>({ contentType, contentTypePrefix, contentLink: rawContentLink, children, fragmentData, layoutProps, noDataLoad, variant, ctx }: BaseCmsContentProps<LocalesType>): ReactNode;
|
|
10
|
+
export declare function CmsContent<LocalesType = string>({ contentType, contentTypePrefix, contentLink: rawContentLink, children, fragmentData, layoutProps, noDataLoad, variant, ctx, }: BaseCmsContentProps<LocalesType>): ReactNode;
|
|
11
11
|
export default CmsContent;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
'use client';
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
3
|
import getContentType from './get-content-type.js';
|
|
4
4
|
import getContent from './get-content.js';
|
|
5
|
-
import { AuthMode, normalizeContentLink, contentLinkToString } from '@remkoj/optimizely-graph-client';
|
|
6
|
-
import resolveComponent, { isComponentMissingComponent } from './resolve-component.js';
|
|
5
|
+
import { AuthMode, normalizeContentLink, contentLinkToString, } from '@remkoj/optimizely-graph-client';
|
|
6
|
+
import resolveComponent, { isComponentMissingComponent, } from './resolve-component.js';
|
|
7
7
|
import resolveContentType from './resolve-content-type.js';
|
|
8
8
|
import { useState, useMemo, useEffect } from 'react';
|
|
9
9
|
/**
|
|
@@ -14,18 +14,25 @@ import { useState, useMemo, useEffect } from 'react';
|
|
|
14
14
|
*/
|
|
15
15
|
export function CmsContent({
|
|
16
16
|
// Own properties
|
|
17
|
-
contentType, contentTypePrefix, contentLink: rawContentLink, children, fragmentData, layoutProps, noDataLoad, variant, ctx }) {
|
|
17
|
+
contentType, contentTypePrefix, contentLink: rawContentLink, children, fragmentData, layoutProps, noDataLoad, variant, ctx, }) {
|
|
18
18
|
// Prepare context
|
|
19
19
|
const graphClient = ctx.client;
|
|
20
20
|
const [myContentType, setMyContentType] = useState(resolveContentType(contentType, fragmentData));
|
|
21
21
|
const contentLink = useMemo(() => normalizeContentLink(rawContentLink), [rawContentLink]);
|
|
22
22
|
const Component = useMemo(() => resolveComponent(myContentType, contentTypePrefix, variant, ctx), [myContentType, variant, contentTypePrefix, ctx]);
|
|
23
|
-
const [data, setData] = useState(
|
|
23
|
+
const [data, setData] = useState(
|
|
24
|
+
//@ts-expect-error
|
|
25
|
+
getContent(graphClient, contentLink, Component, fragmentData, true));
|
|
24
26
|
// Provide a bit of debugging context
|
|
25
27
|
if (graphClient?.debug) {
|
|
26
|
-
const mode = ctx.inEditMode
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
const mode = ctx.inEditMode
|
|
29
|
+
? 'Edit'
|
|
30
|
+
: ctx.inPreviewMode
|
|
31
|
+
? 'Preview'
|
|
32
|
+
: 'Public';
|
|
33
|
+
console.log(`👔 [CmsContent] ${mode} mode active for content with id: ${contentLinkToString(contentLink)} of type ${myContentType?.join('/') ?? 'unknown'}`);
|
|
34
|
+
if ((ctx.inEditMode || ctx.inPreviewMode) &&
|
|
35
|
+
graphClient.currentAuthMode == AuthMode.Public)
|
|
29
36
|
console.warn(`🟠 [CmsContent] ${mode} mode active without an authenticated graphClient, this will cause problems. Make sure the context has an authenticated client.`);
|
|
30
37
|
}
|
|
31
38
|
// Ensure we have a content type to work with
|
|
@@ -39,7 +46,7 @@ contentType, contentTypePrefix, contentLink: rawContentLink, children, fragmentD
|
|
|
39
46
|
}
|
|
40
47
|
if (graphClient.debug)
|
|
41
48
|
console.warn(`🟠 [CmsContent] No content type provided for content ${contentLinkToString(contentLink)}, this causes an additional GraphQL query to resolve the myContentType`);
|
|
42
|
-
getContentType(contentLink, graphClient).then(ct => {
|
|
49
|
+
getContentType(contentLink, graphClient).then((ct) => {
|
|
43
50
|
if (!isCancelled)
|
|
44
51
|
setMyContentType(ct);
|
|
45
52
|
});
|
|
@@ -56,7 +63,8 @@ contentType, contentTypePrefix, contentLink: rawContentLink, children, fragmentD
|
|
|
56
63
|
console.warn(`🔴 [CmsContent] No Optimizely Graph Client present unable to load content type`);
|
|
57
64
|
return;
|
|
58
65
|
}
|
|
59
|
-
|
|
66
|
+
//@ts-expect-error
|
|
67
|
+
getContent(graphClient, contentLink, Component, fragmentData).then((newData) => {
|
|
60
68
|
if (!isCancelled)
|
|
61
69
|
setData(newData);
|
|
62
70
|
});
|
|
@@ -65,8 +73,8 @@ contentType, contentTypePrefix, contentLink: rawContentLink, children, fragmentD
|
|
|
65
73
|
};
|
|
66
74
|
}, [graphClient, contentLink, Component, fragmentData, noDataLoad]);
|
|
67
75
|
if (isComponentMissingComponent(Component))
|
|
68
|
-
return _jsx(Component, {});
|
|
69
|
-
return _jsx(Component, { contentLink: contentLink, data: data, inEditMode: ctx.inEditMode, layoutProps: layoutProps, children: children });
|
|
76
|
+
return _jsx(Component, { contentLink: contentLink });
|
|
77
|
+
return (_jsx(Component, { contentLink: contentLink, data: data, inEditMode: ctx.inEditMode, layoutProps: layoutProps, children: children }));
|
|
70
78
|
}
|
|
71
79
|
export default CmsContent;
|
|
72
80
|
//# sourceMappingURL=client.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/components/cms-content/client.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAIZ,OAAO,cAAc,MAAM,uBAAuB,CAAA;AAClD,OAAO,UAAU,MAAM,kBAAkB,CAAA;AACzC,OAAO,
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/components/cms-content/client.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAIZ,OAAO,cAAc,MAAM,uBAAuB,CAAA;AAClD,OAAO,UAAU,MAAM,kBAAkB,CAAA;AACzC,OAAO,EACL,QAAQ,EACR,oBAAoB,EACpB,mBAAmB,GAEpB,MAAM,iCAAiC,CAAA;AACxC,OAAO,gBAAgB,EAAE,EACvB,2BAA2B,GAC5B,MAAM,wBAAwB,CAAA;AAC/B,OAAO,kBAAkB,MAAM,2BAA2B,CAAA;AAE1D,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAIpD;;;;;GAKG;AACH,MAAM,UAAU,UAAU,CAAuB;AAC/C,iBAAiB;AACjB,WAAW,EACX,iBAAiB,EACjB,WAAW,EAAE,cAAc,EAC3B,QAAQ,EACR,YAAY,EACZ,WAAW,EACX,UAAU,EACV,OAAO,EACP,GAAG,GAC8B;IACjC,kBAAkB;IAClB,MAAM,WAAW,GAAG,GAAG,CAAC,MAAM,CAAA;IAC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QACxC,OAAO,KAAC,SAAS,IAAC,WAAW,EAAE,WAA0B,GAAI,CAAA;IAC/D,OAAO,CACL,KAAC,SAAS,IACR,WAAW,EAAE,WAA0B,EACvC,IAAI,EAAE,IAAI,EACV,UAAU,EAAE,GAAG,CAAC,UAAU,EAC1B,WAAW,EAAE,WAAW,YAEvB,QAAQ,GACC,CACb,CAAA;AACH,CAAC;AAED,eAAe,UAAU,CAAA"}
|
|
@@ -2,18 +2,30 @@ import { print } from 'graphql';
|
|
|
2
2
|
import { isContentLink, isInlineContentLink, contentLinkToString, OptiCmsSchema } from "@remkoj/optimizely-graph-client";
|
|
3
3
|
import { CmsContentFragments } from "../../data/queries.js";
|
|
4
4
|
import { validatesFragment, contentLinkToRequestVariables, isCmsComponentWithFragment, isCmsComponentWithDataQuery } from "../../utilities.js";
|
|
5
|
+
import { getComponentLabel } from './resolve-component.js';
|
|
5
6
|
export function getContent(client, contentLink, Component, fragmentData, noDataLoad) {
|
|
6
7
|
const debug = client?.debug ?? false;
|
|
7
8
|
// Handle provided fragment
|
|
8
|
-
const componentLabel = Component
|
|
9
|
+
const componentLabel = getComponentLabel(Component);
|
|
9
10
|
const fragmentProps = fragmentData ? Object.getOwnPropertyNames(fragmentData).filter(x => !CmsContentFragments.IContentDataProps.includes(x)) : [];
|
|
10
11
|
if (fragmentData && fragmentProps.length > 0) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
// Invalid fragment
|
|
13
|
+
if (validatesFragment(Component) && !Component.validateFragment(fragmentData)) {
|
|
14
|
+
if (debug)
|
|
15
|
+
console.warn("🔴 [CmsContent][getContent] Invalid fragment data received, falling back to loading for ", componentLabel);
|
|
16
|
+
// Preview mode, so load data for changeset
|
|
17
|
+
}
|
|
18
|
+
else if (client?.isPreviewEnabled() && isContentLink(contentLink) && !isInlineContentLink(contentLink)) {
|
|
19
|
+
if (debug)
|
|
20
|
+
console.warn("🔴 [CmsContent][getContent] Rendering shared instance, while in preview mode, falling back to loading for ", componentLabel);
|
|
21
|
+
contentLink.version = null;
|
|
22
|
+
// Default mode, use fragment
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
if (debug)
|
|
26
|
+
console.log("⚪ [CmsContent][getContent] Rendering CMS Component using fragment information", fragmentProps);
|
|
16
27
|
return (noDataLoad ? fragmentData : Promise.resolve(fragmentData));
|
|
28
|
+
}
|
|
17
29
|
}
|
|
18
30
|
if (isInlineContentLink(contentLink)) {
|
|
19
31
|
console.error(`🔴 [CmsContent][getContent] No data for content ${contentLinkToString(contentLink)}, data cannot be resolved for inline content`);
|
|
@@ -39,6 +51,9 @@ export function getContent(client, contentLink, Component, fragmentData, noDataL
|
|
|
39
51
|
if (isCmsComponentWithDataQuery(Component)) {
|
|
40
52
|
const gqlQuery = Component.getDataQuery();
|
|
41
53
|
const gqlVariables = contentLinkToRequestVariables(contentLink);
|
|
54
|
+
// If the CMS Preview mode has been enabled, make sure we include that in the query
|
|
55
|
+
if (client.isPreviewEnabled())
|
|
56
|
+
gqlVariables.changeset = client.getChangeset();
|
|
42
57
|
if (client.debug)
|
|
43
58
|
console.log("⚪ [CmsContent] Component data fetching variables:", gqlVariables);
|
|
44
59
|
return client.request(gqlQuery, gqlVariables).then(gqlResponse => {
|
|
@@ -57,22 +72,14 @@ async function getComponentDataFromFragment(Component, contentLink, client) {
|
|
|
57
72
|
const [name, fragment] = Component.getDataFragment();
|
|
58
73
|
if (client.debug)
|
|
59
74
|
console.log(`⚪ [CmsContent] Component data fetching using fragment: ${name}`);
|
|
60
|
-
const fragmentQuery = client.currentOptiCmsSchema == OptiCmsSchema.CMS12 ?
|
|
61
|
-
`query getContentFragmentById($key: String!, $version: Int, $locale: [Locales!]) { contentById: Content(where: { ContentLink: { GuidValue: { eq: $key }, WorkId: { eq: $version } } }, locale: $locale) { total, items { _type: __typename, _metadata: ContentLink { key: GuidValue, version: WorkId }, _locale: Language { name: Name } ...${name} }}}\n ${print(fragment)}` :
|
|
62
|
-
`query getContentFragmentById($key: String!, $version: String, $locale: [Locales!]) {contentById: _Content(where: {_metadata: {key: { eq: $key }, version: { eq: $version }}} locale: $locale) { total, items { _type: __typename, _metadata { key, version, locale } ...${name} }}}\n ${print(fragment)}`;
|
|
75
|
+
const fragmentQuery = client.currentOptiCmsSchema == OptiCmsSchema.CMS12 ? buildCms12Query(name, fragment) : buildCms13Query(name, fragment);
|
|
63
76
|
const fragmentVariables = contentLinkToRequestVariables(contentLink);
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
fragmentVariables.version = undefined;
|
|
71
|
-
}
|
|
72
|
-
catch {
|
|
73
|
-
fragmentVariables.version = undefined;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
77
|
+
// CMS 12 Requires the version number to be an Int
|
|
78
|
+
if (client.currentOptiCmsSchema == OptiCmsSchema.CMS12)
|
|
79
|
+
fragmentVariables.version = tryParsePositiveInt(fragmentVariables.version);
|
|
80
|
+
// If the CMS Preview mode has been enabled, make sure we include that in the query
|
|
81
|
+
if (client.isPreviewEnabled())
|
|
82
|
+
fragmentVariables.changeset = client.getChangeset();
|
|
76
83
|
if (client.debug)
|
|
77
84
|
console.log(`⚪ [CmsContent] Component data fetching using variables: ${JSON.stringify(fragmentVariables)}`);
|
|
78
85
|
const fragmentResponse = await client.request(fragmentQuery, fragmentVariables);
|
|
@@ -88,4 +95,37 @@ async function getComponentDataFromFragment(Component, contentLink, client) {
|
|
|
88
95
|
}
|
|
89
96
|
return fragmentResponse.contentById.items[0];
|
|
90
97
|
}
|
|
98
|
+
function tryParsePositiveInt(value, defaultValue) {
|
|
99
|
+
try {
|
|
100
|
+
const versionNr = value ? Number.parseInt(value) : 0;
|
|
101
|
+
if (!isNaN(versionNr) && versionNr > 0)
|
|
102
|
+
return versionNr;
|
|
103
|
+
}
|
|
104
|
+
catch {
|
|
105
|
+
// Ignore
|
|
106
|
+
}
|
|
107
|
+
return defaultValue;
|
|
108
|
+
}
|
|
109
|
+
const buildCms12Query = (name, fragment) => `query getContentFragmentById($key: String!, $version: Int, $locale: [Locales!]) { contentById: Content(where: { ContentLink: { GuidValue: { eq: $key }, WorkId: { eq: $version } } }, locale: $locale) { total, items { _type: __typename, _metadata: ContentLink { key: GuidValue, version: WorkId }, _locale: Language { name: Name } ...${name} }}}\n${typeof (fragment) == 'string' ? fragment : print(fragment)}`;
|
|
110
|
+
const buildCms13Query = (name, fragment) => `query getContentFragmentById($key: String!, $version: String, $locale: [Locales!], $changeset: String) {
|
|
111
|
+
contentById: _Content(
|
|
112
|
+
where: {
|
|
113
|
+
_metadata: { key: { eq: $key }, version: { eq: $version }, changeset: { eq: $changeset } }
|
|
114
|
+
}
|
|
115
|
+
locale: $locale
|
|
116
|
+
) {
|
|
117
|
+
total
|
|
118
|
+
items {
|
|
119
|
+
_type: __typename
|
|
120
|
+
__typename
|
|
121
|
+
_metadata {
|
|
122
|
+
key
|
|
123
|
+
version
|
|
124
|
+
locale
|
|
125
|
+
}
|
|
126
|
+
...${name}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
${typeof (fragment) == 'string' ? fragment : print(fragment)}`;
|
|
91
131
|
//# sourceMappingURL=get-content.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-content.js","sourceRoot":"","sources":["../../../src/components/cms-content/get-content.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"get-content.js","sourceRoot":"","sources":["../../../src/components/cms-content/get-content.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,KAAK,EAAE,MAAM,SAAS,CAAA;AAExC,OAAO,EAAmE,aAAa,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAE1L,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,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{ type FunctionComponent, type PropsWithChildren, type ComponentType } from
|
|
1
|
+
import { type ComponentTypeHandle } from '../../factory/types.js';
|
|
2
|
+
import { type EnhancedCmsComponent } from './types.js';
|
|
3
|
+
import { type GenericContext } from '../../context/types.js';
|
|
4
|
+
import { type FunctionComponent, type PropsWithChildren, type ComponentType } from 'react';
|
|
5
|
+
import { type ContentLink } from '@remkoj/optimizely-graph-client';
|
|
6
|
+
export declare function getComponentLabel(componentInstance?: ComponentType | null): string;
|
|
5
7
|
/**
|
|
6
8
|
* Helper function to safely resolve a component from the ContentType information to
|
|
7
9
|
*
|
|
@@ -12,7 +14,9 @@ import { type FunctionComponent, type PropsWithChildren, type ComponentType } fr
|
|
|
12
14
|
*/
|
|
13
15
|
export declare function resolveComponent(contentType: ComponentTypeHandle | null | undefined, prefix: string | null | undefined, variant: string | null | undefined, ctx: GenericContext): EnhancedCmsComponent | ComponentMissingComponent;
|
|
14
16
|
export default resolveComponent;
|
|
15
|
-
export type ComponentMissingComponent = FunctionComponent<PropsWithChildren
|
|
17
|
+
export type ComponentMissingComponent = FunctionComponent<PropsWithChildren<{
|
|
18
|
+
contentLink?: ContentLink;
|
|
19
|
+
}>> & {
|
|
16
20
|
displayName: 'Opti::ComponentMissing';
|
|
17
21
|
};
|
|
18
22
|
export declare function isComponentMissingComponent(toTest: ComponentType<any> | null | undefined): toTest is ComponentMissingComponent;
|
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
import { jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
-
import * as Utils from
|
|
2
|
+
import * as Utils from '../../utilities.js';
|
|
3
|
+
export function getComponentLabel(componentInstance) {
|
|
4
|
+
if (!componentInstance)
|
|
5
|
+
return 'n/a';
|
|
6
|
+
if (componentInstance.displayName)
|
|
7
|
+
return componentInstance.displayName;
|
|
8
|
+
if (typeof componentInstance == 'function' && componentInstance.name)
|
|
9
|
+
return componentInstance.name;
|
|
10
|
+
return componentInstance.toString();
|
|
11
|
+
}
|
|
3
12
|
/**
|
|
4
13
|
* Helper function to safely resolve a component from the ContentType information to
|
|
5
14
|
*
|
|
@@ -13,12 +22,12 @@ export function resolveComponent(contentType, prefix, variant, ctx) {
|
|
|
13
22
|
// Ensure we have a factory - we should, but lets' help by providing an explicit error
|
|
14
23
|
if (!factory) {
|
|
15
24
|
console.error(`🔴 [CmsContent] No content type factory registered in the context`);
|
|
16
|
-
throw new Error(
|
|
25
|
+
throw new Error('Empty factory on the context');
|
|
17
26
|
}
|
|
18
27
|
// Optimizely Graph stores the type in Most Significant first order, we need least significant first, also we're stripping out the common "Content" item from it
|
|
19
|
-
const myContentType = prefix
|
|
20
|
-
Utils.normalizeAndPrefixContentType(Array.isArray(contentType) ? [...contentType].reverse() : contentType, prefix)
|
|
21
|
-
Utils.normalizeContentType(Array.isArray(contentType) ? [...contentType].reverse() : contentType, true);
|
|
28
|
+
const myContentType = prefix
|
|
29
|
+
? Utils.normalizeAndPrefixContentType(Array.isArray(contentType) ? [...contentType].reverse() : contentType, prefix)
|
|
30
|
+
: Utils.normalizeContentType(Array.isArray(contentType) ? [...contentType].reverse() : contentType, true);
|
|
22
31
|
// Validate that we have a value to ask the factory a component for
|
|
23
32
|
if (!myContentType || myContentType.length == 0) {
|
|
24
33
|
if (isDebug)
|
|
@@ -29,21 +38,23 @@ export function resolveComponent(contentType, prefix, variant, ctx) {
|
|
|
29
38
|
const Component = Utils.resolveComponentType(factory, myContentType, variant ? [variant] : []);
|
|
30
39
|
// Handle component not found in factory
|
|
31
40
|
if (!Component) {
|
|
32
|
-
const contentTypeDisplay = Array.isArray(myContentType)
|
|
41
|
+
const contentTypeDisplay = Array.isArray(myContentType)
|
|
42
|
+
? myContentType.join('/')
|
|
43
|
+
: myContentType;
|
|
33
44
|
if (isDebug)
|
|
34
45
|
console.warn(`🟠 [CmsContent] Component of type "${contentTypeDisplay}" not resolved by factory`);
|
|
35
46
|
if (isDebug || inEditMode) {
|
|
36
|
-
const ErrorComponent =
|
|
47
|
+
const ErrorComponent = ({ children, contentLink, }) => (_jsxs(_Fragment, { children: [_jsxs("div", { className: "opti-error", children: ["Component of type \"", contentTypeDisplay, "\" not resolved by factory for", ' ', contentLink?.key ?? '', " version ", contentLink?.version ?? ''] }), children] }));
|
|
37
48
|
ErrorComponent.displayName = 'Opti::ComponentMissing';
|
|
38
49
|
return ErrorComponent;
|
|
39
50
|
}
|
|
40
|
-
const ErrorComponent = props => props.children;
|
|
51
|
+
const ErrorComponent = (props) => props.children;
|
|
41
52
|
ErrorComponent.displayName = 'Opti::ComponentMissing';
|
|
42
53
|
return ErrorComponent;
|
|
43
54
|
}
|
|
44
55
|
// Return the component
|
|
45
56
|
if (isDebug)
|
|
46
|
-
console.log(
|
|
57
|
+
console.log('⚪ [CmsContent] Rendering item using component:', getComponentLabel(Component));
|
|
47
58
|
return Component;
|
|
48
59
|
}
|
|
49
60
|
export default resolveComponent;
|
|
@@ -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;
|
|
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,WAA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AE,CACW,CAAA;IAErC,wCAAwC;IACxC,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,MAAM,kBAAkB,GAAG,KAAK,CAAC,OAAO,CAAC,aAAa,CAAC;YACrD,CAAC,CAAC,aAAa,CAAC,IAAI,CAAC,GAAG,CAAC;YACzB,CAAC,CAAC,aAAa,CAAA;QACjB,IAAI,OAAO;YACT,OAAO,CAAC,IAAI,CACV,sCAAsC,kBAAkB,2BAA2B,CACpF,CAAA;QACH,IAAI,OAAO,IAAI,UAAU,EAAE,CAAC;YAC1B,MAAM,cAAc,GAA8B,CAAC,EACjD,QAAQ,EACR,WAAW,GACZ,EAAE,EAAE,CAAC,CACJ,8BACE,eAAK,SAAS,EAAC,YAAY,qCACL,kBAAkB,oCAA+B,GAAG,EACvE,WAAW,EAAE,GAAG,IAAI,EAAE,eAAW,WAAW,EAAE,OAAO,IAAI,EAAE,IACxD,EACL,QAAQ,IACR,CACJ,CAAA;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,IAAI,OAAO;QACT,OAAO,CAAC,GAAG,CACT,gDAAgD,EAChD,iBAAiB,CAAC,SAA0B,CAAC,CAC9C,CAAA;IACH,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,11 +1,11 @@
|
|
|
1
1
|
import { type ReactNode } from 'react';
|
|
2
2
|
import type { BaseCmsContentProps } from './types.js';
|
|
3
|
-
export type * from
|
|
3
|
+
export type * from './types.js';
|
|
4
4
|
/**
|
|
5
5
|
* React Server Side component for the CmsContent
|
|
6
6
|
*
|
|
7
7
|
* @param param0
|
|
8
8
|
* @returns
|
|
9
9
|
*/
|
|
10
|
-
export declare function CmsContent<LocalesType = string>({ contentType, contentTypePrefix, contentLink: rawContentLink, children, fragmentData, layoutProps, noDataLoad, variant, ctx }: BaseCmsContentProps<LocalesType>): Promise<ReactNode>;
|
|
10
|
+
export declare function CmsContent<LocalesType = string>({ contentType, contentTypePrefix, contentLink: rawContentLink, children, fragmentData, layoutProps, noDataLoad, variant, ctx, }: BaseCmsContentProps<LocalesType>): Promise<ReactNode>;
|
|
11
11
|
export default CmsContent;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import getContentType from './get-content-type.js';
|
|
3
3
|
import getContent from './get-content.js';
|
|
4
|
-
import { AuthMode, normalizeContentLink, contentLinkToString } from '@remkoj/optimizely-graph-client';
|
|
5
|
-
import resolveComponent, { isComponentMissingComponent } from './resolve-component.js';
|
|
4
|
+
import { AuthMode, normalizeContentLink, contentLinkToString, } from '@remkoj/optimizely-graph-client';
|
|
5
|
+
import resolveComponent, { isComponentMissingComponent, } from './resolve-component.js';
|
|
6
6
|
import resolveContentType from './resolve-content-type.js';
|
|
7
7
|
/**
|
|
8
8
|
* React Server Side component for the CmsContent
|
|
@@ -12,7 +12,7 @@ import resolveContentType from './resolve-content-type.js';
|
|
|
12
12
|
*/
|
|
13
13
|
export async function CmsContent({
|
|
14
14
|
// Own properties
|
|
15
|
-
contentType, contentTypePrefix, contentLink: rawContentLink, children, fragmentData, layoutProps, noDataLoad, variant, ctx }) {
|
|
15
|
+
contentType, contentTypePrefix, contentLink: rawContentLink, children, fragmentData, layoutProps, noDataLoad, variant, ctx, }) {
|
|
16
16
|
// Prepare context
|
|
17
17
|
const graphClient = ctx.client;
|
|
18
18
|
// Normalize the ContentLink
|
|
@@ -32,19 +32,24 @@ contentType, contentTypePrefix, contentLink: rawContentLink, children, fragmentD
|
|
|
32
32
|
}
|
|
33
33
|
// Provide a bit of debugging context
|
|
34
34
|
if (graphClient?.debug) {
|
|
35
|
-
const mode = ctx.inEditMode
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
const mode = ctx.inEditMode
|
|
36
|
+
? 'Edit'
|
|
37
|
+
: ctx.inPreviewMode
|
|
38
|
+
? 'Preview'
|
|
39
|
+
: 'Public';
|
|
40
|
+
console.log(`👔 [CmsContent] ${mode} mode active for content with id: ${contentLinkToString(contentLink)} of type ${myContentType?.join('/') ?? 'unknown'}`);
|
|
41
|
+
if ((ctx.inEditMode || ctx.inPreviewMode) &&
|
|
42
|
+
graphClient.currentAuthMode == AuthMode.Public)
|
|
38
43
|
console.warn(`🟠 [CmsContent] ${mode} mode active without an authenticated graphClient, this will cause problems. Make sure the context has an authenticated client.`);
|
|
39
44
|
}
|
|
40
45
|
// Retrieve the Component used to render this item
|
|
41
46
|
const Component = resolveComponent(myContentType, contentTypePrefix, variant, ctx);
|
|
42
47
|
if (isComponentMissingComponent(Component))
|
|
43
|
-
return _jsx(Component, {});
|
|
48
|
+
return _jsx(Component, { contentLink: contentLink });
|
|
44
49
|
// Ensure we have the data the Component requested
|
|
45
50
|
const data = await getContent(graphClient, contentLink, Component, fragmentData, noDataLoad);
|
|
46
51
|
// Output the actual component
|
|
47
|
-
return _jsx(Component, { contentLink: contentLink, data: data, inEditMode: ctx.inEditMode, layoutProps: layoutProps, children: children });
|
|
52
|
+
return (_jsx(Component, { contentLink: contentLink, data: data, inEditMode: ctx.inEditMode, layoutProps: layoutProps, children: children }));
|
|
48
53
|
}
|
|
49
54
|
export default CmsContent;
|
|
50
55
|
//# sourceMappingURL=rsc.js.map
|
|
@@ -1 +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,
|
|
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,EACL,QAAQ,EACR,oBAAoB,EACpB,mBAAmB,GAEpB,MAAM,iCAAiC,CAAA;AACxC,OAAO,gBAAgB,EAAE,EACvB,2BAA2B,GAC5B,MAAM,wBAAwB,CAAA;AAC/B,OAAO,kBAAkB,MAAM,2BAA2B,CAAA;AAI1D;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAAuB;AACrD,iBAAiB;AACjB,WAAW,EACX,iBAAiB,EACjB,WAAW,EAAE,cAAc,EAC3B,QAAQ,EACR,YAAY,EACZ,WAAW,EACX,UAAU,EACV,OAAO,EACP,GAAG,GAC8B;IACjC,kBAAkB;IAClB,MAAM,WAAW,GAAG,GAAG,CAAC,MAAM,CAAA;IAE9B,4BAA4B;IAC5B,MAAM,WAAW,GAAG,oBAAoB,CAAC,cAAc,CAAC,CAAA;IAExD,iCAAiC;IACjC,IAAI,aAAa,GAAG,kBAAkB,CAAC,WAAW,EAAE,YAAY,CAAC,CAAA;IACjE,IAAI,CAAC,aAAa,EAAE,CAAC;QACnB,IAAI,CAAC,WAAW,EAAE,CAAC;YACjB,OAAO,CAAC,KAAK,CACX,kFAAkF,CACnF,CAAA;YACD,OAAM;QACR,CAAC;QACD,IAAI,CAAC,WAAW,EAAE,CAAC;YACjB,OAAO,CAAC,KAAK,CACX,uEAAuE,CACxE,CAAA;YACD,OAAM;QACR,CAAC;QACD,aAAa,GAAG,MAAM,cAAc,CAAC,WAAW,EAAE,WAAW,CAAC,CAAA;IAChE,CAAC;IAED,qCAAqC;IACrC,IAAI,WAAW,EAAE,KAAK,EAAE,CAAC;QACvB,MAAM,IAAI,GAAG,GAAG,CAAC,UAAU;YACzB,CAAC,CAAC,MAAM;YACR,CAAC,CAAC,GAAG,CAAC,aAAa;gBACjB,CAAC,CAAC,SAAS;gBACX,CAAC,CAAC,QAAQ,CAAA;QACd,OAAO,CAAC,GAAG,CACT,mBAAmB,IAAI,qCAAqC,mBAAmB,CAAC,WAAW,CAAC,YAAY,aAAa,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,SAAS,EAAE,CAChJ,CAAA;QACD,IACE,CAAC,GAAG,CAAC,UAAU,IAAI,GAAG,CAAC,aAAa,CAAC;YACrC,WAAW,CAAC,eAAe,IAAI,QAAQ,CAAC,MAAM;YAE9C,OAAO,CAAC,IAAI,CACV,mBAAmB,IAAI,iIAAiI,CACzJ,CAAA;IACL,CAAC;IAED,kDAAkD;IAClD,MAAM,SAAS,GAAG,gBAAgB,CAChC,aAAa,EACb,iBAAiB,EACjB,OAAO,EACP,GAAG,CACJ,CAAA;IACD,IAAI,2BAA2B,CAAC,SAAS,CAAC;QACxC,OAAO,KAAC,SAAS,IAAC,WAAW,EAAE,WAA0B,GAAI,CAAA;IAE/D,kDAAkD;IAClD,MAAM,IAAI,GAAG,MAAM,UAAU,CAC3B,WAAW,EACX,WAAW,EACX,SAAS,EACT,YAAY,EACZ,UAAU,CACX,CAAA;IAED,8BAA8B;IAC9B,OAAO,CACL,KAAC,SAAS,IACR,WAAW,EAAE,WAA0B,EACvC,IAAI,EAAE,IAAI,EACV,UAAU,EAAE,GAAG,CAAC,UAAU,EAC1B,WAAW,EAAE,WAAW,YAEvB,QAAQ,GACC,CACb,CAAA;AACH,CAAC;AAED,eAAe,UAAU,CAAA"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { type ComponentType } from
|
|
2
|
-
import { type CmsContentComponent, type PropsWithCmsContent } from
|
|
1
|
+
import { type ComponentType } from 'react';
|
|
2
|
+
import { type CmsContentComponent, type PropsWithCmsContent } from './types.js';
|
|
3
3
|
export declare function cmsContentAware<P = any>(component: ComponentType<PropsWithCmsContent<P>>, cmsContentComponent: CmsContentComponent): ComponentType<P>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
export function cmsContentAware(component, cmsContentComponent) {
|
|
3
3
|
const BaseComponent = component;
|
|
4
|
-
return (props) => _jsx(BaseComponent, { cmsContent: cmsContentComponent, ...props });
|
|
4
|
+
return (props) => (_jsx(BaseComponent, { cmsContent: cmsContentComponent, ...props }));
|
|
5
5
|
}
|
|
6
6
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/components/cms-content/utils.tsx"],"names":[],"mappings":";AAGA,MAAM,UAAU,eAAe,
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/components/cms-content/utils.tsx"],"names":[],"mappings":";AAGA,MAAM,UAAU,eAAe,CAC7B,SAAgD,EAChD,mBAAwC;IAExC,MAAM,aAAa,GAAG,SAAS,CAAA;IAC/B,OAAO,CAAC,KAAQ,EAAE,EAAE,CAAC,CACnB,KAAC,aAAa,IAAC,UAAU,EAAE,mBAAmB,KAAM,KAAK,GAAI,CAC9D,CAAA;AACH,CAAC"}
|
|
@@ -49,7 +49,8 @@ export const defaultPropsFactory = (node) => {
|
|
|
49
49
|
const contentLink = {
|
|
50
50
|
key: node.component?._metadata?.key || node.key || undefined,
|
|
51
51
|
version: node.component?._metadata?.version,
|
|
52
|
-
locale: node.component?._metadata?.locale
|
|
52
|
+
locale: node.component?._metadata?.locale,
|
|
53
|
+
isInline: node.component?._metadata?.key ? false : true
|
|
53
54
|
};
|
|
54
55
|
if (!(isContentLink(contentLink) || isInlineContentLink(contentLink)))
|
|
55
56
|
throw new Error("Invalid content link: " + JSON.stringify(contentLink));
|
|
@@ -57,7 +58,7 @@ export const defaultPropsFactory = (node) => {
|
|
|
57
58
|
type: node.type,
|
|
58
59
|
layoutType: node.layoutType,
|
|
59
60
|
template: node.template,
|
|
60
|
-
settings: node.settings
|
|
61
|
+
settings: node.settings,
|
|
61
62
|
};
|
|
62
63
|
return [contentLink, contentType, node.component, layoutData];
|
|
63
64
|
};
|
|
@@ -76,8 +77,8 @@ export const defaultNodePropsFactory = (node) => {
|
|
|
76
77
|
["Node", "Content"],
|
|
77
78
|
["Node", "Component", "Content"]
|
|
78
79
|
].filter(x => x);
|
|
79
|
-
const contentLink = { key: node.key ?? '' };
|
|
80
|
-
const componentData = {};
|
|
80
|
+
const contentLink = { key: node.key ?? '', isInline: true };
|
|
81
|
+
const componentData = { __name: node.name };
|
|
81
82
|
const layoutData = {
|
|
82
83
|
type: node.type,
|
|
83
84
|
layoutType: node.layoutType,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"functions.js","sourceRoot":"","sources":["../../../src/components/visual-builder/functions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,EAAE,aAAa,EAAyB,mBAAmB,
|
|
1
|
+
{"version":3,"file":"functions.js","sourceRoot":"","sources":["../../../src/components/visual-builder/functions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,EAAE,aAAa,EAAyB,mBAAmB,EAA+B,MAAM,iCAAiC,CAAA;AAGxI;;;;;;GAMG;AACH,MAAM,UAAU,aAAa,CAAC,IAA0C;IACtE,OAAO,eAAe,CAAC,IAAI,CAAC,CAAA;AAC9B,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,IAA0C;IACxE,OAAO,IAAI,CAAC,UAAU,IAAI,WAAW,CAAA;AACvC,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAiC,IAA0C,EAAE,IAA+C;IAC/J,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC;QACxB,OAAO,KAAK,CAAA;IACd,OAAO,IAAI,CAAC,IAAI,CAAC,S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,MAAM,aAAa,GAAO,EAAE,MAAM,EAAE,IAAI,CAAC,IAAI,EAAmB,CAAA;IAChE,MAAM,UAAU,GAAG;QACjB,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,UAAU,EAAE,IAAI,CAAC,UAAU;QAC3B,QAAQ,EAAE,IAAI,CAAC,QAAQ;QACvB,QAAQ,EAAE,IAAI,CAAC,QAAQ;KACxB,CAAA;IAED,IAAI,CAAC,CAAC,aAAa,CAAC,WAAW,CAAC,IAAI,mBAAmB,CAAC,WAAW,CAAC,CAAC;QACnE,MAAM,IAAI,KAAK,CAAC,2CAA2C,GAAG,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,GAAG,WAAW,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAA;IAEjI,OAAO,CAAC,WAAW,EAAE,cAAc,EAAE,aAAa,EAAE,UAAU,CAAC,CAAA;AACjE,CAAC,CAAA;AAED,MAAM,UAAU,OAAO,CAAC,KAAgC;IACtD,IAAI,OAAO,CAAC,KAAK,CAAC,IAAI,QAAQ,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC;QAChD,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAA;IACpD,OAAO,IAAI,CAAA;AACb,CAAC"}
|
|
@@ -7,5 +7,5 @@ export type * from './types.js';
|
|
|
7
7
|
* @param param0
|
|
8
8
|
* @returns The
|
|
9
9
|
*/
|
|
10
|
-
export declare function OptimizelyComposition({ node, leafPropsFactory, nodePropsFactory, ctx, cmsContent: CmsContent }: BaseOptimizelyCompositionProps): ReactNode;
|
|
10
|
+
export declare function OptimizelyComposition({ node, leafPropsFactory, nodePropsFactory, ctx, cmsContent: CmsContent, }: BaseOptimizelyCompositionProps): ReactNode;
|
|
11
11
|
export default OptimizelyComposition;
|
|
@@ -1,35 +1,34 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { isComponentNode, defaultNodePropsFactory, defaultPropsFactory } from './functions.js';
|
|
2
|
+
import { isComponentNode, defaultNodePropsFactory, defaultPropsFactory, } from './functions.js';
|
|
3
3
|
/**
|
|
4
4
|
* Render the composition as made available through Optimizely Graph for Visual Builder
|
|
5
5
|
*
|
|
6
6
|
* @param param0
|
|
7
7
|
* @returns The
|
|
8
8
|
*/
|
|
9
|
-
export function OptimizelyComposition({ node, leafPropsFactory = defaultPropsFactory, nodePropsFactory = defaultNodePropsFactory, ctx, cmsContent: CmsContent }) {
|
|
9
|
+
export function OptimizelyComposition({ node, leafPropsFactory = defaultPropsFactory, nodePropsFactory = defaultNodePropsFactory, ctx, cmsContent: CmsContent, }) {
|
|
10
10
|
const { factory, isDebug } = ctx;
|
|
11
11
|
// Render the element
|
|
12
12
|
if (isComponentNode(node)) {
|
|
13
13
|
if (isDebug)
|
|
14
14
|
console.log(`⚪ [VisualBuilder] Rendering element node ${JSON.stringify(node)}`);
|
|
15
15
|
const [contentLink, contentType, fragmentData, layoutProps] = leafPropsFactory(node);
|
|
16
|
-
return _jsx(CmsContent, { contentLink: contentLink, contentType: contentType, fragmentData: fragmentData, layoutProps: layoutProps });
|
|
16
|
+
return (_jsx(CmsContent, { contentLink: contentLink, contentType: contentType, fragmentData: fragmentData, layoutProps: layoutProps }));
|
|
17
17
|
}
|
|
18
18
|
// Debug
|
|
19
19
|
if (isDebug)
|
|
20
20
|
console.log(`⚪ [VisualBuilder] Rendering structure node ${JSON.stringify(node)}`);
|
|
21
21
|
// Ensure we've got a factory
|
|
22
22
|
if (!factory)
|
|
23
|
-
throw new Error(
|
|
23
|
+
throw new Error('🟡 [VisualBuilder] [OptimizelyComposition] The factory must be defined within the serverContext');
|
|
24
24
|
const [contentLink, contentTypes, fragmentData, layoutProps] = nodePropsFactory(node);
|
|
25
|
-
const
|
|
26
|
-
const contentType = contentTypes[firstExistingType];
|
|
25
|
+
const contentType = contentTypes.find((ct) => factory.has([...ct].reverse()));
|
|
27
26
|
if (!contentType)
|
|
28
|
-
throw new Error(`🟡 [VisualBuilder] [OptimizelyComposition] The factory must have a definition for one of these types: ${contentTypes.map(x => x.join('/')).join(', ')}`);
|
|
29
|
-
return _jsx(CmsContent, { contentType: contentType, contentLink: contentLink, fragmentData: fragmentData, layoutProps: layoutProps, noDataLoad: true, children: (node.nodes ?? []).map((child) => {
|
|
27
|
+
throw new Error(`🟡 [VisualBuilder] [OptimizelyComposition] The factory must have a definition for one of these types: ${contentTypes.map((x) => x.join('/')).join(', ')}`);
|
|
28
|
+
return (_jsx(CmsContent, { contentType: contentType, contentLink: contentLink, fragmentData: fragmentData, layoutProps: layoutProps, noDataLoad: true, children: (node.nodes ?? []).map((child) => {
|
|
30
29
|
const childKey = child.key ? child.key : `vb::${JSON.stringify(child)}`;
|
|
31
|
-
return _jsx(OptimizelyComposition, { node: child, leafPropsFactory: leafPropsFactory, nodePropsFactory: nodePropsFactory, ctx: ctx, cmsContent: CmsContent }, childKey);
|
|
32
|
-
}) });
|
|
30
|
+
return (_jsx(OptimizelyComposition, { node: child, leafPropsFactory: leafPropsFactory, nodePropsFactory: nodePropsFactory, ctx: ctx, cmsContent: CmsContent }, childKey));
|
|
31
|
+
}) }));
|
|
33
32
|
}
|
|
34
33
|
export default OptimizelyComposition;
|
|
35
34
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/visual-builder/index.tsx"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/visual-builder/index.tsx"],"names":[],"mappings":";AACA,OAAO,EACL,eAAe,EACf,uBAAuB,EACvB,mBAAmB,GACpB,MAAM,gBAAgB,CAAA;AAIvB;;;;;GAKG;AACH,MAAM,UAAU,qBAAqB,CAAC,EACpC,IAAI,EACJ,gBAAgB,GAAG,mBAAmB,EACtC,gBAAgB,GAAG,uBAAuB,EAC1C,GAAG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ACT,WAAW,EAAE,WAAW,EACxB,WAAW,EAAE,WAAW,EACxB,YAAY,EAAE,YAAY,EAC1B,WAAW,EAAE,WAAW,EACxB,UAAU,kBAET,CAAC,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;YAChC,MAAM,QAAQ,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAA;YACvE,OAAO,CACL,KAAC,qBAAqB,IAEpB,IAAI,EAAE,KAAK,EACX,gBAAgB,EAAE,gBAAgB,EAClC,gBAAgB,EAAE,gBAAgB,EAClC,GAAG,EAAE,GAAG,EACR,UAAU,EAAE,UAAU,IALjB,QAAQ,CAMb,CACH,CAAA;QACH,CAAC,CAAC,GACS,CACd,CAAA;AACH,CAAC;AAED,eAAe,qBAAqB,CAAA"}
|
package/dist/types.d.ts
CHANGED
|
@@ -34,6 +34,7 @@ export type ContentQueryProps<LocaleType = string> = ContentLink & {
|
|
|
34
34
|
locale?: Array<LocaleType> | LocaleType | null;
|
|
35
35
|
path?: string | null;
|
|
36
36
|
domain?: string | null;
|
|
37
|
+
changeset?: string | null;
|
|
37
38
|
};
|
|
38
39
|
/**
|
|
39
40
|
* Extract the data type from a GraphQL Query
|
|
@@ -42,7 +43,7 @@ export type ResponseDataType<T extends DocumentNode> = T extends TypedDocumentNo
|
|
|
42
43
|
[key: string]: any;
|
|
43
44
|
};
|
|
44
45
|
export type GetDataQuery<T> = () => TypedDocumentNode<T, ContentQueryProps> | DocumentNode;
|
|
45
|
-
export type GetDataFragment<T> = () => [string, TypedDocumentNode<T, never> | DocumentNode];
|
|
46
|
+
export type GetDataFragment<T> = () => [string, TypedDocumentNode<T, never> | DocumentNode | string];
|
|
46
47
|
export type WithGqlFragment<BaseComponent, DataType> = BaseComponent & {
|
|
47
48
|
getDataFragment: GetDataFragment<DataType>;
|
|
48
49
|
validateFragment?: (data: any) => data is DataType;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@remkoj/optimizely-cms-react",
|
|
3
3
|
"license": "Apache-2.0",
|
|
4
|
-
"version": "4.
|
|
4
|
+
"version": "4.4.0",
|
|
5
5
|
"repository": "https://github.com/remkoj/optimizely-dxp-clients.git",
|
|
6
6
|
"author": "Remko Jantzen <693172+remkoj@users.noreply.github.com>",
|
|
7
7
|
"homepage": "https://github.com/remkoj/optimizely-dxp-clients/tree/main/packages/optimizely-cms-react",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
}
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@remkoj/optimizely-graph-client": "4.
|
|
30
|
+
"@remkoj/optimizely-graph-client": "4.4.0",
|
|
31
31
|
"@types/crypto-js": "^4.2.2",
|
|
32
32
|
"@types/node": "^22.13.5",
|
|
33
33
|
"@types/react": "^18.3.18",
|