@golemui/core 1.5.1-rc.0 → 1.6.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -0
- package/index.js +824 -769
- package/index.umd.cjs +6 -6
- package/lib/store/model.d.ts +23 -0
- package/lib/utils/repeater.d.ts +25 -17
- package/package.json +1 -1
package/index.umd.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const D=require("rxjs"),l=require("ts.data.json");require("@standard-schema/spec");function at(e,t){const r=e["~standard"].validate(t);if(r instanceof Promise)throw new TypeError("Schema validation must be synchronous");return r}function ft(e){return e.issues===void 0}function x(e){return new l.Decoder(t=>{if(typeof t!="object"||t===null)return l.err([{message:`Expected object literal, got "${typeof t}"`,path:[]}]);const r={};for(const[n,o]of Object.entries(e)){const i=o.decoder.decode(t[n]);if(!i.isOk())return l.err(i.issues.map(s=>({message:s.message,path:[n,...s.path]})));if(r[n]=i.value,o.suffixed){for(const[s,c]of Object.entries(t))if(s.startsWith(n+".")){const u=o.decoder.decode(c);if(!u.isOk())return l.err(u.issues.map(a=>({message:a.message,path:[s,...a.path]})));r[s]=u.value}}}return l.ok(r)})}const Yt=e=>typeof e!="function"&&e.kind==="display",ee=e=>typeof e!="function"&&e.kind==="action",I=e=>typeof e!="function"&&e.kind==="input",L=e=>typeof e!="function"&&e.kind==="layout",W=e=>typeof e=="function",er=l.object({in:l.array(l.string())}),je=l.object({when:l.string()}),ue=l.oneOf([er,je]),tr=l.object({from:l.array(l.string())}),le=l.oneOf([tr,je]),Se=l.oneOf([l.boolean(),je]),rr=new l.Decoder(e=>{const t=typeof e;return t==="function"?l.ok(e):l.err([{message:`Expected a function, got '${t}'`,path:[]}])}),P=e=>l.oneOf([e,rr]),ke=x({load:{suffixed:!0,decoder:P(l.optional(l.string()))},click:{suffixed:!0,decoder:P(l.optional(l.string()))},change:{suffixed:!0,decoder:P(l.optional(l.string()))},filter:{suffixed:!0,decoder:P(l.optional(l.string()))},blur:{suffixed:!0,decoder:P(l.optional(l.string()))}}),nr=l.object({key:l.string(),default:l.optional(l.string()),params:l.optional(l.succeed())}),pt=l.oneOf([l.string(),nr]),De=l.optional(l.string()),or=x({kind:{decoder:l.literal("display")},uid:{decoder:De},type:{decoder:l.string()},size:{suffixed:!0,decoder:l.optional(l.number())},include:{decoder:l.optional(ue)},exclude:{decoder:l.optional(le)},props:{decoder:l.optional(l.succeed())}}),ir=x({kind:{decoder:l.literal("action")},uid:{decoder:De},type:{decoder:l.string()},actionType:{decoder:l.optional(l.oneOf([l.literal("button"),l.literal("submit")]))},size:{suffixed:!0,decoder:l.optional(l.number())},include:{decoder:l.optional(ue)},exclude:{decoder:l.optional(le)},label:{suffixed:!0,decoder:P(l.optional(pt))},disabled:{suffixed:!0,decoder:l.optional(Se)},on:{decoder:l.optional(ke)},props:{decoder:l.optional(l.succeed())}}),sr=new l.Decoder(e=>{const t=typeof e;if(t==="function"){const r=e,n=r({$form:{},errors:void 0,touched:void 0,translate:void 0});return r.uid=r.uid||n.uid,r.type=n.type,r.path=n.path,l.ok(r)}else return l.err([{message:`Expected a function, got '${t}'`,path:[]}])}),cr=x({kind:{decoder:l.literal("input")},uid:{decoder:l.optional(l.string())},type:{decoder:l.string()},size:{suffixed:!0,decoder:l.optional(l.number())},include:{decoder:l.optional(ue)},exclude:{decoder:l.optional(le)},disabled:{suffixed:!0,decoder:l.optional(Se)},readonly:{suffixed:!0,decoder:l.optional(Se)},on:{decoder:l.optional(ke)},props:{decoder:l.optional(l.succeed())},label:{suffixed:!0,decoder:P(l.optional(pt))},path:{decoder:l.string()},defaultValue:{decoder:l.optional(l.succeed())},validator:{suffixed:!0,decoder:P(l.optional(l.succeed()))}}).map(e=>{const t={...e};if(e.uid||(t.uid=`${e.path}-${e.type}`),e.type==="repeater"){const r=e.props;t.props={...r,template:We.parse(r.template)}}return t}),dr=l.lazy(()=>{const e=l.discriminatedUnion("kind",{input:cr,layout:We,display:or,action:ir});return new l.Decoder(t=>typeof t=="function"?sr.decode(t):e.decode(t))}),We=x({kind:{decoder:l.literal("layout")},uid:{decoder:De},type:{decoder:l.string()},size:{suffixed:!0,decoder:l.optional(l.number())},include:{decoder:l.optional(ue)},exclude:{decoder:l.optional(le)},props:{decoder:l.optional(l.succeed())},on:{decoder:l.optional(ke)},children:{decoder:l.array(dr)}}),k=class k{constructor(){this.widgetLoaders={},this._ready=!1}get ready(){return this._ready}setWidgetLoaders(t){this.widgetLoaders=t,this._ready=!0}async loadWidget(t){const r=this.widgetLoaders[t];if(!k.sharedCache.has(r)){const n=r().catch(o=>(k.sharedCache.delete(r),Promise.reject(o)));k.sharedCache.set(r,n)}return k.sharedCache.get(r)}async preloadWidgets(t){const r=t??Object.keys(this.widgetLoaders);await Promise.all(r.map(async n=>{const o=await this.loadWidget(n);k.resolvedCache.set(this.widgetLoaders[n],o)}))}getIfLoaded(t){const r=this.widgetLoaders[t];if(r)return k.resolvedCache.get(r)}};k.sharedCache=new Map,k.resolvedCache=new Map;let te=k;async function ur(e){const t=new te;t.setWidgetLoaders(e.widgetLoaders),await t.preloadWidgets()}function lr(e){Ae(e,"#0")}function Ae(e,t){if(W(e)){e.uid||(e.uid=`${t}.f`);return}if(e.uid||(e.uid=t),L(e)&&e.children.forEach((r,n)=>{Ae(r,`${t}.${n}`)}),I(e)&&e.type==="repeater"){const r=e.props?.template;r&&Ae(r,`${t}.t`)}}function ar(e){return{...e,form:{uid:"",type:"flex",kind:"layout",children:e.form}}}const ht=l.object({states:l.optional(l.record(l.string())),form:l.lazy(()=>We)}).map(e=>(lr(e.form),e)),mt=e=>({formName:"",formDef:ht.parse({form:{kind:"layout",type:"flex",children:[]}}),flatForm:{},resolvedSources:{},currentStates:[],calculatedWidgets:{},validations:{},touchedControls:{},injectedValidations:{},isFormValid:!0,widgetFlags:{},repeaterItemScopes:{},widgetPropOverrides:{},data:{},meta:{},formHealth:{status:"ok"},touched:!1,allControlsValidated:!1,lang:e}),fr={submit:"formSubmit",health:"formHealth",event:"formEvent"},pr=e=>!(typeof e!="object"||e===null||typeof e.key!="string");function hr(e){const t=new Intl.Locale(e).maximize().script;return["Arab","Hebr","Thaa","Syrc","Tfng","Adlm","Rohg"].includes(t||"")?"rtl":"ltr"}const gt=(e=typeof navigator<"u"&&navigator.language||"en-US")=>{const t=new Set;return{get lang(){return e},translate(n){return n},subscribe(n){return t.add(n),()=>{t.delete(n)}},setLang(n){e=n,t.forEach(o=>o(e))}}},w={calculateCurrentStateError:10,calculateWidgetFlagsError:11,calculateWidgetPropsError:12,initializeParseError:20,initializeUidCollisionError:21,initializeUnknownError:22,initializeMalformedFormShapeError:23,widgetCouldNotBeLoaded:30,resolveStringInterpolationError:40},mr=e=>{throw new Error(`Unhandled case: ${JSON.stringify(e)}`)},N=(e,t)=>{if(e===void 0)throw new Error("obj is undefined");return t.split(".").reduce((r,n)=>r===void 0||n===""?r:Array.isArray(r)?r[parseInt(n,10)]:r[n],e)},gr=(e,t)=>{if(t==="")return!1;let r=e;for(const n of t.split(".")){if(r===null||typeof r!="object")return!1;if(Array.isArray(r)){const o=parseInt(n,10);if(!(o in r))return!1;r=r[o]}else{if(!(n in r))return!1;r=r[n]}}return!0},Ee=(e,t,r)=>{if(e===null)throw new Error("object is null");if(e===void 0)throw new Error("object is undefined");if(t==="")throw new Error("path cannot be empty");const n=t.split(".");let o=e;for(let s=0;s<n.length-1;s++){const c=n[s],u=n[s+1];(o[c]==null||typeof o[c]!="object")&&(o[c]=vt(u)?[]:{}),o=o[c]}const i=n[n.length-1];return o[i]=r,e},yt=(e,t,r)=>{if(e===null)throw new Error("object is null");if(e===void 0)throw new Error("object is undefined");if(t==="")throw new Error("path cannot be empty");const n=t.split("."),o=Xe(e);let i=o;for(let s=0;s<n.length-1;s++){const c=n[s],u=n[s+1];i[c]==null||typeof i[c]!="object"?i[c]=vt(u)?[]:{}:i[c]=Xe(i[c]),i=i[c]}return i[n[n.length-1]]=r,o},Xe=e=>Array.isArray(e)?e.slice():{...e},yr=(e,t)=>{if(t==="")return e;const r=t.split("."),n=[e];for(let s=0;s<r.length-1;s++){const c=n[s];if(c==null||typeof c!="object")return e;const u=r[s],a=Array.isArray(c)?c[parseInt(u,10)]:c[u];if(a==null||typeof a!="object")return e;n.push(a)}const o=n[n.length-1],i=r[r.length-1];Array.isArray(o)?o.splice(parseInt(i,10),1):delete o[i];for(let s=n.length-1;s>=1;s--){const c=n[s];if(Array.isArray(c)||!vr(c))break;const u=n[s-1],a=r[s-1];if(Array.isArray(u))break;delete u[a]}return e};function vt(e){const t=Number(e);return Number.isInteger(t)&&t>=0&&t.toString()===e}function vr(e){return e!=null&&typeof e=="object"&&!Array.isArray(e)&&Object.keys(e).length===0}function z(e){if(e===null||typeof e!="object")return e;if(Array.isArray(e))return e.map(r=>z(r));const t={};for(const r of Object.keys(e))t[r]=z(e[r]);return t}function Pe(e){return e.flatMap(t=>[t,...L(t)?Pe(t.children):[]])}function ae(e){return Object.entries(e.validations).sort(([n],[o])=>n.split(".").length-o.split(".").length).reduce((n,[o,i])=>(i!==null&&(n.$formIsInvalid=!0,Ee(n.$errors,o,[...i])),n),{$formIsInvalid:!1,$errors:{}})}function T(e){if(e!==void 0)return I(e)||W(e)?e.path:void 0}function ye(e){const t=z(e.data);for(const[r,n]of Object.entries(e.widgetFlags))if(n.hidden===!0){const o=T(e.resolvedSources[r]);o!==void 0&&yr(t,o)}return t}const fe=e=>!W(e)&&e.type==="repeater",X=e=>[...e.matchAll(/\[(\d+)\]/g)].map(t=>parseInt(t[1],10));function Ce(e,t){const r={resolvedSources:{},repeaterItemScopes:{}};for(const n of Object.values(e))r.resolvedSources[n.uid]=n,fe(n)&&$t(n,[],t,r);return r}function $t(e,t,r,n){const o=N(r,e.path);if(!Array.isArray(o))return;const i=Pe([e.props.template]);o.forEach((s,c)=>{const u=[...t,c],a={itemPath:`${e.path}.${c}`,index:c};for(const f of i){const h=Fe(f,u);n.resolvedSources[h.uid]=h,n.repeaterItemScopes[h.uid]=a;const y=$r(f,h,u,r,s,c);y&&$t(y,u,r,n)}})}function $r(e,t,r,n,o,i){if(fe(t))return t;if(!W(e))return;const s=e({$form:n,$item:o,$index:i,errors:void 0,touched:void 0,translate:void 0});if(s.type!=="repeater")return;const c={...s,uid:e.uid};return Fe(c,r)}function Fe(e,t){const r=Te(e.uid,t);if(W(e)){const n=o=>e(o);return n.uid=r,n.type=e.type,e.path!==void 0&&(n.path=qe(e.path,t)),n}return I(e)?{...e,uid:r,path:qe(e.path,t)}:{...e,uid:r}}function Te(e,t){if(t.length===0)throw new Error("Repeater indexes cannot be an empty array");const r=t.reduce((n,o)=>`${n}[${o}]`,"");return`${e}${r}`}function qe(e,t){if(t.length===0)throw new Error("Repeater indexes cannot be an empty array");const r="items",n=e.split(`.${r}`),o=n.length-1;if(o!==t.length)throw new Error(`Path contains ${o} '${r}' occurrences, but ${t.length} indexes were provided.`);return n.reduce((i,s,c)=>c===0?s:`${i}.${t[c-1]}${s}`)}function Sr(e,t){let r=0;return e.replace(/\.items(\??)\./g,(n,o)=>{const i=t[r++];return i===void 0?n:`.${i}${o}.`})}const Qe=["include","exclude","disabled","readonly"];function Ar(e,t){if(!Qe.some(o=>Je(e[o])))return e;const n={...e};for(const o of Qe){const i=n[o];Je(i)&&(n[o]={...i,when:Sr(i.when,t)})}return n}function Je(e){return e!==null&&typeof e=="object"&&"when"in e&&typeof e.when=="string"}const Er=50,Cr=e=>{let t=e.data,r=Ce(e.flatForm,t);for(let n=0;n<Er;n++){let o=!1;for(const i of Object.values(r.resolvedSources))!I(i)||gr(t,i.path)||(t=yt(t,i.path,z(i.defaultValue)),i.defaultValue!==void 0&&(o=!0));if(!o)break;r=Ce(e.flatForm,t)}return{...e,data:t,...r}},Ve=32;let we,m,g,v=e=>(m=0,g=e,v.newline=!1,e=S(),g[m]?_():e||""),_=(e="Unexpected token",t=m,r=g.slice(0,t).split(`
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const k=require("rxjs"),l=require("ts.data.json");require("@standard-schema/spec");function at(e,t){const r=e["~standard"].validate(t);if(r instanceof Promise)throw new TypeError("Schema validation must be synchronous");return r}function ft(e){return e.issues===void 0}function q(e){return new l.Decoder(t=>{if(typeof t!="object"||t===null)return l.err([{message:`Expected object literal, got "${typeof t}"`,path:[]}]);const r={};for(const[n,o]of Object.entries(e)){const i=o.decoder.decode(t[n]);if(!i.isOk())return l.err(i.issues.map(s=>({message:s.message,path:[n,...s.path]})));if(r[n]=i.value,o.suffixed){for(const[s,c]of Object.entries(t))if(s.startsWith(n+".")){const d=o.decoder.decode(c);if(!d.isOk())return l.err(d.issues.map(a=>({message:a.message,path:[s,...a.path]})));r[s]=d.value}}}return l.ok(r)})}const tr=e=>typeof e!="function"&&e.kind==="display",te=e=>typeof e!="function"&&e.kind==="action",I=e=>typeof e!="function"&&e.kind==="input",_=e=>typeof e!="function"&&e.kind==="layout",D=e=>typeof e=="function",rr=l.object({in:l.array(l.string())}),Pe=l.object({when:l.string()}),le=l.oneOf([rr,Pe]),nr=l.object({from:l.array(l.string())}),ae=l.oneOf([nr,Pe]),Se=l.oneOf([l.boolean(),Pe]),or=new l.Decoder(e=>{const t=typeof e;return t==="function"?l.ok(e):l.err([{message:`Expected a function, got '${t}'`,path:[]}])}),W=e=>l.oneOf([e,or]),ke=q({load:{suffixed:!0,decoder:W(l.optional(l.string()))},click:{suffixed:!0,decoder:W(l.optional(l.string()))},change:{suffixed:!0,decoder:W(l.optional(l.string()))},filter:{suffixed:!0,decoder:W(l.optional(l.string()))},blur:{suffixed:!0,decoder:W(l.optional(l.string()))}}),ir=l.object({key:l.string(),default:l.optional(l.string()),params:l.optional(l.succeed())}),pt=l.oneOf([l.string(),ir]),De=l.optional(l.string()),sr=q({kind:{decoder:l.literal("display")},uid:{decoder:De},type:{decoder:l.string()},size:{suffixed:!0,decoder:l.optional(l.number())},include:{decoder:l.optional(le)},exclude:{decoder:l.optional(ae)},props:{decoder:l.optional(l.succeed())}}),cr=q({kind:{decoder:l.literal("action")},uid:{decoder:De},type:{decoder:l.string()},actionType:{decoder:l.optional(l.oneOf([l.literal("button"),l.literal("submit")]))},size:{suffixed:!0,decoder:l.optional(l.number())},include:{decoder:l.optional(le)},exclude:{decoder:l.optional(ae)},label:{suffixed:!0,decoder:W(l.optional(pt))},disabled:{suffixed:!0,decoder:l.optional(Se)},on:{decoder:l.optional(ke)},props:{decoder:l.optional(l.succeed())}}),dr=new l.Decoder(e=>{const t=typeof e;if(t==="function"){const r=e,n=r({$form:{},errors:void 0,touched:void 0,translate:void 0});return r.uid=r.uid||n.uid,r.type=n.type,r.path=n.path,l.ok(r)}else return l.err([{message:`Expected a function, got '${t}'`,path:[]}])}),ur=q({kind:{decoder:l.literal("input")},uid:{decoder:l.optional(l.string())},type:{decoder:l.string()},size:{suffixed:!0,decoder:l.optional(l.number())},include:{decoder:l.optional(le)},exclude:{decoder:l.optional(ae)},disabled:{suffixed:!0,decoder:l.optional(Se)},readonly:{suffixed:!0,decoder:l.optional(Se)},on:{decoder:l.optional(ke)},props:{decoder:l.optional(l.succeed())},label:{suffixed:!0,decoder:W(l.optional(pt))},path:{decoder:l.string()},defaultValue:{decoder:l.optional(l.succeed())},validator:{suffixed:!0,decoder:W(l.optional(l.succeed()))}}).map(e=>{const t={...e};if(e.uid||(t.uid=`${e.path}-${e.type}`),e.type==="repeater"){const r=e.props;t.props={...r,template:We.parse(r.template)}}return t}),lr=l.lazy(()=>{const e=l.discriminatedUnion("kind",{input:ur,layout:We,display:sr,action:cr});return new l.Decoder(t=>typeof t=="function"?dr.decode(t):e.decode(t))}),We=q({kind:{decoder:l.literal("layout")},uid:{decoder:De},type:{decoder:l.string()},size:{suffixed:!0,decoder:l.optional(l.number())},include:{decoder:l.optional(le)},exclude:{decoder:l.optional(ae)},props:{decoder:l.optional(l.succeed())},on:{decoder:l.optional(ke)},children:{decoder:l.array(lr)}}),P=class P{constructor(){this.widgetLoaders={},this._ready=!1}get ready(){return this._ready}setWidgetLoaders(t){this.widgetLoaders=t,this._ready=!0}async loadWidget(t){const r=this.widgetLoaders[t];if(!P.sharedCache.has(r)){const n=r().catch(o=>(P.sharedCache.delete(r),Promise.reject(o)));P.sharedCache.set(r,n)}return P.sharedCache.get(r)}async preloadWidgets(t){const r=t??Object.keys(this.widgetLoaders);await Promise.all(r.map(async n=>{const o=await this.loadWidget(n);P.resolvedCache.set(this.widgetLoaders[n],o)}))}getIfLoaded(t){const r=this.widgetLoaders[t];if(r)return P.resolvedCache.get(r)}};P.sharedCache=new Map,P.resolvedCache=new Map;let re=P;async function ar(e){const t=new re;t.setWidgetLoaders(e.widgetLoaders),await t.preloadWidgets()}function fr(e){Ae(e,"#0")}function Ae(e,t){if(D(e)){e.uid||(e.uid=`${t}.f`);return}if(e.uid||(e.uid=t),_(e)&&e.children.forEach((r,n)=>{Ae(r,`${t}.${n}`)}),I(e)&&e.type==="repeater"){const r=e.props?.template;r&&Ae(r,`${t}.t`)}}function pr(e){return{...e,form:{uid:"",type:"flex",kind:"layout",children:e.form}}}const ht=l.object({states:l.optional(l.record(l.string())),form:l.lazy(()=>We)}).map(e=>(fr(e.form),e)),mt=e=>({formName:"",formDef:ht.parse({form:{kind:"layout",type:"flex",children:[]}}),flatForm:{},resolvedSources:{},currentStates:[],calculatedWidgets:{},validations:{},touchedControls:{},injectedValidations:{},isFormValid:!0,widgetFlags:{},repeaterItemScopes:{},repeaterRows:{},widgetPropOverrides:{},data:{},meta:{},formHealth:{status:"ok"},touched:!1,allControlsValidated:!1,lang:e}),hr={submit:"formSubmit",health:"formHealth",event:"formEvent"},mr=e=>!(typeof e!="object"||e===null||typeof e.key!="string");function gr(e){const t=new Intl.Locale(e).maximize().script;return["Arab","Hebr","Thaa","Syrc","Tfng","Adlm","Rohg"].includes(t||"")?"rtl":"ltr"}const gt=(e=typeof navigator<"u"&&navigator.language||"en-US")=>{const t=new Set;return{get lang(){return e},translate(n){return n},subscribe(n){return t.add(n),()=>{t.delete(n)}},setLang(n){e=n,t.forEach(o=>o(e))}}},C={calculateCurrentStateError:10,calculateWidgetFlagsError:11,calculateWidgetPropsError:12,initializeParseError:20,initializeUidCollisionError:21,initializeUnknownError:22,initializeMalformedFormShapeError:23,widgetCouldNotBeLoaded:30,resolveStringInterpolationError:40},yr=e=>{throw new Error(`Unhandled case: ${JSON.stringify(e)}`)},V=(e,t)=>{if(e===void 0)throw new Error("obj is undefined");return t.split(".").reduce((r,n)=>r===void 0||n===""?r:Array.isArray(r)?r[parseInt(n,10)]:r[n],e)},vr=(e,t)=>{if(t==="")return!1;let r=e;for(const n of t.split(".")){if(r===null||typeof r!="object")return!1;if(Array.isArray(r)){const o=parseInt(n,10);if(!(o in r))return!1;r=r[o]}else{if(!(n in r))return!1;r=r[n]}}return!0},Ee=(e,t,r)=>{if(e===null)throw new Error("object is null");if(e===void 0)throw new Error("object is undefined");if(t==="")throw new Error("path cannot be empty");const n=t.split(".");let o=e;for(let s=0;s<n.length-1;s++){const c=n[s],d=n[s+1];(o[c]==null||typeof o[c]!="object")&&(o[c]=vt(d)?[]:{}),o=o[c]}const i=n[n.length-1];return o[i]=r,e},yt=(e,t,r)=>{if(e===null)throw new Error("object is null");if(e===void 0)throw new Error("object is undefined");if(t==="")throw new Error("path cannot be empty");const n=t.split("."),o=Xe(e);let i=o;for(let s=0;s<n.length-1;s++){const c=n[s],d=n[s+1];i[c]==null||typeof i[c]!="object"?i[c]=vt(d)?[]:{}:i[c]=Xe(i[c]),i=i[c]}return i[n[n.length-1]]=r,o},Xe=e=>Array.isArray(e)?e.slice():{...e},$r=(e,t)=>{if(t==="")return e;const r=t.split("."),n=[e];for(let s=0;s<r.length-1;s++){const c=n[s];if(c==null||typeof c!="object")return e;const d=r[s],a=Array.isArray(c)?c[parseInt(d,10)]:c[d];if(a==null||typeof a!="object")return e;n.push(a)}const o=n[n.length-1],i=r[r.length-1];Array.isArray(o)?o.splice(parseInt(i,10),1):delete o[i];for(let s=n.length-1;s>=1;s--){const c=n[s];if(Array.isArray(c)||!Sr(c))break;const d=n[s-1],a=r[s-1];if(Array.isArray(d))break;delete d[a]}return e};function vt(e){const t=Number(e);return Number.isInteger(t)&&t>=0&&t.toString()===e}function Sr(e){return e!=null&&typeof e=="object"&&!Array.isArray(e)&&Object.keys(e).length===0}function B(e){if(e===null||typeof e!="object")return e;if(Array.isArray(e))return e.map(r=>B(r));const t={};for(const r of Object.keys(e))t[r]=B(e[r]);return t}function Fe(e){return e.flatMap(t=>[t,..._(t)?Fe(t.children):[]])}function fe(e){return Object.entries(e.validations).sort(([n],[o])=>n.split(".").length-o.split(".").length).reduce((n,[o,i])=>(i!==null&&(n.$formIsInvalid=!0,Ee(n.$errors,o,[...i])),n),{$formIsInvalid:!1,$errors:{}})}function R(e){if(e!==void 0)return I(e)||D(e)?e.path:void 0}function ye(e){const t=B(e.data);for(const[r,n]of Object.entries(e.widgetFlags))if(n.hidden===!0){const o=R(e.resolvedSources[r]);o!==void 0&&$r(t,o)}return t}const G=e=>!D(e)&&e.type==="repeater",pe=e=>[...e.matchAll(/\[(\d+)\]/g)].map(t=>parseInt(t[1],10)),we="items";function Ce(e,t){const r={resolvedSources:{},repeaterItemScopes:{},repeaterRows:{}};for(const n of Object.values(e))r.resolvedSources[n.uid]=n,G(n)&&$t(n,n.path,[],t,r);return r}function $t(e,t,r,n,o){const i=V(n,e.path);if(!Array.isArray(i))return;const s=Fe([e.props.template]);i.forEach((c,d)=>{const a=`${e.path}.${d}`,f=[...r,{declaredItemPath:`${t}.${we}`,itemPath:a,index:d}],h={itemPath:a,index:d};for(const y of s){const A=St(y,f);o.resolvedSources[A.uid]=A,o.repeaterItemScopes[A.uid]=h,o.repeaterRows[A.uid]=f;const L=Ar(y,A,f,n,c,d);L&&$t(L.repeater,L.declaredPath,f,n,o)}})}function Ar(e,t,r,n,o,i){if(G(e)&&G(t))return{repeater:t,declaredPath:e.path};if(!D(e))return;const s=e({$form:n,$item:o,$index:i,errors:void 0,touched:void 0,translate:void 0});if(s.type!=="repeater")return;const c={...s,uid:e.uid};return{repeater:St(c,r),declaredPath:s.path}}function St(e,t){const r=t[t.length-1];return At(e,t.map(n=>n.index),n=>Cr(n,r))}function Er(e,t){return At(e,t,r=>wr(r,t))}function At(e,t,r){const n=Re(e.uid,t);if(D(e)){const o=i=>e(i);return o.uid=n,o.type=e.type,e.path!==void 0&&(o.path=r(e.path)),o}return I(e)?{...e,uid:n,path:r(e.path)}:{...e,uid:n}}function Re(e,t){if(t.length===0)throw new Error("Repeater indexes cannot be an empty array");const r=t.reduce((n,o)=>`${n}[${o}]`,"");return`${e}${r}`}function wr(e,t){if(t.length===0)throw new Error("Repeater indexes cannot be an empty array");const r=e.split("."),n=r.map((o,i)=>i>0&&o===we?i:-1).filter(o=>o!==-1);if(n.length!==t.length)throw new Error(`Path contains ${n.length} '${we}' occurrences, but ${t.length} indexes were provided.`);return n.forEach((o,i)=>{r[o]=String(t[i])}),r.join(".")}function Cr(e,t){const r=t.declaredItemPath;if(e!==r&&!e.startsWith(`${r}.`))throw new Error(`Path "${e}" is not inside the repeater row "${r}".`);return`${t.itemPath}${e.slice(r.length)}`}function Ir(e,t){let r=e;for(let n=t.length-1;n>=0;n--)r=Or(r,t[n]);return r}function Or(e,t){const r=t.declaredItemPath.split("."),n=t.itemPath.split(".");return e.replace(jr(t.declaredItemPath),(o,i,s,...c)=>{const d=c.slice(0,r.length-1),a=n.map((f,h)=>h===0?f:d[h-1]+f).join("");return`${i}${s??""}${a}`})}const qe=new Map;function jr(e){let t=qe.get(e);if(t===void 0){const r=e.split(".").map(Pr);t=new RegExp(`(^|[^\\w$.])(\\$form\\??\\.)?${r.join("(\\??\\.)")}(?![\\w$])`,"g"),qe.set(e,t)}return t}function Pr(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}const Qe=["include","exclude","disabled","readonly"];function kr(e,t){if(!Qe.some(o=>Je(e[o])))return e;const n={...e};for(const o of Qe){const i=n[o];Je(i)&&(n[o]={...i,when:Ir(i.when,t)})}return n}function Je(e){return e!==null&&typeof e=="object"&&"when"in e&&typeof e.when=="string"}const Dr=50,Wr=e=>{let t=e.data,r=Ce(e.flatForm,t);for(let n=0;n<Dr;n++){let o=!1;for(const i of Object.values(r.resolvedSources))!I(i)||vr(t,i.path)||(t=yt(t,i.path,B(i.defaultValue)),i.defaultValue!==void 0&&(o=!0));if(!o)break;r=Ce(e.flatForm,t)}return{...e,data:t,...r}},Te=32;let Ie,m,g,v=e=>(m=0,g=e,v.newline=!1,e=S(),g[m]?M():e||""),M=(e="Unexpected token",t=m,r=g.slice(0,t).split(`
|
|
2
2
|
`),n=r.pop(),o=g.slice(Math.max(0,t-40),t),i="̭",s=(g[t]||" ")+i,c=g.slice(t+1,t+20))=>{throw SyntaxError(`${e} at ${r.length+1}:${n.length+1}
|
|
3
3
|
${g[t-41]!==`
|
|
4
|
-
`,""+o}${s}${c}`)},
|
|
5
|
-
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},
|
|
6
|
-
`,"/*":"*/"};let ve;v.space=()=>{ve||(ve=Object.entries(v.comment).map(([o,i])=>[o,i,o.charCodeAt(0)]));for(var e;e=
|
|
7
|
-
`)for(;g.charCodeAt(n)>=
|
|
8
|
-
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},nt=()=>{const e=[];for(let t="",r;(r=g.charCodeAt(m))!==ce;)r?r===gn?(E(),t+=yn[g[m]]||g[m],E()):r===hn&&g.charCodeAt(m+1)===mn?(t&&e.push([,t]),t="",E(2),e.push(S(0,125))):(t+=g[m],E(),r=g.charCodeAt(m),r===ce&&t&&e.push([,t])):_("Unterminated template");return E(),e},vn=j[ce];j[ce]=(e,t)=>e&&t<pn?v.asi&&v.newline?void 0:(E(),["``",e,...nt()]):e?vn?.(e,t):(E(),(r=>r.length<2&&r[0]?.[0]===void 0?r[0]||[,""]:["`",...r])(nt()));p("`",(...e)=>(e=e.map(d),t=>e.map(r=>r(t)).join("")));p("``",(e,...t)=>{e=d(e);const r=[],n=[];for(const i of t)Array.isArray(i)&&i[0]===void 0?r.push(i[1]):n.push(d(i));const o=Object.assign([...r],{raw:r});return i=>e(i)(o,...n.map(s=>s(i)))});v.string["'"]=!0;v.number={"0x":16,"0b":2,"0o":8};const $n={log:(e,t)=>(t?console.log(t,e):console.log(e),e)},Sn=2e3,J=new Map;function Ge(e){const t=J.get(e);if(t!==void 0)return t;const r=d(v(An(e)));return J.size>=Sn&&J.clear(),J.set(e,r),r}function b(e,t,r,n,o,i){return Ge(e)({$form:t,$meta:r,$errors:n,$formIsInvalid:o,$log:$n.log,$fn:{},...i})===!0}function An(e){return e.replace(/(\?\.|\.)(\d+)/g,(t,r,n,o)=>r==="."&&En(e,o)?t:r==="?."?`?.[${n}]`:`[${n}]`)}function En(e,t){let r=t-1,n=!1;for(;r>=0&&e[r]>="0"&&e[r]<="9";)n=!0,r--;if(r<0)return!0;const o=e[r];return n?!/[\w$.\]]/.test(o):!/[\w$)\]]/.test(o)}const Cn=e=>(t,r)=>{let n=t.formDef.states;if(!n||Object.keys(n).length===0||t.formHealth.status==="errored")return t;const{$formIsInvalid:o,$errors:i}=r??ae(t);n=wn(n);let s=[],c={status:"ok"};try{s=Object.keys(n).map(u=>{const a=n[u];let f;try{f=b(a,t.data,t.meta,i,o,{$fn:e})}catch{f=!1}return f===!0?u:void 0}).filter(u=>u!==void 0)}catch(u){const a=u,f=w.calculateCurrentStateError;c={status:"errored",message:`[${f}] ${a.message}`,code:f}}return{...t,currentStates:s,formHealth:c}};function wn(e){const t={};function r(n){const o=n.split(":"),i=[];for(let s=0;s<o.length;s++)i.push(o.slice(0,s+1).join(":"));return i}for(const[n,o]of Object.entries(e)){const i=r(n),s=[];for(const c of i)e[c]&&s.push(`(${e[c]})`);t[n]=s.join(" && ")}return t}const K=e=>e!==void 0&&typeof e=="object"&&e!==null&&"when"in e;function ot(e){if(typeof e!="object"||e===null)return!1;const t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function de(e,t){if(e===t)return!0;if(Array.isArray(e)&&Array.isArray(t))return e.length===t.length&&e.every((r,n)=>de(r,t[n]));if(ot(e)&&ot(t)){const r=Object.keys(e);return r.length!==Object.keys(t).length?!1:r.every(n=>n in t&&de(e[n],t[n]))}return!1}const In=e=>(t,r)=>{const{$formIsInvalid:n,$errors:o}=r??ae(t);return{...t,widgetFlags:On(t,o,n,e)}};function On(e,t,r,n){const o=[];for(const[s,c]of Object.entries(e.resolvedSources))if(W(c)){const u=ct(s,c,e);it(u)&&o.push(u)}else it(c)&&o.push(ct(s,c,e));const i=o.reduce((s,c)=>{s[c.uid]=s[c.uid]||{};const u=e.repeaterItemScopes[c.uid],a=u?{$item:N(e.data,u.itemPath),$index:u.index,$fn:n}:{$fn:n};return c.include&&"in"in c.include?s[c.uid].hidden=!c.include.in.some(f=>e.currentStates.includes(f)):c.include&&"when"in c.include&&(s[c.uid].hidden=!b(c.include.when,e.data,e.meta,t,r,a)),c.exclude&&"from"in c.exclude?s[c.uid].hidden=c.exclude.from.some(f=>e.currentStates.includes(f)):c.exclude&&"when"in c.exclude&&(s[c.uid].hidden=b(c.exclude.when,e.data,e.meta,t,r,a)),(I(c)||ee(c))&&K(c.disabled)&&(s[c.uid].disabled=b(c.disabled.when,e.data,e.meta,t,r,a)),I(c)&&K(c.readonly)&&(s[c.uid].readonly=b(c.readonly.when,e.data,e.meta,t,r,a)),s},{});return jn(e,i),i}function it(e){return!!(e.include&&("in"in e.include||"when"in e.include)||e.exclude&&("from"in e.exclude||"when"in e.exclude)||(I(e)||ee(e))&&K(e.disabled)||I(e)&&K(e.readonly))}function jn(e,t){const r=Object.keys(t).filter(n=>t[n].hidden===!0);for(const n of r)Ht(n,e,t)}function Ht(e,t,r){const n=t.resolvedSources[e];if(n!==void 0){if(fe(n)||W(n)&&n.path!==void 0){const o=`${n.path}.`;for(const[i,s]of Object.entries(t.repeaterItemScopes))s.itemPath.startsWith(o)&&st(i,r)}if(L(n)){const o=X(e);for(const i of n.children){const s=o.length>0?Te(i.uid,o):i.uid;if(t.resolvedSources[s]===void 0)continue;const c=r[s]?.hidden===!0;st(s,r),c||Ht(s,t,r)}}}}function st(e,t){t[e]=t[e]||{},t[e].hidden=!0}function ct(e,t,r){const n=r.repeaterItemScopes[e];let o;W(t)?(o={...t({$form:r.data,$item:n?N(r.data,n.itemPath):void 0,$index:n?.index,errors:void 0,touched:void 0,translate:void 0})},o.uid=e):o=t;const i=X(e);return i.length>0&&(o=Ar(o,i)),o}const bt=(e,t)=>(r,n)=>{try{const o=n??ae(r);return{...r,calculatedWidgets:kn(r,e,t,o)}}catch(o){const i=o,s=i.code??w.calculateWidgetPropsError;return{...r,formHealth:{status:"errored",message:`[${s}] ${i.message}`,code:s}}}};function kn(e,t,r,{$formIsInvalid:n,$errors:o}){const i=xn(e,t,n,o,r),s={};for(const c of Object.keys(e.calculatedWidgets)){if(e.widgetFlags[c]?.hidden)continue;const u=e.calculatedWidgets[c],a=u.source,f=e.repeaterItemScopes[c];if(W(a)){s[c]=Dn(u,c,a,e,t,f);continue}const h=f?{...i,$item:N(i.$form,f.itemPath),$index:f.index}:i;s[c]=Wn(u,a,e,h)}return s}function Dn(e,t,r,n,o,i){const s={...r({$form:n.data,errors:r.path?n.validations[r.path]:void 0,touched:r.path?n.touchedControls[r.path]:void 0,translate:o.translate,$item:i?N(n.data,i.itemPath):void 0,$index:i?.index})};s.uid=t,r.path!==void 0&&(s.path=r.path);const c=n.widgetPropOverrides[t];return c!==void 0&&(s.props={...s.props,...c}),e.current&&de(e.current,s)?e:{source:r,current:s}}function Wn(e,t,r,n){const o=new Kn(t,e.current);return o.write("uid",t.uid),o.write("type",t.type),o.write("kind",t.kind),Yt(t)?Pn(o,n):ee(t)?Fn(o,n):I(t)?Tn(o,n):L(t)&&Vn(o,n),Nn(t,o,n,r),(ee(t)||I(t))&&Rn(t,o,n),L(t)&&Ln(t,o,r),o.changed?{source:e.source,current:o.current}:e}function Pn(e,t){A(e,t,"size"),A(e,t,"include"),A(e,t,"exclude")}function Fn(e,t){A(e,t,"size"),A(e,t,"include"),A(e,t,"exclude"),A(e,t,"label"),A(e,t,"disabled"),A(e,t,"actionType")}function Tn(e,t){A(e,t,"size"),A(e,t,"include"),A(e,t,"exclude"),A(e,t,"label"),A(e,t,"disabled"),A(e,t,"readonly"),A(e,t,"validator"),A(e,t,"path"),A(e,t,"defaultValue")}function Vn(e,t){A(e,t,"size"),A(e,t,"include"),A(e,t,"exclude")}function Nn(e,t,r,n){const o=n.widgetPropOverrides[e.uid]??{},i={...e.props??{},...o};for(const s of Gt(Object.keys(i)))_n(t,r,s)}function Rn(e,t,r){const n=e.on??{};for(const o of Gt(Object.keys(n)))Mn(t,r,o)}function Ln(e,t,r){const n=X(e.uid),o=qn(e.children,n,r.widgetFlags);t.current.children=o;const i=t.previous.children??[];i.length===o.length&&o.every((c,u)=>i[u]&&i[u].uid===o[u].uid)||t.markChanged()}function A(e,t,r){const n=e.source;if(!Xn(n,r))return;const o=xe(n,r,t.sortedStates);let i;switch(r){case"disabled":case"readonly":i=bn(o,t,e.source.uid,r);break;case"defaultValue":i=o;break;default:i=Bt(o,t)}e.write(r,i)}function _n(e,t,r){const n=e.source.props,o=xe(n,r,t.sortedStates);let i=Bt(o,t);const s=t.widgetPropOverrides[e.source.uid]?.[r];s!==void 0&&(i=s),e.write(`props.${r}`,i)}function Mn(e,t,r){const n=e.source.on,o=xe(n,r,t.sortedStates);e.write(`on.${r}`,zn(o,t))}function Ke(e,t){return e({$form:t.$form,translate:t.localization.translate,$item:t.$item,$index:t.$index})}function Un(e,t){return t.localization.translate(e.key,Gn(e.params,t),e.default)}const Hn=/\{\{([^}]+)\}\}/g;function zt(e,t){return e.includes("{{")?e.replace(Hn,(r,n)=>{try{const o=Ge(n.trim())({$form:t.$form,$meta:t.$meta,$errors:t.$errors,$formIsInvalid:t.$formIsInvalid,$item:t.$item,$index:t.$index,$fn:t.$fn});return o==null?"":String(o)}catch(o){const i=o instanceof Error?o.message:String(o);throw new Kt(`Failed to evaluate '{{${n.trim()}}}': ${i}`)}}):e}function Bt(e,t){return typeof e=="function"?Ke(e,t):pr(e)?Un(e,t):typeof e=="string"?zt(e,t):e}function bn(e,t,r,n){return typeof e=="function"?Ke(e,t):K(e)?t.widgetFlags[r]?.[n]:typeof e=="string"?zt(e,t):e}function zn(e,t){return typeof e=="function"?Ke(e,t):e}function xe(e,t,r){if(e){for(const n of r){const o=e[`${t}.${n}`];if(o!==void 0)return o}return e[t]}}function Bn(e){return e.startsWith("$form")||e.startsWith("$meta")||e.startsWith("$errors")||e.startsWith("$item")||e.startsWith("$index")||e.startsWith("$fn")||e==="$formIsInvalid"}function Gn(e,t){return e&&Object.keys(e).reduce((r,n)=>{const o=String(e[n]);if(Bn(o))try{const i=Ge(o)({$form:t.$form,$meta:t.$meta,$errors:t.$errors,$formIsInvalid:t.$formIsInvalid,$item:t.$item,$index:t.$index,$fn:t.$fn});r[n]=i??o}catch(i){const s=i instanceof Error?i.message:String(i);throw new Kt(`Failed to evaluate i18n param '${o}': ${s}`)}else r[n]=o;return r},{})}class Kn{constructor(t,r){this._changed=!1,this.source=t,this.previous=r,this.current={}}get changed(){return this._changed}markChanged(){this._changed=!0}write(t,r){const n=N(this.previous,t);if(de(n,r)){Ee(this.current,t,n);return}Ee(this.current,t,r),this._changed=!0}}function xn(e,t,r,n,o){return{sortedStates:[...e.currentStates].sort((i,s)=>s.length-i.length),widgetPropOverrides:e.widgetPropOverrides,widgetFlags:e.widgetFlags,$form:e.data,$meta:e.meta,$formIsInvalid:r,$errors:n,localization:t,$fn:o}}function Xn(e,t){if(t in e)return!0;const r=`${t}.`;return Object.keys(e).some(n=>n.startsWith(r))}function Gt(e){return Array.from(new Set(e.map(t=>t.split(".")[0])))}function qn(e,t,r){const n=t.map(o=>`[${o}]`).join("");return e.filter(o=>{const i=o.uid+n,s=r[i];return!s||s.hidden!==!0})}class Kt extends Error{constructor(){super(...arguments),this.code=w.resolveStringInterpolationError,this.name="StringInterpolationError"}}const Qn=e=>{const t=Jn(e.resolvedSources),r=Z(e.widgetPropOverrides,s=>s in e.resolvedSources),n=Z(e.touchedControls,s=>t.has(s)),o=Z(e.validations,s=>t.has(s)),i=Z(e.injectedValidations,s=>t.has(s));return r===e.widgetPropOverrides&&n===e.touchedControls&&o===e.validations&&i===e.injectedValidations?e:{...e,widgetPropOverrides:r,touchedControls:n,validations:o,injectedValidations:i}};function Jn(e){const t=new Set;for(const r of Object.values(e)){const n=T(r);n!==void 0&&t.add(n)}return t}function Z(e,t){const r=Object.keys(e).filter(t);if(r.length===Object.keys(e).length)return e;const n={};for(const o of r)n[o]=e[o];return n}const Zn=e=>{const t=Object.keys(e.resolvedSources),r={};let n=t.length!==Object.keys(e.calculatedWidgets).length;for(const o of t){const i=e.calculatedWidgets[o];i?r[o]=i:(r[o]={source:e.resolvedSources[o],current:{}},n=!0)}return n?{...e,calculatedWidgets:r}:e},Yn=({lang:e},t)=>{const r={...mt(e),formName:t.payload.formName};let n=t.payload.formDef,o={status:"ok"};if(typeof n=="string"){try{n=JSON.parse(n)}catch(f){const h=f,y=w.initializeParseError;o={status:"errored",message:`[${y}] ${h.message}`,code:y}}if(o.status==="errored")return{...r,formHealth:o}}let i=n;if(Array.isArray(n.form)){const f=n.form;i={...n,form:{uid:"",type:"flex",kind:"layout",children:f}}}const s=ht.decode(i);if(s.isOk()){o={status:"ok"};let f={};try{f=Pe([s.value.form]).reduce((h,y)=>{const C=y.uid;if(h[C])throw{existingWidget:h[C],newWidget:y};return h[C]=y,h},{})}catch(h){o=ro(h.existingWidget,h.newWidget),f={}}return no(f,s.value.states),{...r,formDef:s.value,flatForm:f,...Ce(f,{}),formHealth:o}}const c=to(n);if(c)return{...r,formHealth:c};const u=w.initializeUnknownError,a=s.issues.map(f=>`${f.path.length>0?l.formatIssuePath(f.path):"root"}: ${f.message}`).join("; ");return{...r,formHealth:{status:"errored",message:`[${u}] ${a}`,code:u}}};function xt(e,t){return{status:"errored",code:e,message:`[${e}] ${t}`}}function eo(){return"Malformed form definition. Pass it directly as formDef - `config={{ formDef: { states, form: [...] } }}`. Do NOT wrap it in an extra `{ form: ... }`."}function to(e){if(!e||typeof e!="object"||Array.isArray(e))return null;const t=e.form;return t&&typeof t=="object"&&!Array.isArray(t)&&!L(t)?xt(w.initializeMalformedFormShapeError,eo()):null}function ro(e,t){const r=o=>I(o)?` at "${o.path}"`:"",n=`Duplicate UID "${t.uid}": Assigned to widget "${e.type}"${r(e)} and "${t.type}"${r(t)}.`;return xt(w.initializeUidCollisionError,n)}function no(e,t){const r=new Set(Object.keys(t??{})),n=new Map;for(const i of Object.values(e)){const s=[],c=i.include;c&&Array.isArray(c.in)&&s.push(...c.in);const u=i.exclude;u&&Array.isArray(u.from)&&s.push(...u.from);for(const a of s){if(r.has(a))continue;const f=n.get(a)??[];f.push(i.uid||"(unknown)"),n.set(a,f)}}if(n.size===0)return;const o=r.size?[...r].join(", "):"(none declared)";for(const[i,s]of n)console.error(`[GolemUI] include/exclude references undefined state "${i}" (on ${s.join(", ")}); these widgets will stay hidden. Declared states: ${o}. Fix: declare "${i}" in formConfig.states, or correct the name.`)}function oo(e,t){const{path:r,issues:n}=t.payload,o=n?.length?{touched:!0,touchedControls:{...e.touchedControls,[r]:!0}}:{};return{...e,...o,injectedValidations:{...e.injectedValidations,[r]:n}}}const io=(e,{payload:t})=>{const r="path"in t?co(e,t.path):so(e,t.uid);if(r===void 0)return e;const n=e.widgetPropOverrides[r]||{};return{...e,widgetPropOverrides:{...e.widgetPropOverrides,[r]:{...n,[t.prop]:t.value}}}};function so(e,t){if(t in e.resolvedSources)return t;console.warn(`Widget with uid "${t}" not found`)}function co(e,t){const r=Object.values(e.calculatedWidgets).find(({source:o,current:i})=>(T(i)??T(o))===t);if(r)return r.source.uid;const n=Object.keys(e.resolvedSources).find(o=>T(e.resolvedSources[o])===t);if(n!==void 0)return n;console.warn(`Input with path "${t}" not found`)}const uo=(e,t)=>({...e,data:{...t.payload.data}}),lo=(e,t)=>({...e,formHealth:t.payload.formHealth}),ao=(e,t)=>({...e,lang:t.payload.lang}),fo=(e,t)=>({...e,meta:{...t.payload.meta}}),po=(e,t)=>({...e,data:yt(e.data,t.payload.path,t.payload.data)}),Xt=Symbol("filterMap.skip");function ho(e,t){const r=[];for(let n=0;n<e.length;n++){const o=t(e[n],n,e);o!==Xt&&r.push(o)}return r}function mo(e,t,r){for(let n=0;n<e.length;n++)t(e[n],n,e)&&r(e[n],n,e)}function go(e,t,r){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!r(e[n],t[n],n,e,t))return!1;return!0}const yo=(e,t)=>r=>{const n=ho(Object.values(r.calculatedWidgets),({current:i})=>I(i)?i:Xt),o=r.validations;return{...r,validations:n.reduce((i,s)=>{if(i[s.path]=null,s.validator){const c=e(s.validator,t),u=N(r.data,s.path),a=at(c,u);i[s.path]=ft(a)?null:a.issues.map(f=>f.message)}return Array.isArray(i[s.path])&&Array.isArray(o[s.path])&&go(i[s.path],o[s.path],(c,u)=>c===u)&&(i[s.path]=o[s.path]),i},{})}},vo=({validators:e,validateOn:t,localization:r,functions:n})=>{const o=Ao(r,n),i=yo(e,r),s=bt(r,n),c=a=>dt(a,o,i,!1),u=a=>dt(a,o,i,!0);return(a,f)=>{switch(f.type){case"INITIALIZE":return Yn(a,f);case"SET_DATA":return c(uo(a,f));case"SET_META":return c(fo(a,f));case"SET_WIDGET_DATA":return c(po(a,f));case"SET_LANGUAGE":return s(ao(a,f));case"OVERRIDE_WIDGET_PROP":{const h=io(a,f);if(h===a)return a;const y=c(h);return Io(y,f)?i(y):y}case"SET_FORM_HEALTH":return lo(a,f);case"VALIDATE_ALL":return u(i(Co(a)));case"ATTEMPT_VALIDATION":{if(!wo(t,f.payload.reason))return a;const h={...a,touched:!0,touchedControls:{...a.touchedControls,[f.payload.path]:!0}};return u(i(h))}case"INJECT_VALIDATION_ISSUES":return oo(a,f);default:return mr(f)}}},$o=new Set([w.calculateCurrentStateError,w.calculateWidgetFlagsError,w.calculateWidgetPropsError,w.resolveStringInterpolationError]),So=e=>e.formHealth.status==="errored"&&!$o.has(e.formHealth.code);function Ao(e,t){const r=Cn(t),n=In(t),o=bt(e,t);return function(s){if(So(s))return s;const c=u=>({...s,formHealth:u});try{let u=s.formHealth.status==="ok"?s:{...s,formHealth:{status:"ok"}};u=Cr(u),u=Qn(u);const a=ae(u);return u=r(u,a),u.formHealth.status!=="ok"?c(u.formHealth):(u=n(u,a),u=Zn(u),u=o(u,a),u.formHealth.status==="ok"?u:c(u.formHealth))}catch(u){const a=w.calculateWidgetFlagsError;return c({status:"errored",code:a,message:`[${a}] ${u.message}`})}}}function dt(e,t,r,n){const o=f=>n?ut(f):f,i=e.resolvedSources,s=e.widgetFlags;let c=t(e);if(!c.allControlsValidated||c.formHealth.status!=="ok")return o(c);const u=Eo(c,i,s);if(u.length===0)return o(c);const a={...c.touchedControls};for(const f of u)a[f]=!0;return c={...c,touchedControls:a},ut(t(r(c)))}function Eo(e,t,r){const n=[];for(const[o,i]of Object.entries(e.resolvedSources)){const s=T(i);if(s===void 0||e.widgetFlags[o]?.hidden===!0||e.touchedControls[s]===!0)continue;const c=t[o]===void 0,u=r[o]?.hidden===!0;(c||u)&&n.push(s)}return n}function Co(e){const t={};for(const{source:r,current:n}of Object.values(e.calculatedWidgets)){const o=T(n)??T(r);o!==void 0&&(t[o]=!0)}return{...e,touched:!0,allControlsValidated:!0,touchedControls:t}}function wo(e,t){return e==="eager"||t===e||Array.isArray(e)&&e.includes(t)}function Io(e,t){if(!e.touched)return!1;let r;if("path"in t.payload)r=t.payload.path;else{const n=e.calculatedWidgets[t.payload.uid]?.current;n&&I(n)&&(r=n.path)}return r!==void 0&&e.touchedControls[r]===!0}function ut(e){const t=Object.keys(e.injectedValidations),r=Object.keys(e.validations);if(t.length===0&&r.length===0)return{...e,isFormValid:!0};let n=t.find(o=>{const i=e.injectedValidations[o];return Array.isArray(i)&&i.length>0});return n!==void 0?{...e,isFormValid:!1}:(n=r.find(o=>{const i=e.validations[o];return Array.isArray(i)&&i.length>0}),n!==void 0?{...e,isFormValid:!1}:{...e,isFormValid:!0})}function Oo(e=[],t,r,n,o={}){const i=new D.BehaviorSubject(mt(n.lang)),s=i.asObservable().pipe(D.distinctUntilChanged()),c=vo({validators:t,validateOn:r,localization:n,functions:o});function u(y){const C=i.getValue(),me=c(C,y);i.next(me)}let a=u;const f={getState:()=>i.getValue(),dispatch:y=>a(y)};return a=e.map(y=>y(f)).reduceRight((y,C)=>C(y),u),{state$:s,dispatch:a,getState:()=>i.getValue()}}class jo{constructor(){this.widgetRegistry=new te,this.store={},this.events$=new D.Subject,this.submit$=new D.Subject,this.itemRenderers={},this.dependencies={}}initialize(t,r=[],n,o,i,s=gt(),c,u={}){this.localization=s,this.dependencies=c,this.widgetRegistry.setWidgetLoaders(t),this.itemRenderers=i,this.store=Oo(r,n,o,s,u)}emitEvent(t,r,n){const i=this.store.getState().currentStates.filter(s=>r.on?.[`${t}.${s}`]!==void 0);if(this.attemptValidation(t,r),i.length>0)i.forEach(s=>{const c=r.on?.[`${t}.${s}`];c&&this.events$.next({name:c,data:ye(this.store.getState()),detail:n??void 0,callback:u=>{this.store.dispatch(u)}})});else{const s=r.on?.[t];s&&this.events$.next({name:s,data:ye(this.store.getState()),detail:n,callback:c=>{this.store.dispatch(c)}})}}emitSubmitEvent(){this.store.dispatch({type:"VALIDATE_ALL"}),this.store.getState().isFormValid&&this.submit$.next({data:ye(this.store.getState()),callback:t=>{this.store.dispatch(t)}})}attemptValidation(t,r){r.kind!=="layout"&&(t==="change"?this.store.dispatch({type:"ATTEMPT_VALIDATION",payload:{reason:"change",path:r.path,uid:r.uid}}):t==="click"&&r.kind==="action"&&r.actionType==="submit"&&this.store.dispatch({type:"VALIDATE_ALL"}))}}function ko(e="GolemUI Form Store"){return t=>{const n=(typeof window<"u"?window.__REDUX_DEVTOOLS_EXTENSION__:void 0)?.connect({name:e});return n?.init(t.getState()),o=>i=>{o(i),n&&n.send(i,t.getState())}}}const Do=D.pipe(D.map(e=>e.formHealth),D.distinctUntilChanged((e,t)=>e.status!==t.status?!1:e.status==="errored"&&t.status==="errored"?e.message===t.message&&e.code===t.code:!0)),Wo=e=>e.pipe(Do);function Po(e,t){return Jt(e,t,Qt(e,t),void 0)}function qt(){const e=new Map;return(t,r)=>{const n=Qt(t,r),o=e.get(r);if(o&&No(o.slices,n))return o.viewModel;const i=Jt(t,r,n,o);return e.set(r,{slices:n,viewModel:i}),i}}const Fo=e=>t=>{const r=qt();return t.pipe(D.map(n=>r(n,e)),D.distinctUntilChanged())},To=[],lt=[],Vo=[];function Qt(e,t){const r=Ro(e,t);return[e.calculatedWidgets[t],e.lang,r===void 0?void 0:N(e.data,r),r!==void 0&&e.touched?e.validations[r]:null,r!==void 0&&e.touched?e.injectedValidations[r]:null,r!==void 0&&e.touchedControls[r]===!0,e.touched&&!e.isFormValid,e.widgetFlags[t]?.hidden===!0]}function No(e,t){return e.every((r,n)=>Object.is(r,t[n]))}function Jt(e,t,r,n){const[o,i,s,c,u,a,f,h]=r,y=n===void 0||!Object.is(n.slices[0],o),C=n===void 0||!Object.is(n.slices[2],s),me=n===void 0||!Object.is(n.slices[3],c)||!Object.is(n.slices[4],u),ge=o?.current;return{uid:t,widget:ge,children:y?Lo(e,t,ge):n.viewModel.children,rows:y||C?_o(e,t,ge,s):n.viewModel.rows,lang:i,value:s,errors:me?Mo(c,u):n.viewModel.errors,touched:a,formInvalid:f,hidden:h}}function Ro(e,t){return e.resolvedSources[t]?.path}function Lo(e,t,r){if(r===void 0||!L(r))return To;const n=r.children,o=X(t);if(o.length===0)return n;const i=o.map(s=>`[${s}]`).join("");return n.map(s=>e.resolvedSources[`${s.uid}${i}`]??s)}function _o(e,t,r,n){if(r===void 0||!Array.isArray(n))return lt;const o=e.resolvedSources[t];if(o===void 0||!fe(o))return lt;const i=o.props.template.uid,s=X(t);return n.map((c,u)=>{const a=Te(i,[...s,u]);return e.resolvedSources[a]}).filter(c=>c!==void 0)}function Mo(e,t){return(e?.length??0)+(t?.length??0)===0?Vo:[...e??[],...t??[]]}let Zt=!1;function Uo(){Zt=!0}function Ho(){return Zt}function bo(e,t,r){if(!Ho())return;const n=Object.keys(t??{}).filter(o=>o in r);if(n.length>0)throw new Error(`[GolemUI] Widget "${e}": prop keys [${n.join(", ")}] collide with widget fields`)}const zo=()=>crypto.randomUUID().slice(0,8);exports.FormContext=jo;exports.assertNoPropCollisions=bo;exports.cloneObject=z;exports.createWidgetViewModelReader=qt;exports.defineForm=ar;exports.devToolsMiddleware=ko;exports.enableDevMode=Uo;exports.errorCodes=w;exports.filterTap=mo;exports.formEventNames=fr;exports.formHealth=Wo;exports.getDirectionFromLanguage=hr;exports.identityTranslator=gt;exports.isStandardValidateSuccess=ft;exports.makeRepeaterItemConfig=Fe;exports.preloadFormWidgets=ur;exports.shortUUID=zo;exports.standardValidate=at;exports.widgetViewModel=Po;exports.widgetViewModel$=Fo;
|
|
4
|
+
`,""+o}${s}${c}`)},Et=(e,t=m)=>(Array.isArray(e)&&(e.loc=t),e),H=(e,t=m,r)=>{for(;r=e(g.charCodeAt(m));)m+=r;return g.slice(t,m)},w=(e=1)=>g[m+=e],Oe=e=>m=e,S=(e=0,t)=>{let r,n,o,i,s;for(t&&v.asi&&(v.newline=!1);(r=v.space())&&(s=v.newline,1)&&r!==t&&(o=(n&&r===91&&Ie&&v.asi?.(n,e,S)||null)??((i=j[r])&&i(n,e))??(n&&s&&v.asi?.(n,e,S))??(!n&&H(v.id)));)n=o;return t&&(r==t?(m++,t===125&&v.asi&&(v.newline=!0)):M("Unclosed "+String.fromCharCode(t-(t>42?2:1)))),n},T=(e,t=m)=>{for(Ie=!1;(e=g.charCodeAt(m))<=Te;)v.asi&&e===10&&(v.newline=Ie=!0),m++;return e},Fr=(e=m)=>{for(;g.charCodeAt(e)<=Te;)e++;return g.charCodeAt(e)};v.id=e=>e>=48&&e<=57||e>=65&&e<=90||e>=97&&e<=122||e==36||e==95||e>=192&&e!=215&&e!=247;let Rr=(e,t=e.length)=>g.substr(m,t)===e&&!v.id(g.charCodeAt(m+t)),j=[],Ze={},O=(e,t=Te,r,n=e.charCodeAt(0),o=e.length,i=j[n],s=e.toUpperCase()!==e,c,d)=>(t=Ze[e]=!i&&Ze[e]||t,j[n]=(a,f,h,y=m)=>(c=h,(h?e==h:(o<2||e.charCodeAt(1)===g.charCodeAt(m+1)&&(o<3||g.substr(m,o)==e))&&(!s||!v.id(g.charCodeAt(m+o)))&&(c=h=e))&&f<t&&(m+=o,(d=r(a))?Et(d,y):(m=y,c=0,!s&&!i&&!a&&M()),d)||i?.(a,f,c))),$=(e,t,r=!1)=>O(e,t,n=>n&&(o=>o&&[e,n,o])(S(t-(r?.5:0)))),N=(e,t,r)=>O(e,t,n=>!n&&(n=S(t-.5))&&[e,n]),Q=(e,t)=>O(e,200,r=>!r&&[,t]),wt=(e,t,r)=>O(e,t,(n,o)=>(o=S(t-(r?.5:0)),n?.[0]!==e&&(n=[e,n||null]),o?.[0]===e?n.push(...o.slice(1)):n.push(o||null),n)),Ve=(e,t)=>O(e[0],t,r=>!r&&[e,S(0,e.charCodeAt(1))||null]),Ct=(e,t)=>O(e[0],t,r=>r&&[e,r,S(0,e.charCodeAt(1))||null]),J=(e,t,r,n=e.charCodeAt(0),o=e.length,i=j[n],s)=>j[n]=(c,d,a,f=m)=>!c&&(a?e==a:(o<2||g.substr(m,o)==e)&&(a=e))&&d<t&&!v.id(g.charCodeAt(m+o))&&(!v.prop||v.prop(m+o))&&(Oe(m+o),(s=r())?Et(s,f):Oe(f),s)||i?.(c,d,a);Object.defineProperty(v,"space",{configurable:!0,enumerable:!0,get:()=>T,set:e=>T=e});const je={},p=(e,t,r=je[e])=>je[e]=(...n)=>t(...n)||r?.(...n),u=e=>Array.isArray(e)?e[0]==null?(t=>()=>t)(e[1]):je[e[0]]?.(...e.slice(1))??M(`Unknown operator: ${e[0]}`,e?.loc):e===void 0?()=>{}:t=>t?.[e],ne=46,K=48,oe=57,Tr=69,Vr=101,Nr=43,Lr=45,ee=95,It=110,_r=97,Mr=102,Ur=65,Hr=70,Ot=e=>e.indexOf("_")<0?e:e.replaceAll("_",""),Ne=e=>{let t=Ot(H(r=>r===ne&&g.charCodeAt(m+1)!==ne||r>=K&&r<=oe||r===ee||((r===Tr||r===Vr)&&((r=g.charCodeAt(m+1))>=K&&r<=oe||r===Nr||r===Lr)?2:0)));return g.charCodeAt(m)===It?(w(),[,BigInt(t)]):(e=+t)!=e?M():[,e]},br={2:e=>e===48||e===49||e===ee,8:e=>e>=48&&e<=55||e===ee,16:e=>e>=K&&e<=oe||e>=_r&&e<=Mr||e>=Ur&&e<=Hr||e===ee};v.number=null;j[ne]=e=>!e&&g.charCodeAt(m+1)!==ne&&Ne();for(let e=K;e<=oe;e++)j[e]=t=>t?void 0:Ne();j[K]=e=>{if(e)return;const t=v.number;if(t){for(const[r,n]of Object.entries(t))if(r[0]==="0"&&g[m+1]?.toLowerCase()===r[1]){w(2);const o=Ot(H(br[n]));return g.charCodeAt(m)===It?(w(),[,BigInt("0"+r[1]+o)]):[,parseInt(o,n)]}}return Ne()};const zr=92,Ye=34,et=39,Br={n:`
|
|
5
|
+
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},jt=e=>(t,r,n="")=>{if(!(t||!v.string?.[String.fromCharCode(e)]))return w(),H(o=>o-e&&(o===zr?(n+=Br[g[m+1]]||g[m+1],2):(n+=g[m],1))),g[m]===String.fromCharCode(e)?w():M("Bad string"),[,n]};j[Ye]=jt(Ye);j[et]=jt(et);v.string={'"':!0};const Gr=20;"= += -= *= /= %= |= &= ^= >>= <<=".split(" ").map(e=>$(e,Gr,!0));const Pt=(e,t,r,n)=>typeof e=="string"?o=>t(o,e,o):e[0]==="."?(r=u(e[1]),n=e[2],o=>t(r(o),n,o)):e[0]==="[]"&&e.length===3?(r=u(e[1]),n=u(e[2]),o=>t(r(o),n(o),o)):e[0]==="()"&&e.length===2?Pt(e[1],t):(()=>{throw Error("Invalid assignment target")})(),tt={"=":(e,t,r)=>e[t]=r,"+=":(e,t,r)=>e[t]+=r,"-=":(e,t,r)=>e[t]-=r,"*=":(e,t,r)=>e[t]*=r,"/=":(e,t,r)=>e[t]/=r,"%=":(e,t,r)=>e[t]%=r,"|=":(e,t,r)=>e[t]|=r,"&=":(e,t,r)=>e[t]&=r,"^=":(e,t,r)=>e[t]^=r,">>=":(e,t,r)=>e[t]>>=r,"<<=":(e,t,r)=>e[t]<<=r};for(const e in tt)p(e,(t,r)=>(r=u(r),Pt(t,(n,o,i)=>tt[e](n,o,r(i)))));const Kr=30,xr=40,Xr=140;N("!",Xr);$("||",Kr);$("&&",xr);p("!",e=>(e=u(e),t=>!e(t)));p("||",(e,t)=>(e=u(e),t=u(t),r=>e(r)||t(r)));p("&&",(e,t)=>(e=u(e),t=u(t),r=>e(r)&&t(r)));const qr=50,Qr=60,Jr=70,kt=100,Zr=140;$("|",qr);$("&",Jr);$("^",Qr);$(">>",kt);$("<<",kt);N("~",Zr);p("~",e=>(e=u(e),t=>~e(t)));p("|",(e,t)=>(e=u(e),t=u(t),r=>e(r)|t(r)));p("&",(e,t)=>(e=u(e),t=u(t),r=>e(r)&t(r)));p("^",(e,t)=>(e=u(e),t=u(t),r=>e(r)^t(r)));p(">>",(e,t)=>(e=u(e),t=u(t),r=>e(r)>>t(r)));p("<<",(e,t)=>(e=u(e),t=u(t),r=>e(r)<<t(r)));const he=90;$("<",he);$(">",he);$("<=",he);$(">=",he);p(">",(e,t)=>(e=u(e),t=u(t),r=>e(r)>t(r)));p("<",(e,t)=>(e=u(e),t=u(t),r=>e(r)<t(r)));p(">=",(e,t)=>(e=u(e),t=u(t),r=>e(r)>=t(r)));p("<=",(e,t)=>(e=u(e),t=u(t),r=>e(r)<=t(r)));const Dt=80;$("==",Dt);$("!=",Dt);p("==",(e,t)=>(e=u(e),t=u(t),r=>e(r)==t(r)));p("!=",(e,t)=>(e=u(e),t=u(t),r=>e(r)!=t(r)));const Wt=110,Le=120,Ft=140;$("+",Wt);$("-",Wt);$("*",Le);$("/",Le);$("%",Le);N("+",Ft);N("-",Ft);p("+",(e,t)=>t!==void 0?(e=u(e),t=u(t),r=>e(r)+t(r)):(e=u(e),r=>+e(r)));p("-",(e,t)=>t!==void 0?(e=u(e),t=u(t),r=>e(r)-t(r)):(e=u(e),r=>-e(r)));p("*",(e,t)=>(e=u(e),t=u(t),r=>e(r)*t(r)));p("/",(e,t)=>(e=u(e),t=u(t),r=>e(r)/t(r)));p("%",(e,t)=>(e=u(e),t=u(t),r=>e(r)%t(r)));const ie=150;O("++",ie,e=>e?["++",e,null]:["++",S(ie-1)]);O("--",ie,e=>e?["--",e,null]:["--",S(ie-1)]);const _e=(e,t,r,n)=>typeof e=="string"?o=>t(o,e):e[0]==="."?(r=u(e[1]),n=e[2],o=>t(r(o),n)):e[0]==="[]"&&e.length===3?(r=u(e[1]),n=u(e[2]),o=>t(r(o),n(o))):e[0]==="()"&&e.length===2?_e(e[1],t):(()=>{throw Error("Invalid increment target")})();p("++",(e,t)=>_e(e,t===null?(r,n)=>r[n]++:(r,n)=>++r[n]));p("--",(e,t)=>_e(e,t===null?(r,n)=>r[n]--:(r,n)=>--r[n]));const Yr=5,en=10;wt(",",en);wt(";",Yr,!0);const Rt=(...e)=>(e=e.map(u),t=>{let r;for(const n of e)r=n(t);return r});p(",",Rt);p(";",Rt);const tn=170;Ve("()",tn);const F=e=>e?.[0]==="_"&&e[1]==="_"||e==="constructor"||e==="prototype",Me=170;Ct("[]",Me);$(".",Me);Ct("()",Me);const se=e=>{throw Error(e)};p("[]",(e,t)=>t===void 0?(e=e?e[0]===","?e.slice(1):[e]:[],e=e.map(r=>r==null?(()=>{}):r[0]==="..."?(r=u(r[1]),n=>r(n)):(r=u(r),n=>[r(n)])),r=>e.flatMap(n=>n(r))):(t==null&&se("Missing index"),e=u(e),t=u(t),r=>{const n=t(r);return F(n)?void 0:e(r)[n]}));p(".",(e,t)=>(e=u(e),t=t[0]?t:t[1],F(t)?()=>{}:r=>e(r)[t]));p("()",(e,t)=>{if(t===void 0)return e==null?se("Empty ()"):u(e);const r=o=>o?.[0]===","&&o.slice(1).some(i=>i==null||r(i));r(t)&&se("Empty argument");const n=t?t[0]===","?(t=t.slice(1).map(u),o=>t.map(i=>i(o))):(t=u(t),o=>[t(o)]):()=>[];return Ue(e,(o,i,s)=>o[i](...n(s)))});const U=e=>typeof e=="string"||Array.isArray(e)&&(e[0]==="."||e[0]==="?."||e[0]==="[]"&&e.length===3||e[0]==="?.[]"||e[0]==="()"&&e.length===2&&U(e[1])||e[0]==="{}"),Ue=(e,t,r,n)=>e==null?se("Empty ()"):e[0]==="()"&&e.length==2?Ue(e[1],t):typeof e=="string"?o=>t(o,e,o):e[0]==="."?(r=u(e[1]),n=e[2],o=>t(r(o),n,o)):e[0]==="?."?(r=u(e[1]),n=e[2],o=>{const i=r(o);return i==null?void 0:t(i,n,o)}):e[0]==="[]"&&e.length===3?(r=u(e[1]),n=u(e[2]),o=>t(r(o),n(o),o)):e[0]==="?.[]"?(r=u(e[1]),n=u(e[2]),o=>{const i=r(o);return i==null?void 0:t(i,n(o),o)}):(e=u(e),o=>t([e(o)],0,o)),b=Ue,rn=32,nn=v.space;v.comment??={"//":`
|
|
6
|
+
`,"/*":"*/"};let ve;v.space=()=>{ve||(ve=Object.entries(v.comment).map(([o,i])=>[o,i,o.charCodeAt(0)]));for(var e;e=nn();){for(var t=0,r;r=ve[t++];)if(e===r[2]&&g.substr(m,r[0].length)===r[0]){var n=m+r[0].length;if(r[1]===`
|
|
7
|
+
`)for(;g.charCodeAt(n)>=rn;)n++;else{for(;g[n]&&g.substr(n,r[1].length)!==r[1];)n++;g[n]&&(n+=r[1].length)}Oe(n),e=0;break}if(e)return e}return e};const Tt=80;$("===",Tt);$("!==",Tt);p("===",(e,t)=>(e=u(e),t=u(t),r=>e(r)===t(r)));p("!==",(e,t)=>(e=u(e),t=u(t),r=>e(r)!==t(r)));const on=30;$("??",on);p("??",(e,t)=>(e=u(e),t=u(t),r=>e(r)??t(r)));const sn=130,cn=20;$("**",sn,!0);$("**=",cn,!0);p("**",(e,t)=>(e=u(e),t=u(t),r=>e(r)**t(r)));const dn=e=>{throw Error(e)};p("**=",(e,t)=>(U(e)||dn("Invalid assignment target"),t=u(t),b(e,(r,n,o)=>r[n]**=t(o))));const Vt=90;$("in",Vt);$("of",Vt);p("in",(e,t)=>(e=u(e),t=u(t),r=>e(r)in t(r)));const un=20,ln=100,an=e=>{throw Error(e)};$(">>>",ln);$(">>>=",un,!0);p(">>>",(e,t)=>(e=u(e),t=u(t),r=>e(r)>>>t(r)));p(">>>=",(e,t)=>(U(e)||an("Invalid assignment target"),t=u(t),b(e,(r,n,o)=>r[n]>>>=t(o))));const He=5,fn=10,pn=20,hn=e=>e[0]?.[0]===","?e[0].slice(1):e,ce=(e,t,r)=>{if(typeof e=="string"){r[e]=t;return}const[n,...o]=e,i=hn(o);if(n==="{}"){const s=[];for(const c of i){if(Array.isArray(c)&&c[0]==="..."){const y={};for(const A in t)s.includes(A)||(y[A]=t[A]);r[c[1]]=y;break}let d,a,f;typeof c=="string"?d=a=c:c[0]==="="?(typeof c[1]=="string"?d=a=c[1]:[,d,a]=c[1],f=c[2]):[,d,a]=c,s.push(d);let h=t[d];h===void 0&&f&&(h=u(f)(r)),ce(a,h,r)}}else if(n==="[]"){let s=0;for(const c of i){if(c===null){s++;continue}if(Array.isArray(c)&&c[0]==="..."){r[c[1]]=t.slice(s);break}let d=c,a;Array.isArray(c)&&c[0]==="="&&([,d,a]=c);let f=t[s++];f===void 0&&a&&(f=u(a)(r)),ce(d,f,r)}}},Nt=e=>{let t=S(fn-1);return t?.[0]==="in"||t?.[0]==="of"?[t[0],[e,t[1]],t[2]]:t?.[0]===","?[e,...t.slice(1)]:[e,t]};J("let",He+1,()=>Nt("let"));J("const",He+1,()=>Nt("const"));J("var",He,()=>(T(),["var",S(pn)]));const Lt=(...e)=>(e=e.map(t=>{if(typeof t=="string")return r=>{r[t]=void 0};if(t[0]==="="){const[,r,n]=t,o=u(n);return typeof r=="string"?i=>{i[r]=o(i)}:i=>ce(r,o(i),i)}return u(t)}),t=>{for(const r of e)r(t)});p("let",Lt);p("const",Lt);p("var",e=>typeof e=="string"?t=>{t[e]=void 0}:()=>{});const be=20,me=e=>{throw Error(e)};$("||=",be,!0);$("&&=",be,!0);$("??=",be,!0);p("=",(e,t)=>{if(Array.isArray(e)&&(e[0]==="let"||e[0]==="const"||e[0]==="var")){const r=e[1];return t=u(t),typeof r=="string"?n=>{n[r]=t(n)}:n=>ce(r,t(n),n)}return U(e)||me("Invalid assignment target"),t=u(t),b(e,(r,n,o)=>r[n]=t(o))});p("||=",(e,t)=>(U(e)||me("Invalid assignment target"),t=u(t),b(e,(r,n,o)=>r[n]||=t(o))));p("&&=",(e,t)=>(U(e)||me("Invalid assignment target"),t=u(t),b(e,(r,n,o)=>r[n]&&=t(o))));p("??=",(e,t)=>(U(e)||me("Invalid assignment target"),t=u(t),b(e,(r,n,o)=>r[n]??=t(o))));Q("true",!0);Q("false",!1);Q("null",null);J("undefined",200,()=>[]);Q("NaN",NaN);Q("Infinity",1/0);const $e=20;O("?",$e,(e,t,r)=>e&&(t=S($e-1))&&H(n=>n===58)&&(r=S($e-1),["?",e,t,r]));p("?",(e,t,r)=>(e=u(e),t=u(t),r=u(r),n=>e(n)?t(n):r(n)));const mn=[],gn=20;$("=>",gn,!0);p("=>",(e,t)=>{e=e?.[0]==="()"?e[1]:e;const r=e?e[0]===","?e.slice(1):[e]:[];let n=-1,o=null;const i=r[r.length-1];Array.isArray(i)&&i[0]==="..."&&(n=r.length-1,o=i[1],r.length--);const s=t?.[0]==="{}";return t=u(s?["{",t[1]]:t),c=>(...d)=>{const a={};r.forEach((h,y)=>a[h]=d[y]),o&&(a[o]=d.slice(n));const f=new Proxy(a,{get:(h,y)=>y in h?h[y]:c?.[y],set:(h,y,A)=>((y in h?h:c)[y]=A,!0),has:(h,y)=>y in h||(c?y in c:!1)});try{const h=t(f);return s?void 0:h}catch(h){if(h===mn)return h[0];throw h}}});const yn=140;N("...",yn);p("...",e=>(e=u(e),t=>Object.entries(e(t))));const rt=170;O("?.",rt,(e,t)=>{if(!e)return;const r=T();return r===40?(w(),["?.()",e,S(0,41)||null]):r===91?(w(),["?.[]",e,S(0,93)]):(t=S(rt),t?["?.",e,t]:void 0)});p("?.",(e,t)=>(e=u(e),F(t)?()=>{}:r=>e(r)?.[t]));p("?.[]",(e,t)=>(e=u(e),t=u(t),r=>{const n=t(r);return F(n)?void 0:e(r)?.[n]}));p("?.()",(e,t)=>{const r=t?t[0]===","?(t=t.slice(1).map(u),o=>t.map(i=>i(o))):(t=u(t),o=>[t(o)]):()=>[];if(e[0]==="?."){const o=u(e[1]),i=e[2];return F(i)?()=>{}:s=>o(s)?.[i]?.(...r(s))}if(e[0]==="?.[]"){const o=u(e[1]),i=u(e[2]);return s=>{const c=o(s),d=i(s);return F(d)?void 0:c?.[d]?.(...r(s))}}if(e[0]==="."){const o=u(e[1]),i=e[2];return F(i)?()=>{}:s=>o(s)?.[i]?.(...r(s))}if(e[0]==="[]"&&e.length===3){const o=u(e[1]),i=u(e[2]);return s=>{const c=o(s),d=i(s);return F(d)?void 0:c?.[d]?.(...r(s))}}const n=u(e);return o=>n(o)?.(...r(o))});const x=140;N("typeof",x);N("void",x);N("delete",x);J("new",x,()=>Rr(".target")?(w(7),["new.target"]):["new",S(x)]);p("typeof",e=>(e=u(e),t=>typeof e(t)));p("void",e=>(e=u(e),t=>(e(t),void 0)));p("delete",e=>{if(e[0]==="."){const t=u(e[1]),r=e[2];return n=>delete t(n)[r]}if(e[0]==="[]"){const t=u(e[1]),r=u(e[2]);return n=>delete t(n)[r(n)]}return()=>!0});p("new",e=>{const t=u(e?.[0]==="()"?e[1]:e),r=e?.[0]==="()"?e[2]:null,n=r?r[0]===","?(o=>i=>o.map(s=>s(i)))(r.slice(1).map(u)):(o=>i=>[o(i)])(u(r)):()=>[];return o=>new(t(o))(...n(o))});const ze=Symbol("accessor"),Be=20,vn=40,_t=41,Mt=123,Ut=125,Ht=e=>t=>{if(t)return;T();const r=H(v.id);if(!r||(T(),g.charCodeAt(m)!==vn))return!1;w();const n=S(0,_t);return T(),g.charCodeAt(m)!==Mt?!1:(w(),[e,r,n,S(0,Ut)])};O("get",Be-1,Ht("get"));O("set",Be-1,Ht("set"));O("(",Be-1,e=>{if(!e||typeof e!="string")return;const t=S(0,_t)||null;if(T(),g.charCodeAt(m)===Mt)return w(),[":",e,["=>",["()",t],S(0,Ut)||null]]});p("get",(e,t)=>(t=t?u(t):()=>{},r=>[[ze,e,{get:function(){const n=Object.create(r||{});return n.this=this,t(n)}}]]));p("set",(e,t,r)=>(r=r?u(r):()=>{},n=>[[ze,e,{set:function(o){const i=Object.create(n||{});i.this=this,i[t]=o,r(i)}}]]));const $n=20,bt=200;v.prop=e=>Fr(e)!==58;const Sn=e=>e==null||typeof e=="string"||[":",",","...","get","set"].includes(e[0]);Ve("[]",bt);Ve("{}",bt);$(":",$n-1,!0);p("{}",(e,t)=>{if(t!==void 0)return;if(!Sn(e))return u(["{",e]);e=e?e[0]!==","?[e]:e.slice(1):[];const r=e.map(n=>u(typeof n=="string"?[":",n,n]:n));return n=>{const o={},i={};for(const s of r.flatMap(c=>c(n)))if(s[0]===ze){const[,c,d]=s;i[c]={...i[c],...d,configurable:!0,enumerable:!0}}else o[s[0]]=s[1];for(const s in i)Object.defineProperty(o,s,i[s]);return o}});p("{",e=>(e=e?u(e):()=>{},t=>e(Object.create(t))));p(":",(e,t)=>(t=u(t),Array.isArray(e)?(e=u(e),r=>[[e(r),t(r)]]):r=>[[e,t(r)]]));const An=170,de=96,En=36,wn=123,Cn=92,In={n:`
|
|
8
|
+
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},nt=()=>{const e=[];for(let t="",r;(r=g.charCodeAt(m))!==de;)r?r===Cn?(w(),t+=In[g[m]]||g[m],w()):r===En&&g.charCodeAt(m+1)===wn?(t&&e.push([,t]),t="",w(2),e.push(S(0,125))):(t+=g[m],w(),r=g.charCodeAt(m),r===de&&t&&e.push([,t])):M("Unterminated template");return w(),e},On=j[de];j[de]=(e,t)=>e&&t<An?v.asi&&v.newline?void 0:(w(),["``",e,...nt()]):e?On?.(e,t):(w(),(r=>r.length<2&&r[0]?.[0]===void 0?r[0]||[,""]:["`",...r])(nt()));p("`",(...e)=>(e=e.map(u),t=>e.map(r=>r(t)).join("")));p("``",(e,...t)=>{e=u(e);const r=[],n=[];for(const i of t)Array.isArray(i)&&i[0]===void 0?r.push(i[1]):n.push(u(i));const o=Object.assign([...r],{raw:r});return i=>e(i)(o,...n.map(s=>s(i)))});v.string["'"]=!0;v.number={"0x":16,"0b":2,"0o":8};const jn={log:(e,t)=>(t?console.log(t,e):console.log(e),e)},Pn=2e3,Z=new Map;function Ge(e){const t=Z.get(e);if(t!==void 0)return t;const r=u(v(kn(e)));return Z.size>=Pn&&Z.clear(),Z.set(e,r),r}function z(e,t,r,n,o,i){return Ge(e)({$form:t,$meta:r,$errors:n,$formIsInvalid:o,$log:jn.log,$fn:{},...i})===!0}function kn(e){return e.replace(/(\?\.|\.)(\d+)/g,(t,r,n,o)=>r==="."&&Dn(e,o)?t:r==="?."?`?.[${n}]`:`[${n}]`)}function Dn(e,t){let r=t-1,n=!1;for(;r>=0&&e[r]>="0"&&e[r]<="9";)n=!0,r--;if(r<0)return!0;const o=e[r];return n?!/[\w$.\]]/.test(o):!/[\w$)\]]/.test(o)}const Wn=e=>(t,r)=>{let n=t.formDef.states;if(!n||Object.keys(n).length===0||t.formHealth.status==="errored")return t;const{$formIsInvalid:o,$errors:i}=r??fe(t);n=Fn(n);let s=[],c={status:"ok"};try{s=Object.keys(n).map(d=>{const a=n[d];let f;try{f=z(a,t.data,t.meta,i,o,{$fn:e})}catch{f=!1}return f===!0?d:void 0}).filter(d=>d!==void 0)}catch(d){const a=d,f=C.calculateCurrentStateError;c={status:"errored",message:`[${f}] ${a.message}`,code:f}}return{...t,currentStates:s,formHealth:c}};function Fn(e){const t={};function r(n){const o=n.split(":"),i=[];for(let s=0;s<o.length;s++)i.push(o.slice(0,s+1).join(":"));return i}for(const[n,o]of Object.entries(e)){const i=r(n),s=[];for(const c of i)e[c]&&s.push(`(${e[c]})`);t[n]=s.join(" && ")}return t}const X=e=>e!==void 0&&typeof e=="object"&&e!==null&&"when"in e;function ot(e){if(typeof e!="object"||e===null)return!1;const t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function ue(e,t){if(e===t)return!0;if(Array.isArray(e)&&Array.isArray(t))return e.length===t.length&&e.every((r,n)=>ue(r,t[n]));if(ot(e)&&ot(t)){const r=Object.keys(e);return r.length!==Object.keys(t).length?!1:r.every(n=>n in t&&ue(e[n],t[n]))}return!1}const Rn=e=>(t,r)=>{const{$formIsInvalid:n,$errors:o}=r??fe(t);return{...t,widgetFlags:Tn(t,o,n,e)}};function Tn(e,t,r,n){const o=[];for(const[s,c]of Object.entries(e.resolvedSources))if(D(c)){const d=ct(s,c,e);it(d)&&o.push(d)}else it(c)&&o.push(ct(s,c,e));const i=o.reduce((s,c)=>{s[c.uid]=s[c.uid]||{};const d=e.repeaterItemScopes[c.uid],a=d?{$item:V(e.data,d.itemPath),$index:d.index,$fn:n}:{$fn:n};return c.include&&"in"in c.include?s[c.uid].hidden=!c.include.in.some(f=>e.currentStates.includes(f)):c.include&&"when"in c.include&&(s[c.uid].hidden=!z(c.include.when,e.data,e.meta,t,r,a)),c.exclude&&"from"in c.exclude?s[c.uid].hidden=c.exclude.from.some(f=>e.currentStates.includes(f)):c.exclude&&"when"in c.exclude&&(s[c.uid].hidden=z(c.exclude.when,e.data,e.meta,t,r,a)),(I(c)||te(c))&&X(c.disabled)&&(s[c.uid].disabled=z(c.disabled.when,e.data,e.meta,t,r,a)),I(c)&&X(c.readonly)&&(s[c.uid].readonly=z(c.readonly.when,e.data,e.meta,t,r,a)),s},{});return Vn(e,i),i}function it(e){return!!(e.include&&("in"in e.include||"when"in e.include)||e.exclude&&("from"in e.exclude||"when"in e.exclude)||(I(e)||te(e))&&X(e.disabled)||I(e)&&X(e.readonly))}function Vn(e,t){const r=Object.keys(t).filter(n=>t[n].hidden===!0);for(const n of r)zt(n,e,t)}function zt(e,t,r){const n=t.resolvedSources[e];if(n!==void 0){if(G(n)||D(n)&&n.path!==void 0){const o=`${n.path}.`;for(const[i,s]of Object.entries(t.repeaterItemScopes))s.itemPath.startsWith(o)&&st(i,r)}if(_(n)){const o=pe(e);for(const i of n.children){const s=o.length>0?Re(i.uid,o):i.uid;if(t.resolvedSources[s]===void 0)continue;const c=r[s]?.hidden===!0;st(s,r),c||zt(s,t,r)}}}}function st(e,t){t[e]=t[e]||{},t[e].hidden=!0}function ct(e,t,r){const n=r.repeaterItemScopes[e];let o;D(t)?(o={...t({$form:r.data,$item:n?V(r.data,n.itemPath):void 0,$index:n?.index,errors:void 0,touched:void 0,translate:void 0})},o.uid=e):o=t;const i=r.repeaterRows[e];return i!==void 0&&(o=kr(o,i)),o}const Bt=(e,t)=>(r,n)=>{try{const o=n??fe(r);return{...r,calculatedWidgets:Nn(r,e,t,o)}}catch(o){const i=o,s=i.code??C.calculateWidgetPropsError;return{...r,formHealth:{status:"errored",message:`[${s}] ${i.message}`,code:s}}}};function Nn(e,t,r,{$formIsInvalid:n,$errors:o}){const i=to(e,t,n,o,r),s={};for(const c of Object.keys(e.calculatedWidgets)){if(e.widgetFlags[c]?.hidden)continue;const d=e.calculatedWidgets[c],a=d.source,f=e.repeaterItemScopes[c];if(D(a)){s[c]=Ln(d,c,a,e,t,f);continue}const h=f?{...i,$item:V(i.$form,f.itemPath),$index:f.index}:i;s[c]=_n(d,a,e,h)}return s}function Ln(e,t,r,n,o,i){const s={...r({$form:n.data,errors:r.path?n.validations[r.path]:void 0,touched:r.path?n.touchedControls[r.path]:void 0,translate:o.translate,$item:i?V(n.data,i.itemPath):void 0,$index:i?.index})};s.uid=t,r.path!==void 0&&(s.path=r.path);const c=n.widgetPropOverrides[t];return c!==void 0&&(s.props={...s.props,...c}),e.current&&ue(e.current,s)?e:{source:r,current:s}}function _n(e,t,r,n){const o=new eo(t,e.current);return o.write("uid",t.uid),o.write("type",t.type),o.write("kind",t.kind),tr(t)?Mn(o,n):te(t)?Un(o,n):I(t)?Hn(o,n):_(t)&&bn(o,n),zn(t,o,n,r),(te(t)||I(t))&&Bn(t,o,n),_(t)&&Gn(t,o,r),o.changed?{source:e.source,current:o.current}:e}function Mn(e,t){E(e,t,"size"),E(e,t,"include"),E(e,t,"exclude")}function Un(e,t){E(e,t,"size"),E(e,t,"include"),E(e,t,"exclude"),E(e,t,"label"),E(e,t,"disabled"),E(e,t,"actionType")}function Hn(e,t){E(e,t,"size"),E(e,t,"include"),E(e,t,"exclude"),E(e,t,"label"),E(e,t,"disabled"),E(e,t,"readonly"),E(e,t,"validator"),E(e,t,"path"),E(e,t,"defaultValue")}function bn(e,t){E(e,t,"size"),E(e,t,"include"),E(e,t,"exclude")}function zn(e,t,r,n){const o=n.widgetPropOverrides[e.uid]??{},i={...e.props??{},...o};for(const s of xt(Object.keys(i)))Kn(t,r,s)}function Bn(e,t,r){const n=e.on??{};for(const o of xt(Object.keys(n)))xn(t,r,o)}function Gn(e,t,r){const n=pe(e.uid),o=no(e.children,n,r.widgetFlags);t.current.children=o;const i=t.previous.children??[];i.length===o.length&&o.every((c,d)=>i[d]&&i[d].uid===o[d].uid)||t.markChanged()}function E(e,t,r){const n=e.source;if(!ro(n,r))return;const o=xe(n,r,t.sortedStates);let i;switch(r){case"disabled":case"readonly":i=Qn(o,t,e.source.uid,r);break;case"defaultValue":i=o;break;default:i=Kt(o,t)}e.write(r,i)}function Kn(e,t,r){const n=e.source.props,o=xe(n,r,t.sortedStates);let i=Kt(o,t);const s=t.widgetPropOverrides[e.source.uid]?.[r];s!==void 0&&(i=s),e.write(`props.${r}`,i)}function xn(e,t,r){const n=e.source.on,o=xe(n,r,t.sortedStates);e.write(`on.${r}`,Jn(o,t))}function Ke(e,t){return e({$form:t.$form,translate:t.localization.translate,$item:t.$item,$index:t.$index})}function Xn(e,t){return t.localization.translate(e.key,Yn(e.params,t),e.default)}const qn=/\{\{([^}]+)\}\}/g;function Gt(e,t){return e.includes("{{")?e.replace(qn,(r,n)=>{try{const o=Ge(n.trim())({$form:t.$form,$meta:t.$meta,$errors:t.$errors,$formIsInvalid:t.$formIsInvalid,$item:t.$item,$index:t.$index,$fn:t.$fn});return o==null?"":String(o)}catch(o){const i=o instanceof Error?o.message:String(o);throw new Xt(`Failed to evaluate '{{${n.trim()}}}': ${i}`)}}):e}function Kt(e,t){return typeof e=="function"?Ke(e,t):mr(e)?Xn(e,t):typeof e=="string"?Gt(e,t):e}function Qn(e,t,r,n){return typeof e=="function"?Ke(e,t):X(e)?t.widgetFlags[r]?.[n]:typeof e=="string"?Gt(e,t):e}function Jn(e,t){return typeof e=="function"?Ke(e,t):e}function xe(e,t,r){if(e){for(const n of r){const o=e[`${t}.${n}`];if(o!==void 0)return o}return e[t]}}function Zn(e){return e.startsWith("$form")||e.startsWith("$meta")||e.startsWith("$errors")||e.startsWith("$item")||e.startsWith("$index")||e.startsWith("$fn")||e==="$formIsInvalid"}function Yn(e,t){return e&&Object.keys(e).reduce((r,n)=>{const o=String(e[n]);if(Zn(o))try{const i=Ge(o)({$form:t.$form,$meta:t.$meta,$errors:t.$errors,$formIsInvalid:t.$formIsInvalid,$item:t.$item,$index:t.$index,$fn:t.$fn});r[n]=i??o}catch(i){const s=i instanceof Error?i.message:String(i);throw new Xt(`Failed to evaluate i18n param '${o}': ${s}`)}else r[n]=o;return r},{})}class eo{constructor(t,r){this._changed=!1,this.source=t,this.previous=r,this.current={}}get changed(){return this._changed}markChanged(){this._changed=!0}write(t,r){const n=V(this.previous,t);if(ue(n,r)){Ee(this.current,t,n);return}Ee(this.current,t,r),this._changed=!0}}function to(e,t,r,n,o){return{sortedStates:[...e.currentStates].sort((i,s)=>s.length-i.length),widgetPropOverrides:e.widgetPropOverrides,widgetFlags:e.widgetFlags,$form:e.data,$meta:e.meta,$formIsInvalid:r,$errors:n,localization:t,$fn:o}}function ro(e,t){if(t in e)return!0;const r=`${t}.`;return Object.keys(e).some(n=>n.startsWith(r))}function xt(e){return Array.from(new Set(e.map(t=>t.split(".")[0])))}function no(e,t,r){const n=t.map(o=>`[${o}]`).join("");return e.filter(o=>{const i=o.uid+n,s=r[i];return!s||s.hidden!==!0})}class Xt extends Error{constructor(){super(...arguments),this.code=C.resolveStringInterpolationError,this.name="StringInterpolationError"}}const oo=e=>{const t=io(e.resolvedSources),r=Y(e.widgetPropOverrides,s=>s in e.resolvedSources),n=Y(e.touchedControls,s=>t.has(s)),o=Y(e.validations,s=>t.has(s)),i=Y(e.injectedValidations,s=>t.has(s));return r===e.widgetPropOverrides&&n===e.touchedControls&&o===e.validations&&i===e.injectedValidations?e:{...e,widgetPropOverrides:r,touchedControls:n,validations:o,injectedValidations:i}};function io(e){const t=new Set;for(const r of Object.values(e)){const n=R(r);n!==void 0&&t.add(n)}return t}function Y(e,t){const r=Object.keys(e).filter(t);if(r.length===Object.keys(e).length)return e;const n={};for(const o of r)n[o]=e[o];return n}const so=e=>{const t=Object.keys(e.resolvedSources),r={};let n=t.length!==Object.keys(e.calculatedWidgets).length;for(const o of t){const i=e.calculatedWidgets[o];i?r[o]=i:(r[o]={source:e.resolvedSources[o],current:{}},n=!0)}return n?{...e,calculatedWidgets:r}:e},co=({lang:e},t)=>{const r={...mt(e),formName:t.payload.formName};let n=t.payload.formDef,o={status:"ok"};if(typeof n=="string"){try{n=JSON.parse(n)}catch(f){const h=f,y=C.initializeParseError;o={status:"errored",message:`[${y}] ${h.message}`,code:y}}if(o.status==="errored")return{...r,formHealth:o}}let i=n;if(Array.isArray(n.form)){const f=n.form;i={...n,form:{uid:"",type:"flex",kind:"layout",children:f}}}const s=ht.decode(i);if(s.isOk()){o={status:"ok"};let f={};try{f=Fe([s.value.form]).reduce((h,y)=>{const A=y.uid;if(h[A])throw{existingWidget:h[A],newWidget:y};return h[A]=y,h},{})}catch(h){o=ao(h.existingWidget,h.newWidget),f={}}return fo(f,s.value.states),{...r,formDef:s.value,flatForm:f,...Ce(f,{}),formHealth:o}}const c=lo(n);if(c)return{...r,formHealth:c};const d=C.initializeUnknownError,a=s.issues.map(f=>`${f.path.length>0?l.formatIssuePath(f.path):"root"}: ${f.message}`).join("; ");return{...r,formHealth:{status:"errored",message:`[${d}] ${a}`,code:d}}};function qt(e,t){return{status:"errored",code:e,message:`[${e}] ${t}`}}function uo(){return"Malformed form definition. Pass it directly as formDef - `config={{ formDef: { states, form: [...] } }}`. Do NOT wrap it in an extra `{ form: ... }`."}function lo(e){if(!e||typeof e!="object"||Array.isArray(e))return null;const t=e.form;return t&&typeof t=="object"&&!Array.isArray(t)&&!_(t)?qt(C.initializeMalformedFormShapeError,uo()):null}function ao(e,t){const r=o=>I(o)?` at "${o.path}"`:"",n=`Duplicate UID "${t.uid}": Assigned to widget "${e.type}"${r(e)} and "${t.type}"${r(t)}.`;return qt(C.initializeUidCollisionError,n)}function fo(e,t){const r=new Set(Object.keys(t??{})),n=new Map;for(const i of Object.values(e)){const s=[],c=i.include;c&&Array.isArray(c.in)&&s.push(...c.in);const d=i.exclude;d&&Array.isArray(d.from)&&s.push(...d.from);for(const a of s){if(r.has(a))continue;const f=n.get(a)??[];f.push(i.uid||"(unknown)"),n.set(a,f)}}if(n.size===0)return;const o=r.size?[...r].join(", "):"(none declared)";for(const[i,s]of n)console.error(`[GolemUI] include/exclude references undefined state "${i}" (on ${s.join(", ")}); these widgets will stay hidden. Declared states: ${o}. Fix: declare "${i}" in formConfig.states, or correct the name.`)}function po(e,t){const{path:r,issues:n}=t.payload,o=n?.length?{touched:!0,touchedControls:{...e.touchedControls,[r]:!0}}:{};return{...e,...o,injectedValidations:{...e.injectedValidations,[r]:n}}}const ho=(e,{payload:t})=>{const r="path"in t?go(e,t.path):mo(e,t.uid);if(r===void 0)return e;const n=e.widgetPropOverrides[r]||{};return{...e,widgetPropOverrides:{...e.widgetPropOverrides,[r]:{...n,[t.prop]:t.value}}}};function mo(e,t){if(t in e.resolvedSources)return t;console.warn(`Widget with uid "${t}" not found`)}function go(e,t){const r=Object.values(e.calculatedWidgets).find(({source:o,current:i})=>(R(i)??R(o))===t);if(r)return r.source.uid;const n=Object.keys(e.resolvedSources).find(o=>R(e.resolvedSources[o])===t);if(n!==void 0)return n;console.warn(`Input with path "${t}" not found`)}const yo=(e,t)=>({...e,data:{...t.payload.data}}),vo=(e,t)=>({...e,formHealth:t.payload.formHealth}),$o=(e,t)=>({...e,lang:t.payload.lang}),So=(e,t)=>({...e,meta:{...t.payload.meta}}),Ao=(e,t)=>({...e,data:yt(e.data,t.payload.path,t.payload.data)}),Qt=Symbol("filterMap.skip");function Eo(e,t){const r=[];for(let n=0;n<e.length;n++){const o=t(e[n],n,e);o!==Qt&&r.push(o)}return r}function wo(e,t,r){for(let n=0;n<e.length;n++)t(e[n],n,e)&&r(e[n],n,e)}function Co(e,t,r){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!r(e[n],t[n],n,e,t))return!1;return!0}const Io=(e,t)=>r=>{const n=Eo(Object.values(r.calculatedWidgets),({current:i})=>I(i)?i:Qt),o=r.validations;return{...r,validations:n.reduce((i,s)=>{if(i[s.path]=null,s.validator){const c=e(s.validator,t),d=V(r.data,s.path),a=at(c,d);i[s.path]=ft(a)?null:a.issues.map(f=>f.message)}return Array.isArray(i[s.path])&&Array.isArray(o[s.path])&&Co(i[s.path],o[s.path],(c,d)=>c===d)&&(i[s.path]=o[s.path]),i},{})}},Oo=({validators:e,validateOn:t,localization:r,functions:n})=>{const o=ko(r,n),i=Io(e,r),s=Bt(r,n),c=a=>dt(a,o,i,!1),d=a=>dt(a,o,i,!0);return(a,f)=>{switch(f.type){case"INITIALIZE":return co(a,f);case"SET_DATA":return c(yo(a,f));case"SET_META":return c(So(a,f));case"SET_WIDGET_DATA":return c(Ao(a,f));case"SET_LANGUAGE":return s($o(a,f));case"OVERRIDE_WIDGET_PROP":{const h=ho(a,f);if(h===a)return a;const y=c(h);return Ro(y,f)?i(y):y}case"SET_FORM_HEALTH":return vo(a,f);case"VALIDATE_ALL":return d(i(Wo(a)));case"ATTEMPT_VALIDATION":{if(!Fo(t,f.payload.reason))return a;const h={...a,touched:!0,touchedControls:{...a.touchedControls,[f.payload.path]:!0}};return d(i(h))}case"INJECT_VALIDATION_ISSUES":return po(a,f);default:return yr(f)}}},jo=new Set([C.calculateCurrentStateError,C.calculateWidgetFlagsError,C.calculateWidgetPropsError,C.resolveStringInterpolationError]),Po=e=>e.formHealth.status==="errored"&&!jo.has(e.formHealth.code);function ko(e,t){const r=Wn(t),n=Rn(t),o=Bt(e,t);return function(s){if(Po(s))return s;const c=d=>({...s,formHealth:d});try{let d=s.formHealth.status==="ok"?s:{...s,formHealth:{status:"ok"}};d=Wr(d),d=oo(d);const a=fe(d);return d=r(d,a),d.formHealth.status!=="ok"?c(d.formHealth):(d=n(d,a),d=so(d),d=o(d,a),d.formHealth.status==="ok"?d:c(d.formHealth))}catch(d){const a=C.calculateWidgetFlagsError;return c({status:"errored",code:a,message:`[${a}] ${d.message}`})}}}function dt(e,t,r,n){const o=f=>n?ut(f):f,i=e.resolvedSources,s=e.widgetFlags;let c=t(e);if(!c.allControlsValidated||c.formHealth.status!=="ok")return o(c);const d=Do(c,i,s);if(d.length===0)return o(c);const a={...c.touchedControls};for(const f of d)a[f]=!0;return c={...c,touchedControls:a},ut(t(r(c)))}function Do(e,t,r){const n=[];for(const[o,i]of Object.entries(e.resolvedSources)){const s=R(i);if(s===void 0||e.widgetFlags[o]?.hidden===!0||e.touchedControls[s]===!0)continue;const c=t[o]===void 0,d=r[o]?.hidden===!0;(c||d)&&n.push(s)}return n}function Wo(e){const t={};for(const{source:r,current:n}of Object.values(e.calculatedWidgets)){const o=R(n)??R(r);o!==void 0&&(t[o]=!0)}return{...e,touched:!0,allControlsValidated:!0,touchedControls:t}}function Fo(e,t){return e==="eager"||t===e||Array.isArray(e)&&e.includes(t)}function Ro(e,t){if(!e.touched)return!1;let r;if("path"in t.payload)r=t.payload.path;else{const n=e.calculatedWidgets[t.payload.uid]?.current;n&&I(n)&&(r=n.path)}return r!==void 0&&e.touchedControls[r]===!0}function ut(e){const t=Object.keys(e.injectedValidations),r=Object.keys(e.validations);if(t.length===0&&r.length===0)return{...e,isFormValid:!0};let n=t.find(o=>{const i=e.injectedValidations[o];return Array.isArray(i)&&i.length>0});return n!==void 0?{...e,isFormValid:!1}:(n=r.find(o=>{const i=e.validations[o];return Array.isArray(i)&&i.length>0}),n!==void 0?{...e,isFormValid:!1}:{...e,isFormValid:!0})}function To(e=[],t,r,n,o={}){const i=new k.BehaviorSubject(mt(n.lang)),s=i.asObservable().pipe(k.distinctUntilChanged()),c=Oo({validators:t,validateOn:r,localization:n,functions:o});function d(y){const A=i.getValue(),L=c(A,y);i.next(L)}let a=d;const f={getState:()=>i.getValue(),dispatch:y=>a(y)};return a=e.map(y=>y(f)).reduceRight((y,A)=>A(y),d),{state$:s,dispatch:a,getState:()=>i.getValue()}}class Vo{constructor(){this.widgetRegistry=new re,this.store={},this.events$=new k.Subject,this.submit$=new k.Subject,this.itemRenderers={},this.dependencies={}}initialize(t,r=[],n,o,i,s=gt(),c,d={}){this.localization=s,this.dependencies=c,this.widgetRegistry.setWidgetLoaders(t),this.itemRenderers=i,this.store=To(r,n,o,s,d)}emitEvent(t,r,n){const i=this.store.getState().currentStates.filter(s=>r.on?.[`${t}.${s}`]!==void 0);if(this.attemptValidation(t,r),i.length>0)i.forEach(s=>{const c=r.on?.[`${t}.${s}`];c&&this.events$.next({name:c,data:ye(this.store.getState()),detail:n??void 0,callback:d=>{this.store.dispatch(d)}})});else{const s=r.on?.[t];s&&this.events$.next({name:s,data:ye(this.store.getState()),detail:n,callback:c=>{this.store.dispatch(c)}})}}emitSubmitEvent(){this.store.dispatch({type:"VALIDATE_ALL"}),this.store.getState().isFormValid&&this.submit$.next({data:ye(this.store.getState()),callback:t=>{this.store.dispatch(t)}})}attemptValidation(t,r){r.kind!=="layout"&&(t==="change"?this.store.dispatch({type:"ATTEMPT_VALIDATION",payload:{reason:"change",path:r.path,uid:r.uid}}):t==="click"&&r.kind==="action"&&r.actionType==="submit"&&this.store.dispatch({type:"VALIDATE_ALL"}))}}function No(e="GolemUI Form Store"){return t=>{const n=(typeof window<"u"?window.__REDUX_DEVTOOLS_EXTENSION__:void 0)?.connect({name:e});return n?.init(t.getState()),o=>i=>{o(i),n&&n.send(i,t.getState())}}}const Lo=k.pipe(k.map(e=>e.formHealth),k.distinctUntilChanged((e,t)=>e.status!==t.status?!1:e.status==="errored"&&t.status==="errored"?e.message===t.message&&e.code===t.code:!0)),_o=e=>e.pipe(Lo);function Mo(e,t){return Yt(e,t,Zt(e,t),void 0)}function Jt(){const e=new Map;return(t,r)=>{const n=Zt(t,r),o=e.get(r);if(o&&zo(o.slices,n))return o.viewModel;const i=Yt(t,r,n,o);return e.set(r,{slices:n,viewModel:i}),i}}const Uo=e=>t=>{const r=Jt();return t.pipe(k.map(n=>r(n,e)),k.distinctUntilChanged())},Ho=[],lt=[],bo=[];function Zt(e,t){const r=Bo(e,t);return[e.calculatedWidgets[t],e.lang,r===void 0?void 0:V(e.data,r),r!==void 0&&e.touched?e.validations[r]:null,r!==void 0&&e.touched?e.injectedValidations[r]:null,r!==void 0&&e.touchedControls[r]===!0,e.touched&&!e.isFormValid,e.widgetFlags[t]?.hidden===!0]}function zo(e,t){return e.every((r,n)=>Object.is(r,t[n]))}function Yt(e,t,r,n){const[o,i,s,c,d,a,f,h]=r,y=n===void 0||!Object.is(n.slices[0],o),A=n===void 0||!Object.is(n.slices[2],s),L=n===void 0||!Object.is(n.slices[3],c)||!Object.is(n.slices[4],d),ge=o?.current;return{uid:t,widget:ge,children:y?Go(e,t,ge):n.viewModel.children,rows:y||A?Ko(e,t,ge,s):n.viewModel.rows,lang:i,value:s,errors:L?xo(c,d):n.viewModel.errors,touched:a,formInvalid:f,hidden:h}}function Bo(e,t){return e.resolvedSources[t]?.path}function Go(e,t,r){if(r===void 0||!_(r))return Ho;const n=r.children,o=pe(t);if(o.length===0)return n;const i=o.map(s=>`[${s}]`).join("");return n.map(s=>e.resolvedSources[`${s.uid}${i}`]??s)}function Ko(e,t,r,n){if(r===void 0||!Array.isArray(n))return lt;const o=e.resolvedSources[t];if(o===void 0||!G(o))return lt;const i=o.props.template.uid,s=pe(t);return n.map((c,d)=>{const a=Re(i,[...s,d]);return e.resolvedSources[a]}).filter(c=>c!==void 0)}function xo(e,t){return(e?.length??0)+(t?.length??0)===0?bo:[...e??[],...t??[]]}let er=!1;function Xo(){er=!0}function qo(){return er}function Qo(e,t,r){if(!qo())return;const n=Object.keys(t??{}).filter(o=>o in r);if(n.length>0)throw new Error(`[GolemUI] Widget "${e}": prop keys [${n.join(", ")}] collide with widget fields`)}const Jo=()=>crypto.randomUUID().slice(0,8);exports.FormContext=Vo;exports.assertNoPropCollisions=Qo;exports.cloneObject=B;exports.createWidgetViewModelReader=Jt;exports.defineForm=pr;exports.devToolsMiddleware=No;exports.enableDevMode=Xo;exports.errorCodes=C;exports.filterTap=wo;exports.formEventNames=hr;exports.formHealth=_o;exports.getDirectionFromLanguage=gr;exports.identityTranslator=gt;exports.isStandardValidateSuccess=ft;exports.makeRepeaterItemConfig=Er;exports.preloadFormWidgets=ar;exports.shortUUID=Jo;exports.standardValidate=at;exports.widgetViewModel=Mo;exports.widgetViewModel$=Uo;
|
package/lib/store/model.d.ts
CHANGED
|
@@ -74,6 +74,17 @@ export type State = {
|
|
|
74
74
|
* @example Nested repeater, keyed by the innermost item: { 'dev-name[2][0]': { itemPath: 'teams.2.devs.0', index: 0 } }
|
|
75
75
|
*/
|
|
76
76
|
repeaterItemScopes: Record<Uid, RepeaterItemScope>;
|
|
77
|
+
/**
|
|
78
|
+
* Maps every widget produced by a repeater item (by its concrete uid) to the rows that own it,
|
|
79
|
+
* outermost first. The flags stage uses it to rewrite `items` tokens in `when` expressions.
|
|
80
|
+
* Built by `expandSources` together with `resolvedSources`.
|
|
81
|
+
*
|
|
82
|
+
* @example Nested repeater: { 'dev-name[2][0]': [
|
|
83
|
+
* { declaredItemPath: 'teams.items', itemPath: 'teams.2', index: 2 },
|
|
84
|
+
* { declaredItemPath: 'teams.items.devs.items', itemPath: 'teams.2.devs.0', index: 0 },
|
|
85
|
+
* ] }
|
|
86
|
+
*/
|
|
87
|
+
repeaterRows: Record<Uid, RepeaterRow[]>;
|
|
77
88
|
/**
|
|
78
89
|
* Allows overriding a widget's `prop` properties externally via its event handler mechanism.
|
|
79
90
|
* For example, this can be used to load options for a select widget asynchronously.
|
|
@@ -125,6 +136,18 @@ export type RepeaterItemScope = {
|
|
|
125
136
|
/** Zero-based position of the owning item in the repeater array */
|
|
126
137
|
index: number;
|
|
127
138
|
};
|
|
139
|
+
/**
|
|
140
|
+
* One repeater row, as template paths write it and as the data holds it.
|
|
141
|
+
* Both paths have the same number of segments.
|
|
142
|
+
*/
|
|
143
|
+
export type RepeaterRow = {
|
|
144
|
+
/** The row path with its `items` token, as template paths write it, e.g. `teams.items.devs.items`. */
|
|
145
|
+
declaredItemPath: DotPath;
|
|
146
|
+
/** The same row with every index filled in, e.g. `teams.2.devs.1`. */
|
|
147
|
+
itemPath: DotPath;
|
|
148
|
+
/** Zero-based position of the row in its repeater array. */
|
|
149
|
+
index: number;
|
|
150
|
+
};
|
|
128
151
|
/**
|
|
129
152
|
* Represents the current operational state of the form.
|
|
130
153
|
* When in an errored state, the form is considered non-operational
|
package/lib/utils/repeater.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { FormWidget, InputWidget, LayoutWidget, NonFunctionWidget } from '../form-widget';
|
|
2
2
|
import { Uid } from '../shared';
|
|
3
|
-
import { RepeaterItemScope, State } from '../store/model';
|
|
3
|
+
import { RepeaterItemScope, RepeaterRow, State } from '../store/model';
|
|
4
4
|
/**
|
|
5
5
|
* A repeater input widget as the core reads it: an input with a layout template under `props.template`.
|
|
6
6
|
*/
|
|
@@ -14,11 +14,12 @@ export declare const isRepeaterWidget: (widget: FormWidget<string>) => widget is
|
|
|
14
14
|
/** `"abc[0][1]"` -> `[0, 1]`, `"abc"` -> `[]`. */
|
|
15
15
|
export declare const extractRepeaterIndexes: (uid: string) => number[];
|
|
16
16
|
/**
|
|
17
|
-
* The
|
|
17
|
+
* The three maps `expandSources` builds from the form and the data.
|
|
18
18
|
*/
|
|
19
19
|
export type ExpandedSources = {
|
|
20
20
|
resolvedSources: Record<Uid, FormWidget<string>>;
|
|
21
21
|
repeaterItemScopes: Record<Uid, RepeaterItemScope>;
|
|
22
|
+
repeaterRows: Record<Uid, RepeaterRow[]>;
|
|
22
23
|
};
|
|
23
24
|
/**
|
|
24
25
|
* Walks the flat form and the current data and returns every widget that exists for that data.
|
|
@@ -28,11 +29,12 @@ export type ExpandedSources = {
|
|
|
28
29
|
* Nested repeater containers are entries too and are recursed with their concrete path. Function widgets
|
|
29
30
|
* stay callable (see {@link makeRepeaterItemConfig}), `when` expressions are not rewritten here.
|
|
30
31
|
*
|
|
31
|
-
* `repeaterItemScopes` maps every row widget uid to the innermost item that owns it
|
|
32
|
+
* `repeaterItemScopes` maps every row widget uid to the innermost item that owns it, and
|
|
33
|
+
* `repeaterRows` to every row that owns it, outermost first.
|
|
32
34
|
*
|
|
33
35
|
* @param flatForm - The flattened form definition keyed by uid.
|
|
34
36
|
* @param data - The current form data the repeater arrays are read from.
|
|
35
|
-
* @returns
|
|
37
|
+
* @returns The maps, rebuilt from scratch.
|
|
36
38
|
*
|
|
37
39
|
* @example
|
|
38
40
|
* const { resolvedSources, repeaterItemScopes } = expandSources(flatForm, { users: [{}, {}] });
|
|
@@ -47,6 +49,10 @@ export declare function expandSources(flatForm: State['flatForm'], data: Record<
|
|
|
47
49
|
* Function widgets are wrapped in a new function that delegates to the original, so they stay callable while
|
|
48
50
|
* carrying the materialized `uid` and `path`.
|
|
49
51
|
*
|
|
52
|
+
* Every path segment named `items`, except the first, is a row token, filled in order. With indexes
|
|
53
|
+
* alone a property named `items` cannot be told apart from a token, so such a path throws.
|
|
54
|
+
* `expandSources` places rows by position and has no such limit.
|
|
55
|
+
*
|
|
50
56
|
* @param widget - The base widget config defined on the repeater template.
|
|
51
57
|
* @param repeaterIndexes - Ordered list of indexes for each nesting level
|
|
52
58
|
* e.g. `[2, 0]` for the first item of a nested repeater inside the third item of an outer repeater.
|
|
@@ -63,20 +69,22 @@ export declare function makeRepeaterItemConfig(widget: NonFunctionWidget<string>
|
|
|
63
69
|
export declare function makeRepeaterItemConfig(widget: FormWidget<string>, repeaterIndexes: number[]): FormWidget<string>;
|
|
64
70
|
export declare function toRepeaterItemUid(uid: Uid, repeaterIndexes: number[]): Uid;
|
|
65
71
|
/**
|
|
66
|
-
*
|
|
67
|
-
* concrete
|
|
68
|
-
*
|
|
72
|
+
* Rewrites the references to the widget's own rows in a `when` expression, so it can be evaluated
|
|
73
|
+
* for one concrete row. A reference is a row's full declared item path, with or without `$form.`
|
|
74
|
+
* in front. It becomes the concrete item path, and `?.` separators are kept. Any other `items`
|
|
75
|
+
* segment, such as `$item.items` or a property named `items`, stays.
|
|
69
76
|
*
|
|
70
|
-
* @
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
* // "$form.reptr.items?.active" -> "$form.reptr.2?.active"
|
|
77
|
+
* @param expression - The `when` expression as the template writes it.
|
|
78
|
+
* @param rows - The rows that own the widget, outermost first, see `State['repeaterRows']`.
|
|
79
|
+
* @returns The expression with every reference to those rows made concrete.
|
|
74
80
|
*
|
|
75
81
|
* @example
|
|
76
|
-
* //
|
|
77
|
-
* //
|
|
82
|
+
* // rows: [{ declaredItemPath: 'teams.items', itemPath: 'teams.1', index: 1 },
|
|
83
|
+
* // { declaredItemPath: 'teams.items.devs.items', itemPath: 'teams.1.devs.0', index: 0 }]
|
|
84
|
+
* transformRepeaterItemWhenExpression('$form.teams.items?.devs?.items?.name?.length > 0', rows);
|
|
85
|
+
* // '$form.teams.1?.devs?.0?.name?.length > 0'
|
|
78
86
|
*/
|
|
79
|
-
export declare function transformRepeaterItemWhenExpression(expression: string,
|
|
87
|
+
export declare function transformRepeaterItemWhenExpression(expression: string, rows: RepeaterRow[]): string;
|
|
80
88
|
/**
|
|
81
89
|
* Returns a copy of a repeater item widget whose reactive flag conditions
|
|
82
90
|
* (`include.when`, `exclude.when`, `disabled.when`, `readonly.when`) are rewritten
|
|
@@ -85,13 +93,13 @@ export declare function transformRepeaterItemWhenExpression(expression: string,
|
|
|
85
93
|
* State-based flags (`include.in`, `exclude.from`) carry no expression and are left untouched.
|
|
86
94
|
*
|
|
87
95
|
* @param widget - A widget already materialized for a repeater item (see {@link makeRepeaterItemConfig}).
|
|
88
|
-
* @param
|
|
96
|
+
* @param rows - The rows that own the widget, outermost first, see `State['repeaterRows']`.
|
|
89
97
|
* @returns A new widget config with item-concrete `when` expressions, or the input widget by
|
|
90
98
|
* reference when no flag field has a `when` expression. The original is never mutated.
|
|
91
99
|
*
|
|
92
100
|
* @example
|
|
93
|
-
* //
|
|
101
|
+
* // rows = [{ declaredItemPath: 'lineItems.items', itemPath: 'lineItems.1', index: 1 }]
|
|
94
102
|
* // { include: { when: '$form.lineItems.items.active' } }
|
|
95
103
|
* // -> { include: { when: '$form.lineItems.1.active' } }
|
|
96
104
|
*/
|
|
97
|
-
export declare function transformWidgetWhenExpressions(widget: NonFunctionWidget<string>,
|
|
105
|
+
export declare function transformWidgetWhenExpressions(widget: NonFunctionWidget<string>, rows: RepeaterRow[]): NonFunctionWidget<string>;
|