@uniformdev/canvas-vue 17.5.0 → 17.5.1-alpha.7
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 +149 -6
- package/dist/index.esm.js +1 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +7 -7
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as vue_demi from 'vue-demi';
|
|
2
2
|
import { ConcreteComponent, PropType, Ref } from 'vue-demi';
|
|
3
|
-
import { ComponentInstance, ComponentParameter, SubscribeToCompositionOptions } from '@uniformdev/canvas';
|
|
3
|
+
import { ComponentInstance, ComponentParameter, SubscribeToCompositionOptions, UpdateCompositionMessage, RootComponentInstance } from '@uniformdev/canvas';
|
|
4
4
|
|
|
5
5
|
interface TestComponent {
|
|
6
6
|
slots?: {
|
|
@@ -63,7 +63,7 @@ declare const Composition: vue_demi.DefineComponent<{
|
|
|
63
63
|
[key: string]: any;
|
|
64
64
|
}>) | (() => vue_demi.VNode<vue_demi.RendererNode, vue_demi.RendererElement, {
|
|
65
65
|
[key: string]: any;
|
|
66
|
-
}>[] | undefined), unknown, {}, {}, vue_demi.ComponentOptionsMixin, vue_demi.ComponentOptionsMixin,
|
|
66
|
+
}>[] | undefined), unknown, {}, {}, vue_demi.ComponentOptionsMixin, vue_demi.ComponentOptionsMixin, {}, string, vue_demi.VNodeProps & vue_demi.AllowedComponentProps & vue_demi.ComponentCustomProps, Readonly<vue_demi.ExtractPropTypes<{
|
|
67
67
|
data: {
|
|
68
68
|
type: PropType<ComponentInstance>;
|
|
69
69
|
required: true;
|
|
@@ -92,7 +92,6 @@ declare type SlotComponentProps = {
|
|
|
92
92
|
};
|
|
93
93
|
/**
|
|
94
94
|
* Renders the content of a Canvas composition's slot
|
|
95
|
-
* @vue-prop {String} name - name of the Uniform Canvas slot you wish to scope to
|
|
96
95
|
*/
|
|
97
96
|
declare const SlotContent: vue_demi.DefineComponent<{
|
|
98
97
|
name: {
|
|
@@ -103,7 +102,7 @@ declare const SlotContent: vue_demi.DefineComponent<{
|
|
|
103
102
|
};
|
|
104
103
|
}, () => (ConcreteComponent<any, any, any, vue_demi.ComputedOptions, vue_demi.MethodOptions> | vue_demi.VNode<vue_demi.RendererNode, vue_demi.RendererElement, {
|
|
105
104
|
[key: string]: any;
|
|
106
|
-
}>[])[], unknown, {}, {}, vue_demi.ComponentOptionsMixin, vue_demi.ComponentOptionsMixin,
|
|
105
|
+
}>[])[], unknown, {}, {}, vue_demi.ComponentOptionsMixin, vue_demi.ComponentOptionsMixin, {}, string, vue_demi.VNodeProps & vue_demi.AllowedComponentProps & vue_demi.ComponentCustomProps, Readonly<vue_demi.ExtractPropTypes<{
|
|
107
106
|
name: {
|
|
108
107
|
type: PropType<string | undefined>;
|
|
109
108
|
};
|
|
@@ -122,7 +121,7 @@ declare const DefaultNotImplementedComponent: vue_demi.DefineComponent<{
|
|
|
122
121
|
};
|
|
123
122
|
}, () => vue_demi.VNode<vue_demi.RendererNode, vue_demi.RendererElement, {
|
|
124
123
|
[key: string]: any;
|
|
125
|
-
}>, unknown, {}, {}, vue_demi.ComponentOptionsMixin, vue_demi.ComponentOptionsMixin,
|
|
124
|
+
}>, unknown, {}, {}, vue_demi.ComponentOptionsMixin, vue_demi.ComponentOptionsMixin, {}, string, vue_demi.VNodeProps & vue_demi.AllowedComponentProps & vue_demi.ComponentCustomProps, Readonly<vue_demi.ExtractPropTypes<{
|
|
126
125
|
component: {
|
|
127
126
|
type: PropType<ComponentInstance>;
|
|
128
127
|
required: true;
|
|
@@ -145,6 +144,150 @@ declare type UseCompositionEventEffectOptions = Omit<Partial<SubscribeToComposit
|
|
|
145
144
|
/** A composable to manage a subscription to a realtime event on a composition */
|
|
146
145
|
declare function useCompositionEventEffect({ enabled, projectId, compositionIdRef, effect, }: UseCompositionEventEffectOptions): Promise<void>;
|
|
147
146
|
|
|
147
|
+
declare const createApiEnhancer: ({ apiUrl }: {
|
|
148
|
+
apiUrl: string;
|
|
149
|
+
}) => (message: UpdateCompositionMessage) => Promise<{
|
|
150
|
+
type: string;
|
|
151
|
+
parameters?: {
|
|
152
|
+
[key: string]: {
|
|
153
|
+
value: unknown;
|
|
154
|
+
type: string;
|
|
155
|
+
connectedData?: {
|
|
156
|
+
pointer: string;
|
|
157
|
+
syntax: "jptr";
|
|
158
|
+
required?: boolean | undefined;
|
|
159
|
+
} | undefined;
|
|
160
|
+
};
|
|
161
|
+
} | undefined;
|
|
162
|
+
variant?: string | undefined;
|
|
163
|
+
slots?: {
|
|
164
|
+
[key: string]: {
|
|
165
|
+
type: string;
|
|
166
|
+
parameters?: {
|
|
167
|
+
[key: string]: {
|
|
168
|
+
value: unknown;
|
|
169
|
+
type: string;
|
|
170
|
+
connectedData?: {
|
|
171
|
+
pointer: string;
|
|
172
|
+
syntax: "jptr";
|
|
173
|
+
required?: boolean | undefined;
|
|
174
|
+
} | undefined;
|
|
175
|
+
};
|
|
176
|
+
} | undefined;
|
|
177
|
+
variant?: string | undefined;
|
|
178
|
+
slots?: {
|
|
179
|
+
[key: string]: any[];
|
|
180
|
+
} | undefined;
|
|
181
|
+
_id?: string | undefined;
|
|
182
|
+
_pattern?: string | undefined;
|
|
183
|
+
_dataResources?: {
|
|
184
|
+
[key: string]: {
|
|
185
|
+
type: string;
|
|
186
|
+
isPatternParameter?: boolean | undefined;
|
|
187
|
+
variables?: {
|
|
188
|
+
[key: string]: string;
|
|
189
|
+
} | undefined;
|
|
190
|
+
};
|
|
191
|
+
} | undefined;
|
|
192
|
+
_patternDataResources?: {
|
|
193
|
+
[key: string]: {
|
|
194
|
+
type: string;
|
|
195
|
+
isPatternParameter?: boolean | undefined;
|
|
196
|
+
variables?: {
|
|
197
|
+
[key: string]: string;
|
|
198
|
+
} | undefined;
|
|
199
|
+
};
|
|
200
|
+
} | undefined;
|
|
201
|
+
_patternError?: "NOTFOUND" | "CYCLIC" | undefined;
|
|
202
|
+
}[];
|
|
203
|
+
} | undefined;
|
|
204
|
+
_id: string;
|
|
205
|
+
_slug?: string | null | undefined;
|
|
206
|
+
_name: string;
|
|
207
|
+
_dataResources?: {
|
|
208
|
+
[key: string]: {
|
|
209
|
+
type: string;
|
|
210
|
+
isPatternParameter?: boolean | undefined;
|
|
211
|
+
variables?: {
|
|
212
|
+
[key: string]: string;
|
|
213
|
+
} | undefined;
|
|
214
|
+
};
|
|
215
|
+
} | undefined;
|
|
216
|
+
}>;
|
|
217
|
+
declare const useCompositionInstance: ({ composition, enhance, }: {
|
|
218
|
+
composition: RootComponentInstance;
|
|
219
|
+
enhance?: ((composition: UpdateCompositionMessage) => RootComponentInstance | Promise<RootComponentInstance>) | undefined;
|
|
220
|
+
}) => {
|
|
221
|
+
composition: vue_demi.Ref<{
|
|
222
|
+
type: string;
|
|
223
|
+
parameters?: {
|
|
224
|
+
[key: string]: {
|
|
225
|
+
value: unknown;
|
|
226
|
+
type: string;
|
|
227
|
+
connectedData?: {
|
|
228
|
+
pointer: string;
|
|
229
|
+
syntax: "jptr";
|
|
230
|
+
required?: boolean | undefined;
|
|
231
|
+
} | undefined;
|
|
232
|
+
};
|
|
233
|
+
} | undefined;
|
|
234
|
+
variant?: string | undefined;
|
|
235
|
+
slots?: {
|
|
236
|
+
[key: string]: {
|
|
237
|
+
type: string;
|
|
238
|
+
parameters?: {
|
|
239
|
+
[key: string]: {
|
|
240
|
+
value: unknown;
|
|
241
|
+
type: string;
|
|
242
|
+
connectedData?: {
|
|
243
|
+
pointer: string;
|
|
244
|
+
syntax: "jptr";
|
|
245
|
+
required?: boolean | undefined;
|
|
246
|
+
} | undefined;
|
|
247
|
+
};
|
|
248
|
+
} | undefined;
|
|
249
|
+
variant?: string | undefined;
|
|
250
|
+
slots?: {
|
|
251
|
+
[key: string]: any[];
|
|
252
|
+
} | undefined;
|
|
253
|
+
_id?: string | undefined;
|
|
254
|
+
_pattern?: string | undefined;
|
|
255
|
+
_dataResources?: {
|
|
256
|
+
[key: string]: {
|
|
257
|
+
type: string;
|
|
258
|
+
isPatternParameter?: boolean | undefined;
|
|
259
|
+
variables?: {
|
|
260
|
+
[key: string]: string;
|
|
261
|
+
} | undefined;
|
|
262
|
+
};
|
|
263
|
+
} | undefined;
|
|
264
|
+
_patternDataResources?: {
|
|
265
|
+
[key: string]: {
|
|
266
|
+
type: string;
|
|
267
|
+
isPatternParameter?: boolean | undefined;
|
|
268
|
+
variables?: {
|
|
269
|
+
[key: string]: string;
|
|
270
|
+
} | undefined;
|
|
271
|
+
};
|
|
272
|
+
} | undefined;
|
|
273
|
+
_patternError?: "NOTFOUND" | "CYCLIC" | undefined;
|
|
274
|
+
}[];
|
|
275
|
+
} | undefined;
|
|
276
|
+
_id: string;
|
|
277
|
+
_slug?: string | null | undefined;
|
|
278
|
+
_name: string;
|
|
279
|
+
_dataResources?: {
|
|
280
|
+
[key: string]: {
|
|
281
|
+
type: string;
|
|
282
|
+
isPatternParameter?: boolean | undefined;
|
|
283
|
+
variables?: {
|
|
284
|
+
[key: string]: string;
|
|
285
|
+
} | undefined;
|
|
286
|
+
};
|
|
287
|
+
} | undefined;
|
|
288
|
+
}>;
|
|
289
|
+
};
|
|
290
|
+
|
|
148
291
|
/** Public ID of Canvas composition component type */
|
|
149
292
|
declare const CANVAS_COMPOSITION_TYPE = "Composition";
|
|
150
293
|
/** Public ID of Canvas slot component component type */
|
|
@@ -152,4 +295,4 @@ declare const CANVAS_SLOT_CONTENT_TYPE = "SlotContent";
|
|
|
152
295
|
declare const compositionInjectionKey = "uniformComposition";
|
|
153
296
|
declare const resolveRendererInjectionKey = "uniformResolveRenderer";
|
|
154
297
|
|
|
155
|
-
export { CANVAS_COMPOSITION_TYPE, CANVAS_SLOT_CONTENT_TYPE, ComponentProps, Composition, CompositionProps, DefaultNotImplementedComponent, DefaultNotImplementedComponentProps, PersonalizeComponent, ResolveRenderer, SlotComponentProps, SlotContent, TestComponent, UseCompositionEventEffectOptions, compositionInjectionKey, convertComponentToProps, resolveRendererInjectionKey, useCompositionEventEffect };
|
|
298
|
+
export { CANVAS_COMPOSITION_TYPE, CANVAS_SLOT_CONTENT_TYPE, ComponentProps, Composition, CompositionProps, DefaultNotImplementedComponent, DefaultNotImplementedComponentProps, PersonalizeComponent, ResolveRenderer, SlotComponentProps, SlotContent, TestComponent, UseCompositionEventEffectOptions, compositionInjectionKey, convertComponentToProps, createApiEnhancer, resolveRendererInjectionKey, useCompositionEventEffect, useCompositionInstance };
|
package/dist/index.esm.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{defineComponent as
|
|
1
|
+
import{defineComponent as _,computed as T,h as O,provide as I,inject as S,resolveComponent as A}from"vue-demi";var h="Composition",P="SlotContent",y="uniformComposition",v="uniformResolveRenderer";import{CANVAS_ENRICHMENT_TAG_PARAM as k}from"@uniformdev/canvas";import{Track as U,TrackSlot as V,isUsingUniformContext as j}from"@uniformdev/context-vue";var b=_({name:h,inheritAttrs:!1,props:{data:{type:Object,required:!0},resolveRenderer:{type:Function,default:()=>({type:e})=>A(e)},behaviorTracking:{type:String,default:"onView"}},setup(e,t){var c,i,C;let o=T(()=>{var l,d;return(d=e.data)!=null?d:(l=S(y))==null?void 0:l.value}),s=(c=e.resolveRenderer)!=null?c:S(v);I(y,o),I(v,s);let r=T(()=>{var l,d;return(d=(l=o.value)==null?void 0:l.slots)!=null?d:{}}),n=T(()=>{var l,d;return(d=(l=o.value)==null?void 0:l.parameters)!=null?d:{}}),p=T(()=>JSON.stringify(o.value)),m=(C=(i=o.value.parameters)==null?void 0:i[k])==null?void 0:C.value,a=()=>{var l,d;return(d=(l=t.slots).default)==null?void 0:d.call(l,{slots:r.value,parameters:n.value})};if(j()){let l=e.behaviorTracking==="onLoad"?V:U;return()=>O(l,{behavior:m,key:p.value},a)}return a}});import{defineComponent as L,computed as z,h as f,inject as w}from"vue-demi";import{CANVAS_PERSONALIZE_TYPE as D,CANVAS_TEST_TYPE as K,IN_CONTEXT_EDITOR_COMPONENT_START_ROLE as Y,mapSlotToPersonalizedVariations as B,mapSlotToTestVariations as $,PLACEHOLDER_ID as F}from"@uniformdev/canvas";import{Personalize as J,Test as X}from"@uniformdev/context-vue";function E(e){var r;let t=(r=e.parameters)!=null?r:{};return{...Object.entries(t).reduce((n,[p,{value:m}])=>({...n,[M(p)]:m}),{}),...e.data,component:e}}function M(e){return e.replace("$","")}var be=L({name:P,inheritAttrs:!1,props:{name:{type:String},resolveRenderer:{type:Function}},setup(e,t){var m;let o=w(y),s=(m=e.resolveRenderer)!=null?m:w(v),r=t.slots.emptyPlaceholder;if(!o||!s)throw new Error("<SlotContent /> can only be used inside a <Composition />");let n=z(()=>{var a,c,i;return e.name?(c=(a=o==null?void 0:o.value.slots)==null?void 0:a[e.name])!=null?c:[]:Object.values((i=o==null?void 0:o.value.slots)!=null?i:{}).flat()}),p=n.value.map((a,c)=>{let i=R({component:a,resolveRenderer:s,indexInSlot:c,slotName:e.name,parentComponent:o.value,slotChildrenCount:n.value.length,emptyPlaceholder:r});return t.slots.default?t.slots.default({child:i,component:a}):i});return()=>p}});function q(e,t){var n,p,m,a,c,i;let o=e==null?void 0:e.parameters,s=B((n=e.slots)==null?void 0:n.pz),r=(a=(m=(p=e.parameters)==null?void 0:p.trackingEventName)==null?void 0:m.value)!=null?a:"Untitled Personalization";return f(J,{name:r,component:C=>t(C),variations:s,count:Number((i=(c=o==null?void 0:o.count)==null?void 0:c.value)!=null?i:1)})}function G(e,t){var n,p,m,a,c;let o=(p=(n=e==null?void 0:e.slots)==null?void 0:n.test)!=null?p:[],s=(c=(a=(m=e==null?void 0:e.parameters)==null?void 0:m.test)==null?void 0:a.value)!=null?c:"Untitled Test",r=$(o);return f(X,{variations:r,name:s,component:i=>t(i)})}function R({component:e,resolveRenderer:t,indexInSlot:o,slotName:s,parentComponent:r,slotChildrenCount:n,emptyPlaceholder:p}){var a,c;if(e.type===K)return G(e,i=>R({component:i,resolveRenderer:t}));if(e.type===D)return q(e,i=>R({component:i,resolveRenderer:t}));let m=t==null?void 0:t(e);if(m){let i=E(e),C=Boolean(e._id),l=e._id===F,d=C?[f("script",{"data-role":Y,"data-parent-type":r==null?void 0:r.type,"data-component-id":e._id,"data-slot-name":s,"data-component-index":o,"data-total-components":n,"data-component-name":e.type,"data-is-placeholder":l?"true":void 0,"data-component-title":(c=(a=e.parameters)==null?void 0:a.title)==null?void 0:c.value}),l&&p!==void 0?p():f(m,i),f("script",{"data-role":"component-end"})]:[f(m,i)];return f(b,{data:e,resolveRenderer:t},()=>d)}return console.warn(`[canvas] found component of type '${e.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.`,e),f("")}import{defineComponent as H,h as u}from"vue-demi";var Q={borderLeft:"10px solid #e42535",background:"rgba(122, 215, 218, 0.3)",color:"#1d3557",padding:"1rem",textAlign:"left",margin:"1rem 5vw"},Z={margin:"0 0 1rem"},xe=H({name:"DefaultNotImplementedComponent",props:{component:{type:Object,required:!0}},setup(e,{attrs:t}){var s;let o=(s=e.component)==null?void 0:s.type;return()=>u("div",{key:"content",style:{...Q}},[u("h2",{style:{...Z}},`Component: ${o}`),u("p",[u("strong",`${o} has no Vue implementation. It may need to be added to your `),u("code",{},"resolveRenderer()"),u("strong",{}," function.")]),u("details",{},[u("summary",{},"props/attributes"),u("pre",{style:{overflowX:"auto"}},`${JSON.stringify(t)}`)])])}});import{CANVAS_DRAFT_STATE as W,createEventBus as ee,subscribeToComposition as oe}from"@uniformdev/canvas";import{watch as te}from"vue-demi";async function Oe({enabled:e,projectId:t,compositionIdRef:o,effect:s}){let r;te([()=>e,()=>o.value,()=>t],async()=>{if(r==null||r(),!e||!o.value||!t)return;let n=await ee();n&&(r=oe({eventBus:n,compositionId:o.value,compositionState:W,projectId:t,callback:s,event:"updated"}))},{immediate:!0})}import{createCanvasChannel as ne,isUpdateCompositionMessage as re,IN_CONTEXT_EDITOR_QUERY_STRING_PARAM as se}from"@uniformdev/canvas";import{ref as ie,computed as ae,watch as x,onMounted as pe}from"vue-demi";var g="uniform-canvas-preview-script",Me=({apiUrl:e})=>async t=>{let o=await fetch(e,{method:"post",body:JSON.stringify({composition:t.composition,hash:t.hash}),headers:{"Content-Type":"application/json"}}),s=await o.json();if(!o.ok)throw new Error("Error reading enhanced composition");return s.composition},Le=({composition:e,enhance:t=o=>o.composition})=>{let o=ie(e);x([()=>e,o],()=>{e._id!==o.value._id&&(o.value=e)},{immediate:!0});let s=ae(()=>{var n;return N()?ne({broadcastTo:[(n=window.opener)!=null?n:window.top],listenTo:[window]}):void 0});return x([s,()=>t],()=>{if(!s.value)return;let r=s.value.on("update-composition",async n=>{if(re(n)){let p=await t(n);o.value=p}});return()=>{r()}},{immediate:!0}),pe(()=>{if(!N()||document.getElementById(g))return;let n=document.createElement("script");n.id=g,n.src=me(),n.async=!0,document.head.appendChild(n)}),{composition:o}};function me(){return`${window.document.referrer}files/canvas-in-context-embed/index.js`}function N(){if(typeof window=="undefined")return!1;let e=new URLSearchParams(window.location.search).has(se),t=Boolean(window.document.referrer.match(/(^https:\/\/|\.)(uniform.app|uniform.wtf|localhost:\d{4})\//));return e&&t}export{h as CANVAS_COMPOSITION_TYPE,P as CANVAS_SLOT_CONTENT_TYPE,b as Composition,xe as DefaultNotImplementedComponent,be as SlotContent,y as compositionInjectionKey,E as convertComponentToProps,Me as createApiEnhancer,v as resolveRendererInjectionKey,Oe as useCompositionEventEffect,Le as useCompositionInstance};
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var E=Object.defineProperty;var V=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var M=Object.prototype.hasOwnProperty;var L=(e,t)=>{for(var o in t)E(e,o,{get:t[o],enumerable:!0})},z=(e,t,o,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of j(t))!M.call(e,n)&&n!==o&&E(e,n,{get:()=>t[n],enumerable:!(s=V(t,n))||s.enumerable});return e};var D=e=>z(E({},"__esModule",{value:!0}),e);var Z={};L(Z,{CANVAS_COMPOSITION_TYPE:()=>w,CANVAS_SLOT_CONTENT_TYPE:()=>x,Composition:()=>g,DefaultNotImplementedComponent:()=>X,SlotContent:()=>Y,compositionInjectionKey:()=>R,convertComponentToProps:()=>N,createApiEnhancer:()=>G,resolveRendererInjectionKey:()=>h,useCompositionEventEffect:()=>q,useCompositionInstance:()=>H});module.exports=D(Z);var p=require("vue-demi");var w="Composition",x="SlotContent",R="uniformComposition",h="uniformResolveRenderer";var O=require("@uniformdev/canvas"),P=require("@uniformdev/context-vue");var g=(0,p.defineComponent)({name:w,inheritAttrs:!1,props:{data:{type:Object,required:!0},resolveRenderer:{type:Function,default:()=>({type:e})=>(0,p.resolveComponent)(e)},behaviorTracking:{type:String,default:"onView"}},setup(e,t){var l,i,T;let o=(0,p.computed)(()=>{var d,f;return(f=e.data)!=null?f:(d=(0,p.inject)(R))==null?void 0:d.value}),s=(l=e.resolveRenderer)!=null?l:(0,p.inject)(h);(0,p.provide)(R,o),(0,p.provide)(h,s);let n=(0,p.computed)(()=>{var d,f;return(f=(d=o.value)==null?void 0:d.slots)!=null?f:{}}),r=(0,p.computed)(()=>{var d,f;return(f=(d=o.value)==null?void 0:d.parameters)!=null?f:{}}),m=(0,p.computed)(()=>JSON.stringify(o.value)),c=(T=(i=o.value.parameters)==null?void 0:i[O.CANVAS_ENRICHMENT_TAG_PARAM])==null?void 0:T.value,a=()=>{var d,f;return(f=(d=t.slots).default)==null?void 0:f.call(d,{slots:n.value,parameters:r.value})};if((0,P.isUsingUniformContext)()){let d=e.behaviorTracking==="onLoad"?P.TrackSlot:P.Track;return()=>(0,p.h)(d,{behavior:c,key:m.value},a)}return a}});var u=require("vue-demi"),C=require("@uniformdev/canvas"),b=require("@uniformdev/context-vue");function N(e){var n;let t=(n=e.parameters)!=null?n:{};return{...Object.entries(t).reduce((r,[m,{value:c}])=>({...r,[K(m)]:c}),{}),...e.data,component:e}}function K(e){return e.replace("$","")}var Y=(0,u.defineComponent)({name:x,inheritAttrs:!1,props:{name:{type:String},resolveRenderer:{type:Function}},setup(e,t){var c;let o=(0,u.inject)(R),s=(c=e.resolveRenderer)!=null?c:(0,u.inject)(h),n=t.slots.emptyPlaceholder;if(!o||!s)throw new Error("<SlotContent /> can only be used inside a <Composition />");let r=(0,u.computed)(()=>{var a,l,i;return e.name?(l=(a=o==null?void 0:o.value.slots)==null?void 0:a[e.name])!=null?l:[]:Object.values((i=o==null?void 0:o.value.slots)!=null?i:{}).flat()}),m=r.value.map((a,l)=>{let i=_({component:a,resolveRenderer:s,indexInSlot:l,slotName:e.name,parentComponent:o.value,slotChildrenCount:r.value.length,emptyPlaceholder:n});return t.slots.default?t.slots.default({child:i,component:a}):i});return()=>m}});function B(e,t){var r,m,c,a,l,i;let o=e==null?void 0:e.parameters,s=(0,C.mapSlotToPersonalizedVariations)((r=e.slots)==null?void 0:r.pz),n=(a=(c=(m=e.parameters)==null?void 0:m.trackingEventName)==null?void 0:c.value)!=null?a:"Untitled Personalization";return(0,u.h)(b.Personalize,{name:n,component:T=>t(T),variations:s,count:Number((i=(l=o==null?void 0:o.count)==null?void 0:l.value)!=null?i:1)})}function $(e,t){var r,m,c,a,l;let o=(m=(r=e==null?void 0:e.slots)==null?void 0:r.test)!=null?m:[],s=(l=(a=(c=e==null?void 0:e.parameters)==null?void 0:c.test)==null?void 0:a.value)!=null?l:"Untitled Test",n=(0,C.mapSlotToTestVariations)(o);return(0,u.h)(b.Test,{variations:n,name:s,component:i=>t(i)})}function _({component:e,resolveRenderer:t,indexInSlot:o,slotName:s,parentComponent:n,slotChildrenCount:r,emptyPlaceholder:m}){var a,l;if(e.type===C.CANVAS_TEST_TYPE)return $(e,i=>_({component:i,resolveRenderer:t}));if(e.type===C.CANVAS_PERSONALIZE_TYPE)return B(e,i=>_({component:i,resolveRenderer:t}));let c=t==null?void 0:t(e);if(c){let i=N(e),T=Boolean(e._id),d=e._id===C.PLACEHOLDER_ID,f=T?[(0,u.h)("script",{"data-role":C.IN_CONTEXT_EDITOR_COMPONENT_START_ROLE,"data-parent-type":n==null?void 0:n.type,"data-component-id":e._id,"data-slot-name":s,"data-component-index":o,"data-total-components":r,"data-component-name":e.type,"data-is-placeholder":d?"true":void 0,"data-component-title":(l=(a=e.parameters)==null?void 0:a.title)==null?void 0:l.value}),d&&m!==void 0?m():(0,u.h)(c,i),(0,u.h)("script",{"data-role":"component-end"})]:[(0,u.h)(c,i)];return(0,u.h)(g,{data:e,resolveRenderer:t},()=>f)}return console.warn(`[canvas] found component of type '${e.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.`,e),(0,u.h)("")}var y=require("vue-demi"),F={borderLeft:"10px solid #e42535",background:"rgba(122, 215, 218, 0.3)",color:"#1d3557",padding:"1rem",textAlign:"left",margin:"1rem 5vw"},J={margin:"0 0 1rem"},X=(0,y.defineComponent)({name:"DefaultNotImplementedComponent",props:{component:{type:Object,required:!0}},setup(e,{attrs:t}){var s;let o=(s=e.component)==null?void 0:s.type;return()=>(0,y.h)("div",{key:"content",style:{...F}},[(0,y.h)("h2",{style:{...J}},`Component: ${o}`),(0,y.h)("p",[(0,y.h)("strong",`${o} has no Vue implementation. It may need to be added to your `),(0,y.h)("code",{},"resolveRenderer()"),(0,y.h)("strong",{}," function.")]),(0,y.h)("details",{},[(0,y.h)("summary",{},"props/attributes"),(0,y.h)("pre",{style:{overflowX:"auto"}},`${JSON.stringify(t)}`)])])}});var I=require("@uniformdev/canvas"),A=require("vue-demi");async function q({enabled:e,projectId:t,compositionIdRef:o,effect:s}){let n;(0,A.watch)([()=>e,()=>o.value,()=>t],async()=>{if(n==null||n(),!e||!o.value||!t)return;let r=await(0,I.createEventBus)();r&&(n=(0,I.subscribeToComposition)({eventBus:r,compositionId:o.value,compositionState:I.CANVAS_DRAFT_STATE,projectId:t,callback:s,event:"updated"}))},{immediate:!0})}var S=require("@uniformdev/canvas"),v=require("vue-demi"),k="uniform-canvas-preview-script",G=({apiUrl:e})=>async t=>{let o=await fetch(e,{method:"post",body:JSON.stringify({composition:t.composition,hash:t.hash}),headers:{"Content-Type":"application/json"}}),s=await o.json();if(!o.ok)throw new Error("Error reading enhanced composition");return s.composition},H=({composition:e,enhance:t=o=>o.composition})=>{let o=(0,v.ref)(e);(0,v.watch)([()=>e,o],()=>{e._id!==o.value._id&&(o.value=e)},{immediate:!0});let s=(0,v.computed)(()=>{var r;return U()?(0,S.createCanvasChannel)({broadcastTo:[(r=window.opener)!=null?r:window.top],listenTo:[window]}):void 0});return(0,v.watch)([s,()=>t],()=>{if(!s.value)return;let n=s.value.on("update-composition",async r=>{if((0,S.isUpdateCompositionMessage)(r)){let m=await t(r);o.value=m}});return()=>{n()}},{immediate:!0}),(0,v.onMounted)(()=>{if(!U()||document.getElementById(k))return;let r=document.createElement("script");r.id=k,r.src=Q(),r.async=!0,document.head.appendChild(r)}),{composition:o}};function Q(){return`${window.document.referrer}files/canvas-in-context-embed/index.js`}function U(){if(typeof window=="undefined")return!1;let e=new URLSearchParams(window.location.search).has(S.IN_CONTEXT_EDITOR_QUERY_STRING_PARAM),t=Boolean(window.document.referrer.match(/(^https:\/\/|\.)(uniform.app|uniform.wtf|localhost:\d{4})\//));return e&&t}0&&(module.exports={CANVAS_COMPOSITION_TYPE,CANVAS_SLOT_CONTENT_TYPE,Composition,DefaultNotImplementedComponent,SlotContent,compositionInjectionKey,convertComponentToProps,createApiEnhancer,resolveRendererInjectionKey,useCompositionEventEffect,useCompositionInstance});
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{defineComponent as
|
|
1
|
+
import{defineComponent as _,computed as T,h as O,provide as I,inject as S,resolveComponent as A}from"vue-demi";var h="Composition",P="SlotContent",y="uniformComposition",v="uniformResolveRenderer";import{CANVAS_ENRICHMENT_TAG_PARAM as k}from"@uniformdev/canvas";import{Track as U,TrackSlot as V,isUsingUniformContext as j}from"@uniformdev/context-vue";var b=_({name:h,inheritAttrs:!1,props:{data:{type:Object,required:!0},resolveRenderer:{type:Function,default:()=>({type:e})=>A(e)},behaviorTracking:{type:String,default:"onView"}},setup(e,t){var c,i,C;let o=T(()=>{var l,d;return(d=e.data)!=null?d:(l=S(y))==null?void 0:l.value}),s=(c=e.resolveRenderer)!=null?c:S(v);I(y,o),I(v,s);let r=T(()=>{var l,d;return(d=(l=o.value)==null?void 0:l.slots)!=null?d:{}}),n=T(()=>{var l,d;return(d=(l=o.value)==null?void 0:l.parameters)!=null?d:{}}),p=T(()=>JSON.stringify(o.value)),m=(C=(i=o.value.parameters)==null?void 0:i[k])==null?void 0:C.value,a=()=>{var l,d;return(d=(l=t.slots).default)==null?void 0:d.call(l,{slots:r.value,parameters:n.value})};if(j()){let l=e.behaviorTracking==="onLoad"?V:U;return()=>O(l,{behavior:m,key:p.value},a)}return a}});import{defineComponent as L,computed as z,h as f,inject as w}from"vue-demi";import{CANVAS_PERSONALIZE_TYPE as D,CANVAS_TEST_TYPE as K,IN_CONTEXT_EDITOR_COMPONENT_START_ROLE as Y,mapSlotToPersonalizedVariations as B,mapSlotToTestVariations as $,PLACEHOLDER_ID as F}from"@uniformdev/canvas";import{Personalize as J,Test as X}from"@uniformdev/context-vue";function E(e){var r;let t=(r=e.parameters)!=null?r:{};return{...Object.entries(t).reduce((n,[p,{value:m}])=>({...n,[M(p)]:m}),{}),...e.data,component:e}}function M(e){return e.replace("$","")}var be=L({name:P,inheritAttrs:!1,props:{name:{type:String},resolveRenderer:{type:Function}},setup(e,t){var m;let o=w(y),s=(m=e.resolveRenderer)!=null?m:w(v),r=t.slots.emptyPlaceholder;if(!o||!s)throw new Error("<SlotContent /> can only be used inside a <Composition />");let n=z(()=>{var a,c,i;return e.name?(c=(a=o==null?void 0:o.value.slots)==null?void 0:a[e.name])!=null?c:[]:Object.values((i=o==null?void 0:o.value.slots)!=null?i:{}).flat()}),p=n.value.map((a,c)=>{let i=R({component:a,resolveRenderer:s,indexInSlot:c,slotName:e.name,parentComponent:o.value,slotChildrenCount:n.value.length,emptyPlaceholder:r});return t.slots.default?t.slots.default({child:i,component:a}):i});return()=>p}});function q(e,t){var n,p,m,a,c,i;let o=e==null?void 0:e.parameters,s=B((n=e.slots)==null?void 0:n.pz),r=(a=(m=(p=e.parameters)==null?void 0:p.trackingEventName)==null?void 0:m.value)!=null?a:"Untitled Personalization";return f(J,{name:r,component:C=>t(C),variations:s,count:Number((i=(c=o==null?void 0:o.count)==null?void 0:c.value)!=null?i:1)})}function G(e,t){var n,p,m,a,c;let o=(p=(n=e==null?void 0:e.slots)==null?void 0:n.test)!=null?p:[],s=(c=(a=(m=e==null?void 0:e.parameters)==null?void 0:m.test)==null?void 0:a.value)!=null?c:"Untitled Test",r=$(o);return f(X,{variations:r,name:s,component:i=>t(i)})}function R({component:e,resolveRenderer:t,indexInSlot:o,slotName:s,parentComponent:r,slotChildrenCount:n,emptyPlaceholder:p}){var a,c;if(e.type===K)return G(e,i=>R({component:i,resolveRenderer:t}));if(e.type===D)return q(e,i=>R({component:i,resolveRenderer:t}));let m=t==null?void 0:t(e);if(m){let i=E(e),C=Boolean(e._id),l=e._id===F,d=C?[f("script",{"data-role":Y,"data-parent-type":r==null?void 0:r.type,"data-component-id":e._id,"data-slot-name":s,"data-component-index":o,"data-total-components":n,"data-component-name":e.type,"data-is-placeholder":l?"true":void 0,"data-component-title":(c=(a=e.parameters)==null?void 0:a.title)==null?void 0:c.value}),l&&p!==void 0?p():f(m,i),f("script",{"data-role":"component-end"})]:[f(m,i)];return f(b,{data:e,resolveRenderer:t},()=>d)}return console.warn(`[canvas] found component of type '${e.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.`,e),f("")}import{defineComponent as H,h as u}from"vue-demi";var Q={borderLeft:"10px solid #e42535",background:"rgba(122, 215, 218, 0.3)",color:"#1d3557",padding:"1rem",textAlign:"left",margin:"1rem 5vw"},Z={margin:"0 0 1rem"},xe=H({name:"DefaultNotImplementedComponent",props:{component:{type:Object,required:!0}},setup(e,{attrs:t}){var s;let o=(s=e.component)==null?void 0:s.type;return()=>u("div",{key:"content",style:{...Q}},[u("h2",{style:{...Z}},`Component: ${o}`),u("p",[u("strong",`${o} has no Vue implementation. It may need to be added to your `),u("code",{},"resolveRenderer()"),u("strong",{}," function.")]),u("details",{},[u("summary",{},"props/attributes"),u("pre",{style:{overflowX:"auto"}},`${JSON.stringify(t)}`)])])}});import{CANVAS_DRAFT_STATE as W,createEventBus as ee,subscribeToComposition as oe}from"@uniformdev/canvas";import{watch as te}from"vue-demi";async function Oe({enabled:e,projectId:t,compositionIdRef:o,effect:s}){let r;te([()=>e,()=>o.value,()=>t],async()=>{if(r==null||r(),!e||!o.value||!t)return;let n=await ee();n&&(r=oe({eventBus:n,compositionId:o.value,compositionState:W,projectId:t,callback:s,event:"updated"}))},{immediate:!0})}import{createCanvasChannel as ne,isUpdateCompositionMessage as re,IN_CONTEXT_EDITOR_QUERY_STRING_PARAM as se}from"@uniformdev/canvas";import{ref as ie,computed as ae,watch as x,onMounted as pe}from"vue-demi";var g="uniform-canvas-preview-script",Me=({apiUrl:e})=>async t=>{let o=await fetch(e,{method:"post",body:JSON.stringify({composition:t.composition,hash:t.hash}),headers:{"Content-Type":"application/json"}}),s=await o.json();if(!o.ok)throw new Error("Error reading enhanced composition");return s.composition},Le=({composition:e,enhance:t=o=>o.composition})=>{let o=ie(e);x([()=>e,o],()=>{e._id!==o.value._id&&(o.value=e)},{immediate:!0});let s=ae(()=>{var n;return N()?ne({broadcastTo:[(n=window.opener)!=null?n:window.top],listenTo:[window]}):void 0});return x([s,()=>t],()=>{if(!s.value)return;let r=s.value.on("update-composition",async n=>{if(re(n)){let p=await t(n);o.value=p}});return()=>{r()}},{immediate:!0}),pe(()=>{if(!N()||document.getElementById(g))return;let n=document.createElement("script");n.id=g,n.src=me(),n.async=!0,document.head.appendChild(n)}),{composition:o}};function me(){return`${window.document.referrer}files/canvas-in-context-embed/index.js`}function N(){if(typeof window=="undefined")return!1;let e=new URLSearchParams(window.location.search).has(se),t=Boolean(window.document.referrer.match(/(^https:\/\/|\.)(uniform.app|uniform.wtf|localhost:\d{4})\//));return e&&t}export{h as CANVAS_COMPOSITION_TYPE,P as CANVAS_SLOT_CONTENT_TYPE,b as Composition,xe as DefaultNotImplementedComponent,be as SlotContent,y as compositionInjectionKey,E as convertComponentToProps,Me as createApiEnhancer,v as resolveRendererInjectionKey,Oe as useCompositionEventEffect,Le as useCompositionInstance};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniformdev/canvas-vue",
|
|
3
|
-
"version": "17.5.
|
|
3
|
+
"version": "17.5.1-alpha.7+ab97e4ba9",
|
|
4
4
|
"description": "Vue SDK for Uniform Canvas",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -22,12 +22,12 @@
|
|
|
22
22
|
"format": "prettier --write \"src/**/*.{js,ts,tsx}\""
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@uniformdev/canvas": "^17.5.
|
|
25
|
+
"@uniformdev/canvas": "^17.5.1-alpha.7+ab97e4ba9",
|
|
26
26
|
"@vue/test-utils": "2.2.1",
|
|
27
|
-
"vue-demi": "^0.13.
|
|
27
|
+
"vue-demi": "^0.13.11"
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|
|
30
|
-
"@uniformdev/context-vue": "
|
|
30
|
+
"@uniformdev/context-vue": ">=17.5.0",
|
|
31
31
|
"@vue/composition-api": "^1.0.0-rc.1",
|
|
32
32
|
"vue": "^2.0.0 || >=3.0.0"
|
|
33
33
|
},
|
|
@@ -39,9 +39,9 @@
|
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@testing-library/vue": "6.6.1",
|
|
41
41
|
"@types/uuid": "8.3.4",
|
|
42
|
-
"@uniformdev/context-vue": "^17.5.
|
|
42
|
+
"@uniformdev/context-vue": "^17.5.1-alpha.7+ab97e4ba9",
|
|
43
43
|
"@vue/server-test-utils": "1.3.0",
|
|
44
|
-
"vue": "3.2.
|
|
44
|
+
"vue": "3.2.45",
|
|
45
45
|
"vue-server-renderer": "2.7.13",
|
|
46
46
|
"vue-template-compiler": "2.7.13"
|
|
47
47
|
},
|
|
@@ -62,5 +62,5 @@
|
|
|
62
62
|
"last 2 versions",
|
|
63
63
|
"not dead"
|
|
64
64
|
],
|
|
65
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "ab97e4ba97e3842e6c7f208c4c96be3f9f74337e"
|
|
66
66
|
}
|