@golemui/core 1.0.3 → 1.1.1-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -0
- package/index.d.ts +2 -1
- package/index.js +1106 -1061
- package/index.umd.cjs +7 -7
- package/internals.d.ts +1 -2
- package/lib/context/form.context.d.ts +2 -2
- package/lib/context/widget-registry.d.ts +3 -1
- package/lib/context/with-widget.type.d.ts +4 -1
- package/lib/form-store.d.ts +2 -2
- package/lib/form.d.ts +9 -1
- package/lib/shared.d.ts +43 -2
- package/lib/store/model.d.ts +31 -1
- package/lib/store/reducer.d.ts +3 -2
- package/lib/store/reducers/calculate-current-state.d.ts +2 -1
- package/lib/store/reducers/calculate-widget-flags.d.ts +2 -1
- package/lib/store/reducers/calculate-widget-props.d.ts +2 -1
- package/lib/store/reducers/index.d.ts +1 -0
- package/lib/store/reducers/materialize-repeater-items.d.ts +10 -0
- package/lib/utils/deterministic-uids.d.ts +19 -0
- package/lib/utils/justin.d.ts +15 -2
- package/lib/utils/repeater.d.ts +31 -7
- package/package.json +1 -1
package/index.umd.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const 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 rr=class{value;constructor(e){this.value=e}map(e){return k(e(this.value))}isOk(){return!0}},nr=class yt{issues;constructor(t){this.issues=t}map(t){return new yt(this.issues)}isOk(){return!1}};function k(e){return new rr(e)}function C(e){return new nr(e)}function At(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:`${At(t.path)}: ${t.message}`).join("; ")}var D=class Fe{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 Fe(r=>{let n=this.decodeFn(r);return n.isOk()?k(t(n.value)):C(n.issues)})}flatMap(t){return new Fe(r=>{let n=this.decodeFn(r);return n.isOk()?t(n.value).decode(r):C(n.issues)})}},K=(e,t)=>[{message:`${JSON.stringify(e)} is not a valid ${t}`,path:[]}],_e=(e,t)=>e.map(r=>({...r,path:[t,...r.path]}));function Ve(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(..._e(i.issues,o))}return n.length>0?C(n):k(r)}else return C(K(t,"array"))})}function or(){return new D(e=>typeof e=="boolean"?k(e):C(K(e,"boolean")))}function ir(e,t){return new D(r=>{if(typeof r!="object"||!r)return C(K(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 $t(e){return new D(t=>e().decode(t))}function J(e){return new D(t=>t===e?k(e):C([{message:`${JSON.stringify(t)} is not exactly ${JSON.stringify(e)}`,path:[]}]))}function $e(){return new D(e=>typeof e=="number"?k(e):C(K(e,"number")))}function re(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(..._e(i.issues,o))}return n.length>0?C(n):k(r)}else return C(K(t,"object"))})}function Q(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:[]},...sr(r)])})}function sr(e){let t=new Map;for(let r of e)for(let n of r){let o=JSON.stringify(n.path),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 A(e){return new D(t=>t===void 0?k(void 0):e.decode(t))}function dr(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(..._e(i.issues,o))}return n.length>0?C(n):k(r)}else return C(K(t,"object"))})}function w(){return new D(e=>typeof e=="string"?k(e):C(K(e,"string")))}function G(){return new D(e=>k(e))}function ne(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,u]of Object.entries(t))if(s.startsWith(n+".")){const c=o.decoder.decode(u);if(!c.isOk())return C(c.issues.map(l=>({message:l.message,path:[s,...l.path]})));r[s]=c.value}}}return k(r)})}const Le=()=>crypto.randomUUID().slice(0,8),ur=e=>typeof e!="function"&&e.kind==="display",Y=e=>typeof e!="function"&&e.kind==="action",I=e=>typeof e!="function"&&e.kind==="input",ae=e=>typeof e!="function"&&e.kind==="layout",oe=e=>typeof e=="function",cr=re({in:Ve(w())}),Re=re({when:w()}),Se=Q([cr,Re]),lr=re({from:Ve(w())}),ve=Q([lr,Re]),je=Q([or(),Re]),ar=new D(e=>{const t=typeof e;return t==="function"?k(e):C([{message:`Expected a function, got '${t}'`,path:[]}])}),V=e=>Q([e,ar]),Me=ne({load:{suffixed:!0,decoder:V(A(w()))},click:{suffixed:!0,decoder:V(A(w()))},change:{suffixed:!0,decoder:V(A(w()))},filter:{suffixed:!0,decoder:V(A(w()))},blur:{suffixed:!0,decoder:V(A(w()))}}),fr=re({key:w(),default:A(w()),params:A(G())}),St=Q([w(),fr]),Be=A(w()).map(e=>e||Le()),pr=ne({kind:{decoder:J("display")},uid:{decoder:Be},type:{decoder:w()},size:{suffixed:!0,decoder:A($e())},include:{decoder:A(Se)},exclude:{decoder:A(ve)},props:{decoder:A(G())}}),hr=ne({kind:{decoder:J("action")},uid:{decoder:Be},type:{decoder:w()},actionType:{decoder:A(Q([J("button"),J("submit")]))},size:{suffixed:!0,decoder:A($e())},include:{decoder:A(Se)},exclude:{decoder:A(ve)},label:{suffixed:!0,decoder:V(A(St))},disabled:{suffixed:!0,decoder:A(je)},on:{decoder:A(Me)},props:{decoder:A(G())}}),mr=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=n.uid||Le(),r.type=n.type,r.path=n.path,k(r)}else return C([{message:`Expected a function, got '${t}'`,path:[]}])}),gr=ne({kind:{decoder:J("input")},uid:{decoder:A(w())},type:{decoder:w()},size:{suffixed:!0,decoder:A($e())},include:{decoder:A(Se)},exclude:{decoder:A(ve)},disabled:{suffixed:!0,decoder:A(je)},readonly:{suffixed:!0,decoder:A(je)},on:{decoder:A(Me)},props:{decoder:A(G())},label:{suffixed:!0,decoder:V(A(St))},path:{decoder:w()},defaultValue:{decoder:A(G())},validator:{suffixed:!0,decoder:V(A(G()))}}).map(e=>{const t={...e};if(e.uid||(t.uid=`${e.path}-${e.type}`),e.type==="repeater"){const r=e.props;r.template=He.parse(r.template)}return t}),yr=$t(()=>{const e=ir("kind",{input:gr,layout:He,display:pr,action:hr});return new D(t=>typeof t=="function"?mr.decode(t):e.decode(t))}),He=ne({kind:{decoder:J("layout")},uid:{decoder:Be},type:{decoder:w()},size:{suffixed:!0,decoder:A($e())},include:{decoder:A(Se)},exclude:{decoder:A(ve)},props:{decoder:A(G())},on:{decoder:A(Me)},children:{decoder:Ve(yr)}}),B=class B{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(!B.sharedCache.has(r)){const n=r().catch(o=>(B.sharedCache.delete(r),Promise.reject(o)));B.sharedCache.set(r,n)}return B.sharedCache.get(r)}};B.sharedCache=new Map;let We=B;function Ar(e){return{...e,form:{uid:"",type:"flex",kind:"layout",children:e.form}}}const vt=re({states:A(dr(w())),form:$t(()=>He)}),Et=e=>({formName:"",formDef:vt.parse({form:{kind:"layout",type:"flex",children:[]}}),flatForm:{},currentStates:[],calculatedWidgets:{},validations:{},touchedControls:{},injectedValidations:{},isFormValid:!0,widgetFlags:{},widgetPropOverrides:{},data:{},meta:{},formHealth:{status:"ok"},touched:!1,lang:e}),$r=e=>!(typeof e!="object"||e===null||typeof e.key!="string");function Sr(e){const t=new Intl.Locale(e).maximize().script;return["Arab","Hebr","Thaa","Syrc","Tfng","Adlm","Rohg"].includes(t||"")?"rtl":"ltr"}const Ct=(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))}}},vr=e=>{throw new Error(`Unhandled case: ${JSON.stringify(e)}`)};function W(e,...t){return t.reduce((r,n)=>n(r),e)}function Er(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.touched&&I(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},ie=(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)},Ge=(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 u=n[s],c=n[s+1];(o[u]==null||typeof o[u]!="object")&&(o[u]=wr(c)?[]:{}),o=o[u]}const i=n[n.length-1];return o[i]=r,e},Cr=(e,t)=>{if(t==="")return e;const r=t.split("."),n=[e];for(let s=0;s<r.length-1;s++){const u=n[s];if(u==null||typeof u!="object")return e;const c=r[s],l=Array.isArray(u)?u[parseInt(c,10)]:u[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 u=n[s];if(Array.isArray(u)||!Or(u))break;const c=n[s-1],l=r[s-1];if(Array.isArray(c))break;delete c[l]}return e};function wr(e){const t=Number(e);return Number.isInteger(t)&&t>=0&&t.toString()===e}function Or(e){return e!=null&&typeof e=="object"&&!Array.isArray(e)&&Object.keys(e).length===0}const Ee=(e,t)=>(delete e[t],e);function fe(e){if(e===null||typeof e!="object")return e;if(Array.isArray(e))return e.map(r=>fe(r));const t={};for(const r of Object.keys(e))t[r]=fe(e[r]);return t}function be(e){return e.flatMap(t=>[t,...ae(t)?be(t.children):[]])}function Ke(e){return Object.entries(e.validations).reduce((r,[n,o])=>(o!==null&&(r.$formIsInvalid=!0,Ge(r.$errors,n,[...o])),r),{$formIsInvalid:!1,$errors:{}})}function Oe(e){const t=fe(e.data);for(const[r,n]of Object.entries(e.widgetFlags))if(n.hidden===!0){const o=e.flatForm[r];o&&I(o)&&Cr(t,o.path)}return t}const ze=32;let Pe,h,y,$=e=>(h=0,y=e,$.newline=!1,e=v(),y[h]?z():e||""),z=(e="Unexpected token",t=h,r=y.slice(0,t).split(`
|
|
2
|
-
`),n=r.pop(),o=y.slice(Math.max(0,t-40),t),i="̭",s=(y[t]||" ")+i,
|
|
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 st(e){return e.map(t=>t.path.length===0?t.message:`${$t(t.path)}: ${t.message}`).join("; ")}var D=class We{decodeFn;constructor(t){this.decodeFn=t}parse(t){let r=this.decode(t);if(r.isOk())return r.value;{let n=r;throw Error(st(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(st(i.issues),{cause:i.issues}))}})}map(t){return new We(r=>{let n=this.decodeFn(r);return n.isOk()?T(t(n.value)):C(n.issues)})}flatMap(t){return new We(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:[]}],_e=(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(..._e(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 ye(){return new D(e=>typeof e=="number"?T(e):C(H(e,"number")))}function ne(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(..._e(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(..._e(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 oe(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(a=>({message:a.message,path:[s,...a.path]})));r[s]=c.value}}}return T(r)})}const St=()=>crypto.randomUUID().slice(0,8),ar=e=>typeof e!="function"&&e.kind==="display",ce=e=>typeof e!="function"&&e.kind==="action",W=e=>typeof e!="function"&&e.kind==="input",ee=e=>typeof e!="function"&&e.kind==="layout",z=e=>typeof e=="function",lr=ne({in:Le(I())}),Re=ne({when:I()}),$e=J([lr,Re]),fr=ne({from:Le(I())}),Ae=J([fr,Re]),Te=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]),Ve=oe({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=ne({key:I(),default:$(I()),params:$(M())}),vt=J([I(),hr]),Me=$(I()),mr=oe({kind:{decoder:X("display")},uid:{decoder:Me},type:{decoder:I()},size:{suffixed:!0,decoder:$(ye())},include:{decoder:$($e)},exclude:{decoder:$(Ae)},props:{decoder:$(M())}}),gr=oe({kind:{decoder:X("action")},uid:{decoder:Me},type:{decoder:I()},actionType:{decoder:$(J([X("button"),X("submit")]))},size:{suffixed:!0,decoder:$(ye())},include:{decoder:$($e)},exclude:{decoder:$(Ae)},label:{suffixed:!0,decoder:U($(vt))},disabled:{suffixed:!0,decoder:$(Te)},on:{decoder:$(Ve)},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=oe({kind:{decoder:X("input")},uid:{decoder:$(I())},type:{decoder:I()},size:{suffixed:!0,decoder:$(ye())},include:{decoder:$($e)},exclude:{decoder:$(Ae)},disabled:{suffixed:!0,decoder:$(Te)},readonly:{suffixed:!0,decoder:$(Te)},on:{decoder:$(Ve)},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:Be.parse(r.template)}}return t}),Ar=At(()=>{const e=dr("kind",{input:$r,layout:Be,display:mr,action:gr});return new D(t=>typeof t=="function"?yr.decode(t):e.decode(t))}),Be=oe({kind:{decoder:X("layout")},uid:{decoder:Me},type:{decoder:I()},size:{suffixed:!0,decoder:$(ye())},include:{decoder:$($e)},exclude:{decoder:$(Ae)},props:{decoder:$(M())},on:{decoder:$(Ve)},children:{decoder:Le(Ar)}}),V=class V{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(!V.sharedCache.has(r)){const n=r().catch(o=>(V.sharedCache.delete(r),Promise.reject(o)));V.sharedCache.set(r,n)}return V.sharedCache.get(r)}};V.sharedCache=new Map;let ke=V;function Sr(e){Fe(e,"#0")}function Fe(e,t){if(!z(e)&&(e.uid||(e.uid=t),ee(e)&&e.children.forEach((r,n)=>{Fe(r,`${t}.${n}`)}),W(e)&&e.type==="repeater")){const r=e.props?.template;r&&Fe(r,`${t}.t`)}}function vr(e){return{...e,form:{uid:"",type:"flex",kind:"layout",children:e.form}}}const Et=ne({states:$(cr(I())),form:At(()=>Be)}).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,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 j(e,...t){return t.reduce((r,n)=>n(r),e)}const P=(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)},He=(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],a=Array.isArray(d)?d[parseInt(c,10)]:d[c];if(a==null||typeof a!="object")return e;n.push(a)}const o=n[n.length-1],i=r[r.length-1];Array.isArray(o)?o.splice(parseInt(i,10),1):delete o[i];for(let s=n.length-1;s>=1;s--){const d=n[s];if(Array.isArray(d)||!Wr(d))break;const c=n[s-1],a=r[s-1];if(Array.isArray(c))break;delete c[a]}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 Se=(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.touched&&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 ze(e){return e.flatMap(t=>[t,...ee(t)?ze(t.children):[]])}function Ge(e){return Object.entries(e.validations).reduce((r,[n,o])=>(o!==null&&(r.$formIsInvalid=!0,He(r.$errors,n,[...o])),r),{$formIsInvalid:!1,$errors:{}})}function Ie(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 be=32;let je,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=y.slice(Math.max(0,t-40),t),i="̭",s=(y[t]||" ")+i,d=y.slice(t+1,t+20))=>{throw SyntaxError(`${e} at ${r.length+1}:${n.length+1}
|
|
3
3
|
${y[t-41]!==`
|
|
4
|
-
`,""+o}${s}${
|
|
5
|
-
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},kt=e=>(t,r,n="")=>{if(!(t
|
|
6
|
-
`,"/*":"*/"};let
|
|
7
|
-
`)for(;y.charCodeAt(n)>=
|
|
8
|
-
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},pt=()=>{const e=[];for(let t="",r;(r=y.charCodeAt(h))!==Ae;)r?r===An?(O(),t+=$n[y[h]]||y[h],O()):r===gn&&y.charCodeAt(h+1)===yn?(t&&e.push([,t]),t="",O(2),e.push(v(0,125))):(t+=y[h],O(),r=y.charCodeAt(h),r===Ae&&t&&e.push([,t])):z("Unterminated template");return O(),e},Sn=j[Ae];j[Ae]=(e,t)=>e&&t<mn?$.asi&&$.newline?void 0:(O(),["``",e,...pt()]):e?Sn?.(e,t):(O(),(r=>r.length<2&&r[0]?.[0]===void 0?r[0]||[,""]:["`",...r])(pt()));a("`",(...e)=>(e=e.map(d),t=>e.map(r=>r(t)).join("")));a("``",(e,...t)=>{e=d(e);const r=[],n=[];for(const i of t)Array.isArray(i)&&i[0]===void 0?r.push(i[1]):n.push(d(i));const o=Object.assign([...r],{raw:r});return i=>e(i)(o,...n.map(s=>s(i)))});$.string["'"]=!0;$.number={"0x":16,"0b":2,"0o":8};const vn={log:(e,t)=>(t?console.log(t,e):console.log(e),e)};function N(e,t,r,n,o){const i=$(nt(e));return d(i)({$form:t,$meta:r,$errors:n,$formIsInvalid:o,$log:vn.log})===!0}function nt(e){return e.replace(/\?\.(\d+)/g,"?.[$1]").replace(/\.(\d+)/g,"[$1]")}const U=e=>{let t=e.formDef.states;if(!t||Object.keys(t).length===0||e.formHealth.status==="errored")return e;const{$formIsInvalid:r,$errors:n}=Ke(e);t=En(t);let o=[],i={status:"ok"};try{o=Object.keys(t).map(s=>{const u=t[s];let c;try{c=N(u,e.data,e.meta,n,r)}catch{c=!1}return c===!0?s:void 0}).filter(s=>s!==void 0)}catch(s){const u=s,c=b.calculateCurrentStateError;i={status:"errored",message:`[${c}] ${u.message}`,code:c}}return{...e,currentStates:o,formHealth:i}};function En(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 u of i)e[u]&&s.push(`(${e[u]})`);t[n]=s.join(" && ")}return t}const ot=Symbol("filterMap.skip");function Kt(e,t){const r=[];for(let n=0;n<e.length;n++){const o=t(e[n],n,e);o!==ot&&r.push(o)}return r}function Cn(e,t,r){for(let n=0;n<e.length;n++)t(e[n],n,e)&&r(e[n],n,e)}function wn(e,t,r,n){let o=n;for(let i=0;i<e.length;i++)t(e[i],i,e)&&(o=r(o,e[i],i,e));return o}function On(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}function zt(e,t){const r=Xt(e.uid,t);return I(e)?{...e,uid:r,path:In(e.path,t)}:{...e,uid:r}}function Xt(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 In(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,u)=>u===0?s:`${i}.${t[u-1]}${s}`)}function ue(e,t){let r=0;return e.replace(/\.items(\??)\./g,(n,o)=>{const i=t[r++];return i===void 0?n:`.${i}${o}.`})}const ce=(e,t)=>r=>e(r)?t(r):r,H=e=>e!==void 0&&typeof e=="object"&&e!==null&&"when"in e,_=e=>{const{$formIsInvalid:t,$errors:r}=Ke(e);return{...e,widgetFlags:{...Dn(e,r,t),...Tn(e,r,t)}}};function Dn(e,t,r){return Kt(Object.values(e.flatForm),n=>{if(n.uid?.includes("["))return ot;if(oe(n)){const o=n({$form:e.data,errors:void 0,touched:void 0,translate:void 0});return o.uid=n.uid,o}return n}).filter(n=>!!(n.include&&("in"in n.include||"when"in n.include)||n.exclude&&("from"in n.exclude||"when"in n.exclude)||(I(n)||Y(n))&&H(n.disabled)||I(n)&&H(n.readonly))).reduce((n,o)=>(n[o.uid]=n[o.uid]||{},o.include&&"in"in o.include?n[o.uid].hidden=!o.include.in.some(i=>e.currentStates.includes(i)):o.include&&"when"in o.include&&(n[o.uid].hidden=!N(o.include.when,e.data,e.meta,t,r)),o.exclude&&"from"in o.exclude?n[o.uid].hidden=o.exclude.from.some(i=>e.currentStates.includes(i)):o.exclude&&"when"in o.exclude&&(n[o.uid].hidden=N(o.exclude.when,e.data,e.meta,t,r)),(I(o)||Y(o))&&H(o.disabled)&&(n[o.uid].disabled=N(o.disabled.when,e.data,e.meta,t,r)),I(o)&&H(o.readonly)&&(n[o.uid].readonly=N(o.readonly.when,e.data,e.meta,t,r)),n),{})}function Tn(e,t,r){return wn(Object.values(e.flatForm),n=>!oe(n)&&n.type==="repeater",(n,o)=>({...n,...Jt(e,o,[],t,r)}),{})}function Jt(e,t,r,n,o){const i=t.props.template,s=ie(e.data,t.path);if(!Array.isArray(s))return{};const u={};return s.forEach((c,l)=>{const g=[...r,l];be([i]).forEach(m=>{let f;if(oe(m)?(f=m({$form:e.data,errors:void 0,touched:void 0,translate:void 0}),f.uid=m.uid):f=m,f.type==="repeater"){const Z=zt(f,g);Object.assign(u,Jt(e,Z,g,n,o));return}const T=Xt(f.uid,g);u[T]=u[T]||{},f.include&&"in"in f.include?u[T].hidden=!f.include.in.some(Z=>e.currentStates.includes(Z)):f.include&&"when"in f.include&&(u[T].hidden=!N(ue(f.include.when,g),e.data,e.meta,n,o)),f.exclude&&"from"in f.exclude?u[T].hidden=f.exclude.from.some(Z=>e.currentStates.includes(Z)):f.exclude&&"when"in f.exclude&&(u[T].hidden=N(ue(f.exclude.when,g),e.data,e.meta,n,o)),(I(f)||Y(f))&&H(f.disabled)&&(u[T].disabled=N(ue(f.disabled.when,g),e.data,e.meta,n,o)),I(f)&&H(f.readonly)&&(u[T].readonly=N(ue(f.readonly.when,g),e.data,e.meta,n,o))})}),u}const P=e=>t=>{try{return{...t,calculatedWidgets:kn(t,e)}}catch(r){const n=r;return{...t,formHealth:{status:"errored",message:`[${n.code}] ${n.message}`,code:n.code}}}};function kn(e,t){const{$formIsInvalid:r,$errors:n}=Ke(e),o=Jn(e,t,r,n),i={};for(const s of Object.keys(e.calculatedWidgets)){if(e.widgetFlags[s]?.hidden)continue;const u=e.calculatedWidgets[s],c=u.source;if(oe(c)){i[s]=Fn(s,c,e,t);continue}i[s]=jn(u,c,e,o)}return i}function Fn(e,t,r,n){const o=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});return o.uid=e,{source:t,current:o}}function jn(e,t,r,n){const o=new Xn(t,e.current);return o.write("uid",t.uid),o.write("type",t.type),o.write("kind",t.kind),ur(t)?Wn(o,n):Y(t)?Pn(o,n):I(t)?Nn(o,n):ae(t)&&Un(o,n),_n(t,o,n,r),(Y(t)||I(t))&&Vn(t,o,n),ae(t)&&Ln(t,o,r),o.changed?{source:e.source,current:o.current}:e}function Wn(e,t){E(e,t,"size"),E(e,t,"include"),E(e,t,"exclude")}function Pn(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 Nn(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 Un(e,t){E(e,t,"size"),E(e,t,"include"),E(e,t,"exclude")}function _n(e,t,r,n){const o=n.widgetPropOverrides[e.uid]??{},i={...e.props??{},...o};for(const s of xt(Object.keys(i)))Rn(t,r,s)}function Vn(e,t,r){const n=e.on??{};for(const o of xt(Object.keys(n)))Mn(t,r,o)}function Ln(e,t,r){const n=xn(e.uid),o=qn(e.children,n,r.widgetFlags);t.current.children=o;const i=t.previous.children??[];i.length===o.length&&o.every((u,c)=>i[c]&&i[c].uid===o[c].uid)||t.markChanged()}function E(e,t,r){const n=e.source;if(!Qn(n,r))return;const o=st(n,r,t.sortedStates);let i;switch(r){case"disabled":case"readonly":i=Gn(o,t,e.source.uid,r);break;case"defaultValue":i=o;break;default:i=qt(o,t)}e.write(r,i)}function Rn(e,t,r){const n=e.source.props,o=st(n,r,t.sortedStates);let i=qt(o,t);const s=t.widgetPropOverrides[e.source.uid]?.[r];s!==void 0&&(i=s),e.write(`props.${r}`,i)}function Mn(e,t,r){const n=e.source.on,o=st(n,r,t.sortedStates);e.write(`on.${r}`,bn(o,t))}function it(e,t){return e({$form:t.$form,translate:t.localization.translate})}function Bn(e,t){return t.localization.translate(e.key,zn(e.params,t),e.default)}const Hn=/\{\{([^}]+)\}\}/g;function Qt(e,t){return e.includes("{{")?e.replace(Hn,(r,n)=>{const o=nt(n.trim());try{const i=d($(o))({$form:t.$form,$meta:t.$meta,$errors:t.$errors,$formIsInvalid:t.$formIsInvalid});return i==null?"":String(i)}catch(i){const s=i instanceof Error?i.message:String(i);throw new Zt(`Failed to evaluate '{{${n.trim()}}}': ${s}`)}}):e}function qt(e,t){return typeof e=="function"?it(e,t):$r(e)?Bn(e,t):typeof e=="string"?Qt(e,t):e}function Gn(e,t,r,n){return typeof e=="function"?it(e,t):H(e)?t.widgetFlags[r]?.[n]:typeof e=="string"?Qt(e,t):e}function bn(e,t){return typeof e=="function"?it(e,t):e}function st(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 Kn(e){return e.startsWith("$form")||e.startsWith("$meta")||e.startsWith("$errors")||e==="$formIsInvalid"}function zn(e,t){return e&&Object.keys(e).reduce((r,n)=>{const o=String(e[n]);if(Kn(o))try{const i=d($(nt(o)))({$form:t.$form,$meta:t.$meta,$errors:t.$errors,$formIsInvalid:t.$formIsInvalid});r[n]=i??o}catch(i){const s=i instanceof Error?i.message:String(i);throw new Zt(`Failed to evaluate i18n param '${o}': ${s}`)}else r[n]=o;return r},{})}class Xn{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){Ge(this.current,t,r),ie(this.previous,t)!==r&&(this._changed=!0)}}function Jn(e,t,r,n){return{sortedStates:[...e.currentStates].sort((o,i)=>i.length-o.length),widgetPropOverrides:e.widgetPropOverrides,widgetFlags:e.widgetFlags,$form:e.data,$meta:e.meta,$formIsInvalid:r,$errors:n,localization:t}}function Qn(e,t){if(t in e)return!0;const r=`${t}.`;return Object.keys(e).some(n=>n.startsWith(r))}function xt(e){return Array.from(new Set(e.map(t=>t.split(".")[0])))}function qn(e,t,r){const n=t.map(o=>`[${o}]`).join("");return e.filter(o=>{const i=o.uid+n,s=r[i];return!s||s.hidden!==!0})}const xn=e=>[...e.matchAll(/\[(\d+)\]/g)].map(t=>parseInt(t[1],10));class Zt extends Error{constructor(){super(...arguments),this.code=b.resolveStringInterpolationError,this.name="StringInterpolationError"}}const Zn=({lang:e},t)=>{const r={...Et(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 g=l,m=b.initializeParseError;o={status:"errored",message:`[${m}] ${g.message}`,code:m}}if(o.status==="errored")return{...r,formHealth:o}}if(Array.isArray(n.form)){const l=n,g=l.form;l.form={uid:"",type:"flex",kind:"layout",children:g}}const i=vt.decode(n);if(i.isOk()){o={status:"ok"};let l={};try{l=be([i.value.form]).reduce((g,m)=>{const f=m.uid;if(g[f])throw{existingWidget:g[f],newWidget:m};return g[f]=m,g},{})}catch(g){o=to(g.existingWidget,g.newWidget),l={}}return ro(l,i.value.states),{...r,formDef:i.value,flatForm:l,formHealth:o}}const s=eo(n);if(s)return{...r,formHealth:s};const u=b.initializeUnknownError,c=i.issues.map(l=>`${l.path.length>0?At(l.path):"root"}: ${l.message}`).join("; ");return{...r,formHealth:{status:"errored",message:`[${u}] ${c}`,code:u}}};function Yt(e,t){return{status:"errored",code:e,message:`[${e}] ${t}`}}function Yn(){return"Malformed form definition. Pass it directly as formDef - `config={{ formDef: { states, form: [...] } }}`. Do NOT wrap it in an extra `{ form: ... }`."}function eo(e){if(!e||typeof e!="object"||Array.isArray(e))return null;const t=e.form;return t&&typeof t=="object"&&!Array.isArray(t)&&!ae(t)?Yt(b.initializeMalformedFormShapeError,Yn()):null}function to(e,t){const r=o=>I(o)?` at "${o.path}"`:"",n=`Duplicate UID "${t.uid}": Assigned to widget "${e.type}"${r(e)} and "${t.type}"${r(t)}.`;return Yt(b.initializeUidCollisionError,n)}function ro(e,t){const r=new Set(Object.keys(t??{})),n=new Map;for(const i of Object.values(e)){const s=[],u=i.include;u&&Array.isArray(u.in)&&s.push(...u.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 g=n.get(l)??[];g.push(i.uid||"(unknown)"),n.set(l,g)}}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 no(e,t){return{...e,injectedValidations:{...e.injectedValidations,[t.payload.path]:t.payload.issues}}}const oo=(e,{payload:t})=>{let r;if("path"in t){if(r=Object.values(e.calculatedWidgets).find(({source:i})=>I(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 io(e,t){return W(e,so(t),uo(t),co(t),lo(t))}const so=e=>t=>({...t,widgetFlags:{...Ee(t.widgetFlags,e.payload.uid)}}),uo=e=>t=>({...t,calculatedWidgets:{...Ee(t.calculatedWidgets,e.payload.uid)}}),co=e=>t=>({...t,widgetPropOverrides:{...Ee(t.widgetPropOverrides,e.payload.uid)}}),lo=e=>t=>({...t,touchedControls:W(t.touchedControls,r=>{const n=t.flatForm[e.payload.uid];return n&&I(n)?Ee(r,n.path):r})}),ao=(e,t)=>({...e,data:{...t.payload.data}}),fo=(e,t)=>({...e,formHealth:t.payload.formHealth}),po=(e,t)=>({...e,lang:t.payload.lang}),ho=(e,t)=>({...e,meta:{...t.payload.meta}}),mo=(e,t)=>{const r=ie(e.data,t.payload.path);return t.type==="SET_WIDGET_DATA"||t.type==="SET_WIDGET_INITIAL_DATA"&&r===void 0?{...e,data:{...Ge(e.data,t.payload.path,t.payload.data)}}:e},Te=(e,t)=>r=>{const n=Kt(Object.values(r.calculatedWidgets),({current:i})=>I(i)?i:ot),o=r.validations;return{...r,validations:n.reduce((i,s)=>{if(i[s.path]=null,s.validator){const u=e(s.validator,t),c=ie(r.data,s.path),l=mt(u,c);i[s.path]=gt(l)?null:l.issues.map(g=>g.message)}return Array.isArray(i[s.path])&&Array.isArray(o[s.path])&&On(i[s.path],o[s.path],(u,c)=>u===c)&&(i[s.path]=o[s.path]),i},{})}},go=({validators:e,validateOn:t,localization:r})=>(n,o)=>{switch(o.type){case"INITIALIZE":return Zn(n,o);case"SET_DATA":return W(ao(n,o),U,_,P(r));case"SET_META":return W(ho(n,o),U,_,P(r));case"SET_LANGUAGE":return W(po(n,o),P(r));case"ADD_WIDGET":return W(Er(n,o),ce(ke,U),ce(ke,_),ce(ke,P(r)));case"REMOVE_WIDGET":return W(io(n,o),U,_,P(r));case"SET_WIDGET_INITIAL_DATA":case"SET_WIDGET_DATA":return W(mo(n,o),U,_,P(r));case"OVERRIDE_WIDGET_PROP":return W(oo(n,o),U,_,P(r),ce(i=>{let s=!1,u="";"path"in o.payload?(s=!0,u=o.payload.path):I(i.calculatedWidgets[o.payload.uid].current)&&(s=!0,u=i.calculatedWidgets[o.payload.uid].current.path);const c=s&&i.touchedControls[u];return i.touched&&c},Te(e,r)));case"SET_FORM_HEALTH":return fo(n,o);case"VALIDATE_ALL":return W({...n,touched:!0,touchedControls:Object.keys(n.calculatedWidgets).reduce((i,s)=>{const u=n.calculatedWidgets[s].source;return I(u)&&(i[u.path]=!0),i},{})},Te(e,r),U,_,P(r),ht);case"ATTEMPT_VALIDATION":{const i=o.payload.reason,s=o.payload.path;return t==="eager"||i===t||t.includes(i)?W({...n,touched:!0,touchedControls:{...n.touchedControls,[s]:!0}},Te(e,r),U,_,P(r),c=>{const l=o.payload.uid,g=c.calculatedWidgets[l],m=g.source;if(oe(m)){const f=m({$form:c.data,errors:c.validations[s],touched:!0,translate:r.translate});return{...c,calculatedWidgets:{...c.calculatedWidgets,[l]:{source:g.source,current:f}}}}return c},ht):n}case"INJECT_VALIDATION_ISSUES":return no(n,o);default:return vr(o)}},ke=e=>e.formHealth.status==="ok";function ht(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 yo(e=[],t,r,n){const o=new p.BehaviorSubject(Et(n.lang)),i=o.asObservable().pipe(p.distinctUntilChanged()),s=go({validators:t,validateOn:r,localization:n});function u(m){const f=o.getValue(),T=s(f,m);o.next(T)}let c=u;const l={getState:()=>o.getValue(),dispatch:m=>c(m)};return c=e.map(m=>m(l)).reduceRight((m,f)=>f(m),u),{state$:i,dispatch:c,getState:()=>o.getValue()}}class Ao{constructor(){this.widgetRegistry=new We,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=Ct(),u){this.localization=s,this.dependencies=u,this.widgetRegistry.setWidgetLoaders(t),this.itemRenderers=i,this.store=yo(r,n,o,s)}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 u=r.on?.[`${t}.${s}`];this.attemptValidation(t,r),u&&this.events$.next({name:u,data:Oe(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:Oe(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:Oe(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 $o(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 So=p.pipe(p.map(e=>e.data),p.distinctUntilChanged()),vo=e=>p.pipe(So,p.map(t=>ie(t,e)),p.distinctUntilChanged()),Eo=p.pipe(p.filter(e=>e.touched===!0),p.map(e=>e.validations),p.distinctUntilChanged()),Co=e=>p.pipe(Eo,p.map(t=>t[e]),p.distinctUntilChanged()),wo=p.pipe(p.filter(e=>e.touched===!0),p.map(e=>e.injectedValidations),p.distinctUntilChanged()),Oo=e=>p.pipe(wo,p.map(t=>t[e]),p.distinctUntilChanged(),p.startWith(null)),Io=p.pipe(p.map(e=>e.lang),p.distinctUntilChanged()),er=p.pipe(p.map(e=>e.calculatedWidgets),p.distinctUntilChanged()),Do=e=>t=>p.combineLatest([t.pipe(Io),t.pipe(er)]).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)),To=e=>p.pipe(er,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 ko=p.pipe(p.map(e=>e.touchedControls),p.distinctUntilChanged()),Fo=e=>p.pipe(ko,p.map(t=>t[e]),p.distinctUntilChanged()),jo=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)),Wo=e=>e.pipe(jo);let tr=!1;function Po(){tr=!0}function No(){return tr}function Uo(e,t,r){if(!No())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=Ao;exports.assertNoPropCollisions=Uo;exports.calculatedLayoutChildrenByUid$=To;exports.calculatedWidgetsByUid$=Do;exports.cloneObject=fe;exports.dataByPath$=vo;exports.defineForm=Ar;exports.devToolsMiddleware=$o;exports.enableDevMode=Po;exports.errorCodes=b;exports.filterTap=Cn;exports.formHealth=Wo;exports.getDirectionFromLanguage=Sr;exports.identityTranslator=Ct;exports.injectedValidationByPath$=Oo;exports.isStandardValidateSuccess=gt;exports.makeRepeaterItemConfig=zt;exports.shortUUID=Le;exports.standardValidate=mt;exports.touchedControlsByPath$=Fo;exports.validationByPath$=Co;
|
|
4
|
+
`,""+o}${s}${d}`)},wt=(e,t=h)=>(Array.isArray(e)&&(e.loc=t),e),x=(e,t=h,r)=>{for(;r=e(y.charCodeAt(h));)h+=r;return y.slice(t,h)},w=(e=1)=>y[h+=e],Pe=e=>h=e,v=(e=0,t)=>{let r,n,o,i,s;for(t&&A.asi&&(A.newline=!1);(r=A.space())&&(s=A.newline,1)&&r!==t&&(o=(n&&r===91&&je&&A.asi?.(n,e,v)||null)??((i=F[r])&&i(n,e))??(n&&s&&A.asi?.(n,e,v))??(!n&&x(A.id)));)n=o;return t&&(r==t?(h++,t===125&&A.asi&&(A.newline=!0)):G("Unclosed "+String.fromCharCode(t-(t>42?2:1)))),n},L=(e,t=h)=>{for(je=!1;(e=y.charCodeAt(h))<=be;)A.asi&&e===10&&(A.newline=je=!0),h++;return e},kr=(e=h)=>{for(;y.charCodeAt(e)<=be;)e++;return y.charCodeAt(e)};A.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 Fr=(e,t=e.length)=>y.substr(h,t)===e&&!A.id(y.charCodeAt(h+t)),F=[],dt={},k=(e,t=be,r,n=e.charCodeAt(0),o=e.length,i=F[n],s=e.toUpperCase()!==e,d,c)=>(t=dt[e]=!i&&dt[e]||t,F[n]=(a,f,g,m=h)=>(d=g,(g?e==g:(o<2||e.charCodeAt(1)===y.charCodeAt(h+1)&&(o<3||y.substr(h,o)==e))&&(!s||!A.id(y.charCodeAt(h+o)))&&(d=g=e))&&f<t&&(h+=o,(c=r(a))?wt(c,m):(h=m,d=0,!s&&!i&&!a&&G()),c)||i?.(a,f,d))),S=(e,t,r=!1)=>k(e,t,n=>n&&(o=>o&&[e,n,o])(v(t-(r?.5:0)))),R=(e,t,r)=>k(e,t,n=>!n&&(n=v(t-.5))&&[e,n]),ie=(e,t)=>k(e,200,r=>!r&&[,t]),Ot=(e,t,r)=>k(e,t,(n,o)=>(o=v(t-(r?.5:0)),n?.[0]!==e&&(n=[e,n||null]),o?.[0]===e?n.push(...o.slice(1)):n.push(o||null),n)),Ke=(e,t)=>k(e[0],t,r=>!r&&[e,v(0,e.charCodeAt(1))||null]),Dt=(e,t)=>k(e[0],t,r=>r&&[e,r,v(0,e.charCodeAt(1))||null]),se=(e,t,r,n=e.charCodeAt(0),o=e.length,i=F[n],s)=>F[n]=(d,c,a,f=h)=>!d&&(a?e==a:(o<2||y.substr(h,o)==e)&&(a=e))&&c<t&&!A.id(y.charCodeAt(h+o))&&(!A.prop||A.prop(h+o))&&(Pe(h+o),(s=r())?wt(s,f):Pe(f),s)||i?.(d,c,a);Object.defineProperty(A,"space",{configurable:!0,enumerable:!0,get:()=>L,set:e=>L=e});const Ne={},l=(e,t,r=Ne[e])=>Ne[e]=(...n)=>t(...n)||r?.(...n),u=e=>Array.isArray(e)?e[0]==null?(t=>()=>t)(e[1]):Ne[e[0]]?.(...e.slice(1))??G(`Unknown operator: ${e[0]}`,e?.loc):e===void 0?()=>{}:t=>t?.[e],le=46,te=48,fe=57,jr=69,Pr=101,Nr=43,Ur=45,ue=95,Wt=110,_r=97,Lr=102,Rr=65,Vr=70,Tt=e=>e.indexOf("_")<0?e:e.replaceAll("_",""),Xe=e=>{let t=Tt(x(r=>r===le&&y.charCodeAt(h+1)!==le||r>=te&&r<=fe||r===ue||((r===jr||r===Pr)&&((r=y.charCodeAt(h+1))>=te&&r<=fe||r===Nr||r===Ur)?2:0)));return y.charCodeAt(h)===Wt?(w(),[,BigInt(t)]):(e=+t)!=e?G():[,e]},Mr={2:e=>e===48||e===49||e===ue,8:e=>e>=48&&e<=55||e===ue,16:e=>e>=te&&e<=fe||e>=_r&&e<=Lr||e>=Rr&&e<=Vr||e===ue};A.number=null;F[le]=e=>!e&&y.charCodeAt(h+1)!==le&&Xe();for(let e=te;e<=fe;e++)F[e]=t=>t?void 0:Xe();F[te]=e=>{if(e)return;const t=A.number;if(t){for(const[r,n]of Object.entries(t))if(r[0]==="0"&&y[h+1]?.toLowerCase()===r[1]){w(2);const o=Tt(x(Mr[n]));return y.charCodeAt(h)===Wt?(w(),[,BigInt("0"+r[1]+o)]):[,parseInt(o,n)]}}return Xe()};const Br=92,ut=34,ct=39,Hr={n:`
|
|
5
|
+
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},kt=e=>(t,r,n="")=>{if(!(t||!A.string?.[String.fromCharCode(e)]))return w(),x(o=>o-e&&(o===Br?(n+=Hr[y[h+1]]||y[h+1],2):(n+=y[h],1))),y[h]===String.fromCharCode(e)?w():G("Bad string"),[,n]};F[ut]=kt(ut);F[ct]=kt(ct);A.string={'"':!0};const zr=20;"= += -= *= /= %= |= &= ^= >>= <<=".split(" ").map(e=>S(e,zr,!0));const Ft=(e,t,r,n)=>typeof e=="string"?o=>t(o,e,o):e[0]==="."?(r=u(e[1]),n=e[2],o=>t(r(o),n,o)):e[0]==="[]"&&e.length===3?(r=u(e[1]),n=u(e[2]),o=>t(r(o),n(o),o)):e[0]==="()"&&e.length===2?Ft(e[1],t):(()=>{throw Error("Invalid assignment target")})(),at={"=":(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 at)l(e,(t,r)=>(r=u(r),Ft(t,(n,o,i)=>at[e](n,o,r(i)))));const Gr=30,br=40,Kr=140;R("!",Kr);S("||",Gr);S("&&",br);l("!",e=>(e=u(e),t=>!e(t)));l("||",(e,t)=>(e=u(e),t=u(t),r=>e(r)||t(r)));l("&&",(e,t)=>(e=u(e),t=u(t),r=>e(r)&&t(r)));const Xr=50,Jr=60,xr=70,jt=100,Qr=140;S("|",Xr);S("&",xr);S("^",Jr);S(">>",jt);S("<<",jt);R("~",Qr);l("~",e=>(e=u(e),t=>~e(t)));l("|",(e,t)=>(e=u(e),t=u(t),r=>e(r)|t(r)));l("&",(e,t)=>(e=u(e),t=u(t),r=>e(r)&t(r)));l("^",(e,t)=>(e=u(e),t=u(t),r=>e(r)^t(r)));l(">>",(e,t)=>(e=u(e),t=u(t),r=>e(r)>>t(r)));l("<<",(e,t)=>(e=u(e),t=u(t),r=>e(r)<<t(r)));const ve=90;S("<",ve);S(">",ve);S("<=",ve);S(">=",ve);l(">",(e,t)=>(e=u(e),t=u(t),r=>e(r)>t(r)));l("<",(e,t)=>(e=u(e),t=u(t),r=>e(r)<t(r)));l(">=",(e,t)=>(e=u(e),t=u(t),r=>e(r)>=t(r)));l("<=",(e,t)=>(e=u(e),t=u(t),r=>e(r)<=t(r)));const Pt=80;S("==",Pt);S("!=",Pt);l("==",(e,t)=>(e=u(e),t=u(t),r=>e(r)==t(r)));l("!=",(e,t)=>(e=u(e),t=u(t),r=>e(r)!=t(r)));const Nt=110,Je=120,Ut=140;S("+",Nt);S("-",Nt);S("*",Je);S("/",Je);S("%",Je);R("+",Ut);R("-",Ut);l("+",(e,t)=>t!==void 0?(e=u(e),t=u(t),r=>e(r)+t(r)):(e=u(e),r=>+e(r)));l("-",(e,t)=>t!==void 0?(e=u(e),t=u(t),r=>e(r)-t(r)):(e=u(e),r=>-e(r)));l("*",(e,t)=>(e=u(e),t=u(t),r=>e(r)*t(r)));l("/",(e,t)=>(e=u(e),t=u(t),r=>e(r)/t(r)));l("%",(e,t)=>(e=u(e),t=u(t),r=>e(r)%t(r)));const pe=150;k("++",pe,e=>e?["++",e,null]:["++",v(pe-1)]);k("--",pe,e=>e?["--",e,null]:["--",v(pe-1)]);const xe=(e,t,r,n)=>typeof e=="string"?o=>t(o,e):e[0]==="."?(r=u(e[1]),n=e[2],o=>t(r(o),n)):e[0]==="[]"&&e.length===3?(r=u(e[1]),n=u(e[2]),o=>t(r(o),n(o))):e[0]==="()"&&e.length===2?xe(e[1],t):(()=>{throw Error("Invalid increment target")})();l("++",(e,t)=>xe(e,t===null?(r,n)=>r[n]++:(r,n)=>++r[n]));l("--",(e,t)=>xe(e,t===null?(r,n)=>r[n]--:(r,n)=>--r[n]));const qr=5,Zr=10;Ot(",",Zr);Ot(";",qr,!0);const _t=(...e)=>(e=e.map(u),t=>{let r;for(const n of e)r=n(t);return r});l(",",_t);l(";",_t);const Yr=170;Ke("()",Yr);const _=e=>e?.[0]==="_"&&e[1]==="_"||e==="constructor"||e==="prototype",Qe=170;Dt("[]",Qe);S(".",Qe);Dt("()",Qe);const he=e=>{throw Error(e)};l("[]",(e,t)=>t===void 0?(e=e?e[0]===","?e.slice(1):[e]:[],e=e.map(r=>r==null?(()=>{}):r[0]==="..."?(r=u(r[1]),n=>r(n)):(r=u(r),n=>[r(n)])),r=>e.flatMap(n=>n(r))):(t==null&&he("Missing index"),e=u(e),t=u(t),r=>{const n=t(r);return _(n)?void 0:e(r)[n]}));l(".",(e,t)=>(e=u(e),t=t[0]?t:t[1],_(t)?()=>{}:r=>e(r)[t]));l("()",(e,t)=>{if(t===void 0)return e==null?he("Empty ()"):u(e);const r=o=>o?.[0]===","&&o.slice(1).some(i=>i==null||r(i));r(t)&&he("Empty argument");const n=t?t[0]===","?(t=t.slice(1).map(u),o=>t.map(i=>i(o))):(t=u(t),o=>[t(o)]):()=>[];return qe(e,(o,i,s)=>o[i](...n(s)))});const b=e=>typeof e=="string"||Array.isArray(e)&&(e[0]==="."||e[0]==="?."||e[0]==="[]"&&e.length===3||e[0]==="?.[]"||e[0]==="()"&&e.length===2&&b(e[1])||e[0]==="{}"),qe=(e,t,r,n)=>e==null?he("Empty ()"):e[0]==="()"&&e.length==2?qe(e[1],t):typeof e=="string"?o=>t(o,e,o):e[0]==="."?(r=u(e[1]),n=e[2],o=>t(r(o),n,o)):e[0]==="?."?(r=u(e[1]),n=e[2],o=>{const i=r(o);return i==null?void 0:t(i,n,o)}):e[0]==="[]"&&e.length===3?(r=u(e[1]),n=u(e[2]),o=>t(r(o),n(o),o)):e[0]==="?.[]"?(r=u(e[1]),n=u(e[2]),o=>{const i=r(o);return i==null?void 0:t(i,n(o),o)}):(e=u(e),o=>t([e(o)],0,o)),Q=qe,en=32,tn=A.space;A.comment??={"//":`
|
|
6
|
+
`,"/*":"*/"};let we;A.space=()=>{we||(we=Object.entries(A.comment).map(([o,i])=>[o,i,o.charCodeAt(0)]));for(var e;e=tn();){for(var t=0,r;r=we[t++];)if(e===r[2]&&y.substr(h,r[0].length)===r[0]){var n=h+r[0].length;if(r[1]===`
|
|
7
|
+
`)for(;y.charCodeAt(n)>=en;)n++;else{for(;y[n]&&y.substr(n,r[1].length)!==r[1];)n++;y[n]&&(n+=r[1].length)}Pe(n),e=0;break}if(e)return e}return e};const Lt=80;S("===",Lt);S("!==",Lt);l("===",(e,t)=>(e=u(e),t=u(t),r=>e(r)===t(r)));l("!==",(e,t)=>(e=u(e),t=u(t),r=>e(r)!==t(r)));const rn=30;S("??",rn);l("??",(e,t)=>(e=u(e),t=u(t),r=>e(r)??t(r)));const nn=130,on=20;S("**",nn,!0);S("**=",on,!0);l("**",(e,t)=>(e=u(e),t=u(t),r=>e(r)**t(r)));const sn=e=>{throw Error(e)};l("**=",(e,t)=>(b(e)||sn("Invalid assignment target"),t=u(t),Q(e,(r,n,o)=>r[n]**=t(o))));const Rt=90;S("in",Rt);S("of",Rt);l("in",(e,t)=>(e=u(e),t=u(t),r=>e(r)in t(r)));const dn=20,un=100,cn=e=>{throw Error(e)};S(">>>",un);S(">>>=",dn,!0);l(">>>",(e,t)=>(e=u(e),t=u(t),r=>e(r)>>>t(r)));l(">>>=",(e,t)=>(b(e)||cn("Invalid assignment target"),t=u(t),Q(e,(r,n,o)=>r[n]>>>=t(o))));const Ze=5,an=10,ln=20,fn=e=>e[0]?.[0]===","?e[0].slice(1):e,me=(e,t,r)=>{if(typeof e=="string"){r[e]=t;return}const[n,...o]=e,i=fn(o);if(n==="{}"){const s=[];for(const d of i){if(Array.isArray(d)&&d[0]==="..."){const m={};for(const O in t)s.includes(O)||(m[O]=t[O]);r[d[1]]=m;break}let c,a,f;typeof d=="string"?c=a=d:d[0]==="="?(typeof d[1]=="string"?c=a=d[1]:[,c,a]=d[1],f=d[2]):[,c,a]=d,s.push(c);let g=t[c];g===void 0&&f&&(g=u(f)(r)),me(a,g,r)}}else if(n==="[]"){let s=0;for(const d of i){if(d===null){s++;continue}if(Array.isArray(d)&&d[0]==="..."){r[d[1]]=t.slice(s);break}let c=d,a;Array.isArray(d)&&d[0]==="="&&([,c,a]=d);let f=t[s++];f===void 0&&a&&(f=u(a)(r)),me(c,f,r)}}},Vt=e=>{let t=v(an-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",Ze+1,()=>Vt("let"));se("const",Ze+1,()=>Vt("const"));se("var",Ze,()=>(L(),["var",v(ln)]));const Mt=(...e)=>(e=e.map(t=>{if(typeof t=="string")return r=>{r[t]=void 0};if(t[0]==="="){const[,r,n]=t,o=u(n);return typeof r=="string"?i=>{i[r]=o(i)}:i=>me(r,o(i),i)}return u(t)}),t=>{for(const r of e)r(t)});l("let",Mt);l("const",Mt);l("var",e=>typeof e=="string"?t=>{t[e]=void 0}:()=>{});const Ye=20,Ee=e=>{throw Error(e)};S("||=",Ye,!0);S("&&=",Ye,!0);S("??=",Ye,!0);l("=",(e,t)=>{if(Array.isArray(e)&&(e[0]==="let"||e[0]==="const"||e[0]==="var")){const r=e[1];return t=u(t),typeof r=="string"?n=>{n[r]=t(n)}:n=>me(r,t(n),n)}return b(e)||Ee("Invalid assignment target"),t=u(t),Q(e,(r,n,o)=>r[n]=t(o))});l("||=",(e,t)=>(b(e)||Ee("Invalid assignment target"),t=u(t),Q(e,(r,n,o)=>r[n]||=t(o))));l("&&=",(e,t)=>(b(e)||Ee("Invalid assignment target"),t=u(t),Q(e,(r,n,o)=>r[n]&&=t(o))));l("??=",(e,t)=>(b(e)||Ee("Invalid assignment target"),t=u(t),Q(e,(r,n,o)=>r[n]??=t(o))));ie("true",!0);ie("false",!1);ie("null",null);se("undefined",200,()=>[]);ie("NaN",NaN);ie("Infinity",1/0);const Oe=20;k("?",Oe,(e,t,r)=>e&&(t=v(Oe-1))&&x(n=>n===58)&&(r=v(Oe-1),["?",e,t,r]));l("?",(e,t,r)=>(e=u(e),t=u(t),r=u(r),n=>e(n)?t(n):r(n)));const pn=[],hn=20;S("=>",hn,!0);l("=>",(e,t)=>{e=e?.[0]==="()"?e[1]:e;const r=e?e[0]===","?e.slice(1):[e]:[];let n=-1,o=null;const i=r[r.length-1];Array.isArray(i)&&i[0]==="..."&&(n=r.length-1,o=i[1],r.length--);const s=t?.[0]==="{}";return t=u(s?["{",t[1]]:t),d=>(...c)=>{const a={};r.forEach((g,m)=>a[g]=c[m]),o&&(a[o]=c.slice(n));const f=new Proxy(a,{get:(g,m)=>m in g?g[m]:d?.[m],set:(g,m,O)=>((m in g?g:d)[m]=O,!0),has:(g,m)=>m in g||(d?m in d:!1)});try{const g=t(f);return s?void 0:g}catch(g){if(g===pn)return g[0];throw g}}});const mn=140;R("...",mn);l("...",e=>(e=u(e),t=>Object.entries(e(t))));const lt=170;k("?.",lt,(e,t)=>{if(!e)return;const r=L();return r===40?(w(),["?.()",e,v(0,41)||null]):r===91?(w(),["?.[]",e,v(0,93)]):(t=v(lt),t?["?.",e,t]:void 0)});l("?.",(e,t)=>(e=u(e),_(t)?()=>{}:r=>e(r)?.[t]));l("?.[]",(e,t)=>(e=u(e),t=u(t),r=>{const n=t(r);return _(n)?void 0:e(r)?.[n]}));l("?.()",(e,t)=>{const r=t?t[0]===","?(t=t.slice(1).map(u),o=>t.map(i=>i(o))):(t=u(t),o=>[t(o)]):()=>[];if(e[0]==="?."){const o=u(e[1]),i=e[2];return _(i)?()=>{}:s=>o(s)?.[i]?.(...r(s))}if(e[0]==="?.[]"){const o=u(e[1]),i=u(e[2]);return s=>{const d=o(s),c=i(s);return _(c)?void 0:d?.[c]?.(...r(s))}}if(e[0]==="."){const o=u(e[1]),i=e[2];return _(i)?()=>{}:s=>o(s)?.[i]?.(...r(s))}if(e[0]==="[]"&&e.length===3){const o=u(e[1]),i=u(e[2]);return s=>{const d=o(s),c=i(s);return _(c)?void 0:d?.[c]?.(...r(s))}}const n=u(e);return o=>n(o)?.(...r(o))});const re=140;R("typeof",re);R("void",re);R("delete",re);se("new",re,()=>Fr(".target")?(w(7),["new.target"]):["new",v(re)]);l("typeof",e=>(e=u(e),t=>typeof e(t)));l("void",e=>(e=u(e),t=>(e(t),void 0)));l("delete",e=>{if(e[0]==="."){const t=u(e[1]),r=e[2];return n=>delete t(n)[r]}if(e[0]==="[]"){const t=u(e[1]),r=u(e[2]);return n=>delete t(n)[r(n)]}return()=>!0});l("new",e=>{const t=u(e?.[0]==="()"?e[1]:e),r=e?.[0]==="()"?e[2]:null,n=r?r[0]===","?(o=>i=>o.map(s=>s(i)))(r.slice(1).map(u)):(o=>i=>[o(i)])(u(r)):()=>[];return o=>new(t(o))(...n(o))});const et=Symbol("accessor"),tt=20,gn=40,Bt=41,Ht=123,zt=125,Gt=e=>t=>{if(t)return;L();const r=x(A.id);if(!r||(L(),y.charCodeAt(h)!==gn))return!1;w();const n=v(0,Bt);return L(),y.charCodeAt(h)!==Ht?!1:(w(),[e,r,n,v(0,zt)])};k("get",tt-1,Gt("get"));k("set",tt-1,Gt("set"));k("(",tt-1,e=>{if(!e||typeof e!="string")return;const t=v(0,Bt)||null;if(L(),y.charCodeAt(h)===Ht)return w(),[":",e,["=>",["()",t],v(0,zt)||null]]});l("get",(e,t)=>(t=t?u(t):()=>{},r=>[[et,e,{get:function(){const n=Object.create(r||{});return n.this=this,t(n)}}]]));l("set",(e,t,r)=>(r=r?u(r):()=>{},n=>[[et,e,{set:function(o){const i=Object.create(n||{});i.this=this,i[t]=o,r(i)}}]]));const yn=20,bt=200;A.prop=e=>kr(e)!==58;const $n=e=>e==null||typeof e=="string"||[":",",","...","get","set"].includes(e[0]);Ke("[]",bt);Ke("{}",bt);S(":",yn-1,!0);l("{}",(e,t)=>{if(t!==void 0)return;if(!$n(e))return u(["{",e]);e=e?e[0]!==","?[e]:e.slice(1):[];const r=e.map(n=>u(typeof n=="string"?[":",n,n]:n));return n=>{const o={},i={};for(const s of r.flatMap(d=>d(n)))if(s[0]===et){const[,d,c]=s;i[d]={...i[d],...c,configurable:!0,enumerable:!0}}else o[s[0]]=s[1];for(const s in i)Object.defineProperty(o,s,i[s]);return o}});l("{",e=>(e=e?u(e):()=>{},t=>e(Object.create(t))));l(":",(e,t)=>(t=u(t),Array.isArray(e)?(e=u(e),r=>[[e(r),t(r)]]):r=>[[e,t(r)]]));const An=170,ge=96,Sn=36,vn=123,En=92,Cn={n:`
|
|
8
|
+
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},ft=()=>{const e=[];for(let t="",r;(r=y.charCodeAt(h))!==ge;)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===ge&&t&&e.push([,t])):G("Unterminated template");return w(),e},In=F[ge];F[ge]=(e,t)=>e&&t<An?A.asi&&A.newline?void 0:(w(),["``",e,...ft()]):e?In?.(e,t):(w(),(r=>r.length<2&&r[0]?.[0]===void 0?r[0]||[,""]:["`",...r])(ft()));l("`",(...e)=>(e=e.map(u),t=>e.map(r=>r(t)).join("")));l("``",(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 Z(e,t,r,n,o,i){const s=A(rt(e));return u(s)({$form:t,$meta:r,$errors:n,$formIsInvalid:o,$log:wn.log,$fn:{},...i})===!0}function rt(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}=Ge(t);r=Wn(r);let i=[],s={status:"ok"};try{i=Object.keys(r).map(d=>{const c=r[d];let a;try{a=Z(c,t.data,t.meta,o,n,{$fn:e})}catch{a=!1}return a===!0?d:void 0}).filter(d=>d!==void 0)}catch(d){const c=d,a=B.calculateCurrentStateError;s={status:"errored",message:`[${a}] ${c.message}`,code:a}}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,Y=e=>e!==void 0&&typeof e=="object"&&e!==null&&"when"in e,Tn=e=>t=>{const{$formIsInvalid:r,$errors:n}=Ge(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)||ce(s))&&Y(s.disabled)||W(s)&&Y(s.readonly))).reduce((s,d)=>{s[d.uid]=s[d.uid]||{};const c=e.repeaterItemScopes[d.uid],a=c?{$item:P(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=!Z(d.include.when,e.data,e.meta,t,r,a)),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=Z(d.exclude.when,e.data,e.meta,t,r,a)),(W(d)||ce(d))&&Y(d.disabled)&&(s[d.uid].disabled=Z(d.disabled.when,e.data,e.meta,t,r,a)),W(d)&&Y(d.readonly)&&(s[d.uid].readonly=Z(d.readonly.when,e.data,e.meta,t,r,a)),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}=Ge(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],a=c.source,f=e.repeaterItemScopes[d];if(!f&&xt(d).length>0){s[d]=c;continue}if(z(a)){s[d]=Pn(d,a,e,t,f);continue}const g=f?{...i,$item:P(i.$form,f.itemPath),$index:f.index}:i;s[d]=Nn(c,a,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?P(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),ar(t)?Un(o,n):ce(t)?_n(o,n):W(t)?Ln(o,n):ee(t)&&Rn(o,n),Vn(t,o,n,r),(ce(t)||W(t))&&Mn(t,o,n),ee(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 Ln(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 Rn(e,t){E(e,t,"size"),E(e,t,"include"),E(e,t,"exclude")}function Vn(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=ot(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=ot(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=ot(n,r,t.sortedStates);e.write(`on.${r}`,Xn(o,t))}function nt(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=rt(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"?nt(e,t):Cr(e)?Gn(e,t):typeof e=="string"?Kt(e,t):e}function Kn(e,t,r,n){return typeof e=="function"?nt(e,t):Y(e)?t.widgetFlags[r]?.[n]:typeof e=="string"?Kt(e,t):e}function Xn(e,t){return typeof e=="function"?nt(e,t):e}function ot(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(rt(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){He(this.current,t,r),P(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(a){const f=a,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 a=n,f=a.form;a.form={uid:"",type:"flex",kind:"layout",children:f}}const i=Et.decode(n);if(i.isOk()){o={status:"ok"};let a={};try{a=ze([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),a={}}return oo(a,i.value.states),{...r,formDef:i.value,flatForm:a,formHealth:o}}const s=ro(n);if(s)return{...r,formHealth:s};const d=B.initializeUnknownError,c=i.issues.map(a=>`${a.path.length>0?$t(a.path):"root"}: ${a.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)&&!ee(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 a of s){if(r.has(a))continue;const f=n.get(a)??[];f.push(i.uid||"(unknown)"),n.set(a,f)}}if(n.size===0)return;const o=r.size?[...r].join(", "):"(none declared)";for(const[i,s]of n)console.error(`[GolemUI] include/exclude references undefined state "${i}" (on ${s.join(", ")}); these widgets will stay hidden. Declared states: ${o}. Fix: declare "${i}" in formConfig.states, or correct the name.`)}function io(e,t){return{...e,injectedValidations:{...e.injectedValidations,[t.payload.path]:t.payload.issues}}}function Ue(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=pt(e.path,t)),n}return W(e)?{...e,uid:r,path:pt(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 pt(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];ao(o)&&(r[n]={...o,when:so(o.when,t)})}return r}function ao(e){return e!==null&&typeof e=="object"&&"when"in e&&typeof e.when=="string"}const N=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=P(e.data,t.path);Array.isArray(s)&&s.forEach((d,c)=>{const a=[...r,c],f={itemPath:`${t.path}.${c}`,index:c};ze([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=Ue(m,a);n[Zt(m.uid,a)]=f,Yt(e,K,a,n,o);return}const O=co(Ue(m,a),a);n[O.uid]=f,o[O.uid]=O})})}const lo=(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 j(e,po(t),ho(t),mo(t),go(t))}const po=e=>t=>({...t,widgetFlags:{...Se(t.widgetFlags,e.payload.uid)}}),ho=e=>t=>({...t,calculatedWidgets:{...Se(t.calculatedWidgets,e.payload.uid)}}),mo=e=>t=>({...t,widgetPropOverrides:{...Se(t.widgetPropOverrides,e.payload.uid)}}),go=e=>t=>({...t,touchedControls:j(t.touchedControls,r=>{const n=t.flatForm[e.payload.uid];return n&&W(n)?Se(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=P(e.data,t.payload.path);return t.type==="SET_WIDGET_DATA"||t.type==="SET_WIDGET_INITIAL_DATA"&&r===void 0?{...e,data:{...He(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 De=(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=P(r.data,s.path),a=mt(d,c);i[s.path]=gt(a)?null:a.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 j(yo(d,c),o,N,i,s);case"SET_META":return j(So(d,c),o,N,i,s);case"SET_LANGUAGE":return j(Ao(d,c),s);case"ADD_WIDGET":return j(Tr(d,c),q(de,o),q(de,N),q(de,i),q(de,s));case"REMOVE_WIDGET":return j(fo(d,c),o,N,i,s);case"SET_WIDGET_INITIAL_DATA":case"SET_WIDGET_DATA":return j(vo(d,c),o,N,i,s);case"OVERRIDE_WIDGET_PROP":return j(lo(d,c),o,N,i,s,q(a=>{let f=!1,g="";"path"in c.payload?(f=!0,g=c.payload.path):W(a.calculatedWidgets[c.payload.uid].current)&&(f=!0,g=a.calculatedWidgets[c.payload.uid].current.path);const m=f&&a.touchedControls[g];return a.touched&&m},De(e,r)));case"SET_FORM_HEALTH":return $o(d,c);case"VALIDATE_ALL":return j({...d,touched:!0,touchedControls:Object.keys(d.calculatedWidgets).reduce((a,f)=>{const g=d.calculatedWidgets[f].source;return W(g)&&(a[g.path]=!0),a},{})},De(e,r),o,N,i,s,ht);case"ATTEMPT_VALIDATION":{const a=c.payload.reason,f=c.payload.path;return t==="eager"||a===t||t.includes(a)?j({...d,touched:!0,touchedControls:{...d.touchedControls,[f]:!0}},De(e,r),o,N,i,s,m=>{const O=c.payload.uid,K=m.calculatedWidgets[O],it=K.source;if(z(it)){const Ce=m.repeaterItemScopes[O],nr=it({$form:m.data,errors:m.validations[f],touched:!0,translate:r.translate,$item:Ce?P(m.data,Ce.itemPath):void 0,$index:Ce?.index});return{...m,calculatedWidgets:{...m.calculatedWidgets,[O]:{source:K.source,current:nr}}}}return m},ht):d}case"INJECT_VALIDATION_ISSUES":return io(d,c);default:return wr(c)}}},de=e=>e.formHealth.status==="ok";function ht(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 a=c;const f={getState:()=>i.getValue(),dispatch:m=>a(m)};return a=e.map(m=>m(f)).reduceRight((m,O)=>O(m),c),{state$:s,dispatch:a,getState:()=>i.getValue()}}class Do{constructor(){this.widgetRegistry=new ke,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:Ie(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:Ie(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: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 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=>P(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)),Lo=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 Ro=p.pipe(p.map(e=>e.touchedControls),p.distinctUntilChanged()),Vo=e=>p.pipe(Ro,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$=Lo;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=Ue;exports.shortUUID=St;exports.standardValidate=mt;exports.touchedControlsByPath$=Vo;exports.validationByPath$=jo;
|
package/internals.d.ts
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
export type { WithWidget } from './lib/context/with-widget.type';
|
|
1
|
+
export {};
|
|
@@ -4,7 +4,7 @@ import { ValidatorFn } from '../form-validator';
|
|
|
4
4
|
import { ActionWidget, InputWidget, LayoutWidget, On } from '../form-widget';
|
|
5
5
|
import { I18nTranslator } from '../i18n';
|
|
6
6
|
import { ItemRenderer } from '../item-renderer';
|
|
7
|
-
import { FormEvent, FormSubmitEvent, ValidateOn } from '../shared';
|
|
7
|
+
import { ExpressionFunctions, FormEvent, FormSubmitEvent, ValidateOn } from '../shared';
|
|
8
8
|
import { Action } from '../store/actions';
|
|
9
9
|
import { Middleware, State } from '../store/model';
|
|
10
10
|
import { WidgetLoaders, WidgetRegistry } from './widget-registry';
|
|
@@ -21,7 +21,7 @@ export declare class FormContext<ComponentType> {
|
|
|
21
21
|
* e.g. a markdown parser for the Markdown component
|
|
22
22
|
*/
|
|
23
23
|
dependencies: Record<string, unknown>;
|
|
24
|
-
initialize(widgetLoaders: WidgetLoaders<ComponentType>, middlewares: Middleware<State, Action>[] | undefined, validators: ValidatorFn<any>, validateOn: ValidateOn, itemRenderers: Record<string, ItemRenderer>, localization: I18nTranslator | undefined, dependencies: Record<string, unknown
|
|
24
|
+
initialize(widgetLoaders: WidgetLoaders<ComponentType>, middlewares: Middleware<State, Action>[] | undefined, validators: ValidatorFn<any>, validateOn: ValidateOn, itemRenderers: Record<string, ItemRenderer>, localization: I18nTranslator | undefined, dependencies: Record<string, unknown>, functions?: ExpressionFunctions): void;
|
|
25
25
|
emitEvent(eventType: keyof On<string>, widget: InputWidget<any, string> | ActionWidget<string> | LayoutWidget<string>, detail?: any): void;
|
|
26
26
|
emitSubmitEvent(): void;
|
|
27
27
|
private attemptValidation;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { NonFunctionWidget } from '../form-widget';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Map of widget type to a lazy component loader. This is the shape of
|
|
4
|
+
* `FormInitConfig.widgetLoaders`: each entry loads the component that renders
|
|
5
|
+
* that widget type, including custom widgets.
|
|
4
6
|
*/
|
|
5
7
|
export type WidgetLoaders<ComponentType, Widget extends string = NonFunctionWidget['type']> = Record<Widget, () => Promise<ComponentType>>;
|
|
6
8
|
export declare class WidgetRegistry<ComponentType> {
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { FormWidget } from '../form-widget';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Contract implemented by every widget component: the component receives the widget
|
|
4
|
+
* definition it renders as its `widget` property. Used by the framework adapters,
|
|
5
|
+
* by custom widgets registered through the form config, and by component libraries
|
|
6
|
+
* built on top of the core runtime.
|
|
4
7
|
*/
|
|
5
8
|
export interface WithWidget {
|
|
6
9
|
widget: FormWidget<string>;
|
package/lib/form-store.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Observable } from 'rxjs';
|
|
2
2
|
import { ValidatorFn } from './form-validator';
|
|
3
3
|
import { I18nTranslator } from './i18n';
|
|
4
|
-
import { ValidateOn } from './shared';
|
|
4
|
+
import { ExpressionFunctions, ValidateOn } from './shared';
|
|
5
5
|
import { Action } from './store/actions';
|
|
6
6
|
import { Middleware, State } from './store/model';
|
|
7
|
-
export declare function createFormStore(middlewares: Middleware<State, Action>[] | undefined, validators: ValidatorFn<any>, validateOn: ValidateOn, localization: I18nTranslator): FormStore;
|
|
7
|
+
export declare function createFormStore(middlewares: Middleware<State, Action>[] | undefined, validators: ValidatorFn<any>, validateOn: ValidateOn, localization: I18nTranslator, functions?: ExpressionFunctions): FormStore;
|
|
8
8
|
export type FormStore = {
|
|
9
9
|
state$: Observable<State>;
|
|
10
10
|
dispatch: (action: Action) => void;
|
package/lib/form.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { WidgetLoaders } from './context/widget-registry';
|
|
|
2
2
|
import { FormWidget, LayoutWidget } from './form-widget';
|
|
3
3
|
import { I18nTranslator } from './i18n';
|
|
4
4
|
import { ItemRenderer } from './item-renderer';
|
|
5
|
-
import { ReactiveExpression, UiState, ValidateOn } from './shared';
|
|
5
|
+
import { ExpressionFunctions, ReactiveExpression, UiState, ValidateOn } from './shared';
|
|
6
6
|
import { Action } from './store/actions';
|
|
7
7
|
import { Middleware, State } from './store/model';
|
|
8
8
|
export type Form<StateKeys extends UiState = never, FormType extends Record<string, any> = any> = {
|
|
@@ -25,6 +25,14 @@ export interface FormInitConfig<ComponentType = unknown> {
|
|
|
25
25
|
itemRenderers?: Record<string, ItemRenderer>;
|
|
26
26
|
localization?: I18nTranslator;
|
|
27
27
|
dependencies?: Record<string, unknown>;
|
|
28
|
+
/**
|
|
29
|
+
* Pure functions callable from reactive expressions under the `$fn` namespace,
|
|
30
|
+
* e.g. `"text": "Total: {{ $fn.grandTotal($form.lineItems) }}"`.
|
|
31
|
+
*
|
|
32
|
+
* Available in every expression context: `{{...}}` string interpolation, i18n params,
|
|
33
|
+
* `when` expressions (include/exclude/disabled/readonly) and state expressions.
|
|
34
|
+
*/
|
|
35
|
+
functions?: ExpressionFunctions;
|
|
28
36
|
middlewares?: Middleware<State, Action>[];
|
|
29
37
|
validateOn?: ValidateOn;
|
|
30
38
|
data?: Record<string, any>;
|
package/lib/shared.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ActionWidget, NonFunctionWidget } from './form-widget';
|
|
2
2
|
import { I18nTranslator } from './i18n';
|
|
3
|
-
import { OVERRIDE_WIDGET_PROP } from './store/actions';
|
|
3
|
+
import { INJECT_VALIDATION_ISSUES, OVERRIDE_WIDGET_PROP } from './store/actions';
|
|
4
4
|
import { ImmutableRecord } from './utils/types';
|
|
5
5
|
/**
|
|
6
6
|
* The UI state name.
|
|
@@ -11,6 +11,22 @@ export type UiState = string;
|
|
|
11
11
|
* A ReactiveExpression is an expression that is evaluated and then substituted by the produced value.
|
|
12
12
|
*/
|
|
13
13
|
export type ReactiveExpression = string;
|
|
14
|
+
/**
|
|
15
|
+
* A pure function exposed to expressions via `$fn`.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* const functions = {
|
|
19
|
+
* grandTotal: (items: Array<{ price?: number }> = []) =>
|
|
20
|
+
* items.reduce((total, item) => total + (item.price ?? 0), 0),
|
|
21
|
+
* };
|
|
22
|
+
* // Form usage: "Grand Total: {{ $fn.grandTotal($form.lineItems) }}"
|
|
23
|
+
*/
|
|
24
|
+
export type ExpressionFunction = (...args: any[]) => unknown;
|
|
25
|
+
/**
|
|
26
|
+
* Map of {@link ExpressionFunction} entries. The key is the name used after `$fn.`
|
|
27
|
+
* in reactive expressions: `functions: { grandTotal }` is called as `$fn.grandTotal(...)`.
|
|
28
|
+
*/
|
|
29
|
+
export type ExpressionFunctions = Record<string, ExpressionFunction>;
|
|
14
30
|
/**
|
|
15
31
|
* The path to a json object
|
|
16
32
|
*/
|
|
@@ -44,6 +60,14 @@ export type $Errors = {
|
|
|
44
60
|
export type WidgetPropertyFunctionParams<FormType extends Record<string, any>> = {
|
|
45
61
|
$form: ImmutableRecord<FormType>;
|
|
46
62
|
translate?: I18nTranslator['translate'];
|
|
63
|
+
/**
|
|
64
|
+
* The current repeater item. Bound only when the widget is inside a repeater `props.template`, for nested repeaters it is the innermost enclosing item.
|
|
65
|
+
*/
|
|
66
|
+
$item?: any;
|
|
67
|
+
/**
|
|
68
|
+
* Zero-based position of the current repeater item. Bound only when the widget is inside a repeater `props.template`.
|
|
69
|
+
*/
|
|
70
|
+
$index?: number;
|
|
47
71
|
};
|
|
48
72
|
/**
|
|
49
73
|
* A WidgetPropertyFunction is a widget function that is evaluated and then substituted by the produced value.
|
|
@@ -54,6 +78,14 @@ export type FunctionWidgetParams<FormType> = {
|
|
|
54
78
|
errors: ValidationStatus | undefined;
|
|
55
79
|
touched: boolean | undefined;
|
|
56
80
|
translate: I18nTranslator['translate'] | undefined;
|
|
81
|
+
/**
|
|
82
|
+
* The current repeater item. Bound only when the widget is inside a repeater `props.template`, for nested repeaters it is the innermost enclosing item.
|
|
83
|
+
*/
|
|
84
|
+
$item?: any;
|
|
85
|
+
/**
|
|
86
|
+
* Zero-based position of the current repeater item. Bound only when the widget is inside a repeater `props.template`.
|
|
87
|
+
*/
|
|
88
|
+
$index?: number;
|
|
57
89
|
};
|
|
58
90
|
/**
|
|
59
91
|
* Defines when widget validation should run.
|
|
@@ -81,7 +113,7 @@ export type EventName = string;
|
|
|
81
113
|
/**
|
|
82
114
|
* Actions that can be called back from the event handler callback
|
|
83
115
|
*/
|
|
84
|
-
export type EventHandlerCallback = OVERRIDE_WIDGET_PROP;
|
|
116
|
+
export type EventHandlerCallback = OVERRIDE_WIDGET_PROP | INJECT_VALIDATION_ISSUES;
|
|
85
117
|
export type FormEvent<T = any> = {
|
|
86
118
|
/** The name of the form widget that dispatched the event. */
|
|
87
119
|
name: EventName;
|
|
@@ -93,6 +125,15 @@ export type FormEvent<T = any> = {
|
|
|
93
125
|
callback: (action: EventHandlerCallback) => void;
|
|
94
126
|
};
|
|
95
127
|
export type FormSubmitEvent<T = any> = Omit<FormEvent<T>, 'name' | 'detail'>;
|
|
128
|
+
/**
|
|
129
|
+
* The DOM event names dispatched by `<gui-core-form>`, and therefore the names the Lit
|
|
130
|
+
* and vanilla-JS surfaces listen for.
|
|
131
|
+
*/
|
|
132
|
+
export declare const formEventNames: {
|
|
133
|
+
readonly submit: "formSubmit";
|
|
134
|
+
readonly health: "formHealth";
|
|
135
|
+
readonly event: "formEvent";
|
|
136
|
+
};
|
|
96
137
|
/**
|
|
97
138
|
* Control adapter templateData
|
|
98
139
|
*/
|
package/lib/store/model.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Form } from '../form';
|
|
2
|
-
import { FormWidget, FunctionWidget } from '../form-widget';
|
|
2
|
+
import { FormWidget, FunctionWidget, NonFunctionWidget } from '../form-widget';
|
|
3
3
|
import { DotPath, Uid, ValidationStatus } from '../shared';
|
|
4
4
|
export type State = {
|
|
5
5
|
formName: string;
|
|
@@ -53,6 +53,27 @@ export type State = {
|
|
|
53
53
|
readonly?: boolean;
|
|
54
54
|
disabled?: boolean;
|
|
55
55
|
}>;
|
|
56
|
+
/**
|
|
57
|
+
* Maps every widget rendered inside a repeater item (by its materialized uid) to the repeater item that owns it.
|
|
58
|
+
* Used to bind the `$item` and `$index` expression scope variables.
|
|
59
|
+
* For nested repeaters the entry points to the innermost enclosing item.
|
|
60
|
+
* Built by `materializeRepeaterItems` on every reducer pipeline run.
|
|
61
|
+
*
|
|
62
|
+
* @example { 'quantity-number[0]': { itemPath: 'lineItems.0', index: 0 } }
|
|
63
|
+
* @example Nested repeater, keyed by the innermost item: { 'dev-name[2][0]': { itemPath: 'teams.2.devs.0', index: 0 } }
|
|
64
|
+
*/
|
|
65
|
+
repeaterItemScopes: Record<Uid, RepeaterItemScope>;
|
|
66
|
+
/**
|
|
67
|
+
* State-managed copies of the repeater template widgets, one per repeater item, keyed by materialized uid.
|
|
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>>;
|
|
56
77
|
/**
|
|
57
78
|
* Allows overriding a widget’s `prop` properties externally via its event handler mechanism.
|
|
58
79
|
* For example, this can be used to load options for a select widget asynchronously.
|
|
@@ -90,6 +111,15 @@ export type MiddlewareAPI<S, A> = {
|
|
|
90
111
|
dispatch: (action: A) => void;
|
|
91
112
|
};
|
|
92
113
|
export type Middleware<S, A> = (api: MiddlewareAPI<S, A>) => (next: (action: A) => void) => (action: A) => void;
|
|
114
|
+
/**
|
|
115
|
+
* Identifies the repeater item that owns a widget rendered inside a repeater `props.template`.
|
|
116
|
+
*/
|
|
117
|
+
export type RepeaterItemScope = {
|
|
118
|
+
/** Data path of the owning item, e.g. `lineItems.0` */
|
|
119
|
+
itemPath: DotPath;
|
|
120
|
+
/** Zero-based position of the owning item in the repeater array */
|
|
121
|
+
index: number;
|
|
122
|
+
};
|
|
93
123
|
/**
|
|
94
124
|
* Represents the current operational state of the form.
|
|
95
125
|
* When in an errored state, the form is considered non-operational
|
package/lib/store/reducer.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { ValidatorFn } from '../form-validator';
|
|
2
2
|
import { I18nTranslator } from '../i18n';
|
|
3
|
-
import { ValidateOn } from '../shared';
|
|
3
|
+
import { ExpressionFunctions, ValidateOn } from '../shared';
|
|
4
4
|
import { Action } from './actions';
|
|
5
5
|
import { State } from './model';
|
|
6
|
-
export declare const reducer: ({ validators, validateOn, localization, }: {
|
|
6
|
+
export declare const reducer: ({ validators, validateOn, localization, functions, }: {
|
|
7
7
|
validators: ValidatorFn<any>;
|
|
8
8
|
validateOn: ValidateOn;
|
|
9
9
|
localization: I18nTranslator;
|
|
10
|
+
functions: ExpressionFunctions;
|
|
10
11
|
}) => (state: State, action: Action) => State;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { I18nTranslator } from '../../i18n';
|
|
2
|
+
import { ExpressionFunctions } from '../../shared';
|
|
2
3
|
import { State } from '../model';
|
|
3
|
-
export declare const calculateWidgetProps: (localization: I18nTranslator) => (state: State) => State;
|
|
4
|
+
export declare const calculateWidgetProps: (localization: I18nTranslator, functions: ExpressionFunctions) => (state: State) => State;
|
|
@@ -4,6 +4,7 @@ export { calculateWidgetFlags } from './calculate-widget-flags';
|
|
|
4
4
|
export { calculateWidgetProps } from './calculate-widget-props';
|
|
5
5
|
export { initialize } from './initialize';
|
|
6
6
|
export { injectValidationIssues } from './inject-validation-issues';
|
|
7
|
+
export { materializeRepeaterItems } from './materialize-repeater-items';
|
|
7
8
|
export { overrideWidgetProp } from './override-widget-prop';
|
|
8
9
|
export { removeWidget } from './remove-widget';
|
|
9
10
|
export { setData } from './set-data';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { State } from '../model';
|
|
2
|
+
/**
|
|
3
|
+
* Walks every repeater's live array data and derives, per item, the same concrete widgets the renderer mounts for that item.
|
|
4
|
+
* Produces two maps keyed by materialized uid, both rebuilt from scratch on every run:
|
|
5
|
+
* - `repeaterItemScopes`: which item owns each widget (binds `$item` / `$index`).
|
|
6
|
+
* - `materializedRepeaterWidgets`: the item-concrete widget configs, with uid and path baked, `when` expressions rewritten for the item's row, and function widgets resolved.
|
|
7
|
+
*
|
|
8
|
+
* `calculateWidgetFlags` and `calculateWidgetProps` consume these maps, so this stage must run before them in the pipeline.
|
|
9
|
+
*/
|
|
10
|
+
export declare const materializeRepeaterItems: (state: State) => State;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { FormWidget } from '../form-widget';
|
|
2
|
+
/**
|
|
3
|
+
* Assigns a position-based uid to every widget in the tree that has none.
|
|
4
|
+
*
|
|
5
|
+
* The generated format is a dot-separated index path prefixed with '#', with a
|
|
6
|
+
* 't' segment for a repeater template, e.g. '#0.2.t.1' is the second template
|
|
7
|
+
* child of the repeater found at position 2 of the root layout. The format must
|
|
8
|
+
* never contain '[<digits>]' because repeater item uids append '[index]' and
|
|
9
|
+
* are parsed back with a regex.
|
|
10
|
+
*
|
|
11
|
+
* @param root - The decoded root widget of a form. Widgets with an explicit uid
|
|
12
|
+
* are left untouched, function widgets are skipped because the decoder assigns
|
|
13
|
+
* their uid directly on the function object.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* const decodedForm = formDefDecoder.parse(rawFormDef);
|
|
17
|
+
* assignDeterministicUids(decodedForm.form); // uid-less widgets now have '#0.x' uids
|
|
18
|
+
*/
|
|
19
|
+
export declare function assignDeterministicUids(root: FormWidget<string>): void;
|
package/lib/utils/justin.d.ts
CHANGED
|
@@ -1,4 +1,17 @@
|
|
|
1
|
-
import { $Errors, ReactiveExpression } from '../shared';
|
|
1
|
+
import { $Errors, ExpressionFunctions, ReactiveExpression } from '../shared';
|
|
2
2
|
import { State } from '../store/model';
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Extra scope variables available to expressions evaluated inside a repeater `props.template`: the current item object and its position
|
|
5
|
+
*/
|
|
6
|
+
export type RepeaterItemExpressionScope = {
|
|
7
|
+
$item?: unknown;
|
|
8
|
+
$index?: number;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Extra scope available to expressions: repeater item variables and host-provided $fn functions.
|
|
12
|
+
*/
|
|
13
|
+
export type ExpressionExtraScope = RepeaterItemExpressionScope & {
|
|
14
|
+
$fn?: ExpressionFunctions;
|
|
15
|
+
};
|
|
16
|
+
export declare function expressionIsTrue(expression: ReactiveExpression, $form: State['data'], $meta: State['meta'], $errors: $Errors, $formIsInvalid: boolean, extraScope?: ExpressionExtraScope): boolean;
|
|
4
17
|
export declare function normalizeArrayIndexes(expression: string): string;
|