@primer/behaviors 0.0.0-20230925221012 → 0.0.0-20230927074223

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.
@@ -5,12 +5,12 @@ const alternateOrders = {
5
5
  'outside-top': ['outside-bottom', 'outside-right', 'outside-left', 'outside-bottom'],
6
6
  'outside-bottom': ['outside-top', 'outside-right', 'outside-left', 'outside-bottom'],
7
7
  'outside-left': ['outside-right', 'outside-bottom', 'outside-top', 'outside-bottom'],
8
- 'outside-right': ['outside-left', 'outside-bottom', 'outside-top', 'outside-bottom'],
8
+ 'outside-right': ['outside-left', 'outside-bottom', 'outside-top', 'outside-bottom']
9
9
  };
10
10
  const alternateAlignments = {
11
11
  start: ['end', 'center'],
12
12
  end: ['start', 'center'],
13
- center: ['end', 'start'],
13
+ center: ['end', 'start']
14
14
  };
15
15
  function getAnchoredPosition(floatingElement, anchorElement, settings = {}) {
16
16
  const parentElement = getPositionedParent(floatingElement);
@@ -20,7 +20,7 @@ function getAnchoredPosition(floatingElement, anchorElement, settings = {}) {
20
20
  const [borderTop, borderLeft] = [parentElementStyle.borderTopWidth, parentElementStyle.borderLeftWidth].map(v => parseInt(v, 10) || 0);
21
21
  const relativeRect = {
22
22
  top: parentElementRect.top + borderTop,
23
- left: parentElementRect.left + borderLeft,
23
+ left: parentElementRect.left + borderLeft
24
24
  };
25
25
  return pureCalculateAnchoredPosition(clippingRect, relativeRect, floatingElement.getBoundingClientRect(), anchorElement instanceof Element ? anchorElement.getBoundingClientRect() : anchorElement, getDefaultSettings(settings));
26
26
  }
@@ -71,13 +71,13 @@ function getClippingRect(element) {
71
71
  elemStyle.borderTopWidth,
72
72
  elemStyle.borderLeftWidth,
73
73
  elemStyle.borderRightWidth,
74
- elemStyle.borderBottomWidth,
74
+ elemStyle.borderBottomWidth
75
75
  ].map(v => parseInt(v, 10) || 0);
76
76
  return {
77
77
  top: elemRect.top + borderTop,
78
78
  left: elemRect.left + borderLeft,
79
79
  width: elemRect.width - borderRight - borderLeft,
80
- height: Math.max(elemRect.height - borderTop - borderBottom, clippingNode === document.body ? window.innerHeight : -Infinity),
80
+ height: Math.max(elemRect.height - borderTop - borderBottom, clippingNode === document.body ? window.innerHeight : -Infinity)
81
81
  };
82
82
  }
