@jetlinks-web/components 3.1.14 → 3.2.0

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 (63) hide show
  1. package/es/EditTable/CellRender.js +69 -3
  2. package/es/EditTable/EditTable.js +108 -165
  3. package/es/EditTable/FormItem.js +234 -96
  4. package/es/EditTable/consts.js +13 -13
  5. package/es/EditTable/context.js +3 -2
  6. package/es/EditTable/fieldPool.js +166 -0
  7. package/es/EditTable/hooks/index.js +4 -2
  8. package/es/EditTable/hooks/useValidate.js +121 -51
  9. package/es/EditTable/hooks/useVirtualTreeTable.js +111 -0
  10. package/es/EditTable/index.js +0 -4
  11. package/es/EditTable/style/body.js +15 -2
  12. package/es/EditTable/style/form.js +2 -2
  13. package/es/EditTable/style/header.js +2 -2
  14. package/es/EditTable/style/table.js +2 -1
  15. package/es/Icon/icon.js +3 -3
  16. package/es/ProTable/Content.js +3 -4
  17. package/es/ProTable/ProTable.js +5 -0
  18. package/es/ProTable/setting.js +1 -1
  19. package/es/Search/Advanced/index.js +2 -1
  20. package/es/Search/Search.js +2 -1
  21. package/es/VirtualTable/Table.js +367 -0
  22. package/es/VirtualTable/VirtualBody.js +94 -0
  23. package/es/VirtualTable/data.js +43 -1
  24. package/es/VirtualTable/index.js +1 -1
  25. package/es/VirtualTable/style/index.js +6 -0
  26. package/es/VirtualTable/useTreeData.js +243 -0
  27. package/es/VirtualTable/useVirtualScroll.js +159 -0
  28. package/lib/EditTable/CellRender.js +69 -3
  29. package/lib/EditTable/EditTable.js +108 -165
  30. package/lib/EditTable/FormItem.js +234 -96
  31. package/lib/EditTable/consts.js +13 -13
  32. package/lib/EditTable/context.js +3 -2
  33. package/lib/EditTable/fieldPool.js +173 -0
  34. package/lib/EditTable/hooks/index.js +15 -2
  35. package/lib/EditTable/hooks/useValidate.js +120 -50
  36. package/lib/EditTable/hooks/useVirtualTreeTable.js +117 -0
  37. package/lib/EditTable/index.js +0 -4
  38. package/lib/EditTable/style/body.js +15 -2
  39. package/lib/EditTable/style/form.js +2 -2
  40. package/lib/EditTable/style/header.js +2 -2
  41. package/lib/EditTable/style/table.js +2 -1
  42. package/lib/Icon/icon.js +3 -3
  43. package/lib/ProTable/Content.js +3 -4
  44. package/lib/ProTable/ProTable.js +5 -0
  45. package/lib/ProTable/setting.js +1 -1
  46. package/lib/Search/Advanced/index.js +2 -1
  47. package/lib/Search/Search.js +2 -1
  48. package/lib/VirtualTable/Table.js +374 -0
  49. package/lib/VirtualTable/VirtualBody.js +100 -0
  50. package/lib/VirtualTable/data.js +44 -2
  51. package/lib/VirtualTable/index.js +4 -4
  52. package/lib/VirtualTable/style/index.js +6 -0
  53. package/lib/VirtualTable/useTreeData.js +250 -0
  54. package/lib/VirtualTable/useVirtualScroll.js +165 -0
  55. package/package.json +3 -3
  56. package/es/EditTable/Body.js +0 -312
  57. package/es/EditTable/Header.js +0 -164
  58. package/es/EditTable/HeaderRender.js +0 -12
  59. package/es/VirtualTable/VirtualTable.js +0 -407
  60. package/lib/EditTable/Body.js +0 -312
  61. package/lib/EditTable/Header.js +0 -164
  62. package/lib/EditTable/HeaderRender.js +0 -12
  63. package/lib/VirtualTable/VirtualTable.js +0 -407
