@uniformdev/canvas-react 20.7.1-alpha.12 → 20.7.1-alpha.121
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 +158 -120
- package/dist/index.js +177 -143
- package/dist/index.mjs +158 -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
|
|
@@ -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
|
|
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
|
|
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 {
|
|
@@ -265,7 +193,9 @@ function useClientConditionsComposition(data) {
|
|
|
265
193
|
try {
|
|
266
194
|
return produce(data, (draft) => {
|
|
267
195
|
walkNodeTree(draft, (context) => {
|
|
268
|
-
evaluateWalkTreeNodeVisibility({ context, rules, showIndeterminate: false })
|
|
196
|
+
if (!evaluateWalkTreeNodeVisibility({ context, rules, showIndeterminate: false })) {
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
269
199
|
evaluateWalkTreePropertyCriteria({ node: context.node, rules, keepIndeterminate: false });
|
|
270
200
|
});
|
|
271
201
|
});
|
|
@@ -285,7 +215,8 @@ import {
|
|
|
285
215
|
IN_CONTEXT_EDITOR_EMBED_SCRIPT_ID,
|
|
286
216
|
IN_CONTEXT_EDITOR_QUERY_STRING_PARAM,
|
|
287
217
|
isAllowedReferrer,
|
|
288
|
-
isUpdateCompositionInternalMessage
|
|
218
|
+
isUpdateCompositionInternalMessage,
|
|
219
|
+
version
|
|
289
220
|
} from "@uniformdev/canvas";
|
|
290
221
|
import { useEffect, useMemo as useMemo3, useRef, useState } from "react";
|
|
291
222
|
var registeredCompositionIds = /* @__PURE__ */ new Set();
|
|
@@ -342,7 +273,8 @@ var useUniformContextualEditing = ({
|
|
|
342
273
|
window.__UNIFORM_CONTEXTUAL_EDITING__ = {
|
|
343
274
|
framework: "React",
|
|
344
275
|
// Make sure to also update the value in canvas-vue
|
|
345
|
-
version: 2
|
|
276
|
+
version: 2,
|
|
277
|
+
canvasPackageVersion: version
|
|
346
278
|
};
|
|
347
279
|
const script = document.createElement("script");
|
|
348
280
|
script.id = IN_CONTEXT_EDITOR_EMBED_SCRIPT_ID;
|
|
@@ -369,6 +301,84 @@ function isInContextEditingMode() {
|
|
|
369
301
|
return isOpenedByInContextEditor && isAllowedReferrer(window.document.referrer);
|
|
370
302
|
}
|
|
371
303
|
|
|
304
|
+
// src/components/ContextualEditingComponentWrapper.tsx
|
|
305
|
+
import {
|
|
306
|
+
isComponentPlaceholderId
|
|
307
|
+
} from "@uniformdev/canvas";
|
|
308
|
+
import React3 from "react";
|
|
309
|
+
|
|
310
|
+
// src/components/PureContextualEditingComponentWrapper.tsx
|
|
311
|
+
import {
|
|
312
|
+
CANVAS_LOCALE_TAG_PARAM,
|
|
313
|
+
IN_CONTEXT_EDITOR_COMPONENT_END_ROLE,
|
|
314
|
+
IN_CONTEXT_EDITOR_COMPONENT_START_ROLE
|
|
315
|
+
} from "@uniformdev/canvas";
|
|
316
|
+
import React2 from "react";
|
|
317
|
+
var PureContextualEditingComponentWrapper = ({
|
|
318
|
+
children,
|
|
319
|
+
isPlaceholder,
|
|
320
|
+
parentComponent,
|
|
321
|
+
component,
|
|
322
|
+
slotName,
|
|
323
|
+
indexInSlot,
|
|
324
|
+
slotChildrenCount,
|
|
325
|
+
isReadOnly
|
|
326
|
+
}) => {
|
|
327
|
+
var _a, _b, _c, _d;
|
|
328
|
+
return /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement(
|
|
329
|
+
"script",
|
|
330
|
+
{
|
|
331
|
+
"data-role": IN_CONTEXT_EDITOR_COMPONENT_START_ROLE,
|
|
332
|
+
"data-parent-id": parentComponent == null ? void 0 : parentComponent._id,
|
|
333
|
+
"data-parent-type": parentComponent == null ? void 0 : parentComponent.type,
|
|
334
|
+
"data-component-id": component == null ? void 0 : component._id,
|
|
335
|
+
"data-slot-name": slotName != null ? slotName : "",
|
|
336
|
+
"data-component-index": indexInSlot != null ? indexInSlot : "",
|
|
337
|
+
"data-total-components": slotChildrenCount != null ? slotChildrenCount : "",
|
|
338
|
+
"data-component-name": component == null ? void 0 : component.type,
|
|
339
|
+
"data-is-placeholder": isPlaceholder ? "true" : void 0,
|
|
340
|
+
"data-is-localized": ((_a = component == null ? void 0 : component.parameters) == null ? void 0 : _a[CANVAS_LOCALE_TAG_PARAM]) ? "true" : void 0,
|
|
341
|
+
"data-component-title": (_d = (_c = (_b = component == null ? void 0 : component.parameters) == null ? void 0 : _b.title) == null ? void 0 : _c.value) != null ? _d : "",
|
|
342
|
+
"data-is-readonly": isReadOnly
|
|
343
|
+
}
|
|
344
|
+
), children, /* @__PURE__ */ React2.createElement("script", { "data-role": IN_CONTEXT_EDITOR_COMPONENT_END_ROLE }));
|
|
345
|
+
};
|
|
346
|
+
|
|
347
|
+
// src/components/ContextualEditingComponentWrapper.tsx
|
|
348
|
+
function ContextualEditingComponentWrapper({
|
|
349
|
+
component,
|
|
350
|
+
parentComponent,
|
|
351
|
+
slotName,
|
|
352
|
+
indexInSlot,
|
|
353
|
+
slotChildrenCount,
|
|
354
|
+
emptyPlaceholder,
|
|
355
|
+
children
|
|
356
|
+
}) {
|
|
357
|
+
var _a;
|
|
358
|
+
const isPlaceholder = isComponentPlaceholderId(component == null ? void 0 : component._id);
|
|
359
|
+
const { isContextualEditing } = useUniformCurrentComposition();
|
|
360
|
+
const isReadOnly = ((_a = component == null ? void 0 : component._contextualEditing) == null ? void 0 : _a.isEditable) ? void 0 : "true";
|
|
361
|
+
if (!isContextualEditing) {
|
|
362
|
+
return /* @__PURE__ */ React3.createElement(React3.Fragment, null, children);
|
|
363
|
+
}
|
|
364
|
+
if (isPlaceholder && emptyPlaceholder === null) {
|
|
365
|
+
return null;
|
|
366
|
+
}
|
|
367
|
+
return /* @__PURE__ */ React3.createElement(
|
|
368
|
+
PureContextualEditingComponentWrapper,
|
|
369
|
+
{
|
|
370
|
+
isPlaceholder,
|
|
371
|
+
parentComponent,
|
|
372
|
+
component,
|
|
373
|
+
slotName,
|
|
374
|
+
indexInSlot,
|
|
375
|
+
slotChildrenCount,
|
|
376
|
+
isReadOnly
|
|
377
|
+
},
|
|
378
|
+
isPlaceholder && emptyPlaceholder !== void 0 ? emptyPlaceholder : children
|
|
379
|
+
);
|
|
380
|
+
}
|
|
381
|
+
|
|
372
382
|
// src/components/UniformComposition.tsx
|
|
373
383
|
var UniformCompositionContext = createContext({
|
|
374
384
|
data: void 0,
|
|
@@ -383,8 +393,21 @@ function UniformComposition({
|
|
|
383
393
|
children,
|
|
384
394
|
resolveRenderer,
|
|
385
395
|
contextualEditingEnhancer,
|
|
386
|
-
contextualEditingDefaultPlaceholder
|
|
396
|
+
contextualEditingDefaultPlaceholder,
|
|
397
|
+
// provide default non-undefined values to avoid serialization issues
|
|
398
|
+
matchedRoute = "",
|
|
399
|
+
dynamicInputs = {}
|
|
387
400
|
}) {
|
|
401
|
+
const maybeContext = useUniformContext({ throwOnMissingProvider: false });
|
|
402
|
+
useEffect2(() => {
|
|
403
|
+
if ((maybeContext == null ? void 0 : maybeContext.context) && (data == null ? void 0 : data._id)) {
|
|
404
|
+
maybeContext.context.updateCompositionMetadata({
|
|
405
|
+
compositionId: data._id,
|
|
406
|
+
matchedRoute,
|
|
407
|
+
dynamicInputs
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
}, [data == null ? void 0 : data._id, maybeContext == null ? void 0 : maybeContext.context, matchedRoute, dynamicInputs]);
|
|
388
411
|
const ruledComposition = useClientConditionsComposition(data);
|
|
389
412
|
const { composition, isContextualEditing } = useUniformContextualEditing({
|
|
390
413
|
initialCompositionValue: ruledComposition,
|
|
@@ -393,7 +416,14 @@ function UniformComposition({
|
|
|
393
416
|
return /* @__PURE__ */ React4.createElement(
|
|
394
417
|
UniformCompositionContext.Provider,
|
|
395
418
|
{
|
|
396
|
-
value: {
|
|
419
|
+
value: {
|
|
420
|
+
data: composition,
|
|
421
|
+
behaviorTracking,
|
|
422
|
+
resolveRenderer,
|
|
423
|
+
isContextualEditing,
|
|
424
|
+
matchedRoute,
|
|
425
|
+
dynamicInputs
|
|
426
|
+
}
|
|
397
427
|
},
|
|
398
428
|
/* @__PURE__ */ React4.createElement(ContextualEditingComponentWrapper, { component: composition }, /* @__PURE__ */ React4.createElement(
|
|
399
429
|
UniformComponent,
|
|
@@ -408,40 +438,48 @@ function UniformComposition({
|
|
|
408
438
|
);
|
|
409
439
|
}
|
|
410
440
|
|
|
411
|
-
// src/
|
|
412
|
-
|
|
413
|
-
component,
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
441
|
+
// src/defaultSystemComponentResolver.tsx
|
|
442
|
+
var defaultSystemComponentResolver = {
|
|
443
|
+
test: function TestComponent(component, key, renderChild) {
|
|
444
|
+
var _a, _b, _c, _d, _e;
|
|
445
|
+
const testComponent = component;
|
|
446
|
+
const variants = (_b = (_a = testComponent.slots) == null ? void 0 : _a.test) != null ? _b : [];
|
|
447
|
+
const testName = (_e = (_d = (_c = testComponent.parameters) == null ? void 0 : _c.test) == null ? void 0 : _d.value) != null ? _e : "Untitled Test";
|
|
448
|
+
const finalVariants = mapSlotToTestVariations(variants);
|
|
449
|
+
const { data, matchedRoute, dynamicInputs } = useUniformCurrentComposition();
|
|
450
|
+
return /* @__PURE__ */ React5.createElement(
|
|
451
|
+
Test,
|
|
452
|
+
{
|
|
453
|
+
key,
|
|
454
|
+
variations: finalVariants,
|
|
455
|
+
name: testName,
|
|
456
|
+
component: (variation) => renderChild(variation, key),
|
|
457
|
+
compositionMetadata: (data == null ? void 0 : data._id) ? { compositionId: data._id, matchedRoute, dynamicInputs } : void 0
|
|
458
|
+
}
|
|
459
|
+
);
|
|
460
|
+
},
|
|
461
|
+
personalization: function PersonalizeComponent(component, key, renderChild) {
|
|
462
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
463
|
+
const pzComponent = component;
|
|
464
|
+
const processedVariants = mapSlotToPersonalizedVariations((_a = pzComponent == null ? void 0 : pzComponent.slots) == null ? void 0 : _a.pz);
|
|
465
|
+
const { data, matchedRoute, dynamicInputs } = useUniformCurrentComposition();
|
|
466
|
+
return /* @__PURE__ */ React5.createElement(
|
|
467
|
+
Personalize,
|
|
468
|
+
{
|
|
469
|
+
key,
|
|
470
|
+
variations: processedVariants,
|
|
471
|
+
count: Number((_d = (_c = (_b = pzComponent.parameters) == null ? void 0 : _b[CANVAS_PERSONALIZATION_TAKE_PARAM]) == null ? void 0 : _c.value) != null ? _d : 1),
|
|
472
|
+
name: (_g = (_f = (_e = pzComponent.parameters) == null ? void 0 : _e[CANVAS_PERSONALIZATION_EVENT_NAME_PARAM]) == null ? void 0 : _f.value) != null ? _g : "Untitled Personalization",
|
|
473
|
+
component: (variation) => renderChild(variation, 0),
|
|
474
|
+
compositionMetadata: (data == null ? void 0 : data._id) ? { compositionId: data._id, matchedRoute, dynamicInputs } : void 0,
|
|
475
|
+
algorithm: (_i = (_h = pzComponent.parameters) == null ? void 0 : _h[CANVAS_PERSONALIZATION_ALGORITHM_PARAM]) == null ? void 0 : _i.value,
|
|
476
|
+
compositionId: data == null ? void 0 : data._id,
|
|
477
|
+
matchedRoute,
|
|
478
|
+
dynamicInputs
|
|
479
|
+
}
|
|
480
|
+
);
|
|
430
481
|
}
|
|
431
|
-
|
|
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
|
-
}
|
|
482
|
+
};
|
|
445
483
|
|
|
446
484
|
// src/components/UniformSlot.tsx
|
|
447
485
|
function UniformSlot({
|
|
@@ -596,7 +634,7 @@ function UniformComponent({
|
|
|
596
634
|
}) {
|
|
597
635
|
var _a, _b, _c;
|
|
598
636
|
const parentData = useUniformCurrentComponent();
|
|
599
|
-
const contextContextProviderPresent =
|
|
637
|
+
const contextContextProviderPresent = useUniformContext2({ throwOnMissingProvider: false }) !== void 0;
|
|
600
638
|
if (!data) {
|
|
601
639
|
if (process.env.NODE_ENV === "development") {
|
|
602
640
|
console.warn(`[canvas-dev] UniformComponent was rendered with no data, nothing will be output.`);
|
|
@@ -981,7 +1019,7 @@ import {
|
|
|
981
1019
|
createCanvasChannel as createCanvasChannel2,
|
|
982
1020
|
isUpdateContextualEditingStateInternalMessage
|
|
983
1021
|
} from "@uniformdev/canvas";
|
|
984
|
-
import { useEffect as
|
|
1022
|
+
import { useEffect as useEffect3, useMemo as useMemo5, useState as useState3 } from "react";
|
|
985
1023
|
var useUniformContextualEditingState = ({
|
|
986
1024
|
global = false
|
|
987
1025
|
} = {}) => {
|
|
@@ -1001,7 +1039,7 @@ var useUniformContextualEditingState = ({
|
|
|
1001
1039
|
});
|
|
1002
1040
|
return channel2;
|
|
1003
1041
|
}, [isContextualEditing]);
|
|
1004
|
-
|
|
1042
|
+
useEffect3(() => {
|
|
1005
1043
|
var _a, _b;
|
|
1006
1044
|
if (!channel) {
|
|
1007
1045
|
return;
|