@a-ludi/rjsf-formulas 0.1.2 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,22 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("react"),pe=require("@rjsf/core"),H=Symbol("arrayIndex");function le(r,t){const o=(t==null?void 0:t.formulaKey)??"x-formula",s=(t==null?void 0:t.formulaContextKey)??"x-formula-context",n=[];return B(r,[],n,o,s),n}const me=["$ref","oneOf","anyOf","allOf"];function ye(r,t){return r===void 0||r==="siblings"?"siblings":r==="extended"?"extended":(console.warn(`[rjsf-formulas] Unknown x-formula-context value "${r}" at path [${re(t)}], treating as "siblings"`),"siblings")}function re(r){return r.map(t=>typeof t=="symbol"?"[*]":String(t)).join(", ")}function B(r,t,o,s,n){for(const a of me)a in r&&console.warn(`[rjsf-formulas] Schema composition operator "${a}" at path [${re(t)}] is not supported and will be skipped. See issue 06.`);if(s in r){const a=r[s];if(typeof a!="string"){console.warn(`[rjsf-formulas] Formula at path [${re(t)}] is not a string (got ${typeof a}), skipping.`);return}o.push({path:t,formula:a,contextMode:ye(r[n],t)});return}if(r.type==="object"&&r.properties)for(const[a,c]of Object.entries(r.properties))B(c,[...t,a],o,s,n);if(r.type==="array"){const a=r;Array.isArray(a.prefixItems)&&a.prefixItems.forEach((i,f)=>{B(i,[...t,f],o,s,n)}),r.items&&!Array.isArray(r.items)&&B(r.items,[...t,H],o,s,n)}}function _e(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}var G={exports:{}},U={};/**
2
- * @license React
3
- * react-jsx-runtime.production.js
4
- *
5
- * Copyright (c) Meta Platforms, Inc. and affiliates.
6
- *
7
- * This source code is licensed under the MIT license found in the
8
- * LICENSE file in the root directory of this source tree.
9
- */var ae;function Re(){if(ae)return U;ae=1;var r=Symbol.for("react.transitional.element"),t=Symbol.for("react.fragment");function o(s,n,a){var c=null;if(a!==void 0&&(c=""+a),n.key!==void 0&&(c=""+n.key),"key"in n){a={};for(var i in n)i!=="key"&&(a[i]=n[i])}else a=n;return n=a.ref,{$$typeof:r,type:s,key:c,ref:n!==void 0?n:null,props:a}}return U.Fragment=t,U.jsx=o,U.jsxs=o,U}var W={};/**
10
- * @license React
11
- * react-jsx-runtime.development.js
12
- *
13
- * Copyright (c) Meta Platforms, Inc. and affiliates.
14
- *
15
- * This source code is licensed under the MIT license found in the
16
- * LICENSE file in the root directory of this source tree.
17
- */var ue;function be(){return ue||(ue=1,process.env.NODE_ENV!=="production"&&(function(){function r(e){if(e==null)return null;if(typeof e=="function")return e.$$typeof===$?null:e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case g:return"Fragment";case D:return"Profiler";case I:return"StrictMode";case S:return"Suspense";case O:return"SuspenseList";case P:return"Activity"}if(typeof e=="object")switch(typeof e.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),e.$$typeof){case A:return"Portal";case w:return e.displayName||"Context";case T:return(e._context.displayName||"Context")+".Consumer";case j:var u=e.render;return e=e.displayName,e||(e=u.displayName||u.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case C:return u=e.displayName||null,u!==null?u:r(e.type)||"Memo";case M:u=e._payload,e=e._init;try{return r(e(u))}catch{}}return null}function t(e){return""+e}function o(e){try{t(e);var u=!1}catch{u=!0}if(u){u=console;var m=u.error,y=typeof Symbol=="function"&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return m.call(u,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",y),t(e)}}function s(e){if(e===g)return"<>";if(typeof e=="object"&&e!==null&&e.$$typeof===M)return"<...>";try{var u=r(e);return u?"<"+u+">":"<...>"}catch{return"<...>"}}function n(){var e=x.A;return e===null?null:e.getOwner()}function a(){return Error("react-stack-top-frame")}function c(e){if(K.call(e,"key")){var u=Object.getOwnPropertyDescriptor(e,"key").get;if(u&&u.isReactWarning)return!1}return e.key!==void 0}function i(e,u){function m(){J||(J=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",u))}m.isReactWarning=!0,Object.defineProperty(e,"key",{get:m,configurable:!0})}function f(){var e=r(this.type);return V[e]||(V[e]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),e=this.props.ref,e!==void 0?e:null}function d(e,u,m,y,X,Z){var _=m.ref;return e={$$typeof:E,type:e,key:u,props:m,_owner:y},(_!==void 0?_:null)!==null?Object.defineProperty(e,"ref",{enumerable:!1,get:f}):Object.defineProperty(e,"ref",{enumerable:!1,value:null}),e._store={},Object.defineProperty(e._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(e,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(e,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:X}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:Z}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function p(e,u,m,y,X,Z){var _=u.children;if(_!==void 0)if(y)if(N(_)){for(y=0;y<_.length;y++)R(_[y]);Object.freeze&&Object.freeze(_)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else R(_);if(K.call(u,"key")){_=r(e);var Y=Object.keys(u).filter(function(de){return de!=="key"});y=0<Y.length?"{key: someKey, "+Y.join(": ..., ")+": ...}":"{key: someKey}",se[_+y]||(Y=0<Y.length?"{"+Y.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
18
- let props = %s;
19
- <%s {...props} />
20
- React keys must be passed directly to JSX without using spread:
21
- let props = %s;
22
- <%s key={someKey} {...props} />`,y,_,Y,_),se[_+y]=!0)}if(_=null,m!==void 0&&(o(m),_=""+m),c(u)&&(o(u.key),_=""+u.key),"key"in u){m={};for(var Q in u)Q!=="key"&&(m[Q]=u[Q])}else m=u;return _&&i(m,typeof e=="function"?e.displayName||e.name||"Unknown":e),d(e,_,m,n(),X,Z)}function R(e){b(e)?e._store&&(e._store.validated=1):typeof e=="object"&&e!==null&&e.$$typeof===M&&(e._payload.status==="fulfilled"?b(e._payload.value)&&e._payload.value._store&&(e._payload.value._store.validated=1):e._store&&(e._store.validated=1))}function b(e){return typeof e=="object"&&e!==null&&e.$$typeof===E}var v=l,E=Symbol.for("react.transitional.element"),A=Symbol.for("react.portal"),g=Symbol.for("react.fragment"),I=Symbol.for("react.strict_mode"),D=Symbol.for("react.profiler"),T=Symbol.for("react.consumer"),w=Symbol.for("react.context"),j=Symbol.for("react.forward_ref"),S=Symbol.for("react.suspense"),O=Symbol.for("react.suspense_list"),C=Symbol.for("react.memo"),M=Symbol.for("react.lazy"),P=Symbol.for("react.activity"),$=Symbol.for("react.client.reference"),x=v.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,K=Object.prototype.hasOwnProperty,N=Array.isArray,h=console.createTask?console.createTask:function(){return null};v={react_stack_bottom_frame:function(e){return e()}};var J,V={},k=v.react_stack_bottom_frame.bind(v,a)(),L=h(s(a)),se={};W.Fragment=g,W.jsx=function(e,u,m){var y=1e4>x.recentlyCreatedOwnerStacks++;return p(e,u,m,!1,y?Error("react-stack-top-frame"):k,y?h(s(e)):L)},W.jsxs=function(e,u,m){var y=1e4>x.recentlyCreatedOwnerStacks++;return p(e,u,m,!0,y?Error("react-stack-top-frame"):k,y?h(s(e)):L)}})()),W}var ce;function Ee(){return ce||(ce=1,process.env.NODE_ENV==="production"?G.exports=Re():G.exports=be()),G.exports}var ge=Ee(),ee,fe;function ve(){return fe||(fe=1,ee=function r(t,o){if(t===o)return!0;if(t&&o&&typeof t=="object"&&typeof o=="object"){if(t.constructor!==o.constructor)return!1;var s,n,a;if(Array.isArray(t)){if(s=t.length,s!=o.length)return!1;for(n=s;n--!==0;)if(!r(t[n],o[n]))return!1;return!0}if(t.constructor===RegExp)return t.source===o.source&&t.flags===o.flags;if(t.valueOf!==Object.prototype.valueOf)return t.valueOf()===o.valueOf();if(t.toString!==Object.prototype.toString)return t.toString()===o.toString();if(a=Object.keys(t),s=a.length,s!==Object.keys(o).length)return!1;for(n=s;n--!==0;)if(!Object.prototype.hasOwnProperty.call(o,a[n]))return!1;for(n=s;n--!==0;){var c=a[n];if(!r(t[c],o[c]))return!1}return!0}return t!==t&&o!==o}),ee}var Oe=ve();const je=_e(Oe);function Ae(r,t,o,s){const a=t.slice(0,-1).reduce((i,f)=>{if(!(i==null||typeof i!="object"))return i[f]},o),c=a!=null&&typeof a=="object"&&!Array.isArray(a)?{...a}:{};return r.contextMode==="extended"?((s.formulaDataKey in c||s.formulaPathKey in c)&&console.warn(`[rjsf-formulas] Extended context key collision: sibling field named "${s.formulaDataKey in c?s.formulaDataKey:s.formulaPathKey}" will be overwritten by the injected context. Use formulaDataKey/formulaPathKey props to choose a different key.`),{...c,[s.formulaDataKey]:o,[s.formulaPathKey]:[...t]}):c}function q(r,t){return t.reduce((o,s)=>{if(!(o==null||typeof o!="object"))return o[s]},r)}function te(r,t,o){if(t.length===0)return;const s=q(r,t.slice(0,-1));s!=null&&typeof s=="object"&&(s[t[t.length-1]]=o)}function F(r,t,o=[]){if(r.length===0)return[o];const[s,...n]=r;if(s===H){const a=q(t,o);if(!Array.isArray(a))return[];const c=[];for(let i=0;i<a.length;i++)c.push(...F(n,t,[...o,i]));return c}return F(n,t,[...o,s])}function oe(r,t){return je(r,t)}async function ie(r,t,o,s){const n=structuredClone(r),a=[];for(const f of t)for(const d of F(f.path,n)){const p=Ae(f,d,n,s);a.push({field:f,concretePath:d,context:p})}const c=await Promise.allSettled(a.map(({field:f,context:d})=>new Promise(p=>p(o(f.formula,d))))),i=[];for(let f=0;f<a.length;f++){const{concretePath:d}=a[f],p=c[f];if(p.status==="fulfilled")te(n,d,p.value);else{const R=p.reason instanceof Error?p.reason:new Error(String(p.reason));i.push({path:d,error:R}),te(n,d,void 0)}}return{data:n,errors:i}}function Te(r,t,o){for(const s of o)for(const n of F(s.path,t))if(!oe(q(r,n),q(t,n)))return!1;return!0}async function xe(r,t,o,s,n,a="__formData__",c="__path__"){if(t.length===0)return r;const i={formulaDataKey:a,formulaPathKey:c};let f=r;for(let R=0;R<s;R++){const{data:b,errors:v}=await ie(f,t,o,i);if(Te(f,b,t)){for(const{path:E,error:A}of v)n==null||n(E,A);return b}f=b}const{data:d}=await ie(f,t,o,i),p=structuredClone(d);for(const R of t)for(const b of F(R.path,d))oe(q(f,b),q(d,b))||(n==null||n(b,new Error(`[rjsf-formulas] Formula at [${b.join(", ")}] did not converge after ${s} passes`)),te(p,b,void 0));return p}function he(r){return JSON.stringify(r)}function ke(r,t,o,s,n,a,c,i){const[f,d]=l.useState(r),p=l.useRef(r),R=l.useRef(r),b=l.useRef(new Map),v=l.useRef(null),E=l.useRef(!1),A=l.useRef(a),g=l.useRef(c),I=l.useRef(o),D=l.useRef(t),T=l.useRef(n),w=l.useRef(i);l.useEffect(()=>{A.current=a},[a]),l.useEffect(()=>{g.current=c},[c]),l.useEffect(()=>{I.current=o},[o]),l.useEffect(()=>{D.current=t},[t]),l.useEffect(()=>{T.current=n},[n]),l.useEffect(()=>{w.current=i},[i]);const j=l.useCallback(()=>{if(E.current)return;(async()=>{var P,$;E.current=!0;try{for(;;){const x=p.current,K=D.current,N=[];for(const k of K)for(const L of F(k.path,x))N.push(L);const h=b.current;h.clear();for(const k of N)h.set(he(k),"running");N.length>0&&((P=g.current)==null||P.call(g,N));const J=await xe(x,K,I.current,T.current,A.current,w.current.formulaDataKey,w.current.formulaPathKey);if(C.current)break;const V=[...h.values()].some(k=>k==="dirty");if(h.clear(),!V){d(J),N.length>0&&(($=g.current)==null||$.call(g,[]));break}}}finally{E.current=!1}})()},[]),S=l.useCallback(M=>{p.current=M;const P=b.current;for(const[$,x]of P)x==="running"&&P.set($,"dirty");E.current||(v.current!==null&&clearTimeout(v.current),v.current=setTimeout(()=>{v.current=null,j()},s))},[s,j]),O=l.useRef(!1),C=l.useRef(!1);return l.useEffect(()=>{O.current?oe(r,R.current)||(R.current=r,S(r)):(O.current=!0,R.current=r,S(r))}),l.useEffect(()=>()=>{C.current=!0,v.current!==null&&clearTimeout(v.current)},[]),{enrichedFormData:f,handleInput:S}}function we(r,t){const o=structuredClone(r??{}),s=Se(t);for(const n of t)z(o,n.path,s);return o}function Se(r){const t=new Set;for(let o=0;o<r.length;o++){const s=r[o].path;for(let n=0;n<s.length;n++){const a=s[n];if(typeof a!="number"&&a!==H)continue;const c=ne(s.slice(0,n)),i=typeof a=="number";r.some((d,p)=>{if(p===o||d.path.length<=n||ne(d.path.slice(0,n))!==c)return!1;const R=d.path[n];return i?R===H:typeof R=="number"})&&t.add(c)}}return t}function ne(r){return JSON.stringify(r.map(t=>typeof t=="symbol"?"__ARRAY_INDEX__":t))}function z(r,t,o,s=[]){if(t.length===0){r["ui:readonly"]=!0;return}const[n,...a]=t;if(typeof n=="string"){(!r[n]||typeof r[n]!="object"||Array.isArray(r[n]))&&(r[n]={}),z(r[n],a,o,[...s,n]);return}if(typeof n=="number"){if(r.items!==void 0&&!Array.isArray(r.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(r.items)||(r.items=[]);const f=r.items;(!f[n]||typeof f[n]!="object")&&(f[n]={}),z(f[n],a,o,[...s,n]);return}const c=ne(s);if(o.has(c))(!r.additionalItems||typeof r.additionalItems!="object")&&(r.additionalItems={}),z(r.additionalItems,a,o,[...s,n]);else{if(Array.isArray(r.items)){console.warn("[rjsf-formulas] mergeReadOnly: cannot inject ui:readonly for uniform array because existing uiSchema has items as an array. Skipping.");return}(!r.items||typeof r.items!="object")&&(r.items={}),z(r.items,a,o,[...s,n])}}function Pe(r){const{schema:t,formData:o,uiSchema:s,evaluator:n,Form:a=pe,formulaKey:c="x-formula",formulaContextKey:i="x-formula-context",formulaDataKey:f="__formData__",formulaPathKey:d="__path__",maxConvergencePasses:p=10,debounceMs:R=300,onFormulaError:b,onLoadingChange:v,onChange:E,...A}=r,g=l.useMemo(()=>le(t,{formulaKey:c,formulaContextKey:i}),[t,c,i]),I=l.useMemo(()=>({formulaDataKey:f,formulaPathKey:d}),[f,d]),D=l.useMemo(()=>we(s,g),[s,g]),{enrichedFormData:T,handleInput:w}=ke(o,g,n,R,p,b,v,I),j=l.useRef(E);l.useEffect(()=>{j.current=E},[E]),l.useEffect(()=>{var O;g.length!==0&&((O=j.current)==null||O.call(j,{formData:T},void 0))},[T]);const S=(O,C)=>{w(O.formData),E==null||E(O,C)};return ge.jsx(a,{...A,schema:t,formData:T,uiSchema:D,onChange:S})}exports.FormulaForm=Pe;exports.analyzeSchema=le;
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"),N=Symbol("arrayIndex");function C(e,t){const n=(t==null?void 0:t.formulaKey)??"x-formula",s=(t==null?void 0:t.formulaContextKey)??"x-formula-context",r=(t==null?void 0:t.formulaConflictBehavior)??"warn",f=[];return w(e,[],f,n,s,r,!0,e),f}function J(e,t){if(e===!0)return t;const n=e;return Array.isArray(n.allOf)?{allOf:[...n.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 [${U(t)}], treating as "siblings"`),"siblings")}function U(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,n){const s=Y(e.path);if(n==="error")throw new TypeError(`[rjsf-formulas] Formula conflict at path [${U(e.path)}]: "${e.formula}" vs "${t.formula}". Resolve the conflict or set formulaConflictBehavior to 'ignore' or 'warn'.`);n==="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,n){for(const s of t){const r=Y(s.path),f=e.findIndex(u=>Y(u.path)===r);f!==-1?(ue(e[f],s,n),e[f]=s):e.push(s)}}function w(e,t,n,s,r,f,u,a){const o=e;if(typeof o.$ref=="string"){const c=se.findSchemaDefinition(o.$ref,a);w(c,t,n,s,r,f,u,a);return}if(s in e){const c=o[s];if(typeof c!="string"){console.warn(`[rjsf-formulas] Formula at path [${U(t)}] is not a string (got ${typeof c}), skipping.`);return}n.push({path:t,formula:c,contextMode:ce(o[r],t),condition:u});return}if(e.properties&&e.type!=="array")for(const[c,l]of Object.entries(e.properties))w(l,[...t,c],n,s,r,f,u,a);if(e.type==="array"&&(Array.isArray(o.prefixItems)&&o.prefixItems.forEach((l,y)=>{w(l,[...t,y],n,s,r,f,u,a)}),e.items&&!Array.isArray(e.items)&&w(e.items,[...t,N],n,s,r,f,u,a)),Array.isArray(o.allOf)){const c=o.allOf;for(const l of c){const y=[];w(l,t,y,s,r,f,u,a),ie(n,y,f)}}for(const c of["oneOf","anyOf"])if(Array.isArray(o[c])){const l=o[c];for(const y of l){const m=J(u,y);w(y,t,n,s,r,f,m,a)}}if("if"in o){const c=o.if,l=o.then,y=o.else;if(s in c&&console.warn(`[rjsf-formulas] Formula key "${s}" found inside an "if" schema at path [${U(t)}]. The "if" schema is a validation predicate and is never rendered — the formula will be ignored.`),l!==void 0){const m=J(u,c);w(l,t,n,s,r,f,m,a)}if(y!==void 0){const m=J(u,{not:c});w(y,t,n,s,r,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,n){if(t===n)return!0;if(t&&n&&typeof t=="object"&&typeof n=="object"){if(t.constructor!==n.constructor)return!1;var s,r,f;if(Array.isArray(t)){if(s=t.length,s!=n.length)return!1;for(r=s;r--!==0;)if(!e(t[r],n[r]))return!1;return!0}if(t.constructor===RegExp)return t.source===n.source&&t.flags===n.flags;if(t.valueOf!==Object.prototype.valueOf)return t.valueOf()===n.valueOf();if(t.toString!==Object.prototype.toString)return t.toString()===n.toString();if(f=Object.keys(t),s=f.length,s!==Object.keys(n).length)return!1;for(r=s;r--!==0;)if(!Object.prototype.hasOwnProperty.call(n,f[r]))return!1;for(r=s;r--!==0;){var u=f[r];if(!e(t[u],n[u]))return!1}return!0}return t!==t&&n!==n}),X}var ye=le();const de=ae(ye);function pe(e,t,n,s){const f=t.slice(0,-1).reduce((a,o)=>{if(!(a==null||typeof a!="object"))return a[o]},n),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]:n,[s.formulaPathKey]:[...t]}):u}function B(e){return e.map(t=>typeof t=="symbol"?"[*]":String(t)).join(", ")}function I(e,t){return t.reduce((n,s)=>{if(!(n==null||typeof n!="object"))return n[s]},e)}function V(e,t,n){if(t.length===0)return;const s=I(e,t.slice(0,-1));s!=null&&typeof s=="object"&&(s[t[t.length-1]]=n)}function k(e,t,n=[]){if(e.length===0)return[n];const[s,...r]=e;if(s===N){const f=I(t,n);if(!Array.isArray(f))return[];const u=[];for(let a=0;a<f.length;a++)u.push(...k(r,t,[...n,a]));return u}return k(r,t,[...n,s])}function H(e,t){return de(e,t)}async function L(e,t,n,s){const r=structuredClone(e),f=[];for(const o of t)for(const c of k(o.path,r)){const l=pe(o,c,r,s);f.push({field:o,concretePath:c,context:l})}const u=await Promise.allSettled(f.map(({field:o,context:c})=>new Promise(l=>l(n(o.formula,c))))),a=[];for(let o=0;o<f.length;o++){const{concretePath:c}=f[o],l=u[o];if(l.status==="fulfilled")V(r,c,l.value);else{const y=l.reason instanceof Error?l.reason:new Error(String(l.reason));a.push({path:c,error:y}),V(r,c,void 0)}}return{data:r,errors:a}}function ge(e,t,n){for(const s of n)for(const r of k(s.path,t))if(!H(I(e,r),I(t,r)))return!1;return!0}async function me(e,t,n,s,r,f,u,a,o){const c=t.filter(d=>d.condition===!0||a(d.condition,e));if(c.length===0)return e;const l=new Map,y=[];for(const d of c){const p=JSON.stringify(d.path);if(l.has(p)){if(o==="error")throw new TypeError(`[rjsf-formulas] Formula conflict: two active fields share path [${B(d.path)}]`);o==="warn"&&console.warn(`[rjsf-formulas] Formula conflict: two active fields share path [${B(d.path)}]; taking last`);const g=y.indexOf(l.get(p));y[g]=d,l.set(p,d)}else l.set(p,d),y.push(d)}const m={formulaDataKey:f,formulaPathKey:u};let h=e;for(let d=0;d<s;d++){const{data:p,errors:g}=await L(h,y,n,m);if(ge(h,p,y)){for(const{path:v,error:$}of g)r==null||r(v,$);return p}h=p}const{data:O}=await L(h,y,n,m),j=structuredClone(O);for(const d of y)for(const p of k(d.path,O))H(I(h,p),I(O,p))||(r==null||r(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,n,s,r,f,u,a,o,c){const[l,y]=i.useState(e),m=i.useRef(e),h=i.useRef(e),O=i.useRef(new Map),j=i.useRef(null),d=i.useRef(!1),p=i.useRef(f),g=i.useRef(u),v=i.useRef(n),$=i.useRef(t),P=i.useRef(r),b=i.useRef(a),M=i.useRef(o),x=i.useRef(c);i.useEffect(()=>{p.current=f},[f]),i.useEffect(()=>{g.current=u},[u]),i.useEffect(()=>{v.current=n},[n]),i.useEffect(()=>{$.current=t},[t]),i.useEffect(()=>{P.current=r},[r]),i.useEffect(()=>{b.current=a},[a]),i.useEffect(()=>{M.current=o},[o]),i.useEffect(()=>{x.current=c},[c]);const S=i.useCallback(()=>{if(d.current)return;(async()=>{var _,T;d.current=!0;try{for(;;){const D=m.current,W=$.current,ee=W.filter(A=>A.condition===!0||M.current(A.condition,D)),q=[];for(const A of ee)for(const ne of k(A.path,D))q.push(ne);const K=O.current;K.clear();for(const A of q)K.set(he(A),"running");q.length>0&&((_=g.current)==null||_.call(g,q));const te=await me(D,W,v.current,P.current,p.current,b.current.formulaDataKey,b.current.formulaPathKey,M.current,x.current);if(z.current)break;const re=[...K.values()].some(A=>A==="dirty");if(K.clear(),!re){y(te),q.length>0&&((T=g.current)==null||T.call(g,[]));break}}}finally{d.current=!1}})()},[]),R=i.useCallback(Q=>{m.current=Q;const _=O.current;for(const[T,D]of _)D==="running"&&_.set(T,"dirty");d.current||(j.current!==null&&clearTimeout(j.current),j.current=setTimeout(()=>{j.current=null,S()},s))},[s,S]),E=i.useRef(!1),z=i.useRef(!1);return i.useEffect(()=>{E.current?H(e,h.current)||(h.current=e,R(e)):(E.current=!0,h.current=e,R(e))}),i.useEffect(()=>(z.current=!1,()=>{z.current=!0,E.current=!1,j.current!==null&&clearTimeout(j.current)}),[]),{enrichedFormData:l,handleInput:R}}function Re(e,t){const n=structuredClone(e??{}),s=we(t);for(const r of t)F(n,r.path,s);return n}function we(e){const t=new Set;for(let n=0;n<e.length;n++){const s=e[n].path;for(let r=0;r<s.length;r++){const f=s[r];if(typeof f!="number"&&f!==N)continue;const u=G(s.slice(0,r)),a=typeof f=="number";e.some((c,l)=>{if(l===n||c.path.length<=r||G(c.path.slice(0,r))!==u)return!1;const y=c.path[r];return a?y===N:typeof y=="number"})&&t.add(u)}}return t}function G(e){return JSON.stringify(e.map(t=>typeof t=="symbol"?"__ARRAY_INDEX__":t))}function F(e,t,n,s=[]){if(t.length===0){e["ui:readonly"]=!0;return}const[r,...f]=t;if(typeof r=="string"){(!e[r]||typeof e[r]!="object"||Array.isArray(e[r]))&&(e[r]={}),F(e[r],f,n,[...s,r]);return}if(typeof r=="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[r]||typeof o[r]!="object")&&(o[r]={}),F(o[r],f,n,[...s,r]);return}const u=G(s);if(n.has(u))(!e.additionalItems||typeof e.additionalItems!="object")&&(e.additionalItems={}),F(e.additionalItems,f,n,[...s,r]);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={}),F(e.items,f,n,[...s,r])}}function Oe(e){const{schema:t,formData:n,validator:s,uiSchema:r,evaluator:f,Form:u=oe,formulaKey:a="x-formula",formulaContextKey:o="x-formula-context",formulaDataKey:c="__formData__",formulaPathKey:l="__path__",maxConvergencePasses:y=10,debounceMs:m=300,onFormulaError:h,onLoadingChange:O,formulaConflictBehavior:j="warn",onChange:d,...p}=e,g=i.useMemo(()=>C(t,{formulaKey:a,formulaContextKey:o}),[t,a,o]),v=i.useMemo(()=>({formulaDataKey:c,formulaPathKey:l}),[c,l]),$=i.useMemo(()=>Re(r,g),[r,g]),P=i.useCallback((R,E)=>s.isValid(R,E,t),[s,t]),{enrichedFormData:b,handleInput:M}=je(n,g,f,m,y,h,O,v,P,j),x=i.useRef(d);i.useEffect(()=>{x.current=d},[d]),i.useEffect(()=>{var R;g.length!==0&&((R=x.current)==null||R.call(x,{formData:b},void 0))},[b]);const S=(R,E)=>{M(R.formData),d==null||d(R,E)};return fe.jsx(u,{...p,schema:t,validator:s,formData:b,uiSchema:$,onChange:S})}exports.FormulaForm=Oe;exports.analyzeSchema=C;
package/dist/index.d.cts CHANGED
@@ -8,8 +8,11 @@ import { StrictRJSFSchema } from '@rjsf/utils';
8
8
  * Scans a JSON Schema and returns descriptors for every field that carries a formula key.
9
9
  *
10
10
  * @remarks
11
- * Traversal is depth-first. Schema composition operators (`$ref`, `oneOf`, `anyOf`, `allOf`)
12
- * are not supported and emit a `console.warn` when encountered.
11
+ * Traversal is depth-first. `allOf`, `$ref`, `oneOf`, and `anyOf` are all supported.
12
+ * `allOf` branches are merged with conflict detection. `oneOf`/`anyOf` branches are each
13
+ * recursed and fields are collected with the branch schema as the `condition`. Nested
14
+ * `oneOf`/`anyOf` conditions are composed via `{ allOf: [...] }`. `$ref` is resolved
15
+ * synchronously using `findSchemaDefinition` (external refs will throw).
13
16
  *
14
17
  * @param schema - The root RJSF schema to scan.
15
18
  * @param options - Optional key overrides for locating formulas in the schema.
@@ -40,6 +43,14 @@ export declare type AnalyzeSchemaOptions = {
40
43
  formulaKey?: string;
41
44
  /** Schema key that selects the context mode for a computed field. Defaults to `'x-formula-context'`. */
42
45
  formulaContextKey?: string;
46
+ /**
47
+ * What to do when multiple `allOf` branches define a formula for the same path.
48
+ *
49
+ * - `'ignore'`: silently take the last definition.
50
+ * - `'warn'` (default): emit `console.warn` and take the last definition.
51
+ * - `'error'`: throw a `TypeError` synchronously.
52
+ */
53
+ formulaConflictBehavior?: 'ignore' | 'warn' | 'error';
43
54
  };
44
55
 
45
56
  /* Excluded from this release type: ARRAY_INDEX */
@@ -67,6 +78,14 @@ export declare type FormulaField = {
67
78
  formula: string;
68
79
  /** Which values are available when evaluating this field's formula. */
69
80
  contextMode: ContextMode;
81
+ /**
82
+ * The schema condition under which this formula is active.
83
+ *
84
+ * - `true` — always active (fields from `properties`, `items`, `prefixItems`, or `allOf` branches).
85
+ * - `RJSFSchema` — a conditional schema (a `oneOf`/`anyOf` branch condition, possibly composed
86
+ * via `{ allOf: [...] }` for nested branches).
87
+ */
88
+ condition: RJSFSchema | true;
70
89
  };
71
90
 
72
91
  /**
@@ -170,6 +189,15 @@ export declare type FormulaFormProps<T = any, S extends StrictRJSFSchema = RJSFS
170
189
  * @param loadingPaths - Paths of all fields whose evaluations are in progress.
171
190
  */
172
191
  onLoadingChange?: (loadingPaths: (string | number)[][]) => void;
192
+ /**
193
+ * What to do when multiple branches of a composition operator (`allOf` at schema-analysis
194
+ * time, or simultaneously-active `oneOf`/`anyOf` branches at evaluation time) define a
195
+ * formula for the same field path.
196
+ * - `'ignore'` — silently take the last definition.
197
+ * - `'warn'` (default) — emit `console.warn` and take the last definition.
198
+ * - `'error'` — throw a `TypeError` synchronously (useful during development).
199
+ */
200
+ formulaConflictBehavior?: 'ignore' | 'warn' | 'error';
173
201
  };
