e-virt-table 0.0.3

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 (90) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +2 -0
  3. package/dist/index.cjs.js +14 -0
  4. package/dist/index.cjs.js.map +1 -0
  5. package/dist/index.es.js +5422 -0
  6. package/dist/index.es.js.map +1 -0
  7. package/dist/index.umd.js +14 -0
  8. package/dist/index.umd.js.map +1 -0
  9. package/dist/lib/Autofill.d.ts +20 -0
  10. package/dist/lib/Autofill.js +185 -0
  11. package/dist/lib/Autofill.js.map +1 -0
  12. package/dist/lib/BaseCell.d.ts +22 -0
  13. package/dist/lib/BaseCell.js +111 -0
  14. package/dist/lib/BaseCell.js.map +1 -0
  15. package/dist/lib/Body.d.ts +29 -0
  16. package/dist/lib/Body.js +382 -0
  17. package/dist/lib/Body.js.map +1 -0
  18. package/dist/lib/Cell.d.ts +101 -0
  19. package/dist/lib/Cell.js +943 -0
  20. package/dist/lib/Cell.js.map +1 -0
  21. package/dist/lib/CellHeader.d.ts +64 -0
  22. package/dist/lib/CellHeader.js +355 -0
  23. package/dist/lib/CellHeader.js.map +1 -0
  24. package/dist/lib/Config.d.ts +106 -0
  25. package/dist/lib/Config.js +617 -0
  26. package/dist/lib/Config.js.map +1 -0
  27. package/dist/lib/Context.d.ts +123 -0
  28. package/dist/lib/Context.js +419 -0
  29. package/dist/lib/Context.js.map +1 -0
  30. package/dist/lib/Database.d.ts +228 -0
  31. package/dist/lib/Database.js +931 -0
  32. package/dist/lib/Database.js.map +1 -0
  33. package/dist/lib/EVirtTable.d.ts +61 -0
  34. package/dist/lib/EVirtTable.js +321 -0
  35. package/dist/lib/EVirtTable.js.map +1 -0
  36. package/dist/lib/Editor.d.ts +16 -0
  37. package/dist/lib/Editor.js +251 -0
  38. package/dist/lib/Editor.js.map +1 -0
  39. package/dist/lib/Empty.d.ts +7 -0
  40. package/dist/lib/Empty.js +45 -0
  41. package/dist/lib/Empty.js.map +1 -0
  42. package/dist/lib/EventBrowser.d.ts +17 -0
  43. package/dist/lib/EventBrowser.js +79 -0
  44. package/dist/lib/EventBrowser.js.map +1 -0
  45. package/dist/lib/EventBus.d.ts +12 -0
  46. package/dist/lib/EventBus.js +58 -0
  47. package/dist/lib/EventBus.js.map +1 -0
  48. package/dist/lib/EventTable.d.ts +26 -0
  49. package/dist/lib/EventTable.js +358 -0
  50. package/dist/lib/EventTable.js.map +1 -0
  51. package/dist/lib/Footer.d.ts +17 -0
  52. package/dist/lib/Footer.js +138 -0
  53. package/dist/lib/Footer.js.map +1 -0
  54. package/dist/lib/Header.d.ts +37 -0
  55. package/dist/lib/Header.js +482 -0
  56. package/dist/lib/Header.js.map +1 -0
  57. package/dist/lib/History.d.ts +27 -0
  58. package/dist/lib/History.js +106 -0
  59. package/dist/lib/History.js.map +1 -0
  60. package/dist/lib/Icons.d.ts +15 -0
  61. package/dist/lib/Icons.js +145 -0
  62. package/dist/lib/Icons.js.map +1 -0
  63. package/dist/lib/Overlayer.d.ts +10 -0
  64. package/dist/lib/Overlayer.js +267 -0
  65. package/dist/lib/Overlayer.js.map +1 -0
  66. package/dist/lib/Paint.d.ts +65 -0
  67. package/dist/lib/Paint.js +223 -0
  68. package/dist/lib/Paint.js.map +1 -0
  69. package/dist/lib/Row.d.ts +22 -0
  70. package/dist/lib/Row.js +125 -0
  71. package/dist/lib/Row.js.map +1 -0
  72. package/dist/lib/Scroller.d.ts +20 -0
  73. package/dist/lib/Scroller.js +448 -0
  74. package/dist/lib/Scroller.js.map +1 -0
  75. package/dist/lib/Selector.d.ts +38 -0
  76. package/dist/lib/Selector.js +532 -0
  77. package/dist/lib/Selector.js.map +1 -0
  78. package/dist/lib/Tooltip.d.ts +13 -0
  79. package/dist/lib/Tooltip.js +204 -0
  80. package/dist/lib/Tooltip.js.map +1 -0
  81. package/dist/lib/index.d.ts +3 -0
  82. package/dist/lib/index.js +4 -0
  83. package/dist/lib/index.js.map +1 -0
  84. package/dist/lib/types.d.ts +160 -0
  85. package/dist/lib/types.js +2 -0
  86. package/dist/lib/types.js.map +1 -0
  87. package/dist/lib/util.d.ts +15 -0
  88. package/dist/lib/util.js +113 -0
  89. package/dist/lib/util.js.map +1 -0
  90. package/package.json +37 -0
