@golemui/core 0.15.1 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/index.js +671 -668
- package/index.umd.cjs +8 -8
- package/lib/errors.d.ts +1 -0
- package/lib/utils/form.d.ts +1 -50
- package/lib/utils/justin.d.ts +1 -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 a=require("rxjs");require("@standard-schema/spec");function ft(e,t){const r=e["~standard"].validate(t);if(r instanceof Promise)throw new TypeError("Schema validation must be synchronous");return r}function ht(e){return e.issues===void 0}var
|
|
2
|
-
`),n=r.pop(),i=
|
|
3
|
-
${
|
|
4
|
-
`,""+i}${s}${u}`)}
|
|
5
|
-
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},
|
|
6
|
-
`,"/*":"*/"};let
|
|
7
|
-
`)for(;
|
|
8
|
-
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},lt=()=>{const e=[];for(let t="",r;(r=g.charCodeAt(h))!==Ae;)r?r===yn?(O(),t+=An[g[h]]||g[h],O()):r===gn&&g.charCodeAt(h+1)===mn?(t&&e.push([,t]),t="",O(2),e.push(v(0,125))):(t+=g[h],O(),r=g.charCodeAt(h),r===Ae&&t&&e.push([,t])):J("Unterminated template");return O(),e},$n=R[Ae];R[Ae]=(e,t)=>e&&t<pn?A.asi&&A.newline?void 0:(O(),["``",e,...lt()]):e?$n?.(e,t):(O(),(r=>r.length<2&&r[0]?.[0]===void 0?r[0]||[,""]:["`",...r])(lt()));l("`",(...e)=>(e=e.map(d),t=>e.map(r=>r(t)).join("")));l("``",(e,...t)=>{e=d(e);const r=[],n=[];for(const o of t)Array.isArray(o)&&o[0]===void 0?r.push(o[1]):n.push(d(o));const i=Object.assign([...r],{raw:r});return o=>e(o)(i,...n.map(s=>s(o)))});A.string["'"]=!0;A.number={"0x":16,"0b":2,"0o":8};const Sn={log:(e,t)=>(t?console.log(t,e):console.log(e),e)};function N(e,t,r,n,i){const o=A(vn(e));return d(o)({$form:t,$meta:r,$errors:n,$formIsInvalid:i,$log:Sn.log})===!0}function vn(e){return e.replace(/\?\.(\d+)/g,"?.[$1]").replace(/\.(\d+)/g,"[$1]")}const U=e=>{let t=e.formDef.states;if(!t||Object.keys(t).length===0||e.formHealth.status==="errored")return e;const{$formIsInvalid:r,$errors:n}=Ke(e);t=En(t);let i=[],o={status:"ok"};try{i=Object.keys(t).map(s=>{const u=t[s];let c;try{c=N(u,e.data,e.meta,n,r)}catch{c=!1}return c===!0?s:void 0}).filter(s=>s!==void 0)}catch(s){const u=s,c=ee.calculateCurrentStateError;o={status:"errored",message:`[${c}] ${u.message}`,code:c}}return{...e,currentStates:i,formHealth:o}};function En(e){const t={};function r(n){const i=n.split(":"),o=[];for(let s=0;s<i.length;s++)o.push(i.slice(0,s+1).join(":"));return o}for(const[n,i]of Object.entries(e)){const o=r(n),s=[];for(const u of o)e[u]&&s.push(`(${e[u]})`);t[n]=s.join(" && ")}return t}const rt=Symbol("filterMap.skip");function Mt(e,t){const r=[];for(let n=0;n<e.length;n++){const i=t(e[n],n,e);i!==rt&&r.push(i)}return r}function In(e,t,r){for(let n=0;n<e.length;n++)t(e[n],n,e)&&r(e[n],n,e)}function Cn(e,t,r,n){let i=n;for(let o=0;o<e.length;o++)t(e[o],o,e)&&(i=r(i,e[o],o,e));return i}function On(e,t,r){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!r(e[n],t[n],n,e,t))return!1;return!0}function Bt(e,t){const r=Ht(e.uid,t);return P(e)?{...e,uid:r,path:wn(e.path,t)}:{...e,uid:r}}function Ht(e,t){if(t.length===0)throw new Error("Repeater indexes cannot be an empty array");const r=t.reduce((n,i)=>`${n}[${i}]`,"");return`${e}${r}`}function wn(e,t){if(t.length===0)throw new Error("Repeater indexes cannot be an empty array");const r="items",n=e.split(`.${r}`),i=n.length-1;if(i!==t.length)throw new Error(`Path contains ${i} '${r}' occurrences, but ${t.length} indexes were provided.`);return n.reduce((o,s,u)=>u===0?s:`${o}.${t[u-1]}${s}`)}function le(e,t){let r=0;return e.replace(/\.items(\??)\./g,(n,i)=>{const o=t[r++];return o===void 0?n:`.${o}${i}.`})}const ae=(e,t)=>r=>e(r)?t(r):r,K=e=>e!==void 0&&typeof e=="object"&&e!==null&&"when"in e,L=e=>{const{$formIsInvalid:t,$errors:r}=Ke(e);return{...e,widgetFlags:{...Fn(e,r,t),...Pn(e,r,t)}}};function Fn(e,t,r){return Mt(Object.values(e.flatForm),n=>{if(n.uid?.includes("["))return rt;if(se(n)){const i=n({$form:e.data,errors:void 0,touched:void 0,translate:void 0});return i.uid=n.uid,i}return n}).filter(n=>!!(n.include&&("in"in n.include||"when"in n.include)||n.exclude&&("from"in n.exclude||"when"in n.exclude)||(P(n)||te(n))&&K(n.disabled)||P(n)&&K(n.readonly))).reduce((n,i)=>(n[i.uid]=n[i.uid]||{},i.include&&"in"in i.include?n[i.uid].hidden=!i.include.in.some(o=>e.currentStates.includes(o)):i.include&&"when"in i.include&&(n[i.uid].hidden=!N(i.include.when,e.data,e.meta,t,r)),i.exclude&&"from"in i.exclude?n[i.uid].hidden=i.exclude.from.some(o=>e.currentStates.includes(o)):i.exclude&&"when"in i.exclude&&(n[i.uid].hidden=N(i.exclude.when,e.data,e.meta,t,r)),(P(i)||te(i))&&K(i.disabled)&&(n[i.uid].disabled=N(i.disabled.when,e.data,e.meta,t,r)),P(i)&&K(i.readonly)&&(n[i.uid].readonly=N(i.readonly.when,e.data,e.meta,t,r)),n),{})}function Pn(e,t,r){return Cn(Object.values(e.flatForm),n=>!se(n)&&n.type==="repeater",(n,i)=>({...n,...Gt(e,i,[],t,r)}),{})}function Gt(e,t,r,n,i){const o=t.props.template,s=k(e.data,t.path);if(!Array.isArray(s))return{};const u={};return s.forEach((c,p)=>{const S=[...r,p];Ge([o]).forEach(m=>{let f;if(se(m)?(f=m({$form:e.data,errors:void 0,touched:void 0,translate:void 0}),f.uid=m.uid):f=m,f.type==="repeater"){const b=Bt(f,S);Object.assign(u,Gt(e,b,S,n,i));return}const w=Ht(f.uid,S);u[w]=u[w]||{},f.include&&"in"in f.include?u[w].hidden=!f.include.in.some(b=>e.currentStates.includes(b)):f.include&&"when"in f.include&&(u[w].hidden=!N(le(f.include.when,S),e.data,e.meta,n,i)),f.exclude&&"from"in f.exclude?u[w].hidden=f.exclude.from.some(b=>e.currentStates.includes(b)):f.exclude&&"when"in f.exclude&&(u[w].hidden=N(le(f.exclude.when,S),e.data,e.meta,n,i)),(P(f)||te(f))&&K(f.disabled)&&(u[w].disabled=N(le(f.disabled.when,S),e.data,e.meta,n,i)),P(f)&&K(f.readonly)&&(u[w].readonly=N(le(f.readonly.when,S),e.data,e.meta,n,i))})}),u}const j=e=>t=>({...t,calculatedWidgets:Dn(t,e)});function Dn(e,t){const{$formIsInvalid:r,$errors:n}=Ke(e),i=zn(e,t,r,n),o={};for(const s of Object.keys(e.calculatedWidgets)){if(e.widgetFlags[s]?.hidden)continue;const u=e.calculatedWidgets[s],c=u.source;if(se(c)){o[s]=Tn(s,c,e,t);continue}o[s]=Wn(u,c,e,i)}return o}function Tn(e,t,r,n){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});return i.uid=e,{source:t,current:i}}function Wn(e,t,r,n){const i=new Xn(t,e.current);return i.write("uid",t.uid),i.write("type",t.type),i.write("kind",t.kind),ir(t)?Rn(i,n):te(t)?kn(i,n):P(t)?_n(i,n):Te(t)&&jn(i,n),Nn(t,i,n,r),(te(t)||P(t))&&Un(t,i,n),Te(t)&&Ln(t,i,r),i.changed?{source:e.source,current:i.current}:e}function Rn(e,t){E(e,t,"size"),E(e,t,"include"),E(e,t,"exclude")}function kn(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 _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,"readonly"),E(e,t,"validator"),E(e,t,"path"),E(e,t,"defaultValue")}function jn(e,t){E(e,t,"size"),E(e,t,"include"),E(e,t,"exclude")}function Nn(e,t,r,n){const i=n.widgetPropOverrides[e.uid]??{},o={...e.props??{},...i};for(const s of zt(Object.keys(o)))Vn(t,r,s)}function Un(e,t,r){const n=e.on??{};for(const i of zt(Object.keys(n)))Mn(t,r,i)}function Ln(e,t,r){const n=qn(e.uid),i=Qn(e.children,n,r.widgetFlags);t.current.children=i;const o=t.previous.children??[];o.length===i.length&&i.every((u,c)=>o[c]&&o[c].uid===i[c].uid)||t.markChanged()}function E(e,t,r){const n=e.source;if(!Jn(n,r))return;const i=it(n,r,t.sortedStates);let o;switch(r){case"disabled":case"readonly":o=Hn(i,t,e.source.uid,r);break;default:o=Xt(i,t)}e.write(r,o)}function Vn(e,t,r){const n=e.source.props,i=it(n,r,t.sortedStates);let o=Xt(i,t);const s=t.widgetPropOverrides[e.source.uid]?.[r];s!==void 0&&(o=s),e.write(`props.${r}`,o)}function Mn(e,t,r){const n=e.source.on,i=it(n,r,t.sortedStates);e.write(`on.${r}`,Gn(i,t))}function nt(e,t){return e({$form:t.$form,translate:t.localization.translate})}function Bn(e,t){return t.localization.translate(e.key,Kn(e.params,t),e.default)}function Kt(e,t){return Ir(e,{resolveFormPath:r=>k(t.$form,r)??e,resolveMetaPath:r=>k(t.$meta,r)??e,resolveErrorsPath:r=>k(t.$errors,r)??e,resolveFormIsInvalid:()=>String(t.$formIsInvalid)})}function Xt(e,t){return typeof e=="function"?nt(e,t):gr(e)?Bn(e,t):typeof e=="string"?Kt(e,t):e}function Hn(e,t,r,n){return typeof e=="function"?nt(e,t):K(e)?t.widgetFlags[r]?.[n]:typeof e=="string"?Kt(e,t):e}function Gn(e,t){return typeof e=="function"?nt(e,t):e}function it(e,t,r){if(e){for(const n of r){const i=e[`${t}.${n}`];if(i!==void 0)return i}return e[t]}}function Kn(e,t){return e&&Object.keys(e).reduce((r,n)=>{const i=String(e[n]);return Sr(i)?r[n]=Cr(i,{resolveFormPath:o=>k(t.$form,o)??i,resolveMetaPath:o=>k(t.$meta,o)??i,resolveErrorsPath:o=>k(t.$errors,o)??i,resolveFormIsInvalid:()=>t.$formIsInvalid}):r[n]=i,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),k(this.previous,t)!==r&&(this._changed=!0)}}function zn(e,t,r,n){return{sortedStates:[...e.currentStates].sort((i,o)=>o.length-i.length),widgetPropOverrides:e.widgetPropOverrides,widgetFlags:e.widgetFlags,$form:e.data,$meta:e.meta,$formIsInvalid:r,$errors:n,localization:t}}function Jn(e,t){if(t in e)return!0;const r=`${t}.`;return Object.keys(e).some(n=>n.startsWith(r))}function zt(e){return Array.from(new Set(e.map(t=>t.split(".")[0])))}function Qn(e,t,r){const n=t.map(i=>`[${i}]`).join("");return e.filter(i=>{const o=i.uid+n,s=r[o];return!s||s.hidden!==!0})}const qn=e=>[...e.matchAll(/\[(\d+)\]/g)].map(t=>parseInt(t[1],10)),Yn=({lang:e},t)=>{const r={...yt(e),formName:t.payload.formName};let n=t.payload.formDef,i={status:"ok"};if(typeof n=="string"){try{n=JSON.parse(n)}catch(u){const c=u,p=ee.initializeParseError;i={status:"errored",message:`[${p}] ${c.message}`,code:p}}if(i.status==="errored")return{...r,formHealth:i}}if(Array.isArray(n.form)){const u=n,c=u.form;u.form={uid:"",type:"flex",kind:"layout",children:c}}const o=mt.decode(n);if(o.isOk()){i={status:"ok"};let u={};try{u=Ge([o.value.form]).reduce((c,p)=>{const S=p.uid;if(c[S])throw{existingWidget:c[S],newWidget:p};return c[S]=p,c},{})}catch(c){const p=ee.initializeUidCollisionError;i={status:"errored",message:`[${p}] ${Zn(c.existingWidget,c.newWidget)}`,code:p},u={}}return{...r,formDef:o.value,flatForm:u,formHealth:i}}const s=ee.initializeUnknownError;return{...r,formHealth:{status:"errored",message:`[${s}] ${o.error}`,code:s}}};function Zn(e,t){const r=n=>P(n)?` at "${n.path}"`:"";return`Duplicate UID "${t.uid}": Assigned to widget "${e.type}"${r(e)} and "${t.type}"${r(t)}.`}function xn(e,t){return{...e,injectedValidations:{...e.injectedValidations,[t.payload.path]:t.payload.issues}}}const bn=(e,{payload:t})=>{let r;if("path"in t){if(r=Object.values(e.calculatedWidgets).find(({source:o})=>P(o)&&o.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,i=e.widgetPropOverrides[n]||{};return{...e,widgetPropOverrides:{...e.widgetPropOverrides,[n]:{...i,[t.prop]:t.value}}}};function ei(e,t){return{...e,widgetFlags:{...ce(e.widgetFlags,t.payload.uid)},calculatedWidgets:{...ce(e.calculatedWidgets,t.payload.uid)},widgetPropOverrides:{...ce(e.widgetPropOverrides,t.payload.uid)},touchedControls:{..._(e.touchedControls,r=>{const n=e.flatForm[t.payload.uid];return n&&P(n)?ce(r,n.path):r})}}}const ti=(e,t)=>({...e,data:{...t.payload.data}}),ri=(e,t)=>({...e,formHealth:t.payload.formHealth}),ni=(e,t)=>({...e,lang:t.payload.lang}),ii=(e,t)=>({...e,meta:{...t.payload.meta}}),oi=(e,t)=>{const r=k(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},Fe=(e,t)=>r=>{const n=Mt(Object.values(r.calculatedWidgets),({current:o})=>P(o)?o:rt),i=r.validations;return{...r,validations:n.reduce((o,s)=>{if(o[s.path]=null,s.validator){const u=e(s.validator,t),c=k(r.data,s.path),p=ft(u,c);o[s.path]=ht(p)?null:p.issues.map(S=>S.message)}return Array.isArray(o[s.path])&&Array.isArray(i[s.path])&&On(o[s.path],i[s.path],(u,c)=>u===c)&&(o[s.path]=i[s.path]),o},{})}},si=({validators:e,validateOn:t,localization:r})=>(n,i)=>{switch(i.type){case"INITIALIZE":return Yn(n,i);case"SET_DATA":return _(ti(n,i),U,L,j(r));case"SET_META":return _(ii(n,i),U,L,j(r));case"SET_LANGUAGE":return _(ni(n,i),j(r));case"ADD_WIDGET":return _(Ar(n,i),ae(Pe,U),ae(Pe,L),ae(Pe,j(r)));case"REMOVE_WIDGET":return _(ei(n,i),U,L,j(r));case"SET_WIDGET_INITIAL_DATA":case"SET_WIDGET_DATA":return _(oi(n,i),U,L,j(r));case"OVERRIDE_WIDGET_PROP":return _(bn(n,i),U,L,j(r),ae(o=>{let s=!1,u="";"path"in i.payload?(s=!0,u=i.payload.path):P(o.calculatedWidgets[i.payload.uid].current)&&(s=!0,u=o.calculatedWidgets[i.payload.uid].current.path);const c=s&&o.touchedControls[u];return o.touched&&c},Fe(e,r)));case"SET_FORM_HEALTH":return ri(n,i);case"VALIDATE_ALL":return _({...n,touched:!0,touchedControls:Object.keys(n.calculatedWidgets).reduce((o,s)=>{const u=n.calculatedWidgets[s].source;return P(u)&&(o[u.path]=!0),o},{})},Fe(e,r),U,L,j(r),at);case"ATTEMPT_VALIDATION":{const o=i.payload.reason,s=i.payload.path;return t==="eager"||o===t||t.includes(o)?_({...n,touched:!0,touchedControls:{...n.touchedControls,[s]:!0}},Fe(e,r),U,L,j(r),c=>{const p=i.payload.uid,S=c.calculatedWidgets[p],m=S.source;if(se(m)){const f=m({$form:c.data,errors:c.validations[s],touched:!0,translate:r.translate});return{...c,calculatedWidgets:{...c.calculatedWidgets,[p]:{source:S.source,current:f}}}}return c},at):n}case"INJECT_VALIDATION_ISSUES":return xn(n,i);default:return yr(i)}},Pe=e=>e.formHealth.status==="ok";function at(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(i=>e.injectedValidations[i]!==null&&Array.isArray(e.injectedValidations[i]));return n!==void 0?{...e,isFormValid:!1}:(n=r.find(i=>e.validations[i]!==null&&Array.isArray(e.validations[i])),n!==void 0?{...e,isFormValid:!1}:{...e,isFormValid:!0})}function di(e=[],t,r,n){const i=new a.BehaviorSubject(yt(n.lang)),o=i.asObservable().pipe(a.distinctUntilChanged()),s=si({validators:t,validateOn:r,localization:n});function u(m){const f=i.getValue(),w=s(f,m);i.next(w)}let c=u;const p={getState:()=>i.getValue(),dispatch:m=>c(m)};return c=e.map(m=>m(p)).reduceRight((m,f)=>f(m),u),{state$:o,dispatch:c,getState:()=>i.getValue()}}class ui{constructor(){this.widgetRegistry=new Re,this.store={},this.events$=new a.Subject,this.submit$=new a.Subject,this.uuid=crypto.randomUUID(),this.itemRenderers={},this.dependencies={}}initialize(t,r=[],n,i,o,s=At(),u){this.localization=s,this.dependencies=u,this.widgetRegistry.setWidgetLoaders(t),this.itemRenderers=o,this.store=di(r,n,i,s)}emitEvent(t,r,n){const o=this.store.getState().currentStates.filter(s=>r.on?.[`${t}.${s}`]!==void 0);if(o.length>0)o.forEach(s=>{const u=r.on?.[`${t}.${s}`];this.attemptValidation(t,r),u&&this.events$.next({name:u,data:this.store.getState().data,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:this.store.getState().data,detail:n,callback:u=>{this.store.dispatch(u)}})}}emitSubmitEvent(){this.store.dispatch({type:"VALIDATE_ALL"}),this.store.getState().isFormValid&&this.submit$.next({data:this.store.getState().data,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 ci(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()),i=>o=>{i(o),n&&n.send(o,t.getState())}}}const li=a.pipe(a.map(e=>e.data),a.distinctUntilChanged()),ai=e=>a.pipe(li,a.map(t=>k(t,e)),a.distinctUntilChanged()),fi=a.pipe(a.filter(e=>e.touched===!0),a.map(e=>e.validations),a.distinctUntilChanged()),hi=e=>a.pipe(fi,a.map(t=>t[e]),a.distinctUntilChanged()),pi=a.pipe(a.filter(e=>e.touched===!0),a.map(e=>e.injectedValidations),a.distinctUntilChanged()),gi=e=>a.pipe(pi,a.map(t=>t[e]),a.distinctUntilChanged(),a.startWith(null)),mi=a.pipe(a.map(e=>e.lang),a.distinctUntilChanged()),Jt=a.pipe(a.map(e=>e.calculatedWidgets),a.distinctUntilChanged()),yi=e=>t=>a.combineLatest([t.pipe(mi),t.pipe(Jt)]).pipe(a.map(([r,n])=>({lang:r,widget:n[e]})),a.filter(r=>r.widget!==void 0),a.distinctUntilChanged((r,n)=>r.lang===n.lang&&r.widget===n.widget),a.map(r=>r.widget.current)),Ai=e=>a.pipe(Jt,a.map(t=>t[e]),a.filter(t=>t!==void 0),a.map(t=>t.current.children),a.distinctUntilChanged());a.pipe(a.map(e=>e.widgetFlags),a.distinctUntilChanged());const $i=a.pipe(a.map(e=>e.touchedControls),a.distinctUntilChanged()),Si=e=>a.pipe($i,a.map(t=>t[e]),a.distinctUntilChanged()),vi=a.pipe(a.map(e=>e.formHealth),a.distinctUntilChanged((e,t)=>e.status!==t.status?!1:e.status==="errored"&&t.status==="errored"?e.message===t.message&&e.code===t.code:!0)),Ei=e=>e.pipe(vi);let Qt=!1;function Ii(){Qt=!0}function Ci(){return Qt}function Oi(e,t,r){if(!Ci())return;const n=Object.keys(t??{}).filter(i=>i in r);if(n.length>0)throw new Error(`[GolemUI] Widget "${e}": prop keys [${n.join(", ")}] collide with widget fields`)}exports.FormContext=ui;exports.assertNoPropCollisions=Oi;exports.calculatedLayoutChildrenByUid$=Ai;exports.calculatedWidgetsByUid$=yi;exports.cloneObject=ke;exports.dataByPath$=ai;exports.defineForm=pr;exports.devToolsMiddleware=ci;exports.enableDevMode=Ii;exports.errorCodes=ee;exports.filterTap=In;exports.formHealth=Ei;exports.getDirectionFromLanguage=mr;exports.identityTranslator=At;exports.injectedValidationByPath$=gi;exports.isStandardValidateSuccess=ht;exports.makeRepeaterItemConfig=Bt;exports.shortUUID=Le;exports.standardValidate=ft;exports.touchedControlsByPath$=Si;exports.validationByPath$=hi;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("rxjs");require("@standard-schema/spec");function ft(e,t){const r=e["~standard"].validate(t);if(r instanceof Promise)throw new TypeError("Schema validation must be synchronous");return r}function ht(e){return e.issues===void 0}var Yt=class{constructor(e){this.value=e}map(e){return F(e(this.value))}isOk(){return!0}},Zt=class{constructor(e){this.error=e}map(e){return C(this.error)}isOk(){return!1}};function F(e){return new Yt(e)}function C(e){return new Zt(e)}var T=class Te{constructor(t){this.decodeFn=t,this["~standard"]={version:1,vendor:"ts.data.json",validate:r=>{let n=this.decode(r);return n.isOk()?{value:n.value}:{issues:[{message:n.error}]}}},this.decodeToPromise=this.decodePromise,this.chain=this.flatMap}parse(t){let r=this.decode(t);if(r.isOk())return r.value;throw r.error}decode(t){return this.decodeFn(t)}decodePromise(t){return new Promise((r,n)=>{let i=this.decode(t);return i.isOk()?r(i.value):n(i.error)})}map(t){return new Te(r=>{let n=this.decodeFn(r);return n.isOk()?F(t(n.value)):C(n.error)})}flatMap(t){return new Te(r=>{let n=this.decodeFn(r);return n.isOk()?t(n.value).decode(r):C(n.error)})}},bt=(e,t,r)=>`<${e}> decoder failed at index "${t}" with error: ${r}`,q=(e,t)=>`${JSON.stringify(e)} is not a valid ${t}`;function Ne(e,t){return new T(r=>{if(r instanceof Array){let n=[];for(let i=0;i<r.length;i++){let o=e.decode(r[i]);if(o.isOk())n.push(o.value);else return C(bt(t,i,o.error))}return F(n)}else return C(q(r,"array"))})}function xt(){return new T(e=>typeof e=="boolean"?F(e):C(q(e,"boolean")))}function pt(e){return new T(t=>e().decode(t))}var er=(e,t)=>`${JSON.stringify(e)} is not exactly ${JSON.stringify(t)}`;function J(e){return new T(t=>t===e?F(e):C(er(t,e)))}function $e(){return new T(e=>typeof e=="number"?F(e):C(q(e,"number")))}var tr=(e,t,r)=>`<${e}> decoder failed at key "${t}" with error: ${r}`;function re(e,t){return new T(r=>{if(r!==null&&typeof r=="object"){let n={};for(let i in e)if(Object.prototype.hasOwnProperty.call(e,i)){let o,s=e[i];if(s instanceof T?o=s.decode(r[i]):o=s.decoder.decode(r[s.fromKey]),o.isOk())n[i]=o.value;else return C(tr(t,i,o.error))}return F(n)}else return C(q(r,t))})}var rr=(e,t)=>`<${e}> decoder failed because ${JSON.stringify(t)} can't be decoded with any of the provided oneOf decoders`;function K(e,t){return new T(r=>{for(let n=0;n<e.length;n++){let i=e[n].decode(r);if(i.isOk())return i}return C(rr(t,r))})}function $(e){return new T(t=>t===void 0?F(void 0):e.decode(t))}var nr=(e,t,r)=>`<${e}> record decoder failed at key "${t}" with error: ${r}`;function ir(e,t){return new T(r=>{if(r!==null&&typeof r=="object"){let n={};for(let i in r)if(Object.prototype.hasOwnProperty.call(r,i)){let o=e.decode(r[i]);if(o.isOk())n[i]=o.value;else return C(nr(t,i,o.error))}return F(n)}else return C(q(r,t))})}function w(){return new T(e=>typeof e=="string"?F(e):C(q(e,"string")))}function G(){return new T(e=>F(e))}function ne(e,t){return new T(r=>{if(typeof r!="object"||r===null)return C(`<${t}> failed. Expected object literal, got "${typeof r}"`);const n={};for(const[i,o]of Object.entries(e)){const s=o.decoder.decode(r[i]);if(!s.isOk())return C(`<${t}> failed at "${i}" with ${s.error}`);if(n[i]=s.value,o.suffixed){for(const[u,c]of Object.entries(r))if(u.startsWith(i+".")){const p=o.decoder.decode(c);if(!p.isOk())return C(`<${t}> failed at "${u}" with ${p.error}`);n[u]=p.value}}}return F(n)})}const Ve=()=>crypto.randomUUID().slice(0,8),or=e=>typeof e!="function"&&e.kind==="display",x=e=>typeof e!="function"&&e.kind==="action",D=e=>typeof e!="function"&&e.kind==="input",Fe=e=>typeof e!="function"&&e.kind==="layout",ie=e=>typeof e=="function",sr=re({in:Ne(w(),"In[]")},"In"),Le=re({when:w()},"When"),Ae=K([sr,Le],"In | When"),dr=re({from:Ne(w(),"From[]")},"From"),Se=K([dr,Le],"Exclude"),We=K([xt(),Le],"Bool | When"),ur=new T(e=>{const t=typeof e;return t==="function"?F(e):C(`Expected a function, got '${t}'`)}),V=e=>K([e,ur],""),Re=ne({load:{suffixed:!0,decoder:V($(w()))},click:{suffixed:!0,decoder:V($(w()))},change:{suffixed:!0,decoder:V($(w()))},filter:{suffixed:!0,decoder:V($(w()))},blur:{suffixed:!0,decoder:V($(w()))}},"On"),cr=re({key:w(),default:$(w()),params:G()},"TranslationConfig"),mt=K([w(),cr],"Localizable"),ve=$(w()).map(e=>e||Ve()),lr=ne({kind:{decoder:J("display")},uid:{decoder:ve},type:{decoder:w()},size:{suffixed:!0,decoder:$($e())},include:{decoder:$(Ae)},exclude:{decoder:$(Se)},props:{decoder:$(G())}},"DisplayWidget"),ar=ne({kind:{decoder:J("action")},uid:{decoder:ve},type:{decoder:w()},actionType:{decoder:$(K([J("button"),J("submit")],"button | submit "))},size:{suffixed:!0,decoder:$($e())},include:{decoder:$(Ae)},exclude:{decoder:$(Se)},label:{suffixed:!0,decoder:V(mt)},disabled:{suffixed:!0,decoder:$(We)},on:{decoder:$(Re)},props:{decoder:$(G())}},"ActionWidget"),fr=new T(e=>{const t=typeof e;if(t==="function"){const r=e,n=r(void 0);return r.uid=n.uid||Ve(),r.type=n.type,r.path=n.path,F(r)}else return C(`Expected a function, got '${t}'`)}),hr=ne({kind:{decoder:J("input")},uid:{decoder:ve},type:{decoder:w()},size:{suffixed:!0,decoder:$($e())},include:{decoder:$(Ae)},exclude:{decoder:$(Se)},disabled:{suffixed:!0,decoder:$(We)},readonly:{suffixed:!0,decoder:$(We)},on:{decoder:$(Re)},props:{decoder:$(G())},label:{suffixed:!0,decoder:V($(mt))},path:{decoder:w()},defaultValue:{decoder:$(G())},validator:{suffixed:!0,decoder:V($(G()))}},"InputWidget").map(e=>{const t={...e};if(e.uid||(t.uid=`${e.path}-${e.type}`),e.type==="repeater"){const r=e.props;r.template=Me.parse(r.template)}return t}),pr=pt(()=>K([fr,hr,Me,lr,ar],"FormWidget")),Me=ne({kind:{decoder:J("layout")},uid:{decoder:ve},type:{decoder:w()},size:{suffixed:!0,decoder:$($e())},include:{decoder:$(Ae)},exclude:{decoder:$(Se)},props:{decoder:$(G())},on:{decoder:$(Re)},children:{decoder:Ne(pr,"FormWidget[]")}},"LayoutWidget"),B=class B{constructor(){this.widgetLoaders={},this._ready=!1}get ready(){return this._ready}setWidgetLoaders(t){this.widgetLoaders=t,this._ready=!0}async loadWidget(t){const r=this.widgetLoaders[t];if(!B.sharedCache.has(r)){const n=r().catch(i=>(B.sharedCache.delete(r),Promise.reject(i)));B.sharedCache.set(r,n)}return B.sharedCache.get(r)}};B.sharedCache=new Map;let ke=B;function mr(e){return{...e,form:{uid:"",type:"flex",kind:"layout",children:e.form}}}const gt=re({states:$(ir(w(),"states")),form:pt(()=>Me)},"FormDef"),yt=e=>({formName:"",formDef:gt.parse({form:{kind:"layout",type:"flex",children:[]}}),flatForm:{},currentStates:[],calculatedWidgets:{},validations:{},touchedControls:{},injectedValidations:{},isFormValid:!0,widgetFlags:{},widgetPropOverrides:{},data:{},meta:{},formHealth:{status:"ok"},touched:!1,lang:e}),gr=e=>!(typeof e!="object"||e===null||typeof e.key!="string");function yr(e){const t=new Intl.Locale(e).maximize().script;return["Arab","Hebr","Thaa","Syrc","Tfng","Adlm","Rohg"].includes(t||"")?"rtl":"ltr"}const $t=(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(i=>i(e))}}},$r=e=>{throw new Error(`Unhandled case: ${JSON.stringify(e)}`)};function P(e,...t){return t.reduce((r,n)=>n(r),e)}function Ar(e,t){const r=t.payload.widget.uid;if(!r)throw new Error("addWidget: widget must have a uid");return{...e,calculatedWidgets:{...e.calculatedWidgets,[r]:{source:t.payload.widget,current:{}}}}}const Q={calculateCurrentStateError:10,initializeParseError:20,initializeUidCollisionError:21,initializeUnknownError:22,widgetCouldNotBeLoaded:30,resolveStringInterpolationError:40},oe=(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)},Be=(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 i=e;for(let s=0;s<n.length-1;s++){const u=n[s],c=n[s+1];(i[u]==null||typeof i[u]!="object")&&(i[u]=Sr(c)?[]:{}),i=i[u]}const o=n[n.length-1];return i[o]=r,e};function Sr(e){const t=Number(e);return Number.isInteger(t)&&t>=0&&t.toString()===e}const ue=(e,t)=>(delete e[t],e);function Pe(e){if(e===null||typeof e!="object")return e;if(Array.isArray(e))return e.map(r=>Pe(r));const t={};for(const r of Object.keys(e))t[r]=Pe(e[r]);return t}function He(e){return e.flatMap(t=>[t,...Fe(t)?He(t.children):[]])}function Ge(e){return Object.entries(e.validations).reduce((r,[n,i])=>(i!==null&&(r.$formIsInvalid=!0,Be(r.$errors,n,[...i])),r),{$formIsInvalid:!1,$errors:{}})}const Ke=32;let je,h,m,y=e=>(h=0,m=e,y.newline=!1,e=v(),m[h]?X():e||""),X=(e="Unexpected token",t=h,r=m.slice(0,t).split(`
|
|
2
|
+
`),n=r.pop(),i=m.slice(Math.max(0,t-40),t),o="̭",s=(m[t]||" ")+o,u=m.slice(t+1,t+20))=>{throw SyntaxError(`${e} at ${r.length+1}:${n.length+1}
|
|
3
|
+
${m[t-41]!==`
|
|
4
|
+
`,""+i}${s}${u}`)},At=(e,t=h)=>(Array.isArray(e)&&(e.loc=t),e),Y=(e,t=h,r)=>{for(;r=e(m.charCodeAt(h));)h+=r;return m.slice(t,h)},I=(e=1)=>m[h+=e],_e=e=>h=e,v=(e=0,t)=>{let r,n,i,o,s;for(t&&y.asi&&(y.newline=!1);(r=y.space())&&(s=y.newline,1)&&r!==t&&(i=(n&&r===91&&je&&y.asi?.(n,e,v)||null)??((o=k[r])&&o(n,e))??(n&&s&&y.asi?.(n,e,v))??(!n&&Y(y.id)));)n=i;return t&&(r==t?(h++,t===125&&y.asi&&(y.newline=!0)):X("Unclosed "+String.fromCharCode(t-(t>42?2:1)))),n},R=(e,t=h)=>{for(je=!1;(e=m.charCodeAt(h))<=Ke;)y.asi&&e===10&&(y.newline=je=!0),h++;return e},vr=(e=h)=>{for(;m.charCodeAt(e)<=Ke;)e++;return m.charCodeAt(e)};y.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 Er=(e,t=e.length)=>m.substr(h,t)===e&&!y.id(m.charCodeAt(h+t)),k=[],ot={},W=(e,t=Ke,r,n=e.charCodeAt(0),i=e.length,o=k[n],s=e.toUpperCase()!==e,u,c)=>(t=ot[e]=!o&&ot[e]||t,k[n]=(p,S,g,f=h)=>(u=g,(g?e==g:(i<2||e.charCodeAt(1)===m.charCodeAt(h+1)&&(i<3||m.substr(h,i)==e))&&(!s||!y.id(m.charCodeAt(h+i)))&&(u=g=e))&&S<t&&(h+=i,(c=r(p))?At(c,f):(h=f,u=0,!s&&!o&&!p&&X()),c)||o?.(p,S,u))),A=(e,t,r=!1)=>W(e,t,n=>n&&(i=>i&&[e,n,i])(v(t-(r?.5:0)))),M=(e,t,r)=>W(e,t,n=>!n&&(n=v(t-.5))&&[e,n]),se=(e,t)=>W(e,200,r=>!r&&[,t]),St=(e,t,r)=>W(e,t,(n,i)=>(i=v(t-(r?.5:0)),n?.[0]!==e&&(n=[e,n||null]),i?.[0]===e?n.push(...i.slice(1)):n.push(i||null),n)),Xe=(e,t)=>W(e[0],t,r=>!r&&[e,v(0,e.charCodeAt(1))||null]),vt=(e,t)=>W(e[0],t,r=>r&&[e,r,v(0,e.charCodeAt(1))||null]),de=(e,t,r,n=e.charCodeAt(0),i=e.length,o=k[n],s)=>k[n]=(u,c,p,S=h)=>!u&&(p?e==p:(i<2||m.substr(h,i)==e)&&(p=e))&&c<t&&!y.id(m.charCodeAt(h+i))&&(!y.prop||y.prop(h+i))&&(_e(h+i),(s=r())?At(s,S):_e(S),s)||o?.(u,c,p);Object.defineProperty(y,"space",{configurable:!0,enumerable:!0,get:()=>R,set:e=>R=e});const Ue={},l=(e,t,r=Ue[e])=>Ue[e]=(...n)=>t(...n)||r?.(...n),d=e=>Array.isArray(e)?e[0]==null?(t=>()=>t)(e[1]):Ue[e[0]]?.(...e.slice(1))??X(`Unknown operator: ${e[0]}`,e?.loc):e===void 0?()=>{}:t=>t?.[e],fe=46,ee=48,he=57,Cr=69,wr=101,Ir=43,Or=45,ae=95,Et=110,Dr=97,Tr=102,Fr=65,Wr=70,Ct=e=>e.indexOf("_")<0?e:e.replaceAll("_",""),ze=e=>{let t=Ct(Y(r=>r===fe&&m.charCodeAt(h+1)!==fe||r>=ee&&r<=he||r===ae||((r===Cr||r===wr)&&((r=m.charCodeAt(h+1))>=ee&&r<=he||r===Ir||r===Or)?2:0)));return m.charCodeAt(h)===Et?(I(),[,BigInt(t)]):(e=+t)!=e?X():[,e]},kr={2:e=>e===48||e===49||e===ae,8:e=>e>=48&&e<=55||e===ae,16:e=>e>=ee&&e<=he||e>=Dr&&e<=Tr||e>=Fr&&e<=Wr||e===ae};y.number=null;k[fe]=e=>!e&&m.charCodeAt(h+1)!==fe&&ze();for(let e=ee;e<=he;e++)k[e]=t=>t?void 0:ze();k[ee]=e=>{if(e)return;const t=y.number;if(t){for(const[r,n]of Object.entries(t))if(r[0]==="0"&&m[h+1]?.toLowerCase()===r[1]){I(2);const i=Ct(Y(kr[n]));return m.charCodeAt(h)===Et?(I(),[,BigInt("0"+r[1]+i)]):[,parseInt(i,n)]}}return ze()};const Pr=92,st=34,dt=39,jr={n:`
|
|
5
|
+
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},wt=e=>(t,r,n="")=>{if(!(t||!y.string?.[String.fromCharCode(e)]))return I(),Y(i=>i-e&&(i===Pr?(n+=jr[m[h+1]]||m[h+1],2):(n+=m[h],1))),m[h]===String.fromCharCode(e)?I():X("Bad string"),[,n]};k[st]=wt(st);k[dt]=wt(dt);y.string={'"':!0};const _r=20;"= += -= *= /= %= |= &= ^= >>= <<=".split(" ").map(e=>A(e,_r,!0));const It=(e,t,r,n)=>typeof e=="string"?i=>t(i,e,i):e[0]==="."?(r=d(e[1]),n=e[2],i=>t(r(i),n,i)):e[0]==="[]"&&e.length===3?(r=d(e[1]),n=d(e[2]),i=>t(r(i),n(i),i)):e[0]==="()"&&e.length===2?It(e[1],t):(()=>{throw Error("Invalid assignment target")})(),ut={"=":(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 ut)l(e,(t,r)=>(r=d(r),It(t,(n,i,o)=>ut[e](n,i,r(o)))));const Ur=30,Nr=40,Vr=140;M("!",Vr);A("||",Ur);A("&&",Nr);l("!",e=>(e=d(e),t=>!e(t)));l("||",(e,t)=>(e=d(e),t=d(t),r=>e(r)||t(r)));l("&&",(e,t)=>(e=d(e),t=d(t),r=>e(r)&&t(r)));const Lr=50,Rr=60,Mr=70,Ot=100,Br=140;A("|",Lr);A("&",Mr);A("^",Rr);A(">>",Ot);A("<<",Ot);M("~",Br);l("~",e=>(e=d(e),t=>~e(t)));l("|",(e,t)=>(e=d(e),t=d(t),r=>e(r)|t(r)));l("&",(e,t)=>(e=d(e),t=d(t),r=>e(r)&t(r)));l("^",(e,t)=>(e=d(e),t=d(t),r=>e(r)^t(r)));l(">>",(e,t)=>(e=d(e),t=d(t),r=>e(r)>>t(r)));l("<<",(e,t)=>(e=d(e),t=d(t),r=>e(r)<<t(r)));const Ee=90;A("<",Ee);A(">",Ee);A("<=",Ee);A(">=",Ee);l(">",(e,t)=>(e=d(e),t=d(t),r=>e(r)>t(r)));l("<",(e,t)=>(e=d(e),t=d(t),r=>e(r)<t(r)));l(">=",(e,t)=>(e=d(e),t=d(t),r=>e(r)>=t(r)));l("<=",(e,t)=>(e=d(e),t=d(t),r=>e(r)<=t(r)));const Dt=80;A("==",Dt);A("!=",Dt);l("==",(e,t)=>(e=d(e),t=d(t),r=>e(r)==t(r)));l("!=",(e,t)=>(e=d(e),t=d(t),r=>e(r)!=t(r)));const Tt=110,Je=120,Ft=140;A("+",Tt);A("-",Tt);A("*",Je);A("/",Je);A("%",Je);M("+",Ft);M("-",Ft);l("+",(e,t)=>t!==void 0?(e=d(e),t=d(t),r=>e(r)+t(r)):(e=d(e),r=>+e(r)));l("-",(e,t)=>t!==void 0?(e=d(e),t=d(t),r=>e(r)-t(r)):(e=d(e),r=>-e(r)));l("*",(e,t)=>(e=d(e),t=d(t),r=>e(r)*t(r)));l("/",(e,t)=>(e=d(e),t=d(t),r=>e(r)/t(r)));l("%",(e,t)=>(e=d(e),t=d(t),r=>e(r)%t(r)));const pe=150;W("++",pe,e=>e?["++",e,null]:["++",v(pe-1)]);W("--",pe,e=>e?["--",e,null]:["--",v(pe-1)]);const Qe=(e,t,r,n)=>typeof e=="string"?i=>t(i,e):e[0]==="."?(r=d(e[1]),n=e[2],i=>t(r(i),n)):e[0]==="[]"&&e.length===3?(r=d(e[1]),n=d(e[2]),i=>t(r(i),n(i))):e[0]==="()"&&e.length===2?Qe(e[1],t):(()=>{throw Error("Invalid increment target")})();l("++",(e,t)=>Qe(e,t===null?(r,n)=>r[n]++:(r,n)=>++r[n]));l("--",(e,t)=>Qe(e,t===null?(r,n)=>r[n]--:(r,n)=>--r[n]));const Hr=5,Gr=10;St(",",Gr);St(";",Hr,!0);const Wt=(...e)=>(e=e.map(d),t=>{let r;for(const n of e)r=n(t);return r});l(",",Wt);l(";",Wt);const Kr=170;Xe("()",Kr);const L=e=>e?.[0]==="_"&&e[1]==="_"||e==="constructor"||e==="prototype",qe=170;vt("[]",qe);A(".",qe);vt("()",qe);const me=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=d(r[1]),n=>r(n)):(r=d(r),n=>[r(n)])),r=>e.flatMap(n=>n(r))):(t==null&&me("Missing index"),e=d(e),t=d(t),r=>{const n=t(r);return L(n)?void 0:e(r)[n]}));l(".",(e,t)=>(e=d(e),t=t[0]?t:t[1],L(t)?()=>{}:r=>e(r)[t]));l("()",(e,t)=>{if(t===void 0)return e==null?me("Empty ()"):d(e);const r=i=>i?.[0]===","&&i.slice(1).some(o=>o==null||r(o));r(t)&&me("Empty argument");const n=t?t[0]===","?(t=t.slice(1).map(d),i=>t.map(o=>o(i))):(t=d(t),i=>[t(i)]):()=>[];return Ye(e,(i,o,s)=>i[o](...n(s)))});const z=e=>typeof e=="string"||Array.isArray(e)&&(e[0]==="."||e[0]==="?."||e[0]==="[]"&&e.length===3||e[0]==="?.[]"||e[0]==="()"&&e.length===2&&z(e[1])||e[0]==="{}"),Ye=(e,t,r,n)=>e==null?me("Empty ()"):e[0]==="()"&&e.length==2?Ye(e[1],t):typeof e=="string"?i=>t(i,e,i):e[0]==="."?(r=d(e[1]),n=e[2],i=>t(r(i),n,i)):e[0]==="?."?(r=d(e[1]),n=e[2],i=>{const o=r(i);return o==null?void 0:t(o,n,i)}):e[0]==="[]"&&e.length===3?(r=d(e[1]),n=d(e[2]),i=>t(r(i),n(i),i)):e[0]==="?.[]"?(r=d(e[1]),n=d(e[2]),i=>{const o=r(i);return o==null?void 0:t(o,n(i),i)}):(e=d(e),i=>t([e(i)],0,i)),Z=Ye,Xr=32,zr=y.space;y.comment??={"//":`
|
|
6
|
+
`,"/*":"*/"};let we;y.space=()=>{we||(we=Object.entries(y.comment).map(([i,o])=>[i,o,i.charCodeAt(0)]));for(var e;e=zr();){for(var t=0,r;r=we[t++];)if(e===r[2]&&m.substr(h,r[0].length)===r[0]){var n=h+r[0].length;if(r[1]===`
|
|
7
|
+
`)for(;m.charCodeAt(n)>=Xr;)n++;else{for(;m[n]&&m.substr(n,r[1].length)!==r[1];)n++;m[n]&&(n+=r[1].length)}_e(n),e=0;break}if(e)return e}return e};const kt=80;A("===",kt);A("!==",kt);l("===",(e,t)=>(e=d(e),t=d(t),r=>e(r)===t(r)));l("!==",(e,t)=>(e=d(e),t=d(t),r=>e(r)!==t(r)));const Jr=30;A("??",Jr);l("??",(e,t)=>(e=d(e),t=d(t),r=>e(r)??t(r)));const Qr=130,qr=20;A("**",Qr,!0);A("**=",qr,!0);l("**",(e,t)=>(e=d(e),t=d(t),r=>e(r)**t(r)));const Yr=e=>{throw Error(e)};l("**=",(e,t)=>(z(e)||Yr("Invalid assignment target"),t=d(t),Z(e,(r,n,i)=>r[n]**=t(i))));const Pt=90;A("in",Pt);A("of",Pt);l("in",(e,t)=>(e=d(e),t=d(t),r=>e(r)in t(r)));const Zr=20,br=100,xr=e=>{throw Error(e)};A(">>>",br);A(">>>=",Zr,!0);l(">>>",(e,t)=>(e=d(e),t=d(t),r=>e(r)>>>t(r)));l(">>>=",(e,t)=>(z(e)||xr("Invalid assignment target"),t=d(t),Z(e,(r,n,i)=>r[n]>>>=t(i))));const Ze=5,en=10,tn=20,rn=e=>e[0]?.[0]===","?e[0].slice(1):e,ge=(e,t,r)=>{if(typeof e=="string"){r[e]=t;return}const[n,...i]=e,o=rn(i);if(n==="{}"){const s=[];for(const u of o){if(Array.isArray(u)&&u[0]==="..."){const f={};for(const O in t)s.includes(O)||(f[O]=t[O]);r[u[1]]=f;break}let c,p,S;typeof u=="string"?c=p=u:u[0]==="="?(typeof u[1]=="string"?c=p=u[1]:[,c,p]=u[1],S=u[2]):[,c,p]=u,s.push(c);let g=t[c];g===void 0&&S&&(g=d(S)(r)),ge(p,g,r)}}else if(n==="[]"){let s=0;for(const u of o){if(u===null){s++;continue}if(Array.isArray(u)&&u[0]==="..."){r[u[1]]=t.slice(s);break}let c=u,p;Array.isArray(u)&&u[0]==="="&&([,c,p]=u);let S=t[s++];S===void 0&&p&&(S=d(p)(r)),ge(c,S,r)}}},jt=e=>{let t=v(en-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",Ze+1,()=>jt("let"));de("const",Ze+1,()=>jt("const"));de("var",Ze,()=>(R(),["var",v(tn)]));const _t=(...e)=>(e=e.map(t=>{if(typeof t=="string")return r=>{r[t]=void 0};if(t[0]==="="){const[,r,n]=t,i=d(n);return typeof r=="string"?o=>{o[r]=i(o)}:o=>ge(r,i(o),o)}return d(t)}),t=>{for(const r of e)r(t)});l("let",_t);l("const",_t);l("var",e=>typeof e=="string"?t=>{t[e]=void 0}:()=>{});const be=20,Ce=e=>{throw Error(e)};A("||=",be,!0);A("&&=",be,!0);A("??=",be,!0);l("=",(e,t)=>{if(Array.isArray(e)&&(e[0]==="let"||e[0]==="const"||e[0]==="var")){const r=e[1];return t=d(t),typeof r=="string"?n=>{n[r]=t(n)}:n=>ge(r,t(n),n)}return z(e)||Ce("Invalid assignment target"),t=d(t),Z(e,(r,n,i)=>r[n]=t(i))});l("||=",(e,t)=>(z(e)||Ce("Invalid assignment target"),t=d(t),Z(e,(r,n,i)=>r[n]||=t(i))));l("&&=",(e,t)=>(z(e)||Ce("Invalid assignment target"),t=d(t),Z(e,(r,n,i)=>r[n]&&=t(i))));l("??=",(e,t)=>(z(e)||Ce("Invalid assignment target"),t=d(t),Z(e,(r,n,i)=>r[n]??=t(i))));se("true",!0);se("false",!1);se("null",null);de("undefined",200,()=>[]);se("NaN",NaN);se("Infinity",1/0);const Ie=20;W("?",Ie,(e,t,r)=>e&&(t=v(Ie-1))&&Y(n=>n===58)&&(r=v(Ie-1),["?",e,t,r]));l("?",(e,t,r)=>(e=d(e),t=d(t),r=d(r),n=>e(n)?t(n):r(n)));const nn=[],on=20;A("=>",on,!0);l("=>",(e,t)=>{e=e?.[0]==="()"?e[1]:e;const r=e?e[0]===","?e.slice(1):[e]:[];let n=-1,i=null;const o=r[r.length-1];Array.isArray(o)&&o[0]==="..."&&(n=r.length-1,i=o[1],r.length--);const s=t?.[0]==="{}";return t=d(s?["{",t[1]]:t),u=>(...c)=>{const p={};r.forEach((g,f)=>p[g]=c[f]),i&&(p[i]=c.slice(n));const S=new Proxy(p,{get:(g,f)=>f in g?g[f]:u?.[f],set:(g,f,O)=>((f in g?g:u)[f]=O,!0),has:(g,f)=>f in g||(u?f in u:!1)});try{const g=t(S);return s?void 0:g}catch(g){if(g===nn)return g[0];throw g}}});const sn=140;M("...",sn);l("...",e=>(e=d(e),t=>Object.entries(e(t))));const ct=170;W("?.",ct,(e,t)=>{if(!e)return;const r=R();return r===40?(I(),["?.()",e,v(0,41)||null]):r===91?(I(),["?.[]",e,v(0,93)]):(t=v(ct),t?["?.",e,t]:void 0)});l("?.",(e,t)=>(e=d(e),L(t)?()=>{}:r=>e(r)?.[t]));l("?.[]",(e,t)=>(e=d(e),t=d(t),r=>{const n=t(r);return L(n)?void 0:e(r)?.[n]}));l("?.()",(e,t)=>{const r=t?t[0]===","?(t=t.slice(1).map(d),i=>t.map(o=>o(i))):(t=d(t),i=>[t(i)]):()=>[];if(e[0]==="?."){const i=d(e[1]),o=e[2];return L(o)?()=>{}:s=>i(s)?.[o]?.(...r(s))}if(e[0]==="?.[]"){const i=d(e[1]),o=d(e[2]);return s=>{const u=i(s),c=o(s);return L(c)?void 0:u?.[c]?.(...r(s))}}if(e[0]==="."){const i=d(e[1]),o=e[2];return L(o)?()=>{}:s=>i(s)?.[o]?.(...r(s))}if(e[0]==="[]"&&e.length===3){const i=d(e[1]),o=d(e[2]);return s=>{const u=i(s),c=o(s);return L(c)?void 0:u?.[c]?.(...r(s))}}const n=d(e);return i=>n(i)?.(...r(i))});const te=140;M("typeof",te);M("void",te);M("delete",te);de("new",te,()=>Er(".target")?(I(7),["new.target"]):["new",v(te)]);l("typeof",e=>(e=d(e),t=>typeof e(t)));l("void",e=>(e=d(e),t=>(e(t),void 0)));l("delete",e=>{if(e[0]==="."){const t=d(e[1]),r=e[2];return n=>delete t(n)[r]}if(e[0]==="[]"){const t=d(e[1]),r=d(e[2]);return n=>delete t(n)[r(n)]}return()=>!0});l("new",e=>{const t=d(e?.[0]==="()"?e[1]:e),r=e?.[0]==="()"?e[2]:null,n=r?r[0]===","?(i=>o=>i.map(s=>s(o)))(r.slice(1).map(d)):(i=>o=>[i(o)])(d(r)):()=>[];return i=>new(t(i))(...n(i))});const xe=Symbol("accessor"),et=20,dn=40,Ut=41,Nt=123,Vt=125,Lt=e=>t=>{if(t)return;R();const r=Y(y.id);if(!r||(R(),m.charCodeAt(h)!==dn))return!1;I();const n=v(0,Ut);return R(),m.charCodeAt(h)!==Nt?!1:(I(),[e,r,n,v(0,Vt)])};W("get",et-1,Lt("get"));W("set",et-1,Lt("set"));W("(",et-1,e=>{if(!e||typeof e!="string")return;const t=v(0,Ut)||null;if(R(),m.charCodeAt(h)===Nt)return I(),[":",e,["=>",["()",t],v(0,Vt)||null]]});l("get",(e,t)=>(t=t?d(t):()=>{},r=>[[xe,e,{get:function(){const n=Object.create(r||{});return n.this=this,t(n)}}]]));l("set",(e,t,r)=>(r=r?d(r):()=>{},n=>[[xe,e,{set:function(i){const o=Object.create(n||{});o.this=this,o[t]=i,r(o)}}]]));const un=20,Rt=200;y.prop=e=>vr(e)!==58;const cn=e=>e==null||typeof e=="string"||[":",",","...","get","set"].includes(e[0]);Xe("[]",Rt);Xe("{}",Rt);A(":",un-1,!0);l("{}",(e,t)=>{if(t!==void 0)return;if(!cn(e))return d(["{",e]);e=e?e[0]!==","?[e]:e.slice(1):[];const r=e.map(n=>d(typeof n=="string"?[":",n,n]:n));return n=>{const i={},o={};for(const s of r.flatMap(u=>u(n)))if(s[0]===xe){const[,u,c]=s;o[u]={...o[u],...c,configurable:!0,enumerable:!0}}else i[s[0]]=s[1];for(const s in o)Object.defineProperty(i,s,o[s]);return i}});l("{",e=>(e=e?d(e):()=>{},t=>e(Object.create(t))));l(":",(e,t)=>(t=d(t),Array.isArray(e)?(e=d(e),r=>[[e(r),t(r)]]):r=>[[e,t(r)]]));const ln=170,ye=96,an=36,fn=123,hn=92,pn={n:`
|
|
8
|
+
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},lt=()=>{const e=[];for(let t="",r;(r=m.charCodeAt(h))!==ye;)r?r===hn?(I(),t+=pn[m[h]]||m[h],I()):r===an&&m.charCodeAt(h+1)===fn?(t&&e.push([,t]),t="",I(2),e.push(v(0,125))):(t+=m[h],I(),r=m.charCodeAt(h),r===ye&&t&&e.push([,t])):X("Unterminated template");return I(),e},mn=k[ye];k[ye]=(e,t)=>e&&t<ln?y.asi&&y.newline?void 0:(I(),["``",e,...lt()]):e?mn?.(e,t):(I(),(r=>r.length<2&&r[0]?.[0]===void 0?r[0]||[,""]:["`",...r])(lt()));l("`",(...e)=>(e=e.map(d),t=>e.map(r=>r(t)).join("")));l("``",(e,...t)=>{e=d(e);const r=[],n=[];for(const o of t)Array.isArray(o)&&o[0]===void 0?r.push(o[1]):n.push(d(o));const i=Object.assign([...r],{raw:r});return o=>e(o)(i,...n.map(s=>s(o)))});y.string["'"]=!0;y.number={"0x":16,"0b":2,"0o":8};const gn={log:(e,t)=>(t?console.log(t,e):console.log(e),e)};function _(e,t,r,n,i){const o=y(tt(e));return d(o)({$form:t,$meta:r,$errors:n,$formIsInvalid:i,$log:gn.log})===!0}function tt(e){return e.replace(/\?\.(\d+)/g,"?.[$1]").replace(/\.(\d+)/g,"[$1]")}const U=e=>{let t=e.formDef.states;if(!t||Object.keys(t).length===0||e.formHealth.status==="errored")return e;const{$formIsInvalid:r,$errors:n}=Ge(e);t=yn(t);let i=[],o={status:"ok"};try{i=Object.keys(t).map(s=>{const u=t[s];let c;try{c=_(u,e.data,e.meta,n,r)}catch{c=!1}return c===!0?s:void 0}).filter(s=>s!==void 0)}catch(s){const u=s,c=Q.calculateCurrentStateError;o={status:"errored",message:`[${c}] ${u.message}`,code:c}}return{...e,currentStates:i,formHealth:o}};function yn(e){const t={};function r(n){const i=n.split(":"),o=[];for(let s=0;s<i.length;s++)o.push(i.slice(0,s+1).join(":"));return o}for(const[n,i]of Object.entries(e)){const o=r(n),s=[];for(const u of o)e[u]&&s.push(`(${e[u]})`);t[n]=s.join(" && ")}return t}const rt=Symbol("filterMap.skip");function Mt(e,t){const r=[];for(let n=0;n<e.length;n++){const i=t(e[n],n,e);i!==rt&&r.push(i)}return r}function $n(e,t,r){for(let n=0;n<e.length;n++)t(e[n],n,e)&&r(e[n],n,e)}function An(e,t,r,n){let i=n;for(let o=0;o<e.length;o++)t(e[o],o,e)&&(i=r(i,e[o],o,e));return i}function Sn(e,t,r){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!r(e[n],t[n],n,e,t))return!1;return!0}function Bt(e,t){const r=Ht(e.uid,t);return D(e)?{...e,uid:r,path:vn(e.path,t)}:{...e,uid:r}}function Ht(e,t){if(t.length===0)throw new Error("Repeater indexes cannot be an empty array");const r=t.reduce((n,i)=>`${n}[${i}]`,"");return`${e}${r}`}function vn(e,t){if(t.length===0)throw new Error("Repeater indexes cannot be an empty array");const r="items",n=e.split(`.${r}`),i=n.length-1;if(i!==t.length)throw new Error(`Path contains ${i} '${r}' occurrences, but ${t.length} indexes were provided.`);return n.reduce((o,s,u)=>u===0?s:`${o}.${t[u-1]}${s}`)}function ce(e,t){let r=0;return e.replace(/\.items(\??)\./g,(n,i)=>{const o=t[r++];return o===void 0?n:`.${o}${i}.`})}const le=(e,t)=>r=>e(r)?t(r):r,H=e=>e!==void 0&&typeof e=="object"&&e!==null&&"when"in e,N=e=>{const{$formIsInvalid:t,$errors:r}=Ge(e);return{...e,widgetFlags:{...En(e,r,t),...Cn(e,r,t)}}};function En(e,t,r){return Mt(Object.values(e.flatForm),n=>{if(n.uid?.includes("["))return rt;if(ie(n)){const i=n({$form:e.data,errors:void 0,touched:void 0,translate:void 0});return i.uid=n.uid,i}return n}).filter(n=>!!(n.include&&("in"in n.include||"when"in n.include)||n.exclude&&("from"in n.exclude||"when"in n.exclude)||(D(n)||x(n))&&H(n.disabled)||D(n)&&H(n.readonly))).reduce((n,i)=>(n[i.uid]=n[i.uid]||{},i.include&&"in"in i.include?n[i.uid].hidden=!i.include.in.some(o=>e.currentStates.includes(o)):i.include&&"when"in i.include&&(n[i.uid].hidden=!_(i.include.when,e.data,e.meta,t,r)),i.exclude&&"from"in i.exclude?n[i.uid].hidden=i.exclude.from.some(o=>e.currentStates.includes(o)):i.exclude&&"when"in i.exclude&&(n[i.uid].hidden=_(i.exclude.when,e.data,e.meta,t,r)),(D(i)||x(i))&&H(i.disabled)&&(n[i.uid].disabled=_(i.disabled.when,e.data,e.meta,t,r)),D(i)&&H(i.readonly)&&(n[i.uid].readonly=_(i.readonly.when,e.data,e.meta,t,r)),n),{})}function Cn(e,t,r){return An(Object.values(e.flatForm),n=>!ie(n)&&n.type==="repeater",(n,i)=>({...n,...Gt(e,i,[],t,r)}),{})}function Gt(e,t,r,n,i){const o=t.props.template,s=oe(e.data,t.path);if(!Array.isArray(s))return{};const u={};return s.forEach((c,p)=>{const S=[...r,p];He([o]).forEach(g=>{let f;if(ie(g)?(f=g({$form:e.data,errors:void 0,touched:void 0,translate:void 0}),f.uid=g.uid):f=g,f.type==="repeater"){const b=Bt(f,S);Object.assign(u,Gt(e,b,S,n,i));return}const O=Ht(f.uid,S);u[O]=u[O]||{},f.include&&"in"in f.include?u[O].hidden=!f.include.in.some(b=>e.currentStates.includes(b)):f.include&&"when"in f.include&&(u[O].hidden=!_(ce(f.include.when,S),e.data,e.meta,n,i)),f.exclude&&"from"in f.exclude?u[O].hidden=f.exclude.from.some(b=>e.currentStates.includes(b)):f.exclude&&"when"in f.exclude&&(u[O].hidden=_(ce(f.exclude.when,S),e.data,e.meta,n,i)),(D(f)||x(f))&&H(f.disabled)&&(u[O].disabled=_(ce(f.disabled.when,S),e.data,e.meta,n,i)),D(f)&&H(f.readonly)&&(u[O].readonly=_(ce(f.readonly.when,S),e.data,e.meta,n,i))})}),u}const j=e=>t=>{try{return{...t,calculatedWidgets:wn(t,e)}}catch(r){const n=r;return{...t,formHealth:{status:"errored",message:`[${n.code}] ${n.message}`,code:n.code}}}};function wn(e,t){const{$formIsInvalid:r,$errors:n}=Ge(e),i=Gn(e,t,r,n),o={};for(const s of Object.keys(e.calculatedWidgets)){if(e.widgetFlags[s]?.hidden)continue;const u=e.calculatedWidgets[s],c=u.source;if(ie(c)){o[s]=In(s,c,e,t);continue}o[s]=On(u,c,e,i)}return o}function In(e,t,r,n){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});return i.uid=e,{source:t,current:i}}function On(e,t,r,n){const i=new Hn(t,e.current);return i.write("uid",t.uid),i.write("type",t.type),i.write("kind",t.kind),or(t)?Dn(i,n):x(t)?Tn(i,n):D(t)?Fn(i,n):Fe(t)&&Wn(i,n),kn(t,i,n,r),(x(t)||D(t))&&Pn(t,i,n),Fe(t)&&jn(t,i,r),i.changed?{source:e.source,current:i.current}:e}function Dn(e,t){E(e,t,"size"),E(e,t,"include"),E(e,t,"exclude")}function Tn(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 Fn(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 Wn(e,t){E(e,t,"size"),E(e,t,"include"),E(e,t,"exclude")}function kn(e,t,r,n){const i=n.widgetPropOverrides[e.uid]??{},o={...e.props??{},...i};for(const s of zt(Object.keys(o)))_n(t,r,s)}function Pn(e,t,r){const n=e.on??{};for(const i of zt(Object.keys(n)))Un(t,r,i)}function jn(e,t,r){const n=zn(e.uid),i=Xn(e.children,n,r.widgetFlags);t.current.children=i;const o=t.previous.children??[];o.length===i.length&&i.every((u,c)=>o[c]&&o[c].uid===i[c].uid)||t.markChanged()}function E(e,t,r){const n=e.source;if(!Kn(n,r))return;const i=it(n,r,t.sortedStates);let o;switch(r){case"disabled":case"readonly":o=Ln(i,t,e.source.uid,r);break;case"defaultValue":o=i;break;default:o=Xt(i,t)}e.write(r,o)}function _n(e,t,r){const n=e.source.props,i=it(n,r,t.sortedStates);let o=Xt(i,t);const s=t.widgetPropOverrides[e.source.uid]?.[r];s!==void 0&&(o=s),e.write(`props.${r}`,o)}function Un(e,t,r){const n=e.source.on,i=it(n,r,t.sortedStates);e.write(`on.${r}`,Rn(i,t))}function nt(e,t){return e({$form:t.$form,translate:t.localization.translate})}function Nn(e,t){return t.localization.translate(e.key,Bn(e.params,t),e.default)}const Vn=/\{\{([^}]+)\}\}/g;function Kt(e,t){return e.includes("{{")?e.replace(Vn,(r,n)=>{const i=tt(n.trim());try{const o=d(y(i))({$form:t.$form,$meta:t.$meta,$errors:t.$errors,$formIsInvalid:t.$formIsInvalid});return o==null?"":String(o)}catch(o){const s=o instanceof Error?o.message:String(o);throw new Jt(`Failed to evaluate '{{${n.trim()}}}': ${s}`)}}):e}function Xt(e,t){return typeof e=="function"?nt(e,t):gr(e)?Nn(e,t):typeof e=="string"?Kt(e,t):e}function Ln(e,t,r,n){return typeof e=="function"?nt(e,t):H(e)?t.widgetFlags[r]?.[n]:typeof e=="string"?Kt(e,t):e}function Rn(e,t){return typeof e=="function"?nt(e,t):e}function it(e,t,r){if(e){for(const n of r){const i=e[`${t}.${n}`];if(i!==void 0)return i}return e[t]}}function Mn(e){return e.startsWith("$form")||e.startsWith("$meta")||e.startsWith("$errors")||e==="$formIsInvalid"}function Bn(e,t){return e&&Object.keys(e).reduce((r,n)=>{const i=String(e[n]);if(Mn(i))try{const o=d(y(tt(i)))({$form:t.$form,$meta:t.$meta,$errors:t.$errors,$formIsInvalid:t.$formIsInvalid});r[n]=o??i}catch(o){const s=o instanceof Error?o.message:String(o);throw new Jt(`Failed to evaluate i18n param '${i}': ${s}`)}else r[n]=i;return r},{})}class Hn{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){Be(this.current,t,r),oe(this.previous,t)!==r&&(this._changed=!0)}}function Gn(e,t,r,n){return{sortedStates:[...e.currentStates].sort((i,o)=>o.length-i.length),widgetPropOverrides:e.widgetPropOverrides,widgetFlags:e.widgetFlags,$form:e.data,$meta:e.meta,$formIsInvalid:r,$errors:n,localization:t}}function Kn(e,t){if(t in e)return!0;const r=`${t}.`;return Object.keys(e).some(n=>n.startsWith(r))}function zt(e){return Array.from(new Set(e.map(t=>t.split(".")[0])))}function Xn(e,t,r){const n=t.map(i=>`[${i}]`).join("");return e.filter(i=>{const o=i.uid+n,s=r[o];return!s||s.hidden!==!0})}const zn=e=>[...e.matchAll(/\[(\d+)\]/g)].map(t=>parseInt(t[1],10));class Jt extends Error{constructor(){super(...arguments),this.code=Q.resolveStringInterpolationError,this.name="StringInterpolationError"}}const Jn=({lang:e},t)=>{const r={...yt(e),formName:t.payload.formName};let n=t.payload.formDef,i={status:"ok"};if(typeof n=="string"){try{n=JSON.parse(n)}catch(u){const c=u,p=Q.initializeParseError;i={status:"errored",message:`[${p}] ${c.message}`,code:p}}if(i.status==="errored")return{...r,formHealth:i}}if(Array.isArray(n.form)){const u=n,c=u.form;u.form={uid:"",type:"flex",kind:"layout",children:c}}const o=gt.decode(n);if(o.isOk()){i={status:"ok"};let u={};try{u=He([o.value.form]).reduce((c,p)=>{const S=p.uid;if(c[S])throw{existingWidget:c[S],newWidget:p};return c[S]=p,c},{})}catch(c){const p=Q.initializeUidCollisionError;i={status:"errored",message:`[${p}] ${Qn(c.existingWidget,c.newWidget)}`,code:p},u={}}return{...r,formDef:o.value,flatForm:u,formHealth:i}}const s=Q.initializeUnknownError;return{...r,formHealth:{status:"errored",message:`[${s}] ${o.error}`,code:s}}};function Qn(e,t){const r=n=>D(n)?` at "${n.path}"`:"";return`Duplicate UID "${t.uid}": Assigned to widget "${e.type}"${r(e)} and "${t.type}"${r(t)}.`}function qn(e,t){return{...e,injectedValidations:{...e.injectedValidations,[t.payload.path]:t.payload.issues}}}const Yn=(e,{payload:t})=>{let r;if("path"in t){if(r=Object.values(e.calculatedWidgets).find(({source:o})=>D(o)&&o.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,i=e.widgetPropOverrides[n]||{};return{...e,widgetPropOverrides:{...e.widgetPropOverrides,[n]:{...i,[t.prop]:t.value}}}};function Zn(e,t){return{...e,widgetFlags:{...ue(e.widgetFlags,t.payload.uid)},calculatedWidgets:{...ue(e.calculatedWidgets,t.payload.uid)},widgetPropOverrides:{...ue(e.widgetPropOverrides,t.payload.uid)},touchedControls:{...P(e.touchedControls,r=>{const n=e.flatForm[t.payload.uid];return n&&D(n)?ue(r,n.path):r})}}}const bn=(e,t)=>({...e,data:{...t.payload.data}}),xn=(e,t)=>({...e,formHealth:t.payload.formHealth}),ei=(e,t)=>({...e,lang:t.payload.lang}),ti=(e,t)=>({...e,meta:{...t.payload.meta}}),ri=(e,t)=>{const r=oe(e.data,t.payload.path);return t.type==="SET_WIDGET_DATA"||t.type==="SET_WIDGET_INITIAL_DATA"&&r===void 0?{...e,data:{...Be(e.data,t.payload.path,t.payload.data)}}:e},Oe=(e,t)=>r=>{const n=Mt(Object.values(r.calculatedWidgets),({current:o})=>D(o)?o:rt),i=r.validations;return{...r,validations:n.reduce((o,s)=>{if(o[s.path]=null,s.validator){const u=e(s.validator,t),c=oe(r.data,s.path),p=ft(u,c);o[s.path]=ht(p)?null:p.issues.map(S=>S.message)}return Array.isArray(o[s.path])&&Array.isArray(i[s.path])&&Sn(o[s.path],i[s.path],(u,c)=>u===c)&&(o[s.path]=i[s.path]),o},{})}},ni=({validators:e,validateOn:t,localization:r})=>(n,i)=>{switch(i.type){case"INITIALIZE":return Jn(n,i);case"SET_DATA":return P(bn(n,i),U,N,j(r));case"SET_META":return P(ti(n,i),U,N,j(r));case"SET_LANGUAGE":return P(ei(n,i),j(r));case"ADD_WIDGET":return P(Ar(n,i),le(De,U),le(De,N),le(De,j(r)));case"REMOVE_WIDGET":return P(Zn(n,i),U,N,j(r));case"SET_WIDGET_INITIAL_DATA":case"SET_WIDGET_DATA":return P(ri(n,i),U,N,j(r));case"OVERRIDE_WIDGET_PROP":return P(Yn(n,i),U,N,j(r),le(o=>{let s=!1,u="";"path"in i.payload?(s=!0,u=i.payload.path):D(o.calculatedWidgets[i.payload.uid].current)&&(s=!0,u=o.calculatedWidgets[i.payload.uid].current.path);const c=s&&o.touchedControls[u];return o.touched&&c},Oe(e,r)));case"SET_FORM_HEALTH":return xn(n,i);case"VALIDATE_ALL":return P({...n,touched:!0,touchedControls:Object.keys(n.calculatedWidgets).reduce((o,s)=>{const u=n.calculatedWidgets[s].source;return D(u)&&(o[u.path]=!0),o},{})},Oe(e,r),U,N,j(r),at);case"ATTEMPT_VALIDATION":{const o=i.payload.reason,s=i.payload.path;return t==="eager"||o===t||t.includes(o)?P({...n,touched:!0,touchedControls:{...n.touchedControls,[s]:!0}},Oe(e,r),U,N,j(r),c=>{const p=i.payload.uid,S=c.calculatedWidgets[p],g=S.source;if(ie(g)){const f=g({$form:c.data,errors:c.validations[s],touched:!0,translate:r.translate});return{...c,calculatedWidgets:{...c.calculatedWidgets,[p]:{source:S.source,current:f}}}}return c},at):n}case"INJECT_VALIDATION_ISSUES":return qn(n,i);default:return $r(i)}},De=e=>e.formHealth.status==="ok";function at(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(i=>e.injectedValidations[i]!==null&&Array.isArray(e.injectedValidations[i]));return n!==void 0?{...e,isFormValid:!1}:(n=r.find(i=>e.validations[i]!==null&&Array.isArray(e.validations[i])),n!==void 0?{...e,isFormValid:!1}:{...e,isFormValid:!0})}function ii(e=[],t,r,n){const i=new a.BehaviorSubject(yt(n.lang)),o=i.asObservable().pipe(a.distinctUntilChanged()),s=ni({validators:t,validateOn:r,localization:n});function u(g){const f=i.getValue(),O=s(f,g);i.next(O)}let c=u;const p={getState:()=>i.getValue(),dispatch:g=>c(g)};return c=e.map(g=>g(p)).reduceRight((g,f)=>f(g),u),{state$:o,dispatch:c,getState:()=>i.getValue()}}class oi{constructor(){this.widgetRegistry=new ke,this.store={},this.events$=new a.Subject,this.submit$=new a.Subject,this.uuid=crypto.randomUUID(),this.itemRenderers={},this.dependencies={}}initialize(t,r=[],n,i,o,s=$t(),u){this.localization=s,this.dependencies=u,this.widgetRegistry.setWidgetLoaders(t),this.itemRenderers=o,this.store=ii(r,n,i,s)}emitEvent(t,r,n){const o=this.store.getState().currentStates.filter(s=>r.on?.[`${t}.${s}`]!==void 0);if(o.length>0)o.forEach(s=>{const u=r.on?.[`${t}.${s}`];this.attemptValidation(t,r),u&&this.events$.next({name:u,data:this.store.getState().data,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:this.store.getState().data,detail:n,callback:u=>{this.store.dispatch(u)}})}}emitSubmitEvent(){this.store.dispatch({type:"VALIDATE_ALL"}),this.store.getState().isFormValid&&this.submit$.next({data:this.store.getState().data,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 si(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()),i=>o=>{i(o),n&&n.send(o,t.getState())}}}const di=a.pipe(a.map(e=>e.data),a.distinctUntilChanged()),ui=e=>a.pipe(di,a.map(t=>oe(t,e)),a.distinctUntilChanged()),ci=a.pipe(a.filter(e=>e.touched===!0),a.map(e=>e.validations),a.distinctUntilChanged()),li=e=>a.pipe(ci,a.map(t=>t[e]),a.distinctUntilChanged()),ai=a.pipe(a.filter(e=>e.touched===!0),a.map(e=>e.injectedValidations),a.distinctUntilChanged()),fi=e=>a.pipe(ai,a.map(t=>t[e]),a.distinctUntilChanged(),a.startWith(null)),hi=a.pipe(a.map(e=>e.lang),a.distinctUntilChanged()),Qt=a.pipe(a.map(e=>e.calculatedWidgets),a.distinctUntilChanged()),pi=e=>t=>a.combineLatest([t.pipe(hi),t.pipe(Qt)]).pipe(a.map(([r,n])=>({lang:r,widget:n[e]})),a.filter(r=>r.widget!==void 0),a.distinctUntilChanged((r,n)=>r.lang===n.lang&&r.widget===n.widget),a.map(r=>r.widget.current)),mi=e=>a.pipe(Qt,a.map(t=>t[e]),a.filter(t=>t!==void 0),a.map(t=>t.current.children),a.distinctUntilChanged());a.pipe(a.map(e=>e.widgetFlags),a.distinctUntilChanged());const gi=a.pipe(a.map(e=>e.touchedControls),a.distinctUntilChanged()),yi=e=>a.pipe(gi,a.map(t=>t[e]),a.distinctUntilChanged()),$i=a.pipe(a.map(e=>e.formHealth),a.distinctUntilChanged((e,t)=>e.status!==t.status?!1:e.status==="errored"&&t.status==="errored"?e.message===t.message&&e.code===t.code:!0)),Ai=e=>e.pipe($i);let qt=!1;function Si(){qt=!0}function vi(){return qt}function Ei(e,t,r){if(!vi())return;const n=Object.keys(t??{}).filter(i=>i in r);if(n.length>0)throw new Error(`[GolemUI] Widget "${e}": prop keys [${n.join(", ")}] collide with widget fields`)}exports.FormContext=oi;exports.assertNoPropCollisions=Ei;exports.calculatedLayoutChildrenByUid$=mi;exports.calculatedWidgetsByUid$=pi;exports.cloneObject=Pe;exports.dataByPath$=ui;exports.defineForm=mr;exports.devToolsMiddleware=si;exports.enableDevMode=Si;exports.errorCodes=Q;exports.filterTap=$n;exports.formHealth=Ai;exports.getDirectionFromLanguage=yr;exports.identityTranslator=$t;exports.injectedValidationByPath$=fi;exports.isStandardValidateSuccess=ht;exports.makeRepeaterItemConfig=Bt;exports.shortUUID=Ve;exports.standardValidate=ft;exports.touchedControlsByPath$=yi;exports.validationByPath$=li;
|
package/lib/errors.d.ts
CHANGED
package/lib/utils/form.d.ts
CHANGED
|
@@ -1,55 +1,6 @@
|
|
|
1
1
|
import { FormWidget } from '../form-widget';
|
|
2
|
-
import { $Errors
|
|
2
|
+
import { $Errors } from '../shared';
|
|
3
3
|
import { State } from '../store/model';
|
|
4
|
-
/**
|
|
5
|
-
* Expression Scopes define the root namespaces accessible within
|
|
6
|
-
* reactive expressions and template strings.
|
|
7
|
-
*/
|
|
8
|
-
export declare const EXPRESSION_SCOPE: {
|
|
9
|
-
readonly FORM: "$form";
|
|
10
|
-
readonly META: "$meta";
|
|
11
|
-
readonly ERRORS: "$errors";
|
|
12
|
-
readonly FORM_IS_INVALID: "$formIsInvalid";
|
|
13
|
-
};
|
|
14
|
-
/**
|
|
15
|
-
* Heuristically checks if a value looks like a scoped path
|
|
16
|
-
* rather than a standard string.
|
|
17
|
-
* To be considered a "potential" scoped path, the value must:
|
|
18
|
-
* 1. Be a string.
|
|
19
|
-
* 2. Start with one of the allowed prefixes ($form.*, $meta.*, etc..).
|
|
20
|
-
* 3. Not contain any spaces (distinguishing it from sentences).
|
|
21
|
-
*
|
|
22
|
-
* * @example
|
|
23
|
-
* isPotentialScopedPath('$form.user.id'); // true
|
|
24
|
-
* isPotentialScopedPath('name'); // false (No prefix)
|
|
25
|
-
* isPotentialScopedPath('my file'); // false (Contains space)
|
|
26
|
-
* isPotentialScopedPath(123); // false (Not a string)
|
|
27
|
-
*/
|
|
28
|
-
export declare const isPotentialScopedPath: (path: unknown) => path is DotPath;
|
|
29
|
-
export interface ScopedPathResolvers {
|
|
30
|
-
resolveFormPath: (expr: string) => any;
|
|
31
|
-
resolveMetaPath: (expr: string) => any;
|
|
32
|
-
resolveErrorsPath: (expr: string) => any;
|
|
33
|
-
resolveFormIsInvalid: () => string | boolean;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Resolves all scoped path placeholders within a string in a single pass.
|
|
37
|
-
* e.g. "User {{ $form.name }} has status {{ $meta.status }} or {{ $formIsInvalid }}"
|
|
38
|
-
*
|
|
39
|
-
* @param input - The template string to process
|
|
40
|
-
* @param resolvers - Implementation of value resolution logic
|
|
41
|
-
* @returns The string with all valid placeholders replaced by their resolved values
|
|
42
|
-
*/
|
|
43
|
-
export declare const resolveScopedPaths: (input: string, resolvers: ScopedPathResolvers) => string;
|
|
44
|
-
/**
|
|
45
|
-
* Resolves a scoped path to its underlying value using the
|
|
46
|
-
* appropriate resolver based on the path prefix (`$form.*`, `$meta.*`, `$errors.*` or `$formIsInvalid`).
|
|
47
|
-
*
|
|
48
|
-
* @param variable - A dot-notation path starting with `$form.`, `$meta.` or `$errors.`, or `$formIsInvalid`.
|
|
49
|
-
* @param resolvers.resolveFormPath - Resolves a path within the $form scope
|
|
50
|
-
* @param resolvers.resolveMetaPath - Resolves a path within the $meta scope
|
|
51
|
-
*/
|
|
52
|
-
export declare const resolveScopedPath: (variable: string, resolvers: ScopedPathResolvers) => any;
|
|
53
4
|
/**
|
|
54
5
|
* Flattens the hierarchical form structure into a single-level array of form widgets.
|
|
55
6
|
*
|
package/lib/utils/justin.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { $Errors, ReactiveExpression } from '../shared';
|
|
2
2
|
import { State } from '../store/model';
|
|
3
3
|
export declare function expressionIsTrue(expression: ReactiveExpression, $form: State['data'], $meta: State['meta'], $errors: $Errors, $formIsInvalid: boolean): boolean;
|
|
4
|
+
export declare function normalizeArrayIndexes(expression: string): string;
|