@primer/react 0.0.0-20260311021722 → 0.0.0-20260311025700
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/CHANGELOG.md
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
# @primer/react
|
|
2
2
|
|
|
3
|
-
## 0.0.0-
|
|
3
|
+
## 0.0.0-20260311025700
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
7
|
- Fake entry to force publishing
|
|
8
8
|
|
|
9
|
-
- [#7544](https://github.com/primer/react/pull/7544) [`b3741d3`](https://github.com/primer/react/commit/b3741d30159cba8710c8db2f751d3526306aa754) Thanks [@hectahertz](https://github.com/hectahertz)! - perf(TreeView): replace O(n) TreeWalker with O(depth) sibling traversal
|
|
10
|
-
|
|
11
9
|
## 38.15.0
|
|
12
10
|
|
|
13
11
|
### Minor Changes
|
|
@@ -5,20 +5,6 @@ export declare function useRovingTabIndex({ containerRef, mouseDownRef, }: {
|
|
|
5
5
|
}): void;
|
|
6
6
|
export declare function getNextFocusableElement(activeElement: HTMLElement, event: KeyboardEvent): HTMLElement | undefined;
|
|
7
7
|
export declare function getElementState(element: HTMLElement): 'open' | 'closed' | 'end';
|
|
8
|
-
/**
|
|
9
|
-
* Find the next or previous visible treeitem using direct DOM traversal.
|
|
10
|
-
*
|
|
11
|
-
* PERFORMANCE: This is O(tree depth) instead of O(n) because it walks
|
|
12
|
-
* siblings and parent/child edges directly, rather than creating a TreeWalker
|
|
13
|
-
* that scans from the root to find the current element on every keystroke.
|
|
14
|
-
*
|
|
15
|
-
* NOTE: This relies on TreeView.SubTree unmounting its children when collapsed
|
|
16
|
-
* (returning null when !isExpanded). Because collapsed subtree children are
|
|
17
|
-
* never in the DOM, we can safely skip them by only entering children of nodes
|
|
18
|
-
* with aria-expanded="true". If SubTree ever changes to keep collapsed children
|
|
19
|
-
* mounted (e.g. via CSS display:none), this logic would need to add filtering
|
|
20
|
-
* for items inside collapsed parents.
|
|
21
|
-
*/
|
|
22
8
|
export declare function getVisibleElement(element: HTMLElement, direction: 'next' | 'previous'): HTMLElement | undefined;
|
|
23
9
|
export declare function getFirstChildElement(element: HTMLElement): HTMLElement | undefined;
|
|
24
10
|
export declare function getParentElement(element: HTMLElement): HTMLElement | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRovingTabIndex.d.ts","sourceRoot":"","sources":["../../src/TreeView/useRovingTabIndex.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAI9B,wBAAgB,iBAAiB,CAAC,EAChC,YAAY,EACZ,YAAY,GACb,EAAE;IACD,YAAY,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,CAAA;IAC1C,YAAY,EAAE,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA;CACvC,QAwDA;AAID,wBAAgB,uBAAuB,CAAC,aAAa,EAAE,WAAW,EAAE,KAAK,EAAE,aAAa,GAAG,WAAW,GAAG,SAAS,CAyDjH;AAED,wBAAgB,eAAe,CAAC,OAAO,EAAE,WAAW,GAAG,MAAM,GAAG,QAAQ,GAAG,KAAK,CAa/E;AAED
|
|
1
|
+
{"version":3,"file":"useRovingTabIndex.d.ts","sourceRoot":"","sources":["../../src/TreeView/useRovingTabIndex.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAI9B,wBAAgB,iBAAiB,CAAC,EAChC,YAAY,EACZ,YAAY,GACb,EAAE;IACD,YAAY,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,CAAA;IAC1C,YAAY,EAAE,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA;CACvC,QAwDA;AAID,wBAAgB,uBAAuB,CAAC,aAAa,EAAE,WAAW,EAAE,KAAK,EAAE,aAAa,GAAG,WAAW,GAAG,SAAS,CAyDjH;AAED,wBAAgB,eAAe,CAAC,OAAO,EAAE,WAAW,GAAG,MAAM,GAAG,QAAQ,GAAG,KAAK,CAa/E;AAED,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,GAAG,UAAU,GAAG,WAAW,GAAG,SAAS,CAwB/G;AAED,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,WAAW,GAAG,WAAW,GAAG,SAAS,CAGlF;AAED,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,WAAW,GAAG,WAAW,GAAG,SAAS,CAI9E;AAED,wBAAgB,eAAe,CAAC,OAAO,EAAE,WAAW,GAAG,WAAW,GAAG,SAAS,CAI7E;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,WAAW,GAAG,WAAW,GAAG,SAAS,CAuB5E"}
|
|
@@ -123,103 +123,25 @@ function getElementState(element) {
|
|
|
123
123
|
return 'end';
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Find the next or previous visible treeitem using direct DOM traversal.
|
|
129
|
-
*
|
|
130
|
-
* PERFORMANCE: This is O(tree depth) instead of O(n) because it walks
|
|
131
|
-
* siblings and parent/child edges directly, rather than creating a TreeWalker
|
|
132
|
-
* that scans from the root to find the current element on every keystroke.
|
|
133
|
-
*
|
|
134
|
-
* NOTE: This relies on TreeView.SubTree unmounting its children when collapsed
|
|
135
|
-
* (returning null when !isExpanded). Because collapsed subtree children are
|
|
136
|
-
* never in the DOM, we can safely skip them by only entering children of nodes
|
|
137
|
-
* with aria-expanded="true". If SubTree ever changes to keep collapsed children
|
|
138
|
-
* mounted (e.g. via CSS display:none), this logic would need to add filtering
|
|
139
|
-
* for items inside collapsed parents.
|
|
140
|
-
*/
|
|
141
126
|
function getVisibleElement(element, direction) {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
// Otherwise, walk up the tree looking for a next sibling
|
|
155
|
-
let current = element;
|
|
156
|
-
while (current) {
|
|
157
|
-
const next = getNextSiblingTreeItem(current);
|
|
158
|
-
if (next) return next;
|
|
159
|
-
|
|
160
|
-
// No next sibling at this level, try the parent's next sibling
|
|
161
|
-
current = getParentElement(current);
|
|
162
|
-
}
|
|
163
|
-
return undefined;
|
|
164
|
-
}
|
|
165
|
-
function getPreviousVisibleElement(element) {
|
|
166
|
-
const prev = getPreviousSiblingTreeItem(element);
|
|
167
|
-
if (prev) {
|
|
168
|
-
// Navigate to the deepest last visible descendant of the previous sibling
|
|
169
|
-
return getDeepestLastDescendant(prev);
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
// No previous sibling, the parent is the previous visible element
|
|
173
|
-
return getParentElement(element);
|
|
174
|
-
}
|
|
127
|
+
const root = element.closest('[role=tree]');
|
|
128
|
+
if (!root) return;
|
|
129
|
+
const walker = document.createTreeWalker(root, NodeFilter.SHOW_ELEMENT, node => {
|
|
130
|
+
if (!(node instanceof HTMLElement)) return NodeFilter.FILTER_SKIP;
|
|
131
|
+
return node.getAttribute('role') === 'treeitem' ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
|
|
132
|
+
});
|
|
133
|
+
let current = walker.firstChild();
|
|
134
|
+
while (current !== element) {
|
|
135
|
+
current = walker.nextNode();
|
|
136
|
+
}
|
|
137
|
+
let next = direction === 'next' ? walker.nextNode() : walker.previousNode();
|
|
175
138
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
*/
|
|
181
|
-
function getDeepestLastDescendant(element) {
|
|
182
|
-
let current = element;
|
|
183
|
-
while (current.getAttribute('aria-expanded') === 'true') {
|
|
184
|
-
const lastChild = getLastChildTreeItem(current);
|
|
185
|
-
if (!lastChild) break;
|
|
186
|
-
current = lastChild;
|
|
187
|
-
}
|
|
188
|
-
return current;
|
|
189
|
-
}
|
|
190
|
-
function getNextSiblingTreeItem(element) {
|
|
191
|
-
let sibling = element.nextElementSibling;
|
|
192
|
-
while (sibling) {
|
|
193
|
-
if (sibling instanceof HTMLElement && sibling.getAttribute('role') === 'treeitem') {
|
|
194
|
-
return sibling;
|
|
195
|
-
}
|
|
196
|
-
sibling = sibling.nextElementSibling;
|
|
197
|
-
}
|
|
198
|
-
return undefined;
|
|
199
|
-
}
|
|
200
|
-
function getPreviousSiblingTreeItem(element) {
|
|
201
|
-
let sibling = element.previousElementSibling;
|
|
202
|
-
while (sibling) {
|
|
203
|
-
if (sibling instanceof HTMLElement && sibling.getAttribute('role') === 'treeitem') {
|
|
204
|
-
return sibling;
|
|
205
|
-
}
|
|
206
|
-
sibling = sibling.previousElementSibling;
|
|
207
|
-
}
|
|
208
|
-
return undefined;
|
|
209
|
-
}
|
|
210
|
-
function getLastChildTreeItem(element) {
|
|
211
|
-
// Find the [role=group] child (the subtree container), then get its last treeitem
|
|
212
|
-
for (let i = element.children.length - 1; i >= 0; i--) {
|
|
213
|
-
const child = element.children[i];
|
|
214
|
-
if (child instanceof HTMLElement && child.getAttribute('role') === 'group') {
|
|
215
|
-
let lastChild = child.lastElementChild;
|
|
216
|
-
while (lastChild && !(lastChild instanceof HTMLElement && lastChild.getAttribute('role') === 'treeitem')) {
|
|
217
|
-
lastChild = lastChild.previousElementSibling;
|
|
218
|
-
}
|
|
219
|
-
return lastChild instanceof HTMLElement ? lastChild : undefined;
|
|
220
|
-
}
|
|
139
|
+
// If next element is nested inside a collapsed subtree, continue iterating
|
|
140
|
+
while (next instanceof HTMLElement && (_next$parentElement = next.parentElement) !== null && _next$parentElement !== void 0 && _next$parentElement.closest('[role=treeitem][aria-expanded=false]')) {
|
|
141
|
+
var _next$parentElement;
|
|
142
|
+
next = direction === 'next' ? walker.nextNode() : walker.previousNode();
|
|
221
143
|
}
|
|
222
|
-
return undefined;
|
|
144
|
+
return next instanceof HTMLElement ? next : undefined;
|
|
223
145
|
}
|
|
224
146
|
function getFirstChildElement(element) {
|
|
225
147
|
const firstChild = element.querySelector('[role=treeitem]');
|
package/package.json
CHANGED