@@ -0,0 +1,943 @@
1
+ import BaseCell from './BaseCell';
2
+ export default class Cell extends BaseCell {
3
+ constructor(ctx, rowIndex, colIndex, x, y, width, height, column, row, cellType = 'body') {
4
+ super(ctx, x, y, width, height, column.fixed, cellType);
5
+ Object.defineProperty(this, "formatter", {
6
+ enumerable: true,
7
+ configurable: true,
8
+ writable: true,
9
+ value: void 0
10
+ });
11
+ Object.defineProperty(this, "hoverIconName", {
12
+ enumerable: true,
13
+ configurable: true,
14
+ writable: true,
15
+ value: ''
16
+ });
17
+ Object.defineProperty(this, "align", {
18
+ enumerable: true,
19
+ configurable: true,
20
+ writable: true,
21
+ value: void 0
22
+ });
23
+ Object.defineProperty(this, "verticalAlign", {
24
+ enumerable: true,
25
+ configurable: true,
26
+ writable: true,
27
+ value: void 0
28
+ });
29
+ Object.defineProperty(this, "fixed", {
30
+ enumerable: true,
31
+ configurable: true,
32
+ writable: true,
33
+ value: void 0
34
+ });
35
+ Object.defineProperty(this, "type", {
36
+ enumerable: true,
37
+ configurable: true,
38
+ writable: true,
39
+ value: void 0
40
+ });
41
+ Object.defineProperty(this, "editorType", {
42
+ enumerable: true,
43
+ configurable: true,
44
+ writable: true,
45
+ value: void 0
46
+ });
47
+ Object.defineProperty(this, "cellType", {
48
+ enumerable: true,
49
+ configurable: true,
50
+ writable: true,
51
+ value: void 0
52
+ });
53
+ Object.defineProperty(this, "level", {
54
+ enumerable: true,
55
+ configurable: true,
56
+ writable: true,
57
+ value: void 0
58
+ });
59
+ Object.defineProperty(this, "colspan", {
60
+ enumerable: true,
61
+ configurable: true,
62
+ writable: true,
63
+ value: 1
64
+ });
65
+ Object.defineProperty(this, "rowspan", {
66
+ enumerable: true,
67
+ configurable: true,
68
+ writable: true,
69
+ value: 1
70
+ });
71
+ Object.defineProperty(this, "key", {
72
+ enumerable: true,
73
+ configurable: true,
74
+ writable: true,
75
+ value: void 0
76
+ });
77
+ Object.defineProperty(this, "column", {
78
+ enumerable: true,
79
+ configurable: true,
80
+ writable: true,
81
+ value: void 0
82
+ });
83
+ Object.defineProperty(this, "rowIndex", {
84
+ enumerable: true,
85
+ configurable: true,
86
+ writable: true,
87
+ value: void 0
88
+ });
89
+ Object.defineProperty(this, "colIndex", {
90
+ enumerable: true,
91
+ configurable: true,
92
+ writable: true,
93
+ value: void 0
94
+ });
95
+ Object.defineProperty(this, "rowKey", {
96
+ enumerable: true,
97
+ configurable: true,
98
+ writable: true,
99
+ value: void 0
100
+ });
101
+ Object.defineProperty(this, "row", {
102
+ enumerable: true,
103
+ configurable: true,
104
+ writable: true,
105
+ value: void 0
106
+ });
107
+ Object.defineProperty(this, "value", {
108
+ enumerable: true,
109
+ configurable: true,
110
+ writable: true,
111
+ value: void 0
112
+ });
113
+ Object.defineProperty(this, "render", {
114
+ enumerable: true,
115
+ configurable: true,
116
+ writable: true,
117
+ value: void 0
118
+ });
119
+ Object.defineProperty(this, "renderFooter", {
120
+ enumerable: true,
121
+ configurable: true,
122
+ writable: true,
123
+ value: void 0
124
+ });
125
+ Object.defineProperty(this, "style", {
126
+ enumerable: true,
127
+ configurable: true,
128
+ writable: true,
129
+ value: {}
130
+ });
131
+ Object.defineProperty(this, "rules", {
132
+ enumerable: true,
133
+ configurable: true,
134
+ writable: true,
135
+ value: {}
136
+ });
137
+ Object.defineProperty(this, "message", {
138
+ enumerable: true,
139
+ configurable: true,
140
+ writable: true,
141
+ value: ''
142
+ });
143
+ Object.defineProperty(this, "text", {
144
+ enumerable: true,
145
+ configurable: true,
146
+ writable: true,
147
+ value: ''
148
+ });
149
+ Object.defineProperty(this, "displayText", {
150
+ enumerable: true,
151
+ configurable: true,
152
+ writable: true,
153
+ value: ''
154
+ });
155
+ Object.defineProperty(this, "visibleWidth", {
156
+ enumerable: true,
157
+ configurable: true,
158
+ writable: true,
159
+ value: 0
160
+ });
161
+ Object.defineProperty(this, "visibleHeight", {
162
+ enumerable: true,
163
+ configurable: true,
164
+ writable: true,
165
+ value: 0
166
+ });
167
+ Object.defineProperty(this, "drawX", {
168
+ enumerable: true,
169
+ configurable: true,
170
+ writable: true,
171
+ value: 0
172
+ });
173
+ Object.defineProperty(this, "drawY", {
174
+ enumerable: true,
175
+ configurable: true,
176
+ writable: true,
177
+ value: 0
178
+ });
179
+ Object.defineProperty(this, "drawCellBgColor", {
180
+ enumerable: true,
181
+ configurable: true,
182
+ writable: true,
183
+ value: ''
184
+ });
185
+ Object.defineProperty(this, "drawCellSkyBgColor", {
186
+ enumerable: true,
187
+ configurable: true,
188
+ writable: true,
189
+ value: ''
190
+ });
191
+ Object.defineProperty(this, "drawTextColor", {
192
+ enumerable: true,
193
+ configurable: true,
194
+ writable: true,
195
+ value: ''
196
+ });
197
+ Object.defineProperty(this, "drawTextX", {
198
+ enumerable: true,
199
+ configurable: true,
200
+ writable: true,
201
+ value: 0
202
+ });
203
+ Object.defineProperty(this, "drawTextY", {
204
+ enumerable: true,
205
+ configurable: true,
206
+ writable: true,
207
+ value: 0
208
+ });
209
+ Object.defineProperty(this, "drawImageX", {
210
+ enumerable: true,
211
+ configurable: true,
212
+ writable: true,
213
+ value: 0
214
+ });
215
+ Object.defineProperty(this, "drawImageY", {
216
+ enumerable: true,
217
+ configurable: true,
218
+ writable: true,
219
+ value: 0
220
+ });
221
+ Object.defineProperty(this, "drawImageWidth", {
222
+ enumerable: true,
223
+ configurable: true,
224
+ writable: true,
225
+ value: 0
226
+ });
227
+ Object.defineProperty(this, "drawImageHeight", {
228
+ enumerable: true,
229
+ configurable: true,
230
+ writable: true,
231
+ value: 0
232
+ });
233
+ Object.defineProperty(this, "drawImageName", {
234
+ enumerable: true,
235
+ configurable: true,
236
+ writable: true,
237
+ value: ''
238
+ });
239
+ Object.defineProperty(this, "drawImageSource", {
240
+ enumerable: true,
241
+ configurable: true,
242
+ writable: true,
243
+ value: void 0
244
+ });
245
+ Object.defineProperty(this, "ellipsis", {
246
+ enumerable: true,
247
+ configurable: true,
248
+ writable: true,
249
+ value: false
250
+ });
251
+ Object.defineProperty(this, "overflowTooltipShow", {
252
+ enumerable: true,
253
+ configurable: true,
254
+ writable: true,
255
+ value: true
256
+ });
257
+ Object.defineProperty(this, "overflowTooltipMaxWidth", {
258
+ enumerable: true,
259
+ configurable: true,
260
+ writable: true,
261
+ value: 500
262
+ });
263
+ Object.defineProperty(this, "overflowTooltipPlacement", {
264
+ enumerable: true,
265
+ configurable: true,
266
+ writable: true,
267
+ value: 'top'
268
+ });
269
+ this.visibleWidth = this.width;
270
+ this.visibleHeight = this.height;
271
+ this.colIndex = colIndex;
272
+ this.rowIndex = rowIndex;
273
+ this.key = column.key;
274
+ this.type = column.type || 'text';
275
+ this.editorType = column.editorType || 'text';
276
+ this.cellType = cellType;
277
+ this.align = column.align || 'center';
278
+ this.verticalAlign = column.verticalAlign || 'middle';
279
+ this.fixed = column.fixed;
280
+ this.level = column.level;
281
+ this.column = column;
282
+ this.rules = column.rules;
283
+ this.row = row;
284
+ this.rowKey =
285
+ this.cellType === 'body'
286
+ ? this.ctx.database.getRowKeyForRowIndex(rowIndex)
287
+ : `${this.cellType}_${this.rowIndex}`;
288
+ this.value = this.getValue();
289
+ this.render = column.render;
290
+ this.overflowTooltipShow = column.overflowTooltipShow === false ? false : true;
291
+ this.overflowTooltipMaxWidth = column.overflowTooltipMaxWidth || 500;
292
+ this.overflowTooltipPlacement = column.overflowTooltipPlacement || 'top';
293
+ this.renderFooter = column.renderFooter;
294
+ this.hoverIconName = column.hoverIconName;
295
+ this.formatter = column.formatter;
296
+ this.update();
297
+ }
298
+ getValidationMessage() {
299
+ const errors = this.ctx.database.getValidationError(this.rowKey, this.key);
300
+ if (Array.isArray(errors) && errors.length) {
301
+ const [err] = errors;
302
+ this.message = err.message;
303
+ }
304
+ return this.message;
305
+ }
306
+ update() {
307
+ this.drawX = this.getDrawX();
308
+ this.drawY = this.getDrawY();
309
+ this.drawTextX = this.drawX;
310
+ this.drawTextY = this.drawY;
311
+ this.updateSpan();
312
+ this.updateStyle();
313
+ this.updateType();
314
+ this.updateHoverIcon();
315
+ this.updateSelection();
316
+ this.updateTree();
317
+ this.updateEditorType();
318
+ this.updateRender();
319
+ this.getValidationMessage();
320
+ this.updateContainer();
321
+ this.text = this.getText();
322
+ this.displayText = this.getDisplayText();
323
+ }
324
+ updateSpan() {
325
+ // 合计不合并
326
+ if (this.cellType === 'footer') {
327
+ return;
328
+ }
329
+ const { SPAN_METHOD } = this.ctx.config;
330
+ if (typeof SPAN_METHOD === 'function') {
331
+ const spanMethod = SPAN_METHOD;
332
+ const { colspan = 1, rowspan = 1 } = spanMethod({
333
+ row: this.row,
334
+ rowIndex: this.rowIndex,
335
+ colIndex: this.colIndex,
336
+ column: this.column,
337
+ value: this.getValue(),
338
+ headIndex: this.ctx.body.headIndex,
339
+ headPosition: this.ctx.database.getPositionForRowIndex(this.ctx.body.headIndex),
340
+ visibleRows: this.ctx.body.visibleRows,
341
+ visibleLeafColumns: this.ctx.header.visibleLeafColumns,
342
+ rows: this.ctx.body.data,
343
+ }) || {};
344
+ this.colspan = colspan;
345
+ this.rowspan = rowspan;
346
+ this.visibleWidth = this.getWidthByColIndexColSpan(this.colIndex, this.colspan);
347
+ this.visibleHeight = this.ctx.database.getHeightByRowIndexRowSpan(this.rowIndex, this.rowspan);
348
+ }
349
+ }
350
+ updateType() {
351
+ // 更改类型
352
+ const { CELL_TYPE_METHOD } = this.ctx.config;
353
+ if (typeof CELL_TYPE_METHOD === 'function') {
354
+ const cellTypeMethod = CELL_TYPE_METHOD;
355
+ const type = cellTypeMethod({
356
+ row: this.row,
357
+ rowIndex: this.rowIndex,
358
+ colIndex: this.colIndex,
359
+ column: this.column,
360
+ value: this.getValue(),
361
+ });
362
+ // 可以动态改变类型
363
+ if (type !== undefined) {
364
+ this.type = type;
365
+ }
366
+ }
367
+ }
368
+ updateEditorType() {
369
+ // 更改类型
370
+ const { CELL_EDITOR_TYPE_METHOD } = this.ctx.config;
371
+ if (typeof CELL_EDITOR_TYPE_METHOD === 'function') {
372
+ const cellEditorTypeMethod = CELL_EDITOR_TYPE_METHOD;
373
+ const editorType = cellEditorTypeMethod({
374
+ row: this.row,
375
+ rowIndex: this.rowIndex,
376
+ colIndex: this.colIndex,
377
+ column: this.column,
378
+ value: this.getValue(),
379
+ });
380
+ // 可以动态改变类型
381
+ if (editorType !== undefined) {
382
+ this.editorType = editorType;
383
+ }
384
+ }
385
+ }
386
+ updateRender() {
387
+ const { CELL_RENDER_METHOD } = this.ctx.config;
388
+ if (typeof CELL_RENDER_METHOD === 'function') {
389
+ const cellRenderMethod = CELL_RENDER_METHOD;
390
+ const render = cellRenderMethod({
391
+ row: this.row,
392
+ rowIndex: this.rowIndex,
393
+ colIndex: this.colIndex,
394
+ column: this.column,
395
+ value: this.getValue(),
396
+ });
397
+ // 可以动态改变类型
398
+ if (render !== undefined) {
399
+ this.render = render;
400
+ }
401
+ }
402
+ }
403
+ validate() {
404
+ this.ctx.database
405
+ .getValidator(this.rowKey, this.key)
406
+ .then(() => {
407
+ this.ctx.database.setValidationError(this.rowKey, this.key, []);
408
+ this.message = '';
409
+ })
410
+ .catch((errors) => {
411
+ if (Array.isArray(errors) && errors.length) {
412
+ const [err] = errors;
413
+ this.message = err.message;
414
+ this.ctx.database.setValidationError(this.rowKey, this.key, errors);
415
+ }
416
+ })
417
+ .finally(() => {
418
+ this.ctx.emit('draw');
419
+ });
420
+ }
421
+ /**
422
+ * 更新样式
423
+ */
424
+ updateStyle() {
425
+ this.style = this.getOverlayerViewsStyle();
426
+ }
427
+ updateTree() {
428
+ const { CELL_PADDING = 0 } = this.ctx.config;
429
+ const { rowKey, cellType } = this;
430
+ let icon = undefined;
431
+ let iconOffsetX = 0;
432
+ let iconName = '';
433
+ if (this.type === 'tree' && cellType === 'body') {
434
+ const row = this.ctx.database.getRowForRowKey(rowKey);
435
+ const { expand = false, hasChildren = false, expandLoading = false, level = 0 } = row || {};
436
+ if (expandLoading) {
437
+ const loadingIcon = this.ctx.icons.get('loading');
438
+ iconName = 'loading';
439
+ icon = loadingIcon;
440
+ iconOffsetX = level * 8;
441
+ }
442
+ else if (hasChildren) {
443
+ const expandIcon = this.ctx.icons.get('expand');
444
+ const shrinkIcon = this.ctx.icons.get('shrink');
445
+ icon = !expand ? expandIcon : shrinkIcon;
446
+ iconName = !expand ? 'expand' : 'shrink';
447
+ iconOffsetX = level * 8;
448
+ }
449
+ else {
450
+ iconOffsetX = level * 8;
451
+ }
452
+ if (icon) {
453
+ let iconWidth = 20;
454
+ let iconHeight = 20;
455
+ let iconX = this.drawX + iconOffsetX + CELL_PADDING;
456
+ let iconY = this.drawY + (this.visibleHeight - iconHeight) / 2 + 2;
457
+ this.ctx.paint.drawImage(icon, iconX, iconY, iconWidth, iconHeight);
458
+ this.drawImageX = iconX;
459
+ this.drawImageY = iconY;
460
+ this.drawImageWidth = iconWidth;
461
+ this.drawImageHeight = iconHeight;
462
+ this.drawImageName = iconName;
463
+ this.drawImageSource = icon;
464
+ // 更改文本距离
465
+ this.align = 'left';
466
+ this.drawTextX = iconOffsetX + this.drawX + iconWidth + 0.5;
467
+ }
468
+ }
469
+ }
470
+ updateContainer() {
471
+ const { BODY_BG_COLOR, EDIT_BG_COLOR, BODY_CELL_STYLE_METHOD, FOOTER_CELL_STYLE_METHOD, READONLY_TEXT_COLOR, FOOTER_BG_COLOR, HIGHLIGHT_SELECTED_ROW, HIGHLIGHT_SELECTED_ROW_COLOR, HIGHLIGHT_HOVER_ROW, HIGHLIGHT_HOVER_ROW_COLOR, } = this.ctx.config;
472
+ if (this.cellType === 'footer') {
473
+ let bgColor = FOOTER_BG_COLOR;
474
+ let textColor = READONLY_TEXT_COLOR;
475
+ if (typeof FOOTER_CELL_STYLE_METHOD === 'function') {
476
+ const footerCellStyleMethod = FOOTER_CELL_STYLE_METHOD;
477
+ const { backgroundColor, color } = footerCellStyleMethod({
478
+ row: this.row,
479
+ rowIndex: this.rowIndex,
480
+ colIndex: this.colIndex,
481
+ column: this.column,
482
+ value: this.getValue(),
483
+ }) || {};
484
+ if (backgroundColor) {
485
+ bgColor = backgroundColor;
486
+ }
487
+ // 文字颜色
488
+ if (color) {
489
+ textColor = color;
490
+ }
491
+ }
492
+ // 合计底部背景色
493
+ this.drawCellSkyBgColor = 'transparent';
494
+ this.drawCellBgColor = bgColor;
495
+ this.drawTextColor = textColor;
496
+ return;
497
+ }
498
+ // 高亮行,在背景色上加一层颜色
499
+ let drawCellSkyBgColor = 'transparent';
500
+ // 高亮行
501
+ const focusCell = this.ctx.focusCell;
502
+ const hoverCell = this.ctx.hoverCell;
503
+ if (HIGHLIGHT_HOVER_ROW && hoverCell?.rowKey === this.rowKey) {
504
+ drawCellSkyBgColor = HIGHLIGHT_HOVER_ROW_COLOR;
505
+ }
506
+ if (HIGHLIGHT_SELECTED_ROW && focusCell?.rowKey === this.rowKey) {
507
+ drawCellSkyBgColor = HIGHLIGHT_SELECTED_ROW_COLOR;
508
+ }
509
+ this.drawCellSkyBgColor = drawCellSkyBgColor;
510
+ // 恢复默认背景色
511
+ let bgColor = BODY_BG_COLOR;
512
+ let textColor = READONLY_TEXT_COLOR;
513
+ // 只读
514
+ if (['index', 'index-selection', 'selection'].includes(this.type)) {
515
+ this.drawCellBgColor = BODY_BG_COLOR;
516
+ this.drawTextColor = READONLY_TEXT_COLOR;
517
+ return;
518
+ }
519
+ if (!this.ctx.database.getReadonly(this.rowKey, this.key)) {
520
+ bgColor = EDIT_BG_COLOR;
521
+ textColor = READONLY_TEXT_COLOR;
522
+ }
523
+ if (typeof BODY_CELL_STYLE_METHOD === 'function') {
524
+ const cellStyleMethod = BODY_CELL_STYLE_METHOD;
525
+ const { backgroundColor, color } = cellStyleMethod({
526
+ row: this.row,
527
+ rowIndex: this.rowIndex,
528
+ colIndex: this.colIndex,
529
+ column: this.column,
530
+ value: this.getValue(),
531
+ }) || {};
532
+ if (backgroundColor) {
533
+ bgColor = backgroundColor;
534
+ }
535
+ // 文字颜色
536
+ if (color) {
537
+ textColor = color;
538
+ }
539
+ }
540
+ this.drawCellBgColor = bgColor;
541
+ this.drawTextColor = textColor;
542
+ // const change = this.grid.database.isHasChangedData(cell.rowKey, cell.key);
543
+ // if (change) {
544
+ // this.setBackgroundColor("red");
545
+ // }
546
+ }
547
+ updateSelection() {
548
+ const { visibleWidth, visibleHeight, rowspan, colspan, cellType, type, rowIndex, rowKey } = this;
549
+ //合并的选框不显示
550
+ if (rowspan === 0 || colspan === 0) {
551
+ return;
552
+ }
553
+ // 合计不显示
554
+ if (cellType === 'footer') {
555
+ return;
556
+ }
557
+ // 选中框类型
558
+ if (['index-selection', 'selection'].includes(type)) {
559
+ const check = this.ctx.database.getRowSelection(rowKey);
560
+ const selectable = this.ctx.database.getRowSelectable(rowKey);
561
+ const { CHECKBOX_SIZE = 0 } = this.ctx.config;
562
+ const _x = this.drawX + (visibleWidth - CHECKBOX_SIZE) / 2;
563
+ const _y = this.drawY + (visibleHeight - CHECKBOX_SIZE) / 2;
564
+ let checkboxImage = this.ctx.icons.get('checkbox-uncheck');
565
+ let checkboxName = 'checkbox-uncheck';
566
+ if (check && selectable) {
567
+ checkboxImage = this.ctx.icons.get('checkbox-check');
568
+ checkboxName = 'checkbox-check';
569
+ }
570
+ else if (check && selectable) {
571
+ checkboxImage = this.ctx.icons.get('checkbox-check-disabled');
572
+ checkboxName = 'checkbox-check-disabled';
573
+ }
574
+ else if (!check && selectable) {
575
+ checkboxImage = this.ctx.icons.get('checkbox-uncheck');
576
+ checkboxName = 'checkbox-uncheck';
577
+ }
578
+ else {
579
+ checkboxImage = this.ctx.icons.get('checkbox-disabled');
580
+ checkboxName = 'checkbox-disabled';
581
+ }
582
+ if (checkboxImage && type == 'index-selection') {
583
+ if ((this.ctx.hoverCell && this.ctx.hoverCell.rowIndex === rowIndex) ||
584
+ ['checkbox-disabled', 'checkbox-check'].includes(checkboxName)) {
585
+ this.drawImageX = _x;
586
+ this.drawImageY = _y;
587
+ this.drawImageWidth = CHECKBOX_SIZE;
588
+ this.drawImageHeight = CHECKBOX_SIZE;
589
+ this.drawImageName = checkboxName;
590
+ this.drawImageSource = checkboxImage;
591
+ }
592
+ }
593
+ else if (checkboxImage && 'selection' === type) {
594
+ this.drawImageX = _x;
595
+ this.drawImageY = _y;
596
+ this.drawImageWidth = CHECKBOX_SIZE;
597
+ this.drawImageHeight = CHECKBOX_SIZE;
598
+ this.drawImageName = checkboxName;
599
+ this.drawImageSource = checkboxImage;
600
+ }
601
+ }
602
+ }
603
+ updateHoverIcon() {
604
+ const { CELL_HOVER_ICON_METHOD, CELL_HOVER_ICON_SIZE, CELL_PADDING } = this.ctx.config;
605
+ if (typeof CELL_HOVER_ICON_METHOD === 'function') {
606
+ const hoverIconMethod = CELL_HOVER_ICON_METHOD;
607
+ const hoverIconName = hoverIconMethod({
608
+ row: this.row,
609
+ rowIndex: this.rowIndex,
610
+ colIndex: this.colIndex,
611
+ column: this.column,
612
+ value: this.getValue(),
613
+ });
614
+ // 可以动态改变hoverIconName
615
+ if (hoverIconName !== undefined) {
616
+ this.hoverIconName = hoverIconName;
617
+ }
618
+ }
619
+ // 永远放在右边
620
+ const _x = this.drawX + this.width - CELL_HOVER_ICON_SIZE - CELL_PADDING;
621
+ const _y = this.drawY + (this.height - CELL_HOVER_ICON_SIZE) / 2;
622
+ if (this.hoverIconName) {
623
+ if (this.ctx.hoverCell && this.ctx.hoverCell.rowIndex === this.rowIndex) {
624
+ const drawImageSource = this.ctx.icons.get(this.hoverIconName);
625
+ this.drawImageX = _x;
626
+ this.drawImageY = _y;
627
+ this.drawImageWidth = CELL_HOVER_ICON_SIZE;
628
+ this.drawImageHeight = CELL_HOVER_ICON_SIZE;
629
+ this.drawImageName = this.hoverIconName;
630
+ this.drawImageSource = drawImageSource;
631
+ }
632
+ }
633
+ }
634
+ /**
635
+ * 获取显示文本
636
+ * @returns
637
+ */
638
+ getDisplayText() {
639
+ if (this.cellType === 'footer') {
640
+ // 插槽不显示文本
641
+ if (this.renderFooter) {
642
+ return '';
643
+ }
644
+ if (this.text === null || this.text === undefined) {
645
+ return '';
646
+ }
647
+ return this.text;
648
+ }
649
+ else {
650
+ // cellType === "body"
651
+ // 被跨度单元格
652
+ if (this.rowspan === 0 || this.colspan === 0) {
653
+ return '';
654
+ }
655
+ // 插槽不显示文本
656
+ if (this.render) {
657
+ return '';
658
+ }
659
+ //
660
+ if (this.type === 'index-selection' &&
661
+ ((this.ctx.hoverCell && this.ctx.hoverCell.rowIndex === this.rowIndex) ||
662
+ ['checkbox-disabled', 'checkbox-check'].includes(this.drawImageName))) {
663
+ return '';
664
+ }
665
+ if (this.text === null || this.text === undefined) {
666
+ return '';
667
+ }
668
+ return `${this.text}`;
669
+ }
670
+ }
671
+ /**
672
+ * 获取文本
673
+ * @returns
674
+ */
675
+ getText() {
676
+ if (this.cellType === 'footer') {
677
+ return this.row[this.key];
678
+ }
679
+ // cellType === "body"
680
+ // formatter优先等级比较高
681
+ if (typeof this.formatter === 'function') {
682
+ const _text = this.formatter({
683
+ row: this.row,
684
+ rowIndex: this.rowIndex,
685
+ colIndex: this.colIndex,
686
+ column: this.column,
687
+ value: this.getValue(),
688
+ });
689
+ return _text;
690
+ }
691
+ const { CELL_FORMATTER_METHOD } = this.ctx.config;
692
+ if (typeof CELL_FORMATTER_METHOD === 'function') {
693
+ const formatterMethod = CELL_FORMATTER_METHOD;
694
+ const _text = formatterMethod({
695
+ row: this.row,
696
+ rowIndex: this.rowIndex,
697
+ colIndex: this.colIndex,
698
+ column: this.column,
699
+ value: this.getValue(),
700
+ });
701
+ return _text;
702
+ }
703
+ if (['index-selection', 'index'].includes(this.type)) {
704
+ const str = `${this.rowIndex + 1}`; // 索引
705
+ return str; // 索引
706
+ }
707
+ this.value = this.ctx.database.getItemValue(this.rowKey, this.key);
708
+ return this.value;
709
+ }
710
+ getValue() {
711
+ return this.ctx.database.getItemValue(this.rowKey, this.key);
712
+ }
713
+ /**
714
+ * 获取样式
715
+ */
716
+ getOverlayerViewsStyle() {
717
+ let left = `${this.drawX - this.ctx.fixedLeftWidth}px`;
718
+ let top = `${this.drawY - this.ctx.body.y}px`;
719
+ // 固定列
720
+ if (this.fixed === 'left') {
721
+ left = `${this.drawX}px`;
722
+ }
723
+ else if (this.fixed === 'right') {
724
+ left = `${this.drawX - (this.ctx.target.width - this.ctx.fixedRightWidth)}px`;
725
+ }
726
+ // 合计
727
+ if (this.cellType === 'footer') {
728
+ if (this.ctx.config.FOOTER_FIXED) {
729
+ top = `${this.drawY - this.ctx.footer.y}px`;
730
+ }
731
+ }
732
+ return {
733
+ position: 'absolute',
734
+ overflow: 'hidden',
735
+ left,
736
+ top,
737
+ width: `${this.visibleWidth}px`,
738
+ height: `${this.visibleHeight}px`,
739
+ pointerEvents: 'none',
740
+ };
741
+ }
742
+ draw() {
743
+ const { paint, config: { BORDER_COLOR }, } = this.ctx;
744
+ const { drawX, drawY } = this;
745
+ // 绘制单元格
746
+ paint.drawRect(drawX, drawY, this.visibleWidth, this.visibleHeight, {
747
+ borderColor: BORDER_COLOR,
748
+ fillColor: this.drawCellBgColor,
749
+ });
750
+ paint.drawRect(drawX, drawY, this.width, this.height, {
751
+ borderColor: 'transparent',
752
+ borderWidth: 1,
753
+ fillColor: this.drawCellSkyBgColor,
754
+ });
755
+ // 画选中框
756
+ this.ellipsis = this.drawText();
757
+ this.drawImage();
758
+ this.drawSelector();
759
+ this.drawAutofillPiont();
760
+ this.drawErrorTip();
761
+ }
762
+ /**
763
+ * 根据列的索引获取列的宽度
764
+ * @param {Number} colIndex
765
+ */
766
+ getWidthByColIndexColSpan(colIndex, colSpan) {
767
+ if (colSpan === 0) {
768
+ return 0;
769
+ }
770
+ let width = 0;
771
+ for (let i = colIndex; i < colIndex + colSpan; i++) {
772
+ const cellHeader = this.ctx.header.leafCellHeaders[i];
773
+ width += cellHeader.width;
774
+ }
775
+ return width;
776
+ }
777
+ drawText() {
778
+ const { CELL_PADDING, BODY_FONT } = this.ctx.config;
779
+ return this.ctx.paint.drawText(this.displayText, this.drawTextX, this.drawTextY, this.visibleWidth, this.visibleHeight, {
780
+ font: BODY_FONT,
781
+ padding: CELL_PADDING,
782
+ align: this.align,
783
+ verticalAlign: this.verticalAlign,
784
+ color: this.drawTextColor,
785
+ });
786
+ }
787
+ drawImage() {
788
+ if (!this.drawImageSource) {
789
+ return;
790
+ }
791
+ this.ctx.paint.drawImage(this.drawImageSource, this.drawImageX, this.drawImageY, this.drawImageWidth, this.drawImageHeight);
792
+ }
793
+ drawAutofillPiont() {
794
+ if (this.cellType === 'footer') {
795
+ return;
796
+ }
797
+ const { SELECT_BORDER_COLOR, ENABLE_AUTOFILL, ENABLE_SELECTOR } = this.ctx.config;
798
+ if (!ENABLE_SELECTOR) {
799
+ return;
800
+ }
801
+ if (!ENABLE_AUTOFILL) {
802
+ return;
803
+ }
804
+ const show = true;
805
+ const { xArr, yArr } = this.ctx.selector;
806
+ const maxX = xArr[1];
807
+ const maxY = yArr[1];
808
+ const { colIndex, rowIndex, drawX, drawY } = this;
809
+ // 绘制自动填充点
810
+ if (show && colIndex === maxX && rowIndex === maxY) {
811
+ this.ctx.paint.drawRect(drawX + this.width - 6, drawY + this.height - 6, 6, 6, {
812
+ borderColor: '#fff',
813
+ fillColor: SELECT_BORDER_COLOR,
814
+ });
815
+ }
816
+ }
817
+ drawSelector() {
818
+ if (this.cellType === 'footer') {
819
+ return;
820
+ }
821
+ const { ENABLE_SELECTOR } = this.ctx.config;
822
+ if (!ENABLE_SELECTOR) {
823
+ return;
824
+ }
825
+ const { xArr, yArr, xArrCopy, yArrCopy } = this.ctx.selector;
826
+ // 复制线
827
+ this.drawBorder({
828
+ xArr: xArrCopy,
829
+ yArr: yArrCopy,
830
+ borderColor: this.ctx.config.SELECT_BORDER_COLOR || 'rgb(82,146,247)',
831
+ fillColor: this.ctx.config.SELECT_AREA_COLOR || 'rgba(82,146,247,0.1)',
832
+ borderWidth: 1,
833
+ lineDash: [4, 4],
834
+ });
835
+ // 填充线
836
+ this.drawBorder({
837
+ xArr: this.ctx.autofill.xArr,
838
+ yArr: this.ctx.autofill.yArr,
839
+ borderColor: this.ctx.config.SELECT_BORDER_COLOR || 'rgb(82,146,247)',
840
+ fillColor: this.ctx.config.SELECT_AREA_COLOR || 'rgba(82,146,247,0.1)',
841
+ borderWidth: 1,
842
+ lineDash: [4, 4],
843
+ });
844
+ // 选择线
845
+ this.drawBorder({
846
+ xArr,
847
+ yArr,
848
+ borderColor: this.ctx.config.SELECT_BORDER_COLOR || 'rgb(82,146,247)',
849
+ fillColor: this.ctx.config.SELECT_AREA_COLOR || 'rgba(82,146,247,0.1)',
850
+ borderWidth: 1,
851
+ });
852
+ }
853
+ drawErrorTip() {
854
+ // 合计不显示
855
+ if (this.cellType === 'footer') {
856
+ return;
857
+ }
858
+ // 没有错误消息
859
+ if (!this.message) {
860
+ return;
861
+ }
862
+ const { ERROR_TIP_ICON_SIZE, ERROR_TIP_COLOR } = this.ctx.config;
863
+ const { width } = this;
864
+ const x = this.drawX;
865
+ const y = this.drawY;
866
+ const points = [
867
+ x + width - ERROR_TIP_ICON_SIZE - 0.5,
868
+ y,
869
+ x + width - 0.5,
870
+ y,
871
+ x + width - 0.5,
872
+ y + ERROR_TIP_ICON_SIZE,
873
+ ];
874
+ this.ctx.paint.drawLine(points, {
875
+ borderColor: ERROR_TIP_COLOR,
876
+ fillColor: ERROR_TIP_COLOR,
877
+ borderWidth: 1,
878
+ lineCap: 'round',
879
+ lineJoin: 'round',
880
+ });
881
+ }
882
+ drawBorder(options) {
883
+ const { drawX, drawY, width, rowIndex, colIndex } = this;
884
+ const x = drawX + 0.5;
885
+ let y = drawY + 0.5;
886
+ let height = this.height;
887
+ // 第一行减去1,不然会被表头覆盖
888
+ if (rowIndex === 0) {
889
+ y = this.y + 1;
890
+ height = height - 1;
891
+ }
892
+ const { xArr, yArr, lineDash = [], borderWidth = 1, borderColor, fillColor } = options;
893
+ const minX = xArr[0];
894
+ const maxX = xArr[1];
895
+ const minY = yArr[0];
896
+ const maxY = yArr[1];
897
+ // 选择
898
+ if (colIndex >= minX && colIndex <= maxX && rowIndex === minY) {
899
+ this.ctx.paint.drawLine([x, y, x + width - 2, y], {
900
+ borderColor,
901
+ fillColor,
902
+ borderWidth,
903
+ lineCap: 'round',
904
+ lineJoin: 'round',
905
+ lineDash,
906
+ });
907
+ }
908
+ // bottom border
909
+ if (colIndex >= minX && colIndex <= maxX && rowIndex === maxY) {
910
+ this.ctx.paint.drawLine([x, y + height - 1.5, x + width, y + height - 1.5], {
911
+ borderColor,
912
+ fillColor,
913
+ borderWidth,
914
+ lineCap: 'round',
915
+ lineJoin: 'round',
916
+ lineDash,
917
+ });
918
+ }
919
+ // left border
920
+ if (colIndex === minX && rowIndex >= minY && rowIndex <= maxY) {
921
+ this.ctx.paint.drawLine([x, y, x, y + height - 1], {
922
+ borderColor,
923
+ fillColor,
924
+ borderWidth,
925
+ lineCap: 'round',
926
+ lineJoin: 'round',
927
+ lineDash,
928
+ });
929
+ }
930
+ // right border
931
+ if (colIndex === maxX && rowIndex >= minY && rowIndex <= maxY) {
932
+ this.ctx.paint.drawLine([x + width - 1, y, x + width - 1, y + height - 1], {
933
+ borderColor,
934
+ fillColor,
935
+ borderWidth,
936
+ lineCap: 'round',
937
+ lineJoin: 'round',
938
+ lineDash,
939
+ });
940
+ }
941
+ }
942
+ }
943
+ //# sourceMappingURL=Cell.js.map