@primer/behaviors 1.10.0 → 1.10.1-rc.f78ec00
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/cjs/focus-zone.js
CHANGED
|
@@ -206,7 +206,7 @@ function focusZone(container, settings) {
|
|
|
206
206
|
return;
|
|
207
207
|
}
|
|
208
208
|
const insertionIndex = findInsertionIndex(filteredElements);
|
|
209
|
-
focusableElements.insertAt(insertionIndex,
|
|
209
|
+
focusableElements.insertAt(insertionIndex, filteredElements);
|
|
210
210
|
for (const element of filteredElements) {
|
|
211
211
|
if (!savedTabIndex.has(element)) {
|
|
212
212
|
savedTabIndex.set(element, element.getAttribute('tabindex'));
|
|
@@ -224,7 +224,7 @@ function focusZone(container, settings) {
|
|
|
224
224
|
function reinitializeWithFreshElements() {
|
|
225
225
|
const freshElements = [...iterateFocusableElements.iterateFocusableElements(container, iterateFocusableElementsOptions)];
|
|
226
226
|
focusableElements.clear();
|
|
227
|
-
focusableElements.insertAt(0,
|
|
227
|
+
focusableElements.insertAt(0, freshElements);
|
|
228
228
|
for (const element of freshElements) {
|
|
229
229
|
if (!savedTabIndex.has(element)) {
|
|
230
230
|
savedTabIndex.set(element, element.getAttribute('tabindex'));
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
export declare class IndexedSet<T> {
|
|
2
2
|
private _items;
|
|
3
3
|
private _itemSet;
|
|
4
|
-
|
|
4
|
+
private _indexMap;
|
|
5
|
+
insertAt(index: number, elements: T[]): void;
|
|
6
|
+
private _chunkedInsert;
|
|
5
7
|
delete(element: T): boolean;
|
|
6
8
|
has(element: T): boolean;
|
|
7
9
|
indexOf(element: T): number;
|
|
@@ -4,33 +4,92 @@ class IndexedSet {
|
|
|
4
4
|
constructor() {
|
|
5
5
|
this._items = [];
|
|
6
6
|
this._itemSet = new Set();
|
|
7
|
+
this._indexMap = new Map();
|
|
7
8
|
}
|
|
8
|
-
insertAt(index,
|
|
9
|
-
|
|
9
|
+
insertAt(index, elements) {
|
|
10
|
+
let newElements;
|
|
11
|
+
if (elements.length <= 100) {
|
|
12
|
+
newElements = elements.filter((e, i, arr) => !this._itemSet.has(e) && arr.indexOf(e) === i);
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
const seen = new Set();
|
|
16
|
+
newElements = [];
|
|
17
|
+
for (let i = 0; i < elements.length; i++) {
|
|
18
|
+
const e = elements[i];
|
|
19
|
+
if (!this._itemSet.has(e) && !seen.has(e)) {
|
|
20
|
+
seen.add(e);
|
|
21
|
+
newElements.push(e);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
10
25
|
if (newElements.length === 0)
|
|
11
26
|
return;
|
|
12
|
-
|
|
13
|
-
|
|
27
|
+
const insertIndex = Math.max(0, Math.min(index, this._items.length));
|
|
28
|
+
if (insertIndex === this._items.length) {
|
|
29
|
+
for (let i = 0; i < newElements.length; i++) {
|
|
30
|
+
const element = newElements[i];
|
|
31
|
+
this._indexMap.set(element, this._items.length);
|
|
32
|
+
this._items.push(element);
|
|
33
|
+
this._itemSet.add(element);
|
|
34
|
+
}
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
if (insertIndex === 0) {
|
|
38
|
+
for (let i = 0; i < this._items.length; i++) {
|
|
39
|
+
this._indexMap.set(this._items[i], i + newElements.length);
|
|
40
|
+
}
|
|
41
|
+
if (newElements.length <= 10000) {
|
|
42
|
+
this._items.splice(0, 0, ...newElements);
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
this._chunkedInsert(0, newElements);
|
|
46
|
+
}
|
|
47
|
+
for (let i = 0; i < newElements.length; i++) {
|
|
48
|
+
this._itemSet.add(newElements[i]);
|
|
49
|
+
this._indexMap.set(newElements[i], i);
|
|
50
|
+
}
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
for (let i = this._items.length - 1; i >= insertIndex; i--) {
|
|
54
|
+
this._indexMap.set(this._items[i], i + newElements.length);
|
|
55
|
+
}
|
|
56
|
+
if (newElements.length <= 10000) {
|
|
57
|
+
this._items.splice(insertIndex, 0, ...newElements);
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
this._chunkedInsert(insertIndex, newElements);
|
|
61
|
+
}
|
|
62
|
+
for (let i = 0; i < newElements.length; i++) {
|
|
63
|
+
const element = newElements[i];
|
|
14
64
|
this._itemSet.add(element);
|
|
65
|
+
this._indexMap.set(element, insertIndex + i);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
_chunkedInsert(index, elements) {
|
|
69
|
+
const CHUNK_SIZE = 10000;
|
|
70
|
+
for (let i = 0; i < elements.length; i += CHUNK_SIZE) {
|
|
71
|
+
const chunk = elements.slice(i, i + CHUNK_SIZE);
|
|
72
|
+
this._items.splice(index + i, 0, ...chunk);
|
|
15
73
|
}
|
|
16
74
|
}
|
|
17
75
|
delete(element) {
|
|
18
76
|
if (!this._itemSet.has(element))
|
|
19
77
|
return false;
|
|
20
|
-
const index = this.
|
|
21
|
-
|
|
22
|
-
this._items.splice(index, 1);
|
|
23
|
-
}
|
|
78
|
+
const index = this._indexMap.get(element);
|
|
79
|
+
this._items.splice(index, 1);
|
|
24
80
|
this._itemSet.delete(element);
|
|
81
|
+
this._indexMap.delete(element);
|
|
82
|
+
for (let i = index; i < this._items.length; i++) {
|
|
83
|
+
this._indexMap.set(this._items[i], i);
|
|
84
|
+
}
|
|
25
85
|
return true;
|
|
26
86
|
}
|
|
27
87
|
has(element) {
|
|
28
88
|
return this._itemSet.has(element);
|
|
29
89
|
}
|
|
30
90
|
indexOf(element) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
return this._items.indexOf(element);
|
|
91
|
+
var _a;
|
|
92
|
+
return (_a = this._indexMap.get(element)) !== null && _a !== void 0 ? _a : -1;
|
|
34
93
|
}
|
|
35
94
|
get(index) {
|
|
36
95
|
return this._items[index];
|
|
@@ -44,6 +103,7 @@ class IndexedSet {
|
|
|
44
103
|
clear() {
|
|
45
104
|
this._items = [];
|
|
46
105
|
this._itemSet.clear();
|
|
106
|
+
this._indexMap.clear();
|
|
47
107
|
}
|
|
48
108
|
find(predicate) {
|
|
49
109
|
return this._items.find(predicate);
|
package/dist/esm/focus-zone.mjs
CHANGED
|
@@ -204,7 +204,7 @@ function focusZone(container, settings) {
|
|
|
204
204
|
return;
|
|
205
205
|
}
|
|
206
206
|
const insertionIndex = findInsertionIndex(filteredElements);
|
|
207
|
-
focusableElements.insertAt(insertionIndex,
|
|
207
|
+
focusableElements.insertAt(insertionIndex, filteredElements);
|
|
208
208
|
for (const element of filteredElements) {
|
|
209
209
|
if (!savedTabIndex.has(element)) {
|
|
210
210
|
savedTabIndex.set(element, element.getAttribute('tabindex'));
|
|
@@ -222,7 +222,7 @@ function focusZone(container, settings) {
|
|
|
222
222
|
function reinitializeWithFreshElements() {
|
|
223
223
|
const freshElements = [...iterateFocusableElements(container, iterateFocusableElementsOptions)];
|
|
224
224
|
focusableElements.clear();
|
|
225
|
-
focusableElements.insertAt(0,
|
|
225
|
+
focusableElements.insertAt(0, freshElements);
|
|
226
226
|
for (const element of freshElements) {
|
|
227
227
|
if (!savedTabIndex.has(element)) {
|
|
228
228
|
savedTabIndex.set(element, element.getAttribute('tabindex'));
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
export declare class IndexedSet<T> {
|
|
2
2
|
private _items;
|
|
3
3
|
private _itemSet;
|
|
4
|
-
|
|
4
|
+
private _indexMap;
|
|
5
|
+
insertAt(index: number, elements: T[]): void;
|
|
6
|
+
private _chunkedInsert;
|
|
5
7
|
delete(element: T): boolean;
|
|
6
8
|
has(element: T): boolean;
|
|
7
9
|
indexOf(element: T): number;
|
|
@@ -2,33 +2,92 @@ class IndexedSet {
|
|
|
2
2
|
constructor() {
|
|
3
3
|
this._items = [];
|
|
4
4
|
this._itemSet = new Set();
|
|
5
|
+
this._indexMap = new Map();
|
|
5
6
|
}
|
|
6
|
-
insertAt(index,
|
|
7
|
-
|
|
7
|
+
insertAt(index, elements) {
|
|
8
|
+
let newElements;
|
|
9
|
+
if (elements.length <= 100) {
|
|
10
|
+
newElements = elements.filter((e, i, arr) => !this._itemSet.has(e) && arr.indexOf(e) === i);
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
const seen = new Set();
|
|
14
|
+
newElements = [];
|
|
15
|
+
for (let i = 0; i < elements.length; i++) {
|
|
16
|
+
const e = elements[i];
|
|
17
|
+
if (!this._itemSet.has(e) && !seen.has(e)) {
|
|
18
|
+
seen.add(e);
|
|
19
|
+
newElements.push(e);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
8
23
|
if (newElements.length === 0)
|
|
9
24
|
return;
|
|
10
|
-
|
|
11
|
-
|
|
25
|
+
const insertIndex = Math.max(0, Math.min(index, this._items.length));
|
|
26
|
+
if (insertIndex === this._items.length) {
|
|
27
|
+
for (let i = 0; i < newElements.length; i++) {
|
|
28
|
+
const element = newElements[i];
|
|
29
|
+
this._indexMap.set(element, this._items.length);
|
|
30
|
+
this._items.push(element);
|
|
31
|
+
this._itemSet.add(element);
|
|
32
|
+
}
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
if (insertIndex === 0) {
|
|
36
|
+
for (let i = 0; i < this._items.length; i++) {
|
|
37
|
+
this._indexMap.set(this._items[i], i + newElements.length);
|
|
38
|
+
}
|
|
39
|
+
if (newElements.length <= 10000) {
|
|
40
|
+
this._items.splice(0, 0, ...newElements);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
this._chunkedInsert(0, newElements);
|
|
44
|
+
}
|
|
45
|
+
for (let i = 0; i < newElements.length; i++) {
|
|
46
|
+
this._itemSet.add(newElements[i]);
|
|
47
|
+
this._indexMap.set(newElements[i], i);
|
|
48
|
+
}
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
for (let i = this._items.length - 1; i >= insertIndex; i--) {
|
|
52
|
+
this._indexMap.set(this._items[i], i + newElements.length);
|
|
53
|
+
}
|
|
54
|
+
if (newElements.length <= 10000) {
|
|
55
|
+
this._items.splice(insertIndex, 0, ...newElements);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
this._chunkedInsert(insertIndex, newElements);
|
|
59
|
+
}
|
|
60
|
+
for (let i = 0; i < newElements.length; i++) {
|
|
61
|
+
const element = newElements[i];
|
|
12
62
|
this._itemSet.add(element);
|
|
63
|
+
this._indexMap.set(element, insertIndex + i);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
_chunkedInsert(index, elements) {
|
|
67
|
+
const CHUNK_SIZE = 10000;
|
|
68
|
+
for (let i = 0; i < elements.length; i += CHUNK_SIZE) {
|
|
69
|
+
const chunk = elements.slice(i, i + CHUNK_SIZE);
|
|
70
|
+
this._items.splice(index + i, 0, ...chunk);
|
|
13
71
|
}
|
|
14
72
|
}
|
|
15
73
|
delete(element) {
|
|
16
74
|
if (!this._itemSet.has(element))
|
|
17
75
|
return false;
|
|
18
|
-
const index = this.
|
|
19
|
-
|
|
20
|
-
this._items.splice(index, 1);
|
|
21
|
-
}
|
|
76
|
+
const index = this._indexMap.get(element);
|
|
77
|
+
this._items.splice(index, 1);
|
|
22
78
|
this._itemSet.delete(element);
|
|
79
|
+
this._indexMap.delete(element);
|
|
80
|
+
for (let i = index; i < this._items.length; i++) {
|
|
81
|
+
this._indexMap.set(this._items[i], i);
|
|
82
|
+
}
|
|
23
83
|
return true;
|
|
24
84
|
}
|
|
25
85
|
has(element) {
|
|
26
86
|
return this._itemSet.has(element);
|
|
27
87
|
}
|
|
28
88
|
indexOf(element) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return this._items.indexOf(element);
|
|
89
|
+
var _a;
|
|
90
|
+
return (_a = this._indexMap.get(element)) !== null && _a !== void 0 ? _a : -1;
|
|
32
91
|
}
|
|
33
92
|
get(index) {
|
|
34
93
|
return this._items[index];
|
|
@@ -42,6 +101,7 @@ class IndexedSet {
|
|
|
42
101
|
clear() {
|
|
43
102
|
this._items = [];
|
|
44
103
|
this._itemSet.clear();
|
|
104
|
+
this._indexMap.clear();
|
|
45
105
|
}
|
|
46
106
|
find(predicate) {
|
|
47
107
|
return this._items.find(predicate);
|