@golemui/core 0.16.2 → 0.17.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 +708 -657
- package/index.umd.cjs +8 -8
- package/lib/shared.d.ts +5 -0
- package/lib/utils/decoder.d.ts +4 -4
- package/lib/utils/form.d.ts +6 -0
- package/lib/utils/object.d.ts +37 -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
|
|
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=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;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("rxjs");require("@standard-schema/spec");function ht(e,t){const r=e["~standard"].validate(t);if(r instanceof Promise)throw new TypeError("Schema validation must be synchronous");return r}function pt(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 w(this.error)}isOk(){return!1}};function F(e){return new Yt(e)}function w(e){return new Zt(e)}var T=class Fe{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 Fe(r=>{let n=this.decodeFn(r);return n.isOk()?F(t(n.value)):w(n.error)})}flatMap(t){return new Fe(r=>{let n=this.decodeFn(r);return n.isOk()?t(n.value).decode(r):w(n.error)})}},xt=(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 w(xt(t,i,o.error))}return F(n)}else return w(q(r,"array"))})}function er(){return new T(e=>typeof e=="boolean"?F(e):w(q(e,"boolean")))}function gt(e){return new T(t=>e().decode(t))}var tr=(e,t)=>`${JSON.stringify(e)} is not exactly ${JSON.stringify(t)}`;function J(e){return new T(t=>t===e?F(e):w(tr(t,e)))}function $e(){return new T(e=>typeof e=="number"?F(e):w(q(e,"number")))}var rr=(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 w(rr(t,i,o.error))}return F(n)}else return w(q(r,t))})}var nr=(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 w(nr(t,r))})}function y(e){return new T(t=>t===void 0?F(void 0):e.decode(t))}var ir=(e,t,r)=>`<${e}> record decoder failed at key "${t}" with error: ${r}`;function or(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 w(ir(t,i,o.error))}return F(n)}else return w(q(r,t))})}function C(){return new T(e=>typeof e=="string"?F(e):w(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 w(`<${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 w(`<${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 a=o.decoder.decode(c);if(!a.isOk())return w(`<${t}> failed at "${u}" with ${a.error}`);n[u]=a.value}}}return F(n)})}const Ve=()=>crypto.randomUUID().slice(0,8),sr=e=>typeof e!="function"&&e.kind==="display",x=e=>typeof e!="function"&&e.kind==="action",O=e=>typeof e!="function"&&e.kind==="input",We=e=>typeof e!="function"&&e.kind==="layout",ie=e=>typeof e=="function",dr=re({in:Ne(C(),"In[]")},"In"),Le=re({when:C()},"When"),Ae=K([dr,Le],"In | When"),ur=re({from:Ne(C(),"From[]")},"From"),Se=K([ur,Le],"Exclude"),ke=K([er(),Le],"Bool | When"),cr=new T(e=>{const t=typeof e;return t==="function"?F(e):w(`Expected a function, got '${t}'`)}),V=e=>K([e,cr],""),Re=ne({load:{suffixed:!0,decoder:V(y(C()))},click:{suffixed:!0,decoder:V(y(C()))},change:{suffixed:!0,decoder:V(y(C()))},filter:{suffixed:!0,decoder:V(y(C()))},blur:{suffixed:!0,decoder:V(y(C()))}},"On"),lr=re({key:C(),default:y(C()),params:y(G())},"TranslationConfig"),mt=K([C(),lr],"Localizable"),Me=y(C()).map(e=>e||Ve()),ar=ne({kind:{decoder:J("display")},uid:{decoder:Me},type:{decoder:C()},size:{suffixed:!0,decoder:y($e())},include:{decoder:y(Ae)},exclude:{decoder:y(Se)},props:{decoder:y(G())}},"DisplayWidget"),fr=ne({kind:{decoder:J("action")},uid:{decoder:Me},type:{decoder:C()},actionType:{decoder:y(K([J("button"),J("submit")],"button | submit "))},size:{suffixed:!0,decoder:y($e())},include:{decoder:y(Ae)},exclude:{decoder:y(Se)},label:{suffixed:!0,decoder:V(y(mt))},disabled:{suffixed:!0,decoder:y(ke)},on:{decoder:y(Re)},props:{decoder:y(G())}},"ActionWidget"),hr=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 w(`Expected a function, got '${t}'`)}),pr=ne({kind:{decoder:J("input")},uid:{decoder:y(C())},type:{decoder:C()},size:{suffixed:!0,decoder:y($e())},include:{decoder:y(Ae)},exclude:{decoder:y(Se)},disabled:{suffixed:!0,decoder:y(ke)},readonly:{suffixed:!0,decoder:y(ke)},on:{decoder:y(Re)},props:{decoder:y(G())},label:{suffixed:!0,decoder:V(y(mt))},path:{decoder:C()},defaultValue:{decoder:y(G())},validator:{suffixed:!0,decoder:V(y(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=Be.parse(r.template)}return t}),gr=gt(()=>K([hr,pr,Be,ar,fr],"FormWidget")),Be=ne({kind:{decoder:J("layout")},uid:{decoder:Me},type:{decoder:C()},size:{suffixed:!0,decoder:y($e())},include:{decoder:y(Ae)},exclude:{decoder:y(Se)},props:{decoder:y(G())},on:{decoder:y(Re)},children:{decoder:Ne(gr,"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 Pe=B;function mr(e){return{...e,form:{uid:"",type:"flex",kind:"layout",children:e.form}}}const yt=re({states:y(or(C(),"states")),form:gt(()=>Be)},"FormDef"),$t=e=>({formName:"",formDef:yt.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}),yr=e=>!(typeof e!="object"||e===null||typeof e.key!="string");function $r(e){const t=new Intl.Locale(e).maximize().script;return["Arab","Hebr","Thaa","Syrc","Tfng","Adlm","Rohg"].includes(t||"")?"rtl":"ltr"}const At=(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))}}},Ar=e=>{throw new Error(`Unhandled case: ${JSON.stringify(e)}`)};function P(e,...t){return t.reduce((r,n)=>n(r),e)}function Sr(e,t){const r=t.payload.widget.uid;if(!r)throw new Error("addWidget: widget must have a uid");const n=t.payload.widget,i=e.touched&&O(n)?{...e.touchedControls,[n.path]:!0}:e.touchedControls;return{...e,touchedControls:i,calculatedWidgets:{...e.calculatedWidgets,[r]:{source:n,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)},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 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]=Er(c)?[]:{}),i=i[u]}const o=n[n.length-1];return i[o]=r,e},vr=(e,t)=>{if(t==="")return e;const r=t.split("."),n=[e];for(let s=0;s<r.length-1;s++){const u=n[s];if(u==null||typeof u!="object")return e;const c=r[s],a=Array.isArray(u)?u[parseInt(c,10)]:u[c];if(a==null||typeof a!="object")return e;n.push(a)}const i=n[n.length-1],o=r[r.length-1];Array.isArray(i)?i.splice(parseInt(o,10),1):delete i[o];for(let s=n.length-1;s>=1;s--){const u=n[s];if(Array.isArray(u)||!Cr(u))break;const c=n[s-1],a=r[s-1];if(Array.isArray(c))break;delete c[a]}return e};function Er(e){const t=Number(e);return Number.isInteger(t)&&t>=0&&t.toString()===e}function Cr(e){return e!=null&&typeof e=="object"&&!Array.isArray(e)&&Object.keys(e).length===0}const ve=(e,t)=>(delete e[t],e);function ae(e){if(e===null||typeof e!="object")return e;if(Array.isArray(e))return e.map(r=>ae(r));const t={};for(const r of Object.keys(e))t[r]=ae(e[r]);return t}function Ge(e){return e.flatMap(t=>[t,...We(t)?Ge(t.children):[]])}function Ke(e){return Object.entries(e.validations).reduce((r,[n,i])=>(i!==null&&(r.$formIsInvalid=!0,He(r.$errors,n,[...i])),r),{$formIsInvalid:!1,$errors:{}})}function we(e){const t=ae(e.data);for(const[r,n]of Object.entries(e.widgetFlags))if(n.hidden===!0){const i=e.flatForm[r];i&&O(i)&&vr(t,i.path)}return t}const Xe=32;let je,p,g,$=e=>(p=0,g=e,$.newline=!1,e=v(),g[p]?X():e||""),X=(e="Unexpected token",t=p,r=g.slice(0,t).split(`
|
|
2
|
+
`),n=r.pop(),i=g.slice(Math.max(0,t-40),t),o="̭",s=(g[t]||" ")+o,u=g.slice(t+1,t+20))=>{throw SyntaxError(`${e} at ${r.length+1}:${n.length+1}
|
|
3
|
+
${g[t-41]!==`
|
|
4
|
+
`,""+i}${s}${u}`)},St=(e,t=p)=>(Array.isArray(e)&&(e.loc=t),e),b=(e,t=p,r)=>{for(;r=e(g.charCodeAt(p));)p+=r;return g.slice(t,p)},I=(e=1)=>g[p+=e],_e=e=>p=e,v=(e=0,t)=>{let r,n,i,o,s;for(t&&$.asi&&($.newline=!1);(r=$.space())&&(s=$.newline,1)&&r!==t&&(i=(n&&r===91&&je&&$.asi?.(n,e,v)||null)??((o=k[r])&&o(n,e))??(n&&s&&$.asi?.(n,e,v))??(!n&&b($.id)));)n=i;return t&&(r==t?(p++,t===125&&$.asi&&($.newline=!0)):X("Unclosed "+String.fromCharCode(t-(t>42?2:1)))),n},R=(e,t=p)=>{for(je=!1;(e=g.charCodeAt(p))<=Xe;)$.asi&&e===10&&($.newline=je=!0),p++;return e},wr=(e=p)=>{for(;g.charCodeAt(e)<=Xe;)e++;return g.charCodeAt(e)};$.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 Ir=(e,t=e.length)=>g.substr(p,t)===e&&!$.id(g.charCodeAt(p+t)),k=[],st={},W=(e,t=Xe,r,n=e.charCodeAt(0),i=e.length,o=k[n],s=e.toUpperCase()!==e,u,c)=>(t=st[e]=!o&&st[e]||t,k[n]=(a,S,m,h=p)=>(u=m,(m?e==m:(i<2||e.charCodeAt(1)===g.charCodeAt(p+1)&&(i<3||g.substr(p,i)==e))&&(!s||!$.id(g.charCodeAt(p+i)))&&(u=m=e))&&S<t&&(p+=i,(c=r(a))?St(c,h):(p=h,u=0,!s&&!o&&!a&&X()),c)||o?.(a,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]),vt=(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)),ze=(e,t)=>W(e[0],t,r=>!r&&[e,v(0,e.charCodeAt(1))||null]),Et=(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,a,S=p)=>!u&&(a?e==a:(i<2||g.substr(p,i)==e)&&(a=e))&&c<t&&!$.id(g.charCodeAt(p+i))&&(!$.prop||$.prop(p+i))&&(_e(p+i),(s=r())?St(s,S):_e(S),s)||o?.(u,c,a);Object.defineProperty($,"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,Or=69,Dr=101,Tr=43,Fr=45,le=95,Ct=110,Wr=97,kr=102,Pr=65,jr=70,wt=e=>e.indexOf("_")<0?e:e.replaceAll("_",""),Je=e=>{let t=wt(b(r=>r===fe&&g.charCodeAt(p+1)!==fe||r>=ee&&r<=he||r===le||((r===Or||r===Dr)&&((r=g.charCodeAt(p+1))>=ee&&r<=he||r===Tr||r===Fr)?2:0)));return g.charCodeAt(p)===Ct?(I(),[,BigInt(t)]):(e=+t)!=e?X():[,e]},_r={2:e=>e===48||e===49||e===le,8:e=>e>=48&&e<=55||e===le,16:e=>e>=ee&&e<=he||e>=Wr&&e<=kr||e>=Pr&&e<=jr||e===le};$.number=null;k[fe]=e=>!e&&g.charCodeAt(p+1)!==fe&&Je();for(let e=ee;e<=he;e++)k[e]=t=>t?void 0:Je();k[ee]=e=>{if(e)return;const t=$.number;if(t){for(const[r,n]of Object.entries(t))if(r[0]==="0"&&g[p+1]?.toLowerCase()===r[1]){I(2);const i=wt(b(_r[n]));return g.charCodeAt(p)===Ct?(I(),[,BigInt("0"+r[1]+i)]):[,parseInt(i,n)]}}return Je()};const Ur=92,dt=34,ut=39,Nr={n:`
|
|
5
|
+
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},It=e=>(t,r,n="")=>{if(!(t||!$.string?.[String.fromCharCode(e)]))return I(),b(i=>i-e&&(i===Ur?(n+=Nr[g[p+1]]||g[p+1],2):(n+=g[p],1))),g[p]===String.fromCharCode(e)?I():X("Bad string"),[,n]};k[dt]=It(dt);k[ut]=It(ut);$.string={'"':!0};const Vr=20;"= += -= *= /= %= |= &= ^= >>= <<=".split(" ").map(e=>A(e,Vr,!0));const Ot=(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?Ot(e[1],t):(()=>{throw Error("Invalid assignment target")})(),ct={"=":(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 ct)l(e,(t,r)=>(r=d(r),Ot(t,(n,i,o)=>ct[e](n,i,r(o)))));const Lr=30,Rr=40,Mr=140;M("!",Mr);A("||",Lr);A("&&",Rr);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 Br=50,Hr=60,Gr=70,Dt=100,Kr=140;A("|",Br);A("&",Gr);A("^",Hr);A(">>",Dt);A("<<",Dt);M("~",Kr);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 Tt=80;A("==",Tt);A("!=",Tt);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 Ft=110,Qe=120,Wt=140;A("+",Ft);A("-",Ft);A("*",Qe);A("/",Qe);A("%",Qe);M("+",Wt);M("-",Wt);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 Xr=5,zr=10;vt(",",zr);vt(";",Xr,!0);const kt=(...e)=>(e=e.map(d),t=>{let r;for(const n of e)r=n(t);return r});l(",",kt);l(";",kt);const Jr=170;ze("()",Jr);const L=e=>e?.[0]==="_"&&e[1]==="_"||e==="constructor"||e==="prototype",be=170;Et("[]",be);A(".",be);Et("()",be);const ge=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&&ge("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?ge("Empty ()"):d(e);const r=i=>i?.[0]===","&&i.slice(1).some(o=>o==null||r(o));r(t)&&ge("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?ge("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)),Y=Ye,Qr=32,qr=$.space;$.comment??={"//":`
|
|
6
|
+
`,"/*":"*/"};let Ie;$.space=()=>{Ie||(Ie=Object.entries($.comment).map(([i,o])=>[i,o,i.charCodeAt(0)]));for(var e;e=qr();){for(var t=0,r;r=Ie[t++];)if(e===r[2]&&g.substr(p,r[0].length)===r[0]){var n=p+r[0].length;if(r[1]===`
|
|
7
|
+
`)for(;g.charCodeAt(n)>=Qr;)n++;else{for(;g[n]&&g.substr(n,r[1].length)!==r[1];)n++;g[n]&&(n+=r[1].length)}_e(n),e=0;break}if(e)return e}return e};const Pt=80;A("===",Pt);A("!==",Pt);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 br=30;A("??",br);l("??",(e,t)=>(e=d(e),t=d(t),r=>e(r)??t(r)));const Yr=130,Zr=20;A("**",Yr,!0);A("**=",Zr,!0);l("**",(e,t)=>(e=d(e),t=d(t),r=>e(r)**t(r)));const xr=e=>{throw Error(e)};l("**=",(e,t)=>(z(e)||xr("Invalid assignment target"),t=d(t),Y(e,(r,n,i)=>r[n]**=t(i))));const jt=90;A("in",jt);A("of",jt);l("in",(e,t)=>(e=d(e),t=d(t),r=>e(r)in t(r)));const en=20,tn=100,rn=e=>{throw Error(e)};A(">>>",tn);A(">>>=",en,!0);l(">>>",(e,t)=>(e=d(e),t=d(t),r=>e(r)>>>t(r)));l(">>>=",(e,t)=>(z(e)||rn("Invalid assignment target"),t=d(t),Y(e,(r,n,i)=>r[n]>>>=t(i))));const Ze=5,nn=10,on=20,sn=e=>e[0]?.[0]===","?e[0].slice(1):e,me=(e,t,r)=>{if(typeof e=="string"){r[e]=t;return}const[n,...i]=e,o=sn(i);if(n==="{}"){const s=[];for(const u of o){if(Array.isArray(u)&&u[0]==="..."){const h={};for(const D in t)s.includes(D)||(h[D]=t[D]);r[u[1]]=h;break}let c,a,S;typeof u=="string"?c=a=u:u[0]==="="?(typeof u[1]=="string"?c=a=u[1]:[,c,a]=u[1],S=u[2]):[,c,a]=u,s.push(c);let m=t[c];m===void 0&&S&&(m=d(S)(r)),me(a,m,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,a;Array.isArray(u)&&u[0]==="="&&([,c,a]=u);let S=t[s++];S===void 0&&a&&(S=d(a)(r)),me(c,S,r)}}},_t=e=>{let t=v(nn-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,()=>_t("let"));de("const",Ze+1,()=>_t("const"));de("var",Ze,()=>(R(),["var",v(on)]));const Ut=(...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=>me(r,i(o),o)}return d(t)}),t=>{for(const r of e)r(t)});l("let",Ut);l("const",Ut);l("var",e=>typeof e=="string"?t=>{t[e]=void 0}:()=>{});const xe=20,Ce=e=>{throw Error(e)};A("||=",xe,!0);A("&&=",xe,!0);A("??=",xe,!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=>me(r,t(n),n)}return z(e)||Ce("Invalid assignment target"),t=d(t),Y(e,(r,n,i)=>r[n]=t(i))});l("||=",(e,t)=>(z(e)||Ce("Invalid assignment target"),t=d(t),Y(e,(r,n,i)=>r[n]||=t(i))));l("&&=",(e,t)=>(z(e)||Ce("Invalid assignment target"),t=d(t),Y(e,(r,n,i)=>r[n]&&=t(i))));l("??=",(e,t)=>(z(e)||Ce("Invalid assignment target"),t=d(t),Y(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 Oe=20;W("?",Oe,(e,t,r)=>e&&(t=v(Oe-1))&&b(n=>n===58)&&(r=v(Oe-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 dn=[],un=20;A("=>",un,!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 a={};r.forEach((m,h)=>a[m]=c[h]),i&&(a[i]=c.slice(n));const S=new Proxy(a,{get:(m,h)=>h in m?m[h]:u?.[h],set:(m,h,D)=>((h in m?m:u)[h]=D,!0),has:(m,h)=>h in m||(u?h in u:!1)});try{const m=t(S);return s?void 0:m}catch(m){if(m===dn)return m[0];throw m}}});const cn=140;M("...",cn);l("...",e=>(e=d(e),t=>Object.entries(e(t))));const lt=170;W("?.",lt,(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(lt),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,()=>Ir(".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 et=Symbol("accessor"),tt=20,ln=40,Nt=41,Vt=123,Lt=125,Rt=e=>t=>{if(t)return;R();const r=b($.id);if(!r||(R(),g.charCodeAt(p)!==ln))return!1;I();const n=v(0,Nt);return R(),g.charCodeAt(p)!==Vt?!1:(I(),[e,r,n,v(0,Lt)])};W("get",tt-1,Rt("get"));W("set",tt-1,Rt("set"));W("(",tt-1,e=>{if(!e||typeof e!="string")return;const t=v(0,Nt)||null;if(R(),g.charCodeAt(p)===Vt)return I(),[":",e,["=>",["()",t],v(0,Lt)||null]]});l("get",(e,t)=>(t=t?d(t):()=>{},r=>[[et,e,{get:function(){const n=Object.create(r||{});return n.this=this,t(n)}}]]));l("set",(e,t,r)=>(r=r?d(r):()=>{},n=>[[et,e,{set:function(i){const o=Object.create(n||{});o.this=this,o[t]=i,r(o)}}]]));const an=20,Mt=200;$.prop=e=>wr(e)!==58;const fn=e=>e==null||typeof e=="string"||[":",",","...","get","set"].includes(e[0]);ze("[]",Mt);ze("{}",Mt);A(":",an-1,!0);l("{}",(e,t)=>{if(t!==void 0)return;if(!fn(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]===et){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 hn=170,ye=96,pn=36,gn=123,mn=92,yn={n:`
|
|
8
|
+
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},at=()=>{const e=[];for(let t="",r;(r=g.charCodeAt(p))!==ye;)r?r===mn?(I(),t+=yn[g[p]]||g[p],I()):r===pn&&g.charCodeAt(p+1)===gn?(t&&e.push([,t]),t="",I(2),e.push(v(0,125))):(t+=g[p],I(),r=g.charCodeAt(p),r===ye&&t&&e.push([,t])):X("Unterminated template");return I(),e},$n=k[ye];k[ye]=(e,t)=>e&&t<hn?$.asi&&$.newline?void 0:(I(),["``",e,...at()]):e?$n?.(e,t):(I(),(r=>r.length<2&&r[0]?.[0]===void 0?r[0]||[,""]:["`",...r])(at()));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)))});$.string["'"]=!0;$.number={"0x":16,"0b":2,"0o":8};const An={log:(e,t)=>(t?console.log(t,e):console.log(e),e)};function _(e,t,r,n,i){const o=$(rt(e));return d(o)({$form:t,$meta:r,$errors:n,$formIsInvalid:i,$log:An.log})===!0}function rt(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=Sn(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 Sn(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 nt=Symbol("filterMap.skip");function Bt(e,t){const r=[];for(let n=0;n<e.length;n++){const i=t(e[n],n,e);i!==nt&&r.push(i)}return r}function vn(e,t,r){for(let n=0;n<e.length;n++)t(e[n],n,e)&&r(e[n],n,e)}function En(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 Cn(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 Ht(e,t){const r=Gt(e.uid,t);return O(e)?{...e,uid:r,path:wn(e.path,t)}:{...e,uid:r}}function Gt(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 ue(e,t){let r=0;return e.replace(/\.items(\??)\./g,(n,i)=>{const o=t[r++];return o===void 0?n:`.${o}${i}.`})}const ce=(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}=Ke(e);return{...e,widgetFlags:{...In(e,r,t),...On(e,r,t)}}};function In(e,t,r){return Bt(Object.values(e.flatForm),n=>{if(n.uid?.includes("["))return nt;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)||(O(n)||x(n))&&H(n.disabled)||O(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)),(O(i)||x(i))&&H(i.disabled)&&(n[i.uid].disabled=_(i.disabled.when,e.data,e.meta,t,r)),O(i)&&H(i.readonly)&&(n[i.uid].readonly=_(i.readonly.when,e.data,e.meta,t,r)),n),{})}function On(e,t,r){return En(Object.values(e.flatForm),n=>!ie(n)&&n.type==="repeater",(n,i)=>({...n,...Kt(e,i,[],t,r)}),{})}function Kt(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,a)=>{const S=[...r,a];Ge([o]).forEach(m=>{let h;if(ie(m)?(h=m({$form:e.data,errors:void 0,touched:void 0,translate:void 0}),h.uid=m.uid):h=m,h.type==="repeater"){const Z=Ht(h,S);Object.assign(u,Kt(e,Z,S,n,i));return}const D=Gt(h.uid,S);u[D]=u[D]||{},h.include&&"in"in h.include?u[D].hidden=!h.include.in.some(Z=>e.currentStates.includes(Z)):h.include&&"when"in h.include&&(u[D].hidden=!_(ue(h.include.when,S),e.data,e.meta,n,i)),h.exclude&&"from"in h.exclude?u[D].hidden=h.exclude.from.some(Z=>e.currentStates.includes(Z)):h.exclude&&"when"in h.exclude&&(u[D].hidden=_(ue(h.exclude.when,S),e.data,e.meta,n,i)),(O(h)||x(h))&&H(h.disabled)&&(u[D].disabled=_(ue(h.disabled.when,S),e.data,e.meta,n,i)),O(h)&&H(h.readonly)&&(u[D].readonly=_(ue(h.readonly.when,S),e.data,e.meta,n,i))})}),u}const j=e=>t=>{try{return{...t,calculatedWidgets:Dn(t,e)}}catch(r){const n=r;return{...t,formHealth:{status:"errored",message:`[${n.code}] ${n.message}`,code:n.code}}}};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(ie(c)){o[s]=Tn(s,c,e,t);continue}o[s]=Fn(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 Fn(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),sr(t)?Wn(i,n):x(t)?kn(i,n):O(t)?Pn(i,n):We(t)&&jn(i,n),_n(t,i,n,r),(x(t)||O(t))&&Un(t,i,n),We(t)&&Nn(t,i,r),i.changed?{source:e.source,current:i.current}:e}function Wn(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 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,"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 _n(e,t,r,n){const i=n.widgetPropOverrides[e.uid]??{},o={...e.props??{},...i};for(const s of Jt(Object.keys(o)))Vn(t,r,s)}function Un(e,t,r){const n=e.on??{};for(const i of Jt(Object.keys(n)))Ln(t,r,i)}function Nn(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=ot(n,r,t.sortedStates);let o;switch(r){case"disabled":case"readonly":o=Bn(i,t,e.source.uid,r);break;case"defaultValue":o=i;break;default:o=zt(i,t)}e.write(r,o)}function Vn(e,t,r){const n=e.source.props,i=ot(n,r,t.sortedStates);let o=zt(i,t);const s=t.widgetPropOverrides[e.source.uid]?.[r];s!==void 0&&(o=s),e.write(`props.${r}`,o)}function Ln(e,t,r){const n=e.source.on,i=ot(n,r,t.sortedStates);e.write(`on.${r}`,Hn(i,t))}function it(e,t){return e({$form:t.$form,translate:t.localization.translate})}function Rn(e,t){return t.localization.translate(e.key,Kn(e.params,t),e.default)}const Mn=/\{\{([^}]+)\}\}/g;function Xt(e,t){return e.includes("{{")?e.replace(Mn,(r,n)=>{const i=rt(n.trim());try{const o=d($(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 Qt(`Failed to evaluate '{{${n.trim()}}}': ${s}`)}}):e}function zt(e,t){return typeof e=="function"?it(e,t):yr(e)?Rn(e,t):typeof e=="string"?Xt(e,t):e}function Bn(e,t,r,n){return typeof e=="function"?it(e,t):H(e)?t.widgetFlags[r]?.[n]:typeof e=="string"?Xt(e,t):e}function Hn(e,t){return typeof e=="function"?it(e,t):e}function ot(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 Gn(e){return e.startsWith("$form")||e.startsWith("$meta")||e.startsWith("$errors")||e==="$formIsInvalid"}function Kn(e,t){return e&&Object.keys(e).reduce((r,n)=>{const i=String(e[n]);if(Gn(i))try{const o=d($(rt(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 Qt(`Failed to evaluate i18n param '${i}': ${s}`)}else r[n]=i;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),oe(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 Jt(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));class Qt extends Error{constructor(){super(...arguments),this.code=Q.resolveStringInterpolationError,this.name="StringInterpolationError"}}const bn=({lang:e},t)=>{const r={...$t(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,a=Q.initializeParseError;i={status:"errored",message:`[${a}] ${c.message}`,code:a}}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=yt.decode(n);if(o.isOk()){i={status:"ok"};let u={};try{u=Ge([o.value.form]).reduce((c,a)=>{const S=a.uid;if(c[S])throw{existingWidget:c[S],newWidget:a};return c[S]=a,c},{})}catch(c){const a=Q.initializeUidCollisionError;i={status:"errored",message:`[${a}] ${Yn(c.existingWidget,c.newWidget)}`,code:a},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 Yn(e,t){const r=n=>O(n)?` at "${n.path}"`:"";return`Duplicate UID "${t.uid}": Assigned to widget "${e.type}"${r(e)} and "${t.type}"${r(t)}.`}function Zn(e,t){return{...e,injectedValidations:{...e.injectedValidations,[t.payload.path]:t.payload.issues}}}const xn=(e,{payload:t})=>{let r;if("path"in t){if(r=Object.values(e.calculatedWidgets).find(({source:o})=>O(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 P(e,ti(t),ri(t),ni(t),ii(t))}const ti=e=>t=>({...t,widgetFlags:{...ve(t.widgetFlags,e.payload.uid)}}),ri=e=>t=>({...t,calculatedWidgets:{...ve(t.calculatedWidgets,e.payload.uid)}}),ni=e=>t=>({...t,widgetPropOverrides:{...ve(t.widgetPropOverrides,e.payload.uid)}}),ii=e=>t=>({...t,touchedControls:P(t.touchedControls,r=>{const n=t.flatForm[e.payload.uid];return n&&O(n)?ve(r,n.path):r})}),oi=(e,t)=>({...e,data:{...t.payload.data}}),si=(e,t)=>({...e,formHealth:t.payload.formHealth}),di=(e,t)=>({...e,lang:t.payload.lang}),ui=(e,t)=>({...e,meta:{...t.payload.meta}}),ci=(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:{...He(e.data,t.payload.path,t.payload.data)}}:e},De=(e,t)=>r=>{const n=Bt(Object.values(r.calculatedWidgets),({current:o})=>O(o)?o:nt),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),a=ht(u,c);o[s.path]=pt(a)?null:a.issues.map(S=>S.message)}return Array.isArray(o[s.path])&&Array.isArray(i[s.path])&&Cn(o[s.path],i[s.path],(u,c)=>u===c)&&(o[s.path]=i[s.path]),o},{})}},li=({validators:e,validateOn:t,localization:r})=>(n,i)=>{switch(i.type){case"INITIALIZE":return bn(n,i);case"SET_DATA":return P(oi(n,i),U,N,j(r));case"SET_META":return P(ui(n,i),U,N,j(r));case"SET_LANGUAGE":return P(di(n,i),j(r));case"ADD_WIDGET":return P(Sr(n,i),ce(Te,U),ce(Te,N),ce(Te,j(r)));case"REMOVE_WIDGET":return P(ei(n,i),U,N,j(r));case"SET_WIDGET_INITIAL_DATA":case"SET_WIDGET_DATA":return P(ci(n,i),U,N,j(r));case"OVERRIDE_WIDGET_PROP":return P(xn(n,i),U,N,j(r),ce(o=>{let s=!1,u="";"path"in i.payload?(s=!0,u=i.payload.path):O(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},De(e,r)));case"SET_FORM_HEALTH":return si(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 O(u)&&(o[u.path]=!0),o},{})},De(e,r),U,N,j(r),ft);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}},De(e,r),U,N,j(r),c=>{const a=i.payload.uid,S=c.calculatedWidgets[a],m=S.source;if(ie(m)){const h=m({$form:c.data,errors:c.validations[s],touched:!0,translate:r.translate});return{...c,calculatedWidgets:{...c.calculatedWidgets,[a]:{source:S.source,current:h}}}}return c},ft):n}case"INJECT_VALIDATION_ISSUES":return Zn(n,i);default:return Ar(i)}},Te=e=>e.formHealth.status==="ok";function ft(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 ai(e=[],t,r,n){const i=new f.BehaviorSubject($t(n.lang)),o=i.asObservable().pipe(f.distinctUntilChanged()),s=li({validators:t,validateOn:r,localization:n});function u(m){const h=i.getValue(),D=s(h,m);i.next(D)}let c=u;const a={getState:()=>i.getValue(),dispatch:m=>c(m)};return c=e.map(m=>m(a)).reduceRight((m,h)=>h(m),u),{state$:o,dispatch:c,getState:()=>i.getValue()}}class fi{constructor(){this.widgetRegistry=new Pe,this.store={},this.events$=new f.Subject,this.submit$=new f.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=ai(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:we(this.store.getState()),detail:n??void 0,callback:c=>{this.store.dispatch(c)}})});else{const s=r.on?.[t];this.attemptValidation(t,r),s&&this.events$.next({name:s,data:we(this.store.getState()),detail:n,callback:u=>{this.store.dispatch(u)}})}}emitSubmitEvent(){this.store.dispatch({type:"VALIDATE_ALL"}),this.store.getState().isFormValid&&this.submit$.next({data:we(this.store.getState()),callback:t=>{this.store.dispatch(t)}})}attemptValidation(t,r){r.kind!=="layout"&&(t==="change"?this.store.dispatch({type:"ATTEMPT_VALIDATION",payload:{reason:"change",path:r.path,uid:r.uid}}):t==="click"&&r.kind==="action"&&r.actionType==="submit"&&this.store.dispatch({type:"VALIDATE_ALL"}))}}function hi(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 pi=f.pipe(f.map(e=>e.data),f.distinctUntilChanged()),gi=e=>f.pipe(pi,f.map(t=>oe(t,e)),f.distinctUntilChanged()),mi=f.pipe(f.filter(e=>e.touched===!0),f.map(e=>e.validations),f.distinctUntilChanged()),yi=e=>f.pipe(mi,f.map(t=>t[e]),f.distinctUntilChanged()),$i=f.pipe(f.filter(e=>e.touched===!0),f.map(e=>e.injectedValidations),f.distinctUntilChanged()),Ai=e=>f.pipe($i,f.map(t=>t[e]),f.distinctUntilChanged(),f.startWith(null)),Si=f.pipe(f.map(e=>e.lang),f.distinctUntilChanged()),qt=f.pipe(f.map(e=>e.calculatedWidgets),f.distinctUntilChanged()),vi=e=>t=>f.combineLatest([t.pipe(Si),t.pipe(qt)]).pipe(f.map(([r,n])=>({lang:r,widget:n[e]})),f.filter(r=>r.widget!==void 0),f.distinctUntilChanged((r,n)=>r.lang===n.lang&&r.widget===n.widget),f.map(r=>r.widget.current)),Ei=e=>f.pipe(qt,f.map(t=>t[e]),f.filter(t=>t!==void 0),f.map(t=>t.current.children),f.distinctUntilChanged());f.pipe(f.map(e=>e.widgetFlags),f.distinctUntilChanged());const Ci=f.pipe(f.map(e=>e.touchedControls),f.distinctUntilChanged()),wi=e=>f.pipe(Ci,f.map(t=>t[e]),f.distinctUntilChanged()),Ii=f.pipe(f.map(e=>e.formHealth),f.distinctUntilChanged((e,t)=>e.status!==t.status?!1:e.status==="errored"&&t.status==="errored"?e.message===t.message&&e.code===t.code:!0)),Oi=e=>e.pipe(Ii);let bt=!1;function Di(){bt=!0}function Ti(){return bt}function Fi(e,t,r){if(!Ti())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=fi;exports.assertNoPropCollisions=Fi;exports.calculatedLayoutChildrenByUid$=Ei;exports.calculatedWidgetsByUid$=vi;exports.cloneObject=ae;exports.dataByPath$=gi;exports.defineForm=mr;exports.devToolsMiddleware=hi;exports.enableDevMode=Di;exports.errorCodes=Q;exports.filterTap=vn;exports.formHealth=Oi;exports.getDirectionFromLanguage=$r;exports.identityTranslator=At;exports.injectedValidationByPath$=Ai;exports.isStandardValidateSuccess=pt;exports.makeRepeaterItemConfig=Ht;exports.shortUUID=Ve;exports.standardValidate=ht;exports.touchedControlsByPath$=wi;exports.validationByPath$=yi;
|
package/lib/shared.d.ts
CHANGED
|
@@ -155,6 +155,11 @@ export type ActionWidgetTemplateData = {
|
|
|
155
155
|
deps?: Record<string, unknown>;
|
|
156
156
|
label?: string;
|
|
157
157
|
disabled?: boolean;
|
|
158
|
+
/**
|
|
159
|
+
* True when the form has been touched and is currently invalid.
|
|
160
|
+
* Used by submit buttons to show an error visual state.
|
|
161
|
+
*/
|
|
162
|
+
invalid?: boolean;
|
|
158
163
|
/**
|
|
159
164
|
* A size relative to the container and sibling components
|
|
160
165
|
* @example
|
package/lib/utils/decoder.d.ts
CHANGED
|
@@ -13,11 +13,11 @@ export type KeySpec<A> = Record<string, {
|
|
|
13
13
|
* - the decoder used to validate the corresponding values
|
|
14
14
|
*
|
|
15
15
|
* Matching rules:
|
|
16
|
-
* - If `suffixed` is `false`, only the exact key is
|
|
16
|
+
* - If `suffixed` is `false`, only the exact key is decoded.
|
|
17
17
|
* - If `suffixed` is `true`, both the base key and any keys starting with
|
|
18
|
-
* `<key>.` are
|
|
19
|
-
* -
|
|
20
|
-
*
|
|
18
|
+
* `<key>.` are decoded.
|
|
19
|
+
* - Object keys that do not match any specification are silently stripped
|
|
20
|
+
* from the decoded output.
|
|
21
21
|
*
|
|
22
22
|
* All values are decoded independently using the decoder associated with the
|
|
23
23
|
* matched key. Decoded values are returned under their original object keys
|
package/lib/utils/form.d.ts
CHANGED
|
@@ -28,3 +28,9 @@ export declare function calculateValidationVariables(state: State): {
|
|
|
28
28
|
$formIsInvalid: boolean;
|
|
29
29
|
$errors: $Errors;
|
|
30
30
|
};
|
|
31
|
+
/**
|
|
32
|
+
* Returns a copy of the form data with values for currently-hidden input widgets removed.
|
|
33
|
+
* Paths are derived from the flat form widget map so this works even though hidden widgets
|
|
34
|
+
* are absent from calculatedWidgets.
|
|
35
|
+
*/
|
|
36
|
+
export declare function pruneHiddenData(state: State): Record<string, any>;
|
package/lib/utils/object.d.ts
CHANGED
|
@@ -119,6 +119,43 @@ export declare const get: <T = any>(obj: Record<string, any>, path: DotPath) =>
|
|
|
119
119
|
* ```
|
|
120
120
|
*/
|
|
121
121
|
export declare const set: (object: Record<string, any>, path: DotPath, value: any) => Record<string, any>;
|
|
122
|
+
/**
|
|
123
|
+
* Removes the property at the given dot-path from object by mutation.
|
|
124
|
+
* After deletion, any ancestor plain objects that become empty are also removed.
|
|
125
|
+
* Ancestor arrays that become empty are left in place — upward pruning stops as
|
|
126
|
+
* soon as an array boundary is encountered.
|
|
127
|
+
*
|
|
128
|
+
* @param object - The object to modify
|
|
129
|
+
* @param path - The dot-separated path of the property to remove (e.g. "user.profile.name").
|
|
130
|
+
* Pass an empty string to return the object unchanged.
|
|
131
|
+
* @returns The modified object (mutates the original object). Returns unchanged if path is
|
|
132
|
+
* empty or does not exist.
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* Basic property removal with sibling preserved:
|
|
136
|
+
* ```typescript
|
|
137
|
+
* const obj = { user: { name: 'John', age: 30 } };
|
|
138
|
+
* unset(obj, 'user.name');
|
|
139
|
+
* // Result: { user: { age: 30 } }
|
|
140
|
+
* ```
|
|
141
|
+
*
|
|
142
|
+
* @example
|
|
143
|
+
* Recursive pruning of empty ancestors:
|
|
144
|
+
* ```typescript
|
|
145
|
+
* const obj = { a: { b: { c: 1 } } };
|
|
146
|
+
* unset(obj, 'a.b.c');
|
|
147
|
+
* // Result: {} — 'b' and 'a' are pruned because they became empty objects
|
|
148
|
+
* ```
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* Pruning stops at array boundaries:
|
|
152
|
+
* ```typescript
|
|
153
|
+
* const obj = { items: [{ name: 'Alice' }] };
|
|
154
|
+
* unset(obj, 'items.0.name');
|
|
155
|
+
* // Result: { items: [{}] } — the empty object is kept inside the array
|
|
156
|
+
* ```
|
|
157
|
+
*/
|
|
158
|
+
export declare const unset: <T extends Record<string, any>>(object: T, path: DotPath) => T;
|
|
122
159
|
/**
|
|
123
160
|
* Deletes a key from an object and returns the same mutated object.
|
|
124
161
|
*
|