@uniformdev/canvas-vue 18.1.1-alpha.11 → 18.1.2-alpha.4

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.mjs CHANGED
@@ -1,24 +1,84 @@
1
- // src/components/Composition.ts
2
- import { CANVAS_ENRICHMENT_TAG_PARAM } from "@uniformdev/canvas";
1
+ // src/components/DefaultNotImplementedComponent.ts
2
+ import { CANVAS_LOCALIZATION_TYPE } from "@uniformdev/canvas";
3
+ import { defineComponent, h } from "vue-demi";
4
+ var wrapperStyles = {
5
+ borderLeft: "4px solid #e42535",
6
+ padding: "16px",
7
+ fontSize: "16px",
8
+ borderRadius: "0 8px 8px 0",
9
+ margin: "8px",
10
+ backgroundColor: "rgba(255, 255, 255, 0.45)",
11
+ color: "#1d3557"
12
+ };
13
+ var DefaultNotImplementedComponent = defineComponent({
14
+ name: "DefaultNotImplementedComponent",
15
+ props: {
16
+ component: {
17
+ type: Object,
18
+ required: true
19
+ }
20
+ },
21
+ setup(props, { attrs }) {
22
+ var _a;
23
+ const componentType = (_a = props.component) == null ? void 0 : _a.type;
24
+ if (componentType === CANVAS_LOCALIZATION_TYPE) {
25
+ h("div", { key: "content", style: wrapperStyles }, [
26
+ h("p", [
27
+ `Seems like localization is not enabled in your application. Please read our documentation on how to `,
28
+ h(
29
+ "a",
30
+ {
31
+ href: "https://docs.uniform.app/guides/composition/localization#activate-front-end",
32
+ target: "_blank",
33
+ style: { fontWeight: "bolder", textDecoration: "underline" }
34
+ },
35
+ "enable localization in your front-end application."
36
+ )
37
+ ])
38
+ ]);
39
+ }
40
+ return () => h("div", { key: "content", style: wrapperStyles }, [
41
+ h("h2", {}, `Component: ${componentType}`),
42
+ h("p", [
43
+ h("strong", `${componentType} has no Vue implementation. It may need to be added to your `),
44
+ h("code", {}, "resolveRenderer()"),
45
+ h("strong", {}, " function.")
46
+ ]),
47
+ h("details", {}, [
48
+ h("summary", {}, "props/attributes"),
49
+ h(
50
+ "pre",
51
+ {
52
+ style: {
53
+ overflowX: "auto"
54
+ }
55
+ },
56
+ `${JSON.stringify(attrs)}`
57
+ )
58
+ ])
59
+ ]);
60
+ }
61
+ });
62
+
63
+ // src/components/UniformComponent.ts
64
+ import {
65
+ CANVAS_ENRICHMENT_TAG_PARAM
66
+ } from "@uniformdev/canvas";
3
67
  import { isUsingUniformContext, Track, TrackSlot } from "@uniformdev/context-vue";
4
68
  import {
5
69
  computed,
6
- defineComponent,
7
- h,
70
+ defineComponent as defineComponent2,
71
+ h as h2,
8
72
  inject,
9
73
  provide,
10
74
  resolveComponent as nativeResolveComponent
11
75
  } from "vue-demi";
