@uniformdev/canvas-vue 19.198.3-alpha.3 → 19.199.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.esm.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/components/DefaultNotImplementedComponent.ts
2
- import { CANVAS_LOCALIZATION_TYPE } from "@uniformdev/canvas";
2
+ import { CANVAS_LOCALIZATION_TYPE, EMPTY_COMPOSITION } from "@uniformdev/canvas";
3
3
  import { defineComponent, h } from "vue-demi";
4
4
  var wrapperStyles = {
5
5
  borderLeft: "4px solid #e42535",
@@ -21,8 +21,25 @@ var DefaultNotImplementedComponent = defineComponent({
21
21
  setup(props, { attrs }) {
22
22
  var _a;
23
23
  const componentType = (_a = props.component) == null ? void 0 : _a.type;
24
+ if (componentType === EMPTY_COMPOSITION.type) {
25
+ return () => h("div", {}, [
26
+ h("style", {
27
+ innerHTML: `@keyframes _uniformDelayedFadeIn { 0%,75% { opacity: 0; } to { opacity: 1; } }`
28
+ }),
29
+ h("p", { style: { animation: "_uniformDelayedFadeIn 3s" } }, [
30
+ h("span", {}, "This component only works inside Uniform Canvas editor."),
31
+ h("br"),
32
+ h("span", {}, "If you think this is an error, try "),
33
+ h(
34
+ "a",
35
+ { href: "", style: { fontWeight: "bolder", textDecoration: "underline" } },
36
+ "reloading the page"
37
+ )
38
+ ])
39
+ ]);
40
+ }
24
41
  if (componentType === CANVAS_LOCALIZATION_TYPE) {
25
- h("div", { key: "content", style: wrapperStyles }, [
42
+ return () => h("div", { key: "content", style: wrapperStyles }, [
26
43
  h("p", [
27
44
  `Seems like localization is not enabled in your application. Please read our documentation on how to `,
28
45
  h(
@@ -149,9 +166,9 @@ var UniformComponent_default = UniformComponent;
149
166
 
150
167
  // src/components/UniformComposition.ts
151
168
  import {
152
- computed as computed3,
153
- defineComponent as defineComponent4,
154
- h as h4,
169
+ computed as computed4,
170
+ defineComponent as defineComponent5,
171
+ h as h5,
155
172
  inject as inject2,
156
173
  provide as provide2,
157
174
  shallowRef
@@ -161,7 +178,7 @@ import {
161
178
  import {
162
179
  createCanvasChannel,
163
180
  createUniformApiEnhancer,
164
- EMPTY_COMPOSITION,
181
+ EMPTY_COMPOSITION as EMPTY_COMPOSITION2,
165
182
  IN_CONTEXT_EDITOR_EMBED_SCRIPT_ID,
166
183
  IN_CONTEXT_EDITOR_QUERY_STRING_PARAM,
167
184
  isAllowedReferrer,
@@ -197,8 +214,8 @@ var useUniformContextualEditing = ({
197
214
  return (_a = initialCompositionValue == null ? void 0 : initialCompositionValue.value) == null ? void 0 : _a._id;
198
215
  }],
199
216
  (_newValue, _oldValue, onCleanup) => {
200
- var _a, _b, _c, _d, _e, _f;
201
- 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)) {
217
+ var _a, _b, _c, _d, _e, _f, _g;
218
+ if (((_a = contextualComposition.value) == null ? void 0 : _a._id) && ((_b = initialCompositionValue == null ? void 0 : initialCompositionValue.value) == null ? void 0 : _b._id) !== EMPTY_COMPOSITION2._id && ((_c = initialCompositionValue == null ? void 0 : initialCompositionValue.value) == null ? void 0 : _c._id) !== ((_d = contextualComposition.value) == null ? void 0 : _d._id)) {
202
219
  contextualComposition.value = void 0;
203
220
  return;
204
221
  }
@@ -214,8 +231,11 @@ var useUniformContextualEditing = ({
214
231
  }
215
232
  const enhancedComposition = await enhance(message);
216
233
  contextualComposition.value = enhancedComposition;
234
+ latestEventTimeStamp = message.eventTimestamp;
217
235
  });
218
- registeredCompositionIds.add((_f = initialCompositionValue == null ? void 0 : initialCompositionValue.value) == null ? void 0 : _f._id);
236
+ if (((_f = initialCompositionValue == null ? void 0 : initialCompositionValue.value) == null ? void 0 : _f._id) !== EMPTY_COMPOSITION2._id) {
237
+ registeredCompositionIds.add((_g = initialCompositionValue == null ? void 0 : initialCompositionValue.value) == null ? void 0 : _g._id);
238
+ }
219
239
  onCleanup(() => {
220
240
  var _a2;
221
241
  unsubscribe();
@@ -326,12 +346,177 @@ var ContextualEditingComponentWrapper = defineComponent3({
326
346
  }
327
347
  });
328
348
 
349
+ // src/components/UniformSlot.ts
350
+ import {
351
+ CANVAS_PERSONALIZE_SLOT,
352
+ CANVAS_PERSONALIZE_TYPE,
353
+ CANVAS_TEST_SLOT,
354
+ CANVAS_TEST_TYPE,
355
+ mapSlotToPersonalizedVariations,
356
+ mapSlotToTestVariations
357
+ } from "@uniformdev/canvas";
358
+ import { Personalize, Test } from "@uniformdev/context-vue";
359
+ import { computed as computed3, defineComponent as defineComponent4, h as h4 } from "vue-demi";
360
+
361
+ // src/helpers/convertComponentToProps.ts
362
+ function convertComponentToProps(component) {
363
+ var _a;
364
+ const parameters = (_a = component.parameters) != null ? _a : {};
365
+ const flatParams = Object.entries(parameters).reduce(
366
+ (props, [key, { value }]) => ({
367
+ ...props,
368
+ [normalizePropName(key)]: value
369
+ }),
370
+ {}
371
+ );
372
+ const renderComponentProps = {
373
+ ...flatParams,
374
+ ...component.data,
375
+ component
376
+ };
377
+ return renderComponentProps;
378
+ }
379
+ function normalizePropName(name) {
380
+ return name.replace("$", "");
381
+ }
382
+
383
+ // src/components/UniformSlot.ts
384
+ var UniformSlot = defineComponent4({
385
+ name: "UniformSlot",
386
+ inheritAttrs: false,
387
+ props: {
388
+ name: {
389
+ type: String
390
+ },
391
+ resolveRenderer: {
392
+ type: Function
393
+ }
394
+ },
395
+ setup(props, context) {
396
+ var _a;
397
+ const { data: parentData, resolveRenderer: parentResolveRenderer } = useUniformCurrentComponent();
398
+ const resolveRenderer = (_a = props.resolveRenderer) != null ? _a : parentResolveRenderer;
399
+ const emptyPlaceholder = context.slots.emptyPlaceholder;
400
+ if (!parentData || !resolveRenderer) {
401
+ throw new Error("<UniformSlot /> can only be used inside a <UniformComposition />");
402
+ }
403
+ const slotItems = computed3(() => {
404
+ var _a2, _b, _c;
405
+ if (props.name) {
406
+ return (_b = (_a2 = parentData.slots) == null ? void 0 : _a2[props.name]) != null ? _b : [];
407
+ }
408
+ return Object.values((_c = parentData.slots) != null ? _c : {}).flat();
409
+ });
410
+ const childrenToRender = slotItems.value.map((component, index) => {
411
+ const child = renderComponent({
412
+ component,
413
+ resolveRenderer,
414
+ indexInSlot: index,
415
+ slotName: props.name,
416
+ parentComponent: parentData,
417
+ slotChildrenCount: slotItems.value.length,
418
+ emptyPlaceholder
419
+ });
420
+ return context.slots.default ? context.slots.default({ child, component }) : child;
421
+ });
422
+ return () => childrenToRender;
423
+ }
424
+ });
425
+ function renderPersonalizeComponent(component, resolveRenderer) {
426
+ var _a, _b, _c, _d, _e, _f;
427
+ const parameters = component == null ? void 0 : component.parameters;
428
+ const processedVariants = mapSlotToPersonalizedVariations((_a = component.slots) == null ? void 0 : _a.pz);
429
+ const name = (_d = (_c = (_b = component.parameters) == null ? void 0 : _b.trackingEventName) == null ? void 0 : _c.value) != null ? _d : "Untitled Personalization";
430
+ return h4(Personalize, {
431
+ name,
432
+ // TODO: Fix the `as unknown`
433
+ component: (variant) => resolveRenderer(variant),
434
+ variations: processedVariants,
435
+ count: Number((_f = (_e = parameters == null ? void 0 : parameters.count) == null ? void 0 : _e.value) != null ? _f : 1)
436
+ });
437
+ }
438
+ function renderTestComponent(component, resolveRenderer) {
439
+ var _a, _b, _c, _d, _e;
440
+ const variants = (_b = (_a = component == null ? void 0 : component.slots) == null ? void 0 : _a.test) != null ? _b : [];
441
+ 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";
442
+ const finalVariants = mapSlotToTestVariations(variants);
443
+ return h4(Test, {
444
+ variations: finalVariants,
445
+ name: testName,
446
+ component: (variant) => resolveRenderer(variant)
447
+ });
448
+ }
449
+ function renderComponent({
450
+ component,
451
+ resolveRenderer,
452
+ indexInSlot,
453
+ slotName,
454
+ parentComponent,
455
+ slotChildrenCount,
456
+ emptyPlaceholder
457
+ }) {
458
+ if (component.type === CANVAS_TEST_TYPE) {
459
+ return renderTestComponent(
460
+ component,
461
+ (variantComponent) => {
462
+ var _a, _b;
463
+ return renderComponent({
464
+ component: variantComponent,
465
+ resolveRenderer,
466
+ parentComponent: component,
467
+ slotName: CANVAS_TEST_SLOT,
468
+ slotChildrenCount: (_a = component == null ? void 0 : component.slots) == null ? void 0 : _a[CANVAS_TEST_SLOT].length,
469
+ indexInSlot: (_b = component == null ? void 0 : component.slots) == null ? void 0 : _b[CANVAS_TEST_SLOT].findIndex(
470
+ ({ _id }) => variantComponent._id === _id
471
+ )
472
+ });
473
+ }
474
+ );
475
+ }
476
+ if (component.type === CANVAS_PERSONALIZE_TYPE) {
477
+ return renderPersonalizeComponent(
478
+ component,
479
+ (variantComponent) => {
480
+ var _a, _b;
481
+ return renderComponent({
482
+ component: variantComponent,
483
+ resolveRenderer,
484
+ parentComponent: component,
485
+ slotName: CANVAS_PERSONALIZE_SLOT,
486
+ slotChildrenCount: (_a = component == null ? void 0 : component.slots) == null ? void 0 : _a[CANVAS_PERSONALIZE_SLOT].length,
487
+ indexInSlot: (_b = component == null ? void 0 : component.slots) == null ? void 0 : _b[CANVAS_PERSONALIZE_SLOT].findIndex(
488
+ ({ _id }) => variantComponent._id === _id
489
+ )
490
+ });
491
+ }
492
+ );
493
+ }
494
+ const resolvedComponent = resolveRenderer == null ? void 0 : resolveRenderer(component);
495
+ if (resolvedComponent) {
496
+ const props = convertComponentToProps(component);
497
+ return h4(
498
+ UniformComponent,
499
+ { data: component, resolveRenderer },
500
+ () => h4(
501
+ ContextualEditingComponentWrapper,
502
+ { component, parentComponent, slotName, indexInSlot, slotChildrenCount },
503
+ { default: () => h4(resolvedComponent, props), emptyPlaceholder }
504
+ )
505
+ );
506
+ }
507
+ console.warn(
508
+ `[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.`,
509
+ component
510
+ );
511
+ return h4("");
512
+ }
513
+
329
514
  // src/components/UniformComposition.ts
330
515
  var uniformCurrentCompositionInjectionKey = "uniformCurrentComposition";
331
516
  var useUniformCurrentComposition = () => {
332
517
  return inject2(uniformCurrentCompositionInjectionKey, {});
333
518
  };
334
- var UniformComposition = defineComponent4({
519
+ var UniformComposition = defineComponent5({
335
520
  name: "UniformComposition",
336
521
  inheritAttrs: false,
337
522
  props: {
@@ -350,7 +535,7 @@ var UniformComposition = defineComponent4({
350
535
  }
351
536
  },
352
537
  setup(props, context) {
353
- var _a;
538
+ var _a, _b;
354
539
  const inheritedEnhancer = inject2(
355
540
  globalCompositionEnhancerInjectionKey,
356
541
  (composition2) => composition2
@@ -366,14 +551,28 @@ var UniformComposition = defineComponent4({
366
551
  resolveRenderer: props.resolveRenderer,
367
552
  isContextualEditing
368
553
  });
369
- const compositionKey = computed3(() => {
554
+ const compositionKey = computed4(() => {
370
555
  return JSON.stringify(composition.value);
371
556
  });
372
- return () => h4(
557
+ const canRenderComposition = composition.value && ((_b = props.resolveRenderer) == null ? void 0 : _b.call(props, composition.value));
558
+ const hasNoChildren = !context.slots.default;
559
+ if (canRenderComposition && hasNoChildren) {
560
+ return () => h5(
561
+ ContextualEditingComponentWrapper,
562
+ { component: composition.value, key: compositionKey.value },
563
+ {
564
+ default: () => renderComponent({
565
+ component: composition.value,
566
+ resolveRenderer: props.resolveRenderer
567
+ })
568
+ }
569
+ );
570
+ }
571
+ return () => h5(
373
572
  ContextualEditingComponentWrapper,
374
573
  { component: composition.value, key: compositionKey.value },
375
574
  {
376
- default: () => h4(
575
+ default: () => h5(
377
576
  UniformComponent_default,
378
577
  {
379
578
  data: composition.value,
@@ -389,34 +588,34 @@ var UniformComposition = defineComponent4({
389
588
  var UniformComposition_default = UniformComposition;
390
589
 
391
590
  // src/components/UniformPlayground.ts
392
- import { EMPTY_COMPOSITION as EMPTY_COMPOSITION2 } from "@uniformdev/canvas";
393
- import { defineComponent as defineComponent5, h as h5 } from "vue-demi";
394
- var UniformPlayground = defineComponent5({
591
+ import { EMPTY_COMPOSITION as EMPTY_COMPOSITION3 } from "@uniformdev/canvas";
592
+ import { defineComponent as defineComponent6, h as h6 } from "vue-demi";
593
+ var UniformPlayground = defineComponent6({
395
594
  name: "UniformPlayground",
396
595
  inheritAttrs: false,
397
596
  props: {
398
597
  resolveRenderer: {
399
- type: Object
598
+ type: Function
400
599
  }
401
600
  },
402
601
  setup(props) {
403
- return () => h5(UniformComposition_default, { data: EMPTY_COMPOSITION2, resolveRenderer: props.resolveRenderer });
602
+ return () => h6(UniformComposition_default, { data: EMPTY_COMPOSITION3, resolveRenderer: props.resolveRenderer });
404
603
  }
405
604
  });
406
605
 
407
606
  // src/components/UniformRichText/nodes/HeadingRichTextNode.ts
408
- import { h as h6 } from "vue-demi";
607
+ import { h as h7 } from "vue-demi";
409
608
  var HeadingRichTextNode = (props, context) => {
410
609
  const { tag } = props.node;
411
- return h6(tag != null ? tag : "h1", {}, context.slots);
610
+ return h7(tag != null ? tag : "h1", {}, context.slots);
412
611
  };
413
612
 
414
613
  // src/components/UniformRichText/nodes/LinkRichTextNode.ts
415
614
  import { linkParamValueToHref } from "@uniformdev/richtext";
416
- import { h as h7 } from "vue-demi";
615
+ import { h as h8 } from "vue-demi";
417
616
  var LinkRichTextNode = (props, context) => {
418
617
  const { link } = props.node;
419
- return h7(
618
+ return h8(
420
619
  "a",
421
620
  {
422
621
  href: linkParamValueToHref(link)
@@ -426,10 +625,10 @@ var LinkRichTextNode = (props, context) => {
426
625
  };
427
626
 
428
627
  // src/components/UniformRichText/nodes/ListItemRichTextNode.ts
429
- import { h as h8 } from "vue-demi";
628
+ import { h as h9 } from "vue-demi";
430
629
  var ListItemRichTextNode = (props, context) => {
431
630
  const { value } = props.node;
432
- return h8(
631
+ return h9(
433
632
  "li",
434
633
  {
435
634
  value: Number.isFinite(value) && value > 0 ? value : void 0
@@ -439,18 +638,18 @@ var ListItemRichTextNode = (props, context) => {
439
638
  };
440
639
 
441
640
  // src/components/UniformRichText/nodes/ListRichTextNode.ts
442
- import { h as h9 } from "vue-demi";
641
+ import { h as h10 } from "vue-demi";
443
642
  var ListRichTextNode = (props, context) => {
444
643
  const { tag } = props.node;
445
- return h9(tag != null ? tag : "h1", {}, context.slots);
644
+ return h10(tag != null ? tag : "h1", {}, context.slots);
446
645
  };
447
646
 
448
647
  // src/components/UniformRichText/nodes/ParagraphRichTextNode.ts
449
648
  import { isPureDirection, isPureTextAlign } from "@uniformdev/richtext";
450
- import { h as h10 } from "vue-demi";
649
+ import { h as h11 } from "vue-demi";
451
650
  var ParagraphRichTextNode = (props, context) => {
452
651
  const { format, direction } = props.node;
453
- return h10(
652
+ return h11(
454
653
  "p",
455
654
  {
456
655
  dir: isPureDirection(direction) ? direction : void 0,
@@ -461,82 +660,87 @@ var ParagraphRichTextNode = (props, context) => {
461
660
  };
462
661
 
463
662
  // src/components/UniformRichText/nodes/QuoteRichTextNode.ts
464
- import { h as h11 } from "vue-demi";
663
+ import { h as h12 } from "vue-demi";
465
664
  var QuoteRichTextNode = (_, context) => {
466
- return h11("blockquote", {}, context.slots);
665
+ return h12("blockquote", {}, context.slots);
467
666
  };
468
667
 
469
668
  // src/components/UniformRichText/nodes/RootRichTextNode.ts
470
- import { h as h12 } from "vue-demi";
669
+ import { h as h13 } from "vue-demi";
471
670
  var RootRichTextNode = (props, c) => {
472
- return h12(() => c.slots.default ? c.slots.default() : null);
671
+ return h13(() => c.slots.default ? c.slots.default() : null);
473
672
  };
474
673
 
475
674
  // src/components/UniformRichText/nodes/TableCellRichTextNode.ts
476
675
  import { getRichTextTagFromTableCellHeaderState } from "@uniformdev/richtext";
477
- import { h as h13 } from "vue-demi";
676
+ import { h as h14 } from "vue-demi";
478
677
  var TableCellRichTextNode = (props, context) => {
479
678
  const { headerState } = props.node;
480
679
  const tag = getRichTextTagFromTableCellHeaderState(headerState);
481
- return h13(tag, {}, context.slots);
680
+ return h14(tag, {}, context.slots);
482
681
  };
483
682
 
484
683
  // src/components/UniformRichText/nodes/TableRichTextNode.ts
485
- import { h as h14 } from "vue-demi";
684
+ import { h as h15 } from "vue-demi";
486
685
  var TableRichTextNode = (_, context) => {
487
- return h14("table", {}, h14("tbody", {}, context.slots));
686
+ return h15("table", {}, h15("tbody", {}, context.slots));
488
687
  };
489
688
 
490
689
  // src/components/UniformRichText/nodes/TableRowRichTextNode.ts
491
- import { h as h15 } from "vue-demi";
690
+ import { h as h16 } from "vue-demi";
492
691
  var TableRowRichTextNode = (_, context) => {
493
- return h15("tr", {}, context.slots);
692
+ return h16("tr", {}, context.slots);
494
693
  };
495
694
 
496
695
  // src/components/UniformRichText/nodes/TextRichTextNode.ts
497
696
  import { getRichTextTagsFromTextFormat } from "@uniformdev/richtext";
498
- import { h as h16 } from "vue-demi";
697
+ import { h as h17 } from "vue-demi";
499
698
  var TextRichTextNode = (props) => {
500
699
  const { format, text } = props.node;
501
700
  const tags = getRichTextTagsFromTextFormat(format);
502
701
  return tags.length > 0 ? tags.reduceRight(
503
702
  (children, tag) => {
504
- return h16(tag, null, children);
703
+ return h17(tag, null, children);
505
704
  },
506
705
  {
507
706
  default: () => text
508
707
  }
509
- ) : h16(() => text);
708
+ ) : h17(() => text);
510
709
  };
511
710
 
512
711
  // src/components/UniformRichText/UniformRichText.ts
712
+ import {
713
+ ATTRIBUTE_COMPONENT_ID,
714
+ ATTRIBUTE_PARAMETER_ID,
715
+ ATTRIBUTE_PARAMETER_TYPE
716
+ } from "@uniformdev/canvas";
513
717
  import { isRichTextNode as isRichTextNode2, isRichTextValueConsideredEmpty } from "@uniformdev/richtext";
514
- import { computed as computed4, defineComponent as defineComponent7, h as h21 } from "vue-demi";
718
+ import { computed as computed5, defineComponent as defineComponent8, h as h22 } from "vue-demi";
515
719
 
516
720
  // src/components/UniformRichText/UniformRichTextNode.ts
517
721
  import { isRichTextNode } from "@uniformdev/richtext";
518
- import { defineComponent as defineComponent6, h as h20 } from "vue-demi";
722
+ import { defineComponent as defineComponent7, h as h21 } from "vue-demi";
519
723
 
520
724
  // src/components/UniformRichText/nodes/CodeRichTextNode.ts
521
- import { h as h17 } from "vue-demi";
725
+ import { h as h18 } from "vue-demi";
522
726
  var CodeRichTextNode = (_, context) => {
523
- return h17("pre", {}, h17("code", {}, context.slots));
727
+ return h18("pre", {}, h18("code", {}, context.slots));
524
728
  };
525
729
 
526
730
  // src/components/UniformRichText/nodes/LinebreakRichTextNode.ts
527
- import { h as h18 } from "vue-demi";
731
+ import { h as h19 } from "vue-demi";
528
732
  var LinebreakRichTextNode = () => {
529
- return h18("br", {});
733
+ return h19("br", {});
530
734
  };
531
735
 
532
736
  // src/components/UniformRichText/nodes/TabRichTextNode.ts
533
- import { h as h19 } from "vue-demi";
737
+ import { h as h20 } from "vue-demi";
534
738
  var TabRichTextNode = () => {
535
- return h19("", {}, " ");
739
+ return h20("", {}, " ");
536
740
  };
537
741
 
538
742
  // src/components/UniformRichText/UniformRichTextNode.ts
539
- var UniformRichTextNode = defineComponent6({
743
+ var UniformRichTextNode = defineComponent7({
540
744
  name: "UniformRichTextNode",
541
745
  props: {
542
746
  node: {
@@ -560,13 +764,13 @@ var UniformRichTextNode = defineComponent6({
560
764
  return () => null;
561
765
  }
562
766
  const children = node.children ? node.children.map(
563
- (childNode) => h20(
767
+ (childNode) => h21(
564
768
  UniformRichTextNode,
565
769
  { node: childNode, resolveRichTextRenderer: props.resolveRichTextRenderer },
566
770
  context.slots
567
771
  )
568
772
  ) : [];
569
- return () => h20(NodeRenderer, { node, children: h20(() => children) }, () => children);
773
+ return () => h21(NodeRenderer, { node, children: h21(() => children) }, () => children);
570
774
  }
571
775
  });
572
776
  var rendererMap = /* @__PURE__ */ new Map([
@@ -590,7 +794,7 @@ var resolveRichTextDefaultRenderer = (node) => {
590
794
  };
591
795
 
592
796
  // src/components/UniformRichText/UniformRichText.ts
593
- var UniformRichText = defineComponent7({
797
+ var UniformRichText = defineComponent8({
594
798
  name: "UniformRichText",
595
799
  props: {
596
800
  parameterId: {
@@ -601,21 +805,26 @@ var UniformRichText = defineComponent7({
601
805
  type: Function,
602
806
  required: false
603
807
  },
808
+ as: {
809
+ type: String,
810
+ required: false
811
+ },
604
812
  placeholder: {
605
813
  type: String
606
814
  }
607
815
  },
608
816
  setup(props, context) {
609
817
  var _a, _b;
818
+ const tag = props.as;
610
819
  const { data: componentData, contextualEditingDefaultPlaceholder } = useUniformCurrentComponent();
611
820
  const { isContextualEditing } = useUniformCurrentComposition();
612
- const parameter = computed4(
821
+ const parameter = computed5(
613
822
  () => {
614
823
  var _a2;
615
824
  return (_a2 = componentData == null ? void 0 : componentData.parameters) == null ? void 0 : _a2[props.parameterId];
616
825
  }
617
826
  );
618
- const value = computed4(() => {
827
+ const value = computed5(() => {
619
828
  var _a2;
620
829
  return (_a2 = parameter.value) == null ? void 0 : _a2.value;
621
830
  });
@@ -625,189 +834,63 @@ var UniformRichText = defineComponent7({
625
834
  }
626
835
  const placeholderProp = (_b = props.placeholder) != null ? _b : contextualEditingDefaultPlaceholder;
627
836
  const computedPlaceholder = typeof placeholderProp === "function" ? placeholderProp({ id: props.parameterId }) : placeholderProp;
628
- if (isRichTextNode2(root)) {
629
- return isContextualEditing && isRichTextValueConsideredEmpty(value.value) ? () => h21("p", {}, h21("i", {}, computedPlaceholder)) : () => h21(
837
+ if (!isRichTextNode2(root)) {
838
+ return () => null;
839
+ }
840
+ if ((isContextualEditing == null ? void 0 : isContextualEditing.value) && isRichTextValueConsideredEmpty(value.value)) {
841
+ return () => maybeWrapInTag(
842
+ tag,
843
+ { isContextualEditing, componentId: componentData == null ? void 0 : componentData._id, parameterId: props.parameterId },
844
+ h22(
845
+ "p",
846
+ // If we don't have a wrapper, then we need to annotate this `p` element
847
+ tag ? {} : getRichTextAnnotations({ componentId: componentData == null ? void 0 : componentData._id, parameterId: props.parameterId }),
848
+ h22("i", {}, computedPlaceholder)
849
+ )
850
+ );
851
+ }
852
+ return () => maybeWrapInTag(
853
+ tag,
854
+ { isContextualEditing, componentId: componentData == null ? void 0 : componentData._id, parameterId: props.parameterId },
855
+ h22(
630
856
  UniformRichTextNode,
631
857
  {
632
858
  node: root,
633
859
  resolveRichTextRenderer: props.resolveRichTextRenderer
634
860
  },
635
861
  context.slots
636
- );
637
- } else {
638
- return () => null;
639
- }
640
- }
641
- });
642
-
643
- // src/components/UniformSlot.ts
644
- import {
645
- CANVAS_PERSONALIZE_SLOT,
646
- CANVAS_PERSONALIZE_TYPE,
647
- CANVAS_TEST_SLOT,
648
- CANVAS_TEST_TYPE,
649
- mapSlotToPersonalizedVariations,
650
- mapSlotToTestVariations
651
- } from "@uniformdev/canvas";
652
- import { Personalize, Test } from "@uniformdev/context-vue";
653
- import { computed as computed5, defineComponent as defineComponent8, h as h22 } from "vue-demi";
654
-
655
- // src/helpers/convertComponentToProps.ts
656
- function convertComponentToProps(component) {
657
- var _a;
658
- const parameters = (_a = component.parameters) != null ? _a : {};
659
- const flatParams = Object.entries(parameters).reduce(
660
- (props, [key, { value }]) => ({
661
- ...props,
662
- [normalizePropName(key)]: value
663
- }),
664
- {}
665
- );
666
- const renderComponentProps = {
667
- ...flatParams,
668
- ...component.data,
669
- component
670
- };
671
- return renderComponentProps;
672
- }
673
- function normalizePropName(name) {
674
- return name.replace("$", "");
675
- }
676
-
677
- // src/components/UniformSlot.ts
678
- var UniformSlot = defineComponent8({
679
- name: "UniformSlot",
680
- inheritAttrs: false,
681
- props: {
682
- name: {
683
- type: String
684
- },
685
- resolveRenderer: {
686
- type: Function
687
- }
688
- },
689
- setup(props, context) {
690
- var _a;
691
- const { data: parentData, resolveRenderer: parentResolveRenderer } = useUniformCurrentComponent();
692
- const resolveRenderer = (_a = props.resolveRenderer) != null ? _a : parentResolveRenderer;
693
- const emptyPlaceholder = context.slots.emptyPlaceholder;
694
- if (!parentData || !resolveRenderer) {
695
- throw new Error("<UniformSlot /> can only be used inside a <UniformComposition />");
696
- }
697
- const slotItems = computed5(() => {
698
- var _a2, _b, _c;
699
- if (props.name) {
700
- return (_b = (_a2 = parentData.slots) == null ? void 0 : _a2[props.name]) != null ? _b : [];
701
- }
702
- return Object.values((_c = parentData.slots) != null ? _c : {}).flat();
703
- });
704
- const childrenToRender = slotItems.value.map((component, index) => {
705
- const child = renderComponent({
706
- component,
707
- resolveRenderer,
708
- indexInSlot: index,
709
- slotName: props.name,
710
- parentComponent: parentData,
711
- slotChildrenCount: slotItems.value.length,
712
- emptyPlaceholder
713
- });
714
- return context.slots.default ? context.slots.default({ child, component }) : child;
715
- });
716
- return () => childrenToRender;
717
- }
718
- });
719
- function renderPersonalizeComponent(component, resolveRenderer) {
720
- var _a, _b, _c, _d, _e, _f;
721
- const parameters = component == null ? void 0 : component.parameters;
722
- const processedVariants = mapSlotToPersonalizedVariations((_a = component.slots) == null ? void 0 : _a.pz);
723
- const name = (_d = (_c = (_b = component.parameters) == null ? void 0 : _b.trackingEventName) == null ? void 0 : _c.value) != null ? _d : "Untitled Personalization";
724
- return h22(Personalize, {
725
- name,
726
- // TODO: Fix the `as unknown`
727
- component: (variant) => resolveRenderer(variant),
728
- variations: processedVariants,
729
- count: Number((_f = (_e = parameters == null ? void 0 : parameters.count) == null ? void 0 : _e.value) != null ? _f : 1)
730
- });
731
- }
732
- function renderTestComponent(component, resolveRenderer) {
733
- var _a, _b, _c, _d, _e;
734
- const variants = (_b = (_a = component == null ? void 0 : component.slots) == null ? void 0 : _a.test) != null ? _b : [];
735
- 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";
736
- const finalVariants = mapSlotToTestVariations(variants);
737
- return h22(Test, {
738
- variations: finalVariants,
739
- name: testName,
740
- component: (variant) => resolveRenderer(variant)
741
- });
742
- }
743
- function renderComponent({
744
- component,
745
- resolveRenderer,
746
- indexInSlot,
747
- slotName,
748
- parentComponent,
749
- slotChildrenCount,
750
- emptyPlaceholder
751
- }) {
752
- if (component.type === CANVAS_TEST_TYPE) {
753
- return renderTestComponent(
754
- component,
755
- (variantComponent) => {
756
- var _a, _b;
757
- return renderComponent({
758
- component: variantComponent,
759
- resolveRenderer,
760
- parentComponent: component,
761
- slotName: CANVAS_TEST_SLOT,
762
- slotChildrenCount: (_a = component == null ? void 0 : component.slots) == null ? void 0 : _a[CANVAS_TEST_SLOT].length,
763
- indexInSlot: (_b = component == null ? void 0 : component.slots) == null ? void 0 : _b[CANVAS_TEST_SLOT].findIndex(
764
- ({ _id }) => variantComponent._id === _id
765
- )
766
- });
767
- }
768
- );
769
- }
770
- if (component.type === CANVAS_PERSONALIZE_TYPE) {
771
- return renderPersonalizeComponent(
772
- component,
773
- (variantComponent) => {
774
- var _a, _b;
775
- return renderComponent({
776
- component: variantComponent,
777
- resolveRenderer,
778
- parentComponent: component,
779
- slotName: CANVAS_PERSONALIZE_SLOT,
780
- slotChildrenCount: (_a = component == null ? void 0 : component.slots) == null ? void 0 : _a[CANVAS_PERSONALIZE_SLOT].length,
781
- indexInSlot: (_b = component == null ? void 0 : component.slots) == null ? void 0 : _b[CANVAS_PERSONALIZE_SLOT].findIndex(
782
- ({ _id }) => variantComponent._id === _id
783
- )
784
- });
785
- }
786
- );
787
- }
788
- const resolvedComponent = resolveRenderer == null ? void 0 : resolveRenderer(component);
789
- if (resolvedComponent) {
790
- const props = convertComponentToProps(component);
791
- return h22(
792
- UniformComponent,
793
- { data: component, resolveRenderer },
794
- () => h22(
795
- ContextualEditingComponentWrapper,
796
- { component, parentComponent, slotName, indexInSlot, slotChildrenCount },
797
- { default: () => h22(resolvedComponent, props), emptyPlaceholder }
798
862
  )
799
863
  );
800
864
  }
801
- console.warn(
802
- `[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.`,
803
- component
865
+ });
866
+ var maybeWrapInTag = (tag, {
867
+ isContextualEditing,
868
+ componentId,
869
+ parameterId
870
+ }, children) => {
871
+ if (!tag) {
872
+ return children;
873
+ }
874
+ return h22(
875
+ tag,
876
+ !(isContextualEditing == null ? void 0 : isContextualEditing.value) ? {} : getRichTextAnnotations({ componentId, parameterId }),
877
+ children
804
878
  );
805
- return h22("");
806
- }
879
+ };
880
+ var getRichTextAnnotations = ({
881
+ componentId,
882
+ parameterId
883
+ }) => {
884
+ return {
885
+ [ATTRIBUTE_COMPONENT_ID]: componentId,
886
+ [ATTRIBUTE_PARAMETER_ID]: parameterId,
887
+ [ATTRIBUTE_PARAMETER_TYPE]: "richText"
888
+ };
889
+ };
807
890
 
808
891
  // src/components/UniformText.ts
809
892
  import {
810
- ATTRIBUTE_PARAMETER_TYPE,
893
+ ATTRIBUTE_PARAMETER_TYPE as ATTRIBUTE_PARAMETER_TYPE2,
811
894
  ATTRIBUTE_PARAMETER_VALUE,
812
895
  ATTRIBUTE_PLACEHOLDER
813
896
  } from "@uniformdev/canvas";
@@ -885,7 +968,7 @@ var UniformText = defineComponent9({
885
968
  isMultiline: props.isMultiline
886
969
  }),
887
970
  [ATTRIBUTE_PARAMETER_VALUE]: (_b = value.value) != null ? _b : "",
888
- [ATTRIBUTE_PARAMETER_TYPE]: "text",
971
+ [ATTRIBUTE_PARAMETER_TYPE2]: "text",
889
972
  [ATTRIBUTE_PLACEHOLDER]: computedPlaceholder,
890
973
  style: props.isMultiline ? { whiteSpace: "pre-wrap" } : {},
891
974
  onFocus: handleOnFocus,
@@ -960,6 +1043,7 @@ export {
960
1043
  createUniformApiEnhancer,
961
1044
  getParameterAttributes,
962
1045
  globalCompositionEnhancerInjectionKey,
1046
+ renderComponent,
963
1047
  useCompositionEventEffect,
964
1048
  useUniformContextualEditing,
965
1049
  useUniformCurrentComponent,