keyborg 2.3.1-canary.0 → 2.4.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/{keyborg.esm.js → esm/index.js} +114 -269
- package/dist/esm/index.js.map +1 -0
- package/dist/{Keyborg.d.ts → index.d.mts} +112 -87
- package/dist/index.d.ts +112 -7
- package/dist/index.js +145 -279
- package/dist/index.js.map +1 -1
- package/package.json +23 -31
- package/dist/FocusEvent.d.ts +0 -29
- package/dist/WeakRefInstance.d.ts +0 -11
- package/dist/keyborg.esm.js.map +0 -1
|
@@ -1,16 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
*/
|
|
5
|
-
// IE11 compat, checks if WeakRef is supported
|
|
6
|
-
const _canUseWeakRef = typeof WeakRef !== "undefined";
|
|
7
|
-
/**
|
|
8
|
-
* WeakRef wrapper around a HTMLElement that also supports IE11
|
|
9
|
-
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakRef}
|
|
10
|
-
* @internal
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
class WeakRefInstance {
|
|
1
|
+
// src/WeakRefInstance.ts
|
|
2
|
+
var _canUseWeakRef = typeof WeakRef !== "undefined";
|
|
3
|
+
var WeakRefInstance = class {
|
|
14
4
|
constructor(instance) {
|
|
15
5
|
if (_canUseWeakRef && typeof instance === "object") {
|
|
16
6
|
this._weakRef = new WeakRef(instance);
|
|
@@ -18,122 +8,89 @@ class WeakRefInstance {
|
|
|
18
8
|
this._instance = instance;
|
|
19
9
|
}
|
|
20
10
|
}
|
|
21
|
-
/**
|
|
22
|
-
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakRef/deref}
|
|
11
|
+
/**
|
|
12
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakRef/deref}
|
|
23
13
|
*/
|
|
24
|
-
|
|
25
|
-
|
|
26
14
|
deref() {
|
|
27
|
-
var _a, _b
|
|
28
|
-
|
|
15
|
+
var _a, _b;
|
|
29
16
|
let instance;
|
|
30
|
-
|
|
31
17
|
if (this._weakRef) {
|
|
32
|
-
instance = (_a = this._weakRef)
|
|
33
|
-
|
|
18
|
+
instance = (_a = this._weakRef) == null ? void 0 : _a.deref();
|
|
34
19
|
if (!instance) {
|
|
35
20
|
delete this._weakRef;
|
|
36
21
|
}
|
|
37
22
|
} else {
|
|
38
23
|
instance = this._instance;
|
|
39
|
-
|
|
40
|
-
if ((_c = (_b = instance) === null || _b === void 0 ? void 0 : _b.isDisposed) === null || _c === void 0 ? void 0 : _c.call(_b)) {
|
|
24
|
+
if ((_b = instance == null ? void 0 : instance.isDisposed) == null ? void 0 : _b.call(instance)) {
|
|
41
25
|
delete this._instance;
|
|
42
26
|
}
|
|
43
27
|
}
|
|
44
|
-
|
|
45
28
|
return instance;
|
|
46
29
|
}
|
|
30
|
+
};
|
|
47
31
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
/*!
|
|
51
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
52
|
-
* Licensed under the MIT License.
|
|
53
|
-
*/
|
|
54
|
-
const KEYBORG_FOCUSIN = "keyborg:focusin";
|
|
55
|
-
|
|
32
|
+
// src/FocusEvent.ts
|
|
33
|
+
var KEYBORG_FOCUSIN = "keyborg:focusin";
|
|
56
34
|
function canOverrideNativeFocus(win) {
|
|
57
35
|
const HTMLElement = win.HTMLElement;
|
|
58
36
|
const origFocus = HTMLElement.prototype.focus;
|
|
59
37
|
let isCustomFocusCalled = false;
|
|
60
|
-
|
|
61
38
|
HTMLElement.prototype.focus = function focus() {
|
|
62
39
|
isCustomFocusCalled = true;
|
|
63
40
|
};
|
|
64
|
-
|
|
65
41
|
const btn = win.document.createElement("button");
|
|
66
42
|
btn.focus();
|
|
67
43
|
HTMLElement.prototype.focus = origFocus;
|
|
68
44
|
return isCustomFocusCalled;
|
|
69
45
|
}
|
|
70
|
-
|
|
71
|
-
let _canOverrideNativeFocus = false;
|
|
72
|
-
/**
|
|
73
|
-
* Guarantees that the native `focus` will be used
|
|
74
|
-
*/
|
|
75
|
-
|
|
46
|
+
var _canOverrideNativeFocus = false;
|
|
76
47
|
function nativeFocus(element) {
|
|
77
48
|
const focus = element.focus;
|
|
78
|
-
|
|
79
49
|
if (focus.__keyborgNativeFocus) {
|
|
80
50
|
focus.__keyborgNativeFocus.call(element);
|
|
81
51
|
} else {
|
|
82
52
|
element.focus();
|
|
83
53
|
}
|
|
84
54
|
}
|
|
85
|
-
/**
|
|
86
|
-
* Overrides the native `focus` and setups the keyborg focus event
|
|
87
|
-
*/
|
|
88
|
-
|
|
89
55
|
function setupFocusEvent(win) {
|
|
90
56
|
const kwin = win;
|
|
91
|
-
|
|
92
57
|
if (!_canOverrideNativeFocus) {
|
|
93
58
|
_canOverrideNativeFocus = canOverrideNativeFocus(kwin);
|
|
94
59
|
}
|
|
95
|
-
|
|
96
60
|
const origFocus = kwin.HTMLElement.prototype.focus;
|
|
97
|
-
|
|
98
61
|
if (origFocus.__keyborgNativeFocus) {
|
|
99
|
-
// Already set up.
|
|
100
62
|
return;
|
|
101
63
|
}
|
|
102
|
-
|
|
103
64
|
kwin.HTMLElement.prototype.focus = focus;
|
|
104
|
-
|
|
105
|
-
const focusOutShadowRootHandler = e => {
|
|
65
|
+
const focusOutShadowRootHandler = (e) => {
|
|
106
66
|
const relatedTarget = e.relatedTarget;
|
|
107
|
-
const currentTarget = e.currentTarget;
|
|
108
|
-
|
|
67
|
+
const currentTarget = e.currentTarget;
|
|
109
68
|
if (!currentTarget.contains(relatedTarget)) {
|
|
110
|
-
currentTarget.removeEventListener("focusin", focusInHandler);
|
|
111
|
-
currentTarget.removeEventListener(
|
|
69
|
+
currentTarget.removeEventListener("focusin", focusInHandler, true);
|
|
70
|
+
currentTarget.removeEventListener(
|
|
71
|
+
"focusout",
|
|
72
|
+
focusOutShadowRootHandler,
|
|
73
|
+
true
|
|
74
|
+
);
|
|
112
75
|
}
|
|
113
76
|
};
|
|
114
|
-
|
|
115
|
-
const focusInHandler = e => {
|
|
77
|
+
const focusInHandler = (e) => {
|
|
116
78
|
var _a;
|
|
117
|
-
|
|
118
|
-
let target = e.target;
|
|
119
|
-
|
|
79
|
+
const target = e.target;
|
|
120
80
|
if (!target) {
|
|
121
81
|
return;
|
|
122
82
|
}
|
|
123
|
-
|
|
124
83
|
if (target.shadowRoot) {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
target = e.composedPath()[0];
|
|
84
|
+
target.shadowRoot.addEventListener("focusin", focusInHandler, true);
|
|
85
|
+
target.shadowRoot.addEventListener(
|
|
86
|
+
"focusout",
|
|
87
|
+
focusOutShadowRootHandler,
|
|
88
|
+
true
|
|
89
|
+
);
|
|
90
|
+
return;
|
|
133
91
|
}
|
|
134
|
-
|
|
135
92
|
const details = {
|
|
136
|
-
relatedTarget: e.relatedTarget ||
|
|
93
|
+
relatedTarget: e.relatedTarget || void 0
|
|
137
94
|
};
|
|
138
95
|
const event = new CustomEvent(KEYBORG_FOCUSIN, {
|
|
139
96
|
cancelable: true,
|
|
@@ -141,113 +98,84 @@ function setupFocusEvent(win) {
|
|
|
141
98
|
// Allows the event to bubble past an open shadow root
|
|
142
99
|
composed: true,
|
|
143
100
|
detail: details
|
|
144
|
-
});
|
|
145
|
-
|
|
101
|
+
});
|
|
146
102
|
event.details = details;
|
|
147
|
-
|
|
148
103
|
if (_canOverrideNativeFocus || data.lastFocusedProgrammatically) {
|
|
149
|
-
details.isFocusedProgrammatically = target === ((_a = data.lastFocusedProgrammatically)
|
|
150
|
-
data.lastFocusedProgrammatically =
|
|
104
|
+
details.isFocusedProgrammatically = target === ((_a = data.lastFocusedProgrammatically) == null ? void 0 : _a.deref());
|
|
105
|
+
data.lastFocusedProgrammatically = void 0;
|
|
151
106
|
}
|
|
152
|
-
|
|
153
107
|
target.dispatchEvent(event);
|
|
154
108
|
};
|
|
155
|
-
|
|
156
109
|
const data = kwin.__keyborgData = {
|
|
157
110
|
focusInHandler
|
|
158
111
|
};
|
|
159
|
-
kwin.document.addEventListener(
|
|
160
|
-
|
|
112
|
+
kwin.document.addEventListener(
|
|
113
|
+
"focusin",
|
|
114
|
+
kwin.__keyborgData.focusInHandler,
|
|
115
|
+
true
|
|
116
|
+
);
|
|
161
117
|
function focus() {
|
|
162
118
|
const keyborgNativeFocusEvent = kwin.__keyborgData;
|
|
163
|
-
|
|
164
119
|
if (keyborgNativeFocusEvent) {
|
|
165
|
-
keyborgNativeFocusEvent.lastFocusedProgrammatically = new WeakRefInstance(
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
120
|
+
keyborgNativeFocusEvent.lastFocusedProgrammatically = new WeakRefInstance(
|
|
121
|
+
this
|
|
122
|
+
);
|
|
123
|
+
}
|
|
169
124
|
return origFocus.apply(this, arguments);
|
|
170
125
|
}
|
|
171
|
-
|
|
172
126
|
focus.__keyborgNativeFocus = origFocus;
|
|
173
127
|
}
|
|
174
|
-
/**
|
|
175
|
-
* Removes keyborg event listeners and custom focus override
|
|
176
|
-
* @param win The window that stores keyborg focus events
|
|
177
|
-
*/
|
|
178
|
-
|
|
179
128
|
function disposeFocusEvent(win) {
|
|
180
129
|
const kwin = win;
|
|
181
130
|
const proto = kwin.HTMLElement.prototype;
|
|
182
131
|
const origFocus = proto.focus.__keyborgNativeFocus;
|
|
183
132
|
const keyborgNativeFocusEvent = kwin.__keyborgData;
|
|
184
|
-
|
|
185
133
|
if (keyborgNativeFocusEvent) {
|
|
186
|
-
kwin.document.removeEventListener(
|
|
134
|
+
kwin.document.removeEventListener(
|
|
135
|
+
"focusin",
|
|
136
|
+
keyborgNativeFocusEvent.focusInHandler,
|
|
137
|
+
true
|
|
138
|
+
);
|
|
187
139
|
delete kwin.__keyborgData;
|
|
188
140
|
}
|
|
189
|
-
|
|
190
141
|
if (origFocus) {
|
|
191
142
|
proto.focus = origFocus;
|
|
192
143
|
}
|
|
193
144
|
}
|
|
194
|
-
/**
|
|
195
|
-
* @param win The window that stores keyborg focus events
|
|
196
|
-
* @returns The last element focused with element.focus()
|
|
197
|
-
*/
|
|
198
|
-
|
|
199
145
|
function getLastFocusedProgrammatically(win) {
|
|
200
146
|
var _a;
|
|
201
|
-
|
|
202
147
|
const keyborgNativeFocusEvent = win.__keyborgData;
|
|
203
|
-
return keyborgNativeFocusEvent ? ((_a = keyborgNativeFocusEvent.lastFocusedProgrammatically)
|
|
148
|
+
return keyborgNativeFocusEvent ? ((_a = keyborgNativeFocusEvent.lastFocusedProgrammatically) == null ? void 0 : _a.deref()) || null : void 0;
|
|
204
149
|
}
|
|
205
150
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
const _dismissTimeout = 500; // When a key from dismissKeys is pressed and the focus is not moved
|
|
211
|
-
// during _dismissTimeout time, dismiss the keyboard navigation mode.
|
|
212
|
-
|
|
213
|
-
let _lastId = 0;
|
|
214
|
-
/**
|
|
215
|
-
* Source of truth for all the keyborg core instances and the current keyboard navigation state
|
|
216
|
-
*/
|
|
217
|
-
|
|
218
|
-
class KeyborgState {
|
|
151
|
+
// src/Keyborg.ts
|
|
152
|
+
var _dismissTimeout = 500;
|
|
153
|
+
var _lastId = 0;
|
|
154
|
+
var KeyborgState = class {
|
|
219
155
|
constructor() {
|
|
220
156
|
this.__keyborgCoreRefs = {};
|
|
221
157
|
this._isNavigatingWithKeyboard = false;
|
|
222
158
|
}
|
|
223
|
-
|
|
224
159
|
add(keyborg) {
|
|
225
160
|
const id = keyborg.id;
|
|
226
|
-
|
|
227
161
|
if (!(id in this.__keyborgCoreRefs)) {
|
|
228
162
|
this.__keyborgCoreRefs[id] = new WeakRefInstance(keyborg);
|
|
229
163
|
}
|
|
230
164
|
}
|
|
231
|
-
|
|
232
165
|
remove(id) {
|
|
233
166
|
delete this.__keyborgCoreRefs[id];
|
|
234
|
-
|
|
235
167
|
if (Object.keys(this.__keyborgCoreRefs).length === 0) {
|
|
236
168
|
this._isNavigatingWithKeyboard = false;
|
|
237
169
|
}
|
|
238
170
|
}
|
|
239
|
-
|
|
240
171
|
setVal(isNavigatingWithKeyboard) {
|
|
241
172
|
if (this._isNavigatingWithKeyboard === isNavigatingWithKeyboard) {
|
|
242
173
|
return;
|
|
243
174
|
}
|
|
244
|
-
|
|
245
175
|
this._isNavigatingWithKeyboard = isNavigatingWithKeyboard;
|
|
246
|
-
|
|
247
176
|
for (const id of Object.keys(this.__keyborgCoreRefs)) {
|
|
248
177
|
const ref = this.__keyborgCoreRefs[id];
|
|
249
178
|
const keyborg = ref.deref();
|
|
250
|
-
|
|
251
179
|
if (keyborg) {
|
|
252
180
|
keyborg.update(isNavigatingWithKeyboard);
|
|
253
181
|
} else {
|
|
@@ -255,207 +183,137 @@ class KeyborgState {
|
|
|
255
183
|
}
|
|
256
184
|
}
|
|
257
185
|
}
|
|
258
|
-
|
|
259
186
|
getVal() {
|
|
260
187
|
return this._isNavigatingWithKeyboard;
|
|
261
188
|
}
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
const _state = /*#__PURE__*/new KeyborgState();
|
|
266
|
-
/**
|
|
267
|
-
* Manages a collection of Keyborg instances in a window/document and updates keyborg state
|
|
268
|
-
*/
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
class KeyborgCore {
|
|
189
|
+
};
|
|
190
|
+
var _state = new KeyborgState();
|
|
191
|
+
var KeyborgCore = class {
|
|
272
192
|
constructor(win, props) {
|
|
273
|
-
this._onFocusIn = e => {
|
|
274
|
-
// When the focus is moved not programmatically and without keydown events,
|
|
275
|
-
// it is likely that the focus is moved by screen reader (as it might swallow
|
|
276
|
-
// the events when the screen reader shortcuts are used). The screen reader
|
|
277
|
-
// usage is keyboard navigation.
|
|
193
|
+
this._onFocusIn = (e) => {
|
|
278
194
|
if (this._isMouseUsedTimer) {
|
|
279
|
-
// There was a mouse event recently.
|
|
280
195
|
return;
|
|
281
196
|
}
|
|
282
|
-
|
|
283
197
|
if (_state.getVal()) {
|
|
284
198
|
return;
|
|
285
199
|
}
|
|
286
|
-
|
|
287
200
|
const details = e.detail;
|
|
288
|
-
|
|
289
201
|
if (!details.relatedTarget) {
|
|
290
202
|
return;
|
|
291
203
|
}
|
|
292
|
-
|
|
293
|
-
if (details.isFocusedProgrammatically || details.isFocusedProgrammatically === undefined) {
|
|
294
|
-
// The element is focused programmatically, or the programmatic focus detection
|
|
295
|
-
// is not working.
|
|
204
|
+
if (details.isFocusedProgrammatically || details.isFocusedProgrammatically === void 0) {
|
|
296
205
|
return;
|
|
297
206
|
}
|
|
298
|
-
|
|
299
207
|
_state.setVal(true);
|
|
300
208
|
};
|
|
301
|
-
|
|
302
|
-
this._onMouseDown = e => {
|
|
209
|
+
this._onMouseDown = (e) => {
|
|
303
210
|
if (e.buttons === 0 || e.clientX === 0 && e.clientY === 0 && e.screenX === 0 && e.screenY === 0) {
|
|
304
|
-
// This is most likely an event triggered by the screen reader to perform
|
|
305
|
-
// an action on an element, do not dismiss the keyboard navigation mode.
|
|
306
211
|
return;
|
|
307
212
|
}
|
|
308
|
-
|
|
309
213
|
const win = this._win;
|
|
310
|
-
|
|
311
214
|
if (win) {
|
|
312
215
|
if (this._isMouseUsedTimer) {
|
|
313
216
|
win.clearTimeout(this._isMouseUsedTimer);
|
|
314
217
|
}
|
|
315
|
-
|
|
316
218
|
this._isMouseUsedTimer = win.setTimeout(() => {
|
|
317
219
|
delete this._isMouseUsedTimer;
|
|
318
|
-
},
|
|
220
|
+
}, 1e3);
|
|
319
221
|
}
|
|
320
|
-
|
|
321
222
|
_state.setVal(false);
|
|
322
223
|
};
|
|
323
|
-
|
|
324
|
-
this._onKeyDown = e => {
|
|
224
|
+
this._onKeyDown = (e) => {
|
|
325
225
|
var _a, _b;
|
|
326
|
-
|
|
327
226
|
const isNavigatingWithKeyboard = _state.getVal();
|
|
328
|
-
|
|
329
227
|
const keyCode = e.keyCode;
|
|
330
228
|
const triggerKeys = this._triggerKeys;
|
|
331
|
-
|
|
332
229
|
if (!isNavigatingWithKeyboard && (!triggerKeys || triggerKeys.has(keyCode))) {
|
|
333
|
-
const activeElement = (_a = this._win)
|
|
334
|
-
|
|
230
|
+
const activeElement = (_a = this._win) == null ? void 0 : _a.document.activeElement;
|
|
335
231
|
if (activeElement && (activeElement.tagName === "INPUT" || activeElement.tagName === "TEXTAREA" || activeElement.contentEditable === "true")) {
|
|
336
|
-
// We're inside an input, textarea or contenteditable, it's not
|
|
337
|
-
// keyboard navigation, it is text editing scenario.
|
|
338
232
|
return;
|
|
339
233
|
}
|
|
340
|
-
|
|
341
234
|
_state.setVal(true);
|
|
342
|
-
} else if (isNavigatingWithKeyboard && ((_b = this._dismissKeys)
|
|
235
|
+
} else if (isNavigatingWithKeyboard && ((_b = this._dismissKeys) == null ? void 0 : _b.has(keyCode))) {
|
|
343
236
|
this._scheduleDismiss();
|
|
344
237
|
}
|
|
345
238
|
};
|
|
346
|
-
|
|
347
239
|
this.id = "c" + ++_lastId;
|
|
348
240
|
this._win = win;
|
|
349
241
|
const doc = win.document;
|
|
350
|
-
|
|
351
242
|
if (props) {
|
|
352
243
|
const triggerKeys = props.triggerKeys;
|
|
353
244
|
const dismissKeys = props.dismissKeys;
|
|
354
|
-
|
|
355
|
-
if (triggerKeys === null || triggerKeys === void 0 ? void 0 : triggerKeys.length) {
|
|
245
|
+
if (triggerKeys == null ? void 0 : triggerKeys.length) {
|
|
356
246
|
this._triggerKeys = new Set(triggerKeys);
|
|
357
247
|
}
|
|
358
|
-
|
|
359
|
-
if (dismissKeys === null || dismissKeys === void 0 ? void 0 : dismissKeys.length) {
|
|
248
|
+
if (dismissKeys == null ? void 0 : dismissKeys.length) {
|
|
360
249
|
this._dismissKeys = new Set(dismissKeys);
|
|
361
250
|
}
|
|
362
251
|
}
|
|
363
|
-
|
|
364
|
-
doc.addEventListener(
|
|
365
|
-
|
|
366
|
-
doc.addEventListener("mousedown", this._onMouseDown, true); // Capture!
|
|
367
|
-
|
|
368
|
-
win.addEventListener("keydown", this._onKeyDown, true); // Capture!
|
|
369
|
-
|
|
252
|
+
doc.addEventListener(KEYBORG_FOCUSIN, this._onFocusIn, true);
|
|
253
|
+
doc.addEventListener("mousedown", this._onMouseDown, true);
|
|
254
|
+
win.addEventListener("keydown", this._onKeyDown, true);
|
|
370
255
|
setupFocusEvent(win);
|
|
371
|
-
|
|
372
256
|
_state.add(this);
|
|
373
257
|
}
|
|
374
|
-
|
|
375
258
|
dispose() {
|
|
376
259
|
const win = this._win;
|
|
377
|
-
|
|
378
260
|
if (win) {
|
|
379
261
|
if (this._isMouseUsedTimer) {
|
|
380
262
|
win.clearTimeout(this._isMouseUsedTimer);
|
|
381
|
-
this._isMouseUsedTimer =
|
|
263
|
+
this._isMouseUsedTimer = void 0;
|
|
382
264
|
}
|
|
383
|
-
|
|
384
265
|
if (this._dismissTimer) {
|
|
385
266
|
win.clearTimeout(this._dismissTimer);
|
|
386
|
-
this._dismissTimer =
|
|
267
|
+
this._dismissTimer = void 0;
|
|
387
268
|
}
|
|
388
|
-
|
|
389
269
|
disposeFocusEvent(win);
|
|
390
270
|
const doc = win.document;
|
|
391
|
-
doc.removeEventListener(KEYBORG_FOCUSIN, this._onFocusIn, true);
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
win.removeEventListener("keydown", this._onKeyDown, true); // Capture!
|
|
396
|
-
|
|
271
|
+
doc.removeEventListener(KEYBORG_FOCUSIN, this._onFocusIn, true);
|
|
272
|
+
doc.removeEventListener("mousedown", this._onMouseDown, true);
|
|
273
|
+
win.removeEventListener("keydown", this._onKeyDown, true);
|
|
397
274
|
delete this._win;
|
|
398
|
-
|
|
399
275
|
_state.remove(this.id);
|
|
400
276
|
}
|
|
401
277
|
}
|
|
402
|
-
|
|
403
278
|
isDisposed() {
|
|
404
279
|
return !!this._win;
|
|
405
280
|
}
|
|
406
|
-
/**
|
|
407
|
-
* Updates all keyborg instances with the keyboard navigation state
|
|
281
|
+
/**
|
|
282
|
+
* Updates all keyborg instances with the keyboard navigation state
|
|
408
283
|
*/
|
|
409
|
-
|
|
410
|
-
|
|
411
284
|
update(isNavigatingWithKeyboard) {
|
|
412
285
|
var _a, _b;
|
|
413
|
-
|
|
414
|
-
const keyborgs = (_b = (_a = this._win) === null || _a === void 0 ? void 0 : _a.__keyborg) === null || _b === void 0 ? void 0 : _b.refs;
|
|
415
|
-
|
|
286
|
+
const keyborgs = (_b = (_a = this._win) == null ? void 0 : _a.__keyborg) == null ? void 0 : _b.refs;
|
|
416
287
|
if (keyborgs) {
|
|
417
288
|
for (const id of Object.keys(keyborgs)) {
|
|
418
289
|
Keyborg.update(keyborgs[id], isNavigatingWithKeyboard);
|
|
419
290
|
}
|
|
420
291
|
}
|
|
421
292
|
}
|
|
422
|
-
|
|
423
293
|
_scheduleDismiss() {
|
|
424
294
|
const win = this._win;
|
|
425
|
-
|
|
426
295
|
if (win) {
|
|
427
296
|
if (this._dismissTimer) {
|
|
428
297
|
win.clearTimeout(this._dismissTimer);
|
|
429
|
-
this._dismissTimer =
|
|
298
|
+
this._dismissTimer = void 0;
|
|
430
299
|
}
|
|
431
|
-
|
|
432
300
|
const was = win.document.activeElement;
|
|
433
301
|
this._dismissTimer = win.setTimeout(() => {
|
|
434
|
-
this._dismissTimer =
|
|
302
|
+
this._dismissTimer = void 0;
|
|
435
303
|
const cur = win.document.activeElement;
|
|
436
|
-
|
|
437
304
|
if (was && cur && was === cur) {
|
|
438
|
-
// Esc was pressed, currently focused element hasn't changed.
|
|
439
|
-
// Just dismiss the keyboard navigation mode.
|
|
440
305
|
_state.setVal(false);
|
|
441
306
|
}
|
|
442
307
|
}, _dismissTimeout);
|
|
443
308
|
}
|
|
444
309
|
}
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
/**
|
|
448
|
-
* Used to determine the keyboard navigation state
|
|
449
|
-
*/
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
class Keyborg {
|
|
310
|
+
};
|
|
311
|
+
var Keyborg = class _Keyborg {
|
|
453
312
|
constructor(win, props) {
|
|
454
313
|
this._cb = [];
|
|
455
314
|
this._id = "k" + ++_lastId;
|
|
456
315
|
this._win = win;
|
|
457
316
|
const current = win.__keyborg;
|
|
458
|
-
|
|
459
317
|
if (current) {
|
|
460
318
|
this._core = current.core;
|
|
461
319
|
current.refs[this._id] = this;
|
|
@@ -463,88 +321,68 @@ class Keyborg {
|
|
|
463
321
|
this._core = new KeyborgCore(win, props);
|
|
464
322
|
win.__keyborg = {
|
|
465
323
|
core: this._core,
|
|
466
|
-
refs: {
|
|
467
|
-
[this._id]: this
|
|
468
|
-
}
|
|
324
|
+
refs: { [this._id]: this }
|
|
469
325
|
};
|
|
470
326
|
}
|
|
471
327
|
}
|
|
472
|
-
|
|
473
328
|
static create(win, props) {
|
|
474
|
-
return new
|
|
329
|
+
return new _Keyborg(win, props);
|
|
475
330
|
}
|
|
476
|
-
|
|
477
331
|
static dispose(instance) {
|
|
478
332
|
instance.dispose();
|
|
479
333
|
}
|
|
480
|
-
/**
|
|
481
|
-
* Updates all subscribed callbacks with the keyboard navigation state
|
|
334
|
+
/**
|
|
335
|
+
* Updates all subscribed callbacks with the keyboard navigation state
|
|
482
336
|
*/
|
|
483
|
-
|
|
484
|
-
|
|
485
337
|
static update(instance, isNavigatingWithKeyboard) {
|
|
486
|
-
instance._cb.forEach(callback => callback(isNavigatingWithKeyboard));
|
|
338
|
+
instance._cb.forEach((callback) => callback(isNavigatingWithKeyboard));
|
|
487
339
|
}
|
|
488
|
-
|
|
489
340
|
dispose() {
|
|
490
341
|
var _a;
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
if (current === null || current === void 0 ? void 0 : current.refs[this._id]) {
|
|
342
|
+
const current = (_a = this._win) == null ? void 0 : _a.__keyborg;
|
|
343
|
+
if (current == null ? void 0 : current.refs[this._id]) {
|
|
495
344
|
delete current.refs[this._id];
|
|
496
|
-
|
|
497
345
|
if (Object.keys(current.refs).length === 0) {
|
|
498
|
-
current.core.dispose();
|
|
499
|
-
|
|
346
|
+
current.core.dispose();
|
|
500
347
|
delete this._win.__keyborg;
|
|
501
348
|
}
|
|
502
|
-
} else if (process.env.NODE_ENV
|
|
503
|
-
console.error(
|
|
349
|
+
} else if (process.env.NODE_ENV !== "production") {
|
|
350
|
+
console.error(
|
|
351
|
+
`Keyborg instance ${this._id} is being disposed incorrectly.`
|
|
352
|
+
);
|
|
504
353
|
}
|
|
505
|
-
|
|
506
354
|
this._cb = [];
|
|
507
355
|
delete this._core;
|
|
508
356
|
delete this._win;
|
|
509
357
|
}
|
|
510
|
-
/**
|
|
511
|
-
* @returns Whether the user is navigating with keyboard
|
|
358
|
+
/**
|
|
359
|
+
* @returns Whether the user is navigating with keyboard
|
|
512
360
|
*/
|
|
513
|
-
|
|
514
|
-
|
|
515
361
|
isNavigatingWithKeyboard() {
|
|
516
362
|
return _state.getVal();
|
|
517
363
|
}
|
|
518
|
-
/**
|
|
519
|
-
* @param callback - Called when the keyboard navigation state changes
|
|
364
|
+
/**
|
|
365
|
+
* @param callback - Called when the keyboard navigation state changes
|
|
520
366
|
*/
|
|
521
|
-
|
|
522
|
-
|
|
523
367
|
subscribe(callback) {
|
|
524
368
|
this._cb.push(callback);
|
|
525
369
|
}
|
|
526
|
-
/**
|
|
527
|
-
* @param callback - Registered with subscribe
|
|
370
|
+
/**
|
|
371
|
+
* @param callback - Registered with subscribe
|
|
528
372
|
*/
|
|
529
|
-
|
|
530
|
-
|
|
531
373
|
unsubscribe(callback) {
|
|
532
374
|
const index = this._cb.indexOf(callback);
|
|
533
|
-
|
|
534
375
|
if (index >= 0) {
|
|
535
376
|
this._cb.splice(index, 1);
|
|
536
377
|
}
|
|
537
378
|
}
|
|
538
|
-
/**
|
|
539
|
-
* Manually set the keyboard navigtion state
|
|
379
|
+
/**
|
|
380
|
+
* Manually set the keyboard navigtion state
|
|
540
381
|
*/
|
|
541
|
-
|
|
542
|
-
|
|
543
382
|
setVal(isNavigatingWithKeyboard) {
|
|
544
383
|
_state.setVal(isNavigatingWithKeyboard);
|
|
545
384
|
}
|
|
546
|
-
|
|
547
|
-
}
|
|
385
|
+
};
|
|
548
386
|
function createKeyborg(win, props) {
|
|
549
387
|
return Keyborg.create(win, props);
|
|
550
388
|
}
|
|
@@ -552,11 +390,18 @@ function disposeKeyborg(instance) {
|
|
|
552
390
|
Keyborg.dispose(instance);
|
|
553
391
|
}
|
|
554
392
|
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
393
|
+
// src/index.ts
|
|
394
|
+
var version = "2.4.0";
|
|
395
|
+
export {
|
|
396
|
+
KEYBORG_FOCUSIN,
|
|
397
|
+
createKeyborg,
|
|
398
|
+
disposeKeyborg,
|
|
399
|
+
getLastFocusedProgrammatically,
|
|
400
|
+
nativeFocus,
|
|
401
|
+
version
|
|
402
|
+
};
|
|
403
|
+
/*!
|
|
404
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
405
|
+
* Licensed under the MIT License.
|
|
558
406
|
*/
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
export { KEYBORG_FOCUSIN, Keyborg, createKeyborg, disposeKeyborg, getLastFocusedProgrammatically, nativeFocus, version };
|
|
562
|
-
//# sourceMappingURL=keyborg.esm.js.map
|
|
407
|
+
//# sourceMappingURL=index.js.map
|