@a-ludi/rjsf-formulas 0.3.2 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const se=require("@rjsf/utils"),oe=require("react/jsx-runtime"),i=require("react"),fe=require("@rjsf/core"),U=Symbol("arrayIndex");function C(e,t){const r=(t==null?void 0:t.formulaKey)??"x-formula",s=(t==null?void 0:t.formulaContextKey)??"x-formula-context",n=(t==null?void 0:t.formulaConflictBehavior)??"warn",o=[];return A(e,[],o,r,s,n,!0,e),o}function J(e,t){if(e===!0)return t;const r=e;return Array.isArray(r.allOf)?{allOf:[...r.allOf,t]}:{allOf:[e,t]}}function ce(e,t){return e===void 0||e==="siblings"?"siblings":e==="extended"?"extended":(console.warn(`[rjsf-formulas] Unknown x-formula-context value "${e}" at path [${z(t)}], treating as "siblings"`),"siblings")}function z(e){return e.map(t=>typeof t=="symbol"?"[*]":String(t)).join(", ")}function Y(e){return e.map(t=>typeof t=="symbol"?"[*]":String(t)).join(".")}function ue(e,t,r){const s=Y(e.path);if(r==="error")throw new TypeError(`[rjsf-formulas] Formula conflict at path [${z(e.path)}]: "${e.formula}" vs "${t.formula}". Resolve the conflict or set formulaConflictBehavior to 'ignore' or 'warn'.`);r==="warn"&&console.warn(`[rjsf-formulas] Formula conflict at path [${s}]: "${e.formula}" (earlier allOf branch) is overridden by "${t.formula}" (later allOf branch).`)}function ie(e,t,r){for(const s of t){const n=Y(s.path),o=e.findIndex(u=>Y(u.path)===n);o!==-1?(ue(e[o],s,r),e[o]=s):e.push(s)}}function A(e,t,r,s,n,o,u,a){const f=e;if(typeof f.$ref=="string"){const c=se.findSchemaDefinition(f.$ref,a);A(c,t,r,s,n,o,u,a);return}if(s in e){const c=f[s];if(typeof c!="string"){console.warn(`[rjsf-formulas] Formula at path [${z(t)}] is not a string (got ${typeof c}), skipping.`);return}r.push({path:t,formula:c,contextMode:ce(f[n],t),condition:u});return}const y=e.type==="array"||e.type==null&&(Array.isArray(f.prefixItems)||e.items!=null&&!Array.isArray(e.items));if(e.properties&&!y)for(const[c,l]of Object.entries(e.properties))A(l,[...t,c],r,s,n,o,u,a);if(y&&(Array.isArray(f.prefixItems)&&f.prefixItems.forEach((l,m)=>{A(l,[...t,m],r,s,n,o,u,a)}),e.items&&!Array.isArray(e.items)&&A(e.items,[...t,U],r,s,n,o,u,a)),Array.isArray(f.allOf)){const c=f.allOf;for(const l of c){const m=[];A(l,t,m,s,n,o,u,a),ie(r,m,o)}}for(const c of["oneOf","anyOf"])if(Array.isArray(f[c])){const l=f[c];for(const m of l){const g=J(u,m);A(m,t,r,s,n,o,g,a)}}if("if"in f){const c=f.if,l=f.then,m=f.else;if(s in c&&console.warn(`[rjsf-formulas] Formula key "${s}" found inside an "if" schema at path [${z(t)}]. The "if" schema is a validation predicate and is never rendered — the formula will be ignored.`),l!==void 0){const g=J(u,c);A(l,t,r,s,n,o,g,a)}if(m!==void 0){const g=J(u,{not:c});A(m,t,r,s,n,o,g,a)}}}function ae(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var X,Z;function le(){return Z||(Z=1,X=function e(t,r){if(t===r)return!0;if(t&&r&&typeof t=="object"&&typeof r=="object"){if(t.constructor!==r.constructor)return!1;var s,n,o;if(Array.isArray(t)){if(s=t.length,s!=r.length)return!1;for(n=s;n--!==0;)if(!e(t[n],r[n]))return!1;return!0}if(t.constructor===RegExp)return t.source===r.source&&t.flags===r.flags;if(t.valueOf!==Object.prototype.valueOf)return t.valueOf()===r.valueOf();if(t.toString!==Object.prototype.toString)return t.toString()===r.toString();if(o=Object.keys(t),s=o.length,s!==Object.keys(r).length)return!1;for(n=s;n--!==0;)if(!Object.prototype.hasOwnProperty.call(r,o[n]))return!1;for(n=s;n--!==0;){var u=o[n];if(!e(t[u],r[u]))return!1}return!0}return t!==t&&r!==r}),X}var ye=le();const de=ae(ye);function pe(e,t,r,s){const o=t.slice(0,-1).reduce((a,f)=>{if(!(a==null||typeof a!="object"))return a[f]},r),u=o!=null&&typeof o=="object"&&!Array.isArray(o)?{...o}:{};return e.contextMode==="extended"?((s.formulaDataKey in u||s.formulaPathKey in u)&&console.warn(`[rjsf-formulas] Extended context key collision: sibling field named "${s.formulaDataKey in u?s.formulaDataKey:s.formulaPathKey}" will be overwritten by the injected context. Use formulaDataKey/formulaPathKey props to choose a different key.`),{...u,[s.formulaDataKey]:r,[s.formulaPathKey]:[...t]}):u}function B(e){return e.map(t=>typeof t=="symbol"?"[*]":String(t)).join(", ")}function I(e,t){return t.reduce((r,s)=>{if(!(r==null||typeof r!="object"))return r[s]},e)}function V(e,t,r){if(t.length===0)return;const s=I(e,t.slice(0,-1));s!=null&&typeof s=="object"&&(s[t[t.length-1]]=r)}function k(e,t,r=[]){if(e.length===0)return[r];const[s,...n]=e;if(s===U){const o=I(t,r);if(!Array.isArray(o))return[];const u=[];for(let a=0;a<o.length;a++)u.push(...k(n,t,[...r,a]));return u}return k(n,t,[...r,s])}function H(e,t){return de(e,t)}async function L(e,t,r,s){const n=structuredClone(e),o=[];for(const f of t)for(const y of k(f.path,n)){const c=pe(f,y,n,s);o.push({field:f,concretePath:y,context:c})}const u=await Promise.allSettled(o.map(({field:f,context:y})=>new Promise(c=>c(r(f.formula,y))))),a=[];for(let f=0;f<o.length;f++){const{concretePath:y}=o[f],c=u[f];if(c.status==="fulfilled")V(n,y,c.value);else{const l=c.reason instanceof Error?c.reason:new Error(String(c.reason));a.push({path:y,error:l}),V(n,y,void 0)}}return{data:n,errors:a}}function me(e,t,r){for(const s of r)for(const n of k(s.path,t))if(!H(I(e,n),I(t,n)))return!1;return!0}async function ge(e,t,r,s,n,o,u,a,f){const y=t.filter(p=>p.condition===!0||a(p.condition,e));if(y.length===0)return e;const c=new Map,l=[];for(const p of y){const d=JSON.stringify(p.path);if(c.has(d)){if(f==="error")throw new TypeError(`[rjsf-formulas] Formula conflict: two active fields share path [${B(p.path)}]`);f==="warn"&&console.warn(`[rjsf-formulas] Formula conflict: two active fields share path [${B(p.path)}]; taking last`);const h=l.indexOf(c.get(d));l[h]=p,c.set(d,p)}else c.set(d,p),l.push(p)}const m={formulaDataKey:o,formulaPathKey:u};let g=e;for(let p=0;p<s;p++){const{data:d,errors:h}=await L(g,l,r,m);if(me(g,d,l)){for(const{path:w,error:$}of h)n==null||n(w,$);return d}g=d}const{data:O}=await L(g,l,r,m),j=structuredClone(O);for(const p of l)for(const d of k(p.path,O))H(I(g,d),I(O,d))||(n==null||n(d,new Error(`[rjsf-formulas] Formula at [${d.join(", ")}] did not converge after ${s} passes`)),V(j,d,void 0));return j}function he(e){return JSON.stringify(e)}function je(e,t,r,s,n,o,u,a,f,y){const[c,l]=i.useState(e),m=i.useRef(e),g=i.useRef(e),O=i.useRef(new Map),j=i.useRef(null),p=i.useRef(!1),d=i.useRef(o),h=i.useRef(u),w=i.useRef(r),$=i.useRef(t),S=i.useRef(n),F=i.useRef(a),x=i.useRef(f),T=i.useRef(y);i.useEffect(()=>{d.current=o},[o]),i.useEffect(()=>{h.current=u},[u]),i.useEffect(()=>{w.current=r},[r]),i.useEffect(()=>{$.current=t},[t]),i.useEffect(()=>{S.current=n},[n]),i.useEffect(()=>{F.current=a},[a]),i.useEffect(()=>{x.current=f},[f]),i.useEffect(()=>{T.current=y},[y]);const E=i.useCallback(()=>{if(p.current)return;(async()=>{var _,K;p.current=!0;try{for(;;){const D=m.current,W=$.current,ee=W.filter(b=>b.condition===!0||x.current(b.condition,D)),q=[];for(const b of ee)for(const ne of k(b.path,D))q.push(ne);const N=O.current;N.clear();for(const b of q)N.set(he(b),"running");q.length>0&&((_=h.current)==null||_.call(h,q));const te=await ge(D,W,w.current,S.current,d.current,F.current.formulaDataKey,F.current.formulaPathKey,x.current,T.current);if(v.current)break;const re=[...N.values()].some(b=>b==="dirty");if(N.clear(),!re){l(te),q.length>0&&((K=h.current)==null||K.call(h,[]));break}}}finally{p.current=!1}})()},[]),M=i.useCallback(Q=>{m.current=Q;const _=O.current;for(const[K,D]of _)D==="running"&&_.set(K,"dirty");p.current||(j.current!==null&&clearTimeout(j.current),j.current=setTimeout(()=>{j.current=null,E()},s))},[s,E]),R=i.useRef(!1),v=i.useRef(!1);return i.useEffect(()=>{R.current?H(e,g.current)||(g.current=e,M(e)):(R.current=!0,g.current=e,M(e))}),i.useEffect(()=>(v.current=!1,()=>{v.current=!0,R.current=!1,j.current!==null&&clearTimeout(j.current)}),[]),{enrichedFormData:c,handleInput:M}}function Re(e,t){const r=structuredClone(e??{}),s=we(t);for(const n of t)P(r,n.path,s);return r}function we(e){const t=new Set;for(let r=0;r<e.length;r++){const s=e[r].path;for(let n=0;n<s.length;n++){const o=s[n];if(typeof o!="number"&&o!==U)continue;const u=G(s.slice(0,n)),a=typeof o=="number";e.some((y,c)=>{if(c===r||y.path.length<=n||G(y.path.slice(0,n))!==u)return!1;const l=y.path[n];return a?l===U:typeof l=="number"})&&t.add(u)}}return t}function G(e){return JSON.stringify(e.map(t=>typeof t=="symbol"?"__ARRAY_INDEX__":t))}function P(e,t,r,s=[]){if(t.length===0){e["ui:readonly"]=!0;return}const[n,...o]=t;if(typeof n=="string"){(!e[n]||typeof e[n]!="object"||Array.isArray(e[n]))&&(e[n]={}),P(e[n],o,r,[...s,n]);return}if(typeof n=="number"){if(e.items!==void 0&&!Array.isArray(e.items)){console.warn("[rjsf-formulas] mergeReadOnly: cannot inject ui:readonly at tuple index because existing uiSchema has items as an object. Skipping.");return}Array.isArray(e.items)||(e.items=[]);const f=e.items;(!f[n]||typeof f[n]!="object")&&(f[n]={}),P(f[n],o,r,[...s,n]);return}const u=G(s);if(r.has(u))(!e.additionalItems||typeof e.additionalItems!="object")&&(e.additionalItems={}),P(e.additionalItems,o,r,[...s,n]);else{if(Array.isArray(e.items)){console.warn("[rjsf-formulas] mergeReadOnly: cannot inject ui:readonly for uniform array because existing uiSchema has items as an array. Skipping.");return}(!e.items||typeof e.items!="object")&&(e.items={}),P(e.items,o,r,[...s,n])}}function Ae(e,t){const{schema:r,formData:s,validator:n,uiSchema:o,evaluator:u,Form:a=fe,formulaKey:f="x-formula",formulaContextKey:y="x-formula-context",formulaDataKey:c="__formData__",formulaPathKey:l="__path__",maxConvergencePasses:m=10,debounceMs:g=300,onFormulaError:O,onLoadingChange:j,formulaConflictBehavior:p="warn",onChange:d,...h}=e,w=i.useMemo(()=>C(r,{formulaKey:f,formulaContextKey:y}),[r,f,y]),$=i.useMemo(()=>({formulaDataKey:c,formulaPathKey:l}),[c,l]),S=i.useMemo(()=>Re(o,w),[o,w]),F=i.useCallback((R,v)=>n.isValid(R,v,r),[n,r]),{enrichedFormData:x,handleInput:T}=je(s,w,u,g,m,O,j,$,F,p),E=i.useRef(d);i.useEffect(()=>{E.current=d},[d]),i.useEffect(()=>{var R;w.length!==0&&((R=E.current)==null||R.call(E,{formData:x},void 0))},[x]);const M=(R,v)=>{T(R.formData),d==null||d(R,v)};return oe.jsx(a,{ref:t,...h,schema:r,validator:n,formData:x,uiSchema:S,onChange:M})}const Oe=i.forwardRef(Ae);exports.FormulaForm=Oe;exports.analyzeSchema=C;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const se=require("@rjsf/utils"),fe=require("react/jsx-runtime"),i=require("react"),oe=require("@rjsf/core"),z=Symbol("arrayIndex");function C(e,t){const r=(t==null?void 0:t.formulaKey)??"x-formula",s=(t==null?void 0:t.formulaContextKey)??"x-formula-context",n=(t==null?void 0:t.formulaConflictBehavior)??"warn",f=[];return w(e,[],f,r,s,n,!0,e),f}function K(e,t){if(e===!0)return t;const r=e;return Array.isArray(r.allOf)?{allOf:[...r.allOf,t]}:{allOf:[e,t]}}function ce(e,t){return e===void 0||e==="siblings"?"siblings":e==="extended"?"extended":(console.warn(`[rjsf-formulas] Unknown x-formula-context value "${e}" at path [${J(t)}], treating as "siblings"`),"siblings")}function J(e){return e.map(t=>typeof t=="symbol"?"[*]":String(t)).join(", ")}function Y(e){return e.map(t=>typeof t=="symbol"?"[*]":String(t)).join(".")}function ue(e,t,r){const s=Y(e.path);if(r==="error")throw new TypeError(`[rjsf-formulas] Formula conflict at path [${J(e.path)}]: "${e.formula}" vs "${t.formula}". Resolve the conflict or set formulaConflictBehavior to 'ignore' or 'warn'.`);r==="warn"&&console.warn(`[rjsf-formulas] Formula conflict at path [${s}]: "${e.formula}" (earlier allOf branch) is overridden by "${t.formula}" (later allOf branch).`)}function ie(e,t,r){for(const s of t){const n=Y(s.path),f=e.findIndex(u=>Y(u.path)===n);f!==-1?(ue(e[f],s,r),e[f]=s):e.push(s)}}function w(e,t,r,s,n,f,u,a){const o=e;if(typeof o.$ref=="string"){const c=se.findSchemaDefinition(o.$ref,a);w(c,t,r,s,n,f,u,a);return}if(s in e){const c=o[s];if(typeof c!="string"){console.warn(`[rjsf-formulas] Formula at path [${J(t)}] is not a string (got ${typeof c}), skipping.`);return}r.push({path:t,formula:c,contextMode:ce(o[n],t),condition:u});return}const y=e.type==="array"||e.type==null&&(Array.isArray(o.prefixItems)||e.items!=null);if(e.properties&&!y)for(const[c,l]of Object.entries(e.properties))w(l,[...t,c],r,s,n,f,u,a);if(y&&(Array.isArray(o.prefixItems)&&o.prefixItems.forEach((l,g)=>{w(l,[...t,g],r,s,n,f,u,a)}),Array.isArray(e.items)&&e.items.forEach((c,l)=>{w(c,[...t,l],r,s,n,f,u,a)}),e.items&&!Array.isArray(e.items)&&w(e.items,[...t,z],r,s,n,f,u,a)),Array.isArray(o.allOf)){const c=o.allOf;for(const l of c){const g=[];w(l,t,g,s,n,f,u,a),ie(r,g,f)}}for(const c of["oneOf","anyOf"])if(Array.isArray(o[c])){const l=o[c];for(const g of l){const m=K(u,g);w(g,t,r,s,n,f,m,a)}}if("if"in o){const c=o.if,l=o.then,g=o.else;if(s in c&&console.warn(`[rjsf-formulas] Formula key "${s}" found inside an "if" schema at path [${J(t)}]. The "if" schema is a validation predicate and is never rendered — the formula will be ignored.`),l!==void 0){const m=K(u,c);w(l,t,r,s,n,f,m,a)}if(g!==void 0){const m=K(u,{not:c});w(g,t,r,s,n,f,m,a)}}}function ae(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var X,Z;function le(){return Z||(Z=1,X=function e(t,r){if(t===r)return!0;if(t&&r&&typeof t=="object"&&typeof r=="object"){if(t.constructor!==r.constructor)return!1;var s,n,f;if(Array.isArray(t)){if(s=t.length,s!=r.length)return!1;for(n=s;n--!==0;)if(!e(t[n],r[n]))return!1;return!0}if(t.constructor===RegExp)return t.source===r.source&&t.flags===r.flags;if(t.valueOf!==Object.prototype.valueOf)return t.valueOf()===r.valueOf();if(t.toString!==Object.prototype.toString)return t.toString()===r.toString();if(f=Object.keys(t),s=f.length,s!==Object.keys(r).length)return!1;for(n=s;n--!==0;)if(!Object.prototype.hasOwnProperty.call(r,f[n]))return!1;for(n=s;n--!==0;){var u=f[n];if(!e(t[u],r[u]))return!1}return!0}return t!==t&&r!==r}),X}var ye=le();const pe=ae(ye);function de(e,t,r,s){const f=t.slice(0,-1).reduce((a,o)=>{if(!(a==null||typeof a!="object"))return a[o]},r),u=f!=null&&typeof f=="object"&&!Array.isArray(f)?{...f}:{};return e.contextMode==="extended"?((s.formulaDataKey in u||s.formulaPathKey in u)&&console.warn(`[rjsf-formulas] Extended context key collision: sibling field named "${s.formulaDataKey in u?s.formulaDataKey:s.formulaPathKey}" will be overwritten by the injected context. Use formulaDataKey/formulaPathKey props to choose a different key.`),{...u,[s.formulaDataKey]:r,[s.formulaPathKey]:[...t]}):u}function L(e){return e.map(t=>typeof t=="symbol"?"[*]":String(t)).join(", ")}function I(e,t){return t.reduce((r,s)=>{if(!(r==null||typeof r!="object"))return r[s]},e)}function V(e,t,r){if(t.length===0)return;const s=I(e,t.slice(0,-1));s!=null&&typeof s=="object"&&(s[t[t.length-1]]=r)}function k(e,t,r=[]){if(e.length===0)return[r];const[s,...n]=e;if(s===z){const f=I(t,r);if(!Array.isArray(f))return[];const u=[];for(let a=0;a<f.length;a++)u.push(...k(n,t,[...r,a]));return u}return k(n,t,[...r,s])}function H(e,t){return pe(e,t)}async function B(e,t,r,s){const n=structuredClone(e),f=[];for(const o of t)for(const y of k(o.path,n)){const c=de(o,y,n,s);f.push({field:o,concretePath:y,context:c})}const u=await Promise.allSettled(f.map(({field:o,context:y})=>new Promise(c=>c(r(o.formula,y))))),a=[];for(let o=0;o<f.length;o++){const{concretePath:y}=f[o],c=u[o];if(c.status==="fulfilled")V(n,y,c.value);else{const l=c.reason instanceof Error?c.reason:new Error(String(c.reason));a.push({path:y,error:l}),V(n,y,void 0)}}return{data:n,errors:a}}function ge(e,t,r){for(const s of r)for(const n of k(s.path,t))if(!H(I(e,n),I(t,n)))return!1;return!0}async function me(e,t,r,s,n,f,u,a,o){const y=t.filter(d=>d.condition===!0||a(d.condition,e));if(y.length===0)return e;const c=new Map,l=[];for(const d of y){const p=JSON.stringify(d.path);if(c.has(p)){if(o==="error")throw new TypeError(`[rjsf-formulas] Formula conflict: two active fields share path [${L(d.path)}]`);o==="warn"&&console.warn(`[rjsf-formulas] Formula conflict: two active fields share path [${L(d.path)}]; taking last`);const h=l.indexOf(c.get(p));l[h]=d,c.set(p,d)}else c.set(p,d),l.push(d)}const g={formulaDataKey:f,formulaPathKey:u};let m=e;for(let d=0;d<s;d++){const{data:p,errors:h}=await B(m,l,r,g);if(ge(m,p,l)){for(const{path:A,error:v}of h)n==null||n(A,v);return p}m=p}const{data:O}=await B(m,l,r,g),j=structuredClone(O);for(const d of l)for(const p of k(d.path,O))H(I(m,p),I(O,p))||(n==null||n(p,new Error(`[rjsf-formulas] Formula at [${p.join(", ")}] did not converge after ${s} passes`)),V(j,p,void 0));return j}function he(e){return JSON.stringify(e)}function je(e,t,r,s,n,f,u,a,o,y){const[c,l]=i.useState(e),g=i.useRef(e),m=i.useRef(e),O=i.useRef(new Map),j=i.useRef(null),d=i.useRef(!1),p=i.useRef(f),h=i.useRef(u),A=i.useRef(r),v=i.useRef(t),S=i.useRef(n),F=i.useRef(a),x=i.useRef(o),T=i.useRef(y);i.useEffect(()=>{p.current=f},[f]),i.useEffect(()=>{h.current=u},[u]),i.useEffect(()=>{A.current=r},[r]),i.useEffect(()=>{v.current=t},[t]),i.useEffect(()=>{S.current=n},[n]),i.useEffect(()=>{F.current=a},[a]),i.useEffect(()=>{x.current=o},[o]),i.useEffect(()=>{T.current=y},[y]);const E=i.useCallback(()=>{if(d.current)return;(async()=>{var _,N;d.current=!0;try{for(;;){const D=g.current,W=v.current,ee=W.filter(b=>b.condition===!0||x.current(b.condition,D)),q=[];for(const b of ee)for(const ne of k(b.path,D))q.push(ne);const U=O.current;U.clear();for(const b of q)U.set(he(b),"running");q.length>0&&((_=h.current)==null||_.call(h,q));const te=await me(D,W,A.current,S.current,p.current,F.current.formulaDataKey,F.current.formulaPathKey,x.current,T.current);if($.current)break;const re=[...U.values()].some(b=>b==="dirty");if(U.clear(),!re){l(te),q.length>0&&((N=h.current)==null||N.call(h,[]));break}}}finally{d.current=!1}})()},[]),M=i.useCallback(Q=>{g.current=Q;const _=O.current;for(const[N,D]of _)D==="running"&&_.set(N,"dirty");d.current||(j.current!==null&&clearTimeout(j.current),j.current=setTimeout(()=>{j.current=null,E()},s))},[s,E]),R=i.useRef(!1),$=i.useRef(!1);return i.useEffect(()=>{R.current?H(e,m.current)||(m.current=e,M(e)):(R.current=!0,m.current=e,M(e))}),i.useEffect(()=>($.current=!1,()=>{$.current=!0,R.current=!1,j.current!==null&&clearTimeout(j.current)}),[]),{enrichedFormData:c,handleInput:M}}function Re(e,t){const r=structuredClone(e??{}),s=we(t);for(const n of t)P(r,n.path,s);return r}function we(e){const t=new Set;for(let r=0;r<e.length;r++){const s=e[r].path;for(let n=0;n<s.length;n++){const f=s[n];if(typeof f!="number"&&f!==z)continue;const u=G(s.slice(0,n)),a=typeof f=="number";e.some((y,c)=>{if(c===r||y.path.length<=n||G(y.path.slice(0,n))!==u)return!1;const l=y.path[n];return a?l===z:typeof l=="number"})&&t.add(u)}}return t}function G(e){return JSON.stringify(e.map(t=>typeof t=="symbol"?"__ARRAY_INDEX__":t))}function P(e,t,r,s=[]){if(t.length===0){e["ui:readonly"]=!0;return}const[n,...f]=t;if(typeof n=="string"){(!e[n]||typeof e[n]!="object"||Array.isArray(e[n]))&&(e[n]={}),P(e[n],f,r,[...s,n]);return}if(typeof n=="number"){if(e.items!==void 0&&!Array.isArray(e.items)){console.warn("[rjsf-formulas] mergeReadOnly: cannot inject ui:readonly at tuple index because existing uiSchema has items as an object. Skipping.");return}Array.isArray(e.items)||(e.items=[]);const o=e.items;(!o[n]||typeof o[n]!="object")&&(o[n]={}),P(o[n],f,r,[...s,n]);return}const u=G(s);if(r.has(u))(!e.additionalItems||typeof e.additionalItems!="object")&&(e.additionalItems={}),P(e.additionalItems,f,r,[...s,n]);else{if(Array.isArray(e.items)){console.warn("[rjsf-formulas] mergeReadOnly: cannot inject ui:readonly for uniform array because existing uiSchema has items as an array. Skipping.");return}(!e.items||typeof e.items!="object")&&(e.items={}),P(e.items,f,r,[...s,n])}}function Ae(e,t){const{schema:r,formData:s,validator:n,uiSchema:f,evaluator:u,Form:a=oe,formulaKey:o="x-formula",formulaContextKey:y="x-formula-context",formulaDataKey:c="__formData__",formulaPathKey:l="__path__",maxConvergencePasses:g=10,debounceMs:m=300,onFormulaError:O,onLoadingChange:j,formulaConflictBehavior:d="warn",onChange:p,...h}=e,A=i.useMemo(()=>C(r,{formulaKey:o,formulaContextKey:y}),[r,o,y]),v=i.useMemo(()=>({formulaDataKey:c,formulaPathKey:l}),[c,l]),S=i.useMemo(()=>Re(f,A),[f,A]),F=i.useCallback((R,$)=>n.isValid(R,$,r),[n,r]),{enrichedFormData:x,handleInput:T}=je(s,A,u,m,g,O,j,v,F,d),E=i.useRef(p);i.useEffect(()=>{E.current=p},[p]),i.useEffect(()=>{var R;A.length!==0&&((R=E.current)==null||R.call(E,{formData:x},void 0))},[x]);const M=(R,$)=>{T(R.formData),p==null||p(R,$)};return fe.jsx(a,{ref:t,...h,schema:r,validator:n,formData:x,uiSchema:S,onChange:M})}const Oe=i.forwardRef(Ae);exports.FormulaForm=Oe;exports.analyzeSchema=C;
2
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sources":["../src/analyzeSchema.ts","../node_modules/fast-deep-equal/index.js","../src/buildContext.ts","../src/enrich.ts","../src/useAsyncFormulas.ts","../src/mergeReadOnly.ts","../src/FormulaForm.tsx"],"sourcesContent":["import type { RJSFSchema } from '@rjsf/utils'\nimport { findSchemaDefinition } from '@rjsf/utils'\n\n/**\n * Sentinel used in formula field paths to represent a uniform array item position.\n * @internal\n */\nexport const ARRAY_INDEX: unique symbol = Symbol('arrayIndex')\n\n/** @internal */\nexport type ArrayIndex = typeof ARRAY_INDEX\n\n/**\n * Controls which values are injected into the formula evaluation context.\n *\n * - `'siblings'` (default): only the sibling fields of the computed field are available by name.\n * - `'extended'`: full form data and the field's resolved path are injected alongside sibling\n * values, under the keys configured by `formulaDataKey` and `formulaPathKey`.\n *\n * Set via the `x-formula-context` schema key (or the `formulaContextKey` prop).\n */\nexport type ContextMode = 'siblings' | 'extended'\n\n/**\n * Describes a single computed field discovered by {@link analyzeSchema}.\n */\nexport type FormulaField = {\n /** JSON path to the field within the form data. Uniform array item positions are represented by {@link ARRAY_INDEX}. */\n path: (string | number | ArrayIndex)[]\n /** The raw formula string from the schema. */\n formula: string\n /** Which values are available when evaluating this field's formula. */\n contextMode: ContextMode\n /**\n * The schema condition under which this formula is active.\n *\n * - `true` — always active (fields from `properties`, `items`, `prefixItems`, or `allOf` branches).\n * - `RJSFSchema` — a conditional schema (a `oneOf`/`anyOf` branch condition, possibly composed\n * via `{ allOf: [...] }` for nested branches).\n */\n condition: RJSFSchema | true\n}\n\n/**\n * Options for {@link analyzeSchema}.\n */\nexport type AnalyzeSchemaOptions = {\n /** Schema key that marks a field as computed. Defaults to `'x-formula'`. */\n formulaKey?: string\n /** Schema key that selects the context mode for a computed field. Defaults to `'x-formula-context'`. */\n formulaContextKey?: string\n /**\n * What to do when multiple `allOf` branches define a formula for the same path.\n *\n * - `'ignore'`: silently take the last definition.\n * - `'warn'` (default): emit `console.warn` and take the last definition.\n * - `'error'`: throw a `TypeError` synchronously.\n */\n formulaConflictBehavior?: 'ignore' | 'warn' | 'error'\n}\n\n/**\n * Scans a JSON Schema and returns descriptors for every field that carries a formula key.\n *\n * @remarks\n * Traversal is depth-first. `allOf`, `$ref`, `oneOf`, and `anyOf` are all supported.\n * `allOf` branches are merged with conflict detection. `oneOf`/`anyOf` branches are each\n * recursed and fields are collected with the branch schema as the `condition`. Nested\n * `oneOf`/`anyOf` conditions are composed via `{ allOf: [...] }`. `$ref` is resolved\n * synchronously using `findSchemaDefinition` (external refs will throw).\n *\n * @param schema - The root RJSF schema to scan.\n * @param options - Optional key overrides for locating formulas in the schema.\n * @returns An array of {@link FormulaField} descriptors, one per computed field found.\n *\n * @example\n * ```ts\n * import { analyzeSchema } from '@a-ludi/rjsf-formulas'\n *\n * const fields = analyzeSchema({\n * type: 'object',\n * properties: {\n * price: { type: 'number' },\n * total: { type: 'number', 'x-formula': 'price * 2' },\n * },\n * })\n * // fields[0].path => ['total']\n * // fields[0].formula => 'price * 2'\n * ```\n */\nexport function analyzeSchema(\n schema: RJSFSchema,\n options?: AnalyzeSchemaOptions\n): FormulaField[] {\n const formulaKey = options?.formulaKey ?? 'x-formula'\n const formulaContextKey = options?.formulaContextKey ?? 'x-formula-context'\n const formulaConflictBehavior = options?.formulaConflictBehavior ?? 'warn'\n const fields: FormulaField[] = []\n traverse(schema, [], fields, formulaKey, formulaContextKey, formulaConflictBehavior, true, schema)\n return fields\n}\n\n/**\n * Compose an ambient condition with a new branch schema.\n *\n * - If `ambient === true`: returns `branch` directly (no wrapping needed).\n * - If `ambient` already has an `allOf`: appends `branch` to that array.\n * - Otherwise: wraps both in `{ allOf: [ambient, branch] }`.\n */\nfunction composeCondition(ambient: RJSFSchema | true, branch: RJSFSchema): RJSFSchema {\n if (ambient === true) return branch\n const ambientAny = ambient as Record<string, unknown>\n if (Array.isArray(ambientAny['allOf'])) {\n return { allOf: [...(ambientAny['allOf'] as RJSFSchema[]), branch] }\n }\n return { allOf: [ambient, branch] }\n}\n\nfunction resolveContextMode(\n value: unknown,\n path: (string | number | ArrayIndex)[]\n): ContextMode {\n if (value === undefined || value === 'siblings') return 'siblings'\n if (value === 'extended') return 'extended'\n console.warn(\n `[rjsf-formulas] Unknown x-formula-context value \"${value}\" at path [${formatPath(path)}], treating as \"siblings\"`\n )\n return 'siblings'\n}\n\nfunction formatPath(path: (string | number | ArrayIndex)[]): string {\n return path.map(s => (typeof s === 'symbol' ? '[*]' : String(s))).join(', ')\n}\n\nfunction pathKey(path: (string | number | ArrayIndex)[]): string {\n return path.map(s => (typeof s === 'symbol' ? '[*]' : String(s))).join('.')\n}\n\nfunction applyConflictBehavior(\n existing: FormulaField,\n incoming: FormulaField,\n behavior: 'ignore' | 'warn' | 'error'\n): void {\n const key = pathKey(existing.path)\n if (behavior === 'error') {\n throw new TypeError(\n `[rjsf-formulas] Formula conflict at path [${formatPath(existing.path)}]: \"${existing.formula}\" vs \"${incoming.formula}\". Resolve the conflict or set formulaConflictBehavior to 'ignore' or 'warn'.`\n )\n }\n if (behavior === 'warn') {\n console.warn(\n `[rjsf-formulas] Formula conflict at path [${key}]: \"${existing.formula}\" (earlier allOf branch) is overridden by \"${incoming.formula}\" (later allOf branch).`\n )\n }\n}\n\nfunction mergeFields(\n base: FormulaField[],\n incoming: FormulaField[],\n behavior: 'ignore' | 'warn' | 'error'\n): void {\n for (const field of incoming) {\n const key = pathKey(field.path)\n const existingIndex = base.findIndex(f => pathKey(f.path) === key)\n if (existingIndex !== -1) {\n applyConflictBehavior(base[existingIndex], field, behavior)\n base[existingIndex] = field\n } else {\n base.push(field)\n }\n }\n}\n\nfunction traverse(\n schema: RJSFSchema,\n path: (string | number | ArrayIndex)[],\n fields: FormulaField[],\n formulaKey: string,\n formulaContextKey: string,\n formulaConflictBehavior: 'ignore' | 'warn' | 'error',\n ambientCondition: RJSFSchema | true,\n rootSchema: RJSFSchema\n): void {\n const schemaAny = schema as Record<string, unknown>\n\n // $ref — resolve and continue traversal with the same ambientCondition\n if (typeof schemaAny['$ref'] === 'string') {\n const resolved = findSchemaDefinition(schemaAny['$ref'] as string, rootSchema)\n traverse(resolved, path, fields, formulaKey, formulaContextKey, formulaConflictBehavior, ambientCondition, rootSchema)\n return\n }\n\n // Rule 1: computed field — record and stop\n if (formulaKey in schema) {\n const formula = schemaAny[formulaKey]\n if (typeof formula !== 'string') {\n console.warn(\n `[rjsf-formulas] Formula at path [${formatPath(path)}] is not a string (got ${typeof formula}), skipping.`\n )\n return\n }\n fields.push({\n path,\n formula,\n contextMode: resolveContextMode(schemaAny[formulaContextKey], path),\n condition: ambientCondition,\n })\n return\n }\n\n // Rule 2: object — recurse into properties (type: 'object' is implicit when properties are present)\n const isArray = schema.type === 'array' ||\n (schema.type == null && (Array.isArray(schemaAny['prefixItems']) || schema.items != null))\n if (schema.properties && !isArray) {\n for (const [key, propSchema] of Object.entries(schema.properties)) {\n traverse(\n propSchema as RJSFSchema,\n [...path, key],\n fields,\n formulaKey,\n formulaContextKey,\n formulaConflictBehavior,\n ambientCondition,\n rootSchema\n )\n }\n }\n\n // Rule 3: array — recurse into prefixItems and/or items (type: 'array' is implicit when items/prefixItems are present)\n if (isArray) {\n // Rule 3a: prefixItems (tuple positions with static indices)\n if (Array.isArray(schemaAny['prefixItems'])) {\n const prefixItems = schemaAny['prefixItems'] as RJSFSchema[]\n prefixItems.forEach((itemSchema, index) => {\n traverse(itemSchema, [...path, index], fields, formulaKey, formulaContextKey, formulaConflictBehavior, ambientCondition, rootSchema)\n })\n }\n\n // Rule 3b: items as array (legacy draft-07 tuple — positional schemas, equivalent to prefixItems)\n if (Array.isArray(schema.items)) {\n ;(schema.items as RJSFSchema[]).forEach((itemSchema, index) => {\n traverse(itemSchema, [...path, index], fields, formulaKey, formulaContextKey, formulaConflictBehavior, ambientCondition, rootSchema)\n })\n }\n\n // Rule 3c: items as object (uniform array — all elements share one schema)\n if (schema.items && !Array.isArray(schema.items)) {\n traverse(\n schema.items as RJSFSchema,\n [...path, ARRAY_INDEX],\n fields,\n formulaKey,\n formulaContextKey,\n formulaConflictBehavior,\n ambientCondition,\n rootSchema\n )\n }\n }\n\n // Rule 4: allOf — recurse into each branch, then merge with conflict detection\n // allOf does not add to the condition — branches are always active within their parent's condition\n if (Array.isArray(schemaAny['allOf'])) {\n const allOfBranches = schemaAny['allOf'] as RJSFSchema[]\n for (const branch of allOfBranches) {\n const branchFields: FormulaField[] = []\n traverse(branch, path, branchFields, formulaKey, formulaContextKey, formulaConflictBehavior, ambientCondition, rootSchema)\n mergeFields(fields, branchFields, formulaConflictBehavior)\n }\n }\n\n // Rule 5: oneOf / anyOf — recurse each branch with a composed condition\n for (const compositionKey of ['oneOf', 'anyOf'] as const) {\n if (Array.isArray(schemaAny[compositionKey])) {\n const branches = schemaAny[compositionKey] as RJSFSchema[]\n for (const branch of branches) {\n const branchCondition = composeCondition(ambientCondition, branch)\n traverse(branch, path, fields, formulaKey, formulaContextKey, formulaConflictBehavior, branchCondition, rootSchema)\n }\n }\n }\n\n // Rule 6: if/then/else — traverse then/else with appropriate conditions; warn if formula found in if\n if ('if' in schemaAny) {\n const ifSchema = schemaAny['if'] as RJSFSchema\n const thenSchema = schemaAny['then'] as RJSFSchema | undefined\n const elseSchema = schemaAny['else'] as RJSFSchema | undefined\n\n // Warn if the if schema itself contains a formula key (it is never rendered by RJSF)\n if (formulaKey in (ifSchema as Record<string, unknown>)) {\n console.warn(\n `[rjsf-formulas] Formula key \"${formulaKey}\" found inside an \"if\" schema at path [${formatPath(path)}]. The \"if\" schema is a validation predicate and is never rendered — the formula will be ignored.`\n )\n }\n\n if (thenSchema !== undefined) {\n const thenCondition = composeCondition(ambientCondition, ifSchema)\n traverse(thenSchema, path, fields, formulaKey, formulaContextKey, formulaConflictBehavior, thenCondition, rootSchema)\n }\n\n if (elseSchema !== undefined) {\n const elseCondition = composeCondition(ambientCondition, { not: ifSchema })\n traverse(elseSchema, path, fields, formulaKey, formulaContextKey, formulaConflictBehavior, elseCondition, rootSchema)\n }\n }\n}\n","'use strict';\n\n// do not edit .js files directly - edit src/index.jst\n\n\n\nmodule.exports = function equal(a, b) {\n if (a === b) return true;\n\n if (a && b && typeof a == 'object' && typeof b == 'object') {\n if (a.constructor !== b.constructor) return false;\n\n var length, i, keys;\n if (Array.isArray(a)) {\n length = a.length;\n if (length != b.length) return false;\n for (i = length; i-- !== 0;)\n if (!equal(a[i], b[i])) return false;\n return true;\n }\n\n\n\n if (a.constructor === RegExp) return a.source === b.source && a.flags === b.flags;\n if (a.valueOf !== Object.prototype.valueOf) return a.valueOf() === b.valueOf();\n if (a.toString !== Object.prototype.toString) return a.toString() === b.toString();\n\n keys = Object.keys(a);\n length = keys.length;\n if (length !== Object.keys(b).length) return false;\n\n for (i = length; i-- !== 0;)\n if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false;\n\n for (i = length; i-- !== 0;) {\n var key = keys[i];\n\n if (!equal(a[key], b[key])) return false;\n }\n\n return true;\n }\n\n // true if both NaN, false otherwise\n return a!==a && b!==b;\n};\n","import type { FormulaField } from './analyzeSchema'\n\nexport type BuildContextOptions = {\n formulaDataKey: string\n formulaPathKey: string\n}\n\nexport function buildContext(\n field: FormulaField,\n resolvedPath: (string | number)[],\n candidateFormData: unknown,\n options: BuildContextOptions\n): object {\n const parentPath = resolvedPath.slice(0, -1)\n const parent = parentPath.reduce<unknown>((curr, key) => {\n if (curr == null || typeof curr !== 'object') return undefined\n return (curr as Record<string | number, unknown>)[key]\n }, candidateFormData)\n\n const siblings =\n parent != null && typeof parent === 'object' && !Array.isArray(parent)\n ? { ...(parent as object) }\n : {}\n\n if (field.contextMode === 'extended') {\n if (options.formulaDataKey in siblings || options.formulaPathKey in siblings) {\n console.warn(\n `[rjsf-formulas] Extended context key collision: sibling field named \"${\n options.formulaDataKey in siblings ? options.formulaDataKey : options.formulaPathKey\n }\" will be overwritten by the injected context. Use formulaDataKey/formulaPathKey props to choose a different key.`\n )\n }\n return {\n ...siblings,\n [options.formulaDataKey]: candidateFormData,\n [options.formulaPathKey]: [...resolvedPath],\n }\n }\n\n return siblings\n}\n","import equal from 'fast-deep-equal'\nimport type { RJSFSchema } from '@rjsf/utils'\nimport type { FormulaField, ArrayIndex } from './analyzeSchema'\nimport { ARRAY_INDEX } from './analyzeSchema'\nimport { buildContext } from './buildContext'\nimport type { BuildContextOptions } from './buildContext'\n\nexport { ARRAY_INDEX }\n\nfunction formatPath(path: (string | number | ArrayIndex)[]): string {\n return path.map(s => (typeof s === 'symbol' ? '[*]' : String(s))).join(', ')\n}\n\nexport function getAt(data: unknown, path: (string | number)[]): unknown {\n return path.reduce<unknown>((curr, key) => {\n if (curr == null || typeof curr !== 'object') return undefined\n return (curr as Record<string | number, unknown>)[key]\n }, data)\n}\n\nexport function setAt(data: unknown, path: (string | number)[], value: unknown): void {\n if (path.length === 0) return\n const parent = getAt(data, path.slice(0, -1))\n if (parent != null && typeof parent === 'object') {\n ;(parent as Record<string | number, unknown>)[path[path.length - 1]] = value\n }\n}\n\nexport function expandPaths(\n templatePath: (string | number | ArrayIndex)[],\n data: unknown,\n currentPath: (string | number)[] = []\n): (string | number)[][] {\n if (templatePath.length === 0) return [currentPath]\n const [head, ...rest] = templatePath\n if (head === ARRAY_INDEX) {\n const arr = getAt(data, currentPath)\n if (!Array.isArray(arr)) return []\n const results: (string | number)[][] = []\n for (let i = 0; i < arr.length; i++) {\n results.push(...expandPaths(rest, data, [...currentPath, i]))\n }\n return results\n }\n return expandPaths(rest, data, [...currentPath, head as string | number])\n}\n\nexport function deepEqual(a: unknown, b: unknown): boolean {\n return equal(a, b)\n}\n\ntype EvalTask = { field: FormulaField; concretePath: (string | number)[]; context: object }\n\ninterface PassResult {\n data: unknown\n errors: Array<{ path: (string | number)[]; error: Error }>\n}\n\nasync function applyAllFormulas(\n formData: unknown,\n formulaFields: FormulaField[],\n evaluator: (formula: string, context: object) => unknown | Promise<unknown>,\n contextOptions: BuildContextOptions\n): Promise<PassResult> {\n const result = structuredClone(formData)\n\n // Collect all tasks from the snapshot before any evaluation\n const tasks: EvalTask[] = []\n for (const field of formulaFields) {\n for (const concretePath of expandPaths(field.path, result)) {\n const context = buildContext(field, concretePath, result, contextOptions)\n tasks.push({ field, concretePath, context })\n }\n }\n\n // Evaluate all formulas in parallel; new Promise() executor is try-catched, catching sync throws\n const settled = await Promise.allSettled(\n tasks.map(({ field, context }) => new Promise<unknown>(resolve => resolve(evaluator(field.formula, context))))\n )\n\n // Apply results\n const errors: Array<{ path: (string | number)[]; error: Error }> = []\n for (let i = 0; i < tasks.length; i++) {\n const { concretePath } = tasks[i]\n const outcome = settled[i]\n if (outcome.status === 'fulfilled') {\n setAt(result, concretePath, outcome.value)\n } else {\n const err = outcome.reason instanceof Error\n ? outcome.reason\n : new Error(String(outcome.reason))\n errors.push({ path: concretePath, error: err })\n setAt(result, concretePath, undefined)\n }\n }\n\n return { data: result, errors }\n}\n\nfunction allConverged(\n prev: unknown,\n next: unknown,\n formulaFields: FormulaField[]\n): boolean {\n for (const field of formulaFields) {\n for (const concretePath of expandPaths(field.path, next)) {\n if (!deepEqual(getAt(prev, concretePath), getAt(next, concretePath))) {\n return false\n }\n }\n }\n return true\n}\n\nexport async function enrich(\n formData: unknown,\n formulaFields: FormulaField[],\n evaluator: (formula: string, context: object) => unknown | Promise<unknown>,\n maxConvergencePasses: number,\n onFormulaError: ((path: (string | number)[], error: Error) => void) | undefined,\n formulaDataKey: string,\n formulaPathKey: string,\n checkCondition: (condition: RJSFSchema, formData: unknown) => boolean,\n formulaConflictBehavior: 'ignore' | 'warn' | 'error'\n): Promise<unknown> {\n // Filter to only active fields based on condition\n const activeFields = formulaFields.filter(field =>\n field.condition === true || checkCondition(field.condition as RJSFSchema, formData)\n )\n\n if (activeFields.length === 0) return formData\n\n // Detect runtime conflicts among active fields with the same template path\n const pathSeen = new Map<string, FormulaField>()\n const deduped: FormulaField[] = []\n for (const field of activeFields) {\n const key = JSON.stringify(field.path)\n if (pathSeen.has(key)) {\n if (formulaConflictBehavior === 'error') {\n throw new TypeError(\n `[rjsf-formulas] Formula conflict: two active fields share path [${formatPath(field.path)}]`\n )\n } else if (formulaConflictBehavior === 'warn') {\n console.warn(\n `[rjsf-formulas] Formula conflict: two active fields share path [${formatPath(field.path)}]; taking last`\n )\n }\n // Replace the previous entry with the last one (take last)\n const idx = deduped.indexOf(pathSeen.get(key)!)\n deduped[idx] = field\n pathSeen.set(key, field)\n } else {\n pathSeen.set(key, field)\n deduped.push(field)\n }\n }\n\n const contextOptions: BuildContextOptions = { formulaDataKey, formulaPathKey }\n let current = formData\n\n for (let pass = 0; pass < maxConvergencePasses; pass++) {\n const { data: candidate, errors } = await applyAllFormulas(current, deduped, evaluator, contextOptions)\n if (allConverged(current, candidate, deduped)) {\n // Stable — emit error callbacks now that we know this is the final result\n for (const { path, error } of errors) {\n onFormulaError?.(path, error)\n }\n return candidate\n }\n current = candidate\n }\n\n // maxConvergencePasses exceeded — identify and report non-converging fields\n const { data: candidate } = await applyAllFormulas(current, deduped, evaluator, contextOptions)\n const result = structuredClone(candidate)\n\n for (const field of deduped) {\n for (const concretePath of expandPaths(field.path, candidate)) {\n if (!deepEqual(getAt(current, concretePath), getAt(candidate, concretePath))) {\n onFormulaError?.(\n concretePath,\n new Error(\n `[rjsf-formulas] Formula at [${concretePath.join(', ')}] did not converge after ${maxConvergencePasses} passes`\n )\n )\n setAt(result, concretePath, undefined)\n }\n }\n }\n\n return result\n}\n","import { useState, useRef, useEffect, useCallback } from 'react'\nimport type { FormulaField } from './analyzeSchema'\nimport { expandPaths, enrich, deepEqual } from './enrich'\nimport type { BuildContextOptions } from './buildContext'\nimport type { RJSFSchema } from '@rjsf/utils'\n\ntype FieldState = 'idle' | 'running' | 'dirty'\n\nfunction pathKey(path: (string | number)[]): string {\n return JSON.stringify(path)\n}\n\nexport function useAsyncFormulas(\n formData: unknown,\n formulaFields: FormulaField[],\n evaluator: (formula: string, context: object) => unknown | Promise<unknown>,\n debounceMs: number,\n maxConvergencePasses: number,\n onFormulaError: ((path: (string | number)[], error: Error) => void) | undefined,\n onLoadingChange: ((loadingPaths: (string | number)[][]) => void) | undefined,\n contextOptions: BuildContextOptions,\n checkCondition: (condition: RJSFSchema, formData: unknown) => boolean,\n formulaConflictBehavior: 'ignore' | 'warn' | 'error'\n): { enrichedFormData: unknown; handleInput: (newFormData: unknown) => void } {\n const [enrichedFormData, setEnrichedFormData] = useState<unknown>(formData)\n\n const pendingInputRef = useRef<unknown>(formData)\n const lastExternalFormDataRef = useRef<unknown>(formData)\n const fieldStateRef = useRef<Map<string, FieldState>>(new Map())\n const debounceTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null)\n const runningRef = useRef(false)\n\n // Stable refs so callbacks/config don't require restarting the debounce\n const onFormulaErrorRef = useRef(onFormulaError)\n const onLoadingChangeRef = useRef(onLoadingChange)\n const evaluatorRef = useRef(evaluator)\n const formulaFieldsRef = useRef(formulaFields)\n const maxPassesRef = useRef(maxConvergencePasses)\n const contextOptionsRef = useRef(contextOptions)\n const checkConditionRef = useRef(checkCondition)\n const formulaConflictBehaviorRef = useRef(formulaConflictBehavior)\n\n useEffect(() => { onFormulaErrorRef.current = onFormulaError }, [onFormulaError])\n useEffect(() => { onLoadingChangeRef.current = onLoadingChange }, [onLoadingChange])\n useEffect(() => { evaluatorRef.current = evaluator }, [evaluator])\n useEffect(() => { formulaFieldsRef.current = formulaFields }, [formulaFields])\n useEffect(() => { maxPassesRef.current = maxConvergencePasses }, [maxConvergencePasses])\n useEffect(() => { contextOptionsRef.current = contextOptions }, [contextOptions])\n useEffect(() => { checkConditionRef.current = checkCondition }, [checkCondition])\n useEffect(() => { formulaConflictBehaviorRef.current = formulaConflictBehavior }, [formulaConflictBehavior])\n\n // startSequence reads all config from refs so it is stable across renders\n const startSequence = useCallback(() => {\n if (runningRef.current) return\n\n const run = async () => {\n runningRef.current = true\n\n try {\n while (true) {\n const input = pendingInputRef.current\n const fields = formulaFieldsRef.current\n\n // Only report loading for fields whose condition is currently active\n const activeFields = fields.filter(f =>\n f.condition === true || checkConditionRef.current(f.condition as any, input)\n )\n\n // Collect concrete paths for loading reporting\n const concretePaths: (string | number)[][] = []\n for (const field of activeFields) {\n for (const cp of expandPaths(field.path, input)) {\n concretePaths.push(cp)\n }\n }\n\n // Mark all fields running\n const stateMap = fieldStateRef.current\n stateMap.clear()\n for (const cp of concretePaths) stateMap.set(pathKey(cp), 'running')\n if (concretePaths.length > 0) onLoadingChangeRef.current?.(concretePaths)\n\n const result = await enrich(\n input,\n fields,\n evaluatorRef.current,\n maxPassesRef.current,\n onFormulaErrorRef.current,\n contextOptionsRef.current.formulaDataKey,\n contextOptionsRef.current.formulaPathKey,\n checkConditionRef.current,\n formulaConflictBehaviorRef.current\n )\n\n if (isUnmountedRef.current) break\n\n const anyDirty = [...stateMap.values()].some(s => s === 'dirty')\n stateMap.clear()\n\n if (!anyDirty) {\n setEnrichedFormData(result)\n if (concretePaths.length > 0) onLoadingChangeRef.current?.([])\n break\n }\n // New input arrived while evaluating — re-run with pendingInputRef.current\n }\n } finally {\n runningRef.current = false\n }\n }\n\n run()\n }, []) // stable: all dependencies accessed via refs\n\n const handleInput = useCallback(\n (newFormData: unknown) => {\n pendingInputRef.current = newFormData\n\n // Flip any running fields to dirty\n const stateMap = fieldStateRef.current\n for (const [key, state] of stateMap) {\n if (state === 'running') stateMap.set(key, 'dirty')\n }\n\n // Only manage debounce when no sequence is in flight;\n // the while loop picks up dirty fields automatically\n if (!runningRef.current) {\n if (debounceTimerRef.current !== null) clearTimeout(debounceTimerRef.current)\n debounceTimerRef.current = setTimeout(() => {\n debounceTimerRef.current = null\n startSequence()\n }, debounceMs)\n }\n },\n [debounceMs, startSequence]\n )\n\n // React to external formData prop changes.\n // We use a no-dependency effect that runs every render but guards with deep equality\n // to avoid spurious re-evaluations when the parent re-renders with a new object\n // reference but the same value. On first render this always fires (initialises evaluation).\n const hasMountedRef = useRef(false)\n const isUnmountedRef = useRef(false)\n useEffect(() => {\n if (!hasMountedRef.current) {\n // Initial mount: always trigger evaluation\n hasMountedRef.current = true\n lastExternalFormDataRef.current = formData\n handleInput(formData)\n } else if (!deepEqual(formData, lastExternalFormDataRef.current)) {\n // Subsequent renders: only trigger on actual value change\n lastExternalFormDataRef.current = formData\n handleInput(formData)\n }\n }) // runs every render — guarded by deep equality\n\n // Reset lifecycle sentinels on every (re)mount; clean up on unmount.\n // The setup body runs before any debounce fires, so isUnmountedRef is false\n // by the time startSequence checks it.\n useEffect(() => {\n isUnmountedRef.current = false\n return () => {\n isUnmountedRef.current = true\n hasMountedRef.current = false // allow re-init on next mount (React StrictMode)\n if (debounceTimerRef.current !== null) clearTimeout(debounceTimerRef.current)\n }\n }, [])\n\n return { enrichedFormData, handleInput }\n}\n","import type { FormulaField, ArrayIndex } from './analyzeSchema'\nimport { ARRAY_INDEX } from './analyzeSchema'\n\ntype UiSchema = Record<string, unknown>\n\nexport function mergeReadOnly(\n uiSchema: UiSchema | undefined,\n formulaFields: FormulaField[]\n): UiSchema {\n const result: UiSchema = structuredClone(uiSchema ?? {})\n const mixedArrayPaths = findMixedArrayPaths(formulaFields)\n\n for (const field of formulaFields) {\n setReadOnly(result, field.path, mixedArrayPaths)\n }\n\n return result\n}\n\n// Returns a set of serialized parent paths for arrays that have both integer\n// (prefixItems) and ARRAY_INDEX (items) formula fields at the same depth.\nfunction findMixedArrayPaths(formulaFields: FormulaField[]): Set<string> {\n const mixed = new Set<string>()\n\n for (let i = 0; i < formulaFields.length; i++) {\n const path = formulaFields[i].path\n\n for (let depth = 0; depth < path.length; depth++) {\n const seg = path[depth]\n if (typeof seg !== 'number' && seg !== ARRAY_INDEX) continue\n\n const parentKey = serializePath(path.slice(0, depth))\n const isInt = typeof seg === 'number'\n\n const hasSibling = formulaFields.some((f, j) => {\n if (j === i) return false\n if (f.path.length <= depth) return false\n if (serializePath(f.path.slice(0, depth)) !== parentKey) return false\n const sibling = f.path[depth]\n return isInt ? sibling === ARRAY_INDEX : typeof sibling === 'number'\n })\n\n if (hasSibling) mixed.add(parentKey)\n }\n }\n\n return mixed\n}\n\nfunction serializePath(path: (string | number | ArrayIndex)[]): string {\n return JSON.stringify(path.map(s => (typeof s === 'symbol' ? '__ARRAY_INDEX__' : s)))\n}\n\nfunction setReadOnly(\n uiSchema: UiSchema,\n path: (string | number | ArrayIndex)[],\n mixedArrayPaths: Set<string>,\n traversedPath: (string | number | ArrayIndex)[] = []\n): void {\n if (path.length === 0) {\n uiSchema['ui:readonly'] = true\n return\n }\n\n const [head, ...tail] = path\n\n if (typeof head === 'string') {\n if (!uiSchema[head] || typeof uiSchema[head] !== 'object' || Array.isArray(uiSchema[head])) {\n uiSchema[head] = {}\n }\n setReadOnly(uiSchema[head] as UiSchema, tail, mixedArrayPaths, [...traversedPath, head])\n return\n }\n\n if (typeof head === 'number') {\n // prefixItems tuple slot — use items as array\n if (uiSchema['items'] !== undefined && !Array.isArray(uiSchema['items'])) {\n console.warn('[rjsf-formulas] mergeReadOnly: cannot inject ui:readonly at tuple index because existing uiSchema has items as an object. Skipping.')\n return\n }\n if (!Array.isArray(uiSchema['items'])) {\n uiSchema['items'] = []\n }\n const items = uiSchema['items'] as unknown[]\n if (!items[head] || typeof items[head] !== 'object') {\n items[head] = {}\n }\n setReadOnly(items[head] as UiSchema, tail, mixedArrayPaths, [...traversedPath, head])\n return\n }\n\n // head === ARRAY_INDEX\n const parentKey = serializePath(traversedPath)\n const isMixed = mixedArrayPaths.has(parentKey)\n\n if (isMixed) {\n // Mixed array: ARRAY_INDEX → additionalItems\n if (!uiSchema['additionalItems'] || typeof uiSchema['additionalItems'] !== 'object') {\n uiSchema['additionalItems'] = {}\n }\n setReadOnly(uiSchema['additionalItems'] as UiSchema, tail, mixedArrayPaths, [...traversedPath, head])\n } else {\n // Uniform array: ARRAY_INDEX → items as object\n if (Array.isArray(uiSchema['items'])) {\n console.warn('[rjsf-formulas] mergeReadOnly: cannot inject ui:readonly for uniform array because existing uiSchema has items as an array. Skipping.')\n return\n }\n if (!uiSchema['items'] || typeof uiSchema['items'] !== 'object') {\n uiSchema['items'] = {}\n }\n setReadOnly(uiSchema['items'] as UiSchema, tail, mixedArrayPaths, [...traversedPath, head])\n }\n}\n","import React, { useMemo, useEffect, useRef, useCallback, forwardRef } from 'react'\nimport Form from '@rjsf/core'\nimport type { FormProps, IChangeEvent } from '@rjsf/core'\nimport type { StrictRJSFSchema, RJSFSchema, FormContextType } from '@rjsf/utils'\nimport { analyzeSchema } from './analyzeSchema'\nimport type { FormulaField } from './analyzeSchema'\nimport { useAsyncFormulas } from './useAsyncFormulas'\nimport { mergeReadOnly } from './mergeReadOnly'\nimport type { BuildContextOptions } from './buildContext'\n\n/**\n * Props accepted by {@link FormulaForm}.\n *\n * Extends all standard RJSF `FormProps` with formula-specific configuration.\n * All formula-specific props are optional except `evaluator`.\n */\nexport type FormulaFormProps<\n T = any,\n S extends StrictRJSFSchema = RJSFSchema,\n F extends FormContextType = any\n> = FormProps<T, S, F> & {\n /**\n * Evaluates a formula string against a context object and returns the computed value.\n *\n * @remarks\n * May return a plain value or a `Promise`. For user-supplied formulas, **do not use `eval`**\n * — it allows arbitrary code execution. Prefer a sandboxed evaluator such as\n * [`expr-eval`](https://github.com/silentmatt/expr-eval) or\n * [`mathjs`](https://mathjs.org/). For additional isolation, run the evaluator in a Web Worker.\n *\n * @param formula - The formula string from the schema.\n * @param context - Sibling field values, or full form data in extended mode.\n * @returns The computed value, or a Promise resolving to it.\n */\n evaluator: (formula: string, context: object) => unknown | Promise<unknown>\n\n /**\n * Inner RJSF `Form` component to render.\n * Defaults to `Form` from `@rjsf/core`. Swap to use a themed form\n * (e.g. `Form` from `@rjsf/bootstrap-4`).\n */\n Form?: React.ComponentType<FormProps<T, S, F>>\n\n /** Schema key that marks a field as computed. Defaults to `'x-formula'`. */\n formulaKey?: string\n\n /** Schema key that selects the context mode for a field. Defaults to `'x-formula-context'`. */\n formulaContextKey?: string\n\n /**\n * Key injected into the extended context carrying the full form data.\n * Defaults to `'__formData__'`. Override if a sibling field uses the same name.\n */\n formulaDataKey?: string\n\n /**\n * Key injected into the extended context carrying the field's resolved path.\n * Defaults to `'__path__'`. Override if a sibling field uses the same name.\n */\n formulaPathKey?: string\n\n /**\n * Maximum number of re-evaluation passes triggered by a single input event.\n * Guards against infinite loops from circular formula dependencies. Defaults to `10`.\n */\n maxConvergencePasses?: number\n\n /**\n * Milliseconds to debounce formula evaluation after a user input event. Defaults to `300`.\n * Set to `0` to disable the debounce delay and evaluate on the next event loop tick.\n */\n debounceMs?: number\n\n /**\n * Called when a formula throws during evaluation.\n * @param path - JSON path of the field whose formula failed.\n * @param error - The error thrown by the evaluator.\n */\n onFormulaError?: (path: (string | number)[], error: Error) => void\n\n /**\n * Called whenever the set of currently-evaluating fields changes.\n * Useful for showing per-field loading indicators.\n * @param loadingPaths - Paths of all fields whose evaluations are in progress.\n */\n onLoadingChange?: (loadingPaths: (string | number)[][]) => void\n\n /**\n * What to do when multiple branches of a composition operator (`allOf` at schema-analysis\n * time, or simultaneously-active `oneOf`/`anyOf` branches at evaluation time) define a\n * formula for the same field path.\n * - `'ignore'` — silently take the last definition.\n * - `'warn'` (default) — emit `console.warn` and take the last definition.\n * - `'error'` — throw a `TypeError` synchronously (useful during development).\n */\n formulaConflictBehavior?: 'ignore' | 'warn' | 'error'\n}\n\n/**\n * Drop-in replacement for RJSF's `<Form>` with support for computed fields.\n *\n * @remarks\n * Fields marked with a formula key in the JSON schema are evaluated automatically\n * on every data change and rendered as read-only. The `evaluator` prop receives\n * the formula string and a context object, and returns the computed value.\n *\n * @example\n * ```tsx\n * import { FormulaForm } from '@a-ludi/rjsf-formulas'\n * import validator from '@rjsf/validator-ajv8'\n * import { Parser } from 'expr-eval'\n *\n * const parser = new Parser()\n *\n * const schema = {\n * type: 'object' as const,\n * properties: {\n * price: { type: 'number' as const },\n * quantity: { type: 'number' as const },\n * total: { type: 'number' as const, 'x-formula': 'price * quantity' },\n * },\n * }\n *\n * function MyForm() {\n * return (\n * <FormulaForm\n * schema={schema}\n * validator={validator}\n * evaluator={(formula, ctx) => parser.evaluate(formula, ctx)}\n * />\n * )\n * }\n * ```\n */\nfunction FormulaFormImpl<\n T = any,\n S extends StrictRJSFSchema = RJSFSchema,\n F extends FormContextType = any\n>(props: FormulaFormProps<T, S, F>, ref: React.Ref<Form<T, S, F>>): JSX.Element {\n const {\n schema,\n formData,\n validator,\n uiSchema,\n evaluator,\n Form: InnerForm = Form as React.ComponentType<FormProps<T, S, F>>,\n formulaKey = 'x-formula',\n formulaContextKey = 'x-formula-context',\n formulaDataKey = '__formData__',\n formulaPathKey = '__path__',\n maxConvergencePasses = 10,\n debounceMs = 300,\n onFormulaError,\n onLoadingChange,\n formulaConflictBehavior = 'warn',\n onChange,\n ...rest\n } = props\n\n const formulaFields: FormulaField[] = useMemo(\n () => analyzeSchema(schema as RJSFSchema, { formulaKey, formulaContextKey }),\n [schema, formulaKey, formulaContextKey]\n )\n\n const contextOptions: BuildContextOptions = useMemo(\n () => ({ formulaDataKey, formulaPathKey }),\n [formulaDataKey, formulaPathKey]\n )\n\n const mergedUiSchema = useMemo(\n () => mergeReadOnly(uiSchema as Record<string, unknown> | undefined, formulaFields),\n [uiSchema, formulaFields]\n )\n\n const checkCondition = useCallback(\n (condition: RJSFSchema, formData: unknown) =>\n validator.isValid(condition as any, formData as any, schema as any),\n [validator, schema]\n )\n\n const { enrichedFormData, handleInput } = useAsyncFormulas(\n formData,\n formulaFields,\n evaluator,\n debounceMs,\n maxConvergencePasses,\n onFormulaError,\n onLoadingChange,\n contextOptions,\n checkCondition,\n formulaConflictBehavior\n )\n\n const onChangeRef = useRef(onChange)\n useEffect(() => { onChangeRef.current = onChange }, [onChange])\n\n useEffect(() => {\n if (formulaFields.length === 0) return\n onChangeRef.current?.({ formData: enrichedFormData as T } as IChangeEvent<T, S, F>, undefined)\n }, [enrichedFormData]) // eslint-disable-line react-hooks/exhaustive-deps\n\n const handleChange = (data: IChangeEvent<T, S, F>, id?: string) => {\n handleInput(data.formData)\n onChange?.(data, id)\n }\n\n return (\n <InnerForm\n ref={ref as any}\n {...rest}\n schema={schema}\n validator={validator}\n formData={enrichedFormData as T}\n uiSchema={mergedUiSchema as any}\n onChange={handleChange}\n />\n )\n}\n\nexport const FormulaForm = forwardRef(FormulaFormImpl) as <\n T = any,\n S extends StrictRJSFSchema = RJSFSchema,\n F extends FormContextType = any\n>(props: FormulaFormProps<T, S, F>) => JSX.Element\n"],"names":["ARRAY_INDEX","analyzeSchema","schema","options","formulaKey","formulaContextKey","formulaConflictBehavior","fields","traverse","composeCondition","ambient","branch","ambientAny","resolveContextMode","value","path","formatPath","s","pathKey","applyConflictBehavior","existing","incoming","behavior","key","mergeFields","base","field","existingIndex","f","ambientCondition","rootSchema","schemaAny","resolved","findSchemaDefinition","formula","isArray","propSchema","itemSchema","index","allOfBranches","branchFields","compositionKey","branches","branchCondition","ifSchema","thenSchema","elseSchema","thenCondition","elseCondition","fastDeepEqual","equal","a","b","length","i","keys","buildContext","resolvedPath","candidateFormData","parent","curr","siblings","getAt","data","setAt","expandPaths","templatePath","currentPath","head","rest","arr","results","deepEqual","applyAllFormulas","formData","formulaFields","evaluator","contextOptions","result","tasks","concretePath","context","settled","resolve","errors","outcome","err","allConverged","prev","next","enrich","maxConvergencePasses","onFormulaError","formulaDataKey","formulaPathKey","checkCondition","activeFields","pathSeen","deduped","idx","current","pass","candidate","error","useAsyncFormulas","debounceMs","onLoadingChange","enrichedFormData","setEnrichedFormData","useState","pendingInputRef","useRef","lastExternalFormDataRef","fieldStateRef","debounceTimerRef","runningRef","onFormulaErrorRef","onLoadingChangeRef","evaluatorRef","formulaFieldsRef","maxPassesRef","contextOptionsRef","checkConditionRef","formulaConflictBehaviorRef","useEffect","startSequence","useCallback","input","concretePaths","cp","stateMap","_a","isUnmountedRef","anyDirty","_b","handleInput","newFormData","state","hasMountedRef","mergeReadOnly","uiSchema","mixedArrayPaths","findMixedArrayPaths","setReadOnly","mixed","depth","seg","parentKey","serializePath","isInt","j","sibling","traversedPath","tail","items","FormulaFormImpl","props","ref","validator","InnerForm","Form","onChange","useMemo","mergedUiSchema","condition","onChangeRef","handleChange","id","jsx","FormulaForm","forwardRef"],"mappings":"4LAOaA,EAA6B,OAAO,YAAY,EAmFtD,SAASC,EACdC,EACAC,EACgB,CAChB,MAAMC,GAAaD,GAAA,YAAAA,EAAS,aAAc,YACpCE,GAAoBF,GAAA,YAAAA,EAAS,oBAAqB,oBAClDG,GAA0BH,GAAA,YAAAA,EAAS,0BAA2B,OAC9DI,EAAyB,CAAA,EAC/B,OAAAC,EAASN,EAAQ,CAAA,EAAIK,EAAQH,EAAYC,EAAmBC,EAAyB,GAAMJ,CAAM,EAC1FK,CACT,CASA,SAASE,EAAiBC,EAA4BC,EAAgC,CACpF,GAAID,IAAY,GAAM,OAAOC,EAC7B,MAAMC,EAAaF,EACnB,OAAI,MAAM,QAAQE,EAAW,KAAQ,EAC5B,CAAE,MAAO,CAAC,GAAIA,EAAW,MAA2BD,CAAM,CAAA,EAE5D,CAAE,MAAO,CAACD,EAASC,CAAM,CAAA,CAClC,CAEA,SAASE,GACPC,EACAC,EACa,CACb,OAAID,IAAU,QAAaA,IAAU,WAAmB,WACpDA,IAAU,WAAmB,YACjC,QAAQ,KACN,oDAAoDA,CAAK,cAAcE,EAAWD,CAAI,CAAC,2BAAA,EAElF,WACT,CAEA,SAASC,EAAWD,EAAgD,CAClE,OAAOA,EAAK,IAAIE,GAAM,OAAOA,GAAM,SAAW,MAAQ,OAAOA,CAAC,CAAE,EAAE,KAAK,IAAI,CAC7E,CAEA,SAASC,EAAQH,EAAgD,CAC/D,OAAOA,EAAK,IAAIE,GAAM,OAAOA,GAAM,SAAW,MAAQ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ACV,SAAUwD,EACV,SAAUG,CAAA,CAAA,CAGhB,CAEO,MAAMG,GAAcC,EAAAA,WAAWf,EAAe","x_google_ignoreList":[1]}
package/dist/index.mjs CHANGED
@@ -1,74 +1,74 @@
1
1
  import { findSchemaDefinition as ft } from "@rjsf/utils";
2
2
  import { jsx as ct } from "react/jsx-runtime";
3
- import { useState as it, useRef as g, useEffect as j, useCallback as G, forwardRef as ut, useMemo as X } from "react";
3
+ import { useState as it, useRef as m, useEffect as j, useCallback as G, forwardRef as ut, useMemo as X } from "react";
4
4
  import at from "@rjsf/core";
5
- const J = Symbol("arrayIndex");
6
- function lt(t, e) {
7
- const r = (e == null ? void 0 : e.formulaKey) ?? "x-formula", s = (e == null ? void 0 : e.formulaContextKey) ?? "x-formula-context", n = (e == null ? void 0 : e.formulaConflictBehavior) ?? "warn", o = [];
8
- return x(t, [], o, r, s, n, !0, t), o;
5
+ const K = Symbol("arrayIndex");
6
+ function lt(t, r) {
7
+ const e = (r == null ? void 0 : r.formulaKey) ?? "x-formula", s = (r == null ? void 0 : r.formulaContextKey) ?? "x-formula-context", n = (r == null ? void 0 : r.formulaConflictBehavior) ?? "warn", o = [];
8
+ return O(t, [], o, e, s, n, !0, t), o;
9
9
  }
10
- function Y(t, e) {
11
- if (t === !0) return e;
12
- const r = t;
13
- return Array.isArray(r.allOf) ? { allOf: [...r.allOf, e] } : { allOf: [t, e] };
10
+ function Y(t, r) {
11
+ if (t === !0) return r;
12
+ const e = t;
13
+ return Array.isArray(e.allOf) ? { allOf: [...e.allOf, r] } : { allOf: [t, r] };
14
14
  }
15
- function yt(t, e) {
15
+ function pt(t, r) {
16
16
  return t === void 0 || t === "siblings" ? "siblings" : t === "extended" ? "extended" : (console.warn(
17
- `[rjsf-formulas] Unknown x-formula-context value "${t}" at path [${z(e)}], treating as "siblings"`
17
+ `[rjsf-formulas] Unknown x-formula-context value "${t}" at path [${z(r)}], treating as "siblings"`
18
18
  ), "siblings");
19
19
  }
20
20
  function z(t) {
21
- return t.map((e) => typeof e == "symbol" ? "[*]" : String(e)).join(", ");
21
+ return t.map((r) => typeof r == "symbol" ? "[*]" : String(r)).join(", ");
22
22
  }
23
23
  function H(t) {
24
- return t.map((e) => typeof e == "symbol" ? "[*]" : String(e)).join(".");
24
+ return t.map((r) => typeof r == "symbol" ? "[*]" : String(r)).join(".");
25
25
  }
26
- function pt(t, e, r) {
26
+ function yt(t, r, e) {
27
27
  const s = H(t.path);
28
- if (r === "error")
28
+ if (e === "error")
29
29
  throw new TypeError(
30
- `[rjsf-formulas] Formula conflict at path [${z(t.path)}]: "${t.formula}" vs "${e.formula}". Resolve the conflict or set formulaConflictBehavior to 'ignore' or 'warn'.`
30
+ `[rjsf-formulas] Formula conflict at path [${z(t.path)}]: "${t.formula}" vs "${r.formula}". Resolve the conflict or set formulaConflictBehavior to 'ignore' or 'warn'.`
31
31
  );
32
- r === "warn" && console.warn(
33
- `[rjsf-formulas] Formula conflict at path [${s}]: "${t.formula}" (earlier allOf branch) is overridden by "${e.formula}" (later allOf branch).`
32
+ e === "warn" && console.warn(
33
+ `[rjsf-formulas] Formula conflict at path [${s}]: "${t.formula}" (earlier allOf branch) is overridden by "${r.formula}" (later allOf branch).`
34
34
  );
35
35
  }
36
- function dt(t, e, r) {
37
- for (const s of e) {
36
+ function dt(t, r, e) {
37
+ for (const s of r) {
38
38
  const n = H(s.path), o = t.findIndex((i) => H(i.path) === n);
39
- o !== -1 ? (pt(t[o], s, r), t[o] = s) : t.push(s);
39
+ o !== -1 ? (yt(t[o], s, e), t[o] = s) : t.push(s);
40
40
  }
41
41
  }
42
- function x(t, e, r, s, n, o, i, u) {
42
+ function O(t, r, e, s, n, o, i, u) {
43
43
  const f = t;
44
44
  if (typeof f.$ref == "string") {
45
45
  const c = ft(f.$ref, u);
46
- x(c, e, r, s, n, o, i, u);
46
+ O(c, r, e, s, n, o, i, u);
47
47
  return;
48
48
  }
49
49
  if (s in t) {
50
50
  const c = f[s];
51
51
  if (typeof c != "string") {
52
52
  console.warn(
53
- `[rjsf-formulas] Formula at path [${z(e)}] is not a string (got ${typeof c}), skipping.`
53
+ `[rjsf-formulas] Formula at path [${z(r)}] is not a string (got ${typeof c}), skipping.`
54
54
  );
55
55
  return;
56
56
  }
57
- r.push({
58
- path: e,
57
+ e.push({
58
+ path: r,
59
59
  formula: c,
60
- contextMode: yt(f[n], e),
60
+ contextMode: pt(f[n], r),
61
61
  condition: i
62
62
  });
63
63
  return;
64
64
  }
65
- const l = t.type === "array" || t.type == null && (Array.isArray(f.prefixItems) || t.items != null && !Array.isArray(t.items));
65
+ const l = t.type === "array" || t.type == null && (Array.isArray(f.prefixItems) || t.items != null);
66
66
  if (t.properties && !l)
67
67
  for (const [c, a] of Object.entries(t.properties))
68
- x(
68
+ O(
69
69
  a,
70
- [...e, c],
71
- r,
70
+ [...r, c],
71
+ e,
72
72
  s,
73
73
  n,
74
74
  o,
@@ -76,11 +76,13 @@ function x(t, e, r, s, n, o, i, u) {
76
76
  u
77
77
  );
78
78
  if (l && (Array.isArray(f.prefixItems) && f.prefixItems.forEach((a, d) => {
79
- x(a, [...e, d], r, s, n, o, i, u);
80
- }), t.items && !Array.isArray(t.items) && x(
79
+ O(a, [...r, d], e, s, n, o, i, u);
80
+ }), Array.isArray(t.items) && t.items.forEach((c, a) => {
81
+ O(c, [...r, a], e, s, n, o, i, u);
82
+ }), t.items && !Array.isArray(t.items) && O(
81
83
  t.items,
82
- [...e, J],
83
- r,
84
+ [...r, K],
85
+ e,
84
86
  s,
85
87
  n,
86
88
  o,
@@ -90,116 +92,116 @@ function x(t, e, r, s, n, o, i, u) {
90
92
  const c = f.allOf;
91
93
  for (const a of c) {
92
94
  const d = [];
93
- x(a, e, d, s, n, o, i, u), dt(r, d, o);
95
+ O(a, r, d, s, n, o, i, u), dt(e, d, o);
94
96
  }
95
97
  }
96
98
  for (const c of ["oneOf", "anyOf"])
97
99
  if (Array.isArray(f[c])) {
98
100
  const a = f[c];
99
101
  for (const d of a) {
100
- const m = Y(i, d);
101
- x(d, e, r, s, n, o, m, u);
102
+ const g = Y(i, d);
103
+ O(d, r, e, s, n, o, g, u);
102
104
  }
103
105
  }
104
106
  if ("if" in f) {
105
107
  const c = f.if, a = f.then, d = f.else;
106
108
  if (s in c && console.warn(
107
- `[rjsf-formulas] Formula key "${s}" found inside an "if" schema at path [${z(e)}]. The "if" schema is a validation predicate and is never rendered — the formula will be ignored.`
109
+ `[rjsf-formulas] Formula key "${s}" found inside an "if" schema at path [${z(r)}]. The "if" schema is a validation predicate and is never rendered — the formula will be ignored.`
108
110
  ), a !== void 0) {
109
- const m = Y(i, c);
110
- x(a, e, r, s, n, o, m, u);
111
+ const g = Y(i, c);
112
+ O(a, r, e, s, n, o, g, u);
111
113
  }
112
114
  if (d !== void 0) {
113
- const m = Y(i, { not: c });
114
- x(d, e, r, s, n, o, m, u);
115
+ const g = Y(i, { not: c });
116
+ O(d, r, e, s, n, o, g, u);
115
117
  }
116
118
  }
117
119
  }
118
- function mt(t) {
120
+ function gt(t) {
119
121
  return t && t.__esModule && Object.prototype.hasOwnProperty.call(t, "default") ? t.default : t;
120
122
  }
121
123
  var V, C;
122
- function gt() {
123
- return C || (C = 1, V = function t(e, r) {
124
- if (e === r) return !0;
125
- if (e && r && typeof e == "object" && typeof r == "object") {
126
- if (e.constructor !== r.constructor) return !1;
124
+ function mt() {
125
+ return C || (C = 1, V = function t(r, e) {
126
+ if (r === e) return !0;
127
+ if (r && e && typeof r == "object" && typeof e == "object") {
128
+ if (r.constructor !== e.constructor) return !1;
127
129
  var s, n, o;
128
- if (Array.isArray(e)) {
129
- if (s = e.length, s != r.length) return !1;
130
+ if (Array.isArray(r)) {
131
+ if (s = r.length, s != e.length) return !1;
130
132
  for (n = s; n-- !== 0; )
131
- if (!t(e[n], r[n])) return !1;
133
+ if (!t(r[n], e[n])) return !1;
132
134
  return !0;
133
135
  }
134
- if (e.constructor === RegExp) return e.source === r.source && e.flags === r.flags;
135
- if (e.valueOf !== Object.prototype.valueOf) return e.valueOf() === r.valueOf();
136
- if (e.toString !== Object.prototype.toString) return e.toString() === r.toString();
137
- if (o = Object.keys(e), s = o.length, s !== Object.keys(r).length) return !1;
136
+ if (r.constructor === RegExp) return r.source === e.source && r.flags === e.flags;
137
+ if (r.valueOf !== Object.prototype.valueOf) return r.valueOf() === e.valueOf();
138
+ if (r.toString !== Object.prototype.toString) return r.toString() === e.toString();
139
+ if (o = Object.keys(r), s = o.length, s !== Object.keys(e).length) return !1;
138
140
  for (n = s; n-- !== 0; )
139
- if (!Object.prototype.hasOwnProperty.call(r, o[n])) return !1;
141
+ if (!Object.prototype.hasOwnProperty.call(e, o[n])) return !1;
140
142
  for (n = s; n-- !== 0; ) {
141
143
  var i = o[n];
142
- if (!t(e[i], r[i])) return !1;
144
+ if (!t(r[i], e[i])) return !1;
143
145
  }
144
146
  return !0;
145
147
  }
146
- return e !== e && r !== r;
148
+ return r !== r && e !== e;
147
149
  }), V;
148
150
  }
149
- var ht = gt();
150
- const jt = /* @__PURE__ */ mt(ht);
151
- function wt(t, e, r, s) {
152
- const o = e.slice(0, -1).reduce((u, f) => {
151
+ var ht = mt();
152
+ const jt = /* @__PURE__ */ gt(ht);
153
+ function wt(t, r, e, s) {
154
+ const o = r.slice(0, -1).reduce((u, f) => {
153
155
  if (!(u == null || typeof u != "object"))
154
156
  return u[f];
155
- }, r), i = o != null && typeof o == "object" && !Array.isArray(o) ? { ...o } : {};
157
+ }, e), i = o != null && typeof o == "object" && !Array.isArray(o) ? { ...o } : {};
156
158
  return t.contextMode === "extended" ? ((s.formulaDataKey in i || s.formulaPathKey in i) && console.warn(
157
159
  `[rjsf-formulas] Extended context key collision: sibling field named "${s.formulaDataKey in i ? s.formulaDataKey : s.formulaPathKey}" will be overwritten by the injected context. Use formulaDataKey/formulaPathKey props to choose a different key.`
158
160
  ), {
159
161
  ...i,
160
- [s.formulaDataKey]: r,
161
- [s.formulaPathKey]: [...e]
162
+ [s.formulaDataKey]: e,
163
+ [s.formulaPathKey]: [...r]
162
164
  }) : i;
163
165
  }
164
166
  function tt(t) {
165
- return t.map((e) => typeof e == "symbol" ? "[*]" : String(e)).join(", ");
167
+ return t.map((r) => typeof r == "symbol" ? "[*]" : String(r)).join(", ");
166
168
  }
167
- function k(t, e) {
168
- return e.reduce((r, s) => {
169
- if (!(r == null || typeof r != "object"))
170
- return r[s];
169
+ function k(t, r) {
170
+ return r.reduce((e, s) => {
171
+ if (!(e == null || typeof e != "object"))
172
+ return e[s];
171
173
  }, t);
172
174
  }
173
- function Q(t, e, r) {
174
- if (e.length === 0) return;
175
- const s = k(t, e.slice(0, -1));
176
- s != null && typeof s == "object" && (s[e[e.length - 1]] = r);
175
+ function Q(t, r, e) {
176
+ if (r.length === 0) return;
177
+ const s = k(t, r.slice(0, -1));
178
+ s != null && typeof s == "object" && (s[r[r.length - 1]] = e);
177
179
  }
178
- function D(t, e, r = []) {
179
- if (t.length === 0) return [r];
180
+ function D(t, r, e = []) {
181
+ if (t.length === 0) return [e];
180
182
  const [s, ...n] = t;
181
- if (s === J) {
182
- const o = k(e, r);
183
+ if (s === K) {
184
+ const o = k(r, e);
183
185
  if (!Array.isArray(o)) return [];
184
186
  const i = [];
185
187
  for (let u = 0; u < o.length; u++)
186
- i.push(...D(n, e, [...r, u]));
188
+ i.push(...D(n, r, [...e, u]));
187
189
  return i;
188
190
  }
189
- return D(n, e, [...r, s]);
191
+ return D(n, r, [...e, s]);
190
192
  }
191
- function Z(t, e) {
192
- return jt(t, e);
193
+ function Z(t, r) {
194
+ return jt(t, r);
193
195
  }
194
- async function et(t, e, r, s) {
196
+ async function rt(t, r, e, s) {
195
197
  const n = structuredClone(t), o = [];
196
- for (const f of e)
198
+ for (const f of r)
197
199
  for (const l of D(f.path, n)) {
198
200
  const c = wt(f, l, n, s);
199
201
  o.push({ field: f, concretePath: l, context: c });
200
202
  }
201
203
  const i = await Promise.allSettled(
202
- o.map(({ field: f, context: l }) => new Promise((c) => c(r(f.formula, l))))
204
+ o.map(({ field: f, context: l }) => new Promise((c) => c(e(f.formula, l))))
203
205
  ), u = [];
204
206
  for (let f = 0; f < o.length; f++) {
205
207
  const { concretePath: l } = o[f], c = i[f];
@@ -212,169 +214,169 @@ async function et(t, e, r, s) {
212
214
  }
213
215
  return { data: n, errors: u };
214
216
  }
215
- function At(t, e, r) {
216
- for (const s of r)
217
- for (const n of D(s.path, e))
218
- if (!Z(k(t, n), k(e, n)))
217
+ function At(t, r, e) {
218
+ for (const s of e)
219
+ for (const n of D(s.path, r))
220
+ if (!Z(k(t, n), k(r, n)))
219
221
  return !1;
220
222
  return !0;
221
223
  }
222
- async function Ot(t, e, r, s, n, o, i, u, f) {
223
- const l = e.filter(
224
- (p) => p.condition === !0 || u(p.condition, t)
224
+ async function Ot(t, r, e, s, n, o, i, u, f) {
225
+ const l = r.filter(
226
+ (y) => y.condition === !0 || u(y.condition, t)
225
227
  );
226
228
  if (l.length === 0) return t;
227
229
  const c = /* @__PURE__ */ new Map(), a = [];
228
- for (const p of l) {
229
- const y = JSON.stringify(p.path);
230
- if (c.has(y)) {
230
+ for (const y of l) {
231
+ const p = JSON.stringify(y.path);
232
+ if (c.has(p)) {
231
233
  if (f === "error")
232
234
  throw new TypeError(
233
- `[rjsf-formulas] Formula conflict: two active fields share path [${tt(p.path)}]`
235
+ `[rjsf-formulas] Formula conflict: two active fields share path [${tt(y.path)}]`
234
236
  );
235
237
  f === "warn" && console.warn(
236
- `[rjsf-formulas] Formula conflict: two active fields share path [${tt(p.path)}]; taking last`
238
+ `[rjsf-formulas] Formula conflict: two active fields share path [${tt(y.path)}]; taking last`
237
239
  );
238
- const h = a.indexOf(c.get(y));
239
- a[h] = p, c.set(y, p);
240
+ const h = a.indexOf(c.get(p));
241
+ a[h] = y, c.set(p, y);
240
242
  } else
241
- c.set(y, p), a.push(p);
243
+ c.set(p, y), a.push(y);
242
244
  }
243
245
  const d = { formulaDataKey: o, formulaPathKey: i };
244
- let m = t;
245
- for (let p = 0; p < s; p++) {
246
- const { data: y, errors: h } = await et(m, a, r, d);
247
- if (At(m, y, a)) {
248
- for (const { path: O, error: _ } of h)
249
- n == null || n(O, _);
250
- return y;
246
+ let g = t;
247
+ for (let y = 0; y < s; y++) {
248
+ const { data: p, errors: h } = await rt(g, a, e, d);
249
+ if (At(g, p, a)) {
250
+ for (const { path: x, error: _ } of h)
251
+ n == null || n(x, _);
252
+ return p;
251
253
  }
252
- m = y;
254
+ g = p;
253
255
  }
254
- const { data: b } = await et(m, a, r, d), w = structuredClone(b);
255
- for (const p of a)
256
- for (const y of D(p.path, b))
257
- Z(k(m, y), k(b, y)) || (n == null || n(
258
- y,
256
+ const { data: b } = await rt(g, a, e, d), w = structuredClone(b);
257
+ for (const y of a)
258
+ for (const p of D(y.path, b))
259
+ Z(k(g, p), k(b, p)) || (n == null || n(
260
+ p,
259
261
  new Error(
260
- `[rjsf-formulas] Formula at [${y.join(", ")}] did not converge after ${s} passes`
262
+ `[rjsf-formulas] Formula at [${p.join(", ")}] did not converge after ${s} passes`
261
263
  )
262
- ), Q(w, y, void 0));
264
+ ), Q(w, p, void 0));
263
265
  return w;
264
266
  }
265
267
  function xt(t) {
266
268
  return JSON.stringify(t);
267
269
  }
268
- function bt(t, e, r, s, n, o, i, u, f, l) {
269
- const [c, a] = it(t), d = g(t), m = g(t), b = g(/* @__PURE__ */ new Map()), w = g(null), p = g(!1), y = g(o), h = g(i), O = g(r), _ = g(e), T = g(n), F = g(u), $ = g(f), S = g(l);
270
+ function bt(t, r, e, s, n, o, i, u, f, l) {
271
+ const [c, a] = it(t), d = m(t), g = m(t), b = m(/* @__PURE__ */ new Map()), w = m(null), y = m(!1), p = m(o), h = m(i), x = m(e), _ = m(r), T = m(n), F = m(u), $ = m(f), N = m(l);
270
272
  j(() => {
271
- y.current = o;
273
+ p.current = o;
272
274
  }, [o]), j(() => {
273
275
  h.current = i;
274
276
  }, [i]), j(() => {
275
- O.current = r;
276
- }, [r]), j(() => {
277
- _.current = e;
277
+ x.current = e;
278
278
  }, [e]), j(() => {
279
+ _.current = r;
280
+ }, [r]), j(() => {
279
281
  T.current = n;
280
282
  }, [n]), j(() => {
281
283
  F.current = u;
282
284
  }, [u]), j(() => {
283
285
  $.current = f;
284
286
  }, [f]), j(() => {
285
- S.current = l;
287
+ N.current = l;
286
288
  }, [l]);
287
- const v = G(() => {
288
- if (p.current) return;
289
+ const I = G(() => {
290
+ if (y.current) return;
289
291
  (async () => {
290
- var M, N;
291
- p.current = !0;
292
+ var M, U;
293
+ y.current = !0;
292
294
  try {
293
295
  for (; ; ) {
294
- const E = d.current, L = _.current, rt = L.filter(
296
+ const E = d.current, B = _.current, et = B.filter(
295
297
  (R) => R.condition === !0 || $.current(R.condition, E)
296
298
  ), q = [];
297
- for (const R of rt)
299
+ for (const R of et)
298
300
  for (const ot of D(R.path, E))
299
301
  q.push(ot);
300
- const U = b.current;
301
- U.clear();
302
- for (const R of q) U.set(xt(R), "running");
302
+ const J = b.current;
303
+ J.clear();
304
+ for (const R of q) J.set(xt(R), "running");
303
305
  q.length > 0 && ((M = h.current) == null || M.call(h, q));
304
306
  const nt = await Ot(
305
307
  E,
306
- L,
307
- O.current,
308
+ B,
309
+ x.current,
308
310
  T.current,
309
- y.current,
311
+ p.current,
310
312
  F.current.formulaDataKey,
311
313
  F.current.formulaPathKey,
312
314
  $.current,
313
- S.current
315
+ N.current
314
316
  );
315
- if (I.current) break;
316
- const st = [...U.values()].some((R) => R === "dirty");
317
- if (U.clear(), !st) {
318
- a(nt), q.length > 0 && ((N = h.current) == null || N.call(h, []));
317
+ if (v.current) break;
318
+ const st = [...J.values()].some((R) => R === "dirty");
319
+ if (J.clear(), !st) {
320
+ a(nt), q.length > 0 && ((U = h.current) == null || U.call(h, []));
319
321
  break;
320
322
  }
321
323
  }
322
324
  } finally {
323
- p.current = !1;
325
+ y.current = !1;
324
326
  }
325
327
  })();
326
- }, []), K = G(
327
- (B) => {
328
- d.current = B;
328
+ }, []), S = G(
329
+ (L) => {
330
+ d.current = L;
329
331
  const M = b.current;
330
- for (const [N, E] of M)
331
- E === "running" && M.set(N, "dirty");
332
- p.current || (w.current !== null && clearTimeout(w.current), w.current = setTimeout(() => {
333
- w.current = null, v();
332
+ for (const [U, E] of M)
333
+ E === "running" && M.set(U, "dirty");
334
+ y.current || (w.current !== null && clearTimeout(w.current), w.current = setTimeout(() => {
335
+ w.current = null, I();
334
336
  }, s));
335
337
  },
336
- [s, v]
337
- ), A = g(!1), I = g(!1);
338
+ [s, I]
339
+ ), A = m(!1), v = m(!1);
338
340
  return j(() => {
339
- A.current ? Z(t, m.current) || (m.current = t, K(t)) : (A.current = !0, m.current = t, K(t));
340
- }), j(() => (I.current = !1, () => {
341
- I.current = !0, A.current = !1, w.current !== null && clearTimeout(w.current);
342
- }), []), { enrichedFormData: c, handleInput: K };
341
+ A.current ? Z(t, g.current) || (g.current = t, S(t)) : (A.current = !0, g.current = t, S(t));
342
+ }), j(() => (v.current = !1, () => {
343
+ v.current = !0, A.current = !1, w.current !== null && clearTimeout(w.current);
344
+ }), []), { enrichedFormData: c, handleInput: S };
343
345
  }
344
- function Rt(t, e) {
345
- const r = structuredClone(t ?? {}), s = $t(e);
346
- for (const n of e)
347
- P(r, n.path, s);
348
- return r;
346
+ function Rt(t, r) {
347
+ const e = structuredClone(t ?? {}), s = $t(r);
348
+ for (const n of r)
349
+ P(e, n.path, s);
350
+ return e;
349
351
  }
350
352
  function $t(t) {
351
- const e = /* @__PURE__ */ new Set();
352
- for (let r = 0; r < t.length; r++) {
353
- const s = t[r].path;
353
+ const r = /* @__PURE__ */ new Set();
354
+ for (let e = 0; e < t.length; e++) {
355
+ const s = t[e].path;
354
356
  for (let n = 0; n < s.length; n++) {
355
357
  const o = s[n];
356
- if (typeof o != "number" && o !== J) continue;
358
+ if (typeof o != "number" && o !== K) continue;
357
359
  const i = W(s.slice(0, n)), u = typeof o == "number";
358
360
  t.some((l, c) => {
359
- if (c === r || l.path.length <= n || W(l.path.slice(0, n)) !== i) return !1;
361
+ if (c === e || l.path.length <= n || W(l.path.slice(0, n)) !== i) return !1;
360
362
  const a = l.path[n];
361
- return u ? a === J : typeof a == "number";
362
- }) && e.add(i);
363
+ return u ? a === K : typeof a == "number";
364
+ }) && r.add(i);
363
365
  }
364
366
  }
365
- return e;
367
+ return r;
366
368
  }
367
369
  function W(t) {
368
- return JSON.stringify(t.map((e) => typeof e == "symbol" ? "__ARRAY_INDEX__" : e));
370
+ return JSON.stringify(t.map((r) => typeof r == "symbol" ? "__ARRAY_INDEX__" : r));
369
371
  }
370
- function P(t, e, r, s = []) {
371
- if (e.length === 0) {
372
+ function P(t, r, e, s = []) {
373
+ if (r.length === 0) {
372
374
  t["ui:readonly"] = !0;
373
375
  return;
374
376
  }
375
- const [n, ...o] = e;
377
+ const [n, ...o] = r;
376
378
  if (typeof n == "string") {
377
- (!t[n] || typeof t[n] != "object" || Array.isArray(t[n])) && (t[n] = {}), P(t[n], o, r, [...s, n]);
379
+ (!t[n] || typeof t[n] != "object" || Array.isArray(t[n])) && (t[n] = {}), P(t[n], o, e, [...s, n]);
378
380
  return;
379
381
  }
380
382
  if (typeof n == "number") {
@@ -384,23 +386,23 @@ function P(t, e, r, s = []) {
384
386
  }
385
387
  Array.isArray(t.items) || (t.items = []);
386
388
  const f = t.items;
387
- (!f[n] || typeof f[n] != "object") && (f[n] = {}), P(f[n], o, r, [...s, n]);
389
+ (!f[n] || typeof f[n] != "object") && (f[n] = {}), P(f[n], o, e, [...s, n]);
388
390
  return;
389
391
  }
390
392
  const i = W(s);
391
- if (r.has(i))
392
- (!t.additionalItems || typeof t.additionalItems != "object") && (t.additionalItems = {}), P(t.additionalItems, o, r, [...s, n]);
393
+ if (e.has(i))
394
+ (!t.additionalItems || typeof t.additionalItems != "object") && (t.additionalItems = {}), P(t.additionalItems, o, e, [...s, n]);
393
395
  else {
394
396
  if (Array.isArray(t.items)) {
395
397
  console.warn("[rjsf-formulas] mergeReadOnly: cannot inject ui:readonly for uniform array because existing uiSchema has items as an array. Skipping.");
396
398
  return;
397
399
  }
398
- (!t.items || typeof t.items != "object") && (t.items = {}), P(t.items, o, r, [...s, n]);
400
+ (!t.items || typeof t.items != "object") && (t.items = {}), P(t.items, o, e, [...s, n]);
399
401
  }
400
402
  }
401
- function vt(t, e) {
403
+ function It(t, r) {
402
404
  const {
403
- schema: r,
405
+ schema: e,
404
406
  formData: s,
405
407
  validator: n,
406
408
  uiSchema: o,
@@ -411,58 +413,59 @@ function vt(t, e) {
411
413
  formulaDataKey: c = "__formData__",
412
414
  formulaPathKey: a = "__path__",
413
415
  maxConvergencePasses: d = 10,
414
- debounceMs: m = 300,
416
+ debounceMs: g = 300,
415
417
  onFormulaError: b,
416
418
  onLoadingChange: w,
417
- formulaConflictBehavior: p = "warn",
418
- onChange: y,
419
+ formulaConflictBehavior: y = "warn",
420
+ onChange: p,
419
421
  ...h
420
- } = t, O = X(
421
- () => lt(r, { formulaKey: f, formulaContextKey: l }),
422
- [r, f, l]
422
+ } = t, x = X(
423
+ () => lt(e, { formulaKey: f, formulaContextKey: l }),
424
+ [e, f, l]
423
425
  ), _ = X(
424
426
  () => ({ formulaDataKey: c, formulaPathKey: a }),
425
427
  [c, a]
426
428
  ), T = X(
427
- () => Rt(o, O),
428
- [o, O]
429
+ () => Rt(o, x),
430
+ [o, x]
429
431
  ), F = G(
430
- (A, I) => n.isValid(A, I, r),
431
- [n, r]
432
- ), { enrichedFormData: $, handleInput: S } = bt(
432
+ (A, v) => n.isValid(A, v, e),
433
+ [n, e]
434
+ ), { enrichedFormData: $, handleInput: N } = bt(
433
435
  s,
434
- O,
436
+ x,
435
437
  i,
436
- m,
438
+ g,
437
439
  d,
438
440
  b,
439
441
  w,
440
442
  _,
441
443
  F,
442
- p
443
- ), v = g(y);
444
+ y
445
+ ), I = m(p);
444
446
  return j(() => {
445
- v.current = y;
446
- }, [y]), j(() => {
447
+ I.current = p;
448
+ }, [p]), j(() => {
447
449
  var A;
448
- O.length !== 0 && ((A = v.current) == null || A.call(v, { formData: $ }, void 0));
450
+ x.length !== 0 && ((A = I.current) == null || A.call(I, { formData: $ }, void 0));
449
451
  }, [$]), /* @__PURE__ */ ct(
450
452
  u,
451
453
  {
452
- ref: e,
454
+ ref: r,
453
455
  ...h,
454
- schema: r,
456
+ schema: e,
455
457
  validator: n,
456
458
  formData: $,
457
459
  uiSchema: T,
458
- onChange: (A, I) => {
459
- S(A.formData), y == null || y(A, I);
460
+ onChange: (A, v) => {
461
+ N(A.formData), p == null || p(A, v);
460
462
  }
461
463
  }
462
464
  );
463
465
  }
464
- const Ft = ut(vt);
466
+ const Ft = ut(It);
465
467
  export {
466
468
  Ft as FormulaForm,
467
469
  lt as analyzeSchema
468
470
  };
471
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sources":["../src/analyzeSchema.ts","../node_modules/fast-deep-equal/index.js","../src/buildContext.ts","../src/enrich.ts","../src/useAsyncFormulas.ts","../src/mergeReadOnly.ts","../src/FormulaForm.tsx"],"sourcesContent":["import type { RJSFSchema } from '@rjsf/utils'\nimport { findSchemaDefinition } from '@rjsf/utils'\n\n/**\n * Sentinel used in formula field paths to represent a uniform array item position.\n * @internal\n */\nexport const ARRAY_INDEX: unique symbol = Symbol('arrayIndex')\n\n/** @internal */\nexport type ArrayIndex = typeof ARRAY_INDEX\n\n/**\n * Controls which values are injected into the formula evaluation context.\n *\n * - `'siblings'` (default): only the sibling fields of the computed field are available by name.\n * - `'extended'`: full form data and the field's resolved path are injected alongside sibling\n * values, under the keys configured by `formulaDataKey` and `formulaPathKey`.\n *\n * Set via the `x-formula-context` schema key (or the `formulaContextKey` prop).\n */\nexport type ContextMode = 'siblings' | 'extended'\n\n/**\n * Describes a single computed field discovered by {@link analyzeSchema}.\n */\nexport type FormulaField = {\n /** JSON path to the field within the form data. Uniform array item positions are represented by {@link ARRAY_INDEX}. */\n path: (string | number | ArrayIndex)[]\n /** The raw formula string from the schema. */\n formula: string\n /** Which values are available when evaluating this field's formula. */\n contextMode: ContextMode\n /**\n * The schema condition under which this formula is active.\n *\n * - `true` — always active (fields from `properties`, `items`, `prefixItems`, or `allOf` branches).\n * - `RJSFSchema` — a conditional schema (a `oneOf`/`anyOf` branch condition, possibly composed\n * via `{ allOf: [...] }` for nested branches).\n */\n condition: RJSFSchema | true\n}\n\n/**\n * Options for {@link analyzeSchema}.\n */\nexport type AnalyzeSchemaOptions = {\n /** Schema key that marks a field as computed. Defaults to `'x-formula'`. */\n formulaKey?: string\n /** Schema key that selects the context mode for a computed field. Defaults to `'x-formula-context'`. */\n formulaContextKey?: string\n /**\n * What to do when multiple `allOf` branches define a formula for the same path.\n *\n * - `'ignore'`: silently take the last definition.\n * - `'warn'` (default): emit `console.warn` and take the last definition.\n * - `'error'`: throw a `TypeError` synchronously.\n */\n formulaConflictBehavior?: 'ignore' | 'warn' | 'error'\n}\n\n/**\n * Scans a JSON Schema and returns descriptors for every field that carries a formula key.\n *\n * @remarks\n * Traversal is depth-first. `allOf`, `$ref`, `oneOf`, and `anyOf` are all supported.\n * `allOf` branches are merged with conflict detection. `oneOf`/`anyOf` branches are each\n * recursed and fields are collected with the branch schema as the `condition`. Nested\n * `oneOf`/`anyOf` conditions are composed via `{ allOf: [...] }`. `$ref` is resolved\n * synchronously using `findSchemaDefinition` (external refs will throw).\n *\n * @param schema - The root RJSF schema to scan.\n * @param options - Optional key overrides for locating formulas in the schema.\n * @returns An array of {@link FormulaField} descriptors, one per computed field found.\n *\n * @example\n * ```ts\n * import { analyzeSchema } from '@a-ludi/rjsf-formulas'\n *\n * const fields = analyzeSchema({\n * type: 'object',\n * properties: {\n * price: { type: 'number' },\n * total: { type: 'number', 'x-formula': 'price * 2' },\n * },\n * })\n * // fields[0].path => ['total']\n * // fields[0].formula => 'price * 2'\n * ```\n */\nexport function analyzeSchema(\n schema: RJSFSchema,\n options?: AnalyzeSchemaOptions\n): FormulaField[] {\n const formulaKey = options?.formulaKey ?? 'x-formula'\n const formulaContextKey = options?.formulaContextKey ?? 'x-formula-context'\n const formulaConflictBehavior = options?.formulaConflictBehavior ?? 'warn'\n const fields: FormulaField[] = []\n traverse(schema, [], fields, formulaKey, formulaContextKey, formulaConflictBehavior, true, schema)\n return fields\n}\n\n/**\n * Compose an ambient condition with a new branch schema.\n *\n * - If `ambient === true`: returns `branch` directly (no wrapping needed).\n * - If `ambient` already has an `allOf`: appends `branch` to that array.\n * - Otherwise: wraps both in `{ allOf: [ambient, branch] }`.\n */\nfunction composeCondition(ambient: RJSFSchema | true, branch: RJSFSchema): RJSFSchema {\n if (ambient === true) return branch\n const ambientAny = ambient as Record<string, unknown>\n if (Array.isArray(ambientAny['allOf'])) {\n return { allOf: [...(ambientAny['allOf'] as RJSFSchema[]), branch] }\n }\n return { allOf: [ambient, branch] }\n}\n\nfunction resolveContextMode(\n value: unknown,\n path: (string | number | ArrayIndex)[]\n): ContextMode {\n if (value === undefined || value === 'siblings') return 'siblings'\n if (value === 'extended') return 'extended'\n console.warn(\n `[rjsf-formulas] Unknown x-formula-context value \"${value}\" at path [${formatPath(path)}], treating as \"siblings\"`\n )\n return 'siblings'\n}\n\nfunction formatPath(path: (string | number | ArrayIndex)[]): string {\n return path.map(s => (typeof s === 'symbol' ? '[*]' : String(s))).join(', ')\n}\n\nfunction pathKey(path: (string | number | ArrayIndex)[]): string {\n return path.map(s => (typeof s === 'symbol' ? '[*]' : String(s))).join('.')\n}\n\nfunction applyConflictBehavior(\n existing: FormulaField,\n incoming: FormulaField,\n behavior: 'ignore' | 'warn' | 'error'\n): void {\n const key = pathKey(existing.path)\n if (behavior === 'error') {\n throw new TypeError(\n `[rjsf-formulas] Formula conflict at path [${formatPath(existing.path)}]: \"${existing.formula}\" vs \"${incoming.formula}\". Resolve the conflict or set formulaConflictBehavior to 'ignore' or 'warn'.`\n )\n }\n if (behavior === 'warn') {\n console.warn(\n `[rjsf-formulas] Formula conflict at path [${key}]: \"${existing.formula}\" (earlier allOf branch) is overridden by \"${incoming.formula}\" (later allOf branch).`\n )\n }\n}\n\nfunction mergeFields(\n base: FormulaField[],\n incoming: FormulaField[],\n behavior: 'ignore' | 'warn' | 'error'\n): void {\n for (const field of incoming) {\n const key = pathKey(field.path)\n const existingIndex = base.findIndex(f => pathKey(f.path) === key)\n if (existingIndex !== -1) {\n applyConflictBehavior(base[existingIndex], field, behavior)\n base[existingIndex] = field\n } else {\n base.push(field)\n }\n }\n}\n\nfunction traverse(\n schema: RJSFSchema,\n path: (string | number | ArrayIndex)[],\n fields: FormulaField[],\n formulaKey: string,\n formulaContextKey: string,\n formulaConflictBehavior: 'ignore' | 'warn' | 'error',\n ambientCondition: RJSFSchema | true,\n rootSchema: RJSFSchema\n): void {\n const schemaAny = schema as Record<string, unknown>\n\n // $ref — resolve and continue traversal with the same ambientCondition\n if (typeof schemaAny['$ref'] === 'string') {\n const resolved = findSchemaDefinition(schemaAny['$ref'] as string, rootSchema)\n traverse(resolved, path, fields, formulaKey, formulaContextKey, formulaConflictBehavior, ambientCondition, rootSchema)\n return\n }\n\n // Rule 1: computed field — record and stop\n if (formulaKey in schema) {\n const formula = schemaAny[formulaKey]\n if (typeof formula !== 'string') {\n console.warn(\n `[rjsf-formulas] Formula at path [${formatPath(path)}] is not a string (got ${typeof formula}), skipping.`\n )\n return\n }\n fields.push({\n path,\n formula,\n contextMode: resolveContextMode(schemaAny[formulaContextKey], path),\n condition: ambientCondition,\n })\n return\n }\n\n // Rule 2: object — recurse into properties (type: 'object' is implicit when properties are present)\n const isArray = schema.type === 'array' ||\n (schema.type == null && (Array.isArray(schemaAny['prefixItems']) || schema.items != null))\n if (schema.properties && !isArray) {\n for (const [key, propSchema] of Object.entries(schema.properties)) {\n traverse(\n propSchema as RJSFSchema,\n [...path, key],\n fields,\n formulaKey,\n formulaContextKey,\n formulaConflictBehavior,\n ambientCondition,\n rootSchema\n )\n }\n }\n\n // Rule 3: array — recurse into prefixItems and/or items (type: 'array' is implicit when items/prefixItems are present)\n if (isArray) {\n // Rule 3a: prefixItems (tuple positions with static indices)\n if (Array.isArray(schemaAny['prefixItems'])) {\n const prefixItems = schemaAny['prefixItems'] as RJSFSchema[]\n prefixItems.forEach((itemSchema, index) => {\n traverse(itemSchema, [...path, index], fields, formulaKey, formulaContextKey, formulaConflictBehavior, ambientCondition, rootSchema)\n })\n }\n\n // Rule 3b: items as array (legacy draft-07 tuple — positional schemas, equivalent to prefixItems)\n if (Array.isArray(schema.items)) {\n ;(schema.items as RJSFSchema[]).forEach((itemSchema, index) => {\n traverse(itemSchema, [...path, index], fields, formulaKey, formulaContextKey, formulaConflictBehavior, ambientCondition, rootSchema)\n })\n }\n\n // Rule 3c: items as object (uniform array — all elements share one schema)\n if (schema.items && !Array.isArray(schema.items)) {\n traverse(\n schema.items as RJSFSchema,\n [...path, ARRAY_INDEX],\n fields,\n formulaKey,\n formulaContextKey,\n formulaConflictBehavior,\n ambientCondition,\n rootSchema\n )\n }\n }\n\n // Rule 4: allOf — recurse into each branch, then merge with conflict detection\n // allOf does not add to the condition — branches are always active within their parent's condition\n if (Array.isArray(schemaAny['allOf'])) {\n const allOfBranches = schemaAny['allOf'] as RJSFSchema[]\n for (const branch of allOfBranches) {\n const branchFields: FormulaField[] = []\n traverse(branch, path, branchFields, formulaKey, formulaContextKey, formulaConflictBehavior, ambientCondition, rootSchema)\n mergeFields(fields, branchFields, formulaConflictBehavior)\n }\n }\n\n // Rule 5: oneOf / anyOf — recurse each branch with a composed condition\n for (const compositionKey of ['oneOf', 'anyOf'] as const) {\n if (Array.isArray(schemaAny[compositionKey])) {\n const branches = schemaAny[compositionKey] as RJSFSchema[]\n for (const branch of branches) {\n const branchCondition = composeCondition(ambientCondition, branch)\n traverse(branch, path, fields, formulaKey, formulaContextKey, formulaConflictBehavior, branchCondition, rootSchema)\n }\n }\n }\n\n // Rule 6: if/then/else — traverse then/else with appropriate conditions; warn if formula found in if\n if ('if' in schemaAny) {\n const ifSchema = schemaAny['if'] as RJSFSchema\n const thenSchema = schemaAny['then'] as RJSFSchema | undefined\n const elseSchema = schemaAny['else'] as RJSFSchema | undefined\n\n // Warn if the if schema itself contains a formula key (it is never rendered by RJSF)\n if (formulaKey in (ifSchema as Record<string, unknown>)) {\n console.warn(\n `[rjsf-formulas] Formula key \"${formulaKey}\" found inside an \"if\" schema at path [${formatPath(path)}]. The \"if\" schema is a validation predicate and is never rendered — the formula will be ignored.`\n )\n }\n\n if (thenSchema !== undefined) {\n const thenCondition = composeCondition(ambientCondition, ifSchema)\n traverse(thenSchema, path, fields, formulaKey, formulaContextKey, formulaConflictBehavior, thenCondition, rootSchema)\n }\n\n if (elseSchema !== undefined) {\n const elseCondition = composeCondition(ambientCondition, { not: ifSchema })\n traverse(elseSchema, path, fields, formulaKey, formulaContextKey, formulaConflictBehavior, elseCondition, rootSchema)\n }\n }\n}\n","'use strict';\n\n// do not edit .js files directly - edit src/index.jst\n\n\n\nmodule.exports = function equal(a, b) {\n if (a === b) return true;\n\n if (a && b && typeof a == 'object' && typeof b == 'object') {\n if (a.constructor !== b.constructor) return false;\n\n var length, i, keys;\n if (Array.isArray(a)) {\n length = a.length;\n if (length != b.length) return false;\n for (i = length; i-- !== 0;)\n if (!equal(a[i], b[i])) return false;\n return true;\n }\n\n\n\n if (a.constructor === RegExp) return a.source === b.source && a.flags === b.flags;\n if (a.valueOf !== Object.prototype.valueOf) return a.valueOf() === b.valueOf();\n if (a.toString !== Object.prototype.toString) return a.toString() === b.toString();\n\n keys = Object.keys(a);\n length = keys.length;\n if (length !== Object.keys(b).length) return false;\n\n for (i = length; i-- !== 0;)\n if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false;\n\n for (i = length; i-- !== 0;) {\n var key = keys[i];\n\n if (!equal(a[key], b[key])) return false;\n }\n\n return true;\n }\n\n // true if both NaN, false otherwise\n return a!==a && b!==b;\n};\n","import type { FormulaField } from './analyzeSchema'\n\nexport type BuildContextOptions = {\n formulaDataKey: string\n formulaPathKey: string\n}\n\nexport function buildContext(\n field: FormulaField,\n resolvedPath: (string | number)[],\n candidateFormData: unknown,\n options: BuildContextOptions\n): object {\n const parentPath = resolvedPath.slice(0, -1)\n const parent = parentPath.reduce<unknown>((curr, key) => {\n if (curr == null || typeof curr !== 'object') return undefined\n return (curr as Record<string | number, unknown>)[key]\n }, candidateFormData)\n\n const siblings =\n parent != null && typeof parent === 'object' && !Array.isArray(parent)\n ? { ...(parent as object) }\n : {}\n\n if (field.contextMode === 'extended') {\n if (options.formulaDataKey in siblings || options.formulaPathKey in siblings) {\n console.warn(\n `[rjsf-formulas] Extended context key collision: sibling field named \"${\n options.formulaDataKey in siblings ? options.formulaDataKey : options.formulaPathKey\n }\" will be overwritten by the injected context. Use formulaDataKey/formulaPathKey props to choose a different key.`\n )\n }\n return {\n ...siblings,\n [options.formulaDataKey]: candidateFormData,\n [options.formulaPathKey]: [...resolvedPath],\n }\n }\n\n return siblings\n}\n","import equal from 'fast-deep-equal'\nimport type { RJSFSchema } from '@rjsf/utils'\nimport type { FormulaField, ArrayIndex } from './analyzeSchema'\nimport { ARRAY_INDEX } from './analyzeSchema'\nimport { buildContext } from './buildContext'\nimport type { BuildContextOptions } from './buildContext'\n\nexport { ARRAY_INDEX }\n\nfunction formatPath(path: (string | number | ArrayIndex)[]): string {\n return path.map(s => (typeof s === 'symbol' ? '[*]' : String(s))).join(', ')\n}\n\nexport function getAt(data: unknown, path: (string | number)[]): unknown {\n return path.reduce<unknown>((curr, key) => {\n if (curr == null || typeof curr !== 'object') return undefined\n return (curr as Record<string | number, unknown>)[key]\n }, data)\n}\n\nexport function setAt(data: unknown, path: (string | number)[], value: unknown): void {\n if (path.length === 0) return\n const parent = getAt(data, path.slice(0, -1))\n if (parent != null && typeof parent === 'object') {\n ;(parent as Record<string | number, unknown>)[path[path.length - 1]] = value\n }\n}\n\nexport function expandPaths(\n templatePath: (string | number | ArrayIndex)[],\n data: unknown,\n currentPath: (string | number)[] = []\n): (string | number)[][] {\n if (templatePath.length === 0) return [currentPath]\n const [head, ...rest] = templatePath\n if (head === ARRAY_INDEX) {\n const arr = getAt(data, currentPath)\n if (!Array.isArray(arr)) return []\n const results: (string | number)[][] = []\n for (let i = 0; i < arr.length; i++) {\n results.push(...expandPaths(rest, data, [...currentPath, i]))\n }\n return results\n }\n return expandPaths(rest, data, [...currentPath, head as string | number])\n}\n\nexport function deepEqual(a: unknown, b: unknown): boolean {\n return equal(a, b)\n}\n\ntype EvalTask = { field: FormulaField; concretePath: (string | number)[]; context: object }\n\ninterface PassResult {\n data: unknown\n errors: Array<{ path: (string | number)[]; error: Error }>\n}\n\nasync function applyAllFormulas(\n formData: unknown,\n formulaFields: FormulaField[],\n evaluator: (formula: string, context: object) => unknown | Promise<unknown>,\n contextOptions: BuildContextOptions\n): Promise<PassResult> {\n const result = structuredClone(formData)\n\n // Collect all tasks from the snapshot before any evaluation\n const tasks: EvalTask[] = []\n for (const field of formulaFields) {\n for (const concretePath of expandPaths(field.path, result)) {\n const context = buildContext(field, concretePath, result, contextOptions)\n tasks.push({ field, concretePath, context })\n }\n }\n\n // Evaluate all formulas in parallel; new Promise() executor is try-catched, catching sync throws\n const settled = await Promise.allSettled(\n tasks.map(({ field, context }) => new Promise<unknown>(resolve => resolve(evaluator(field.formula, context))))\n )\n\n // Apply results\n const errors: Array<{ path: (string | number)[]; error: Error }> = []\n for (let i = 0; i < tasks.length; i++) {\n const { concretePath } = tasks[i]\n const outcome = settled[i]\n if (outcome.status === 'fulfilled') {\n setAt(result, concretePath, outcome.value)\n } else {\n const err = outcome.reason instanceof Error\n ? outcome.reason\n : new Error(String(outcome.reason))\n errors.push({ path: concretePath, error: err })\n setAt(result, concretePath, undefined)\n }\n }\n\n return { data: result, errors }\n}\n\nfunction allConverged(\n prev: unknown,\n next: unknown,\n formulaFields: FormulaField[]\n): boolean {\n for (const field of formulaFields) {\n for (const concretePath of expandPaths(field.path, next)) {\n if (!deepEqual(getAt(prev, concretePath), getAt(next, concretePath))) {\n return false\n }\n }\n }\n return true\n}\n\nexport async function enrich(\n formData: unknown,\n formulaFields: FormulaField[],\n evaluator: (formula: string, context: object) => unknown | Promise<unknown>,\n maxConvergencePasses: number,\n onFormulaError: ((path: (string | number)[], error: Error) => void) | undefined,\n formulaDataKey: string,\n formulaPathKey: string,\n checkCondition: (condition: RJSFSchema, formData: unknown) => boolean,\n formulaConflictBehavior: 'ignore' | 'warn' | 'error'\n): Promise<unknown> {\n // Filter to only active fields based on condition\n const activeFields = formulaFields.filter(field =>\n field.condition === true || checkCondition(field.condition as RJSFSchema, formData)\n )\n\n if (activeFields.length === 0) return formData\n\n // Detect runtime conflicts among active fields with the same template path\n const pathSeen = new Map<string, FormulaField>()\n const deduped: FormulaField[] = []\n for (const field of activeFields) {\n const key = JSON.stringify(field.path)\n if (pathSeen.has(key)) {\n if (formulaConflictBehavior === 'error') {\n throw new TypeError(\n `[rjsf-formulas] Formula conflict: two active fields share path [${formatPath(field.path)}]`\n )\n } else if (formulaConflictBehavior === 'warn') {\n console.warn(\n `[rjsf-formulas] Formula conflict: two active fields share path [${formatPath(field.path)}]; taking last`\n )\n }\n // Replace the previous entry with the last one (take last)\n const idx = deduped.indexOf(pathSeen.get(key)!)\n deduped[idx] = field\n pathSeen.set(key, field)\n } else {\n pathSeen.set(key, field)\n deduped.push(field)\n }\n }\n\n const contextOptions: BuildContextOptions = { formulaDataKey, formulaPathKey }\n let current = formData\n\n for (let pass = 0; pass < maxConvergencePasses; pass++) {\n const { data: candidate, errors } = await applyAllFormulas(current, deduped, evaluator, contextOptions)\n if (allConverged(current, candidate, deduped)) {\n // Stable — emit error callbacks now that we know this is the final result\n for (const { path, error } of errors) {\n onFormulaError?.(path, error)\n }\n return candidate\n }\n current = candidate\n }\n\n // maxConvergencePasses exceeded — identify and report non-converging fields\n const { data: candidate } = await applyAllFormulas(current, deduped, evaluator, contextOptions)\n const result = structuredClone(candidate)\n\n for (const field of deduped) {\n for (const concretePath of expandPaths(field.path, candidate)) {\n if (!deepEqual(getAt(current, concretePath), getAt(candidate, concretePath))) {\n onFormulaError?.(\n concretePath,\n new Error(\n `[rjsf-formulas] Formula at [${concretePath.join(', ')}] did not converge after ${maxConvergencePasses} passes`\n )\n )\n setAt(result, concretePath, undefined)\n }\n }\n }\n\n return result\n}\n","import { useState, useRef, useEffect, useCallback } from 'react'\nimport type { FormulaField } from './analyzeSchema'\nimport { expandPaths, enrich, deepEqual } from './enrich'\nimport type { BuildContextOptions } from './buildContext'\nimport type { RJSFSchema } from '@rjsf/utils'\n\ntype FieldState = 'idle' | 'running' | 'dirty'\n\nfunction pathKey(path: (string | number)[]): string {\n return JSON.stringify(path)\n}\n\nexport function useAsyncFormulas(\n formData: unknown,\n formulaFields: FormulaField[],\n evaluator: (formula: string, context: object) => unknown | Promise<unknown>,\n debounceMs: number,\n maxConvergencePasses: number,\n onFormulaError: ((path: (string | number)[], error: Error) => void) | undefined,\n onLoadingChange: ((loadingPaths: (string | number)[][]) => void) | undefined,\n contextOptions: BuildContextOptions,\n checkCondition: (condition: RJSFSchema, formData: unknown) => boolean,\n formulaConflictBehavior: 'ignore' | 'warn' | 'error'\n): { enrichedFormData: unknown; handleInput: (newFormData: unknown) => void } {\n const [enrichedFormData, setEnrichedFormData] = useState<unknown>(formData)\n\n const pendingInputRef = useRef<unknown>(formData)\n const lastExternalFormDataRef = useRef<unknown>(formData)\n const fieldStateRef = useRef<Map<string, FieldState>>(new Map())\n const debounceTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null)\n const runningRef = useRef(false)\n\n // Stable refs so callbacks/config don't require restarting the debounce\n const onFormulaErrorRef = useRef(onFormulaError)\n const onLoadingChangeRef = useRef(onLoadingChange)\n const evaluatorRef = useRef(evaluator)\n const formulaFieldsRef = useRef(formulaFields)\n const maxPassesRef = useRef(maxConvergencePasses)\n const contextOptionsRef = useRef(contextOptions)\n const checkConditionRef = useRef(checkCondition)\n const formulaConflictBehaviorRef = useRef(formulaConflictBehavior)\n\n useEffect(() => { onFormulaErrorRef.current = onFormulaError }, [onFormulaError])\n useEffect(() => { onLoadingChangeRef.current = onLoadingChange }, [onLoadingChange])\n useEffect(() => { evaluatorRef.current = evaluator }, [evaluator])\n useEffect(() => { formulaFieldsRef.current = formulaFields }, [formulaFields])\n useEffect(() => { maxPassesRef.current = maxConvergencePasses }, [maxConvergencePasses])\n useEffect(() => { contextOptionsRef.current = contextOptions }, [contextOptions])\n useEffect(() => { checkConditionRef.current = checkCondition }, [checkCondition])\n useEffect(() => { formulaConflictBehaviorRef.current = formulaConflictBehavior }, [formulaConflictBehavior])\n\n // startSequence reads all config from refs so it is stable across renders\n const startSequence = useCallback(() => {\n if (runningRef.current) return\n\n const run = async () => {\n runningRef.current = true\n\n try {\n while (true) {\n const input = pendingInputRef.current\n const fields = formulaFieldsRef.current\n\n // Only report loading for fields whose condition is currently active\n const activeFields = fields.filter(f =>\n f.condition === true || checkConditionRef.current(f.condition as any, input)\n )\n\n // Collect concrete paths for loading reporting\n const concretePaths: (string | number)[][] = []\n for (const field of activeFields) {\n for (const cp of expandPaths(field.path, input)) {\n concretePaths.push(cp)\n }\n }\n\n // Mark all fields running\n const stateMap = fieldStateRef.current\n stateMap.clear()\n for (const cp of concretePaths) stateMap.set(pathKey(cp), 'running')\n if (concretePaths.length > 0) onLoadingChangeRef.current?.(concretePaths)\n\n const result = await enrich(\n input,\n fields,\n evaluatorRef.current,\n maxPassesRef.current,\n onFormulaErrorRef.current,\n contextOptionsRef.current.formulaDataKey,\n contextOptionsRef.current.formulaPathKey,\n checkConditionRef.current,\n formulaConflictBehaviorRef.current\n )\n\n if (isUnmountedRef.current) break\n\n const anyDirty = [...stateMap.values()].some(s => s === 'dirty')\n stateMap.clear()\n\n if (!anyDirty) {\n setEnrichedFormData(result)\n if (concretePaths.length > 0) onLoadingChangeRef.current?.([])\n break\n }\n // New input arrived while evaluating — re-run with pendingInputRef.current\n }\n } finally {\n runningRef.current = false\n }\n }\n\n run()\n }, []) // stable: all dependencies accessed via refs\n\n const handleInput = useCallback(\n (newFormData: unknown) => {\n pendingInputRef.current = newFormData\n\n // Flip any running fields to dirty\n const stateMap = fieldStateRef.current\n for (const [key, state] of stateMap) {\n if (state === 'running') stateMap.set(key, 'dirty')\n }\n\n // Only manage debounce when no sequence is in flight;\n // the while loop picks up dirty fields automatically\n if (!runningRef.current) {\n if (debounceTimerRef.current !== null) clearTimeout(debounceTimerRef.current)\n debounceTimerRef.current = setTimeout(() => {\n debounceTimerRef.current = null\n startSequence()\n }, debounceMs)\n }\n },\n [debounceMs, startSequence]\n )\n\n // React to external formData prop changes.\n // We use a no-dependency effect that runs every render but guards with deep equality\n // to avoid spurious re-evaluations when the parent re-renders with a new object\n // reference but the same value. On first render this always fires (initialises evaluation).\n const hasMountedRef = useRef(false)\n const isUnmountedRef = useRef(false)\n useEffect(() => {\n if (!hasMountedRef.current) {\n // Initial mount: always trigger evaluation\n hasMountedRef.current = true\n lastExternalFormDataRef.current = formData\n handleInput(formData)\n } else if (!deepEqual(formData, lastExternalFormDataRef.current)) {\n // Subsequent renders: only trigger on actual value change\n lastExternalFormDataRef.current = formData\n handleInput(formData)\n }\n }) // runs every render — guarded by deep equality\n\n // Reset lifecycle sentinels on every (re)mount; clean up on unmount.\n // The setup body runs before any debounce fires, so isUnmountedRef is false\n // by the time startSequence checks it.\n useEffect(() => {\n isUnmountedRef.current = false\n return () => {\n isUnmountedRef.current = true\n hasMountedRef.current = false // allow re-init on next mount (React StrictMode)\n if (debounceTimerRef.current !== null) clearTimeout(debounceTimerRef.current)\n }\n }, [])\n\n return { enrichedFormData, handleInput }\n}\n","import type { FormulaField, ArrayIndex } from './analyzeSchema'\nimport { ARRAY_INDEX } from './analyzeSchema'\n\ntype UiSchema = Record<string, unknown>\n\nexport function mergeReadOnly(\n uiSchema: UiSchema | undefined,\n formulaFields: FormulaField[]\n): UiSchema {\n const result: UiSchema = structuredClone(uiSchema ?? {})\n const mixedArrayPaths = findMixedArrayPaths(formulaFields)\n\n for (const field of formulaFields) {\n setReadOnly(result, field.path, mixedArrayPaths)\n }\n\n return result\n}\n\n// Returns a set of serialized parent paths for arrays that have both integer\n// (prefixItems) and ARRAY_INDEX (items) formula fields at the same depth.\nfunction findMixedArrayPaths(formulaFields: FormulaField[]): Set<string> {\n const mixed = new Set<string>()\n\n for (let i = 0; i < formulaFields.length; i++) {\n const path = formulaFields[i].path\n\n for (let depth = 0; depth < path.length; depth++) {\n const seg = path[depth]\n if (typeof seg !== 'number' && seg !== ARRAY_INDEX) continue\n\n const parentKey = serializePath(path.slice(0, depth))\n const isInt = typeof seg === 'number'\n\n const hasSibling = formulaFields.some((f, j) => {\n if (j === i) return false\n if (f.path.length <= depth) return false\n if (serializePath(f.path.slice(0, depth)) !== parentKey) return false\n const sibling = f.path[depth]\n return isInt ? sibling === ARRAY_INDEX : typeof sibling === 'number'\n })\n\n if (hasSibling) mixed.add(parentKey)\n }\n }\n\n return mixed\n}\n\nfunction serializePath(path: (string | number | ArrayIndex)[]): string {\n return JSON.stringify(path.map(s => (typeof s === 'symbol' ? '__ARRAY_INDEX__' : s)))\n}\n\nfunction setReadOnly(\n uiSchema: UiSchema,\n path: (string | number | ArrayIndex)[],\n mixedArrayPaths: Set<string>,\n traversedPath: (string | number | ArrayIndex)[] = []\n): void {\n if (path.length === 0) {\n uiSchema['ui:readonly'] = true\n return\n }\n\n const [head, ...tail] = path\n\n if (typeof head === 'string') {\n if (!uiSchema[head] || typeof uiSchema[head] !== 'object' || Array.isArray(uiSchema[head])) {\n uiSchema[head] = {}\n }\n setReadOnly(uiSchema[head] as UiSchema, tail, mixedArrayPaths, [...traversedPath, head])\n return\n }\n\n if (typeof head === 'number') {\n // prefixItems tuple slot — use items as array\n if (uiSchema['items'] !== undefined && !Array.isArray(uiSchema['items'])) {\n console.warn('[rjsf-formulas] mergeReadOnly: cannot inject ui:readonly at tuple index because existing uiSchema has items as an object. Skipping.')\n return\n }\n if (!Array.isArray(uiSchema['items'])) {\n uiSchema['items'] = []\n }\n const items = uiSchema['items'] as unknown[]\n if (!items[head] || typeof items[head] !== 'object') {\n items[head] = {}\n }\n setReadOnly(items[head] as UiSchema, tail, mixedArrayPaths, [...traversedPath, head])\n return\n }\n\n // head === ARRAY_INDEX\n const parentKey = serializePath(traversedPath)\n const isMixed = mixedArrayPaths.has(parentKey)\n\n if (isMixed) {\n // Mixed array: ARRAY_INDEX → additionalItems\n if (!uiSchema['additionalItems'] || typeof uiSchema['additionalItems'] !== 'object') {\n uiSchema['additionalItems'] = {}\n }\n setReadOnly(uiSchema['additionalItems'] as UiSchema, tail, mixedArrayPaths, [...traversedPath, head])\n } else {\n // Uniform array: ARRAY_INDEX → items as object\n if (Array.isArray(uiSchema['items'])) {\n console.warn('[rjsf-formulas] mergeReadOnly: cannot inject ui:readonly for uniform array because existing uiSchema has items as an array. Skipping.')\n return\n }\n if (!uiSchema['items'] || typeof uiSchema['items'] !== 'object') {\n uiSchema['items'] = {}\n }\n setReadOnly(uiSchema['items'] as UiSchema, tail, mixedArrayPaths, [...traversedPath, head])\n }\n}\n","import React, { useMemo, useEffect, useRef, useCallback, forwardRef } from 'react'\nimport Form from '@rjsf/core'\nimport type { FormProps, IChangeEvent } from '@rjsf/core'\nimport type { StrictRJSFSchema, RJSFSchema, FormContextType } from '@rjsf/utils'\nimport { analyzeSchema } from './analyzeSchema'\nimport type { FormulaField } from './analyzeSchema'\nimport { useAsyncFormulas } from './useAsyncFormulas'\nimport { mergeReadOnly } from './mergeReadOnly'\nimport type { BuildContextOptions } from './buildContext'\n\n/**\n * Props accepted by {@link FormulaForm}.\n *\n * Extends all standard RJSF `FormProps` with formula-specific configuration.\n * All formula-specific props are optional except `evaluator`.\n */\nexport type FormulaFormProps<\n T = any,\n S extends StrictRJSFSchema = RJSFSchema,\n F extends FormContextType = any\n> = FormProps<T, S, F> & {\n /**\n * Evaluates a formula string against a context object and returns the computed value.\n *\n * @remarks\n * May return a plain value or a `Promise`. For user-supplied formulas, **do not use `eval`**\n * — it allows arbitrary code execution. Prefer a sandboxed evaluator such as\n * [`expr-eval`](https://github.com/silentmatt/expr-eval) or\n * [`mathjs`](https://mathjs.org/). For additional isolation, run the evaluator in a Web Worker.\n *\n * @param formula - The formula string from the schema.\n * @param context - Sibling field values, or full form data in extended mode.\n * @returns The computed value, or a Promise resolving to it.\n */\n evaluator: (formula: string, context: object) => unknown | Promise<unknown>\n\n /**\n * Inner RJSF `Form` component to render.\n * Defaults to `Form` from `@rjsf/core`. Swap to use a themed form\n * (e.g. `Form` from `@rjsf/bootstrap-4`).\n */\n Form?: React.ComponentType<FormProps<T, S, F>>\n\n /** Schema key that marks a field as computed. Defaults to `'x-formula'`. */\n formulaKey?: string\n\n /** Schema key that selects the context mode for a field. Defaults to `'x-formula-context'`. */\n formulaContextKey?: string\n\n /**\n * Key injected into the extended context carrying the full form data.\n * Defaults to `'__formData__'`. Override if a sibling field uses the same name.\n */\n formulaDataKey?: string\n\n /**\n * Key injected into the extended context carrying the field's resolved path.\n * Defaults to `'__path__'`. Override if a sibling field uses the same name.\n */\n formulaPathKey?: string\n\n /**\n * Maximum number of re-evaluation passes triggered by a single input event.\n * Guards against infinite loops from circular formula dependencies. Defaults to `10`.\n */\n maxConvergencePasses?: number\n\n /**\n * Milliseconds to debounce formula evaluation after a user input event. Defaults to `300`.\n * Set to `0` to disable the debounce delay and evaluate on the next event loop tick.\n */\n debounceMs?: number\n\n /**\n * Called when a formula throws during evaluation.\n * @param path - JSON path of the field whose formula failed.\n * @param error - The error thrown by the evaluator.\n */\n onFormulaError?: (path: (string | number)[], error: Error) => void\n\n /**\n * Called whenever the set of currently-evaluating fields changes.\n * Useful for showing per-field loading indicators.\n * @param loadingPaths - Paths of all fields whose evaluations are in progress.\n */\n onLoadingChange?: (loadingPaths: (string | number)[][]) => void\n\n /**\n * What to do when multiple branches of a composition operator (`allOf` at schema-analysis\n * time, or simultaneously-active `oneOf`/`anyOf` branches at evaluation time) define a\n * formula for the same field path.\n * - `'ignore'` — silently take the last definition.\n * - `'warn'` (default) — emit `console.warn` and take the last definition.\n * - `'error'` — throw a `TypeError` synchronously (useful during development).\n */\n formulaConflictBehavior?: 'ignore' | 'warn' | 'error'\n}\n\n/**\n * Drop-in replacement for RJSF's `<Form>` with support for computed fields.\n *\n * @remarks\n * Fields marked with a formula key in the JSON schema are evaluated automatically\n * on every data change and rendered as read-only. The `evaluator` prop receives\n * the formula string and a context object, and returns the computed value.\n *\n * @example\n * ```tsx\n * import { FormulaForm } from '@a-ludi/rjsf-formulas'\n * import validator from '@rjsf/validator-ajv8'\n * import { Parser } from 'expr-eval'\n *\n * const parser = new Parser()\n *\n * const schema = {\n * type: 'object' as const,\n * properties: {\n * price: { type: 'number' as const },\n * quantity: { type: 'number' as const },\n * total: { type: 'number' as const, 'x-formula': 'price * quantity' },\n * },\n * }\n *\n * function MyForm() {\n * return (\n * <FormulaForm\n * schema={schema}\n * validator={validator}\n * evaluator={(formula, ctx) => parser.evaluate(formula, ctx)}\n * />\n * )\n * }\n * ```\n */\nfunction FormulaFormImpl<\n T = any,\n S extends StrictRJSFSchema = RJSFSchema,\n F extends FormContextType = any\n>(props: FormulaFormProps<T, S, F>, ref: React.Ref<Form<T, S, F>>): JSX.Element {\n const {\n schema,\n formData,\n validator,\n uiSchema,\n evaluator,\n Form: InnerForm = Form as React.ComponentType<FormProps<T, S, F>>,\n formulaKey = 'x-formula',\n formulaContextKey = 'x-formula-context',\n formulaDataKey = '__formData__',\n formulaPathKey = '__path__',\n maxConvergencePasses = 10,\n debounceMs = 300,\n onFormulaError,\n onLoadingChange,\n formulaConflictBehavior = 'warn',\n onChange,\n ...rest\n } = props\n\n const formulaFields: FormulaField[] = useMemo(\n () => analyzeSchema(schema as RJSFSchema, { formulaKey, formulaContextKey }),\n [schema, formulaKey, formulaContextKey]\n )\n\n const contextOptions: BuildContextOptions = useMemo(\n () => ({ formulaDataKey, formulaPathKey }),\n [formulaDataKey, formulaPathKey]\n )\n\n const mergedUiSchema = useMemo(\n () => mergeReadOnly(uiSchema as Record<string, unknown> | undefined, formulaFields),\n [uiSchema, formulaFields]\n )\n\n const checkCondition = useCallback(\n (condition: RJSFSchema, formData: unknown) =>\n validator.isValid(condition as any, formData as any, schema as any),\n [validator, schema]\n )\n\n const { enrichedFormData, handleInput } = useAsyncFormulas(\n formData,\n formulaFields,\n evaluator,\n debounceMs,\n maxConvergencePasses,\n onFormulaError,\n onLoadingChange,\n contextOptions,\n checkCondition,\n formulaConflictBehavior\n )\n\n const onChangeRef = useRef(onChange)\n useEffect(() => { onChangeRef.current = onChange }, [onChange])\n\n useEffect(() => {\n if (formulaFields.length === 0) return\n onChangeRef.current?.({ formData: enrichedFormData as T } as IChangeEvent<T, S, F>, undefined)\n }, [enrichedFormData]) // eslint-disable-line react-hooks/exhaustive-deps\n\n const handleChange = (data: IChangeEvent<T, S, F>, id?: string) => {\n handleInput(data.formData)\n onChange?.(data, id)\n }\n\n return (\n <InnerForm\n ref={ref as any}\n {...rest}\n schema={schema}\n validator={validator}\n formData={enrichedFormData as T}\n uiSchema={mergedUiSchema as any}\n onChange={handleChange}\n />\n )\n}\n\nexport const FormulaForm = forwardRef(FormulaFormImpl) as <\n T = any,\n S extends StrictRJSFSchema = RJSFSchema,\n F extends FormContextType = any\n>(props: FormulaFormProps<T, S, F>) => JSX.Element\n"],"names":["ARRAY_INDEX","analyzeSchema","schema","options","formulaKey","formulaContextKey","formulaConflictBehavior","fields","traverse","composeCondition","ambient","branch","ambientAny","resolveContextMode","value","path","formatPath","s","pathKey","applyConflictBehavior","existing","incoming","behavior","key","mergeFields","base","field","existingIndex","f","ambientCondition","rootSchema","schemaAny","resolved","findSchemaDefinition","formula","isArray","propSchema","itemSchema","index","allOfBranches","branchFields","compositionKey","branches","branchCondition","ifSchema","thenSchema","elseSchema","thenCondition","elseCondition","fastDeepEqual","equal","a","b","length","i","keys","buildContext","resolvedPath","candidateFormData","parent","curr","siblings","getAt","data","setAt","expandPaths","templatePath","currentPath","head","rest","arr","results","deepEqual","applyAllFormulas","formData","formulaFields","evaluator","contextOptions","result","tasks","concretePath","context","settled","resolve","errors","outcome","err","allConverged","prev","next","enrich","maxConvergencePasses","onFormulaError","formulaDataKey","formulaPathKey","checkCondition","activeFields","pathSeen","deduped","idx","current","pass","candidate","error","useAsyncFormulas","debounceMs","onLoadingChange","enrichedFormData","setEnrichedFormData","useState","pendingInputRef","useRef","lastExternalFormDataRef","fieldStateRef","debounceTimerRef","runningRef","onFormulaErrorRef","onLoadingChangeRef","evaluatorRef","formulaFieldsRef","maxPassesRef","contextOptionsRef","checkConditionRef","formulaConflictBehaviorRef","useEffect","startSequence","useCallback","input","concretePaths","cp","stateMap","_a","isUnmountedRef","anyDirty","_b","handleInput","newFormData","state","hasMountedRef","mergeReadOnly","uiSchema","mixedArrayPaths","findMixedArrayPaths","setReadOnly","mixed","depth","seg","parentKey","serializePath","isInt","j","sibling","traversedPath","tail","items","FormulaFormImpl","props","ref","validator","InnerForm","Form","onChange","useMemo","mergedUiSchema","condition","onChangeRef","jsx","id","FormulaForm","forwardRef"],"mappings":";;;;AAOO,MAAMA,IAA6B,OAAO,YAAY;AAmFtD,SAASC,GACdC,GACAC,GACgB;AAChB,QAAMC,KAAaD,KAAA,gBAAAA,EAAS,eAAc,aACpCE,KAAoBF,KAAA,gBAAAA,EAAS,sBAAqB,qBAClDG,KAA0BH,KAAA,gBAAAA,EAAS,4BAA2B,QAC9DI,IAAyB,CAAA;AAC/B,SAAAC,EAASN,GAAQ,CAAA,GAAIK,GAAQH,GAAYC,GAAmBC,GAAyB,IAAMJ,CAAM,GAC1FK;AACT;AASA,SAASE,EAAiBC,GAA4BC,GAAgC;AACpF,MAAID,MAAY,GAAM,QAAOC;AAC7B,QAAMC,IAAaF;AACnB,SAAI,MAAM,QAAQE,EAAW,KAAQ,IAC5B,EAAE,OAAO,CAAC,GAAIA,EAAW,OAA2BD,CAAM,EAAA,IAE5D,EAAE,OAAO,CAACD,GAASC,CAAM,EAAA;AAClC;AAEA,SAASE,GACPC,GACAC,GACa;AACb,SAAID,MAAU,UAAaA,MAAU,aAAmB,aACpDA,MAAU,aAAmB,cACjC,QAAQ;A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AAC,GAQnB,gBAAA2D;AAAA,IAACP;AAAA,IAAA;AAAA,MACC,KAAAF;AAAA,MACC,GAAGxF;AAAA,MACJ,QAAAnE;AAAA,MACA,WAAA4J;AAAA,MACA,UAAUnD;AAAA,MACV,UAAUwD;AAAA,MACV,UAbiB,CAACpG,GAA6BwG,MAAgB;AACjE,QAAAhC,EAAYxE,EAAK,QAAQ,GACzBkG,KAAA,QAAAA,EAAWlG,GAAMwG;AAAA,MACnB;AAAA,IAUc;AAAA,EAAA;AAGhB;AAEO,MAAMC,KAAcC,GAAWd,EAAe;","x_google_ignoreList":[1]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@a-ludi/rjsf-formulas",
3
- "version": "0.3.2",
3
+ "version": "0.4.1",
4
4
  "description": "RJSF extension for computed fields driven by formulas",
5
5
  "author": "Arne Ludwig <arne.ludwig@posteo.de>",
6
6
  "license": "MIT",