@uniformdev/canvas-react 20.6.5-alpha.1 → 20.7.1-alpha.106

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.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
@@ -148,90 +148,18 @@ import React6 from "react";
148
148
 
149
149
  // src/defaultSystemComponentResolver.tsx
150
150
  import {
151
+ CANVAS_PERSONALIZATION_ALGORITHM_PARAM,
152
+ CANVAS_PERSONALIZATION_EVENT_NAME_PARAM,
153
+ CANVAS_PERSONALIZATION_TAKE_PARAM,
151
154
  mapSlotToPersonalizedVariations,
152
155
  mapSlotToTestVariations
153
156
  } from "@uniformdev/canvas";
154
157
  import { Personalize, Test } from "@uniformdev/context-react";
155
- import * as React2 from "react";
156
- var defaultSystemComponentResolver = {
157
- test: (component, key, renderChild) => {
158
- var _a, _b, _c, _d, _e;
159
- const testComponent = component;
160
- const variants = (_b = (_a = testComponent.slots) == null ? void 0 : _a.test) != null ? _b : [];
161
- const testName = (_e = (_d = (_c = testComponent.parameters) == null ? void 0 : _c.test) == null ? void 0 : _d.value) != null ? _e : "Untitled Test";
162
- const finalVariants = mapSlotToTestVariations(variants);
163
- return /* @__PURE__ */ React2.createElement(
164
- Test,
165
- {
166
- key,
167
- variations: finalVariants,
168
- name: testName,
169
- component: (variation) => renderChild(variation, key)
170
- }
171
- );
172
- },
173
- personalization: (component, key, renderChild) => {
174
- var _a, _b, _c, _d, _e, _f, _g;
175
- const pzComponent = component;
176
- const processedVariants = mapSlotToPersonalizedVariations((_a = pzComponent == null ? void 0 : pzComponent.slots) == null ? void 0 : _a.pz);
177
- return /* @__PURE__ */ React2.createElement(
178
- Personalize,
179
- {
180
- key,
181
- variations: processedVariants,
182
- count: Number((_d = (_c = (_b = pzComponent.parameters) == null ? void 0 : _b.count) == null ? void 0 : _c.value) != null ? _d : 1),
183
- name: (_g = (_f = (_e = pzComponent.parameters) == null ? void 0 : _e.trackingEventName) == null ? void 0 : _f.value) != null ? _g : "Untitled Personalization",
184
- component: (variation) => renderChild(variation, 0)
185
- }
186
- );
187
- }
188
- };
189
-
190
- // src/components/ContextualEditingComponentWrapper.tsx
191
- import {
192
- isComponentPlaceholderId
193
- } from "@uniformdev/canvas";
194
- import React5 from "react";
195
-
196
- // src/components/PureContextualEditingComponentWrapper.tsx
197
- import {
198
- CANVAS_LOCALE_TAG_PARAM,
199
- IN_CONTEXT_EDITOR_COMPONENT_END_ROLE,
200
- IN_CONTEXT_EDITOR_COMPONENT_START_ROLE
201
- } from "@uniformdev/canvas";
202
- import React3 from "react";
203
- var PureContextualEditingComponentWrapper = ({
204
- children,
205
- isPlaceholder,
206
- parentComponent,
207
- component,
208
- slotName,
209
- indexInSlot,
210
- slotChildrenCount,
211
- isReadOnly
212
- }) => {
213
- var _a, _b, _c, _d;
214
- return /* @__PURE__ */ React3.createElement(React3.Fragment, null, /* @__PURE__ */ React3.createElement(
215
- "script",
216
- {
217
- "data-role": IN_CONTEXT_EDITOR_COMPONENT_START_ROLE,
218
- "data-parent-id": parentComponent == null ? void 0 : parentComponent._id,
219
- "data-parent-type": parentComponent == null ? void 0 : parentComponent.type,
220
- "data-component-id": component == null ? void 0 : component._id,
221
- "data-slot-name": slotName != null ? slotName : "",
222
- "data-component-index": indexInSlot != null ? indexInSlot : "",
223
- "data-total-components": slotChildrenCount != null ? slotChildrenCount : "",
224
- "data-component-name": component == null ? void 0 : component.type,
225
- "data-is-placeholder": isPlaceholder ? "true" : void 0,
226
- "data-is-localized": ((_a = component == null ? void 0 : component.parameters) == null ? void 0 : _a[CANVAS_LOCALE_TAG_PARAM]) ? "true" : void 0,
227
- "data-component-title": (_d = (_c = (_b = component == null ? void 0 : component.parameters) == null ? void 0 : _b.title) == null ? void 0 : _c.value) != null ? _d : "",
228
- "data-is-readonly": isReadOnly
229
- }
230
- ), children, /* @__PURE__ */ React3.createElement("script", { "data-role": IN_CONTEXT_EDITOR_COMPONENT_END_ROLE }));
231
- };
158
+ import * as React5 from "react";
232
159
 
233
160
  // src/components/UniformComposition.tsx
234
- import React4, { createContext, useContext } from "react";
161
+ import { useUniformContext } from "@uniformdev/context-react";
162
+ import React4, { createContext, useContext, useEffect as useEffect2 } from "react";
235
163
 
236
164
  // src/hooks/useClientConditionsComposition.ts
