@golemui/core 1.3.0-rc.0 → 1.4.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 +8 -0
- package/index.d.ts +3 -1
- package/index.js +1249 -1128
- package/index.umd.cjs +8 -8
- package/lib/context/form.context.d.ts +0 -1
- package/lib/errors.d.ts +2 -0
- package/lib/shared.d.ts +5 -0
- package/lib/store/actions.d.ts +1 -25
- package/lib/store/model.d.ts +21 -21
- package/lib/store/reducers/apply-default-values.d.ts +14 -0
- package/lib/store/reducers/calculate-current-state.d.ts +7 -1
- package/lib/store/reducers/calculate-widget-flags.d.ts +7 -1
- package/lib/store/reducers/calculate-widget-props.d.ts +7 -1
- package/lib/store/reducers/drop-removed-widget-entries.d.ts +13 -0
- package/lib/store/reducers/fill-calculated-widgets.d.ts +12 -0
- package/lib/store/reducers/index.d.ts +3 -3
- package/lib/store/reducers/override-widget-prop.d.ts +6 -0
- package/lib/store/reducers/set-widget-data.d.ts +2 -2
- package/lib/store/reducers/utils.d.ts +5 -27
- package/lib/store/selectors.d.ts +0 -22
- package/lib/store/view-model.d.ts +92 -0
- package/lib/utils/form.d.ts +19 -6
- package/lib/utils/justin.d.ts +10 -0
- package/lib/utils/object.d.ts +37 -18
- package/lib/utils/repeater.d.ts +43 -2
- package/package.json +1 -1
- package/lib/store/reducers/add-widget.d.ts +0 -3
- package/lib/store/reducers/materialize-repeater-items.d.ts +0 -10
- package/lib/store/reducers/remove-widget.d.ts +0 -3
- package/lib/utils/function.d.ts +0 -71
package/index.umd.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("rxjs");require("@standard-schema/spec");function mt(e,t){const r=e["~standard"].validate(t);if(r instanceof Promise)throw new TypeError("Schema validation must be synchronous");return r}function gt(e){return e.issues===void 0}var or=class{value;constructor(e){this.value=e}map(e){return T(e(this.value))}isOk(){return!0}},ir=class yt{issues;constructor(t){this.issues=t}map(t){return new yt(this.issues)}isOk(){return!1}};function T(e){return new or(e)}function C(e){return new ir(e)}function $t(e){return e.reduce((t,r)=>typeof r=="number"?`${t}[${r}]`:t.length===0?String(r):`${t}.${r}`,"")}function dt(e){return e.map(t=>t.path.length===0?t.message:`${$t(t.path)}: ${t.message}`).join("; ")}var D=class Te{decodeFn;constructor(t){this.decodeFn=t}parse(t){let r=this.decode(t);if(r.isOk())return r.value;{let n=r;throw Error(dt(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 i=o;return n(Error(dt(i.issues),{cause:i.issues}))}})}map(t){return new Te(r=>{let n=this.decodeFn(r);return n.isOk()?T(t(n.value)):C(n.issues)})}flatMap(t){return new Te(r=>{let n=this.decodeFn(r);return n.isOk()?t(n.value).decode(r):C(n.issues)})}},H=(e,t)=>[{message:`${JSON.stringify(e)} is not a valid ${t}`,path:[]}],Ve=(e,t)=>e.map(r=>({...r,path:[t,...r.path]}));function Le(e){return new D(t=>{if(t instanceof Array){let r=[],n=[];for(let o=0;o<t.length;o++){let i=e.decode(t[o]);i.isOk()?r.push(i.value):n.push(...Ve(i.issues,o))}return n.length>0?C(n):T(r)}else return C(H(t,"array"))})}function sr(){return new D(e=>typeof e=="boolean"?T(e):C(H(e,"boolean")))}function dr(e,t){return new D(r=>{if(typeof r!="object"||!r)return C(H(r,"object"));let n=r[e];return Object.prototype.hasOwnProperty.call(t,n)?t[n].decode(r):C([{message:`"${e}" must be one of ${Object.keys(t).map(o=>JSON.stringify(o)).join(", ")}, but got ${JSON.stringify(n)}`,path:[e]}])})}function At(e){return new D(t=>e().decode(t))}function X(e){return new D(t=>t===e?T(e):C([{message:`${JSON.stringify(t)} is not exactly ${JSON.stringify(e)}`,path:[]}]))}function $e(){return new D(e=>typeof e=="number"?T(e):C(H(e,"number")))}function oe(e){return new D(t=>{if(typeof t=="object"&&t){let r={},n=[];for(let o in e)if(Object.prototype.hasOwnProperty.call(e,o)){let i,s=e[o];i=s instanceof D?s.decode(t[o]):s.decoder.decode(t[s.fromKey]),i.isOk()?r[o]=i.value:n.push(...Ve(i.issues,o))}return n.length>0?C(n):T(r)}else return C(H(t,"object"))})}function J(e){return new D(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 C([{message:`no alternative matched (tried ${e.length})`,path:[]},...ur(r)])})}function ur(e){let t=new Map;for(let r of e)for(let n of r){let o=JSON.stringify(n.path),i=t.get(o);i?i.messages.includes(n.message)||i.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 $(e){return new D(t=>t===void 0?T(void 0):e.decode(t))}function cr(e){return new D(t=>{if(typeof t=="object"&&t){let r={},n=[];for(let o in t)if(Object.prototype.hasOwnProperty.call(t,o)){let i=e.decode(t[o]);i.isOk()?r[o]=i.value:n.push(...Ve(i.issues,o))}return n.length>0?C(n):T(r)}else return C(H(t,"object"))})}function I(){return new D(e=>typeof e=="string"?T(e):C(H(e,"string")))}function M(){return new D(e=>T(e))}function ie(e){return new D(t=>{if(typeof t!="object"||t===null)return C([{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 C(i.issues.map(s=>({message:s.message,path:[n,...s.path]})));if(r[n]=i.value,o.suffixed){for(const[s,d]of Object.entries(t))if(s.startsWith(n+".")){const c=o.decoder.decode(d);if(!c.isOk())return C(c.issues.map(l=>({message:l.message,path:[s,...l.path]})));r[s]=c.value}}}return T(r)})}const St=()=>crypto.randomUUID().slice(0,8),lr=e=>typeof e!="function"&&e.kind==="display",le=e=>typeof e!="function"&&e.kind==="action",W=e=>typeof e!="function"&&e.kind==="input",te=e=>typeof e!="function"&&e.kind==="layout",z=e=>typeof e=="function",ar=oe({in:Le(I())}),Re=oe({when:I()}),Ae=J([ar,Re]),fr=oe({from:Le(I())}),Se=J([fr,Re]),ke=J([sr(),Re]),pr=new D(e=>{const t=typeof e;return t==="function"?T(e):C([{message:`Expected a function, got '${t}'`,path:[]}])}),U=e=>J([e,pr]),Me=ie({load:{suffixed:!0,decoder:U($(I()))},click:{suffixed:!0,decoder:U($(I()))},change:{suffixed:!0,decoder:U($(I()))},filter:{suffixed:!0,decoder:U($(I()))},blur:{suffixed:!0,decoder:U($(I()))}}),hr=oe({key:I(),default:$(I()),params:$(M())}),vt=J([I(),hr]),Be=$(I()),mr=ie({kind:{decoder:X("display")},uid:{decoder:Be},type:{decoder:I()},size:{suffixed:!0,decoder:$($e())},include:{decoder:$(Ae)},exclude:{decoder:$(Se)},props:{decoder:$(M())}}),gr=ie({kind:{decoder:X("action")},uid:{decoder:Be},type:{decoder:I()},actionType:{decoder:$(J([X("button"),X("submit")]))},size:{suffixed:!0,decoder:$($e())},include:{decoder:$(Ae)},exclude:{decoder:$(Se)},label:{suffixed:!0,decoder:U($(vt))},disabled:{suffixed:!0,decoder:$(ke)},on:{decoder:$(Me)},props:{decoder:$(M())}}),yr=new D(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||St(),r.type=n.type,r.path=n.path,T(r)}else return C([{message:`Expected a function, got '${t}'`,path:[]}])}),$r=ie({kind:{decoder:X("input")},uid:{decoder:$(I())},type:{decoder:I()},size:{suffixed:!0,decoder:$($e())},include:{decoder:$(Ae)},exclude:{decoder:$(Se)},disabled:{suffixed:!0,decoder:$(ke)},readonly:{suffixed:!0,decoder:$(ke)},on:{decoder:$(Me)},props:{decoder:$(M())},label:{suffixed:!0,decoder:U($(vt))},path:{decoder:I()},defaultValue:{decoder:$(M())},validator:{suffixed:!0,decoder:U($(M()))}}).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:He.parse(r.template)}}return t}),Ar=At(()=>{const e=dr("kind",{input:$r,layout:He,display:mr,action:gr});return new D(t=>typeof t=="function"?yr.decode(t):e.decode(t))}),He=ie({kind:{decoder:X("layout")},uid:{decoder:Be},type:{decoder:I()},size:{suffixed:!0,decoder:$($e())},include:{decoder:$(Ae)},exclude:{decoder:$(Se)},props:{decoder:$(M())},on:{decoder:$(Me)},children:{decoder:Le(Ar)}}),R=class R{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(!R.sharedCache.has(r)){const n=r().catch(o=>(R.sharedCache.delete(r),Promise.reject(o)));R.sharedCache.set(r,n)}return R.sharedCache.get(r)}};R.sharedCache=new Map;let Fe=R;function Sr(e){je(e,"#0")}function je(e,t){if(!z(e)&&(e.uid||(e.uid=t),te(e)&&e.children.forEach((r,n)=>{je(r,`${t}.${n}`)}),W(e)&&e.type==="repeater")){const r=e.props?.template;r&&je(r,`${t}.t`)}}function vr(e){return{...e,form:{uid:"",type:"flex",kind:"layout",children:e.form}}}const Et=oe({states:$(cr(I())),form:At(()=>He)}).map(e=>(Sr(e.form),e)),Ct=e=>({formName:"",formDef:Et.parse({form:{kind:"layout",type:"flex",children:[]}}),flatForm:{},currentStates:[],calculatedWidgets:{},validations:{},touchedControls:{},injectedValidations:{},isFormValid:!0,widgetFlags:{},repeaterItemScopes:{},materializedRepeaterWidgets:{},widgetPropOverrides:{},data:{},meta:{},formHealth:{status:"ok"},touched:!1,allControlsValidated:!1,lang:e}),Er={submit:"formSubmit",health:"formHealth",event:"formEvent"},Cr=e=>!(typeof e!="object"||e===null||typeof e.key!="string");function Ir(e){const t=new Intl.Locale(e).maximize().script;return["Arab","Hebr","Thaa","Syrc","Tfng","Adlm","Rohg"].includes(t||"")?"rtl":"ltr"}const It=(e=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))}}},wr=e=>{throw new Error(`Unhandled case: ${JSON.stringify(e)}`)};function F(e,...t){return t.reduce((r,n)=>n(r),e)}const 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)},ze=(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 d=n[s],c=n[s+1];(o[d]==null||typeof o[d]!="object")&&(o[d]=Dr(c)?[]:{}),o=o[d]}const i=n[n.length-1];return o[i]=r,e},Or=(e,t)=>{if(t==="")return e;const r=t.split("."),n=[e];for(let s=0;s<r.length-1;s++){const d=n[s];if(d==null||typeof d!="object")return e;const c=r[s],l=Array.isArray(d)?d[parseInt(c,10)]:d[c];if(l==null||typeof l!="object")return e;n.push(l)}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 d=n[s];if(Array.isArray(d)||!Wr(d))break;const c=n[s-1],l=r[s-1];if(Array.isArray(c))break;delete c[l]}return e};function Dr(e){const t=Number(e);return Number.isInteger(t)&&t>=0&&t.toString()===e}function Wr(e){return e!=null&&typeof e=="object"&&!Array.isArray(e)&&Object.keys(e).length===0}const ve=(e,t)=>(delete e[t],e);function ae(e){if(e===null||typeof e!="object")return e;if(Array.isArray(e))return e.map(r=>ae(r));const t={};for(const r of Object.keys(e))t[r]=ae(e[r]);return t}function Tr(e,t){const r=t.payload.widget.uid;if(!r)throw new Error("addWidget: widget must have a uid");const n=t.payload.widget,o=e.allControlsValidated&&W(n)?{...e.touchedControls,[n.path]:!0}:e.touchedControls;return{...e,touchedControls:o,calculatedWidgets:{...e.calculatedWidgets,[r]:{source:n,current:{}}}}}const B={calculateCurrentStateError:10,initializeParseError:20,initializeUidCollisionError:21,initializeUnknownError:22,initializeMalformedFormShapeError:23,widgetCouldNotBeLoaded:30,resolveStringInterpolationError:40};function Ge(e){return e.flatMap(t=>[t,...te(t)?Ge(t.children):[]])}function be(e){return Object.entries(e.validations).reduce((r,[n,o])=>(o!==null&&(r.$formIsInvalid=!0,ze(r.$errors,n,[...o])),r),{$formIsInvalid:!1,$errors:{}})}function we(e){const t=ae(e.data);for(const[r,n]of Object.entries(e.widgetFlags))if(n.hidden===!0){const o=e.flatForm[r];o&&W(o)&&Or(t,o.path)}return t}const Ke=32;let Pe,h,y,A=e=>(h=0,y=e,A.newline=!1,e=v(),y[h]?G():e||""),G=(e="Unexpected token",t=h,r=y.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"},pt=()=>{const e=[];for(let t="",r;(r=y.charCodeAt(h))!==ye;)r?r===En?(w(),t+=Cn[y[h]]||y[h],w()):r===Sn&&y.charCodeAt(h+1)===vn?(t&&e.push([,t]),t="",w(2),e.push(v(0,125))):(t+=y[h],w(),r=y.charCodeAt(h),r===ye&&t&&e.push([,t])):G("Unterminated template");return w(),e},In=j[ye];j[ye]=(e,t)=>e&&t<An?A.asi&&A.newline?void 0:(w(),["``",e,...pt()]):e?In?.(e,t):(w(),(r=>r.length<2&&r[0]?.[0]===void 0?r[0]||[,""]:["`",...r])(pt()));a("`",(...e)=>(e=e.map(u),t=>e.map(r=>r(t)).join("")));a("``",(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)))});A.string["'"]=!0;A.number={"0x":16,"0b":2,"0o":8};const wn={log:(e,t)=>(t?console.log(t,e):console.log(e),e)};function Y(e,t,r,n,o,i){const s=A(nt(e));return u(s)({$form:t,$meta:r,$errors:n,$formIsInvalid:o,$log:wn.log,$fn:{},...i})===!0}function nt(e){return e.replace(/(\?\.|\.)(\d+)/g,(t,r,n,o)=>r==="."&&On(e,o)?t:r==="?."?`?.[${n}]`:`[${n}]`)}function On(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 Dn=e=>t=>{let r=t.formDef.states;if(!r||Object.keys(r).length===0||t.formHealth.status==="errored")return t;const{$formIsInvalid:n,$errors:o}=be(t);r=Wn(r);let i=[],s={status:"ok"};try{i=Object.keys(r).map(d=>{const c=r[d];let l;try{l=Y(c,t.data,t.meta,o,n,{$fn:e})}catch{l=!1}return l===!0?d:void 0}).filter(d=>d!==void 0)}catch(d){const c=d,l=B.calculateCurrentStateError;s={status:"errored",message:`[${l}] ${c.message}`,code:l}}return{...t,currentStates:i,formHealth:s}};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 d of i)e[d]&&s.push(`(${e[d]})`);t[n]=s.join(" && ")}return t}const q=(e,t)=>r=>e(r)?t(r):r,ee=e=>e!==void 0&&typeof e=="object"&&e!==null&&"when"in e,Tn=e=>t=>{const{$formIsInvalid:r,$errors:n}=be(t);return{...t,widgetFlags:kn(t,n,r,e)}};function kn(e,t,r,n){const o=Object.values(e.flatForm).map(s=>{if(z(s)){const d=s({$form:e.data,errors:void 0,touched:void 0,translate:void 0});return d.uid=s.uid,d}return s}),i=Object.values(e.materializedRepeaterWidgets);return[...o,...i].filter(s=>!!(s.include&&("in"in s.include||"when"in s.include)||s.exclude&&("from"in s.exclude||"when"in s.exclude)||(W(s)||le(s))&&ee(s.disabled)||W(s)&&ee(s.readonly))).reduce((s,d)=>{s[d.uid]=s[d.uid]||{};const c=e.repeaterItemScopes[d.uid],l=c?{$item:N(e.data,c.itemPath),$index:c.index,$fn:n}:{$fn:n};return d.include&&"in"in d.include?s[d.uid].hidden=!d.include.in.some(f=>e.currentStates.includes(f)):d.include&&"when"in d.include&&(s[d.uid].hidden=!Y(d.include.when,e.data,e.meta,t,r,l)),d.exclude&&"from"in d.exclude?s[d.uid].hidden=d.exclude.from.some(f=>e.currentStates.includes(f)):d.exclude&&"when"in d.exclude&&(s[d.uid].hidden=Y(d.exclude.when,e.data,e.meta,t,r,l)),(W(d)||le(d))&&ee(d.disabled)&&(s[d.uid].disabled=Y(d.disabled.when,e.data,e.meta,t,r,l)),W(d)&&ee(d.readonly)&&(s[d.uid].readonly=Y(d.readonly.when,e.data,e.meta,t,r,l)),s},{})}const Fn=(e,t)=>r=>{try{return{...r,calculatedWidgets:jn(r,e,t)}}catch(n){const o=n;return{...r,formHealth:{status:"errored",message:`[${o.code}] ${o.message}`,code:o.code}}}};function jn(e,t,r){const{$formIsInvalid:n,$errors:o}=be(e),i=qn(e,t,n,o,r),s={};for(const d of Object.keys(e.calculatedWidgets)){if(e.widgetFlags[d]?.hidden)continue;const c=e.calculatedWidgets[d],l=c.source,f=e.repeaterItemScopes[d];if(!f&&xt(d).length>0){s[d]=c;continue}if(z(l)){s[d]=Pn(d,l,e,t,f);continue}const g=f?{...i,$item:N(i.$form,f.itemPath),$index:f.index}:i;s[d]=Nn(c,l,e,g)}return s}function Pn(e,t,r,n,o){const i=t({$form:r.data,errors:t.path?r.validations[t.path]:void 0,touched:t.path?r.touchedControls[t.path]:void 0,translate:n.translate,$item:o?N(r.data,o.itemPath):void 0,$index:o?.index});return i.uid=e,{source:t,current:i}}function Nn(e,t,r,n){const o=new Qn(t,e.current);return o.write("uid",t.uid),o.write("type",t.type),o.write("kind",t.kind),lr(t)?Un(o,n):le(t)?_n(o,n):W(t)?Vn(o,n):te(t)&&Ln(o,n),Rn(t,o,n,r),(le(t)||W(t))&&Mn(t,o,n),te(t)&&Bn(t,o,r),o.changed?{source:e.source,current:o.current}:e}function Un(e,t){E(e,t,"size"),E(e,t,"include"),E(e,t,"exclude")}function _n(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 Vn(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 Ln(e,t){E(e,t,"size"),E(e,t,"include"),E(e,t,"exclude")}function Rn(e,t,r,n){const o=n.widgetPropOverrides[e.uid]??{},i={...e.props??{},...o};for(const s of Jt(Object.keys(i)))Hn(t,r,s)}function Mn(e,t,r){const n=e.on??{};for(const o of Jt(Object.keys(n)))zn(t,r,o)}function Bn(e,t,r){const n=xt(e.uid),o=Yn(e.children,n,r.widgetFlags);t.current.children=o;const i=t.previous.children??[];i.length===o.length&&o.every((d,c)=>i[c]&&i[c].uid===o[c].uid)||t.markChanged()}function E(e,t,r){const n=e.source;if(!Zn(n,r))return;const o=it(n,r,t.sortedStates);let i;switch(r){case"disabled":case"readonly":i=Kn(o,t,e.source.uid,r);break;case"defaultValue":i=o;break;default:i=Xt(o,t)}e.write(r,i)}function Hn(e,t,r){const n=e.source.props,o=it(n,r,t.sortedStates);let i=Xt(o,t);const s=t.widgetPropOverrides[e.source.uid]?.[r];s!==void 0&&(i=s),e.write(`props.${r}`,i)}function zn(e,t,r){const n=e.source.on,o=it(n,r,t.sortedStates);e.write(`on.${r}`,Xn(o,t))}function ot(e,t){return e({$form:t.$form,translate:t.localization.translate,$item:t.$item,$index:t.$index})}function Gn(e,t){return t.localization.translate(e.key,xn(e.params,t),e.default)}const bn=/\{\{([^}]+)\}\}/g;function Kt(e,t){return e.includes("{{")?e.replace(bn,(r,n)=>{const o=nt(n.trim());try{const i=u(A(o))({$form:t.$form,$meta:t.$meta,$errors:t.$errors,$formIsInvalid:t.$formIsInvalid,$item:t.$item,$index:t.$index,$fn:t.$fn});return i==null?"":String(i)}catch(i){const s=i instanceof Error?i.message:String(i);throw new Qt(`Failed to evaluate '{{${n.trim()}}}': ${s}`)}}):e}function Xt(e,t){return typeof e=="function"?ot(e,t):Cr(e)?Gn(e,t):typeof e=="string"?Kt(e,t):e}function Kn(e,t,r,n){return typeof e=="function"?ot(e,t):ee(e)?t.widgetFlags[r]?.[n]:typeof e=="string"?Kt(e,t):e}function Xn(e,t){return typeof e=="function"?ot(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 Jn(e){return e.startsWith("$form")||e.startsWith("$meta")||e.startsWith("$errors")||e.startsWith("$item")||e.startsWith("$index")||e.startsWith("$fn")||e==="$formIsInvalid"}function xn(e,t){return e&&Object.keys(e).reduce((r,n)=>{const o=String(e[n]);if(Jn(o))try{const i=u(A(nt(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 Qt(`Failed to evaluate i18n param '${o}': ${s}`)}else r[n]=o;return r},{})}class Qn{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){ze(this.current,t,r),N(this.previous,t)!==r&&(this._changed=!0)}}function qn(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 Zn(e,t){if(t in e)return!0;const r=`${t}.`;return Object.keys(e).some(n=>n.startsWith(r))}function Jt(e){return Array.from(new Set(e.map(t=>t.split(".")[0])))}function Yn(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})}const xt=e=>[...e.matchAll(/\[(\d+)\]/g)].map(t=>parseInt(t[1],10));class Qt extends Error{constructor(){super(...arguments),this.code=B.resolveStringInterpolationError,this.name="StringInterpolationError"}}const eo=({lang:e},t)=>{const r={...Ct(e),formName:t.payload.formName};let n=t.payload.formDef,o={status:"ok"};if(typeof n=="string"){try{n=JSON.parse(n)}catch(l){const f=l,g=B.initializeParseError;o={status:"errored",message:`[${g}] ${f.message}`,code:g}}if(o.status==="errored")return{...r,formHealth:o}}if(Array.isArray(n.form)){const l=n,f=l.form;l.form={uid:"",type:"flex",kind:"layout",children:f}}const i=Et.decode(n);if(i.isOk()){o={status:"ok"};let l={};try{l=Ge([i.value.form]).reduce((f,g)=>{const m=g.uid;if(f[m])throw{existingWidget:f[m],newWidget:g};return f[m]=g,f},{})}catch(f){o=no(f.existingWidget,f.newWidget),l={}}return oo(l,i.value.states),{...r,formDef:i.value,flatForm:l,formHealth:o}}const s=ro(n);if(s)return{...r,formHealth:s};const d=B.initializeUnknownError,c=i.issues.map(l=>`${l.path.length>0?$t(l.path):"root"}: ${l.message}`).join("; ");return{...r,formHealth:{status:"errored",message:`[${d}] ${c}`,code:d}}};function qt(e,t){return{status:"errored",code:e,message:`[${e}] ${t}`}}function to(){return"Malformed form definition. Pass it directly as formDef - `config={{ formDef: { states, form: [...] } }}`. Do NOT wrap it in an extra `{ form: ... }`."}function ro(e){if(!e||typeof e!="object"||Array.isArray(e))return null;const t=e.form;return t&&typeof t=="object"&&!Array.isArray(t)&&!te(t)?qt(B.initializeMalformedFormShapeError,to()):null}function no(e,t){const r=o=>W(o)?` at "${o.path}"`:"",n=`Duplicate UID "${t.uid}": Assigned to widget "${e.type}"${r(e)} and "${t.type}"${r(t)}.`;return qt(B.initializeUidCollisionError,n)}function oo(e,t){const r=new Set(Object.keys(t??{})),n=new Map;for(const i of Object.values(e)){const s=[],d=i.include;d&&Array.isArray(d.in)&&s.push(...d.in);const c=i.exclude;c&&Array.isArray(c.from)&&s.push(...c.from);for(const l of s){if(r.has(l))continue;const f=n.get(l)??[];f.push(i.uid||"(unknown)"),n.set(l,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 io(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}}}function _e(e,t){const r=Zt(e.uid,t);if(z(e)){const n=o=>e(o);return n.uid=r,n.type=e.type,e.path!==void 0&&(n.path=ht(e.path,t)),n}return W(e)?{...e,uid:r,path:ht(e.path,t)}:{...e,uid:r}}function Zt(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 ht(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,d)=>d===0?s:`${i}.${t[d-1]}${s}`)}function so(e,t){let r=0;return e.replace(/\.items(\??)\./g,(n,o)=>{const i=t[r++];return i===void 0?n:`.${i}${o}.`})}const uo=["include","exclude","disabled","readonly"];function co(e,t){const r={...e};for(const n of uo){const o=r[n];lo(o)&&(r[n]={...o,when:so(o.when,t)})}return r}function lo(e){return e!==null&&typeof e=="object"&&"when"in e&&typeof e.when=="string"}const P=e=>{const t={},r={},n=Object.values(e.flatForm).filter(o=>!z(o)&&o.type==="repeater");for(const o of n)Yt(e,o,[],t,r);return{...e,repeaterItemScopes:t,materializedRepeaterWidgets:r}};function Yt(e,t,r,n,o){const i=t.props.template,s=N(e.data,t.path);Array.isArray(s)&&s.forEach((d,c)=>{const l=[...r,c],f={itemPath:`${t.path}.${c}`,index:c};Ge([i]).forEach(g=>{let m;if(z(g)?(m=g({$form:e.data,$item:d,$index:c,errors:void 0,touched:void 0,translate:void 0}),m.uid=g.uid):m=g,m.type==="repeater"){const K=_e(m,l);n[Zt(m.uid,l)]=f,Yt(e,K,l,n,o);return}const O=co(_e(m,l),l);n[O.uid]=f,o[O.uid]=O})})}const ao=(e,{payload:t})=>{let r;if("path"in t){if(r=Object.values(e.calculatedWidgets).find(({source:i})=>W(i)&&i.path===t.path),!r)return console.warn(`Input with path "${t.path}" not found`),e}else if(r=e.calculatedWidgets[t.uid],!r)return console.warn(`Widget with uid "${t.uid}" not found`),e;const n=r.source.uid,o=e.widgetPropOverrides[n]||{};return{...e,widgetPropOverrides:{...e.widgetPropOverrides,[n]:{...o,[t.prop]:t.value}}}};function fo(e,t){return F(e,po(t),ho(t),mo(t),go(t))}const po=e=>t=>({...t,widgetFlags:{...ve(t.widgetFlags,e.payload.uid)}}),ho=e=>t=>({...t,calculatedWidgets:{...ve(t.calculatedWidgets,e.payload.uid)}}),mo=e=>t=>({...t,widgetPropOverrides:{...ve(t.widgetPropOverrides,e.payload.uid)}}),go=e=>t=>({...t,touchedControls:F(t.touchedControls,r=>{const n=t.flatForm[e.payload.uid];return n&&W(n)?ve(r,n.path):r})}),yo=(e,t)=>({...e,data:{...t.payload.data}}),$o=(e,t)=>({...e,formHealth:t.payload.formHealth}),Ao=(e,t)=>({...e,lang:t.payload.lang}),So=(e,t)=>({...e,meta:{...t.payload.meta}}),vo=(e,t)=>{const r=N(e.data,t.payload.path);return t.type==="SET_WIDGET_DATA"||t.type==="SET_WIDGET_INITIAL_DATA"&&r===void 0?{...e,data:{...ze(e.data,t.payload.path,t.payload.data)}}:e},er=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!==er&&r.push(o)}return r}function Co(e,t,r){for(let n=0;n<e.length;n++)t(e[n],n,e)&&r(e[n],n,e)}function Io(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 ue=(e,t)=>r=>{const n=Eo(Object.values(r.calculatedWidgets),({current:i})=>W(i)?i:er),o=r.validations;return{...r,validations:n.reduce((i,s)=>{if(i[s.path]=null,s.validator){const d=e(s.validator,t),c=N(r.data,s.path),l=mt(d,c);i[s.path]=gt(l)?null:l.issues.map(f=>f.message)}return Array.isArray(i[s.path])&&Array.isArray(o[s.path])&&Io(i[s.path],o[s.path],(d,c)=>d===c)&&(i[s.path]=o[s.path]),i},{})}},wo=({validators:e,validateOn:t,localization:r,functions:n})=>{const o=Dn(n),i=Tn(n),s=Fn(r,n);return(d,c)=>{switch(c.type){case"INITIALIZE":return eo(d,c);case"SET_DATA":return F(yo(d,c),o,P,i,s);case"SET_META":return F(So(d,c),o,P,i,s);case"SET_LANGUAGE":return F(Ao(d,c),s);case"ADD_WIDGET":{const l=F(Tr(d,c),q(Z,o),q(Z,P),q(Z,i),q(Z,s));return Z(l)&&l.allControlsValidated?F(l,ue(e,r),o,P,i,s,We):l}case"REMOVE_WIDGET":return F(fo(d,c),o,P,i,s);case"SET_WIDGET_INITIAL_DATA":case"SET_WIDGET_DATA":return F(vo(d,c),o,P,i,s);case"OVERRIDE_WIDGET_PROP":return F(ao(d,c),o,P,i,s,q(l=>{let f=!1,g="";"path"in c.payload?(f=!0,g=c.payload.path):W(l.calculatedWidgets[c.payload.uid].current)&&(f=!0,g=l.calculatedWidgets[c.payload.uid].current.path);const m=f&&l.touchedControls[g];return l.touched&&m},ue(e,r)));case"SET_FORM_HEALTH":return $o(d,c);case"VALIDATE_ALL":return F({...d,touched:!0,allControlsValidated:!0,touchedControls:Object.keys(d.calculatedWidgets).reduce((l,f)=>{const g=d.calculatedWidgets[f].source;return W(g)&&(l[g.path]=!0),l},{})},ue(e,r),o,P,i,s,We);case"ATTEMPT_VALIDATION":{const l=c.payload.reason,f=c.payload.path;return t==="eager"||l===t||t.includes(l)?F({...d,touched:!0,touchedControls:{...d.touchedControls,[f]:!0}},ue(e,r),o,P,i,s,m=>{const O=c.payload.uid,K=m.calculatedWidgets[O],st=K.source;if(z(st)){const Ie=m.repeaterItemScopes[O],nr=st({$form:m.data,errors:m.validations[f],touched:!0,translate:r.translate,$item:Ie?N(m.data,Ie.itemPath):void 0,$index:Ie?.index});return{...m,calculatedWidgets:{...m.calculatedWidgets,[O]:{source:K.source,current:nr}}}}return m},We):d}case"INJECT_VALIDATION_ISSUES":return io(d,c);default:return wr(c)}}},Z=e=>e.formHealth.status==="ok";function We(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=>e.injectedValidations[o]!==null&&Array.isArray(e.injectedValidations[o]));return n!==void 0?{...e,isFormValid:!1}:(n=r.find(o=>e.validations[o]!==null&&Array.isArray(e.validations[o])),n!==void 0?{...e,isFormValid:!1}:{...e,isFormValid:!0})}function Oo(e=[],t,r,n,o={}){const i=new p.BehaviorSubject(Ct(n.lang)),s=i.asObservable().pipe(p.distinctUntilChanged()),d=wo({validators:t,validateOn:r,localization:n,functions:o});function c(m){const O=i.getValue(),K=d(O,m);i.next(K)}let l=c;const f={getState:()=>i.getValue(),dispatch:m=>l(m)};return l=e.map(m=>m(f)).reduceRight((m,O)=>O(m),c),{state$:s,dispatch:l,getState:()=>i.getValue()}}class Do{constructor(){this.widgetRegistry=new Fe,this.store={},this.events$=new p.Subject,this.submit$=new p.Subject,this.uuid=crypto.randomUUID(),this.itemRenderers={},this.dependencies={}}initialize(t,r=[],n,o,i,s=It(),d,c={}){this.localization=s,this.dependencies=d,this.widgetRegistry.setWidgetLoaders(t),this.itemRenderers=i,this.store=Oo(r,n,o,s,c)}emitEvent(t,r,n){const i=this.store.getState().currentStates.filter(s=>r.on?.[`${t}.${s}`]!==void 0);if(i.length>0)i.forEach(s=>{const d=r.on?.[`${t}.${s}`];this.attemptValidation(t,r),d&&this.events$.next({name:d,data:we(this.store.getState()),detail:n??void 0,callback:c=>{this.store.dispatch(c)}})});else{const s=r.on?.[t];this.attemptValidation(t,r),s&&this.events$.next({name:s,data:we(this.store.getState()),detail:n,callback:d=>{this.store.dispatch(d)}})}}emitSubmitEvent(){this.store.dispatch({type:"VALIDATE_ALL"}),this.store.getState().isFormValid&&this.submit$.next({data:we(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 Wo(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 To=p.pipe(p.map(e=>e.data),p.distinctUntilChanged()),ko=e=>p.pipe(To,p.map(t=>N(t,e)),p.distinctUntilChanged()),Fo=p.pipe(p.filter(e=>e.touched===!0),p.map(e=>e.validations),p.distinctUntilChanged()),jo=e=>p.pipe(Fo,p.map(t=>t[e]),p.distinctUntilChanged()),Po=p.pipe(p.filter(e=>e.touched===!0),p.map(e=>e.injectedValidations),p.distinctUntilChanged()),No=e=>p.pipe(Po,p.map(t=>t[e]),p.distinctUntilChanged(),p.startWith(null)),Uo=p.pipe(p.map(e=>e.lang),p.distinctUntilChanged()),tr=p.pipe(p.map(e=>e.calculatedWidgets),p.distinctUntilChanged()),_o=e=>t=>p.combineLatest([t.pipe(Uo),t.pipe(tr)]).pipe(p.map(([r,n])=>({lang:r,widget:n[e]})),p.filter(r=>r.widget!==void 0),p.distinctUntilChanged((r,n)=>r.lang===n.lang&&r.widget===n.widget),p.map(r=>r.widget.current)),Vo=e=>p.pipe(tr,p.map(t=>t[e]),p.filter(t=>t!==void 0),p.map(t=>t.current.children),p.distinctUntilChanged());p.pipe(p.map(e=>e.widgetFlags),p.distinctUntilChanged());const Lo=p.pipe(p.map(e=>e.touchedControls),p.distinctUntilChanged()),Ro=e=>p.pipe(Lo,p.map(t=>t[e]),p.distinctUntilChanged()),Mo=p.pipe(p.map(e=>e.formHealth),p.distinctUntilChanged((e,t)=>e.status!==t.status?!1:e.status==="errored"&&t.status==="errored"?e.message===t.message&&e.code===t.code:!0)),Bo=e=>e.pipe(Mo);let rr=!1;function Ho(){rr=!0}function zo(){return rr}function Go(e,t,r){if(!zo())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`)}exports.FormContext=Do;exports.assertNoPropCollisions=Go;exports.calculatedLayoutChildrenByUid$=Vo;exports.calculatedWidgetsByUid$=_o;exports.cloneObject=ae;exports.dataByPath$=ko;exports.defineForm=vr;exports.devToolsMiddleware=Wo;exports.enableDevMode=Ho;exports.errorCodes=B;exports.filterTap=Co;exports.formEventNames=Er;exports.formHealth=Bo;exports.getDirectionFromLanguage=Ir;exports.identityTranslator=It;exports.injectedValidationByPath$=No;exports.isStandardValidateSuccess=gt;exports.makeRepeaterItemConfig=_e;exports.shortUUID=St;exports.standardValidate=mt;exports.touchedControlsByPath$=Ro;exports.validationByPath$=jo;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const W=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 yr=class{value;constructor(e){this.value=e}map(e){return j(e(this.value))}isOk(){return!0}},vr=class jt{issues;constructor(t){this.issues=t}map(t){return new jt(this.issues)}isOk(){return!1}};function j(e){return new yr(e)}function E(e){return new vr(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)):E(n.issues)})}flatMap(t){return new Pe(r=>{let n=this.decodeFn(r);return n.isOk()?t(n.value).decode(r):E(n.issues)})}},z=(e,t)=>[{message:`${JSON.stringify(e)} is not a valid ${t}`,path:[]}],_e=(e,t)=>e.map(r=>({...r,path:[t,...r.path]}));function Le(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(..._e(s.issues,o))}return n.length>0?E(n):j(r)}else return E(z(t,"array"))})}function $r(){return new C(e=>typeof e=="boolean"?j(e):E(z(e,"boolean")))}function Sr(e,t){return new C(r=>{if(typeof r!="object"||!r)return E(z(r,"object"));let n=r[e];return Object.prototype.hasOwnProperty.call(t,n)?t[n].decode(r):E([{message:`"${e}" must be one of ${Object.keys(t).map(o=>JSON.stringify(o)).join(", ")}, but got ${JSON.stringify(n)}`,path:[e]}])})}function Pt(e){return new C(t=>e().decode(t))}function K(e){return new C(t=>t===e?j(e):E([{message:`${JSON.stringify(t)} is not exactly ${JSON.stringify(e)}`,path:[]}]))}function ye(){return new C(e=>typeof e=="number"?j(e):E(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(..._e(s.issues,o))}return n.length>0?E(n):j(r)}else return E(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 E([{message:`no alternative matched (tried ${e.length})`,path:[]},...Ar(r)])})}function Ar(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 Er(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(..._e(s.issues,o))}return n.length>0?E(n):j(r)}else return E(z(t,"object"))})}function w(){return new C(e=>typeof e=="string"?j(e):E(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 E([{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 E(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 E(d.issues.map(l=>({message:l.message,path:[i,...l.path]})));r[i]=d.value}}}return j(r)})}const Ft=()=>crypto.randomUUID().slice(0,8),wr=e=>typeof e!="function"&&e.kind==="display",de=e=>typeof e!="function"&&e.kind==="action",P=e=>typeof e!="function"&&e.kind==="input",H=e=>typeof e!="function"&&e.kind==="layout",T=e=>typeof e=="function",Or=te({in:Le(w())}),Ue=te({when:w()}),ve=x([Or,Ue]),Cr=te({from:Le(w())}),$e=x([Cr,Ue]),Fe=x([$r(),Ue]),Ir=new C(e=>{const t=typeof e;return t==="function"?j(e):E([{message:`Expected a function, got '${t}'`,path:[]}])}),N=e=>x([e,Ir]),be=re({load:{suffixed:!0,decoder:N(y(w()))},click:{suffixed:!0,decoder:N(y(w()))},change:{suffixed:!0,decoder:N(y(w()))},filter:{suffixed:!0,decoder:N(y(w()))},blur:{suffixed:!0,decoder:N(y(w()))}}),jr=te({key:w(),default:y(w()),params:y(b())}),Dt=x([w(),jr]),He=y(w()),kr=re({kind:{decoder:K("display")},uid:{decoder:He},type:{decoder:w()},size:{suffixed:!0,decoder:y(ye())},include:{decoder:y(ve)},exclude:{decoder:y($e)},props:{decoder:y(b())}}),Pr=re({kind:{decoder:K("action")},uid:{decoder:He},type:{decoder:w()},actionType:{decoder:y(x([K("button"),K("submit")]))},size:{suffixed:!0,decoder:y(ye())},include:{decoder:y(ve)},exclude:{decoder:y($e)},label:{suffixed:!0,decoder:N(y(Dt))},disabled:{suffixed:!0,decoder:y(Fe)},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||Ft(),r.type=n.type,r.path=n.path,j(r)}else return E([{message:`Expected a function, got '${t}'`,path:[]}])}),Dr=re({kind:{decoder:K("input")},uid:{decoder:y(w())},type:{decoder:w()},size:{suffixed:!0,decoder:y(ye())},include:{decoder:y(ve)},exclude:{decoder:y($e)},disabled:{suffixed:!0,decoder:y(Fe)},readonly:{suffixed:!0,decoder:y(Fe)},on:{decoder:y(be)},props:{decoder:y(b())},label:{suffixed:!0,decoder:N(y(Dt))},path:{decoder:w()},defaultValue:{decoder:y(b())},validator:{suffixed:!0,decoder:N(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=Pt(()=>{const e=Sr("kind",{input:Dr,layout:ze,display:kr,action:Pr});return new C(t=>typeof t=="function"?Fr.decode(t):e.decode(t))}),ze=re({kind:{decoder:K("layout")},uid:{decoder:He},type:{decoder:w()},size:{suffixed:!0,decoder:y(ye())},include:{decoder:y(ve)},exclude:{decoder:y($e)},props:{decoder:y(b())},on:{decoder:y(be)},children:{decoder:Le(Wr)}}),U=class U{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(!U.sharedCache.has(r)){const n=r().catch(o=>(U.sharedCache.delete(r),Promise.reject(o)));U.sharedCache.set(r,n)}return U.sharedCache.get(r)}};U.sharedCache=new Map;let De=U;function Tr(e){We(e,"#0")}function We(e,t){if(!T(e)&&(e.uid||(e.uid=t),H(e)&&e.children.forEach((r,n)=>{We(r,`${t}.${n}`)}),P(e)&&e.type==="repeater")){const r=e.props?.template;r&&We(r,`${t}.t`)}}function Nr(e){return{...e,form:{uid:"",type:"flex",kind:"layout",children:e.form}}}const Wt=te({states:y(Er(w())),form:Pt(()=>ze)}).map(e=>(Tr(e.form),e)),Tt=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 Mr(e){const t=new Intl.Locale(e).maximize().script;return["Arab","Hebr","Thaa","Syrc","Tfng","Adlm","Rohg"].includes(t||"")?"rtl":"ltr"}const Nt=(e=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},_r=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)},Lr=(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]=Rt(d)?[]:{}),o=o[u]}const s=n[n.length-1];return o[s]=r,e},Vt=(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]=Rt(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 Rt(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 Se(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 R(e){if(e!==void 0)return P(e)||T(e)?e.path:void 0}function Ie(e){const t=q(e.data);for(const[r,n]of Object.entries(e.widgetFlags))if(n.hidden===!0){const o=R(e.resolvedSources[r]);o!==void 0&&Ur(t,o)}return t}const Ae=e=>!T(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,Ae(n)&&Mt(n,[],t,r);return r}function Mt(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&&Mt(g,d,r,n)}})}function Hr(e,t,r,n,o,s){if(Ae(t))return t;if(!T(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(T(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 P(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))!P(s)||Lr(t,s.path)||(t=Vt(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=m.slice(Math.max(0,t-40),t),s="̭",i=(m[t]||" ")+s,u=m.slice(t+1,t+20))=>{throw SyntaxError(`${e} at ${r.length+1}:${n.length+1}
|
|
3
|
+
${m[t-41]!==`
|
|
4
|
+
`,""+o}${i}${u}`)},_t=(e,t=h)=>(Array.isArray(e)&&(e.loc=t),e),X=(e,t=h,r)=>{for(;r=e(m.charCodeAt(h));)h+=r;return m.slice(t,h)},O=(e=1)=>m[h+=e],Re=e=>h=e,S=(e=0,t)=>{let r,n,o,s,i;for(t&&v.asi&&(v.newline=!1);(r=v.space())&&(i=v.newline,1)&&r!==t&&(o=(n&&r===91&&Ve&&v.asi?.(n,e,S)||null)??((s=D[r])&&s(n,e))??(n&&i&&v.asi?.(n,e,S))??(!n&&X(v.id)));)n=o;return t&&(r==t?(h++,t===125&&v.asi&&(v.newline=!0)):B("Unclosed "+String.fromCharCode(t-(t>42?2:1)))),n},M=(e,t=h)=>{for(Ve=!1;(e=m.charCodeAt(h))<=xe;)v.asi&&e===10&&(v.newline=Ve=!0),h++;return e},xr=(e=h)=>{for(;m.charCodeAt(e)<=xe;)e++;return m.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 Xr=(e,t=e.length)=>m.substr(h,t)===e&&!v.id(m.charCodeAt(h+t)),D=[],ft={},F=(e,t=xe,r,n=e.charCodeAt(0),o=e.length,s=D[n],i=e.toUpperCase()!==e,u,d)=>(t=ft[e]=!s&&ft[e]||t,D[n]=(l,a,p,g=h)=>(u=p,(p?e==p:(o<2||e.charCodeAt(1)===m.charCodeAt(h+1)&&(o<3||m.substr(h,o)==e))&&(!i||!v.id(m.charCodeAt(h+o)))&&(u=p=e))&&a<t&&(h+=o,(d=r(l))?_t(d,g):(h=g,u=0,!i&&!s&&!l&&B()),d)||s?.(l,a,u))),$=(e,t,r=!1)=>F(e,t,n=>n&&(o=>o&&[e,n,o])(S(t-(r?.5:0)))),L=(e,t,r)=>F(e,t,n=>!n&&(n=S(t-.5))&&[e,n]),oe=(e,t)=>F(e,200,r=>!r&&[,t]),Lt=(e,t,r)=>F(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)),Xe=(e,t)=>F(e[0],t,r=>!r&&[e,S(0,e.charCodeAt(1))||null]),Ut=(e,t)=>F(e[0],t,r=>r&&[e,r,S(0,e.charCodeAt(1))||null]),se=(e,t,r,n=e.charCodeAt(0),o=e.length,s=D[n],i)=>D[n]=(u,d,l,a=h)=>!u&&(l?e==l:(o<2||m.substr(h,o)==e)&&(l=e))&&d<t&&!v.id(m.charCodeAt(h+o))&&(!v.prop||v.prop(h+o))&&(Re(h+o),(i=r())?_t(i,a):Re(a),i)||s?.(u,d,l);Object.defineProperty(v,"space",{configurable:!0,enumerable:!0,get:()=>M,set:e=>M=e});const Me={},f=(e,t,r=Me[e])=>Me[e]=(...n)=>t(...n)||r?.(...n),c=e=>Array.isArray(e)?e[0]==null?(t=>()=>t)(e[1]):Me[e[0]]?.(...e.slice(1))??B(`Unknown operator: ${e[0]}`,e?.loc):e===void 0?()=>{}:t=>t?.[e],le=46,Z=48,ae=57,Jr=69,Qr=101,qr=43,Zr=45,ce=95,bt=110,Yr=97,en=102,tn=65,rn=70,Ht=e=>e.indexOf("_")<0?e:e.replaceAll("_",""),Je=e=>{let t=Ht(X(r=>r===le&&m.charCodeAt(h+1)!==le||r>=Z&&r<=ae||r===ce||((r===Jr||r===Qr)&&((r=m.charCodeAt(h+1))>=Z&&r<=ae||r===qr||r===Zr)?2:0)));return m.charCodeAt(h)===bt?(O(),[,BigInt(t)]):(e=+t)!=e?B():[,e]},nn={2:e=>e===48||e===49||e===ce,8:e=>e>=48&&e<=55||e===ce,16:e=>e>=Z&&e<=ae||e>=Yr&&e<=en||e>=tn&&e<=rn||e===ce};v.number=null;D[le]=e=>!e&&m.charCodeAt(h+1)!==le&&Je();for(let e=Z;e<=ae;e++)D[e]=t=>t?void 0:Je();D[Z]=e=>{if(e)return;const t=v.number;if(t){for(const[r,n]of Object.entries(t))if(r[0]==="0"&&m[h+1]?.toLowerCase()===r[1]){O(2);const o=Ht(X(nn[n]));return m.charCodeAt(h)===bt?(O(),[,BigInt("0"+r[1]+o)]):[,parseInt(o,n)]}}return Je()};const on=92,pt=34,ht=39,sn={n:`
|
|
5
|
+
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},zt=e=>(t,r,n="")=>{if(!(t||!v.string?.[String.fromCharCode(e)]))return O(),X(o=>o-e&&(o===on?(n+=sn[m[h+1]]||m[h+1],2):(n+=m[h],1))),m[h]===String.fromCharCode(e)?O():B("Bad string"),[,n]};D[pt]=zt(pt);D[ht]=zt(ht);v.string={'"':!0};const un=20;"= += -= *= /= %= |= &= ^= >>= <<=".split(" ").map(e=>$(e,un,!0));const Bt=(e,t,r,n)=>typeof e=="string"?o=>t(o,e,o):e[0]==="."?(r=c(e[1]),n=e[2],o=>t(r(o),n,o)):e[0]==="[]"&&e.length===3?(r=c(e[1]),n=c(e[2]),o=>t(r(o),n(o),o)):e[0]==="()"&&e.length===2?Bt(e[1],t):(()=>{throw Error("Invalid assignment target")})(),mt={"=":(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 mt)f(e,(t,r)=>(r=c(r),Bt(t,(n,o,s)=>mt[e](n,o,r(s)))));const cn=30,dn=40,ln=140;L("!",ln);$("||",cn);$("&&",dn);f("!",e=>(e=c(e),t=>!e(t)));f("||",(e,t)=>(e=c(e),t=c(t),r=>e(r)||t(r)));f("&&",(e,t)=>(e=c(e),t=c(t),r=>e(r)&&t(r)));const an=50,fn=60,pn=70,Gt=100,hn=140;$("|",an);$("&",pn);$("^",fn);$(">>",Gt);$("<<",Gt);L("~",hn);f("~",e=>(e=c(e),t=>~e(t)));f("|",(e,t)=>(e=c(e),t=c(t),r=>e(r)|t(r)));f("&",(e,t)=>(e=c(e),t=c(t),r=>e(r)&t(r)));f("^",(e,t)=>(e=c(e),t=c(t),r=>e(r)^t(r)));f(">>",(e,t)=>(e=c(e),t=c(t),r=>e(r)>>t(r)));f("<<",(e,t)=>(e=c(e),t=c(t),r=>e(r)<<t(r)));const Ee=90;$("<",Ee);$(">",Ee);$("<=",Ee);$(">=",Ee);f(">",(e,t)=>(e=c(e),t=c(t),r=>e(r)>t(r)));f("<",(e,t)=>(e=c(e),t=c(t),r=>e(r)<t(r)));f(">=",(e,t)=>(e=c(e),t=c(t),r=>e(r)>=t(r)));f("<=",(e,t)=>(e=c(e),t=c(t),r=>e(r)<=t(r)));const Kt=80;$("==",Kt);$("!=",Kt);f("==",(e,t)=>(e=c(e),t=c(t),r=>e(r)==t(r)));f("!=",(e,t)=>(e=c(e),t=c(t),r=>e(r)!=t(r)));const xt=110,Qe=120,Xt=140;$("+",xt);$("-",xt);$("*",Qe);$("/",Qe);$("%",Qe);L("+",Xt);L("-",Xt);f("+",(e,t)=>t!==void 0?(e=c(e),t=c(t),r=>e(r)+t(r)):(e=c(e),r=>+e(r)));f("-",(e,t)=>t!==void 0?(e=c(e),t=c(t),r=>e(r)-t(r)):(e=c(e),r=>-e(r)));f("*",(e,t)=>(e=c(e),t=c(t),r=>e(r)*t(r)));f("/",(e,t)=>(e=c(e),t=c(t),r=>e(r)/t(r)));f("%",(e,t)=>(e=c(e),t=c(t),r=>e(r)%t(r)));const fe=150;F("++",fe,e=>e?["++",e,null]:["++",S(fe-1)]);F("--",fe,e=>e?["--",e,null]:["--",S(fe-1)]);const qe=(e,t,r,n)=>typeof e=="string"?o=>t(o,e):e[0]==="."?(r=c(e[1]),n=e[2],o=>t(r(o),n)):e[0]==="[]"&&e.length===3?(r=c(e[1]),n=c(e[2]),o=>t(r(o),n(o))):e[0]==="()"&&e.length===2?qe(e[1],t):(()=>{throw Error("Invalid increment target")})();f("++",(e,t)=>qe(e,t===null?(r,n)=>r[n]++:(r,n)=>++r[n]));f("--",(e,t)=>qe(e,t===null?(r,n)=>r[n]--:(r,n)=>--r[n]));const mn=5,gn=10;Lt(",",gn);Lt(";",mn,!0);const Jt=(...e)=>(e=e.map(c),t=>{let r;for(const n of e)r=n(t);return r});f(",",Jt);f(";",Jt);const yn=170;Xe("()",yn);const V=e=>e?.[0]==="_"&&e[1]==="_"||e==="constructor"||e==="prototype",Ze=170;Ut("[]",Ze);$(".",Ze);Ut("()",Ze);const pe=e=>{throw Error(e)};f("[]",(e,t)=>t===void 0?(e=e?e[0]===","?e.slice(1):[e]:[],e=e.map(r=>r==null?(()=>{}):r[0]==="..."?(r=c(r[1]),n=>r(n)):(r=c(r),n=>[r(n)])),r=>e.flatMap(n=>n(r))):(t==null&&pe("Missing index"),e=c(e),t=c(t),r=>{const n=t(r);return V(n)?void 0:e(r)[n]}));f(".",(e,t)=>(e=c(e),t=t[0]?t:t[1],V(t)?()=>{}:r=>e(r)[t]));f("()",(e,t)=>{if(t===void 0)return e==null?pe("Empty ()"):c(e);const r=o=>o?.[0]===","&&o.slice(1).some(s=>s==null||r(s));r(t)&&pe("Empty argument");const n=t?t[0]===","?(t=t.slice(1).map(c),o=>t.map(s=>s(o))):(t=c(t),o=>[t(o)]):()=>[];return Ye(e,(o,s,i)=>o[s](...n(i)))});const G=e=>typeof e=="string"||Array.isArray(e)&&(e[0]==="."||e[0]==="?."||e[0]==="[]"&&e.length===3||e[0]==="?.[]"||e[0]==="()"&&e.length===2&&G(e[1])||e[0]==="{}"),Ye=(e,t,r,n)=>e==null?pe("Empty ()"):e[0]==="()"&&e.length==2?Ye(e[1],t):typeof e=="string"?o=>t(o,e,o):e[0]==="."?(r=c(e[1]),n=e[2],o=>t(r(o),n,o)):e[0]==="?."?(r=c(e[1]),n=e[2],o=>{const s=r(o);return s==null?void 0:t(s,n,o)}):e[0]==="[]"&&e.length===3?(r=c(e[1]),n=c(e[2]),o=>t(r(o),n(o),o)):e[0]==="?.[]"?(r=c(e[1]),n=c(e[2]),o=>{const s=r(o);return s==null?void 0:t(s,n(o),o)}):(e=c(e),o=>t([e(o)],0,o)),J=Ye,vn=32,$n=v.space;v.comment??={"//":`
|
|
6
|
+
`,"/*":"*/"};let je;v.space=()=>{je||(je=Object.entries(v.comment).map(([o,s])=>[o,s,o.charCodeAt(0)]));for(var e;e=$n();){for(var t=0,r;r=je[t++];)if(e===r[2]&&m.substr(h,r[0].length)===r[0]){var n=h+r[0].length;if(r[1]===`
|
|
7
|
+
`)for(;m.charCodeAt(n)>=vn;)n++;else{for(;m[n]&&m.substr(n,r[1].length)!==r[1];)n++;m[n]&&(n+=r[1].length)}Re(n),e=0;break}if(e)return e}return e};const Qt=80;$("===",Qt);$("!==",Qt);f("===",(e,t)=>(e=c(e),t=c(t),r=>e(r)===t(r)));f("!==",(e,t)=>(e=c(e),t=c(t),r=>e(r)!==t(r)));const Sn=30;$("??",Sn);f("??",(e,t)=>(e=c(e),t=c(t),r=>e(r)??t(r)));const An=130,En=20;$("**",An,!0);$("**=",En,!0);f("**",(e,t)=>(e=c(e),t=c(t),r=>e(r)**t(r)));const wn=e=>{throw Error(e)};f("**=",(e,t)=>(G(e)||wn("Invalid assignment target"),t=c(t),J(e,(r,n,o)=>r[n]**=t(o))));const qt=90;$("in",qt);$("of",qt);f("in",(e,t)=>(e=c(e),t=c(t),r=>e(r)in t(r)));const On=20,Cn=100,In=e=>{throw Error(e)};$(">>>",Cn);$(">>>=",On,!0);f(">>>",(e,t)=>(e=c(e),t=c(t),r=>e(r)>>>t(r)));f(">>>=",(e,t)=>(G(e)||In("Invalid assignment target"),t=c(t),J(e,(r,n,o)=>r[n]>>>=t(o))));const et=5,jn=10,kn=20,Pn=e=>e[0]?.[0]===","?e[0].slice(1):e,he=(e,t,r)=>{if(typeof e=="string"){r[e]=t;return}const[n,...o]=e,s=Pn(o);if(n==="{}"){const i=[];for(const u of s){if(Array.isArray(u)&&u[0]==="..."){const g={};for(const I in t)i.includes(I)||(g[I]=t[I]);r[u[1]]=g;break}let d,l,a;typeof u=="string"?d=l=u:u[0]==="="?(typeof u[1]=="string"?d=l=u[1]:[,d,l]=u[1],a=u[2]):[,d,l]=u,i.push(d);let p=t[d];p===void 0&&a&&(p=c(a)(r)),he(l,p,r)}}else if(n==="[]"){let i=0;for(const u of s){if(u===null){i++;continue}if(Array.isArray(u)&&u[0]==="..."){r[u[1]]=t.slice(i);break}let d=u,l;Array.isArray(u)&&u[0]==="="&&([,d,l]=u);let a=t[i++];a===void 0&&l&&(a=c(l)(r)),he(d,a,r)}}},Zt=e=>{let t=S(jn-1);return t?.[0]==="in"||t?.[0]==="of"?[t[0],[e,t[1]],t[2]]:t?.[0]===","?[e,...t.slice(1)]:[e,t]};se("let",et+1,()=>Zt("let"));se("const",et+1,()=>Zt("const"));se("var",et,()=>(M(),["var",S(kn)]));const Yt=(...e)=>(e=e.map(t=>{if(typeof t=="string")return r=>{r[t]=void 0};if(t[0]==="="){const[,r,n]=t,o=c(n);return typeof r=="string"?s=>{s[r]=o(s)}:s=>he(r,o(s),s)}return c(t)}),t=>{for(const r of e)r(t)});f("let",Yt);f("const",Yt);f("var",e=>typeof e=="string"?t=>{t[e]=void 0}:()=>{});const tt=20,we=e=>{throw Error(e)};$("||=",tt,!0);$("&&=",tt,!0);$("??=",tt,!0);f("=",(e,t)=>{if(Array.isArray(e)&&(e[0]==="let"||e[0]==="const"||e[0]==="var")){const r=e[1];return t=c(t),typeof r=="string"?n=>{n[r]=t(n)}:n=>he(r,t(n),n)}return G(e)||we("Invalid assignment target"),t=c(t),J(e,(r,n,o)=>r[n]=t(o))});f("||=",(e,t)=>(G(e)||we("Invalid assignment target"),t=c(t),J(e,(r,n,o)=>r[n]||=t(o))));f("&&=",(e,t)=>(G(e)||we("Invalid assignment target"),t=c(t),J(e,(r,n,o)=>r[n]&&=t(o))));f("??=",(e,t)=>(G(e)||we("Invalid assignment target"),t=c(t),J(e,(r,n,o)=>r[n]??=t(o))));oe("true",!0);oe("false",!1);oe("null",null);se("undefined",200,()=>[]);oe("NaN",NaN);oe("Infinity",1/0);const ke=20;F("?",ke,(e,t,r)=>e&&(t=S(ke-1))&&X(n=>n===58)&&(r=S(ke-1),["?",e,t,r]));f("?",(e,t,r)=>(e=c(e),t=c(t),r=c(r),n=>e(n)?t(n):r(n)));const Fn=[],Dn=20;$("=>",Dn,!0);f("=>",(e,t)=>{e=e?.[0]==="()"?e[1]:e;const r=e?e[0]===","?e.slice(1):[e]:[];let n=-1,o=null;const s=r[r.length-1];Array.isArray(s)&&s[0]==="..."&&(n=r.length-1,o=s[1],r.length--);const i=t?.[0]==="{}";return t=c(i?["{",t[1]]:t),u=>(...d)=>{const l={};r.forEach((p,g)=>l[p]=d[g]),o&&(l[o]=d.slice(n));const a=new Proxy(l,{get:(p,g)=>g in p?p[g]:u?.[g],set:(p,g,I)=>((g in p?p:u)[g]=I,!0),has:(p,g)=>g in p||(u?g in u:!1)});try{const p=t(a);return i?void 0:p}catch(p){if(p===Fn)return p[0];throw p}}});const Wn=140;L("...",Wn);f("...",e=>(e=c(e),t=>Object.entries(e(t))));const gt=170;F("?.",gt,(e,t)=>{if(!e)return;const r=M();return r===40?(O(),["?.()",e,S(0,41)||null]):r===91?(O(),["?.[]",e,S(0,93)]):(t=S(gt),t?["?.",e,t]:void 0)});f("?.",(e,t)=>(e=c(e),V(t)?()=>{}:r=>e(r)?.[t]));f("?.[]",(e,t)=>(e=c(e),t=c(t),r=>{const n=t(r);return V(n)?void 0:e(r)?.[n]}));f("?.()",(e,t)=>{const r=t?t[0]===","?(t=t.slice(1).map(c),o=>t.map(s=>s(o))):(t=c(t),o=>[t(o)]):()=>[];if(e[0]==="?."){const o=c(e[1]),s=e[2];return V(s)?()=>{}:i=>o(i)?.[s]?.(...r(i))}if(e[0]==="?.[]"){const o=c(e[1]),s=c(e[2]);return i=>{const u=o(i),d=s(i);return V(d)?void 0:u?.[d]?.(...r(i))}}if(e[0]==="."){const o=c(e[1]),s=e[2];return V(s)?()=>{}:i=>o(i)?.[s]?.(...r(i))}if(e[0]==="[]"&&e.length===3){const o=c(e[1]),s=c(e[2]);return i=>{const u=o(i),d=s(i);return V(d)?void 0:u?.[d]?.(...r(i))}}const n=c(e);return o=>n(o)?.(...r(o))});const Y=140;L("typeof",Y);L("void",Y);L("delete",Y);se("new",Y,()=>Xr(".target")?(O(7),["new.target"]):["new",S(Y)]);f("typeof",e=>(e=c(e),t=>typeof e(t)));f("void",e=>(e=c(e),t=>(e(t),void 0)));f("delete",e=>{if(e[0]==="."){const t=c(e[1]),r=e[2];return n=>delete t(n)[r]}if(e[0]==="[]"){const t=c(e[1]),r=c(e[2]);return n=>delete t(n)[r(n)]}return()=>!0});f("new",e=>{const t=c(e?.[0]==="()"?e[1]:e),r=e?.[0]==="()"?e[2]:null,n=r?r[0]===","?(o=>s=>o.map(i=>i(s)))(r.slice(1).map(c)):(o=>s=>[o(s)])(c(r)):()=>[];return o=>new(t(o))(...n(o))});const rt=Symbol("accessor"),nt=20,Tn=40,er=41,tr=123,rr=125,nr=e=>t=>{if(t)return;M();const r=X(v.id);if(!r||(M(),m.charCodeAt(h)!==Tn))return!1;O();const n=S(0,er);return M(),m.charCodeAt(h)!==tr?!1:(O(),[e,r,n,S(0,rr)])};F("get",nt-1,nr("get"));F("set",nt-1,nr("set"));F("(",nt-1,e=>{if(!e||typeof e!="string")return;const t=S(0,er)||null;if(M(),m.charCodeAt(h)===tr)return O(),[":",e,["=>",["()",t],S(0,rr)||null]]});f("get",(e,t)=>(t=t?c(t):()=>{},r=>[[rt,e,{get:function(){const n=Object.create(r||{});return n.this=this,t(n)}}]]));f("set",(e,t,r)=>(r=r?c(r):()=>{},n=>[[rt,e,{set:function(o){const s=Object.create(n||{});s.this=this,s[t]=o,r(s)}}]]));const Nn=20,or=200;v.prop=e=>xr(e)!==58;const Vn=e=>e==null||typeof e=="string"||[":",",","...","get","set"].includes(e[0]);Xe("[]",or);Xe("{}",or);$(":",Nn-1,!0);f("{}",(e,t)=>{if(t!==void 0)return;if(!Vn(e))return c(["{",e]);e=e?e[0]!==","?[e]:e.slice(1):[];const r=e.map(n=>c(typeof n=="string"?[":",n,n]:n));return n=>{const o={},s={};for(const i of r.flatMap(u=>u(n)))if(i[0]===rt){const[,u,d]=i;s[u]={...s[u],...d,configurable:!0,enumerable:!0}}else o[i[0]]=i[1];for(const i in s)Object.defineProperty(o,i,s[i]);return o}});f("{",e=>(e=e?c(e):()=>{},t=>e(Object.create(t))));f(":",(e,t)=>(t=c(t),Array.isArray(e)?(e=c(e),r=>[[e(r),t(r)]]):r=>[[e,t(r)]]));const Rn=170,me=96,Mn=36,_n=123,Ln=92,Un={n:`
|
|
8
|
+
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},yt=()=>{const e=[];for(let t="",r;(r=m.charCodeAt(h))!==me;)r?r===Ln?(O(),t+=Un[m[h]]||m[h],O()):r===Mn&&m.charCodeAt(h+1)===_n?(t&&e.push([,t]),t="",O(2),e.push(S(0,125))):(t+=m[h],O(),r=m.charCodeAt(h),r===me&&t&&e.push([,t])):B("Unterminated template");return O(),e},bn=D[me];D[me]=(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??Se(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 ge(e,t){if(e===t)return!0;if(Array.isArray(e)&&Array.isArray(t))return e.length===t.length&&e.every((r,n)=>ge(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&&ge(e[n],t[n]))}return!1}const Xn=e=>(t,r)=>{const{$formIsInvalid:n,$errors:o}=r??Se(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(T(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)),(P(u)||de(u))&&ee(u.disabled)&&(i[u.uid].disabled=Q(u.disabled.when,e.data,e.meta,t,r,l)),P(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)||(P(e)||de(e))&&ee(e.disabled)||P(e)&&ee(e.readonly))}function Qn(e,t){const r=Object.keys(t).filter(n=>t[n].hidden===!0);for(const n of r)sr(n,e,t)}function sr(e,t,r){const n=t.resolvedSources[e];if(n!==void 0){if(Ae(n)||T(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||sr(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;T(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 ir=(e,t)=>(r,n)=>{try{const o=n??Se(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(T(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&&ge(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):P(t)?ro(o,n):H(t)&&no(o,n),oo(t,o,n,r),(de(t)||P(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 dr(Object.keys(s)))uo(t,r,i)}function so(e,t,r){const n=e.on??{};for(const o of dr(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=cr(o,t)}e.write(r,s)}function uo(e,t,r){const n=e.source.props,o=it(n,r,t.sortedStates);let s=cr(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 ur(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 lr(`Failed to evaluate '{{${n.trim()}}}': ${s}`)}}):e}function cr(e,t){return typeof e=="function"?st(e,t):Rr(e)?lo(e,t):typeof e=="string"?ur(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"?ur(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 lr(`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(ge(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 dr(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 lr 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=R(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 Eo=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},wo=({lang:e},t)=>{const r={...Tt(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 ar(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)?ar(k.initializeMalformedFormShapeError,Oo()):null}function Io(e,t){const r=o=>P(o)?` at "${o.path}"`:"",n=`Duplicate UID "${t.uid}": Assigned to widget "${e.type}"${r(e)} and "${t.type}"${r(t)}.`;return ar(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 Po=(e,{payload:t})=>{const r="path"in t?Do(e,t.path):Fo(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 Fo(e,t){if(t in e.resolvedSources)return t;console.warn(`Widget with uid "${t}" not found`)}function Do(e,t){const r=Object.values(e.calculatedWidgets).find(({source:o,current:s})=>(R(s)??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 Wo=(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:Vt(e.data,t.payload.path,t.payload.data)}),fr=Symbol("filterMap.skip");function Mo(e,t){const r=[];for(let n=0;n<e.length;n++){const o=t(e[n],n,e);o!==fr&&r.push(o)}return r}function _o(e,t,r){for(let n=0;n<e.length;n++)t(e[n],n,e)&&r(e[n],n,e)}function Lo(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=Mo(Object.values(r.calculatedWidgets),({current:s})=>P(s)?s:fr),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])&&Lo(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=ir(r,n),u=l=>Et(l,o,s,!1),d=l=>Et(l,o,s,!0);return(l,a)=>{switch(a.type){case"INITIALIZE":return wo(l,a);case"SET_DATA":return u(Wo(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=Po(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 _r(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=ir(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=Se(d);return d=r(d,l),d.formHealth.status!=="ok"?u(d.formHealth):(d=n(d,l),d=Eo(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 Et(e,t,r,n){const o=a=>n?wt(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},wt(t(r(u)))}function Go(e,t,r){const n=[];for(const[o,s]of Object.entries(e.resolvedSources)){const i=R(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=R(n)??R(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&&P(n)&&(r=n.path)}return r!==void 0&&e.touchedControls[r]===!0}function wt(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 W.BehaviorSubject(Tt(n.lang)),i=s.asObservable().pipe(W.distinctUntilChanged()),u=bo({validators:t,validateOn:r,localization:n,functions:o});function d(g){const I=s.getValue(),Oe=u(I,g);s.next(Oe)}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 De,this.store={},this.events$=new W.Subject,this.submit$=new W.Subject,this.itemRenderers={},this.dependencies={}}initialize(t,r=[],n,o,s,i=Nt(),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:Ie(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:Ie(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:Ie(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=W.pipe(W.map(e=>e.formHealth),W.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 mr(e,t,hr(e,t),void 0)}function pr(){const e=new Map;return(t,r)=>{const n=hr(t,r),o=e.get(r);if(o&&os(o.slices,n))return o.viewModel;const s=mr(t,r,n,o);return e.set(r,{slices:n,viewModel:s}),s}}const ts=e=>t=>{const r=pr();return t.pipe(W.map(n=>r(n,e)),W.distinctUntilChanged())},rs=[],Ot=[],ns=[];function hr(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 mr(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),Oe=n===void 0||!Object.is(n.slices[3],u)||!Object.is(n.slices[4],d),Ce=o?.current;return{uid:t,widget:Ce,children:g?is(e,t,Ce):n.viewModel.children,rows:g||I?us(e,t,Ce,i):n.viewModel.rows,lang:s,value:i,errors:Oe?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||!Ae(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 gr=!1;function ds(){gr=!0}function ls(){return gr}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`)}exports.FormContext=Qo;exports.assertNoPropCollisions=as;exports.cloneObject=q;exports.createWidgetViewModelReader=pr;exports.defineForm=Nr;exports.devToolsMiddleware=qo;exports.enableDevMode=ds;exports.errorCodes=k;exports.filterTap=_o;exports.formEventNames=Vr;exports.formHealth=Yo;exports.getDirectionFromLanguage=Mr;exports.identityTranslator=Nt;exports.isStandardValidateSuccess=It;exports.makeRepeaterItemConfig=Ge;exports.shortUUID=Ft;exports.standardValidate=Ct;exports.widgetViewModel=es;exports.widgetViewModel$=ts;
|
|
@@ -13,7 +13,6 @@ export declare class FormContext<ComponentType> {
|
|
|
13
13
|
store: FormStore;
|
|
14
14
|
events$: Subject<FormEvent>;
|
|
15
15
|
submit$: Subject<FormSubmitEvent>;
|
|
16
|
-
uuid: `${string}-${string}-${string}-${string}-${string}`;
|
|
17
16
|
itemRenderers: Record<string, ItemRenderer>;
|
|
18
17
|
localization: I18nTranslator;
|
|
19
18
|
/**
|
package/lib/errors.d.ts
CHANGED
package/lib/shared.d.ts
CHANGED
|
@@ -157,6 +157,11 @@ export type ControlTemplateData<T, V = any> = {
|
|
|
157
157
|
disabled?: boolean;
|
|
158
158
|
readonly?: boolean;
|
|
159
159
|
touched?: boolean;
|
|
160
|
+
/**
|
|
161
|
+
* A repeater's rows: one row layout node per entry of its array value, with the row indexes
|
|
162
|
+
* already applied to every uid and path. Only set for repeater inputs.
|
|
163
|
+
*/
|
|
164
|
+
rows?: NonFunctionWidget<string>[];
|
|
160
165
|
};
|
|
161
166
|
/**
|
|
162
167
|
* Layout adapter templateData
|
package/lib/store/actions.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { FormWidget } from '../form-widget';
|
|
2
1
|
import { DotPath, Uid, ValidateOn } from '../shared';
|
|
3
2
|
import { FormHealth } from './model';
|
|
4
3
|
export type INITIALIZE = {
|
|
@@ -40,28 +39,6 @@ export type SET_LANGUAGE = {
|
|
|
40
39
|
lang: string;
|
|
41
40
|
};
|
|
42
41
|
};
|
|
43
|
-
export type ADD_WIDGET = {
|
|
44
|
-
type: 'ADD_WIDGET';
|
|
45
|
-
payload: {
|
|
46
|
-
widget: FormWidget<string>;
|
|
47
|
-
};
|
|
48
|
-
};
|
|
49
|
-
export type REMOVE_WIDGET = {
|
|
50
|
-
type: 'REMOVE_WIDGET';
|
|
51
|
-
payload: {
|
|
52
|
-
uid: Uid;
|
|
53
|
-
};
|
|
54
|
-
};
|
|
55
|
-
/**
|
|
56
|
-
* Sets the default value for a single form widget.
|
|
57
|
-
*/
|
|
58
|
-
export type SET_WIDGET_INITIAL_DATA = {
|
|
59
|
-
type: 'SET_WIDGET_INITIAL_DATA';
|
|
60
|
-
payload: {
|
|
61
|
-
path: DotPath;
|
|
62
|
-
data: any;
|
|
63
|
-
};
|
|
64
|
-
};
|
|
65
42
|
/**
|
|
66
43
|
* Sets the data for a single form widget.
|
|
67
44
|
*/
|
|
@@ -104,7 +81,6 @@ export type SET_FORM_HEALTH = {
|
|
|
104
81
|
*
|
|
105
82
|
* The actual validation behavior is determined by the form's configuration and
|
|
106
83
|
* may not execute immediately upon dispatch.
|
|
107
|
-
* ```
|
|
108
84
|
*/
|
|
109
85
|
export type ATTEMPT_VALIDATION = {
|
|
110
86
|
type: 'ATTEMPT_VALIDATION';
|
|
@@ -134,4 +110,4 @@ export type INJECT_VALIDATION_ISSUES = {
|
|
|
134
110
|
path: DotPath;
|
|
135
111
|
};
|
|
136
112
|
};
|
|
137
|
-
export type Action = INITIALIZE | SET_LANGUAGE | SET_DATA | SET_META |
|
|
113
|
+
export type Action = INITIALIZE | SET_LANGUAGE | SET_DATA | SET_META | SET_WIDGET_DATA | OVERRIDE_WIDGET_PROP | SET_FORM_HEALTH | INJECT_VALIDATION_ISSUES | ATTEMPT_VALIDATION | VALIDATE_ALL;
|
package/lib/store/model.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Form } from '../form';
|
|
2
|
-
import { FormWidget, FunctionWidget
|
|
2
|
+
import { FormWidget, FunctionWidget } from '../form-widget';
|
|
3
3
|
import { DotPath, Uid, ValidationStatus } from '../shared';
|
|
4
4
|
export type State = {
|
|
5
5
|
formName: string;
|
|
@@ -12,13 +12,24 @@ export type State = {
|
|
|
12
12
|
* Enables more efficient lookup and processing in downstream operations.
|
|
13
13
|
*/
|
|
14
14
|
flatForm: Record<Uid, FormWidget<string>>;
|
|
15
|
+
/**
|
|
16
|
+
* `flatForm` plus one entry per repeater row widget, keyed by concrete uid.
|
|
17
|
+
* Row entries carry the row indexes in `uid` and (for inputs) `path`, and include the row layout node
|
|
18
|
+
* and nested repeater containers. Function widgets stay callable, `when` expressions are not rewritten.
|
|
19
|
+
* Pure function of `(flatForm, data)`, built by `expandSources` on every reducer pipeline run.
|
|
20
|
+
* Read by the derive passes, the view model, `dropRemovedWidgetEntries`, `overrideWidgetProp`
|
|
21
|
+
* and `pruneHiddenData`.
|
|
22
|
+
*
|
|
23
|
+
* @example { 'quantity-number[0]': { uid: 'quantity-number[0]', path: 'lineItems.0.quantity', ... } }
|
|
24
|
+
*/
|
|
25
|
+
resolvedSources: Record<Uid, FormWidget<string>>;
|
|
15
26
|
/**
|
|
16
27
|
* List of states computed for the current form state.
|
|
17
28
|
*/
|
|
18
29
|
currentStates: string[];
|
|
19
30
|
/**
|
|
20
|
-
*
|
|
21
|
-
*
|
|
31
|
+
* The resolved widget for every visible widget in `resolvedSources`, recomputed from the data on
|
|
32
|
+
* every derive. Independent of which components are mounted. Hidden widgets have no entry.
|
|
22
33
|
*/
|
|
23
34
|
calculatedWidgets: Record<Uid, DerivedWidget<FormWidget<string>>>;
|
|
24
35
|
/**
|
|
@@ -45,8 +56,8 @@ export type State = {
|
|
|
45
56
|
*/
|
|
46
57
|
isFormValid: boolean;
|
|
47
58
|
/**
|
|
48
|
-
*
|
|
49
|
-
*
|
|
59
|
+
* The hidden, readonly and disabled flags for every widget in `resolvedSources`, recomputed on
|
|
60
|
+
* every derive. A hidden layout propagates its flag to its descendants.
|
|
50
61
|
*/
|
|
51
62
|
widgetFlags: Record<Uid, {
|
|
52
63
|
hidden?: boolean;
|
|
@@ -54,34 +65,23 @@ export type State = {
|
|
|
54
65
|
disabled?: boolean;
|
|
55
66
|
}>;
|
|
56
67
|
/**
|
|
57
|
-
* Maps every widget
|
|
68
|
+
* Maps every widget produced by a repeater item (by its concrete uid) to the repeater item that owns it.
|
|
58
69
|
* Used to bind the `$item` and `$index` expression scope variables.
|
|
59
70
|
* For nested repeaters the entry points to the innermost enclosing item.
|
|
60
|
-
* Built by `
|
|
71
|
+
* Built by `expandSources` together with `resolvedSources`.
|
|
61
72
|
*
|
|
62
73
|
* @example { 'quantity-number[0]': { itemPath: 'lineItems.0', index: 0 } }
|
|
63
74
|
* @example Nested repeater, keyed by the innermost item: { 'dev-name[2][0]': { itemPath: 'teams.2.devs.0', index: 0 } }
|
|
64
75
|
*/
|
|
65
76
|
repeaterItemScopes: Record<Uid, RepeaterItemScope>;
|
|
66
77
|
/**
|
|
67
|
-
*
|
|
68
|
-
* Each entry mirrors the widget the renderer mounts for that item:
|
|
69
|
-
* - the uid and data path carry the concrete indexes,
|
|
70
|
-
* - `when` expressions are rewritten for the item's row,
|
|
71
|
-
* - and function widgets are already resolved to plain configs.
|
|
72
|
-
* Built by `materializeRepeaterItems` on every reducer pipeline run and consumed by `calculateWidgetFlags`.
|
|
73
|
-
*
|
|
74
|
-
* @example { 'quantity-number[0]': { uid: 'quantity-number[0]', path: 'lineItems.0.quantity', ... } }
|
|
75
|
-
*/
|
|
76
|
-
materializedRepeaterWidgets: Record<Uid, NonFunctionWidget<string>>;
|
|
77
|
-
/**
|
|
78
|
-
* Allows overriding a widget’s `prop` properties externally via its event handler mechanism.
|
|
78
|
+
* Allows overriding a widget's `prop` properties externally via its event handler mechanism.
|
|
79
79
|
* For example, this can be used to load options for a select widget asynchronously.
|
|
80
80
|
*/
|
|
81
81
|
widgetPropOverrides: Record<Uid, Record<string, any>>;
|
|
82
82
|
/**
|
|
83
|
-
*
|
|
84
|
-
*
|
|
83
|
+
* The form's data tree. Input widgets address it by dot path, so a key can hold a nested
|
|
84
|
+
* object or an array as well as a leaf value.
|
|
85
85
|
*/
|
|
86
86
|
data: Record<string, any>;
|
|
87
87
|
/**
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { State } from '../model';
|
|
2
|
+
/**
|
|
3
|
+
* Writes the default value of every input whose path is missing from the data, and rebuilds
|
|
4
|
+
* `resolvedSources` and `repeaterItemScopes` for the data that results.
|
|
5
|
+
*
|
|
6
|
+
* An input whose path already exists keeps its value, so a cleared input is not defaulted again.
|
|
7
|
+
* An input without a `defaultValue` gets `undefined` written at its path, which creates the
|
|
8
|
+
* parent objects that expressions like `$form.user.name` read.
|
|
9
|
+
*
|
|
10
|
+
* @param state - The state to derive the defaults for
|
|
11
|
+
* @returns The state with `data` (only when something was written), `resolvedSources` and
|
|
12
|
+
* `repeaterItemScopes` updated. `touched` and `touchedControls` are never modified.
|
|
13
|
+
*/
|
|
14
|
+
export declare const applyDefaultValues: (state: State) => State;
|
|
@@ -1,3 +1,9 @@
|
|
|
1
1
|
import { ExpressionFunctions } from '../../shared';
|
|
2
|
+
import { ValidationVariables } from '../../utils/form';
|
|
2
3
|
import { State } from '../model';
|
|
3
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Evaluates the declared state expressions and writes the active state names to `currentStates`.
|
|
6
|
+
*
|
|
7
|
+
* @param validationVariables - Pass them when already computed for this pass, otherwise they are computed here.
|
|
8
|
+
*/
|
|
9
|
+
export declare const calculateCurrentState: (functions: ExpressionFunctions) => (state: State, validationVariables?: ValidationVariables) => State;
|
|
@@ -1,3 +1,9 @@
|
|
|
1
1
|
import { ExpressionFunctions } from '../../shared';
|
|
2
|
+
import { ValidationVariables } from '../../utils/form';
|
|
2
3
|
import { State } from '../model';
|
|
3
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Evaluates the include / exclude / disabled / readonly conditions of every widget in `resolvedSources`.
|
|
6
|
+
*
|
|
7
|
+
* @param validationVariables - Pass them when already computed for this pass, otherwise they are computed here.
|
|
8
|
+
*/
|
|
9
|
+
export declare const calculateWidgetFlags: (functions: ExpressionFunctions) => (state: State, validationVariables?: ValidationVariables) => State;
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import { I18nTranslator } from '../../i18n';
|
|
2
2
|
import { ExpressionFunctions } from '../../shared';
|
|
3
|
+
import { ValidationVariables } from '../../utils/form';
|
|
3
4
|
import { State } from '../model';
|
|
4
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Resolves the props of every visible entry in `calculatedWidgets`.
|
|
7
|
+
*
|
|
8
|
+
* @param validationVariables - Pass them when already computed for this pass, otherwise they are computed here.
|
|
9
|
+
*/
|
|
10
|
+
export declare const calculateWidgetProps: (localization: I18nTranslator, functions: ExpressionFunctions) => (state: State, validationVariables?: ValidationVariables) => State;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { State } from '../model';
|
|
2
|
+
/**
|
|
3
|
+
* Removes the entries that belong to widgets the current data no longer produces, for example
|
|
4
|
+
* the widgets of a repeater row that was deleted.
|
|
5
|
+
*
|
|
6
|
+
* `widgetPropOverrides` is keyed by uid, the other three are keyed by the input path, so a path
|
|
7
|
+
* that no live input owns is dropped from them.
|
|
8
|
+
*
|
|
9
|
+
* @param state - The state to clean, after `resolvedSources` has been rebuilt
|
|
10
|
+
* @returns The same state object when nothing was removed, otherwise a new one. Each record is
|
|
11
|
+
* also returned by reference when it did not lose an entry.
|
|
12
|
+
*/
|
|
13
|
+
export declare const dropRemovedWidgetEntries: (state: State) => State;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { State } from '../model';
|
|
2
|
+
/**
|
|
3
|
+
* Gives every widget the current data produces an entry in `calculatedWidgets`, and removes the
|
|
4
|
+
* entries of widgets it no longer produces.
|
|
5
|
+
*
|
|
6
|
+
* A new entry starts with an empty `current`, which the props step fills in. Existing entries are
|
|
7
|
+
* kept as they are so the props step can compare against the widget it computed last time.
|
|
8
|
+
*
|
|
9
|
+
* @param state - The state to fill, after `resolvedSources` has been rebuilt
|
|
10
|
+
* @returns The same state object when the set of uids did not change, otherwise a new one
|
|
11
|
+
*/
|
|
12
|
+
export declare const fillCalculatedWidgets: (state: State) => State;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { applyDefaultValues } from './apply-default-values';
|
|
2
2
|
export { calculateCurrentState } from './calculate-current-state';
|
|
3
3
|
export { calculateWidgetFlags } from './calculate-widget-flags';
|
|
4
4
|
export { calculateWidgetProps } from './calculate-widget-props';
|
|
5
|
+
export { dropRemovedWidgetEntries } from './drop-removed-widget-entries';
|
|
6
|
+
export { fillCalculatedWidgets } from './fill-calculated-widgets';
|
|
5
7
|
export { initialize } from './initialize';
|
|
6
8
|
export { injectValidationIssues } from './inject-validation-issues';
|
|
7
|
-
export { materializeRepeaterItems } from './materialize-repeater-items';
|
|
8
9
|
export { overrideWidgetProp } from './override-widget-prop';
|
|
9
|
-
export { removeWidget } from './remove-widget';
|
|
10
10
|
export { setData } from './set-data';
|
|
11
11
|
export { setFormHealth } from './set-form-health';
|
|
12
12
|
export { setLanguage } from './set-language';
|
|
@@ -1,3 +1,9 @@
|
|
|
1
1
|
import { OVERRIDE_WIDGET_PROP } from '../actions';
|
|
2
2
|
import { State } from '../model';
|
|
3
|
+
/**
|
|
4
|
+
* Stores a prop override for one widget, addressed by uid or by the path its input owns.
|
|
5
|
+
*
|
|
6
|
+
* The target is looked up in `resolvedSources`, not in `calculatedWidgets`, so a hidden widget can
|
|
7
|
+
* be addressed too. The props pass applies the stored value on the derive that reveals it.
|
|
8
|
+
*/
|
|
3
9
|
export declare const overrideWidgetProp: (state: State, { payload }: OVERRIDE_WIDGET_PROP) => State;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { SET_WIDGET_DATA
|
|
1
|
+
import { SET_WIDGET_DATA } from '../actions';
|
|
2
2
|
import { State } from '../model';
|
|
3
|
-
export declare const setWidgetData: (state: State, action: SET_WIDGET_DATA
|
|
3
|
+
export declare const setWidgetData: (state: State, action: SET_WIDGET_DATA) => State;
|