sheet-happens 0.0.50 → 0.0.52

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.
@@ -1,64 +1,46 @@
1
- import React, { useState, useMemo, useRef, useCallback, useLayoutEffect, forwardRef, useImperativeHandle } from 'react';
1
+ import React, { useState, useMemo, useCallback, useRef, useLayoutEffect, forwardRef, useImperativeHandle } from 'react';
2
2
  import useResizeObserver from 'use-resize-observer';
3
-
4
- function _extends() {
5
- _extends = Object.assign || function (target) {
6
- for (var i = 1; i < arguments.length; i++) {
7
- var source = arguments[i];
8
-
9
- for (var key in source) {
10
- if (Object.prototype.hasOwnProperty.call(source, key)) {
11
- target[key] = source[key];
12
- }
13
- }
14
- }
15
-
16
- return target;
17
- };
18
-
19
- return _extends.apply(this, arguments);
20
- }
21
-
22
- function _unsupportedIterableToArray(o, minLen) {
23
- if (!o) return;
24
- if (typeof o === "string") return _arrayLikeToArray(o, minLen);
25
- var n = Object.prototype.toString.call(o).slice(8, -1);
26
- if (n === "Object" && o.constructor) n = o.constructor.name;
27
- if (n === "Map" || n === "Set") return Array.from(o);
28
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
29
- }
30
-
31
- function _arrayLikeToArray(arr, len) {
32
- if (len == null || len > arr.length) len = arr.length;
33
-
34
- for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
35
-
36
- return arr2;
3
+ import { renderToString } from 'react-dom/server';
4
+ import toRGBA from 'color-rgba';
5
+ import LineBreak from 'linebreak';
6
+
7
+ function _arrayLikeToArray(r, a) {
8
+ (null == a || a > r.length) && (a = r.length);
9
+ for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
10
+ return n;
37
11
  }
38
-
39
- function _createForOfIteratorHelperLoose(o, allowArrayLike) {
40
- var it;
41
-
42
- if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) {
43
- if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
44
- if (it) o = it;
45
- var i = 0;
46
- return function () {
47
- if (i >= o.length) return {
48
- done: true
49
- };
50
- return {
51
- done: false,
52
- value: o[i++]
53
- };
12
+ function _createForOfIteratorHelperLoose(r, e) {
13
+ var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
14
+ if (t) return (t = t.call(r)).next.bind(t);
15
+ if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) {
16
+ t && (r = t);
17
+ var o = 0;
18
+ return function () {
19
+ return o >= r.length ? {
20
+ done: !0
21
+ } : {
22
+ done: !1,
23
+ value: r[o++]
54
24
  };
25
+ };
26
+ }
27
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
28
+ }
29
+ function _extends() {
30
+ return _extends = Object.assign ? Object.assign.bind() : function (n) {
31
+ for (var e = 1; e < arguments.length; e++) {
32
+ var t = arguments[e];
33
+ for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
55
34
  }
56
-
57
- throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
35
+ return n;
36
+ }, _extends.apply(null, arguments);
37
+ }
38
+ function _unsupportedIterableToArray(r, a) {
39
+ if (r) {
40
+ if ("string" == typeof r) return _arrayLikeToArray(r, a);
41
+ var t = {}.toString.call(r).slice(8, -1);
42
+ return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
58
43
  }
59
-
60
- it = o[Symbol.iterator]();
61
- return it.next.bind(it);
62
44
  }
63
45
 
64
46
  var styles = {"sheetscroll":"_PxIi8"};
@@ -105,22 +87,28 @@ var SIZES = {
105
87
  var DEFAULT_CELL_STYLE = {
106
88
  textAlign: 'left',
107
89
  fontSize: 12,
108
- marginRight: 5,
90
+ lineHeight: 16,
91
+ marginTop: 3,
92
+ marginBottom: 3,
109
93
  marginLeft: 5,
94
+ marginRight: 5,
110
95
  color: '#000',
111
96
  fontFamily: 'sans-serif',
112
- weight: '',
97
+ fontWeight: '',
113
98
  fillColor: '',
114
99
  backgroundColor: ''
115
100
  };
116
101
  var DEFAULT_COLUMN_HEADER_STYLE = {
117
102
  textAlign: 'center',
118
103
  fontSize: 12,
104
+ lineHeight: 16,
105
+ marginTop: 3,
106
+ marginBottom: 3,
119
107
  marginRight: 5,
120
108
  marginLeft: 5,
121
109
  color: '#000',
122
110
  fontFamily: 'sans-serif',
123
- weight: '',
111
+ fontWeight: '',
124
112
  fillColor: '',
125
113
  backgroundColor: ''
126
114
  };
@@ -146,11 +134,9 @@ var seq = function seq(n, s, d) {
146
134
  if (s === void 0) {
147
135
  s = 0;
148
136
  }
149
-
150
137
  if (d === void 0) {
151
138
  d = 1;
152
139
  }
153
-
154
140
  return Array.from({
155
141
  length: n
156
142
  }).map(function (_, i) {
@@ -192,41 +178,47 @@ var getDirectionStep = function getDirectionStep(direction) {
192
178
  var isSameXY = function isSameXY(a, b) {
193
179
  return a[0] === b[0] && a[1] === b[1];
194
180
  };
195
- var isSameSelection = function isSameSelection(a, b) {
181
+ var isSameRectangle = function isSameRectangle(a, b) {
196
182
  var a1 = a[0],
197
- a2 = a[1];
183
+ a2 = a[1];
198
184
  var b1 = b[0],
199
- b2 = b[1];
185
+ b2 = b[1];
200
186
  return isSameXY(a1, b1) && isSameXY(a2, b2);
201
187
  };
188
+ var isPointInsideRectangle = function isPointInsideRectangle(rectangle, point) {
189
+ var _rectangle$ = rectangle[0],
190
+ left = _rectangle$[0],
191
+ top = _rectangle$[1],
192
+ _rectangle$2 = rectangle[1],
193
+ right = _rectangle$2[0],
194
+ bottom = _rectangle$2[1];
195
+ var x = point[0],
196
+ y = point[1];
197
+ return x >= left && x < right && y >= top && y < bottom;
198
+ };
202
199
  var forRange = function forRange(min, max, callback) {
203
- for (var i = min; i <= max; ++i) {
204
- callback(i);
205
- }
200
+ for (var i = min; i <= max; ++i) callback(i);
206
201
  };
207
202
  var forSelectionColumns = function forSelectionColumns(selection) {
208
203
  return function (callback) {
209
204
  var _normalizeSelection = normalizeSelection(selection),
210
- _normalizeSelection$ = _normalizeSelection[0],
211
- left = _normalizeSelection$[0],
212
- _normalizeSelection$2 = _normalizeSelection[1],
213
- right = _normalizeSelection$2[0];
214
-
205
+ _normalizeSelection$ = _normalizeSelection[0],
206
+ left = _normalizeSelection$[0],
207
+ _normalizeSelection$2 = _normalizeSelection[1],
208
+ right = _normalizeSelection$2[0];
215
209
  forRange(left, right, callback);
216
210
  };
217
211
  };
218
212
  var forSelectionRows = function forSelectionRows(selection) {
219
213
  return function (callback) {
220
214
  var _normalizeSelection2 = normalizeSelection(selection),
221
- _normalizeSelection2$ = _normalizeSelection2[0],
222
- top = _normalizeSelection2$[1],
223
- _normalizeSelection2$2 = _normalizeSelection2[1],
224
- bottom = _normalizeSelection2$2[1];
225
-
215
+ _normalizeSelection2$ = _normalizeSelection2[0],
216
+ top = _normalizeSelection2$[1],
217
+ _normalizeSelection2$2 = _normalizeSelection2[1],
218
+ bottom = _normalizeSelection2$2[1];
226
219
  forRange(top, bottom, callback);
227
220
  };
228
221
  };
229
-
230
222
  var forToMap = function forToMap(forLoop) {
231
223
  return function (map) {
232
224
  var out = [];
@@ -236,7 +228,6 @@ var forToMap = function forToMap(forLoop) {
236
228
  return out;
237
229
  };
238
230
  };
239
-
240
231
  var mapSelectionColumns = function mapSelectionColumns(selection) {
241
232
  return forToMap(forSelectionColumns(selection));
242
233
  };
@@ -245,70 +236,69 @@ var mapSelectionRows = function mapSelectionRows(selection) {
245
236
  };
246
237
  var isMaybeRowSelection = function isMaybeRowSelection(selection) {
247
238
  var _selection$ = selection[0],
248
- left = _selection$[0],
249
- _selection$2 = selection[1],
250
- right = _selection$2[0];
239
+ left = _selection$[0],
240
+ _selection$2 = selection[1],
241
+ right = _selection$2[0];
251
242
  return left === -1 && right === -1;
252
243
  };
253
244
  var isMaybeColumnSelection = function isMaybeColumnSelection(selection) {
254
245
  var _selection$3 = selection[0],
255
- top = _selection$3[1],
256
- _selection$4 = selection[1],
257
- bottom = _selection$4[1];
246
+ top = _selection$3[1],
247
+ _selection$4 = selection[1],
248
+ bottom = _selection$4[1];
258
249
  return top === -1 && bottom === -1;
259
250
  };
260
251
  var isRowSelection = function isRowSelection(selection) {
261
252
  var _selection$5 = selection[0],
262
- left = _selection$5[0],
263
- top = _selection$5[1],
264
- _selection$6 = selection[1],
265
- right = _selection$6[0],
266
- bottom = _selection$6[1];
253
+ left = _selection$5[0],
254
+ top = _selection$5[1],
255
+ _selection$6 = selection[1],
256
+ right = _selection$6[0],
257
+ bottom = _selection$6[1];
267
258
  return left === -1 && right === -1 && top !== -1 && bottom !== -1;
268
259
  };
269
260
  var isColumnSelection = function isColumnSelection(selection) {
270
261
  var _selection$7 = selection[0],
271
- left = _selection$7[0],
272
- top = _selection$7[1],
273
- _selection$8 = selection[1],
274
- right = _selection$8[0],
275
- bottom = _selection$8[1];
262
+ left = _selection$7[0],
263
+ top = _selection$7[1],
264
+ _selection$8 = selection[1],
265
+ right = _selection$8[0],
266
+ bottom = _selection$8[1];
276
267
  return top === -1 && bottom === -1 && left !== -1 && right !== -1;
277
268
  };
278
269
  var isCellSelection = function isCellSelection(selection) {
279
270
  var _selection$9 = selection[0],
280
- left = _selection$9[0],
281
- top = _selection$9[1],
282
- _selection$10 = selection[1],
283
- right = _selection$10[0],
284
- bottom = _selection$10[1];
271
+ left = _selection$9[0],
272
+ top = _selection$9[1],
273
+ _selection$10 = selection[1],
274
+ right = _selection$10[0],
275
+ bottom = _selection$10[1];
285
276
  return left !== -1 && right !== -1 && top !== -1 && bottom !== -1;
286
277
  };
287
278
  var isEmptySelection = function isEmptySelection(selection) {
288
279
  var _selection$11 = selection[0],
289
- left = _selection$11[0],
290
- top = _selection$11[1],
291
- _selection$12 = selection[1],
292
- right = _selection$12[0],
293
- bottom = _selection$12[1];
280
+ left = _selection$11[0],
281
+ top = _selection$11[1],
282
+ _selection$12 = selection[1],
283
+ right = _selection$12[0],
284
+ bottom = _selection$12[1];
294
285
  return left === -1 && right === -1 && top === -1 && bottom === -1;
295
286
  };
296
287
  var isPointInsideSelection = function isPointInsideSelection(selection, point) {
297
288
  var _normalizeSelection3 = normalizeSelection(selection),
298
- _normalizeSelection3$ = _normalizeSelection3[0],
299
- left = _normalizeSelection3$[0],
300
- top = _normalizeSelection3$[1],
301
- _normalizeSelection3$2 = _normalizeSelection3[1],
302
- right = _normalizeSelection3$2[0],
303
- bottom = _normalizeSelection3$2[1];
304
-
289
+ _normalizeSelection3$ = _normalizeSelection3[0],
290
+ left = _normalizeSelection3$[0],
291
+ top = _normalizeSelection3$[1],
292
+ _normalizeSelection3$2 = _normalizeSelection3[1],
293
+ right = _normalizeSelection3$2[0],
294
+ bottom = _normalizeSelection3$2[1];
305
295
  var x = point[0],
306
- y = point[1];
296
+ y = point[1];
307
297
  return x >= left && x <= right && y >= top && y <= bottom;
308
298
  };
309
299
  var validateSelection = function validateSelection(selection) {
310
300
  var anchor = selection[0],
311
- head = selection[1];
301
+ head = selection[1];
312
302
  anchor = anchor.slice();
313
303
  head = head.slice();
314
304
  var min = minXY(anchor, head);
@@ -318,48 +308,157 @@ var validateSelection = function validateSelection(selection) {
318
308
  };
319
309
  var normalizeSelection = function normalizeSelection(selection) {
320
310
  var anchor = selection[0],
321
- head = selection[1];
311
+ head = selection[1];
322
312
  return [minXY(anchor, head), maxXY(anchor, head)];
323
313
  };
324
314
  var orientSelection = function orientSelection(normalized, to) {
325
315
  var _normalized$ = normalized[0],
326
- left = _normalized$[0],
327
- top = _normalized$[1],
328
- _normalized$2 = normalized[1],
329
- right = _normalized$2[0],
330
- bottom = _normalized$2[1];
316
+ left = _normalized$[0],
317
+ top = _normalized$[1],
318
+ _normalized$2 = normalized[1],
319
+ right = _normalized$2[0],
320
+ bottom = _normalized$2[1];
331
321
  var anchor = to[0],
332
- head = to[1];
322
+ head = to[1];
333
323
  var ax = anchor[0],
334
- ay = anchor[1];
324
+ ay = anchor[1];
335
325
  var hx = head[0],
336
- hy = head[1];
326
+ hy = head[1];
337
327
  var swapX = (ax - hx || 1) * (right - left || 1) < 0;
338
328
  var swapY = (ay - hy || 1) * (bottom - top || 1) < 0;
339
329
  return [[swapX ? right : left, swapY ? bottom : top], [swapX ? left : right, swapY ? top : bottom]];
340
330
  };
341
331
 
342
- var LIMIT = 1000;
332
+ var DEFAULT_ICON_SIZE = 32;
333
+ var svgToImage = function svgToImage(icon) {
334
+ var image = new Image();
335
+ try {
336
+ var iconAsString = typeof icon === 'string' ? icon : renderToString(icon);
337
+ var base64String = window.btoa(iconAsString);
338
+ image.src = "data:image/svg+xml;base64," + base64String;
339
+ } catch (err) {
340
+ console.log(err);
341
+ }
342
+ return image;
343
+ };
344
+ var useImageRenderer = function useImageRenderer() {
345
+ var _useState = useState(0),
346
+ setVersion = _useState[1];
347
+ var _useState2 = useState(DEFAULT_ICON_SIZE),
348
+ canvasWidth = _useState2[0],
349
+ setCanvasWidth = _useState2[1];
350
+ var _useState3 = useState(DEFAULT_ICON_SIZE),
351
+ canvasHeight = _useState3[0],
352
+ setCanvasHeight = _useState3[1];
353
+ var imageMap = useMemo(function () {
354
+ return new Map();
355
+ }, []);
356
+ var loadImage = useCallback(function (src) {
357
+ var image = imageMap.get(src);
358
+ if (image) return image;
359
+ image = new Image();
360
+ image.src = src;
361
+ imageMap.set(src, image);
362
+ return image;
363
+ }, [imageMap]);
364
+ var dpi = window.devicePixelRatio;
365
+ var iconContext = useMemo(function () {
366
+ var canvas = document.createElement('canvas');
367
+ canvas.width = canvasWidth * dpi;
368
+ canvas.height = canvasHeight * dpi;
369
+ var context = canvas.getContext('2d', {
370
+ willReadFrequently: true
371
+ });
372
+ return context;
373
+ }, [canvasWidth, canvasHeight, dpi]);
374
+ return function (renderContext, item, style, box) {
375
+ if (!iconContext) return;
376
+ var display = item.display;
377
+ var image = 'image' in item ? item.image : 'src' in item ? loadImage(item.src) : null;
378
+ if (!image) return;
379
+ if (!image.complete) {
380
+ if (!image.onload) {
381
+ image.onload = function () {
382
+ setVersion(function (v) {
383
+ return v + 1;
384
+ });
385
+ setCanvasWidth(function (w) {
386
+ return Math.max(w, image.width);
387
+ });
388
+ setCanvasHeight(function (h) {
389
+ return Math.max(h, image.height);
390
+ });
391
+ };
392
+ }
393
+ return;
394
+ } else {
395
+ if (canvasWidth < image.width) setCanvasWidth(function (w) {
396
+ return Math.max(w, image.width);
397
+ });
398
+ if (canvasHeight < image.height) setCanvasHeight(function (h) {
399
+ return Math.max(h, image.height);
400
+ });
401
+ }
402
+ var _box$ = box[0],
403
+ left = _box$[0],
404
+ top = _box$[1],
405
+ _box$2 = box[1],
406
+ right = _box$2[0],
407
+ bottom = _box$2[1];
408
+ var width = right - left;
409
+ var height = bottom - top;
410
+ if (display === 'image') {
411
+ renderContext.drawImage(image, 0, 0, image.width, image.height, left, top, width, height);
412
+ } else if (display === 'icon') {
413
+ var _item$color;
414
+ var color = (_item$color = item.color) != null ? _item$color : style.color;
415
+ var rgba = toRGBA(color);
416
+ var _rgba$ = rgba[0],
417
+ r = _rgba$ === void 0 ? 0 : _rgba$,
418
+ _rgba$2 = rgba[1],
419
+ g = _rgba$2 === void 0 ? 0 : _rgba$2,
420
+ _rgba$3 = rgba[2],
421
+ b = _rgba$3 === void 0 ? 0 : _rgba$3,
422
+ _rgba$4 = rgba[3],
423
+ a = _rgba$4 === void 0 ? 1 : _rgba$4;
424
+ try {
425
+ var wDpi = width * dpi;
426
+ var hDpi = height * dpi;
427
+ iconContext.clearRect(0, 0, wDpi, hDpi);
428
+ iconContext.drawImage(image, 0, 0, image.width, image.height, 0, 0, wDpi, hDpi);
429
+ var imageData = iconContext.getImageData(0, 0, wDpi, hDpi);
430
+ var data = imageData.data;
431
+ var n = data.length;
432
+ for (var i = 0; i < n; i += 4) {
433
+ data[i] = r;
434
+ data[i + 1] = g;
435
+ data[i + 2] = b;
436
+ data[i + 3] = data[i + 3] * a;
437
+ }
438
+ iconContext.putImageData(imageData, 0, 0, 0, 0, wDpi, hDpi);
439
+ renderContext.drawImage(iconContext.canvas, 0, 0, wDpi, hDpi, left, top, width, height);
440
+ } catch (e) {
441
+ console.error(e);
442
+ }
443
+ }
444
+ };
445
+ };
343
446
 
447
+ var LIMIT = 1000;
344
448
  var scanGroup = function scanGroup(keys, index, direction, matchKeys) {
345
449
  var i = 1;
346
450
  var limit = direction > 0 ? LIMIT : Math.min(LIMIT, index + 1);
347
-
348
451
  for (; i < limit; i++) {
349
452
  var key = keys(index + i * direction);
350
453
  if (key == null || !matchKeys.has(key)) break;
351
454
  }
352
-
353
455
  return index + (i - 1) * direction;
354
456
  };
355
-
356
457
  var expandSelectionToRowOrColumnGroups = function expandSelectionToRowOrColumnGroups(selection, groupKeys, matchKeys, coordinate) {
357
458
  if (!matchKeys) return selection;
358
-
359
459
  var _normalizeSelection = normalizeSelection(selection),
360
- first = _normalizeSelection[0],
361
- second = _normalizeSelection[1];
362
-
460
+ first = _normalizeSelection[0],
461
+ second = _normalizeSelection[1];
363
462
  var start = first[coordinate];
364
463
  var end = second[coordinate];
365
464
  var startIndex = scanGroup(groupKeys, start, -1, matchKeys);
@@ -474,164 +573,125 @@ var findApproxMaxEditDataIndex = function findApproxMaxEditDataIndex(editData) {
474
573
  var howManyEmpty = 0;
475
574
  var growthIncrement = 10;
476
575
  var growthIncrementFactor = 1.5;
477
-
478
576
  while (howManyEmpty < 4) {
479
577
  var allEmpty = true;
480
-
481
578
  for (var yy = 0; yy < 10; yy++) {
482
579
  var data = editData(x, yy);
483
-
484
580
  if (data !== null && data !== undefined && data !== '') {
485
581
  allEmpty = false;
486
582
  break;
487
583
  }
488
584
  }
489
-
490
585
  if (allEmpty) {
491
586
  howManyEmpty += 1;
492
587
  }
493
-
494
588
  x += growthIncrement;
495
-
496
589
  if (x > MAX_SEARCHABLE_INDEX) {
497
590
  break;
498
591
  }
499
-
500
592
  growthIncrement = Math.floor(growthIncrement * growthIncrementFactor);
501
593
  }
502
-
503
594
  howManyEmpty = 0;
504
595
  growthIncrement = 10;
505
596
  growthIncrementFactor = 1.5;
506
-
507
597
  while (howManyEmpty < 4) {
508
598
  var _allEmpty = true;
509
-
510
599
  for (var xx = 0; xx < 10; xx++) {
511
600
  var _data = editData(xx, y);
512
-
513
601
  if (_data !== null && _data !== undefined && _data !== '') {
514
602
  _allEmpty = false;
515
603
  break;
516
604
  }
517
605
  }
518
-
519
606
  if (_allEmpty) {
520
607
  howManyEmpty += 1;
521
608
  }
522
-
523
609
  y += growthIncrement;
524
-
525
610
  if (y > MAX_SEARCHABLE_INDEX) {
526
611
  break;
527
612
  }
528
-
529
613
  growthIncrement = Math.floor(growthIncrement * growthIncrementFactor);
530
614
  }
531
-
532
615
  return [x, y];
533
616
  };
534
617
  var findInDisplayData = function findInDisplayData(displayData, start, direction) {
535
618
  var step = getDirectionStep(direction);
536
619
  var cell = maxXY(start, ORIGIN);
537
-
538
620
  var _addXY = addXY(cell, step),
539
- x = _addXY[0],
540
- y = _addXY[1];
541
-
621
+ x = _addXY[0],
622
+ y = _addXY[1];
542
623
  var first = displayData(x, y, DEFAULT_CELL_STYLE);
543
624
  var firstFilled = first !== '' && first !== null && first !== undefined;
544
-
545
625
  if (!firstFilled) {
546
626
  cell = addXY(cell, step);
547
627
  }
548
-
549
628
  var _cell = cell,
550
- cellX = _cell[0],
551
- cellY = _cell[1];
629
+ cellX = _cell[0],
630
+ cellY = _cell[1];
552
631
  var maxX = cellX + MAX_SEARCHABLE_INDEX - 1;
553
632
  var maxY = cellY + MAX_SEARCHABLE_INDEX - 1;
554
-
555
633
  while (cellX < maxX && cellY < maxY && cellX >= 0 && cellY >= 0) {
556
634
  var data = displayData(cellX, cellY, DEFAULT_CELL_STYLE);
557
-
558
635
  if (firstFilled && (data === '' || data === null || data === undefined)) {
559
636
  return subXY(cell, step);
560
637
  }
561
-
562
638
  if (!firstFilled && data !== '' && data !== null && data !== undefined) {
563
639
  return cell;
564
640
  }
565
-
566
641
  var _cell2 = cell = addXY(cell, step);
567
-
568
642
  cellX = _cell2[0];
569
643
  cellY = _cell2[1];
570
644
  }
571
-
572
645
  return maxXY(cell, [0, 0]);
573
646
  };
574
647
 
575
- var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editData, sourceData, cellReadOnly, canSizeColumn, canSizeRow, canOrderColumn, canOrderRow, cellLayout, visibleCells, sheetStyle, columnGroupKeys, rowGroupKeys, selectedColumnGroups, selectedRowGroups, getAutoSizeWidth, onEdit, onCommit, onKnobAreaChange, onDragIndicesChange, onDragOffsetChange, onDropTargetChange, onSelectionChange, onFocusChange, onInvalidateColumn, onInvalidateRow, onChange, onColumnOrderChange, onRowOrderChange, onCellWidthChange, onCellHeightChange, onRightClick, dontCommitEditOnSelectionChange, dontChangeSelectionOnOrderChange) {
648
+ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editData, sourceData, cellReadOnly, canSizeColumn, canSizeRow, canOrderColumn, canOrderRow, cellLayout, visibleCells, sheetStyle, columnGroupKeys, rowGroupKeys, selectedColumnGroups, selectedRowGroups, getAutoSizeWidth, getAutoSizeHeight, onEdit, onCommit, onKnobAreaChange, onDragIndicesChange, onDragOffsetChange, onDropTargetChange, onSelectionChange, onFocusChange, onInvalidateColumn, onInvalidateRow, onChange, onColumnOrderChange, onRowOrderChange, onCellWidthChange, onCellHeightChange, onRightClick, dontCommitEditOnSelectionChange, dontChangeSelectionOnOrderChange) {
576
649
  var _useState = useState(null),
577
- hitTarget = _useState[0],
578
- setHitTarget = _useState[1];
579
-
650
+ columnResize = _useState[0],
651
+ setColumnResize = _useState[1];
580
652
  var _useState2 = useState(null),
581
- columnResize = _useState2[0],
582
- setColumnResize = _useState2[1];
583
-
653
+ rowResize = _useState2[0],
654
+ setRowResize = _useState2[1];
584
655
  var _useState3 = useState(null),
585
- rowResize = _useState3[0],
586
- setRowResize = _useState3[1];
587
-
656
+ columnDrag = _useState3[0],
657
+ setColumnDrag = _useState3[1];
588
658
  var _useState4 = useState(null),
589
- columnDrag = _useState4[0],
590
- setColumnDrag = _useState4[1];
591
-
659
+ rowDrag = _useState4[0],
660
+ setRowDrag = _useState4[1];
592
661
  var _useState5 = useState(null),
593
- rowDrag = _useState5[0],
594
- setRowDrag = _useState5[1];
595
-
662
+ hitTestDown = _useState5[0],
663
+ setHitTestDown = _useState5[1];
596
664
  var _useState6 = useState(false),
597
- draggingKnob = _useState6[0],
598
- setDraggingKnob = _useState6[1];
599
-
665
+ draggingKnob = _useState6[0],
666
+ setDraggingKnob = _useState6[1];
600
667
  var _useState7 = useState(false),
601
- draggingSelection = _useState7[0],
602
- setDraggingSelection = _useState7[1];
603
-
668
+ draggingSelection = _useState7[0],
669
+ setDraggingSelection = _useState7[1];
604
670
  var _useState8 = useState(false),
605
- draggingRowSelection = _useState8[0],
606
- setDraggingRowSelection = _useState8[1];
607
-
671
+ draggingRowSelection = _useState8[0],
672
+ setDraggingRowSelection = _useState8[1];
608
673
  var _useState9 = useState(false),
609
- draggingColumnSelection = _useState9[0],
610
- setDraggingColumnSelection = _useState9[1];
611
-
674
+ draggingColumnSelection = _useState9[0],
675
+ setDraggingColumnSelection = _useState9[1];
612
676
  var hideRowHeaders = sheetStyle.hideRowHeaders,
613
- hideColumnHeaders = sheetStyle.hideColumnHeaders;
677
+ hideColumnHeaders = sheetStyle.hideColumnHeaders;
614
678
  var cellToPixel = cellLayout.cellToPixel,
615
- getVersion = cellLayout.getVersion;
679
+ getVersion = cellLayout.getVersion;
616
680
  var version = getVersion();
617
681
  var knobPosition = useMemo(function () {
618
682
  var _normalizeSelection = normalizeSelection(selection),
619
- _normalizeSelection$ = _normalizeSelection[1],
620
- maxX = _normalizeSelection$[0],
621
- maxY = _normalizeSelection$[1];
622
-
683
+ _normalizeSelection$ = _normalizeSelection[1],
684
+ maxX = _normalizeSelection$[0],
685
+ maxY = _normalizeSelection$[1];
623
686
  if (isRowSelection(selection)) {
624
687
  return subXY(addXY(cellToPixel([0, maxY], [0, 1]), [SIZES.knobArea * 0.5, 0]), ONE_ONE);
625
688
  }
626
-
627
689
  if (isColumnSelection(selection)) {
628
690
  return subXY(addXY(cellToPixel([maxX, 0], [1, 0]), [0, SIZES.knobArea * 0.5]), ONE_ONE);
629
691
  }
630
-
631
692
  if (isCellSelection(selection)) {
632
693
  return subXY(cellToPixel([maxX, maxY], ONE_ONE), ONE_ONE);
633
694
  }
634
-
635
695
  return null;
636
696
  }, [selection, cellToPixel, version]);
637
697
  var refState = {
@@ -642,7 +702,6 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
642
702
  sourceData: sourceData,
643
703
  cellLayout: cellLayout,
644
704
  visibleCells: visibleCells,
645
- hitTarget: hitTarget,
646
705
  knobPosition: knobPosition,
647
706
  columnResize: columnResize,
648
707
  rowResize: rowResize,
@@ -659,40 +718,33 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
659
718
  if (!e.target || !(e.target instanceof Element)) {
660
719
  return null;
661
720
  }
662
-
663
721
  var rect = e.target.getBoundingClientRect();
664
722
  var xy = [e.clientX - rect.left, e.clientY - rect.top];
665
-
666
723
  if (xy[0] > e.target.clientWidth || xy[1] > e.target.clientHeight) {
667
724
  return null;
668
725
  }
669
-
670
726
  return xy;
671
727
  }, []);
672
728
  var getScrollPosition = useCallback(function (e) {
673
729
  if (!e.target || !(e.target instanceof Element)) {
674
730
  return [0, 0];
675
731
  }
676
-
677
732
  var _e$target = e.target,
678
- scrollLeft = _e$target.scrollLeft,
679
- scrollTop = _e$target.scrollTop;
733
+ scrollLeft = _e$target.scrollLeft,
734
+ scrollTop = _e$target.scrollTop;
680
735
  var xy = [scrollLeft, scrollTop];
681
736
  return xy;
682
737
  }, []);
683
738
  var getMouseHit = useCallback(function (xy) {
684
739
  var hitmap = hitmapRef.current;
685
740
  if (!hitmap) return null;
686
-
687
741
  for (var _iterator = _createForOfIteratorHelperLoose(hitmap), _step; !(_step = _iterator()).done;) {
688
742
  var object = _step.value;
689
- var rect = object.rect;
690
-
691
- if (isPointInsideSelection(rect, xy)) {
743
+ var box = object.box;
744
+ if (isPointInsideRectangle(box, xy)) {
692
745
  return object;
693
746
  }
694
747
  }
695
-
696
748
  return null;
697
749
  }, [hitmapRef]);
698
750
  var onPointerLeave = useCallback(function () {
@@ -700,61 +752,49 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
700
752
  }, []);
701
753
  var onPointerDown = useCallback(function (e) {
702
754
  var _e$target2, _e$target2$setPointer;
703
-
704
755
  var _ref$current = ref.current,
705
- selection = _ref$current.selection,
706
- _ref$current$cellLayo = _ref$current.cellLayout,
707
- columnToPixel = _ref$current$cellLayo.columnToPixel,
708
- rowToPixel = _ref$current$cellLayo.rowToPixel,
709
- pixelToCell = _ref$current$cellLayo.pixelToCell,
710
- getIndentX = _ref$current$cellLayo.getIndentX,
711
- getIndentY = _ref$current$cellLayo.getIndentY,
712
- _ref$current$visibleC = _ref$current.visibleCells,
713
- columns = _ref$current$visibleC.columns,
714
- rows = _ref$current$visibleC.rows,
715
- knobPosition = _ref$current.knobPosition;
756
+ selection = _ref$current.selection,
757
+ _ref$current$cellLayo = _ref$current.cellLayout,
758
+ columnToPixel = _ref$current$cellLayo.columnToPixel,
759
+ rowToPixel = _ref$current$cellLayo.rowToPixel,
760
+ pixelToCell = _ref$current$cellLayo.pixelToCell,
761
+ getIndentX = _ref$current$cellLayo.getIndentX,
762
+ getIndentY = _ref$current$cellLayo.getIndentY,
763
+ _ref$current$visibleC = _ref$current.visibleCells,
764
+ columns = _ref$current$visibleC.columns,
765
+ rows = _ref$current$visibleC.rows,
766
+ knobPosition = _ref$current.knobPosition;
716
767
  onFocusChange === null || onFocusChange === void 0 ? void 0 : onFocusChange(true);
717
768
  if (e.button !== 0) return;
718
769
  (_e$target2 = e.target) === null || _e$target2 === void 0 ? void 0 : (_e$target2$setPointer = _e$target2.setPointerCapture) === null || _e$target2$setPointer === void 0 ? void 0 : _e$target2$setPointer.call(_e$target2, e.pointerId);
719
770
  var xy = getMousePosition(e);
720
771
  if (!xy) return;
721
- var x = xy[0],
722
- y = xy[1];
723
772
  var hitTarget = getMouseHit(xy);
724
-
725
- if (hitTarget) {
726
- setHitTarget(hitTarget);
727
- ref.current.hitTarget = hitTarget;
728
- return;
729
- }
730
-
773
+ setHitTestDown(hitTarget);
774
+ var x = xy[0],
775
+ y = xy[1];
731
776
  var normalized = normalizeSelection(selection);
732
777
  var _normalized$ = normalized[0],
733
- minX = _normalized$[0],
734
- minY = _normalized$[1],
735
- _normalized$2 = normalized[1],
736
- maxX = _normalized$2[0],
737
- maxY = _normalized$2[1];
778
+ minX = _normalized$[0],
779
+ minY = _normalized$[1],
780
+ _normalized$2 = normalized[1],
781
+ maxX = _normalized$2[0],
782
+ maxY = _normalized$2[1];
738
783
  var selectedColumns = mapSelectionColumns(selection)(function (i) {
739
784
  return i;
740
785
  });
741
786
  var selectedRows = mapSelectionRows(selection)(function (i) {
742
787
  return i;
743
788
  });
744
-
745
789
  if (!hideColumnHeaders && y < getIndentY()) {
746
790
  if (onColumnOrderChange) {
747
791
  var start = columnToPixel(minX) + SIZES.resizeZone;
748
792
  var end = columnToPixel(maxX, 1) - SIZES.resizeZone;
749
-
750
793
  if (isInRange(x, start, end) || selectedColumnGroups) {
751
794
  for (var _iterator2 = _createForOfIteratorHelperLoose(columns), _step2; !(_step2 = _iterator2()).done;) {
752
795
  var index = _step2.value;
753
-
754
796
  var _start = columnToPixel(index, 0);
755
-
756
797
  var _end = columnToPixel(index, 1);
757
-
758
798
  if (isColumnSelection(selection) && isInRange(x, _start, _end) && (isInRange(index, minX, maxX) || selectedColumnGroups !== null && selectedColumnGroups !== void 0 && selectedColumnGroups.has(columnGroupKeys(index))) && canOrderColumn(index)) {
759
799
  window.document.body.style.cursor = 'grabbing';
760
800
  var indices = Array.from(new Set([].concat(selectedColumns, selectedColumnGroups ? columns.filter(function (index) {
@@ -764,27 +804,21 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
764
804
  return a - b;
765
805
  });
766
806
  var dragIndices = indices;
767
-
768
807
  if (selectedColumnGroups) {
769
808
  var clickSelection = [[index, -1], [index, -1]];
770
-
771
809
  var _expandSelectionToRow = expandSelectionToRowOrColumnGroups(clickSelection, columnGroupKeys, selectedColumnGroups, 0),
772
- _expandSelectionToRow2 = _expandSelectionToRow[0],
773
- left = _expandSelectionToRow2[0],
774
- _expandSelectionToRow3 = _expandSelectionToRow[1],
775
- right = _expandSelectionToRow3[0];
776
-
810
+ _expandSelectionToRow2 = _expandSelectionToRow[0],
811
+ left = _expandSelectionToRow2[0],
812
+ _expandSelectionToRow3 = _expandSelectionToRow[1],
813
+ right = _expandSelectionToRow3[0];
777
814
  var connected = !(minX > right || maxX < left);
778
815
  var dragStart = connected ? Math.min(minX, left) : left;
779
816
  var dragEnd = connected ? Math.max(maxX, right) : right;
780
817
  dragIndices = seq(dragEnd - dragStart + 1, dragStart);
781
818
  }
782
-
783
819
  var size = columnToPixel(maxX, 1) - columnToPixel(minX);
784
-
785
820
  var _getScrollPosition = getScrollPosition(e),
786
- scroll = _getScrollPosition[0];
787
-
821
+ scroll = _getScrollPosition[0];
788
822
  setColumnDrag({
789
823
  anchor: x,
790
824
  scroll: scroll,
@@ -798,24 +832,17 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
798
832
  }
799
833
  }
800
834
  }
801
-
802
835
  if (onCellWidthChange) {
803
- for (var _iterator3 = _createForOfIteratorHelperLoose(columns), _step3; !(_step3 = _iterator3()).done;) {
804
- var _index = _step3.value;
836
+ for (var _i = 0, _arr = [-1].concat(columns); _i < _arr.length; _i++) {
837
+ var _index = _arr[_i];
805
838
  var edge = columnToPixel(_index, 1);
806
-
807
839
  if (Math.abs(edge - x) < SIZES.resizeZone && canSizeColumn(_index)) {
808
840
  window.document.body.style.cursor = 'col-resize';
809
-
810
841
  var asGroup = isColumnSelection(selection) && maxX === _index;
811
-
812
842
  var _indices = asGroup ? selectedColumns : [_index];
813
-
814
843
  var _size = asGroup ? columnToPixel(maxX, 1) - columnToPixel(minX) : columnToPixel(_index, 1) - columnToPixel(_index);
815
-
816
844
  var _getScrollPosition2 = getScrollPosition(e),
817
- _scroll = _getScrollPosition2[0];
818
-
845
+ _scroll = _getScrollPosition2[0];
819
846
  setColumnResize({
820
847
  anchor: x,
821
848
  scroll: _scroll,
@@ -827,59 +854,41 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
827
854
  }
828
855
  }
829
856
  }
830
-
831
857
  if (!hideRowHeaders && x < getIndentX()) {
832
858
  if (onRowOrderChange) {
833
859
  var _start2 = rowToPixel(minY) + SIZES.resizeZone;
834
-
835
860
  var _end2 = rowToPixel(maxY, 1) - SIZES.resizeZone;
836
-
837
861
  if (isInRange(y, _start2, _end2) || selectedRowGroups) {
838
- for (var _iterator4 = _createForOfIteratorHelperLoose(rows), _step4; !(_step4 = _iterator4()).done;) {
839
- var _index2 = _step4.value;
840
-
862
+ for (var _iterator3 = _createForOfIteratorHelperLoose(rows), _step3; !(_step3 = _iterator3()).done;) {
863
+ var _index2 = _step3.value;
841
864
  var _start3 = rowToPixel(_index2, 0);
842
-
843
865
  var _end3 = rowToPixel(_index2, 1);
844
-
845
866
  if (isRowSelection(selection) && isInRange(y, _start3, _end3) && (isInRange(_index2, minY, maxY) || selectedRowGroups !== null && selectedRowGroups !== void 0 && selectedRowGroups.has(rowGroupKeys(_index2))) && canOrderRow(_index2)) {
846
867
  window.document.body.style.cursor = 'grabbing';
847
-
848
868
  var _indices2 = Array.from(new Set([].concat(selectedRows, selectedRowGroups ? rows.map(function (_, i) {
849
869
  return i;
850
870
  }).filter(function (index) {
851
871
  return selectedRowGroups.has(rowGroupKeys(index));
852
872
  }) : [])).values());
853
-
854
873
  _indices2.sort(function (a, b) {
855
874
  return a - b;
856
875
  });
857
-
858
876
  var _dragIndices = _indices2;
859
-
860
877
  if (selectedRowGroups) {
861
878
  var _clickSelection = [[-1, _index2], [-1, _index2]];
862
-
863
879
  var _expandSelectionToRow4 = expandSelectionToRowOrColumnGroups(_clickSelection, rowGroupKeys, selectedRowGroups, 1),
864
- _expandSelectionToRow5 = _expandSelectionToRow4[0],
865
- top = _expandSelectionToRow5[1],
866
- _expandSelectionToRow6 = _expandSelectionToRow4[1],
867
- bottom = _expandSelectionToRow6[1];
868
-
880
+ _expandSelectionToRow5 = _expandSelectionToRow4[0],
881
+ top = _expandSelectionToRow5[1],
882
+ _expandSelectionToRow6 = _expandSelectionToRow4[1],
883
+ bottom = _expandSelectionToRow6[1];
869
884
  var _connected = !(minY > bottom || maxY < top);
870
-
871
885
  var _dragStart = _connected ? Math.min(minY, top) : top;
872
-
873
886
  var _dragEnd = _connected ? Math.max(maxY, bottom) : bottom;
874
-
875
887
  _dragIndices = seq(_dragEnd - _dragStart + 1, _dragStart);
876
888
  }
877
-
878
889
  var _size2 = rowToPixel(maxY, 1) - rowToPixel(minY);
879
-
880
890
  var _getScrollPosition3 = getScrollPosition(e),
881
- _scroll2 = _getScrollPosition3[1];
882
-
891
+ _scroll2 = _getScrollPosition3[1];
883
892
  setRowDrag({
884
893
  anchor: y,
885
894
  scroll: _scroll2,
@@ -893,25 +902,17 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
893
902
  }
894
903
  }
895
904
  }
896
-
897
905
  if (onCellHeightChange) {
898
- for (var _iterator5 = _createForOfIteratorHelperLoose(rows), _step5; !(_step5 = _iterator5()).done;) {
899
- var _index3 = _step5.value;
900
-
906
+ for (var _i2 = 0, _arr2 = [-1].concat(rows); _i2 < _arr2.length; _i2++) {
907
+ var _index3 = _arr2[_i2];
901
908
  var _edge = rowToPixel(_index3, 1);
902
-
903
909
  if (Math.abs(_edge - y) < SIZES.resizeZone && canSizeRow(_index3)) {
904
910
  window.document.body.style.cursor = 'row-resize';
905
-
906
911
  var _asGroup = isRowSelection(selection) && maxY === _index3;
907
-
908
912
  var _indices3 = _asGroup ? selectedRows : [_index3];
909
-
910
913
  var _size3 = _asGroup ? rowToPixel(maxY, 1) - rowToPixel(minY) : rowToPixel(_index3, 1) - rowToPixel(_index3);
911
-
912
914
  var _getScrollPosition4 = getScrollPosition(e),
913
- _scroll3 = _getScrollPosition4[1];
914
-
915
+ _scroll3 = _getScrollPosition4[1];
915
916
  setRowResize({
916
917
  anchor: y,
917
918
  scroll: _scroll3,
@@ -923,95 +924,78 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
923
924
  }
924
925
  }
925
926
  }
926
-
927
927
  if (knobPosition) {
928
928
  var knobX = knobPosition[0],
929
- knobY = knobPosition[1];
930
-
929
+ knobY = knobPosition[1];
931
930
  if (Math.abs(x - knobX) < SIZES.knobArea && Math.abs(y - knobY) < SIZES.knobArea) {
932
931
  setDraggingKnob(true);
933
932
  onKnobAreaChange === null || onKnobAreaChange === void 0 ? void 0 : onKnobAreaChange(selection);
934
933
  return;
935
934
  }
936
935
  }
937
-
938
936
  var head = pixelToCell(xy);
939
937
  var anchor = e.shiftKey ? [].concat(selection[0]) : head;
940
-
941
938
  if (editMode) {
942
939
  if (!dontCommitEditOnSelectionChange) {
943
940
  onCommit === null || onCommit === void 0 ? void 0 : onCommit();
944
941
  }
945
942
  }
946
-
947
943
  var scrollTo = true;
948
-
949
944
  if (!hideRowHeaders && x < getIndentX()) {
950
945
  scrollTo = false;
951
946
  setDraggingRowSelection(true);
952
947
  anchor[0] = -1;
953
948
  head[0] = -1;
954
949
  }
955
-
956
950
  if (!hideColumnHeaders && y < getIndentY()) {
957
951
  scrollTo = false;
958
952
  setDraggingColumnSelection(true);
959
953
  anchor[1] = -1;
960
954
  head[1] = -1;
961
955
  }
962
-
963
956
  setDraggingSelection(true);
964
957
  onSelectionChange === null || onSelectionChange === void 0 ? void 0 : onSelectionChange([anchor, head], scrollTo, true);
965
958
  }, [getMousePosition, getScrollPosition, getMouseHit, onColumnOrderChange, onRowOrderChange, onCellWidthChange, onCellHeightChange, onKnobAreaChange, onSelectionChange, onCommit, canSizeColumn, canSizeRow, canOrderColumn, canOrderRow, dontCommitEditOnSelectionChange, columnGroupKeys, rowGroupKeys, selectedColumnGroups, selectedRowGroups]);
966
959
  var onPointerUp = useCallback(function (e) {
967
960
  var _ref$current2 = ref.current,
968
- knobArea = _ref$current2.knobArea,
969
- selection = _ref$current2.selection,
970
- sourceData = _ref$current2.sourceData,
971
- editData = _ref$current2.editData,
972
- columnDrag = _ref$current2.columnDrag,
973
- rowDrag = _ref$current2.rowDrag,
974
- draggingKnob = _ref$current2.draggingKnob,
975
- _ref$current2$cellLay = _ref$current2.cellLayout,
976
- pixelToColumn = _ref$current2$cellLay.pixelToColumn,
977
- pixelToRow = _ref$current2$cellLay.pixelToRow,
978
- getIndentX = _ref$current2$cellLay.getIndentX,
979
- getIndentY = _ref$current2$cellLay.getIndentY;
961
+ knobArea = _ref$current2.knobArea,
962
+ selection = _ref$current2.selection,
963
+ sourceData = _ref$current2.sourceData,
964
+ editData = _ref$current2.editData,
965
+ columnDrag = _ref$current2.columnDrag,
966
+ rowDrag = _ref$current2.rowDrag,
967
+ draggingKnob = _ref$current2.draggingKnob,
968
+ _ref$current2$cellLay = _ref$current2.cellLayout,
969
+ pixelToColumn = _ref$current2$cellLay.pixelToColumn,
970
+ pixelToRow = _ref$current2$cellLay.pixelToRow;
980
971
  onFocusChange === null || onFocusChange === void 0 ? void 0 : onFocusChange(true);
981
-
982
972
  if (knobArea && draggingKnob) {
983
973
  var changes = parseKnobOperation(knobArea, selection, sourceData, editData, cellReadOnly);
984
974
  onChange === null || onChange === void 0 ? void 0 : onChange(changes);
985
975
  onSelectionChange === null || onSelectionChange === void 0 ? void 0 : onSelectionChange(knobArea, true, true);
986
976
  onKnobAreaChange === null || onKnobAreaChange === void 0 ? void 0 : onKnobAreaChange(null);
987
977
  }
988
-
989
978
  var xy = getMousePosition(e);
990
-
991
979
  if (xy && (columnDrag || rowDrag)) {
992
980
  window.document.body.style.cursor = 'auto';
993
981
  onDragIndicesChange === null || onDragIndicesChange === void 0 ? void 0 : onDragIndicesChange([null, null]);
994
982
  onDragOffsetChange === null || onDragOffsetChange === void 0 ? void 0 : onDragOffsetChange(null);
995
983
  onDropTargetChange === null || onDropTargetChange === void 0 ? void 0 : onDropTargetChange(null);
996
984
  var x = xy[0],
997
- y = xy[1];
998
-
985
+ y = xy[1];
999
986
  var _normalizeSelection2 = normalizeSelection(selection),
1000
- _normalizeSelection2$ = _normalizeSelection2[0],
1001
- minX = _normalizeSelection2$[0],
1002
- minY = _normalizeSelection2$[1],
1003
- _normalizeSelection2$2 = _normalizeSelection2[1],
1004
- maxX = _normalizeSelection2$2[0],
1005
- maxY = _normalizeSelection2$2[1];
1006
-
1007
- var cellX = pixelToColumn(Math.max(x, getIndentX()), 0.5);
1008
- var cellY = pixelToRow(Math.max(y, getIndentY()), 0.5);
1009
-
987
+ _normalizeSelection2$ = _normalizeSelection2[0],
988
+ minX = _normalizeSelection2$[0],
989
+ minY = _normalizeSelection2$[1],
990
+ _normalizeSelection2$2 = _normalizeSelection2[1],
991
+ maxX = _normalizeSelection2$2[0],
992
+ maxY = _normalizeSelection2$2[1];
993
+ var cellX = Math.max(0, pixelToColumn(x, 0.5));
994
+ var cellY = Math.max(0, pixelToRow(y, 0.5));
1010
995
  if (columnDrag) {
1011
996
  var indices = columnDrag.indices;
1012
997
  var insideSelection = cellX >= minX && cellX <= maxX + 1;
1013
998
  var insideGroup = selectedColumnGroups === null || selectedColumnGroups === void 0 ? void 0 : selectedColumnGroups.has(columnGroupKeys(x));
1014
-
1015
999
  if (!insideSelection && !insideGroup) {
1016
1000
  var preceding = indices.filter(function (i) {
1017
1001
  return i < cellX;
@@ -1022,28 +1006,21 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
1022
1006
  onInvalidateColumn === null || onInvalidateColumn === void 0 ? void 0 : onInvalidateColumn(Math.min(minX, order));
1023
1007
  }
1024
1008
  }
1025
-
1026
1009
  if (rowDrag) {
1027
1010
  var _indices4 = rowDrag.indices;
1028
-
1029
1011
  var _insideSelection = cellY >= minY && cellY <= maxY + 1;
1030
-
1031
1012
  var _insideGroup = selectedRowGroups === null || selectedRowGroups === void 0 ? void 0 : selectedRowGroups.has(rowGroupKeys(y));
1032
-
1033
1013
  if (!_insideSelection && !_insideGroup) {
1034
1014
  var _preceding = _indices4.filter(function (i) {
1035
1015
  return i < cellY;
1036
1016
  });
1037
-
1038
1017
  var _order = cellY - _preceding.length;
1039
-
1040
1018
  dontChangeSelectionOnOrderChange || (onSelectionChange === null || onSelectionChange === void 0 ? void 0 : onSelectionChange([[minX, _order], [maxX, _order + _indices4.length - 1]]));
1041
1019
  onRowOrderChange === null || onRowOrderChange === void 0 ? void 0 : onRowOrderChange(_indices4, _order);
1042
1020
  onInvalidateRow === null || onInvalidateRow === void 0 ? void 0 : onInvalidateRow(Math.min(minY, _order));
1043
1021
  }
1044
1022
  }
1045
1023
  }
1046
-
1047
1024
  setDraggingSelection(false);
1048
1025
  setDraggingRowSelection(false);
1049
1026
  setDraggingColumnSelection(false);
@@ -1055,33 +1032,30 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
1055
1032
  }, [getMousePosition, getMouseHit, onChange, onSelectionChange, onKnobAreaChange, onDropTargetChange, onColumnOrderChange, onRowOrderChange, dontChangeSelectionOnOrderChange]);
1056
1033
  var onPointerMove = useCallback(function (e) {
1057
1034
  var _ref$current3 = ref.current,
1058
- selection = _ref$current3.selection,
1059
- visibleCells = _ref$current3.visibleCells,
1060
- knobPosition = _ref$current3.knobPosition,
1061
- columnResize = _ref$current3.columnResize,
1062
- columnDrag = _ref$current3.columnDrag,
1063
- rowResize = _ref$current3.rowResize,
1064
- rowDrag = _ref$current3.rowDrag,
1065
- draggingKnob = _ref$current3.draggingKnob,
1066
- draggingSelection = _ref$current3.draggingSelection,
1067
- draggingColumnSelection = _ref$current3.draggingColumnSelection,
1068
- draggingRowSelection = _ref$current3.draggingRowSelection,
1069
- _ref$current3$cellLay = _ref$current3.cellLayout,
1070
- columnToPixel = _ref$current3$cellLay.columnToPixel,
1071
- rowToPixel = _ref$current3$cellLay.rowToPixel,
1072
- pixelToCell = _ref$current3$cellLay.pixelToCell,
1073
- pixelToColumn = _ref$current3$cellLay.pixelToColumn,
1074
- pixelToRow = _ref$current3$cellLay.pixelToRow,
1075
- getIndentX = _ref$current3$cellLay.getIndentX,
1076
- getIndentY = _ref$current3$cellLay.getIndentY;
1035
+ selection = _ref$current3.selection,
1036
+ visibleCells = _ref$current3.visibleCells,
1037
+ knobPosition = _ref$current3.knobPosition,
1038
+ columnResize = _ref$current3.columnResize,
1039
+ columnDrag = _ref$current3.columnDrag,
1040
+ rowResize = _ref$current3.rowResize,
1041
+ rowDrag = _ref$current3.rowDrag,
1042
+ draggingKnob = _ref$current3.draggingKnob,
1043
+ draggingSelection = _ref$current3.draggingSelection,
1044
+ draggingColumnSelection = _ref$current3.draggingColumnSelection,
1045
+ draggingRowSelection = _ref$current3.draggingRowSelection,
1046
+ _ref$current3$cellLay = _ref$current3.cellLayout,
1047
+ columnToPixel = _ref$current3$cellLay.columnToPixel,
1048
+ rowToPixel = _ref$current3$cellLay.rowToPixel,
1049
+ pixelToCell = _ref$current3$cellLay.pixelToCell,
1050
+ pixelToColumn = _ref$current3$cellLay.pixelToColumn,
1051
+ pixelToRow = _ref$current3$cellLay.pixelToRow,
1052
+ getIndentX = _ref$current3$cellLay.getIndentX,
1053
+ getIndentY = _ref$current3$cellLay.getIndentY;
1077
1054
  window.document.body.style.cursor = 'auto';
1078
1055
  var xy = getMousePosition(e);
1079
1056
  if (!xy) return;
1080
1057
  var hitTarget = getMouseHit(xy);
1081
-
1082
- if (hitTarget) {
1083
- window.document.body.style.cursor = 'pointer';
1084
- } else if (columnDrag || rowDrag) {
1058
+ if (columnDrag || rowDrag) {
1085
1059
  window.document.body.style.cursor = 'grabbing';
1086
1060
  } else if (columnResize) {
1087
1061
  window.document.body.style.cursor = 'col-resize';
@@ -1091,37 +1065,31 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
1091
1065
  e.preventDefault();
1092
1066
  } else if (draggingRowSelection || draggingColumnSelection) {
1093
1067
  e.preventDefault();
1068
+ } else if (hitTarget) {
1069
+ window.document.body.style.cursor = 'pointer';
1094
1070
  }
1095
-
1096
1071
  var columns = visibleCells.columns,
1097
- rows = visibleCells.rows;
1072
+ rows = visibleCells.rows;
1098
1073
  var x = xy[0],
1099
- y = xy[1];
1100
-
1074
+ y = xy[1];
1101
1075
  var _normalizeSelection3 = normalizeSelection(selection),
1102
- _normalizeSelection3$ = _normalizeSelection3[0],
1103
- minX = _normalizeSelection3$[0],
1104
- minY = _normalizeSelection3$[1],
1105
- _normalizeSelection3$2 = _normalizeSelection3[1],
1106
- maxX = _normalizeSelection3$2[0],
1107
- maxY = _normalizeSelection3$2[1];
1108
-
1076
+ _normalizeSelection3$ = _normalizeSelection3[0],
1077
+ minX = _normalizeSelection3$[0],
1078
+ minY = _normalizeSelection3$[1],
1079
+ _normalizeSelection3$2 = _normalizeSelection3[1],
1080
+ maxX = _normalizeSelection3$2[0],
1081
+ maxY = _normalizeSelection3$2[1];
1109
1082
  var isDragging = columnResize || columnDrag || rowResize || rowDrag || draggingRowSelection || draggingColumnSelection;
1110
-
1111
1083
  if (!isDragging) {
1112
1084
  if (!hideColumnHeaders && y < getIndentY()) {
1113
1085
  if (onColumnOrderChange) {
1114
1086
  var start = columnToPixel(minX) + SIZES.resizeZone;
1115
1087
  var end = columnToPixel(maxX, 1) - SIZES.resizeZone;
1116
-
1117
1088
  if (isInRange(x, start, end) || selectedColumnGroups) {
1118
- for (var _iterator6 = _createForOfIteratorHelperLoose(columns), _step6; !(_step6 = _iterator6()).done;) {
1119
- var index = _step6.value;
1120
-
1089
+ for (var _iterator4 = _createForOfIteratorHelperLoose(columns), _step4; !(_step4 = _iterator4()).done;) {
1090
+ var index = _step4.value;
1121
1091
  var _start4 = columnToPixel(index);
1122
-
1123
1092
  var _end4 = columnToPixel(index, 1);
1124
-
1125
1093
  if (!draggingColumnSelection && isColumnSelection(selection) && isInRange(x, _start4, _end4) && (isInRange(index, minX, maxX) || selectedColumnGroups !== null && selectedColumnGroups !== void 0 && selectedColumnGroups.has(columnGroupKeys(index))) && canOrderColumn(index)) {
1126
1094
  window.document.body.style.cursor = 'grab';
1127
1095
  return;
@@ -1129,12 +1097,10 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
1129
1097
  }
1130
1098
  }
1131
1099
  }
1132
-
1133
1100
  if (onCellWidthChange) {
1134
- for (var _iterator7 = _createForOfIteratorHelperLoose(columns), _step7; !(_step7 = _iterator7()).done;) {
1135
- var _index4 = _step7.value;
1101
+ for (var _i3 = 0, _arr3 = [-1].concat(columns); _i3 < _arr3.length; _i3++) {
1102
+ var _index4 = _arr3[_i3];
1136
1103
  var edge = columnToPixel(_index4, 1);
1137
-
1138
1104
  if (Math.abs(edge - x) < SIZES.resizeZone && canSizeColumn(_index4)) {
1139
1105
  window.document.body.style.cursor = 'col-resize';
1140
1106
  return;
@@ -1142,21 +1108,15 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
1142
1108
  }
1143
1109
  }
1144
1110
  }
1145
-
1146
1111
  if (!hideRowHeaders && x < getIndentX()) {
1147
1112
  if (onRowOrderChange) {
1148
1113
  var _start5 = rowToPixel(minY) + SIZES.resizeZone;
1149
-
1150
1114
  var _end5 = rowToPixel(maxY, 1) - SIZES.resizeZone;
1151
-
1152
1115
  if (isInRange(y, _start5, _end5) || selectedRowGroups) {
1153
- for (var _iterator8 = _createForOfIteratorHelperLoose(rows), _step8; !(_step8 = _iterator8()).done;) {
1154
- var _index5 = _step8.value;
1155
-
1116
+ for (var _iterator5 = _createForOfIteratorHelperLoose(rows), _step5; !(_step5 = _iterator5()).done;) {
1117
+ var _index5 = _step5.value;
1156
1118
  var _start6 = rowToPixel(_index5);
1157
-
1158
1119
  var _end6 = rowToPixel(_index5, 1);
1159
-
1160
1120
  if (!draggingRowSelection && isRowSelection(selection) && isInRange(y, _start6, _end6) && (isInRange(_index5, minY, maxY) || selectedRowGroups !== null && selectedRowGroups !== void 0 && selectedRowGroups.has(rowGroupKeys(_index5))) && canOrderRow(_index5)) {
1161
1121
  window.document.body.style.cursor = 'grab';
1162
1122
  return;
@@ -1164,13 +1124,10 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
1164
1124
  }
1165
1125
  }
1166
1126
  }
1167
-
1168
1127
  if (onCellHeightChange) {
1169
- for (var _iterator9 = _createForOfIteratorHelperLoose(rows), _step9; !(_step9 = _iterator9()).done;) {
1170
- var _index6 = _step9.value;
1171
-
1128
+ for (var _i4 = 0, _arr4 = [-1].concat(rows); _i4 < _arr4.length; _i4++) {
1129
+ var _index6 = _arr4[_i4];
1172
1130
  var _edge2 = rowToPixel(_index6, 1);
1173
-
1174
1131
  if (Math.abs(_edge2 - y) < SIZES.resizeZone && canSizeRow(_index6)) {
1175
1132
  window.document.body.style.cursor = 'row-resize';
1176
1133
  return;
@@ -1178,66 +1135,54 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
1178
1135
  }
1179
1136
  }
1180
1137
  }
1181
-
1182
1138
  if (knobPosition) {
1183
1139
  var knobX = knobPosition[0],
1184
- knobY = knobPosition[1];
1185
-
1140
+ knobY = knobPosition[1];
1186
1141
  if (Math.abs(x - knobX) < SIZES.knobArea && Math.abs(y - knobY) < SIZES.knobArea) {
1187
1142
  window.document.body.style.cursor = 'crosshair';
1188
1143
  return;
1189
1144
  }
1190
1145
  }
1191
1146
  }
1192
-
1193
1147
  if (columnResize) {
1194
1148
  if (onCellWidthChange) {
1195
1149
  var size = columnResize.size,
1196
- anchor = columnResize.anchor,
1197
- scroll = columnResize.scroll,
1198
- indices = columnResize.indices;
1199
-
1150
+ anchor = columnResize.anchor,
1151
+ scroll = columnResize.scroll,
1152
+ indices = columnResize.indices;
1200
1153
  var _getScrollPosition5 = getScrollPosition(e),
1201
- currentScroll = _getScrollPosition5[0];
1202
-
1154
+ currentScroll = _getScrollPosition5[0];
1203
1155
  var newWidth = Math.round(Math.max(size + x - anchor + scroll - currentScroll, SIZES.minimumWidth * indices.length));
1204
1156
  onInvalidateColumn === null || onInvalidateColumn === void 0 ? void 0 : onInvalidateColumn(indices[0] - 1);
1205
1157
  onCellWidthChange(indices, indices.map(function (_) {
1206
1158
  return Math.round(newWidth / indices.length);
1207
1159
  }));
1208
1160
  }
1209
-
1210
1161
  return;
1211
1162
  }
1212
-
1213
1163
  if (rowResize) {
1214
1164
  if (onCellHeightChange) {
1215
1165
  var _size4 = rowResize.size,
1216
- _anchor = rowResize.anchor,
1217
- _scroll4 = rowResize.scroll,
1218
- _indices5 = rowResize.indices;
1219
-
1166
+ _anchor = rowResize.anchor,
1167
+ _scroll4 = rowResize.scroll,
1168
+ _indices5 = rowResize.indices;
1220
1169
  var _getScrollPosition6 = getScrollPosition(e),
1221
- _currentScroll = _getScrollPosition6[1];
1222
-
1170
+ _currentScroll = _getScrollPosition6[1];
1223
1171
  var newHeight = Math.round(Math.max(_size4 + y - _anchor + _scroll4 - _currentScroll, SIZES.minimumHeight * _indices5.length));
1224
1172
  onInvalidateRow === null || onInvalidateRow === void 0 ? void 0 : onInvalidateRow(_indices5[0] - 1);
1225
1173
  onCellHeightChange(_indices5, _indices5.map(function (_) {
1226
1174
  return newHeight / _indices5.length;
1227
1175
  }));
1228
1176
  }
1229
-
1230
1177
  return;
1231
1178
  }
1232
-
1233
1179
  if (draggingSelection) {
1234
1180
  var _anchor2 = selection[0];
1235
1181
  var head = pixelToCell(xy);
1236
1182
  var anchorX = _anchor2[0],
1237
- anchorY = _anchor2[1];
1183
+ anchorY = _anchor2[1];
1238
1184
  var headX = head[0],
1239
- headY = head[1];
1240
-
1185
+ headY = head[1];
1241
1186
  if (draggingRowSelection) {
1242
1187
  onSelectionChange === null || onSelectionChange === void 0 ? void 0 : onSelectionChange([[-1, anchorY], [-1, Math.max(0, headY)]], false);
1243
1188
  } else if (draggingColumnSelection) {
@@ -1246,25 +1191,20 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
1246
1191
  onSelectionChange === null || onSelectionChange === void 0 ? void 0 : onSelectionChange([maxXY(_anchor2, ORIGIN), maxXY(head, ORIGIN)], false);
1247
1192
  }
1248
1193
  }
1249
-
1250
1194
  if (draggingKnob) {
1251
1195
  window.document.body.style.cursor = 'crosshair';
1252
-
1253
1196
  var _pixelToCell = pixelToCell(xy),
1254
- cellX = _pixelToCell[0],
1255
- cellY = _pixelToCell[1];
1256
-
1197
+ cellX = _pixelToCell[0],
1198
+ cellY = _pixelToCell[1];
1257
1199
  var _normalizeSelection4 = normalizeSelection(selection),
1258
- _normalizeSelection4$ = _normalizeSelection4[0],
1259
- _minX = _normalizeSelection4$[0],
1260
- _minY = _normalizeSelection4$[1],
1261
- _normalizeSelection4$2 = _normalizeSelection4[1],
1262
- _maxX = _normalizeSelection4$2[0],
1263
- _maxY = _normalizeSelection4$2[1];
1264
-
1200
+ _normalizeSelection4$ = _normalizeSelection4[0],
1201
+ _minX = _normalizeSelection4$[0],
1202
+ _minY = _normalizeSelection4$[1],
1203
+ _normalizeSelection4$2 = _normalizeSelection4[1],
1204
+ _maxX = _normalizeSelection4$2[0],
1205
+ _maxY = _normalizeSelection4$2[1];
1265
1206
  var xCellDiff = Math.min(cellX - _minX, _maxX - cellX, 0);
1266
1207
  var yCellDiff = Math.min(cellY - _minY, _maxY - cellY, 0);
1267
-
1268
1208
  if (isMaybeRowSelection(selection) || xCellDiff > yCellDiff) {
1269
1209
  if (cellY < _minY) {
1270
1210
  _minY = cellY;
@@ -1278,156 +1218,152 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
1278
1218
  _maxX = cellX;
1279
1219
  }
1280
1220
  }
1281
-
1282
1221
  onKnobAreaChange === null || onKnobAreaChange === void 0 ? void 0 : onKnobAreaChange([[_minX, _minY], [_maxX, _maxY]]);
1283
1222
  }
1284
-
1285
1223
  if (columnDrag || rowDrag) {
1286
1224
  var _x = xy[0],
1287
- _y = xy[1];
1288
-
1225
+ _y = xy[1];
1289
1226
  if (columnDrag) {
1290
- var _cellX = pixelToColumn(Math.max(_x, getIndentX()), 0.5);
1291
-
1227
+ var _cellX = Math.max(0, pixelToColumn(_x, 0.5));
1292
1228
  var insideSelection = _cellX >= minX && _cellX <= maxX + 1;
1293
1229
  var insideGroup = isBoundaryInsideGroup(_cellX, columnGroupKeys);
1294
1230
  var _anchor3 = columnDrag.anchor,
1295
- _scroll5 = columnDrag.scroll;
1231
+ _scroll5 = columnDrag.scroll;
1296
1232
  var shift = _x - _anchor3;
1297
-
1298
1233
  var _getScrollPosition7 = getScrollPosition(e),
1299
- _currentScroll2 = _getScrollPosition7[0];
1300
-
1234
+ _currentScroll2 = _getScrollPosition7[0];
1301
1235
  onDragOffsetChange === null || onDragOffsetChange === void 0 ? void 0 : onDragOffsetChange([shift + _currentScroll2 - _scroll5, 0]);
1302
1236
  onDropTargetChange === null || onDropTargetChange === void 0 ? void 0 : onDropTargetChange(insideSelection || insideGroup ? null : [[_cellX, -1], [_cellX, -1]]);
1303
1237
  }
1304
-
1305
1238
  if (rowDrag) {
1306
- var _cellY = pixelToRow(Math.max(_y, getIndentY()), 0.5);
1307
-
1239
+ var _cellY = Math.max(0, pixelToRow(_y, 0.5));
1308
1240
  var _insideSelection2 = _cellY >= minY && _cellY <= maxY + 1;
1309
-
1310
1241
  var _insideGroup2 = isBoundaryInsideGroup(_cellY, rowGroupKeys);
1311
-
1312
1242
  var _anchor4 = rowDrag.anchor,
1313
- _scroll6 = rowDrag.scroll;
1314
-
1243
+ _scroll6 = rowDrag.scroll;
1315
1244
  var _shift = _y - _anchor4;
1316
-
1317
1245
  var _getScrollPosition8 = getScrollPosition(e),
1318
- _currentScroll3 = _getScrollPosition8[1];
1319
-
1246
+ _currentScroll3 = _getScrollPosition8[1];
1320
1247
  onDragOffsetChange === null || onDragOffsetChange === void 0 ? void 0 : onDragOffsetChange([0, _shift + _currentScroll3 - _scroll6]);
1321
1248
  onDropTargetChange === null || onDropTargetChange === void 0 ? void 0 : onDropTargetChange(_insideSelection2 || _insideGroup2 ? null : [[-1, _cellY], [-1, _cellY]]);
1322
1249
  }
1323
1250
  }
1324
1251
  }, [getMousePosition, getScrollPosition, getMouseHit, onCellWidthChange, onCellHeightChange, onDragIndicesChange, onDragOffsetChange, onDropTargetChange, onSelectionChange, onKnobAreaChange, onInvalidateRow, onInvalidateColumn, columnGroupKeys, rowGroupKeys]);
1325
1252
  var onClick = useCallback(function (e) {
1326
- var _getMouseHit;
1327
-
1328
- var hitTarget = ref.current.hitTarget;
1329
- if (!hitTarget) return;
1330
1253
  var xy = getMousePosition(e);
1331
1254
  if (!xy) return;
1332
- setHitTarget(null);
1333
- var previousRect = JSON.stringify(hitTarget.rect);
1334
- var currentRect = JSON.stringify((_getMouseHit = getMouseHit(xy)) === null || _getMouseHit === void 0 ? void 0 : _getMouseHit.rect);
1335
-
1336
- if (previousRect === currentRect) {
1337
- var _obj$onClick;
1338
-
1339
- var obj = hitTarget.obj;
1340
- (_obj$onClick = obj.onClick) === null || _obj$onClick === void 0 ? void 0 : _obj$onClick.call(obj, e);
1255
+ var mouseHit = getMouseHit(xy);
1256
+ if (hitTestDown && mouseHit) {
1257
+ if (isSameRectangle(hitTestDown.box, mouseHit.box)) {
1258
+ var _mouseHit$item, _mouseHit$item$onClic;
1259
+ mouseHit === null || mouseHit === void 0 ? void 0 : (_mouseHit$item = mouseHit.item) === null || _mouseHit$item === void 0 ? void 0 : (_mouseHit$item$onClic = _mouseHit$item.onClick) === null || _mouseHit$item$onClic === void 0 ? void 0 : _mouseHit$item$onClic.call(_mouseHit$item, e);
1260
+ }
1341
1261
  }
1342
- }, [getMousePosition, getMouseHit]);
1262
+ setHitTestDown(null);
1263
+ }, [getMousePosition, getMouseHit, hitTestDown]);
1343
1264
  var onDoubleClick = useCallback(function (e) {
1344
1265
  var _ref$current4 = ref.current,
1345
- selection = _ref$current4.selection,
1346
- _ref$current4$cellLay = _ref$current4.cellLayout,
1347
- pixelToCell = _ref$current4$cellLay.pixelToCell,
1348
- columnToPixel = _ref$current4$cellLay.columnToPixel,
1349
- getIndentY = _ref$current4$cellLay.getIndentY;
1266
+ selection = _ref$current4.selection,
1267
+ _ref$current4$cellLay = _ref$current4.cellLayout,
1268
+ pixelToCell = _ref$current4$cellLay.pixelToCell,
1269
+ columnToPixel = _ref$current4$cellLay.columnToPixel,
1270
+ rowToPixel = _ref$current4$cellLay.rowToPixel,
1271
+ getIndentX = _ref$current4$cellLay.getIndentX,
1272
+ getIndentY = _ref$current4$cellLay.getIndentY;
1350
1273
  e.preventDefault();
1351
1274
  if (e.shiftKey) return;
1352
1275
  var xy = getMousePosition(e);
1353
1276
  if (!xy) return;
1354
1277
  var x = xy[0],
1355
- y = xy[1];
1278
+ y = xy[1];
1356
1279
  var indentY = getIndentY();
1357
1280
  var columns = visibleCells.columns;
1358
-
1359
1281
  if (onCellWidthChange && y < indentY) {
1360
1282
  var autosized = [];
1361
-
1362
- for (var _iterator10 = _createForOfIteratorHelperLoose(columns), _step10; !(_step10 = _iterator10()).done;) {
1363
- var index = _step10.value;
1283
+ for (var _iterator6 = _createForOfIteratorHelperLoose(columns), _step6; !(_step6 = _iterator6()).done;) {
1284
+ var index = _step6.value;
1364
1285
  var edge = columnToPixel(index, 1);
1365
-
1366
1286
  if (Math.abs(edge - x) < SIZES.resizeZone && canSizeColumn(index)) {
1367
1287
  var _normalizeSelection5 = normalizeSelection(selection),
1368
- _normalizeSelection5$ = _normalizeSelection5[0],
1369
- minX = _normalizeSelection5$[0],
1370
- _normalizeSelection5$2 = _normalizeSelection5[1],
1371
- maxX = _normalizeSelection5$2[0];
1372
-
1288
+ _normalizeSelection5$ = _normalizeSelection5[0],
1289
+ minX = _normalizeSelection5$[0],
1290
+ _normalizeSelection5$2 = _normalizeSelection5[1],
1291
+ maxX = _normalizeSelection5$2[0];
1373
1292
  var indices = isColumnSelection(selection) && index >= minX && index <= maxX ? mapSelectionColumns(selection)(function (i) {
1374
1293
  return i;
1375
1294
  }) : [index];
1376
1295
  autosized.push.apply(autosized, indices);
1377
1296
  }
1378
1297
  }
1379
-
1380
- for (var _i = 0, _autosized = autosized; _i < _autosized.length; _i++) {
1381
- var column = _autosized[_i];
1298
+ for (var _i5 = 0, _autosized = autosized; _i5 < _autosized.length; _i5++) {
1299
+ var column = _autosized[_i5];
1382
1300
  onInvalidateColumn === null || onInvalidateColumn === void 0 ? void 0 : onInvalidateColumn(column - 1);
1383
1301
  }
1384
-
1385
1302
  onCellWidthChange(autosized, autosized.map(function (column) {
1386
1303
  return getAutoSizeWidth(column);
1387
1304
  }));
1388
1305
  if (autosized.length) return;
1389
1306
  }
1390
-
1307
+ var indentX = getIndentX();
1308
+ var rows = visibleCells.rows;
1309
+ if (onCellHeightChange && x < indentX) {
1310
+ var _autosized2 = [];
1311
+ for (var _i6 = 0, _arr5 = [-1].concat(rows); _i6 < _arr5.length; _i6++) {
1312
+ var _index7 = _arr5[_i6];
1313
+ var _edge3 = _index7 < 0 ? rowToPixel(0) : rowToPixel(_index7, 1);
1314
+ if (Math.abs(_edge3 - y) < SIZES.resizeZone && canSizeRow(_index7)) {
1315
+ var _normalizeSelection6 = normalizeSelection(selection),
1316
+ _normalizeSelection6$ = _normalizeSelection6[0],
1317
+ minY = _normalizeSelection6$[1],
1318
+ _normalizeSelection6$2 = _normalizeSelection6[1],
1319
+ maxY = _normalizeSelection6$2[1];
1320
+ var _indices6 = isRowSelection(selection) && _index7 >= minY && _index7 <= maxY ? mapSelectionRows(selection)(function (i) {
1321
+ return i;
1322
+ }) : [_index7];
1323
+ _autosized2.push.apply(_autosized2, _indices6);
1324
+ }
1325
+ }
1326
+ for (var _i7 = 0, _autosized3 = _autosized2; _i7 < _autosized3.length; _i7++) {
1327
+ var row = _autosized3[_i7];
1328
+ onInvalidateRow === null || onInvalidateRow === void 0 ? void 0 : onInvalidateRow(row - 1);
1329
+ }
1330
+ onCellHeightChange(_autosized2, _autosized2.map(function (row) {
1331
+ return getAutoSizeHeight(row);
1332
+ }));
1333
+ if (_autosized2.length) return;
1334
+ }
1391
1335
  var hitTarget = getMouseHit(xy);
1392
-
1393
1336
  if (hitTarget) {
1394
1337
  window.document.body.style.cursor = 'pointer';
1395
1338
  return;
1396
1339
  }
1397
-
1398
1340
  var editCell = pixelToCell(xy);
1399
1341
  if (editMode) onCommit === null || onCommit === void 0 ? void 0 : onCommit();
1400
1342
  onEdit === null || onEdit === void 0 ? void 0 : onEdit(editCell);
1401
1343
  }, [getMousePosition, getMouseHit, onCommit, onEdit, onInvalidateColumn, onCellWidthChange, getAutoSizeWidth, visibleCells, canSizeColumn]);
1402
1344
  var onContextMenu = useCallback(function (e) {
1403
1345
  var _ref$current$cellLayo2 = ref.current.cellLayout,
1404
- pixelToCell = _ref$current$cellLayo2.pixelToCell,
1405
- getIndentX = _ref$current$cellLayo2.getIndentX,
1406
- getIndentY = _ref$current$cellLayo2.getIndentY;
1346
+ pixelToCell = _ref$current$cellLayo2.pixelToCell,
1347
+ getIndentX = _ref$current$cellLayo2.getIndentX,
1348
+ getIndentY = _ref$current$cellLayo2.getIndentY;
1407
1349
  var xy = getMousePosition(e);
1408
1350
  if (!xy) return;
1409
1351
  var x = xy[0],
1410
- y = xy[1];
1411
-
1352
+ y = xy[1];
1412
1353
  if (x <= getIndentX() || y <= getIndentY()) {
1413
1354
  return;
1414
1355
  }
1415
-
1416
1356
  var cell = pixelToCell(xy);
1417
-
1418
1357
  if (!isPointInsideSelection(selection, cell)) {
1419
1358
  onSelectionChange === null || onSelectionChange === void 0 ? void 0 : onSelectionChange([cell, cell]);
1420
1359
  }
1421
-
1422
1360
  onPointerMove(e);
1423
1361
  var cellX = cell[0],
1424
- cellY = cell[1];
1425
-
1362
+ cellY = cell[1];
1426
1363
  var event = _extends({}, e, {
1427
1364
  cellX: cellX,
1428
1365
  cellY: cellY
1429
1366
  });
1430
-
1431
1367
  onRightClick === null || onRightClick === void 0 ? void 0 : onRightClick(event);
1432
1368
  }, [getMousePosition, onSelectionChange, onPointerMove, onRightClick]);
1433
1369
  var mouseHandlers = {
@@ -1444,51 +1380,42 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
1444
1380
  mouseHandlers: mouseHandlers
1445
1381
  };
1446
1382
  };
1447
-
1448
1383
  var parseKnobOperation = function parseKnobOperation(knobArea, selection, sourceData, editData, cellReadOnly) {
1449
- var _normalizeSelection6 = normalizeSelection(knobArea),
1450
- _normalizeSelection6$ = _normalizeSelection6[0],
1451
- kx1 = _normalizeSelection6$[0],
1452
- ky1 = _normalizeSelection6$[1],
1453
- _normalizeSelection6$2 = _normalizeSelection6[1],
1454
- kx2 = _normalizeSelection6$2[0],
1455
- ky2 = _normalizeSelection6$2[1];
1456
-
1457
- var _normalizeSelection7 = normalizeSelection(selection),
1458
- _normalizeSelection7$ = _normalizeSelection7[0],
1459
- sx1 = _normalizeSelection7$[0],
1460
- sy1 = _normalizeSelection7$[1],
1461
- _normalizeSelection7$2 = _normalizeSelection7[1],
1462
- sx2 = _normalizeSelection7$2[0],
1463
- sy2 = _normalizeSelection7$2[1];
1464
-
1384
+ var _normalizeSelection7 = normalizeSelection(knobArea),
1385
+ _normalizeSelection7$ = _normalizeSelection7[0],
1386
+ kx1 = _normalizeSelection7$[0],
1387
+ ky1 = _normalizeSelection7$[1],
1388
+ _normalizeSelection7$2 = _normalizeSelection7[1],
1389
+ kx2 = _normalizeSelection7$2[0],
1390
+ ky2 = _normalizeSelection7$2[1];
1391
+ var _normalizeSelection8 = normalizeSelection(selection),
1392
+ _normalizeSelection8$ = _normalizeSelection8[0],
1393
+ sx1 = _normalizeSelection8$[0],
1394
+ sy1 = _normalizeSelection8$[1],
1395
+ _normalizeSelection8$2 = _normalizeSelection8[1],
1396
+ sx2 = _normalizeSelection8$2[0],
1397
+ sy2 = _normalizeSelection8$2[1];
1465
1398
  var fx1 = kx1;
1466
1399
  var fy1 = ky1;
1467
1400
  var fx2 = kx2;
1468
1401
  var fy2 = ky2;
1469
1402
  var changes = [];
1470
-
1471
1403
  if (fx2 - fx1 === sx2 - sx1) {
1472
1404
  if (fy1 === sy1) {
1473
1405
  fy1 = sy2 + 1;
1474
1406
  } else {
1475
1407
  fy2 = sy1 - 1;
1476
1408
  }
1477
-
1478
1409
  if (fx1 === -1 && fx2 === -1) {
1479
1410
  var _findApproxMaxEditDat = findApproxMaxEditDataIndex(editData),
1480
- maxX = _findApproxMaxEditDat[0];
1481
-
1411
+ maxX = _findApproxMaxEditDat[0];
1482
1412
  fx1 = 0;
1483
1413
  fx2 = maxX;
1484
1414
  }
1485
-
1486
1415
  var srcY = sy1;
1487
-
1488
1416
  for (var y = fy1; y <= fy2; y++) {
1489
1417
  for (var x = fx1; x <= fx2; x++) {
1490
1418
  var value = sourceData(x, srcY);
1491
-
1492
1419
  if (!cellReadOnly(x, y)) {
1493
1420
  changes.push({
1494
1421
  x: x,
@@ -1501,9 +1428,7 @@ var parseKnobOperation = function parseKnobOperation(knobArea, selection, source
1501
1428
  });
1502
1429
  }
1503
1430
  }
1504
-
1505
1431
  srcY = srcY + 1;
1506
-
1507
1432
  if (srcY > sy2) {
1508
1433
  srcY = sy1;
1509
1434
  }
@@ -1514,21 +1439,16 @@ var parseKnobOperation = function parseKnobOperation(knobArea, selection, source
1514
1439
  } else {
1515
1440
  fx2 = sx1 - 1;
1516
1441
  }
1517
-
1518
1442
  if (fy1 === -1 && fy2 === -1) {
1519
1443
  var _findApproxMaxEditDat2 = findApproxMaxEditDataIndex(editData),
1520
- maxY = _findApproxMaxEditDat2[1];
1521
-
1444
+ maxY = _findApproxMaxEditDat2[1];
1522
1445
  fy1 = 0;
1523
1446
  fy2 = maxY;
1524
1447
  }
1525
-
1526
1448
  var srcX = sx1;
1527
-
1528
1449
  for (var _x2 = fx1; _x2 <= fx2; _x2++) {
1529
1450
  for (var _y2 = fy1; _y2 <= fy2; _y2++) {
1530
1451
  var _value = sourceData(srcX, _y2);
1531
-
1532
1452
  if (!cellReadOnly(_x2, _y2)) {
1533
1453
  changes.push({
1534
1454
  x: _x2,
@@ -1541,15 +1461,12 @@ var parseKnobOperation = function parseKnobOperation(knobArea, selection, source
1541
1461
  });
1542
1462
  }
1543
1463
  }
1544
-
1545
1464
  srcX = srcX + 1;
1546
-
1547
1465
  if (srcX > sx2) {
1548
1466
  srcX = sx1;
1549
1467
  }
1550
1468
  }
1551
1469
  }
1552
-
1553
1470
  return changes;
1554
1471
  };
1555
1472
 
@@ -1559,9 +1476,7 @@ var useKeyboard = function useKeyboard(arrowKeyCommitMode, overlayRef, cellReadO
1559
1476
  onCancel === null || onCancel === void 0 ? void 0 : onCancel();
1560
1477
  return;
1561
1478
  }
1562
-
1563
1479
  var direction = e.key === 'Enter' ? 'down' : e.key === 'Tab' ? 'right' : arrowKeyCommitMode ? ARROW_KEYS[e.key] : null;
1564
-
1565
1480
  if (direction) {
1566
1481
  e.preventDefault();
1567
1482
  var step = getDirectionStep(direction);
@@ -1570,48 +1485,39 @@ var useKeyboard = function useKeyboard(arrowKeyCommitMode, overlayRef, cellReadO
1570
1485
  onSelectionChange === null || onSelectionChange === void 0 ? void 0 : onSelectionChange([head, head]);
1571
1486
  }
1572
1487
  };
1573
-
1574
1488
  var onGridKeyDown = function onGridKeyDown(e) {
1575
1489
  if (editMode && arrowKeyCommitMode && e.key in ARROW_KEYS) {
1576
1490
  onCommit === null || onCommit === void 0 ? void 0 : onCommit();
1577
1491
  return;
1578
1492
  }
1579
-
1580
1493
  if ((e.metaKey || e.ctrlKey) && String.fromCharCode(e.which).toLowerCase() === 'v') {
1581
1494
  return;
1582
1495
  }
1583
-
1584
1496
  if ((e.metaKey || e.ctrlKey) && String.fromCharCode(e.which).toLowerCase() === 'c') {
1585
1497
  onClipboardCopy === null || onClipboardCopy === void 0 ? void 0 : onClipboardCopy(false);
1586
1498
  return;
1587
1499
  }
1588
-
1589
1500
  if ((e.metaKey || e.ctrlKey) && String.fromCharCode(e.which).toLowerCase() === 'x') {
1590
1501
  onClipboardCopy === null || onClipboardCopy === void 0 ? void 0 : onClipboardCopy(true);
1591
1502
  return;
1592
1503
  }
1593
-
1594
1504
  if (e.key === 'Backspace' || e.key === 'Delete') {
1595
1505
  var _normalizeSelection = normalizeSelection(selection),
1596
- _normalizeSelection$ = _normalizeSelection[0],
1597
- x1 = _normalizeSelection$[0],
1598
- y1 = _normalizeSelection$[1],
1599
- _normalizeSelection$2 = _normalizeSelection[1],
1600
- x2 = _normalizeSelection$2[0],
1601
- y2 = _normalizeSelection$2[1];
1602
-
1506
+ _normalizeSelection$ = _normalizeSelection[0],
1507
+ x1 = _normalizeSelection$[0],
1508
+ y1 = _normalizeSelection$[1],
1509
+ _normalizeSelection$2 = _normalizeSelection[1],
1510
+ x2 = _normalizeSelection$2[0],
1511
+ y2 = _normalizeSelection$2[1];
1603
1512
  if (isRowSelection(selection)) {
1604
1513
  x1 = 0;
1605
1514
  x2 = MAX_SEARCHABLE_INDEX;
1606
1515
  }
1607
-
1608
1516
  if (isColumnSelection(selection)) {
1609
1517
  y1 = 0;
1610
1518
  y2 = MAX_SEARCHABLE_INDEX;
1611
1519
  }
1612
-
1613
1520
  var changes = [];
1614
-
1615
1521
  for (var y = y1; y <= y2; y++) {
1616
1522
  for (var x = x1; x <= x2; x++) {
1617
1523
  if (!cellReadOnly(x, y)) {
@@ -1623,79 +1529,61 @@ var useKeyboard = function useKeyboard(arrowKeyCommitMode, overlayRef, cellReadO
1623
1529
  }
1624
1530
  }
1625
1531
  }
1626
-
1627
1532
  onChange === null || onChange === void 0 ? void 0 : onChange(changes);
1628
1533
  return;
1629
1534
  }
1630
-
1631
1535
  if (isEmptySelection(selection)) {
1632
1536
  return;
1633
1537
  }
1634
-
1635
1538
  if (e.keyCode >= 48 && e.keyCode <= 57 || e.keyCode >= 96 && e.keyCode <= 105 || e.keyCode >= 65 && e.keyCode <= 90 || e.key === 'Enter' || e.key === '-' || e.key === '.' || e.key === ',') {
1636
1539
  var cell = selection[0];
1637
1540
  var cellX = cell[0],
1638
- cellY = cell[1];
1639
-
1541
+ cellY = cell[1];
1640
1542
  if (cellReadOnly(cellX, cellY)) {
1641
1543
  return;
1642
1544
  }
1643
-
1644
1545
  if (e.key === 'Enter') e.preventDefault();
1645
1546
  onEdit === null || onEdit === void 0 ? void 0 : onEdit(cell, e.key !== 'Enter');
1646
1547
  return;
1647
1548
  }
1648
-
1649
1549
  e.preventDefault();
1650
-
1651
1550
  if (e.key in ARROW_KEYS) {
1652
1551
  var anchor = rawSelection[0],
1653
- head = rawSelection[1];
1552
+ head = rawSelection[1];
1654
1553
  var direction = ARROW_KEYS[e.key];
1655
1554
  var step = getDirectionStep(direction);
1656
1555
  var shift = e.shiftKey;
1657
-
1658
1556
  if (e.metaKey || e.ctrlKey) {
1659
1557
  head = findInDisplayData(displayData, head, direction);
1660
1558
  } else {
1661
1559
  var limit = shift ? isRowSelection(selection) ? [-1, 0] : isColumnSelection(selection) ? [0, -1] : NEG_NEG : ORIGIN;
1662
1560
  head = maxXY(addXY(head, step), limit);
1663
1561
  }
1664
-
1665
1562
  if (!shift) {
1666
1563
  anchor = head;
1667
1564
  }
1668
-
1669
1565
  onSelectionChange === null || onSelectionChange === void 0 ? void 0 : onSelectionChange([anchor, head], true, true);
1670
1566
  return;
1671
1567
  }
1672
1568
  };
1673
-
1674
1569
  var onGridFocus = function onGridFocus() {
1675
1570
  onFocusChange === null || onFocusChange === void 0 ? void 0 : onFocusChange(true);
1676
1571
  };
1677
-
1678
1572
  var onGridBlur = function onGridBlur() {
1679
1573
  onFocusChange === null || onFocusChange === void 0 ? void 0 : onFocusChange(false);
1680
1574
  };
1681
-
1682
1575
  useLayoutEffect(function () {
1683
1576
  var overlay = overlayRef.current;
1684
-
1685
1577
  if (!overlay) {
1686
1578
  return;
1687
1579
  }
1688
-
1689
1580
  if (editMode || !focused) {
1690
1581
  return;
1691
1582
  }
1692
-
1693
1583
  if (document.activeElement === overlay) {
1694
1584
  return;
1695
1585
  }
1696
-
1697
1586
  var activeTagName = document.activeElement.tagName.toLowerCase();
1698
-
1699
1587
  if (!(activeTagName === 'div' && document.activeElement.contentEditable === 'true' || activeTagName === 'input' || activeTagName === 'textarea' || activeTagName === 'select')) {
1700
1588
  overlay.focus({
1701
1589
  preventScroll: true
@@ -1715,28 +1603,22 @@ var useScroll = function useScroll(offset, maxScroll, cellLayout, onOffsetChange
1715
1603
  if (!e.target || !(e.target instanceof Element)) {
1716
1604
  return;
1717
1605
  }
1718
-
1719
1606
  var absoluteToCell = cellLayout.absoluteToCell,
1720
- cellToAbsolute = cellLayout.cellToAbsolute;
1721
-
1722
- var _cellToAbsolute = cellToAbsolute([0, 0], [0.5, 0.5]),
1723
- nudgeX = _cellToAbsolute[0],
1724
- nudgeY = _cellToAbsolute[1];
1725
-
1607
+ cellToAbsolute = cellLayout.cellToAbsolute;
1608
+ var _subXY = subXY(cellToAbsolute([0, 0], [0.5, 0.5]), cellToAbsolute([0, 0])),
1609
+ nudgeX = _subXY[0],
1610
+ nudgeY = _subXY[1];
1726
1611
  var xy = [e.target.scrollLeft + nudgeX, e.target.scrollTop + nudgeY];
1727
1612
  var cell = absoluteToCell(xy);
1728
-
1729
1613
  if (!isSameXY(cell, offset)) {
1730
1614
  onOffsetChange === null || onOffsetChange === void 0 ? void 0 : onOffsetChange(cell);
1731
1615
  }
1732
-
1733
1616
  var x = xy[0],
1734
- y = xy[1];
1617
+ y = xy[1];
1735
1618
  var maxScrollX = maxScroll[0],
1736
- maxScrollY = maxScroll[1];
1619
+ maxScrollY = maxScroll[1];
1737
1620
  var growX = maxScrollX < x + 1 ? 1.5 : 1;
1738
1621
  var growY = maxScrollY < y + 1 ? 1.5 : 1;
1739
-
1740
1622
  if (growX > 1 || growY > 1) {
1741
1623
  onMaxScrollChange === null || onMaxScrollChange === void 0 ? void 0 : onMaxScrollChange(mulXY(maxScroll, [growX, growY]));
1742
1624
  }
@@ -1744,52 +1626,43 @@ var useScroll = function useScroll(offset, maxScroll, cellLayout, onOffsetChange
1744
1626
  };
1745
1627
  var clipDataOffset = function clipDataOffset(view, offset, freeze, maxCells, cellLayout) {
1746
1628
  var newX = offset[0],
1747
- newY = offset[1];
1629
+ newY = offset[1];
1748
1630
  var freezeX = freeze[0],
1749
- freezeY = freeze[1];
1631
+ freezeY = freeze[1];
1750
1632
  var maxColumns = maxCells[0],
1751
- maxRows = maxCells[1];
1633
+ maxRows = maxCells[1];
1752
1634
  var absoluteToColumn = cellLayout.absoluteToColumn,
1753
- columnToAbsolute = cellLayout.columnToAbsolute,
1754
- absoluteToRow = cellLayout.absoluteToRow,
1755
- rowToAbsolute = cellLayout.rowToAbsolute;
1756
-
1635
+ columnToAbsolute = cellLayout.columnToAbsolute,
1636
+ absoluteToRow = cellLayout.absoluteToRow,
1637
+ rowToAbsolute = cellLayout.rowToAbsolute;
1757
1638
  var _getViewExtent = getViewExtent(view, [newX, newY], freeze, cellLayout),
1758
- _getViewExtent$edge = _getViewExtent.edge,
1759
- leftEdge = _getViewExtent$edge[0],
1760
- topEdge = _getViewExtent$edge[1],
1761
- _getViewExtent$viewpo = _getViewExtent.viewport,
1762
- scrollW = _getViewExtent$viewpo[0],
1763
- scrollH = _getViewExtent$viewpo[1];
1764
-
1639
+ _getViewExtent$edge = _getViewExtent.edge,
1640
+ leftEdge = _getViewExtent$edge[0],
1641
+ topEdge = _getViewExtent$edge[1],
1642
+ _getViewExtent$viewpo = _getViewExtent.viewport,
1643
+ scrollW = _getViewExtent$viewpo[0],
1644
+ scrollH = _getViewExtent$viewpo[1];
1765
1645
  if (leftEdge >= maxColumns) {
1766
1646
  var remainder = columnToAbsolute(maxColumns) - columnToAbsolute(newX + freezeX);
1767
1647
  newX = Math.max(0, absoluteToColumn(columnToAbsolute(newX + freezeX) - scrollW + remainder) - freezeX + 1);
1768
1648
  }
1769
-
1770
1649
  if (topEdge >= maxRows) {
1771
1650
  var _remainder = rowToAbsolute(maxRows) - rowToAbsolute(newY + freezeY);
1772
-
1773
1651
  newY = Math.max(0, absoluteToRow(rowToAbsolute(newY + freezeY) - scrollH + _remainder) - freezeY + 1);
1774
1652
  }
1775
-
1776
1653
  return [newX, newY];
1777
1654
  };
1778
1655
  var getViewExtent = function getViewExtent(view, offset, freeze, cellLayout) {
1779
- var cellToAbsolute = cellLayout.cellToAbsolute,
1780
- getIndentX = cellLayout.getIndentX,
1781
- getIndentY = cellLayout.getIndentY;
1656
+ var cellToAbsolute = cellLayout.cellToAbsolute;
1782
1657
  var x = offset[0],
1783
- y = offset[1];
1658
+ y = offset[1];
1784
1659
  var w = view[0],
1785
- h = view[1];
1786
-
1787
- var _cellToAbsolute2 = cellToAbsolute(freeze),
1788
- frozenX = _cellToAbsolute2[0],
1789
- frozenY = _cellToAbsolute2[1];
1790
-
1791
- var scrollW = w - frozenX - getIndentX();
1792
- var scrollH = h - frozenY - getIndentY();
1660
+ h = view[1];
1661
+ var _cellToAbsolute = cellToAbsolute(freeze),
1662
+ frozenX = _cellToAbsolute[0],
1663
+ frozenY = _cellToAbsolute[1];
1664
+ var scrollW = w - frozenX;
1665
+ var scrollH = h - frozenY;
1793
1666
  var leftEdge = x + freeze[0];
1794
1667
  var topEdge = y + freeze[1];
1795
1668
  return {
@@ -1799,55 +1672,44 @@ var getViewExtent = function getViewExtent(view, offset, freeze, cellLayout) {
1799
1672
  };
1800
1673
  var scrollToCell = function scrollToCell(element, cell, view, freeze, offset, maxScroll, cellLayout, callback) {
1801
1674
  var x = cell[0],
1802
- y = cell[1];
1675
+ y = cell[1];
1803
1676
  var w = view[0],
1804
- h = view[1];
1677
+ h = view[1];
1805
1678
  var offsetX = offset[0],
1806
- offsetY = offset[1];
1679
+ offsetY = offset[1];
1807
1680
  var cellToAbsolute = cellLayout.cellToAbsolute,
1808
- cellToPixel = cellLayout.cellToPixel,
1809
- columnToPixel = cellLayout.columnToPixel,
1810
- rowToPixel = cellLayout.rowToPixel;
1811
-
1812
- var _cellToAbsolute3 = cellToAbsolute(freeze),
1813
- frozenX = _cellToAbsolute3[0],
1814
- frozenY = _cellToAbsolute3[1];
1815
-
1681
+ cellToPixel = cellLayout.cellToPixel,
1682
+ columnToPixel = cellLayout.columnToPixel,
1683
+ rowToPixel = cellLayout.rowToPixel;
1684
+ var origin = cellToAbsolute([0, 0]);
1685
+ var frozen = cellToAbsolute(freeze);
1686
+ var frozenX = frozen[0],
1687
+ frozenY = frozen[1];
1816
1688
  var _cellToPixel = cellToPixel(cell),
1817
- left = _cellToPixel[0],
1818
- top = _cellToPixel[1];
1819
-
1689
+ left = _cellToPixel[0],
1690
+ top = _cellToPixel[1];
1820
1691
  var _cellToPixel2 = cellToPixel(cell, ONE_ONE),
1821
- right = _cellToPixel2[0],
1822
- bottom = _cellToPixel2[1];
1823
-
1692
+ right = _cellToPixel2[0],
1693
+ bottom = _cellToPixel2[1];
1824
1694
  var newX = offset[0],
1825
- newY = offset[1];
1826
-
1695
+ newY = offset[1];
1827
1696
  if (left <= frozenX) {
1828
1697
  newX = x - freeze[0];
1829
1698
  }
1830
-
1831
1699
  if (top <= frozenY) {
1832
1700
  newY = y - freeze[1];
1833
1701
  }
1834
-
1835
1702
  if (right > w) {
1836
1703
  var edge = right - w + columnToPixel(newX);
1837
-
1838
1704
  while (columnToPixel(++newX) < edge) {}
1839
1705
  }
1840
-
1841
1706
  if (bottom > h) {
1842
1707
  var _edge = bottom - h + rowToPixel(newY);
1843
-
1844
1708
  while (rowToPixel(++newY) < _edge) {}
1845
1709
  }
1846
-
1847
1710
  var newOffset = [newX >= 0 ? newX : offsetX, newY >= 0 ? newY : offsetY];
1848
-
1849
1711
  if (!isSameXY(newOffset, offset)) {
1850
- var scroll = cellToAbsolute(newOffset);
1712
+ var scroll = subXY(cellToAbsolute(newOffset), origin);
1851
1713
  callback(newOffset, maxXY(maxScroll, scroll));
1852
1714
  setTimeout(function () {
1853
1715
  updateScrollPosition(element, newOffset, cellLayout);
@@ -1857,89 +1719,414 @@ var scrollToCell = function scrollToCell(element, cell, view, freeze, offset, ma
1857
1719
  var updateScrollPosition = function updateScrollPosition(element, dataOffset, cellLayout) {
1858
1720
  var cellToAbsolute = cellLayout.cellToAbsolute;
1859
1721
  var scroll = cellToAbsolute(dataOffset);
1860
-
1861
- var _cellToAbsolute4 = cellToAbsolute([0, 0], [0.5, 0.5]),
1862
- nudgeX = _cellToAbsolute4[0],
1863
- nudgeY = _cellToAbsolute4[1];
1864
-
1722
+ var _subXY2 = subXY(cellToAbsolute([0, 0], [0.5, 0.5]), cellToAbsolute([0, 0])),
1723
+ nudgeX = _subXY2[0],
1724
+ nudgeY = _subXY2[1];
1865
1725
  var scrollX = scroll[0],
1866
- scrollY = scroll[1];
1726
+ scrollY = scroll[1];
1867
1727
  element.scrollLeft = scrollX - nudgeX;
1868
1728
  element.scrollTop = scrollY - nudgeY;
1869
1729
  };
1870
1730
 
1871
- var useAutoSizeColumn = function useAutoSizeColumn(rows, displayData, cellStyle, columnHeaders, columnHeaderStyle, canvasWidth) {
1731
+ var getInlineAlignment = function getInlineAlignment(cellWidth, contentWidth, align) {
1732
+ if (align === 'left') return 0;
1733
+ if (align === 'right') return cellWidth - contentWidth;
1734
+ return Math.round((cellWidth - contentWidth) / 2);
1735
+ };
1736
+ var measureFlexWidth = function measureFlexWidth(context, item) {
1737
+ var width = item.width;
1738
+ if (width != null) return width;
1739
+ if (item.display === 'inline') {
1740
+ var text = item.text;
1741
+ if (text != null) {
1742
+ var _context$measureText = context.measureText(text.toString()),
1743
+ actualBoundingBoxLeft = _context$measureText.actualBoundingBoxLeft,
1744
+ actualBoundingBoxRight = _context$measureText.actualBoundingBoxRight;
1745
+ var w = actualBoundingBoxRight + actualBoundingBoxLeft;
1746
+ return width != null ? width : w;
1747
+ }
1748
+ } else {
1749
+ throw new Error('Image or JSX content must have dimension specified');
1750
+ }
1751
+ return 0;
1752
+ };
1753
+ var resolveCellFlexLayout = function resolveCellFlexLayout(context, cellContent, cellLeft, cellTop, cellWidth, cellHeight) {
1754
+ var _cellContent$flexJust = cellContent.flexJustify,
1755
+ flexJustify = _cellContent$flexJust === void 0 ? 'start' : _cellContent$flexJust,
1756
+ _cellContent$flexAlig = cellContent.flexAlign,
1757
+ flexAlign = _cellContent$flexAlig === void 0 ? 'center' : _cellContent$flexAlig,
1758
+ _cellContent$flexGap = cellContent.flexGap,
1759
+ flexGap = _cellContent$flexGap === void 0 ? 0 : _cellContent$flexGap,
1760
+ items = cellContent.items;
1761
+ var flexItems = items.filter(function (item) {
1762
+ return !item.absolute;
1763
+ });
1764
+ var measuredWidths = cellContent.items.map(function (item) {
1765
+ return measureFlexWidth(context, item);
1766
+ });
1767
+ var sizes = [];
1768
+ var grows = [];
1769
+ var shrinks = [];
1770
+ var x = 0;
1771
+ flexItems.forEach(function (item, i) {
1772
+ var defaultGrow = item.display === 'inline' ? 1 : 0;
1773
+ var defaultShrink = defaultGrow || (item.display === 'space' ? 1 : 0);
1774
+ var _item$width = item.width,
1775
+ width = _item$width === void 0 ? measuredWidths[i] : _item$width,
1776
+ _item$flexGrow = item.flexGrow,
1777
+ flexGrow = _item$flexGrow === void 0 ? defaultGrow : _item$flexGrow,
1778
+ _item$flexShrink = item.flexShrink,
1779
+ flexShrink = _item$flexShrink === void 0 ? defaultShrink : _item$flexShrink,
1780
+ _item$marginLeft = item.marginLeft,
1781
+ marginLeft = _item$marginLeft === void 0 ? 0 : _item$marginLeft,
1782
+ _item$marginRight = item.marginRight,
1783
+ marginRight = _item$marginRight === void 0 ? 0 : _item$marginRight;
1784
+ sizes.push(width);
1785
+ grows.push(flexGrow);
1786
+ shrinks.push(flexShrink);
1787
+ x += width + marginLeft + marginRight + flexGap;
1788
+ });
1789
+ var slackX = cellWidth - x + flexGap;
1790
+ if (slackX > 0 && growRow(slackX, grows, sizes)) slackX = 0;
1791
+ if (slackX < 0 && _shrinkRow(slackX, shrinks, sizes)) slackX = 0;
1792
+ var _getAlignmentSpacing = getAlignmentSpacing(slackX, flexItems.length, flexJustify),
1793
+ gapX = _getAlignmentSpacing[0],
1794
+ leadX = _getAlignmentSpacing[1];
1795
+ var combinedGapX = gapX + flexGap;
1796
+ var maxHeight = flexItems.map(function (_ref) {
1797
+ var height = _ref.height,
1798
+ _ref$marginTop = _ref.marginTop,
1799
+ marginTop = _ref$marginTop === void 0 ? 0 : _ref$marginTop,
1800
+ _ref$marginBottom = _ref.marginBottom,
1801
+ marginBottom = _ref$marginBottom === void 0 ? 0 : _ref$marginBottom;
1802
+ return (height != null ? height : cellHeight) + marginTop + marginBottom;
1803
+ }).reduce(function (a, b) {
1804
+ return Math.max(a, b);
1805
+ });
1806
+ var slackY = Math.max(0, cellHeight - maxHeight);
1807
+ var offsetY = getAlignmentAnchor(flexAlign) * slackY;
1808
+ var leftCursor = leadX;
1809
+ return flexItems.map(function (item, i) {
1810
+ var fixedHeight = item.height,
1811
+ _item$marginLeft2 = item.marginLeft,
1812
+ marginLeft = _item$marginLeft2 === void 0 ? 0 : _item$marginLeft2,
1813
+ _item$marginRight2 = item.marginRight,
1814
+ marginRight = _item$marginRight2 === void 0 ? 0 : _item$marginRight2,
1815
+ _item$marginTop = item.marginTop,
1816
+ marginTop = _item$marginTop === void 0 ? 0 : _item$marginTop,
1817
+ _item$marginBottom = item.marginBottom,
1818
+ marginBottom = _item$marginBottom === void 0 ? 0 : _item$marginBottom,
1819
+ _item$flexAlignSelf = item.flexAlignSelf,
1820
+ flexAlignSelf = _item$flexAlignSelf === void 0 ? flexAlign : _item$flexAlignSelf;
1821
+ var marginX = marginLeft + marginRight;
1822
+ var marginY = marginTop + marginBottom;
1823
+ var height = fixedHeight != null ? fixedHeight : maxHeight - marginY;
1824
+ var slackSelfY = maxHeight - height - marginY;
1825
+ var offsetSelfY = getAlignmentAnchor(flexAlignSelf) * slackSelfY;
1826
+ var x = Math.round(cellLeft + marginLeft + leftCursor);
1827
+ var y = Math.round(cellTop + marginTop + offsetY + offsetSelfY);
1828
+ leftCursor += combinedGapX + marginX + sizes[i];
1829
+ var boxW = sizes[i];
1830
+ var boxH = height;
1831
+ var box = [[x, y], [x + boxW, y + boxH]];
1832
+ return {
1833
+ box: box,
1834
+ item: item
1835
+ };
1836
+ });
1837
+ };
1838
+ var resolveCellAbsoluteLayout = function resolveCellAbsoluteLayout(cellContent, cellLeft, cellTop, cellWidth, cellHeight) {
1839
+ var items = cellContent.items;
1840
+ var absoluteItems = items.filter(function (item) {
1841
+ return item.absolute;
1842
+ });
1843
+ var resolvePosition = function resolvePosition(container, size, start, end, marginStart, marginEnd) {
1844
+ if (marginStart === void 0) {
1845
+ marginStart = 0;
1846
+ }
1847
+ if (marginEnd === void 0) {
1848
+ marginEnd = 0;
1849
+ }
1850
+ if (start != null) return start + marginStart;
1851
+ if (end != null) return container - end - marginEnd - size;
1852
+ return 0;
1853
+ };
1854
+ var resolveSize = function resolveSize(container, span, start, end, marginStart, marginEnd) {
1855
+ if (marginStart === void 0) {
1856
+ marginStart = 0;
1857
+ }
1858
+ if (marginEnd === void 0) {
1859
+ marginEnd = 0;
1860
+ }
1861
+ if (span != null) return span;
1862
+ if (start != null && end != null) return container - start - end - marginStart - marginEnd;
1863
+ return 0;
1864
+ };
1865
+ return absoluteItems.map(function (item) {
1866
+ var left = item.left,
1867
+ top = item.top,
1868
+ right = item.right,
1869
+ bottom = item.bottom,
1870
+ width = item.width,
1871
+ height = item.height,
1872
+ marginLeft = item.marginLeft,
1873
+ marginTop = item.marginTop,
1874
+ marginRight = item.marginRight,
1875
+ marginBottom = item.marginBottom;
1876
+ var w = resolveSize(cellWidth, width, left, right, marginLeft, marginRight);
1877
+ var h = resolveSize(cellHeight, height, top, bottom, marginTop, marginBottom);
1878
+ var l = cellLeft + resolvePosition(cellWidth, w, left, right, marginLeft, marginRight);
1879
+ var t = cellTop + resolvePosition(cellHeight, h, top, bottom, marginTop, marginBottom);
1880
+ var box = [[l, t], [l + w, t + h]];
1881
+ return {
1882
+ box: box,
1883
+ item: item
1884
+ };
1885
+ });
1886
+ };
1887
+ var growRow = function growRow(slack, grow, sizes) {
1888
+ var n = grow.length;
1889
+ var weight = 0;
1890
+ for (var i = 0; i < n; ++i) if (grow[i] > 0) weight += grow[i];
1891
+ if (weight > 0) {
1892
+ for (var _i = 0; _i < n; ++_i) {
1893
+ if (grow[_i] > 0) {
1894
+ sizes[_i] += slack * grow[_i] / weight;
1895
+ }
1896
+ }
1897
+ return true;
1898
+ }
1899
+ return false;
1900
+ };
1901
+ var _shrinkRow = function shrinkRow(slack, shrink, sizes) {
1902
+ var n = shrink.length;
1903
+ var weight = 0;
1904
+ for (var i = 0; i < n; ++i) if (shrink[i]) weight += shrink[i] * sizes[i];
1905
+ if (weight > 0) {
1906
+ var negative = 0;
1907
+ for (var _i2 = 0; _i2 < n; ++_i2) {
1908
+ if (shrink[_i2] > 0 && sizes[_i2]) {
1909
+ sizes[_i2] += slack * shrink[_i2] * sizes[_i2] / weight;
1910
+ if (sizes[_i2] < 0) {
1911
+ negative += sizes[_i2];
1912
+ sizes[_i2] = 0;
1913
+ }
1914
+ }
1915
+ }
1916
+ if (negative) {
1917
+ _shrinkRow(negative, shrink, sizes);
1918
+ }
1919
+ return true;
1920
+ }
1921
+ return false;
1922
+ };
1923
+ var getAlignmentAnchor = function getAlignmentAnchor(x) {
1924
+ var isStart = x === 'start';
1925
+ var isEnd = x === 'end';
1926
+ var align = isStart ? 0 : isEnd ? 1 : 0.5;
1927
+ return align;
1928
+ };
1929
+ var getAlignmentSpacing = function getAlignmentSpacing(slack, n, justify) {
1930
+ var gap = 0;
1931
+ var lead = 0;
1932
+ var isJustify = justify === 'justify';
1933
+ var isBetween = justify === 'between';
1934
+ var isEvenly = justify === 'evenly';
1935
+ if (slack > 0) {
1936
+ if (isEvenly || isBetween || isJustify) {
1937
+ if (n === 1) {
1938
+ lead = slack / 2;
1939
+ } else if (isEvenly) {
1940
+ gap = Math.max(0, slack / (n + 1));
1941
+ lead = gap;
1942
+ } else if (isBetween) {
1943
+ gap = Math.max(0, slack / n);
1944
+ lead = gap / 2;
1945
+ } else if (isJustify) {
1946
+ gap = Math.max(0, slack / Math.max(1, n - 1));
1947
+ }
1948
+ } else {
1949
+ lead = getAlignmentAnchor(justify) * slack;
1950
+ }
1951
+ }
1952
+ return [gap, lead];
1953
+ };
1954
+
1955
+ var wrapText = function wrapText(context, text, style, itemAlign, xCoord, yCoord, cellWidth, cellHeight, emit) {
1956
+ var textAlign = style.textAlign,
1957
+ lineHeight = style.lineHeight,
1958
+ fontSize = style.fontSize,
1959
+ marginBottom = style.marginBottom;
1960
+ var align = itemAlign != null ? itemAlign : textAlign;
1961
+ context.textAlign = align;
1962
+ var x = xCoord + getInlineAlignment(cellWidth, 0, align);
1963
+ var y = yCoord;
1964
+ var s = text.toString();
1965
+ var n = s.length;
1966
+ var xCursor = 0;
1967
+ var yCursor = 0;
1968
+ var wordsPerLine = 0;
1969
+ var startOfLine = 0;
1970
+ var newline = function newline(endOfLine, ellipsis, endsInSpace) {
1971
+ if (ellipsis === void 0) {
1972
+ ellipsis = false;
1973
+ }
1974
+ if (endsInSpace === void 0) {
1975
+ endsInSpace = false;
1976
+ }
1977
+ var line = s.slice(startOfLine, endOfLine - +endsInSpace);
1978
+ emit(ellipsis ? line + '…' : line, x, y + yCursor);
1979
+ startOfLine = endOfLine;
1980
+ wordsPerLine = 0;
1981
+ xCursor = 0;
1982
+ yCursor += lineHeight;
1983
+ };
1984
+ var breaker = new LineBreak(s);
1985
+ var lastPosition = 0;
1986
+ var bk;
1987
+ while (bk = breaker.nextBreak()) {
1988
+ var _bk = bk,
1989
+ position = _bk.position,
1990
+ required = _bk.required;
1991
+ var word = s.slice(lastPosition, position);
1992
+ var _context$measureText = context.measureText(word),
1993
+ width = _context$measureText.width;
1994
+ var canNewLine = yCursor + lineHeight + marginBottom < cellHeight;
1995
+ var hasMoreText = position < n;
1996
+ var endsInSpace = word[word.length - 1] === ' ';
1997
+ var ellipsisSpace = !canNewLine && hasMoreText ? (endsInSpace ? 0.5 : 1) * fontSize : 0;
1998
+ var nextX = xCursor + width + ellipsisSpace;
1999
+ if (wordsPerLine && nextX >= cellWidth) {
2000
+ if (canNewLine) newline(lastPosition);else {
2001
+ if (endsInSpace) {
2002
+ var _context$measureText2 = context.measureText(' '),
2003
+ _width = _context$measureText2.width;
2004
+ xCursor -= _width;
2005
+ }
2006
+ newline(lastPosition, true, endsInSpace);
2007
+ return;
2008
+ }
2009
+ }
2010
+ xCursor += width;
2011
+ wordsPerLine++;
2012
+ if (required) newline(position);
2013
+ lastPosition = position;
2014
+ }
2015
+ newline(n);
2016
+ };
2017
+
2018
+ var useAutoSizeColumn = function useAutoSizeColumn(rows, displayData, cellLayout, cellStyle, columnHeaders, columnHeaderStyle, canvasWidth, frozenColumns) {
1872
2019
  var context = useMemo(function () {
1873
2020
  return document.createElement('canvas').getContext('2d');
1874
2021
  }, []);
1875
2022
  var getAutoSizeWidth = useCallback(function (x) {
1876
2023
  if (!context) return 0;
1877
-
2024
+ var viewWidth = canvasWidth - cellLayout.columnToAbsolute(x < frozenColumns ? 0 : frozenColumns);
1878
2025
  var getWidth = function getWidth(cellContent, style) {
1879
- context.font = style.weight + ' ' + style.fontSize + 'px ' + style.fontFamily;
2026
+ context.font = style.fontWeight + ' ' + style.fontSize + 'px ' + style.fontFamily;
1880
2027
  var inlineMargin = style.marginLeft + style.marginRight;
1881
-
1882
2028
  if (typeof cellContent === 'string' || typeof cellContent === 'number') {
1883
2029
  var _context$measureText = context.measureText(cellContent.toString()),
1884
- width = _context$measureText.width;
1885
-
2030
+ width = _context$measureText.width;
1886
2031
  return width + inlineMargin;
1887
2032
  } else if (typeof cellContent === 'object') {
1888
- var _maxWidth = 0;
1889
- var extraWidth = 0;
1890
-
1891
- for (var _iterator = _createForOfIteratorHelperLoose(cellContent.items), _step; !(_step = _iterator()).done;) {
1892
- var obj = _step.value;
1893
- var _width = 0;
1894
-
1895
- if (typeof obj.content === 'string' || typeof obj.content === 'number') {
1896
- var _context$measureText2 = context.measureText(obj.content.toString()),
1897
- w = _context$measureText2.width;
1898
-
1899
- _width = obj.x + w + inlineMargin;
1900
- } else if (obj.width) {
1901
- _width = obj.width;
1902
- }
1903
-
1904
- if (obj.horizontalAlign === 'right') {
1905
- extraWidth += style.textAlign === 'right' ? _width * 2 : _width;
1906
- } else {
1907
- _maxWidth = Math.max(_maxWidth, _width);
2033
+ var totalWidth = inlineMargin;
2034
+ var _cellContent$flexGap = cellContent.flexGap,
2035
+ flexGap = _cellContent$flexGap === void 0 ? 0 : _cellContent$flexGap,
2036
+ items = cellContent.items;
2037
+ for (var _iterator = _createForOfIteratorHelperLoose(items), _step; !(_step = _iterator()).done;) {
2038
+ var item = _step.value;
2039
+ if (item.absolute) continue;
2040
+ if (item.width != null) {
2041
+ totalWidth += item.width;
2042
+ } else if (item.display === 'inline' && item.text != null) {
2043
+ var _context$measureText2 = context.measureText(item.text.toString()),
2044
+ _width = _context$measureText2.width;
2045
+ totalWidth += _width;
1908
2046
  }
2047
+ totalWidth += flexGap;
1909
2048
  }
1910
-
1911
- return _maxWidth + extraWidth;
2049
+ totalWidth -= flexGap;
2050
+ return totalWidth;
1912
2051
  }
1913
-
1914
2052
  return 0;
1915
2053
  };
1916
-
1917
2054
  var maxWidth = SIZES.minimumWidth;
1918
-
1919
2055
  var headerStyle = _extends({}, DEFAULT_COLUMN_HEADER_STYLE, columnHeaderStyle(x));
1920
-
1921
2056
  var headerContent = columnHeaders(x, headerStyle);
1922
-
1923
2057
  if (headerContent) {
1924
2058
  maxWidth = Math.max(maxWidth, getWidth(headerContent, headerStyle));
1925
2059
  }
1926
-
1927
2060
  for (var _iterator2 = _createForOfIteratorHelperLoose(rows), _step2; !(_step2 = _iterator2()).done;) {
1928
2061
  var y = _step2.value;
1929
-
1930
2062
  var style = _extends({}, DEFAULT_CELL_STYLE, cellStyle(x, y));
1931
-
1932
2063
  var cellContent = displayData(x, y, style);
1933
-
1934
2064
  if (cellContent != null) {
1935
2065
  maxWidth = Math.max(maxWidth, getWidth(cellContent, style));
1936
2066
  }
1937
2067
  }
1938
-
1939
- return Math.ceil(Math.min(canvasWidth, maxWidth));
1940
- }, [context, displayData, cellStyle, columnHeaders, columnHeaderStyle]);
2068
+ return Math.ceil(Math.min(viewWidth, maxWidth));
2069
+ }, [context, rows, displayData, cellLayout, cellStyle, columnHeaders, columnHeaderStyle, canvasWidth, frozenColumns]);
1941
2070
  return getAutoSizeWidth;
1942
2071
  };
2072
+ var useAutoSizeRow = function useAutoSizeRow(columns, displayData, cellLayout, cellStyle, columnHeaders, columnHeaderStyle, cellWidth, canvasHeight, frozenRows) {
2073
+ var context = useMemo(function () {
2074
+ return document.createElement('canvas').getContext('2d');
2075
+ }, []);
2076
+ var getAutoSizeHeight = useCallback(function (y) {
2077
+ if (!context) return 0;
2078
+ var viewHeight = canvasHeight - cellLayout.rowToAbsolute(y < frozenRows ? 0 : frozenRows);
2079
+ var measureTextHeight = function measureTextHeight(text, style, columnWidth) {
2080
+ var maxY = 0;
2081
+ var measureY = function measureY(_t, _x, y) {
2082
+ maxY = y + style.lineHeight;
2083
+ };
2084
+ wrapText(context, text, style, undefined, 0, 0, columnWidth, viewHeight, measureY);
2085
+ return maxY;
2086
+ };
2087
+ var getHeight = function getHeight(cellContent, style, columnWidth) {
2088
+ context.font = style.fontWeight + ' ' + style.fontSize + 'px ' + style.fontFamily;
2089
+ var verticalMargin = style.marginTop + style.marginBottom;
2090
+ if (typeof cellContent === 'string' || typeof cellContent === 'number') {
2091
+ var height = measureTextHeight(cellContent.toString(), style, columnWidth);
2092
+ return height + verticalMargin;
2093
+ } else if (typeof cellContent === 'object') {
2094
+ var _maxHeight = 0;
2095
+ var flexLayout = resolveCellFlexLayout(context, cellContent, 0, 0, columnWidth, 0);
2096
+ for (var _iterator3 = _createForOfIteratorHelperLoose(flexLayout), _step3; !(_step3 = _iterator3()).done;) {
2097
+ var _step3$value = _step3.value,
2098
+ box = _step3$value.box,
2099
+ item = _step3$value.item;
2100
+ if (item.height != null) {
2101
+ _maxHeight = Math.max(_maxHeight, item.height);
2102
+ } else if (item.display === 'inline' && item.text != null) {
2103
+ var _box$ = box[0],
2104
+ left = _box$[0],
2105
+ _box$2 = box[1],
2106
+ right = _box$2[0];
2107
+ var _height = measureTextHeight(item.text.toString(), style, right - left);
2108
+ _maxHeight = Math.max(_maxHeight, _height);
2109
+ }
2110
+ }
2111
+ return _maxHeight + verticalMargin;
2112
+ }
2113
+ return 0;
2114
+ };
2115
+ var isHeader = y === -1;
2116
+ var maxHeight = SIZES.minimumHeight;
2117
+ for (var _iterator4 = _createForOfIteratorHelperLoose(columns), _step4; !(_step4 = _iterator4()).done;) {
2118
+ var x = _step4.value;
2119
+ var style = isHeader ? _extends({}, DEFAULT_COLUMN_HEADER_STYLE, columnHeaderStyle(x)) : _extends({}, DEFAULT_CELL_STYLE, cellStyle(x, y));
2120
+ var cellContent = isHeader ? columnHeaders(x, style) : displayData(x, y, style);
2121
+ if (cellContent != null) {
2122
+ var columnWidth = cellWidth(x) - style.marginLeft - style.marginRight;
2123
+ maxHeight = Math.max(maxHeight, getHeight(cellContent, style, columnWidth));
2124
+ }
2125
+ }
2126
+ return Math.ceil(Math.min(viewHeight, maxHeight));
2127
+ }, [context, columns, displayData, cellLayout, cellStyle, columnHeaders, columnHeaderStyle, cellWidth, canvasHeight, frozenRows]);
2128
+ return getAutoSizeHeight;
2129
+ };
1943
2130
 
1944
2131
  // A type of promise-like that resolves synchronously and supports only one observer
1945
2132
 
@@ -1965,9 +2152,8 @@ var EMPTY_TABLE = {
1965
2152
  };
1966
2153
  var useClipboardTable = function useClipboardTable() {
1967
2154
  var _useState = useState(),
1968
- peek = _useState[0],
1969
- setPeek = _useState[1];
1970
-
2155
+ peek = _useState[0],
2156
+ setPeek = _useState[1];
1971
2157
  useLayoutEffect(function () {
1972
2158
  var softRefresh = function softRefresh() {
1973
2159
  return Promise.resolve(_catch(function () {
@@ -1979,13 +2165,11 @@ var useClipboardTable = function useClipboardTable() {
1979
2165
  });
1980
2166
  }, function () {}));
1981
2167
  };
1982
-
1983
2168
  var hardRefresh = function hardRefresh() {
1984
2169
  try {
1985
- var _temp3 = _catch(function () {
2170
+ var _temp2 = _catch(function () {
1986
2171
  return Promise.resolve(navigator.clipboard.read()).then(function (items) {
1987
2172
  var item = items[0];
1988
-
1989
2173
  var _temp = function () {
1990
2174
  if (item) {
1991
2175
  return Promise.resolve(parseClipboardTable(item)).then(function (peek) {
@@ -1995,21 +2179,17 @@ var useClipboardTable = function useClipboardTable() {
1995
2179
  setPeek(EMPTY_TABLE);
1996
2180
  }
1997
2181
  }();
1998
-
1999
2182
  if (_temp && _temp.then) return _temp.then(function () {});
2000
2183
  });
2001
2184
  }, function () {});
2002
-
2003
- return Promise.resolve(_temp3 && _temp3.then ? _temp3.then(function () {}) : void 0);
2185
+ return Promise.resolve(_temp2 && _temp2.then ? _temp2.then(function () {}) : void 0);
2004
2186
  } catch (e) {
2005
2187
  return Promise.reject(e);
2006
2188
  }
2007
2189
  };
2008
-
2009
2190
  var delayedRefresh = function delayedRefresh() {
2010
2191
  return setTimeout(hardRefresh);
2011
2192
  };
2012
-
2013
2193
  window.document.addEventListener('cut', delayedRefresh);
2014
2194
  window.document.addEventListener('copy', delayedRefresh);
2015
2195
  window.document.addEventListener('focus', softRefresh);
@@ -2022,7 +2202,6 @@ var useClipboardTable = function useClipboardTable() {
2022
2202
  }, []);
2023
2203
  var canPaste = useCallback(function () {
2024
2204
  var _peek$rows;
2025
-
2026
2205
  return !!(peek == null || (_peek$rows = peek.rows) !== null && _peek$rows !== void 0 && _peek$rows.length);
2027
2206
  }, [peek]);
2028
2207
  return {
@@ -2034,20 +2213,17 @@ var useClipboardTable = function useClipboardTable() {
2034
2213
  };
2035
2214
  var useClipboardAPI = function useClipboardAPI(selection, editData, cellReadOnly, addListener, onSelectionChange, onChange, onCopy, onPaste) {
2036
2215
  var _useClipboardTable = useClipboardTable(),
2037
- canPaste = _useClipboardTable.canPaste,
2038
- copyTable = _useClipboardTable.copyTable,
2039
- pasteTable = _useClipboardTable.pasteTable;
2040
-
2216
+ canPaste = _useClipboardTable.canPaste,
2217
+ copyTable = _useClipboardTable.copyTable,
2218
+ pasteTable = _useClipboardTable.pasteTable;
2041
2219
  var pasteIntoSelection = useCallback(function (selection, table) {
2042
2220
  try {
2043
2221
  var rows = table.rows,
2044
- payload = table.payload;
2045
-
2222
+ payload = table.payload;
2046
2223
  var _normalizeSelection = normalizeSelection(selection),
2047
- min = _normalizeSelection[0];
2048
-
2224
+ min = _normalizeSelection[0];
2049
2225
  var minX = min[0],
2050
- minY = min[1];
2226
+ minY = min[1];
2051
2227
  var left = Math.max(0, minX);
2052
2228
  var top = Math.max(0, minY);
2053
2229
  var width = rows.reduce(function (a, b) {
@@ -2082,14 +2258,11 @@ var useClipboardAPI = function useClipboardAPI(selection, editData, cellReadOnly
2082
2258
  if (cut === void 0) {
2083
2259
  cut = false;
2084
2260
  }
2085
-
2086
2261
  try {
2087
2262
  var _payload$cut;
2088
-
2089
2263
  var rows = formatSelectionAsRows(selection, editData);
2090
2264
  var payload = onCopy === null || onCopy === void 0 ? void 0 : onCopy(selection, rows, cut);
2091
2265
  copyTable(rows, payload);
2092
-
2093
2266
  if ((_payload$cut = payload === null || payload === void 0 ? void 0 : payload.cut) != null ? _payload$cut : cut) {
2094
2267
  var changes = [];
2095
2268
  forSelectionRows(selection)(function (y) {
@@ -2106,7 +2279,6 @@ var useClipboardAPI = function useClipboardAPI(selection, editData, cellReadOnly
2106
2279
  });
2107
2280
  onChange === null || onChange === void 0 ? void 0 : onChange(changes);
2108
2281
  }
2109
-
2110
2282
  return Promise.resolve();
2111
2283
  } catch (e) {
2112
2284
  return Promise.reject(e);
@@ -2121,12 +2293,10 @@ var useClipboardAPI = function useClipboardAPI(selection, editData, cellReadOnly
2121
2293
  return Promise.reject(e);
2122
2294
  }
2123
2295
  }, [pasteIntoSelection]);
2124
-
2125
2296
  var onClipboardCopy = function onClipboardCopy(cut) {
2126
2297
  if (isEmptySelection(selection)) return;
2127
2298
  return copySelection(selection, cut);
2128
2299
  };
2129
-
2130
2300
  var onClipboardPaste = function onClipboardPaste(e) {
2131
2301
  try {
2132
2302
  e.preventDefault();
@@ -2138,7 +2308,6 @@ var useClipboardAPI = function useClipboardAPI(selection, editData, cellReadOnly
2138
2308
  return Promise.reject(e);
2139
2309
  }
2140
2310
  };
2141
-
2142
2311
  useLayoutEffect(function () {
2143
2312
  if (!addListener) return;
2144
2313
  window.document.addEventListener('paste', onClipboardPaste);
@@ -2159,7 +2328,6 @@ var useClipboardAPI = function useClipboardAPI(selection, editData, cellReadOnly
2159
2328
  onClipboardPaste: onClipboardPaste
2160
2329
  };
2161
2330
  };
2162
-
2163
2331
  var copyClipboardTable = function copyClipboardTable(rows, payload) {
2164
2332
  try {
2165
2333
  var text = formatRowsAsTSV(rows);
@@ -2179,7 +2347,6 @@ var copyClipboardTable = function copyClipboardTable(rows, payload) {
2179
2347
  return Promise.reject(e);
2180
2348
  }
2181
2349
  };
2182
-
2183
2350
  var pasteClipboardTable = function pasteClipboardTable() {
2184
2351
  try {
2185
2352
  return Promise.resolve(navigator.clipboard.read()).then(function (items) {
@@ -2191,10 +2358,9 @@ var pasteClipboardTable = function pasteClipboardTable() {
2191
2358
  return Promise.reject(e);
2192
2359
  }
2193
2360
  };
2194
-
2195
2361
  var parseClipboardTable = function parseClipboardTable(item) {
2196
2362
  try {
2197
- var _temp7 = function _temp7() {
2363
+ var _temp5 = function _temp5() {
2198
2364
  return rows ? {
2199
2365
  rows: rows,
2200
2366
  payload: payload
@@ -2202,53 +2368,44 @@ var parseClipboardTable = function parseClipboardTable(item) {
2202
2368
  rows: []
2203
2369
  };
2204
2370
  };
2205
-
2206
2371
  var has = function has(type) {
2207
2372
  return item.types.includes(type);
2208
2373
  };
2209
-
2210
2374
  var get = function get(type) {
2211
2375
  if ('getData' in item) return item.getData(type);else if ('getType' in item) return item.getType(type).then(function (blob) {
2212
2376
  return blob.text();
2213
2377
  });
2214
2378
  return '';
2215
2379
  };
2216
-
2217
2380
  var rows, payload;
2218
-
2219
- var _temp8 = function () {
2381
+ var _temp4 = function () {
2220
2382
  if (has('text/html')) {
2221
2383
  return Promise.resolve(get('text/html')).then(function (pastedHtml) {
2222
2384
  var _parsePastedHtml = parsePastedHtml(pastedHtml);
2223
-
2224
2385
  rows = _parsePastedHtml.rows;
2225
2386
  payload = _parsePastedHtml.payload;
2226
2387
  });
2227
2388
  } else {
2228
- var _temp9 = function () {
2389
+ var _temp6 = function () {
2229
2390
  if (has('text/plain')) {
2230
2391
  return Promise.resolve(get('text/plain')).then(function (text) {
2231
2392
  rows = parsePastedText(text);
2232
2393
  });
2233
2394
  }
2234
2395
  }();
2235
-
2236
- if (_temp9 && _temp9.then) return _temp9.then(function () {});
2396
+ if (_temp6 && _temp6.then) return _temp6.then(function () {});
2237
2397
  }
2238
2398
  }();
2239
-
2240
- return Promise.resolve(_temp8 && _temp8.then ? _temp8.then(_temp7) : _temp7(_temp8));
2399
+ return Promise.resolve(_temp4 && _temp4.then ? _temp4.then(_temp5) : _temp5(_temp4));
2241
2400
  } catch (e) {
2242
2401
  return Promise.reject(e);
2243
2402
  }
2244
2403
  };
2245
-
2246
2404
  var formatRowsAsTSV = function formatRowsAsTSV(rows) {
2247
2405
  return rows.map(function (row) {
2248
2406
  return row.join('\t');
2249
2407
  }).join('\n');
2250
2408
  };
2251
-
2252
2409
  var formatRowsAsHTML = function formatRowsAsHTML(rows, payload) {
2253
2410
  var trs = rows.map(function (row) {
2254
2411
  var tds = row.map(formatTextAsHTML).map(function (cell) {
@@ -2259,120 +2416,90 @@ var formatRowsAsHTML = function formatRowsAsHTML(rows, payload) {
2259
2416
  return "<tr>" + row + "</tr>";
2260
2417
  }).join('\n');
2261
2418
  var table = "<table>" + trs + "</table>";
2262
-
2263
2419
  if (payload) {
2264
2420
  var extra = "<SheetHappens payload=\"" + formatTextAsHTML(JSON.stringify(payload)) + "\"></SheetHappens>";
2265
2421
  return extra + table;
2266
2422
  }
2267
-
2268
2423
  return table;
2269
2424
  };
2270
-
2271
2425
  var formatTextAsHTML = function formatTextAsHTML(s) {
2272
2426
  return s.replace(/[&"'<>]/g, function (i) {
2273
2427
  return "&#" + i.charCodeAt(0) + ";";
2274
2428
  });
2275
2429
  };
2276
-
2277
2430
  var formatSelectionAsRows = function formatSelectionAsRows(selection, editData) {
2278
2431
  if (isEmptySelection(selection)) return [];
2279
-
2280
2432
  var _normalizeSelection2 = normalizeSelection(selection),
2281
- _normalizeSelection2$ = _normalizeSelection2[0],
2282
- minX = _normalizeSelection2$[0],
2283
- minY = _normalizeSelection2$[1],
2284
- _normalizeSelection2$2 = _normalizeSelection2[1],
2285
- maxX = _normalizeSelection2$2[0],
2286
- maxY = _normalizeSelection2$2[1];
2287
-
2433
+ _normalizeSelection2$ = _normalizeSelection2[0],
2434
+ minX = _normalizeSelection2$[0],
2435
+ minY = _normalizeSelection2$[1],
2436
+ _normalizeSelection2$2 = _normalizeSelection2[1],
2437
+ maxX = _normalizeSelection2$2[0],
2438
+ maxY = _normalizeSelection2$2[1];
2288
2439
  if (isMaybeRowSelection(selection)) {
2289
2440
  var _findApproxMaxEditDat = findApproxMaxEditDataIndex(editData),
2290
- cellX = _findApproxMaxEditDat[0];
2291
-
2441
+ cellX = _findApproxMaxEditDat[0];
2292
2442
  minX = 0;
2293
2443
  maxX = cellX;
2294
2444
  }
2295
-
2296
2445
  if (isMaybeColumnSelection(selection)) {
2297
2446
  var _findApproxMaxEditDat2 = findApproxMaxEditDataIndex(editData),
2298
- cellY = _findApproxMaxEditDat2[1];
2299
-
2447
+ cellY = _findApproxMaxEditDat2[1];
2300
2448
  minY = 0;
2301
2449
  maxY = cellY;
2302
2450
  }
2303
-
2304
2451
  var rows = [];
2305
-
2306
2452
  for (var y = minY; y <= maxY; y++) {
2307
2453
  var row = [];
2308
-
2309
2454
  for (var x = minX; x <= maxX; x++) {
2310
2455
  var value = editData(x, y);
2311
-
2312
2456
  if (value !== null && value !== undefined) {
2313
2457
  row.push(value != null ? value : '');
2314
2458
  }
2315
2459
  }
2316
-
2317
2460
  rows.push(row);
2318
2461
  }
2319
-
2320
2462
  return rows;
2321
2463
  };
2322
-
2323
- var findTag = function findTag(element, tagName) {
2464
+ var _findTag = function findTag(element, tagName) {
2324
2465
  for (var _iterator = _createForOfIteratorHelperLoose(element.children), _step; !(_step = _iterator()).done;) {
2325
2466
  var child = _step.value;
2326
-
2327
2467
  if (child.nodeName === tagName) {
2328
2468
  return child;
2329
2469
  }
2330
-
2331
- var maybeTag = findTag(child, tagName);
2332
-
2470
+ var maybeTag = _findTag(child, tagName);
2333
2471
  if (maybeTag) {
2334
2472
  return maybeTag;
2335
2473
  }
2336
2474
  }
2337
2475
  };
2338
-
2339
2476
  var parsePastedHtml = function parsePastedHtml(html) {
2340
2477
  var div = document.createElement('div');
2341
2478
  div.innerHTML = html.trim();
2342
2479
  var rows = [];
2343
2480
  var payload = undefined;
2344
- var sheetNode = findTag(div, 'SHEETHAPPENS');
2345
-
2481
+ var sheetNode = _findTag(div, 'SHEETHAPPENS');
2346
2482
  if (sheetNode) {
2347
2483
  var json = sheetNode.getAttribute('payload');
2348
-
2349
2484
  try {
2350
2485
  payload = JSON.parse(json);
2351
2486
  } catch (e) {}
2352
2487
  }
2353
-
2354
- var tableNode = findTag(div, 'TABLE');
2355
-
2488
+ var tableNode = _findTag(div, 'TABLE');
2356
2489
  if (tableNode) {
2357
2490
  for (var _iterator2 = _createForOfIteratorHelperLoose(tableNode.children), _step2; !(_step2 = _iterator2()).done;) {
2358
2491
  var tableChild = _step2.value;
2359
-
2360
2492
  if (tableChild.nodeName === 'TBODY') {
2361
2493
  for (var _iterator3 = _createForOfIteratorHelperLoose(tableChild.children), _step3; !(_step3 = _iterator3()).done;) {
2362
2494
  var tr = _step3.value;
2363
-
2364
2495
  if (tr.nodeName === 'TR') {
2365
2496
  var row = [];
2366
-
2367
2497
  for (var _iterator4 = _createForOfIteratorHelperLoose(tr.children), _step4; !(_step4 = _iterator4()).done;) {
2368
2498
  var td = _step4.value;
2369
-
2370
2499
  if (td.nodeName === 'TD') {
2371
2500
  var str = '';
2372
-
2373
2501
  if (td.children.length !== 0 && td.children[0].nodeName === 'P') {
2374
2502
  var p = td.children[0];
2375
-
2376
2503
  if (p.children.length !== 0 && p.children[0].nodeName === 'FONT') {
2377
2504
  str = p.children[0].textContent.trim();
2378
2505
  } else {
@@ -2381,26 +2508,22 @@ var parsePastedHtml = function parsePastedHtml(html) {
2381
2508
  } else {
2382
2509
  str = td.textContent.trim();
2383
2510
  }
2384
-
2385
2511
  str = str.replaceAll('\n', '');
2386
2512
  str = str.replaceAll(/\s\s+/g, ' ');
2387
2513
  row.push(str);
2388
2514
  }
2389
2515
  }
2390
-
2391
2516
  rows.push(row);
2392
2517
  }
2393
2518
  }
2394
2519
  }
2395
2520
  }
2396
2521
  }
2397
-
2398
2522
  return {
2399
2523
  rows: rows,
2400
2524
  payload: payload
2401
2525
  };
2402
2526
  };
2403
-
2404
2527
  var parsePastedText = function parsePastedText(text) {
2405
2528
  return text.split(/\r?\n/).map(function (line) {
2406
2529
  return line.split('\t');
@@ -2408,204 +2531,167 @@ var parsePastedText = function parsePastedText(text) {
2408
2531
  };
2409
2532
 
2410
2533
  var INITIAL_SIZE = 256;
2411
- var makeCellLayout = function makeCellLayout(freeze, indent, offset, columns, rows) {
2534
+ var makeCellLayout = function makeCellLayout(freeze, offset, columns, rows) {
2412
2535
  var freezeX = freeze[0],
2413
- freezeY = freeze[1];
2414
- var indentX = indent[0],
2415
- indentY = indent[1];
2536
+ freezeY = freeze[1];
2416
2537
  var offsetX = offset[0],
2417
- offsetY = offset[1];
2418
-
2538
+ offsetY = offset[1];
2419
2539
  var getIndentX = function getIndentX() {
2420
- return indentX;
2540
+ return columns.getStart(0);
2421
2541
  };
2422
-
2423
2542
  var getIndentY = function getIndentY() {
2424
- return indentY;
2543
+ return rows.getStart(0);
2425
2544
  };
2426
-
2427
2545
  var getBaseOriginFor = function getBaseOriginFor(index, freeze, offset) {
2428
2546
  return index < freeze ? 0 : offset + freeze;
2429
2547
  };
2430
-
2431
2548
  var columnToPixel = function columnToPixel(column, anchor) {
2432
2549
  if (anchor === void 0) {
2433
2550
  anchor = 0;
2434
2551
  }
2435
-
2436
2552
  var base = getBaseOriginFor(column, freezeX, offsetX);
2437
2553
  var relative = columns.getStart(column) - columns.getStart(base);
2438
2554
  var adjust = column < freezeX ? 0 : columns.getStart(freezeX) - columns.getStart(0);
2439
- var size = column < 0 ? indentX : columns.getSize(column);
2440
- return column < 0 ? 0 : indentX + relative + adjust + anchor * size;
2555
+ var size = columns.getSize(column);
2556
+ return getIndentX() + relative + adjust + anchor * size;
2441
2557
  };
2442
-
2443
2558
  var rowToPixel = function rowToPixel(row, anchor) {
2444
2559
  if (anchor === void 0) {
2445
2560
  anchor = 0;
2446
2561
  }
2447
-
2448
2562
  var base = getBaseOriginFor(row, freezeY, offsetY);
2449
2563
  var relative = rows.getStart(row) - rows.getStart(base);
2450
2564
  var adjust = row < freezeY ? 0 : rows.getStart(freezeY) - rows.getStart(0);
2451
- var size = row < 0 ? indentY : rows.getSize(row);
2452
- return row < 0 ? 0 : indentY + relative + adjust + anchor * size;
2565
+ var size = rows.getSize(row);
2566
+ return getIndentY() + relative + adjust + anchor * size;
2453
2567
  };
2454
-
2455
2568
  var cellToPixel = function cellToPixel(cell, anchor) {
2456
2569
  if (anchor === void 0) {
2457
2570
  anchor = ORIGIN;
2458
2571
  }
2459
-
2460
2572
  var cellX = cell[0],
2461
- cellY = cell[1];
2573
+ cellY = cell[1];
2462
2574
  var _anchor = anchor,
2463
- anchorX = _anchor[0],
2464
- anchorY = _anchor[1];
2575
+ anchorX = _anchor[0],
2576
+ anchorY = _anchor[1];
2465
2577
  return [columnToPixel(cellX, anchorX), rowToPixel(cellY, anchorY)];
2466
2578
  };
2467
-
2468
2579
  var columnToAbsolute = function columnToAbsolute(column, anchorX) {
2469
2580
  if (anchorX === void 0) {
2470
2581
  anchorX = 0;
2471
2582
  }
2472
-
2473
2583
  var relative = columns.getStart(column);
2474
2584
  var size = column < 0 ? 0 : columns.getSize(column);
2475
2585
  return relative + anchorX * size;
2476
2586
  };
2477
-
2478
2587
  var rowToAbsolute = function rowToAbsolute(row, anchorY) {
2479
2588
  if (anchorY === void 0) {
2480
2589
  anchorY = 0;
2481
2590
  }
2482
-
2483
2591
  var relative = rows.getStart(row);
2484
2592
  var size = row < 0 ? 0 : rows.getSize(row);
2485
2593
  return relative + anchorY * size;
2486
2594
  };
2487
-
2488
2595
  var cellToAbsolute = function cellToAbsolute(cell, anchor) {
2489
2596
  if (anchor === void 0) {
2490
2597
  anchor = ORIGIN;
2491
2598
  }
2492
-
2493
2599
  var cellX = cell[0],
2494
- cellY = cell[1];
2600
+ cellY = cell[1];
2495
2601
  var _anchor2 = anchor,
2496
- anchorX = _anchor2[0],
2497
- anchorY = _anchor2[1];
2602
+ anchorX = _anchor2[0],
2603
+ anchorY = _anchor2[1];
2498
2604
  return [columnToAbsolute(cellX, anchorX), rowToAbsolute(cellY, anchorY)];
2499
2605
  };
2500
-
2501
- var pixelToIndex = function pixelToIndex(pixel, anchor, indent, freeze, offset, layout) {
2502
- var relative = pixel - indent;
2503
- if (relative < 0) return -1;
2606
+ var pixelToIndex = function pixelToIndex(pixel, anchor, freeze, offset, layout) {
2504
2607
  var getStart = layout.getStart,
2505
- lookupIndex = layout.lookupIndex;
2608
+ lookupIndex = layout.lookupIndex;
2609
+ var indent = getStart(0);
2610
+ if (pixel < indent) return -1;
2506
2611
  var frozen = getStart(freeze);
2507
-
2508
- if (relative < frozen) {
2509
- return lookupIndex(relative, anchor);
2612
+ if (pixel < frozen) {
2613
+ return lookupIndex(pixel, anchor);
2510
2614
  } else {
2615
+ var relative = pixel - indent;
2511
2616
  var base = getStart(offset + freeze);
2512
2617
  var adjust = getStart(freeze) - getStart(0);
2513
2618
  return lookupIndex(base + relative - adjust, anchor);
2514
2619
  }
2515
2620
  };
2516
-
2517
2621
  var pixelToColumn = function pixelToColumn(pixelX, anchorX) {
2518
2622
  if (anchorX === void 0) {
2519
2623
  anchorX = 0;
2520
2624
  }
2521
-
2522
- return pixelToIndex(pixelX, anchorX, indentX, freezeX, offsetX, columns);
2625
+ return pixelToIndex(pixelX, anchorX, freezeX, offsetX, columns);
2523
2626
  };
2524
-
2525
2627
  var pixelToRow = function pixelToRow(pixelY, anchorY) {
2526
2628
  if (anchorY === void 0) {
2527
2629
  anchorY = 0;
2528
2630
  }
2529
-
2530
- return pixelToIndex(pixelY, anchorY, indentY, freezeY, offsetY, rows);
2631
+ return pixelToIndex(pixelY, anchorY, freezeY, offsetY, rows);
2531
2632
  };
2532
-
2533
2633
  var pixelToCell = function pixelToCell(pixel, anchor) {
2534
2634
  if (anchor === void 0) {
2535
2635
  anchor = ORIGIN;
2536
2636
  }
2537
-
2538
2637
  var pixelX = pixel[0],
2539
- pixelY = pixel[1];
2638
+ pixelY = pixel[1];
2540
2639
  var _anchor3 = anchor,
2541
- anchorX = _anchor3[0],
2542
- anchorY = _anchor3[1];
2640
+ anchorX = _anchor3[0],
2641
+ anchorY = _anchor3[1];
2543
2642
  return [pixelToColumn(pixelX, anchorX), pixelToRow(pixelY, anchorY)];
2544
2643
  };
2545
-
2546
2644
  var absoluteToIndex = function absoluteToIndex(pixel, anchor, layout) {
2547
2645
  if (pixel < 0) return -1;
2548
2646
  var lookupIndex = layout.lookupIndex;
2549
2647
  return lookupIndex(pixel, anchor);
2550
2648
  };
2551
-
2552
2649
  var absoluteToColumn = function absoluteToColumn(pixelX, anchorX) {
2553
2650
  if (anchorX === void 0) {
2554
2651
  anchorX = 0;
2555
2652
  }
2556
-
2557
2653
  return absoluteToIndex(pixelX, anchorX, columns);
2558
2654
  };
2559
-
2560
2655
  var absoluteToRow = function absoluteToRow(pixelY, anchorY) {
2561
2656
  if (anchorY === void 0) {
2562
2657
  anchorY = 0;
2563
2658
  }
2564
-
2565
2659
  return absoluteToIndex(pixelY, anchorY, rows);
2566
2660
  };
2567
-
2568
2661
  var absoluteToCell = function absoluteToCell(pixel, anchor) {
2569
2662
  if (anchor === void 0) {
2570
2663
  anchor = ORIGIN;
2571
2664
  }
2572
-
2573
2665
  var pixelX = pixel[0],
2574
- pixelY = pixel[1];
2666
+ pixelY = pixel[1];
2575
2667
  var _anchor4 = anchor,
2576
- anchorX = _anchor4[0],
2577
- anchorY = _anchor4[1];
2668
+ anchorX = _anchor4[0],
2669
+ anchorY = _anchor4[1];
2578
2670
  return [absoluteToColumn(pixelX, anchorX), absoluteToRow(pixelY, anchorY)];
2579
2671
  };
2580
-
2581
- var getVisibleIndices = function getVisibleIndices(view, indent, freeze, offset, layout) {
2672
+ var getVisibleIndices = function getVisibleIndices(view, freeze, offset, layout) {
2582
2673
  var indices = [].concat(seq(freeze));
2583
2674
  var getStart = layout.getStart,
2584
- getEnd = layout.getEnd;
2675
+ getEnd = layout.getEnd;
2585
2676
  var frozen = getEnd(freeze - 1);
2586
2677
  var notFrozen = getStart(offset + freeze);
2587
- var relative = view - indent - frozen;
2588
-
2678
+ var relative = view - frozen;
2589
2679
  for (var i = offset + freeze; getStart(i) - notFrozen <= relative; ++i) {
2590
2680
  indices.push(i);
2591
2681
  }
2592
-
2593
2682
  return indices;
2594
2683
  };
2595
-
2596
2684
  var getVisibleCells = function getVisibleCells(view) {
2597
2685
  var viewX = view[0],
2598
- viewY = view[1];
2686
+ viewY = view[1];
2599
2687
  return {
2600
- columns: getVisibleIndices(viewX, indentX, freezeX, offsetX, columns),
2601
- rows: getVisibleIndices(viewY, indentY, freezeY, offsetY, rows)
2688
+ columns: getVisibleIndices(viewX, freezeX, offsetX, columns),
2689
+ rows: getVisibleIndices(viewY, freezeY, offsetY, rows)
2602
2690
  };
2603
2691
  };
2604
-
2605
2692
  var getVersion = function getVersion() {
2606
2693
  return columns.getVersion() + rows.getVersion();
2607
2694
  };
2608
-
2609
2695
  return {
2610
2696
  columnToPixel: columnToPixel,
2611
2697
  rowToPixel: rowToPixel,
@@ -2629,76 +2715,58 @@ var makeLayoutCache = function makeLayoutCache(sizer) {
2629
2715
  var offsets = makeIntMap(INITIAL_SIZE);
2630
2716
  var sizes = makeIntMap(INITIAL_SIZE);
2631
2717
  var version = 0;
2632
- offsets.set(0, 0);
2633
-
2718
+ offsets.set(0, sizer(-1));
2634
2719
  var getSize = function getSize(i) {
2635
- if (i < 0) return 0;
2720
+ if (i < 0) return sizer(i);
2636
2721
  if (sizes.has(i)) return sizes.get(i);
2637
2722
  var size = sizer(i) || 0;
2638
2723
  sizes.set(i, size);
2639
2724
  return size;
2640
2725
  };
2641
-
2642
2726
  var getOffset = function getOffset(i) {
2643
2727
  if (i < 0) return 0;
2644
2728
  if (offsets.has(i)) return offsets.get(i);
2645
- var j = offsets.tail() || 0;
2646
-
2729
+ var j = offsets.tail() || -1;
2647
2730
  while (j < i) {
2648
2731
  var size = getSize(j);
2649
2732
  var offset = (offsets.get(j) || 0) + size;
2650
2733
  offsets.set(++j, offset);
2651
2734
  }
2652
-
2653
2735
  return offsets.get(i);
2654
2736
  };
2655
-
2656
2737
  var getStart = function getStart(i) {
2657
2738
  return getOffset(i);
2658
2739
  };
2659
-
2660
2740
  var getEnd = function getEnd(i) {
2661
2741
  return getOffset(i + 1);
2662
2742
  };
2663
-
2664
2743
  var lookupIndex = function lookupIndex(x, anchor) {
2665
2744
  if (anchor === void 0) {
2666
2745
  anchor = 0;
2667
2746
  }
2668
-
2669
2747
  var last = offsets.tail() || 0;
2670
-
2671
- while (getOffset(last) < x && getSize(last)) {
2672
- last += 64;
2673
- }
2674
-
2748
+ while (getOffset(last) < x && getSize(last)) last += 64;
2675
2749
  var start = 0;
2676
2750
  var end = last;
2677
-
2678
2751
  while (start < end) {
2679
2752
  var mid = start + Math.floor((end - start) / 2) + 1;
2680
2753
  var value = getOffset(mid) - (anchor ? anchor * getSize(mid - 1) : 0);
2681
2754
  if (value <= x) start = mid;else end = mid - 1;
2682
2755
  }
2683
-
2684
2756
  return start;
2685
2757
  };
2686
-
2687
2758
  var clearAfter = function clearAfter(index) {
2688
2759
  index = Math.max(0, index);
2689
2760
  offsets.truncate(index);
2690
2761
  sizes.truncate(index);
2691
2762
  version++;
2692
2763
  };
2693
-
2694
2764
  var setSizer = function setSizer(s) {
2695
2765
  sizer = s;
2696
2766
  };
2697
-
2698
2767
  var getVersion = function getVersion() {
2699
2768
  return version;
2700
2769
  };
2701
-
2702
2770
  return {
2703
2771
  getSize: getSize,
2704
2772
  getStart: getStart,
@@ -2709,17 +2777,14 @@ var makeLayoutCache = function makeLayoutCache(sizer) {
2709
2777
  clearAfter: clearAfter
2710
2778
  };
2711
2779
  };
2712
-
2713
2780
  var makeIntMap = function makeIntMap(initialSize) {
2714
2781
  if (initialSize === void 0) {
2715
2782
  initialSize = 128;
2716
2783
  }
2717
-
2718
2784
  var used;
2719
2785
  var values;
2720
2786
  var last = 0;
2721
2787
  var GROW = 1.2;
2722
-
2723
2788
  var allocate = function allocate(size) {
2724
2789
  var newUsed = new Uint8Array(size);
2725
2790
  var newValues = new Uint32Array(size);
@@ -2728,56 +2793,41 @@ var makeIntMap = function makeIntMap(initialSize) {
2728
2793
  used = newUsed;
2729
2794
  values = newValues;
2730
2795
  };
2731
-
2732
2796
  allocate(initialSize);
2733
-
2734
2797
  var copy = function copy(from, to) {
2735
2798
  var n = Math.min(from.length, to.length);
2736
-
2737
2799
  for (var i = 0; i < n; ++i) {
2738
2800
  to[i] = from[i];
2739
2801
  }
2740
2802
  };
2741
-
2742
2803
  var ensure = function ensure(size) {
2743
2804
  var l = values.length;
2744
2805
  var grow = Math.round(l * GROW);
2745
2806
  if (l < size) allocate(Math.max(grow, size));
2746
2807
  };
2747
-
2748
2808
  var truncate = function truncate(size) {
2749
2809
  var l = values.length;
2750
2810
  if (l < size) return;
2751
2811
  var shrink = Math.round(size * GROW);
2752
- if (l > shrink) allocate(size);else for (var i = size; i < l; ++i) {
2753
- used[i] = 0;
2754
- }
2812
+ if (l > shrink) allocate(size);else for (var i = size; i < l; ++i) used[i] = 0;
2755
2813
  last = Math.min(last, size);
2756
-
2757
- while (last > 0 && !used[last]) {
2758
- last--;
2759
- }
2814
+ while (last > 0 && !used[last]) last--;
2760
2815
  };
2761
-
2762
2816
  var getTail = function getTail() {
2763
2817
  return used[last] ? last : null;
2764
2818
  };
2765
-
2766
2819
  var setValue = function setValue(i, value) {
2767
2820
  ensure(i + 1);
2768
2821
  values[i] = value;
2769
2822
  used[i] = 1;
2770
2823
  last = Math.max(last, i);
2771
2824
  };
2772
-
2773
2825
  var getValue = function getValue(i) {
2774
2826
  return used[i] ? values[i] : null;
2775
2827
  };
2776
-
2777
2828
  var hasValue = function hasValue(i) {
2778
2829
  return !!used[i];
2779
2830
  };
2780
-
2781
2831
  return {
2782
2832
  truncate: truncate,
2783
2833
  set: setValue,
@@ -2787,191 +2837,129 @@ var makeIntMap = function makeIntMap(initialSize) {
2787
2837
  };
2788
2838
  };
2789
2839
 
2790
- var resolveSheetStyle = function resolveSheetStyle(sheetStyle) {
2791
- var _sheetStyle$shadowBlu, _sheetStyle$shadowOpa, _sheetStyle$shadowCol;
2792
-
2793
- return {
2794
- freezeColumns: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.freezeColumns) || 0,
2795
- freezeRows: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.freezeRows) || 0,
2796
- hideColumnHeaders: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.hideColumnHeaders) || false,
2797
- hideRowHeaders: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.hideRowHeaders) || false,
2798
- hideGridlines: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.hideGridlines) || false,
2799
- hideScrollBars: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.hideScrollBars) || false,
2800
- columnHeaderHeight: sheetStyle !== null && sheetStyle !== void 0 && sheetStyle.hideColumnHeaders ? 1 : SIZES.headerHeight,
2801
- rowHeaderWidth: sheetStyle !== null && sheetStyle !== void 0 && sheetStyle.hideRowHeaders ? 1 : SIZES.headerWidth,
2802
- shadowBlur: (_sheetStyle$shadowBlu = sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.shadowBlur) != null ? _sheetStyle$shadowBlu : SIZES.shadowBlur,
2803
- shadowOpacity: (_sheetStyle$shadowOpa = sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.shadowOpacity) != null ? _sheetStyle$shadowOpa : SIZES.shadowOpacity,
2804
- shadowColor: (_sheetStyle$shadowCol = sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.shadowColor) != null ? _sheetStyle$shadowCol : COLORS.shadowColor
2805
- };
2806
- };
2807
- var applyAlignment = function applyAlignment(start, cellSize, style, imageWidth, alignment) {
2808
- if (alignment === void 0) {
2809
- alignment = style.textAlign;
2810
- }
2811
-
2812
- if (alignment === 'left') {
2813
- return start + style.marginLeft;
2814
- } else if (alignment === 'center') {
2815
- return start + cellSize * 0.5 - imageWidth / 2;
2816
- } else if (alignment === 'right') {
2817
- return start + (cellSize - style.marginRight - imageWidth);
2818
- }
2819
-
2820
- return start;
2821
- };
2822
-
2823
- var renderSheet = function renderSheet(context, cellLayout, visibleCells, sheetStyle, cellStyle, selection, secondarySelections, isFocused, knobPosition, knobArea, dragIndices, dragOffset, dropTarget, columnHeaders, columnHeaderStyle, displayData, columnGroupKeys, rowGroupKeys, selectedColumnGroups, selectedRowGroups, dataOffset) {
2840
+ var renderSheet = function renderSheet(context, imageRenderer, cellLayout, visibleCells, sheetStyle, cellStyle, selection, secondarySelections, isFocused, knobPosition, knobArea, dragIndices, dragOffset, dropTarget, columnHeaders, columnHeaderStyle, displayData, columnGroupKeys, rowGroupKeys, selectedColumnGroups, selectedRowGroups, dataOffset) {
2824
2841
  var canvas = context.canvas;
2825
2842
  var width = canvas.width,
2826
- height = canvas.height;
2843
+ height = canvas.height;
2827
2844
  var hideGridlines = sheetStyle.hideGridlines,
2828
- hideRowHeaders = sheetStyle.hideRowHeaders,
2829
- hideColumnHeaders = sheetStyle.hideColumnHeaders,
2830
- rowHeaderWidth = sheetStyle.rowHeaderWidth,
2831
- columnHeaderHeight = sheetStyle.columnHeaderHeight,
2832
- freezeColumns = sheetStyle.freezeColumns,
2833
- freezeRows = sheetStyle.freezeRows,
2834
- shadowBlur = sheetStyle.shadowBlur,
2835
- shadowColor = sheetStyle.shadowColor,
2836
- shadowOpacity = sheetStyle.shadowOpacity;
2845
+ hideRowHeaders = sheetStyle.hideRowHeaders,
2846
+ hideColumnHeaders = sheetStyle.hideColumnHeaders,
2847
+ freezeColumns = sheetStyle.freezeColumns,
2848
+ freezeRows = sheetStyle.freezeRows,
2849
+ shadowBlur = sheetStyle.shadowBlur,
2850
+ shadowColor = sheetStyle.shadowColor,
2851
+ shadowOpacity = sheetStyle.shadowOpacity;
2837
2852
  var columns = visibleCells.columns,
2838
- rows = visibleCells.rows;
2853
+ rows = visibleCells.rows;
2839
2854
  var columnToPixel = cellLayout.columnToPixel,
2840
- rowToPixel = cellLayout.rowToPixel,
2841
- columnToAbsolute = cellLayout.columnToAbsolute,
2842
- rowToAbsolute = cellLayout.rowToAbsolute;
2843
- var clickables = [];
2855
+ rowToPixel = cellLayout.rowToPixel,
2856
+ columnToAbsolute = cellLayout.columnToAbsolute,
2857
+ rowToAbsolute = cellLayout.rowToAbsolute;
2858
+ var allClickables = [];
2844
2859
  var freeze = [freezeColumns, freezeRows];
2845
- var indent = [rowHeaderWidth, columnHeaderHeight];
2846
- var pixelRatio = resizeCanvas(canvas);
2860
+ var indentX = columnToAbsolute(0);
2861
+ var indentY = rowToAbsolute(0);
2862
+ resizeCanvas(canvas);
2847
2863
  context.clearRect(0, 0, width, height);
2848
2864
  context.fillStyle = 'white';
2849
2865
  context.fillRect(0, 0, width, height);
2850
2866
  context.shadowColor = '#00000080';
2851
-
2852
2867
  for (var _iterator = _createForOfIteratorHelperLoose(rows), _step; !(_step = _iterator()).done;) {
2853
2868
  var y = _step.value;
2854
-
2855
2869
  for (var _iterator10 = _createForOfIteratorHelperLoose(columns), _step10; !(_step10 = _iterator10()).done;) {
2856
2870
  var x = _step10.value;
2857
-
2858
2871
  var _left7 = columnToPixel(x);
2859
-
2860
2872
  var _right7 = columnToPixel(x, 1);
2861
-
2862
2873
  var _top7 = rowToPixel(y);
2863
-
2864
2874
  var _bottom7 = rowToPixel(y, 1);
2865
-
2866
2875
  var _cellStyle = cellStyle(x, y),
2867
- fillColor = _cellStyle.fillColor;
2868
-
2876
+ fillColor = _cellStyle.fillColor;
2869
2877
  if (fillColor) {
2870
2878
  context.fillStyle = fillColor;
2871
2879
  context.fillRect(_left7, _top7, _right7 - _left7, _bottom7 - _top7);
2872
2880
  }
2873
2881
  }
2874
2882
  }
2875
-
2876
2883
  var selectionActive = !isEmptySelection(selection);
2877
2884
  var rowSelectionActive = isRowSelection(selection);
2878
2885
  var columnSelectionActive = isColumnSelection(selection);
2879
-
2880
- var _resolveFrozenSelecti = resolveFrozenSelection(selection, cellLayout, freeze, indent, dataOffset),
2881
- selected = _resolveFrozenSelecti[0],
2882
- hideKnob = _resolveFrozenSelecti[1];
2883
-
2886
+ var _resolveFrozenSelecti = resolveFrozenSelection(selection, cellLayout, freeze, dataOffset),
2887
+ selected = _resolveFrozenSelecti[0],
2888
+ hideKnob = _resolveFrozenSelecti[1];
2884
2889
  if (selectionActive) {
2885
2890
  var _selected$ = selected[0],
2886
- left = _selected$[0],
2887
- top = _selected$[1],
2888
- _selected$2 = selected[1],
2889
- right = _selected$2[0],
2890
- bottom = _selected$2[1];
2891
+ left = _selected$[0],
2892
+ top = _selected$[1],
2893
+ _selected$2 = selected[1],
2894
+ right = _selected$2[0],
2895
+ bottom = _selected$2[1];
2891
2896
  context.fillStyle = COLORS.selectionBackground;
2892
2897
  context.fillRect(left, top, right - left, bottom - top);
2893
2898
  }
2894
-
2895
2899
  if (!hideRowHeaders) {
2896
2900
  context.fillStyle = COLORS.headerBackground;
2897
- context.fillRect(0, 0, rowHeaderWidth, context.canvas.height);
2898
-
2901
+ context.fillRect(0, 0, indentX, context.canvas.height);
2899
2902
  if (selectionActive && !columnSelectionActive) {
2900
2903
  var _selected$3 = selected[0],
2901
- _top = _selected$3[1],
2902
- _selected$4 = selected[1],
2903
- _bottom = _selected$4[1];
2904
+ _top = _selected$3[1],
2905
+ _selected$4 = selected[1],
2906
+ _bottom = _selected$4[1];
2904
2907
  context.fillStyle = COLORS.headerActive;
2905
- context.fillRect(0, _top, rowHeaderWidth, _bottom - _top);
2908
+ context.fillRect(0, _top, indentX, _bottom - _top);
2906
2909
  }
2907
2910
  }
2908
-
2909
2911
  if (!hideColumnHeaders) {
2910
2912
  context.fillStyle = COLORS.headerBackground;
2911
- context.fillRect(0, 0, context.canvas.width, columnHeaderHeight);
2912
-
2913
+ context.fillRect(0, 0, context.canvas.width, indentY);
2913
2914
  if (selectionActive && !rowSelectionActive) {
2914
2915
  var _selected$5 = selected[0],
2915
- _left = _selected$5[0],
2916
- _selected$6 = selected[1],
2917
- _right = _selected$6[0];
2916
+ _left = _selected$5[0],
2917
+ _selected$6 = selected[1],
2918
+ _right = _selected$6[0];
2918
2919
  context.fillStyle = COLORS.headerActive;
2919
- context.fillRect(_left, 0, _right - _left, columnHeaderHeight);
2920
+ context.fillRect(_left, 0, _right - _left, indentY);
2920
2921
  }
2921
2922
  }
2922
-
2923
2923
  context.strokeStyle = COLORS.gridLine;
2924
2924
  context.lineWidth = 1;
2925
- var gridRight = hideGridlines ? rowHeaderWidth : context.canvas.width;
2926
- var gridBottom = hideGridlines ? columnHeaderHeight : context.canvas.height;
2927
-
2925
+ var gridRight = hideGridlines ? indentX : context.canvas.width;
2926
+ var gridBottom = hideGridlines ? indentY : context.canvas.height;
2928
2927
  var drawGridLineX = function drawGridLineX(x, height) {
2929
2928
  context.beginPath();
2930
2929
  context.moveTo(x - 0.5, 0);
2931
2930
  context.lineTo(x - 0.5, height);
2932
2931
  context.stroke();
2933
2932
  };
2934
-
2935
2933
  var drawGridLineY = function drawGridLineY(y, width) {
2936
2934
  context.beginPath();
2937
2935
  context.moveTo(0, y - 0.5);
2938
2936
  context.lineTo(width, y - 0.5);
2939
2937
  context.stroke();
2940
2938
  };
2941
-
2942
- drawGridLineX(rowHeaderWidth, context.canvas.height);
2943
- drawGridLineY(columnHeaderHeight, context.canvas.width);
2944
-
2939
+ drawGridLineX(indentX, context.canvas.height);
2940
+ drawGridLineY(indentY, context.canvas.width);
2945
2941
  for (var _iterator2 = _createForOfIteratorHelperLoose(columns), _step2; !(_step2 = _iterator2()).done;) {
2946
2942
  var _column2 = _step2.value;
2947
-
2948
2943
  var _right8 = columnToPixel(_column2, 1);
2949
-
2950
2944
  drawGridLineX(_right8, gridBottom);
2951
2945
  }
2952
-
2953
2946
  for (var _iterator3 = _createForOfIteratorHelperLoose(rows), _step3; !(_step3 = _iterator3()).done;) {
2954
2947
  var _row2 = _step3.value;
2955
-
2956
2948
  var _bottom8 = rowToPixel(_row2, 1);
2957
-
2958
2949
  drawGridLineY(_bottom8, gridRight);
2959
2950
  }
2960
-
2961
2951
  var _normalizeSelection = normalizeSelection(selection),
2962
- _normalizeSelection$ = _normalizeSelection[0],
2963
- minX = _normalizeSelection$[0],
2964
- minY = _normalizeSelection$[1],
2965
- _normalizeSelection$2 = _normalizeSelection[1],
2966
- maxX = _normalizeSelection$2[0],
2967
- maxY = _normalizeSelection$2[1];
2968
-
2952
+ _normalizeSelection$ = _normalizeSelection[0],
2953
+ minX = _normalizeSelection$[0],
2954
+ minY = _normalizeSelection$[1],
2955
+ _normalizeSelection$2 = _normalizeSelection[1],
2956
+ maxX = _normalizeSelection$2[0],
2957
+ maxY = _normalizeSelection$2[1];
2969
2958
  if (!hideRowHeaders) {
2970
2959
  context.textBaseline = 'middle';
2971
2960
  context.textAlign = 'center';
2972
2961
  context.font = DEFAULT_CELL_STYLE.fontSize + 'px ' + DEFAULT_CELL_STYLE.fontFamily;
2973
2962
  context.fillStyle = COLORS.headerText;
2974
-
2975
2963
  for (var _iterator4 = _createForOfIteratorHelperLoose(rows), _step4; !(_step4 = _iterator4()).done;) {
2976
2964
  var row = _step4.value;
2977
2965
  var content = "" + (row + 1);
@@ -2981,542 +2969,469 @@ var renderSheet = function renderSheet(context, cellLayout, visibleCells, sheetS
2981
2969
  var isSelfSelected = rowSelectionActive && isActive;
2982
2970
  var isGroupSelected = rowSelectionActive && isInRowGroup;
2983
2971
  var style = isSelfSelected ? HEADER_SELECTED_STYLE : isGroupSelected ? HEADER_GROUP_SELECTED_STYLE : isActive ? HEADER_ACTIVE_STYLE : NO_STYLE;
2984
-
2985
2972
  var resolvedStyle = _extends({}, DEFAULT_COLUMN_HEADER_STYLE, style);
2986
-
2987
2973
  var _top2 = rowToPixel(row);
2988
-
2989
2974
  var _bottom2 = rowToPixel(row, 1);
2990
-
2991
- clickables.push.apply(clickables, renderCell(context, content, resolvedStyle, 0, _top2, rowHeaderWidth, _bottom2 - _top2, pixelRatio));
2975
+ var clickables = renderCell(context, imageRenderer, content, resolvedStyle, 0, _top2, indentX, _bottom2 - _top2);
2976
+ if (clickables) allClickables.push.apply(allClickables, clickables);
2992
2977
  }
2993
2978
  }
2994
-
2995
2979
  if (!hideColumnHeaders) {
2996
2980
  context.textBaseline = 'middle';
2997
- context.textAlign = 'center';
2998
-
2999
2981
  for (var _iterator5 = _createForOfIteratorHelperLoose(columns), _step5; !(_step5 = _iterator5()).done;) {
3000
2982
  var _columnHeaders;
3001
-
3002
2983
  var column = _step5.value;
3003
-
3004
2984
  var _isActive = isInRange(column, minX, maxX);
3005
-
3006
2985
  var _groupKey = columnGroupKeys(column);
3007
-
3008
2986
  var isInColumnGroup = _groupKey != null && (selectedColumnGroups === null || selectedColumnGroups === void 0 ? void 0 : selectedColumnGroups.has(_groupKey));
3009
2987
  var isSelected = columnSelectionActive && !rowSelectionActive && (_isActive || isInColumnGroup);
3010
2988
  var selectedStyle = isSelected ? HEADER_SELECTED_STYLE : NO_STYLE;
3011
2989
  var activeStyle = _isActive ? HEADER_ACTIVE_STYLE : NO_STYLE;
3012
-
3013
2990
  var _style = _extends({}, DEFAULT_COLUMN_HEADER_STYLE, columnHeaderStyle(column), activeStyle, selectedStyle);
3014
-
3015
2991
  var _left2 = columnToPixel(column);
3016
-
3017
2992
  var _right2 = columnToPixel(column, 1);
3018
-
3019
2993
  var _content = (_columnHeaders = columnHeaders(column, _style)) != null ? _columnHeaders : excelHeaderString(column + 1);
3020
-
3021
- clickables.push.apply(clickables, renderCell(context, _content, _style, _left2, 0, _right2 - _left2, columnHeaderHeight, pixelRatio));
2994
+ var _clickables = renderCell(context, imageRenderer, _content, _style, _left2, 0, _right2 - _left2, indentY);
2995
+ if (_clickables) allClickables.push.apply(allClickables, _clickables);
3022
2996
  }
3023
2997
  }
3024
-
3025
2998
  if (selectionActive) {
3026
2999
  context.strokeStyle = COLORS.selectionBorder;
3027
3000
  context.lineWidth = 2;
3028
3001
  context.globalAlpha = isFocused ? 1 : 0.5;
3029
3002
  var _selected$7 = selected[0],
3030
- _left3 = _selected$7[0],
3031
- _top3 = _selected$7[1],
3032
- _selected$8 = selected[1],
3033
- _right3 = _selected$8[0],
3034
- _bottom3 = _selected$8[1];
3003
+ _left3 = _selected$7[0],
3004
+ _top3 = _selected$7[1],
3005
+ _selected$8 = selected[1],
3006
+ _right3 = _selected$8[0],
3007
+ _bottom3 = _selected$8[1];
3035
3008
  context.strokeRect(_left3, _top3, _right3 - _left3 - 1, _bottom3 - _top3 - 1);
3036
3009
  context.globalAlpha = 1;
3037
3010
  }
3038
-
3039
3011
  for (var _iterator6 = _createForOfIteratorHelperLoose(secondarySelections), _step6; !(_step6 = _iterator6()).done;) {
3040
3012
  var secondarySelection = _step6.value;
3041
3013
  var _selection = secondarySelection.span;
3042
3014
  if (isEmptySelection(_selection)) continue;
3043
-
3044
- var _resolveFrozenSelecti2 = resolveFrozenSelection(_selection, cellLayout, freeze, indent, dataOffset),
3045
- _selected = _resolveFrozenSelecti2[0];
3046
-
3015
+ var _resolveFrozenSelecti2 = resolveFrozenSelection(_selection, cellLayout, freeze, dataOffset),
3016
+ _selected = _resolveFrozenSelecti2[0];
3047
3017
  var _selected$9 = _selected[0],
3048
- _left8 = _selected$9[0],
3049
- _top8 = _selected$9[1],
3050
- _selected$10 = _selected[1],
3051
- _right9 = _selected$10[0],
3052
- _bottom9 = _selected$10[1];
3018
+ _left8 = _selected$9[0],
3019
+ _top8 = _selected$9[1],
3020
+ _selected$10 = _selected[1],
3021
+ _right9 = _selected$10[0],
3022
+ _bottom9 = _selected$10[1];
3053
3023
  context.strokeStyle = secondarySelection.color;
3054
3024
  context.lineWidth = 1;
3055
3025
  context.beginPath();
3056
3026
  context.strokeRect(_left8 - 1, _top8 - 1, _right9 - _left8 + 1, _bottom9 - _top8 + 1);
3057
3027
  }
3058
-
3059
3028
  if (knobArea) {
3060
3029
  var _normalizeSelection2 = normalizeSelection(knobArea),
3061
- _normalizeSelection2$ = _normalizeSelection2[0],
3062
- _minX = _normalizeSelection2$[0],
3063
- _minY = _normalizeSelection2$[1],
3064
- _normalizeSelection2$2 = _normalizeSelection2[1],
3065
- _maxX = _normalizeSelection2$2[0],
3066
- _maxY = _normalizeSelection2$2[1];
3067
-
3030
+ _normalizeSelection2$ = _normalizeSelection2[0],
3031
+ _minX = _normalizeSelection2$[0],
3032
+ _minY = _normalizeSelection2$[1],
3033
+ _normalizeSelection2$2 = _normalizeSelection2[1],
3034
+ _maxX = _normalizeSelection2$2[0],
3035
+ _maxY = _normalizeSelection2$2[1];
3068
3036
  var _left4 = columnToPixel(_minX);
3069
-
3070
3037
  var _top4 = rowToPixel(_minY);
3071
-
3072
3038
  var _right4 = columnToPixel(_maxX, 1);
3073
-
3074
3039
  var _bottom4 = rowToPixel(_maxY, 1);
3075
-
3076
3040
  context.strokeStyle = COLORS.knobAreaBorder;
3077
3041
  context.setLineDash([3, 3]);
3078
3042
  context.lineWidth = 1;
3079
3043
  context.strokeRect(_left4 - 1, _top4 - 1, _right4 - _left4 + 1, _bottom4 - _top4 + 1);
3080
3044
  context.setLineDash([]);
3081
3045
  }
3082
-
3083
3046
  if (knobPosition && !hideKnob) {
3084
3047
  var knobX = knobPosition[0],
3085
- knobY = knobPosition[1];
3048
+ knobY = knobPosition[1];
3086
3049
  context.fillStyle = COLORS.selectionBorder;
3087
3050
  context.fillRect(knobX - SIZES.knobArea * 0.5, knobY - SIZES.knobArea * 0.5, SIZES.knobArea, SIZES.knobArea);
3088
3051
  }
3089
-
3090
3052
  if (dragOffset) {
3091
3053
  var shiftX = dragOffset[0],
3092
- shiftY = dragOffset[1];
3054
+ shiftY = dragOffset[1];
3093
3055
  var dragColumns = dragIndices[0],
3094
- dragRows = dragIndices[1];
3056
+ dragRows = dragIndices[1];
3095
3057
  context.fillStyle = COLORS.dragGhost;
3096
-
3097
3058
  if (dragColumns) {
3098
3059
  for (var _iterator7 = _createForOfIteratorHelperLoose(dragColumns), _step7; !(_step7 = _iterator7()).done;) {
3099
3060
  var _column = _step7.value;
3100
-
3101
3061
  var _left5 = columnToPixel(_column);
3102
-
3103
3062
  var _right5 = columnToPixel(_column, 1);
3104
-
3105
3063
  context.fillRect(_left5 + shiftX, 0, _right5 - _left5, height);
3106
3064
  }
3107
3065
  }
3108
-
3109
3066
  if (dragRows) {
3110
3067
  for (var _iterator8 = _createForOfIteratorHelperLoose(dragRows), _step8; !(_step8 = _iterator8()).done;) {
3111
3068
  var _row = _step8.value;
3112
-
3113
3069
  var _top5 = rowToPixel(_row);
3114
-
3115
3070
  var _bottom5 = rowToPixel(_row, 1);
3116
-
3117
3071
  context.fillRect(0, _top5 + shiftY, width, _bottom5 - _top5);
3118
3072
  }
3119
3073
  }
3120
3074
  }
3121
-
3122
3075
  if (dropTarget) {
3123
3076
  var _resolveSelection = resolveSelection(dropTarget, cellLayout),
3124
- _resolveSelection$ = _resolveSelection[0],
3125
- _left6 = _resolveSelection$[0],
3126
- _top6 = _resolveSelection$[1],
3127
- _resolveSelection$2 = _resolveSelection[1],
3128
- _right6 = _resolveSelection$2[0],
3129
- _bottom6 = _resolveSelection$2[1];
3130
-
3077
+ _resolveSelection$ = _resolveSelection[0],
3078
+ _left6 = _resolveSelection$[0],
3079
+ _top6 = _resolveSelection$[1],
3080
+ _resolveSelection$2 = _resolveSelection[1],
3081
+ _right6 = _resolveSelection$2[0],
3082
+ _bottom6 = _resolveSelection$2[1];
3131
3083
  context.strokeStyle = COLORS.dropTarget;
3132
3084
  context.lineWidth = 4;
3133
-
3134
3085
  if (isColumnSelection(dropTarget)) {
3135
3086
  _right6 = _left6;
3136
3087
  }
3137
-
3138
3088
  if (isRowSelection(dropTarget)) {
3139
3089
  _bottom6 = _top6;
3140
3090
  }
3141
-
3142
3091
  context.strokeRect(_left6 - 1, _top6 - 1, _right6 - _left6, _bottom6 - _top6);
3143
3092
  }
3144
-
3145
3093
  var scrollX = dataOffset[0],
3146
- scrollY = dataOffset[1];
3094
+ scrollY = dataOffset[1];
3147
3095
  var hasRowShadow = freezeRows > 0 && scrollY > 0;
3148
3096
  var hasColumnShadow = freezeColumns > 0 && scrollX > 0;
3149
-
3150
3097
  if (hasRowShadow || hasColumnShadow) {
3151
3098
  if (hasRowShadow) {
3152
- var h = columnHeaderHeight + rowToAbsolute(freezeRows);
3099
+ var h = rowToAbsolute(freezeRows);
3153
3100
  var gradient = context.createLinearGradient(0, h, 0, h + shadowBlur);
3154
3101
  halfShadowGradient(gradient, shadowColor, shadowOpacity);
3155
3102
  context.fillStyle = gradient;
3156
3103
  context.fillRect(0, h, width, shadowBlur);
3157
3104
  }
3158
-
3159
3105
  if (hasColumnShadow) {
3160
- var w = rowHeaderWidth + columnToAbsolute(freezeColumns);
3161
-
3106
+ var w = columnToAbsolute(freezeColumns);
3162
3107
  var _gradient = context.createLinearGradient(w, 0, w + shadowBlur, 0);
3163
-
3164
3108
  halfShadowGradient(_gradient, shadowColor, shadowOpacity);
3165
3109
  context.fillStyle = _gradient;
3166
3110
  context.fillRect(w, 0, shadowBlur, height);
3167
3111
  }
3168
3112
  }
3169
-
3170
3113
  context.textBaseline = 'middle';
3171
-
3172
3114
  for (var _iterator9 = _createForOfIteratorHelperLoose(rows), _step9; !(_step9 = _iterator9()).done;) {
3173
3115
  var _y = _step9.value;
3174
-
3175
3116
  for (var _iterator11 = _createForOfIteratorHelperLoose(columns), _step11; !(_step11 = _iterator11()).done;) {
3176
3117
  var _x = _step11.value;
3177
-
3178
3118
  var _left9 = columnToPixel(_x);
3179
-
3180
3119
  var _right10 = columnToPixel(_x, 1);
3181
-
3182
3120
  var _top9 = rowToPixel(_y);
3183
-
3184
3121
  var _bottom10 = rowToPixel(_y, 1);
3185
-
3186
3122
  var _style2 = _extends({}, DEFAULT_CELL_STYLE, cellStyle(_x, _y));
3187
-
3188
3123
  var cellContent = displayData(_x, _y, _style2);
3189
-
3190
3124
  if (cellContent !== null && cellContent !== undefined) {
3191
- clickables.push.apply(clickables, renderCell(context, cellContent, _style2, _left9, _top9, _right10 - _left9, _bottom10 - _top9, pixelRatio));
3125
+ var _clickables2 = renderCell(context, imageRenderer, cellContent, _style2, _left9, _top9, _right10 - _left9, _bottom10 - _top9);
3126
+ if (_clickables2) allClickables.push.apply(allClickables, _clickables2);
3192
3127
  }
3193
3128
  }
3194
3129
  }
3195
-
3196
- return clickables;
3130
+ return allClickables;
3197
3131
  };
3198
- var renderCell = function renderCell(context, cellContent, style, xCoord, yCoord, cellWidth, cellHeight, pixelRatio) {
3199
- var clickables = [];
3200
-
3132
+ var renderCell = function renderCell(context, imageRenderer, cellContent, style, xCoord, yCoord, cellWidth, cellHeight) {
3201
3133
  if (cellContent === null) {
3202
- return clickables;
3134
+ return null;
3203
3135
  }
3204
-
3136
+ var fillText = context.fillText.bind(context);
3137
+ var fontString = style.fontWeight + ' ' + style.fontSize + 'px ' + style.fontFamily;
3138
+ context.font = fontString;
3205
3139
  context.fillStyle = style.color;
3206
- context.font = style.weight + ' ' + style.fontSize + 'px ' + style.fontFamily;
3207
- context.textAlign = style.textAlign;
3208
- var yy = Math.round((yCoord + cellHeight * 0.5) * pixelRatio) / pixelRatio;
3209
- context.save();
3210
- context.beginPath();
3211
- context.rect(xCoord, yCoord, cellWidth, cellHeight);
3212
- context.clip();
3213
-
3140
+ var marginTop = style.marginTop,
3141
+ marginBottom = style.marginBottom,
3142
+ marginLeft = style.marginLeft,
3143
+ marginRight = style.marginRight,
3144
+ lineHeight = style.lineHeight;
3145
+ var innerX = Math.round(xCoord + marginLeft);
3146
+ var innerY = Math.round(yCoord + marginTop);
3147
+ var innerWidth = Math.round(cellWidth - marginRight - marginLeft);
3148
+ var innerHeight = Math.round(cellHeight - marginTop - marginBottom);
3149
+ var middleY = roundDpi(yCoord + marginTop + lineHeight / 2);
3214
3150
  if (style.backgroundColor !== '') {
3215
3151
  context.fillStyle = style.backgroundColor;
3216
3152
  context.fillRect(xCoord, yCoord, cellWidth, cellHeight);
3217
3153
  context.fillStyle = style.color;
3218
3154
  }
3219
-
3220
3155
  if (typeof cellContent === 'string' || typeof cellContent === 'number') {
3221
- var xx = applyAlignment(xCoord, cellWidth, style, 0);
3222
- var text = '' + cellContent;
3223
- context.fillText(text, xx, yy);
3156
+ clipToBox(context, xCoord, yCoord, cellWidth, cellHeight, function () {
3157
+ wrapText(context, cellContent, style, undefined, innerX, middleY, innerWidth, innerHeight, fillText);
3158
+ });
3159
+ return null;
3224
3160
  } else if (typeof cellContent === 'object') {
3225
- for (var _iterator12 = _createForOfIteratorHelperLoose(cellContent.items), _step12; !(_step12 = _iterator12()).done;) {
3226
- var obj = _step12.value;
3227
- var x = 0;
3228
- var y = 0;
3229
- var w = 0;
3230
- var h = 0;
3231
-
3232
- if (obj.content instanceof HTMLImageElement) {
3233
- w = obj.width || cellWidth;
3234
- h = obj.height || cellHeight;
3235
- var finalX = applyAlignment(xCoord, cellWidth, style, w, obj.horizontalAlign);
3236
- x = finalX + obj.x;
3237
- y = yy + obj.y;
3238
- context.drawImage(obj.content, x, y, w, h);
3239
- } else if (typeof obj.content === 'string' || typeof obj.content === 'number') {
3240
- if (obj.horizontalAlign) {
3241
- context.textAlign = obj.horizontalAlign;
3161
+ var renderedFlex = resolveCellFlexLayout(context, cellContent, innerX, innerY, innerWidth, innerHeight);
3162
+ var renderedAbsolute = resolveCellAbsoluteLayout(cellContent, innerX, innerY, innerWidth, innerHeight);
3163
+ var rendered = [].concat(renderedFlex, renderedAbsolute);
3164
+ clipToBox(context, xCoord, yCoord, cellWidth, cellHeight, function () {
3165
+ var _loop = function _loop() {
3166
+ var _step12$value = _step12.value,
3167
+ i = _step12$value[0],
3168
+ render = _step12$value[1];
3169
+ var box = render.box,
3170
+ item = render.item;
3171
+ var _box$ = box[0],
3172
+ left = _box$[0],
3173
+ top = _box$[1],
3174
+ _box$2 = box[1],
3175
+ right = _box$2[0],
3176
+ bottom = _box$2[1];
3177
+ var width = right - left;
3178
+ var height = bottom - top;
3179
+ if (cellContent.inspect) {
3180
+ context.lineWidth = 1;
3181
+ context.strokeStyle = '#ff00ff';
3182
+ context.strokeRect(left + 0.5, top + 0.5, width - 0.5, height - 0.5);
3242
3183
  }
3243
-
3244
- var _finalX = applyAlignment(xCoord, cellWidth, style, 0, obj.horizontalAlign);
3245
-
3246
- var _text = '' + obj.content;
3247
-
3248
- var left = _finalX + obj.x;
3249
- var top = yy + obj.y;
3250
- context.fillText(_text, left, top);
3251
- var measure = context.measureText(_text);
3252
- x = left - measure.actualBoundingBoxLeft;
3253
- y = top - measure.actualBoundingBoxAscent;
3254
- w = left + measure.actualBoundingBoxRight - x;
3255
- h = top + measure.actualBoundingBoxDescent - y;
3256
- }
3257
-
3258
- if (obj.onClick) {
3259
- clickables.push({
3260
- rect: [[x, y], [x + w, y + h]],
3261
- obj: obj
3184
+ var clipLeft = i > 0 ? left : xCoord;
3185
+ var clipRight = i < rendered.length ? right : yCoord + cellWidth;
3186
+ var clipWidth = clipRight - clipLeft;
3187
+ clipToBox(context, clipLeft, yCoord, clipWidth, cellHeight, function () {
3188
+ if (item.display === 'inline') {
3189
+ var text = item.text;
3190
+ if (text != null) {
3191
+ wrapText(context, text, style, item.textAlign, left, roundDpi(top + lineHeight / 2), width, height, fillText);
3192
+ }
3193
+ }
3194
+ if (item.display === 'image' || item.display === 'icon') {
3195
+ imageRenderer(context, item, style, box);
3196
+ }
3262
3197
  });
3198
+ };
3199
+ for (var _iterator12 = _createForOfIteratorHelperLoose(rendered.entries()), _step12; !(_step12 = _iterator12()).done;) {
3200
+ _loop();
3263
3201
  }
3264
- }
3202
+ });
3203
+ return rendered.filter(function (_ref) {
3204
+ var item = _ref.item;
3205
+ return item === null || item === void 0 ? void 0 : item.onClick;
3206
+ });
3265
3207
  }
3266
-
3208
+ return null;
3209
+ };
3210
+ var clipToBox = function clipToBox(context, xCoord, yCoord, cellWidth, cellHeight, callback) {
3211
+ context.save();
3212
+ context.beginPath();
3213
+ context.rect(xCoord, yCoord, cellWidth, cellHeight);
3214
+ context.clip();
3215
+ callback();
3267
3216
  context.restore();
3268
- return clickables;
3269
3217
  };
3270
-
3271
3218
  var resolveSelection = function resolveSelection(selection, cellLayout) {
3272
3219
  var cellToPixel = cellLayout.cellToPixel;
3273
3220
  var rowSelectionActive = isRowSelection(selection);
3274
3221
  var columnSelectionActive = isColumnSelection(selection);
3275
-
3276
3222
  var _normalizeSelection3 = normalizeSelection(selection),
3277
- min = _normalizeSelection3[0],
3278
- max = _normalizeSelection3[1];
3279
-
3223
+ min = _normalizeSelection3[0],
3224
+ max = _normalizeSelection3[1];
3280
3225
  var _cellToPixel = cellToPixel(min),
3281
- left = _cellToPixel[0],
3282
- top = _cellToPixel[1];
3283
-
3226
+ left = _cellToPixel[0],
3227
+ top = _cellToPixel[1];
3284
3228
  var _cellToPixel2 = cellToPixel(max, ONE_ONE),
3285
- right = _cellToPixel2[0],
3286
- bottom = _cellToPixel2[1];
3287
-
3229
+ right = _cellToPixel2[0],
3230
+ bottom = _cellToPixel2[1];
3288
3231
  if (rowSelectionActive) {
3289
3232
  right = 1e5;
3290
3233
  }
3291
-
3292
3234
  if (columnSelectionActive) {
3293
3235
  bottom = 1e5;
3294
3236
  }
3295
-
3296
3237
  return [[left, top], [right, bottom]];
3297
3238
  };
3298
-
3299
- var resolveFrozenSelection = function resolveFrozenSelection(selection, cellLayout, freeze, indent, offset) {
3239
+ var resolveFrozenSelection = function resolveFrozenSelection(selection, cellLayout, freeze, offset) {
3300
3240
  var cellToPixel = cellLayout.cellToPixel,
3301
- columnToAbsolute = cellLayout.columnToAbsolute,
3302
- rowToAbsolute = cellLayout.rowToAbsolute;
3241
+ columnToAbsolute = cellLayout.columnToAbsolute,
3242
+ rowToAbsolute = cellLayout.rowToAbsolute;
3303
3243
  var rowSelectionActive = isRowSelection(selection);
3304
3244
  var columnSelectionActive = isColumnSelection(selection);
3305
3245
  var freezeX = freeze[0],
3306
- freezeY = freeze[1];
3307
- var indentX = indent[0],
3308
- indentY = indent[1];
3246
+ freezeY = freeze[1];
3309
3247
  var offsetX = offset[0],
3310
- offsetY = offset[1];
3311
-
3248
+ offsetY = offset[1];
3312
3249
  var _normalizeSelection4 = normalizeSelection(selection),
3313
- min = _normalizeSelection4[0],
3314
- max = _normalizeSelection4[1];
3315
-
3250
+ min = _normalizeSelection4[0],
3251
+ max = _normalizeSelection4[1];
3316
3252
  var minX = min[0],
3317
- minY = min[1];
3253
+ minY = min[1];
3318
3254
  var maxX = max[0],
3319
- maxY = max[1];
3320
-
3255
+ maxY = max[1];
3321
3256
  var _cellToPixel3 = cellToPixel(min),
3322
- left = _cellToPixel3[0],
3323
- top = _cellToPixel3[1];
3324
-
3257
+ left = _cellToPixel3[0],
3258
+ top = _cellToPixel3[1];
3325
3259
  var _cellToPixel4 = cellToPixel(max, ONE_ONE),
3326
- right = _cellToPixel4[0],
3327
- bottom = _cellToPixel4[1];
3328
-
3260
+ right = _cellToPixel4[0],
3261
+ bottom = _cellToPixel4[1];
3262
+ var indentX = columnToAbsolute(0);
3263
+ var indentY = rowToAbsolute(0);
3329
3264
  var frozenX = columnToAbsolute(freezeX);
3330
3265
  var frozenY = rowToAbsolute(freezeY);
3331
3266
  var hideKnob = false;
3332
-
3333
3267
  if (isInRangeCenter(freezeX, minX, maxX + 1)) {
3334
- var edge = indentX + frozenX;
3335
-
3268
+ var edge = frozenX;
3336
3269
  if (right <= edge) {
3337
3270
  right = edge;
3338
3271
  hideKnob = true;
3339
3272
  }
3340
3273
  }
3341
-
3342
3274
  if (isInRangeCenter(freezeY, minY, maxY + 1)) {
3343
- var _edge = indentY + frozenY;
3344
-
3275
+ var _edge = frozenY;
3345
3276
  if (bottom <= _edge) {
3346
3277
  bottom = _edge;
3347
3278
  hideKnob = true;
3348
3279
  }
3349
3280
  }
3350
-
3351
3281
  if (isInRangeLeft(minX, freezeX, offsetX + freezeX)) {
3352
3282
  left = -1e5;
3353
3283
  var lastInvisibleX = offsetX + freezeX - 1;
3354
-
3355
3284
  if (maxX <= lastInvisibleX) {
3356
3285
  if (maxX === lastInvisibleX) right = indentX;else right = -1e5;
3357
3286
  hideKnob = true;
3358
3287
  }
3359
3288
  }
3360
-
3361
3289
  if (isInRangeLeft(minY, freezeY, offsetY + freezeY)) {
3362
3290
  top = -1e5;
3363
3291
  var lastInvisibleY = offsetY + freezeY - 1;
3364
-
3365
3292
  if (maxY <= lastInvisibleY) {
3366
3293
  if (maxY === lastInvisibleY) bottom = indentY;else bottom = -1e5;
3367
3294
  hideKnob = true;
3368
3295
  }
3369
3296
  }
3370
-
3371
3297
  if (rowSelectionActive && offsetX > 0) {
3372
3298
  hideKnob = true;
3373
3299
  }
3374
-
3375
3300
  if (columnSelectionActive && offsetY > 0) {
3376
3301
  hideKnob = true;
3377
3302
  }
3378
-
3379
3303
  if (rowSelectionActive) {
3380
3304
  right = 1e5;
3381
3305
  }
3382
-
3383
3306
  if (columnSelectionActive) {
3384
3307
  bottom = 1e5;
3385
3308
  }
3386
-
3387
3309
  return [[[left, top], [right, bottom]], hideKnob];
3388
3310
  };
3389
-
3390
3311
  var resizeCanvas = function resizeCanvas(canvas) {
3391
3312
  var _canvas$getBoundingCl = canvas.getBoundingClientRect(),
3392
- width = _canvas$getBoundingCl.width,
3393
- height = _canvas$getBoundingCl.height;
3394
-
3313
+ width = _canvas$getBoundingCl.width,
3314
+ height = _canvas$getBoundingCl.height;
3395
3315
  var _window = window,
3396
- _window$devicePixelRa = _window.devicePixelRatio,
3397
- ratio = _window$devicePixelRa === void 0 ? 1 : _window$devicePixelRa;
3398
-
3316
+ _window$devicePixelRa = _window.devicePixelRatio,
3317
+ ratio = _window$devicePixelRa === void 0 ? 1 : _window$devicePixelRa;
3399
3318
  if (ratio < 1) {
3400
3319
  ratio = 1;
3401
3320
  }
3402
-
3403
3321
  var newCanvasWidth = Math.round(width * ratio);
3404
3322
  var newCanvasHeight = Math.round(height * ratio);
3405
-
3406
3323
  if (canvas.width !== newCanvasWidth || canvas.height !== newCanvasHeight) {
3407
3324
  var context = canvas.getContext('2d');
3408
-
3409
3325
  if (context) {
3410
3326
  canvas.width = newCanvasWidth;
3411
3327
  canvas.height = newCanvasHeight;
3412
3328
  context.scale(ratio, ratio);
3413
3329
  }
3414
3330
  }
3415
-
3416
- return ratio;
3417
3331
  };
3418
-
3419
3332
  var excelHeaderString = function excelHeaderString(num) {
3420
3333
  var s = '';
3421
3334
  var t = 0;
3422
-
3423
3335
  while (num > 0) {
3424
3336
  t = (num - 1) % 26;
3425
3337
  s = String.fromCharCode(65 + t) + s;
3426
3338
  num = (num - t) / 26 | 0;
3427
3339
  }
3428
-
3429
3340
  return s || '';
3430
3341
  };
3431
-
3432
3342
  var halfShadowGradient = function halfShadowGradient(gradient, rgb, opacity) {
3433
3343
  var hex = function hex(x) {
3434
3344
  return ('0' + Math.round(x).toString(16)).slice(-2);
3435
3345
  };
3436
-
3437
3346
  var ease = function ease(x) {
3438
3347
  return 1.0 - Math.sin(x * Math.PI / 2);
3439
3348
  };
3440
-
3441
3349
  var adjust = function adjust(x) {
3442
3350
  return 1.0 - Math.pow(1.0 - x, 2.2);
3443
3351
  };
3444
-
3445
3352
  for (var i = 0; i <= 16; ++i) {
3446
3353
  var f = i / 16;
3447
3354
  gradient.addColorStop(f, rgb + hex(adjust(opacity * ease(f) * 0.5) * 255));
3448
3355
  }
3449
3356
  };
3357
+ var getDpiNudge = function getDpiNudge() {
3358
+ var _window2 = window,
3359
+ devicePixelRatio = _window2.devicePixelRatio;
3360
+ return (devicePixelRatio - 1) / devicePixelRatio;
3361
+ };
3362
+ var roundDpi = function roundDpi(y) {
3363
+ var _window3 = window,
3364
+ devicePixelRatio = _window3.devicePixelRatio;
3365
+ return Math.round((y + getDpiNudge()) * devicePixelRatio) / devicePixelRatio;
3366
+ };
3367
+
3368
+ var resolveSheetStyle = function resolveSheetStyle(sheetStyle) {
3369
+ var _sheetStyle$shadowBlu, _sheetStyle$shadowOpa, _sheetStyle$shadowCol;
3370
+ return {
3371
+ freezeColumns: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.freezeColumns) || 0,
3372
+ freezeRows: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.freezeRows) || 0,
3373
+ hideColumnHeaders: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.hideColumnHeaders) || false,
3374
+ hideRowHeaders: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.hideRowHeaders) || false,
3375
+ hideGridlines: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.hideGridlines) || false,
3376
+ hideScrollBars: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.hideScrollBars) || false,
3377
+ shadowBlur: (_sheetStyle$shadowBlu = sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.shadowBlur) != null ? _sheetStyle$shadowBlu : SIZES.shadowBlur,
3378
+ shadowOpacity: (_sheetStyle$shadowOpa = sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.shadowOpacity) != null ? _sheetStyle$shadowOpa : SIZES.shadowOpacity,
3379
+ shadowColor: (_sheetStyle$shadowCol = sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.shadowColor) != null ? _sheetStyle$shadowCol : COLORS.shadowColor
3380
+ };
3381
+ };
3450
3382
 
3451
3383
  var Sheet = forwardRef(function (props, ref) {
3452
3384
  var _props$selection, _props$secondarySelec, _props$cacheLayout, _props$inputComponent;
3453
-
3454
3385
  var canvasRef = useRef(null);
3455
3386
  var overlayRef = useRef(null);
3456
-
3457
3387
  var _useState = useState(INITIAL_MAX_SCROLL),
3458
- maxScroll = _useState[0],
3459
- setMaxScroll = _useState[1];
3460
-
3388
+ maxScroll = _useState[0],
3389
+ setMaxScroll = _useState[1];
3461
3390
  var _useState2 = useState(ORIGIN),
3462
- dataOffset = _useState2[0],
3463
- setDataOffset = _useState2[1];
3464
-
3391
+ dataOffset = _useState2[0],
3392
+ setDataOffset = _useState2[1];
3465
3393
  var selectionProp = (_props$selection = props.selection) != null ? _props$selection : NO_SELECTION;
3466
-
3467
3394
  var _useState3 = useState(selectionProp),
3468
- rawSelection = _useState3[0],
3469
- setRawSelection = _useState3[1];
3470
-
3395
+ rawSelection = _useState3[0],
3396
+ setRawSelection = _useState3[1];
3471
3397
  var _useState4 = useState(null),
3472
- knobArea = _useState4[0],
3473
- setKnobArea = _useState4[1];
3474
-
3398
+ knobArea = _useState4[0],
3399
+ setKnobArea = _useState4[1];
3475
3400
  var _useState5 = useState(null),
3476
- dragOffset = _useState5[0],
3477
- setDragOffset = _useState5[1];
3478
-
3401
+ dragOffset = _useState5[0],
3402
+ setDragOffset = _useState5[1];
3479
3403
  var _useState6 = useState([null, null]),
3480
- dragIndices = _useState6[0],
3481
- setDragIndices = _useState6[1];
3482
-
3404
+ dragIndices = _useState6[0],
3405
+ setDragIndices = _useState6[1];
3483
3406
  var _useState7 = useState(null),
3484
- dropTarget = _useState7[0],
3485
- setDropTarget = _useState7[1];
3486
-
3407
+ dropTarget = _useState7[0],
3408
+ setDropTarget = _useState7[1];
3487
3409
  var _useState8 = useState(NO_CELL),
3488
- editCell = _useState8[0],
3489
- setEditCell = _useState8[1];
3490
-
3410
+ editCell = _useState8[0],
3411
+ setEditCell = _useState8[1];
3491
3412
  var _useState9 = useState(!!props.autoFocus),
3492
- focused = _useState9[0],
3493
- setFocused = _useState9[1];
3494
-
3413
+ focused = _useState9[0],
3414
+ setFocused = _useState9[1];
3495
3415
  var _useState10 = useState(selectionProp),
3496
- lastSelectionProp = _useState10[0],
3497
- setLastSelectionProp = _useState10[1];
3498
-
3416
+ lastSelectionProp = _useState10[0],
3417
+ setLastSelectionProp = _useState10[1];
3499
3418
  if (lastSelectionProp !== selectionProp) {
3500
3419
  setLastSelectionProp(selectionProp);
3501
3420
  setRawSelection(selectionProp);
3502
3421
  }
3503
-
3504
3422
  var _useState11 = useState(''),
3505
- editValue = _useState11[0],
3506
- setEditValue = _useState11[1];
3507
-
3423
+ editValue = _useState11[0],
3424
+ setEditValue = _useState11[1];
3508
3425
  var _useState12 = useState(false),
3509
- arrowKeyCommitMode = _useState12[0],
3510
- setArrowKeyCommitMode = _useState12[1];
3511
-
3426
+ arrowKeyCommitMode = _useState12[0],
3427
+ setArrowKeyCommitMode = _useState12[1];
3512
3428
  var _useResizeObserver = useResizeObserver({
3513
- ref: overlayRef
3514
- }),
3515
- _useResizeObserver$wi = _useResizeObserver.width,
3516
- canvasWidth = _useResizeObserver$wi === void 0 ? 3000 : _useResizeObserver$wi,
3517
- _useResizeObserver$he = _useResizeObserver.height,
3518
- canvasHeight = _useResizeObserver$he === void 0 ? 3000 : _useResizeObserver$he;
3519
-
3429
+ ref: overlayRef
3430
+ }),
3431
+ _useResizeObserver$wi = _useResizeObserver.width,
3432
+ canvasWidth = _useResizeObserver$wi === void 0 ? 3000 : _useResizeObserver$wi,
3433
+ _useResizeObserver$he = _useResizeObserver.height,
3434
+ canvasHeight = _useResizeObserver$he === void 0 ? 3000 : _useResizeObserver$he;
3520
3435
  var cellWidth = useMemo(function () {
3521
3436
  return createRowOrColumnProp(props.cellWidth, 100);
3522
3437
  }, [props.cellWidth]);
@@ -3587,9 +3502,9 @@ var Sheet = forwardRef(function (props, ref) {
3587
3502
  })) : null;
3588
3503
  }, [props.rowGroupKeys, rowGroupKeys, selection]);
3589
3504
  var maxScrollX = maxScroll[0],
3590
- maxScrollY = maxScroll[1];
3505
+ maxScrollY = maxScroll[1];
3591
3506
  var editCellX = editCell[0],
3592
- editCellY = editCell[1];
3507
+ editCellY = editCell[1];
3593
3508
  var editMode = editCellX !== -1 && editCellY !== -1;
3594
3509
  var shouldCacheLayout = ((_props$cacheLayout = props.cacheLayout) != null ? _props$cacheLayout : false) !== false;
3595
3510
  var layoutVersion = typeof props.cacheLayout === 'number' ? props.cacheLayout : 0;
@@ -3605,15 +3520,13 @@ var Sheet = forwardRef(function (props, ref) {
3605
3520
  rowLayout.setSizer(cellHeight);
3606
3521
  }, [shouldCacheLayout, layoutVersion, cellWidth, cellHeight]);
3607
3522
  var freezeColumns = sheetStyle.freezeColumns,
3608
- freezeRows = sheetStyle.freezeRows,
3609
- rowHeaderWidth = sheetStyle.rowHeaderWidth,
3610
- columnHeaderHeight = sheetStyle.columnHeaderHeight;
3523
+ freezeRows = sheetStyle.freezeRows;
3611
3524
  var cellLayout = useMemo(function () {
3612
- return makeCellLayout([freezeColumns, freezeRows], [rowHeaderWidth, columnHeaderHeight], dataOffset, columnLayout, rowLayout);
3613
- }, [freezeColumns, freezeRows, rowHeaderWidth, columnHeaderHeight, dataOffset, columnLayout, rowLayout]);
3525
+ return makeCellLayout([freezeColumns, freezeRows], dataOffset, columnLayout, rowLayout);
3526
+ }, [freezeColumns, freezeRows, dataOffset, columnLayout, rowLayout]);
3614
3527
  var getVisibleCells = cellLayout.getVisibleCells,
3615
- cellToPixel = cellLayout.cellToPixel,
3616
- getVersion = cellLayout.getVersion;
3528
+ cellToPixel = cellLayout.cellToPixel,
3529
+ getVersion = cellLayout.getVersion;
3617
3530
  var visibleCells = useMemo(function () {
3618
3531
  return getVisibleCells([canvasWidth, canvasHeight]);
3619
3532
  }, [getVisibleCells, canvasWidth, canvasHeight, getVersion()]);
@@ -3622,16 +3535,14 @@ var Sheet = forwardRef(function (props, ref) {
3622
3535
  props.onScrollChange([].concat(visibleCells.rows), [].concat(visibleCells.columns));
3623
3536
  }
3624
3537
  }, [visibleCells, props.onScrollChange]);
3625
-
3626
3538
  var scrollToSelection = function scrollToSelection(selection, toHead) {
3627
3539
  if (toHead === void 0) {
3628
3540
  toHead = false;
3629
3541
  }
3630
-
3631
3542
  var overlay = overlayRef.current;
3632
3543
  if (!overlay) return;
3633
3544
  var anchor = selection[0],
3634
- head = selection[1];
3545
+ head = selection[1];
3635
3546
  var view = [canvasWidth, canvasHeight];
3636
3547
  var freeze = [freezeColumns, freezeRows];
3637
3548
  scrollToCell(overlay, toHead ? head : anchor, view, freeze, dataOffset, maxScroll, cellLayout, function (dataOffset, maxScroll) {
@@ -3639,89 +3550,72 @@ var Sheet = forwardRef(function (props, ref) {
3639
3550
  setMaxScroll(maxScroll);
3640
3551
  });
3641
3552
  };
3642
-
3643
3553
  var changeSelection = function changeSelection(newSelection, scrollTo, toHead) {
3644
3554
  if (scrollTo === void 0) {
3645
3555
  scrollTo = true;
3646
3556
  }
3647
-
3648
3557
  if (toHead === void 0) {
3649
3558
  toHead = false;
3650
3559
  }
3651
-
3652
- if (!isSameSelection(selection, newSelection)) {
3560
+ if (!isSameRectangle(selection, newSelection)) {
3653
3561
  setRawSelection(newSelection);
3654
3562
  }
3655
-
3656
3563
  var overlay = overlayRef.current;
3657
3564
  if (!overlay) return;
3658
-
3659
3565
  if (scrollTo) {
3660
3566
  scrollToSelection(newSelection, toHead);
3661
3567
  }
3662
-
3663
3568
  if (props.onSelectionChanged) {
3664
3569
  var _normalizeSelection = normalizeSelection(validateSelection(newSelection)),
3665
- _normalizeSelection$ = _normalizeSelection[0],
3666
- minX = _normalizeSelection$[0],
3667
- minY = _normalizeSelection$[1],
3668
- _normalizeSelection$2 = _normalizeSelection[1],
3669
- maxX = _normalizeSelection$2[0],
3670
- maxY = _normalizeSelection$2[1];
3671
-
3570
+ _normalizeSelection$ = _normalizeSelection[0],
3571
+ minX = _normalizeSelection$[0],
3572
+ minY = _normalizeSelection$[1],
3573
+ _normalizeSelection$2 = _normalizeSelection[1],
3574
+ maxX = _normalizeSelection$2[0],
3575
+ maxY = _normalizeSelection$2[1];
3672
3576
  props.onSelectionChanged(minX, minY, maxX, maxY);
3673
3577
  }
3674
3578
  };
3675
-
3676
3579
  var cancelEditingCell = function cancelEditingCell() {
3677
3580
  setEditCell(NO_CELL);
3678
3581
  setFocused(true);
3679
3582
  };
3680
-
3681
3583
  var commitEditingCell = function commitEditingCell(value) {
3682
3584
  if (props.onChange) {
3683
3585
  var cellX = editCell[0],
3684
- cellY = editCell[1];
3586
+ cellY = editCell[1];
3685
3587
  props.onChange([{
3686
3588
  x: cellX,
3687
3589
  y: cellY,
3688
3590
  value: value !== undefined ? value : editValue
3689
3591
  }]);
3690
3592
  }
3691
-
3692
3593
  setEditCell(NO_CELL);
3693
3594
  setFocused(true);
3694
3595
  };
3695
-
3696
3596
  var startEditingCell = function startEditingCell(editCell, arrowKeyCommitMode) {
3697
3597
  if (arrowKeyCommitMode === void 0) {
3698
3598
  arrowKeyCommitMode = false;
3699
3599
  }
3700
-
3701
3600
  var cellX = editCell[0],
3702
- cellY = editCell[1];
3703
-
3601
+ cellY = editCell[1];
3704
3602
  if (cellReadOnly(cellX, cellY)) {
3705
3603
  return;
3706
3604
  }
3707
-
3708
3605
  var editDataValue = editData(cellX, cellY);
3709
3606
  var val = '';
3710
-
3711
3607
  if (editDataValue !== null && editDataValue !== undefined) {
3712
3608
  val = editDataValue;
3713
3609
  }
3714
-
3715
3610
  setEditCell(editCell);
3716
3611
  setEditValue(val);
3717
3612
  setArrowKeyCommitMode(arrowKeyCommitMode);
3718
3613
  setLastEditKey(editKeys.apply(void 0, editCell));
3719
3614
  };
3720
-
3721
3615
  var _props$maxColumns = props.maxColumns,
3722
- maxColumns = _props$maxColumns === void 0 ? Infinity : _props$maxColumns,
3723
- _props$maxRows = props.maxRows,
3724
- maxRows = _props$maxRows === void 0 ? Infinity : _props$maxRows;
3616
+ maxColumns = _props$maxColumns === void 0 ? Infinity : _props$maxColumns,
3617
+ _props$maxRows = props.maxRows,
3618
+ maxRows = _props$maxRows === void 0 ? Infinity : _props$maxRows;
3725
3619
  useLayoutEffect(function () {
3726
3620
  var overlay = overlayRef.current;
3727
3621
  if (!overlay) return;
@@ -3733,72 +3627,71 @@ var Sheet = forwardRef(function (props, ref) {
3733
3627
  }, [maxRows, maxColumns]);
3734
3628
  var hitmapRef = useRef(NO_CLICKABLES);
3735
3629
  var isFocused = focused || editMode;
3736
-
3737
3630
  var _useClipboardAPI = useClipboardAPI(selection, editData, cellReadOnly, isFocused && !editMode, changeSelection, props.onChange, props.onCopy, props.onPaste),
3738
- clipboardApi = _useClipboardAPI.clipboardApi,
3739
- onClipboardCopy = _useClipboardAPI.onClipboardCopy;
3740
-
3631
+ clipboardApi = _useClipboardAPI.clipboardApi,
3632
+ onClipboardCopy = _useClipboardAPI.onClipboardCopy;
3741
3633
  var onScroll = useScroll(dataOffset, maxScroll, cellLayout, setDataOffset, setMaxScroll);
3742
- var getAutoSizeWidth = useAutoSizeColumn(visibleCells.rows, displayData, cellStyle, columnHeaders, columnHeaderStyle, canvasWidth);
3743
-
3744
- var _useMouse = useMouse(hitmapRef, selection, knobArea, editMode, editData, sourceData, cellReadOnly, canSizeColumn, canSizeRow, canOrderColumn, canOrderRow, cellLayout, visibleCells, sheetStyle, columnGroupKeys, rowGroupKeys, selectedColumnGroups, selectedRowGroups, getAutoSizeWidth, startEditingCell, commitEditingCell, setKnobArea, setDragIndices, setDragOffset, setDropTarget, changeSelection, setFocused, props.cacheLayout ? columnLayout.clearAfter : undefined, props.cacheLayout ? rowLayout.clearAfter : undefined, props.onChange, props.onColumnOrderChange, props.onRowOrderChange, props.onCellWidthChange, props.onCellHeightChange, props.onRightClick, props.dontCommitEditOnSelectionChange, props.dontChangeSelectionOnOrderChange),
3745
- mouseHandlers = _useMouse.mouseHandlers,
3746
- knobPosition = _useMouse.knobPosition;
3747
-
3634
+ var getAutoSizeWidth = useAutoSizeColumn(visibleCells.rows, displayData, cellLayout, cellStyle, columnHeaders, columnHeaderStyle, canvasWidth, freezeColumns);
3635
+ var getAutoSizeHeight = useAutoSizeRow(visibleCells.columns, displayData, cellLayout, cellStyle, columnHeaders, columnHeaderStyle, cellWidth, canvasHeight, freezeRows);
3636
+ var _useMouse = useMouse(hitmapRef, selection, knobArea, editMode, editData, sourceData, cellReadOnly, canSizeColumn, canSizeRow, canOrderColumn, canOrderRow, cellLayout, visibleCells, sheetStyle, columnGroupKeys, rowGroupKeys, selectedColumnGroups, selectedRowGroups, getAutoSizeWidth, getAutoSizeHeight, startEditingCell, commitEditingCell, setKnobArea, setDragIndices, setDragOffset, setDropTarget, changeSelection, setFocused, props.cacheLayout ? columnLayout.clearAfter : undefined, props.cacheLayout ? rowLayout.clearAfter : undefined, props.onChange, props.onColumnOrderChange, props.onRowOrderChange, props.onCellWidthChange, props.onCellHeightChange, props.onRightClick, props.dontCommitEditOnSelectionChange, props.dontChangeSelectionOnOrderChange),
3637
+ mouseHandlers = _useMouse.mouseHandlers,
3638
+ knobPosition = _useMouse.knobPosition;
3748
3639
  var _useKeyboard = useKeyboard(arrowKeyCommitMode, overlayRef, cellReadOnly, displayData, editCell, editMode, focused, rawSelection, selection, startEditingCell, commitEditingCell, cancelEditingCell, changeSelection, setFocused, onClipboardCopy, props.onChange),
3749
- onInputKeyDown = _useKeyboard.onInputKeyDown,
3750
- onGridKeyDown = _useKeyboard.onGridKeyDown,
3751
- onGridFocus = _useKeyboard.onGridFocus,
3752
- onGridBlur = _useKeyboard.onGridBlur;
3753
-
3640
+ onInputKeyDown = _useKeyboard.onInputKeyDown,
3641
+ onGridKeyDown = _useKeyboard.onGridKeyDown,
3642
+ onGridFocus = _useKeyboard.onGridFocus,
3643
+ onGridBlur = _useKeyboard.onGridBlur;
3644
+ var imageRenderer = useImageRenderer();
3754
3645
  useLayoutEffect(function () {
3755
3646
  var canvas = canvasRef.current;
3756
-
3757
3647
  if (!canvas) {
3758
3648
  return;
3759
3649
  }
3760
-
3761
3650
  var context = canvas.getContext('2d');
3762
-
3763
3651
  if (!context) {
3764
3652
  return;
3765
3653
  }
3766
-
3767
3654
  var animationFrameId = window.requestAnimationFrame(function () {
3768
- hitmapRef.current = renderSheet(context, cellLayout, visibleCells, sheetStyle, cellStyle, selection, secondarySelections, isFocused, knobPosition, knobArea, dragIndices, dragOffset, dropTarget, columnHeaders, columnHeaderStyle, displayData, columnGroupKeys, rowGroupKeys, selectedColumnGroups, selectedRowGroups, dataOffset);
3655
+ hitmapRef.current = renderSheet(context, imageRenderer, cellLayout, visibleCells, sheetStyle, cellStyle, selection, secondarySelections, isFocused, knobPosition, knobArea, dragIndices, dragOffset, dropTarget, columnHeaders, columnHeaderStyle, displayData, columnGroupKeys, rowGroupKeys, selectedColumnGroups, selectedRowGroups, dataOffset);
3769
3656
  });
3770
3657
  return function () {
3771
3658
  window.cancelAnimationFrame(animationFrameId);
3772
3659
  };
3773
3660
  }, [cellLayout, visibleCells, sheetStyle, cellStyle, selection, secondarySelections, isFocused, knobPosition, knobArea, dragOffset, dropTarget, columnHeaders, columnHeaderStyle, displayData, columnGroupKeys, rowGroupKeys, selectedColumnGroups, selectedRowGroups, dataOffset]);
3774
-
3775
3661
  var _useState13 = useState(''),
3776
- lastEditKey = _useState13[0],
3777
- setLastEditKey = _useState13[1];
3778
-
3662
+ lastEditKey = _useState13[0],
3663
+ setLastEditKey = _useState13[1];
3779
3664
  var editTextPosition = ORIGIN;
3780
3665
  var editTextWidth = 0;
3781
3666
  var editTextHeight = 0;
3782
- var editTextTextAlign = 'right';
3783
-
3667
+ var editTextAlign = 'right';
3668
+ var editTextLineHeight = '';
3669
+ var editTextMargin = '';
3670
+ var editTextFontSize = DEFAULT_CELL_STYLE.fontSize;
3671
+ var editTextFontFamily = DEFAULT_CELL_STYLE.fontFamily;
3672
+ var editTextFontWeight = DEFAULT_CELL_STYLE.fontWeight;
3784
3673
  if (editMode) {
3785
- var style = cellStyle.apply(void 0, editCell);
3674
+ var style = _extends({}, DEFAULT_CELL_STYLE, cellStyle.apply(void 0, editCell));
3786
3675
  editTextPosition = cellToPixel(editCell);
3787
3676
  editTextPosition = addXY(editTextPosition, ONE_ONE);
3788
3677
  editTextWidth = cellWidth(editCellX) - 3;
3789
3678
  editTextHeight = cellHeight(editCellY) - 3;
3790
- editTextTextAlign = style.textAlign || DEFAULT_CELL_STYLE.textAlign || 'left';
3679
+ editTextAlign = style.textAlign;
3680
+ editTextLineHeight = style.lineHeight + "px";
3681
+ editTextFontSize = style.fontSize;
3682
+ editTextFontFamily = style.fontFamily;
3683
+ editTextFontWeight = style.fontWeight;
3684
+ var yNudge = getDpiNudge();
3685
+ editTextMargin = style.marginTop - 1 + yNudge + "px " + (style.marginRight - 2) + "px " + (style.marginBottom - 2) + "px " + (style.marginLeft - 1) + "px";
3791
3686
  var editKey = editKeys.apply(void 0, editCell);
3792
-
3793
3687
  if (editKey !== lastEditKey) {
3794
3688
  setLastEditKey('');
3795
3689
  setEditCell(NO_CELL);
3796
3690
  }
3797
3691
  }
3798
-
3799
3692
  var _editTextPosition = editTextPosition,
3800
- textX = _editTextPosition[0],
3801
- textY = _editTextPosition[1];
3693
+ textX = _editTextPosition[0],
3694
+ textY = _editTextPosition[1];
3802
3695
  var inputProps = {
3803
3696
  value: editValue,
3804
3697
  autoFocus: true,
@@ -3807,15 +3700,18 @@ var Sheet = forwardRef(function (props, ref) {
3807
3700
  position: 'absolute',
3808
3701
  left: textX,
3809
3702
  top: textY,
3810
- padding: '0px 4px',
3703
+ padding: editTextMargin,
3811
3704
  width: editTextWidth,
3812
3705
  height: editTextHeight,
3813
3706
  outline: 'none',
3814
3707
  border: 'none',
3815
- textAlign: editTextTextAlign,
3708
+ textAlign: editTextAlign,
3709
+ lineHeight: editTextLineHeight,
3816
3710
  color: 'black',
3817
- fontSize: DEFAULT_CELL_STYLE.fontSize,
3818
- fontFamily: 'sans-serif'
3711
+ fontSize: editTextFontSize,
3712
+ fontFamily: editTextFontFamily,
3713
+ fontWeight: editTextFontWeight,
3714
+ resize: 'none'
3819
3715
  }
3820
3716
  };
3821
3717
  var input = (_props$inputComponent = props.inputComponent) === null || _props$inputComponent === void 0 ? void 0 : _props$inputComponent.call(props, editCellX, editCellY, _extends({}, inputProps, {
@@ -3837,16 +3733,13 @@ var Sheet = forwardRef(function (props, ref) {
3837
3733
  height: canvasHeight,
3838
3734
  outline: '1px solid #ddd'
3839
3735
  };
3840
-
3841
3736
  if (sheetStyle.hideScrollBars) {
3842
3737
  delete canvasStyles['outline'];
3843
3738
  delete overlayDivStyles['borderBottom'];
3844
3739
  overlayDivClassName = '';
3845
3740
  }
3846
-
3847
3741
  var renderedInside = useMemo(function () {
3848
3742
  var _props$renderInside;
3849
-
3850
3743
  return (_props$renderInside = props.renderInside) === null || _props$renderInside === void 0 ? void 0 : _props$renderInside.call(props, {
3851
3744
  visibleCells: visibleCells,
3852
3745
  cellLayout: cellLayout,
@@ -3856,7 +3749,6 @@ var Sheet = forwardRef(function (props, ref) {
3856
3749
  }, [props.renderInside, visibleCells, cellLayout, selection, editMode]);
3857
3750
  var renderedOutside = useMemo(function () {
3858
3751
  var _props$renderOutside;
3859
-
3860
3752
  return (_props$renderOutside = props.renderOutside) === null || _props$renderOutside === void 0 ? void 0 : _props$renderOutside.call(props, {
3861
3753
  visibleCells: visibleCells,
3862
3754
  cellLayout: cellLayout,
@@ -3921,8 +3813,7 @@ var Sheet = forwardRef(function (props, ref) {
3921
3813
  height: '100%',
3922
3814
  pointerEvents: 'none'
3923
3815
  }
3924
- }, renderedOutside) : null, editMode && (input !== undefined ? input : React.createElement("input", Object.assign({}, inputProps, {
3925
- type: "text",
3816
+ }, renderedOutside) : null, editMode && (input !== undefined ? input : React.createElement("textarea", Object.assign({}, inputProps, {
3926
3817
  onFocus: function onFocus(e) {
3927
3818
  return e.target.select();
3928
3819
  },
@@ -3933,5 +3824,5 @@ var Sheet = forwardRef(function (props, ref) {
3933
3824
  });
3934
3825
 
3935
3826
  export default Sheet;
3936
- export { useClipboardTable };
3827
+ export { svgToImage, useClipboardTable };
3937
3828
  //# sourceMappingURL=index.modern.js.map