@@ -1,407 +0,0 @@
1
- function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) {
2
- const op = ops[i];
3
- const fn = ops[i + 1];
4
- i += 2;
5
- if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) {
6
- return undefined;
7
- }
8
- if (op === 'access' || op === 'optionalAccess') {
9
- lastAccessLHS = value;
10
- value = fn(value);
11
- }
12
- else if (op === 'call' || op === 'optionalCall') {
13
- value = fn((...args) => value.call(lastAccessLHS, ...args));
14
- lastAccessLHS = undefined;
15
- }
16
- } return value; }
17
- /* Analyzed bindings: {
18
- "dataSource": "props",
19
- "columns": "props",
20
- "expandedRowKeys": "props",
21
- "rowSelection": "props",
22
- "rowKey": "props",
23
- "height": "props",
24
- "findAllChildren": "setup-maybe-ref",
25
- "flattenTree": "setup-maybe-ref",
26
- "isNumber": "setup-maybe-ref",
27
- "map": "setup-maybe-ref",
28
- "omit": "setup-maybe-ref",
29
- "h": "setup-const",
30
- "computed": "setup-const",
31
- "ref": "setup-const",
32
- "watch": "setup-const",
33
- "onMounted": "setup-const",
34
- "nextTick": "setup-const",
35
- "Table": "setup-maybe-ref",
36
- "Checkbox": "setup-maybe-ref",
37
- "AIcon": "setup-maybe-ref",
38
- "useVirtualTableStyle": "setup-maybe-ref",
39
- "useLocaleReceiver": "setup-maybe-ref",
40
- "props": "setup-reactive-const",
41
- "emits": "setup-const",
42
- "prefixCls": "setup-ref",
43
- "wrapSSR": "setup-maybe-ref",
44
- "hashId": "setup-maybe-ref",
45
- "contextLocale": "setup-maybe-ref",
46
- "container": "setup-ref",
47
- "rowHeights": "setup-ref",
48
- "prefixSum": "setup-ref",
49
- "start": "setup-ref",
50
- "end": "setup-ref",
51
- "offsetY": "setup-ref",
52
- "buffer": "literal-const",
53
- "selectedAll": "setup-ref",
54
- "visibleNodes": "setup-ref",
55
- "flattenData": "setup-ref",
56
- "firstColumn": "setup-ref",
57
- "totalHeight": "setup-ref",
58
- "visibleRows": "setup-ref",
59
- "_indeterminate": "setup-ref",
60
- "viewportHeight": "setup-ref",
61
- "_columns": "setup-ref",
62
- "_rowSelection": "setup-ref",
63
- "onSelectedAllChange": "setup-const",
64
- "onScroll": "setup-const",
65
- "toggleExpand": "setup-const",
66
- "updatePrefixSum": "setup-const",
67
- "updateVisibleNodes": "setup-const"
68
- } */
69
- import { unref as _unref, openBlock as _openBlock, createBlock as _createBlock, createCommentVNode as _createCommentVNode, toDisplayString as _toDisplayString, createElementVNode as _createElementVNode, createElementBlock as _createElementBlock, renderSlot as _renderSlot, createTextVNode as _createTextVNode, withCtx as _withCtx, createVNode as _createVNode, normalizeStyle as _normalizeStyle, Fragment as _Fragment, normalizeClass as _normalizeClass } from "vue";
70
- const _hoisted_1 = { class: "virtual-table-header" };
71
- const _hoisted_2 = {
72
- key: 0,
73
- class: "virtual-table-all-selected"
74
- };
75
- const _hoisted_3 = ["onClick"];
76
- import { findAllChildren, flattenTree } from "./data";
77
- import { isNumber, map, omit } from "lodash-es";
78
- import { h, computed, ref, watch, onMounted, nextTick } from 'vue';
79
- import { Table, Checkbox } from 'ant-design-vue';
80
- import AIcon from '../Icon';
81
- import useVirtualTableStyle from './style';
82
- import { useLocaleReceiver } from "../LocaleReciver";
83
- const buffer = 5;
84
- const __sfc_main__ = Object.assign({
85
- name: 'JVirtualTable'
86
- }, {
87
- props: {
88
- dataSource: {
89
- type: Array,
90
- default: () => []
91
- },
92
- columns: {
93
- type: Array,
94
- default: () => []
95
- },
96
- expandedRowKeys: {
97
- type: Array,
98
- default: () => []
99
- },
100
- rowSelection: {
101
- type: Object
102
- },
103
- rowKey: {
104
- type: [String, Function],
105
- default: 'id',
106
- },
107
- height: {
108
- type: Number,
109
- default: 500
110
- }
111
- },
112
- emits: ['update:expandedRowKeys'],
113
- setup(__props, { emit: __emit }) {
114
- const props = __props;
115
- const emits = __emit;
116
- const prefixCls = computed(() => 'virtual-table');
117
- const [wrapSSR, hashId] = useVirtualTableStyle(prefixCls);
118
- const [contextLocale] = useLocaleReceiver('ProTable');
119
- const container = ref(null);
120
- const rowHeights = ref([]);
121
- const prefixSum = ref([]);
122
- const start = ref(0);
123
- const end = ref(15);
124
- const offsetY = ref(0);
125
- const selectedAll = ref(false);
126
- // 被展开的所有数据
127
- const visibleNodes = ref([]);
128
- const flattenData = ref([]);
129
- const firstColumn = computed(() => props.columns[0]);
130
- const totalHeight = computed(() => prefixSum.value.length ? prefixSum.value[prefixSum.value.length - 1] : 0);
131
- const visibleRows = computed(() => visibleNodes.value.slice(start.value, end.value));
132
- const _indeterminate = computed(() => !selectedAll.value && _optionalChain([props, 'access', _2 => _2.rowSelection, 'optionalAccess', _3 => _3.selectedRowKeys, 'optionalAccess', _4 => _4.length]) > 0);
133
- const viewportHeight = computed(() => props.height || 500);
134
- const _columns = computed(() => {
135
- const arr = [];
136
- if (props.rowSelection) {
137
- const _width = props.rowSelection.columnWidth || 32;
138
- arr.push({
139
- key: '__selection__',
140
- title: contextLocale.value.select.all,
141
- dataIndex: '__selection__',
142
- width: isNumber(_width) ? `${_width}px` : _width,
143
- customHeaderCell: (props) => {
144
- return {
145
- class: 'ant-table-selection-column',
146
- };
147
- }
148
- }); //
149
- }
150
- arr.push(...props.columns);
151
- return arr;
152
- });
153
- const _rowSelection = computed(() => {
154
- return props.rowSelection ? {
155
- ...props.rowSelection,
156
- onSelect: (record, selected, selectedRows, nativeEvent) => {
157
- const _selectedRowKeys = props.rowSelection.selectedRowKeys || [];
158
- const _set = new Set([..._selectedRowKeys]);
159
- if (props.rowSelection.type === 'radio') {
160
- _set.clear();
161
- _set.add(record[props.rowKey]);
162
- }
163
- else {
164
- const _checkStrictly = props.rowSelection.checkStrictly !== undefined ? props.rowSelection.checkStrictly : true;
165
- let __arr = [];
166
- if (_checkStrictly) { // 需要获取子
167
- __arr = [record[props.rowKey]];
168
- }
169
- else {
170
- __arr = map(findAllChildren(flattenData.value, record[props.rowKey]), props.rowKey);
171
- __arr.push(record[props.rowKey]);
172
- }
173
- if (selected) {
174
- __arr.forEach(i => _set.add(i));
175
- }
176
- else {
177
- __arr.forEach(i => _set.delete(i));
178
- }
179
- }
180
- const _selectedRows = flattenData.value.filter(i => _set.has(i[props.rowKey])).map(item => omit(item, ['expanded', 'hasChildren', 'visible']));
181
- if (props.rowSelection.onSelect) {
182
- props.rowSelection.onSelect(record, selected, _selectedRows, nativeEvent);
183
- }
184
- if (props.rowSelection.onChange) {
185
- props.rowSelection.onChange([..._set], _selectedRows);
186
- }
187
- },
188
- onChange: () => {
189
- },
190
- onSelectAll: () => {
191
- },
192
- onSelectNone: () => {
193
- if (props.rowSelection.onSelectNone) {
194
- props.rowSelection.onSelectNone();
195
- }
196
- }
197
- } : undefined;
198
- });
199
- const onSelectedAllChange = (e) => {
200
- const selected = e.target.checked;
201
- const arr = flattenData.value.map(i => omit(i, ['expanded', 'hasChildren', 'visible']));
202
- const _checked = selected;
203
- const _selectedRowKeys = _checked ? map(arr, props.rowKey) : [];
204
- if (props.rowSelection.onSelectAll) {
205
- props.rowSelection.onSelectAll(_checked, _checked ? arr : []);
206
- }
207
- if (props.rowSelection.onChange) {
208
- props.rowSelection.onChange(_selectedRowKeys, _checked ? arr : []);
209
- }
210
- };
211
- const onScroll = (e) => {
212
- const scrollTop = e.target.scrollTop;
213
- const vh = viewportHeight.value || 500;
214
- const total = totalHeight.value;
215
- // 防止 scrollTop 超出范围
216
- const clampedScrollTop = Math.min(scrollTop, total - vh);
217
- // 二分查找
218
- let low = 0, high = prefixSum.value.length - 1;
219
- while (low < high) {
220
- const mid = Math.floor((low + high) / 2);
221
- if (prefixSum.value[mid] <= clampedScrollTop)
222
- low = mid + 1;
223
- else
224
- high = mid;
225
- }
226
- const newStart = Math.max(0, low - 1);
227
- // 如果 start 没变化,直接跳过,避免重复计算导致闪动
228
- if (newStart === start.value)
229
- return;
230
- start.value = newStart;
231
- // 计算 end
232
- let y = prefixSum.value[start.value] || 0;
233
- let i = start.value;
234
- while (i < visibleNodes.value.length && y < clampedScrollTop + vh) {
235
- y += rowHeights.value[i] || 40;
236
- i++;
237
- }
238
- end.value = Math.min(i + buffer, visibleNodes.value.length);
239
- // 防止 offsetY 波动
240
- offsetY.value = prefixSum.value[start.value - 1] || 0;
241
- };
242
- const toggleExpand = (row) => {
243
- row.expanded = !row.expanded;
244
- const stack = [...flattenData.value.filter(n => n.parentId === row[props.rowKey])];
245
- while (stack.length) {
246
- const child = stack.pop();
247
- child.visible = row.expanded;
248
- if (!child.visible) {
249
- child.expanded = false;
250
- }
251
- if (!row.expanded && child.hasChildren) {
252
- stack.push(...flattenData.value.filter(n => n.parentId === child[props.rowKey]));
253
- }
254
- }
255
- updateVisibleNodes();
256
- };
257
- const updatePrefixSum = () => {
258
- rowHeights.value = visibleNodes.value.map(() => 40); // 默认行高
259
- prefixSum.value = [];
260
- let sum = 0;
261
- for (let h of rowHeights.value) {
262
- sum += h;
263
- prefixSum.value.push(sum);
264
- }
265
- };
266
- const updateVisibleNodes = () => {
267
- visibleNodes.value = flattenData.value.filter(i => i.visible);
268
- updatePrefixSum();
269
- console.log('123');
270
- nextTick(() => onScroll({ target: container.value }));
271
- };
272
- watch(() => [JSON.stringify(props.dataSource), JSON.stringify(props.expandedRowKeys)], () => {
273
- flattenData.value = flattenTree(props.dataSource, 0, null);
274
- flattenData.value.forEach(i => {
275
- if (props.expandedRowKeys.includes(i[props.rowKey])) {
276
- toggleExpand(i);
277
- // i.expanded = true
278
- }
279
- });
280
- updateVisibleNodes();
281
- }, {
282
- immediate: true
283
- });
284
- // watch(() => props.expandedRowKeys, () => {
285
- // flattenData.value.forEach(i => {
286
- // if (props.expandedRowKeys.includes(i[props.rowKey])) {
287
- // toggleExpand(i)
288
- // // i.expanded = true
289
- // }
290
- // })
291
- // updateVisibleNodes()
292
- // }, {
293
- // immediate: true
294
- // })
295
- watch(() => _optionalChain([props, 'access', _5 => _5.rowSelection, 'optionalAccess', _6 => _6.selectedRowKeys]), (val) => {
296
- if (val) {
297
- selectedAll.value = val.length > 0 && flattenData.value.length === val.length;
298
- }
299
- }, {
300
- immediate: true
301
- });
302
- onMounted(() => {
303
- updateVisibleNodes();
304
- });
305
- return (_ctx, _cache) => {
306
- return (_openBlock(), _createElementBlock("div", {
307
- class: _normalizeClass(['virtual-table-wrapper', _unref(hashId)])
308
- }, [
309
- _createElementVNode("div", _hoisted_1, [
310
- _createVNode(_unref(Table), {
311
- columns: _columns.value,
312
- pagination: false,
313
- rowKey: __props.rowKey,
314
- "data-source": [],
315
- components: {
316
- body: {
317
- wrapper: () => h('div')
318
- },
319
- }
320
- }, {
321
- headerCell: _withCtx(({ column, title }) => [
322
- (column.key === '__selection__')
323
- ? (_openBlock(), _createElementBlock("span", _hoisted_2, [
324
- (__props.rowSelection.type !== 'radio' && !__props.rowSelection.hideSelectAll)
325
- ? (_openBlock(), _createBlock(_unref(Checkbox), {
326
- key: 0,
327
- checked: selectedAll.value,
328
- "onUpdate:checked": _cache[0] || (_cache[0] = $event => ((selectedAll).value = $event)),
329
- onChange: onSelectedAllChange,
330
- indeterminate: _indeterminate.value,
331
- disabled: visibleRows.value.length === 0
332
- }, null, 8 /* PROPS */, ["checked", "indeterminate", "disabled"]))
333
- : _createCommentVNode("v-if", true),
334
- _createElementVNode("span", null, _toDisplayString(_optionalChain([__props, 'access', _7 => _7.rowSelection, 'optionalAccess', _8 => _8.columnTitle])), 1 /* TEXT */)
335
- ]))
336
- : _renderSlot(_ctx.$slots, "headerCell", {
337
- key: 1,
338
- title: title,
339
- column: column
340
- }, () => [
341
- _createTextVNode(_toDisplayString(title), 1 /* TEXT */)
342
- ])
343
- ]),
344
- _: 3 /* FORWARDED */
345
- }, 8 /* PROPS */, ["columns", "rowKey", "components"])
346
- ]),
347
- _createElementVNode("div", {
348
- class: "virtual-table-body",
349
- ref_key: "container",
350
- ref: container,
351
- onScroll: onScroll,
352
- style: _normalizeStyle({ height: `${viewportHeight.value}px` })
353
- }, [
354
- _createElementVNode("div", {
355
- class: "virtual-table-height",
356
- style: _normalizeStyle({ height: totalHeight.value + 'px' })
357
- }, null, 4 /* STYLE */),
358
- _createElementVNode("div", {
359
- class: "virtual-table-visible-box",
360
- style: _normalizeStyle({ transform: `translateY(${offsetY.value}px)`, position: 'absolute', top: 0, left: 0, right: 0 })
361
- }, [
362
- _createVNode(_unref(Table), {
363
- columns: __props.columns,
364
- rowKey: __props.rowKey,
365
- "data-source": visibleRows.value,
366
- showHeader: false,
367
- pagination: false,
368
- rowSelection: _rowSelection.value
369
- }, {
370
- bodyCell: _withCtx(({ text, record, index, column }) => [
371
- ((firstColumn.value.dataIndex && column.dataIndex === firstColumn.value.dataIndex) || (firstColumn.value.key && column.key === firstColumn.value.key))
372
- ? (_openBlock(), _createElementBlock(_Fragment, { key: 0 }, [
373
- _createElementVNode("span", {
374
- class: "ant-table-row-indent indent-level-3",
375
- style: _normalizeStyle({ paddingLeft: `${record.level * 15}px` })
376
- }, null, 4 /* STYLE */),
377
- _createElementVNode("span", {
378
- class: "virtual-table-row-expand-icon",
379
- onClick: $event => (toggleExpand(record))
380
- }, [
381
- (record.hasChildren)
382
- ? (_openBlock(), _createBlock(_unref(AIcon), {
383
- key: 0,
384
- type: !record.expanded ? 'PlusSquareOutlined' : 'MinusSquareOutlined'
385
- }, null, 8 /* PROPS */, ["type"]))
386
- : _createCommentVNode("v-if", true)
387
- ], 8 /* PROPS */, _hoisted_3)
388
- ], 64 /* STABLE_FRAGMENT */))
389
- : _createCommentVNode("v-if", true),
390
- _renderSlot(_ctx.$slots, "bodyCell", {
391
- text: text,
392
- record: record,
393
- index: index,
394
- column: column
395
- }, () => [
396
- _createTextVNode(_toDisplayString(text || '--'), 1 /* TEXT */)
397
- ])
398
- ]),
399
- _: 3 /* FORWARDED */
400
- }, 8 /* PROPS */, ["columns", "rowKey", "data-source", "rowSelection"])
401
- ], 4 /* STYLE */)
402
- ], 36 /* STYLE, NEED_HYDRATION */)
403
- ], 2 /* CLASS */));
404
- };
405
- }
406
- });
407
- export default __sfc_main__;