@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.
- package/dist/CellInputField.js +88 -40
- package/dist/CellInputField.js.map +1 -1
- package/dist/Grid.js +1484 -1449
- package/dist/Grid.js.map +1 -1
- package/dist/GridColorUtils.js +51 -18
- package/dist/GridColorUtils.js.map +1 -1
- package/dist/GridMetricCalculator.js +994 -1017
- package/dist/GridMetricCalculator.js.map +1 -1
- package/dist/GridModel.js +286 -171
- package/dist/GridModel.js.map +1 -1
- package/dist/GridMouseHandler.js +59 -39
- package/dist/GridMouseHandler.js.map +1 -1
- package/dist/GridRange.js +630 -572
- package/dist/GridRange.js.map +1 -1
- package/dist/GridRenderer.d.ts.map +1 -1
- package/dist/GridRenderer.js +1564 -1650
- package/dist/GridRenderer.js.map +1 -1
- package/dist/GridTestUtils.js +29 -15
- package/dist/GridTestUtils.js.map +1 -1
- package/dist/GridUtils.js +717 -679
- package/dist/GridUtils.js.map +1 -1
- package/dist/KeyHandler.js +18 -6
- package/dist/KeyHandler.js.map +1 -1
- package/dist/MockGridModel.js +210 -105
- package/dist/MockGridModel.js.map +1 -1
- package/dist/MockTreeGridModel.js +183 -113
- package/dist/MockTreeGridModel.js.map +1 -1
- package/dist/errors/PasteError.js +44 -5
- package/dist/errors/PasteError.js.map +1 -1
- package/dist/errors/index.js +1 -1
- package/dist/errors/index.js.map +1 -1
- package/dist/index.js +15 -15
- package/dist/index.js.map +1 -1
- package/dist/key-handlers/EditKeyHandler.js +75 -42
- package/dist/key-handlers/EditKeyHandler.js.map +1 -1
- package/dist/key-handlers/PasteKeyHandler.js +78 -42
- package/dist/key-handlers/PasteKeyHandler.js.map +1 -1
- package/dist/key-handlers/SelectionKeyHandler.js +234 -220
- package/dist/key-handlers/SelectionKeyHandler.js.map +1 -1
- package/dist/key-handlers/TreeKeyHandler.js +72 -42
- package/dist/key-handlers/TreeKeyHandler.js.map +1 -1
- package/dist/key-handlers/index.js +4 -4
- package/dist/key-handlers/index.js.map +1 -1
- package/dist/memoizeClear.js +1 -1
- package/dist/memoizeClear.js.map +1 -1
- package/dist/mouse-handlers/EditMouseHandler.js +50 -18
- package/dist/mouse-handlers/EditMouseHandler.js.map +1 -1
- package/dist/mouse-handlers/GridColumnMoveMouseHandler.js +163 -141
- package/dist/mouse-handlers/GridColumnMoveMouseHandler.js.map +1 -1
- package/dist/mouse-handlers/GridColumnSeparatorMouseHandler.js +86 -47
- package/dist/mouse-handlers/GridColumnSeparatorMouseHandler.js.map +1 -1
- package/dist/mouse-handlers/GridHorizontalScrollBarMouseHandler.d.ts.map +1 -1
- package/dist/mouse-handlers/GridHorizontalScrollBarMouseHandler.js +171 -143
- package/dist/mouse-handlers/GridHorizontalScrollBarMouseHandler.js.map +1 -1
- package/dist/mouse-handlers/GridRowMoveMouseHandler.js +147 -125
- package/dist/mouse-handlers/GridRowMoveMouseHandler.js.map +1 -1
- package/dist/mouse-handlers/GridRowSeparatorMouseHandler.js +86 -47
- package/dist/mouse-handlers/GridRowSeparatorMouseHandler.js.map +1 -1
- package/dist/mouse-handlers/GridRowTreeMouseHandler.js +76 -46
- package/dist/mouse-handlers/GridRowTreeMouseHandler.js.map +1 -1
- package/dist/mouse-handlers/GridScrollBarCornerMouseHandler.d.ts.map +1 -1
- package/dist/mouse-handlers/GridScrollBarCornerMouseHandler.js +62 -31
- package/dist/mouse-handlers/GridScrollBarCornerMouseHandler.js.map +1 -1
- package/dist/mouse-handlers/GridSelectionMouseHandler.js +222 -200
- package/dist/mouse-handlers/GridSelectionMouseHandler.js.map +1 -1
- package/dist/mouse-handlers/GridSeparatorMouseHandler.js +253 -206
- package/dist/mouse-handlers/GridSeparatorMouseHandler.js.map +1 -1
- package/dist/mouse-handlers/GridVerticalScrollBarMouseHandler.d.ts.map +1 -1
- package/dist/mouse-handlers/GridVerticalScrollBarMouseHandler.js +172 -144
- package/dist/mouse-handlers/GridVerticalScrollBarMouseHandler.js.map +1 -1
- package/dist/mouse-handlers/index.js +10 -10
- package/dist/mouse-handlers/index.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -5
|
@@ -1,57 +1,90 @@
|
|
|
1
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
-
|
|
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","
|
|
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,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
|
|
3
|
-
import KeyHandler from
|
|
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(
|
|
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(
|
|
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
|
-
|
|
99
|
-
|
|
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
|
-
|
|
123
|
+
var _super = _createSuper(PasteKeyHandler);
|
|
110
124
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
dummyInput.remove();
|
|
114
|
-
grid.focus();
|
|
115
|
-
var value = parseValueFromElement(dummyInput);
|
|
125
|
+
function PasteKeyHandler() {
|
|
126
|
+
_classCallCheck(this, PasteKeyHandler);
|
|
116
127
|
|
|
117
|
-
|
|
118
|
-
|
|
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
|
-
|
|
143
|
+
dummyInput.setAttribute('style', 'clip-path: "inset(50%)"; height: 1px; width: 1px; margin: -1px; overflow: hidden; padding 0; position: absolute;');
|
|
126
144
|
|
|
127
|
-
|
|
145
|
+
var listener = function listener() {
|
|
146
|
+
dummyInput.removeEventListener('input', listener);
|
|
147
|
+
dummyInput.remove();
|
|
148
|
+
grid.focus();
|
|
149
|
+
var value = parseValueFromElement(dummyInput);
|
|
128
150
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
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
|
-
|
|
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","
|
|
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,CAAuB,IAAvB,CAAb;;AACA,OAAK,IAAIC,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGF,IAAI,CAACG,MAAzB,EAAiCD,CAAC,IAAI,CAAtC,EAAyC;AACvC,QAAME,GAAG,GAAGJ,IAAI,CAACE,CAAD,CAAhB;AACA,QAAMG,KAAK,GAAGD,GAAG,CAACH,gBAAJ,CAAqB,IAArB,CAAd;AACA,QAAMK,OAAO,GAAG,EAAhB;;AACA,SAAK,IAAIC,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGF,KAAK,CAACF,MAA1B,EAAkCI,CAAC,IAAI,CAAvC,EAA0C;AAAA;;AACxC,UAAMC,IAAI,GAAGH,KAAK,CAACE,CAAD,CAAlB;AACAD,MAAAA,OAAO,CAACG,IAAR,+CAAaD,IAAI,CAACE,WAAlB,sDAAa,kBAAkBC,IAAl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BD,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"}
|