@remkoj/optimizely-cms-react 4.3.1 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/cms-content/get-content.js +23 -21
- package/dist/components/cms-content/get-content.js.map +1 -1
- package/dist/components/cms-content/resolve-component.d.ts +4 -4
- package/dist/components/cms-content/resolve-component.js +14 -14
- 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 +14 -7
- package/dist/components/cms-content/rsc.js.map +1 -1
- package/dist/components/cms-content/types.d.ts +11 -4
- package/dist/components/cms-content-area/index.d.ts +3 -10
- package/dist/components/cms-content-area/index.js +35 -51
- package/dist/components/cms-content-area/index.js.map +1 -1
- package/dist/components/cms-content-area/types.d.ts +49 -57
- package/dist/components/cms-editable/index.d.ts +48 -13
- package/dist/components/cms-editable/index.js +41 -5
- package/dist/components/cms-editable/index.js.map +1 -1
- package/dist/components/rich-text/components.d.ts +8 -7
- package/dist/components/rich-text/components.js +27 -22
- package/dist/components/rich-text/components.js.map +1 -1
- package/dist/components/rich-text/index.d.ts +4 -4
- package/dist/components/rich-text/index.js +19 -20
- package/dist/components/rich-text/index.js.map +1 -1
- package/dist/components/rich-text/types.d.ts +7 -15
- package/dist/components/rsc.d.ts +12 -12
- package/dist/components/rsc.js +17 -16
- package/dist/components/rsc.js.map +1 -1
- package/dist/components/type-utils.d.ts +13 -0
- package/dist/components/visual-builder/functions.js +1 -1
- 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 +11 -9
- package/dist/components/visual-builder/index.js.map +1 -1
- package/dist/components/visual-builder/types.d.ts +3 -3
- package/dist/components/visual-builder/types.js.map +1 -1
- package/dist/components.d.ts +1 -1
- package/dist/context/client.d.ts +16 -4
- package/dist/context/client.js +38 -12
- package/dist/context/client.js.map +1 -1
- package/dist/context/rsc.d.ts +26 -9
- package/dist/context/rsc.js +84 -18
- package/dist/context/rsc.js.map +1 -1
- package/dist/context/shared.d.ts +3 -0
- package/dist/context/shared.js +7 -0
- package/dist/context/shared.js.map +1 -0
- package/dist/context/types.d.ts +24 -2
- package/dist/factory/default.js +16 -16
- package/dist/factory/default.js.map +1 -1
- package/dist/index.d.ts +4 -5
- package/dist/index.js +6 -2
- package/dist/index.js.map +1 -1
- package/dist/rsc.d.ts +2 -4
- package/dist/rsc.js +3 -1
- package/dist/rsc.js.map +1 -1
- package/dist/types.d.ts +5 -0
- package/dist/version.json +3 -0
- package/package.json +7 -7
package/dist/context/rsc.js
CHANGED
|
@@ -1,17 +1,10 @@
|
|
|
1
1
|
import 'server-only';
|
|
2
|
-
import { createClient, isOptiGraphClient } from '@remkoj/optimizely-graph-client';
|
|
2
|
+
import { createClient, isOptiGraphClient, } from '@remkoj/optimizely-graph-client';
|
|
3
3
|
import React from 'react';
|
|
4
|
-
import { DefaultComponentFactory } from '../factory/index.js';
|
|
4
|
+
import { DefaultComponentFactory, } from '../factory/index.js';
|
|
5
5
|
import { isDebug, isDevelopment } from '../rsc-utilities.js';
|
|
6
|
-
export * from
|
|
7
|
-
|
|
8
|
-
if (isDebug() || isDevelopment())
|
|
9
|
-
console.warn("🚧 [React Context] Running client/server react code instead of server context, no cache() available.");
|
|
10
|
-
return factory;
|
|
11
|
-
};
|
|
12
|
-
//@ts-expect-error React.cache is only available in the react-server context
|
|
13
|
-
const cache = (React.cache || cachePlaceholder);
|
|
14
|
-
class ServerContext {
|
|
6
|
+
export * from './types.js';
|
|
7
|
+
export class ServerContext {
|
|
15
8
|
get client() {
|
|
16
9
|
return this._client;
|
|
17
10
|
}
|
|
@@ -39,11 +32,14 @@ class ServerContext {
|
|
|
39
32
|
get editableContent() {
|
|
40
33
|
return this._editable;
|
|
41
34
|
}
|
|
42
|
-
constructor({ factory, client, locale }) {
|
|
43
|
-
this.
|
|
44
|
-
|
|
35
|
+
constructor({ factory, client, locale, mode, editableContent, }) {
|
|
36
|
+
this._factory = Array.isArray(factory)
|
|
37
|
+
? new DefaultComponentFactory(factory)
|
|
38
|
+
: factory || new DefaultComponentFactory();
|
|
45
39
|
this._client = client || createClient();
|
|
46
40
|
this._locale = locale;
|
|
41
|
+
this._mode = mode ?? 'public';
|
|
42
|
+
this._editable = editableContent;
|
|
47
43
|
}
|
|
48
44
|
setMode(mode) {
|
|
49
45
|
if (this.isDebug)
|
|
@@ -60,14 +56,19 @@ class ServerContext {
|
|
|
60
56
|
setOptimizelyGraphClient(client) {
|
|
61
57
|
if (this.isDebug)
|
|
62
58
|
console.log(`🦺 [ServerContext] Assigning new Optimizely Graph Client`);
|
|
63
|
-
this._client =
|
|
59
|
+
this._client =
|
|
60
|
+
typeof client == 'function'
|
|
61
|
+
? client(this._client)
|
|
62
|
+
: isOptiGraphClient(client)
|
|
63
|
+
? client
|
|
64
|
+
: undefined;
|
|
64
65
|
}
|
|
65
66
|
setComponentFactory(factory) {
|
|
66
67
|
if (this.isDebug)
|
|
67
68
|
console.log(`🦺 [ServerContext] Assigning new Component Factory`);
|
|
68
|
-
const newFactory = typeof
|
|
69
|
+
const newFactory = typeof factory == 'function' ? factory(this._factory) : factory;
|
|
69
70
|
if (!newFactory)
|
|
70
|
-
throw new Error(
|
|
71
|
+
throw new Error('Unsetting the context factory is not allowed!');
|
|
71
72
|
this._factory = newFactory;
|
|
72
73
|
}
|
|
73
74
|
setEditableContentId(link) {
|
|
@@ -75,7 +76,25 @@ class ServerContext {
|
|
|
75
76
|
console.log(`🦺 [ServerContext] Assigning editable content id: ${JSON.stringify(link)}`);
|
|
76
77
|
this._editable = link;
|
|
77
78
|
}
|
|
79
|
+
toJSON(key) {
|
|
80
|
+
if (this.isDebugOrDevelopment) {
|
|
81
|
+
console.warn('🦺 [ServerContext] Converting Context to JSON, this is typically a side effect of the context being passed between Server & Client components');
|
|
82
|
+
if (this.isDebug) {
|
|
83
|
+
console.trace('The conversion happened here');
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return {
|
|
87
|
+
inEditMode: this.inEditMode,
|
|
88
|
+
inPreviewMode: this.inPreviewMode,
|
|
89
|
+
isDebug: this.isDebug,
|
|
90
|
+
isDebugOrDevelopment: this.isDebugOrDevelopment,
|
|
91
|
+
isDevelopment: this.isDevelopment,
|
|
92
|
+
clientConfig: this.client?.toJSON(),
|
|
93
|
+
locale: this.locale,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
78
96
|
}
|
|
97
|
+
//#region Obsolete & Deprecated methods, as context must be handed down in React Server Context
|
|
79
98
|
/**
|
|
80
99
|
* Obtain an instance of the servercontext, this either uses `React.cache`,
|
|
81
100
|
* when available in the current context. If `React.cache` is not available, the
|
|
@@ -83,11 +102,58 @@ class ServerContext {
|
|
|
83
102
|
*
|
|
84
103
|
* It the cache fallback will notify in development or debug mode when it is in
|
|
85
104
|
* use.
|
|
105
|
+
*
|
|
106
|
+
* @deprecated Use the context handed down through the CmsContentArea and CmsContent
|
|
107
|
+
* components
|
|
86
108
|
*/
|
|
87
|
-
export const getServerContext =
|
|
109
|
+
export const getServerContext = () => {
|
|
110
|
+
if (isDebug())
|
|
111
|
+
console.debug('🦺 [ServerContext] getServerContext has been deprecated, this provides an instance of the Server Context that is potentially shared between requests');
|
|
112
|
+
return internalGetServerContext();
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* Update the shared server context from the provided context. This is compatibility
|
|
116
|
+
* method to ensure that the value returned by `getServerContext` can be retrieved and
|
|
117
|
+
* updated.
|
|
118
|
+
*
|
|
119
|
+
* @deprecated Use the context handed down through the CmsContentArea and CmsContent
|
|
120
|
+
* components
|
|
121
|
+
* @param currentCtx The current context to apply to the server context
|
|
122
|
+
* @returns The updated shared server context
|
|
123
|
+
*/
|
|
124
|
+
export function updateSharedServerContext(currentCtx) {
|
|
125
|
+
const serverCtx = internalGetServerContext();
|
|
126
|
+
// Update component factory
|
|
127
|
+
serverCtx.setComponentFactory(currentCtx.factory);
|
|
128
|
+
// Update Optimizely Graph Client
|
|
129
|
+
if (currentCtx.client)
|
|
130
|
+
serverCtx.setOptimizelyGraphClient(currentCtx.client);
|
|
131
|
+
// Update locale
|
|
132
|
+
if (currentCtx.locale)
|
|
133
|
+
serverCtx.setLocale(currentCtx.locale);
|
|
134
|
+
// Update mode
|
|
135
|
+
if (currentCtx.inEditMode)
|
|
136
|
+
serverCtx.setMode('edit');
|
|
137
|
+
else if (currentCtx.inPreviewMode)
|
|
138
|
+
serverCtx.setMode('preview');
|
|
139
|
+
else if (!currentCtx.inEditMode && !currentCtx.inPreviewMode)
|
|
140
|
+
serverCtx.setMode('public');
|
|
141
|
+
// Update editable content
|
|
142
|
+
serverCtx.setEditableContentId(currentCtx.editableContent);
|
|
143
|
+
return serverCtx;
|
|
144
|
+
}
|
|
145
|
+
const cachePlaceholder = (factory) => {
|
|
146
|
+
if (isDebug() || isDevelopment())
|
|
147
|
+
console.warn('🚧 [React Context] Running client/server react code instead of server context, no cache() available.');
|
|
148
|
+
return factory;
|
|
149
|
+
};
|
|
150
|
+
//@ts-ignore React.cache is only available in the react-server context
|
|
151
|
+
const cache = (React.cache || cachePlaceholder);
|
|
152
|
+
const internalGetServerContext = cache(() => {
|
|
88
153
|
const ctx = new ServerContext({});
|
|
89
154
|
if (ctx.isDebug)
|
|
90
155
|
console.log('🦺 [ServerContext] Created new context');
|
|
91
156
|
return ctx;
|
|
92
157
|
});
|
|
158
|
+
//#endregion
|
|
93
159
|
//# sourceMappingURL=rsc.js.map
|
package/dist/context/rsc.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rsc.js","sourceRoot":"","sources":["../../src/context/rsc.tsx"],"names":[],"mappings":"AAAA,OAAO,aAAa,CAAA;AACpB,OAAO,
|
|
1
|
+
{"version":3,"file":"rsc.js","sourceRoot":"","sources":["../../src/context/rsc.tsx"],"names":[],"mappings":"AAAA,OAAO,aAAa,CAAA;AACpB,OAAO,EACL,YAAY,EACZ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M,CAAC,CAAA;IAE5E,gBAAgB;IAChB,IAAI,UAAU,CAAC,MAAM;QAAE,SAAS,CAAC,SAAS,CAAC,UAAU,CAAC,MAAM,CAAC,CAAA;IAE7D,cAAc;IACd,IAAI,UAAU,CAAC,UAAU;QAAE,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;SAC/C,IAAI,UAAU,CAAC,aAAa;QAAE,SAAS,CAAC,OAAO,CAAC,SAAS,CAAC,CAAA;SAC1D,IAAI,CAAC,UAAU,CAAC,UAAU,IAAI,CAAC,UAAU,CAAC,aAAa;QAC1D,SAAS,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;IAE7B,0BAA0B;IAC1B,SAAS,CAAC,oBAAoB,CAAC,UAAU,CAAC,eAAe,CAAC,CAAA;IAC1D,OAAO,SAAS,CAAA;AAClB,CAAC;AAOD,MAAM,gBAAgB,GAAqB,CACzC,OAAU,EACV,EAAE;IACF,IAAI,OAAO,EAAE,IAAI,aAAa,EAAE;QAC9B,OAAO,CAAC,IAAI,CACV,sGAAsG,CACvG,CAAA;IACH,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA;AAED,sEAAsE;AACtE,MAAM,KAAK,GAAG,CAAC,KAAK,CAAC,KAAK,IAAI,gBAAgB,CAAqB,CAAA;AAEnE,MAAM,wBAAwB,GAAG,KAAK,CAAC,GAAG,EAAE;IAC1C,MAAM,GAAG,GAAG,IAAI,aAAa,CAAC,EAAE,CAAC,CAAA;IACjC,IAAI,GAAG,CAAC,OAAO;QAAE,OAAO,CAAC,GAAG,CAAC,wCAAwC,CAAC,CAAA;IACtE,OAAO,GAAG,CAAA;AACZ,CAAC,CAAC,CAAA;AACF,YAAY"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { GenericContext, TransferrableContext, BaseContext } from "./types.js";
|
|
2
|
+
export declare function isTransferrableContext(ctxIn?: BaseContext | null): ctxIn is TransferrableContext;
|
|
3
|
+
export declare function isGenericContext(ctxIn?: BaseContext | null): ctxIn is GenericContext;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export function isTransferrableContext(ctxIn) {
|
|
2
|
+
return typeof (ctxIn) == 'object' && ctxIn != null && ctxIn.factory === undefined;
|
|
3
|
+
}
|
|
4
|
+
export function isGenericContext(ctxIn) {
|
|
5
|
+
return typeof (ctxIn) == 'object' && ctxIn != null && typeof ctxIn.factory == 'object' && ctxIn.factory != null;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=shared.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../../src/context/shared.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,sBAAsB,CAAC,KAA0B;IAC/D,OAAO,OAAO,CAAC,KAAK,CAAC,IAAI,QAAQ,IAAI,KAAK,IAAI,IAAI,IAAK,KAAwB,CAAC,OAAO,KAAK,SAAS,CAAA;AACvG,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,KAA0B;IACzD,OAAO,OAAO,CAAC,KAAK,CAAC,IAAI,QAAQ,IAAI,KAAK,IAAI,IAAI,IAAI,OAAQ,KAAwB,CAAC,OAAO,IAAI,QAAQ,IAAK,KAAwB,CAAC,OAAO,IAAI,IAAI,CAAA;AACzJ,CAAC"}
|
package/dist/context/types.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { type IOptiGraphClient } from "@remkoj/optimizely-graph-client";
|
|
1
|
+
import { type IOptiGraphClient, type OptimizelyGraphConfig, type ContentLink } from "@remkoj/optimizely-graph-client";
|
|
2
2
|
import { type ComponentFactory } from "../factory/types.js";
|
|
3
|
+
export type RenderMode = 'edit' | 'preview' | 'public';
|
|
3
4
|
export interface GenericContext {
|
|
4
5
|
readonly client?: IOptiGraphClient;
|
|
5
6
|
readonly factory: ComponentFactory;
|
|
@@ -9,7 +10,28 @@ export interface GenericContext {
|
|
|
9
10
|
readonly isDevelopment: boolean;
|
|
10
11
|
readonly isDebug: boolean;
|
|
11
12
|
readonly isDebugOrDevelopment: boolean;
|
|
13
|
+
readonly editableContent?: ContentLink | null;
|
|
12
14
|
}
|
|
13
|
-
|
|
15
|
+
/**
|
|
16
|
+
* The context information that can cross the React Server/Client boundary
|
|
17
|
+
*/
|
|
18
|
+
export interface TransferrableContext {
|
|
19
|
+
readonly clientConfig?: OptimizelyGraphConfig;
|
|
20
|
+
readonly locale?: string;
|
|
21
|
+
readonly inEditMode: boolean;
|
|
22
|
+
readonly inPreviewMode: boolean;
|
|
23
|
+
readonly isDevelopment: boolean;
|
|
24
|
+
readonly isDebug: boolean;
|
|
25
|
+
readonly isDebugOrDevelopment: boolean;
|
|
26
|
+
readonly editableContent?: ContentLink | null;
|
|
27
|
+
}
|
|
28
|
+
export type BaseContext = TransferrableContext | GenericContext;
|
|
29
|
+
export type PropsWithContext<P = {}> = P & {
|
|
14
30
|
ctx: GenericContext;
|
|
15
31
|
};
|
|
32
|
+
export type PropsWithOptionalContext<P = {}> = P & {
|
|
33
|
+
/**
|
|
34
|
+
* The context to be used when rendering this component
|
|
35
|
+
*/
|
|
36
|
+
ctx?: GenericContext;
|
|
37
|
+
};
|
package/dist/factory/default.js
CHANGED
|
@@ -29,37 +29,37 @@ export class DefaultComponentFactory {
|
|
|
29
29
|
register(type, component, useSuspense = false, loader) {
|
|
30
30
|
const registryKey = processComponentTypeHandle(type);
|
|
31
31
|
if (this.dbg)
|
|
32
|
-
console.log(`➕ [DefaultComponentFactory]
|
|
32
|
+
console.log(`➕ [DefaultComponentFactory] Registering ${registryKey}`);
|
|
33
33
|
this.registry.set(registryKey, { type, component, useSuspense, loader });
|
|
34
34
|
}
|
|
35
35
|
registerAll(components) {
|
|
36
|
-
components.forEach(c => {
|
|
36
|
+
components.forEach((c) => {
|
|
37
37
|
const registryKey = processComponentTypeHandle(c.type);
|
|
38
38
|
if (this.dbg)
|
|
39
|
-
console.log(`➕ [DefaultComponentFactory]
|
|
39
|
+
console.log(`➕ [DefaultComponentFactory] Registering ${registryKey}`);
|
|
40
40
|
this.registry.set(registryKey, c);
|
|
41
41
|
});
|
|
42
42
|
}
|
|
43
43
|
has(type) {
|
|
44
44
|
const registryKey = processComponentTypeHandle(type);
|
|
45
|
-
if (this.dbg)
|
|
46
|
-
console.log(`🔎 [DefaultComponentFactory] Checking for ${registryKey}`);
|
|
45
|
+
//if (this.dbg) console.log(`🔎 [DefaultComponentFactory] Checking for ${ registryKey }`)
|
|
47
46
|
return this.registry.has(registryKey);
|
|
48
47
|
}
|
|
49
48
|
resolve(type) {
|
|
50
49
|
const registryKey = processComponentTypeHandle(type);
|
|
51
|
-
if (this.dbg)
|
|
52
|
-
console.log(`⚡ [DefaultComponentFactory] Resolving ${registryKey}`);
|
|
53
50
|
const entry = this.registry.get(registryKey);
|
|
54
|
-
if (!entry)
|
|
51
|
+
if (!entry) {
|
|
52
|
+
if (this.dbg)
|
|
53
|
+
console.warn(`⚡ [DefaultComponentFactory] Unable to resolve ${registryKey}`);
|
|
55
54
|
return undefined; // The key is not registered in the factory
|
|
55
|
+
}
|
|
56
56
|
if (entry.useSuspense != true)
|
|
57
57
|
return entry.component; // There's no suspense, so we're using the component directly
|
|
58
58
|
// We need to wrap the component in a Supense
|
|
59
59
|
const EntryComponent = entry.component;
|
|
60
60
|
const EntryLoader = entry.loader;
|
|
61
61
|
function Suspended(props) {
|
|
62
|
-
return _jsx(Suspense, { fallback: EntryLoader && _jsx(EntryLoader, { ...props }), children: _jsx(EntryComponent, { ...props }) });
|
|
62
|
+
return (_jsx(Suspense, { fallback: EntryLoader && _jsx(EntryLoader, { ...props }), children: _jsx(EntryComponent, { ...props }) }));
|
|
63
63
|
}
|
|
64
64
|
return Suspended;
|
|
65
65
|
}
|
|
@@ -78,14 +78,14 @@ export class DefaultComponentFactory {
|
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
80
|
function processComponentTypeHandle(handle) {
|
|
81
|
-
if (typeof
|
|
82
|
-
return handle ==
|
|
83
|
-
if (Array.isArray(handle) && handle.every(s => typeof
|
|
81
|
+
if (typeof handle == 'string')
|
|
82
|
+
return handle == '' ? EmptyComponentHandle : handle;
|
|
83
|
+
if (Array.isArray(handle) && handle.every((s) => typeof s == 'string'))
|
|
84
84
|
return handle
|
|
85
|
-
.map(s => s.startsWith(
|
|
86
|
-
.filter(s => s.toLowerCase() != 'content') // Remove the "Content" base type
|
|
87
|
-
.map(s => s ==
|
|
85
|
+
.map((s) => (s.startsWith('_') ? s.substring(1) : s)) // Remove all leading underscores
|
|
86
|
+
.filter((s) => s.toLowerCase() != 'content') // Remove the "Content" base type
|
|
87
|
+
.map((s) => (s == '' ? EmptyComponentHandle : s)) // Fall back to a fragment
|
|
88
88
|
.join(MERGE_SYMBOL); // Types are processed as a string
|
|
89
|
-
throw new Error(`Invalid component type handle: ${typeof
|
|
89
|
+
throw new Error(`Invalid component type handle: ${typeof handle}`);
|
|
90
90
|
}
|
|
91
91
|
//# sourceMappingURL=default.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"default.js","sourceRoot":"","sources":["../../src/factory/default.tsx"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"default.js","sourceRoot":"","sources":["../../src/factory/default.tsx"],"names":[],"mappings":";AAOA,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAEhC,MAAM,CAAC,MAAM,YAAY,GAAG,GAAG,CAAA;AAE/B,MAAM,CAAC,MAAM,oBAAoB,GAAG,cAAc,CAAA;AAElD;;;GAGG;AACH,MAAM,OAAO,uBAAuB;IAIlC;;;;;OAKG;IACH,YAAmB,iBAA2C;QATtD,aAAQ,GAAG,IAAI,GAAG,EAAwC,CAAA;QAUhE,qBAAqB;QACrB,IAAI,CAAC;YACH,IAAI,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,gBAAgB,IAAI,GAAG,CAAA;QAChD,CAAC;QAAC,MAAM,CAAC;YACP,IAAI,CAAC,GAAG,GAAG,KAAK,CAAA;QAClB,CAAC;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C,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAC,MAAM,CAAA;IACrD,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,QAAQ,CAAC;QACpE,OAAO,MAAM;aACV,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,iCAAiC;aACtF,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,IAAI,SAAS,CAAC,CAAC,iCAAiC;aAC7E,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,0BAA0B;aAC3E,IAAI,CAAC,YAAY,CAAC,CAAA,CAAC,kCAAkC;IAC1D,MAAM,IAAI,KAAK,CAAC,kCAAkC,OAAO,MAAM,EAAE,CAAC,CAAA;AACpE,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
* The version of the current Optimizely DXP React SDK
|
|
3
|
-
*/
|
|
4
|
-
export declare const Version = "3.2.2";
|
|
5
|
-
export * from './types.js';
|
|
1
|
+
export declare const Version: string;
|
|
6
2
|
export * as Errors from './errors.js';
|
|
7
3
|
export * as Utils from './utilities.js';
|
|
4
|
+
export * from './types.js';
|
|
5
|
+
export * from './factory/index.js';
|
|
6
|
+
export * from './context/types.js';
|
|
8
7
|
export * from './context/client.js';
|
|
9
8
|
export * from './factory/index.js';
|
|
10
9
|
export * from './components/client.js';
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The version of the current Optimizely DXP React SDK
|
|
3
3
|
*/
|
|
4
|
-
|
|
4
|
+
import buildInfo from "./version.json" with { type: "json" };
|
|
5
|
+
export const Version = buildInfo.version;
|
|
5
6
|
// Export library
|
|
6
|
-
export * from './types.js';
|
|
7
7
|
export * as Errors from './errors.js';
|
|
8
8
|
export * as Utils from './utilities.js';
|
|
9
|
+
export * from './types.js';
|
|
10
|
+
export * from './factory/index.js';
|
|
11
|
+
export * from './context/types.js';
|
|
12
|
+
// Export React Client Components
|
|
9
13
|
export * from './context/client.js';
|
|
10
14
|
export * from './factory/index.js';
|
|
11
15
|
export * from './components/client.js';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,SAAS,MAAM,gBAAgB,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAA;AAC5D,MAAM,CAAC,MAAM,OAAO,GAAG,SAAS,CAAC,OAAO,CAAA;AAExC,iBAAiB;AACjB,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AACrC,OAAO,KAAK,KAAK,MAAM,gBAAgB,CAAA;AACvC,cAAc,YAAY,CAAA;AAC1B,cAAc,oBAAoB,CAAA;AAClC,cAAc,oBAAoB,CAAA;AAElC,iCAAiC;AACjC,cAAc,qBAAqB,CAAA;AACnC,cAAc,oBAAoB,CAAA;AAClC,cAAc,wBAAwB,CAAA"}
|
package/dist/rsc.d.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
* The version of the current Optimizely DXP React SDK
|
|
3
|
-
*/
|
|
4
|
-
export declare const Version = "3.2.2";
|
|
1
|
+
export declare const Version: string;
|
|
5
2
|
export * as Errors from './errors.js';
|
|
6
3
|
export * as Utils from './utilities.js';
|
|
7
4
|
export * from './types.js';
|
|
8
5
|
export * from './factory/index.js';
|
|
6
|
+
export * from './context/types.js';
|
|
9
7
|
export * from './context/rsc.js';
|
|
10
8
|
export * from './components/rsc.js';
|
|
11
9
|
export * from './rsc-utilities.js';
|
package/dist/rsc.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The version of the current Optimizely DXP React SDK
|
|
3
3
|
*/
|
|
4
|
-
|
|
4
|
+
import buildInfo from "./version.json" with { type: "json" };
|
|
5
|
+
export const Version = buildInfo.version;
|
|
5
6
|
// Export library
|
|
6
7
|
export * as Errors from './errors.js';
|
|
7
8
|
export * as Utils from './utilities.js';
|
|
8
9
|
export * from './types.js';
|
|
9
10
|
export * from './factory/index.js';
|
|
11
|
+
export * from './context/types.js';
|
|
10
12
|
// Export React Server Components
|
|
11
13
|
export * from './context/rsc.js';
|
|
12
14
|
export * from './components/rsc.js';
|
package/dist/rsc.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rsc.js","sourceRoot":"","sources":["../src/rsc.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"rsc.js","sourceRoot":"","sources":["../src/rsc.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,SAAS,MAAM,gBAAgB,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAA;AAC5D,MAAM,CAAC,MAAM,OAAO,GAAG,SAAS,CAAC,OAAO,CAAA;AAExC,iBAAiB;AACjB,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AACrC,OAAO,KAAK,KAAK,MAAM,gBAAgB,CAAA;AACvC,cAAc,YAAY,CAAA;AAC1B,cAAc,oBAAoB,CAAA;AAClC,cAAc,oBAAoB,CAAA;AAElC,iCAAiC;AACjC,cAAc,kBAAkB,CAAA;AAChC,cAAc,qBAAqB,CAAA;AACnC,cAAc,oBAAoB,CAAA"}
|
package/dist/types.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { PropsWithChildren, ComponentType as ReactComponentType } from "rea
|
|
|
2
2
|
import type { DocumentNode } from "graphql";
|
|
3
3
|
import type { TypedDocumentNode } from '@graphql-typed-document-node/core';
|
|
4
4
|
import type { ContentLinkWithLocale, ContentLink, InlineContentLinkWithLocale } from "@remkoj/optimizely-graph-client";
|
|
5
|
+
import type { GenericContext } from "./context/types.js";
|
|
5
6
|
export type ContentType = string[];
|
|
6
7
|
export type {
|
|
7
8
|
/**
|
|
@@ -29,6 +30,10 @@ export type CmsComponentProps<T, L extends Record<string, any> = Record<string,
|
|
|
29
30
|
* Contextual layout data, if any
|
|
30
31
|
*/
|
|
31
32
|
layoutProps?: L;
|
|
33
|
+
/**
|
|
34
|
+
* The context in which this component will be rendered
|
|
35
|
+
*/
|
|
36
|
+
ctx?: GenericContext;
|
|
32
37
|
}>;
|
|
33
38
|
export type ContentQueryProps<LocaleType = string> = ContentLink & {
|
|
34
39
|
locale?: Array<LocaleType> | LocaleType | null;
|
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
|
+
"version": "5.0.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,11 +27,11 @@
|
|
|
27
27
|
}
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@remkoj/optimizely-graph-client": "
|
|
30
|
+
"@remkoj/optimizely-graph-client": "5.0.0",
|
|
31
31
|
"@types/crypto-js": "^4.2.2",
|
|
32
|
-
"@types/node": "^22.
|
|
33
|
-
"@types/react": "^18.3.
|
|
34
|
-
"@types/react-dom": "18.3.
|
|
32
|
+
"@types/node": "^22.14.1",
|
|
33
|
+
"@types/react": "^18.3.20",
|
|
34
|
+
"@types/react-dom": "18.3.6",
|
|
35
35
|
"entities": "^6.0.0",
|
|
36
36
|
"graphql": "^16.10.0",
|
|
37
37
|
"graphql-request": "^6.1.0",
|
|
@@ -39,14 +39,14 @@
|
|
|
39
39
|
"react": "^18.3.1",
|
|
40
40
|
"react-dom": "^18.3.1",
|
|
41
41
|
"scheduler": "^0.25.0",
|
|
42
|
-
"typescript": "^5.
|
|
42
|
+
"typescript": "^5.8.3"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"@graphql-typed-document-node/core": "^3.2.0",
|
|
46
46
|
"crypto-js": "^4.2.0"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
|
49
|
-
"@remkoj/optimizely-graph-client": "^
|
|
49
|
+
"@remkoj/optimizely-graph-client": "^5.0.0",
|
|
50
50
|
"entities": "^6",
|
|
51
51
|
"graphql": "^16",
|
|
52
52
|
"graphql-request": "^6",
|