@jetlinks-web/components 2.0.37 → 2.1.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 (74) hide show
  1. package/es/CardSelect/style/index.js +1 -0
  2. package/es/CheckButton/style/index.js +1 -0
  3. package/es/DragModal/DragModal.js +307 -0
  4. package/es/DragModal/index.js +5 -0
  5. package/es/DragModal/style/index.css +81 -0
  6. package/es/DragModal/style/index.js +1 -0
  7. package/es/DragModal/style/index.less +96 -0
  8. package/es/EditTable/Body.js +368 -0
  9. package/es/EditTable/EditTable.js +412 -0
  10. package/es/EditTable/Header.js +242 -0
  11. package/es/EditTable/components/ContextMenu/Menu.js +154 -0
  12. package/es/EditTable/components/ContextMenu/index.js +81 -0
  13. package/es/EditTable/components/Search/Search.js +290 -0
  14. package/es/EditTable/components/Search/index.js +1 -0
  15. package/es/EditTable/consts.js +7 -0
  16. package/es/EditTable/hooks/index.js +40 -0
  17. package/es/EditTable/hooks/useResizeObserver.js +31 -0
  18. package/es/EditTable/hooks/useValidate.js +87 -0
  19. package/es/EditTable/index.js +9 -0
  20. package/es/EditTable/props.js +50 -0
  21. package/es/EditTable/style/body.less +76 -0
  22. package/es/EditTable/style/header.less +77 -0
  23. package/es/EditTable/style/index.css +214 -0
  24. package/es/EditTable/style/index.js +1 -0
  25. package/es/EditTable/style/index.less +38 -0
  26. package/es/EditTable/style/table.less +42 -0
  27. package/es/EditTable/utils.js +97 -0
  28. package/es/Ellipsis/style/index.js +1 -0
  29. package/es/FullPage/FullPage.js +1 -1
  30. package/es/Search/Advanced/SaveHistory.js +1 -1
  31. package/es/Search/Item.js +1 -1
  32. package/es/Search/Search.js +1 -1
  33. package/es/components.js +3 -1
  34. package/es/style/index.css +287 -0
  35. package/es/style/index.less +9 -7
  36. package/es/style.js +3 -1
  37. package/lib/CardSelect/style/index.js +3 -0
  38. package/lib/CheckButton/style/index.js +3 -0
  39. package/lib/DragModal/DragModal.js +307 -0
  40. package/lib/DragModal/index.js +12 -0
  41. package/lib/DragModal/style/index.css +81 -0
  42. package/lib/DragModal/style/index.js +3 -0
  43. package/lib/DragModal/style/index.less +96 -0
  44. package/lib/EditTable/Body.js +368 -0
  45. package/lib/EditTable/EditTable.js +412 -0
  46. package/lib/EditTable/Header.js +242 -0
  47. package/lib/EditTable/components/ContextMenu/Menu.js +154 -0
  48. package/lib/EditTable/components/ContextMenu/index.js +88 -0
  49. package/lib/EditTable/components/Search/Search.js +290 -0
  50. package/lib/EditTable/components/Search/index.js +13 -0
  51. package/lib/EditTable/consts.js +13 -0
  52. package/lib/EditTable/hooks/index.js +79 -0
  53. package/lib/EditTable/hooks/useResizeObserver.js +38 -0
  54. package/lib/EditTable/hooks/useValidate.js +94 -0
  55. package/lib/EditTable/index.js +16 -0
  56. package/lib/EditTable/props.js +56 -0
  57. package/lib/EditTable/style/body.less +76 -0
  58. package/lib/EditTable/style/header.less +77 -0
  59. package/lib/EditTable/style/index.css +214 -0
  60. package/lib/EditTable/style/index.js +3 -0
  61. package/lib/EditTable/style/index.less +38 -0
  62. package/lib/EditTable/style/table.less +42 -0
  63. package/lib/EditTable/utils.js +104 -0
  64. package/lib/Ellipsis/style/index.js +3 -0
  65. package/lib/FullPage/FullPage.js +1 -1
  66. package/lib/Search/Advanced/SaveHistory.js +1 -1
  67. package/lib/Search/Item.js +1 -1
  68. package/lib/Search/Search.js +1 -1
  69. package/lib/components.js +14 -0
  70. package/lib/style/components.less +2 -0
  71. package/lib/style/index.css +287 -0
  72. package/lib/style/index.less +9 -7
  73. package/lib/style.js +3 -1
  74. package/package.json +3 -1
