@jobber/components 8.23.0 → 8.23.1

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.
Files changed (134) hide show
  1. package/dist/Autocomplete/index.cjs +1 -1
  2. package/dist/Autocomplete/index.mjs +1 -1
  3. package/dist/Card/index.cjs +4 -4
  4. package/dist/Card/index.mjs +4 -4
  5. package/dist/Chip/index.cjs +1 -1
  6. package/dist/Chip/index.mjs +1 -1
  7. package/dist/Chips/InternalChipDismissible/hooks/index.cjs +1 -1
  8. package/dist/Chips/InternalChipDismissible/hooks/index.mjs +1 -1
  9. package/dist/Chips/InternalChipDismissible/index.cjs +1 -1
  10. package/dist/Chips/InternalChipDismissible/index.mjs +1 -1
  11. package/dist/Chips/index.cjs +1 -1
  12. package/dist/Chips/index.mjs +1 -1
  13. package/dist/ComboboxChipRemove-cjs.js +668 -379
  14. package/dist/ComboboxChipRemove-es.js +508 -219
  15. package/dist/ConfirmationModal/index.cjs +1 -1
  16. package/dist/ConfirmationModal/index.mjs +1 -1
  17. package/dist/DataDump/index.cjs +4 -4
  18. package/dist/DataDump/index.mjs +4 -4
  19. package/dist/DataList/components/DataListActions/index.cjs +1 -1
  20. package/dist/DataList/components/DataListActions/index.mjs +1 -1
  21. package/dist/DataList/components/DataListBulkActions/index.cjs +1 -1
  22. package/dist/DataList/components/DataListBulkActions/index.mjs +1 -1
  23. package/dist/DataList/components/DataListFilters/components/DataListSort/index.cjs +1 -1
  24. package/dist/DataList/components/DataListFilters/components/DataListSort/index.mjs +1 -1
  25. package/dist/DataList/components/DataListFilters/index.cjs +1 -1
  26. package/dist/DataList/components/DataListFilters/index.mjs +1 -1
  27. package/dist/DataList/components/DataListHeader/index.cjs +1 -1
  28. package/dist/DataList/components/DataListHeader/index.mjs +1 -1
  29. package/dist/DataList/components/DataListItem/index.cjs +1 -1
  30. package/dist/DataList/components/DataListItem/index.mjs +1 -1
  31. package/dist/DataList/components/DataListItemActions/index.cjs +1 -1
  32. package/dist/DataList/components/DataListItemActions/index.mjs +1 -1
  33. package/dist/DataList/components/DataListItemActionsOverflow/index.cjs +1 -1
  34. package/dist/DataList/components/DataListItemActionsOverflow/index.mjs +1 -1
  35. package/dist/DataList/components/DataListItems/index.cjs +1 -1
  36. package/dist/DataList/components/DataListItems/index.mjs +1 -1
  37. package/dist/DataList/components/DataListLayout/index.cjs +1 -1
  38. package/dist/DataList/components/DataListLayout/index.mjs +1 -1
  39. package/dist/DataList/components/DataListLayoutActions/index.cjs +1 -1
  40. package/dist/DataList/components/DataListLayoutActions/index.mjs +1 -1
  41. package/dist/DataList/index.cjs +1 -1
  42. package/dist/DataList/index.mjs +1 -1
  43. package/dist/DatePicker/index.cjs +1 -1
  44. package/dist/DatePicker/index.mjs +1 -1
  45. package/dist/Dialog/index.cjs +3 -3
  46. package/dist/Dialog/index.mjs +3 -3
  47. package/dist/DrawerDescription-cjs.js +32 -33
  48. package/dist/DrawerDescription-es.js +19 -20
  49. package/dist/DrawerTitle-cjs.js +7 -5
  50. package/dist/DrawerTitle-es.js +7 -5
  51. package/dist/FilterPicker/components/FilterPickerActivator/index.cjs +1 -1
  52. package/dist/FilterPicker/components/FilterPickerActivator/index.mjs +1 -1
  53. package/dist/FilterPicker/components/FilterPickerContent/index.cjs +1 -1
  54. package/dist/FilterPicker/components/FilterPickerContent/index.mjs +1 -1
  55. package/dist/FilterPicker/components/FilterPickerTrigger/index.cjs +1 -1
  56. package/dist/FilterPicker/components/FilterPickerTrigger/index.mjs +1 -1
  57. package/dist/FilterPicker/index.cjs +1 -1
  58. package/dist/FilterPicker/index.mjs +1 -1
  59. package/dist/FormFieldWrapper-cjs.js +2 -2
  60. package/dist/FormFieldWrapper-es.js +2 -2
  61. package/dist/FormatFile/index.cjs +1 -1
  62. package/dist/FormatFile/index.mjs +1 -1
  63. package/dist/Gallery/index.cjs +1 -1
  64. package/dist/Gallery/index.mjs +1 -1
  65. package/dist/InputDate/index.cjs +1 -1
  66. package/dist/InputDate/index.mjs +1 -1
  67. package/dist/InputNumberExperimental-cjs.js +319 -102
  68. package/dist/InputNumberExperimental-es.js +321 -104
  69. package/dist/LightBox/index.cjs +1 -1
  70. package/dist/LightBox/index.mjs +1 -1
  71. package/dist/Menu/index.cjs +4 -4
  72. package/dist/Menu/index.mjs +4 -4
  73. package/dist/MenuSubmenuTrigger-cjs.js +545 -498
  74. package/dist/MenuSubmenuTrigger-es.js +490 -443
  75. package/dist/Modal/index.cjs +1 -1
  76. package/dist/Modal/index.mjs +1 -1
  77. package/dist/NumberFieldInput-cjs.js +609 -496
  78. package/dist/NumberFieldInput-es.js +612 -498
  79. package/dist/Page/index.cjs +4 -4
  80. package/dist/Page/index.mjs +4 -4
  81. package/dist/Popover/index.cjs +1 -1
  82. package/dist/Popover/index.mjs +1 -1
  83. package/dist/ScrollAreaViewport-cjs.js +326 -601
  84. package/dist/ScrollAreaViewport-es.js +278 -548
  85. package/dist/SelectGroupLabel-cjs.js +494 -528
  86. package/dist/SelectGroupLabel-es.js +411 -445
  87. package/dist/Separator-cjs.js +1 -0
  88. package/dist/Separator-es.js +1 -0
  89. package/dist/Tooltip/index.cjs +1 -1
  90. package/dist/Tooltip/index.mjs +1 -1
  91. package/dist/docs/InputTime/InputTime.md +8 -0
  92. package/dist/docs/SelectPrimitive/SelectPrimitive.md +38 -25
  93. package/dist/floating-ui.react-cjs.js +586 -10
  94. package/dist/floating-ui.react-dom-cjs.js +92 -92
  95. package/dist/floating-ui.react-dom-es.js +1 -1
  96. package/dist/floating-ui.react-es.js +580 -4
  97. package/dist/floating-ui.utils-cjs.js +159 -0
  98. package/dist/floating-ui.utils-es.js +136 -0
  99. package/dist/index.cjs +4 -4
  100. package/dist/index.mjs +4 -4
  101. package/dist/{ToolbarRootContext-cjs.js → isElementDisabled-cjs.js} +5 -0
  102. package/dist/{ToolbarRootContext-es.js → isElementDisabled-es.js} +5 -1
  103. package/dist/primitives/BottomSheet/index.cjs +3 -3
  104. package/dist/primitives/BottomSheet/index.mjs +3 -3
  105. package/dist/primitives/ComboboxPrimitive/index.cjs +2 -2
  106. package/dist/primitives/ComboboxPrimitive/index.mjs +2 -2
  107. package/dist/primitives/InputNumberExperimental/index.cjs +1 -1
  108. package/dist/primitives/InputNumberExperimental/index.mjs +1 -1
  109. package/dist/primitives/SelectPrimitive/index.cjs +5 -5
  110. package/dist/primitives/SelectPrimitive/index.mjs +5 -5
  111. package/dist/primitives/index.cjs +4 -4
  112. package/dist/primitives/index.mjs +4 -4
  113. package/dist/resolveAriaLabelledBy-cjs.js +5 -0
  114. package/dist/resolveAriaLabelledBy-es.js +5 -1
  115. package/dist/{CSPContext-cjs.js → scrollEdges-cjs.js} +30 -2
  116. package/dist/{CSPContext-es.js → scrollEdges-es.js} +28 -3
  117. package/dist/styles.css +9 -3
  118. package/dist/unstyledPrimitives/index.cjs +1217 -639
  119. package/dist/unstyledPrimitives/index.mjs +1163 -585
  120. package/dist/useButton-cjs.js +283 -317
  121. package/dist/useButton-es.js +277 -298
  122. package/dist/useCompositeListItem-cjs.js +328 -279
  123. package/dist/useCompositeListItem-es.js +293 -246
  124. package/dist/useLabel-cjs.js +11 -1
  125. package/dist/useLabel-es.js +11 -2
  126. package/dist/useLabelableId-cjs.js +37 -91
  127. package/dist/useLabelableId-es.js +37 -90
  128. package/dist/useRenderElement-cjs.js +81 -26
  129. package/dist/useRenderElement-es.js +81 -27
  130. package/dist/{InternalBackdrop-cjs.js → useScrollLock-cjs.js} +1286 -1220
  131. package/dist/{InternalBackdrop-es.js → useScrollLock-es.js} +1250 -1207
  132. package/package.json +3 -3
  133. package/dist/index.esm-cjs.js +0 -738
  134. package/dist/index.esm-es.js +0 -712
