@datawheel/bespoke 0.7.6-rc.9 → 0.7.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cms.js +64 -63
- package/dist/explore.js +5 -4
- package/dist/redux-store.js +2 -2
- package/dist/report.js +34 -33
- package/dist/server.js +37 -33
- package/package.json +1 -1
package/dist/explore.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { Stack, Text, Badge, Group, Container, TextInput, Loader, ActionIcon, LoadingOverlay, Alert, Tooltip, Modal, Autocomplete, Button, useMantineTheme, ScrollArea, Grid, Pagination, Image, Card } from '@mantine/core';
|
|
1
|
+
import { Stack, Text, Badge, Group, Container, TextInput, Loader, ActionIcon, LoadingOverlay, Alert, Tooltip, Modal, Autocomplete, MediaQuery, Select, Button, useMantineTheme, ScrollArea, Grid, Pagination, Image, Card } from '@mantine/core';
|
|
2
2
|
import { createContext, forwardRef, useContext, useState, useCallback, useEffect, useMemo, useRef } from 'react';
|
|
3
3
|
import { IconSearch, IconTrash, IconX } from '@tabler/icons-react';
|
|
4
4
|
import { useDebouncedValue, useClickOutside } from '@mantine/hooks';
|
|
5
5
|
import { useRouter } from 'next/router';
|
|
6
|
-
import
|
|
6
|
+
import de from 'axios';
|
|
7
7
|
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
8
|
+
import { format } from 'd3-format';
|
|
8
9
|
|
|
9
|
-
var ae={try_another:"Try another search or filter.",search:"Search",filters_all:"All",no_results:"No Results",load_more:"Load more",report:{},dimension:{},variant:{}},de=createContext({metadata:[],loadingItems:!1,setLoadingItems:()=>null,loadingMetadata:!1,setLoadingMetadata:()=>null,resultCount:{},totalCount:{},setResultCount:()=>null,activePage:1,setActivePage:()=>null,pageSize:10,results:[],filters:{},doQuery:()=>null,setFilters:()=>null,query:"",setQuery:()=>null,debouncedQuery:"",currentPageTotal:10,selectorStructure:[],translations:ae,setTranslations:()=>null,showSelectors:!0}),A=()=>useContext(de);function $e({children:o,pageSize:r=10}){let n={profile:void 0,variant:void 0},[l,u]=useState([]),[h,i]=useState(!1),[x,p]=useState(!1),[c,y]=useState({}),[e,b]=useState({}),[m,C]=useState(1),[f,L]=useState(n),[M,J]=useState(""),[N]=useDebouncedValue(M,500),[Q,Y]=useState([]),[W,V]=useState(ae),[B,k]=useState(!1),{locale:G}=useRouter(),X=async()=>{try{p(!0),ue.get("/api/cms/read/metadata").then(t=>{if(t&&t.data&&t.data.data&&t.data.data.data){let R=t.data.data.data.reduce((g,s)=>(s.dimensions&&s.dimensions.forEach(d=>{d.variants&&d.variants.forEach(a=>{g[a.id]=a.members_count||0;});}),g),{});u(t.data.data.data),y(R),b(R);}p(!1),k(!0);}).catch(t=>{console.error(t);});}catch(t){console.error("Error fetching metadata:",t),u([]),p(!1),y({}),b({});}},Z=t=>{y(t||e);},O=useCallback(async(t,R)=>{!B&&l.length===0&&await X(),L({profile:t,variant:R});},[]);useEffect(()=>{let t=!1;return B&&(i(!0),C(1),H(t,0)),()=>{t=!1;}},[N,f,B]),useEffect(()=>{if(B){i(!0);let t=(m-1)*r;H(!1,t);}},[m]);let H=async(t,R)=>{let g=f.profile&&!Number.isNaN(f.profile)?[f.profile]:[],s=f.variant&&!Number.isNaN(f.variant)?[f.variant]:[],d={query:N,format:"profiles",locale:G,limit:r,offset:R,visible:!0,includes:!0,noImage:!1,variant:s,dimension:[],report:g,all:!1};ue.get("/api/cms/search/reports",{params:d}).then(a=>{if(a&&a.data&&a.data.data&&a.data.data.results&&!t){let w=a.data.data.results;Y(w),y(M===""?!1:a.data.data.meta.variantCount);}i(!1);}).catch(a=>{console.error(a),i(!1);});},_=c||e,$={id:void 0,name:W.filters_all||"ALL"},ee=t=>{let R=t.reduce((s,d)=>s.reduce((a,w)=>a.concat(d.map(Be=>[].concat(w,Be))),[])).map(s=>{let d;return Array.isArray(s)?d={id:s.map(a=>a.id).join(","),name:s.map(a=>a.name).join(" / "),members_count:s.reduce((a,w)=>a*(_[w.id]||1),0)}:(s.members_count=_[s.id]||0,d={...s,members_count:_[s.id]||0}),d}),g=R.reduce((s,d)=>s+(d.members_count||0),0);return [{...$,members_count:g},...R]},te=l.length>1,F=useMemo(()=>{let t=[];if(!x&&l.length>0&&_){let R=l.filter(g=>g.dimensions.length>0).map(g=>{let s=!1,d=ee(g.dimensions.map(a=>a.variants));return d&&d.length>2&&(s=!0),{id:g.id,name:g.dimensions.map(a=>a.name).join(" / "),variants:d,members_count:d.filter(a=>a.id).reduce((a,w)=>a+(w.members_count||0),0),show:s}});t=[{...$,members_count:R.reduce((g,s)=>g+(s.members_count||0),0)},...R];}return t},[x,_,l,$]),oe=useMemo(()=>{let t;return F&&(f.profile?f.profile&&(t=F.find(R=>R.id===f.profile),t&&f.variant&&t.variants&&(t=t.variants.find(R=>R.id===f.variant))):t=F.find(R=>!R.id)),t?t.members_count:r},[f,F]),re={metadata:l,loadingMetadata:x,setLoadingMetadata:p,loadingItems:h,setLoadingItems:i,resultCount:c,totalCount:e,setResultCount:Z,activePage:m,setActivePage:C,pageSize:r,filters:f,setFilters:L,doQuery:H,query:M,setQuery:J,debouncedQuery:N,results:Q,currentPageTotal:oe,selectorStructure:F,translations:W,setTranslations:t=>V({...ae,...t}),showSelectors:te,initExplore:O};return jsx(de.Provider,{value:re,children:o})}function qe({translations:o}){let{loadingItems:r,setFilters:n,selectorStructure:l,filters:u,showSelectors:h}=A(),i=e=>{e!==u.profile&&n({profile:e,variant:void 0});},x=e=>{e!==u.variant&&n({...u,variant:e});},p=l.length===2?l[1].id:u.profile,c=p?l.find(e=>e.id===p):void 0,y=c&&c.variants&&u.variant?c.variants.find(e=>e.id===u.variant):void 0;return jsxs(Fragment,{children:[h&&jsx(Group,{position:"center",className:"bespoke-explore-reports-selector",mb:"md",children:l.map(e=>jsxs(Button,{"data-selected":e.id===c?.id?"true":"false","data-report-name":e.name,variant:e.id===c?.id?"outline":"subtle",onClick:()=>i(e.id),children:[o?.dimension[e.name]??e.name,!r&&jsx(Text,{span:!0,size:"xs",ml:"0.2rem",children:`(${e.members_count})`})]},`p-${e.id}`))}),c&&c.variants&&c.variants.length>2&&jsx(Group,{position:"center",style:{minHeight:"36px"},className:"bespoke-explore-variant-selector",mb:"md",children:c.variants.map(e=>jsxs(Button,{"data-selected":e.id===y?.id?"true":"false","data-variant-name":e.name,variant:e.id===y?.id?"outline":"subtle",onClick:()=>x(e.id),children:[o?.dimension[e.name]??e.name,!r&&jsx(Text,{span:!0,size:"xs",ml:"0.2rem",children:`(${e.members_count})`})]},`v-${e.id}`))})]})}var xe=qe;function U(){return useMantineTheme().other.bespokeStyles??{}}var q=()=>{let o=process.env.NEXT_PUBLIC_REPORTS_LOCALE_DEFAULT||"en",r=process.env.NEXT_PUBLIC_REPORTS_LOCALES?.split(",")||[o];return r.includes(o)||r.push(o),{localeDefault:o,locales:r}};function Je({reportName:o,members:r,href:n,onClick:l}){let u=r.map(i=>jsx(Image,{src:i.image.src,height:160,imageProps:{loading:"lazy"},alt:i.name},i.id)),h=r.map(i=>jsxs(Stack,{children:[jsx(Text,{weight:500,children:i.name}),jsx(Badge,{color:"green",variant:"light",w:"fit-content",children:i.variant})]},i.id));return jsxs(Card,{shadow:"sm",p:"lg",radius:"md",withBorder:!0,children:[jsx(Card.Section,{children:jsx(Group,{grow:!0,spacing:0,children:u})}),jsx(Group,{position:"apart",mt:"md",mb:"xs",children:h}),jsx("a",{href:n,onClick:l,children:jsx(Button,{variant:"light",color:"blue",fullWidth:!0,mt:"md",radius:"md",children:`See ${o} Report`})})]})}var Ye=o=>{let{components:r}=U(),n=Je;return r?.ReportTile&&(n=r?.ReportTile),o&&(n=o),n};function Ze({profile:o,profilePrefix:r,onSelect:n,reportTile:l}){let u=useRouter(),h=u.locale,{localeDefault:i}=q(),p=`${h===i?"":`/${h}`}${r}${o.path}`,c=o.members.map(m=>({original_id:m.metadata.id,name:m.name,id:m.id,variant:m.metadata.variant.name,image:{src:`/api/cms/member/image?member=${m.id}&size=thumb`,alt:m.name}})),y=m=>{u.push(`${m}`),n&&n();},e=m=>{m.preventDefault(),y(p);},b=Ye(l);return jsx(Grid.Col,{xs:12,sm:6,md:4,lg:4,xl:3,children:jsx(b,{reportName:o.report.name,members:c,href:p,onClick:e})},o.id)}var Pe=Ze;function nt({profilePrefix:o,onSelect:r=()=>{},reportTile:n}){let[l,u]=useState(500),h=useRef(null),{results:i}=A(),x=h.current?.offsetTop||0,p=50;return useEffect(()=>{let{innerHeight:c}=window;u(c-x-p);},[x]),jsx(ScrollArea,{offsetScrollbars:!0,type:"always",h:l,ref:h,children:jsx(Grid,{align:"stretch",children:i.map(c=>jsx(Pe,{profile:c,profilePrefix:o,reportTile:n,onSelect:r},c.id))})})}var ve=nt;function lt(){let{activePage:o,setActivePage:r,pageSize:n,currentPageTotal:l}=A();return jsx(Group,{position:"center",children:jsx(Pagination,{value:o,onChange:h=>{r(h);},total:Math.ceil(l/n),size:"sm",py:"xs"})})}var Se=lt;function Rt({profilePrefix:o,initialReportId:r,initialVariantId:n,translations:l,onSelect:u,reportTile:h}){let i=useRef(),x=A(),{query:p,setQuery:c,results:y,loadingItems:e,loadingMetadata:b,translations:m,setTranslations:C,initExplore:f}=x;useEffect(()=>{f&&f(r,n);},[f]),useEffect(()=>{e||i.current?.focus();},[e]),useEffect(()=>{l&&C(l);},[l]);let L=()=>{c("");};return jsxs(Container,{fluid:!0,pt:"1em",children:[jsx(TextInput,{placeholder:m.search,mb:"md",size:"xl",onChange:M=>c(M.target.value),readOnly:b||e,icon:jsx(IconSearch,{size:24}),value:p,rightSectionWidth:100,rightSectionProps:{style:{justifyContent:"flex-end",padding:"0 15px 0 0"}},rightSection:jsxs(Group,{align:"center",children:[(b||e)&&jsx(Loader,{size:28}),p!==""&&jsx(ActionIcon,{onClick:L,children:jsx(IconTrash,{size:24})})]}),ref:i}),jsx(xe,{translations:m}),jsx(LoadingOverlay,{visible:b||e}),!e&&y.length===0&&jsx(Alert,{title:m.no_results,color:"blue",children:m.try_another}),jsx(ve,{profilePrefix:o,onSelect:u,reportTile:h}),jsx(Se,{})]})}var le=Rt;var{localeDefault:Et}=q();function It({exploreProps:o={profilePrefix:"/",locale:Et},icon:r=jsx(IconSearch,{size:20}),actionIconProps:n={},modalProps:l={},tooltipProps:u={},tooltipText:h="Click to Explore",showIcon:i=!0,showTooltip:x=!1,children:p}){let[c,y]=useState(!1),e={variant:"light",size:"md",radius:"md",...n},b={fullScreen:!0,opened:c,onClose:()=>y(!1)},m=jsx(ActionIcon,{...e,onClick:()=>y(!0),children:r}),C=i?jsxs(Group,{spacing:"sm",style:{cursor:"pointer"},children:[p,m]}):p;return x&&(C=jsx(Tooltip,{label:h,...u,children:C})),jsxs(Fragment,{children:[jsx(Modal,{...b,...l,children:c&&jsx(le,{...o,onSelect:()=>y(!1)})}),jsx("div",{onClick:()=>y(!0),children:p?C:jsx(Fragment,{children:m})})]})}var kt=It;var wt=forwardRef(({id:o,members:r,profilePrefix:n,reportName:l,reportPath:u,...h},i)=>{let x=r.map(p=>jsxs(Stack,{align:"center",children:[jsx(Text,{weight:500,children:p.name}),jsx(Badge,{color:"green",variant:"light",children:p.variant})]},p.id));return jsx("div",{ref:i,children:jsx(Group,{position:"apart",grow:!0,...h,children:x})},o)}),ke=wt;var Ht=o=>{let{components:r}=U(),n=ke;return r?.ReportItem&&(n=r?.ReportItem),o&&(n=o),n};function Ut({locale:o,profilePrefix:r="/report",autocompleteProps:n={},tooltipProps:l={},tooltipText:u="Click to search",searchReportParams:h={},callback:i,children:x}){let p=useRouter(),c=p.locale,{localeDefault:y}=q(),e=c===y?"":`/${c}`,b=Ht(n?n.itemComponent:null),[m,C]=useState(""),[f,L]=useDebouncedValue(m,500),[M,J]=useState([]),[N,Q]=useState(!1),[Y,W]=useState(!1),[V,B]=useState(!1),[k,G]=useState(!x),X=()=>{G(!1);},Z=()=>{G(!0),$();},O=useRef(),H=useClickOutside(X),_=n?.searchConfig?.searchLimit??10,$=()=>{Q(!0);let g={query:f,format:"profiles",locale:o,limit:_,visible:!0,includes:!0,noImage:!1,variant:[],dimension:[],report:[],all:!1,...h};ue.get("/api/cms/search/reports",{params:g}).then(s=>{s&&s.data&&s.data.data&&s.data.data.results&&J(s.data.data.results.map(d=>({id:d.id,reportName:d.report.name,href:`${e}${r}${d.path}`,reportPath:`${d.path}`,profilePrefix:r,value:`VALUE: ${d.id}`,members:d.members.map(a=>({original_id:a.metadata.id,name:a.name,id:a.id,variant:a.metadata.variant.name,image:{src:`/api/cms/member/image?member=${a.id}&size=thumb`,alt:a.name}}))}))),Q(!1),O.current?.focus();}).catch(s=>{console.error(s),Q(!1);});};useEffect(()=>{V&&f.length>=(n.searchConfig?.queryThreshold??0)&&$();},[V,f,n.searchConfig?.queryThreshold]),useEffect(()=>{L(),O.current&&k&&B(!0);},[]),useEffect(()=>{L(),O.current&&k&&B(!0);},[k]);let ee=g=>{G(!1),i?i(g):(p.push(g.href),W(!0));},te=g=>{g.includes("VALUE:")||C(g);},{searchConfig:F,...oe}=n,re={placeholder:"Search",size:"md",icon:jsx(IconSearch,{}),...oe,data:M},t=jsx(Autocomplete,{value:m,itemComponent:b,onItemSubmit:ee,onChange:te,filter:()=>!0,disabled:(N||Y)&&!V,limit:_,maxDropdownHeight:250,rightSection:jsx(Group,{spacing:0,position:"right",children:N?jsx(Loader,{size:20}):jsx(Fragment,{})}),rightSectionWidth:50,ref:O,...re});return x?jsx(Tooltip,{label:u,disabled:k,...l,children:jsxs(Group,{ref:H,spacing:"sm",align:"center",style:{cursor:"pointer"},children:[!k&&jsx("div",{onClick:()=>G(!0),children:x}),k&&jsx(Fragment,{children:t}),k?jsx(ActionIcon,{variant:"light",onClick:X,children:jsx(IconX,{size:20})}):jsx(ActionIcon,{variant:"light",onClick:Z,children:jsx(IconSearch,{size:20})})]})}):t}var Wt=Ut;
|
|
10
|
+
var ne={try_another:"Try another search or filter.",search:"Search",filters_all:"All",no_results:"No Results",load_more:"Load more",select_report:"Select Report",select_variant:"Select Variant",count_format:".2s",report:{},dimension:{},variant:{}},fe=createContext({metadata:[],loadingItems:!1,setLoadingItems:()=>null,loadingMetadata:!1,setLoadingMetadata:()=>null,resultCount:{},totalCount:{},setResultCount:()=>null,activePage:1,setActivePage:()=>null,pageSize:10,results:[],filters:{},doQuery:()=>null,setFilters:()=>null,query:"",setQuery:()=>null,debouncedQuery:"",currentPageTotal:10,selectorStructure:[],translations:ne,setTranslations:()=>null,showSelectors:!0}),L=()=>useContext(fe);function Ve({children:t,pageSize:n=10}){let i={profile:void 0,variant:void 0},[s,d]=useState([]),[y,p]=useState(!1),[b,m]=useState(!1),[h,o]=useState({}),[x,v]=useState({}),[u,e]=useState(1),[c,_]=useState(i),[B,G]=useState(""),[$]=useDebouncedValue(B,750),[H,Y]=useState([]),[K,U]=useState(ne),[z,A]=useState(!1),{locale:O}=useRouter(),Z=async()=>{try{m(!0),de.get("/api/cms/read/metadata").then(r=>{if(r&&r.data&&r.data.data&&r.data.data.data){let R=r.data.data.data.reduce((f,l)=>(l.dimensions&&l.dimensions.forEach(g=>{g.variants&&g.variants.forEach(a=>{f[a.id]=a.members_count||0;});}),f),{});d(r.data.data.data),o(R),v(R);}m(!1),A(!0);}).catch(r=>{console.error(r);});}catch(r){console.error("Error fetching metadata:",r),d([]),m(!1),o({}),v({});}},ee=r=>{o(r||x);},F=useCallback(async(r,R,f)=>{!z&&s.length===0&&await Z(),_({profile:r,variant:R}),f!==""&&G(f);},[]);useEffect(()=>{let r=!1;return z&&(p(!0),e(1),X(r,0)),()=>{r=!1;}},[$,c,z]),useEffect(()=>{if(z){p(!0);let r=(u-1)*n;X(!1,r);}},[u]);let X=async(r,R)=>{let f=c.profile&&!Number.isNaN(c.profile)?[c.profile]:[],l=c.variant?typeof c.variant=="string"&&c.variant.includes(",")?c.variant.split(",").map(a=>parseInt(a,10)):[parseInt(c.variant,10)]:[],g={query:$,format:"profiles",locale:O,limit:n,offset:R,visible:!0,includes:!0,noImage:!1,variant:l,dimension:[],report:f,all:!1,origin:"typesense"};de.get("/api/cms/search/reports",{params:g}).then(a=>{if(a&&a.data&&a.data.data&&a.data.data.results&&!r){let M=a.data.data.results;Y(M),o(!B||B===""?!1:a.data.data.meta.variantCount);}p(!1);}).catch(a=>{console.error(a),p(!1);});},w=h||x,D={id:void 0,name:K.filters_all||"ALL"},te=r=>{let R=r.reduce((l,g)=>l.reduce((a,M)=>a.concat(g.map($e=>[].concat(M,$e))),[])).map(l=>{let g;return Array.isArray(l)?g={id:l.map(a=>a.id).join(","),name:l.map(a=>a.name).join(" / "),members_count:l.reduce((a,M)=>a*(w[M.id]||1),1),ordering:l.reduce((a,M)=>a+M.ordering,0)}:(l.members_count=w[l.id]||0,g={...l,members_count:w[l.id]||0}),g}),f=R.reduce((l,g)=>l+(g.members_count||0),0);return [{...D,members_count:f},...R]},re=s.length>1,Q=useMemo(()=>{let r=[];if(!b&&s.length>0&&w){let R=s.filter(f=>f.dimensions.length>0).map(f=>{let l=!1,g=te(f.dimensions.map(a=>a.variants));return g&&g.length>2&&(l=!0),{id:f.id,name:f.dimensions.map(a=>a.name).join(" / "),variants:g,members_count:g.filter(a=>a.id).reduce((a,M)=>a+(M.members_count||0),0),show:l}});r=[{...D,members_count:R.reduce((f,l)=>f+(l.members_count||0),0)},...R];}return r},[b,w,s,D]),oe=useMemo(()=>{let r;return Q&&(c.profile?c.profile&&(r=Q.find(R=>R.id===c.profile),r&&c.variant&&r.variants&&(r=r.variants.find(R=>R.id===c.variant))):r=Q.find(R=>!R.id)),r?r.members_count:n},[c,Q]),ae={metadata:s,loadingMetadata:b,setLoadingMetadata:m,loadingItems:y,setLoadingItems:p,resultCount:h,totalCount:x,setResultCount:ee,activePage:u,setActivePage:e,pageSize:n,filters:c,setFilters:_,doQuery:X,query:B,setQuery:G,debouncedQuery:$,results:H,currentPageTotal:oe,selectorStructure:Q,translations:K,setTranslations:r=>U({...ne,...r}),showSelectors:re,initExplore:F};return jsx(fe.Provider,{value:ae,children:t})}function Xe({translations:t}){let{loadingItems:n,setFilters:i,selectorStructure:s,filters:d,showSelectors:y}=L(),p=e=>{let c=e===null||Number.isNaN(e)?void 0:parseInt(e,10);c!==d.profile?i({profile:c,variant:void 0}):c&&i({profile:void 0,variant:void 0});},b=e=>{let c=e===null?void 0:typeof e=="string"&&e.includes(",")?e:parseInt(e,10);c!==d.variant?i({...d,variant:c}):c&&i({...d,variant:void 0});},m=e=>e<1e3?e:format(t.count_format)(e).replace(/\.0+([a-zA-Z]*)$/,"$1"),h=s.length===2?s[1].id:d.profile,o=h?s.find(e=>e.id===h):void 0,x=o&&o.variants&&d.variant?o.variants.find(e=>e.id===d.variant):void 0,v=useMemo(()=>s.map(e=>({value:String(e.id||""),label:t?.dimension[e.name]??e.name+(!n&&(!o||e.id===o?.id)?` (${m(e.members_count)})`:"")})),[t,o,s]),u=useMemo(()=>o?.variants?.map(e=>({value:String(e.id||""),label:t?.dimension[e.name]??e.name+(!n&&(!x||e.id===x?.id)?` (${m(e.members_count)})`:"")}))??[],[t,x,s]);return jsx(Fragment,{children:y&&jsxs(Fragment,{children:[jsx(MediaQuery,{largerThan:1e3,styles:{display:"none"},children:jsxs(Group,{className:"bespoke-explore-reports-select-container",position:"center",mb:"md",children:[jsx(Select,{className:"bespoke-explore-reports-select",data:v,value:String(o?.id||""),onChange:e=>p(e),label:t.select_report||"Select Report",placeholder:t.select_report||"Select Report",clearable:typeof o?.id<"u",style:{width:"450px"}}),o?.variants&&o.variants.length>2&&jsx(Select,{className:"bespoke-explore-variant-select",data:u,value:String(x?.id||""),onChange:e=>b(e),label:t.select_variant||"Select Variant",placeholder:t.select_variant||"Select Variant",clearable:typeof x?.id<"u",style:{width:"450px"}})]})}),jsx(MediaQuery,{smallerThan:1e3,styles:{display:"none"},children:jsxs("div",{children:[jsx(Group,{position:"center",className:"bespoke-explore-reports-selector",mb:"md",children:s.map(e=>jsxs(Button,{"data-selected":e.id===o?.id?"true":"false","data-report-name":e.name,variant:e.id===o?.id?"outline":"subtle",onClick:()=>p(e.id),rightIcon:e.id&&e.id===o?.id?jsx(IconX,{size:"1rem"}):void 0,children:[t?.dimension[e.name]??e.name,!n&&(!o||e.id===o?.id)&&jsx(Text,{span:!0,size:"xs",ml:"0.2rem",children:`(${m(e.members_count)})`})]},`p-${e.id}`))}),o&&o.variants&&o.variants.length>2&&jsx(Group,{position:"center",style:{minHeight:"36px"},className:"bespoke-explore-variant-selector",mb:"md",children:o.variants.map(e=>jsxs(Button,{"data-selected":e.id===x?.id?"true":"false","data-variant-name":e.name,variant:e.id===x?.id?"outline":"subtle",onClick:()=>b(e.id),rightIcon:e.id&&e.id===x?.id?jsx(IconX,{size:"1rem"}):void 0,children:[t?.dimension[e.name]??e.name,!n&&(!x||e.id===x?.id)&&jsx(Text,{span:!0,size:"xs",ml:"0.2rem",children:`(${m(e.members_count)})`})]},`v-${e.id}`))})]})})]})})}var Pe=Xe;function j(){return useMantineTheme().other.bespokeStyles??{}}var q=()=>{let t=process.env.NEXT_PUBLIC_REPORTS_LOCALE_DEFAULT||"en",n=process.env.NEXT_PUBLIC_REPORTS_LOCALES?.split(",")||[t];return n.includes(t)||n.push(t),{localeDefault:t,locales:n}};function rt({reportName:t,members:n,href:i,onClick:s}){let d=n.map(p=>jsx(Image,{src:p.image.src,height:160,imageProps:{loading:"lazy"},alt:p.name},p.id)),y=n.map(p=>jsxs(Stack,{children:[jsx(Text,{weight:500,children:p.name}),jsx(Badge,{color:"green",variant:"light",w:"fit-content",children:p.variant})]},p.id));return jsxs(Card,{shadow:"sm",p:"lg",radius:"md",withBorder:!0,children:[jsx(Card.Section,{children:jsx(Group,{grow:!0,spacing:0,children:d})}),jsx(Group,{position:"apart",mt:"md",mb:"xs",children:y}),jsx("a",{href:i,onClick:s,children:jsx(Button,{variant:"light",color:"blue",fullWidth:!0,mt:"md",radius:"md",children:`See ${t} Report`})})]})}var ot=t=>{let{components:n}=j(),i=rt;return n?.ReportTile&&(i=n?.ReportTile),t&&(i=t),i};function at({profile:t,profilePrefix:n,onSelect:i,reportTile:s}){let d=useRouter(),y=d.locale,{localeDefault:p}=q(),m=`${y===p?"":`/${y}`}${n}${t.path}`,h=t.members.map(u=>({original_id:u.metadata.id,name:u.name,id:u.id,variant:u.metadata.variant.name,image:{src:`/api/cms/member/image?member=${u.id}&size=thumb`,alt:u.name}})),o=u=>{d.push(`${u}`),i&&i();},x=u=>{u.preventDefault(),o(m);},v=ot(s);return jsx(Grid.Col,{xs:12,sm:6,md:4,lg:4,xl:3,children:jsx(v,{reportName:t.report.name,members:h,href:m,onClick:x})},t.id)}var Ee=at;function pt({profilePrefix:t,onSelect:n=()=>{},reportTile:i}){let[s,d]=useState(500),y=useRef(null),{results:p}=L(),b=y.current?.offsetTop||0,m=50;return useEffect(()=>{let{innerHeight:h}=window;d(h-b-m);},[b]),jsx(ScrollArea,{offsetScrollbars:!0,type:"always",h:s,ref:y,children:jsx(Grid,{align:"stretch",children:p.map(h=>jsx(Ee,{profile:h,profilePrefix:t,reportTile:i,onSelect:n},h.id))})})}var Ie=pt;function dt(){let{activePage:t,setActivePage:n,pageSize:i,currentPageTotal:s}=L();return jsx(Group,{position:"center",children:jsx(Pagination,{value:t,onChange:y=>{n(y);},total:Math.ceil(s/i),size:"sm",py:"xs"})})}var _e=dt;function Tt({profilePrefix:t,initialReportId:n,initialVariantId:i,translations:s,onSelect:d,reportTile:y,initialQuery:p}){let b=useRef(),m=L(),{query:h,setQuery:o,results:x,loadingItems:v,loadingMetadata:u,translations:e,setTranslations:c,initExplore:_}=m;useEffect(()=>{_&&_(n,i,p);},[_]),useEffect(()=>{v||b.current?.focus();},[v]),useEffect(()=>{s&&c(s);},[s]);let B=()=>{o("");};return jsxs(Container,{fluid:!0,pt:"1em",children:[jsx(TextInput,{placeholder:e.search,mb:"md",size:"xl",onChange:G=>o(G.target.value),readOnly:u||v,icon:jsx(IconSearch,{size:24}),value:h,rightSectionWidth:100,rightSectionProps:{style:{justifyContent:"flex-end",padding:"0 15px 0 0"}},rightSection:jsxs(Group,{align:"center",children:[(u||v)&&jsx(Loader,{size:28}),h&&h!==""&&jsx(ActionIcon,{onClick:B,children:jsx(IconTrash,{size:24})})]}),ref:b}),jsx(Pe,{translations:e}),jsx(LoadingOverlay,{visible:u||v}),!v&&x.length===0&&jsx(Alert,{title:e.no_results,color:"blue",children:e.try_another}),jsx(Ie,{profilePrefix:t,onSelect:d,reportTile:y}),jsx(_e,{})]})}var ce=Tt;var{localeDefault:Mt}=q();function Lt({exploreProps:t={profilePrefix:"/",locale:Mt},icon:n=jsx(IconSearch,{size:20}),actionIconProps:i={},modalProps:s={},tooltipProps:d={},tooltipText:y="Click to Explore",showIcon:p=!0,showTooltip:b=!1,children:m}){let[h,o]=useState(!1),x={variant:"light",size:"md",radius:"md",...i},v={fullScreen:!0,opened:h,onClose:()=>o(!1)},u=jsx(ActionIcon,{...x,onClick:()=>o(!0),children:n}),e=p?jsxs(Group,{spacing:"sm",style:{cursor:"pointer"},children:[m,u]}):m;return b&&(e=jsx(Tooltip,{label:y,...d,children:e})),jsxs(Fragment,{children:[jsx(Modal,{...v,...s,children:h&&jsx(ce,{...t,onSelect:()=>o(!1)})}),jsx("div",{onClick:()=>o(!0),children:m?e:jsx(Fragment,{children:u})})]})}var Bt=Lt;var Ot=forwardRef(({id:t,members:n,profilePrefix:i,reportName:s,reportPath:d,...y},p)=>{let b=n.map(m=>jsxs(Stack,{align:"center",children:[jsx(Text,{weight:500,children:m.name}),jsx(Badge,{color:"green",variant:"light",children:m.variant})]},m.id));return jsx("div",{ref:p,children:jsx(Group,{position:"apart",grow:!0,...y,children:b})},t)}),Be=Ot;var Kt=t=>{let{components:n}=j(),i=Be;return n?.ReportItem&&(i=n?.ReportItem),t&&(i=t),i};function Zt({locale:t,profilePrefix:n="/report",autocompleteProps:i={},tooltipProps:s={},tooltipText:d="Click to search",searchReportParams:y={},callback:p,children:b}){let m=useRouter(),h=m.locale,{localeDefault:o}=q(),x=h===o?"":`/${h}`,v=Kt(i?i.itemComponent:null),[u,e]=useState(""),[c,_]=useDebouncedValue(u,500),[B,G]=useState([]),[$,H]=useState(!1),[Y,K]=useState(!1),[U,z]=useState(!1),[A,O]=useState(!b),Z=()=>{O(!1);},ee=()=>{O(!0),D();},F=useRef(),X=useClickOutside(Z),w=i?.searchConfig?.searchLimit??10,D=()=>{H(!0);let f={query:c,format:"profiles",locale:t,limit:w,visible:!0,includes:!0,noImage:!1,variant:[],dimension:[],report:[],all:!1,...y};de.get("/api/cms/search/reports",{params:f}).then(l=>{l&&l.data&&l.data.data&&l.data.data.results&&G(l.data.data.results.map(g=>({id:g.id,reportName:g.report.name,href:`${x}${n}${g.path}`,reportPath:`${g.path}`,profilePrefix:n,value:`VALUE: ${g.id}`,members:g.members.map(a=>({original_id:a.metadata.id,name:a.name,id:a.id,variant:a.metadata.variant.name,image:{src:`/api/cms/member/image?member=${a.id}&size=thumb`,alt:a.name}}))}))),H(!1),F.current?.focus();}).catch(l=>{console.error(l),H(!1);});};useEffect(()=>{U&&c.length>=(i.searchConfig?.queryThreshold??0)&&D();},[U,c,i.searchConfig?.queryThreshold]),useEffect(()=>{_(),F.current&&A&&z(!0);},[]),useEffect(()=>{_(),F.current&&A&&z(!0);},[A]);let te=f=>{O(!1),p?p(f):(m.push(f.href),K(!0));},re=f=>{f.includes("VALUE:")||e(f);},{searchConfig:Q,...oe}=i,ae={placeholder:"Search",size:"md",icon:jsx(IconSearch,{}),...oe,data:B},r=jsx(Autocomplete,{value:u,itemComponent:v,onItemSubmit:te,onChange:re,filter:()=>!0,disabled:($||Y)&&!U,limit:w,maxDropdownHeight:250,rightSection:jsx(Group,{spacing:0,position:"right",children:$?jsx(Loader,{size:20}):jsx(Fragment,{})}),rightSectionWidth:50,ref:F,...ae});return b?jsx(Tooltip,{label:d,disabled:A,...s,children:jsxs(Group,{ref:X,spacing:"sm",align:"center",style:{cursor:"pointer"},children:[!A&&jsx("div",{onClick:()=>O(!0),children:b}),A&&jsx(Fragment,{children:r}),A?jsx(ActionIcon,{variant:"light",onClick:Z,children:jsx(IconX,{size:20})}):jsx(ActionIcon,{variant:"light",onClick:ee,children:jsx(IconSearch,{size:20})})]})}):r}var Jt=Zt;
|
|
10
11
|
|
|
11
|
-
export {
|
|
12
|
+
export { ce as BespokeExplore, Bt as BespokeExploreModal, Ve as BespokeExploreProvider, Jt as BespokeSearch, L as useBespokeExplore };
|
package/dist/redux-store.js
CHANGED
|
@@ -23,9 +23,9 @@ import 'react/jsx-runtime';
|
|
|
23
23
|
import '@mantine/core';
|
|
24
24
|
|
|
25
25
|
var Hr=Object.defineProperty;var Kr=(e,t)=>{for(var r in t)Hr(e,r,{get:t[r],enumerable:!0});};function Y(e,t){return e.request(t).then(r=>{let{status:o,data:n}=r;return "error"in n?{ok:!1,status:o,error:n.error}:{ok:!0,status:o,data:n.data}},r=>{if("isAxiosError"in r){let{status:o,data:n}=r.response||{status:500};return {ok:!1,status:o,error:n?.error??r.message}}return {ok:!1,status:500,error:r.message}})}function F(e,t,r){let o=typeof t=="string"?{url:t}:t;return n=>Y(e,{...o,method:"GET",params:r?r(n):n})}function $(e,t,r){let o=typeof t=="string"?{url:t}:t;return n=>Y(e,{...o,method:"POST",data:r?r(n):n})}function ne(e,t,r){let o=typeof t=="string"?{url:t}:t;return n=>Y(e,{...o,method:"DELETE",params:r?r(n):n})}function Re(e,t){return r=>Y(e,{method:"POST",url:`images/save/${t}`,params:{prompt:r.prompt,provider:t}})}function Le(e,t){return r=>Y(e,{method:"GET",url:`images/search/${t}`,params:{prompt:r.prompt,page:r.page,provider:t}})}function Mt(e,t){return ()=>Y(e,{method:"GET",url:`list/icons/${t}`,params:{provider:t}})}function Dt(e,t){return r=>Y(e,{method:"GET",url:`read/icons/${t}/icon.svg`,params:{name:r.name}})}var ge=e=>({id:e}),Wr=e=>{if(e.mode==="slugs"){let t=e.slugs.map(r=>[r.variantSlug,r.memberSlug].join("/")).join(",");return {...e,slugs:t}}return ["related","whole"].includes(e.mode)?{...e}:{...e,[e.mode]:e[e.mode].join(",")}};function _e(e){let t=We.create({baseURL:e});return {createBulkBlock:$(t,"create/bulk/block"),createBlock:$(t,"create/block"),createDimension:$(t,"create/dimension"),createFormatter:$(t,"create/formatter"),createReport:$(t,"create/report"),createSection:$(t,"create/section"),createVariant:$(t,"create/variant"),deleteBlock:ne(t,"delete/block",ge),deleteDimension:ne(t,"delete/dimension",ge),deleteFormatter:ne(t,"delete/formatter",ge),deleteReport:ne(t,"delete/report",ge),deleteSection:ne(t,"delete/section",ge),deleteVariant:ne(t,"delete/variant",ge),readBlock:F(t,"read/block"),readDimension:F(t,"read/dimension"),readFormatter:F(t,"read/formatter"),readReport:F(t,"read/report"),readSection:F(t,"read/section"),readVariant:F(t,"read/variant"),updateBulkBlock:$(t,"update/bulk/block"),updateBlock:$(t,"update/block"),updateDimension:$(t,"update/dimension"),updateFormatter:$(t,"update/formatter"),updateReport:$(t,"update/report"),updateSection:$(t,"update/section"),updateVariant:$(t,"update/variant"),searchReport:F(t,"search/reports"),validateVariantSlug:F(t,"validate/variant"),readMember:F(t,"read/members",Wr),readMemberImage:F(t,{url:"member/image",responseType:"blob"}),searchMember:F(t,"search/members"),updateMember:F(t,"update/members"),imageLocalSearch:Le(t,"local"),imageLocalSave:Re(t,"local"),imageFlickrSearch:Le(t,"flickr"),imageFlickrSave:Re(t,"flickr"),imageUnsplashSearch:Le(t,"unsplash"),imageUnsplashSave:Re(t,"unsplash"),imageUploadSave:Re(t,"upload"),imageAdobeSearch:Le(t,"adobe"),imageAdobeSave:Re(t,"adobe"),readMetadata:F(t,"read/metadata"),regenerateSearch:$(t,"search/regenerate"),urlProxy:F(t,"url/proxy"),searchRole:F(t,"auth/search/roles"),searchUser:F(t,"auth/search/users"),readUser:F(t,"auth/read/user"),updateUser:$(t,"auth/update/user"),updateMyData:$(t,"auth/update/me"),revalidateReport:F(t,"revalidate/report"),revalidateUrl:F(t,"revalidate/url"),readPrivateBlocks:$(t,"read/blocks/private"),listTablerIcons:Mt(t,"tabler"),readTablerIcon:Dt(t,"tabler")}}function Qr(e,t){return +(e<t)-+(e>t)}function Ue(e,t,r="ordering"){return Qr(t[r],e[r])}function nt(e){let t=1+76.18009173/e-86.50532033/(e+1)+24.01409822/(e+2)-1.231739516/(e+3)+.00120858003/(e+4)-536382e-11/(e+5);return (e-.5)*Math.log(e+4.5)-(e+4.5)+Math.log(t*2.50662827465)}function Ut(e,t,r){let o=0,n=1,s=1,i=1,a=0,c=0,l;for(;Math.abs((s-c)/s)>1e-5;)c=s,l=-(t+a)*(t+r+a)*e/(t+2*a)/(t+2*a+1),o=s+l*o,n=i+l*n,a+=1,l=a*(r-a)*e/(t+2*a-1)/(t+2*a),s=o+l*s,i=n+l*i,o/=i,n/=i,s/=i,i=1;return s/t}function Zr(e,t,r){let o,n;if(e<0)n=0;else if(e>=t)n=1;else {e=Math.floor(e);let s=r,i=e+1,a=t-e,c=i+a,l=Math.exp(nt(c)-nt(a)-nt(i)+i*Math.log(s)+a*Math.log(1-s));s<(i+1)/(c+2)?o=l*Ut(s,i,a):o=1-l*Ut(1-s,a,i),n=1-o;}return Math.round(n*1e5)/1e5}function Jr(e){return {.99999:15.137,.99:6.635,.95:3.841,.9:2.706}[e]}function Oe(e,t,r,o){let n=t/(1-t),s=0,i=1,a=0,c=0;for(;s<=e;)c+=i,s>=r&s<=o&&(a+=i),c>1e30&&(a/=1e30,c/=1e30,i/=1e30),s+=1,i=i*n*(e+1-s)/s;return a/c}function Xr(e,t,r){let o=e/t,s=(100-r*100)/2,i,a;if(e===0)i=0;else {let c=o/2,l=0,p=o,u=s/100;for(;p-l>1e-5;)Oe(t,c,e,e)*.5+Oe(t,c,e+1,t)>u?(p=c,c=(l+c)/2):(l=c,c=(p+c)/2);i=c;}if(e===t)a=0;else {let c=(1+o)/2,l=o,p=1,u=s/100;for(;p-l>1e-5;)Oe(t,c,e,e)*.5+Oe(t,c,0,e-1)<u?(p=c,c=(l+c)/2):(l=c,c=(p+c)/2);a=c;}return {lci:i,uci:a}}function eo(e,t){let r=e,o=t,n=r,s=o,i=95,a=.5,c=.5,p=(100-i)/2/100,u=n;for(;c>1e-5;)c/=2,Fe((1+u)*a/(1-a),u+1,1e10)+.5*Fe((1+u)*a/(1-a),u,u)>p?a-=c:a+=c;let d=(1+u)*a/(1-a)/s;for(a=.5,c=.5,p=(100-i)/2/100;c>1e-5;)c/=2,Fe((1+u)*a/(1-a),0,u-1)+.5*Fe((1+u)*a/(1-a),u,u)<p?a-=c:a+=c;let h=(1+u)*a/(1-a)/s;return {lci:d,uci:h}}function Fe(e,t,r){let o=1,n=0,s=0,i=0;for(;i<e||o>n*1e-10;)n+=o,i>=t&i<=r&&(s+=o),n>1e30&&(s/=1e30,n/=1e30,o/=1e30),i+=1,o=o*e/i;return s/n}var Ft={binomialCdf:Zr,binP:Oe,computeMidP:Xr,criticalValue:Jr,smr:eo};var he={d3:{...to,...ro,...oo,...no},d3plus:{assign:assign,closest:closest,date:date,formatAbbreviate:formatAbbreviate,merge:merge,strip:strip,titleCase:titleCase},stats:Ft};var Z=()=>{let e=process.env.NEXT_PUBLIC_REPORTS_LOCALE_DEFAULT||"en",t=process.env.NEXT_PUBLIC_REPORTS_LOCALES?.split(",")||[e];return t.includes(e)||t.push(e),{localeDefault:e,locales:t}};Z();var Ie=new schema.Entity("block",{},{mergeStrategy(e,t){return t.block_input?e||{}:{...e,...t}}});Ie.define({consumers:[Ie],inputs:[Ie]});var qt=new schema.Entity("variant"),$t=new schema.Entity("dimension",{variants:[qt]},{processStrategy(e){return {...e,variants:"variants"in e?e.variants:[]}}}),Vt=new schema.Entity("section",{blocks:[Ie]}),mo=new schema.Entity("report",{dimensions:[$t],sections:[Vt]},{processStrategy(e){return {...e,sections:"sections"in e?e.sections.sort(Ue):[]}}}),yo=new schema.Entity("formatter"),Ro={report:mo,section:Vt,block:Ie,dimension:$t,variant:qt,formatter:yo};function qe(e,t){let r=Ro[e];if(!r)throw new Error(`Invalid entity type: ${e}`);let{entities:o}=normalize(t,[r]);return {report:Ee(o,"report"),dimension:Ee(o,"dimension"),section:Ee(o,"section"),block:Ee(o,"block"),variant:Ee(o,"variant"),formatter:Ee(o,"formatter")}}function Ee(e,t){return e.hasOwnProperty(t)?e[t]:{}}var jt=(e,t=void 0)=>{let{sid:r,bid:o,previews:n=[],query:s={}}=t||{},i,a,c={};return r?(i=r,c.activeSection=i):i=e.activeSection,n.length>0?(a=n,c.previews=a.filter(Boolean)):a=e.previews,{parsedParams:{sid:i,bid:o,previews:a,query:s},statusPayload:c}};var Eo={tree:[],reports:null,entities:{block:{},dimension:{},report:{},section:{},variant:{},formatter:{}},requests:{block:{},dimension:{},report:{},section:{},variant:{},formatter:{}}},oe=createSlice({name:"records",initialState:Eo,reducers:{set:(e,t)=>{let r=t.payload;return {entities:Be(e.entities,r.entities||{}),requests:Be(e.requests,r.requests||{}),reports:r.reports||e.reports,tree:r.tree||e.tree}},setRequest:(e,t)=>{let r=t.payload;e.requests[r.type][r.key]=r;},setCreateRequest(e,t){let r=t.payload;if(e.requests[r.type][r.key]=r,r.status==="SUCCESS"){let o=Array.isArray(r.data)?r.data:[r.data],n=qe(r.type,o),s=Be(e.entities,n);if(e.entities=s,r.type==="report"){let i=r.data;e.reports?e.reports.indexOf(i.id)===-1&&(e.reports=[...e.reports,i.id]):e.reports=[i.id];}else if(r.type==="dimension"){let i=r.data;e.entities.report[i.report_id].dimensions.push(i.id),e.entities.report[i.report_id].dimensions=$e(s.report[i.report_id].dimensions,s.dimension);}else if(r.type==="variant"){let i=r.data;e.entities.dimension[i.dimension_id].variants.push(i.id);}else if(r.type==="section"&&!Array.isArray(r.data)){let i=r.data;e.entities.report[i.report_id].sections.push(i.id),e.entities.report[i.report_id].sections=$e(s.report[i.report_id].sections,s.section);}else if(r.type==="block")if(Array.isArray(r.data)){let i=r.data,a=i[0],c=i.map(l=>l.id);e.entities.section[a.section_id].blocks.concat(c);}else {let i=r.data;e.entities.section[i.section_id].blocks.push(i.id);}}},setReadRequest(e,t){let r=t.payload;if(r.type!=="report"&&(e.requests[r.type][r.key]=r),r.status==="SUCCESS"){let o=qe(r.type,r.data),n=Be(e.entities,o);e.entities=n;}},setUpdateRequest(e,t){let r=t.payload;if(e.requests[r.type][r.key]=r,r.status==="SUCCESS"){let o=Array.isArray(r.data)?r.data:[r.data],n=qe(r.type,o),s,i,a;if(r.type==="block"&&!Array.isArray(r.data)){let l=e.entities.block[r.data.id].inputs,p=n.block[r.data.id].inputs;s=l.length!==p.length,s&&(a=l.length>p.length,i=a?l.filter(u=>!p.includes(u))[0]:p.filter(u=>!l.includes(u))[0]),Object.values(n.block).forEach(u=>{u.block_input&&delete n.block[u.id];});}let c=Be(e.entities,n);if(e.entities=c,r.type==="dimension"){let l=r.data;e.entities.report[l.report_id].dimensions=$e(c.report[l.report_id].dimensions,c.dimension);}else if(r.type==="section"&&!Array.isArray(r.data)){let l=r.data;e.entities.report[l.report_id].sections=$e(c.report[l.report_id].sections,c.section);}else if(r.type==="block"&&!Array.isArray(r.data)){let l=r.data;s&&(a?e.entities.block[i].consumers=e.entities.block[i].consumers.filter(p=>p!==l.id):e.entities.block[i].consumers.push(l.id));}}},setDeleteRequest(e,t){let r=t.payload;if(e.requests[r.type][r.key]=r,r.status==="SUCCESS"){let{id:o,parentId:n,parentType:s}=r.data;if(delete e.entities[r.type][o],s&&n!=null){let i=`${r.type}s`;To(e.entities[s][n][i],o);}}},removeBlocks:(e,t)=>{let r=t.payload,o={...e.entities.block};return r.forEach(n=>{delete o[n];}),{...e,entities:{...e.entities,block:o}}},addBlocks:(e,t)=>{let r=t.payload;return {...e,entities:{...e.entities,block:{...e.entities.block,...r}}}}},extraReducers:{[HYDRATE]:(e,t)=>{let r=t.payload.records,o=r.entities;return {entities:o,reports:Object.values(o.report).map(n=>n.id),requests:{block:{},dimension:{},report:{},section:{},variant:{},formatter:{}},tree:r.tree}}}});function Be(e,t){return Object.fromEntries(Object.keys(e).map(r=>[r,{...e[r],...t[r]}]))}function $e(e,t){return e.map(n=>t[n]).sort(Ue).map(n=>n.id)}function To(e,t){let r=e.indexOf(t);r>-1&&e.splice(r,1);}var se=process.env.NEXT_PUBLIC_REPORTS_LOCALE_DEFAULT||"en",Ve=process.env.NEXT_PUBLIC_REPORTS_LOCALES?.split(",")||[se];Ve.includes(se)||Ve.push(se);var Ao={localeDefault:se,locales:Ve,currentLocale:se,preferredLocale:se,showToolbar:!1,activeSection:null,previews:[],query:{},sectionState:{},activeEntity:{type:null,id:null},sidebarStatus:{tools:!0,settings:!1,reportEditor:!1},isCMS:!1},je=createSlice({name:"status",initialState:Ao,reducers:{setStatus:(e,t)=>{Object.assign(e,t.payload);},setPreviews(e,t){e.previews=t.payload;},setCurrentLocale(e,t){e.currentLocale=t.payload;},setPreferredLocale(e,t){e.preferredLocale=t.payload;},setSectionState(e,t){e.sectionState={...e.sectionState,...t.payload};},resetSectionState(e,t){e.sectionState={...e.sectionState,[t.payload]:{}};},setActiveEntity(e,t){e.activeEntity=t.payload;},openSidebar(e,t){e.sidebarStatus={...e.sidebarStatus,[t.payload]:!0};},closeSidebar(e,t){e.sidebarStatus={...e.sidebarStatus,[t.payload]:!1};},toggleSidebar(e,t){e.sidebarStatus={...e.sidebarStatus,[t.payload]:!e.sidebarStatus[t.payload]};}},extraReducers:{[HYDRATE]:(e,t)=>({...e,previews:t.payload.status.previews})}}),ze=je.actions;var xo={attributes:{},variables:{},status:{}},Ge=createSlice({name:"variables",initialState:xo,reducers:{setVariableChange:(e,t)=>{e.attributes={...e.attributes,...t.payload.attributes},e.variables={...e.variables,...t.payload.variables},e.status={...e.status,...t.payload.status};}},extraReducers:{[HYDRATE]:(e,t)=>({attributes:{...e.attributes,...t.payload.variables.attributes},status:{...e.status,...t.payload.variables.status},variables:{...e.variables,...t.payload.variables.variables}})}}),zt=Ge.actions;var Gt=e=>configureStore({reducer:{[oe.name]:oe.reducer,[je.name]:je.reducer,[Ge.name]:Ge.reducer},middleware(t){return t({thunk:{extraArgument:_e("/api/cms/")}})}}),Ht=createWrapper(Gt);var et={};Kr(et,{addBlockToState:()=>jn,cloneEntity:()=>Pr,createEntity:()=>kr,deleteEntity:()=>Cr,deleteQueryParam:()=>Bn,readEntity:()=>Me,readMember:()=>Nr,readMetadata:()=>Nn,readPrivateBlocks:()=>zn,readUser:()=>Fn,recalculateVariables:()=>Dr,removeBlocksFromState:()=>Vn,reportSearch:()=>_n,resetSectionState:()=>wr,revalidateReport:()=>Hn,revalidateUrl:()=>Gn,searchMember:()=>In,searchRegenerate:()=>On,searchRole:()=>Dn,searchUser:()=>Un,setCurrentLocale:()=>Cn,setPreferredLocale:()=>Pn,setPreviews:()=>xn,setQueryParam:()=>wn,setSectionState:()=>Br,setStatus:()=>Ir,updateEntity:()=>xr,updateMyData:()=>$n,updateUser:()=>qn,urlProxy:()=>Mn,variantValidateSlug:()=>Ln});var{localeDefault:Oo}=Z();function K(e){return {variables:e.variables||{},query:e.query||{},locale:e.locale||Oo}}var ie={SINGLE:"single",MULTI:"multi"};var wo={IMAGE:"image",PARAGRAPH:"paragraph",SELECTOR:"selector",STAT:"stat",SUBTITLE:"subtitle",TITLE:"title",NAV:"nav",RESET_BUTTON:"reset_button",COMPARISON_BUTTON:"comparison_button",TABLE:"table",BUTTON:"button",MULTIHIERARCHY_SELECTOR:"multihierarchy_selector",FALLBACK:"fallback"},at={GENERATOR:"generator",RELATED:"related",VIZ:"visualization",SECTION_FLAG:"section_flag"},it="logic",E={...wo,...at};var Uo=Mo(process.env.REPORTS_LOGGING),ce=Fo;function Fo(e,t,r,o,n=void 0,s){let i={},a=[],{locale:c}=K(s);try{if(t){let l=new Proxy(console,{get(u,d){return qo(d,"log","debug","info","warn","error")?(...S)=>{a.push(`${d} ${Date.now()} - ${S.map(h=>format(h)).join(" ")}`),Uo&&u[d](...S);}:u[d]}}),p;return n?p=new Function(e,"console","libs","formatters","locale","variables",r)(t,l,he,o,c,n):p=new Function(e,"console","libs","formatters","locale",r)(t,l,he,o,c),typeof p=="object"&&Object.keys(p).length>0&&Object.assign(i,p),{vars:i,error:null,log:a,output:p}}return {vars:i,error:"Invalid API Link",log:a}}catch(l){return {vars:i,error:l.message,log:a}}}function qo(e,...t){return t.includes(e)}function ct(e){return e.reduce((t,r,o)=>(o?o===e.length-1&&o===1?t+=` and ${r}`:o===e.length-1?t+=`, and ${r}`:t+=`, ${r}`:t+=r,t),"")}var Se=$o;function $o(e,t,r,o=!1){let{variables:n}=K(r);if(!e)return e;let s=/([A-z0-9]*)\{\{([^\}]+)\}\}/g;return e.replace(s,(a,c,l)=>{let p=d=>d;if(c){let d=c.replace(/^\w/g,S=>S.toLowerCase());d in t?p=t[d]:p=S=>`${c}${S}`;}let u=Array.isArray(n[l])?ct(n[l]):n[l];if(u===void 0)return o?a:"N/A";try{return p(u,he,t)}catch(d){return console.error(`Error using formatter ${p.name}
|
|
26
|
-
`,`Error message: ${d.message}`),"N/A"}})}var lt=(e,t,r)=>{let{variables:o}=r,n=i=>i.allowed==="never"?!1:!i.allowed||i.allowed==="always"||o[i.allowed],s={...e};return Object.keys(s).forEach(i=>{typeof s[i]=="string"?s[i]=Se(s[i],t,r):Array.isArray(s[i])?s[i]=s[i].filter(n).map(a=>typeof a=="object"?lt(a,t,r):typeof a=="string"?Se(a,t,r):a):typeof s[i]=="object"&&s[i]!==null&&!(s[i]instanceof Date)&&(s[i]=lt(s[i],t,r));}),s},Ke=lt;var Qt=e=>Array.isArray(e)?e.map(t=>typeof t=="string"?{allowed:"always",label:t,id:t}:{allowed:"always",label:t.id,...t}):[];var ut=(e,t,r)=>{if(!r)return !1;if(e===ie.SINGLE)return r.find(n=>n.id===t);let o=Array.isArray(t)?t:t.split(",");return Array.isArray(o)&&o.every(n=>r.map(s=>s.id).includes(n))};function pt(e,t,r,o,n=!1){let{variables:s}=K(o),i=Ke({logic:t},r,o).logic,a=ce("variables",s,i,r,void 0,o),{vars:c,log:l,error:p}=a,u=c.type||ie.SINGLE,d=c.component||"Selector",S=c.hideLabel||"false",h=c.resetSectionVars||"false",A=c.name||"Unlabeled Selector",f=Qt(c.options||[]),
|
|
26
|
+
`,`Error message: ${d.message}`),"N/A"}})}var lt=(e,t,r)=>{let{variables:o}=r,n=i=>i.allowed==="never"?!1:!i.allowed||i.allowed==="always"||o[i.allowed],s={...e};return Object.keys(s).forEach(i=>{typeof s[i]=="string"?s[i]=Se(s[i],t,r):Array.isArray(s[i])?s[i]=s[i].filter(n).map(a=>typeof a=="object"?lt(a,t,r):typeof a=="string"?Se(a,t,r):a):typeof s[i]=="object"&&s[i]!==null&&!(s[i]instanceof Date)&&(s[i]=lt(s[i],t,r));}),s},Ke=lt;var Qt=e=>Array.isArray(e)?e.map(t=>typeof t=="string"?{allowed:"always",label:t,id:t}:{allowed:"always",label:t.id,...t}):[];var ut=(e,t,r)=>{if(!r)return !1;if(e===ie.SINGLE)return r.find(n=>n.id===t);let o=Array.isArray(t)?t:t.split(",");return Array.isArray(o)&&o.every(n=>r.map(s=>s.id).includes(n))};function pt(e,t,r,o,n=!1){let{variables:s}=K(o),i=Ke({logic:t},r,o).logic,a=ce("variables",s,i,r,void 0,o),{vars:c,log:l,error:p}=a,u=c.type||ie.SINGLE,d=c.component||"Selector",S=c.hideLabel||"false",h=c.resetSectionVars||"false",A=c.name||"Unlabeled Selector",f=Qt(c.options||[]),x=T=>u===ie.MULTI&&!Array.isArray(T)?[T]:T,P=c.defaultValue,w;if(P&&(P=x(P),ut(u,P,f)&&(w=P)),!w){let T=f&&f[0]&&f[0].id||f[0]||"";w=x(T);}if(n&&typeof window<"u"){let T=`selector${e}id`,N=new URLSearchParams(window.location.search),V=Object.fromEntries(N)[T];V&&!ut(u,V,f)&&V!==void 0&&(N.delete(T),window.history.replaceState(null,null,`?${N.toString()}`));}return {config:{name:A,type:u,options:f,defaultValue:w,component:d,hideLabel:S,resetSectionVars:h},log:l,error:p}}function dt(e,t,r){if(!e)return !1;let o=Array.isArray(r)?r:r.split(",");return Array.isArray(o)&&o.every(n=>e.map(s=>`${s[`${t} ID`]}`).includes(n))}function ft(e,t,r,o,n=!1){let{variables:s}=K(o),i=Ke({logic:t},r,o).logic,a=ce("variables",s,i,r,void 0,o),{vars:c,log:l,error:p}=a;if(n&&typeof window<"u"){let d=`multihierarchySelector${e}-value`,S=`multihierarchySelector${e}-type`,h=new URLSearchParams(window.location.search),A=Object.fromEntries(h),f=A[d],x=A[S];f&&f!==void 0&&x&&x!==void 0&&!dt(c.data,x,f)&&(h.delete(d),h.delete(S),window.history.replaceState(null,null,`?${h.toString()}`));}return {config:c,log:l,error:p}}var Vo=(e,t,r)=>{let o=`selector${e}id`,n=new URLSearchParams(typeof location<"u"&&location?.search?location.search:"").get(o),s=new URLSearchParams(t).get(o),i=n||s;if(r.type===ie.MULTI){let l=i?i.split(","):r.defaultValue,p=r.options.filter(u=>l.includes(u.id));return {[`selector${e}id`]:l,[`selector${e}label`]:(p||[]).map(u=>u.label)}}let a=i&&r.options.find(l=>l.id===i)?i:r.defaultValue,c=r.options.find(l=>l.id===a);return {[`selector${e}id`]:a,[`selector${e}label`]:c&&c.label||void 0}},Zt=Vo;var jo=(e,t,r)=>{let o=`multihierarchySelector${e}-value`,n=`multihierarchySelector${e}-type`,s=new URLSearchParams(typeof location<"u"&&location?.search?location.search:"").get(o),i=new URLSearchParams(typeof location<"u"&&location?.search?location.search:"").get(n),a=new URLSearchParams(t).get(o),c=new URLSearchParams(t).get(n),l=s||a,p=i||c,u=l?l.split(","):r.defaultValue||[],d=p||r.defaultValueType||"",S=r.data?.filter(h=>u.includes(`${h[`${d} ID`]}`))||[];return {[`multihierarchySelector${e}id`]:u,[`multihierarchySelector${e}label`]:[...new Set((S||[]).map(h=>h[d]))],[`multihierarchySelector${e}type`]:d}},Jt=jo;var{localeDefault:Xt,locales:zo}=Z(),Go=Object.values(at),Ho=(e,t=Xt)=>e&&Go.includes(e.type)?{locale:it,locales:[it]}:{locale:t,locales:zo},er=(e,t=Xt)=>{if(!e)return {};let{locale:r}=Ho(e,t);return e.contentByLocale?.[r]?.content};function Ko(e,t){let r=Object.values(t),o=r.filter(n=>n.shared&&n.section_id!==e).map(n=>n.id);return Object.fromEntries(r.filter(n=>n.section_id===e&&(n.inputs.length===0||n.inputs.some(s=>o.includes(s)))).map(n=>[n.id,n]))}var tr=Ko;var rr=(e,t)=>t&&typeof t=="string"?t.split(".").reduce((r,o)=>r[o],e):e;var or="|||";var nr="SECTION_ALLOWED";function mt(e){return e.type===E.SECTION_FLAG&&e.inputs.length===0&&e.consumers.length===0}var le=Mo(process.env.NEXT_PUBLIC_REPORTS_DEBUG),Zo=process.env.REPORTS_ORIGIN||"";sr(We,{retries:3,retryDelay:sr.exponentialDelay,onRetry:(e,t,r)=>{console.log("Generator request failed. Retrying... Count: ",e),console.log("URL: ",r.url),console.log(t.message);}});We.interceptors.request.use(e=>({...e,requestStart:Date.now()}));We.interceptors.response.use(e=>({...e,requestDuration:new Date().getTime()-e.config.requestStart}),e=>Promise.reject(e));var Jo=(e,t,r)=>{let o=Se(e,t,r);return o.startsWith("http")||(o=`${Zo}${o.startsWith("/")?"":"/"}${o}`),o},{urlProxy:Xo}=_e("/api/cms");function Ye(e){return e.ok!==void 0}function yt(e){this.message=e,this.name="ApiFetchException";}var ar=process.env.NEXT_PUBLIC_REPORTS_API_FETCH_TIMEOUT||0;async function en(e,t,r="en",o){let n=Date.now(),s=e,i,c=new URL(e).searchParams;if(c.has("bespoke_slugs")){let u=new RegExp(`[?&]bespoke_slugs=${c.get("bespoke_slugs")}`,"g");s=s.replace(u,"");}let l=o?o.settings:{},p=!!(l&&l.useProxy&&l.useProxy==="true");if(typeof window=="object"&&p){let u=await Xo({url:s,timeout:ar});if(u.ok===!0)i=u.data;else throw new yt(u?.error)}else try{let u=await We({url:s,timeout:ar});if(u.status===200)u.headers["content-type"]==="text/csv"?i=csvParse(u.data):i=u.data;else throw new yt("No response")}catch(u){throw new yt(u.message)}if(c.has("bespoke_slugs")){let u=c.get("bespoke_slugs");if(u){let d=u.split(",");if(d.length===3){let[S,h,A]=d,f=rr(i,A);if(f&&Array.isArray(f)){let x=Array.from(new Set(f.map(b=>`${b[h]}`).filter(b=>!["","undefined"].includes(b)))),P=x.join("").length>2e3,w=await t({mode:P?"whole":"ids",ids:P?void 0:x,all:!1,locale:r,variant:[parseInt(S,10)],output:"lite",limit:x.length+1}).then(b=>{let T=[];return Ye(b)?b.ok&&(T=b.data.results):T=b.results,T&&Array.isArray(T)?T:[]}).catch(b=>(console.error(`Error hydrating slugs for Variant: ${S}, Key: ${h}, Accessor: ${A}`),console.error(` Url ${e}`),o&&console.error(` From Section ${o.section_id} and Block ${o.id}`),console.error(b),[]));if(w){let b=Object.fromEntries(w.map(T=>[T.id,`/${T.variant_slug}/${T.slug}`]));f.map(T=>(T.bespoke_slug=b[T[h]]?b[T[h]]:null,T));}}}}}return {data:i,requestDuration:Date.now()-n}}function tn(e){this.name="BlockException",this.message=e;}async function ir(e,t,r,o){let{locale:n,variables:s,query:i}=K(r),a=on(e,r,s,t),c=null,l=e.contentByLocale?.logic?.content?.api,p=null,u=null,d=null;if(!a)return {outputVariables:{},renderVariables:{},status:{allowed:!1,hiddenByCascade:e.id}};if(e.type===E.FALLBACK)return {outputVariables:{},renderVariables:{},status:{allowed:a,hiddenByCascade:e.id}};if(l){d=Jo(l,t,r);let b=d.split(or).filter(I=>I!==""),T=[];for(let I=0;I<b.length;I++){let V=b[I];new RegExp("^(?:[a-z+]+:)?//","i").test(d)||(V=`${process.env.NEXT_PUBLIC_REPORTS_BASE_URL}/${V}`.replace(/([^:]\/)\/+/g,"$1")),T.push(en(V,o,n,e).catch(X=>{throw new tn(` Excecution of ${e.type}-${e.id} in section ${e.section_id} in report ${s.report_name} (${s.report_id}) failed.
|
|
27
27
|
Error fetching ${V}.
|
|
28
28
|
Message: ${X.message}.
|
|
29
|
-
`)}));}let N=await Promise.all(T).catch(I=>I.message);if(typeof N=="string"&&N)return {outputVariables:{},renderVariables:{},status:{error:N}};c=N.length===1?N[0].data:N.map(I=>I.data),u=N.reduce((I,V)=>I+JSON.stringify(V.data).length/1024,0),p=Math.max(...N.map(I=>I.requestDuration));}if(e.type===E.SELECTOR){let{config:b,log:T,error:N}=pt(e.id,e.contentByLocale[n].content.logic,t,r,!0);return {outputVariables:Zt(e.id,i,b),renderVariables:b,status:{log:T,error:N,allowed:a}}}if(e.type===E.MULTIHIERARCHY_SELECTOR){let{config:b,log:T,error:N}=ft(e.id,e.contentByLocale[n].content.logic,t,r,!0);return {outputVariables:Jt(e.id,i,b),renderVariables:b,status:{log:T,error:N,allowed:a}}}if(e.type===E.VIZ)return {outputVariables:{},renderVariables:e.contentByLocale.logic.content,status:{log:[],allowed:a}};if(e.type===E.RELATED){let b=e.contentByLocale?.logic?.content?.simple?.compare||"variant",T=e.contentByLocale?.logic?.content?.simple?.limit||4,N=Object.keys(s).filter(m=>m.startsWith("report_id")).map(m=>s[m]),I=Object.keys(s).filter(m=>m.startsWith("dimension_id")).map(m=>s[m]),V=Object.keys(s).filter(m=>m.startsWith("variant_id")).map(m=>s[m]),Q=Object.keys(s).filter(m=>m.startsWith("id")).map(m=>s[m]);if(!Q.length)return {outputVariables:{related_reports:[]},renderVariables:{},status:{log:[],allowed:!1}};let X=await o({mode:"ids",locale:n,ids:Q,output:"lite",variant:V}).then(m=>{let U=[];return Ye(m)?m.ok&&(U=m.data.results):U=m.results,U&&Array.isArray(U)?U:[]}).catch(m=>(console.log("Error getting related members",m),[]));if(I.length>1){let m=Object.keys(s).filter(_=>_.startsWith("variant_slug")).map(_=>s[_]),U=X.map((_,B)=>{let v={mode:"related",locale:n,related:T??4,current_ids:[_.content_id],output:"full",variant_ids:[_.variant_id]};return B===0&&(v.include_ids=[_.content_id]),v}),L=await Promise.all(U.map(_=>o(_))).then(_=>_.flatMap(B=>{let v=[];return Ye(B)?B.ok&&(v=B.data.results):v=B.results,v&&Array.isArray(v)?v:[]})).catch(_=>(console.log("Error getting related members",_),[])),q=L.reduce((_,B)=>{let v=B.variant_slug;return _[v]||(_[v]=[]),_[v].push(B),_},{}),z=[],ee=Object.keys(q),te=[{combination:[],index:0}];for(;te.length>0;){let _=te.pop();if(!_)continue;let{combination:B,index:v}=_;if(v===ee.length){z.push(B);continue}let ot=ee[v],zr=q[ot];for(let Gr of zr)te.push({combination:[...B,Gr],index:v+1});}return {outputVariables:{related_reports:z.map(_=>{let B=_.sort((v,ot)=>m.indexOf(v.variant_slug)-m.indexOf(ot.variant_slug));return {entities:B,link:"/"+B.map(v=>`${v.variant_slug}/${v.slug}`).join("/")}})},renderVariables:{},status:{log:[],allowed:L.length>0}}}let x=X.map(m=>m.content_id),P={mode:"related",locale:n,related:T??4,current_ids:x,output:"full"};b&&(b==="report"?P.report_ids=N:b==="dimension"?P.dimension_ids=I:P.variant_ids=V);let D=await o(P).then(m=>{let U=[];return Ye(m)?m.ok&&(U=m.data.results):U=m.results,U&&Array.isArray(U)?U:[]}).catch(m=>(console.log("Error getting related members",m),[]));return {outputVariables:{related_reports:D.map(m=>({entities:[m],link:`/${m.variant_slug}/${m.slug}`}))},renderVariables:{},status:{log:[],allowed:D.length>0}}}let{logic:S}=er(e,n),h=Se(S,t,r),A=ce("resp",c||{},h,t,s,r),{vars:f,error:k,log:C}=A;if(typeof f!="object")return {outputVariables:{},renderVariables:{},status:{error:"Configuration did not return an object",log:C,duration:p,responseSize:u,resp:c,api:d,allowed:a}};let w=Object.keys(f).reduce((b,T)=>({...b,[`${e.type}${e.id}${T}`]:f[T]}),{});return {renderVariables:f,outputVariables:[E.GENERATOR,E.SECTION_FLAG].includes(e.type)?f:w,status:{log:C,error:k,duration:p,responseSize:u,resp:c,api:d,allowed:a}}}function rn(e,t,r,o,n,s,i){return e.consumers.forEach(a=>{if(t[a]){let c=`${r}-${a}`;!o.includes(c)&&(t[a].section_id===t[r].section_id||!n)&&o.push(c),e.consumers.filter(l=>t[l].section_id===t[r].section_id||!n).forEach(l=>Rt(l,t,o,!1,s,n,i));}})}var Rt=(e,t,r=[],o=!0,n=!0,s=!0,i=[])=>{if(i.includes(e))return [];i.push(e);let a=t[e];return a&&a.inputs.length&&o&&a.inputs.forEach(c=>{let l=`${c}-${e}`;r.includes(l)||r.push(l),a.inputs.forEach(p=>Rt(p,t,r,o,!1,s,i));}),a&&a.consumers.length&&n&&rn(a,t,e,r,s,n,i),r},on=(e,t,r,o)=>{let n=!0;if(e&&"allowed"in e.settings&&e.settings.allowed!=="always")if(e.settings.allowed==="never")n=!1;else {let s=K(t),{error:i,output:a}=ce("variables",r,e.settings.allowedLogic||"return false;",o,void 0,s);i||(n=!!a);}return n},cr=async(e,t,r,o,n,s={},i,a="section")=>{let c=a==="section",l=K(n),p=l.variables,u={...s.variables??{}},d={...s.status??{}},S=new Set,h=[],A={};r?A={...A,[r]:e[r]}:t?A=(t??[]).reduce((x,{id:P})=>({...x,...tr(P,e)}),{}):A=Object.values(e).filter(x=>mt(x)).reduce((x,P)=>({...x,[P.id]:P}),{});let f=Object.values(A).filter(x=>mt(x));if(f.length>0){le&&console.log("%crunConsumers: calculating section flags","color:purple",f.map(g=>g.id).join(", "));let x=Object.fromEntries(await Promise.all(f.map(async g=>[g.id,await ir(g,o,{...l,variables:p,locale:p.locale},i).then(m=>{let{outputVariables:U,status:L}=m;if(L.error){if(typeof window>"u")throw new Error(`Run consumers (Block: ${g.id}, Section ${g.section_id}) failed with message: ${L.error}. `);d[g.id]={allowed:!1,error:L.error},u[g.id]={};}return (g.consumers.length>0||[E.GENERATOR,E.SECTION_FLAG,E.RELATED].includes(g.type))&&L.allowed&&Object.keys(U).length>0?u[g.id]=U:u[g.id]={},a==="report"?(d[g.id]={allowed:L.allowed},[E.GENERATOR,E.SECTION_FLAG].includes(g.type)&&L.api&&(d[g.id].api=L.api)):d[g.id]=L,m})]))),D=Object.entries(x).filter(([g,m])=>!m.outputVariables[nr]).map(([g])=>Number(g));S=new Set(D.map(g=>e[g].section_id)),Object.values(A).filter(g=>S.has(g.section_id)).forEach(g=>{h.push(g.id),delete A[g.id];}),le&&console.log("%crunConsumers: removing sections","color:purple",S.keys());}let k=S.size>0?Object.fromEntries(Object.entries(e).filter(([x,P])=>S?.has(P.section_id)?(h.includes(P.id)||h.push(P.id),!1):!0)):e;if(h.length>0&&(k=Object.fromEntries(Object.entries(k).map(([x,P])=>{let D={...P,inputs:P.inputs.filter(g=>!h.includes(g)),consumers:P.consumers.filter(g=>!h.includes(g))};return [x,D]}))),!r&&!t)return {variables:{...s.variables??{},...u},status:{...s.status??{},...d}};a==="report"&&h.length>0&&h.forEach(x=>{delete u[x],delete d[x],delete e[x];}),le&&console.log("%crunConsumers: running root blocks","color:purple",Object.keys(A));let C=Object.keys(A).reduce((x,P)=>{let D=new Date,g=Rt(Number(P),k,[],!r,!0,c).map(L=>L.split("-")),U=(new Date().getTime()-D.getTime())/1e3;return le&&console.log(`%cResolved dependencies for ${P} (${U.toFixed(2)}s)`,"color:blue"),[...x,...g]},[]),w=new Date,b=Object.keys(A).reduce((x,P)=>x.includes(P)?[...x]:[P,...x],Yo(C)),N=(new Date().getTime()-w.getTime())/1e3;le&&console.log(`%cResolved DAG (${N.toFixed(2)}s): `,"color:green",b);async function I(x,P){let D=new Map;for(let g of x){let m=P[g],L=Promise.all(m.inputs.filter(q=>x.includes(String(q))).map(q=>D.get(Number(q)))).then(async()=>{let q=m.inputs.reduce((B,v)=>({...B,...u[v]}),p),z=m.inputs.find(B=>(m.settings?.ignoreCascade?m.settings?.ignoreCascade:[]).includes(B)||!d[B]?!1:!d[B].allowed||d[B].hiddenByCascade);if(z){d[g]={allowed:!1,hiddenByCascade:d[z].hiddenByCascade||z},u[g]={};return}let ee=new Date,te=await ir(m,o,{...l,variables:q,locale:q.locale},i).then(({outputVariables:B,status:v})=>{if(v.error){if(typeof window>"u")throw new Error(`Run consumers (Block: ${g}, Section ${m.section_id}) failed with message: ${v.error}. `);d[g]={allowed:!1,error:v.error},u[g]={};}(m.consumers.length>0||[E.GENERATOR,E.SECTION_FLAG,E.RELATED].includes(m.type))&&v.allowed&&Object.keys(B).length>0?u[g]=B:u[g]={},a==="report"?(d[g]={allowed:v.allowed},[E.GENERATOR,E.SECTION_FLAG].includes(m.type)&&v.api&&(d[g].api=v.api)):d[g]=v;}),_=(new Date().getTime()-ee.getTime())/1e3;return le&&console.log(`%cBlock ${m.id} resolved in ${_.toFixed(3)}s`,_>500?"color:red":"color:green"),te});D.set(Number(g),L);}await Promise.all(Array.from(D.values()));}let V=new Date;await I(b,k);let X=(new Date().getTime()-V.getTime())/1e3;return le&&console.log(`%cResolved Variables (${X.toFixed(2)}s): `,"color:green"),{variables:{...s.variables??{},...u},status:{...s.status??{},...d}}};function nn(e=[]){return e.reduce((t,r,o)=>{if(r){let n=o+1;t[`id${n}`]=r.id,t[`name${n}`]=r.name,t[`slug${n}`]=r.slug,"attributes"in r&&Object.keys(r.attributes).forEach(s=>{t[`attr_${s}${n}`]=r.attributes[s];}),t[`variant_id${n}`]=r.variant_id,t[`variant_name${n}`]=r.variant_name,t[`variant_slug${n}`]=r.variant_slug,t[`dimension_id${n}`]=r.dimension_id,t[`dimension_name${n}`]=r.dimension_name,t.report_id=r.report_id,t.report_name=r.report_name;}return t},{})}var lr=nn;function an(){let{publicRuntimeConfig:e}=sn(),t=e.bespoke_report_env_vars||{};return {...Object.keys(t).reduce((r,o)=>(r[`ENV_${o}`]=t[o]||"N/A",r),{})}}var ur=an;function ue(e,t,r){if(t==="createBulk"||t==="updateBulk"){let n=`${t}${pr(r)}`;return e[n]}let o=`${t}${pr(r)}`;return e[o]}function pr(e){return e[0].toUpperCase()+e.slice(1)}function j(e){for(var t=arguments.length,r=Array(t>1?t-1:0),o=1;o<t;o++)r[o-1]=arguments[o];if(process.env.NODE_ENV!=="production"){var n=yn[e],s=n?typeof n=="function"?n.apply(null,r):n:"unknown error nr: "+e;throw Error("[Immer] "+s)}throw Error("[Immer] minified error nr: "+e+(r.length?" "+r.map(function(i){return "'"+i+"'"}).join(","):"")+". Find the full error at: https://bit.ly/3cXEKWf")}function be(e){return !!e&&!!e[G]}function de(e){var t;return !!e&&(function(r){if(!r||typeof r!="object")return !1;var o=Object.getPrototypeOf(r);if(o===null)return !0;var n=Object.hasOwnProperty.call(o,"constructor")&&o.constructor;return n===Object||typeof n=="function"&&Function.toString.call(n)===Rn}(e)||Array.isArray(e)||!!e[Er]||!!(!((t=e.constructor)===null||t===void 0)&&t[Er])||xt(e)||Ct(e))}function Ne(e,t,r){r===void 0&&(r=!1),ve(e)===0?(r?Object.keys:It)(e).forEach(function(o){r&&typeof o=="symbol"||t(o,e[o],e);}):e.forEach(function(o,n){return t(n,o,e)});}function ve(e){var t=e[G];return t?t.i>3?t.i-4:t.i:Array.isArray(e)?1:xt(e)?2:Ct(e)?3:0}function St(e,t){return ve(e)===2?e.has(t):Object.prototype.hasOwnProperty.call(e,t)}function cn(e,t){return ve(e)===2?e.get(t):e[t]}function Tr(e,t,r){var o=ve(e);o===2?e.set(t,r):o===3?e.add(r):e[t]=r;}function ln(e,t){return e===t?e!==0||1/e==1/t:e!=e&&t!=t}function xt(e){return fn&&e instanceof Map}function Ct(e){return mn&&e instanceof Set}function pe(e){return e.o||e.t}function Pt(e){if(Array.isArray(e))return Array.prototype.slice.call(e);var t=gn(e);delete t[G];for(var r=It(t),o=0;o<r.length;o++){var n=r[o],s=t[n];s.writable===!1&&(s.writable=!0,s.configurable=!0),(s.get||s.set)&&(t[n]={configurable:!0,writable:!0,enumerable:s.enumerable,value:e[n]});}return Object.create(Object.getPrototypeOf(e),t)}function Lt(e,t){return t===void 0&&(t=!1),_t(e)||be(e)||!de(e)||(ve(e)>1&&(e.set=e.add=e.clear=e.delete=un),Object.freeze(e),t&&Ne(e,function(r,o){return Lt(o,!0)},!0)),e}function un(){j(2);}function _t(e){return e==null||typeof e!="object"||Object.isFrozen(e)}function J(e){var t=hn[e];return t||j(18,e),t}function dr(){return process.env.NODE_ENV==="production"||Ae||j(0),Ae}function gt(e,t){t&&(J("Patches"),e.u=[],e.s=[],e.v=t);}function Qe(e){bt(e),e.p.forEach(pn),e.p=null;}function bt(e){e===Ae&&(Ae=e.l);}function fr(e){return Ae={p:[],l:Ae,h:e,m:!0,_:0}}function pn(e){var t=e[G];t.i===0||t.i===1?t.j():t.g=!0;}function ht(e,t){t._=t.p.length;var r=t.p[0],o=e!==void 0&&e!==r;return t.h.O||J("ES5").S(t,e,o),o?(r[G].P&&(Qe(t),j(4)),de(e)&&(e=Ze(t,e),t.l||Je(t,e)),t.u&&J("Patches").M(r[G].t,e,t.u,t.s)):e=Ze(t,r,[]),Qe(t),t.u&&t.v(t.u,t.s),e!==Sr?e:void 0}function Ze(e,t,r){if(_t(t))return t;var o=t[G];if(!o)return Ne(t,function(a,c){return mr(e,o,t,a,c,r)},!0),t;if(o.A!==e)return t;if(!o.P)return Je(e,o.t,!0),o.t;if(!o.I){o.I=!0,o.A._--;var n=o.i===4||o.i===5?o.o=Pt(o.k):o.o,s=n,i=!1;o.i===3&&(s=new Set(n),n.clear(),i=!0),Ne(s,function(a,c){return mr(e,o,n,a,c,r,i)}),Je(e,n,!1),r&&e.u&&J("Patches").N(o,r,e.u,e.s);}return o.o}function mr(e,t,r,o,n,s,i){if(process.env.NODE_ENV!=="production"&&n===r&&j(5),be(n)){var a=Ze(e,n,s&&t&&t.i!==3&&!St(t.R,o)?s.concat(o):void 0);if(Tr(r,o,a),!be(a))return;e.m=!1;}else i&&r.add(n);if(de(n)&&!_t(n)){if(!e.h.D&&e._<1)return;Ze(e,n),t&&t.A.l||Je(e,n);}}function Je(e,t,r){r===void 0&&(r=!1),!e.l&&e.h.D&&e.m&&Lt(t,r);}function Et(e,t){var r=e[G];return (r?pe(r):e)[t]}function yr(e,t){if(t in e)for(var r=Object.getPrototypeOf(e);r;){var o=Object.getOwnPropertyDescriptor(r,t);if(o)return o;r=Object.getPrototypeOf(r);}}function At(e){e.P||(e.P=!0,e.l&&At(e.l));}function Tt(e){e.o||(e.o=Pt(e.t));}function vt(e,t,r){var o=xt(t)?J("MapSet").F(t,r):Ct(t)?J("MapSet").T(t,r):e.O?function(n,s){var i=Array.isArray(n),a={i:i?1:0,A:s?s.A:dr(),P:!1,I:!1,R:{},l:s,t:n,k:null,o:null,j:null,C:!1},c=a,l=kt;i&&(c=[a],l=we);var p=Proxy.revocable(c,l),u=p.revoke,d=p.proxy;return a.k=d,a.j=u,d}(t,r):J("ES5").J(t,r);return (r?r.A:dr()).p.push(o),o}function dn(e){return be(e)||j(22,e),function t(r){if(!de(r))return r;var o,n=r[G],s=ve(r);if(n){if(!n.P&&(n.i<4||!J("ES5").K(n)))return n.t;n.I=!0,o=Rr(r,s),n.I=!1;}else o=Rr(r,s);return Ne(o,function(i,a){n&&cn(n.t,i)===a||Tr(o,i,t(a));}),s===3?new Set(o):o}(e)}function Rr(e,t){switch(t){case 2:return new Map(e);case 3:return Array.from(e)}return Pt(e)}var gr,Ae,Ot=typeof Symbol<"u"&&typeof Symbol("x")=="symbol",fn=typeof Map<"u",mn=typeof Set<"u",hr=typeof Proxy<"u"&&Proxy.revocable!==void 0&&typeof Reflect<"u",Sr=Ot?Symbol.for("immer-nothing"):((gr={})["immer-nothing"]=!0,gr),Er=Ot?Symbol.for("immer-draftable"):"__$immer_draftable",G=Ot?Symbol.for("immer-state"):"__$immer_state";var yn={0:"Illegal state",1:"Immer drafts cannot have computed properties",2:"This object has been frozen and should not be mutated",3:function(e){return "Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? "+e},4:"An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.",5:"Immer forbids circular references",6:"The first or second argument to `produce` must be a function",7:"The third argument to `produce` must be a function or undefined",8:"First argument to `createDraft` must be a plain object, an array, or an immerable object",9:"First argument to `finishDraft` must be a draft returned by `createDraft`",10:"The given draft is already finalized",11:"Object.defineProperty() cannot be used on an Immer draft",12:"Object.setPrototypeOf() cannot be used on an Immer draft",13:"Immer only supports deleting array indices",14:"Immer only supports setting array indices and the 'length' property",15:function(e){return "Cannot apply patch, path doesn't resolve: "+e},16:'Sets cannot have "replace" patches.',17:function(e){return "Unsupported patch operation: "+e},18:function(e){return "The plugin for '"+e+"' has not been loaded into Immer. To enable the plugin, import and call `enable"+e+"()` when initializing your application."},20:"Cannot use proxies if Proxy, Proxy.revocable or Reflect are not available",21:function(e){return "produce can only be called on things that are draftable: plain objects, arrays, Map, Set or classes that are marked with '[immerable]: true'. Got '"+e+"'"},22:function(e){return "'current' expects a draft, got: "+e},23:function(e){return "'original' expects a draft, got: "+e},24:"Patching reserved attributes like __proto__, prototype and constructor is not allowed"},Rn=""+Object.prototype.constructor,It=typeof Reflect<"u"&&Reflect.ownKeys?Reflect.ownKeys:Object.getOwnPropertySymbols!==void 0?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:Object.getOwnPropertyNames,gn=Object.getOwnPropertyDescriptors||function(e){var t={};return It(e).forEach(function(r){t[r]=Object.getOwnPropertyDescriptor(e,r);}),t},hn={},kt={get:function(e,t){if(t===G)return e;var r=pe(e);if(!St(r,t))return function(n,s,i){var a,c=yr(s,i);return c?"value"in c?c.value:(a=c.get)===null||a===void 0?void 0:a.call(n.k):void 0}(e,r,t);var o=r[t];return e.I||!de(o)?o:o===Et(e.t,t)?(Tt(e),e.o[t]=vt(e.A.h,o,e)):o},has:function(e,t){return t in pe(e)},ownKeys:function(e){return Reflect.ownKeys(pe(e))},set:function(e,t,r){var o=yr(pe(e),t);if(o?.set)return o.set.call(e.k,r),!0;if(!e.P){var n=Et(pe(e),t),s=n?.[G];if(s&&s.t===r)return e.o[t]=r,e.R[t]=!1,!0;if(ln(r,n)&&(r!==void 0||St(e.t,t)))return !0;Tt(e),At(e);}return e.o[t]===r&&(r!==void 0||t in e.o)||Number.isNaN(r)&&Number.isNaN(e.o[t])||(e.o[t]=r,e.R[t]=!0),!0},deleteProperty:function(e,t){return Et(e.t,t)!==void 0||t in e.t?(e.R[t]=!1,Tt(e),At(e)):delete e.R[t],e.o&&delete e.o[t],!0},getOwnPropertyDescriptor:function(e,t){var r=pe(e),o=Reflect.getOwnPropertyDescriptor(r,t);return o&&{writable:!0,configurable:e.i!==1||t!=="length",enumerable:o.enumerable,value:r[t]}},defineProperty:function(){j(11);},getPrototypeOf:function(e){return Object.getPrototypeOf(e.t)},setPrototypeOf:function(){j(12);}},we={};Ne(kt,function(e,t){we[e]=function(){return arguments[0]=arguments[0][0],t.apply(this,arguments)};}),we.deleteProperty=function(e,t){return process.env.NODE_ENV!=="production"&&isNaN(parseInt(t))&&j(13),we.set.call(this,e,t,void 0)},we.set=function(e,t,r){return process.env.NODE_ENV!=="production"&&t!=="length"&&isNaN(parseInt(t))&&j(14),kt.set.call(this,e[0],t,r,e[0])};var En=function(){function e(r){var o=this;this.O=hr,this.D=!0,this.produce=function(n,s,i){if(typeof n=="function"&&typeof s!="function"){var a=s;s=n;var c=o;return function(A){var f=this;A===void 0&&(A=a);for(var k=arguments.length,C=Array(k>1?k-1:0),w=1;w<k;w++)C[w-1]=arguments[w];return c.produce(A,function(b){var T;return (T=s).call.apply(T,[f,b].concat(C))})}}var l;if(typeof s!="function"&&j(6),i!==void 0&&typeof i!="function"&&j(7),de(n)){var p=fr(o),u=vt(o,n,void 0),d=!0;try{l=s(u),d=!1;}finally{d?Qe(p):bt(p);}return typeof Promise<"u"&&l instanceof Promise?l.then(function(A){return gt(p,i),ht(A,p)},function(A){throw Qe(p),A}):(gt(p,i),ht(l,p))}if(!n||typeof n!="object"){if((l=s(n))===void 0&&(l=n),l===Sr&&(l=void 0),o.D&&Lt(l,!0),i){var S=[],h=[];J("Patches").M(n,l,S,h),i(S,h);}return l}j(21,n);},this.produceWithPatches=function(n,s){if(typeof n=="function")return function(l){for(var p=arguments.length,u=Array(p>1?p-1:0),d=1;d<p;d++)u[d-1]=arguments[d];return o.produceWithPatches(l,function(S){return n.apply(void 0,[S].concat(u))})};var i,a,c=o.produce(n,s,function(l,p){i=l,a=p;});return typeof Promise<"u"&&c instanceof Promise?c.then(function(l){return [l,i,a]}):[c,i,a]},typeof r?.useProxies=="boolean"&&this.setUseProxies(r.useProxies),typeof r?.autoFreeze=="boolean"&&this.setAutoFreeze(r.autoFreeze);}var t=e.prototype;return t.createDraft=function(r){de(r)||j(8),be(r)&&(r=dn(r));var o=fr(this),n=vt(this,r,void 0);return n[G].C=!0,bt(o),n},t.finishDraft=function(r,o){var n=r&&r[G];process.env.NODE_ENV!=="production"&&(n&&n.C||j(9),n.I&&j(10));var s=n.A;return gt(s,o),ht(void 0,s)},t.setAutoFreeze=function(r){this.D=r;},t.setUseProxies=function(r){r&&!hr&&j(20),this.O=r;},t.applyPatches=function(r,o){var n;for(n=o.length-1;n>=0;n--){var s=o[n];if(s.path.length===0&&s.op==="replace"){r=s.value;break}}n>-1&&(o=o.slice(n+1));var i=J("Patches").$;return be(r)?i(r,o):this.produce(r,function(a){return i(a,o)})},e}(),H=new En,Tn=H.produce;H.produceWithPatches.bind(H);H.setAutoFreeze.bind(H);H.setUseProxies.bind(H);H.applyPatches.bind(H);H.createDraft.bind(H);H.finishDraft.bind(H);var Xe=Tn;var W=oe.actions,kr=De({block:fe("block"),dimension:fe("dimension"),formatter:fe("formatter"),report:fe("report"),section:fe("section"),variant:fe("variant")}),Me=De({block:me("block"),dimension:me("dimension"),formatter:me("formatter"),report:me("report"),section:me("section"),variant:me("variant")}),xr=De({block:re("block"),dimension:re("dimension"),formatter:re("formatter"),report:re("report"),section:re("section"),variant:re("variant")}),Cr=De({block:ke("block"),dimension:ke("dimension"),formatter:ke("formatter"),report:ke("report"),section:ke("section"),variant:ke("variant")}),Pr=De({block:Ar("block"),section:Ar("section")});function De(e){return (t,r)=>{let o=e[t];if(!o)throw new Error(`Attempting to dispatch action for invalid entity type '${t}'`);return o(r)}}function ye(e,t){return (r,o)=>{let s=o().records.requests[e][t],i=!s||s.status==="UNINITIALIZED"?"LOADING":"FETCHING";r(W.setRequest({key:t,type:e,status:i}));}}function xe(e,t,r,o){return n=>{typeof window=="object"&¬ifications.show({autoClose:3e3,color:"red",id:t,message:o,title:"Error"}),n(W.setRequest({key:t,type:e,status:"FAILURE",error:{code:r,message:o}}));}}function fe(e){return t=>{let r=wt(e,t);return (o,n,s)=>(o(ye(e,r)),ue(s,"create",e)(t).then(a=>(a.ok===!0?o(W.setCreateRequest({key:r,operation:"create",status:"SUCCESS",type:e,data:a.data})):o(xe(e,r,a.status,a.error)),a)))}}function An(e){return t=>{let r=wt(e,t[0]);return (o,n,s)=>(o(ye(e,r)),ue(s,"createBulk",e)(t).then(a=>(a.ok===!0?o(W.setCreateRequest({key:r,operation:"createBulk",status:"SUCCESS",type:e,data:a.data})):o(xe(e,r,a.status,a.error)),a)))}}function br(e,t,r){return r.replace(new RegExp(e,"g"),t)}function vn(e){return e.section_id!==void 0}function kn(e){return e.report_id!==void 0}function Ar(e){return t=>{let{create:r}=t;return (o,n,s)=>fe(e)(r)(o,n,s).then(async a=>{if(a.ok){let{data:c}=a,{id:l}=c,{update:p}=t,u=Or(e,{id:l});if(o(ye(e,`${u}`)),e==="block"&&vn(r)){let d=Xe(p,f=>{f.id=l;}),{contentByLocale:S}=d;S&&(d=Xe(d,f=>{f.id=l,f.contentByLocale=Object.keys(S).reduce((k,C)=>{let w=S?S[C]:{};return k[C]={...w,id:l},k},{});}));let A=d.inputs?.map(f=>({type:f.type,id:f.id,inputAction:{operation:"create",input:{input_id:f.id,block_id:d.id}}}));return A&&A.length>0&&vr(e)([d,...A])(o,n,s).then(()=>me("section")({id:d.section_id,include:!0})(o,n,s).then(f=>(f.ok&&o(W.setRequest({key:u,type:e,status:"SUCCESS",data:f.data})),f))),re(e)(d)(o,n,s).then(f=>(f.ok&&o(W.setRequest({key:u,type:e,status:"SUCCESS",data:f.data})),f))}if(e==="section"&&kn(r)){let{id:d}=c,S=Xe(p,f=>{f.id=d;}),{blocks:h}=S,A=h?.map(f=>({type:f.type,blockcol:f.blockcol,blockrow:f.blockrow,section_id:d,locales:Object.keys(f.contentByLocale).map(k=>k)}));return A&&h&&await An("block")(A)(o,n,s).then(f=>{if(f.ok){let k=f.data,C=[],w=k.map((b,T)=>{let I={...b},V=I.id,Q=h[T];Q.contentByLocale&&(I.contentByLocale=Object.keys(Q.contentByLocale).reduce((L,q)=>{let z=Q.contentByLocale[q];return L[q]={...z,content:{...z.content},id:I.id},L},{}));let{settings:X}=Q,{contentByLocale:x,id:P}=I;I.settings=X;let D={id:P,contentByLocale:x,settings:X};return Q.inputs.map(L=>L.id).reduce((L,q)=>{let z=h.findIndex(ee=>ee.id===q);return [...L,z]},[]).map(L=>({...k[L],originalBlock:h[L]})).forEach(L=>{let{id:q,type:z,originalBlock:ee}=L;if([E.SELECTOR,E.VIZ].includes(z)){if(D.contentByLocale?.logic?.content?.api){let te=D.contentByLocale?.logic.content.api;D.contentByLocale.logic.content.api=br(`(selector${ee.id}id)`,`selector${q}id`,te);}if(D.contentByLocale?.logic?.content?.logic){let te=D.contentByLocale.logic.content.logic;D.contentByLocale.logic.content.logic=br(`(selector${ee.id}id)`,`selector${q}id`,te);}}C.push({id:q,inputAction:{operation:"create",input:{input_id:q,block_id:V}}});}),D});return vr("block")([...w,...C])(o,n,s)}}),re(e)(S)(o,n,s).then(f=>(f.ok&&o(W.setRequest({key:u,type:e,status:"SUCCESS",data:f.data})),f))}return re(e)({...p,id:c.id})(o,n,s)}})}}function me(e){return t=>{let r=Lr(e,t);return (o,n,s)=>(o(ye(e,r)),ue(s,"read",e)(t).then(a=>(a.ok===!0?o(W.setReadRequest({key:r,operation:"read",status:"SUCCESS",type:e,data:a.data})):o(xe(e,r,a.status,a.error)),a)))}}function re(e){return t=>{let r=Nt(e,t);return (o,n,s)=>(o(ye(e,r)),ue(s,"update",e)(t).then(a=>(a.ok===!0?o(W.setUpdateRequest({key:r,operation:"update",status:"SUCCESS",type:e,data:a.data})):o(xe(e,r,a.status,a.error)),a)))}}function vr(e){return t=>{let r=Nt(e,t[0]);return (o,n,s)=>(o(ye(e,r)),ue(s,"updateBulk",e)(t).then(a=>(a.ok===!0?o(W.setUpdateRequest({key:r,operation:"updateBulk",status:"SUCCESS",type:e,data:a.data})):o(xe(e,r,a.status,a.error)),a)))}}function ke(e){return t=>{let r=_r(e,t);return (o,n,s)=>(o(ye(e,r)),ue(s,"delete",e)(t).then(a=>{a.ok===!0?o(W.setDeleteRequest({key:r,operation:"delete",status:"SUCCESS",type:e,data:a.data})):o(xe(e,r,a.status,a.error));}))}}function wt(e,t){if(e==="variant"){let r=t;return `create(variant, [${r.dimension_id}, ${r.name}])`}return `create(${e}, [${Object.keys(t)}])`}function Lr(e,t={}){let r=t.id==null?null:`'${t.id}'`;return `read(${e}, ${r}, ${!!t.include})`}function Nt(e,t){let{id:r,...o}=t;return `update(${e}, ${r}, [${Object.keys(o)}])`}function _r(e,t){return `delete(${e}, ${t})`}function Or(e,t){let r=t.id==null?null:`'${t.id}'`;return `clone(${e}, ${r})`}var{setStatus:Ir,setPreviews:xn,setSectionState:Br,resetSectionState:wr,setCurrentLocale:Cn,setPreferredLocale:Pn}=ze;function Ln(e,t){return async(r,o,n)=>{let s=await n.validateVariantSlug({dimension:e,slug:t});if("error"in s)throw new Error(s.error);return s.data}}function _n(e){return async(t,r,o)=>{let n=await o.searchReport(e);if("error"in n)throw new Error(n.error);return n.data}}function On(){return async(e,t,r)=>{let o=await r.regenerateSearch(void 0);if("error"in o)throw new Error(o.error);return o.data}}function Nr(e){return async(t,r,o)=>{let n=await o.readMember(e);if("error"in n)throw new Error(n.error);return n.data}}function In(e){return async(t,r,o)=>{let n=await o.searchMember(e);if(n.ok===!0)return n.data;throw new Error(n.error)}}async function Mr(e,t,r,o){let n=r().status,s={...n,...o},i={...n.query,...o.query};Object.keys(i).forEach(c=>i[c]===void 0&&delete i[c]);let a={...s,query:i};t(Ir(a)),n.activeSection&&t(Dr(e,{query:i}));}function Bn(e,t){return async(r,o)=>Mr(e,r,o,{query:{[t]:void 0}})}function wn(e,t,r){return async(o,n)=>Mr(e,o,n,{query:{[t]:r}})}function Dr(e,t){return async(r,o)=>{let n=o(),{currentLocale:s}=n.status,i=n.records.entities.block,a=e.formatterFunctions[s],{parsedParams:c,statusPayload:l}=jt(n.status,t),{sid:p,bid:u,previews:d,query:S}=c;Object.keys(l).length&&r(ze.setStatus(l));let h={...lr(d),locale:s,...ur()},A={variables:h,query:S,locale:s},f=n.records.entities.section[p],k=async C=>r(Nr(C));try{let C=await cr(i,f&&[f],u,a,A,void 0,k),{variables:w,status:b}=C;r(zt.setVariableChange({attributes:h,variables:w,status:b}));}catch(C){console.log("Error in runConsumers client side: recalculateVariables",C);}}}function Nn(e){return async(t,r,o)=>{let n=await o.readMetadata(e);if("error"in n)throw new Error(n.error);return n.data}}function Mn(e){return async(t,r,o)=>{let n=await o.urlProxy({url:e});if("error"in n)throw new Error(n.error);return n.data}}function Dn(){return async(e,t,r)=>{let o=await r.searchRole("");if("error"in o)throw new Error(o.error);return o.data}}function Un(e){return async(t,r,o)=>{let n=await o.searchUser(e);if("error"in n)throw new Error(n.error);return n.data}}function Fn(e){return async(t,r,o)=>{let n=await o.readUser({user_id:e});if("error"in n)throw new Error(n.error);return n.data}}function qn({user:e}){return async(t,r,o)=>{let n=await o.updateUser(e);if("error"in n)throw new Error(n.error);return n.data}}function $n(e){return async(t,r,o)=>{let n=await o.updateMyData(e);if("error"in n)throw new Error(n.error);return n.data}}function Vn(e){let{removeBlocks:t}=oe.actions;return async r=>{await r(t(e));}}function jn(e){let{addBlocks:t}=oe.actions;return async r=>{await r(t(e));}}function zn(e){return async(t,r,o)=>{let n=await o.readPrivateBlocks({...e,roles:[]});if("error"in n)throw new Error(n.error);return n.data}}function Gn(e){return async(t,r,o)=>{let n=await o.revalidateUrl({target:e.target});if("error"in n)throw new Error(n.error);return n.data}}function Hn(e){return async(t,r,o)=>{let n=await o.revalidateReport({reportId:e.reportId,profilePrefix:e.profilePrefix});if("error"in n)throw new Error(n.error);return n.data}}var {locales:Yn}=Z(),Wn={pathSegment:"path",formatterFunctions:Yn.reduce((e,t)=>({...e,[t]:{}}),{}),profilePrefix:"path",siteProps:{}};createContext(Wn);Z();var tt=useDispatch,rt=useSelector;
|
|
29
|
+
`)}));}let N=await Promise.all(T).catch(I=>I.message);if(typeof N=="string"&&N)return {outputVariables:{},renderVariables:{},status:{error:N}};c=N.length===1?N[0].data:N.map(I=>I.data),u=N.reduce((I,V)=>I+JSON.stringify(V.data).length/1024,0),p=Math.max(...N.map(I=>I.requestDuration));}if(e.type===E.SELECTOR){let{config:b,log:T,error:N}=pt(e.id,e.contentByLocale[n].content.logic,t,r,!0);return {outputVariables:Zt(e.id,i,b),renderVariables:b,status:{log:T,error:N,allowed:a}}}if(e.type===E.MULTIHIERARCHY_SELECTOR){let{config:b,log:T,error:N}=ft(e.id,e.contentByLocale[n].content.logic,t,r,!0);return {outputVariables:Jt(e.id,i,b),renderVariables:b,status:{log:T,error:N,allowed:a}}}if(e.type===E.VIZ)return {outputVariables:{},renderVariables:e.contentByLocale.logic.content,status:{log:[],allowed:a}};if(e.type===E.RELATED){let b=e.contentByLocale?.logic?.content?.simple?.compare||"variant",T=e.contentByLocale?.logic?.content?.simple?.limit||4,N=Object.keys(s).filter(m=>m.startsWith("report_id")).map(m=>s[m]),I=Object.keys(s).filter(m=>m.startsWith("dimension_id")).map(m=>s[m]),V=Object.keys(s).filter(m=>m.startsWith("variant_id")).map(m=>s[m]),Q=Object.keys(s).filter(m=>m.startsWith("id")).map(m=>s[m]);if(!Q.length)return {outputVariables:{related_reports:[]},renderVariables:{},status:{log:[],allowed:!1}};let X=await Promise.all(Q.map((m,M)=>o({mode:"ids",locale:n,ids:[m],output:"lite",variant:[V[M]]}))).then(m=>m.flatMap(M=>{let v=[];return Ye(M)?M.ok&&(v=M.data.results):v=M.results,v&&Array.isArray(v)?v:[]})).catch(m=>(console.log("Error getting related members",m),[]));if(I.length>1){let m=Object.keys(s).filter(_=>_.startsWith("variant_slug")).map(_=>s[_]),M=X.map((_,B)=>{let k={mode:"related",locale:n,related:T??4,current_ids:[_.content_id],output:"full",variant_ids:[_.variant_id]};return B===0&&(k.include_ids=[_.content_id]),k}),v=await Promise.all(M.map(_=>o(_))).then(_=>_.flatMap(B=>{let k=[];return Ye(B)?B.ok&&(k=B.data.results):k=B.results,k&&Array.isArray(k)?k:[]})).catch(_=>(console.log("Error getting related members",_),[])),q=v.reduce((_,B)=>{let k=B.variant_slug;return _[k]||(_[k]=[]),_[k].push(B),_},{}),z=[],ee=Object.keys(q),te=[{combination:[],index:0}];for(;te.length>0;){let _=te.pop();if(!_)continue;let{combination:B,index:k}=_;if(k===ee.length){z.push(B);continue}let ot=ee[k],zr=q[ot];for(let Gr of zr)te.push({combination:[...B,Gr],index:k+1});}return {outputVariables:{related_reports:z.map(_=>{let B=_.sort((k,ot)=>m.indexOf(k.variant_slug)-m.indexOf(ot.variant_slug));return {entities:B,link:"/"+B.map(k=>`${k.variant_slug}/${k.slug}`).join("/")}})},renderVariables:{},status:{log:[],allowed:v.length>0}}}let C=X.map(m=>m.content_id),L={mode:"related",locale:n,related:T??4,current_ids:C,output:"full"};b&&(b==="report"?L.report_ids=N:b==="dimension"?L.dimension_ids=I:L.variant_ids=V);let U=await o(L).then(m=>{let M=[];return Ye(m)?m.ok&&(M=m.data.results):M=m.results,M&&Array.isArray(M)?M:[]}).catch(m=>(console.log("Error getting related members",m),[]));return {outputVariables:{related_reports:U.map(m=>({entities:[m],link:`/${m.variant_slug}/${m.slug}`}))},renderVariables:{},status:{log:[],allowed:U.length>0}}}let{logic:S}=er(e,n),h=Se(S,t,r),A=ce("resp",c||{},h,t,s,r),{vars:f,error:x,log:P}=A;if(typeof f!="object")return {outputVariables:{},renderVariables:{},status:{error:"Configuration did not return an object",log:P,duration:p,responseSize:u,resp:c,api:d,allowed:a}};let w=Object.keys(f).reduce((b,T)=>({...b,[`${e.type}${e.id}${T}`]:f[T]}),{});return {renderVariables:f,outputVariables:[E.GENERATOR,E.SECTION_FLAG].includes(e.type)?f:w,status:{log:P,error:x,duration:p,responseSize:u,resp:c,api:d,allowed:a}}}function rn(e,t,r,o,n,s,i){return e.consumers.forEach(a=>{if(t[a]){let c=`${r}-${a}`;!o.includes(c)&&(t[a].section_id===t[r].section_id||!n)&&o.push(c),e.consumers.filter(l=>t[l].section_id===t[r].section_id||!n).forEach(l=>Rt(l,t,o,!1,s,n,i));}})}var Rt=(e,t,r=[],o=!0,n=!0,s=!0,i=[])=>{if(i.includes(e))return [];i.push(e);let a=t[e];return a&&a.inputs.length&&o&&a.inputs.forEach(c=>{let l=`${c}-${e}`;r.includes(l)||r.push(l),a.inputs.forEach(p=>Rt(p,t,r,o,!1,s,i));}),a&&a.consumers.length&&n&&rn(a,t,e,r,s,n,i),r},on=(e,t,r,o)=>{let n=!0;if(e&&"allowed"in e.settings&&e.settings.allowed!=="always")if(e.settings.allowed==="never")n=!1;else {let s=K(t),{error:i,output:a}=ce("variables",r,e.settings.allowedLogic||"return false;",o,void 0,s);i||(n=!!a);}return n},cr=async(e,t,r,o,n,s={},i,a="section")=>{let c=a==="section",l=K(n),p=l.variables,u={...s.variables??{}},d={...s.status??{}},S=new Set,h=[],A={};r?A={...A,[r]:e[r]}:t?A=(t??[]).reduce((C,{id:L})=>({...C,...tr(L,e)}),{}):A=Object.values(e).filter(C=>mt(C)).reduce((C,L)=>({...C,[L.id]:L}),{});let f=Object.values(A).filter(C=>mt(C));if(f.length>0){le&&console.log("%crunConsumers: calculating section flags","color:purple",f.map(g=>g.id).join(", "));let C=Object.fromEntries(await Promise.all(f.map(async g=>[g.id,await ir(g,o,{...l,variables:p,locale:p.locale},i).then(m=>{let{outputVariables:M,status:v}=m;if(v.error){if(typeof window>"u")throw new Error(`Run consumers (Block: ${g.id}, Section ${g.section_id}) failed with message: ${v.error}. `);d[g.id]={allowed:!1,error:v.error},u[g.id]={};}return (g.consumers.length>0||[E.GENERATOR,E.SECTION_FLAG,E.RELATED].includes(g.type))&&v.allowed&&Object.keys(M).length>0?u[g.id]=M:u[g.id]={},a==="report"?(d[g.id]={allowed:v.allowed},[E.GENERATOR,E.SECTION_FLAG].includes(g.type)&&v.api&&(d[g.id].api=v.api)):d[g.id]=v,m})]))),U=Object.entries(C).filter(([g,m])=>!m.outputVariables[nr]).map(([g])=>Number(g));S=new Set(U.map(g=>e[g].section_id)),Object.values(A).filter(g=>S.has(g.section_id)).forEach(g=>{h.push(g.id),delete A[g.id];}),le&&console.log("%crunConsumers: removing sections","color:purple",S.keys());}let x=S.size>0?Object.fromEntries(Object.entries(e).filter(([C,L])=>S?.has(L.section_id)?(h.includes(L.id)||h.push(L.id),!1):!0)):e;if(h.length>0&&(x=Object.fromEntries(Object.entries(x).map(([C,L])=>{let U={...L,inputs:L.inputs.filter(g=>!h.includes(g)),consumers:L.consumers.filter(g=>!h.includes(g))};return [C,U]}))),!r&&!t)return {variables:{...s.variables??{},...u},status:{...s.status??{},...d}};a==="report"&&h.length>0&&h.forEach(C=>{delete u[C],delete d[C],delete e[C];}),le&&console.log("%crunConsumers: running root blocks","color:purple",Object.keys(A));let P=Object.keys(A).reduce((C,L)=>{let U=new Date,g=Rt(Number(L),x,[],!r,!0,c).map(v=>v.split("-")),M=(new Date().getTime()-U.getTime())/1e3;return le&&console.log(`%cResolved dependencies for ${L} (${M.toFixed(2)}s)`,"color:blue"),[...C,...g]},[]),w=new Date,b=Object.keys(A).reduce((C,L)=>C.includes(L)?[...C]:[L,...C],Yo(P)),N=(new Date().getTime()-w.getTime())/1e3;le&&console.log(`%cResolved DAG (${N.toFixed(2)}s): `,"color:green",b);async function I(C,L){let U=new Map;for(let g of C){let m=L[g],v=Promise.all(m.inputs.filter(q=>C.includes(String(q))).map(q=>U.get(Number(q)))).then(async()=>{let q=m.inputs.reduce((B,k)=>({...B,...u[k]}),p),z=m.inputs.find(B=>(m.settings?.ignoreCascade?m.settings?.ignoreCascade:[]).includes(B)||!d[B]?!1:!d[B].allowed||d[B].hiddenByCascade);if(z){d[g]={allowed:!1,hiddenByCascade:d[z].hiddenByCascade||z},u[g]={};return}let ee=new Date,te=await ir(m,o,{...l,variables:q,locale:q.locale},i).then(({outputVariables:B,status:k})=>{if(k.error){if(typeof window>"u")throw new Error(`Run consumers (Block: ${g}, Section ${m.section_id}) failed with message: ${k.error}. `);d[g]={allowed:!1,error:k.error},u[g]={};}(m.consumers.length>0||[E.GENERATOR,E.SECTION_FLAG,E.RELATED].includes(m.type))&&k.allowed&&Object.keys(B).length>0?u[g]=B:u[g]={},a==="report"?(d[g]={allowed:k.allowed},[E.GENERATOR,E.SECTION_FLAG].includes(m.type)&&k.api&&(d[g].api=k.api)):d[g]=k;}),_=(new Date().getTime()-ee.getTime())/1e3;return le&&console.log(`%cBlock ${m.id} resolved in ${_.toFixed(3)}s`,_>500?"color:red":"color:green"),te});U.set(Number(g),v);}await Promise.all(Array.from(U.values()));}let V=new Date;await I(b,x);let X=(new Date().getTime()-V.getTime())/1e3;return le&&console.log(`%cResolved Variables (${X.toFixed(2)}s): `,"color:green"),{variables:{...s.variables??{},...u},status:{...s.status??{},...d}}};function nn(e=[]){return e.reduce((t,r,o)=>{if(r){let n=o+1;t[`id${n}`]=r.id,t[`name${n}`]=r.name,t[`slug${n}`]=r.slug,"attributes"in r&&Object.keys(r.attributes).forEach(s=>{t[`attr_${s}${n}`]=r.attributes[s];}),t[`variant_id${n}`]=r.variant_id,t[`variant_name${n}`]=r.variant_name,t[`variant_slug${n}`]=r.variant_slug,t[`dimension_id${n}`]=r.dimension_id,t[`dimension_name${n}`]=r.dimension_name,t.report_id=r.report_id,t.report_name=r.report_name;}return t},{})}var lr=nn;function an(){let{publicRuntimeConfig:e}=sn(),t=e.bespoke_report_env_vars||{};return {...Object.keys(t).reduce((r,o)=>(r[`ENV_${o}`]=t[o]||"N/A",r),{})}}var ur=an;function ue(e,t,r){if(t==="createBulk"||t==="updateBulk"){let n=`${t}${pr(r)}`;return e[n]}let o=`${t}${pr(r)}`;return e[o]}function pr(e){return e[0].toUpperCase()+e.slice(1)}function j(e){for(var t=arguments.length,r=Array(t>1?t-1:0),o=1;o<t;o++)r[o-1]=arguments[o];if(process.env.NODE_ENV!=="production"){var n=yn[e],s=n?typeof n=="function"?n.apply(null,r):n:"unknown error nr: "+e;throw Error("[Immer] "+s)}throw Error("[Immer] minified error nr: "+e+(r.length?" "+r.map(function(i){return "'"+i+"'"}).join(","):"")+". Find the full error at: https://bit.ly/3cXEKWf")}function be(e){return !!e&&!!e[G]}function de(e){var t;return !!e&&(function(r){if(!r||typeof r!="object")return !1;var o=Object.getPrototypeOf(r);if(o===null)return !0;var n=Object.hasOwnProperty.call(o,"constructor")&&o.constructor;return n===Object||typeof n=="function"&&Function.toString.call(n)===Rn}(e)||Array.isArray(e)||!!e[Er]||!!(!((t=e.constructor)===null||t===void 0)&&t[Er])||xt(e)||Ct(e))}function Ne(e,t,r){r===void 0&&(r=!1),ve(e)===0?(r?Object.keys:It)(e).forEach(function(o){r&&typeof o=="symbol"||t(o,e[o],e);}):e.forEach(function(o,n){return t(n,o,e)});}function ve(e){var t=e[G];return t?t.i>3?t.i-4:t.i:Array.isArray(e)?1:xt(e)?2:Ct(e)?3:0}function St(e,t){return ve(e)===2?e.has(t):Object.prototype.hasOwnProperty.call(e,t)}function cn(e,t){return ve(e)===2?e.get(t):e[t]}function Tr(e,t,r){var o=ve(e);o===2?e.set(t,r):o===3?e.add(r):e[t]=r;}function ln(e,t){return e===t?e!==0||1/e==1/t:e!=e&&t!=t}function xt(e){return fn&&e instanceof Map}function Ct(e){return mn&&e instanceof Set}function pe(e){return e.o||e.t}function Pt(e){if(Array.isArray(e))return Array.prototype.slice.call(e);var t=gn(e);delete t[G];for(var r=It(t),o=0;o<r.length;o++){var n=r[o],s=t[n];s.writable===!1&&(s.writable=!0,s.configurable=!0),(s.get||s.set)&&(t[n]={configurable:!0,writable:!0,enumerable:s.enumerable,value:e[n]});}return Object.create(Object.getPrototypeOf(e),t)}function Lt(e,t){return t===void 0&&(t=!1),_t(e)||be(e)||!de(e)||(ve(e)>1&&(e.set=e.add=e.clear=e.delete=un),Object.freeze(e),t&&Ne(e,function(r,o){return Lt(o,!0)},!0)),e}function un(){j(2);}function _t(e){return e==null||typeof e!="object"||Object.isFrozen(e)}function J(e){var t=hn[e];return t||j(18,e),t}function dr(){return process.env.NODE_ENV==="production"||Ae||j(0),Ae}function gt(e,t){t&&(J("Patches"),e.u=[],e.s=[],e.v=t);}function Qe(e){bt(e),e.p.forEach(pn),e.p=null;}function bt(e){e===Ae&&(Ae=e.l);}function fr(e){return Ae={p:[],l:Ae,h:e,m:!0,_:0}}function pn(e){var t=e[G];t.i===0||t.i===1?t.j():t.g=!0;}function ht(e,t){t._=t.p.length;var r=t.p[0],o=e!==void 0&&e!==r;return t.h.O||J("ES5").S(t,e,o),o?(r[G].P&&(Qe(t),j(4)),de(e)&&(e=Ze(t,e),t.l||Je(t,e)),t.u&&J("Patches").M(r[G].t,e,t.u,t.s)):e=Ze(t,r,[]),Qe(t),t.u&&t.v(t.u,t.s),e!==Sr?e:void 0}function Ze(e,t,r){if(_t(t))return t;var o=t[G];if(!o)return Ne(t,function(a,c){return mr(e,o,t,a,c,r)},!0),t;if(o.A!==e)return t;if(!o.P)return Je(e,o.t,!0),o.t;if(!o.I){o.I=!0,o.A._--;var n=o.i===4||o.i===5?o.o=Pt(o.k):o.o,s=n,i=!1;o.i===3&&(s=new Set(n),n.clear(),i=!0),Ne(s,function(a,c){return mr(e,o,n,a,c,r,i)}),Je(e,n,!1),r&&e.u&&J("Patches").N(o,r,e.u,e.s);}return o.o}function mr(e,t,r,o,n,s,i){if(process.env.NODE_ENV!=="production"&&n===r&&j(5),be(n)){var a=Ze(e,n,s&&t&&t.i!==3&&!St(t.R,o)?s.concat(o):void 0);if(Tr(r,o,a),!be(a))return;e.m=!1;}else i&&r.add(n);if(de(n)&&!_t(n)){if(!e.h.D&&e._<1)return;Ze(e,n),t&&t.A.l||Je(e,n);}}function Je(e,t,r){r===void 0&&(r=!1),!e.l&&e.h.D&&e.m&&Lt(t,r);}function Et(e,t){var r=e[G];return (r?pe(r):e)[t]}function yr(e,t){if(t in e)for(var r=Object.getPrototypeOf(e);r;){var o=Object.getOwnPropertyDescriptor(r,t);if(o)return o;r=Object.getPrototypeOf(r);}}function At(e){e.P||(e.P=!0,e.l&&At(e.l));}function Tt(e){e.o||(e.o=Pt(e.t));}function vt(e,t,r){var o=xt(t)?J("MapSet").F(t,r):Ct(t)?J("MapSet").T(t,r):e.O?function(n,s){var i=Array.isArray(n),a={i:i?1:0,A:s?s.A:dr(),P:!1,I:!1,R:{},l:s,t:n,k:null,o:null,j:null,C:!1},c=a,l=kt;i&&(c=[a],l=we);var p=Proxy.revocable(c,l),u=p.revoke,d=p.proxy;return a.k=d,a.j=u,d}(t,r):J("ES5").J(t,r);return (r?r.A:dr()).p.push(o),o}function dn(e){return be(e)||j(22,e),function t(r){if(!de(r))return r;var o,n=r[G],s=ve(r);if(n){if(!n.P&&(n.i<4||!J("ES5").K(n)))return n.t;n.I=!0,o=Rr(r,s),n.I=!1;}else o=Rr(r,s);return Ne(o,function(i,a){n&&cn(n.t,i)===a||Tr(o,i,t(a));}),s===3?new Set(o):o}(e)}function Rr(e,t){switch(t){case 2:return new Map(e);case 3:return Array.from(e)}return Pt(e)}var gr,Ae,Ot=typeof Symbol<"u"&&typeof Symbol("x")=="symbol",fn=typeof Map<"u",mn=typeof Set<"u",hr=typeof Proxy<"u"&&Proxy.revocable!==void 0&&typeof Reflect<"u",Sr=Ot?Symbol.for("immer-nothing"):((gr={})["immer-nothing"]=!0,gr),Er=Ot?Symbol.for("immer-draftable"):"__$immer_draftable",G=Ot?Symbol.for("immer-state"):"__$immer_state";var yn={0:"Illegal state",1:"Immer drafts cannot have computed properties",2:"This object has been frozen and should not be mutated",3:function(e){return "Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? "+e},4:"An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.",5:"Immer forbids circular references",6:"The first or second argument to `produce` must be a function",7:"The third argument to `produce` must be a function or undefined",8:"First argument to `createDraft` must be a plain object, an array, or an immerable object",9:"First argument to `finishDraft` must be a draft returned by `createDraft`",10:"The given draft is already finalized",11:"Object.defineProperty() cannot be used on an Immer draft",12:"Object.setPrototypeOf() cannot be used on an Immer draft",13:"Immer only supports deleting array indices",14:"Immer only supports setting array indices and the 'length' property",15:function(e){return "Cannot apply patch, path doesn't resolve: "+e},16:'Sets cannot have "replace" patches.',17:function(e){return "Unsupported patch operation: "+e},18:function(e){return "The plugin for '"+e+"' has not been loaded into Immer. To enable the plugin, import and call `enable"+e+"()` when initializing your application."},20:"Cannot use proxies if Proxy, Proxy.revocable or Reflect are not available",21:function(e){return "produce can only be called on things that are draftable: plain objects, arrays, Map, Set or classes that are marked with '[immerable]: true'. Got '"+e+"'"},22:function(e){return "'current' expects a draft, got: "+e},23:function(e){return "'original' expects a draft, got: "+e},24:"Patching reserved attributes like __proto__, prototype and constructor is not allowed"},Rn=""+Object.prototype.constructor,It=typeof Reflect<"u"&&Reflect.ownKeys?Reflect.ownKeys:Object.getOwnPropertySymbols!==void 0?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:Object.getOwnPropertyNames,gn=Object.getOwnPropertyDescriptors||function(e){var t={};return It(e).forEach(function(r){t[r]=Object.getOwnPropertyDescriptor(e,r);}),t},hn={},kt={get:function(e,t){if(t===G)return e;var r=pe(e);if(!St(r,t))return function(n,s,i){var a,c=yr(s,i);return c?"value"in c?c.value:(a=c.get)===null||a===void 0?void 0:a.call(n.k):void 0}(e,r,t);var o=r[t];return e.I||!de(o)?o:o===Et(e.t,t)?(Tt(e),e.o[t]=vt(e.A.h,o,e)):o},has:function(e,t){return t in pe(e)},ownKeys:function(e){return Reflect.ownKeys(pe(e))},set:function(e,t,r){var o=yr(pe(e),t);if(o?.set)return o.set.call(e.k,r),!0;if(!e.P){var n=Et(pe(e),t),s=n?.[G];if(s&&s.t===r)return e.o[t]=r,e.R[t]=!1,!0;if(ln(r,n)&&(r!==void 0||St(e.t,t)))return !0;Tt(e),At(e);}return e.o[t]===r&&(r!==void 0||t in e.o)||Number.isNaN(r)&&Number.isNaN(e.o[t])||(e.o[t]=r,e.R[t]=!0),!0},deleteProperty:function(e,t){return Et(e.t,t)!==void 0||t in e.t?(e.R[t]=!1,Tt(e),At(e)):delete e.R[t],e.o&&delete e.o[t],!0},getOwnPropertyDescriptor:function(e,t){var r=pe(e),o=Reflect.getOwnPropertyDescriptor(r,t);return o&&{writable:!0,configurable:e.i!==1||t!=="length",enumerable:o.enumerable,value:r[t]}},defineProperty:function(){j(11);},getPrototypeOf:function(e){return Object.getPrototypeOf(e.t)},setPrototypeOf:function(){j(12);}},we={};Ne(kt,function(e,t){we[e]=function(){return arguments[0]=arguments[0][0],t.apply(this,arguments)};}),we.deleteProperty=function(e,t){return process.env.NODE_ENV!=="production"&&isNaN(parseInt(t))&&j(13),we.set.call(this,e,t,void 0)},we.set=function(e,t,r){return process.env.NODE_ENV!=="production"&&t!=="length"&&isNaN(parseInt(t))&&j(14),kt.set.call(this,e[0],t,r,e[0])};var En=function(){function e(r){var o=this;this.O=hr,this.D=!0,this.produce=function(n,s,i){if(typeof n=="function"&&typeof s!="function"){var a=s;s=n;var c=o;return function(A){var f=this;A===void 0&&(A=a);for(var x=arguments.length,P=Array(x>1?x-1:0),w=1;w<x;w++)P[w-1]=arguments[w];return c.produce(A,function(b){var T;return (T=s).call.apply(T,[f,b].concat(P))})}}var l;if(typeof s!="function"&&j(6),i!==void 0&&typeof i!="function"&&j(7),de(n)){var p=fr(o),u=vt(o,n,void 0),d=!0;try{l=s(u),d=!1;}finally{d?Qe(p):bt(p);}return typeof Promise<"u"&&l instanceof Promise?l.then(function(A){return gt(p,i),ht(A,p)},function(A){throw Qe(p),A}):(gt(p,i),ht(l,p))}if(!n||typeof n!="object"){if((l=s(n))===void 0&&(l=n),l===Sr&&(l=void 0),o.D&&Lt(l,!0),i){var S=[],h=[];J("Patches").M(n,l,S,h),i(S,h);}return l}j(21,n);},this.produceWithPatches=function(n,s){if(typeof n=="function")return function(l){for(var p=arguments.length,u=Array(p>1?p-1:0),d=1;d<p;d++)u[d-1]=arguments[d];return o.produceWithPatches(l,function(S){return n.apply(void 0,[S].concat(u))})};var i,a,c=o.produce(n,s,function(l,p){i=l,a=p;});return typeof Promise<"u"&&c instanceof Promise?c.then(function(l){return [l,i,a]}):[c,i,a]},typeof r?.useProxies=="boolean"&&this.setUseProxies(r.useProxies),typeof r?.autoFreeze=="boolean"&&this.setAutoFreeze(r.autoFreeze);}var t=e.prototype;return t.createDraft=function(r){de(r)||j(8),be(r)&&(r=dn(r));var o=fr(this),n=vt(this,r,void 0);return n[G].C=!0,bt(o),n},t.finishDraft=function(r,o){var n=r&&r[G];process.env.NODE_ENV!=="production"&&(n&&n.C||j(9),n.I&&j(10));var s=n.A;return gt(s,o),ht(void 0,s)},t.setAutoFreeze=function(r){this.D=r;},t.setUseProxies=function(r){r&&!hr&&j(20),this.O=r;},t.applyPatches=function(r,o){var n;for(n=o.length-1;n>=0;n--){var s=o[n];if(s.path.length===0&&s.op==="replace"){r=s.value;break}}n>-1&&(o=o.slice(n+1));var i=J("Patches").$;return be(r)?i(r,o):this.produce(r,function(a){return i(a,o)})},e}(),H=new En,Tn=H.produce;H.produceWithPatches.bind(H);H.setAutoFreeze.bind(H);H.setUseProxies.bind(H);H.applyPatches.bind(H);H.createDraft.bind(H);H.finishDraft.bind(H);var Xe=Tn;var W=oe.actions,kr=De({block:fe("block"),dimension:fe("dimension"),formatter:fe("formatter"),report:fe("report"),section:fe("section"),variant:fe("variant")}),Me=De({block:me("block"),dimension:me("dimension"),formatter:me("formatter"),report:me("report"),section:me("section"),variant:me("variant")}),xr=De({block:re("block"),dimension:re("dimension"),formatter:re("formatter"),report:re("report"),section:re("section"),variant:re("variant")}),Cr=De({block:ke("block"),dimension:ke("dimension"),formatter:ke("formatter"),report:ke("report"),section:ke("section"),variant:ke("variant")}),Pr=De({block:Ar("block"),section:Ar("section")});function De(e){return (t,r)=>{let o=e[t];if(!o)throw new Error(`Attempting to dispatch action for invalid entity type '${t}'`);return o(r)}}function ye(e,t){return (r,o)=>{let s=o().records.requests[e][t],i=!s||s.status==="UNINITIALIZED"?"LOADING":"FETCHING";r(W.setRequest({key:t,type:e,status:i}));}}function xe(e,t,r,o){return n=>{typeof window=="object"&¬ifications.show({autoClose:3e3,color:"red",id:t,message:o,title:"Error"}),n(W.setRequest({key:t,type:e,status:"FAILURE",error:{code:r,message:o}}));}}function fe(e){return t=>{let r=wt(e,t);return (o,n,s)=>(o(ye(e,r)),ue(s,"create",e)(t).then(a=>(a.ok===!0?o(W.setCreateRequest({key:r,operation:"create",status:"SUCCESS",type:e,data:a.data})):o(xe(e,r,a.status,a.error)),a)))}}function An(e){return t=>{let r=wt(e,t[0]);return (o,n,s)=>(o(ye(e,r)),ue(s,"createBulk",e)(t).then(a=>(a.ok===!0?o(W.setCreateRequest({key:r,operation:"createBulk",status:"SUCCESS",type:e,data:a.data})):o(xe(e,r,a.status,a.error)),a)))}}function br(e,t,r){return r.replace(new RegExp(e,"g"),t)}function vn(e){return e.section_id!==void 0}function kn(e){return e.report_id!==void 0}function Ar(e){return t=>{let{create:r}=t;return (o,n,s)=>fe(e)(r)(o,n,s).then(async a=>{if(a.ok){let{data:c}=a,{id:l}=c,{update:p}=t,u=Or(e,{id:l});if(o(ye(e,`${u}`)),e==="block"&&vn(r)){let d=Xe(p,f=>{f.id=l;}),{contentByLocale:S}=d;S&&(d=Xe(d,f=>{f.id=l,f.contentByLocale=Object.keys(S).reduce((x,P)=>{let w=S?S[P]:{};return x[P]={...w,id:l},x},{});}));let A=d.inputs?.map(f=>({type:f.type,id:f.id,inputAction:{operation:"create",input:{input_id:f.id,block_id:d.id}}}));return A&&A.length>0&&vr(e)([d,...A])(o,n,s).then(()=>me("section")({id:d.section_id,include:!0})(o,n,s).then(f=>(f.ok&&o(W.setRequest({key:u,type:e,status:"SUCCESS",data:f.data})),f))),re(e)(d)(o,n,s).then(f=>(f.ok&&o(W.setRequest({key:u,type:e,status:"SUCCESS",data:f.data})),f))}if(e==="section"&&kn(r)){let{id:d}=c,S=Xe(p,f=>{f.id=d;}),{blocks:h}=S,A=h?.map(f=>({type:f.type,blockcol:f.blockcol,blockrow:f.blockrow,section_id:d,locales:Object.keys(f.contentByLocale).map(x=>x)}));return A&&h&&await An("block")(A)(o,n,s).then(f=>{if(f.ok){let x=f.data,P=[],w=x.map((b,T)=>{let I={...b},V=I.id,Q=h[T];Q.contentByLocale&&(I.contentByLocale=Object.keys(Q.contentByLocale).reduce((v,q)=>{let z=Q.contentByLocale[q];return v[q]={...z,content:{...z.content},id:I.id},v},{}));let{settings:X}=Q,{contentByLocale:C,id:L}=I;I.settings=X;let U={id:L,contentByLocale:C,settings:X};return Q.inputs.map(v=>v.id).reduce((v,q)=>{let z=h.findIndex(ee=>ee.id===q);return [...v,z]},[]).map(v=>({...x[v],originalBlock:h[v]})).forEach(v=>{let{id:q,type:z,originalBlock:ee}=v;if([E.SELECTOR,E.VIZ].includes(z)){if(U.contentByLocale?.logic?.content?.api){let te=U.contentByLocale?.logic.content.api;U.contentByLocale.logic.content.api=br(`(selector${ee.id}id)`,`selector${q}id`,te);}if(U.contentByLocale?.logic?.content?.logic){let te=U.contentByLocale.logic.content.logic;U.contentByLocale.logic.content.logic=br(`(selector${ee.id}id)`,`selector${q}id`,te);}}P.push({id:q,inputAction:{operation:"create",input:{input_id:q,block_id:V}}});}),U});return vr("block")([...w,...P])(o,n,s)}}),re(e)(S)(o,n,s).then(f=>(f.ok&&o(W.setRequest({key:u,type:e,status:"SUCCESS",data:f.data})),f))}return re(e)({...p,id:c.id})(o,n,s)}})}}function me(e){return t=>{let r=Lr(e,t);return (o,n,s)=>(o(ye(e,r)),ue(s,"read",e)(t).then(a=>(a.ok===!0?o(W.setReadRequest({key:r,operation:"read",status:"SUCCESS",type:e,data:a.data})):o(xe(e,r,a.status,a.error)),a)))}}function re(e){return t=>{let r=Nt(e,t);return (o,n,s)=>(o(ye(e,r)),ue(s,"update",e)(t).then(a=>(a.ok===!0?o(W.setUpdateRequest({key:r,operation:"update",status:"SUCCESS",type:e,data:a.data})):o(xe(e,r,a.status,a.error)),a)))}}function vr(e){return t=>{let r=Nt(e,t[0]);return (o,n,s)=>(o(ye(e,r)),ue(s,"updateBulk",e)(t).then(a=>(a.ok===!0?o(W.setUpdateRequest({key:r,operation:"updateBulk",status:"SUCCESS",type:e,data:a.data})):o(xe(e,r,a.status,a.error)),a)))}}function ke(e){return t=>{let r=_r(e,t);return (o,n,s)=>(o(ye(e,r)),ue(s,"delete",e)(t).then(a=>{a.ok===!0?o(W.setDeleteRequest({key:r,operation:"delete",status:"SUCCESS",type:e,data:a.data})):o(xe(e,r,a.status,a.error));}))}}function wt(e,t){if(e==="variant"){let r=t;return `create(variant, [${r.dimension_id}, ${r.name}])`}return `create(${e}, [${Object.keys(t)}])`}function Lr(e,t={}){let r=t.id==null?null:`'${t.id}'`;return `read(${e}, ${r}, ${!!t.include})`}function Nt(e,t){let{id:r,...o}=t;return `update(${e}, ${r}, [${Object.keys(o)}])`}function _r(e,t){return `delete(${e}, ${t})`}function Or(e,t){let r=t.id==null?null:`'${t.id}'`;return `clone(${e}, ${r})`}var{setStatus:Ir,setPreviews:xn,setSectionState:Br,resetSectionState:wr,setCurrentLocale:Cn,setPreferredLocale:Pn}=ze;function Ln(e,t){return async(r,o,n)=>{let s=await n.validateVariantSlug({dimension:e,slug:t});if("error"in s)throw new Error(s.error);return s.data}}function _n(e){return async(t,r,o)=>{let n=await o.searchReport(e);if("error"in n)throw new Error(n.error);return n.data}}function On(){return async(e,t,r)=>{let o=await r.regenerateSearch(void 0);if("error"in o)throw new Error(o.error);return o.data}}function Nr(e){return async(t,r,o)=>{let n=await o.readMember(e);if("error"in n)throw new Error(n.error);return n.data}}function In(e){return async(t,r,o)=>{let n=await o.searchMember(e);if(n.ok===!0)return n.data;throw new Error(n.error)}}async function Mr(e,t,r,o){let n=r().status,s={...n,...o},i={...n.query,...o.query};Object.keys(i).forEach(c=>i[c]===void 0&&delete i[c]);let a={...s,query:i};t(Ir(a)),n.activeSection&&t(Dr(e,{query:i}));}function Bn(e,t){return async(r,o)=>Mr(e,r,o,{query:{[t]:void 0}})}function wn(e,t,r){return async(o,n)=>Mr(e,o,n,{query:{[t]:r}})}function Dr(e,t){return async(r,o)=>{let n=o(),{currentLocale:s}=n.status,i=n.records.entities.block,a=e.formatterFunctions[s],{parsedParams:c,statusPayload:l}=jt(n.status,t),{sid:p,bid:u,previews:d,query:S}=c;Object.keys(l).length&&r(ze.setStatus(l));let h={...lr(d),locale:s,...ur()},A={variables:h,query:S,locale:s},f=n.records.entities.section[p],x=async P=>r(Nr(P));try{let P=await cr(i,f&&[f],u,a,A,void 0,x),{variables:w,status:b}=P;r(zt.setVariableChange({attributes:h,variables:w,status:b}));}catch(P){console.log("Error in runConsumers client side: recalculateVariables",P);}}}function Nn(e){return async(t,r,o)=>{let n=await o.readMetadata(e);if("error"in n)throw new Error(n.error);return n.data}}function Mn(e){return async(t,r,o)=>{let n=await o.urlProxy({url:e});if("error"in n)throw new Error(n.error);return n.data}}function Dn(){return async(e,t,r)=>{let o=await r.searchRole("");if("error"in o)throw new Error(o.error);return o.data}}function Un(e){return async(t,r,o)=>{let n=await o.searchUser(e);if("error"in n)throw new Error(n.error);return n.data}}function Fn(e){return async(t,r,o)=>{let n=await o.readUser({user_id:e});if("error"in n)throw new Error(n.error);return n.data}}function qn({user:e}){return async(t,r,o)=>{let n=await o.updateUser(e);if("error"in n)throw new Error(n.error);return n.data}}function $n(e){return async(t,r,o)=>{let n=await o.updateMyData(e);if("error"in n)throw new Error(n.error);return n.data}}function Vn(e){let{removeBlocks:t}=oe.actions;return async r=>{await r(t(e));}}function jn(e){let{addBlocks:t}=oe.actions;return async r=>{await r(t(e));}}function zn(e){return async(t,r,o)=>{let n=await o.readPrivateBlocks({...e,roles:[]});if("error"in n)throw new Error(n.error);return n.data}}function Gn(e){return async(t,r,o)=>{let n=await o.revalidateUrl({target:e.target});if("error"in n)throw new Error(n.error);return n.data}}function Hn(e){return async(t,r,o)=>{let n=await o.revalidateReport({reportId:e.reportId,profilePrefix:e.profilePrefix});if("error"in n)throw new Error(n.error);return n.data}}var {locales:Yn}=Z(),Wn={pathSegment:"path",formatterFunctions:Yn.reduce((e,t)=>({...e,[t]:{}}),{}),profilePrefix:"path",siteProps:{}};createContext(Wn);Z();var tt=useDispatch,rt=useSelector;
|
|
30
30
|
|
|
31
31
|
export { et as actions, Ht as storeWrapper, tt as useBespokeDispatch, rt as useBespokeSelector };
|