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