174
202
 
175
203
  export { }
package/dist/index.d.mts CHANGED
@@ -8,8 +8,11 @@ import { StrictRJSFSchema } from '@rjsf/utils';
8
8
  * Scans a JSON Schema and returns descriptors for every field that carries a formula key.
9
9
  *
10
10
  * @remarks
11
- * Traversal is depth-first. Schema composition operators (`$ref`, `oneOf`, `anyOf`, `allOf`)
12
- * are not supported and emit a `console.warn` when encountered.
11
+ * Traversal is depth-first. `allOf`, `$ref`, `oneOf`, and `anyOf` are all supported.
12
+ * `allOf` branches are merged with conflict detection. `oneOf`/`anyOf` branches are each
13
+ * recursed and fields are collected with the branch schema as the `condition`. Nested
14
+ * `oneOf`/`anyOf` conditions are composed via `{ allOf: [...] }`. `$ref` is resolved
15
+ * synchronously using `findSchemaDefinition` (external refs will throw).
13
16
  *
14
17
  * @param schema - The root RJSF schema to scan.
15
18
  * @param options - Optional key overrides for locating formulas in the schema.
@@ -40,6 +43,14 @@ export declare type AnalyzeSchemaOptions = {
40
43
  formulaKey?: string;
41
44
  /** Schema key that selects the context mode for a computed field. Defaults to `'x-formula-context'`. */
42
45
  formulaContextKey?: string;
46
+ /**
47
+ * What to do when multiple `allOf` branches define a formula for the same path.
48
+ *
49
+ * - `'ignore'`: silently take the last definition.
50
+ * - `'warn'` (default): emit `console.warn` and take the last definition.
51
+ * - `'error'`: throw a `TypeError` synchronously.
52
+ */
53
+ formulaConflictBehavior?: 'ignore' | 'warn' | 'error';
43
54
  };
