@getflip/swirl-components 0.8.1 → 0.8.3

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