UNPKG

@react-form-builder/core

Version:

React JSON Schema Form Builder to create complex, validated, reusable forms with no deep React knowledge required

54 lines (53 loc) 1.35 kB
import { isNumber as i } from "../../../utils/tools.js"; import { ActionDefinition as D } from "../ActionDefinition.js"; const s = (e) => { if (e) try { return JSON.parse(e); } catch { return; } }, p = (e, t, n, a, r) => { const o = e[t] ?? []; if (i(n) && o.length >= n) return; const d = s(a) ?? {}, c = [...o]; i(r) ? c.splice(r, 0, d) : c.push(d), e[t] = c; }, u = (e, t, n, a) => { const r = e[t]; if (!Array.isArray(r) || i(a) && r.length <= a) return; const o = [...r]; o.splice(n, 1), e[t] = o; }, f = (e) => { const t = e.dataRoot; if (i(t.index)) return t.store.props?.repeaterDataKey?.value; }, x = D.functionalAction(((e, t) => { if (t.dataKey) { p(e.data, t.dataKey, t.max, t.rowData, t.index); return; } const n = f(e.sender); n && e.parentData && p(e.parentData, n, t.max, t.rowData, t.index); }), { dataKey: "string", rowData: "string", index: "number", max: "number" }), l = D.functionalAction(((e, t) => { const n = t.index ?? e.index ?? -1; if (t.dataKey) { u(e.data, t.dataKey, n, t.min); return; } const a = f(e.sender); a && e.parentData && u(e.parentData, a, n, t.min); }), { dataKey: "string", index: "number", min: "number" }); export { x as addRowAction, l as removeRowAction }; //# sourceMappingURL=repeaterActions.js.map