@@ -0,0 +1,368 @@
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
+ "groupKey": "props",
19
+ "ContextMenu": "setup-maybe-ref",
20
+ "useRightMenuContext": "setup-maybe-ref",
21
+ "useTableTool": "setup-maybe-ref",
22
+ "randomString": "setup-maybe-ref",
23
+ "bodyProps": "setup-maybe-ref",
24
+ "defaultProps": "setup-maybe-ref",
25
+ "ref": "setup-const",
26
+ "reactive": "setup-const",
27
+ "computed": "setup-const",
28
+ "watch": "setup-const",
29
+ "onMounted": "setup-const",
30
+ "onBeforeUnmount": "setup-const",
31
+ "handleColumnFixed": "setup-maybe-ref",
32
+ "props": "setup-reactive-const",
33
+ "emit": "setup-const",
34
+ "viewScrollRef": "setup-ref",
35
+ "virtualRang": "setup-reactive-const",
36
+ "containerStyle": "setup-ref",
37
+ "context": "setup-maybe-ref",
38
+ "tableTool": "setup-maybe-ref",
39
+ "selectedRowKeys": "setup-ref",
40
+ "hoverKeys": "setup-ref",
41
+ "scrollLock": "setup-ref",
42
+ "menuInstance": "setup-let",
43
+ "maxLen": "setup-ref",
44
+ "virtualData": "setup-ref",
45
+ "columnFixedMap": "setup-ref",
46
+ "onScroll": "setup-const",
47
+ "scrollTo": "setup-const",
48
+ "showContextMenu": "setup-const",
49
+ "rowClick": "setup-const",
50
+ "updateSelectedKeys": "setup-const",
51
+ "getViewScrollRef": "setup-const"
52
+ } */
53
+ import { normalizeStyle as _normalizeStyle, createElementVNode as _createElementVNode, unref as _unref, renderList as _renderList, Fragment as _Fragment, openBlock as _openBlock, createElementBlock as _createElementBlock, renderSlot as _renderSlot, toDisplayString as _toDisplayString, createTextVNode as _createTextVNode, withModifiers as _withModifiers, normalizeClass as _normalizeClass, createCommentVNode as _createCommentVNode, resolveComponent as _resolveComponent, createVNode as _createVNode } from "vue";
54
+ const _hoisted_1 = {
55
+ class: "jetlinks-edit-table-body-container",
56
+ style: { position: 'relative' }
57
+ };
58
+ const _hoisted_2 = ["data-row-key", "onContextmenu", "onClick", "onMouseover"];
59
+ const _hoisted_3 = { class: "body-cell-box" };
60
+ const _hoisted_4 = ["data-row-key", "onContextmenu", "onClick", "onMouseover"];
61
+ const _hoisted_5 = { class: "body-cell-box" };
62
+ const _hoisted_6 = ["data-row-key", "onContextmenu", "onClick", "onMouseover"];
63
+ const _hoisted_7 = { class: "body-cell-box" };
64
+ const _hoisted_8 = { class: "jetlinks-edit-table-body-empty" };
65
+ import ContextMenu from './components/ContextMenu';
66
+ import { useRightMenuContext, useTableTool } from "./hooks";
67
+ import { randomString } from "@jetlinks-web/utils";
68
+ import { bodyProps, defaultProps } from "./props";
69
+ import { ref, reactive, computed, watch, onMounted, onBeforeUnmount } from 'vue';
70
+ import { handleColumnFixed } from "./utils";
71
+ const __sfc_main__ = Object.assign({
72
+ name: 'JEditTableBody'
73
+ }, {
74
+ props: {
75
+ ...defaultProps(),
76
+ ...bodyProps(),
77
+ groupKey: {
78
+ type: [String, Number],
79
+ default: undefined
80
+ }
81
+ },
82
+ emits: ['update:dataSource', 'scrollDown'],
83
+ setup(__props, { expose: __expose, emit: __emit }) {
84
+ const props = __props;
85
+ const emit = __emit;
86
+ const viewScrollRef = ref();
87
+ const virtualRang = reactive({
88
+ start: 0,
89
+ end: 15
90
+ });
91
+ const containerStyle = ref(0);
92
+ const context = useRightMenuContext();
93
+ const tableTool = useTableTool();
94
+ const selectedRowKeys = ref([]);
95
+ const hoverKeys = ref();
96
+ const scrollLock = ref(false);
97
+ let menuInstance;
98
+ const maxLen = computed(() => {
99
+ return Math.trunc(props.height / props.cellHeight);
100
+ });
101
+ const virtualData = computed(() => props.dataSource.slice(virtualRang.start, virtualRang.end));
102
+ const columnFixedMap = computed(() => {
103
+ return handleColumnFixed(props.columns);
104
+ });
105
+ const onScroll = () => {
106
+ if (!viewScrollRef.value)
107
+ return;
108
+ const height = viewScrollRef.value.scrollTop;
109
+ const clientHeight = viewScrollRef.value.clientHeight;
110
+ const scrollHeight = viewScrollRef.value.scrollHeight;
111
+ const _index = Math.round(height / props.cellHeight) - 1;
112
+ const start = _index < 0 ? 0 : _index;
113
+ const end = start + maxLen.value + 4;
114
+ if (height + clientHeight >= props.dataSource.length * props.cellHeight && !scrollLock.value) { // 滚动到底
115
+ emit('scrollDown');
116
+ scrollLock.value = true;
117
+ }
118
+ virtualRang.start = start;
119
+ virtualRang.end = end;
120
+ // updateVirtualData(start, end)
121
+ };
122
+ const scrollTo = (index) => {
123
+ if (viewScrollRef.value) {
124
+ let top = index * props.cellHeight;
125
+ viewScrollRef.value.scrollTop = top;
126
+ }
127
+ };
128
+ const showContextMenu = (e, record, _index) => {
129
+ e.preventDefault();
130
+ if (!props.disableMenu) {
131
+ record = {
132
+ ...record,
133
+ __index: _index
134
+ };
135
+ menuInstance = ContextMenu(e, record, context);
136
+ }
137
+ };
138
+ const rowClick = (record) => {
139
+ if (_optionalChain([props, 'access', _ => _.rowSelection, 'optionalAccess', _2 => _2.selectedRowKeys])) {
140
+ const rowSet = new Set(selectedRowKeys.value);
141
+ const key = record[props.rowKey];
142
+ const selected = !rowSet.has(key);
143
+ if (selected) {
144
+ rowSet.delete(key);
145
+ }
146
+ else {
147
+ rowSet.add(key);
148
+ }
149
+ _optionalChain([props, 'access', _3 => _3.rowSelection, 'access', _4 => _4.onSelect, 'optionalCall', _5 => _5(record, selected)]);
150
+ selectedRowKeys.value = [...rowSet.values()];
151
+ }
152
+ };
153
+ const updateSelectedKeys = (keys) => {
154
+ selectedRowKeys.value = keys;
155
+ };
156
+ const getViewScrollRef = () => viewScrollRef.value;
157
+ watch(() => JSON.stringify(_optionalChain([props, 'access', _6 => _6.rowSelection, 'optionalAccess', _7 => _7.selectedRowKeys])), (val) => {
158
+ selectedRowKeys.value = JSON.parse(val || '[]');
159
+ }, { immediate: true });
160
+ watch(() => props.dataSource, (val, oldVal) => {
161
+ props.dataSource.forEach((item, index) => {
162
+ if (!item.__key) {
163
+ item.__key = randomString();
164
+ }
165
+ });
166
+ }, {
167
+ immediate: true,
168
+ deep: true
169
+ });
170
+ watch(() => props.dataSource.length, () => {
171
+ scrollLock.value = false;
172
+ containerStyle.value = {
173
+ height: props.dataSource.length * props.cellHeight + 'px'
174
+ };
175
+ if (props.dataSource.length <= maxLen.value || props.dataSource.length === 0) {
176
+ emit('scrollDown', maxLen.value - props.dataSource.length + 3);
177
+ }
178
+ }, { immediate: true });
179
+ // watch(() => props.height, () => {
180
+ // updateView()
181
+ // })
182
+ onMounted(() => {
183
+ nextTick(() => {
184
+ onScroll();
185
+ });
186
+ });
187
+ onBeforeUnmount(() => {
188
+ _optionalChain([menuInstance, 'optionalAccess', _8 => _8.destroy, 'call', _9 => _9()]);
189
+ _optionalChain([menuInstance, 'optionalAccess', _10 => _10.cleanCopy, 'call', _11 => _11()]);
190
+ });
191
+ __expose({
192
+ scrollTo,
193
+ updateSelectedKeys,
194
+ getViewScrollRef
195
+ });
196
+ return (_ctx, _cache) => {
197
+ const _component_j_empty = _resolveComponent("j-empty");
198
+ return (_ctx.dataSource.length)
199
+ ? (_openBlock(), _createElementBlock("div", {
200
+ key: 0,
201
+ class: "jetlinks-edit-table-body-viewport",
202
+ style: _normalizeStyle({ ..._ctx.style, height: _ctx.height + 'px' }),
203
+ ref_key: "viewScrollRef",
204
+ ref: viewScrollRef,
205
+ onScroll: onScroll
206
+ }, [
207
+ _createElementVNode("div", _hoisted_1, [
208
+ _createElementVNode("div", {
209
+ class: "jetlinks-edit-scrollbar",
210
+ style: _normalizeStyle(containerStyle.value)
211
+ }, null, 4 /* STYLE */),
212
+ (columnFixedMap.value.left.keys.length)
213
+ ? (_openBlock(), _createElementBlock("div", {
214
+ key: 0,
215
+ class: "jetlinks-edit-table-left",
216
+ style: _normalizeStyle({
217
+ webkitTransform: `translate3d(0, ${virtualRang.start * props.cellHeight}px, 0)`,
218
+ maxWidth: columnFixedMap.value.left.width + 'px',
219
+ minWidth: columnFixedMap.value.left.width + 'px',
220
+ width: columnFixedMap.value.left.width + 'px',
221
+ boxShadow: _unref(tableTool).scrollMap.x ? '0 0 12px 0 rgba(0 ,0, 0, .2)' : ''
222
+ })
223
+ }, [
224
+ (_openBlock(true), _createElementBlock(_Fragment, null, _renderList(virtualData.value, (item, index) => {
225
+ return (_openBlock(), _createElementBlock("div", {
226
+ class: _normalizeClass({
227
+ 'jetlinks-edit-table-row': true,
228
+ 'jetlinks-edit-table-row-selected': _optionalChain([selectedRowKeys, 'access', _12 => _12.value, 'optionalAccess', _13 => _13.includes, 'call', _14 => _14(item[_ctx.rowKey] || virtualRang.start + index + 1)]),
229
+ 'jetlinks-edit-table-row-hover': hoverKeys.value === (item[_ctx.rowKey] || virtualRang.start + index + 1)
230
+ }),
231
+ key: 'left' + index,
232
+ style: _normalizeStyle({ height: `${_ctx.cellHeight}px` }),
233
+ "data-row-key": item[_ctx.rowKey] || virtualRang.start + index + 1,
234
+ onContextmenu: _withModifiers((e) => showContextMenu(e, item, virtualRang.start + index), ["right"]),
235
+ onClick: _withModifiers(() => rowClick(item), ["stop"]),
236
+ onMouseover: $event => (hoverKeys.value = (item[_ctx.rowKey] || virtualRang.start + index + 1)),
237
+ onMouseleave: _cache[0] || (_cache[0] = $event => (hoverKeys.value = undefined))
238
+ }, [
239
+ (_openBlock(true), _createElementBlock(_Fragment, null, _renderList(columnFixedMap.value.left.keys, (column) => {
240
+ return (_openBlock(), _createElementBlock("div", {
241
+ class: "jetlinks-edit-table-cell",
242
+ style: _normalizeStyle({
243
+ width: `${column._width}px`,
244
+ })
245
+ }, [
246
+ _createElementVNode("div", _hoisted_3, [
247
+ _renderSlot(_ctx.$slots, column.dataIndex, {
248
+ record: item,
249
+ index: item.__dataIndex,
250
+ column: column
251
+ }, () => [
252
+ _createTextVNode(_toDisplayString(column.dataIndex === '__serial' ? virtualRang.start + index + 1 : item[column.dataIndex]), 1 /* TEXT */)
253
+ ])
254
+ ])
255
+ ], 4 /* STYLE */));
256
+ }), 256 /* UNKEYED_FRAGMENT */))
257
+ ], 46 /* CLASS, STYLE, PROPS, NEED_HYDRATION */, _hoisted_2));
258
+ }), 128 /* KEYED_FRAGMENT */))
259
+ ], 4 /* STYLE */))
260
+ : _createCommentVNode("v-if", true),
261
+ _createElementVNode("div", {
262
+ class: "jetlinks-edit-table-center",
263
+ style: _normalizeStyle({
264
+ webkitTransform: `translate3d(-${_unref(tableTool).scrollMap.x}px, ${virtualRang.start * props.cellHeight}px, 0)`
265
+ })
266
+ }, [
267
+ _createElementVNode("div", {
268
+ style: _normalizeStyle({ width: columnFixedMap.value.center.width + 'px' })
269
+ }, [
270
+ (virtualData.value.length)
271
+ ? (_openBlock(true), _createElementBlock(_Fragment, { key: 0 }, _renderList(virtualData.value, (item, index) => {
272
+ return (_openBlock(), _createElementBlock("div", {
273
+ class: _normalizeClass({
274
+ 'jetlinks-edit-table-row': true,
275
+ 'jetlinks-edit-table-row-selected': _optionalChain([selectedRowKeys, 'access', _15 => _15.value, 'optionalAccess', _16 => _16.includes, 'call', _17 => _17(item[_ctx.rowKey] || virtualRang.start + index + 1)]),
276
+ 'jetlinks-edit-table-row-hover': hoverKeys.value === (item[_ctx.rowKey] || virtualRang.start + index + 1)
277
+ }),
278
+ key: 'center' + index,
279
+ style: _normalizeStyle({ height: `${_ctx.cellHeight}px`, }),
280
+ "data-row-key": item[_ctx.rowKey] || virtualRang.start + index + 1,
281
+ onContextmenu: _withModifiers((e) => showContextMenu(e, item, virtualRang.start + index), ["right"]),
282
+ onClick: _withModifiers(() => rowClick(item), ["stop"]),
283
+ onMouseover: $event => (hoverKeys.value = (item[_ctx.rowKey] || virtualRang.start + index + 1)),
284
+ onMouseleave: _cache[1] || (_cache[1] = $event => (hoverKeys.value = undefined))
285
+ }, [
286
+ (_openBlock(true), _createElementBlock(_Fragment, null, _renderList(columnFixedMap.value.center.keys, (column) => {
287
+ return (_openBlock(), _createElementBlock("div", {
288
+ class: "jetlinks-edit-table-cell",
289
+ style: _normalizeStyle({
290
+ width: `${column._width}px`,
291
+ })
292
+ }, [
293
+ _createElementVNode("div", _hoisted_5, [
294
+ _renderSlot(_ctx.$slots, column.dataIndex, {
295
+ record: item,
296
+ index: item.__dataIndex,
297
+ column: column
298
+ }, () => [
299
+ _createTextVNode(_toDisplayString(column.dataIndex === '__serial' ? virtualRang.start + index + 1 : item[column.dataIndex]), 1 /* TEXT */)
300
+ ])
301
+ ])
302
+ ], 4 /* STYLE */));
303
+ }), 256 /* UNKEYED_FRAGMENT */))
304
+ ], 46 /* CLASS, STYLE, PROPS, NEED_HYDRATION */, _hoisted_4));
305
+ }), 128 /* KEYED_FRAGMENT */))
306
+ : _createCommentVNode("v-if", true)
307
+ ], 4 /* STYLE */)
308
+ ], 4 /* STYLE */),
309
+ (columnFixedMap.value.right.keys.length)
310
+ ? (_openBlock(), _createElementBlock("div", {
311
+ key: 1,
312
+ class: "jetlinks-edit-table-right",
313
+ style: _normalizeStyle({
314
+ webkitTransform: `translate3d(0, ${virtualRang.start * props.cellHeight}px, 0)`,
315
+ maxWidth: columnFixedMap.value.right.width + 'px',
316
+ minWidth: columnFixedMap.value.right.width + 'px',
317
+ width: columnFixedMap.value.right.width + 'px',
318
+ boxShadow: _unref(tableTool).scrollMap.down !== 'right' ? '0 0 12px 0 rgba(0 ,0, 0, .2)' : ''
319
+ })
320
+ }, [
321
+ (_openBlock(true), _createElementBlock(_Fragment, null, _renderList(virtualData.value, (item, index) => {
322
+ return (_openBlock(), _createElementBlock("div", {
323
+ class: _normalizeClass({
324
+ 'jetlinks-edit-table-row': true,
325
+ 'jetlinks-edit-table-row-selected': _optionalChain([selectedRowKeys, 'access', _18 => _18.value, 'optionalAccess', _19 => _19.includes, 'call', _20 => _20(item[_ctx.rowKey] || virtualRang.start + index + 1)]),
326
+ 'jetlinks-edit-table-row-hover': hoverKeys.value === (item[_ctx.rowKey] || virtualRang.start + index + 1)
327
+ }),
328
+ key: 'right' + index,
329
+ style: _normalizeStyle({ height: `${_ctx.cellHeight}px` }),
330
+ "data-row-key": item[_ctx.rowKey] || virtualRang.start + index + 1,
331
+ onContextmenu: _withModifiers((e) => showContextMenu(e, item, virtualRang.start + index), ["right"]),
332
+ onClick: _withModifiers(() => rowClick(item), ["stop"]),
333
+ onMouseover: $event => (hoverKeys.value = (item[_ctx.rowKey] || virtualRang.start + index + 1)),
334
+ onMouseleave: _cache[2] || (_cache[2] = $event => (hoverKeys.value = undefined))
335
+ }, [
336
+ (_openBlock(true), _createElementBlock(_Fragment, null, _renderList(columnFixedMap.value.right.keys, (column) => {
337
+ return (_openBlock(), _createElementBlock("div", {
338
+ class: "jetlinks-edit-table-cell",
339
+ style: _normalizeStyle({
340
+ width: `${column._width}px`,
341
+ })
342
+ }, [
343
+ _createElementVNode("div", _hoisted_7, [
344
+ _renderSlot(_ctx.$slots, column.dataIndex, {
345
+ record: item,
346
+ index: item.__dataIndex,
347
+ column: column
348
+ }, () => [
349
+ _createTextVNode(_toDisplayString(column.dataIndex === '__serial' ? virtualRang.start + index + 1 : item[column.dataIndex]), 1 /* TEXT */)
350
+ ])
351
+ ])
352
+ ], 4 /* STYLE */));
353
+ }), 256 /* UNKEYED_FRAGMENT */))
354
+ ], 46 /* CLASS, STYLE, PROPS, NEED_HYDRATION */, _hoisted_6));
355
+ }), 128 /* KEYED_FRAGMENT */))
356
+ ], 4 /* STYLE */))
357
+ : _createCommentVNode("v-if", true)
358
+ ])
359
+ ], 36 /* STYLE, NEED_HYDRATION */))
360
+ : _renderSlot(_ctx.$slots, "empty", { key: 1 }, () => [
361
+ _createElementVNode("div", _hoisted_8, [
362
+ _createVNode(_component_j_empty)
363
+ ])
364
+ ]);
365
+ };
366
+ }
367
+ });
368
+ export default __sfc_main__;