@uniformdev/canvas-vue 17.5.1-alpha.7 → 17.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +96 -29
- package/dist/index.esm.js +1 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +8 -8
package/dist/index.d.ts
CHANGED
|
@@ -81,6 +81,23 @@ declare const Composition: vue_demi.DefineComponent<{
|
|
|
81
81
|
behaviorTracking: "onLoad" | "onView" | undefined;
|
|
82
82
|
}>;
|
|
83
83
|
|
|
84
|
+
declare type DefaultNotImplementedComponentProps = {
|
|
85
|
+
component: ComponentInstance;
|
|
86
|
+
};
|
|
87
|
+
declare const DefaultNotImplementedComponent: vue_demi.DefineComponent<{
|
|
88
|
+
component: {
|
|
89
|
+
type: PropType<ComponentInstance>;
|
|
90
|
+
required: true;
|
|
91
|
+
};
|
|
92
|
+
}, () => vue_demi.VNode<vue_demi.RendererNode, vue_demi.RendererElement, {
|
|
93
|
+
[key: string]: any;
|
|
94
|
+
}>, unknown, {}, {}, vue_demi.ComponentOptionsMixin, vue_demi.ComponentOptionsMixin, {}, string, vue_demi.VNodeProps & vue_demi.AllowedComponentProps & vue_demi.ComponentCustomProps, Readonly<vue_demi.ExtractPropTypes<{
|
|
95
|
+
component: {
|
|
96
|
+
type: PropType<ComponentInstance>;
|
|
97
|
+
required: true;
|
|
98
|
+
};
|
|
99
|
+
}>>, {}>;
|
|
100
|
+
|
|
84
101
|
declare type SlotComponentProps = {
|
|
85
102
|
/** Name of the slot to render */
|
|
86
103
|
name?: string;
|
|
@@ -111,31 +128,6 @@ declare const SlotContent: vue_demi.DefineComponent<{
|
|
|
111
128
|
};
|
|
112
129
|
}>>, {}>;
|
|
113
130
|
|
|
114
|
-
declare type DefaultNotImplementedComponentProps = {
|
|
115
|
-
component: ComponentInstance;
|
|
116
|
-
};
|
|
117
|
-
declare const DefaultNotImplementedComponent: vue_demi.DefineComponent<{
|
|
118
|
-
component: {
|
|
119
|
-
type: PropType<ComponentInstance>;
|
|
120
|
-
required: true;
|
|
121
|
-
};
|
|
122
|
-
}, () => vue_demi.VNode<vue_demi.RendererNode, vue_demi.RendererElement, {
|
|
123
|
-
[key: string]: any;
|
|
124
|
-
}>, unknown, {}, {}, vue_demi.ComponentOptionsMixin, vue_demi.ComponentOptionsMixin, {}, string, vue_demi.VNodeProps & vue_demi.AllowedComponentProps & vue_demi.ComponentCustomProps, Readonly<vue_demi.ExtractPropTypes<{
|
|
125
|
-
component: {
|
|
126
|
-
type: PropType<ComponentInstance>;
|
|
127
|
-
required: true;
|
|
128
|
-
};
|
|
129
|
-
}>>, {}>;
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* Converts a raw Canvas component instance to Vue component props format.
|
|
133
|
-
* This merges each parameter moved to the root object and removes the 'value' node,
|
|
134
|
-
* hugely simplifying rendering code. For example if the raw object has parameters.foo.value,
|
|
135
|
-
* then the final props have props.foo === raw.parameters.foo.value.
|
|
136
|
-
*/
|
|
137
|
-
declare function convertComponentToProps<T = unknown>(component: ComponentInstance): ComponentProps<T>;
|
|
138
|
-
|
|
139
131
|
declare type UseCompositionEventEffectOptions = Omit<Partial<SubscribeToCompositionOptions>, 'callback' | 'compositionId'> & {
|
|
140
132
|
compositionIdRef: Ref<SubscribeToCompositionOptions['compositionId']>;
|
|
141
133
|
enabled: boolean;
|
|
@@ -214,8 +206,75 @@ declare const createApiEnhancer: ({ apiUrl }: {
|
|
|
214
206
|
};
|
|
215
207
|
} | undefined;
|
|
216
208
|
}>;
|
|
217
|
-
declare const
|
|
218
|
-
|
|
209
|
+
declare const useContextualEditing: ({ initialCompositionValue, enhance, }: {
|
|
210
|
+
initialCompositionValue?: {
|
|
211
|
+
type: string;
|
|
212
|
+
parameters?: {
|
|
213
|
+
[key: string]: {
|
|
214
|
+
value: unknown;
|
|
215
|
+
type: string;
|
|
216
|
+
connectedData?: {
|
|
217
|
+
pointer: string;
|
|
218
|
+
syntax: "jptr";
|
|
219
|
+
required?: boolean | undefined;
|
|
220
|
+
} | undefined;
|
|
221
|
+
};
|
|
222
|
+
} | undefined;
|
|
223
|
+
variant?: string | undefined;
|
|
224
|
+
slots?: {
|
|
225
|
+
[key: string]: {
|
|
226
|
+
type: string;
|
|
227
|
+
parameters?: {
|
|
228
|
+
[key: string]: {
|
|
229
|
+
value: unknown;
|
|
230
|
+
type: string;
|
|
231
|
+
connectedData?: {
|
|
232
|
+
pointer: string;
|
|
233
|
+
syntax: "jptr";
|
|
234
|
+
required?: boolean | undefined;
|
|
235
|
+
} | undefined;
|
|
236
|
+
};
|
|
237
|
+
} | undefined;
|
|
238
|
+
variant?: string | undefined;
|
|
239
|
+
slots?: {
|
|
240
|
+
[key: string]: any[];
|
|
241
|
+
} | undefined;
|
|
242
|
+
_id?: string | undefined;
|
|
243
|
+
_pattern?: string | undefined;
|
|
244
|
+
_dataResources?: {
|
|
245
|
+
[key: string]: {
|
|
246
|
+
type: string;
|
|
247
|
+
isPatternParameter?: boolean | undefined;
|
|
248
|
+
variables?: {
|
|
249
|
+
[key: string]: string;
|
|
250
|
+
} | undefined;
|
|
251
|
+
};
|
|
252
|
+
} | undefined;
|
|
253
|
+
_patternDataResources?: {
|
|
254
|
+
[key: string]: {
|
|
255
|
+
type: string;
|
|
256
|
+
isPatternParameter?: boolean | undefined;
|
|
257
|
+
variables?: {
|
|
258
|
+
[key: string]: string;
|
|
259
|
+
} | undefined;
|
|
260
|
+
};
|
|
261
|
+
} | undefined;
|
|
262
|
+
_patternError?: "NOTFOUND" | "CYCLIC" | undefined;
|
|
263
|
+
}[];
|
|
264
|
+
} | undefined;
|
|
265
|
+
_id: string;
|
|
266
|
+
_slug?: string | null | undefined;
|
|
267
|
+
_name: string;
|
|
268
|
+
_dataResources?: {
|
|
269
|
+
[key: string]: {
|
|
270
|
+
type: string;
|
|
271
|
+
isPatternParameter?: boolean | undefined;
|
|
272
|
+
variables?: {
|
|
273
|
+
[key: string]: string;
|
|
274
|
+
} | undefined;
|
|
275
|
+
};
|
|
276
|
+
} | undefined;
|
|
277
|
+
} | undefined;
|
|
219
278
|
enhance?: ((composition: UpdateCompositionMessage) => RootComponentInstance | Promise<RootComponentInstance>) | undefined;
|
|
220
279
|
}) => {
|
|
221
280
|
composition: vue_demi.Ref<{
|
|
@@ -285,9 +344,17 @@ declare const useCompositionInstance: ({ composition, enhance, }: {
|
|
|
285
344
|
} | undefined;
|
|
286
345
|
};
|
|
287
346
|
} | undefined;
|
|
288
|
-
}>;
|
|
347
|
+
} | undefined>;
|
|
289
348
|
};
|
|
290
349
|
|
|
350
|
+
/**
|
|
351
|
+
* Converts a raw Canvas component instance to Vue component props format.
|
|
352
|
+
* This merges each parameter moved to the root object and removes the 'value' node,
|
|
353
|
+
* hugely simplifying rendering code. For example if the raw object has parameters.foo.value,
|
|
354
|
+
* then the final props have props.foo === raw.parameters.foo.value.
|
|
355
|
+
*/
|
|
356
|
+
declare function convertComponentToProps<T = unknown>(component: ComponentInstance): ComponentProps<T>;
|
|
357
|
+
|
|
291
358
|
/** Public ID of Canvas composition component type */
|
|
292
359
|
declare const CANVAS_COMPOSITION_TYPE = "Composition";
|
|
293
360
|
/** Public ID of Canvas slot component component type */
|
|
@@ -295,4 +362,4 @@ declare const CANVAS_SLOT_CONTENT_TYPE = "SlotContent";
|
|
|
295
362
|
declare const compositionInjectionKey = "uniformComposition";
|
|
296
363
|
declare const resolveRendererInjectionKey = "uniformResolveRenderer";
|
|
297
364
|
|
|
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,
|
|
365
|
+
export { CANVAS_COMPOSITION_TYPE, CANVAS_SLOT_CONTENT_TYPE, ComponentProps, Composition, CompositionProps, DefaultNotImplementedComponent, DefaultNotImplementedComponentProps, PersonalizeComponent, ResolveRenderer, SlotComponentProps, SlotContent, TestComponent, UseCompositionEventEffectOptions, compositionInjectionKey, convertComponentToProps, createApiEnhancer, resolveRendererInjectionKey, useCompositionEventEffect, useContextualEditing };
|
package/dist/index.esm.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{CANVAS_ENRICHMENT_TAG_PARAM as _}from"@uniformdev/canvas";import{isUsingUniformContext as O,Track as A,TrackSlot as k}from"@uniformdev/context-vue";import{computed as T,defineComponent as U,h as j,inject as I,provide as S,resolveComponent as M}from"vue-demi";var h="Composition",P="SlotContent",y="uniformComposition",v="uniformResolveRenderer";var E=U({name:h,inheritAttrs:!1,props:{data:{type:Object,required:!0},resolveRenderer:{type:Function,default:()=>({type:e})=>M(e)},behaviorTracking:{type:String,default:"onView"}},setup(e,o){var c,a,C;let t=T(()=>{var d,l;return(l=e.data)!=null?l:(d=I(y))==null?void 0:d.value}),s=(c=e.resolveRenderer)!=null?c:I(v);S(y,t),S(v,s);let n=T(()=>{var d,l;return(l=(d=t.value)==null?void 0:d.slots)!=null?l:{}}),r=T(()=>{var d,l;return(l=(d=t.value)==null?void 0:d.parameters)!=null?l:{}}),p=T(()=>JSON.stringify(t.value)),m=(C=(a=t.value.parameters)==null?void 0:a[_])==null?void 0:C.value,i=()=>{var d,l;return(l=(d=o.slots).default)==null?void 0:l.call(d,{slots:n.value,parameters:r.value})};if(O()){let d=e.behaviorTracking==="onLoad"?k:A;return()=>j(d,{behavior:m,key:p.value},i)}return i}});import{defineComponent as L,h as u}from"vue-demi";var z={borderLeft:"10px solid #e42535",background:"rgba(122, 215, 218, 0.3)",color:"#1d3557",padding:"1rem",textAlign:"left",margin:"1rem 5vw"},D={margin:"0 0 1rem"},Te=L({name:"DefaultNotImplementedComponent",props:{component:{type:Object,required:!0}},setup(e,{attrs:o}){var s;let t=(s=e.component)==null?void 0:s.type;return()=>u("div",{key:"content",style:{...z}},[u("h2",{style:{...D}},`Component: ${t}`),u("p",[u("strong",`${t} 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(o)}`)])])}});import{CANVAS_PERSONALIZE_TYPE as K,CANVAS_TEST_TYPE as Y,IN_CONTEXT_EDITOR_COMPONENT_START_ROLE as B,mapSlotToPersonalizedVariations as $,mapSlotToTestVariations as F,PLACEHOLDER_ID as J}from"@uniformdev/canvas";import{Personalize as X,Test as q}from"@uniformdev/context-vue";import{computed as G,defineComponent as H,h as f,inject as w}from"vue-demi";function b(e){var n;let o=(n=e.parameters)!=null?n:{};return{...Object.entries(o).reduce((r,[p,{value:m}])=>({...r,[V(p)]:m}),{}),...e.data,component:e}}function V(e){return e.replace("$","")}var xe=H({name:P,inheritAttrs:!1,props:{name:{type:String},resolveRenderer:{type:Function}},setup(e,o){var m;let t=w(y),s=(m=e.resolveRenderer)!=null?m:w(v),n=o.slots.emptyPlaceholder;if(!t||!s)throw new Error("<SlotContent /> can only be used inside a <Composition />");let r=G(()=>{var i,c,a;return e.name?(c=(i=t==null?void 0:t.value.slots)==null?void 0:i[e.name])!=null?c:[]:Object.values((a=t==null?void 0:t.value.slots)!=null?a:{}).flat()}),p=r.value.map((i,c)=>{let a=R({component:i,resolveRenderer:s,indexInSlot:c,slotName:e.name,parentComponent:t.value,slotChildrenCount:r.value.length,emptyPlaceholder:n});return o.slots.default?o.slots.default({child:a,component:i}):a});return()=>p}});function Q(e,o){var r,p,m,i,c,a;let t=e==null?void 0:e.parameters,s=$((r=e.slots)==null?void 0:r.pz),n=(i=(m=(p=e.parameters)==null?void 0:p.trackingEventName)==null?void 0:m.value)!=null?i:"Untitled Personalization";return f(X,{name:n,component:C=>o(C),variations:s,count:Number((a=(c=t==null?void 0:t.count)==null?void 0:c.value)!=null?a:1)})}function Z(e,o){var r,p,m,i,c;let t=(p=(r=e==null?void 0:e.slots)==null?void 0:r.test)!=null?p:[],s=(c=(i=(m=e==null?void 0:e.parameters)==null?void 0:m.test)==null?void 0:i.value)!=null?c:"Untitled Test",n=F(t);return f(q,{variations:n,name:s,component:a=>o(a)})}function R({component:e,resolveRenderer:o,indexInSlot:t,slotName:s,parentComponent:n,slotChildrenCount:r,emptyPlaceholder:p}){var i,c;if(e.type===Y)return Z(e,a=>R({component:a,resolveRenderer:o}));if(e.type===K)return Q(e,a=>R({component:a,resolveRenderer:o}));let m=o==null?void 0:o(e);if(m){let a=b(e),C=Boolean(e._id),d=e._id===J,l=C?[f("script",{"data-role":B,"data-parent-id":n==null?void 0:n._id,"data-parent-type":n==null?void 0:n.type,"data-component-id":e._id,"data-slot-name":s,"data-component-index":t,"data-total-components":r,"data-component-name":e.type,"data-is-placeholder":d?"true":void 0,"data-component-title":(c=(i=e.parameters)==null?void 0:i.title)==null?void 0:c.value}),d&&p!==void 0?p():f(m,a),f("script",{"data-role":"component-end"})]:[f(m,a)];return f(E,{data:e,resolveRenderer:o},()=>l)}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{CANVAS_DRAFT_STATE as W,createEventBus as ee,subscribeToComposition as te}from"@uniformdev/canvas";import{watch as oe}from"vue-demi";async function Oe({enabled:e,projectId:o,compositionIdRef:t,effect:s}){let n;oe([()=>e,()=>t.value,()=>o],async()=>{if(n==null||n(),!e||!t.value||!o)return;let r=await ee();r&&(n=te({eventBus:r,compositionId:t.value,compositionState:W,projectId:o,callback:s,event:"updated"}))},{immediate:!0})}import{createCanvasChannel as ne,IN_CONTEXT_EDITOR_QUERY_STRING_PARAM as re,isUpdateCompositionMessage as se}from"@uniformdev/canvas";import{computed as ae,onMounted as ie,ref as pe,watch as x}from"vue-demi";var g="uniform-canvas-preview-script",Le=({apiUrl:e})=>async o=>{let t=await fetch(e,{method:"post",body:JSON.stringify({composition:o.composition,hash:o.hash}),headers:{"Content-Type":"application/json"}}),s=await t.json();if(!t.ok)throw new Error("Error reading enhanced composition");return s.composition},ze=({initialCompositionValue:e,enhance:o=t=>t.composition})=>{let t=pe(e);x([()=>e,t],()=>{var n;!e||(e==null?void 0:e._id)===((n=t.value)==null?void 0:n._id)||(t.value=e)},{immediate:!0});let s=ae(()=>{var r;return N()?ne({broadcastTo:[(r=window.opener)!=null?r:window.top],listenTo:[window]}):void 0});return x([s,()=>o],()=>{if(!s.value)return;let n=s.value.on("update-composition",async r=>{if(se(r)){let p=await o(r);t.value=p}});return()=>{n()}},{immediate:!0}),ie(()=>{if(!N()||document.getElementById(g))return;let r=document.createElement("script");r.id=g,r.src=me(),r.async=!0,document.head.appendChild(r)}),{composition:t}};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(re),o=Boolean(window.document.referrer.match(/(^https:\/\/|\.)(uniform.app|uniform.wtf|localhost:\d{4})\//));return e&&o}export{h as CANVAS_COMPOSITION_TYPE,P as CANVAS_SLOT_CONTENT_TYPE,E as Composition,Te as DefaultNotImplementedComponent,xe as SlotContent,y as compositionInjectionKey,b as convertComponentToProps,Le as createApiEnhancer,v as resolveRendererInjectionKey,Oe as useCompositionEventEffect,ze as useContextualEditing};
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var b=Object.defineProperty;var j=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames;var L=Object.prototype.hasOwnProperty;var z=(e,o)=>{for(var t in o)b(e,t,{get:o[t],enumerable:!0})},D=(e,o,t,s)=>{if(o&&typeof o=="object"||typeof o=="function")for(let n of M(o))!L.call(e,n)&&n!==t&&b(e,n,{get:()=>o[n],enumerable:!(s=j(o,n))||s.enumerable});return e};var V=e=>D(b({},"__esModule",{value:!0}),e);var Z={};z(Z,{CANVAS_COMPOSITION_TYPE:()=>w,CANVAS_SLOT_CONTENT_TYPE:()=>x,Composition:()=>g,DefaultNotImplementedComponent:()=>B,SlotContent:()=>F,compositionInjectionKey:()=>R,convertComponentToProps:()=>N,createApiEnhancer:()=>G,resolveRendererInjectionKey:()=>h,useCompositionEventEffect:()=>q,useContextualEditing:()=>H});module.exports=V(Z);var O=require("@uniformdev/canvas"),P=require("@uniformdev/context-vue"),p=require("vue-demi");var w="Composition",x="SlotContent",R="uniformComposition",h="uniformResolveRenderer";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,o){var d,a,T;let t=(0,p.computed)(()=>{var l,f;return(f=e.data)!=null?f:(l=(0,p.inject)(R))==null?void 0:l.value}),s=(d=e.resolveRenderer)!=null?d:(0,p.inject)(h);(0,p.provide)(R,t),(0,p.provide)(h,s);let n=(0,p.computed)(()=>{var l,f;return(f=(l=t.value)==null?void 0:l.slots)!=null?f:{}}),r=(0,p.computed)(()=>{var l,f;return(f=(l=t.value)==null?void 0:l.parameters)!=null?f:{}}),m=(0,p.computed)(()=>JSON.stringify(t.value)),c=(T=(a=t.value.parameters)==null?void 0:a[O.CANVAS_ENRICHMENT_TAG_PARAM])==null?void 0:T.value,i=()=>{var l,f;return(f=(l=o.slots).default)==null?void 0:f.call(l,{slots:n.value,parameters:r.value})};if((0,P.isUsingUniformContext)()){let l=e.behaviorTracking==="onLoad"?P.TrackSlot:P.Track;return()=>(0,p.h)(l,{behavior:c,key:m.value},i)}return i}});var C=require("vue-demi"),K={borderLeft:"10px solid #e42535",background:"rgba(122, 215, 218, 0.3)",color:"#1d3557",padding:"1rem",textAlign:"left",margin:"1rem 5vw"},Y={margin:"0 0 1rem"},B=(0,C.defineComponent)({name:"DefaultNotImplementedComponent",props:{component:{type:Object,required:!0}},setup(e,{attrs:o}){var s;let t=(s=e.component)==null?void 0:s.type;return()=>(0,C.h)("div",{key:"content",style:{...K}},[(0,C.h)("h2",{style:{...Y}},`Component: ${t}`),(0,C.h)("p",[(0,C.h)("strong",`${t} has no Vue implementation. It may need to be added to your `),(0,C.h)("code",{},"resolveRenderer()"),(0,C.h)("strong",{}," function.")]),(0,C.h)("details",{},[(0,C.h)("summary",{},"props/attributes"),(0,C.h)("pre",{style:{overflowX:"auto"}},`${JSON.stringify(o)}`)])])}});var y=require("@uniformdev/canvas"),E=require("@uniformdev/context-vue"),u=require("vue-demi");function N(e){var n;let o=(n=e.parameters)!=null?n:{};return{...Object.entries(o).reduce((r,[m,{value:c}])=>({...r,[$(m)]:c}),{}),...e.data,component:e}}function $(e){return e.replace("$","")}var F=(0,u.defineComponent)({name:x,inheritAttrs:!1,props:{name:{type:String},resolveRenderer:{type:Function}},setup(e,o){var c;let t=(0,u.inject)(R),s=(c=e.resolveRenderer)!=null?c:(0,u.inject)(h),n=o.slots.emptyPlaceholder;if(!t||!s)throw new Error("<SlotContent /> can only be used inside a <Composition />");let r=(0,u.computed)(()=>{var i,d,a;return e.name?(d=(i=t==null?void 0:t.value.slots)==null?void 0:i[e.name])!=null?d:[]:Object.values((a=t==null?void 0:t.value.slots)!=null?a:{}).flat()}),m=r.value.map((i,d)=>{let a=_({component:i,resolveRenderer:s,indexInSlot:d,slotName:e.name,parentComponent:t.value,slotChildrenCount:r.value.length,emptyPlaceholder:n});return o.slots.default?o.slots.default({child:a,component:i}):a});return()=>m}});function J(e,o){var r,m,c,i,d,a;let t=e==null?void 0:e.parameters,s=(0,y.mapSlotToPersonalizedVariations)((r=e.slots)==null?void 0:r.pz),n=(i=(c=(m=e.parameters)==null?void 0:m.trackingEventName)==null?void 0:c.value)!=null?i:"Untitled Personalization";return(0,u.h)(E.Personalize,{name:n,component:T=>o(T),variations:s,count:Number((a=(d=t==null?void 0:t.count)==null?void 0:d.value)!=null?a:1)})}function X(e,o){var r,m,c,i,d;let t=(m=(r=e==null?void 0:e.slots)==null?void 0:r.test)!=null?m:[],s=(d=(i=(c=e==null?void 0:e.parameters)==null?void 0:c.test)==null?void 0:i.value)!=null?d:"Untitled Test",n=(0,y.mapSlotToTestVariations)(t);return(0,u.h)(E.Test,{variations:n,name:s,component:a=>o(a)})}function _({component:e,resolveRenderer:o,indexInSlot:t,slotName:s,parentComponent:n,slotChildrenCount:r,emptyPlaceholder:m}){var i,d;if(e.type===y.CANVAS_TEST_TYPE)return X(e,a=>_({component:a,resolveRenderer:o}));if(e.type===y.CANVAS_PERSONALIZE_TYPE)return J(e,a=>_({component:a,resolveRenderer:o}));let c=o==null?void 0:o(e);if(c){let a=N(e),T=Boolean(e._id),l=e._id===y.PLACEHOLDER_ID,f=T?[(0,u.h)("script",{"data-role":y.IN_CONTEXT_EDITOR_COMPONENT_START_ROLE,"data-parent-id":n==null?void 0:n._id,"data-parent-type":n==null?void 0:n.type,"data-component-id":e._id,"data-slot-name":s,"data-component-index":t,"data-total-components":r,"data-component-name":e.type,"data-is-placeholder":l?"true":void 0,"data-component-title":(d=(i=e.parameters)==null?void 0:i.title)==null?void 0:d.value}),l&&m!==void 0?m():(0,u.h)(c,a),(0,u.h)("script",{"data-role":"component-end"})]:[(0,u.h)(c,a)];return(0,u.h)(g,{data:e,resolveRenderer:o},()=>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 I=require("@uniformdev/canvas"),A=require("vue-demi");async function q({enabled:e,projectId:o,compositionIdRef:t,effect:s}){let n;(0,A.watch)([()=>e,()=>t.value,()=>o],async()=>{if(n==null||n(),!e||!t.value||!o)return;let r=await(0,I.createEventBus)();r&&(n=(0,I.subscribeToComposition)({eventBus:r,compositionId:t.value,compositionState:I.CANVAS_DRAFT_STATE,projectId:o,callback:s,event:"updated"}))},{immediate:!0})}var S=require("@uniformdev/canvas"),v=require("vue-demi"),k="uniform-canvas-preview-script",G=({apiUrl:e})=>async o=>{let t=await fetch(e,{method:"post",body:JSON.stringify({composition:o.composition,hash:o.hash}),headers:{"Content-Type":"application/json"}}),s=await t.json();if(!t.ok)throw new Error("Error reading enhanced composition");return s.composition},H=({initialCompositionValue:e,enhance:o=t=>t.composition})=>{let t=(0,v.ref)(e);(0,v.watch)([()=>e,t],()=>{var n;!e||(e==null?void 0:e._id)===((n=t.value)==null?void 0:n._id)||(t.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,()=>o],()=>{if(!s.value)return;let n=s.value.on("update-composition",async r=>{if((0,S.isUpdateCompositionMessage)(r)){let m=await o(r);t.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:t}};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),o=Boolean(window.document.referrer.match(/(^https:\/\/|\.)(uniform.app|uniform.wtf|localhost:\d{4})\//));return e&&o}0&&(module.exports={CANVAS_COMPOSITION_TYPE,CANVAS_SLOT_CONTENT_TYPE,Composition,DefaultNotImplementedComponent,SlotContent,compositionInjectionKey,convertComponentToProps,createApiEnhancer,resolveRendererInjectionKey,useCompositionEventEffect,useContextualEditing});
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{CANVAS_ENRICHMENT_TAG_PARAM as _}from"@uniformdev/canvas";import{isUsingUniformContext as O,Track as A,TrackSlot as k}from"@uniformdev/context-vue";import{computed as T,defineComponent as U,h as j,inject as I,provide as S,resolveComponent as M}from"vue-demi";var h="Composition",P="SlotContent",y="uniformComposition",v="uniformResolveRenderer";var E=U({name:h,inheritAttrs:!1,props:{data:{type:Object,required:!0},resolveRenderer:{type:Function,default:()=>({type:e})=>M(e)},behaviorTracking:{type:String,default:"onView"}},setup(e,o){var c,a,C;let t=T(()=>{var d,l;return(l=e.data)!=null?l:(d=I(y))==null?void 0:d.value}),s=(c=e.resolveRenderer)!=null?c:I(v);S(y,t),S(v,s);let n=T(()=>{var d,l;return(l=(d=t.value)==null?void 0:d.slots)!=null?l:{}}),r=T(()=>{var d,l;return(l=(d=t.value)==null?void 0:d.parameters)!=null?l:{}}),p=T(()=>JSON.stringify(t.value)),m=(C=(a=t.value.parameters)==null?void 0:a[_])==null?void 0:C.value,i=()=>{var d,l;return(l=(d=o.slots).default)==null?void 0:l.call(d,{slots:n.value,parameters:r.value})};if(O()){let d=e.behaviorTracking==="onLoad"?k:A;return()=>j(d,{behavior:m,key:p.value},i)}return i}});import{defineComponent as L,h as u}from"vue-demi";var z={borderLeft:"10px solid #e42535",background:"rgba(122, 215, 218, 0.3)",color:"#1d3557",padding:"1rem",textAlign:"left",margin:"1rem 5vw"},D={margin:"0 0 1rem"},Te=L({name:"DefaultNotImplementedComponent",props:{component:{type:Object,required:!0}},setup(e,{attrs:o}){var s;let t=(s=e.component)==null?void 0:s.type;return()=>u("div",{key:"content",style:{...z}},[u("h2",{style:{...D}},`Component: ${t}`),u("p",[u("strong",`${t} 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(o)}`)])])}});import{CANVAS_PERSONALIZE_TYPE as K,CANVAS_TEST_TYPE as Y,IN_CONTEXT_EDITOR_COMPONENT_START_ROLE as B,mapSlotToPersonalizedVariations as $,mapSlotToTestVariations as F,PLACEHOLDER_ID as J}from"@uniformdev/canvas";import{Personalize as X,Test as q}from"@uniformdev/context-vue";import{computed as G,defineComponent as H,h as f,inject as w}from"vue-demi";function b(e){var n;let o=(n=e.parameters)!=null?n:{};return{...Object.entries(o).reduce((r,[p,{value:m}])=>({...r,[V(p)]:m}),{}),...e.data,component:e}}function V(e){return e.replace("$","")}var xe=H({name:P,inheritAttrs:!1,props:{name:{type:String},resolveRenderer:{type:Function}},setup(e,o){var m;let t=w(y),s=(m=e.resolveRenderer)!=null?m:w(v),n=o.slots.emptyPlaceholder;if(!t||!s)throw new Error("<SlotContent /> can only be used inside a <Composition />");let r=G(()=>{var i,c,a;return e.name?(c=(i=t==null?void 0:t.value.slots)==null?void 0:i[e.name])!=null?c:[]:Object.values((a=t==null?void 0:t.value.slots)!=null?a:{}).flat()}),p=r.value.map((i,c)=>{let a=R({component:i,resolveRenderer:s,indexInSlot:c,slotName:e.name,parentComponent:t.value,slotChildrenCount:r.value.length,emptyPlaceholder:n});return o.slots.default?o.slots.default({child:a,component:i}):a});return()=>p}});function Q(e,o){var r,p,m,i,c,a;let t=e==null?void 0:e.parameters,s=$((r=e.slots)==null?void 0:r.pz),n=(i=(m=(p=e.parameters)==null?void 0:p.trackingEventName)==null?void 0:m.value)!=null?i:"Untitled Personalization";return f(X,{name:n,component:C=>o(C),variations:s,count:Number((a=(c=t==null?void 0:t.count)==null?void 0:c.value)!=null?a:1)})}function Z(e,o){var r,p,m,i,c;let t=(p=(r=e==null?void 0:e.slots)==null?void 0:r.test)!=null?p:[],s=(c=(i=(m=e==null?void 0:e.parameters)==null?void 0:m.test)==null?void 0:i.value)!=null?c:"Untitled Test",n=F(t);return f(q,{variations:n,name:s,component:a=>o(a)})}function R({component:e,resolveRenderer:o,indexInSlot:t,slotName:s,parentComponent:n,slotChildrenCount:r,emptyPlaceholder:p}){var i,c;if(e.type===Y)return Z(e,a=>R({component:a,resolveRenderer:o}));if(e.type===K)return Q(e,a=>R({component:a,resolveRenderer:o}));let m=o==null?void 0:o(e);if(m){let a=b(e),C=Boolean(e._id),d=e._id===J,l=C?[f("script",{"data-role":B,"data-parent-id":n==null?void 0:n._id,"data-parent-type":n==null?void 0:n.type,"data-component-id":e._id,"data-slot-name":s,"data-component-index":t,"data-total-components":r,"data-component-name":e.type,"data-is-placeholder":d?"true":void 0,"data-component-title":(c=(i=e.parameters)==null?void 0:i.title)==null?void 0:c.value}),d&&p!==void 0?p():f(m,a),f("script",{"data-role":"component-end"})]:[f(m,a)];return f(E,{data:e,resolveRenderer:o},()=>l)}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{CANVAS_DRAFT_STATE as W,createEventBus as ee,subscribeToComposition as te}from"@uniformdev/canvas";import{watch as oe}from"vue-demi";async function Oe({enabled:e,projectId:o,compositionIdRef:t,effect:s}){let n;oe([()=>e,()=>t.value,()=>o],async()=>{if(n==null||n(),!e||!t.value||!o)return;let r=await ee();r&&(n=te({eventBus:r,compositionId:t.value,compositionState:W,projectId:o,callback:s,event:"updated"}))},{immediate:!0})}import{createCanvasChannel as ne,IN_CONTEXT_EDITOR_QUERY_STRING_PARAM as re,isUpdateCompositionMessage as se}from"@uniformdev/canvas";import{computed as ae,onMounted as ie,ref as pe,watch as x}from"vue-demi";var g="uniform-canvas-preview-script",Le=({apiUrl:e})=>async o=>{let t=await fetch(e,{method:"post",body:JSON.stringify({composition:o.composition,hash:o.hash}),headers:{"Content-Type":"application/json"}}),s=await t.json();if(!t.ok)throw new Error("Error reading enhanced composition");return s.composition},ze=({initialCompositionValue:e,enhance:o=t=>t.composition})=>{let t=pe(e);x([()=>e,t],()=>{var n;!e||(e==null?void 0:e._id)===((n=t.value)==null?void 0:n._id)||(t.value=e)},{immediate:!0});let s=ae(()=>{var r;return N()?ne({broadcastTo:[(r=window.opener)!=null?r:window.top],listenTo:[window]}):void 0});return x([s,()=>o],()=>{if(!s.value)return;let n=s.value.on("update-composition",async r=>{if(se(r)){let p=await o(r);t.value=p}});return()=>{n()}},{immediate:!0}),ie(()=>{if(!N()||document.getElementById(g))return;let r=document.createElement("script");r.id=g,r.src=me(),r.async=!0,document.head.appendChild(r)}),{composition:t}};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(re),o=Boolean(window.document.referrer.match(/(^https:\/\/|\.)(uniform.app|uniform.wtf|localhost:\d{4})\//));return e&&o}export{h as CANVAS_COMPOSITION_TYPE,P as CANVAS_SLOT_CONTENT_TYPE,E as Composition,Te as DefaultNotImplementedComponent,xe as SlotContent,y as compositionInjectionKey,b as convertComponentToProps,Le as createApiEnhancer,v as resolveRendererInjectionKey,Oe as useCompositionEventEffect,ze as useContextualEditing};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniformdev/canvas-vue",
|
|
3
|
-
"version": "17.
|
|
3
|
+
"version": "17.6.0",
|
|
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.
|
|
26
|
-
"@vue/test-utils": "2.2.
|
|
25
|
+
"@uniformdev/canvas": "^17.6.0",
|
|
26
|
+
"@vue/test-utils": "2.2.4",
|
|
27
27
|
"vue-demi": "^0.13.11"
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|
|
30
|
-
"@uniformdev/context-vue": ">=17.
|
|
30
|
+
"@uniformdev/context-vue": ">=17.6.0",
|
|
31
31
|
"@vue/composition-api": "^1.0.0-rc.1",
|
|
32
32
|
"vue": "^2.0.0 || >=3.0.0"
|
|
33
33
|
},
|
|
@@ -39,11 +39,11 @@
|
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@testing-library/vue": "6.6.1",
|
|
41
41
|
"@types/uuid": "8.3.4",
|
|
42
|
-
"@uniformdev/context-vue": "^17.
|
|
42
|
+
"@uniformdev/context-vue": "^17.6.0",
|
|
43
43
|
"@vue/server-test-utils": "1.3.0",
|
|
44
44
|
"vue": "3.2.45",
|
|
45
|
-
"vue-server-renderer": "2.7.
|
|
46
|
-
"vue-template-compiler": "2.7.
|
|
45
|
+
"vue-server-renderer": "2.7.14",
|
|
46
|
+
"vue-template-compiler": "2.7.14"
|
|
47
47
|
},
|
|
48
48
|
"files": [
|
|
49
49
|
"dist",
|
|
@@ -62,5 +62,5 @@
|
|
|
62
62
|
"last 2 versions",
|
|
63
63
|
"not dead"
|
|
64
64
|
],
|
|
65
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "8346fa3ffe24fa0f81fb0c8b0d12e27806ae321b"
|
|
66
66
|
}
|