@uniformdev/canvas-vue 18.33.0 → 18.34.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +5 -86
- package/dist/index.esm.js +124 -63
- package/dist/index.js +132 -75
- package/dist/index.mjs +124 -63
- package/package.json +4 -4
package/dist/index.esm.js
CHANGED
|
@@ -150,16 +150,18 @@ var UniformComponent_default = UniformComponent;
|
|
|
150
150
|
// src/components/UniformComposition.ts
|
|
151
151
|
import {
|
|
152
152
|
computed as computed3,
|
|
153
|
-
defineComponent as
|
|
154
|
-
h as
|
|
153
|
+
defineComponent as defineComponent4,
|
|
154
|
+
h as h4,
|
|
155
155
|
inject as inject2,
|
|
156
|
-
provide as provide2
|
|
156
|
+
provide as provide2,
|
|
157
|
+
shallowRef
|
|
157
158
|
} from "vue-demi";
|
|
158
159
|
|
|
159
160
|
// src/composables/useUniformContextualEditing.ts
|
|
160
161
|
import {
|
|
161
162
|
createCanvasChannel,
|
|
162
163
|
createUniformApiEnhancer,
|
|
164
|
+
EMPTY_COMPOSITION,
|
|
163
165
|
IN_CONTEXT_EDITOR_EMBED_SCRIPT_ID,
|
|
164
166
|
IN_CONTEXT_EDITOR_QUERY_STRING_PARAM,
|
|
165
167
|
isUpdateCompositionMessage
|
|
@@ -174,8 +176,9 @@ var useUniformContextualEditing = ({
|
|
|
174
176
|
const contextualComposition = ref();
|
|
175
177
|
const composition = computed2(() => {
|
|
176
178
|
var _a;
|
|
177
|
-
return (_a = contextualComposition.value) != null ? _a : initialCompositionValue;
|
|
179
|
+
return (_a = contextualComposition.value) != null ? _a : initialCompositionValue == null ? void 0 : initialCompositionValue.value;
|
|
178
180
|
});
|
|
181
|
+
const isContextualEditing = computed2(() => Boolean(contextualComposition.value));
|
|
179
182
|
const channel = computed2(() => {
|
|
180
183
|
var _a;
|
|
181
184
|
if (!isInContextEditingMode()) {
|
|
@@ -188,9 +191,17 @@ var useUniformContextualEditing = ({
|
|
|
188
191
|
return channel2;
|
|
189
192
|
});
|
|
190
193
|
watch(
|
|
191
|
-
[channel, () => enhance, () =>
|
|
192
|
-
|
|
193
|
-
|
|
194
|
+
[channel, contextualComposition, () => enhance, () => {
|
|
195
|
+
var _a;
|
|
196
|
+
return (_a = initialCompositionValue == null ? void 0 : initialCompositionValue.value) == null ? void 0 : _a._id;
|
|
197
|
+
}],
|
|
198
|
+
(_newValue, _oldValue, onCleanup) => {
|
|
199
|
+
var _a, _b, _c, _d, _e, _f;
|
|
200
|
+
if (((_a = contextualComposition.value) == null ? void 0 : _a._id) && ((_b = initialCompositionValue == null ? void 0 : initialCompositionValue.value) == null ? void 0 : _b._id) !== EMPTY_COMPOSITION._id && ((_c = initialCompositionValue == null ? void 0 : initialCompositionValue.value) == null ? void 0 : _c._id) !== ((_d = contextualComposition.value) == null ? void 0 : _d._id)) {
|
|
201
|
+
contextualComposition.value = void 0;
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
if (!channel.value || registeredCompositionIds.has((_e = initialCompositionValue == null ? void 0 : initialCompositionValue.value) == null ? void 0 : _e._id)) {
|
|
194
205
|
return;
|
|
195
206
|
}
|
|
196
207
|
const unsubscribe = channel.value.on("update-composition", async (message) => {
|
|
@@ -200,11 +211,12 @@ var useUniformContextualEditing = ({
|
|
|
200
211
|
const enhancedComposition = await enhance(message);
|
|
201
212
|
contextualComposition.value = enhancedComposition;
|
|
202
213
|
});
|
|
203
|
-
registeredCompositionIds.add(initialCompositionValue == null ? void 0 : initialCompositionValue._id);
|
|
204
|
-
|
|
214
|
+
registeredCompositionIds.add((_f = initialCompositionValue == null ? void 0 : initialCompositionValue.value) == null ? void 0 : _f._id);
|
|
215
|
+
onCleanup(() => {
|
|
216
|
+
var _a2;
|
|
205
217
|
unsubscribe();
|
|
206
|
-
registeredCompositionIds.delete(initialCompositionValue == null ? void 0 : initialCompositionValue._id);
|
|
207
|
-
};
|
|
218
|
+
registeredCompositionIds.delete((_a2 = initialCompositionValue == null ? void 0 : initialCompositionValue.value) == null ? void 0 : _a2._id);
|
|
219
|
+
});
|
|
208
220
|
},
|
|
209
221
|
{ immediate: true }
|
|
210
222
|
);
|
|
@@ -217,7 +229,9 @@ var useUniformContextualEditing = ({
|
|
|
217
229
|
return;
|
|
218
230
|
}
|
|
219
231
|
window.__UNIFORM_CONTEXTUAL_EDITING__ = {
|
|
220
|
-
framework: "Vue"
|
|
232
|
+
framework: "Vue",
|
|
233
|
+
// Make sure to also update the value in canvas-react
|
|
234
|
+
version: 1
|
|
221
235
|
};
|
|
222
236
|
const script = document.createElement("script");
|
|
223
237
|
script.id = IN_CONTEXT_EDITOR_EMBED_SCRIPT_ID;
|
|
@@ -226,7 +240,8 @@ var useUniformContextualEditing = ({
|
|
|
226
240
|
document.head.appendChild(script);
|
|
227
241
|
});
|
|
228
242
|
return {
|
|
229
|
-
composition
|
|
243
|
+
composition,
|
|
244
|
+
isContextualEditing
|
|
230
245
|
};
|
|
231
246
|
};
|
|
232
247
|
function getCanvasInContextEmbedScriptUrl() {
|
|
@@ -250,12 +265,69 @@ var useContextualEditing = useUniformContextualEditing;
|
|
|
250
265
|
// src/utils/constants.ts
|
|
251
266
|
var globalCompositionEnhancerInjectionKey = "uniformGlobalCompositionEnhancer";
|
|
252
267
|
|
|
268
|
+
// src/components/ContextualEditingComponentWrapper.ts
|
|
269
|
+
import {
|
|
270
|
+
CANVAS_LOCALE_TAG_PARAM,
|
|
271
|
+
IN_CONTEXT_EDITOR_COMPONENT_END_ROLE,
|
|
272
|
+
IN_CONTEXT_EDITOR_COMPONENT_START_ROLE,
|
|
273
|
+
PLACEHOLDER_ID
|
|
274
|
+
} from "@uniformdev/canvas";
|
|
275
|
+
import { defineComponent as defineComponent3, h as h3 } from "vue-demi";
|
|
276
|
+
var ContextualEditingComponentWrapper = defineComponent3({
|
|
277
|
+
name: "ContextualEditingComponentWrapper",
|
|
278
|
+
inheritAttrs: false,
|
|
279
|
+
props: {
|
|
280
|
+
component: {
|
|
281
|
+
type: Object
|
|
282
|
+
},
|
|
283
|
+
parentComponent: {
|
|
284
|
+
type: Object
|
|
285
|
+
},
|
|
286
|
+
slotName: {
|
|
287
|
+
type: String
|
|
288
|
+
},
|
|
289
|
+
indexInSlot: {
|
|
290
|
+
type: Number
|
|
291
|
+
},
|
|
292
|
+
slotChildrenCount: {
|
|
293
|
+
type: Number
|
|
294
|
+
}
|
|
295
|
+
},
|
|
296
|
+
setup(props, context) {
|
|
297
|
+
var _a;
|
|
298
|
+
const { isContextualEditing } = useUniformCurrentComposition();
|
|
299
|
+
const isPlaceholder = ((_a = props.component) == null ? void 0 : _a._id) === PLACEHOLDER_ID;
|
|
300
|
+
return () => {
|
|
301
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
302
|
+
return !(isContextualEditing == null ? void 0 : isContextualEditing.value) ? (_b = (_a2 = context.slots).default) == null ? void 0 : _b.call(_a2) : [
|
|
303
|
+
h3("script", {
|
|
304
|
+
"data-role": IN_CONTEXT_EDITOR_COMPONENT_START_ROLE,
|
|
305
|
+
"data-parent-id": (_c = props.parentComponent) == null ? void 0 : _c._id,
|
|
306
|
+
"data-parent-type": (_d = props.parentComponent) == null ? void 0 : _d.type,
|
|
307
|
+
"data-component-id": (_e = props.component) == null ? void 0 : _e._id,
|
|
308
|
+
"data-slot-name": props.slotName,
|
|
309
|
+
"data-component-index": props.indexInSlot,
|
|
310
|
+
"data-total-components": props.slotChildrenCount,
|
|
311
|
+
"data-component-name": (_f = props.component) == null ? void 0 : _f.type,
|
|
312
|
+
"data-is-placeholder": isPlaceholder ? "true" : void 0,
|
|
313
|
+
"data-is-localized": ((_h = (_g = props.component) == null ? void 0 : _g.parameters) == null ? void 0 : _h[CANVAS_LOCALE_TAG_PARAM]) ? "true" : void 0,
|
|
314
|
+
// TODO: use a proper way to get the component's title, don't assume that it's always "title"
|
|
315
|
+
// https://linear.app/uniform/issue/UNI-937/show-the-right-component-title-in-the-highlighter
|
|
316
|
+
"data-component-title": (_k = (_j = (_i = props.component) == null ? void 0 : _i.parameters) == null ? void 0 : _j.title) == null ? void 0 : _k.value
|
|
317
|
+
}),
|
|
318
|
+
isPlaceholder && context.slots.emptyPlaceholder !== void 0 ? context.slots.emptyPlaceholder() : (_m = (_l = context.slots).default) == null ? void 0 : _m.call(_l),
|
|
319
|
+
h3("script", { "data-role": IN_CONTEXT_EDITOR_COMPONENT_END_ROLE })
|
|
320
|
+
];
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
});
|
|
324
|
+
|
|
253
325
|
// src/components/UniformComposition.ts
|
|
254
326
|
var uniformCurrentCompositionInjectionKey = "uniformCurrentComposition";
|
|
255
327
|
var useUniformCurrentComposition = () => {
|
|
256
328
|
return inject2(uniformCurrentCompositionInjectionKey, {});
|
|
257
329
|
};
|
|
258
|
-
var UniformComposition =
|
|
330
|
+
var UniformComposition = defineComponent4({
|
|
259
331
|
name: "UniformComposition",
|
|
260
332
|
inheritAttrs: false,
|
|
261
333
|
props: {
|
|
@@ -280,27 +352,33 @@ var UniformComposition = defineComponent3({
|
|
|
280
352
|
(composition2) => composition2
|
|
281
353
|
);
|
|
282
354
|
const inheritedContextualEnhancer = (message) => inheritedEnhancer(message.composition);
|
|
283
|
-
const { composition } = useUniformContextualEditing({
|
|
284
|
-
initialCompositionValue: props.data,
|
|
355
|
+
const { composition, isContextualEditing } = useUniformContextualEditing({
|
|
356
|
+
initialCompositionValue: shallowRef(props.data),
|
|
285
357
|
enhance: (_a = props.contextualEditingEnhancer) != null ? _a : inheritedContextualEnhancer
|
|
286
358
|
});
|
|
287
359
|
provide2(uniformCurrentCompositionInjectionKey, {
|
|
288
360
|
data: composition,
|
|
289
361
|
behaviorTracking: props.behaviorTracking,
|
|
290
|
-
resolveRenderer: props.resolveRenderer
|
|
362
|
+
resolveRenderer: props.resolveRenderer,
|
|
363
|
+
isContextualEditing
|
|
291
364
|
});
|
|
292
365
|
const compositionKey = computed3(() => {
|
|
293
366
|
return JSON.stringify(composition.value);
|
|
294
367
|
});
|
|
295
|
-
return () =>
|
|
296
|
-
|
|
368
|
+
return () => h4(
|
|
369
|
+
ContextualEditingComponentWrapper,
|
|
370
|
+
{ component: composition.value, key: compositionKey.value },
|
|
297
371
|
{
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
372
|
+
default: () => h4(
|
|
373
|
+
UniformComponent_default,
|
|
374
|
+
{
|
|
375
|
+
data: composition.value,
|
|
376
|
+
behaviorTracking: props.behaviorTracking,
|
|
377
|
+
resolveRenderer: props.resolveRenderer
|
|
378
|
+
},
|
|
379
|
+
context.slots.default
|
|
380
|
+
)
|
|
381
|
+
}
|
|
304
382
|
);
|
|
305
383
|
}
|
|
306
384
|
});
|
|
@@ -308,18 +386,15 @@ var Composition = UniformComposition;
|
|
|
308
386
|
|
|
309
387
|
// src/components/UniformSlot.ts
|
|
310
388
|
import {
|
|
311
|
-
CANVAS_LOCALE_TAG_PARAM,
|
|
312
389
|
CANVAS_PERSONALIZE_SLOT,
|
|
313
390
|
CANVAS_PERSONALIZE_TYPE,
|
|
314
391
|
CANVAS_TEST_SLOT,
|
|
315
392
|
CANVAS_TEST_TYPE,
|
|
316
|
-
IN_CONTEXT_EDITOR_COMPONENT_START_ROLE,
|
|
317
393
|
mapSlotToPersonalizedVariations,
|
|
318
|
-
mapSlotToTestVariations
|
|
319
|
-
PLACEHOLDER_ID
|
|
394
|
+
mapSlotToTestVariations
|
|
320
395
|
} from "@uniformdev/canvas";
|
|
321
396
|
import { Personalize, Test } from "@uniformdev/context-vue";
|
|
322
|
-
import { computed as computed4, defineComponent as
|
|
397
|
+
import { computed as computed4, defineComponent as defineComponent5, h as h5 } from "vue-demi";
|
|
323
398
|
|
|
324
399
|
// src/utils/convertComponentToProps.ts
|
|
325
400
|
function convertComponentToProps(component) {
|
|
@@ -344,7 +419,7 @@ function normalizePropName(name) {
|
|
|
344
419
|
}
|
|
345
420
|
|
|
346
421
|
// src/components/UniformSlot.ts
|
|
347
|
-
var UniformSlot =
|
|
422
|
+
var UniformSlot = defineComponent5({
|
|
348
423
|
name: "UniformSlot",
|
|
349
424
|
inheritAttrs: false,
|
|
350
425
|
props: {
|
|
@@ -390,7 +465,7 @@ function renderPersonalizeComponent(component, resolveRenderer) {
|
|
|
390
465
|
const parameters = component == null ? void 0 : component.parameters;
|
|
391
466
|
const processedVariants = mapSlotToPersonalizedVariations((_a = component.slots) == null ? void 0 : _a.pz);
|
|
392
467
|
const name = (_d = (_c = (_b = component.parameters) == null ? void 0 : _b.trackingEventName) == null ? void 0 : _c.value) != null ? _d : "Untitled Personalization";
|
|
393
|
-
return
|
|
468
|
+
return h5(Personalize, {
|
|
394
469
|
name,
|
|
395
470
|
// TODO: Fix the `as unknown`
|
|
396
471
|
component: (variant) => resolveRenderer(variant),
|
|
@@ -403,7 +478,7 @@ function renderTestComponent(component, resolveRenderer) {
|
|
|
403
478
|
const variants = (_b = (_a = component == null ? void 0 : component.slots) == null ? void 0 : _a.test) != null ? _b : [];
|
|
404
479
|
const testName = (_e = (_d = (_c = component == null ? void 0 : component.parameters) == null ? void 0 : _c.test) == null ? void 0 : _d.value) != null ? _e : "Untitled Test";
|
|
405
480
|
const finalVariants = mapSlotToTestVariations(variants);
|
|
406
|
-
return
|
|
481
|
+
return h5(Test, {
|
|
407
482
|
variations: finalVariants,
|
|
408
483
|
name: testName,
|
|
409
484
|
component: (variant) => resolveRenderer(variant)
|
|
@@ -418,19 +493,18 @@ function renderComponent({
|
|
|
418
493
|
slotChildrenCount,
|
|
419
494
|
emptyPlaceholder
|
|
420
495
|
}) {
|
|
421
|
-
var _a, _b, _c;
|
|
422
496
|
if (component.type === CANVAS_TEST_TYPE) {
|
|
423
497
|
return renderTestComponent(
|
|
424
498
|
component,
|
|
425
499
|
(variantComponent) => {
|
|
426
|
-
var
|
|
500
|
+
var _a, _b;
|
|
427
501
|
return renderComponent({
|
|
428
502
|
component: variantComponent,
|
|
429
503
|
resolveRenderer,
|
|
430
504
|
parentComponent: component,
|
|
431
505
|
slotName: CANVAS_TEST_SLOT,
|
|
432
|
-
slotChildrenCount: (
|
|
433
|
-
indexInSlot: (
|
|
506
|
+
slotChildrenCount: (_a = component == null ? void 0 : component.slots) == null ? void 0 : _a[CANVAS_TEST_SLOT].length,
|
|
507
|
+
indexInSlot: (_b = component == null ? void 0 : component.slots) == null ? void 0 : _b[CANVAS_TEST_SLOT].findIndex(
|
|
434
508
|
({ _id }) => variantComponent._id === _id
|
|
435
509
|
)
|
|
436
510
|
});
|
|
@@ -441,14 +515,14 @@ function renderComponent({
|
|
|
441
515
|
return renderPersonalizeComponent(
|
|
442
516
|
component,
|
|
443
517
|
(variantComponent) => {
|
|
444
|
-
var
|
|
518
|
+
var _a, _b;
|
|
445
519
|
return renderComponent({
|
|
446
520
|
component: variantComponent,
|
|
447
521
|
resolveRenderer,
|
|
448
522
|
parentComponent: component,
|
|
449
523
|
slotName: CANVAS_PERSONALIZE_SLOT,
|
|
450
|
-
slotChildrenCount: (
|
|
451
|
-
indexInSlot: (
|
|
524
|
+
slotChildrenCount: (_a = component == null ? void 0 : component.slots) == null ? void 0 : _a[CANVAS_PERSONALIZE_SLOT].length,
|
|
525
|
+
indexInSlot: (_b = component == null ? void 0 : component.slots) == null ? void 0 : _b[CANVAS_PERSONALIZE_SLOT].findIndex(
|
|
452
526
|
({ _id }) => variantComponent._id === _id
|
|
453
527
|
)
|
|
454
528
|
});
|
|
@@ -458,34 +532,21 @@ function renderComponent({
|
|
|
458
532
|
const resolvedComponent = resolveRenderer == null ? void 0 : resolveRenderer(component);
|
|
459
533
|
if (resolvedComponent) {
|
|
460
534
|
const props = convertComponentToProps(component);
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
"data-component-index": indexInSlot,
|
|
471
|
-
"data-total-components": slotChildrenCount,
|
|
472
|
-
"data-component-name": component.type,
|
|
473
|
-
"data-is-placeholder": isPlaceholder ? "true" : void 0,
|
|
474
|
-
"data-is-localized": ((_a = component.parameters) == null ? void 0 : _a[CANVAS_LOCALE_TAG_PARAM]) ? "true" : void 0,
|
|
475
|
-
// TODO: use a proper way to get the component's title, don't assume that it's always "title"
|
|
476
|
-
// https://linear.app/uniform/issue/UNI-937/show-the-right-component-title-in-the-highlighter
|
|
477
|
-
"data-component-title": (_c = (_b = component.parameters) == null ? void 0 : _b.title) == null ? void 0 : _c.value
|
|
478
|
-
}),
|
|
479
|
-
isPlaceholder && emptyPlaceholder !== void 0 ? emptyPlaceholder() : h4(resolvedComponent, props),
|
|
480
|
-
h4("script", { "data-role": "component-end" })
|
|
481
|
-
] : [h4(resolvedComponent, props)];
|
|
482
|
-
return h4(UniformComponent, { data: component, resolveRenderer }, () => elementsToRender);
|
|
535
|
+
return h5(
|
|
536
|
+
UniformComponent,
|
|
537
|
+
{ data: component, resolveRenderer },
|
|
538
|
+
() => h5(
|
|
539
|
+
ContextualEditingComponentWrapper,
|
|
540
|
+
{ component, parentComponent, slotName, indexInSlot, slotChildrenCount },
|
|
541
|
+
{ default: () => h5(resolvedComponent, props), emptyPlaceholder }
|
|
542
|
+
)
|
|
543
|
+
);
|
|
483
544
|
}
|
|
484
545
|
console.warn(
|
|
485
546
|
`[canvas] found component of type '${component.type}' which the 'resolveRenderer' prop returned no component for. Nothing will be rendered. The resolveRenderer function may need to be extended to handle the new type.`,
|
|
486
547
|
component
|
|
487
548
|
);
|
|
488
|
-
return
|
|
549
|
+
return h5("");
|
|
489
550
|
}
|
|
490
551
|
var SlotContent = UniformSlot;
|
|
491
552
|
|