@@ -1,712 +0,0 @@
1
- /**
2
- * Custom positioning reference element.
3
- * @see https://floating-ui.com/docs/virtual-elements
4
- */
5
-
6
- const sides = ['top', 'right', 'bottom', 'left'];
7
- const alignments = ['start', 'end'];
8
- const placements = /*#__PURE__*/sides.reduce((acc, side) => acc.concat(side, side + "-" + alignments[0], side + "-" + alignments[1]), []);
9
- const min = Math.min;
10
- const max = Math.max;
11
- const round = Math.round;
12
- const floor = Math.floor;
13
- const createCoords = v => ({
14
- x: v,
15
- y: v
16
- });
17
- const oppositeSideMap = {
18
- left: 'right',
19
- right: 'left',
20
- bottom: 'top',
21
- top: 'bottom'
22
- };
23
- function clamp(start, value, end) {
24
- return max(start, min(value, end));
25
- }
26
- function evaluate(value, param) {
27
- return typeof value === 'function' ? value(param) : value;
28
- }
29
- function getSide(placement) {
30
- return placement.split('-')[0];
31
- }
32
- function getAlignment(placement) {
33
- return placement.split('-')[1];
34
- }
35
- function getOppositeAxis(axis) {
36
- return axis === 'x' ? 'y' : 'x';
37
- }
38
- function getAxisLength(axis) {
39
- return axis === 'y' ? 'height' : 'width';
40
- }
41
- function getSideAxis(placement) {
42
- const firstChar = placement[0];
43
- return firstChar === 't' || firstChar === 'b' ? 'y' : 'x';
44
- }
45
- function getAlignmentAxis(placement) {
46
- return getOppositeAxis(getSideAxis(placement));
47
- }
48
- function getAlignmentSides(placement, rects, rtl) {
49
- if (rtl === void 0) {
50
- rtl = false;
51
- }
52
- const alignment = getAlignment(placement);
53
- const alignmentAxis = getAlignmentAxis(placement);
54
- const length = getAxisLength(alignmentAxis);
55
- let mainAlignmentSide = alignmentAxis === 'x' ? alignment === (rtl ? 'end' : 'start') ? 'right' : 'left' : alignment === 'start' ? 'bottom' : 'top';
56
- if (rects.reference[length] > rects.floating[length]) {
57
- mainAlignmentSide = getOppositePlacement(mainAlignmentSide);
58
- }
59
- return [mainAlignmentSide, getOppositePlacement(mainAlignmentSide)];
60
- }
61
- function getExpandedPlacements(placement) {
62
- const oppositePlacement = getOppositePlacement(placement);
63
- return [getOppositeAlignmentPlacement(placement), oppositePlacement, getOppositeAlignmentPlacement(oppositePlacement)];
64
- }
65
- function getOppositeAlignmentPlacement(placement) {
66
- return placement.includes('start') ? placement.replace('start', 'end') : placement.replace('end', 'start');
67
- }
68
- const lrPlacement = ['left', 'right'];
69
- const rlPlacement = ['right', 'left'];
70
- const tbPlacement = ['top', 'bottom'];
71
- const btPlacement = ['bottom', 'top'];
72
- function getSideList(side, isStart, rtl) {
73
- switch (side) {
74
- case 'top':
75
- case 'bottom':
76
- if (rtl) return isStart ? rlPlacement : lrPlacement;
77
- return isStart ? lrPlacement : rlPlacement;
78
- case 'left':
79
- case 'right':
80
- return isStart ? tbPlacement : btPlacement;
81
- default:
82
- return [];
83
- }
84
- }
85
- function getOppositeAxisPlacements(placement, flipAlignment, direction, rtl) {
86
- const alignment = getAlignment(placement);
87
- let list = getSideList(getSide(placement), direction === 'start', rtl);
88
- if (alignment) {
89
- list = list.map(side => side + "-" + alignment);
90
- if (flipAlignment) {
91
- list = list.concat(list.map(getOppositeAlignmentPlacement));
92
- }
93
- }
94
- return list;
95
- }
96
- function getOppositePlacement(placement) {
97
- const side = getSide(placement);
98
- return oppositeSideMap[side] + placement.slice(side.length);
99
- }
100
- function expandPaddingObject(padding) {
101
- return {
102
- top: 0,
103
- right: 0,
104
- bottom: 0,
105
- left: 0,
106
- ...padding
107
- };
108
- }
109
- function getPaddingObject(padding) {
110
- return typeof padding !== 'number' ? expandPaddingObject(padding) : {
111
- top: padding,
112
- right: padding,
113
- bottom: padding,
114
- left: padding
115
- };
116
- }
117
- function rectToClientRect(rect) {
118
- const {
119
- x,
120
- y,
121
- width,
122
- height
123
- } = rect;
124
- return {
125
- width,
126
- height,
127
- top: y,
128
- left: x,
129
- right: x + width,
130
- bottom: y + height,
131
- x,
132
- y
133
- };
134
- }
135
-
136
- /*!
137
- * tabbable 6.4.0
138
- * @license MIT, https://github.com/focus-trap/tabbable/blob/master/LICENSE
139
- */
140
- // NOTE: separate `:not()` selectors has broader browser support than the newer
141
- // `:not([inert], [inert] *)` (Feb 2023)
142
- var candidateSelectors = ['input:not([inert]):not([inert] *)', 'select:not([inert]):not([inert] *)', 'textarea:not([inert]):not([inert] *)', 'a[href]:not([inert]):not([inert] *)', 'button:not([inert]):not([inert] *)', '[tabindex]:not(slot):not([inert]):not([inert] *)', 'audio[controls]:not([inert]):not([inert] *)', 'video[controls]:not([inert]):not([inert] *)', '[contenteditable]:not([contenteditable="false"]):not([inert]):not([inert] *)', 'details>summary:first-of-type:not([inert]):not([inert] *)', 'details:not([inert]):not([inert] *)'];
143
- var candidateSelector = /* #__PURE__ */candidateSelectors.join(',');
144
- var NoElement = typeof Element === 'undefined';
145
- var matches = NoElement ? function () {} : Element.prototype.matches || Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector;
146
- var getRootNode = !NoElement && Element.prototype.getRootNode ? function (element) {
147
- var _element$getRootNode;
148
- return element === null || element === void 0 ? void 0 : (_element$getRootNode = element.getRootNode) === null || _element$getRootNode === void 0 ? void 0 : _element$getRootNode.call(element);
149
- } : function (element) {
150
- return element === null || element === void 0 ? void 0 : element.ownerDocument;
151
- };
152
-
153
- /**
154
- * Determines if a node is inert or in an inert ancestor.
155
- * @param {Node} [node]
156
- * @param {boolean} [lookUp] If true and `node` is not inert, looks up at ancestors to
157
- * see if any of them are inert. If false, only `node` itself is considered.
158
- * @returns {boolean} True if inert itself or by way of being in an inert ancestor.
159
- * False if `node` is falsy.
160
- */
161
- var _isInert = function isInert(node, lookUp) {
162
- var _node$getAttribute;
163
- if (lookUp === void 0) {
164
- lookUp = true;
165
- }
166
- // CAREFUL: JSDom does not support inert at all, so we can't use the `HTMLElement.inert`
167
- // JS API property; we have to check the attribute, which can either be empty or 'true';
168
- // if it's `null` (not specified) or 'false', it's an active element
169
- var inertAtt = node === null || node === void 0 ? void 0 : (_node$getAttribute = node.getAttribute) === null || _node$getAttribute === void 0 ? void 0 : _node$getAttribute.call(node, 'inert');
170
- var inert = inertAtt === '' || inertAtt === 'true';
171
-
172
- // NOTE: this could also be handled with `node.matches('[inert], :is([inert] *)')`
173
- // if it weren't for `matches()` not being a function on shadow roots; the following
174
- // code works for any kind of node
175
- var result = inert || lookUp && node && (
176
- // closest does not exist on shadow roots, so we fall back to a manual
177
- // lookup upward, in case it is not defined.
178
- typeof node.closest === 'function' ? node.closest('[inert]') : _isInert(node.parentNode));
179
- return result;
180
- };
181
-
182
- /**
183
- * Determines if a node's content is editable.
184
- * @param {Element} [node]
185
- * @returns True if it's content-editable; false if it's not or `node` is falsy.
186
- */
187
- var isContentEditable = function isContentEditable(node) {
188
- var _node$getAttribute2;
189
- // CAREFUL: JSDom does not support the `HTMLElement.isContentEditable` API so we have
190
- // to use the attribute directly to check for this, which can either be empty or 'true';
191
- // if it's `null` (not specified) or 'false', it's a non-editable element
192
- var attValue = node === null || node === void 0 ? void 0 : (_node$getAttribute2 = node.getAttribute) === null || _node$getAttribute2 === void 0 ? void 0 : _node$getAttribute2.call(node, 'contenteditable');
193
- return attValue === '' || attValue === 'true';
194
- };
195
-
196
- /**
197
- * @param {Element} el container to check in
198
- * @param {boolean} includeContainer add container to check
199
- * @param {(node: Element) => boolean} filter filter candidates
200
- * @returns {Element[]}
201
- */
202
- var getCandidates = function getCandidates(el, includeContainer, filter) {
203
- // even if `includeContainer=false`, we still have to check it for inertness because
204
- // if it's inert (either by itself or via its parent), then all its children are inert
205
- if (_isInert(el)) {
206
- return [];
207
- }
208
- var candidates = Array.prototype.slice.apply(el.querySelectorAll(candidateSelector));
209
- if (includeContainer && matches.call(el, candidateSelector)) {
210
- candidates.unshift(el);
211
- }
212
- candidates = candidates.filter(filter);
213
- return candidates;
214
- };
215
-
216
- /**
217
- * @callback GetShadowRoot
218
- * @param {Element} element to check for shadow root
219
- * @returns {ShadowRoot|boolean} ShadowRoot if available or boolean indicating if a shadowRoot is attached but not available.
220
- */
221
-
222
- /**
223
- * @callback ShadowRootFilter
224
- * @param {Element} shadowHostNode the element which contains shadow content
225
- * @returns {boolean} true if a shadow root could potentially contain valid candidates.
226
- */
227
-
228
- /**
229
- * @typedef {Object} CandidateScope
230
- * @property {Element} scopeParent contains inner candidates
231
- * @property {Element[]} candidates list of candidates found in the scope parent
232
- */
233
-
234
- /**
235
- * @typedef {Object} IterativeOptions
236
- * @property {GetShadowRoot|boolean} getShadowRoot true if shadow support is enabled; falsy if not;
237
- * if a function, implies shadow support is enabled and either returns the shadow root of an element
238
- * or a boolean stating if it has an undisclosed shadow root
239
- * @property {(node: Element) => boolean} filter filter candidates
240
- * @property {boolean} flatten if true then result will flatten any CandidateScope into the returned list
241
- * @property {ShadowRootFilter} shadowRootFilter filter shadow roots;
242
- */
243
-
244
- /**
245
- * @param {Element[]} elements list of element containers to match candidates from
246
- * @param {boolean} includeContainer add container list to check
247
- * @param {IterativeOptions} options
248
- * @returns {Array.<Element|CandidateScope>}
249
- */
250
- var _getCandidatesIteratively = function getCandidatesIteratively(elements, includeContainer, options) {
251
- var candidates = [];
252
- var elementsToCheck = Array.from(elements);
253
- while (elementsToCheck.length) {
254
- var element = elementsToCheck.shift();
255
- if (_isInert(element, false)) {
256
- // no need to look up since we're drilling down
257
- // anything inside this container will also be inert
258
- continue;
259
- }
260
- if (element.tagName === 'SLOT') {
261
- // add shadow dom slot scope (slot itself cannot be focusable)
262
- var assigned = element.assignedElements();
263
- var content = assigned.length ? assigned : element.children;
264
- var nestedCandidates = _getCandidatesIteratively(content, true, options);
265
- if (options.flatten) {
266
- candidates.push.apply(candidates, nestedCandidates);
267
- } else {
268
- candidates.push({
269
- scopeParent: element,
270
- candidates: nestedCandidates
271
- });
272
- }
273
- } else {
274
- // check candidate element
275
- var validCandidate = matches.call(element, candidateSelector);
276
- if (validCandidate && options.filter(element) && (includeContainer || !elements.includes(element))) {
277
- candidates.push(element);
278
- }
279
-
280
- // iterate over shadow content if possible
281
- var shadowRoot = element.shadowRoot ||
282
- // check for an undisclosed shadow
283
- typeof options.getShadowRoot === 'function' && options.getShadowRoot(element);
284
-
285
- // no inert look up because we're already drilling down and checking for inertness
286
- // on the way down, so all containers to this root node should have already been
287
- // vetted as non-inert
288
- var validShadowRoot = !_isInert(shadowRoot, false) && (!options.shadowRootFilter || options.shadowRootFilter(element));
289
- if (shadowRoot && validShadowRoot) {
290
- // add shadow dom scope IIF a shadow root node was given; otherwise, an undisclosed
291
- // shadow exists, so look at light dom children as fallback BUT create a scope for any
292
- // child candidates found because they're likely slotted elements (elements that are
293
- // children of the web component element (which has the shadow), in the light dom, but
294
- // slotted somewhere _inside_ the undisclosed shadow) -- the scope is created below,
295
- // _after_ we return from this recursive call
296
- var _nestedCandidates = _getCandidatesIteratively(shadowRoot === true ? element.children : shadowRoot.children, true, options);
297
- if (options.flatten) {
298
- candidates.push.apply(candidates, _nestedCandidates);
299
- } else {
300
- candidates.push({
301
- scopeParent: element,
302
- candidates: _nestedCandidates
303
- });
304
- }
305
- } else {
306
- // there's not shadow so just dig into the element's (light dom) children
307
- // __without__ giving the element special scope treatment
308
- elementsToCheck.unshift.apply(elementsToCheck, element.children);
309
- }
310
- }
311
- }
312
- return candidates;
313
- };
314
-
315
- /**
316
- * @private
317
- * Determines if the node has an explicitly specified `tabindex` attribute.
318
- * @param {HTMLElement} node
319
- * @returns {boolean} True if so; false if not.
320
- */
321
- var hasTabIndex = function hasTabIndex(node) {
322
- return !isNaN(parseInt(node.getAttribute('tabindex'), 10));
323
- };
324
-
325
- /**
326
- * Determine the tab index of a given node.
327
- * @param {HTMLElement} node
328
- * @returns {number} Tab order (negative, 0, or positive number).
329
- * @throws {Error} If `node` is falsy.
330
- */
331
- var getTabIndex = function getTabIndex(node) {
332
- if (!node) {
333
- throw new Error('No node provided');
334
- }
335
- if (node.tabIndex < 0) {
336
- // in Chrome, <details/>, <audio controls/> and <video controls/> elements get a default
337
- // `tabIndex` of -1 when the 'tabindex' attribute isn't specified in the DOM,
338
- // yet they are still part of the regular tab order; in FF, they get a default
339
- // `tabIndex` of 0; since Chrome still puts those elements in the regular tab
340
- // order, consider their tab index to be 0.
341
- // Also browsers do not return `tabIndex` correctly for contentEditable nodes;
342
- // so if they don't have a tabindex attribute specifically set, assume it's 0.
343
- if ((/^(AUDIO|VIDEO|DETAILS)$/.test(node.tagName) || isContentEditable(node)) && !hasTabIndex(node)) {
344
- return 0;
345
- }
346
- }
347
- return node.tabIndex;
348
- };
349
-
350
- /**
351
- * Determine the tab index of a given node __for sort order purposes__.
352
- * @param {HTMLElement} node
353
- * @param {boolean} [isScope] True for a custom element with shadow root or slot that, by default,
354
- * has tabIndex -1, but needs to be sorted by document order in order for its content to be
355
- * inserted into the correct sort position.
356
- * @returns {number} Tab order (negative, 0, or positive number).
357
- */
358
- var getSortOrderTabIndex = function getSortOrderTabIndex(node, isScope) {
359
- var tabIndex = getTabIndex(node);
360
- if (tabIndex < 0 && isScope && !hasTabIndex(node)) {
361
- return 0;
362
- }
363
- return tabIndex;
364
- };
365
- var sortOrderedTabbables = function sortOrderedTabbables(a, b) {
366
- return a.tabIndex === b.tabIndex ? a.documentOrder - b.documentOrder : a.tabIndex - b.tabIndex;
367
- };
368
- var isInput = function isInput(node) {
369
- return node.tagName === 'INPUT';
370
- };
371
- var isHiddenInput = function isHiddenInput(node) {
372
- return isInput(node) && node.type === 'hidden';
373
- };
374
- var isDetailsWithSummary = function isDetailsWithSummary(node) {
375
- var r = node.tagName === 'DETAILS' && Array.prototype.slice.apply(node.children).some(function (child) {
376
- return child.tagName === 'SUMMARY';
377
- });
378
- return r;
379
- };
380
- var getCheckedRadio = function getCheckedRadio(nodes, form) {
381
- for (var i = 0; i < nodes.length; i++) {
382
- if (nodes[i].checked && nodes[i].form === form) {
383
- return nodes[i];
384
- }
385
- }
386
- };
387
- var isTabbableRadio = function isTabbableRadio(node) {
388
- if (!node.name) {
389
- return true;
390
- }
391
- var radioScope = node.form || getRootNode(node);
392
- var queryRadios = function queryRadios(name) {
393
- return radioScope.querySelectorAll('input[type="radio"][name="' + name + '"]');
394
- };
395
- var radioSet;
396
- if (typeof window !== 'undefined' && typeof window.CSS !== 'undefined' && typeof window.CSS.escape === 'function') {
397
- radioSet = queryRadios(window.CSS.escape(node.name));
398
- } else {
399
- try {
400
- radioSet = queryRadios(node.name);
401
- } catch (err) {
402
- // eslint-disable-next-line no-console
403
- console.error('Looks like you have a radio button with a name attribute containing invalid CSS selector characters and need the CSS.escape polyfill: %s', err.message);
404
- return false;
405
- }
406
- }
407
- var checked = getCheckedRadio(radioSet, node.form);
408
- return !checked || checked === node;
409
- };
410
- var isRadio = function isRadio(node) {
411
- return isInput(node) && node.type === 'radio';
412
- };
413
- var isNonTabbableRadio = function isNonTabbableRadio(node) {
414
- return isRadio(node) && !isTabbableRadio(node);
415
- };
416
-
417
- // determines if a node is ultimately attached to the window's document
418
- var isNodeAttached = function isNodeAttached(node) {
419
- var _nodeRoot;
420
- // The root node is the shadow root if the node is in a shadow DOM; some document otherwise
421
- // (but NOT _the_ document; see second 'If' comment below for more).
422
- // If rootNode is shadow root, it'll have a host, which is the element to which the shadow
423
- // is attached, and the one we need to check if it's in the document or not (because the
424
- // shadow, and all nodes it contains, is never considered in the document since shadows
425
- // behave like self-contained DOMs; but if the shadow's HOST, which is part of the document,
426
- // is hidden, or is not in the document itself but is detached, it will affect the shadow's
427
- // visibility, including all the nodes it contains). The host could be any normal node,
428
- // or a custom element (i.e. web component). Either way, that's the one that is considered
429
- // part of the document, not the shadow root, nor any of its children (i.e. the node being
430
- // tested).
431
- // To further complicate things, we have to look all the way up until we find a shadow HOST
432
- // that is attached (or find none) because the node might be in nested shadows...
433
- // If rootNode is not a shadow root, it won't have a host, and so rootNode should be the
434
- // document (per the docs) and while it's a Document-type object, that document does not
435
- // appear to be the same as the node's `ownerDocument` for some reason, so it's safer
436
- // to ignore the rootNode at this point, and use `node.ownerDocument`. Otherwise,
437
- // using `rootNode.contains(node)` will _always_ be true we'll get false-positives when
438
- // node is actually detached.
439
- // NOTE: If `nodeRootHost` or `node` happens to be the `document` itself (which is possible
440
- // if a tabbable/focusable node was quickly added to the DOM, focused, and then removed
441
- // from the DOM as in https://github.com/focus-trap/focus-trap-react/issues/905), then
442
- // `ownerDocument` will be `null`, hence the optional chaining on it.
443
- var nodeRoot = node && getRootNode(node);
444
- var nodeRootHost = (_nodeRoot = nodeRoot) === null || _nodeRoot === void 0 ? void 0 : _nodeRoot.host;
445
-
446
- // in some cases, a detached node will return itself as the root instead of a document or
447
- // shadow root object, in which case, we shouldn't try to look further up the host chain
448
- var attached = false;
449
- if (nodeRoot && nodeRoot !== node) {
450
- var _nodeRootHost, _nodeRootHost$ownerDo, _node$ownerDocument;
451
- attached = !!((_nodeRootHost = nodeRootHost) !== null && _nodeRootHost !== void 0 && (_nodeRootHost$ownerDo = _nodeRootHost.ownerDocument) !== null && _nodeRootHost$ownerDo !== void 0 && _nodeRootHost$ownerDo.contains(nodeRootHost) || node !== null && node !== void 0 && (_node$ownerDocument = node.ownerDocument) !== null && _node$ownerDocument !== void 0 && _node$ownerDocument.contains(node));
452
- while (!attached && nodeRootHost) {
453
- var _nodeRoot2, _nodeRootHost2, _nodeRootHost2$ownerD;
454
- // since it's not attached and we have a root host, the node MUST be in a nested shadow DOM,
455
- // which means we need to get the host's host and check if that parent host is contained
456
- // in (i.e. attached to) the document
457
- nodeRoot = getRootNode(nodeRootHost);
458
- nodeRootHost = (_nodeRoot2 = nodeRoot) === null || _nodeRoot2 === void 0 ? void 0 : _nodeRoot2.host;
459
- attached = !!((_nodeRootHost2 = nodeRootHost) !== null && _nodeRootHost2 !== void 0 && (_nodeRootHost2$ownerD = _nodeRootHost2.ownerDocument) !== null && _nodeRootHost2$ownerD !== void 0 && _nodeRootHost2$ownerD.contains(nodeRootHost));
460
- }
461
- }
462
- return attached;
463
- };
464
- var isZeroArea = function isZeroArea(node) {
465
- var _node$getBoundingClie = node.getBoundingClientRect(),
466
- width = _node$getBoundingClie.width,
467
- height = _node$getBoundingClie.height;
468
- return width === 0 && height === 0;
469
- };
470
- var isHidden = function isHidden(node, _ref) {
471
- var displayCheck = _ref.displayCheck,
472
- getShadowRoot = _ref.getShadowRoot;
473
- if (displayCheck === 'full-native') {
474
- if ('checkVisibility' in node) {
475
- // Chrome >= 105, Edge >= 105, Firefox >= 106, Safari >= 17.4
476
- // @see https://developer.mozilla.org/en-US/docs/Web/API/Element/checkVisibility#browser_compatibility
477
- var visible = node.checkVisibility({
478
- // Checking opacity might be desirable for some use cases, but natively,
479
- // opacity zero elements _are_ focusable and tabbable.
480
- checkOpacity: false,
481
- opacityProperty: false,
482
- contentVisibilityAuto: true,
483
- visibilityProperty: true,
484
- // This is an alias for `visibilityProperty`. Contemporary browsers
485
- // support both. However, this alias has wider browser support (Chrome
486
- // >= 105 and Firefox >= 106, vs. Chrome >= 121 and Firefox >= 122), so
487
- // we include it anyway.
488
- checkVisibilityCSS: true
489
- });
490
- return !visible;
491
- }
492
- // Fall through to manual visibility checks
493
- }
494
-
495
- // NOTE: visibility will be `undefined` if node is detached from the document
496
- // (see notes about this further down), which means we will consider it visible
497
- // (this is legacy behavior from a very long way back)
498
- // NOTE: we check this regardless of `displayCheck="none"` because this is a
499
- // _visibility_ check, not a _display_ check
500
- if (getComputedStyle(node).visibility === 'hidden') {
501
- return true;
502
- }
503
- var isDirectSummary = matches.call(node, 'details>summary:first-of-type');
504
- var nodeUnderDetails = isDirectSummary ? node.parentElement : node;
505
- if (matches.call(nodeUnderDetails, 'details:not([open]) *')) {
506
- return true;
507
- }
508
- if (!displayCheck || displayCheck === 'full' ||
509
- // full-native can run this branch when it falls through in case
510
- // Element#checkVisibility is unsupported
511
- displayCheck === 'full-native' || displayCheck === 'legacy-full') {
512
- if (typeof getShadowRoot === 'function') {
513
- // figure out if we should consider the node to be in an undisclosed shadow and use the
514
- // 'non-zero-area' fallback
515
- var originalNode = node;
516
- while (node) {
517
- var parentElement = node.parentElement;
518
- var rootNode = getRootNode(node);
519
- if (parentElement && !parentElement.shadowRoot && getShadowRoot(parentElement) === true // check if there's an undisclosed shadow
520
- ) {
521
- // node has an undisclosed shadow which means we can only treat it as a black box, so we
522
- // fall back to a non-zero-area test
523
- return isZeroArea(node);
524
- } else if (node.assignedSlot) {
525
- // iterate up slot
526
- node = node.assignedSlot;
527
- } else if (!parentElement && rootNode !== node.ownerDocument) {
528
- // cross shadow boundary
529
- node = rootNode.host;
530
- } else {
531
- // iterate up normal dom
532
- node = parentElement;
533
- }
534
- }
535
- node = originalNode;
536
- }
537
- // else, `getShadowRoot` might be true, but all that does is enable shadow DOM support
538
- // (i.e. it does not also presume that all nodes might have undisclosed shadows); or
539
- // it might be a falsy value, which means shadow DOM support is disabled
540
-
541
- // Since we didn't find it sitting in an undisclosed shadow (or shadows are disabled)
542
- // now we can just test to see if it would normally be visible or not, provided it's
543
- // attached to the main document.
544
- // NOTE: We must consider case where node is inside a shadow DOM and given directly to
545
- // `isTabbable()` or `isFocusable()` -- regardless of `getShadowRoot` option setting.
546
-
547
- if (isNodeAttached(node)) {
548
- // this works wherever the node is: if there's at least one client rect, it's
549
- // somehow displayed; it also covers the CSS 'display: contents' case where the
550
- // node itself is hidden in place of its contents; and there's no need to search
551
- // up the hierarchy either
552
- return !node.getClientRects().length;
553
- }
554
-
555
- // Else, the node isn't attached to the document, which means the `getClientRects()`
556
- // API will __always__ return zero rects (this can happen, for example, if React
557
- // is used to render nodes onto a detached tree, as confirmed in this thread:
558
- // https://github.com/facebook/react/issues/9117#issuecomment-284228870)
559
- //
560
- // It also means that even window.getComputedStyle(node).display will return `undefined`
561
- // because styles are only computed for nodes that are in the document.
562
- //
563
- // NOTE: THIS HAS BEEN THE CASE FOR YEARS. It is not new, nor is it caused by tabbable
564
- // somehow. Though it was never stated officially, anyone who has ever used tabbable
565
- // APIs on nodes in detached containers has actually implicitly used tabbable in what
566
- // was later (as of v5.2.0 on Apr 9, 2021) called `displayCheck="none"` mode -- essentially
567
- // considering __everything__ to be visible because of the innability to determine styles.
568
- //
569
- // v6.0.0: As of this major release, the default 'full' option __no longer treats detached
570
- // nodes as visible with the 'none' fallback.__
571
- if (displayCheck !== 'legacy-full') {
572
- return true; // hidden
573
- }
574
- // else, fallback to 'none' mode and consider the node visible
575
- } else if (displayCheck === 'non-zero-area') {
576
- // NOTE: Even though this tests that the node's client rect is non-zero to determine
577
- // whether it's displayed, and that a detached node will __always__ have a zero-area
578
- // client rect, we don't special-case for whether the node is attached or not. In
579
- // this mode, we do want to consider nodes that have a zero area to be hidden at all
580
- // times, and that includes attached or not.
581
- return isZeroArea(node);
582
- }
583
-
584
- // visible, as far as we can tell, or per current `displayCheck=none` mode, we assume
585
- // it's visible
586
- return false;
587
- };
588
-
589
- // form fields (nested) inside a disabled fieldset are not focusable/tabbable
590
- // unless they are in the _first_ <legend> element of the top-most disabled
591
- // fieldset
592
- var isDisabledFromFieldset = function isDisabledFromFieldset(node) {
593
- if (/^(INPUT|BUTTON|SELECT|TEXTAREA)$/.test(node.tagName)) {
594
- var parentNode = node.parentElement;
595
- // check if `node` is contained in a disabled <fieldset>
596
- while (parentNode) {
597
- if (parentNode.tagName === 'FIELDSET' && parentNode.disabled) {
598
- // look for the first <legend> among the children of the disabled <fieldset>
599
- for (var i = 0; i < parentNode.children.length; i++) {
600
- var child = parentNode.children.item(i);
601
- // when the first <legend> (in document order) is found
602
- if (child.tagName === 'LEGEND') {
603
- // if its parent <fieldset> is not nested in another disabled <fieldset>,
604
- // return whether `node` is a descendant of its first <legend>
605
- return matches.call(parentNode, 'fieldset[disabled] *') ? true : !child.contains(node);
606
- }
607
- }
608
- // the disabled <fieldset> containing `node` has no <legend>
609
- return true;
610
- }
611
- parentNode = parentNode.parentElement;
612
- }
613
- }
614
-
615
- // else, node's tabbable/focusable state should not be affected by a fieldset's
616
- // enabled/disabled state
617
- return false;
618
- };
619
- var isNodeMatchingSelectorFocusable = function isNodeMatchingSelectorFocusable(options, node) {
620
- if (node.disabled || isHiddenInput(node) || isHidden(node, options) ||
621
- // For a details element with a summary, the summary element gets the focus
622
- isDetailsWithSummary(node) || isDisabledFromFieldset(node)) {
623
- return false;
624
- }
625
- return true;
626
- };
627
- var isNodeMatchingSelectorTabbable = function isNodeMatchingSelectorTabbable(options, node) {
628
- if (isNonTabbableRadio(node) || getTabIndex(node) < 0 || !isNodeMatchingSelectorFocusable(options, node)) {
629
- return false;
630
- }
631
- return true;
632
- };
633
- var isShadowRootTabbable = function isShadowRootTabbable(shadowHostNode) {
634
- var tabIndex = parseInt(shadowHostNode.getAttribute('tabindex'), 10);
635
- if (isNaN(tabIndex) || tabIndex >= 0) {
636
- return true;
637
- }
638
- // If a custom element has an explicit negative tabindex,
639
- // browsers will not allow tab targeting said element's children.
640
- return false;
641
- };
642
-
643
- /**
644
- * @param {Array.<Element|CandidateScope>} candidates
645
- * @returns Element[]
646
- */
647
- var _sortByOrder = function sortByOrder(candidates) {
648
- var regularTabbables = [];
649
- var orderedTabbables = [];
650
- candidates.forEach(function (item, i) {
651
- var isScope = !!item.scopeParent;
652
- var element = isScope ? item.scopeParent : item;
653
- var candidateTabindex = getSortOrderTabIndex(element, isScope);
654
- var elements = isScope ? _sortByOrder(item.candidates) : element;
655
- if (candidateTabindex === 0) {
656
- isScope ? regularTabbables.push.apply(regularTabbables, elements) : regularTabbables.push(element);
657
- } else {
658
- orderedTabbables.push({
659
- documentOrder: i,
660
- tabIndex: candidateTabindex,
661
- item: item,
662
- isScope: isScope,
663
- content: elements
664
- });
665
- }
666
- });
667
- return orderedTabbables.sort(sortOrderedTabbables).reduce(function (acc, sortable) {
668
- sortable.isScope ? acc.push.apply(acc, sortable.content) : acc.push(sortable.content);
669
- return acc;
670
- }, []).concat(regularTabbables);
671
- };
672
- var tabbable = function tabbable(container, options) {
673
- options = options || {};
674
- var candidates;
675
- if (options.getShadowRoot) {
676
- candidates = _getCandidatesIteratively([container], options.includeContainer, {
677
- filter: isNodeMatchingSelectorTabbable.bind(null, options),
678
- flatten: false,
679
- getShadowRoot: options.getShadowRoot,
680
- shadowRootFilter: isShadowRootTabbable
681
- });
682
- } else {
683
- candidates = getCandidates(container, options.includeContainer, isNodeMatchingSelectorTabbable.bind(null, options));
684
- }
685
- return _sortByOrder(candidates);
686
- };
687
- var focusable = function focusable(container, options) {
688
- options = options || {};
689
- var candidates;
690
- if (options.getShadowRoot) {
691
- candidates = _getCandidatesIteratively([container], options.includeContainer, {
692
- filter: isNodeMatchingSelectorFocusable.bind(null, options),
693
- flatten: true,
694
- getShadowRoot: options.getShadowRoot
695
- });
696
- } else {
697
- candidates = getCandidates(container, options.includeContainer, isNodeMatchingSelectorFocusable.bind(null, options));
698
- }
699
- return candidates;
700
- };
701
- var isTabbable = function isTabbable(node, options) {
702
- options = options || {};
703
- if (!node) {
704
- throw new Error('No node provided');
705
- }
706
- if (matches.call(node, candidateSelector) === false) {
707
- return false;
708
- }
709
- return isNodeMatchingSelectorTabbable(options, node);
710
- };
711
-
712
- export { focusable as a, getAlignmentAxis as b, getSide as c, getAlignment as d, evaluate as e, floor as f, getSideAxis as g, getPaddingObject as h, isTabbable as i, getOppositePlacement as j, getExpandedPlacements as k, getOppositeAxisPlacements as l, getAlignmentSides as m, clamp as n, min as o, max as p, getAxisLength as q, rectToClientRect as r, sides as s, tabbable as t, getOppositeAxis as u, placements as v, getOppositeAlignmentPlacement as w, createCoords as x, round as y };