@golemui/core 0.0.2

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.
Files changed (51) hide show
  1. package/CHANGELOG.md +517 -0
  2. package/README.md +11 -0
  3. package/index.d.ts +18 -0
  4. package/index.js +1598 -0
  5. package/index.umd.cjs +8 -0
  6. package/lib/context/form.context.d.ts +21 -0
  7. package/lib/context/index.d.ts +3 -0
  8. package/lib/context/widget-registry.d.ts +13 -0
  9. package/lib/context/with-widget.type.d.ts +4 -0
  10. package/lib/form-store.d.ts +12 -0
  11. package/lib/form-validator.d.ts +10 -0
  12. package/lib/form-widget.d.ts +93 -0
  13. package/lib/form.d.ts +22 -0
  14. package/lib/i18n.d.ts +87 -0
  15. package/lib/item-renderer.d.ts +24 -0
  16. package/lib/middleware/index.d.ts +2 -0
  17. package/lib/middleware/json-schema/json-schema.d.ts +67 -0
  18. package/lib/middleware/json-schema/json-schema.middleware.d.ts +19 -0
  19. package/lib/shared.d.ts +143 -0
  20. package/lib/store/actions.d.ts +121 -0
  21. package/lib/store/model.d.ts +107 -0
  22. package/lib/store/reducer.d.ts +10 -0
  23. package/lib/store/reducers/add-widget.d.ts +3 -0
  24. package/lib/store/reducers/calculate-current-state.d.ts +2 -0
  25. package/lib/store/reducers/calculate-widget-flags.d.ts +2 -0
  26. package/lib/store/reducers/calculate-widget-props.d.ts +3 -0
  27. package/lib/store/reducers/index.d.ts +13 -0
  28. package/lib/store/reducers/initialize.d.ts +3 -0
  29. package/lib/store/reducers/inject-validation-issues.d.ts +3 -0
  30. package/lib/store/reducers/override-widget-prop.d.ts +3 -0
  31. package/lib/store/reducers/remove-widget.d.ts +3 -0
  32. package/lib/store/reducers/set-data.d.ts +3 -0
  33. package/lib/store/reducers/set-form-health.d.ts +8 -0
  34. package/lib/store/reducers/set-language.d.ts +3 -0
  35. package/lib/store/reducers/set-widget-data.d.ts +3 -0
  36. package/lib/store/reducers/utils.d.ts +32 -0
  37. package/lib/store/reducers/validate-all.d.ts +3 -0
  38. package/lib/store/selectors.d.ts +21 -0
  39. package/lib/utils/array.d.ts +61 -0
  40. package/lib/utils/assert-never.d.ts +5 -0
  41. package/lib/utils/debug.d.ts +3 -0
  42. package/lib/utils/decoder.d.ts +51 -0
  43. package/lib/utils/dot-path.d.ts +16 -0
  44. package/lib/utils/form.d.ts +20 -0
  45. package/lib/utils/function.d.ts +71 -0
  46. package/lib/utils/object.d.ts +140 -0
  47. package/lib/utils/random.d.ts +1 -0
  48. package/lib/utils/repeater.d.ts +2 -0
  49. package/lib/utils/suffixable.d.ts +16 -0
  50. package/lib/utils/types.d.ts +63 -0
  51. package/package.json +30 -0
