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