@deephaven/grid 0.5.2-beta.0 → 0.6.1-demo.8

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.
Files changed (76) hide show
  1. package/dist/CellInputField.js +40 -88
  2. package/dist/CellInputField.js.map +1 -1
  3. package/dist/Grid.js +1449 -1484
  4. package/dist/Grid.js.map +1 -1
  5. package/dist/GridColorUtils.js +18 -51
  6. package/dist/GridColorUtils.js.map +1 -1
  7. package/dist/GridMetricCalculator.d.ts +8 -1
  8. package/dist/GridMetricCalculator.d.ts.map +1 -1
  9. package/dist/GridMetricCalculator.js +1031 -994
  10. package/dist/GridMetricCalculator.js.map +1 -1
  11. package/dist/GridModel.d.ts +4 -1
  12. package/dist/GridModel.d.ts.map +1 -1
  13. package/dist/GridModel.js +175 -286
  14. package/dist/GridModel.js.map +1 -1
  15. package/dist/GridMouseHandler.js +39 -59
  16. package/dist/GridMouseHandler.js.map +1 -1
  17. package/dist/GridRange.js +572 -630
  18. package/dist/GridRange.js.map +1 -1
  19. package/dist/GridRenderer.js +1650 -1564
  20. package/dist/GridRenderer.js.map +1 -1
  21. package/dist/GridTestUtils.js +15 -29
  22. package/dist/GridTestUtils.js.map +1 -1
  23. package/dist/GridUtils.js +679 -717
  24. package/dist/GridUtils.js.map +1 -1
  25. package/dist/KeyHandler.js +6 -18
  26. package/dist/KeyHandler.js.map +1 -1
  27. package/dist/MockGridModel.js +105 -210
  28. package/dist/MockGridModel.js.map +1 -1
  29. package/dist/MockTreeGridModel.js +113 -183
  30. package/dist/MockTreeGridModel.js.map +1 -1
  31. package/dist/errors/PasteError.js +5 -44
  32. package/dist/errors/PasteError.js.map +1 -1
  33. package/dist/errors/index.js +1 -1
  34. package/dist/errors/index.js.map +1 -1
  35. package/dist/index.js +15 -15
  36. package/dist/index.js.map +1 -1
  37. package/dist/key-handlers/EditKeyHandler.js +42 -75
  38. package/dist/key-handlers/EditKeyHandler.js.map +1 -1
  39. package/dist/key-handlers/PasteKeyHandler.js +42 -78
  40. package/dist/key-handlers/PasteKeyHandler.js.map +1 -1
  41. package/dist/key-handlers/SelectionKeyHandler.d.ts.map +1 -1
  42. package/dist/key-handlers/SelectionKeyHandler.js +239 -229
  43. package/dist/key-handlers/SelectionKeyHandler.js.map +1 -1
  44. package/dist/key-handlers/TreeKeyHandler.js +42 -72
  45. package/dist/key-handlers/TreeKeyHandler.js.map +1 -1
  46. package/dist/key-handlers/index.js +4 -4
  47. package/dist/key-handlers/index.js.map +1 -1
  48. package/dist/memoizeClear.js +1 -1
  49. package/dist/memoizeClear.js.map +1 -1
  50. package/dist/mouse-handlers/EditMouseHandler.js +18 -50
  51. package/dist/mouse-handlers/EditMouseHandler.js.map +1 -1
  52. package/dist/mouse-handlers/GridColumnMoveMouseHandler.d.ts.map +1 -1
  53. package/dist/mouse-handlers/GridColumnMoveMouseHandler.js +141 -163
  54. package/dist/mouse-handlers/GridColumnMoveMouseHandler.js.map +1 -1
  55. package/dist/mouse-handlers/GridColumnSeparatorMouseHandler.js +47 -86
  56. package/dist/mouse-handlers/GridColumnSeparatorMouseHandler.js.map +1 -1
  57. package/dist/mouse-handlers/GridHorizontalScrollBarMouseHandler.js +145 -171
  58. package/dist/mouse-handlers/GridHorizontalScrollBarMouseHandler.js.map +1 -1
  59. package/dist/mouse-handlers/GridRowMoveMouseHandler.js +125 -147
  60. package/dist/mouse-handlers/GridRowMoveMouseHandler.js.map +1 -1
  61. package/dist/mouse-handlers/GridRowSeparatorMouseHandler.js +47 -86
  62. package/dist/mouse-handlers/GridRowSeparatorMouseHandler.js.map +1 -1
  63. package/dist/mouse-handlers/GridRowTreeMouseHandler.js +46 -76
  64. package/dist/mouse-handlers/GridRowTreeMouseHandler.js.map +1 -1
  65. package/dist/mouse-handlers/GridScrollBarCornerMouseHandler.js +31 -62
  66. package/dist/mouse-handlers/GridScrollBarCornerMouseHandler.js.map +1 -1
  67. package/dist/mouse-handlers/GridSelectionMouseHandler.js +200 -222
  68. package/dist/mouse-handlers/GridSelectionMouseHandler.js.map +1 -1
  69. package/dist/mouse-handlers/GridSeparatorMouseHandler.js +206 -253
  70. package/dist/mouse-handlers/GridSeparatorMouseHandler.js.map +1 -1
  71. package/dist/mouse-handlers/GridVerticalScrollBarMouseHandler.js +146 -172
  72. package/dist/mouse-handlers/GridVerticalScrollBarMouseHandler.js.map +1 -1
  73. package/dist/mouse-handlers/index.js +10 -10
  74. package/dist/mouse-handlers/index.js.map +1 -1
  75. package/dist/tsconfig.tsbuildinfo +1 -1
  76. package/package.json +6 -10
