keyborg 1.2.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Keyborg.d.ts +9 -3
- package/dist/index.js +31 -15
- package/dist/index.js.map +1 -1
- package/dist/keyborg.esm.js +31 -15
- package/dist/keyborg.esm.js.map +1 -1
- package/package.json +2 -2
package/dist/Keyborg.d.ts
CHANGED
|
@@ -11,6 +11,10 @@ interface WindowWithKeyborg extends Window {
|
|
|
11
11
|
};
|
|
12
12
|
};
|
|
13
13
|
}
|
|
14
|
+
export interface KeyborgProps {
|
|
15
|
+
triggerKeys?: number[];
|
|
16
|
+
dismissKeys?: number[];
|
|
17
|
+
}
|
|
14
18
|
export declare type KeyborgCallback = (isNavigatingWithKeyboard: boolean) => void;
|
|
15
19
|
/**
|
|
16
20
|
* Source of truth for all the keyborg core instances and the current keyboard navigation state
|
|
@@ -31,7 +35,9 @@ declare class KeyborgCore implements Disposable {
|
|
|
31
35
|
private _win?;
|
|
32
36
|
private _isMouseUsed;
|
|
33
37
|
private _dismissTimer;
|
|
34
|
-
|
|
38
|
+
private _triggerKeys?;
|
|
39
|
+
private _dismissKeys?;
|
|
40
|
+
constructor(win: WindowWithKeyborg, props?: KeyborgProps);
|
|
35
41
|
dispose(): void;
|
|
36
42
|
isDisposed(): boolean;
|
|
37
43
|
/**
|
|
@@ -51,7 +57,7 @@ export declare class Keyborg {
|
|
|
51
57
|
private _win?;
|
|
52
58
|
private _core?;
|
|
53
59
|
private _cb;
|
|
54
|
-
static create(win: WindowWithKeyborg): Keyborg;
|
|
60
|
+
static create(win: WindowWithKeyborg, props?: KeyborgProps): Keyborg;
|
|
55
61
|
static dispose(instance: Keyborg): void;
|
|
56
62
|
/**
|
|
57
63
|
* Updates all subscribed callbacks with the keyboard navigation state
|
|
@@ -76,6 +82,6 @@ export declare class Keyborg {
|
|
|
76
82
|
*/
|
|
77
83
|
setVal(isNavigatingWithKeyboard: boolean): void;
|
|
78
84
|
}
|
|
79
|
-
export declare function createKeyborg(win: Window): Keyborg;
|
|
85
|
+
export declare function createKeyborg(win: Window, props?: KeyborgProps): Keyborg;
|
|
80
86
|
export declare function disposeKeyborg(instance: Keyborg): void;
|
|
81
87
|
export {};
|
package/dist/index.js
CHANGED
|
@@ -181,11 +181,8 @@ function getLastFocusedProgrammatically(win) {
|
|
|
181
181
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
182
182
|
* Licensed under the MIT License.
|
|
183
183
|
*/
|
|
184
|
-
const
|
|
185
|
-
|
|
186
|
-
const _dismissTimeout = 500; // When Esc is pressed and the focused is not moved
|
|
187
|
-
// during _dismissTimeout time, dismiss the keyboard
|
|
188
|
-
// navigation mode.
|
|
184
|
+
const _dismissTimeout = 500; // When a key from dismissKeys is pressed and the focus is not moved
|
|
185
|
+
// during _dismissTimeout time, dismiss the keyboard navigation mode.
|
|
189
186
|
|
|
190
187
|
let _lastId = 0;
|
|
191
188
|
/**
|
|
@@ -246,7 +243,7 @@ const _state = /*#__PURE__*/new KeyborgState();
|
|
|
246
243
|
|
|
247
244
|
|
|
248
245
|
class KeyborgCore {
|
|
249
|
-
constructor(win) {
|
|
246
|
+
constructor(win, props) {
|
|
250
247
|
this._isMouseUsed = false;
|
|
251
248
|
|
|
252
249
|
this._onFocusIn = e => {
|
|
@@ -287,11 +284,16 @@ class KeyborgCore {
|
|
|
287
284
|
};
|
|
288
285
|
|
|
289
286
|
this._onKeyDown = e => {
|
|
287
|
+
var _a;
|
|
288
|
+
|
|
290
289
|
const isNavigatingWithKeyboard = _state.getVal();
|
|
291
290
|
|
|
292
|
-
|
|
291
|
+
const keyCode = e.keyCode;
|
|
292
|
+
const triggerKeys = this._triggerKeys;
|
|
293
|
+
|
|
294
|
+
if (!isNavigatingWithKeyboard && (!triggerKeys || triggerKeys.has(keyCode))) {
|
|
293
295
|
_state.setVal(true);
|
|
294
|
-
} else if (isNavigatingWithKeyboard &&
|
|
296
|
+
} else if (isNavigatingWithKeyboard && ((_a = this._dismissKeys) === null || _a === void 0 ? void 0 : _a.has(keyCode))) {
|
|
295
297
|
this._scheduleDismiss();
|
|
296
298
|
}
|
|
297
299
|
};
|
|
@@ -299,6 +301,20 @@ class KeyborgCore {
|
|
|
299
301
|
this.id = "c" + ++_lastId;
|
|
300
302
|
this._win = win;
|
|
301
303
|
const doc = win.document;
|
|
304
|
+
|
|
305
|
+
if (props) {
|
|
306
|
+
const triggerKeys = props.triggerKeys;
|
|
307
|
+
const dismissKeys = props.dismissKeys;
|
|
308
|
+
|
|
309
|
+
if (triggerKeys === null || triggerKeys === void 0 ? void 0 : triggerKeys.length) {
|
|
310
|
+
this._triggerKeys = new Set(triggerKeys);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
if (dismissKeys === null || dismissKeys === void 0 ? void 0 : dismissKeys.length) {
|
|
314
|
+
this._dismissKeys = new Set(dismissKeys);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
302
318
|
doc.addEventListener(KEYBORG_FOCUSIN, this._onFocusIn, true); // Capture!
|
|
303
319
|
|
|
304
320
|
doc.addEventListener("mousedown", this._onMouseDown, true); // Capture!
|
|
@@ -383,7 +399,7 @@ class KeyborgCore {
|
|
|
383
399
|
|
|
384
400
|
|
|
385
401
|
class Keyborg {
|
|
386
|
-
constructor(win) {
|
|
402
|
+
constructor(win, props) {
|
|
387
403
|
this._cb = [];
|
|
388
404
|
this._id = "k" + ++_lastId;
|
|
389
405
|
this._win = win;
|
|
@@ -393,7 +409,7 @@ class Keyborg {
|
|
|
393
409
|
this._core = current.core;
|
|
394
410
|
current.refs[this._id] = this;
|
|
395
411
|
} else {
|
|
396
|
-
this._core = new KeyborgCore(win);
|
|
412
|
+
this._core = new KeyborgCore(win, props);
|
|
397
413
|
win.__keyborg = {
|
|
398
414
|
core: this._core,
|
|
399
415
|
refs: {
|
|
@@ -403,8 +419,8 @@ class Keyborg {
|
|
|
403
419
|
}
|
|
404
420
|
}
|
|
405
421
|
|
|
406
|
-
static create(win) {
|
|
407
|
-
return new Keyborg(win);
|
|
422
|
+
static create(win, props) {
|
|
423
|
+
return new Keyborg(win, props);
|
|
408
424
|
}
|
|
409
425
|
|
|
410
426
|
static dispose(instance) {
|
|
@@ -478,8 +494,8 @@ class Keyborg {
|
|
|
478
494
|
}
|
|
479
495
|
|
|
480
496
|
}
|
|
481
|
-
function createKeyborg(win) {
|
|
482
|
-
return Keyborg.create(win);
|
|
497
|
+
function createKeyborg(win, props) {
|
|
498
|
+
return Keyborg.create(win, props);
|
|
483
499
|
}
|
|
484
500
|
function disposeKeyborg(instance) {
|
|
485
501
|
Keyborg.dispose(instance);
|
|
@@ -489,7 +505,7 @@ function disposeKeyborg(instance) {
|
|
|
489
505
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
490
506
|
* Licensed under the MIT License.
|
|
491
507
|
*/
|
|
492
|
-
const version = "
|
|
508
|
+
const version = "2.0.0";
|
|
493
509
|
|
|
494
510
|
exports.KEYBORG_FOCUSIN = KEYBORG_FOCUSIN;
|
|
495
511
|
exports.Keyborg = Keyborg;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/keyborg.esm.js
CHANGED
|
@@ -177,11 +177,8 @@ function getLastFocusedProgrammatically(win) {
|
|
|
177
177
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
178
178
|
* Licensed under the MIT License.
|
|
179
179
|
*/
|
|
180
|
-
const
|
|
181
|
-
|
|
182
|
-
const _dismissTimeout = 500; // When Esc is pressed and the focused is not moved
|
|
183
|
-
// during _dismissTimeout time, dismiss the keyboard
|
|
184
|
-
// navigation mode.
|
|
180
|
+
const _dismissTimeout = 500; // When a key from dismissKeys is pressed and the focus is not moved
|
|
181
|
+
// during _dismissTimeout time, dismiss the keyboard navigation mode.
|
|
185
182
|
|
|
186
183
|
let _lastId = 0;
|
|
187
184
|
/**
|
|
@@ -242,7 +239,7 @@ const _state = /*#__PURE__*/new KeyborgState();
|
|
|
242
239
|
|
|
243
240
|
|
|
244
241
|
class KeyborgCore {
|
|
245
|
-
constructor(win) {
|
|
242
|
+
constructor(win, props) {
|
|
246
243
|
this._isMouseUsed = false;
|
|
247
244
|
|
|
248
245
|
this._onFocusIn = e => {
|
|
@@ -283,11 +280,16 @@ class KeyborgCore {
|
|
|
283
280
|
};
|
|
284
281
|
|
|
285
282
|
this._onKeyDown = e => {
|
|
283
|
+
var _a;
|
|
284
|
+
|
|
286
285
|
const isNavigatingWithKeyboard = _state.getVal();
|
|
287
286
|
|
|
288
|
-
|
|
287
|
+
const keyCode = e.keyCode;
|
|
288
|
+
const triggerKeys = this._triggerKeys;
|
|
289
|
+
|
|
290
|
+
if (!isNavigatingWithKeyboard && (!triggerKeys || triggerKeys.has(keyCode))) {
|
|
289
291
|
_state.setVal(true);
|
|
290
|
-
} else if (isNavigatingWithKeyboard &&
|
|
292
|
+
} else if (isNavigatingWithKeyboard && ((_a = this._dismissKeys) === null || _a === void 0 ? void 0 : _a.has(keyCode))) {
|
|
291
293
|
this._scheduleDismiss();
|
|
292
294
|
}
|
|
293
295
|
};
|
|
@@ -295,6 +297,20 @@ class KeyborgCore {
|
|
|
295
297
|
this.id = "c" + ++_lastId;
|
|
296
298
|
this._win = win;
|
|
297
299
|
const doc = win.document;
|
|
300
|
+
|
|
301
|
+
if (props) {
|
|
302
|
+
const triggerKeys = props.triggerKeys;
|
|
303
|
+
const dismissKeys = props.dismissKeys;
|
|
304
|
+
|
|
305
|
+
if (triggerKeys === null || triggerKeys === void 0 ? void 0 : triggerKeys.length) {
|
|
306
|
+
this._triggerKeys = new Set(triggerKeys);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
if (dismissKeys === null || dismissKeys === void 0 ? void 0 : dismissKeys.length) {
|
|
310
|
+
this._dismissKeys = new Set(dismissKeys);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
298
314
|
doc.addEventListener(KEYBORG_FOCUSIN, this._onFocusIn, true); // Capture!
|
|
299
315
|
|
|
300
316
|
doc.addEventListener("mousedown", this._onMouseDown, true); // Capture!
|
|
@@ -379,7 +395,7 @@ class KeyborgCore {
|
|
|
379
395
|
|
|
380
396
|
|
|
381
397
|
class Keyborg {
|
|
382
|
-
constructor(win) {
|
|
398
|
+
constructor(win, props) {
|
|
383
399
|
this._cb = [];
|
|
384
400
|
this._id = "k" + ++_lastId;
|
|
385
401
|
this._win = win;
|
|
@@ -389,7 +405,7 @@ class Keyborg {
|
|
|
389
405
|
this._core = current.core;
|
|
390
406
|
current.refs[this._id] = this;
|
|
391
407
|
} else {
|
|
392
|
-
this._core = new KeyborgCore(win);
|
|
408
|
+
this._core = new KeyborgCore(win, props);
|
|
393
409
|
win.__keyborg = {
|
|
394
410
|
core: this._core,
|
|
395
411
|
refs: {
|
|
@@ -399,8 +415,8 @@ class Keyborg {
|
|
|
399
415
|
}
|
|
400
416
|
}
|
|
401
417
|
|
|
402
|
-
static create(win) {
|
|
403
|
-
return new Keyborg(win);
|
|
418
|
+
static create(win, props) {
|
|
419
|
+
return new Keyborg(win, props);
|
|
404
420
|
}
|
|
405
421
|
|
|
406
422
|
static dispose(instance) {
|
|
@@ -474,8 +490,8 @@ class Keyborg {
|
|
|
474
490
|
}
|
|
475
491
|
|
|
476
492
|
}
|
|
477
|
-
function createKeyborg(win) {
|
|
478
|
-
return Keyborg.create(win);
|
|
493
|
+
function createKeyborg(win, props) {
|
|
494
|
+
return Keyborg.create(win, props);
|
|
479
495
|
}
|
|
480
496
|
function disposeKeyborg(instance) {
|
|
481
497
|
Keyborg.dispose(instance);
|
|
@@ -485,7 +501,7 @@ function disposeKeyborg(instance) {
|
|
|
485
501
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
486
502
|
* Licensed under the MIT License.
|
|
487
503
|
*/
|
|
488
|
-
const version = "
|
|
504
|
+
const version = "2.0.0";
|
|
489
505
|
|
|
490
506
|
export { KEYBORG_FOCUSIN, Keyborg, createKeyborg, disposeKeyborg, getLastFocusedProgrammatically, nativeFocus, version };
|
|
491
507
|
//# sourceMappingURL=keyborg.esm.js.map
|
package/dist/keyborg.esm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keyborg.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"keyborg.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "keyborg",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Keyboard Navigation Detection for Web",
|
|
5
5
|
"author": "Marat Abdullin <marata@microsoft.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"eslint-plugin-import": "^2.25.3",
|
|
47
47
|
"node-fetch": "^2.6.6",
|
|
48
48
|
"prettier": "^2.4.1",
|
|
49
|
-
"release-it": "^
|
|
49
|
+
"release-it": "^15.6.0",
|
|
50
50
|
"rimraf": "^3.0.2",
|
|
51
51
|
"rollup": "^2.60.1",
|
|
52
52
|
"rollup-plugin-sourcemaps": "^0.6.3",
|