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