sheet-happens 0.0.50 → 0.0.52

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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 = Math.max(0, pixelToColumn(x, 0.5));
997
+ var cellY = Math.max(0, pixelToRow(y, 0.5));
1013
998
  if (columnDrag) {
1014
999
  var indices = columnDrag.indices;
1015
1000
  var insideSelection = cellX >= minX && cellX <= maxX + 1;
1016
1001
  var insideGroup = selectedColumnGroups === null || selectedColumnGroups === void 0 ? void 0 : selectedColumnGroups.has(columnGroupKeys(x));
1017
-
1018
1002
  if (!insideSelection && !insideGroup) {
1019
1003
  var preceding = indices.filter(function (i) {
1020
1004
  return i < cellX;
@@ -1025,28 +1009,21 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
1025
1009
  onInvalidateColumn === null || onInvalidateColumn === void 0 ? void 0 : onInvalidateColumn(Math.min(minX, order));
1026
1010
  }
1027
1011
  }
1028
-
1029
1012
  if (rowDrag) {
1030
1013
  var _indices4 = rowDrag.indices;
1031
-
1032
1014
  var _insideSelection = cellY >= minY && cellY <= maxY + 1;
1033
-
1034
1015
  var _insideGroup = selectedRowGroups === null || selectedRowGroups === void 0 ? void 0 : selectedRowGroups.has(rowGroupKeys(y));
1035
-
1036
1016
  if (!_insideSelection && !_insideGroup) {
1037
1017
  var _preceding = _indices4.filter(function (i) {
1038
1018
  return i < cellY;
1039
1019
  });
1040
-
1041
1020
  var _order = cellY - _preceding.length;
1042
-
1043
1021
  dontChangeSelectionOnOrderChange || (onSelectionChange === null || onSelectionChange === void 0 ? void 0 : onSelectionChange([[minX, _order], [maxX, _order + _indices4.length - 1]]));
1044
1022
  onRowOrderChange === null || onRowOrderChange === void 0 ? void 0 : onRowOrderChange(_indices4, _order);
1045
1023
  onInvalidateRow === null || onInvalidateRow === void 0 ? void 0 : onInvalidateRow(Math.min(minY, _order));
1046
1024
  }
1047
1025
  }
1048
1026
  }
1049
-
1050
1027
  setDraggingSelection(false);
1051
1028
  setDraggingRowSelection(false);
1052
1029
  setDraggingColumnSelection(false);
@@ -1058,33 +1035,30 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
1058
1035
  }, [getMousePosition, getMouseHit, onChange, onSelectionChange, onKnobAreaChange, onDropTargetChange, onColumnOrderChange, onRowOrderChange, dontChangeSelectionOnOrderChange]);
