@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
@@ -1,418 +1,632 @@
1
1
  'use strict';
2
2
 
3
- var tslib = require('tslib');
4
3
  var VTable = require('@visactor/vtable');
5
4
  var vrender = require('@visactor/vtable/es/vrender');
6
5
  var vutils = require('@visactor/vutils');
7
6
  var vue = require('vue');
8
7
 
9
- class VTableVueAttributePlugin extends vrender.HtmlAttributePlugin {
10
- constructor(currentContext) {
11
- super();
12
- this.name = 'VTableVueAttributePlugin';
13
- this.renderQueue = new Set();
14
- this.isRendering = false;
15
- this.MAX_CACHE_COUNT = 100;
16
- this.accessQueue = [];
17
- this.VIEWPORT_BUFFER = 100;
18
- this.BUFFER_ZONE = 500;
19
- this.styleUpdateQueue = new Map();
20
- this.styleUpdateRequested = false;
21
- this.eventHandlers = new WeakMap();
22
- this.currentContext = currentContext;
23
- }
24
- renderGraphicHTML(graphic) {
25
- if (!this.checkNeedRender(graphic)) {
26
- return;
27
- }
28
- this.renderQueue.add(graphic);
29
- this.scheduleRender();
30
- }
31
- scheduleRender() {
32
- if (this.isRendering) {
33
- return;
34
- }
35
- this.isRendering = true;
36
- vrender.vglobal.getRequestAnimationFrame()(() => {
37
- this.renderQueue.forEach(graphic => {
38
- try {
39
- this.doRenderGraphic(graphic);
40
- }
41
- catch (error) {
42
- const { id } = this.getGraphicOptions(graphic) || {};
43
- this.removeElement(id, true);
44
- }
45
- });
46
- this.renderQueue.clear();
47
- this.isRendering = false;
48
- });
49
- }
50
- doRenderGraphic(graphic) {
51
- var _a;
52
- const { id, options } = this.getGraphicOptions(graphic);
53
- if (!id) {
54
- return;
55
- }
56
- const stage = graphic.stage;
57
- const { element, container: expectedContainer } = options;
58
- const actualContainer = expectedContainer ? checkFrozenContainer(graphic) : expectedContainer;
59
- let targetMap = (_a = this.htmlMap) === null || _a === void 0 ? void 0 : _a[id];
60
- if (targetMap && actualContainer && actualContainer !== targetMap.container) {
61
- this.removeElement(id);
62
- targetMap = null;
63
- }
64
- this.checkToPassAppContext(element, graphic);
65
- if (!targetMap || !this.checkDom(targetMap.wrapContainer)) {
66
- this.checkAndClearCache(graphic);
67
- const { wrapContainer, nativeContainer, reuse } = this.getWrapContainer(stage, actualContainer, { id, options });
68
- if (wrapContainer) {
69
- const dataRenderId = `${this.renderId}`;
70
- wrapContainer.id = id;
71
- wrapContainer.setAttribute('data-vue-renderId', dataRenderId);
72
- wrapContainer.style.display = 'none';
73
- if (!reuse) {
74
- vue.render(element, wrapContainer);
75
- }
76
- targetMap = {
77
- wrapContainer,
78
- nativeContainer,
79
- container: actualContainer,
80
- renderId: this.renderId,
81
- graphic,
82
- isInViewport: true,
83
- lastPosition: null,
84
- lastStyle: {}
85
- };
86
- this.htmlMap[id] = targetMap;
87
- }
88
- }
89
- if (targetMap) {
90
- targetMap.renderId = this.renderId;
91
- targetMap.lastAccessed = Date.now();
92
- this.updateAccessQueue(id);
93
- this.updateStyleOfWrapContainer(graphic, stage, targetMap.wrapContainer, targetMap.nativeContainer);
94
- }
95
- }
96
- getGraphicOptions(graphic) {
97
- var _a;
98
- const { vue } = (graphic === null || graphic === void 0 ? void 0 : graphic.attribute) || {};
99
- if (!vue) {
100
- return null;
101
- }
102
- const id = vutils.isNil(vue.id) ? (_a = graphic.id) !== null && _a !== void 0 ? _a : graphic._uid : vue.id;
103
- return { id: `vue_${id}`, options: vue };
104
- }
105
- checkToPassAppContext(vnode, graphic) {
106
- var _a, _b;
107
- try {
108
- const customConfig = this.getCustomConfig(graphic);
109
- const userAppContext = (_b = (_a = customConfig === null || customConfig === void 0 ? void 0 : customConfig.getVueUserAppContext) === null || _a === void 0 ? void 0 : _a.call(customConfig)) !== null && _b !== void 0 ? _b : this.currentContext;
110
- if (!!(userAppContext === null || userAppContext === void 0 ? void 0 : userAppContext.components) && !!(userAppContext === null || userAppContext === void 0 ? void 0 : userAppContext.directives)) {
111
- vnode.appContext = userAppContext;
112
- }
113
- }
114
- catch (error) { }
115
- }
116
- getCustomConfig(graphic) {
117
- var _a, _b, _c;
118
- const target = getTargetGroup(graphic);
119
- return (_c = (_b = (_a = target === null || target === void 0 ? void 0 : target.stage) === null || _a === void 0 ? void 0 : _a.table) === null || _b === void 0 ? void 0 : _b.options) === null || _c === void 0 ? void 0 : _c.customConfig;
120
- }
121
- checkNeedRender(graphic) {
122
- const { id, options } = this.getGraphicOptions(graphic) || {};
123
- if (!id) {
124
- return false;
125
- }
126
- const stage = graphic.stage;
127
- if (!stage) {
128
- return false;
129
- }
130
- const { element } = options;
131
- if (!element) {
132
- return false;
133
- }
134
- const isInViewport = this.checkInViewport(graphic);
135
- return isInViewport;
136
- }
137
- checkInViewport(graphic) {
138
- return this.checkInViewportByZone(graphic, this.VIEWPORT_BUFFER);
139
- }
140
- checkInBuffer(graphic) {
141
- return this.checkInViewportByZone(graphic, this.BUFFER_ZONE);
142
- }
143
- checkInViewportByZone(graphic, buffer = 0) {
144
- const { stage, globalAABBBounds: cBounds } = graphic;
145
- if (!stage) {
146
- return false;
147
- }
148
- const { AABBBounds: vBounds } = stage;
149
- const eBounds = {
150
- x1: vBounds.x1 - buffer,
151
- x2: vBounds.x2 + buffer,
152
- y1: vBounds.y1 - buffer,
153
- y2: vBounds.y2 + buffer
154
- };
155
- const isIntersecting = cBounds.x1 < eBounds.x2 && cBounds.x2 > eBounds.x1 && cBounds.y1 < eBounds.y2 && cBounds.y2 > eBounds.y1;
156
- return isIntersecting;
157
- }
158
- updateAccessQueue(id) {
159
- const index = this.accessQueue.indexOf(id);
160
- if (index > -1) {
161
- this.accessQueue.splice(index, 1);
162
- }
163
- this.accessQueue.unshift(id);
164
- }
165
- checkAndClearCache(graphic) {
166
- var _a;
167
- const { viewportNodes, bufferNodes, cacheNodes } = this.classifyNodes();
168
- const total = viewportNodes.length + bufferNodes.length + cacheNodes.length;
169
- const customConfig = this.getCustomConfig(graphic);
170
- const maxTotal = (_a = customConfig === null || customConfig === void 0 ? void 0 : customConfig.maxDomCacheCount) !== null && _a !== void 0 ? _a : this.MAX_CACHE_COUNT;
171
- if (total <= maxTotal) {
172
- return;
173
- }
174
- const exceedingCount = total - maxTotal;
175
- let toRemove = cacheNodes.slice(0, exceedingCount);
176
- if (toRemove.length < exceedingCount) {
177
- const bufferCandidates = bufferNodes
178
- .sort((a, b) => this.htmlMap[a].lastAccessed - this.htmlMap[b].lastAccessed)
179
- .slice(0, exceedingCount - toRemove.length);
180
- toRemove = toRemove.concat(bufferCandidates);
181
- }
182
- toRemove.forEach(id => this.removeElement(id, true));
183
- }
184
- classifyNodes() {
185
- const viewportNodes = [];
186
- const bufferNodes = [];
187
- const cacheNodes = [];
188
- Object.keys(this.htmlMap).forEach(id => {
189
- const node = this.htmlMap[id];
190
- if (node.isInViewport) {
191
- viewportNodes.push(id);
192
- }
193
- else if (this.checkInBuffer(node.graphic)) {
194
- bufferNodes.push(id);
195
- }
196
- else {
197
- cacheNodes.push(id);
198
- }
199
- });
200
- return {
201
- viewportNodes,
202
- bufferNodes,
203
- cacheNodes
204
- };
205
- }
206
- checkDom(dom) {
207
- if (!dom) {
208
- return false;
209
- }
210
- return document.contains(dom);
211
- }
212
- removeAllDom(g) {
213
- if (this.htmlMap) {
214
- Object.keys(this.htmlMap).forEach(key => {
215
- this.removeElement(key, true);
216
- });
217
- this.htmlMap = null;
218
- }
219
- }
220
- removeElement(id, clear) {
221
- var _a;
222
- const record = (_a = this.htmlMap) === null || _a === void 0 ? void 0 : _a[id];
223
- if (!record) {
224
- return;
225
- }
226
- const { wrapContainer } = record;
227
- if (!wrapContainer) {
228
- return;
229
- }
230
- if (!clear) {
231
- wrapContainer.remove();
232
- record.isInViewport = false;
233
- const index = this.accessQueue.indexOf(id);
234
- if (index > -1) {
235
- this.accessQueue.splice(index, 1);
236
- }
237
- }
238
- else {
239
- vue.render(null, wrapContainer);
240
- this.checkDom(wrapContainer) && super.removeElement(id);
241
- delete this.htmlMap[id];
242
- }
243
- this.removeWrapContainerEventListener(wrapContainer);
244
- }
245
- getWrapContainer(stage, userContainer, domParams) {
246
- var _a;
247
- let nativeContainer;
248
- if (userContainer) {
249
- nativeContainer =
250
- typeof userContainer === 'string' ? vrender.application.global.getElementById(userContainer) : userContainer;
251
- }
252
- else {
253
- nativeContainer = stage.window.getContainer();
254
- }
255
- const { id } = domParams || {};
256
- const record = (_a = this.htmlMap) === null || _a === void 0 ? void 0 : _a[id];
257
- if (record && !record.isInViewport) {
258
- const { wrapContainer } = record;
259
- if (!this.checkDom(wrapContainer)) {
260
- nativeContainer.appendChild(wrapContainer);
261
- }
262
- return {
263
- reuse: true,
264
- wrapContainer,
265
- nativeContainer
266
- };
267
- }
268
- return {
269
- wrapContainer: vrender.application.global.createDom({ tagName: 'div', parent: nativeContainer }),
270
- nativeContainer
271
- };
272
- }
273
- updateStyleOfWrapContainer(graphic, stage, wrapContainer, nativeContainer) {
274
- const { attribute, type } = graphic;
275
- const _a = attribute || {}, { vue: options, width, height, visible, display } = _a, rest = tslib.__rest(_a, ["vue", "width", "height", "visible", "display"]);
276
- const { x: left, y: top } = this.calculatePosition(graphic, options.anchorType);
277
- const { left: offsetX, top: offsetTop } = this.calculateOffset(stage, nativeContainer, left, top);
278
- const { id } = this.getGraphicOptions(graphic) || {};
279
- const record = id ? this.htmlMap[id] : null;
280
- if (!record) {
281
- return;
282
- }
283
- const positionChanged = !record.lastPosition || record.lastPosition.x !== offsetX || record.lastPosition.y !== offsetTop;
284
- if (!positionChanged) {
285
- return;
286
- }
287
- const { pointerEvents } = options;
288
- const calculateStyle = this.parseDefaultStyleFromGraphic(graphic);
289
- const style = this.convertCellStyle(graphic);
290
- Object.assign(calculateStyle, Object.assign(Object.assign(Object.assign({ width: `${width}px`, height: `${height}px`, overflow: 'hidden' }, (style || {})), (rest || {})), { transform: `translate(${offsetX}px, ${offsetTop}px)`, boxSizing: 'border-box', display: visible !== false ? display || 'block' : 'none', pointerEvents: pointerEvents === true ? 'all' : pointerEvents || 'none', position: 'absolute' }));
291
- if (calculateStyle.pointerEvents !== 'none') {
292
- this.checkToAddEventListener(wrapContainer);
293
- }
294
- if (type === 'text' && options.anchorType === 'position') {
295
- Object.assign(calculateStyle, this.getTransformOfText(graphic));
296
- }
297
- this.applyUserStyles(options, calculateStyle, { offsetX, offsetTop, graphic, wrapContainer });
298
- const styleChanged = !vutils.isEqual(record.lastStyle, calculateStyle);
299
- if (styleChanged) {
300
- this.styleUpdateQueue.set(wrapContainer.id, calculateStyle);
301
- this.requestStyleUpdate();
302
- record.lastStyle = calculateStyle;
303
- }
304
- }
305
- checkToAddEventListener(wrapContainer) {
306
- if (!this.eventHandlers.has(wrapContainer)) {
307
- const handler = (e) => {
308
- e.preventDefault();
309
- this.onWheel(e);
310
- };
311
- wrapContainer.addEventListener('wheel', handler, { passive: false });
312
- this.eventHandlers.set(wrapContainer, handler);
313
- }
314
- }
315
- requestStyleUpdate() {
316
- if (!this.styleUpdateRequested) {
317
- this.styleUpdateRequested = true;
318
- vrender.vglobal.getRequestAnimationFrame()(() => {
319
- this.styleUpdateQueue.forEach((changes, id) => {
320
- var _a, _b;
321
- const container = (_b = (_a = this.htmlMap) === null || _a === void 0 ? void 0 : _a[id]) === null || _b === void 0 ? void 0 : _b.wrapContainer;
322
- if (container) {
323
- Object.assign(container.style, changes);
324
- }
325
- });
326
- this.styleUpdateQueue.clear();
327
- this.styleUpdateRequested = false;
328
- });
329
- }
330
- }
331
- convertCellStyle(graphic) {
332
- var _a;
333
- const { col, row, stage } = getTargetGroup(graphic);
334
- const style = (_a = stage === null || stage === void 0 ? void 0 : stage.table) === null || _a === void 0 ? void 0 : _a.getCellStyle(col, row);
335
- if (!vutils.isObject(style)) {
336
- return;
337
- }
338
- const _b = style, { lineHeight, padding } = _b, rest = tslib.__rest(_b, ["lineHeight", "padding"]);
339
- return Object.assign(Object.assign({}, rest), { padding: vutils.isArray(padding) ? padding.map(value => `${value}px`).join(' ') : padding });
340
- }
341
- calculatePosition(graphic, anchorType) {
342
- const bounds = graphic.globalAABBBounds;
343
- if (anchorType === 'position' || bounds.empty()) {
344
- const matrix = graphic.globalTransMatrix;
345
- return { x: matrix.e, y: matrix.f };
346
- }
347
- return vutils.calculateAnchorOfBounds(bounds, anchorType || 'top-left');
348
- }
349
- calculateOffset(stage, nativeContainer, x, y) {
350
- const containerTL = vrender.application.global.getElementTopLeft(nativeContainer, false);
351
- const windowTL = stage.window.getTopLeft(false);
352
- return {
353
- left: x + windowTL.left - containerTL.left,
354
- top: y + windowTL.top - containerTL.top
355
- };
356
- }
357
- applyUserStyles(options, baseStyle, context) {
358
- if (vutils.isFunction(options.style)) {
359
- const userStyle = options.style({
360
- top: context.offsetTop,
361
- left: context.offsetX,
362
- width: context.graphic.globalAABBBounds.width(),
363
- height: context.graphic.globalAABBBounds.height()
364
- }, context.graphic, context.wrapContainer);
365
- Object.assign(baseStyle, userStyle);
366
- }
367
- else if (vutils.isObject(options.style)) {
368
- Object.assign(baseStyle, options.style);
369
- }
370
- else if (vutils.isString(options.style)) {
371
- Object.assign(baseStyle, vutils.styleStringToObject(options.style));
372
- }
373
- }
374
- }
375
- function checkFrozenContainer(graphic) {
376
- var _a;
377
- const { col, row, stage } = getTargetGroup(graphic);
378
- let container = (_a = graphic.attribute.vue) === null || _a === void 0 ? void 0 : _a.container;
379
- const { table } = stage;
380
- if (container === table.bodyDomContainer) {
381
- if (col < table.frozenColCount && row >= table.rowCount - table.bottomFrozenRowCount) {
382
- container = table.bottomFrozenBodyDomContainer;
383
- }
384
- else if (col >= table.colCount - table.rightFrozenColCount &&
385
- row >= table.rowCount - table.bottomFrozenRowCount) {
386
- container = table.rightFrozenBottomDomContainer;
387
- }
388
- else if (row >= table.rowCount - table.bottomFrozenRowCount) {
389
- container = table.bottomFrozenBodyDomContainer;
390
- }
391
- else if (col < table.frozenColCount) {
392
- container = table.frozenBodyDomContainer;
393
- }
394
- else if (col >= table.colCount - table.rightFrozenColCount) {
395
- container = table.rightFrozenBodyDomContainer;
396
- }
397
- }
398
- else if (container === table.headerDomContainer) {
399
- if (col < table.frozenColCount) {
400
- container = table.frozenHeaderDomContainer;
401
- }
402
- else if (col >= table.colCount - table.rightFrozenColCount) {
403
- container = table.rightFrozenHeaderDomContainer;
404
- }
405
- }
406
- return container;
407
- }
408
- function getTargetGroup(target) {
409
- while (target === null || target === void 0 ? void 0 : target.parent) {
410
- if (target.name === VTable.CUSTOM_CONTAINER_NAME || (target.name || '').startsWith(VTable.CUSTOM_MERGE_PRE_NAME)) {
411
- return target;
412
- }
413
- target = target.parent;
414
- }
415
- return { col: -1, row: -1, stage: null };
8
+ var __rest = (undefined && undefined.__rest) || function (s, e) {
9
+ var t = {};
10
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
11
+ t[p] = s[p];
12
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
13
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
14
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
15
+ t[p[i]] = s[p[i]];
16
+ }
17
+ return t;
18
+ };
19
+ /**
20
+ * 表格自定义组件集成插件
21
+ */
22
+ class VTableVueAttributePlugin extends vrender.HtmlAttributePlugin {
23
+ constructor(currentContext) {
24
+ super();
25
+ this.name = 'VTableVueAttributePlugin';
26
+ /** 渲染队列 */
27
+ this.renderQueue = new Set();
28
+ /** 是否正在渲染 */
29
+ this.isRendering = false;
30
+ /** 最大缓存节点数(兜底值) */
31
+ this.MAX_CACHE_COUNT = 100;
32
+ /** 记录节点访问顺序(LRU用) */
33
+ this.accessQueue = [];
34
+ /** 目标可视区区(可视区外一定范围内的节点,保留) */
35
+ this.VIEWPORT_BUFFER = 100;
36
+ /** 缓冲区(非可视区且非缓冲区的节点需清理) */
37
+ this.BUFFER_ZONE = 500;
38
+ // 新增批量更新队列
39
+ this.styleUpdateQueue = new Map();
40
+ /** 样式更新中 */
41
+ this.styleUpdateRequested = false;
42
+ /** 事件集 */
43
+ this.eventHandlers = new WeakMap();
44
+ this.currentContext = currentContext;
45
+ }
46
+ /**
47
+ * @description: 单元格变化后重新渲染组件,由 HtmlAttributePlugin 插件触发
48
+ * @param {IGraphic} graphic
49
+ * @return {*}
50
+ */
51
+ renderGraphicHTML(graphic) {
52
+ if (!this.checkNeedRender(graphic)) {
53
+ return;
54
+ }
55
+ // 加入异步渲染队列
56
+ this.renderQueue.add(graphic);
57
+ this.scheduleRender();
58
+ }
59
+ /**
60
+ * @description: 渲染调度
61
+ * @return {*}
62
+ */
63
+ scheduleRender() {
64
+ if (this.isRendering) {
65
+ return;
66
+ }
67
+ this.isRendering = true;
68
+ vrender.vglobal.getRequestAnimationFrame()(() => {
69
+ this.renderQueue.forEach(graphic => {
70
+ try {
71
+ this.doRenderGraphic(graphic);
72
+ }
73
+ catch (error) {
74
+ const { id } = this.getGraphicOptions(graphic) || {};
75
+ this.removeElement(id, true);
76
+ }
77
+ });
78
+ this.renderQueue.clear();
79
+ this.isRendering = false;
80
+ });
81
+ }
82
+ /**
83
+ * @description: 单元格变化后实际组件渲染方法
84
+ * @param {IGraphic} graphic
85
+ * @return {*}
86
+ */
87
+ doRenderGraphic(graphic) {
88
+ var _a;
89
+ const { id, options } = this.getGraphicOptions(graphic);
90
+ if (!id) {
91
+ return;
92
+ }
93
+ const stage = graphic.stage;
94
+ const { element, container: expectedContainer } = options;
95
+ // 获取实际容器
96
+ const actualContainer = expectedContainer ? checkFrozenContainer(graphic) : expectedContainer;
97
+ // 检查是否需要移除旧容器
98
+ let targetMap = (_a = this.htmlMap) === null || _a === void 0 ? void 0 : _a[id];
99
+ if (targetMap && actualContainer && actualContainer !== targetMap.container) {
100
+ // 容器变更
101
+ this.removeElement(id);
102
+ targetMap = null;
103
+ }
104
+ // 校验并传递上下文
105
+ this.checkToPassAppContext(element, graphic);
106
+ // 渲染或更新 Vue 组件
107
+ if (!targetMap || !this.checkDom(targetMap.wrapContainer)) {
108
+ // 缓存节点检查
109
+ this.checkAndClearCache(graphic);
110
+ const { wrapContainer, nativeContainer, reuse } = this.getWrapContainer(stage, actualContainer, { id, options });
111
+ if (wrapContainer) {
112
+ const dataRenderId = `${this.renderId}`;
113
+ wrapContainer.id = id;
114
+ wrapContainer.setAttribute('data-vue-renderId', dataRenderId);
115
+ // 先隐藏
116
+ wrapContainer.style.display = 'none';
117
+ if (!reuse) {
118
+ // 仅在非复用时需要重新渲染
119
+ vue.render(element, wrapContainer);
120
+ }
121
+ targetMap = {
122
+ wrapContainer,
123
+ nativeContainer,
124
+ container: actualContainer,
125
+ renderId: this.renderId,
126
+ graphic,
127
+ isInViewport: true,
128
+ lastPosition: null,
129
+ lastStyle: {}
130
+ };
131
+ this.htmlMap[id] = targetMap;
132
+ }
133
+ }
134
+ // 更新样式并记录渲染 ID
135
+ if (targetMap) {
136
+ targetMap.renderId = this.renderId;
137
+ targetMap.lastAccessed = Date.now();
138
+ this.updateAccessQueue(id);
139
+ this.updateStyleOfWrapContainer(graphic, stage, targetMap.wrapContainer, targetMap.nativeContainer);
140
+ }
141
+ }
142
+ /**
143
+ * @description: 获取渲染参数
144
+ * @param {IGraphic} graphic
145
+ * @return {*}
146
+ */
147
+ getGraphicOptions(graphic) {
148
+ var _a;
149
+ // TODO render 组件接入 vue 类型
150
+ //@ts-ignore
151
+ const { vue } = (graphic === null || graphic === void 0 ? void 0 : graphic.attribute) || {};
152
+ if (!vue) {
153
+ return null;
154
+ }
155
+ const id = vutils.isNil(vue.id) ? (_a = graphic.id) !== null && _a !== void 0 ? _a : graphic._uid : vue.id;
156
+ return { id: `vue_${id}`, options: vue };
157
+ }
158
+ /**
159
+ * @description: 校验并传递上下文
160
+ * @param {VNode} vnode
161
+ * @param {IGraphic} graphic
162
+ * @return {*}
163
+ */
164
+ checkToPassAppContext(vnode, graphic) {
165
+ var _a, _b;
166
+ try {
167
+ const customConfig = this.getCustomConfig(graphic);
168
+ const userAppContext = (_b = (_a = customConfig === null || customConfig === void 0 ? void 0 : customConfig.getVueUserAppContext) === null || _a === void 0 ? void 0 : _a.call(customConfig)) !== null && _b !== void 0 ? _b : this.currentContext;
169
+ // 简单校验合法性
170
+ if (!!(userAppContext === null || userAppContext === void 0 ? void 0 : userAppContext.components) && !!(userAppContext === null || userAppContext === void 0 ? void 0 : userAppContext.directives)) {
171
+ vnode.appContext = userAppContext;
172
+ }
173
+ }
174
+ catch (error) { }
175
+ }
176
+ /**
177
+ * @description: 获取自定义配置
178
+ * @param {IGraphic} graphic
179
+ * @return {*}
180
+ */
181
+ getCustomConfig(graphic) {
182
+ var _a, _b, _c;
183
+ const target = getTargetGroup(graphic);
184
+ return (_c = (_b = (_a = target === null || target === void 0 ? void 0 : target.stage) === null || _a === void 0 ? void 0 : _a.table) === null || _b === void 0 ? void 0 : _b.options) === null || _c === void 0 ? void 0 : _c.customConfig;
185
+ }
186
+ /**
187
+ * @description: 检查是否需要渲染
188
+ * @param {IGraphic} graphic
189
+ * @return {*}
190
+ */
191
+ checkNeedRender(graphic) {
192
+ const { id, options } = this.getGraphicOptions(graphic) || {};
193
+ if (!id) {
194
+ return false;
195
+ }
196
+ const stage = graphic.stage;
197
+ if (!stage) {
198
+ return false;
199
+ }
200
+ const { element } = options;
201
+ if (!element) {
202
+ return false;
203
+ }
204
+ const isInViewport = this.checkInViewport(graphic);
205
+ // 不在可视区内暂时不需要移除,因为在 clearCacheContainer 方法中提前被移除了
206
+ return isInViewport;
207
+ }
208
+ /**
209
+ * @description: 判断是否在可视范围内
210
+ * @param {IGraphic} graphic
211
+ * @return {*}
212
+ */
213
+ checkInViewport(graphic) {
214
+ return this.checkInViewportByZone(graphic, this.VIEWPORT_BUFFER);
215
+ }
216
+ /**
217
+ * @description: 判断是否在缓冲区内
218
+ * @param {IGraphic} graphic
219
+ * @return {*}
220
+ */
221
+ checkInBuffer(graphic) {
222
+ return this.checkInViewportByZone(graphic, this.BUFFER_ZONE);
223
+ }
224
+ /**
225
+ * @description: 判断当前是否在指定视口范围内
226
+ * @param {IGraphic} graphic
227
+ * @param {number} buffer
228
+ * @return {*}
229
+ */
230
+ checkInViewportByZone(graphic, buffer = 0) {
231
+ const { stage, globalAABBBounds: cBounds } = graphic;
232
+ if (!stage) {
233
+ return false;
234
+ }
235
+ // 获取视口的AABB边界
236
+ //@ts-ignore
237
+ const { AABBBounds: vBounds } = stage;
238
+ // 扩展视口判断范围
239
+ const eBounds = {
240
+ x1: vBounds.x1 - buffer,
241
+ x2: vBounds.x2 + buffer,
242
+ y1: vBounds.y1 - buffer,
243
+ y2: vBounds.y2 + buffer
244
+ };
245
+ // 判断两个区域是否相交
246
+ const isIntersecting = cBounds.x1 < eBounds.x2 && cBounds.x2 > eBounds.x1 && cBounds.y1 < eBounds.y2 && cBounds.y2 > eBounds.y1;
247
+ return isIntersecting;
248
+ }
249
+ /**
250
+ * @description: 节点访问顺序队列
251
+ * @param {string} id
252
+ * @return {*}
253
+ */
254
+ updateAccessQueue(id) {
255
+ // 移除旧记录
256
+ const index = this.accessQueue.indexOf(id);
257
+ if (index > -1) {
258
+ this.accessQueue.splice(index, 1);
259
+ }
260
+ // 添加到队列头部
261
+ this.accessQueue.unshift(id);
262
+ }
263
+ /**
264
+ * @description: 在添加新节点前检查缓存大小
265
+ * @param {IGraphic} graphic
266
+ * @return {*}
267
+ */
268
+ checkAndClearCache(graphic) {
269
+ var _a;
270
+ const { viewportNodes, bufferNodes, cacheNodes } = this.classifyNodes();
271
+ const total = viewportNodes.length + bufferNodes.length + cacheNodes.length;
272
+ const customConfig = this.getCustomConfig(graphic);
273
+ const maxTotal = (_a = customConfig === null || customConfig === void 0 ? void 0 : customConfig.maxDomCacheCount) !== null && _a !== void 0 ? _a : this.MAX_CACHE_COUNT;
274
+ // 仅当总数超过阈值时清理
275
+ if (total <= maxTotal) {
276
+ return;
277
+ }
278
+ const exceedingCount = total - maxTotal;
279
+ // 优先清理缓存区节点: 移除缓存区的前 exceedingCount 个节点
280
+ let toRemove = cacheNodes.slice(0, exceedingCount);
281
+ // 若缓存区节点不满足阈值,为了控制内存占用率,按最后访问时间清除最早访问的缓冲区节点
282
+ if (toRemove.length < exceedingCount) {
283
+ const bufferCandidates = bufferNodes
284
+ .sort((a, b) => this.htmlMap[a].lastAccessed - this.htmlMap[b].lastAccessed)
285
+ .slice(0, exceedingCount - toRemove.length);
286
+ toRemove = toRemove.concat(bufferCandidates);
287
+ }
288
+ // 执行清理
289
+ toRemove.forEach(id => this.removeElement(id, true));
290
+ }
291
+ /**
292
+ * @description: 节点按可视区/缓存区/缓冲区分类
293
+ * @return {*}
294
+ */
295
+ classifyNodes() {
296
+ /** 可视区节点 */
297
+ const viewportNodes = [];
298
+ /** 缓冲区节点 */
299
+ const bufferNodes = [];
300
+ /** 既不在可视区也不在缓冲区的节点 */
301
+ const cacheNodes = [];
302
+ Object.keys(this.htmlMap).forEach(id => {
303
+ const node = this.htmlMap[id];
304
+ if (node.isInViewport) {
305
+ viewportNodes.push(id);
306
+ }
307
+ else if (this.checkInBuffer(node.graphic)) {
308
+ bufferNodes.push(id);
309
+ }
310
+ else {
311
+ cacheNodes.push(id);
312
+ }
313
+ });
314
+ return {
315
+ viewportNodes,
316
+ bufferNodes,
317
+ cacheNodes
318
+ };
319
+ }
320
+ /**
321
+ * @description: 检查 dom 是否存在
322
+ * @param {HTMLElement} dom
323
+ * @return {*}
324
+ */
325
+ checkDom(dom) {
326
+ if (!dom) {
327
+ return false;
328
+ }
329
+ return document.contains(dom);
330
+ }
331
+ /**
332
+ * @description: 清除所有 dom
333
+ * @param {IGraphic} g
334
+ * @return {*}
335
+ */
336
+ removeAllDom(g) {
337
+ if (this.htmlMap) {
338
+ Object.keys(this.htmlMap).forEach(key => {
339
+ this.removeElement(key, true);
340
+ });
341
+ this.htmlMap = null;
342
+ }
343
+ }
344
+ /**
345
+ * @description: 移除元素
346
+ * @param {string} id
347
+ * @param {boolean} clear 强制清除
348
+ * @return {*}
349
+ * 目前涉及到页面重绘的操作(比如列宽拖动会使得图形重绘,id变更),会有短暂的容器插拔现象
350
+ */
351
+ removeElement(id, clear) {
352
+ var _a;
353
+ const record = (_a = this.htmlMap) === null || _a === void 0 ? void 0 : _a[id];
354
+ if (!record) {
355
+ return;
356
+ }
357
+ const { wrapContainer } = record;
358
+ if (!wrapContainer) {
359
+ return;
360
+ }
361
+ if (!clear) {
362
+ // 移除 dom 但保留在 htmlMap 中,供下次进入可视区时快速复用
363
+ wrapContainer.remove();
364
+ // 标记不在视口
365
+ record.isInViewport = false;
366
+ // 清理访问队列
367
+ const index = this.accessQueue.indexOf(id);
368
+ if (index > -1) {
369
+ this.accessQueue.splice(index, 1);
370
+ }
371
+ }
372
+ else {
373
+ // 卸载子组件
374
+ vue.render(null, wrapContainer);
375
+ this.checkDom(wrapContainer) && super.removeElement(id);
376
+ // 清理引用
377
+ delete this.htmlMap[id];
378
+ }
379
+ // 清理事件
380
+ this.removeWrapContainerEventListener(wrapContainer);
381
+ }
382
+ /**
383
+ * @description: 获取包裹容器
384
+ * @param {IStage} stage
385
+ * @param {string} userContainer
386
+ * @param {CreateDOMParamsType} domParams
387
+ * @return {*}
388
+ */
389
+ getWrapContainer(stage, userContainer, domParams) {
390
+ var _a;
391
+ let nativeContainer;
392
+ if (userContainer) {
393
+ nativeContainer =
394
+ typeof userContainer === 'string' ? vrender.application.global.getElementById(userContainer) : userContainer;
395
+ }
396
+ else {
397
+ nativeContainer = stage.window.getContainer();
398
+ }
399
+ const { id } = domParams || {};
400
+ // 从 htmlMap 查找可复用 dom
401
+ const record = (_a = this.htmlMap) === null || _a === void 0 ? void 0 : _a[id];
402
+ if (record && !record.isInViewport) {
403
+ const { wrapContainer } = record;
404
+ if (!this.checkDom(wrapContainer)) {
405
+ // 添加游离节点
406
+ nativeContainer.appendChild(wrapContainer);
407
+ }
408
+ return {
409
+ reuse: true,
410
+ wrapContainer,
411
+ nativeContainer
412
+ };
413
+ }
414
+ return {
415
+ wrapContainer: vrender.application.global.createDom({ tagName: 'div', parent: nativeContainer }),
416
+ nativeContainer
417
+ };
418
+ }
419
+ /**
420
+ * @description: 更新包裹容器样式
421
+ * @param {IGraphic} graphic
422
+ * @param {IStage} stage
423
+ * @param {HTMLElement} wrapContainer
424
+ * @param {HTMLElement} nativeContainer
425
+ * @return {*}
426
+ */
427
+ updateStyleOfWrapContainer(graphic, stage, wrapContainer, nativeContainer) {
428
+ const { attribute, type } = graphic;
429
+ //@ts-ignore
430
+ const _a = attribute || {}, { vue: options, width, height, visible, display } = _a, rest = __rest(_a, ["vue", "width", "height", "visible", "display"]);
431
+ const { x: left, y: top } = this.calculatePosition(graphic, options.anchorType);
432
+ const { left: offsetX, top: offsetTop } = this.calculateOffset(stage, nativeContainer, left, top);
433
+ const { id } = this.getGraphicOptions(graphic) || {};
434
+ const record = id ? this.htmlMap[id] : null;
435
+ if (!record) {
436
+ return;
437
+ }
438
+ // 位置变化检查
439
+ const positionChanged = !record.lastPosition || record.lastPosition.x !== offsetX || record.lastPosition.y !== offsetTop;
440
+ if (!positionChanged) {
441
+ // 位置没有变化,无需更新样式
442
+ return;
443
+ }
444
+ // 默认自定义区域内也可带动表格画布滚动
445
+ const { pointerEvents } = options;
446
+ const calculateStyle = this.parseDefaultStyleFromGraphic(graphic);
447
+ // 单元格样式
448
+ const style = this.convertCellStyle(graphic);
449
+ Object.assign(calculateStyle, Object.assign(Object.assign(Object.assign({ width: `${width}px`, height: `${height}px`, overflow: 'hidden' }, (style || {})), (rest || {})), { transform: `translate(${offsetX}px, ${offsetTop}px)`, boxSizing: 'border-box', display: visible !== false ? display || 'block' : 'none', pointerEvents: pointerEvents === true ? 'all' : pointerEvents || 'none', position: 'absolute' }));
450
+ if (calculateStyle.pointerEvents !== 'none') {
451
+ this.checkToAddEventListener(wrapContainer);
452
+ }
453
+ if (type === 'text' && options.anchorType === 'position') {
454
+ Object.assign(calculateStyle, this.getTransformOfText(graphic));
455
+ }
456
+ this.applyUserStyles(options, calculateStyle, { offsetX, offsetTop, graphic, wrapContainer });
457
+ // 样式变化检查
458
+ const styleChanged = !vutils.isEqual(record.lastStyle, calculateStyle);
459
+ if (styleChanged) {
460
+ this.styleUpdateQueue.set(wrapContainer.id, calculateStyle);
461
+ // 请求批量更新
462
+ this.requestStyleUpdate();
463
+ // TODO 确认是否需要对接 VTableBrowserEnvContribution
464
+ // application.global.updateDom(wrapContainer, {
465
+ // width,
466
+ // height,
467
+ // style: calculateStyle
468
+ // });
469
+ record.lastStyle = calculateStyle;
470
+ }
471
+ }
472
+ /**
473
+ * @description: 事件监听器管理
474
+ * @param {HTMLElement} wrapContainer
475
+ * @return {*}
476
+ */
477
+ checkToAddEventListener(wrapContainer) {
478
+ if (!this.eventHandlers.has(wrapContainer)) {
479
+ const handler = (e) => {
480
+ e.preventDefault();
481
+ this.onWheel(e);
482
+ };
483
+ wrapContainer.addEventListener('wheel', handler, { passive: false });
484
+ this.eventHandlers.set(wrapContainer, handler);
485
+ }
486
+ }
487
+ /**
488
+ * @description: 样式更新
489
+ * @return {*}
490
+ */
491
+ requestStyleUpdate() {
492
+ if (!this.styleUpdateRequested) {
493
+ this.styleUpdateRequested = true;
494
+ vrender.vglobal.getRequestAnimationFrame()(() => {
495
+ this.styleUpdateQueue.forEach((changes, id) => {
496
+ var _a, _b;
497
+ const container = (_b = (_a = this.htmlMap) === null || _a === void 0 ? void 0 : _a[id]) === null || _b === void 0 ? void 0 : _b.wrapContainer;
498
+ if (container) {
499
+ Object.assign(container.style, changes);
500
+ }
501
+ });
502
+ this.styleUpdateQueue.clear();
503
+ this.styleUpdateRequested = false;
504
+ });
505
+ }
506
+ }
507
+ /**
508
+ * @description: 转换单元格样式
509
+ * @param {IGraphic} graphic
510
+ * @return {*}
511
+ */
512
+ convertCellStyle(graphic) {
513
+ var _a;
514
+ const { col, row, stage } = getTargetGroup(graphic);
515
+ const style = (_a = stage === null || stage === void 0 ? void 0 : stage.table) === null || _a === void 0 ? void 0 : _a.getCellStyle(col, row);
516
+ if (!vutils.isObject(style)) {
517
+ return;
518
+ }
519
+ const _b = style, { lineHeight, padding } = _b, rest = __rest(_b, ["lineHeight", "padding"]);
520
+ // TODO 表格提供具体解析方法,暂时只解析padding
521
+ return Object.assign(Object.assign({}, rest), { padding: vutils.isArray(padding) ? padding.map(value => `${value}px`).join(' ') : padding });
522
+ }
523
+ /**
524
+ * @description: 位置计算
525
+ * @param {IGraphic} graphic
526
+ * @param {string} anchorType
527
+ * @return {*}
528
+ */
529
+ calculatePosition(graphic, anchorType) {
530
+ const bounds = graphic.globalAABBBounds;
531
+ if (anchorType === 'position' || bounds.empty()) {
532
+ const matrix = graphic.globalTransMatrix;
533
+ return { x: matrix.e, y: matrix.f };
534
+ }
535
+ return vutils.calculateAnchorOfBounds(bounds, anchorType || 'top-left');
536
+ }
537
+ /**
538
+ * @description: 偏移计算
539
+ * @param {IStage} stage
540
+ * @param {HTMLElement} nativeContainer
541
+ * @param {number} x
542
+ * @param {number} y
543
+ * @return {*}
544
+ */
545
+ calculateOffset(stage, nativeContainer, x, y) {
546
+ const containerTL = vrender.application.global.getElementTopLeft(nativeContainer, false);
547
+ const windowTL = stage.window.getTopLeft(false);
548
+ return {
549
+ left: x + windowTL.left - containerTL.left,
550
+ top: y + windowTL.top - containerTL.top
551
+ };
552
+ }
553
+ /**
554
+ * @description: 应用用户样式
555
+ * @param {SimpleDomStyleOptions & CommonDomOptions} options
556
+ * @param {Record<string, any>} baseStyle
557
+ * @param {Object} context
558
+ * @return {*}
559
+ */
560
+ applyUserStyles(options, baseStyle, context) {
561
+ if (vutils.isFunction(options.style)) {
562
+ const userStyle = options.style({
563
+ top: context.offsetTop,
564
+ left: context.offsetX,
565
+ width: context.graphic.globalAABBBounds.width(),
566
+ height: context.graphic.globalAABBBounds.height()
567
+ }, context.graphic, context.wrapContainer);
568
+ Object.assign(baseStyle, userStyle);
569
+ }
570
+ else if (vutils.isObject(options.style)) {
571
+ Object.assign(baseStyle, options.style);
572
+ }
573
+ else if (vutils.isString(options.style)) {
574
+ Object.assign(baseStyle, vutils.styleStringToObject(options.style));
575
+ }
576
+ }
577
+ }
578
+ /**
579
+ * @description: 检查冻结容器
580
+ * @param {IGraphic} graphic
581
+ * @return {*}
582
+ */
583
+ function checkFrozenContainer(graphic) {
584
+ var _a;
585
+ const { col, row, stage } = getTargetGroup(graphic);
586
+ // @ts-ignore
587
+ let container = (_a = graphic.attribute.vue) === null || _a === void 0 ? void 0 : _a.container;
588
+ const { table } = stage;
589
+ if (container === table.bodyDomContainer) {
590
+ if (col < table.frozenColCount && row >= table.rowCount - table.bottomFrozenRowCount) {
591
+ container = table.bottomFrozenBodyDomContainer;
592
+ }
593
+ else if (col >= table.colCount - table.rightFrozenColCount &&
594
+ row >= table.rowCount - table.bottomFrozenRowCount) {
595
+ container = table.rightFrozenBottomDomContainer;
596
+ }
597
+ else if (row >= table.rowCount - table.bottomFrozenRowCount) {
598
+ container = table.bottomFrozenBodyDomContainer;
599
+ }
600
+ else if (col < table.frozenColCount) {
601
+ container = table.frozenBodyDomContainer;
602
+ }
603
+ else if (col >= table.colCount - table.rightFrozenColCount) {
604
+ container = table.rightFrozenBodyDomContainer;
605
+ }
606
+ }
607
+ else if (container === table.headerDomContainer) {
608
+ if (col < table.frozenColCount) {
609
+ container = table.frozenHeaderDomContainer;
610
+ }
611
+ else if (col >= table.colCount - table.rightFrozenColCount) {
612
+ container = table.rightFrozenHeaderDomContainer;
613
+ }
614
+ }
615
+ return container;
616
+ }
617
+ /**
618
+ * @description: 获取目标组
619
+ * @param {any} target
620
+ * @return {*}
621
+ */
622
+ function getTargetGroup(target) {
623
+ while (target === null || target === void 0 ? void 0 : target.parent) {
624
+ if (target.name === VTable.CUSTOM_CONTAINER_NAME || (target.name || '').startsWith(VTable.CUSTOM_MERGE_PRE_NAME)) {
625
+ return target;
626
+ }
627
+ target = target.parent;
628
+ }
629
+ return { col: -1, row: -1, stage: null };
416
630
  }
417
631
 
418
632
  exports.VTableVueAttributePlugin = VTableVueAttributePlugin;