@uniformdev/context-ui 16.0.0 → 16.0.1-alpha.221
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 +8 -2
- package/dist/index.esm.js +23 -11
- package/dist/index.js +23 -11
- package/dist/index.mjs +23 -11
- package/package.json +21 -21
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as _emotion_react_types_jsx_namespace from '@emotion/react/types/jsx-namespace';
|
|
2
|
+
import * as _emotion_react from '@emotion/react';
|
|
2
3
|
import React, { ReactElement, ComponentType } from 'react';
|
|
3
4
|
import { DimensionDefinition, ManifestGetResponse } from '@uniformdev/context/api';
|
|
4
5
|
import { EnrichmentData, DimensionMatch, VariantMatchCriteria } from '@uniformdev/context';
|
|
@@ -24,10 +25,12 @@ declare type ResolvedDimensionDefinition = DimensionDefinition & {
|
|
|
24
25
|
displayName: string;
|
|
25
26
|
};
|
|
26
27
|
|
|
28
|
+
declare const addEnrichmentLink: _emotion_react.SerializedStyles;
|
|
27
29
|
interface EnrichmentTagProps {
|
|
28
30
|
value: EnrichmentData[] | null | undefined;
|
|
29
31
|
setValue: (value: EnrichmentData[] | null) => void;
|
|
30
32
|
contextConfig: ContextConfig;
|
|
33
|
+
displayTitle?: boolean;
|
|
31
34
|
}
|
|
32
35
|
declare const EnrichmentTag: React.FC<EnrichmentTagProps>;
|
|
33
36
|
|
|
@@ -39,6 +42,9 @@ interface PersonalizationCriteriaProps {
|
|
|
39
42
|
value: VariantMatchCriteria | null | undefined;
|
|
40
43
|
setValue: (value: VariantMatchCriteria | null) => void;
|
|
41
44
|
contextConfig: ContextConfig;
|
|
45
|
+
displayTitle?: boolean;
|
|
46
|
+
onMenuOpen?: () => void;
|
|
47
|
+
onMenuClose?: () => void;
|
|
42
48
|
}
|
|
43
49
|
declare const PersonalizationCriteria: React.FC<PersonalizationCriteriaProps>;
|
|
44
50
|
|
|
@@ -75,7 +81,7 @@ interface ContextDataProps {
|
|
|
75
81
|
noIntentsComponent?: ComponentType<DataContextErrorProps>;
|
|
76
82
|
contextConfig: ContextConfig;
|
|
77
83
|
}
|
|
78
|
-
declare const ContextData: React.FC<ContextDataProps
|
|
84
|
+
declare const ContextData: React.FC<React.PropsWithChildren<ContextDataProps>>;
|
|
79
85
|
declare function useContextConfig(): ContextConfig;
|
|
80
86
|
declare function useManifest(): ManifestGetResponse;
|
|
81
87
|
declare function useDimensionsDataContext(): DimensionsData;
|
|
@@ -96,4 +102,4 @@ declare const useValidateContextConfig: (contextConfig?: ContextConfig | undefin
|
|
|
96
102
|
declare function isEnrichmentTagData(obj: any): obj is EnrichmentData[];
|
|
97
103
|
declare function isPersonalizationCriteriaData(obj: any): obj is VariantMatchCriteria;
|
|
98
104
|
|
|
99
|
-
export { ContextConfig, ContextData, ContextDataProps, DataContextErrorProps, DimensionsData, EditLink, EditLinkProps, EnrichmentTag, EnrichmentTagProps, PersonalizationCriteria, PersonalizationCriteriaProps, ProjectUIVersion, ResolvedDimensionDefinition, UseContextDataResult, UseDimensionsResult, UseValidateContextConfigResult, equality, isEnrichmentTagData, isPersonalizationCriteriaData, useContextConfig, useContextData, useDimensions, useDimensionsDataContext, useManifest, useValidateContextConfig, validateContextConfig };
|
|
105
|
+
export { ContextConfig, ContextData, ContextDataProps, DataContextErrorProps, DimensionsData, EditLink, EditLinkProps, EnrichmentTag, EnrichmentTagProps, PersonalizationCriteria, PersonalizationCriteriaProps, ProjectUIVersion, ResolvedDimensionDefinition, UseContextDataResult, UseDimensionsResult, UseValidateContextConfigResult, addEnrichmentLink, equality, isEnrichmentTagData, isPersonalizationCriteriaData, useContextConfig, useContextData, useDimensions, useDimensionsDataContext, useManifest, useValidateContextConfig, validateContextConfig };
|
package/dist/index.esm.js
CHANGED
|
@@ -1,13 +1,26 @@
|
|
|
1
|
-
import{jsx as e}from"@emotion/react";import*as y from"react";import{Icon as
|
|
1
|
+
import{jsx as e}from"@emotion/react";import*as y from"react";import{Icon as oe}from"@uniformdev/design-system";import{CgChevronRight as ie}from"react-icons/cg";import{css as ne}from"@emotion/react";var U=ne`
|
|
2
2
|
display: flex;
|
|
3
3
|
align-items: center;
|
|
4
4
|
font-weight: var(--fw-bold);
|
|
5
|
+
gap: var(--spacing-sm);
|
|
6
|
+
margin-top: var(--spacing-md);
|
|
5
7
|
color: var(--brand-secondary-3);
|
|
6
8
|
&:hover,
|
|
7
9
|
&:focus {
|
|
8
10
|
text-decoration-line: underline;
|
|
9
11
|
}
|
|
10
|
-
`;var
|
|
12
|
+
`;var A=({linkTo:t,name:n,linkText:r=`Edit ${n} Component`})=>e("a",{css:U,title:`Edit ${n} component definition`,rel:"noopener noreferrer",target:"_blank",href:t},r,e(oe,{icon:ie,iconColor:"currentColor",size:"1.5rem"}));import G,{useMemo as O,useState as N}from"react";import{useEffect as ae,useState as se}from"react";import{DimensionClient as le,computeDimensionDisplayName as ce,ApiClientError as ue}from"@uniformdev/context/api";function B(t,n,r){return t.reduce((s,a)=>{let o=n(a);if(typeof o=="undefined"||o===null)throw new Error("Objectify key selector returned undefined or null.");return s[n(a)]=r?r(a):a,s},{})}function R({apiHost:t,apiKey:n,projectId:r}){let[s,a]=se({loading:!1,notConfigured:!1,error:null,result:null});return ae(()=>{if(!r||!n||!t){a({notConfigured:!0,loading:!1,error:null,result:null});return}(async()=>{a({notConfigured:!1,loading:!0,error:null,result:null});try{let i=(await new le({projectId:r,apiKey:n,apiHost:t}).get()).dimensions.map(c=>({...c,displayName:ce(c)})),d={dimensions:i,dimIndex:B(i,c=>c.dim,c=>c)};a({notConfigured:!1,loading:!1,error:null,result:d})}catch(l){let i;l instanceof ue?i=l.message:i=l.toString(),a({notConfigured:!1,loading:!1,error:i,result:null});return}})()},[t,n,r]),{result:s.result,error:s.error,loading:s.loading,notConfigured:s.notConfigured}}import{getEnrichmentVectorKey as H}from"@uniformdev/context";import{Input as _,Button as de,InputSelect as me,Callout as P,Icon as x,LoadingIndicator as pe}from"@uniformdev/design-system";import{CgMathPlus as q,CgMathMinus as fe,CgCloseO as ge}from"react-icons/cg";import W from"immer";import{css as V}from"@emotion/react";var Ce=V`
|
|
13
|
+
flex: 2;
|
|
14
|
+
display: flex;
|
|
15
|
+
width: 50%;
|
|
16
|
+
align-items: center;
|
|
17
|
+
font-weight: var(--fw-bold);
|
|
18
|
+
color: var(--brand-primary-1);
|
|
19
|
+
&:hover,
|
|
20
|
+
&:focus {
|
|
21
|
+
text-decoration-line: underline;
|
|
22
|
+
}
|
|
23
|
+
`,lt=({value:t,setValue:n,contextConfig:r,displayTitle:s=!0})=>{let{loading:a,result:o,error:l}=R(r),i=O(()=>{if(o)return o.dimensions.filter(f=>f.category==="ENR")},[o]),d=O(()=>{if(!t)return i;if(i)return i.filter(f=>!t.some(b=>H(b.cat,b.key)===f.dim))},[i,t]),[c,E]=N(""),[u,g]=N(50),[D,m]=N(!1),p=i==null?void 0:i.find(f=>f.dim===c),w=()=>{let[f,b]=c.split("_");k([...t!=null?t:[],{cat:f,key:b,str:u}]),E(""),g(50),m(!1)},k=f=>{let b=f.length===0?null:f;n(b)};return l?e(P,{type:"danger"},l):a||o===null?e(pe,null):e("fieldset",{className:"enrichment-tag"},s?e("div",{css:{display:"flex",justifyContent:"space-between",marginBottom:"var(--spacing-base)"}},e("legend",{css:{fontSize:"var(--fs-md)",fontWeight:"var(--fw-bold)"}},"Enrichment Tags")):null,i!=null&&i.length?!D&&!t?e(P,{title:"No enrichment tags assigned.",type:"info",css:{marginBlock:"var(--spacing-base)"}},e("p",null,"Click"," ",e("a",{onClick:()=>m(!0),target:"_blank",rel:"noopener noreferrer",css:{textDecorationLine:"underline"}},"here")," ","to assign your first enrichment tag.")):e(G.Fragment,null,o&&e(ye,{list:t!=null?t:[],setList:k,dimIndex:o.dimIndex}),D&&d&&d.length>0?e("div",{className:"add-enrichment-tag",css:{display:"flex",flexWrap:"wrap",gap:"var(--spacing-lg)",marginTop:"var(--spacing-md)",alignItems:"center"}},e("div",{css:{flexGrow:1}},e(me,{name:"enrichment-type",label:"Enrichment Tag",showLabel:!0,value:c,options:[{label:"Select",value:""},...d.map(f=>({label:f.displayName,value:f.dim}))],onChange:f=>E(f.currentTarget.value)})),e(be,{score:u,setValue:g,cap:p?p.cap:100,css:{flexBasis:"9rem"}}),e(de,{buttonType:"tertiary",size:"xl",css:{marginBottom:"var(--spacing-xs)",height:"3.5rem",margin:0,alignSelf:"flex-end"},onClick:w,disabled:!c},"Add")):null,e("div",{className:"enrichment-cta",style:{paddingTop:"10px",display:"flex",justifyContent:"space-between"}},!D&&d&&d.length>0&&t?e("button",{type:"button",className:"add-more",onClick:()=>m(!0),css:{color:"var(--brand-secondary-3)",display:"flex",gap:"var(--spacing-sm)",fontWeight:"var(--fw-bold)",marginTop:"var(--spacing-md)",alignItems:"center",backgroundColor:"transparent",backgroundImage:"none",borderWidth:0,width:"50%",flex:2}},e("div",{css:{color:"white",backgroundColor:"var(--brand-secondary-3)",borderRadius:"var(--rounded-full)",padding:"var(--spacing-xs)"}},e(x,{icon:q,iconColor:"currentColor",size:"1.25rem"})),"Add More"):e("a",{css:Ce,title:"none",href:"#"}),e(A,{name:"Enrichments",linkText:"Manage Enrichments",linkTo:`${r.apiHost}/projects/${encodeURIComponent(r.projectId)}/personalization/enrichments`}))):e(ve,{contextConfig:r}))},ve=({contextConfig:t})=>e(P,{title:"No enrichments found.",type:"caution",css:{marginBlock:"var(--spacing-base)"}},e("p",null,"Looks like you do not have any enrichments created in your connected Uniform project. Start by creating your first enrichment"," ",e("a",{href:`${t.apiHost}/projects/${encodeURIComponent(t.projectId)}/personalization/enrichments`,target:"_blank",rel:"noopener noreferrer",css:{":hover":{textDecorationLine:"underline"}}},"here"),".")),F=(t,n=100,r=0)=>Math.max(Math.min(t,n),r),K=V`
|
|
11
24
|
position: absolute;
|
|
12
25
|
bottom: 0.875rem;
|
|
13
26
|
left: var(--spacing-sm);
|
|
@@ -19,27 +32,27 @@ import{jsx as e}from"@emotion/react";import*as y from"react";import{Icon as Z}fr
|
|
|
19
32
|
background-color: var(--gray-100);
|
|
20
33
|
border: 1px solid var(--gray-300);
|
|
21
34
|
border-radius: var(--rounded-full);
|
|
22
|
-
`,
|
|
23
|
-
${
|
|
35
|
+
`,he=V`
|
|
36
|
+
${K}
|
|
24
37
|
left: auto;
|
|
25
38
|
right: var(--spacing-sm);
|
|
26
|
-
`,
|
|
39
|
+
`,be=({score:t,setValue:n,cap:r=100,...s})=>{let a=o=>{let l=o==="increment"?t+10:t-10;l<0&&(l=0),l>r&&(l=r),n(l)};return e("div",{css:{position:"relative"},...s},e(_,{label:"Strength",id:"enrichment-score",type:"number",min:0,max:r,value:t,onChange:o=>n(F(Number(o.currentTarget.value)||0,r)),css:{textAlign:"center",boxSizing:"border-box"}}),e("button",{type:"button",title:"Reduce enrichment count",onClick:()=>a("decrement"),disabled:t===0,className:"scoreCounterButton",css:K},e(x,{icon:fe,iconColor:"gray",size:"1.5rem"})),e("button",{type:"button",title:"Increase enrichment count",onClick:()=>a("increment"),className:"scoreCounterButton",css:he},e(x,{icon:q,iconColor:"gray",size:"1.5rem"})))},ye=({list:t,setList:n,dimIndex:r})=>{let s=o=>{n(W(t,l=>{l.splice(o,1)}))},a=(o,l)=>{var d;let i=(d=r[`${t[o].cat}_${t[o].key}`])==null?void 0:d.cap;n(W(t,c=>{c[o].str=F(Number(l)||0,i)}))};return e(G.Fragment,null,t.map((o,l)=>{let i=r[H(o.cat,o.key)];return e("div",{css:{display:"flex",alignItems:"center",gap:"var(--spacing-base)",backgroundColor:"var(--brand-secondary-2)",boxShadow:"var(--shadow-base)",borderRadius:"var(--rounded-base)",paddingInline:"var(--spacing-base)",marginBlock:"var(--spacing-base)"},className:"selected-enrichments",key:`${o.cat}-${o.key}`},e("span",{css:{fontWeight:"var(--fw-bold)",color:i?void 0:"var(--brand-secondary-5)"}},i?i.displayName:`Enrichment '${o.cat}_${o.key}' is unknown`),e("div",{css:{marginLeft:"auto",display:"flex",alignItems:"center",border:"0 solid var(--gray-400)",borderLeftWidth:"1px",borderRightWidth:"1px",padding:"var(--spacing-sm) var(--spacing-base)",flexBasis:"9rem"}},e(_,{type:"text",min:0,max:i.cap||100,title:"score",value:o.str,css:{textAlign:"center",width:"100px"},onChange:d=>a(l,d.currentTarget.value)})),e("button",{type:"button",title:"Delete enrichment",onClick:()=>s(l),css:{border:0}},e(x,{icon:ge,iconColor:"red",size:"1.5rem"})))}))};import{useState as we}from"react";import{LoadingIndicator as Ee,Callout as $,InputSelect as Q,InputComboBox as ke,InputInlineSelect as Re,Icon as Z}from"@uniformdev/design-system";import j from"immer";import{CgCloseO as xe,CgMathPlus as Ie}from"react-icons/cg";import{css as X}from"@emotion/react";var L="6rem",Y=X`
|
|
27
40
|
position: relative;
|
|
28
41
|
padding: var(--spacing-base);
|
|
29
42
|
border: 1px solid var(--gray-300);
|
|
30
43
|
box-shadow: var(--shadow-base);
|
|
31
44
|
background-color: white;
|
|
32
45
|
border-radius: var(--rounded-base);
|
|
33
|
-
margin-top: ${
|
|
46
|
+
margin-top: ${L};
|
|
34
47
|
display: flex;
|
|
35
48
|
&:before {
|
|
36
49
|
content: '';
|
|
37
50
|
display: block;
|
|
38
51
|
width: 1px;
|
|
39
|
-
height: ${
|
|
52
|
+
height: ${L};
|
|
40
53
|
background-color: var(--gray-300);
|
|
41
54
|
position: absolute;
|
|
42
|
-
top: -${
|
|
55
|
+
top: -${L};
|
|
43
56
|
left: var(--spacing-lg);
|
|
44
57
|
}
|
|
45
58
|
&:first-of-type {
|
|
@@ -48,10 +61,9 @@ import{jsx as e}from"@emotion/react";import*as y from"react";import{Icon as Z}fr
|
|
|
48
61
|
display: none;
|
|
49
62
|
}
|
|
50
63
|
}
|
|
51
|
-
`,
|
|
64
|
+
`,J=X`
|
|
52
65
|
display: grid;
|
|
53
|
-
grid-template-columns: repeat(3, minmax(0, 1fr));
|
|
54
66
|
gap: var(--spacing-base);
|
|
55
67
|
flex-grow: 1;
|
|
56
68
|
margin-right: var(--spacing-base);
|
|
57
|
-
`;var
|
|
69
|
+
`;var Me=[{name:"=",value:"="},{name:"!=",value:"!="},{name:">",value:">"},{name:">=",value:">="},{name:"<",value:"<"},{name:"<=",value:"<="},{name:"is strongest",value:"+"},{name:"is weakest",value:"-"}],vt=({value:t,setValue:n,contextConfig:r,onMenuOpen:s,onMenuClose:a,displayTitle:o=!0})=>{let{loading:l,result:i,error:d}=R(r),c=t||{crit:[]},E=m=>{n({...c,op:m==="&"?void 0:m})},u=()=>{n({...c,crit:[...c.crit,{l:"",op:">",r:50}]})},g=(m,p)=>{n(j(c,w=>{w.crit[p]=m}))},D=m=>{let p=j(c,k=>{k.crit.splice(m,1)}),w=p.crit.length===0?null:p;n(w)};return d?e($,{type:"danger"},d):l||i===null?e(Ee,null):e("fieldset",{className:"personalization-criteria"},o?e("legend",{css:{fontSize:"var(--fs-md)",fontWeight:"var(--fw-bold)"}},"Personalize This"):null,c.crit.length?c.crit.map((m,p)=>{var f,b;let w=((f=m.l)==null?void 0:f.length)>0,k=m.op!=="+"&&m.op!=="-";return e("div",{css:Y,key:p},e("div",{css:J,style:{gridTemplateColumns:`repeat(${k?3:2}, minmax(0, 1fr))`},className:"criteriaItemInner"},e(Q,{name:`lhs-${p}`,label:"Match Dimension",showLabel:!1,value:m.l,options:[{label:"Select",value:""},...i.dimensions.map(h=>({label:h.displayName,value:h.dim}))],onChange:h=>{g({...m,l:h.target.value},p)}}),e("div",{css:{display:"flex",alignItems:"center",gap:"var(--spacing-base)",justifyContent:"space-around"}},e("span",{css:{color:"var(--gray-700)"}},"score"),e(Q,{css:{width:"100%"},name:`op-${p}`,label:"Operator",showLabel:!1,value:m.op,options:Me.map(h=>({label:h.name,value:h.value})),onChange:h=>{let S=h.target.value;g(S==="+"||S==="-"?{...m,op:S,r:void 0,rDim:void 0}:{...m,op:h.target.value},p)},disabled:!w})),k?e(Te,{critHasLhs:w,currentCriteria:m,dimensions:i,update:g,index:p,onMenuOpen:s,onMenuClose:a}):null),e("button",{type:"button",onClick:()=>D(p),title:"Delete Personalization",css:{backgroundColor:"transparent",backgroundImage:"none",borderWidth:0}},e(Z,{icon:xe,iconColor:"red",size:"1.5rem"})),p>0?e("div",{className:"criteria-group-operation",css:{position:"absolute",top:"-4rem",transform:"translateX(calc(1.5rem - 50%))"}},e(Re,{disabled:p>1,value:(b=c.op)!=null?b:"&",options:[{label:"AND",value:"&"},{label:"OR",value:"|"}],onChange:h=>{E(h.value)}})):null)}):e($,{title:"Default variant",type:"info",css:{marginBlock:"var(--spacing-base)"}},e("p",null,'This personalized variant has no match criteria and will be shown to any visitor that does not match any preceding variants. Ensure that default variants come last in the variant list. Personalize this variant by clicking "Add Criteria" to get started.')),i.dimensions.length===0?e($,{title:"Dimensions",type:"info",css:{marginBlock:"var(--spacing-base)"}},e("p",null,"You do not have any dimensions configured. Create your first"," ",e("a",{href:`${r.apiHost}/projects/${encodeURIComponent(r.projectId)}/personalization`,target:"_blank",rel:"noopener noreferrer",css:{":hover":{textDecorationLine:"underline"}}},"Dimension"))):e("button",{type:"button",className:"add-more",onClick:u,css:{color:"var(--brand-secondary-3)",display:"flex",gap:"var(--spacing-sm)",fontWeight:"var(--fw-bold)",marginTop:"var(--spacing-md)",alignItems:"center",backgroundColor:"transparent",backgroundImage:"none",borderWidth:0}},e("div",{css:{color:"white",backgroundColor:"var(--brand-secondary-3)",borderRadius:"var(--rounded-full)",padding:"var(--spacing-xs)"}},e(Z,{icon:Ie,iconColor:"currentColor",size:"1.25rem"})),"Add Criteria"))};function Te({update:t,currentCriteria:n,index:r,dimensions:s,critHasLhs:a,onMenuOpen:o,onMenuClose:l}){var c,E;let[i,d]=we(n.r&&I(n.r)!==null?n.r.toString(10):"");return e(ke,{name:`rhs-${r}`,className:"input-combobox",inputValue:i,value:{label:n.rDim?(E=(c=s.dimIndex[n.rDim])==null?void 0:c.displayName)!=null?E:n.r:"",value:n.r,isDisabled:!1},styles:{option:(u,{isDisabled:g})=>({...u,background:g?"transparent":void 0,fontSize:g?"0.8rem":void 0})},options:[{label:"Enter numeric score or choose another dimension score",value:"",isDisabled:!0},...s.dimensions.map(u=>({label:u.displayName,value:u.dim,isDisabled:!1}))],onChange:u=>{var g;u&&t({...n,rDim:(g=u.value)==null?void 0:g.toString(),r:void 0},r)},onInputChange:(u,g)=>{let D=I(u);g.action==="input-change"||g.action==="set-value"?(d(u),(D||u==="")&&t({...n,r:u,rDim:void 0},r)):!D&&!I(g.prevInputValue)&&d(u)},isDisabled:!a,noOptionsMessage:({inputValue:u})=>I(u)?`${u}`:"No options match",onMenuOpen:o,onMenuClose:l})}function I(t){return/^\d+$/.test(t.toString(10))}import Le from"react";import{useEffect as Se,useState as Ne}from"react";import{ManifestClient as Pe,ApiClientError as Ve}from"@uniformdev/context/api";function M({apiHost:t,apiKey:n,projectId:r}){let[s,a]=Ne({loading:!1,notConfigured:!1,error:null,result:null});return Se(()=>{if(!r||!n||!t){a({notConfigured:!0,loading:!1,error:null,result:null});return}(async()=>{a({notConfigured:!1,loading:!0,error:null,result:null});try{let i=await new Pe({projectId:r,apiKey:n,apiHost:t}).get({preview:!0});a({notConfigured:!1,loading:!1,error:null,result:i})}catch(l){let i;l instanceof Ve?(l.statusCode===403&&(i=`The API key ${n} did not have permissions to fetch the manifest. Ensure Context > Read Drafts permissions are granted.`),i=l.message):i=l.toString(),a({notConfigured:!1,loading:!1,error:i,result:null});return}})()},[t,n,r]),{result:s.result,error:s.error,loading:s.loading,notConfigured:s.notConfigured}}import{LoadingIndicator as $e}from"@uniformdev/design-system";function It({children:t,versionMap:n,contextConfig:r}){let{loading:s,result:a}=M(r);if(s)return e($e,null);if(a){let o=n[a.project.ui_version];if(o)return e(o,null)}return e(Le.Fragment,null,t)}import ee,{createContext as ze,useContext as z}from"react";import{LoadingIndicator as Ue}from"@uniformdev/design-system";var T=ze(null),zt=({loadingComponent:t,errorComponent:n,contextConfig:r,children:s})=>{let a=M(r),o=R(r);return a.error||a.notConfigured?n?e(n,{contextConfig:r,result:a}):e(ee.Fragment,null,"ErrorComponent is not configured"):o.error||o.notConfigured?n?e(n,{contextConfig:r,result:o}):e(ee.Fragment,null,"ErrorComponent is not configured"):a.loading||o.loading?t?e(t,null):e(Ue,null):e(T.Provider,{value:{manifest:a.result,dimensions:o.result,contextConfig:r}},s)};function Ut(){let t=z(T);if(!(t!=null&&t.contextConfig))throw new Error("Not within DataContext! Configuration data is not exist.");return t.contextConfig}function At(){let t=z(T);if(!(t!=null&&t.manifest))throw new Error("Not within DataContext! Manifest data is not exist.");return t.manifest}function Bt(){let t=z(T);if(!(t!=null&&t.dimensions))throw new Error("Not within DataContext! Dimensions data is not exist.");return t.dimensions}import{validate as Ae}from"uuid";import{ManifestClient as Be}from"@uniformdev/context/api";var te=async t=>{if(!t)return{valid:!1,error:new Error("contextConfig was not defined.")};if(!t.apiHost)return{valid:!1,error:new Error("apiHost was not defined.")};if(!t.apiKey)return{valid:!1,error:new Error("apiKey was not defined.")};if(!Ae(t.apiKey)&&!t.projectId)return{valid:!1,error:new Error("projectId is required when using a modern API key.")};let n=new Be({projectId:t.projectId,apiKey:t.apiKey,apiHost:t.apiHost});try{let r=await n.get({preview:!0});return{valid:!0,result:r}}catch(r){return{valid:!1,error:r}}};import{useEffect as Oe,useState as We}from"react";var Kt=t=>{let[n,r]=We({validating:!1,error:void 0}),{apiKey:s,apiHost:a,projectId:o}=t||{};return Oe(()=>{if(!s||!a)return;(async()=>{r({validating:!0,error:void 0});let{error:i,result:d}=await te({apiHost:a,apiKey:s,projectId:o});r(i?{error:i,validating:!1}:{error:void 0,validating:!1,result:d})})()},[a,s,o]),{validating:n.validating,error:n.error,result:n.result}};function Yt(t){return Array.isArray(t)&&t.length>0&&t[0].cat!==void 0}function Jt(t){return t.crit!==void 0}export*from"@uniformdev/design-system";export{zt as ContextData,A as EditLink,lt as EnrichmentTag,vt as PersonalizationCriteria,It as ProjectUIVersion,Ce as addEnrichmentLink,Me as equality,Yt as isEnrichmentTagData,Jt as isPersonalizationCriteriaData,Ut as useContextConfig,M as useContextData,R as useDimensions,Bt as useDimensionsDataContext,At as useManifest,Kt as useValidateContextConfig,te as validateContextConfig};
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,26 @@
|
|
|
1
|
-
var
|
|
1
|
+
var Ce=Object.create;var z=Object.defineProperty;var ve=Object.getOwnPropertyDescriptor;var he=Object.getOwnPropertyNames;var be=Object.getPrototypeOf,ye=Object.prototype.hasOwnProperty;var De=(e,n)=>{for(var r in n)z(e,r,{get:n[r],enumerable:!0})},$=(e,n,r,s)=>{if(n&&typeof n=="object"||typeof n=="function")for(let i of he(n))!ye.call(e,i)&&i!==r&&z(e,i,{get:()=>n[i],enumerable:!(s=ve(n,i))||s.enumerable});return e},D=(e,n,r)=>($(e,n,"default"),r&&$(r,n,"default")),P=(e,n,r)=>(r=e!=null?Ce(be(e)):{},$(n||!e||!e.__esModule?z(r,"default",{value:e,enumerable:!0}):r,e)),we=e=>$(z({},"__esModule",{value:!0}),e);var b={};De(b,{ContextData:()=>Ve,EditLink:()=>F,EnrichmentTag:()=>ke,PersonalizationCriteria:()=>Se,ProjectUIVersion:()=>Pe,addEnrichmentLink:()=>oe,equality:()=>ue,isEnrichmentTagData:()=>Ae,isPersonalizationCriteriaData:()=>Be,useContextConfig:()=>Le,useContextData:()=>L,useDimensions:()=>S,useDimensionsDataContext:()=>ze,useManifest:()=>$e,useValidateContextConfig:()=>Ue,validateContextConfig:()=>Z});module.exports=we(b);var t=require("@emotion/react"),k=P(require("react"));var te=require("@uniformdev/design-system"),ne=require("react-icons/cg");var j=require("@emotion/react"),ee=j.css`
|
|
2
2
|
display: flex;
|
|
3
3
|
align-items: center;
|
|
4
4
|
font-weight: var(--fw-bold);
|
|
5
|
+
gap: var(--spacing-sm);
|
|
6
|
+
margin-top: var(--spacing-md);
|
|
5
7
|
color: var(--brand-secondary-3);
|
|
6
8
|
&:hover,
|
|
7
9
|
&:focus {
|
|
8
10
|
text-decoration-line: underline;
|
|
9
11
|
}
|
|
10
|
-
`;var
|
|
12
|
+
`;var F=({linkTo:e,name:n,linkText:r=`Edit ${n} Component`})=>(0,t.jsx)("a",{css:ee,title:`Edit ${n} component definition`,rel:"noopener noreferrer",target:"_blank",href:e},r,(0,t.jsx)(te.Icon,{icon:ne.CgChevronRight,iconColor:"currentColor",size:"1.5rem"}));var w=P(require("react"));var U=require("react"),V=require("@uniformdev/context/api");function re(e,n,r){return e.reduce((s,i)=>{let o=n(i);if(typeof o=="undefined"||o===null)throw new Error("Objectify key selector returned undefined or null.");return s[n(i)]=r?r(i):i,s},{})}function S({apiHost:e,apiKey:n,projectId:r}){let[s,i]=(0,U.useState)({loading:!1,notConfigured:!1,error:null,result:null});return(0,U.useEffect)(()=>{if(!r||!n||!e){i({notConfigured:!0,loading:!1,error:null,result:null});return}(async()=>{i({notConfigured:!1,loading:!0,error:null,result:null});try{let a=(await new V.DimensionClient({projectId:r,apiKey:n,apiHost:e}).get()).dimensions.map(c=>({...c,displayName:(0,V.computeDimensionDisplayName)(c)})),d={dimensions:a,dimIndex:re(a,c=>c.dim,c=>c)};i({notConfigured:!1,loading:!1,error:null,result:d})}catch(l){let a;l instanceof V.ApiClientError?a=l.message:a=l.toString(),i({notConfigured:!1,loading:!1,error:a,result:null});return}})()},[e,n,r]),{result:s.result,error:s.error,loading:s.loading,notConfigured:s.notConfigured}}var X=require("@uniformdev/context"),g=require("@uniformdev/design-system"),N=require("react-icons/cg"),K=P(require("immer")),A=require("@emotion/react"),oe=A.css`
|
|
13
|
+
flex: 2;
|
|
14
|
+
display: flex;
|
|
15
|
+
width: 50%;
|
|
16
|
+
align-items: center;
|
|
17
|
+
font-weight: var(--fw-bold);
|
|
18
|
+
color: var(--brand-primary-1);
|
|
19
|
+
&:hover,
|
|
20
|
+
&:focus {
|
|
21
|
+
text-decoration-line: underline;
|
|
22
|
+
}
|
|
23
|
+
`,ke=({value:e,setValue:n,contextConfig:r,displayTitle:s=!0})=>{let{loading:i,result:o,error:l}=S(r),a=(0,w.useMemo)(()=>{if(o)return o.dimensions.filter(f=>f.category==="ENR")},[o]),d=(0,w.useMemo)(()=>{if(!e)return a;if(a)return a.filter(f=>!e.some(E=>(0,X.getEnrichmentVectorKey)(E.cat,E.key)===f.dim))},[a,e]),[c,M]=(0,w.useState)(""),[u,C]=(0,w.useState)(50),[x,m]=(0,w.useState)(!1),p=a==null?void 0:a.find(f=>f.dim===c),I=()=>{let[f,E]=c.split("_");T([...e!=null?e:[],{cat:f,key:E,str:u}]),M(""),C(50),m(!1)},T=f=>{let E=f.length===0?null:f;n(E)};return l?(0,t.jsx)(g.Callout,{type:"danger"},l):i||o===null?(0,t.jsx)(g.LoadingIndicator,null):(0,t.jsx)("fieldset",{className:"enrichment-tag"},s?(0,t.jsx)("div",{css:{display:"flex",justifyContent:"space-between",marginBottom:"var(--spacing-base)"}},(0,t.jsx)("legend",{css:{fontSize:"var(--fs-md)",fontWeight:"var(--fw-bold)"}},"Enrichment Tags")):null,a!=null&&a.length?!x&&!e?(0,t.jsx)(g.Callout,{title:"No enrichment tags assigned.",type:"info",css:{marginBlock:"var(--spacing-base)"}},(0,t.jsx)("p",null,"Click"," ",(0,t.jsx)("a",{onClick:()=>m(!0),target:"_blank",rel:"noopener noreferrer",css:{textDecorationLine:"underline"}},"here")," ","to assign your first enrichment tag.")):(0,t.jsx)(w.default.Fragment,null,o&&(0,t.jsx)(Me,{list:e!=null?e:[],setList:T,dimIndex:o.dimIndex}),x&&d&&d.length>0?(0,t.jsx)("div",{className:"add-enrichment-tag",css:{display:"flex",flexWrap:"wrap",gap:"var(--spacing-lg)",marginTop:"var(--spacing-md)",alignItems:"center"}},(0,t.jsx)("div",{css:{flexGrow:1}},(0,t.jsx)(g.InputSelect,{name:"enrichment-type",label:"Enrichment Tag",showLabel:!0,value:c,options:[{label:"Select",value:""},...d.map(f=>({label:f.displayName,value:f.dim}))],onChange:f=>M(f.currentTarget.value)})),(0,t.jsx)(Ie,{score:u,setValue:C,cap:p?p.cap:100,css:{flexBasis:"9rem"}}),(0,t.jsx)(g.Button,{buttonType:"tertiary",size:"xl",css:{marginBottom:"var(--spacing-xs)",height:"3.5rem",margin:0,alignSelf:"flex-end"},onClick:I,disabled:!c},"Add")):null,(0,t.jsx)("div",{className:"enrichment-cta",style:{paddingTop:"10px",display:"flex",justifyContent:"space-between"}},!x&&d&&d.length>0&&e?(0,t.jsx)("button",{type:"button",className:"add-more",onClick:()=>m(!0),css:{color:"var(--brand-secondary-3)",display:"flex",gap:"var(--spacing-sm)",fontWeight:"var(--fw-bold)",marginTop:"var(--spacing-md)",alignItems:"center",backgroundColor:"transparent",backgroundImage:"none",borderWidth:0,width:"50%",flex:2}},(0,t.jsx)("div",{css:{color:"white",backgroundColor:"var(--brand-secondary-3)",borderRadius:"var(--rounded-full)",padding:"var(--spacing-xs)"}},(0,t.jsx)(g.Icon,{icon:N.CgMathPlus,iconColor:"currentColor",size:"1.25rem"})),"Add More"):(0,t.jsx)("a",{css:oe,title:"none",href:"#"}),(0,t.jsx)(F,{name:"Enrichments",linkText:"Manage Enrichments",linkTo:`${r.apiHost}/projects/${encodeURIComponent(r.projectId)}/personalization/enrichments`}))):(0,t.jsx)(Re,{contextConfig:r}))},Re=({contextConfig:e})=>(0,t.jsx)(g.Callout,{title:"No enrichments found.",type:"caution",css:{marginBlock:"var(--spacing-base)"}},(0,t.jsx)("p",null,"Looks like you do not have any enrichments created in your connected Uniform project. Start by creating your first enrichment"," ",(0,t.jsx)("a",{href:`${e.apiHost}/projects/${encodeURIComponent(e.projectId)}/personalization/enrichments`,target:"_blank",rel:"noopener noreferrer",css:{":hover":{textDecorationLine:"underline"}}},"here"),".")),ie=(e,n=100,r=0)=>Math.max(Math.min(e,n),r),ae=A.css`
|
|
11
24
|
position: absolute;
|
|
12
25
|
bottom: 0.875rem;
|
|
13
26
|
left: var(--spacing-sm);
|
|
@@ -19,27 +32,27 @@ var ce=Object.create;var V=Object.defineProperty;var de=Object.getOwnPropertyDes
|
|
|
19
32
|
background-color: var(--gray-100);
|
|
20
33
|
border: 1px solid var(--gray-300);
|
|
21
34
|
border-radius: var(--rounded-full);
|
|
22
|
-
`,
|
|
23
|
-
${
|
|
35
|
+
`,xe=A.css`
|
|
36
|
+
${ae}
|
|
24
37
|
left: auto;
|
|
25
38
|
right: var(--spacing-sm);
|
|
26
|
-
`,
|
|
39
|
+
`,Ie=({score:e,setValue:n,cap:r=100,...s})=>{let i=o=>{let l=o==="increment"?e+10:e-10;l<0&&(l=0),l>r&&(l=r),n(l)};return(0,t.jsx)("div",{css:{position:"relative"},...s},(0,t.jsx)(g.Input,{label:"Strength",id:"enrichment-score",type:"number",min:0,max:r,value:e,onChange:o=>n(ie(Number(o.currentTarget.value)||0,r)),css:{textAlign:"center",boxSizing:"border-box"}}),(0,t.jsx)("button",{type:"button",title:"Reduce enrichment count",onClick:()=>i("decrement"),disabled:e===0,className:"scoreCounterButton",css:ae},(0,t.jsx)(g.Icon,{icon:N.CgMathMinus,iconColor:"gray",size:"1.5rem"})),(0,t.jsx)("button",{type:"button",title:"Increase enrichment count",onClick:()=>i("increment"),className:"scoreCounterButton",css:xe},(0,t.jsx)(g.Icon,{icon:N.CgMathPlus,iconColor:"gray",size:"1.5rem"})))},Me=({list:e,setList:n,dimIndex:r})=>{let s=o=>{n((0,K.default)(e,l=>{l.splice(o,1)}))},i=(o,l)=>{var d;let a=(d=r[`${e[o].cat}_${e[o].key}`])==null?void 0:d.cap;n((0,K.default)(e,c=>{c[o].str=ie(Number(l)||0,a)}))};return(0,t.jsx)(w.default.Fragment,null,e.map((o,l)=>{let a=r[(0,X.getEnrichmentVectorKey)(o.cat,o.key)];return(0,t.jsx)("div",{css:{display:"flex",alignItems:"center",gap:"var(--spacing-base)",backgroundColor:"var(--brand-secondary-2)",boxShadow:"var(--shadow-base)",borderRadius:"var(--rounded-base)",paddingInline:"var(--spacing-base)",marginBlock:"var(--spacing-base)"},className:"selected-enrichments",key:`${o.cat}-${o.key}`},(0,t.jsx)("span",{css:{fontWeight:"var(--fw-bold)",color:a?void 0:"var(--brand-secondary-5)"}},a?a.displayName:`Enrichment '${o.cat}_${o.key}' is unknown`),(0,t.jsx)("div",{css:{marginLeft:"auto",display:"flex",alignItems:"center",border:"0 solid var(--gray-400)",borderLeftWidth:"1px",borderRightWidth:"1px",padding:"var(--spacing-sm) var(--spacing-base)",flexBasis:"9rem"}},(0,t.jsx)(g.Input,{type:"text",min:0,max:a.cap||100,title:"score",value:o.str,css:{textAlign:"center",width:"100px"},onChange:d=>i(l,d.currentTarget.value)})),(0,t.jsx)("button",{type:"button",title:"Delete enrichment",onClick:()=>s(l),css:{border:0}},(0,t.jsx)(g.Icon,{icon:N.CgCloseO,iconColor:"red",size:"1.5rem"})))}))};var ce=require("react");var v=require("@uniformdev/design-system"),Q=P(require("immer")),O=require("react-icons/cg");var J=require("@emotion/react"),Y="6rem",se=J.css`
|
|
27
40
|
position: relative;
|
|
28
41
|
padding: var(--spacing-base);
|
|
29
42
|
border: 1px solid var(--gray-300);
|
|
30
43
|
box-shadow: var(--shadow-base);
|
|
31
44
|
background-color: white;
|
|
32
45
|
border-radius: var(--rounded-base);
|
|
33
|
-
margin-top: ${
|
|
46
|
+
margin-top: ${Y};
|
|
34
47
|
display: flex;
|
|
35
48
|
&:before {
|
|
36
49
|
content: '';
|
|
37
50
|
display: block;
|
|
38
51
|
width: 1px;
|
|
39
|
-
height: ${
|
|
52
|
+
height: ${Y};
|
|
40
53
|
background-color: var(--gray-300);
|
|
41
54
|
position: absolute;
|
|
42
|
-
top: -${
|
|
55
|
+
top: -${Y};
|
|
43
56
|
left: var(--spacing-lg);
|
|
44
57
|
}
|
|
45
58
|
&:first-of-type {
|
|
@@ -48,10 +61,9 @@ var ce=Object.create;var V=Object.defineProperty;var de=Object.getOwnPropertyDes
|
|
|
48
61
|
display: none;
|
|
49
62
|
}
|
|
50
63
|
}
|
|
51
|
-
`,
|
|
64
|
+
`,le=J.css`
|
|
52
65
|
display: grid;
|
|
53
|
-
grid-template-columns: repeat(3, minmax(0, 1fr));
|
|
54
66
|
gap: var(--spacing-base);
|
|
55
67
|
flex-grow: 1;
|
|
56
68
|
margin-right: var(--spacing-base);
|
|
57
|
-
`;var
|
|
69
|
+
`;var ue=[{name:"=",value:"="},{name:"!=",value:"!="},{name:">",value:">"},{name:">=",value:">="},{name:"<",value:"<"},{name:"<=",value:"<="},{name:"is strongest",value:"+"},{name:"is weakest",value:"-"}],Se=({value:e,setValue:n,contextConfig:r,onMenuOpen:s,onMenuClose:i,displayTitle:o=!0})=>{let{loading:l,result:a,error:d}=S(r),c=e||{crit:[]},M=m=>{n({...c,op:m==="&"?void 0:m})},u=()=>{n({...c,crit:[...c.crit,{l:"",op:">",r:50}]})},C=(m,p)=>{n((0,Q.default)(c,I=>{I.crit[p]=m}))},x=m=>{let p=(0,Q.default)(c,T=>{T.crit.splice(m,1)}),I=p.crit.length===0?null:p;n(I)};return d?(0,t.jsx)(v.Callout,{type:"danger"},d):l||a===null?(0,t.jsx)(v.LoadingIndicator,null):(0,t.jsx)("fieldset",{className:"personalization-criteria"},o?(0,t.jsx)("legend",{css:{fontSize:"var(--fs-md)",fontWeight:"var(--fw-bold)"}},"Personalize This"):null,c.crit.length?c.crit.map((m,p)=>{var f,E;let I=((f=m.l)==null?void 0:f.length)>0,T=m.op!=="+"&&m.op!=="-";return(0,t.jsx)("div",{css:se,key:p},(0,t.jsx)("div",{css:le,style:{gridTemplateColumns:`repeat(${T?3:2}, minmax(0, 1fr))`},className:"criteriaItemInner"},(0,t.jsx)(v.InputSelect,{name:`lhs-${p}`,label:"Match Dimension",showLabel:!1,value:m.l,options:[{label:"Select",value:""},...a.dimensions.map(y=>({label:y.displayName,value:y.dim}))],onChange:y=>{C({...m,l:y.target.value},p)}}),(0,t.jsx)("div",{css:{display:"flex",alignItems:"center",gap:"var(--spacing-base)",justifyContent:"space-around"}},(0,t.jsx)("span",{css:{color:"var(--gray-700)"}},"score"),(0,t.jsx)(v.InputSelect,{css:{width:"100%"},name:`op-${p}`,label:"Operator",showLabel:!1,value:m.op,options:ue.map(y=>({label:y.name,value:y.value})),onChange:y=>{let q=y.target.value;C(q==="+"||q==="-"?{...m,op:q,r:void 0,rDim:void 0}:{...m,op:y.target.value},p)},disabled:!I})),T?(0,t.jsx)(Ne,{critHasLhs:I,currentCriteria:m,dimensions:a,update:C,index:p,onMenuOpen:s,onMenuClose:i}):null),(0,t.jsx)("button",{type:"button",onClick:()=>x(p),title:"Delete Personalization",css:{backgroundColor:"transparent",backgroundImage:"none",borderWidth:0}},(0,t.jsx)(v.Icon,{icon:O.CgCloseO,iconColor:"red",size:"1.5rem"})),p>0?(0,t.jsx)("div",{className:"criteria-group-operation",css:{position:"absolute",top:"-4rem",transform:"translateX(calc(1.5rem - 50%))"}},(0,t.jsx)(v.InputInlineSelect,{disabled:p>1,value:(E=c.op)!=null?E:"&",options:[{label:"AND",value:"&"},{label:"OR",value:"|"}],onChange:y=>{M(y.value)}})):null)}):(0,t.jsx)(v.Callout,{title:"Default variant",type:"info",css:{marginBlock:"var(--spacing-base)"}},(0,t.jsx)("p",null,'This personalized variant has no match criteria and will be shown to any visitor that does not match any preceding variants. Ensure that default variants come last in the variant list. Personalize this variant by clicking "Add Criteria" to get started.')),a.dimensions.length===0?(0,t.jsx)(v.Callout,{title:"Dimensions",type:"info",css:{marginBlock:"var(--spacing-base)"}},(0,t.jsx)("p",null,"You do not have any dimensions configured. Create your first"," ",(0,t.jsx)("a",{href:`${r.apiHost}/projects/${encodeURIComponent(r.projectId)}/personalization`,target:"_blank",rel:"noopener noreferrer",css:{":hover":{textDecorationLine:"underline"}}},"Dimension"))):(0,t.jsx)("button",{type:"button",className:"add-more",onClick:u,css:{color:"var(--brand-secondary-3)",display:"flex",gap:"var(--spacing-sm)",fontWeight:"var(--fw-bold)",marginTop:"var(--spacing-md)",alignItems:"center",backgroundColor:"transparent",backgroundImage:"none",borderWidth:0}},(0,t.jsx)("div",{css:{color:"white",backgroundColor:"var(--brand-secondary-3)",borderRadius:"var(--rounded-full)",padding:"var(--spacing-xs)"}},(0,t.jsx)(v.Icon,{icon:O.CgMathPlus,iconColor:"currentColor",size:"1.25rem"})),"Add Criteria"))};function Ne({update:e,currentCriteria:n,index:r,dimensions:s,critHasLhs:i,onMenuOpen:o,onMenuClose:l}){var c,M;let[a,d]=(0,ce.useState)(n.r&&B(n.r)!==null?n.r.toString(10):"");return(0,t.jsx)(v.InputComboBox,{name:`rhs-${r}`,className:"input-combobox",inputValue:a,value:{label:n.rDim?(M=(c=s.dimIndex[n.rDim])==null?void 0:c.displayName)!=null?M:n.r:"",value:n.r,isDisabled:!1},styles:{option:(u,{isDisabled:C})=>({...u,background:C?"transparent":void 0,fontSize:C?"0.8rem":void 0})},options:[{label:"Enter numeric score or choose another dimension score",value:"",isDisabled:!0},...s.dimensions.map(u=>({label:u.displayName,value:u.dim,isDisabled:!1}))],onChange:u=>{var C;u&&e({...n,rDim:(C=u.value)==null?void 0:C.toString(),r:void 0},r)},onInputChange:(u,C)=>{let x=B(u);C.action==="input-change"||C.action==="set-value"?(d(u),(x||u==="")&&e({...n,r:u,rDim:void 0},r)):!x&&!B(C.prevInputValue)&&d(u)},isDisabled:!i,noOptionsMessage:({inputValue:u})=>B(u)?`${u}`:"No options match",onMenuOpen:o,onMenuClose:l})}function B(e){return/^\d+$/.test(e.toString(10))}var de=P(require("react"));var W=require("react"),G=require("@uniformdev/context/api");function L({apiHost:e,apiKey:n,projectId:r}){let[s,i]=(0,W.useState)({loading:!1,notConfigured:!1,error:null,result:null});return(0,W.useEffect)(()=>{if(!r||!n||!e){i({notConfigured:!0,loading:!1,error:null,result:null});return}(async()=>{i({notConfigured:!1,loading:!0,error:null,result:null});try{let a=await new G.ManifestClient({projectId:r,apiKey:n,apiHost:e}).get({preview:!0});i({notConfigured:!1,loading:!1,error:null,result:a})}catch(l){let a;l instanceof G.ApiClientError?(l.statusCode===403&&(a=`The API key ${n} did not have permissions to fetch the manifest. Ensure Context > Read Drafts permissions are granted.`),a=l.message):a=l.toString(),i({notConfigured:!1,loading:!1,error:a,result:null});return}})()},[e,n,r]),{result:s.result,error:s.error,loading:s.loading,notConfigured:s.notConfigured}}var me=require("@uniformdev/design-system");function Pe({children:e,versionMap:n,contextConfig:r}){let{loading:s,result:i}=L(r);if(s)return(0,t.jsx)(me.LoadingIndicator,null);if(i){let o=n[i.project.ui_version];if(o)return(0,t.jsx)(o,null)}return(0,t.jsx)(de.default.Fragment,null,e)}var R=P(require("react"));var pe=require("@uniformdev/design-system"),H=(0,R.createContext)(null),Ve=({loadingComponent:e,errorComponent:n,contextConfig:r,children:s})=>{let i=L(r),o=S(r);return i.error||i.notConfigured?n?(0,t.jsx)(n,{contextConfig:r,result:i}):(0,t.jsx)(R.default.Fragment,null,"ErrorComponent is not configured"):o.error||o.notConfigured?n?(0,t.jsx)(n,{contextConfig:r,result:o}):(0,t.jsx)(R.default.Fragment,null,"ErrorComponent is not configured"):i.loading||o.loading?e?(0,t.jsx)(e,null):(0,t.jsx)(pe.LoadingIndicator,null):(0,t.jsx)(H.Provider,{value:{manifest:i.result,dimensions:o.result,contextConfig:r}},s)};function Le(){let e=(0,R.useContext)(H);if(!(e!=null&&e.contextConfig))throw new Error("Not within DataContext! Configuration data is not exist.");return e.contextConfig}function $e(){let e=(0,R.useContext)(H);if(!(e!=null&&e.manifest))throw new Error("Not within DataContext! Manifest data is not exist.");return e.manifest}function ze(){let e=(0,R.useContext)(H);if(!(e!=null&&e.dimensions))throw new Error("Not within DataContext! Dimensions data is not exist.");return e.dimensions}var fe=require("uuid"),ge=require("@uniformdev/context/api"),Z=async e=>{if(!e)return{valid:!1,error:new Error("contextConfig was not defined.")};if(!e.apiHost)return{valid:!1,error:new Error("apiHost was not defined.")};if(!e.apiKey)return{valid:!1,error:new Error("apiKey was not defined.")};if(!(0,fe.validate)(e.apiKey)&&!e.projectId)return{valid:!1,error:new Error("projectId is required when using a modern API key.")};let n=new ge.ManifestClient({projectId:e.projectId,apiKey:e.apiKey,apiHost:e.apiHost});try{let r=await n.get({preview:!0});return{valid:!0,result:r}}catch(r){return{valid:!1,error:r}}};var _=require("react");var Ue=e=>{let[n,r]=(0,_.useState)({validating:!1,error:void 0}),{apiKey:s,apiHost:i,projectId:o}=e||{};return(0,_.useEffect)(()=>{if(!s||!i)return;(async()=>{r({validating:!0,error:void 0});let{error:a,result:d}=await Z({apiHost:i,apiKey:s,projectId:o});r(a?{error:a,validating:!1}:{error:void 0,validating:!1,result:d})})()},[i,s,o]),{validating:n.validating,error:n.error,result:n.result}};function Ae(e){return Array.isArray(e)&&e.length>0&&e[0].cat!==void 0}function Be(e){return e.crit!==void 0}D(b,require("@uniformdev/design-system"),module.exports);0&&(module.exports={ContextData,EditLink,EnrichmentTag,PersonalizationCriteria,ProjectUIVersion,addEnrichmentLink,equality,isEnrichmentTagData,isPersonalizationCriteriaData,useContextConfig,useContextData,useDimensions,useDimensionsDataContext,useManifest,useValidateContextConfig,validateContextConfig});
|
package/dist/index.mjs
CHANGED
|
@@ -1,13 +1,26 @@
|
|
|
1
|
-
import{jsx as e}from"@emotion/react";import*as y from"react";import{Icon as
|
|
1
|
+
import{jsx as e}from"@emotion/react";import*as y from"react";import{Icon as oe}from"@uniformdev/design-system";import{CgChevronRight as ie}from"react-icons/cg";import{css as ne}from"@emotion/react";var U=ne`
|
|
2
2
|
display: flex;
|
|
3
3
|
align-items: center;
|
|
4
4
|
font-weight: var(--fw-bold);
|
|
5
|
+
gap: var(--spacing-sm);
|
|
6
|
+
margin-top: var(--spacing-md);
|
|
5
7
|
color: var(--brand-secondary-3);
|
|
6
8
|
&:hover,
|
|
7
9
|
&:focus {
|
|
8
10
|
text-decoration-line: underline;
|
|
9
11
|
}
|
|
10
|
-
`;var
|
|
12
|
+
`;var A=({linkTo:t,name:n,linkText:r=`Edit ${n} Component`})=>e("a",{css:U,title:`Edit ${n} component definition`,rel:"noopener noreferrer",target:"_blank",href:t},r,e(oe,{icon:ie,iconColor:"currentColor",size:"1.5rem"}));import G,{useMemo as O,useState as N}from"react";import{useEffect as ae,useState as se}from"react";import{DimensionClient as le,computeDimensionDisplayName as ce,ApiClientError as ue}from"@uniformdev/context/api";function B(t,n,r){return t.reduce((s,a)=>{let o=n(a);if(typeof o=="undefined"||o===null)throw new Error("Objectify key selector returned undefined or null.");return s[n(a)]=r?r(a):a,s},{})}function R({apiHost:t,apiKey:n,projectId:r}){let[s,a]=se({loading:!1,notConfigured:!1,error:null,result:null});return ae(()=>{if(!r||!n||!t){a({notConfigured:!0,loading:!1,error:null,result:null});return}(async()=>{a({notConfigured:!1,loading:!0,error:null,result:null});try{let i=(await new le({projectId:r,apiKey:n,apiHost:t}).get()).dimensions.map(c=>({...c,displayName:ce(c)})),d={dimensions:i,dimIndex:B(i,c=>c.dim,c=>c)};a({notConfigured:!1,loading:!1,error:null,result:d})}catch(l){let i;l instanceof ue?i=l.message:i=l.toString(),a({notConfigured:!1,loading:!1,error:i,result:null});return}})()},[t,n,r]),{result:s.result,error:s.error,loading:s.loading,notConfigured:s.notConfigured}}import{getEnrichmentVectorKey as H}from"@uniformdev/context";import{Input as _,Button as de,InputSelect as me,Callout as P,Icon as x,LoadingIndicator as pe}from"@uniformdev/design-system";import{CgMathPlus as q,CgMathMinus as fe,CgCloseO as ge}from"react-icons/cg";import W from"immer";import{css as V}from"@emotion/react";var Ce=V`
|
|
13
|
+
flex: 2;
|
|
14
|
+
display: flex;
|
|
15
|
+
width: 50%;
|
|
16
|
+
align-items: center;
|
|
17
|
+
font-weight: var(--fw-bold);
|
|
18
|
+
color: var(--brand-primary-1);
|
|
19
|
+
&:hover,
|
|
20
|
+
&:focus {
|
|
21
|
+
text-decoration-line: underline;
|
|
22
|
+
}
|
|
23
|
+
`,lt=({value:t,setValue:n,contextConfig:r,displayTitle:s=!0})=>{let{loading:a,result:o,error:l}=R(r),i=O(()=>{if(o)return o.dimensions.filter(f=>f.category==="ENR")},[o]),d=O(()=>{if(!t)return i;if(i)return i.filter(f=>!t.some(b=>H(b.cat,b.key)===f.dim))},[i,t]),[c,E]=N(""),[u,g]=N(50),[D,m]=N(!1),p=i==null?void 0:i.find(f=>f.dim===c),w=()=>{let[f,b]=c.split("_");k([...t!=null?t:[],{cat:f,key:b,str:u}]),E(""),g(50),m(!1)},k=f=>{let b=f.length===0?null:f;n(b)};return l?e(P,{type:"danger"},l):a||o===null?e(pe,null):e("fieldset",{className:"enrichment-tag"},s?e("div",{css:{display:"flex",justifyContent:"space-between",marginBottom:"var(--spacing-base)"}},e("legend",{css:{fontSize:"var(--fs-md)",fontWeight:"var(--fw-bold)"}},"Enrichment Tags")):null,i!=null&&i.length?!D&&!t?e(P,{title:"No enrichment tags assigned.",type:"info",css:{marginBlock:"var(--spacing-base)"}},e("p",null,"Click"," ",e("a",{onClick:()=>m(!0),target:"_blank",rel:"noopener noreferrer",css:{textDecorationLine:"underline"}},"here")," ","to assign your first enrichment tag.")):e(G.Fragment,null,o&&e(ye,{list:t!=null?t:[],setList:k,dimIndex:o.dimIndex}),D&&d&&d.length>0?e("div",{className:"add-enrichment-tag",css:{display:"flex",flexWrap:"wrap",gap:"var(--spacing-lg)",marginTop:"var(--spacing-md)",alignItems:"center"}},e("div",{css:{flexGrow:1}},e(me,{name:"enrichment-type",label:"Enrichment Tag",showLabel:!0,value:c,options:[{label:"Select",value:""},...d.map(f=>({label:f.displayName,value:f.dim}))],onChange:f=>E(f.currentTarget.value)})),e(be,{score:u,setValue:g,cap:p?p.cap:100,css:{flexBasis:"9rem"}}),e(de,{buttonType:"tertiary",size:"xl",css:{marginBottom:"var(--spacing-xs)",height:"3.5rem",margin:0,alignSelf:"flex-end"},onClick:w,disabled:!c},"Add")):null,e("div",{className:"enrichment-cta",style:{paddingTop:"10px",display:"flex",justifyContent:"space-between"}},!D&&d&&d.length>0&&t?e("button",{type:"button",className:"add-more",onClick:()=>m(!0),css:{color:"var(--brand-secondary-3)",display:"flex",gap:"var(--spacing-sm)",fontWeight:"var(--fw-bold)",marginTop:"var(--spacing-md)",alignItems:"center",backgroundColor:"transparent",backgroundImage:"none",borderWidth:0,width:"50%",flex:2}},e("div",{css:{color:"white",backgroundColor:"var(--brand-secondary-3)",borderRadius:"var(--rounded-full)",padding:"var(--spacing-xs)"}},e(x,{icon:q,iconColor:"currentColor",size:"1.25rem"})),"Add More"):e("a",{css:Ce,title:"none",href:"#"}),e(A,{name:"Enrichments",linkText:"Manage Enrichments",linkTo:`${r.apiHost}/projects/${encodeURIComponent(r.projectId)}/personalization/enrichments`}))):e(ve,{contextConfig:r}))},ve=({contextConfig:t})=>e(P,{title:"No enrichments found.",type:"caution",css:{marginBlock:"var(--spacing-base)"}},e("p",null,"Looks like you do not have any enrichments created in your connected Uniform project. Start by creating your first enrichment"," ",e("a",{href:`${t.apiHost}/projects/${encodeURIComponent(t.projectId)}/personalization/enrichments`,target:"_blank",rel:"noopener noreferrer",css:{":hover":{textDecorationLine:"underline"}}},"here"),".")),F=(t,n=100,r=0)=>Math.max(Math.min(t,n),r),K=V`
|
|
11
24
|
position: absolute;
|
|
12
25
|
bottom: 0.875rem;
|
|
13
26
|
left: var(--spacing-sm);
|
|
@@ -19,27 +32,27 @@ import{jsx as e}from"@emotion/react";import*as y from"react";import{Icon as Z}fr
|
|
|
19
32
|
background-color: var(--gray-100);
|
|
20
33
|
border: 1px solid var(--gray-300);
|
|
21
34
|
border-radius: var(--rounded-full);
|
|
22
|
-
`,
|
|
23
|
-
${
|
|
35
|
+
`,he=V`
|
|
36
|
+
${K}
|
|
24
37
|
left: auto;
|
|
25
38
|
right: var(--spacing-sm);
|
|
26
|
-
`,
|
|
39
|
+
`,be=({score:t,setValue:n,cap:r=100,...s})=>{let a=o=>{let l=o==="increment"?t+10:t-10;l<0&&(l=0),l>r&&(l=r),n(l)};return e("div",{css:{position:"relative"},...s},e(_,{label:"Strength",id:"enrichment-score",type:"number",min:0,max:r,value:t,onChange:o=>n(F(Number(o.currentTarget.value)||0,r)),css:{textAlign:"center",boxSizing:"border-box"}}),e("button",{type:"button",title:"Reduce enrichment count",onClick:()=>a("decrement"),disabled:t===0,className:"scoreCounterButton",css:K},e(x,{icon:fe,iconColor:"gray",size:"1.5rem"})),e("button",{type:"button",title:"Increase enrichment count",onClick:()=>a("increment"),className:"scoreCounterButton",css:he},e(x,{icon:q,iconColor:"gray",size:"1.5rem"})))},ye=({list:t,setList:n,dimIndex:r})=>{let s=o=>{n(W(t,l=>{l.splice(o,1)}))},a=(o,l)=>{var d;let i=(d=r[`${t[o].cat}_${t[o].key}`])==null?void 0:d.cap;n(W(t,c=>{c[o].str=F(Number(l)||0,i)}))};return e(G.Fragment,null,t.map((o,l)=>{let i=r[H(o.cat,o.key)];return e("div",{css:{display:"flex",alignItems:"center",gap:"var(--spacing-base)",backgroundColor:"var(--brand-secondary-2)",boxShadow:"var(--shadow-base)",borderRadius:"var(--rounded-base)",paddingInline:"var(--spacing-base)",marginBlock:"var(--spacing-base)"},className:"selected-enrichments",key:`${o.cat}-${o.key}`},e("span",{css:{fontWeight:"var(--fw-bold)",color:i?void 0:"var(--brand-secondary-5)"}},i?i.displayName:`Enrichment '${o.cat}_${o.key}' is unknown`),e("div",{css:{marginLeft:"auto",display:"flex",alignItems:"center",border:"0 solid var(--gray-400)",borderLeftWidth:"1px",borderRightWidth:"1px",padding:"var(--spacing-sm) var(--spacing-base)",flexBasis:"9rem"}},e(_,{type:"text",min:0,max:i.cap||100,title:"score",value:o.str,css:{textAlign:"center",width:"100px"},onChange:d=>a(l,d.currentTarget.value)})),e("button",{type:"button",title:"Delete enrichment",onClick:()=>s(l),css:{border:0}},e(x,{icon:ge,iconColor:"red",size:"1.5rem"})))}))};import{useState as we}from"react";import{LoadingIndicator as Ee,Callout as $,InputSelect as Q,InputComboBox as ke,InputInlineSelect as Re,Icon as Z}from"@uniformdev/design-system";import j from"immer";import{CgCloseO as xe,CgMathPlus as Ie}from"react-icons/cg";import{css as X}from"@emotion/react";var L="6rem",Y=X`
|
|
27
40
|
position: relative;
|
|
28
41
|
padding: var(--spacing-base);
|
|
29
42
|
border: 1px solid var(--gray-300);
|
|
30
43
|
box-shadow: var(--shadow-base);
|
|
31
44
|
background-color: white;
|
|
32
45
|
border-radius: var(--rounded-base);
|
|
33
|
-
margin-top: ${
|
|
46
|
+
margin-top: ${L};
|
|
34
47
|
display: flex;
|
|
35
48
|
&:before {
|
|
36
49
|
content: '';
|
|
37
50
|
display: block;
|
|
38
51
|
width: 1px;
|
|
39
|
-
height: ${
|
|
52
|
+
height: ${L};
|
|
40
53
|
background-color: var(--gray-300);
|
|
41
54
|
position: absolute;
|
|
42
|
-
top: -${
|
|
55
|
+
top: -${L};
|
|
43
56
|
left: var(--spacing-lg);
|
|
44
57
|
}
|
|
45
58
|
&:first-of-type {
|
|
@@ -48,10 +61,9 @@ import{jsx as e}from"@emotion/react";import*as y from"react";import{Icon as Z}fr
|
|
|
48
61
|
display: none;
|
|
49
62
|
}
|
|
50
63
|
}
|
|
51
|
-
`,
|
|
64
|
+
`,J=X`
|
|
52
65
|
display: grid;
|
|
53
|
-
grid-template-columns: repeat(3, minmax(0, 1fr));
|
|
54
66
|
gap: var(--spacing-base);
|
|
55
67
|
flex-grow: 1;
|
|
56
68
|
margin-right: var(--spacing-base);
|
|
57
|
-
`;var
|
|
69
|
+
`;var Me=[{name:"=",value:"="},{name:"!=",value:"!="},{name:">",value:">"},{name:">=",value:">="},{name:"<",value:"<"},{name:"<=",value:"<="},{name:"is strongest",value:"+"},{name:"is weakest",value:"-"}],vt=({value:t,setValue:n,contextConfig:r,onMenuOpen:s,onMenuClose:a,displayTitle:o=!0})=>{let{loading:l,result:i,error:d}=R(r),c=t||{crit:[]},E=m=>{n({...c,op:m==="&"?void 0:m})},u=()=>{n({...c,crit:[...c.crit,{l:"",op:">",r:50}]})},g=(m,p)=>{n(j(c,w=>{w.crit[p]=m}))},D=m=>{let p=j(c,k=>{k.crit.splice(m,1)}),w=p.crit.length===0?null:p;n(w)};return d?e($,{type:"danger"},d):l||i===null?e(Ee,null):e("fieldset",{className:"personalization-criteria"},o?e("legend",{css:{fontSize:"var(--fs-md)",fontWeight:"var(--fw-bold)"}},"Personalize This"):null,c.crit.length?c.crit.map((m,p)=>{var f,b;let w=((f=m.l)==null?void 0:f.length)>0,k=m.op!=="+"&&m.op!=="-";return e("div",{css:Y,key:p},e("div",{css:J,style:{gridTemplateColumns:`repeat(${k?3:2}, minmax(0, 1fr))`},className:"criteriaItemInner"},e(Q,{name:`lhs-${p}`,label:"Match Dimension",showLabel:!1,value:m.l,options:[{label:"Select",value:""},...i.dimensions.map(h=>({label:h.displayName,value:h.dim}))],onChange:h=>{g({...m,l:h.target.value},p)}}),e("div",{css:{display:"flex",alignItems:"center",gap:"var(--spacing-base)",justifyContent:"space-around"}},e("span",{css:{color:"var(--gray-700)"}},"score"),e(Q,{css:{width:"100%"},name:`op-${p}`,label:"Operator",showLabel:!1,value:m.op,options:Me.map(h=>({label:h.name,value:h.value})),onChange:h=>{let S=h.target.value;g(S==="+"||S==="-"?{...m,op:S,r:void 0,rDim:void 0}:{...m,op:h.target.value},p)},disabled:!w})),k?e(Te,{critHasLhs:w,currentCriteria:m,dimensions:i,update:g,index:p,onMenuOpen:s,onMenuClose:a}):null),e("button",{type:"button",onClick:()=>D(p),title:"Delete Personalization",css:{backgroundColor:"transparent",backgroundImage:"none",borderWidth:0}},e(Z,{icon:xe,iconColor:"red",size:"1.5rem"})),p>0?e("div",{className:"criteria-group-operation",css:{position:"absolute",top:"-4rem",transform:"translateX(calc(1.5rem - 50%))"}},e(Re,{disabled:p>1,value:(b=c.op)!=null?b:"&",options:[{label:"AND",value:"&"},{label:"OR",value:"|"}],onChange:h=>{E(h.value)}})):null)}):e($,{title:"Default variant",type:"info",css:{marginBlock:"var(--spacing-base)"}},e("p",null,'This personalized variant has no match criteria and will be shown to any visitor that does not match any preceding variants. Ensure that default variants come last in the variant list. Personalize this variant by clicking "Add Criteria" to get started.')),i.dimensions.length===0?e($,{title:"Dimensions",type:"info",css:{marginBlock:"var(--spacing-base)"}},e("p",null,"You do not have any dimensions configured. Create your first"," ",e("a",{href:`${r.apiHost}/projects/${encodeURIComponent(r.projectId)}/personalization`,target:"_blank",rel:"noopener noreferrer",css:{":hover":{textDecorationLine:"underline"}}},"Dimension"))):e("button",{type:"button",className:"add-more",onClick:u,css:{color:"var(--brand-secondary-3)",display:"flex",gap:"var(--spacing-sm)",fontWeight:"var(--fw-bold)",marginTop:"var(--spacing-md)",alignItems:"center",backgroundColor:"transparent",backgroundImage:"none",borderWidth:0}},e("div",{css:{color:"white",backgroundColor:"var(--brand-secondary-3)",borderRadius:"var(--rounded-full)",padding:"var(--spacing-xs)"}},e(Z,{icon:Ie,iconColor:"currentColor",size:"1.25rem"})),"Add Criteria"))};function Te({update:t,currentCriteria:n,index:r,dimensions:s,critHasLhs:a,onMenuOpen:o,onMenuClose:l}){var c,E;let[i,d]=we(n.r&&I(n.r)!==null?n.r.toString(10):"");return e(ke,{name:`rhs-${r}`,className:"input-combobox",inputValue:i,value:{label:n.rDim?(E=(c=s.dimIndex[n.rDim])==null?void 0:c.displayName)!=null?E:n.r:"",value:n.r,isDisabled:!1},styles:{option:(u,{isDisabled:g})=>({...u,background:g?"transparent":void 0,fontSize:g?"0.8rem":void 0})},options:[{label:"Enter numeric score or choose another dimension score",value:"",isDisabled:!0},...s.dimensions.map(u=>({label:u.displayName,value:u.dim,isDisabled:!1}))],onChange:u=>{var g;u&&t({...n,rDim:(g=u.value)==null?void 0:g.toString(),r:void 0},r)},onInputChange:(u,g)=>{let D=I(u);g.action==="input-change"||g.action==="set-value"?(d(u),(D||u==="")&&t({...n,r:u,rDim:void 0},r)):!D&&!I(g.prevInputValue)&&d(u)},isDisabled:!a,noOptionsMessage:({inputValue:u})=>I(u)?`${u}`:"No options match",onMenuOpen:o,onMenuClose:l})}function I(t){return/^\d+$/.test(t.toString(10))}import Le from"react";import{useEffect as Se,useState as Ne}from"react";import{ManifestClient as Pe,ApiClientError as Ve}from"@uniformdev/context/api";function M({apiHost:t,apiKey:n,projectId:r}){let[s,a]=Ne({loading:!1,notConfigured:!1,error:null,result:null});return Se(()=>{if(!r||!n||!t){a({notConfigured:!0,loading:!1,error:null,result:null});return}(async()=>{a({notConfigured:!1,loading:!0,error:null,result:null});try{let i=await new Pe({projectId:r,apiKey:n,apiHost:t}).get({preview:!0});a({notConfigured:!1,loading:!1,error:null,result:i})}catch(l){let i;l instanceof Ve?(l.statusCode===403&&(i=`The API key ${n} did not have permissions to fetch the manifest. Ensure Context > Read Drafts permissions are granted.`),i=l.message):i=l.toString(),a({notConfigured:!1,loading:!1,error:i,result:null});return}})()},[t,n,r]),{result:s.result,error:s.error,loading:s.loading,notConfigured:s.notConfigured}}import{LoadingIndicator as $e}from"@uniformdev/design-system";function It({children:t,versionMap:n,contextConfig:r}){let{loading:s,result:a}=M(r);if(s)return e($e,null);if(a){let o=n[a.project.ui_version];if(o)return e(o,null)}return e(Le.Fragment,null,t)}import ee,{createContext as ze,useContext as z}from"react";import{LoadingIndicator as Ue}from"@uniformdev/design-system";var T=ze(null),zt=({loadingComponent:t,errorComponent:n,contextConfig:r,children:s})=>{let a=M(r),o=R(r);return a.error||a.notConfigured?n?e(n,{contextConfig:r,result:a}):e(ee.Fragment,null,"ErrorComponent is not configured"):o.error||o.notConfigured?n?e(n,{contextConfig:r,result:o}):e(ee.Fragment,null,"ErrorComponent is not configured"):a.loading||o.loading?t?e(t,null):e(Ue,null):e(T.Provider,{value:{manifest:a.result,dimensions:o.result,contextConfig:r}},s)};function Ut(){let t=z(T);if(!(t!=null&&t.contextConfig))throw new Error("Not within DataContext! Configuration data is not exist.");return t.contextConfig}function At(){let t=z(T);if(!(t!=null&&t.manifest))throw new Error("Not within DataContext! Manifest data is not exist.");return t.manifest}function Bt(){let t=z(T);if(!(t!=null&&t.dimensions))throw new Error("Not within DataContext! Dimensions data is not exist.");return t.dimensions}import{validate as Ae}from"uuid";import{ManifestClient as Be}from"@uniformdev/context/api";var te=async t=>{if(!t)return{valid:!1,error:new Error("contextConfig was not defined.")};if(!t.apiHost)return{valid:!1,error:new Error("apiHost was not defined.")};if(!t.apiKey)return{valid:!1,error:new Error("apiKey was not defined.")};if(!Ae(t.apiKey)&&!t.projectId)return{valid:!1,error:new Error("projectId is required when using a modern API key.")};let n=new Be({projectId:t.projectId,apiKey:t.apiKey,apiHost:t.apiHost});try{let r=await n.get({preview:!0});return{valid:!0,result:r}}catch(r){return{valid:!1,error:r}}};import{useEffect as Oe,useState as We}from"react";var Kt=t=>{let[n,r]=We({validating:!1,error:void 0}),{apiKey:s,apiHost:a,projectId:o}=t||{};return Oe(()=>{if(!s||!a)return;(async()=>{r({validating:!0,error:void 0});let{error:i,result:d}=await te({apiHost:a,apiKey:s,projectId:o});r(i?{error:i,validating:!1}:{error:void 0,validating:!1,result:d})})()},[a,s,o]),{validating:n.validating,error:n.error,result:n.result}};function Yt(t){return Array.isArray(t)&&t.length>0&&t[0].cat!==void 0}function Jt(t){return t.crit!==void 0}export*from"@uniformdev/design-system";export{zt as ContextData,A as EditLink,lt as EnrichmentTag,vt as PersonalizationCriteria,It as ProjectUIVersion,Ce as addEnrichmentLink,Me as equality,Yt as isEnrichmentTagData,Jt as isPersonalizationCriteriaData,Ut as useContextConfig,M as useContextData,R as useDimensions,Bt as useDimensionsDataContext,At as useManifest,Kt as useValidateContextConfig,te as validateContextConfig};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniformdev/context-ui",
|
|
3
|
-
"version": "16.0.
|
|
3
|
+
"version": "16.0.1-alpha.221+a3ca75662",
|
|
4
4
|
"description": "React-based functionality and components for Uniform Context",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -35,13 +35,13 @@
|
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@emotion/react": "11.9.0",
|
|
38
|
-
"@uniformdev/context": "^16.0.
|
|
39
|
-
"@uniformdev/design-system": "^16.0.
|
|
40
|
-
"immer": "9.0.
|
|
38
|
+
"@uniformdev/context": "^16.0.1-alpha.221+a3ca75662",
|
|
39
|
+
"@uniformdev/design-system": "^16.0.1-alpha.221+a3ca75662",
|
|
40
|
+
"immer": "9.0.14",
|
|
41
41
|
"react-beautiful-dnd": "13.1.0",
|
|
42
42
|
"react-icons": "^4.3.1",
|
|
43
|
-
"react-select": "5.3.
|
|
44
|
-
"react-use": "17.
|
|
43
|
+
"react-select": "5.3.2",
|
|
44
|
+
"react-use": "17.4.0",
|
|
45
45
|
"reakit": "1.3.11",
|
|
46
46
|
"timeago.js": "4.0.2",
|
|
47
47
|
"uuid": "8.3.2"
|
|
@@ -51,25 +51,25 @@
|
|
|
51
51
|
"react-dom": ">=16.8"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"@babel/core": "7.
|
|
55
|
-
"@babel/preset-env": "7.
|
|
56
|
-
"@babel/preset-react": "7.
|
|
54
|
+
"@babel/core": "7.18.0",
|
|
55
|
+
"@babel/preset-env": "7.18.0",
|
|
56
|
+
"@babel/preset-react": "7.17.12",
|
|
57
57
|
"@emotion/babel-preset-css-prop": "11.2.0",
|
|
58
|
-
"@storybook/addon-controls": "6.4
|
|
59
|
-
"@storybook/addon-essentials": "6.4
|
|
58
|
+
"@storybook/addon-controls": "6.5.4",
|
|
59
|
+
"@storybook/addon-essentials": "6.5.4",
|
|
60
60
|
"@storybook/addon-postcss": "2.0.0",
|
|
61
|
-
"@storybook/builder-webpack5": "6.5.
|
|
62
|
-
"@storybook/manager-webpack5": "6.5.
|
|
63
|
-
"@storybook/react": "6.4
|
|
64
|
-
"@types/react": "
|
|
61
|
+
"@storybook/builder-webpack5": "6.5.4",
|
|
62
|
+
"@storybook/manager-webpack5": "6.5.4",
|
|
63
|
+
"@storybook/react": "6.5.4",
|
|
64
|
+
"@types/react": "18.0.9",
|
|
65
65
|
"@types/react-beautiful-dnd": "13.1.2",
|
|
66
66
|
"@types/uuid": "8.3.4",
|
|
67
|
-
"autoprefixer": "10.4.
|
|
68
|
-
"postcss": "8.4.
|
|
67
|
+
"autoprefixer": "10.4.7",
|
|
68
|
+
"postcss": "8.4.14",
|
|
69
69
|
"postcss-import": "14.1.0",
|
|
70
|
-
"react": "
|
|
71
|
-
"react-dom": "
|
|
72
|
-
"webpack": "5.72.
|
|
70
|
+
"react": "18.1.0",
|
|
71
|
+
"react-dom": "18.1.0",
|
|
72
|
+
"webpack": "5.72.1"
|
|
73
73
|
},
|
|
74
74
|
"files": [
|
|
75
75
|
"/dist"
|
|
@@ -77,5 +77,5 @@
|
|
|
77
77
|
"publishConfig": {
|
|
78
78
|
"access": "public"
|
|
79
79
|
},
|
|
80
|
-
"gitHead": "
|
|
80
|
+
"gitHead": "a3ca7566254cda6539ae81923567cc06754241aa"
|
|
81
81
|
}
|