@@ -1,90 +1,57 @@
1
- function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
2
-
3
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
4
-
5
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
6
-
7
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
8
-
9
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
10
-
11
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
12
-
13
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
14
-
15
- function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
16
-
17
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
18
-
19
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
20
-
21
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
22
-
23
1
  /* eslint class-methods-use-this: "off" */
24
- import GridUtils from '../GridUtils';
25
- import GridRange from '../GridRange';
26
- import KeyHandler from '../KeyHandler';
27
-
28
- var EditKeyHandler = /*#__PURE__*/function (_KeyHandler) {
29
- _inherits(EditKeyHandler, _KeyHandler);
2
+ import GridUtils from "../GridUtils.js";
3
+ import GridRange from "../GridRange.js";
4
+ import KeyHandler from "../KeyHandler.js";
30
5
 
31
- var _super = _createSuper(EditKeyHandler);
32
-
33
- function EditKeyHandler() {
34
- _classCallCheck(this, EditKeyHandler);
35
-
36
- return _super.apply(this, arguments);
37
- }
38
-
39
- _createClass(EditKeyHandler, [{
40
- key: "onDown",
41
- value: function onDown(e, grid) {
42
- if (GridUtils.isModifierKeyDown(e)) {
43
- return false;
44
- }
45
-
46
- var model = grid.props.model;
47
- var _grid$state = grid.state,
48
- cursorColumn = _grid$state.cursorColumn,
49
- cursorRow = _grid$state.cursorRow;
6
+ class EditKeyHandler extends KeyHandler {
7
+ onDown(e, grid) {
8
+ if (GridUtils.isModifierKeyDown(e)) {
9
+ return false;
10
+ }
50
11
 
51
- if (cursorColumn == null || cursorRow == null || !model.isEditableRange(GridRange.makeCell(cursorColumn, cursorRow))) {
52
- return false;
53
- }
12
+ var {
13
+ model
14
+ } = grid.props;
15
+ var {
16
+ cursorColumn,
17
+ cursorRow
18
+ } = grid.state;
54
19
 
55
- var column = cursorColumn;
56
- var row = cursorRow;
20
+ if (cursorColumn == null || cursorRow == null || !model.isEditableRange(GridRange.makeCell(cursorColumn, cursorRow))) {
21
+ return false;
22
+ }
57
23
 
58
- if (column == null || row == null) {
59
- return false;
60
- }
24
+ var column = cursorColumn;
25
+ var row = cursorRow;
61
26
 
62
- if (e.key.length === 1) {
63
- grid.startEditing(column, row, true, [1, 1], e.key);
64
- return true;
65
- }
27
+ if (column == null || row == null) {
28
+ return false;
29
+ }
66
30
 
67
- if (e.key === 'F2') {
68
- grid.startEditing(column, row);
69
- return true;
70
- }
31
+ if (e.key.length === 1) {
32
+ grid.startEditing(column, row, true, [1, 1], e.key);
33
+ return true;
34
+ }
71
35
 
72
- if (e.key === 'Backspace') {
73
- grid.startEditing(column, row, true, null, '');
74
- return true;
75
- }
36
+ if (e.key === 'F2') {
37
+ grid.startEditing(column, row);
38
+ return true;
39
+ }
76
40
 
77
- if (e.key === 'Delete') {
78
- grid.setValueForCell(column, row, '');
79
- return true;
80
- }
41
+ if (e.key === 'Backspace') {
42
+ grid.startEditing(column, row, true, null, '');
43
+ return true;
44
+ }
81
45
 
82
- return false;
46
+ if (e.key === 'Delete') {
47
+ grid.setValueForCell(column, row, '');
48
+ return true;
83
49
  }
84
- }]);
85
50
 
86
- return EditKeyHandler;
87
- }(KeyHandler);
51
+ return false;
52
+ }
53
+
54
+ }
88
55
 
89
56
  export default EditKeyHandler;
90
57
  //# sourceMappingURL=EditKeyHandler.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/key-handlers/EditKeyHandler.ts"],"names":["GridUtils","GridRange","KeyHandler","EditKeyHandler","e","grid","isModifierKeyDown","model","props","state","cursorColumn","cursorRow","isEditableRange","makeCell","column","row","key","length","startEditing","setValueForCell"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA;AACA,OAAOA,SAAP,MAAsB,cAAtB;AAEA,OAAOC,SAAP,MAAsB,cAAtB;AACA,OAAOC,UAAP,MAAuB,eAAvB;;IAEMC,c;;;;;;;;;;;;;WACJ,gBAAOC,CAAP,EAAyBC,IAAzB,EAA8C;AAC5C,UAAIL,SAAS,CAACM,iBAAV,CAA4BF,CAA5B,CAAJ,EAAoC;AAClC,eAAO,KAAP;AACD;;AAED,UAAQG,KAAR,GAAkBF,IAAI,CAACG,KAAvB,CAAQD,KAAR;AACA,wBAAoCF,IAAI,CAACI,KAAzC;AAAA,UAAQC,YAAR,eAAQA,YAAR;AAAA,UAAsBC,SAAtB,eAAsBA,SAAtB;;AACA,UACED,YAAY,IAAI,IAAhB,IACAC,SAAS,IAAI,IADb,IAEA,CAACJ,KAAK,CAACK,eAAN,CAAsBX,SAAS,CAACY,QAAV,CAAmBH,YAAnB,EAAiCC,SAAjC,CAAtB,CAHH,EAIE;AACA,eAAO,KAAP;AACD;;AACD,UAAMG,MAAqB,GAAGJ,YAA9B;AACA,UAAMK,GAAkB,GAAGJ,SAA3B;;AACA,UAAIG,MAAM,IAAI,IAAV,IAAkBC,GAAG,IAAI,IAA7B,EAAmC;AACjC,eAAO,KAAP;AACD;;AAED,UAAIX,CAAC,CAACY,GAAF,CAAMC,MAAN,KAAiB,CAArB,EAAwB;AACtBZ,QAAAA,IAAI,CAACa,YAAL,CAAkBJ,MAAlB,EAA0BC,GAA1B,EAA+B,IAA/B,EAAqC,CAAC,CAAD,EAAI,CAAJ,CAArC,EAA6CX,CAAC,CAACY,GAA/C;AACA,eAAO,IAAP;AACD;;AAED,UAAIZ,CAAC,CAACY,GAAF,KAAU,IAAd,EAAoB;AAClBX,QAAAA,IAAI,CAACa,YAAL,CAAkBJ,MAAlB,EAA0BC,GAA1B;AACA,eAAO,IAAP;AACD;;AAED,UAAIX,CAAC,CAACY,GAAF,KAAU,WAAd,EAA2B;AACzBX,QAAAA,IAAI,CAACa,YAAL,CAAkBJ,MAAlB,EAA0BC,GAA1B,EAA+B,IAA/B,EAAqC,IAArC,EAA2C,EAA3C;AACA,eAAO,IAAP;AACD;;AAED,UAAIX,CAAC,CAACY,GAAF,KAAU,QAAd,EAAwB;AACtBX,QAAAA,IAAI,CAACc,eAAL,CAAqBL,MAArB,EAA6BC,GAA7B,EAAkC,EAAlC;AACA,eAAO,IAAP;AACD;;AACD,aAAO,KAAP;AACD;;;;EAzC0Bb,U;;AA4C7B,eAAeC,cAAf","sourcesContent":["/* eslint class-methods-use-this: \"off\" */\nimport GridUtils from '../GridUtils';\nimport Grid from '../Grid';\nimport GridRange from '../GridRange';\nimport KeyHandler from '../KeyHandler';\n\nclass EditKeyHandler extends KeyHandler {\n onDown(e: KeyboardEvent, grid: Grid): boolean {\n if (GridUtils.isModifierKeyDown(e)) {\n return false;\n }\n\n const { model } = grid.props;\n const { cursorColumn, cursorRow } = grid.state;\n if (\n cursorColumn == null ||\n cursorRow == null ||\n !model.isEditableRange(GridRange.makeCell(cursorColumn, cursorRow))\n ) {\n return false;\n }\n const column: number | null = cursorColumn;\n const row: number | null = cursorRow;\n if (column == null || row == null) {\n return false;\n }\n\n if (e.key.length === 1) {\n grid.startEditing(column, row, true, [1, 1], e.key);\n return true;\n }\n\n if (e.key === 'F2') {\n grid.startEditing(column, row);\n return true;\n }\n\n if (e.key === 'Backspace') {\n grid.startEditing(column, row, true, null, '');\n return true;\n }\n\n if (e.key === 'Delete') {\n grid.setValueForCell(column, row, '');\n return true;\n }\n return false;\n }\n}\n\nexport default EditKeyHandler;\n"],"file":"EditKeyHandler.js"}
1
+ {"version":3,"sources":["../../src/key-handlers/EditKeyHandler.ts"],"names":["GridUtils","GridRange","KeyHandler","EditKeyHandler","onDown","e","grid","isModifierKeyDown","model","props","cursorColumn","cursorRow","state","isEditableRange","makeCell","column","row","key","length","startEditing","setValueForCell"],"mappings":"AAAA;OACOA,S;OAEAC,S;OACAC,U;;AAEP,MAAMC,cAAN,SAA6BD,UAA7B,CAAwC;AACtCE,EAAAA,MAAM,CAACC,CAAD,EAAmBC,IAAnB,EAAwC;AAC5C,QAAIN,SAAS,CAACO,iBAAV,CAA4BF,CAA5B,CAAJ,EAAoC;AAClC,aAAO,KAAP;AACD;;AAED,QAAM;AAAEG,MAAAA;AAAF,QAAYF,IAAI,CAACG,KAAvB;AACA,QAAM;AAAEC,MAAAA,YAAF;AAAgBC,MAAAA;AAAhB,QAA8BL,IAAI,CAACM,KAAzC;;AACA,QACEF,YAAY,IAAI,IAAhB,IACAC,SAAS,IAAI,IADb,IAEA,CAACH,KAAK,CAACK,eAAN,CAAsBZ,SAAS,CAACa,QAAV,CAAmBJ,YAAnB,EAAiCC,SAAjC,CAAtB,CAHH,EAIE;AACA,aAAO,KAAP;AACD;;AACD,QAAMI,MAAqB,GAAGL,YAA9B;AACA,QAAMM,GAAkB,GAAGL,SAA3B;;AACA,QAAII,MAAM,IAAI,IAAV,IAAkBC,GAAG,IAAI,IAA7B,EAAmC;AACjC,aAAO,KAAP;AACD;;AAED,QAAIX,CAAC,CAACY,GAAF,CAAMC,MAAN,KAAiB,CAArB,EAAwB;AACtBZ,MAAAA,IAAI,CAACa,YAAL,CAAkBJ,MAAlB,EAA0BC,GAA1B,EAA+B,IAA/B,EAAqC,CAAC,CAAD,EAAI,CAAJ,CAArC,EAA6CX,CAAC,CAACY,GAA/C;AACA,aAAO,IAAP;AACD;;AAED,QAAIZ,CAAC,CAACY,GAAF,KAAU,IAAd,EAAoB;AAClBX,MAAAA,IAAI,CAACa,YAAL,CAAkBJ,MAAlB,EAA0BC,GAA1B;AACA,aAAO,IAAP;AACD;;AAED,QAAIX,CAAC,CAACY,GAAF,KAAU,WAAd,EAA2B;AACzBX,MAAAA,IAAI,CAACa,YAAL,CAAkBJ,MAAlB,EAA0BC,GAA1B,EAA+B,IAA/B,EAAqC,IAArC,EAA2C,EAA3C;AACA,aAAO,IAAP;AACD;;AAED,QAAIX,CAAC,CAACY,GAAF,KAAU,QAAd,EAAwB;AACtBX,MAAAA,IAAI,CAACc,eAAL,CAAqBL,MAArB,EAA6BC,GAA7B,EAAkC,EAAlC;AACA,aAAO,IAAP;AACD;;AACD,WAAO,KAAP;AACD;;AAzCqC;;AA4CxC,eAAeb,cAAf","sourcesContent":["/* eslint class-methods-use-this: \"off\" */\nimport GridUtils from '../GridUtils';\nimport Grid from '../Grid';\nimport GridRange from '../GridRange';\nimport KeyHandler from '../KeyHandler';\n\nclass EditKeyHandler extends KeyHandler {\n onDown(e: KeyboardEvent, grid: Grid): boolean {\n if (GridUtils.isModifierKeyDown(e)) {\n return false;\n }\n\n const { model } = grid.props;\n const { cursorColumn, cursorRow } = grid.state;\n if (\n cursorColumn == null ||\n cursorRow == null ||\n !model.isEditableRange(GridRange.makeCell(cursorColumn, cursorRow))\n ) {\n return false;\n }\n const column: number | null = cursorColumn;\n const row: number | null = cursorRow;\n if (column == null || row == null) {\n return false;\n }\n\n if (e.key.length === 1) {\n grid.startEditing(column, row, true, [1, 1], e.key);\n return true;\n }\n\n if (e.key === 'F2') {\n grid.startEditing(column, row);\n return true;\n }\n\n if (e.key === 'Backspace') {\n grid.startEditing(column, row, true, null, '');\n return true;\n }\n\n if (e.key === 'Delete') {\n grid.setValueForCell(column, row, '');\n return true;\n }\n return false;\n }\n}\n\nexport default EditKeyHandler;\n"],"file":"EditKeyHandler.js"}
@@ -1,28 +1,6 @@
1
- function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
2
-
3
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
4
-
5
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
6
-
7
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
8
-
9
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
10
-
11
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
12
-
13
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
14
-
15
- function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
16
-
17
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
18
-
19
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
20
-
21
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
22
-
23
1
  /* eslint class-methods-use-this: "off" */
24
- import GridUtils from '../GridUtils';
25
- import KeyHandler from '../KeyHandler';
2
+ import GridUtils from "../GridUtils.js";
3
+ import KeyHandler from "../KeyHandler.js";
26
4
  /**
27
5
  * Parse out data from an HTML table. Currently does not support colspan/rowspan
28
6
  * @param table HTML Table
@@ -59,7 +37,7 @@ export function parseValueFromTable(table) {
59
37
 
60
38
  export function parseValueFromNodes(nodes) {
61
39
  var result = [];
62
- nodes.forEach(function (node) {
40
+ nodes.forEach(node => {
63
41
  var _node$textContent;
64
42
 
65
43
  var text = (_node$textContent = node.textContent) !== null && _node$textContent !== void 0 ? _node$textContent : '';
@@ -90,17 +68,17 @@ export function parseValueFromElement(element) {
90
68
 
91
69
  // If there's text content, try and parse out a table from the child nodes. Each node is a row.
92
70
  // If there's only one row and it doesn't contain a tab, then just treat it as a regular value
93
- var childNodes = element.childNodes;
71
+ var {
72
+ childNodes
73
+ } = element;
94
74
  var hasTabChar = text.includes('\t');
95
- var hasFirefoxTab = text.includes("\xA0\xA0 \xA0");
75
+ var hasFirefoxTab = text.includes('\u00a0\u00a0 \u00a0');
96
76
 
97
77
  if (hasTabChar && childNodes.length !== 0 && (childNodes.length === 1 || childNodes.length > 1 && !((_childNodes$0$textCon = childNodes[0].textContent) !== null && _childNodes$0$textCon !== void 0 && _childNodes$0$textCon.includes('\t')))) {
98
78
  // When Chrome pastes a single row, it gets split into multiple child nodes
99
79
  // If we check the first child node and it doesn't have a tab character, but the full element text content does, then
100
80
  // just parse the text out separated by the tab chars
101
- return text.split('\n').map(function (row) {
102
- return row.split('\t');
103
- });
81
+ return text.split('\n').map(row => row.split('\t'));
104
82
  }
105
83
 
106
84
  if (childNodes.length > 1 || hasFirefoxTab) {
@@ -117,64 +95,50 @@ export function parseValueFromElement(element) {
117
95
  * Handles the paste key combination
118
96
  */
119
97
 
120
- var PasteKeyHandler = /*#__PURE__*/function (_KeyHandler) {
121
- _inherits(PasteKeyHandler, _KeyHandler);
122
-
123
- var _super = _createSuper(PasteKeyHandler);
124
-
125
- function PasteKeyHandler() {
126
- _classCallCheck(this, PasteKeyHandler);
127
-
128
- return _super.apply(this, arguments);
129
- }
130
-
131
- _createClass(PasteKeyHandler, [{
132
- key: "onDown",
133
- value: function onDown(e, grid) {
134
- switch (e.key) {
135
- case 'v':
136
- if (GridUtils.isModifierKeyDown(e)) {
137
- // Chrome doesn't allow the paste event on canvas elements
138
- // Instead, we capture the ctrl+v keydown, then do this to capture the input
139
- var dummyInput = document.createElement('div');
140
- document.body.appendChild(dummyInput);
141
- dummyInput.setAttribute('contenteditable', 'true'); // Give it invisible styling
142
-
143
- dummyInput.setAttribute('style', 'clip-path: "inset(50%)"; height: 1px; width: 1px; margin: -1px; overflow: hidden; padding 0; position: absolute;');
98
+ class PasteKeyHandler extends KeyHandler {
99
+ onDown(e, grid) {
100
+ switch (e.key) {
101
+ case 'v':
102
+ if (GridUtils.isModifierKeyDown(e)) {
103
+ // Chrome doesn't allow the paste event on canvas elements
104
+ // Instead, we capture the ctrl+v keydown, then do this to capture the input
105
+ var dummyInput = document.createElement('div');
106
+ document.body.appendChild(dummyInput);
107
+ dummyInput.setAttribute('contenteditable', 'true'); // Give it invisible styling
144
108
 
145
- var listener = function listener() {
146
- dummyInput.removeEventListener('input', listener);
147
- dummyInput.remove();
148
- grid.focus();
149
- var value = parseValueFromElement(dummyInput);
109
+ dummyInput.setAttribute('style', 'clip-path: "inset(50%)"; height: 1px; width: 1px; margin: -1px; overflow: hidden; padding 0; position: absolute;');
150
110
 
151
- if (value != null) {
152
- grid.pasteValue(value);
153
- }
154
- }; // Listen for the `input` event, when there's a change to the HTML
155
- // We could also listen to the `paste` event to get the clipboard data, but that's just text data
156
- // By listening to `input`, we can get a table that's already parsed in HTML, which is easier to consume
111
+ var listener = () => {
112
+ dummyInput.removeEventListener('input', listener);
113
+ dummyInput.remove();
114
+ grid.focus();
115
+ var value = parseValueFromElement(dummyInput);
157
116
 
117
+ if (value != null) {
118
+ grid.pasteValue(value);
119
+ }
120
+ }; // Listen for the `input` event, when there's a change to the HTML
121
+ // We could also listen to the `paste` event to get the clipboard data, but that's just text data
122
+ // By listening to `input`, we can get a table that's already parsed in HTML, which is easier to consume
158
123
 
159
- dummyInput.addEventListener('input', listener); // Focus the element so it receives the paste event
160
124
 
161
- dummyInput.focus(); // Don't block the paste event from updating our dummy input
125
+ dummyInput.addEventListener('input', listener); // Focus the element so it receives the paste event
162
126
 
163
- return {
164
- preventDefault: false,
165
- stopPropagation: true
166
- };
167
- }
127
+ dummyInput.focus(); // Don't block the paste event from updating our dummy input
168
128
 
169
- break;
170
- }
129
+ return {
130
+ preventDefault: false,
131
+ stopPropagation: true
132
+ };
133
+ }
171
134
 
172
- return false;
135
+ break;
173
136
  }
174
- }]);
175
137
 
176
- return PasteKeyHandler;
177
- }(KeyHandler);
138
+ return false;
139
+ }
140
+
141
+ }
178
142
 
179
143
  export default PasteKeyHandler;
180
144
  //# sourceMappingURL=PasteKeyHandler.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/key-handlers/PasteKeyHandler.ts"],"names":["GridUtils","KeyHandler","parseValueFromTable","table","data","rows","querySelectorAll","r","length","row","cells","rowData","c","cell","push","textContent","trim","parseValueFromNodes","nodes","result","forEach","node","text","split","parseValueFromElement","element","querySelector","childNodes","hasTabChar","includes","hasFirefoxTab","map","PasteKeyHandler","e","grid","key","isModifierKeyDown","dummyInput","document","createElement","body","appendChild","setAttribute","listener","removeEventListener","remove","focus","value","pasteValue","addEventListener","preventDefault","stopPropagation"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA;AAEA,OAAOA,SAAP,MAAsB,cAAtB;AACA,OAAOC,UAAP,MAAuB,eAAvB;AAEA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,mBAAT,CAA6BC,KAA7B,EAAkE;AACvE,MAAMC,IAAI,GAAG,EAAb;AACA,MAAMC,IA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BAAMI,UAAU,GAAGC,QAAQ,CAACC,aAAT,CAAuB,KAAvB,CAAnB;AACAD,YAAAA,QAAQ,CAACE,IAAT,CAAcC,WAAd,CAA0BJ,UAA1B;AACAA,YAAAA,UAAU,CAACK,YAAX,CAAwB,iBAAxB,EAA2C,MAA3C,EALkC,CAOlC;;AACAL,YAAAA,UAAU,CAACK,YAAX,CACE,OADF,EAEE,kHAFF;;AAKA,gBAAMC,QAAQ,GAAG,SAAXA,QAAW,GAAM;AACrBN,cAAAA,UAAU,CAACO,mBAAX,CAA+B,OAA/B,EAAwCD,QAAxC;AACAN,cAAAA,UAAU,CAACQ,MAAX;AAEAX,cAAAA,IAAI,CAACY,KAAL;AACA,kBAAMC,KAAK,GAAGvB,qBAAqB,CAACa,UAAD,CAAnC;;AACA,kBAAIU,KAAK,IAAI,IAAb,EAAmB;AACjBb,gBAAAA,IAAI,CAACc,UAAL,CAAgBD,KAAhB;AACD;AACF,aATD,CAbkC,CAwBlC;AACA;AACA;;;AACAV,YAAAA,UAAU,CAACY,gBAAX,CAA4B,OAA5B,EAAqCN,QAArC,EA3BkC,CA6BlC;;AACAN,YAAAA,UAAU,CAACS,KAAX,GA9BkC,CAgClC;;AACA,mBAAO;AAAEI,cAAAA,cAAc,EAAE,KAAlB;AAAyBC,cAAAA,eAAe,EAAE;AAA1C,aAAP;AACD;;AACD;AArCJ;;AAuCA,aAAO,KAAP;AACD;;;;EA7C2BlD,U;;AAgD9B,eAAe+B,eAAf","sourcesContent":["/* eslint class-methods-use-this: \"off\" */\nimport Grid from '../Grid';\nimport GridUtils from '../GridUtils';\nimport KeyHandler from '../KeyHandler';\n\n/**\n * Parse out data from an HTML table. Currently does not support colspan/rowspan\n * @param table HTML Table\n * @returns A two dimensional array with the data found in the table\n */\nexport function parseValueFromTable(table: HTMLTableElement): string[][] {\n const data = [];\n const rows = table.querySelectorAll('tr');\n for (let r = 0; r < rows.length; r += 1) {\n const row = rows[r];\n const cells = row.querySelectorAll('td');\n const rowData = [];\n for (let c = 0; c < cells.length; c += 1) {\n const cell = cells[c];\n rowData.push(cell.textContent?.trim() ?? '');\n }\n data.push(rowData);\n }\n\n return data;\n}\n\n/**\n * Parses out a table of data from HTML elements. Treats each element as one rows.\n * Filters out blank rows.\n * @param rows The elements to parse out\n * @returns A string table of data\n */\nexport function parseValueFromNodes(nodes: NodeListOf<ChildNode>): string[][] {\n const result = [] as string[][];\n nodes.forEach(node => {\n const text = node.textContent ?? '';\n if (text.length > 0) {\n // When Chrome pastes a table from text, it preserves the tab characters\n // In Firefox, it breaks it into a combination of non-breaking spaces and spaces\n result.push(text.split(/\\t|\\u00a0\\u00a0 \\u00a0/));\n }\n });\n\n return result;\n}\n\nexport function parseValueFromElement(\n element: HTMLElement\n): string | string[][] | null {\n // Check first if there's an HTML table element that we can use\n const table = element.querySelector('table');\n if (table != null) {\n return parseValueFromTable(table);\n }\n\n // Otherwise check if there's any text content at all\n const text = element.textContent?.trim() ?? '';\n if (text.length > 0) {\n // If there's text content, try and parse out a table from the child nodes. Each node is a row.\n // If there's only one row and it doesn't contain a tab, then just treat it as a regular value\n const { childNodes } = element;\n const hasTabChar = text.includes('\\t');\n const hasFirefoxTab = text.includes('\\u00a0\\u00a0 \\u00a0');\n if (\n hasTabChar &&\n childNodes.length !== 0 &&\n (childNodes.length === 1 ||\n (childNodes.length > 1 && !childNodes[0].textContent?.includes('\\t')))\n ) {\n // When Chrome pastes a single row, it gets split into multiple child nodes\n // If we check the first child node and it doesn't have a tab character, but the full element text content does, then\n // just parse the text out separated by the tab chars\n return text.split('\\n').map(row => row.split('\\t'));\n }\n if (childNodes.length > 1 || hasFirefoxTab) {\n return parseValueFromNodes(element.childNodes);\n }\n // If there's no tabs or no multiple rows, than just treat it as one value\n return text;\n }\n return null;\n}\n\n/**\n * Handles the paste key combination\n */\nclass PasteKeyHandler extends KeyHandler {\n onDown(\n e: KeyboardEvent,\n grid: Grid\n ): boolean | { stopPropagation?: boolean; preventDefault?: boolean } {\n switch (e.key) {\n case 'v':\n if (GridUtils.isModifierKeyDown(e)) {\n // Chrome doesn't allow the paste event on canvas elements\n // Instead, we capture the ctrl+v keydown, then do this to capture the input\n const dummyInput = document.createElement('div');\n document.body.appendChild(dummyInput);\n dummyInput.setAttribute('contenteditable', 'true');\n\n // Give it invisible styling\n dummyInput.setAttribute(\n 'style',\n 'clip-path: \"inset(50%)\"; height: 1px; width: 1px; margin: -1px; overflow: hidden; padding 0; position: absolute;'\n );\n\n const listener = () => {\n dummyInput.removeEventListener('input', listener);\n dummyInput.remove();\n\n grid.focus();\n const value = parseValueFromElement(dummyInput);\n if (value != null) {\n grid.pasteValue(value);\n }\n };\n\n // Listen for the `input` event, when there's a change to the HTML\n // We could also listen to the `paste` event to get the clipboard data, but that's just text data\n // By listening to `input`, we can get a table that's already parsed in HTML, which is easier to consume\n dummyInput.addEventListener('input', listener);\n\n // Focus the element so it receives the paste event\n dummyInput.focus();\n\n // Don't block the paste event from updating our dummy input\n return { preventDefault: false, stopPropagation: true };\n }\n break;\n }\n return false;\n }\n}\n\nexport default PasteKeyHandler;\n"],"file":"PasteKeyHandler.js"}
1
+ {"version":3,"sources":["../../src/key-handlers/PasteKeyHandler.ts"],"names":["GridUtils","KeyHandler","parseValueFromTable","table","data","rows","querySelectorAll","r","length","row","cells","rowData","c","cell","push","textContent","trim","parseValueFromNodes","nodes","result","forEach","node","text","split","parseValueFromElement","element","querySelector","childNodes","hasTabChar","includes","hasFirefoxTab","map","PasteKeyHandler","onDown","e","grid","key","isModifierKeyDown","dummyInput","document","createElement","body","appendChild","setAttribute","listener","removeEventListener","remove","focus","value","pasteValue","addEventListener","preventDefault","stopPropagation"],"mappings":"AAAA;OAEOA,S;OACAC,U;AAEP;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,mBAAT,CAA6BC,KAA7B,EAAkE;AACvE,MAAMC,IAAI,GAAG,EAAb;AACA,MAAMC,IAAI,GAAGF,KAAK,CAACG,gBAAN,CAAuB,IAAvB,CAAb;;AACA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B,CAAnB;AACAD,UAAAA,QAAQ,CAACE,IAAT,CAAcC,WAAd,CAA0BJ,UAA1B;AACAA,UAAAA,UAAU,CAACK,YAAX,CAAwB,iBAAxB,EAA2C,MAA3C,EALkC,CAOlC;;AACAL,UAAAA,UAAU,CAACK,YAAX,CACE,OADF,EAEE,kHAFF;;AAKA,cAAMC,QAAQ,GAAG,MAAM;AACrBN,YAAAA,UAAU,CAACO,mBAAX,CAA+B,OAA/B,EAAwCD,QAAxC;AACAN,YAAAA,UAAU,CAACQ,MAAX;AAEAX,YAAAA,IAAI,CAACY,KAAL;AACA,gBAAMC,KAAK,GAAGxB,qBAAqB,CAACc,UAAD,CAAnC;;AACA,gBAAIU,KAAK,IAAI,IAAb,EAAmB;AACjBb,cAAAA,IAAI,CAACc,UAAL,CAAgBD,KAAhB;AACD;AACF,WATD,CAbkC,CAwBlC;AACA;AACA;;;AACAV,UAAAA,UAAU,CAACY,gBAAX,CAA4B,OAA5B,EAAqCN,QAArC,EA3BkC,CA6BlC;;AACAN,UAAAA,UAAU,CAACS,KAAX,GA9BkC,CAgClC;;AACA,iBAAO;AAAEI,YAAAA,cAAc,EAAE,KAAlB;AAAyBC,YAAAA,eAAe,EAAE;AAA1C,WAAP;AACD;;AACD;AArCJ;;AAuCA,WAAO,KAAP;AACD;;AA7CsC;;AAgDzC,eAAepB,eAAf","sourcesContent":["/* eslint class-methods-use-this: \"off\" */\nimport Grid from '../Grid';\nimport GridUtils from '../GridUtils';\nimport KeyHandler from '../KeyHandler';\n\n/**\n * Parse out data from an HTML table. Currently does not support colspan/rowspan\n * @param table HTML Table\n * @returns A two dimensional array with the data found in the table\n */\nexport function parseValueFromTable(table: HTMLTableElement): string[][] {\n const data = [];\n const rows = table.querySelectorAll('tr');\n for (let r = 0; r < rows.length; r += 1) {\n const row = rows[r];\n const cells = row.querySelectorAll('td');\n const rowData = [];\n for (let c = 0; c < cells.length; c += 1) {\n const cell = cells[c];\n rowData.push(cell.textContent?.trim() ?? '');\n }\n data.push(rowData);\n }\n\n return data;\n}\n\n/**\n * Parses out a table of data from HTML elements. Treats each element as one rows.\n * Filters out blank rows.\n * @param rows The elements to parse out\n * @returns A string table of data\n */\nexport function parseValueFromNodes(nodes: NodeListOf<ChildNode>): string[][] {\n const result = [] as string[][];\n nodes.forEach(node => {\n const text = node.textContent ?? '';\n if (text.length > 0) {\n // When Chrome pastes a table from text, it preserves the tab characters\n // In Firefox, it breaks it into a combination of non-breaking spaces and spaces\n result.push(text.split(/\\t|\\u00a0\\u00a0 \\u00a0/));\n }\n });\n\n return result;\n}\n\nexport function parseValueFromElement(\n element: HTMLElement\n): string | string[][] | null {\n // Check first if there's an HTML table element that we can use\n const table = element.querySelector('table');\n if (table != null) {\n return parseValueFromTable(table);\n }\n\n // Otherwise check if there's any text content at all\n const text = element.textContent?.trim() ?? '';\n if (text.length > 0) {\n // If there's text content, try and parse out a table from the child nodes. Each node is a row.\n // If there's only one row and it doesn't contain a tab, then just treat it as a regular value\n const { childNodes } = element;\n const hasTabChar = text.includes('\\t');\n const hasFirefoxTab = text.includes('\\u00a0\\u00a0 \\u00a0');\n if (\n hasTabChar &&\n childNodes.length !== 0 &&\n (childNodes.length === 1 ||\n (childNodes.length > 1 && !childNodes[0].textContent?.includes('\\t')))\n ) {\n // When Chrome pastes a single row, it gets split into multiple child nodes\n // If we check the first child node and it doesn't have a tab character, but the full element text content does, then\n // just parse the text out separated by the tab chars\n return text.split('\\n').map(row => row.split('\\t'));\n }\n if (childNodes.length > 1 || hasFirefoxTab) {\n return parseValueFromNodes(element.childNodes);\n }\n // If there's no tabs or no multiple rows, than just treat it as one value\n return text;\n }\n return null;\n}\n\n/**\n * Handles the paste key combination\n */\nclass PasteKeyHandler extends KeyHandler {\n onDown(\n e: KeyboardEvent,\n grid: Grid\n ): boolean | { stopPropagation?: boolean; preventDefault?: boolean } {\n switch (e.key) {\n case 'v':\n if (GridUtils.isModifierKeyDown(e)) {\n // Chrome doesn't allow the paste event on canvas elements\n // Instead, we capture the ctrl+v keydown, then do this to capture the input\n const dummyInput = document.createElement('div');\n document.body.appendChild(dummyInput);\n dummyInput.setAttribute('contenteditable', 'true');\n\n // Give it invisible styling\n dummyInput.setAttribute(\n 'style',\n 'clip-path: \"inset(50%)\"; height: 1px; width: 1px; margin: -1px; overflow: hidden; padding 0; position: absolute;'\n );\n\n const listener = () => {\n dummyInput.removeEventListener('input', listener);\n dummyInput.remove();\n\n grid.focus();\n const value = parseValueFromElement(dummyInput);\n if (value != null) {\n grid.pasteValue(value);\n }\n };\n\n // Listen for the `input` event, when there's a change to the HTML\n // We could also listen to the `paste` event to get the clipboard data, but that's just text data\n // By listening to `input`, we can get a table that's already parsed in HTML, which is easier to consume\n dummyInput.addEventListener('input', listener);\n\n // Focus the element so it receives the paste event\n dummyInput.focus();\n\n // Don't block the paste event from updating our dummy input\n return { preventDefault: false, stopPropagation: true };\n }\n break;\n }\n return false;\n }\n}\n\nexport default PasteKeyHandler;\n"],"file":"PasteKeyHandler.js"}
@@ -1 +1 @@
1
- {"version":3,"file":"SelectionKeyHandler.d.ts","sourceRoot":"","sources":["../../src/key-handlers/SelectionKeyHandler.ts"],"names":[],"mappings":"AAEA,OAAO,IAAI,MAAM,SAAS,CAAC;AAG3B,OAAO,UAAU,MAAM,eAAe,CAAC;AAEvC,cAAM,mBAAoB,SAAQ,UAAU;IAC1C,MAAM,CAAC,CAAC,EAAE,aAAa,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO;IAgE7C,eAAe,CACb,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,aAAa,EACpB,IAAI,EAAE,IAAI,GACT,OAAO;IAyEV,YAAY,CAAC,CAAC,EAAE,aAAa,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO;IA2CnD,cAAc,CAAC,CAAC,EAAE,aAAa,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO;CA8CtD;AAED,eAAe,mBAAmB,CAAC"}
1
+ {"version":3,"file":"SelectionKeyHandler.d.ts","sourceRoot":"","sources":["../../src/key-handlers/SelectionKeyHandler.ts"],"names":[],"mappings":"AAEA,OAAO,IAAI,MAAM,SAAS,CAAC;AAG3B,OAAO,UAAU,MAAM,eAAe,CAAC;AAEvC,cAAM,mBAAoB,SAAQ,UAAU;IAC1C,MAAM,CAAC,CAAC,EAAE,aAAa,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO;IA2F7C,eAAe,CACb,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,aAAa,EACpB,IAAI,EAAE,IAAI,GACT,OAAO;IAyEV,YAAY,CAAC,CAAC,EAAE,aAAa,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO;IA2CnD,cAAc,CAAC,CAAC,EAAE,aAAa,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO;CA8CtD;AAED,eAAe,mBAAmB,CAAC"}