@antdv-vue/pro-table 0.0.0-stage → 2.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/CHANGELOG.md +255 -0
  2. package/README.md +106 -2
  3. package/dist/InternalTable.d.ts +360 -0
  4. package/dist/InternalTable.js +444 -0
  5. package/dist/RenderTypings.d.ts +33 -0
  6. package/dist/RenderTypings.js +1 -0
  7. package/dist/ResizableTableTitle.d.ts +24 -0
  8. package/dist/ResizableTableTitle.js +89 -0
  9. package/dist/Store/Provide.d.ts +68 -0
  10. package/dist/Store/Provide.js +132 -0
  11. package/dist/Table.d.ts +363 -0
  12. package/dist/Table.js +151 -0
  13. package/dist/TableRender.d.ts +54 -0
  14. package/dist/TableRender.js +295 -0
  15. package/dist/components/Alert/index.d.ts +45 -0
  16. package/dist/components/Alert/index.js +94 -0
  17. package/dist/components/Alert/style/index.d.ts +8 -0
  18. package/dist/components/Alert/style/index.js +11 -0
  19. package/dist/components/ColumnSetting/CheckboxList.d.ts +24 -0
  20. package/dist/components/ColumnSetting/CheckboxList.js +138 -0
  21. package/dist/components/ColumnSetting/CheckboxListItem.d.ts +17 -0
  22. package/dist/components/ColumnSetting/CheckboxListItem.js +84 -0
  23. package/dist/components/ColumnSetting/GroupCheckboxList.d.ts +22 -0
  24. package/dist/components/ColumnSetting/GroupCheckboxList.js +82 -0
  25. package/dist/components/ColumnSetting/ToolTipIcon.d.ts +12 -0
  26. package/dist/components/ColumnSetting/ToolTipIcon.js +47 -0
  27. package/dist/components/ColumnSetting/index.d.ts +26 -0
  28. package/dist/components/ColumnSetting/index.js +117 -0
  29. package/dist/components/ColumnSetting/style/index.d.ts +8 -0
  30. package/dist/components/ColumnSetting/style/index.js +73 -0
  31. package/dist/components/DragSortTable/index.d.ts +375 -0
  32. package/dist/components/DragSortTable/index.js +166 -0
  33. package/dist/components/DragSortTable/style/index.d.ts +8 -0
  34. package/dist/components/DragSortTable/style/index.js +25 -0
  35. package/dist/components/Dropdown/Button.d.ts +20 -0
  36. package/dist/components/Dropdown/Button.js +155 -0
  37. package/dist/components/Dropdown/index.d.ts +27 -0
  38. package/dist/components/Dropdown/index.js +149 -0
  39. package/dist/components/EditableTable/CellEditorTable.d.ts +63 -0
  40. package/dist/components/EditableTable/CellEditorTable.js +167 -0
  41. package/dist/components/EditableTable/EditableTable.d.ts +67 -0
  42. package/dist/components/EditableTable/EditableTable.js +141 -0
  43. package/dist/components/EditableTable/InternalEditableTable.d.ts +189 -0
  44. package/dist/components/EditableTable/InternalEditableTable.js +508 -0
  45. package/dist/components/EditableTable/RowEditorTable.d.ts +63 -0
  46. package/dist/components/EditableTable/RowEditorTable.js +147 -0
  47. package/dist/components/EditableTable/context.d.ts +9 -0
  48. package/dist/components/EditableTable/context.js +11 -0
  49. package/dist/components/EditableTable/index.d.ts +5 -0
  50. package/dist/components/EditableTable/index.js +5 -0
  51. package/dist/components/Form/FormRender.d.ts +77 -0
  52. package/dist/components/Form/FormRender.js +198 -0
  53. package/dist/components/Form/index.d.ts +33 -0
  54. package/dist/components/Form/index.js +91 -0
  55. package/dist/components/ToolBar/DensityIcon.d.ts +22 -0
  56. package/dist/components/ToolBar/DensityIcon.js +71 -0
  57. package/dist/components/ToolBar/FullScreenIcon.d.ts +6 -0
  58. package/dist/components/ToolBar/FullScreenIcon.js +30 -0
  59. package/dist/components/ToolBar/HeaderMenu.d.ts +22 -0
  60. package/dist/components/ToolBar/HeaderMenu.js +84 -0
  61. package/dist/components/ToolBar/index.d.ts +102 -0
  62. package/dist/components/ToolBar/index.js +322 -0
  63. package/dist/components/ToolBar/style/index.d.ts +8 -0
  64. package/dist/components/ToolBar/style/index.js +116 -0
  65. package/dist/index.d.ts +11 -0
  66. package/dist/index.js +10 -0
  67. package/dist/pro-table.esm.js +3274 -0
  68. package/dist/style/index.d.ts +11 -0
  69. package/dist/style/index.js +162 -0
  70. package/dist/typing.d.ts +409 -0
  71. package/dist/typing.js +1 -0
  72. package/dist/useFetchData.d.ts +10 -0
  73. package/dist/useFetchData.js +243 -0
  74. package/dist/utils/cellRenderToFromItem.d.ts +52 -0
  75. package/dist/utils/cellRenderToFromItem.js +163 -0
  76. package/dist/utils/columnRender.d.ts +54 -0
  77. package/dist/utils/columnRender.js +148 -0
  78. package/dist/utils/columnSort.d.ts +7 -0
  79. package/dist/utils/columnSort.js +17 -0
  80. package/dist/utils/genProColumnsToColumns.d.ts +69 -0
  81. package/dist/utils/genProColumnsToColumns.js +197 -0
  82. package/dist/utils/index.d.ts +122 -0
  83. package/dist/utils/index.js +227 -0
  84. package/dist/utils/useDragSort.d.ts +182 -0
  85. package/dist/utils/useDragSort.js +162 -0
  86. package/package.json +67 -3