83
83
  const positionDefaults = {
@@ -85,7 +85,7 @@ const positionDefaults = {
85
85
  align: 'start',
86
86
  anchorOffset: 4,
87
87
  alignmentOffset: 4,
88
- allowOutOfBounds: false,
88
+ allowOutOfBounds: false
89
89
  };
90
90
  function getDefaultSettings(settings = {}) {
91
91
  var _a, _b, _c, _d, _e;
@@ -96,7 +96,7 @@ function getDefaultSettings(settings = {}) {
96
96
  align,
97
97
  anchorOffset: (_c = settings.anchorOffset) !== null && _c !== void 0 ? _c : (side === 'inside-center' ? 0 : positionDefaults.anchorOffset),
98
98
  alignmentOffset: (_d = settings.alignmentOffset) !== null && _d !== void 0 ? _d : (align !== 'center' && side.startsWith('inside') ? positionDefaults.alignmentOffset : 0),
99
- allowOutOfBounds: (_e = settings.allowOutOfBounds) !== null && _e !== void 0 ? _e : positionDefaults.allowOutOfBounds,
99
+ allowOutOfBounds: (_e = settings.allowOutOfBounds) !== null && _e !== void 0 ? _e : positionDefaults.allowOutOfBounds
100
100
  };
101
101
  }
102
102
  function pureCalculateAnchoredPosition(viewportRect, relativePosition, floatingRect, anchorRect, { side, align, allowOutOfBounds, anchorOffset, alignmentOffset }) {
@@ -104,7 +104,7 @@ function pureCalculateAnchoredPosition(viewportRect, relativePosition, floatingR
104
104
  top: viewportRect.top - relativePosition.top,
105
105
  left: viewportRect.left - relativePosition.left,
106
106
  width: viewportRect.width,
107
- height: viewportRect.height,
107
+ height: viewportRect.height
108
108
  };
109
109
  let pos = calculatePosition(floatingRect, anchorRect, side, align, anchorOffset, alignmentOffset);
110
110
  let anchorSide = side;
@@ -5,7 +5,7 @@ function offset(element) {
5
5
  const rect = element.getBoundingClientRect();
6
6
  return {
7
7
  top: rect.top + window.pageYOffset,
8
- left: rect.left + window.pageXOffset,
8
+ left: rect.left + window.pageXOffset
9
9
  };
10
10
  }
11
11
  exports.offset = offset;
@@ -62,11 +62,11 @@ function overflowOffset(element, targetContainer) {
62
62
  const scroll = container === document.documentElement && document.defaultView
63
63
  ? {
64
64
  top: document.defaultView.pageYOffset,
65
- left: document.defaultView.pageXOffset,
65
+ left: document.defaultView.pageXOffset
66
66
  }
67
67
  : {
68
68
  top: container.scrollTop,
69
- left: container.scrollLeft,
69
+ left: container.scrollLeft
70
70
  };
71
71
  const top = elementOffset.top - scroll.top;
72
72
  const left = elementOffset.left - scroll.left;
@@ -94,7 +94,7 @@ function focusTrap(container, initialFocus, abortSignal) {
94
94
  container,
95
95
  controller: wrappingController,
96
96
  initialFocus,
97
- originalSignal: signal,
97
+ originalSignal: signal
98
98
  };
99
99
  const suspendedTrapIndex = suspendedTrapStack.findIndex(t => t.container === container);
100
100
  if (suspendedTrapIndex >= 0) {
@@ -41,7 +41,7 @@ const KEY_TO_BIT = {
41
41
  End: FocusKeys.HomeAndEnd,
42
42
  PageUp: FocusKeys.PageUpDown,
43
43
  PageDown: FocusKeys.PageUpDown,
44
- Backspace: FocusKeys.Backspace,
44
+ Backspace: FocusKeys.Backspace
45
45
  };
46
46
  const KEY_TO_DIRECTION = {
47
47
  ArrowLeft: 'previous',
@@ -61,7 +61,7 @@ const KEY_TO_DIRECTION = {
61
61
  End: 'end',
62
62
  PageUp: 'start',
63
63
  PageDown: 'end',
64
- Backspace: 'previous',
64
+ Backspace: 'previous'
65
65
  };
66
66
  function getDirection(keyboardEvent) {
67
67
  const direction = KEY_TO_DIRECTION[keyboardEvent.key];
@@ -265,7 +265,7 @@ function focusZone(container, settings) {
265
265
  });
266
266
  observer.observe(container, {
267
267
  subtree: true,
268
- childList: true,
268
+ childList: true
269
269
  });
270
270
  const controller = new AbortController();
271
271
  const signal = (_e = settings === null || settings === void 0 ? void 0 : settings.abortSignal) !== null && _e !== void 0 ? _e : controller.signal;
@@ -8,8 +8,8 @@ try {
8
8
  signal: {
9
9
  get() {
10
10
  signalSupported = true;
11
- },
12
- },
11
+ }
12
+ }
13
13
  });
14
14
  window.addEventListener('test', noop, options);
15
15
  window.removeEventListener('test', noop, options);
@@ -6,7 +6,7 @@ function* iterateFocusableElements(container, options = {}) {
6
6
  const strict = (_a = options.strict) !== null && _a !== void 0 ? _a : false;
7
7
  const acceptFn = ((_b = options.onlyTabbable) !== null && _b !== void 0 ? _b : false) ? isTabbable : isFocusable;
8
8
  const walker = document.createTreeWalker(container, NodeFilter.SHOW_ELEMENT, {
9
- acceptNode: node => node instanceof HTMLElement && acceptFn(node, strict) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP,
9
+ acceptNode: node => node instanceof HTMLElement && acceptFn(node, strict) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP
10
10
  });
11
11
  let nextNode = null;
12
12
  if (!options.reverse && acceptFn(container, strict)) {
@@ -2,12 +2,12 @@ const alternateOrders = {
2
2
  'outside-top': ['outside-bottom', 'outside-right', 'outside-left', 'outside-bottom'],
3
3
  'outside-bottom': ['outside-top', 'outside-right', 'outside-left', 'outside-bottom'],
4
4
  'outside-left': ['outside-right', 'outside-bottom', 'outside-top', 'outside-bottom'],
5
- 'outside-right': ['outside-left', 'outside-bottom', 'outside-top', 'outside-bottom'],
5
+ 'outside-right': ['outside-left', 'outside-bottom', 'outside-top', 'outside-bottom']
6
6
  };
7
7
  const alternateAlignments = {
8
8
  start: ['end', 'center'],
9
9
  end: ['start', 'center'],
10
- center: ['end', 'start'],
10
+ center: ['end', 'start']
11
11
  };
12
12
  export function getAnchoredPosition(floatingElement, anchorElement, settings = {}) {
13
13
  const parentElement = getPositionedParent(floatingElement);
@@ -17,7 +17,7 @@ export function getAnchoredPosition(floatingElement, anchorElement, settings = {
17
17
  const [borderTop, borderLeft] = [parentElementStyle.borderTopWidth, parentElementStyle.borderLeftWidth].map(v => parseInt(v, 10) || 0);
18
18
  const relativeRect = {
19
19
  top: parentElementRect.top + borderTop,
20
- left: parentElementRect.left + borderLeft,
20
+ left: parentElementRect.left + borderLeft
21
21
  };
22
22
  return pureCalculateAnchoredPosition(clippingRect, relativeRect, floatingElement.getBoundingClientRect(), anchorElement instanceof Element ? anchorElement.getBoundingClientRect() : anchorElement, getDefaultSettings(settings));
23
23
  }
@@ -67,13 +67,13 @@ function getClippingRect(element) {
67
67
  elemStyle.borderTopWidth,
68
68
  elemStyle.borderLeftWidth,
69
69
  elemStyle.borderRightWidth,
70
- elemStyle.borderBottomWidth,
70
+ elemStyle.borderBottomWidth
71
71
  ].map(v => parseInt(v, 10) || 0);
72
72
  return {
73
73
  top: elemRect.top + borderTop,
74
74
  left: elemRect.left + borderLeft,
75
75
  width: elemRect.width - borderRight - borderLeft,
76
- height: Math.max(elemRect.height - borderTop - borderBottom, clippingNode === document.body ? window.innerHeight : -Infinity),
76
+ height: Math.max(elemRect.height - borderTop - borderBottom, clippingNode === document.body ? window.innerHeight : -Infinity)
77
77
  };
78
78
  }
79
79
  const positionDefaults = {
@@ -81,7 +81,7 @@ const positionDefaults = {
81
81
  align: 'start',
82
82
  anchorOffset: 4,
83
83
  alignmentOffset: 4,
84
- allowOutOfBounds: false,
84
+ allowOutOfBounds: false
85
85
  };
86
86
  function getDefaultSettings(settings = {}) {
87
87
  var _a, _b, _c, _d, _e;
@@ -92,7 +92,7 @@ function getDefaultSettings(settings = {}) {
92
92
  align,
93
93
  anchorOffset: (_c = settings.anchorOffset) !== null && _c !== void 0 ? _c : (side === 'inside-center' ? 0 : positionDefaults.anchorOffset),
94
94
  alignmentOffset: (_d = settings.alignmentOffset) !== null && _d !== void 0 ? _d : (align !== 'center' && side.startsWith('inside') ? positionDefaults.alignmentOffset : 0),
95
- allowOutOfBounds: (_e = settings.allowOutOfBounds) !== null && _e !== void 0 ? _e : positionDefaults.allowOutOfBounds,
95
+ allowOutOfBounds: (_e = settings.allowOutOfBounds) !== null && _e !== void 0 ? _e : positionDefaults.allowOutOfBounds
96
96
  };
97
97
  }
98
98
  function pureCalculateAnchoredPosition(viewportRect, relativePosition, floatingRect, anchorRect, { side, align, allowOutOfBounds, anchorOffset, alignmentOffset }) {
@@ -100,7 +100,7 @@ function pureCalculateAnchoredPosition(viewportRect, relativePosition, floatingR
100
100
  top: viewportRect.top - relativePosition.top,
101
101
  left: viewportRect.left - relativePosition.left,
102
102
  width: viewportRect.width,
103
- height: viewportRect.height,
103
+ height: viewportRect.height
104
104
  };
105
105
  let pos = calculatePosition(floatingRect, anchorRect, side, align, anchorOffset, alignmentOffset);
106
106
  let anchorSide = side;
@@ -2,7 +2,7 @@ export function offset(element) {
2
2
  const rect = element.getBoundingClientRect();
3
3
  return {
4
4
  top: rect.top + window.pageYOffset,
5
- left: rect.left + window.pageXOffset,
5
+ left: rect.left + window.pageXOffset
6
6
  };
7
7
  }
8
8
  export function overflowParent(targetElement) {
@@ -57,11 +57,11 @@ export function overflowOffset(element, targetContainer) {
57
57
  const scroll = container === document.documentElement && document.defaultView
58
58
  ? {
59
59
  top: document.defaultView.pageYOffset,
60
- left: document.defaultView.pageXOffset,
60
+ left: document.defaultView.pageXOffset
61
61
  }
62
62
  : {
63
63
  top: container.scrollTop,
64
- left: container.scrollLeft,
64
+ left: container.scrollLeft
65
65
  };
66
66
  const top = elementOffset.top - scroll.top;
67
67
  const left = elementOffset.left - scroll.left;
@@ -91,7 +91,7 @@ export function focusTrap(container, initialFocus, abortSignal) {
91
91
  container,
92
92
  controller: wrappingController,
93
93
  initialFocus,
94
- originalSignal: signal,
94
+ originalSignal: signal
95
95
  };
96
96
  const suspendedTrapIndex = suspendedTrapStack.findIndex(t => t.container === container);
97
97
  if (suspendedTrapIndex >= 0) {
@@ -38,7 +38,7 @@ const KEY_TO_BIT = {
38
38
  End: FocusKeys.HomeAndEnd,
39
39
  PageUp: FocusKeys.PageUpDown,
40
40
  PageDown: FocusKeys.PageUpDown,
41
- Backspace: FocusKeys.Backspace,
41
+ Backspace: FocusKeys.Backspace
42
42
  };
43
43
  const KEY_TO_DIRECTION = {
44
44
  ArrowLeft: 'previous',
@@ -58,7 +58,7 @@ const KEY_TO_DIRECTION = {
58
58
  End: 'end',
59
59
  PageUp: 'start',
60
60
  PageDown: 'end',
61
- Backspace: 'previous',
61
+ Backspace: 'previous'
62
62
  };
63
63
  function getDirection(keyboardEvent) {
64
64
  const direction = KEY_TO_DIRECTION[keyboardEvent.key];
@@ -262,7 +262,7 @@ export function focusZone(container, settings) {
262
262
  });
263
263
  observer.observe(container, {
264
264
  subtree: true,
265
- childList: true,
265
+ childList: true
266
266
  });
267
267
  const controller = new AbortController();
268
268
  const signal = (_e = settings === null || settings === void 0 ? void 0 : settings.abortSignal) !== null && _e !== void 0 ? _e : controller.signal;
@@ -5,8 +5,8 @@ try {
5
5
  signal: {
6
6
  get() {
7
7
  signalSupported = true;
8
- },
9
- },
8
+ }
9
+ }
10
10
  });
11
11
  window.addEventListener('test', noop, options);
12
12
  window.removeEventListener('test', noop, options);
@@ -3,7 +3,7 @@ export function* iterateFocusableElements(container, options = {}) {
3
3
  const strict = (_a = options.strict) !== null && _a !== void 0 ? _a : false;
4
4
  const acceptFn = ((_b = options.onlyTabbable) !== null && _b !== void 0 ? _b : false) ? isTabbable : isFocusable;
5
5
  const walker = document.createTreeWalker(container, NodeFilter.SHOW_ELEMENT, {
6
- acceptNode: node => node instanceof HTMLElement && acceptFn(node, strict) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP,
6
+ acceptNode: node => node instanceof HTMLElement && acceptFn(node, strict) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP
7
7
  });
8
8
  let nextNode = null;
9
9
  if (!options.reverse && acceptFn(container, strict)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primer/behaviors",
3
- "version": "0.0.0-20230925221012",
3
+ "version": "0.0.0-20230927074223",
4
4
  "description": "Shared behaviors for JavaScript components",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -30,17 +30,17 @@
30
30
  "dist/cjs/focus-trap.js"
31
31
  ],
32
32
  "scripts": {
33
- "lint": "eslint src/",
34
- "test": "npm run jest && npm run lint",
35
- "test:watch": "jest --watch",
36
- "jest": "jest",
37
33
  "clean": "rm -rf dist",
38
- "prebuild": "npm run clean",
39
34
  "build": "npm run build:esm && npm run build:cjs",
40
35
  "build:esm": "tsc",
41
36
  "build:cjs": "tsc --module commonjs --outDir dist/cjs",
37
+ "lint": "eslint src/",
38
+ "test": "jest",
39
+ "test:watch": "jest --watch",
40
+ "prebuild": "npm run clean",
41
+ "release": "npm run build && changeset publish",
42
42
  "size-limit": "npm run build && size-limit",
43
- "release": "npm run build && changeset publish"
43
+ "type-check": "tsc --noEmit"
44
44
  },
45
45
  "repository": {
46
46
  "type": "git",
@@ -68,7 +68,7 @@
68
68
  "devDependencies": {
69
69
  "@changesets/changelog-github": "^0.4.2",
70
70
  "@changesets/cli": "^2.18.1",
71
- "@github/prettier-config": "^0.0.6",
71
+ "@github/prettier-config": "0.0.4",
72
72
  "@size-limit/preset-small-lib": "^8.2.4",
73
73
  "@testing-library/react": "^12.1.2",
74
74
  "@testing-library/user-event": "^13.5.0",
@@ -76,11 +76,10 @@
76
76
  "@types/react": "^17.0.37",
77
77
  "esbuild": "^0.15.16",
78
78
  "esbuild-jest": "^0.5.0",
79
- "eslint": "^8.50.0",
80
- "eslint-plugin-github": "^4.10.0",
81
- "eslint-plugin-prettier": "^5.0.0",
79
+ "eslint": "^8.3.0",
80
+ "eslint-plugin-github": "^4.3.5",
82
81
  "jest": "^27.4.3",
83
- "prettier": "^3.0.3",
82
+ "prettier": "^2.5.0",
84
83
  "react": "^17.0.2",
85
84
  "react-dom": "^17.0.2",
86
85
  "size-limit": "^8.2.4",