@deephaven/grid 0.4.1-modules.0 → 0.5.2-beta.0

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 (74) hide show
  1. package/dist/CellInputField.js +88 -40
  2. package/dist/CellInputField.js.map +1 -1
  3. package/dist/Grid.js +1484 -1449
  4. package/dist/Grid.js.map +1 -1
  5. package/dist/GridColorUtils.js +51 -18
  6. package/dist/GridColorUtils.js.map +1 -1
  7. package/dist/GridMetricCalculator.js +994 -1017
  8. package/dist/GridMetricCalculator.js.map +1 -1
  9. package/dist/GridModel.js +286 -171
  10. package/dist/GridModel.js.map +1 -1
  11. package/dist/GridMouseHandler.js +59 -39
  12. package/dist/GridMouseHandler.js.map +1 -1
  13. package/dist/GridRange.js +630 -572
  14. package/dist/GridRange.js.map +1 -1
  15. package/dist/GridRenderer.d.ts.map +1 -1
  16. package/dist/GridRenderer.js +1564 -1650
  17. package/dist/GridRenderer.js.map +1 -1
  18. package/dist/GridTestUtils.js +29 -15
  19. package/dist/GridTestUtils.js.map +1 -1
  20. package/dist/GridUtils.js +717 -679
  21. package/dist/GridUtils.js.map +1 -1
  22. package/dist/KeyHandler.js +18 -6
  23. package/dist/KeyHandler.js.map +1 -1
  24. package/dist/MockGridModel.js +210 -105
  25. package/dist/MockGridModel.js.map +1 -1
  26. package/dist/MockTreeGridModel.js +183 -113
  27. package/dist/MockTreeGridModel.js.map +1 -1
  28. package/dist/errors/PasteError.js +44 -5
  29. package/dist/errors/PasteError.js.map +1 -1
  30. package/dist/errors/index.js +1 -1
  31. package/dist/errors/index.js.map +1 -1
  32. package/dist/index.js +15 -15
  33. package/dist/index.js.map +1 -1
  34. package/dist/key-handlers/EditKeyHandler.js +75 -42
  35. package/dist/key-handlers/EditKeyHandler.js.map +1 -1
  36. package/dist/key-handlers/PasteKeyHandler.js +78 -42
  37. package/dist/key-handlers/PasteKeyHandler.js.map +1 -1
  38. package/dist/key-handlers/SelectionKeyHandler.js +234 -220
  39. package/dist/key-handlers/SelectionKeyHandler.js.map +1 -1
  40. package/dist/key-handlers/TreeKeyHandler.js +72 -42
  41. package/dist/key-handlers/TreeKeyHandler.js.map +1 -1
  42. package/dist/key-handlers/index.js +4 -4
  43. package/dist/key-handlers/index.js.map +1 -1
  44. package/dist/memoizeClear.js +1 -1
  45. package/dist/memoizeClear.js.map +1 -1
  46. package/dist/mouse-handlers/EditMouseHandler.js +50 -18
  47. package/dist/mouse-handlers/EditMouseHandler.js.map +1 -1
  48. package/dist/mouse-handlers/GridColumnMoveMouseHandler.js +163 -141
  49. package/dist/mouse-handlers/GridColumnMoveMouseHandler.js.map +1 -1
  50. package/dist/mouse-handlers/GridColumnSeparatorMouseHandler.js +86 -47
  51. package/dist/mouse-handlers/GridColumnSeparatorMouseHandler.js.map +1 -1
  52. package/dist/mouse-handlers/GridHorizontalScrollBarMouseHandler.d.ts.map +1 -1
  53. package/dist/mouse-handlers/GridHorizontalScrollBarMouseHandler.js +171 -143
  54. package/dist/mouse-handlers/GridHorizontalScrollBarMouseHandler.js.map +1 -1
  55. package/dist/mouse-handlers/GridRowMoveMouseHandler.js +147 -125
  56. package/dist/mouse-handlers/GridRowMoveMouseHandler.js.map +1 -1
  57. package/dist/mouse-handlers/GridRowSeparatorMouseHandler.js +86 -47
  58. package/dist/mouse-handlers/GridRowSeparatorMouseHandler.js.map +1 -1
  59. package/dist/mouse-handlers/GridRowTreeMouseHandler.js +76 -46
  60. package/dist/mouse-handlers/GridRowTreeMouseHandler.js.map +1 -1
  61. package/dist/mouse-handlers/GridScrollBarCornerMouseHandler.d.ts.map +1 -1
  62. package/dist/mouse-handlers/GridScrollBarCornerMouseHandler.js +62 -31
  63. package/dist/mouse-handlers/GridScrollBarCornerMouseHandler.js.map +1 -1
  64. package/dist/mouse-handlers/GridSelectionMouseHandler.js +222 -200
  65. package/dist/mouse-handlers/GridSelectionMouseHandler.js.map +1 -1
  66. package/dist/mouse-handlers/GridSeparatorMouseHandler.js +253 -206
  67. package/dist/mouse-handlers/GridSeparatorMouseHandler.js.map +1 -1
  68. package/dist/mouse-handlers/GridVerticalScrollBarMouseHandler.d.ts.map +1 -1
  69. package/dist/mouse-handlers/GridVerticalScrollBarMouseHandler.js +172 -144
  70. package/dist/mouse-handlers/GridVerticalScrollBarMouseHandler.js.map +1 -1
  71. package/dist/mouse-handlers/index.js +10 -10
  72. package/dist/mouse-handlers/index.js.map +1 -1
  73. package/dist/tsconfig.tsbuildinfo +1 -1
  74. package/package.json +4 -5
