keyborg 1.1.0-alpha.1 → 1.1.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/{lib-commonjs → dist}/FocusEvent.d.ts +0 -0
- package/{lib-commonjs → dist}/Keyborg.d.ts +0 -0
- package/{lib-commonjs → dist}/WeakRefInstance.d.ts +0 -0
- package/{lib-commonjs → dist}/index.d.ts +0 -0
- package/{lib-commonjs/Keyborg.js → dist/index.js} +190 -9
- package/dist/index.js.map +1 -0
- package/{lib/Keyborg.js → dist/keyborg.esm.js} +182 -4
- package/dist/keyborg.esm.js.map +1 -0
- package/package.json +10 -11
- package/lib/FocusEvent.d.ts +0 -26
- package/lib/FocusEvent.js +0 -130
- package/lib/FocusEvent.js.map +0 -1
- package/lib/Keyborg.d.ts +0 -81
- package/lib/Keyborg.js.map +0 -1
- package/lib/WeakRefInstance.d.ts +0 -25
- package/lib/WeakRefInstance.js +0 -51
- package/lib/WeakRefInstance.js.map +0 -1
- package/lib/index.d.ts +0 -7
- package/lib/index.js +0 -11
- package/lib/index.js.map +0 -1
- package/lib-commonjs/FocusEvent.js +0 -138
- package/lib-commonjs/FocusEvent.js.map +0 -1
- package/lib-commonjs/Keyborg.js.map +0 -1
- package/lib-commonjs/WeakRefInstance.js +0 -56
- package/lib-commonjs/WeakRefInstance.js.map +0 -1
- package/lib-commonjs/index.js +0 -21
- package/lib-commonjs/index.js.map +0 -1
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -2,8 +2,180 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
/*!
|
|
6
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
7
|
+
* Licensed under the MIT License.
|
|
8
|
+
*/
|
|
9
|
+
// IE11 compat, checks if WeakRef is supported
|
|
10
|
+
const _canUseWeakRef = typeof WeakRef !== "undefined";
|
|
11
|
+
/**
|
|
12
|
+
* WeakRef wrapper around a HTMLElement that also supports IE11
|
|
13
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakRef}
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
class WeakRefInstance {
|
|
18
|
+
constructor(instance) {
|
|
19
|
+
if (_canUseWeakRef && typeof instance === "object") {
|
|
20
|
+
this._weakRef = new WeakRef(instance);
|
|
21
|
+
} else {
|
|
22
|
+
this._instance = instance;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakRef/deref}
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
deref() {
|
|
31
|
+
var _a, _b, _c;
|
|
32
|
+
|
|
33
|
+
let instance;
|
|
34
|
+
|
|
35
|
+
if (this._weakRef) {
|
|
36
|
+
instance = (_a = this._weakRef) === null || _a === void 0 ? void 0 : _a.deref();
|
|
37
|
+
|
|
38
|
+
if (!instance) {
|
|
39
|
+
delete this._weakRef;
|
|
40
|
+
}
|
|
41
|
+
} else {
|
|
42
|
+
instance = this._instance;
|
|
43
|
+
|
|
44
|
+
if ((_c = (_b = instance) === null || _b === void 0 ? void 0 : _b.isDisposed) === null || _c === void 0 ? void 0 : _c.call(_b)) {
|
|
45
|
+
delete this._instance;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return instance;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/*!
|
|
55
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
56
|
+
* Licensed under the MIT License.
|
|
57
|
+
*/
|
|
58
|
+
const KEYBORG_FOCUSIN = "keyborg:focusin";
|
|
59
|
+
|
|
60
|
+
function canOverrideNativeFocus(win) {
|
|
61
|
+
const HTMLElement = win.HTMLElement;
|
|
62
|
+
const origFocus = HTMLElement.prototype.focus;
|
|
63
|
+
let isCustomFocusCalled = false;
|
|
64
|
+
|
|
65
|
+
HTMLElement.prototype.focus = function focus() {
|
|
66
|
+
isCustomFocusCalled = true;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const btn = win.document.createElement("button");
|
|
70
|
+
btn.focus();
|
|
71
|
+
HTMLElement.prototype.focus = origFocus;
|
|
72
|
+
return isCustomFocusCalled;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
let _canOverrideNativeFocus = false;
|
|
76
|
+
/**
|
|
77
|
+
* Guarantees that the native `focus` will be used
|
|
78
|
+
*/
|
|
79
|
+
|
|
80
|
+
function nativeFocus(element) {
|
|
81
|
+
const focus = element.focus;
|
|
82
|
+
|
|
83
|
+
if (focus.__keyborgNativeFocus) {
|
|
84
|
+
focus.__keyborgNativeFocus.call(element);
|
|
85
|
+
} else {
|
|
86
|
+
element.focus();
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Overrides the native `focus` and setups the keyborg focus event
|
|
91
|
+
*/
|
|
92
|
+
|
|
93
|
+
function setupFocusEvent(win) {
|
|
94
|
+
const kwin = win;
|
|
95
|
+
|
|
96
|
+
if (!_canOverrideNativeFocus) {
|
|
97
|
+
_canOverrideNativeFocus = canOverrideNativeFocus(kwin);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const origFocus = kwin.HTMLElement.prototype.focus;
|
|
101
|
+
|
|
102
|
+
if (origFocus.__keyborgNativeFocus) {
|
|
103
|
+
// Already set up.
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
kwin.HTMLElement.prototype.focus = focus;
|
|
108
|
+
const data = kwin.__keyborgData = {
|
|
109
|
+
focusInHandler: e => {
|
|
110
|
+
var _a;
|
|
111
|
+
|
|
112
|
+
const target = e.target;
|
|
113
|
+
|
|
114
|
+
if (!target) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const event = document.createEvent("HTMLEvents");
|
|
119
|
+
event.initEvent(KEYBORG_FOCUSIN, true, true);
|
|
120
|
+
const details = {
|
|
121
|
+
relatedTarget: e.relatedTarget || undefined
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
if (_canOverrideNativeFocus || data.lastFocusedProgrammatically) {
|
|
125
|
+
details.isFocusedProgrammatically = target === ((_a = data.lastFocusedProgrammatically) === null || _a === void 0 ? void 0 : _a.deref());
|
|
126
|
+
data.lastFocusedProgrammatically = undefined;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
event.details = details;
|
|
130
|
+
target.dispatchEvent(event);
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
kwin.document.addEventListener("focusin", kwin.__keyborgData.focusInHandler, true);
|
|
134
|
+
|
|
135
|
+
function focus() {
|
|
136
|
+
const keyborgNativeFocusEvent = kwin.__keyborgData;
|
|
137
|
+
|
|
138
|
+
if (keyborgNativeFocusEvent) {
|
|
139
|
+
keyborgNativeFocusEvent.lastFocusedProgrammatically = new WeakRefInstance(this);
|
|
140
|
+
} // eslint-disable-next-line prefer-rest-params
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
return origFocus.apply(this, arguments);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
focus.__keyborgNativeFocus = origFocus;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Removes keyborg event listeners and custom focus override
|
|
150
|
+
* @param win The window that stores keyborg focus events
|
|
151
|
+
*/
|
|
152
|
+
|
|
153
|
+
function disposeFocusEvent(win) {
|
|
154
|
+
const kwin = win;
|
|
155
|
+
const proto = kwin.HTMLElement.prototype;
|
|
156
|
+
const origFocus = proto.focus.__keyborgNativeFocus;
|
|
157
|
+
const keyborgNativeFocusEvent = kwin.__keyborgData;
|
|
158
|
+
|
|
159
|
+
if (keyborgNativeFocusEvent) {
|
|
160
|
+
kwin.document.removeEventListener("focusin", keyborgNativeFocusEvent.focusInHandler, true);
|
|
161
|
+
delete kwin.__keyborgData;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if (origFocus) {
|
|
165
|
+
proto.focus = origFocus;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* @param win The window that stores keyborg focus events
|
|
170
|
+
* @returns The last element focused with element.focus()
|
|
171
|
+
*/
|
|
172
|
+
|
|
173
|
+
function getLastFocusedProgrammatically(win) {
|
|
174
|
+
var _a;
|
|
175
|
+
|
|
176
|
+
const keyborgNativeFocusEvent = win.__keyborgData;
|
|
177
|
+
return keyborgNativeFocusEvent ? ((_a = keyborgNativeFocusEvent.lastFocusedProgrammatically) === null || _a === void 0 ? void 0 : _a.deref()) || null : undefined;
|
|
178
|
+
}
|
|
7
179
|
|
|
8
180
|
/*!
|
|
9
181
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
@@ -30,7 +202,7 @@ class KeyborgState {
|
|
|
30
202
|
const id = keyborg.id;
|
|
31
203
|
|
|
32
204
|
if (!(id in this.__keyborgCoreRefs)) {
|
|
33
|
-
this.__keyborgCoreRefs[id] = new WeakRefInstance
|
|
205
|
+
this.__keyborgCoreRefs[id] = new WeakRefInstance(keyborg);
|
|
34
206
|
}
|
|
35
207
|
}
|
|
36
208
|
|
|
@@ -127,13 +299,13 @@ class KeyborgCore {
|
|
|
127
299
|
this.id = "c" + ++_lastId;
|
|
128
300
|
this._win = win;
|
|
129
301
|
const doc = win.document;
|
|
130
|
-
doc.addEventListener(
|
|
302
|
+
doc.addEventListener(KEYBORG_FOCUSIN, this._onFocusIn, true); // Capture!
|
|
131
303
|
|
|
132
304
|
doc.addEventListener("mousedown", this._onMouseDown, true); // Capture!
|
|
133
305
|
|
|
134
306
|
win.addEventListener("keydown", this._onKeyDown, true); // Capture!
|
|
135
307
|
|
|
136
|
-
|
|
308
|
+
setupFocusEvent(win);
|
|
137
309
|
|
|
138
310
|
_state.add(this);
|
|
139
311
|
}
|
|
@@ -147,9 +319,9 @@ class KeyborgCore {
|
|
|
147
319
|
this._dismissTimer = undefined;
|
|
148
320
|
}
|
|
149
321
|
|
|
150
|
-
|
|
322
|
+
disposeFocusEvent(win);
|
|
151
323
|
const doc = win.document;
|
|
152
|
-
doc.removeEventListener(
|
|
324
|
+
doc.removeEventListener(KEYBORG_FOCUSIN, this._onFocusIn, true); // Capture!
|
|
153
325
|
|
|
154
326
|
doc.removeEventListener("mousedown", this._onMouseDown, true); // Capture!
|
|
155
327
|
|
|
@@ -313,8 +485,17 @@ function disposeKeyborg(instance) {
|
|
|
313
485
|
Keyborg.dispose(instance);
|
|
314
486
|
}
|
|
315
487
|
|
|
488
|
+
/*!
|
|
489
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
490
|
+
* Licensed under the MIT License.
|
|
491
|
+
*/
|
|
492
|
+
const version = "1.1.0";
|
|
493
|
+
|
|
494
|
+
exports.KEYBORG_FOCUSIN = KEYBORG_FOCUSIN;
|
|
316
495
|
exports.Keyborg = Keyborg;
|
|
317
|
-
exports.KeyborgState = KeyborgState;
|
|
318
496
|
exports.createKeyborg = createKeyborg;
|
|
319
497
|
exports.disposeKeyborg = disposeKeyborg;
|
|
320
|
-
|
|
498
|
+
exports.getLastFocusedProgrammatically = getLastFocusedProgrammatically;
|
|
499
|
+
exports.nativeFocus = nativeFocus;
|
|
500
|
+
exports.version = version;
|
|
501
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,5 +1,177 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
// IE11 compat, checks if WeakRef is supported
|
|
6
|
+
const _canUseWeakRef = typeof WeakRef !== "undefined";
|
|
7
|
+
/**
|
|
8
|
+
* WeakRef wrapper around a HTMLElement that also supports IE11
|
|
9
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakRef}
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
class WeakRefInstance {
|
|
14
|
+
constructor(instance) {
|
|
15
|
+
if (_canUseWeakRef && typeof instance === "object") {
|
|
16
|
+
this._weakRef = new WeakRef(instance);
|
|
17
|
+
} else {
|
|
18
|
+
this._instance = instance;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakRef/deref}
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
deref() {
|
|
27
|
+
var _a, _b, _c;
|
|
28
|
+
|
|
29
|
+
let instance;
|
|
30
|
+
|
|
31
|
+
if (this._weakRef) {
|
|
32
|
+
instance = (_a = this._weakRef) === null || _a === void 0 ? void 0 : _a.deref();
|
|
33
|
+
|
|
34
|
+
if (!instance) {
|
|
35
|
+
delete this._weakRef;
|
|
36
|
+
}
|
|
37
|
+
} else {
|
|
38
|
+
instance = this._instance;
|
|
39
|
+
|
|
40
|
+
if ((_c = (_b = instance) === null || _b === void 0 ? void 0 : _b.isDisposed) === null || _c === void 0 ? void 0 : _c.call(_b)) {
|
|
41
|
+
delete this._instance;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return instance;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/*!
|
|
51
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
52
|
+
* Licensed under the MIT License.
|
|
53
|
+
*/
|
|
54
|
+
const KEYBORG_FOCUSIN = "keyborg:focusin";
|
|
55
|
+
|
|
56
|
+
function canOverrideNativeFocus(win) {
|
|
57
|
+
const HTMLElement = win.HTMLElement;
|
|
58
|
+
const origFocus = HTMLElement.prototype.focus;
|
|
59
|
+
let isCustomFocusCalled = false;
|
|
60
|
+
|
|
61
|
+
HTMLElement.prototype.focus = function focus() {
|
|
62
|
+
isCustomFocusCalled = true;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const btn = win.document.createElement("button");
|
|
66
|
+
btn.focus();
|
|
67
|
+
HTMLElement.prototype.focus = origFocus;
|
|
68
|
+
return isCustomFocusCalled;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
let _canOverrideNativeFocus = false;
|
|
72
|
+
/**
|
|
73
|
+
* Guarantees that the native `focus` will be used
|
|
74
|
+
*/
|
|
75
|
+
|
|
76
|
+
function nativeFocus(element) {
|
|
77
|
+
const focus = element.focus;
|
|
78
|
+
|
|
79
|
+
if (focus.__keyborgNativeFocus) {
|
|
80
|
+
focus.__keyborgNativeFocus.call(element);
|
|
81
|
+
} else {
|
|
82
|
+
element.focus();
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Overrides the native `focus` and setups the keyborg focus event
|
|
87
|
+
*/
|
|
88
|
+
|
|
89
|
+
function setupFocusEvent(win) {
|
|
90
|
+
const kwin = win;
|
|
91
|
+
|
|
92
|
+
if (!_canOverrideNativeFocus) {
|
|
93
|
+
_canOverrideNativeFocus = canOverrideNativeFocus(kwin);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const origFocus = kwin.HTMLElement.prototype.focus;
|
|
97
|
+
|
|
98
|
+
if (origFocus.__keyborgNativeFocus) {
|
|
99
|
+
// Already set up.
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
kwin.HTMLElement.prototype.focus = focus;
|
|
104
|
+
const data = kwin.__keyborgData = {
|
|
105
|
+
focusInHandler: e => {
|
|
106
|
+
var _a;
|
|
107
|
+
|
|
108
|
+
const target = e.target;
|
|
109
|
+
|
|
110
|
+
if (!target) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const event = document.createEvent("HTMLEvents");
|
|
115
|
+
event.initEvent(KEYBORG_FOCUSIN, true, true);
|
|
116
|
+
const details = {
|
|
117
|
+
relatedTarget: e.relatedTarget || undefined
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
if (_canOverrideNativeFocus || data.lastFocusedProgrammatically) {
|
|
121
|
+
details.isFocusedProgrammatically = target === ((_a = data.lastFocusedProgrammatically) === null || _a === void 0 ? void 0 : _a.deref());
|
|
122
|
+
data.lastFocusedProgrammatically = undefined;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
event.details = details;
|
|
126
|
+
target.dispatchEvent(event);
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
kwin.document.addEventListener("focusin", kwin.__keyborgData.focusInHandler, true);
|
|
130
|
+
|
|
131
|
+
function focus() {
|
|
132
|
+
const keyborgNativeFocusEvent = kwin.__keyborgData;
|
|
133
|
+
|
|
134
|
+
if (keyborgNativeFocusEvent) {
|
|
135
|
+
keyborgNativeFocusEvent.lastFocusedProgrammatically = new WeakRefInstance(this);
|
|
136
|
+
} // eslint-disable-next-line prefer-rest-params
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
return origFocus.apply(this, arguments);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
focus.__keyborgNativeFocus = origFocus;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Removes keyborg event listeners and custom focus override
|
|
146
|
+
* @param win The window that stores keyborg focus events
|
|
147
|
+
*/
|
|
148
|
+
|
|
149
|
+
function disposeFocusEvent(win) {
|
|
150
|
+
const kwin = win;
|
|
151
|
+
const proto = kwin.HTMLElement.prototype;
|
|
152
|
+
const origFocus = proto.focus.__keyborgNativeFocus;
|
|
153
|
+
const keyborgNativeFocusEvent = kwin.__keyborgData;
|
|
154
|
+
|
|
155
|
+
if (keyborgNativeFocusEvent) {
|
|
156
|
+
kwin.document.removeEventListener("focusin", keyborgNativeFocusEvent.focusInHandler, true);
|
|
157
|
+
delete kwin.__keyborgData;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (origFocus) {
|
|
161
|
+
proto.focus = origFocus;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* @param win The window that stores keyborg focus events
|
|
166
|
+
* @returns The last element focused with element.focus()
|
|
167
|
+
*/
|
|
168
|
+
|
|
169
|
+
function getLastFocusedProgrammatically(win) {
|
|
170
|
+
var _a;
|
|
171
|
+
|
|
172
|
+
const keyborgNativeFocusEvent = win.__keyborgData;
|
|
173
|
+
return keyborgNativeFocusEvent ? ((_a = keyborgNativeFocusEvent.lastFocusedProgrammatically) === null || _a === void 0 ? void 0 : _a.deref()) || null : undefined;
|
|
174
|
+
}
|
|
3
175
|
|
|
4
176
|
/*!
|
|
5
177
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
@@ -309,5 +481,11 @@ function disposeKeyborg(instance) {
|
|
|
309
481
|
Keyborg.dispose(instance);
|
|
310
482
|
}
|
|
311
483
|
|
|
312
|
-
|
|
313
|
-
|
|
484
|
+
/*!
|
|
485
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
486
|
+
* Licensed under the MIT License.
|
|
487
|
+
*/
|
|
488
|
+
const version = "1.1.0";
|
|
489
|
+
|
|
490
|
+
export { KEYBORG_FOCUSIN, Keyborg, createKeyborg, disposeKeyborg, getLastFocusedProgrammatically, nativeFocus, version };
|
|
491
|
+
//# sourceMappingURL=keyborg.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keyborg.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/package.json
CHANGED
|
@@ -1,31 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "keyborg",
|
|
3
|
-
"version": "1.1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Keyboard Navigation Detection for Web",
|
|
5
5
|
"author": "Marat Abdullin <marata@microsoft.com>",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"sideEffects": false,
|
|
8
|
-
"main": "./
|
|
9
|
-
"module": "./
|
|
10
|
-
"typings": "./
|
|
8
|
+
"main": "./dist/index.js",
|
|
9
|
+
"module": "./dist/keyborg.esm.js",
|
|
10
|
+
"typings": "./dist/index.d.ts",
|
|
11
11
|
"files": [
|
|
12
|
-
"
|
|
13
|
-
"lib-commonjs"
|
|
12
|
+
"dist"
|
|
14
13
|
],
|
|
15
14
|
"repository": {
|
|
16
15
|
"type": "git",
|
|
17
16
|
"url": "git+https://github.com/microsoft/keyborg"
|
|
18
17
|
},
|
|
19
18
|
"scripts": {
|
|
19
|
+
"clean": "rimraf dist",
|
|
20
20
|
"build": "npm run clean && rollup -c",
|
|
21
|
-
"bundle-size": "bundle-size measure",
|
|
22
|
-
"lint": "eslint src/",
|
|
23
|
-
"lint:fix": "eslint src/ --fix",
|
|
21
|
+
"bundle-size": "npm run build && bundle-size measure",
|
|
24
22
|
"format": "prettier --check .",
|
|
25
23
|
"format:fix": "prettier --write .",
|
|
24
|
+
"lint": "eslint src/",
|
|
25
|
+
"lint:fix": "eslint src/ --fix",
|
|
26
26
|
"prepublishOnly": "npm run lint && npm run format && npm run build",
|
|
27
|
-
"release": "release-it"
|
|
28
|
-
"clean": "rimraf lib && rimraf lib-commonjs"
|
|
27
|
+
"release": "release-it --verbose"
|
|
29
28
|
},
|
|
30
29
|
"devDependencies": {
|
|
31
30
|
"@babel/core": "^7.16.0",
|
package/lib/FocusEvent.d.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
export declare const KEYBORG_FOCUSIN = "keyborg:focusin";
|
|
2
|
-
export interface KeyborgFocusInEventDetails {
|
|
3
|
-
relatedTarget?: HTMLElement;
|
|
4
|
-
isFocusedProgrammatically?: boolean;
|
|
5
|
-
}
|
|
6
|
-
export interface KeyborgFocusInEvent extends Event {
|
|
7
|
-
details: KeyborgFocusInEventDetails;
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* Guarantees that the native `focus` will be used
|
|
11
|
-
*/
|
|
12
|
-
export declare function nativeFocus(element: HTMLElement): void;
|
|
13
|
-
/**
|
|
14
|
-
* Overrides the native `focus` and setups the keyborg focus event
|
|
15
|
-
*/
|
|
16
|
-
export declare function setupFocusEvent(win: Window): void;
|
|
17
|
-
/**
|
|
18
|
-
* Removes keyborg event listeners and custom focus override
|
|
19
|
-
* @param win The window that stores keyborg focus events
|
|
20
|
-
*/
|
|
21
|
-
export declare function disposeFocusEvent(win: Window): void;
|
|
22
|
-
/**
|
|
23
|
-
* @param win The window that stores keyborg focus events
|
|
24
|
-
* @returns The last element focused with element.focus()
|
|
25
|
-
*/
|
|
26
|
-
export declare function getLastFocusedProgrammatically(win: Window): HTMLElement | null | undefined;
|
package/lib/FocusEvent.js
DELETED
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import { WeakRefInstance } from './WeakRefInstance.js';
|
|
2
|
-
|
|
3
|
-
/*!
|
|
4
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
5
|
-
* Licensed under the MIT License.
|
|
6
|
-
*/
|
|
7
|
-
const KEYBORG_FOCUSIN = "keyborg:focusin";
|
|
8
|
-
|
|
9
|
-
function canOverrideNativeFocus(win) {
|
|
10
|
-
const HTMLElement = win.HTMLElement;
|
|
11
|
-
const origFocus = HTMLElement.prototype.focus;
|
|
12
|
-
let isCustomFocusCalled = false;
|
|
13
|
-
|
|
14
|
-
HTMLElement.prototype.focus = function focus() {
|
|
15
|
-
isCustomFocusCalled = true;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
const btn = win.document.createElement("button");
|
|
19
|
-
btn.focus();
|
|
20
|
-
HTMLElement.prototype.focus = origFocus;
|
|
21
|
-
return isCustomFocusCalled;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
let _canOverrideNativeFocus = false;
|
|
25
|
-
/**
|
|
26
|
-
* Guarantees that the native `focus` will be used
|
|
27
|
-
*/
|
|
28
|
-
|
|
29
|
-
function nativeFocus(element) {
|
|
30
|
-
const focus = element.focus;
|
|
31
|
-
|
|
32
|
-
if (focus.__keyborgNativeFocus) {
|
|
33
|
-
focus.__keyborgNativeFocus.call(element);
|
|
34
|
-
} else {
|
|
35
|
-
element.focus();
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Overrides the native `focus` and setups the keyborg focus event
|
|
40
|
-
*/
|
|
41
|
-
|
|
42
|
-
function setupFocusEvent(win) {
|
|
43
|
-
const kwin = win;
|
|
44
|
-
|
|
45
|
-
if (!_canOverrideNativeFocus) {
|
|
46
|
-
_canOverrideNativeFocus = canOverrideNativeFocus(kwin);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const origFocus = kwin.HTMLElement.prototype.focus;
|
|
50
|
-
|
|
51
|
-
if (origFocus.__keyborgNativeFocus) {
|
|
52
|
-
// Already set up.
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
kwin.HTMLElement.prototype.focus = focus;
|
|
57
|
-
const data = kwin.__keyborgData = {
|
|
58
|
-
focusInHandler: e => {
|
|
59
|
-
var _a;
|
|
60
|
-
|
|
61
|
-
const target = e.target;
|
|
62
|
-
|
|
63
|
-
if (!target) {
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const event = document.createEvent("HTMLEvents");
|
|
68
|
-
event.initEvent(KEYBORG_FOCUSIN, true, true);
|
|
69
|
-
const details = {
|
|
70
|
-
relatedTarget: e.relatedTarget || undefined
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
if (_canOverrideNativeFocus || data.lastFocusedProgrammatically) {
|
|
74
|
-
details.isFocusedProgrammatically = target === ((_a = data.lastFocusedProgrammatically) === null || _a === void 0 ? void 0 : _a.deref());
|
|
75
|
-
data.lastFocusedProgrammatically = undefined;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
event.details = details;
|
|
79
|
-
target.dispatchEvent(event);
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
kwin.document.addEventListener("focusin", kwin.__keyborgData.focusInHandler, true);
|
|
83
|
-
|
|
84
|
-
function focus() {
|
|
85
|
-
const keyborgNativeFocusEvent = kwin.__keyborgData;
|
|
86
|
-
|
|
87
|
-
if (keyborgNativeFocusEvent) {
|
|
88
|
-
keyborgNativeFocusEvent.lastFocusedProgrammatically = new WeakRefInstance(this);
|
|
89
|
-
} // eslint-disable-next-line prefer-rest-params
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
return origFocus.apply(this, arguments);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
focus.__keyborgNativeFocus = origFocus;
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Removes keyborg event listeners and custom focus override
|
|
99
|
-
* @param win The window that stores keyborg focus events
|
|
100
|
-
*/
|
|
101
|
-
|
|
102
|
-
function disposeFocusEvent(win) {
|
|
103
|
-
const kwin = win;
|
|
104
|
-
const proto = kwin.HTMLElement.prototype;
|
|
105
|
-
const origFocus = proto.focus.__keyborgNativeFocus;
|
|
106
|
-
const keyborgNativeFocusEvent = kwin.__keyborgData;
|
|
107
|
-
|
|
108
|
-
if (keyborgNativeFocusEvent) {
|
|
109
|
-
kwin.document.removeEventListener("focusin", keyborgNativeFocusEvent.focusInHandler, true);
|
|
110
|
-
delete kwin.__keyborgData;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
if (origFocus) {
|
|
114
|
-
proto.focus = origFocus;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* @param win The window that stores keyborg focus events
|
|
119
|
-
* @returns The last element focused with element.focus()
|
|
120
|
-
*/
|
|
121
|
-
|
|
122
|
-
function getLastFocusedProgrammatically(win) {
|
|
123
|
-
var _a;
|
|
124
|
-
|
|
125
|
-
const keyborgNativeFocusEvent = win.__keyborgData;
|
|
126
|
-
return keyborgNativeFocusEvent ? ((_a = keyborgNativeFocusEvent.lastFocusedProgrammatically) === null || _a === void 0 ? void 0 : _a.deref()) || null : undefined;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
export { KEYBORG_FOCUSIN, disposeFocusEvent, getLastFocusedProgrammatically, nativeFocus, setupFocusEvent };
|
|
130
|
-
//# sourceMappingURL=FocusEvent.js.map
|
package/lib/FocusEvent.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"FocusEvent.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/lib/Keyborg.d.ts
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
import { Disposable } from "./WeakRefInstance";
|
|
6
|
-
interface WindowWithKeyborg extends Window {
|
|
7
|
-
__keyborg?: {
|
|
8
|
-
core: KeyborgCore;
|
|
9
|
-
refs: {
|
|
10
|
-
[id: string]: Keyborg;
|
|
11
|
-
};
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
export declare type KeyborgCallback = (isNavigatingWithKeyboard: boolean) => void;
|
|
15
|
-
/**
|
|
16
|
-
* Source of truth for all the keyborg core instances and the current keyboard navigation state
|
|
17
|
-
*/
|
|
18
|
-
export declare class KeyborgState {
|
|
19
|
-
private __keyborgCoreRefs;
|
|
20
|
-
private _isNavigatingWithKeyboard;
|
|
21
|
-
add(keyborg: KeyborgCore): void;
|
|
22
|
-
remove(id: string): void;
|
|
23
|
-
setVal(isNavigatingWithKeyboard: boolean): void;
|
|
24
|
-
getVal(): boolean;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Manages a collection of Keyborg instances in a window/document and updates keyborg state
|
|
28
|
-
*/
|
|
29
|
-
declare class KeyborgCore implements Disposable {
|
|
30
|
-
readonly id: string;
|
|
31
|
-
private _win?;
|
|
32
|
-
private _isMouseUsed;
|
|
33
|
-
private _dismissTimer;
|
|
34
|
-
constructor(win: WindowWithKeyborg);
|
|
35
|
-
dispose(): void;
|
|
36
|
-
isDisposed(): boolean;
|
|
37
|
-
/**
|
|
38
|
-
* Updates all keyborg instances with the keyboard navigation state
|
|
39
|
-
*/
|
|
40
|
-
update(isNavigatingWithKeyboard: boolean): void;
|
|
41
|
-
private _onFocusIn;
|
|
42
|
-
private _onMouseDown;
|
|
43
|
-
private _onKeyDown;
|
|
44
|
-
private _scheduleDismiss;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Used to determine the keyboard navigation state
|
|
48
|
-
*/
|
|
49
|
-
export declare class Keyborg {
|
|
50
|
-
private _id;
|
|
51
|
-
private _win?;
|
|
52
|
-
private _core?;
|
|
53
|
-
private _cb;
|
|
54
|
-
static create(win: WindowWithKeyborg): Keyborg;
|
|
55
|
-
static dispose(instance: Keyborg): void;
|
|
56
|
-
/**
|
|
57
|
-
* Updates all subscribed callbacks with the keyboard navigation state
|
|
58
|
-
*/
|
|
59
|
-
static update(instance: Keyborg, isNavigatingWithKeyboard: boolean): void;
|
|
60
|
-
private constructor();
|
|
61
|
-
private dispose;
|
|
62
|
-
/**
|
|
63
|
-
* @returns Whether the user is navigating with keyboard
|
|
64
|
-
*/
|
|
65
|
-
isNavigatingWithKeyboard(): boolean;
|
|
66
|
-
/**
|
|
67
|
-
* @param callback - Called when the keyboard navigation state changes
|
|
68
|
-
*/
|
|
69
|
-
subscribe(callback: KeyborgCallback): void;
|
|
70
|
-
/**
|
|
71
|
-
* @param callback - Registered with subscribe
|
|
72
|
-
*/
|
|
73
|
-
unsubscribe(callback: KeyborgCallback): void;
|
|
74
|
-
/**
|
|
75
|
-
* Manually set the keyboard navigtion state
|
|
76
|
-
*/
|
|
77
|
-
setVal(isNavigatingWithKeyboard: boolean): void;
|
|
78
|
-
}
|
|
79
|
-
export declare function createKeyborg(win: Window): Keyborg;
|
|
80
|
-
export declare function disposeKeyborg(instance: Keyborg): void;
|
|
81
|
-
export {};
|
package/lib/Keyborg.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Keyborg.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/lib/WeakRefInstance.d.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
export declare const _canUseWeakRef: boolean;
|
|
6
|
-
/**
|
|
7
|
-
* Allows disposable instances to be used
|
|
8
|
-
*/
|
|
9
|
-
export interface Disposable {
|
|
10
|
-
isDisposed?(): boolean;
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* WeakRef wrapper around a HTMLElement that also supports IE11
|
|
14
|
-
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakRef}
|
|
15
|
-
* @internal
|
|
16
|
-
*/
|
|
17
|
-
export declare class WeakRefInstance<T extends Disposable | object> {
|
|
18
|
-
private _weakRef?;
|
|
19
|
-
private _instance?;
|
|
20
|
-
constructor(instance: T);
|
|
21
|
-
/**
|
|
22
|
-
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakRef/deref}
|
|
23
|
-
*/
|
|
24
|
-
deref(): T | undefined;
|
|
25
|
-
}
|
package/lib/WeakRefInstance.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
// IE11 compat, checks if WeakRef is supported
|
|
6
|
-
const _canUseWeakRef = typeof WeakRef !== "undefined";
|
|
7
|
-
/**
|
|
8
|
-
* WeakRef wrapper around a HTMLElement that also supports IE11
|
|
9
|
-
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakRef}
|
|
10
|
-
* @internal
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
class WeakRefInstance {
|
|
14
|
-
constructor(instance) {
|
|
15
|
-
if (_canUseWeakRef && typeof instance === "object") {
|
|
16
|
-
this._weakRef = new WeakRef(instance);
|
|
17
|
-
} else {
|
|
18
|
-
this._instance = instance;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakRef/deref}
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
deref() {
|
|
27
|
-
var _a, _b, _c;
|
|
28
|
-
|
|
29
|
-
let instance;
|
|
30
|
-
|
|
31
|
-
if (this._weakRef) {
|
|
32
|
-
instance = (_a = this._weakRef) === null || _a === void 0 ? void 0 : _a.deref();
|
|
33
|
-
|
|
34
|
-
if (!instance) {
|
|
35
|
-
delete this._weakRef;
|
|
36
|
-
}
|
|
37
|
-
} else {
|
|
38
|
-
instance = this._instance;
|
|
39
|
-
|
|
40
|
-
if ((_c = (_b = instance) === null || _b === void 0 ? void 0 : _b.isDisposed) === null || _c === void 0 ? void 0 : _c.call(_b)) {
|
|
41
|
-
delete this._instance;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return instance;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export { WeakRefInstance, _canUseWeakRef };
|
|
51
|
-
//# sourceMappingURL=WeakRefInstance.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"WeakRefInstance.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/lib/index.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
export { Keyborg, createKeyborg, disposeKeyborg } from "./Keyborg";
|
|
6
|
-
export { getLastFocusedProgrammatically, nativeFocus, KEYBORG_FOCUSIN, KeyborgFocusInEvent, KeyborgFocusInEventDetails, } from "./FocusEvent";
|
|
7
|
-
export declare const version: string;
|
package/lib/index.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export { Keyborg, createKeyborg, disposeKeyborg } from './Keyborg.js';
|
|
2
|
-
export { KEYBORG_FOCUSIN, getLastFocusedProgrammatically, nativeFocus } from './FocusEvent.js';
|
|
3
|
-
|
|
4
|
-
/*!
|
|
5
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
6
|
-
* Licensed under the MIT License.
|
|
7
|
-
*/
|
|
8
|
-
const version = "1.1.0-alpha.1";
|
|
9
|
-
|
|
10
|
-
export { version };
|
|
11
|
-
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;"}
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var WeakRefInstance = require('./WeakRefInstance.js');
|
|
6
|
-
|
|
7
|
-
/*!
|
|
8
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
9
|
-
* Licensed under the MIT License.
|
|
10
|
-
*/
|
|
11
|
-
const KEYBORG_FOCUSIN = "keyborg:focusin";
|
|
12
|
-
|
|
13
|
-
function canOverrideNativeFocus(win) {
|
|
14
|
-
const HTMLElement = win.HTMLElement;
|
|
15
|
-
const origFocus = HTMLElement.prototype.focus;
|
|
16
|
-
let isCustomFocusCalled = false;
|
|
17
|
-
|
|
18
|
-
HTMLElement.prototype.focus = function focus() {
|
|
19
|
-
isCustomFocusCalled = true;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
const btn = win.document.createElement("button");
|
|
23
|
-
btn.focus();
|
|
24
|
-
HTMLElement.prototype.focus = origFocus;
|
|
25
|
-
return isCustomFocusCalled;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
let _canOverrideNativeFocus = false;
|
|
29
|
-
/**
|
|
30
|
-
* Guarantees that the native `focus` will be used
|
|
31
|
-
*/
|
|
32
|
-
|
|
33
|
-
function nativeFocus(element) {
|
|
34
|
-
const focus = element.focus;
|
|
35
|
-
|
|
36
|
-
if (focus.__keyborgNativeFocus) {
|
|
37
|
-
focus.__keyborgNativeFocus.call(element);
|
|
38
|
-
} else {
|
|
39
|
-
element.focus();
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Overrides the native `focus` and setups the keyborg focus event
|
|
44
|
-
*/
|
|
45
|
-
|
|
46
|
-
function setupFocusEvent(win) {
|
|
47
|
-
const kwin = win;
|
|
48
|
-
|
|
49
|
-
if (!_canOverrideNativeFocus) {
|
|
50
|
-
_canOverrideNativeFocus = canOverrideNativeFocus(kwin);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const origFocus = kwin.HTMLElement.prototype.focus;
|
|
54
|
-
|
|
55
|
-
if (origFocus.__keyborgNativeFocus) {
|
|
56
|
-
// Already set up.
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
kwin.HTMLElement.prototype.focus = focus;
|
|
61
|
-
const data = kwin.__keyborgData = {
|
|
62
|
-
focusInHandler: e => {
|
|
63
|
-
var _a;
|
|
64
|
-
|
|
65
|
-
const target = e.target;
|
|
66
|
-
|
|
67
|
-
if (!target) {
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const event = document.createEvent("HTMLEvents");
|
|
72
|
-
event.initEvent(KEYBORG_FOCUSIN, true, true);
|
|
73
|
-
const details = {
|
|
74
|
-
relatedTarget: e.relatedTarget || undefined
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
if (_canOverrideNativeFocus || data.lastFocusedProgrammatically) {
|
|
78
|
-
details.isFocusedProgrammatically = target === ((_a = data.lastFocusedProgrammatically) === null || _a === void 0 ? void 0 : _a.deref());
|
|
79
|
-
data.lastFocusedProgrammatically = undefined;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
event.details = details;
|
|
83
|
-
target.dispatchEvent(event);
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
kwin.document.addEventListener("focusin", kwin.__keyborgData.focusInHandler, true);
|
|
87
|
-
|
|
88
|
-
function focus() {
|
|
89
|
-
const keyborgNativeFocusEvent = kwin.__keyborgData;
|
|
90
|
-
|
|
91
|
-
if (keyborgNativeFocusEvent) {
|
|
92
|
-
keyborgNativeFocusEvent.lastFocusedProgrammatically = new WeakRefInstance.WeakRefInstance(this);
|
|
93
|
-
} // eslint-disable-next-line prefer-rest-params
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
return origFocus.apply(this, arguments);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
focus.__keyborgNativeFocus = origFocus;
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Removes keyborg event listeners and custom focus override
|
|
103
|
-
* @param win The window that stores keyborg focus events
|
|
104
|
-
*/
|
|
105
|
-
|
|
106
|
-
function disposeFocusEvent(win) {
|
|
107
|
-
const kwin = win;
|
|
108
|
-
const proto = kwin.HTMLElement.prototype;
|
|
109
|
-
const origFocus = proto.focus.__keyborgNativeFocus;
|
|
110
|
-
const keyborgNativeFocusEvent = kwin.__keyborgData;
|
|
111
|
-
|
|
112
|
-
if (keyborgNativeFocusEvent) {
|
|
113
|
-
kwin.document.removeEventListener("focusin", keyborgNativeFocusEvent.focusInHandler, true);
|
|
114
|
-
delete kwin.__keyborgData;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
if (origFocus) {
|
|
118
|
-
proto.focus = origFocus;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* @param win The window that stores keyborg focus events
|
|
123
|
-
* @returns The last element focused with element.focus()
|
|
124
|
-
*/
|
|
125
|
-
|
|
126
|
-
function getLastFocusedProgrammatically(win) {
|
|
127
|
-
var _a;
|
|
128
|
-
|
|
129
|
-
const keyborgNativeFocusEvent = win.__keyborgData;
|
|
130
|
-
return keyborgNativeFocusEvent ? ((_a = keyborgNativeFocusEvent.lastFocusedProgrammatically) === null || _a === void 0 ? void 0 : _a.deref()) || null : undefined;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
exports.KEYBORG_FOCUSIN = KEYBORG_FOCUSIN;
|
|
134
|
-
exports.disposeFocusEvent = disposeFocusEvent;
|
|
135
|
-
exports.getLastFocusedProgrammatically = getLastFocusedProgrammatically;
|
|
136
|
-
exports.nativeFocus = nativeFocus;
|
|
137
|
-
exports.setupFocusEvent = setupFocusEvent;
|
|
138
|
-
//# sourceMappingURL=FocusEvent.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"FocusEvent.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Keyborg.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
/*!
|
|
6
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
7
|
-
* Licensed under the MIT License.
|
|
8
|
-
*/
|
|
9
|
-
// IE11 compat, checks if WeakRef is supported
|
|
10
|
-
const _canUseWeakRef = typeof WeakRef !== "undefined";
|
|
11
|
-
/**
|
|
12
|
-
* WeakRef wrapper around a HTMLElement that also supports IE11
|
|
13
|
-
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakRef}
|
|
14
|
-
* @internal
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
class WeakRefInstance {
|
|
18
|
-
constructor(instance) {
|
|
19
|
-
if (_canUseWeakRef && typeof instance === "object") {
|
|
20
|
-
this._weakRef = new WeakRef(instance);
|
|
21
|
-
} else {
|
|
22
|
-
this._instance = instance;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakRef/deref}
|
|
27
|
-
*/
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
deref() {
|
|
31
|
-
var _a, _b, _c;
|
|
32
|
-
|
|
33
|
-
let instance;
|
|
34
|
-
|
|
35
|
-
if (this._weakRef) {
|
|
36
|
-
instance = (_a = this._weakRef) === null || _a === void 0 ? void 0 : _a.deref();
|
|
37
|
-
|
|
38
|
-
if (!instance) {
|
|
39
|
-
delete this._weakRef;
|
|
40
|
-
}
|
|
41
|
-
} else {
|
|
42
|
-
instance = this._instance;
|
|
43
|
-
|
|
44
|
-
if ((_c = (_b = instance) === null || _b === void 0 ? void 0 : _b.isDisposed) === null || _c === void 0 ? void 0 : _c.call(_b)) {
|
|
45
|
-
delete this._instance;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return instance;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
exports.WeakRefInstance = WeakRefInstance;
|
|
55
|
-
exports._canUseWeakRef = _canUseWeakRef;
|
|
56
|
-
//# sourceMappingURL=WeakRefInstance.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"WeakRefInstance.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/lib-commonjs/index.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var Keyborg = require('./Keyborg.js');
|
|
6
|
-
var FocusEvent = require('./FocusEvent.js');
|
|
7
|
-
|
|
8
|
-
/*!
|
|
9
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
10
|
-
* Licensed under the MIT License.
|
|
11
|
-
*/
|
|
12
|
-
const version = "1.1.0-alpha.1";
|
|
13
|
-
|
|
14
|
-
exports.Keyborg = Keyborg.Keyborg;
|
|
15
|
-
exports.createKeyborg = Keyborg.createKeyborg;
|
|
16
|
-
exports.disposeKeyborg = Keyborg.disposeKeyborg;
|
|
17
|
-
exports.KEYBORG_FOCUSIN = FocusEvent.KEYBORG_FOCUSIN;
|
|
18
|
-
exports.getLastFocusedProgrammatically = FocusEvent.getLastFocusedProgrammatically;
|
|
19
|
-
exports.nativeFocus = FocusEvent.nativeFocus;
|
|
20
|
-
exports.version = version;
|
|
21
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;"}
|