@spscommerce/ds-react 4.8.1 → 4.9.0-ie

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.
package/lib/index.cjs.js CHANGED
@@ -15,7 +15,6 @@ var positioning = require('@spscommerce/positioning');
15
15
  var moment$6 = require('moment-timezone');
16
16
  var isPlainObject = require('lodash.isplainobject');
17
17
  var dsColors = require('@spscommerce/ds-colors');
18
- var collections = require('@react-stately/collections');
19
18
 
20
19
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
21
20
 
@@ -40,7 +39,6 @@ function _interopNamespace(e) {
40
39
  }
41
40
 
42
41
  var React__namespace = /*#__PURE__*/_interopNamespace(React);
43
- var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
44
42
  var clsx__default = /*#__PURE__*/_interopDefaultLegacy(clsx);
45
43
  var PropTypes__namespace = /*#__PURE__*/_interopNamespace(PropTypes);
46
44
  var nanoid__default = /*#__PURE__*/_interopDefaultLegacy(nanoid);
@@ -1780,7 +1778,7 @@ Object.assign(SpsCardTabbedPane, {
1780
1778
  * @param activeTab
1781
1779
  * @param isTabbedCard
1782
1780
  */
1783
- function useTab$1(children, activeTab, isTabbedCard) {
1781
+ function useTab(children, activeTab, isTabbedCard) {
1784
1782
  // STATE: Currently active tab state
1785
1783
  var _a = __read(React__namespace.useState({
1786
1784
  index: 0,
@@ -1864,7 +1862,7 @@ function SpsCard(props) {
1864
1862
  var activeTab = props.activeTab, children = props.children, className = props.className, footer = props.footer, headerContent = props.headerContent, headerIcon = props.headerIcon, headerTitle = props.headerTitle, testId = props["data-testid"], unsafelyReplaceClassName = props.unsafelyReplaceClassName, rest = __rest(props, ["activeTab", "children", "className", "footer", "headerContent", "headerIcon", "headerTitle", 'data-testid', "unsafelyReplaceClassName"]);
1865
1863
  // This used to be a prop but now we derive it
1866
1864
  var isTabbedCard = React__namespace.Children.toArray(children).some(function (child) { return React__namespace.isValidElement(child) && child.type === SpsCardTabbedPane; });
1867
- var _a = __read(useTab$1(children, activeTab, isTabbedCard), 2), currentlyActiveTab = _a[0], setCurrentlyActiveTab = _a[1];
1865
+ var _a = __read(useTab(children, activeTab, isTabbedCard), 2), currentlyActiveTab = _a[0], setCurrentlyActiveTab = _a[1];
1868
1866
  var classes = clsx__default['default'](unsafelyReplaceClassName || 'sps-card', className);
1869
1867
  return (React__namespace.createElement("div", __assign({}, rest, { className: classes, "data-testid": testId + "__card" }),
1870
1868
  (headerTitle || headerContent) && (React__namespace.createElement(SpsCardHeader, { title: headerTitle, content: contentOf(headerContent), icon: headerIcon, "data-testid": testId + "__header" })),
@@ -7719,6 +7717,22 @@ function SpsModalV2(_a) {
7719
7717
  if (event && event.key === 'Escape' && onClose) {
7720
7718
  onClose();
7721
7719
  }
7720
+ if (event && event.key === 'Tab') {
7721
+ var focusableElements = rootElement.current.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])');
7722
+ var firstFocusableElement = focusableElements[0];
7723
+ var lastFocusableElement = focusableElements[focusableElements.length - 1];
7724
+ if (focusableElements.length === 0) {
7725
+ event.preventDefault();
7726
+ }
7727
+ else if (event.shiftKey && event.target === firstFocusableElement) {
7728
+ event.preventDefault();
7729
+ lastFocusableElement.focus();
7730
+ }
7731
+ else if (!event.shiftKey && event.target === lastFocusableElement) {
7732
+ event.preventDefault();
7733
+ firstFocusableElement.focus();
7734
+ }
7735
+ }
7722
7736
  }, [onClose]);
7723
7737
  var _e = __read(selectChildren(children, [{ type: SpsModalV2Footer }]), 2), _f = __read(_e[0], 1), footer = _f[0], bodyContent = _e[1];
7724
7738
  return bodyIsReady
@@ -10921,3232 +10935,6 @@ var MANIFEST = {
10921
10935
  },
10922
10936
  };
10923
10937
 
10924
- function useControlledState(value, defaultValue, onChange) {
10925
- let [stateValue, setStateValue] = React.useState(value || defaultValue);
10926
- let ref = React.useRef(value !== undefined);
10927
- let wasControlled = ref.current;
10928
- let isControlled = value !== undefined; // Internal state reference for useCallback
10929
-
10930
- let stateRef = React.useRef(stateValue);
10931
-
10932
- if (wasControlled !== isControlled) {
10933
- console.warn("WARN: A component changed from " + (wasControlled ? 'controlled' : 'uncontrolled') + " to " + (isControlled ? 'controlled' : 'uncontrolled') + ".");
10934
- }
10935
-
10936
- ref.current = isControlled;
10937
- let setValue = React.useCallback(function (value) {
10938
- for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
10939
- args[_key - 1] = arguments[_key];
10940
- }
10941
-
10942
- let onChangeCaller = function onChangeCaller(value) {
10943
- if (onChange) {
10944
- if (!Object.is(stateRef.current, value)) {
10945
- for (var _len2 = arguments.length, onChangeArgs = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
10946
- onChangeArgs[_key2 - 1] = arguments[_key2];
10947
- }
10948
-
10949
- onChange(value, ...onChangeArgs);
10950
- }
10951
- }
10952
-
10953
- if (!isControlled) {
10954
- stateRef.current = value;
10955
- }
10956
- };
10957
-
10958
- if (typeof value === 'function') {
10959
- // this supports functional updates https://reactjs.org/docs/hooks-reference.html#functional-updates
10960
- // when someone using useControlledState calls setControlledState(myFunc)
10961
- // this will call our useState setState with a function as well which invokes myFunc and calls onChange with the value from myFunc
10962
- // if we're in an uncontrolled state, then we also return the value of myFunc which to setState looks as though it was just called with myFunc from the beginning
10963
- // otherwise we just return the controlled value, which won't cause a rerender because React knows to bail out when the value is the same
10964
- let updateFunction = function updateFunction(oldValue) {
10965
- for (var _len3 = arguments.length, functionArgs = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
10966
- functionArgs[_key3 - 1] = arguments[_key3];
10967
- }
10968
-
10969
- let interceptedValue = value(isControlled ? stateRef.current : oldValue, ...functionArgs);
10970
- onChangeCaller(interceptedValue, ...args);
10971
-
10972
- if (!isControlled) {
10973
- return interceptedValue;
10974
- }
10975
-
10976
- return oldValue;
10977
- };
10978
-
10979
- setStateValue(updateFunction);
10980
- } else {
10981
- if (!isControlled) {
10982
- setStateValue(value);
10983
- }
10984
-
10985
- onChangeCaller(value, ...args);
10986
- }
10987
- }, [isControlled, onChange]); // If a controlled component's value prop changes, we need to update stateRef
10988
-
10989
- if (isControlled) {
10990
- stateRef.current = value;
10991
- } else {
10992
- value = stateValue;
10993
- }
10994
-
10995
- return [value, setValue];
10996
- }
10997
-
10998
- function _extends$3() {
10999
- _extends$3 = Object.assign || function (target) {
11000
- for (var i = 1; i < arguments.length; i++) {
11001
- var source = arguments[i];
11002
-
11003
- for (var key in source) {
11004
- if (Object.prototype.hasOwnProperty.call(source, key)) {
11005
- target[key] = source[key];
11006
- }
11007
- }
11008
- }
11009
-
11010
- return target;
11011
- };
11012
-
11013
- return _extends$3.apply(this, arguments);
11014
- }
11015
-
11016
- /*
11017
- * Copyright 2020 Adobe. All rights reserved.
11018
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
11019
- * you may not use this file except in compliance with the License. You may obtain a copy
11020
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
11021
- *
11022
- * Unless required by applicable law or agreed to in writing, software distributed under
11023
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
11024
- * OF ANY KIND, either express or implied. See the License for the specific language
11025
- * governing permissions and limitations under the License.
11026
- */
11027
-
11028
- /**
11029
- * A Selection is a special Set containing Keys, which also has an anchor
11030
- * and current selected key for use when range selecting.
11031
- */
11032
- class $c91e86e24f2dc9a2182dcc2674c58c$export$Selection extends Set {
11033
- constructor(keys, anchorKey, currentKey) {
11034
- super(keys);
11035
- this.anchorKey = void 0;
11036
- this.currentKey = void 0;
11037
-
11038
- if (keys instanceof $c91e86e24f2dc9a2182dcc2674c58c$export$Selection) {
11039
- this.anchorKey = anchorKey || keys.anchorKey;
11040
- this.currentKey = currentKey || keys.currentKey;
11041
- } else {
11042
- this.anchorKey = anchorKey;
11043
- this.currentKey = currentKey;
11044
- }
11045
- }
11046
-
11047
- }
11048
-
11049
- /**
11050
- * Manages state for multiple selection and focus in a collection.
11051
- */
11052
- function useMultipleSelectionState(props) {
11053
- let {
11054
- selectionMode = 'none',
11055
- disallowEmptySelection
11056
- } = props; // We want synchronous updates to `isFocused` and `focusedKey` after their setters are called.
11057
- // But we also need to trigger a react re-render. So, we have both a ref (sync) and state (async).
11058
-
11059
- let isFocusedRef = React.useRef(false);
11060
- let [, setFocused] = React.useState(false);
11061
- let focusedKeyRef = React.useRef(null);
11062
- let childFocusStrategyRef = React.useRef(null);
11063
- let [, setFocusedKey] = React.useState(null);
11064
- let selectedKeysProp = React.useMemo(() => $c86d35e876e048ac11515eee40c7$var$convertSelection(props.selectedKeys), [props.selectedKeys]);
11065
- let defaultSelectedKeys = React.useMemo(() => $c86d35e876e048ac11515eee40c7$var$convertSelection(props.defaultSelectedKeys, new $c91e86e24f2dc9a2182dcc2674c58c$export$Selection()), [props.defaultSelectedKeys]);
11066
- let [selectedKeys, setSelectedKeys] = useControlledState(selectedKeysProp, defaultSelectedKeys, props.onSelectionChange);
11067
- let disabledKeysProp = React.useMemo(() => props.disabledKeys ? new Set(props.disabledKeys) : new Set(), [props.disabledKeys]);
11068
- return {
11069
- selectionMode,
11070
- disallowEmptySelection,
11071
-
11072
- get isFocused() {
11073
- return isFocusedRef.current;
11074
- },
11075
-
11076
- setFocused(f) {
11077
- isFocusedRef.current = f;
11078
- setFocused(f);
11079
- },
11080
-
11081
- get focusedKey() {
11082
- return focusedKeyRef.current;
11083
- },
11084
-
11085
- get childFocusStrategy() {
11086
- return childFocusStrategyRef.current;
11087
- },
11088
-
11089
- setFocusedKey(k, childFocusStrategy) {
11090
- if (childFocusStrategy === void 0) {
11091
- childFocusStrategy = 'first';
11092
- }
11093
-
11094
- focusedKeyRef.current = k;
11095
- childFocusStrategyRef.current = childFocusStrategy;
11096
- setFocusedKey(k);
11097
- },
11098
-
11099
- selectedKeys,
11100
- setSelectedKeys,
11101
- disabledKeys: disabledKeysProp
11102
- };
11103
- }
11104
-
11105
- function $c86d35e876e048ac11515eee40c7$var$convertSelection(selection, defaultValue) {
11106
- if (!selection) {
11107
- return defaultValue;
11108
- }
11109
-
11110
- return selection === 'all' ? 'all' : new $c91e86e24f2dc9a2182dcc2674c58c$export$Selection(selection);
11111
- }
11112
-
11113
- /**
11114
- * An interface for reading and updating multiple selection state.
11115
- */
11116
- class SelectionManager {
11117
- constructor(collection, state, options) {
11118
- var _options$allowsCellSe;
11119
-
11120
- this.collection = void 0;
11121
- this.state = void 0;
11122
- this.allowsCellSelection = void 0;
11123
- this._isSelectAll = void 0;
11124
- this.collection = collection;
11125
- this.state = state;
11126
- this.allowsCellSelection = (_options$allowsCellSe = options == null ? void 0 : options.allowsCellSelection) != null ? _options$allowsCellSe : false;
11127
- this._isSelectAll = null;
11128
- }
11129
- /**
11130
- * The type of selection that is allowed in the collection.
11131
- */
11132
-
11133
-
11134
- get selectionMode() {
11135
- return this.state.selectionMode;
11136
- }
11137
- /**
11138
- * Whether the collection allows empty selection.
11139
- */
11140
-
11141
-
11142
- get disallowEmptySelection() {
11143
- return this.state.disallowEmptySelection;
11144
- }
11145
- /**
11146
- * Whether the collection is currently focused.
11147
- */
11148
-
11149
-
11150
- get isFocused() {
11151
- return this.state.isFocused;
11152
- }
11153
- /**
11154
- * Sets whether the collection is focused.
11155
- */
11156
-
11157
-
11158
- setFocused(isFocused) {
11159
- this.state.setFocused(isFocused);
11160
- }
11161
- /**
11162
- * The current focused key in the collection.
11163
- */
11164
-
11165
-
11166
- get focusedKey() {
11167
- return this.state.focusedKey;
11168
- }
11169
- /** Whether the first or last child of the focused key should receive focus. */
11170
-
11171
-
11172
- get childFocusStrategy() {
11173
- return this.state.childFocusStrategy;
11174
- }
11175
- /**
11176
- * Sets the focused key.
11177
- */
11178
-
11179
-
11180
- setFocusedKey(key, childFocusStrategy) {
11181
- this.state.setFocusedKey(key, childFocusStrategy);
11182
- }
11183
- /**
11184
- * The currently selected keys in the collection.
11185
- */
11186
-
11187
-
11188
- get selectedKeys() {
11189
- return this.state.selectedKeys === 'all' ? new Set(this.getSelectAllKeys()) : this.state.selectedKeys;
11190
- }
11191
- /**
11192
- * The raw selection value for the collection.
11193
- * Either 'all' for select all, or a set of keys.
11194
- */
11195
-
11196
-
11197
- get rawSelection() {
11198
- return this.state.selectedKeys;
11199
- }
11200
- /**
11201
- * Returns whether a key is selected.
11202
- */
11203
-
11204
-
11205
- isSelected(key) {
11206
- if (this.state.selectionMode === 'none') {
11207
- return false;
11208
- }
11209
-
11210
- key = this.getKey(key);
11211
- return this.state.selectedKeys === 'all' ? !this.state.disabledKeys.has(key) : this.state.selectedKeys.has(key);
11212
- }
11213
- /**
11214
- * Whether the selection is empty.
11215
- */
11216
-
11217
-
11218
- get isEmpty() {
11219
- return this.state.selectedKeys !== 'all' && this.state.selectedKeys.size === 0;
11220
- }
11221
- /**
11222
- * Whether all items in the collection are selected.
11223
- */
11224
-
11225
-
11226
- get isSelectAll() {
11227
- if (this.isEmpty) {
11228
- return false;
11229
- }
11230
-
11231
- if (this.state.selectedKeys === 'all') {
11232
- return true;
11233
- }
11234
-
11235
- if (this._isSelectAll != null) {
11236
- return this._isSelectAll;
11237
- }
11238
-
11239
- let allKeys = this.getSelectAllKeys();
11240
- let selectedKeys = this.state.selectedKeys;
11241
- this._isSelectAll = allKeys.every(k => selectedKeys.has(k));
11242
- return this._isSelectAll;
11243
- }
11244
-
11245
- get firstSelectedKey() {
11246
- var _first;
11247
-
11248
- let first = null;
11249
-
11250
- for (let key of this.state.selectedKeys) {
11251
- let item = this.collection.getItem(key);
11252
-
11253
- if (!first || (item == null ? void 0 : item.index) < first.index) {
11254
- first = item;
11255
- }
11256
- }
11257
-
11258
- return (_first = first) == null ? void 0 : _first.key;
11259
- }
11260
-
11261
- get lastSelectedKey() {
11262
- var _last;
11263
-
11264
- let last = null;
11265
-
11266
- for (let key of this.state.selectedKeys) {
11267
- let item = this.collection.getItem(key);
11268
-
11269
- if (!last || (item == null ? void 0 : item.index) > last.index) {
11270
- last = item;
11271
- }
11272
- }
11273
-
11274
- return (_last = last) == null ? void 0 : _last.key;
11275
- }
11276
- /**
11277
- * Extends the selection to the given key.
11278
- */
11279
-
11280
-
11281
- extendSelection(toKey) {
11282
- toKey = this.getKey(toKey);
11283
- let selection; // Only select the one key if coming from a select all.
11284
-
11285
- if (this.state.selectedKeys === 'all') {
11286
- selection = new $c91e86e24f2dc9a2182dcc2674c58c$export$Selection([toKey], toKey, toKey);
11287
- } else {
11288
- let selectedKeys = this.state.selectedKeys;
11289
- let anchorKey = selectedKeys.anchorKey || toKey;
11290
- selection = new $c91e86e24f2dc9a2182dcc2674c58c$export$Selection(selectedKeys, anchorKey, toKey);
11291
-
11292
- for (let key of this.getKeyRange(anchorKey, selectedKeys.currentKey || toKey)) {
11293
- selection.delete(key);
11294
- }
11295
-
11296
- for (let key of this.getKeyRange(toKey, anchorKey)) {
11297
- if (!this.state.disabledKeys.has(key)) {
11298
- selection.add(key);
11299
- }
11300
- }
11301
- }
11302
-
11303
- this.state.setSelectedKeys(selection);
11304
- }
11305
-
11306
- getKeyRange(from, to) {
11307
- let fromItem = this.collection.getItem(from);
11308
- let toItem = this.collection.getItem(to);
11309
-
11310
- if (fromItem && toItem) {
11311
- if (fromItem.index <= toItem.index) {
11312
- return this.getKeyRangeInternal(from, to);
11313
- }
11314
-
11315
- return this.getKeyRangeInternal(to, from);
11316
- }
11317
-
11318
- return [];
11319
- }
11320
-
11321
- getKeyRangeInternal(from, to) {
11322
- let keys = [];
11323
- let key = from;
11324
-
11325
- while (key) {
11326
- let item = this.collection.getItem(key);
11327
-
11328
- if (item && item.type === 'item' || item.type === 'cell' && this.allowsCellSelection) {
11329
- keys.push(key);
11330
- }
11331
-
11332
- if (key === to) {
11333
- return keys;
11334
- }
11335
-
11336
- key = this.collection.getKeyAfter(key);
11337
- }
11338
-
11339
- return [];
11340
- }
11341
-
11342
- getKey(key) {
11343
- let item = this.collection.getItem(key);
11344
-
11345
- if (!item) {
11346
- // ¯\_(ツ)_/¯
11347
- return key;
11348
- } // If cell selection is allowed, just return the key.
11349
-
11350
-
11351
- if (item.type === 'cell' && this.allowsCellSelection) {
11352
- return key;
11353
- } // Find a parent item to select
11354
-
11355
-
11356
- while (item.type !== 'item' && item.parentKey) {
11357
- item = this.collection.getItem(item.parentKey);
11358
- }
11359
-
11360
- if (!item || item.type !== 'item') {
11361
- return null;
11362
- }
11363
-
11364
- return item.key;
11365
- }
11366
- /**
11367
- * Toggles whether the given key is selected.
11368
- */
11369
-
11370
-
11371
- toggleSelection(key) {
11372
- key = this.getKey(key);
11373
-
11374
- if (key == null) {
11375
- return;
11376
- }
11377
-
11378
- let keys = new $c91e86e24f2dc9a2182dcc2674c58c$export$Selection(this.state.selectedKeys === 'all' ? this.getSelectAllKeys() : this.state.selectedKeys);
11379
-
11380
- if (keys.has(key)) {
11381
- keys.delete(key); // TODO: move anchor to last selected key...
11382
- // Does `current` need to move here too?
11383
- } else {
11384
- keys.add(key);
11385
- keys.anchorKey = key;
11386
- keys.currentKey = key;
11387
- }
11388
-
11389
- if (this.disallowEmptySelection && keys.size === 0) {
11390
- return;
11391
- }
11392
-
11393
- this.state.setSelectedKeys(keys);
11394
- }
11395
- /**
11396
- * Replaces the selection with only the given key.
11397
- */
11398
-
11399
-
11400
- replaceSelection(key) {
11401
- key = this.getKey(key);
11402
-
11403
- if (key == null) {
11404
- return;
11405
- }
11406
-
11407
- this.state.setSelectedKeys(new $c91e86e24f2dc9a2182dcc2674c58c$export$Selection([key], key, key));
11408
- }
11409
- /**
11410
- * Replaces the selection with the given keys.
11411
- */
11412
-
11413
-
11414
- setSelectedKeys(keys) {
11415
- if (this.selectionMode === 'none') {
11416
- return;
11417
- }
11418
-
11419
- let selection = new $c91e86e24f2dc9a2182dcc2674c58c$export$Selection();
11420
-
11421
- for (let key of keys) {
11422
- key = this.getKey(key);
11423
-
11424
- if (key != null) {
11425
- selection.add(key);
11426
-
11427
- if (this.selectionMode === 'single') {
11428
- break;
11429
- }
11430
- }
11431
- }
11432
-
11433
- this.state.setSelectedKeys(selection);
11434
- }
11435
-
11436
- getSelectAllKeys() {
11437
- let keys = [];
11438
-
11439
- let addKeys = key => {
11440
- while (key) {
11441
- if (!this.state.disabledKeys.has(key)) {
11442
- let item = this.collection.getItem(key);
11443
-
11444
- if (item.type === 'item') {
11445
- keys.push(key);
11446
- } // Add child keys. If cell selection is allowed, then include item children too.
11447
-
11448
-
11449
- if (item.hasChildNodes && (this.allowsCellSelection || item.type !== 'item')) {
11450
- addKeys([...item.childNodes][0].key);
11451
- }
11452
- }
11453
-
11454
- key = this.collection.getKeyAfter(key);
11455
- }
11456
- };
11457
-
11458
- addKeys(this.collection.getFirstKey());
11459
- return keys;
11460
- }
11461
- /**
11462
- * Selects all items in the collection.
11463
- */
11464
-
11465
-
11466
- selectAll() {
11467
- if (this.selectionMode === 'multiple') {
11468
- this.state.setSelectedKeys('all');
11469
- }
11470
- }
11471
- /**
11472
- * Removes all keys from the selection.
11473
- */
11474
-
11475
-
11476
- clearSelection() {
11477
- if (!this.disallowEmptySelection && (this.state.selectedKeys === 'all' || this.state.selectedKeys.size > 0)) {
11478
- this.state.setSelectedKeys(new $c91e86e24f2dc9a2182dcc2674c58c$export$Selection());
11479
- }
11480
- }
11481
- /**
11482
- * Toggles between select all and an empty selection.
11483
- */
11484
-
11485
-
11486
- toggleSelectAll() {
11487
- if (this.isSelectAll) {
11488
- this.clearSelection();
11489
- } else {
11490
- this.selectAll();
11491
- }
11492
- }
11493
-
11494
- select(key, e) {
11495
- if (this.selectionMode === 'none') {
11496
- return;
11497
- }
11498
-
11499
- if (this.selectionMode === 'single') {
11500
- if (this.isSelected(key) && !this.disallowEmptySelection) {
11501
- this.toggleSelection(key);
11502
- } else {
11503
- this.replaceSelection(key);
11504
- }
11505
- } else if (e && e.shiftKey) {
11506
- this.extendSelection(key);
11507
- } else {
11508
- this.toggleSelection(key);
11509
- }
11510
- }
11511
- /**
11512
- * Returns whether the current selection is equal to the given selection.
11513
- */
11514
-
11515
-
11516
- isSelectionEqual(selection) {
11517
- if (selection === this.state.selectedKeys) {
11518
- return true;
11519
- } // Check if the set of keys match.
11520
-
11521
-
11522
- let selectedKeys = this.selectedKeys;
11523
-
11524
- if (selection.size !== selectedKeys.size) {
11525
- return false;
11526
- }
11527
-
11528
- for (let key of selection) {
11529
- if (!selectedKeys.has(key)) {
11530
- return false;
11531
- }
11532
- }
11533
-
11534
- for (let key of selectedKeys) {
11535
- if (!selection.has(key)) {
11536
- return false;
11537
- }
11538
- }
11539
-
11540
- return true;
11541
- }
11542
-
11543
- }
11544
-
11545
- let $ed5d55e571caf578a4f08babbaa26be$var$_Symbol$iterator;
11546
- $ed5d55e571caf578a4f08babbaa26be$var$_Symbol$iterator = Symbol.iterator;
11547
-
11548
- /*
11549
- * Copyright 2020 Adobe. All rights reserved.
11550
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
11551
- * you may not use this file except in compliance with the License. You may obtain a copy
11552
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
11553
- *
11554
- * Unless required by applicable law or agreed to in writing, software distributed under
11555
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
11556
- * OF ANY KIND, either express or implied. See the License for the specific language
11557
- * governing permissions and limitations under the License.
11558
- */
11559
- class ListCollection {
11560
- constructor(nodes) {
11561
- var _last;
11562
-
11563
- this.keyMap = new Map();
11564
- this.iterable = void 0;
11565
- this.firstKey = void 0;
11566
- this.lastKey = void 0;
11567
- this.iterable = nodes;
11568
-
11569
- let visit = node => {
11570
- this.keyMap.set(node.key, node);
11571
-
11572
- if (node.childNodes && node.type === 'section') {
11573
- for (let child of node.childNodes) {
11574
- visit(child);
11575
- }
11576
- }
11577
- };
11578
-
11579
- for (let node of nodes) {
11580
- visit(node);
11581
- }
11582
-
11583
- let last;
11584
- let index = 0;
11585
-
11586
- for (let [key, node] of this.keyMap) {
11587
- if (last) {
11588
- last.nextKey = key;
11589
- node.prevKey = last.key;
11590
- } else {
11591
- this.firstKey = key;
11592
- node.prevKey = undefined;
11593
- }
11594
-
11595
- if (node.type === 'item') {
11596
- node.index = index++;
11597
- }
11598
-
11599
- last = node; // Set nextKey as undefined since this might be the last node
11600
- // If it isn't the last node, last.nextKey will properly set at start of new loop
11601
-
11602
- last.nextKey = undefined;
11603
- }
11604
-
11605
- this.lastKey = (_last = last) == null ? void 0 : _last.key;
11606
- }
11607
-
11608
- *[$ed5d55e571caf578a4f08babbaa26be$var$_Symbol$iterator]() {
11609
- yield* this.iterable;
11610
- }
11611
-
11612
- get size() {
11613
- return this.keyMap.size;
11614
- }
11615
-
11616
- getKeys() {
11617
- return this.keyMap.keys();
11618
- }
11619
-
11620
- getKeyBefore(key) {
11621
- let node = this.keyMap.get(key);
11622
- return node ? node.prevKey : null;
11623
- }
11624
-
11625
- getKeyAfter(key) {
11626
- let node = this.keyMap.get(key);
11627
- return node ? node.nextKey : null;
11628
- }
11629
-
11630
- getFirstKey() {
11631
- return this.firstKey;
11632
- }
11633
-
11634
- getLastKey() {
11635
- return this.lastKey;
11636
- }
11637
-
11638
- getItem(key) {
11639
- return this.keyMap.get(key);
11640
- }
11641
-
11642
- at(idx) {
11643
- const keys = [...this.getKeys()];
11644
- return this.getItem(keys[idx]);
11645
- }
11646
-
11647
- }
11648
-
11649
- /**
11650
- * Provides state management for list-like components. Handles building a collection
11651
- * of items from props, and manages multiple selection state.
11652
- */
11653
- function useListState(props) {
11654
- let {
11655
- filter
11656
- } = props;
11657
- let selectionState = useMultipleSelectionState(props);
11658
- let disabledKeys = React.useMemo(() => props.disabledKeys ? new Set(props.disabledKeys) : new Set(), [props.disabledKeys]);
11659
-
11660
- let factory = nodes => filter ? new ListCollection(filter(nodes)) : new ListCollection(nodes);
11661
-
11662
- let context = React.useMemo(() => ({
11663
- suppressTextValueWarning: props.suppressTextValueWarning
11664
- }), [props.suppressTextValueWarning]);
11665
- let collection = collections.useCollection(props, factory, context, [filter]); // Reset focused key if that item is deleted from the collection.
11666
-
11667
- React.useEffect(() => {
11668
- if (selectionState.focusedKey != null && !collection.getItem(selectionState.focusedKey)) {
11669
- selectionState.setFocusedKey(null);
11670
- }
11671
- }, [collection, selectionState.focusedKey]);
11672
- return {
11673
- collection,
11674
- disabledKeys,
11675
- selectionManager: new SelectionManager(collection, selectionState)
11676
- };
11677
- }
11678
-
11679
- /**
11680
- * Provides state management for list-like components with single selection.
11681
- * Handles building a collection of items from props, and manages selection state.
11682
- */
11683
- function useSingleSelectListState(props) {
11684
- var _props$defaultSelecte;
11685
-
11686
- let [selectedKey, setSelectedKey] = useControlledState(props.selectedKey, (_props$defaultSelecte = props.defaultSelectedKey) != null ? _props$defaultSelecte : null, props.onSelectionChange);
11687
- let selectedKeys = React.useMemo(() => selectedKey != null ? [selectedKey] : [], [selectedKey]);
11688
- let {
11689
- collection,
11690
- disabledKeys,
11691
- selectionManager
11692
- } = useListState(_extends$3({}, props, {
11693
- selectionMode: 'single',
11694
- disallowEmptySelection: true,
11695
- selectedKeys,
11696
- onSelectionChange: keys => {
11697
- let key = keys.values().next().value; // Always fire onSelectionChange, even if the key is the same
11698
- // as the current key (useControlledState does not).
11699
-
11700
- if (key === selectedKey && props.onSelectionChange) {
11701
- props.onSelectionChange(key);
11702
- }
11703
-
11704
- setSelectedKey(key);
11705
- }
11706
- }));
11707
- let selectedItem = selectedKey != null ? collection.getItem(selectedKey) : null;
11708
- return {
11709
- collection,
11710
- disabledKeys,
11711
- selectionManager,
11712
- selectedKey,
11713
- setSelectedKey,
11714
- selectedItem
11715
- };
11716
- }
11717
-
11718
- function _extends$2() {
11719
- _extends$2 = Object.assign || function (target) {
11720
- for (var i = 1; i < arguments.length; i++) {
11721
- var source = arguments[i];
11722
-
11723
- for (var key in source) {
11724
- if (Object.prototype.hasOwnProperty.call(source, key)) {
11725
- target[key] = source[key];
11726
- }
11727
- }
11728
- }
11729
-
11730
- return target;
11731
- };
11732
-
11733
- return _extends$2.apply(this, arguments);
11734
- }
11735
-
11736
- /**
11737
- * Provides state management for a Tabs component. Tabs include a TabList which tracks
11738
- * which tab is currently selected and displays the content associated with that Tab in a TabPanel.
11739
- */
11740
- function useTabListState(props) {
11741
- let state = useSingleSelectListState(_extends$2({}, props, {
11742
- suppressTextValueWarning: true
11743
- }));
11744
- React.useEffect(() => {
11745
- // Ensure a tab is always selected (in case no selected key was specified or if selected item was deleted from collection)
11746
- let selectedKey = state.selectedKey;
11747
-
11748
- if (state.selectionManager.isEmpty || !state.collection.getItem(selectedKey)) {
11749
- selectedKey = state.collection.getFirstKey();
11750
- state.selectionManager.replaceSelection(selectedKey);
11751
- }
11752
-
11753
- if (state.selectionManager.focusedKey == null) {
11754
- state.selectionManager.setFocusedKey(selectedKey);
11755
- }
11756
- }, [state.selectionManager, state.selectedKey, state.collection]);
11757
- return state;
11758
- }
11759
-
11760
- // Default context value to use in case there is no SSRProvider. This is fine for
11761
- // client-only apps. In order to support multiple copies of React Aria potentially
11762
- // being on the page at once, the prefix is set to a random number. SSRProvider
11763
- // will reset this to zero for consistency between server and client, so in the
11764
- // SSR case multiple copies of React Aria is not supported.
11765
- const $f01a183cc7bdff77849e49ad26eb904$var$defaultContext = {
11766
- prefix: Math.round(Math.random() * 10000000000),
11767
- current: 0
11768
- };
11769
-
11770
- const $f01a183cc7bdff77849e49ad26eb904$var$SSRContext = /*#__PURE__*/React__default['default'].createContext($f01a183cc7bdff77849e49ad26eb904$var$defaultContext);
11771
- let $f01a183cc7bdff77849e49ad26eb904$var$canUseDOM = Boolean(typeof window !== 'undefined' && window.document && window.document.createElement);
11772
- /** @private */
11773
-
11774
- function useSSRSafeId(defaultId) {
11775
- let ctx = React.useContext($f01a183cc7bdff77849e49ad26eb904$var$SSRContext); // If we are rendering in a non-DOM environment, and there's no SSRProvider,
11776
- // provide a warning to hint to the developer to add one.
11777
-
11778
- if (ctx === $f01a183cc7bdff77849e49ad26eb904$var$defaultContext && !$f01a183cc7bdff77849e49ad26eb904$var$canUseDOM) {
11779
- console.warn('When server rendering, you must wrap your application in an <SSRProvider> to ensure consistent ids are generated between the client and server.');
11780
- }
11781
-
11782
- return React.useMemo(() => defaultId || "react-aria-" + ctx.prefix + "-" + ++ctx.current, [defaultId]);
11783
- }
11784
- /**
11785
- * Returns whether the component is currently being server side rendered or
11786
- * hydrated on the client. Can be used to delay browser-specific rendering
11787
- * until after hydration.
11788
- */
11789
-
11790
- function useIsSSR() {
11791
- let cur = React.useContext($f01a183cc7bdff77849e49ad26eb904$var$SSRContext);
11792
- let isInSSRContext = cur !== $f01a183cc7bdff77849e49ad26eb904$var$defaultContext;
11793
- let [isSSR, setIsSSR] = React.useState(isInSSRContext); // If on the client, and the component was initially server rendered,
11794
- // then schedule a layout effect to update the component after hydration.
11795
-
11796
- if (typeof window !== 'undefined' && isInSSRContext) {
11797
- // This if statement technically breaks the rules of hooks, but is safe
11798
- // because the condition never changes after mounting.
11799
- // eslint-disable-next-line react-hooks/rules-of-hooks
11800
- React.useLayoutEffect(() => {
11801
- setIsSSR(false);
11802
- }, []);
11803
- }
11804
-
11805
- return isSSR;
11806
- }
11807
-
11808
- /*
11809
- * Copyright 2020 Adobe. All rights reserved.
11810
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
11811
- * you may not use this file except in compliance with the License. You may obtain a copy
11812
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
11813
- *
11814
- * Unless required by applicable law or agreed to in writing, software distributed under
11815
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
11816
- * OF ANY KIND, either express or implied. See the License for the specific language
11817
- * governing permissions and limitations under the License.
11818
- */
11819
- // https://en.wikipedia.org/wiki/Right-to-left
11820
- const $d26e725ad56fbcb2c25f52b7de27$var$RTL_SCRIPTS = new Set(['Arab', 'Syrc', 'Samr', 'Mand', 'Thaa', 'Mend', 'Nkoo', 'Adlm', 'Rohg', 'Hebr']);
11821
- const $d26e725ad56fbcb2c25f52b7de27$var$RTL_LANGS = new Set(['ae', 'ar', 'arc', 'bcc', 'bqi', 'ckb', 'dv', 'fa', 'glk', 'he', 'ku', 'mzn', 'nqo', 'pnb', 'ps', 'sd', 'ug', 'ur', 'yi']);
11822
- /**
11823
- * Determines if a locale is read right to left using [Intl.Locale]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale}.
11824
- */
11825
-
11826
- function $d26e725ad56fbcb2c25f52b7de27$export$isRTL(locale) {
11827
- // If the Intl.Locale API is available, use it to get the script for the locale.
11828
- // This is more accurate than guessing by language, since languages can be written in multiple scripts.
11829
- // @ts-ignore
11830
- if (Intl.Locale) {
11831
- // @ts-ignore
11832
- let script = new Intl.Locale(locale).maximize().script;
11833
- return $d26e725ad56fbcb2c25f52b7de27$var$RTL_SCRIPTS.has(script);
11834
- } // If not, just guess by the language (first part of the locale)
11835
-
11836
-
11837
- let lang = locale.split('-')[0];
11838
- return $d26e725ad56fbcb2c25f52b7de27$var$RTL_LANGS.has(lang);
11839
- }
11840
-
11841
- /**
11842
- * Gets the locale setting of the browser.
11843
- */
11844
- function $e851d0b81d46abd5f971c8e95c27f1$export$getDefaultLocale() {
11845
- // @ts-ignore
11846
- let locale = typeof navigator !== 'undefined' && (navigator.language || navigator.userLanguage) || 'en-US';
11847
- return {
11848
- locale,
11849
- direction: $d26e725ad56fbcb2c25f52b7de27$export$isRTL(locale) ? 'rtl' : 'ltr'
11850
- };
11851
- }
11852
-
11853
- let $e851d0b81d46abd5f971c8e95c27f1$var$currentLocale = $e851d0b81d46abd5f971c8e95c27f1$export$getDefaultLocale();
11854
- let $e851d0b81d46abd5f971c8e95c27f1$var$listeners = new Set();
11855
-
11856
- function $e851d0b81d46abd5f971c8e95c27f1$var$updateLocale() {
11857
- $e851d0b81d46abd5f971c8e95c27f1$var$currentLocale = $e851d0b81d46abd5f971c8e95c27f1$export$getDefaultLocale();
11858
-
11859
- for (let listener of $e851d0b81d46abd5f971c8e95c27f1$var$listeners) {
11860
- listener($e851d0b81d46abd5f971c8e95c27f1$var$currentLocale);
11861
- }
11862
- }
11863
- /**
11864
- * Returns the current browser/system language, and updates when it changes.
11865
- */
11866
-
11867
-
11868
- function $e851d0b81d46abd5f971c8e95c27f1$export$useDefaultLocale() {
11869
- let isSSR = useIsSSR();
11870
- let [defaultLocale, setDefaultLocale] = React.useState($e851d0b81d46abd5f971c8e95c27f1$var$currentLocale);
11871
- React.useEffect(() => {
11872
- if ($e851d0b81d46abd5f971c8e95c27f1$var$listeners.size === 0) {
11873
- window.addEventListener('languagechange', $e851d0b81d46abd5f971c8e95c27f1$var$updateLocale);
11874
- }
11875
-
11876
- $e851d0b81d46abd5f971c8e95c27f1$var$listeners.add(setDefaultLocale);
11877
- return () => {
11878
- $e851d0b81d46abd5f971c8e95c27f1$var$listeners.delete(setDefaultLocale);
11879
-
11880
- if ($e851d0b81d46abd5f971c8e95c27f1$var$listeners.size === 0) {
11881
- window.removeEventListener('languagechange', $e851d0b81d46abd5f971c8e95c27f1$var$updateLocale);
11882
- }
11883
- };
11884
- }, []); // We cannot determine the browser's language on the server, so default to
11885
- // en-US. This will be updated after hydration on the client to the correct value.
11886
-
11887
- if (isSSR) {
11888
- return {
11889
- locale: 'en-US',
11890
- direction: 'ltr'
11891
- };
11892
- }
11893
-
11894
- return defaultLocale;
11895
- }
11896
-
11897
- const $cff8541df3b5c83067b2ab3ee0d20$var$I18nContext = /*#__PURE__*/React__default['default'].createContext(null);
11898
- /**
11899
- * Returns the current locale and layout direction.
11900
- */
11901
-
11902
- function useLocale() {
11903
- let defaultLocale = $e851d0b81d46abd5f971c8e95c27f1$export$useDefaultLocale();
11904
- let context = React.useContext($cff8541df3b5c83067b2ab3ee0d20$var$I18nContext);
11905
- return context || defaultLocale;
11906
- }
11907
-
11908
- // During SSR, React emits a warning when calling useLayoutEffect.
11909
- // Since neither useLayoutEffect nor useEffect run on the server,
11910
- // we can suppress this by replace it with a noop on the server.
11911
- const useLayoutEffect = typeof window !== 'undefined' ? React__default['default'].useLayoutEffect : () => {};
11912
- let $f8b5fdd96fb429d7102983f777c41307$var$idsUpdaterMap = new Map();
11913
- /**
11914
- * If a default is not provided, generate an id.
11915
- * @param defaultId - Default component id.
11916
- */
11917
-
11918
- function useId(defaultId) {
11919
- let isRendering = React.useRef(true);
11920
- isRendering.current = true;
11921
- let [value, setValue] = React.useState(defaultId);
11922
- let nextId = React.useRef(null);
11923
- let res = useSSRSafeId(value); // don't memo this, we want it new each render so that the Effects always run
11924
-
11925
- let updateValue = val => {
11926
- if (!isRendering.current) {
11927
- setValue(val);
11928
- } else {
11929
- nextId.current = val;
11930
- }
11931
- };
11932
-
11933
- $f8b5fdd96fb429d7102983f777c41307$var$idsUpdaterMap.set(res, updateValue);
11934
- useLayoutEffect(() => {
11935
- isRendering.current = false;
11936
- }, [updateValue]);
11937
- useLayoutEffect(() => {
11938
- let r = res;
11939
- return () => {
11940
- $f8b5fdd96fb429d7102983f777c41307$var$idsUpdaterMap.delete(r);
11941
- };
11942
- }, [res]);
11943
- React.useEffect(() => {
11944
- let newId = nextId.current;
11945
-
11946
- if (newId) {
11947
- setValue(newId);
11948
- nextId.current = null;
11949
- }
11950
- }, [setValue, updateValue]);
11951
- return res;
11952
- }
11953
- /**
11954
- * Merges two ids.
11955
- * Different ids will trigger a side-effect and re-render components hooked up with `useId`.
11956
- */
11957
-
11958
- function mergeIds(idA, idB) {
11959
- if (idA === idB) {
11960
- return idA;
11961
- }
11962
-
11963
- let setIdA = $f8b5fdd96fb429d7102983f777c41307$var$idsUpdaterMap.get(idA);
11964
-
11965
- if (setIdA) {
11966
- setIdA(idB);
11967
- return idB;
11968
- }
11969
-
11970
- let setIdB = $f8b5fdd96fb429d7102983f777c41307$var$idsUpdaterMap.get(idB);
11971
-
11972
- if (setIdB) {
11973
- setIdB(idA);
11974
- return idA;
11975
- }
11976
-
11977
- return idB;
11978
- }
11979
-
11980
- /*
11981
- * Copyright 2020 Adobe. All rights reserved.
11982
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
11983
- * you may not use this file except in compliance with the License. You may obtain a copy
11984
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
11985
- *
11986
- * Unless required by applicable law or agreed to in writing, software distributed under
11987
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
11988
- * OF ANY KIND, either express or implied. See the License for the specific language
11989
- * governing permissions and limitations under the License.
11990
- */
11991
-
11992
- /**
11993
- * Calls all functions in the order they were chained with the same arguments.
11994
- */
11995
- function chain() {
11996
- for (var _len = arguments.length, callbacks = new Array(_len), _key = 0; _key < _len; _key++) {
11997
- callbacks[_key] = arguments[_key];
11998
- }
11999
-
12000
- return function () {
12001
- for (let callback of callbacks) {
12002
- if (typeof callback === 'function') {
12003
- callback(...arguments);
12004
- }
12005
- }
12006
- };
12007
- }
12008
-
12009
- /**
12010
- * Merges multiple props objects together. Event handlers are chained,
12011
- * classNames are combined, and ids are deduplicated - different ids
12012
- * will trigger a side-effect and re-render components hooked up with `useId`.
12013
- * For all other props, the last prop object overrides all previous ones.
12014
- * @param args - Multiple sets of props to merge together.
12015
- */
12016
- function mergeProps() {
12017
- let result = {};
12018
-
12019
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
12020
- args[_key] = arguments[_key];
12021
- }
12022
-
12023
- for (let props of args) {
12024
- for (let key in result) {
12025
- // Chain events
12026
- if (/^on[A-Z]/.test(key) && typeof result[key] === 'function' && typeof props[key] === 'function') {
12027
- result[key] = chain(result[key], props[key]); // Merge classnames, sometimes classNames are empty string which eval to false, so we just need to do a type check
12028
- } else if (key === 'className' && typeof result.className === 'string' && typeof props.className === 'string') {
12029
- result[key] = clsx__default['default'](result.className, props.className);
12030
- } else if (key === 'UNSAFE_className' && typeof result.UNSAFE_className === 'string' && typeof props.UNSAFE_className === 'string') {
12031
- result[key] = clsx__default['default'](result.UNSAFE_className, props.UNSAFE_className);
12032
- } else if (key === 'id' && result.id && props.id) {
12033
- result.id = mergeIds(result.id, props.id); // Override others
12034
- } else {
12035
- result[key] = props[key] !== undefined ? props[key] : result[key];
12036
- }
12037
- } // Add props from b that are not in a
12038
-
12039
-
12040
- for (let key in props) {
12041
- if (result[key] === undefined) {
12042
- result[key] = props[key];
12043
- }
12044
- }
12045
- }
12046
-
12047
- return result;
12048
- }
12049
- // Currently necessary for Safari and old Edge:
12050
- // https://caniuse.com/#feat=mdn-api_htmlelement_focus_preventscroll_option
12051
- // See https://bugs.webkit.org/show_bug.cgi?id=178583
12052
- //
12053
- // Original licensing for the following methods can be found in the
12054
- // NOTICE file in the root directory of this source tree.
12055
- // See https://github.com/calvellido/focus-options-polyfill
12056
- function focusWithoutScrolling(element) {
12057
- if ($bc7c9c3af78f5218ff72cecce15730$var$supportsPreventScroll()) {
12058
- element.focus({
12059
- preventScroll: true
12060
- });
12061
- } else {
12062
- let scrollableElements = $bc7c9c3af78f5218ff72cecce15730$var$getScrollableElements(element);
12063
- element.focus();
12064
- $bc7c9c3af78f5218ff72cecce15730$var$restoreScrollPosition(scrollableElements);
12065
- }
12066
- }
12067
- let $bc7c9c3af78f5218ff72cecce15730$var$supportsPreventScrollCached = null;
12068
-
12069
- function $bc7c9c3af78f5218ff72cecce15730$var$supportsPreventScroll() {
12070
- if ($bc7c9c3af78f5218ff72cecce15730$var$supportsPreventScrollCached == null) {
12071
- $bc7c9c3af78f5218ff72cecce15730$var$supportsPreventScrollCached = false;
12072
-
12073
- try {
12074
- var focusElem = document.createElement('div');
12075
- focusElem.focus({
12076
- get preventScroll() {
12077
- $bc7c9c3af78f5218ff72cecce15730$var$supportsPreventScrollCached = true;
12078
- return true;
12079
- }
12080
-
12081
- });
12082
- } catch (e) {// Ignore
12083
- }
12084
- }
12085
-
12086
- return $bc7c9c3af78f5218ff72cecce15730$var$supportsPreventScrollCached;
12087
- }
12088
-
12089
- function $bc7c9c3af78f5218ff72cecce15730$var$getScrollableElements(element) {
12090
- var parent = element.parentNode;
12091
- var scrollableElements = [];
12092
- var rootScrollingElement = document.scrollingElement || document.documentElement;
12093
-
12094
- while (parent instanceof HTMLElement && parent !== rootScrollingElement) {
12095
- if (parent.offsetHeight < parent.scrollHeight || parent.offsetWidth < parent.scrollWidth) {
12096
- scrollableElements.push({
12097
- element: parent,
12098
- scrollTop: parent.scrollTop,
12099
- scrollLeft: parent.scrollLeft
12100
- });
12101
- }
12102
-
12103
- parent = parent.parentNode;
12104
- }
12105
-
12106
- if (rootScrollingElement instanceof HTMLElement) {
12107
- scrollableElements.push({
12108
- element: rootScrollingElement,
12109
- scrollTop: rootScrollingElement.scrollTop,
12110
- scrollLeft: rootScrollingElement.scrollLeft
12111
- });
12112
- }
12113
-
12114
- return scrollableElements;
12115
- }
12116
-
12117
- function $bc7c9c3af78f5218ff72cecce15730$var$restoreScrollPosition(scrollableElements) {
12118
- for (let {
12119
- element,
12120
- scrollTop,
12121
- scrollLeft
12122
- } of scrollableElements) {
12123
- element.scrollTop = scrollTop;
12124
- element.scrollLeft = scrollLeft;
12125
- }
12126
- }
12127
- // mapped to a set of CSS properties that are transitioning for that element.
12128
- // This is necessary rather than a simple count of transitions because of browser
12129
- // bugs, e.g. Chrome sometimes fires both transitionend and transitioncancel rather
12130
- // than one or the other. So we need to track what's actually transitioning so that
12131
- // we can ignore these duplicate events.
12132
- let $b3e8d5c5f32fa26afa6df1b81f09b6b8$var$transitionsByElement = new Map(); // A list of callbacks to call once there are no transitioning elements.
12133
-
12134
- let $b3e8d5c5f32fa26afa6df1b81f09b6b8$var$transitionCallbacks = new Set();
12135
-
12136
- function $b3e8d5c5f32fa26afa6df1b81f09b6b8$var$setupGlobalEvents() {
12137
- if (typeof window === 'undefined') {
12138
- return;
12139
- }
12140
-
12141
- let onTransitionStart = e => {
12142
- // Add the transitioning property to the list for this element.
12143
- let transitions = $b3e8d5c5f32fa26afa6df1b81f09b6b8$var$transitionsByElement.get(e.target);
12144
-
12145
- if (!transitions) {
12146
- transitions = new Set();
12147
- $b3e8d5c5f32fa26afa6df1b81f09b6b8$var$transitionsByElement.set(e.target, transitions); // The transitioncancel event must be registered on the element itself, rather than as a global
12148
- // event. This enables us to handle when the node is deleted from the document while it is transitioning.
12149
- // In that case, the cancel event would have nowhere to bubble to so we need to handle it directly.
12150
-
12151
- e.target.addEventListener('transitioncancel', onTransitionEnd);
12152
- }
12153
-
12154
- transitions.add(e.propertyName);
12155
- };
12156
-
12157
- let onTransitionEnd = e => {
12158
- // Remove property from list of transitioning properties.
12159
- let properties = $b3e8d5c5f32fa26afa6df1b81f09b6b8$var$transitionsByElement.get(e.target);
12160
-
12161
- if (!properties) {
12162
- return;
12163
- }
12164
-
12165
- properties.delete(e.propertyName); // If empty, remove transitioncancel event, and remove the element from the list of transitioning elements.
12166
-
12167
- if (properties.size === 0) {
12168
- e.target.removeEventListener('transitioncancel', onTransitionEnd);
12169
- $b3e8d5c5f32fa26afa6df1b81f09b6b8$var$transitionsByElement.delete(e.target);
12170
- } // If no transitioning elements, call all of the queued callbacks.
12171
-
12172
-
12173
- if ($b3e8d5c5f32fa26afa6df1b81f09b6b8$var$transitionsByElement.size === 0) {
12174
- for (let cb of $b3e8d5c5f32fa26afa6df1b81f09b6b8$var$transitionCallbacks) {
12175
- cb();
12176
- }
12177
-
12178
- $b3e8d5c5f32fa26afa6df1b81f09b6b8$var$transitionCallbacks.clear();
12179
- }
12180
- };
12181
-
12182
- document.body.addEventListener('transitionrun', onTransitionStart);
12183
- document.body.addEventListener('transitionend', onTransitionEnd);
12184
- }
12185
-
12186
- if (typeof document !== 'undefined') {
12187
- if (document.readyState !== 'loading') {
12188
- $b3e8d5c5f32fa26afa6df1b81f09b6b8$var$setupGlobalEvents();
12189
- } else {
12190
- document.addEventListener('DOMContentLoaded', $b3e8d5c5f32fa26afa6df1b81f09b6b8$var$setupGlobalEvents);
12191
- }
12192
- }
12193
-
12194
- function runAfterTransition(fn) {
12195
- // Wait one frame to see if an animation starts, e.g. a transition on mount.
12196
- requestAnimationFrame(() => {
12197
- // If no transitions are running, call the function immediately.
12198
- // Otherwise, add it to a list of callbacks to run at the end of the animation.
12199
- if ($b3e8d5c5f32fa26afa6df1b81f09b6b8$var$transitionsByElement.size === 0) {
12200
- fn();
12201
- } else {
12202
- $b3e8d5c5f32fa26afa6df1b81f09b6b8$var$transitionCallbacks.add(fn);
12203
- }
12204
- });
12205
- }
12206
- function useGlobalListeners() {
12207
- let globalListeners = React.useRef(new Map());
12208
- let addGlobalListener = React.useCallback((eventTarget, type, listener, options) => {
12209
- globalListeners.current.set(listener, {
12210
- type,
12211
- eventTarget,
12212
- options
12213
- });
12214
- eventTarget.addEventListener(type, listener, options);
12215
- }, []);
12216
- let removeGlobalListener = React.useCallback((eventTarget, type, listener, options) => {
12217
- eventTarget.removeEventListener(type, listener, options);
12218
- globalListeners.current.delete(listener);
12219
- }, []);
12220
- let removeAllGlobalListeners = React.useCallback(() => {
12221
- globalListeners.current.forEach((value, key) => {
12222
- removeGlobalListener(value.eventTarget, value.type, key, value.options);
12223
- });
12224
- }, [removeGlobalListener]); // eslint-disable-next-line arrow-body-style
12225
-
12226
- React.useEffect(() => {
12227
- return removeAllGlobalListeners;
12228
- }, [removeAllGlobalListeners]);
12229
- return {
12230
- addGlobalListener,
12231
- removeGlobalListener,
12232
- removeAllGlobalListeners
12233
- };
12234
- }
12235
-
12236
- /**
12237
- * Merges aria-label and aria-labelledby into aria-labelledby when both exist.
12238
- * @param props - Aria label props.
12239
- * @param defaultLabel - Default value for aria-label when not present.
12240
- */
12241
- function useLabels(props, defaultLabel) {
12242
- let {
12243
- id,
12244
- 'aria-label': label,
12245
- 'aria-labelledby': labelledBy
12246
- } = props; // If there is both an aria-label and aria-labelledby,
12247
- // combine them by pointing to the element itself.
12248
-
12249
- id = useId(id);
12250
-
12251
- if (labelledBy && label) {
12252
- let ids = new Set([...labelledBy.trim().split(/\s+/), id]);
12253
- labelledBy = [...ids].join(' ');
12254
- } else if (labelledBy) {
12255
- labelledBy = labelledBy.trim().split(/\s+/).join(' ');
12256
- } // If no labels are provided, use the default
12257
-
12258
-
12259
- if (!label && !labelledBy && defaultLabel) {
12260
- label = defaultLabel;
12261
- }
12262
-
12263
- return {
12264
- id,
12265
- 'aria-label': label,
12266
- 'aria-labelledby': labelledBy
12267
- };
12268
- }
12269
- // Syncs ref from context with ref passed to hook
12270
- function useSyncRef(context, ref) {
12271
- useLayoutEffect(() => {
12272
- if (context && context.ref && ref) {
12273
- context.ref.current = ref.current;
12274
- return () => {
12275
- context.ref.current = null;
12276
- };
12277
- }
12278
- }, [context, ref]);
12279
- }
12280
-
12281
- function $b0986c1243f71db8e992f67117a1ed9$var$testPlatform(re) {
12282
- return typeof window !== 'undefined' && window.navigator != null ? re.test(window.navigator.platform) : false;
12283
- }
12284
-
12285
- function isMac() {
12286
- return $b0986c1243f71db8e992f67117a1ed9$var$testPlatform(/^Mac/);
12287
- }
12288
-
12289
- function _objectWithoutPropertiesLoose(source, excluded) {
12290
- if (source == null) return {};
12291
- var target = {};
12292
- var sourceKeys = Object.keys(source);
12293
- var key, i;
12294
-
12295
- for (i = 0; i < sourceKeys.length; i++) {
12296
- key = sourceKeys[i];
12297
- if (excluded.indexOf(key) >= 0) continue;
12298
- target[key] = source[key];
12299
- }
12300
-
12301
- return target;
12302
- }
12303
-
12304
- let $e17c9db826984f8ab8e5d837bf0b8$var$state = 'default';
12305
- let $e17c9db826984f8ab8e5d837bf0b8$var$savedUserSelect = '';
12306
-
12307
- function $e17c9db826984f8ab8e5d837bf0b8$export$disableTextSelection() {
12308
- if ($e17c9db826984f8ab8e5d837bf0b8$var$state === 'default') {
12309
- $e17c9db826984f8ab8e5d837bf0b8$var$savedUserSelect = document.documentElement.style.webkitUserSelect;
12310
- document.documentElement.style.webkitUserSelect = 'none';
12311
- }
12312
-
12313
- $e17c9db826984f8ab8e5d837bf0b8$var$state = 'disabled';
12314
- }
12315
-
12316
- function $e17c9db826984f8ab8e5d837bf0b8$export$restoreTextSelection() {
12317
- // If the state is already default, there's nothing to do.
12318
- // If it is restoring, then there's no need to queue a second restore.
12319
- if ($e17c9db826984f8ab8e5d837bf0b8$var$state !== 'disabled') {
12320
- return;
12321
- }
12322
-
12323
- $e17c9db826984f8ab8e5d837bf0b8$var$state = 'restoring'; // There appears to be a delay on iOS where selection still might occur
12324
- // after pointer up, so wait a bit before removing user-select.
12325
-
12326
- setTimeout(() => {
12327
- // Wait for any CSS transitions to complete so we don't recompute style
12328
- // for the whole page in the middle of the animation and cause jank.
12329
- runAfterTransition(() => {
12330
- // Avoid race conditions
12331
- if ($e17c9db826984f8ab8e5d837bf0b8$var$state === 'restoring') {
12332
- if (document.documentElement.style.webkitUserSelect === 'none') {
12333
- document.documentElement.style.webkitUserSelect = $e17c9db826984f8ab8e5d837bf0b8$var$savedUserSelect || '';
12334
- }
12335
-
12336
- $e17c9db826984f8ab8e5d837bf0b8$var$savedUserSelect = '';
12337
- $e17c9db826984f8ab8e5d837bf0b8$var$state = 'default';
12338
- }
12339
- });
12340
- }, 300);
12341
- }
12342
-
12343
- /*
12344
- * Copyright 2020 Adobe. All rights reserved.
12345
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
12346
- * you may not use this file except in compliance with the License. You may obtain a copy
12347
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
12348
- *
12349
- * Unless required by applicable law or agreed to in writing, software distributed under
12350
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
12351
- * OF ANY KIND, either express or implied. See the License for the specific language
12352
- * governing permissions and limitations under the License.
12353
- */
12354
- // Original licensing for the following method can be found in the
12355
- // NOTICE file in the root directory of this source tree.
12356
- // See https://github.com/facebook/react/blob/3c713d513195a53788b3f8bb4b70279d68b15bcc/packages/react-interactions/events/src/dom/shared/index.js#L74-L87
12357
- // Keyboards, Assistive Technologies, and element.click() all produce a "virtual"
12358
- // click event. This is a method of inferring such clicks. Every browser except
12359
- // IE 11 only sets a zero value of "detail" for click events that are "virtual".
12360
- // However, IE 11 uses a zero value for all click events. For IE 11 we rely on
12361
- // the quirk that it produces click events that are of type PointerEvent, and
12362
- // where only the "virtual" click lacks a pointerType field.
12363
- function $f67ef9f1b8ed09b4b00fd0840cd8b94b$export$isVirtualClick(event) {
12364
- // JAWS/NVDA with Firefox.
12365
- if (event.mozInputSource === 0 && event.isTrusted) {
12366
- return true;
12367
- }
12368
-
12369
- return event.detail === 0 && !event.pointerType;
12370
- }
12371
-
12372
- const $a3ff51240de6f955c79cf17a88e349$export$PressResponderContext = /*#__PURE__*/React__default['default'].createContext(null);
12373
-
12374
- $a3ff51240de6f955c79cf17a88e349$export$PressResponderContext.displayName = 'PressResponderContext';
12375
-
12376
- function $ffc54430b1dbeee65879852feaaff07d$var$usePressResponderContext(props) {
12377
- // Consume context from <PressResponder> and merge with props.
12378
- let context = React.useContext($a3ff51240de6f955c79cf17a88e349$export$PressResponderContext);
12379
-
12380
- if (context) {
12381
- let {
12382
- register
12383
- } = context,
12384
- contextProps = _objectWithoutPropertiesLoose(context, ["register"]);
12385
-
12386
- props = mergeProps(contextProps, props);
12387
- register();
12388
- }
12389
-
12390
- useSyncRef(context, props.ref);
12391
- return props;
12392
- }
12393
- /**
12394
- * Handles press interactions across mouse, touch, keyboard, and screen readers.
12395
- * It normalizes behavior across browsers and platforms, and handles many nuances
12396
- * of dealing with pointer and keyboard events.
12397
- */
12398
-
12399
-
12400
- function usePress(props) {
12401
- let _usePressResponderCon = $ffc54430b1dbeee65879852feaaff07d$var$usePressResponderContext(props),
12402
- {
12403
- onPress,
12404
- onPressChange,
12405
- onPressStart,
12406
- onPressEnd,
12407
- onPressUp,
12408
- isDisabled,
12409
- isPressed: isPressedProp,
12410
- preventFocusOnPress
12411
- } = _usePressResponderCon,
12412
- domProps = _objectWithoutPropertiesLoose(_usePressResponderCon, ["onPress", "onPressChange", "onPressStart", "onPressEnd", "onPressUp", "isDisabled", "isPressed", "preventFocusOnPress", "ref"]);
12413
-
12414
- let propsRef = React.useRef(null);
12415
- propsRef.current = {
12416
- onPress,
12417
- onPressChange,
12418
- onPressStart,
12419
- onPressEnd,
12420
- onPressUp,
12421
- isDisabled
12422
- };
12423
- let [isPressed, setPressed] = React.useState(false);
12424
- let ref = React.useRef({
12425
- isPressed: false,
12426
- ignoreEmulatedMouseEvents: false,
12427
- ignoreClickAfterPress: false,
12428
- didFirePressStart: false,
12429
- activePointerId: null,
12430
- target: null,
12431
- isOverTarget: false,
12432
- pointerType: null
12433
- });
12434
- let {
12435
- addGlobalListener,
12436
- removeAllGlobalListeners
12437
- } = useGlobalListeners();
12438
- let pressProps = React.useMemo(() => {
12439
- let state = ref.current;
12440
-
12441
- let triggerPressStart = (originalEvent, pointerType) => {
12442
- let {
12443
- onPressStart,
12444
- onPressChange,
12445
- isDisabled
12446
- } = propsRef.current;
12447
-
12448
- if (isDisabled || state.didFirePressStart) {
12449
- return;
12450
- }
12451
-
12452
- if (onPressStart) {
12453
- onPressStart({
12454
- type: 'pressstart',
12455
- pointerType,
12456
- target: originalEvent.currentTarget,
12457
- shiftKey: originalEvent.shiftKey,
12458
- metaKey: originalEvent.metaKey,
12459
- ctrlKey: originalEvent.ctrlKey
12460
- });
12461
- }
12462
-
12463
- if (onPressChange) {
12464
- onPressChange(true);
12465
- }
12466
-
12467
- state.didFirePressStart = true;
12468
- setPressed(true);
12469
- };
12470
-
12471
- let triggerPressEnd = function triggerPressEnd(originalEvent, pointerType, wasPressed) {
12472
- if (wasPressed === void 0) {
12473
- wasPressed = true;
12474
- }
12475
-
12476
- let {
12477
- onPressEnd,
12478
- onPressChange,
12479
- onPress,
12480
- isDisabled
12481
- } = propsRef.current;
12482
-
12483
- if (!state.didFirePressStart) {
12484
- return;
12485
- }
12486
-
12487
- state.ignoreClickAfterPress = true;
12488
- state.didFirePressStart = false;
12489
-
12490
- if (onPressEnd) {
12491
- onPressEnd({
12492
- type: 'pressend',
12493
- pointerType,
12494
- target: originalEvent.currentTarget,
12495
- shiftKey: originalEvent.shiftKey,
12496
- metaKey: originalEvent.metaKey,
12497
- ctrlKey: originalEvent.ctrlKey
12498
- });
12499
- }
12500
-
12501
- if (onPressChange) {
12502
- onPressChange(false);
12503
- }
12504
-
12505
- setPressed(false);
12506
-
12507
- if (onPress && wasPressed && !isDisabled) {
12508
- onPress({
12509
- type: 'press',
12510
- pointerType,
12511
- target: originalEvent.currentTarget,
12512
- shiftKey: originalEvent.shiftKey,
12513
- metaKey: originalEvent.metaKey,
12514
- ctrlKey: originalEvent.ctrlKey
12515
- });
12516
- }
12517
- };
12518
-
12519
- let triggerPressUp = (originalEvent, pointerType) => {
12520
- let {
12521
- onPressUp,
12522
- isDisabled
12523
- } = propsRef.current;
12524
-
12525
- if (isDisabled) {
12526
- return;
12527
- }
12528
-
12529
- if (onPressUp) {
12530
- onPressUp({
12531
- type: 'pressup',
12532
- pointerType,
12533
- target: originalEvent.currentTarget,
12534
- shiftKey: originalEvent.shiftKey,
12535
- metaKey: originalEvent.metaKey,
12536
- ctrlKey: originalEvent.ctrlKey
12537
- });
12538
- }
12539
- };
12540
-
12541
- let cancel = e => {
12542
- if (state.isPressed) {
12543
- if (state.isOverTarget) {
12544
- triggerPressEnd($ffc54430b1dbeee65879852feaaff07d$var$createEvent(state.target, e), state.pointerType, false);
12545
- }
12546
-
12547
- state.isPressed = false;
12548
- state.isOverTarget = false;
12549
- state.activePointerId = null;
12550
- state.pointerType = null;
12551
- removeAllGlobalListeners();
12552
- $e17c9db826984f8ab8e5d837bf0b8$export$restoreTextSelection();
12553
- }
12554
- };
12555
-
12556
- let pressProps = {
12557
- onKeyDown(e) {
12558
- if ($ffc54430b1dbeee65879852feaaff07d$var$isValidKeyboardEvent(e.nativeEvent) && e.currentTarget.contains(e.target)) {
12559
- e.preventDefault();
12560
- e.stopPropagation(); // If the event is repeating, it may have started on a different element
12561
- // after which focus moved to the current element. Ignore these events and
12562
- // only handle the first key down event.
12563
-
12564
- if (!state.isPressed && !e.repeat) {
12565
- state.target = e.currentTarget;
12566
- state.isPressed = true;
12567
- triggerPressStart(e, 'keyboard'); // Focus may move before the key up event, so register the event on the document
12568
- // instead of the same element where the key down event occurred.
12569
-
12570
- addGlobalListener(document, 'keyup', onKeyUp, false);
12571
- }
12572
- }
12573
- },
12574
-
12575
- onKeyUp(e) {
12576
- if ($ffc54430b1dbeee65879852feaaff07d$var$isValidKeyboardEvent(e.nativeEvent) && !e.repeat && e.currentTarget.contains(e.target)) {
12577
- triggerPressUp($ffc54430b1dbeee65879852feaaff07d$var$createEvent(state.target, e), 'keyboard');
12578
- }
12579
- },
12580
-
12581
- onClick(e) {
12582
- if (e && !e.currentTarget.contains(e.target)) {
12583
- return;
12584
- }
12585
-
12586
- if (e && e.button === 0) {
12587
- e.stopPropagation();
12588
-
12589
- if (isDisabled) {
12590
- e.preventDefault();
12591
- } // If triggered from a screen reader or by using element.click(),
12592
- // trigger as if it were a keyboard click.
12593
-
12594
-
12595
- if (!state.ignoreClickAfterPress && !state.ignoreEmulatedMouseEvents && $f67ef9f1b8ed09b4b00fd0840cd8b94b$export$isVirtualClick(e.nativeEvent)) {
12596
- // Ensure the element receives focus (VoiceOver on iOS does not do this)
12597
- if (!isDisabled && !preventFocusOnPress) {
12598
- focusWithoutScrolling(e.currentTarget);
12599
- }
12600
-
12601
- triggerPressStart(e, 'virtual');
12602
- triggerPressUp(e, 'virtual');
12603
- triggerPressEnd(e, 'virtual');
12604
- }
12605
-
12606
- state.ignoreEmulatedMouseEvents = false;
12607
- state.ignoreClickAfterPress = false;
12608
- }
12609
- }
12610
-
12611
- };
12612
-
12613
- let onKeyUp = e => {
12614
- if (state.isPressed && $ffc54430b1dbeee65879852feaaff07d$var$isValidKeyboardEvent(e)) {
12615
- e.preventDefault();
12616
- e.stopPropagation();
12617
- state.isPressed = false;
12618
- triggerPressEnd($ffc54430b1dbeee65879852feaaff07d$var$createEvent(state.target, e), 'keyboard', e.target === state.target);
12619
- removeAllGlobalListeners(); // If the target is a link, trigger the click method to open the URL,
12620
- // but defer triggering pressEnd until onClick event handler.
12621
-
12622
- if (e.target === state.target && $ffc54430b1dbeee65879852feaaff07d$var$isHTMLAnchorLink(state.target) || state.target.getAttribute('role') === 'link') {
12623
- state.target.click();
12624
- }
12625
- }
12626
- };
12627
-
12628
- if (typeof PointerEvent !== 'undefined') {
12629
- pressProps.onPointerDown = e => {
12630
- // Only handle left clicks, and ignore events that bubbled through portals.
12631
- if (e.button !== 0 || !e.currentTarget.contains(e.target)) {
12632
- return;
12633
- } // Due to browser inconsistencies, especially on mobile browsers, we prevent
12634
- // default on pointer down and handle focusing the pressable element ourselves.
12635
-
12636
-
12637
- if ($ffc54430b1dbeee65879852feaaff07d$var$shouldPreventDefault(e.target)) {
12638
- e.preventDefault();
12639
- } // iOS safari fires pointer events from VoiceOver (but only when outside an iframe...)
12640
- // https://bugs.webkit.org/show_bug.cgi?id=222627
12641
-
12642
-
12643
- state.pointerType = $ffc54430b1dbeee65879852feaaff07d$var$isVirtualPointerEvent(e.nativeEvent) ? 'virtual' : e.pointerType;
12644
- e.stopPropagation();
12645
-
12646
- if (!state.isPressed) {
12647
- state.isPressed = true;
12648
- state.isOverTarget = true;
12649
- state.activePointerId = e.pointerId;
12650
- state.target = e.currentTarget;
12651
-
12652
- if (!isDisabled && !preventFocusOnPress) {
12653
- focusWithoutScrolling(e.currentTarget);
12654
- }
12655
-
12656
- $e17c9db826984f8ab8e5d837bf0b8$export$disableTextSelection();
12657
- triggerPressStart(e, state.pointerType);
12658
- addGlobalListener(document, 'pointermove', onPointerMove, false);
12659
- addGlobalListener(document, 'pointerup', onPointerUp, false);
12660
- addGlobalListener(document, 'pointercancel', onPointerCancel, false);
12661
- }
12662
- };
12663
-
12664
- pressProps.onMouseDown = e => {
12665
- if (!e.currentTarget.contains(e.target)) {
12666
- return;
12667
- }
12668
-
12669
- if (e.button === 0) {
12670
- // Chrome and Firefox on touch Windows devices require mouse down events
12671
- // to be canceled in addition to pointer events, or an extra asynchronous
12672
- // focus event will be fired.
12673
- if ($ffc54430b1dbeee65879852feaaff07d$var$shouldPreventDefault(e.target)) {
12674
- e.preventDefault();
12675
- }
12676
-
12677
- e.stopPropagation();
12678
- }
12679
- };
12680
-
12681
- pressProps.onPointerUp = e => {
12682
- if (!e.currentTarget.contains(e.target)) {
12683
- return;
12684
- } // Only handle left clicks
12685
- // Safari on iOS sometimes fires pointerup events, even
12686
- // when the touch isn't over the target, so double check.
12687
-
12688
-
12689
- if (e.button === 0 && $ffc54430b1dbeee65879852feaaff07d$var$isOverTarget(e, e.currentTarget)) {
12690
- triggerPressUp(e, state.pointerType);
12691
- }
12692
- }; // Safari on iOS < 13.2 does not implement pointerenter/pointerleave events correctly.
12693
- // Use pointer move events instead to implement our own hit testing.
12694
- // See https://bugs.webkit.org/show_bug.cgi?id=199803
12695
-
12696
-
12697
- let onPointerMove = e => {
12698
- if (e.pointerId !== state.activePointerId) {
12699
- return;
12700
- }
12701
-
12702
- if ($ffc54430b1dbeee65879852feaaff07d$var$isOverTarget(e, state.target)) {
12703
- if (!state.isOverTarget) {
12704
- state.isOverTarget = true;
12705
- triggerPressStart($ffc54430b1dbeee65879852feaaff07d$var$createEvent(state.target, e), state.pointerType);
12706
- }
12707
- } else if (state.isOverTarget) {
12708
- state.isOverTarget = false;
12709
- triggerPressEnd($ffc54430b1dbeee65879852feaaff07d$var$createEvent(state.target, e), state.pointerType, false);
12710
- }
12711
- };
12712
-
12713
- let onPointerUp = e => {
12714
- if (e.pointerId === state.activePointerId && state.isPressed && e.button === 0) {
12715
- if ($ffc54430b1dbeee65879852feaaff07d$var$isOverTarget(e, state.target)) {
12716
- triggerPressEnd($ffc54430b1dbeee65879852feaaff07d$var$createEvent(state.target, e), state.pointerType);
12717
- } else if (state.isOverTarget) {
12718
- triggerPressEnd($ffc54430b1dbeee65879852feaaff07d$var$createEvent(state.target, e), state.pointerType, false);
12719
- }
12720
-
12721
- state.isPressed = false;
12722
- state.isOverTarget = false;
12723
- state.activePointerId = null;
12724
- state.pointerType = null;
12725
- removeAllGlobalListeners();
12726
- $e17c9db826984f8ab8e5d837bf0b8$export$restoreTextSelection();
12727
- }
12728
- };
12729
-
12730
- let onPointerCancel = e => {
12731
- cancel(e);
12732
- };
12733
-
12734
- pressProps.onDragStart = e => {
12735
- if (!e.currentTarget.contains(e.target)) {
12736
- return;
12737
- } // Safari does not call onPointerCancel when a drag starts, whereas Chrome and Firefox do.
12738
-
12739
-
12740
- cancel(e);
12741
- };
12742
- } else {
12743
- pressProps.onMouseDown = e => {
12744
- // Only handle left clicks
12745
- if (e.button !== 0 || !e.currentTarget.contains(e.target)) {
12746
- return;
12747
- } // Due to browser inconsistencies, especially on mobile browsers, we prevent
12748
- // default on mouse down and handle focusing the pressable element ourselves.
12749
-
12750
-
12751
- if ($ffc54430b1dbeee65879852feaaff07d$var$shouldPreventDefault(e.target)) {
12752
- e.preventDefault();
12753
- }
12754
-
12755
- e.stopPropagation();
12756
-
12757
- if (state.ignoreEmulatedMouseEvents) {
12758
- return;
12759
- }
12760
-
12761
- state.isPressed = true;
12762
- state.isOverTarget = true;
12763
- state.target = e.currentTarget;
12764
- state.pointerType = $f67ef9f1b8ed09b4b00fd0840cd8b94b$export$isVirtualClick(e.nativeEvent) ? 'virtual' : 'mouse';
12765
-
12766
- if (!isDisabled && !preventFocusOnPress) {
12767
- focusWithoutScrolling(e.currentTarget);
12768
- }
12769
-
12770
- triggerPressStart(e, state.pointerType);
12771
- addGlobalListener(document, 'mouseup', onMouseUp, false);
12772
- };
12773
-
12774
- pressProps.onMouseEnter = e => {
12775
- if (!e.currentTarget.contains(e.target)) {
12776
- return;
12777
- }
12778
-
12779
- e.stopPropagation();
12780
-
12781
- if (state.isPressed && !state.ignoreEmulatedMouseEvents) {
12782
- state.isOverTarget = true;
12783
- triggerPressStart(e, state.pointerType);
12784
- }
12785
- };
12786
-
12787
- pressProps.onMouseLeave = e => {
12788
- if (!e.currentTarget.contains(e.target)) {
12789
- return;
12790
- }
12791
-
12792
- e.stopPropagation();
12793
-
12794
- if (state.isPressed && !state.ignoreEmulatedMouseEvents) {
12795
- state.isOverTarget = false;
12796
- triggerPressEnd(e, state.pointerType, false);
12797
- }
12798
- };
12799
-
12800
- pressProps.onMouseUp = e => {
12801
- if (!e.currentTarget.contains(e.target)) {
12802
- return;
12803
- }
12804
-
12805
- if (!state.ignoreEmulatedMouseEvents && e.button === 0) {
12806
- triggerPressUp(e, state.pointerType);
12807
- }
12808
- };
12809
-
12810
- let onMouseUp = e => {
12811
- // Only handle left clicks
12812
- if (e.button !== 0) {
12813
- return;
12814
- }
12815
-
12816
- state.isPressed = false;
12817
- removeAllGlobalListeners();
12818
-
12819
- if (state.ignoreEmulatedMouseEvents) {
12820
- state.ignoreEmulatedMouseEvents = false;
12821
- return;
12822
- }
12823
-
12824
- if ($ffc54430b1dbeee65879852feaaff07d$var$isOverTarget(e, state.target)) {
12825
- triggerPressEnd($ffc54430b1dbeee65879852feaaff07d$var$createEvent(state.target, e), state.pointerType);
12826
- } else if (state.isOverTarget) {
12827
- triggerPressEnd($ffc54430b1dbeee65879852feaaff07d$var$createEvent(state.target, e), state.pointerType, false);
12828
- }
12829
-
12830
- state.isOverTarget = false;
12831
- };
12832
-
12833
- pressProps.onTouchStart = e => {
12834
- if (!e.currentTarget.contains(e.target)) {
12835
- return;
12836
- }
12837
-
12838
- e.stopPropagation();
12839
- let touch = $ffc54430b1dbeee65879852feaaff07d$var$getTouchFromEvent(e.nativeEvent);
12840
-
12841
- if (!touch) {
12842
- return;
12843
- }
12844
-
12845
- state.activePointerId = touch.identifier;
12846
- state.ignoreEmulatedMouseEvents = true;
12847
- state.isOverTarget = true;
12848
- state.isPressed = true;
12849
- state.target = e.currentTarget;
12850
- state.pointerType = 'touch'; // Due to browser inconsistencies, especially on mobile browsers, we prevent default
12851
- // on the emulated mouse event and handle focusing the pressable element ourselves.
12852
-
12853
- if (!isDisabled && !preventFocusOnPress) {
12854
- focusWithoutScrolling(e.currentTarget);
12855
- }
12856
-
12857
- $e17c9db826984f8ab8e5d837bf0b8$export$disableTextSelection();
12858
- triggerPressStart(e, state.pointerType);
12859
- addGlobalListener(window, 'scroll', onScroll, true);
12860
- };
12861
-
12862
- pressProps.onTouchMove = e => {
12863
- if (!e.currentTarget.contains(e.target)) {
12864
- return;
12865
- }
12866
-
12867
- e.stopPropagation();
12868
-
12869
- if (!state.isPressed) {
12870
- return;
12871
- }
12872
-
12873
- let touch = $ffc54430b1dbeee65879852feaaff07d$var$getTouchById(e.nativeEvent, state.activePointerId);
12874
-
12875
- if (touch && $ffc54430b1dbeee65879852feaaff07d$var$isOverTarget(touch, e.currentTarget)) {
12876
- if (!state.isOverTarget) {
12877
- state.isOverTarget = true;
12878
- triggerPressStart(e, state.pointerType);
12879
- }
12880
- } else if (state.isOverTarget) {
12881
- state.isOverTarget = false;
12882
- triggerPressEnd(e, state.pointerType, false);
12883
- }
12884
- };
12885
-
12886
- pressProps.onTouchEnd = e => {
12887
- if (!e.currentTarget.contains(e.target)) {
12888
- return;
12889
- }
12890
-
12891
- e.stopPropagation();
12892
-
12893
- if (!state.isPressed) {
12894
- return;
12895
- }
12896
-
12897
- let touch = $ffc54430b1dbeee65879852feaaff07d$var$getTouchById(e.nativeEvent, state.activePointerId);
12898
-
12899
- if (touch && $ffc54430b1dbeee65879852feaaff07d$var$isOverTarget(touch, e.currentTarget)) {
12900
- triggerPressUp(e, state.pointerType);
12901
- triggerPressEnd(e, state.pointerType);
12902
- } else if (state.isOverTarget) {
12903
- triggerPressEnd(e, state.pointerType, false);
12904
- }
12905
-
12906
- state.isPressed = false;
12907
- state.activePointerId = null;
12908
- state.isOverTarget = false;
12909
- state.ignoreEmulatedMouseEvents = true;
12910
- $e17c9db826984f8ab8e5d837bf0b8$export$restoreTextSelection();
12911
- removeAllGlobalListeners();
12912
- };
12913
-
12914
- pressProps.onTouchCancel = e => {
12915
- if (!e.currentTarget.contains(e.target)) {
12916
- return;
12917
- }
12918
-
12919
- e.stopPropagation();
12920
-
12921
- if (state.isPressed) {
12922
- cancel(e);
12923
- }
12924
- };
12925
-
12926
- let onScroll = e => {
12927
- if (state.isPressed && e.target.contains(state.target)) {
12928
- cancel({
12929
- currentTarget: state.target,
12930
- shiftKey: false,
12931
- ctrlKey: false,
12932
- metaKey: false
12933
- });
12934
- }
12935
- };
12936
-
12937
- pressProps.onDragStart = e => {
12938
- if (!e.currentTarget.contains(e.target)) {
12939
- return;
12940
- }
12941
-
12942
- cancel(e);
12943
- };
12944
- }
12945
-
12946
- return pressProps;
12947
- }, [addGlobalListener, isDisabled, preventFocusOnPress, removeAllGlobalListeners]); // Remove user-select: none in case component unmounts immediately after pressStart
12948
- // eslint-disable-next-line arrow-body-style
12949
-
12950
- React.useEffect(() => {
12951
- return () => $e17c9db826984f8ab8e5d837bf0b8$export$restoreTextSelection();
12952
- }, []);
12953
- return {
12954
- isPressed: isPressedProp || isPressed,
12955
- pressProps: mergeProps(domProps, pressProps)
12956
- };
12957
- }
12958
-
12959
- function $ffc54430b1dbeee65879852feaaff07d$var$isHTMLAnchorLink(target) {
12960
- return target.tagName === 'A' && target.hasAttribute('href');
12961
- }
12962
-
12963
- function $ffc54430b1dbeee65879852feaaff07d$var$isValidKeyboardEvent(event) {
12964
- const {
12965
- key,
12966
- target
12967
- } = event;
12968
- const element = target;
12969
- const {
12970
- tagName,
12971
- isContentEditable
12972
- } = element;
12973
- const role = element.getAttribute('role'); // Accessibility for keyboards. Space and Enter only.
12974
- // "Spacebar" is for IE 11
12975
-
12976
- return (key === 'Enter' || key === ' ' || key === 'Spacebar') && tagName !== 'INPUT' && tagName !== 'TEXTAREA' && isContentEditable !== true && ( // A link with a valid href should be handled natively,
12977
- // unless it also has role='button' and was triggered using Space.
12978
- !$ffc54430b1dbeee65879852feaaff07d$var$isHTMLAnchorLink(element) || role === 'button' && key !== 'Enter') && // An element with role='link' should only trigger with Enter key
12979
- !(role === 'link' && key !== 'Enter');
12980
- }
12981
-
12982
- function $ffc54430b1dbeee65879852feaaff07d$var$getTouchFromEvent(event) {
12983
- const {
12984
- targetTouches
12985
- } = event;
12986
-
12987
- if (targetTouches.length > 0) {
12988
- return targetTouches[0];
12989
- }
12990
-
12991
- return null;
12992
- }
12993
-
12994
- function $ffc54430b1dbeee65879852feaaff07d$var$getTouchById(event, pointerId) {
12995
- const changedTouches = event.changedTouches;
12996
-
12997
- for (let i = 0; i < changedTouches.length; i++) {
12998
- const touch = changedTouches[i];
12999
-
13000
- if (touch.identifier === pointerId) {
13001
- return touch;
13002
- }
13003
- }
13004
-
13005
- return null;
13006
- }
13007
-
13008
- function $ffc54430b1dbeee65879852feaaff07d$var$createEvent(target, e) {
13009
- return {
13010
- currentTarget: target,
13011
- shiftKey: e.shiftKey,
13012
- ctrlKey: e.ctrlKey,
13013
- metaKey: e.metaKey
13014
- };
13015
- }
13016
-
13017
- function $ffc54430b1dbeee65879852feaaff07d$var$getPointClientRect(point) {
13018
- let offsetX = point.width / 2 || point.radiusX || 0;
13019
- let offsetY = point.height / 2 || point.radiusY || 0;
13020
- return {
13021
- top: point.clientY - offsetY,
13022
- right: point.clientX + offsetX,
13023
- bottom: point.clientY + offsetY,
13024
- left: point.clientX - offsetX
13025
- };
13026
- }
13027
-
13028
- function $ffc54430b1dbeee65879852feaaff07d$var$areRectanglesOverlapping(a, b) {
13029
- // check if they cannot overlap on x axis
13030
- if (a.left > b.right || b.left > a.right) {
13031
- return false;
13032
- } // check if they cannot overlap on y axis
13033
-
13034
-
13035
- if (a.top > b.bottom || b.top > a.bottom) {
13036
- return false;
13037
- }
13038
-
13039
- return true;
13040
- }
13041
-
13042
- function $ffc54430b1dbeee65879852feaaff07d$var$isOverTarget(point, target) {
13043
- let rect = target.getBoundingClientRect();
13044
- let pointRect = $ffc54430b1dbeee65879852feaaff07d$var$getPointClientRect(point);
13045
- return $ffc54430b1dbeee65879852feaaff07d$var$areRectanglesOverlapping(rect, pointRect);
13046
- }
13047
-
13048
- function $ffc54430b1dbeee65879852feaaff07d$var$shouldPreventDefault(target) {
13049
- // We cannot prevent default if the target is inside a draggable element.
13050
- return !target.closest('[draggable="true"]');
13051
- }
13052
-
13053
- function $ffc54430b1dbeee65879852feaaff07d$var$isVirtualPointerEvent(event) {
13054
- // If the pointer size is zero, then we assume it's from a screen reader.
13055
- return event.width === 0 && event.height === 0;
13056
- }
13057
- let $d01f69bb2ab5f70dfd0005370a2a2cbc$var$currentModality = null;
13058
- let $d01f69bb2ab5f70dfd0005370a2a2cbc$var$changeHandlers = new Set();
13059
- let $d01f69bb2ab5f70dfd0005370a2a2cbc$var$hasSetupGlobalListeners = false;
13060
- let $d01f69bb2ab5f70dfd0005370a2a2cbc$var$hasEventBeforeFocus = false;
13061
- let $d01f69bb2ab5f70dfd0005370a2a2cbc$var$hasBlurredWindowRecently = false; // Only Tab or Esc keys will make focus visible on text input elements
13062
-
13063
- function $d01f69bb2ab5f70dfd0005370a2a2cbc$var$triggerChangeHandlers(modality, e) {
13064
- for (let handler of $d01f69bb2ab5f70dfd0005370a2a2cbc$var$changeHandlers) {
13065
- handler(modality, e);
13066
- }
13067
- }
13068
- /**
13069
- * Helper function to determine if a KeyboardEvent is unmodified and could make keyboard focus styles visible.
13070
- */
13071
-
13072
-
13073
- function $d01f69bb2ab5f70dfd0005370a2a2cbc$var$isValidKey(e) {
13074
- // Control and Shift keys trigger when navigating back to the tab with keyboard.
13075
- return !(e.metaKey || !isMac() && e.altKey || e.ctrlKey || e.type === 'keyup' && (e.key === 'Control' || e.key === 'Shift'));
13076
- }
13077
-
13078
- function $d01f69bb2ab5f70dfd0005370a2a2cbc$var$handleKeyboardEvent(e) {
13079
- $d01f69bb2ab5f70dfd0005370a2a2cbc$var$hasEventBeforeFocus = true;
13080
-
13081
- if ($d01f69bb2ab5f70dfd0005370a2a2cbc$var$isValidKey(e)) {
13082
- $d01f69bb2ab5f70dfd0005370a2a2cbc$var$currentModality = 'keyboard';
13083
- $d01f69bb2ab5f70dfd0005370a2a2cbc$var$triggerChangeHandlers('keyboard', e);
13084
- }
13085
- }
13086
-
13087
- function $d01f69bb2ab5f70dfd0005370a2a2cbc$var$handlePointerEvent(e) {
13088
- $d01f69bb2ab5f70dfd0005370a2a2cbc$var$currentModality = 'pointer';
13089
-
13090
- if (e.type === 'mousedown' || e.type === 'pointerdown') {
13091
- $d01f69bb2ab5f70dfd0005370a2a2cbc$var$hasEventBeforeFocus = true;
13092
- $d01f69bb2ab5f70dfd0005370a2a2cbc$var$triggerChangeHandlers('pointer', e);
13093
- }
13094
- }
13095
-
13096
- function $d01f69bb2ab5f70dfd0005370a2a2cbc$var$handleClickEvent(e) {
13097
- if ($f67ef9f1b8ed09b4b00fd0840cd8b94b$export$isVirtualClick(e)) {
13098
- $d01f69bb2ab5f70dfd0005370a2a2cbc$var$hasEventBeforeFocus = true;
13099
- $d01f69bb2ab5f70dfd0005370a2a2cbc$var$currentModality = 'virtual';
13100
- }
13101
- }
13102
-
13103
- function $d01f69bb2ab5f70dfd0005370a2a2cbc$var$handleFocusEvent(e) {
13104
- // Firefox fires two extra focus events when the user first clicks into an iframe:
13105
- // first on the window, then on the document. We ignore these events so they don't
13106
- // cause keyboard focus rings to appear.
13107
- if (e.target === window || e.target === document) {
13108
- return;
13109
- } // If a focus event occurs without a preceding keyboard or pointer event, switch to virtual modality.
13110
- // This occurs, for example, when navigating a form with the next/previous buttons on iOS.
13111
-
13112
-
13113
- if (!$d01f69bb2ab5f70dfd0005370a2a2cbc$var$hasEventBeforeFocus && !$d01f69bb2ab5f70dfd0005370a2a2cbc$var$hasBlurredWindowRecently) {
13114
- $d01f69bb2ab5f70dfd0005370a2a2cbc$var$currentModality = 'virtual';
13115
- $d01f69bb2ab5f70dfd0005370a2a2cbc$var$triggerChangeHandlers('virtual', e);
13116
- }
13117
-
13118
- $d01f69bb2ab5f70dfd0005370a2a2cbc$var$hasEventBeforeFocus = false;
13119
- $d01f69bb2ab5f70dfd0005370a2a2cbc$var$hasBlurredWindowRecently = false;
13120
- }
13121
-
13122
- function $d01f69bb2ab5f70dfd0005370a2a2cbc$var$handleWindowBlur() {
13123
- // When the window is blurred, reset state. This is necessary when tabbing out of the window,
13124
- // for example, since a subsequent focus event won't be fired.
13125
- $d01f69bb2ab5f70dfd0005370a2a2cbc$var$hasEventBeforeFocus = false;
13126
- $d01f69bb2ab5f70dfd0005370a2a2cbc$var$hasBlurredWindowRecently = true;
13127
- }
13128
- /**
13129
- * Setup global event listeners to control when keyboard focus style should be visible.
13130
- */
13131
-
13132
-
13133
- function $d01f69bb2ab5f70dfd0005370a2a2cbc$var$setupGlobalFocusEvents() {
13134
- if (typeof window === 'undefined' || $d01f69bb2ab5f70dfd0005370a2a2cbc$var$hasSetupGlobalListeners) {
13135
- return;
13136
- } // Programmatic focus() calls shouldn't affect the current input modality.
13137
- // However, we need to detect other cases when a focus event occurs without
13138
- // a preceding user event (e.g. screen reader focus). Overriding the focus
13139
- // method on HTMLElement.prototype is a bit hacky, but works.
13140
-
13141
-
13142
- let focus = HTMLElement.prototype.focus;
13143
-
13144
- HTMLElement.prototype.focus = function () {
13145
- $d01f69bb2ab5f70dfd0005370a2a2cbc$var$hasEventBeforeFocus = true;
13146
- focus.apply(this, arguments);
13147
- };
13148
-
13149
- document.addEventListener('keydown', $d01f69bb2ab5f70dfd0005370a2a2cbc$var$handleKeyboardEvent, true);
13150
- document.addEventListener('keyup', $d01f69bb2ab5f70dfd0005370a2a2cbc$var$handleKeyboardEvent, true);
13151
- document.addEventListener('click', $d01f69bb2ab5f70dfd0005370a2a2cbc$var$handleClickEvent, true); // Register focus events on the window so they are sure to happen
13152
- // before React's event listeners (registered on the document).
13153
-
13154
- window.addEventListener('focus', $d01f69bb2ab5f70dfd0005370a2a2cbc$var$handleFocusEvent, true);
13155
- window.addEventListener('blur', $d01f69bb2ab5f70dfd0005370a2a2cbc$var$handleWindowBlur, false);
13156
-
13157
- if (typeof PointerEvent !== 'undefined') {
13158
- document.addEventListener('pointerdown', $d01f69bb2ab5f70dfd0005370a2a2cbc$var$handlePointerEvent, true);
13159
- document.addEventListener('pointermove', $d01f69bb2ab5f70dfd0005370a2a2cbc$var$handlePointerEvent, true);
13160
- document.addEventListener('pointerup', $d01f69bb2ab5f70dfd0005370a2a2cbc$var$handlePointerEvent, true);
13161
- } else {
13162
- document.addEventListener('mousedown', $d01f69bb2ab5f70dfd0005370a2a2cbc$var$handlePointerEvent, true);
13163
- document.addEventListener('mousemove', $d01f69bb2ab5f70dfd0005370a2a2cbc$var$handlePointerEvent, true);
13164
- document.addEventListener('mouseup', $d01f69bb2ab5f70dfd0005370a2a2cbc$var$handlePointerEvent, true);
13165
- }
13166
-
13167
- $d01f69bb2ab5f70dfd0005370a2a2cbc$var$hasSetupGlobalListeners = true;
13168
- }
13169
-
13170
- if (typeof document !== 'undefined') {
13171
- if (document.readyState !== 'loading') {
13172
- $d01f69bb2ab5f70dfd0005370a2a2cbc$var$setupGlobalFocusEvents();
13173
- } else {
13174
- document.addEventListener('DOMContentLoaded', $d01f69bb2ab5f70dfd0005370a2a2cbc$var$setupGlobalFocusEvents);
13175
- }
13176
- }
13177
- function getInteractionModality() {
13178
- return $d01f69bb2ab5f70dfd0005370a2a2cbc$var$currentModality;
13179
- }
13180
-
13181
- /**
13182
- * A utility function that focuses an element while avoiding undesired side effects such
13183
- * as page scrolling and screen reader issues with CSS transitions.
13184
- */
13185
- function focusSafely(element) {
13186
- // If the user is interacting with a virtual cursor, e.g. screen reader, then
13187
- // wait until after any animated transitions that are currently occurring on
13188
- // the page before shifting focus. This avoids issues with VoiceOver on iOS
13189
- // causing the page to scroll when moving focus if the element is transitioning
13190
- // from off the screen.
13191
- if (getInteractionModality() === 'virtual') {
13192
- let lastFocusedElement = document.activeElement;
13193
- runAfterTransition(() => {
13194
- // If focus did not move and the element is still in the document, focus it.
13195
- if (document.activeElement === lastFocusedElement && document.contains(element)) {
13196
- focusWithoutScrolling(element);
13197
- }
13198
- });
13199
- } else {
13200
- focusWithoutScrolling(element);
13201
- }
13202
- }
13203
-
13204
- /*
13205
- * Copyright 2021 Adobe. All rights reserved.
13206
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
13207
- * you may not use this file except in compliance with the License. You may obtain a copy
13208
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
13209
- *
13210
- * Unless required by applicable law or agreed to in writing, software distributed under
13211
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
13212
- * OF ANY KIND, either express or implied. See the License for the specific language
13213
- * governing permissions and limitations under the License.
13214
- */
13215
- function $ee5e90cbb4a22466973155c14222fa1$var$isStyleVisible(element) {
13216
- if (!(element instanceof HTMLElement) && !(element instanceof SVGElement)) {
13217
- return false;
13218
- }
13219
-
13220
- let {
13221
- display,
13222
- visibility
13223
- } = element.style;
13224
- let isVisible = display !== 'none' && visibility !== 'hidden' && visibility !== 'collapse';
13225
-
13226
- if (isVisible) {
13227
- const {
13228
- getComputedStyle
13229
- } = element.ownerDocument.defaultView;
13230
- let {
13231
- display: computedDisplay,
13232
- visibility: computedVisibility
13233
- } = getComputedStyle(element);
13234
- isVisible = computedDisplay !== 'none' && computedVisibility !== 'hidden' && computedVisibility !== 'collapse';
13235
- }
13236
-
13237
- return isVisible;
13238
- }
13239
-
13240
- function $ee5e90cbb4a22466973155c14222fa1$var$isAttributeVisible(element, childElement) {
13241
- return !element.hasAttribute('hidden') && (element.nodeName === 'DETAILS' && childElement && childElement.nodeName !== 'SUMMARY' ? element.hasAttribute('open') : true);
13242
- }
13243
- /**
13244
- * Adapted from https://github.com/testing-library/jest-dom and
13245
- * https://github.com/vuejs/vue-test-utils-next/.
13246
- * Licensed under the MIT License.
13247
- * @param element - Element to evaluate for display or visibility.
13248
- */
13249
-
13250
-
13251
- function $ee5e90cbb4a22466973155c14222fa1$export$isElementVisible(element, childElement) {
13252
- return element.nodeName !== '#comment' && $ee5e90cbb4a22466973155c14222fa1$var$isStyleVisible(element) && $ee5e90cbb4a22466973155c14222fa1$var$isAttributeVisible(element, childElement) && (!element.parentElement || $ee5e90cbb4a22466973155c14222fa1$export$isElementVisible(element.parentElement, element));
13253
- }
13254
-
13255
- const $c9e8f80f5bb1841844f54e4ad30b$var$focusableElements = ['input:not([disabled]):not([type=hidden])', 'select:not([disabled])', 'textarea:not([disabled])', 'button:not([disabled])', 'a[href]', 'area[href]', 'summary', 'iframe', 'object', 'embed', 'audio[controls]', 'video[controls]', '[contenteditable]'];
13256
- const $c9e8f80f5bb1841844f54e4ad30b$var$FOCUSABLE_ELEMENT_SELECTOR = $c9e8f80f5bb1841844f54e4ad30b$var$focusableElements.join(':not([hidden]),') + ',[tabindex]:not([disabled]):not([hidden])';
13257
- $c9e8f80f5bb1841844f54e4ad30b$var$focusableElements.push('[tabindex]:not([tabindex="-1"]):not([disabled])');
13258
- const $c9e8f80f5bb1841844f54e4ad30b$var$TABBABLE_ELEMENT_SELECTOR = $c9e8f80f5bb1841844f54e4ad30b$var$focusableElements.join(':not([hidden]):not([tabindex="-1"]),');
13259
-
13260
- const $c9e8f80f5bb1841844f54e4ad30b$var$focusScopeDataAttrNames = ['data-focus-scope-start', 'data-focus-scope-end'];
13261
-
13262
- function $c9e8f80f5bb1841844f54e4ad30b$var$isFocusScopeDirectChild(scope) {
13263
- return $c9e8f80f5bb1841844f54e4ad30b$var$focusScopeDataAttrNames.some(name => scope.getAttribute(name) !== null);
13264
- }
13265
-
13266
- function $c9e8f80f5bb1841844f54e4ad30b$var$isFocusScopeNestedChild(scope) {
13267
- return $c9e8f80f5bb1841844f54e4ad30b$var$focusScopeDataAttrNames.some(name => scope.querySelector("[" + name + "]"));
13268
- }
13269
-
13270
- function $c9e8f80f5bb1841844f54e4ad30b$var$isFocusScopeInScope(scopes) {
13271
- return scopes.some(scope => $c9e8f80f5bb1841844f54e4ad30b$var$isFocusScopeDirectChild(scope) || $c9e8f80f5bb1841844f54e4ad30b$var$isFocusScopeNestedChild(scope));
13272
- }
13273
-
13274
- function $c9e8f80f5bb1841844f54e4ad30b$var$isElementInScope(element, scope) {
13275
- return !$c9e8f80f5bb1841844f54e4ad30b$var$isFocusScopeInScope(scope) && scope.some(node => node.contains(element));
13276
- }
13277
- /**
13278
- * Create a [TreeWalker]{@link https://developer.mozilla.org/en-US/docs/Web/API/TreeWalker}
13279
- * that matches all focusable/tabbable elements.
13280
- */
13281
-
13282
-
13283
- function getFocusableTreeWalker(root, opts, scope) {
13284
- let selector = opts != null && opts.tabbable ? $c9e8f80f5bb1841844f54e4ad30b$var$TABBABLE_ELEMENT_SELECTOR : $c9e8f80f5bb1841844f54e4ad30b$var$FOCUSABLE_ELEMENT_SELECTOR;
13285
- let walker = document.createTreeWalker(root, NodeFilter.SHOW_ELEMENT, {
13286
- acceptNode(node) {
13287
- var _opts$from;
13288
-
13289
- // Skip nodes inside the starting node.
13290
- if (opts != null && (_opts$from = opts.from) != null && _opts$from.contains(node)) {
13291
- return NodeFilter.FILTER_REJECT;
13292
- }
13293
-
13294
- if (node.matches(selector) && $ee5e90cbb4a22466973155c14222fa1$export$isElementVisible(node) && (!scope || $c9e8f80f5bb1841844f54e4ad30b$var$isElementInScope(node, scope))) {
13295
- return NodeFilter.FILTER_ACCEPT;
13296
- }
13297
-
13298
- return NodeFilter.FILTER_SKIP;
13299
- }
13300
-
13301
- });
13302
-
13303
- if (opts != null && opts.from) {
13304
- walker.currentNode = opts.from;
13305
- }
13306
-
13307
- return walker;
13308
- }
13309
-
13310
- function _extends$1() {
13311
- _extends$1 = Object.assign || function (target) {
13312
- for (var i = 1; i < arguments.length; i++) {
13313
- var source = arguments[i];
13314
-
13315
- for (var key in source) {
13316
- if (Object.prototype.hasOwnProperty.call(source, key)) {
13317
- target[key] = source[key];
13318
- }
13319
- }
13320
- }
13321
-
13322
- return target;
13323
- };
13324
-
13325
- return _extends$1.apply(this, arguments);
13326
- }
13327
-
13328
- /**
13329
- * Handles typeahead interactions with collections.
13330
- */
13331
- function useTypeSelect(options) {
13332
- let {
13333
- keyboardDelegate,
13334
- selectionManager,
13335
- onTypeSelect
13336
- } = options;
13337
- let state = React.useRef({
13338
- search: '',
13339
- timeout: null
13340
- }).current;
13341
-
13342
- let onKeyDown = e => {
13343
- let character = $c78d7fa5f7d5832f9b4f97b33a679865$var$getStringForKey(e.key);
13344
-
13345
- if (!character || e.ctrlKey || e.metaKey) {
13346
- return;
13347
- } // Do not propagate the Spacebar event if it's meant to be part of the search.
13348
- // When we time out, the search term becomes empty, hence the check on length.
13349
- // Trimming is to account for the case of pressing the Spacebar more than once,
13350
- // which should cycle through the selection/deselection of the focused item.
13351
-
13352
-
13353
- if (character === ' ' && state.search.trim().length > 0) {
13354
- e.preventDefault();
13355
-
13356
- if (!('continuePropagation' in e)) {
13357
- e.stopPropagation();
13358
- }
13359
- }
13360
-
13361
- state.search += character; // Use the delegate to find a key to focus.
13362
- // Prioritize items after the currently focused item, falling back to searching the whole list.
13363
-
13364
- let key = keyboardDelegate.getKeyForSearch(state.search, selectionManager.focusedKey); // If no key found, search from the top.
13365
-
13366
- if (key == null) {
13367
- key = keyboardDelegate.getKeyForSearch(state.search);
13368
- }
13369
-
13370
- if (key != null) {
13371
- selectionManager.setFocusedKey(key);
13372
-
13373
- if (onTypeSelect) {
13374
- onTypeSelect(key);
13375
- }
13376
- }
13377
-
13378
- clearTimeout(state.timeout);
13379
- state.timeout = setTimeout(() => {
13380
- state.search = '';
13381
- }, 500);
13382
- };
13383
-
13384
- return {
13385
- typeSelectProps: {
13386
- // Using a capturing listener to catch the keydown event before
13387
- // other hooks in order to handle the Spacebar event.
13388
- onKeyDownCapture: keyboardDelegate.getKeyForSearch ? onKeyDown : null
13389
- }
13390
- };
13391
- }
13392
-
13393
- function $c78d7fa5f7d5832f9b4f97b33a679865$var$getStringForKey(key) {
13394
- // If the key is of length 1, it is an ASCII value.
13395
- // Otherwise, if there are no ASCII characters in the key name,
13396
- // it is a Unicode character.
13397
- // See https://www.w3.org/TR/uievents-key/
13398
- if (key.length === 1 || !/^[A-Z]/i.test(key)) {
13399
- return key;
13400
- }
13401
-
13402
- return '';
13403
- }
13404
-
13405
- function $a9b9aa71af07c56ab1d89ca45381f4b$var$isCtrlKeyPressed(e) {
13406
- if (isMac()) {
13407
- return e.metaKey;
13408
- }
13409
-
13410
- return e.ctrlKey;
13411
- }
13412
-
13413
- /**
13414
- * Handles interactions with selectable collections.
13415
- */
13416
- function useSelectableCollection(options) {
13417
- let {
13418
- selectionManager: manager,
13419
- keyboardDelegate: delegate,
13420
- ref,
13421
- autoFocus = false,
13422
- shouldFocusWrap = false,
13423
- disallowEmptySelection = false,
13424
- disallowSelectAll = false,
13425
- selectOnFocus = false,
13426
- disallowTypeAhead = false,
13427
- shouldUseVirtualFocus,
13428
- allowsTabNavigation = false
13429
- } = options;
13430
- let {
13431
- direction
13432
- } = useLocale();
13433
-
13434
- let onKeyDown = e => {
13435
- // Prevent option + tab from doing anything since it doesn't move focus to the cells, only buttons/checkboxes
13436
- if (e.altKey && e.key === 'Tab') {
13437
- e.preventDefault();
13438
- } // Let child element (e.g. menu button) handle the event if the Alt key is pressed.
13439
- // Keyboard events bubble through portals. Don't handle keyboard events
13440
- // for elements outside the collection (e.g. menus).
13441
-
13442
-
13443
- if (e.altKey || !ref.current.contains(e.target)) {
13444
- return;
13445
- }
13446
-
13447
- const navigateToKey = (key, childFocus) => {
13448
- if (key != null) {
13449
- manager.setFocusedKey(key, childFocus);
13450
-
13451
- if (e.shiftKey && manager.selectionMode === 'multiple') {
13452
- manager.extendSelection(key);
13453
- } else if (selectOnFocus) {
13454
- manager.replaceSelection(key);
13455
- }
13456
- }
13457
- };
13458
-
13459
- switch (e.key) {
13460
- case 'ArrowDown':
13461
- {
13462
- if (delegate.getKeyBelow) {
13463
- e.preventDefault();
13464
- let nextKey = manager.focusedKey != null ? delegate.getKeyBelow(manager.focusedKey) : delegate.getFirstKey == null ? void 0 : delegate.getFirstKey();
13465
-
13466
- if (nextKey == null && shouldFocusWrap) {
13467
- nextKey = delegate.getFirstKey == null ? void 0 : delegate.getFirstKey(manager.focusedKey);
13468
- }
13469
-
13470
- navigateToKey(nextKey);
13471
- }
13472
-
13473
- break;
13474
- }
13475
-
13476
- case 'ArrowUp':
13477
- {
13478
- if (delegate.getKeyAbove) {
13479
- e.preventDefault();
13480
- let nextKey = manager.focusedKey != null ? delegate.getKeyAbove(manager.focusedKey) : delegate.getLastKey == null ? void 0 : delegate.getLastKey();
13481
-
13482
- if (nextKey == null && shouldFocusWrap) {
13483
- nextKey = delegate.getLastKey == null ? void 0 : delegate.getLastKey(manager.focusedKey);
13484
- }
13485
-
13486
- navigateToKey(nextKey);
13487
- }
13488
-
13489
- break;
13490
- }
13491
-
13492
- case 'ArrowLeft':
13493
- {
13494
- if (delegate.getKeyLeftOf) {
13495
- e.preventDefault();
13496
- let nextKey = delegate.getKeyLeftOf(manager.focusedKey);
13497
- navigateToKey(nextKey, direction === 'rtl' ? 'first' : 'last');
13498
- }
13499
-
13500
- break;
13501
- }
13502
-
13503
- case 'ArrowRight':
13504
- {
13505
- if (delegate.getKeyRightOf) {
13506
- e.preventDefault();
13507
- let nextKey = delegate.getKeyRightOf(manager.focusedKey);
13508
- navigateToKey(nextKey, direction === 'rtl' ? 'last' : 'first');
13509
- }
13510
-
13511
- break;
13512
- }
13513
-
13514
- case 'Home':
13515
- if (delegate.getFirstKey) {
13516
- e.preventDefault();
13517
- let firstKey = delegate.getFirstKey(manager.focusedKey, $a9b9aa71af07c56ab1d89ca45381f4b$var$isCtrlKeyPressed(e));
13518
- manager.setFocusedKey(firstKey);
13519
-
13520
- if ($a9b9aa71af07c56ab1d89ca45381f4b$var$isCtrlKeyPressed(e) && e.shiftKey && manager.selectionMode === 'multiple') {
13521
- manager.extendSelection(firstKey);
13522
- } else if (selectOnFocus) {
13523
- manager.replaceSelection(firstKey);
13524
- }
13525
- }
13526
-
13527
- break;
13528
-
13529
- case 'End':
13530
- if (delegate.getLastKey) {
13531
- e.preventDefault();
13532
- let lastKey = delegate.getLastKey(manager.focusedKey, $a9b9aa71af07c56ab1d89ca45381f4b$var$isCtrlKeyPressed(e));
13533
- manager.setFocusedKey(lastKey);
13534
-
13535
- if ($a9b9aa71af07c56ab1d89ca45381f4b$var$isCtrlKeyPressed(e) && e.shiftKey && manager.selectionMode === 'multiple') {
13536
- manager.extendSelection(lastKey);
13537
- } else if (selectOnFocus) {
13538
- manager.replaceSelection(lastKey);
13539
- }
13540
- }
13541
-
13542
- break;
13543
-
13544
- case 'PageDown':
13545
- if (delegate.getKeyPageBelow) {
13546
- e.preventDefault();
13547
- let nextKey = delegate.getKeyPageBelow(manager.focusedKey);
13548
- navigateToKey(nextKey);
13549
- }
13550
-
13551
- break;
13552
-
13553
- case 'PageUp':
13554
- if (delegate.getKeyPageAbove) {
13555
- e.preventDefault();
13556
- let nextKey = delegate.getKeyPageAbove(manager.focusedKey);
13557
- navigateToKey(nextKey);
13558
- }
13559
-
13560
- break;
13561
-
13562
- case 'a':
13563
- if ($a9b9aa71af07c56ab1d89ca45381f4b$var$isCtrlKeyPressed(e) && manager.selectionMode === 'multiple' && disallowSelectAll !== true) {
13564
- e.preventDefault();
13565
- manager.selectAll();
13566
- }
13567
-
13568
- break;
13569
-
13570
- case 'Escape':
13571
- e.preventDefault();
13572
-
13573
- if (!disallowEmptySelection) {
13574
- manager.clearSelection();
13575
- }
13576
-
13577
- break;
13578
-
13579
- case 'Tab':
13580
- {
13581
- if (!allowsTabNavigation) {
13582
- // There may be elements that are "tabbable" inside a collection (e.g. in a grid cell).
13583
- // However, collections should be treated as a single tab stop, with arrow key navigation internally.
13584
- // We don't control the rendering of these, so we can't override the tabIndex to prevent tabbing.
13585
- // Instead, we handle the Tab key, and move focus manually to the first/last tabbable element
13586
- // in the collection, so that the browser default behavior will apply starting from that element
13587
- // rather than the currently focused one.
13588
- if (e.shiftKey) {
13589
- ref.current.focus();
13590
- } else {
13591
- let walker = getFocusableTreeWalker(ref.current, {
13592
- tabbable: true
13593
- });
13594
- let next;
13595
- let last;
13596
-
13597
- do {
13598
- last = walker.lastChild();
13599
-
13600
- if (last) {
13601
- next = last;
13602
- }
13603
- } while (last);
13604
-
13605
- if (next && !next.contains(document.activeElement)) {
13606
- focusWithoutScrolling(next);
13607
- }
13608
- }
13609
-
13610
- break;
13611
- }
13612
- }
13613
- }
13614
- };
13615
-
13616
- let onFocus = e => {
13617
- if (manager.isFocused) {
13618
- // If a focus event bubbled through a portal, reset focus state.
13619
- if (!e.currentTarget.contains(e.target)) {
13620
- manager.setFocused(false);
13621
- }
13622
-
13623
- return;
13624
- } // Focus events can bubble through portals. Ignore these events.
13625
-
13626
-
13627
- if (!e.currentTarget.contains(e.target)) {
13628
- return;
13629
- }
13630
-
13631
- manager.setFocused(true);
13632
-
13633
- if (manager.focusedKey == null) {
13634
- // If the user hasn't yet interacted with the collection, there will be no focusedKey set.
13635
- // Attempt to detect whether the user is tabbing forward or backward into the collection
13636
- // and either focus the first or last item accordingly.
13637
- let relatedTarget = e.relatedTarget;
13638
-
13639
- if (relatedTarget && e.currentTarget.compareDocumentPosition(relatedTarget) & Node.DOCUMENT_POSITION_FOLLOWING) {
13640
- var _manager$lastSelected;
13641
-
13642
- manager.setFocusedKey((_manager$lastSelected = manager.lastSelectedKey) != null ? _manager$lastSelected : delegate.getLastKey());
13643
- } else {
13644
- var _manager$firstSelecte;
13645
-
13646
- manager.setFocusedKey((_manager$firstSelecte = manager.firstSelectedKey) != null ? _manager$firstSelecte : delegate.getFirstKey());
13647
- }
13648
- }
13649
- };
13650
-
13651
- let onBlur = e => {
13652
- // Don't set blurred and then focused again if moving focus within the collection.
13653
- if (!e.currentTarget.contains(e.relatedTarget)) {
13654
- manager.setFocused(false);
13655
- }
13656
- };
13657
-
13658
- const autoFocusRef = React.useRef(autoFocus);
13659
- React.useEffect(() => {
13660
- if (autoFocusRef.current) {
13661
- let focusedKey = null; // Check focus strategy to determine which item to focus
13662
-
13663
- if (autoFocus === 'first') {
13664
- focusedKey = delegate.getFirstKey();
13665
- }
13666
-
13667
- if (autoFocus === 'last') {
13668
- focusedKey = delegate.getLastKey();
13669
- } // If there are any selected keys, make the first one the new focus target
13670
-
13671
-
13672
- let selectedKeys = manager.selectedKeys;
13673
-
13674
- if (selectedKeys.size) {
13675
- focusedKey = selectedKeys.values().next().value;
13676
- }
13677
-
13678
- manager.setFocused(true);
13679
- manager.setFocusedKey(focusedKey); // If no default focus key is selected, focus the collection itself.
13680
-
13681
- if (focusedKey == null && !shouldUseVirtualFocus) {
13682
- focusSafely(ref.current);
13683
- }
13684
- }
13685
-
13686
- autoFocusRef.current = false; // eslint-disable-next-line react-hooks/exhaustive-deps
13687
- }, []);
13688
- let handlers = {
13689
- onKeyDown,
13690
- onFocus,
13691
- onBlur,
13692
-
13693
- onMouseDown(e) {
13694
- // Ignore events that bubbled through portals.
13695
- if (e.currentTarget.contains(e.target)) {
13696
- // Prevent focus going to the collection when clicking on the scrollbar.
13697
- e.preventDefault();
13698
- }
13699
- }
13700
-
13701
- };
13702
- let {
13703
- typeSelectProps
13704
- } = useTypeSelect({
13705
- keyboardDelegate: delegate,
13706
- selectionManager: manager
13707
- });
13708
-
13709
- if (!disallowTypeAhead) {
13710
- handlers = mergeProps(typeSelectProps, handlers);
13711
- } // If nothing is focused within the collection, make the collection itself tabbable.
13712
- // This will be marshalled to either the first or last item depending on where focus came from.
13713
- // If using virtual focus, don't set a tabIndex at all so that VoiceOver on iOS 14 doesn't try
13714
- // to move real DOM focus to the element anyway.
13715
-
13716
-
13717
- let tabIndex;
13718
-
13719
- if (!shouldUseVirtualFocus) {
13720
- tabIndex = manager.focusedKey == null ? 0 : -1;
13721
- }
13722
-
13723
- return {
13724
- collectionProps: _extends$1({}, handlers, {
13725
- tabIndex
13726
- })
13727
- };
13728
- }
13729
-
13730
- /**
13731
- * Handles interactions with an item in a selectable collection.
13732
- */
13733
- function useSelectableItem(options) {
13734
- let {
13735
- selectionManager: manager,
13736
- key,
13737
- ref,
13738
- shouldSelectOnPressUp,
13739
- isVirtualized,
13740
- shouldUseVirtualFocus,
13741
- focus
13742
- } = options;
13743
-
13744
- let onSelect = e => manager.select(key, e); // Focus the associated DOM node when this item becomes the focusedKey
13745
-
13746
-
13747
- let isFocused = key === manager.focusedKey;
13748
- React.useEffect(() => {
13749
- if (isFocused && manager.isFocused && !shouldUseVirtualFocus && document.activeElement !== ref.current) {
13750
- if (focus) {
13751
- focus();
13752
- } else {
13753
- focusSafely(ref.current);
13754
- }
13755
- }
13756
- }, [ref, isFocused, manager.focusedKey, manager.childFocusStrategy, manager.isFocused, shouldUseVirtualFocus]); // Set tabIndex to 0 if the element is focused, or -1 otherwise so that only the last focused
13757
- // item is tabbable. If using virtual focus, don't set a tabIndex at all so that VoiceOver
13758
- // on iOS 14 doesn't try to move real DOM focus to the item anyway.
13759
-
13760
- let itemProps = {};
13761
-
13762
- if (!shouldUseVirtualFocus) {
13763
- itemProps = {
13764
- tabIndex: isFocused ? 0 : -1,
13765
-
13766
- onFocus(e) {
13767
- if (e.target === ref.current) {
13768
- manager.setFocusedKey(key);
13769
- }
13770
- }
13771
-
13772
- };
13773
- } // By default, selection occurs on pointer down. This can be strange if selecting an
13774
- // item causes the UI to disappear immediately (e.g. menus).
13775
- // If shouldSelectOnPressUp is true, we use onPressUp instead of onPressStart.
13776
- // onPress requires a pointer down event on the same element as pointer up. For menus,
13777
- // we want to be able to have the pointer down on the trigger that opens the menu and
13778
- // the pointer up on the menu item rather than requiring a separate press.
13779
- // For keyboard events, selection still occurs on key down.
13780
-
13781
-
13782
- if (shouldSelectOnPressUp) {
13783
- itemProps.onPressStart = e => {
13784
- if (e.pointerType === 'keyboard') {
13785
- onSelect(e);
13786
- }
13787
- };
13788
-
13789
- itemProps.onPressUp = e => {
13790
- if (e.pointerType !== 'keyboard') {
13791
- onSelect(e);
13792
- }
13793
- };
13794
- } else {
13795
- // On touch, it feels strange to select on touch down, so we special case this.
13796
- itemProps.onPressStart = e => {
13797
- if (e.pointerType !== 'touch') {
13798
- onSelect(e);
13799
- }
13800
- };
13801
-
13802
- itemProps.onPress = e => {
13803
- if (e.pointerType === 'touch') {
13804
- onSelect(e);
13805
- }
13806
- };
13807
- }
13808
-
13809
- if (!isVirtualized) {
13810
- itemProps['data-key'] = key;
13811
- }
13812
-
13813
- return {
13814
- itemProps
13815
- };
13816
- }
13817
-
13818
- function _extends() {
13819
- _extends = Object.assign || function (target) {
13820
- for (var i = 1; i < arguments.length; i++) {
13821
- var source = arguments[i];
13822
-
13823
- for (var key in source) {
13824
- if (Object.prototype.hasOwnProperty.call(source, key)) {
13825
- target[key] = source[key];
13826
- }
13827
- }
13828
- }
13829
-
13830
- return target;
13831
- };
13832
-
13833
- return _extends.apply(this, arguments);
13834
- }
13835
-
13836
- /*
13837
- * Copyright 2020 Adobe. All rights reserved.
13838
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
13839
- * you may not use this file except in compliance with the License. You may obtain a copy
13840
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
13841
- *
13842
- * Unless required by applicable law or agreed to in writing, software distributed under
13843
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
13844
- * OF ANY KIND, either express or implied. See the License for the specific language
13845
- * governing permissions and limitations under the License.
13846
- */
13847
- const $c5c378b07d37fb3729fd37493414d657$export$tabsIds = new WeakMap();
13848
-
13849
- function $c5c378b07d37fb3729fd37493414d657$export$generateId(state, key, role) {
13850
- if (typeof key === 'string') {
13851
- key = key.replace(/\s+/g, '');
13852
- }
13853
-
13854
- let baseId = $c5c378b07d37fb3729fd37493414d657$export$tabsIds.get(state);
13855
- return baseId + "-" + role + "-" + key;
13856
- }
13857
-
13858
- /**
13859
- * Provides the behavior and accessibility implementation for a tab.
13860
- * When selected, the associated tab panel is shown.
13861
- */
13862
- function useTab(props, state, ref) {
13863
- let {
13864
- key,
13865
- isDisabled: propsDisabled
13866
- } = props;
13867
- let {
13868
- selectionManager: manager,
13869
- selectedKey
13870
- } = state;
13871
- let isSelected = key === selectedKey;
13872
- let {
13873
- itemProps
13874
- } = useSelectableItem({
13875
- selectionManager: manager,
13876
- key,
13877
- ref
13878
- });
13879
- let isDisabled = propsDisabled || state.disabledKeys.has(key);
13880
- let {
13881
- pressProps
13882
- } = usePress(_extends({}, itemProps, {
13883
- isDisabled
13884
- }));
13885
- let tabId = $c5c378b07d37fb3729fd37493414d657$export$generateId(state, key, 'tab');
13886
- let tabPanelId = $c5c378b07d37fb3729fd37493414d657$export$generateId(state, key, 'tabpanel');
13887
- let {
13888
- tabIndex
13889
- } = pressProps;
13890
- return {
13891
- tabProps: _extends({}, pressProps, {
13892
- id: tabId,
13893
- 'aria-selected': isSelected,
13894
- 'aria-disabled': isDisabled || undefined,
13895
- 'aria-controls': isSelected ? tabPanelId : undefined,
13896
- tabIndex: isDisabled ? undefined : tabIndex,
13897
- role: 'tab'
13898
- })
13899
- };
13900
- }
13901
-
13902
- /**
13903
- * Provides the behavior and accessibility implementation for a tab panel. A tab panel is a container for
13904
- * the contents of a tab, and is shown when the tab is selected.
13905
- */
13906
- function useTabPanel(props, state, ref) {
13907
- let [tabIndex, setTabIndex] = React.useState(0); // The tabpanel should have tabIndex=0 when there are no tabbable elements within it.
13908
- // Otherwise, tabbing from the focused tab should go directly to the first tabbable element
13909
- // within the tabpanel.
13910
-
13911
- React.useLayoutEffect(() => {
13912
- if (ref != null && ref.current) {
13913
- let update = () => {
13914
- // Detect if there are any tabbable elements and update the tabIndex accordingly.
13915
- let walker = getFocusableTreeWalker(ref.current, {
13916
- tabbable: true
13917
- });
13918
- setTabIndex(walker.nextNode() ? undefined : 0);
13919
- };
13920
-
13921
- update(); // Update when new elements are inserted, or the tabIndex/disabled attribute updates.
13922
-
13923
- let observer = new MutationObserver(update);
13924
- observer.observe(ref.current, {
13925
- subtree: true,
13926
- childList: true,
13927
- attributes: true,
13928
- attributeFilter: ['tabIndex', 'disabled']
13929
- });
13930
- return () => {
13931
- observer.disconnect();
13932
- };
13933
- }
13934
- }, [ref]);
13935
- const id = $c5c378b07d37fb3729fd37493414d657$export$generateId(state, state == null ? void 0 : state.selectedKey, 'tabpanel');
13936
- const tabPanelProps = useLabels(_extends({}, props, {
13937
- id,
13938
- 'aria-labelledby': $c5c378b07d37fb3729fd37493414d657$export$generateId(state, state == null ? void 0 : state.selectedKey, 'tab')
13939
- }));
13940
- return {
13941
- tabPanelProps: mergeProps(tabPanelProps, {
13942
- tabIndex,
13943
- role: 'tabpanel',
13944
- 'aria-describedby': props['aria-describedby'],
13945
- 'aria-details': props['aria-details']
13946
- })
13947
- };
13948
- }
13949
-
13950
- class $ace72fda23df319bd9db38f00073d9$export$TabsKeyboardDelegate {
13951
- constructor(collection, direction, orientation, disabledKeys) {
13952
- if (disabledKeys === void 0) {
13953
- disabledKeys = new Set();
13954
- }
13955
-
13956
- this.collection = void 0;
13957
- this.flipDirection = void 0;
13958
- this.disabledKeys = void 0;
13959
- this.orientation = void 0;
13960
- this.collection = collection;
13961
- this.flipDirection = direction === 'rtl' && orientation === 'horizontal';
13962
- this.orientation = orientation;
13963
- this.disabledKeys = disabledKeys;
13964
- }
13965
-
13966
- getKeyLeftOf(key) {
13967
- if (this.flipDirection) {
13968
- return this.getNextKey(key);
13969
- } else {
13970
- if (this.orientation === 'horizontal') {
13971
- return this.getPreviousKey(key);
13972
- }
13973
-
13974
- return null;
13975
- }
13976
- }
13977
-
13978
- getKeyRightOf(key) {
13979
- if (this.flipDirection) {
13980
- return this.getPreviousKey(key);
13981
- } else {
13982
- if (this.orientation === 'horizontal') {
13983
- return this.getNextKey(key);
13984
- }
13985
-
13986
- return null;
13987
- }
13988
- }
13989
-
13990
- getKeyAbove(key) {
13991
- if (this.orientation === 'vertical') {
13992
- return this.getPreviousKey(key);
13993
- }
13994
-
13995
- return null;
13996
- }
13997
-
13998
- getKeyBelow(key) {
13999
- if (this.orientation === 'vertical') {
14000
- return this.getNextKey(key);
14001
- }
14002
-
14003
- return null;
14004
- }
14005
-
14006
- getFirstKey() {
14007
- let key = this.collection.getFirstKey();
14008
-
14009
- if (this.disabledKeys.has(key)) {
14010
- key = this.getNextKey(key);
14011
- }
14012
-
14013
- return key;
14014
- }
14015
-
14016
- getLastKey() {
14017
- let key = this.collection.getLastKey();
14018
-
14019
- if (this.disabledKeys.has(key)) {
14020
- key = this.getPreviousKey(key);
14021
- }
14022
-
14023
- return key;
14024
- }
14025
-
14026
- getNextKey(key) {
14027
- do {
14028
- key = this.collection.getKeyAfter(key);
14029
-
14030
- if (key == null) {
14031
- key = this.collection.getFirstKey();
14032
- }
14033
- } while (this.disabledKeys.has(key));
14034
-
14035
- return key;
14036
- }
14037
-
14038
- getPreviousKey(key) {
14039
- do {
14040
- key = this.collection.getKeyBefore(key);
14041
-
14042
- if (key == null) {
14043
- key = this.collection.getLastKey();
14044
- }
14045
- } while (this.disabledKeys.has(key));
14046
-
14047
- return key;
14048
- }
14049
-
14050
- }
14051
-
14052
- /**
14053
- * Provides the behavior and accessibility implementation for a tab list.
14054
- * Tabs organize content into multiple sections and allow users to navigate between them.
14055
- */
14056
- function useTabList(props, state, ref) {
14057
- let {
14058
- orientation = 'horizontal',
14059
- keyboardActivation = 'automatic'
14060
- } = props;
14061
- let {
14062
- collection,
14063
- selectionManager: manager,
14064
- disabledKeys
14065
- } = state;
14066
- let {
14067
- direction
14068
- } = useLocale();
14069
- let delegate = React.useMemo(() => new $ace72fda23df319bd9db38f00073d9$export$TabsKeyboardDelegate(collection, direction, orientation, disabledKeys), [collection, disabledKeys, orientation, direction]);
14070
- let {
14071
- collectionProps
14072
- } = useSelectableCollection({
14073
- ref,
14074
- selectionManager: manager,
14075
- keyboardDelegate: delegate,
14076
- selectOnFocus: keyboardActivation === 'automatic',
14077
- disallowEmptySelection: true
14078
- }); // Compute base id for all tabs
14079
-
14080
- let tabsId = useId();
14081
- $c5c378b07d37fb3729fd37493414d657$export$tabsIds.set(state, tabsId);
14082
- let tabListLabelProps = useLabels(_extends({}, props, {
14083
- id: tabsId
14084
- }));
14085
- return {
14086
- tabListProps: _extends({}, mergeProps(collectionProps, tabListLabelProps), {
14087
- role: 'tablist',
14088
- 'aria-orientation': orientation,
14089
- tabIndex: undefined
14090
- })
14091
- };
14092
- }
14093
-
14094
- function SpsTab(_a) {
14095
- var item = _a.item, state = _a.state;
14096
- var key = item.key;
14097
- var ref = React__namespace.useRef();
14098
- var tabProps = useTab({ key: key }, state, ref).tabProps;
14099
- var isSelected = state.selectedKey === key;
14100
- var isDisabled = state.disabledKeys.has(key);
14101
- return (React__namespace.createElement("div", __assign({}, tabProps, { ref: ref, className: clsx__default['default']('sps-nav__item', 'sps-nav__link', isSelected && 'active', isDisabled && 'sps-nav__item--disabled') }), item.rendered));
14102
- }
14103
-
14104
- function SpsTabPanel(_a) {
14105
- var state = _a.state, props = __rest(_a, ["state"]);
14106
- var ref = React__namespace.useRef();
14107
- var tabPanelProps = useTabPanel(props, state, ref).tabPanelProps;
14108
- return (React__namespace.createElement("div", __assign({}, tabPanelProps, { ref: ref, className: "sps-card__body" }), state.selectedItem ? state.selectedItem.props.children : null));
14109
- }
14110
-
14111
- function SpsTabsV2(props) {
14112
- var state = useTabListState(props);
14113
- var ref = React__namespace.useRef();
14114
- var tabListProps = useTabList(props, state, ref).tabListProps;
14115
- return (React__namespace.createElement(React__namespace.Fragment, null,
14116
- React__namespace.createElement("div", __assign({}, tabListProps, { ref: ref, className: "sps-nav sps-nav--tabs sps-tabs-v2" }), __spreadArray([], __read(state.collection)).map(function (item) { return (React__namespace.createElement(SpsTab, { key: item.key, item: item, state: state })); })),
14117
- React__namespace.createElement(SpsTabPanel, { key: state.selectedItem ? state.selectedItem.key : null, state: state })));
14118
- }
14119
-
14120
- function SpsCardV2Footer(_a) {
14121
- var children = _a.children, className = _a.className, rest = __rest(_a, ["children", "className"]);
14122
- return (React__namespace.createElement("div", __assign({ className: clsx__default['default']('sps-card__footer', className) }, rest), children));
14123
- }
14124
-
14125
- function SpsCardV2Header(_a) {
14126
- var children = _a.children, className = _a.className, rest = __rest(_a, ["children", "className"]);
14127
- return (React__namespace.createElement("div", __assign({ className: clsx__default['default']('sps-card__header', className) }, rest), children));
14128
- }
14129
-
14130
- function SpsCardV2(_a) {
14131
- var children = _a.children, className = _a.className, rest = __rest(_a, ["children", "className"]);
14132
- var _b = __read(selectChildren(children, [
14133
- { type: SpsCardV2Header },
14134
- { type: SpsTabsV2 },
14135
- { type: SpsCardV2Footer },
14136
- ]), 4), header = _b[0], tabs = _b[1], footer = _b[2], bodyContent = _b[3];
14137
- return (React__namespace.createElement("div", __assign({ className: clsx__default['default']('sps-card', className) }, rest),
14138
- header,
14139
- tabs.length > 0
14140
- ? tabs
14141
- : (React__namespace.createElement("div", { className: "sps-card__body" }, bodyContent)),
14142
- footer));
14143
- }
14144
-
14145
- function SpsCardV2Title(_a) {
14146
- var children = _a.children, className = _a.className, rest = __rest(_a, ["children", "className"]);
14147
- return (React__namespace.createElement("div", __assign({ className: clsx__default['default']('sps-card__title', className) }, rest), children));
14148
- }
14149
-
14150
10938
  var moment$2 = moment__namespace.default || moment__namespace;
14151
10939
  function newWeekArray() {
14152
10940
  return (new Array(7)).fill(null);
@@ -14982,10 +11770,6 @@ exports.SpsButtonGroup = SpsButtonGroup;
14982
11770
  exports.SpsCard = SpsCard;
14983
11771
  exports.SpsCardExamples = SpsCardExamples;
14984
11772
  exports.SpsCardTabbedPane = SpsCardTabbedPane;
14985
- exports.SpsCardV2 = SpsCardV2;
14986
- exports.SpsCardV2Footer = SpsCardV2Footer;
14987
- exports.SpsCardV2Header = SpsCardV2Header;
14988
- exports.SpsCardV2Title = SpsCardV2Title;
14989
11773
  exports.SpsCheckbox = SpsCheckbox;
14990
11774
  exports.SpsCheckboxDropdown = SpsCheckboxDropdown;
14991
11775
  exports.SpsCheckboxExamples = SpsCheckboxExamples;
@@ -15111,8 +11895,6 @@ exports.SpsSummaryListColumn = SpsSummaryListColumn;
15111
11895
  exports.SpsSummaryListExamples = SpsSummaryListExamples;
15112
11896
  exports.SpsSummaryListExpansion = SpsSummaryListExpansion;
15113
11897
  exports.SpsSummaryListRow = SpsSummaryListRow;
15114
- exports.SpsTab = SpsTab;
15115
- exports.SpsTabPanel = SpsTabPanel;
15116
11898
  exports.SpsTable = SpsTable;
15117
11899
  exports.SpsTableBody = SpsTableBody;
15118
11900
  exports.SpsTableCell = SpsTableCell;
@@ -15120,7 +11902,6 @@ exports.SpsTableExamples = SpsTableExamples;
15120
11902
  exports.SpsTableHead = SpsTableHead;
15121
11903
  exports.SpsTableHeader = SpsTableHeader;
15122
11904
  exports.SpsTableRow = SpsTableRow;
15123
- exports.SpsTabsV2 = SpsTabsV2;
15124
11905
  exports.SpsTag = SpsTag;
15125
11906
  exports.SpsTagExamples = SpsTagExamples;
15126
11907
  exports.SpsTaskQueue = SpsTaskQueue;