UNPKG

@aplus-frontend/ui

Version:

56 lines (55 loc) 1.5 kB
import { defineComponent as k, onMounted as V, computed as f, unref as o, renderSlot as K } from "vue"; import { useInjectForm as g } from "../context.mjs"; import { isArray as h } from "lodash-unified"; const L = /* @__PURE__ */ k({ name: "ApFormList", __name: "index", props: { name: {}, initialValue: {}, transform: { type: [Function, Object] } }, setup(p) { let a = 1; const s = [], t = p, { model: l, updateModel: m, internalInstance: d } = g(); V(() => { d?.registerField({ name: t.name, initialValue: t.initialValue, transform: t.transform }); }); const i = f(() => t.name ? h(t.name) ? t.name.reduce((e, n) => e?.[n], o(l)) : l?.value[t.name] : null); function y(e = void 0) { const n = o(i) ? [...o(i), e] : [e], r = a; return s.push(r), a += 1, m?.(t.name, n), r; } function v(e) { let n = o(i) || []; n = [...n.slice(0, e), ...n.slice(e + 1)], s.splice(e, 1), m?.(t.name, n); } function F() { return c.value.map((e) => e.key); } const _ = { add: y, remove: v, getFieldKeys: F }, c = f(() => (o(i) || []).map((n, r) => { let u = s[r]; return typeof u > "u" && (s[r] = a, u = a, a += 1), { key: u, fieldName: r, name: [t.name, r].flat(), value: n }; })); return (e, n) => K(e.$slots, "default", { fields: c.value, actions: _ }); } }); export { L as default };