@aplus-frontend/ui
Version:
317 lines (316 loc) • 8.05 kB
JavaScript
import { defineComponent as I, useSlots as W, ref as y, watch as C, unref as r, createBlock as U, openBlock as $, withCtx as p, createVNode as w, mergeProps as q, createSlots as J, renderList as Q, renderSlot as X, normalizeProps as Y, guardReactiveProps as Z } from "vue";
import { ApForm as m } from "../../ap-form/index.mjs";
import { isEqual as M, isArray as c, isUndefined as ee, isNumber as g, cloneDeep as ae, omit as te } from "lodash-unified";
import "../../config-provider/index.mjs";
import "../../hooks/index.mjs";
import { isDef as b } from "../../utils/index.mjs";
import { useGetEditableColumns as oe } from "../hooks/use-editable-columns.mjs";
import "../index.vue2.mjs";
import { useDevWarning as ne } from "../../utils/warning.mjs";
import { useNamespace as le } from "../../config-provider/hooks/use-namespace.mjs";
import { useControllableValue as se } from "../../hooks/useControllableValue.mjs";
import { useGlobalConfig as re } from "../../config-provider/hooks/use-global-config.mjs";
import ie from "../index.vue.mjs";
const Re = /* @__PURE__ */ I({
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,
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 = W(), a = v, {
b: F
} = le("editable-grid"), S = R;
ne("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: E
} = se(a, S), i = y(), N = re("valueTypeMap"), f = m.useWatch(a.name, i);
C(() => f.value, (e) => {
E(e), a.onChange?.(e);
}, {
deep: !0,
flush: "post"
}), C(u, (e) => {
e !== r(f) && (M(e, r(f)) || i.value?.setFieldValue(a.name, e));
}, {
deep: !0
});
const V = oe(a, N);
function k() {
i.value?.resetFields();
}
function L(e) {
return e ? (c(e) ? e : [e]).map((l) => c(l) ? [a.name, ...l] : [a.name, l]) : void 0;
}
async function _(e, n) {
return (await i.value?.validateFields(L(e), n))?.[a.name];
}
function D(e, n) {
const l = r(u)?.length || 0;
if (b(a.maxLength) && l >= a.maxLength)
return;
const t = {
...e || {}
};
i.value?.setFieldValue?.(a.name, t, !0, (o, s) => {
if (!o[s]) {
o[s] = [t];
return;
}
ee(n) ? o[s].push(t) : o[s].splice(n, 0, t);
});
}
function T(e, n = "suffix") {
const l = r(u)?.length || 0, t = g(e) ? e : e.length;
if (b(a.maxLength) && l + t > a.maxLength)
return;
const o = g(e) ? new Array(e).fill(0).map(() => ({})) : ae(e);
i.value?.setFieldValue?.(a.name, o, !0, (s, d) => {
if (!s[d]) {
s[d] = [...o];
return;
}
n === "suffix" ? s[d].push(...o) : s[d].unshift(...o);
});
}
function O(e) {
const n = new Set(g(e) ? [e] : e);
i.value?.setFieldValue?.(a.name, void 0, !0, (l, t) => {
l[t] = l[t].filter((o, s) => !n.has(s));
});
}
function j(e) {
const n = new Set(c(e) ? e : [e]);
n.size !== 0 && i.value?.setFieldValue?.(a.name, void 0, !0, (l, t) => {
l[t] = l[t].filter((o) => !n.has(o[a.rowKey]));
});
}
function A() {
return r(u);
}
function z(e) {
i.value?.setFieldValue(a.name, e);
}
function G(e) {
return r(u)?.[e];
}
function K(e, n, l = !0) {
i.value?.setFieldValue?.(a.name, void 0, !0, (t, o) => {
if (!(!t[o] || !t[o][e])) {
if (!l) {
const s = Object.keys(t[o][e]);
for (const d of s)
d !== a.rowKey && delete t[o][e][d];
}
Object.assign(t[o][e], {
...n
});
}
});
}
function P(e) {
const n = e === "end" ? u.value.length - 1 : e;
h.value?.scrollToRow(n);
}
function H() {
i.value?.setFieldValue?.(a.name, []);
}
return x({
resetFields: k,
validateFields: _,
add: D,
remove: O,
getRowData: G,
getRowsData: A,
setRowData: K,
addMultiple: T,
scrollTo: P,
clear: H,
setTableData: z,
removeByKey: j
}), (e, n) => ($(), U(r(m), {
ref_key: "formRef",
ref: i,
"initial-values": {
[a.name]: r(u)
},
style: {
height: "100%"
}
}, {
default: p(() => [w(r(m).FormItem, {
name: e.name,
"no-style": ""
}, {
default: p(() => [w(ie, q(r(te)(a, ["name", "value", "onUpdate:value", "maxLength", "onChange", "defaultValue"]), {
ref_key: "tableRef",
ref: h,
class: r(F)(),
columns: r(V),
"data-source": r(u),
"search-form": !1
}), J({
_: 2
}, [Q(B, (l, t) => ({
name: t,
fn: p((o) => [X(e.$slots, t, Y(Z(o || {})))])
}))]), 1040, ["class", "columns", "data-source"])]),
_: 3
}, 8, ["name"])]),
_: 3
}, 8, ["initial-values"]));
}
});
export {
Re as default
};