@uniformdev/canvas-react 14.2.1-alpha.34 → 16.0.1-alpha.128
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/LICENSE.txt +2 -2
- package/dist/index.d.ts +15 -3
- package/dist/index.esm.js +1 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +10 -7
package/LICENSE.txt
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
©
|
|
2
|
-
See details of Uniform Systems, Inc. Master Subscription Agreement here: https://uniform.dev/eula
|
|
1
|
+
© 2022 Uniform Systems, Inc. All Rights Reserved.
|
|
2
|
+
See details of Uniform Systems, Inc. Master Subscription Agreement here: https://uniform.dev/eula
|
package/dist/index.d.ts
CHANGED
|
@@ -29,20 +29,32 @@ declare type CompositionProps<TRenderProps = unknown> = {
|
|
|
29
29
|
resolveRenderer?: RenderComponentResolver;
|
|
30
30
|
/** Either markup to render the composition directly, or render props to provide the ComponentProps for the root component */
|
|
31
31
|
children: ReactNode | ((props: ComponentProps<TRenderProps>) => JSX.Element);
|
|
32
|
+
/**
|
|
33
|
+
* When to track behavior from enrichment tags on this composition
|
|
34
|
+
* onView: adds enrichment score when the visitor views the tagged component in the browser viewport.
|
|
35
|
+
* onLoad: adds enrichment score as soon as the composition mounts, regardless of viewport.
|
|
36
|
+
*
|
|
37
|
+
* NOTE: onView renders a <div> tag around components that have enrichment tags, to support IntersectionObserver.
|
|
38
|
+
* onLoad does not need to do this, and renders no wrapping tag.
|
|
39
|
+
*
|
|
40
|
+
* Default: onView
|
|
41
|
+
*/
|
|
42
|
+
behaviorTracking?: 'onLoad' | 'onView';
|
|
32
43
|
};
|
|
33
44
|
declare type CompositionContext = {
|
|
34
45
|
/** The parent composition */
|
|
35
46
|
composition: ComponentInstance;
|
|
36
47
|
/** The current function to translate component data into React components */
|
|
37
|
-
resolveRenderer
|
|
48
|
+
resolveRenderer?: RenderComponentResolver;
|
|
49
|
+
behaviorTracking: 'onLoad' | 'onView';
|
|
38
50
|
};
|
|
39
51
|
/**
|
|
40
52
|
* Gets the parent Canvas composition of the current component.
|
|
41
53
|
* Note: this gets the direct parent, not necessarily the root of the composition.
|
|
42
54
|
*/
|
|
43
|
-
declare function useComposition(): CompositionContext;
|
|
55
|
+
declare function useComposition(): CompositionContext | undefined;
|
|
44
56
|
/** Forms a Canvas composition root, providing services to render a tree of Canvas components */
|
|
45
|
-
declare function Composition<TRenderProps = unknown>({ data, resolveRenderer, children, }: CompositionProps<TRenderProps>): JSX.Element | null;
|
|
57
|
+
declare function Composition<TRenderProps = unknown>({ data, resolveRenderer, children, behaviorTracking, }: CompositionProps<TRenderProps>): JSX.Element | null;
|
|
46
58
|
|
|
47
59
|
declare type CustomSlotChildRenderFunc = (options: {
|
|
48
60
|
child: ReactNode;
|
package/dist/index.esm.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Track as
|
|
1
|
+
import{Track as N,TrackFragment as R,useUniformContext as g}from"@uniformdev/context-react";import{CANVAS_ENRICHMENT_TAG_PARAM as w}from"@uniformdev/canvas";import E,{createContext as b,useContext as A}from"react";function C(o){var n;let e=(n=o.parameters)!=null?n:{};return{...Object.keys(e).reduce((t,s)=>(t[s]=e[s].value,t),{}),...o.data,component:o}}var x=b(void 0);function v(){return A(x)}function S({data:o,resolveRenderer:e,children:r,behaviorTracking:n}){var p,a,f;let t=v(),s=g({throwOnMissingProvider:!1})!==void 0;if(!o)return process.env.NODE_ENV==="development"&&console.warn("[canvas-dev] Composition was rendered with no data, nothing will be output."),null;let i={composition:o,resolveRenderer:e!=null?e:t==null?void 0:t.resolveRenderer,behaviorTracking:(p=n!=null?n:t==null?void 0:t.behaviorTracking)!=null?p:"onView"},d=(f=(a=o.parameters)==null?void 0:a[w])==null?void 0:f.value,l=i.behaviorTracking==="onLoad"?R:N,m=typeof r=="function"?r(C(o)):r;return E.createElement(x.Provider,{value:i},s?E.createElement(l,{behavior:d},m):m)}import u from"react";import{CANVAS_PERSONALIZE_TYPE as I,CANVAS_TEST_TYPE as z}from"@uniformdev/canvas";import{Personalize as k,Test as V}from"@uniformdev/context-react";import{mapSlotToPersonalizedVariations as O,mapSlotToTestVariations as _}from"@uniformdev/canvas";import*as y from"react";var h={test:(o,e,r)=>{var d,l,m,p;let n=o,t=(l=(d=n.slots)==null?void 0:d.test)!=null?l:[],s=(p=(m=n.parameters.test)==null?void 0:m.value)!=null?p:"Untitled Test",i=_(t);return y.createElement(V,{key:e,variations:i,name:s,component:a=>r(a,e)})},personalization:(o,e,r)=>{var s,i,d,l,m,p,a;let n=o,t=O((s=n==null?void 0:n.slots)==null?void 0:s.pz);return y.createElement(k,{key:e,variations:t,count:Number((l=(d=(i=n.parameters)==null?void 0:i.count)==null?void 0:d.value)!=null?l:1),name:(a=(p=(m=n.parameters)==null?void 0:m.trackingEventName)==null?void 0:p.value)!=null?a:"Untitled Personalization",component:f=>r(f,0)})}};function so({name:o,resolveRenderer:e,children:r}){var p;let n=v();if(!(n!=null&&n.composition))throw new Error("Slot must be rendered within a Composition");let{composition:t,resolveRenderer:s}=n;if(!t)throw new Error("Cannot use Slot without a Composition wrapper.");let i=(p=t.slots)==null?void 0:p[o];if(!i||!Array.isArray(i))return process.env.NODE_ENV==="development"&&console.warn(`[canvas-dev] slot '${o}' was rendered, but it was not defined on its component. This is expected if the slot is optional, otherwise it may indicate a typo. Component:`,t),null;let d=e!=null?e:s,l=h,m=i.map((a,f)=>{let P=T({component:a,resolveRenderer:d,resolveSystem:l,key:f});return r?r({child:P,component:a,key:f}):P});return u.createElement(u.Fragment,void 0,m)}function T({component:o,resolveRenderer:e,resolveSystem:r,key:n=0}){let t=e==null?void 0:e(o);if(o.type===z)return r.test(o,n,(s,i)=>T({component:s,resolveRenderer:e,resolveSystem:r,key:i}));if(o.type===I)return r.personalization(o,n,(s,i)=>T({component:s,resolveRenderer:e,resolveSystem:r,key:i}));if(t){let s=C(o);return u.createElement(S,{key:n,data:o,resolveRenderer:e},u.createElement(t,{...s}))}else process.env.NODE_ENV!=="production"&&console.warn(`[canvas] found component of type '${o.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.`,o);return null}import c from"react";function mo(o){var r;let e=(r=o.component)==null?void 0:r.type;return e?c.createElement("div",{style:{borderLeft:"10px solid #e42535!important",padding:"0.01em 16px 16px",borderRadius:"16px",backgroundColor:"rgba(122, 215, 218, 0.3)",color:"#1d3557"}},c.createElement("h2",null,"Component: ",e),c.createElement("p",null,c.createElement("strong",null,e)," has no React implementation. It may need to be added to your"," ",c.createElement("code",null,"resolveRenderer()")," function."),c.createElement("details",null,c.createElement("summary",null,"Props"),c.createElement("pre",null,JSON.stringify(o,null,2)))):null}import{CANVAS_DRAFT_STATE as D,createEventBus as F,subscribeToComposition as J}from"@uniformdev/canvas";import{useEffect as U}from"react";function Co({enabled:o,projectId:e,compositionId:r,effect:n}){U(()=>{if(!o||!r||!e)return;let t;return(async()=>{let i=await F();i&&(t=J({eventBus:i,compositionId:r,compositionState:D,projectId:e,callback:n,event:"updated"}))})(),()=>{t&&t()}},[r,o,e,n])}export{S as Composition,mo as DefaultNotImplementedComponent,so as Slot,v as useComposition,Co as useCompositionEventEffect};
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var I=Object.create;var T=Object.defineProperty;var z=Object.getOwnPropertyDescriptor;var D=Object.getOwnPropertyNames;var F=Object.getPrototypeOf,J=Object.prototype.hasOwnProperty;var U=(o,e)=>{for(var n in e)T(o,n,{get:e[n],enumerable:!0})},A=(o,e,n,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of D(e))!J.call(o,r)&&r!==n&&T(o,r,{get:()=>e[r],enumerable:!(t=z(e,r))||t.enumerable});return o};var P=(o,e,n)=>(n=o!=null?I(F(o)):{},A(e||!o||!o.__esModule?T(n,"default",{value:o,enumerable:!0}):n,o)),X=o=>A(T({},"__esModule",{value:!0}),o);var L={};U(L,{Composition:()=>R,DefaultNotImplementedComponent:()=>M,Slot:()=>K,useComposition:()=>x,useCompositionEventEffect:()=>B});module.exports=X(L);var u=require("@uniformdev/context-react"),k=require("@uniformdev/canvas"),C=P(require("react"));function E(o){var t;let e=(t=o.parameters)!=null?t:{};return{...Object.keys(e).reduce((r,s)=>(r[s]=e[s].value,r),{}),...o.data,component:o}}var V=(0,C.createContext)(void 0);function x(){return(0,C.useContext)(V)}function R({data:o,resolveRenderer:e,children:n,behaviorTracking:t}){var p,a,f;let r=x(),s=(0,u.useUniformContext)({throwOnMissingProvider:!1})!==void 0;if(!o)return process.env.NODE_ENV==="development"&&console.warn("[canvas-dev] Composition was rendered with no data, nothing will be output."),null;let i={composition:o,resolveRenderer:e!=null?e:r==null?void 0:r.resolveRenderer,behaviorTracking:(p=t!=null?t:r==null?void 0:r.behaviorTracking)!=null?p:"onView"},d=(f=(a=o.parameters)==null?void 0:a[k.CANVAS_ENRICHMENT_TAG_PARAM])==null?void 0:f.value,l=i.behaviorTracking==="onLoad"?u.TrackFragment:u.Track,m=typeof n=="function"?n(E(o)):n;return C.default.createElement(V.Provider,{value:i},s?C.default.createElement(l,{behavior:d},m):m)}var y=P(require("react"));var N=require("@uniformdev/canvas");var S=require("@uniformdev/context-react"),h=require("@uniformdev/canvas"),g=P(require("react")),O={test:(o,e,n)=>{var d,l,m,p;let t=o,r=(l=(d=t.slots)==null?void 0:d.test)!=null?l:[],s=(p=(m=t.parameters.test)==null?void 0:m.value)!=null?p:"Untitled Test",i=(0,h.mapSlotToTestVariations)(r);return g.createElement(S.Test,{key:e,variations:i,name:s,component:a=>n(a,e)})},personalization:(o,e,n)=>{var s,i,d,l,m,p,a;let t=o,r=(0,h.mapSlotToPersonalizedVariations)((s=t==null?void 0:t.slots)==null?void 0:s.pz);return g.createElement(S.Personalize,{key:e,variations:r,count:Number((l=(d=(i=t.parameters)==null?void 0:i.count)==null?void 0:d.value)!=null?l:1),name:(a=(p=(m=t.parameters)==null?void 0:m.trackingEventName)==null?void 0:p.value)!=null?a:"Untitled Personalization",component:f=>n(f,0)})}};function K({name:o,resolveRenderer:e,children:n}){var p;let t=x();if(!(t!=null&&t.composition))throw new Error("Slot must be rendered within a Composition");let{composition:r,resolveRenderer:s}=t;if(!r)throw new Error("Cannot use Slot without a Composition wrapper.");let i=(p=r.slots)==null?void 0:p[o];if(!i||!Array.isArray(i))return process.env.NODE_ENV==="development"&&console.warn(`[canvas-dev] slot '${o}' was rendered, but it was not defined on its component. This is expected if the slot is optional, otherwise it may indicate a typo. Component:`,r),null;let d=e!=null?e:s,l=O,m=i.map((a,f)=>{let b=w({component:a,resolveRenderer:d,resolveSystem:l,key:f});return n?n({child:b,component:a,key:f}):b});return y.default.createElement(y.default.Fragment,void 0,m)}function w({component:o,resolveRenderer:e,resolveSystem:n,key:t=0}){let r=e==null?void 0:e(o);if(o.type===N.CANVAS_TEST_TYPE)return n.test(o,t,(s,i)=>w({component:s,resolveRenderer:e,resolveSystem:n,key:i}));if(o.type===N.CANVAS_PERSONALIZE_TYPE)return n.personalization(o,t,(s,i)=>w({component:s,resolveRenderer:e,resolveSystem:n,key:i}));if(r){let s=E(o);return y.default.createElement(R,{key:t,data:o,resolveRenderer:e},y.default.createElement(r,{...s}))}else process.env.NODE_ENV!=="production"&&console.warn(`[canvas] found component of type '${o.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.`,o);return null}var c=P(require("react"));function M(o){var n;let e=(n=o.component)==null?void 0:n.type;return e?c.default.createElement("div",{style:{borderLeft:"10px solid #e42535!important",padding:"0.01em 16px 16px",borderRadius:"16px",backgroundColor:"rgba(122, 215, 218, 0.3)",color:"#1d3557"}},c.default.createElement("h2",null,"Component: ",e),c.default.createElement("p",null,c.default.createElement("strong",null,e)," has no React implementation. It may need to be added to your"," ",c.default.createElement("code",null,"resolveRenderer()")," function."),c.default.createElement("details",null,c.default.createElement("summary",null,"Props"),c.default.createElement("pre",null,JSON.stringify(o,null,2)))):null}var v=require("@uniformdev/canvas"),_=require("react");function B({enabled:o,projectId:e,compositionId:n,effect:t}){(0,_.useEffect)(()=>{if(!o||!n||!e)return;let r;return(async()=>{let i=await(0,v.createEventBus)();i&&(r=(0,v.subscribeToComposition)({eventBus:i,compositionId:n,compositionState:v.CANVAS_DRAFT_STATE,projectId:e,callback:t,event:"updated"}))})(),()=>{r&&r()}},[n,o,e,t])}0&&(module.exports={Composition,DefaultNotImplementedComponent,Slot,useComposition,useCompositionEventEffect});
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Track as
|
|
1
|
+
import{Track as N,TrackFragment as R,useUniformContext as g}from"@uniformdev/context-react";import{CANVAS_ENRICHMENT_TAG_PARAM as w}from"@uniformdev/canvas";import E,{createContext as b,useContext as A}from"react";function C(o){var n;let e=(n=o.parameters)!=null?n:{};return{...Object.keys(e).reduce((t,s)=>(t[s]=e[s].value,t),{}),...o.data,component:o}}var x=b(void 0);function v(){return A(x)}function S({data:o,resolveRenderer:e,children:r,behaviorTracking:n}){var p,a,f;let t=v(),s=g({throwOnMissingProvider:!1})!==void 0;if(!o)return process.env.NODE_ENV==="development"&&console.warn("[canvas-dev] Composition was rendered with no data, nothing will be output."),null;let i={composition:o,resolveRenderer:e!=null?e:t==null?void 0:t.resolveRenderer,behaviorTracking:(p=n!=null?n:t==null?void 0:t.behaviorTracking)!=null?p:"onView"},d=(f=(a=o.parameters)==null?void 0:a[w])==null?void 0:f.value,l=i.behaviorTracking==="onLoad"?R:N,m=typeof r=="function"?r(C(o)):r;return E.createElement(x.Provider,{value:i},s?E.createElement(l,{behavior:d},m):m)}import u from"react";import{CANVAS_PERSONALIZE_TYPE as I,CANVAS_TEST_TYPE as z}from"@uniformdev/canvas";import{Personalize as k,Test as V}from"@uniformdev/context-react";import{mapSlotToPersonalizedVariations as O,mapSlotToTestVariations as _}from"@uniformdev/canvas";import*as y from"react";var h={test:(o,e,r)=>{var d,l,m,p;let n=o,t=(l=(d=n.slots)==null?void 0:d.test)!=null?l:[],s=(p=(m=n.parameters.test)==null?void 0:m.value)!=null?p:"Untitled Test",i=_(t);return y.createElement(V,{key:e,variations:i,name:s,component:a=>r(a,e)})},personalization:(o,e,r)=>{var s,i,d,l,m,p,a;let n=o,t=O((s=n==null?void 0:n.slots)==null?void 0:s.pz);return y.createElement(k,{key:e,variations:t,count:Number((l=(d=(i=n.parameters)==null?void 0:i.count)==null?void 0:d.value)!=null?l:1),name:(a=(p=(m=n.parameters)==null?void 0:m.trackingEventName)==null?void 0:p.value)!=null?a:"Untitled Personalization",component:f=>r(f,0)})}};function so({name:o,resolveRenderer:e,children:r}){var p;let n=v();if(!(n!=null&&n.composition))throw new Error("Slot must be rendered within a Composition");let{composition:t,resolveRenderer:s}=n;if(!t)throw new Error("Cannot use Slot without a Composition wrapper.");let i=(p=t.slots)==null?void 0:p[o];if(!i||!Array.isArray(i))return process.env.NODE_ENV==="development"&&console.warn(`[canvas-dev] slot '${o}' was rendered, but it was not defined on its component. This is expected if the slot is optional, otherwise it may indicate a typo. Component:`,t),null;let d=e!=null?e:s,l=h,m=i.map((a,f)=>{let P=T({component:a,resolveRenderer:d,resolveSystem:l,key:f});return r?r({child:P,component:a,key:f}):P});return u.createElement(u.Fragment,void 0,m)}function T({component:o,resolveRenderer:e,resolveSystem:r,key:n=0}){let t=e==null?void 0:e(o);if(o.type===z)return r.test(o,n,(s,i)=>T({component:s,resolveRenderer:e,resolveSystem:r,key:i}));if(o.type===I)return r.personalization(o,n,(s,i)=>T({component:s,resolveRenderer:e,resolveSystem:r,key:i}));if(t){let s=C(o);return u.createElement(S,{key:n,data:o,resolveRenderer:e},u.createElement(t,{...s}))}else process.env.NODE_ENV!=="production"&&console.warn(`[canvas] found component of type '${o.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.`,o);return null}import c from"react";function mo(o){var r;let e=(r=o.component)==null?void 0:r.type;return e?c.createElement("div",{style:{borderLeft:"10px solid #e42535!important",padding:"0.01em 16px 16px",borderRadius:"16px",backgroundColor:"rgba(122, 215, 218, 0.3)",color:"#1d3557"}},c.createElement("h2",null,"Component: ",e),c.createElement("p",null,c.createElement("strong",null,e)," has no React implementation. It may need to be added to your"," ",c.createElement("code",null,"resolveRenderer()")," function."),c.createElement("details",null,c.createElement("summary",null,"Props"),c.createElement("pre",null,JSON.stringify(o,null,2)))):null}import{CANVAS_DRAFT_STATE as D,createEventBus as F,subscribeToComposition as J}from"@uniformdev/canvas";import{useEffect as U}from"react";function Co({enabled:o,projectId:e,compositionId:r,effect:n}){U(()=>{if(!o||!r||!e)return;let t;return(async()=>{let i=await F();i&&(t=J({eventBus:i,compositionId:r,compositionState:D,projectId:e,callback:n,event:"updated"}))})(),()=>{t&&t()}},[r,o,e,n])}export{S as Composition,mo as DefaultNotImplementedComponent,so as Slot,v as useComposition,Co as useCompositionEventEffect};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniformdev/canvas-react",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "16.0.1-alpha.128+6cdb4ff33",
|
|
4
4
|
"description": "React SDK for Uniform Canvas",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -23,15 +23,18 @@
|
|
|
23
23
|
"format": "prettier --write \"src/**/*.{js,ts,tsx}\""
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@uniformdev/canvas": "^
|
|
27
|
-
"@uniformdev/context": "^
|
|
28
|
-
"@uniformdev/context-react": "^
|
|
26
|
+
"@uniformdev/canvas": "^16.0.1-alpha.128+6cdb4ff33",
|
|
27
|
+
"@uniformdev/context": "^16.0.1-alpha.128+6cdb4ff33",
|
|
28
|
+
"@uniformdev/context-react": "^16.0.1-alpha.128+6cdb4ff33"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
|
-
"react": ">= 16"
|
|
31
|
+
"react": ">= 16",
|
|
32
|
+
"react-dom": ">=16"
|
|
32
33
|
},
|
|
33
34
|
"devDependencies": {
|
|
34
|
-
"react": "
|
|
35
|
+
"@types/react": "18.0.12",
|
|
36
|
+
"react": "18.1.0",
|
|
37
|
+
"react-dom": "18.1.0"
|
|
35
38
|
},
|
|
36
39
|
"files": [
|
|
37
40
|
"/dist"
|
|
@@ -39,5 +42,5 @@
|
|
|
39
42
|
"publishConfig": {
|
|
40
43
|
"access": "public"
|
|
41
44
|
},
|
|
42
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "6cdb4ff331d6d0d9d5c154b7b342e7703067bfc3"
|
|
43
46
|
}
|