@visactor/vue-vtable 1.25.0 → 1.25.1-alpha.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 (143) hide show
  1. package/cjs/components/component/menu.js +3 -3
  2. package/cjs/components/component/tooltip.js +3 -3
  3. package/cjs/components/custom/checkBox.js +3 -3
  4. package/cjs/components/custom/group.js +3 -3
  5. package/cjs/components/custom/image.js +3 -3
  6. package/cjs/components/custom/radio.js +3 -3
  7. package/cjs/components/custom/tag.js +3 -3
  8. package/cjs/components/custom/text.js +3 -3
  9. package/cjs/components/custom/vtable-vue-attribute-plugin.js +622 -408
  10. package/cjs/components/list/list-column.js +3 -3
  11. package/cjs/components/pivot/pivot-column-dimension.js +3 -3
  12. package/cjs/components/pivot/pivot-column-header-title.js +3 -3
  13. package/cjs/components/pivot/pivot-corner.js +3 -3
  14. package/cjs/components/pivot/pivot-indicator.js +3 -3
  15. package/cjs/components/pivot/pivot-row-dimension.js +3 -3
  16. package/cjs/components/pivot/pivot-row-header-title.js +3 -3
  17. package/cjs/constants.js +1 -0
  18. package/cjs/edit/editor.js +209 -194
  19. package/cjs/edit/util.js +51 -31
  20. package/cjs/eventsUtils.js +97 -60
  21. package/cjs/hooks/useCellRender.js +27 -20
  22. package/cjs/hooks/useEditorRender.js +75 -52
  23. package/cjs/index.js +5 -5
  24. package/cjs/tables/base-table.vue.js +266 -237
  25. package/cjs/tables/chartModule.js +2 -2
  26. package/cjs/tables/list-table.vue.js +41 -39
  27. package/cjs/tables/pivot-chart.vue.js +35 -37
  28. package/cjs/tables/pivot-table.vue.js +36 -38
  29. package/cjs/utils/customLayoutUtils.js +109 -96
  30. package/cjs/utils/slotUtils.js +85 -88
  31. package/cjs/utils/stringUtils.js +14 -12
  32. package/cjs/utils/vnodeUtils.js +3 -2
  33. package/dist/vue-vtable.js +1715 -1358
  34. package/dist/vue-vtable.min.js +1 -1
  35. package/es/components/component/menu.js +3 -3
  36. package/es/components/component/tooltip.js +3 -3
  37. package/es/components/custom/checkBox.js +3 -3
  38. package/es/components/custom/group.js +3 -3
  39. package/es/components/custom/image.js +3 -3
  40. package/es/components/custom/radio.js +3 -3
  41. package/es/components/custom/tag.js +3 -3
  42. package/es/components/custom/text.js +3 -3
  43. package/es/components/custom/vtable-vue-attribute-plugin.js +622 -408
  44. package/es/components/list/list-column.js +3 -3
  45. package/es/components/pivot/pivot-column-dimension.js +3 -3
  46. package/es/components/pivot/pivot-column-header-title.js +3 -3
  47. package/es/components/pivot/pivot-corner.js +3 -3
  48. package/es/components/pivot/pivot-indicator.js +3 -3
  49. package/es/components/pivot/pivot-row-dimension.js +3 -3
  50. package/es/components/pivot/pivot-row-header-title.js +3 -3
  51. package/es/constants.js +1 -0
  52. package/es/edit/editor.js +209 -194
  53. package/es/edit/util.js +51 -31
  54. package/es/eventsUtils.js +97 -60
  55. package/es/hooks/useCellRender.js +27 -20
  56. package/es/hooks/useEditorRender.js +75 -52
  57. package/es/index.js +3 -3
  58. package/es/tables/base-table.vue.js +266 -237
  59. package/es/tables/chartModule.js +2 -2
  60. package/es/tables/list-table.vue.js +41 -39
  61. package/es/tables/pivot-chart.vue.js +35 -37
  62. package/es/tables/pivot-table.vue.js +36 -38
  63. package/es/utils/customLayoutUtils.js +109 -96
  64. package/es/utils/slotUtils.js +85 -88
  65. package/es/utils/stringUtils.js +14 -12
  66. package/es/utils/vnodeUtils.js +3 -2
  67. package/package.json +5 -5
  68. package/cjs/components/component/menu.d.ts +0 -14
  69. package/cjs/components/component/tooltip.d.ts +0 -11
  70. package/cjs/components/custom/checkBox.d.ts +0 -20
  71. package/cjs/components/custom/custom-layout.d.ts +0 -20
  72. package/cjs/components/custom/group.d.ts +0 -6
  73. package/cjs/components/custom/image.d.ts +0 -6
  74. package/cjs/components/custom/radio.d.ts +0 -17
  75. package/cjs/components/custom/tag.d.ts +0 -16
  76. package/cjs/components/custom/text.d.ts +0 -6
  77. package/cjs/components/custom/vtable-vue-attribute-plugin.d.ts +0 -62
  78. package/cjs/components/index.d.ts +0 -15
  79. package/cjs/components/list/list-column.d.ts +0 -7
  80. package/cjs/components/pivot/pivot-column-dimension.d.ts +0 -11
  81. package/cjs/components/pivot/pivot-column-header-title.d.ts +0 -7
  82. package/cjs/components/pivot/pivot-corner.d.ts +0 -7
  83. package/cjs/components/pivot/pivot-indicator.d.ts +0 -7
  84. package/cjs/components/pivot/pivot-row-dimension.d.ts +0 -11
  85. package/cjs/components/pivot/pivot-row-header-title.d.ts +0 -7
  86. package/cjs/constants.d.ts +0 -1
  87. package/cjs/edit/editor.d.ts +0 -50
  88. package/cjs/edit/index.d.ts +0 -2
  89. package/cjs/edit/util.d.ts +0 -4
  90. package/cjs/eventsUtils.d.ts +0 -120
  91. package/cjs/hooks/index.d.ts +0 -2
  92. package/cjs/hooks/useCellRender.d.ts +0 -2
  93. package/cjs/hooks/useEditorRender.d.ts +0 -2
  94. package/cjs/index.d.ts +0 -6
  95. package/cjs/tables/base-table.vue.d.ts +0 -543
  96. package/cjs/tables/chartModule.d.ts +0 -1
  97. package/cjs/tables/index.d.ts +0 -5
  98. package/cjs/tables/list-table.vue.d.ts +0 -38
  99. package/cjs/tables/pivot-chart.vue.d.ts +0 -38
  100. package/cjs/tables/pivot-table.vue.d.ts +0 -38
  101. package/cjs/utils/customLayoutUtils.d.ts +0 -5
  102. package/cjs/utils/slotUtils.d.ts +0 -28
  103. package/cjs/utils/stringUtils.d.ts +0 -2
  104. package/cjs/utils/vnodeUtils.d.ts +0 -1
  105. package/cjs/utils.d.ts +0 -4
  106. package/es/components/component/menu.d.ts +0 -14
  107. package/es/components/component/tooltip.d.ts +0 -11
  108. package/es/components/custom/checkBox.d.ts +0 -20
  109. package/es/components/custom/custom-layout.d.ts +0 -20
  110. package/es/components/custom/group.d.ts +0 -6
  111. package/es/components/custom/image.d.ts +0 -6
  112. package/es/components/custom/radio.d.ts +0 -17
  113. package/es/components/custom/tag.d.ts +0 -16
  114. package/es/components/custom/text.d.ts +0 -6
  115. package/es/components/custom/vtable-vue-attribute-plugin.d.ts +0 -62
  116. package/es/components/index.d.ts +0 -15
  117. package/es/components/list/list-column.d.ts +0 -7
  118. package/es/components/pivot/pivot-column-dimension.d.ts +0 -11
  119. package/es/components/pivot/pivot-column-header-title.d.ts +0 -7
  120. package/es/components/pivot/pivot-corner.d.ts +0 -7
  121. package/es/components/pivot/pivot-indicator.d.ts +0 -7
  122. package/es/components/pivot/pivot-row-dimension.d.ts +0 -11
  123. package/es/components/pivot/pivot-row-header-title.d.ts +0 -7
  124. package/es/constants.d.ts +0 -1
  125. package/es/edit/editor.d.ts +0 -50
  126. package/es/edit/index.d.ts +0 -2
  127. package/es/edit/util.d.ts +0 -4
  128. package/es/eventsUtils.d.ts +0 -120
  129. package/es/hooks/index.d.ts +0 -2
  130. package/es/hooks/useCellRender.d.ts +0 -2
  131. package/es/hooks/useEditorRender.d.ts +0 -2
  132. package/es/index.d.ts +0 -6
  133. package/es/tables/base-table.vue.d.ts +0 -543
  134. package/es/tables/chartModule.d.ts +0 -1
  135. package/es/tables/index.d.ts +0 -5
  136. package/es/tables/list-table.vue.d.ts +0 -38
  137. package/es/tables/pivot-chart.vue.d.ts +0 -38
  138. package/es/tables/pivot-table.vue.d.ts +0 -38
  139. package/es/utils/customLayoutUtils.d.ts +0 -5
  140. package/es/utils/slotUtils.d.ts +0 -28
  141. package/es/utils/stringUtils.d.ts +0 -2
  142. package/es/utils/vnodeUtils.d.ts +0 -1
  143. package/es/utils.d.ts +0 -4
