stk-table-vue 1.0.0-beta.3 → 1.0.0-beta.5

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/README.md +173 -173
  2. package/lib/{Dropdown-CX_2Kv4I.js → Dropdown-Clc70S1z.js} +158 -158
  3. package/lib/{StkTable-BugG7a1E.js → StkTable-QUd4TJCF.js} +4810 -4758
  4. package/lib/src/StkTable/StkTable.vue.d.ts +1 -1
  5. package/lib/src/StkTable/custom-cells/CheckboxCell/Checkbox.vue.d.ts +29 -0
  6. package/lib/src/StkTable/custom-cells/CheckboxCell/createCheckboxCell.d.ts +82 -0
  7. package/lib/src/StkTable/custom-cells/CheckboxCell/index.d.ts +2 -0
  8. package/lib/src/StkTable/custom-cells/{Filter → FilterCell}/Dropdown/index.vue.d.ts +1 -1
  9. package/lib/src/StkTable/custom-cells/{Filter → FilterCell}/Filter.vue.d.ts +35 -35
  10. package/lib/src/StkTable/custom-cells/{Filter/createFilter.d.ts → FilterCell/createFilterCell.d.ts} +4 -4
  11. package/lib/src/StkTable/custom-cells/FilterCell/index.d.ts +2 -0
  12. package/lib/src/StkTable/custom-cells/{Filter → FilterCell}/types.d.ts +1 -1
  13. package/lib/src/StkTable/features/useAreaSelection.bak.d.ts +25 -0
  14. package/lib/src/StkTable/features/useAreaSelection.d.ts +1 -3
  15. package/lib/src/StkTable/index.d.ts +4 -2
  16. package/lib/src/StkTable/types/index.d.ts +4 -4
  17. package/lib/stk-table-vue.js +465 -314
  18. package/lib/style.css +701 -688
  19. package/package.json +85 -85
  20. package/src/StkTable/StkTable.vue +1849 -1859
  21. package/src/StkTable/components/DragHandle.vue +9 -9
  22. package/src/StkTable/components/SortIcon.vue +6 -6
  23. package/src/StkTable/components/TreeNodeCell.vue +19 -19
  24. package/src/StkTable/components/TriangleIcon.vue +3 -3
  25. package/src/StkTable/const.ts +50 -50
  26. package/src/StkTable/custom-cells/CheckboxCell/Checkbox.less +14 -0
  27. package/src/StkTable/custom-cells/CheckboxCell/Checkbox.vue +41 -0
  28. package/src/StkTable/custom-cells/CheckboxCell/createCheckboxCell.ts +146 -0
  29. package/src/StkTable/custom-cells/CheckboxCell/index.ts +5 -0
  30. package/src/StkTable/custom-cells/{Filter → FilterCell}/Dropdown/index.ts +16 -16
  31. package/src/StkTable/custom-cells/{Filter → FilterCell}/Dropdown/index.vue +184 -184
  32. package/src/StkTable/custom-cells/{Filter → FilterCell}/Filter.less +118 -118
  33. package/src/StkTable/custom-cells/{Filter → FilterCell}/Filter.vue +66 -66
  34. package/src/StkTable/custom-cells/{Filter/createFilter.ts → FilterCell/createFilterCell.ts} +120 -120
  35. package/src/StkTable/custom-cells/FilterCell/index.ts +6 -0
  36. package/src/StkTable/custom-cells/{Filter → FilterCell}/types.ts +43 -43
  37. package/src/StkTable/features/const.ts +1 -1
  38. package/src/StkTable/features/index.ts +1 -1
  39. package/src/StkTable/features/useAreaSelection.bak.ts +951 -0
  40. package/src/StkTable/features/useAreaSelection.ts +1079 -951
  41. package/src/StkTable/index.ts +14 -12
  42. package/src/StkTable/registerFeature.ts +40 -40
  43. package/src/StkTable/style.less +767 -767
  44. package/src/StkTable/types/highlightDimOptions.ts +28 -28
  45. package/src/StkTable/types/index.ts +452 -452
  46. package/src/StkTable/useAutoResize.ts +87 -87
  47. package/src/StkTable/useColResize.ts +202 -202
  48. package/src/StkTable/useFixedCol.ts +142 -142
  49. package/src/StkTable/useFixedStyle.ts +75 -75
  50. package/src/StkTable/useGetFixedColPosition.ts +63 -63
  51. package/src/StkTable/useHighlight.ts +270 -270
  52. package/src/StkTable/useIndexResolver.ts +29 -29
  53. package/src/StkTable/useKeyboardArrowScroll.ts +114 -114
  54. package/src/StkTable/useMaxRowSpan.ts +50 -50
  55. package/src/StkTable/useMergeCells.ts +138 -138
  56. package/src/StkTable/useRowExpand.ts +81 -81
  57. package/src/StkTable/useScrollRowByRow.ts +96 -96
  58. package/src/StkTable/useScrollbar.ts +177 -177
  59. package/src/StkTable/useSorter.ts +259 -259
  60. package/src/StkTable/useTableColumns.ts +131 -131
  61. package/src/StkTable/useThDrag.ts +94 -94
  62. package/src/StkTable/useTrDrag.ts +100 -100
  63. package/src/StkTable/useTree.ts +152 -152
  64. package/src/StkTable/useVirtualScroll.ts +693 -684
  65. package/src/StkTable/useWheeling.ts +23 -23
  66. package/src/StkTable/utils/constRefUtils.ts +29 -29
  67. package/src/StkTable/utils/index.ts +331 -331
  68. package/src/StkTable/utils/useTriggerRef.ts +33 -33
  69. package/src/VirtualTree.vue +622 -622
  70. package/src/VirtualTreeSelect.vue +367 -367
  71. package/src/vite-env.d.ts +10 -10
  72. package/lib/src/StkTable/custom-cells/Filter/index.d.ts +0 -2
  73. package/src/StkTable/custom-cells/Filter/index.ts +0 -6
  74. /package/lib/src/StkTable/custom-cells/{Filter → FilterCell}/Dropdown/index.d.ts +0 -0