1059
1036
  var onPointerMove = React.useCallback(function (e) {
1060
1037
  var _ref$current3 = ref.current,
1061
- selection = _ref$current3.selection,
1062
- visibleCells = _ref$current3.visibleCells,
1063
- knobPosition = _ref$current3.knobPosition,
1064
- columnResize = _ref$current3.columnResize,
1065
- columnDrag = _ref$current3.columnDrag,
1066
- rowResize = _ref$current3.rowResize,
1067
- rowDrag = _ref$current3.rowDrag,
1068
- draggingKnob = _ref$current3.draggingKnob,
1069
- draggingSelection = _ref$current3.draggingSelection,
1070
- draggingColumnSelection = _ref$current3.draggingColumnSelection,
1071
- draggingRowSelection = _ref$current3.draggingRowSelection,
1072
- _ref$current3$cellLay = _ref$current3.cellLayout,
1073
- columnToPixel = _ref$current3$cellLay.columnToPixel,
1074
- rowToPixel = _ref$current3$cellLay.rowToPixel,
1075
- pixelToCell = _ref$current3$cellLay.pixelToCell,
1076
- pixelToColumn = _ref$current3$cellLay.pixelToColumn,
1077
- pixelToRow = _ref$current3$cellLay.pixelToRow,
1078
- getIndentX = _ref$current3$cellLay.getIndentX,
1079
- getIndentY = _ref$current3$cellLay.getIndentY;
1038
+ selection = _ref$current3.selection,
1039
+ visibleCells = _ref$current3.visibleCells,
1040
+ knobPosition = _ref$current3.knobPosition,
1041
+ columnResize = _ref$current3.columnResize,
1042
+ columnDrag = _ref$current3.columnDrag,
1043
+ rowResize = _ref$current3.rowResize,
1044
+ rowDrag = _ref$current3.rowDrag,
1045
+ draggingKnob = _ref$current3.draggingKnob,
1046
+ draggingSelection = _ref$current3.draggingSelection,
1047
+ draggingColumnSelection = _ref$current3.draggingColumnSelection,
1048
+ draggingRowSelection = _ref$current3.draggingRowSelection,
1049
+ _ref$current3$cellLay = _ref$current3.cellLayout,
1050
+ columnToPixel = _ref$current3$cellLay.columnToPixel,
1051
+ rowToPixel = _ref$current3$cellLay.rowToPixel,
1052
+ pixelToCell = _ref$current3$cellLay.pixelToCell,
1053
+ pixelToColumn = _ref$current3$cellLay.pixelToColumn,
1054
+ pixelToRow = _ref$current3$cellLay.pixelToRow,
1055
+ getIndentX = _ref$current3$cellLay.getIndentX,
1056
+ getIndentY = _ref$current3$cellLay.getIndentY;
1080
1057
  window.document.body.style.cursor = 'auto';
1081
1058
  var xy = getMousePosition(e);
1082
1059
  if (!xy) return;
1083
1060
  var hitTarget = getMouseHit(xy);
1084
-
1085
- if (hitTarget) {
1086
- window.document.body.style.cursor = 'pointer';
1087
- } else if (columnDrag || rowDrag) {
1061
+ if (columnDrag || rowDrag) {
1088
1062
  window.document.body.style.cursor = 'grabbing';
1089
1063
  } else if (columnResize) {
1090
1064
  window.document.body.style.cursor = 'col-resize';
@@ -1094,37 +1068,31 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
1094
1068
  e.preventDefault();
1095
1069
  } else if (draggingRowSelection || draggingColumnSelection) {
1096
1070
  e.preventDefault();
1071
+ } else if (hitTarget) {
1072
+ window.document.body.style.cursor = 'pointer';
1097
1073
  }
1098
-
1099
1074
  var columns = visibleCells.columns,
1100
- rows = visibleCells.rows;
1075
+ rows = visibleCells.rows;
1101
1076
  var x = xy[0],
1102
- y = xy[1];
1103
-
1077
+ y = xy[1];
1104
1078
  var _normalizeSelection3 = normalizeSelection(selection),
1105
- _normalizeSelection3$ = _normalizeSelection3[0],
1106
- minX = _normalizeSelection3$[0],
1107
- minY = _normalizeSelection3$[1],
1108
- _normalizeSelection3$2 = _normalizeSelection3[1],
1109
- maxX = _normalizeSelection3$2[0],
1110
- maxY = _normalizeSelection3$2[1];
1111
-
1079
+ _normalizeSelection3$ = _normalizeSelection3[0],
1080
+ minX = _normalizeSelection3$[0],
1081
+ minY = _normalizeSelection3$[1],
1082
+ _normalizeSelection3$2 = _normalizeSelection3[1],
1083
+ maxX = _normalizeSelection3$2[0],
1084
+ maxY = _normalizeSelection3$2[1];
1112
1085
  var isDragging = columnResize || columnDrag || rowResize || rowDrag || draggingRowSelection || draggingColumnSelection;
1113
-
1114
1086
  if (!isDragging) {
1115
1087
  if (!hideColumnHeaders && y < getIndentY()) {
1116
1088
  if (onColumnOrderChange) {
1117
1089
  var start = columnToPixel(minX) + SIZES.resizeZone;
1118
1090
  var end = columnToPixel(maxX, 1) - SIZES.resizeZone;
1119
-
1120
1091
  if (isInRange(x, start, end) || selectedColumnGroups) {
1121
- for (var _iterator6 = _createForOfIteratorHelperLoose(columns), _step6; !(_step6 = _iterator6()).done;) {
1122
- var index = _step6.value;
1123
-
1092
+ for (var _iterator4 = _createForOfIteratorHelperLoose(columns), _step4; !(_step4 = _iterator4()).done;) {
1093
+ var index = _step4.value;
1124
1094
  var _start4 = columnToPixel(index);
1125
-
1126
1095
  var _end4 = columnToPixel(index, 1);
1127
-
1128
1096
  if (!draggingColumnSelection && isColumnSelection(selection) && isInRange(x, _start4, _end4) && (isInRange(index, minX, maxX) || selectedColumnGroups !== null && selectedColumnGroups !== void 0 && selectedColumnGroups.has(columnGroupKeys(index))) && canOrderColumn(index)) {
1129
1097
  window.document.body.style.cursor = 'grab';
1130
1098
  return;
@@ -1132,12 +1100,10 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
1132
1100
  }
1133
1101
  }
1134
1102
  }
1135
-
1136
1103
  if (onCellWidthChange) {
1137
- for (var _iterator7 = _createForOfIteratorHelperLoose(columns), _step7; !(_step7 = _iterator7()).done;) {
1138
- var _index4 = _step7.value;
1104
+ for (var _i3 = 0, _arr3 = [-1].concat(columns); _i3 < _arr3.length; _i3++) {
1105
+ var _index4 = _arr3[_i3];
1139
1106
  var edge = columnToPixel(_index4, 1);
1140
-
1141
1107
  if (Math.abs(edge - x) < SIZES.resizeZone && canSizeColumn(_index4)) {
1142
1108
  window.document.body.style.cursor = 'col-resize';
1143
1109
  return;
@@ -1145,21 +1111,15 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
1145
1111
  }
1146
1112
  }
1147
1113
  }
1148
-
1149
1114
  if (!hideRowHeaders && x < getIndentX()) {
1150
1115
  if (onRowOrderChange) {
1151
1116
  var _start5 = rowToPixel(minY) + SIZES.resizeZone;
1152
-
1153
1117
  var _end5 = rowToPixel(maxY, 1) - SIZES.resizeZone;
1154
-
1155
1118
  if (isInRange(y, _start5, _end5) || selectedRowGroups) {
1156
- for (var _iterator8 = _createForOfIteratorHelperLoose(rows), _step8; !(_step8 = _iterator8()).done;) {
1157
- var _index5 = _step8.value;
1158
-
1119
+ for (var _iterator5 = _createForOfIteratorHelperLoose(rows), _step5; !(_step5 = _iterator5()).done;) {
1120
+ var _index5 = _step5.value;
1159
1121
  var _start6 = rowToPixel(_index5);
1160
-
1161
1122
  var _end6 = rowToPixel(_index5, 1);
1162
-
1163
1123
  if (!draggingRowSelection && isRowSelection(selection) && isInRange(y, _start6, _end6) && (isInRange(_index5, minY, maxY) || selectedRowGroups !== null && selectedRowGroups !== void 0 && selectedRowGroups.has(rowGroupKeys(_index5))) && canOrderRow(_index5)) {
1164
1124
  window.document.body.style.cursor = 'grab';
1165
1125
  return;
@@ -1167,13 +1127,10 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
1167
1127
  }
1168
1128
  }
1169
1129
  }
1170
-
1171
1130
  if (onCellHeightChange) {
1172
- for (var _iterator9 = _createForOfIteratorHelperLoose(rows), _step9; !(_step9 = _iterator9()).done;) {
1173
- var _index6 = _step9.value;
1174
-
1131
+ for (var _i4 = 0, _arr4 = [-1].concat(rows); _i4 < _arr4.length; _i4++) {
1132
+ var _index6 = _arr4[_i4];
1175
1133
  var _edge2 = rowToPixel(_index6, 1);
1176
-
1177
1134
  if (Math.abs(_edge2 - y) < SIZES.resizeZone && canSizeRow(_index6)) {
1178
1135
  window.document.body.style.cursor = 'row-resize';
1179
1136
  return;
@@ -1181,66 +1138,54 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
1181
1138
  }
1182
1139
  }
1183
1140
  }
1184
-
1185
1141
  if (knobPosition) {
1186
1142
  var knobX = knobPosition[0],
1187
- knobY = knobPosition[1];
1188
-
1143
+ knobY = knobPosition[1];
1189
1144
  if (Math.abs(x - knobX) < SIZES.knobArea && Math.abs(y - knobY) < SIZES.knobArea) {
1190
1145
  window.document.body.style.cursor = 'crosshair';
1191
1146
  return;
1192
1147
  }
1193
1148
  }
1194
1149
  }
1195
-
1196
1150
  if (columnResize) {
1197
1151
  if (onCellWidthChange) {
1198
1152
  var size = columnResize.size,
1199
- anchor = columnResize.anchor,
1200
- scroll = columnResize.scroll,
1201
- indices = columnResize.indices;
1202
-
1153
+ anchor = columnResize.anchor,
1154
+ scroll = columnResize.scroll,
1155
+ indices = columnResize.indices;
1203
1156
  var _getScrollPosition5 = getScrollPosition(e),
1204
- currentScroll = _getScrollPosition5[0];
1205
-
1157
+ currentScroll = _getScrollPosition5[0];
1206
1158
  var newWidth = Math.round(Math.max(size + x - anchor + scroll - currentScroll, SIZES.minimumWidth * indices.length));
1207
1159
  onInvalidateColumn === null || onInvalidateColumn === void 0 ? void 0 : onInvalidateColumn(indices[0] - 1);
1208
1160
  onCellWidthChange(indices, indices.map(function (_) {
1209
1161
  return Math.round(newWidth / indices.length);
1210
1162
  }));
1211
1163
  }
1212
-
1213
1164
  return;
1214
1165
  }
1215
-
1216
1166
  if (rowResize) {
1217
1167
  if (onCellHeightChange) {
1218
1168
  var _size4 = rowResize.size,
1219
- _anchor = rowResize.anchor,
1220
- _scroll4 = rowResize.scroll,
1221
- _indices5 = rowResize.indices;
1222
-
1169
+ _anchor = rowResize.anchor,
1170
+ _scroll4 = rowResize.scroll,
1171
+ _indices5 = rowResize.indices;
1223
1172
  var _getScrollPosition6 = getScrollPosition(e),
1224
- _currentScroll = _getScrollPosition6[1];
1225
-
1173
+ _currentScroll = _getScrollPosition6[1];
1226
1174
  var newHeight = Math.round(Math.max(_size4 + y - _anchor + _scroll4 - _currentScroll, SIZES.minimumHeight * _indices5.length));
1227
1175
  onInvalidateRow === null || onInvalidateRow === void 0 ? void 0 : onInvalidateRow(_indices5[0] - 1);
1228
1176
  onCellHeightChange(_indices5, _indices5.map(function (_) {
1229
1177
  return newHeight / _indices5.length;
1230
1178
  }));
1231
1179
  }
1232
-
1233
1180
  return;
1234
1181
  }
1235
-
1236
1182
  if (draggingSelection) {
1237
1183
  var _anchor2 = selection[0];
1238
1184
  var head = pixelToCell(xy);
1239
1185
  var anchorX = _anchor2[0],
1240
- anchorY = _anchor2[1];
1186
+ anchorY = _anchor2[1];
1241
1187
  var headX = head[0],
1242
- headY = head[1];
1243
-
1188
+ headY = head[1];
1244
1189
  if (draggingRowSelection) {
1245
1190
  onSelectionChange === null || onSelectionChange === void 0 ? void 0 : onSelectionChange([[-1, anchorY], [-1, Math.max(0, headY)]], false);
1246
1191
  } else if (draggingColumnSelection) {
@@ -1249,25 +1194,20 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
1249
1194
  onSelectionChange === null || onSelectionChange === void 0 ? void 0 : onSelectionChange([maxXY(_anchor2, ORIGIN), maxXY(head, ORIGIN)], false);
1250
1195
  }
1251
1196
  }
1252
-
1253
1197
  if (draggingKnob) {
1254
1198
  window.document.body.style.cursor = 'crosshair';
1255
-
1256
1199
  var _pixelToCell = pixelToCell(xy),
1257
- cellX = _pixelToCell[0],
1258
- cellY = _pixelToCell[1];
1259
-
1200
+ cellX = _pixelToCell[0],
1201
+ cellY = _pixelToCell[1];
1260
1202
  var _normalizeSelection4 = normalizeSelection(selection),
1261
- _normalizeSelection4$ = _normalizeSelection4[0],
1262
- _minX = _normalizeSelection4$[0],
1263
- _minY = _normalizeSelection4$[1],
1264
- _normalizeSelection4$2 = _normalizeSelection4[1],
1265
- _maxX = _normalizeSelection4$2[0],
1266
- _maxY = _normalizeSelection4$2[1];
1267
-
1203
+ _normalizeSelection4$ = _normalizeSelection4[0],
1204
+ _minX = _normalizeSelection4$[0],
1205
+ _minY = _normalizeSelection4$[1],
1206
+ _normalizeSelection4$2 = _normalizeSelection4[1],
1207
+ _maxX = _normalizeSelection4$2[0],
1208
+ _maxY = _normalizeSelection4$2[1];
1268
1209
  var xCellDiff = Math.min(cellX - _minX, _maxX - cellX, 0);
1269
1210
  var yCellDiff = Math.min(cellY - _minY, _maxY - cellY, 0);
1270
-
1271
1211
  if (isMaybeRowSelection(selection) || xCellDiff > yCellDiff) {
1272
1212
  if (cellY < _minY) {
1273
1213
  _minY = cellY;
@@ -1281,156 +1221,152 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
1281
1221
  _maxX = cellX;
1282
1222
  }
1283
1223
  }
1284
-
1285
1224
  onKnobAreaChange === null || onKnobAreaChange === void 0 ? void 0 : onKnobAreaChange([[_minX, _minY], [_maxX, _maxY]]);
1286
1225
  }
1287
-
1288
1226
  if (columnDrag || rowDrag) {
1289
1227
  var _x = xy[0],
1290
- _y = xy[1];
1291
-
1228
+ _y = xy[1];
1292
1229
  if (columnDrag) {
1293
- var _cellX = pixelToColumn(Math.max(_x, getIndentX()), 0.5);
1294
-
1230
+ var _cellX = Math.max(0, pixelToColumn(_x, 0.5));
1295
1231
  var insideSelection = _cellX >= minX && _cellX <= maxX + 1;
1296
1232
  var insideGroup = isBoundaryInsideGroup(_cellX, columnGroupKeys);
1297
1233
  var _anchor3 = columnDrag.anchor,
1298
- _scroll5 = columnDrag.scroll;
1234
+ _scroll5 = columnDrag.scroll;
1299
1235
  var shift = _x - _anchor3;
1300
-
1301
1236
  var _getScrollPosition7 = getScrollPosition(e),
1302
- _currentScroll2 = _getScrollPosition7[0];
1303
-
1237
+ _currentScroll2 = _getScrollPosition7[0];
1304
1238
  onDragOffsetChange === null || onDragOffsetChange === void 0 ? void 0 : onDragOffsetChange([shift + _currentScroll2 - _scroll5, 0]);
1305
1239
  onDropTargetChange === null || onDropTargetChange === void 0 ? void 0 : onDropTargetChange(insideSelection || insideGroup ? null : [[_cellX, -1], [_cellX, -1]]);
1306
1240
  }
1307
-
1308
1241
  if (rowDrag) {
1309
- var _cellY = pixelToRow(Math.max(_y, getIndentY()), 0.5);
1310
-
1242
+ var _cellY = Math.max(0, pixelToRow(_y, 0.5));
1311
1243
  var _insideSelection2 = _cellY >= minY && _cellY <= maxY + 1;
1312
-
1313
1244
  var _insideGroup2 = isBoundaryInsideGroup(_cellY, rowGroupKeys);
1314
-
1315
1245
  var _anchor4 = rowDrag.anchor,
1316
- _scroll6 = rowDrag.scroll;
1317
-
1246
+ _scroll6 = rowDrag.scroll;
1318
1247
  var _shift = _y - _anchor4;
1319
-
1320
1248
  var _getScrollPosition8 = getScrollPosition(e),
1321
- _currentScroll3 = _getScrollPosition8[1];
1322
-
1249
+ _currentScroll3 = _getScrollPosition8[1];
1323
1250
  onDragOffsetChange === null || onDragOffsetChange === void 0 ? void 0 : onDragOffsetChange([0, _shift + _currentScroll3 - _scroll6]);
1324
1251
  onDropTargetChange === null || onDropTargetChange === void 0 ? void 0 : onDropTargetChange(_insideSelection2 || _insideGroup2 ? null : [[-1, _cellY], [-1, _cellY]]);
1325
1252
  }
1326
1253
  }
1327
1254
  }, [getMousePosition, getScrollPosition, getMouseHit, onCellWidthChange, onCellHeightChange, onDragIndicesChange, onDragOffsetChange, onDropTargetChange, onSelectionChange, onKnobAreaChange, onInvalidateRow, onInvalidateColumn, columnGroupKeys, rowGroupKeys]);
1328
1255
  var onClick = React.useCallback(function (e) {
1329
- var _getMouseHit;
1330
-
1331
- var hitTarget = ref.current.hitTarget;
1332
- if (!hitTarget) return;
1333
1256
  var xy = getMousePosition(e);
1334
1257
  if (!xy) return;
1335
- setHitTarget(null);
1336
- var previousRect = JSON.stringify(hitTarget.rect);
1337
- var currentRect = JSON.stringify((_getMouseHit = getMouseHit(xy)) === null || _getMouseHit === void 0 ? void 0 : _getMouseHit.rect);
1338
-
1339
- if (previousRect === currentRect) {
1340
- var _obj$onClick;
1341
-
1342
- var obj = hitTarget.obj;
1343
- (_obj$onClick = obj.onClick) === null || _obj$onClick === void 0 ? void 0 : _obj$onClick.call(obj, e);
1258
+ var mouseHit = getMouseHit(xy);
1259
+ if (hitTestDown && mouseHit) {
1260
+ if (isSameRectangle(hitTestDown.box, mouseHit.box)) {
1261
+ var _mouseHit$item, _mouseHit$item$onClic;
1262
+ mouseHit === null || mouseHit === void 0 ? void 0 : (_mouseHit$item = mouseHit.item) === null || _mouseHit$item === void 0 ? void 0 : (_mouseHit$item$onClic = _mouseHit$item.onClick) === null || _mouseHit$item$onClic === void 0 ? void 0 : _mouseHit$item$onClic.call(_mouseHit$item, e);
1263
+ }
1344
1264
  }
1345
- }, [getMousePosition, getMouseHit]);
1265
+ setHitTestDown(null);
1266
+ }, [getMousePosition, getMouseHit, hitTestDown]);
1346
1267
  var onDoubleClick = React.useCallback(function (e) {
1347
1268
  var _ref$current4 = ref.current,
1348
- selection = _ref$current4.selection,
1349
- _ref$current4$cellLay = _ref$current4.cellLayout,
1350
- pixelToCell = _ref$current4$cellLay.pixelToCell,
1351
- columnToPixel = _ref$current4$cellLay.columnToPixel,
1352
- getIndentY = _ref$current4$cellLay.getIndentY;
1269
+ selection = _ref$current4.selection,
1270
+ _ref$current4$cellLay = _ref$current4.cellLayout,
1271
+ pixelToCell = _ref$current4$cellLay.pixelToCell,
1272
+ columnToPixel = _ref$current4$cellLay.columnToPixel,
1273
+ rowToPixel = _ref$current4$cellLay.rowToPixel,
1274
+ getIndentX = _ref$current4$cellLay.getIndentX,
1275
+ getIndentY = _ref$current4$cellLay.getIndentY;
1353
1276
  e.preventDefault();
1354
1277
  if (e.shiftKey) return;
1355
1278
  var xy = getMousePosition(e);
1356
1279
  if (!xy) return;
1357
1280
  var x = xy[0],
1358
- y = xy[1];
1281
+ y = xy[1];
1359
1282
  var indentY = getIndentY();
1360
1283
  var columns = visibleCells.columns;
1361
-
1362
1284
  if (onCellWidthChange && y < indentY) {
1363
1285
  var autosized = [];
1364
-
1365
- for (var _iterator10 = _createForOfIteratorHelperLoose(columns), _step10; !(_step10 = _iterator10()).done;) {
1366
- var index = _step10.value;
1286
+ for (var _iterator6 = _createForOfIteratorHelperLoose(columns), _step6; !(_step6 = _iterator6()).done;) {
1287
+ var index = _step6.value;
1367
1288
  var edge = columnToPixel(index, 1);
1368
-
1369
1289
  if (Math.abs(edge - x) < SIZES.resizeZone && canSizeColumn(index)) {
1370
1290
  var _normalizeSelection5 = normalizeSelection(selection),
1371
- _normalizeSelection5$ = _normalizeSelection5[0],
1372
- minX = _normalizeSelection5$[0],
1373
- _normalizeSelection5$2 = _normalizeSelection5[1],
1374
- maxX = _normalizeSelection5$2[0];
1375
-
1291
+ _normalizeSelection5$ = _normalizeSelection5[0],
1292
+ minX = _normalizeSelection5$[0],
1293
+ _normalizeSelection5$2 = _normalizeSelection5[1],
1294
+ maxX = _normalizeSelection5$2[0];
1376
1295
  var indices = isColumnSelection(selection) && index >= minX && index <= maxX ? mapSelectionColumns(selection)(function (i) {
1377
1296
  return i;
1378
1297
  }) : [index];
1379
1298
  autosized.push.apply(autosized, indices);
1380
1299
  }
1381
1300
  }
1382
-
1383
- for (var _i = 0, _autosized = autosized; _i < _autosized.length; _i++) {
1384
- var column = _autosized[_i];
1301
+ for (var _i5 = 0, _autosized = autosized; _i5 < _autosized.length; _i5++) {
1302
+ var column = _autosized[_i5];
1385
1303
  onInvalidateColumn === null || onInvalidateColumn === void 0 ? void 0 : onInvalidateColumn(column - 1);
1386
1304
  }
1387
-
1388
1305
  onCellWidthChange(autosized, autosized.map(function (column) {
1389
1306
  return getAutoSizeWidth(column);
1390
1307
  }));
1391
1308
  if (autosized.length) return;
1392
1309
  }
1393
-
1310
+ var indentX = getIndentX();
1311
+ var rows = visibleCells.rows;
1312
+ if (onCellHeightChange && x < indentX) {
1313
+ var _autosized2 = [];
1314
+ for (var _i6 = 0, _arr5 = [-1].concat(rows); _i6 < _arr5.length; _i6++) {
1315
+ var _index7 = _arr5[_i6];
1316
+ var _edge3 = _index7 < 0 ? rowToPixel(0) : rowToPixel(_index7, 1);
1317
+ if (Math.abs(_edge3 - y) < SIZES.resizeZone && canSizeRow(_index7)) {
1318
+ var _normalizeSelection6 = normalizeSelection(selection),
1319
+ _normalizeSelection6$ = _normalizeSelection6[0],
1320
+ minY = _normalizeSelection6$[1],
1321
+ _normalizeSelection6$2 = _normalizeSelection6[1],
1322
+ maxY = _normalizeSelection6$2[1];
1323
+ var _indices6 = isRowSelection(selection) && _index7 >= minY && _index7 <= maxY ? mapSelectionRows(selection)(function (i) {
1324
+ return i;
1325
+ }) : [_index7];
1326
+ _autosized2.push.apply(_autosized2, _indices6);
1327
+ }
1328
+ }
1329
+ for (var _i7 = 0, _autosized3 = _autosized2; _i7 < _autosized3.length; _i7++) {
1330
+ var row = _autosized3[_i7];
1331
+ onInvalidateRow === null || onInvalidateRow === void 0 ? void 0 : onInvalidateRow(row - 1);
1332
+ }
1333
+ onCellHeightChange(_autosized2, _autosized2.map(function (row) {
1334
+ return getAutoSizeHeight(row);
1335
+ }));
1336
+ if (_autosized2.length) return;
1337
+ }
1394
1338
  var hitTarget = getMouseHit(xy);
1395
-
1396
1339
  if (hitTarget) {
1397
1340
  window.document.body.style.cursor = 'pointer';
1398
1341
  return;
1399
1342
  }
1400
-
1401
1343
  var editCell = pixelToCell(xy);
1402
1344
  if (editMode) onCommit === null || onCommit === void 0 ? void 0 : onCommit();
1403
1345
  onEdit === null || onEdit === void 0 ? void 0 : onEdit(editCell);
1404
1346
  }, [getMousePosition, getMouseHit, onCommit, onEdit, onInvalidateColumn, onCellWidthChange, getAutoSizeWidth, visibleCells, canSizeColumn]);
1405
1347
  var onContextMenu = React.useCallback(function (e) {
1406
1348
  var _ref$current$cellLayo2 = ref.current.cellLayout,
1407
- pixelToCell = _ref$current$cellLayo2.pixelToCell,
1408
- getIndentX = _ref$current$cellLayo2.getIndentX,
1409
- getIndentY = _ref$current$cellLayo2.getIndentY;
1349
+ pixelToCell = _ref$current$cellLayo2.pixelToCell,
1350
+ getIndentX = _ref$current$cellLayo2.getIndentX,
1351
+ getIndentY = _ref$current$cellLayo2.getIndentY;
1410
1352
  var xy = getMousePosition(e);
1411
1353
  if (!xy) return;
1412
1354
  var x = xy[0],
1413
- y = xy[1];
1414
-
1355
+ y = xy[1];
1415
1356
  if (x <= getIndentX() || y <= getIndentY()) {
1416
1357
  return;
1417
1358
  }
1418
-
1419
1359
  var cell = pixelToCell(xy);
1420
-
1421
1360
  if (!isPointInsideSelection(selection, cell)) {
1422
1361
  onSelectionChange === null || onSelectionChange === void 0 ? void 0 : onSelectionChange([cell, cell]);
1423
1362
  }
1424
-
1425
1363
  onPointerMove(e);
1426
1364
  var cellX = cell[0],
1427
- cellY = cell[1];
1428
-
1365
+ cellY = cell[1];
1429
1366
  var event = _extends({}, e, {
1430
1367
  cellX: cellX,
1431
1368
  cellY: cellY
1432
1369
  });
1433
-
1434
1370
  onRightClick === null || onRightClick === void 0 ? void 0 : onRightClick(event);
1435
1371
  }, [getMousePosition, onSelectionChange, onPointerMove, onRightClick]);
1436
1372
  var mouseHandlers = {
@@ -1447,51 +1383,42 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
1447
1383
  mouseHandlers: mouseHandlers
1448
1384
  };
1449
1385
  };
1450
-
1451
1386
  var parseKnobOperation = function parseKnobOperation(knobArea, selection, sourceData, editData, cellReadOnly) {
1452
- var _normalizeSelection6 = normalizeSelection(knobArea),
1453
- _normalizeSelection6$ = _normalizeSelection6[0],
1454
- kx1 = _normalizeSelection6$[0],
1455
- ky1 = _normalizeSelection6$[1],
1456
- _normalizeSelection6$2 = _normalizeSelection6[1],
1457
- kx2 = _normalizeSelection6$2[0],
1458
- ky2 = _normalizeSelection6$2[1];
1459
-
1460
- var _normalizeSelection7 = normalizeSelection(selection),
1461
- _normalizeSelection7$ = _normalizeSelection7[0],
1462
- sx1 = _normalizeSelection7$[0],
1463
- sy1 = _normalizeSelection7$[1],
1464
- _normalizeSelection7$2 = _normalizeSelection7[1],
1465
- sx2 = _normalizeSelection7$2[0],
1466
- sy2 = _normalizeSelection7$2[1];
1467
-
1387
+ var _normalizeSelection7 = normalizeSelection(knobArea),
1388
+ _normalizeSelection7$ = _normalizeSelection7[0],
1389
+ kx1 = _normalizeSelection7$[0],
1390
+ ky1 = _normalizeSelection7$[1],
1391
+ _normalizeSelection7$2 = _normalizeSelection7[1],
1392
+ kx2 = _normalizeSelection7$2[0],
1393
+ ky2 = _normalizeSelection7$2[1];
1394
+ var _normalizeSelection8 = normalizeSelection(selection),
1395
+ _normalizeSelection8$ = _normalizeSelection8[0],
1396
+ sx1 = _normalizeSelection8$[0],
1397
+ sy1 = _normalizeSelection8$[1],
1398
+ _normalizeSelection8$2 = _normalizeSelection8[1],
1399
+ sx2 = _normalizeSelection8$2[0],
1400
+ sy2 = _normalizeSelection8$2[1];
1468
1401
  var fx1 = kx1;
1469
1402
  var fy1 = ky1;
1470
1403
  var fx2 = kx2;
1471
1404
  var fy2 = ky2;
1472
1405
  var changes = [];
1473
-
1474
1406
  if (fx2 - fx1 === sx2 - sx1) {
1475
1407
  if (fy1 === sy1) {
1476
1408
  fy1 = sy2 + 1;
1477
1409
  } else {
1478
1410
  fy2 = sy1 - 1;
1479
1411
  }
1480
-
1481
1412
  if (fx1 === -1 && fx2 === -1) {
1482
1413
  var _findApproxMaxEditDat = findApproxMaxEditDataIndex(editData),
1483
- maxX = _findApproxMaxEditDat[0];
1484
-
1414
+ maxX = _findApproxMaxEditDat[0];
1485
1415
  fx1 = 0;
1486
1416
  fx2 = maxX;
1487
1417
  }
1488
-
1489
1418
  var srcY = sy1;
1490
-
1491
1419
  for (var y = fy1; y <= fy2; y++) {
1492
1420
  for (var x = fx1; x <= fx2; x++) {
1493
1421
  var value = sourceData(x, srcY);
1494
-
1495
1422
  if (!cellReadOnly(x, y)) {
1496
1423
  changes.push({
1497
1424
  x: x,
@@ -1504,9 +1431,7 @@ var parseKnobOperation = function parseKnobOperation(knobArea, selection, source
1504
1431
  });
1505
1432
  }
1506
1433
  }
1507
-
1508
1434
  srcY = srcY + 1;
1509
-
1510
1435
  if (srcY > sy2) {
1511
1436
  srcY = sy1;
1512
1437
  }
@@ -1517,21 +1442,16 @@ var parseKnobOperation = function parseKnobOperation(knobArea, selection, source
1517
1442
  } else {
1518
1443
  fx2 = sx1 - 1;
1519
1444
  }
1520
-
1521
1445
  if (fy1 === -1 && fy2 === -1) {
1522
1446
  var _findApproxMaxEditDat2 = findApproxMaxEditDataIndex(editData),
1523
- maxY = _findApproxMaxEditDat2[1];
1524
-
1447
+ maxY = _findApproxMaxEditDat2[1];
1525
1448
  fy1 = 0;
1526
1449
  fy2 = maxY;
1527
1450
  }
1528
-
1529
1451
  var srcX = sx1;
1530
-
1531
1452
  for (var _x2 = fx1; _x2 <= fx2; _x2++) {
1532
1453
  for (var _y2 = fy1; _y2 <= fy2; _y2++) {
1533
1454
  var _value = sourceData(srcX, _y2);
1534
-
1535
1455
  if (!cellReadOnly(_x2, _y2)) {
1536
1456
  changes.push({
1537
1457
  x: _x2,
@@ -1544,15 +1464,12 @@ var parseKnobOperation = function parseKnobOperation(knobArea, selection, source
1544
1464
  });
1545
1465
  }
1546
1466
  }
1547
-
1548
1467
  srcX = srcX + 1;
1549
-
1550
1468
  if (srcX > sx2) {
1551
1469
  srcX = sx1;
1552
1470
  }
1553
1471
  }
1554
1472
  }
1555
-
1556
1473
  return changes;
1557
1474
  };
1558
1475
 
@@ -1562,9 +1479,7 @@ var useKeyboard = function useKeyboard(arrowKeyCommitMode, overlayRef, cellReadO
1562
1479
  onCancel === null || onCancel === void 0 ? void 0 : onCancel();
1563
1480
  return;
1564
1481
  }
1565
-
1566
1482
  var direction = e.key === 'Enter' ? 'down' : e.key === 'Tab' ? 'right' : arrowKeyCommitMode ? ARROW_KEYS[e.key] : null;
1567
-
1568
1483
  if (direction) {
1569
1484
  e.preventDefault();
1570
1485
  var step = getDirectionStep(direction);
@@ -1573,48 +1488,39 @@ var useKeyboard = function useKeyboard(arrowKeyCommitMode, overlayRef, cellReadO
1573
1488
  onSelectionChange === null || onSelectionChange === void 0 ? void 0 : onSelectionChange([head, head]);
1574
1489
  }
1575
1490
  };
1576
-
1577
1491
  var onGridKeyDown = function onGridKeyDown(e) {
1578
1492
  if (editMode && arrowKeyCommitMode && e.key in ARROW_KEYS) {
1579
1493
  onCommit === null || onCommit === void 0 ? void 0 : onCommit();
1580
1494
  return;
1581
1495
  }
1582
-
1583
1496
  if ((e.metaKey || e.ctrlKey) && String.fromCharCode(e.which).toLowerCase() === 'v') {
1584
1497
  return;
1585
1498
  }
1586
-
1587
1499
  if ((e.metaKey || e.ctrlKey) && String.fromCharCode(e.which).toLowerCase() === 'c') {
1588
1500
  onClipboardCopy === null || onClipboardCopy === void 0 ? void 0 : onClipboardCopy(false);
1589
1501
  return;
1590
1502
  }
1591
-
1592
1503
  if ((e.metaKey || e.ctrlKey) && String.fromCharCode(e.which).toLowerCase() === 'x') {
1593
1504
  onClipboardCopy === null || onClipboardCopy === void 0 ? void 0 : onClipboardCopy(true);
1594
1505
  return;
1595
1506
  }
1596
-
1597
1507
  if (e.key === 'Backspace' || e.key === 'Delete') {
1598
1508
  var _normalizeSelection = normalizeSelection(selection),
1599
- _normalizeSelection$ = _normalizeSelection[0],
1600
- x1 = _normalizeSelection$[0],
1601
- y1 = _normalizeSelection$[1],
1602
- _normalizeSelection$2 = _normalizeSelection[1],
1603
- x2 = _normalizeSelection$2[0],
1604
- y2 = _normalizeSelection$2[1];
1605
-
1509
+ _normalizeSelection$ = _normalizeSelection[0],
1510
+ x1 = _normalizeSelection$[0],
1511
+ y1 = _normalizeSelection$[1],
1512
+ _normalizeSelection$2 = _normalizeSelection[1],
1513
+ x2 = _normalizeSelection$2[0],
1514
+ y2 = _normalizeSelection$2[1];
1606
1515
  if (isRowSelection(selection)) {
1607
1516
  x1 = 0;
1608
1517
  x2 = MAX_SEARCHABLE_INDEX;
1609
1518
  }
1610
-
1611
1519
  if (isColumnSelection(selection)) {
1612
1520
  y1 = 0;
1613
1521
  y2 = MAX_SEARCHABLE_INDEX;
1614
1522
  }
1615
-
1616
1523
  var changes = [];
1617
-
1618
1524
  for (var y = y1; y <= y2; y++) {
1619
1525
  for (var x = x1; x <= x2; x++) {
1620
1526
  if (!cellReadOnly(x, y)) {
@@ -1626,79 +1532,61 @@ var useKeyboard = function useKeyboard(arrowKeyCommitMode, overlayRef, cellReadO
1626
1532
  }
1627
1533
  }
1628
1534
  }
1629
-
1630
1535
  onChange === null || onChange === void 0 ? void 0 : onChange(changes);
1631
1536
  return;
1632
1537
  }
1633
-
1634
1538
  if (isEmptySelection(selection)) {
1635
1539
  return;
1636
1540
  }
1637
-
1638
1541
  if (e.keyCode >= 48 && e.keyCode <= 57 || e.keyCode >= 96 && e.keyCode <= 105 || e.keyCode >= 65 && e.keyCode <= 90 || e.key === 'Enter' || e.key === '-' || e.key === '.' || e.key === ',') {
1639
1542
  var cell = selection[0];
1640
1543
  var cellX = cell[0],
1641
- cellY = cell[1];
1642
-
1544
+ cellY = cell[1];
1643
1545
  if (cellReadOnly(cellX, cellY)) {
1644
1546
  return;
1645
1547
  }
1646
-
1647
1548
  if (e.key === 'Enter') e.preventDefault();
1648
1549
  onEdit === null || onEdit === void 0 ? void 0 : onEdit(cell, e.key !== 'Enter');
1649
1550
  return;
1650
1551
  }
1651
-
1652
1552
  e.preventDefault();
1653
-
1654
1553
  if (e.key in ARROW_KEYS) {
1655
1554
  var anchor = rawSelection[0],
1656
- head = rawSelection[1];
1555
+ head = rawSelection[1];
1657
1556
  var direction = ARROW_KEYS[e.key];
1658
1557
  var step = getDirectionStep(direction);
1659
1558
  var shift = e.shiftKey;
1660
-
1661
1559
  if (e.metaKey || e.ctrlKey) {
1662
1560
  head = findInDisplayData(displayData, head, direction);
1663
1561
  } else {
1664
1562
  var limit = shift ? isRowSelection(selection) ? [-1, 0] : isColumnSelection(selection) ? [0, -1] : NEG_NEG : ORIGIN;
1665
1563
  head = maxXY(addXY(head, step), limit);
1666
1564
  }
1667
-
1668
1565
  if (!shift) {
1669
1566
  anchor = head;
1670
1567
  }
1671
-
1672
1568
  onSelectionChange === null || onSelectionChange === void 0 ? void 0 : onSelectionChange([anchor, head], true, true);
1673
1569
  return;
1674
1570
  }
1675
1571
  };
1676
-
1677
1572
  var onGridFocus = function onGridFocus() {
1678
1573
  onFocusChange === null || onFocusChange === void 0 ? void 0 : onFocusChange(true);
1679
1574
  };
1680
-
1681
1575
  var onGridBlur = function onGridBlur() {
1682
1576
  onFocusChange === null || onFocusChange === void 0 ? void 0 : onFocusChange(false);
1683
1577
  };
1684
-
1685
1578
  React.useLayoutEffect(function () {
1686
1579
  var overlay = overlayRef.current;
1687
-
1688
1580
  if (!overlay) {
1689
1581
  return;
1690
1582
  }
1691
-
1692
1583
  if (editMode || !focused) {
1693
1584
  return;
1694
1585
  }
1695
-
1696
1586
  if (document.activeElement === overlay) {
1697
1587
  return;
1698
1588
  }
1699
-
1700
1589
  var activeTagName = document.activeElement.tagName.toLowerCase();
1701
-
1702
1590
  if (!(activeTagName === 'div' && document.activeElement.contentEditable === 'true' || activeTagName === 'input' || activeTagName === 'textarea' || activeTagName === 'select')) {
1703
1591
  overlay.focus({
1704
1592
  preventScroll: true
@@ -1718,28 +1606,22 @@ var useScroll = function useScroll(offset, maxScroll, cellLayout, onOffsetChange
1718
1606
  if (!e.target || !(e.target instanceof Element)) {
1719
1607
  return;
1720
1608
  }
1721
-
1722
1609
  var absoluteToCell = cellLayout.absoluteToCell,
1723
- cellToAbsolute = cellLayout.cellToAbsolute;
1724
-
1725
- var _cellToAbsolute = cellToAbsolute([0, 0], [0.5, 0.5]),
1726
- nudgeX = _cellToAbsolute[0],
1727
- nudgeY = _cellToAbsolute[1];
1728
-
1610
+ cellToAbsolute = cellLayout.cellToAbsolute;
1611
+ var _subXY = subXY(cellToAbsolute([0, 0], [0.5, 0.5]), cellToAbsolute([0, 0])),
1612
+ nudgeX = _subXY[0],
1613
+ nudgeY = _subXY[1];
1729
1614
  var xy = [e.target.scrollLeft + nudgeX, e.target.scrollTop + nudgeY];
1730
1615
  var cell = absoluteToCell(xy);
1731
-
1732
1616
  if (!isSameXY(cell, offset)) {
1733
1617
  onOffsetChange === null || onOffsetChange === void 0 ? void 0 : onOffsetChange(cell);
1734
1618
  }
1735
-
1736
1619
  var x = xy[0],
1737
- y = xy[1];
1620
+ y = xy[1];
1738
1621
  var maxScrollX = maxScroll[0],
1739
- maxScrollY = maxScroll[1];
1622
+ maxScrollY = maxScroll[1];
1740
1623
  var growX = maxScrollX < x + 1 ? 1.5 : 1;
1741
1624
  var growY = maxScrollY < y + 1 ? 1.5 : 1;
1742
-
1743
1625
  if (growX > 1 || growY > 1) {
1744
1626
  onMaxScrollChange === null || onMaxScrollChange === void 0 ? void 0 : onMaxScrollChange(mulXY(maxScroll, [growX, growY]));
1745
1627
  }
@@ -1747,52 +1629,43 @@ var useScroll = function useScroll(offset, maxScroll, cellLayout, onOffsetChange
1747
1629
  };
1748
1630
  var clipDataOffset = function clipDataOffset(view, offset, freeze, maxCells, cellLayout) {
1749
1631
  var newX = offset[0],
1750
- newY = offset[1];
1632
+ newY = offset[1];
1751
1633
  var freezeX = freeze[0],
1752
- freezeY = freeze[1];
1634
+ freezeY = freeze[1];
1753
1635
  var maxColumns = maxCells[0],
1754
- maxRows = maxCells[1];
1636
+ maxRows = maxCells[1];
1755
1637
  var absoluteToColumn = cellLayout.absoluteToColumn,
1756
- columnToAbsolute = cellLayout.columnToAbsolute,
1757
- absoluteToRow = cellLayout.absoluteToRow,
1758
- rowToAbsolute = cellLayout.rowToAbsolute;
1759
-
1638
+ columnToAbsolute = cellLayout.columnToAbsolute,
1639
+ absoluteToRow = cellLayout.absoluteToRow,
1640
+ rowToAbsolute = cellLayout.rowToAbsolute;
1760
1641
  var _getViewExtent = getViewExtent(view, [newX, newY], freeze, cellLayout),
1761
- _getViewExtent$edge = _getViewExtent.edge,
1762
- leftEdge = _getViewExtent$edge[0],
1763
- topEdge = _getViewExtent$edge[1],
1764
- _getViewExtent$viewpo = _getViewExtent.viewport,
1765
- scrollW = _getViewExtent$viewpo[0],
1766
- scrollH = _getViewExtent$viewpo[1];
1767
-
1642
+ _getViewExtent$edge = _getViewExtent.edge,
1643
+ leftEdge = _getViewExtent$edge[0],
1644
+ topEdge = _getViewExtent$edge[1],
1645
+ _getViewExtent$viewpo = _getViewExtent.viewport,
1646
+ scrollW = _getViewExtent$viewpo[0],
1647
+ scrollH = _getViewExtent$viewpo[1];
1768
1648
  if (leftEdge >= maxColumns) {
1769
1649
  var remainder = columnToAbsolute(maxColumns) - columnToAbsolute(newX + freezeX);
1770
1650
  newX = Math.max(0, absoluteToColumn(columnToAbsolute(newX + freezeX) - scrollW + remainder) - freezeX + 1);
1771
1651
  }
1772
-
1773
1652
  if (topEdge >= maxRows) {
1774
1653
  var _remainder = rowToAbsolute(maxRows) - rowToAbsolute(newY + freezeY);
1775
-
1776
1654
  newY = Math.max(0, absoluteToRow(rowToAbsolute(newY + freezeY) - scrollH + _remainder) - freezeY + 1);
1777
1655
  }
1778
-
1779
1656
  return [newX, newY];
1780
1657
  };
1781
1658
  var getViewExtent = function getViewExtent(view, offset, freeze, cellLayout) {
1782
- var cellToAbsolute = cellLayout.cellToAbsolute,
1783
- getIndentX = cellLayout.getIndentX,
1784
- getIndentY = cellLayout.getIndentY;
1659
+ var cellToAbsolute = cellLayout.cellToAbsolute;
1785
1660
  var x = offset[0],
1786
- y = offset[1];
1661
+ y = offset[1];
1787
1662
  var w = view[0],
1788
- h = view[1];
1789
-
1790
- var _cellToAbsolute2 = cellToAbsolute(freeze),
1791
- frozenX = _cellToAbsolute2[0],
1792
- frozenY = _cellToAbsolute2[1];
1793
-
1794
- var scrollW = w - frozenX - getIndentX();
1795
- var scrollH = h - frozenY - getIndentY();
1663
+ h = view[1];
1664
+ var _cellToAbsolute = cellToAbsolute(freeze),
1665
+ frozenX = _cellToAbsolute[0],
1666
+ frozenY = _cellToAbsolute[1];
1667
+ var scrollW = w - frozenX;
1668
+ var scrollH = h - frozenY;
1796
1669
  var leftEdge = x + freeze[0];
1797
1670
  var topEdge = y + freeze[1];
1798
1671
  return {
@@ -1802,55 +1675,44 @@ var getViewExtent = function getViewExtent(view, offset, freeze, cellLayout) {
1802
1675
  };
1803
1676
  var scrollToCell = function scrollToCell(element, cell, view, freeze, offset, maxScroll, cellLayout, callback) {
1804
1677
  var x = cell[0],
1805
- y = cell[1];
1678
+ y = cell[1];
1806
1679
  var w = view[0],
1807
- h = view[1];
1680
+ h = view[1];
1808
1681
  var offsetX = offset[0],
1809
- offsetY = offset[1];
1682
+ offsetY = offset[1];
1810
1683
  var cellToAbsolute = cellLayout.cellToAbsolute,
1811
- cellToPixel = cellLayout.cellToPixel,
1812
- columnToPixel = cellLayout.columnToPixel,
1813
- rowToPixel = cellLayout.rowToPixel;
1814
-
1815
- var _cellToAbsolute3 = cellToAbsolute(freeze),
1816
- frozenX = _cellToAbsolute3[0],
1817
- frozenY = _cellToAbsolute3[1];
1818
-
1684
+ cellToPixel = cellLayout.cellToPixel,
1685
+ columnToPixel = cellLayout.columnToPixel,
1686
+ rowToPixel = cellLayout.rowToPixel;
1687
+ var origin = cellToAbsolute([0, 0]);
1688
+ var frozen = cellToAbsolute(freeze);
1689
+ var frozenX = frozen[0],
1690
+ frozenY = frozen[1];
1819
1691
  var _cellToPixel = cellToPixel(cell),
1820
- left = _cellToPixel[0],
1821
- top = _cellToPixel[1];
1822
-
1692
+ left = _cellToPixel[0],
1693
+ top = _cellToPixel[1];
1823
1694
  var _cellToPixel2 = cellToPixel(cell, ONE_ONE),
1824
- right = _cellToPixel2[0],
1825
- bottom = _cellToPixel2[1];
1826
-
1695
+ right = _cellToPixel2[0],
1696
+ bottom = _cellToPixel2[1];
1827
1697
  var newX = offset[0],
1828
- newY = offset[1];
1829
-
1698
+ newY = offset[1];
1830
1699
  if (left <= frozenX) {
1831
1700
  newX = x - freeze[0];
1832
1701
  }
1833
-
1834
1702
  if (top <= frozenY) {
1835
1703
  newY = y - freeze[1];
1836
1704
  }
1837
-
1838
1705
  if (right > w) {
1839
1706
  var edge = right - w + columnToPixel(newX);
1840
-
1841
1707
  while (columnToPixel(++newX) < edge) {}
1842
1708
  }
1843
-
1844
1709
  if (bottom > h) {
1845
1710
  var _edge = bottom - h + rowToPixel(newY);
1846
-
1847
1711
  while (rowToPixel(++newY) < _edge) {}
1848
1712
  }
1849
-
1850
1713
  var newOffset = [newX >= 0 ? newX : offsetX, newY >= 0 ? newY : offsetY];
1851
-
1852
1714
  if (!isSameXY(newOffset, offset)) {
1853
- var scroll = cellToAbsolute(newOffset);
1715
+ var scroll = subXY(cellToAbsolute(newOffset), origin);
1854
1716
  callback(newOffset, maxXY(maxScroll, scroll));
1855
1717
  setTimeout(function () {
1856
1718
  updateScrollPosition(element, newOffset, cellLayout);
@@ -1860,89 +1722,414 @@ var scrollToCell = function scrollToCell(element, cell, view, freeze, offset, ma
1860
1722
  var updateScrollPosition = function updateScrollPosition(element, dataOffset, cellLayout) {
1861
1723
  var cellToAbsolute = cellLayout.cellToAbsolute;
1862
1724
  var scroll = cellToAbsolute(dataOffset);
1863
-
1864
- var _cellToAbsolute4 = cellToAbsolute([0, 0], [0.5, 0.5]),
1865
- nudgeX = _cellToAbsolute4[0],
1866
- nudgeY = _cellToAbsolute4[1];
1867
-
1725
+ var _subXY2 = subXY(cellToAbsolute([0, 0], [0.5, 0.5]), cellToAbsolute([0, 0])),
1726
+ nudgeX = _subXY2[0],
1727
+ nudgeY = _subXY2[1];
1868
1728
  var scrollX = scroll[0],
1869
- scrollY = scroll[1];
1729
+ scrollY = scroll[1];
1870
1730
  element.scrollLeft = scrollX - nudgeX;
1871
1731
  element.scrollTop = scrollY - nudgeY;
1872
1732
  };
1873
1733
 
1874
- var useAutoSizeColumn = function useAutoSizeColumn(rows, displayData, cellStyle, columnHeaders, columnHeaderStyle, canvasWidth) {
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
+
2021
+ var useAutoSizeColumn = function useAutoSizeColumn(rows, displayData, cellLayout, cellStyle, columnHeaders, columnHeaderStyle, canvasWidth, frozenColumns) {
1875
2022
  var context = React.useMemo(function () {
1876
2023
  return document.createElement('canvas').getContext('2d');
1877
2024
  }, []);
1878
2025
  var getAutoSizeWidth = React.useCallback(function (x) {
1879
2026
  if (!context) return 0;
1880
-
2027
+ var viewWidth = canvasWidth - cellLayout.columnToAbsolute(x < frozenColumns ? 0 : frozenColumns);
1881
2028
  var getWidth = function getWidth(cellContent, style) {
1882
- context.font = style.weight + ' ' + style.fontSize + 'px ' + style.fontFamily;
2029
+ context.font = style.fontWeight + ' ' + style.fontSize + 'px ' + style.fontFamily;
1883
2030
  var inlineMargin = style.marginLeft + style.marginRight;
1884
-
1885
2031
  if (typeof cellContent === 'string' || typeof cellContent === 'number') {
1886
2032
  var _context$measureText = context.measureText(cellContent.toString()),
1887
- width = _context$measureText.width;
1888
-
2033
+ width = _context$measureText.width;
1889
2034
  return width + inlineMargin;
1890
2035
  } else if (typeof cellContent === 'object') {
1891
- var _maxWidth = 0;
1892
- var extraWidth = 0;
1893
-
1894
- for (var _iterator = _createForOfIteratorHelperLoose(cellContent.items), _step; !(_step = _iterator()).done;) {
1895
- var obj = _step.value;
1896
- var _width = 0;
1897
-
1898
- if (typeof obj.content === 'string' || typeof obj.content === 'number') {
1899
- var _context$measureText2 = context.measureText(obj.content.toString()),
1900
- w = _context$measureText2.width;
1901
-
1902
- _width = obj.x + w + inlineMargin;
1903
- } else if (obj.width) {
1904
- _width = obj.width;
1905
- }
1906
-
1907
- if (obj.horizontalAlign === 'right') {
1908
- extraWidth += style.textAlign === 'right' ? _width * 2 : _width;
1909
- } else {
1910
- _maxWidth = Math.max(_maxWidth, _width);
2036
+ var totalWidth = inlineMargin;
2037
+ var _cellContent$flexGap = cellContent.flexGap,
2038
+ flexGap = _cellContent$flexGap === void 0 ? 0 : _cellContent$flexGap,
2039
+ items = cellContent.items;
2040
+ for (var _iterator = _createForOfIteratorHelperLoose(items), _step; !(_step = _iterator()).done;) {
2041
+ var item = _step.value;
2042
+ if (item.absolute) continue;
2043
+ if (item.width != null) {
2044
+ totalWidth += item.width;
2045
+ } else if (item.display === 'inline' && item.text != null) {
2046
+ var _context$measureText2 = context.measureText(item.text.toString()),
2047
+ _width = _context$measureText2.width;
2048
+ totalWidth += _width;
1911
2049
  }
2050
+ totalWidth += flexGap;
1912
2051
  }
1913
-
1914
- return _maxWidth + extraWidth;
2052
+ totalWidth -= flexGap;
2053
+ return totalWidth;
1915
2054
  }
1916
-
1917
2055
  return 0;
1918
2056
  };
1919
-
1920
2057
  var maxWidth = SIZES.minimumWidth;
1921
-
1922
2058
  var headerStyle = _extends({}, DEFAULT_COLUMN_HEADER_STYLE, columnHeaderStyle(x));
1923
-
1924
2059
  var headerContent = columnHeaders(x, headerStyle);
1925
-
1926
2060
  if (headerContent) {
1927
2061
  maxWidth = Math.max(maxWidth, getWidth(headerContent, headerStyle));
1928
2062
  }
1929
-
1930
2063
  for (var _iterator2 = _createForOfIteratorHelperLoose(rows), _step2; !(_step2 = _iterator2()).done;) {
1931
2064
  var y = _step2.value;
1932
-
1933
2065
  var style = _extends({}, DEFAULT_CELL_STYLE, cellStyle(x, y));
1934
-
1935
2066
  var cellContent = displayData(x, y, style);
1936
-
1937
2067
  if (cellContent != null) {
1938
2068
  maxWidth = Math.max(maxWidth, getWidth(cellContent, style));
1939
2069
  }
1940
2070
  }
1941
-
1942
- return Math.ceil(Math.min(canvasWidth, maxWidth));
1943
- }, [context, displayData, cellStyle, columnHeaders, columnHeaderStyle]);
2071
+ return Math.ceil(Math.min(viewWidth, maxWidth));
2072
+ }, [context, rows, displayData, cellLayout, cellStyle, columnHeaders, columnHeaderStyle, canvasWidth, frozenColumns]);
1944
2073
  return getAutoSizeWidth;
1945
2074
  };
2075
+ var useAutoSizeRow = function useAutoSizeRow(columns, displayData, cellLayout, cellStyle, columnHeaders, columnHeaderStyle, cellWidth, canvasHeight, frozenRows) {
2076
+ var context = React.useMemo(function () {
2077
+ return document.createElement('canvas').getContext('2d');
2078
+ }, []);
2079
+ var getAutoSizeHeight = React.useCallback(function (y) {
2080
+ if (!context) return 0;
2081
+ var viewHeight = canvasHeight - cellLayout.rowToAbsolute(y < frozenRows ? 0 : frozenRows);
2082
+ var measureTextHeight = function measureTextHeight(text, style, columnWidth) {
2083
+ var maxY = 0;
2084
+ var measureY = function measureY(_t, _x, y) {
2085
+ maxY = y + style.lineHeight;
2086
+ };
2087
+ wrapText(context, text, style, undefined, 0, 0, columnWidth, viewHeight, measureY);
2088
+ return maxY;
2089
+ };
2090
+ var getHeight = function getHeight(cellContent, style, columnWidth) {
2091
+ context.font = style.fontWeight + ' ' + style.fontSize + 'px ' + style.fontFamily;
2092
+ var verticalMargin = style.marginTop + style.marginBottom;
2093
+ if (typeof cellContent === 'string' || typeof cellContent === 'number') {
2094
+ var height = measureTextHeight(cellContent.toString(), style, columnWidth);
2095
+ return height + verticalMargin;
2096
+ } else if (typeof cellContent === 'object') {
2097
+ var _maxHeight = 0;
2098
+ var flexLayout = resolveCellFlexLayout(context, cellContent, 0, 0, columnWidth, 0);
2099
+ for (var _iterator3 = _createForOfIteratorHelperLoose(flexLayout), _step3; !(_step3 = _iterator3()).done;) {
2100
+ var _step3$value = _step3.value,
2101
+ box = _step3$value.box,
2102
+ item = _step3$value.item;
2103
+ if (item.height != null) {
2104
+ _maxHeight = Math.max(_maxHeight, item.height);
2105
+ } else if (item.display === 'inline' && item.text != null) {
2106
+ var _box$ = box[0],
2107
+ left = _box$[0],
2108
+ _box$2 = box[1],
2109
+ right = _box$2[0];
2110
+ var _height = measureTextHeight(item.text.toString(), style, right - left);
2111
+ _maxHeight = Math.max(_maxHeight, _height);
2112
+ }
2113
+ }
2114
+ return _maxHeight + verticalMargin;
2115
+ }
2116
+ return 0;
2117
+ };
2118
+ var isHeader = y === -1;
2119
+ var maxHeight = SIZES.minimumHeight;
2120
+ for (var _iterator4 = _createForOfIteratorHelperLoose(columns), _step4; !(_step4 = _iterator4()).done;) {
2121
+ var x = _step4.value;
2122
+ var style = isHeader ? _extends({}, DEFAULT_COLUMN_HEADER_STYLE, columnHeaderStyle(x)) : _extends({}, DEFAULT_CELL_STYLE, cellStyle(x, y));
2123
+ var cellContent = isHeader ? columnHeaders(x, style) : displayData(x, y, style);
2124
+ if (cellContent != null) {
2125
+ var columnWidth = cellWidth(x) - style.marginLeft - style.marginRight;
2126
+ maxHeight = Math.max(maxHeight, getHeight(cellContent, style, columnWidth));
2127
+ }
2128
+ }
2129
+ return Math.ceil(Math.min(viewHeight, maxHeight));
2130
+ }, [context, columns, displayData, cellLayout, cellStyle, columnHeaders, columnHeaderStyle, cellWidth, canvasHeight, frozenRows]);
2131
+ return getAutoSizeHeight;
2132
+ };
1946
2133
 
1947
2134
  // A type of promise-like that resolves synchronously and supports only one observer
1948
2135
 
@@ -1968,9 +2155,8 @@ var EMPTY_TABLE = {
1968
2155
  };
1969
2156
  var useClipboardTable = function useClipboardTable() {
1970
2157
  var _useState = React.useState(),
1971
- peek = _useState[0],
1972
- setPeek = _useState[1];
1973
-
2158
+ peek = _useState[0],
2159
+ setPeek = _useState[1];
1974
2160
  React.useLayoutEffect(function () {
1975
2161
  var softRefresh = function softRefresh() {
1976
2162
  return Promise.resolve(_catch(function () {
@@ -1982,13 +2168,11 @@ var useClipboardTable = function useClipboardTable() {
1982
2168
  });
1983
2169
  }, function () {}));
1984
2170
  };
1985
-
1986
2171
  var hardRefresh = function hardRefresh() {
1987
2172
  try {
1988
- var _temp3 = _catch(function () {
2173
+ var _temp2 = _catch(function () {
1989
2174
  return Promise.resolve(navigator.clipboard.read()).then(function (items) {
1990
2175
  var item = items[0];
1991
-
1992
2176
  var _temp = function () {
1993
2177
  if (item) {
1994
2178
  return Promise.resolve(parseClipboardTable(item)).then(function (peek) {
@@ -1998,21 +2182,17 @@ var useClipboardTable = function useClipboardTable() {
1998
2182
  setPeek(EMPTY_TABLE);
1999
2183
  }
2000
2184
  }();
2001
-
2002
2185
  if (_temp && _temp.then) return _temp.then(function () {});
2003
2186
  });
2004
2187
  }, function () {});
2005
-
2006
- return Promise.resolve(_temp3 && _temp3.then ? _temp3.then(function () {}) : void 0);
2188
+ return Promise.resolve(_temp2 && _temp2.then ? _temp2.then(function () {}) : void 0);
2007
2189
  } catch (e) {
2008
2190
  return Promise.reject(e);
2009
2191
  }
2010
2192
  };
2011
-
2012
2193
  var delayedRefresh = function delayedRefresh() {
2013
2194
  return setTimeout(hardRefresh);
2014
2195
  };
2015
-
2016
2196
  window.document.addEventListener('cut', delayedRefresh);
2017
2197
  window.document.addEventListener('copy', delayedRefresh);
2018
2198
  window.document.addEventListener('focus', softRefresh);
@@ -2025,7 +2205,6 @@ var useClipboardTable = function useClipboardTable() {
2025
2205
  }, []);
2026
2206
  var canPaste = React.useCallback(function () {
2027
2207
  var _peek$rows;
2028
-
2029
2208
  return !!(peek == null || (_peek$rows = peek.rows) !== null && _peek$rows !== void 0 && _peek$rows.length);
2030
2209
  }, [peek]);
2031
2210
  return {
@@ -2037,20 +2216,17 @@ var useClipboardTable = function useClipboardTable() {
2037
2216
  };
2038
2217
  var useClipboardAPI = function useClipboardAPI(selection, editData, cellReadOnly, addListener, onSelectionChange, onChange, onCopy, onPaste) {
2039
2218
  var _useClipboardTable = useClipboardTable(),
2040
- canPaste = _useClipboardTable.canPaste,
2041
- copyTable = _useClipboardTable.copyTable,
2042
- pasteTable = _useClipboardTable.pasteTable;
2043
-
2219
+ canPaste = _useClipboardTable.canPaste,
2220
+ copyTable = _useClipboardTable.copyTable,
2221
+ pasteTable = _useClipboardTable.pasteTable;
2044
2222
  var pasteIntoSelection = React.useCallback(function (selection, table) {
2045
2223
  try {
2046
2224
  var rows = table.rows,
2047
- payload = table.payload;
2048
-
2225
+ payload = table.payload;
2049
2226
  var _normalizeSelection = normalizeSelection(selection),
2050
- min = _normalizeSelection[0];
2051
-
2227
+ min = _normalizeSelection[0];
2052
2228
  var minX = min[0],
2053
- minY = min[1];
2229
+ minY = min[1];
2054
2230
  var left = Math.max(0, minX);
2055
2231
  var top = Math.max(0, minY);
2056
2232
  var width = rows.reduce(function (a, b) {
@@ -2085,14 +2261,11 @@ var useClipboardAPI = function useClipboardAPI(selection, editData, cellReadOnly
2085
2261
  if (cut === void 0) {
2086
2262
  cut = false;
2087
2263
  }
2088
-
2089
2264
  try {
2090
2265
  var _payload$cut;
2091
-
2092
2266
  var rows = formatSelectionAsRows(selection, editData);
2093
2267
  var payload = onCopy === null || onCopy === void 0 ? void 0 : onCopy(selection, rows, cut);
2094
2268
  copyTable(rows, payload);
2095
-
2096
2269
  if ((_payload$cut = payload === null || payload === void 0 ? void 0 : payload.cut) != null ? _payload$cut : cut) {
2097
2270
  var changes = [];
2098
2271
  forSelectionRows(selection)(function (y) {
@@ -2109,7 +2282,6 @@ var useClipboardAPI = function useClipboardAPI(selection, editData, cellReadOnly
2109
2282
  });
2110
2283
  onChange === null || onChange === void 0 ? void 0 : onChange(changes);
2111
2284
  }
2112
-
2113
2285
  return Promise.resolve();
2114
2286
  } catch (e) {
2115
2287
  return Promise.reject(e);
@@ -2124,12 +2296,10 @@ var useClipboardAPI = function useClipboardAPI(selection, editData, cellReadOnly
2124
2296
  return Promise.reject(e);
2125
2297
  }
2126
2298
  }, [pasteIntoSelection]);
2127
-
2128
2299
  var onClipboardCopy = function onClipboardCopy(cut) {
2129
2300
  if (isEmptySelection(selection)) return;
2130
2301
  return copySelection(selection, cut);
2131
2302
  };
2132
-
2133
2303
  var onClipboardPaste = function onClipboardPaste(e) {
2134
2304
  try {
2135
2305
  e.preventDefault();
@@ -2141,7 +2311,6 @@ var useClipboardAPI = function useClipboardAPI(selection, editData, cellReadOnly
2141
2311
  return Promise.reject(e);
2142
2312
  }
2143
2313
  };
2144
-
2145
2314
  React.useLayoutEffect(function () {
2146
2315
  if (!addListener) return;
2147
2316
  window.document.addEventListener('paste', onClipboardPaste);
@@ -2162,7 +2331,6 @@ var useClipboardAPI = function useClipboardAPI(selection, editData, cellReadOnly
2162
2331
  onClipboardPaste: onClipboardPaste
2163
2332
  };
2164
2333
  };
2165
-
2166
2334
  var copyClipboardTable = function copyClipboardTable(rows, payload) {
2167
2335
  try {
2168
2336
  var text = formatRowsAsTSV(rows);
@@ -2182,7 +2350,6 @@ var copyClipboardTable = function copyClipboardTable(rows, payload) {
2182
2350
  return Promise.reject(e);
2183
2351
  }
2184
2352
  };
2185
-
2186
2353
  var pasteClipboardTable = function pasteClipboardTable() {
2187
2354
  try {
2188
2355
  return Promise.resolve(navigator.clipboard.read()).then(function (items) {
@@ -2194,10 +2361,9 @@ var pasteClipboardTable = function pasteClipboardTable() {
2194
2361
  return Promise.reject(e);
2195
2362
  }
2196
2363
  };
2197
-
2198
2364
  var parseClipboardTable = function parseClipboardTable(item) {
2199
2365
  try {
2200
- var _temp7 = function _temp7() {
2366
+ var _temp5 = function _temp5() {
2201
2367
  return rows ? {
2202
2368
  rows: rows,
2203
2369
  payload: payload
@@ -2205,53 +2371,44 @@ var parseClipboardTable = function parseClipboardTable(item) {
2205
2371
  rows: []
2206
2372
  };
2207
2373
  };
2208
-
2209
2374
  var has = function has(type) {
2210
2375
  return item.types.includes(type);
2211
2376
  };
2212
-
2213
2377
  var get = function get(type) {
2214
2378
  if ('getData' in item) return item.getData(type);else if ('getType' in item) return item.getType(type).then(function (blob) {
2215
2379
  return blob.text();
2216
2380
  });
2217
2381
  return '';
2218
2382
  };
2219
-
2220
2383
  var rows, payload;
2221
-
2222
- var _temp8 = function () {
2384
+ var _temp4 = function () {
2223
2385
  if (has('text/html')) {
2224
2386
  return Promise.resolve(get('text/html')).then(function (pastedHtml) {
2225
2387
  var _parsePastedHtml = parsePastedHtml(pastedHtml);
2226
-
2227
2388
  rows = _parsePastedHtml.rows;
2228
2389
  payload = _parsePastedHtml.payload;
2229
2390
  });
2230
2391
  } else {
2231
- var _temp9 = function () {
2392
+ var _temp6 = function () {
2232
2393
  if (has('text/plain')) {
2233
2394
  return Promise.resolve(get('text/plain')).then(function (text) {
2234
2395
  rows = parsePastedText(text);
2235
2396
  });
2236
2397
  }
2237
2398
  }();
2238
-
2239
- if (_temp9 && _temp9.then) return _temp9.then(function () {});
2399
+ if (_temp6 && _temp6.then) return _temp6.then(function () {});
2240
2400
  }
2241
2401
  }();
2242
-
2243
- return Promise.resolve(_temp8 && _temp8.then ? _temp8.then(_temp7) : _temp7(_temp8));
2402
+ return Promise.resolve(_temp4 && _temp4.then ? _temp4.then(_temp5) : _temp5(_temp4));
2244
2403
  } catch (e) {
2245
2404
  return Promise.reject(e);
2246
2405
  }
2247
2406
  };
2248
-
2249
2407
  var formatRowsAsTSV = function formatRowsAsTSV(rows) {
2250
2408
  return rows.map(function (row) {
2251
2409
  return row.join('\t');
2252
2410
  }).join('\n');
2253
2411
  };
2254
-
2255
2412
  var formatRowsAsHTML = function formatRowsAsHTML(rows, payload) {
2256
2413
  var trs = rows.map(function (row) {
2257
2414
  var tds = row.map(formatTextAsHTML).map(function (cell) {
@@ -2262,120 +2419,90 @@ var formatRowsAsHTML = function formatRowsAsHTML(rows, payload) {
2262
2419
  return "<tr>" + row + "</tr>";
2263
2420
  }).join('\n');
2264
2421
  var table = "<table>" + trs + "</table>";
2265
-
2266
2422
  if (payload) {
2267
2423
  var extra = "<SheetHappens payload=\"" + formatTextAsHTML(JSON.stringify(payload)) + "\"></SheetHappens>";
2268
2424
  return extra + table;
2269
2425
  }
2270
-
2271
2426
  return table;
2272
2427
  };
2273
-
2274
2428
  var formatTextAsHTML = function formatTextAsHTML(s) {
2275
2429
  return s.replace(/[&"'<>]/g, function (i) {
2276
2430
  return "&#" + i.charCodeAt(0) + ";";
2277
2431
  });
2278
2432
  };
2279
-
2280
2433
  var formatSelectionAsRows = function formatSelectionAsRows(selection, editData) {
2281
2434
  if (isEmptySelection(selection)) return [];
2282
-
2283
2435
  var _normalizeSelection2 = normalizeSelection(selection),
2284
- _normalizeSelection2$ = _normalizeSelection2[0],
2285
- minX = _normalizeSelection2$[0],
2286
- minY = _normalizeSelection2$[1],
2287
- _normalizeSelection2$2 = _normalizeSelection2[1],
2288
- maxX = _normalizeSelection2$2[0],
2289
- maxY = _normalizeSelection2$2[1];
2290
-
2436
+ _normalizeSelection2$ = _normalizeSelection2[0],
2437
+ minX = _normalizeSelection2$[0],
2438
+ minY = _normalizeSelection2$[1],
2439
+ _normalizeSelection2$2 = _normalizeSelection2[1],
2440
+ maxX = _normalizeSelection2$2[0],
2441
+ maxY = _normalizeSelection2$2[1];
2291
2442
  if (isMaybeRowSelection(selection)) {
2292
2443
  var _findApproxMaxEditDat = findApproxMaxEditDataIndex(editData),
2293
- cellX = _findApproxMaxEditDat[0];
2294
-
2444
+ cellX = _findApproxMaxEditDat[0];
2295
2445
  minX = 0;
2296
2446
  maxX = cellX;
2297
2447
  }
2298
-
2299
2448
  if (isMaybeColumnSelection(selection)) {
2300
2449
  var _findApproxMaxEditDat2 = findApproxMaxEditDataIndex(editData),
2301
- cellY = _findApproxMaxEditDat2[1];
2302
-
2450
+ cellY = _findApproxMaxEditDat2[1];
2303
2451
  minY = 0;
2304
2452
  maxY = cellY;
2305
2453
  }
2306
-
2307
2454
  var rows = [];
2308
-
2309
2455
  for (var y = minY; y <= maxY; y++) {
2310
2456
  var row = [];
2311
-
2312
2457
  for (var x = minX; x <= maxX; x++) {
2313
2458
  var value = editData(x, y);
2314
-
2315
2459
  if (value !== null && value !== undefined) {
2316
2460
  row.push(value != null ? value : '');
2317
2461
  }
2318
2462
  }
2319
-
2320
2463
  rows.push(row);
2321
2464
  }
2322
-
2323
2465
  return rows;
2324
2466
  };
2325
-
2326
- var findTag = function findTag(element, tagName) {
2467
+ var _findTag = function findTag(element, tagName) {
2327
2468
  for (var _iterator = _createForOfIteratorHelperLoose(element.children), _step; !(_step = _iterator()).done;) {
2328
2469
  var child = _step.value;
2329
-
2330
2470
  if (child.nodeName === tagName) {
2331
2471
  return child;
2332
2472
  }
2333
-
2334
- var maybeTag = findTag(child, tagName);
2335
-
2473
+ var maybeTag = _findTag(child, tagName);
2336
2474
  if (maybeTag) {
2337
2475
  return maybeTag;
2338
2476
  }
2339
2477
  }
2340
2478
  };
2341
-
2342
2479
  var parsePastedHtml = function parsePastedHtml(html) {
2343
2480
  var div = document.createElement('div');
2344
2481
  div.innerHTML = html.trim();
2345
2482
  var rows = [];
2346
2483
  var payload = undefined;
2347
- var sheetNode = findTag(div, 'SHEETHAPPENS');
2348
-
2484
+ var sheetNode = _findTag(div, 'SHEETHAPPENS');
2349
2485
  if (sheetNode) {
2350
2486
  var json = sheetNode.getAttribute('payload');
2351
-
2352
2487
  try {
2353
2488
  payload = JSON.parse(json);
2354
2489
  } catch (e) {}
2355
2490
  }
2356
-
2357
- var tableNode = findTag(div, 'TABLE');
2358
-
2491
+ var tableNode = _findTag(div, 'TABLE');
2359
2492
  if (tableNode) {
2360
2493
  for (var _iterator2 = _createForOfIteratorHelperLoose(tableNode.children), _step2; !(_step2 = _iterator2()).done;) {
2361
2494
  var tableChild = _step2.value;
2362
-
2363
2495
  if (tableChild.nodeName === 'TBODY') {
2364
2496
  for (var _iterator3 = _createForOfIteratorHelperLoose(tableChild.children), _step3; !(_step3 = _iterator3()).done;) {
2365
2497
  var tr = _step3.value;
2366
-
2367
2498
  if (tr.nodeName === 'TR') {
2368
2499
  var row = [];
2369
-
2370
2500
  for (var _iterator4 = _createForOfIteratorHelperLoose(tr.children), _step4; !(_step4 = _iterator4()).done;) {
2371
2501
  var td = _step4.value;
2372
-
2373
2502
  if (td.nodeName === 'TD') {
2374
2503
  var str = '';
2375
-
2376
2504
  if (td.children.length !== 0 && td.children[0].nodeName === 'P') {
2377
2505
  var p = td.children[0];
2378
-
2379
2506
  if (p.children.length !== 0 && p.children[0].nodeName === 'FONT') {
2380
2507
  str = p.children[0].textContent.trim();
2381
2508
  } else {
@@ -2384,26 +2511,22 @@ var parsePastedHtml = function parsePastedHtml(html) {
2384
2511
  } else {
2385
2512
  str = td.textContent.trim();
2386
2513
  }
2387
-
2388
2514
  str = str.replaceAll('\n', '');
2389
2515
  str = str.replaceAll(/\s\s+/g, ' ');
2390
2516
  row.push(str);
2391
2517
  }
2392
2518
  }
2393
-
2394
2519
  rows.push(row);
2395
2520
  }
2396
2521
  }
2397
2522
  }
2398
2523
  }
2399
2524
  }
2400
-
2401
2525
  return {
2402
2526
  rows: rows,
2403
2527
  payload: payload
2404
2528
  };
2405
2529
  };
2406
-
2407
2530
  var parsePastedText = function parsePastedText(text) {
2408
2531
  return text.split(/\r?\n/).map(function (line) {
2409
2532
  return line.split('\t');
@@ -2411,204 +2534,167 @@ var parsePastedText = function parsePastedText(text) {
2411
2534
  };
2412
2535
 
2413
2536
  var INITIAL_SIZE = 256;
2414
- var makeCellLayout = function makeCellLayout(freeze, indent, offset, columns, rows) {
2537
+ var makeCellLayout = function makeCellLayout(freeze, offset, columns, rows) {
2415
2538
  var freezeX = freeze[0],
2416
- freezeY = freeze[1];
2417
- var indentX = indent[0],
2418
- indentY = indent[1];
2539
+ freezeY = freeze[1];
2419
2540
  var offsetX = offset[0],
2420
- offsetY = offset[1];
2421
-
2541
+ offsetY = offset[1];
2422
2542
  var getIndentX = function getIndentX() {
2423
- return indentX;
2543
+ return columns.getStart(0);
2424
2544
  };
2425
-
2426
2545
  var getIndentY = function getIndentY() {
2427
- return indentY;
2546
+ return rows.getStart(0);
2428
2547
  };
2429
-
2430
2548
  var getBaseOriginFor = function getBaseOriginFor(index, freeze, offset) {
2431
2549
  return index < freeze ? 0 : offset + freeze;
2432
2550
  };
2433
-
2434
2551
  var columnToPixel = function columnToPixel(column, anchor) {
2435
2552
  if (anchor === void 0) {
2436
2553
  anchor = 0;
2437
2554
  }
2438
-
2439
2555
  var base = getBaseOriginFor(column, freezeX, offsetX);
2440
2556
  var relative = columns.getStart(column) - columns.getStart(base);
2441
2557
  var adjust = column < freezeX ? 0 : columns.getStart(freezeX) - columns.getStart(0);
2442
- var size = column < 0 ? indentX : columns.getSize(column);
2443
- return column < 0 ? 0 : indentX + relative + adjust + anchor * size;
2558
+ var size = columns.getSize(column);
2559
+ return getIndentX() + relative + adjust + anchor * size;
2444
2560
  };
2445
-
2446
2561
  var rowToPixel = function rowToPixel(row, anchor) {
2447
2562
  if (anchor === void 0) {
2448
2563
  anchor = 0;
2449
2564
  }
2450
-
2451
2565
  var base = getBaseOriginFor(row, freezeY, offsetY);
2452
2566
  var relative = rows.getStart(row) - rows.getStart(base);
2453
2567
  var adjust = row < freezeY ? 0 : rows.getStart(freezeY) - rows.getStart(0);
2454
- var size = row < 0 ? indentY : rows.getSize(row);
2455
- return row < 0 ? 0 : indentY + relative + adjust + anchor * size;
2568
+ var size = rows.getSize(row);
2569
+ return getIndentY() + relative + adjust + anchor * size;
2456
2570
  };
2457
-
2458
2571
  var cellToPixel = function cellToPixel(cell, anchor) {
2459
2572
  if (anchor === void 0) {
2460
2573
  anchor = ORIGIN;
2461
2574
  }
2462
-
2463
2575
  var cellX = cell[0],
2464
- cellY = cell[1];
2576
+ cellY = cell[1];
2465
2577
  var _anchor = anchor,
2466
- anchorX = _anchor[0],
2467
- anchorY = _anchor[1];
2578
+ anchorX = _anchor[0],
2579
+ anchorY = _anchor[1];
2468
2580
  return [columnToPixel(cellX, anchorX), rowToPixel(cellY, anchorY)];
2469
2581
  };
2470
-
2471
2582
  var columnToAbsolute = function columnToAbsolute(column, anchorX) {
2472
2583
  if (anchorX === void 0) {
2473
2584
  anchorX = 0;
2474
2585
  }
2475
-
2476
2586
  var relative = columns.getStart(column);
2477
2587
  var size = column < 0 ? 0 : columns.getSize(column);
2478
2588
  return relative + anchorX * size;
2479
2589
  };
2480
-
2481
2590
  var rowToAbsolute = function rowToAbsolute(row, anchorY) {
2482
2591
  if (anchorY === void 0) {
2483
2592
  anchorY = 0;
2484
2593
  }
2485
-
2486
2594
  var relative = rows.getStart(row);
2487
2595
  var size = row < 0 ? 0 : rows.getSize(row);
2488
2596
  return relative + anchorY * size;
2489
2597
  };
2490
-
2491
2598
  var cellToAbsolute = function cellToAbsolute(cell, anchor) {
2492
2599
  if (anchor === void 0) {
2493
2600
  anchor = ORIGIN;
2494
2601
  }
2495
-
2496
2602
  var cellX = cell[0],
2497
- cellY = cell[1];
2603
+ cellY = cell[1];
2498
2604
  var _anchor2 = anchor,
2499
- anchorX = _anchor2[0],
2500
- anchorY = _anchor2[1];
2605
+ anchorX = _anchor2[0],
2606
+ anchorY = _anchor2[1];
2501
2607
  return [columnToAbsolute(cellX, anchorX), rowToAbsolute(cellY, anchorY)];
2502
2608
  };
2503
-
2504
- var pixelToIndex = function pixelToIndex(pixel, anchor, indent, freeze, offset, layout) {
2505
- var relative = pixel - indent;
2506
- if (relative < 0) return -1;
2609
+ var pixelToIndex = function pixelToIndex(pixel, anchor, freeze, offset, layout) {
2507
2610
  var getStart = layout.getStart,
2508
- lookupIndex = layout.lookupIndex;
2611
+ lookupIndex = layout.lookupIndex;
2612
+ var indent = getStart(0);
2613
+ if (pixel < indent) return -1;
2509
2614
  var frozen = getStart(freeze);
2510
-
2511
- if (relative < frozen) {
2512
- return lookupIndex(relative, anchor);
2615
+ if (pixel < frozen) {
2616
+ return lookupIndex(pixel, anchor);
2513
2617
  } else {
2618
+ var relative = pixel - indent;
2514
2619
  var base = getStart(offset + freeze);
2515
2620
  var adjust = getStart(freeze) - getStart(0);
2516
2621
  return lookupIndex(base + relative - adjust, anchor);
2517
2622
  }
2518
2623
  };
2519
-
2520
2624
  var pixelToColumn = function pixelToColumn(pixelX, anchorX) {
2521
2625
  if (anchorX === void 0) {
2522
2626
  anchorX = 0;
2523
2627
  }
2524
-
2525
- return pixelToIndex(pixelX, anchorX, indentX, freezeX, offsetX, columns);
2628
+ return pixelToIndex(pixelX, anchorX, freezeX, offsetX, columns);
2526
2629
  };
2527
-
2528
2630
  var pixelToRow = function pixelToRow(pixelY, anchorY) {
2529
2631
  if (anchorY === void 0) {
2530
2632
  anchorY = 0;
2531
2633
  }
2532
-
2533
- return pixelToIndex(pixelY, anchorY, indentY, freezeY, offsetY, rows);
2634
+ return pixelToIndex(pixelY, anchorY, freezeY, offsetY, rows);
2534
2635
  };
2535
-
2536
2636
  var pixelToCell = function pixelToCell(pixel, anchor) {
2537
2637
  if (anchor === void 0) {
2538
2638
  anchor = ORIGIN;
2539
2639
  }
2540
-
2541
2640
  var pixelX = pixel[0],
2542
- pixelY = pixel[1];
2641
+ pixelY = pixel[1];
2543
2642
  var _anchor3 = anchor,
2544
- anchorX = _anchor3[0],
2545
- anchorY = _anchor3[1];
2643
+ anchorX = _anchor3[0],
2644
+ anchorY = _anchor3[1];
2546
2645
  return [pixelToColumn(pixelX, anchorX), pixelToRow(pixelY, anchorY)];
2547
2646
  };
2548
-
2549
2647
  var absoluteToIndex = function absoluteToIndex(pixel, anchor, layout) {
2550
2648
  if (pixel < 0) return -1;
2551
2649
  var lookupIndex = layout.lookupIndex;
2552
2650
  return lookupIndex(pixel, anchor);
2553
2651
  };
2554
-
2555
2652
  var absoluteToColumn = function absoluteToColumn(pixelX, anchorX) {
2556
2653
  if (anchorX === void 0) {
2557
2654
  anchorX = 0;
2558
2655
  }
2559
-
2560
2656
  return absoluteToIndex(pixelX, anchorX, columns);
2561
2657
  };
2562
-
2563
2658
  var absoluteToRow = function absoluteToRow(pixelY, anchorY) {
2564
2659
  if (anchorY === void 0) {
2565
2660
  anchorY = 0;
2566
2661
  }
2567
-
2568
2662
  return absoluteToIndex(pixelY, anchorY, rows);
2569
2663
  };
2570
-
2571
2664
  var absoluteToCell = function absoluteToCell(pixel, anchor) {
2572
2665
  if (anchor === void 0) {
2573
2666
  anchor = ORIGIN;
2574
2667
  }
2575
-
2576
2668
  var pixelX = pixel[0],
2577
- pixelY = pixel[1];
2669
+ pixelY = pixel[1];
2578
2670
  var _anchor4 = anchor,
2579
- anchorX = _anchor4[0],
2580
- anchorY = _anchor4[1];
2671
+ anchorX = _anchor4[0],
2672
+ anchorY = _anchor4[1];
2581
2673
  return [absoluteToColumn(pixelX, anchorX), absoluteToRow(pixelY, anchorY)];
2582
2674
  };
2583
-
2584
- var getVisibleIndices = function getVisibleIndices(view, indent, freeze, offset, layout) {
2675
+ var getVisibleIndices = function getVisibleIndices(view, freeze, offset, layout) {
2585
2676
  var indices = [].concat(seq(freeze));
2586
2677
  var getStart = layout.getStart,
2587
- getEnd = layout.getEnd;
2678
+ getEnd = layout.getEnd;
2588
2679
  var frozen = getEnd(freeze - 1);
2589
2680
  var notFrozen = getStart(offset + freeze);
2590
- var relative = view - indent - frozen;
2591
-
2681
+ var relative = view - frozen;
2592
2682
  for (var i = offset + freeze; getStart(i) - notFrozen <= relative; ++i) {
2593
2683
  indices.push(i);
2594
2684
  }
2595
-
2596
2685
  return indices;
2597
2686
  };
2598
-
2599
2687
  var getVisibleCells = function getVisibleCells(view) {
2600
2688
  var viewX = view[0],
2601
- viewY = view[1];
2689
+ viewY = view[1];
2602
2690
  return {
2603
- columns: getVisibleIndices(viewX, indentX, freezeX, offsetX, columns),
2604
- rows: getVisibleIndices(viewY, indentY, freezeY, offsetY, rows)
2691
+ columns: getVisibleIndices(viewX, freezeX, offsetX, columns),
2692
+ rows: getVisibleIndices(viewY, freezeY, offsetY, rows)
2605
2693
  };
2606
2694
  };
2607
-
2608
2695
  var getVersion = function getVersion() {
2609
2696
  return columns.getVersion() + rows.getVersion();
2610
2697
  };
2611
-
2612
2698
  return {
2613
2699
  columnToPixel: columnToPixel,
2614
2700
  rowToPixel: rowToPixel,
@@ -2632,76 +2718,58 @@ var makeLayoutCache = function makeLayoutCache(sizer) {
2632
2718
  var offsets = makeIntMap(INITIAL_SIZE);
2633
2719
  var sizes = makeIntMap(INITIAL_SIZE);
2634
2720
  var version = 0;
2635
- offsets.set(0, 0);
2636
-
2721
+ offsets.set(0, sizer(-1));
2637
2722
  var getSize = function getSize(i) {
2638
- if (i < 0) return 0;
2723
+ if (i < 0) return sizer(i);
2639
2724
  if (sizes.has(i)) return sizes.get(i);
2640
2725
  var size = sizer(i) || 0;
2641
2726
  sizes.set(i, size);
2642
2727
  return size;
2643
2728
  };
2644
-
2645
2729
  var getOffset = function getOffset(i) {
2646
2730
  if (i < 0) return 0;
2647
2731
  if (offsets.has(i)) return offsets.get(i);
2648
- var j = offsets.tail() || 0;
2649
-
2732
+ var j = offsets.tail() || -1;
2650
2733
  while (j < i) {
2651
2734
  var size = getSize(j);
2652
2735
  var offset = (offsets.get(j) || 0) + size;
2653
2736
  offsets.set(++j, offset);
2654
2737
  }
2655
-
2656
2738
  return offsets.get(i);
2657
2739
  };
2658
-
2659
2740
  var getStart = function getStart(i) {
2660
2741
  return getOffset(i);
2661
2742
  };
2662
-
2663
2743
  var getEnd = function getEnd(i) {
2664
2744
  return getOffset(i + 1);
2665
2745
  };
2666
-
2667
2746
  var lookupIndex = function lookupIndex(x, anchor) {
2668
2747
  if (anchor === void 0) {
2669
2748
  anchor = 0;
2670
2749
  }
2671
-
2672
2750
  var last = offsets.tail() || 0;
2673
-
2674
- while (getOffset(last) < x && getSize(last)) {
2675
- last += 64;
2676
- }
2677
-
2751
+ while (getOffset(last) < x && getSize(last)) last += 64;
2678
2752
  var start = 0;
2679
2753
  var end = last;
2680
-
2681
2754
  while (start < end) {
2682
2755
  var mid = start + Math.floor((end - start) / 2) + 1;
2683
2756
  var value = getOffset(mid) - (anchor ? anchor * getSize(mid - 1) : 0);
2684
2757
  if (value <= x) start = mid;else end = mid - 1;
2685
2758
  }
2686
-
2687
2759
  return start;
2688
2760
  };
2689
-
2690
2761
  var clearAfter = function clearAfter(index) {
2691
2762
  index = Math.max(0, index);
2692
2763
  offsets.truncate(index);
2693
2764
  sizes.truncate(index);
2694
2765
  version++;
2695
2766
  };
2696
-
2697
2767
  var setSizer = function setSizer(s) {
2698
2768
  sizer = s;
2699
2769
  };
2700
-
2701
2770
  var getVersion = function getVersion() {
2702
2771
  return version;
2703
2772
  };
2704
-
2705
2773
  return {
2706
2774
  getSize: getSize,
2707
2775
  getStart: getStart,
@@ -2712,17 +2780,14 @@ var makeLayoutCache = function makeLayoutCache(sizer) {
2712
2780
  clearAfter: clearAfter
2713
2781
  };
2714
2782
  };
2715
-
2716
2783
  var makeIntMap = function makeIntMap(initialSize) {
2717
2784
  if (initialSize === void 0) {
2718
2785
  initialSize = 128;
2719
2786
  }
2720
-
2721
2787
  var used;
2722
2788
  var values;
2723
2789
  var last = 0;
2724
2790
  var GROW = 1.2;
2725
-
2726
2791
  var allocate = function allocate(size) {
2727
2792
  var newUsed = new Uint8Array(size);
2728
2793
  var newValues = new Uint32Array(size);
@@ -2731,56 +2796,41 @@ var makeIntMap = function makeIntMap(initialSize) {
2731
2796
  used = newUsed;
2732
2797
  values = newValues;
2733
2798
  };
2734
-
2735
2799
  allocate(initialSize);
2736
-
2737
2800
  var copy = function copy(from, to) {
2738
2801
  var n = Math.min(from.length, to.length);
2739
-
2740
2802
  for (var i = 0; i < n; ++i) {
2741
2803
  to[i] = from[i];
2742
2804
  }
2743
2805
  };
2744
-
2745
2806
  var ensure = function ensure(size) {
2746
2807
  var l = values.length;
2747
2808
  var grow = Math.round(l * GROW);
2748
2809
  if (l < size) allocate(Math.max(grow, size));
2749
2810
  };
2750
-
2751
2811
  var truncate = function truncate(size) {
2752
2812
  var l = values.length;
2753
2813
  if (l < size) return;
2754
2814
  var shrink = Math.round(size * GROW);
2755
- if (l > shrink) allocate(size);else for (var i = size; i < l; ++i) {
2756
- used[i] = 0;
2757
- }
2815
+ if (l > shrink) allocate(size);else for (var i = size; i < l; ++i) used[i] = 0;
2758
2816
  last = Math.min(last, size);
2759
-
2760
- while (last > 0 && !used[last]) {
2761
- last--;
2762
- }
2817
+ while (last > 0 && !used[last]) last--;
2763
2818
  };
2764
-
2765
2819
  var getTail = function getTail() {
2766
2820
  return used[last] ? last : null;
2767
2821
  };
2768
-
2769
2822
  var setValue = function setValue(i, value) {
2770
2823
  ensure(i + 1);
2771
2824
  values[i] = value;
2772
2825
  used[i] = 1;
2773
2826
  last = Math.max(last, i);
2774
2827
  };
2775
-
2776
2828
  var getValue = function getValue(i) {
2777
2829
  return used[i] ? values[i] : null;
2778
2830
  };
2779
-
2780
2831
  var hasValue = function hasValue(i) {
2781
2832
  return !!used[i];
2782
2833
  };
2783
-
2784
2834
  return {
2785
2835
  truncate: truncate,
2786
2836
  set: setValue,
@@ -2790,191 +2840,129 @@ var makeIntMap = function makeIntMap(initialSize) {
2790
2840
  };
2791
2841
  };
2792
2842
 
2793
- var resolveSheetStyle = function resolveSheetStyle(sheetStyle) {
2794
- var _sheetStyle$shadowBlu, _sheetStyle$shadowOpa, _sheetStyle$shadowCol;
2795
-
2796
- return {
2797
- freezeColumns: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.freezeColumns) || 0,
2798
- freezeRows: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.freezeRows) || 0,
2799
- hideColumnHeaders: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.hideColumnHeaders) || false,
2800
- hideRowHeaders: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.hideRowHeaders) || false,
2801
- hideGridlines: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.hideGridlines) || false,
2802
- hideScrollBars: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.hideScrollBars) || false,
2803
- columnHeaderHeight: sheetStyle !== null && sheetStyle !== void 0 && sheetStyle.hideColumnHeaders ? 1 : SIZES.headerHeight,
2804
- rowHeaderWidth: sheetStyle !== null && sheetStyle !== void 0 && sheetStyle.hideRowHeaders ? 1 : SIZES.headerWidth,
2805
- shadowBlur: (_sheetStyle$shadowBlu = sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.shadowBlur) != null ? _sheetStyle$shadowBlu : SIZES.shadowBlur,
2806
- shadowOpacity: (_sheetStyle$shadowOpa = sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.shadowOpacity) != null ? _sheetStyle$shadowOpa : SIZES.shadowOpacity,
2807
- shadowColor: (_sheetStyle$shadowCol = sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.shadowColor) != null ? _sheetStyle$shadowCol : COLORS.shadowColor
2808
- };
2809
- };
2810
- var applyAlignment = function applyAlignment(start, cellSize, style, imageWidth, alignment) {
2811
- if (alignment === void 0) {
2812
- alignment = style.textAlign;
2813
- }
2814
-
2815
- if (alignment === 'left') {
2816
- return start + style.marginLeft;
2817
- } else if (alignment === 'center') {
2818
- return start + cellSize * 0.5 - imageWidth / 2;
2819
- } else if (alignment === 'right') {
2820
- return start + (cellSize - style.marginRight - imageWidth);
2821
- }
2822
-
2823
- return start;
2824
- };
2825
-
2826
- var renderSheet = function renderSheet(context, cellLayout, visibleCells, sheetStyle, cellStyle, selection, secondarySelections, isFocused, knobPosition, knobArea, dragIndices, dragOffset, dropTarget, columnHeaders, columnHeaderStyle, displayData, columnGroupKeys, rowGroupKeys, selectedColumnGroups, selectedRowGroups, dataOffset) {
2843
+ var renderSheet = function renderSheet(context, imageRenderer, cellLayout, visibleCells, sheetStyle, cellStyle, selection, secondarySelections, isFocused, knobPosition, knobArea, dragIndices, dragOffset, dropTarget, columnHeaders, columnHeaderStyle, displayData, columnGroupKeys, rowGroupKeys, selectedColumnGroups, selectedRowGroups, dataOffset) {
2827
2844
  var canvas = context.canvas;
2828
2845
  var width = canvas.width,
2829
- height = canvas.height;
2846
+ height = canvas.height;
2830
2847
  var hideGridlines = sheetStyle.hideGridlines,
2831
- hideRowHeaders = sheetStyle.hideRowHeaders,
2832
- hideColumnHeaders = sheetStyle.hideColumnHeaders,
2833
- rowHeaderWidth = sheetStyle.rowHeaderWidth,
2834
- columnHeaderHeight = sheetStyle.columnHeaderHeight,
2835
- freezeColumns = sheetStyle.freezeColumns,
2836
- freezeRows = sheetStyle.freezeRows,
2837
- shadowBlur = sheetStyle.shadowBlur,
2838
- shadowColor = sheetStyle.shadowColor,
2839
- shadowOpacity = sheetStyle.shadowOpacity;
2848
+ hideRowHeaders = sheetStyle.hideRowHeaders,
2849
+ hideColumnHeaders = sheetStyle.hideColumnHeaders,
2850
+ freezeColumns = sheetStyle.freezeColumns,
2851
+ freezeRows = sheetStyle.freezeRows,
2852
+ shadowBlur = sheetStyle.shadowBlur,
2853
+ shadowColor = sheetStyle.shadowColor,
2854
+ shadowOpacity = sheetStyle.shadowOpacity;
2840
2855
  var columns = visibleCells.columns,
2841
- rows = visibleCells.rows;
2856
+ rows = visibleCells.rows;
2842
2857
  var columnToPixel = cellLayout.columnToPixel,
2843
- rowToPixel = cellLayout.rowToPixel,
2844
- columnToAbsolute = cellLayout.columnToAbsolute,
2845
- rowToAbsolute = cellLayout.rowToAbsolute;
2846
- var clickables = [];
2858
+ rowToPixel = cellLayout.rowToPixel,
2859
+ columnToAbsolute = cellLayout.columnToAbsolute,
2860
+ rowToAbsolute = cellLayout.rowToAbsolute;
2861
+ var allClickables = [];
2847
2862
  var freeze = [freezeColumns, freezeRows];
2848
- var indent = [rowHeaderWidth, columnHeaderHeight];
2849
- var pixelRatio = resizeCanvas(canvas);
2863
+ var indentX = columnToAbsolute(0);
2864
+ var indentY = rowToAbsolute(0);
2865
+ resizeCanvas(canvas);
2850
2866
  context.clearRect(0, 0, width, height);
2851
2867
  context.fillStyle = 'white';
2852
2868
  context.fillRect(0, 0, width, height);
2853
2869
  context.shadowColor = '#00000080';
2854
-
2855
2870
  for (var _iterator = _createForOfIteratorHelperLoose(rows), _step; !(_step = _iterator()).done;) {
2856
2871
  var y = _step.value;
2857
-
2858
2872
  for (var _iterator10 = _createForOfIteratorHelperLoose(columns), _step10; !(_step10 = _iterator10()).done;) {
2859
2873
  var x = _step10.value;
2860
-
2861
2874
  var _left7 = columnToPixel(x);
2862
-
2863
2875
  var _right7 = columnToPixel(x, 1);
2864
-
2865
2876
  var _top7 = rowToPixel(y);
2866
-
2867
2877
  var _bottom7 = rowToPixel(y, 1);
2868
-
2869
2878
  var _cellStyle = cellStyle(x, y),
2870
- fillColor = _cellStyle.fillColor;
2871
-
2879
+ fillColor = _cellStyle.fillColor;
2872
2880
  if (fillColor) {
2873
2881
  context.fillStyle = fillColor;
2874
2882
  context.fillRect(_left7, _top7, _right7 - _left7, _bottom7 - _top7);
2875
2883
  }
2876
2884
  }
2877
2885
  }
2878
-
2879
2886
  var selectionActive = !isEmptySelection(selection);
2880
2887
  var rowSelectionActive = isRowSelection(selection);
2881
2888
  var columnSelectionActive = isColumnSelection(selection);
2882
-
2883
- var _resolveFrozenSelecti = resolveFrozenSelection(selection, cellLayout, freeze, indent, dataOffset),
2884
- selected = _resolveFrozenSelecti[0],
2885
- hideKnob = _resolveFrozenSelecti[1];
2886
-
2889
+ var _resolveFrozenSelecti = resolveFrozenSelection(selection, cellLayout, freeze, dataOffset),
2890
+ selected = _resolveFrozenSelecti[0],
2891
+ hideKnob = _resolveFrozenSelecti[1];
2887
2892
  if (selectionActive) {
2888
2893
  var _selected$ = selected[0],
2889
- left = _selected$[0],
2890
- top = _selected$[1],
2891
- _selected$2 = selected[1],
2892
- right = _selected$2[0],
2893
- bottom = _selected$2[1];
2894
+ left = _selected$[0],
2895
+ top = _selected$[1],
2896
+ _selected$2 = selected[1],
2897
+ right = _selected$2[0],
2898
+ bottom = _selected$2[1];
2894
2899
  context.fillStyle = COLORS.selectionBackground;
2895
2900
  context.fillRect(left, top, right - left, bottom - top);
2896
2901
  }
2897
-
2898
2902
  if (!hideRowHeaders) {
2899
2903
  context.fillStyle = COLORS.headerBackground;
2900
- context.fillRect(0, 0, rowHeaderWidth, context.canvas.height);
2901
-
2904
+ context.fillRect(0, 0, indentX, context.canvas.height);
2902
2905
  if (selectionActive && !columnSelectionActive) {
2903
2906
  var _selected$3 = selected[0],
2904
- _top = _selected$3[1],
2905
- _selected$4 = selected[1],
2906
- _bottom = _selected$4[1];
2907
+ _top = _selected$3[1],
2908
+ _selected$4 = selected[1],
2909
+ _bottom = _selected$4[1];
2907
2910
  context.fillStyle = COLORS.headerActive;
2908
- context.fillRect(0, _top, rowHeaderWidth, _bottom - _top);
2911
+ context.fillRect(0, _top, indentX, _bottom - _top);
2909
2912
  }
2910
2913
  }
2911
-
2912
2914
  if (!hideColumnHeaders) {
2913
2915
  context.fillStyle = COLORS.headerBackground;
2914
- context.fillRect(0, 0, context.canvas.width, columnHeaderHeight);
2915
-
2916
+ context.fillRect(0, 0, context.canvas.width, indentY);
2916
2917
  if (selectionActive && !rowSelectionActive) {
2917
2918
  var _selected$5 = selected[0],
2918
- _left = _selected$5[0],
2919
- _selected$6 = selected[1],
2920
- _right = _selected$6[0];
2919
+ _left = _selected$5[0],
2920
+ _selected$6 = selected[1],
2921
+ _right = _selected$6[0];
2921
2922
  context.fillStyle = COLORS.headerActive;
2922
- context.fillRect(_left, 0, _right - _left, columnHeaderHeight);
2923
+ context.fillRect(_left, 0, _right - _left, indentY);
2923
2924
  }
2924
2925
  }
2925
-
2926
2926
  context.strokeStyle = COLORS.gridLine;
2927
2927
  context.lineWidth = 1;
2928
- var gridRight = hideGridlines ? rowHeaderWidth : context.canvas.width;
2929
- var gridBottom = hideGridlines ? columnHeaderHeight : context.canvas.height;
2930
-
2928
+ var gridRight = hideGridlines ? indentX : context.canvas.width;
2929
+ var gridBottom = hideGridlines ? indentY : context.canvas.height;
2931
2930
  var drawGridLineX = function drawGridLineX(x, height) {
2932
2931
  context.beginPath();
2933
2932
  context.moveTo(x - 0.5, 0);
2934
2933
  context.lineTo(x - 0.5, height);
2935
2934
  context.stroke();
2936
2935
  };
2937
-
2938
2936
  var drawGridLineY = function drawGridLineY(y, width) {
2939
2937
  context.beginPath();
2940
2938
  context.moveTo(0, y - 0.5);
2941
2939
  context.lineTo(width, y - 0.5);
2942
2940
  context.stroke();
2943
2941
  };
2944
-
2945
- drawGridLineX(rowHeaderWidth, context.canvas.height);
2946
- drawGridLineY(columnHeaderHeight, context.canvas.width);
2947
-
2942
+ drawGridLineX(indentX, context.canvas.height);
2943
+ drawGridLineY(indentY, context.canvas.width);
2948
2944
  for (var _iterator2 = _createForOfIteratorHelperLoose(columns), _step2; !(_step2 = _iterator2()).done;) {
2949
2945
  var _column2 = _step2.value;
2950
-
2951
2946
  var _right8 = columnToPixel(_column2, 1);
2952
-
2953
2947
  drawGridLineX(_right8, gridBottom);
2954
2948
  }
2955
-
2956
2949
  for (var _iterator3 = _createForOfIteratorHelperLoose(rows), _step3; !(_step3 = _iterator3()).done;) {
2957
2950
  var _row2 = _step3.value;
2958
-
2959
2951
  var _bottom8 = rowToPixel(_row2, 1);
2960
-
2961
2952
  drawGridLineY(_bottom8, gridRight);
2962
2953
  }
2963
-
2964
2954
  var _normalizeSelection = normalizeSelection(selection),
2965
- _normalizeSelection$ = _normalizeSelection[0],
2966
- minX = _normalizeSelection$[0],
2967
- minY = _normalizeSelection$[1],
2968
- _normalizeSelection$2 = _normalizeSelection[1],
2969
- maxX = _normalizeSelection$2[0],
2970
- maxY = _normalizeSelection$2[1];
2971
-
2955
+ _normalizeSelection$ = _normalizeSelection[0],
2956
+ minX = _normalizeSelection$[0],
2957
+ minY = _normalizeSelection$[1],
2958
+ _normalizeSelection$2 = _normalizeSelection[1],
2959
+ maxX = _normalizeSelection$2[0],
2960
+ maxY = _normalizeSelection$2[1];
2972
2961
  if (!hideRowHeaders) {
2973
2962
  context.textBaseline = 'middle';
2974
2963
  context.textAlign = 'center';
2975
2964
  context.font = DEFAULT_CELL_STYLE.fontSize + 'px ' + DEFAULT_CELL_STYLE.fontFamily;
2976
2965
  context.fillStyle = COLORS.headerText;
2977
-
2978
2966
  for (var _iterator4 = _createForOfIteratorHelperLoose(rows), _step4; !(_step4 = _iterator4()).done;) {
2979
2967
  var row = _step4.value;
2980
2968
  var content = "" + (row + 1);
@@ -2984,542 +2972,469 @@ var renderSheet = function renderSheet(context, cellLayout, visibleCells, sheetS
2984
2972
  var isSelfSelected = rowSelectionActive && isActive;
2985
2973
  var isGroupSelected = rowSelectionActive && isInRowGroup;
2986
2974
  var style = isSelfSelected ? HEADER_SELECTED_STYLE : isGroupSelected ? HEADER_GROUP_SELECTED_STYLE : isActive ? HEADER_ACTIVE_STYLE : NO_STYLE;
2987
-
2988
2975
  var resolvedStyle = _extends({}, DEFAULT_COLUMN_HEADER_STYLE, style);
2989
-
2990
2976
  var _top2 = rowToPixel(row);
2991
-
2992
2977
  var _bottom2 = rowToPixel(row, 1);
2993
-
2994
- clickables.push.apply(clickables, renderCell(context, content, resolvedStyle, 0, _top2, rowHeaderWidth, _bottom2 - _top2, pixelRatio));
2978
+ var clickables = renderCell(context, imageRenderer, content, resolvedStyle, 0, _top2, indentX, _bottom2 - _top2);
2979
+ if (clickables) allClickables.push.apply(allClickables, clickables);
2995
2980
  }
2996
2981
  }
2997
-
2998
2982
  if (!hideColumnHeaders) {
2999
2983
  context.textBaseline = 'middle';
3000
- context.textAlign = 'center';
3001
-
3002
2984
  for (var _iterator5 = _createForOfIteratorHelperLoose(columns), _step5; !(_step5 = _iterator5()).done;) {
3003
2985
  var _columnHeaders;
3004
-
3005
2986
  var column = _step5.value;
3006
-
3007
2987
  var _isActive = isInRange(column, minX, maxX);
3008
-
3009
2988
  var _groupKey = columnGroupKeys(column);
3010
-
3011
2989
  var isInColumnGroup = _groupKey != null && (selectedColumnGroups === null || selectedColumnGroups === void 0 ? void 0 : selectedColumnGroups.has(_groupKey));
3012
2990
  var isSelected = columnSelectionActive && !rowSelectionActive && (_isActive || isInColumnGroup);
3013
2991
  var selectedStyle = isSelected ? HEADER_SELECTED_STYLE : NO_STYLE;
3014
2992
  var activeStyle = _isActive ? HEADER_ACTIVE_STYLE : NO_STYLE;
3015
-
3016
2993
  var _style = _extends({}, DEFAULT_COLUMN_HEADER_STYLE, columnHeaderStyle(column), activeStyle, selectedStyle);
3017
-
3018
2994
  var _left2 = columnToPixel(column);
3019
-
3020
2995
  var _right2 = columnToPixel(column, 1);
3021
-
3022
2996
  var _content = (_columnHeaders = columnHeaders(column, _style)) != null ? _columnHeaders : excelHeaderString(column + 1);
3023
-
3024
- clickables.push.apply(clickables, renderCell(context, _content, _style, _left2, 0, _right2 - _left2, columnHeaderHeight, pixelRatio));
2997
+ var _clickables = renderCell(context, imageRenderer, _content, _style, _left2, 0, _right2 - _left2, indentY);
2998
+ if (_clickables) allClickables.push.apply(allClickables, _clickables);
3025
2999
  }
3026
3000
  }
3027
-
3028
3001
  if (selectionActive) {
3029
3002
  context.strokeStyle = COLORS.selectionBorder;
3030
3003
  context.lineWidth = 2;
3031
3004
  context.globalAlpha = isFocused ? 1 : 0.5;
3032
3005
  var _selected$7 = selected[0],
3033
- _left3 = _selected$7[0],
3034
- _top3 = _selected$7[1],
3035
- _selected$8 = selected[1],
3036
- _right3 = _selected$8[0],
3037
- _bottom3 = _selected$8[1];
3006
+ _left3 = _selected$7[0],
3007
+ _top3 = _selected$7[1],
3008
+ _selected$8 = selected[1],
3009
+ _right3 = _selected$8[0],
3010
+ _bottom3 = _selected$8[1];
3038
3011
  context.strokeRect(_left3, _top3, _right3 - _left3 - 1, _bottom3 - _top3 - 1);
3039
3012
  context.globalAlpha = 1;
3040
3013
  }
3041
-
3042
3014
  for (var _iterator6 = _createForOfIteratorHelperLoose(secondarySelections), _step6; !(_step6 = _iterator6()).done;) {
3043
3015
  var secondarySelection = _step6.value;
3044
3016
  var _selection = secondarySelection.span;
3045
3017
  if (isEmptySelection(_selection)) continue;
3046
-
3047
- var _resolveFrozenSelecti2 = resolveFrozenSelection(_selection, cellLayout, freeze, indent, dataOffset),
3048
- _selected = _resolveFrozenSelecti2[0];
3049
-
3018
+ var _resolveFrozenSelecti2 = resolveFrozenSelection(_selection, cellLayout, freeze, dataOffset),
3019
+ _selected = _resolveFrozenSelecti2[0];
3050
3020
  var _selected$9 = _selected[0],
3051
- _left8 = _selected$9[0],
3052
- _top8 = _selected$9[1],
3053
- _selected$10 = _selected[1],
3054
- _right9 = _selected$10[0],
3055
- _bottom9 = _selected$10[1];
3021
+ _left8 = _selected$9[0],
3022
+ _top8 = _selected$9[1],
3023
+ _selected$10 = _selected[1],
3024
+ _right9 = _selected$10[0],
3025
+ _bottom9 = _selected$10[1];
3056
3026
  context.strokeStyle = secondarySelection.color;
3057
3027
  context.lineWidth = 1;
3058
3028
  context.beginPath();
3059
3029
  context.strokeRect(_left8 - 1, _top8 - 1, _right9 - _left8 + 1, _bottom9 - _top8 + 1);
3060
3030
  }
3061
-
3062
3031
  if (knobArea) {
3063
3032
  var _normalizeSelection2 = normalizeSelection(knobArea),
3064
- _normalizeSelection2$ = _normalizeSelection2[0],
3065
- _minX = _normalizeSelection2$[0],
3066
- _minY = _normalizeSelection2$[1],
3067
- _normalizeSelection2$2 = _normalizeSelection2[1],
3068
- _maxX = _normalizeSelection2$2[0],
3069
- _maxY = _normalizeSelection2$2[1];
3070
-
3033
+ _normalizeSelection2$ = _normalizeSelection2[0],
3034
+ _minX = _normalizeSelection2$[0],
3035
+ _minY = _normalizeSelection2$[1],
3036
+ _normalizeSelection2$2 = _normalizeSelection2[1],
3037
+ _maxX = _normalizeSelection2$2[0],
3038
+ _maxY = _normalizeSelection2$2[1];
3071
3039
  var _left4 = columnToPixel(_minX);
3072
-
3073
3040
  var _top4 = rowToPixel(_minY);
3074
-
3075
3041
  var _right4 = columnToPixel(_maxX, 1);
3076
-
3077
3042
  var _bottom4 = rowToPixel(_maxY, 1);
3078
-
3079
3043
  context.strokeStyle = COLORS.knobAreaBorder;
3080
3044
  context.setLineDash([3, 3]);
3081
3045
  context.lineWidth = 1;
3082
3046
  context.strokeRect(_left4 - 1, _top4 - 1, _right4 - _left4 + 1, _bottom4 - _top4 + 1);
3083
3047
  context.setLineDash([]);
3084
3048
  }
3085
-
3086
3049
  if (knobPosition && !hideKnob) {
3087
3050
  var knobX = knobPosition[0],
3088
- knobY = knobPosition[1];
3051
+ knobY = knobPosition[1];
3089
3052
  context.fillStyle = COLORS.selectionBorder;
3090
3053
  context.fillRect(knobX - SIZES.knobArea * 0.5, knobY - SIZES.knobArea * 0.5, SIZES.knobArea, SIZES.knobArea);
3091
3054
  }
3092
-
3093
3055
  if (dragOffset) {
3094
3056
  var shiftX = dragOffset[0],
3095
- shiftY = dragOffset[1];
3057
+ shiftY = dragOffset[1];
3096
3058
  var dragColumns = dragIndices[0],
3097
- dragRows = dragIndices[1];
3059
+ dragRows = dragIndices[1];
3098
3060
  context.fillStyle = COLORS.dragGhost;
3099
-
3100
3061
  if (dragColumns) {
3101
3062
  for (var _iterator7 = _createForOfIteratorHelperLoose(dragColumns), _step7; !(_step7 = _iterator7()).done;) {
3102
3063
  var _column = _step7.value;
3103
-
3104
3064
  var _left5 = columnToPixel(_column);
3105
-
3106
3065
  var _right5 = columnToPixel(_column, 1);
3107
-
3108
3066
  context.fillRect(_left5 + shiftX, 0, _right5 - _left5, height);
3109
3067
  }
3110
3068
  }
3111
-
3112
3069
  if (dragRows) {
3113
3070
  for (var _iterator8 = _createForOfIteratorHelperLoose(dragRows), _step8; !(_step8 = _iterator8()).done;) {
3114
3071
  var _row = _step8.value;
3115
-
3116
3072
  var _top5 = rowToPixel(_row);
3117
-
3118
3073
  var _bottom5 = rowToPixel(_row, 1);
3119
-
3120
3074
  context.fillRect(0, _top5 + shiftY, width, _bottom5 - _top5);
3121
3075
  }
3122
3076
  }
3123
3077
  }
3124
-
3125
3078
  if (dropTarget) {
3126
3079
  var _resolveSelection = resolveSelection(dropTarget, cellLayout),
3127
- _resolveSelection$ = _resolveSelection[0],
3128
- _left6 = _resolveSelection$[0],
3129
- _top6 = _resolveSelection$[1],
3130
- _resolveSelection$2 = _resolveSelection[1],
3131
- _right6 = _resolveSelection$2[0],
3132
- _bottom6 = _resolveSelection$2[1];
3133
-
3080
+ _resolveSelection$ = _resolveSelection[0],
3081
+ _left6 = _resolveSelection$[0],
3082
+ _top6 = _resolveSelection$[1],
3083
+ _resolveSelection$2 = _resolveSelection[1],
3084
+ _right6 = _resolveSelection$2[0],
3085
+ _bottom6 = _resolveSelection$2[1];
3134
3086
  context.strokeStyle = COLORS.dropTarget;
3135
3087
  context.lineWidth = 4;
3136
-
3137
3088
  if (isColumnSelection(dropTarget)) {
3138
3089
  _right6 = _left6;
3139
3090
  }
3140
-
3141
3091
  if (isRowSelection(dropTarget)) {
3142
3092
  _bottom6 = _top6;
3143
3093
  }
3144
-
3145
3094
  context.strokeRect(_left6 - 1, _top6 - 1, _right6 - _left6, _bottom6 - _top6);
3146
3095
  }
3147
-
3148
3096
  var scrollX = dataOffset[0],
3149
- scrollY = dataOffset[1];
3097
+ scrollY = dataOffset[1];
3150
3098
  var hasRowShadow = freezeRows > 0 && scrollY > 0;
3151
3099
  var hasColumnShadow = freezeColumns > 0 && scrollX > 0;
3152
-
3153
3100
  if (hasRowShadow || hasColumnShadow) {
3154
3101
  if (hasRowShadow) {
3155
- var h = columnHeaderHeight + rowToAbsolute(freezeRows);
3102
+ var h = rowToAbsolute(freezeRows);
3156
3103
  var gradient = context.createLinearGradient(0, h, 0, h + shadowBlur);
3157
3104
  halfShadowGradient(gradient, shadowColor, shadowOpacity);
3158
3105
  context.fillStyle = gradient;
3159
3106
  context.fillRect(0, h, width, shadowBlur);
3160
3107
  }
3161
-
3162
3108
  if (hasColumnShadow) {
3163
- var w = rowHeaderWidth + columnToAbsolute(freezeColumns);
3164
-
3109
+ var w = columnToAbsolute(freezeColumns);
3165
3110
  var _gradient = context.createLinearGradient(w, 0, w + shadowBlur, 0);
3166
-
3167
3111
  halfShadowGradient(_gradient, shadowColor, shadowOpacity);
3168
3112
  context.fillStyle = _gradient;
3169
3113
  context.fillRect(w, 0, shadowBlur, height);
3170
3114
  }
3171
3115
  }
3172
-
3173
3116
  context.textBaseline = 'middle';
3174
-
3175
3117
  for (var _iterator9 = _createForOfIteratorHelperLoose(rows), _step9; !(_step9 = _iterator9()).done;) {
3176
3118
  var _y = _step9.value;
3177
-
3178
3119
  for (var _iterator11 = _createForOfIteratorHelperLoose(columns), _step11; !(_step11 = _iterator11()).done;) {
3179
3120
  var _x = _step11.value;
3180
-
3181
3121
  var _left9 = columnToPixel(_x);
3182
-
3183
3122
  var _right10 = columnToPixel(_x, 1);
3184
-
3185
3123
  var _top9 = rowToPixel(_y);
3186
-
3187
3124
  var _bottom10 = rowToPixel(_y, 1);
3188
-
3189
3125
  var _style2 = _extends({}, DEFAULT_CELL_STYLE, cellStyle(_x, _y));
3190
-
3191
3126
  var cellContent = displayData(_x, _y, _style2);
3192
-
3193
3127
  if (cellContent !== null && cellContent !== undefined) {
3194
- clickables.push.apply(clickables, renderCell(context, cellContent, _style2, _left9, _top9, _right10 - _left9, _bottom10 - _top9, pixelRatio));
3128
+ var _clickables2 = renderCell(context, imageRenderer, cellContent, _style2, _left9, _top9, _right10 - _left9, _bottom10 - _top9);
3129
+ if (_clickables2) allClickables.push.apply(allClickables, _clickables2);
3195
3130
  }
3196
3131
  }
3197
3132
  }
3198
-
3199
- return clickables;
3133
+ return allClickables;
3200
3134
  };
3201
- var renderCell = function renderCell(context, cellContent, style, xCoord, yCoord, cellWidth, cellHeight, pixelRatio) {
3202
- var clickables = [];
3203
-
3135
+ var renderCell = function renderCell(context, imageRenderer, cellContent, style, xCoord, yCoord, cellWidth, cellHeight) {
3204
3136
  if (cellContent === null) {
3205
- return clickables;
3137
+ return null;
3206
3138
  }
3207
-
3139
+ var fillText = context.fillText.bind(context);
3140
+ var fontString = style.fontWeight + ' ' + style.fontSize + 'px ' + style.fontFamily;
3141
+ context.font = fontString;
3208
3142
  context.fillStyle = style.color;
3209
- context.font = style.weight + ' ' + style.fontSize + 'px ' + style.fontFamily;
3210
- context.textAlign = style.textAlign;
3211
- var yy = Math.round((yCoord + cellHeight * 0.5) * pixelRatio) / pixelRatio;
3212
- context.save();
3213
- context.beginPath();
3214
- context.rect(xCoord, yCoord, cellWidth, cellHeight);
3215
- context.clip();
3216
-
3143
+ var marginTop = style.marginTop,
3144
+ marginBottom = style.marginBottom,
3145
+ marginLeft = style.marginLeft,
3146
+ marginRight = style.marginRight,
3147
+ lineHeight = style.lineHeight;
3148
+ var innerX = Math.round(xCoord + marginLeft);
3149
+ var innerY = Math.round(yCoord + marginTop);
3150
+ var innerWidth = Math.round(cellWidth - marginRight - marginLeft);
3151
+ var innerHeight = Math.round(cellHeight - marginTop - marginBottom);
3152
+ var middleY = roundDpi(yCoord + marginTop + lineHeight / 2);
3217
3153
  if (style.backgroundColor !== '') {
3218
3154
  context.fillStyle = style.backgroundColor;
3219
3155
  context.fillRect(xCoord, yCoord, cellWidth, cellHeight);
3220
3156
  context.fillStyle = style.color;
3221
3157
  }
3222
-
3223
3158
  if (typeof cellContent === 'string' || typeof cellContent === 'number') {
3224
- var xx = applyAlignment(xCoord, cellWidth, style, 0);
3225
- var text = '' + cellContent;
3226
- context.fillText(text, xx, yy);
3159
+ clipToBox(context, xCoord, yCoord, cellWidth, cellHeight, function () {
3160
+ wrapText(context, cellContent, style, undefined, innerX, middleY, innerWidth, innerHeight, fillText);
3161
+ });
3162
+ return null;
3227
3163
  } else if (typeof cellContent === 'object') {
3228
- for (var _iterator12 = _createForOfIteratorHelperLoose(cellContent.items), _step12; !(_step12 = _iterator12()).done;) {
3229
- var obj = _step12.value;
3230
- var x = 0;
3231
- var y = 0;
3232
- var w = 0;
3233
- var h = 0;
3234
-
3235
- if (obj.content instanceof HTMLImageElement) {
3236
- w = obj.width || cellWidth;
3237
- h = obj.height || cellHeight;
3238
- var finalX = applyAlignment(xCoord, cellWidth, style, w, obj.horizontalAlign);
3239
- x = finalX + obj.x;
3240
- y = yy + obj.y;
3241
- context.drawImage(obj.content, x, y, w, h);
3242
- } else if (typeof obj.content === 'string' || typeof obj.content === 'number') {
3243
- if (obj.horizontalAlign) {
3244
- context.textAlign = obj.horizontalAlign;
3164
+ var renderedFlex = resolveCellFlexLayout(context, cellContent, innerX, innerY, innerWidth, innerHeight);
3165
+ var renderedAbsolute = resolveCellAbsoluteLayout(cellContent, innerX, innerY, innerWidth, innerHeight);
3166
+ var rendered = [].concat(renderedFlex, renderedAbsolute);
3167
+ clipToBox(context, xCoord, yCoord, cellWidth, cellHeight, function () {
3168
+ var _loop = function _loop() {
3169
+ var _step12$value = _step12.value,
3170
+ i = _step12$value[0],
3171
+ render = _step12$value[1];
3172
+ var box = render.box,
3173
+ item = render.item;
3174
+ var _box$ = box[0],
3175
+ left = _box$[0],
3176
+ top = _box$[1],
3177
+ _box$2 = box[1],
3178
+ right = _box$2[0],
3179
+ bottom = _box$2[1];
3180
+ var width = right - left;
3181
+ var height = bottom - top;
3182
+ if (cellContent.inspect) {
3183
+ context.lineWidth = 1;
3184
+ context.strokeStyle = '#ff00ff';
3185
+ context.strokeRect(left + 0.5, top + 0.5, width - 0.5, height - 0.5);
3245
3186
  }
3246
-
3247
- var _finalX = applyAlignment(xCoord, cellWidth, style, 0, obj.horizontalAlign);
3248
-
3249
- var _text = '' + obj.content;
3250
-
3251
- var left = _finalX + obj.x;
3252
- var top = yy + obj.y;
3253
- context.fillText(_text, left, top);
3254
- var measure = context.measureText(_text);
3255
- x = left - measure.actualBoundingBoxLeft;
3256
- y = top - measure.actualBoundingBoxAscent;
3257
- w = left + measure.actualBoundingBoxRight - x;
3258
- h = top + measure.actualBoundingBoxDescent - y;
3259
- }
3260
-
3261
- if (obj.onClick) {
3262
- clickables.push({
3263
- rect: [[x, y], [x + w, y + h]],
3264
- obj: obj
3187
+ var clipLeft = i > 0 ? left : xCoord;
3188
+ var clipRight = i < rendered.length ? right : yCoord + cellWidth;
3189
+ var clipWidth = clipRight - clipLeft;
3190
+ clipToBox(context, clipLeft, yCoord, clipWidth, cellHeight, function () {
3191
+ if (item.display === 'inline') {
3192
+ var text = item.text;
3193
+ if (text != null) {
3194
+ wrapText(context, text, style, item.textAlign, left, roundDpi(top + lineHeight / 2), width, height, fillText);
3195
+ }
3196
+ }
3197
+ if (item.display === 'image' || item.display === 'icon') {
3198
+ imageRenderer(context, item, style, box);
3199
+ }
3265
3200
  });
3201
+ };
3202
+ for (var _iterator12 = _createForOfIteratorHelperLoose(rendered.entries()), _step12; !(_step12 = _iterator12()).done;) {
3203
+ _loop();
3266
3204
  }
3267
- }
3205
+ });
3206
+ return rendered.filter(function (_ref) {
3207
+ var item = _ref.item;
3208
+ return item === null || item === void 0 ? void 0 : item.onClick;
3209
+ });
3268
3210
  }
3269
-
3211
+ return null;
3212
+ };
3213
+ var clipToBox = function clipToBox(context, xCoord, yCoord, cellWidth, cellHeight, callback) {
3214
+ context.save();
3215
+ context.beginPath();
3216
+ context.rect(xCoord, yCoord, cellWidth, cellHeight);
3217
+ context.clip();
3218
+ callback();
3270
3219
  context.restore();
3271
- return clickables;
3272
3220
  };
3273
-
3274
3221
  var resolveSelection = function resolveSelection(selection, cellLayout) {
3275
3222
  var cellToPixel = cellLayout.cellToPixel;
3276
3223
  var rowSelectionActive = isRowSelection(selection);
3277
3224
  var columnSelectionActive = isColumnSelection(selection);
3278
-
3279
3225
  var _normalizeSelection3 = normalizeSelection(selection),
3280
- min = _normalizeSelection3[0],
3281
- max = _normalizeSelection3[1];
3282
-
3226
+ min = _normalizeSelection3[0],
3227
+ max = _normalizeSelection3[1];
3283
3228
  var _cellToPixel = cellToPixel(min),
3284
- left = _cellToPixel[0],
3285
- top = _cellToPixel[1];
3286
-
3229
+ left = _cellToPixel[0],
3230
+ top = _cellToPixel[1];
3287
3231
  var _cellToPixel2 = cellToPixel(max, ONE_ONE),
3288
- right = _cellToPixel2[0],
3289
- bottom = _cellToPixel2[1];
3290
-
3232
+ right = _cellToPixel2[0],
3233
+ bottom = _cellToPixel2[1];
3291
3234
  if (rowSelectionActive) {
3292
3235
  right = 1e5;
3293
3236
  }
3294
-
3295
3237
  if (columnSelectionActive) {
3296
3238
  bottom = 1e5;
3297
3239
  }
3298
-
3299
3240
  return [[left, top], [right, bottom]];
3300
3241
  };
3301
-
3302
- var resolveFrozenSelection = function resolveFrozenSelection(selection, cellLayout, freeze, indent, offset) {
3242
+ var resolveFrozenSelection = function resolveFrozenSelection(selection, cellLayout, freeze, offset) {
3303
3243
  var cellToPixel = cellLayout.cellToPixel,
3304
- columnToAbsolute = cellLayout.columnToAbsolute,
3305
- rowToAbsolute = cellLayout.rowToAbsolute;
3244
+ columnToAbsolute = cellLayout.columnToAbsolute,
3245
+ rowToAbsolute = cellLayout.rowToAbsolute;
3306
3246
  var rowSelectionActive = isRowSelection(selection);
3307
3247
  var columnSelectionActive = isColumnSelection(selection);
3308
3248
  var freezeX = freeze[0],
3309
- freezeY = freeze[1];
3310
- var indentX = indent[0],
3311
- indentY = indent[1];
3249
+ freezeY = freeze[1];
3312
3250
  var offsetX = offset[0],
3313
- offsetY = offset[1];
3314
-
3251
+ offsetY = offset[1];
3315
3252
  var _normalizeSelection4 = normalizeSelection(selection),
3316
- min = _normalizeSelection4[0],
3317
- max = _normalizeSelection4[1];
3318
-
3253
+ min = _normalizeSelection4[0],
3254
+ max = _normalizeSelection4[1];
3319
3255
  var minX = min[0],
3320
- minY = min[1];
3256
+ minY = min[1];
3321
3257
  var maxX = max[0],
3322
- maxY = max[1];
3323
-
3258
+ maxY = max[1];
3324
3259
  var _cellToPixel3 = cellToPixel(min),
3325
- left = _cellToPixel3[0],
3326
- top = _cellToPixel3[1];
3327
-
3260
+ left = _cellToPixel3[0],
3261
+ top = _cellToPixel3[1];
3328
3262
  var _cellToPixel4 = cellToPixel(max, ONE_ONE),
3329
- right = _cellToPixel4[0],
3330
- bottom = _cellToPixel4[1];
3331
-
3263
+ right = _cellToPixel4[0],
3264
+ bottom = _cellToPixel4[1];
3265
+ var indentX = columnToAbsolute(0);
3266
+ var indentY = rowToAbsolute(0);
3332
3267
  var frozenX = columnToAbsolute(freezeX);
3333
3268
  var frozenY = rowToAbsolute(freezeY);
3334
3269
  var hideKnob = false;
3335
-
3336
3270
  if (isInRangeCenter(freezeX, minX, maxX + 1)) {
3337
- var edge = indentX + frozenX;
3338
-
3271
+ var edge = frozenX;
3339
3272
  if (right <= edge) {
3340
3273
  right = edge;
3341
3274
  hideKnob = true;
3342
3275
  }
3343
3276
  }
3344
-
3345
3277
  if (isInRangeCenter(freezeY, minY, maxY + 1)) {
3346
- var _edge = indentY + frozenY;
3347
-
3278
+ var _edge = frozenY;
3348
3279
  if (bottom <= _edge) {
3349
3280
  bottom = _edge;
3350
3281
  hideKnob = true;
3351
3282
  }
3352
3283
  }
3353
-
3354
3284
  if (isInRangeLeft(minX, freezeX, offsetX + freezeX)) {
3355
3285
  left = -1e5;
3356
3286
  var lastInvisibleX = offsetX + freezeX - 1;
3357
-
3358
3287
  if (maxX <= lastInvisibleX) {
3359
3288
  if (maxX === lastInvisibleX) right = indentX;else right = -1e5;
3360
3289
  hideKnob = true;
3361
3290
  }
3362
3291
  }
3363
-
3364
3292
  if (isInRangeLeft(minY, freezeY, offsetY + freezeY)) {
3365
3293
  top = -1e5;
3366
3294
  var lastInvisibleY = offsetY + freezeY - 1;
3367
-
3368
3295
  if (maxY <= lastInvisibleY) {
3369
3296
  if (maxY === lastInvisibleY) bottom = indentY;else bottom = -1e5;
3370
3297
  hideKnob = true;
3371
3298
  }
3372
3299
  }
3373
-
3374
3300
  if (rowSelectionActive && offsetX > 0) {
3375
3301
  hideKnob = true;
3376
3302
  }
3377
-
3378
3303
  if (columnSelectionActive && offsetY > 0) {
3379
3304
  hideKnob = true;
3380
3305
  }
3381
-
3382
3306
  if (rowSelectionActive) {
3383
3307
  right = 1e5;
3384
3308
  }
3385
-
3386
3309
  if (columnSelectionActive) {
3387
3310
  bottom = 1e5;
3388
3311
  }
3389
-
3390
3312
  return [[[left, top], [right, bottom]], hideKnob];
3391
3313
  };
3392
-
3393
3314
  var resizeCanvas = function resizeCanvas(canvas) {
3394
3315
  var _canvas$getBoundingCl = canvas.getBoundingClientRect(),
3395
- width = _canvas$getBoundingCl.width,
3396
- height = _canvas$getBoundingCl.height;
3397
-
3316
+ width = _canvas$getBoundingCl.width,
3317
+ height = _canvas$getBoundingCl.height;
3398
3318
  var _window = window,
3399
- _window$devicePixelRa = _window.devicePixelRatio,
3400
- ratio = _window$devicePixelRa === void 0 ? 1 : _window$devicePixelRa;
3401
-
3319
+ _window$devicePixelRa = _window.devicePixelRatio,
3320
+ ratio = _window$devicePixelRa === void 0 ? 1 : _window$devicePixelRa;
3402
3321
  if (ratio < 1) {
3403
3322
  ratio = 1;
3404
3323
  }
3405
-
3406
3324
  var newCanvasWidth = Math.round(width * ratio);
3407
3325
  var newCanvasHeight = Math.round(height * ratio);
3408
-
3409
3326
  if (canvas.width !== newCanvasWidth || canvas.height !== newCanvasHeight) {
3410
3327
  var context = canvas.getContext('2d');
3411
-
3412
3328
  if (context) {
3413
3329
  canvas.width = newCanvasWidth;
3414
3330
  canvas.height = newCanvasHeight;
3415
3331
  context.scale(ratio, ratio);
3416
3332
  }
3417
3333
  }
3418
-
3419
- return ratio;
3420
3334
  };
3421
-
3422
3335
  var excelHeaderString = function excelHeaderString(num) {
3423
3336
  var s = '';
3424
3337
  var t = 0;
3425
-
3426
3338
  while (num > 0) {
3427
3339
  t = (num - 1) % 26;
3428
3340
  s = String.fromCharCode(65 + t) + s;
3429
3341
  num = (num - t) / 26 | 0;
3430
3342
  }
3431
-
3432
3343
  return s || '';
3433
3344
  };
3434
-
3435
3345
  var halfShadowGradient = function halfShadowGradient(gradient, rgb, opacity) {
3436
3346
  var hex = function hex(x) {
3437
3347
  return ('0' + Math.round(x).toString(16)).slice(-2);
3438
3348
  };
3439
-
3440
3349
  var ease = function ease(x) {
3441
3350
  return 1.0 - Math.sin(x * Math.PI / 2);
3442
3351
  };
3443
-
3444
3352
  var adjust = function adjust(x) {
3445
3353
  return 1.0 - Math.pow(1.0 - x, 2.2);
3446
3354
  };
3447
-
3448
3355
  for (var i = 0; i <= 16; ++i) {
3449
3356
  var f = i / 16;
3450
3357
  gradient.addColorStop(f, rgb + hex(adjust(opacity * ease(f) * 0.5) * 255));
3451
3358
  }
3452
3359
  };
3360
+ var getDpiNudge = function getDpiNudge() {
3361
+ var _window2 = window,
3362
+ devicePixelRatio = _window2.devicePixelRatio;
3363
+ return (devicePixelRatio - 1) / devicePixelRatio;
3364
+ };
3365
+ var roundDpi = function roundDpi(y) {
3366
+ var _window3 = window,
3367
+ devicePixelRatio = _window3.devicePixelRatio;
3368
+ return Math.round((y + getDpiNudge()) * devicePixelRatio) / devicePixelRatio;
3369
+ };
3370
+
3371
+ var resolveSheetStyle = function resolveSheetStyle(sheetStyle) {
3372
+ var _sheetStyle$shadowBlu, _sheetStyle$shadowOpa, _sheetStyle$shadowCol;
3373
+ return {
3374
+ freezeColumns: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.freezeColumns) || 0,
3375
+ freezeRows: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.freezeRows) || 0,
3376
+ hideColumnHeaders: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.hideColumnHeaders) || false,
3377
+ hideRowHeaders: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.hideRowHeaders) || false,
3378
+ hideGridlines: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.hideGridlines) || false,
3379
+ hideScrollBars: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.hideScrollBars) || false,
3380
+ shadowBlur: (_sheetStyle$shadowBlu = sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.shadowBlur) != null ? _sheetStyle$shadowBlu : SIZES.shadowBlur,
3381
+ shadowOpacity: (_sheetStyle$shadowOpa = sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.shadowOpacity) != null ? _sheetStyle$shadowOpa : SIZES.shadowOpacity,
3382
+ shadowColor: (_sheetStyle$shadowCol = sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.shadowColor) != null ? _sheetStyle$shadowCol : COLORS.shadowColor
3383
+ };
3384
+ };
3453
3385
 
3454
3386
  var Sheet = React.forwardRef(function (props, ref) {
3455
3387
  var _props$selection, _props$secondarySelec, _props$cacheLayout, _props$inputComponent;
3456
-
3457
3388
  var canvasRef = React.useRef(null);
3458
3389
  var overlayRef = React.useRef(null);
3459
-
3460
3390
  var _useState = React.useState(INITIAL_MAX_SCROLL),
3461
- maxScroll = _useState[0],
3462
- setMaxScroll = _useState[1];
3463
-
3391
+ maxScroll = _useState[0],
3392
+ setMaxScroll = _useState[1];
3464
3393
  var _useState2 = React.useState(ORIGIN),
3465
- dataOffset = _useState2[0],
3466
- setDataOffset = _useState2[1];
3467
-
3394
+ dataOffset = _useState2[0],
3395
+ setDataOffset = _useState2[1];
3468
3396
  var selectionProp = (_props$selection = props.selection) != null ? _props$selection : NO_SELECTION;
3469
-
3470
3397
  var _useState3 = React.useState(selectionProp),
3471
- rawSelection = _useState3[0],
3472
- setRawSelection = _useState3[1];
3473
-
3398
+ rawSelection = _useState3[0],
3399
+ setRawSelection = _useState3[1];
3474
3400
  var _useState4 = React.useState(null),
3475
- knobArea = _useState4[0],
3476
- setKnobArea = _useState4[1];
3477
-
3401
+ knobArea = _useState4[0],
3402
+ setKnobArea = _useState4[1];
3478
3403
  var _useState5 = React.useState(null),
3479
- dragOffset = _useState5[0],
3480
- setDragOffset = _useState5[1];
3481
-
3404
+ dragOffset = _useState5[0],
3405
+ setDragOffset = _useState5[1];
3482
3406
  var _useState6 = React.useState([null, null]),
3483
- dragIndices = _useState6[0],
3484
- setDragIndices = _useState6[1];
3485
-
3407
+ dragIndices = _useState6[0],
3408
+ setDragIndices = _useState6[1];
3486
3409
  var _useState7 = React.useState(null),
3487
- dropTarget = _useState7[0],
3488
- setDropTarget = _useState7[1];
3489
-
3410
+ dropTarget = _useState7[0],
3411
+ setDropTarget = _useState7[1];
3490
3412
  var _useState8 = React.useState(NO_CELL),
3491
- editCell = _useState8[0],
3492
- setEditCell = _useState8[1];
3493
-
3413
+ editCell = _useState8[0],
3414
+ setEditCell = _useState8[1];
3494
3415
  var _useState9 = React.useState(!!props.autoFocus),
3495
- focused = _useState9[0],
3496
- setFocused = _useState9[1];
3497
-
3416
+ focused = _useState9[0],
3417
+ setFocused = _useState9[1];
3498
3418
  var _useState10 = React.useState(selectionProp),
3499
- lastSelectionProp = _useState10[0],
3500
- setLastSelectionProp = _useState10[1];
3501
-
3419
+ lastSelectionProp = _useState10[0],
3420
+ setLastSelectionProp = _useState10[1];
3502
3421
  if (lastSelectionProp !== selectionProp) {
3503
3422
  setLastSelectionProp(selectionProp);
3504
3423
  setRawSelection(selectionProp);
3505
3424
  }
3506
-
3507
3425
  var _useState11 = React.useState(''),
3508
- editValue = _useState11[0],
3509
- setEditValue = _useState11[1];
3510
-
3426
+ editValue = _useState11[0],
3427
+ setEditValue = _useState11[1];
3511
3428
  var _useState12 = React.useState(false),
3512
- arrowKeyCommitMode = _useState12[0],
3513
- setArrowKeyCommitMode = _useState12[1];
3514
-
3429
+ arrowKeyCommitMode = _useState12[0],
3430
+ setArrowKeyCommitMode = _useState12[1];
3515
3431
  var _useResizeObserver = useResizeObserver({
3516
- ref: overlayRef
3517
- }),
3518
- _useResizeObserver$wi = _useResizeObserver.width,
3519
- canvasWidth = _useResizeObserver$wi === void 0 ? 3000 : _useResizeObserver$wi,
3520
- _useResizeObserver$he = _useResizeObserver.height,
3521
- canvasHeight = _useResizeObserver$he === void 0 ? 3000 : _useResizeObserver$he;
3522
-
3432
+ ref: overlayRef
3433
+ }),
3434
+ _useResizeObserver$wi = _useResizeObserver.width,
3435
+ canvasWidth = _useResizeObserver$wi === void 0 ? 3000 : _useResizeObserver$wi,
3436
+ _useResizeObserver$he = _useResizeObserver.height,
3437
+ canvasHeight = _useResizeObserver$he === void 0 ? 3000 : _useResizeObserver$he;
3523
3438
  var cellWidth = React.useMemo(function () {
3524
3439
  return createRowOrColumnProp(props.cellWidth, 100);
3525
3440
  }, [props.cellWidth]);
@@ -3590,9 +3505,9 @@ var Sheet = React.forwardRef(function (props, ref) {
3590
3505
  })) : null;
3591
3506
  }, [props.rowGroupKeys, rowGroupKeys, selection]);
3592
3507
  var maxScrollX = maxScroll[0],
3593
- maxScrollY = maxScroll[1];
3508
+ maxScrollY = maxScroll[1];
3594
3509
  var editCellX = editCell[0],
3595
- editCellY = editCell[1];
3510
+ editCellY = editCell[1];
3596
3511
  var editMode = editCellX !== -1 && editCellY !== -1;
3597
3512
  var shouldCacheLayout = ((_props$cacheLayout = props.cacheLayout) != null ? _props$cacheLayout : false) !== false;
3598
3513
  var layoutVersion = typeof props.cacheLayout === 'number' ? props.cacheLayout : 0;
@@ -3608,15 +3523,13 @@ var Sheet = React.forwardRef(function (props, ref) {
3608
3523
  rowLayout.setSizer(cellHeight);
3609
3524
  }, [shouldCacheLayout, layoutVersion, cellWidth, cellHeight]);
3610
3525
  var freezeColumns = sheetStyle.freezeColumns,
3611
- freezeRows = sheetStyle.freezeRows,
3612
- rowHeaderWidth = sheetStyle.rowHeaderWidth,
3613
- columnHeaderHeight = sheetStyle.columnHeaderHeight;
3526
+ freezeRows = sheetStyle.freezeRows;
3614
3527
  var cellLayout = React.useMemo(function () {
3615
- return makeCellLayout([freezeColumns, freezeRows], [rowHeaderWidth, columnHeaderHeight], dataOffset, columnLayout, rowLayout);
3616
- }, [freezeColumns, freezeRows, rowHeaderWidth, columnHeaderHeight, dataOffset, columnLayout, rowLayout]);
3528
+ return makeCellLayout([freezeColumns, freezeRows], dataOffset, columnLayout, rowLayout);
3529
+ }, [freezeColumns, freezeRows, dataOffset, columnLayout, rowLayout]);
3617
3530
  var getVisibleCells = cellLayout.getVisibleCells,
3618
- cellToPixel = cellLayout.cellToPixel,
3619
- getVersion = cellLayout.getVersion;
3531
+ cellToPixel = cellLayout.cellToPixel,
3532
+ getVersion = cellLayout.getVersion;
3620
3533
  var visibleCells = React.useMemo(function () {
3621
3534
  return getVisibleCells([canvasWidth, canvasHeight]);
3622
3535
  }, [getVisibleCells, canvasWidth, canvasHeight, getVersion()]);
@@ -3625,16 +3538,14 @@ var Sheet = React.forwardRef(function (props, ref) {
3625
3538
  props.onScrollChange([].concat(visibleCells.rows), [].concat(visibleCells.columns));
3626
3539
  }
3627
3540
  }, [visibleCells, props.onScrollChange]);
3628
-
3629
3541
  var scrollToSelection = function scrollToSelection(selection, toHead) {
3630
3542
  if (toHead === void 0) {
3631
3543
  toHead = false;
3632
3544
  }
3633
-
3634
3545
  var overlay = overlayRef.current;
3635
3546
  if (!overlay) return;
3636
3547
  var anchor = selection[0],
3637
- head = selection[1];
3548
+ head = selection[1];
3638
3549
  var view = [canvasWidth, canvasHeight];
3639
3550
  var freeze = [freezeColumns, freezeRows];
3640
3551
  scrollToCell(overlay, toHead ? head : anchor, view, freeze, dataOffset, maxScroll, cellLayout, function (dataOffset, maxScroll) {
@@ -3642,89 +3553,72 @@ var Sheet = React.forwardRef(function (props, ref) {
3642
3553
  setMaxScroll(maxScroll);
3643
3554
  });
3644
3555
  };
3645
-
3646
3556
  var changeSelection = function changeSelection(newSelection, scrollTo, toHead) {
3647
3557
  if (scrollTo === void 0) {
3648
3558
  scrollTo = true;
3649
3559
  }
3650
-
3651
3560
  if (toHead === void 0) {
3652
3561
  toHead = false;
3653
3562
  }
3654
-
3655
- if (!isSameSelection(selection, newSelection)) {
3563
+ if (!isSameRectangle(selection, newSelection)) {
3656
3564
  setRawSelection(newSelection);
3657
3565
  }
3658
-
3659
3566
  var overlay = overlayRef.current;
3660
3567
  if (!overlay) return;
3661
-
3662
3568
  if (scrollTo) {
3663
3569
  scrollToSelection(newSelection, toHead);
3664
3570
  }
3665
-
3666
3571
  if (props.onSelectionChanged) {
3667
3572
  var _normalizeSelection = normalizeSelection(validateSelection(newSelection)),
3668
- _normalizeSelection$ = _normalizeSelection[0],
3669
- minX = _normalizeSelection$[0],
3670
- minY = _normalizeSelection$[1],
3671
- _normalizeSelection$2 = _normalizeSelection[1],
3672
- maxX = _normalizeSelection$2[0],
3673
- maxY = _normalizeSelection$2[1];
3674
-
3573
+ _normalizeSelection$ = _normalizeSelection[0],
3574
+ minX = _normalizeSelection$[0],
3575
+ minY = _normalizeSelection$[1],
3576
+ _normalizeSelection$2 = _normalizeSelection[1],
3577
+ maxX = _normalizeSelection$2[0],
3578
+ maxY = _normalizeSelection$2[1];
3675
3579
  props.onSelectionChanged(minX, minY, maxX, maxY);
3676
3580
  }
3677
3581
  };
3678
-
3679
3582
  var cancelEditingCell = function cancelEditingCell() {
3680
3583
  setEditCell(NO_CELL);
3681
3584
  setFocused(true);
3682
3585
  };
3683
-
3684
3586
  var commitEditingCell = function commitEditingCell(value) {
3685
3587
  if (props.onChange) {
3686
3588
  var cellX = editCell[0],
3687
- cellY = editCell[1];
3589
+ cellY = editCell[1];
3688
3590
  props.onChange([{
3689
3591
  x: cellX,
3690
3592
  y: cellY,
3691
3593
  value: value !== undefined ? value : editValue
3692
3594
  }]);
3693
3595
  }
3694
-
3695
3596
  setEditCell(NO_CELL);
3696
3597
  setFocused(true);
3697
3598
  };
3698
-
3699
3599
  var startEditingCell = function startEditingCell(editCell, arrowKeyCommitMode) {
3700
3600
  if (arrowKeyCommitMode === void 0) {
3701
3601
  arrowKeyCommitMode = false;
3702
3602
  }
3703
-
3704
3603
  var cellX = editCell[0],
3705
- cellY = editCell[1];
3706
-
3604
+ cellY = editCell[1];
3707
3605
  if (cellReadOnly(cellX, cellY)) {
3708
3606
  return;
3709
3607
  }
3710
-
3711
3608
  var editDataValue = editData(cellX, cellY);
3712
3609
  var val = '';
3713
-
3714
3610
  if (editDataValue !== null && editDataValue !== undefined) {
3715
3611
  val = editDataValue;
3716
3612
  }
3717
-
3718
3613
  setEditCell(editCell);
3719
3614
  setEditValue(val);
3720
3615
  setArrowKeyCommitMode(arrowKeyCommitMode);
3721
3616
  setLastEditKey(editKeys.apply(void 0, editCell));
3722
3617
  };
3723
-
3724
3618
  var _props$maxColumns = props.maxColumns,
3725
- maxColumns = _props$maxColumns === void 0 ? Infinity : _props$maxColumns,
3726
- _props$maxRows = props.maxRows,
3727
- maxRows = _props$maxRows === void 0 ? Infinity : _props$maxRows;
3619
+ maxColumns = _props$maxColumns === void 0 ? Infinity : _props$maxColumns,
3620
+ _props$maxRows = props.maxRows,
3621
+ maxRows = _props$maxRows === void 0 ? Infinity : _props$maxRows;
3728
3622
  React.useLayoutEffect(function () {
3729
3623
  var overlay = overlayRef.current;
3730
3624
  if (!overlay) return;
@@ -3736,72 +3630,71 @@ var Sheet = React.forwardRef(function (props, ref) {
3736
3630
  }, [maxRows, maxColumns]);
3737
3631
  var hitmapRef = React.useRef(NO_CLICKABLES);
3738
3632
  var isFocused = focused || editMode;
3739
-
3740
3633
  var _useClipboardAPI = useClipboardAPI(selection, editData, cellReadOnly, isFocused && !editMode, changeSelection, props.onChange, props.onCopy, props.onPaste),
3741
- clipboardApi = _useClipboardAPI.clipboardApi,
3742
- onClipboardCopy = _useClipboardAPI.onClipboardCopy;
3743
-
3634
+ clipboardApi = _useClipboardAPI.clipboardApi,
3635
+ onClipboardCopy = _useClipboardAPI.onClipboardCopy;
3744
3636
  var onScroll = useScroll(dataOffset, maxScroll, cellLayout, setDataOffset, setMaxScroll);
3745
- var getAutoSizeWidth = useAutoSizeColumn(visibleCells.rows, displayData, cellStyle, columnHeaders, columnHeaderStyle, canvasWidth);
3746
-
3747
- var _useMouse = useMouse(hitmapRef, selection, knobArea, editMode, editData, sourceData, cellReadOnly, canSizeColumn, canSizeRow, canOrderColumn, canOrderRow, cellLayout, visibleCells, sheetStyle, columnGroupKeys, rowGroupKeys, selectedColumnGroups, selectedRowGroups, getAutoSizeWidth, startEditingCell, commitEditingCell, setKnobArea, setDragIndices, setDragOffset, setDropTarget, changeSelection, setFocused, props.cacheLayout ? columnLayout.clearAfter : undefined, props.cacheLayout ? rowLayout.clearAfter : undefined, props.onChange, props.onColumnOrderChange, props.onRowOrderChange, props.onCellWidthChange, props.onCellHeightChange, props.onRightClick, props.dontCommitEditOnSelectionChange, props.dontChangeSelectionOnOrderChange),
3748
- mouseHandlers = _useMouse.mouseHandlers,
3749
- knobPosition = _useMouse.knobPosition;
3750
-
3637
+ var getAutoSizeWidth = useAutoSizeColumn(visibleCells.rows, displayData, cellLayout, cellStyle, columnHeaders, columnHeaderStyle, canvasWidth, freezeColumns);
3638
+ var getAutoSizeHeight = useAutoSizeRow(visibleCells.columns, displayData, cellLayout, cellStyle, columnHeaders, columnHeaderStyle, cellWidth, canvasHeight, freezeRows);
3639
+ 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),
3640
+ mouseHandlers = _useMouse.mouseHandlers,
3641
+ knobPosition = _useMouse.knobPosition;
3751
3642
  var _useKeyboard = useKeyboard(arrowKeyCommitMode, overlayRef, cellReadOnly, displayData, editCell, editMode, focused, rawSelection, selection, startEditingCell, commitEditingCell, cancelEditingCell, changeSelection, setFocused, onClipboardCopy, props.onChange),
3752
- onInputKeyDown = _useKeyboard.onInputKeyDown,
3753
- onGridKeyDown = _useKeyboard.onGridKeyDown,
3754
- onGridFocus = _useKeyboard.onGridFocus,
3755
- onGridBlur = _useKeyboard.onGridBlur;
3756
-
3643
+ onInputKeyDown = _useKeyboard.onInputKeyDown,
3644
+ onGridKeyDown = _useKeyboard.onGridKeyDown,
3645
+ onGridFocus = _useKeyboard.onGridFocus,
3646
+ onGridBlur = _useKeyboard.onGridBlur;
3647
+ var imageRenderer = useImageRenderer();
3757
3648
  React.useLayoutEffect(function () {
3758
3649
  var canvas = canvasRef.current;
3759
-
3760
3650
  if (!canvas) {
3761
3651
  return;
3762
3652
  }
3763
-
3764
3653
  var context = canvas.getContext('2d');
3765
-
3766
3654
  if (!context) {
3767
3655
  return;
3768
3656
  }
3769
-
3770
3657
  var animationFrameId = window.requestAnimationFrame(function () {
3771
- hitmapRef.current = renderSheet(context, cellLayout, visibleCells, sheetStyle, cellStyle, selection, secondarySelections, isFocused, knobPosition, knobArea, dragIndices, dragOffset, dropTarget, columnHeaders, columnHeaderStyle, displayData, columnGroupKeys, rowGroupKeys, selectedColumnGroups, selectedRowGroups, dataOffset);
3658
+ hitmapRef.current = renderSheet(context, imageRenderer, cellLayout, visibleCells, sheetStyle, cellStyle, selection, secondarySelections, isFocused, knobPosition, knobArea, dragIndices, dragOffset, dropTarget, columnHeaders, columnHeaderStyle, displayData, columnGroupKeys, rowGroupKeys, selectedColumnGroups, selectedRowGroups, dataOffset);
3772
3659
  });
3773
3660
  return function () {
3774
3661
  window.cancelAnimationFrame(animationFrameId);
3775
3662
  };
3776
3663
  }, [cellLayout, visibleCells, sheetStyle, cellStyle, selection, secondarySelections, isFocused, knobPosition, knobArea, dragOffset, dropTarget, columnHeaders, columnHeaderStyle, displayData, columnGroupKeys, rowGroupKeys, selectedColumnGroups, selectedRowGroups, dataOffset]);
3777
-
3778
3664
  var _useState13 = React.useState(''),
3779
- lastEditKey = _useState13[0],
3780
- setLastEditKey = _useState13[1];
3781
-
3665
+ lastEditKey = _useState13[0],
3666
+ setLastEditKey = _useState13[1];
3782
3667
  var editTextPosition = ORIGIN;
3783
3668
  var editTextWidth = 0;
3784
3669
  var editTextHeight = 0;
3785
- var editTextTextAlign = 'right';
3786
-
3670
+ var editTextAlign = 'right';
3671
+ var editTextLineHeight = '';
3672
+ var editTextMargin = '';
3673
+ var editTextFontSize = DEFAULT_CELL_STYLE.fontSize;
3674
+ var editTextFontFamily = DEFAULT_CELL_STYLE.fontFamily;
3675
+ var editTextFontWeight = DEFAULT_CELL_STYLE.fontWeight;
3787
3676
  if (editMode) {
3788
- var style = cellStyle.apply(void 0, editCell);
3677
+ var style = _extends({}, DEFAULT_CELL_STYLE, cellStyle.apply(void 0, editCell));
3789
3678
  editTextPosition = cellToPixel(editCell);
3790
3679
  editTextPosition = addXY(editTextPosition, ONE_ONE);
3791
3680
  editTextWidth = cellWidth(editCellX) - 3;
3792
3681
  editTextHeight = cellHeight(editCellY) - 3;
3793
- editTextTextAlign = style.textAlign || DEFAULT_CELL_STYLE.textAlign || 'left';
3682
+ editTextAlign = style.textAlign;
3683
+ editTextLineHeight = style.lineHeight + "px";
3684
+ editTextFontSize = style.fontSize;
3685
+ editTextFontFamily = style.fontFamily;
3686
+ editTextFontWeight = style.fontWeight;
3687
+ var yNudge = getDpiNudge();
3688
+ editTextMargin = style.marginTop - 1 + yNudge + "px " + (style.marginRight - 2) + "px " + (style.marginBottom - 2) + "px " + (style.marginLeft - 1) + "px";
3794
3689
  var editKey = editKeys.apply(void 0, editCell);
3795
-
3796
3690
  if (editKey !== lastEditKey) {
3797
3691
  setLastEditKey('');
3798
3692
  setEditCell(NO_CELL);
3799
3693
  }
3800
3694
  }
3801
-
3802
3695
  var _editTextPosition = editTextPosition,
3803
- textX = _editTextPosition[0],
3804
- textY = _editTextPosition[1];
3696
+ textX = _editTextPosition[0],
3697
+ textY = _editTextPosition[1];
3805
3698
  var inputProps = {
3806
3699
  value: editValue,
3807
3700
  autoFocus: true,
@@ -3810,15 +3703,18 @@ var Sheet = React.forwardRef(function (props, ref) {
3810
3703
  position: 'absolute',
3811
3704
  left: textX,
3812
3705
  top: textY,
3813
- padding: '0px 4px',
3706
+ padding: editTextMargin,
3814
3707
  width: editTextWidth,
3815
3708
  height: editTextHeight,
3816
3709
  outline: 'none',
3817
3710
  border: 'none',
3818
- textAlign: editTextTextAlign,
3711
+ textAlign: editTextAlign,
3712
+ lineHeight: editTextLineHeight,
3819
3713
  color: 'black',
3820
- fontSize: DEFAULT_CELL_STYLE.fontSize,
3821
- fontFamily: 'sans-serif'
3714
+ fontSize: editTextFontSize,
3715
+ fontFamily: editTextFontFamily,
3716
+ fontWeight: editTextFontWeight,
3717
+ resize: 'none'
3822
3718
  }
3823
3719
  };
3824
3720
  var input = (_props$inputComponent = props.inputComponent) === null || _props$inputComponent === void 0 ? void 0 : _props$inputComponent.call(props, editCellX, editCellY, _extends({}, inputProps, {
@@ -3840,16 +3736,13 @@ var Sheet = React.forwardRef(function (props, ref) {
3840
3736
  height: canvasHeight,
3841
3737
  outline: '1px solid #ddd'
3842
3738
  };
3843
-
3844
3739
  if (sheetStyle.hideScrollBars) {
3845
3740
  delete canvasStyles['outline'];
3846
3741
  delete overlayDivStyles['borderBottom'];
3847
3742
  overlayDivClassName = '';
3848
3743
  }
3849
-
3850
3744
  var renderedInside = React.useMemo(function () {
3851
3745
  var _props$renderInside;
3852
-
3853
3746
  return (_props$renderInside = props.renderInside) === null || _props$renderInside === void 0 ? void 0 : _props$renderInside.call(props, {
3854
3747
  visibleCells: visibleCells,
3855
3748
  cellLayout: cellLayout,
@@ -3859,7 +3752,6 @@ var Sheet = React.forwardRef(function (props, ref) {
3859
3752
  }, [props.renderInside, visibleCells, cellLayout, selection, editMode]);
3860
3753
  var renderedOutside = React.useMemo(function () {
3861
3754
  var _props$renderOutside;
3862
-
3863
3755
  return (_props$renderOutside = props.renderOutside) === null || _props$renderOutside === void 0 ? void 0 : _props$renderOutside.call(props, {
3864
3756
  visibleCells: visibleCells,
3865
3757
  cellLayout: cellLayout,
@@ -3924,8 +3816,7 @@ var Sheet = React.forwardRef(function (props, ref) {
3924
3816
  height: '100%',
3925
3817
  pointerEvents: 'none'
3926
3818
  }
3927
- }, renderedOutside) : null, editMode && (input !== undefined ? input : React__default.createElement("input", Object.assign({}, inputProps, {
3928
- type: "text",
3819
+ }, renderedOutside) : null, editMode && (input !== undefined ? input : React__default.createElement("textarea", Object.assign({}, inputProps, {
3929
3820
  onFocus: function onFocus(e) {
3930
3821
  return e.target.select();
3931
3822
  },
@@ -3936,5 +3827,6 @@ var Sheet = React.forwardRef(function (props, ref) {
3936
3827
  });
3937
3828
 
3938
3829
  exports.default = Sheet;
3830
+ exports.svgToImage = svgToImage;
3939
3831
  exports.useClipboardTable = useClipboardTable;
3940
3832
  //# sourceMappingURL=index.js.map