keyborg 2.5.0-canary.0 → 2.6.0-canary.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/esm/index.js +69 -78
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.mts +6 -2
- package/dist/index.d.ts +6 -2
- package/dist/index.js +69 -78
- package/dist/index.js.map +1 -1
- package/dist/ts3.9/index.d.ts +5 -2
- package/package.json +1 -1
package/dist/esm/index.js
CHANGED
|
@@ -85,7 +85,7 @@ function setupFocusEvent(win) {
|
|
|
85
85
|
if (!target) {
|
|
86
86
|
return;
|
|
87
87
|
}
|
|
88
|
-
let node =
|
|
88
|
+
let node = e.composedPath()[0];
|
|
89
89
|
const currentShadows = /* @__PURE__ */ new Set();
|
|
90
90
|
while (node) {
|
|
91
91
|
if (node.nodeType === Node.DOCUMENT_FRAGMENT_NODE) {
|
|
@@ -95,11 +95,14 @@ function setupFocusEvent(win) {
|
|
|
95
95
|
node = node.parentNode;
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
|
-
for (const
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
98
|
+
for (const shadowRootWeakRef of shadowTargets) {
|
|
99
|
+
const shadowRoot = shadowRootWeakRef.deref();
|
|
100
|
+
if (!shadowRoot || !currentShadows.has(shadowRoot)) {
|
|
101
|
+
shadowTargets.delete(shadowRootWeakRef);
|
|
102
|
+
if (shadowRoot) {
|
|
103
|
+
shadowRoot.removeEventListener("focusin", focusInHandler, true);
|
|
104
|
+
shadowRoot.removeEventListener("focusout", focusOutHandler, true);
|
|
105
|
+
}
|
|
103
106
|
}
|
|
104
107
|
}
|
|
105
108
|
onFocusIn(target, e.relatedTarget || void 0);
|
|
@@ -108,12 +111,14 @@ function setupFocusEvent(win) {
|
|
|
108
111
|
var _a;
|
|
109
112
|
const shadowRoot = target.shadowRoot;
|
|
110
113
|
if (shadowRoot) {
|
|
111
|
-
|
|
112
|
-
|
|
114
|
+
for (const shadowRootWeakRef of shadowTargets) {
|
|
115
|
+
if (shadowRootWeakRef.deref() === shadowRoot) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
113
118
|
}
|
|
114
119
|
shadowRoot.addEventListener("focusin", focusInHandler, true);
|
|
115
120
|
shadowRoot.addEventListener("focusout", focusOutHandler, true);
|
|
116
|
-
shadowTargets.add(shadowRoot);
|
|
121
|
+
shadowTargets.add(new WeakRefInstance(shadowRoot));
|
|
117
122
|
return;
|
|
118
123
|
}
|
|
119
124
|
const details = {
|
|
@@ -181,17 +186,20 @@ function disposeFocusEvent(win) {
|
|
|
181
186
|
keyborgNativeFocusEvent.focusOutHandler,
|
|
182
187
|
true
|
|
183
188
|
);
|
|
184
|
-
for (const
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
189
|
+
for (const shadowRootWeakRef of keyborgNativeFocusEvent.shadowTargets) {
|
|
190
|
+
const shadowRoot = shadowRootWeakRef.deref();
|
|
191
|
+
if (shadowRoot) {
|
|
192
|
+
shadowRoot.removeEventListener(
|
|
193
|
+
"focusin",
|
|
194
|
+
keyborgNativeFocusEvent.focusInHandler,
|
|
195
|
+
true
|
|
196
|
+
);
|
|
197
|
+
shadowRoot.removeEventListener(
|
|
198
|
+
"focusout",
|
|
199
|
+
keyborgNativeFocusEvent.focusOutHandler,
|
|
200
|
+
true
|
|
201
|
+
);
|
|
202
|
+
}
|
|
195
203
|
}
|
|
196
204
|
keyborgNativeFocusEvent.shadowTargets.clear();
|
|
197
205
|
delete kwin.__keyborgData;
|
|
@@ -209,50 +217,14 @@ function getLastFocusedProgrammatically(win) {
|
|
|
209
217
|
// src/Keyborg.ts
|
|
210
218
|
var _dismissTimeout = 500;
|
|
211
219
|
var _lastId = 0;
|
|
212
|
-
var KeyborgState = class {
|
|
213
|
-
constructor() {
|
|
214
|
-
this.__keyborgCoreRefs = {};
|
|
215
|
-
this._isNavigatingWithKeyboard = false;
|
|
216
|
-
}
|
|
217
|
-
add(keyborg) {
|
|
218
|
-
const id = keyborg.id;
|
|
219
|
-
if (!(id in this.__keyborgCoreRefs)) {
|
|
220
|
-
this.__keyborgCoreRefs[id] = new WeakRefInstance(keyborg);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
remove(id) {
|
|
224
|
-
delete this.__keyborgCoreRefs[id];
|
|
225
|
-
if (Object.keys(this.__keyborgCoreRefs).length === 0) {
|
|
226
|
-
this._isNavigatingWithKeyboard = false;
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
setVal(isNavigatingWithKeyboard) {
|
|
230
|
-
if (this._isNavigatingWithKeyboard === isNavigatingWithKeyboard) {
|
|
231
|
-
return;
|
|
232
|
-
}
|
|
233
|
-
this._isNavigatingWithKeyboard = isNavigatingWithKeyboard;
|
|
234
|
-
for (const id of Object.keys(this.__keyborgCoreRefs)) {
|
|
235
|
-
const ref = this.__keyborgCoreRefs[id];
|
|
236
|
-
const keyborg = ref.deref();
|
|
237
|
-
if (keyborg) {
|
|
238
|
-
keyborg.update(isNavigatingWithKeyboard);
|
|
239
|
-
} else {
|
|
240
|
-
this.remove(id);
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
getVal() {
|
|
245
|
-
return this._isNavigatingWithKeyboard;
|
|
246
|
-
}
|
|
247
|
-
};
|
|
248
|
-
var _state = new KeyborgState();
|
|
249
220
|
var KeyborgCore = class {
|
|
250
221
|
constructor(win, props) {
|
|
222
|
+
this._isNavigatingWithKeyboard_DO_NOT_USE = false;
|
|
251
223
|
this._onFocusIn = (e) => {
|
|
252
|
-
if (this.
|
|
224
|
+
if (this._isMouseOrTouchUsedTimer) {
|
|
253
225
|
return;
|
|
254
226
|
}
|
|
255
|
-
if (
|
|
227
|
+
if (this.isNavigatingWithKeyboard) {
|
|
256
228
|
return;
|
|
257
229
|
}
|
|
258
230
|
const details = e.detail;
|
|
@@ -262,32 +234,35 @@ var KeyborgCore = class {
|
|
|
262
234
|
if (details.isFocusedProgrammatically || details.isFocusedProgrammatically === void 0) {
|
|
263
235
|
return;
|
|
264
236
|
}
|
|
265
|
-
|
|
237
|
+
this.isNavigatingWithKeyboard = true;
|
|
266
238
|
};
|
|
267
239
|
this._onMouseDown = (e) => {
|
|
268
240
|
if (e.buttons === 0 || e.clientX === 0 && e.clientY === 0 && e.screenX === 0 && e.screenY === 0) {
|
|
269
241
|
return;
|
|
270
242
|
}
|
|
243
|
+
this._onMouseOrTouch();
|
|
244
|
+
};
|
|
245
|
+
this._onMouseOrTouch = () => {
|
|
271
246
|
const win = this._win;
|
|
272
247
|
if (win) {
|
|
273
|
-
if (this.
|
|
274
|
-
win.clearTimeout(this.
|
|
248
|
+
if (this._isMouseOrTouchUsedTimer) {
|
|
249
|
+
win.clearTimeout(this._isMouseOrTouchUsedTimer);
|
|
275
250
|
}
|
|
276
|
-
this.
|
|
277
|
-
delete this.
|
|
251
|
+
this._isMouseOrTouchUsedTimer = win.setTimeout(() => {
|
|
252
|
+
delete this._isMouseOrTouchUsedTimer;
|
|
278
253
|
}, 1e3);
|
|
279
254
|
}
|
|
280
|
-
|
|
255
|
+
this.isNavigatingWithKeyboard = false;
|
|
281
256
|
};
|
|
282
257
|
this._onKeyDown = (e) => {
|
|
283
|
-
const isNavigatingWithKeyboard =
|
|
258
|
+
const isNavigatingWithKeyboard = this.isNavigatingWithKeyboard;
|
|
284
259
|
if (isNavigatingWithKeyboard) {
|
|
285
260
|
if (this._shouldDismissKeyboardNavigation(e)) {
|
|
286
261
|
this._scheduleDismiss();
|
|
287
262
|
}
|
|
288
263
|
} else {
|
|
289
264
|
if (this._shouldTriggerKeyboardNavigation(e)) {
|
|
290
|
-
|
|
265
|
+
this.isNavigatingWithKeyboard = true;
|
|
291
266
|
}
|
|
292
267
|
}
|
|
293
268
|
};
|
|
@@ -307,15 +282,26 @@ var KeyborgCore = class {
|
|
|
307
282
|
doc.addEventListener(KEYBORG_FOCUSIN, this._onFocusIn, true);
|
|
308
283
|
doc.addEventListener("mousedown", this._onMouseDown, true);
|
|
309
284
|
win.addEventListener("keydown", this._onKeyDown, true);
|
|
285
|
+
doc.addEventListener("touchstart", this._onMouseOrTouch, true);
|
|
286
|
+
doc.addEventListener("touchend", this._onMouseOrTouch, true);
|
|
287
|
+
doc.addEventListener("touchcancel", this._onMouseOrTouch, true);
|
|
310
288
|
setupFocusEvent(win);
|
|
311
|
-
|
|
289
|
+
}
|
|
290
|
+
get isNavigatingWithKeyboard() {
|
|
291
|
+
return this._isNavigatingWithKeyboard_DO_NOT_USE;
|
|
292
|
+
}
|
|
293
|
+
set isNavigatingWithKeyboard(val) {
|
|
294
|
+
if (this._isNavigatingWithKeyboard_DO_NOT_USE !== val) {
|
|
295
|
+
this._isNavigatingWithKeyboard_DO_NOT_USE = val;
|
|
296
|
+
this.update();
|
|
297
|
+
}
|
|
312
298
|
}
|
|
313
299
|
dispose() {
|
|
314
300
|
const win = this._win;
|
|
315
301
|
if (win) {
|
|
316
|
-
if (this.
|
|
317
|
-
win.clearTimeout(this.
|
|
318
|
-
this.
|
|
302
|
+
if (this._isMouseOrTouchUsedTimer) {
|
|
303
|
+
win.clearTimeout(this._isMouseOrTouchUsedTimer);
|
|
304
|
+
this._isMouseOrTouchUsedTimer = void 0;
|
|
319
305
|
}
|
|
320
306
|
if (this._dismissTimer) {
|
|
321
307
|
win.clearTimeout(this._dismissTimer);
|
|
@@ -326,8 +312,10 @@ var KeyborgCore = class {
|
|
|
326
312
|
doc.removeEventListener(KEYBORG_FOCUSIN, this._onFocusIn, true);
|
|
327
313
|
doc.removeEventListener("mousedown", this._onMouseDown, true);
|
|
328
314
|
win.removeEventListener("keydown", this._onKeyDown, true);
|
|
315
|
+
doc.removeEventListener("touchstart", this._onMouseOrTouch, true);
|
|
316
|
+
doc.removeEventListener("touchend", this._onMouseOrTouch, true);
|
|
317
|
+
doc.removeEventListener("touchcancel", this._onMouseOrTouch, true);
|
|
329
318
|
delete this._win;
|
|
330
|
-
_state.remove(this.id);
|
|
331
319
|
}
|
|
332
320
|
}
|
|
333
321
|
isDisposed() {
|
|
@@ -336,12 +324,12 @@ var KeyborgCore = class {
|
|
|
336
324
|
/**
|
|
337
325
|
* Updates all keyborg instances with the keyboard navigation state
|
|
338
326
|
*/
|
|
339
|
-
update(
|
|
327
|
+
update() {
|
|
340
328
|
var _a, _b;
|
|
341
329
|
const keyborgs = (_b = (_a = this._win) == null ? void 0 : _a.__keyborg) == null ? void 0 : _b.refs;
|
|
342
330
|
if (keyborgs) {
|
|
343
331
|
for (const id of Object.keys(keyborgs)) {
|
|
344
|
-
Keyborg.update(keyborgs[id], isNavigatingWithKeyboard);
|
|
332
|
+
Keyborg.update(keyborgs[id], this.isNavigatingWithKeyboard);
|
|
345
333
|
}
|
|
346
334
|
}
|
|
347
335
|
}
|
|
@@ -377,7 +365,7 @@ var KeyborgCore = class {
|
|
|
377
365
|
this._dismissTimer = void 0;
|
|
378
366
|
const cur = win.document.activeElement;
|
|
379
367
|
if (was && cur && was === cur) {
|
|
380
|
-
|
|
368
|
+
this.isNavigatingWithKeyboard = false;
|
|
381
369
|
}
|
|
382
370
|
}, _dismissTimeout);
|
|
383
371
|
}
|
|
@@ -434,7 +422,8 @@ var Keyborg = class _Keyborg {
|
|
|
434
422
|
* @returns Whether the user is navigating with keyboard
|
|
435
423
|
*/
|
|
436
424
|
isNavigatingWithKeyboard() {
|
|
437
|
-
|
|
425
|
+
var _a;
|
|
426
|
+
return !!((_a = this._core) == null ? void 0 : _a.isNavigatingWithKeyboard);
|
|
438
427
|
}
|
|
439
428
|
/**
|
|
440
429
|
* @param callback - Called when the keyboard navigation state changes
|
|
@@ -455,7 +444,9 @@ var Keyborg = class _Keyborg {
|
|
|
455
444
|
* Manually set the keyboard navigtion state
|
|
456
445
|
*/
|
|
457
446
|
setVal(isNavigatingWithKeyboard) {
|
|
458
|
-
|
|
447
|
+
if (this._core) {
|
|
448
|
+
this._core.isNavigatingWithKeyboard = isNavigatingWithKeyboard;
|
|
449
|
+
}
|
|
459
450
|
}
|
|
460
451
|
};
|
|
461
452
|
function createKeyborg(win, props) {
|
|
@@ -466,7 +457,7 @@ function disposeKeyborg(instance) {
|
|
|
466
457
|
}
|
|
467
458
|
|
|
468
459
|
// src/index.ts
|
|
469
|
-
var version = "2.
|
|
460
|
+
var version = "2.6.0-canary.0";
|
|
470
461
|
export {
|
|
471
462
|
KEYBORG_FOCUSIN,
|
|
472
463
|
KEYBORG_FOCUSOUT,
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/WeakRefInstance.ts","../../src/FocusEvent.ts","../../src/Keyborg.ts","../../src/index.ts"],"sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License.\n */\n\n// IE11 compat, checks if WeakRef is supported\nexport const _canUseWeakRef = typeof WeakRef !== \"undefined\";\n\n/**\n * Allows disposable instances to be used\n */\nexport interface Disposable {\n isDisposed?(): boolean;\n}\n\n/**\n * WeakRef wrapper around a HTMLElement that also supports IE11\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakRef}\n * @internal\n */\nexport class WeakRefInstance<T extends Disposable | object> {\n private _weakRef?: WeakRef<T>;\n private _instance?: T;\n\n constructor(instance: T) {\n if (_canUseWeakRef && typeof instance === \"object\") {\n this._weakRef = new WeakRef(instance);\n } else {\n this._instance = instance;\n }\n }\n\n /**\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakRef/deref}\n */\n deref(): T | undefined {\n let instance: T | undefined;\n\n if (this._weakRef) {\n instance = this._weakRef?.deref();\n\n if (!instance) {\n delete this._weakRef;\n }\n } else {\n instance = this._instance;\n if ((instance as Disposable)?.isDisposed?.()) {\n delete this._instance;\n }\n }\n\n return instance;\n }\n}\n","/*!\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License.\n */\nimport { WeakRefInstance } from \"./WeakRefInstance\";\n\nexport const KEYBORG_FOCUSIN = \"keyborg:focusin\";\nexport const KEYBORG_FOCUSOUT = \"keyborg:focusout\";\n\ninterface KeyborgFocus {\n /**\n * This is the native `focus` function that is retained so that it can be restored when keyborg is disposed\n */\n __keyborgNativeFocus?: (options?: FocusOptions | undefined) => void;\n}\n\ninterface KeyborgFocusEventData {\n focusInHandler: (e: FocusEvent) => void;\n focusOutHandler: (e: FocusEvent) => void;\n lastFocusedProgrammatically?: WeakRefInstance<HTMLElement>;\n shadowTargets: Set<ShadowRoot>;\n}\n\n/**\n * Extends the global window with keyborg focus event data\n */\ninterface WindowWithKeyborgFocusEvent extends Window {\n HTMLElement: typeof HTMLElement;\n __keyborgData?: KeyborgFocusEventData;\n}\n\nfunction canOverrideNativeFocus(win: Window): boolean {\n const HTMLElement = (win as WindowWithKeyborgFocusEvent).HTMLElement;\n const origFocus = HTMLElement.prototype.focus;\n\n let isCustomFocusCalled = false;\n\n HTMLElement.prototype.focus = function focus(): void {\n isCustomFocusCalled = true;\n };\n\n const btn = win.document.createElement(\"button\");\n\n btn.focus();\n\n HTMLElement.prototype.focus = origFocus;\n\n return isCustomFocusCalled;\n}\n\nlet _canOverrideNativeFocus = false;\n\nexport interface KeyborgFocusInEventDetails {\n relatedTarget?: HTMLElement;\n isFocusedProgrammatically?: boolean;\n originalEvent?: FocusEvent;\n}\n\nexport interface KeyborgFocusInEvent\n extends CustomEvent<KeyborgFocusInEventDetails> {\n /**\n * @deprecated - used `event.detail`\n */\n details?: KeyborgFocusInEventDetails;\n}\n\nexport interface KeyborgFocusOutEventDetails {\n originalEvent: FocusEvent;\n}\n\nexport type KeyborgFocusOutEvent = CustomEvent<KeyborgFocusOutEventDetails>;\n\n/**\n * Guarantees that the native `focus` will be used\n */\nexport function nativeFocus(element: HTMLElement): void {\n const focus = element.focus as KeyborgFocus;\n\n if (focus.__keyborgNativeFocus) {\n focus.__keyborgNativeFocus.call(element);\n } else {\n element.focus();\n }\n}\n\n/**\n * Overrides the native `focus` and setups the keyborg focus event\n */\nexport function setupFocusEvent(win: Window): void {\n const kwin = win as WindowWithKeyborgFocusEvent;\n\n if (!_canOverrideNativeFocus) {\n _canOverrideNativeFocus = canOverrideNativeFocus(kwin);\n }\n\n const origFocus = kwin.HTMLElement.prototype.focus;\n\n if ((origFocus as KeyborgFocus).__keyborgNativeFocus) {\n // Already set up.\n return;\n }\n\n kwin.HTMLElement.prototype.focus = focus;\n\n const shadowTargets: Set<ShadowRoot> = new Set();\n\n const focusOutHandler = (e: FocusEvent) => {\n const target = e.target as HTMLElement;\n\n if (!target) {\n return;\n }\n\n const event: KeyborgFocusOutEvent = new CustomEvent(KEYBORG_FOCUSOUT, {\n cancelable: true,\n bubbles: true,\n // Allows the event to bubble past an open shadow root\n composed: true,\n detail: {\n originalEvent: e,\n },\n });\n\n target.dispatchEvent(event);\n };\n\n const focusInHandler = (e: FocusEvent) => {\n const target = e.target as HTMLElement;\n\n if (!target) {\n return;\n }\n\n let node: Node | null = target;\n const currentShadows: Set<ShadowRoot> = new Set();\n\n while (node) {\n if (node.nodeType === Node.DOCUMENT_FRAGMENT_NODE) {\n currentShadows.add(node as ShadowRoot);\n node = (node as ShadowRoot).host;\n } else {\n node = node.parentNode;\n }\n }\n\n for (const shadow of shadowTargets) {\n if (!currentShadows.has(shadow)) {\n shadow.removeEventListener(\"focusin\", focusInHandler, true);\n shadow.removeEventListener(\"focusout\", focusOutHandler, true);\n shadowTargets.delete(shadow);\n }\n }\n\n onFocusIn(target, (e.relatedTarget as HTMLElement | null) || undefined);\n };\n\n const onFocusIn = (\n target: Element,\n relatedTarget?: HTMLElement,\n originalEvent?: FocusEvent,\n ) => {\n const shadowRoot = target.shadowRoot;\n\n if (shadowRoot) {\n /**\n * https://bugs.chromium.org/p/chromium/issues/detail?id=1512028\n * focusin events don't bubble up through an open shadow root once focus is inside\n * once focus moves into a shadow root - we drop the same focusin handler there\n * keyborg's custom event will still bubble up since it is composed\n * event handlers should be cleaned up once focus leaves the shadow root.\n *\n * When a focusin event is dispatched from a shadow root, its target is the shadow root parent.\n * Each shadow root encounter requires a new capture listener.\n * Why capture? - we want to follow the focus event in order or descending nested shadow roots\n * When there are no more shadow root targets - dispatch the keyborg:focusin event\n *\n * 1. no focus event\n * > document - capture listener ✅\n * > shadow root 1\n * > shadow root 2\n * > shadow root 3\n * > focused element\n *\n * 2. focus event received by document listener\n * > document - capture listener ✅ (focus event here)\n * > shadow root 1 - capture listener ✅\n * > shadow root 2\n * > shadow root 3\n * > focused element\n\n * 3. focus event received by root l1 listener\n * > document - capture listener ✅\n * > shadow root 1 - capture listener ✅ (focus event here)\n * > shadow root 2 - capture listener ✅\n * > shadow root 3\n * > focused element\n *\n * 4. focus event received by root l2 listener\n * > document - capture listener ✅\n * > shadow root 1 - capture listener ✅\n * > shadow root 2 - capture listener ✅ (focus event here)\n * > shadow root 3 - capture listener ✅\n * > focused element\n *\n * 5. focus event received by root l3 listener, no more shadow root targets\n * > document - capture listener ✅\n * > shadow root 1 - capture listener ✅\n * > shadow root 2 - capture listener ✅\n * > shadow root 3 - capture listener ✅ (focus event here)\n * > focused element ✅ (no shadow root - dispatch keyborg event)\n */\n\n if (shadowTargets.has(shadowRoot)) {\n return;\n }\n\n shadowRoot.addEventListener(\"focusin\", focusInHandler, true);\n shadowRoot.addEventListener(\"focusout\", focusOutHandler, true);\n\n shadowTargets.add(shadowRoot);\n\n return;\n }\n\n const details: KeyborgFocusInEventDetails = {\n relatedTarget,\n originalEvent,\n };\n\n const event: KeyborgFocusInEvent = new CustomEvent(KEYBORG_FOCUSIN, {\n cancelable: true,\n bubbles: true,\n // Allows the event to bubble past an open shadow root\n composed: true,\n detail: details,\n });\n\n // Tabster (and other users) can still use the legacy details field - keeping for backwards compat\n event.details = details;\n\n if (_canOverrideNativeFocus || data.lastFocusedProgrammatically) {\n details.isFocusedProgrammatically =\n target === data.lastFocusedProgrammatically?.deref();\n\n data.lastFocusedProgrammatically = undefined;\n }\n\n target.dispatchEvent(event);\n };\n\n const data: KeyborgFocusEventData = (kwin.__keyborgData = {\n focusInHandler,\n focusOutHandler,\n shadowTargets,\n });\n\n kwin.document.addEventListener(\n \"focusin\",\n kwin.__keyborgData.focusInHandler,\n true,\n );\n\n kwin.document.addEventListener(\n \"focusout\",\n kwin.__keyborgData.focusOutHandler,\n true,\n );\n\n function focus(this: HTMLElement) {\n const keyborgNativeFocusEvent = (kwin as WindowWithKeyborgFocusEvent)\n .__keyborgData;\n\n if (keyborgNativeFocusEvent) {\n keyborgNativeFocusEvent.lastFocusedProgrammatically = new WeakRefInstance(\n this,\n );\n }\n\n // eslint-disable-next-line prefer-rest-params\n return origFocus.apply(this, arguments);\n }\n\n let activeElement = kwin.document.activeElement as Element | null;\n\n // If keyborg is created with the focus inside shadow root, we need\n // to go through the shadows up to make sure all relevant shadows\n // have focus handlers attached.\n while (activeElement && activeElement.shadowRoot) {\n onFocusIn(activeElement);\n activeElement = activeElement.shadowRoot.activeElement;\n }\n\n (focus as KeyborgFocus).__keyborgNativeFocus = origFocus;\n}\n\n/**\n * Removes keyborg event listeners and custom focus override\n * @param win The window that stores keyborg focus events\n */\nexport function disposeFocusEvent(win: Window): void {\n const kwin = win as WindowWithKeyborgFocusEvent;\n const proto = kwin.HTMLElement.prototype;\n const origFocus = (proto.focus as KeyborgFocus).__keyborgNativeFocus;\n const keyborgNativeFocusEvent = kwin.__keyborgData;\n\n if (keyborgNativeFocusEvent) {\n kwin.document.removeEventListener(\n \"focusin\",\n keyborgNativeFocusEvent.focusInHandler,\n true,\n );\n\n kwin.document.removeEventListener(\n \"focusout\",\n keyborgNativeFocusEvent.focusOutHandler,\n true,\n );\n\n for (const shadow of keyborgNativeFocusEvent.shadowTargets) {\n shadow.removeEventListener(\n \"focusin\",\n keyborgNativeFocusEvent.focusInHandler,\n true,\n );\n shadow.removeEventListener(\n \"focusout\",\n keyborgNativeFocusEvent.focusOutHandler,\n true,\n );\n }\n\n keyborgNativeFocusEvent.shadowTargets.clear();\n\n delete kwin.__keyborgData;\n }\n\n if (origFocus) {\n proto.focus = origFocus;\n }\n}\n\n/**\n * @param win The window that stores keyborg focus events\n * @returns The last element focused with element.focus()\n */\nexport function getLastFocusedProgrammatically(\n win: Window,\n): HTMLElement | null | undefined {\n const keyborgNativeFocusEvent = (win as WindowWithKeyborgFocusEvent)\n .__keyborgData;\n\n return keyborgNativeFocusEvent\n ? keyborgNativeFocusEvent.lastFocusedProgrammatically?.deref() || null\n : undefined;\n}\n","/*!\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n disposeFocusEvent,\n KeyborgFocusInEvent,\n KEYBORG_FOCUSIN,\n setupFocusEvent,\n} from \"./FocusEvent\";\nimport { Disposable, WeakRefInstance } from \"./WeakRefInstance\";\n\ninterface WindowWithKeyborg extends Window {\n __keyborg?: {\n core: KeyborgCore;\n refs: { [id: string]: Keyborg };\n };\n}\n\nconst _dismissTimeout = 500; // When a key from dismissKeys is pressed and the focus is not moved\n// during _dismissTimeout time, dismiss the keyboard navigation mode.\n\nlet _lastId = 0;\n\nexport interface KeyborgProps {\n // Keys to be used to trigger keyboard navigation mode. By default, any key will trigger\n // it. Could be limited to, for example, just Tab (or Tab and arrow keys).\n triggerKeys?: number[];\n // Keys to be used to dismiss keyboard navigation mode using keyboard (in addition to\n // mouse clicks which dismiss it). For example, Esc could be used to dismiss.\n dismissKeys?: number[];\n}\n\nexport type KeyborgCallback = (isNavigatingWithKeyboard: boolean) => void;\n\n/**\n * Source of truth for all the keyborg core instances and the current keyboard navigation state\n */\nexport class KeyborgState {\n private __keyborgCoreRefs: { [id: string]: WeakRefInstance<KeyborgCore> } =\n {};\n private _isNavigatingWithKeyboard = false;\n\n add(keyborg: KeyborgCore): void {\n const id = keyborg.id;\n\n if (!(id in this.__keyborgCoreRefs)) {\n this.__keyborgCoreRefs[id] = new WeakRefInstance<KeyborgCore>(keyborg);\n }\n }\n\n remove(id: string): void {\n delete this.__keyborgCoreRefs[id];\n\n if (Object.keys(this.__keyborgCoreRefs).length === 0) {\n this._isNavigatingWithKeyboard = false;\n }\n }\n\n setVal(isNavigatingWithKeyboard: boolean): void {\n if (this._isNavigatingWithKeyboard === isNavigatingWithKeyboard) {\n return;\n }\n\n this._isNavigatingWithKeyboard = isNavigatingWithKeyboard;\n\n for (const id of Object.keys(this.__keyborgCoreRefs)) {\n const ref = this.__keyborgCoreRefs[id];\n const keyborg = ref.deref();\n\n if (keyborg) {\n keyborg.update(isNavigatingWithKeyboard);\n } else {\n this.remove(id);\n }\n }\n }\n\n getVal(): boolean {\n return this._isNavigatingWithKeyboard;\n }\n}\n\nconst _state = new KeyborgState();\n\n/**\n * Manages a collection of Keyborg instances in a window/document and updates keyborg state\n */\nclass KeyborgCore implements Disposable {\n readonly id: string;\n\n private _win?: WindowWithKeyborg;\n private _isMouseUsedTimer: number | undefined;\n private _dismissTimer: number | undefined;\n private _triggerKeys?: Set<number>;\n private _dismissKeys?: Set<number>;\n\n constructor(win: WindowWithKeyborg, props?: KeyborgProps) {\n this.id = \"c\" + ++_lastId;\n this._win = win;\n const doc = win.document;\n\n if (props) {\n const triggerKeys = props.triggerKeys;\n const dismissKeys = props.dismissKeys;\n\n if (triggerKeys?.length) {\n this._triggerKeys = new Set(triggerKeys);\n }\n\n if (dismissKeys?.length) {\n this._dismissKeys = new Set(dismissKeys);\n }\n }\n\n doc.addEventListener(KEYBORG_FOCUSIN, this._onFocusIn, true); // Capture!\n doc.addEventListener(\"mousedown\", this._onMouseDown, true); // Capture!\n win.addEventListener(\"keydown\", this._onKeyDown, true); // Capture!\n\n setupFocusEvent(win);\n\n _state.add(this);\n }\n\n dispose(): void {\n const win = this._win;\n\n if (win) {\n if (this._isMouseUsedTimer) {\n win.clearTimeout(this._isMouseUsedTimer);\n this._isMouseUsedTimer = undefined;\n }\n\n if (this._dismissTimer) {\n win.clearTimeout(this._dismissTimer);\n this._dismissTimer = undefined;\n }\n\n disposeFocusEvent(win);\n\n const doc = win.document;\n\n doc.removeEventListener(KEYBORG_FOCUSIN, this._onFocusIn, true); // Capture!\n doc.removeEventListener(\"mousedown\", this._onMouseDown, true); // Capture!\n win.removeEventListener(\"keydown\", this._onKeyDown, true); // Capture!\n\n delete this._win;\n\n _state.remove(this.id);\n }\n }\n\n isDisposed(): boolean {\n return !!this._win;\n }\n\n /**\n * Updates all keyborg instances with the keyboard navigation state\n */\n update(isNavigatingWithKeyboard: boolean): void {\n const keyborgs = this._win?.__keyborg?.refs;\n\n if (keyborgs) {\n for (const id of Object.keys(keyborgs)) {\n Keyborg.update(keyborgs[id], isNavigatingWithKeyboard);\n }\n }\n }\n\n private _onFocusIn = (e: KeyborgFocusInEvent) => {\n // When the focus is moved not programmatically and without keydown events,\n // it is likely that the focus is moved by screen reader (as it might swallow\n // the events when the screen reader shortcuts are used). The screen reader\n // usage is keyboard navigation.\n\n if (this._isMouseUsedTimer) {\n // There was a mouse event recently.\n return;\n }\n\n if (_state.getVal()) {\n return;\n }\n\n const details = e.detail;\n\n if (!details.relatedTarget) {\n return;\n }\n\n if (\n details.isFocusedProgrammatically ||\n details.isFocusedProgrammatically === undefined\n ) {\n // The element is focused programmatically, or the programmatic focus detection\n // is not working.\n return;\n }\n\n _state.setVal(true);\n };\n\n private _onMouseDown = (e: MouseEvent): void => {\n if (\n e.buttons === 0 ||\n (e.clientX === 0 && e.clientY === 0 && e.screenX === 0 && e.screenY === 0)\n ) {\n // This is most likely an event triggered by the screen reader to perform\n // an action on an element, do not dismiss the keyboard navigation mode.\n return;\n }\n\n const win = this._win;\n\n if (win) {\n if (this._isMouseUsedTimer) {\n win.clearTimeout(this._isMouseUsedTimer);\n }\n\n this._isMouseUsedTimer = win.setTimeout(() => {\n delete this._isMouseUsedTimer;\n }, 1000); // Keeping the indication of the mouse usage for some time.\n }\n\n _state.setVal(false);\n };\n\n private _onKeyDown = (e: KeyboardEvent): void => {\n const isNavigatingWithKeyboard = _state.getVal();\n\n if (isNavigatingWithKeyboard) {\n if (this._shouldDismissKeyboardNavigation(e)) {\n this._scheduleDismiss();\n }\n } else {\n if (this._shouldTriggerKeyboardNavigation(e)) {\n _state.setVal(true);\n }\n }\n };\n\n /**\n * @returns whether the keyboard event should trigger keyboard navigation mode\n */\n private _shouldTriggerKeyboardNavigation(e: KeyboardEvent) {\n // TODO Some rich text fields can allow Tab key for indentation so it doesn't\n // need to be a navigation key. If there is a bug regarding that we should revisit\n if (e.key === \"Tab\") {\n return true;\n }\n\n const activeElement = this._win?.document\n .activeElement as HTMLElement | null;\n const isTriggerKey = !this._triggerKeys || this._triggerKeys.has(e.keyCode);\n\n const isEditable =\n activeElement &&\n (activeElement.tagName === \"INPUT\" ||\n activeElement.tagName === \"TEXTAREA\" ||\n activeElement.isContentEditable);\n\n return isTriggerKey && !isEditable;\n }\n\n /**\n * @returns whether the keyboard event should dismiss keyboard navigation mode\n */\n private _shouldDismissKeyboardNavigation(e: KeyboardEvent) {\n return this._dismissKeys?.has(e.keyCode);\n }\n\n private _scheduleDismiss(): void {\n const win = this._win;\n\n if (win) {\n if (this._dismissTimer) {\n win.clearTimeout(this._dismissTimer);\n this._dismissTimer = undefined;\n }\n\n const was = win.document.activeElement;\n\n this._dismissTimer = win.setTimeout(() => {\n this._dismissTimer = undefined;\n\n const cur = win.document.activeElement;\n\n if (was && cur && was === cur) {\n // Esc was pressed, currently focused element hasn't changed.\n // Just dismiss the keyboard navigation mode.\n _state.setVal(false);\n }\n }, _dismissTimeout);\n }\n }\n}\n\n/**\n * Used to determine the keyboard navigation state\n */\nexport class Keyborg {\n private _id: string;\n private _win?: WindowWithKeyborg;\n private _core?: KeyborgCore;\n private _cb: KeyborgCallback[] = [];\n\n static create(win: WindowWithKeyborg, props?: KeyborgProps): Keyborg {\n return new Keyborg(win, props);\n }\n\n static dispose(instance: Keyborg): void {\n instance.dispose();\n }\n\n /**\n * Updates all subscribed callbacks with the keyboard navigation state\n */\n static update(instance: Keyborg, isNavigatingWithKeyboard: boolean): void {\n instance._cb.forEach((callback) => callback(isNavigatingWithKeyboard));\n }\n\n private constructor(win: WindowWithKeyborg, props?: KeyborgProps) {\n this._id = \"k\" + ++_lastId;\n this._win = win;\n\n const current = win.__keyborg;\n\n if (current) {\n this._core = current.core;\n current.refs[this._id] = this;\n } else {\n this._core = new KeyborgCore(win, props);\n win.__keyborg = {\n core: this._core,\n refs: { [this._id]: this },\n };\n }\n }\n\n private dispose(): void {\n const current = this._win?.__keyborg;\n\n if (current?.refs[this._id]) {\n delete current.refs[this._id];\n\n if (Object.keys(current.refs).length === 0) {\n current.core.dispose();\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n delete this._win!.__keyborg;\n }\n } else if (process.env.NODE_ENV !== \"production\") {\n console.error(\n `Keyborg instance ${this._id} is being disposed incorrectly.`,\n );\n }\n\n this._cb = [];\n delete this._core;\n delete this._win;\n }\n\n /**\n * @returns Whether the user is navigating with keyboard\n */\n isNavigatingWithKeyboard(): boolean {\n return _state.getVal();\n }\n\n /**\n * @param callback - Called when the keyboard navigation state changes\n */\n subscribe(callback: KeyborgCallback): void {\n this._cb.push(callback);\n }\n\n /**\n * @param callback - Registered with subscribe\n */\n unsubscribe(callback: KeyborgCallback): void {\n const index = this._cb.indexOf(callback);\n\n if (index >= 0) {\n this._cb.splice(index, 1);\n }\n }\n\n /**\n * Manually set the keyboard navigtion state\n */\n setVal(isNavigatingWithKeyboard: boolean): void {\n _state.setVal(isNavigatingWithKeyboard);\n }\n}\n\nexport function createKeyborg(win: Window, props?: KeyborgProps): Keyborg {\n return Keyborg.create(win, props);\n}\n\nexport function disposeKeyborg(instance: Keyborg) {\n Keyborg.dispose(instance);\n}\n","/*!\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport type { Keyborg, KeyborgCallback } from \"./Keyborg\";\nexport { createKeyborg, disposeKeyborg } from \"./Keyborg\";\n\nexport type {\n KeyborgFocusInEvent,\n KeyborgFocusInEventDetails,\n KeyborgFocusOutEvent,\n KeyborgFocusOutEventDetails,\n} from \"./FocusEvent\";\nexport {\n getLastFocusedProgrammatically,\n nativeFocus,\n KEYBORG_FOCUSIN,\n KEYBORG_FOCUSOUT,\n} from \"./FocusEvent\";\n\nexport const version = process.env.PKG_VERSION;\n"],"mappings":";AAMO,IAAM,iBAAiB,OAAO,YAAY;AAc1C,IAAM,kBAAN,MAAqD;AAAA,EAI1D,YAAY,UAAa;AACvB,QAAI,kBAAkB,OAAO,aAAa,UAAU;AAClD,WAAK,WAAW,IAAI,QAAQ,QAAQ;AAAA,IACtC,OAAO;AACL,WAAK,YAAY;AAAA,IACnB;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,QAAuB;AAnCzB;AAoCI,QAAI;AAEJ,QAAI,KAAK,UAAU;AACjB,kBAAW,UAAK,aAAL,mBAAe;AAE1B,UAAI,CAAC,UAAU;AACb,eAAO,KAAK;AAAA,MACd;AAAA,IACF,OAAO;AACL,iBAAW,KAAK;AAChB,WAAK,0CAAyB,eAAzB,mCAAyC;AAC5C,eAAO,KAAK;AAAA,MACd;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AACF;;;AC/CO,IAAM,kBAAkB;AACxB,IAAM,mBAAmB;AAwBhC,SAAS,uBAAuB,KAAsB;AACpD,QAAM,cAAe,IAAoC;AACzD,QAAM,YAAY,YAAY,UAAU;AAExC,MAAI,sBAAsB;AAE1B,cAAY,UAAU,QAAQ,SAAS,QAAc;AACnD,0BAAsB;AAAA,EACxB;AAEA,QAAM,MAAM,IAAI,SAAS,cAAc,QAAQ;AAE/C,MAAI,MAAM;AAEV,cAAY,UAAU,QAAQ;AAE9B,SAAO;AACT;AAEA,IAAI,0BAA0B;AAyBvB,SAAS,YAAY,SAA4B;AACtD,QAAM,QAAQ,QAAQ;AAEtB,MAAI,MAAM,sBAAsB;AAC9B,UAAM,qBAAqB,KAAK,OAAO;AAAA,E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AO,CAAC;AAAA,IAC1B;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,OAAO,0BAAyC;AAC9C,WAAO,OAAO,wBAAwB;AAAA,EACxC;AACF;AAEO,SAAS,cAAc,KAAa,OAA+B;AACxE,SAAO,QAAQ,OAAO,KAAK,KAAK;AAClC;AAEO,SAAS,eAAe,UAAmB;AAChD,UAAQ,QAAQ,QAAQ;AAC1B;;;AC5XO,IAAM,UAAU;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/WeakRefInstance.ts","../../src/FocusEvent.ts","../../src/Keyborg.ts","../../src/index.ts"],"sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License.\n */\n\n// IE11 compat, checks if WeakRef is supported\nexport const _canUseWeakRef = typeof WeakRef !== \"undefined\";\n\n/**\n * Allows disposable instances to be used\n */\nexport interface Disposable {\n isDisposed?(): boolean;\n}\n\n/**\n * WeakRef wrapper around a HTMLElement that also supports IE11\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakRef}\n * @internal\n */\nexport class WeakRefInstance<T extends Disposable | object> {\n private _weakRef?: WeakRef<T>;\n private _instance?: T;\n\n constructor(instance: T) {\n if (_canUseWeakRef && typeof instance === \"object\") {\n this._weakRef = new WeakRef(instance);\n } else {\n this._instance = instance;\n }\n }\n\n /**\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakRef/deref}\n */\n deref(): T | undefined {\n let instance: T | undefined;\n\n if (this._weakRef) {\n instance = this._weakRef?.deref();\n\n if (!instance) {\n delete this._weakRef;\n }\n } else {\n instance = this._instance;\n if ((instance as Disposable)?.isDisposed?.()) {\n delete this._instance;\n }\n }\n\n return instance;\n }\n}\n","/*!\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License.\n */\nimport { WeakRefInstance } from \"./WeakRefInstance\";\n\nexport const KEYBORG_FOCUSIN = \"keyborg:focusin\";\nexport const KEYBORG_FOCUSOUT = \"keyborg:focusout\";\n\ninterface KeyborgFocus {\n /**\n * This is the native `focus` function that is retained so that it can be restored when keyborg is disposed\n */\n __keyborgNativeFocus?: (options?: FocusOptions | undefined) => void;\n}\n\ninterface KeyborgFocusEventData {\n focusInHandler: (e: FocusEvent) => void;\n focusOutHandler: (e: FocusEvent) => void;\n lastFocusedProgrammatically?: WeakRefInstance<HTMLElement>;\n shadowTargets: Set<WeakRefInstance<ShadowRoot>>;\n}\n\n/**\n * Extends the global window with keyborg focus event data\n */\ninterface WindowWithKeyborgFocusEvent extends Window {\n HTMLElement: typeof HTMLElement;\n __keyborgData?: KeyborgFocusEventData;\n}\n\nfunction canOverrideNativeFocus(win: Window): boolean {\n const HTMLElement = (win as WindowWithKeyborgFocusEvent).HTMLElement;\n const origFocus = HTMLElement.prototype.focus;\n\n let isCustomFocusCalled = false;\n\n HTMLElement.prototype.focus = function focus(): void {\n isCustomFocusCalled = true;\n };\n\n const btn = win.document.createElement(\"button\");\n\n btn.focus();\n\n HTMLElement.prototype.focus = origFocus;\n\n return isCustomFocusCalled;\n}\n\nlet _canOverrideNativeFocus = false;\n\nexport interface KeyborgFocusInEventDetails {\n relatedTarget?: HTMLElement;\n isFocusedProgrammatically?: boolean;\n originalEvent?: FocusEvent;\n}\n\nexport interface KeyborgFocusInEvent\n extends CustomEvent<KeyborgFocusInEventDetails> {\n /**\n * @deprecated - used `event.detail`\n */\n details?: KeyborgFocusInEventDetails;\n}\n\nexport interface KeyborgFocusOutEventDetails {\n originalEvent: FocusEvent;\n}\n\nexport type KeyborgFocusOutEvent = CustomEvent<KeyborgFocusOutEventDetails>;\n\n/**\n * Guarantees that the native `focus` will be used\n */\nexport function nativeFocus(element: HTMLElement): void {\n const focus = element.focus as KeyborgFocus;\n\n if (focus.__keyborgNativeFocus) {\n focus.__keyborgNativeFocus.call(element);\n } else {\n element.focus();\n }\n}\n\n/**\n * Overrides the native `focus` and setups the keyborg focus event\n */\nexport function setupFocusEvent(win: Window): void {\n const kwin = win as WindowWithKeyborgFocusEvent;\n\n if (!_canOverrideNativeFocus) {\n _canOverrideNativeFocus = canOverrideNativeFocus(kwin);\n }\n\n const origFocus = kwin.HTMLElement.prototype.focus;\n\n if ((origFocus as KeyborgFocus).__keyborgNativeFocus) {\n // Already set up.\n return;\n }\n\n kwin.HTMLElement.prototype.focus = focus;\n\n const shadowTargets: Set<WeakRefInstance<ShadowRoot>> = new Set();\n\n const focusOutHandler = (e: FocusEvent) => {\n const target = e.target as HTMLElement;\n\n if (!target) {\n return;\n }\n\n const event: KeyborgFocusOutEvent = new CustomEvent(KEYBORG_FOCUSOUT, {\n cancelable: true,\n bubbles: true,\n // Allows the event to bubble past an open shadow root\n composed: true,\n detail: {\n originalEvent: e,\n },\n });\n\n target.dispatchEvent(event);\n };\n\n const focusInHandler = (e: FocusEvent) => {\n const target = e.target as HTMLElement;\n\n if (!target) {\n return;\n }\n\n let node: Node | null | undefined = e.composedPath()[0] as\n | Node\n | null\n | undefined;\n\n const currentShadows: Set<ShadowRoot> = new Set();\n\n while (node) {\n if (node.nodeType === Node.DOCUMENT_FRAGMENT_NODE) {\n currentShadows.add(node as ShadowRoot);\n node = (node as ShadowRoot).host;\n } else {\n node = node.parentNode;\n }\n }\n\n for (const shadowRootWeakRef of shadowTargets) {\n const shadowRoot = shadowRootWeakRef.deref();\n\n if (!shadowRoot || !currentShadows.has(shadowRoot)) {\n shadowTargets.delete(shadowRootWeakRef);\n\n if (shadowRoot) {\n shadowRoot.removeEventListener(\"focusin\", focusInHandler, true);\n shadowRoot.removeEventListener(\"focusout\", focusOutHandler, true);\n }\n }\n }\n\n onFocusIn(target, (e.relatedTarget as HTMLElement | null) || undefined);\n };\n\n const onFocusIn = (\n target: Element,\n relatedTarget?: HTMLElement,\n originalEvent?: FocusEvent,\n ) => {\n const shadowRoot = target.shadowRoot;\n\n if (shadowRoot) {\n /**\n * https://bugs.chromium.org/p/chromium/issues/detail?id=1512028\n * focusin events don't bubble up through an open shadow root once focus is inside\n * once focus moves into a shadow root - we drop the same focusin handler there\n * keyborg's custom event will still bubble up since it is composed\n * event handlers should be cleaned up once focus leaves the shadow root.\n *\n * When a focusin event is dispatched from a shadow root, its target is the shadow root parent.\n * Each shadow root encounter requires a new capture listener.\n * Why capture? - we want to follow the focus event in order or descending nested shadow roots\n * When there are no more shadow root targets - dispatch the keyborg:focusin event\n *\n * 1. no focus event\n * > document - capture listener ✅\n * > shadow root 1\n * > shadow root 2\n * > shadow root 3\n * > focused element\n *\n * 2. focus event received by document listener\n * > document - capture listener ✅ (focus event here)\n * > shadow root 1 - capture listener ✅\n * > shadow root 2\n * > shadow root 3\n * > focused element\n\n * 3. focus event received by root l1 listener\n * > document - capture listener ✅\n * > shadow root 1 - capture listener ✅ (focus event here)\n * > shadow root 2 - capture listener ✅\n * > shadow root 3\n * > focused element\n *\n * 4. focus event received by root l2 listener\n * > document - capture listener ✅\n * > shadow root 1 - capture listener ✅\n * > shadow root 2 - capture listener ✅ (focus event here)\n * > shadow root 3 - capture listener ✅\n * > focused element\n *\n * 5. focus event received by root l3 listener, no more shadow root targets\n * > document - capture listener ✅\n * > shadow root 1 - capture listener ✅\n * > shadow root 2 - capture listener ✅\n * > shadow root 3 - capture listener ✅ (focus event here)\n * > focused element ✅ (no shadow root - dispatch keyborg event)\n */\n\n for (const shadowRootWeakRef of shadowTargets) {\n if (shadowRootWeakRef.deref() === shadowRoot) {\n return;\n }\n }\n\n shadowRoot.addEventListener(\"focusin\", focusInHandler, true);\n shadowRoot.addEventListener(\"focusout\", focusOutHandler, true);\n\n shadowTargets.add(new WeakRefInstance(shadowRoot));\n\n return;\n }\n\n const details: KeyborgFocusInEventDetails = {\n relatedTarget,\n originalEvent,\n };\n\n const event: KeyborgFocusInEvent = new CustomEvent(KEYBORG_FOCUSIN, {\n cancelable: true,\n bubbles: true,\n // Allows the event to bubble past an open shadow root\n composed: true,\n detail: details,\n });\n\n // Tabster (and other users) can still use the legacy details field - keeping for backwards compat\n event.details = details;\n\n if (_canOverrideNativeFocus || data.lastFocusedProgrammatically) {\n details.isFocusedProgrammatically =\n target === data.lastFocusedProgrammatically?.deref();\n\n data.lastFocusedProgrammatically = undefined;\n }\n\n target.dispatchEvent(event);\n };\n\n const data: KeyborgFocusEventData = (kwin.__keyborgData = {\n focusInHandler,\n focusOutHandler,\n shadowTargets,\n });\n\n kwin.document.addEventListener(\n \"focusin\",\n kwin.__keyborgData.focusInHandler,\n true,\n );\n\n kwin.document.addEventListener(\n \"focusout\",\n kwin.__keyborgData.focusOutHandler,\n true,\n );\n\n function focus(this: HTMLElement) {\n const keyborgNativeFocusEvent = (kwin as WindowWithKeyborgFocusEvent)\n .__keyborgData;\n\n if (keyborgNativeFocusEvent) {\n keyborgNativeFocusEvent.lastFocusedProgrammatically = new WeakRefInstance(\n this,\n );\n }\n\n // eslint-disable-next-line prefer-rest-params\n return origFocus.apply(this, arguments);\n }\n\n let activeElement = kwin.document.activeElement as Element | null;\n\n // If keyborg is created with the focus inside shadow root, we need\n // to go through the shadows up to make sure all relevant shadows\n // have focus handlers attached.\n while (activeElement && activeElement.shadowRoot) {\n onFocusIn(activeElement);\n activeElement = activeElement.shadowRoot.activeElement;\n }\n\n (focus as KeyborgFocus).__keyborgNativeFocus = origFocus;\n}\n\n/**\n * Removes keyborg event listeners and custom focus override\n * @param win The window that stores keyborg focus events\n */\nexport function disposeFocusEvent(win: Window): void {\n const kwin = win as WindowWithKeyborgFocusEvent;\n const proto = kwin.HTMLElement.prototype;\n const origFocus = (proto.focus as KeyborgFocus).__keyborgNativeFocus;\n const keyborgNativeFocusEvent = kwin.__keyborgData;\n\n if (keyborgNativeFocusEvent) {\n kwin.document.removeEventListener(\n \"focusin\",\n keyborgNativeFocusEvent.focusInHandler,\n true,\n );\n\n kwin.document.removeEventListener(\n \"focusout\",\n keyborgNativeFocusEvent.focusOutHandler,\n true,\n );\n\n for (const shadowRootWeakRef of keyborgNativeFocusEvent.shadowTargets) {\n const shadowRoot = shadowRootWeakRef.deref();\n\n if (shadowRoot) {\n shadowRoot.removeEventListener(\n \"focusin\",\n keyborgNativeFocusEvent.focusInHandler,\n true,\n );\n shadowRoot.removeEventListener(\n \"focusout\",\n keyborgNativeFocusEvent.focusOutHandler,\n true,\n );\n }\n }\n\n keyborgNativeFocusEvent.shadowTargets.clear();\n\n delete kwin.__keyborgData;\n }\n\n if (origFocus) {\n proto.focus = origFocus;\n }\n}\n\n/**\n * @param win The window that stores keyborg focus events\n * @returns The last element focused with element.focus()\n */\nexport function getLastFocusedProgrammatically(\n win: Window,\n): HTMLElement | null | undefined {\n const keyborgNativeFocusEvent = (win as WindowWithKeyborgFocusEvent)\n .__keyborgData;\n\n return keyborgNativeFocusEvent\n ? keyborgNativeFocusEvent.lastFocusedProgrammatically?.deref() || null\n : undefined;\n}\n","/*!\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n disposeFocusEvent,\n KeyborgFocusInEvent,\n KEYBORG_FOCUSIN,\n setupFocusEvent,\n} from \"./FocusEvent\";\nimport { Disposable } from \"./WeakRefInstance\";\n\ninterface WindowWithKeyborg extends Window {\n __keyborg?: {\n core: KeyborgCore;\n refs: { [id: string]: Keyborg };\n };\n}\n\nconst _dismissTimeout = 500; // When a key from dismissKeys is pressed and the focus is not moved\n// during _dismissTimeout time, dismiss the keyboard navigation mode.\n\nlet _lastId = 0;\n\nexport interface KeyborgProps {\n // Keys to be used to trigger keyboard navigation mode. By default, any key will trigger\n // it. Could be limited to, for example, just Tab (or Tab and arrow keys).\n triggerKeys?: number[];\n // Keys to be used to dismiss keyboard navigation mode using keyboard (in addition to\n // mouse clicks which dismiss it). For example, Esc could be used to dismiss.\n dismissKeys?: number[];\n}\n\nexport type KeyborgCallback = (isNavigatingWithKeyboard: boolean) => void;\n\n/**\n * Manages a collection of Keyborg instances in a window/document and updates keyborg state\n */\nclass KeyborgCore implements Disposable {\n readonly id: string;\n\n private _win?: WindowWithKeyborg;\n private _isMouseOrTouchUsedTimer: number | undefined;\n private _dismissTimer: number | undefined;\n private _triggerKeys?: Set<number>;\n private _dismissKeys?: Set<number>;\n private _isNavigatingWithKeyboard_DO_NOT_USE = false;\n\n constructor(win: WindowWithKeyborg, props?: KeyborgProps) {\n this.id = \"c\" + ++_lastId;\n this._win = win;\n const doc = win.document;\n\n if (props) {\n const triggerKeys = props.triggerKeys;\n const dismissKeys = props.dismissKeys;\n\n if (triggerKeys?.length) {\n this._triggerKeys = new Set(triggerKeys);\n }\n\n if (dismissKeys?.length) {\n this._dismissKeys = new Set(dismissKeys);\n }\n }\n\n doc.addEventListener(KEYBORG_FOCUSIN, this._onFocusIn, true); // Capture!\n doc.addEventListener(\"mousedown\", this._onMouseDown, true); // Capture!\n win.addEventListener(\"keydown\", this._onKeyDown, true); // Capture!\n\n doc.addEventListener(\"touchstart\", this._onMouseOrTouch, true); // Capture!\n doc.addEventListener(\"touchend\", this._onMouseOrTouch, true); // Capture!\n doc.addEventListener(\"touchcancel\", this._onMouseOrTouch, true); // Capture!\n\n setupFocusEvent(win);\n }\n\n get isNavigatingWithKeyboard() {\n return this._isNavigatingWithKeyboard_DO_NOT_USE;\n }\n\n set isNavigatingWithKeyboard(val: boolean) {\n if (this._isNavigatingWithKeyboard_DO_NOT_USE !== val) {\n this._isNavigatingWithKeyboard_DO_NOT_USE = val;\n this.update();\n }\n }\n\n dispose(): void {\n const win = this._win;\n\n if (win) {\n if (this._isMouseOrTouchUsedTimer) {\n win.clearTimeout(this._isMouseOrTouchUsedTimer);\n this._isMouseOrTouchUsedTimer = undefined;\n }\n\n if (this._dismissTimer) {\n win.clearTimeout(this._dismissTimer);\n this._dismissTimer = undefined;\n }\n\n disposeFocusEvent(win);\n\n const doc = win.document;\n\n doc.removeEventListener(KEYBORG_FOCUSIN, this._onFocusIn, true); // Capture!\n doc.removeEventListener(\"mousedown\", this._onMouseDown, true); // Capture!\n win.removeEventListener(\"keydown\", this._onKeyDown, true); // Capture!\n\n doc.removeEventListener(\"touchstart\", this._onMouseOrTouch, true); // Capture!\n doc.removeEventListener(\"touchend\", this._onMouseOrTouch, true); // Capture!\n doc.removeEventListener(\"touchcancel\", this._onMouseOrTouch, true); // Capture!\n\n delete this._win;\n }\n }\n\n isDisposed(): boolean {\n return !!this._win;\n }\n\n /**\n * Updates all keyborg instances with the keyboard navigation state\n */\n update(): void {\n const keyborgs = this._win?.__keyborg?.refs;\n\n if (keyborgs) {\n for (const id of Object.keys(keyborgs)) {\n Keyborg.update(keyborgs[id], this.isNavigatingWithKeyboard);\n }\n }\n }\n\n private _onFocusIn = (e: KeyborgFocusInEvent) => {\n // When the focus is moved not programmatically and without keydown events,\n // it is likely that the focus is moved by screen reader (as it might swallow\n // the events when the screen reader shortcuts are used). The screen reader\n // usage is keyboard navigation.\n\n if (this._isMouseOrTouchUsedTimer) {\n // There was a mouse or touch event recently.\n return;\n }\n\n if (this.isNavigatingWithKeyboard) {\n return;\n }\n\n const details = e.detail;\n\n if (!details.relatedTarget) {\n return;\n }\n\n if (\n details.isFocusedProgrammatically ||\n details.isFocusedProgrammatically === undefined\n ) {\n // The element is focused programmatically, or the programmatic focus detection\n // is not working.\n return;\n }\n\n this.isNavigatingWithKeyboard = true;\n };\n\n private _onMouseDown = (e: MouseEvent): void => {\n if (\n e.buttons === 0 ||\n (e.clientX === 0 && e.clientY === 0 && e.screenX === 0 && e.screenY === 0)\n ) {\n // This is most likely an event triggered by the screen reader to perform\n // an action on an element, do not dismiss the keyboard navigation mode.\n return;\n }\n\n this._onMouseOrTouch();\n };\n\n private _onMouseOrTouch = (): void => {\n const win = this._win;\n\n if (win) {\n if (this._isMouseOrTouchUsedTimer) {\n win.clearTimeout(this._isMouseOrTouchUsedTimer);\n }\n\n this._isMouseOrTouchUsedTimer = win.setTimeout(() => {\n delete this._isMouseOrTouchUsedTimer;\n }, 1000); // Keeping the indication of mouse or touch usage for some time.\n }\n\n this.isNavigatingWithKeyboard = false;\n };\n\n private _onKeyDown = (e: KeyboardEvent): void => {\n const isNavigatingWithKeyboard = this.isNavigatingWithKeyboard;\n\n if (isNavigatingWithKeyboard) {\n if (this._shouldDismissKeyboardNavigation(e)) {\n this._scheduleDismiss();\n }\n } else {\n if (this._shouldTriggerKeyboardNavigation(e)) {\n this.isNavigatingWithKeyboard = true;\n }\n }\n };\n\n /**\n * @returns whether the keyboard event should trigger keyboard navigation mode\n */\n private _shouldTriggerKeyboardNavigation(e: KeyboardEvent) {\n // TODO Some rich text fields can allow Tab key for indentation so it doesn't\n // need to be a navigation key. If there is a bug regarding that we should revisit\n if (e.key === \"Tab\") {\n return true;\n }\n\n const activeElement = this._win?.document\n .activeElement as HTMLElement | null;\n const isTriggerKey = !this._triggerKeys || this._triggerKeys.has(e.keyCode);\n\n const isEditable =\n activeElement &&\n (activeElement.tagName === \"INPUT\" ||\n activeElement.tagName === \"TEXTAREA\" ||\n activeElement.isContentEditable);\n\n return isTriggerKey && !isEditable;\n }\n\n /**\n * @returns whether the keyboard event should dismiss keyboard navigation mode\n */\n private _shouldDismissKeyboardNavigation(e: KeyboardEvent) {\n return this._dismissKeys?.has(e.keyCode);\n }\n\n private _scheduleDismiss(): void {\n const win = this._win;\n\n if (win) {\n if (this._dismissTimer) {\n win.clearTimeout(this._dismissTimer);\n this._dismissTimer = undefined;\n }\n\n const was = win.document.activeElement;\n\n this._dismissTimer = win.setTimeout(() => {\n this._dismissTimer = undefined;\n\n const cur = win.document.activeElement;\n\n if (was && cur && was === cur) {\n // Esc was pressed, currently focused element hasn't changed.\n // Just dismiss the keyboard navigation mode.\n this.isNavigatingWithKeyboard = false;\n }\n }, _dismissTimeout);\n }\n }\n}\n\n/**\n * Used to determine the keyboard navigation state\n */\nexport class Keyborg {\n private _id: string;\n private _win?: WindowWithKeyborg;\n private _core?: KeyborgCore;\n private _cb: KeyborgCallback[] = [];\n\n static create(win: WindowWithKeyborg, props?: KeyborgProps): Keyborg {\n return new Keyborg(win, props);\n }\n\n static dispose(instance: Keyborg): void {\n instance.dispose();\n }\n\n /**\n * Updates all subscribed callbacks with the keyboard navigation state\n */\n static update(instance: Keyborg, isNavigatingWithKeyboard: boolean): void {\n instance._cb.forEach((callback) => callback(isNavigatingWithKeyboard));\n }\n\n private constructor(win: WindowWithKeyborg, props?: KeyborgProps) {\n this._id = \"k\" + ++_lastId;\n this._win = win;\n\n const current = win.__keyborg;\n\n if (current) {\n this._core = current.core;\n current.refs[this._id] = this;\n } else {\n this._core = new KeyborgCore(win, props);\n win.__keyborg = {\n core: this._core,\n refs: { [this._id]: this },\n };\n }\n }\n\n private dispose(): void {\n const current = this._win?.__keyborg;\n\n if (current?.refs[this._id]) {\n delete current.refs[this._id];\n\n if (Object.keys(current.refs).length === 0) {\n current.core.dispose();\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n delete this._win!.__keyborg;\n }\n } else if (process.env.NODE_ENV !== \"production\") {\n console.error(\n `Keyborg instance ${this._id} is being disposed incorrectly.`,\n );\n }\n\n this._cb = [];\n delete this._core;\n delete this._win;\n }\n\n /**\n * @returns Whether the user is navigating with keyboard\n */\n isNavigatingWithKeyboard(): boolean {\n return !!this._core?.isNavigatingWithKeyboard;\n }\n\n /**\n * @param callback - Called when the keyboard navigation state changes\n */\n subscribe(callback: KeyborgCallback): void {\n this._cb.push(callback);\n }\n\n /**\n * @param callback - Registered with subscribe\n */\n unsubscribe(callback: KeyborgCallback): void {\n const index = this._cb.indexOf(callback);\n\n if (index >= 0) {\n this._cb.splice(index, 1);\n }\n }\n\n /**\n * Manually set the keyboard navigtion state\n */\n setVal(isNavigatingWithKeyboard: boolean): void {\n if (this._core) {\n this._core.isNavigatingWithKeyboard = isNavigatingWithKeyboard;\n }\n }\n}\n\nexport function createKeyborg(win: Window, props?: KeyborgProps): Keyborg {\n return Keyborg.create(win, props);\n}\n\nexport function disposeKeyborg(instance: Keyborg) {\n Keyborg.dispose(instance);\n}\n","/*!\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport type { Keyborg, KeyborgCallback } from \"./Keyborg\";\nexport { createKeyborg, disposeKeyborg } from \"./Keyborg\";\n\nexport type {\n KeyborgFocusInEvent,\n KeyborgFocusInEventDetails,\n KeyborgFocusOutEvent,\n KeyborgFocusOutEventDetails,\n} from \"./FocusEvent\";\nexport {\n getLastFocusedProgrammatically,\n nativeFocus,\n KEYBORG_FOCUSIN,\n KEYBORG_FOCUSOUT,\n} from \"./FocusEvent\";\n\nexport const version = process.env.PKG_VERSION;\n"],"mappings":";AAMO,IAAM,iBAAiB,OAAO,YAAY;AAc1C,IAAM,kBAAN,MAAqD;AAAA,EAI1D,YAAY,UAAa;AACvB,QAAI,kBAAkB,OAAO,aAAa,UAAU;AAClD,WAAK,WAAW,IAAI,QAAQ,QAAQ;AAAA,IACtC,OAAO;AACL,WAAK,YAAY;AAAA,IACnB;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,QAAuB;AAnCzB;AAoCI,QAAI;AAEJ,QAAI,KAAK,UAAU;AACjB,kBAAW,UAAK,aAAL,mBAAe;AAE1B,UAAI,CAAC,UAAU;AACb,eAAO,KAAK;AAAA,MACd;AAAA,IACF,OAAO;AACL,iBAAW,KAAK;AAChB,WAAK,0CAAyB,eAAzB,mCAAyC;AAC5C,eAAO,KAAK;AAAA,MACd;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AACF;;;AC/CO,IAAM,kBAAkB;AACxB,IAAM,mBAAmB;AAwBhC,SAAS,uBAAuB,KAAsB;AACpD,QAAM,cAAe,IAAoC;AACzD,QAAM,YAAY,YAAY,UAAU;AAExC,MAAI,sBAAsB;AAE1B,cAAY,UAAU,QAAQ,SAAS,QAAc;AACnD,0BAAsB;AAAA,EACxB;AAEA,QAAM,MAAM,IAAI,SAAS,cAAc,QAAQ;AAE/C,MAAI,MAAM;AAEV,cAAY,UAAU,QAAQ;AAE9B,SAAO;AACT;AAEA,IAAI,0BAA0B;AAyBvB,SAAS,YAAY,SAA4B;AACtD,QAAM,Q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;AAAA;AAAA;AAAA;AAAA,EAKA,OAAO,0BAAyC;AAC9C,QAAI,KAAK,OAAO;AACd,WAAK,MAAM,2BAA2B;AAAA,IACxC;AAAA,EACF;AACF;AAEO,SAAS,cAAc,KAAa,OAA+B;AACxE,SAAO,QAAQ,OAAO,KAAK,KAAK;AAClC;AAEO,SAAS,eAAe,UAAmB;AAChD,UAAQ,QAAQ,QAAQ;AAC1B;;;AChWO,IAAM,UAAU;","names":[]}
|
package/dist/index.d.mts
CHANGED
|
@@ -29,19 +29,23 @@ type KeyborgCallback = (isNavigatingWithKeyboard: boolean) => void;
|
|
|
29
29
|
declare class KeyborgCore implements Disposable {
|
|
30
30
|
readonly id: string;
|
|
31
31
|
private _win?;
|
|
32
|
-
private
|
|
32
|
+
private _isMouseOrTouchUsedTimer;
|
|
33
33
|
private _dismissTimer;
|
|
34
34
|
private _triggerKeys?;
|
|
35
35
|
private _dismissKeys?;
|
|
36
|
+
private _isNavigatingWithKeyboard_DO_NOT_USE;
|
|
36
37
|
constructor(win: WindowWithKeyborg, props?: KeyborgProps);
|
|
38
|
+
get isNavigatingWithKeyboard(): boolean;
|
|
39
|
+
set isNavigatingWithKeyboard(val: boolean);
|
|
37
40
|
dispose(): void;
|
|
38
41
|
isDisposed(): boolean;
|
|
39
42
|
/**
|
|
40
43
|
* Updates all keyborg instances with the keyboard navigation state
|
|
41
44
|
*/
|
|
42
|
-
update(
|
|
45
|
+
update(): void;
|
|
43
46
|
private _onFocusIn;
|
|
44
47
|
private _onMouseDown;
|
|
48
|
+
private _onMouseOrTouch;
|
|
45
49
|
private _onKeyDown;
|
|
46
50
|
/**
|
|
47
51
|
* @returns whether the keyboard event should trigger keyboard navigation mode
|
package/dist/index.d.ts
CHANGED
|
@@ -29,19 +29,23 @@ type KeyborgCallback = (isNavigatingWithKeyboard: boolean) => void;
|
|
|
29
29
|
declare class KeyborgCore implements Disposable {
|
|
30
30
|
readonly id: string;
|
|
31
31
|
private _win?;
|
|
32
|
-
private
|
|
32
|
+
private _isMouseOrTouchUsedTimer;
|
|
33
33
|
private _dismissTimer;
|
|
34
34
|
private _triggerKeys?;
|
|
35
35
|
private _dismissKeys?;
|
|
36
|
+
private _isNavigatingWithKeyboard_DO_NOT_USE;
|
|
36
37
|
constructor(win: WindowWithKeyborg, props?: KeyborgProps);
|
|
38
|
+
get isNavigatingWithKeyboard(): boolean;
|
|
39
|
+
set isNavigatingWithKeyboard(val: boolean);
|
|
37
40
|
dispose(): void;
|
|
38
41
|
isDisposed(): boolean;
|
|
39
42
|
/**
|
|
40
43
|
* Updates all keyborg instances with the keyboard navigation state
|
|
41
44
|
*/
|
|
42
|
-
update(
|
|
45
|
+
update(): void;
|
|
43
46
|
private _onFocusIn;
|
|
44
47
|
private _onMouseDown;
|
|
48
|
+
private _onMouseOrTouch;
|
|
45
49
|
private _onKeyDown;
|
|
46
50
|
/**
|
|
47
51
|
* @returns whether the keyboard event should trigger keyboard navigation mode
|
package/dist/index.js
CHANGED
|
@@ -116,7 +116,7 @@ function setupFocusEvent(win) {
|
|
|
116
116
|
if (!target) {
|
|
117
117
|
return;
|
|
118
118
|
}
|
|
119
|
-
let node =
|
|
119
|
+
let node = e.composedPath()[0];
|
|
120
120
|
const currentShadows = /* @__PURE__ */ new Set();
|
|
121
121
|
while (node) {
|
|
122
122
|
if (node.nodeType === Node.DOCUMENT_FRAGMENT_NODE) {
|
|
@@ -126,11 +126,14 @@ function setupFocusEvent(win) {
|
|
|
126
126
|
node = node.parentNode;
|
|
127
127
|
}
|
|
128
128
|
}
|
|
129
|
-
for (const
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
129
|
+
for (const shadowRootWeakRef of shadowTargets) {
|
|
130
|
+
const shadowRoot = shadowRootWeakRef.deref();
|
|
131
|
+
if (!shadowRoot || !currentShadows.has(shadowRoot)) {
|
|
132
|
+
shadowTargets.delete(shadowRootWeakRef);
|
|
133
|
+
if (shadowRoot) {
|
|
134
|
+
shadowRoot.removeEventListener("focusin", focusInHandler, true);
|
|
135
|
+
shadowRoot.removeEventListener("focusout", focusOutHandler, true);
|
|
136
|
+
}
|
|
134
137
|
}
|
|
135
138
|
}
|
|
136
139
|
onFocusIn(target, e.relatedTarget || void 0);
|
|
@@ -139,12 +142,14 @@ function setupFocusEvent(win) {
|
|
|
139
142
|
var _a;
|
|
140
143
|
const shadowRoot = target.shadowRoot;
|
|
141
144
|
if (shadowRoot) {
|
|
142
|
-
|
|
143
|
-
|
|
145
|
+
for (const shadowRootWeakRef of shadowTargets) {
|
|
146
|
+
if (shadowRootWeakRef.deref() === shadowRoot) {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
144
149
|
}
|
|
145
150
|
shadowRoot.addEventListener("focusin", focusInHandler, true);
|
|
146
151
|
shadowRoot.addEventListener("focusout", focusOutHandler, true);
|
|
147
|
-
shadowTargets.add(shadowRoot);
|
|
152
|
+
shadowTargets.add(new WeakRefInstance(shadowRoot));
|
|
148
153
|
return;
|
|
149
154
|
}
|
|
150
155
|
const details = {
|
|
@@ -212,17 +217,20 @@ function disposeFocusEvent(win) {
|
|
|
212
217
|
keyborgNativeFocusEvent.focusOutHandler,
|
|
213
218
|
true
|
|
214
219
|
);
|
|
215
|
-
for (const
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
220
|
+
for (const shadowRootWeakRef of keyborgNativeFocusEvent.shadowTargets) {
|
|
221
|
+
const shadowRoot = shadowRootWeakRef.deref();
|
|
222
|
+
if (shadowRoot) {
|
|
223
|
+
shadowRoot.removeEventListener(
|
|
224
|
+
"focusin",
|
|
225
|
+
keyborgNativeFocusEvent.focusInHandler,
|
|
226
|
+
true
|
|
227
|
+
);
|
|
228
|
+
shadowRoot.removeEventListener(
|
|
229
|
+
"focusout",
|
|
230
|
+
keyborgNativeFocusEvent.focusOutHandler,
|
|
231
|
+
true
|
|
232
|
+
);
|
|
233
|
+
}
|
|
226
234
|
}
|
|
227
235
|
keyborgNativeFocusEvent.shadowTargets.clear();
|
|
228
236
|
delete kwin.__keyborgData;
|
|
@@ -240,50 +248,14 @@ function getLastFocusedProgrammatically(win) {
|
|
|
240
248
|
// src/Keyborg.ts
|
|
241
249
|
var _dismissTimeout = 500;
|
|
242
250
|
var _lastId = 0;
|
|
243
|
-
var KeyborgState = class {
|
|
244
|
-
constructor() {
|
|
245
|
-
this.__keyborgCoreRefs = {};
|
|
246
|
-
this._isNavigatingWithKeyboard = false;
|
|
247
|
-
}
|
|
248
|
-
add(keyborg) {
|
|
249
|
-
const id = keyborg.id;
|
|
250
|
-
if (!(id in this.__keyborgCoreRefs)) {
|
|
251
|
-
this.__keyborgCoreRefs[id] = new WeakRefInstance(keyborg);
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
remove(id) {
|
|
255
|
-
delete this.__keyborgCoreRefs[id];
|
|
256
|
-
if (Object.keys(this.__keyborgCoreRefs).length === 0) {
|
|
257
|
-
this._isNavigatingWithKeyboard = false;
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
setVal(isNavigatingWithKeyboard) {
|
|
261
|
-
if (this._isNavigatingWithKeyboard === isNavigatingWithKeyboard) {
|
|
262
|
-
return;
|
|
263
|
-
}
|
|
264
|
-
this._isNavigatingWithKeyboard = isNavigatingWithKeyboard;
|
|
265
|
-
for (const id of Object.keys(this.__keyborgCoreRefs)) {
|
|
266
|
-
const ref = this.__keyborgCoreRefs[id];
|
|
267
|
-
const keyborg = ref.deref();
|
|
268
|
-
if (keyborg) {
|
|
269
|
-
keyborg.update(isNavigatingWithKeyboard);
|
|
270
|
-
} else {
|
|
271
|
-
this.remove(id);
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
getVal() {
|
|
276
|
-
return this._isNavigatingWithKeyboard;
|
|
277
|
-
}
|
|
278
|
-
};
|
|
279
|
-
var _state = new KeyborgState();
|
|
280
251
|
var KeyborgCore = class {
|
|
281
252
|
constructor(win, props) {
|
|
253
|
+
this._isNavigatingWithKeyboard_DO_NOT_USE = false;
|
|
282
254
|
this._onFocusIn = (e) => {
|
|
283
|
-
if (this.
|
|
255
|
+
if (this._isMouseOrTouchUsedTimer) {
|
|
284
256
|
return;
|
|
285
257
|
}
|
|
286
|
-
if (
|
|
258
|
+
if (this.isNavigatingWithKeyboard) {
|
|
287
259
|
return;
|
|
288
260
|
}
|
|
289
261
|
const details = e.detail;
|
|
@@ -293,32 +265,35 @@ var KeyborgCore = class {
|
|
|
293
265
|
if (details.isFocusedProgrammatically || details.isFocusedProgrammatically === void 0) {
|
|
294
266
|
return;
|
|
295
267
|
}
|
|
296
|
-
|
|
268
|
+
this.isNavigatingWithKeyboard = true;
|
|
297
269
|
};
|
|
298
270
|
this._onMouseDown = (e) => {
|
|
299
271
|
if (e.buttons === 0 || e.clientX === 0 && e.clientY === 0 && e.screenX === 0 && e.screenY === 0) {
|
|
300
272
|
return;
|
|
301
273
|
}
|
|
274
|
+
this._onMouseOrTouch();
|
|
275
|
+
};
|
|
276
|
+
this._onMouseOrTouch = () => {
|
|
302
277
|
const win = this._win;
|
|
303
278
|
if (win) {
|
|
304
|
-
if (this.
|
|
305
|
-
win.clearTimeout(this.
|
|
279
|
+
if (this._isMouseOrTouchUsedTimer) {
|
|
280
|
+
win.clearTimeout(this._isMouseOrTouchUsedTimer);
|
|
306
281
|
}
|
|
307
|
-
this.
|
|
308
|
-
delete this.
|
|
282
|
+
this._isMouseOrTouchUsedTimer = win.setTimeout(() => {
|
|
283
|
+
delete this._isMouseOrTouchUsedTimer;
|
|
309
284
|
}, 1e3);
|
|
310
285
|
}
|
|
311
|
-
|
|
286
|
+
this.isNavigatingWithKeyboard = false;
|
|
312
287
|
};
|
|
313
288
|
this._onKeyDown = (e) => {
|
|
314
|
-
const isNavigatingWithKeyboard =
|
|
289
|
+
const isNavigatingWithKeyboard = this.isNavigatingWithKeyboard;
|
|
315
290
|
if (isNavigatingWithKeyboard) {
|
|
316
291
|
if (this._shouldDismissKeyboardNavigation(e)) {
|
|
317
292
|
this._scheduleDismiss();
|
|
318
293
|
}
|
|
319
294
|
} else {
|
|
320
295
|
if (this._shouldTriggerKeyboardNavigation(e)) {
|
|
321
|
-
|
|
296
|
+
this.isNavigatingWithKeyboard = true;
|
|
322
297
|
}
|
|
323
298
|
}
|
|
324
299
|
};
|
|
@@ -338,15 +313,26 @@ var KeyborgCore = class {
|
|
|
338
313
|
doc.addEventListener(KEYBORG_FOCUSIN, this._onFocusIn, true);
|
|
339
314
|
doc.addEventListener("mousedown", this._onMouseDown, true);
|
|
340
315
|
win.addEventListener("keydown", this._onKeyDown, true);
|
|
316
|
+
doc.addEventListener("touchstart", this._onMouseOrTouch, true);
|
|
317
|
+
doc.addEventListener("touchend", this._onMouseOrTouch, true);
|
|
318
|
+
doc.addEventListener("touchcancel", this._onMouseOrTouch, true);
|
|
341
319
|
setupFocusEvent(win);
|
|
342
|
-
|
|
320
|
+
}
|
|
321
|
+
get isNavigatingWithKeyboard() {
|
|
322
|
+
return this._isNavigatingWithKeyboard_DO_NOT_USE;
|
|
323
|
+
}
|
|
324
|
+
set isNavigatingWithKeyboard(val) {
|
|
325
|
+
if (this._isNavigatingWithKeyboard_DO_NOT_USE !== val) {
|
|
326
|
+
this._isNavigatingWithKeyboard_DO_NOT_USE = val;
|
|
327
|
+
this.update();
|
|
328
|
+
}
|
|
343
329
|
}
|
|
344
330
|
dispose() {
|
|
345
331
|
const win = this._win;
|
|
346
332
|
if (win) {
|
|
347
|
-
if (this.
|
|
348
|
-
win.clearTimeout(this.
|
|
349
|
-
this.
|
|
333
|
+
if (this._isMouseOrTouchUsedTimer) {
|
|
334
|
+
win.clearTimeout(this._isMouseOrTouchUsedTimer);
|
|
335
|
+
this._isMouseOrTouchUsedTimer = void 0;
|
|
350
336
|
}
|
|
351
337
|
if (this._dismissTimer) {
|
|
352
338
|
win.clearTimeout(this._dismissTimer);
|
|
@@ -357,8 +343,10 @@ var KeyborgCore = class {
|
|
|
357
343
|
doc.removeEventListener(KEYBORG_FOCUSIN, this._onFocusIn, true);
|
|
358
344
|
doc.removeEventListener("mousedown", this._onMouseDown, true);
|
|
359
345
|
win.removeEventListener("keydown", this._onKeyDown, true);
|
|
346
|
+
doc.removeEventListener("touchstart", this._onMouseOrTouch, true);
|
|
347
|
+
doc.removeEventListener("touchend", this._onMouseOrTouch, true);
|
|
348
|
+
doc.removeEventListener("touchcancel", this._onMouseOrTouch, true);
|
|
360
349
|
delete this._win;
|
|
361
|
-
_state.remove(this.id);
|
|
362
350
|
}
|
|
363
351
|
}
|
|
364
352
|
isDisposed() {
|
|
@@ -367,12 +355,12 @@ var KeyborgCore = class {
|
|
|
367
355
|
/**
|
|
368
356
|
* Updates all keyborg instances with the keyboard navigation state
|
|
369
357
|
*/
|
|
370
|
-
update(
|
|
358
|
+
update() {
|
|
371
359
|
var _a, _b;
|
|
372
360
|
const keyborgs = (_b = (_a = this._win) == null ? void 0 : _a.__keyborg) == null ? void 0 : _b.refs;
|
|
373
361
|
if (keyborgs) {
|
|
374
362
|
for (const id of Object.keys(keyborgs)) {
|
|
375
|
-
Keyborg.update(keyborgs[id], isNavigatingWithKeyboard);
|
|
363
|
+
Keyborg.update(keyborgs[id], this.isNavigatingWithKeyboard);
|
|
376
364
|
}
|
|
377
365
|
}
|
|
378
366
|
}
|
|
@@ -408,7 +396,7 @@ var KeyborgCore = class {
|
|
|
408
396
|
this._dismissTimer = void 0;
|
|
409
397
|
const cur = win.document.activeElement;
|
|
410
398
|
if (was && cur && was === cur) {
|
|
411
|
-
|
|
399
|
+
this.isNavigatingWithKeyboard = false;
|
|
412
400
|
}
|
|
413
401
|
}, _dismissTimeout);
|
|
414
402
|
}
|
|
@@ -465,7 +453,8 @@ var Keyborg = class _Keyborg {
|
|
|
465
453
|
* @returns Whether the user is navigating with keyboard
|
|
466
454
|
*/
|
|
467
455
|
isNavigatingWithKeyboard() {
|
|
468
|
-
|
|
456
|
+
var _a;
|
|
457
|
+
return !!((_a = this._core) == null ? void 0 : _a.isNavigatingWithKeyboard);
|
|
469
458
|
}
|
|
470
459
|
/**
|
|
471
460
|
* @param callback - Called when the keyboard navigation state changes
|
|
@@ -486,7 +475,9 @@ var Keyborg = class _Keyborg {
|
|
|
486
475
|
* Manually set the keyboard navigtion state
|
|
487
476
|
*/
|
|
488
477
|
setVal(isNavigatingWithKeyboard) {
|
|
489
|
-
|
|
478
|
+
if (this._core) {
|
|
479
|
+
this._core.isNavigatingWithKeyboard = isNavigatingWithKeyboard;
|
|
480
|
+
}
|
|
490
481
|
}
|
|
491
482
|
};
|
|
492
483
|
function createKeyborg(win, props) {
|
|
@@ -497,7 +488,7 @@ function disposeKeyborg(instance) {
|
|
|
497
488
|
}
|
|
498
489
|
|
|
499
490
|
// src/index.ts
|
|
500
|
-
var version = "2.
|
|
491
|
+
var version = "2.6.0-canary.0";
|
|
501
492
|
// Annotate the CommonJS export names for ESM import in node:
|
|
502
493
|
0 && (module.exports = {
|
|
503
494
|
KEYBORG_FOCUSIN,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/WeakRefInstance.ts","../src/FocusEvent.ts","../src/Keyborg.ts"],"sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport type { Keyborg, KeyborgCallback } from \"./Keyborg\";\nexport { createKeyborg, disposeKeyborg } from \"./Keyborg\";\n\nexport type {\n KeyborgFocusInEvent,\n KeyborgFocusInEventDetails,\n KeyborgFocusOutEvent,\n KeyborgFocusOutEventDetails,\n} from \"./FocusEvent\";\nexport {\n getLastFocusedProgrammatically,\n nativeFocus,\n KEYBORG_FOCUSIN,\n KEYBORG_FOCUSOUT,\n} from \"./FocusEvent\";\n\nexport const version = process.env.PKG_VERSION;\n","/*!\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License.\n */\n\n// IE11 compat, checks if WeakRef is supported\nexport const _canUseWeakRef = typeof WeakRef !== \"undefined\";\n\n/**\n * Allows disposable instances to be used\n */\nexport interface Disposable {\n isDisposed?(): boolean;\n}\n\n/**\n * WeakRef wrapper around a HTMLElement that also supports IE11\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakRef}\n * @internal\n */\nexport class WeakRefInstance<T extends Disposable | object> {\n private _weakRef?: WeakRef<T>;\n private _instance?: T;\n\n constructor(instance: T) {\n if (_canUseWeakRef && typeof instance === \"object\") {\n this._weakRef = new WeakRef(instance);\n } else {\n this._instance = instance;\n }\n }\n\n /**\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakRef/deref}\n */\n deref(): T | undefined {\n let instance: T | undefined;\n\n if (this._weakRef) {\n instance = this._weakRef?.deref();\n\n if (!instance) {\n delete this._weakRef;\n }\n } else {\n instance = this._instance;\n if ((instance as Disposable)?.isDisposed?.()) {\n delete this._instance;\n }\n }\n\n return instance;\n }\n}\n","/*!\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License.\n */\nimport { WeakRefInstance } from \"./WeakRefInstance\";\n\nexport const KEYBORG_FOCUSIN = \"keyborg:focusin\";\nexport const KEYBORG_FOCUSOUT = \"keyborg:focusout\";\n\ninterface KeyborgFocus {\n /**\n * This is the native `focus` function that is retained so that it can be restored when keyborg is disposed\n */\n __keyborgNativeFocus?: (options?: FocusOptions | undefined) => void;\n}\n\ninterface KeyborgFocusEventData {\n focusInHandler: (e: FocusEvent) => void;\n focusOutHandler: (e: FocusEvent) => void;\n lastFocusedProgrammatically?: WeakRefInstance<HTMLElement>;\n shadowTargets: Set<ShadowRoot>;\n}\n\n/**\n * Extends the global window with keyborg focus event data\n */\ninterface WindowWithKeyborgFocusEvent extends Window {\n HTMLElement: typeof HTMLElement;\n __keyborgData?: KeyborgFocusEventData;\n}\n\nfunction canOverrideNativeFocus(win: Window): boolean {\n const HTMLElement = (win as WindowWithKeyborgFocusEvent).HTMLElement;\n const origFocus = HTMLElement.prototype.focus;\n\n let isCustomFocusCalled = false;\n\n HTMLElement.prototype.focus = function focus(): void {\n isCustomFocusCalled = true;\n };\n\n const btn = win.document.createElement(\"button\");\n\n btn.focus();\n\n HTMLElement.prototype.focus = origFocus;\n\n return isCustomFocusCalled;\n}\n\nlet _canOverrideNativeFocus = false;\n\nexport interface KeyborgFocusInEventDetails {\n relatedTarget?: HTMLElement;\n isFocusedProgrammatically?: boolean;\n originalEvent?: FocusEvent;\n}\n\nexport interface KeyborgFocusInEvent\n extends CustomEvent<KeyborgFocusInEventDetails> {\n /**\n * @deprecated - used `event.detail`\n */\n details?: KeyborgFocusInEventDetails;\n}\n\nexport interface KeyborgFocusOutEventDetails {\n originalEvent: FocusEvent;\n}\n\nexport type KeyborgFocusOutEvent = CustomEvent<KeyborgFocusOutEventDetails>;\n\n/**\n * Guarantees that the native `focus` will be used\n */\nexport function nativeFocus(element: HTMLElement): void {\n const focus = element.focus as KeyborgFocus;\n\n if (focus.__keyborgNativeFocus) {\n focus.__keyborgNativeFocus.call(element);\n } else {\n element.focus();\n }\n}\n\n/**\n * Overrides the native `focus` and setups the keyborg focus event\n */\nexport function setupFocusEvent(win: Window): void {\n const kwin = win as WindowWithKeyborgFocusEvent;\n\n if (!_canOverrideNativeFocus) {\n _canOverrideNativeFocus = canOverrideNativeFocus(kwin);\n }\n\n const origFocus = kwin.HTMLElement.prototype.focus;\n\n if ((origFocus as KeyborgFocus).__keyborgNativeFocus) {\n // Already set up.\n return;\n }\n\n kwin.HTMLElement.prototype.focus = focus;\n\n const shadowTargets: Set<ShadowRoot> = new Set();\n\n const focusOutHandler = (e: FocusEvent) => {\n const target = e.target as HTMLElement;\n\n if (!target) {\n return;\n }\n\n const event: KeyborgFocusOutEvent = new CustomEvent(KEYBORG_FOCUSOUT, {\n cancelable: true,\n bubbles: true,\n // Allows the event to bubble past an open shadow root\n composed: true,\n detail: {\n originalEvent: e,\n },\n });\n\n target.dispatchEvent(event);\n };\n\n const focusInHandler = (e: FocusEvent) => {\n const target = e.target as HTMLElement;\n\n if (!target) {\n return;\n }\n\n let node: Node | null = target;\n const currentShadows: Set<ShadowRoot> = new Set();\n\n while (node) {\n if (node.nodeType === Node.DOCUMENT_FRAGMENT_NODE) {\n currentShadows.add(node as ShadowRoot);\n node = (node as ShadowRoot).host;\n } else {\n node = node.parentNode;\n }\n }\n\n for (const shadow of shadowTargets) {\n if (!currentShadows.has(shadow)) {\n shadow.removeEventListener(\"focusin\", focusInHandler, true);\n shadow.removeEventListener(\"focusout\", focusOutHandler, true);\n shadowTargets.delete(shadow);\n }\n }\n\n onFocusIn(target, (e.relatedTarget as HTMLElement | null) || undefined);\n };\n\n const onFocusIn = (\n target: Element,\n relatedTarget?: HTMLElement,\n originalEvent?: FocusEvent,\n ) => {\n const shadowRoot = target.shadowRoot;\n\n if (shadowRoot) {\n /**\n * https://bugs.chromium.org/p/chromium/issues/detail?id=1512028\n * focusin events don't bubble up through an open shadow root once focus is inside\n * once focus moves into a shadow root - we drop the same focusin handler there\n * keyborg's custom event will still bubble up since it is composed\n * event handlers should be cleaned up once focus leaves the shadow root.\n *\n * When a focusin event is dispatched from a shadow root, its target is the shadow root parent.\n * Each shadow root encounter requires a new capture listener.\n * Why capture? - we want to follow the focus event in order or descending nested shadow roots\n * When there are no more shadow root targets - dispatch the keyborg:focusin event\n *\n * 1. no focus event\n * > document - capture listener ✅\n * > shadow root 1\n * > shadow root 2\n * > shadow root 3\n * > focused element\n *\n * 2. focus event received by document listener\n * > document - capture listener ✅ (focus event here)\n * > shadow root 1 - capture listener ✅\n * > shadow root 2\n * > shadow root 3\n * > focused element\n\n * 3. focus event received by root l1 listener\n * > document - capture listener ✅\n * > shadow root 1 - capture listener ✅ (focus event here)\n * > shadow root 2 - capture listener ✅\n * > shadow root 3\n * > focused element\n *\n * 4. focus event received by root l2 listener\n * > document - capture listener ✅\n * > shadow root 1 - capture listener ✅\n * > shadow root 2 - capture listener ✅ (focus event here)\n * > shadow root 3 - capture listener ✅\n * > focused element\n *\n * 5. focus event received by root l3 listener, no more shadow root targets\n * > document - capture listener ✅\n * > shadow root 1 - capture listener ✅\n * > shadow root 2 - capture listener ✅\n * > shadow root 3 - capture listener ✅ (focus event here)\n * > focused element ✅ (no shadow root - dispatch keyborg event)\n */\n\n if (shadowTargets.has(shadowRoot)) {\n return;\n }\n\n shadowRoot.addEventListener(\"focusin\", focusInHandler, true);\n shadowRoot.addEventListener(\"focusout\", focusOutHandler, true);\n\n shadowTargets.add(shadowRoot);\n\n return;\n }\n\n const details: KeyborgFocusInEventDetails = {\n relatedTarget,\n originalEvent,\n };\n\n const event: KeyborgFocusInEvent = new CustomEvent(KEYBORG_FOCUSIN, {\n cancelable: true,\n bubbles: true,\n // Allows the event to bubble past an open shadow root\n composed: true,\n detail: details,\n });\n\n // Tabster (and other users) can still use the legacy details field - keeping for backwards compat\n event.details = details;\n\n if (_canOverrideNativeFocus || data.lastFocusedProgrammatically) {\n details.isFocusedProgrammatically =\n target === data.lastFocusedProgrammatically?.deref();\n\n data.lastFocusedProgrammatically = undefined;\n }\n\n target.dispatchEvent(event);\n };\n\n const data: KeyborgFocusEventData = (kwin.__keyborgData = {\n focusInHandler,\n focusOutHandler,\n shadowTargets,\n });\n\n kwin.document.addEventListener(\n \"focusin\",\n kwin.__keyborgData.focusInHandler,\n true,\n );\n\n kwin.document.addEventListener(\n \"focusout\",\n kwin.__keyborgData.focusOutHandler,\n true,\n );\n\n function focus(this: HTMLElement) {\n const keyborgNativeFocusEvent = (kwin as WindowWithKeyborgFocusEvent)\n .__keyborgData;\n\n if (keyborgNativeFocusEvent) {\n keyborgNativeFocusEvent.lastFocusedProgrammatically = new WeakRefInstance(\n this,\n );\n }\n\n // eslint-disable-next-line prefer-rest-params\n return origFocus.apply(this, arguments);\n }\n\n let activeElement = kwin.document.activeElement as Element | null;\n\n // If keyborg is created with the focus inside shadow root, we need\n // to go through the shadows up to make sure all relevant shadows\n // have focus handlers attached.\n while (activeElement && activeElement.shadowRoot) {\n onFocusIn(activeElement);\n activeElement = activeElement.shadowRoot.activeElement;\n }\n\n (focus as KeyborgFocus).__keyborgNativeFocus = origFocus;\n}\n\n/**\n * Removes keyborg event listeners and custom focus override\n * @param win The window that stores keyborg focus events\n */\nexport function disposeFocusEvent(win: Window): void {\n const kwin = win as WindowWithKeyborgFocusEvent;\n const proto = kwin.HTMLElement.prototype;\n const origFocus = (proto.focus as KeyborgFocus).__keyborgNativeFocus;\n const keyborgNativeFocusEvent = kwin.__keyborgData;\n\n if (keyborgNativeFocusEvent) {\n kwin.document.removeEventListener(\n \"focusin\",\n keyborgNativeFocusEvent.focusInHandler,\n true,\n );\n\n kwin.document.removeEventListener(\n \"focusout\",\n keyborgNativeFocusEvent.focusOutHandler,\n true,\n );\n\n for (const shadow of keyborgNativeFocusEvent.shadowTargets) {\n shadow.removeEventListener(\n \"focusin\",\n keyborgNativeFocusEvent.focusInHandler,\n true,\n );\n shadow.removeEventListener(\n \"focusout\",\n keyborgNativeFocusEvent.focusOutHandler,\n true,\n );\n }\n\n keyborgNativeFocusEvent.shadowTargets.clear();\n\n delete kwin.__keyborgData;\n }\n\n if (origFocus) {\n proto.focus = origFocus;\n }\n}\n\n/**\n * @param win The window that stores keyborg focus events\n * @returns The last element focused with element.focus()\n */\nexport function getLastFocusedProgrammatically(\n win: Window,\n): HTMLElement | null | undefined {\n const keyborgNativeFocusEvent = (win as WindowWithKeyborgFocusEvent)\n .__keyborgData;\n\n return keyborgNativeFocusEvent\n ? keyborgNativeFocusEvent.lastFocusedProgrammatically?.deref() || null\n : undefined;\n}\n","/*!\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n disposeFocusEvent,\n KeyborgFocusInEvent,\n KEYBORG_FOCUSIN,\n setupFocusEvent,\n} from \"./FocusEvent\";\nimport { Disposable, WeakRefInstance } from \"./WeakRefInstance\";\n\ninterface WindowWithKeyborg extends Window {\n __keyborg?: {\n core: KeyborgCore;\n refs: { [id: string]: Keyborg };\n };\n}\n\nconst _dismissTimeout = 500; // When a key from dismissKeys is pressed and the focus is not moved\n// during _dismissTimeout time, dismiss the keyboard navigation mode.\n\nlet _lastId = 0;\n\nexport interface KeyborgProps {\n // Keys to be used to trigger keyboard navigation mode. By default, any key will trigger\n // it. Could be limited to, for example, just Tab (or Tab and arrow keys).\n triggerKeys?: number[];\n // Keys to be used to dismiss keyboard navigation mode using keyboard (in addition to\n // mouse clicks which dismiss it). For example, Esc could be used to dismiss.\n dismissKeys?: number[];\n}\n\nexport type KeyborgCallback = (isNavigatingWithKeyboard: boolean) => void;\n\n/**\n * Source of truth for all the keyborg core instances and the current keyboard navigation state\n */\nexport class KeyborgState {\n private __keyborgCoreRefs: { [id: string]: WeakRefInstance<KeyborgCore> } =\n {};\n private _isNavigatingWithKeyboard = false;\n\n add(keyborg: KeyborgCore): void {\n const id = keyborg.id;\n\n if (!(id in this.__keyborgCoreRefs)) {\n this.__keyborgCoreRefs[id] = new WeakRefInstance<KeyborgCore>(keyborg);\n }\n }\n\n remove(id: string): void {\n delete this.__keyborgCoreRefs[id];\n\n if (Object.keys(this.__keyborgCoreRefs).length === 0) {\n this._isNavigatingWithKeyboard = false;\n }\n }\n\n setVal(isNavigatingWithKeyboard: boolean): void {\n if (this._isNavigatingWithKeyboard === isNavigatingWithKeyboard) {\n return;\n }\n\n this._isNavigatingWithKeyboard = isNavigatingWithKeyboard;\n\n for (const id of Object.keys(this.__keyborgCoreRefs)) {\n const ref = this.__keyborgCoreRefs[id];\n const keyborg = ref.deref();\n\n if (keyborg) {\n keyborg.update(isNavigatingWithKeyboard);\n } else {\n this.remove(id);\n }\n }\n }\n\n getVal(): boolean {\n return this._isNavigatingWithKeyboard;\n }\n}\n\nconst _state = new KeyborgState();\n\n/**\n * Manages a collection of Keyborg instances in a window/document and updates keyborg state\n */\nclass KeyborgCore implements Disposable {\n readonly id: string;\n\n private _win?: WindowWithKeyborg;\n private _isMouseUsedTimer: number | undefined;\n private _dismissTimer: number | undefined;\n private _triggerKeys?: Set<number>;\n private _dismissKeys?: Set<number>;\n\n constructor(win: WindowWithKeyborg, props?: KeyborgProps) {\n this.id = \"c\" + ++_lastId;\n this._win = win;\n const doc = win.document;\n\n if (props) {\n const triggerKeys = props.triggerKeys;\n const dismissKeys = props.dismissKeys;\n\n if (triggerKeys?.length) {\n this._triggerKeys = new Set(triggerKeys);\n }\n\n if (dismissKeys?.length) {\n this._dismissKeys = new Set(dismissKeys);\n }\n }\n\n doc.addEventListener(KEYBORG_FOCUSIN, this._onFocusIn, true); // Capture!\n doc.addEventListener(\"mousedown\", this._onMouseDown, true); // Capture!\n win.addEventListener(\"keydown\", this._onKeyDown, true); // Capture!\n\n setupFocusEvent(win);\n\n _state.add(this);\n }\n\n dispose(): void {\n const win = this._win;\n\n if (win) {\n if (this._isMouseUsedTimer) {\n win.clearTimeout(this._isMouseUsedTimer);\n this._isMouseUsedTimer = undefined;\n }\n\n if (this._dismissTimer) {\n win.clearTimeout(this._dismissTimer);\n this._dismissTimer = undefined;\n }\n\n disposeFocusEvent(win);\n\n const doc = win.document;\n\n doc.removeEventListener(KEYBORG_FOCUSIN, this._onFocusIn, true); // Capture!\n doc.removeEventListener(\"mousedown\", this._onMouseDown, true); // Capture!\n win.removeEventListener(\"keydown\", this._onKeyDown, true); // Capture!\n\n delete this._win;\n\n _state.remove(this.id);\n }\n }\n\n isDisposed(): boolean {\n return !!this._win;\n }\n\n /**\n * Updates all keyborg instances with the keyboard navigation state\n */\n update(isNavigatingWithKeyboard: boolean): void {\n const keyborgs = this._win?.__keyborg?.refs;\n\n if (keyborgs) {\n for (const id of Object.keys(keyborgs)) {\n Keyborg.update(keyborgs[id], isNavigatingWithKeyboard);\n }\n }\n }\n\n private _onFocusIn = (e: KeyborgFocusInEvent) => {\n // When the focus is moved not programmatically and without keydown events,\n // it is likely that the focus is moved by screen reader (as it might swallow\n // the events when the screen reader shortcuts are used). The screen reader\n // usage is keyboard navigation.\n\n if (this._isMouseUsedTimer) {\n // There was a mouse event recently.\n return;\n }\n\n if (_state.getVal()) {\n return;\n }\n\n const details = e.detail;\n\n if (!details.relatedTarget) {\n return;\n }\n\n if (\n details.isFocusedProgrammatically ||\n details.isFocusedProgrammatically === undefined\n ) {\n // The element is focused programmatically, or the programmatic focus detection\n // is not working.\n return;\n }\n\n _state.setVal(true);\n };\n\n private _onMouseDown = (e: MouseEvent): void => {\n if (\n e.buttons === 0 ||\n (e.clientX === 0 && e.clientY === 0 && e.screenX === 0 && e.screenY === 0)\n ) {\n // This is most likely an event triggered by the screen reader to perform\n // an action on an element, do not dismiss the keyboard navigation mode.\n return;\n }\n\n const win = this._win;\n\n if (win) {\n if (this._isMouseUsedTimer) {\n win.clearTimeout(this._isMouseUsedTimer);\n }\n\n this._isMouseUsedTimer = win.setTimeout(() => {\n delete this._isMouseUsedTimer;\n }, 1000); // Keeping the indication of the mouse usage for some time.\n }\n\n _state.setVal(false);\n };\n\n private _onKeyDown = (e: KeyboardEvent): void => {\n const isNavigatingWithKeyboard = _state.getVal();\n\n if (isNavigatingWithKeyboard) {\n if (this._shouldDismissKeyboardNavigation(e)) {\n this._scheduleDismiss();\n }\n } else {\n if (this._shouldTriggerKeyboardNavigation(e)) {\n _state.setVal(true);\n }\n }\n };\n\n /**\n * @returns whether the keyboard event should trigger keyboard navigation mode\n */\n private _shouldTriggerKeyboardNavigation(e: KeyboardEvent) {\n // TODO Some rich text fields can allow Tab key for indentation so it doesn't\n // need to be a navigation key. If there is a bug regarding that we should revisit\n if (e.key === \"Tab\") {\n return true;\n }\n\n const activeElement = this._win?.document\n .activeElement as HTMLElement | null;\n const isTriggerKey = !this._triggerKeys || this._triggerKeys.has(e.keyCode);\n\n const isEditable =\n activeElement &&\n (activeElement.tagName === \"INPUT\" ||\n activeElement.tagName === \"TEXTAREA\" ||\n activeElement.isContentEditable);\n\n return isTriggerKey && !isEditable;\n }\n\n /**\n * @returns whether the keyboard event should dismiss keyboard navigation mode\n */\n private _shouldDismissKeyboardNavigation(e: KeyboardEvent) {\n return this._dismissKeys?.has(e.keyCode);\n }\n\n private _scheduleDismiss(): void {\n const win = this._win;\n\n if (win) {\n if (this._dismissTimer) {\n win.clearTimeout(this._dismissTimer);\n this._dismissTimer = undefined;\n }\n\n const was = win.document.activeElement;\n\n this._dismissTimer = win.setTimeout(() => {\n this._dismissTimer = undefined;\n\n const cur = win.document.activeElement;\n\n if (was && cur && was === cur) {\n // Esc was pressed, currently focused element hasn't changed.\n // Just dismiss the keyboard navigation mode.\n _state.setVal(false);\n }\n }, _dismissTimeout);\n }\n }\n}\n\n/**\n * Used to determine the keyboard navigation state\n */\nexport class Keyborg {\n private _id: string;\n private _win?: WindowWithKeyborg;\n private _core?: KeyborgCore;\n private _cb: KeyborgCallback[] = [];\n\n static create(win: WindowWithKeyborg, props?: KeyborgProps): Keyborg {\n return new Keyborg(win, props);\n }\n\n static dispose(instance: Keyborg): void {\n instance.dispose();\n }\n\n /**\n * Updates all subscribed callbacks with the keyboard navigation state\n */\n static update(instance: Keyborg, isNavigatingWithKeyboard: boolean): void {\n instance._cb.forEach((callback) => callback(isNavigatingWithKeyboard));\n }\n\n private constructor(win: WindowWithKeyborg, props?: KeyborgProps) {\n this._id = \"k\" + ++_lastId;\n this._win = win;\n\n const current = win.__keyborg;\n\n if (current) {\n this._core = current.core;\n current.refs[this._id] = this;\n } else {\n this._core = new KeyborgCore(win, props);\n win.__keyborg = {\n core: this._core,\n refs: { [this._id]: this },\n };\n }\n }\n\n private dispose(): void {\n const current = this._win?.__keyborg;\n\n if (current?.refs[this._id]) {\n delete current.refs[this._id];\n\n if (Object.keys(current.refs).length === 0) {\n current.core.dispose();\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n delete this._win!.__keyborg;\n }\n } else if (process.env.NODE_ENV !== \"production\") {\n console.error(\n `Keyborg instance ${this._id} is being disposed incorrectly.`,\n );\n }\n\n this._cb = [];\n delete this._core;\n delete this._win;\n }\n\n /**\n * @returns Whether the user is navigating with keyboard\n */\n isNavigatingWithKeyboard(): boolean {\n return _state.getVal();\n }\n\n /**\n * @param callback - Called when the keyboard navigation state changes\n */\n subscribe(callback: KeyborgCallback): void {\n this._cb.push(callback);\n }\n\n /**\n * @param callback - Registered with subscribe\n */\n unsubscribe(callback: KeyborgCallback): void {\n const index = this._cb.indexOf(callback);\n\n if (index >= 0) {\n this._cb.splice(index, 1);\n }\n }\n\n /**\n * Manually set the keyboard navigtion state\n */\n setVal(isNavigatingWithKeyboard: boolean): void {\n _state.setVal(isNavigatingWithKeyboard);\n }\n}\n\nexport function createKeyborg(win: Window, props?: KeyborgProps): Keyborg {\n return Keyborg.create(win, props);\n}\n\nexport function disposeKeyborg(instance: Keyborg) {\n Keyborg.dispose(instance);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACMO,IAAM,iBAAiB,OAAO,YAAY;AAc1C,IAAM,kBAAN,MAAqD;AAAA,EAI1D,YAAY,UAAa;AACvB,QAAI,kBAAkB,OAAO,aAAa,UAAU;AAClD,WAAK,WAAW,IAAI,QAAQ,QAAQ;AAAA,IACtC,OAAO;AACL,WAAK,YAAY;AAAA,IACnB;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,QAAuB;AAnCzB;AAoCI,QAAI;AAEJ,QAAI,KAAK,UAAU;AACjB,kBAAW,UAAK,aAAL,mBAAe;AAE1B,UAAI,CAAC,UAAU;AACb,eAAO,KAAK;AAAA,MACd;AAAA,IACF,OAAO;AACL,iBAAW,KAAK;AAChB,WAAK,0CAAyB,eAAzB,mCAAyC;AAC5C,eAAO,KAAK;AAAA,MACd;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AACF;;;AC/CO,IAAM,kBAAkB;AACxB,IAAM,mBAAmB;AAwBhC,SAAS,uBAAuB,KAA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A,MAC9B;AAAA,IACF;AAEA,SAAK,MAAM,CAAC;AACZ,WAAO,KAAK;AACZ,WAAO,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA,EAKA,2BAAoC;AAClC,WAAO,OAAO,OAAO;AAAA,EACvB;AAAA;AAAA;AAAA;AAAA,EAKA,UAAU,UAAiC;AACzC,SAAK,IAAI,KAAK,QAAQ;AAAA,EACxB;AAAA;AAAA;AAAA;AAAA,EAKA,YAAY,UAAiC;AAC3C,UAAM,QAAQ,KAAK,IAAI,QAAQ,QAAQ;AAEvC,QAAI,SAAS,GAAG;AACd,WAAK,IAAI,OAAO,OAAO,CAAC;AAAA,IAC1B;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,OAAO,0BAAyC;AAC9C,WAAO,OAAO,wBAAwB;AAAA,EACxC;AACF;AAEO,SAAS,cAAc,KAAa,OAA+B;AACxE,SAAO,QAAQ,OAAO,KAAK,KAAK;AAClC;AAEO,SAAS,eAAe,UAAmB;AAChD,UAAQ,QAAQ,QAAQ;AAC1B;;;AH5XO,IAAM,UAAU;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/WeakRefInstance.ts","../src/FocusEvent.ts","../src/Keyborg.ts"],"sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport type { Keyborg, KeyborgCallback } from \"./Keyborg\";\nexport { createKeyborg, disposeKeyborg } from \"./Keyborg\";\n\nexport type {\n KeyborgFocusInEvent,\n KeyborgFocusInEventDetails,\n KeyborgFocusOutEvent,\n KeyborgFocusOutEventDetails,\n} from \"./FocusEvent\";\nexport {\n getLastFocusedProgrammatically,\n nativeFocus,\n KEYBORG_FOCUSIN,\n KEYBORG_FOCUSOUT,\n} from \"./FocusEvent\";\n\nexport const version = process.env.PKG_VERSION;\n","/*!\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License.\n */\n\n// IE11 compat, checks if WeakRef is supported\nexport const _canUseWeakRef = typeof WeakRef !== \"undefined\";\n\n/**\n * Allows disposable instances to be used\n */\nexport interface Disposable {\n isDisposed?(): boolean;\n}\n\n/**\n * WeakRef wrapper around a HTMLElement that also supports IE11\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakRef}\n * @internal\n */\nexport class WeakRefInstance<T extends Disposable | object> {\n private _weakRef?: WeakRef<T>;\n private _instance?: T;\n\n constructor(instance: T) {\n if (_canUseWeakRef && typeof instance === \"object\") {\n this._weakRef = new WeakRef(instance);\n } else {\n this._instance = instance;\n }\n }\n\n /**\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakRef/deref}\n */\n deref(): T | undefined {\n let instance: T | undefined;\n\n if (this._weakRef) {\n instance = this._weakRef?.deref();\n\n if (!instance) {\n delete this._weakRef;\n }\n } else {\n instance = this._instance;\n if ((instance as Disposable)?.isDisposed?.()) {\n delete this._instance;\n }\n }\n\n return instance;\n }\n}\n","/*!\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License.\n */\nimport { WeakRefInstance } from \"./WeakRefInstance\";\n\nexport const KEYBORG_FOCUSIN = \"keyborg:focusin\";\nexport const KEYBORG_FOCUSOUT = \"keyborg:focusout\";\n\ninterface KeyborgFocus {\n /**\n * This is the native `focus` function that is retained so that it can be restored when keyborg is disposed\n */\n __keyborgNativeFocus?: (options?: FocusOptions | undefined) => void;\n}\n\ninterface KeyborgFocusEventData {\n focusInHandler: (e: FocusEvent) => void;\n focusOutHandler: (e: FocusEvent) => void;\n lastFocusedProgrammatically?: WeakRefInstance<HTMLElement>;\n shadowTargets: Set<WeakRefInstance<ShadowRoot>>;\n}\n\n/**\n * Extends the global window with keyborg focus event data\n */\ninterface WindowWithKeyborgFocusEvent extends Window {\n HTMLElement: typeof HTMLElement;\n __keyborgData?: KeyborgFocusEventData;\n}\n\nfunction canOverrideNativeFocus(win: Window): boolean {\n const HTMLElement = (win as WindowWithKeyborgFocusEvent).HTMLElement;\n const origFocus = HTMLElement.prototype.focus;\n\n let isCustomFocusCalled = false;\n\n HTMLElement.prototype.focus = function focus(): void {\n isCustomFocusCalled = true;\n };\n\n const btn = win.document.createElement(\"button\");\n\n btn.focus();\n\n HTMLElement.prototype.focus = origFocus;\n\n return isCustomFocusCalled;\n}\n\nlet _canOverrideNativeFocus = false;\n\nexport interface KeyborgFocusInEventDetails {\n relatedTarget?: HTMLElement;\n isFocusedProgrammatically?: boolean;\n originalEvent?: FocusEvent;\n}\n\nexport interface KeyborgFocusInEvent\n extends CustomEvent<KeyborgFocusInEventDetails> {\n /**\n * @deprecated - used `event.detail`\n */\n details?: KeyborgFocusInEventDetails;\n}\n\nexport interface KeyborgFocusOutEventDetails {\n originalEvent: FocusEvent;\n}\n\nexport type KeyborgFocusOutEvent = CustomEvent<KeyborgFocusOutEventDetails>;\n\n/**\n * Guarantees that the native `focus` will be used\n */\nexport function nativeFocus(element: HTMLElement): void {\n const focus = element.focus as KeyborgFocus;\n\n if (focus.__keyborgNativeFocus) {\n focus.__keyborgNativeFocus.call(element);\n } else {\n element.focus();\n }\n}\n\n/**\n * Overrides the native `focus` and setups the keyborg focus event\n */\nexport function setupFocusEvent(win: Window): void {\n const kwin = win as WindowWithKeyborgFocusEvent;\n\n if (!_canOverrideNativeFocus) {\n _canOverrideNativeFocus = canOverrideNativeFocus(kwin);\n }\n\n const origFocus = kwin.HTMLElement.prototype.focus;\n\n if ((origFocus as KeyborgFocus).__keyborgNativeFocus) {\n // Already set up.\n return;\n }\n\n kwin.HTMLElement.prototype.focus = focus;\n\n const shadowTargets: Set<WeakRefInstance<ShadowRoot>> = new Set();\n\n const focusOutHandler = (e: FocusEvent) => {\n const target = e.target as HTMLElement;\n\n if (!target) {\n return;\n }\n\n const event: KeyborgFocusOutEvent = new CustomEvent(KEYBORG_FOCUSOUT, {\n cancelable: true,\n bubbles: true,\n // Allows the event to bubble past an open shadow root\n composed: true,\n detail: {\n originalEvent: e,\n },\n });\n\n target.dispatchEvent(event);\n };\n\n const focusInHandler = (e: FocusEvent) => {\n const target = e.target as HTMLElement;\n\n if (!target) {\n return;\n }\n\n let node: Node | null | undefined = e.composedPath()[0] as\n | Node\n | null\n | undefined;\n\n const currentShadows: Set<ShadowRoot> = new Set();\n\n while (node) {\n if (node.nodeType === Node.DOCUMENT_FRAGMENT_NODE) {\n currentShadows.add(node as ShadowRoot);\n node = (node as ShadowRoot).host;\n } else {\n node = node.parentNode;\n }\n }\n\n for (const shadowRootWeakRef of shadowTargets) {\n const shadowRoot = shadowRootWeakRef.deref();\n\n if (!shadowRoot || !currentShadows.has(shadowRoot)) {\n shadowTargets.delete(shadowRootWeakRef);\n\n if (shadowRoot) {\n shadowRoot.removeEventListener(\"focusin\", focusInHandler, true);\n shadowRoot.removeEventListener(\"focusout\", focusOutHandler, true);\n }\n }\n }\n\n onFocusIn(target, (e.relatedTarget as HTMLElement | null) || undefined);\n };\n\n const onFocusIn = (\n target: Element,\n relatedTarget?: HTMLElement,\n originalEvent?: FocusEvent,\n ) => {\n const shadowRoot = target.shadowRoot;\n\n if (shadowRoot) {\n /**\n * https://bugs.chromium.org/p/chromium/issues/detail?id=1512028\n * focusin events don't bubble up through an open shadow root once focus is inside\n * once focus moves into a shadow root - we drop the same focusin handler there\n * keyborg's custom event will still bubble up since it is composed\n * event handlers should be cleaned up once focus leaves the shadow root.\n *\n * When a focusin event is dispatched from a shadow root, its target is the shadow root parent.\n * Each shadow root encounter requires a new capture listener.\n * Why capture? - we want to follow the focus event in order or descending nested shadow roots\n * When there are no more shadow root targets - dispatch the keyborg:focusin event\n *\n * 1. no focus event\n * > document - capture listener ✅\n * > shadow root 1\n * > shadow root 2\n * > shadow root 3\n * > focused element\n *\n * 2. focus event received by document listener\n * > document - capture listener ✅ (focus event here)\n * > shadow root 1 - capture listener ✅\n * > shadow root 2\n * > shadow root 3\n * > focused element\n\n * 3. focus event received by root l1 listener\n * > document - capture listener ✅\n * > shadow root 1 - capture listener ✅ (focus event here)\n * > shadow root 2 - capture listener ✅\n * > shadow root 3\n * > focused element\n *\n * 4. focus event received by root l2 listener\n * > document - capture listener ✅\n * > shadow root 1 - capture listener ✅\n * > shadow root 2 - capture listener ✅ (focus event here)\n * > shadow root 3 - capture listener ✅\n * > focused element\n *\n * 5. focus event received by root l3 listener, no more shadow root targets\n * > document - capture listener ✅\n * > shadow root 1 - capture listener ✅\n * > shadow root 2 - capture listener ✅\n * > shadow root 3 - capture listener ✅ (focus event here)\n * > focused element ✅ (no shadow root - dispatch keyborg event)\n */\n\n for (const shadowRootWeakRef of shadowTargets) {\n if (shadowRootWeakRef.deref() === shadowRoot) {\n return;\n }\n }\n\n shadowRoot.addEventListener(\"focusin\", focusInHandler, true);\n shadowRoot.addEventListener(\"focusout\", focusOutHandler, true);\n\n shadowTargets.add(new WeakRefInstance(shadowRoot));\n\n return;\n }\n\n const details: KeyborgFocusInEventDetails = {\n relatedTarget,\n originalEvent,\n };\n\n const event: KeyborgFocusInEvent = new CustomEvent(KEYBORG_FOCUSIN, {\n cancelable: true,\n bubbles: true,\n // Allows the event to bubble past an open shadow root\n composed: true,\n detail: details,\n });\n\n // Tabster (and other users) can still use the legacy details field - keeping for backwards compat\n event.details = details;\n\n if (_canOverrideNativeFocus || data.lastFocusedProgrammatically) {\n details.isFocusedProgrammatically =\n target === data.lastFocusedProgrammatically?.deref();\n\n data.lastFocusedProgrammatically = undefined;\n }\n\n target.dispatchEvent(event);\n };\n\n const data: KeyborgFocusEventData = (kwin.__keyborgData = {\n focusInHandler,\n focusOutHandler,\n shadowTargets,\n });\n\n kwin.document.addEventListener(\n \"focusin\",\n kwin.__keyborgData.focusInHandler,\n true,\n );\n\n kwin.document.addEventListener(\n \"focusout\",\n kwin.__keyborgData.focusOutHandler,\n true,\n );\n\n function focus(this: HTMLElement) {\n const keyborgNativeFocusEvent = (kwin as WindowWithKeyborgFocusEvent)\n .__keyborgData;\n\n if (keyborgNativeFocusEvent) {\n keyborgNativeFocusEvent.lastFocusedProgrammatically = new WeakRefInstance(\n this,\n );\n }\n\n // eslint-disable-next-line prefer-rest-params\n return origFocus.apply(this, arguments);\n }\n\n let activeElement = kwin.document.activeElement as Element | null;\n\n // If keyborg is created with the focus inside shadow root, we need\n // to go through the shadows up to make sure all relevant shadows\n // have focus handlers attached.\n while (activeElement && activeElement.shadowRoot) {\n onFocusIn(activeElement);\n activeElement = activeElement.shadowRoot.activeElement;\n }\n\n (focus as KeyborgFocus).__keyborgNativeFocus = origFocus;\n}\n\n/**\n * Removes keyborg event listeners and custom focus override\n * @param win The window that stores keyborg focus events\n */\nexport function disposeFocusEvent(win: Window): void {\n const kwin = win as WindowWithKeyborgFocusEvent;\n const proto = kwin.HTMLElement.prototype;\n const origFocus = (proto.focus as KeyborgFocus).__keyborgNativeFocus;\n const keyborgNativeFocusEvent = kwin.__keyborgData;\n\n if (keyborgNativeFocusEvent) {\n kwin.document.removeEventListener(\n \"focusin\",\n keyborgNativeFocusEvent.focusInHandler,\n true,\n );\n\n kwin.document.removeEventListener(\n \"focusout\",\n keyborgNativeFocusEvent.focusOutHandler,\n true,\n );\n\n for (const shadowRootWeakRef of keyborgNativeFocusEvent.shadowTargets) {\n const shadowRoot = shadowRootWeakRef.deref();\n\n if (shadowRoot) {\n shadowRoot.removeEventListener(\n \"focusin\",\n keyborgNativeFocusEvent.focusInHandler,\n true,\n );\n shadowRoot.removeEventListener(\n \"focusout\",\n keyborgNativeFocusEvent.focusOutHandler,\n true,\n );\n }\n }\n\n keyborgNativeFocusEvent.shadowTargets.clear();\n\n delete kwin.__keyborgData;\n }\n\n if (origFocus) {\n proto.focus = origFocus;\n }\n}\n\n/**\n * @param win The window that stores keyborg focus events\n * @returns The last element focused with element.focus()\n */\nexport function getLastFocusedProgrammatically(\n win: Window,\n): HTMLElement | null | undefined {\n const keyborgNativeFocusEvent = (win as WindowWithKeyborgFocusEvent)\n .__keyborgData;\n\n return keyborgNativeFocusEvent\n ? keyborgNativeFocusEvent.lastFocusedProgrammatically?.deref() || null\n : undefined;\n}\n","/*!\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n disposeFocusEvent,\n KeyborgFocusInEvent,\n KEYBORG_FOCUSIN,\n setupFocusEvent,\n} from \"./FocusEvent\";\nimport { Disposable } from \"./WeakRefInstance\";\n\ninterface WindowWithKeyborg extends Window {\n __keyborg?: {\n core: KeyborgCore;\n refs: { [id: string]: Keyborg };\n };\n}\n\nconst _dismissTimeout = 500; // When a key from dismissKeys is pressed and the focus is not moved\n// during _dismissTimeout time, dismiss the keyboard navigation mode.\n\nlet _lastId = 0;\n\nexport interface KeyborgProps {\n // Keys to be used to trigger keyboard navigation mode. By default, any key will trigger\n // it. Could be limited to, for example, just Tab (or Tab and arrow keys).\n triggerKeys?: number[];\n // Keys to be used to dismiss keyboard navigation mode using keyboard (in addition to\n // mouse clicks which dismiss it). For example, Esc could be used to dismiss.\n dismissKeys?: number[];\n}\n\nexport type KeyborgCallback = (isNavigatingWithKeyboard: boolean) => void;\n\n/**\n * Manages a collection of Keyborg instances in a window/document and updates keyborg state\n */\nclass KeyborgCore implements Disposable {\n readonly id: string;\n\n private _win?: WindowWithKeyborg;\n private _isMouseOrTouchUsedTimer: number | undefined;\n private _dismissTimer: number | undefined;\n private _triggerKeys?: Set<number>;\n private _dismissKeys?: Set<number>;\n private _isNavigatingWithKeyboard_DO_NOT_USE = false;\n\n constructor(win: WindowWithKeyborg, props?: KeyborgProps) {\n this.id = \"c\" + ++_lastId;\n this._win = win;\n const doc = win.document;\n\n if (props) {\n const triggerKeys = props.triggerKeys;\n const dismissKeys = props.dismissKeys;\n\n if (triggerKeys?.length) {\n this._triggerKeys = new Set(triggerKeys);\n }\n\n if (dismissKeys?.length) {\n this._dismissKeys = new Set(dismissKeys);\n }\n }\n\n doc.addEventListener(KEYBORG_FOCUSIN, this._onFocusIn, true); // Capture!\n doc.addEventListener(\"mousedown\", this._onMouseDown, true); // Capture!\n win.addEventListener(\"keydown\", this._onKeyDown, true); // Capture!\n\n doc.addEventListener(\"touchstart\", this._onMouseOrTouch, true); // Capture!\n doc.addEventListener(\"touchend\", this._onMouseOrTouch, true); // Capture!\n doc.addEventListener(\"touchcancel\", this._onMouseOrTouch, true); // Capture!\n\n setupFocusEvent(win);\n }\n\n get isNavigatingWithKeyboard() {\n return this._isNavigatingWithKeyboard_DO_NOT_USE;\n }\n\n set isNavigatingWithKeyboard(val: boolean) {\n if (this._isNavigatingWithKeyboard_DO_NOT_USE !== val) {\n this._isNavigatingWithKeyboard_DO_NOT_USE = val;\n this.update();\n }\n }\n\n dispose(): void {\n const win = this._win;\n\n if (win) {\n if (this._isMouseOrTouchUsedTimer) {\n win.clearTimeout(this._isMouseOrTouchUsedTimer);\n this._isMouseOrTouchUsedTimer = undefined;\n }\n\n if (this._dismissTimer) {\n win.clearTimeout(this._dismissTimer);\n this._dismissTimer = undefined;\n }\n\n disposeFocusEvent(win);\n\n const doc = win.document;\n\n doc.removeEventListener(KEYBORG_FOCUSIN, this._onFocusIn, true); // Capture!\n doc.removeEventListener(\"mousedown\", this._onMouseDown, true); // Capture!\n win.removeEventListener(\"keydown\", this._onKeyDown, true); // Capture!\n\n doc.removeEventListener(\"touchstart\", this._onMouseOrTouch, true); // Capture!\n doc.removeEventListener(\"touchend\", this._onMouseOrTouch, true); // Capture!\n doc.removeEventListener(\"touchcancel\", this._onMouseOrTouch, true); // Capture!\n\n delete this._win;\n }\n }\n\n isDisposed(): boolean {\n return !!this._win;\n }\n\n /**\n * Updates all keyborg instances with the keyboard navigation state\n */\n update(): void {\n const keyborgs = this._win?.__keyborg?.refs;\n\n if (keyborgs) {\n for (const id of Object.keys(keyborgs)) {\n Keyborg.update(keyborgs[id], this.isNavigatingWithKeyboard);\n }\n }\n }\n\n private _onFocusIn = (e: KeyborgFocusInEvent) => {\n // When the focus is moved not programmatically and without keydown events,\n // it is likely that the focus is moved by screen reader (as it might swallow\n // the events when the screen reader shortcuts are used). The screen reader\n // usage is keyboard navigation.\n\n if (this._isMouseOrTouchUsedTimer) {\n // There was a mouse or touch event recently.\n return;\n }\n\n if (this.isNavigatingWithKeyboard) {\n return;\n }\n\n const details = e.detail;\n\n if (!details.relatedTarget) {\n return;\n }\n\n if (\n details.isFocusedProgrammatically ||\n details.isFocusedProgrammatically === undefined\n ) {\n // The element is focused programmatically, or the programmatic focus detection\n // is not working.\n return;\n }\n\n this.isNavigatingWithKeyboard = true;\n };\n\n private _onMouseDown = (e: MouseEvent): void => {\n if (\n e.buttons === 0 ||\n (e.clientX === 0 && e.clientY === 0 && e.screenX === 0 && e.screenY === 0)\n ) {\n // This is most likely an event triggered by the screen reader to perform\n // an action on an element, do not dismiss the keyboard navigation mode.\n return;\n }\n\n this._onMouseOrTouch();\n };\n\n private _onMouseOrTouch = (): void => {\n const win = this._win;\n\n if (win) {\n if (this._isMouseOrTouchUsedTimer) {\n win.clearTimeout(this._isMouseOrTouchUsedTimer);\n }\n\n this._isMouseOrTouchUsedTimer = win.setTimeout(() => {\n delete this._isMouseOrTouchUsedTimer;\n }, 1000); // Keeping the indication of mouse or touch usage for some time.\n }\n\n this.isNavigatingWithKeyboard = false;\n };\n\n private _onKeyDown = (e: KeyboardEvent): void => {\n const isNavigatingWithKeyboard = this.isNavigatingWithKeyboard;\n\n if (isNavigatingWithKeyboard) {\n if (this._shouldDismissKeyboardNavigation(e)) {\n this._scheduleDismiss();\n }\n } else {\n if (this._shouldTriggerKeyboardNavigation(e)) {\n this.isNavigatingWithKeyboard = true;\n }\n }\n };\n\n /**\n * @returns whether the keyboard event should trigger keyboard navigation mode\n */\n private _shouldTriggerKeyboardNavigation(e: KeyboardEvent) {\n // TODO Some rich text fields can allow Tab key for indentation so it doesn't\n // need to be a navigation key. If there is a bug regarding that we should revisit\n if (e.key === \"Tab\") {\n return true;\n }\n\n const activeElement = this._win?.document\n .activeElement as HTMLElement | null;\n const isTriggerKey = !this._triggerKeys || this._triggerKeys.has(e.keyCode);\n\n const isEditable =\n activeElement &&\n (activeElement.tagName === \"INPUT\" ||\n activeElement.tagName === \"TEXTAREA\" ||\n activeElement.isContentEditable);\n\n return isTriggerKey && !isEditable;\n }\n\n /**\n * @returns whether the keyboard event should dismiss keyboard navigation mode\n */\n private _shouldDismissKeyboardNavigation(e: KeyboardEvent) {\n return this._dismissKeys?.has(e.keyCode);\n }\n\n private _scheduleDismiss(): void {\n const win = this._win;\n\n if (win) {\n if (this._dismissTimer) {\n win.clearTimeout(this._dismissTimer);\n this._dismissTimer = undefined;\n }\n\n const was = win.document.activeElement;\n\n this._dismissTimer = win.setTimeout(() => {\n this._dismissTimer = undefined;\n\n const cur = win.document.activeElement;\n\n if (was && cur && was === cur) {\n // Esc was pressed, currently focused element hasn't changed.\n // Just dismiss the keyboard navigation mode.\n this.isNavigatingWithKeyboard = false;\n }\n }, _dismissTimeout);\n }\n }\n}\n\n/**\n * Used to determine the keyboard navigation state\n */\nexport class Keyborg {\n private _id: string;\n private _win?: WindowWithKeyborg;\n private _core?: KeyborgCore;\n private _cb: KeyborgCallback[] = [];\n\n static create(win: WindowWithKeyborg, props?: KeyborgProps): Keyborg {\n return new Keyborg(win, props);\n }\n\n static dispose(instance: Keyborg): void {\n instance.dispose();\n }\n\n /**\n * Updates all subscribed callbacks with the keyboard navigation state\n */\n static update(instance: Keyborg, isNavigatingWithKeyboard: boolean): void {\n instance._cb.forEach((callback) => callback(isNavigatingWithKeyboard));\n }\n\n private constructor(win: WindowWithKeyborg, props?: KeyborgProps) {\n this._id = \"k\" + ++_lastId;\n this._win = win;\n\n const current = win.__keyborg;\n\n if (current) {\n this._core = current.core;\n current.refs[this._id] = this;\n } else {\n this._core = new KeyborgCore(win, props);\n win.__keyborg = {\n core: this._core,\n refs: { [this._id]: this },\n };\n }\n }\n\n private dispose(): void {\n const current = this._win?.__keyborg;\n\n if (current?.refs[this._id]) {\n delete current.refs[this._id];\n\n if (Object.keys(current.refs).length === 0) {\n current.core.dispose();\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n delete this._win!.__keyborg;\n }\n } else if (process.env.NODE_ENV !== \"production\") {\n console.error(\n `Keyborg instance ${this._id} is being disposed incorrectly.`,\n );\n }\n\n this._cb = [];\n delete this._core;\n delete this._win;\n }\n\n /**\n * @returns Whether the user is navigating with keyboard\n */\n isNavigatingWithKeyboard(): boolean {\n return !!this._core?.isNavigatingWithKeyboard;\n }\n\n /**\n * @param callback - Called when the keyboard navigation state changes\n */\n subscribe(callback: KeyborgCallback): void {\n this._cb.push(callback);\n }\n\n /**\n * @param callback - Registered with subscribe\n */\n unsubscribe(callback: KeyborgCallback): void {\n const index = this._cb.indexOf(callback);\n\n if (index >= 0) {\n this._cb.splice(index, 1);\n }\n }\n\n /**\n * Manually set the keyboard navigtion state\n */\n setVal(isNavigatingWithKeyboard: boolean): void {\n if (this._core) {\n this._core.isNavigatingWithKeyboard = isNavigatingWithKeyboard;\n }\n }\n}\n\nexport function createKeyborg(win: Window, props?: KeyborgProps): Keyborg {\n return Keyborg.create(win, props);\n}\n\nexport function disposeKeyborg(instance: Keyborg) {\n Keyborg.dispose(instance);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACMO,IAAM,iBAAiB,OAAO,YAAY;AAc1C,IAAM,kBAAN,MAAqD;AAAA,EAI1D,YAAY,UAAa;AACvB,QAAI,kBAAkB,OAAO,aAAa,UAAU;AAClD,WAAK,WAAW,IAAI,QAAQ,QAAQ;AAAA,IACtC,OAAO;AACL,WAAK,YAAY;AAAA,IACnB;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,QAAuB;AAnCzB;AAoCI,QAAI;AAEJ,QAAI,KAAK,UAAU;AACjB,kBAAW,UAAK,aAAL,mBAAe;AAE1B,UAAI,CAAC,UAAU;AACb,eAAO,KAAK;AAAA,MACd;AAAA,IACF,OAAO;AACL,iBAAW,KAAK;AAChB,WA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oBAAoB,KAAK,GAAG;AAAA,MAC9B;AAAA,IACF;AAEA,SAAK,MAAM,CAAC;AACZ,WAAO,KAAK;AACZ,WAAO,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA,EAKA,2BAAoC;AA/UtC;AAgVI,WAAO,CAAC,GAAC,UAAK,UAAL,mBAAY;AAAA,EACvB;AAAA;AAAA;AAAA;AAAA,EAKA,UAAU,UAAiC;AACzC,SAAK,IAAI,KAAK,QAAQ;AAAA,EACxB;AAAA;AAAA;AAAA;AAAA,EAKA,YAAY,UAAiC;AAC3C,UAAM,QAAQ,KAAK,IAAI,QAAQ,QAAQ;AAEvC,QAAI,SAAS,GAAG;AACd,WAAK,IAAI,OAAO,OAAO,CAAC;AAAA,IAC1B;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,OAAO,0BAAyC;AAC9C,QAAI,KAAK,OAAO;AACd,WAAK,MAAM,2BAA2B;AAAA,IACxC;AAAA,EACF;AACF;AAEO,SAAS,cAAc,KAAa,OAA+B;AACxE,SAAO,QAAQ,OAAO,KAAK,KAAK;AAClC;AAEO,SAAS,eAAe,UAAmB;AAChD,UAAQ,QAAQ,QAAQ;AAC1B;;;AHhWO,IAAM,UAAU;","names":[]}
|
package/dist/ts3.9/index.d.ts
CHANGED
|
@@ -27,19 +27,22 @@ type KeyborgCallback = (isNavigatingWithKeyboard: boolean) => void;
|
|
|
27
27
|
declare class KeyborgCore implements Disposable {
|
|
28
28
|
readonly id: string;
|
|
29
29
|
private _win?;
|
|
30
|
-
private
|
|
30
|
+
private _isMouseOrTouchUsedTimer;
|
|
31
31
|
private _dismissTimer;
|
|
32
32
|
private _triggerKeys?;
|
|
33
33
|
private _dismissKeys?;
|
|
34
|
+
private _isNavigatingWithKeyboard_DO_NOT_USE;
|
|
34
35
|
constructor(win: WindowWithKeyborg, props?: KeyborgProps);
|
|
36
|
+
isNavigatingWithKeyboard: boolean;
|
|
35
37
|
dispose(): void;
|
|
36
38
|
isDisposed(): boolean;
|
|
37
39
|
/**
|
|
38
40
|
* Updates all keyborg instances with the keyboard navigation state
|
|
39
41
|
*/
|
|
40
|
-
update(
|
|
42
|
+
update(): void;
|
|
41
43
|
private _onFocusIn;
|
|
42
44
|
private _onMouseDown;
|
|
45
|
+
private _onMouseOrTouch;
|
|
43
46
|
private _onKeyDown;
|
|
44
47
|
/**
|
|
45
48
|
* @returns whether the keyboard event should trigger keyboard navigation mode
|