@uniformdev/canvas-react 20.6.2-alpha.11 → 20.7.1-alpha.102
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.txt +1 -1
- package/dist/index.d.mts +206 -20
- package/dist/index.d.ts +206 -20
- package/dist/index.esm.js +152 -120
- package/dist/index.js +175 -144
- package/dist/index.mjs +152 -120
- package/package.json +8 -8
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 {
|
|
@@ -289,7 +213,8 @@ import {
|
|
|
289
213
|
IN_CONTEXT_EDITOR_EMBED_SCRIPT_ID,
|
|
290
214
|
IN_CONTEXT_EDITOR_QUERY_STRING_PARAM,
|
|
291
215
|
isAllowedReferrer,
|
|
292
|
-
isUpdateCompositionInternalMessage
|
|
216
|
+
isUpdateCompositionInternalMessage,
|
|
217
|
+
version
|
|
293
218
|
} from "@uniformdev/canvas";
|
|
294
219
|
import { useEffect, useMemo as useMemo3, useRef, useState } from "react";
|
|
295
220
|
var registeredCompositionIds = /* @__PURE__ */ new Set();
|
|
@@ -346,7 +271,8 @@ var useUniformContextualEditing = ({
|
|
|
346
271
|
window.__UNIFORM_CONTEXTUAL_EDITING__ = {
|
|
347
272
|
framework: "React",
|
|
348
273
|
// Make sure to also update the value in canvas-vue
|
|
349
|
-
version: 2
|
|
274
|
+
version: 2,
|
|
275
|
+
canvasPackageVersion: version
|
|
350
276
|
};
|
|
351
277
|
const script = document.createElement("script");
|
|
352
278
|
script.id = IN_CONTEXT_EDITOR_EMBED_SCRIPT_ID;
|
|
@@ -373,6 +299,84 @@ function isInContextEditingMode() {
|
|
|
373
299
|
return isOpenedByInContextEditor && isAllowedReferrer(window.document.referrer);
|
|
374
300
|
}
|
|
375
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
|
+
|
|
376
380
|
// src/components/UniformComposition.tsx
|
|
377
381
|
var UniformCompositionContext = createContext({
|
|
378
382
|
data: void 0,
|
|
@@ -387,8 +391,21 @@ function UniformComposition({
|
|
|
387
391
|
children,
|
|
388
392
|
resolveRenderer,
|
|
389
393
|
contextualEditingEnhancer,
|
|
390
|
-
contextualEditingDefaultPlaceholder
|
|
394
|
+
contextualEditingDefaultPlaceholder,
|
|
395
|
+
// provide default non-undefined values to avoid serialization issues
|
|
396
|
+
matchedRoute = "",
|
|
397
|
+
dynamicInputs = {}
|
|
391
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]);
|
|
392
409
|
const ruledComposition = useClientConditionsComposition(data);
|
|
393
410
|
const { composition, isContextualEditing } = useUniformContextualEditing({
|
|
394
411
|
initialCompositionValue: ruledComposition,
|
|
@@ -397,7 +414,14 @@ function UniformComposition({
|
|
|
397
414
|
return /* @__PURE__ */ React4.createElement(
|
|
398
415
|
UniformCompositionContext.Provider,
|
|
399
416
|
{
|
|
400
|
-
value: {
|
|
417
|
+
value: {
|
|
418
|
+
data: composition,
|
|
419
|
+
behaviorTracking,
|
|
420
|
+
resolveRenderer,
|
|
421
|
+
isContextualEditing,
|
|
422
|
+
matchedRoute,
|
|
423
|
+
dynamicInputs
|
|
424
|
+
}
|
|
401
425
|
},
|
|
402
426
|
/* @__PURE__ */ React4.createElement(ContextualEditingComponentWrapper, { component: composition }, /* @__PURE__ */ React4.createElement(
|
|
403
427
|
UniformComponent,
|
|
@@ -412,40 +436,48 @@ function UniformComposition({
|
|
|
412
436
|
);
|
|
413
437
|
}
|
|
414
438
|
|
|
415
|
-
// src/
|
|
416
|
-
|
|
417
|
-
component,
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
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
|
+
);
|
|
434
479
|
}
|
|
435
|
-
|
|
436
|
-
PureContextualEditingComponentWrapper,
|
|
437
|
-
{
|
|
438
|
-
isPlaceholder,
|
|
439
|
-
parentComponent,
|
|
440
|
-
component,
|
|
441
|
-
slotName,
|
|
442
|
-
indexInSlot,
|
|
443
|
-
slotChildrenCount,
|
|
444
|
-
isReadOnly
|
|
445
|
-
},
|
|
446
|
-
isPlaceholder && emptyPlaceholder !== void 0 ? emptyPlaceholder : children
|
|
447
|
-
);
|
|
448
|
-
}
|
|
480
|
+
};
|
|
449
481
|
|
|
450
482
|
// src/components/UniformSlot.tsx
|
|
451
483
|
function UniformSlot({
|
|
@@ -600,7 +632,7 @@ function UniformComponent({
|
|
|
600
632
|
}) {
|
|
601
633
|
var _a, _b, _c;
|
|
602
634
|
const parentData = useUniformCurrentComponent();
|
|
603
|
-
const contextContextProviderPresent =
|
|
635
|
+
const contextContextProviderPresent = useUniformContext2({ throwOnMissingProvider: false }) !== void 0;
|
|
604
636
|
if (!data) {
|
|
605
637
|
if (process.env.NODE_ENV === "development") {
|
|
606
638
|
console.warn(`[canvas-dev] UniformComponent was rendered with no data, nothing will be output.`);
|
|
@@ -985,7 +1017,7 @@ import {
|
|
|
985
1017
|
createCanvasChannel as createCanvasChannel2,
|
|
986
1018
|
isUpdateContextualEditingStateInternalMessage
|
|
987
1019
|
} from "@uniformdev/canvas";
|
|
988
|
-
import { useEffect as
|
|
1020
|
+
import { useEffect as useEffect3, useMemo as useMemo5, useState as useState3 } from "react";
|
|
989
1021
|
var useUniformContextualEditingState = ({
|
|
990
1022
|
global = false
|
|
991
1023
|
} = {}) => {
|
|
@@ -1005,7 +1037,7 @@ var useUniformContextualEditingState = ({
|
|
|
1005
1037
|
});
|
|
1006
1038
|
return channel2;
|
|
1007
1039
|
}, [isContextualEditing]);
|
|
1008
|
-
|
|
1040
|
+
useEffect3(() => {
|
|
1009
1041
|
var _a, _b;
|
|
1010
1042
|
if (!channel) {
|
|
1011
1043
|
return;
|