sheet-happens 0.0.50 → 0.0.51

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