@uniformdev/canvas-react 20.35.0 → 20.35.1-alpha.210
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/index.d.mts +15 -7
- package/dist/index.d.ts +15 -7
- package/dist/index.esm.js +149 -119
- package/dist/index.js +174 -144
- package/dist/index.mjs +149 -119
- package/package.json +10 -10
package/dist/index.d.mts
CHANGED
|
@@ -2,6 +2,7 @@ import React$1, { Key, ReactNode, PropsWithChildren } from 'react';
|
|
|
2
2
|
import { ComponentInstance, RootComponentInstance, UpdateCompositionMessage, getParameterAttributes as getParameterAttributes$1, UpdateContextualEditingStateInternalMessage } from '@uniformdev/canvas';
|
|
3
3
|
export { GetParameterAttributesProps, createUniformApiEnhancer } from '@uniformdev/canvas';
|
|
4
4
|
import { P as PureUniformTextProps } from './PureUniformText-B3GAm6Dc.mjs';
|
|
5
|
+
import { CompositionMetadata } from '@uniformdev/context';
|
|
5
6
|
import { RichTextNode } from '@uniformdev/richtext';
|
|
6
7
|
|
|
7
8
|
/**
|
|
@@ -18,7 +19,7 @@ type ComponentProps<TProps = unknown> = TProps & {
|
|
|
18
19
|
*/
|
|
19
20
|
type RenderComponentResolver = (component: ComponentInstance) => React.ComponentType<ComponentProps<any>> | null;
|
|
20
21
|
/** Function that renders Canvas system internals */
|
|
21
|
-
type SystemRenderFunction = (component: ComponentInstance, key: Key, renderChild: (component: ComponentInstance, key: Key) =>
|
|
22
|
+
type SystemRenderFunction = (component: ComponentInstance, key: Key, renderChild: (component: ComponentInstance, key: Key) => ReactNode | null) => ReactNode | null;
|
|
22
23
|
/** Configures rendering of system components (tests, pz) */
|
|
23
24
|
type SystemRenderConfig = {
|
|
24
25
|
test: SystemRenderFunction;
|
|
@@ -54,7 +55,7 @@ type UniformComponentProps<TRenderProps = unknown> = {
|
|
|
54
55
|
/** Resolves a React component to render a Canvas component, generally by inspecting type/variant */
|
|
55
56
|
resolveRenderer?: RenderComponentResolver;
|
|
56
57
|
/** Children to render. Can also be a function that takes ComponentProps as argument */
|
|
57
|
-
children?: ReactNode | ((props: ComponentProps<TRenderProps>) =>
|
|
58
|
+
children?: ReactNode | ((props: ComponentProps<TRenderProps>) => ReactNode);
|
|
58
59
|
/**
|
|
59
60
|
* When to track behavior from enrichment tags on the current composition
|
|
60
61
|
* onView: adds enrichment score when the visitor views the tagged component in the browser viewport.
|
|
@@ -158,6 +159,13 @@ declare const useUniformContextualEditing: ({ initialCompositionValue, enhance,
|
|
|
158
159
|
name: string;
|
|
159
160
|
value?: string;
|
|
160
161
|
helpText?: string;
|
|
162
|
+
optionsSource?: {
|
|
163
|
+
source: "static";
|
|
164
|
+
options: {
|
|
165
|
+
name: string;
|
|
166
|
+
value: string;
|
|
167
|
+
}[];
|
|
168
|
+
};
|
|
161
169
|
}[];
|
|
162
170
|
previewValue?: string;
|
|
163
171
|
};
|
|
@@ -727,12 +735,12 @@ declare const useUniformContextualEditing: ({ initialCompositionValue, enhance,
|
|
|
727
735
|
isContextualEditing: boolean;
|
|
728
736
|
};
|
|
729
737
|
|
|
730
|
-
type UniformCompositionProps<TRenderProps = unknown> = UniformComponentProps<TRenderProps> & {
|
|
738
|
+
type UniformCompositionProps<TRenderProps = unknown> = UniformComponentProps<TRenderProps> & Omit<CompositionMetadata, 'compositionId'> & {
|
|
731
739
|
/** The composition data */
|
|
732
740
|
data?: RootComponentInstance;
|
|
733
741
|
contextualEditingEnhancer?: UseUniformContextualEditingProps['enhance'];
|
|
734
742
|
};
|
|
735
|
-
type UniformCompositionContextValue = {
|
|
743
|
+
type UniformCompositionContextValue = Omit<CompositionMetadata, 'compositionId'> & {
|
|
736
744
|
data: UniformCompositionProps['data'] | undefined;
|
|
737
745
|
resolveRenderer?: UniformCompositionProps['resolveRenderer'];
|
|
738
746
|
behaviorTracking?: UniformCompositionProps['behaviorTracking'];
|
|
@@ -748,7 +756,7 @@ declare function useUniformCurrentComposition(): UniformCompositionContextValue;
|
|
|
748
756
|
* It renders the full tree of components, and provides some services to the children, such as `useUniformCurrentComposition`.
|
|
749
757
|
* It also takes care of enabling [Contextual Editing](https://docs.uniform.app/capabilities/composition/contextual-editing).
|
|
750
758
|
*/
|
|
751
|
-
declare function UniformComposition<TRenderProps = unknown>({ data, behaviorTracking, children, resolveRenderer, contextualEditingEnhancer, contextualEditingDefaultPlaceholder, }: UniformCompositionProps<TRenderProps>): React$1.JSX.Element;
|
|
759
|
+
declare function UniformComposition<TRenderProps = unknown>({ data, behaviorTracking, children, resolveRenderer, contextualEditingEnhancer, contextualEditingDefaultPlaceholder, matchedRoute, dynamicInputs, }: UniformCompositionProps<TRenderProps>): React$1.JSX.Element;
|
|
752
760
|
|
|
753
761
|
type UniformPlaygroundDecorator = (props: {
|
|
754
762
|
/** The rendered component instance, needs to be wrapped and rendered by the decorator */
|
|
@@ -841,7 +849,7 @@ type CustomSlotChildRenderFunc = (options: {
|
|
|
841
849
|
child: ReactNode;
|
|
842
850
|
component: ComponentInstance;
|
|
843
851
|
key: Key;
|
|
844
|
-
}) =>
|
|
852
|
+
}) => ReactNode;
|
|
845
853
|
type UniformSlotWrapperComponentProps = {
|
|
846
854
|
items: ReactNode[];
|
|
847
855
|
slotName: string;
|
|
@@ -867,7 +875,7 @@ type UniformSlotProps<TSlotNames extends string> = {
|
|
|
867
875
|
emptyPlaceholder?: React$1.ReactNode;
|
|
868
876
|
};
|
|
869
877
|
/** Renders a named Slot within a Composition. */
|
|
870
|
-
declare function UniformSlot<TSlotNames extends string = string>({ name, resolveRenderer, emptyPlaceholder, wrapperComponent, }: UniformSlotProps<TSlotNames>):
|
|
878
|
+
declare function UniformSlot<TSlotNames extends string = string>({ name, resolveRenderer, emptyPlaceholder, wrapperComponent, }: UniformSlotProps<TSlotNames>): ReactNode | null;
|
|
871
879
|
|
|
872
880
|
/**
|
|
873
881
|
* Converts a raw Canvas component instance to React component props format.
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import React$1, { Key, ReactNode, PropsWithChildren } from 'react';
|
|
|
2
2
|
import { ComponentInstance, RootComponentInstance, UpdateCompositionMessage, getParameterAttributes as getParameterAttributes$1, UpdateContextualEditingStateInternalMessage } from '@uniformdev/canvas';
|
|
3
3
|
export { GetParameterAttributesProps, createUniformApiEnhancer } from '@uniformdev/canvas';
|
|
4
4
|
import { P as PureUniformTextProps } from './PureUniformText-B3GAm6Dc.js';
|
|
5
|
+
import { CompositionMetadata } from '@uniformdev/context';
|
|
5
6
|
import { RichTextNode } from '@uniformdev/richtext';
|
|
6
7
|
|
|
7
8
|
/**
|
|
@@ -18,7 +19,7 @@ type ComponentProps<TProps = unknown> = TProps & {
|
|
|
18
19
|
*/
|
|
19
20
|
type RenderComponentResolver = (component: ComponentInstance) => React.ComponentType<ComponentProps<any>> | null;
|
|
20
21
|
/** Function that renders Canvas system internals */
|
|
21
|
-
type SystemRenderFunction = (component: ComponentInstance, key: Key, renderChild: (component: ComponentInstance, key: Key) =>
|
|
22
|
+
type SystemRenderFunction = (component: ComponentInstance, key: Key, renderChild: (component: ComponentInstance, key: Key) => ReactNode | null) => ReactNode | null;
|
|
22
23
|
/** Configures rendering of system components (tests, pz) */
|
|
23
24
|
type SystemRenderConfig = {
|
|
24
25
|
test: SystemRenderFunction;
|
|
@@ -54,7 +55,7 @@ type UniformComponentProps<TRenderProps = unknown> = {
|
|
|
54
55
|
/** Resolves a React component to render a Canvas component, generally by inspecting type/variant */
|
|
55
56
|
resolveRenderer?: RenderComponentResolver;
|
|
56
57
|
/** Children to render. Can also be a function that takes ComponentProps as argument */
|
|
57
|
-
children?: ReactNode | ((props: ComponentProps<TRenderProps>) =>
|
|
58
|
+
children?: ReactNode | ((props: ComponentProps<TRenderProps>) => ReactNode);
|
|
58
59
|
/**
|
|
59
60
|
* When to track behavior from enrichment tags on the current composition
|
|
60
61
|
* onView: adds enrichment score when the visitor views the tagged component in the browser viewport.
|
|
@@ -158,6 +159,13 @@ declare const useUniformContextualEditing: ({ initialCompositionValue, enhance,
|
|
|
158
159
|
name: string;
|
|
159
160
|
value?: string;
|
|
160
161
|
helpText?: string;
|
|
162
|
+
optionsSource?: {
|
|
163
|
+
source: "static";
|
|
164
|
+
options: {
|
|
165
|
+
name: string;
|
|
166
|
+
value: string;
|
|
167
|
+
}[];
|
|
168
|
+
};
|
|
161
169
|
}[];
|
|
162
170
|
previewValue?: string;
|
|
163
171
|
};
|
|
@@ -727,12 +735,12 @@ declare const useUniformContextualEditing: ({ initialCompositionValue, enhance,
|
|
|
727
735
|
isContextualEditing: boolean;
|
|
728
736
|
};
|
|
729
737
|
|
|
730
|
-
type UniformCompositionProps<TRenderProps = unknown> = UniformComponentProps<TRenderProps> & {
|
|
738
|
+
type UniformCompositionProps<TRenderProps = unknown> = UniformComponentProps<TRenderProps> & Omit<CompositionMetadata, 'compositionId'> & {
|
|
731
739
|
/** The composition data */
|
|
732
740
|
data?: RootComponentInstance;
|
|
733
741
|
contextualEditingEnhancer?: UseUniformContextualEditingProps['enhance'];
|
|
734
742
|
};
|
|
735
|
-
type UniformCompositionContextValue = {
|
|
743
|
+
type UniformCompositionContextValue = Omit<CompositionMetadata, 'compositionId'> & {
|
|
736
744
|
data: UniformCompositionProps['data'] | undefined;
|
|
737
745
|
resolveRenderer?: UniformCompositionProps['resolveRenderer'];
|
|
738
746
|
behaviorTracking?: UniformCompositionProps['behaviorTracking'];
|
|
@@ -748,7 +756,7 @@ declare function useUniformCurrentComposition(): UniformCompositionContextValue;
|
|
|
748
756
|
* It renders the full tree of components, and provides some services to the children, such as `useUniformCurrentComposition`.
|
|
749
757
|
* It also takes care of enabling [Contextual Editing](https://docs.uniform.app/capabilities/composition/contextual-editing).
|
|
750
758
|
*/
|
|
751
|
-
declare function UniformComposition<TRenderProps = unknown>({ data, behaviorTracking, children, resolveRenderer, contextualEditingEnhancer, contextualEditingDefaultPlaceholder, }: UniformCompositionProps<TRenderProps>): React$1.JSX.Element;
|
|
759
|
+
declare function UniformComposition<TRenderProps = unknown>({ data, behaviorTracking, children, resolveRenderer, contextualEditingEnhancer, contextualEditingDefaultPlaceholder, matchedRoute, dynamicInputs, }: UniformCompositionProps<TRenderProps>): React$1.JSX.Element;
|
|
752
760
|
|
|
753
761
|
type UniformPlaygroundDecorator = (props: {
|
|
754
762
|
/** The rendered component instance, needs to be wrapped and rendered by the decorator */
|
|
@@ -841,7 +849,7 @@ type CustomSlotChildRenderFunc = (options: {
|
|
|
841
849
|
child: ReactNode;
|
|
842
850
|
component: ComponentInstance;
|
|
843
851
|
key: Key;
|
|
844
|
-
}) =>
|
|
852
|
+
}) => ReactNode;
|
|
845
853
|
type UniformSlotWrapperComponentProps = {
|
|
846
854
|
items: ReactNode[];
|
|
847
855
|
slotName: string;
|
|
@@ -867,7 +875,7 @@ type UniformSlotProps<TSlotNames extends string> = {
|
|
|
867
875
|
emptyPlaceholder?: React$1.ReactNode;
|
|
868
876
|
};
|
|
869
877
|
/** Renders a named Slot within a Composition. */
|
|
870
|
-
declare function UniformSlot<TSlotNames extends string = string>({ name, resolveRenderer, emptyPlaceholder, wrapperComponent, }: UniformSlotProps<TSlotNames>):
|
|
878
|
+
declare function UniformSlot<TSlotNames extends string = string>({ name, resolveRenderer, emptyPlaceholder, wrapperComponent, }: UniformSlotProps<TSlotNames>): ReactNode | null;
|
|
871
879
|
|
|
872
880
|
/**
|
|
873
881
|
* Converts a raw Canvas component instance to React component props format.
|
package/dist/index.esm.js
CHANGED
|
@@ -77,7 +77,7 @@ registerUniformComponent({ type: "${componentType}", component: ${proposedFileNa
|
|
|
77
77
|
import {
|
|
78
78
|
CANVAS_ENRICHMENT_TAG_PARAM
|
|
79
79
|
} from "@uniformdev/canvas";
|
|
80
|
-
import { Track, TrackFragment, useUniformContext } from "@uniformdev/context-react";
|
|
80
|
+
import { Track, TrackFragment, useUniformContext as useUniformContext2 } from "@uniformdev/context-react";
|
|
81
81
|
import React7, { createContext as createContext2, useContext as useContext2 } from "react";
|
|
82
82
|
|
|
83
83
|
// src/helpers/convertComponentToProps.ts
|
|
@@ -155,87 +155,11 @@ import {
|
|
|
155
155
|
mapSlotToTestVariations
|
|
156
156
|
} from "@uniformdev/canvas";
|
|
157
157
|
import { Personalize, Test } from "@uniformdev/context-react";
|
|
158
|
-
import * as
|
|
159
|
-
var defaultSystemComponentResolver = {
|
|
160
|
-
test: (component, key, renderChild) => {
|
|
161
|
-
var _a, _b, _c, _d, _e;
|
|
162
|
-
const testComponent = component;
|
|
163
|
-
const variants = (_b = (_a = testComponent.slots) == null ? void 0 : _a.test) != null ? _b : [];
|
|
164
|
-
const testName = (_e = (_d = (_c = testComponent.parameters) == null ? void 0 : _c.test) == null ? void 0 : _d.value) != null ? _e : "Untitled Test";
|
|
165
|
-
const finalVariants = mapSlotToTestVariations(variants);
|
|
166
|
-
return /* @__PURE__ */ React2.createElement(
|
|
167
|
-
Test,
|
|
168
|
-
{
|
|
169
|
-
key,
|
|
170
|
-
variations: finalVariants,
|
|
171
|
-
name: testName,
|
|
172
|
-
component: (variation) => renderChild(variation, key)
|
|
173
|
-
}
|
|
174
|
-
);
|
|
175
|
-
},
|
|
176
|
-
personalization: (component, key, renderChild) => {
|
|
177
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
178
|
-
const pzComponent = component;
|
|
179
|
-
const processedVariants = mapSlotToPersonalizedVariations((_a = pzComponent == null ? void 0 : pzComponent.slots) == null ? void 0 : _a.pz);
|
|
180
|
-
return /* @__PURE__ */ React2.createElement(
|
|
181
|
-
Personalize,
|
|
182
|
-
{
|
|
183
|
-
key,
|
|
184
|
-
variations: processedVariants,
|
|
185
|
-
count: Number((_d = (_c = (_b = pzComponent.parameters) == null ? void 0 : _b[CANVAS_PERSONALIZATION_TAKE_PARAM]) == null ? void 0 : _c.value) != null ? _d : 1),
|
|
186
|
-
name: (_g = (_f = (_e = pzComponent.parameters) == null ? void 0 : _e[CANVAS_PERSONALIZATION_EVENT_NAME_PARAM]) == null ? void 0 : _f.value) != null ? _g : "Untitled Personalization",
|
|
187
|
-
component: (variation) => renderChild(variation, 0),
|
|
188
|
-
algorithm: (_i = (_h = pzComponent.parameters) == null ? void 0 : _h[CANVAS_PERSONALIZATION_ALGORITHM_PARAM]) == null ? void 0 : _i.value
|
|
189
|
-
}
|
|
190
|
-
);
|
|
191
|
-
}
|
|
192
|
-
};
|
|
193
|
-
|
|
194
|
-
// src/components/ContextualEditingComponentWrapper.tsx
|
|
195
|
-
import {
|
|
196
|
-
isComponentPlaceholderId
|
|
197
|
-
} from "@uniformdev/canvas";
|
|
198
|
-
import React5 from "react";
|
|
199
|
-
|
|
200
|
-
// src/components/PureContextualEditingComponentWrapper.tsx
|
|
201
|
-
import {
|
|
202
|
-
CANVAS_LOCALE_TAG_PARAM,
|
|
203
|
-
IN_CONTEXT_EDITOR_COMPONENT_END_ROLE,
|
|
204
|
-
IN_CONTEXT_EDITOR_COMPONENT_START_ROLE
|
|
205
|
-
} from "@uniformdev/canvas";
|
|
206
|
-
import React3 from "react";
|
|
207
|
-
var PureContextualEditingComponentWrapper = ({
|
|
208
|
-
children,
|
|
209
|
-
isPlaceholder,
|
|
210
|
-
parentComponent,
|
|
211
|
-
component,
|
|
212
|
-
slotName,
|
|
213
|
-
indexInSlot,
|
|
214
|
-
slotChildrenCount,
|
|
215
|
-
isReadOnly
|
|
216
|
-
}) => {
|
|
217
|
-
var _a, _b, _c, _d;
|
|
218
|
-
return /* @__PURE__ */ React3.createElement(React3.Fragment, null, /* @__PURE__ */ React3.createElement(
|
|
219
|
-
"script",
|
|
220
|
-
{
|
|
221
|
-
"data-role": IN_CONTEXT_EDITOR_COMPONENT_START_ROLE,
|
|
222
|
-
"data-parent-id": parentComponent == null ? void 0 : parentComponent._id,
|
|
223
|
-
"data-parent-type": parentComponent == null ? void 0 : parentComponent.type,
|
|
224
|
-
"data-component-id": component == null ? void 0 : component._id,
|
|
225
|
-
"data-slot-name": slotName != null ? slotName : "",
|
|
226
|
-
"data-component-index": indexInSlot != null ? indexInSlot : "",
|
|
227
|
-
"data-total-components": slotChildrenCount != null ? slotChildrenCount : "",
|
|
228
|
-
"data-component-name": component == null ? void 0 : component.type,
|
|
229
|
-
"data-is-placeholder": isPlaceholder ? "true" : void 0,
|
|
230
|
-
"data-is-localized": ((_a = component == null ? void 0 : component.parameters) == null ? void 0 : _a[CANVAS_LOCALE_TAG_PARAM]) ? "true" : void 0,
|
|
231
|
-
"data-component-title": (_d = (_c = (_b = component == null ? void 0 : component.parameters) == null ? void 0 : _b.title) == null ? void 0 : _c.value) != null ? _d : "",
|
|
232
|
-
"data-is-readonly": isReadOnly
|
|
233
|
-
}
|
|
234
|
-
), children, /* @__PURE__ */ React3.createElement("script", { "data-role": IN_CONTEXT_EDITOR_COMPONENT_END_ROLE }));
|
|
235
|
-
};
|
|
158
|
+
import * as React5 from "react";
|
|
236
159
|
|
|
237
160
|
// src/components/UniformComposition.tsx
|
|
238
|
-
import
|
|
161
|
+
import { useUniformContext } from "@uniformdev/context-react";
|
|
162
|
+
import React4, { createContext, useContext, useEffect as useEffect2 } from "react";
|
|
239
163
|
|
|
240
164
|
// src/hooks/useClientConditionsComposition.ts
|
|
241
165
|
import {
|
|
@@ -299,7 +223,7 @@ var useUniformContextualEditing = ({
|
|
|
299
223
|
enhance = (message) => message.composition
|
|
300
224
|
}) => {
|
|
301
225
|
const [contextualComposition, setContextualComposition] = useState();
|
|
302
|
-
const latestEventTimeStamp = useRef();
|
|
226
|
+
const latestEventTimeStamp = useRef(void 0);
|
|
303
227
|
const channel = useMemo3(() => {
|
|
304
228
|
var _a;
|
|
305
229
|
if (!isInContextEditingMode()) {
|
|
@@ -375,6 +299,84 @@ function isInContextEditingMode() {
|
|
|
375
299
|
return isOpenedByInContextEditor && isAllowedReferrer(window.document.referrer);
|
|
376
300
|
}
|
|
377
301
|
|
|
302
|
+
// src/components/ContextualEditingComponentWrapper.tsx
|
|
303
|
+
import {
|
|
304
|
+
isComponentPlaceholderId
|
|
305
|
+
} from "@uniformdev/canvas";
|
|
306
|
+
import React3 from "react";
|
|
307
|
+
|
|
308
|
+
// src/components/PureContextualEditingComponentWrapper.tsx
|
|
309
|
+
import {
|
|
310
|
+
CANVAS_LOCALE_TAG_PARAM,
|
|
311
|
+
IN_CONTEXT_EDITOR_COMPONENT_END_ROLE,
|
|
312
|
+
IN_CONTEXT_EDITOR_COMPONENT_START_ROLE
|
|
313
|
+
} from "@uniformdev/canvas";
|
|
314
|
+
import React2 from "react";
|
|
315
|
+
var PureContextualEditingComponentWrapper = ({
|
|
316
|
+
children,
|
|
317
|
+
isPlaceholder,
|
|
318
|
+
parentComponent,
|
|
319
|
+
component,
|
|
320
|
+
slotName,
|
|
321
|
+
indexInSlot,
|
|
322
|
+
slotChildrenCount,
|
|
323
|
+
isReadOnly
|
|
324
|
+
}) => {
|
|
325
|
+
var _a, _b, _c, _d;
|
|
326
|
+
return /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement(
|
|
327
|
+
"script",
|
|
328
|
+
{
|
|
329
|
+
"data-role": IN_CONTEXT_EDITOR_COMPONENT_START_ROLE,
|
|
330
|
+
"data-parent-id": parentComponent == null ? void 0 : parentComponent._id,
|
|
331
|
+
"data-parent-type": parentComponent == null ? void 0 : parentComponent.type,
|
|
332
|
+
"data-component-id": component == null ? void 0 : component._id,
|
|
333
|
+
"data-slot-name": slotName != null ? slotName : "",
|
|
334
|
+
"data-component-index": indexInSlot != null ? indexInSlot : "",
|
|
335
|
+
"data-total-components": slotChildrenCount != null ? slotChildrenCount : "",
|
|
336
|
+
"data-component-name": component == null ? void 0 : component.type,
|
|
337
|
+
"data-is-placeholder": isPlaceholder ? "true" : void 0,
|
|
338
|
+
"data-is-localized": ((_a = component == null ? void 0 : component.parameters) == null ? void 0 : _a[CANVAS_LOCALE_TAG_PARAM]) ? "true" : void 0,
|
|
339
|
+
"data-component-title": (_d = (_c = (_b = component == null ? void 0 : component.parameters) == null ? void 0 : _b.title) == null ? void 0 : _c.value) != null ? _d : "",
|
|
340
|
+
"data-is-readonly": isReadOnly
|
|
341
|
+
}
|
|
342
|
+
), children, /* @__PURE__ */ React2.createElement("script", { "data-role": IN_CONTEXT_EDITOR_COMPONENT_END_ROLE }));
|
|
343
|
+
};
|
|
344
|
+
|
|
345
|
+
// src/components/ContextualEditingComponentWrapper.tsx
|
|
346
|
+
function ContextualEditingComponentWrapper({
|
|
347
|
+
component,
|
|
348
|
+
parentComponent,
|
|
349
|
+
slotName,
|
|
350
|
+
indexInSlot,
|
|
351
|
+
slotChildrenCount,
|
|
352
|
+
emptyPlaceholder,
|
|
353
|
+
children
|
|
354
|
+
}) {
|
|
355
|
+
var _a;
|
|
356
|
+
const isPlaceholder = isComponentPlaceholderId(component == null ? void 0 : component._id);
|
|
357
|
+
const { isContextualEditing } = useUniformCurrentComposition();
|
|
358
|
+
const isReadOnly = ((_a = component == null ? void 0 : component._contextualEditing) == null ? void 0 : _a.isEditable) ? void 0 : "true";
|
|
359
|
+
if (!isContextualEditing) {
|
|
360
|
+
return /* @__PURE__ */ React3.createElement(React3.Fragment, null, children);
|
|
361
|
+
}
|
|
362
|
+
if (isPlaceholder && emptyPlaceholder === null) {
|
|
363
|
+
return null;
|
|
364
|
+
}
|
|
365
|
+
return /* @__PURE__ */ React3.createElement(
|
|
366
|
+
PureContextualEditingComponentWrapper,
|
|
367
|
+
{
|
|
368
|
+
isPlaceholder,
|
|
369
|
+
parentComponent,
|
|
370
|
+
component,
|
|
371
|
+
slotName,
|
|
372
|
+
indexInSlot,
|
|
373
|
+
slotChildrenCount,
|
|
374
|
+
isReadOnly
|
|
375
|
+
},
|
|
376
|
+
isPlaceholder && emptyPlaceholder !== void 0 ? emptyPlaceholder : children
|
|
377
|
+
);
|
|
378
|
+
}
|
|
379
|
+
|
|
378
380
|
// src/components/UniformComposition.tsx
|
|
379
381
|
var UniformCompositionContext = createContext({
|
|
380
382
|
data: void 0,
|
|
@@ -389,8 +391,21 @@ function UniformComposition({
|
|
|
389
391
|
children,
|
|
390
392
|
resolveRenderer,
|
|
391
393
|
contextualEditingEnhancer,
|
|
392
|
-
contextualEditingDefaultPlaceholder
|
|
394
|
+
contextualEditingDefaultPlaceholder,
|
|
395
|
+
// provide default non-undefined values to avoid serialization issues
|
|
396
|
+
matchedRoute = "",
|
|
397
|
+
dynamicInputs = {}
|
|
393
398
|
}) {
|
|
399
|
+
const maybeContext = useUniformContext({ throwOnMissingProvider: false });
|
|
400
|
+
useEffect2(() => {
|
|
401
|
+
if ((maybeContext == null ? void 0 : maybeContext.context) && (data == null ? void 0 : data._id)) {
|
|
402
|
+
maybeContext.context.updateCompositionMetadata({
|
|
403
|
+
compositionId: data._id,
|
|
404
|
+
matchedRoute,
|
|
405
|
+
dynamicInputs
|
|
406
|
+
});
|
|
407
|
+
}
|
|
408
|
+
}, [data == null ? void 0 : data._id, maybeContext == null ? void 0 : maybeContext.context, matchedRoute, dynamicInputs]);
|
|
394
409
|
const ruledComposition = useClientConditionsComposition(data);
|
|
395
410
|
const { composition, isContextualEditing } = useUniformContextualEditing({
|
|
396
411
|
initialCompositionValue: ruledComposition,
|
|
@@ -399,7 +414,14 @@ function UniformComposition({
|
|
|
399
414
|
return /* @__PURE__ */ React4.createElement(
|
|
400
415
|
UniformCompositionContext.Provider,
|
|
401
416
|
{
|
|
402
|
-
value: {
|
|
417
|
+
value: {
|
|
418
|
+
data: composition,
|
|
419
|
+
behaviorTracking,
|
|
420
|
+
resolveRenderer,
|
|
421
|
+
isContextualEditing,
|
|
422
|
+
matchedRoute,
|
|
423
|
+
dynamicInputs
|
|
424
|
+
}
|
|
403
425
|
},
|
|
404
426
|
/* @__PURE__ */ React4.createElement(ContextualEditingComponentWrapper, { component: composition }, /* @__PURE__ */ React4.createElement(
|
|
405
427
|
UniformComponent,
|
|
@@ -414,40 +436,48 @@ function UniformComposition({
|
|
|
414
436
|
);
|
|
415
437
|
}
|
|
416
438
|
|
|
417
|
-
// src/
|
|
418
|
-
|
|
419
|
-
component,
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
439
|
+
// src/defaultSystemComponentResolver.tsx
|
|
440
|
+
var defaultSystemComponentResolver = {
|
|
441
|
+
test: function TestComponent(component, key, renderChild) {
|
|
442
|
+
var _a, _b, _c, _d, _e;
|
|
443
|
+
const testComponent = component;
|
|
444
|
+
const variants = (_b = (_a = testComponent.slots) == null ? void 0 : _a.test) != null ? _b : [];
|
|
445
|
+
const testName = (_e = (_d = (_c = testComponent.parameters) == null ? void 0 : _c.test) == null ? void 0 : _d.value) != null ? _e : "Untitled Test";
|
|
446
|
+
const finalVariants = mapSlotToTestVariations(variants);
|
|
447
|
+
const { data, matchedRoute, dynamicInputs } = useUniformCurrentComposition();
|
|
448
|
+
return /* @__PURE__ */ React5.createElement(
|
|
449
|
+
Test,
|
|
450
|
+
{
|
|
451
|
+
key,
|
|
452
|
+
variations: finalVariants,
|
|
453
|
+
name: testName,
|
|
454
|
+
component: (variation) => renderChild(variation, key),
|
|
455
|
+
compositionMetadata: (data == null ? void 0 : data._id) ? { compositionId: data._id, matchedRoute, dynamicInputs } : void 0
|
|
456
|
+
}
|
|
457
|
+
);
|
|
458
|
+
},
|
|
459
|
+
personalization: function PersonalizeComponent(component, key, renderChild) {
|
|
460
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
461
|
+
const pzComponent = component;
|
|
462
|
+
const processedVariants = mapSlotToPersonalizedVariations((_a = pzComponent == null ? void 0 : pzComponent.slots) == null ? void 0 : _a.pz);
|
|
463
|
+
const { data, matchedRoute, dynamicInputs } = useUniformCurrentComposition();
|
|
464
|
+
return /* @__PURE__ */ React5.createElement(
|
|
465
|
+
Personalize,
|
|
466
|
+
{
|
|
467
|
+
key,
|
|
468
|
+
variations: processedVariants,
|
|
469
|
+
count: Number((_d = (_c = (_b = pzComponent.parameters) == null ? void 0 : _b[CANVAS_PERSONALIZATION_TAKE_PARAM]) == null ? void 0 : _c.value) != null ? _d : 1),
|
|
470
|
+
name: (_g = (_f = (_e = pzComponent.parameters) == null ? void 0 : _e[CANVAS_PERSONALIZATION_EVENT_NAME_PARAM]) == null ? void 0 : _f.value) != null ? _g : "Untitled Personalization",
|
|
471
|
+
component: (variation) => renderChild(variation, 0),
|
|
472
|
+
compositionMetadata: (data == null ? void 0 : data._id) ? { compositionId: data._id, matchedRoute, dynamicInputs } : void 0,
|
|
473
|
+
algorithm: (_i = (_h = pzComponent.parameters) == null ? void 0 : _h[CANVAS_PERSONALIZATION_ALGORITHM_PARAM]) == null ? void 0 : _i.value,
|
|
474
|
+
compositionId: data == null ? void 0 : data._id,
|
|
475
|
+
matchedRoute,
|
|
476
|
+
dynamicInputs
|
|
477
|
+
}
|
|
478
|
+
);
|
|
436
479
|
}
|
|
437
|
-
|
|
438
|
-
PureContextualEditingComponentWrapper,
|
|
439
|
-
{
|
|
440
|
-
isPlaceholder,
|
|
441
|
-
parentComponent,
|
|
442
|
-
component,
|
|
443
|
-
slotName,
|
|
444
|
-
indexInSlot,
|
|
445
|
-
slotChildrenCount,
|
|
446
|
-
isReadOnly
|
|
447
|
-
},
|
|
448
|
-
isPlaceholder && emptyPlaceholder !== void 0 ? emptyPlaceholder : children
|
|
449
|
-
);
|
|
450
|
-
}
|
|
480
|
+
};
|
|
451
481
|
|
|
452
482
|
// src/components/UniformSlot.tsx
|
|
453
483
|
function UniformSlot({
|
|
@@ -602,7 +632,7 @@ function UniformComponent({
|
|
|
602
632
|
}) {
|
|
603
633
|
var _a, _b, _c;
|
|
604
634
|
const parentData = useUniformCurrentComponent();
|
|
605
|
-
const contextContextProviderPresent =
|
|
635
|
+
const contextContextProviderPresent = useUniformContext2({ throwOnMissingProvider: false }) !== void 0;
|
|
606
636
|
if (!data) {
|
|
607
637
|
if (process.env.NODE_ENV === "development") {
|
|
608
638
|
console.warn(`[canvas-dev] UniformComponent was rendered with no data, nothing will be output.`);
|
|
@@ -987,7 +1017,7 @@ import {
|
|
|
987
1017
|
createCanvasChannel as createCanvasChannel2,
|
|
988
1018
|
isUpdateContextualEditingStateInternalMessage
|
|
989
1019
|
} from "@uniformdev/canvas";
|
|
990
|
-
import { useEffect as
|
|
1020
|
+
import { useEffect as useEffect3, useMemo as useMemo5, useState as useState3 } from "react";
|
|
991
1021
|
var useUniformContextualEditingState = ({
|
|
992
1022
|
global = false
|
|
993
1023
|
} = {}) => {
|
|
@@ -1007,7 +1037,7 @@ var useUniformContextualEditingState = ({
|
|
|
1007
1037
|
});
|
|
1008
1038
|
return channel2;
|
|
1009
1039
|
}, [isContextualEditing]);
|
|
1010
|
-
|
|
1040
|
+
useEffect3(() => {
|
|
1011
1041
|
var _a, _b;
|
|
1012
1042
|
if (!channel) {
|
|
1013
1043
|
return;
|
package/dist/index.js
CHANGED
|
@@ -46,7 +46,7 @@ __export(src_exports, {
|
|
|
46
46
|
convertComponentToProps: () => convertComponentToProps,
|
|
47
47
|
createComponentStore: () => createComponentStore,
|
|
48
48
|
createComponentStoreResolver: () => createComponentStoreResolver,
|
|
49
|
-
createUniformApiEnhancer: () =>
|
|
49
|
+
createUniformApiEnhancer: () => import_canvas4.createUniformApiEnhancer,
|
|
50
50
|
getParameterAttributes: () => getParameterAttributes,
|
|
51
51
|
registerUniformComponent: () => registerUniformComponent,
|
|
52
52
|
useUniformContextualEditing: () => useUniformContextualEditing,
|
|
@@ -131,7 +131,7 @@ registerUniformComponent({ type: "${componentType}", component: ${proposedFileNa
|
|
|
131
131
|
|
|
132
132
|
// src/components/UniformComponent.tsx
|
|
133
133
|
var import_canvas9 = require("@uniformdev/canvas");
|
|
134
|
-
var
|
|
134
|
+
var import_context_react4 = require("@uniformdev/context-react");
|
|
135
135
|
var import_react9 = __toESM(require("react"));
|
|
136
136
|
|
|
137
137
|
// src/helpers/convertComponentToProps.ts
|
|
@@ -195,98 +195,28 @@ var import_canvas8 = require("@uniformdev/canvas");
|
|
|
195
195
|
var import_react8 = __toESM(require("react"));
|
|
196
196
|
|
|
197
197
|
// src/defaultSystemComponentResolver.tsx
|
|
198
|
-
var import_canvas2 = require("@uniformdev/canvas");
|
|
199
|
-
var import_context_react = require("@uniformdev/context-react");
|
|
200
|
-
var React2 = __toESM(require("react"));
|
|
201
|
-
var defaultSystemComponentResolver = {
|
|
202
|
-
test: (component, key, renderChild) => {
|
|
203
|
-
var _a, _b, _c, _d, _e;
|
|
204
|
-
const testComponent = component;
|
|
205
|
-
const variants = (_b = (_a = testComponent.slots) == null ? void 0 : _a.test) != null ? _b : [];
|
|
206
|
-
const testName = (_e = (_d = (_c = testComponent.parameters) == null ? void 0 : _c.test) == null ? void 0 : _d.value) != null ? _e : "Untitled Test";
|
|
207
|
-
const finalVariants = (0, import_canvas2.mapSlotToTestVariations)(variants);
|
|
208
|
-
return /* @__PURE__ */ React2.createElement(
|
|
209
|
-
import_context_react.Test,
|
|
210
|
-
{
|
|
211
|
-
key,
|
|
212
|
-
variations: finalVariants,
|
|
213
|
-
name: testName,
|
|
214
|
-
component: (variation) => renderChild(variation, key)
|
|
215
|
-
}
|
|
216
|
-
);
|
|
217
|
-
},
|
|
218
|
-
personalization: (component, key, renderChild) => {
|
|
219
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
220
|
-
const pzComponent = component;
|
|
221
|
-
const processedVariants = (0, import_canvas2.mapSlotToPersonalizedVariations)((_a = pzComponent == null ? void 0 : pzComponent.slots) == null ? void 0 : _a.pz);
|
|
222
|
-
return /* @__PURE__ */ React2.createElement(
|
|
223
|
-
import_context_react.Personalize,
|
|
224
|
-
{
|
|
225
|
-
key,
|
|
226
|
-
variations: processedVariants,
|
|
227
|
-
count: Number((_d = (_c = (_b = pzComponent.parameters) == null ? void 0 : _b[import_canvas2.CANVAS_PERSONALIZATION_TAKE_PARAM]) == null ? void 0 : _c.value) != null ? _d : 1),
|
|
228
|
-
name: (_g = (_f = (_e = pzComponent.parameters) == null ? void 0 : _e[import_canvas2.CANVAS_PERSONALIZATION_EVENT_NAME_PARAM]) == null ? void 0 : _f.value) != null ? _g : "Untitled Personalization",
|
|
229
|
-
component: (variation) => renderChild(variation, 0),
|
|
230
|
-
algorithm: (_i = (_h = pzComponent.parameters) == null ? void 0 : _h[import_canvas2.CANVAS_PERSONALIZATION_ALGORITHM_PARAM]) == null ? void 0 : _i.value
|
|
231
|
-
}
|
|
232
|
-
);
|
|
233
|
-
}
|
|
234
|
-
};
|
|
235
|
-
|
|
236
|
-
// src/components/ContextualEditingComponentWrapper.tsx
|
|
237
198
|
var import_canvas7 = require("@uniformdev/canvas");
|
|
238
|
-
var
|
|
239
|
-
|
|
240
|
-
// src/components/PureContextualEditingComponentWrapper.tsx
|
|
241
|
-
var import_canvas3 = require("@uniformdev/canvas");
|
|
242
|
-
var import_react2 = __toESM(require("react"));
|
|
243
|
-
var PureContextualEditingComponentWrapper = ({
|
|
244
|
-
children,
|
|
245
|
-
isPlaceholder,
|
|
246
|
-
parentComponent,
|
|
247
|
-
component,
|
|
248
|
-
slotName,
|
|
249
|
-
indexInSlot,
|
|
250
|
-
slotChildrenCount,
|
|
251
|
-
isReadOnly
|
|
252
|
-
}) => {
|
|
253
|
-
var _a, _b, _c, _d;
|
|
254
|
-
return /* @__PURE__ */ import_react2.default.createElement(import_react2.default.Fragment, null, /* @__PURE__ */ import_react2.default.createElement(
|
|
255
|
-
"script",
|
|
256
|
-
{
|
|
257
|
-
"data-role": import_canvas3.IN_CONTEXT_EDITOR_COMPONENT_START_ROLE,
|
|
258
|
-
"data-parent-id": parentComponent == null ? void 0 : parentComponent._id,
|
|
259
|
-
"data-parent-type": parentComponent == null ? void 0 : parentComponent.type,
|
|
260
|
-
"data-component-id": component == null ? void 0 : component._id,
|
|
261
|
-
"data-slot-name": slotName != null ? slotName : "",
|
|
262
|
-
"data-component-index": indexInSlot != null ? indexInSlot : "",
|
|
263
|
-
"data-total-components": slotChildrenCount != null ? slotChildrenCount : "",
|
|
264
|
-
"data-component-name": component == null ? void 0 : component.type,
|
|
265
|
-
"data-is-placeholder": isPlaceholder ? "true" : void 0,
|
|
266
|
-
"data-is-localized": ((_a = component == null ? void 0 : component.parameters) == null ? void 0 : _a[import_canvas3.CANVAS_LOCALE_TAG_PARAM]) ? "true" : void 0,
|
|
267
|
-
"data-component-title": (_d = (_c = (_b = component == null ? void 0 : component.parameters) == null ? void 0 : _b.title) == null ? void 0 : _c.value) != null ? _d : "",
|
|
268
|
-
"data-is-readonly": isReadOnly
|
|
269
|
-
}
|
|
270
|
-
), children, /* @__PURE__ */ import_react2.default.createElement("script", { "data-role": import_canvas3.IN_CONTEXT_EDITOR_COMPONENT_END_ROLE }));
|
|
271
|
-
};
|
|
199
|
+
var import_context_react3 = require("@uniformdev/context-react");
|
|
200
|
+
var React5 = __toESM(require("react"));
|
|
272
201
|
|
|
273
202
|
// src/components/UniformComposition.tsx
|
|
274
|
-
var
|
|
203
|
+
var import_context_react2 = require("@uniformdev/context-react");
|
|
204
|
+
var import_react7 = __toESM(require("react"));
|
|
275
205
|
|
|
276
206
|
// src/hooks/useClientConditionsComposition.ts
|
|
277
|
-
var
|
|
207
|
+
var import_canvas3 = require("@uniformdev/canvas");
|
|
278
208
|
var import_immer = require("immer");
|
|
279
|
-
var
|
|
209
|
+
var import_react3 = require("react");
|
|
280
210
|
|
|
281
211
|
// src/hooks/useClientVisibilityRules.ts
|
|
282
|
-
var
|
|
283
|
-
var
|
|
284
|
-
var
|
|
212
|
+
var import_canvas2 = require("@uniformdev/canvas");
|
|
213
|
+
var import_context_react = require("@uniformdev/context-react");
|
|
214
|
+
var import_react2 = require("react");
|
|
285
215
|
function useClientVisibilityRules() {
|
|
286
|
-
const quirks = (0,
|
|
287
|
-
return (0,
|
|
216
|
+
const quirks = (0, import_context_react.useQuirks)({ throwOnMissingProvider: false });
|
|
217
|
+
return (0, import_react2.useMemo)(() => {
|
|
288
218
|
return {
|
|
289
|
-
...(0,
|
|
219
|
+
...(0, import_canvas2.createQuirksVisibilityRule)(quirks)
|
|
290
220
|
};
|
|
291
221
|
}, [quirks]);
|
|
292
222
|
}
|
|
@@ -294,15 +224,15 @@ function useClientVisibilityRules() {
|
|
|
294
224
|
// src/hooks/useClientConditionsComposition.ts
|
|
295
225
|
function useClientConditionsComposition(data) {
|
|
296
226
|
const rules = useClientVisibilityRules();
|
|
297
|
-
const preprocessedValue = (0,
|
|
227
|
+
const preprocessedValue = (0, import_react3.useMemo)(() => {
|
|
298
228
|
if (!data) {
|
|
299
229
|
return data;
|
|
300
230
|
}
|
|
301
231
|
try {
|
|
302
232
|
return (0, import_immer.produce)(data, (draft) => {
|
|
303
|
-
(0,
|
|
304
|
-
(0,
|
|
305
|
-
(0,
|
|
233
|
+
(0, import_canvas3.walkNodeTree)(draft, (context) => {
|
|
234
|
+
(0, import_canvas3.evaluateWalkTreeNodeVisibility)({ context, rules, showIndeterminate: false });
|
|
235
|
+
(0, import_canvas3.evaluateWalkTreePropertyCriteria)({ node: context.node, rules, keepIndeterminate: false });
|
|
306
236
|
});
|
|
307
237
|
});
|
|
308
238
|
} catch (e) {
|
|
@@ -314,28 +244,28 @@ function useClientConditionsComposition(data) {
|
|
|
314
244
|
}
|
|
315
245
|
|
|
316
246
|
// src/hooks/useUniformContextualEditing.ts
|
|
317
|
-
var
|
|
318
|
-
var
|
|
247
|
+
var import_canvas4 = require("@uniformdev/canvas");
|
|
248
|
+
var import_react4 = require("react");
|
|
319
249
|
var registeredCompositionIds = /* @__PURE__ */ new Set();
|
|
320
250
|
var useUniformContextualEditing = ({
|
|
321
251
|
initialCompositionValue,
|
|
322
252
|
enhance = (message) => message.composition
|
|
323
253
|
}) => {
|
|
324
|
-
const [contextualComposition, setContextualComposition] = (0,
|
|
325
|
-
const latestEventTimeStamp = (0,
|
|
326
|
-
const channel = (0,
|
|
254
|
+
const [contextualComposition, setContextualComposition] = (0, import_react4.useState)();
|
|
255
|
+
const latestEventTimeStamp = (0, import_react4.useRef)(void 0);
|
|
256
|
+
const channel = (0, import_react4.useMemo)(() => {
|
|
327
257
|
var _a;
|
|
328
258
|
if (!isInContextEditingMode()) {
|
|
329
259
|
return;
|
|
330
260
|
}
|
|
331
|
-
const channel2 = (0,
|
|
261
|
+
const channel2 = (0, import_canvas4.createCanvasChannel)({
|
|
332
262
|
broadcastTo: [(_a = window.opener) != null ? _a : window.top],
|
|
333
263
|
listenTo: [window]
|
|
334
264
|
});
|
|
335
265
|
return channel2;
|
|
336
266
|
}, []);
|
|
337
|
-
(0,
|
|
338
|
-
if ((contextualComposition == null ? void 0 : contextualComposition._id) && (initialCompositionValue == null ? void 0 : initialCompositionValue._id) !==
|
|
267
|
+
(0, import_react4.useEffect)(() => {
|
|
268
|
+
if ((contextualComposition == null ? void 0 : contextualComposition._id) && (initialCompositionValue == null ? void 0 : initialCompositionValue._id) !== import_canvas4.EMPTY_COMPOSITION._id && (initialCompositionValue == null ? void 0 : initialCompositionValue._id) !== (contextualComposition == null ? void 0 : contextualComposition._id)) {
|
|
339
269
|
setContextualComposition(void 0);
|
|
340
270
|
return;
|
|
341
271
|
}
|
|
@@ -343,7 +273,7 @@ var useUniformContextualEditing = ({
|
|
|
343
273
|
return;
|
|
344
274
|
}
|
|
345
275
|
const unsubscribeFromCompositionUpdates = channel.on("update-composition-internal", async (message) => {
|
|
346
|
-
if (!(0,
|
|
276
|
+
if (!(0, import_canvas4.isUpdateCompositionInternalMessage)(message)) {
|
|
347
277
|
return;
|
|
348
278
|
}
|
|
349
279
|
if (latestEventTimeStamp.current && message.eventTimestamp && message.eventTimestamp <= latestEventTimeStamp.current) {
|
|
@@ -359,11 +289,11 @@ var useUniformContextualEditing = ({
|
|
|
359
289
|
registeredCompositionIds.delete(initialCompositionValue == null ? void 0 : initialCompositionValue._id);
|
|
360
290
|
};
|
|
361
291
|
}, [channel, enhance, initialCompositionValue == null ? void 0 : initialCompositionValue._id, contextualComposition == null ? void 0 : contextualComposition._id]);
|
|
362
|
-
(0,
|
|
292
|
+
(0, import_react4.useEffect)(() => {
|
|
363
293
|
if (!isInContextEditingMode()) {
|
|
364
294
|
return;
|
|
365
295
|
}
|
|
366
|
-
const existingScript = document.getElementById(
|
|
296
|
+
const existingScript = document.getElementById(import_canvas4.IN_CONTEXT_EDITOR_EMBED_SCRIPT_ID);
|
|
367
297
|
if (existingScript) {
|
|
368
298
|
return;
|
|
369
299
|
}
|
|
@@ -371,10 +301,10 @@ var useUniformContextualEditing = ({
|
|
|
371
301
|
framework: "React",
|
|
372
302
|
// Make sure to also update the value in canvas-vue
|
|
373
303
|
version: 2,
|
|
374
|
-
canvasPackageVersion:
|
|
304
|
+
canvasPackageVersion: import_canvas4.version
|
|
375
305
|
};
|
|
376
306
|
const script = document.createElement("script");
|
|
377
|
-
script.id =
|
|
307
|
+
script.id = import_canvas4.IN_CONTEXT_EDITOR_EMBED_SCRIPT_ID;
|
|
378
308
|
script.src = getCanvasInContextEmbedScriptUrl();
|
|
379
309
|
script.async = true;
|
|
380
310
|
document.head.appendChild(script);
|
|
@@ -393,49 +323,47 @@ function isInContextEditingMode() {
|
|
|
393
323
|
return false;
|
|
394
324
|
}
|
|
395
325
|
const isOpenedByInContextEditor = new URLSearchParams(window.location.search).has(
|
|
396
|
-
|
|
326
|
+
import_canvas4.IN_CONTEXT_EDITOR_QUERY_STRING_PARAM
|
|
397
327
|
);
|
|
398
|
-
return isOpenedByInContextEditor && (0,
|
|
328
|
+
return isOpenedByInContextEditor && (0, import_canvas4.isAllowedReferrer)(window.document.referrer);
|
|
399
329
|
}
|
|
400
330
|
|
|
401
|
-
// src/components/
|
|
402
|
-
var
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
function UniformComposition({
|
|
410
|
-
data,
|
|
411
|
-
behaviorTracking = "onView",
|
|
331
|
+
// src/components/ContextualEditingComponentWrapper.tsx
|
|
332
|
+
var import_canvas6 = require("@uniformdev/canvas");
|
|
333
|
+
var import_react6 = __toESM(require("react"));
|
|
334
|
+
|
|
335
|
+
// src/components/PureContextualEditingComponentWrapper.tsx
|
|
336
|
+
var import_canvas5 = require("@uniformdev/canvas");
|
|
337
|
+
var import_react5 = __toESM(require("react"));
|
|
338
|
+
var PureContextualEditingComponentWrapper = ({
|
|
412
339
|
children,
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
return /* @__PURE__ */
|
|
423
|
-
|
|
340
|
+
isPlaceholder,
|
|
341
|
+
parentComponent,
|
|
342
|
+
component,
|
|
343
|
+
slotName,
|
|
344
|
+
indexInSlot,
|
|
345
|
+
slotChildrenCount,
|
|
346
|
+
isReadOnly
|
|
347
|
+
}) => {
|
|
348
|
+
var _a, _b, _c, _d;
|
|
349
|
+
return /* @__PURE__ */ import_react5.default.createElement(import_react5.default.Fragment, null, /* @__PURE__ */ import_react5.default.createElement(
|
|
350
|
+
"script",
|
|
424
351
|
{
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
}
|
|
352
|
+
"data-role": import_canvas5.IN_CONTEXT_EDITOR_COMPONENT_START_ROLE,
|
|
353
|
+
"data-parent-id": parentComponent == null ? void 0 : parentComponent._id,
|
|
354
|
+
"data-parent-type": parentComponent == null ? void 0 : parentComponent.type,
|
|
355
|
+
"data-component-id": component == null ? void 0 : component._id,
|
|
356
|
+
"data-slot-name": slotName != null ? slotName : "",
|
|
357
|
+
"data-component-index": indexInSlot != null ? indexInSlot : "",
|
|
358
|
+
"data-total-components": slotChildrenCount != null ? slotChildrenCount : "",
|
|
359
|
+
"data-component-name": component == null ? void 0 : component.type,
|
|
360
|
+
"data-is-placeholder": isPlaceholder ? "true" : void 0,
|
|
361
|
+
"data-is-localized": ((_a = component == null ? void 0 : component.parameters) == null ? void 0 : _a[import_canvas5.CANVAS_LOCALE_TAG_PARAM]) ? "true" : void 0,
|
|
362
|
+
"data-component-title": (_d = (_c = (_b = component == null ? void 0 : component.parameters) == null ? void 0 : _b.title) == null ? void 0 : _c.value) != null ? _d : "",
|
|
363
|
+
"data-is-readonly": isReadOnly
|
|
364
|
+
}
|
|
365
|
+
), children, /* @__PURE__ */ import_react5.default.createElement("script", { "data-role": import_canvas5.IN_CONTEXT_EDITOR_COMPONENT_END_ROLE }));
|
|
366
|
+
};
|
|
439
367
|
|
|
440
368
|
// src/components/ContextualEditingComponentWrapper.tsx
|
|
441
369
|
function ContextualEditingComponentWrapper({
|
|
@@ -448,16 +376,16 @@ function ContextualEditingComponentWrapper({
|
|
|
448
376
|
children
|
|
449
377
|
}) {
|
|
450
378
|
var _a;
|
|
451
|
-
const isPlaceholder = (0,
|
|
379
|
+
const isPlaceholder = (0, import_canvas6.isComponentPlaceholderId)(component == null ? void 0 : component._id);
|
|
452
380
|
const { isContextualEditing } = useUniformCurrentComposition();
|
|
453
381
|
const isReadOnly = ((_a = component == null ? void 0 : component._contextualEditing) == null ? void 0 : _a.isEditable) ? void 0 : "true";
|
|
454
382
|
if (!isContextualEditing) {
|
|
455
|
-
return /* @__PURE__ */
|
|
383
|
+
return /* @__PURE__ */ import_react6.default.createElement(import_react6.default.Fragment, null, children);
|
|
456
384
|
}
|
|
457
385
|
if (isPlaceholder && emptyPlaceholder === null) {
|
|
458
386
|
return null;
|
|
459
387
|
}
|
|
460
|
-
return /* @__PURE__ */
|
|
388
|
+
return /* @__PURE__ */ import_react6.default.createElement(
|
|
461
389
|
PureContextualEditingComponentWrapper,
|
|
462
390
|
{
|
|
463
391
|
isPlaceholder,
|
|
@@ -472,6 +400,108 @@ function ContextualEditingComponentWrapper({
|
|
|
472
400
|
);
|
|
473
401
|
}
|
|
474
402
|
|
|
403
|
+
// src/components/UniformComposition.tsx
|
|
404
|
+
var UniformCompositionContext = (0, import_react7.createContext)({
|
|
405
|
+
data: void 0,
|
|
406
|
+
isContextualEditing: false
|
|
407
|
+
});
|
|
408
|
+
function useUniformCurrentComposition() {
|
|
409
|
+
return (0, import_react7.useContext)(UniformCompositionContext);
|
|
410
|
+
}
|
|
411
|
+
function UniformComposition({
|
|
412
|
+
data,
|
|
413
|
+
behaviorTracking = "onView",
|
|
414
|
+
children,
|
|
415
|
+
resolveRenderer,
|
|
416
|
+
contextualEditingEnhancer,
|
|
417
|
+
contextualEditingDefaultPlaceholder,
|
|
418
|
+
// provide default non-undefined values to avoid serialization issues
|
|
419
|
+
matchedRoute = "",
|
|
420
|
+
dynamicInputs = {}
|
|
421
|
+
}) {
|
|
422
|
+
const maybeContext = (0, import_context_react2.useUniformContext)({ throwOnMissingProvider: false });
|
|
423
|
+
(0, import_react7.useEffect)(() => {
|
|
424
|
+
if ((maybeContext == null ? void 0 : maybeContext.context) && (data == null ? void 0 : data._id)) {
|
|
425
|
+
maybeContext.context.updateCompositionMetadata({
|
|
426
|
+
compositionId: data._id,
|
|
427
|
+
matchedRoute,
|
|
428
|
+
dynamicInputs
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
}, [data == null ? void 0 : data._id, maybeContext == null ? void 0 : maybeContext.context, matchedRoute, dynamicInputs]);
|
|
432
|
+
const ruledComposition = useClientConditionsComposition(data);
|
|
433
|
+
const { composition, isContextualEditing } = useUniformContextualEditing({
|
|
434
|
+
initialCompositionValue: ruledComposition,
|
|
435
|
+
enhance: contextualEditingEnhancer
|
|
436
|
+
});
|
|
437
|
+
return /* @__PURE__ */ import_react7.default.createElement(
|
|
438
|
+
UniformCompositionContext.Provider,
|
|
439
|
+
{
|
|
440
|
+
value: {
|
|
441
|
+
data: composition,
|
|
442
|
+
behaviorTracking,
|
|
443
|
+
resolveRenderer,
|
|
444
|
+
isContextualEditing,
|
|
445
|
+
matchedRoute,
|
|
446
|
+
dynamicInputs
|
|
447
|
+
}
|
|
448
|
+
},
|
|
449
|
+
/* @__PURE__ */ import_react7.default.createElement(ContextualEditingComponentWrapper, { component: composition }, /* @__PURE__ */ import_react7.default.createElement(
|
|
450
|
+
UniformComponent,
|
|
451
|
+
{
|
|
452
|
+
data: composition,
|
|
453
|
+
behaviorTracking,
|
|
454
|
+
resolveRenderer,
|
|
455
|
+
contextualEditingDefaultPlaceholder
|
|
456
|
+
},
|
|
457
|
+
children
|
|
458
|
+
))
|
|
459
|
+
);
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
// src/defaultSystemComponentResolver.tsx
|
|
463
|
+
var defaultSystemComponentResolver = {
|
|
464
|
+
test: function TestComponent(component, key, renderChild) {
|
|
465
|
+
var _a, _b, _c, _d, _e;
|
|
466
|
+
const testComponent = component;
|
|
467
|
+
const variants = (_b = (_a = testComponent.slots) == null ? void 0 : _a.test) != null ? _b : [];
|
|
468
|
+
const testName = (_e = (_d = (_c = testComponent.parameters) == null ? void 0 : _c.test) == null ? void 0 : _d.value) != null ? _e : "Untitled Test";
|
|
469
|
+
const finalVariants = (0, import_canvas7.mapSlotToTestVariations)(variants);
|
|
470
|
+
const { data, matchedRoute, dynamicInputs } = useUniformCurrentComposition();
|
|
471
|
+
return /* @__PURE__ */ React5.createElement(
|
|
472
|
+
import_context_react3.Test,
|
|
473
|
+
{
|
|
474
|
+
key,
|
|
475
|
+
variations: finalVariants,
|
|
476
|
+
name: testName,
|
|
477
|
+
component: (variation) => renderChild(variation, key),
|
|
478
|
+
compositionMetadata: (data == null ? void 0 : data._id) ? { compositionId: data._id, matchedRoute, dynamicInputs } : void 0
|
|
479
|
+
}
|
|
480
|
+
);
|
|
481
|
+
},
|
|
482
|
+
personalization: function PersonalizeComponent(component, key, renderChild) {
|
|
483
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
484
|
+
const pzComponent = component;
|
|
485
|
+
const processedVariants = (0, import_canvas7.mapSlotToPersonalizedVariations)((_a = pzComponent == null ? void 0 : pzComponent.slots) == null ? void 0 : _a.pz);
|
|
486
|
+
const { data, matchedRoute, dynamicInputs } = useUniformCurrentComposition();
|
|
487
|
+
return /* @__PURE__ */ React5.createElement(
|
|
488
|
+
import_context_react3.Personalize,
|
|
489
|
+
{
|
|
490
|
+
key,
|
|
491
|
+
variations: processedVariants,
|
|
492
|
+
count: Number((_d = (_c = (_b = pzComponent.parameters) == null ? void 0 : _b[import_canvas7.CANVAS_PERSONALIZATION_TAKE_PARAM]) == null ? void 0 : _c.value) != null ? _d : 1),
|
|
493
|
+
name: (_g = (_f = (_e = pzComponent.parameters) == null ? void 0 : _e[import_canvas7.CANVAS_PERSONALIZATION_EVENT_NAME_PARAM]) == null ? void 0 : _f.value) != null ? _g : "Untitled Personalization",
|
|
494
|
+
component: (variation) => renderChild(variation, 0),
|
|
495
|
+
compositionMetadata: (data == null ? void 0 : data._id) ? { compositionId: data._id, matchedRoute, dynamicInputs } : void 0,
|
|
496
|
+
algorithm: (_i = (_h = pzComponent.parameters) == null ? void 0 : _h[import_canvas7.CANVAS_PERSONALIZATION_ALGORITHM_PARAM]) == null ? void 0 : _i.value,
|
|
497
|
+
compositionId: data == null ? void 0 : data._id,
|
|
498
|
+
matchedRoute,
|
|
499
|
+
dynamicInputs
|
|
500
|
+
}
|
|
501
|
+
);
|
|
502
|
+
}
|
|
503
|
+
};
|
|
504
|
+
|
|
475
505
|
// src/components/UniformSlot.tsx
|
|
476
506
|
function UniformSlot({
|
|
477
507
|
name,
|
|
@@ -625,7 +655,7 @@ function UniformComponent({
|
|
|
625
655
|
}) {
|
|
626
656
|
var _a, _b, _c;
|
|
627
657
|
const parentData = useUniformCurrentComponent();
|
|
628
|
-
const contextContextProviderPresent = (0,
|
|
658
|
+
const contextContextProviderPresent = (0, import_context_react4.useUniformContext)({ throwOnMissingProvider: false }) !== void 0;
|
|
629
659
|
if (!data) {
|
|
630
660
|
if (process.env.NODE_ENV === "development") {
|
|
631
661
|
console.warn(`[canvas-dev] UniformComponent was rendered with no data, nothing will be output.`);
|
|
@@ -639,7 +669,7 @@ function UniformComponent({
|
|
|
639
669
|
contextualEditingDefaultPlaceholder: contextualEditingDefaultPlaceholder != null ? contextualEditingDefaultPlaceholder : parentData.contextualEditingDefaultPlaceholder
|
|
640
670
|
};
|
|
641
671
|
const enrichmentTags = (_c = (_b = data.parameters) == null ? void 0 : _b[import_canvas9.CANVAS_ENRICHMENT_TAG_PARAM]) == null ? void 0 : _c.value;
|
|
642
|
-
const TrackComponent = contextValue.behaviorTracking === "onLoad" ?
|
|
672
|
+
const TrackComponent = contextValue.behaviorTracking === "onLoad" ? import_context_react4.TrackFragment : import_context_react4.Track;
|
|
643
673
|
const resolvedChildren = resolveChildren({
|
|
644
674
|
children,
|
|
645
675
|
data,
|
package/dist/index.mjs
CHANGED
|
@@ -77,7 +77,7 @@ registerUniformComponent({ type: "${componentType}", component: ${proposedFileNa
|
|
|
77
77
|
import {
|
|
78
78
|
CANVAS_ENRICHMENT_TAG_PARAM
|
|
79
79
|
} from "@uniformdev/canvas";
|
|
80
|
-
import { Track, TrackFragment, useUniformContext } from "@uniformdev/context-react";
|
|
80
|
+
import { Track, TrackFragment, useUniformContext as useUniformContext2 } from "@uniformdev/context-react";
|
|
81
81
|
import React7, { createContext as createContext2, useContext as useContext2 } from "react";
|
|
82
82
|
|
|
83
83
|
// src/helpers/convertComponentToProps.ts
|
|
@@ -155,87 +155,11 @@ import {
|
|
|
155
155
|
mapSlotToTestVariations
|
|
156
156
|
} from "@uniformdev/canvas";
|
|
157
157
|
import { Personalize, Test } from "@uniformdev/context-react";
|
|
158
|
-
import * as
|
|
159
|
-
var defaultSystemComponentResolver = {
|
|
160
|
-
test: (component, key, renderChild) => {
|
|
161
|
-
var _a, _b, _c, _d, _e;
|
|
162
|
-
const testComponent = component;
|
|
163
|
-
const variants = (_b = (_a = testComponent.slots) == null ? void 0 : _a.test) != null ? _b : [];
|
|
164
|
-
const testName = (_e = (_d = (_c = testComponent.parameters) == null ? void 0 : _c.test) == null ? void 0 : _d.value) != null ? _e : "Untitled Test";
|
|
165
|
-
const finalVariants = mapSlotToTestVariations(variants);
|
|
166
|
-
return /* @__PURE__ */ React2.createElement(
|
|
167
|
-
Test,
|
|
168
|
-
{
|
|
169
|
-
key,
|
|
170
|
-
variations: finalVariants,
|
|
171
|
-
name: testName,
|
|
172
|
-
component: (variation) => renderChild(variation, key)
|
|
173
|
-
}
|
|
174
|
-
);
|
|
175
|
-
},
|
|
176
|
-
personalization: (component, key, renderChild) => {
|
|
177
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
178
|
-
const pzComponent = component;
|
|
179
|
-
const processedVariants = mapSlotToPersonalizedVariations((_a = pzComponent == null ? void 0 : pzComponent.slots) == null ? void 0 : _a.pz);
|
|
180
|
-
return /* @__PURE__ */ React2.createElement(
|
|
181
|
-
Personalize,
|
|
182
|
-
{
|
|
183
|
-
key,
|
|
184
|
-
variations: processedVariants,
|
|
185
|
-
count: Number((_d = (_c = (_b = pzComponent.parameters) == null ? void 0 : _b[CANVAS_PERSONALIZATION_TAKE_PARAM]) == null ? void 0 : _c.value) != null ? _d : 1),
|
|
186
|
-
name: (_g = (_f = (_e = pzComponent.parameters) == null ? void 0 : _e[CANVAS_PERSONALIZATION_EVENT_NAME_PARAM]) == null ? void 0 : _f.value) != null ? _g : "Untitled Personalization",
|
|
187
|
-
component: (variation) => renderChild(variation, 0),
|
|
188
|
-
algorithm: (_i = (_h = pzComponent.parameters) == null ? void 0 : _h[CANVAS_PERSONALIZATION_ALGORITHM_PARAM]) == null ? void 0 : _i.value
|
|
189
|
-
}
|
|
190
|
-
);
|
|
191
|
-
}
|
|
192
|
-
};
|
|
193
|
-
|
|
194
|
-
// src/components/ContextualEditingComponentWrapper.tsx
|
|
195
|
-
import {
|
|
196
|
-
isComponentPlaceholderId
|
|
197
|
-
} from "@uniformdev/canvas";
|
|
198
|
-
import React5 from "react";
|
|
199
|
-
|
|
200
|
-
// src/components/PureContextualEditingComponentWrapper.tsx
|
|
201
|
-
import {
|
|
202
|
-
CANVAS_LOCALE_TAG_PARAM,
|
|
203
|
-
IN_CONTEXT_EDITOR_COMPONENT_END_ROLE,
|
|
204
|
-
IN_CONTEXT_EDITOR_COMPONENT_START_ROLE
|
|
205
|
-
} from "@uniformdev/canvas";
|
|
206
|
-
import React3 from "react";
|
|
207
|
-
var PureContextualEditingComponentWrapper = ({
|
|
208
|
-
children,
|
|
209
|
-
isPlaceholder,
|
|
210
|
-
parentComponent,
|
|
211
|
-
component,
|
|
212
|
-
slotName,
|
|
213
|
-
indexInSlot,
|
|
214
|
-
slotChildrenCount,
|
|
215
|
-
isReadOnly
|
|
216
|
-
}) => {
|
|
217
|
-
var _a, _b, _c, _d;
|
|
218
|
-
return /* @__PURE__ */ React3.createElement(React3.Fragment, null, /* @__PURE__ */ React3.createElement(
|
|
219
|
-
"script",
|
|
220
|
-
{
|
|
221
|
-
"data-role": IN_CONTEXT_EDITOR_COMPONENT_START_ROLE,
|
|
222
|
-
"data-parent-id": parentComponent == null ? void 0 : parentComponent._id,
|
|
223
|
-
"data-parent-type": parentComponent == null ? void 0 : parentComponent.type,
|
|
224
|
-
"data-component-id": component == null ? void 0 : component._id,
|
|
225
|
-
"data-slot-name": slotName != null ? slotName : "",
|
|
226
|
-
"data-component-index": indexInSlot != null ? indexInSlot : "",
|
|
227
|
-
"data-total-components": slotChildrenCount != null ? slotChildrenCount : "",
|
|
228
|
-
"data-component-name": component == null ? void 0 : component.type,
|
|
229
|
-
"data-is-placeholder": isPlaceholder ? "true" : void 0,
|
|
230
|
-
"data-is-localized": ((_a = component == null ? void 0 : component.parameters) == null ? void 0 : _a[CANVAS_LOCALE_TAG_PARAM]) ? "true" : void 0,
|
|
231
|
-
"data-component-title": (_d = (_c = (_b = component == null ? void 0 : component.parameters) == null ? void 0 : _b.title) == null ? void 0 : _c.value) != null ? _d : "",
|
|
232
|
-
"data-is-readonly": isReadOnly
|
|
233
|
-
}
|
|
234
|
-
), children, /* @__PURE__ */ React3.createElement("script", { "data-role": IN_CONTEXT_EDITOR_COMPONENT_END_ROLE }));
|
|
235
|
-
};
|
|
158
|
+
import * as React5 from "react";
|
|
236
159
|
|
|
237
160
|
// src/components/UniformComposition.tsx
|
|
238
|
-
import
|
|
161
|
+
import { useUniformContext } from "@uniformdev/context-react";
|
|
162
|
+
import React4, { createContext, useContext, useEffect as useEffect2 } from "react";
|
|
239
163
|
|
|
240
164
|
// src/hooks/useClientConditionsComposition.ts
|
|
241
165
|
import {
|
|
@@ -299,7 +223,7 @@ var useUniformContextualEditing = ({
|
|
|
299
223
|
enhance = (message) => message.composition
|
|
300
224
|
}) => {
|
|
301
225
|
const [contextualComposition, setContextualComposition] = useState();
|
|
302
|
-
const latestEventTimeStamp = useRef();
|
|
226
|
+
const latestEventTimeStamp = useRef(void 0);
|
|
303
227
|
const channel = useMemo3(() => {
|
|
304
228
|
var _a;
|
|
305
229
|
if (!isInContextEditingMode()) {
|
|
@@ -375,6 +299,84 @@ function isInContextEditingMode() {
|
|
|
375
299
|
return isOpenedByInContextEditor && isAllowedReferrer(window.document.referrer);
|
|
376
300
|
}
|
|
377
301
|
|
|
302
|
+
// src/components/ContextualEditingComponentWrapper.tsx
|
|
303
|
+
import {
|
|
304
|
+
isComponentPlaceholderId
|
|
305
|
+
} from "@uniformdev/canvas";
|
|
306
|
+
import React3 from "react";
|
|
307
|
+
|
|
308
|
+
// src/components/PureContextualEditingComponentWrapper.tsx
|
|
309
|
+
import {
|
|
310
|
+
CANVAS_LOCALE_TAG_PARAM,
|
|
311
|
+
IN_CONTEXT_EDITOR_COMPONENT_END_ROLE,
|
|
312
|
+
IN_CONTEXT_EDITOR_COMPONENT_START_ROLE
|
|
313
|
+
} from "@uniformdev/canvas";
|
|
314
|
+
import React2 from "react";
|
|
315
|
+
var PureContextualEditingComponentWrapper = ({
|
|
316
|
+
children,
|
|
317
|
+
isPlaceholder,
|
|
318
|
+
parentComponent,
|
|
319
|
+
component,
|
|
320
|
+
slotName,
|
|
321
|
+
indexInSlot,
|
|
322
|
+
slotChildrenCount,
|
|
323
|
+
isReadOnly
|
|
324
|
+
}) => {
|
|
325
|
+
var _a, _b, _c, _d;
|
|
326
|
+
return /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement(
|
|
327
|
+
"script",
|
|
328
|
+
{
|
|
329
|
+
"data-role": IN_CONTEXT_EDITOR_COMPONENT_START_ROLE,
|
|
330
|
+
"data-parent-id": parentComponent == null ? void 0 : parentComponent._id,
|
|
331
|
+
"data-parent-type": parentComponent == null ? void 0 : parentComponent.type,
|
|
332
|
+
"data-component-id": component == null ? void 0 : component._id,
|
|
333
|
+
"data-slot-name": slotName != null ? slotName : "",
|
|
334
|
+
"data-component-index": indexInSlot != null ? indexInSlot : "",
|
|
335
|
+
"data-total-components": slotChildrenCount != null ? slotChildrenCount : "",
|
|
336
|
+
"data-component-name": component == null ? void 0 : component.type,
|
|
337
|
+
"data-is-placeholder": isPlaceholder ? "true" : void 0,
|
|
338
|
+
"data-is-localized": ((_a = component == null ? void 0 : component.parameters) == null ? void 0 : _a[CANVAS_LOCALE_TAG_PARAM]) ? "true" : void 0,
|
|
339
|
+
"data-component-title": (_d = (_c = (_b = component == null ? void 0 : component.parameters) == null ? void 0 : _b.title) == null ? void 0 : _c.value) != null ? _d : "",
|
|
340
|
+
"data-is-readonly": isReadOnly
|
|
341
|
+
}
|
|
342
|
+
), children, /* @__PURE__ */ React2.createElement("script", { "data-role": IN_CONTEXT_EDITOR_COMPONENT_END_ROLE }));
|
|
343
|
+
};
|
|
344
|
+
|
|
345
|
+
// src/components/ContextualEditingComponentWrapper.tsx
|
|
346
|
+
function ContextualEditingComponentWrapper({
|
|
347
|
+
component,
|
|
348
|
+
parentComponent,
|
|
349
|
+
slotName,
|
|
350
|
+
indexInSlot,
|
|
351
|
+
slotChildrenCount,
|
|
352
|
+
emptyPlaceholder,
|
|
353
|
+
children
|
|
354
|
+
}) {
|
|
355
|
+
var _a;
|
|
356
|
+
const isPlaceholder = isComponentPlaceholderId(component == null ? void 0 : component._id);
|
|
357
|
+
const { isContextualEditing } = useUniformCurrentComposition();
|
|
358
|
+
const isReadOnly = ((_a = component == null ? void 0 : component._contextualEditing) == null ? void 0 : _a.isEditable) ? void 0 : "true";
|
|
359
|
+
if (!isContextualEditing) {
|
|
360
|
+
return /* @__PURE__ */ React3.createElement(React3.Fragment, null, children);
|
|
361
|
+
}
|
|
362
|
+
if (isPlaceholder && emptyPlaceholder === null) {
|
|
363
|
+
return null;
|
|
364
|
+
}
|
|
365
|
+
return /* @__PURE__ */ React3.createElement(
|
|
366
|
+
PureContextualEditingComponentWrapper,
|
|
367
|
+
{
|
|
368
|
+
isPlaceholder,
|
|
369
|
+
parentComponent,
|
|
370
|
+
component,
|
|
371
|
+
slotName,
|
|
372
|
+
indexInSlot,
|
|
373
|
+
slotChildrenCount,
|
|
374
|
+
isReadOnly
|
|
375
|
+
},
|
|
376
|
+
isPlaceholder && emptyPlaceholder !== void 0 ? emptyPlaceholder : children
|
|
377
|
+
);
|
|
378
|
+
}
|
|
379
|
+
|
|
378
380
|
// src/components/UniformComposition.tsx
|
|
379
381
|
var UniformCompositionContext = createContext({
|
|
380
382
|
data: void 0,
|
|
@@ -389,8 +391,21 @@ function UniformComposition({
|
|
|
389
391
|
children,
|
|
390
392
|
resolveRenderer,
|
|
391
393
|
contextualEditingEnhancer,
|
|
392
|
-
contextualEditingDefaultPlaceholder
|
|
394
|
+
contextualEditingDefaultPlaceholder,
|
|
395
|
+
// provide default non-undefined values to avoid serialization issues
|
|
396
|
+
matchedRoute = "",
|
|
397
|
+
dynamicInputs = {}
|
|
393
398
|
}) {
|
|
399
|
+
const maybeContext = useUniformContext({ throwOnMissingProvider: false });
|
|
400
|
+
useEffect2(() => {
|
|
401
|
+
if ((maybeContext == null ? void 0 : maybeContext.context) && (data == null ? void 0 : data._id)) {
|
|
402
|
+
maybeContext.context.updateCompositionMetadata({
|
|
403
|
+
compositionId: data._id,
|
|
404
|
+
matchedRoute,
|
|
405
|
+
dynamicInputs
|
|
406
|
+
});
|
|
407
|
+
}
|
|
408
|
+
}, [data == null ? void 0 : data._id, maybeContext == null ? void 0 : maybeContext.context, matchedRoute, dynamicInputs]);
|
|
394
409
|
const ruledComposition = useClientConditionsComposition(data);
|
|
395
410
|
const { composition, isContextualEditing } = useUniformContextualEditing({
|
|
396
411
|
initialCompositionValue: ruledComposition,
|
|
@@ -399,7 +414,14 @@ function UniformComposition({
|
|
|
399
414
|
return /* @__PURE__ */ React4.createElement(
|
|
400
415
|
UniformCompositionContext.Provider,
|
|
401
416
|
{
|
|
402
|
-
value: {
|
|
417
|
+
value: {
|
|
418
|
+
data: composition,
|
|
419
|
+
behaviorTracking,
|
|
420
|
+
resolveRenderer,
|
|
421
|
+
isContextualEditing,
|
|
422
|
+
matchedRoute,
|
|
423
|
+
dynamicInputs
|
|
424
|
+
}
|
|
403
425
|
},
|
|
404
426
|
/* @__PURE__ */ React4.createElement(ContextualEditingComponentWrapper, { component: composition }, /* @__PURE__ */ React4.createElement(
|
|
405
427
|
UniformComponent,
|
|
@@ -414,40 +436,48 @@ function UniformComposition({
|
|
|
414
436
|
);
|
|
415
437
|
}
|
|
416
438
|
|
|
417
|
-
// src/
|
|
418
|
-
|
|
419
|
-
component,
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
439
|
+
// src/defaultSystemComponentResolver.tsx
|
|
440
|
+
var defaultSystemComponentResolver = {
|
|
441
|
+
test: function TestComponent(component, key, renderChild) {
|
|
442
|
+
var _a, _b, _c, _d, _e;
|
|
443
|
+
const testComponent = component;
|
|
444
|
+
const variants = (_b = (_a = testComponent.slots) == null ? void 0 : _a.test) != null ? _b : [];
|
|
445
|
+
const testName = (_e = (_d = (_c = testComponent.parameters) == null ? void 0 : _c.test) == null ? void 0 : _d.value) != null ? _e : "Untitled Test";
|
|
446
|
+
const finalVariants = mapSlotToTestVariations(variants);
|
|
447
|
+
const { data, matchedRoute, dynamicInputs } = useUniformCurrentComposition();
|
|
448
|
+
return /* @__PURE__ */ React5.createElement(
|
|
449
|
+
Test,
|
|
450
|
+
{
|
|
451
|
+
key,
|
|
452
|
+
variations: finalVariants,
|
|
453
|
+
name: testName,
|
|
454
|
+
component: (variation) => renderChild(variation, key),
|
|
455
|
+
compositionMetadata: (data == null ? void 0 : data._id) ? { compositionId: data._id, matchedRoute, dynamicInputs } : void 0
|
|
456
|
+
}
|
|
457
|
+
);
|
|
458
|
+
},
|
|
459
|
+
personalization: function PersonalizeComponent(component, key, renderChild) {
|
|
460
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
461
|
+
const pzComponent = component;
|
|
462
|
+
const processedVariants = mapSlotToPersonalizedVariations((_a = pzComponent == null ? void 0 : pzComponent.slots) == null ? void 0 : _a.pz);
|
|
463
|
+
const { data, matchedRoute, dynamicInputs } = useUniformCurrentComposition();
|
|
464
|
+
return /* @__PURE__ */ React5.createElement(
|
|
465
|
+
Personalize,
|
|
466
|
+
{
|
|
467
|
+
key,
|
|
468
|
+
variations: processedVariants,
|
|
469
|
+
count: Number((_d = (_c = (_b = pzComponent.parameters) == null ? void 0 : _b[CANVAS_PERSONALIZATION_TAKE_PARAM]) == null ? void 0 : _c.value) != null ? _d : 1),
|
|
470
|
+
name: (_g = (_f = (_e = pzComponent.parameters) == null ? void 0 : _e[CANVAS_PERSONALIZATION_EVENT_NAME_PARAM]) == null ? void 0 : _f.value) != null ? _g : "Untitled Personalization",
|
|
471
|
+
component: (variation) => renderChild(variation, 0),
|
|
472
|
+
compositionMetadata: (data == null ? void 0 : data._id) ? { compositionId: data._id, matchedRoute, dynamicInputs } : void 0,
|
|
473
|
+
algorithm: (_i = (_h = pzComponent.parameters) == null ? void 0 : _h[CANVAS_PERSONALIZATION_ALGORITHM_PARAM]) == null ? void 0 : _i.value,
|
|
474
|
+
compositionId: data == null ? void 0 : data._id,
|
|
475
|
+
matchedRoute,
|
|
476
|
+
dynamicInputs
|
|
477
|
+
}
|
|
478
|
+
);
|
|
436
479
|
}
|
|
437
|
-
|
|
438
|
-
PureContextualEditingComponentWrapper,
|
|
439
|
-
{
|
|
440
|
-
isPlaceholder,
|
|
441
|
-
parentComponent,
|
|
442
|
-
component,
|
|
443
|
-
slotName,
|
|
444
|
-
indexInSlot,
|
|
445
|
-
slotChildrenCount,
|
|
446
|
-
isReadOnly
|
|
447
|
-
},
|
|
448
|
-
isPlaceholder && emptyPlaceholder !== void 0 ? emptyPlaceholder : children
|
|
449
|
-
);
|
|
450
|
-
}
|
|
480
|
+
};
|
|
451
481
|
|
|
452
482
|
// src/components/UniformSlot.tsx
|
|
453
483
|
function UniformSlot({
|
|
@@ -602,7 +632,7 @@ function UniformComponent({
|
|
|
602
632
|
}) {
|
|
603
633
|
var _a, _b, _c;
|
|
604
634
|
const parentData = useUniformCurrentComponent();
|
|
605
|
-
const contextContextProviderPresent =
|
|
635
|
+
const contextContextProviderPresent = useUniformContext2({ throwOnMissingProvider: false }) !== void 0;
|
|
606
636
|
if (!data) {
|
|
607
637
|
if (process.env.NODE_ENV === "development") {
|
|
608
638
|
console.warn(`[canvas-dev] UniformComponent was rendered with no data, nothing will be output.`);
|
|
@@ -987,7 +1017,7 @@ import {
|
|
|
987
1017
|
createCanvasChannel as createCanvasChannel2,
|
|
988
1018
|
isUpdateContextualEditingStateInternalMessage
|
|
989
1019
|
} from "@uniformdev/canvas";
|
|
990
|
-
import { useEffect as
|
|
1020
|
+
import { useEffect as useEffect3, useMemo as useMemo5, useState as useState3 } from "react";
|
|
991
1021
|
var useUniformContextualEditingState = ({
|
|
992
1022
|
global = false
|
|
993
1023
|
} = {}) => {
|
|
@@ -1007,7 +1037,7 @@ var useUniformContextualEditingState = ({
|
|
|
1007
1037
|
});
|
|
1008
1038
|
return channel2;
|
|
1009
1039
|
}, [isContextualEditing]);
|
|
1010
|
-
|
|
1040
|
+
useEffect3(() => {
|
|
1011
1041
|
var _a, _b;
|
|
1012
1042
|
if (!channel) {
|
|
1013
1043
|
return;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniformdev/canvas-react",
|
|
3
|
-
"version": "20.35.
|
|
3
|
+
"version": "20.35.1-alpha.210+4fa236da76",
|
|
4
4
|
"description": "React SDK for Uniform Canvas",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -45,10 +45,10 @@
|
|
|
45
45
|
"document:prebuild": "api-extractor run --local"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@uniformdev/canvas": "20.35.
|
|
49
|
-
"@uniformdev/context": "20.35.
|
|
50
|
-
"@uniformdev/context-react": "20.35.
|
|
51
|
-
"@uniformdev/richtext": "20.35.
|
|
48
|
+
"@uniformdev/canvas": "20.35.1-alpha.210+4fa236da76",
|
|
49
|
+
"@uniformdev/context": "20.35.1-alpha.210+4fa236da76",
|
|
50
|
+
"@uniformdev/context-react": "20.35.1-alpha.210+4fa236da76",
|
|
51
|
+
"@uniformdev/richtext": "20.35.1-alpha.210+4fa236da76"
|
|
52
52
|
},
|
|
53
53
|
"peerDependencies": {
|
|
54
54
|
"immer": ">= 10",
|
|
@@ -56,10 +56,10 @@
|
|
|
56
56
|
"react-dom": ">=16"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
|
-
"@types/react": "
|
|
60
|
-
"immer": "10.1.
|
|
61
|
-
"react": "
|
|
62
|
-
"react-dom": "
|
|
59
|
+
"@types/react": "19.2.2",
|
|
60
|
+
"immer": "10.1.3",
|
|
61
|
+
"react": "19.2.1",
|
|
62
|
+
"react-dom": "19.2.1"
|
|
63
63
|
},
|
|
64
64
|
"files": [
|
|
65
65
|
"/dist"
|
|
@@ -67,5 +67,5 @@
|
|
|
67
67
|
"publishConfig": {
|
|
68
68
|
"access": "public"
|
|
69
69
|
},
|
|
70
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "4fa236da76e057582eae6c2595a2fa763fda886a"
|
|
71
71
|
}
|