@golemui/core 1.2.0 → 1.2.1
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 +27 -0
- package/index.js +384 -367
- package/index.umd.cjs +6 -6
- package/lib/store/model.d.ts +5 -0
- 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 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(`
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("rxjs");require("@standard-schema/spec");function mt(e,t){const r=e["~standard"].validate(t);if(r instanceof Promise)throw new TypeError("Schema validation must be synchronous");return r}function gt(e){return e.issues===void 0}var or=class{value;constructor(e){this.value=e}map(e){return T(e(this.value))}isOk(){return!0}},ir=class yt{issues;constructor(t){this.issues=t}map(t){return new yt(this.issues)}isOk(){return!1}};function T(e){return new or(e)}function C(e){return new ir(e)}function $t(e){return e.reduce((t,r)=>typeof r=="number"?`${t}[${r}]`:t.length===0?String(r):`${t}.${r}`,"")}function dt(e){return e.map(t=>t.path.length===0?t.message:`${$t(t.path)}: ${t.message}`).join("; ")}var D=class Te{decodeFn;constructor(t){this.decodeFn=t}parse(t){let r=this.decode(t);if(r.isOk())return r.value;{let n=r;throw Error(dt(n.issues),{cause:n.issues})}}decode(t){return this.decodeFn(t)}"~standard"={version:1,vendor:"ts.data.json",validate:t=>{let r=this.decode(t);return r.isOk()?{value:r.value}:{issues:r.issues.map(n=>({message:n.message,path:n.path.length>0?n.path.map(o=>({key:o})):void 0}))}}};decodePromise(t){return new Promise((r,n)=>{let o=this.decode(t);if(o.isOk())return r(o.value);{let i=o;return n(Error(dt(i.issues),{cause:i.issues}))}})}map(t){return new Te(r=>{let n=this.decodeFn(r);return n.isOk()?T(t(n.value)):C(n.issues)})}flatMap(t){return new Te(r=>{let n=this.decodeFn(r);return n.isOk()?t(n.value).decode(r):C(n.issues)})}},H=(e,t)=>[{message:`${JSON.stringify(e)} is not a valid ${t}`,path:[]}],Ve=(e,t)=>e.map(r=>({...r,path:[t,...r.path]}));function Le(e){return new D(t=>{if(t instanceof Array){let r=[],n=[];for(let o=0;o<t.length;o++){let i=e.decode(t[o]);i.isOk()?r.push(i.value):n.push(...Ve(i.issues,o))}return n.length>0?C(n):T(r)}else return C(H(t,"array"))})}function sr(){return new D(e=>typeof e=="boolean"?T(e):C(H(e,"boolean")))}function dr(e,t){return new D(r=>{if(typeof r!="object"||!r)return C(H(r,"object"));let n=r[e];return Object.prototype.hasOwnProperty.call(t,n)?t[n].decode(r):C([{message:`"${e}" must be one of ${Object.keys(t).map(o=>JSON.stringify(o)).join(", ")}, but got ${JSON.stringify(n)}`,path:[e]}])})}function At(e){return new D(t=>e().decode(t))}function X(e){return new D(t=>t===e?T(e):C([{message:`${JSON.stringify(t)} is not exactly ${JSON.stringify(e)}`,path:[]}]))}function $e(){return new D(e=>typeof e=="number"?T(e):C(H(e,"number")))}function oe(e){return new D(t=>{if(typeof t=="object"&&t){let r={},n=[];for(let o in e)if(Object.prototype.hasOwnProperty.call(e,o)){let i,s=e[o];i=s instanceof D?s.decode(t[o]):s.decoder.decode(t[s.fromKey]),i.isOk()?r[o]=i.value:n.push(...Ve(i.issues,o))}return n.length>0?C(n):T(r)}else return C(H(t,"object"))})}function J(e){return new D(t=>{let r=[];for(let n=0;n<e.length;n++){let o=e[n].decode(t);if(o.isOk())return o;r.push(o.issues)}return C([{message:`no alternative matched (tried ${e.length})`,path:[]},...ur(r)])})}function ur(e){let t=new Map;for(let r of e)for(let n of r){let o=JSON.stringify(n.path),i=t.get(o);i?i.messages.includes(n.message)||i.messages.push(n.message):t.set(o,{path:n.path,messages:[n.message]})}return Array.from(t.values()).map(({path:r,messages:n})=>({message:n.join(" or "),path:r}))}function $(e){return new D(t=>t===void 0?T(void 0):e.decode(t))}function cr(e){return new D(t=>{if(typeof t=="object"&&t){let r={},n=[];for(let o in t)if(Object.prototype.hasOwnProperty.call(t,o)){let i=e.decode(t[o]);i.isOk()?r[o]=i.value:n.push(...Ve(i.issues,o))}return n.length>0?C(n):T(r)}else return C(H(t,"object"))})}function I(){return new D(e=>typeof e=="string"?T(e):C(H(e,"string")))}function M(){return new D(e=>T(e))}function ie(e){return new D(t=>{if(typeof t!="object"||t===null)return C([{message:`Expected object literal, got "${typeof t}"`,path:[]}]);const r={};for(const[n,o]of Object.entries(e)){const i=o.decoder.decode(t[n]);if(!i.isOk())return C(i.issues.map(s=>({message:s.message,path:[n,...s.path]})));if(r[n]=i.value,o.suffixed){for(const[s,d]of Object.entries(t))if(s.startsWith(n+".")){const c=o.decoder.decode(d);if(!c.isOk())return C(c.issues.map(l=>({message:l.message,path:[s,...l.path]})));r[s]=c.value}}}return T(r)})}const St=()=>crypto.randomUUID().slice(0,8),lr=e=>typeof e!="function"&&e.kind==="display",le=e=>typeof e!="function"&&e.kind==="action",W=e=>typeof e!="function"&&e.kind==="input",te=e=>typeof e!="function"&&e.kind==="layout",z=e=>typeof e=="function",ar=oe({in:Le(I())}),Re=oe({when:I()}),Ae=J([ar,Re]),fr=oe({from:Le(I())}),Se=J([fr,Re]),ke=J([sr(),Re]),pr=new D(e=>{const t=typeof e;return t==="function"?T(e):C([{message:`Expected a function, got '${t}'`,path:[]}])}),U=e=>J([e,pr]),Me=ie({load:{suffixed:!0,decoder:U($(I()))},click:{suffixed:!0,decoder:U($(I()))},change:{suffixed:!0,decoder:U($(I()))},filter:{suffixed:!0,decoder:U($(I()))},blur:{suffixed:!0,decoder:U($(I()))}}),hr=oe({key:I(),default:$(I()),params:$(M())}),vt=J([I(),hr]),Be=$(I()),mr=ie({kind:{decoder:X("display")},uid:{decoder:Be},type:{decoder:I()},size:{suffixed:!0,decoder:$($e())},include:{decoder:$(Ae)},exclude:{decoder:$(Se)},props:{decoder:$(M())}}),gr=ie({kind:{decoder:X("action")},uid:{decoder:Be},type:{decoder:I()},actionType:{decoder:$(J([X("button"),X("submit")]))},size:{suffixed:!0,decoder:$($e())},include:{decoder:$(Ae)},exclude:{decoder:$(Se)},label:{suffixed:!0,decoder:U($(vt))},disabled:{suffixed:!0,decoder:$(ke)},on:{decoder:$(Me)},props:{decoder:$(M())}}),yr=new D(e=>{const t=typeof e;if(t==="function"){const r=e,n=r({$form:{},errors:void 0,touched:void 0,translate:void 0});return r.uid=r.uid||n.uid||St(),r.type=n.type,r.path=n.path,T(r)}else return C([{message:`Expected a function, got '${t}'`,path:[]}])}),$r=ie({kind:{decoder:X("input")},uid:{decoder:$(I())},type:{decoder:I()},size:{suffixed:!0,decoder:$($e())},include:{decoder:$(Ae)},exclude:{decoder:$(Se)},disabled:{suffixed:!0,decoder:$(ke)},readonly:{suffixed:!0,decoder:$(ke)},on:{decoder:$(Me)},props:{decoder:$(M())},label:{suffixed:!0,decoder:U($(vt))},path:{decoder:I()},defaultValue:{decoder:$(M())},validator:{suffixed:!0,decoder:U($(M()))}}).map(e=>{const t={...e};if(e.uid||(t.uid=`${e.path}-${e.type}`),e.type==="repeater"){const r=e.props;t.props={...r,template:He.parse(r.template)}}return t}),Ar=At(()=>{const e=dr("kind",{input:$r,layout:He,display:mr,action:gr});return new D(t=>typeof t=="function"?yr.decode(t):e.decode(t))}),He=ie({kind:{decoder:X("layout")},uid:{decoder:Be},type:{decoder:I()},size:{suffixed:!0,decoder:$($e())},include:{decoder:$(Ae)},exclude:{decoder:$(Se)},props:{decoder:$(M())},on:{decoder:$(Me)},children:{decoder:Le(Ar)}}),R=class R{constructor(){this.widgetLoaders={},this._ready=!1}get ready(){return this._ready}setWidgetLoaders(t){this.widgetLoaders=t,this._ready=!0}async loadWidget(t){const r=this.widgetLoaders[t];if(!R.sharedCache.has(r)){const n=r().catch(o=>(R.sharedCache.delete(r),Promise.reject(o)));R.sharedCache.set(r,n)}return R.sharedCache.get(r)}};R.sharedCache=new Map;let Fe=R;function Sr(e){je(e,"#0")}function je(e,t){if(!z(e)&&(e.uid||(e.uid=t),te(e)&&e.children.forEach((r,n)=>{je(r,`${t}.${n}`)}),W(e)&&e.type==="repeater")){const r=e.props?.template;r&&je(r,`${t}.t`)}}function vr(e){return{...e,form:{uid:"",type:"flex",kind:"layout",children:e.form}}}const Et=oe({states:$(cr(I())),form:At(()=>He)}).map(e=>(Sr(e.form),e)),Ct=e=>({formName:"",formDef:Et.parse({form:{kind:"layout",type:"flex",children:[]}}),flatForm:{},currentStates:[],calculatedWidgets:{},validations:{},touchedControls:{},injectedValidations:{},isFormValid:!0,widgetFlags:{},repeaterItemScopes:{},materializedRepeaterWidgets:{},widgetPropOverrides:{},data:{},meta:{},formHealth:{status:"ok"},touched:!1,allControlsValidated:!1,lang:e}),Er={submit:"formSubmit",health:"formHealth",event:"formEvent"},Cr=e=>!(typeof e!="object"||e===null||typeof e.key!="string");function Ir(e){const t=new Intl.Locale(e).maximize().script;return["Arab","Hebr","Thaa","Syrc","Tfng","Adlm","Rohg"].includes(t||"")?"rtl":"ltr"}const It=(e=navigator.language||"en-US")=>{const t=new Set;return{get lang(){return e},translate(n){return n},subscribe(n){return t.add(n),()=>{t.delete(n)}},setLang(n){e=n,t.forEach(o=>o(e))}}},wr=e=>{throw new Error(`Unhandled case: ${JSON.stringify(e)}`)};function F(e,...t){return t.reduce((r,n)=>n(r),e)}const N=(e,t)=>{if(e===void 0)throw new Error("obj is undefined");return t.split(".").reduce((r,n)=>r===void 0||n===""?r:Array.isArray(r)?r[parseInt(n,10)]:r[n],e)},ze=(e,t,r)=>{if(e===null)throw new Error("object is null");if(e===void 0)throw new Error("object is undefined");if(t==="")throw new Error("path cannot be empty");const n=t.split(".");let o=e;for(let s=0;s<n.length-1;s++){const d=n[s],c=n[s+1];(o[d]==null||typeof o[d]!="object")&&(o[d]=Dr(c)?[]:{}),o=o[d]}const i=n[n.length-1];return o[i]=r,e},Or=(e,t)=>{if(t==="")return e;const r=t.split("."),n=[e];for(let s=0;s<r.length-1;s++){const d=n[s];if(d==null||typeof d!="object")return e;const c=r[s],l=Array.isArray(d)?d[parseInt(c,10)]:d[c];if(l==null||typeof l!="object")return e;n.push(l)}const o=n[n.length-1],i=r[r.length-1];Array.isArray(o)?o.splice(parseInt(i,10),1):delete o[i];for(let s=n.length-1;s>=1;s--){const d=n[s];if(Array.isArray(d)||!Wr(d))break;const c=n[s-1],l=r[s-1];if(Array.isArray(c))break;delete c[l]}return e};function Dr(e){const t=Number(e);return Number.isInteger(t)&&t>=0&&t.toString()===e}function Wr(e){return e!=null&&typeof e=="object"&&!Array.isArray(e)&&Object.keys(e).length===0}const ve=(e,t)=>(delete e[t],e);function ae(e){if(e===null||typeof e!="object")return e;if(Array.isArray(e))return e.map(r=>ae(r));const t={};for(const r of Object.keys(e))t[r]=ae(e[r]);return t}function Tr(e,t){const r=t.payload.widget.uid;if(!r)throw new Error("addWidget: widget must have a uid");const n=t.payload.widget,o=e.allControlsValidated&&W(n)?{...e.touchedControls,[n.path]:!0}:e.touchedControls;return{...e,touchedControls:o,calculatedWidgets:{...e.calculatedWidgets,[r]:{source:n,current:{}}}}}const B={calculateCurrentStateError:10,initializeParseError:20,initializeUidCollisionError:21,initializeUnknownError:22,initializeMalformedFormShapeError:23,widgetCouldNotBeLoaded:30,resolveStringInterpolationError:40};function Ge(e){return e.flatMap(t=>[t,...te(t)?Ge(t.children):[]])}function be(e){return Object.entries(e.validations).reduce((r,[n,o])=>(o!==null&&(r.$formIsInvalid=!0,ze(r.$errors,n,[...o])),r),{$formIsInvalid:!1,$errors:{}})}function we(e){const t=ae(e.data);for(const[r,n]of Object.entries(e.widgetFlags))if(n.hidden===!0){const o=e.flatForm[r];o&&W(o)&&Or(t,o.path)}return t}const Ke=32;let Pe,h,y,A=e=>(h=0,y=e,A.newline=!1,e=v(),y[h]?G():e||""),G=(e="Unexpected token",t=h,r=y.slice(0,t).split(`
|
|
2
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}${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],
|
|
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]};
|
|
6
|
-
`,"/*":"*/"};let
|
|
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)}
|
|
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;
|
|
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],Ne=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&&Pe&&A.asi?.(n,e,v)||null)??((i=j[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},V=(e,t=h)=>{for(Pe=!1;(e=y.charCodeAt(h))<=Ke;)A.asi&&e===10&&(A.newline=Pe=!0),h++;return e},kr=(e=h)=>{for(;y.charCodeAt(e)<=Ke;)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)),j=[],ut={},k=(e,t=Ke,r,n=e.charCodeAt(0),o=e.length,i=j[n],s=e.toUpperCase()!==e,d,c)=>(t=ut[e]=!i&&ut[e]||t,j[n]=(l,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(l))?wt(c,m):(h=m,d=0,!s&&!i&&!l&&G()),c)||i?.(l,f,d))),S=(e,t,r=!1)=>k(e,t,n=>n&&(o=>o&&[e,n,o])(v(t-(r?.5:0)))),L=(e,t,r)=>k(e,t,n=>!n&&(n=v(t-.5))&&[e,n]),se=(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)),Xe=(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]),de=(e,t,r,n=e.charCodeAt(0),o=e.length,i=j[n],s)=>j[n]=(d,c,l,f=h)=>!d&&(l?e==l:(o<2||y.substr(h,o)==e)&&(l=e))&&c<t&&!A.id(y.charCodeAt(h+o))&&(!A.prop||A.prop(h+o))&&(Ne(h+o),(s=r())?wt(s,f):Ne(f),s)||i?.(d,c,l);Object.defineProperty(A,"space",{configurable:!0,enumerable:!0,get:()=>V,set:e=>V=e});const Ue={},a=(e,t,r=Ue[e])=>Ue[e]=(...n)=>t(...n)||r?.(...n),u=e=>Array.isArray(e)?e[0]==null?(t=>()=>t)(e[1]):Ue[e[0]]?.(...e.slice(1))??G(`Unknown operator: ${e[0]}`,e?.loc):e===void 0?()=>{}:t=>t?.[e],fe=46,re=48,pe=57,jr=69,Pr=101,Nr=43,Ur=45,ce=95,Wt=110,_r=97,Vr=102,Lr=65,Rr=70,Tt=e=>e.indexOf("_")<0?e:e.replaceAll("_",""),Je=e=>{let t=Tt(x(r=>r===fe&&y.charCodeAt(h+1)!==fe||r>=re&&r<=pe||r===ce||((r===jr||r===Pr)&&((r=y.charCodeAt(h+1))>=re&&r<=pe||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===ce,8:e=>e>=48&&e<=55||e===ce,16:e=>e>=re&&e<=pe||e>=_r&&e<=Vr||e>=Lr&&e<=Rr||e===ce};A.number=null;j[fe]=e=>!e&&y.charCodeAt(h+1)!==fe&&Je();for(let e=re;e<=pe;e++)j[e]=t=>t?void 0:Je();j[re]=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 Je()};const Br=92,ct=34,lt=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]};j[ct]=kt(ct);j[lt]=kt(lt);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)a(e,(t,r)=>(r=u(r),Ft(t,(n,o,i)=>at[e](n,o,r(i)))));const Gr=30,br=40,Kr=140;L("!",Kr);S("||",Gr);S("&&",br);a("!",e=>(e=u(e),t=>!e(t)));a("||",(e,t)=>(e=u(e),t=u(t),r=>e(r)||t(r)));a("&&",(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);L("~",Qr);a("~",e=>(e=u(e),t=>~e(t)));a("|",(e,t)=>(e=u(e),t=u(t),r=>e(r)|t(r)));a("&",(e,t)=>(e=u(e),t=u(t),r=>e(r)&t(r)));a("^",(e,t)=>(e=u(e),t=u(t),r=>e(r)^t(r)));a(">>",(e,t)=>(e=u(e),t=u(t),r=>e(r)>>t(r)));a("<<",(e,t)=>(e=u(e),t=u(t),r=>e(r)<<t(r)));const Ee=90;S("<",Ee);S(">",Ee);S("<=",Ee);S(">=",Ee);a(">",(e,t)=>(e=u(e),t=u(t),r=>e(r)>t(r)));a("<",(e,t)=>(e=u(e),t=u(t),r=>e(r)<t(r)));a(">=",(e,t)=>(e=u(e),t=u(t),r=>e(r)>=t(r)));a("<=",(e,t)=>(e=u(e),t=u(t),r=>e(r)<=t(r)));const Pt=80;S("==",Pt);S("!=",Pt);a("==",(e,t)=>(e=u(e),t=u(t),r=>e(r)==t(r)));a("!=",(e,t)=>(e=u(e),t=u(t),r=>e(r)!=t(r)));const Nt=110,xe=120,Ut=140;S("+",Nt);S("-",Nt);S("*",xe);S("/",xe);S("%",xe);L("+",Ut);L("-",Ut);a("+",(e,t)=>t!==void 0?(e=u(e),t=u(t),r=>e(r)+t(r)):(e=u(e),r=>+e(r)));a("-",(e,t)=>t!==void 0?(e=u(e),t=u(t),r=>e(r)-t(r)):(e=u(e),r=>-e(r)));a("*",(e,t)=>(e=u(e),t=u(t),r=>e(r)*t(r)));a("/",(e,t)=>(e=u(e),t=u(t),r=>e(r)/t(r)));a("%",(e,t)=>(e=u(e),t=u(t),r=>e(r)%t(r)));const he=150;k("++",he,e=>e?["++",e,null]:["++",v(he-1)]);k("--",he,e=>e?["--",e,null]:["--",v(he-1)]);const Qe=(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?Qe(e[1],t):(()=>{throw Error("Invalid increment target")})();a("++",(e,t)=>Qe(e,t===null?(r,n)=>r[n]++:(r,n)=>++r[n]));a("--",(e,t)=>Qe(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});a(",",_t);a(";",_t);const Yr=170;Xe("()",Yr);const _=e=>e?.[0]==="_"&&e[1]==="_"||e==="constructor"||e==="prototype",qe=170;Dt("[]",qe);S(".",qe);Dt("()",qe);const me=e=>{throw Error(e)};a("[]",(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&&me("Missing index"),e=u(e),t=u(t),r=>{const n=t(r);return _(n)?void 0:e(r)[n]}));a(".",(e,t)=>(e=u(e),t=t[0]?t:t[1],_(t)?()=>{}:r=>e(r)[t]));a("()",(e,t)=>{if(t===void 0)return e==null?me("Empty ()"):u(e);const r=o=>o?.[0]===","&&o.slice(1).some(i=>i==null||r(i));r(t)&&me("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 Ze(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]==="{}"),Ze=(e,t,r,n)=>e==null?me("Empty ()"):e[0]==="()"&&e.length==2?Ze(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=Ze,en=32,tn=A.space;A.comment??={"//":`
|
|
6
|
+
`,"/*":"*/"};let Oe;A.space=()=>{Oe||(Oe=Object.entries(A.comment).map(([o,i])=>[o,i,o.charCodeAt(0)]));for(var e;e=tn();){for(var t=0,r;r=Oe[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)}Ne(n),e=0;break}if(e)return e}return e};const Vt=80;S("===",Vt);S("!==",Vt);a("===",(e,t)=>(e=u(e),t=u(t),r=>e(r)===t(r)));a("!==",(e,t)=>(e=u(e),t=u(t),r=>e(r)!==t(r)));const rn=30;S("??",rn);a("??",(e,t)=>(e=u(e),t=u(t),r=>e(r)??t(r)));const nn=130,on=20;S("**",nn,!0);S("**=",on,!0);a("**",(e,t)=>(e=u(e),t=u(t),r=>e(r)**t(r)));const sn=e=>{throw Error(e)};a("**=",(e,t)=>(b(e)||sn("Invalid assignment target"),t=u(t),Q(e,(r,n,o)=>r[n]**=t(o))));const Lt=90;S("in",Lt);S("of",Lt);a("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);a(">>>",(e,t)=>(e=u(e),t=u(t),r=>e(r)>>>t(r)));a(">>>=",(e,t)=>(b(e)||cn("Invalid assignment target"),t=u(t),Q(e,(r,n,o)=>r[n]>>>=t(o))));const Ye=5,ln=10,an=20,fn=e=>e[0]?.[0]===","?e[0].slice(1):e,ge=(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,l,f;typeof d=="string"?c=l=d:d[0]==="="?(typeof d[1]=="string"?c=l=d[1]:[,c,l]=d[1],f=d[2]):[,c,l]=d,s.push(c);let g=t[c];g===void 0&&f&&(g=u(f)(r)),ge(l,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,l;Array.isArray(d)&&d[0]==="="&&([,c,l]=d);let f=t[s++];f===void 0&&l&&(f=u(l)(r)),ge(c,f,r)}}},Rt=e=>{let t=v(ln-1);return t?.[0]==="in"||t?.[0]==="of"?[t[0],[e,t[1]],t[2]]:t?.[0]===","?[e,...t.slice(1)]:[e,t]};de("let",Ye+1,()=>Rt("let"));de("const",Ye+1,()=>Rt("const"));de("var",Ye,()=>(V(),["var",v(an)]));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=>ge(r,o(i),i)}return u(t)}),t=>{for(const r of e)r(t)});a("let",Mt);a("const",Mt);a("var",e=>typeof e=="string"?t=>{t[e]=void 0}:()=>{});const et=20,Ce=e=>{throw Error(e)};S("||=",et,!0);S("&&=",et,!0);S("??=",et,!0);a("=",(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=>ge(r,t(n),n)}return b(e)||Ce("Invalid assignment target"),t=u(t),Q(e,(r,n,o)=>r[n]=t(o))});a("||=",(e,t)=>(b(e)||Ce("Invalid assignment target"),t=u(t),Q(e,(r,n,o)=>r[n]||=t(o))));a("&&=",(e,t)=>(b(e)||Ce("Invalid assignment target"),t=u(t),Q(e,(r,n,o)=>r[n]&&=t(o))));a("??=",(e,t)=>(b(e)||Ce("Invalid assignment target"),t=u(t),Q(e,(r,n,o)=>r[n]??=t(o))));se("true",!0);se("false",!1);se("null",null);de("undefined",200,()=>[]);se("NaN",NaN);se("Infinity",1/0);const De=20;k("?",De,(e,t,r)=>e&&(t=v(De-1))&&x(n=>n===58)&&(r=v(De-1),["?",e,t,r]));a("?",(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);a("=>",(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 l={};r.forEach((g,m)=>l[g]=c[m]),o&&(l[o]=c.slice(n));const f=new Proxy(l,{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;L("...",mn);a("...",e=>(e=u(e),t=>Object.entries(e(t))));const ft=170;k("?.",ft,(e,t)=>{if(!e)return;const r=V();return r===40?(w(),["?.()",e,v(0,41)||null]):r===91?(w(),["?.[]",e,v(0,93)]):(t=v(ft),t?["?.",e,t]:void 0)});a("?.",(e,t)=>(e=u(e),_(t)?()=>{}:r=>e(r)?.[t]));a("?.[]",(e,t)=>(e=u(e),t=u(t),r=>{const n=t(r);return _(n)?void 0:e(r)?.[n]}));a("?.()",(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 ne=140;L("typeof",ne);L("void",ne);L("delete",ne);de("new",ne,()=>Fr(".target")?(w(7),["new.target"]):["new",v(ne)]);a("typeof",e=>(e=u(e),t=>typeof e(t)));a("void",e=>(e=u(e),t=>(e(t),void 0)));a("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});a("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 tt=Symbol("accessor"),rt=20,gn=40,Bt=41,Ht=123,zt=125,Gt=e=>t=>{if(t)return;V();const r=x(A.id);if(!r||(V(),y.charCodeAt(h)!==gn))return!1;w();const n=v(0,Bt);return V(),y.charCodeAt(h)!==Ht?!1:(w(),[e,r,n,v(0,zt)])};k("get",rt-1,Gt("get"));k("set",rt-1,Gt("set"));k("(",rt-1,e=>{if(!e||typeof e!="string")return;const t=v(0,Bt)||null;if(V(),y.charCodeAt(h)===Ht)return w(),[":",e,["=>",["()",t],v(0,zt)||null]]});a("get",(e,t)=>(t=t?u(t):()=>{},r=>[[tt,e,{get:function(){const n=Object.create(r||{});return n.this=this,t(n)}}]]));a("set",(e,t,r)=>(r=r?u(r):()=>{},n=>[[tt,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]);Xe("[]",bt);Xe("{}",bt);S(":",yn-1,!0);a("{}",(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]===tt){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}});a("{",e=>(e=e?u(e):()=>{},t=>e(Object.create(t))));a(":",(e,t)=>(t=u(t),Array.isArray(e)?(e=u(e),r=>[[e(r),t(r)]]):r=>[[e,t(r)]]));const An=170,ye=96,Sn=36,vn=123,En=92,Cn={n:`
|
|
8
|
+
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},pt=()=>{const e=[];for(let t="",r;(r=y.charCodeAt(h))!==ye;)r?r===En?(w(),t+=Cn[y[h]]||y[h],w()):r===Sn&&y.charCodeAt(h+1)===vn?(t&&e.push([,t]),t="",w(2),e.push(v(0,125))):(t+=y[h],w(),r=y.charCodeAt(h),r===ye&&t&&e.push([,t])):G("Unterminated template");return w(),e},In=j[ye];j[ye]=(e,t)=>e&&t<An?A.asi&&A.newline?void 0:(w(),["``",e,...pt()]):e?In?.(e,t):(w(),(r=>r.length<2&&r[0]?.[0]===void 0?r[0]||[,""]:["`",...r])(pt()));a("`",(...e)=>(e=e.map(u),t=>e.map(r=>r(t)).join("")));a("``",(e,...t)=>{e=u(e);const r=[],n=[];for(const i of t)Array.isArray(i)&&i[0]===void 0?r.push(i[1]):n.push(u(i));const o=Object.assign([...r],{raw:r});return i=>e(i)(o,...n.map(s=>s(i)))});A.string["'"]=!0;A.number={"0x":16,"0b":2,"0o":8};const wn={log:(e,t)=>(t?console.log(t,e):console.log(e),e)};function Y(e,t,r,n,o,i){const s=A(nt(e));return u(s)({$form:t,$meta:r,$errors:n,$formIsInvalid:o,$log:wn.log,$fn:{},...i})===!0}function nt(e){return e.replace(/(\?\.|\.)(\d+)/g,(t,r,n,o)=>r==="."&&On(e,o)?t:r==="?."?`?.[${n}]`:`[${n}]`)}function On(e,t){let r=t-1,n=!1;for(;r>=0&&e[r]>="0"&&e[r]<="9";)n=!0,r--;if(r<0)return!0;const o=e[r];return n?!/[\w$.\]]/.test(o):!/[\w$)\]]/.test(o)}const Dn=e=>t=>{let r=t.formDef.states;if(!r||Object.keys(r).length===0||t.formHealth.status==="errored")return t;const{$formIsInvalid:n,$errors:o}=be(t);r=Wn(r);let i=[],s={status:"ok"};try{i=Object.keys(r).map(d=>{const c=r[d];let l;try{l=Y(c,t.data,t.meta,o,n,{$fn:e})}catch{l=!1}return l===!0?d:void 0}).filter(d=>d!==void 0)}catch(d){const c=d,l=B.calculateCurrentStateError;s={status:"errored",message:`[${l}] ${c.message}`,code:l}}return{...t,currentStates:i,formHealth:s}};function Wn(e){const t={};function r(n){const o=n.split(":"),i=[];for(let s=0;s<o.length;s++)i.push(o.slice(0,s+1).join(":"));return i}for(const[n,o]of Object.entries(e)){const i=r(n),s=[];for(const d of i)e[d]&&s.push(`(${e[d]})`);t[n]=s.join(" && ")}return t}const q=(e,t)=>r=>e(r)?t(r):r,ee=e=>e!==void 0&&typeof e=="object"&&e!==null&&"when"in e,Tn=e=>t=>{const{$formIsInvalid:r,$errors:n}=be(t);return{...t,widgetFlags:kn(t,n,r,e)}};function kn(e,t,r,n){const o=Object.values(e.flatForm).map(s=>{if(z(s)){const d=s({$form:e.data,errors:void 0,touched:void 0,translate:void 0});return d.uid=s.uid,d}return s}),i=Object.values(e.materializedRepeaterWidgets);return[...o,...i].filter(s=>!!(s.include&&("in"in s.include||"when"in s.include)||s.exclude&&("from"in s.exclude||"when"in s.exclude)||(W(s)||le(s))&&ee(s.disabled)||W(s)&&ee(s.readonly))).reduce((s,d)=>{s[d.uid]=s[d.uid]||{};const c=e.repeaterItemScopes[d.uid],l=c?{$item:N(e.data,c.itemPath),$index:c.index,$fn:n}:{$fn:n};return d.include&&"in"in d.include?s[d.uid].hidden=!d.include.in.some(f=>e.currentStates.includes(f)):d.include&&"when"in d.include&&(s[d.uid].hidden=!Y(d.include.when,e.data,e.meta,t,r,l)),d.exclude&&"from"in d.exclude?s[d.uid].hidden=d.exclude.from.some(f=>e.currentStates.includes(f)):d.exclude&&"when"in d.exclude&&(s[d.uid].hidden=Y(d.exclude.when,e.data,e.meta,t,r,l)),(W(d)||le(d))&&ee(d.disabled)&&(s[d.uid].disabled=Y(d.disabled.when,e.data,e.meta,t,r,l)),W(d)&&ee(d.readonly)&&(s[d.uid].readonly=Y(d.readonly.when,e.data,e.meta,t,r,l)),s},{})}const Fn=(e,t)=>r=>{try{return{...r,calculatedWidgets:jn(r,e,t)}}catch(n){const o=n;return{...r,formHealth:{status:"errored",message:`[${o.code}] ${o.message}`,code:o.code}}}};function jn(e,t,r){const{$formIsInvalid:n,$errors:o}=be(e),i=qn(e,t,n,o,r),s={};for(const d of Object.keys(e.calculatedWidgets)){if(e.widgetFlags[d]?.hidden)continue;const c=e.calculatedWidgets[d],l=c.source,f=e.repeaterItemScopes[d];if(!f&&xt(d).length>0){s[d]=c;continue}if(z(l)){s[d]=Pn(d,l,e,t,f);continue}const g=f?{...i,$item:N(i.$form,f.itemPath),$index:f.index}:i;s[d]=Nn(c,l,e,g)}return s}function Pn(e,t,r,n,o){const i=t({$form:r.data,errors:t.path?r.validations[t.path]:void 0,touched:t.path?r.touchedControls[t.path]:void 0,translate:n.translate,$item:o?N(r.data,o.itemPath):void 0,$index:o?.index});return i.uid=e,{source:t,current:i}}function Nn(e,t,r,n){const o=new Qn(t,e.current);return o.write("uid",t.uid),o.write("type",t.type),o.write("kind",t.kind),lr(t)?Un(o,n):le(t)?_n(o,n):W(t)?Vn(o,n):te(t)&&Ln(o,n),Rn(t,o,n,r),(le(t)||W(t))&&Mn(t,o,n),te(t)&&Bn(t,o,r),o.changed?{source:e.source,current:o.current}:e}function Un(e,t){E(e,t,"size"),E(e,t,"include"),E(e,t,"exclude")}function _n(e,t){E(e,t,"size"),E(e,t,"include"),E(e,t,"exclude"),E(e,t,"label"),E(e,t,"disabled"),E(e,t,"actionType")}function Vn(e,t){E(e,t,"size"),E(e,t,"include"),E(e,t,"exclude"),E(e,t,"label"),E(e,t,"disabled"),E(e,t,"readonly"),E(e,t,"validator"),E(e,t,"path"),E(e,t,"defaultValue")}function Ln(e,t){E(e,t,"size"),E(e,t,"include"),E(e,t,"exclude")}function Rn(e,t,r,n){const o=n.widgetPropOverrides[e.uid]??{},i={...e.props??{},...o};for(const s of Jt(Object.keys(i)))Hn(t,r,s)}function Mn(e,t,r){const n=e.on??{};for(const o of Jt(Object.keys(n)))zn(t,r,o)}function Bn(e,t,r){const n=xt(e.uid),o=Yn(e.children,n,r.widgetFlags);t.current.children=o;const i=t.previous.children??[];i.length===o.length&&o.every((d,c)=>i[c]&&i[c].uid===o[c].uid)||t.markChanged()}function E(e,t,r){const n=e.source;if(!Zn(n,r))return;const o=it(n,r,t.sortedStates);let i;switch(r){case"disabled":case"readonly":i=Kn(o,t,e.source.uid,r);break;case"defaultValue":i=o;break;default:i=Xt(o,t)}e.write(r,i)}function Hn(e,t,r){const n=e.source.props,o=it(n,r,t.sortedStates);let i=Xt(o,t);const s=t.widgetPropOverrides[e.source.uid]?.[r];s!==void 0&&(i=s),e.write(`props.${r}`,i)}function zn(e,t,r){const n=e.source.on,o=it(n,r,t.sortedStates);e.write(`on.${r}`,Xn(o,t))}function ot(e,t){return e({$form:t.$form,translate:t.localization.translate,$item:t.$item,$index:t.$index})}function Gn(e,t){return t.localization.translate(e.key,xn(e.params,t),e.default)}const bn=/\{\{([^}]+)\}\}/g;function Kt(e,t){return e.includes("{{")?e.replace(bn,(r,n)=>{const o=nt(n.trim());try{const i=u(A(o))({$form:t.$form,$meta:t.$meta,$errors:t.$errors,$formIsInvalid:t.$formIsInvalid,$item:t.$item,$index:t.$index,$fn:t.$fn});return i==null?"":String(i)}catch(i){const s=i instanceof Error?i.message:String(i);throw new Qt(`Failed to evaluate '{{${n.trim()}}}': ${s}`)}}):e}function Xt(e,t){return typeof e=="function"?ot(e,t):Cr(e)?Gn(e,t):typeof e=="string"?Kt(e,t):e}function Kn(e,t,r,n){return typeof e=="function"?ot(e,t):ee(e)?t.widgetFlags[r]?.[n]:typeof e=="string"?Kt(e,t):e}function Xn(e,t){return typeof e=="function"?ot(e,t):e}function it(e,t,r){if(e){for(const n of r){const o=e[`${t}.${n}`];if(o!==void 0)return o}return e[t]}}function Jn(e){return e.startsWith("$form")||e.startsWith("$meta")||e.startsWith("$errors")||e.startsWith("$item")||e.startsWith("$index")||e.startsWith("$fn")||e==="$formIsInvalid"}function xn(e,t){return e&&Object.keys(e).reduce((r,n)=>{const o=String(e[n]);if(Jn(o))try{const i=u(A(nt(o)))({$form:t.$form,$meta:t.$meta,$errors:t.$errors,$formIsInvalid:t.$formIsInvalid,$item:t.$item,$index:t.$index,$fn:t.$fn});r[n]=i??o}catch(i){const s=i instanceof Error?i.message:String(i);throw new Qt(`Failed to evaluate i18n param '${o}': ${s}`)}else r[n]=o;return r},{})}class Qn{constructor(t,r){this._changed=!1,this.source=t,this.previous=r,this.current={}}get changed(){return this._changed}markChanged(){this._changed=!0}write(t,r){ze(this.current,t,r),N(this.previous,t)!==r&&(this._changed=!0)}}function qn(e,t,r,n,o){return{sortedStates:[...e.currentStates].sort((i,s)=>s.length-i.length),widgetPropOverrides:e.widgetPropOverrides,widgetFlags:e.widgetFlags,$form:e.data,$meta:e.meta,$formIsInvalid:r,$errors:n,localization:t,$fn:o}}function Zn(e,t){if(t in e)return!0;const r=`${t}.`;return Object.keys(e).some(n=>n.startsWith(r))}function Jt(e){return Array.from(new Set(e.map(t=>t.split(".")[0])))}function Yn(e,t,r){const n=t.map(o=>`[${o}]`).join("");return e.filter(o=>{const i=o.uid+n,s=r[i];return!s||s.hidden!==!0})}const xt=e=>[...e.matchAll(/\[(\d+)\]/g)].map(t=>parseInt(t[1],10));class Qt extends Error{constructor(){super(...arguments),this.code=B.resolveStringInterpolationError,this.name="StringInterpolationError"}}const eo=({lang:e},t)=>{const r={...Ct(e),formName:t.payload.formName};let n=t.payload.formDef,o={status:"ok"};if(typeof n=="string"){try{n=JSON.parse(n)}catch(l){const f=l,g=B.initializeParseError;o={status:"errored",message:`[${g}] ${f.message}`,code:g}}if(o.status==="errored")return{...r,formHealth:o}}if(Array.isArray(n.form)){const l=n,f=l.form;l.form={uid:"",type:"flex",kind:"layout",children:f}}const i=Et.decode(n);if(i.isOk()){o={status:"ok"};let l={};try{l=Ge([i.value.form]).reduce((f,g)=>{const m=g.uid;if(f[m])throw{existingWidget:f[m],newWidget:g};return f[m]=g,f},{})}catch(f){o=no(f.existingWidget,f.newWidget),l={}}return oo(l,i.value.states),{...r,formDef:i.value,flatForm:l,formHealth:o}}const s=ro(n);if(s)return{...r,formHealth:s};const d=B.initializeUnknownError,c=i.issues.map(l=>`${l.path.length>0?$t(l.path):"root"}: ${l.message}`).join("; ");return{...r,formHealth:{status:"errored",message:`[${d}] ${c}`,code:d}}};function qt(e,t){return{status:"errored",code:e,message:`[${e}] ${t}`}}function to(){return"Malformed form definition. Pass it directly as formDef - `config={{ formDef: { states, form: [...] } }}`. Do NOT wrap it in an extra `{ form: ... }`."}function ro(e){if(!e||typeof e!="object"||Array.isArray(e))return null;const t=e.form;return t&&typeof t=="object"&&!Array.isArray(t)&&!te(t)?qt(B.initializeMalformedFormShapeError,to()):null}function no(e,t){const r=o=>W(o)?` at "${o.path}"`:"",n=`Duplicate UID "${t.uid}": Assigned to widget "${e.type}"${r(e)} and "${t.type}"${r(t)}.`;return qt(B.initializeUidCollisionError,n)}function oo(e,t){const r=new Set(Object.keys(t??{})),n=new Map;for(const i of Object.values(e)){const s=[],d=i.include;d&&Array.isArray(d.in)&&s.push(...d.in);const c=i.exclude;c&&Array.isArray(c.from)&&s.push(...c.from);for(const l of s){if(r.has(l))continue;const f=n.get(l)??[];f.push(i.uid||"(unknown)"),n.set(l,f)}}if(n.size===0)return;const o=r.size?[...r].join(", "):"(none declared)";for(const[i,s]of n)console.error(`[GolemUI] include/exclude references undefined state "${i}" (on ${s.join(", ")}); these widgets will stay hidden. Declared states: ${o}. Fix: declare "${i}" in formConfig.states, or correct the name.`)}function io(e,t){const{path:r,issues:n}=t.payload,o=n?.length?{touched:!0,touchedControls:{...e.touchedControls,[r]:!0}}:{};return{...e,...o,injectedValidations:{...e.injectedValidations,[r]:n}}}function _e(e,t){const r=Zt(e.uid,t);if(z(e)){const n=o=>e(o);return n.uid=r,n.type=e.type,e.path!==void 0&&(n.path=ht(e.path,t)),n}return W(e)?{...e,uid:r,path:ht(e.path,t)}:{...e,uid:r}}function Zt(e,t){if(t.length===0)throw new Error("Repeater indexes cannot be an empty array");const r=t.reduce((n,o)=>`${n}[${o}]`,"");return`${e}${r}`}function ht(e,t){if(t.length===0)throw new Error("Repeater indexes cannot be an empty array");const r="items",n=e.split(`.${r}`),o=n.length-1;if(o!==t.length)throw new Error(`Path contains ${o} '${r}' occurrences, but ${t.length} indexes were provided.`);return n.reduce((i,s,d)=>d===0?s:`${i}.${t[d-1]}${s}`)}function so(e,t){let r=0;return e.replace(/\.items(\??)\./g,(n,o)=>{const i=t[r++];return i===void 0?n:`.${i}${o}.`})}const uo=["include","exclude","disabled","readonly"];function co(e,t){const r={...e};for(const n of uo){const o=r[n];lo(o)&&(r[n]={...o,when:so(o.when,t)})}return r}function lo(e){return e!==null&&typeof e=="object"&&"when"in e&&typeof e.when=="string"}const P=e=>{const t={},r={},n=Object.values(e.flatForm).filter(o=>!z(o)&&o.type==="repeater");for(const o of n)Yt(e,o,[],t,r);return{...e,repeaterItemScopes:t,materializedRepeaterWidgets:r}};function Yt(e,t,r,n,o){const i=t.props.template,s=N(e.data,t.path);Array.isArray(s)&&s.forEach((d,c)=>{const l=[...r,c],f={itemPath:`${t.path}.${c}`,index:c};Ge([i]).forEach(g=>{let m;if(z(g)?(m=g({$form:e.data,$item:d,$index:c,errors:void 0,touched:void 0,translate:void 0}),m.uid=g.uid):m=g,m.type==="repeater"){const K=_e(m,l);n[Zt(m.uid,l)]=f,Yt(e,K,l,n,o);return}const O=co(_e(m,l),l);n[O.uid]=f,o[O.uid]=O})})}const ao=(e,{payload:t})=>{let r;if("path"in t){if(r=Object.values(e.calculatedWidgets).find(({source:i})=>W(i)&&i.path===t.path),!r)return console.warn(`Input with path "${t.path}" not found`),e}else if(r=e.calculatedWidgets[t.uid],!r)return console.warn(`Widget with uid "${t.uid}" not found`),e;const n=r.source.uid,o=e.widgetPropOverrides[n]||{};return{...e,widgetPropOverrides:{...e.widgetPropOverrides,[n]:{...o,[t.prop]:t.value}}}};function fo(e,t){return F(e,po(t),ho(t),mo(t),go(t))}const po=e=>t=>({...t,widgetFlags:{...ve(t.widgetFlags,e.payload.uid)}}),ho=e=>t=>({...t,calculatedWidgets:{...ve(t.calculatedWidgets,e.payload.uid)}}),mo=e=>t=>({...t,widgetPropOverrides:{...ve(t.widgetPropOverrides,e.payload.uid)}}),go=e=>t=>({...t,touchedControls:F(t.touchedControls,r=>{const n=t.flatForm[e.payload.uid];return n&&W(n)?ve(r,n.path):r})}),yo=(e,t)=>({...e,data:{...t.payload.data}}),$o=(e,t)=>({...e,formHealth:t.payload.formHealth}),Ao=(e,t)=>({...e,lang:t.payload.lang}),So=(e,t)=>({...e,meta:{...t.payload.meta}}),vo=(e,t)=>{const r=N(e.data,t.payload.path);return t.type==="SET_WIDGET_DATA"||t.type==="SET_WIDGET_INITIAL_DATA"&&r===void 0?{...e,data:{...ze(e.data,t.payload.path,t.payload.data)}}:e},er=Symbol("filterMap.skip");function Eo(e,t){const r=[];for(let n=0;n<e.length;n++){const o=t(e[n],n,e);o!==er&&r.push(o)}return r}function Co(e,t,r){for(let n=0;n<e.length;n++)t(e[n],n,e)&&r(e[n],n,e)}function Io(e,t,r){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!r(e[n],t[n],n,e,t))return!1;return!0}const ue=(e,t)=>r=>{const n=Eo(Object.values(r.calculatedWidgets),({current:i})=>W(i)?i:er),o=r.validations;return{...r,validations:n.reduce((i,s)=>{if(i[s.path]=null,s.validator){const d=e(s.validator,t),c=N(r.data,s.path),l=mt(d,c);i[s.path]=gt(l)?null:l.issues.map(f=>f.message)}return Array.isArray(i[s.path])&&Array.isArray(o[s.path])&&Io(i[s.path],o[s.path],(d,c)=>d===c)&&(i[s.path]=o[s.path]),i},{})}},wo=({validators:e,validateOn:t,localization:r,functions:n})=>{const o=Dn(n),i=Tn(n),s=Fn(r,n);return(d,c)=>{switch(c.type){case"INITIALIZE":return eo(d,c);case"SET_DATA":return F(yo(d,c),o,P,i,s);case"SET_META":return F(So(d,c),o,P,i,s);case"SET_LANGUAGE":return F(Ao(d,c),s);case"ADD_WIDGET":{const l=F(Tr(d,c),q(Z,o),q(Z,P),q(Z,i),q(Z,s));return Z(l)&&l.allControlsValidated?F(l,ue(e,r),o,P,i,s,We):l}case"REMOVE_WIDGET":return F(fo(d,c),o,P,i,s);case"SET_WIDGET_INITIAL_DATA":case"SET_WIDGET_DATA":return F(vo(d,c),o,P,i,s);case"OVERRIDE_WIDGET_PROP":return F(ao(d,c),o,P,i,s,q(l=>{let f=!1,g="";"path"in c.payload?(f=!0,g=c.payload.path):W(l.calculatedWidgets[c.payload.uid].current)&&(f=!0,g=l.calculatedWidgets[c.payload.uid].current.path);const m=f&&l.touchedControls[g];return l.touched&&m},ue(e,r)));case"SET_FORM_HEALTH":return $o(d,c);case"VALIDATE_ALL":return F({...d,touched:!0,allControlsValidated:!0,touchedControls:Object.keys(d.calculatedWidgets).reduce((l,f)=>{const g=d.calculatedWidgets[f].source;return W(g)&&(l[g.path]=!0),l},{})},ue(e,r),o,P,i,s,We);case"ATTEMPT_VALIDATION":{const l=c.payload.reason,f=c.payload.path;return t==="eager"||l===t||t.includes(l)?F({...d,touched:!0,touchedControls:{...d.touchedControls,[f]:!0}},ue(e,r),o,P,i,s,m=>{const O=c.payload.uid,K=m.calculatedWidgets[O],st=K.source;if(z(st)){const Ie=m.repeaterItemScopes[O],nr=st({$form:m.data,errors:m.validations[f],touched:!0,translate:r.translate,$item:Ie?N(m.data,Ie.itemPath):void 0,$index:Ie?.index});return{...m,calculatedWidgets:{...m.calculatedWidgets,[O]:{source:K.source,current:nr}}}}return m},We):d}case"INJECT_VALIDATION_ISSUES":return io(d,c);default:return wr(c)}}},Z=e=>e.formHealth.status==="ok";function We(e){const t=Object.keys(e.injectedValidations),r=Object.keys(e.validations);if(t.length===0&&r.length===0)return{...e,isFormValid:!0};let n=t.find(o=>e.injectedValidations[o]!==null&&Array.isArray(e.injectedValidations[o]));return n!==void 0?{...e,isFormValid:!1}:(n=r.find(o=>e.validations[o]!==null&&Array.isArray(e.validations[o])),n!==void 0?{...e,isFormValid:!1}:{...e,isFormValid:!0})}function Oo(e=[],t,r,n,o={}){const i=new p.BehaviorSubject(Ct(n.lang)),s=i.asObservable().pipe(p.distinctUntilChanged()),d=wo({validators:t,validateOn:r,localization:n,functions:o});function c(m){const O=i.getValue(),K=d(O,m);i.next(K)}let l=c;const f={getState:()=>i.getValue(),dispatch:m=>l(m)};return l=e.map(m=>m(f)).reduceRight((m,O)=>O(m),c),{state$:s,dispatch:l,getState:()=>i.getValue()}}class Do{constructor(){this.widgetRegistry=new Fe,this.store={},this.events$=new p.Subject,this.submit$=new p.Subject,this.uuid=crypto.randomUUID(),this.itemRenderers={},this.dependencies={}}initialize(t,r=[],n,o,i,s=It(),d,c={}){this.localization=s,this.dependencies=d,this.widgetRegistry.setWidgetLoaders(t),this.itemRenderers=i,this.store=Oo(r,n,o,s,c)}emitEvent(t,r,n){const i=this.store.getState().currentStates.filter(s=>r.on?.[`${t}.${s}`]!==void 0);if(i.length>0)i.forEach(s=>{const d=r.on?.[`${t}.${s}`];this.attemptValidation(t,r),d&&this.events$.next({name:d,data:we(this.store.getState()),detail:n??void 0,callback:c=>{this.store.dispatch(c)}})});else{const s=r.on?.[t];this.attemptValidation(t,r),s&&this.events$.next({name:s,data:we(this.store.getState()),detail:n,callback:d=>{this.store.dispatch(d)}})}}emitSubmitEvent(){this.store.dispatch({type:"VALIDATE_ALL"}),this.store.getState().isFormValid&&this.submit$.next({data:we(this.store.getState()),callback:t=>{this.store.dispatch(t)}})}attemptValidation(t,r){r.kind!=="layout"&&(t==="change"?this.store.dispatch({type:"ATTEMPT_VALIDATION",payload:{reason:"change",path:r.path,uid:r.uid}}):t==="click"&&r.kind==="action"&&r.actionType==="submit"&&this.store.dispatch({type:"VALIDATE_ALL"}))}}function Wo(e="GolemUI Form Store"){return t=>{const n=(typeof window<"u"?window.__REDUX_DEVTOOLS_EXTENSION__:void 0)?.connect({name:e});return n?.init(t.getState()),o=>i=>{o(i),n&&n.send(i,t.getState())}}}const To=p.pipe(p.map(e=>e.data),p.distinctUntilChanged()),ko=e=>p.pipe(To,p.map(t=>N(t,e)),p.distinctUntilChanged()),Fo=p.pipe(p.filter(e=>e.touched===!0),p.map(e=>e.validations),p.distinctUntilChanged()),jo=e=>p.pipe(Fo,p.map(t=>t[e]),p.distinctUntilChanged()),Po=p.pipe(p.filter(e=>e.touched===!0),p.map(e=>e.injectedValidations),p.distinctUntilChanged()),No=e=>p.pipe(Po,p.map(t=>t[e]),p.distinctUntilChanged(),p.startWith(null)),Uo=p.pipe(p.map(e=>e.lang),p.distinctUntilChanged()),tr=p.pipe(p.map(e=>e.calculatedWidgets),p.distinctUntilChanged()),_o=e=>t=>p.combineLatest([t.pipe(Uo),t.pipe(tr)]).pipe(p.map(([r,n])=>({lang:r,widget:n[e]})),p.filter(r=>r.widget!==void 0),p.distinctUntilChanged((r,n)=>r.lang===n.lang&&r.widget===n.widget),p.map(r=>r.widget.current)),Vo=e=>p.pipe(tr,p.map(t=>t[e]),p.filter(t=>t!==void 0),p.map(t=>t.current.children),p.distinctUntilChanged());p.pipe(p.map(e=>e.widgetFlags),p.distinctUntilChanged());const Lo=p.pipe(p.map(e=>e.touchedControls),p.distinctUntilChanged()),Ro=e=>p.pipe(Lo,p.map(t=>t[e]),p.distinctUntilChanged()),Mo=p.pipe(p.map(e=>e.formHealth),p.distinctUntilChanged((e,t)=>e.status!==t.status?!1:e.status==="errored"&&t.status==="errored"?e.message===t.message&&e.code===t.code:!0)),Bo=e=>e.pipe(Mo);let rr=!1;function Ho(){rr=!0}function zo(){return rr}function Go(e,t,r){if(!zo())return;const n=Object.keys(t??{}).filter(o=>o in r);if(n.length>0)throw new Error(`[GolemUI] Widget "${e}": prop keys [${n.join(", ")}] collide with widget fields`)}exports.FormContext=Do;exports.assertNoPropCollisions=Go;exports.calculatedLayoutChildrenByUid$=Vo;exports.calculatedWidgetsByUid$=_o;exports.cloneObject=ae;exports.dataByPath$=ko;exports.defineForm=vr;exports.devToolsMiddleware=Wo;exports.enableDevMode=Ho;exports.errorCodes=B;exports.filterTap=Co;exports.formEventNames=Er;exports.formHealth=Bo;exports.getDirectionFromLanguage=Ir;exports.identityTranslator=It;exports.injectedValidationByPath$=No;exports.isStandardValidateSuccess=gt;exports.makeRepeaterItemConfig=_e;exports.shortUUID=St;exports.standardValidate=mt;exports.touchedControlsByPath$=Ro;exports.validationByPath$=jo;
|
package/lib/store/model.d.ts
CHANGED
|
@@ -100,6 +100,11 @@ export type State = {
|
|
|
100
100
|
* Set to true when a validateOn-type event occurs on any form control.
|
|
101
101
|
*/
|
|
102
102
|
touched: boolean;
|
|
103
|
+
/**
|
|
104
|
+
* True once a VALIDATE_ALL pass has run (typically a submit attempt).
|
|
105
|
+
* Input widgets added afterwards are immediately marked as touched.
|
|
106
|
+
*/
|
|
107
|
+
allControlsValidated: boolean;
|
|
103
108
|
/**
|
|
104
109
|
* The BCP 47 language tag of the current locale (e.g., 'en-US', 'es', 'fr-CA').
|
|
105
110
|
*/
|