@primer/behaviors 0.0.0-20251215034054 → 0.0.0-20251215124648

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.
@@ -7,7 +7,7 @@ eventListenerSignal.polyfill();
7
7
  const suspendedTrapStack = [];
8
8
  let activeTrap = undefined;
9
9
  const SR_ONLY_STYLES = 'position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0';
10
- function createSentinel(onFocus) {
10
+ function createSentinel({ onFocus }) {
11
11
  const sentinel = document.createElement('span');
12
12
  sentinel.setAttribute('class', 'sentinel');
13
13
  sentinel.setAttribute('tabindex', '0');
@@ -57,13 +57,17 @@ function focusTrap(container, initialFocus, abortSignal) {
57
57
  const controller = new AbortController();
58
58
  const signal = abortSignal !== null && abortSignal !== void 0 ? abortSignal : controller.signal;
59
59
  container.setAttribute('data-focus-trap', 'active');
60
- const sentinelStart = createSentinel(() => {
61
- const lastFocusableChild = iterateFocusableElements.getFocusableChild(container, true);
62
- lastFocusableChild === null || lastFocusableChild === void 0 ? void 0 : lastFocusableChild.focus();
60
+ const sentinelStart = createSentinel({
61
+ onFocus: () => {
62
+ const lastFocusableChild = iterateFocusableElements.getFocusableChild(container, true);
63
+ lastFocusableChild === null || lastFocusableChild === void 0 ? void 0 : lastFocusableChild.focus();
64
+ },
63
65
  });
64
- const sentinelEnd = createSentinel(() => {
65
- const firstFocusableChild = iterateFocusableElements.getFocusableChild(container);
66
- firstFocusableChild === null || firstFocusableChild === void 0 ? void 0 : firstFocusableChild.focus();
66
+ const sentinelEnd = createSentinel({
67
+ onFocus: () => {
68
+ const firstFocusableChild = iterateFocusableElements.getFocusableChild(container);
69
+ firstFocusableChild === null || firstFocusableChild === void 0 ? void 0 : firstFocusableChild.focus();
70
+ },
67
71
  });
68
72
  const hasExistingSentinels = container.querySelector(':scope > span.sentinel') !== null;
69
73
  if (!hasExistingSentinels) {
@@ -1,5 +1,6 @@
1
1
  export declare class IndexedSet<T> {
2
- #private;
2
+ private _items;
3
+ private _itemSet;
3
4
  insertAt(index: number, ...elements: T[]): void;
4
5
  delete(element: T): boolean;
5
6
  has(element: T): boolean;
@@ -1,55 +1,52 @@
1
1
  'use strict';
2
2
 
3
- var tslib = require('tslib');
4
-
5
- var _IndexedSet_items, _IndexedSet_itemSet;
6
3
  class IndexedSet {
7
4
  constructor() {
8
- _IndexedSet_items.set(this, []);
9
- _IndexedSet_itemSet.set(this, new Set());
5
+ this._items = [];
6
+ this._itemSet = new Set();
10
7
  }
11
8
  insertAt(index, ...elements) {
12
- const newElements = elements.filter(e => !tslib.__classPrivateFieldGet(this, _IndexedSet_itemSet, "f").has(e));
9
+ const newElements = elements.filter(e => !this._itemSet.has(e));
13
10
  if (newElements.length === 0)
14
11
  return;
15
- tslib.__classPrivateFieldGet(this, _IndexedSet_items, "f").splice(index, 0, ...newElements);
12
+ this._items.splice(index, 0, ...newElements);
16
13
  for (const element of newElements) {
17
- tslib.__classPrivateFieldGet(this, _IndexedSet_itemSet, "f").add(element);
14
+ this._itemSet.add(element);
18
15
  }
19
16
  }
20
17
  delete(element) {
21
- if (!tslib.__classPrivateFieldGet(this, _IndexedSet_itemSet, "f").has(element))
18
+ if (!this._itemSet.has(element))
22
19
  return false;
23
- const index = tslib.__classPrivateFieldGet(this, _IndexedSet_items, "f").indexOf(element);
20
+ const index = this._items.indexOf(element);
24
21
  if (index >= 0) {
25
- tslib.__classPrivateFieldGet(this, _IndexedSet_items, "f").splice(index, 1);
22
+ this._items.splice(index, 1);
26
23
  }
27
- tslib.__classPrivateFieldGet(this, _IndexedSet_itemSet, "f").delete(element);
24
+ this._itemSet.delete(element);
28
25
  return true;
29
26
  }
30
27
  has(element) {
31
- return tslib.__classPrivateFieldGet(this, _IndexedSet_itemSet, "f").has(element);
28
+ return this._itemSet.has(element);
32
29
  }
33
30
  indexOf(element) {
34
- if (!tslib.__classPrivateFieldGet(this, _IndexedSet_itemSet, "f").has(element))
31
+ if (!this._itemSet.has(element))
35
32
  return -1;
36
- return tslib.__classPrivateFieldGet(this, _IndexedSet_items, "f").indexOf(element);
33
+ return this._items.indexOf(element);
37
34
  }
38
35
  get(index) {
39
- return tslib.__classPrivateFieldGet(this, _IndexedSet_items, "f")[index];
36
+ return this._items[index];
40
37
  }
41
38
  get size() {
42
- return tslib.__classPrivateFieldGet(this, _IndexedSet_items, "f").length;
39
+ return this._items.length;
43
40
  }
44
- [(_IndexedSet_items = new WeakMap(), _IndexedSet_itemSet = new WeakMap(), Symbol.iterator)]() {
45
- return tslib.__classPrivateFieldGet(this, _IndexedSet_items, "f")[Symbol.iterator]();
41
+ [Symbol.iterator]() {
42
+ return this._items[Symbol.iterator]();
46
43
  }
47
44
  clear() {
48
- tslib.__classPrivateFieldSet(this, _IndexedSet_items, [], "f");
49
- tslib.__classPrivateFieldGet(this, _IndexedSet_itemSet, "f").clear();
45
+ this._items = [];
46
+ this._itemSet.clear();
50
47
  }
51
48
  find(predicate) {
52
- return tslib.__classPrivateFieldGet(this, _IndexedSet_items, "f").find(predicate);
49
+ return this._items.find(predicate);
53
50
  }
54
51
  }
55
52
 
@@ -5,7 +5,7 @@ polyfill();
5
5
  const suspendedTrapStack = [];
6
6
  let activeTrap = undefined;
7
7
  const SR_ONLY_STYLES = 'position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0';
8
- function createSentinel(onFocus) {
8
+ function createSentinel({ onFocus }) {
9
9
  const sentinel = document.createElement('span');
10
10
  sentinel.setAttribute('class', 'sentinel');
11
11
  sentinel.setAttribute('tabindex', '0');
@@ -55,13 +55,17 @@ function focusTrap(container, initialFocus, abortSignal) {
55
55
  const controller = new AbortController();
56
56
  const signal = abortSignal !== null && abortSignal !== void 0 ? abortSignal : controller.signal;
57
57
  container.setAttribute('data-focus-trap', 'active');
58
- const sentinelStart = createSentinel(() => {
59
- const lastFocusableChild = getFocusableChild(container, true);
60
- lastFocusableChild === null || lastFocusableChild === void 0 ? void 0 : lastFocusableChild.focus();
58
+ const sentinelStart = createSentinel({
59
+ onFocus: () => {
60
+ const lastFocusableChild = getFocusableChild(container, true);
61
+ lastFocusableChild === null || lastFocusableChild === void 0 ? void 0 : lastFocusableChild.focus();
62
+ },
61
63
  });
62
- const sentinelEnd = createSentinel(() => {
63
- const firstFocusableChild = getFocusableChild(container);
64
- firstFocusableChild === null || firstFocusableChild === void 0 ? void 0 : firstFocusableChild.focus();
64
+ const sentinelEnd = createSentinel({
65
+ onFocus: () => {
66
+ const firstFocusableChild = getFocusableChild(container);
67
+ firstFocusableChild === null || firstFocusableChild === void 0 ? void 0 : firstFocusableChild.focus();
68
+ },
65
69
  });
66
70
  const hasExistingSentinels = container.querySelector(':scope > span.sentinel') !== null;
67
71
  if (!hasExistingSentinels) {
@@ -1,5 +1,6 @@
1
1
  export declare class IndexedSet<T> {
2
- #private;
2
+ private _items;
3
+ private _itemSet;
3
4
  insertAt(index: number, ...elements: T[]): void;
4
5
  delete(element: T): boolean;
5
6
  has(element: T): boolean;
@@ -1,53 +1,50 @@
1
- import { __classPrivateFieldGet, __classPrivateFieldSet } from 'tslib';
2
-
3
- var _IndexedSet_items, _IndexedSet_itemSet;
4
1
  class IndexedSet {
5
2
  constructor() {
6
- _IndexedSet_items.set(this, []);
7
- _IndexedSet_itemSet.set(this, new Set());
3
+ this._items = [];
4
+ this._itemSet = new Set();
8
5
  }
9
6
  insertAt(index, ...elements) {
10
- const newElements = elements.filter(e => !__classPrivateFieldGet(this, _IndexedSet_itemSet, "f").has(e));
7
+ const newElements = elements.filter(e => !this._itemSet.has(e));
11
8
  if (newElements.length === 0)
12
9
  return;
13
- __classPrivateFieldGet(this, _IndexedSet_items, "f").splice(index, 0, ...newElements);
10
+ this._items.splice(index, 0, ...newElements);
14
11
  for (const element of newElements) {
15
- __classPrivateFieldGet(this, _IndexedSet_itemSet, "f").add(element);
12
+ this._itemSet.add(element);
16
13
  }
17
14
  }
18
15
  delete(element) {
19
- if (!__classPrivateFieldGet(this, _IndexedSet_itemSet, "f").has(element))
16
+ if (!this._itemSet.has(element))
20
17
  return false;
21
- const index = __classPrivateFieldGet(this, _IndexedSet_items, "f").indexOf(element);
18
+ const index = this._items.indexOf(element);
22
19
  if (index >= 0) {
23
- __classPrivateFieldGet(this, _IndexedSet_items, "f").splice(index, 1);
20
+ this._items.splice(index, 1);
24
21
  }
25
- __classPrivateFieldGet(this, _IndexedSet_itemSet, "f").delete(element);
22
+ this._itemSet.delete(element);
26
23
  return true;
27
24
  }
28
25
  has(element) {
29
- return __classPrivateFieldGet(this, _IndexedSet_itemSet, "f").has(element);
26
+ return this._itemSet.has(element);
30
27
  }
31
28
  indexOf(element) {
32
- if (!__classPrivateFieldGet(this, _IndexedSet_itemSet, "f").has(element))
29
+ if (!this._itemSet.has(element))
33
30
  return -1;
34
- return __classPrivateFieldGet(this, _IndexedSet_items, "f").indexOf(element);
31
+ return this._items.indexOf(element);
35
32
  }
36
33
  get(index) {
37
- return __classPrivateFieldGet(this, _IndexedSet_items, "f")[index];
34
+ return this._items[index];
38
35
  }
39
36
  get size() {
40
- return __classPrivateFieldGet(this, _IndexedSet_items, "f").length;
37
+ return this._items.length;
41
38
  }
42
- [(_IndexedSet_items = new WeakMap(), _IndexedSet_itemSet = new WeakMap(), Symbol.iterator)]() {
43
- return __classPrivateFieldGet(this, _IndexedSet_items, "f")[Symbol.iterator]();
39
+ [Symbol.iterator]() {
40
+ return this._items[Symbol.iterator]();
44
41
  }
45
42
  clear() {
46
- __classPrivateFieldSet(this, _IndexedSet_items, [], "f");
47
- __classPrivateFieldGet(this, _IndexedSet_itemSet, "f").clear();
43
+ this._items = [];
44
+ this._itemSet.clear();
48
45
  }
49
46
  find(predicate) {
50
- return __classPrivateFieldGet(this, _IndexedSet_items, "f").find(predicate);
47
+ return this._items.find(predicate);
51
48
  }
52
49
  }
53
50
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primer/behaviors",
3
- "version": "0.0.0-20251215034054",
3
+ "version": "0.0.0-20251215124648",
4
4
  "description": "Shared behaviors for JavaScript components",
5
5
  "type": "commonjs",
6
6
  "main": "dist/cjs/index.js",