44
55
 
45
56
  /* Excluded from this release type: ARRAY_INDEX */
@@ -67,6 +78,14 @@ export declare type FormulaField = {
67
78
  formula: string;
68
79
  /** Which values are available when evaluating this field's formula. */
69
80
  contextMode: ContextMode;
81
+ /**
82
+ * The schema condition under which this formula is active.
83
+ *
84
+ * - `true` — always active (fields from `properties`, `items`, `prefixItems`, or `allOf` branches).
85
+ * - `RJSFSchema` — a conditional schema (a `oneOf`/`anyOf` branch condition, possibly composed
86
+ * via `{ allOf: [...] }` for nested branches).
87
+ */
88
+ condition: RJSFSchema | true;
70
89
  };
71
90
 
72
91
  /**
@@ -170,6 +189,15 @@ export declare type FormulaFormProps<T = any, S extends StrictRJSFSchema = RJSFS
170
189
  * @param loadingPaths - Paths of all fields whose evaluations are in progress.
171
190
  */
172
191
  onLoadingChange?: (loadingPaths: (string | number)[][]) => void;
192
+ /**
193
+ * What to do when multiple branches of a composition operator (`allOf` at schema-analysis
194
+ * time, or simultaneously-active `oneOf`/`anyOf` branches at evaluation time) define a
195
+ * formula for the same field path.
196
+ * - `'ignore'` — silently take the last definition.
197
+ * - `'warn'` (default) — emit `console.warn` and take the last definition.
198
+ * - `'error'` — throw a `TypeError` synchronously (useful during development).
199
+ */
200
+ formulaConflictBehavior?: 'ignore' | 'warn' | 'error';
173
201
  };