package/index.umd.cjs ADDED
@@ -0,0 +1,8 @@
1
+ (function(g,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("rxjs")):typeof define=="function"&&define.amd?define(["exports","rxjs"],a):(g=typeof globalThis<"u"?globalThis:g||self,a(g.core={},g.rxjs))})(this,(function(g,a){"use strict";var _t=class{constructor(e){this.value=e}map(e){return w(e(this.value))}isOk(){return!0}},Ut=class{constructor(e){this.error=e}map(e){return v(this.error)}isOk(){return!1}};function w(e){return new _t(e)}function v(e){return new Ut(e)}var D=class qe{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 o=this.decode(t);return o.isOk()?r(o.value):n(o.error)})}map(t){return new qe(r=>{let n=this.decodeFn(r);return n.isOk()?w(t(n.value)):v(n.error)})}flatMap(t){return new qe(r=>{let n=this.decodeFn(r);return n.isOk()?t(n.value).decode(r):v(n.error)})}},Nt=(e,t,r)=>`<${e}> decoder failed at index "${t}" with error: ${r}`,H=(e,t)=>`${JSON.stringify(e)} is not a valid ${t}`;function Ce(e,t){return new D(r=>{if(r instanceof Array){let n=[];for(let o=0;o<r.length;o++){let i=e.decode(r[o]);if(i.isOk())n.push(i.value);else return v(Nt(t,o,i.error))}return w(n)}else return v(H(r,"array"))})}function Lt(){return new D(e=>typeof e=="boolean"?w(e):v(H(e,"boolean")))}function Rt(e){return new D(t=>e().decode(t))}var Vt=(e,t)=>`${JSON.stringify(e)} is not exactly ${JSON.stringify(t)}`;function ne(e){return new D(t=>t===e?w(e):v(Vt(t,e)))}function oe(){return new D(e=>typeof e=="number"?w(e):v(H(e,"number")))}var Bt=(e,t,r)=>`<${e}> decoder failed at key "${t}" with error: ${r}`;function X(e,t){return new D(r=>{if(r!==null&&typeof r=="object"){let n={};for(let o in e)if(Object.prototype.hasOwnProperty.call(e,o)){let i,s=e[o];if(s instanceof D?i=s.decode(r[o]):i=s.decoder.decode(r[s.fromKey]),i.isOk())n[o]=i.value;else return v(Bt(t,o,i.error))}return w(n)}else return v(H(r,t))})}var Ht=(e,t)=>`<${e}> decoder failed because ${JSON.stringify(t)} can't be decoded with any of the provided oneOf decoders`;function G(e,t){return new D(r=>{for(let n=0;n<e.length;n++){let o=e[n].decode(r);if(o.isOk())return o}return v(Ht(t,r))})}function S(e){return new D(t=>t===void 0?w(void 0):e.decode(t))}var Gt=(e,t,r)=>`<${e}> record decoder failed at key "${t}" with error: ${r}`;function Mt(e,t){return new D(r=>{if(r!==null&&typeof r=="object"){let n={};for(let o in r)if(Object.prototype.hasOwnProperty.call(r,o)){let i=e.decode(r[o]);if(i.isOk())n[o]=i.value;else return v(Gt(t,o,i.error))}return w(n)}else return v(H(r,t))})}function I(){return new D(e=>typeof e=="string"?w(e):v(H(e,"string")))}function U(){return new D(e=>w(e))}function Q(e,t){return new D(r=>{if(typeof r!="object"||r===null)return v(`<${t}> failed. Expected object literal, got "${typeof r}"`);const n={};for(const[o,i]of Object.entries(e)){const s=i.decoder.decode(r[o]);if(!s.isOk())return v(`<${t}> failed at "${o}" with ${s.error}`);if(n[o]=s.value,i.suffixed){for(const[u,c]of Object.entries(r))if(u.startsWith(o+".")){const f=i.decoder.decode(c);if(!f.isOk())return v(`<${t}> failed at "${u}" with ${f.error}`);n[u]=f.value}}}return w(n)})}const Ee=()=>crypto.randomUUID().slice(0,8),Jt=e=>typeof e!="function"&&e.kind==="display",ie=e=>typeof e!="function"&&e.kind==="action",W=e=>typeof e!="function"&&e.kind==="input",ve=e=>typeof e!="function"&&e.kind==="layout",se=e=>typeof e=="function",Kt=X({in:Ce(I(),"In[]")},"In"),Ie=X({when:I()},"When"),de=G([Kt,Ie],"In | When"),Xt=X({from:Ce(I(),"From[]")},"From"),ue=G([Xt,Ie],"Exclude"),Oe=G([Lt(),Ie],"Bool | When"),Qt=new D(e=>{const t=typeof e;return t==="function"?w(e):v(`Expected a function, got '${t}'`)}),N=e=>G([e,Qt],""),De=Q({load:{suffixed:!0,decoder:N(S(I()))},click:{suffixed:!0,decoder:N(S(I()))},change:{suffixed:!0,decoder:N(S(I()))},filter:{suffixed:!0,decoder:N(S(I()))}},"On"),Zt=X({key:I(),default:S(I()),params:U()},"TranslationConfig"),Ye=G([I(),Zt],"Localizable"),ce=S(I()).map(e=>e||Ee()),qt=Q({kind:{decoder:ne("display")},uid:{decoder:ce},type:{decoder:I()},size:{suffixed:!0,decoder:S(oe())},include:{decoder:S(de)},exclude:{decoder:S(ue)},props:{decoder:S(U())}},"DisplayWidget"),Yt=Q({kind:{decoder:ne("action")},uid:{decoder:ce},type:{decoder:I()},size:{suffixed:!0,decoder:S(oe())},include:{decoder:S(de)},exclude:{decoder:S(ue)},label:{suffixed:!0,decoder:N(Ye)},disabled:{suffixed:!0,decoder:S(Oe)},on:{decoder:S(De)},props:{decoder:S(U())}},"ActionWidget"),jt=new D(e=>{const t=typeof e;if(t==="function"){const r=e,n=r(void 0);return r.uid=n.uid||Ee(),r.type=n.type,r.path=n.path,w(r)}else return v(`Expected a function, got '${t}'`)}),zt=Q({kind:{decoder:ne("input")},uid:{decoder:ce},type:{decoder:I()},size:{suffixed:!0,decoder:S(oe())},include:{decoder:S(de)},exclude:{decoder:S(ue)},disabled:{suffixed:!0,decoder:S(Oe)},readonly:{suffixed:!0,decoder:S(Oe)},on:{decoder:S(De)},props:{decoder:S(U())},label:{suffixed:!0,decoder:N(S(Ye))},path:{decoder:I()},defaultValue:{decoder:S(U())},validator:{suffixed:!0,decoder:N(S(U()))}},"InputWidget").map(e=>{const t={...e};if(e.uid||(t.uid=`${e.path}-${e.type}`),e.type==="repeater"){const r=e.props;r.template=le.parse(r.template)}return t}),bt=Rt(()=>G([jt,zt,le,qt,Yt],"FormWidget")),le=Q({kind:{decoder:ne("layout")},uid:{decoder:ce},type:{decoder:I()},size:{suffixed:!0,decoder:S(oe())},include:{decoder:S(de)},exclude:{decoder:S(ue)},props:{decoder:S(U())},on:{decoder:S(De)},children:{decoder:Ce(bt,"FormWidget[]")}},"LayoutWidget");function xt(e){return{...e,form:{uid:"",type:"flex",kind:"layout",children:e.form}}}const we=X({states:S(Mt(I(),"states")),form:le},"FormDef"),Fe=e=>({formName:"",formDef:we.parse({form:{kind:"layout",type:"flex",children:[]}}),flatForm:{},currentStates:[],calculatedWidgets:{},validations:{},touchedControls:{},injectedValidations:{},widgetFlags:{},widgetPropOverrides:{},data:{},formHealth:{status:"ok"},touched:!1,lang:e}),er=e=>{throw new Error(`Unhandled case: ${JSON.stringify(e)}`)};function k(e,...t){return t.reduce((r,n)=>n(r),e)}function tr(...e){return t=>e.reduceRight((r,n)=>n(r),t)}function rr(e,t){return{...e,calculatedWidgets:{...e.calculatedWidgets,[t.payload.widget.uid]:{source:t.payload.widget,current:{},previous:{}}}}}const We=32;let h,y,$=e=>(h=0,y=e,$.newline=!1,e=E(),y[h]?L():e||""),L=(e="Unexpected token",t=h,r=y.slice(0,t).split(`
2
+ `),n=r.pop(),o=y.slice(Math.max(0,t-40),t),i="̭",s=(y[t]||" ")+i,u=y.slice(t+1,t+20))=>{throw SyntaxError(`${e} at ${r.length+1}:${n.length+1}
3
+ ${y[t-41]!==`
4
+ `,""+o}${s}${u}`)},je=(e,t=h)=>(Array.isArray(e)&&(e.loc=t),e),M=(e,t=h,r)=>{for(;r=e(y.charCodeAt(h));)h+=r;return y.slice(t,h)},O=(e=1)=>y[h+=e],Te=e=>h=e,E=(e=0,t)=>{let r,n,o,i,s;for(t&&$.asi&&($.newline=!1);(r=$.space())&&(s=$.newline,1)&&r!==t&&(o=((i=T[r])&&i(n,e))??(n&&s&&$.asi?.(n,e,E))??(!n&&M($.id)));)n=o;return t&&(r==t?h++:L("Unclosed "+String.fromCharCode(t-(t>42?2:1)))),n},Z=$.space=(e,t=h)=>{for(;(e=y.charCodeAt(h))<=We;)$.asi&&e===10&&($.newline=!0),h++;return e},nr=(e=h)=>{for(;y.charCodeAt(e)<=We;)e++;return y.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 or=(e,t=e.length)=>y.substr(h,t)===e&&!$.id(y.charCodeAt(h+t)),T=[],ze={},F=(e,t=We,r,n=e.charCodeAt(0),o=e.length,i=T[n],s=e.toUpperCase()!==e,u,c)=>(t=ze[e]=!i&&ze[e]||t,T[n]=(f,A,p,C=h)=>(u=p,(p?e==p:(o<2||e.charCodeAt(1)===y.charCodeAt(h+1)&&(o<3||y.substr(h,o)==e))&&(!s||!$.id(y.charCodeAt(h+o)))&&(u=p=e))&&A<t&&(h+=o,(c=r(f))?je(c,C):(h=C,u=0,!s&&!i&&L()),c)||i?.(f,A,u))),m=(e,t,r=!1)=>F(e,t,n=>n&&(o=>o&&[e,n,o])(E(t-(r?.5:0)))),P=(e,t,r)=>F(e,t,n=>!n&&(n=E(t-.5))&&[e,n]),q=(e,t)=>F(e,200,r=>!r&&[,t]),be=(e,t,r)=>F(e,t,(n,o)=>(o=E(t-(r?.5:0)),n?.[0]!==e&&(n=[e,n||null]),o?.[0]===e?n.push(...o.slice(1)):n.push(o||null),n)),ke=(e,t)=>F(e[0],t,r=>!r&&[e,E(0,e.charCodeAt(1))||null]),xe=(e,t)=>F(e[0],t,r=>r&&[e,r,E(0,e.charCodeAt(1))||null]);const Pe={},l=(e,t,r=Pe[e])=>Pe[e]=(...n)=>t(...n)||r?.(...n),d=e=>Array.isArray(e)?e[0]==null?(t=>()=>t)(e[1]):Pe[e[0]]?.(...e.slice(1))??L(`Unknown operator: ${e[0]}`,e?.loc):e===void 0?()=>{}:t=>t?.[e],ae=46,Y=48,fe=57,ir=69,sr=101,dr=43,ur=45,he=95,cr=110,lr=97,ar=102,fr=65,hr=70,et=e=>e.indexOf("_")<0?e:e.replaceAll("_",""),_e=e=>{let t=et(M(r=>r===ae&&y.charCodeAt(h+1)!==ae||r>=Y&&r<=fe||r===he||((r===ir||r===sr)&&((r=y.charCodeAt(h+1))>=Y&&r<=fe||r===dr||r===ur)?2:0)));return y.charCodeAt(h)===cr?(O(),[,BigInt(t)]):(e=+t)!=e?L():[,e]},pr={2:e=>e===48||e===49||e===he,8:e=>e>=48&&e<=55||e===he,16:e=>e>=Y&&e<=fe||e>=lr&&e<=ar||e>=fr&&e<=hr||e===he};$.number=null,T[ae]=e=>!e&&y.charCodeAt(h+1)!==ae&&_e();for(let e=Y;e<=fe;e++)T[e]=t=>t?void 0:_e();T[Y]=e=>{if(e)return;const t=$.number;if(t){for(const[r,n]of Object.entries(t))if(r[0]==="0"&&y[h+1]?.toLowerCase()===r[1])return O(2),[,parseInt(et(M(pr[n])),n)]}return _e()};const gr=92,tt=34,rt=39,yr={n:`
5
+ `,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},nt=e=>(t,r,n="")=>{if(!(t||!$.string?.[String.fromCharCode(e)]))return O(),M(o=>o-e&&(o===gr?(n+=yr[y[h+1]]||y[h+1],2):(n+=y[h],1))),y[h]===String.fromCharCode(e)?O():L("Bad string"),[,n]};T[tt]=nt(tt),T[rt]=nt(rt),$.string={'"':!0};const mr=20;"= += -= *= /= %= |= &= ^= >>= <<=".split(" ").map(e=>m(e,mr,!0));const ot=(e,t,r,n)=>typeof e=="string"?o=>t(o,e,o):e[0]==="."?(r=d(e[1]),n=e[2],o=>t(r(o),n,o)):e[0]==="[]"&&e.length===3?(r=d(e[1]),n=d(e[2]),o=>t(r(o),n(o),o)):e[0]==="()"&&e.length===2?ot(e[1],t):(()=>{throw Error("Invalid assignment target")})(),it={"=":(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 it)l(e,(t,r)=>(r=d(r),ot(t,(n,o,i)=>it[e](n,o,r(i)))));const Ar=30,Sr=40,st=140;m("!",st),P("!",st),m("||",Ar),m("&&",Sr),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 $r=50,Cr=60,Er=70,dt=100,vr=140;m("|",$r),m("&",Er),m("^",Cr),m(">>",dt),m("<<",dt),P("~",vr),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 pe=90;m("<",pe),m(">",pe),m("<=",pe),m(">=",pe),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 ut=80;m("==",ut),m("!=",ut),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 ct=110,Ue=120,lt=140;m("+",ct),m("-",ct),m("*",Ue),m("/",Ue),m("%",Ue),P("+",lt),P("-",lt),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 ge=150;F("++",ge,e=>e?["++",e,null]:["++",E(ge-1)]),F("--",ge,e=>e?["--",e,null]:["--",E(ge-1)]);const Ne=(e,t,r,n)=>typeof e=="string"?o=>t(o,e):e[0]==="."?(r=d(e[1]),n=e[2],o=>t(r(o),n)):e[0]==="[]"&&e.length===3?(r=d(e[1]),n=d(e[2]),o=>t(r(o),n(o))):e[0]==="()"&&e.length===2?Ne(e[1],t):(()=>{throw Error("Invalid increment target")})();l("++",(e,t)=>Ne(e,t===null?(r,n)=>r[n]++:(r,n)=>++r[n])),l("--",(e,t)=>Ne(e,t===null?(r,n)=>r[n]--:(r,n)=>--r[n]));const Ir=5;be(",",10),be(";",Ir,!0);const at=(...e)=>(e=e.map(d),t=>{let r;for(const n of e)r=n(t);return r});l(",",at),l(";",at),ke("()",170);const _=e=>e?.[0]==="_"&&e[1]==="_"||e==="constructor"||e==="prototype",Le=170;xe("[]",Le),m(".",Le),xe("()",Le);const ye=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&&ye("Missing index"),e=d(e),t=d(t),r=>{const n=t(r);return _(n)?void 0:e(r)[n]})),l(".",(e,t)=>(e=d(e),t=t[0]?t:t[1],_(t)?()=>{}:r=>e(r)[t])),l("()",(e,t)=>{if(t===void 0)return e==null?ye("Empty ()"):d(e);const r=o=>o?.[0]===","&&o.slice(1).some(i=>i==null||r(i));r(t)&&ye("Empty argument");const n=t?t[0]===","?(t=t.slice(1).map(d),o=>t.map(i=>i(o))):(t=d(t),o=>[t(o)]):()=>[];return Re(e,(o,i,s)=>o[i](...n(s)))});const R=e=>typeof e=="string"||Array.isArray(e)&&(e[0]==="."||e[0]==="?."||e[0]==="[]"&&e.length===3||e[0]==="?.[]"||e[0]==="()"&&e.length===2&&R(e[1])||e[0]==="{}"),Re=(e,t,r,n)=>e==null?ye("Empty ()"):e[0]==="()"&&e.length==2?Re(e[1],t):typeof e=="string"?o=>t(o,e,o):e[0]==="."?(r=d(e[1]),n=e[2],o=>t(r(o),n,o)):e[0]==="?."?(r=d(e[1]),n=e[2],o=>{const i=r(o);return i==null?void 0:t(i,n,o)}):e[0]==="[]"&&e.length===3?(r=d(e[1]),n=d(e[2]),o=>t(r(o),n(o),o)):e[0]==="?.[]"?(r=d(e[1]),n=d(e[2]),o=>{const i=r(o);return i==null?void 0:t(i,n(o),o)}):(e=d(e),o=>t([e(o)],0,o)),J=Re,Or=32,Dr=$.space;$.comment??={"//":`
6
+ `,"/*":"*/"};let Ve;$.space=()=>{Ve||(Ve=Object.entries($.comment).map(([o,i])=>[o,i,o.charCodeAt(0)]));for(var e;e=Dr();){for(var t=0,r;r=Ve[t++];)if(e===r[2]&&y.substr(h,r[0].length)===r[0]){var n=h+r[0].length;if(r[1]===`
7
+ `)for(;y.charCodeAt(n)>=Or;)n++;else{for(;y[n]&&y.substr(n,r[1].length)!==r[1];)n++;y[n]&&(n+=r[1].length)}Te(n),e=0;break}if(e)return e}return e};const ft=80;m("===",ft),m("!==",ft),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))),m("??",30),l("??",(e,t)=>(e=d(e),t=d(t),r=>e(r)??t(r)));const wr=130,Fr=20;m("**",wr,!0),m("**=",Fr,!0),l("**",(e,t)=>(e=d(e),t=d(t),r=>e(r)**t(r)));const Wr=e=>{throw Error(e)};l("**=",(e,t)=>(R(e)||Wr("Invalid assignment target"),t=d(t),J(e,(r,n,o)=>r[n]**=t(o))));const ht=90;m("in",ht),m("of",ht),l("in",(e,t)=>(e=d(e),t=d(t),r=>e(r)in t(r)));const Tr=20,kr=100,Pr=e=>{throw Error(e)};m(">>>",kr),m(">>>=",Tr,!0),l(">>>",(e,t)=>(e=d(e),t=d(t),r=>e(r)>>>t(r))),l(">>>=",(e,t)=>(R(e)||Pr("Invalid assignment target"),t=d(t),J(e,(r,n,o)=>r[n]>>>=t(o))));const _r=e=>e[0]?.[0]===","?e[0].slice(1):e,Be=(e,t,r)=>{if(typeof e=="string"){r[e]=t;return}const[n,...o]=e,i=_r(o);if(n==="{}"){const s=[];for(const u of i){if(Array.isArray(u)&&u[0]==="..."){const C={};for(const B in t)s.includes(B)||(C[B]=t[B]);r[u[1]]=C;break}let c,f,A;typeof u=="string"?c=f=u:u[0]==="="?(typeof u[1]=="string"?c=f=u[1]:[,c,f]=u[1],A=u[2]):[,c,f]=u,s.push(c);let p=t[c];p===void 0&&A&&(p=d(A)(r)),Be(f,p,r)}}else if(n==="[]"){let s=0;for(const u of i){if(u===null){s++;continue}if(Array.isArray(u)&&u[0]==="..."){r[u[1]]=t.slice(s);break}let c=u,f;Array.isArray(u)&&u[0]==="="&&([,c,f]=u);let A=t[s++];A===void 0&&f&&(A=d(f)(r)),Be(c,A,r)}}},He=20,me=e=>{throw Error(e)};m("||=",He,!0),m("&&=",He,!0),m("??=",He,!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=>Be(r,t(n),n)}return R(e)||me("Invalid assignment target"),t=d(t),J(e,(r,n,o)=>r[n]=t(o))}),l("||=",(e,t)=>(R(e)||me("Invalid assignment target"),t=d(t),J(e,(r,n,o)=>r[n]||=t(o)))),l("&&=",(e,t)=>(R(e)||me("Invalid assignment target"),t=d(t),J(e,(r,n,o)=>r[n]&&=t(o)))),l("??=",(e,t)=>(R(e)||me("Invalid assignment target"),t=d(t),J(e,(r,n,o)=>r[n]??=t(o))));const pt=(e,t,r,n=e.charCodeAt(0),o=e.length,i=T[n],s)=>T[n]=(u,c,f,A=h)=>!u&&(f?e==f:(o<2||y.substr(h,o)==e)&&(f=e))&&c<t&&!$.id(y.charCodeAt(h+o))&&nr(h+o)!==58&&(Te(h+o),(s=r())?je(s,A):Te(A),s)||i?.(u,c,f);q("true",!0),q("false",!1),q("null",null),pt("undefined",200,()=>[]),q("NaN",NaN),q("Infinity",1/0);const Ge=20;F("?",Ge,(e,t,r)=>e&&(t=E(Ge-1))&&M(n=>n===58)&&(r=E(Ge-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 Ur=[];m("=>",20,!0),l("=>",(e,t)=>{e=e?.[0]==="()"?e[1]:e;const r=e?e[0]===","?e.slice(1):[e]:[];let n=-1,o=null;const i=r[r.length-1];Array.isArray(i)&&i[0]==="..."&&(n=r.length-1,o=i[1],r.length--);const s=t?.[0]==="{}";return t=d(s?["{",t[1]]:t),u=>(...c)=>{const f={};r.forEach((p,C)=>f[p]=c[C]),o&&(f[o]=c.slice(n));const A=new Proxy(f,{get:(p,C)=>C in p?p[C]:u?.[C],set:(p,C,B)=>((C in p?p:u)[C]=B,!0),has:(p,C)=>C in p||(u?C in u:!1)});try{const p=t(A);return s?void 0:p}catch(p){if(p===Ur)return p[0];throw p}}}),P("...",140),l("...",e=>(e=d(e),t=>Object.entries(e(t))));const gt=170;F("?.",gt,(e,t)=>{if(!e)return;const r=Z();return r===40?(O(),["?.()",e,E(0,41)||null]):r===91?(O(),["?.[]",e,E(0,93)]):(t=E(gt),t?["?.",e,t]:void 0)}),l("?.",(e,t)=>(e=d(e),_(t)?()=>{}:r=>e(r)?.[t])),l("?.[]",(e,t)=>(e=d(e),t=d(t),r=>{const n=t(r);return _(n)?void 0:e(r)?.[n]})),l("?.()",(e,t)=>{const r=t?t[0]===","?(t=t.slice(1).map(d),o=>t.map(i=>i(o))):(t=d(t),o=>[t(o)]):()=>[];if(e[0]==="?."){const o=d(e[1]),i=e[2];return _(i)?()=>{}:s=>o(s)?.[i]?.(...r(s))}if(e[0]==="?.[]"){const o=d(e[1]),i=d(e[2]);return s=>{const u=o(s),c=i(s);return _(c)?void 0:u?.[c]?.(...r(s))}}if(e[0]==="."){const o=d(e[1]),i=e[2];return _(i)?()=>{}:s=>o(s)?.[i]?.(...r(s))}if(e[0]==="[]"&&e.length===3){const o=d(e[1]),i=d(e[2]);return s=>{const u=o(s),c=i(s);return _(c)?void 0:u?.[c]?.(...r(s))}}const n=d(e);return o=>n(o)?.(...r(o))});const j=140;P("typeof",j),P("void",j),P("delete",j),pt("new",j,()=>or(".target")?(O(7),["new.target"]):["new",E(j)]),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]===","?(o=>i=>o.map(s=>s(i)))(r.slice(1).map(d)):(o=>i=>[o(i)])(d(r)):()=>[];return o=>new(t(o))(...n(o))});const Me=Symbol("accessor"),Je=20,Nr=40,yt=41,mt=123,At=125,St=e=>t=>{if(t)return;Z();const r=M($.id);if(!r||(Z(),y.charCodeAt(h)!==Nr))return!1;O();const n=E(0,yt);return Z(),y.charCodeAt(h)!==mt?!1:(O(),[e,r,n,E(0,At)])};F("get",Je-1,St("get")),F("set",Je-1,St("set")),F("(",Je-1,e=>{if(!e||typeof e!="string")return;const t=E(0,yt)||null;if(Z(),y.charCodeAt(h)===mt)return O(),[":",e,["=>",["()",t],E(0,At)||null]]}),l("get",(e,t)=>(t=t?d(t):()=>{},r=>[[Me,e,{get:function(){const n=Object.create(r||{});return n.this=this,t(n)}}]])),l("set",(e,t,r)=>(r=r?d(r):()=>{},n=>[[Me,e,{set:function(o){const i=Object.create(n||{});i.this=this,i[t]=o,r(i)}}]]));const Lr=20,$t=200,Rr=e=>e==null||typeof e=="string"||[":",",","...","get","set"].includes(e[0]);ke("[]",$t),ke("{}",$t),m(":",Lr-1,!0),l("{}",(e,t)=>{if(t!==void 0)return;if(!Rr(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 o={},i={};for(const s of r.flatMap(u=>u(n)))if(s[0]===Me){const[,u,c]=s;i[u]={...i[u],...c,configurable:!0,enumerable:!0}}else o[s[0]]=s[1];for(const s in i)Object.defineProperty(o,s,i[s]);return o}}),l("{",e=>(e=e?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 Vr=170,Ae=96,Br=36,Hr=123,Gr=92,Mr={n:`
8
+ `,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},Ct=()=>{const e=[];for(let t="",r;(r=y.charCodeAt(h))!==Ae;)r?r===Gr?(O(),t+=Mr[y[h]]||y[h],O()):r===Br&&y.charCodeAt(h+1)===Hr?(t&&e.push([,t]),t="",O(2),e.push(E(0,125))):(t+=y[h],O(),r=y.charCodeAt(h),r===Ae&&t&&e.push([,t])):L("Unterminated template");return O(),e},Jr=T[Ae];T[Ae]=(e,t)=>e&&t<Vr?$.asi&&$.newline?void 0:(O(),["``",e,...Ct()]):e?Jr?.(e,t):(O(),(r=>r.length<2&&r[0]?.[0]===void 0?r[0]||[,""]:["`",...r])(Ct())),l("`",(...e)=>(e=e.map(d),t=>e.map(r=>r(t)).join(""))),l("``",(e,...t)=>{e=d(e);const r=[],n=[];for(const i of t)Array.isArray(i)&&i[0]===void 0?r.push(i[1]):n.push(d(i));const o=Object.assign([...r],{raw:r});return i=>e(i)(o,...n.map(s=>s(i)))}),$.string["'"]=!0,$.number={"0x":16,"0b":2,"0o":8};const z=e=>{let t=e.formDef.states;if(!t||Object.keys(t).length===0||e.formHealth.status==="errored")return e;t=Kr(t);let r=[],n={status:"ok"};try{r=Object.keys(t).map(o=>{const i=t[o],s=$(i);return d(s)({$form:e.data,$log:(f,A)=>(A?console.log(A,f):console.log(f),f)})===!0?o:void 0}).filter(o=>o!==void 0)}catch(o){n={status:"errored",message:o.message}}return{...e,currentStates:r,formHealth:n}};function Kr(e){const t={};function r(n){const o=n.split(":"),i=[];for(let s=0;s<o.length;s++)i.push(o.slice(0,s+1).join(":"));return i}for(const[n,o]of Object.entries(e)){const i=r(n),s=[];for(const u of i)e[u]&&s.push(`(${e[u]})`);t[n]=s.join(" && ")}return t}const Se=(e,t)=>r=>e(r)?t(r):r,Xr=e=>t=>{const r=t.touchedControls[e];return t.touched&&r},b=e=>e!==void 0&&typeof e=="object"&&e!==null&&"when"in e,x=e=>({...e,widgetFlags:Qr(e)});function Qr(e){return Object.values(e.flatForm).map(t=>{if(se(t)){const r=t({$form:e.data,errors:void 0,touched:void 0,translate:void 0});return r.uid=t.uid,r}return t}).filter(t=>!!(t.include&&("in"in t.include||t.include)||t.exclude&&("from"in t.exclude||"when"in t.exclude)||W(t)||ie(t)&&b(t.disabled)||W(t)&&b(t.readonly))).reduce((t,r)=>(t[r.uid]=t[r.uid]||{},r.include&&"in"in r.include?t[r.uid].hidden=!r.include.in.some(n=>e.currentStates.includes(n)):r.include&&"when"in r.include&&(t[r.uid].hidden=!$e(r.include.when,e.data)),r.exclude&&"from"in r.exclude?t[r.uid].hidden=r.exclude.from.some(n=>e.currentStates.includes(n)):r.exclude&&"when"in r.exclude&&(t[r.uid].hidden=$e(r.exclude.when,e.data)),(W(r)||ie(r))&&b(r.disabled)&&(t[r.uid].disabled=$e(r.disabled.when,e.data)),W(r)&&b(r.readonly)&&(t[r.uid].readonly=$e(r.readonly.when,e.data)),t),{})}function $e(e,t){const r=$(e);return d(r)({$form:t,$log:(i,s)=>(s?console.log(s,i):console.log(i),i)})===!0}const Et=e=>!(typeof e!="object"||e===null||typeof e.key!="string");function Zr(e){const t=new Intl.Locale(e).maximize().script;return["Arab","Hebr","Thaa","Syrc","Tfng","Adlm","Rohg"].includes(t||"")?"rtl":"ltr"}const vt=(e=navigator.language||"en-US")=>({get lang(){return e},translate(t){return t},subscribe(){return()=>{}}}),qr=e=>typeof e=="string"&&!e.includes(" ")&&(e.startsWith("$form.")||e.startsWith("$error.")||e.startsWith("$meta.")),V=(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)},ee=(e,t,r)=>{if(e===null)throw new Error("object is null");if(e===void 0)throw new Error("object is undefined");if(t==="")throw new Error("path cannot be empty");const n=t.split(".");let o=e;for(let s=0;s<n.length-1;s++){const u=n[s],c=n[s+1];(o[u]==null||typeof o[u]!="object")&&(o[u]=Yr(c)?[]:{}),o=o[u]}const i=n[n.length-1];return o[i]=r,e};function Yr(e){const t=Number(e);return Number.isInteger(t)&&t>=0&&t.toString()===e}const te=(e,t)=>(delete e[t],e);function jr(e){return JSON.parse(JSON.stringify(e))}const K=e=>t=>({...t,calculatedWidgets:br(t,e)}),zr=(e,t)=>({source:e,previous:t,current:{},changed:!1});function Ke(e){return Array.from(new Set(e.map(t=>t.split(".")[0])))}function br(e,t){return Object.keys(e.calculatedWidgets).reduce((r,n)=>{if(e.widgetFlags[n]!==void 0&&e.widgetFlags[n].hidden)return r;const o=e.calculatedWidgets[n],i=o.source;if(se(i))return o.previous=o.current,o.current=i({$form:e.data,errors:i.path?e.validations[i.path]:void 0,touched:i.path?e.touchedControls[i.path]:void 0,translate:t.translate}),o.current.uid=n,r[n]={...o},r;const s=zr(i,o.current);Ke(Object.keys(i)).filter(c=>c!=="props"&&c!=="on").forEach(c=>{Xe({currentStates:e.currentStates,widgetPropOverrides:e.widgetPropOverrides,derivedWidget:s,property:c,$form:e.data,widgetFlags:e.widgetFlags,localization:t})});const u={...i.props||{},...e.widgetPropOverrides[i.uid]};if(Ke(Object.keys(u)).forEach(c=>{Xe({currentStates:e.currentStates,widgetPropOverrides:e.widgetPropOverrides,derivedWidget:s,property:"props",subProp:c,$form:e.data,widgetFlags:e.widgetFlags,localization:t})}),(W(i)||ie(i))&&Ke(Object.keys(i.on||{})).forEach(c=>{Xe({currentStates:e.currentStates,widgetPropOverrides:e.widgetPropOverrides,derivedWidget:s,property:"on",subProp:c,$form:e.data,widgetFlags:e.widgetFlags,localization:t})}),ve(i)){const c=s.previous.children||[],f=i.children.filter(A=>!e.widgetFlags[A.uid]||e.widgetFlags[A.uid].hidden!==!0);s.current.children=f,s.changed=c.length!==f.length||!f.every((A,p)=>c[p]&&c[p].uid===f[p].uid)}return r[n]=s.changed?s:o,delete r[n].changed,r},{})}function Xe({currentStates:e,widgetPropOverrides:t,derivedWidget:r,property:n,subProp:o,$form:i,widgetFlags:s,localization:u}){const c=e.sort((p,C)=>C.length-p.length).find(p=>(o?r.source?.[n]?.[`${o}.${p}`]:r.source[`${n}.${p}`])!==void 0);let f;c===void 0?f=o?r.source[n]?.[o]:r.source[n]:f=o?r.source[n]?.[`${o}.${c}`]:r.source[`${n}.${c}`];const A=o?`${n}.${o}`:n;typeof f=="function"?ee(r.current,A,f({$form:i,translate:u.translate})):(Et(f)&&(f=u.translate(f.key,xr(f.params,i),f.default)),(n==="disabled"||n==="readonly")&&b(f)&&(f=s[r.current.uid][n]),ee(r.current,A,f)),n==="props"&&o&&t[r.source.uid]&&t[r.source.uid][o]!==void 0&&ee(r.current,A,t[r.source.uid][o]),V(r.previous,A)!==V(r.current,A)&&(r.changed=!0)}const xr=(e,t)=>e&&Object.keys(e).reduce((r,n)=>{const o=String(e[n]);if(qr(o)){const i=o.replace("$form.","");r[n]=V(t,i)||o}else r[n]=o;return r},{});function It(e){return e.flatMap(t=>[t,...ve(t)?It(t.children):[]])}const en=({lang:e},t)=>{const r={...Fe(e),formName:t.payload.formName};let n=t.payload.formDef,o={status:"ok"};if(typeof n=="string"){try{n=JSON.parse(n)}catch(s){o={status:"errored",message:s.message}}if(o.status==="errored")return{...r,formHealth:o}}if(Array.isArray(n.form)){const s=n,u=s.form;s.form={uid:"",type:"flex",kind:"layout",children:u}}const i=we.decode(n);if(i.isOk()){o={status:"ok"};let s={};try{s=It([i.value.form]).reduce((u,c)=>{if(u[c.uid])throw{existingWidget:u[c.uid],newWidget:c};return u[c.uid]=c,u},{})}catch(u){o={status:"errored",message:tn(u.existingWidget,u.newWidget)},s={}}return{...r,formDef:i.value,flatForm:s,formHealth:o}}return{...r,formHealth:{status:"errored",message:i.error}}};function tn(e,t){const r=n=>W(n)?` at "${n.path}"`:"";return`Duplicate UID "${t.uid}": Assigned to widget "${e.type}"${r(e)} and "${t.type}"${r(t)}.`}function rn(e,t){return{...e,injectedValidations:{...e.injectedValidations,[t.payload.path]:t.payload.issues}}}const nn=(e,{payload:t})=>{const r=Object.values(e.calculatedWidgets).find(({source:o})=>W(o)&&o.path===t.path);if(!r)return console.warn(`Control "${t.path}" not found`),e;const n=e.widgetPropOverrides[r.source.uid]||{};return{...e,widgetPropOverrides:{[r.source.uid]:{...n,[t.prop]:t.value}}}};function on(e,t){return{...e,widgetFlags:{...te(e.widgetFlags,t.payload.uid)},calculatedWidgets:{...te(e.calculatedWidgets,t.payload.uid)},widgetPropOverrides:{...te(e.widgetPropOverrides,t.payload.uid)},touchedControls:{...k(e.touchedControls,r=>{const n=e.flatForm[t.payload.uid];return n&&W(n)?te(r,n.path):r})}}}const sn=(e,t)=>({...e,data:{...t.payload.data}}),dn=(e,t)=>{const r=V(e.data,t.payload.path);return t.type==="SET_WIDGET_DATA"||t.type==="SET_WIDGET_INITIAL_DATA"&&r===void 0?{...e,data:{...ee(e.data,t.payload.path,t.payload.data)}}:e},un=(e,t)=>({...e,formHealth:t.payload.formHealth}),cn=(e,t)=>({...e,lang:t.payload.lang});function Ot(e,t){const r=e["~standard"].validate(t);if(r instanceof Promise)throw new TypeError("Schema validation must be synchronous");return r}function Dt(e){return e.issues===void 0}const wt=Symbol("filterMap.skip");function ln(e,t){const r=[];for(let n=0;n<e.length;n++){const o=t(e[n],n,e);o!==wt&&r.push(o)}return r}function an(e,t,r){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!r(e[n],t[n],n,e,t))return!1;return!0}const Qe=e=>t=>{const r=ln(Object.values(t.calculatedWidgets),({current:o})=>W(o)?o:wt),n=t.validations;return{...t,validations:r.reduce((o,i)=>{if(o[i.path]=null,i.validator){const s=e(i.validator),u=V(t.data,i.path),c=Ot(s,u);o[i.path]=Dt(c)?null:c.issues.map(f=>f.message)}return Array.isArray(o[i.path])&&Array.isArray(n[i.path])&&an(o[i.path],n[i.path],(s,u)=>s===u)&&(o[i.path]=n[i.path]),o},{})}},fn=({validators:e,validateOn:t,localization:r})=>(n,o)=>{switch(o.type){case"INITIALIZE":return en(n,o);case"SET_DATA":return k(sn(n,o),z,x,K(r));case"SET_LANGUAGE":return k(cn(n,o),K(r));case"ADD_WIDGET":return k(rr(n,o),Se(Ze,z),Se(Ze,x),Se(Ze,K(r)));case"REMOVE_WIDGET":return k(on(n,o),z,x,K(r));case"SET_WIDGET_INITIAL_DATA":case"SET_WIDGET_DATA":return k(dn(n,o),z,x,K(r));case"OVERRIDE_WIDGET_PROP":return k(nn(n,o),z,x,K(r),Se(Xr(o.payload.path),Qe(e)));case"SET_FORM_HEALTH":return un(n,o);case"VALIDATE_ALL":return k({...n,touched:!0,touchedControls:Object.keys(n.calculatedWidgets).reduce((i,s)=>{const u=n.calculatedWidgets[s].source;return W(u)&&(i[u.path]=!0),i},{})},Qe(e));case"ATTEMPT_VALIDATION":{const i=o.payload.reason,s=o.payload.path;return t==="eager"||i===t||t.includes(i)?k({...n,touched:!0,touchedControls:{...n.touchedControls,[s]:!0}},Qe(e),c=>{const f=o.payload.uid,A=c.calculatedWidgets[f],p=A.source;if(se(p)){const C=p({$form:c.data,errors:c.validations[s],touched:!0,translate:r.translate});return{...c,calculatedWidgets:{...c.calculatedWidgets,[f]:{...A,previous:A.current,current:C}}}}return c}):n}case"INJECT_VALIDATION_ISSUES":return rn(n,o);default:return er(o)}},Ze=e=>e.formHealth.status==="ok";function Ft(e=[],t,r,n){const o=new a.BehaviorSubject(Fe(n.lang)),i=o.asObservable().pipe(a.distinctUntilChanged()),s=fn({validators:t,validateOn:r,localization:n});function u(p){const C=o.getValue(),B=s(C,p);o.next(B)}let c=u;const f={getState:()=>o.getValue(),dispatch:p=>c(p)};return c=e.map(p=>p(f)).reduceRight((p,C)=>C(p),u),{state$:i,dispatch:c,getState:()=>o.getValue()}}const hn=a.pipe(a.map(e=>e.data),a.distinctUntilChanged()),pn=e=>a.pipe(hn,a.map(t=>V(t,e)),a.distinctUntilChanged()),gn=a.pipe(a.filter(e=>e.touched===!0),a.map(e=>e.validations),a.distinctUntilChanged()),yn=e=>a.pipe(gn,a.map(t=>t[e]),a.distinctUntilChanged()),mn=a.pipe(a.filter(e=>e.touched===!0),a.map(e=>e.injectedValidations),a.distinctUntilChanged()),An=e=>a.pipe(mn,a.map(t=>t[e]),a.distinctUntilChanged(),a.startWith(null)),Wt=a.pipe(a.map(e=>e.calculatedWidgets),a.distinctUntilChanged()),Sn=e=>a.pipe(Wt,a.map(t=>t[e]),a.filter(t=>t!==void 0),a.map(t=>t.current),a.distinctUntilChanged()),$n=e=>a.pipe(Wt,a.map(t=>t[e]),a.filter(t=>t!==void 0),a.map(t=>t.current.children),a.distinctUntilChanged()),Tt=a.pipe(a.map(e=>e.widgetFlags),a.distinctUntilChanged()),Cn=e=>a.pipe(Tt,a.map(t=>t[e]),a.distinctUntilChanged()),En=a.pipe(a.map(e=>e.touchedControls),a.distinctUntilChanged()),vn=e=>a.pipe(En,a.map(t=>t[e]),a.distinctUntilChanged()),In=a.pipe(a.map(e=>e.formHealth),a.distinctUntilChanged((e,t)=>!(e.status!==t.status||e.status==="errored"))),On=e=>e.pipe(In);class kt{constructor(){this.registry={},this.widgetLoaders={},this._ready=!1}get ready(){return this._ready}setWidgetLoaders(t){this.widgetLoaders=t,this._ready=!0}async loadWidget(t){return this.registry[t]??(this.registry[t]=await this.widgetLoaders[t]())}}class Dn{constructor(){this.widgetRegistry=new kt,this.store={},this.events$=new a.Subject,this.uuid=crypto.randomUUID(),this.itemRenderers={}}initialize(t,r=[],n,o,i,s=vt()){this.localization=s,this.widgetRegistry.setWidgetLoaders(t),this.itemRenderers=i,this.store=Ft(r,n,o,s)}emitEvent(t,r,n){const i=this.store.getState().currentStates.filter(s=>r.on?.[`${t}.${s}`]!==void 0);if(i.length>0)i.forEach(s=>{const u=r.on?.[`${t}.${s}`];this.attemptValidation(t,u,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,s,r),s&&this.events$.next({name:s,data:this.store.getState().data,detail:n,callback:u=>{this.store.dispatch(u)}})}}attemptValidation(t,r,n){n.kind!=="layout"&&(t==="change"?this.store.dispatch({type:"ATTEMPT_VALIDATION",payload:{reason:"change",path:n.path,uid:n.uid}}):t==="click"&&r==="submit"&&this.store.dispatch({type:"VALIDATE_ALL"}))}}function Pt(e){return e.$schema!==void 0&&e.$schema.startsWith("https://json-schema.org/draft")}const wn=e=>t=>r=>n=>{if(n.type==="INITIALIZE"){let o=n.payload.formDef==="string"?JSON.parse(n.payload.formDef):n.payload.formDef;Pt(o)&&(o=re(o,e,()=>{throw new Error("Ref resolving not implemented")}),o={form:o}),r({...n,payload:{...n.payload,formDef:o}})}else r(n)};function re(e,t,r,n=[]){if(e.$ref){const i=r(e.$ref);return re(i,t,r,n)}if(e.oneOf)return{...t.oneOf(e),props:{},children:e.oneOf.map(s=>re(s,t,r,n))};if(e.anyOf)return{...t.anyOf(e),props:{},children:e.anyOf.map(s=>re(s,t,r,n))};if(e.type==="object"){const i=[];if(e.properties)for(const[s,u]of Object.entries(e.properties)){const c=[...n,s],f=re(u,t,r,c);i.push(f)}return t.object(e,i)}if(e.type==="array")throw new Error(`Arrays not supported yet at path: ${n.join(".")}`);if(e.enum)return t.enum(e,n.join("."));const o=t[e.type];return o?o(e,n.join(".")):t.fallback(e)}const Fn={log:(e,t)=>(t?console.log(t,e):console.log(e),e)};function Wn(e,t){const r=Tn(e.uid,t);return W(e)?{...e,uid:r,path:kn(e.path,t)}:{...e,uid:r}}function Tn(e,t){if(t===-1)throw new Error("-1 is an invalid Repeater index");return`${e}[${t}]`}function kn(e,t){if(t===-1)throw new Error("-1 is an invalid Repeater index");return e.replace(".items.",`.${t}.`)}g.Debug=Fn,g.FormContext=Dn,g.WidgetRegistry=kt,g.calculatedLayoutChildrenByUid$=$n,g.calculatedWidgetsByUid$=Sn,g.cloneObject=jr,g.compose=tr,g.createFormStore=Ft,g.createInitialState=Fe,g.dataByPath$=pn,g.defineForm=xt,g.deleteKey=te,g.formDefDecoder=we,g.formHealth=On,g.get=V,g.getDirectionFromLanguage=Zr,g.identityTranslator=vt,g.injectedValidationByPath$=An,g.isActionWidget=ie,g.isDisplayWidget=Jt,g.isFunctionWidget=se,g.isInputWidget=W,g.isJsonSchema=Pt,g.isLayoutWidget=ve,g.isStandardValidateSuccess=Dt,g.isTranslationConfig=Et,g.jsonSchemaMiddleware=wn,g.layoutWidgetDecoder=le,g.makeRepeaterItemConfig=Wn,g.pipe=k,g.selectWidgetFlags=Tt,g.set=ee,g.shortUUID=Ee,g.standardValidate=Ot,g.touchedControlsByPath$=vn,g.validationByPath$=yn,g.widgetFlagsByUid$=Cn,Object.defineProperty(g,Symbol.toStringTag,{value:"Module"})}));
@@ -0,0 +1,21 @@
1
+ import { Subject } from 'rxjs';
2
+ import { ActionWidget, InputWidget, LayoutWidget, On } from '../form-widget';
3
+ import { FormStore } from '../form-store';
4
+ import { ValidatorFn } from '../form-validator';
5
+ import { I18nTranslator } from '../i18n';
6
+ import { ItemRenderer } from '../item-renderer';
7
+ import { EventName, FormEvent, ValidateOn } from '../shared';
8
+ import { Action } from '../store/actions';
9
+ import { Middleware, State } from '../store/model';
10
+ import { WidgetLoaders, WidgetRegistry } from './widget-registry';
11
+ export declare class FormContext<ComponentType> {
12
+ widgetRegistry: WidgetRegistry<ComponentType>;
13
+ store: FormStore;
14
+ events$: Subject<FormEvent>;
15
+ uuid: `${string}-${string}-${string}-${string}-${string}`;
16
+ itemRenderers: Record<string, ItemRenderer>;
17
+ localization: I18nTranslator;
18
+ initialize(widgetLoaders: WidgetLoaders<ComponentType>, middlewares: Middleware<State, Action>[] | undefined, validators: ValidatorFn<any>, validateOn: ValidateOn, itemRenderers: Record<string, ItemRenderer>, localization?: I18nTranslator): void;
19
+ emitEvent(eventType: keyof On<string>, widget: InputWidget<any, string> | ActionWidget<string> | LayoutWidget<string>, detail?: any): void;
20
+ attemptValidation(eventType: keyof On<string>, eventName: EventName | undefined, widget: InputWidget<any, string> | ActionWidget<string> | LayoutWidget<string>): void;
21
+ }
@@ -0,0 +1,3 @@
1
+ export * from './widget-registry';
2
+ export * from './form.context';
3
+ export * from './with-widget.type';
@@ -0,0 +1,13 @@
1
+ import { NonFunctionWidget } from '../form-widget';
2
+ export type WidgetLoaders<ComponentType, Widget extends string = NonFunctionWidget['type']> = Record<Widget, () => Promise<ComponentType>>;
3
+ export declare class WidgetRegistry<ComponentType> {
4
+ private registry;
5
+ private widgetLoaders;
6
+ private _ready;
7
+ /**
8
+ * When the registry has been initialized by calling `setWidgetLoaders`
9
+ */
10
+ get ready(): boolean;
11
+ setWidgetLoaders(widgetLoaders: WidgetLoaders<ComponentType>): void;
12
+ loadWidget(widget: NonFunctionWidget['type']): Promise<ComponentType>;
13
+ }
@@ -0,0 +1,4 @@
1
+ import { FormWidget } from '../form-widget';
2
+ export interface WithWidget {
3
+ widget: FormWidget<string>;
4
+ }
@@ -0,0 +1,12 @@
1
+ import { Observable } from 'rxjs';
2
+ import { ValidatorFn } from './form-validator';
3
+ import { I18nTranslator } from './i18n';
4
+ import { ValidateOn } from './shared';
5
+ import { Action } from './store/actions';
6
+ import { Middleware, State } from './store/model';
7
+ export declare function createFormStore(middlewares: Middleware<State, Action>[] | undefined, validators: ValidatorFn<any>, validateOn: ValidateOn, localization: I18nTranslator): FormStore;
8
+ export type FormStore = {
9
+ state$: Observable<State>;
10
+ dispatch: (action: Action) => void;
11
+ getState: () => State;
12
+ };
@@ -0,0 +1,10 @@
1
+ import { StandardSchemaV1 } from '@standard-schema/spec';
2
+ export type JsonSchemaValidators<V> = {
3
+ stringValidator: () => V;
4
+ booleanValidator: () => V;
5
+ numberValidator: () => V;
6
+ integerValidator: () => V;
7
+ };
8
+ export type ValidatorFn<V> = (validator: V) => StandardSchemaV1;
9
+ export declare function standardValidate<T extends StandardSchemaV1>(schema: T, input: StandardSchemaV1.InferInput<T>): StandardSchemaV1.InferOutput<T>;
10
+ export declare function isStandardValidateSuccess<O>(result: StandardSchemaV1.Result<O>): result is StandardSchemaV1.SuccessResult<O>;
@@ -0,0 +1,93 @@
1
+ import { Localizable } from './i18n';
2
+ import { DotPath, FunctionWidgetParams, ReactiveExpression, Uid, UiState, WidgetPropertyFunction } from './shared';
3
+ import { AllSuffixable, SomeSuffixable } from './utils/suffixable';
4
+ import * as jd from 'ts.data.json';
5
+ /**
6
+ * The widget type identifier used to resolve the corresponding UI component from the registry.
7
+ * Examples: 'textinput', 'textarea', 'password', 'flex', 'grid', 'heading', 'markdown', 'alert'
8
+ */
9
+ export type WidgetType = string;
10
+ type ReactiveWidgetPropertyValue<T, FormType extends Record<string, any> = any> = ReactiveExpression | WidgetPropertyFunction<T, FormType> | T;
11
+ /**
12
+ * An event expression is basically a way to send an event `loadData` for the forms engine runtime to process.
13
+ */
14
+ type EventExpression = string;
15
+ export type On<StateKeys extends UiState = never, FormType extends Record<string, any> = any> = AllSuffixable<{
16
+ load?: ReactiveWidgetPropertyValue<EventExpression, FormType>;
17
+ click?: ReactiveWidgetPropertyValue<EventExpression, FormType>;
18
+ change?: ReactiveWidgetPropertyValue<EventExpression, FormType>;
19
+ filter?: ReactiveWidgetPropertyValue<EventExpression, FormType>;
20
+ }, StateKeys>;
21
+ export type BaseWidget<StateKeys extends UiState = never, FormType extends Record<string, any> = any, Props extends Record<string, any> = any> = {
22
+ uid: Uid;
23
+ type: WidgetType;
24
+ size?: number;
25
+ include?: {
26
+ in: StateKeys[];
27
+ } | {
28
+ when: ReactiveExpression;
29
+ };
30
+ exclude?: {
31
+ from: StateKeys[];
32
+ } | {
33
+ when: ReactiveExpression;
34
+ };
35
+ /**
36
+ * Non-core properties e.g. text, level...
37
+ * props can be suffixed with state keys. e.g. { props: {text: 'Login', 'text.register': 'Register'} }
38
+ */
39
+ props?: AllSuffixable<MakeProps<Props, FormType>, StateKeys>;
40
+ };
41
+ type MakeProps<Props extends Record<string, any> = any, FormType extends Record<string, any> = any> = {
42
+ [K in keyof Props]: Props[K] extends string | (string | undefined) ? Props[K] | WidgetPropertyFunction<Props[K], FormType> | Exclude<Localizable, string> | (string & {}) : Props[K] | WidgetPropertyFunction<Props[K], FormType>;
43
+ };
44
+ export type DisplayWidget<StateKeys extends UiState = never, FormType extends Record<string, any> = any, Props extends Record<string, any> = any> = SomeSuffixable<BaseWidget<StateKeys, FormType, Props> & {
45
+ kind: 'display';
46
+ }, never, StateKeys>;
47
+ export type ActionWidget<StateKeys extends UiState = never, FormType extends Record<string, any> = any, Props extends Record<string, any> = any> = SomeSuffixable<BaseWidget<StateKeys, FormType, Props> & {
48
+ kind: 'action';
49
+ label?: ReactiveWidgetPropertyValue<Localizable, FormType>;
50
+ disabled?: boolean | {
51
+ when: ReactiveExpression;
52
+ };
53
+ on?: On<StateKeys, FormType>;
54
+ }, 'disabled' | 'label' | 'size', StateKeys>;
55
+ export type InputWidget<T, StateKeys extends UiState = never, FormType extends Record<string, any> = any, Props extends Record<string, any> = any, V = any> = SomeSuffixable<BaseWidget<StateKeys, FormType, Props> & {
56
+ kind: 'input';
57
+ path: DotPath;
58
+ label?: ReactiveWidgetPropertyValue<Localizable, FormType>;
59
+ disabled?: boolean | {
60
+ when: ReactiveExpression;
61
+ };
62
+ readonly?: boolean | {
63
+ when: ReactiveExpression;
64
+ };
65
+ on?: On<StateKeys, FormType>;
66
+ defaultValue?: T;
67
+ validator?: ReactiveWidgetPropertyValue<V, FormType>;
68
+ }, 'disabled' | 'readonly' | 'label' | 'validator' | 'size', StateKeys>;
69
+ type LayoutChildren<StateKeys extends UiState = never, FormType extends Record<string, any> = any> = (DisplayWidget<StateKeys, FormType> | InputWidget<any, StateKeys, FormType> | LayoutWidget<StateKeys, FormType> | ActionWidget<StateKeys, FormType> | FunctionWidget<StateKeys, FormType>)[];
70
+ export type LayoutWidget<StateKeys extends UiState = never, FormType extends Record<string, any> = any, Props extends Record<string, any> = any, Children extends FormWidget<StateKeys, FormType>[] = LayoutChildren<StateKeys, FormType>> = SomeSuffixable<BaseWidget<StateKeys, FormType, Props> & {
71
+ kind: 'layout';
72
+ on?: On<StateKeys, FormType>;
73
+ children: Children;
74
+ }, 'size', StateKeys>;
75
+ export type NonFunctionWidget<StateKeys extends UiState = never, FormType extends Record<string, any> = any, Validator = any> = DisplayWidget<StateKeys, FormType> | InputWidget<any, StateKeys, FormType, any, Validator> | LayoutWidget<StateKeys, FormType> | ActionWidget<StateKeys, FormType>;
76
+ export type FunctionWidget<StateKeys extends UiState = never, FormType extends Record<string, any> = any, Validator = any> = {
77
+ uid?: Uid;
78
+ type?: string;
79
+ path?: string;
80
+ /**
81
+ * Function that calculates the widget definition.
82
+ * Function Widgets are called at least once with `undefined`.
83
+ */
84
+ (api?: FunctionWidgetParams<FormType>): NonFunctionWidget<StateKeys, FormType, Validator>;
85
+ };
86
+ export type FormWidget<StateKeys extends UiState = never, FormType extends Record<string, any> = any, Validator = any> = NonFunctionWidget<StateKeys, FormType, Validator> | FunctionWidget<StateKeys, FormType, Validator>;
87
+ export declare const isDisplayWidget: <StateKeys extends string, FormType extends Record<string, any> = any>(widget: FormWidget<StateKeys, FormType>) => widget is DisplayWidget<StateKeys, FormType>;
88
+ export declare const isActionWidget: <StateKeys extends string, FormType extends Record<string, any> = any>(widget: FormWidget<StateKeys, FormType>) => widget is ActionWidget<StateKeys, FormType>;
89
+ export declare const isInputWidget: <T, StateKeys extends string, FormType extends Record<string, any> = any>(widget: FormWidget<StateKeys, FormType>) => widget is InputWidget<T, StateKeys, FormType>;
90
+ export declare const isLayoutWidget: <StateKeys extends string, FormType extends Record<string, any> = any>(widget: FormWidget<StateKeys, FormType>) => widget is LayoutWidget<StateKeys, FormType>;
91
+ export declare const isFunctionWidget: <StateKeys extends string, FormType extends Record<string, any> = any>(widget: FormWidget<StateKeys, FormType>) => widget is FunctionWidget<StateKeys, FormType>;
92
+ export declare const layoutWidgetDecoder: jd.Decoder<LayoutWidget<string, any, any, LayoutChildren<string, any>>>;
93
+ export {};
package/lib/form.d.ts ADDED
@@ -0,0 +1,22 @@
1
+ import { FormWidget, LayoutWidget } from './form-widget';
2
+ import { ReactiveExpression, UiState } from './shared';
3
+ import * as jd from 'ts.data.json';
4
+ export type Form<StateKeys extends UiState = never, FormType extends Record<string, any> = any> = {
5
+ states?: Record<StateKeys, ReactiveExpression>;
6
+ form: LayoutWidget<StateKeys, FormType>;
7
+ };
8
+ /**
9
+ * Creates a type-safe form definition using TypeScript.
10
+ *
11
+ * Use this helper to enforce strong typing in form structures.
12
+ */
13
+ export declare function defineForm<FormType extends Record<string, any> = any, States extends Record<string, ReactiveExpression> = Record<string, ReactiveExpression>>(config: {
14
+ states?: States;
15
+ form: FormWidget<Extract<keyof States, string>, FormType>[];
16
+ }): Form<Extract<keyof States, string>, FormType>;
17
+ export declare const formDefDecoder: jd.Decoder<{
18
+ states: {
19
+ [K: string]: string;
20
+ } | undefined;
21
+ form: LayoutWidget<string, any, any, (import('./form-widget').DisplayWidget<string, any, any> | import('./form-widget').InputWidget<any, string, any, any, any> | LayoutWidget<string, any, any, (import('./form-widget').DisplayWidget<string, any, any> | import('./form-widget').InputWidget<any, string, any, any, any> | LayoutWidget<string, any, any, (import('./form-widget').DisplayWidget<string, any, any> | import('./form-widget').InputWidget<any, string, any, any, any> | LayoutWidget<string, any, any, (import('./form-widget').DisplayWidget<string, any, any> | import('./form-widget').InputWidget<any, string, any, any, any> | LayoutWidget<string, any, any, (import('./form-widget').DisplayWidget<string, any, any> | import('./form-widget').InputWidget<any, string, any, any, any> | LayoutWidget<string, any, any, (import('./form-widget').DisplayWidget<string, any, any> | import('./form-widget').InputWidget<any, string, any, any, any> | LayoutWidget<string, any, any, (import('./form-widget').DisplayWidget<string, any, any> | import('./form-widget').InputWidget<any, string, any, any, any> | LayoutWidget<string, any, any, (import('./form-widget').DisplayWidget<string, any, any> | import('./form-widget').InputWidget<any, string, any, any, any> | LayoutWidget<string, any, any, (import('./form-widget').DisplayWidget<string, any, any> | import('./form-widget').InputWidget<any, string, any, any, any> | LayoutWidget<string, any, any, (import('./form-widget').DisplayWidget<string, any, any> | import('./form-widget').InputWidget<any, string, any, any, any> | LayoutWidget<string, any, any, (import('./form-widget').DisplayWidget<string, any, any> | import('./form-widget').InputWidget<any, string, any, any, any> | LayoutWidget<string, any, any, /*elided*/ any> | import('./form-widget').ActionWidget<string, any, any> | import('./form-widget').FunctionWidget<string, any, any>)[]> | import('./form-widget').ActionWidget<string, any, any> | import('./form-widget').FunctionWidget<string, any, any>)[]> | import('./form-widget').ActionWidget<string, any, any> | import('./form-widget').FunctionWidget<string, any, any>)[]> | import('./form-widget').ActionWidget<string, any, any> | import('./form-widget').FunctionWidget<string, any, any>)[]> | import('./form-widget').ActionWidget<string, any, any> | import('./form-widget').FunctionWidget<string, any, any>)[]> | import('./form-widget').ActionWidget<string, any, any> | import('./form-widget').FunctionWidget<string, any, any>)[]> | import('./form-widget').ActionWidget<string, any, any> | import('./form-widget').FunctionWidget<string, any, any>)[]> | import('./form-widget').ActionWidget<string, any, any> | import('./form-widget').FunctionWidget<string, any, any>)[]> | import('./form-widget').ActionWidget<string, any, any> | import('./form-widget').FunctionWidget<string, any, any>)[]> | import('./form-widget').ActionWidget<string, any, any> | import('./form-widget').FunctionWidget<string, any, any>)[]> | import('./form-widget').ActionWidget<string, any, any> | import('./form-widget').FunctionWidget<string, any, any>)[]>;
22
+ }>;
package/lib/i18n.d.ts ADDED
@@ -0,0 +1,87 @@
1
+ import { DotPath } from './shared';
2
+ export type I18nParams = Record<string, string | number | DotPath>;
3
+ export type TranslationKey = string;
4
+ /**
5
+ * Contract for a core internationalization adapter.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * export const i18nTranslator: Core.I18nTranslator = {
10
+ * get lang() {
11
+ * return i18next.language;
12
+ * },
13
+ * translate(key: Core.TranslationKey, params?: Core.I18nParams, defaultValue?: string): string {
14
+ * return i18next.t(key, { ...params, defaultValue });
15
+ * },
16
+ * subscribe(listener: (lang: string) => void) {
17
+ * const onLanguageChanged = (lng: string) => listener(lng);
18
+ * i18next.on('languageChanged', onLanguageChanged);
19
+ * return () => {
20
+ * i18next.off('languageChanged', onLanguageChanged);
21
+ * };
22
+ * },
23
+ * };
24
+ * ```
25
+ */
26
+ export interface I18nTranslator {
27
+ /**
28
+ * The BCP 47 language tag of the current locale (e.g., 'en-US', 'es', 'fr-CA').
29
+ * Accessing this property should return the currently active language.
30
+ */
31
+ get lang(): string;
32
+ /**
33
+ * Resolves a localized string based on the provided key and parameters.
34
+ *
35
+ * @param key - The unique translation key (e.g., "errors.required").
36
+ * @param params - Optional values for interpolation (e.g., `{ name: "Alice" }`).
37
+ * @param defaultValue - A fallback string returned if the key cannot be resolved.
38
+ * @returns The translated string or the default value.
39
+ */
40
+ translate(key: TranslationKey, params?: I18nParams, defaultValue?: string): string;
41
+ /**
42
+ * Subscribes to language change events.
43
+ *
44
+ * @param listener - A callback function invoked with the new language code when the locale changes.
45
+ * @returns A teardown function that removes the listener and cleans up resources.
46
+ */
47
+ subscribe(listener: (lang: string) => void): () => void;
48
+ }
49
+ export type TranslationConfig = {
50
+ /** Translation key used for lookup */
51
+ key: TranslationKey;
52
+ /** Parameters used for interpolation */
53
+ params?: I18nParams;
54
+ /** Fallback text used when the key cannot be resolved */
55
+ default?: string;
56
+ };
57
+ /**
58
+ * Represents a widget property that can be localized.
59
+ *
60
+ * - If a plain string is provided, it is returned as-is.
61
+ * - If a structured descriptor is provided, it is resolved via the translation system.
62
+ */
63
+ export type Localizable = string | {
64
+ /** Translation key used for lookup */
65
+ key: TranslationKey;
66
+ /** Parameters used for interpolation */
67
+ params?: I18nParams;
68
+ /** Fallback text used when the key cannot be resolved */
69
+ default?: string;
70
+ };
71
+ export declare const isTranslationConfig: (value: unknown) => value is TranslationConfig;
72
+ /**
73
+ * Determines the text direction (left-to-right or right-to-left) based on the given language code.
74
+ *
75
+ * @param {string} lang - The BCP 47 language tag of the current locale (e.g., 'en-US', 'es', 'fr-CA').
76
+ * @return {'ltr' | 'rtl'} Returns 'ltr' for left-to-right or 'rtl' for right-to-left text direction.
77
+ */
78
+ export declare function getDirectionFromLanguage(lang: string): 'ltr' | 'rtl';
79
+ /**
80
+ * Default no-op translator.
81
+ *
82
+ * This implementation performs no localization and simply returns the
83
+ * translation key unchanged. It is intended for use as a safe default
84
+ * when no i18n system is configured.
85
+ * @param lang The BCP 47 language tag of the current localeby default `(navigator.language || 'en-US')`.
86
+ */
87
+ export declare const identityTranslator: (lang?: string) => I18nTranslator;
@@ -0,0 +1,24 @@
1
+ export type ItemRenderItemData = string | Record<string, unknown>;
2
+ /**
3
+ * The ItemRenderer Data Contract
4
+ */
5
+ export interface ItemRenderContext<T extends ItemRenderItemData> {
6
+ template: T;
7
+ /**
8
+ * @see OptionValue
9
+ */
10
+ value: string | number;
11
+ index: number;
12
+ selected?: boolean;
13
+ disabled?: boolean;
14
+ focused?: boolean;
15
+ }
16
+ export type ItemRendererFn<T extends ItemRenderItemData = ItemRenderItemData, R = unknown> = (context: ItemRenderContext<T>) => R;
17
+ export type ItemRendererClass<R = unknown> = R;
18
+ /**
19
+ * The Universal item renderer type.
20
+ * @template T The type of the data item.
21
+ * @template R The framework-specific return type.
22
+ * R can be React's React.FC, Lit's TemplateResult or Angular's Type<?>)
23
+ */
24
+ export type ItemRenderer<T extends ItemRenderItemData = ItemRenderItemData, R = unknown> = ItemRendererFn<T, R> | ItemRendererClass<R>;
@@ -0,0 +1,2 @@
1
+ export * from './json-schema/json-schema';
2
+ export * from './json-schema/json-schema.middleware';
@@ -0,0 +1,67 @@
1
+ export type RefResolver = (ref: string) => JSONSchemaObject;
2
+ export declare function isJsonSchema(json: Record<string, any>): json is JSONSchemaObject;
3
+ /**
4
+ * JSON Schema Draft 2020-12
5
+ * @see
6
+ * https://json-schema.org/draft/2020-12
7
+ */
8
+ export interface JSONSchemaObject {
9
+ $schema?: string;
10
+ $id?: string;
11
+ $ref?: string;
12
+ $defs?: Record<string, JSONSchemaObject>;
13
+ $comment?: string;
14
+ $vocabulary?: Record<string, boolean>;
15
+ $dynamicRef?: string;
16
+ $dynamicAnchor?: string;
17
+ $anchor?: string;
18
+ title?: string;
19
+ description?: string;
20
+ default?: unknown;
21
+ deprecated?: boolean;
22
+ readOnly?: boolean;
23
+ writeOnly?: boolean;
24
+ examples?: unknown[];
25
+ type?: JSONSchemaType | JSONSchemaType[];
26
+ enum?: unknown[];
27
+ const?: unknown;
28
+ multipleOf?: number;
29
+ maximum?: number;
30
+ exclusiveMaximum?: number;
31
+ minimum?: number;
32
+ exclusiveMinimum?: number;
33
+ maxLength?: number;
34
+ minLength?: number;
35
+ pattern?: string;
36
+ prefixItems?: JSONSchemaObject[];
37
+ items?: JSONSchemaObject;
38
+ contains?: JSONSchemaObject;
39
+ maxContains?: number;
40
+ minContains?: number;
41
+ maxItems?: number;
42
+ minItems?: number;
43
+ uniqueItems?: boolean;
44
+ properties?: Record<string, JSONSchemaObject>;
45
+ patternProperties?: Record<string, JSONSchemaObject>;
46
+ additionalProperties?: JSONSchemaObject;
47
+ propertyNames?: JSONSchemaObject;
48
+ maxProperties?: number;
49
+ minProperties?: number;
50
+ required?: string[];
51
+ dependentRequired?: Record<string, string[]>;
52
+ allOf?: JSONSchemaObject[];
53
+ anyOf?: JSONSchemaObject[];
54
+ oneOf?: JSONSchemaObject[];
55
+ not?: JSONSchemaObject;
56
+ if?: JSONSchemaObject;
57
+ then?: JSONSchemaObject;
58
+ else?: JSONSchemaObject;
59
+ dependentSchemas?: Record<string, JSONSchemaObject>;
60
+ unevaluatedItems?: JSONSchemaObject;
61
+ unevaluatedProperties?: JSONSchemaObject;
62
+ format?: string;
63
+ contentEncoding?: string;
64
+ contentMediaType?: string;
65
+ contentSchema?: JSONSchemaObject;
66
+ }
67
+ export type JSONSchemaType = 'null' | 'boolean' | 'object' | 'array' | 'number' | 'integer' | 'string';
@@ -0,0 +1,19 @@
1
+ import { FormWidget } from '../../form-widget';
2
+ import { Action } from '../../store/actions';
3
+ import { Middleware, State } from '../../store/model';
4
+ import { JSONSchemaObject } from './json-schema';
5
+ type JsonSchemaTypeMap = 'string' | 'enum' | 'boolean' | 'number' | 'integer' | 'object' | 'oneOf' | 'anyOf' | 'fallback';
6
+ /**
7
+ * Maps a Json Schema type to a widget name, so
8
+ */
9
+ export type SchemaToWidgetMap = Record<JsonSchemaTypeMap, (schema: JSONSchemaObject, ...rest: any[]) => FormWidget>;
10
+ /**
11
+ * Use this middleware to convert a JSON schema into a JSON form.
12
+ *
13
+ * @example
14
+ * protected middlewares = jsonSchemaMiddleware(vanillaSchemaToWidgetMap);
15
+ * @example
16
+ * <gui-form [middlewares]="middlewares" />
17
+ */
18
+ export declare const jsonSchemaMiddleware: (schemaToWidgetMap: SchemaToWidgetMap) => Middleware<State, Action>;
19
+ export {};
@@ -0,0 +1,143 @@
1
+ import { NonFunctionWidget } from './form-widget';
2
+ import { I18nTranslator } from './i18n';
3
+ import { OVERRIDE_WIDGET_PROP } from './store/actions';
4
+ import { ImmutableRecord } from './utils/types';
5
+ /**
6
+ * The UI state name.
7
+ * To be used with includeIn, excludeFrom and composite property names `{ "label.success": "Message sent successfully", "label.error": "An error occurred" }`
8
+ */
9
+ export type UiState = string;
10
+ /**
11
+ * A ReactiveExpression is an expression that is evaluated and then substituted by the produced value.
12
+ */
13
+ export type ReactiveExpression = string;
14
+ /**
15
+ * The path to a json object
16
+ */
17
+ export type DotPath = string;
18
+ /**
19
+ * The components uid identifier
20
+ */
21
+ export type Uid = string;
22
+ /**
23
+ * Represents a generic validation status.
24
+ * Either `null` (there are no validation issues) or an array of issues.
25
+ */
26
+ export type ValidationStatus = null | string[];
27
+ export type WidgetPropertyFunctionParams<FormType extends Record<string, any>> = {
28
+ $form: ImmutableRecord<FormType>;
29
+ translate?: I18nTranslator['translate'];
30
+ };
31
+ /**
32
+ * A WidgetPropertyFunction is a widget function that is evaluated and then substituted by the produced value.
33
+ */
34
+ export type WidgetPropertyFunction<T, FormType extends Record<string, any> = any> = (api: WidgetPropertyFunctionParams<FormType>) => T;
35
+ export type FunctionWidgetParams<FormType> = {
36
+ $form: ImmutableRecord<FormType>;
37
+ errors: ValidationStatus | undefined;
38
+ touched: boolean | undefined;
39
+ translate: I18nTranslator['translate'] | undefined;
40
+ };
41
+ /**
42
+ * Defines when widget validation should run.
43
+ * - `'eager'` validates on `'change'`, `'blur'` and `'submit'`.
44
+ * - When using 'submit', validation triggers when the 'submit' event is emitted. When that happens, all widgets are also _touched_ first.
45
+ * ```ts
46
+ * {
47
+ * widget: 'button',
48
+ * label: 'Create User',
49
+ * on: {
50
+ * click: 'submit',
51
+ * }
52
+ * }
53
+ * ```
54
+ */
55
+ export type ValidateOn = 'eager' | 'change' | 'blur' | 'submit' | ('change' | 'blur' | 'submit')[];
56
+ /**
57
+ * // TODO: should this be removed?
58
+ * The bare minimum validation required for ny validation implementation
59
+ */
60
+ export type Validator<V = any> = V;
61
+ /**
62
+ * Represents a form event payload.
63
+ */
64
+ export type EventName = string;
65
+ /**
66
+ * Actions that can be called back from the event handler callback
67
+ */
68
+ export type EventHandlerCallback = OVERRIDE_WIDGET_PROP;
69
+ export type FormEvent<T = any> = {
70
+ /** The name of the form widget that dispatched the event. */
71
+ name: EventName;
72
+ /** The form's data at the moment the event was dispatched. */
73
+ data: Record<string, T>;
74
+ /** The detail provided by the widget at the moment the event was dispatched. */
75
+ detail?: any;
76
+ /** Actions that the client can execute to interact with the forms engine from the application scope */
77
+ callback: (action: EventHandlerCallback) => void;
78
+ };
79
+ /**
80
+ * Control adapter templateData
81
+ */
82
+ export type ControlTemplateData<T, V = any> = {
83
+ lang?: string;
84
+ label?: string;
85
+ value?: T;
86
+ /**
87
+ * A size relative to the container and sibling components
88
+ * @example
89
+ * // This component will measure twice than sibling components with size: 1
90
+ * size: 2
91
+ */
92
+ size?: number;
93
+ /**
94
+ * validation errors
95
+ */
96
+ errors?: string[];
97
+ validator?: V;
98
+ disabled?: boolean;
99
+ readonly?: boolean;
100
+ touched?: boolean;
101
+ };
102
+ /**
103
+ * Layout adapter templateData
104
+ */
105
+ export type LayoutTemplateData = {
106
+ lang?: string;
107
+ /**
108
+ * A size relative to the container and sibling components
109
+ * @example
110
+ * // This component will measure twice than sibling components with size: 1
111
+ * size: 2
112
+ */
113
+ size?: number;
114
+ children: NonFunctionWidget<string>[];
115
+ };
116
+ /**
117
+ * Display widget adapter templateData
118
+ */
119
+ export type DisplayWidgetTemplateData = {
120
+ lang?: string;
121
+ /**
122
+ * A size relative to the container and sibling components
123
+ * @example
124
+ * // This component will measure twice than sibling components with size: 1
125
+ * size: 2
126
+ */
127
+ size?: number;
128
+ };
129
+ /**
130
+ * Action widget adapter templateData
131
+ */
132
+ export type ActionWidgetTemplateData = {
133
+ lang?: string;
134
+ label?: string;
135
+ disabled?: boolean;
136
+ /**
137
+ * A size relative to the container and sibling components
138
+ * @example
139
+ * // This component will measure twice than sibling components with size: 1
140
+ * size: 2
141
+ */
142
+ size?: number;
143
+ };