UNPKG

@aplus-frontend/ui

Version:

294 lines (293 loc) 7.56 kB
import { defineComponent as z, useSlots as G, toRef as H, ref as c, unref as s, watch as K, nextTick as P, createBlock as A, openBlock as W, mergeProps as g, withCtx as h, createVNode as U, createSlots as $, renderList as q, renderSlot as J, normalizeProps as Q, guardReactiveProps as X } from "vue"; import { isUndefined as Y, isNumber as d, cloneDeep as Z, isArray as M, omit as ee } from "lodash-unified"; import { ApForm as y } from "../../ap-form/index.mjs"; import { useInjectForm as te } from "../../ap-form/context.mjs"; import { getModelValue as oe } from "../../ap-form/utils/get.mjs"; import "../../config-provider/index.mjs"; import "../../utils/index.mjs"; import { useDevWarning as ae } from "../../utils/warning.mjs"; import { useGetEditableColumns as le } from "../hooks/use-editable-columns.mjs"; import "../index.vue2.mjs"; import ne from "../style/editable.mjs"; import { useNamespace as re } from "../../config-provider/hooks/use-namespace.mjs"; import { useGlobalConfig as se } from "../../config-provider/hooks/use-global-config.mjs"; import { isDef as C } from "../../utils/is.mjs"; import ie from "../index.vue.mjs"; const ve = /* @__PURE__ */ z({ name: "EditableGridFormItem", __name: "form-item", 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: {}, rowHoverable: { type: Boolean }, 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: {}, onFieldChange: {}, label: {}, name: {}, formItem: { default: () => ({}) } }, setup(w, { expose: b }) { const x = G(), a = w; ae("EditableGridFormItem")(!1, "breaking", "EditableGridFormItem has been EOL, Please use EditableAgGridFormItem(https://aplus.aplnk.com/aplus-ui/components/ag-grid/editable/) instead."); const { b: R } = re("editable-grid"), B = ne("editable-grid"), { internalInstance: i, model: S } = te(), m = H(a.name), f = c(oe(s(S), m.value) || []), v = y.useWatch(m); K(() => v.value, async (e) => { await P(), f.value = e, a.onChange?.(e); }, { deep: !0 }); const p = c(), F = se("valueTypeMap"), I = le(a, F); function N(e, l) { const r = s(f)?.length || 0; if (C(a.maxLength) && r >= a.maxLength) return; const t = { ...e || {} }; i?.setFieldValue(a.name, t, !0, (o, n) => { if (!o[n]) { o[n] = [t]; return; } Y(l) ? o[n].push(t) : o[n].splice(l, 0, t); }); } function D(e, l = "suffix") { const r = s(f)?.length || 0, t = d(e) ? e : e.length; if (C(a.maxLength) && r + t > a.maxLength) return; const o = d(e) ? new Array(e).fill(0).map(() => ({})) : Z(e); i?.setFieldValue(a.name, o, !0, (n, u) => { if (!n[u]) { n[u] = [...o]; return; } l === "suffix" ? n[u].push(...o) : n[u].unshift(...o); }); } function E(e) { const l = new Set(d(e) ? [e] : e); i?.setFieldValue(a.name, void 0, !0, (r, t) => { r[t] = r[t].filter((o, n) => !l.has(n)); }); } function k(e) { const l = new Set(M(e) ? e : [e]); l.size !== 0 && i?.setFieldValue?.(a.name, void 0, !0, (r, t) => { r[t] = r[t].filter((o) => !l.has(o[a.rowKey])); }); } function L() { return s(f); } function V(e) { return s(f)?.[e]; } function T(e, l, r = !0) { i?.setFieldValue(a.name, void 0, !0, (t, o) => { if (!(!t[o] || !t[o][e])) { if (!r) { const n = Object.keys(t[o][e]); for (const u of n) u !== a.rowKey && delete t[o][e][u]; } Object.assign(t[o][e], { ...l }); } }); } function j(e) { i?.setFieldValue(a.name, e); } function O(e) { const l = e === "end" ? f.value.length - 1 : e; p.value?.scrollToRow(l); } function _() { i?.setFieldValue?.(a.name, []); } return b({ add: N, remove: E, getRowData: V, getRowsData: L, setRowData: T, addMultiple: D, scrollTo: O, setTableData: j, clear: _, removeByKey: k }), (e, l) => (W(), A(s(y).FormItem, g(e.formItem, { name: e.name, label: e.label }), { default: h(() => [U(ie, g(s(ee)(a, ["name", "value", "onUpdate:value", "maxLength", "onChange", "defaultValue", "formItem"]), { ref_key: "tableRef", ref: p, class: [s(R)(), s(B)], columns: s(I), "data-source": f.value, "search-form": !1 }), $({ _: 2 }, [q(x, (r, t) => ({ name: t, fn: h((o) => [J(e.$slots, t, Q(X(o || {})))]) }))]), 1040, ["class", "columns", "data-source"])]), _: 3 }, 16, ["name", "label"])); } }); export { ve as default };