@react-form-builder/core
Version:
React JSON Schema Form Builder to create complex, validated, reusable forms with no deep React knowledge required
51 lines (50 loc) • 1.33 kB
JavaScript
import { isFunctionalProperty as u } from "../../stores/ComponentStore.js";
import { CalculableResult as c } from "../../utils/CalculableResult.js";
import { isUndefined as h } from "../../utils/tools.js";
const o = /* @__PURE__ */ new Map(), y = (r) => {
const e = o.get(r);
if (e) return e;
const t = new Function("form", r);
return o.set(r, t), t;
}, l = (r, e) => {
try {
const n = y(r)(e);
return c.success(n);
} catch (t) {
return c.error([
t,
{
name: "Function source",
message: r
}
]);
}
}, a = (r, e) => l(r.fnSource || "", e), b = (r, e) => {
if (u(r)) return a(r, e).result;
const t = r.value || "";
return l(`return ${t}`, e).result;
}, x = (r, e) => {
const t = {};
return Object.keys(r.props).forEach((n) => {
const s = r.props[n];
if (s) {
if (u(s)) {
const { result: i, error: f, exceptions: p } = a(s, e);
if (f) {
const m = `Error in the calculable field '${n}' of the '${r.key}' component `;
console.warn(m, p);
return;
}
t[n] = i;
return;
}
h(s.value) || (t[n] = s.value);
}
}), t;
};
export {
b as calculateExpressionProperty,
x as calculateProperties,
a as calculatePropertyValue
};
//# sourceMappingURL=propertyCalculator.js.map