237
165
  import {
@@ -285,7 +213,8 @@ import {
285
213
  IN_CONTEXT_EDITOR_EMBED_SCRIPT_ID,
286
214
  IN_CONTEXT_EDITOR_QUERY_STRING_PARAM,
287
215
  isAllowedReferrer,
288
- isUpdateCompositionInternalMessage
216
+ isUpdateCompositionInternalMessage,
217
+ version
289
218
  } from "@uniformdev/canvas";
290
219
  import { useEffect, useMemo as useMemo3, useRef, useState } from "react";
291
220
  var registeredCompositionIds = /* @__PURE__ */ new Set();
@@ -342,7 +271,8 @@ var useUniformContextualEditing = ({
342
271
  window.__UNIFORM_CONTEXTUAL_EDITING__ = {
343
272
  framework: "React",
344
273
  // Make sure to also update the value in canvas-vue
345
- version: 2
274
+ version: 2,
275
+ canvasPackageVersion: version
346
276
  };
347
277
  const script = document.createElement("script");
348
278
  script.id = IN_CONTEXT_EDITOR_EMBED_SCRIPT_ID;
@@ -369,6 +299,84 @@ function isInContextEditingMode() {
369
299
  return isOpenedByInContextEditor && isAllowedReferrer(window.document.referrer);
370
300
  }
371
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
+
372
380
  // src/components/UniformComposition.tsx
373
381
  var UniformCompositionContext = createContext({
374
382
  data: void 0,
@@ -383,8 +391,21 @@ function UniformComposition({
383
391
  children,
384
392
  resolveRenderer,
385
393
  contextualEditingEnhancer,
386
- contextualEditingDefaultPlaceholder
394
+ contextualEditingDefaultPlaceholder,
395
+ // provide default non-undefined values to avoid serialization issues
396
+ matchedRoute = "",
397
+ dynamicInputs = {}
387
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]);
388
409
  const ruledComposition = useClientConditionsComposition(data);
389
410
  const { composition, isContextualEditing } = useUniformContextualEditing({
390
411
  initialCompositionValue: ruledComposition,
@@ -393,7 +414,14 @@ function UniformComposition({
393
414
  return /* @__PURE__ */ React4.createElement(
394
415
  UniformCompositionContext.Provider,
395
416
  {
396
- value: { data: composition, behaviorTracking, resolveRenderer, isContextualEditing }
417
+ value: {
418
+ data: composition,
419
+ behaviorTracking,
420
+ resolveRenderer,
421
+ isContextualEditing,
422
+ matchedRoute,
423
+ dynamicInputs
424
+ }
397
425
  },
398
426
  /* @__PURE__ */ React4.createElement(ContextualEditingComponentWrapper, { component: composition }, /* @__PURE__ */ React4.createElement(
399
427
  UniformComponent,
@@ -408,40 +436,48 @@ function UniformComposition({
408
436
  );
409
437
  }
410
438
 
411
- // src/components/ContextualEditingComponentWrapper.tsx
412
- function ContextualEditingComponentWrapper({
413
- component,
414
- parentComponent,
415
- slotName,
416
- indexInSlot,
417
- slotChildrenCount,
418
- emptyPlaceholder,
419
- children
420
- }) {
421
- var _a;
422
- const isPlaceholder = isComponentPlaceholderId(component == null ? void 0 : component._id);
423
- const { isContextualEditing } = useUniformCurrentComposition();
424
- const isReadOnly = ((_a = component == null ? void 0 : component._contextualEditing) == null ? void 0 : _a.isEditable) ? void 0 : "true";
425
- if (!isContextualEditing) {
426
- return /* @__PURE__ */ React5.createElement(React5.Fragment, null, children);
427
- }
428
- if (isPlaceholder && emptyPlaceholder === null) {
429
- return null;
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
+ );
430
479
  }
431
- return /* @__PURE__ */ React5.createElement(
432
- PureContextualEditingComponentWrapper,
433
- {
434
- isPlaceholder,
435
- parentComponent,
436
- component,
437
- slotName,
438
- indexInSlot,
439
- slotChildrenCount,
440
- isReadOnly
441
- },
442
- isPlaceholder && emptyPlaceholder !== void 0 ? emptyPlaceholder : children
443
- );
444
- }
480
+ };
445
481
 
446
482
  // src/components/UniformSlot.tsx
447
483
  function UniformSlot({
@@ -596,7 +632,7 @@ function UniformComponent({
596
632
  }) {
597
633
  var _a, _b, _c;
598
634
  const parentData = useUniformCurrentComponent();
599
- const contextContextProviderPresent = useUniformContext({ throwOnMissingProvider: false }) !== void 0;
635
+ const contextContextProviderPresent = useUniformContext2({ throwOnMissingProvider: false }) !== void 0;
600
636
  if (!data) {
601
637
  if (process.env.NODE_ENV === "development") {
602
638
  console.warn(`[canvas-dev] UniformComponent was rendered with no data, nothing will be output.`);
@@ -981,7 +1017,7 @@ import {
981
1017
  createCanvasChannel as createCanvasChannel2,
982
1018
  isUpdateContextualEditingStateInternalMessage
983
1019
  } from "@uniformdev/canvas";
984
- import { useEffect as useEffect2, useMemo as useMemo5, useState as useState3 } from "react";
1020
+ import { useEffect as useEffect3, useMemo as useMemo5, useState as useState3 } from "react";
985
1021
  var useUniformContextualEditingState = ({
986
1022
  global = false
987
1023
  } = {}) => {
@@ -1001,7 +1037,7 @@ var useUniformContextualEditingState = ({
1001
1037
  });
1002
1038
  return channel2;
1003
1039
  }, [isContextualEditing]);
1004
- useEffect2(() => {
1040
+ useEffect3(() => {
1005
1041
  var _a, _b;
1006
1042
  if (!channel) {
1007
1043
  return;