174
202
 
175
203
  export { }
package/dist/index.mjs CHANGED
@@ -1,654 +1,465 @@
1
- import ye, { useState as _e, useRef as v, useEffect as j, useCallback as ce, useMemo as re } from "react";
2
- import be from "@rjsf/core";
3
- const Z = Symbol("arrayIndex");
4
- function Re(r, t) {
5
- const o = (t == null ? void 0 : t.formulaKey) ?? "x-formula", s = (t == null ? void 0 : t.formulaContextKey) ?? "x-formula-context", n = [];
6
- return H(r, [], n, o, s), n;
1
+ import { findSchemaDefinition as ft } from "@rjsf/utils";
2
+ import { jsx as ct } from "react/jsx-runtime";
3
+ import { useState as it, useRef as m, useEffect as h, useCallback as G, useMemo as X } from "react";
4
+ import ut from "@rjsf/core";
5
+ const N = Symbol("arrayIndex");
6
+ function at(t, e) {
7
+ const n = (e == null ? void 0 : e.formulaKey) ?? "x-formula", s = (e == null ? void 0 : e.formulaContextKey) ?? "x-formula-context", r = (e == null ? void 0 : e.formulaConflictBehavior) ?? "warn", o = [];
8
+ return A(t, [], o, n, s, r, !0, t), o;
7
9
  }
8
- const Ee = ["$ref", "oneOf", "anyOf", "allOf"];
9
- function ge(r, t) {
10
- return r === void 0 || r === "siblings" ? "siblings" : r === "extended" ? "extended" : (console.warn(
11
- `[rjsf-formulas] Unknown x-formula-context value "${r}" at path [${ne(t)}], treating as "siblings"`
10
+ function Y(t, e) {
11
+ if (t === !0) return e;
12
+ const n = t;
13
+ return Array.isArray(n.allOf) ? { allOf: [...n.allOf, e] } : { allOf: [t, e] };
14
+ }
15
+ function lt(t, e) {
16
+ return t === void 0 || t === "siblings" ? "siblings" : t === "extended" ? "extended" : (console.warn(
17
+ `[rjsf-formulas] Unknown x-formula-context value "${t}" at path [${U(e)}], treating as "siblings"`
12
18
  ), "siblings");
13
19
  }
14
- function ne(r) {
15
- return r.map((t) => typeof t == "symbol" ? "[*]" : String(t)).join(", ");
20
+ function U(t) {
21
+ return t.map((e) => typeof e == "symbol" ? "[*]" : String(e)).join(", ");
22
+ }
23
+ function H(t) {
24
+ return t.map((e) => typeof e == "symbol" ? "[*]" : String(e)).join(".");
16
25
  }
17
- function H(r, t, o, s, n) {
18
- for (const a of Ee)
19
- a in r && console.warn(
20
- `[rjsf-formulas] Schema composition operator "${a}" at path [${ne(t)}] is not supported and will be skipped. See issue 06.`
26
+ function pt(t, e, n) {
27
+ const s = H(t.path);
28
+ if (n === "error")
29
+ throw new TypeError(
30
+ `[rjsf-formulas] Formula conflict at path [${U(t.path)}]: "${t.formula}" vs "${e.formula}". Resolve the conflict or set formulaConflictBehavior to 'ignore' or 'warn'.`
21
31
  );
22
- if (s in r) {
23
- const a = r[s];
24
- if (typeof a != "string") {
32
+ n === "warn" && console.warn(
33
+ `[rjsf-formulas] Formula conflict at path [${s}]: "${t.formula}" (earlier allOf branch) is overridden by "${e.formula}" (later allOf branch).`
34
+ );
35
+ }
36
+ function yt(t, e, n) {
37
+ for (const s of e) {
38
+ const r = H(s.path), o = t.findIndex((i) => H(i.path) === r);
39
+ o !== -1 ? (pt(t[o], s, n), t[o] = s) : t.push(s);
40
+ }
41
+ }
42
+ function A(t, e, n, s, r, o, i, u) {
43
+ const f = t;
44
+ if (typeof f.$ref == "string") {
45
+ const c = ft(f.$ref, u);
46
+ A(c, e, n, s, r, o, i, u);
47
+ return;
48
+ }
49
+ if (s in t) {
50
+ const c = f[s];
51
+ if (typeof c != "string") {
25
52
  console.warn(
26
- `[rjsf-formulas] Formula at path [${ne(t)}] is not a string (got ${typeof a}), skipping.`
53
+ `[rjsf-formulas] Formula at path [${U(e)}] is not a string (got ${typeof c}), skipping.`
27
54
  );
28
55
  return;
29
56
  }
30
- o.push({
31
- path: t,
32
- formula: a,
33
- contextMode: ge(
34
- r[n],
35
- t
36
- )
57
+ n.push({
58
+ path: e,
59
+ formula: c,
60
+ contextMode: lt(f[r], e),
61
+ condition: i
37
62
  });
38
63
  return;
39
64
  }
40
- if (r.type === "object" && r.properties)
41
- for (const [a, c] of Object.entries(r.properties))
42
- H(
43
- c,
44
- [...t, a],
45
- o,
65
+ if (t.properties && t.type !== "array")
66
+ for (const [c, a] of Object.entries(t.properties))
67
+ A(
68
+ a,
69
+ [...e, c],
70
+ n,
46
71
  s,
47
- n
72
+ r,
73
+ o,
74
+ i,
75
+ u
48
76
  );
49
- if (r.type === "array") {
50
- const a = r;
51
- Array.isArray(a.prefixItems) && a.prefixItems.forEach((f, i) => {
52
- H(f, [...t, i], o, s, n);
53
- }), r.items && !Array.isArray(r.items) && H(
54
- r.items,
55
- [...t, Z],
56
- o,
57
- s,
58
- n
59
- );
60
- }
61
- }
62
- function ve(r) {
63
- return r && r.__esModule && Object.prototype.hasOwnProperty.call(r, "default") ? r.default : r;
64
- }
65
- var B = { exports: {} }, W = {};
66
- /**
67
- * @license React
68
- * react-jsx-runtime.production.js
69
- *
70
- * Copyright (c) Meta Platforms, Inc. and affiliates.
71
- *
72
- * This source code is licensed under the MIT license found in the
73
- * LICENSE file in the root directory of this source tree.
74
- */
75
- var ie;
76
- function Oe() {
77
- if (ie) return W;
78
- ie = 1;
79
- var r = Symbol.for("react.transitional.element"), t = Symbol.for("react.fragment");
80
- function o(s, n, a) {
81
- var c = null;
82
- if (a !== void 0 && (c = "" + a), n.key !== void 0 && (c = "" + n.key), "key" in n) {
83
- a = {};
84
- for (var f in n)
85
- f !== "key" && (a[f] = n[f]);
86
- } else a = n;
87
- return n = a.ref, {
88
- $$typeof: r,
89
- type: s,
90
- key: c,
91
- ref: n !== void 0 ? n : null,
92
- props: a
93
- };
94
- }
95
- return W.Fragment = t, W.jsx = o, W.jsxs = o, W;
96
- }
97
- var J = {};
98
- /**
99
- * @license React
100
- * react-jsx-runtime.development.js
101
- *
102
- * Copyright (c) Meta Platforms, Inc. and affiliates.
103
- *
104
- * This source code is licensed under the MIT license found in the
105
- * LICENSE file in the root directory of this source tree.
106
- */
107
- var fe;
108
- function je() {
109
- return fe || (fe = 1, process.env.NODE_ENV !== "production" && (function() {
110
- function r(e) {
111
- if (e == null) return null;
112
- if (typeof e == "function")
113
- return e.$$typeof === Y ? null : e.displayName || e.name || null;
114
- if (typeof e == "string") return e;
115
- switch (e) {
116
- case E:
117
- return "Fragment";
118
- case $:
119
- return "Profiler";
120
- case D:
121
- return "StrictMode";
122
- case P:
123
- return "Suspense";
124
- case O:
125
- return "SuspenseList";
126
- case N:
127
- return "Activity";
128
- }
129
- if (typeof e == "object")
130
- switch (typeof e.tag == "number" && console.error(
131
- "Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
132
- ), e.$$typeof) {
133
- case x:
134
- return "Portal";
135
- case S:
136
- return e.displayName || "Context";
137
- case T:
138
- return (e._context.displayName || "Context") + ".Consumer";
139
- case A:
140
- var u = e.render;
141
- return e = e.displayName, e || (e = u.displayName || u.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e;
142
- case C:
143
- return u = e.displayName || null, u !== null ? u : r(e.type) || "Memo";
144
- case M:
145
- u = e._payload, e = e._init;
146
- try {
147
- return r(e(u));
148
- } catch {
149
- }
150
- }
151
- return null;
152
- }
153
- function t(e) {
154
- return "" + e;
155
- }
156
- function o(e) {
157
- try {
158
- t(e);
159
- var u = !1;
160
- } catch {
161
- u = !0;
162
- }
163
- if (u) {
164
- u = console;
165
- var p = u.error, m = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
166
- return p.call(
167
- u,
168
- "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
169
- m
170
- ), t(e);
171
- }
172
- }
173
- function s(e) {
174
- if (e === E) return "<>";
175
- if (typeof e == "object" && e !== null && e.$$typeof === M)
176
- return "<...>";
177
- try {
178
- var u = r(e);
179
- return u ? "<" + u + ">" : "<...>";
180
- } catch {
181
- return "<...>";
182
- }
183
- }
184
- function n() {
185
- var e = h.A;
186
- return e === null ? null : e.getOwner();
187
- }
188
- function a() {
189
- return Error("react-stack-top-frame");
190
- }
191
- function c(e) {
192
- if (F.call(e, "key")) {
193
- var u = Object.getOwnPropertyDescriptor(e, "key").get;
194
- if (u && u.isReactWarning) return !1;
195
- }
196
- return e.key !== void 0;
197
- }
198
- function f(e, u) {
199
- function p() {
200
- V || (V = !0, console.error(
201
- "%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
202
- u
203
- ));
204
- }
205
- p.isReactWarning = !0, Object.defineProperty(e, "key", {
206
- get: p,
207
- configurable: !0
208
- });
209
- }
210
- function i() {
211
- var e = r(this.type);
212
- return L[e] || (L[e] = !0, console.error(
213
- "Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
214
- )), e = this.props.ref, e !== void 0 ? e : null;
215
- }
216
- function l(e, u, p, m, G, Q) {
217
- var y = p.ref;
218
- return e = {
219
- $$typeof: R,
220
- type: e,
221
- key: u,
222
- props: p,
223
- _owner: m
224
- }, (y !== void 0 ? y : null) !== null ? Object.defineProperty(e, "ref", {
225
- enumerable: !1,
226
- get: i
227
- }) : Object.defineProperty(e, "ref", { enumerable: !1, value: null }), e._store = {}, Object.defineProperty(e._store, "validated", {
228
- configurable: !1,
229
- enumerable: !1,
230
- writable: !0,
231
- value: 0
232
- }), Object.defineProperty(e, "_debugInfo", {
233
- configurable: !1,
234
- enumerable: !1,
235
- writable: !0,
236
- value: null
237
- }), Object.defineProperty(e, "_debugStack", {
238
- configurable: !1,
239
- enumerable: !1,
240
- writable: !0,
241
- value: G
242
- }), Object.defineProperty(e, "_debugTask", {
243
- configurable: !1,
244
- enumerable: !1,
245
- writable: !0,
246
- value: Q
247
- }), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
77
+ if (t.type === "array" && (Array.isArray(f.prefixItems) && f.prefixItems.forEach((a, l) => {
78
+ A(a, [...e, l], n, s, r, o, i, u);
79
+ }), t.items && !Array.isArray(t.items) && A(
80
+ t.items,
81
+ [...e, N],
82
+ n,
83
+ s,
84
+ r,
85
+ o,
86
+ i,
87
+ u
88
+ )), Array.isArray(f.allOf)) {
89
+ const c = f.allOf;
90
+ for (const a of c) {
91
+ const l = [];
92
+ A(a, e, l, s, r, o, i, u), yt(n, l, o);
248
93
  }
249
- function d(e, u, p, m, G, Q) {
250
- var y = u.children;
251
- if (y !== void 0)
252
- if (m)
253
- if (I(y)) {
254
- for (m = 0; m < y.length; m++)
255
- _(y[m]);
256
- Object.freeze && Object.freeze(y);
257
- } else
258
- console.error(
259
- "React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
260
- );
261
- else _(y);
262
- if (F.call(u, "key")) {
263
- y = r(e);
264
- var q = Object.keys(u).filter(function(me) {
265
- return me !== "key";
266
- });
267
- m = 0 < q.length ? "{key: someKey, " + q.join(": ..., ") + ": ...}" : "{key: someKey}", ue[y + m] || (q = 0 < q.length ? "{" + q.join(": ..., ") + ": ...}" : "{}", console.error(
268
- `A props object containing a "key" prop is being spread into JSX:
269
- let props = %s;
270
- <%s {...props} />
271
- React keys must be passed directly to JSX without using spread:
272
- let props = %s;
273
- <%s key={someKey} {...props} />`,
274
- m,
275
- y,
276
- q,
277
- y
278
- ), ue[y + m] = !0);
94
+ }
95
+ for (const c of ["oneOf", "anyOf"])
96
+ if (Array.isArray(f[c])) {
97
+ const a = f[c];
98
+ for (const l of a) {
99
+ const g = Y(i, l);
100
+ A(l, e, n, s, r, o, g, u);
279
101
  }
280
- if (y = null, p !== void 0 && (o(p), y = "" + p), c(u) && (o(u.key), y = "" + u.key), "key" in u) {
281
- p = {};
282
- for (var ee in u)
283
- ee !== "key" && (p[ee] = u[ee]);
284
- } else p = u;
285
- return y && f(
286
- p,
287
- typeof e == "function" ? e.displayName || e.name || "Unknown" : e
288
- ), l(
289
- e,
290
- y,
291
- p,
292
- n(),
293
- G,
294
- Q
295
- );
296
102
  }
297
- function _(e) {
298
- b(e) ? e._store && (e._store.validated = 1) : typeof e == "object" && e !== null && e.$$typeof === M && (e._payload.status === "fulfilled" ? b(e._payload.value) && e._payload.value._store && (e._payload.value._store.validated = 1) : e._store && (e._store.validated = 1));
103
+ if ("if" in f) {
104
+ const c = f.if, a = f.then, l = f.else;
105
+ if (s in c && console.warn(
106
+ `[rjsf-formulas] Formula key "${s}" found inside an "if" schema at path [${U(e)}]. The "if" schema is a validation predicate and is never rendered — the formula will be ignored.`
107
+ ), a !== void 0) {
108
+ const g = Y(i, c);
109
+ A(a, e, n, s, r, o, g, u);
299
110
  }
300
- function b(e) {
301
- return typeof e == "object" && e !== null && e.$$typeof === R;
111
+ if (l !== void 0) {
112
+ const g = Y(i, { not: c });
113
+ A(l, e, n, s, r, o, g, u);
302
114
  }
303
- var g = ye, R = Symbol.for("react.transitional.element"), x = Symbol.for("react.portal"), E = Symbol.for("react.fragment"), D = Symbol.for("react.strict_mode"), $ = Symbol.for("react.profiler"), T = Symbol.for("react.consumer"), S = Symbol.for("react.context"), A = Symbol.for("react.forward_ref"), P = Symbol.for("react.suspense"), O = Symbol.for("react.suspense_list"), C = Symbol.for("react.memo"), M = Symbol.for("react.lazy"), N = Symbol.for("react.activity"), Y = Symbol.for("react.client.reference"), h = g.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, F = Object.prototype.hasOwnProperty, I = Array.isArray, k = console.createTask ? console.createTask : function() {
304
- return null;
305
- };
306
- g = {
307
- react_stack_bottom_frame: function(e) {
308
- return e();
309
- }
310
- };
311
- var V, L = {}, w = g.react_stack_bottom_frame.bind(
312
- g,
313
- a
314
- )(), X = k(s(a)), ue = {};
315
- J.Fragment = E, J.jsx = function(e, u, p) {
316
- var m = 1e4 > h.recentlyCreatedOwnerStacks++;
317
- return d(
318
- e,
319
- u,
320
- p,
321
- !1,
322
- m ? Error("react-stack-top-frame") : w,
323
- m ? k(s(e)) : X
324
- );
325
- }, J.jsxs = function(e, u, p) {
326
- var m = 1e4 > h.recentlyCreatedOwnerStacks++;
327
- return d(
328
- e,
329
- u,
330
- p,
331
- !0,
332
- m ? Error("react-stack-top-frame") : w,
333
- m ? k(s(e)) : X
334
- );
335
- };
336
- })()), J;
115
+ }
337
116
  }
338
- var le;
339
- function Ae() {
340
- return le || (le = 1, process.env.NODE_ENV === "production" ? B.exports = Oe() : B.exports = je()), B.exports;
117
+ function dt(t) {
118
+ return t && t.__esModule && Object.prototype.hasOwnProperty.call(t, "default") ? t.default : t;
341
119
  }
342
- var xe = Ae(), te, de;
343
- function Te() {
344
- return de || (de = 1, te = function r(t, o) {
345
- if (t === o) return !0;
346
- if (t && o && typeof t == "object" && typeof o == "object") {
347
- if (t.constructor !== o.constructor) return !1;
348
- var s, n, a;
349
- if (Array.isArray(t)) {
350
- if (s = t.length, s != o.length) return !1;
351
- for (n = s; n-- !== 0; )
352
- if (!r(t[n], o[n])) return !1;
120
+ var V, C;
121
+ function mt() {
122
+ return C || (C = 1, V = function t(e, n) {
123
+ if (e === n) return !0;
124
+ if (e && n && typeof e == "object" && typeof n == "object") {
125
+ if (e.constructor !== n.constructor) return !1;
126
+ var s, r, o;
127
+ if (Array.isArray(e)) {
128
+ if (s = e.length, s != n.length) return !1;
129
+ for (r = s; r-- !== 0; )
130
+ if (!t(e[r], n[r])) return !1;
353
131
  return !0;
354
132
  }
355
- if (t.constructor === RegExp) return t.source === o.source && t.flags === o.flags;
356
- if (t.valueOf !== Object.prototype.valueOf) return t.valueOf() === o.valueOf();
357
- if (t.toString !== Object.prototype.toString) return t.toString() === o.toString();
358
- if (a = Object.keys(t), s = a.length, s !== Object.keys(o).length) return !1;
359
- for (n = s; n-- !== 0; )
360
- if (!Object.prototype.hasOwnProperty.call(o, a[n])) return !1;
361
- for (n = s; n-- !== 0; ) {
362
- var c = a[n];
363
- if (!r(t[c], o[c])) return !1;
133
+ if (e.constructor === RegExp) return e.source === n.source && e.flags === n.flags;
134
+ if (e.valueOf !== Object.prototype.valueOf) return e.valueOf() === n.valueOf();
135
+ if (e.toString !== Object.prototype.toString) return e.toString() === n.toString();
136
+ if (o = Object.keys(e), s = o.length, s !== Object.keys(n).length) return !1;
137
+ for (r = s; r-- !== 0; )
138
+ if (!Object.prototype.hasOwnProperty.call(n, o[r])) return !1;
139
+ for (r = s; r-- !== 0; ) {
140
+ var i = o[r];
141
+ if (!t(e[i], n[i])) return !1;
364
142
  }
365
143
  return !0;
366
144
  }
367
- return t !== t && o !== o;
368
- }), te;
145
+ return e !== e && n !== n;
146
+ }), V;
369
147
  }
370
- var he = Te();
371
- const ke = /* @__PURE__ */ ve(he);
372
- function we(r, t, o, s) {
373
- const a = t.slice(0, -1).reduce((f, i) => {
374
- if (!(f == null || typeof f != "object"))
375
- return f[i];
376
- }, o), c = a != null && typeof a == "object" && !Array.isArray(a) ? { ...a } : {};
377
- return r.contextMode === "extended" ? ((s.formulaDataKey in c || s.formulaPathKey in c) && console.warn(
378
- `[rjsf-formulas] Extended context key collision: sibling field named "${s.formulaDataKey in c ? s.formulaDataKey : s.formulaPathKey}" will be overwritten by the injected context. Use formulaDataKey/formulaPathKey props to choose a different key.`
148
+ var gt = mt();
149
+ const ht = /* @__PURE__ */ dt(gt);
150
+ function jt(t, e, n, s) {
151
+ const o = e.slice(0, -1).reduce((u, f) => {
152
+ if (!(u == null || typeof u != "object"))
153
+ return u[f];
154
+ }, n), i = o != null && typeof o == "object" && !Array.isArray(o) ? { ...o } : {};
155
+ return t.contextMode === "extended" ? ((s.formulaDataKey in i || s.formulaPathKey in i) && console.warn(
156
+ `[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.`
379
157
  ), {
380
- ...c,
381
- [s.formulaDataKey]: o,
382
- [s.formulaPathKey]: [...t]
383
- }) : c;
158
+ ...i,
159
+ [s.formulaDataKey]: n,
160
+ [s.formulaPathKey]: [...e]
161
+ }) : i;
384
162
  }
385
- function K(r, t) {
386
- return t.reduce((o, s) => {
387
- if (!(o == null || typeof o != "object"))
388
- return o[s];
389
- }, r);
163
+ function tt(t) {
164
+ return t.map((e) => typeof e == "symbol" ? "[*]" : String(e)).join(", ");
390
165
  }
391
- function oe(r, t, o) {
392
- if (t.length === 0) return;
393
- const s = K(r, t.slice(0, -1));
394
- s != null && typeof s == "object" && (s[t[t.length - 1]] = o);
166
+ function k(t, e) {
167
+ return e.reduce((n, s) => {
168
+ if (!(n == null || typeof n != "object"))
169
+ return n[s];
170
+ }, t);
395
171
  }
396
- function U(r, t, o = []) {
397
- if (r.length === 0) return [o];
398
- const [s, ...n] = r;
399
- if (s === Z) {
400
- const a = K(t, o);
401
- if (!Array.isArray(a)) return [];
402
- const c = [];
403
- for (let f = 0; f < a.length; f++)
404
- c.push(...U(n, t, [...o, f]));
405
- return c;
172
+ function Q(t, e, n) {
173
+ if (e.length === 0) return;
174
+ const s = k(t, e.slice(0, -1));
175
+ s != null && typeof s == "object" && (s[e[e.length - 1]] = n);
176
+ }
177
+ function D(t, e, n = []) {
178
+ if (t.length === 0) return [n];
179
+ const [s, ...r] = t;
180
+ if (s === N) {
181
+ const o = k(e, n);
182
+ if (!Array.isArray(o)) return [];
183
+ const i = [];
184
+ for (let u = 0; u < o.length; u++)
185
+ i.push(...D(r, e, [...n, u]));
186
+ return i;
406
187
  }
407
- return U(n, t, [...o, s]);
188
+ return D(r, e, [...n, s]);
408
189
  }
409
- function ae(r, t) {
410
- return ke(r, t);
190
+ function Z(t, e) {
191
+ return ht(t, e);
411
192
  }
412
- async function pe(r, t, o, s) {
413
- const n = structuredClone(r), a = [];
414
- for (const i of t)
415
- for (const l of U(i.path, n)) {
416
- const d = we(i, l, n, s);
417
- a.push({ field: i, concretePath: l, context: d });
193
+ async function et(t, e, n, s) {
194
+ const r = structuredClone(t), o = [];
195
+ for (const f of e)
196
+ for (const c of D(f.path, r)) {
197
+ const a = jt(f, c, r, s);
198
+ o.push({ field: f, concretePath: c, context: a });
418
199
  }
419
- const c = await Promise.allSettled(
420
- a.map(({ field: i, context: l }) => new Promise((d) => d(o(i.formula, l))))
421
- ), f = [];
422
- for (let i = 0; i < a.length; i++) {
423
- const { concretePath: l } = a[i], d = c[i];
424
- if (d.status === "fulfilled")
425
- oe(n, l, d.value);
200
+ const i = await Promise.allSettled(
201
+ o.map(({ field: f, context: c }) => new Promise((a) => a(n(f.formula, c))))
202
+ ), u = [];
203
+ for (let f = 0; f < o.length; f++) {
204
+ const { concretePath: c } = o[f], a = i[f];
205
+ if (a.status === "fulfilled")
206
+ Q(r, c, a.value);
426
207
  else {
427
- const _ = d.reason instanceof Error ? d.reason : new Error(String(d.reason));
428
- f.push({ path: l, error: _ }), oe(n, l, void 0);
208
+ const l = a.reason instanceof Error ? a.reason : new Error(String(a.reason));
209
+ u.push({ path: c, error: l }), Q(r, c, void 0);
429
210
  }
430
211
  }
431
- return { data: n, errors: f };
212
+ return { data: r, errors: u };
432
213
  }
433
- function Se(r, t, o) {
434
- for (const s of o)
435
- for (const n of U(s.path, t))
436
- if (!ae(K(r, n), K(t, n)))
214
+ function wt(t, e, n) {
215
+ for (const s of n)
216
+ for (const r of D(s.path, e))
217
+ if (!Z(k(t, r), k(e, r)))
437
218
  return !1;
438
219
  return !0;
439
220
  }
440
- async function Pe(r, t, o, s, n, a = "__formData__", c = "__path__") {
441
- if (t.length === 0) return r;
442
- const f = { formulaDataKey: a, formulaPathKey: c };
443
- let i = r;
444
- for (let _ = 0; _ < s; _++) {
445
- const { data: b, errors: g } = await pe(i, t, o, f);
446
- if (Se(i, b, t)) {
447
- for (const { path: R, error: x } of g)
448
- n == null || n(R, x);
449
- return b;
221
+ async function Ot(t, e, n, s, r, o, i, u, f) {
222
+ const c = e.filter(
223
+ (p) => p.condition === !0 || u(p.condition, t)
224
+ );
225
+ if (c.length === 0) return t;
226
+ const a = /* @__PURE__ */ new Map(), l = [];
227
+ for (const p of c) {
228
+ const y = JSON.stringify(p.path);
229
+ if (a.has(y)) {
230
+ if (f === "error")
231
+ throw new TypeError(
232
+ `[rjsf-formulas] Formula conflict: two active fields share path [${tt(p.path)}]`
233
+ );
234
+ f === "warn" && console.warn(
235
+ `[rjsf-formulas] Formula conflict: two active fields share path [${tt(p.path)}]; taking last`
236
+ );
237
+ const d = l.indexOf(a.get(y));
238
+ l[d] = p, a.set(y, p);
239
+ } else
240
+ a.set(y, p), l.push(p);
241
+ }
242
+ const g = { formulaDataKey: o, formulaPathKey: i };
243
+ let j = t;
244
+ for (let p = 0; p < s; p++) {
245
+ const { data: y, errors: d } = await et(j, l, n, g);
246
+ if (wt(j, y, l)) {
247
+ for (const { path: I, error: _ } of d)
248
+ r == null || r(I, _);
249
+ return y;
450
250
  }
451
- i = b;
251
+ j = y;
452
252
  }
453
- const { data: l } = await pe(i, t, o, f), d = structuredClone(l);
454
- for (const _ of t)
455
- for (const b of U(_.path, l))
456
- ae(K(i, b), K(l, b)) || (n == null || n(
457
- b,
253
+ const { data: x } = await et(j, l, n, g), w = structuredClone(x);
254
+ for (const p of l)
255
+ for (const y of D(p.path, x))
256
+ Z(k(j, y), k(x, y)) || (r == null || r(
257
+ y,
458
258
  new Error(
459
- `[rjsf-formulas] Formula at [${b.join(", ")}] did not converge after ${s} passes`
259
+ `[rjsf-formulas] Formula at [${y.join(", ")}] did not converge after ${s} passes`
460
260
  )
461
- ), oe(d, b, void 0));
462
- return d;
261
+ ), Q(w, y, void 0));
262
+ return w;
463
263
  }
464
- function Ne(r) {
465
- return JSON.stringify(r);
264
+ function At(t) {
265
+ return JSON.stringify(t);
466
266
  }
467
- function Ie(r, t, o, s, n, a, c, f) {
468
- const [i, l] = _e(r), d = v(r), _ = v(r), b = v(/* @__PURE__ */ new Map()), g = v(null), R = v(!1), x = v(a), E = v(c), D = v(o), $ = v(t), T = v(n), S = v(f);
469
- j(() => {
470
- x.current = a;
471
- }, [a]), j(() => {
472
- E.current = c;
473
- }, [c]), j(() => {
474
- D.current = o;
475
- }, [o]), j(() => {
476
- $.current = t;
477
- }, [t]), j(() => {
478
- T.current = n;
479
- }, [n]), j(() => {
480
- S.current = f;
481
- }, [f]);
482
- const A = ce(() => {
483
- if (R.current) return;
267
+ function xt(t, e, n, s, r, o, i, u, f, c) {
268
+ const [a, l] = it(t), g = m(t), j = m(t), x = m(/* @__PURE__ */ new Map()), w = m(null), p = m(!1), y = m(o), d = m(i), I = m(n), _ = m(e), T = m(r), R = m(u), M = m(f), $ = m(c);
269
+ h(() => {
270
+ y.current = o;
271
+ }, [o]), h(() => {
272
+ d.current = i;
273
+ }, [i]), h(() => {
274
+ I.current = n;
275
+ }, [n]), h(() => {
276
+ _.current = e;
277
+ }, [e]), h(() => {
278
+ T.current = r;
279
+ }, [r]), h(() => {
280
+ R.current = u;
281
+ }, [u]), h(() => {
282
+ M.current = f;
283
+ }, [f]), h(() => {
284
+ $.current = c;
285
+ }, [c]);
286
+ const J = G(() => {
287
+ if (p.current) return;
484
288
  (async () => {
485
- var N, Y;
486
- R.current = !0;
289
+ var F, S;
290
+ p.current = !0;
487
291
  try {
488
292
  for (; ; ) {
489
- const h = d.current, F = $.current, I = [];
490
- for (const w of F)
491
- for (const X of U(w.path, h))
492
- I.push(X);
493
- const k = b.current;
494
- k.clear();
495
- for (const w of I) k.set(Ne(w), "running");
496
- I.length > 0 && ((N = E.current) == null || N.call(E, I));
497
- const V = await Pe(
498
- h,
499
- F,
500
- D.current,
293
+ const E = g.current, L = _.current, rt = L.filter(
294
+ (b) => b.condition === !0 || M.current(b.condition, E)
295
+ ), q = [];
296
+ for (const b of rt)
297
+ for (const ot of D(b.path, E))
298
+ q.push(ot);
299
+ const K = x.current;
300
+ K.clear();
301
+ for (const b of q) K.set(At(b), "running");
302
+ q.length > 0 && ((F = d.current) == null || F.call(d, q));
303
+ const nt = await Ot(
304
+ E,
305
+ L,
306
+ I.current,
501
307
  T.current,
502
- x.current,
503
- S.current.formulaDataKey,
504
- S.current.formulaPathKey
308
+ y.current,
309
+ R.current.formulaDataKey,
310
+ R.current.formulaPathKey,
311
+ M.current,
312
+ $.current
505
313
  );
506
- if (C.current) break;
507
- const L = [...k.values()].some((w) => w === "dirty");
508
- if (k.clear(), !L) {
509
- l(V), I.length > 0 && ((Y = E.current) == null || Y.call(E, []));
314
+ if (z.current) break;
315
+ const st = [...K.values()].some((b) => b === "dirty");
316
+ if (K.clear(), !st) {
317
+ l(nt), q.length > 0 && ((S = d.current) == null || S.call(d, []));
510
318
  break;
511
319
  }
512
320
  }
513
321
  } finally {
514
- R.current = !1;
322
+ p.current = !1;
515
323
  }
516
324
  })();
517
- }, []), P = ce(
518
- (M) => {
519
- d.current = M;
520
- const N = b.current;
521
- for (const [Y, h] of N)
522
- h === "running" && N.set(Y, "dirty");
523
- R.current || (g.current !== null && clearTimeout(g.current), g.current = setTimeout(() => {
524
- g.current = null, A();
325
+ }, []), O = G(
326
+ (B) => {
327
+ g.current = B;
328
+ const F = x.current;
329
+ for (const [S, E] of F)
330
+ E === "running" && F.set(S, "dirty");
331
+ p.current || (w.current !== null && clearTimeout(w.current), w.current = setTimeout(() => {
332
+ w.current = null, J();
525
333
  }, s));
526
334
  },
527
- [s, A]
528
- ), O = v(!1), C = v(!1);
529
- return j(() => {
530
- O.current ? ae(r, _.current) || (_.current = r, P(r)) : (O.current = !0, _.current = r, P(r));
531
- }), j(
532
- () => () => {
533
- C.current = !0, g.current !== null && clearTimeout(g.current);
534
- },
535
- []
536
- ), { enrichedFormData: i, handleInput: P };
335
+ [s, J]
336
+ ), v = m(!1), z = m(!1);
337
+ return h(() => {
338
+ v.current ? Z(t, j.current) || (j.current = t, O(t)) : (v.current = !0, j.current = t, O(t));
339
+ }), h(() => (z.current = !1, () => {
340
+ z.current = !0, v.current = !1, w.current !== null && clearTimeout(w.current);
341
+ }), []), { enrichedFormData: a, handleInput: O };
537
342
  }
538
- function De(r, t) {
539
- const o = structuredClone(r ?? {}), s = $e(t);
540
- for (const n of t)
541
- z(o, n.path, s);
542
- return o;
343
+ function bt(t, e) {
344
+ const n = structuredClone(t ?? {}), s = Rt(e);
345
+ for (const r of e)
346
+ P(n, r.path, s);
347
+ return n;
543
348
  }
544
- function $e(r) {
545
- const t = /* @__PURE__ */ new Set();
546
- for (let o = 0; o < r.length; o++) {
547
- const s = r[o].path;
548
- for (let n = 0; n < s.length; n++) {
549
- const a = s[n];
550
- if (typeof a != "number" && a !== Z) continue;
551
- const c = se(s.slice(0, n)), f = typeof a == "number";
552
- r.some((l, d) => {
553
- if (d === o || l.path.length <= n || se(l.path.slice(0, n)) !== c) return !1;
554
- const _ = l.path[n];
555
- return f ? _ === Z : typeof _ == "number";
556
- }) && t.add(c);
349
+ function Rt(t) {
350
+ const e = /* @__PURE__ */ new Set();
351
+ for (let n = 0; n < t.length; n++) {
352
+ const s = t[n].path;
353
+ for (let r = 0; r < s.length; r++) {
354
+ const o = s[r];
355
+ if (typeof o != "number" && o !== N) continue;
356
+ const i = W(s.slice(0, r)), u = typeof o == "number";
357
+ t.some((c, a) => {
358
+ if (a === n || c.path.length <= r || W(c.path.slice(0, r)) !== i) return !1;
359
+ const l = c.path[r];
360
+ return u ? l === N : typeof l == "number";
361
+ }) && e.add(i);
557
362
  }
558
363
  }
559
- return t;
364
+ return e;
560
365
  }
561
- function se(r) {
562
- return JSON.stringify(r.map((t) => typeof t == "symbol" ? "__ARRAY_INDEX__" : t));
366
+ function W(t) {
367
+ return JSON.stringify(t.map((e) => typeof e == "symbol" ? "__ARRAY_INDEX__" : e));
563
368
  }
564
- function z(r, t, o, s = []) {
565
- if (t.length === 0) {
566
- r["ui:readonly"] = !0;
369
+ function P(t, e, n, s = []) {
370
+ if (e.length === 0) {
371
+ t["ui:readonly"] = !0;
567
372
  return;
568
373
  }
569
- const [n, ...a] = t;
570
- if (typeof n == "string") {
571
- (!r[n] || typeof r[n] != "object" || Array.isArray(r[n])) && (r[n] = {}), z(r[n], a, o, [...s, n]);
374
+ const [r, ...o] = e;
375
+ if (typeof r == "string") {
376
+ (!t[r] || typeof t[r] != "object" || Array.isArray(t[r])) && (t[r] = {}), P(t[r], o, n, [...s, r]);
572
377
  return;
573
378
  }
574
- if (typeof n == "number") {
575
- if (r.items !== void 0 && !Array.isArray(r.items)) {
379
+ if (typeof r == "number") {
380
+ if (t.items !== void 0 && !Array.isArray(t.items)) {
576
381
  console.warn("[rjsf-formulas] mergeReadOnly: cannot inject ui:readonly at tuple index because existing uiSchema has items as an object. Skipping.");
577
382
  return;
578
383
  }
579
- Array.isArray(r.items) || (r.items = []);
580
- const i = r.items;
581
- (!i[n] || typeof i[n] != "object") && (i[n] = {}), z(i[n], a, o, [...s, n]);
384
+ Array.isArray(t.items) || (t.items = []);
385
+ const f = t.items;
386
+ (!f[r] || typeof f[r] != "object") && (f[r] = {}), P(f[r], o, n, [...s, r]);
582
387
  return;
583
388
  }
584
- const c = se(s);
585
- if (o.has(c))
586
- (!r.additionalItems || typeof r.additionalItems != "object") && (r.additionalItems = {}), z(r.additionalItems, a, o, [...s, n]);
389
+ const i = W(s);
390
+ if (n.has(i))
391
+ (!t.additionalItems || typeof t.additionalItems != "object") && (t.additionalItems = {}), P(t.additionalItems, o, n, [...s, r]);
587
392
  else {
588
- if (Array.isArray(r.items)) {
393
+ if (Array.isArray(t.items)) {
589
394
  console.warn("[rjsf-formulas] mergeReadOnly: cannot inject ui:readonly for uniform array because existing uiSchema has items as an array. Skipping.");
590
395
  return;
591
396
  }
592
- (!r.items || typeof r.items != "object") && (r.items = {}), z(r.items, a, o, [...s, n]);
397
+ (!t.items || typeof t.items != "object") && (t.items = {}), P(t.items, o, n, [...s, r]);
593
398
  }
594
399
  }
595
- function Ye(r) {
400
+ function kt(t) {
596
401
  const {
597
- schema: t,
598
- formData: o,
599
- uiSchema: s,
600
- evaluator: n,
601
- Form: a = be,
602
- formulaKey: c = "x-formula",
402
+ schema: e,
403
+ formData: n,
404
+ validator: s,
405
+ uiSchema: r,
406
+ evaluator: o,
407
+ Form: i = ut,
408
+ formulaKey: u = "x-formula",
603
409
  formulaContextKey: f = "x-formula-context",
604
- formulaDataKey: i = "__formData__",
605
- formulaPathKey: l = "__path__",
606
- maxConvergencePasses: d = 10,
607
- debounceMs: _ = 300,
608
- onFormulaError: b,
609
- onLoadingChange: g,
610
- onChange: R,
611
- ...x
612
- } = r, E = re(
613
- () => Re(t, { formulaKey: c, formulaContextKey: f }),
614
- [t, c, f]
615
- ), D = re(
616
- () => ({ formulaDataKey: i, formulaPathKey: l }),
617
- [i, l]
618
- ), $ = re(
619
- () => De(s, E),
620
- [s, E]
621
- ), { enrichedFormData: T, handleInput: S } = Ie(
622
- o,
623
- E,
410
+ formulaDataKey: c = "__formData__",
411
+ formulaPathKey: a = "__path__",
412
+ maxConvergencePasses: l = 10,
413
+ debounceMs: g = 300,
414
+ onFormulaError: j,
415
+ onLoadingChange: x,
416
+ formulaConflictBehavior: w = "warn",
417
+ onChange: p,
418
+ ...y
419
+ } = t, d = X(
420
+ () => at(e, { formulaKey: u, formulaContextKey: f }),
421
+ [e, u, f]
422
+ ), I = X(
423
+ () => ({ formulaDataKey: c, formulaPathKey: a }),
424
+ [c, a]
425
+ ), _ = X(
426
+ () => bt(r, d),
427
+ [r, d]
428
+ ), T = G(
429
+ (O, v) => s.isValid(O, v, e),
430
+ [s, e]
431
+ ), { enrichedFormData: R, handleInput: M } = xt(
624
432
  n,
625
- _,
626
433
  d,
627
- b,
434
+ o,
628
435
  g,
629
- D
630
- ), A = v(R);
631
- j(() => {
632
- A.current = R;
633
- }, [R]), j(() => {
436
+ l,
437
+ j,
438
+ x,
439
+ I,
440
+ T,
441
+ w
442
+ ), $ = m(p);
443
+ return h(() => {
444
+ $.current = p;
445
+ }, [p]), h(() => {
634
446
  var O;
635
- E.length !== 0 && ((O = A.current) == null || O.call(A, { formData: T }, void 0));
636
- }, [T]);
637
- const P = (O, C) => {
638
- S(O.formData), R == null || R(O, C);
639
- };
640
- return /* @__PURE__ */ xe.jsx(
641
- a,
447
+ d.length !== 0 && ((O = $.current) == null || O.call($, { formData: R }, void 0));
448
+ }, [R]), /* @__PURE__ */ ct(
449
+ i,
642
450
  {
643
- ...x,
644
- schema: t,
645
- formData: T,
646
- uiSchema: $,
647
- onChange: P
451
+ ...y,
452
+ schema: e,
453
+ validator: s,
454
+ formData: R,
455
+ uiSchema: _,
456
+ onChange: (O, v) => {
457
+ M(O.formData), p == null || p(O, v);
458
+ }
648
459
  }
649
460
  );
650
461
  }
651
462
  export {
652
- Ye as FormulaForm,
653
- Re as analyzeSchema
463
+ kt as FormulaForm,
464
+ at as analyzeSchema
654
465
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@a-ludi/rjsf-formulas",
3
- "version": "0.1.2",
3
+ "version": "0.2.0",
4
4
  "description": "RJSF extension for computed fields driven by formulas",
5
5
  "author": "Arne Ludwig <arne.ludwig@posteo.de>",
6
6
  "license": "MIT",
@@ -41,7 +41,8 @@
41
41
  "peerDependencies": {
42
42
  "@rjsf/core": ">=5",
43
43
  "@rjsf/utils": ">=5",
44
- "react": ">=17"
44
+ "react": ">=17",
45
+ "react-dom": ">=17"
45
46
  },
46
47
  "devDependencies": {
47
48
  "@rjsf/core": "^6",
@@ -49,12 +50,14 @@
49
50
  "@rjsf/validator-ajv8": "^6",
50
51
  "@testing-library/jest-dom": "^6.9.1",
51
52
  "@testing-library/react": "^16.3.2",
53
+ "@types/node": "^22",
52
54
  "@types/react": "^18",
53
55
  "fast-deep-equal": "^3.1.3",
54
56
  "husky": "^9",
55
57
  "jsdom": "^29.1.1",
56
58
  "publint": "^0.3",
57
59
  "react": "^19",
60
+ "react-dom": "^19",
58
61
  "rjsf-core-v5": "npm:@rjsf/core@^5",
59
62
  "rjsf-utils-v5": "npm:@rjsf/utils@^5",
60
63
  "rjsf-validator-v5": "npm:@rjsf/validator-ajv8@^5",
@@ -65,8 +68,5 @@
65
68
  "vite-plugin-dts": "^4",
66
69
  "vitepress": "^1.6.4",
67
70
  "vitest": "^3"
68
- },
69
- "dependencies": {
70
- "react-dom": "^19"
71
71
  }
72
72
  }