UNPKG

@aplus-frontend/ui

Version:

257 lines (256 loc) 6.88 kB
import { defineComponent as W, useSlots as H, shallowRef as $, ref as q, watch as b, unref as s, createBlock as J, openBlock as Q, withCtx as p, createVNode as w, mergeProps as X, createSlots as Y, renderList as Z, renderSlot as M, normalizeProps as ee, guardReactiveProps as te } from "vue"; import { Table as ae } from "@aplus-frontend/antdv"; import { ApForm as m } from "../ap-form/index.mjs"; import { isEqual as ne, isArray as c, isUndefined as oe, isNumber as h, cloneDeep as le, omit as v } from "lodash-unified"; import "../config-provider/index.mjs"; import "../hooks/index.mjs"; import "../utils/index.mjs"; import { scrollToRowIndex as se } from "./utils.mjs"; import re from "./hooks/use-get-columns.mjs"; import { useDevWarning as ue } from "../utils/warning.mjs"; import ie from "./style/index.mjs"; import { useNamespace as de } from "../config-provider/hooks/use-namespace.mjs"; import { useControllableValue as fe } from "../hooks/useControllableValue.mjs"; import { useGlobalConfig as pe } from "../config-provider/hooks/use-global-config.mjs"; import { isDef as x } from "../utils/is.mjs"; const Se = /* @__PURE__ */ W({ name: "EditableTable", __name: "index", props: { dropdownPrefixCls: {}, pagination: { type: [Boolean, Object], default: !1 }, loading: { type: [Boolean, Object], default: void 0 }, size: { default: "small" }, bordered: { type: Boolean, default: !1 }, locale: {}, onResizeColumn: {}, rowSelection: {}, getPopupContainer: {}, scroll: {}, sortDirections: { default: () => ["ascend", "descend"] }, showSorterTooltip: { type: [Boolean, Object], default: !0 }, prefixCls: {}, rowKey: { type: [String, Function], default: "key" }, tableLayout: { default: "fixed" }, rowClassName: {}, title: {}, footer: {}, id: {}, showHeader: { type: Boolean, default: !0 }, components: {}, customRow: {}, customHeaderRow: {}, direction: {}, expandFixed: { type: [String, Boolean], default: !1 }, expandColumnWidth: {}, expandedRowKeys: {}, defaultExpandedRowKeys: {}, expandedRowRender: {}, expandRowByClick: { type: Boolean, default: !1 }, expandIcon: {}, onExpand: {}, onExpandedRowsChange: {}, defaultExpandAllRows: { type: Boolean, default: !1 }, indentSize: { default: 15 }, expandIconColumnIndex: {}, showExpandColumn: { type: Boolean, default: !0 }, expandedRowClassName: {}, childrenColumnName: { default: "children" }, rowExpandable: {}, sticky: { type: [Boolean, Object] }, transformCellText: {}, columns: {}, value: {}, defaultValue: {}, "onUpdate:value": {}, onChange: {}, maxLength: {}, name: { default: "ap-editable-table-inner-name" }, onFieldChange: {} }, emits: ["update:value"], setup(y, { expose: C, emit: R }) { const t = y; ue("EditableTable")(!1, "breaking", "EditableTable has been EOL, Please use EditableAgGrid(https://aplus.aplnk.com/aplus-ui/components/ag-grid/editable/) instead."); const { b: F } = de("editable-table"), B = ie("editable-table"), T = H(), E = R, g = $(), { value: i, updateValue: V } = fe(t, E), r = q(), S = pe("valueTypeMap"), f = m.useWatch(t.name, r); b(() => f.value, (e) => { V(e), t.onChange?.(e); }, { deep: !0, flush: "post" }), b(i, (e) => { e !== s(f) && (ne(e, s(f)) || r.value?.setFieldValue(t.name, e)); }, { deep: !0 }); const D = re(t, S); function L() { r.value?.resetFields(); } function _(e) { return e ? (c(e) ? e : [e]).map((n) => c(n) ? [t.name, ...n] : [t.name, n]) : void 0; } async function k(e, l) { return (await r.value?.validateFields(_(e), l))?.[t.name]; } function N(e, l) { const n = s(i)?.length || 0; if (x(t.maxLength) && n >= t.maxLength) return; const a = { ...e || {} }; r.value?.setFieldValue?.(t.name, a, !0, (o, u) => { if (!o[u]) { o[u] = [a]; return; } oe(l) ? o[u].push(a) : o[u].splice(l, 0, a); }); } function A(e, l = "suffix") { const n = s(i)?.length || 0, a = h(e) ? e : e.length; if (x(t.maxLength) && n + a > t.maxLength) return; const o = h(e) ? new Array(e).fill(0).map(() => ({})) : le(e); r.value?.setFieldValue?.(t.name, o, !0, (u, d) => { if (!u[d]) { u[d] = [...o]; return; } l === "suffix" ? u[d].push(...o) : u[d].unshift(...o); }); } function I(e) { const l = new Set(h(e) ? [e] : e); r.value?.setFieldValue?.(t.name, void 0, !0, (n, a) => { n[a] = n[a].filter((o, u) => !l.has(u)); }); } function P(e) { const l = new Set(c(e) ? e : [e]); l.size !== 0 && r.value?.setFieldValue?.(t.name, void 0, !0, (n, a) => { n[a] = n[a].filter((o) => !l.has(o[t.rowKey])); }); } function z() { return s(i); } function K(e) { r.value?.setFieldValue(t.name, e); } function O(e) { return s(i)?.[e]; } function j(e, l, n = !0) { r.value?.setFieldValue?.(t.name, void 0, !0, (a, o) => { !a[o] || !a[o][e] || (a[o][e] = { ...n ? a[o][e] : {}, ...l }); }); } function G(e, l) { const n = e === "end" ? i.value.length - 1 : e; se(n, g.value?.$el, l); } function U() { r.value?.setFieldValue?.(t.name, []); } return C({ resetFields: L, validateFields: k, add: N, remove: I, getRowData: O, getRowsData: z, setRowData: j, addMultiple: A, scrollTo: G, clear: U, setTableData: K, removeByKey: P }), (e, l) => (Q(), J(s(m), { ref_key: "formRef", ref: r, "initial-values": { [t.name]: s(i) } }, { default: p(() => [w(s(m).FormItem, { name: e.name, "no-style": "" }, { default: p(() => [w(s(ae), X(s(v)(t, ["name", "value", "onUpdate:value", "maxLength", "onChange"]), { ref_key: "tableRef", ref: g, class: [s(F)(), s(B)], columns: s(D), "data-source": s(i) }), Y({ _: 2 }, [Z(s(v)(T, ["headerCell"]), (n, a) => ({ name: a, fn: p((o) => [M(e.$slots, a, ee(te(o || {})))]) }))]), 1040, ["class", "columns", "data-source"])]), _: 3 }, 8, ["name"])]), _: 3 }, 8, ["initial-values"])); } }); export { Se as default };