12
-
13
- // src/utils/constants.ts
14
- var CANVAS_COMPOSITION_TYPE = "Composition";
15
- var CANVAS_SLOT_CONTENT_TYPE = "SlotContent";
16
- var compositionInjectionKey = "uniformComposition";
17
- var resolveRendererInjectionKey = "uniformResolveRenderer";
18
-
19
- // src/components/Composition.ts
20
- var Composition = defineComponent({
21
- name: CANVAS_COMPOSITION_TYPE,
76
+ var uniformCurrentComponentInjectionKey = "uniformCurrentComponent";
77
+ var useUniformCurrentComponent = () => {
78
+ return inject(uniformCurrentComponentInjectionKey, {});
79
+ };
80
+ var UniformComponent = defineComponent2({
81
+ name: "UniformComponent",
22
82
  inheritAttrs: false,
23
83
  props: {
24
84
  data: {
@@ -26,8 +86,7 @@ var Composition = defineComponent({
26
86
  required: true
27
87
  },
28
88
  resolveRenderer: {
29
- type: Function,
30
- default: () => ({ type }) => nativeResolveComponent(type)
89
+ type: Function
31
90
  },
32
91
  behaviorTracking: {
33
92
  type: String,
@@ -35,14 +94,27 @@ var Composition = defineComponent({
35
94
  }
36
95
  },
37
96
  setup(props, context) {
38
- var _a, _b, _c;
97
+ var _a, _b;
98
+ const parentComponent = useUniformCurrentComponent();
39
99
  const data = computed(() => {
40
- var _a2, _b2;
41
- return (_b2 = props.data) != null ? _b2 : (_a2 = inject(compositionInjectionKey)) == null ? void 0 : _a2.value;
100
+ var _a2;
101
+ return (_a2 = props.data) != null ? _a2 : parentComponent == null ? void 0 : parentComponent.data;
102
+ });
103
+ if (!data) {
104
+ if (process.env.NODE_ENV === "development") {
105
+ console.warn(`[canvas-dev] UniformComponent was rendered with no data, nothing will be output.`);
106
+ }
107
+ return null;
108
+ }
109
+ const currentComponent = computed(() => {
110
+ var _a2, _b2, _c, _d;
111
+ return {
112
+ data: data.value,
113
+ resolveRenderer: (_b2 = (_a2 = props.resolveRenderer) != null ? _a2 : parentComponent == null ? void 0 : parentComponent.resolveRenderer) != null ? _b2 : ({ type }) => nativeResolveComponent(type),
114
+ behaviorTracking: (_d = (_c = props.behaviorTracking) != null ? _c : parentComponent == null ? void 0 : parentComponent.behaviorTracking) != null ? _d : "onView"
115
+ };
42
116
  });
43
- const resolveRenderer = (_a = props.resolveRenderer) != null ? _a : inject(resolveRendererInjectionKey);
44
- provide(compositionInjectionKey, data);
45
- provide(resolveRendererInjectionKey, resolveRenderer);
117
+ provide(uniformCurrentComponentInjectionKey, currentComponent.value);
46
118
  const slots = computed(() => {
47
119
  var _a2, _b2;
48
120
  return (_b2 = (_a2 = data.value) == null ? void 0 : _a2.slots) != null ? _b2 : {};
@@ -54,7 +126,7 @@ var Composition = defineComponent({
54
126
  const componentKey = computed(() => {
55
127
  return JSON.stringify(data.value);
56
128
  });
57
- const enrichmentTags = (_c = (_b = data.value.parameters) == null ? void 0 : _b[CANVAS_ENRICHMENT_TAG_PARAM]) == null ? void 0 : _c.value;
129
+ const enrichmentTags = (_b = (_a = data.value.parameters) == null ? void 0 : _a[CANVAS_ENRICHMENT_TAG_PARAM]) == null ? void 0 : _b.value;
58
130
  const renderChildren = () => {
59
131
  var _a2, _b2;
60
132
  return (_b2 = (_a2 = context.slots).default) == null ? void 0 : _b2.call(_a2, {
@@ -64,7 +136,7 @@ var Composition = defineComponent({
64
136
  };
65
137
  if (isUsingUniformContext()) {
66
138
  const TrackComponent = props.behaviorTracking === "onLoad" ? TrackSlot : Track;
67
- return () => h(
139
+ return () => h2(
68
140
  TrackComponent,
69
141
  { behavior: enrichmentTags, key: componentKey.value },
70
142
  renderChildren
@@ -73,70 +145,165 @@ var Composition = defineComponent({
73
145
  return renderChildren;
74
146
  }
75
147
  });
148
+ var UniformComponent_default = UniformComponent;
76
149
 
77
- // src/components/DefaultNotImplementedComponent.ts
78
- import { CANVAS_LOCALIZATION_TYPE } from "@uniformdev/canvas";
79
- import { defineComponent as defineComponent2, h as h2 } from "vue-demi";
80
- var wrapperStyles = {
81
- borderLeft: "4px solid #e42535",
82
- padding: "16px",
83
- fontSize: "16px",
84
- borderRadius: "0 8px 8px 0",
85
- margin: "8px",
86
- backgroundColor: "rgba(255, 255, 255, 0.45)",
87
- color: "#1d3557"
150
+ // src/components/UniformComposition.ts
151
+ import {
152
+ computed as computed3,
153
+ defineComponent as defineComponent3,
154
+ h as h3,
155
+ inject as inject2,
156
+ provide as provide2
157
+ } from "vue-demi";
158
+
159
+ // src/composables/useUniformContextualEditing.ts
160
+ import {
161
+ createCanvasChannel,
162
+ createUniformApiEnhancer,
163
+ IN_CONTEXT_EDITOR_EMBED_SCRIPT_ID,
164
+ IN_CONTEXT_EDITOR_QUERY_STRING_PARAM,
165
+ isUpdateCompositionMessage
166
+ } from "@uniformdev/canvas";
167
+ import { computed as computed2, onMounted, ref, watch } from "vue-demi";
168
+ var createApiEnhancer = createUniformApiEnhancer;
169
+ var registeredCompositionIds = /* @__PURE__ */ new Set();
170
+ var useUniformContextualEditing = ({
171
+ initialCompositionValue,
172
+ enhance = (message) => message.composition
173
+ }) => {
174
+ const contextualComposition = ref();
175
+ const composition = computed2(() => {
176
+ var _a;
177
+ return (_a = contextualComposition.value) != null ? _a : initialCompositionValue;
178
+ });
179
+ const channel = computed2(() => {
180
+ var _a;
181
+ if (!isInContextEditingMode()) {
182
+ return;
183
+ }
184
+ const channel2 = createCanvasChannel({
185
+ broadcastTo: [(_a = window.opener) != null ? _a : window.top],
186
+ listenTo: [window]
187
+ });
188
+ return channel2;
189
+ });
190
+ watch(
191
+ [channel, () => enhance, () => initialCompositionValue == null ? void 0 : initialCompositionValue._id],
192
+ () => {
193
+ if (!channel.value || registeredCompositionIds.has(initialCompositionValue._id)) {
194
+ return;
195
+ }
196
+ const unsubscribe = channel.value.on("update-composition", async (message) => {
197
+ if (!isUpdateCompositionMessage(message)) {
198
+ return;
199
+ }
200
+ const enhancedComposition = await enhance(message);
201
+ contextualComposition.value = enhancedComposition;
202
+ });
203
+ registeredCompositionIds.add(initialCompositionValue._id);
204
+ return () => {
205
+ unsubscribe();
206
+ registeredCompositionIds.delete(initialCompositionValue._id);
207
+ };
208
+ },
209
+ { immediate: true }
210
+ );
211
+ onMounted(() => {
212
+ if (!isInContextEditingMode()) {
213
+ return;
214
+ }
215
+ const existingScript = document.getElementById(IN_CONTEXT_EDITOR_EMBED_SCRIPT_ID);
216
+ if (existingScript) {
217
+ return;
218
+ }
219
+ const script = document.createElement("script");
220
+ script.id = IN_CONTEXT_EDITOR_EMBED_SCRIPT_ID;
221
+ script.src = getCanvasInContextEmbedScriptUrl();
222
+ script.async = true;
223
+ document.head.appendChild(script);
224
+ });
225
+ return {
226
+ composition
227
+ };
88
228
  };
89
- var DefaultNotImplementedComponent = defineComponent2({
90
- name: "DefaultNotImplementedComponent",
229
+ function getCanvasInContextEmbedScriptUrl() {
230
+ const scriptUrl = `${window.document.referrer}files/canvas-in-context-embed/index.js`;
231
+ return scriptUrl;
232
+ }
233
+ function isInContextEditingMode() {
234
+ if (typeof window === "undefined") {
235
+ return false;
236
+ }
237
+ const isOpenedByInContextEditor = new URLSearchParams(window.location.search).has(
238
+ IN_CONTEXT_EDITOR_QUERY_STRING_PARAM
239
+ );
240
+ const isAllowlistedReferrer = Boolean(
241
+ window.document.referrer.match(/(^https:\/\/|\.)(uniform.app|uniform.wtf|localhost:\d{4})\//)
242
+ );
243
+ return isOpenedByInContextEditor && isAllowlistedReferrer;
244
+ }
245
+
246
+ // src/utils/constants.ts
247
+ var globalCompositionEnhancerInjectionKey = "uniformGlobalCompositionEnhancer";
248
+
249
+ // src/components/UniformComposition.ts
250
+ var uniformCurrentCompositionInjectionKey = "uniformCurrentComposition";
251
+ var useUniformCurrentComposition = () => {
252
+ return inject2(uniformCurrentCompositionInjectionKey, {});
253
+ };
254
+ var UniformComposition = defineComponent3({
255
+ name: "UniformComposition",
256
+ inheritAttrs: false,
91
257
  props: {
92
- component: {
258
+ data: {
93
259
  type: Object,
94
260
  required: true
261
+ },
262
+ resolveRenderer: {
263
+ type: Function
264
+ },
265
+ behaviorTracking: {
266
+ type: String,
267
+ default: "onView"
268
+ },
269
+ contextualEditingEnhancer: {
270
+ type: Function
95
271
  }
96
272
  },
97
- setup(props, { attrs }) {
273
+ setup(props, context) {
98
274
  var _a;
99
- const componentType = (_a = props.component) == null ? void 0 : _a.type;
100
- if (componentType === CANVAS_LOCALIZATION_TYPE) {
101
- h2("div", { key: "content", style: wrapperStyles }, [
102
- h2("p", [
103
- `Seems like localization is not enabled in your application. Please read our documentation on how to `,
104
- h2(
105
- "a",
106
- {
107
- href: "https://docs.uniform.app/guides/composition/localization#activate-front-end",
108
- target: "_blank",
109
- style: { fontWeight: "bolder", textDecoration: "underline" }
110
- },
111
- "enable localization in your front-end application."
112
- )
113
- ])
114
- ]);
115
- }
116
- return () => h2("div", { key: "content", style: wrapperStyles }, [
117
- h2("h2", {}, `Component: ${componentType}`),
118
- h2("p", [
119
- h2("strong", `${componentType} has no Vue implementation. It may need to be added to your `),
120
- h2("code", {}, "resolveRenderer()"),
121
- h2("strong", {}, " function.")
122
- ]),
123
- h2("details", {}, [
124
- h2("summary", {}, "props/attributes"),
125
- h2(
126
- "pre",
127
- {
128
- style: {
129
- overflowX: "auto"
130
- }
131
- },
132
- `${JSON.stringify(attrs)}`
133
- )
134
- ])
135
- ]);
275
+ const inheritedEnhancer = inject2(
276
+ globalCompositionEnhancerInjectionKey,
277
+ (composition2) => composition2
278
+ );
279
+ const inheritedContextualEnhancer = (message) => inheritedEnhancer(message.composition);
280
+ const { composition } = useUniformContextualEditing({
281
+ initialCompositionValue: props.data,
282
+ enhance: (_a = props.contextualEditingEnhancer) != null ? _a : inheritedContextualEnhancer
283
+ });
284
+ provide2(uniformCurrentCompositionInjectionKey, {
285
+ data: composition,
286
+ behaviorTracking: props.behaviorTracking,
287
+ resolveRenderer: props.resolveRenderer
288
+ });
289
+ const compositionKey = computed3(() => {
290
+ return JSON.stringify(composition.value);
291
+ });
292
+ return () => h3(
293
+ UniformComponent_default,
294
+ {
295
+ key: compositionKey.value,
296
+ data: composition.value,
297
+ behaviorTracking: props.behaviorTracking,
298
+ resolveRenderer: props.resolveRenderer
299
+ },
300
+ context.slots.default
301
+ );
136
302
  }
137
303
  });
304
+ var Composition = UniformComposition;
138
305
 
139
- // src/components/SlotContent.ts
306
+ // src/components/UniformSlot.ts
140
307
  import {
141
308
  CANVAS_PERSONALIZE_TYPE,
142
309
  CANVAS_TEST_TYPE,
@@ -146,12 +313,7 @@ import {
146
313
  PLACEHOLDER_ID
147
314
  } from "@uniformdev/canvas";
148
315
  import { Personalize, Test } from "@uniformdev/context-vue";
149
- import {
150
- computed as computed2,
151
- defineComponent as defineComponent3,
152
- h as h3,
153
- inject as inject2
154
- } from "vue-demi";
316
+ import { computed as computed4, defineComponent as defineComponent4, h as h4 } from "vue-demi";
155
317
 
156
318
  // src/utils/convertComponentToProps.ts
157
319
  function convertComponentToProps(component) {
@@ -175,9 +337,9 @@ function normalizePropName(name) {
175
337
  return name.replace("$", "");
176
338
  }
177
339
 
178
- // src/components/SlotContent.ts
179
- var SlotContent = defineComponent3({
180
- name: CANVAS_SLOT_CONTENT_TYPE,
340
+ // src/components/UniformSlot.ts
341
+ var UniformSlot = defineComponent4({
342
+ name: "UniformSlot",
181
343
  inheritAttrs: false,
182
344
  props: {
183
345
  name: {
@@ -189,18 +351,18 @@ var SlotContent = defineComponent3({
189
351
  },
190
352
  setup(props, context) {
191
353
  var _a;
192
- const componentData = inject2(compositionInjectionKey);
193
- const resolveRenderer = (_a = props.resolveRenderer) != null ? _a : inject2(resolveRendererInjectionKey);
354
+ const { data: parentData, resolveRenderer: parentResolveRenderer } = useUniformCurrentComponent();
355
+ const resolveRenderer = (_a = props.resolveRenderer) != null ? _a : parentResolveRenderer;
194
356
  const emptyPlaceholder = context.slots.emptyPlaceholder;
195
- if (!componentData || !resolveRenderer) {
196
- throw new Error("<SlotContent /> can only be used inside a <Composition />");
357
+ if (!parentData || !resolveRenderer) {
358
+ throw new Error("<UniformSlot /> can only be used inside a <UniformComposition />");
197
359
  }
198
- const slotItems = computed2(() => {
360
+ const slotItems = computed4(() => {
199
361
  var _a2, _b, _c;
200
362
  if (props.name) {
201
- return (_b = (_a2 = componentData == null ? void 0 : componentData.value.slots) == null ? void 0 : _a2[props.name]) != null ? _b : [];
363
+ return (_b = (_a2 = parentData.slots) == null ? void 0 : _a2[props.name]) != null ? _b : [];
202
364
  }
203
- return Object.values((_c = componentData == null ? void 0 : componentData.value.slots) != null ? _c : {}).flat();
365
+ return Object.values((_c = parentData.slots) != null ? _c : {}).flat();
204
366
  });
205
367
  const childrenToRender = slotItems.value.map((component, index) => {
206
368
  const child = renderComponent({
@@ -208,7 +370,7 @@ var SlotContent = defineComponent3({
208
370
  resolveRenderer,
209
371
  indexInSlot: index,
210
372
  slotName: props.name,
211
- parentComponent: componentData.value,
373
+ parentComponent: parentData,
212
374
  slotChildrenCount: slotItems.value.length,
213
375
  emptyPlaceholder
214
376
  });
@@ -222,7 +384,7 @@ function renderPersonalizeComponent(component, resolveRenderer) {
222
384
  const parameters = component == null ? void 0 : component.parameters;
223
385
  const processedVariants = mapSlotToPersonalizedVariations((_a = component.slots) == null ? void 0 : _a.pz);
224
386
  const name = (_d = (_c = (_b = component.parameters) == null ? void 0 : _b.trackingEventName) == null ? void 0 : _c.value) != null ? _d : "Untitled Personalization";
225
- return h3(Personalize, {
387
+ return h4(Personalize, {
226
388
  name,
227
389
  component: (variant) => resolveRenderer(variant),
228
390
  variations: processedVariants,
@@ -234,7 +396,7 @@ function renderTestComponent(component, resolveRenderer) {
234
396
  const variants = (_b = (_a = component == null ? void 0 : component.slots) == null ? void 0 : _a.test) != null ? _b : [];
235
397
  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";
236
398
  const finalVariants = mapSlotToTestVariations(variants);
237
- return h3(Test, {
399
+ return h4(Test, {
238
400
  variations: finalVariants,
239
401
  name: testName,
240
402
  component: (variant) => resolveRenderer(variant)
@@ -268,7 +430,7 @@ function renderComponent({
268
430
  const shouldRenderContextualEditingTags = Boolean(component._id);
269
431
  const isPlaceholder = component._id === PLACEHOLDER_ID;
270
432
  const elementsToRender = shouldRenderContextualEditingTags ? [
271
- h3("script", {
433
+ h4("script", {
272
434
  "data-role": IN_CONTEXT_EDITOR_COMPONENT_START_ROLE,
273
435
  "data-parent-id": parentComponent == null ? void 0 : parentComponent._id,
274
436
  "data-parent-type": parentComponent == null ? void 0 : parentComponent.type,
@@ -280,17 +442,18 @@ function renderComponent({
280
442
  "data-is-placeholder": isPlaceholder ? "true" : void 0,
281
443
  "data-component-title": (_b = (_a = component.parameters) == null ? void 0 : _a.title) == null ? void 0 : _b.value
282
444
  }),
283
- isPlaceholder && emptyPlaceholder !== void 0 ? emptyPlaceholder() : h3(resolvedComponent, props),
284
- h3("script", { "data-role": "component-end" })
285
- ] : [h3(resolvedComponent, props)];
286
- return h3(Composition, { data: component, resolveRenderer }, () => elementsToRender);
445
+ isPlaceholder && emptyPlaceholder !== void 0 ? emptyPlaceholder() : h4(resolvedComponent, props),
446
+ h4("script", { "data-role": "component-end" })
447
+ ] : [h4(resolvedComponent, props)];
448
+ return h4(UniformComponent, { data: component, resolveRenderer }, () => elementsToRender);
287
449
  }
288
450
  console.warn(
289
451
  `[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.`,
290
452
  component
291
453
  );
292
- return h3("");
454
+ return h4("");
293
455
  }
456
+ var SlotContent = UniformSlot;
294
457
 
295
458
  // src/composables/useCompositionEventEffect.ts
296
459
  import {
@@ -298,7 +461,7 @@ import {
298
461
  createEventBus,
299
462
  subscribeToComposition
300
463
  } from "@uniformdev/canvas";
301
- import { watch } from "vue-demi";
464
+ import { watch as watch2 } from "vue-demi";
302
465
  async function useCompositionEventEffect({
303
466
  enabled,
304
467
  projectId,
@@ -306,7 +469,7 @@ async function useCompositionEventEffect({
306
469
  effect
307
470
  }) {
308
471
  let unsubscribe;
309
- watch(
472
+ watch2(
310
473
  [() => enabled, () => compositionIdRef.value, () => projectId],
311
474
  async () => {
312
475
  unsubscribe == null ? void 0 : unsubscribe();
@@ -328,113 +491,19 @@ async function useCompositionEventEffect({
328
491
  { immediate: true }
329
492
  );
330
493
  }
331
-
332
- // src/composables/useContextualEditing.ts
333
- import {
334
- createCanvasChannel,
335
- IN_CONTEXT_EDITOR_QUERY_STRING_PARAM,
336
- isUpdateCompositionMessage
337
- } from "@uniformdev/canvas";
338
- import { computed as computed3, onMounted, ref, watch as watch2 } from "vue-demi";
339
- var previewScriptId = "uniform-canvas-preview-script";
340
- var createApiEnhancer = ({ apiUrl }) => {
341
- return async (message) => {
342
- const response = await fetch(apiUrl, {
343
- method: "post",
344
- body: JSON.stringify({
345
- composition: message.composition,
346
- hash: message.hash
347
- }),
348
- headers: {
349
- "Content-Type": "application/json"
350
- }
351
- });
352
- const json = await response.json();
353
- if (!response.ok) {
354
- throw new Error("Error reading enhanced composition");
355
- }
356
- const body = json;
357
- return body.composition;
358
- };
359
- };
360
- var useContextualEditing = ({
361
- initialCompositionValue,
362
- enhance = (message) => message.composition
363
- }) => {
364
- const contextualComposition = ref();
365
- const channel = computed3(() => {
366
- var _a;
367
- if (!isInContextEditingMode()) {
368
- return;
369
- }
370
- const channel2 = createCanvasChannel({
371
- broadcastTo: [(_a = window.opener) != null ? _a : window.top],
372
- listenTo: [window]
373
- });
374
- return channel2;
375
- });
376
- watch2(
377
- [channel, () => enhance],
378
- () => {
379
- if (!channel.value) {
380
- return;
381
- }
382
- const unsubscribe = channel.value.on("update-composition", async (message) => {
383
- if (isUpdateCompositionMessage(message)) {
384
- const composition = await enhance(message);
385
- contextualComposition.value = composition;
386
- }
387
- });
388
- return () => {
389
- unsubscribe();
390
- };
391
- },
392
- { immediate: true }
393
- );
394
- onMounted(() => {
395
- if (!isInContextEditingMode()) {
396
- return;
397
- }
398
- const existingScript = document.getElementById(previewScriptId);
399
- if (existingScript) {
400
- return;
401
- }
402
- const script = document.createElement("script");
403
- script.id = previewScriptId;
404
- script.src = getCanvasInContextEmbedScriptUrl();
405
- script.async = true;
406
- document.head.appendChild(script);
407
- });
408
- return {
409
- composition: contextualComposition != null ? contextualComposition : initialCompositionValue
410
- };
411
- };
412
- function getCanvasInContextEmbedScriptUrl() {
413
- const scriptUrl = `${window.document.referrer}files/canvas-in-context-embed/index.js`;
414
- return scriptUrl;
415
- }
416
- function isInContextEditingMode() {
417
- if (typeof window === "undefined") {
418
- return false;
419
- }
420
- const isOpenedByInContextEditor = new URLSearchParams(window.location.search).has(
421
- IN_CONTEXT_EDITOR_QUERY_STRING_PARAM
422
- );
423
- const isAllowlistedReferrer = Boolean(
424
- window.document.referrer.match(/(^https:\/\/|\.)(uniform.app|uniform.wtf|localhost:\d{4})\//)
425
- );
426
- return isOpenedByInContextEditor && isAllowlistedReferrer;
427
- }
428
494
  export {
429
- CANVAS_COMPOSITION_TYPE,
430
- CANVAS_SLOT_CONTENT_TYPE,
431
495
  Composition,
432
496
  DefaultNotImplementedComponent,
433
497
  SlotContent,
434
- compositionInjectionKey,
498
+ UniformComponent,
499
+ UniformComposition,
500
+ UniformSlot,
435
501
  convertComponentToProps,
436
502
  createApiEnhancer,
437
- resolveRendererInjectionKey,
503
+ createUniformApiEnhancer,
504
+ globalCompositionEnhancerInjectionKey,
438
505
  useCompositionEventEffect,
439
- useContextualEditing
506
+ useUniformContextualEditing,
507
+ useUniformCurrentComponent,
508
+ useUniformCurrentComposition
440
509
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniformdev/canvas-vue",
3
- "version": "18.1.1-alpha.11+c81a052e2",
3
+ "version": "18.1.2-alpha.4+e9d268bce",
4
4
  "description": "Vue SDK for Uniform Canvas",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "main": "./dist/index.js",
@@ -22,7 +22,7 @@
22
22
  "format": "prettier --write \"src/**/*.{js,ts,tsx}\""
23
23
  },
24
24
  "dependencies": {
25
- "@uniformdev/canvas": "18.1.1-alpha.11+c81a052e2",
25
+ "@uniformdev/canvas": "18.1.2-alpha.4+e9d268bce",
26
26
  "@vue/test-utils": "2.2.7",
27
27
  "vue-demi": "^0.13.11"
28
28
  },
@@ -39,7 +39,7 @@
39
39
  "devDependencies": {
40
40
  "@testing-library/vue": "6.6.1",
41
41
  "@types/uuid": "9.0.0",
42
- "@uniformdev/context-vue": "18.1.1-alpha.11+c81a052e2",
42
+ "@uniformdev/context-vue": "18.1.2-alpha.4+e9d268bce",
43
43
  "@vue/server-test-utils": "1.3.0",
44
44
  "vue": "3.2.45",
45
45
  "vue-server-renderer": "2.7.14",
@@ -62,5 +62,5 @@
62
62
  "last 2 versions",
63
63
  "not dead"
64
64
  ],
65
- "gitHead": "c81a052e2c13c6d3d786d7030f11a7724a52b2da"
65
+ "gitHead": "e9d268bcef28fc22632f4968ca988e3b0b92d146"
66
66
  }