@a-ludi/rjsf-formulas 0.3.0 → 0.3.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 +1 -1
- package/dist/index.mjs +206 -205
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
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 O(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 O(e,t,r,s,n,o,u,l){const f=e;if(typeof f.$ref=="string"){const c=se.findSchemaDefinition(f.$ref,l);O(c,t,r,s,n,o,u,l);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}if(e.properties&&e.type!=="array")for(const[c,a]of Object.entries(e.properties))O(a,[...t,c],r,s,n,o,u,l);if(e.type==="array"&&(Array.isArray(f.prefixItems)&&f.prefixItems.forEach((a,y)=>{O(a,[...t,y],r,s,n,o,u,l)}),e.items&&!Array.isArray(e.items)&&O(e.items,[...t,U],r,s,n,o,u,l)),Array.isArray(f.allOf)){const c=f.allOf;for(const a of c){const y=[];O(a,t,y,s,n,o,u,l),ie(r,y,o)}}for(const c of["oneOf","anyOf"])if(Array.isArray(f[c])){const a=f[c];for(const y of a){const m=J(u,y);O(y,t,r,s,n,o,m,l)}}if("if"in f){const c=f.if,a=f.then,y=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.`),a!==void 0){const m=J(u,c);O(a,t,r,s,n,o,m,l)}if(y!==void 0){const m=J(u,{not:c});O(y,t,r,s,n,o,m,l)}}}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((l,f)=>{if(!(l==null||typeof l!="object"))return l[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 l=0;l<o.length;l++)u.push(...k(n,t,[...r,l]));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 c of k(f.path,n)){const a=pe(f,c,n,s);o.push({field:f,concretePath:c,context:a})}const u=await Promise.allSettled(o.map(({field:f,context:c})=>new Promise(a=>a(r(f.formula,c))))),l=[];for(let f=0;f<o.length;f++){const{concretePath:c}=o[f],a=u[f];if(a.status==="fulfilled")V(n,c,a.value);else{const y=a.reason instanceof Error?a.reason:new Error(String(a.reason));l.push({path:c,error:y}),V(n,c,void 0)}}return{data:n,errors:l}}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,l,f){const c=t.filter(p=>p.condition===!0||l(p.condition,e));if(c.length===0)return e;const a=new Map,y=[];for(const p of c){const d=JSON.stringify(p.path);if(a.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 g=y.indexOf(a.get(d));y[g]=p,a.set(d,p)}else a.set(d,p),y.push(p)}const m={formulaDataKey:o,formulaPathKey:u};let h=e;for(let p=0;p<s;p++){const{data:d,errors:g}=await L(h,y,r,m);if(me(h,d,y)){for(const{path:w,error:$}of g)n==null||n(w,$);return d}h=d}const{data:A}=await L(h,y,r,m),j=structuredClone(A);for(const p of y)for(const d of k(p.path,A))H(I(h,d),I(A,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,l,f,c){const[a,y]=i.useState(e),m=i.useRef(e),h=i.useRef(e),A=i.useRef(new Map),j=i.useRef(null),p=i.useRef(!1),d=i.useRef(o),g=i.useRef(u),w=i.useRef(r),$=i.useRef(t),S=i.useRef(n),F=i.useRef(l),x=i.useRef(f),T=i.useRef(c);i.useEffect(()=>{d.current=o},[o]),i.useEffect(()=>{g.current=u},[u]),i.useEffect(()=>{w.current=r},[r]),i.useEffect(()=>{$.current=t},[t]),i.useEffect(()=>{S.current=n},[n]),i.useEffect(()=>{F.current=l},[l]),i.useEffect(()=>{x.current=f},[f]),i.useEffect(()=>{T.current=c},[c]);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=A.current;N.clear();for(const b of q)N.set(he(b),"running");q.length>0&&((_=g.current)==null||_.call(g,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){y(te),q.length>0&&((K=g.current)==null||K.call(g,[]));break}}}finally{p.current=!1}})()},[]),M=i.useCallback(Q=>{m.current=Q;const _=A.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,h.current)||(h.current=e,M(e)):(R.current=!0,h.current=e,M(e))}),i.useEffect(()=>(v.current=!1,()=>{v.current=!0,R.current=!1,j.current!==null&&clearTimeout(j.current)}),[]),{enrichedFormData:a,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)),l=typeof o=="number";e.some((c,a)=>{if(a===r||c.path.length<=n||G(c.path.slice(0,n))!==u)return!1;const y=c.path[n];return l?y===U:typeof y=="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 Oe(e,t){const{schema:r,formData:s,validator:n,uiSchema:o,evaluator:u,Form:l=fe,formulaKey:f="x-formula",formulaContextKey:c="x-formula-context",formulaDataKey:a="__formData__",formulaPathKey:y="__path__",maxConvergencePasses:m=10,debounceMs:h=300,onFormulaError:A,onLoadingChange:j,formulaConflictBehavior:p="warn",onChange:d,...g}=e,w=i.useMemo(()=>C(r,{formulaKey:f,formulaContextKey:c}),[r,f,c]),$=i.useMemo(()=>({formulaDataKey:a,formulaPathKey:y}),[a,y]),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,h,m,A,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(l,{ref:t,...g,schema:r,validator:n,formData:x,uiSchema:S,onChange:M})}const Ae=i.forwardRef(Oe);exports.FormulaForm=Ae;exports.analyzeSchema=C;
|
|
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;
|
package/dist/index.mjs
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
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
|
|
3
|
+
import { useState as it, useRef as g, useEffect as j, useCallback as G, forwardRef as ut, useMemo as X } from "react";
|
|
4
4
|
import at from "@rjsf/core";
|
|
5
5
|
const J = Symbol("arrayIndex");
|
|
6
6
|
function lt(t, e) {
|
|
7
|
-
const r = (e == null ? void 0 : e.formulaKey) ?? "x-formula",
|
|
8
|
-
return x(t, [],
|
|
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;
|
|
9
9
|
}
|
|
10
10
|
function Y(t, e) {
|
|
11
11
|
if (t === !0) return e;
|
|
12
12
|
const r = t;
|
|
13
13
|
return Array.isArray(r.allOf) ? { allOf: [...r.allOf, e] } : { allOf: [t, e] };
|
|
14
14
|
}
|
|
15
|
-
function
|
|
15
|
+
function yt(t, e) {
|
|
16
16
|
return t === void 0 || t === "siblings" ? "siblings" : t === "extended" ? "extended" : (console.warn(
|
|
17
17
|
`[rjsf-formulas] Unknown x-formula-context value "${t}" at path [${z(e)}], treating as "siblings"`
|
|
18
18
|
), "siblings");
|
|
@@ -23,31 +23,31 @@ function z(t) {
|
|
|
23
23
|
function H(t) {
|
|
24
24
|
return t.map((e) => typeof e == "symbol" ? "[*]" : String(e)).join(".");
|
|
25
25
|
}
|
|
26
|
-
function
|
|
27
|
-
const
|
|
26
|
+
function pt(t, e, r) {
|
|
27
|
+
const s = H(t.path);
|
|
28
28
|
if (r === "error")
|
|
29
29
|
throw new TypeError(
|
|
30
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'.`
|
|
31
31
|
);
|
|
32
32
|
r === "warn" && console.warn(
|
|
33
|
-
`[rjsf-formulas] Formula conflict at path [${
|
|
33
|
+
`[rjsf-formulas] Formula conflict at path [${s}]: "${t.formula}" (earlier allOf branch) is overridden by "${e.formula}" (later allOf branch).`
|
|
34
34
|
);
|
|
35
35
|
}
|
|
36
36
|
function dt(t, e, r) {
|
|
37
|
-
for (const
|
|
38
|
-
const n = H(
|
|
39
|
-
|
|
37
|
+
for (const s of e) {
|
|
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);
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
|
-
function x(t, e, r,
|
|
42
|
+
function x(t, e, r, s, n, o, i, u) {
|
|
43
43
|
const f = t;
|
|
44
44
|
if (typeof f.$ref == "string") {
|
|
45
|
-
const c = ft(f.$ref,
|
|
46
|
-
x(c, e, r,
|
|
45
|
+
const c = ft(f.$ref, u);
|
|
46
|
+
x(c, e, r, s, n, o, i, u);
|
|
47
47
|
return;
|
|
48
48
|
}
|
|
49
|
-
if (
|
|
50
|
-
const c = f[
|
|
49
|
+
if (s in t) {
|
|
50
|
+
const c = f[s];
|
|
51
51
|
if (typeof c != "string") {
|
|
52
52
|
console.warn(
|
|
53
53
|
`[rjsf-formulas] Formula at path [${z(e)}] is not a string (got ${typeof c}), skipping.`
|
|
@@ -57,60 +57,61 @@ function x(t, e, r, o, n, s, i, a) {
|
|
|
57
57
|
r.push({
|
|
58
58
|
path: e,
|
|
59
59
|
formula: c,
|
|
60
|
-
contextMode:
|
|
60
|
+
contextMode: yt(f[n], e),
|
|
61
61
|
condition: i
|
|
62
62
|
});
|
|
63
63
|
return;
|
|
64
64
|
}
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
const l = t.type === "array" || t.type == null && (Array.isArray(f.prefixItems) || t.items != null && !Array.isArray(t.items));
|
|
66
|
+
if (t.properties && !l)
|
|
67
|
+
for (const [c, a] of Object.entries(t.properties))
|
|
67
68
|
x(
|
|
68
|
-
|
|
69
|
+
a,
|
|
69
70
|
[...e, c],
|
|
70
71
|
r,
|
|
71
|
-
o,
|
|
72
|
-
n,
|
|
73
72
|
s,
|
|
73
|
+
n,
|
|
74
|
+
o,
|
|
74
75
|
i,
|
|
75
|
-
|
|
76
|
+
u
|
|
76
77
|
);
|
|
77
|
-
if (
|
|
78
|
-
x(
|
|
78
|
+
if (l && (Array.isArray(f.prefixItems) && f.prefixItems.forEach((a, d) => {
|
|
79
|
+
x(a, [...e, d], r, s, n, o, i, u);
|
|
79
80
|
}), t.items && !Array.isArray(t.items) && x(
|
|
80
81
|
t.items,
|
|
81
82
|
[...e, J],
|
|
82
83
|
r,
|
|
83
|
-
o,
|
|
84
|
-
n,
|
|
85
84
|
s,
|
|
85
|
+
n,
|
|
86
|
+
o,
|
|
86
87
|
i,
|
|
87
|
-
|
|
88
|
+
u
|
|
88
89
|
)), Array.isArray(f.allOf)) {
|
|
89
90
|
const c = f.allOf;
|
|
90
|
-
for (const
|
|
91
|
-
const
|
|
92
|
-
x(
|
|
91
|
+
for (const a of c) {
|
|
92
|
+
const d = [];
|
|
93
|
+
x(a, e, d, s, n, o, i, u), dt(r, d, o);
|
|
93
94
|
}
|
|
94
95
|
}
|
|
95
96
|
for (const c of ["oneOf", "anyOf"])
|
|
96
97
|
if (Array.isArray(f[c])) {
|
|
97
|
-
const
|
|
98
|
-
for (const
|
|
99
|
-
const m = Y(i,
|
|
100
|
-
x(
|
|
98
|
+
const a = f[c];
|
|
99
|
+
for (const d of a) {
|
|
100
|
+
const m = Y(i, d);
|
|
101
|
+
x(d, e, r, s, n, o, m, u);
|
|
101
102
|
}
|
|
102
103
|
}
|
|
103
104
|
if ("if" in f) {
|
|
104
|
-
const c = f.if,
|
|
105
|
-
if (
|
|
106
|
-
`[rjsf-formulas] Formula key "${
|
|
107
|
-
),
|
|
105
|
+
const c = f.if, a = f.then, d = f.else;
|
|
106
|
+
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.`
|
|
108
|
+
), a !== void 0) {
|
|
108
109
|
const m = Y(i, c);
|
|
109
|
-
x(
|
|
110
|
+
x(a, e, r, s, n, o, m, u);
|
|
110
111
|
}
|
|
111
|
-
if (
|
|
112
|
+
if (d !== void 0) {
|
|
112
113
|
const m = Y(i, { not: c });
|
|
113
|
-
x(
|
|
114
|
+
x(d, e, r, s, n, o, m, u);
|
|
114
115
|
}
|
|
115
116
|
}
|
|
116
117
|
}
|
|
@@ -123,21 +124,21 @@ function gt() {
|
|
|
123
124
|
if (e === r) return !0;
|
|
124
125
|
if (e && r && typeof e == "object" && typeof r == "object") {
|
|
125
126
|
if (e.constructor !== r.constructor) return !1;
|
|
126
|
-
var
|
|
127
|
+
var s, n, o;
|
|
127
128
|
if (Array.isArray(e)) {
|
|
128
|
-
if (
|
|
129
|
-
for (n =
|
|
129
|
+
if (s = e.length, s != r.length) return !1;
|
|
130
|
+
for (n = s; n-- !== 0; )
|
|
130
131
|
if (!t(e[n], r[n])) return !1;
|
|
131
132
|
return !0;
|
|
132
133
|
}
|
|
133
134
|
if (e.constructor === RegExp) return e.source === r.source && e.flags === r.flags;
|
|
134
135
|
if (e.valueOf !== Object.prototype.valueOf) return e.valueOf() === r.valueOf();
|
|
135
136
|
if (e.toString !== Object.prototype.toString) return e.toString() === r.toString();
|
|
136
|
-
if (
|
|
137
|
-
for (n =
|
|
138
|
-
if (!Object.prototype.hasOwnProperty.call(r,
|
|
139
|
-
for (n =
|
|
140
|
-
var i =
|
|
137
|
+
if (o = Object.keys(e), s = o.length, s !== Object.keys(r).length) return !1;
|
|
138
|
+
for (n = s; n-- !== 0; )
|
|
139
|
+
if (!Object.prototype.hasOwnProperty.call(r, o[n])) return !1;
|
|
140
|
+
for (n = s; n-- !== 0; ) {
|
|
141
|
+
var i = o[n];
|
|
141
142
|
if (!t(e[i], r[i])) return !1;
|
|
142
143
|
}
|
|
143
144
|
return !0;
|
|
@@ -147,217 +148,217 @@ function gt() {
|
|
|
147
148
|
}
|
|
148
149
|
var ht = gt();
|
|
149
150
|
const jt = /* @__PURE__ */ mt(ht);
|
|
150
|
-
function wt(t, e, r,
|
|
151
|
-
const
|
|
152
|
-
if (!(
|
|
153
|
-
return
|
|
154
|
-
}, r), i =
|
|
155
|
-
return t.contextMode === "extended" ? ((
|
|
156
|
-
`[rjsf-formulas] Extended context key collision: sibling field named "${
|
|
151
|
+
function wt(t, e, r, s) {
|
|
152
|
+
const o = e.slice(0, -1).reduce((u, f) => {
|
|
153
|
+
if (!(u == null || typeof u != "object"))
|
|
154
|
+
return u[f];
|
|
155
|
+
}, r), i = o != null && typeof o == "object" && !Array.isArray(o) ? { ...o } : {};
|
|
156
|
+
return t.contextMode === "extended" ? ((s.formulaDataKey in i || s.formulaPathKey in i) && console.warn(
|
|
157
|
+
`[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.`
|
|
157
158
|
), {
|
|
158
159
|
...i,
|
|
159
|
-
[
|
|
160
|
-
[
|
|
160
|
+
[s.formulaDataKey]: r,
|
|
161
|
+
[s.formulaPathKey]: [...e]
|
|
161
162
|
}) : i;
|
|
162
163
|
}
|
|
163
164
|
function tt(t) {
|
|
164
165
|
return t.map((e) => typeof e == "symbol" ? "[*]" : String(e)).join(", ");
|
|
165
166
|
}
|
|
166
167
|
function k(t, e) {
|
|
167
|
-
return e.reduce((r,
|
|
168
|
+
return e.reduce((r, s) => {
|
|
168
169
|
if (!(r == null || typeof r != "object"))
|
|
169
|
-
return r[
|
|
170
|
+
return r[s];
|
|
170
171
|
}, t);
|
|
171
172
|
}
|
|
172
173
|
function Q(t, e, r) {
|
|
173
174
|
if (e.length === 0) return;
|
|
174
|
-
const
|
|
175
|
-
|
|
175
|
+
const s = k(t, e.slice(0, -1));
|
|
176
|
+
s != null && typeof s == "object" && (s[e[e.length - 1]] = r);
|
|
176
177
|
}
|
|
177
178
|
function D(t, e, r = []) {
|
|
178
179
|
if (t.length === 0) return [r];
|
|
179
|
-
const [
|
|
180
|
-
if (
|
|
181
|
-
const
|
|
182
|
-
if (!Array.isArray(
|
|
180
|
+
const [s, ...n] = t;
|
|
181
|
+
if (s === J) {
|
|
182
|
+
const o = k(e, r);
|
|
183
|
+
if (!Array.isArray(o)) return [];
|
|
183
184
|
const i = [];
|
|
184
|
-
for (let
|
|
185
|
-
i.push(...D(n, e, [...r,
|
|
185
|
+
for (let u = 0; u < o.length; u++)
|
|
186
|
+
i.push(...D(n, e, [...r, u]));
|
|
186
187
|
return i;
|
|
187
188
|
}
|
|
188
|
-
return D(n, e, [...r,
|
|
189
|
+
return D(n, e, [...r, s]);
|
|
189
190
|
}
|
|
190
191
|
function Z(t, e) {
|
|
191
192
|
return jt(t, e);
|
|
192
193
|
}
|
|
193
|
-
async function et(t, e, r,
|
|
194
|
-
const n = structuredClone(t),
|
|
194
|
+
async function et(t, e, r, s) {
|
|
195
|
+
const n = structuredClone(t), o = [];
|
|
195
196
|
for (const f of e)
|
|
196
|
-
for (const
|
|
197
|
-
const
|
|
198
|
-
|
|
197
|
+
for (const l of D(f.path, n)) {
|
|
198
|
+
const c = wt(f, l, n, s);
|
|
199
|
+
o.push({ field: f, concretePath: l, context: c });
|
|
199
200
|
}
|
|
200
201
|
const i = await Promise.allSettled(
|
|
201
|
-
|
|
202
|
-
),
|
|
203
|
-
for (let f = 0; f <
|
|
204
|
-
const { concretePath:
|
|
205
|
-
if (
|
|
206
|
-
Q(n,
|
|
202
|
+
o.map(({ field: f, context: l }) => new Promise((c) => c(r(f.formula, l))))
|
|
203
|
+
), u = [];
|
|
204
|
+
for (let f = 0; f < o.length; f++) {
|
|
205
|
+
const { concretePath: l } = o[f], c = i[f];
|
|
206
|
+
if (c.status === "fulfilled")
|
|
207
|
+
Q(n, l, c.value);
|
|
207
208
|
else {
|
|
208
|
-
const
|
|
209
|
-
|
|
209
|
+
const a = c.reason instanceof Error ? c.reason : new Error(String(c.reason));
|
|
210
|
+
u.push({ path: l, error: a }), Q(n, l, void 0);
|
|
210
211
|
}
|
|
211
212
|
}
|
|
212
|
-
return { data: n, errors:
|
|
213
|
+
return { data: n, errors: u };
|
|
213
214
|
}
|
|
214
|
-
function
|
|
215
|
-
for (const
|
|
216
|
-
for (const n of D(
|
|
215
|
+
function At(t, e, r) {
|
|
216
|
+
for (const s of r)
|
|
217
|
+
for (const n of D(s.path, e))
|
|
217
218
|
if (!Z(k(t, n), k(e, n)))
|
|
218
219
|
return !1;
|
|
219
220
|
return !0;
|
|
220
221
|
}
|
|
221
|
-
async function
|
|
222
|
-
const
|
|
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
225
|
);
|
|
225
|
-
if (
|
|
226
|
-
const
|
|
227
|
-
for (const
|
|
228
|
-
const
|
|
229
|
-
if (
|
|
226
|
+
if (l.length === 0) return t;
|
|
227
|
+
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
231
|
if (f === "error")
|
|
231
232
|
throw new TypeError(
|
|
232
|
-
`[rjsf-formulas] Formula conflict: two active fields share path [${tt(
|
|
233
|
+
`[rjsf-formulas] Formula conflict: two active fields share path [${tt(p.path)}]`
|
|
233
234
|
);
|
|
234
235
|
f === "warn" && console.warn(
|
|
235
|
-
`[rjsf-formulas] Formula conflict: two active fields share path [${tt(
|
|
236
|
+
`[rjsf-formulas] Formula conflict: two active fields share path [${tt(p.path)}]; taking last`
|
|
236
237
|
);
|
|
237
|
-
const
|
|
238
|
-
|
|
238
|
+
const h = a.indexOf(c.get(y));
|
|
239
|
+
a[h] = p, c.set(y, p);
|
|
239
240
|
} else
|
|
240
|
-
|
|
241
|
+
c.set(y, p), a.push(p);
|
|
241
242
|
}
|
|
242
|
-
const
|
|
243
|
-
let
|
|
244
|
-
for (let
|
|
245
|
-
const { data:
|
|
246
|
-
if (
|
|
247
|
-
for (const { path:
|
|
248
|
-
n == null || n(
|
|
249
|
-
return
|
|
243
|
+
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;
|
|
250
251
|
}
|
|
251
|
-
|
|
252
|
+
m = y;
|
|
252
253
|
}
|
|
253
|
-
const { data: b } = await et(
|
|
254
|
-
for (const
|
|
255
|
-
for (const
|
|
256
|
-
Z(k(
|
|
257
|
-
|
|
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,
|
|
258
259
|
new Error(
|
|
259
|
-
`[rjsf-formulas] Formula at [${
|
|
260
|
+
`[rjsf-formulas] Formula at [${y.join(", ")}] did not converge after ${s} passes`
|
|
260
261
|
)
|
|
261
|
-
), Q(w,
|
|
262
|
+
), Q(w, y, void 0));
|
|
262
263
|
return w;
|
|
263
264
|
}
|
|
264
265
|
function xt(t) {
|
|
265
266
|
return JSON.stringify(t);
|
|
266
267
|
}
|
|
267
|
-
function bt(t, e, r,
|
|
268
|
-
const [
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
}, [
|
|
272
|
-
|
|
273
|
-
}, [i]),
|
|
274
|
-
|
|
275
|
-
}, [r]),
|
|
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
|
+
j(() => {
|
|
271
|
+
y.current = o;
|
|
272
|
+
}, [o]), j(() => {
|
|
273
|
+
h.current = i;
|
|
274
|
+
}, [i]), j(() => {
|
|
275
|
+
O.current = r;
|
|
276
|
+
}, [r]), j(() => {
|
|
276
277
|
_.current = e;
|
|
277
|
-
}, [e]),
|
|
278
|
+
}, [e]), j(() => {
|
|
278
279
|
T.current = n;
|
|
279
|
-
}, [n]),
|
|
280
|
-
F.current =
|
|
281
|
-
}, [
|
|
280
|
+
}, [n]), j(() => {
|
|
281
|
+
F.current = u;
|
|
282
|
+
}, [u]), j(() => {
|
|
282
283
|
$.current = f;
|
|
283
|
-
}, [f]),
|
|
284
|
-
S.current =
|
|
285
|
-
}, [
|
|
284
|
+
}, [f]), j(() => {
|
|
285
|
+
S.current = l;
|
|
286
|
+
}, [l]);
|
|
286
287
|
const v = G(() => {
|
|
287
|
-
if (
|
|
288
|
+
if (p.current) return;
|
|
288
289
|
(async () => {
|
|
289
290
|
var M, N;
|
|
290
|
-
|
|
291
|
+
p.current = !0;
|
|
291
292
|
try {
|
|
292
293
|
for (; ; ) {
|
|
293
|
-
const E =
|
|
294
|
+
const E = d.current, L = _.current, rt = L.filter(
|
|
294
295
|
(R) => R.condition === !0 || $.current(R.condition, E)
|
|
295
296
|
), q = [];
|
|
296
297
|
for (const R of rt)
|
|
297
|
-
for (const
|
|
298
|
-
q.push(
|
|
298
|
+
for (const ot of D(R.path, E))
|
|
299
|
+
q.push(ot);
|
|
299
300
|
const U = b.current;
|
|
300
301
|
U.clear();
|
|
301
302
|
for (const R of q) U.set(xt(R), "running");
|
|
302
|
-
q.length > 0 && ((M =
|
|
303
|
-
const nt = await
|
|
303
|
+
q.length > 0 && ((M = h.current) == null || M.call(h, q));
|
|
304
|
+
const nt = await Ot(
|
|
304
305
|
E,
|
|
305
306
|
L,
|
|
306
|
-
|
|
307
|
+
O.current,
|
|
307
308
|
T.current,
|
|
308
|
-
|
|
309
|
+
y.current,
|
|
309
310
|
F.current.formulaDataKey,
|
|
310
311
|
F.current.formulaPathKey,
|
|
311
312
|
$.current,
|
|
312
313
|
S.current
|
|
313
314
|
);
|
|
314
315
|
if (I.current) break;
|
|
315
|
-
const
|
|
316
|
-
if (U.clear(), !
|
|
317
|
-
|
|
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, []));
|
|
318
319
|
break;
|
|
319
320
|
}
|
|
320
321
|
}
|
|
321
322
|
} finally {
|
|
322
|
-
|
|
323
|
+
p.current = !1;
|
|
323
324
|
}
|
|
324
325
|
})();
|
|
325
326
|
}, []), K = G(
|
|
326
327
|
(B) => {
|
|
327
|
-
|
|
328
|
+
d.current = B;
|
|
328
329
|
const M = b.current;
|
|
329
330
|
for (const [N, E] of M)
|
|
330
331
|
E === "running" && M.set(N, "dirty");
|
|
331
|
-
|
|
332
|
+
p.current || (w.current !== null && clearTimeout(w.current), w.current = setTimeout(() => {
|
|
332
333
|
w.current = null, v();
|
|
333
|
-
},
|
|
334
|
+
}, s));
|
|
334
335
|
},
|
|
335
|
-
[
|
|
336
|
-
),
|
|
337
|
-
return
|
|
338
|
-
|
|
339
|
-
}),
|
|
340
|
-
I.current = !0,
|
|
341
|
-
}), []), { enrichedFormData:
|
|
336
|
+
[s, v]
|
|
337
|
+
), A = g(!1), I = g(!1);
|
|
338
|
+
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 };
|
|
342
343
|
}
|
|
343
344
|
function Rt(t, e) {
|
|
344
|
-
const r = structuredClone(t ?? {}),
|
|
345
|
+
const r = structuredClone(t ?? {}), s = $t(e);
|
|
345
346
|
for (const n of e)
|
|
346
|
-
P(r, n.path,
|
|
347
|
+
P(r, n.path, s);
|
|
347
348
|
return r;
|
|
348
349
|
}
|
|
349
350
|
function $t(t) {
|
|
350
351
|
const e = /* @__PURE__ */ new Set();
|
|
351
352
|
for (let r = 0; r < t.length; r++) {
|
|
352
|
-
const
|
|
353
|
-
for (let n = 0; n <
|
|
354
|
-
const
|
|
355
|
-
if (typeof
|
|
356
|
-
const i = W(
|
|
357
|
-
t.some((
|
|
358
|
-
if (
|
|
359
|
-
const
|
|
360
|
-
return
|
|
353
|
+
const s = t[r].path;
|
|
354
|
+
for (let n = 0; n < s.length; n++) {
|
|
355
|
+
const o = s[n];
|
|
356
|
+
if (typeof o != "number" && o !== J) continue;
|
|
357
|
+
const i = W(s.slice(0, n)), u = typeof o == "number";
|
|
358
|
+
t.some((l, c) => {
|
|
359
|
+
if (c === r || l.path.length <= n || W(l.path.slice(0, n)) !== i) return !1;
|
|
360
|
+
const a = l.path[n];
|
|
361
|
+
return u ? a === J : typeof a == "number";
|
|
361
362
|
}) && e.add(i);
|
|
362
363
|
}
|
|
363
364
|
}
|
|
@@ -366,14 +367,14 @@ function $t(t) {
|
|
|
366
367
|
function W(t) {
|
|
367
368
|
return JSON.stringify(t.map((e) => typeof e == "symbol" ? "__ARRAY_INDEX__" : e));
|
|
368
369
|
}
|
|
369
|
-
function P(t, e, r,
|
|
370
|
+
function P(t, e, r, s = []) {
|
|
370
371
|
if (e.length === 0) {
|
|
371
372
|
t["ui:readonly"] = !0;
|
|
372
373
|
return;
|
|
373
374
|
}
|
|
374
|
-
const [n, ...
|
|
375
|
+
const [n, ...o] = e;
|
|
375
376
|
if (typeof n == "string") {
|
|
376
|
-
(!t[n] || typeof t[n] != "object" || Array.isArray(t[n])) && (t[n] = {}), P(t[n],
|
|
377
|
+
(!t[n] || typeof t[n] != "object" || Array.isArray(t[n])) && (t[n] = {}), P(t[n], o, r, [...s, n]);
|
|
377
378
|
return;
|
|
378
379
|
}
|
|
379
380
|
if (typeof n == "number") {
|
|
@@ -383,79 +384,79 @@ function P(t, e, r, o = []) {
|
|
|
383
384
|
}
|
|
384
385
|
Array.isArray(t.items) || (t.items = []);
|
|
385
386
|
const f = t.items;
|
|
386
|
-
(!f[n] || typeof f[n] != "object") && (f[n] = {}), P(f[n],
|
|
387
|
+
(!f[n] || typeof f[n] != "object") && (f[n] = {}), P(f[n], o, r, [...s, n]);
|
|
387
388
|
return;
|
|
388
389
|
}
|
|
389
|
-
const i = W(
|
|
390
|
+
const i = W(s);
|
|
390
391
|
if (r.has(i))
|
|
391
|
-
(!t.additionalItems || typeof t.additionalItems != "object") && (t.additionalItems = {}), P(t.additionalItems,
|
|
392
|
+
(!t.additionalItems || typeof t.additionalItems != "object") && (t.additionalItems = {}), P(t.additionalItems, o, r, [...s, n]);
|
|
392
393
|
else {
|
|
393
394
|
if (Array.isArray(t.items)) {
|
|
394
395
|
console.warn("[rjsf-formulas] mergeReadOnly: cannot inject ui:readonly for uniform array because existing uiSchema has items as an array. Skipping.");
|
|
395
396
|
return;
|
|
396
397
|
}
|
|
397
|
-
(!t.items || typeof t.items != "object") && (t.items = {}), P(t.items,
|
|
398
|
+
(!t.items || typeof t.items != "object") && (t.items = {}), P(t.items, o, r, [...s, n]);
|
|
398
399
|
}
|
|
399
400
|
}
|
|
400
401
|
function vt(t, e) {
|
|
401
402
|
const {
|
|
402
403
|
schema: r,
|
|
403
|
-
formData:
|
|
404
|
+
formData: s,
|
|
404
405
|
validator: n,
|
|
405
|
-
uiSchema:
|
|
406
|
+
uiSchema: o,
|
|
406
407
|
evaluator: i,
|
|
407
|
-
Form:
|
|
408
|
+
Form: u = at,
|
|
408
409
|
formulaKey: f = "x-formula",
|
|
409
|
-
formulaContextKey:
|
|
410
|
-
formulaDataKey:
|
|
411
|
-
formulaPathKey:
|
|
412
|
-
maxConvergencePasses:
|
|
413
|
-
debounceMs:
|
|
410
|
+
formulaContextKey: l = "x-formula-context",
|
|
411
|
+
formulaDataKey: c = "__formData__",
|
|
412
|
+
formulaPathKey: a = "__path__",
|
|
413
|
+
maxConvergencePasses: d = 10,
|
|
414
|
+
debounceMs: m = 300,
|
|
414
415
|
onFormulaError: b,
|
|
415
416
|
onLoadingChange: w,
|
|
416
|
-
formulaConflictBehavior:
|
|
417
|
-
onChange:
|
|
418
|
-
...
|
|
419
|
-
} = t,
|
|
420
|
-
() => lt(r, { formulaKey: f, formulaContextKey:
|
|
421
|
-
[r, f,
|
|
417
|
+
formulaConflictBehavior: p = "warn",
|
|
418
|
+
onChange: y,
|
|
419
|
+
...h
|
|
420
|
+
} = t, O = X(
|
|
421
|
+
() => lt(r, { formulaKey: f, formulaContextKey: l }),
|
|
422
|
+
[r, f, l]
|
|
422
423
|
), _ = X(
|
|
423
|
-
() => ({ formulaDataKey:
|
|
424
|
-
[
|
|
424
|
+
() => ({ formulaDataKey: c, formulaPathKey: a }),
|
|
425
|
+
[c, a]
|
|
425
426
|
), T = X(
|
|
426
|
-
() => Rt(
|
|
427
|
-
[
|
|
427
|
+
() => Rt(o, O),
|
|
428
|
+
[o, O]
|
|
428
429
|
), F = G(
|
|
429
|
-
(
|
|
430
|
+
(A, I) => n.isValid(A, I, r),
|
|
430
431
|
[n, r]
|
|
431
432
|
), { enrichedFormData: $, handleInput: S } = bt(
|
|
432
|
-
|
|
433
|
-
|
|
433
|
+
s,
|
|
434
|
+
O,
|
|
434
435
|
i,
|
|
435
|
-
j,
|
|
436
436
|
m,
|
|
437
|
+
d,
|
|
437
438
|
b,
|
|
438
439
|
w,
|
|
439
440
|
_,
|
|
440
441
|
F,
|
|
441
|
-
|
|
442
|
-
), v =
|
|
443
|
-
return
|
|
444
|
-
v.current =
|
|
445
|
-
}, [
|
|
446
|
-
var
|
|
447
|
-
|
|
442
|
+
p
|
|
443
|
+
), v = g(y);
|
|
444
|
+
return j(() => {
|
|
445
|
+
v.current = y;
|
|
446
|
+
}, [y]), j(() => {
|
|
447
|
+
var A;
|
|
448
|
+
O.length !== 0 && ((A = v.current) == null || A.call(v, { formData: $ }, void 0));
|
|
448
449
|
}, [$]), /* @__PURE__ */ ct(
|
|
449
|
-
|
|
450
|
+
u,
|
|
450
451
|
{
|
|
451
452
|
ref: e,
|
|
452
|
-
...
|
|
453
|
+
...h,
|
|
453
454
|
schema: r,
|
|
454
455
|
validator: n,
|
|
455
456
|
formData: $,
|
|
456
457
|
uiSchema: T,
|
|
457
|
-
onChange: (
|
|
458
|
-
S(
|
|
458
|
+
onChange: (A, I) => {
|
|
459
|
+
S(A.formData), y == null || y(A, I);
|
|
459
460
|
}
|
|
460
461
|
}
|
|
461
462
|
);
|