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