1 | "use strict";
|
2 |
|
3 | exports.__esModule = true;
|
4 | require("core-js/modules/es.error.cause.js");
|
5 | var _console = require("./helpers/console");
|
6 | var _element = require("./helpers/dom/element");
|
7 | var _function = require("./helpers/function");
|
8 | function _classPrivateMethodInitSpec(e, a) { _checkPrivateRedeclaration(e, a), a.add(e); }
|
9 | function _classPrivateFieldInitSpec(e, t, a) { _checkPrivateRedeclaration(e, t), t.set(e, a); }
|
10 | function _checkPrivateRedeclaration(e, t) { if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object"); }
|
11 | function _classPrivateFieldGet(s, a) { return s.get(_assertClassBrand(s, a)); }
|
12 | function _classPrivateFieldSet(s, a, r) { return s.set(_assertClassBrand(s, a), r), r; }
|
13 | function _assertClassBrand(e, t, n) { if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError("Private element is not present on this object"); }
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | const FOCUS_MODES = Object.freeze({
|
23 | CELL: 'cell',
|
24 | MIXED: 'mixed'
|
25 | });
|
26 |
|
27 |
|
28 |
|
29 |
|
30 | var _hot = new WeakMap();
|
31 | var _focusMode = new WeakMap();
|
32 | var _refocusDelay = new WeakMap();
|
33 | var _refocusElementGetter = new WeakMap();
|
34 | var _debouncedSelect = new WeakMap();
|
35 | var _FocusManager_brand = new WeakSet();
|
36 | class FocusManager {
|
37 | constructor(hotInstance) {
|
38 | var _this = this;
|
39 | |
40 |
|
41 |
|
42 |
|
43 |
|
44 | _classPrivateMethodInitSpec(this, _FocusManager_brand);
|
45 | |
46 |
|
47 |
|
48 | _classPrivateFieldInitSpec(this, _hot, void 0);
|
49 | |
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 | _classPrivateFieldInitSpec(this, _focusMode, void 0);
|
60 | |
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 | _classPrivateFieldInitSpec(this, _refocusDelay, 1);
|
67 | |
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 | _classPrivateFieldInitSpec(this, _refocusElementGetter, null);
|
74 | |
75 |
|
76 |
|
77 |
|
78 |
|
79 | _classPrivateFieldInitSpec(this, _debouncedSelect, new Map());
|
80 | const hotSettings = hotInstance.getSettings();
|
81 | _classPrivateFieldSet(_hot, this, hotInstance);
|
82 | _classPrivateFieldSet(_focusMode, this, hotSettings.imeFastEdit ? FOCUS_MODES.MIXED : FOCUS_MODES.CELL);
|
83 | _classPrivateFieldGet(_hot, this).addHook('afterUpdateSettings', function () {
|
84 | for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
85 | args[_key] = arguments[_key];
|
86 | }
|
87 | return _assertClassBrand(_FocusManager_brand, _this, _onUpdateSettings).call(_this, ...args);
|
88 | });
|
89 | _classPrivateFieldGet(_hot, this).addHook('afterSelection', function () {
|
90 | for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
91 | args[_key2] = arguments[_key2];
|
92 | }
|
93 | return _assertClassBrand(_FocusManager_brand, _this, _focusCell).call(_this, ...args);
|
94 | });
|
95 | _classPrivateFieldGet(_hot, this).addHook('afterSelectionFocusSet', function () {
|
96 | for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
97 | args[_key3] = arguments[_key3];
|
98 | }
|
99 | return _assertClassBrand(_FocusManager_brand, _this, _focusCell).call(_this, ...args);
|
100 | });
|
101 | _classPrivateFieldGet(_hot, this).addHook('afterSelectionEnd', function () {
|
102 | for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
103 | args[_key4] = arguments[_key4];
|
104 | }
|
105 | return _assertClassBrand(_FocusManager_brand, _this, _focusEditorElement).call(_this, ...args);
|
106 | });
|
107 | }
|
108 |
|
109 | |
110 |
|
111 |
|
112 |
|
113 |
|
114 | getFocusMode() {
|
115 | return _classPrivateFieldGet(_focusMode, this);
|
116 | }
|
117 |
|
118 | |
119 |
|
120 |
|
121 |
|
122 |
|
123 | setFocusMode(focusMode) {
|
124 | if (Object.values(FOCUS_MODES).includes(focusMode)) {
|
125 | _classPrivateFieldSet(_focusMode, this, focusMode);
|
126 | } else {
|
127 | (0, _console.warn)(`"${focusMode}" is not a valid focus mode.`);
|
128 | }
|
129 | }
|
130 |
|
131 | |
132 |
|
133 |
|
134 |
|
135 |
|
136 |
|
137 | getRefocusDelay() {
|
138 | return _classPrivateFieldGet(_refocusDelay, this);
|
139 | }
|
140 |
|
141 | |
142 |
|
143 |
|
144 |
|
145 |
|
146 |
|
147 | setRefocusDelay(delay) {
|
148 | _classPrivateFieldSet(_refocusDelay, this, delay);
|
149 | }
|
150 |
|
151 | |
152 |
|
153 |
|
154 |
|
155 |
|
156 | setRefocusElementGetter(getRefocusElementFunction) {
|
157 | _classPrivateFieldSet(_refocusElementGetter, this, getRefocusElementFunction);
|
158 | }
|
159 |
|
160 | |
161 |
|
162 |
|
163 |
|
164 |
|
165 | getRefocusElement() {
|
166 | if (typeof _classPrivateFieldGet(_refocusElementGetter, this) === 'function') {
|
167 | return _classPrivateFieldGet(_refocusElementGetter, this).call(this);
|
168 | } else {
|
169 | var _classPrivateFieldGet2;
|
170 | return (_classPrivateFieldGet2 = _classPrivateFieldGet(_hot, this).getActiveEditor()) === null || _classPrivateFieldGet2 === void 0 ? void 0 : _classPrivateFieldGet2.TEXTAREA;
|
171 | }
|
172 | }
|
173 |
|
174 | |
175 |
|
176 |
|
177 |
|
178 |
|
179 | focusOnHighlightedCell(selectedCell) {
|
180 | const focusElement = element => {
|
181 | var _classPrivateFieldGet3, _classPrivateFieldGet4;
|
182 | const currentHighlightCoords = (_classPrivateFieldGet3 = _classPrivateFieldGet(_hot, this).getSelectedRangeLast()) === null || _classPrivateFieldGet3 === void 0 ? void 0 : _classPrivateFieldGet3.highlight;
|
183 | if (!currentHighlightCoords) {
|
184 | return;
|
185 | }
|
186 | let elementToBeFocused = _classPrivateFieldGet(_hot, this).runHooks('modifyFocusedElement', currentHighlightCoords.row, currentHighlightCoords.col, element);
|
187 | if (!(elementToBeFocused instanceof HTMLElement)) {
|
188 | elementToBeFocused = element;
|
189 | }
|
190 | if (elementToBeFocused && !((_classPrivateFieldGet4 = _classPrivateFieldGet(_hot, this).getActiveEditor()) !== null && _classPrivateFieldGet4 !== void 0 && _classPrivateFieldGet4.isOpened())) {
|
191 | elementToBeFocused.focus({
|
192 | preventScroll: true
|
193 | });
|
194 | }
|
195 | };
|
196 | if (selectedCell) {
|
197 | focusElement(selectedCell);
|
198 | } else {
|
199 | _assertClassBrand(_FocusManager_brand, this, _getSelectedCell).call(this, element => focusElement(element));
|
200 | }
|
201 | }
|
202 |
|
203 | |
204 |
|
205 |
|
206 |
|
207 |
|
208 |
|
209 | refocusToEditorTextarea() {
|
210 | var _classPrivateFieldGet5;
|
211 | let delay = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _classPrivateFieldGet(_refocusDelay, this);
|
212 | const refocusElement = this.getRefocusElement();
|
213 |
|
214 |
|
215 | if (_classPrivateFieldGet(_hot, this).getSettings().imeFastEdit && !((_classPrivateFieldGet5 = _classPrivateFieldGet(_hot, this).getActiveEditor()) !== null && _classPrivateFieldGet5 !== void 0 && _classPrivateFieldGet5.isOpened()) && !!refocusElement) {
|
216 | if (!_classPrivateFieldGet(_debouncedSelect, this).has(delay)) {
|
217 | _classPrivateFieldGet(_debouncedSelect, this).set(delay, (0, _function.debounce)(() => {
|
218 | refocusElement.select();
|
219 | }, delay));
|
220 | }
|
221 | _classPrivateFieldGet(_debouncedSelect, this).get(delay)();
|
222 | }
|
223 | }
|
224 | }
|
225 | exports.FocusManager = FocusManager;
|
226 | function _getSelectedCell(callback) {
|
227 | var _classPrivateFieldGet6;
|
228 | const highlight = (_classPrivateFieldGet6 = _classPrivateFieldGet(_hot, this).getSelectedRangeLast()) === null || _classPrivateFieldGet6 === void 0 ? void 0 : _classPrivateFieldGet6.highlight;
|
229 | if (!highlight || !_classPrivateFieldGet(_hot, this).selection.isCellVisible(highlight)) {
|
230 | callback(null);
|
231 | return;
|
232 | }
|
233 | const cell = _classPrivateFieldGet(_hot, this).getCell(highlight.row, highlight.col, true);
|
234 | if (cell === null) {
|
235 | _classPrivateFieldGet(_hot, this).addHookOnce('afterScroll', () => {
|
236 | callback(_classPrivateFieldGet(_hot, this).getCell(highlight.row, highlight.col, true));
|
237 | });
|
238 | } else {
|
239 | callback(cell);
|
240 | }
|
241 | }
|
242 |
|
243 |
|
244 |
|
245 | function _focusCell() {
|
246 | _assertClassBrand(_FocusManager_brand, this, _getSelectedCell).call(this, selectedCell => {
|
247 | const {
|
248 | activeElement
|
249 | } = _classPrivateFieldGet(_hot, this).rootDocument;
|
250 |
|
251 |
|
252 |
|
253 |
|
254 |
|
255 | if (activeElement && (0, _element.isOutsideInput)(activeElement)) {
|
256 | activeElement.blur();
|
257 | }
|
258 | this.focusOnHighlightedCell(selectedCell);
|
259 | });
|
260 | }
|
261 |
|
262 |
|
263 |
|
264 | function _focusEditorElement() {
|
265 | _assertClassBrand(_FocusManager_brand, this, _getSelectedCell).call(this, selectedCell => {
|
266 | if (this.getFocusMode() === FOCUS_MODES.MIXED && selectedCell.nodeName === 'TD') {
|
267 | this.refocusToEditorTextarea();
|
268 | }
|
269 | });
|
270 | }
|
271 |
|
272 |
|
273 |
|
274 |
|
275 |
|
276 | function _onUpdateSettings(newSettings) {
|
277 | if (typeof newSettings.imeFastEdit === 'boolean') {
|
278 | this.setFocusMode(newSettings.imeFastEdit ? FOCUS_MODES.MIXED : FOCUS_MODES.CELL);
|
279 | }
|
280 | } |
\ | No newline at end of file |