@getflip/swirl-components 0.8.0 → 0.8.2

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.
@@ -3,1148 +3,6 @@ import { c as classnames } from './index-6d2e18c6.js';
3
3
  import { i as isMobileViewport } from './utils-39b2afe8.js';
4
4
  import './_commonjsHelpers-44457d8d.js';
5
5
 
6
- /*!
7
- * tabbable 6.0.1
8
- * @license MIT, https://github.com/focus-trap/tabbable/blob/master/LICENSE
9
- */
10
- var candidateSelectors = ['input', 'select', 'textarea', 'a[href]', 'button', '[tabindex]:not(slot)', 'audio[controls]', 'video[controls]', '[contenteditable]:not([contenteditable="false"])', 'details>summary:first-of-type', 'details'];
11
- var candidateSelector = /* #__PURE__ */candidateSelectors.join(',');
12
- var NoElement = typeof Element === 'undefined';
13
- var matches = NoElement ? function () {} : Element.prototype.matches || Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector;
14
- var getRootNode = !NoElement && Element.prototype.getRootNode ? function (element) {
15
- return element.getRootNode();
16
- } : function (element) {
17
- return element.ownerDocument;
18
- };
19
-
20
- /**
21
- * @param {Element} el container to check in
22
- * @param {boolean} includeContainer add container to check
23
- * @param {(node: Element) => boolean} filter filter candidates
24
- * @returns {Element[]}
25
- */
26
- var getCandidates = function getCandidates(el, includeContainer, filter) {
27
- var candidates = Array.prototype.slice.apply(el.querySelectorAll(candidateSelector));
28
- if (includeContainer && matches.call(el, candidateSelector)) {
29
- candidates.unshift(el);
30
- }
31
- candidates = candidates.filter(filter);
32
- return candidates;
33
- };
34
-
35
- /**
36
- * @callback GetShadowRoot
37
- * @param {Element} element to check for shadow root
38
- * @returns {ShadowRoot|boolean} ShadowRoot if available or boolean indicating if a shadowRoot is attached but not available.
39
- */
40
-
41
- /**
42
- * @callback ShadowRootFilter
43
- * @param {Element} shadowHostNode the element which contains shadow content
44
- * @returns {boolean} true if a shadow root could potentially contain valid candidates.
45
- */
46
-
47
- /**
48
- * @typedef {Object} CandidateScope
49
- * @property {Element} scopeParent contains inner candidates
50
- * @property {Element[]} candidates list of candidates found in the scope parent
51
- */
52
-
53
- /**
54
- * @typedef {Object} IterativeOptions
55
- * @property {GetShadowRoot|boolean} getShadowRoot true if shadow support is enabled; falsy if not;
56
- * if a function, implies shadow support is enabled and either returns the shadow root of an element
57
- * or a boolean stating if it has an undisclosed shadow root
58
- * @property {(node: Element) => boolean} filter filter candidates
59
- * @property {boolean} flatten if true then result will flatten any CandidateScope into the returned list
60
- * @property {ShadowRootFilter} shadowRootFilter filter shadow roots;
61
- */
62
-
63
- /**
64
- * @param {Element[]} elements list of element containers to match candidates from
65
- * @param {boolean} includeContainer add container list to check
66
- * @param {IterativeOptions} options
67
- * @returns {Array.<Element|CandidateScope>}
68
- */
69
- var getCandidatesIteratively = function getCandidatesIteratively(elements, includeContainer, options) {
70
- var candidates = [];
71
- var elementsToCheck = Array.from(elements);
72
- while (elementsToCheck.length) {
73
- var element = elementsToCheck.shift();
74
- if (element.tagName === 'SLOT') {
75
- // add shadow dom slot scope (slot itself cannot be focusable)
76
- var assigned = element.assignedElements();
77
- var content = assigned.length ? assigned : element.children;
78
- var nestedCandidates = getCandidatesIteratively(content, true, options);
79
- if (options.flatten) {
80
- candidates.push.apply(candidates, nestedCandidates);
81
- } else {
82
- candidates.push({
83
- scopeParent: element,
84
- candidates: nestedCandidates
85
- });
86
- }
87
- } else {
88
- // check candidate element
89
- var validCandidate = matches.call(element, candidateSelector);
90
- if (validCandidate && options.filter(element) && (includeContainer || !elements.includes(element))) {
91
- candidates.push(element);
92
- }
93
-
94
- // iterate over shadow content if possible
95
- var shadowRoot = element.shadowRoot ||
96
- // check for an undisclosed shadow
97
- typeof options.getShadowRoot === 'function' && options.getShadowRoot(element);
98
- var validShadowRoot = !options.shadowRootFilter || options.shadowRootFilter(element);
99
- if (shadowRoot && validShadowRoot) {
100
- // add shadow dom scope IIF a shadow root node was given; otherwise, an undisclosed
101
- // shadow exists, so look at light dom children as fallback BUT create a scope for any
102
- // child candidates found because they're likely slotted elements (elements that are
103
- // children of the web component element (which has the shadow), in the light dom, but
104
- // slotted somewhere _inside_ the undisclosed shadow) -- the scope is created below,
105
- // _after_ we return from this recursive call
106
- var _nestedCandidates = getCandidatesIteratively(shadowRoot === true ? element.children : shadowRoot.children, true, options);
107
- if (options.flatten) {
108
- candidates.push.apply(candidates, _nestedCandidates);
109
- } else {
110
- candidates.push({
111
- scopeParent: element,
112
- candidates: _nestedCandidates
113
- });
114
- }
115
- } else {
116
- // there's not shadow so just dig into the element's (light dom) children
117
- // __without__ giving the element special scope treatment
118
- elementsToCheck.unshift.apply(elementsToCheck, element.children);
119
- }
120
- }
121
- }
122
- return candidates;
123
- };
124
- var getTabindex = function getTabindex(node, isScope) {
125
- if (node.tabIndex < 0) {
126
- // in Chrome, <details/>, <audio controls/> and <video controls/> elements get a default
127
- // `tabIndex` of -1 when the 'tabindex' attribute isn't specified in the DOM,
128
- // yet they are still part of the regular tab order; in FF, they get a default
129
- // `tabIndex` of 0; since Chrome still puts those elements in the regular tab
130
- // order, consider their tab index to be 0.
131
- // Also browsers do not return `tabIndex` correctly for contentEditable nodes;
132
- // so if they don't have a tabindex attribute specifically set, assume it's 0.
133
- //
134
- // isScope is positive for custom element with shadow root or slot that by default
135
- // have tabIndex -1, but need to be sorted by document order in order for their
136
- // content to be inserted in the correct position
137
- if ((isScope || /^(AUDIO|VIDEO|DETAILS)$/.test(node.tagName) || node.isContentEditable) && isNaN(parseInt(node.getAttribute('tabindex'), 10))) {
138
- return 0;
139
- }
140
- }
141
- return node.tabIndex;
142
- };
143
- var sortOrderedTabbables = function sortOrderedTabbables(a, b) {
144
- return a.tabIndex === b.tabIndex ? a.documentOrder - b.documentOrder : a.tabIndex - b.tabIndex;
145
- };
146
- var isInput = function isInput(node) {
147
- return node.tagName === 'INPUT';
148
- };
149
- var isHiddenInput = function isHiddenInput(node) {
150
- return isInput(node) && node.type === 'hidden';
151
- };
152
- var isDetailsWithSummary = function isDetailsWithSummary(node) {
153
- var r = node.tagName === 'DETAILS' && Array.prototype.slice.apply(node.children).some(function (child) {
154
- return child.tagName === 'SUMMARY';
155
- });
156
- return r;
157
- };
158
- var getCheckedRadio = function getCheckedRadio(nodes, form) {
159
- for (var i = 0; i < nodes.length; i++) {
160
- if (nodes[i].checked && nodes[i].form === form) {
161
- return nodes[i];
162
- }
163
- }
164
- };
165
- var isTabbableRadio = function isTabbableRadio(node) {
166
- if (!node.name) {
167
- return true;
168
- }
169
- var radioScope = node.form || getRootNode(node);
170
- var queryRadios = function queryRadios(name) {
171
- return radioScope.querySelectorAll('input[type="radio"][name="' + name + '"]');
172
- };
173
- var radioSet;
174
- if (typeof window !== 'undefined' && typeof window.CSS !== 'undefined' && typeof window.CSS.escape === 'function') {
175
- radioSet = queryRadios(window.CSS.escape(node.name));
176
- } else {
177
- try {
178
- radioSet = queryRadios(node.name);
179
- } catch (err) {
180
- // eslint-disable-next-line no-console
181
- 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);
182
- return false;
183
- }
184
- }
185
- var checked = getCheckedRadio(radioSet, node.form);
186
- return !checked || checked === node;
187
- };
188
- var isRadio = function isRadio(node) {
189
- return isInput(node) && node.type === 'radio';
190
- };
191
- var isNonTabbableRadio = function isNonTabbableRadio(node) {
192
- return isRadio(node) && !isTabbableRadio(node);
193
- };
194
-
195
- // determines if a node is ultimately attached to the window's document
196
- var isNodeAttached = function isNodeAttached(node) {
197
- var _nodeRootHost;
198
- // The root node is the shadow root if the node is in a shadow DOM; some document otherwise
199
- // (but NOT _the_ document; see second 'If' comment below for more).
200
- // If rootNode is shadow root, it'll have a host, which is the element to which the shadow
201
- // is attached, and the one we need to check if it's in the document or not (because the
202
- // shadow, and all nodes it contains, is never considered in the document since shadows
203
- // behave like self-contained DOMs; but if the shadow's HOST, which is part of the document,
204
- // is hidden, or is not in the document itself but is detached, it will affect the shadow's
205
- // visibility, including all the nodes it contains). The host could be any normal node,
206
- // or a custom element (i.e. web component). Either way, that's the one that is considered
207
- // part of the document, not the shadow root, nor any of its children (i.e. the node being
208
- // tested).
209
- // To further complicate things, we have to look all the way up until we find a shadow HOST
210
- // that is attached (or find none) because the node might be in nested shadows...
211
- // If rootNode is not a shadow root, it won't have a host, and so rootNode should be the
212
- // document (per the docs) and while it's a Document-type object, that document does not
213
- // appear to be the same as the node's `ownerDocument` for some reason, so it's safer
214
- // to ignore the rootNode at this point, and use `node.ownerDocument`. Otherwise,
215
- // using `rootNode.contains(node)` will _always_ be true we'll get false-positives when
216
- // node is actually detached.
217
- var nodeRootHost = getRootNode(node).host;
218
- var attached = !!((_nodeRootHost = nodeRootHost) !== null && _nodeRootHost !== void 0 && _nodeRootHost.ownerDocument.contains(nodeRootHost) || node.ownerDocument.contains(node));
219
- while (!attached && nodeRootHost) {
220
- var _nodeRootHost2;
221
- // since it's not attached and we have a root host, the node MUST be in a nested shadow DOM,
222
- // which means we need to get the host's host and check if that parent host is contained
223
- // in (i.e. attached to) the document
224
- nodeRootHost = getRootNode(nodeRootHost).host;
225
- attached = !!((_nodeRootHost2 = nodeRootHost) !== null && _nodeRootHost2 !== void 0 && _nodeRootHost2.ownerDocument.contains(nodeRootHost));
226
- }
227
- return attached;
228
- };
229
- var isZeroArea = function isZeroArea(node) {
230
- var _node$getBoundingClie = node.getBoundingClientRect(),
231
- width = _node$getBoundingClie.width,
232
- height = _node$getBoundingClie.height;
233
- return width === 0 && height === 0;
234
- };
235
- var isHidden = function isHidden(node, _ref) {
236
- var displayCheck = _ref.displayCheck,
237
- getShadowRoot = _ref.getShadowRoot;
238
- // NOTE: visibility will be `undefined` if node is detached from the document
239
- // (see notes about this further down), which means we will consider it visible
240
- // (this is legacy behavior from a very long way back)
241
- // NOTE: we check this regardless of `displayCheck="none"` because this is a
242
- // _visibility_ check, not a _display_ check
243
- if (getComputedStyle(node).visibility === 'hidden') {
244
- return true;
245
- }
246
- var isDirectSummary = matches.call(node, 'details>summary:first-of-type');
247
- var nodeUnderDetails = isDirectSummary ? node.parentElement : node;
248
- if (matches.call(nodeUnderDetails, 'details:not([open]) *')) {
249
- return true;
250
- }
251
- if (!displayCheck || displayCheck === 'full' || displayCheck === 'legacy-full') {
252
- if (typeof getShadowRoot === 'function') {
253
- // figure out if we should consider the node to be in an undisclosed shadow and use the
254
- // 'non-zero-area' fallback
255
- var originalNode = node;
256
- while (node) {
257
- var parentElement = node.parentElement;
258
- var rootNode = getRootNode(node);
259
- if (parentElement && !parentElement.shadowRoot && getShadowRoot(parentElement) === true // check if there's an undisclosed shadow
260
- ) {
261
- // node has an undisclosed shadow which means we can only treat it as a black box, so we
262
- // fall back to a non-zero-area test
263
- return isZeroArea(node);
264
- } else if (node.assignedSlot) {
265
- // iterate up slot
266
- node = node.assignedSlot;
267
- } else if (!parentElement && rootNode !== node.ownerDocument) {
268
- // cross shadow boundary
269
- node = rootNode.host;
270
- } else {
271
- // iterate up normal dom
272
- node = parentElement;
273
- }
274
- }
275
- node = originalNode;
276
- }
277
- // else, `getShadowRoot` might be true, but all that does is enable shadow DOM support
278
- // (i.e. it does not also presume that all nodes might have undisclosed shadows); or
279
- // it might be a falsy value, which means shadow DOM support is disabled
280
-
281
- // Since we didn't find it sitting in an undisclosed shadow (or shadows are disabled)
282
- // now we can just test to see if it would normally be visible or not, provided it's
283
- // attached to the main document.
284
- // NOTE: We must consider case where node is inside a shadow DOM and given directly to
285
- // `isTabbable()` or `isFocusable()` -- regardless of `getShadowRoot` option setting.
286
-
287
- if (isNodeAttached(node)) {
288
- // this works wherever the node is: if there's at least one client rect, it's
289
- // somehow displayed; it also covers the CSS 'display: contents' case where the
290
- // node itself is hidden in place of its contents; and there's no need to search
291
- // up the hierarchy either
292
- return !node.getClientRects().length;
293
- }
294
-
295
- // Else, the node isn't attached to the document, which means the `getClientRects()`
296
- // API will __always__ return zero rects (this can happen, for example, if React
297
- // is used to render nodes onto a detached tree, as confirmed in this thread:
298
- // https://github.com/facebook/react/issues/9117#issuecomment-284228870)
299
- //
300
- // It also means that even window.getComputedStyle(node).display will return `undefined`
301
- // because styles are only computed for nodes that are in the document.
302
- //
303
- // NOTE: THIS HAS BEEN THE CASE FOR YEARS. It is not new, nor is it caused by tabbable
304
- // somehow. Though it was never stated officially, anyone who has ever used tabbable
305
- // APIs on nodes in detached containers has actually implicitly used tabbable in what
306
- // was later (as of v5.2.0 on Apr 9, 2021) called `displayCheck="none"` mode -- essentially
307
- // considering __everything__ to be visible because of the innability to determine styles.
308
- //
309
- // v6.0.0: As of this major release, the default 'full' option __no longer treats detached
310
- // nodes as visible with the 'none' fallback.__
311
- if (displayCheck !== 'legacy-full') {
312
- return true; // hidden
313
- }
314
- // else, fallback to 'none' mode and consider the node visible
315
- } else if (displayCheck === 'non-zero-area') {
316
- // NOTE: Even though this tests that the node's client rect is non-zero to determine
317
- // whether it's displayed, and that a detached node will __always__ have a zero-area
318
- // client rect, we don't special-case for whether the node is attached or not. In
319
- // this mode, we do want to consider nodes that have a zero area to be hidden at all
320
- // times, and that includes attached or not.
321
- return isZeroArea(node);
322
- }
323
-
324
- // visible, as far as we can tell, or per current `displayCheck=none` mode, we assume
325
- // it's visible
326
- return false;
327
- };
328
-
329
- // form fields (nested) inside a disabled fieldset are not focusable/tabbable
330
- // unless they are in the _first_ <legend> element of the top-most disabled
331
- // fieldset
332
- var isDisabledFromFieldset = function isDisabledFromFieldset(node) {
333
- if (/^(INPUT|BUTTON|SELECT|TEXTAREA)$/.test(node.tagName)) {
334
- var parentNode = node.parentElement;
335
- // check if `node` is contained in a disabled <fieldset>
336
- while (parentNode) {
337
- if (parentNode.tagName === 'FIELDSET' && parentNode.disabled) {
338
- // look for the first <legend> among the children of the disabled <fieldset>
339
- for (var i = 0; i < parentNode.children.length; i++) {
340
- var child = parentNode.children.item(i);
341
- // when the first <legend> (in document order) is found
342
- if (child.tagName === 'LEGEND') {
343
- // if its parent <fieldset> is not nested in another disabled <fieldset>,
344
- // return whether `node` is a descendant of its first <legend>
345
- return matches.call(parentNode, 'fieldset[disabled] *') ? true : !child.contains(node);
346
- }
347
- }
348
- // the disabled <fieldset> containing `node` has no <legend>
349
- return true;
350
- }
351
- parentNode = parentNode.parentElement;
352
- }
353
- }
354
-
355
- // else, node's tabbable/focusable state should not be affected by a fieldset's
356
- // enabled/disabled state
357
- return false;
358
- };
359
- var isNodeMatchingSelectorFocusable = function isNodeMatchingSelectorFocusable(options, node) {
360
- if (node.disabled || isHiddenInput(node) || isHidden(node, options) ||
361
- // For a details element with a summary, the summary element gets the focus
362
- isDetailsWithSummary(node) || isDisabledFromFieldset(node)) {
363
- return false;
364
- }
365
- return true;
366
- };
367
- var isNodeMatchingSelectorTabbable = function isNodeMatchingSelectorTabbable(options, node) {
368
- if (isNonTabbableRadio(node) || getTabindex(node) < 0 || !isNodeMatchingSelectorFocusable(options, node)) {
369
- return false;
370
- }
371
- return true;
372
- };
373
- var isValidShadowRootTabbable = function isValidShadowRootTabbable(shadowHostNode) {
374
- var tabIndex = parseInt(shadowHostNode.getAttribute('tabindex'), 10);
375
- if (isNaN(tabIndex) || tabIndex >= 0) {
376
- return true;
377
- }
378
- // If a custom element has an explicit negative tabindex,
379
- // browsers will not allow tab targeting said element's children.
380
- return false;
381
- };
382
-
383
- /**
384
- * @param {Array.<Element|CandidateScope>} candidates
385
- * @returns Element[]
386
- */
387
- var sortByOrder = function sortByOrder(candidates) {
388
- var regularTabbables = [];
389
- var orderedTabbables = [];
390
- candidates.forEach(function (item, i) {
391
- var isScope = !!item.scopeParent;
392
- var element = isScope ? item.scopeParent : item;
393
- var candidateTabindex = getTabindex(element, isScope);
394
- var elements = isScope ? sortByOrder(item.candidates) : element;
395
- if (candidateTabindex === 0) {
396
- isScope ? regularTabbables.push.apply(regularTabbables, elements) : regularTabbables.push(element);
397
- } else {
398
- orderedTabbables.push({
399
- documentOrder: i,
400
- tabIndex: candidateTabindex,
401
- item: item,
402
- isScope: isScope,
403
- content: elements
404
- });
405
- }
406
- });
407
- return orderedTabbables.sort(sortOrderedTabbables).reduce(function (acc, sortable) {
408
- sortable.isScope ? acc.push.apply(acc, sortable.content) : acc.push(sortable.content);
409
- return acc;
410
- }, []).concat(regularTabbables);
411
- };
412
- var tabbable = function tabbable(el, options) {
413
- options = options || {};
414
- var candidates;
415
- if (options.getShadowRoot) {
416
- candidates = getCandidatesIteratively([el], options.includeContainer, {
417
- filter: isNodeMatchingSelectorTabbable.bind(null, options),
418
- flatten: false,
419
- getShadowRoot: options.getShadowRoot,
420
- shadowRootFilter: isValidShadowRootTabbable
421
- });
422
- } else {
423
- candidates = getCandidates(el, options.includeContainer, isNodeMatchingSelectorTabbable.bind(null, options));
424
- }
425
- return sortByOrder(candidates);
426
- };
427
- var focusable = function focusable(el, options) {
428
- options = options || {};
429
- var candidates;
430
- if (options.getShadowRoot) {
431
- candidates = getCandidatesIteratively([el], options.includeContainer, {
432
- filter: isNodeMatchingSelectorFocusable.bind(null, options),
433
- flatten: true,
434
- getShadowRoot: options.getShadowRoot
435
- });
436
- } else {
437
- candidates = getCandidates(el, options.includeContainer, isNodeMatchingSelectorFocusable.bind(null, options));
438
- }
439
- return candidates;
440
- };
441
- var isTabbable = function isTabbable(node, options) {
442
- options = options || {};
443
- if (!node) {
444
- throw new Error('No node provided');
445
- }
446
- if (matches.call(node, candidateSelector) === false) {
447
- return false;
448
- }
449
- return isNodeMatchingSelectorTabbable(options, node);
450
- };
451
- var focusableCandidateSelector = /* #__PURE__ */candidateSelectors.concat('iframe').join(',');
452
- var isFocusable = function isFocusable(node, options) {
453
- options = options || {};
454
- if (!node) {
455
- throw new Error('No node provided');
456
- }
457
- if (matches.call(node, focusableCandidateSelector) === false) {
458
- return false;
459
- }
460
- return isNodeMatchingSelectorFocusable(options, node);
461
- };
462
-
463
- /*!
464
- * focus-trap 7.1.0
465
- * @license MIT, https://github.com/focus-trap/focus-trap/blob/master/LICENSE
466
- */
467
-
468
- function ownKeys(object, enumerableOnly) {
469
- var keys = Object.keys(object);
470
- if (Object.getOwnPropertySymbols) {
471
- var symbols = Object.getOwnPropertySymbols(object);
472
- enumerableOnly && (symbols = symbols.filter(function (sym) {
473
- return Object.getOwnPropertyDescriptor(object, sym).enumerable;
474
- })), keys.push.apply(keys, symbols);
475
- }
476
- return keys;
477
- }
478
- function _objectSpread2(target) {
479
- for (var i = 1; i < arguments.length; i++) {
480
- var source = null != arguments[i] ? arguments[i] : {};
481
- i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
482
- _defineProperty(target, key, source[key]);
483
- }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
484
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
485
- });
486
- }
487
- return target;
488
- }
489
- function _defineProperty(obj, key, value) {
490
- if (key in obj) {
491
- Object.defineProperty(obj, key, {
492
- value: value,
493
- enumerable: true,
494
- configurable: true,
495
- writable: true
496
- });
497
- } else {
498
- obj[key] = value;
499
- }
500
- return obj;
501
- }
502
-
503
- var rooTrapStack = [];
504
- var activeFocusTraps = {
505
- activateTrap: function activateTrap(trapStack, trap) {
506
- if (trapStack.length > 0) {
507
- var activeTrap = trapStack[trapStack.length - 1];
508
- if (activeTrap !== trap) {
509
- activeTrap.pause();
510
- }
511
- }
512
- var trapIndex = trapStack.indexOf(trap);
513
- if (trapIndex === -1) {
514
- trapStack.push(trap);
515
- } else {
516
- // move this existing trap to the front of the queue
517
- trapStack.splice(trapIndex, 1);
518
- trapStack.push(trap);
519
- }
520
- },
521
- deactivateTrap: function deactivateTrap(trapStack, trap) {
522
- var trapIndex = trapStack.indexOf(trap);
523
- if (trapIndex !== -1) {
524
- trapStack.splice(trapIndex, 1);
525
- }
526
- if (trapStack.length > 0) {
527
- trapStack[trapStack.length - 1].unpause();
528
- }
529
- }
530
- };
531
- var isSelectableInput = function isSelectableInput(node) {
532
- return node.tagName && node.tagName.toLowerCase() === 'input' && typeof node.select === 'function';
533
- };
534
- var isEscapeEvent = function isEscapeEvent(e) {
535
- return e.key === 'Escape' || e.key === 'Esc' || e.keyCode === 27;
536
- };
537
- var isTabEvent = function isTabEvent(e) {
538
- return e.key === 'Tab' || e.keyCode === 9;
539
- };
540
- var delay = function delay(fn) {
541
- return setTimeout(fn, 0);
542
- };
543
-
544
- // Array.find/findIndex() are not supported on IE; this replicates enough
545
- // of Array.findIndex() for our needs
546
- var findIndex = function findIndex(arr, fn) {
547
- var idx = -1;
548
- arr.every(function (value, i) {
549
- if (fn(value)) {
550
- idx = i;
551
- return false; // break
552
- }
553
-
554
- return true; // next
555
- });
556
-
557
- return idx;
558
- };
559
-
560
- /**
561
- * Get an option's value when it could be a plain value, or a handler that provides
562
- * the value.
563
- * @param {*} value Option's value to check.
564
- * @param {...*} [params] Any parameters to pass to the handler, if `value` is a function.
565
- * @returns {*} The `value`, or the handler's returned value.
566
- */
567
- var valueOrHandler = function valueOrHandler(value) {
568
- for (var _len = arguments.length, params = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
569
- params[_key - 1] = arguments[_key];
570
- }
571
- return typeof value === 'function' ? value.apply(void 0, params) : value;
572
- };
573
- var getActualTarget = function getActualTarget(event) {
574
- // NOTE: If the trap is _inside_ a shadow DOM, event.target will always be the
575
- // shadow host. However, event.target.composedPath() will be an array of
576
- // nodes "clicked" from inner-most (the actual element inside the shadow) to
577
- // outer-most (the host HTML document). If we have access to composedPath(),
578
- // then use its first element; otherwise, fall back to event.target (and
579
- // this only works for an _open_ shadow DOM; otherwise,
580
- // composedPath()[0] === event.target always).
581
- return event.target.shadowRoot && typeof event.composedPath === 'function' ? event.composedPath()[0] : event.target;
582
- };
583
- var createFocusTrap = function createFocusTrap(elements, userOptions) {
584
- // SSR: a live trap shouldn't be created in this type of environment so this
585
- // should be safe code to execute if the `document` option isn't specified
586
- var doc = (userOptions === null || userOptions === void 0 ? void 0 : userOptions.document) || document;
587
- var trapStack = (userOptions === null || userOptions === void 0 ? void 0 : userOptions.trapStack) || rooTrapStack;
588
- var config = _objectSpread2({
589
- returnFocusOnDeactivate: true,
590
- escapeDeactivates: true,
591
- delayInitialFocus: true
592
- }, userOptions);
593
- var state = {
594
- // containers given to createFocusTrap()
595
- // @type {Array<HTMLElement>}
596
- containers: [],
597
- // list of objects identifying tabbable nodes in `containers` in the trap
598
- // NOTE: it's possible that a group has no tabbable nodes if nodes get removed while the trap
599
- // is active, but the trap should never get to a state where there isn't at least one group
600
- // with at least one tabbable node in it (that would lead to an error condition that would
601
- // result in an error being thrown)
602
- // @type {Array<{
603
- // container: HTMLElement,
604
- // tabbableNodes: Array<HTMLElement>, // empty if none
605
- // focusableNodes: Array<HTMLElement>, // empty if none
606
- // firstTabbableNode: HTMLElement|null,
607
- // lastTabbableNode: HTMLElement|null,
608
- // nextTabbableNode: (node: HTMLElement, forward: boolean) => HTMLElement|undefined
609
- // }>}
610
- containerGroups: [],
611
- // same order/length as `containers` list
612
-
613
- // references to objects in `containerGroups`, but only those that actually have
614
- // tabbable nodes in them
615
- // NOTE: same order as `containers` and `containerGroups`, but __not necessarily__
616
- // the same length
617
- tabbableGroups: [],
618
- nodeFocusedBeforeActivation: null,
619
- mostRecentlyFocusedNode: null,
620
- active: false,
621
- paused: false,
622
- // timer ID for when delayInitialFocus is true and initial focus in this trap
623
- // has been delayed during activation
624
- delayInitialFocusTimer: undefined
625
- };
626
- var trap; // eslint-disable-line prefer-const -- some private functions reference it, and its methods reference private functions, so we must declare here and define later
627
-
628
- /**
629
- * Gets a configuration option value.
630
- * @param {Object|undefined} configOverrideOptions If true, and option is defined in this set,
631
- * value will be taken from this object. Otherwise, value will be taken from base configuration.
632
- * @param {string} optionName Name of the option whose value is sought.
633
- * @param {string|undefined} [configOptionName] Name of option to use __instead of__ `optionName`
634
- * IIF `configOverrideOptions` is not defined. Otherwise, `optionName` is used.
635
- */
636
- var getOption = function getOption(configOverrideOptions, optionName, configOptionName) {
637
- return configOverrideOptions && configOverrideOptions[optionName] !== undefined ? configOverrideOptions[optionName] : config[configOptionName || optionName];
638
- };
639
-
640
- /**
641
- * Finds the index of the container that contains the element.
642
- * @param {HTMLElement} element
643
- * @returns {number} Index of the container in either `state.containers` or
644
- * `state.containerGroups` (the order/length of these lists are the same); -1
645
- * if the element isn't found.
646
- */
647
- var findContainerIndex = function findContainerIndex(element) {
648
- // NOTE: search `containerGroups` because it's possible a group contains no tabbable
649
- // nodes, but still contains focusable nodes (e.g. if they all have `tabindex=-1`)
650
- // and we still need to find the element in there
651
- return state.containerGroups.findIndex(function (_ref) {
652
- var container = _ref.container,
653
- tabbableNodes = _ref.tabbableNodes;
654
- return container.contains(element) ||
655
- // fall back to explicit tabbable search which will take into consideration any
656
- // web components if the `tabbableOptions.getShadowRoot` option was used for
657
- // the trap, enabling shadow DOM support in tabbable (`Node.contains()` doesn't
658
- // look inside web components even if open)
659
- tabbableNodes.find(function (node) {
660
- return node === element;
661
- });
662
- });
663
- };
664
-
665
- /**
666
- * Gets the node for the given option, which is expected to be an option that
667
- * can be either a DOM node, a string that is a selector to get a node, `false`
668
- * (if a node is explicitly NOT given), or a function that returns any of these
669
- * values.
670
- * @param {string} optionName
671
- * @returns {undefined | false | HTMLElement | SVGElement} Returns
672
- * `undefined` if the option is not specified; `false` if the option
673
- * resolved to `false` (node explicitly not given); otherwise, the resolved
674
- * DOM node.
675
- * @throws {Error} If the option is set, not `false`, and is not, or does not
676
- * resolve to a node.
677
- */
678
- var getNodeForOption = function getNodeForOption(optionName) {
679
- var optionValue = config[optionName];
680
- if (typeof optionValue === 'function') {
681
- for (var _len2 = arguments.length, params = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
682
- params[_key2 - 1] = arguments[_key2];
683
- }
684
- optionValue = optionValue.apply(void 0, params);
685
- }
686
- if (optionValue === true) {
687
- optionValue = undefined; // use default value
688
- }
689
-
690
- if (!optionValue) {
691
- if (optionValue === undefined || optionValue === false) {
692
- return optionValue;
693
- }
694
- // else, empty string (invalid), null (invalid), 0 (invalid)
695
-
696
- throw new Error("`".concat(optionName, "` was specified but was not a node, or did not return a node"));
697
- }
698
- var node = optionValue; // could be HTMLElement, SVGElement, or non-empty string at this point
699
-
700
- if (typeof optionValue === 'string') {
701
- node = doc.querySelector(optionValue); // resolve to node, or null if fails
702
- if (!node) {
703
- throw new Error("`".concat(optionName, "` as selector refers to no known node"));
704
- }
705
- }
706
- return node;
707
- };
708
- var getInitialFocusNode = function getInitialFocusNode() {
709
- var node = getNodeForOption('initialFocus');
710
-
711
- // false explicitly indicates we want no initialFocus at all
712
- if (node === false) {
713
- return false;
714
- }
715
- if (node === undefined) {
716
- // option not specified: use fallback options
717
- if (findContainerIndex(doc.activeElement) >= 0) {
718
- node = doc.activeElement;
719
- } else {
720
- var firstTabbableGroup = state.tabbableGroups[0];
721
- var firstTabbableNode = firstTabbableGroup && firstTabbableGroup.firstTabbableNode;
722
-
723
- // NOTE: `fallbackFocus` option function cannot return `false` (not supported)
724
- node = firstTabbableNode || getNodeForOption('fallbackFocus');
725
- }
726
- }
727
- if (!node) {
728
- throw new Error('Your focus-trap needs to have at least one focusable element');
729
- }
730
- return node;
731
- };
732
- var updateTabbableNodes = function updateTabbableNodes() {
733
- state.containerGroups = state.containers.map(function (container) {
734
- var tabbableNodes = tabbable(container, config.tabbableOptions);
735
-
736
- // NOTE: if we have tabbable nodes, we must have focusable nodes; focusable nodes
737
- // are a superset of tabbable nodes
738
- var focusableNodes = focusable(container, config.tabbableOptions);
739
- return {
740
- container: container,
741
- tabbableNodes: tabbableNodes,
742
- focusableNodes: focusableNodes,
743
- firstTabbableNode: tabbableNodes.length > 0 ? tabbableNodes[0] : null,
744
- lastTabbableNode: tabbableNodes.length > 0 ? tabbableNodes[tabbableNodes.length - 1] : null,
745
- /**
746
- * Finds the __tabbable__ node that follows the given node in the specified direction,
747
- * in this container, if any.
748
- * @param {HTMLElement} node
749
- * @param {boolean} [forward] True if going in forward tab order; false if going
750
- * in reverse.
751
- * @returns {HTMLElement|undefined} The next tabbable node, if any.
752
- */
753
- nextTabbableNode: function nextTabbableNode(node) {
754
- var forward = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
755
- // NOTE: If tabindex is positive (in order to manipulate the tab order separate
756
- // from the DOM order), this __will not work__ because the list of focusableNodes,
757
- // while it contains tabbable nodes, does not sort its nodes in any order other
758
- // than DOM order, because it can't: Where would you place focusable (but not
759
- // tabbable) nodes in that order? They have no order, because they aren't tabbale...
760
- // Support for positive tabindex is already broken and hard to manage (possibly
761
- // not supportable, TBD), so this isn't going to make things worse than they
762
- // already are, and at least makes things better for the majority of cases where
763
- // tabindex is either 0/unset or negative.
764
- // FYI, positive tabindex issue: https://github.com/focus-trap/focus-trap/issues/375
765
- var nodeIdx = focusableNodes.findIndex(function (n) {
766
- return n === node;
767
- });
768
- if (nodeIdx < 0) {
769
- return undefined;
770
- }
771
- if (forward) {
772
- return focusableNodes.slice(nodeIdx + 1).find(function (n) {
773
- return isTabbable(n, config.tabbableOptions);
774
- });
775
- }
776
- return focusableNodes.slice(0, nodeIdx).reverse().find(function (n) {
777
- return isTabbable(n, config.tabbableOptions);
778
- });
779
- }
780
- };
781
- });
782
- state.tabbableGroups = state.containerGroups.filter(function (group) {
783
- return group.tabbableNodes.length > 0;
784
- });
785
-
786
- // throw if no groups have tabbable nodes and we don't have a fallback focus node either
787
- if (state.tabbableGroups.length <= 0 && !getNodeForOption('fallbackFocus') // returning false not supported for this option
788
- ) {
789
- throw new Error('Your focus-trap must have at least one container with at least one tabbable node in it at all times');
790
- }
791
- };
792
- var tryFocus = function tryFocus(node) {
793
- if (node === false) {
794
- return;
795
- }
796
- if (node === doc.activeElement) {
797
- return;
798
- }
799
- if (!node || !node.focus) {
800
- tryFocus(getInitialFocusNode());
801
- return;
802
- }
803
- node.focus({
804
- preventScroll: !!config.preventScroll
805
- });
806
- state.mostRecentlyFocusedNode = node;
807
- if (isSelectableInput(node)) {
808
- node.select();
809
- }
810
- };
811
- var getReturnFocusNode = function getReturnFocusNode(previousActiveElement) {
812
- var node = getNodeForOption('setReturnFocus', previousActiveElement);
813
- return node ? node : node === false ? false : previousActiveElement;
814
- };
815
-
816
- // This needs to be done on mousedown and touchstart instead of click
817
- // so that it precedes the focus event.
818
- var checkPointerDown = function checkPointerDown(e) {
819
- var target = getActualTarget(e);
820
- if (findContainerIndex(target) >= 0) {
821
- // allow the click since it ocurred inside the trap
822
- return;
823
- }
824
- if (valueOrHandler(config.clickOutsideDeactivates, e)) {
825
- // immediately deactivate the trap
826
- trap.deactivate({
827
- // if, on deactivation, we should return focus to the node originally-focused
828
- // when the trap was activated (or the configured `setReturnFocus` node),
829
- // then assume it's also OK to return focus to the outside node that was
830
- // just clicked, causing deactivation, as long as that node is focusable;
831
- // if it isn't focusable, then return focus to the original node focused
832
- // on activation (or the configured `setReturnFocus` node)
833
- // NOTE: by setting `returnFocus: false`, deactivate() will do nothing,
834
- // which will result in the outside click setting focus to the node
835
- // that was clicked, whether it's focusable or not; by setting
836
- // `returnFocus: true`, we'll attempt to re-focus the node originally-focused
837
- // on activation (or the configured `setReturnFocus` node)
838
- returnFocus: config.returnFocusOnDeactivate && !isFocusable(target, config.tabbableOptions)
839
- });
840
- return;
841
- }
842
-
843
- // This is needed for mobile devices.
844
- // (If we'll only let `click` events through,
845
- // then on mobile they will be blocked anyways if `touchstart` is blocked.)
846
- if (valueOrHandler(config.allowOutsideClick, e)) {
847
- // allow the click outside the trap to take place
848
- return;
849
- }
850
-
851
- // otherwise, prevent the click
852
- e.preventDefault();
853
- };
854
-
855
- // In case focus escapes the trap for some strange reason, pull it back in.
856
- var checkFocusIn = function checkFocusIn(e) {
857
- var target = getActualTarget(e);
858
- var targetContained = findContainerIndex(target) >= 0;
859
-
860
- // In Firefox when you Tab out of an iframe the Document is briefly focused.
861
- if (targetContained || target instanceof Document) {
862
- if (targetContained) {
863
- state.mostRecentlyFocusedNode = target;
864
- }
865
- } else {
866
- // escaped! pull it back in to where it just left
867
- e.stopImmediatePropagation();
868
- tryFocus(state.mostRecentlyFocusedNode || getInitialFocusNode());
869
- }
870
- };
871
-
872
- // Hijack Tab events on the first and last focusable nodes of the trap,
873
- // in order to prevent focus from escaping. If it escapes for even a
874
- // moment it can end up scrolling the page and causing confusion so we
875
- // kind of need to capture the action at the keydown phase.
876
- var checkTab = function checkTab(e) {
877
- var target = getActualTarget(e);
878
- updateTabbableNodes();
879
- var destinationNode = null;
880
- if (state.tabbableGroups.length > 0) {
881
- // make sure the target is actually contained in a group
882
- // NOTE: the target may also be the container itself if it's focusable
883
- // with tabIndex='-1' and was given initial focus
884
- var containerIndex = findContainerIndex(target);
885
- var containerGroup = containerIndex >= 0 ? state.containerGroups[containerIndex] : undefined;
886
- if (containerIndex < 0) {
887
- // target not found in any group: quite possible focus has escaped the trap,
888
- // so bring it back in to...
889
- if (e.shiftKey) {
890
- // ...the last node in the last group
891
- destinationNode = state.tabbableGroups[state.tabbableGroups.length - 1].lastTabbableNode;
892
- } else {
893
- // ...the first node in the first group
894
- destinationNode = state.tabbableGroups[0].firstTabbableNode;
895
- }
896
- } else if (e.shiftKey) {
897
- // REVERSE
898
-
899
- // is the target the first tabbable node in a group?
900
- var startOfGroupIndex = findIndex(state.tabbableGroups, function (_ref2) {
901
- var firstTabbableNode = _ref2.firstTabbableNode;
902
- return target === firstTabbableNode;
903
- });
904
- if (startOfGroupIndex < 0 && (containerGroup.container === target || isFocusable(target, config.tabbableOptions) && !isTabbable(target, config.tabbableOptions) && !containerGroup.nextTabbableNode(target, false))) {
905
- // an exception case where the target is either the container itself, or
906
- // a non-tabbable node that was given focus (i.e. tabindex is negative
907
- // and user clicked on it or node was programmatically given focus)
908
- // and is not followed by any other tabbable node, in which
909
- // case, we should handle shift+tab as if focus were on the container's
910
- // first tabbable node, and go to the last tabbable node of the LAST group
911
- startOfGroupIndex = containerIndex;
912
- }
913
- if (startOfGroupIndex >= 0) {
914
- // YES: then shift+tab should go to the last tabbable node in the
915
- // previous group (and wrap around to the last tabbable node of
916
- // the LAST group if it's the first tabbable node of the FIRST group)
917
- var destinationGroupIndex = startOfGroupIndex === 0 ? state.tabbableGroups.length - 1 : startOfGroupIndex - 1;
918
- var destinationGroup = state.tabbableGroups[destinationGroupIndex];
919
- destinationNode = destinationGroup.lastTabbableNode;
920
- }
921
- } else {
922
- // FORWARD
923
-
924
- // is the target the last tabbable node in a group?
925
- var lastOfGroupIndex = findIndex(state.tabbableGroups, function (_ref3) {
926
- var lastTabbableNode = _ref3.lastTabbableNode;
927
- return target === lastTabbableNode;
928
- });
929
- if (lastOfGroupIndex < 0 && (containerGroup.container === target || isFocusable(target, config.tabbableOptions) && !isTabbable(target, config.tabbableOptions) && !containerGroup.nextTabbableNode(target))) {
930
- // an exception case where the target is the container itself, or
931
- // a non-tabbable node that was given focus (i.e. tabindex is negative
932
- // and user clicked on it or node was programmatically given focus)
933
- // and is not followed by any other tabbable node, in which
934
- // case, we should handle tab as if focus were on the container's
935
- // last tabbable node, and go to the first tabbable node of the FIRST group
936
- lastOfGroupIndex = containerIndex;
937
- }
938
- if (lastOfGroupIndex >= 0) {
939
- // YES: then tab should go to the first tabbable node in the next
940
- // group (and wrap around to the first tabbable node of the FIRST
941
- // group if it's the last tabbable node of the LAST group)
942
- var _destinationGroupIndex = lastOfGroupIndex === state.tabbableGroups.length - 1 ? 0 : lastOfGroupIndex + 1;
943
- var _destinationGroup = state.tabbableGroups[_destinationGroupIndex];
944
- destinationNode = _destinationGroup.firstTabbableNode;
945
- }
946
- }
947
- } else {
948
- // NOTE: the fallbackFocus option does not support returning false to opt-out
949
- destinationNode = getNodeForOption('fallbackFocus');
950
- }
951
- if (destinationNode) {
952
- e.preventDefault();
953
- tryFocus(destinationNode);
954
- }
955
- // else, let the browser take care of [shift+]tab and move the focus
956
- };
957
-
958
- var checkKey = function checkKey(e) {
959
- if (isEscapeEvent(e) && valueOrHandler(config.escapeDeactivates, e) !== false) {
960
- e.preventDefault();
961
- trap.deactivate();
962
- return;
963
- }
964
- if (isTabEvent(e)) {
965
- checkTab(e);
966
- return;
967
- }
968
- };
969
- var checkClick = function checkClick(e) {
970
- var target = getActualTarget(e);
971
- if (findContainerIndex(target) >= 0) {
972
- return;
973
- }
974
- if (valueOrHandler(config.clickOutsideDeactivates, e)) {
975
- return;
976
- }
977
- if (valueOrHandler(config.allowOutsideClick, e)) {
978
- return;
979
- }
980
- e.preventDefault();
981
- e.stopImmediatePropagation();
982
- };
983
-
984
- //
985
- // EVENT LISTENERS
986
- //
987
-
988
- var addListeners = function addListeners() {
989
- if (!state.active) {
990
- return;
991
- }
992
-
993
- // There can be only one listening focus trap at a time
994
- activeFocusTraps.activateTrap(trapStack, trap);
995
-
996
- // Delay ensures that the focused element doesn't capture the event
997
- // that caused the focus trap activation.
998
- state.delayInitialFocusTimer = config.delayInitialFocus ? delay(function () {
999
- tryFocus(getInitialFocusNode());
1000
- }) : tryFocus(getInitialFocusNode());
1001
- doc.addEventListener('focusin', checkFocusIn, true);
1002
- doc.addEventListener('mousedown', checkPointerDown, {
1003
- capture: true,
1004
- passive: false
1005
- });
1006
- doc.addEventListener('touchstart', checkPointerDown, {
1007
- capture: true,
1008
- passive: false
1009
- });
1010
- doc.addEventListener('click', checkClick, {
1011
- capture: true,
1012
- passive: false
1013
- });
1014
- doc.addEventListener('keydown', checkKey, {
1015
- capture: true,
1016
- passive: false
1017
- });
1018
- return trap;
1019
- };
1020
- var removeListeners = function removeListeners() {
1021
- if (!state.active) {
1022
- return;
1023
- }
1024
- doc.removeEventListener('focusin', checkFocusIn, true);
1025
- doc.removeEventListener('mousedown', checkPointerDown, true);
1026
- doc.removeEventListener('touchstart', checkPointerDown, true);
1027
- doc.removeEventListener('click', checkClick, true);
1028
- doc.removeEventListener('keydown', checkKey, true);
1029
- return trap;
1030
- };
1031
-
1032
- //
1033
- // TRAP DEFINITION
1034
- //
1035
-
1036
- trap = {
1037
- get active() {
1038
- return state.active;
1039
- },
1040
- get paused() {
1041
- return state.paused;
1042
- },
1043
- activate: function activate(activateOptions) {
1044
- if (state.active) {
1045
- return this;
1046
- }
1047
- var onActivate = getOption(activateOptions, 'onActivate');
1048
- var onPostActivate = getOption(activateOptions, 'onPostActivate');
1049
- var checkCanFocusTrap = getOption(activateOptions, 'checkCanFocusTrap');
1050
- if (!checkCanFocusTrap) {
1051
- updateTabbableNodes();
1052
- }
1053
- state.active = true;
1054
- state.paused = false;
1055
- state.nodeFocusedBeforeActivation = doc.activeElement;
1056
- if (onActivate) {
1057
- onActivate();
1058
- }
1059
- var finishActivation = function finishActivation() {
1060
- if (checkCanFocusTrap) {
1061
- updateTabbableNodes();
1062
- }
1063
- addListeners();
1064
- if (onPostActivate) {
1065
- onPostActivate();
1066
- }
1067
- };
1068
- if (checkCanFocusTrap) {
1069
- checkCanFocusTrap(state.containers.concat()).then(finishActivation, finishActivation);
1070
- return this;
1071
- }
1072
- finishActivation();
1073
- return this;
1074
- },
1075
- deactivate: function deactivate(deactivateOptions) {
1076
- if (!state.active) {
1077
- return this;
1078
- }
1079
- var options = _objectSpread2({
1080
- onDeactivate: config.onDeactivate,
1081
- onPostDeactivate: config.onPostDeactivate,
1082
- checkCanReturnFocus: config.checkCanReturnFocus
1083
- }, deactivateOptions);
1084
- clearTimeout(state.delayInitialFocusTimer); // noop if undefined
1085
- state.delayInitialFocusTimer = undefined;
1086
- removeListeners();
1087
- state.active = false;
1088
- state.paused = false;
1089
- activeFocusTraps.deactivateTrap(trapStack, trap);
1090
- var onDeactivate = getOption(options, 'onDeactivate');
1091
- var onPostDeactivate = getOption(options, 'onPostDeactivate');
1092
- var checkCanReturnFocus = getOption(options, 'checkCanReturnFocus');
1093
- var returnFocus = getOption(options, 'returnFocus', 'returnFocusOnDeactivate');
1094
- if (onDeactivate) {
1095
- onDeactivate();
1096
- }
1097
- var finishDeactivation = function finishDeactivation() {
1098
- delay(function () {
1099
- if (returnFocus) {
1100
- tryFocus(getReturnFocusNode(state.nodeFocusedBeforeActivation));
1101
- }
1102
- if (onPostDeactivate) {
1103
- onPostDeactivate();
1104
- }
1105
- });
1106
- };
1107
- if (returnFocus && checkCanReturnFocus) {
1108
- checkCanReturnFocus(getReturnFocusNode(state.nodeFocusedBeforeActivation)).then(finishDeactivation, finishDeactivation);
1109
- return this;
1110
- }
1111
- finishDeactivation();
1112
- return this;
1113
- },
1114
- pause: function pause() {
1115
- if (state.paused || !state.active) {
1116
- return this;
1117
- }
1118
- state.paused = true;
1119
- removeListeners();
1120
- return this;
1121
- },
1122
- unpause: function unpause() {
1123
- if (!state.paused || !state.active) {
1124
- return this;
1125
- }
1126
- state.paused = false;
1127
- updateTabbableNodes();
1128
- addListeners();
1129
- return this;
1130
- },
1131
- updateContainerElements: function updateContainerElements(containerElements) {
1132
- var elementsAsArray = [].concat(containerElements).filter(Boolean);
1133
- state.containers = elementsAsArray.map(function (element) {
1134
- return typeof element === 'string' ? doc.querySelector(element) : element;
1135
- });
1136
- if (state.active) {
1137
- updateTabbableNodes();
1138
- }
1139
- return this;
1140
- }
1141
- };
1142
-
1143
- // initialize container elements
1144
- trap.updateContainerElements(elements);
1145
- return trap;
1146
- };
1147
-
1148
6
  const flipConsoleLayoutCss = ":host{display:block;width:100%;height:100vh}:host *{box-sizing:border-box}.console-layout{display:grid;width:100%;height:100%;grid-template-columns:1fr;grid-template-areas:\"main\"}@media (min-width: 768px){.console-layout{grid-template-columns:20rem 1fr;grid-template-areas:\"sidebar main\"}}@media (max-width: 767px){.console-layout--sidebar-active .console-layout__sidebar{transform:translate3d(0, 0, 0)}}.console-layout__sidebar{position:fixed;z-index:1;top:4rem;bottom:0;left:0;display:grid;overflow-x:hidden;overflow-y:auto;width:100%;max-width:20rem;border-right:var(--s-border-width-default) solid var(--s-border-default);transition:transform 0.15s;transform:translate3d(-100%, 0, 0);box-shadow:0 0 1rem rgba(0, 0, 0, 0.06);grid-template-rows:auto 1fr auto;grid-template-areas:\"header\"\n \"navigation\"\n \"user\"}@media (prefers-reduced-motion){.console-layout__sidebar{transition:none}}@media (min-width: 768px){.console-layout__sidebar{position:static;top:auto;left:auto;max-width:none;height:100%;transform:none;box-shadow:none;grid-area:sidebar}}.console-layout__header{overflow:hidden;min-width:0;padding:var(--s-space-20) var(--s-space-24);background-color:var(--s-background-default);grid-area:header}.console-layout__navigation{overflow-x:hidden;overflow-y:auto;padding-top:var(--s-space-8);padding-bottom:var(--s-space-8);background-color:var(--s-background-default);grid-area:navigation}@media (min-width: 768px){.console-layout__hide-navigation-button{display:none}}.console-layout__user{overflow:hidden;margin-top:var(--s-border-width-default);padding:var(--s-space-16) var(--s-space-24) var(--s-space-24);border-top:var(--s-border-width-default) solid var(--s-border-default);background-color:var(--s-background-default);grid-area:user}.console-layout__main{display:grid;overflow-x:hidden;overflow-y:auto;width:100%;height:100%;grid-area:main;gap:var(--s-border-width-default);grid-template-rows:4rem 1fr;grid-template-areas:\"app-bar\"\n \"content\"}.console-layout__app-bar{position:sticky;z-index:1;top:0;display:flex;min-width:0;padding-right:var(--s-space-16);padding-left:var(--s-space-16);align-items:center;border-bottom:var(--s-border-width-default) solid var(--s-border-default);background-color:var(--s-background-default);gap:var(--s-space-12);grid-area:app-bar}@media (min-width: 768px){.console-layout__app-bar{padding-right:2.5rem;padding-left:2.5rem}}@media (min-width: 768px){.console-layout__mobile-navigation-button{display:none}}.console-layout__app-name{min-width:0;flex-grow:1}.console-layout__app-name .heading{overflow:hidden;font-weight:var(--s-font-weight-regular);white-space:nowrap;text-overflow:ellipsis}.console-layout__help-button{flex-shrink:0}.console-layout__content{display:flex;padding:var(--s-space-16);background-color:var(--s-background-default);flex-direction:column;grid-area:content}@media (min-width: 768px){.console-layout__content{padding:2.5rem}}.console-layout__content-header{flex-shrink:0}.console-layout__integration{flex-grow:1}.console-layout__logo{display:flex;min-width:0;align-items:center;gap:var(--s-space-12)}.console-layout__logo-mark{flex-shrink:0}.console-layout__logo-text{min-width:0}.console-layout__logo-text::part(text){overflow:hidden;white-space:nowrap;text-overflow:ellipsis}.console-layout__content-header{display:flex;margin-bottom:2.5rem;gap:var(--s-space-16)}.console-layout__back-button{position:relative;top:calc(-1 * var(--s-space-2));flex-shrink:0}.console-layout__subheading{margin-top:var(--s-space-8)}";