@@ -1,57 +1,90 @@
1
- /* eslint class-methods-use-this: "off" */
2
- import GridUtils from "../GridUtils.js";
3
- import GridRange from "../GridRange.js";
4
- import KeyHandler from "../KeyHandler.js";
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); }
5
2
 
6
- class EditKeyHandler extends KeyHandler {
7
- onDown(e, grid) {
8
- if (GridUtils.isModifierKeyDown(e)) {
9
- return false;
10
- }
3
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
11
4
 
12
- var {
13
- model
14
- } = grid.props;
15
- var {
16
- cursorColumn,
17
- cursorRow
18
- } = grid.state;
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); } }
19
6
 
20
- if (cursorColumn == null || cursorRow == null || !model.isEditableRange(GridRange.makeCell(cursorColumn, cursorRow))) {
21
- return false;
22
- }
7
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
23
8
 
24
- var column = cursorColumn;
25
- var row = cursorRow;
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); }
26
10
 
27
- if (column == null || row == null) {
28
- return false;
29
- }
11
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
30
12
 
31
- if (e.key.length === 1) {
32
- grid.startEditing(column, row, true, [1, 1], e.key);
33
- return true;
34
- }
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); }; }
35
14
 
36
- if (e.key === 'F2') {
37
- grid.startEditing(column, row);
38
- return true;
39
- }
15
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
40
16
 
41
- if (e.key === 'Backspace') {
42
- grid.startEditing(column, row, true, null, '');
43
- return true;
44
- }
17
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
45
18
 
46
- if (e.key === 'Delete') {
47
- grid.setValueForCell(column, row, '');
48
- return true;
49
- }
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
+ /* 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);
50
30
 
51
- return false;
31
+ var _super = _createSuper(EditKeyHandler);
32
+
33
+ function EditKeyHandler() {
34
+ _classCallCheck(this, EditKeyHandler);
35
+
36
+ return _super.apply(this, arguments);
52
37
  }
53
38
 
54
- }
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;
50
+
51
+ if (cursorColumn == null || cursorRow == null || !model.isEditableRange(GridRange.makeCell(cursorColumn, cursorRow))) {
52
+ return false;
53
+ }
54
+
55
+ var column = cursorColumn;
56
+ var row = cursorRow;
57
+
58
+ if (column == null || row == null) {
59
+ return false;
60
+ }
61
+
62
+ if (e.key.length === 1) {
63
+ grid.startEditing(column, row, true, [1, 1], e.key);
64
+ return true;
65
+ }
66
+
67
+ if (e.key === 'F2') {
68
+ grid.startEditing(column, row);
69
+ return true;
70
+ }
71
+
72
+ if (e.key === 'Backspace') {
73
+ grid.startEditing(column, row, true, null, '');
74
+ return true;
75
+ }
76
+
77
+ if (e.key === 'Delete') {
78
+ grid.setValueForCell(column, row, '');
79
+ return true;
80
+ }
81
+
82
+ return false;
83
+ }
84
+ }]);
85
+
86
+ return EditKeyHandler;
87
+ }(KeyHandler);
55
88
 
56
89
  export default EditKeyHandler;
57
90
  //# sourceMappingURL=EditKeyHandler.js.map
@@ -1 +1 @@
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
+ {"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":";;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,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,6 +1,28 @@
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
+
1
23
  /* eslint class-methods-use-this: "off" */
