@visactor/vtable-plugins 1.11.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.
@@ -0,0 +1,350 @@
1
+ (function (global, factory) {
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@visactor/vtable/es/vrender'), require('@visactor/vtable/es/tools/cell-range'), require('@visactor/vtable/es/tools/helper')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', '@visactor/vtable/es/vrender', '@visactor/vtable/es/tools/cell-range', '@visactor/vtable/es/tools/helper'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.VTable = global.VTable || {}, global.VTable.plugins = {}), global.vrender, global.cellRange, global.helper));
5
+ })(this, (function (exports, vrender, cellRange, helper) { 'use strict';
6
+
7
+ class CarouselAnimationPlugin {
8
+ table;
9
+ rowCount;
10
+ colCount;
11
+ animationDuration;
12
+ animationDelay;
13
+ animationEasing;
14
+ replaceScrollAction;
15
+ playing;
16
+ row;
17
+ col;
18
+ willUpdateRow = false;
19
+ willUpdateCol = false;
20
+ customDistRowFunction;
21
+ customDistColFunction;
22
+ constructor(table, options) {
23
+ this.table = table;
24
+ this.rowCount = options?.rowCount ?? undefined;
25
+ this.colCount = options?.colCount ?? undefined;
26
+ this.animationDuration = options?.animationDuration ?? 500;
27
+ this.animationDelay = options?.animationDelay ?? 1000;
28
+ this.animationEasing = options?.animationEasing ?? 'linear';
29
+ this.replaceScrollAction = options?.replaceScrollAction ?? false;
30
+ this.customDistColFunction = options.customDistColFunction;
31
+ this.customDistRowFunction = options.customDistRowFunction;
32
+ this.reset();
33
+ this.init();
34
+ }
35
+ init() {
36
+ if (this.replaceScrollAction) {
37
+ this.table.disableScroll();
38
+ this.table.scenegraph.stage.addEventListener('wheel', this.onScrollEnd.bind(this));
39
+ }
40
+ }
41
+ reset() {
42
+ this.playing = false;
43
+ this.row = this.table.frozenRowCount;
44
+ this.col = this.table.frozenColCount;
45
+ }
46
+ onScrollEnd(e) {
47
+ if (this.rowCount) {
48
+ if (e.deltaY > 0) {
49
+ this.row += this.rowCount;
50
+ this.row = Math.min(this.row, this.table.rowCount - this.table.frozenRowCount);
51
+ }
52
+ else if (e.deltaY < 0) {
53
+ this.row -= this.rowCount;
54
+ this.row = Math.max(this.row, this.table.frozenRowCount);
55
+ }
56
+ this.table.scrollToRow(this.row, { duration: this.animationDuration, easing: this.animationEasing });
57
+ }
58
+ else if (this.colCount) {
59
+ if (e.deltaX > 0) {
60
+ this.col += this.colCount;
61
+ this.col = Math.min(this.col, this.table.colCount - this.table.frozenColCount);
62
+ }
63
+ else if (e.deltaX < 0) {
64
+ this.col -= this.colCount;
65
+ this.col = Math.max(this.col, this.table.frozenColCount);
66
+ }
67
+ this.table.scrollToCol(this.col, { duration: this.animationDuration, easing: this.animationEasing });
68
+ }
69
+ }
70
+ play() {
71
+ this.playing = true;
72
+ if (this.rowCount && !this.willUpdateRow) {
73
+ this.updateRow();
74
+ }
75
+ else if (this.colCount && !this.willUpdateCol) {
76
+ this.updateCol();
77
+ }
78
+ }
79
+ pause() {
80
+ this.playing = false;
81
+ }
82
+ updateRow() {
83
+ if (!this.playing || this.table.isReleased) {
84
+ return;
85
+ }
86
+ let animation = true;
87
+ const customRow = this.customDistRowFunction && this.customDistRowFunction(this.row, this.table);
88
+ if (customRow) {
89
+ this.row = customRow.distRow;
90
+ animation = customRow.animation ?? true;
91
+ }
92
+ else if (this.table.scenegraph.proxy.screenTopRow !== this.row) {
93
+ this.row = this.table.frozenRowCount;
94
+ animation = false;
95
+ }
96
+ else {
97
+ this.row += this.rowCount;
98
+ }
99
+ this.table.scrollToRow(this.row, animation ? { duration: this.animationDuration, easing: this.animationEasing } : undefined);
100
+ this.willUpdateRow = true;
101
+ setTimeout(() => {
102
+ this.willUpdateRow = false;
103
+ this.updateRow();
104
+ }, this.animationDuration + this.animationDelay);
105
+ }
106
+ updateCol() {
107
+ if (!this.playing || this.table.isReleased) {
108
+ return;
109
+ }
110
+ let animation = true;
111
+ const customCol = this.customDistColFunction && this.customDistColFunction(this.col, this.table);
112
+ if (customCol) {
113
+ this.col = customCol.distCol;
114
+ animation = customCol.animation ?? true;
115
+ }
116
+ else if (this.table.scenegraph.proxy.screenLeftCol !== this.col) {
117
+ this.col = this.table.frozenColCount;
118
+ animation = false;
119
+ }
120
+ else {
121
+ this.col += this.colCount;
122
+ }
123
+ this.table.scrollToCol(this.col, animation ? { duration: this.animationDuration, easing: this.animationEasing } : undefined);
124
+ this.willUpdateCol = true;
125
+ setTimeout(() => {
126
+ this.willUpdateCol = false;
127
+ this.updateCol();
128
+ }, this.animationDuration + this.animationDelay);
129
+ }
130
+ }
131
+
132
+ class InvertHighlightPlugin {
133
+ table;
134
+ range;
135
+ _fill;
136
+ _opacity;
137
+ constructor(table, options) {
138
+ this.table = table;
139
+ this._fill = options?.fill ?? '#000';
140
+ this._opacity = options?.opacity ?? 0.5;
141
+ }
142
+ setInvertHighlightRange(range) {
143
+ if (cellRange.isSameRange(this.range, range)) {
144
+ return;
145
+ }
146
+ this.range = range;
147
+ if (!range) {
148
+ this.deleteAllCellGroupShadow();
149
+ }
150
+ else {
151
+ this.updateCellGroupShadow();
152
+ }
153
+ this.table.scenegraph.updateNextFrame();
154
+ }
155
+ deleteAllCellGroupShadow() {
156
+ if (!this.table.isPivotTable()) {
157
+ this.updateCellGroupShadowInContainer(this.table.scenegraph.rowHeaderGroup);
158
+ this.updateCellGroupShadowInContainer(this.table.scenegraph.leftBottomCornerGroup);
159
+ }
160
+ this.updateCellGroupShadowInContainer(this.table.scenegraph.bodyGroup);
161
+ this.updateCellGroupShadowInContainer(this.table.scenegraph.rightFrozenGroup);
162
+ this.updateCellGroupShadowInContainer(this.table.scenegraph.bottomFrozenGroup);
163
+ this.updateCellGroupShadowInContainer(this.table.scenegraph.rightBottomCornerGroup);
164
+ }
165
+ updateCellGroupShadow() {
166
+ if (!this.table.isPivotTable()) {
167
+ this.updateCellGroupShadowInContainer(this.table.scenegraph.rowHeaderGroup, this.range);
168
+ this.updateCellGroupShadowInContainer(this.table.scenegraph.leftBottomCornerGroup, this.range);
169
+ }
170
+ this.updateCellGroupShadowInContainer(this.table.scenegraph.bodyGroup, this.range);
171
+ this.updateCellGroupShadowInContainer(this.table.scenegraph.rightFrozenGroup, this.range);
172
+ this.updateCellGroupShadowInContainer(this.table.scenegraph.bottomFrozenGroup), this.range;
173
+ this.updateCellGroupShadowInContainer(this.table.scenegraph.rightBottomCornerGroup, this.range);
174
+ }
175
+ updateCellGroupShadowInContainer(container, range) {
176
+ container.forEachChildrenSkipChild((item) => {
177
+ const column = item;
178
+ if (column.role === 'column') {
179
+ column.forEachChildrenSkipChild((item) => {
180
+ const cell = item;
181
+ if (cell.role !== 'cell') {
182
+ return;
183
+ }
184
+ cell.attachShadow(cell.shadowRoot);
185
+ const shadowGroup = cell.shadowRoot;
186
+ if (!range) {
187
+ shadowGroup.removeAllChild();
188
+ }
189
+ else if (helper.cellInRange(range, cell.col, cell.row)) {
190
+ shadowGroup.removeAllChild();
191
+ }
192
+ else if (!shadowGroup.firstChild) {
193
+ const shadowRect = vrender.createRect({
194
+ x: 0,
195
+ y: 0,
196
+ width: cell.attribute.width,
197
+ height: cell.attribute.height,
198
+ fill: this._fill,
199
+ opacity: this._opacity
200
+ });
201
+ shadowRect.name = 'shadow-rect';
202
+ shadowGroup.appendChild(shadowRect);
203
+ }
204
+ });
205
+ }
206
+ });
207
+ }
208
+ }
209
+
210
+ class HeaderHighlightPlugin {
211
+ table;
212
+ options;
213
+ colHeaderRange;
214
+ rowHeaderRange;
215
+ constructor(table, options) {
216
+ this.table = table;
217
+ this.options = options;
218
+ this.registerStyle();
219
+ this.bindEvent();
220
+ }
221
+ registerStyle() {
222
+ this.table.registerCustomCellStyle('col-highlight', {
223
+ bgColor: this.options?.colHighlightBGColor ?? '#82b2f5',
224
+ color: this.options?.colHighlightColor ?? '#FFF'
225
+ });
226
+ this.table.registerCustomCellStyle('row-highlight', {
227
+ bgColor: this.options?.rowHighlightBGColor ?? '#82b2f5',
228
+ color: this.options?.rowHighlightColor ?? '#FFF'
229
+ });
230
+ }
231
+ bindEvent() {
232
+ this.table.on('selected_cell', e => {
233
+ this.updateHighlight();
234
+ });
235
+ this.table.on('selected_clear', () => {
236
+ this.clearHighlight();
237
+ });
238
+ this.table.on('mousemove_table', () => {
239
+ if (this.table.stateManager.select.selecting) {
240
+ this.updateHighlight();
241
+ }
242
+ });
243
+ }
244
+ clearHighlight() {
245
+ this.colHeaderRange && this.table.arrangeCustomCellStyle({ range: this.colHeaderRange }, undefined);
246
+ this.rowHeaderRange && this.table.arrangeCustomCellStyle({ range: this.rowHeaderRange }, undefined);
247
+ this.colHeaderRange = undefined;
248
+ this.rowHeaderRange = undefined;
249
+ }
250
+ updateHighlight() {
251
+ if (this.options?.colHighlight === false && this.options?.rowHighlight === false) {
252
+ return;
253
+ }
254
+ const selectRanges = this.table.getSelectedCellRanges();
255
+ if (selectRanges.length === 0) {
256
+ this.clearHighlight();
257
+ return;
258
+ }
259
+ const selectRange = selectRanges[0];
260
+ const rowSelectRange = [selectRange.start.row, selectRange.end.row];
261
+ rowSelectRange.sort((a, b) => a - b);
262
+ const colSelectRange = [selectRange.start.col, selectRange.end.col];
263
+ colSelectRange.sort((a, b) => a - b);
264
+ let colHeaderRange;
265
+ let rowHeaderRange;
266
+ if (this.table.isPivotTable()) {
267
+ colHeaderRange = {
268
+ start: {
269
+ col: colSelectRange[0],
270
+ row: 0
271
+ },
272
+ end: {
273
+ col: colSelectRange[1],
274
+ row: this.table.columnHeaderLevelCount - 1
275
+ }
276
+ };
277
+ rowHeaderRange = {
278
+ start: {
279
+ col: 0,
280
+ row: rowSelectRange[0]
281
+ },
282
+ end: {
283
+ col: this.table.rowHeaderLevelCount - 1,
284
+ row: rowSelectRange[1]
285
+ }
286
+ };
287
+ }
288
+ else if (this.table.internalProps.transpose) {
289
+ rowHeaderRange = {
290
+ start: {
291
+ col: 0,
292
+ row: rowSelectRange[0]
293
+ },
294
+ end: {
295
+ col: this.table.rowHeaderLevelCount - 1,
296
+ row: rowSelectRange[1]
297
+ }
298
+ };
299
+ }
300
+ else {
301
+ colHeaderRange = {
302
+ start: {
303
+ col: colSelectRange[0],
304
+ row: 0
305
+ },
306
+ end: {
307
+ col: colSelectRange[1],
308
+ row: this.table.columnHeaderLevelCount - 1
309
+ }
310
+ };
311
+ if (this.table.internalProps.rowSeriesNumber) {
312
+ rowHeaderRange = {
313
+ start: {
314
+ col: 0,
315
+ row: rowSelectRange[0]
316
+ },
317
+ end: {
318
+ col: 0,
319
+ row: rowSelectRange[1]
320
+ }
321
+ };
322
+ }
323
+ }
324
+ if (this.options?.colHighlight !== false && !isSameRange(this.colHeaderRange, colHeaderRange)) {
325
+ this.colHeaderRange && this.table.arrangeCustomCellStyle({ range: this.colHeaderRange }, undefined);
326
+ colHeaderRange && this.table.arrangeCustomCellStyle({ range: colHeaderRange }, 'col-highlight');
327
+ this.colHeaderRange = colHeaderRange;
328
+ }
329
+ if (this.options?.rowHighlight !== false && !isSameRange(this.rowHeaderRange, rowHeaderRange)) {
330
+ this.rowHeaderRange && this.table.arrangeCustomCellStyle({ range: this.rowHeaderRange }, undefined);
331
+ rowHeaderRange && this.table.arrangeCustomCellStyle({ range: rowHeaderRange }, 'row-highlight');
332
+ this.rowHeaderRange = rowHeaderRange;
333
+ }
334
+ }
335
+ }
336
+ function isSameRange(a, b) {
337
+ if (a === undefined && b === undefined) {
338
+ return true;
339
+ }
340
+ if (a === undefined || b === undefined) {
341
+ return false;
342
+ }
343
+ return (a.start.col === b.start.col && a.start.row === b.start.row && a.end.col === b.end.col && a.end.row === b.end.row);
344
+ }
345
+
346
+ exports.CarouselAnimationPlugin = CarouselAnimationPlugin;
347
+ exports.HeaderHighlightPlugin = HeaderHighlightPlugin;
348
+ exports.InvertHighlightPlugin = InvertHighlightPlugin;
349
+
350
+ }));
@@ -0,0 +1 @@
1
+ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@visactor/vtable/es/vrender"),require("@visactor/vtable/es/tools/cell-range"),require("@visactor/vtable/es/tools/helper")):"function"==typeof define&&define.amd?define(["exports","@visactor/vtable/es/vrender","@visactor/vtable/es/tools/cell-range","@visactor/vtable/es/tools/helper"],e):e(((t="undefined"!=typeof globalThis?globalThis:t||self).VTable=t.VTable||{},t.VTable.plugins={}),t.vrender,t.cellRange,t.helper)}(this,(function(t,e,o,i){"use strict";function l(t,e){return void 0===t&&void 0===e||void 0!==t&&void 0!==e&&(t.start.col===e.start.col&&t.start.row===e.start.row&&t.end.col===e.end.col&&t.end.row===e.end.row)}t.CarouselAnimationPlugin=class{table;rowCount;colCount;animationDuration;animationDelay;animationEasing;replaceScrollAction;playing;row;col;willUpdateRow=!1;willUpdateCol=!1;customDistRowFunction;customDistColFunction;constructor(t,e){this.table=t,this.rowCount=e?.rowCount??void 0,this.colCount=e?.colCount??void 0,this.animationDuration=e?.animationDuration??500,this.animationDelay=e?.animationDelay??1e3,this.animationEasing=e?.animationEasing??"linear",this.replaceScrollAction=e?.replaceScrollAction??!1,this.customDistColFunction=e.customDistColFunction,this.customDistRowFunction=e.customDistRowFunction,this.reset(),this.init()}init(){this.replaceScrollAction&&(this.table.disableScroll(),this.table.scenegraph.stage.addEventListener("wheel",this.onScrollEnd.bind(this)))}reset(){this.playing=!1,this.row=this.table.frozenRowCount,this.col=this.table.frozenColCount}onScrollEnd(t){this.rowCount?(t.deltaY>0?(this.row+=this.rowCount,this.row=Math.min(this.row,this.table.rowCount-this.table.frozenRowCount)):t.deltaY<0&&(this.row-=this.rowCount,this.row=Math.max(this.row,this.table.frozenRowCount)),this.table.scrollToRow(this.row,{duration:this.animationDuration,easing:this.animationEasing})):this.colCount&&(t.deltaX>0?(this.col+=this.colCount,this.col=Math.min(this.col,this.table.colCount-this.table.frozenColCount)):t.deltaX<0&&(this.col-=this.colCount,this.col=Math.max(this.col,this.table.frozenColCount)),this.table.scrollToCol(this.col,{duration:this.animationDuration,easing:this.animationEasing}))}play(){this.playing=!0,this.rowCount&&!this.willUpdateRow?this.updateRow():this.colCount&&!this.willUpdateCol&&this.updateCol()}pause(){this.playing=!1}updateRow(){if(!this.playing||this.table.isReleased)return;let t=!0;const e=this.customDistRowFunction&&this.customDistRowFunction(this.row,this.table);e?(this.row=e.distRow,t=e.animation??!0):this.table.scenegraph.proxy.screenTopRow!==this.row?(this.row=this.table.frozenRowCount,t=!1):this.row+=this.rowCount,this.table.scrollToRow(this.row,t?{duration:this.animationDuration,easing:this.animationEasing}:void 0),this.willUpdateRow=!0,setTimeout((()=>{this.willUpdateRow=!1,this.updateRow()}),this.animationDuration+this.animationDelay)}updateCol(){if(!this.playing||this.table.isReleased)return;let t=!0;const e=this.customDistColFunction&&this.customDistColFunction(this.col,this.table);e?(this.col=e.distCol,t=e.animation??!0):this.table.scenegraph.proxy.screenLeftCol!==this.col?(this.col=this.table.frozenColCount,t=!1):this.col+=this.colCount,this.table.scrollToCol(this.col,t?{duration:this.animationDuration,easing:this.animationEasing}:void 0),this.willUpdateCol=!0,setTimeout((()=>{this.willUpdateCol=!1,this.updateCol()}),this.animationDuration+this.animationDelay)}},t.HeaderHighlightPlugin=class{table;options;colHeaderRange;rowHeaderRange;constructor(t,e){this.table=t,this.options=e,this.registerStyle(),this.bindEvent()}registerStyle(){this.table.registerCustomCellStyle("col-highlight",{bgColor:this.options?.colHighlightBGColor??"#82b2f5",color:this.options?.colHighlightColor??"#FFF"}),this.table.registerCustomCellStyle("row-highlight",{bgColor:this.options?.rowHighlightBGColor??"#82b2f5",color:this.options?.rowHighlightColor??"#FFF"})}bindEvent(){this.table.on("selected_cell",(t=>{this.updateHighlight()})),this.table.on("selected_clear",(()=>{this.clearHighlight()})),this.table.on("mousemove_table",(()=>{this.table.stateManager.select.selecting&&this.updateHighlight()}))}clearHighlight(){this.colHeaderRange&&this.table.arrangeCustomCellStyle({range:this.colHeaderRange},void 0),this.rowHeaderRange&&this.table.arrangeCustomCellStyle({range:this.rowHeaderRange},void 0),this.colHeaderRange=void 0,this.rowHeaderRange=void 0}updateHighlight(){if(!1===this.options?.colHighlight&&!1===this.options?.rowHighlight)return;const t=this.table.getSelectedCellRanges();if(0===t.length)return void this.clearHighlight();const e=t[0],o=[e.start.row,e.end.row];o.sort(((t,e)=>t-e));const i=[e.start.col,e.end.col];let a,s;i.sort(((t,e)=>t-e)),this.table.isPivotTable()?(a={start:{col:i[0],row:0},end:{col:i[1],row:this.table.columnHeaderLevelCount-1}},s={start:{col:0,row:o[0]},end:{col:this.table.rowHeaderLevelCount-1,row:o[1]}}):this.table.internalProps.transpose?s={start:{col:0,row:o[0]},end:{col:this.table.rowHeaderLevelCount-1,row:o[1]}}:(a={start:{col:i[0],row:0},end:{col:i[1],row:this.table.columnHeaderLevelCount-1}},this.table.internalProps.rowSeriesNumber&&(s={start:{col:0,row:o[0]},end:{col:0,row:o[1]}})),!1===this.options?.colHighlight||l(this.colHeaderRange,a)||(this.colHeaderRange&&this.table.arrangeCustomCellStyle({range:this.colHeaderRange},void 0),a&&this.table.arrangeCustomCellStyle({range:a},"col-highlight"),this.colHeaderRange=a),!1===this.options?.rowHighlight||l(this.rowHeaderRange,s)||(this.rowHeaderRange&&this.table.arrangeCustomCellStyle({range:this.rowHeaderRange},void 0),s&&this.table.arrangeCustomCellStyle({range:s},"row-highlight"),this.rowHeaderRange=s)}},t.InvertHighlightPlugin=class{table;range;_fill;_opacity;constructor(t,e){this.table=t,this._fill=e?.fill??"#000",this._opacity=e?.opacity??.5}setInvertHighlightRange(t){o.isSameRange(this.range,t)||(this.range=t,t?this.updateCellGroupShadow():this.deleteAllCellGroupShadow(),this.table.scenegraph.updateNextFrame())}deleteAllCellGroupShadow(){this.table.isPivotTable()||(this.updateCellGroupShadowInContainer(this.table.scenegraph.rowHeaderGroup),this.updateCellGroupShadowInContainer(this.table.scenegraph.leftBottomCornerGroup)),this.updateCellGroupShadowInContainer(this.table.scenegraph.bodyGroup),this.updateCellGroupShadowInContainer(this.table.scenegraph.rightFrozenGroup),this.updateCellGroupShadowInContainer(this.table.scenegraph.bottomFrozenGroup),this.updateCellGroupShadowInContainer(this.table.scenegraph.rightBottomCornerGroup)}updateCellGroupShadow(){this.table.isPivotTable()||(this.updateCellGroupShadowInContainer(this.table.scenegraph.rowHeaderGroup,this.range),this.updateCellGroupShadowInContainer(this.table.scenegraph.leftBottomCornerGroup,this.range)),this.updateCellGroupShadowInContainer(this.table.scenegraph.bodyGroup,this.range),this.updateCellGroupShadowInContainer(this.table.scenegraph.rightFrozenGroup,this.range),this.updateCellGroupShadowInContainer(this.table.scenegraph.bottomFrozenGroup),this.range,this.updateCellGroupShadowInContainer(this.table.scenegraph.rightBottomCornerGroup,this.range)}updateCellGroupShadowInContainer(t,o){t.forEachChildrenSkipChild((t=>{const l=t;"column"===l.role&&l.forEachChildrenSkipChild((t=>{const l=t;if("cell"!==l.role)return;l.attachShadow(l.shadowRoot);const a=l.shadowRoot;if(o){if(i.cellInRange(o,l.col,l.row))a.removeAllChild();else if(!a.firstChild){const t=e.createRect({x:0,y:0,width:l.attribute.width,height:l.attribute.height,fill:this._fill,opacity:this._opacity});t.name="shadow-rect",a.appendChild(t)}}else a.removeAllChild()}))}))}}}));
@@ -0,0 +1,48 @@
1
+ import type { EasingType } from '@visactor/vtable/es/vrender';
2
+ import type { BaseTableAPI } from '@visactor/vtable/es/ts-types/base-table';
3
+ export interface ICarouselAnimationPluginOptions {
4
+ rowCount?: number;
5
+ colCount?: number;
6
+ animationDuration?: number;
7
+ animationDelay?: number;
8
+ animationEasing?: EasingType;
9
+ replaceScrollAction?: boolean;
10
+ customDistRowFunction?: (row: number, table: BaseTableAPI) => {
11
+ distRow: number;
12
+ animation?: boolean;
13
+ } | undefined;
14
+ customDistColFunction?: (col: number, table: BaseTableAPI) => {
15
+ distCol: number;
16
+ animation?: boolean;
17
+ } | undefined;
18
+ }
19
+ export declare class CarouselAnimationPlugin {
20
+ table: BaseTableAPI;
21
+ rowCount: number;
22
+ colCount: number;
23
+ animationDuration: number;
24
+ animationDelay: number;
25
+ animationEasing: EasingType;
26
+ replaceScrollAction: boolean;
27
+ playing: boolean;
28
+ row: number;
29
+ col: number;
30
+ willUpdateRow: boolean;
31
+ willUpdateCol: boolean;
32
+ customDistRowFunction?: (row: number, table: BaseTableAPI) => {
33
+ distRow: number;
34
+ animation?: boolean;
35
+ } | undefined;
36
+ customDistColFunction?: (col: number, table: BaseTableAPI) => {
37
+ distCol: number;
38
+ animation?: boolean;
39
+ } | undefined;
40
+ constructor(table: BaseTableAPI, options?: ICarouselAnimationPluginOptions);
41
+ init(): void;
42
+ reset(): void;
43
+ onScrollEnd(e: Event): void;
44
+ play(): void;
45
+ pause(): void;
46
+ updateRow(): void;
47
+ updateCol(): void;
48
+ }
@@ -0,0 +1,62 @@
1
+ export class CarouselAnimationPlugin {
2
+ constructor(table, options) {
3
+ var _a, _b, _c, _d, _e, _f;
4
+ this.willUpdateRow = !1, this.willUpdateCol = !1, this.table = table, this.rowCount = null !== (_a = null == options ? void 0 : options.rowCount) && void 0 !== _a ? _a : void 0,
5
+ this.colCount = null !== (_b = null == options ? void 0 : options.colCount) && void 0 !== _b ? _b : void 0,
6
+ this.animationDuration = null !== (_c = null == options ? void 0 : options.animationDuration) && void 0 !== _c ? _c : 500,
7
+ this.animationDelay = null !== (_d = null == options ? void 0 : options.animationDelay) && void 0 !== _d ? _d : 1e3,
8
+ this.animationEasing = null !== (_e = null == options ? void 0 : options.animationEasing) && void 0 !== _e ? _e : "linear",
9
+ this.replaceScrollAction = null !== (_f = null == options ? void 0 : options.replaceScrollAction) && void 0 !== _f && _f,
10
+ this.customDistColFunction = options.customDistColFunction, this.customDistRowFunction = options.customDistRowFunction,
11
+ this.reset(), this.init();
12
+ }
13
+ init() {
14
+ this.replaceScrollAction && (this.table.disableScroll(), this.table.scenegraph.stage.addEventListener("wheel", this.onScrollEnd.bind(this)));
15
+ }
16
+ reset() {
17
+ this.playing = !1, this.row = this.table.frozenRowCount, this.col = this.table.frozenColCount;
18
+ }
19
+ onScrollEnd(e) {
20
+ this.rowCount ? (e.deltaY > 0 ? (this.row += this.rowCount, this.row = Math.min(this.row, this.table.rowCount - this.table.frozenRowCount)) : e.deltaY < 0 && (this.row -= this.rowCount,
21
+ this.row = Math.max(this.row, this.table.frozenRowCount)), this.table.scrollToRow(this.row, {
22
+ duration: this.animationDuration,
23
+ easing: this.animationEasing
24
+ })) : this.colCount && (e.deltaX > 0 ? (this.col += this.colCount, this.col = Math.min(this.col, this.table.colCount - this.table.frozenColCount)) : e.deltaX < 0 && (this.col -= this.colCount,
25
+ this.col = Math.max(this.col, this.table.frozenColCount)), this.table.scrollToCol(this.col, {
26
+ duration: this.animationDuration,
27
+ easing: this.animationEasing
28
+ }));
29
+ }
30
+ play() {
31
+ this.playing = !0, this.rowCount && !this.willUpdateRow ? this.updateRow() : this.colCount && !this.willUpdateCol && this.updateCol();
32
+ }
33
+ pause() {
34
+ this.playing = !1;
35
+ }
36
+ updateRow() {
37
+ var _a;
38
+ if (!this.playing || this.table.isReleased) return;
39
+ let animation = !0;
40
+ const customRow = this.customDistRowFunction && this.customDistRowFunction(this.row, this.table);
41
+ customRow ? (this.row = customRow.distRow, animation = null === (_a = customRow.animation) || void 0 === _a || _a) : this.table.scenegraph.proxy.screenTopRow !== this.row ? (this.row = this.table.frozenRowCount,
42
+ animation = !1) : this.row += this.rowCount, this.table.scrollToRow(this.row, animation ? {
43
+ duration: this.animationDuration,
44
+ easing: this.animationEasing
45
+ } : void 0), this.willUpdateRow = !0, setTimeout((() => {
46
+ this.willUpdateRow = !1, this.updateRow();
47
+ }), this.animationDuration + this.animationDelay);
48
+ }
49
+ updateCol() {
50
+ var _a;
51
+ if (!this.playing || this.table.isReleased) return;
52
+ let animation = !0;
53
+ const customCol = this.customDistColFunction && this.customDistColFunction(this.col, this.table);
54
+ customCol ? (this.col = customCol.distCol, animation = null === (_a = customCol.animation) || void 0 === _a || _a) : this.table.scenegraph.proxy.screenLeftCol !== this.col ? (this.col = this.table.frozenColCount,
55
+ animation = !1) : this.col += this.colCount, this.table.scrollToCol(this.col, animation ? {
56
+ duration: this.animationDuration,
57
+ easing: this.animationEasing
58
+ } : void 0), this.willUpdateCol = !0, setTimeout((() => {
59
+ this.willUpdateCol = !1, this.updateCol();
60
+ }), this.animationDuration + this.animationDelay);
61
+ }
62
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["carousel-animation.ts"],"names":[],"mappings":"AAeA,MAAM,OAAO,uBAAuB;IAkBlC,YAAY,KAAmB,EAAE,OAAyC;;QAL1E,kBAAa,GAAY,KAAK,CAAC;QAC/B,kBAAa,GAAY,KAAK,CAAC;QAK7B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QAEnB,IAAI,CAAC,QAAQ,GAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,QAAQ,mCAAI,SAAS,CAAC;QAC/C,IAAI,CAAC,QAAQ,GAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,QAAQ,mCAAI,SAAS,CAAC;QAC/C,IAAI,CAAC,iBAAiB,GAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,iBAAiB,mCAAI,GAAG,CAAC;QAC3D,IAAI,CAAC,cAAc,GAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,cAAc,mCAAI,IAAI,CAAC;QACtD,IAAI,CAAC,eAAe,GAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,eAAe,mCAAI,QAAQ,CAAC;QAC5D,IAAI,CAAC,mBAAmB,GAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,mBAAmB,mCAAI,KAAK,CAAC;QAEjE,IAAI,CAAC,qBAAqB,GAAG,OAAO,CAAC,qBAAqB,CAAC;QAC3D,IAAI,CAAC,qBAAqB,GAAG,OAAO,CAAC,qBAAqB,CAAC;QAE3D,IAAI,CAAC,KAAK,EAAE,CAAC;QACb,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jG,IAAI,SAAS,EAAE;YACb,IAAI,CAAC,GAAG,GAAG,SAAS,CAAC,OAAO,CAAC;YAC7B,SAAS,GAAG,MAAA,SAAS,CAAC,SAAS,mCAAI,IAAI,CAAC;SACzC;aAAM,IAAI,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,aAAa,KAAK,IAAI,CAAC,GAAG,EAAE;YACjE,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC;YACrC,SAAS,GAAG,KAAK,CAAC;SACnB;aAAM;YACL,IAAI,CAAC,GAAG,IAAI,IAAI,CAAC,QAAQ,CAAC;SAC3B;QAED,IAAI,CAAC,KAAK,CAAC,WAAW,CACpB,IAAI,CAAC,GAAG,EACR,SAAS,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,IAAI,CAAC,iBAAiB,EAAE,MAAM,EAAE,IAAI,CAAC,eAAe,EAAE,CAAC,CAAC,CAAC,SAAS,CAC3F,CAAC;QAEF,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;QAC1B,UAAU,CACR,GAAG,EAAE;YACH,IAAI,CAAC,aAAa,GAAG,KAAK,CAAC;YAC3B,IAAI,CAAC,SAAS,EAAE,CAAC;QACnB,CAAC,EAED,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC,cAAc,CAC7C,CAAC;IACJ,CAAC;CACF","file":"carousel-animation.js","sourcesContent":["import type { EasingType } from '@visactor/vtable/es/vrender';\nimport type { BaseTableAPI } from '@visactor/vtable/es/ts-types/base-table';\n\nexport interface ICarouselAnimationPluginOptions {\n rowCount?: number;\n colCount?: number;\n animationDuration?: number;\n animationDelay?: number;\n animationEasing?: EasingType;\n replaceScrollAction?: boolean;\n\n customDistRowFunction?: (row: number, table: BaseTableAPI) => { distRow: number; animation?: boolean } | undefined;\n customDistColFunction?: (col: number, table: BaseTableAPI) => { distCol: number; animation?: boolean } | undefined;\n}\n\nexport class CarouselAnimationPlugin {\n table: BaseTableAPI;\n\n rowCount: number;\n colCount: number;\n animationDuration: number;\n animationDelay: number;\n animationEasing: EasingType;\n replaceScrollAction: boolean;\n\n playing: boolean;\n row: number;\n col: number;\n willUpdateRow: boolean = false;\n willUpdateCol: boolean = false;\n\n customDistRowFunction?: (row: number, table: BaseTableAPI) => { distRow: number; animation?: boolean } | undefined;\n customDistColFunction?: (col: number, table: BaseTableAPI) => { distCol: number; animation?: boolean } | undefined;\n constructor(table: BaseTableAPI, options?: ICarouselAnimationPluginOptions) {\n this.table = table;\n\n this.rowCount = options?.rowCount ?? undefined;\n this.colCount = options?.colCount ?? undefined;\n this.animationDuration = options?.animationDuration ?? 500;\n this.animationDelay = options?.animationDelay ?? 1000;\n this.animationEasing = options?.animationEasing ?? 'linear';\n this.replaceScrollAction = options?.replaceScrollAction ?? false;\n\n this.customDistColFunction = options.customDistColFunction;\n this.customDistRowFunction = options.customDistRowFunction;\n\n this.reset();\n this.init();\n }\n\n init() {\n if (this.replaceScrollAction) {\n this.table.disableScroll();\n\n this.table.scenegraph.stage.addEventListener('wheel', this.onScrollEnd.bind(this));\n }\n }\n\n reset() {\n this.playing = false;\n this.row = this.table.frozenRowCount;\n this.col = this.table.frozenColCount;\n }\n\n onScrollEnd(e: Event) {\n if (this.rowCount) {\n if ((e as any).deltaY > 0) {\n this.row += this.rowCount;\n this.row = Math.min(this.row, this.table.rowCount - this.table.frozenRowCount);\n } else if ((e as any).deltaY < 0) {\n this.row -= this.rowCount;\n this.row = Math.max(this.row, this.table.frozenRowCount);\n }\n this.table.scrollToRow(this.row, { duration: this.animationDuration, easing: this.animationEasing });\n } else if (this.colCount) {\n if ((e as any).deltaX > 0) {\n this.col += this.colCount;\n this.col = Math.min(this.col, this.table.colCount - this.table.frozenColCount);\n } else if ((e as any).deltaX < 0) {\n this.col -= this.colCount;\n this.col = Math.max(this.col, this.table.frozenColCount);\n }\n this.table.scrollToCol(this.col, { duration: this.animationDuration, easing: this.animationEasing });\n }\n }\n\n play() {\n this.playing = true;\n\n if (this.rowCount && !this.willUpdateRow) {\n this.updateRow();\n } else if (this.colCount && !this.willUpdateCol) {\n this.updateCol();\n }\n }\n\n pause() {\n this.playing = false;\n }\n\n updateRow() {\n if (!this.playing || this.table.isReleased) {\n return;\n }\n\n let animation = true;\n const customRow = this.customDistRowFunction && this.customDistRowFunction(this.row, this.table);\n if (customRow) {\n this.row = customRow.distRow;\n animation = customRow.animation ?? true;\n } else if (this.table.scenegraph.proxy.screenTopRow !== this.row) {\n this.row = this.table.frozenRowCount;\n animation = false;\n } else {\n this.row += this.rowCount;\n }\n this.table.scrollToRow(\n this.row,\n animation ? { duration: this.animationDuration, easing: this.animationEasing } : undefined\n );\n this.willUpdateRow = true;\n setTimeout(\n () => {\n this.willUpdateRow = false;\n this.updateRow();\n },\n // animation ? this.animationDuration + this.animationDelay : 0\n this.animationDuration + this.animationDelay\n );\n }\n\n updateCol() {\n if (!this.playing || this.table.isReleased) {\n return;\n }\n\n let animation = true;\n const customCol = this.customDistColFunction && this.customDistColFunction(this.col, this.table);\n if (customCol) {\n this.col = customCol.distCol;\n animation = customCol.animation ?? true;\n } else if (this.table.scenegraph.proxy.screenLeftCol !== this.col) {\n this.col = this.table.frozenColCount;\n animation = false;\n } else {\n this.col += this.colCount;\n }\n\n this.table.scrollToCol(\n this.col,\n animation ? { duration: this.animationDuration, easing: this.animationEasing } : undefined\n );\n\n this.willUpdateCol = true;\n setTimeout(\n () => {\n this.willUpdateCol = false;\n this.updateCol();\n },\n // animation ? this.animationDuration + this.animationDelay : 0\n this.animationDuration + this.animationDelay\n );\n }\n}\n"]}
@@ -0,0 +1,21 @@
1
+ import type { CellRange } from '@visactor/vtable/es/ts-types';
2
+ import type { BaseTableAPI } from '@visactor/vtable/es/ts-types/base-table';
3
+ export interface IHeaderHighlightPluginOptions {
4
+ rowHighlight?: boolean;
5
+ colHighlight?: boolean;
6
+ colHighlightBGColor?: string;
7
+ colHighlightColor?: string;
8
+ rowHighlightBGColor?: string;
9
+ rowHighlightColor?: string;
10
+ }
11
+ export declare class HeaderHighlightPlugin {
12
+ table: BaseTableAPI;
13
+ options: IHeaderHighlightPluginOptions;
14
+ colHeaderRange?: CellRange;
15
+ rowHeaderRange?: CellRange;
16
+ constructor(table: BaseTableAPI, options?: IHeaderHighlightPluginOptions);
17
+ registerStyle(): void;
18
+ bindEvent(): void;
19
+ clearHighlight(): void;
20
+ updateHighlight(): void;
21
+ }
@@ -0,0 +1,100 @@
1
+ export class HeaderHighlightPlugin {
2
+ constructor(table, options) {
3
+ this.table = table, this.options = options, this.registerStyle(), this.bindEvent();
4
+ }
5
+ registerStyle() {
6
+ var _a, _b, _c, _d, _e, _f, _g, _h;
7
+ this.table.registerCustomCellStyle("col-highlight", {
8
+ bgColor: null !== (_b = null === (_a = this.options) || void 0 === _a ? void 0 : _a.colHighlightBGColor) && void 0 !== _b ? _b : "#82b2f5",
9
+ color: null !== (_d = null === (_c = this.options) || void 0 === _c ? void 0 : _c.colHighlightColor) && void 0 !== _d ? _d : "#FFF"
10
+ }), this.table.registerCustomCellStyle("row-highlight", {
11
+ bgColor: null !== (_f = null === (_e = this.options) || void 0 === _e ? void 0 : _e.rowHighlightBGColor) && void 0 !== _f ? _f : "#82b2f5",
12
+ color: null !== (_h = null === (_g = this.options) || void 0 === _g ? void 0 : _g.rowHighlightColor) && void 0 !== _h ? _h : "#FFF"
13
+ });
14
+ }
15
+ bindEvent() {
16
+ this.table.on("selected_cell", (e => {
17
+ this.updateHighlight();
18
+ })), this.table.on("selected_clear", (() => {
19
+ this.clearHighlight();
20
+ })), this.table.on("mousemove_table", (() => {
21
+ this.table.stateManager.select.selecting && this.updateHighlight();
22
+ }));
23
+ }
24
+ clearHighlight() {
25
+ this.colHeaderRange && this.table.arrangeCustomCellStyle({
26
+ range: this.colHeaderRange
27
+ }, void 0), this.rowHeaderRange && this.table.arrangeCustomCellStyle({
28
+ range: this.rowHeaderRange
29
+ }, void 0), this.colHeaderRange = void 0, this.rowHeaderRange = void 0;
30
+ }
31
+ updateHighlight() {
32
+ var _a, _b, _c, _d;
33
+ if (!1 === (null === (_a = this.options) || void 0 === _a ? void 0 : _a.colHighlight) && !1 === (null === (_b = this.options) || void 0 === _b ? void 0 : _b.rowHighlight)) return;
34
+ const selectRanges = this.table.getSelectedCellRanges();
35
+ if (0 === selectRanges.length) return void this.clearHighlight();
36
+ const selectRange = selectRanges[0], rowSelectRange = [ selectRange.start.row, selectRange.end.row ];
37
+ rowSelectRange.sort(((a, b) => a - b));
38
+ const colSelectRange = [ selectRange.start.col, selectRange.end.col ];
39
+ let colHeaderRange, rowHeaderRange;
40
+ colSelectRange.sort(((a, b) => a - b)), this.table.isPivotTable() ? (colHeaderRange = {
41
+ start: {
42
+ col: colSelectRange[0],
43
+ row: 0
44
+ },
45
+ end: {
46
+ col: colSelectRange[1],
47
+ row: this.table.columnHeaderLevelCount - 1
48
+ }
49
+ }, rowHeaderRange = {
50
+ start: {
51
+ col: 0,
52
+ row: rowSelectRange[0]
53
+ },
54
+ end: {
55
+ col: this.table.rowHeaderLevelCount - 1,
56
+ row: rowSelectRange[1]
57
+ }
58
+ }) : this.table.internalProps.transpose ? rowHeaderRange = {
59
+ start: {
60
+ col: 0,
61
+ row: rowSelectRange[0]
62
+ },
63
+ end: {
64
+ col: this.table.rowHeaderLevelCount - 1,
65
+ row: rowSelectRange[1]
66
+ }
67
+ } : (colHeaderRange = {
68
+ start: {
69
+ col: colSelectRange[0],
70
+ row: 0
71
+ },
72
+ end: {
73
+ col: colSelectRange[1],
74
+ row: this.table.columnHeaderLevelCount - 1
75
+ }
76
+ }, this.table.internalProps.rowSeriesNumber && (rowHeaderRange = {
77
+ start: {
78
+ col: 0,
79
+ row: rowSelectRange[0]
80
+ },
81
+ end: {
82
+ col: 0,
83
+ row: rowSelectRange[1]
84
+ }
85
+ })), !1 === (null === (_c = this.options) || void 0 === _c ? void 0 : _c.colHighlight) || isSameRange(this.colHeaderRange, colHeaderRange) || (this.colHeaderRange && this.table.arrangeCustomCellStyle({
86
+ range: this.colHeaderRange
87
+ }, void 0), colHeaderRange && this.table.arrangeCustomCellStyle({
88
+ range: colHeaderRange
89
+ }, "col-highlight"), this.colHeaderRange = colHeaderRange), !1 === (null === (_d = this.options) || void 0 === _d ? void 0 : _d.rowHighlight) || isSameRange(this.rowHeaderRange, rowHeaderRange) || (this.rowHeaderRange && this.table.arrangeCustomCellStyle({
90
+ range: this.rowHeaderRange
91
+ }, void 0), rowHeaderRange && this.table.arrangeCustomCellStyle({
92
+ range: rowHeaderRange
93
+ }, "row-highlight"), this.rowHeaderRange = rowHeaderRange);
94
+ }
95
+ }
96
+
97
+ function isSameRange(a, b) {
98
+ return void 0 === a && void 0 === b || void 0 !== a && void 0 !== b && (a.start.col === b.start.col && a.start.row === b.start.row && a.end.col === b.end.col && a.end.row === b.end.row);
99
+ }
100
+ //# sourceMappingURL=header-highlight.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["header-highlight.ts"],"names":[],"mappings":"AAYA,MAAM,OAAO,qBAAqB;IAKhC,YAAY,KAAmB,EAAE,OAAuC;QACtE,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QAEvB,IAAI,CAAC,aAAa,EAAE,CAAC;QACrB,IAAI,CAAC,SAAS,EAAE,CAAC;IACnB,CAAC;IAED,aAAa;;QACX,IAAI,CAAC,KAAK,CAAC,uBAAuB,CAAC,eAAe,EAAE;YAClD,OAAO,EAAE,MAAA,MAAA,IAAI,CAAC,OAAO,0CAAE,mBAAmB,mCAAI,SAAS;YACvD,KAAK,EAAE,MAAA,MAAA,IAAI,CAAC,OAAO,0CAAE,iBAAiB,mCAAI,MAAM;SACjD,CAAC,CAAC;QAEH,IAAI,CAAC,KAAK,CAAC,uBAAuB,CAAC,eAAe,EAAE;YAClD,OAAO,EAAE,MAAA,MAAA,IAAI,CAAC,OAAO,0CAAE,mBAAmB,mCAAI,SAAS;YACvD,KAAK,EAAE,MAAA,M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,0CAAE,YAAY,MAAK,KAAK,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,cAAc,EAAE,cAAc,CAAC,EAAE;YAC7F,IAAI,CAAC,cAAc,IAAI,IAAI,CAAC,KAAK,CAAC,sBAAsB,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,cAAc,EAAE,EAAE,SAAS,CAAC,CAAC;YACpG,cAAc,IAAI,IAAI,CAAC,KAAK,CAAC,sBAAsB,CAAC,EAAE,KAAK,EAAE,cAAc,EAAE,EAAE,eAAe,CAAC,CAAC;YAChG,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;SACtC;IACH,CAAC;CACF;AAED,SAAS,WAAW,CAAC,CAAwB,EAAE,CAAwB;IACrE,IAAI,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,SAAS,EAAE;QACtC,OAAO,IAAI,CAAC;KACb;IAED,IAAI,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,SAAS,EAAE;QACtC,OAAO,KAAK,CAAC;KACd;IAED,OAAO,CACL,CAAC,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC,GAAG,CAAC,GAAG,CACjH,CAAC;AACJ,CAAC","file":"header-highlight.js","sourcesContent":["import type { CellRange } from '@visactor/vtable/es/ts-types';\nimport type { BaseTableAPI } from '@visactor/vtable/es/ts-types/base-table';\n\nexport interface IHeaderHighlightPluginOptions {\n rowHighlight?: boolean;\n colHighlight?: boolean;\n colHighlightBGColor?: string;\n colHighlightColor?: string;\n rowHighlightBGColor?: string;\n rowHighlightColor?: string;\n}\n\nexport class HeaderHighlightPlugin {\n table: BaseTableAPI;\n options: IHeaderHighlightPluginOptions;\n colHeaderRange?: CellRange;\n rowHeaderRange?: CellRange;\n constructor(table: BaseTableAPI, options?: IHeaderHighlightPluginOptions) {\n this.table = table;\n this.options = options;\n\n this.registerStyle();\n this.bindEvent();\n }\n\n registerStyle() {\n this.table.registerCustomCellStyle('col-highlight', {\n bgColor: this.options?.colHighlightBGColor ?? '#82b2f5',\n color: this.options?.colHighlightColor ?? '#FFF'\n });\n\n this.table.registerCustomCellStyle('row-highlight', {\n bgColor: this.options?.rowHighlightBGColor ?? '#82b2f5',\n color: this.options?.rowHighlightColor ?? '#FFF'\n });\n }\n\n bindEvent() {\n this.table.on('selected_cell', e => {\n this.updateHighlight();\n });\n\n this.table.on('selected_clear', () => {\n this.clearHighlight();\n });\n\n this.table.on('mousemove_table', () => {\n if (this.table.stateManager.select.selecting) {\n this.updateHighlight();\n }\n });\n }\n\n clearHighlight() {\n this.colHeaderRange && this.table.arrangeCustomCellStyle({ range: this.colHeaderRange }, undefined);\n this.rowHeaderRange && this.table.arrangeCustomCellStyle({ range: this.rowHeaderRange }, undefined);\n\n // clear range\n this.colHeaderRange = undefined;\n this.rowHeaderRange = undefined;\n }\n\n updateHighlight() {\n if (this.options?.colHighlight === false && this.options?.rowHighlight === false) {\n return;\n }\n const selectRanges = this.table.getSelectedCellRanges();\n if (selectRanges.length === 0) {\n this.clearHighlight();\n return;\n }\n\n const selectRange = selectRanges[0];\n const rowSelectRange = [selectRange.start.row, selectRange.end.row];\n rowSelectRange.sort((a, b) => a - b); // sort\n const colSelectRange = [selectRange.start.col, selectRange.end.col];\n colSelectRange.sort((a, b) => a - b); // sort\n\n let colHeaderRange: CellRange;\n let rowHeaderRange: CellRange;\n if (this.table.isPivotTable()) {\n colHeaderRange = {\n start: {\n col: colSelectRange[0],\n row: 0\n },\n end: {\n col: colSelectRange[1],\n row: this.table.columnHeaderLevelCount - 1\n }\n };\n rowHeaderRange = {\n start: {\n col: 0,\n row: rowSelectRange[0]\n },\n end: {\n col: this.table.rowHeaderLevelCount - 1,\n row: rowSelectRange[1]\n }\n };\n } else if (this.table.internalProps.transpose) {\n rowHeaderRange = {\n start: {\n col: 0,\n row: rowSelectRange[0]\n },\n end: {\n col: this.table.rowHeaderLevelCount - 1,\n row: rowSelectRange[1]\n }\n };\n } else {\n colHeaderRange = {\n start: {\n col: colSelectRange[0],\n row: 0\n },\n end: {\n col: colSelectRange[1],\n row: this.table.columnHeaderLevelCount - 1\n }\n };\n if (this.table.internalProps.rowSeriesNumber) {\n rowHeaderRange = {\n start: {\n col: 0,\n row: rowSelectRange[0]\n },\n end: {\n col: 0,\n row: rowSelectRange[1]\n }\n };\n }\n }\n\n if (this.options?.colHighlight !== false && !isSameRange(this.colHeaderRange, colHeaderRange)) {\n this.colHeaderRange && this.table.arrangeCustomCellStyle({ range: this.colHeaderRange }, undefined);\n colHeaderRange && this.table.arrangeCustomCellStyle({ range: colHeaderRange }, 'col-highlight');\n this.colHeaderRange = colHeaderRange;\n }\n\n if (this.options?.rowHighlight !== false && !isSameRange(this.rowHeaderRange, rowHeaderRange)) {\n this.rowHeaderRange && this.table.arrangeCustomCellStyle({ range: this.rowHeaderRange }, undefined);\n rowHeaderRange && this.table.arrangeCustomCellStyle({ range: rowHeaderRange }, 'row-highlight');\n this.rowHeaderRange = rowHeaderRange;\n }\n }\n}\n\nfunction isSameRange(a: CellRange | undefined, b: CellRange | undefined) {\n if (a === undefined && b === undefined) {\n return true;\n }\n\n if (a === undefined || b === undefined) {\n return false;\n }\n\n return (\n a.start.col === b.start.col && a.start.row === b.start.row && a.end.col === b.end.col && a.end.row === b.end.row\n );\n}\n"]}
package/es/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export * from './carousel-animation';
2
+ export * from './invert-highlight';
3
+ export * from './header-highlight';
package/es/index.js ADDED
@@ -0,0 +1,6 @@
1
+ export * from "./carousel-animation";
2
+
3
+ export * from "./invert-highlight";
4
+
5
+ export * from "./header-highlight";
6
+ //# sourceMappingURL=index.js.map