@golemui/core 1.5.0-rc.2 → 1.5.1-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 +18 -0
- package/index.js +959 -1147
- package/index.umd.cjs +8 -8
- package/package.json +1 -2
package/index.umd.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const T=require("rxjs");require("@standard-schema/spec");function Ct(e,t){const r=e["~standard"].validate(t);if(r instanceof Promise)throw new TypeError("Schema validation must be synchronous");return r}function It(e){return e.issues===void 0}var gr=class{value;constructor(e){this.value=e}map(e){return j(e(this.value))}isOk(){return!0}},yr=class jt{issues;constructor(t){this.issues=t}map(t){return new jt(this.issues)}isOk(){return!1}};function j(e){return new gr(e)}function w(e){return new yr(e)}function kt(e){return e.reduce((t,r)=>typeof r=="number"?`${t}[${r}]`:t.length===0?String(r):`${t}.${r}`,"")}function ut(e){return e.map(t=>t.path.length===0?t.message:`${kt(t.path)}: ${t.message}`).join("; ")}var C=class Pe{decodeFn;constructor(t){this.decodeFn=t}parse(t){let r=this.decode(t);if(r.isOk())return r.value;{let n=r;throw Error(ut(n.issues),{cause:n.issues})}}decode(t){return this.decodeFn(t)}"~standard"={version:1,vendor:"ts.data.json",validate:t=>{let r=this.decode(t);return r.isOk()?{value:r.value}:{issues:r.issues.map(n=>({message:n.message,path:n.path.length>0?n.path.map(o=>({key:o})):void 0}))}}};decodePromise(t){return new Promise((r,n)=>{let o=this.decode(t);if(o.isOk())return r(o.value);{let s=o;return n(Error(ut(s.issues),{cause:s.issues}))}})}map(t){return new Pe(r=>{let n=this.decodeFn(r);return n.isOk()?j(t(n.value)):w(n.issues)})}flatMap(t){return new Pe(r=>{let n=this.decodeFn(r);return n.isOk()?t(n.value).decode(r):w(n.issues)})}},z=(e,t)=>[{message:`${JSON.stringify(e)} is not a valid ${t}`,path:[]}],Me=(e,t)=>e.map(r=>({...r,path:[t,...r.path]}));function _e(e){return new C(t=>{if(t instanceof Array){let r=[],n=[];for(let o=0;o<t.length;o++){let s=e.decode(t[o]);s.isOk()?r.push(s.value):n.push(...Me(s.issues,o))}return n.length>0?w(n):j(r)}else return w(z(t,"array"))})}function vr(){return new C(e=>typeof e=="boolean"?j(e):w(z(e,"boolean")))}function $r(e,t){return new C(r=>{if(typeof r!="object"||!r)return w(z(r,"object"));let n=r[e];return Object.prototype.hasOwnProperty.call(t,n)?t[n].decode(r):w([{message:`"${e}" must be one of ${Object.keys(t).map(o=>JSON.stringify(o)).join(", ")}, but got ${JSON.stringify(n)}`,path:[e]}])})}function Ft(e){return new C(t=>e().decode(t))}function K(e){return new C(t=>t===e?j(e):w([{message:`${JSON.stringify(t)} is not exactly ${JSON.stringify(e)}`,path:[]}]))}function ve(){return new C(e=>typeof e=="number"?j(e):w(z(e,"number")))}function te(e){return new C(t=>{if(typeof t=="object"&&t){let r={},n=[];for(let o in e)if(Object.prototype.hasOwnProperty.call(e,o)){let s,i=e[o];s=i instanceof C?i.decode(t[o]):i.decoder.decode(t[i.fromKey]),s.isOk()?r[o]=s.value:n.push(...Me(s.issues,o))}return n.length>0?w(n):j(r)}else return w(z(t,"object"))})}function x(e){return new C(t=>{let r=[];for(let n=0;n<e.length;n++){let o=e[n].decode(t);if(o.isOk())return o;r.push(o.issues)}return w([{message:`no alternative matched (tried ${e.length})`,path:[]},...Sr(r)])})}function Sr(e){let t=new Map;for(let r of e)for(let n of r){let o=JSON.stringify(n.path),s=t.get(o);s?s.messages.includes(n.message)||s.messages.push(n.message):t.set(o,{path:n.path,messages:[n.message]})}return Array.from(t.values()).map(({path:r,messages:n})=>({message:n.join(" or "),path:r}))}function y(e){return new C(t=>t===void 0?j(void 0):e.decode(t))}function Ar(e){return new C(t=>{if(typeof t=="object"&&t){let r={},n=[];for(let o in t)if(Object.prototype.hasOwnProperty.call(t,o)){let s=e.decode(t[o]);s.isOk()?r[o]=s.value:n.push(...Me(s.issues,o))}return n.length>0?w(n):j(r)}else return w(z(t,"object"))})}function E(){return new C(e=>typeof e=="string"?j(e):w(z(e,"string")))}function b(){return new C(e=>j(e))}function re(e){return new C(t=>{if(typeof t!="object"||t===null)return w([{message:`Expected object literal, got "${typeof t}"`,path:[]}]);const r={};for(const[n,o]of Object.entries(e)){const s=o.decoder.decode(t[n]);if(!s.isOk())return w(s.issues.map(i=>({message:i.message,path:[n,...i.path]})));if(r[n]=s.value,o.suffixed){for(const[i,u]of Object.entries(t))if(i.startsWith(n+".")){const d=o.decoder.decode(u);if(!d.isOk())return w(d.issues.map(l=>({message:l.message,path:[i,...l.path]})));r[i]=d.value}}}return j(r)})}const wr=e=>typeof e!="function"&&e.kind==="display",de=e=>typeof e!="function"&&e.kind==="action",F=e=>typeof e!="function"&&e.kind==="input",H=e=>typeof e!="function"&&e.kind==="layout",N=e=>typeof e=="function",Er=te({in:_e(E())}),Ue=te({when:E()}),$e=x([Er,Ue]),Or=te({from:_e(E())}),Se=x([Or,Ue]),We=x([vr(),Ue]),Cr=new C(e=>{const t=typeof e;return t==="function"?j(e):w([{message:`Expected a function, got '${t}'`,path:[]}])}),V=e=>x([e,Cr]),be=re({load:{suffixed:!0,decoder:V(y(E()))},click:{suffixed:!0,decoder:V(y(E()))},change:{suffixed:!0,decoder:V(y(E()))},filter:{suffixed:!0,decoder:V(y(E()))},blur:{suffixed:!0,decoder:V(y(E()))}}),Ir=te({key:E(),default:y(E()),params:y(b())}),Pt=x([E(),Ir]),He=y(E()),jr=re({kind:{decoder:K("display")},uid:{decoder:He},type:{decoder:E()},size:{suffixed:!0,decoder:y(ve())},include:{decoder:y($e)},exclude:{decoder:y(Se)},props:{decoder:y(b())}}),kr=re({kind:{decoder:K("action")},uid:{decoder:He},type:{decoder:E()},actionType:{decoder:y(x([K("button"),K("submit")]))},size:{suffixed:!0,decoder:y(ve())},include:{decoder:y($e)},exclude:{decoder:y(Se)},label:{suffixed:!0,decoder:V(y(Pt))},disabled:{suffixed:!0,decoder:y(We)},on:{decoder:y(be)},props:{decoder:y(b())}}),Fr=new C(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,j(r)}else return w([{message:`Expected a function, got '${t}'`,path:[]}])}),Pr=re({kind:{decoder:K("input")},uid:{decoder:y(E())},type:{decoder:E()},size:{suffixed:!0,decoder:y(ve())},include:{decoder:y($e)},exclude:{decoder:y(Se)},disabled:{suffixed:!0,decoder:y(We)},readonly:{suffixed:!0,decoder:y(We)},on:{decoder:y(be)},props:{decoder:y(b())},label:{suffixed:!0,decoder:V(y(Pt))},path:{decoder:E()},defaultValue:{decoder:y(b())},validator:{suffixed:!0,decoder:V(y(b()))}}).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:ze.parse(r.template)}}return t}),Wr=Ft(()=>{const e=$r("kind",{input:Pr,layout:ze,display:jr,action:kr});return new C(t=>typeof t=="function"?Fr.decode(t):e.decode(t))}),ze=re({kind:{decoder:K("layout")},uid:{decoder:He},type:{decoder:E()},size:{suffixed:!0,decoder:y(ve())},include:{decoder:y($e)},exclude:{decoder:y(Se)},props:{decoder:y(b())},on:{decoder:y(be)},children:{decoder:_e(Wr)}}),D=class D{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(!D.sharedCache.has(r)){const n=r().catch(o=>(D.sharedCache.delete(r),Promise.reject(o)));D.sharedCache.set(r,n)}return D.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);D.resolvedCache.set(this.widgetLoaders[n],o)}))}getIfLoaded(t){const r=this.widgetLoaders[t];if(r)return D.resolvedCache.get(r)}};D.sharedCache=new Map,D.resolvedCache=new Map;let le=D;async function Dr(e){const t=new le;t.setWidgetLoaders(e.widgetLoaders),await t.preloadWidgets()}function Tr(e){De(e,"#0")}function De(e,t){if(N(e)){e.uid||(e.uid=`${t}.f`);return}if(e.uid||(e.uid=t),H(e)&&e.children.forEach((r,n)=>{De(r,`${t}.${n}`)}),F(e)&&e.type==="repeater"){const r=e.props?.template;r&&De(r,`${t}.t`)}}function Nr(e){return{...e,form:{uid:"",type:"flex",kind:"layout",children:e.form}}}const Wt=te({states:y(Ar(E())),form:Ft(()=>ze)}).map(e=>(Tr(e.form),e)),Dt=e=>({formName:"",formDef:Wt.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}),Vr={submit:"formSubmit",health:"formHealth",event:"formEvent"},Rr=e=>!(typeof e!="object"||e===null||typeof e.key!="string");function Lr(e){const t=new Intl.Locale(e).maximize().script;return["Arab","Hebr","Thaa","Syrc","Tfng","Adlm","Rohg"].includes(t||"")?"rtl":"ltr"}const Tt=(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))}}},k={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)}`)},_=(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)},_r=(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},Te=(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 i=0;i<n.length-1;i++){const u=n[i],d=n[i+1];(o[u]==null||typeof o[u]!="object")&&(o[u]=Vt(d)?[]:{}),o=o[u]}const s=n[n.length-1];return o[s]=r,e},Nt=(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=ct(e);let s=o;for(let i=0;i<n.length-1;i++){const u=n[i],d=n[i+1];s[u]==null||typeof s[u]!="object"?s[u]=Vt(d)?[]:{}:s[u]=ct(s[u]),s=s[u]}return s[n[n.length-1]]=r,o},ct=e=>Array.isArray(e)?e.slice():{...e},Ur=(e,t)=>{if(t==="")return e;const r=t.split("."),n=[e];for(let i=0;i<r.length-1;i++){const u=n[i];if(u==null||typeof u!="object")return e;const d=r[i],l=Array.isArray(u)?u[parseInt(d,10)]:u[d];if(l==null||typeof l!="object")return e;n.push(l)}const o=n[n.length-1],s=r[r.length-1];Array.isArray(o)?o.splice(parseInt(s,10),1):delete o[s];for(let i=n.length-1;i>=1;i--){const u=n[i];if(Array.isArray(u)||!br(u))break;const d=n[i-1],l=r[i-1];if(Array.isArray(d))break;delete d[l]}return e};function Vt(e){const t=Number(e);return Number.isInteger(t)&&t>=0&&t.toString()===e}function br(e){return e!=null&&typeof e=="object"&&!Array.isArray(e)&&Object.keys(e).length===0}function q(e){if(e===null||typeof e!="object")return e;if(Array.isArray(e))return e.map(r=>q(r));const t={};for(const r of Object.keys(e))t[r]=q(e[r]);return t}function Be(e){return e.flatMap(t=>[t,...H(t)?Be(t.children):[]])}function Ae(e){return Object.entries(e.validations).sort(([n],[o])=>n.split(".").length-o.split(".").length).reduce((n,[o,s])=>(s!==null&&(n.$formIsInvalid=!0,Te(n.$errors,o,[...s])),n),{$formIsInvalid:!1,$errors:{}})}function L(e){if(e!==void 0)return F(e)||N(e)?e.path:void 0}function je(e){const t=q(e.data);for(const[r,n]of Object.entries(e.widgetFlags))if(n.hidden===!0){const o=L(e.resolvedSources[r]);o!==void 0&&Ur(t,o)}return t}const we=e=>!N(e)&&e.type==="repeater",ne=e=>[...e.matchAll(/\[(\d+)\]/g)].map(t=>parseInt(t[1],10));function Ne(e,t){const r={resolvedSources:{},repeaterItemScopes:{}};for(const n of Object.values(e))r.resolvedSources[n.uid]=n,we(n)&&Rt(n,[],t,r);return r}function Rt(e,t,r,n){const o=_(r,e.path);if(!Array.isArray(o))return;const s=Be([e.props.template]);o.forEach((i,u)=>{const d=[...t,u],l={itemPath:`${e.path}.${u}`,index:u};for(const a of s){const p=Ge(a,d);n.resolvedSources[p.uid]=p,n.repeaterItemScopes[p.uid]=l;const g=Hr(a,p,d,r,i,u);g&&Rt(g,d,r,n)}})}function Hr(e,t,r,n,o,s){if(we(t))return t;if(!N(e))return;const i=e({$form:n,$item:o,$index:s,errors:void 0,touched:void 0,translate:void 0});if(i.type!=="repeater")return;const u={...i,uid:e.uid};return Ge(u,r)}function Ge(e,t){const r=Ke(e.uid,t);if(N(e)){const n=o=>e(o);return n.uid=r,n.type=e.type,e.path!==void 0&&(n.path=dt(e.path,t)),n}return F(e)?{...e,uid:r,path:dt(e.path,t)}:{...e,uid:r}}function Ke(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 dt(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((s,i,u)=>u===0?i:`${s}.${t[u-1]}${i}`)}function zr(e,t){let r=0;return e.replace(/\.items(\??)\./g,(n,o)=>{const s=t[r++];return s===void 0?n:`.${s}${o}.`})}const lt=["include","exclude","disabled","readonly"];function Br(e,t){if(!lt.some(o=>at(e[o])))return e;const n={...e};for(const o of lt){const s=n[o];at(s)&&(n[o]={...s,when:zr(s.when,t)})}return n}function at(e){return e!==null&&typeof e=="object"&&"when"in e&&typeof e.when=="string"}const Gr=50,Kr=e=>{let t=e.data,r=Ne(e.flatForm,t);for(let n=0;n<Gr;n++){let o=!1;for(const s of Object.values(r.resolvedSources))!F(s)||_r(t,s.path)||(t=Nt(t,s.path,q(s.defaultValue)),s.defaultValue!==void 0&&(o=!0));if(!o)break;r=Ne(e.flatForm,t)}return{...e,data:t,...r}},xe=32;let Ve,h,m,v=e=>(h=0,m=e,v.newline=!1,e=S(),m[h]?B():e||""),B=(e="Unexpected token",t=h,r=m.slice(0,t).split(`
|
|
2
|
-
`),n=r.pop(),o=
|
|
3
|
-
${
|
|
4
|
-
`,""+o}${
|
|
5
|
-
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},
|
|
6
|
-
`,"/*":"*/"};let
|
|
7
|
-
`)for(;
|
|
8
|
-
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},yt=()=>{const e=[];for(let t="",r;(r=m.charCodeAt(h))!==ge;)r?r===_n?(O(),t+=Un[m[h]]||m[h],O()):r===Ln&&m.charCodeAt(h+1)===Mn?(t&&e.push([,t]),t="",O(2),e.push(S(0,125))):(t+=m[h],O(),r=m.charCodeAt(h),r===ge&&t&&e.push([,t])):B("Unterminated template");return O(),e},bn=W[ge];W[ge]=(e,t)=>e&&t<Rn?v.asi&&v.newline?void 0:(O(),["``",e,...yt()]):e?bn?.(e,t):(O(),(r=>r.length<2&&r[0]?.[0]===void 0?r[0]||[,""]:["`",...r])(yt()));f("`",(...e)=>(e=e.map(c),t=>e.map(r=>r(t)).join("")));f("``",(e,...t)=>{e=c(e);const r=[],n=[];for(const s of t)Array.isArray(s)&&s[0]===void 0?r.push(s[1]):n.push(c(s));const o=Object.assign([...r],{raw:r});return s=>e(s)(o,...n.map(i=>i(s)))});v.string["'"]=!0;v.number={"0x":16,"0b":2,"0o":8};const Hn={log:(e,t)=>(t?console.log(t,e):console.log(e),e)},zn=2e3,ie=new Map;function ot(e){const t=ie.get(e);if(t!==void 0)return t;const r=c(v(Bn(e)));return ie.size>=zn&&ie.clear(),ie.set(e,r),r}function Q(e,t,r,n,o,s){return ot(e)({$form:t,$meta:r,$errors:n,$formIsInvalid:o,$log:Hn.log,$fn:{},...s})===!0}function Bn(e){return e.replace(/(\?\.|\.)(\d+)/g,(t,r,n,o)=>r==="."&&Gn(e,o)?t:r==="?."?`?.[${n}]`:`[${n}]`)}function Gn(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 Kn=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:s}=r??Ae(t);n=xn(n);let i=[],u={status:"ok"};try{i=Object.keys(n).map(d=>{const l=n[d];let a;try{a=Q(l,t.data,t.meta,s,o,{$fn:e})}catch{a=!1}return a===!0?d:void 0}).filter(d=>d!==void 0)}catch(d){const l=d,a=k.calculateCurrentStateError;u={status:"errored",message:`[${a}] ${l.message}`,code:a}}return{...t,currentStates:i,formHealth:u}};function xn(e){const t={};function r(n){const o=n.split(":"),s=[];for(let i=0;i<o.length;i++)s.push(o.slice(0,i+1).join(":"));return s}for(const[n,o]of Object.entries(e)){const s=r(n),i=[];for(const u of s)e[u]&&i.push(`(${e[u]})`);t[n]=i.join(" && ")}return t}const ee=e=>e!==void 0&&typeof e=="object"&&e!==null&&"when"in e;function vt(e){if(typeof e!="object"||e===null)return!1;const t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function ye(e,t){if(e===t)return!0;if(Array.isArray(e)&&Array.isArray(t))return e.length===t.length&&e.every((r,n)=>ye(r,t[n]));if(vt(e)&&vt(t)){const r=Object.keys(e);return r.length!==Object.keys(t).length?!1:r.every(n=>n in t&&ye(e[n],t[n]))}return!1}const Xn=e=>(t,r)=>{const{$formIsInvalid:n,$errors:o}=r??Ae(t);return{...t,widgetFlags:Jn(t,o,n,e)}};function Jn(e,t,r,n){const o=[];for(const[i,u]of Object.entries(e.resolvedSources))if(N(u)){const d=At(i,u,e);$t(d)&&o.push(d)}else $t(u)&&o.push(At(i,u,e));const s=o.reduce((i,u)=>{i[u.uid]=i[u.uid]||{};const d=e.repeaterItemScopes[u.uid],l=d?{$item:_(e.data,d.itemPath),$index:d.index,$fn:n}:{$fn:n};return u.include&&"in"in u.include?i[u.uid].hidden=!u.include.in.some(a=>e.currentStates.includes(a)):u.include&&"when"in u.include&&(i[u.uid].hidden=!Q(u.include.when,e.data,e.meta,t,r,l)),u.exclude&&"from"in u.exclude?i[u.uid].hidden=u.exclude.from.some(a=>e.currentStates.includes(a)):u.exclude&&"when"in u.exclude&&(i[u.uid].hidden=Q(u.exclude.when,e.data,e.meta,t,r,l)),(F(u)||de(u))&&ee(u.disabled)&&(i[u.uid].disabled=Q(u.disabled.when,e.data,e.meta,t,r,l)),F(u)&&ee(u.readonly)&&(i[u.uid].readonly=Q(u.readonly.when,e.data,e.meta,t,r,l)),i},{});return Qn(e,s),s}function $t(e){return!!(e.include&&("in"in e.include||"when"in e.include)||e.exclude&&("from"in e.exclude||"when"in e.exclude)||(F(e)||de(e))&&ee(e.disabled)||F(e)&&ee(e.readonly))}function Qn(e,t){const r=Object.keys(t).filter(n=>t[n].hidden===!0);for(const n of r)or(n,e,t)}function or(e,t,r){const n=t.resolvedSources[e];if(n!==void 0){if(we(n)||N(n)&&n.path!==void 0){const o=`${n.path}.`;for(const[s,i]of Object.entries(t.repeaterItemScopes))i.itemPath.startsWith(o)&&St(s,r)}if(H(n)){const o=ne(e);for(const s of n.children){const i=o.length>0?Ke(s.uid,o):s.uid;if(t.resolvedSources[i]===void 0)continue;const u=r[i]?.hidden===!0;St(i,r),u||or(i,t,r)}}}}function St(e,t){t[e]=t[e]||{},t[e].hidden=!0}function At(e,t,r){const n=r.repeaterItemScopes[e];let o;N(t)?(o={...t({$form:r.data,$item: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 s=ne(e);return s.length>0&&(o=Br(o,s)),o}const sr=(e,t)=>(r,n)=>{try{const o=n??Ae(r);return{...r,calculatedWidgets:qn(r,e,t,o)}}catch(o){const s=o,i=s.code??k.calculateWidgetPropsError;return{...r,formHealth:{status:"errored",message:`[${i}] ${s.message}`,code:i}}}};function qn(e,t,r,{$formIsInvalid:n,$errors:o}){const s=yo(e,t,n,o,r),i={};for(const u of Object.keys(e.calculatedWidgets)){if(e.widgetFlags[u]?.hidden)continue;const d=e.calculatedWidgets[u],l=d.source,a=e.repeaterItemScopes[u];if(N(l)){i[u]=Zn(d,u,l,e,t,a);continue}const p=a?{...s,$item:_(s.$form,a.itemPath),$index:a.index}:s;i[u]=Yn(d,l,e,p)}return i}function Zn(e,t,r,n,o,s){const i={...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:s?_(n.data,s.itemPath):void 0,$index:s?.index})};i.uid=t,r.path!==void 0&&(i.path=r.path);const u=n.widgetPropOverrides[t];return u!==void 0&&(i.props={...i.props,...u}),e.current&&ye(e.current,i)?e:{source:r,current:i}}function Yn(e,t,r,n){const o=new go(t,e.current);return o.write("uid",t.uid),o.write("type",t.type),o.write("kind",t.kind),wr(t)?eo(o,n):de(t)?to(o,n):F(t)?ro(o,n):H(t)&&no(o,n),oo(t,o,n,r),(de(t)||F(t))&&so(t,o,n),H(t)&&io(t,o,r),o.changed?{source:e.source,current:o.current}:e}function eo(e,t){A(e,t,"size"),A(e,t,"include"),A(e,t,"exclude")}function to(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 ro(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 no(e,t){A(e,t,"size"),A(e,t,"include"),A(e,t,"exclude")}function oo(e,t,r,n){const o=n.widgetPropOverrides[e.uid]??{},s={...e.props??{},...o};for(const i of cr(Object.keys(s)))uo(t,r,i)}function so(e,t,r){const n=e.on??{};for(const o of cr(Object.keys(n)))co(t,r,o)}function io(e,t,r){const n=ne(e.uid),o=$o(e.children,n,r.widgetFlags);t.current.children=o;const s=t.previous.children??[];s.length===o.length&&o.every((u,d)=>s[d]&&s[d].uid===o[d].uid)||t.markChanged()}function A(e,t,r){const n=e.source;if(!vo(n,r))return;const o=it(n,r,t.sortedStates);let s;switch(r){case"disabled":case"readonly":s=fo(o,t,e.source.uid,r);break;case"defaultValue":s=o;break;default:s=ur(o,t)}e.write(r,s)}function uo(e,t,r){const n=e.source.props,o=it(n,r,t.sortedStates);let s=ur(o,t);const i=t.widgetPropOverrides[e.source.uid]?.[r];i!==void 0&&(s=i),e.write(`props.${r}`,s)}function co(e,t,r){const n=e.source.on,o=it(n,r,t.sortedStates);e.write(`on.${r}`,po(o,t))}function st(e,t){return e({$form:t.$form,translate:t.localization.translate,$item:t.$item,$index:t.$index})}function lo(e,t){return t.localization.translate(e.key,mo(e.params,t),e.default)}const ao=/\{\{([^}]+)\}\}/g;function ir(e,t){return e.includes("{{")?e.replace(ao,(r,n)=>{try{const o=ot(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 s=o instanceof Error?o.message:String(o);throw new dr(`Failed to evaluate '{{${n.trim()}}}': ${s}`)}}):e}function ur(e,t){return typeof e=="function"?st(e,t):Rr(e)?lo(e,t):typeof e=="string"?ir(e,t):e}function fo(e,t,r,n){return typeof e=="function"?st(e,t):ee(e)?t.widgetFlags[r]?.[n]:typeof e=="string"?ir(e,t):e}function po(e,t){return typeof e=="function"?st(e,t):e}function it(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 ho(e){return e.startsWith("$form")||e.startsWith("$meta")||e.startsWith("$errors")||e.startsWith("$item")||e.startsWith("$index")||e.startsWith("$fn")||e==="$formIsInvalid"}function mo(e,t){return e&&Object.keys(e).reduce((r,n)=>{const o=String(e[n]);if(ho(o))try{const s=ot(o)({$form:t.$form,$meta:t.$meta,$errors:t.$errors,$formIsInvalid:t.$formIsInvalid,$item:t.$item,$index:t.$index,$fn:t.$fn});r[n]=s??o}catch(s){const i=s instanceof Error?s.message:String(s);throw new dr(`Failed to evaluate i18n param '${o}': ${i}`)}else r[n]=o;return r},{})}class go{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=_(this.previous,t);if(ye(n,r)){Te(this.current,t,n);return}Te(this.current,t,r),this._changed=!0}}function yo(e,t,r,n,o){return{sortedStates:[...e.currentStates].sort((s,i)=>i.length-s.length),widgetPropOverrides:e.widgetPropOverrides,widgetFlags:e.widgetFlags,$form:e.data,$meta:e.meta,$formIsInvalid:r,$errors:n,localization:t,$fn:o}}function vo(e,t){if(t in e)return!0;const r=`${t}.`;return Object.keys(e).some(n=>n.startsWith(r))}function cr(e){return Array.from(new Set(e.map(t=>t.split(".")[0])))}function $o(e,t,r){const n=t.map(o=>`[${o}]`).join("");return e.filter(o=>{const s=o.uid+n,i=r[s];return!i||i.hidden!==!0})}class dr extends Error{constructor(){super(...arguments),this.code=k.resolveStringInterpolationError,this.name="StringInterpolationError"}}const So=e=>{const t=Ao(e.resolvedSources),r=ue(e.widgetPropOverrides,i=>i in e.resolvedSources),n=ue(e.touchedControls,i=>t.has(i)),o=ue(e.validations,i=>t.has(i)),s=ue(e.injectedValidations,i=>t.has(i));return r===e.widgetPropOverrides&&n===e.touchedControls&&o===e.validations&&s===e.injectedValidations?e:{...e,widgetPropOverrides:r,touchedControls:n,validations:o,injectedValidations:s}};function Ao(e){const t=new Set;for(const r of Object.values(e)){const n=L(r);n!==void 0&&t.add(n)}return t}function ue(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 wo=e=>{const t=Object.keys(e.resolvedSources),r={};let n=t.length!==Object.keys(e.calculatedWidgets).length;for(const o of t){const s=e.calculatedWidgets[o];s?r[o]=s:(r[o]={source:e.resolvedSources[o],current:{}},n=!0)}return n?{...e,calculatedWidgets:r}:e},Eo=({lang:e},t)=>{const r={...Dt(e),formName:t.payload.formName};let n=t.payload.formDef,o={status:"ok"};if(typeof n=="string"){try{n=JSON.parse(n)}catch(a){const p=a,g=k.initializeParseError;o={status:"errored",message:`[${g}] ${p.message}`,code:g}}if(o.status==="errored")return{...r,formHealth:o}}let s=n;if(Array.isArray(n.form)){const a=n.form;s={...n,form:{uid:"",type:"flex",kind:"layout",children:a}}}const i=Wt.decode(s);if(i.isOk()){o={status:"ok"};let a={};try{a=Be([i.value.form]).reduce((p,g)=>{const I=g.uid;if(p[I])throw{existingWidget:p[I],newWidget:g};return p[I]=g,p},{})}catch(p){o=Io(p.existingWidget,p.newWidget),a={}}return jo(a,i.value.states),{...r,formDef:i.value,flatForm:a,...Ne(a,{}),formHealth:o}}const u=Co(n);if(u)return{...r,formHealth:u};const d=k.initializeUnknownError,l=i.issues.map(a=>`${a.path.length>0?kt(a.path):"root"}: ${a.message}`).join("; ");return{...r,formHealth:{status:"errored",message:`[${d}] ${l}`,code:d}}};function lr(e,t){return{status:"errored",code:e,message:`[${e}] ${t}`}}function Oo(){return"Malformed form definition. Pass it directly as formDef - `config={{ formDef: { states, form: [...] } }}`. Do NOT wrap it in an extra `{ form: ... }`."}function Co(e){if(!e||typeof e!="object"||Array.isArray(e))return null;const t=e.form;return t&&typeof t=="object"&&!Array.isArray(t)&&!H(t)?lr(k.initializeMalformedFormShapeError,Oo()):null}function Io(e,t){const r=o=>F(o)?` at "${o.path}"`:"",n=`Duplicate UID "${t.uid}": Assigned to widget "${e.type}"${r(e)} and "${t.type}"${r(t)}.`;return lr(k.initializeUidCollisionError,n)}function jo(e,t){const r=new Set(Object.keys(t??{})),n=new Map;for(const s of Object.values(e)){const i=[],u=s.include;u&&Array.isArray(u.in)&&i.push(...u.in);const d=s.exclude;d&&Array.isArray(d.from)&&i.push(...d.from);for(const l of i){if(r.has(l))continue;const a=n.get(l)??[];a.push(s.uid||"(unknown)"),n.set(l,a)}}if(n.size===0)return;const o=r.size?[...r].join(", "):"(none declared)";for(const[s,i]of n)console.error(`[GolemUI] include/exclude references undefined state "${s}" (on ${i.join(", ")}); these widgets will stay hidden. Declared states: ${o}. Fix: declare "${s}" in formConfig.states, or correct the name.`)}function ko(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 Fo=(e,{payload:t})=>{const r="path"in t?Wo(e,t.path):Po(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 Po(e,t){if(t in e.resolvedSources)return t;console.warn(`Widget with uid "${t}" not found`)}function Wo(e,t){const r=Object.values(e.calculatedWidgets).find(({source:o,current:s})=>(L(s)??L(o))===t);if(r)return r.source.uid;const n=Object.keys(e.resolvedSources).find(o=>L(e.resolvedSources[o])===t);if(n!==void 0)return n;console.warn(`Input with path "${t}" not found`)}const Do=(e,t)=>({...e,data:{...t.payload.data}}),To=(e,t)=>({...e,formHealth:t.payload.formHealth}),No=(e,t)=>({...e,lang:t.payload.lang}),Vo=(e,t)=>({...e,meta:{...t.payload.meta}}),Ro=(e,t)=>({...e,data:Nt(e.data,t.payload.path,t.payload.data)}),ar=Symbol("filterMap.skip");function Lo(e,t){const r=[];for(let n=0;n<e.length;n++){const o=t(e[n],n,e);o!==ar&&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 _o(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 Uo=(e,t)=>r=>{const n=Lo(Object.values(r.calculatedWidgets),({current:s})=>F(s)?s:ar),o=r.validations;return{...r,validations:n.reduce((s,i)=>{if(s[i.path]=null,i.validator){const u=e(i.validator,t),d=_(r.data,i.path),l=Ct(u,d);s[i.path]=It(l)?null:l.issues.map(a=>a.message)}return Array.isArray(s[i.path])&&Array.isArray(o[i.path])&&_o(s[i.path],o[i.path],(u,d)=>u===d)&&(s[i.path]=o[i.path]),s},{})}},bo=({validators:e,validateOn:t,localization:r,functions:n})=>{const o=Bo(r,n),s=Uo(e,r),i=sr(r,n),u=l=>wt(l,o,s,!1),d=l=>wt(l,o,s,!0);return(l,a)=>{switch(a.type){case"INITIALIZE":return Eo(l,a);case"SET_DATA":return u(Do(l,a));case"SET_META":return u(Vo(l,a));case"SET_WIDGET_DATA":return u(Ro(l,a));case"SET_LANGUAGE":return i(No(l,a));case"OVERRIDE_WIDGET_PROP":{const p=Fo(l,a);if(p===l)return l;const g=u(p);return Xo(g,a)?s(g):g}case"SET_FORM_HEALTH":return To(l,a);case"VALIDATE_ALL":return d(s(Ko(l)));case"ATTEMPT_VALIDATION":{if(!xo(t,a.payload.reason))return l;const p={...l,touched:!0,touchedControls:{...l.touchedControls,[a.payload.path]:!0}};return d(s(p))}case"INJECT_VALIDATION_ISSUES":return ko(l,a);default:return Mr(a)}}},Ho=new Set([k.calculateCurrentStateError,k.calculateWidgetFlagsError,k.calculateWidgetPropsError,k.resolveStringInterpolationError]),zo=e=>e.formHealth.status==="errored"&&!Ho.has(e.formHealth.code);function Bo(e,t){const r=Kn(t),n=Xn(t),o=sr(e,t);return function(i){if(zo(i))return i;const u=d=>({...i,formHealth:d});try{let d=i.formHealth.status==="ok"?i:{...i,formHealth:{status:"ok"}};d=Kr(d),d=So(d);const l=Ae(d);return d=r(d,l),d.formHealth.status!=="ok"?u(d.formHealth):(d=n(d,l),d=wo(d),d=o(d,l),d.formHealth.status==="ok"?d:u(d.formHealth))}catch(d){const l=k.calculateWidgetFlagsError;return u({status:"errored",code:l,message:`[${l}] ${d.message}`})}}}function wt(e,t,r,n){const o=a=>n?Et(a):a,s=e.resolvedSources,i=e.widgetFlags;let u=t(e);if(!u.allControlsValidated||u.formHealth.status!=="ok")return o(u);const d=Go(u,s,i);if(d.length===0)return o(u);const l={...u.touchedControls};for(const a of d)l[a]=!0;return u={...u,touchedControls:l},Et(t(r(u)))}function Go(e,t,r){const n=[];for(const[o,s]of Object.entries(e.resolvedSources)){const i=L(s);if(i===void 0||e.widgetFlags[o]?.hidden===!0||e.touchedControls[i]===!0)continue;const u=t[o]===void 0,d=r[o]?.hidden===!0;(u||d)&&n.push(i)}return n}function Ko(e){const t={};for(const{source:r,current:n}of Object.values(e.calculatedWidgets)){const o=L(n)??L(r);o!==void 0&&(t[o]=!0)}return{...e,touched:!0,allControlsValidated:!0,touchedControls:t}}function xo(e,t){return e==="eager"||t===e||Array.isArray(e)&&e.includes(t)}function Xo(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&&F(n)&&(r=n.path)}return r!==void 0&&e.touchedControls[r]===!0}function Et(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 s=e.injectedValidations[o];return Array.isArray(s)&&s.length>0});return n!==void 0?{...e,isFormValid:!1}:(n=r.find(o=>{const s=e.validations[o];return Array.isArray(s)&&s.length>0}),n!==void 0?{...e,isFormValid:!1}:{...e,isFormValid:!0})}function Jo(e=[],t,r,n,o={}){const s=new T.BehaviorSubject(Dt(n.lang)),i=s.asObservable().pipe(T.distinctUntilChanged()),u=bo({validators:t,validateOn:r,localization:n,functions:o});function d(g){const I=s.getValue(),Ce=u(I,g);s.next(Ce)}let l=d;const a={getState:()=>s.getValue(),dispatch:g=>l(g)};return l=e.map(g=>g(a)).reduceRight((g,I)=>I(g),d),{state$:i,dispatch:l,getState:()=>s.getValue()}}class Qo{constructor(){this.widgetRegistry=new le,this.store={},this.events$=new T.Subject,this.submit$=new T.Subject,this.itemRenderers={},this.dependencies={}}initialize(t,r=[],n,o,s,i=Tt(),u,d={}){this.localization=i,this.dependencies=u,this.widgetRegistry.setWidgetLoaders(t),this.itemRenderers=s,this.store=Jo(r,n,o,i,d)}emitEvent(t,r,n){const s=this.store.getState().currentStates.filter(i=>r.on?.[`${t}.${i}`]!==void 0);if(this.attemptValidation(t,r),s.length>0)s.forEach(i=>{const u=r.on?.[`${t}.${i}`];u&&this.events$.next({name:u,data:je(this.store.getState()),detail:n??void 0,callback:d=>{this.store.dispatch(d)}})});else{const i=r.on?.[t];i&&this.events$.next({name:i,data:je(this.store.getState()),detail:n,callback:u=>{this.store.dispatch(u)}})}}emitSubmitEvent(){this.store.dispatch({type:"VALIDATE_ALL"}),this.store.getState().isFormValid&&this.submit$.next({data:je(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 qo(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=>s=>{o(s),n&&n.send(s,t.getState())}}}const Zo=T.pipe(T.map(e=>e.formHealth),T.distinctUntilChanged((e,t)=>e.status!==t.status?!1:e.status==="errored"&&t.status==="errored"?e.message===t.message&&e.code===t.code:!0)),Yo=e=>e.pipe(Zo);function es(e,t){return hr(e,t,pr(e,t),void 0)}function fr(){const e=new Map;return(t,r)=>{const n=pr(t,r),o=e.get(r);if(o&&os(o.slices,n))return o.viewModel;const s=hr(t,r,n,o);return e.set(r,{slices:n,viewModel:s}),s}}const ts=e=>t=>{const r=fr();return t.pipe(T.map(n=>r(n,e)),T.distinctUntilChanged())},rs=[],Ot=[],ns=[];function pr(e,t){const r=ss(e,t);return[e.calculatedWidgets[t],e.lang,r===void 0?void 0:_(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 os(e,t){return e.every((r,n)=>Object.is(r,t[n]))}function hr(e,t,r,n){const[o,s,i,u,d,l,a,p]=r,g=n===void 0||!Object.is(n.slices[0],o),I=n===void 0||!Object.is(n.slices[2],i),Ce=n===void 0||!Object.is(n.slices[3],u)||!Object.is(n.slices[4],d),Ie=o?.current;return{uid:t,widget:Ie,children:g?is(e,t,Ie):n.viewModel.children,rows:g||I?us(e,t,Ie,i):n.viewModel.rows,lang:s,value:i,errors:Ce?cs(u,d):n.viewModel.errors,touched:l,formInvalid:a,hidden:p}}function ss(e,t){return e.resolvedSources[t]?.path}function is(e,t,r){if(r===void 0||!H(r))return rs;const n=r.children,o=ne(t);if(o.length===0)return n;const s=o.map(i=>`[${i}]`).join("");return n.map(i=>e.resolvedSources[`${i.uid}${s}`]??i)}function us(e,t,r,n){if(r===void 0||!Array.isArray(n))return Ot;const o=e.resolvedSources[t];if(o===void 0||!we(o))return Ot;const s=o.props.template.uid,i=ne(t);return n.map((u,d)=>{const l=Ke(s,[...i,d]);return e.resolvedSources[l]}).filter(u=>u!==void 0)}function cs(e,t){return(e?.length??0)+(t?.length??0)===0?ns:[...e??[],...t??[]]}let mr=!1;function ds(){mr=!0}function ls(){return mr}function as(e,t,r){if(!ls())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 fs=()=>crypto.randomUUID().slice(0,8);exports.FormContext=Qo;exports.assertNoPropCollisions=as;exports.cloneObject=q;exports.createWidgetViewModelReader=fr;exports.defineForm=Nr;exports.devToolsMiddleware=qo;exports.enableDevMode=ds;exports.errorCodes=k;exports.filterTap=Mo;exports.formEventNames=Vr;exports.formHealth=Yo;exports.getDirectionFromLanguage=Lr;exports.identityTranslator=Tt;exports.isStandardValidateSuccess=It;exports.makeRepeaterItemConfig=Ge;exports.preloadFormWidgets=Dr;exports.shortUUID=fs;exports.standardValidate=Ct;exports.widgetViewModel=es;exports.widgetViewModel$=ts;
|
|
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(`
|
|
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
|
+
${g[t-41]!==`
|
|
4
|
+
`,""+o}${s}${c}`)},St=(e,t=m)=>(Array.isArray(e)&&(e.loc=t),e),U=(e,t=m,r)=>{for(;r=e(g.charCodeAt(m));)m+=r;return g.slice(t,m)},E=(e=1)=>g[m+=e],Ie=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&&we&&v.asi?.(n,e,S)||null)??((i=j[r])&&i(n,e))??(n&&s&&v.asi?.(n,e,S))??(!n&&U(v.id)));)n=o;return t&&(r==t?(m++,t===125&&v.asi&&(v.newline=!0)):_("Unclosed "+String.fromCharCode(t-(t>42?2:1)))),n},V=(e,t=m)=>{for(we=!1;(e=g.charCodeAt(m))<=Ve;)v.asi&&e===10&&(v.newline=we=!0),m++;return e},wr=(e=m)=>{for(;g.charCodeAt(e)<=Ve;)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 Ir=(e,t=e.length)=>g.substr(m,t)===e&&!v.id(g.charCodeAt(m+t)),j=[],Ze={},O=(e,t=Ve,r,n=e.charCodeAt(0),o=e.length,i=j[n],s=e.toUpperCase()!==e,c,u)=>(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,(u=r(a))?St(u,y):(m=y,c=0,!s&&!i&&!a&&_()),u)||i?.(a,f,c))),$=(e,t,r=!1)=>O(e,t,n=>n&&(o=>o&&[e,n,o])(S(t-(r?.5:0)))),R=(e,t,r)=>O(e,t,n=>!n&&(n=S(t-.5))&&[e,n]),q=(e,t)=>O(e,200,r=>!r&&[,t]),At=(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)),Ne=(e,t)=>O(e[0],t,r=>!r&&[e,S(0,e.charCodeAt(1))||null]),Et=(e,t)=>O(e[0],t,r=>r&&[e,r,S(0,e.charCodeAt(1))||null]),Q=(e,t,r,n=e.charCodeAt(0),o=e.length,i=j[n],s)=>j[n]=(c,u,a,f=m)=>!c&&(a?e==a:(o<2||g.substr(m,o)==e)&&(a=e))&&u<t&&!v.id(g.charCodeAt(m+o))&&(!v.prop||v.prop(m+o))&&(Ie(m+o),(s=r())?St(s,f):Ie(f),s)||i?.(c,u,a);Object.defineProperty(v,"space",{configurable:!0,enumerable:!0,get:()=>V,set:e=>V=e});const Oe={},p=(e,t,r=Oe[e])=>Oe[e]=(...n)=>t(...n)||r?.(...n),d=e=>Array.isArray(e)?e[0]==null?(t=>()=>t)(e[1]):Oe[e[0]]?.(...e.slice(1))??_(`Unknown operator: ${e[0]}`,e?.loc):e===void 0?()=>{}:t=>t?.[e],re=46,B=48,ne=57,Or=69,jr=101,kr=43,Dr=45,Y=95,Ct=110,Wr=97,Pr=102,Fr=65,Tr=70,wt=e=>e.indexOf("_")<0?e:e.replaceAll("_",""),Re=e=>{let t=wt(U(r=>r===re&&g.charCodeAt(m+1)!==re||r>=B&&r<=ne||r===Y||((r===Or||r===jr)&&((r=g.charCodeAt(m+1))>=B&&r<=ne||r===kr||r===Dr)?2:0)));return g.charCodeAt(m)===Ct?(E(),[,BigInt(t)]):(e=+t)!=e?_():[,e]},Vr={2:e=>e===48||e===49||e===Y,8:e=>e>=48&&e<=55||e===Y,16:e=>e>=B&&e<=ne||e>=Wr&&e<=Pr||e>=Fr&&e<=Tr||e===Y};v.number=null;j[re]=e=>!e&&g.charCodeAt(m+1)!==re&&Re();for(let e=B;e<=ne;e++)j[e]=t=>t?void 0:Re();j[B]=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]){E(2);const o=wt(U(Vr[n]));return g.charCodeAt(m)===Ct?(E(),[,BigInt("0"+r[1]+o)]):[,parseInt(o,n)]}}return Re()};const Nr=92,Ye=34,et=39,Rr={n:`
|
|
5
|
+
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},It=e=>(t,r,n="")=>{if(!(t||!v.string?.[String.fromCharCode(e)]))return E(),U(o=>o-e&&(o===Nr?(n+=Rr[g[m+1]]||g[m+1],2):(n+=g[m],1))),g[m]===String.fromCharCode(e)?E():_("Bad string"),[,n]};j[Ye]=It(Ye);j[et]=It(et);v.string={'"':!0};const Lr=20;"= += -= *= /= %= |= &= ^= >>= <<=".split(" ").map(e=>$(e,Lr,!0));const Ot=(e,t,r,n)=>typeof e=="string"?o=>t(o,e,o):e[0]==="."?(r=d(e[1]),n=e[2],o=>t(r(o),n,o)):e[0]==="[]"&&e.length===3?(r=d(e[1]),n=d(e[2]),o=>t(r(o),n(o),o)):e[0]==="()"&&e.length===2?Ot(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=d(r),Ot(t,(n,o,i)=>tt[e](n,o,r(i)))));const _r=30,Mr=40,Ur=140;R("!",Ur);$("||",_r);$("&&",Mr);p("!",e=>(e=d(e),t=>!e(t)));p("||",(e,t)=>(e=d(e),t=d(t),r=>e(r)||t(r)));p("&&",(e,t)=>(e=d(e),t=d(t),r=>e(r)&&t(r)));const Hr=50,br=60,zr=70,jt=100,Br=140;$("|",Hr);$("&",zr);$("^",br);$(">>",jt);$("<<",jt);R("~",Br);p("~",e=>(e=d(e),t=>~e(t)));p("|",(e,t)=>(e=d(e),t=d(t),r=>e(r)|t(r)));p("&",(e,t)=>(e=d(e),t=d(t),r=>e(r)&t(r)));p("^",(e,t)=>(e=d(e),t=d(t),r=>e(r)^t(r)));p(">>",(e,t)=>(e=d(e),t=d(t),r=>e(r)>>t(r)));p("<<",(e,t)=>(e=d(e),t=d(t),r=>e(r)<<t(r)));const pe=90;$("<",pe);$(">",pe);$("<=",pe);$(">=",pe);p(">",(e,t)=>(e=d(e),t=d(t),r=>e(r)>t(r)));p("<",(e,t)=>(e=d(e),t=d(t),r=>e(r)<t(r)));p(">=",(e,t)=>(e=d(e),t=d(t),r=>e(r)>=t(r)));p("<=",(e,t)=>(e=d(e),t=d(t),r=>e(r)<=t(r)));const kt=80;$("==",kt);$("!=",kt);p("==",(e,t)=>(e=d(e),t=d(t),r=>e(r)==t(r)));p("!=",(e,t)=>(e=d(e),t=d(t),r=>e(r)!=t(r)));const Dt=110,Le=120,Wt=140;$("+",Dt);$("-",Dt);$("*",Le);$("/",Le);$("%",Le);R("+",Wt);R("-",Wt);p("+",(e,t)=>t!==void 0?(e=d(e),t=d(t),r=>e(r)+t(r)):(e=d(e),r=>+e(r)));p("-",(e,t)=>t!==void 0?(e=d(e),t=d(t),r=>e(r)-t(r)):(e=d(e),r=>-e(r)));p("*",(e,t)=>(e=d(e),t=d(t),r=>e(r)*t(r)));p("/",(e,t)=>(e=d(e),t=d(t),r=>e(r)/t(r)));p("%",(e,t)=>(e=d(e),t=d(t),r=>e(r)%t(r)));const oe=150;O("++",oe,e=>e?["++",e,null]:["++",S(oe-1)]);O("--",oe,e=>e?["--",e,null]:["--",S(oe-1)]);const _e=(e,t,r,n)=>typeof e=="string"?o=>t(o,e):e[0]==="."?(r=d(e[1]),n=e[2],o=>t(r(o),n)):e[0]==="[]"&&e.length===3?(r=d(e[1]),n=d(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 Gr=5,Kr=10;At(",",Kr);At(";",Gr,!0);const Pt=(...e)=>(e=e.map(d),t=>{let r;for(const n of e)r=n(t);return r});p(",",Pt);p(";",Pt);const xr=170;Ne("()",xr);const F=e=>e?.[0]==="_"&&e[1]==="_"||e==="constructor"||e==="prototype",Me=170;Et("[]",Me);$(".",Me);Et("()",Me);const ie=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=d(r[1]),n=>r(n)):(r=d(r),n=>[r(n)])),r=>e.flatMap(n=>n(r))):(t==null&&ie("Missing index"),e=d(e),t=d(t),r=>{const n=t(r);return F(n)?void 0:e(r)[n]}));p(".",(e,t)=>(e=d(e),t=t[0]?t:t[1],F(t)?()=>{}:r=>e(r)[t]));p("()",(e,t)=>{if(t===void 0)return e==null?ie("Empty ()"):d(e);const r=o=>o?.[0]===","&&o.slice(1).some(i=>i==null||r(i));r(t)&&ie("Empty argument");const n=t?t[0]===","?(t=t.slice(1).map(d),o=>t.map(i=>i(o))):(t=d(t),o=>[t(o)]):()=>[];return Ue(e,(o,i,s)=>o[i](...n(s)))});const M=e=>typeof e=="string"||Array.isArray(e)&&(e[0]==="."||e[0]==="?."||e[0]==="[]"&&e.length===3||e[0]==="?.[]"||e[0]==="()"&&e.length===2&&M(e[1])||e[0]==="{}"),Ue=(e,t,r,n)=>e==null?ie("Empty ()"):e[0]==="()"&&e.length==2?Ue(e[1],t):typeof e=="string"?o=>t(o,e,o):e[0]==="."?(r=d(e[1]),n=e[2],o=>t(r(o),n,o)):e[0]==="?."?(r=d(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=d(e[1]),n=d(e[2]),o=>t(r(o),n(o),o)):e[0]==="?.[]"?(r=d(e[1]),n=d(e[2]),o=>{const i=r(o);return i==null?void 0:t(i,n(o),o)}):(e=d(e),o=>t([e(o)],0,o)),H=Ue,Xr=32,qr=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=qr();){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)>=Xr;)n++;else{for(;g[n]&&g.substr(n,r[1].length)!==r[1];)n++;g[n]&&(n+=r[1].length)}Ie(n),e=0;break}if(e)return e}return e};const Ft=80;$("===",Ft);$("!==",Ft);p("===",(e,t)=>(e=d(e),t=d(t),r=>e(r)===t(r)));p("!==",(e,t)=>(e=d(e),t=d(t),r=>e(r)!==t(r)));const Qr=30;$("??",Qr);p("??",(e,t)=>(e=d(e),t=d(t),r=>e(r)??t(r)));const Jr=130,Zr=20;$("**",Jr,!0);$("**=",Zr,!0);p("**",(e,t)=>(e=d(e),t=d(t),r=>e(r)**t(r)));const Yr=e=>{throw Error(e)};p("**=",(e,t)=>(M(e)||Yr("Invalid assignment target"),t=d(t),H(e,(r,n,o)=>r[n]**=t(o))));const Tt=90;$("in",Tt);$("of",Tt);p("in",(e,t)=>(e=d(e),t=d(t),r=>e(r)in t(r)));const en=20,tn=100,rn=e=>{throw Error(e)};$(">>>",tn);$(">>>=",en,!0);p(">>>",(e,t)=>(e=d(e),t=d(t),r=>e(r)>>>t(r)));p(">>>=",(e,t)=>(M(e)||rn("Invalid assignment target"),t=d(t),H(e,(r,n,o)=>r[n]>>>=t(o))));const He=5,nn=10,on=20,sn=e=>e[0]?.[0]===","?e[0].slice(1):e,se=(e,t,r)=>{if(typeof e=="string"){r[e]=t;return}const[n,...o]=e,i=sn(o);if(n==="{}"){const s=[];for(const c of i){if(Array.isArray(c)&&c[0]==="..."){const y={};for(const C in t)s.includes(C)||(y[C]=t[C]);r[c[1]]=y;break}let u,a,f;typeof c=="string"?u=a=c:c[0]==="="?(typeof c[1]=="string"?u=a=c[1]:[,u,a]=c[1],f=c[2]):[,u,a]=c,s.push(u);let h=t[u];h===void 0&&f&&(h=d(f)(r)),se(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 u=c,a;Array.isArray(c)&&c[0]==="="&&([,u,a]=c);let f=t[s++];f===void 0&&a&&(f=d(a)(r)),se(u,f,r)}}},Vt=e=>{let t=S(nn-1);return t?.[0]==="in"||t?.[0]==="of"?[t[0],[e,t[1]],t[2]]:t?.[0]===","?[e,...t.slice(1)]:[e,t]};Q("let",He+1,()=>Vt("let"));Q("const",He+1,()=>Vt("const"));Q("var",He,()=>(V(),["var",S(on)]));const Nt=(...e)=>(e=e.map(t=>{if(typeof t=="string")return r=>{r[t]=void 0};if(t[0]==="="){const[,r,n]=t,o=d(n);return typeof r=="string"?i=>{i[r]=o(i)}:i=>se(r,o(i),i)}return d(t)}),t=>{for(const r of e)r(t)});p("let",Nt);p("const",Nt);p("var",e=>typeof e=="string"?t=>{t[e]=void 0}:()=>{});const be=20,he=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=d(t),typeof r=="string"?n=>{n[r]=t(n)}:n=>se(r,t(n),n)}return M(e)||he("Invalid assignment target"),t=d(t),H(e,(r,n,o)=>r[n]=t(o))});p("||=",(e,t)=>(M(e)||he("Invalid assignment target"),t=d(t),H(e,(r,n,o)=>r[n]||=t(o))));p("&&=",(e,t)=>(M(e)||he("Invalid assignment target"),t=d(t),H(e,(r,n,o)=>r[n]&&=t(o))));p("??=",(e,t)=>(M(e)||he("Invalid assignment target"),t=d(t),H(e,(r,n,o)=>r[n]??=t(o))));q("true",!0);q("false",!1);q("null",null);Q("undefined",200,()=>[]);q("NaN",NaN);q("Infinity",1/0);const $e=20;O("?",$e,(e,t,r)=>e&&(t=S($e-1))&&U(n=>n===58)&&(r=S($e-1),["?",e,t,r]));p("?",(e,t,r)=>(e=d(e),t=d(t),r=d(r),n=>e(n)?t(n):r(n)));const cn=[],dn=20;$("=>",dn,!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=d(s?["{",t[1]]:t),c=>(...u)=>{const a={};r.forEach((h,y)=>a[h]=u[y]),o&&(a[o]=u.slice(n));const f=new Proxy(a,{get:(h,y)=>y in h?h[y]:c?.[y],set:(h,y,C)=>((y in h?h:c)[y]=C,!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===cn)return h[0];throw h}}});const un=140;R("...",un);p("...",e=>(e=d(e),t=>Object.entries(e(t))));const rt=170;O("?.",rt,(e,t)=>{if(!e)return;const r=V();return r===40?(E(),["?.()",e,S(0,41)||null]):r===91?(E(),["?.[]",e,S(0,93)]):(t=S(rt),t?["?.",e,t]:void 0)});p("?.",(e,t)=>(e=d(e),F(t)?()=>{}:r=>e(r)?.[t]));p("?.[]",(e,t)=>(e=d(e),t=d(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(d),o=>t.map(i=>i(o))):(t=d(t),o=>[t(o)]):()=>[];if(e[0]==="?."){const o=d(e[1]),i=e[2];return F(i)?()=>{}:s=>o(s)?.[i]?.(...r(s))}if(e[0]==="?.[]"){const o=d(e[1]),i=d(e[2]);return s=>{const c=o(s),u=i(s);return F(u)?void 0:c?.[u]?.(...r(s))}}if(e[0]==="."){const o=d(e[1]),i=e[2];return F(i)?()=>{}:s=>o(s)?.[i]?.(...r(s))}if(e[0]==="[]"&&e.length===3){const o=d(e[1]),i=d(e[2]);return s=>{const c=o(s),u=i(s);return F(u)?void 0:c?.[u]?.(...r(s))}}const n=d(e);return o=>n(o)?.(...r(o))});const G=140;R("typeof",G);R("void",G);R("delete",G);Q("new",G,()=>Ir(".target")?(E(7),["new.target"]):["new",S(G)]);p("typeof",e=>(e=d(e),t=>typeof e(t)));p("void",e=>(e=d(e),t=>(e(t),void 0)));p("delete",e=>{if(e[0]==="."){const t=d(e[1]),r=e[2];return n=>delete t(n)[r]}if(e[0]==="[]"){const t=d(e[1]),r=d(e[2]);return n=>delete t(n)[r(n)]}return()=>!0});p("new",e=>{const t=d(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(d)):(o=>i=>[o(i)])(d(r)):()=>[];return o=>new(t(o))(...n(o))});const ze=Symbol("accessor"),Be=20,ln=40,Rt=41,Lt=123,_t=125,Mt=e=>t=>{if(t)return;V();const r=U(v.id);if(!r||(V(),g.charCodeAt(m)!==ln))return!1;E();const n=S(0,Rt);return V(),g.charCodeAt(m)!==Lt?!1:(E(),[e,r,n,S(0,_t)])};O("get",Be-1,Mt("get"));O("set",Be-1,Mt("set"));O("(",Be-1,e=>{if(!e||typeof e!="string")return;const t=S(0,Rt)||null;if(V(),g.charCodeAt(m)===Lt)return E(),[":",e,["=>",["()",t],S(0,_t)||null]]});p("get",(e,t)=>(t=t?d(t):()=>{},r=>[[ze,e,{get:function(){const n=Object.create(r||{});return n.this=this,t(n)}}]]));p("set",(e,t,r)=>(r=r?d(r):()=>{},n=>[[ze,e,{set:function(o){const i=Object.create(n||{});i.this=this,i[t]=o,r(i)}}]]));const an=20,Ut=200;v.prop=e=>wr(e)!==58;const fn=e=>e==null||typeof e=="string"||[":",",","...","get","set"].includes(e[0]);Ne("[]",Ut);Ne("{}",Ut);$(":",an-1,!0);p("{}",(e,t)=>{if(t!==void 0)return;if(!fn(e))return d(["{",e]);e=e?e[0]!==","?[e]:e.slice(1):[];const r=e.map(n=>d(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,u]=s;i[c]={...i[c],...u,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?d(e):()=>{},t=>e(Object.create(t))));p(":",(e,t)=>(t=d(t),Array.isArray(e)?(e=d(e),r=>[[e(r),t(r)]]):r=>[[e,t(r)]]));const pn=170,ce=96,hn=36,mn=123,gn=92,yn={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;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@golemui/core",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.1-rc.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -35,7 +35,6 @@
|
|
|
35
35
|
"ts.data.json": "^4.1.0"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
|
-
"subscript": "^10.1.8",
|
|
39
38
|
"rxjs": "^7.8.0",
|
|
40
39
|
"@standard-schema/spec": "^1.0.0"
|
|
41
40
|
},
|