2
- import GridUtils from "../GridUtils.js";
3
- import KeyHandler from "../KeyHandler.js";
24
+ import GridUtils from '../GridUtils';
25
+ import KeyHandler from '../KeyHandler';
4
26
  /**
5
27
  * Parse out data from an HTML table. Currently does not support colspan/rowspan
6
28
  * @param table HTML Table
@@ -37,7 +59,7 @@ export function parseValueFromTable(table) {
37
59
 
38
60
  export function parseValueFromNodes(nodes) {
39
61
  var result = [];
40
- nodes.forEach(node => {
62
+ nodes.forEach(function (node) {
41
63
  var _node$textContent;
42
64
 
43
65
  var text = (_node$textContent = node.textContent) !== null && _node$textContent !== void 0 ? _node$textContent : '';
@@ -68,17 +90,17 @@ export function parseValueFromElement(element) {
68
90
 
69
91
  // If there's text content, try and parse out a table from the child nodes. Each node is a row.
70
92
  // If there's only one row and it doesn't contain a tab, then just treat it as a regular value
71
- var {
72
- childNodes
73
- } = element;
93
+ var childNodes = element.childNodes;
74
94
  var hasTabChar = text.includes('\t');
75
- var hasFirefoxTab = text.includes('\u00a0\u00a0 \u00a0');
95
+ var hasFirefoxTab = text.includes("\xA0\xA0 \xA0");
76
96
 
77
97
  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')))) {
78
98
  // When Chrome pastes a single row, it gets split into multiple child nodes
79
99
  // If we check the first child node and it doesn't have a tab character, but the full element text content does, then
80
100
  // just parse the text out separated by the tab chars
81
- return text.split('\n').map(row => row.split('\t'));
101
+ return text.split('\n').map(function (row) {
102
+ return row.split('\t');
103
+ });
82
104
  }
83
105
 
84
106
  if (childNodes.length > 1 || hasFirefoxTab) {
@@ -95,50 +117,64 @@ export function parseValueFromElement(element) {
95
117
  * Handles the paste key combination
96
118
  */
97
119
 
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
120
+ var PasteKeyHandler = /*#__PURE__*/function (_KeyHandler) {
121
+ _inherits(PasteKeyHandler, _KeyHandler);
108
122
 
109
- dummyInput.setAttribute('style', 'clip-path: "inset(50%)"; height: 1px; width: 1px; margin: -1px; overflow: hidden; padding 0; position: absolute;');
123
+ var _super = _createSuper(PasteKeyHandler);
110
124
 
111
- var listener = () => {
112
- dummyInput.removeEventListener('input', listener);
113
- dummyInput.remove();
114
- grid.focus();
115
- var value = parseValueFromElement(dummyInput);
125
+ function PasteKeyHandler() {
126
+ _classCallCheck(this, PasteKeyHandler);
116
127
 
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
128
+ return _super.apply(this, arguments);
129
+ }
123
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
124
142
 
125
- dummyInput.addEventListener('input', listener); // Focus the element so it receives the paste event
143
+ dummyInput.setAttribute('style', 'clip-path: "inset(50%)"; height: 1px; width: 1px; margin: -1px; overflow: hidden; padding 0; position: absolute;');
126
144
 
127
- dummyInput.focus(); // Don't block the paste event from updating our dummy input
145
+ var listener = function listener() {
146
+ dummyInput.removeEventListener('input', listener);
147
+ dummyInput.remove();
148
+ grid.focus();
149
+ var value = parseValueFromElement(dummyInput);
128
150
 
129
- return {
130
- preventDefault: false,
131
- stopPropagation: true
132
- };
133
- }
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
134
157
 
135
- break;
136
- }
137
158
 
138
- return false;
139
- }
159
+ dummyInput.addEventListener('input', listener); // Focus the element so it receives the paste event
140
160
 
141
- }
161
+ dummyInput.focus(); // Don't block the paste event from updating our dummy input
162
+
163
+ return {
164
+ preventDefault: false,
165
+ stopPropagation: true
166
+ };
167
+ }
168
+
169
+ break;
170
+ }
171
+
172
+ return false;
173
+ }
174
+ }]);
175
+
176
+ return PasteKeyHandler;
177
+ }(KeyHandler);
142
178
 
143
179
  export default PasteKeyHandler;
144
180
  //# 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","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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C,QAAQ,CAACC,aAAT,CAAuB,KAAvB,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
+ {"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,IAAI,GAAGF,KAAK,CAACG,gBAAN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AACC,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"}