@@ -4,243 +4,272 @@ import { TABLE_EVENTS_KEYS, TABLE_EVENTS } from '../eventsUtils.js';
4
4
  import { useEditorRender } from '../hooks/useEditorRender.js';
5
5
  import { useCellRender } from '../hooks/useCellRender.js';
6
6
 
7
- var _sfc_main = defineComponent({
8
- __name: 'base-table',
9
- props: {
10
- type: { type: String, required: false },
11
- options: { type: null, required: false },
12
- records: { type: Array, required: false },
13
- width: { type: [Number, String], required: false, default: '100%' },
14
- height: { type: [Number, String], required: false, default: '100%' },
15
- onReady: { type: Function, required: false },
16
- onError: { type: Function, required: false },
17
- keepColumnWidthChange: { type: Boolean, required: false },
18
- onClickCell: { type: Function, required: false },
19
- onDblClickCell: { type: Function, required: false },
20
- onMouseDownCell: { type: Function, required: false },
21
- onMouseUpCell: { type: Function, required: false },
22
- onSelectedCell: { type: Function, required: false },
23
- onKeyDown: { type: Function, required: false },
24
- onMouseEnterTable: { type: Function, required: false },
25
- onMouseLeaveTable: { type: Function, required: false },
26
- onMouseDownTable: { type: Function, required: false },
27
- onMouseMoveCell: { type: Function, required: false },
28
- onMouseEnterCell: { type: Function, required: false },
29
- onMouseLeaveCell: { type: Function, required: false },
30
- onContextMenuCell: { type: Function, required: false },
31
- onContextMenuCanvas: { type: Function, required: false },
32
- onResizeColumn: { type: Function, required: false },
33
- onResizeColumnEnd: { type: Function, required: false },
34
- onChangeHeaderPosition: { type: Function, required: false },
35
- onChangeHeaderPositionStart: { type: Function, required: false },
36
- onChangeHeaderPositionFail: { type: Function, required: false },
37
- onSortClick: { type: Function, required: false },
38
- onFreezeClick: { type: Function, required: false },
39
- onScroll: { type: Function, required: false },
40
- onDropdownMenuClick: { type: Function, required: false },
41
- onMouseOverChartSymbol: { type: Function, required: false },
42
- onDragSelectEnd: { type: Function, required: false },
43
- onDropdownIconClick: { type: Function, required: false },
44
- onDropdownMenuClear: { type: Function, required: false },
45
- onTreeHierarchyStateChange: { type: Function, required: false },
46
- onShowMenu: { type: Function, required: false },
47
- onHideMenu: { type: Function, required: false },
48
- onIconClick: { type: Function, required: false },
49
- onLegendItemClick: { type: Function, required: false },
50
- onLegendItemHover: { type: Function, required: false },
51
- onLegendItemUnHover: { type: Function, required: false },
52
- onLegendChange: { type: Function, required: false },
53
- onMouseEnterAxis: { type: Function, required: false },
54
- onMouseLeaveAxis: { type: Function, required: false },
55
- onCheckboxStateChange: { type: Function, required: false },
56
- onRadioStateChange: { type: Function, required: false },
57
- onAfterRender: { type: Function, required: false },
58
- onInitialized: { type: Function, required: false },
59
- onPivotSortClick: { type: Function, required: false },
60
- onDrillMenuClick: { type: Function, required: false },
61
- onVChartEventType: { type: Function, required: false },
62
- onChangeCellValue: { type: Function, required: false },
63
- onMousedownFillHandle: { type: Function, required: false },
64
- onDragFillHandleEnd: { type: Function, required: false },
65
- onDblclickFillHandle: { type: Function, required: false },
66
- onScrollVerticalEnd: { type: Function, required: false },
67
- onScrollHorizontalEnd: { type: Function, required: false },
68
- onChangCellValue: { type: Function, required: false },
69
- onEmptyTipClick: { type: Function, required: false },
70
- onEmptyTipDblClick: { type: Function, required: false },
71
- onButtonClick: { type: Function, required: false },
72
- onBeforeCacheChartImage: { type: Function, required: false },
73
- onPastedData: { type: Function, required: false }
74
- },
75
- emits: TABLE_EVENTS_KEYS,
76
- setup(__props, { expose: __expose, emit: __emit }) {
77
- const props = __props;
78
- const vTableContainer = ref(null);
79
- const vTableInstance = shallowRef(null);
80
- const columnWidths = ref(new Map());
81
- const pivotColumnWidths = ref([]);
82
- const pivotHeaderColumnWidths = ref([]);
83
- useEditorRender(props, vTableInstance);
84
- useCellRender(props, vTableInstance);
85
- __expose({ vTableInstance });
86
- const containerWidth = computed(() => (typeof props.width === 'number' ? `${props.width}px` : props.width));
87
- const containerHeight = computed(() => (typeof props.height === 'number' ? `${props.height}px` : props.height));
88
- const emit = __emit;
89
- const bindEvents = (instance) => {
90
- TABLE_EVENTS_KEYS.forEach(eventKey => {
91
- const vueEventHandler = (event) => {
92
- emit(eventKey, event);
93
- };
94
- instance.on(TABLE_EVENTS[eventKey], vueEventHandler);
95
- });
96
- };
97
- const createTableInstance = (Type, options) => {
98
- const vtable = new Type(vTableContainer.value, options);
99
- vTableInstance.value = vtable;
100
- columnWidths.value.clear();
101
- pivotColumnWidths.value = [];
102
- pivotHeaderColumnWidths.value = [];
103
- vtable.on('resize_column_end', (args) => {
104
- if (!props.keepColumnWidthChange) {
105
- return;
106
- }
107
- const { col, colWidths } = args;
108
- const width = colWidths[col];
109
- if (vtable.isPivotTable()) {
110
- const path = vtable.getCellHeaderPaths(col, vtable.columnHeaderLevelCount);
111
- let dimensions = null;
112
- if (path.cellLocation === 'rowHeader') {
113
- dimensions = path.rowHeaderPaths;
114
- }
115
- else {
116
- dimensions = path.colHeaderPaths;
117
- }
118
- let found = false;
119
- for (let i = 0; i < pivotColumnWidths.value.length; i++) {
120
- const item = pivotColumnWidths.value[i];
121
- if (JSON.stringify(item.dimensions) === JSON.stringify(dimensions)) {
122
- item.width = width;
123
- found = true;
124
- }
125
- }
126
- if (!found) {
127
- pivotColumnWidths.value.push({ dimensions, width });
128
- }
129
- }
130
- else {
131
- const define = vtable.getBodyColumnDefine(col, 0);
132
- if (define === null || define === void 0 ? void 0 : define.key) {
133
- columnWidths.value.set(define.key, width);
134
- }
135
- }
136
- });
137
- };
138
- const createVTable = () => {
139
- var _a, _b;
140
- if (!vTableContainer.value) {
141
- return;
142
- }
143
- if (vTableInstance.value) {
144
- vTableInstance.value.release();
145
- }
146
- const getRecords = () => {
147
- return props.records !== undefined && props.records !== null && props.records.length > 0
148
- ? props.records
149
- : props.options.records;
150
- };
151
- try {
152
- switch (props.type) {
153
- case 'list':
154
- createTableInstance(ListTable, Object.assign(Object.assign({}, props.options), { records: getRecords() }));
155
- break;
156
- case 'pivot':
157
- createTableInstance(PivotTable, Object.assign(Object.assign({}, props.options), { records: getRecords() }));
158
- break;
159
- case 'chart':
160
- createTableInstance(PivotChart, Object.assign(Object.assign({}, props.options), { records: getRecords() }));
161
- break;
162
- }
163
- bindEvents(vTableInstance.value);
164
- (_a = props.onReady) === null || _a === void 0 ? void 0 : _a.call(props, vTableInstance.value, true);
165
- }
166
- catch (err) {
167
- (_b = props.onError) === null || _b === void 0 ? void 0 : _b.call(props, err);
168
- }
169
- };
170
- const updateVTable = (newOptions) => {
171
- var _a;
172
- if (!vTableInstance.value) {
173
- return;
174
- }
175
- try {
176
- if (props.keepColumnWidthChange) {
177
- const columnWidthConfig = updateWidthCache(columnWidths.value, pivotColumnWidths.value, vTableInstance.value);
178
- newOptions = Object.assign(Object.assign({}, newOptions), { columnWidthConfig: columnWidthConfig, columnWidthConfigForRowHeader: columnWidthConfig });
179
- }
180
- switch (props.type) {
181
- case 'list':
182
- if (vTableInstance.value instanceof ListTable) {
183
- vTableInstance.value.updateOption(newOptions);
184
- }
185
- break;
186
- case 'pivot':
187
- if (vTableInstance.value instanceof PivotTable) {
188
- vTableInstance.value.updateOption(newOptions);
189
- }
190
- break;
191
- case 'chart':
192
- if (vTableInstance.value instanceof PivotChart) {
193
- vTableInstance.value.updateOption(newOptions);
194
- }
195
- break;
196
- }
197
- }
198
- catch (err) {
199
- (_a = props.onError) === null || _a === void 0 ? void 0 : _a.call(props, err);
200
- }
201
- };
202
- onMounted(createVTable);
203
- onBeforeUnmount(() => {
204
- var _a;
205
- (_a = vTableInstance.value) === null || _a === void 0 ? void 0 : _a.release();
206
- });
207
- watch(() => props.options, (newOptions, oldOptions) => {
208
- if (vTableInstance.value) {
209
- updateVTable(newOptions);
210
- }
211
- else {
212
- createVTable();
213
- }
214
- });
215
- watch(() => props.records, (newRecords, oldRecords) => {
216
- if (vTableInstance.value) {
217
- updateVTable(Object.assign(Object.assign({}, props.options), { records: newRecords }));
218
- }
219
- else {
220
- createVTable();
221
- }
222
- }, { deep: true });
223
- function updateWidthCache(columnWidths, pivotColumnWidths, table) {
224
- if (table.isPivotTable()) {
225
- return pivotColumnWidths;
226
- }
227
- const columnWidthConfig = [];
228
- columnWidths.forEach((width, key) => {
229
- columnWidthConfig.push({
230
- key,
231
- width
232
- });
233
- });
234
- return columnWidthConfig;
235
- }
236
- return (_ctx, _cache) => {
237
- return (openBlock(), createElementBlock("div", {
238
- ref_key: "vTableContainer",
239
- ref: vTableContainer,
240
- style: normalizeStyle([{ width: containerWidth.value, height: containerHeight.value }, { "position": "relative" }])
241
- }, null, 4));
242
- };
243
- }
7
+ // 创建表格实例
8
+ // use Constructor<T> will cause error in rollup-plugin-typescript2, use any temporarily
9
+ var _sfc_main = /*@__PURE__*/ defineComponent({
10
+ __name: 'base-table',
11
+ props: {
12
+ type: { type: String, required: false },
13
+ options: { type: null, required: false },
14
+ records: { type: Array, required: false },
15
+ width: { type: [Number, String], required: false, default: '100%' },
16
+ height: { type: [Number, String], required: false, default: '100%' },
17
+ onReady: { type: Function, required: false },
18
+ onError: { type: Function, required: false },
19
+ keepColumnWidthChange: { type: Boolean, required: false },
20
+ onClickCell: { type: Function, required: false },
21
+ onDblClickCell: { type: Function, required: false },
22
+ onMouseDownCell: { type: Function, required: false },
23
+ onMouseUpCell: { type: Function, required: false },
24
+ onSelectedCell: { type: Function, required: false },
25
+ onKeyDown: { type: Function, required: false },
26
+ onMouseEnterTable: { type: Function, required: false },
27
+ onMouseLeaveTable: { type: Function, required: false },
28
+ onMouseDownTable: { type: Function, required: false },
29
+ onMouseMoveCell: { type: Function, required: false },
30
+ onMouseEnterCell: { type: Function, required: false },
31
+ onMouseLeaveCell: { type: Function, required: false },
32
+ onContextMenuCell: { type: Function, required: false },
33
+ onContextMenuCanvas: { type: Function, required: false },
34
+ onResizeColumn: { type: Function, required: false },
35
+ onResizeColumnEnd: { type: Function, required: false },
36
+ onChangeHeaderPosition: { type: Function, required: false },
37
+ onChangeHeaderPositionStart: { type: Function, required: false },
38
+ onChangeHeaderPositionFail: { type: Function, required: false },
39
+ onSortClick: { type: Function, required: false },
40
+ onFreezeClick: { type: Function, required: false },
41
+ onScroll: { type: Function, required: false },
42
+ onDropdownMenuClick: { type: Function, required: false },
43
+ onMouseOverChartSymbol: { type: Function, required: false },
44
+ onDragSelectEnd: { type: Function, required: false },
45
+ onDropdownIconClick: { type: Function, required: false },
46
+ onDropdownMenuClear: { type: Function, required: false },
47
+ onTreeHierarchyStateChange: { type: Function, required: false },
48
+ onShowMenu: { type: Function, required: false },
49
+ onHideMenu: { type: Function, required: false },
50
+ onIconClick: { type: Function, required: false },
51
+ onLegendItemClick: { type: Function, required: false },
52
+ onLegendItemHover: { type: Function, required: false },
53
+ onLegendItemUnHover: { type: Function, required: false },
54
+ onLegendChange: { type: Function, required: false },
55
+ onMouseEnterAxis: { type: Function, required: false },
56
+ onMouseLeaveAxis: { type: Function, required: false },
57
+ onCheckboxStateChange: { type: Function, required: false },
58
+ onRadioStateChange: { type: Function, required: false },
59
+ onAfterRender: { type: Function, required: false },
60
+ onInitialized: { type: Function, required: false },
61
+ onPivotSortClick: { type: Function, required: false },
62
+ onDrillMenuClick: { type: Function, required: false },
63
+ onVChartEventType: { type: Function, required: false },
64
+ onChangeCellValue: { type: Function, required: false },
65
+ onMousedownFillHandle: { type: Function, required: false },
66
+ onDragFillHandleEnd: { type: Function, required: false },
67
+ onDblclickFillHandle: { type: Function, required: false },
68
+ onScrollVerticalEnd: { type: Function, required: false },
69
+ onScrollHorizontalEnd: { type: Function, required: false },
70
+ onChangCellValue: { type: Function, required: false },
71
+ onEmptyTipClick: { type: Function, required: false },
72
+ onEmptyTipDblClick: { type: Function, required: false },
73
+ onButtonClick: { type: Function, required: false },
74
+ onBeforeCacheChartImage: { type: Function, required: false },
75
+ onPastedData: { type: Function, required: false }
76
+ },
77
+ emits: TABLE_EVENTS_KEYS,
78
+ setup(__props, { expose: __expose, emit: __emit }) {
79
+ const props = __props;
80
+ // 创建用于引用 DOM 元素和表格实例的 ref
81
+ const vTableContainer = ref(null);
82
+ const vTableInstance = shallowRef(null);
83
+ // for keepColumnWidthChange
84
+ const columnWidths = ref(new Map());
85
+ const pivotColumnWidths = ref([]);
86
+ const pivotHeaderColumnWidths = ref([]);
87
+ // 自定义编辑渲染器
88
+ useEditorRender(props, vTableInstance);
89
+ // 自定义单元格渲染器
90
+ useCellRender(props, vTableInstance);
91
+ // 公开 vTableInstance,以便外部组件可以访问
92
+ __expose({ vTableInstance });
93
+ // 计算容器的宽度和高度
94
+ const containerWidth = computed(() => (typeof props.width === 'number' ? `${props.width}px` : props.width));
95
+ const containerHeight = computed(() => (typeof props.height === 'number' ? `${props.height}px` : props.height));
96
+ // 绑定事件到表格实例
97
+ const emit = __emit;
98
+ const bindEvents = (instance) => {
99
+ TABLE_EVENTS_KEYS.forEach(eventKey => {
100
+ const vueEventHandler = (event) => {
101
+ emit(eventKey, event);
102
+ };
103
+ instance.on(TABLE_EVENTS[eventKey], vueEventHandler);
104
+ });
105
+ };
106
+ const createTableInstance = (Type, options) => {
107
+ const vtable = new Type(vTableContainer.value, options);
108
+ vTableInstance.value = vtable;
109
+ // for keepColumnWidthChange
110
+ columnWidths.value.clear();
111
+ pivotColumnWidths.value = [];
112
+ pivotHeaderColumnWidths.value = [];
113
+ vtable.on('resize_column_end', (args) => {
114
+ // const table = vTableInstance.value;
115
+ if (!props.keepColumnWidthChange) {
116
+ return;
117
+ }
118
+ const { col, colWidths } = args;
119
+ const width = colWidths[col];
120
+ if (vtable.isPivotTable()) {
121
+ const path = vtable.getCellHeaderPaths(col, vtable.columnHeaderLevelCount);
122
+ let dimensions = null;
123
+ if (path.cellLocation === 'rowHeader') {
124
+ dimensions = path.rowHeaderPaths;
125
+ }
126
+ else {
127
+ dimensions = path.colHeaderPaths;
128
+ }
129
+ let found = false;
130
+ // pivotColumnWidths.value.forEach(item => {
131
+ // if (JSON.stringify(item.dimensions) === JSON.stringify(dimensions)) {
132
+ // item.width = width;
133
+ // found = true;
134
+ // }
135
+ // });
136
+ for (let i = 0; i < pivotColumnWidths.value.length; i++) {
137
+ const item = pivotColumnWidths.value[i];
138
+ if (JSON.stringify(item.dimensions) === JSON.stringify(dimensions)) {
139
+ item.width = width;
140
+ found = true;
141
+ }
142
+ }
143
+ if (!found) {
144
+ pivotColumnWidths.value.push({ dimensions, width });
145
+ }
146
+ }
147
+ else {
148
+ const define = vtable.getBodyColumnDefine(col, 0);
149
+ if (define === null || define === void 0 ? void 0 : define.key) {
150
+ columnWidths.value.set(define.key, width);
151
+ }
152
+ }
153
+ });
154
+ };
155
+ const createVTable = () => {
156
+ var _a, _b;
157
+ if (!vTableContainer.value) {
158
+ return;
159
+ }
160
+ if (vTableInstance.value) {
161
+ vTableInstance.value.release();
162
+ }
163
+ const getRecords = () => {
164
+ return props.records !== undefined && props.records !== null && props.records.length > 0
165
+ ? props.records
166
+ : props.options.records;
167
+ };
168
+ try {
169
+ switch (props.type) {
170
+ case 'list':
171
+ createTableInstance(ListTable, Object.assign(Object.assign({}, props.options), { records: getRecords() }));
172
+ break;
173
+ case 'pivot':
174
+ createTableInstance(PivotTable, Object.assign(Object.assign({}, props.options), { records: getRecords() }));
175
+ break;
176
+ case 'chart':
177
+ createTableInstance(PivotChart, Object.assign(Object.assign({}, props.options), { records: getRecords() }));
178
+ break;
179
+ }
180
+ bindEvents(vTableInstance.value);
181
+ (_a = props.onReady) === null || _a === void 0 ? void 0 : _a.call(props, vTableInstance.value, true);
182
+ }
183
+ catch (err) {
184
+ (_b = props.onError) === null || _b === void 0 ? void 0 : _b.call(props, err);
185
+ }
186
+ };
187
+ // 更新表格实例
188
+ const updateVTable = (newOptions) => {
189
+ var _a;
190
+ if (!vTableInstance.value) {
191
+ return;
192
+ }
193
+ try {
194
+ // for keepColumnWidthChange, update column width
195
+ if (props.keepColumnWidthChange) {
196
+ const columnWidthConfig = updateWidthCache(columnWidths.value, pivotColumnWidths.value, vTableInstance.value);
197
+ newOptions = Object.assign(Object.assign({}, newOptions), { columnWidthConfig: columnWidthConfig, columnWidthConfigForRowHeader: columnWidthConfig });
198
+ }
199
+ switch (props.type) {
200
+ case 'list':
201
+ if (vTableInstance.value instanceof ListTable) {
202
+ vTableInstance.value.updateOption(newOptions);
203
+ }
204
+ break;
205
+ case 'pivot':
206
+ if (vTableInstance.value instanceof PivotTable) {
207
+ vTableInstance.value.updateOption(newOptions);
208
+ }
209
+ break;
210
+ case 'chart':
211
+ if (vTableInstance.value instanceof PivotChart) {
212
+ vTableInstance.value.updateOption(newOptions);
213
+ }
214
+ break;
215
+ }
216
+ }
217
+ catch (err) {
218
+ (_a = props.onError) === null || _a === void 0 ? void 0 : _a.call(props, err);
219
+ }
220
+ };
221
+ // 组件挂载时创建表格
222
+ onMounted(createVTable);
223
+ onBeforeUnmount(() => {
224
+ var _a;
225
+ (_a = vTableInstance.value) === null || _a === void 0 ? void 0 : _a.release();
226
+ });
227
+ // 监听 options 属性的变化
228
+ // 需要去做细颗粒度的比较
229
+ // deep 选中会导致tree失效
230
+ watch(() => props.options, (newOptions, oldOptions) => {
231
+ if (vTableInstance.value) {
232
+ updateVTable(newOptions);
233
+ }
234
+ else {
235
+ createVTable();
236
+ }
237
+ }
238
+ // { deep: true },
239
+ );
240
+ // 监听 records 属性的变化并更新表格
241
+ // 需要去做细颗粒度的比较
242
+ watch(() => props.records, (newRecords, oldRecords) => {
243
+ // if (!isEqual(newRecords, oldRecords)) {
244
+ if (vTableInstance.value) {
245
+ updateVTable(Object.assign(Object.assign({}, props.options), { records: newRecords }));
246
+ }
247
+ else {
248
+ createVTable();
249
+ }
250
+ // }
251
+ }, { deep: true });
252
+ function updateWidthCache(columnWidths, pivotColumnWidths, table) {
253
+ if (table.isPivotTable()) {
254
+ return pivotColumnWidths;
255
+ }
256
+ const columnWidthConfig = [];
257
+ columnWidths.forEach((width, key) => {
258
+ columnWidthConfig.push({
259
+ key,
260
+ width
261
+ });
262
+ });
263
+ return columnWidthConfig;
264
+ }
265
+ return (_ctx, _cache) => {
266
+ return (openBlock(), createElementBlock("div", {
267
+ ref_key: "vTableContainer",
268
+ ref: vTableContainer,
269
+ style: normalizeStyle([{ width: containerWidth.value, height: containerHeight.value }, { "position": "relative" }])
270
+ }, null, 4 /* STYLE */));
271
+ };
272
+ }
244
273
  });
245
274
 
246
275
  export { _sfc_main as default };
@@ -1,7 +1,7 @@
1
1
  import * as VTable from '@visactor/vtable';
2
2
 
3
- const registerChartModule = (name, chart) => {
4
- VTable.register.chartModule(name, chart);
3
+ const registerChartModule = (name, chart) => {
4
+ VTable.register.chartModule(name, chart);
5
5
  };
6
6
 
7
7
  export { registerChartModule };
@@ -1,46 +1,48 @@
1
1
  import { defineComponent, ref, useSlots, computed, openBlock, createElementBlock, Fragment, createVNode, mergeProps, renderSlot } from 'vue';
2
+ import _sfc_main$1 from './base-table.vue.js';
2
3
  import { flattenVNodes } from '../utils/vnodeUtils.js';
3
- import '@visactor/vtable';
4
- import '@visactor/vutils';
5
4
  import { extractListSlotOptions, mergeSlotOptions } from '../utils/slotUtils.js';
6
- import _sfc_main$1 from './base-table.vue.js';
7
5
 
8
- var _sfc_main = defineComponent({
9
- __name: 'list-table',
10
- props: {
11
- options: { type: Object, required: true },
12
- records: { type: Array, required: false },
13
- width: { type: [String, Number], required: false },
14
- height: { type: [String, Number], required: false }
15
- },
16
- setup(__props, { expose: __expose }) {
17
- const props = __props;
18
- const baseTableRef = ref(null);
19
- const slots = useSlots();
20
- const computedOptions = computed(() => {
21
- var _a;
22
- const flattenedSlots = flattenVNodes(((_a = slots.default) === null || _a === void 0 ? void 0 : _a.call(slots)) || []);
23
- const slotOptions = extractListSlotOptions(flattenedSlots);
24
- return mergeSlotOptions(props.options, slotOptions);
25
- });
26
- __expose({
27
- vTableInstance: computed(() => { var _a; return ((_a = baseTableRef.value) === null || _a === void 0 ? void 0 : _a.vTableInstance) || null; }),
28
- });
29
- return (_ctx, _cache) => {
30
- return (openBlock(), createElementBlock(Fragment, null, [
31
- createVNode(_sfc_main$1, mergeProps({
32
- type: "list",
33
- options: computedOptions.value,
34
- records: __props.records,
35
- width: __props.width,
36
- height: __props.height,
37
- ref_key: "baseTableRef",
38
- ref: baseTableRef
39
- }, _ctx.$attrs), null, 16, ["options", "records", "width", "height"]),
40
- renderSlot(_ctx.$slots, "default")
41
- ], 64));
42
- };
43
- }
6
+ // 定义属性
7
+ var _sfc_main = /*@__PURE__*/ defineComponent({
8
+ __name: 'list-table',
9
+ props: {
10
+ options: { type: Object, required: true },
11
+ records: { type: Array, required: false },
12
+ width: { type: [String, Number], required: false },
13
+ height: { type: [String, Number], required: false }
14
+ },
15
+ setup(__props, { expose: __expose }) {
16
+ const props = __props;
17
+ // 引用BaseTable实例
18
+ const baseTableRef = ref(null);
19
+ const slots = useSlots();
20
+ // 合并插槽配置
21
+ const computedOptions = computed(() => {
22
+ var _a;
23
+ const flattenedSlots = flattenVNodes(((_a = slots.default) === null || _a === void 0 ? void 0 : _a.call(slots)) || []);
24
+ const slotOptions = extractListSlotOptions(flattenedSlots);
25
+ return mergeSlotOptions(props.options, slotOptions);
26
+ });
27
+ // 暴露实例
28
+ __expose({
29
+ vTableInstance: computed(() => { var _a; return ((_a = baseTableRef.value) === null || _a === void 0 ? void 0 : _a.vTableInstance) || null; }),
30
+ });
31
+ return (_ctx, _cache) => {
32
+ return (openBlock(), createElementBlock(Fragment, null, [
33
+ createVNode(_sfc_main$1, mergeProps({
34
+ type: "list",
35
+ options: computedOptions.value,
36
+ records: __props.records,
37
+ width: __props.width,
38
+ height: __props.height,
39
+ ref_key: "baseTableRef",
40
+ ref: baseTableRef
41
+ }, _ctx.$attrs), null, 16 /* FULL_PROPS */, ["options", "records", "width", "height"]),
42
+ renderSlot(_ctx.$slots, "default")
43
+ ], 64 /* STABLE_FRAGMENT */));
44
+ };
45
+ }
44
46
  });
45
47
 
46
48
  export { _sfc_main as default };