package/README.md CHANGED
@@ -1,173 +1,173 @@
1
- <p align="center">
2
- <a href="https://ja-plus.github.io/stk-table-vue/">
3
- <img src="./docs-src/public/assets/logo.svg" width="152">
4
- </a>
5
- <h3 align='center'>Stk Table Vue</h3>
6
- <p align="center">
7
- <a href="https://www.npmjs.com/package/stk-table-vue"><img src="https://img.shields.io/npm/v/stk-table-vue"></a>
8
- <a href="https://www.npmjs.com/package/stk-table-vue"><img src="https://img.shields.io/npm/dw/stk-table-vue"></a>
9
- <a href="https://github.com/ja-plus/stk-table-vue/stargazers"><img src="https://img.shields.io/github/stars/ja-plus/stk-table-vue.svg"></a>
10
- <a href="https://raw.githubusercontent.com/ja-plus/stk-table-vue/master/LICENSE"><img src="https://img.shields.io/npm/l/stk-table-vue"></a>
11
- <a href="https://github.com/ja-plus/stk-table-vue"><img src="https://img.shields.io/npm/types/stk-table-vue"></a>
12
- </p>
13
- </p>
14
-
15
- Stk Table Vue(Sticky Table) is a high-performance virtual list component based on Vue.
16
-
17
- Smooth performance with tens of thousands of rows
18
-
19
- Used for real-time data display, with data highlighting and dynamic effects.
20
-
21
- Support Vue3 and Vue2.7
22
-
23
-
24
- ## Documentation
25
- ### [Stk Table Vue Official](https://ja-plus.github.io/stk-table-vue/)
26
-
27
-
28
- ## Repo:
29
- - [Github](https://github.com/ja-plus/stk-table-vue)
30
- - [Gitee](https://gitee.com/japlus/stk-table-vue)
31
-
32
- ## Demo
33
- [<span style="font-size: 16px;font-weight: bold;">Online Demo in stackblitz</span>](https://stackblitz.com/edit/vitejs-vite-ad91hh?file=src%2FDemo%2Findex.vue)
34
-
35
- ## Usage
36
- > npm install stk-table-vue
37
-
38
- ```html
39
- <script setup>
40
- import { StkTable } from 'stk-table-vue'
41
- import { ref, useTemplateRef } from 'vue'
42
- const stkTableRef = ref<InstanceType<typeof StkTable>>();
43
- // or Vue 3.5 useTemplateRef
44
- const stkTableRef = useTemplateRef('stkTableRef');
45
-
46
- // highlight row
47
- stkTableRef.value.setHighlightDimRow([rowKey], {
48
- method: 'css' | 'animation', // default animation
49
- className: 'custom-class-name', // for method 'css'
50
- keyframe: [{ backgroundColor: '#aaa' }, { backgroundColor: '#222' }], // same as https://developer.mozilla.org/zh-CN/docs/Web/API/Web_Animations_API/Keyframe_Formats
51
- duration: 2000,
52
- });
53
- // highlight cell
54
- stkTableRef.value.setHighlightDimCell(rowKey, colDataIndex, {
55
- method: 'css' | 'animation',
56
- className: 'custom-class-name', // for method 'css'
57
- keyframe: [{ backgroundColor: '#aaa' }, { backgroundColor: '#222' }], // for method 'animation'
58
- duration: 2000,
59
- });
60
-
61
- const columns = [
62
- {title: 'name', dataIndex: 'name'},
63
- {title: 'age', dataIndex: 'age'},
64
- {title: 'address', dataIndex: 'address'},
65
- ];
66
-
67
- const dataSource = [
68
- {id: 1, name: 'John', age: 32, address: 'New York'},
69
- {id: 2, name: 'Jim', age: 42, address: 'London'},
70
- {id: 3, name: 'Joe', age: 52, address: 'Tokyo'},
71
- {id: 4, name: 'Jack', age: 62, address: 'Sydney'},
72
- {id: 5, name: 'Jill', age: 72, address: 'Paris'},
73
- ]
74
-
75
- </script>
76
-
77
- <template>
78
- <StkTable ref='stkTableRef' row-key="id" :data-source="dataSource" :columns="columns"></StkTable>
79
- </template>
80
-
81
- ```
82
-
83
- ### Vue2.7 Usage
84
- [Vue2.7 Usage](https://ja-plus.github.io/stk-table-vue/main/start/vue2-usage.html)
85
-
86
- ## API
87
- * [Props](https://ja-plus.github.io/stk-table-vue/main/api/table-props.html)
88
-
89
- * [Emits](https://ja-plus.github.io/stk-table-vue/main/api/emits.html)
90
-
91
- * [Slots](https://ja-plus.github.io/stk-table-vue/main/api/slots.html)
92
-
93
- * [Expose](https://ja-plus.github.io/stk-table-vue/main/api/expose.html)
94
-
95
- * [StkTableColumn: Define column type](https://ja-plus.github.io/stk-table-vue/main/api/stk-table-column.html)
96
-
97
- * [Highlight: setHighlightDimCell & setHighlightDimRow](https://ja-plus.github.io/stk-table-vue/main/api/expose.html#sethighlightdimcell)
98
-
99
-
100
- ### Example
101
- ```vue
102
- <template>
103
- <StkTable
104
- ref="stkTable"
105
- row-key="name"
106
- v-model:columns="columns"
107
- :style="{height:props.height}"
108
- theme='dark'
109
- height='200px'
110
- bordered="h"
111
- :row-height="28"
112
- :show-overflow="false"
113
- :show-header-overflow="false"
114
- :sort-remote="false"
115
- col-resizable
116
- header-drag
117
- virtual
118
- virtual-x
119
- no-data-full
120
- col-resizable
121
- auto-resize
122
- fixed-col-shadow
123
- :col-min-width="10"
124
- :headless="false"
125
- :data-source="dataSource"
126
- @current-change="onCurrentChange"
127
- @row-menu="onRowMenu"
128
- @header-row-menu="onHeaderRowMenu"
129
- @row-click="onRowClick"
130
- @row-dblclick="onRowDblclick"
131
- @sort-change="handleSortChange"
132
- @cell-click="onCellClick"
133
- @header-cell-click="onHeaderCellClick"
134
- @scroll="onTableScroll"
135
- @scroll-x="onTableScrollX"
136
- @col-order-change="onColOrderChange"
137
- />
138
- </template>
139
- <script setup>
140
- import { h, defineComponent } from 'vue';
141
- const columns = [
142
- {
143
- title: 'Name',
144
- dataIndex: 'name',
145
- fixed: 'left',
146
- width: '200px',
147
- headerClassName: 'my-th',
148
- className: 'my-td',
149
- sorter: true,
150
- customHeaderCell: function FunctionalComponent(props){
151
- return h(
152
- 'span',
153
- { style: 'overflow:hidden;text-overflow:ellipsis;white-space:nowrap' },
154
- props.col.title + '(render) text-overflow,',
155
- );
156
- },
157
- customCell: defineComponent({
158
- setup(){
159
- //...
160
- return () => <div></div> // vue jsx
161
- }
162
- })
163
- },
164
- ]
165
- </script>
166
- ```
167
-
168
- ## Compare
169
- Compare performance with other vue table [vue-table-compare](https://github.com/ja-plus/vue-table-compare)
170
-
171
-
172
- ## Other
173
- * `$*$`
1
+ <p align="center">
2
+ <a href="https://ja-plus.github.io/stk-table-vue/">
3
+ <img src="./docs-src/public/assets/logo.svg" width="152">
4
+ </a>
5
+ <h3 align='center'>Stk Table Vue</h3>
6
+ <p align="center">
7
+ <a href="https://www.npmjs.com/package/stk-table-vue"><img src="https://img.shields.io/npm/v/stk-table-vue"></a>
8
+ <a href="https://www.npmjs.com/package/stk-table-vue"><img src="https://img.shields.io/npm/dw/stk-table-vue"></a>
9
+ <a href="https://github.com/ja-plus/stk-table-vue/stargazers"><img src="https://img.shields.io/github/stars/ja-plus/stk-table-vue.svg"></a>
10
+ <a href="https://raw.githubusercontent.com/ja-plus/stk-table-vue/master/LICENSE"><img src="https://img.shields.io/npm/l/stk-table-vue"></a>
11
+ <a href="https://github.com/ja-plus/stk-table-vue"><img src="https://img.shields.io/npm/types/stk-table-vue"></a>
12
+ </p>
13
+ </p>
14
+
15
+ Stk Table Vue(Sticky Table) is a high-performance virtual list component based on Vue.
16
+
17
+ Smooth performance with tens of thousands of rows
18
+
19
+ Used for real-time data display, with data highlighting and dynamic effects.
20
+
21
+ Support Vue3 and Vue2.7
22
+
23
+
24
+ ## Documentation
25
+ ### [Stk Table Vue Official](https://ja-plus.github.io/stk-table-vue/)
26
+
27
+
28
+ ## Repo:
29
+ - [Github](https://github.com/ja-plus/stk-table-vue)
30
+ - [Gitee](https://gitee.com/japlus/stk-table-vue)
31
+
32
+ ## Demo
33
+ [<span style="font-size: 16px;font-weight: bold;">Online Demo in stackblitz</span>](https://stackblitz.com/edit/vitejs-vite-ad91hh?file=src%2FDemo%2Findex.vue)
34
+
35
+ ## Usage
36
+ > npm install stk-table-vue
37
+
38
+ ```html
39
+ <script setup>
40
+ import { StkTable } from 'stk-table-vue'
41
+ import { ref, useTemplateRef } from 'vue'
42
+ const stkTableRef = ref<InstanceType<typeof StkTable>>();
43
+ // or Vue 3.5 useTemplateRef
44
+ const stkTableRef = useTemplateRef('stkTableRef');
45
+
46
+ // highlight row
47
+ stkTableRef.value.setHighlightDimRow([rowKey], {
48
+ method: 'css' | 'animation', // default animation
49
+ className: 'custom-class-name', // for method 'css'
50
+ keyframe: [{ backgroundColor: '#aaa' }, { backgroundColor: '#222' }], // same as https://developer.mozilla.org/zh-CN/docs/Web/API/Web_Animations_API/Keyframe_Formats
51
+ duration: 2000,
52
+ });
53
+ // highlight cell
54
+ stkTableRef.value.setHighlightDimCell(rowKey, colDataIndex, {
55
+ method: 'css' | 'animation',
56
+ className: 'custom-class-name', // for method 'css'
57
+ keyframe: [{ backgroundColor: '#aaa' }, { backgroundColor: '#222' }], // for method 'animation'
58
+ duration: 2000,
59
+ });
60
+
61
+ const columns = [
62
+ {title: 'name', dataIndex: 'name'},
63
+ {title: 'age', dataIndex: 'age'},
64
+ {title: 'address', dataIndex: 'address'},
65
+ ];
66
+
67
+ const dataSource = [
68
+ {id: 1, name: 'John', age: 32, address: 'New York'},
69
+ {id: 2, name: 'Jim', age: 42, address: 'London'},
70
+ {id: 3, name: 'Joe', age: 52, address: 'Tokyo'},
71
+ {id: 4, name: 'Jack', age: 62, address: 'Sydney'},
72
+ {id: 5, name: 'Jill', age: 72, address: 'Paris'},
73
+ ]
74
+
75
+ </script>
76
+
77
+ <template>
78
+ <StkTable ref='stkTableRef' row-key="id" :data-source="dataSource" :columns="columns"></StkTable>
79
+ </template>
80
+
81
+ ```
82
+
83
+ ### Vue2.7 Usage
84
+ [Vue2.7 Usage](https://ja-plus.github.io/stk-table-vue/main/start/vue2-usage.html)
85
+
86
+ ## API
87
+ * [Props](https://ja-plus.github.io/stk-table-vue/main/api/table-props.html)
88
+
89
+ * [Emits](https://ja-plus.github.io/stk-table-vue/main/api/emits.html)
90
+
91
+ * [Slots](https://ja-plus.github.io/stk-table-vue/main/api/slots.html)
92
+
93
+ * [Expose](https://ja-plus.github.io/stk-table-vue/main/api/expose.html)
94
+
95
+ * [StkTableColumn: Define column type](https://ja-plus.github.io/stk-table-vue/main/api/stk-table-column.html)
96
+
97
+ * [Highlight: setHighlightDimCell & setHighlightDimRow](https://ja-plus.github.io/stk-table-vue/main/api/expose.html#sethighlightdimcell)
98
+
99
+
100
+ ### Example
101
+ ```vue
102
+ <template>
103
+ <StkTable
104
+ ref="stkTable"
105
+ row-key="name"
106
+ v-model:columns="columns"
107
+ :style="{height:props.height}"
108
+ theme='dark'
109
+ height='200px'
110
+ bordered="h"
111
+ :row-height="28"
112
+ :show-overflow="false"
113
+ :show-header-overflow="false"
114
+ :sort-remote="false"
115
+ col-resizable
116
+ header-drag
117
+ virtual
118
+ virtual-x
119
+ no-data-full
120
+ col-resizable
121
+ auto-resize
122
+ fixed-col-shadow
123
+ :col-min-width="10"
124
+ :headless="false"
125
+ :data-source="dataSource"
126
+ @current-change="onCurrentChange"
127
+ @row-menu="onRowMenu"
128
+ @header-row-menu="onHeaderRowMenu"
129
+ @row-click="onRowClick"
130
+ @row-dblclick="onRowDblclick"
131
+ @sort-change="handleSortChange"
132
+ @cell-click="onCellClick"
133
+ @header-cell-click="onHeaderCellClick"
134
+ @scroll="onTableScroll"
135
+ @scroll-x="onTableScrollX"
136
+ @col-order-change="onColOrderChange"
137
+ />
138
+ </template>
139
+ <script setup>
140
+ import { h, defineComponent } from 'vue';
141
+ const columns = [
142
+ {
143
+ title: 'Name',
144
+ dataIndex: 'name',
145
+ fixed: 'left',
146
+ width: '200px',
147
+ headerClassName: 'my-th',
148
+ className: 'my-td',
149
+ sorter: true,
150
+ customHeaderCell: function FunctionalComponent(props){
151
+ return h(
152
+ 'span',
153
+ { style: 'overflow:hidden;text-overflow:ellipsis;white-space:nowrap' },
154
+ props.col.title + '(render) text-overflow,',
155
+ );
156
+ },
157
+ customCell: defineComponent({
158
+ setup(){
159
+ //...
160
+ return () => <div></div> // vue jsx
161
+ }
162
+ })
163
+ },
164
+ ]
165
+ </script>
166
+ ```
167
+
168
+ ## Compare
169
+ Compare performance with other vue table [vue-table-compare](https://github.com/ja-plus/vue-table-compare)
170
+
171
+
172
+ ## Other
173
+ * `$*$`
@@ -1,158 +1,158 @@
1
- /**
2
- * name: stk-table-vue
3
- * version: v1.0.0-beta.3
4
- * description: High performance realtime virtual table for vue3 and vue2.7
5
- * author: japlus
6
- * homepage: https://ja-plus.github.io/stk-table-vue/
7
- * license: MIT
8
- */
9
- import { t as StkTable_default } from "./StkTable-BugG7a1E.js";
10
- import { createElementBlock, createElementVNode, createVNode, defineComponent, h, nextTick, normalizeClass, normalizeStyle, onMounted, onUnmounted, openBlock, reactive, ref, withModifiers } from "vue";
11
- //#region src/StkTable/custom-cells/Filter/Dropdown/index.vue?vue&type=script&setup=true&lang.ts
12
- var DROPDOWN_DEFAULT_WIDTH = 300;
13
- var DROPDOWN_DEFAULT_HEIGHT = 400;
14
- var PADDING = 6;
15
- //#endregion
16
- //#region src/StkTable/custom-cells/Filter/Dropdown/index.vue
17
- var Dropdown_default = /* @__PURE__ */ defineComponent({
18
- __name: "index",
19
- setup(__props, { expose: __expose }) {
20
- const theme = ref("light");
21
- const checkedTempValueSet = reactive(/* @__PURE__ */ new Set());
22
- const columns = ref([{
23
- title: "",
24
- dataIndex: "value",
25
- width: 30,
26
- className: "stk-filter-dropdown-checkbox",
27
- customCell: ({ row }) => h("input", {
28
- type: "checkbox",
29
- checked: checkedTempValueSet.has(row.value)
30
- })
31
- }, {
32
- title: "",
33
- dataIndex: "label"
34
- }]);
35
- const visible = ref(false);
36
- const position = ref({
37
- x: 0,
38
- y: 0
39
- });
40
- const options = ref([]);
41
- const dropdownEl = ref();
42
- onMounted(() => {
43
- document.addEventListener("click", handleClickOutside);
44
- });
45
- onUnmounted(() => {
46
- document.removeEventListener("click", handleClickOutside);
47
- });
48
- let onConfirmFn;
49
- function getDropdownSize() {
50
- if (!dropdownEl.value) return [DROPDOWN_DEFAULT_WIDTH, DROPDOWN_DEFAULT_HEIGHT];
51
- const rect = dropdownEl.value.getBoundingClientRect();
52
- return [rect.width || DROPDOWN_DEFAULT_WIDTH, rect.height || DROPDOWN_DEFAULT_HEIGHT];
53
- }
54
- function calculatePosition(docPos) {
55
- const scrollTop = window.pageYOffset || document.documentElement.scrollTop;
56
- const scrollLeft = window.pageXOffset || document.documentElement.scrollLeft;
57
- const viewportWidth = document.documentElement.clientWidth;
58
- const viewportHeight = document.documentElement.clientHeight;
59
- const [dropdownWidth, dropdownHeight] = getDropdownSize();
60
- let finalX = docPos.x;
61
- let finalY = docPos.y;
62
- if (docPos.x - scrollLeft + dropdownWidth > viewportWidth - PADDING) finalX = viewportWidth - dropdownWidth - PADDING + scrollLeft;
63
- const relativeY = docPos.y - scrollTop;
64
- if (relativeY + dropdownHeight > viewportHeight - PADDING) {
65
- const triggerHeight = docPos.height || 30;
66
- if (relativeY - triggerHeight >= dropdownHeight + PADDING) finalY = docPos.y - triggerHeight - dropdownHeight - PADDING;
67
- else finalY = PADDING + scrollTop;
68
- }
69
- finalX = Math.max(PADDING + scrollLeft, finalX);
70
- finalY = Math.max(PADDING + scrollTop, finalY);
71
- return {
72
- x: finalX,
73
- y: finalY
74
- };
75
- }
76
- async function show(pos, opt, onConfirm) {
77
- if (dropdownEl.value) dropdownEl.value.style.visibility = "hidden";
78
- visible.value = true;
79
- options.value = opt || [];
80
- initChecked();
81
- onConfirmFn = onConfirm;
82
- await nextTick();
83
- position.value = calculatePosition(pos);
84
- if (dropdownEl.value) dropdownEl.value.style.visibility = "visible";
85
- }
86
- async function handleClickOutside(e) {
87
- var _dropdownEl$value;
88
- if (!visible.value || ((_dropdownEl$value = dropdownEl.value) === null || _dropdownEl$value === void 0 ? void 0 : _dropdownEl$value.contains(e.target))) return;
89
- hide();
90
- }
91
- function initChecked() {
92
- options.value.forEach((opt) => {
93
- if (opt.selected) checkedTempValueSet.add(opt.value);
94
- });
95
- }
96
- function updateChecked(checked, row) {
97
- if (checked) checkedTempValueSet.add(row.value);
98
- else checkedTempValueSet.delete(row.value);
99
- }
100
- function confirm() {
101
- options.value.forEach((opt) => opt.selected = checkedTempValueSet.has(opt.value));
102
- onConfirmFn(Array.from(checkedTempValueSet));
103
- hide();
104
- }
105
- function hide() {
106
- visible.value = false;
107
- options.value = [];
108
- checkedTempValueSet.clear();
109
- }
110
- function handleRowClick(e, row) {
111
- updateChecked(!checkedTempValueSet.has(row.value), row);
112
- }
113
- function setTheme(t) {
114
- theme.value = t;
115
- }
116
- function handleClear() {
117
- checkedTempValueSet.clear();
118
- confirm();
119
- }
120
- __expose({
121
- visible,
122
- show,
123
- hide,
124
- setTheme
125
- });
126
- return (_ctx, _cache) => {
127
- return openBlock(), createElementBlock("div", {
128
- ref_key: "dropdownEl",
129
- ref: dropdownEl,
130
- class: normalizeClass(["stk-filter-dropdown", [`stk-filter-dropdown--${theme.value}`]]),
131
- style: normalizeStyle({
132
- top: position.value.y + "px",
133
- left: position.value.x + "px",
134
- display: visible.value ? void 0 : "none"
135
- }),
136
- onClick: _cache[0] || (_cache[0] = withModifiers(() => {}, ["stop"]))
137
- }, [createVNode(StkTable_default, {
138
- "row-key": "id",
139
- headless: "",
140
- virtual: "",
141
- "no-data-full": "",
142
- theme: theme.value,
143
- "row-active": false,
144
- "row-height": 20,
145
- bordered: false,
146
- columns: columns.value,
147
- "data-source": options.value,
148
- onRowClick: handleRowClick
149
- }, null, 8, [
150
- "theme",
151
- "columns",
152
- "data-source"
153
- ]), createElementVNode("footer", null, [createElementVNode("button", { onClick: handleClear }, "↺"), createElementVNode("button", { onClick: confirm }, "✓")])], 6);
154
- };
155
- }
156
- });
157
- //#endregion
158
- export { Dropdown_default as default };
1
+ /**
2
+ * name: stk-table-vue
3
+ * version: v1.0.0-beta.4
4
+ * description: High performance realtime virtual table for vue3 and vue2.7
5
+ * author: japlus
6
+ * homepage: https://ja-plus.github.io/stk-table-vue/
7
+ * license: MIT
8
+ */
9
+ import { t as StkTable_default } from "./StkTable-QUd4TJCF.js";
10
+ import { createElementBlock, createElementVNode, createVNode, defineComponent, h, nextTick, normalizeClass, normalizeStyle, onMounted, onUnmounted, openBlock, reactive, ref, withModifiers } from "vue";
11
+ //#region src/StkTable/custom-cells/FilterCell/Dropdown/index.vue?vue&type=script&setup=true&lang.ts
12
+ var DROPDOWN_DEFAULT_WIDTH = 300;
13
+ var DROPDOWN_DEFAULT_HEIGHT = 400;
14
+ var PADDING = 6;
15
+ //#endregion
16
+ //#region src/StkTable/custom-cells/FilterCell/Dropdown/index.vue
17
+ var Dropdown_default = /* @__PURE__ */ defineComponent({
18
+ __name: "index",
19
+ setup(__props, { expose: __expose }) {
20
+ const theme = ref("light");
21
+ const checkedTempValueSet = reactive(/* @__PURE__ */ new Set());
22
+ const columns = ref([{
23
+ title: "",
24
+ dataIndex: "value",
25
+ width: 30,
26
+ className: "stk-filter-dropdown-checkbox",
27
+ customCell: ({ row }) => h("input", {
28
+ type: "checkbox",
29
+ checked: checkedTempValueSet.has(row.value)
30
+ })
31
+ }, {
32
+ title: "",
33
+ dataIndex: "label"
34
+ }]);
35
+ const visible = ref(false);
36
+ const position = ref({
37
+ x: 0,
38
+ y: 0
39
+ });
40
+ const options = ref([]);
41
+ const dropdownEl = ref();
42
+ onMounted(() => {
43
+ document.addEventListener("click", handleClickOutside);
44
+ });
45
+ onUnmounted(() => {
46
+ document.removeEventListener("click", handleClickOutside);
47
+ });
48
+ let onConfirmFn;
49
+ function getDropdownSize() {
50
+ if (!dropdownEl.value) return [DROPDOWN_DEFAULT_WIDTH, DROPDOWN_DEFAULT_HEIGHT];
51
+ const rect = dropdownEl.value.getBoundingClientRect();
52
+ return [rect.width || DROPDOWN_DEFAULT_WIDTH, rect.height || DROPDOWN_DEFAULT_HEIGHT];
53
+ }
54
+ function calculatePosition(docPos) {
55
+ const scrollTop = window.pageYOffset || document.documentElement.scrollTop;
56
+ const scrollLeft = window.pageXOffset || document.documentElement.scrollLeft;
57
+ const viewportWidth = document.documentElement.clientWidth;
58
+ const viewportHeight = document.documentElement.clientHeight;
59
+ const [dropdownWidth, dropdownHeight] = getDropdownSize();
60
+ let finalX = docPos.x;
61
+ let finalY = docPos.y;
62
+ if (docPos.x - scrollLeft + dropdownWidth > viewportWidth - PADDING) finalX = viewportWidth - dropdownWidth - PADDING + scrollLeft;
63
+ const relativeY = docPos.y - scrollTop;
64
+ if (relativeY + dropdownHeight > viewportHeight - PADDING) {
65
+ const triggerHeight = docPos.height || 30;
66
+ if (relativeY - triggerHeight >= dropdownHeight + PADDING) finalY = docPos.y - triggerHeight - dropdownHeight - PADDING;
67
+ else finalY = PADDING + scrollTop;
68
+ }
69
+ finalX = Math.max(PADDING + scrollLeft, finalX);
70
+ finalY = Math.max(PADDING + scrollTop, finalY);
71
+ return {
72
+ x: finalX,
73
+ y: finalY
74
+ };
75
+ }
76
+ async function show(pos, opt, onConfirm) {
77
+ if (dropdownEl.value) dropdownEl.value.style.visibility = "hidden";
78
+ visible.value = true;
79
+ options.value = opt || [];
80
+ initChecked();
81
+ onConfirmFn = onConfirm;
82
+ await nextTick();
83
+ position.value = calculatePosition(pos);
84
+ if (dropdownEl.value) dropdownEl.value.style.visibility = "visible";
85
+ }
86
+ async function handleClickOutside(e) {
87
+ var _dropdownEl$value;
88
+ if (!visible.value || ((_dropdownEl$value = dropdownEl.value) === null || _dropdownEl$value === void 0 ? void 0 : _dropdownEl$value.contains(e.target))) return;
89
+ hide();
90
+ }
91
+ function initChecked() {
92
+ options.value.forEach((opt) => {
93
+ if (opt.selected) checkedTempValueSet.add(opt.value);
94
+ });
95
+ }
96
+ function updateChecked(checked, row) {
97
+ if (checked) checkedTempValueSet.add(row.value);
98
+ else checkedTempValueSet.delete(row.value);
99
+ }
100
+ function confirm() {
101
+ options.value.forEach((opt) => opt.selected = checkedTempValueSet.has(opt.value));
102
+ onConfirmFn(Array.from(checkedTempValueSet));
103
+ hide();
104
+ }
105
+ function hide() {
106
+ visible.value = false;
107
+ options.value = [];
108
+ checkedTempValueSet.clear();
109
+ }
110
+ function handleRowClick(e, row) {
111
+ updateChecked(!checkedTempValueSet.has(row.value), row);
112
+ }
113
+ function setTheme(t) {
114
+ theme.value = t;
115
+ }
116
+ function handleClear() {
117
+ checkedTempValueSet.clear();
118
+ confirm();
119
+ }
120
+ __expose({
121
+ visible,
122
+ show,
123
+ hide,
124
+ setTheme
125
+ });
126
+ return (_ctx, _cache) => {
127
+ return openBlock(), createElementBlock("div", {
128
+ ref_key: "dropdownEl",
129
+ ref: dropdownEl,
130
+ class: normalizeClass(["stk-filter-dropdown", [`stk-filter-dropdown--${theme.value}`]]),
131
+ style: normalizeStyle({
132
+ top: position.value.y + "px",
133
+ left: position.value.x + "px",
134
+ display: visible.value ? void 0 : "none"
135
+ }),
136
+ onClick: _cache[0] || (_cache[0] = withModifiers(() => {}, ["stop"]))
137
+ }, [createVNode(StkTable_default, {
138
+ "row-key": "id",
139
+ headless: "",
140
+ virtual: "",
141
+ "no-data-full": "",
142
+ theme: theme.value,
143
+ "row-active": false,
144
+ "row-height": 20,
145
+ bordered: false,
146
+ columns: columns.value,
147
+ "data-source": options.value,
148
+ onRowClick: handleRowClick
149
+ }, null, 8, [
150
+ "theme",
151
+ "columns",
152
+ "data-source"
153
+ ]), createElementVNode("footer", null, [createElementVNode("button", { onClick: handleClear }, "↺"), createElementVNode("button", { onClick: confirm }, "✓")])], 6);
154
+ };
155
+ }
156
+ });
157
+ //#endregion
158
+ export { Dropdown_default as default };