@aplus-frontend/ui
Version:
234 lines (233 loc) • 5.8 kB
JavaScript
import { defineComponent as G, useSlots as H, ref as f, watch as O, unref as n, createBlock as U, openBlock as W, withCtx as d, createVNode as y, mergeProps as M, createSlots as $, renderList as q, renderSlot as J, normalizeProps as Q, guardReactiveProps as X } from "vue";
import { ApForm as u } from "../../ap-form/index.mjs";
import { isEqual as Y, isArray as w, omit as Z } from "lodash-unified";
import "../../config-provider/index.mjs";
import "../../hooks/index.mjs";
import { useGetEditableColumns as ee } from "../hooks/use-editable-columns.mjs";
import "../index.vue2.mjs";
import { useEditableApi as oe } from "../hooks/use-editable-api.mjs";
import { arrayToObject as p } from "./utils.mjs";
import { useNamespace as ae } from "../../config-provider/hooks/use-namespace.mjs";
import { useControllableValue as te } from "../../hooks/useControllableValue.mjs";
import { useGlobalConfig as ne } from "../../config-provider/hooks/use-global-config.mjs";
import le from "../index.vue.mjs";
const be = /* @__PURE__ */ G({
name: "EditableGrid",
__name: "index",
props: {
dropdownPrefixCls: {},
bordered: {
type: Boolean
},
locale: {},
onResizeColumn: {},
getPopupContainer: {},
scroll: {},
sortDirections: {},
showSorterTooltip: {
type: [Boolean, Object]
},
prefixCls: {},
rowKey: {
type: [String, Function],
default: "key"
},
tableLayout: {},
title: {},
id: {},
showHeader: {
type: Boolean
},
components: {},
customRow: {},
customHeaderRow: {},
direction: {},
expandFixed: {
type: [String, Boolean]
},
expandColumnWidth: {},
expandedRowKeys: {},
defaultExpandedRowKeys: {},
expandedRowRender: {},
expandRowByClick: {
type: Boolean
},
expandIcon: {},
onExpand: {},
onExpandedRowsChange: {},
defaultExpandAllRows: {
type: Boolean
},
indentSize: {},
expandIconColumnIndex: {},
showExpandColumn: {
type: Boolean
},
expandedRowClassName: {},
childrenColumnName: {},
rowExpandable: {},
transformCellText: {},
rowSelection: {
type: Boolean
},
onLoadingChange: {},
onShownColumnsChange: {},
pagination: {
type: [Boolean, Object],
default: !1
},
searchFormWrapperStyle: {},
tableWrapperStyle: {},
wrapperStyle: {},
tableStyle: {},
adaptive: {
type: Boolean
},
columnResizable: {
type: Boolean,
default: !1
},
loading: {
type: Boolean,
default: void 0
},
summary: {},
rowHeight: {
default: 66
},
advanceRenderer: {
type: Boolean
},
browserTooltips: {
type: Boolean
},
virtual: {
type: [Boolean, Object],
default: void 0
},
onRowClicked: {},
onScrollEnd: {},
rowClassName: {},
rowClassRules: {},
autoHeight: {
type: Boolean
},
onUpdate: {},
columns: {},
value: {},
defaultValue: {},
"onUpdate:value": {},
onChange: {},
maxLength: {},
name: {
default: "ap-editable-table-inner-name"
},
onFieldChange: {}
},
emits: ["update:value"],
setup(g, {
expose: h,
emit: b
}) {
const v = H(), o = g, {
b: C
} = ae("editable-aggrid"), R = b, s = f(), {
value: r,
updateValue: m
} = te(o, R), l = f(), x = u.useWatch(o.name, l);
O(r, (e) => {
const a = p(e, o.rowKey);
Y(a, n(x)) || l.value?.setFieldValue(o.name, a);
}, {
deep: !0
});
const B = ne("valueTypeMap"), S = ee(o, B), {
add: _,
addMultiple: F,
remove: E,
removeByKey: T,
getRowData: N,
getRowsData: A,
setRowData: V,
clear: k,
refreshRowIds: i
} = oe(o, l, r, m);
function D() {
const e = s.value?._internalGridApi;
if (!i.value?.length || !e)
return;
const a = i.value.map((t) => e.getRowNode(t)).filter((t) => !!t);
e.refreshCells({
rowNodes: a,
force: !0
}), i.value = [];
}
function K() {
l.value?.resetFields();
}
function j(e) {
return e ? (w(e) ? e : [e]).map((t) => w(t) ? [o.name, ...t] : [o.name, t]) : void 0;
}
async function z(e, a) {
return (await l.value?.validateFields(j(e), a))?.[o.name];
}
function I(e) {
m(e);
const a = p(e, o.rowKey);
l.value?.setFieldValue(o.name, a);
}
function L(e) {
const a = e === "end" ? r.value.length - 1 : e;
s.value?.scrollToRow(a);
}
return h({
resetFields: K,
validateFields: z,
add: _,
addMultiple: F,
remove: E,
removeByKey: T,
getRowData: N,
getRowsData: A,
setRowData: V,
clear: k,
setTableData: I,
scrollTo: L
}), (e, a) => (W(), U(n(u), {
ref_key: "formRef",
ref: l,
"initial-values": {
[o.name]: n(p)(n(r), o.rowKey)
},
style: {
height: "100%"
}
}, {
default: d(() => [y(n(u).FormItem, {
name: e.name,
"no-style": ""
}, {
default: d(() => [y(le, M(n(Z)(o, ["name", "value", "onUpdate:value", "maxLength", "onChange", "defaultValue"]), {
ref_key: "tableRef",
ref: s,
class: n(C)(),
size: "mini",
columns: n(S),
"data-source": n(r),
"search-form": !1,
onUpdate: D
}), $({
_: 2
}, [q(v, (t, c) => ({
name: c,
fn: d((P) => [J(e.$slots, c, Q(X(P || {})))])
}))]), 1040, ["class", "columns", "data-source"])]),
_: 3
}, 8, ["name"])]),
_: 3
}, 8, ["initial-values"]));
}
});
export {
be as default
};