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