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