@@ -0,0 +1,243 @@
1
+ import { postDataPipeline } from "./utils/index.js";
2
+ import { computed, ref } from "vue";
3
+ import { runFunction, useDebounceFn, useEffect, useMountMergeState, usePrevious } from "@antdv-vue/pro-utils";
4
+ //#region src/useFetchData.ts
5
+ /**
6
+ * 组合用户的配置和默认值
7
+ */
8
+ function mergeOptionAndPageInfo({ pageInfo }) {
9
+ if (pageInfo.value) {
10
+ const { current, pageSize, defaultPageSize } = pageInfo.value;
11
+ return {
12
+ current: current || 1,
13
+ total: 0,
14
+ pageSize: pageSize || defaultPageSize || 20
15
+ };
16
+ }
17
+ return {
18
+ current: 1,
19
+ total: 0,
20
+ pageSize: 20
21
+ };
22
+ }
23
+ function useFetchData(getData, defaultData, options) {
24
+ /**
25
+ * 用于保存组件是否被卸载的状态的引用
26
+ */
27
+ const umount = ref(false);
28
+ /**
29
+ * 用于保存 AbortController 实例的引用,方便需要时进行请求的取消操作
30
+ */
31
+ const abortRef = ref(null);
32
+ /**
33
+ * useFetchData 钩子的配置项
34
+ */
35
+ const { onLoad, manual, polling, onRequestError, debounceTime = ref(20), effects = [], dataSource, loading, pageInfo, onLoadingChange, onPageInfoChange, onDataSourceChange } = options || {};
36
+ /** 是否首次加载的指示器 */
37
+ const manualRequest = ref(manual.value);
38
+ /** 轮询的setTime ID 存储 */
39
+ const pollingSetTime = ref(null);
40
+ /**
41
+ * 用于存储最新的数据,这样可以在切换的时候保持数据的一致性
42
+ */
43
+ const [tableDataList, setTableDataList] = useMountMergeState(() => defaultData, {
44
+ value: dataSource,
45
+ defaultValue: defaultData,
46
+ onChange: onDataSourceChange
47
+ });
48
+ /**
49
+ * 表格的加载状态
50
+ */
51
+ const [tableLoading, setTableLoading] = useMountMergeState(() => false, {
52
+ value: computed(() => typeof loading.value === "object" ? loading.value?.spinning : loading.value),
53
+ onChange: onLoadingChange
54
+ });
55
+ /**
56
+ * 表示页面信息的类型 useMountMergeState 钩子的初始值和参数
57
+ * @property {number} current 当前页码
58
+ * @property {number} pageSize 页面大小
59
+ * @property {number} total 数据总量
60
+ */
61
+ const [pageInfoState, setPageInfoState] = useMountMergeState(() => mergeOptionAndPageInfo(options), { onChange: onPageInfoChange });
62
+ /**
63
+ * 用于比较并设置页面信息和回调函数的引用更新
64
+ */
65
+ const setPageInfo = (changePageInfo) => {
66
+ if (changePageInfo.current !== pageInfoState.value.current || changePageInfo.pageSize !== pageInfoState.value.pageSize || changePageInfo.total !== pageInfoState.value.total) setPageInfoState(changePageInfo);
67
+ };
68
+ const [pollingLoading, setPollingLoading] = useMountMergeState(false);
69
+ const setDataAndLoading = (newData, dataTotal) => {
70
+ setTableDataList(newData);
71
+ if (pageInfoState?.value.total !== dataTotal) setPageInfo({
72
+ ...pageInfoState.value,
73
+ total: dataTotal || newData.length
74
+ });
75
+ };
76
+ /**
77
+ * 上一页的页码
78
+ */
79
+ const prePage = usePrevious(computed(() => pageInfoState.value.current));
80
+ /**
81
+ * 上一页的页面大小
82
+ */
83
+ const prePageSize = usePrevious(computed(() => pageInfoState.value.pageSize));
84
+ /**
85
+ * 上一页的轮询时间
86
+ */
87
+ const prePolling = usePrevious(polling);
88
+ const requestFinally = () => {
89
+ setTableLoading(false);
90
+ setPollingLoading(false);
91
+ };
92
+ /** 请求数据 */
93
+ const fetchList = async (isPolling, signal) => {
94
+ if (manualRequest.value) {
95
+ manualRequest.value = false;
96
+ return;
97
+ }
98
+ if (!isPolling) setTableLoading(true);
99
+ else setPollingLoading(true);
100
+ const { pageSize, current } = pageInfoState.value || {};
101
+ try {
102
+ const pageParams = pageInfo.value !== false ? {
103
+ current,
104
+ pageSize
105
+ } : void 0;
106
+ const { data = [], success, total = 0, ...rest } = await getData.value?.(pageParams) || {};
107
+ if (signal?.aborted) return [];
108
+ if (success === false) return [];
109
+ const responseData = postDataPipeline(data, [options.postData].filter((item) => item));
110
+ if (signal?.aborted) return [];
111
+ setDataAndLoading(responseData, total);
112
+ onLoad?.(responseData, rest);
113
+ return responseData;
114
+ } catch (e) {
115
+ if (signal?.aborted) return [];
116
+ if (onRequestError === void 0) throw new Error(e);
117
+ if (tableDataList.value === void 0) setTableDataList([]);
118
+ onRequestError(e);
119
+ } finally {
120
+ if (!signal?.aborted) requestFinally();
121
+ }
122
+ return [];
123
+ };
124
+ /**
125
+ * 该函数用于进行数据请求,可以用于轮询或单次请求。
126
+ * 通过使用 AbortController 取消之前的请求,避免出现请求堆积。
127
+ * 若需要轮询,则在一定时间后再次调用该函数,最小时间为 200ms,避免一直处于 loading 状态。
128
+ * 如果请求被取消,则返回空。
129
+ */
130
+ const fetchListDebounce = useDebounceFn(async (isPolling) => {
131
+ if (pollingSetTime.value) {
132
+ clearTimeout(pollingSetTime.value);
133
+ pollingSetTime.value = null;
134
+ }
135
+ if (!getData.value) return;
136
+ const abort = new AbortController();
137
+ abortRef.value = abort;
138
+ try {
139
+ /**
140
+ * 这段代码使用了 Promise.race,同时发起了两个异步请求。
141
+ * fetchList 函数发起一个数据请求,而第二个 Promise 是等待通过 AbortSignal 取得一个信号。
142
+ * 如果第二个 Promise 得到了一个 AbortSignal 的信号,就会触发 reject,Promise.race 的结果也会结束。
143
+ * 这样,就达到了取消请求的目的。如果 fetchList 函数先返回了结果,那么该结果就是 Promise.race 的结果,
144
+ * 此时第二个 Promise 就会被取消。
145
+ */
146
+ const msg = await Promise.race([fetchList(isPolling, abort.signal), new Promise((_, reject) => {
147
+ abortRef.value?.signal.addEventListener("abort", () => {
148
+ reject(/* @__PURE__ */ new Error("aborted"));
149
+ fetchListDebounce.cancel();
150
+ requestFinally();
151
+ });
152
+ })]);
153
+ if (abort.signal.aborted) return;
154
+ const needPolling = runFunction(polling?.value, msg);
155
+ if (needPolling && !umount.value) pollingSetTime.value = setTimeout(() => fetchListDebounce.run(needPolling), Math.max(needPolling, 2e3));
156
+ return msg;
157
+ } catch (e) {
158
+ if (e === "aborted") return;
159
+ throw e;
160
+ }
161
+ }, debounceTime.value || 30);
162
+ /**
163
+ * 取消请求
164
+ */
165
+ const abortFetch = () => {
166
+ abortRef.value?.abort();
167
+ fetchListDebounce.cancel();
168
+ requestFinally();
169
+ };
170
+ useEffect(() => {
171
+ if (!polling.value && pollingSetTime.value) {
172
+ clearTimeout(pollingSetTime.value);
173
+ pollingSetTime.value = null;
174
+ }
175
+ if (!prePolling.value && polling.value) (async () => await fetchListDebounce.run(true))();
176
+ return () => {
177
+ if (pollingSetTime.value) {
178
+ clearTimeout(pollingSetTime.value);
179
+ pollingSetTime.value = null;
180
+ }
181
+ };
182
+ }, [polling]);
183
+ useEffect(() => {
184
+ umount.value = false;
185
+ return () => {
186
+ umount.value = true;
187
+ };
188
+ }, []);
189
+ /** PageIndex 改变的时候自动刷新 */
190
+ useEffect(() => {
191
+ const { current, pageSize } = pageInfoState.value || {};
192
+ if ((!prePage.value || prePage.value === current) && (!prePageSize.value || prePageSize.value === pageSize)) return;
193
+ if (pageInfo.value && tableDataList.value && tableDataList.value.length > pageSize || 0) return;
194
+ if (current !== void 0 && tableDataList.value && tableDataList.value.length <= pageSize) {
195
+ abortFetch();
196
+ (async () => await fetchListDebounce.run(false))();
197
+ }
198
+ }, [() => pageInfoState?.value.current]);
199
+ useEffect(() => {
200
+ if (!prePageSize.value) return;
201
+ abortFetch();
202
+ (async () => await fetchListDebounce.run(false))();
203
+ }, [() => pageInfoState.value.pageSize]);
204
+ /**
205
+ * 检查是否有正在进行的请求需要被中止。如果是,则使用 abort 中的方法来中止请求。
206
+ * 接下来,使用名为 fetchListDebounce 的防抖函数并传入 false 参数。这个函数可以防止请求过于频繁地发出,通过延迟执行传递给它的函数来实现。
207
+ * 最后,检查是否有正在进行的请求,如果有,则中止它。
208
+ */
209
+ useEffect(() => {
210
+ abortFetch();
211
+ (async () => await fetchListDebounce.run(false))();
212
+ if (!manual.value) manualRequest.value = false;
213
+ return () => abortFetch();
214
+ }, [...effects, manual]);
215
+ return {
216
+ dataSource: tableDataList,
217
+ setDataSource: setTableDataList,
218
+ loading: computed(() => typeof loading.value === "object" ? {
219
+ ...loading.value,
220
+ spinning: tableLoading.value
221
+ } : tableLoading.value),
222
+ reload: async () => {
223
+ abortFetch();
224
+ await fetchListDebounce.run(false);
225
+ },
226
+ pageInfo: pageInfoState,
227
+ pollingLoading,
228
+ reset: async () => {
229
+ const { defaultPageSize = 20, current = 1 } = pageInfo.value || {};
230
+ setPageInfo({
231
+ current,
232
+ total: 0,
233
+ pageSize: defaultPageSize
234
+ });
235
+ },
236
+ setPageInfo: async (info) => setPageInfo({
237
+ ...pageInfoState.value,
238
+ ...info
239
+ })
240
+ };
241
+ }
242
+ //#endregion
243
+ export { useFetchData as default };
@@ -0,0 +1,52 @@
1
+ import { ContainerReturnType } from "../Store/Provide.js";
2
+ import { ProColumnType } from "../typing.js";
3
+ import * as _$vue from "vue";
4
+ import { ProFormFieldProps } from "@antdv-vue/pro-form";
5
+ import { ProFieldValueObjectType, ProFieldValueType, ProSchemaComponentTypes, UseEditableUtilType } from "@antdv-vue/pro-utils";
6
+ import { ProFieldEmptyText } from "@antdv-vue/pro-field";
7
+ import { NamePath } from "antdv-next/dist/form/types";
8
+ import { AnyObject, Key as Key$1, VueNode as VueNode$1 } from "@v-c/util/dist/type";
9
+
10
+ //#region src/utils/cellRenderToFromItem.d.ts
11
+ interface CellRenderFromItemProps<T extends AnyObject, U extends Record<string, any>, ValueType extends (ProFieldValueType | ProFieldValueObjectType)> {
12
+ text: VueNode$1;
13
+ valueType: ProColumnType<T, ValueType>['valueType'];
14
+ index: number;
15
+ rowData?: T;
16
+ columnEmptyText?: ProFieldEmptyText;
17
+ columnProps?: ProColumnType<T, ValueType> & {
18
+ entity: T;
19
+ };
20
+ type?: ProSchemaComponentTypes;
21
+ recordKey?: Key$1;
22
+ mode: 'edit' | 'read';
23
+ /**
24
+ * If there is, use EditableTable in the Form
25
+ */
26
+ prefixName?: NamePath<string | number | boolean>;
27
+ counter?: ContainerReturnType<T, U, ValueType>;
28
+ proFieldProps?: ProFormFieldProps;
29
+ subName?: string[];
30
+ editableUtils?: UseEditableUtilType<T>;
31
+ }
32
+ /**
33
+ * 拼接用于编辑的 key
34
+ */
35
+ declare function spellNamePath(...rest: any[]): Key$1[];
36
+ /**
37
+ * 根据不同的类型来转化数值
38
+ *
39
+ * @param config
40
+ */
41
+ declare function cellRenderToFromItem<T extends AnyObject, U extends Record<string, any>, ValueType extends (ProFieldValueType | ProFieldValueObjectType)>(config: CellRenderFromItemProps<T, U, ValueType>): string | number | boolean | void | _$vue.ComponentOptions<any, any, any, _$vue.ComputedOptions, _$vue.MethodOptions, any, any, any, string, {}, {}, string, {}, {}, {}, string, _$vue.ComponentProvideOptions> | _$vue.FunctionalComponent<any, {}, any, {}> | {
42
+ new (...args: any[]): any;
43
+ __isFragment?: never;
44
+ __isTeleport?: never;
45
+ __isSuspense?: never;
46
+ } | _$vue.VNode<_$vue.RendererNode, _$vue.RendererElement, {
47
+ [key: string]: any;
48
+ }> | (string | number | boolean | void | _$vue.Component | _$vue.VNode<_$vue.RendererNode, _$vue.RendererElement, {
49
+ [key: string]: any;
50
+ }> | null | undefined)[] | null;
51
+ //#endregion
52
+ export { cellRenderToFromItem as default, spellNamePath };
@@ -0,0 +1,163 @@
1
+ import { Fragment, createVNode, defineComponent, isVNode, mergeProps } from "vue";
2
+ import { ProForm, ProFormField, useFieldContextInject } from "@antdv-vue/pro-form";
3
+ import { useIntl } from "@antdv-vue/pro-provider";
4
+ import { FormItem, InlineErrorFormItem, getFieldPropsOrFormItemProps, runFunction } from "@antdv-vue/pro-utils";
5
+ //#region src/utils/cellRenderToFromItem.tsx
6
+ function _isSlot(s) {
7
+ return typeof s === "function" || Object.prototype.toString.call(s) === "[object Object]" && !isVNode(s);
8
+ }
9
+ const SHOW_EMPTY_TEXT_LIST = [
10
+ "",
11
+ null,
12
+ void 0
13
+ ];
14
+ /**
15
+ * 拼接用于编辑的 key
16
+ */
17
+ function spellNamePath(...rest) {
18
+ return rest.filter((index) => index !== void 0).map((item) => {
19
+ if (typeof item === "number") return item.toString();
20
+ return item;
21
+ }).flat(1);
22
+ }
23
+ const CellRenderFromItem = /* @__PURE__ */ defineComponent((props, { expose }) => {
24
+ const intl = useIntl();
25
+ const formContext = useFieldContextInject();
26
+ const editableForm = ProForm.useFormInstance();
27
+ expose({});
28
+ return () => {
29
+ const { columnProps, prefixName, text, counter, rowData, index, recordKey, subName, proFieldProps, editableUtils } = props;
30
+ const key = recordKey || index;
31
+ const realIndex = editableUtils?.getRealIndex?.(rowData) ?? index;
32
+ const formItemName = spellNamePath(prefixName, prefixName ? subName : [], prefixName ? realIndex : key, columnProps?.key ?? columnProps?.dataIndex ?? index);
33
+ const rowName = formItemName.slice(0, -1);
34
+ const needProps = [editableForm, {
35
+ ...columnProps,
36
+ rowKey: rowName,
37
+ rowIndex: index,
38
+ isEditable: true
39
+ }];
40
+ const generateFormItem = () => {
41
+ const formItemProps = { ...getFieldPropsOrFormItemProps(columnProps?.formItemProps, ...needProps) };
42
+ formItemProps.messageVariables = {
43
+ label: columnProps?.title || intl.value.getMessage({
44
+ id: "editableTable.defaultFieldLabel",
45
+ defaultMessage: "此项"
46
+ }),
47
+ type: columnProps?.valueType || intl.value.getMessage({
48
+ id: "editableTable.defaultFieldType",
49
+ defaultMessage: "文本"
50
+ }),
51
+ ...formItemProps?.messageVariables
52
+ };
53
+ formItemProps.initialValue = (prefixName ? null : text) ?? formItemProps?.initialValue ?? columnProps?.initialValue;
54
+ let fieldDom = createVNode(ProFormField, mergeProps({
55
+ "key": formItemName.join("-"),
56
+ "name": formItemName,
57
+ "proFormFieldKey": key,
58
+ "ignoreFormItem": true,
59
+ "fieldProps": {
60
+ style: { width: "100%" },
61
+ ...getFieldPropsOrFormItemProps(columnProps?.fieldProps, ...needProps)
62
+ }
63
+ }, proFieldProps), null);
64
+ /**
65
+ * 如果没有自定义直接返回
66
+ */
67
+ if (columnProps?.formItemRender) {
68
+ fieldDom = columnProps.formItemRender({
69
+ ...columnProps,
70
+ index,
71
+ isEditable: true,
72
+ type: "table"
73
+ }, {
74
+ defaultRender: () => createVNode(Fragment, null, [fieldDom]),
75
+ type: "form",
76
+ recordKey,
77
+ record: {
78
+ ...rowData,
79
+ ...editableForm?.getFieldValue(rowName)
80
+ },
81
+ isEditable: true
82
+ }, editableForm, props.editableUtils);
83
+ if (columnProps.ignoreFormItem) return createVNode(Fragment, null, [fieldDom]);
84
+ }
85
+ return createVNode(InlineErrorFormItem, mergeProps({ "key": formItemName.join("-") }, formItemProps, {
86
+ "errorType": "popover",
87
+ "popoverProps": { getPopupContainer: formContext.getPopupContainer?.value || (() => counter?.rootDomRef?.value || document.body) },
88
+ "name": formItemName
89
+ }), _isSlot(fieldDom) ? fieldDom : { default: () => [fieldDom] });
90
+ };
91
+ if (formItemName.length === 0) return null;
92
+ if (typeof columnProps?.formItemRender === "function" || typeof columnProps?.fieldProps === "function" || typeof columnProps?.formItemProps === "function") return createVNode(FormItem, { "noStyle": true }, { default: () => generateFormItem() });
93
+ return generateFormItem();
94
+ };
95
+ }, {
96
+ name: "CellRenderFromItem",
97
+ inheritAttrs: false,
98
+ props: [
99
+ "columnEmptyText",
100
+ "columnProps",
101
+ "counter",
102
+ "editableUtils",
103
+ "index",
104
+ "mode",
105
+ "mode",
106
+ "prefixName",
107
+ "proFieldProps",
108
+ "recordKey",
109
+ "rowData",
110
+ "subName",
111
+ "text",
112
+ "type",
113
+ "valueType"
114
+ ]
115
+ });
116
+ /**
117
+ * 根据不同的类型来转化数值
118
+ *
119
+ * @param config
120
+ */
121
+ function cellRenderToFromItem(config) {
122
+ const { text, valueType, rowData, columnProps, index } = config;
123
+ if ((!valueType || ["textarea", "text"].includes(valueType.toString())) && !columnProps?.valueEnum && config.mode === "read") return SHOW_EMPTY_TEXT_LIST.includes(text) ? config.columnEmptyText : text;
124
+ if (typeof valueType === "function" && rowData) return cellRenderToFromItem({
125
+ ...config,
126
+ valueType: valueType(rowData, config.type) || "text"
127
+ });
128
+ const columnKey = columnProps?.key || columnProps?.dataIndex?.toString();
129
+ const dependencies = columnProps?.dependencies ? [
130
+ config.prefixName,
131
+ config.prefixName ? index?.toString() : config.recordKey?.toString(),
132
+ columnProps?.dependencies
133
+ ].filter(Boolean).flat(1) : [];
134
+ /**
135
+ * 生成公用的 proField dom 配置
136
+ */
137
+ const proFieldProps = {
138
+ valueEnum: runFunction(columnProps?.valueEnum, rowData),
139
+ request: columnProps?.request,
140
+ dependencies: columnProps?.dependencies ? [dependencies] : void 0,
141
+ originDependencies: columnProps?.dependencies ? [columnProps?.dependencies] : void 0,
142
+ params: runFunction(columnProps?.params, rowData, columnProps),
143
+ readonly: columnProps?.readonly,
144
+ text: valueType === "index" || valueType === "indexBorder" ? index : text,
145
+ mode: config.mode,
146
+ formItemRender: void 0,
147
+ valueType,
148
+ record: rowData,
149
+ proFieldProps: {
150
+ emptyText: config.columnEmptyText,
151
+ proFieldKey: columnKey ? `table-field-${columnKey}` : void 0
152
+ }
153
+ };
154
+ /** 只读模式直接返回就好了,不需要处理 formItem */
155
+ if (config.mode !== "edit") return createVNode(ProFormField, mergeProps({
156
+ "mode": "read",
157
+ "ignoreFormItem": true,
158
+ "fieldProps": getFieldPropsOrFormItemProps(columnProps?.fieldProps, null, columnProps)
159
+ }, proFieldProps), null);
160
+ return createVNode(CellRenderFromItem, mergeProps({ "key": config.recordKey }, config, { "proFieldProps": proFieldProps }), null);
161
+ }
162
+ //#endregion
163
+ export { cellRenderToFromItem as default, spellNamePath };
@@ -0,0 +1,54 @@
1
+ import { ContainerReturnType } from "../Store/Provide.js";
2
+ import { ProColumns } from "../typing.js";
3
+ import { ProFieldValueObjectType, ProFieldValueType, ProSchemaComponentTypes, UseEditableUtilType } from "@antdv-vue/pro-utils";
4
+ import { ProFieldEmptyText } from "@antdv-vue/pro-field";
5
+ import { AnyObject, VueNode as VueNode$1 } from "@v-c/util/dist/type";
6
+ import * as _$vue_jsx_runtime0 from "vue/jsx-runtime";
7
+
8
+ //#region src/utils/columnRender.d.ts
9
+ /** 转化列的定义 */
10
+ interface ColumnRenderInterface<T extends Record<string, any>, U extends Record<string, any>, ValueType extends (ProFieldValueType | ProFieldValueObjectType)> {
11
+ columnProps: ProColumns<T, ValueType>;
12
+ text: VueNode$1;
13
+ rowData: T;
14
+ index: number;
15
+ columnEmptyText?: ProFieldEmptyText;
16
+ type: ProSchemaComponentTypes;
17
+ counter?: ContainerReturnType<T, U, ValueType>;
18
+ editableUtils?: UseEditableUtilType<T>;
19
+ subName?: string[];
20
+ marginSM?: number;
21
+ }
22
+ declare function isMergeCell(dom: VueNode$1): any;
23
+ /**
24
+ * 增加了 icon 的功能 render title
25
+ *
26
+ * @param item
27
+ */
28
+ declare function renderColumnsTitle<T extends Record<string, any>, P extends (ProFieldValueType | ProFieldValueObjectType)>(item: ProColumns<T, P>): _$vue_jsx_runtime0.JSX.Element;
29
+ /**
30
+ * 默认的 filter 方法
31
+ *
32
+ * @param value
33
+ * @param record
34
+ * @param dataIndex
35
+ */
36
+ declare function defaultOnFilter(value: string, record: any, dataIndex: string | string[]): boolean;
37
+ /**
38
+ * 这个组件负责单元格的具体渲染
39
+ *
40
+ */
41
+ declare function columnRender<T extends AnyObject, U extends Record<string, any>, ValueType extends (ProFieldValueType | ProFieldValueObjectType)>({
42
+ columnProps,
43
+ text,
44
+ rowData,
45
+ index,
46
+ columnEmptyText,
47
+ counter,
48
+ type,
49
+ marginSM,
50
+ subName,
51
+ editableUtils
52
+ }: ColumnRenderInterface<T, U, ValueType>): VueNode$1;
53
+ //#endregion
54
+ export { columnRender as default, defaultOnFilter, isMergeCell, renderColumnsTitle };
@@ -0,0 +1,148 @@
1
+ import cellRenderToFromItem from "./cellRenderToFromItem.js";
2
+ import { Fragment, createVNode, defineComponent, isVNode } from "vue";
3
+ import { LabelIconTip, genCopyable, isNil } from "@antdv-vue/pro-utils";
4
+ import { Divider, Flex, Space } from "antdv-next";
5
+ import get from "@v-c/util/dist/utils/get";
6
+ //#region src/utils/columnRender.tsx
7
+ /** 转化列的定义 */
8
+ function _isSlot(s) {
9
+ return typeof s === "function" || Object.prototype.toString.call(s) === "[object Object]" && !isVNode(s);
10
+ }
11
+ function isMergeCell(dom) {
12
+ return dom && isVNode(dom) && dom?.props?.colSpan;
13
+ }
14
+ /**
15
+ * 增加了 icon 的功能 render title
16
+ *
17
+ * @param item
18
+ */
19
+ function renderColumnsTitle(item) {
20
+ const { title } = item;
21
+ const ellipsis = typeof item?.ellipsis === "boolean" ? item?.ellipsis : item?.ellipsis?.showTitle;
22
+ if (title && typeof title === "function") return createVNode(Fragment, null, [title(item, "table", createVNode(LabelIconTip, {
23
+ "label": null,
24
+ "tooltip": item.tooltip
25
+ }, null))]);
26
+ return createVNode(LabelIconTip, {
27
+ "label": title,
28
+ "tooltip": item.tooltip,
29
+ "ellipsis": ellipsis
30
+ }, null);
31
+ }
32
+ /** 判断是否为不可编辑的单元格 */
33
+ function isNotEditableCell(text, record, index, editable) {
34
+ if (typeof editable === "boolean") return !editable;
35
+ return editable?.(text, record, index) === false;
36
+ }
37
+ /**
38
+ * 默认的 filter 方法
39
+ *
40
+ * @param value
41
+ * @param record
42
+ * @param dataIndex
43
+ */
44
+ function defaultOnFilter(value, record, dataIndex) {
45
+ const recordElement = Array.isArray(dataIndex) ? get(record, dataIndex) : record[dataIndex];
46
+ return String(String(recordElement)) === String(value);
47
+ }
48
+ const EditableOptionActions = /* @__PURE__ */ defineComponent((props, { expose }) => {
49
+ expose({});
50
+ return () => {
51
+ const { editableUtils, rowData, index, columnProps, marginSM, type } = props;
52
+ const actions = editableUtils?.actionRender?.({
53
+ ...rowData,
54
+ index
55
+ });
56
+ if (!actions) return null;
57
+ return type === "table" ? createVNode(Space, {
58
+ "align": "center",
59
+ "size": 0,
60
+ "separator": createVNode(Divider, { "orientation": "vertical" }, null)
61
+ }, _isSlot(actions) ? actions : { default: () => [actions] }) : createVNode(Flex, {
62
+ "align": "center",
63
+ "gap": marginSM,
64
+ "justify": columnProps?.align === "center" ? "center" : "flex-start"
65
+ }, _isSlot(actions) ? actions : { default: () => [actions] });
66
+ };
67
+ }, {
68
+ name: "EditableOptionActions",
69
+ inheritAttrs: false,
70
+ props: [
71
+ "editableUtils",
72
+ "rowData",
73
+ "index",
74
+ "columnProps",
75
+ "type",
76
+ "marginSM"
77
+ ]
78
+ });
79
+ /**
80
+ * 这个组件负责单元格的具体渲染
81
+ *
82
+ */
83
+ function columnRender({ columnProps, text, rowData, index, columnEmptyText, counter, type, marginSM, subName, editableUtils }) {
84
+ const { action, prefixName } = counter;
85
+ const { isEditable, recordKey } = editableUtils?.isEditable?.({
86
+ ...rowData,
87
+ index
88
+ });
89
+ const { renderText = (val) => val } = columnProps;
90
+ const renderTextStr = renderText(text, rowData, index, action?.value);
91
+ const mode = isEditable && !isNotEditableCell(text, rowData, index, columnProps?.editable) ? "edit" : "read";
92
+ const textDom = cellRenderToFromItem({
93
+ text: renderTextStr,
94
+ valueType: columnProps.valueType || "text",
95
+ index,
96
+ rowData,
97
+ subName,
98
+ columnProps: {
99
+ ...columnProps,
100
+ entity: rowData
101
+ },
102
+ counter,
103
+ columnEmptyText,
104
+ type,
105
+ recordKey,
106
+ mode,
107
+ prefixName: prefixName?.value,
108
+ editableUtils
109
+ });
110
+ const dom = mode === "edit" ? textDom : genCopyable(textDom, columnProps, renderTextStr, text);
111
+ /** 如果是编辑模式,并且 renderFormItem 存在直接走 renderFormItem */
112
+ if (mode === "edit") {
113
+ if (columnProps.valueType === "option") return createVNode(EditableOptionActions, {
114
+ "type": type,
115
+ "marginSM": marginSM,
116
+ "columnProps": columnProps,
117
+ "editableUtils": editableUtils,
118
+ "rowData": rowData,
119
+ "index": columnProps.index || index
120
+ }, null);
121
+ return dom;
122
+ }
123
+ if (!columnProps.render) {
124
+ const isVueRenderNode = isVNode(dom) || ["string", "number"].includes(typeof dom);
125
+ return !isNil(dom) && isVueRenderNode ? dom : null;
126
+ }
127
+ const renderDom = columnProps.render(dom, rowData, index, {
128
+ ...action?.value,
129
+ ...editableUtils
130
+ }, {
131
+ ...columnProps,
132
+ isEditable,
133
+ type: "table"
134
+ });
135
+ if (isMergeCell(renderDom)) return renderDom;
136
+ if (renderDom && columnProps.valueType === "option" && Array.isArray(renderDom)) return type === "table" ? createVNode(Space, {
137
+ "align": "center",
138
+ "size": 0,
139
+ "separator": createVNode(Divider, { "orientation": "vertical" }, null)
140
+ }, _isSlot(renderDom) ? renderDom : { default: () => [renderDom] }) : createVNode(Flex, {
141
+ "gap": 8,
142
+ "align": "center",
143
+ "justify": "flex-start"
144
+ }, _isSlot(renderDom) ? renderDom : { default: () => [renderDom] });
145
+ return renderDom;
146
+ }
147
+ //#endregion
148
+ export { columnRender as default, defaultOnFilter, isMergeCell, renderColumnsTitle };
@@ -0,0 +1,7 @@
1
+ import { ColumnsState } from "../Store/Provide.js";
2
+ import { ProColumns } from "../typing.js";
3
+
4
+ //#region src/utils/columnSort.d.ts
5
+ declare function columnSort<T, ValueType>(columnsMap?: Record<string, ColumnsState>): (a: ProColumns<T, ValueType>, b: ProColumns<T, ValueType>) => number;
6
+ //#endregion
7
+ export { columnSort };
@@ -0,0 +1,17 @@
1
+ //#region src/utils/columnSort.ts
2
+ function columnSort(columnsMap) {
3
+ return (a, b) => {
4
+ const { fixed: aFixed, index: aIndex } = a;
5
+ const { fixed: bFixed, index: bIndex } = b;
6
+ if (aFixed === "start" && bFixed !== "start" || bFixed === "end" && aFixed !== "end") return -2;
7
+ if (bFixed === "start" && aFixed !== "start" || aFixed === "end" && bFixed !== "end") return 2;
8
+ const aKey = a.key || `${aIndex}`;
9
+ const bKey = b.key || `${bIndex}`;
10
+ if (columnsMap) {
11
+ if (columnsMap[aKey]?.order || columnsMap[bKey]?.order) return (columnsMap[aKey]?.order || 0) - (columnsMap[bKey]?.order || 0);
12
+ }
13
+ return (a.index || 0) - (b.index || 0);
14
+ };
15
+ }
16
+ //#endregion
17
+ export { columnSort };