@jetlinks-web/components 3.1.15 → 3.2.1

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