1149
7
 
1150
8
  const FlipConsoleLayout = class {
@@ -1167,12 +25,20 @@ const FlipConsoleLayout = class {
1167
25
  this.onMobileNavigationToggleClick = () => {
1168
26
  this.toggleSidebar();
1169
27
  };
28
+ this.onHideNavigationButtonClick = () => {
29
+ this.hideSidebar();
30
+ };
1170
31
  this.onClick = (event) => {
32
+ var _a;
1171
33
  const target = event.target;
1172
34
  const clickOnToggle = Boolean(target.closest(".console-layout__mobile-navigation-button"));
35
+ const clickOnOverlay = ((_a = target.closest("[slot]")) === null || _a === void 0 ? void 0 : _a.slot) === "overlays";
1173
36
  const clickInsideSidebar = event.composedPath().includes(this.sidebarEl);
1174
- if (!clickInsideSidebar && !clickOnToggle && this.sidebarActive) {
1175
- this.sidebarActive = false;
37
+ if (!clickInsideSidebar &&
38
+ !clickOnToggle &&
39
+ !clickOnOverlay &&
40
+ this.sidebarActive) {
41
+ this.deactivateSidebar();
1176
42
  }
1177
43
  };
1178
44
  this.onKeyDown = (event) => {
@@ -1182,13 +48,6 @@ const FlipConsoleLayout = class {
1182
48
  };
1183
49
  }
1184
50
  componentDidLoad() {
1185
- const sidebarContents = [
1186
- this.sidebarEl,
1187
- ...Array.from(this.el.querySelectorAll('[slot="navigation"], [slot="user"]')).filter((el) => Boolean(el)),
1188
- ];
1189
- this.focusTrap = createFocusTrap(sidebarContents, {
1190
- clickOutsideDeactivates: true,
1191
- });
1192
51
  queueMicrotask(() => {
1193
52
  if (!isMobileViewport()) {
1194
53
  this.activateSidebar();
@@ -1218,31 +77,45 @@ const FlipConsoleLayout = class {
1218
77
  this.activateSidebar();
1219
78
  }
1220
79
  }
80
+ /**
81
+ * Show the mobile navigation.
82
+ */
83
+ async showSidebar() {
84
+ if (!this.sidebarActive) {
85
+ this.activateSidebar();
86
+ }
87
+ }
88
+ /**
89
+ * Hide the mobile navigation.
90
+ */
91
+ async hideSidebar() {
92
+ if (this.sidebarActive) {
93
+ this.deactivateSidebar();
94
+ }
95
+ }
1221
96
  activateSidebar() {
1222
97
  var _a;
1223
98
  this.sidebarActive = true;
1224
99
  this.sidebarEl.removeAttribute("inert");
1225
100
  if (isMobileViewport()) {
1226
- (_a = this.focusTrap) === null || _a === void 0 ? void 0 : _a.activate();
101
+ (_a = this.el.querySelector("flip-tree-navigation-item")) === null || _a === void 0 ? void 0 : _a.focus();
1227
102
  }
1228
103
  }
1229
104
  deactivateSidebar() {
1230
- var _a;
1231
105
  this.sidebarActive = false;
1232
106
  if (isMobileViewport()) {
1233
107
  this.sidebarEl.setAttribute("inert", "");
1234
108
  }
1235
- (_a = this.focusTrap) === null || _a === void 0 ? void 0 : _a.deactivate({ returnFocus: true });
1236
109
  }
1237
110
  render() {
1238
111
  const className = classnames("console-layout", {
1239
112
  "console-layout--sidebar-active": this.sidebarActive,
1240
113
  });
1241
- return (h(Host, null, h("div", { class: className, onClick: this.onClick, onKeyDown: this.onKeyDown }, h("div", { "aria-hidden": String(!this.sidebarActive), class: "console-layout__sidebar", ref: (el) => (this.sidebarEl = el) }, h("header", { class: "console-layout__header" }, h("div", { class: "console-layout__logo" }, h("svg", { class: "console-layout__logo-mark", fill: "none", height: "26", viewBox: "0 0 16 26", width: "16", xmlns: "http://www.w3.org/2000/svg" }, h("path", { d: "M0.624238 14.0705C0.326496 13.5353 0.118077 12.9406 0.0287543 12.3161C-0.0307941 11.662 -0.0010199 11.0375 0.147851 10.4428C0.296722 9.84813 0.594464 9.25343 0.951754 8.77767C1.33882 8.27217 1.78543 7.85588 2.35114 7.55853L14.6181 0.362671C14.9159 0.8979 15.1243 1.4926 15.2136 2.11703C15.3029 2.74147 15.2434 3.3659 15.0945 3.99034C14.9456 4.58504 14.6479 5.17974 14.2906 5.6555C13.9035 6.16099 13.4569 6.57728 12.8912 6.87463L0.624238 14.0705Z", fill: "#145AF5" }), h("path", { d: "M3.69214 21.4743C3.3944 20.9391 3.18598 20.3444 3.09666 19.72C3.00733 19.0956 3.06688 18.4711 3.21575 17.8467C3.36462 17.252 3.66237 16.6573 4.01966 16.1815C4.40672 15.676 4.85333 15.2597 5.41904 14.9624L12.2076 10.9779C12.5053 11.5131 12.7137 12.1078 12.803 12.7323C12.8924 13.3567 12.8328 13.9811 12.6839 14.6056C12.5351 15.2003 12.2373 15.795 11.88 16.2707C11.493 16.7762 11.0464 17.1925 10.4807 17.4899L3.69214 21.4743Z", fill: "#145AF5" }), h("path", { d: "M3.69141 21.4739L7.77047 19.0951C8.39573 20.1953 8.5446 21.5036 8.24686 22.7228C7.91934 23.9419 7.14521 24.9826 6.04357 25.6368L3.69141 21.4739Z", fill: "#80A8F4" }), h("path", { d: "M12.2072 10.9785L7.32419 10.1459L0.625 14.0709L5.38887 14.9629L12.2072 10.9785Z", fill: "#80A8F4" })), h("flip-text", { class: "console-layout__logo-text", weight: "medium" }, this.logoText))), h("nav", { "aria-label": this.navigationLabel, class: "console-layout__navigation" }, h("slot", { name: "navigation" }), this.sidebarActive && (h("flip-visually-hidden", null, h("button", { class: "console-layout__hide-navigation-button", onClick: this.onMobileNavigationToggleClick, type: "button" }, this.hideNavigationButtonLabel)))), h("div", { class: "console-layout__user" }, h("slot", { name: "user" }))), h("main", { "aria-labelledby": "app-name", class: "console-layout__main" }, h("header", { class: "console-layout__app-bar" }, h("flip-button", { class: "console-layout__mobile-navigation-button", flipAriaExpanded: String(this.sidebarActive), hideLabel: true, icon: this.sidebarActive
114
+ return (h(Host, null, h("div", { class: className, onClick: this.onClick, onKeyDown: this.onKeyDown }, h("div", { "aria-hidden": String(!this.sidebarActive), class: "console-layout__sidebar", ref: (el) => (this.sidebarEl = el) }, h("header", { class: "console-layout__header" }, h("div", { class: "console-layout__logo" }, h("svg", { class: "console-layout__logo-mark", fill: "none", height: "26", viewBox: "0 0 16 26", width: "16", xmlns: "http://www.w3.org/2000/svg" }, h("path", { d: "M0.624238 14.0705C0.326496 13.5353 0.118077 12.9406 0.0287543 12.3161C-0.0307941 11.662 -0.0010199 11.0375 0.147851 10.4428C0.296722 9.84813 0.594464 9.25343 0.951754 8.77767C1.33882 8.27217 1.78543 7.85588 2.35114 7.55853L14.6181 0.362671C14.9159 0.8979 15.1243 1.4926 15.2136 2.11703C15.3029 2.74147 15.2434 3.3659 15.0945 3.99034C14.9456 4.58504 14.6479 5.17974 14.2906 5.6555C13.9035 6.16099 13.4569 6.57728 12.8912 6.87463L0.624238 14.0705Z", fill: "#145AF5" }), h("path", { d: "M3.69214 21.4743C3.3944 20.9391 3.18598 20.3444 3.09666 19.72C3.00733 19.0956 3.06688 18.4711 3.21575 17.8467C3.36462 17.252 3.66237 16.6573 4.01966 16.1815C4.40672 15.676 4.85333 15.2597 5.41904 14.9624L12.2076 10.9779C12.5053 11.5131 12.7137 12.1078 12.803 12.7323C12.8924 13.3567 12.8328 13.9811 12.6839 14.6056C12.5351 15.2003 12.2373 15.795 11.88 16.2707C11.493 16.7762 11.0464 17.1925 10.4807 17.4899L3.69214 21.4743Z", fill: "#145AF5" }), h("path", { d: "M3.69141 21.4739L7.77047 19.0951C8.39573 20.1953 8.5446 21.5036 8.24686 22.7228C7.91934 23.9419 7.14521 24.9826 6.04357 25.6368L3.69141 21.4739Z", fill: "#80A8F4" }), h("path", { d: "M12.2072 10.9785L7.32419 10.1459L0.625 14.0709L5.38887 14.9629L12.2072 10.9785Z", fill: "#80A8F4" })), h("flip-text", { class: "console-layout__logo-text", weight: "medium" }, this.logoText))), h("nav", { "aria-label": this.navigationLabel, class: "console-layout__navigation" }, h("slot", { name: "navigation" }), this.sidebarActive && (h("flip-visually-hidden", null, h("button", { class: "console-layout__hide-navigation-button", onClick: this.onHideNavigationButtonClick, type: "button" }, this.hideNavigationButtonLabel)))), h("div", { class: "console-layout__user" }, h("slot", { name: "user" }))), h("main", { "aria-labelledby": "app-name", class: "console-layout__main" }, h("header", { class: "console-layout__app-bar" }, h("flip-button", { class: "console-layout__mobile-navigation-button", flipAriaExpanded: String(this.sidebarActive), hideLabel: true, icon: this.sidebarActive
1242
115
  ? "<flip-icon-close></flip-icon-close>"
1243
116
  : "<flip-icon-menu></flip-icon-menu>", label: this.sidebarActive
1244
117
  ? this.hideNavigationButtonLabel
1245
- : this.showNavigationButtonLabel, onClick: this.onMobileNavigationToggleClick }), h("flip-heading", { as: "h1", class: "console-layout__app-name", headingId: "app-name", level: 4, text: this.appName }), this.showHelpButton && (h("flip-button", { class: "console-layout__help-button", hideLabel: true, icon: "<flip-icon-help></flip-icon-help>", label: this.helpButonLabel, onClick: this.onHelpButtonClick }))), h("section", { "aria-labelledby": "heading", class: "console-layout__content" }, h("header", { class: "console-layout__content-header" }, this.showBackButton && (h("flip-button", { class: "console-layout__back-button", hideLabel: true, icon: "<flip-icon-arrow-back></flip-icon-arrow-back>", label: this.backButonLabel, onClick: this.onBackButtonClick })), h("div", null, h("flip-heading", { as: "h2", class: "console-layout__heading", headingId: "heading", level: 1, text: this.heading }), this.subheading && (h("flip-text", { class: "console-layout__subheading", color: "subdued" }, this.subheading)))), h("div", { class: "console-layout__integration" }, h("slot", { name: "content" })))))));
118
+ : this.showNavigationButtonLabel, onClick: this.onMobileNavigationToggleClick }), h("flip-heading", { as: "h1", class: "console-layout__app-name", headingId: "app-name", level: 4, text: this.appName }), this.showHelpButton && (h("flip-button", { class: "console-layout__help-button", hideLabel: true, icon: "<flip-icon-help></flip-icon-help>", label: this.helpButonLabel, onClick: this.onHelpButtonClick }))), h("section", { "aria-labelledby": "heading", class: "console-layout__content" }, h("header", { class: "console-layout__content-header" }, this.showBackButton && (h("flip-button", { class: "console-layout__back-button", hideLabel: true, icon: "<flip-icon-arrow-back></flip-icon-arrow-back>", label: this.backButonLabel, onClick: this.onBackButtonClick })), h("div", null, h("flip-heading", { as: "h2", class: "console-layout__heading", headingId: "heading", level: 1, text: this.heading }), this.subheading && (h("flip-text", { class: "console-layout__subheading", color: "subdued" }, this.subheading)))), h("div", { class: "console-layout__integration" }, h("slot", { name: "content" }))), h("div", { class: "console-layout__overlays" }, h("slot", { name: "overlays" }))))));
1246
119
  }
1247
120
  get el() { return getElement(this); }
1248
121
  };