@picked/client 0.0.32-next.1 → 0.0.32-next.2
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/cjs/index.js +1 -1
- package/dist/cjs/server/index.js +1 -1
- package/dist/esm/index.js +46 -46
- package/dist/esm/server/index.js +1 -1
- package/dist/{experience-instance-BmL4VkmP.js → experience-instance-Bg6BWuwI.js} +99 -87
- package/dist/experience-instance-DBi45xr9.cjs +1 -0
- package/dist/types/entities/predicate/predicate.d.ts +3 -1
- package/dist/types/entities/predicate/predicate.d.ts.map +1 -1
- package/dist/types/logic-engine.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/experience-instance-IpJwvfUH.cjs +0 -1
package/dist/cjs/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var q=Object.defineProperty;var K=(t,e,r)=>e in t?q(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var h=(t,e,r)=>K(t,typeof e!="symbol"?e+"":e,r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("effector"),v=require("@withease/factories"),b=require("../experience-instance-IpJwvfUH.cjs"),E=require("../logger-BsmHUUw1.cjs"),w=require("../storage-YlR83AWP.cjs"),W=require("../id-BKIWbSTy.cjs"),H=require("../object-BbFTsGh3.cjs"),k=require("../supports-YvpQZxbh.cjs"),L=g.createDomain("experience"),G=v.createFactory(({client:t,experience:e})=>{const r=L.store(e),n=g.createApi(r,{merge(a,f){return{...a,...f.experience}}}),s=r.map(a=>({name:a.name,decisionLogic:a.condition??a.decide,targetSelectors:a.targets,initializeOpenLogic:e.initializeOpen})),d=t.components.listStore.map(a=>a.find(f=>f.name===`experience:${e.id}`)||a.find(f=>f.name==="experience"),{skipVoid:!1}),o=r.map(a=>({steps:a.steps,nodes:a.nodes,edges:a.edges,conditionals:a.conditionals})),i=e.actions??[];return{id:e.id,configStore:s,treeStore:o,componentStore:d,actions:i,merge:n.merge}});function Y(t){return v.invoke(G,t)}const J=v.createFactory(({client:t})=>{const e=L.store({}),r=g.createApi(e,{register(o,i){return{...o,[i.id]:i}}});function n(o){const i=e.getState()[o.id];if(i){i.merge({experience:o,strategy:"override"});return}const a=Y({client:t,experience:o});r.register(a)}const s=e.map(o=>Object.values(o));function d(o){return e.map(i=>i[o],{skipVoid:!1})}return{register:n,getById:d,listStore:s}});function Q(t){return v.invoke(J,t)}const X=(t,e)=>{e.register(t)},V=(t,e)=>{const{targetSelectors:r}=e.configStore.getState(),n=b.getTargetElements(r,e.id);n.forEach(({elements:d})=>d.forEach(o=>b.tagTargetElement(o,e.id))),b.createAppHosts(n,e.id).forEach(d=>{t.experienceInstances.spawn(e,d)})},$=async t=>{await Promise.all(t.experiences.listStore.getState().map(async e=>{await Z(t,e)&&V(t,e)}))},Z=async(t,e)=>{const{decisionLogic:r,targetSelectors:n}=e.configStore.getState();return b.getTargetElements(n,e.id).length<1||n.length===0?!1:r&&b.isRulesLogic(r)?await b.evaluateRuleLogic(t,r)===!0:!0},ee=(t,e,r)=>{const n=e.name,s=e.setup(t);if(s){const d=r[n]??{};r[n]=Object.freeze({...d,...s})}},te=g.createDomain("component"),re=v.createFactory(({client:t,component:e,name:r})=>{const n=t.frameworks.getByName(e.frameworkName);return{name:r,component:e,frameworkStore:n}});function ne(t){return v.invoke(re,t)}const se=v.createFactory(({client:t})=>{const e=te.store({}),r=g.createApi(e,{register(o,i){return{...o,[i.name]:i}}});function n(o,i){e.getState()[o]&&E.logger("warn",`Component '${o}' already registered. Registering again will override the previous registration.`);const f=ne({client:t,name:o,component:i});r.register(f)}const s=e.map(o=>Object.values(o));function d(o){return e.map(i=>i[o],{skipVoid:!1})}return{register:n,getByName:d,listStore:s}});function ie(t){return v.invoke(se,t)}const C=(t,e,r)=>{r.register(t,e)},oe=g.createDomain("framework"),ae=v.createFactory(({client:t})=>{const e=oe.store({}),r=g.createApi(e,{register(o,i){return{...o,[i.name]:i.framework}}});function n(o,i){e.getState()[o]&&E.logger("warn",`Framework '${o}' already registered. Registering again will override the previous registration.`),r.register({name:o,framework:i})}const s=e.map(o=>Object.values(o));function d(o){return e.map(i=>i[o],{skipVoid:!1})}return{register:n,getByName:d,listStore:s}});function ce(t){return v.invoke(ae,t)}const ue=(t,e)=>{e.register(t.name,t)},de=6e3,le=w.createStorageKey("last_ping","global"),pe=t=>`${t}/api/v1/ping`,ge=async t=>{try{const e=Date.now(),r=w.localStore.get(le);let n=0;if(r.isSet()&&(n=r.json()??0),n&&e-n<de)return!0;const s=pe(t.apiUrl),d={projectId:t.projectId,path:window.location.pathname},o=JSON.stringify(d),i={"Content-Type":"application/json"},a=document.getElementById("picked_script"),f=a==null?void 0:a.dataset.verceltoken;f&&(i["x-vercel-protection-bypass"]=f);const F=(await fetch(s,{method:"POST",headers:i,body:o})).ok;return F&&r.set(e),F}catch(e){return E.logger("error",e),!1}};function M(t){const e=typeof window<"u",r={client:t,responses:t.responses.listStore.getState(),fields:t.fields.listStore.getState(),location:e?window.location:void 0,document:e?window.document:void 0,sessionStorage:e?window.sessionStorage:void 0,localStorage:e?window.localStorage:void 0};return Object.freeze(r)}const fe=g.createDomain("predicate"),me=v.createFactory(({client:t})=>{const e=fe.store({}),r=g.createApi(e,{register(i,a){return{...i,[a.name]:{name:a.name,predicate:a.predicate}}}});function n(i,a){e.getState()[i]&&E.logger("warn",`Predicate '${i}' already registered. Registering again will override the previous registration.`),r.register(Object.freeze({name:i,predicate:a}))}const s=e.map(i=>Object.values(i));function d(i){return e.map(a=>{var f;return(f=a[i])==null?void 0:f.predicate},{skipVoid:!1})}function o(i){const a=g.createStore(()=>{},{skipVoid:!1}),f=g.createEffect(async()=>{const S=d(i).getState();if(!S)return;const F=M(t);return()=>S(F)});return g.sample({source:{responses:t.responses.listStore,fields:t.fields.listStore},target:f}),g.sample({clock:f.doneData,filter:S=>S!==void 0,target:a}),f(),a}return{register:n,getByName:d,listStore:s,getEvokablePredicate:o}});function ye(t){return v.invoke(me,t)}const he=(t,e,r)=>{r.register(t,e)},O=g.createDomain("feature"),Se=v.createFactory(({client:t})=>{const e=O.store({}),r=O.store([]),n=g.createApi(e,{register(c,u){return{...c,[u.id]:u.feature}}});function s(c,u){e.getState()[c]&&E.logger("warn",`Feature '${c}' already registered. Registering again will override the previous registration.`);const p={id:c,feature:{...u,id:c}};n.register(Object.freeze({id:c,feature:p}))}const d=g.createEffect(async({id:c,key:u,storage:l="local"})=>{const p=w.createStorageKey(`feature:${c}:${u}`,"global"),I=(l==="session"?w.sessionStore:w.localStore).get(p).boolean();return I===null?null:{id:c,key:u,bucket:I,storage:l}}),o=g.createEffect(c=>{if(!c)return null;const u=w.createStorageKey(`feature:${c.id}:${c.key}`,"global");(c.storage==="session"?w.sessionStore:w.localStore).set(u,c.bucket)}),i=new Map,a=g.attach({source:{allFeaturesStore:e,resolvedFeaturesStore:r},effect:async({allFeaturesStore:c,resolvedFeaturesStore:u},{id:l,decide:p,key:m})=>{const I=u.find(A=>A.id===l&&A.key===m);if(I)return I;const x=c[l];if(!x)throw new Error(`Feature with id '${l}' not found`);const j=i.get(`${l}:${m}`);if(j!==void 0){const A=await j;return{id:x.id,bucket:A,key:m,storage:x.feature.storage}}const D=p();i.set(`${l}:${m}`,D);const _=await D;return{id:x.id,bucket:_,key:m,storage:x.feature.storage}}});g.sample({clock:n.register,fn:c=>{const{id:u,feature:l}=c;return{id:u,key:l.feature.key,storage:l.feature.storage}},target:d}),g.sample({source:e,clock:a.doneData,fn:(c,u)=>{var x;const{id:l,bucket:p,storage:m}=u,I=(x=c[l])==null?void 0:x.feature.key;return I?{key:I,id:l,bucket:p,storage:m}:null},target:o});const f=g.combine({allFeaturesStore:e,resolvedFeaturesStore:r}).map(({allFeaturesStore:c,resolvedFeaturesStore:u})=>Object.values(c).map(l=>{const p=u.find(m=>m.id===l.id&&m.key===l.feature.key);return p?{id:l.id,name:l.feature.name,key:l.feature.key,getBucket:()=>({id:l.id,bucket:p.bucket}),isResolved:!0}:{id:l.id,name:l.feature.name,key:l.feature.key,getBucket:async()=>await a(l.feature),isResolved:!1}}));g.sample({clock:a.doneData,source:{resolvedFeatures:r},filter:({resolvedFeatures:c},{id:u,key:l})=>!c.some(m=>m.id===u&&m.key===l),fn:(c,u)=>u,target:t.eventBus.prepend(c=>({type:"feature_decide",feature:c}))}),g.sample({clock:[d.doneData,a.doneData],source:r,fn:(c,u)=>!u||c.some(p=>p.id===u.id&&p.key===u.key)?c:[...c,u],target:r});function S(c){return f.map(u=>u.find(l=>l.id===c))}function F(c){return e.map(u=>u[c],{skipVoid:!1})}function y(c){const u=g.createStore(async()=>{},{skipVoid:!1}),l=g.createEffect(async()=>{const p=S(c).getState();if(p)return async()=>(await p.getBucket()).bucket});return g.sample({source:r,filter:p=>p.some(m=>m.id===c),target:l}),g.sample({clock:l.doneData,filter:p=>p!==void 0,target:u}),l(),u}return{register:s,getById:S,getByName:F,listStore:f,getEvokableFeature:y}});function ve(t){return v.invoke(Se,t)}const ke=(t,e,r)=>{r.register(t,e)},R=g.createDomain("history");function z(t,e){return{id:W.generateId(`history-entry-${Date.now()}-${Math.random()}}`),node:e,at:Date.now(),experienceId:t}}const we=v.createFactory(()=>{const t=R.store({entries:[]}),e=R.event(),r=R.event(),n=R.event(),s=R.event();t.on(e,(o,i)=>({entries:[...o.entries,z(i.experienceId,i.node)]})),t.on(r,(o,i)=>({entries:[...o.entries.slice(0,-1),z(i.experienceId,i.node)]})),t.on(s,(o,i)=>i);function d(o,i){const a={lastStepIndex:-1,secondLastStepIndex:-1};for(let f=o.length-1;f>=0;f--){const S=o[f],F=S==null?void 0:S.node;if(!(!F||!b.isStepNode(F))&&!(i&&(S==null?void 0:S.experienceId)!==i))if(a.lastStepIndex===-1)a.lastStepIndex=f;else{a.secondLastStepIndex=f;break}}return a}return t.on(n,(o,i)=>{const{secondLastStepIndex:a}=d(o.entries,i.experienceId),f=a!==-1?o.entries.slice(0,a+1):o.entries;return{...o,entries:f}}),{push:e,replace:r,back:n,restore:s,entriesStore:t.map(o=>o.entries)}});function Ie(){return v.invoke(we)}const be=()=>g.createEvent(),Fe=g.createDomain("field"),Ee=v.createFactory(()=>{const t=Fe.store({}),e=g.createApi(t,{register(i,a){return{...i,[a.field.id]:a.field}}});function r(i){e.register({field:i})}function n(i,a){const f=d(i).getState();if(!f)return;const S=Object.assign({},f,{...a});e.register({field:{...S}})}const s=t.map(i=>Object.values(i));function d(i){return t.map(a=>a[i]||null)}function o(i){return t.map(a=>Object.values(a).find(f=>f.name===i)||null)}return{register:r,update:n,getById:d,listStore:s,getByName:o}});function xe(){return v.invoke(Ee)}const je=(t,e)=>{e.register(t)},Re=g.createDomain("action"),Ae=v.createFactory(()=>{const t=Re.store({}),e=g.createApi(t,{register(o,i){return{...o,[i.name]:{name:i.name,action:i.action}}}});function r(o,i){e.register({name:o,action:i})}const n=t.map(o=>Object.values(o));function s(o){return t.map(i=>i[o],{skipVoid:!1})}function d(o){return t.map(i=>{const a=i[o];return a?a.action:void 0},{skipVoid:!1})}return{register:r,getByName:s,listStore:n,getEvokableAction:d}});function Pe(){return v.invoke(Ae)}const Be=(t,e,r)=>{r.register(t,e)};function U(t){return typeof t>"u"||t===null||t===""||Array.isArray(t)&&!t.length}const De=g.createDomain("response"),$e=v.createFactory(({client:t})=>{const e=De.store({}),r=g.createEvent(),n=g.createEvent(),s=g.createApi(e,{register(y,c){return{...y,[c.fieldId]:c.response}},registerBatch(y,c){return{...y,...c}},clear(y,c){const{[c]:u,...l}=y;return l},clearAll(){return{}}});function d(y,c){if(typeof y=="string"){if(c===void 0)throw new Error("Response is required when registering a single field");s.register({fieldId:y,response:c})}else s.registerBatch(y)}async function o(y){const c=[];return await Promise.allSettled(Object.entries(y).map(async([u,l])=>{let p=l;const m=t.fields.getById(u).getState();if(!m){c.push({fieldId:u,userMessage:`Field '${u}' not found`,systemMessage:`No field with ID '${u}' exists. Available field IDs are: ${Object.keys(t.fields.listStore.getState()).join(",")}.`,value:p});return}if(m.multiple&&(typeof p=="string"||typeof p=="number"||typeof p=="boolean")&&(p=[p]),m.validation&&!H.isEmpty(m.validation)&&!U(p)){const I=await b.evaluateRuleLogic(t,m.validation,{$input:p});if(typeof I=="string"){c.push({fieldId:u,userMessage:I,systemMessage:`Field validation resulted in an error: ${I}.`,value:p});return}if(I===!1){c.push({fieldId:u,userMessage:"This field is invalid",systemMessage:"Field validation resulted in an unspecified error.",value:p});return}}if(m.required&&U(p)){c.push({fieldId:u,userMessage:"This field is required",systemMessage:"Field is required.",value:p});return}if(!m.multiple&&Array.isArray(p)&&p.length>1){c.push({fieldId:u,userMessage:"This field expects a single response",systemMessage:"Field expects a single response.",value:p});return}if(m.options){const I=m.options.map(j=>j.value),x=Array.isArray(p)?p:[p];Array.isArray(p)&&(x.every(j=>I.includes(j))||c.push({fieldId:u,userMessage:"This field expects a valid option",systemMessage:`Field expects a valid option. Valid options are: ${I.join(", ")}`,value:p}))}})),{responsesToCommit:y,validationErrors:c}}async function i(y){const{responsesToCommit:c,validationErrors:u}=await o(y);return u.length?{errors:u}:(s.registerBatch(c),{errors:[]})}const a=e.map(y=>y),f=e.map(y=>Object.keys(y).map(u=>({fieldId:u,value:y[u]})));function S(y){const c=t.fields.getById(y),u=e.map(l=>l[y]||null);return g.combine({f:c,r:u},({f:l,r:p})=>p||(l!=null&&l.defaultValue?l.defaultValue:null))}function F(y){const c=t.fields.getByName(y);return g.combine({f:c,s:e},({f:u,s:l})=>{const p=u&&l[u.id]||null;return p||(u!=null&&u.defaultValue?u.defaultValue:null)})}return g.sample({clock:r,target:s.clearAll}),g.sample({clock:n,target:s.clear}),{register:d,clearAll:r,clear:n,commit:i,getResponsesToCommit:o,listStore:f,getAllStore:a,getByFieldId:S,getByFieldName:F}});function Ce(t){return v.invoke($e,t)}const Oe=()=>"0.0.32-next.1";function ze(){if(k.supportsDocument()){const t=[document.currentScript,document.getElementById("picked_script"),document.getElementById("picked"),document.getElementById("cvly"),document.getElementById("cvly-x")];for(const e of t)if(e!=null&&e.dataset.api)return e.dataset.api}return"https://api.picked.app"}function Ue(){if(!k.supportsWindow())return{};const t=new URLSearchParams(window.location.search),e={},r=new Set;for(const[s]of t.entries())s.startsWith("picked-")&&r.add(s);for(const s of r){const d=s.replace("picked-","");e[d]=t.getAll(s)}const n=w.createStorageKey("s");if(r.size>0)w.sessionStore.set(n,e);else{const s=w.sessionStore.get(n);if(s)return s.json()||{}}return e}function Le(){if(k.supportsCryptoRandomUUID())return crypto.randomUUID();const t=Date.now().toString(36),e=Math.random().toString(36).substring(2,15),r=Math.random().toString(36).substring(2,15),n=Math.random().toString(36).substring(2,15);return`${t}-${e}-${r}-${n}`}const Ve=w.createStorageKey("session","global"),Me=()=>{const t=w.localStore.get(Ve);let e;t.isSet()&&(e=t.json());const r=s=>t.set({id:s.id,isUser:s.isUser,identifiers:s.identifiers}),n={id:(e==null?void 0:e.id)??Le(),isUser:(e==null?void 0:e.isUser)??void 0,identifiers:(e==null?void 0:e.identifiers)??void 0,setIsUser(s){this.isUser=s,r(this)},setIdentifier(s,d){this.identifiers={...this.identifiers,[s]:d},r(this)},removeIdentifier(s){this.identifiers&&(this.identifiers=Object.fromEntries(Object.entries(this.identifiers).filter(([d])=>d!==s)),this.identifiers=Object.keys(this.identifiers).length?this.identifiers:void 0,r(this))}};return r(n),n},Te=()=>k.supportsLocalStorage()?Me():null;function T(){if(k.supportsWindow())return globalThis.window.pickedConfig}function Ne(){if(!k.supportsWindow())return;const t=T(),e=t==null?void 0:t.organizationId,r=t==null?void 0:t.projectId;return e&&r?{organizationId:e,projectId:r}:void 0}function _e(){if(!k.supportsDocument())return;const t=document.getElementById("picked_script")||document.querySelector("script#picked")||document.getElementById("cvly");if(!t)return;const e=t.dataset.organizationid||t.getAttribute("organization-id"),r=t.dataset.projectid||t.getAttribute("project-id");return e&&r?{organizationId:e,projectId:r}:void 0}function qe(t){const{organizationId:e,projectId:r}=t;if(e&&r)return{organizationId:e,projectId:r};const n=Ne();if(n)return n;const s=_e();if(s)return s;throw new Error(`organizationId and projectId are required. You can provide them via one of:
|
|
1
|
+
"use strict";var q=Object.defineProperty;var K=(t,e,r)=>e in t?q(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var h=(t,e,r)=>K(t,typeof e!="symbol"?e+"":e,r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("effector"),v=require("@withease/factories"),b=require("../experience-instance-DBi45xr9.cjs"),E=require("../logger-BsmHUUw1.cjs"),w=require("../storage-YlR83AWP.cjs"),W=require("../id-BKIWbSTy.cjs"),H=require("../object-BbFTsGh3.cjs"),k=require("../supports-YvpQZxbh.cjs"),L=g.createDomain("experience"),G=v.createFactory(({client:t,experience:e})=>{const r=L.store(e),n=g.createApi(r,{merge(a,f){return{...a,...f.experience}}}),s=r.map(a=>({name:a.name,decisionLogic:a.condition??a.decide,targetSelectors:a.targets,initializeOpenLogic:e.initializeOpen})),d=t.components.listStore.map(a=>a.find(f=>f.name===`experience:${e.id}`)||a.find(f=>f.name==="experience"),{skipVoid:!1}),o=r.map(a=>({steps:a.steps,nodes:a.nodes,edges:a.edges,conditionals:a.conditionals})),i=e.actions??[];return{id:e.id,configStore:s,treeStore:o,componentStore:d,actions:i,merge:n.merge}});function Y(t){return v.invoke(G,t)}const J=v.createFactory(({client:t})=>{const e=L.store({}),r=g.createApi(e,{register(o,i){return{...o,[i.id]:i}}});function n(o){const i=e.getState()[o.id];if(i){i.merge({experience:o,strategy:"override"});return}const a=Y({client:t,experience:o});r.register(a)}const s=e.map(o=>Object.values(o));function d(o){return e.map(i=>i[o],{skipVoid:!1})}return{register:n,getById:d,listStore:s}});function Q(t){return v.invoke(J,t)}const X=(t,e)=>{e.register(t)},V=(t,e)=>{const{targetSelectors:r}=e.configStore.getState(),n=b.getTargetElements(r,e.id);n.forEach(({elements:d})=>d.forEach(o=>b.tagTargetElement(o,e.id))),b.createAppHosts(n,e.id).forEach(d=>{t.experienceInstances.spawn(e,d)})},$=async t=>{await Promise.all(t.experiences.listStore.getState().map(async e=>{await Z(t,e)&&V(t,e)}))},Z=async(t,e)=>{const{decisionLogic:r,targetSelectors:n}=e.configStore.getState();return b.getTargetElements(n,e.id).length<1||n.length===0?!1:r&&b.isRulesLogic(r)?await b.evaluateRuleLogic(t,r)===!0:!0},ee=(t,e,r)=>{const n=e.name,s=e.setup(t);if(s){const d=r[n]??{};r[n]=Object.freeze({...d,...s})}},te=g.createDomain("component"),re=v.createFactory(({client:t,component:e,name:r})=>{const n=t.frameworks.getByName(e.frameworkName);return{name:r,component:e,frameworkStore:n}});function ne(t){return v.invoke(re,t)}const se=v.createFactory(({client:t})=>{const e=te.store({}),r=g.createApi(e,{register(o,i){return{...o,[i.name]:i}}});function n(o,i){e.getState()[o]&&E.logger("warn",`Component '${o}' already registered. Registering again will override the previous registration.`);const f=ne({client:t,name:o,component:i});r.register(f)}const s=e.map(o=>Object.values(o));function d(o){return e.map(i=>i[o],{skipVoid:!1})}return{register:n,getByName:d,listStore:s}});function ie(t){return v.invoke(se,t)}const C=(t,e,r)=>{r.register(t,e)},oe=g.createDomain("framework"),ae=v.createFactory(({client:t})=>{const e=oe.store({}),r=g.createApi(e,{register(o,i){return{...o,[i.name]:i.framework}}});function n(o,i){e.getState()[o]&&E.logger("warn",`Framework '${o}' already registered. Registering again will override the previous registration.`),r.register({name:o,framework:i})}const s=e.map(o=>Object.values(o));function d(o){return e.map(i=>i[o],{skipVoid:!1})}return{register:n,getByName:d,listStore:s}});function ce(t){return v.invoke(ae,t)}const ue=(t,e)=>{e.register(t.name,t)},de=6e3,le=w.createStorageKey("last_ping","global"),pe=t=>`${t}/api/v1/ping`,ge=async t=>{try{const e=Date.now(),r=w.localStore.get(le);let n=0;if(r.isSet()&&(n=r.json()??0),n&&e-n<de)return!0;const s=pe(t.apiUrl),d={projectId:t.projectId,path:window.location.pathname},o=JSON.stringify(d),i={"Content-Type":"application/json"},a=document.getElementById("picked_script"),f=a==null?void 0:a.dataset.verceltoken;f&&(i["x-vercel-protection-bypass"]=f);const F=(await fetch(s,{method:"POST",headers:i,body:o})).ok;return F&&r.set(e),F}catch(e){return E.logger("error",e),!1}};function M(t){const e=typeof window<"u",r={client:t,responses:t.responses.listStore.getState(),fields:t.fields.listStore.getState(),location:e?window.location:void 0,document:e?window.document:void 0,sessionStorage:e?window.sessionStorage:void 0,localStorage:e?window.localStorage:void 0};return Object.freeze(r)}const fe=g.createDomain("predicate"),me=v.createFactory(({client:t})=>{const e=fe.store({}),r=g.createApi(e,{register(i,a){return{...i,[a.name]:{name:a.name,predicate:a.predicate}}}});function n(i,a){e.getState()[i]&&E.logger("warn",`Predicate '${i}' already registered. Registering again will override the previous registration.`),r.register(Object.freeze({name:i,predicate:a}))}const s=e.map(i=>Object.values(i));function d(i){return e.map(a=>{var f;return(f=a[i])==null?void 0:f.predicate},{skipVoid:!1})}function o(i){const a=g.createStore(()=>{},{skipVoid:!1}),f=g.createEffect(async()=>{const S=d(i).getState();if(!S)return;const F=M(t);return(...m)=>S({...F,args:m})});return g.sample({source:{responses:t.responses.listStore,fields:t.fields.listStore},target:f}),g.sample({clock:f.doneData,filter:S=>S!==void 0,target:a}),f(),a}return{register:n,getByName:d,listStore:s,getEvokablePredicate:o}});function ye(t){return v.invoke(me,t)}const he=(t,e,r)=>{r.register(t,e)},O=g.createDomain("feature"),Se=v.createFactory(({client:t})=>{const e=O.store({}),r=O.store([]),n=g.createApi(e,{register(c,u){return{...c,[u.id]:u.feature}}});function s(c,u){e.getState()[c]&&E.logger("warn",`Feature '${c}' already registered. Registering again will override the previous registration.`);const p={id:c,feature:{...u,id:c}};n.register(Object.freeze({id:c,feature:p}))}const d=g.createEffect(async({id:c,key:u,storage:l="local"})=>{const p=w.createStorageKey(`feature:${c}:${u}`,"global"),I=(l==="session"?w.sessionStore:w.localStore).get(p).boolean();return I===null?null:{id:c,key:u,bucket:I,storage:l}}),o=g.createEffect(c=>{if(!c)return null;const u=w.createStorageKey(`feature:${c.id}:${c.key}`,"global");(c.storage==="session"?w.sessionStore:w.localStore).set(u,c.bucket)}),i=new Map,a=g.attach({source:{allFeaturesStore:e,resolvedFeaturesStore:r},effect:async({allFeaturesStore:c,resolvedFeaturesStore:u},{id:l,decide:p,key:y})=>{const I=u.find(A=>A.id===l&&A.key===y);if(I)return I;const x=c[l];if(!x)throw new Error(`Feature with id '${l}' not found`);const j=i.get(`${l}:${y}`);if(j!==void 0){const A=await j;return{id:x.id,bucket:A,key:y,storage:x.feature.storage}}const D=p();i.set(`${l}:${y}`,D);const _=await D;return{id:x.id,bucket:_,key:y,storage:x.feature.storage}}});g.sample({clock:n.register,fn:c=>{const{id:u,feature:l}=c;return{id:u,key:l.feature.key,storage:l.feature.storage}},target:d}),g.sample({source:e,clock:a.doneData,fn:(c,u)=>{var x;const{id:l,bucket:p,storage:y}=u,I=(x=c[l])==null?void 0:x.feature.key;return I?{key:I,id:l,bucket:p,storage:y}:null},target:o});const f=g.combine({allFeaturesStore:e,resolvedFeaturesStore:r}).map(({allFeaturesStore:c,resolvedFeaturesStore:u})=>Object.values(c).map(l=>{const p=u.find(y=>y.id===l.id&&y.key===l.feature.key);return p?{id:l.id,name:l.feature.name,key:l.feature.key,getBucket:()=>({id:l.id,bucket:p.bucket}),isResolved:!0}:{id:l.id,name:l.feature.name,key:l.feature.key,getBucket:async()=>await a(l.feature),isResolved:!1}}));g.sample({clock:a.doneData,source:{resolvedFeatures:r},filter:({resolvedFeatures:c},{id:u,key:l})=>!c.some(y=>y.id===u&&y.key===l),fn:(c,u)=>u,target:t.eventBus.prepend(c=>({type:"feature_decide",feature:c}))}),g.sample({clock:[d.doneData,a.doneData],source:r,fn:(c,u)=>!u||c.some(p=>p.id===u.id&&p.key===u.key)?c:[...c,u],target:r});function S(c){return f.map(u=>u.find(l=>l.id===c))}function F(c){return e.map(u=>u[c],{skipVoid:!1})}function m(c){const u=g.createStore(async()=>{},{skipVoid:!1}),l=g.createEffect(async()=>{const p=S(c).getState();if(p)return async()=>(await p.getBucket()).bucket});return g.sample({source:r,filter:p=>p.some(y=>y.id===c),target:l}),g.sample({clock:l.doneData,filter:p=>p!==void 0,target:u}),l(),u}return{register:s,getById:S,getByName:F,listStore:f,getEvokableFeature:m}});function ve(t){return v.invoke(Se,t)}const ke=(t,e,r)=>{r.register(t,e)},R=g.createDomain("history");function z(t,e){return{id:W.generateId(`history-entry-${Date.now()}-${Math.random()}}`),node:e,at:Date.now(),experienceId:t}}const we=v.createFactory(()=>{const t=R.store({entries:[]}),e=R.event(),r=R.event(),n=R.event(),s=R.event();t.on(e,(o,i)=>({entries:[...o.entries,z(i.experienceId,i.node)]})),t.on(r,(o,i)=>({entries:[...o.entries.slice(0,-1),z(i.experienceId,i.node)]})),t.on(s,(o,i)=>i);function d(o,i){const a={lastStepIndex:-1,secondLastStepIndex:-1};for(let f=o.length-1;f>=0;f--){const S=o[f],F=S==null?void 0:S.node;if(!(!F||!b.isStepNode(F))&&!(i&&(S==null?void 0:S.experienceId)!==i))if(a.lastStepIndex===-1)a.lastStepIndex=f;else{a.secondLastStepIndex=f;break}}return a}return t.on(n,(o,i)=>{const{secondLastStepIndex:a}=d(o.entries,i.experienceId),f=a!==-1?o.entries.slice(0,a+1):o.entries;return{...o,entries:f}}),{push:e,replace:r,back:n,restore:s,entriesStore:t.map(o=>o.entries)}});function Ie(){return v.invoke(we)}const be=()=>g.createEvent(),Fe=g.createDomain("field"),Ee=v.createFactory(()=>{const t=Fe.store({}),e=g.createApi(t,{register(i,a){return{...i,[a.field.id]:a.field}}});function r(i){e.register({field:i})}function n(i,a){const f=d(i).getState();if(!f)return;const S=Object.assign({},f,{...a});e.register({field:{...S}})}const s=t.map(i=>Object.values(i));function d(i){return t.map(a=>a[i]||null)}function o(i){return t.map(a=>Object.values(a).find(f=>f.name===i)||null)}return{register:r,update:n,getById:d,listStore:s,getByName:o}});function xe(){return v.invoke(Ee)}const je=(t,e)=>{e.register(t)},Re=g.createDomain("action"),Ae=v.createFactory(()=>{const t=Re.store({}),e=g.createApi(t,{register(o,i){return{...o,[i.name]:{name:i.name,action:i.action}}}});function r(o,i){e.register({name:o,action:i})}const n=t.map(o=>Object.values(o));function s(o){return t.map(i=>i[o],{skipVoid:!1})}function d(o){return t.map(i=>{const a=i[o];return a?a.action:void 0},{skipVoid:!1})}return{register:r,getByName:s,listStore:n,getEvokableAction:d}});function Pe(){return v.invoke(Ae)}const Be=(t,e,r)=>{r.register(t,e)};function U(t){return typeof t>"u"||t===null||t===""||Array.isArray(t)&&!t.length}const De=g.createDomain("response"),$e=v.createFactory(({client:t})=>{const e=De.store({}),r=g.createEvent(),n=g.createEvent(),s=g.createApi(e,{register(m,c){return{...m,[c.fieldId]:c.response}},registerBatch(m,c){return{...m,...c}},clear(m,c){const{[c]:u,...l}=m;return l},clearAll(){return{}}});function d(m,c){if(typeof m=="string"){if(c===void 0)throw new Error("Response is required when registering a single field");s.register({fieldId:m,response:c})}else s.registerBatch(m)}async function o(m){const c=[];return await Promise.allSettled(Object.entries(m).map(async([u,l])=>{let p=l;const y=t.fields.getById(u).getState();if(!y){c.push({fieldId:u,userMessage:`Field '${u}' not found`,systemMessage:`No field with ID '${u}' exists. Available field IDs are: ${Object.keys(t.fields.listStore.getState()).join(",")}.`,value:p});return}if(y.multiple&&(typeof p=="string"||typeof p=="number"||typeof p=="boolean")&&(p=[p]),y.validation&&!H.isEmpty(y.validation)&&!U(p)){const I=await b.evaluateRuleLogic(t,y.validation,{$input:p});if(typeof I=="string"){c.push({fieldId:u,userMessage:I,systemMessage:`Field validation resulted in an error: ${I}.`,value:p});return}if(I===!1){c.push({fieldId:u,userMessage:"This field is invalid",systemMessage:"Field validation resulted in an unspecified error.",value:p});return}}if(y.required&&U(p)){c.push({fieldId:u,userMessage:"This field is required",systemMessage:"Field is required.",value:p});return}if(!y.multiple&&Array.isArray(p)&&p.length>1){c.push({fieldId:u,userMessage:"This field expects a single response",systemMessage:"Field expects a single response.",value:p});return}if(y.options){const I=y.options.map(j=>j.value),x=Array.isArray(p)?p:[p];Array.isArray(p)&&(x.every(j=>I.includes(j))||c.push({fieldId:u,userMessage:"This field expects a valid option",systemMessage:`Field expects a valid option. Valid options are: ${I.join(", ")}`,value:p}))}})),{responsesToCommit:m,validationErrors:c}}async function i(m){const{responsesToCommit:c,validationErrors:u}=await o(m);return u.length?{errors:u}:(s.registerBatch(c),{errors:[]})}const a=e.map(m=>m),f=e.map(m=>Object.keys(m).map(u=>({fieldId:u,value:m[u]})));function S(m){const c=t.fields.getById(m),u=e.map(l=>l[m]||null);return g.combine({f:c,r:u},({f:l,r:p})=>p||(l!=null&&l.defaultValue?l.defaultValue:null))}function F(m){const c=t.fields.getByName(m);return g.combine({f:c,s:e},({f:u,s:l})=>{const p=u&&l[u.id]||null;return p||(u!=null&&u.defaultValue?u.defaultValue:null)})}return g.sample({clock:r,target:s.clearAll}),g.sample({clock:n,target:s.clear}),{register:d,clearAll:r,clear:n,commit:i,getResponsesToCommit:o,listStore:f,getAllStore:a,getByFieldId:S,getByFieldName:F}});function Ce(t){return v.invoke($e,t)}const Oe=()=>"0.0.32-next.2";function ze(){if(k.supportsDocument()){const t=[document.currentScript,document.getElementById("picked_script"),document.getElementById("picked"),document.getElementById("cvly"),document.getElementById("cvly-x")];for(const e of t)if(e!=null&&e.dataset.api)return e.dataset.api}return"https://api.picked.app"}function Ue(){if(!k.supportsWindow())return{};const t=new URLSearchParams(window.location.search),e={},r=new Set;for(const[s]of t.entries())s.startsWith("picked-")&&r.add(s);for(const s of r){const d=s.replace("picked-","");e[d]=t.getAll(s)}const n=w.createStorageKey("s");if(r.size>0)w.sessionStore.set(n,e);else{const s=w.sessionStore.get(n);if(s)return s.json()||{}}return e}function Le(){if(k.supportsCryptoRandomUUID())return crypto.randomUUID();const t=Date.now().toString(36),e=Math.random().toString(36).substring(2,15),r=Math.random().toString(36).substring(2,15),n=Math.random().toString(36).substring(2,15);return`${t}-${e}-${r}-${n}`}const Ve=w.createStorageKey("session","global"),Me=()=>{const t=w.localStore.get(Ve);let e;t.isSet()&&(e=t.json());const r=s=>t.set({id:s.id,isUser:s.isUser,identifiers:s.identifiers}),n={id:(e==null?void 0:e.id)??Le(),isUser:(e==null?void 0:e.isUser)??void 0,identifiers:(e==null?void 0:e.identifiers)??void 0,setIsUser(s){this.isUser=s,r(this)},setIdentifier(s,d){this.identifiers={...this.identifiers,[s]:d},r(this)},removeIdentifier(s){this.identifiers&&(this.identifiers=Object.fromEntries(Object.entries(this.identifiers).filter(([d])=>d!==s)),this.identifiers=Object.keys(this.identifiers).length?this.identifiers:void 0,r(this))}};return r(n),n},Te=()=>k.supportsLocalStorage()?Me():null;function T(){if(k.supportsWindow())return globalThis.window.pickedConfig}function Ne(){if(!k.supportsWindow())return;const t=T(),e=t==null?void 0:t.organizationId,r=t==null?void 0:t.projectId;return e&&r?{organizationId:e,projectId:r}:void 0}function _e(){if(!k.supportsDocument())return;const t=document.getElementById("picked_script")||document.querySelector("script#picked")||document.getElementById("cvly");if(!t)return;const e=t.dataset.organizationid||t.getAttribute("organization-id"),r=t.dataset.projectid||t.getAttribute("project-id");return e&&r?{organizationId:e,projectId:r}:void 0}function qe(t){const{organizationId:e,projectId:r}=t;if(e&&r)return{organizationId:e,projectId:r};const n=Ne();if(n)return n;const s=_e();if(s)return s;throw new Error(`organizationId and projectId are required. You can provide them via one of:
|
|
2
2
|
(1) createClient({ organizationId, projectId }) options;
|
|
3
3
|
(2) window.pickedConfig = { organizationId, projectId };
|
|
4
4
|
(3) a <script> tag with id 'picked_script', 'picked', or 'cvly' that includes data-organizationid/data-projectid (or organization-id/project-id) attributes.`)}function P(t){return t==null||t===""||Number.isNaN(t)}const Ke={default:(t,e)=>P(t)?String(e??""):String(t),append:(t,e)=>e&&!P(t)?`${t} ${e}`:t,prepend:(t,e)=>e&&!P(t)?`${e} ${t}`:t,upper:t=>typeof t=="string"?t.toUpperCase():t,lower:t=>typeof t=="string"?t.toLowerCase():t,capitalize:t=>typeof t=="string"?t.charAt(0).toUpperCase()+t.slice(1):t,list:t=>{if(!t||typeof t!="object")return t;const e=new Intl.ListFormat("en",{style:"long",type:"conjunction"});if(Array.isArray(t))return e.format(t.map(String));if(t instanceof Map){const r=Array.from(t.entries()).map(([n,s])=>`${n}: ${s}`);return e.format(r)}return t instanceof Set?e.format(Array.from(t).map(String)):t}};function We(t){return typeof t=="object"&&t!==null}function He(t,e){let r=e;for(const n of t.split("."))if(We(r)&&n in r)r=r[n];else return;return typeof r=="function"?r():r}function Ge(t,e){const r=t.split("|").map(d=>d.trim()),n=r.shift()??"";let s=He(n,e);for(const d of r){const[o,...i]=d.split(":"),a=(o==null?void 0:o.trim())??"",f=i.join(":").trim().replaceAll(/(?:^['"]|['"]$)/g,""),S=Ke[a];S&&(s=S(s,f))}return P(s)?"":typeof s=="object"?JSON.stringify(s):String(s)}function Ye(t,e){let r="",n=0;for(;n<t.length;)if(t[n]==="{"&&t[n+1]==="{"){n+=2;let s="";for(;n<t.length;){if(t[n]==="}"&&t[n+1]==="}"){n+=2;break}s+=t[n++]}r+=Ge(s.trim(),e)}else r+=t[n++];return r}class B{constructor(e){h(this,"options");h(this,"isReady",!1);h(this,"project");h(this,"plugins",{});h(this,"eventBus",be());h(this,"organizationId");h(this,"projectId");h(this,"apiUrl");h(this,"session");h(this,"precondition");h(this,"condition");h(this,"searchParams",Ue());h(this,"history",Ie());h(this,"components",ie({client:this}));h(this,"experienceInstances",b.createExperienceInstanceIndex({client:this}));h(this,"experiences",Q({client:this}));h(this,"frameworks",ce({client:this}));h(this,"predicates",ye({client:this}));h(this,"features",ve({client:this}));h(this,"responses",Ce({client:this}));h(this,"fields",xe());h(this,"actions",Pe());h(this,"renderString",(e,r)=>{const n=this.responses.listStore.getState().reduce((s,d)=>(s[d.fieldId]=d.value,s),{});return Ye(e,{...r,responses:n})});E.logger("info","Picked client initializing.");const{organizationId:r,projectId:n}=qe(e);this.organizationId=r,this.projectId=n,this.options=Object.freeze(e),this.apiUrl=e.apiUrl||ze(),this.session=Te(),this.setupPlugins(),this.setupFeatures(),this.setupPredicates(),this.setupActions(),this.precondition=e.precondition,this.condition=e.condition,this.eventBus({type:"load",version:Oe()}),E.logger("info","Picked client initialized.")}start(){ge(this),(async()=>{if(!k.supportsDocument())return;let r;typeof this.precondition>"u"?r=!0:typeof this.precondition=="boolean"?r=this.precondition:r=await b.evaluateRuleLogic(this,this.precondition)===!0;let n;r&&(this.condition===void 0?n=!0:typeof this.condition=="boolean"?n=this.condition:n=await b.evaluateRuleLogic(this,this.condition)===!0);const s=r&&n===!0;if(typeof n=="boolean"&&this.session){const d=n;this.session.setIsUser(d),this.eventBus({type:"user_decide",value:d})}this.eventBus({type:"initialize"}),document.body&&s&&$(this),await b.domInteractive(),s&&$(this),this.eventBus({type:"ready"}),this.isReady=!0,this.session&&this.eventBus({type:"session",...this.session})})()}registerFramework(e){ue(e,this.frameworks)}registerComponent(e,r){C(e,r,this.components)}registerPlugin(e){ee(this,e,this.plugins)}registerFeature(e,r){ke(e,r,this.features)}registerPredicate(e,r){he(e,r,this.predicates)}registerField(e){je(e,this.fields)}registerAction(e,r){Be(e,r,this.actions)}registerExperience(e){e.component&&C(`experience:${e.id}`,e.component,this.components),X(e,this.experiences)}getStateSnapshot(){return M(this)}async launchExperienceById(e){const r=this.experiences.getById(e).getState();if(!r){E.logger("warn",`Experience with id '${e}' not found.`);return}V(this,r)}setupPlugins(){var e;(e=this.options.plugins)==null||e.forEach(r=>{if(Array.isArray(r)){r.forEach(s=>{this.registerPlugin(s)});return}const n=typeof r=="function"?r():r;if(Array.isArray(n)){n.forEach(s=>this.registerPlugin(s));return}this.registerPlugin(n)})}setupFeatures(){const e=this.options.features;e&&(Object.entries(e).forEach(([r,n])=>{const s=typeof n=="function"?n():n;this.registerFeature(r,s)}),this.searchParams.feature&&this.searchParams.feature.forEach(r=>{try{const[n,s]=r.split(":");if(!n||!s)return;let d=s;d==="true"&&(d=!0),d==="false"&&(d=!1),this.registerFeature(n,{key:`${d}`,name:n,decide:()=>d,storage:"session"})}catch{}}))}setupPredicates(){const e=this.options.predicates;e&&Object.entries(e).forEach(([r,n])=>{if(typeof n!="function"){E.logger("warn",`Predicate "${r}" is not a function.`);return}this.registerPredicate(r,n)})}setupActions(){const e=this.options.actions;e&&Object.entries(e).forEach(([r,n])=>{if(typeof n!="function"){E.logger("warn",`Action "${r}" is not a function.`);return}this.registerAction(r,n)})}getPluginConfig(e){return this.plugins[e]??{}}}h(B,"logger",E.logger);function N(t){var e;return((e=t.options)==null?void 0:e.some(r=>"condition"in r))??!1}function Je(t){return t.some(e=>e.condition||N(e))}async function Qe(t,e){return e.length===0||!Je(e)?e:(await Promise.all(e.map(async n=>{if(!(n.condition?await b.evaluateRuleLogic(t,n.condition):!0))return null;if(!n.options||!N(n))return n;const o=(await Promise.all(n.options.map(async a=>a.condition?await b.evaluateRuleLogic(t,a.condition)?a:null:a))).filter(a=>a!==null);return o.length===n.options.length?n:o.length===0?null:{...n,options:o}}))).filter(n=>n!==null)}const Xe=t=>{const e=new B(t);return k.bindClient(e),e};exports.evaluateRuleLogic=b.evaluateRuleLogic;exports.isPickedRoot=b.isPickedRoot;exports.createStorageKey=w.createStorageKey;exports.localStore=w.localStore;exports.sessionStore=w.sessionStore;exports.subscribe=w.subscribe;exports.supportsCookies=k.supportsCookies;exports.supportsCryptoRandomUUID=k.supportsCryptoRandomUUID;exports.supportsDocument=k.supportsDocument;exports.supportsHistory=k.supportsHistory;exports.supportsIntersectionObserver=k.supportsIntersectionObserver;exports.supportsLocalStorage=k.supportsLocalStorage;exports.supportsLocation=k.supportsLocation;exports.supportsSessionStorage=k.supportsSessionStorage;exports.supportsShadowRoot=k.supportsShadowRoot;exports.supportsWebComponents=k.supportsWebComponents;exports.supportsWindow=k.supportsWindow;exports.Picked=B;exports.createClient=Xe;exports.getPickedConfig=T;exports.getStepFields=Qe;
|
package/dist/cjs/server/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("effector"),k=require("../../experience-instance-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("effector"),k=require("../../experience-instance-DBi45xr9.cjs");function S(){let c,i;return{promise:new Promise((t,o)=>{c=t,i=o}),resolve:t=>c(t),reject:t=>i(t)}}function C(c,i){const{promise:f,resolve:t}=S(),o=r.createEvent(),s=r.createEvent(),l=r.createEvent(),u=r.createEvent(),p=r.createEvent(),g=c.experiences.listStore.map(e=>e.map(n=>k.createExperienceInstance({client:c,experience:n}))),a=r.createStore({currentExperienceIndex:0,renderedExperiences:[],isComplete:!1}),m=r.createEffect(async({experience:e,availableRenderers:n,startRendererIndex:v=0})=>{if(!e)return null;for(let d=v;d<n.length;d++){const x=n[d],E=e.componentStore.getState();if(E&&(x!=null&&x.isValidComponent(E.component)))return{rendered:await x.render(E.component,c,e),rendererIndex:d}}return null});a.on(l,(e,n)=>({...e,renderedExperiences:[...e.renderedExperiences,n],currentExperienceIndex:e.currentExperienceIndex+1})).on(p,e=>({...e,currentExperienceIndex:e.currentExperienceIndex+1})).on(u,e=>({...e,isComplete:!0})).reset(o),r.sample({clock:o,target:s}),r.sample({clock:s,source:{experiences:g,state:a},filter:({experiences:e,state:n})=>n.currentExperienceIndex<e.length&&!n.isComplete,fn:({experiences:e,state:n})=>({experience:e[n.currentExperienceIndex],availableRenderers:i,startRendererIndex:0}),target:m}),r.sample({clock:m.doneData,filter:e=>e!==null,fn:e=>e.rendered.body,target:l}),r.sample({clock:l,target:s}),r.sample({clock:m.doneData,filter:e=>e===null,target:p}),r.sample({clock:p,target:s}),r.sample({clock:[s,p,l],source:{experiences:g,state:a},filter:({experiences:e,state:n})=>n.currentExperienceIndex>=e.length,target:u});const I=r.attach({source:a,effect:e=>{e.isComplete&&t(e.renderedExperiences)}});return r.sample({clock:u,target:I}),o(),f}exports.render=C;
|
package/dist/esm/index.js
CHANGED
|
@@ -3,8 +3,8 @@ var te = (t, e, r) => e in t ? ee(t, e, { enumerable: !0, configurable: !0, writ
|
|
|
3
3
|
var h = (t, e, r) => te(t, typeof e != "symbol" ? e + "" : e, r);
|
|
4
4
|
import { createDomain as x, createApi as E, createStore as q, createEffect as $, sample as F, attach as re, combine as D, createEvent as U } from "effector";
|
|
5
5
|
import { createFactory as w, invoke as I } from "@withease/factories";
|
|
6
|
-
import { g as K, t as ne, c as se, i as ie, e as P, a as oe, b as ae, d as ce } from "../experience-instance-
|
|
7
|
-
import { f as Rt } from "../experience-instance-
|
|
6
|
+
import { g as K, t as ne, c as se, i as ie, e as P, a as oe, b as ae, d as ce } from "../experience-instance-Bg6BWuwI.js";
|
|
7
|
+
import { f as Rt } from "../experience-instance-Bg6BWuwI.js";
|
|
8
8
|
import { l as v } from "../logger-C9a75KZn.js";
|
|
9
9
|
import { c as B, l as z, s as O } from "../storage-BLmAhfhl.js";
|
|
10
10
|
import { a as Ct } from "../storage-BLmAhfhl.js";
|
|
@@ -247,7 +247,7 @@ const ze = x("predicate"), Oe = w(({ client: t }) => {
|
|
|
247
247
|
if (!y)
|
|
248
248
|
return;
|
|
249
249
|
const k = J(t);
|
|
250
|
-
return () => y(k);
|
|
250
|
+
return (...g) => y({ ...k, args: g });
|
|
251
251
|
});
|
|
252
252
|
return F({
|
|
253
253
|
source: { responses: t.responses.listStore, fields: t.fields.listStore },
|
|
@@ -314,24 +314,24 @@ const Ue = (t, e, r) => {
|
|
|
314
314
|
(c.storage === "session" ? O : z).set(u, c.bucket);
|
|
315
315
|
}), i = /* @__PURE__ */ new Map(), a = re({
|
|
316
316
|
source: { allFeaturesStore: e, resolvedFeaturesStore: r },
|
|
317
|
-
effect: async ({ allFeaturesStore: c, resolvedFeaturesStore: u }, { id: l, decide: p, key:
|
|
317
|
+
effect: async ({ allFeaturesStore: c, resolvedFeaturesStore: u }, { id: l, decide: p, key: m }) => {
|
|
318
318
|
const S = u.find(
|
|
319
|
-
(R) => R.id === l && R.key ===
|
|
319
|
+
(R) => R.id === l && R.key === m
|
|
320
320
|
);
|
|
321
321
|
if (S)
|
|
322
322
|
return S;
|
|
323
323
|
const b = c[l];
|
|
324
324
|
if (!b)
|
|
325
325
|
throw new Error(`Feature with id '${l}' not found`);
|
|
326
|
-
const j = i.get(`${l}:${
|
|
326
|
+
const j = i.get(`${l}:${m}`);
|
|
327
327
|
if (j !== void 0) {
|
|
328
328
|
const R = await j;
|
|
329
|
-
return { id: b.id, bucket: R, key:
|
|
329
|
+
return { id: b.id, bucket: R, key: m, storage: b.feature.storage };
|
|
330
330
|
}
|
|
331
331
|
const N = p();
|
|
332
|
-
i.set(`${l}:${
|
|
332
|
+
i.set(`${l}:${m}`, N);
|
|
333
333
|
const Z = await N;
|
|
334
|
-
return { id: b.id, bucket: Z, key:
|
|
334
|
+
return { id: b.id, bucket: Z, key: m, storage: b.feature.storage };
|
|
335
335
|
}
|
|
336
336
|
});
|
|
337
337
|
F({
|
|
@@ -346,8 +346,8 @@ const Ue = (t, e, r) => {
|
|
|
346
346
|
clock: a.doneData,
|
|
347
347
|
fn: (c, u) => {
|
|
348
348
|
var b;
|
|
349
|
-
const { id: l, bucket: p, storage:
|
|
350
|
-
return S ? { key: S, id: l, bucket: p, storage:
|
|
349
|
+
const { id: l, bucket: p, storage: m } = u, S = (b = c[l]) == null ? void 0 : b.feature.key;
|
|
350
|
+
return S ? { key: S, id: l, bucket: p, storage: m } : null;
|
|
351
351
|
},
|
|
352
352
|
target: o
|
|
353
353
|
});
|
|
@@ -357,7 +357,7 @@ const Ue = (t, e, r) => {
|
|
|
357
357
|
resolvedFeaturesStore: u
|
|
358
358
|
}) => Object.values(c).map((l) => {
|
|
359
359
|
const p = u.find(
|
|
360
|
-
(
|
|
360
|
+
(m) => m.id === l.id && m.key === l.feature.key
|
|
361
361
|
);
|
|
362
362
|
return p ? {
|
|
363
363
|
id: l.id,
|
|
@@ -378,7 +378,7 @@ const Ue = (t, e, r) => {
|
|
|
378
378
|
clock: a.doneData,
|
|
379
379
|
source: { resolvedFeatures: r },
|
|
380
380
|
filter: ({ resolvedFeatures: c }, { id: u, key: l }) => !c.some(
|
|
381
|
-
(
|
|
381
|
+
(m) => m.id === u && m.key === l
|
|
382
382
|
),
|
|
383
383
|
fn: (c, u) => u,
|
|
384
384
|
target: t.eventBus.prepend((c) => ({
|
|
@@ -399,7 +399,7 @@ const Ue = (t, e, r) => {
|
|
|
399
399
|
function k(c) {
|
|
400
400
|
return e.map((u) => u[c], { skipVoid: !1 });
|
|
401
401
|
}
|
|
402
|
-
function
|
|
402
|
+
function g(c) {
|
|
403
403
|
const u = q(
|
|
404
404
|
async () => {
|
|
405
405
|
},
|
|
@@ -411,7 +411,7 @@ const Ue = (t, e, r) => {
|
|
|
411
411
|
});
|
|
412
412
|
return F({
|
|
413
413
|
source: r,
|
|
414
|
-
filter: (p) => p.some((
|
|
414
|
+
filter: (p) => p.some((m) => m.id === c),
|
|
415
415
|
target: l
|
|
416
416
|
}), F({
|
|
417
417
|
clock: l.doneData,
|
|
@@ -424,7 +424,7 @@ const Ue = (t, e, r) => {
|
|
|
424
424
|
getById: y,
|
|
425
425
|
getByName: k,
|
|
426
426
|
listStore: f,
|
|
427
|
-
getEvokableFeature:
|
|
427
|
+
getEvokableFeature: g
|
|
428
428
|
};
|
|
429
429
|
});
|
|
430
430
|
function Me(t) {
|
|
@@ -570,41 +570,41 @@ function H(t) {
|
|
|
570
570
|
}
|
|
571
571
|
const Xe = x("response"), Ze = w(({ client: t }) => {
|
|
572
572
|
const e = Xe.store({}), r = U(), n = U(), s = E(e, {
|
|
573
|
-
register(
|
|
573
|
+
register(g, c) {
|
|
574
574
|
return {
|
|
575
|
-
...
|
|
575
|
+
...g,
|
|
576
576
|
[c.fieldId]: c.response
|
|
577
577
|
};
|
|
578
578
|
},
|
|
579
|
-
registerBatch(
|
|
579
|
+
registerBatch(g, c) {
|
|
580
580
|
return {
|
|
581
|
-
...
|
|
581
|
+
...g,
|
|
582
582
|
...c
|
|
583
583
|
};
|
|
584
584
|
},
|
|
585
|
-
clear(
|
|
586
|
-
const { [c]: u, ...l } =
|
|
585
|
+
clear(g, c) {
|
|
586
|
+
const { [c]: u, ...l } = g;
|
|
587
587
|
return l;
|
|
588
588
|
},
|
|
589
589
|
clearAll() {
|
|
590
590
|
return {};
|
|
591
591
|
}
|
|
592
592
|
});
|
|
593
|
-
function d(
|
|
594
|
-
if (typeof
|
|
593
|
+
function d(g, c) {
|
|
594
|
+
if (typeof g == "string") {
|
|
595
595
|
if (c === void 0)
|
|
596
596
|
throw new Error("Response is required when registering a single field");
|
|
597
|
-
s.register({ fieldId:
|
|
597
|
+
s.register({ fieldId: g, response: c });
|
|
598
598
|
} else
|
|
599
|
-
s.registerBatch(
|
|
599
|
+
s.registerBatch(g);
|
|
600
600
|
}
|
|
601
|
-
async function o(
|
|
601
|
+
async function o(g) {
|
|
602
602
|
const c = [];
|
|
603
603
|
return await Promise.allSettled(
|
|
604
|
-
Object.entries(
|
|
604
|
+
Object.entries(g).map(async ([u, l]) => {
|
|
605
605
|
let p = l;
|
|
606
|
-
const
|
|
607
|
-
if (!
|
|
606
|
+
const m = t.fields.getById(u).getState();
|
|
607
|
+
if (!m) {
|
|
608
608
|
c.push({
|
|
609
609
|
fieldId: u,
|
|
610
610
|
userMessage: `Field '${u}' not found`,
|
|
@@ -613,8 +613,8 @@ const Xe = x("response"), Ze = w(({ client: t }) => {
|
|
|
613
613
|
});
|
|
614
614
|
return;
|
|
615
615
|
}
|
|
616
|
-
if (
|
|
617
|
-
const S = await P(t,
|
|
616
|
+
if (m.multiple && (typeof p == "string" || typeof p == "number" || typeof p == "boolean") && (p = [p]), m.validation && !de(m.validation) && !H(p)) {
|
|
617
|
+
const S = await P(t, m.validation, {
|
|
618
618
|
$input: p
|
|
619
619
|
});
|
|
620
620
|
if (typeof S == "string") {
|
|
@@ -636,7 +636,7 @@ const Xe = x("response"), Ze = w(({ client: t }) => {
|
|
|
636
636
|
return;
|
|
637
637
|
}
|
|
638
638
|
}
|
|
639
|
-
if (
|
|
639
|
+
if (m.required && H(p)) {
|
|
640
640
|
c.push({
|
|
641
641
|
fieldId: u,
|
|
642
642
|
userMessage: "This field is required",
|
|
@@ -645,7 +645,7 @@ const Xe = x("response"), Ze = w(({ client: t }) => {
|
|
|
645
645
|
});
|
|
646
646
|
return;
|
|
647
647
|
}
|
|
648
|
-
if (!
|
|
648
|
+
if (!m.multiple && Array.isArray(p) && p.length > 1) {
|
|
649
649
|
c.push({
|
|
650
650
|
fieldId: u,
|
|
651
651
|
userMessage: "This field expects a single response",
|
|
@@ -654,8 +654,8 @@ const Xe = x("response"), Ze = w(({ client: t }) => {
|
|
|
654
654
|
});
|
|
655
655
|
return;
|
|
656
656
|
}
|
|
657
|
-
if (
|
|
658
|
-
const S =
|
|
657
|
+
if (m.options) {
|
|
658
|
+
const S = m.options.map((j) => j.value), b = Array.isArray(p) ? p : [p];
|
|
659
659
|
Array.isArray(p) && (b.every((j) => S.includes(j)) || c.push({
|
|
660
660
|
fieldId: u,
|
|
661
661
|
userMessage: "This field expects a valid option",
|
|
@@ -664,22 +664,22 @@ const Xe = x("response"), Ze = w(({ client: t }) => {
|
|
|
664
664
|
}));
|
|
665
665
|
}
|
|
666
666
|
})
|
|
667
|
-
), { responsesToCommit:
|
|
667
|
+
), { responsesToCommit: g, validationErrors: c };
|
|
668
668
|
}
|
|
669
|
-
async function i(
|
|
670
|
-
const { responsesToCommit: c, validationErrors: u } = await o(
|
|
669
|
+
async function i(g) {
|
|
670
|
+
const { responsesToCommit: c, validationErrors: u } = await o(g);
|
|
671
671
|
return u.length ? { errors: u } : (s.registerBatch(c), { errors: [] });
|
|
672
672
|
}
|
|
673
|
-
const a = e.map((
|
|
673
|
+
const a = e.map((g) => g), f = e.map((g) => Object.keys(g).map((u) => ({
|
|
674
674
|
fieldId: u,
|
|
675
|
-
value:
|
|
675
|
+
value: g[u]
|
|
676
676
|
})));
|
|
677
|
-
function y(
|
|
678
|
-
const c = t.fields.getById(
|
|
677
|
+
function y(g) {
|
|
678
|
+
const c = t.fields.getById(g), u = e.map((l) => l[g] || null);
|
|
679
679
|
return D({ f: c, r: u }, ({ f: l, r: p }) => p || (l != null && l.defaultValue ? l.defaultValue : null));
|
|
680
680
|
}
|
|
681
|
-
function k(
|
|
682
|
-
const c = t.fields.getByName(
|
|
681
|
+
function k(g) {
|
|
682
|
+
const c = t.fields.getByName(g);
|
|
683
683
|
return D({ f: c, s: e }, ({ f: u, s: l }) => {
|
|
684
684
|
const p = u && l[u.id] || null;
|
|
685
685
|
return p || (u != null && u.defaultValue ? u.defaultValue : null);
|
|
@@ -706,7 +706,7 @@ const Xe = x("response"), Ze = w(({ client: t }) => {
|
|
|
706
706
|
function et(t) {
|
|
707
707
|
return I(Ze, t);
|
|
708
708
|
}
|
|
709
|
-
const tt = () => "0.0.32-next.
|
|
709
|
+
const tt = () => "0.0.32-next.2";
|
|
710
710
|
function rt() {
|
|
711
711
|
if (V()) {
|
|
712
712
|
const t = [
|
package/dist/esm/server/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createEvent as i, createStore as v, createEffect as C, sample as n, attach as S } from "effector";
|
|
2
|
-
import { h as F } from "../../experience-instance-
|
|
2
|
+
import { h as F } from "../../experience-instance-Bg6BWuwI.js";
|
|
3
3
|
function R() {
|
|
4
4
|
let c, p;
|
|
5
5
|
return {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createDomain as ht, createEvent as O, combine as C, createApi as ot, createEffect as M, attach as
|
|
1
|
+
import { createDomain as ht, createEvent as O, combine as C, createApi as ot, createEffect as M, attach as F, split as yt, sample as m } from "effector";
|
|
2
2
|
import { createFactory as it, invoke as st } from "@withease/factories";
|
|
3
3
|
import { i as wt, s as at, a as Nt } from "./supports-BjhuLJ8z.js";
|
|
4
4
|
import { l as I } from "./logger-C9a75KZn.js";
|
|
@@ -112,9 +112,21 @@ const Et = {
|
|
|
112
112
|
const n = r.filter(H);
|
|
113
113
|
return e.filter(H).length - n.length >= g(t) ? [] : n;
|
|
114
114
|
},
|
|
115
|
+
/**
|
|
116
|
+
* Invoke operator - executes a function with optional arguments
|
|
117
|
+
*
|
|
118
|
+
* Object format (no arguments):
|
|
119
|
+
* { "invoke": { "var": "functionName" } }
|
|
120
|
+
*
|
|
121
|
+
* Array format (with arguments):
|
|
122
|
+
* { "invoke": [{ "var": "functionName" }, arg1, arg2, ...] }
|
|
123
|
+
*
|
|
124
|
+
* Arguments are evaluated as JSONLogic expressions before being passed to the function.
|
|
125
|
+
*/
|
|
115
126
|
// eslint-disable-next-line sonarjs/function-return-type
|
|
116
|
-
invoke(t) {
|
|
117
|
-
|
|
127
|
+
invoke(...t) {
|
|
128
|
+
const [e, ...r] = t;
|
|
129
|
+
return typeof e != "function" ? null : Reflect.apply(e, null, r);
|
|
118
130
|
},
|
|
119
131
|
regexp_matches(t, e) {
|
|
120
132
|
let r = t, n = "";
|
|
@@ -165,8 +177,8 @@ async function p(t, e) {
|
|
|
165
177
|
const o = await p(n[0], e);
|
|
166
178
|
return N(o) ? (await Promise.all(
|
|
167
179
|
o.map(async (d) => {
|
|
168
|
-
const
|
|
169
|
-
return { item: d, shouldInclude:
|
|
180
|
+
const S = await B(await p(n[1], d));
|
|
181
|
+
return { item: d, shouldInclude: S };
|
|
170
182
|
})
|
|
171
183
|
)).filter(({ shouldInclude: d }) => d).map(({ item: d }) => d) : [];
|
|
172
184
|
}
|
|
@@ -175,10 +187,10 @@ async function p(t, e) {
|
|
|
175
187
|
if (!N(o))
|
|
176
188
|
return n.length > 2 ? await p(n[2], e) : null;
|
|
177
189
|
const c = n[1];
|
|
178
|
-
let
|
|
190
|
+
let S = n.length > 2 ? await p(n[2], e) : null;
|
|
179
191
|
for (const k of o)
|
|
180
|
-
|
|
181
|
-
return
|
|
192
|
+
S = await p(c, { current: k, accumulator: S });
|
|
193
|
+
return S;
|
|
182
194
|
}
|
|
183
195
|
case "all": {
|
|
184
196
|
const o = await p(n[0], e);
|
|
@@ -224,12 +236,12 @@ function At(t) {
|
|
|
224
236
|
async function et(t, e, r) {
|
|
225
237
|
const n = t.getStateSnapshot(), s = t.predicates.listStore.getState().reduce((c, d) => ({
|
|
226
238
|
...c,
|
|
227
|
-
[d.name]: () => d.predicate(n)
|
|
239
|
+
[d.name]: (...S) => d.predicate({ ...n, args: S })
|
|
228
240
|
}), {}), a = t.features.listStore.getState().reduce((c, d) => ({
|
|
229
241
|
...c,
|
|
230
242
|
[d.id]: async () => {
|
|
231
|
-
const { bucket:
|
|
232
|
-
return
|
|
243
|
+
const { bucket: S } = await d.getBucket();
|
|
244
|
+
return S;
|
|
233
245
|
}
|
|
234
246
|
}), {}), o = {
|
|
235
247
|
...r,
|
|
@@ -276,18 +288,18 @@ function Bt(t, e) {
|
|
|
276
288
|
});
|
|
277
289
|
r.observe(document.body, { childList: !0, subtree: !0 });
|
|
278
290
|
}
|
|
279
|
-
const G = "picked-root", K = "picked-target",
|
|
291
|
+
const G = "picked-root", K = "picked-target", Ft = "picked-root";
|
|
280
292
|
function Jt(t, e) {
|
|
281
293
|
return [
|
|
282
294
|
...t,
|
|
283
295
|
// Target and replace picked-root web components
|
|
284
296
|
{
|
|
285
|
-
selector: `${
|
|
297
|
+
selector: `${Ft}[experience-id="${e}"]`,
|
|
286
298
|
placement: "replace"
|
|
287
299
|
}
|
|
288
300
|
].flatMap((n) => {
|
|
289
301
|
const s = bt(n.selector).filter(
|
|
290
|
-
(a) =>
|
|
302
|
+
(a) => !_t(a, e) && !$t(a, e)
|
|
291
303
|
);
|
|
292
304
|
return {
|
|
293
305
|
...n,
|
|
@@ -301,10 +313,10 @@ function Qt(t, e) {
|
|
|
301
313
|
function Yt(t, e) {
|
|
302
314
|
t.classList.add(K), t.classList.add(`${K}-${e}`);
|
|
303
315
|
}
|
|
304
|
-
function
|
|
316
|
+
function _t(t, e) {
|
|
305
317
|
return e ? t.classList.contains(`${K}-${e}`) : t.classList.contains(`${K}`);
|
|
306
318
|
}
|
|
307
|
-
function
|
|
319
|
+
function $t(t, e) {
|
|
308
320
|
return e ? t.classList.contains(`${G}-${e}`) : t.classList.contains(G);
|
|
309
321
|
}
|
|
310
322
|
function Mt(t) {
|
|
@@ -356,41 +368,41 @@ function rt(t) {
|
|
|
356
368
|
const ut = (t, e, r, n, s = /* @__PURE__ */ new Set()) => s.has(r.id) ? [] : (s.add(r.id), j(r) && !n ? [r] : e.filter((o) => o.sourceNodeId === r.id).flatMap((o) => {
|
|
357
369
|
const c = t.find((d) => d.id === o.destinationNodeId);
|
|
358
370
|
return c ? ut(t, e, c, !1, s) : [];
|
|
359
|
-
})),
|
|
371
|
+
})), Rt = (t, e, r) => ut(t, e, r, !0, /* @__PURE__ */ new Set()), ft = (t, e, r, n, s = /* @__PURE__ */ new Set()) => {
|
|
360
372
|
if (s.has(r.id)) return [-1, -1];
|
|
361
373
|
s.add(r.id);
|
|
362
374
|
const a = e.filter((d) => d.sourceNodeId === r.id);
|
|
363
375
|
if (a.length === 0) return [0, 0];
|
|
364
376
|
let o = 1 / 0, c = -1 / 0;
|
|
365
377
|
for (const d of a) {
|
|
366
|
-
const
|
|
367
|
-
if (!
|
|
368
|
-
const [k,
|
|
378
|
+
const S = t.find((R) => R.id === d.destinationNodeId);
|
|
379
|
+
if (!S) continue;
|
|
380
|
+
const [k, _] = ft(
|
|
369
381
|
t,
|
|
370
382
|
e,
|
|
371
|
-
|
|
383
|
+
S,
|
|
372
384
|
!1,
|
|
373
385
|
new Set(s)
|
|
374
386
|
);
|
|
375
|
-
k !== -1 && (o = Math.min(o, k + 1), c = Math.max(c,
|
|
387
|
+
k !== -1 && (o = Math.min(o, k + 1), c = Math.max(c, _ + 1));
|
|
376
388
|
}
|
|
377
389
|
return o === 1 / 0 ? [-1, -1] : [o, c];
|
|
378
|
-
},
|
|
390
|
+
}, Pt = (t, e, r) => ft(t, e, r, !0, /* @__PURE__ */ new Set()), lt = (t, e, r, n = /* @__PURE__ */ new Set()) => {
|
|
379
391
|
if (n.has(r.id)) return [-1, -1];
|
|
380
392
|
if (n.add(r.id), r.type === "origin") return [0, 0];
|
|
381
393
|
const s = e.filter((c) => c.destinationNodeId === r.id);
|
|
382
394
|
if (s.length === 0) return [-1, -1];
|
|
383
395
|
let a = 1 / 0, o = -1 / 0;
|
|
384
396
|
for (const c of s) {
|
|
385
|
-
const d = t.find((
|
|
397
|
+
const d = t.find((_) => _.id === c.sourceNodeId);
|
|
386
398
|
if (!d) continue;
|
|
387
|
-
const [
|
|
399
|
+
const [S, k] = lt(
|
|
388
400
|
t,
|
|
389
401
|
e,
|
|
390
402
|
d,
|
|
391
403
|
new Set(n)
|
|
392
404
|
);
|
|
393
|
-
|
|
405
|
+
S !== -1 && (a = Math.min(a, S + 1), o = Math.max(o, k + 1));
|
|
394
406
|
}
|
|
395
407
|
return a === 1 / 0 ? [-1, -1] : [a, o];
|
|
396
408
|
}, Ct = (t, e, r) => lt(t, e, r, /* @__PURE__ */ new Set()), dt = (t) => t.find((r) => r.type === "origin") || null, X = (t, e, r) => {
|
|
@@ -414,17 +426,17 @@ const z = ht("experience-instance"), jt = it(
|
|
|
414
426
|
experience: e,
|
|
415
427
|
target: r
|
|
416
428
|
}) => {
|
|
417
|
-
const n = O(), s = O(), a = O(), o = O(), c = O(), d = O(),
|
|
429
|
+
const n = O(), s = O(), a = O(), o = O(), c = O(), d = O(), S = e.componentStore, k = z.store("transitioning"), _ = t.history.entriesStore.map((i) => i.filter((f) => f.experienceId === e.id)), R = _.map((i) => i.filter((f) => j(f.node))), x = _.map((i) => {
|
|
418
430
|
var f;
|
|
419
431
|
return ((f = i[i.length - 1]) == null ? void 0 : f.node) || null;
|
|
420
432
|
}), u = C(
|
|
421
433
|
e.treeStore,
|
|
422
434
|
x,
|
|
423
435
|
({ steps: i }, f) => i.find((l) => f && j(f) && l.id === f.stepId) || null
|
|
424
|
-
),
|
|
436
|
+
), h = C(
|
|
425
437
|
e.treeStore,
|
|
426
438
|
x,
|
|
427
|
-
({ nodes: i, edges: f }, l) => l ?
|
|
439
|
+
({ nodes: i, edges: f }, l) => l ? Rt(i, f, l) : []
|
|
428
440
|
), v = C(
|
|
429
441
|
e.treeStore,
|
|
430
442
|
x,
|
|
@@ -432,31 +444,31 @@ const z = ht("experience-instance"), jt = it(
|
|
|
432
444
|
), T = C(
|
|
433
445
|
e.treeStore,
|
|
434
446
|
x,
|
|
435
|
-
({ nodes: i, edges: f }, l) => l ?
|
|
436
|
-
), A = z.store(!1),
|
|
447
|
+
({ nodes: i, edges: f }, l) => l ? Pt(i, f, l) : [-1, -1]
|
|
448
|
+
), A = z.store(!1), $ = ot(A, {
|
|
437
449
|
open: () => !0,
|
|
438
450
|
close: () => !1,
|
|
439
451
|
toggle: (i) => !i,
|
|
440
452
|
set: (i, f) => f
|
|
441
453
|
}), pt = M(async () => {
|
|
442
454
|
t.history.back({ experienceId: e.id });
|
|
443
|
-
}), gt =
|
|
455
|
+
}), gt = F({
|
|
444
456
|
source: e.treeStore,
|
|
445
457
|
effect: async (i, f) => {
|
|
446
458
|
const l = i.nodes.find((w) => j(w) && w.stepId === f);
|
|
447
459
|
l && t.history.push({ experienceId: e.id, node: l });
|
|
448
460
|
}
|
|
449
|
-
}), J =
|
|
461
|
+
}), J = F({
|
|
450
462
|
source: x,
|
|
451
463
|
effect: (i) => {
|
|
452
464
|
}
|
|
453
|
-
}), U =
|
|
465
|
+
}), U = F({
|
|
454
466
|
source: e.treeStore,
|
|
455
467
|
effect: async ({ nodes: i }) => dt(i)
|
|
456
|
-
}), V =
|
|
468
|
+
}), V = F({
|
|
457
469
|
source: e.treeStore,
|
|
458
470
|
effect: async ({ nodes: i, edges: f }, l) => X(l, i, f)
|
|
459
|
-
}), q =
|
|
471
|
+
}), q = F({
|
|
460
472
|
source: e.treeStore,
|
|
461
473
|
effect: async ({ nodes: i, edges: f, conditionals: l }, w) => {
|
|
462
474
|
if (!w)
|
|
@@ -464,10 +476,10 @@ const z = ht("experience-instance"), jt = it(
|
|
|
464
476
|
const L = l.find((b) => b.id === w.conditionalId);
|
|
465
477
|
if (!L)
|
|
466
478
|
return;
|
|
467
|
-
const E = w.id,
|
|
468
|
-
return Ht(!!
|
|
479
|
+
const E = w.id, y = await et(t, L.condition);
|
|
480
|
+
return Ht(!!y, E, i, f);
|
|
469
481
|
}
|
|
470
|
-
}), Q =
|
|
482
|
+
}), Q = F({
|
|
471
483
|
source: e.treeStore,
|
|
472
484
|
effect: async ({ nodes: i, edges: f }, l) => {
|
|
473
485
|
if (!l || !rt(l))
|
|
@@ -481,16 +493,16 @@ const z = ht("experience-instance"), jt = it(
|
|
|
481
493
|
if (!L) {
|
|
482
494
|
I("warn", `Action '${w}' not registered on client`);
|
|
483
495
|
const E = f.find(
|
|
484
|
-
(
|
|
496
|
+
(y) => y.sourceNodeId === l.id && y.sourceNodeHandle === "false"
|
|
485
497
|
);
|
|
486
|
-
return E ? i.find((
|
|
498
|
+
return E ? i.find((y) => y.id === E.destinationNodeId) : null;
|
|
487
499
|
}
|
|
488
500
|
if (typeof L.action != "function") {
|
|
489
501
|
I("warn", `Action '${w}' is not a function`);
|
|
490
502
|
const E = f.find(
|
|
491
|
-
(
|
|
503
|
+
(y) => y.sourceNodeId === l.id && y.sourceNodeHandle === "false"
|
|
492
504
|
);
|
|
493
|
-
return E ? i.find((
|
|
505
|
+
return E ? i.find((y) => y.id === E.destinationNodeId) : null;
|
|
494
506
|
}
|
|
495
507
|
try {
|
|
496
508
|
I("info", `Executing action: ${w}`), await L.action(w);
|
|
@@ -499,31 +511,31 @@ const z = ht("experience-instance"), jt = it(
|
|
|
499
511
|
);
|
|
500
512
|
if (!E)
|
|
501
513
|
return I("warn", `No 'true' edge found for action node ${l.id}`), null;
|
|
502
|
-
const
|
|
503
|
-
return I("info", `Action '${w}' succeeded, moving to node ${
|
|
514
|
+
const y = i.find((b) => b.id === E.destinationNodeId);
|
|
515
|
+
return I("info", `Action '${w}' succeeded, moving to node ${y == null ? void 0 : y.id}`), y || null;
|
|
504
516
|
} catch (E) {
|
|
505
517
|
I("warn", `Action '${w}' failed:`, E);
|
|
506
|
-
const
|
|
518
|
+
const y = f.find(
|
|
507
519
|
(W) => W.sourceNodeId === l.id && W.sourceNodeHandle === "false"
|
|
508
520
|
);
|
|
509
|
-
if (!
|
|
521
|
+
if (!y)
|
|
510
522
|
return I("warn", `No 'false' edge found for action node ${l.id}`), null;
|
|
511
|
-
const b = i.find((W) => W.id ===
|
|
523
|
+
const b = i.find((W) => W.id === y.destinationNodeId);
|
|
512
524
|
return I("info", `Action '${w}' failed, moving to node ${b == null ? void 0 : b.id}`), b || null;
|
|
513
525
|
}
|
|
514
526
|
}
|
|
515
527
|
}), mt = M((i) => {
|
|
516
528
|
if (i)
|
|
517
529
|
return t.launchExperienceById(i.experienceId);
|
|
518
|
-
}), Y =
|
|
530
|
+
}), Y = F({
|
|
519
531
|
source: [x, e.treeStore],
|
|
520
532
|
effect: async ([i, { nodes: f, edges: l }]) => X(i, f, l)
|
|
521
|
-
}),
|
|
533
|
+
}), P = F({
|
|
522
534
|
source: [x, e.treeStore],
|
|
523
535
|
effect: async ([i, { nodes: f, edges: l }]) => X(i, f, l)
|
|
524
536
|
}), St = M((i) => {
|
|
525
537
|
t.history.push({ experienceId: e.id, node: i });
|
|
526
|
-
}), Z =
|
|
538
|
+
}), Z = F({
|
|
527
539
|
source: e.configStore,
|
|
528
540
|
effect: async ({ initializeOpenLogic: i }) => At(i) ? !!await et(t, i) : i ?? !1
|
|
529
541
|
});
|
|
@@ -544,7 +556,7 @@ const z = ht("experience-instance"), jt = it(
|
|
|
544
556
|
q.doneData,
|
|
545
557
|
V.doneData,
|
|
546
558
|
U.doneData,
|
|
547
|
-
|
|
559
|
+
P.doneData,
|
|
548
560
|
Y.doneData,
|
|
549
561
|
Q.doneData
|
|
550
562
|
],
|
|
@@ -552,7 +564,7 @@ const z = ht("experience-instance"), jt = it(
|
|
|
552
564
|
target: St
|
|
553
565
|
}), m({
|
|
554
566
|
clock: s,
|
|
555
|
-
target:
|
|
567
|
+
target: P
|
|
556
568
|
}), m({
|
|
557
569
|
clock: s,
|
|
558
570
|
source: u,
|
|
@@ -563,7 +575,7 @@ const z = ht("experience-instance"), jt = it(
|
|
|
563
575
|
experience: e
|
|
564
576
|
}))
|
|
565
577
|
}), m({
|
|
566
|
-
clock:
|
|
578
|
+
clock: P.done,
|
|
567
579
|
source: u,
|
|
568
580
|
filter: Boolean,
|
|
569
581
|
target: t.eventBus.prepend((i) => ({
|
|
@@ -572,7 +584,7 @@ const z = ht("experience-instance"), jt = it(
|
|
|
572
584
|
experience: e
|
|
573
585
|
}))
|
|
574
586
|
}), m({
|
|
575
|
-
clock:
|
|
587
|
+
clock: P.fail,
|
|
576
588
|
source: u,
|
|
577
589
|
filter: Boolean,
|
|
578
590
|
target: t.eventBus.prepend((i) => ({
|
|
@@ -588,7 +600,7 @@ const z = ht("experience-instance"), jt = it(
|
|
|
588
600
|
q.pending,
|
|
589
601
|
V.pending,
|
|
590
602
|
U.pending,
|
|
591
|
-
|
|
603
|
+
P.pending
|
|
592
604
|
]),
|
|
593
605
|
fn: (i) => i.some(Boolean) ? "transitioning" : "ready",
|
|
594
606
|
target: k
|
|
@@ -640,27 +652,27 @@ const z = ht("experience-instance"), jt = it(
|
|
|
640
652
|
experienceId: e.id,
|
|
641
653
|
configStore: e.configStore,
|
|
642
654
|
target: r,
|
|
643
|
-
componentStore:
|
|
655
|
+
componentStore: S,
|
|
644
656
|
// state
|
|
645
657
|
stateStore: k,
|
|
646
658
|
// open close
|
|
647
659
|
isOpenStore: A,
|
|
648
|
-
open:
|
|
649
|
-
close:
|
|
650
|
-
toggleOpen:
|
|
651
|
-
setOpen:
|
|
660
|
+
open: $.open,
|
|
661
|
+
close: $.close,
|
|
662
|
+
toggleOpen: $.toggle,
|
|
663
|
+
setOpen: $.set,
|
|
652
664
|
// nodes
|
|
653
665
|
treeStore: e.treeStore,
|
|
654
666
|
currentNodeStore: x,
|
|
655
667
|
currentStepStore: u,
|
|
656
|
-
nextReachableStepNodesStore:
|
|
668
|
+
nextReachableStepNodesStore: h,
|
|
657
669
|
stepsToOriginStore: v,
|
|
658
670
|
stepsToLeafStore: T,
|
|
659
671
|
// history
|
|
660
672
|
goToNextStep: s,
|
|
661
673
|
goToPreviousStep: a,
|
|
662
674
|
goToStepById: o,
|
|
663
|
-
stepsHistoryStore:
|
|
675
|
+
stepsHistoryStore: R
|
|
664
676
|
};
|
|
665
677
|
}
|
|
666
678
|
);
|
|
@@ -669,19 +681,19 @@ function Wt(t) {
|
|
|
669
681
|
}
|
|
670
682
|
const Gt = it(({ client: t }) => {
|
|
671
683
|
const e = z.store({}), r = O(), n = O(), s = O(), a = ot(e, {
|
|
672
|
-
register(u,
|
|
684
|
+
register(u, h) {
|
|
673
685
|
const v = [
|
|
674
|
-
...u[
|
|
686
|
+
...u[h.experienceId] ?? []
|
|
675
687
|
];
|
|
676
|
-
return v.push(
|
|
688
|
+
return v.push(h), {
|
|
677
689
|
...u,
|
|
678
|
-
[
|
|
690
|
+
[h.experienceId]: v
|
|
679
691
|
};
|
|
680
692
|
},
|
|
681
|
-
unregister(u,
|
|
693
|
+
unregister(u, h) {
|
|
682
694
|
var A;
|
|
683
|
-
const v =
|
|
684
|
-
(
|
|
695
|
+
const v = h.experienceId, T = (A = u[v]) == null ? void 0 : A.filter(
|
|
696
|
+
($) => $ !== h
|
|
685
697
|
);
|
|
686
698
|
return {
|
|
687
699
|
...u,
|
|
@@ -689,7 +701,7 @@ const Gt = it(({ client: t }) => {
|
|
|
689
701
|
};
|
|
690
702
|
}
|
|
691
703
|
}), o = M(
|
|
692
|
-
({ experience: u, target:
|
|
704
|
+
({ experience: u, target: h }) => Wt({ client: t, experience: u, target: h })
|
|
693
705
|
), c = M((u) => {
|
|
694
706
|
a.register(u);
|
|
695
707
|
}), d = M(
|
|
@@ -698,19 +710,19 @@ const Gt = it(({ client: t }) => {
|
|
|
698
710
|
s(u);
|
|
699
711
|
});
|
|
700
712
|
}
|
|
701
|
-
),
|
|
713
|
+
), S = M((u) => {
|
|
702
714
|
a.unregister(u);
|
|
703
715
|
}), k = M((u) => {
|
|
704
|
-
const
|
|
705
|
-
if (!
|
|
716
|
+
const h = u.componentStore.getState();
|
|
717
|
+
if (!h) {
|
|
706
718
|
I("warn", "No app component registered. Skipping init.");
|
|
707
719
|
return;
|
|
708
720
|
}
|
|
709
|
-
const v =
|
|
721
|
+
const v = h.frameworkStore.getState();
|
|
710
722
|
if (!v) {
|
|
711
723
|
I(
|
|
712
724
|
"error",
|
|
713
|
-
`No framework registered for component '${
|
|
725
|
+
`No framework registered for component '${h.name}'. Skipping rendering.`
|
|
714
726
|
);
|
|
715
727
|
return;
|
|
716
728
|
}
|
|
@@ -724,9 +736,9 @@ const Gt = it(({ client: t }) => {
|
|
|
724
736
|
}
|
|
725
737
|
const A = Ot(T);
|
|
726
738
|
try {
|
|
727
|
-
v.render(A,
|
|
728
|
-
} catch (
|
|
729
|
-
I("error",
|
|
739
|
+
v.render(A, h.component, t, u);
|
|
740
|
+
} catch ($) {
|
|
741
|
+
I("error", $);
|
|
730
742
|
}
|
|
731
743
|
});
|
|
732
744
|
m({
|
|
@@ -734,7 +746,7 @@ const Gt = it(({ client: t }) => {
|
|
|
734
746
|
target: o
|
|
735
747
|
}), m({
|
|
736
748
|
clock: s,
|
|
737
|
-
target:
|
|
749
|
+
target: S
|
|
738
750
|
}), m({
|
|
739
751
|
clock: o.doneData,
|
|
740
752
|
target: [
|
|
@@ -752,17 +764,17 @@ const Gt = it(({ client: t }) => {
|
|
|
752
764
|
clock: n,
|
|
753
765
|
target: k
|
|
754
766
|
});
|
|
755
|
-
function
|
|
756
|
-
r({ experience: u, target:
|
|
767
|
+
function _(u, h) {
|
|
768
|
+
r({ experience: u, target: h });
|
|
757
769
|
}
|
|
758
|
-
const
|
|
770
|
+
const R = e.map((u) => Object.values(u).flat());
|
|
759
771
|
function x(u) {
|
|
760
|
-
return e.map((
|
|
772
|
+
return e.map((h) => h[u] || [], { skipVoid: !1 });
|
|
761
773
|
}
|
|
762
774
|
return {
|
|
763
|
-
spawn:
|
|
775
|
+
spawn: _,
|
|
764
776
|
getByExperienceId: x,
|
|
765
|
-
listStore:
|
|
777
|
+
listStore: R
|
|
766
778
|
};
|
|
767
779
|
});
|
|
768
780
|
function Zt(t) {
|
|
@@ -774,7 +786,7 @@ export {
|
|
|
774
786
|
Qt as c,
|
|
775
787
|
zt as d,
|
|
776
788
|
et as e,
|
|
777
|
-
|
|
789
|
+
$t as f,
|
|
778
790
|
Jt as g,
|
|
779
791
|
Wt as h,
|
|
780
792
|
At as i,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const i=require("effector"),q=require("@withease/factories"),H=require("./supports-YvpQZxbh.cjs"),N=require("./logger-BsmHUUw1.cjs"),ge=require("./object-BbFTsGh3.cjs");function me(e){return typeof e=="number"&&!isNaN(e)}function R(e){return typeof e=="string"}function E(e){return Array.isArray(e)}function ne(e){return e instanceof Promise}function Z(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&Object.keys(e).length===1}function m(e){if(me(e))return e;const t=parseFloat(`${e}`);return isNaN(t)?0:t}function T(e){return`${e}`}const he={"==":(e,t)=>e==t,"===":(e,t)=>e===t,"!=":(e,t)=>e!=t,"!==":(e,t)=>e!==t,">":(e,t)=>m(e)>m(t),">=":(e,t)=>m(e)>=m(t),"<":(e,t,r)=>{const n=m(e),a=m(t);if(r===void 0)return n<a;const c=m(r);return n<a&&a<c},"<=":(e,t,r)=>{const n=m(e),a=m(t);if(r===void 0)return n<=a;const c=m(r);return n<=a&&a<=c},"!!":async e=>await O(e),"!":async e=>!await O(e),"%":(e,t)=>m(e)%m(t),log:e=>(console.log(e),e),in:(e,t)=>t?R(t)?t.indexOf(T(e))!==-1:E(t)?t.includes(e):!1:!1,cat:(...e)=>e.map(T).join(""),substr:(e,t,r)=>{const n=T(e),a=m(t);if(r===void 0)return n.substr(a);const c=m(r);if(c<0){const o=n.substr(a);return o.substr(0,o.length+c)}return n.substr(a,c)},"+":(...e)=>e.reduce((t,r)=>m(t)+m(r),0),"*":(...e)=>e.reduce((t,r)=>m(t)*m(r),1),"-":(e,t)=>{const r=m(e);return t===void 0?-r:r-m(t)},"/":(e,t)=>m(e)/m(t),min:(...e)=>Math.min(...e.map(m)),max:(...e)=>Math.max(...e.map(m)),merge:(...e)=>e.reduce((t,r)=>E(r)?t.concat(r):t.concat([r]),[]),var(e,t){const r=arguments.length>1?t:null;if(e===""||e==="."||e===null||e===void 0)return this;if(typeof e=="number"&&Array.isArray(this))return e>=0&&e<this.length?this[e]:r;const n=T(e);if(n===""||n===".")return this;const a=n.split(".");let c=this;for(const o of a){if(c==null)return r;if(Array.isArray(c)){const u=parseInt(o,10);isNaN(u)?c=c[o]:c=c[u]}else c=c[o]}return c!==void 0?c:r},async missing(...e){const t=E(e[0])?e[0]:e,r=[];for(const n of t){const a=await g({var:n},this);(a===null||a==="")&&r.push(`${n}`)}return r},async missing_some(e,t){const r=await g({missing:t},this);if(!E(r)||!E(t))return[];const n=r.filter(R);return t.filter(R).length-n.length>=m(e)?[]:n},invoke(...e){const[t,...r]=e;return typeof t!="function"?null:Reflect.apply(t,null,r)},regexp_matches(e,t){let r=e,n="";if(E(e)){const[c,o]=e;r=c,n=o}return!R(r)||!R(n)?!1:new RegExp(r,n).test(T(t))},throw(e){throw new Error(T(e))}};async function g(e,t){if(!e)return e;if(ne(e))return g(await e,t);if(E(e))return Promise.all(e.map(o=>g(o,t)));if(!Z(e))return e;const r=Se(e);let n=r?e[r]??[]:[];switch(E(n)||(n=[n]),r){case"if":case"?:":for(let o=0;o<n.length-1;o+=2)if(await O(await g(n[o],t)))return g(n[o+1],t);return n.length%2===1?g(n[n.length-1],t):null;case"and":{let o=null;for(const u of n)if(o=await g(u,t),!await O(o))return o;return o}case"or":{let o=null;for(const u of n)if(o=await g(u,t),await O(o))return o;return o}case"map":{const o=await g(n[0],t);return E(o)?await Promise.all(o.map(u=>g(n[1],u))):[]}case"filter":{const o=await g(n[0],t);return E(o)?(await Promise.all(o.map(async p=>{const h=await O(await g(n[1],p));return{item:p,shouldInclude:h}}))).filter(({shouldInclude:p})=>p).map(({item:p})=>p):[]}case"reduce":{const o=await g(n[0],t);if(!E(o))return n.length>2?await g(n[2],t):null;const u=n[1];let h=n.length>2?await g(n[2],t):null;for(const k of o)h=await g(u,{current:k,accumulator:h});return h}case"all":{const o=await g(n[0],t);if(!E(o)||o.length===0)return!1;for(const u of o)if(!await O(await g(n[1],u)))return!1;return!0}case"some":{const o=await g(n[0],t);if(!E(o))return!1;for(const u of o)if(await O(await g(n[1],u)))return!0;return!1}case"none":{const o=await g(n[0],t);if(!E(o))return!0;for(const u of o)if(await O(await g(n[1],u)))return!1;return!0}case"catch":try{return await g(n[0],t)}catch(o){return Z(o)?await g(o,t):n[1]?await g(n[1],o):o instanceof Error?o.message:o}}const a=await Promise.all(n.map(o=>g(o,t))),c=r?he[r]:void 0;if(!c)throw new Error(`Unrecognized operation ${r}`);return c.apply(t,a)}async function O(e){return ne(e)?O(await e):!(Array.isArray(e)&&e.length===0)&&!!e}function Se(e){return Object.keys(e)[0]}function re(e){return!ge.isEmpty(e)}async function V(e,t,r){const n=e.getStateSnapshot(),a=e.predicates.listStore.getState().reduce((u,p)=>({...u,[p.name]:(...h)=>p.predicate({...n,args:h})}),{}),c=e.features.listStore.getState().reduce((u,p)=>({...u,[p.id]:async()=>{const{bucket:h}=await p.getBucket();return h}}),{}),o={...r,responses:e.responses.getAllStore.getState(),location:typeof n.location=="object"?{hash:n.location.hash,host:n.location.host,hostname:n.location.hostname,href:n.location.href,origin:n.location.origin,pathname:n.location.pathname,port:n.location.port,protocol:n.location.protocol,search:n.location.search}:void 0,predicates:a,features:c};return await g(t,o)}function ye(e){return!H.supportsWindow()||!H.supportsDocument()?[]:Array.from(window.document.querySelectorAll(e)).filter(t=>t instanceof HTMLElement)}const we="open";function Ee(e){if(!H.supportsShadowRoot())throw new Error("Shadow DOM is not supported in this environment");return e.attachShadow({mode:we})}function Ne(){return new Promise((e,t)=>{if(!H.supportsDocument()){t();return}document.readyState!=="loading"?e():document.addEventListener("readystatechange",()=>e(),{once:!0})})}function Ie(e,t){const r=new MutationObserver(n=>{document.contains(e)||(r.disconnect(),t())});r.observe(document.body,{childList:!0,subtree:!0})}const C="picked-root",j="picked-target",xe="picked-root";function ke(e,t){return[...e,{selector:`${xe}[experience-id="${t}"]`,placement:"replace"}].flatMap(n=>{const a=ye(n.selector).filter(c=>!Ae(c,t)&&!oe(c,t));return{...n,elements:a}})}function ve(e,t){return e.flatMap(r=>r.elements.map(n=>Fe(n,r.placement,t)))}function be(e,t){e.classList.add(j),e.classList.add(`${j}-${t}`)}function Ae(e,t){return t?e.classList.contains(`${j}-${t}`):e.classList.contains(`${j}`)}function oe(e,t){return t?e.classList.contains(`${C}-${t}`):e.classList.contains(C)}function Oe(e){const t=document.createElement("div");return t.style.display="block",t.classList.add(C),t.classList.add(`${C}-${e}`),t}function Fe(e,t,r){let n;const a=Oe(r);if(e instanceof Document)n=e.body.appendChild(a);else{switch(t){case"replace":e.replaceWith(a);break;case"before":e.before(a);break;case"after":e.after(a);break;case"prepend":e.prepend(a);break;default:e.append(a);break}n=a}return n}function Be(e){return e.type==="conditional"}function M(e){return e.type==="step"}function _e(e){return e.type==="experience"}function ee(e){return e.type==="origin"}function te(e){return e.type==="action"}const se=(e,t,r,n,a=new Set)=>a.has(r.id)?[]:(a.add(r.id),M(r)&&!n?[r]:t.filter(o=>o.sourceNodeId===r.id).flatMap(o=>{const u=e.find(p=>p.id===o.destinationNodeId);return u?se(e,t,u,!1,a):[]})),$e=(e,t,r)=>se(e,t,r,!0,new Set),ie=(e,t,r,n,a=new Set)=>{if(a.has(r.id))return[-1,-1];a.add(r.id);const c=t.filter(p=>p.sourceNodeId===r.id);if(c.length===0)return[0,0];let o=1/0,u=-1/0;for(const p of c){const h=e.find(L=>L.id===p.destinationNodeId);if(!h)continue;const[k,F]=ie(e,t,h,!1,new Set(a));k!==-1&&(o=Math.min(o,k+1),u=Math.max(u,F+1))}return o===1/0?[-1,-1]:[o,u]},Te=(e,t,r)=>ie(e,t,r,!0,new Set),ae=(e,t,r,n=new Set)=>{if(n.has(r.id))return[-1,-1];if(n.add(r.id),r.type==="origin")return[0,0];const a=t.filter(u=>u.destinationNodeId===r.id);if(a.length===0)return[-1,-1];let c=1/0,o=-1/0;for(const u of a){const p=e.find(F=>F.id===u.sourceNodeId);if(!p)continue;const[h,k]=ae(e,t,p,new Set(n));h!==-1&&(c=Math.min(c,h+1),o=Math.max(o,k+1))}return c===1/0?[-1,-1]:[c,o]},Me=(e,t,r)=>ae(e,t,r,new Set),ce=e=>e.find(r=>r.type==="origin")||null,U=(e,t,r)=>{if(!e)return ce(t);const n=r.find(c=>c.sourceNodeId===e.id);if(!n)return null;const a=t.find(c=>c.id===n.destinationNodeId);return a||null};async function Le(e,t,r,n){const a=e?"true":"false",c=n.find(o=>o.sourceNodeHandle===a&&o.sourceNodeId===t);return r.find(o=>o.id===(c==null?void 0:c.destinationNodeId))}const X=i.createDomain("experience-instance"),De=q.createFactory(({client:e,experience:t,target:r})=>{const n=i.createEvent(),a=i.createEvent(),c=i.createEvent(),o=i.createEvent(),u=i.createEvent(),p=i.createEvent(),h=t.componentStore,k=X.store("transitioning"),F=e.history.entriesStore.map(s=>s.filter(l=>l.experienceId===t.id)),L=F.map(s=>s.filter(l=>M(l.node))),I=F.map(s=>{var l;return((l=s[s.length-1])==null?void 0:l.node)||null}),f=i.combine(t.treeStore,I,({steps:s},l)=>s.find(d=>l&&M(l)&&d.id===l.stepId)||null),S=i.combine(t.treeStore,I,({nodes:s,edges:l},d)=>d?$e(s,l,d):[]),A=i.combine(t.treeStore,I,({nodes:s,edges:l},d)=>d?Me(s,l,d):[-1,-1]),_=i.combine(t.treeStore,I,({nodes:s,edges:l},d)=>d?Te(s,l,d):[-1,-1]),v=X.store(!1),B=i.createApi(v,{open:()=>!0,close:()=>!1,toggle:s=>!s,set:(s,l)=>l}),fe=i.createEffect(async()=>{e.history.back({experienceId:t.id})}),le=i.attach({source:t.treeStore,effect:async(s,l)=>{const d=s.nodes.find(w=>M(w)&&w.stepId===l);d&&e.history.push({experienceId:t.id,node:d})}}),z=i.attach({source:I,effect:s=>{}}),W=i.attach({source:t.treeStore,effect:async({nodes:s})=>ce(s)}),G=i.attach({source:t.treeStore,effect:async({nodes:s,edges:l},d)=>U(d,s,l)}),K=i.attach({source:t.treeStore,effect:async({nodes:s,edges:l,conditionals:d},w)=>{if(!w)return;const $=d.find(b=>b.id===w.conditionalId);if(!$)return;const x=w.id,y=await V(e,$.condition);return Le(!!y,x,s,l)}}),J=i.attach({source:t.treeStore,effect:async({nodes:s,edges:l},d)=>{if(!d||!te(d))return;const w=d.action;if(!w){N.logger("warn",`Action node ${d.id} has no action name`);return}const $=e.actions.getByName(w).getState();if(!$){N.logger("warn",`Action '${w}' not registered on client`);const x=l.find(y=>y.sourceNodeId===d.id&&y.sourceNodeHandle==="false");return x?s.find(y=>y.id===x.destinationNodeId):null}if(typeof $.action!="function"){N.logger("warn",`Action '${w}' is not a function`);const x=l.find(y=>y.sourceNodeId===d.id&&y.sourceNodeHandle==="false");return x?s.find(y=>y.id===x.destinationNodeId):null}try{N.logger("info",`Executing action: ${w}`),await $.action(w);const x=l.find(b=>b.sourceNodeId===d.id&&b.sourceNodeHandle==="true");if(!x)return N.logger("warn",`No 'true' edge found for action node ${d.id}`),null;const y=s.find(b=>b.id===x.destinationNodeId);return N.logger("info",`Action '${w}' succeeded, moving to node ${y==null?void 0:y.id}`),y||null}catch(x){N.logger("warn",`Action '${w}' failed:`,x);const y=l.find(P=>P.sourceNodeId===d.id&&P.sourceNodeHandle==="false");if(!y)return N.logger("warn",`No 'false' edge found for action node ${d.id}`),null;const b=s.find(P=>P.id===y.destinationNodeId);return N.logger("info",`Action '${w}' failed, moving to node ${b==null?void 0:b.id}`),b||null}}}),de=i.createEffect(s=>{if(s)return e.launchExperienceById(s.experienceId)}),Q=i.attach({source:[I,t.treeStore],effect:async([s,{nodes:l,edges:d}])=>U(s,l,d)}),D=i.attach({source:[I,t.treeStore],effect:async([s,{nodes:l,edges:d}])=>U(s,l,d)}),pe=i.createEffect(s=>{e.history.push({experienceId:t.id,node:s})}),Y=i.attach({source:t.configStore,effect:async({initializeOpenLogic:s})=>re(s)?!!await V(e,s):s??!1});return i.split({source:I,match:s=>s?Be(s)?"condition":M(s)?"step":_e(s)?"launchExperience":ee(s)?"origin":te(s)?"action":"other":"none",cases:{none:W,origin:G,condition:K,step:z,launchExperience:de,action:J,__:i.createEvent()}}),i.sample({clock:[K.doneData,G.doneData,W.doneData,D.doneData,Q.doneData,J.doneData],filter:Boolean,target:pe}),i.sample({clock:a,target:D}),i.sample({clock:a,source:f,filter:Boolean,target:e.eventBus.prepend(s=>({type:"step_submit",step:s,experience:t}))}),i.sample({clock:D.done,source:f,filter:Boolean,target:e.eventBus.prepend(s=>({type:"step_submit_success",step:s,experience:t}))}),i.sample({clock:D.fail,source:f,filter:Boolean,target:e.eventBus.prepend(s=>({type:"step_submit_error",step:s,experience:t}))}),i.sample({clock:c,target:fe}),i.sample({clock:o,target:le}),i.sample({source:i.combine([K.pending,G.pending,W.pending,D.pending]),fn:s=>s.some(Boolean)?"transitioning":"ready",target:k}),i.sample({clock:z.doneData,source:f,filter:Boolean,target:e.eventBus.prepend(s=>({type:"step_enter",step:s,experience:t}))}),i.sample({clock:p,target:Y}),i.sample({source:Y.doneData,fn:Boolean,target:v}),i.sample({source:I,clock:n,filter:s=>s?ee(s):!0,target:Q}),i.sample({source:v,filter:Boolean,target:n}),i.sample({source:v,filter:Boolean,target:e.eventBus.prepend(()=>({type:"experience_open",experience:t}))}),i.sample({source:v,filter:s=>!s,target:e.eventBus.prepend(()=>({type:"experience_close",experience:t}))}),i.sample({clock:u,target:[p]}),u(),{id:Math.random().toString(36).substring(7),experienceId:t.id,configStore:t.configStore,target:r,componentStore:h,stateStore:k,isOpenStore:v,open:B.open,close:B.close,toggleOpen:B.toggle,setOpen:B.set,treeStore:t.treeStore,currentNodeStore:I,currentStepStore:f,nextReachableStepNodesStore:S,stepsToOriginStore:A,stepsToLeafStore:_,goToNextStep:a,goToPreviousStep:c,goToStepById:o,stepsHistoryStore:L}});function ue(e){return q.invoke(De,e)}const Re=q.createFactory(({client:e})=>{const t=X.store({}),r=i.createEvent(),n=i.createEvent(),a=i.createEvent(),c=i.createApi(t,{register(f,S){const A=[...f[S.experienceId]??[]];return A.push(S),{...f,[S.experienceId]:A}},unregister(f,S){var v;const A=S.experienceId,_=(v=f[A])==null?void 0:v.filter(B=>B!==S);return{...f,[A]:_??[]}}}),o=i.createEffect(({experience:f,target:S})=>ue({client:e,experience:f,target:S})),u=i.createEffect(f=>{c.register(f)}),p=i.createEffect(f=>{f.target&&Ie(f.target,()=>{a(f)})}),h=i.createEffect(f=>{c.unregister(f)}),k=i.createEffect(f=>{const S=f.componentStore.getState();if(!S){N.logger("warn","No app component registered. Skipping init.");return}const A=S.frameworkStore.getState();if(!A){N.logger("error",`No framework registered for component '${S.name}'. Skipping rendering.`);return}const _=f.target;if(!_){N.logger("error",`No target element registered for experience '${f.experienceId}'. Skipping rendering.`);return}const v=Ee(_);try{A.render(v,S.component,e,f)}catch(B){N.logger("error",B)}});i.sample({clock:r,target:o}),i.sample({clock:a,target:h}),i.sample({clock:o.doneData,target:[u,p,n]}),i.sample({clock:o.doneData,target:e.eventBus.prepend(f=>({type:"experience_initialize",experienceInstance:f}))}),i.sample({clock:n,target:k});function F(f,S){r({experience:f,target:S})}const L=t.map(f=>Object.values(f).flat());function I(f){return t.map(S=>S[f]||[],{skipVoid:!1})}return{spawn:F,getByExperienceId:I,listStore:L}});function Pe(e){return q.invoke(Re,e)}exports.createAppHosts=ve;exports.createExperienceInstance=ue;exports.createExperienceInstanceIndex=Pe;exports.domInteractive=Ne;exports.evaluateRuleLogic=V;exports.getTargetElements=ke;exports.isPickedRoot=oe;exports.isRulesLogic=re;exports.isStepNode=M;exports.tagTargetElement=be;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { Store } from 'effector';
|
|
2
2
|
import { StateSnapshot } from '../../utils/state-snaphot';
|
|
3
3
|
import { Picked } from '../../picked';
|
|
4
|
-
export type Predicate = (snapshot: StateSnapshot
|
|
4
|
+
export type Predicate = (snapshot: StateSnapshot & {
|
|
5
|
+
args: unknown[];
|
|
6
|
+
}) => boolean | Promise<boolean> | string | Promise<string> | string[] | Promise<string[]> | undefined;
|
|
5
7
|
export type PredicatesStore = ReturnType<typeof createPredicateIndex>;
|
|
6
8
|
export interface PredicateIndexItem {
|
|
7
9
|
name: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"predicate.d.ts","sourceRoot":"","sources":["../../../../src/entities/predicate/predicate.ts"],"names":[],"mappings":"AAAA,OAAO,EAA8D,KAAK,KAAK,EAAE,MAAM,UAAU,CAAA;AAGjG,OAAO,
|
|
1
|
+
{"version":3,"file":"predicate.d.ts","sourceRoot":"","sources":["../../../../src/entities/predicate/predicate.ts"],"names":[],"mappings":"AAAA,OAAO,EAA8D,KAAK,KAAK,EAAE,MAAM,UAAU,CAAA;AAGjG,OAAO,EAAuB,KAAK,aAAa,EAAE,MAAM,2BAA2B,CAAA;AACnF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAE1C,MAAM,MAAM,SAAS,GAAG,CACtB,QAAQ,EAAE,aAAa,GAAG;IAAE,IAAI,EAAE,OAAO,EAAE,CAAA;CAAE,KAE3C,OAAO,GACP,OAAO,CAAC,OAAO,CAAC,GAChB,MAAM,GACN,OAAO,CAAC,MAAM,CAAC,GACf,MAAM,EAAE,GACR,OAAO,CAAC,MAAM,EAAE,CAAC,GACjB,SAAS,CAAA;AAEb,MAAM,MAAM,eAAe,GAAG,UAAU,CAAC,OAAO,oBAAoB,CAAC,CAAA;AAErE,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,EAAE,SAAS,CAAA;CACrB;AAKD,QAAA,MAAM,2BAA2B,eAA8B;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE;qBAoBvD,MAAM,aAAa,SAAS,KAAG,IAAI;sBAiBlC,MAAM;;cAlCrB,MAAM;mBACD,SAAS;;0CAqCqB,MAAM,KAAG,KAAK,CAAC,MAAM,UAAU,CAAC,SAAS,CAAC,CAAC;CAuCxF,CAAA;AAEF,wBAAgB,oBAAoB,CAAC,CAAC,SAAS,UAAU,CAAC,OAAO,2BAA2B,CAAC,CAAC,CAAC,CAAC,EAC9F,MAAM,EAAE,CAAC,GACR,UAAU,CAAC,OAAO,2BAA2B,CAAC,CAEhD;AAED,eAAO,MAAM,cAAc,GAAI,MAAM,MAAM,EAAE,WAAW,SAAS,EAAE,YAAY,eAAe,SAE7F,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logic-engine.d.ts","sourceRoot":"","sources":["../../src/logic-engine.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,GAAG,UAAU,GAAG,WAAW,CAAA;AAEpG,MAAM,MAAM,UAAU,GAClB,cAAc,GACd,CAAC,MAAM,UAAU,CAAC,GAClB,CAAC,MAAM,OAAO,CAAC,cAAc,CAAC,CAAC,GAC/B,OAAO,CAAC,cAAc,CAAC,CAAA;AAE3B,MAAM,WAAW,WAAW;IAC1B,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAAA;CAC1B;AAED,MAAM,MAAM,UAAU,GAAG,KAAK,CAAC,UAAU,CAAC,CAAA;AAE1C,MAAM,MAAM,cAAc,GACtB,MAAM,GACN,MAAM,GACN,OAAO,GACP,IAAI,GACJ,SAAS,GACT,SAAS,GACT,SAAS,EAAE,GACX,cAAc,EAAE,CAAA;AAEpB,MAAM,WAAW,SAAS;IACxB,CAAC,GAAG,EAAE,MAAM,GAAG,cAAc,GAAG,cAAc,EAAE,CAAA;CACjD;AAED,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,UAAU,KAAK,OAAO,CAAA;AAC3E,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,OAAO,GAAG,MAAM,CAAA;AACrF,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,EAAE,UAAU,KAAK,UAAU,CAAA;AAC1D,MAAM,MAAM,eAAe,GAAG,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,KAAK,MAAM,CAAA;AACzF,MAAM,MAAM,cAAc,GAAG,CAAC,GAAG,IAAI,EAAE,UAAU,EAAE,KAAK,UAAU,EAAE,CAAA;AACpE,MAAM,MAAM,aAAa,GAAG,CAAC,GAAG,IAAI,EAAE,MAAM,EAAE,KAAK,MAAM,CAAA;AAEzD,MAAM,MAAM,YAAY,GACpB;IACE,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAAA;CAC1B,GACD,UAAU,CAAA;AAqCd,MAAM,MAAM,SAAS,GAAG,CACtB,IAAI,EAAE,YAAY,EAClB,GAAG,IAAI,EAAE,UAAU,EAAE,KAClB,UAAU,GAAG,OAAO,CAAC,cAAc,CAAC,CAAA;
|
|
1
|
+
{"version":3,"file":"logic-engine.d.ts","sourceRoot":"","sources":["../../src/logic-engine.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,GAAG,UAAU,GAAG,WAAW,CAAA;AAEpG,MAAM,MAAM,UAAU,GAClB,cAAc,GACd,CAAC,MAAM,UAAU,CAAC,GAClB,CAAC,MAAM,OAAO,CAAC,cAAc,CAAC,CAAC,GAC/B,OAAO,CAAC,cAAc,CAAC,CAAA;AAE3B,MAAM,WAAW,WAAW;IAC1B,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAAA;CAC1B;AAED,MAAM,MAAM,UAAU,GAAG,KAAK,CAAC,UAAU,CAAC,CAAA;AAE1C,MAAM,MAAM,cAAc,GACtB,MAAM,GACN,MAAM,GACN,OAAO,GACP,IAAI,GACJ,SAAS,GACT,SAAS,GACT,SAAS,EAAE,GACX,cAAc,EAAE,CAAA;AAEpB,MAAM,WAAW,SAAS;IACxB,CAAC,GAAG,EAAE,MAAM,GAAG,cAAc,GAAG,cAAc,EAAE,CAAA;CACjD;AAED,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,UAAU,KAAK,OAAO,CAAA;AAC3E,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,OAAO,GAAG,MAAM,CAAA;AACrF,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,EAAE,UAAU,KAAK,UAAU,CAAA;AAC1D,MAAM,MAAM,eAAe,GAAG,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,KAAK,MAAM,CAAA;AACzF,MAAM,MAAM,cAAc,GAAG,CAAC,GAAG,IAAI,EAAE,UAAU,EAAE,KAAK,UAAU,EAAE,CAAA;AACpE,MAAM,MAAM,aAAa,GAAG,CAAC,GAAG,IAAI,EAAE,MAAM,EAAE,KAAK,MAAM,CAAA;AAEzD,MAAM,MAAM,YAAY,GACpB;IACE,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAAA;CAC1B,GACD,UAAU,CAAA;AAqCd,MAAM,MAAM,SAAS,GAAG,CACtB,IAAI,EAAE,YAAY,EAClB,GAAG,IAAI,EAAE,UAAU,EAAE,KAClB,UAAU,GAAG,OAAO,CAAC,cAAc,CAAC,CAAA;AAuMzC,wBAAsB,KAAK,CACzB,KAAK,EAAE,WAAW,GAAG,UAAU,GAAG,SAAS,EAC3C,IAAI,CAAC,EAAE,YAAY,GAClB,OAAO,CAAC,UAAU,CAAC,CAoJrB"}
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const i=require("effector"),q=require("@withease/factories"),H=require("./supports-YvpQZxbh.cjs"),N=require("./logger-BsmHUUw1.cjs"),ge=require("./object-BbFTsGh3.cjs");function me(e){return typeof e=="number"&&!isNaN(e)}function R(e){return typeof e=="string"}function E(e){return Array.isArray(e)}function ne(e){return e instanceof Promise}function Z(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&Object.keys(e).length===1}function m(e){if(me(e))return e;const t=parseFloat(`${e}`);return isNaN(t)?0:t}function T(e){return`${e}`}const he={"==":(e,t)=>e==t,"===":(e,t)=>e===t,"!=":(e,t)=>e!=t,"!==":(e,t)=>e!==t,">":(e,t)=>m(e)>m(t),">=":(e,t)=>m(e)>=m(t),"<":(e,t,r)=>{const n=m(e),a=m(t);if(r===void 0)return n<a;const c=m(r);return n<a&&a<c},"<=":(e,t,r)=>{const n=m(e),a=m(t);if(r===void 0)return n<=a;const c=m(r);return n<=a&&a<=c},"!!":async e=>await O(e),"!":async e=>!await O(e),"%":(e,t)=>m(e)%m(t),log:e=>(console.log(e),e),in:(e,t)=>t?R(t)?t.indexOf(T(e))!==-1:E(t)?t.includes(e):!1:!1,cat:(...e)=>e.map(T).join(""),substr:(e,t,r)=>{const n=T(e),a=m(t);if(r===void 0)return n.substr(a);const c=m(r);if(c<0){const o=n.substr(a);return o.substr(0,o.length+c)}return n.substr(a,c)},"+":(...e)=>e.reduce((t,r)=>m(t)+m(r),0),"*":(...e)=>e.reduce((t,r)=>m(t)*m(r),1),"-":(e,t)=>{const r=m(e);return t===void 0?-r:r-m(t)},"/":(e,t)=>m(e)/m(t),min:(...e)=>Math.min(...e.map(m)),max:(...e)=>Math.max(...e.map(m)),merge:(...e)=>e.reduce((t,r)=>E(r)?t.concat(r):t.concat([r]),[]),var(e,t){const r=arguments.length>1?t:null;if(e===""||e==="."||e===null||e===void 0)return this;if(typeof e=="number"&&Array.isArray(this))return e>=0&&e<this.length?this[e]:r;const n=T(e);if(n===""||n===".")return this;const a=n.split(".");let c=this;for(const o of a){if(c==null)return r;if(Array.isArray(c)){const u=parseInt(o,10);isNaN(u)?c=c[o]:c=c[u]}else c=c[o]}return c!==void 0?c:r},async missing(...e){const t=E(e[0])?e[0]:e,r=[];for(const n of t){const a=await g({var:n},this);(a===null||a==="")&&r.push(`${n}`)}return r},async missing_some(e,t){const r=await g({missing:t},this);if(!E(r)||!E(t))return[];const n=r.filter(R);return t.filter(R).length-n.length>=m(e)?[]:n},invoke(e){return typeof e!="function"?null:e()},regexp_matches(e,t){let r=e,n="";if(E(e)){const[c,o]=e;r=c,n=o}return!R(r)||!R(n)?!1:new RegExp(r,n).test(T(t))},throw(e){throw new Error(T(e))}};async function g(e,t){if(!e)return e;if(ne(e))return g(await e,t);if(E(e))return Promise.all(e.map(o=>g(o,t)));if(!Z(e))return e;const r=Se(e);let n=r?e[r]??[]:[];switch(E(n)||(n=[n]),r){case"if":case"?:":for(let o=0;o<n.length-1;o+=2)if(await O(await g(n[o],t)))return g(n[o+1],t);return n.length%2===1?g(n[n.length-1],t):null;case"and":{let o=null;for(const u of n)if(o=await g(u,t),!await O(o))return o;return o}case"or":{let o=null;for(const u of n)if(o=await g(u,t),await O(o))return o;return o}case"map":{const o=await g(n[0],t);return E(o)?await Promise.all(o.map(u=>g(n[1],u))):[]}case"filter":{const o=await g(n[0],t);return E(o)?(await Promise.all(o.map(async p=>{const y=await O(await g(n[1],p));return{item:p,shouldInclude:y}}))).filter(({shouldInclude:p})=>p).map(({item:p})=>p):[]}case"reduce":{const o=await g(n[0],t);if(!E(o))return n.length>2?await g(n[2],t):null;const u=n[1];let y=n.length>2?await g(n[2],t):null;for(const k of o)y=await g(u,{current:k,accumulator:y});return y}case"all":{const o=await g(n[0],t);if(!E(o)||o.length===0)return!1;for(const u of o)if(!await O(await g(n[1],u)))return!1;return!0}case"some":{const o=await g(n[0],t);if(!E(o))return!1;for(const u of o)if(await O(await g(n[1],u)))return!0;return!1}case"none":{const o=await g(n[0],t);if(!E(o))return!0;for(const u of o)if(await O(await g(n[1],u)))return!1;return!0}case"catch":try{return await g(n[0],t)}catch(o){return Z(o)?await g(o,t):n[1]?await g(n[1],o):o instanceof Error?o.message:o}}const a=await Promise.all(n.map(o=>g(o,t))),c=r?he[r]:void 0;if(!c)throw new Error(`Unrecognized operation ${r}`);return c.apply(t,a)}async function O(e){return ne(e)?O(await e):!(Array.isArray(e)&&e.length===0)&&!!e}function Se(e){return Object.keys(e)[0]}function re(e){return!ge.isEmpty(e)}async function V(e,t,r){const n=e.getStateSnapshot(),a=e.predicates.listStore.getState().reduce((u,p)=>({...u,[p.name]:()=>p.predicate(n)}),{}),c=e.features.listStore.getState().reduce((u,p)=>({...u,[p.id]:async()=>{const{bucket:y}=await p.getBucket();return y}}),{}),o={...r,responses:e.responses.getAllStore.getState(),location:typeof n.location=="object"?{hash:n.location.hash,host:n.location.host,hostname:n.location.hostname,href:n.location.href,origin:n.location.origin,pathname:n.location.pathname,port:n.location.port,protocol:n.location.protocol,search:n.location.search}:void 0,predicates:a,features:c};return await g(t,o)}function ye(e){return!H.supportsWindow()||!H.supportsDocument()?[]:Array.from(window.document.querySelectorAll(e)).filter(t=>t instanceof HTMLElement)}const we="open";function Ee(e){if(!H.supportsShadowRoot())throw new Error("Shadow DOM is not supported in this environment");return e.attachShadow({mode:we})}function Ne(){return new Promise((e,t)=>{if(!H.supportsDocument()){t();return}document.readyState!=="loading"?e():document.addEventListener("readystatechange",()=>e(),{once:!0})})}function Ie(e,t){const r=new MutationObserver(n=>{document.contains(e)||(r.disconnect(),t())});r.observe(document.body,{childList:!0,subtree:!0})}const C="picked-root",j="picked-target",xe="picked-root";function ke(e,t){return[...e,{selector:`${xe}[experience-id="${t}"]`,placement:"replace"}].flatMap(n=>{const a=ye(n.selector).filter(c=>!Ae(c,t)&&!oe(c,t));return{...n,elements:a}})}function ve(e,t){return e.flatMap(r=>r.elements.map(n=>Be(n,r.placement,t)))}function be(e,t){e.classList.add(j),e.classList.add(`${j}-${t}`)}function Ae(e,t){return t?e.classList.contains(`${j}-${t}`):e.classList.contains(`${j}`)}function oe(e,t){return t?e.classList.contains(`${C}-${t}`):e.classList.contains(C)}function Oe(e){const t=document.createElement("div");return t.style.display="block",t.classList.add(C),t.classList.add(`${C}-${e}`),t}function Be(e,t,r){let n;const a=Oe(r);if(e instanceof Document)n=e.body.appendChild(a);else{switch(t){case"replace":e.replaceWith(a);break;case"before":e.before(a);break;case"after":e.after(a);break;case"prepend":e.prepend(a);break;default:e.append(a);break}n=a}return n}function Fe(e){return e.type==="conditional"}function M(e){return e.type==="step"}function _e(e){return e.type==="experience"}function ee(e){return e.type==="origin"}function te(e){return e.type==="action"}const se=(e,t,r,n,a=new Set)=>a.has(r.id)?[]:(a.add(r.id),M(r)&&!n?[r]:t.filter(o=>o.sourceNodeId===r.id).flatMap(o=>{const u=e.find(p=>p.id===o.destinationNodeId);return u?se(e,t,u,!1,a):[]})),$e=(e,t,r)=>se(e,t,r,!0,new Set),ie=(e,t,r,n,a=new Set)=>{if(a.has(r.id))return[-1,-1];a.add(r.id);const c=t.filter(p=>p.sourceNodeId===r.id);if(c.length===0)return[0,0];let o=1/0,u=-1/0;for(const p of c){const y=e.find(L=>L.id===p.destinationNodeId);if(!y)continue;const[k,B]=ie(e,t,y,!1,new Set(a));k!==-1&&(o=Math.min(o,k+1),u=Math.max(u,B+1))}return o===1/0?[-1,-1]:[o,u]},Te=(e,t,r)=>ie(e,t,r,!0,new Set),ae=(e,t,r,n=new Set)=>{if(n.has(r.id))return[-1,-1];if(n.add(r.id),r.type==="origin")return[0,0];const a=t.filter(u=>u.destinationNodeId===r.id);if(a.length===0)return[-1,-1];let c=1/0,o=-1/0;for(const u of a){const p=e.find(B=>B.id===u.sourceNodeId);if(!p)continue;const[y,k]=ae(e,t,p,new Set(n));y!==-1&&(c=Math.min(c,y+1),o=Math.max(o,k+1))}return c===1/0?[-1,-1]:[c,o]},Me=(e,t,r)=>ae(e,t,r,new Set),ce=e=>e.find(r=>r.type==="origin")||null,U=(e,t,r)=>{if(!e)return ce(t);const n=r.find(c=>c.sourceNodeId===e.id);if(!n)return null;const a=t.find(c=>c.id===n.destinationNodeId);return a||null};async function Le(e,t,r,n){const a=e?"true":"false",c=n.find(o=>o.sourceNodeHandle===a&&o.sourceNodeId===t);return r.find(o=>o.id===(c==null?void 0:c.destinationNodeId))}const X=i.createDomain("experience-instance"),De=q.createFactory(({client:e,experience:t,target:r})=>{const n=i.createEvent(),a=i.createEvent(),c=i.createEvent(),o=i.createEvent(),u=i.createEvent(),p=i.createEvent(),y=t.componentStore,k=X.store("transitioning"),B=e.history.entriesStore.map(s=>s.filter(l=>l.experienceId===t.id)),L=B.map(s=>s.filter(l=>M(l.node))),I=B.map(s=>{var l;return((l=s[s.length-1])==null?void 0:l.node)||null}),f=i.combine(t.treeStore,I,({steps:s},l)=>s.find(d=>l&&M(l)&&d.id===l.stepId)||null),h=i.combine(t.treeStore,I,({nodes:s,edges:l},d)=>d?$e(s,l,d):[]),A=i.combine(t.treeStore,I,({nodes:s,edges:l},d)=>d?Me(s,l,d):[-1,-1]),_=i.combine(t.treeStore,I,({nodes:s,edges:l},d)=>d?Te(s,l,d):[-1,-1]),v=X.store(!1),F=i.createApi(v,{open:()=>!0,close:()=>!1,toggle:s=>!s,set:(s,l)=>l}),fe=i.createEffect(async()=>{e.history.back({experienceId:t.id})}),le=i.attach({source:t.treeStore,effect:async(s,l)=>{const d=s.nodes.find(w=>M(w)&&w.stepId===l);d&&e.history.push({experienceId:t.id,node:d})}}),z=i.attach({source:I,effect:s=>{}}),W=i.attach({source:t.treeStore,effect:async({nodes:s})=>ce(s)}),G=i.attach({source:t.treeStore,effect:async({nodes:s,edges:l},d)=>U(d,s,l)}),K=i.attach({source:t.treeStore,effect:async({nodes:s,edges:l,conditionals:d},w)=>{if(!w)return;const $=d.find(b=>b.id===w.conditionalId);if(!$)return;const x=w.id,S=await V(e,$.condition);return Le(!!S,x,s,l)}}),J=i.attach({source:t.treeStore,effect:async({nodes:s,edges:l},d)=>{if(!d||!te(d))return;const w=d.action;if(!w){N.logger("warn",`Action node ${d.id} has no action name`);return}const $=e.actions.getByName(w).getState();if(!$){N.logger("warn",`Action '${w}' not registered on client`);const x=l.find(S=>S.sourceNodeId===d.id&&S.sourceNodeHandle==="false");return x?s.find(S=>S.id===x.destinationNodeId):null}if(typeof $.action!="function"){N.logger("warn",`Action '${w}' is not a function`);const x=l.find(S=>S.sourceNodeId===d.id&&S.sourceNodeHandle==="false");return x?s.find(S=>S.id===x.destinationNodeId):null}try{N.logger("info",`Executing action: ${w}`),await $.action(w);const x=l.find(b=>b.sourceNodeId===d.id&&b.sourceNodeHandle==="true");if(!x)return N.logger("warn",`No 'true' edge found for action node ${d.id}`),null;const S=s.find(b=>b.id===x.destinationNodeId);return N.logger("info",`Action '${w}' succeeded, moving to node ${S==null?void 0:S.id}`),S||null}catch(x){N.logger("warn",`Action '${w}' failed:`,x);const S=l.find(P=>P.sourceNodeId===d.id&&P.sourceNodeHandle==="false");if(!S)return N.logger("warn",`No 'false' edge found for action node ${d.id}`),null;const b=s.find(P=>P.id===S.destinationNodeId);return N.logger("info",`Action '${w}' failed, moving to node ${b==null?void 0:b.id}`),b||null}}}),de=i.createEffect(s=>{if(s)return e.launchExperienceById(s.experienceId)}),Q=i.attach({source:[I,t.treeStore],effect:async([s,{nodes:l,edges:d}])=>U(s,l,d)}),D=i.attach({source:[I,t.treeStore],effect:async([s,{nodes:l,edges:d}])=>U(s,l,d)}),pe=i.createEffect(s=>{e.history.push({experienceId:t.id,node:s})}),Y=i.attach({source:t.configStore,effect:async({initializeOpenLogic:s})=>re(s)?!!await V(e,s):s??!1});return i.split({source:I,match:s=>s?Fe(s)?"condition":M(s)?"step":_e(s)?"launchExperience":ee(s)?"origin":te(s)?"action":"other":"none",cases:{none:W,origin:G,condition:K,step:z,launchExperience:de,action:J,__:i.createEvent()}}),i.sample({clock:[K.doneData,G.doneData,W.doneData,D.doneData,Q.doneData,J.doneData],filter:Boolean,target:pe}),i.sample({clock:a,target:D}),i.sample({clock:a,source:f,filter:Boolean,target:e.eventBus.prepend(s=>({type:"step_submit",step:s,experience:t}))}),i.sample({clock:D.done,source:f,filter:Boolean,target:e.eventBus.prepend(s=>({type:"step_submit_success",step:s,experience:t}))}),i.sample({clock:D.fail,source:f,filter:Boolean,target:e.eventBus.prepend(s=>({type:"step_submit_error",step:s,experience:t}))}),i.sample({clock:c,target:fe}),i.sample({clock:o,target:le}),i.sample({source:i.combine([K.pending,G.pending,W.pending,D.pending]),fn:s=>s.some(Boolean)?"transitioning":"ready",target:k}),i.sample({clock:z.doneData,source:f,filter:Boolean,target:e.eventBus.prepend(s=>({type:"step_enter",step:s,experience:t}))}),i.sample({clock:p,target:Y}),i.sample({source:Y.doneData,fn:Boolean,target:v}),i.sample({source:I,clock:n,filter:s=>s?ee(s):!0,target:Q}),i.sample({source:v,filter:Boolean,target:n}),i.sample({source:v,filter:Boolean,target:e.eventBus.prepend(()=>({type:"experience_open",experience:t}))}),i.sample({source:v,filter:s=>!s,target:e.eventBus.prepend(()=>({type:"experience_close",experience:t}))}),i.sample({clock:u,target:[p]}),u(),{id:Math.random().toString(36).substring(7),experienceId:t.id,configStore:t.configStore,target:r,componentStore:y,stateStore:k,isOpenStore:v,open:F.open,close:F.close,toggleOpen:F.toggle,setOpen:F.set,treeStore:t.treeStore,currentNodeStore:I,currentStepStore:f,nextReachableStepNodesStore:h,stepsToOriginStore:A,stepsToLeafStore:_,goToNextStep:a,goToPreviousStep:c,goToStepById:o,stepsHistoryStore:L}});function ue(e){return q.invoke(De,e)}const Re=q.createFactory(({client:e})=>{const t=X.store({}),r=i.createEvent(),n=i.createEvent(),a=i.createEvent(),c=i.createApi(t,{register(f,h){const A=[...f[h.experienceId]??[]];return A.push(h),{...f,[h.experienceId]:A}},unregister(f,h){var v;const A=h.experienceId,_=(v=f[A])==null?void 0:v.filter(F=>F!==h);return{...f,[A]:_??[]}}}),o=i.createEffect(({experience:f,target:h})=>ue({client:e,experience:f,target:h})),u=i.createEffect(f=>{c.register(f)}),p=i.createEffect(f=>{f.target&&Ie(f.target,()=>{a(f)})}),y=i.createEffect(f=>{c.unregister(f)}),k=i.createEffect(f=>{const h=f.componentStore.getState();if(!h){N.logger("warn","No app component registered. Skipping init.");return}const A=h.frameworkStore.getState();if(!A){N.logger("error",`No framework registered for component '${h.name}'. Skipping rendering.`);return}const _=f.target;if(!_){N.logger("error",`No target element registered for experience '${f.experienceId}'. Skipping rendering.`);return}const v=Ee(_);try{A.render(v,h.component,e,f)}catch(F){N.logger("error",F)}});i.sample({clock:r,target:o}),i.sample({clock:a,target:y}),i.sample({clock:o.doneData,target:[u,p,n]}),i.sample({clock:o.doneData,target:e.eventBus.prepend(f=>({type:"experience_initialize",experienceInstance:f}))}),i.sample({clock:n,target:k});function B(f,h){r({experience:f,target:h})}const L=t.map(f=>Object.values(f).flat());function I(f){return t.map(h=>h[f]||[],{skipVoid:!1})}return{spawn:B,getByExperienceId:I,listStore:L}});function Pe(e){return q.invoke(Re,e)}exports.createAppHosts=ve;exports.createExperienceInstance=ue;exports.createExperienceInstanceIndex=Pe;exports.domInteractive=Ne;exports.evaluateRuleLogic=V;exports.getTargetElements=ke;exports.isPickedRoot=oe;exports.isRulesLogic=re;exports.isStepNode=M;exports.tagTargetElement=be;
|