@primer/behaviors 0.0.0-202342222036 → 0.0.0-2023818155639
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.
|
@@ -26,8 +26,6 @@ function getAnchoredPosition(floatingElement, anchorElement, settings = {}) {
|
|
|
26
26
|
}
|
|
27
27
|
exports.getAnchoredPosition = getAnchoredPosition;
|
|
28
28
|
function getPositionedParent(element) {
|
|
29
|
-
if (isOnTopLayer(element))
|
|
30
|
-
return document.body;
|
|
31
29
|
let parentNode = element.parentNode;
|
|
32
30
|
while (parentNode !== null) {
|
|
33
31
|
if (parentNode instanceof HTMLElement && getComputedStyle(parentNode).position !== 'static') {
|
|
@@ -37,21 +35,6 @@ function getPositionedParent(element) {
|
|
|
37
35
|
}
|
|
38
36
|
return document.body;
|
|
39
37
|
}
|
|
40
|
-
function isOnTopLayer(element) {
|
|
41
|
-
var _a;
|
|
42
|
-
if (element.tagName === 'DIALOG') {
|
|
43
|
-
return true;
|
|
44
|
-
}
|
|
45
|
-
try {
|
|
46
|
-
if (element.matches(':popover-open') && /native code/.test((_a = document.body.showPopover) === null || _a === void 0 ? void 0 : _a.toString())) {
|
|
47
|
-
return true;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
catch (_b) {
|
|
51
|
-
return false;
|
|
52
|
-
}
|
|
53
|
-
return false;
|
|
54
|
-
}
|
|
55
38
|
function getClippingRect(element) {
|
|
56
39
|
let parentNode = element;
|
|
57
40
|
while (parentNode !== null) {
|
package/dist/cjs/focus-zone.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export declare type Direction = 'previous' | 'next' | 'start' | 'end';
|
|
2
|
-
export declare type FocusMovementKeys = 'ArrowLeft' | 'ArrowDown' | 'ArrowUp' | 'ArrowRight' | 'h' | 'j' | 'k' | 'l' | 'a' | 's' | 'w' | 'd' | 'Tab' | 'Home' | 'End' | 'PageUp' | 'PageDown'
|
|
2
|
+
export declare type FocusMovementKeys = 'ArrowLeft' | 'ArrowDown' | 'ArrowUp' | 'ArrowRight' | 'h' | 'j' | 'k' | 'l' | 'a' | 's' | 'w' | 'd' | 'Tab' | 'Home' | 'End' | 'PageUp' | 'PageDown';
|
|
3
3
|
export declare enum FocusKeys {
|
|
4
4
|
ArrowHorizontal = 1,
|
|
5
5
|
ArrowVertical = 2,
|
|
@@ -10,7 +10,6 @@ export declare enum FocusKeys {
|
|
|
10
10
|
WS = 32,
|
|
11
11
|
AD = 64,
|
|
12
12
|
Tab = 128,
|
|
13
|
-
Backspace = 512,
|
|
14
13
|
ArrowAll = 3,
|
|
15
14
|
HJKL = 12,
|
|
16
15
|
WASD = 96,
|
package/dist/cjs/focus-zone.js
CHANGED
|
@@ -17,7 +17,6 @@ var FocusKeys;
|
|
|
17
17
|
FocusKeys[FocusKeys["WS"] = 32] = "WS";
|
|
18
18
|
FocusKeys[FocusKeys["AD"] = 64] = "AD";
|
|
19
19
|
FocusKeys[FocusKeys["Tab"] = 128] = "Tab";
|
|
20
|
-
FocusKeys[FocusKeys["Backspace"] = 512] = "Backspace";
|
|
21
20
|
FocusKeys[FocusKeys["ArrowAll"] = 3] = "ArrowAll";
|
|
22
21
|
FocusKeys[FocusKeys["HJKL"] = 12] = "HJKL";
|
|
23
22
|
FocusKeys[FocusKeys["WASD"] = 96] = "WASD";
|
|
@@ -40,8 +39,7 @@ const KEY_TO_BIT = {
|
|
|
40
39
|
Home: FocusKeys.HomeAndEnd,
|
|
41
40
|
End: FocusKeys.HomeAndEnd,
|
|
42
41
|
PageUp: FocusKeys.PageUpDown,
|
|
43
|
-
PageDown: FocusKeys.PageUpDown
|
|
44
|
-
Backspace: FocusKeys.Backspace
|
|
42
|
+
PageDown: FocusKeys.PageUpDown
|
|
45
43
|
};
|
|
46
44
|
const KEY_TO_DIRECTION = {
|
|
47
45
|
ArrowLeft: 'previous',
|
|
@@ -60,8 +58,7 @@ const KEY_TO_DIRECTION = {
|
|
|
60
58
|
Home: 'start',
|
|
61
59
|
End: 'end',
|
|
62
60
|
PageUp: 'start',
|
|
63
|
-
PageDown: 'end'
|
|
64
|
-
Backspace: 'previous'
|
|
61
|
+
PageDown: 'end'
|
|
65
62
|
};
|
|
66
63
|
function getDirection(keyboardEvent) {
|
|
67
64
|
const direction = KEY_TO_DIRECTION[keyboardEvent.key];
|
|
@@ -190,7 +187,8 @@ function focusZone(container, settings) {
|
|
|
190
187
|
if (filteredElements.length === 0) {
|
|
191
188
|
return;
|
|
192
189
|
}
|
|
193
|
-
focusableElements.
|
|
190
|
+
const insertIndex = focusableElements.findIndex(e => (e.compareDocumentPosition(filteredElements[0]) & Node.DOCUMENT_POSITION_PRECEDING) > 0);
|
|
191
|
+
focusableElements.splice(insertIndex === -1 ? focusableElements.length : insertIndex, 0, ...filteredElements);
|
|
194
192
|
for (const element of filteredElements) {
|
|
195
193
|
if (!savedTabIndex.has(element)) {
|
|
196
194
|
savedTabIndex.set(element, element.getAttribute('tabindex'));
|
|
@@ -201,27 +199,6 @@ function focusZone(container, settings) {
|
|
|
201
199
|
updateFocusedElement(getFirstFocusableElement());
|
|
202
200
|
}
|
|
203
201
|
}
|
|
204
|
-
function findInsertionIndex(elementsToInsert) {
|
|
205
|
-
const firstElementToInsert = elementsToInsert[0];
|
|
206
|
-
if (focusableElements.length === 0)
|
|
207
|
-
return 0;
|
|
208
|
-
let iMin = 0;
|
|
209
|
-
let iMax = focusableElements.length - 1;
|
|
210
|
-
while (iMin <= iMax) {
|
|
211
|
-
const i = Math.floor((iMin + iMax) / 2);
|
|
212
|
-
const element = focusableElements[i];
|
|
213
|
-
if (followsInDocument(firstElementToInsert, element)) {
|
|
214
|
-
iMax = i - 1;
|
|
215
|
-
}
|
|
216
|
-
else {
|
|
217
|
-
iMin = i + 1;
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
return iMin;
|
|
221
|
-
}
|
|
222
|
-
function followsInDocument(first, second) {
|
|
223
|
-
return (second.compareDocumentPosition(first) & Node.DOCUMENT_POSITION_PRECEDING) > 0;
|
|
224
|
-
}
|
|
225
202
|
function endFocusManagement(...elements) {
|
|
226
203
|
for (const element of elements) {
|
|
227
204
|
const focusableElementIndex = focusableElements.indexOf(element);
|
|
@@ -245,8 +222,7 @@ function focusZone(container, settings) {
|
|
|
245
222
|
}
|
|
246
223
|
}
|
|
247
224
|
beginFocusManagement(...(0, iterate_focusable_elements_js_1.iterateFocusableElements)(container));
|
|
248
|
-
|
|
249
|
-
updateFocusedElement(initialElement);
|
|
225
|
+
updateFocusedElement(getFirstFocusableElement());
|
|
250
226
|
const observer = new MutationObserver(mutations => {
|
|
251
227
|
for (const mutation of mutations) {
|
|
252
228
|
for (const removedNode of mutation.removedNodes) {
|
|
@@ -22,8 +22,6 @@ export function getAnchoredPosition(floatingElement, anchorElement, settings = {
|
|
|
22
22
|
return pureCalculateAnchoredPosition(clippingRect, relativeRect, floatingElement.getBoundingClientRect(), anchorElement instanceof Element ? anchorElement.getBoundingClientRect() : anchorElement, getDefaultSettings(settings));
|
|
23
23
|
}
|
|
24
24
|
function getPositionedParent(element) {
|
|
25
|
-
if (isOnTopLayer(element))
|
|
26
|
-
return document.body;
|
|
27
25
|
let parentNode = element.parentNode;
|
|
28
26
|
while (parentNode !== null) {
|
|
29
27
|
if (parentNode instanceof HTMLElement && getComputedStyle(parentNode).position !== 'static') {
|
|
@@ -33,21 +31,6 @@ function getPositionedParent(element) {
|
|
|
33
31
|
}
|
|
34
32
|
return document.body;
|
|
35
33
|
}
|
|
36
|
-
function isOnTopLayer(element) {
|
|
37
|
-
var _a;
|
|
38
|
-
if (element.tagName === 'DIALOG') {
|
|
39
|
-
return true;
|
|
40
|
-
}
|
|
41
|
-
try {
|
|
42
|
-
if (element.matches(':popover-open') && /native code/.test((_a = document.body.showPopover) === null || _a === void 0 ? void 0 : _a.toString())) {
|
|
43
|
-
return true;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
catch (_b) {
|
|
47
|
-
return false;
|
|
48
|
-
}
|
|
49
|
-
return false;
|
|
50
|
-
}
|
|
51
34
|
function getClippingRect(element) {
|
|
52
35
|
let parentNode = element;
|
|
53
36
|
while (parentNode !== null) {
|
package/dist/esm/focus-zone.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export declare type Direction = 'previous' | 'next' | 'start' | 'end';
|
|
2
|
-
export declare type FocusMovementKeys = 'ArrowLeft' | 'ArrowDown' | 'ArrowUp' | 'ArrowRight' | 'h' | 'j' | 'k' | 'l' | 'a' | 's' | 'w' | 'd' | 'Tab' | 'Home' | 'End' | 'PageUp' | 'PageDown'
|
|
2
|
+
export declare type FocusMovementKeys = 'ArrowLeft' | 'ArrowDown' | 'ArrowUp' | 'ArrowRight' | 'h' | 'j' | 'k' | 'l' | 'a' | 's' | 'w' | 'd' | 'Tab' | 'Home' | 'End' | 'PageUp' | 'PageDown';
|
|
3
3
|
export declare enum FocusKeys {
|
|
4
4
|
ArrowHorizontal = 1,
|
|
5
5
|
ArrowVertical = 2,
|
|
@@ -10,7 +10,6 @@ export declare enum FocusKeys {
|
|
|
10
10
|
WS = 32,
|
|
11
11
|
AD = 64,
|
|
12
12
|
Tab = 128,
|
|
13
|
-
Backspace = 512,
|
|
14
13
|
ArrowAll = 3,
|
|
15
14
|
HJKL = 12,
|
|
16
15
|
WASD = 96,
|
package/dist/esm/focus-zone.js
CHANGED
|
@@ -14,7 +14,6 @@ export var FocusKeys;
|
|
|
14
14
|
FocusKeys[FocusKeys["WS"] = 32] = "WS";
|
|
15
15
|
FocusKeys[FocusKeys["AD"] = 64] = "AD";
|
|
16
16
|
FocusKeys[FocusKeys["Tab"] = 128] = "Tab";
|
|
17
|
-
FocusKeys[FocusKeys["Backspace"] = 512] = "Backspace";
|
|
18
17
|
FocusKeys[FocusKeys["ArrowAll"] = 3] = "ArrowAll";
|
|
19
18
|
FocusKeys[FocusKeys["HJKL"] = 12] = "HJKL";
|
|
20
19
|
FocusKeys[FocusKeys["WASD"] = 96] = "WASD";
|
|
@@ -37,8 +36,7 @@ const KEY_TO_BIT = {
|
|
|
37
36
|
Home: FocusKeys.HomeAndEnd,
|
|
38
37
|
End: FocusKeys.HomeAndEnd,
|
|
39
38
|
PageUp: FocusKeys.PageUpDown,
|
|
40
|
-
PageDown: FocusKeys.PageUpDown
|
|
41
|
-
Backspace: FocusKeys.Backspace
|
|
39
|
+
PageDown: FocusKeys.PageUpDown
|
|
42
40
|
};
|
|
43
41
|
const KEY_TO_DIRECTION = {
|
|
44
42
|
ArrowLeft: 'previous',
|
|
@@ -57,8 +55,7 @@ const KEY_TO_DIRECTION = {
|
|
|
57
55
|
Home: 'start',
|
|
58
56
|
End: 'end',
|
|
59
57
|
PageUp: 'start',
|
|
60
|
-
PageDown: 'end'
|
|
61
|
-
Backspace: 'previous'
|
|
58
|
+
PageDown: 'end'
|
|
62
59
|
};
|
|
63
60
|
function getDirection(keyboardEvent) {
|
|
64
61
|
const direction = KEY_TO_DIRECTION[keyboardEvent.key];
|
|
@@ -187,7 +184,8 @@ export function focusZone(container, settings) {
|
|
|
187
184
|
if (filteredElements.length === 0) {
|
|
188
185
|
return;
|
|
189
186
|
}
|
|
190
|
-
focusableElements.
|
|
187
|
+
const insertIndex = focusableElements.findIndex(e => (e.compareDocumentPosition(filteredElements[0]) & Node.DOCUMENT_POSITION_PRECEDING) > 0);
|
|
188
|
+
focusableElements.splice(insertIndex === -1 ? focusableElements.length : insertIndex, 0, ...filteredElements);
|
|
191
189
|
for (const element of filteredElements) {
|
|
192
190
|
if (!savedTabIndex.has(element)) {
|
|
193
191
|
savedTabIndex.set(element, element.getAttribute('tabindex'));
|
|
@@ -198,27 +196,6 @@ export function focusZone(container, settings) {
|
|
|
198
196
|
updateFocusedElement(getFirstFocusableElement());
|
|
199
197
|
}
|
|
200
198
|
}
|
|
201
|
-
function findInsertionIndex(elementsToInsert) {
|
|
202
|
-
const firstElementToInsert = elementsToInsert[0];
|
|
203
|
-
if (focusableElements.length === 0)
|
|
204
|
-
return 0;
|
|
205
|
-
let iMin = 0;
|
|
206
|
-
let iMax = focusableElements.length - 1;
|
|
207
|
-
while (iMin <= iMax) {
|
|
208
|
-
const i = Math.floor((iMin + iMax) / 2);
|
|
209
|
-
const element = focusableElements[i];
|
|
210
|
-
if (followsInDocument(firstElementToInsert, element)) {
|
|
211
|
-
iMax = i - 1;
|
|
212
|
-
}
|
|
213
|
-
else {
|
|
214
|
-
iMin = i + 1;
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
return iMin;
|
|
218
|
-
}
|
|
219
|
-
function followsInDocument(first, second) {
|
|
220
|
-
return (second.compareDocumentPosition(first) & Node.DOCUMENT_POSITION_PRECEDING) > 0;
|
|
221
|
-
}
|
|
222
199
|
function endFocusManagement(...elements) {
|
|
223
200
|
for (const element of elements) {
|
|
224
201
|
const focusableElementIndex = focusableElements.indexOf(element);
|
|
@@ -242,8 +219,7 @@ export function focusZone(container, settings) {
|
|
|
242
219
|
}
|
|
243
220
|
}
|
|
244
221
|
beginFocusManagement(...iterateFocusableElements(container));
|
|
245
|
-
|
|
246
|
-
updateFocusedElement(initialElement);
|
|
222
|
+
updateFocusedElement(getFirstFocusableElement());
|
|
247
223
|
const observer = new MutationObserver(mutations => {
|
|
248
224
|
for (const mutation of mutations) {
|
|
249
225
|
for (const removedNode of mutation.removedNodes) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@primer/behaviors",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-2023818155639",
|
|
4
4
|
"description": "Shared behaviors for JavaScript components",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
"@testing-library/user-event": "^13.5.0",
|
|
75
75
|
"@types/jest": "^27.0.3",
|
|
76
76
|
"@types/react": "^17.0.37",
|
|
77
|
-
"esbuild": "^0.
|
|
77
|
+
"esbuild": "^0.14.1",
|
|
78
78
|
"esbuild-jest": "^0.5.0",
|
|
79
79
|
"eslint": "^8.3.0",
|
|
80
80
|
"eslint-plugin-github": "^4.3.5",
|