UNPKG

@aplus-frontend/ui

Version:

260 lines (259 loc) 6.92 kB
import { defineComponent as U, useSlots as W, 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 { isEqual as ne, isArray as m, isUndefined as oe, isNumber as c, cloneDeep as le, omit as v } from "lodash-unified"; import { useDevWarning as se } from "../utils/warning.mjs"; import { ApForm as h } from "../ap-form/index.mjs"; import "../config-provider/index.mjs"; import "../hooks/index.mjs"; import "../utils/index.mjs"; import re from "./hooks/use-get-columns.mjs"; import ue from "./style/index.mjs"; import { scrollToRowIndex as ie } from "./utils.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 y } from "../utils/is.mjs"; const Se = /* @__PURE__ */ U({ 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: {}, rowHoverable: { type: Boolean }, columns: {}, value: {}, defaultValue: {}, "onUpdate:value": {}, onChange: {}, maxLength: {}, name: { default: "ap-editable-table-inner-name" }, onFieldChange: {} }, emits: ["update:value"], setup(x, { expose: C, emit: R }) { const t = x; se("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 = ue("editable-table"), T = W(), E = R, g = $(), { value: i, updateValue: V } = fe(t, E), r = q(), S = pe("valueTypeMap"), f = h.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 ? (m(e) ? e : [e]).map((n) => m(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 (y(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 = c(e) ? e : e.length; if (y(t.maxLength) && n + a > t.maxLength) return; const o = c(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(c(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(m(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; ie(n, g.value?.$el, l); } function H() { 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: H, setTableData: K, removeByKey: P }), (e, l) => (Q(), J(s(h), { ref_key: "formRef", ref: r, "initial-values": { [t.name]: s(i) } }, { default: p(() => [w(s(h).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 };