@golemui/core 1.1.0 → 1.1.1-rc.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 +26 -0
- package/index.d.ts +1 -0
- package/index.js +453 -437
- package/index.umd.cjs +6 -6
- package/internals.d.ts +1 -2
- package/lib/context/widget-registry.d.ts +3 -1
- package/lib/context/with-widget.type.d.ts +4 -1
- package/lib/shared.d.ts +11 -2
- package/lib/utils/deterministic-uids.d.ts +19 -0
- package/package.json +4 -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 nr=class{value;constructor(e){this.value=e}map(e){return T(e(this.value))}isOk(){return!0}},or=class yt{issues;constructor(t){this.issues=t}map(t){return new yt(this.issues)}isOk(){return!1}};function T(e){return new nr(e)}function C(e){return new or(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:[]}],Ue=(e,t)=>e.map(r=>({...r,path:[t,...r.path]}));function _e(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(...Ue(i.issues,o))}return n.length>0?C(n):T(r)}else return C(H(t,"array"))})}function ir(){return new D(e=>typeof e=="boolean"?T(e):C(H(e,"boolean")))}function sr(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 K(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 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(...Ue(i.issues,o))}return n.length>0?C(n):T(r)}else return C(H(t,"object"))})}function X(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:[]},...dr(r)])})}function dr(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 ur(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(...Ue(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 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,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 Le=()=>crypto.randomUUID().slice(0,8),cr=e=>typeof e!="function"&&e.kind==="display",ue=e=>typeof e!="function"&&e.kind==="action",W=e=>typeof e!="function"&&e.kind==="input",ce=e=>typeof e!="function"&&e.kind==="layout",J=e=>typeof e=="function",lr=re({in:_e(I())}),Re=re({when:I()}),$e=X([lr,Re]),ar=re({from:_e(I())}),Ae=X([ar,Re]),Te=X([ir(),Re]),fr=new D(e=>{const t=typeof e;return t==="function"?T(e):C([{message:`Expected a function, got '${t}'`,path:[]}])}),U=e=>X([e,fr]),Ve=ne({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()))}}),pr=re({key:I(),default:$(I()),params:$(M())}),St=X([I(),pr]),Me=$(I()).map(e=>e||Le()),hr=ne({kind:{decoder:K("display")},uid:{decoder:Me},type:{decoder:I()},size:{suffixed:!0,decoder:$(ye())},include:{decoder:$($e)},exclude:{decoder:$(Ae)},props:{decoder:$(M())}}),mr=ne({kind:{decoder:K("action")},uid:{decoder:Me},type:{decoder:I()},actionType:{decoder:$(X([K("button"),K("submit")]))},size:{suffixed:!0,decoder:$(ye())},include:{decoder:$($e)},exclude:{decoder:$(Ae)},label:{suffixed:!0,decoder:U($(St))},disabled:{suffixed:!0,decoder:$(Te)},on:{decoder:$(Ve)},props:{decoder:$(M())}}),gr=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,T(r)}else return C([{message:`Expected a function, got '${t}'`,path:[]}])}),yr=ne({kind:{decoder:K("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($(St))},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;r.template=Be.parse(r.template)}return t}),$r=At(()=>{const e=sr("kind",{input:yr,layout:Be,display:hr,action:mr});return new D(t=>typeof t=="function"?gr.decode(t):e.decode(t))}),Be=ne({kind:{decoder:K("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:_e($r)}}),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 Ar(e){return{...e,form:{uid:"",type:"flex",kind:"layout",children:e.form}}}const vt=re({states:$(ur(I())),form:At(()=>Be)}),Et=e=>({formName:"",formDef:vt.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}),Sr=e=>!(typeof e!="object"||e===null||typeof e.key!="string");function vr(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))}}},Er=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]=Ir(c)?[]:{}),o=o[d]}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 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 Ir(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 le(e){if(e===null||typeof e!="object")return e;if(Array.isArray(e))return e.map(r=>le(r));const t={};for(const r of Object.keys(e))t[r]=le(e[r]);return t}function Or(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,...ce(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=le(e.data);for(const[r,n]of Object.entries(e.widgetFlags))if(n.hidden===!0){const o=e.flatForm[r];o&&W(o)&&Cr(t,o.path)}return t}const be=32;let Fe,h,y,A=e=>(h=0,y=e,A.newline=!1,e=v(),y[h]?z():e||""),z=(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 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
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}`)},
|
|
5
|
-
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},
|
|
6
|
-
`,"/*":"*/"};let we;A.space=()=>{we||(we=Object.entries(A.comment).map(([o,i])=>[o,i,o.charCodeAt(0)]));for(var e;e=
|
|
7
|
-
`)for(;y.charCodeAt(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===An?(w(),t+=Sn[y[h]]||y[h],w()):r===yn&&y.charCodeAt(h+1)===$n?(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])):z("Unterminated template");return w(),e},vn=F[ge];F[ge]=(e,t)=>e&&t<gn?A.asi&&A.newline?void 0:(w(),["``",e,...ft()]):e?vn?.(e,t):(w(),(r=>r.length<2&&r[0]?.[0]===void 0?r[0]||[,""]:["`",...r])(ft()));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 En={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:En.log,$fn:{},...i})===!0}function rt(e){return e.replace(/(\?\.|\.)(\d+)/g,(t,r,n,o)=>r==="."&&Cn(e,o)?t:r==="?."?`?.[${n}]`:`[${n}]`)}function Cn(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 In=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 l;try{l=Z(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,Y=e=>e!==void 0&&typeof e=="object"&&e!==null&&"when"in e,On=e=>t=>{const{$formIsInvalid:r,$errors:n}=Ge(t);return{...t,widgetFlags:Dn(t,n,r,e)}};function Dn(e,t,r,n){const o=Object.values(e.flatForm).map(s=>{if(J(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)||ue(s))&&Y(s.disabled)||W(s)&&Y(s.readonly))).reduce((s,d)=>{s[d.uid]=s[d.uid]||{};const c=e.repeaterItemScopes[d.uid],l=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,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=Z(d.exclude.when,e.data,e.meta,t,r,l)),(W(d)||ue(d))&&Y(d.disabled)&&(s[d.uid].disabled=Z(d.disabled.when,e.data,e.meta,t,r,l)),W(d)&&Y(d.readonly)&&(s[d.uid].readonly=Z(d.readonly.when,e.data,e.meta,t,r,l)),s},{})}const Wn=(e,t)=>r=>{try{return{...r,calculatedWidgets:Tn(r,e,t)}}catch(n){const o=n;return{...r,formHealth:{status:"errored",message:`[${o.code}] ${o.message}`,code:o.code}}}};function Tn(e,t,r){const{$formIsInvalid:n,$errors:o}=Ge(e),i=Jn(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&&Jt(d).length>0){s[d]=c;continue}if(J(l)){s[d]=kn(d,l,e,t,f);continue}const g=f?{...i,$item:P(i.$form,f.itemPath),$index:f.index}:i;s[d]=Fn(c,l,e,g)}return s}function kn(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 Fn(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),cr(t)?jn(o,n):ue(t)?Pn(o,n):W(t)?Nn(o,n):ce(t)&&Un(o,n),_n(t,o,n,r),(ue(t)||W(t))&&Ln(t,o,n),ce(t)&&Rn(t,o,r),o.changed?{source:e.source,current:o.current}:e}function jn(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)))Vn(t,r,s)}function Ln(e,t,r){const n=e.on??{};for(const o of Xt(Object.keys(n)))Mn(t,r,o)}function Rn(e,t,r){const n=Jt(e.uid),o=Qn(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(!xn(n,r))return;const o=ot(n,r,t.sortedStates);let i;switch(r){case"disabled":case"readonly":i=zn(o,t,e.source.uid,r);break;case"defaultValue":i=o;break;default:i=Kt(o,t)}e.write(r,i)}function Vn(e,t,r){const n=e.source.props,o=ot(n,r,t.sortedStates);let i=Kt(o,t);const s=t.widgetPropOverrides[e.source.uid]?.[r];s!==void 0&&(i=s),e.write(`props.${r}`,i)}function Mn(e,t,r){const n=e.source.on,o=ot(n,r,t.sortedStates);e.write(`on.${r}`,Gn(o,t))}function nt(e,t){return e({$form:t.$form,translate:t.localization.translate,$item:t.$item,$index:t.$index})}function Bn(e,t){return t.localization.translate(e.key,Kn(e.params,t),e.default)}const Hn=/\{\{([^}]+)\}\}/g;function bt(e,t){return e.includes("{{")?e.replace(Hn,(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 xt(`Failed to evaluate '{{${n.trim()}}}': ${s}`)}}):e}function Kt(e,t){return typeof e=="function"?nt(e,t):Sr(e)?Bn(e,t):typeof e=="string"?bt(e,t):e}function zn(e,t,r,n){return typeof e=="function"?nt(e,t):Y(e)?t.widgetFlags[r]?.[n]:typeof e=="string"?bt(e,t):e}function Gn(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 bn(e){return e.startsWith("$form")||e.startsWith("$meta")||e.startsWith("$errors")||e.startsWith("$item")||e.startsWith("$index")||e.startsWith("$fn")||e==="$formIsInvalid"}function Kn(e,t){return e&&Object.keys(e).reduce((r,n)=>{const o=String(e[n]);if(bn(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 xt(`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){He(this.current,t,r),P(this.previous,t)!==r&&(this._changed=!0)}}function Jn(e,t,r,n,o){return{sortedStates:[...e.currentStates].sort((i,s)=>s.length-i.length),widgetPropOverrides:e.widgetPropOverrides,widgetFlags:e.widgetFlags,$form:e.data,$meta:e.meta,$formIsInvalid:r,$errors:n,localization:t,$fn:o}}function xn(e,t){if(t in e)return!0;const r=`${t}.`;return Object.keys(e).some(n=>n.startsWith(r))}function 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 Jt=e=>[...e.matchAll(/\[(\d+)\]/g)].map(t=>parseInt(t[1],10));class xt extends Error{constructor(){super(...arguments),this.code=B.resolveStringInterpolationError,this.name="StringInterpolationError"}}const qn=({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 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=vt.decode(n);if(i.isOk()){o={status:"ok"};let l={};try{l=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=eo(f.existingWidget,f.newWidget),l={}}return to(l,i.value.states),{...r,formDef:i.value,flatForm:l,formHealth:o}}const s=Yn(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 Zn(){return"Malformed form definition. Pass it directly as formDef - `config={{ formDef: { states, form: [...] } }}`. Do NOT wrap it in an extra `{ form: ... }`."}function Yn(e){if(!e||typeof e!="object"||Array.isArray(e))return null;const t=e.form;return t&&typeof t=="object"&&!Array.isArray(t)&&!ce(t)?Qt(B.initializeMalformedFormShapeError,Zn()):null}function eo(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 to(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 ro(e,t){return{...e,injectedValidations:{...e.injectedValidations,[t.payload.path]:t.payload.issues}}}function Ne(e,t){const r=qt(e.uid,t);if(J(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 qt(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 no(e,t){let r=0;return e.replace(/\.items(\??)\./g,(n,o)=>{const i=t[r++];return i===void 0?n:`.${i}${o}.`})}const oo=["include","exclude","disabled","readonly"];function io(e,t){const r={...e};for(const n of oo){const o=r[n];so(o)&&(r[n]={...o,when:no(o.when,t)})}return r}function so(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=>!J(o)&&o.type==="repeater");for(const o of n)Zt(e,o,[],t,r);return{...e,repeaterItemScopes:t,materializedRepeaterWidgets:r}};function Zt(e,t,r,n,o){const i=t.props.template,s=P(e.data,t.path);Array.isArray(s)&&s.forEach((d,c)=>{const l=[...r,c],f={itemPath:`${t.path}.${c}`,index:c};ze([i]).forEach(g=>{let m;if(J(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 b=Ne(m,l);n[qt(m.uid,l)]=f,Zt(e,b,l,n,o);return}const O=io(Ne(m,l),l);n[O.uid]=f,o[O.uid]=O})})}const uo=(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 co(e,t){return j(e,lo(t),ao(t),fo(t),po(t))}const lo=e=>t=>({...t,widgetFlags:{...Se(t.widgetFlags,e.payload.uid)}}),ao=e=>t=>({...t,calculatedWidgets:{...Se(t.calculatedWidgets,e.payload.uid)}}),fo=e=>t=>({...t,widgetPropOverrides:{...Se(t.widgetPropOverrides,e.payload.uid)}}),po=e=>t=>({...t,touchedControls:j(t.touchedControls,r=>{const n=t.flatForm[e.payload.uid];return n&&W(n)?Se(r,n.path):r})}),ho=(e,t)=>({...e,data:{...t.payload.data}}),mo=(e,t)=>({...e,formHealth:t.payload.formHealth}),go=(e,t)=>({...e,lang:t.payload.lang}),yo=(e,t)=>({...e,meta:{...t.payload.meta}}),$o=(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},Yt=Symbol("filterMap.skip");function Ao(e,t){const r=[];for(let n=0;n<e.length;n++){const o=t(e[n],n,e);o!==Yt&&r.push(o)}return r}function So(e,t,r){for(let n=0;n<e.length;n++)t(e[n],n,e)&&r(e[n],n,e)}function vo(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=Ao(Object.values(r.calculatedWidgets),({current:i})=>W(i)?i:Yt),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),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])&&vo(i[s.path],o[s.path],(d,c)=>d===c)&&(i[s.path]=o[s.path]),i},{})}},Eo=({validators:e,validateOn:t,localization:r,functions:n})=>{const o=In(n),i=On(n),s=Wn(r,n);return(d,c)=>{switch(c.type){case"INITIALIZE":return qn(d,c);case"SET_DATA":return j(ho(d,c),o,N,i,s);case"SET_META":return j(yo(d,c),o,N,i,s);case"SET_LANGUAGE":return j(go(d,c),s);case"ADD_WIDGET":return j(Or(d,c),q(se,o),q(se,N),q(se,i),q(se,s));case"REMOVE_WIDGET":return j(co(d,c),o,N,i,s);case"SET_WIDGET_INITIAL_DATA":case"SET_WIDGET_DATA":return j($o(d,c),o,N,i,s);case"OVERRIDE_WIDGET_PROP":return j(uo(d,c),o,N,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},De(e,r)));case"SET_FORM_HEALTH":return mo(d,c);case"VALIDATE_ALL":return j({...d,touched:!0,touchedControls:Object.keys(d.calculatedWidgets).reduce((l,f)=>{const g=d.calculatedWidgets[f].source;return W(g)&&(l[g.path]=!0),l},{})},De(e,r),o,N,i,s,ht);case"ATTEMPT_VALIDATION":{const l=c.payload.reason,f=c.payload.path;return t==="eager"||l===t||t.includes(l)?j({...d,touched:!0,touchedControls:{...d.touchedControls,[f]:!0}},De(e,r),o,N,i,s,m=>{const O=c.payload.uid,b=m.calculatedWidgets[O],it=b.source;if(J(it)){const Ce=m.repeaterItemScopes[O],rr=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:b.source,current:rr}}}}return m},ht):d}case"INJECT_VALIDATION_ISSUES":return ro(d,c);default:return Er(c)}}},se=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 Co(e=[],t,r,n,o={}){const i=new p.BehaviorSubject(Et(n.lang)),s=i.asObservable().pipe(p.distinctUntilChanged()),d=Eo({validators:t,validateOn:r,localization:n,functions:o});function c(m){const O=i.getValue(),b=d(O,m);i.next(b)}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 Io{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=Ct(),d,c={}){this.localization=s,this.dependencies=d,this.widgetRegistry.setWidgetLoaders(t),this.itemRenderers=i,this.store=Co(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 Oo=p.pipe(p.map(e=>e.data),p.distinctUntilChanged()),Do=e=>p.pipe(Oo,p.map(t=>P(t,e)),p.distinctUntilChanged()),Wo=p.pipe(p.filter(e=>e.touched===!0),p.map(e=>e.validations),p.distinctUntilChanged()),To=e=>p.pipe(Wo,p.map(t=>t[e]),p.distinctUntilChanged()),ko=p.pipe(p.filter(e=>e.touched===!0),p.map(e=>e.injectedValidations),p.distinctUntilChanged()),Fo=e=>p.pipe(ko,p.map(t=>t[e]),p.distinctUntilChanged(),p.startWith(null)),jo=p.pipe(p.map(e=>e.lang),p.distinctUntilChanged()),er=p.pipe(p.map(e=>e.calculatedWidgets),p.distinctUntilChanged()),Po=e=>t=>p.combineLatest([t.pipe(jo),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)),No=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 Uo=p.pipe(p.map(e=>e.touchedControls),p.distinctUntilChanged()),_o=e=>p.pipe(Uo,p.map(t=>t[e]),p.distinctUntilChanged()),Lo=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)),Ro=e=>e.pipe(Lo);let tr=!1;function Vo(){tr=!0}function Mo(){return tr}function Bo(e,t,r){if(!Mo())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=Io;exports.assertNoPropCollisions=Bo;exports.calculatedLayoutChildrenByUid$=No;exports.calculatedWidgetsByUid$=Po;exports.cloneObject=le;exports.dataByPath$=Do;exports.defineForm=Ar;exports.devToolsMiddleware=wo;exports.enableDevMode=Vo;exports.errorCodes=B;exports.filterTap=So;exports.formHealth=Ro;exports.getDirectionFromLanguage=vr;exports.identityTranslator=Ct;exports.injectedValidationByPath$=Fo;exports.isStandardValidateSuccess=gt;exports.makeRepeaterItemConfig=Ne;exports.shortUUID=Le;exports.standardValidate=mt;exports.touchedControlsByPath$=_o;exports.validationByPath$=To;
|
|
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 {};
|
|
@@ -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/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.
|
|
@@ -113,7 +113,7 @@ export type EventName = string;
|
|
|
113
113
|
/**
|
|
114
114
|
* Actions that can be called back from the event handler callback
|
|
115
115
|
*/
|
|
116
|
-
export type EventHandlerCallback = OVERRIDE_WIDGET_PROP;
|
|
116
|
+
export type EventHandlerCallback = OVERRIDE_WIDGET_PROP | INJECT_VALIDATION_ISSUES;
|
|
117
117
|
export type FormEvent<T = any> = {
|
|
118
118
|
/** The name of the form widget that dispatched the event. */
|
|
119
119
|
name: EventName;
|
|
@@ -125,6 +125,15 @@ export type FormEvent<T = any> = {
|
|
|
125
125
|
callback: (action: EventHandlerCallback) => void;
|
|
126
126
|
};
|
|
127
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
|
+
};
|
|
128
137
|
/**
|
|
129
138
|
* Control adapter templateData
|
|
130
139
|
*/
|
|
@@ -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;
|