UNPKG

@aplus-frontend/ui

Version:

318 lines (317 loc) 8.13 kB
import { defineComponent as W, useSlots as U, ref as y, watch as C, unref as s, createBlock as $, openBlock as q, withCtx as p, createVNode as w, mergeProps as J, createSlots as Q, renderList as X, renderSlot as Y, normalizeProps as Z, guardReactiveProps as M } from "vue"; import { ApForm as m } from "../../ap-form/index.mjs"; import { isEqual as ee, isArray as c, isUndefined as te, isNumber as g, cloneDeep as ae, omit as oe } from "lodash-unified"; import "../../config-provider/index.mjs"; import "../../hooks/index.mjs"; import { isDef as b } from "../../utils/index.mjs"; import { useGetEditableColumns as ne } from "../hooks/use-editable-columns.mjs"; import "../index.vue2.mjs"; import { useDevWarning as le } from "../../utils/warning.mjs"; import se from "../style/editable.mjs"; import { useNamespace as re } from "../../config-provider/hooks/use-namespace.mjs"; import { useControllableValue as ie } from "../../hooks/useControllableValue.mjs"; import { useGlobalConfig as ue } from "../../config-provider/hooks/use-global-config.mjs"; import de from "../index.vue.mjs"; const Fe = /* @__PURE__ */ W({ name: "EditableGrid", __name: "index", props: { dropdownPrefixCls: {}, bordered: { type: Boolean, default: !1 }, locale: {}, onResizeColumn: {}, getPopupContainer: {}, scroll: {}, sortDirections: { default: () => ["ascend", "descend"] }, showSorterTooltip: { type: [Boolean, Object], default: !0 }, prefixCls: {}, tableLayout: { default: "fixed" }, title: {}, 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], default: !1 }, transformCellText: {}, rowClassName: {}, stripe: { type: Boolean }, headerRowClassName: {}, footerRowClassName: {}, cellClassName: {}, headerCellClassName: {}, footerCellClassName: {}, rowStyle: {}, headerRowStyle: {}, footerRowStyle: {}, cellStyle: {}, headerCellStyle: {}, footerCellStyle: {}, height: {}, minHeight: {}, maxHeight: {}, mergeCells: {}, mergeFooterItems: {}, cellConfig: {}, loading: { type: Boolean, default: void 0 }, loadingConfig: {}, headerCellConfig: {}, footerCellConfig: {}, round: { type: Boolean }, rowSelection: { type: [Boolean, Object], default: void 0 }, onLoadingChange: {}, onShownColumnsChange: {}, pagination: { type: [Boolean, Object], default: !1 }, searchFormWrapperStyle: {}, tableWrapperStyle: {}, wrapperStyle: {}, size: { default: "mini" }, adaptive: { type: Boolean, default: !1 }, columnResizable: { type: [Boolean, Object], default: !1 }, rowKey: { default: "key" }, footer: {}, virtual: { type: [Boolean, Object], default: void 0 }, expandable: {}, value: {}, rowHighlightable: { type: [Boolean, Function] }, treeConfig: {}, onReady: {}, columns: {}, defaultValue: {}, "onUpdate:value": {}, onChange: {}, maxLength: {}, name: { default: "ap-editable-table-inner-name" }, onFieldChange: {} }, emits: ["update:value"], setup(v, { expose: x, emit: R }) { const B = U(), t = v, { b: S } = re("editable-grid"), F = se("editable-grid"), E = R; le("EditableGrid")(!1, "breaking", "EditableGrid has been EOL, Please use EditableAgGrid(https://aplus.aplnk.com/aplus-ui/components/ag-grid/editable/) instead."); const h = y(), { value: u, updateValue: N } = ie(t, E), i = y(), V = ue("valueTypeMap"), f = m.useWatch(t.name, i); C(() => f.value, (e) => { N(e), t.onChange?.(e); }, { deep: !0, flush: "post" }), C(u, (e) => { e !== s(f) && (ee(e, s(f)) || i.value?.setFieldValue(t.name, e)); }, { deep: !0 }); const k = ne(t, V); function L() { i.value?.resetFields(); } function _(e) { return e ? (c(e) ? e : [e]).map((l) => c(l) ? [t.name, ...l] : [t.name, l]) : void 0; } async function D(e, n) { return (await i.value?.validateFields(_(e), n))?.[t.name]; } function O(e, n) { const l = s(u)?.length || 0; if (b(t.maxLength) && l >= t.maxLength) return; const a = { ...e || {} }; i.value?.setFieldValue?.(t.name, a, !0, (o, r) => { if (!o[r]) { o[r] = [a]; return; } te(n) ? o[r].push(a) : o[r].splice(n, 0, a); }); } function T(e, n = "suffix") { const l = s(u)?.length || 0, a = g(e) ? e : e.length; if (b(t.maxLength) && l + a > t.maxLength) return; const o = g(e) ? new Array(e).fill(0).map(() => ({})) : ae(e); i.value?.setFieldValue?.(t.name, o, !0, (r, d) => { if (!r[d]) { r[d] = [...o]; return; } n === "suffix" ? r[d].push(...o) : r[d].unshift(...o); }); } function j(e) { const n = new Set(g(e) ? [e] : e); i.value?.setFieldValue?.(t.name, void 0, !0, (l, a) => { l[a] = l[a].filter((o, r) => !n.has(r)); }); } function A(e) { const n = new Set(c(e) ? e : [e]); n.size !== 0 && i.value?.setFieldValue?.(t.name, void 0, !0, (l, a) => { l[a] = l[a].filter((o) => !n.has(o[t.rowKey])); }); } function z() { return s(u); } function G(e) { i.value?.setFieldValue(t.name, e); } function I(e) { return s(u)?.[e]; } function K(e, n, l = !0) { i.value?.setFieldValue?.(t.name, void 0, !0, (a, o) => { if (!(!a[o] || !a[o][e])) { if (!l) { const r = Object.keys(a[o][e]); for (const d of r) d !== t.rowKey && delete a[o][e][d]; } Object.assign(a[o][e], { ...n }); } }); } function P(e) { const n = e === "end" ? u.value.length - 1 : e; h.value?.scrollToRow(n); } function H() { i.value?.setFieldValue?.(t.name, []); } return x({ resetFields: L, validateFields: D, add: O, remove: j, getRowData: I, getRowsData: z, setRowData: K, addMultiple: T, scrollTo: P, clear: H, setTableData: G, removeByKey: A }), (e, n) => (q(), $(s(m), { ref_key: "formRef", ref: i, "initial-values": { [t.name]: s(u) }, style: { height: "100%" } }, { default: p(() => [w(s(m).FormItem, { name: e.name, "no-style": "" }, { default: p(() => [w(de, J(s(oe)(t, ["name", "value", "onUpdate:value", "maxLength", "onChange", "defaultValue"]), { ref_key: "tableRef", ref: h, class: [s(S)(), s(F)], columns: s(k), "data-source": s(u), "search-form": !1 }), Q({ _: 2 }, [X(B, (l, a) => ({ name: a, fn: p((o) => [Y(e.$slots, a, Z(M(o || {})))]) }))]), 1040, ["class", "columns", "data-source"])]), _: 3 }, 8, ["name"])]), _: 3 }, 8, ["initial-values"])); } }); export { Fe as default };