2024-06-15 00:55:43 +03:00

233 lines
9.6 KiB
JavaScript

var $jitug$reactstatelyselection = require("@react-stately/selection");
var $jitug$react = require("react");
var $jitug$reactstatelycollections = require("@react-stately/collections");
var $jitug$reactstatelyutils = require("@react-stately/utils");
function $parcel$export(e, n, v, s) {
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
}
$parcel$export(module.exports, "useListState", () => $5450691d3629f6ea$export$2f645645f7bca764);
$parcel$export(module.exports, "useSingleSelectListState", () => $b9e99587a092d199$export$e7f05e985daf4b5f);
$parcel$export(module.exports, "ListCollection", () => $c9aa5a224613c979$export$d085fb9e920b5ca7);
/*
* Copyright 2020 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/ /*
* Copyright 2020 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/ /*
* Copyright 2020 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/ class $c9aa5a224613c979$export$d085fb9e920b5ca7 {
*[Symbol.iterator]() {
yield* this.iterable;
}
get size() {
return this.keyMap.size;
}
getKeys() {
return this.keyMap.keys();
}
getKeyBefore(key) {
let node = this.keyMap.get(key);
return node ? node.prevKey : null;
}
getKeyAfter(key) {
let node = this.keyMap.get(key);
return node ? node.nextKey : null;
}
getFirstKey() {
return this.firstKey;
}
getLastKey() {
return this.lastKey;
}
getItem(key) {
return this.keyMap.get(key);
}
at(idx) {
const keys = [
...this.getKeys()
];
return this.getItem(keys[idx]);
}
getChildren(key) {
let node = this.keyMap.get(key);
return (node === null || node === void 0 ? void 0 : node.childNodes) || [];
}
constructor(nodes){
this.keyMap = new Map();
this.iterable = nodes;
let visit = (node)=>{
this.keyMap.set(node.key, node);
if (node.childNodes && node.type === "section") for (let child of node.childNodes)visit(child);
};
for (let node of nodes)visit(node);
let last;
let index = 0;
for (let [key, node] of this.keyMap){
if (last) {
last.nextKey = key;
node.prevKey = last.key;
} else {
this.firstKey = key;
node.prevKey = undefined;
}
if (node.type === "item") node.index = index++;
last = node;
// Set nextKey as undefined since this might be the last node
// If it isn't the last node, last.nextKey will properly set at start of new loop
last.nextKey = undefined;
}
this.lastKey = last === null || last === void 0 ? void 0 : last.key;
}
}
function $5450691d3629f6ea$export$2f645645f7bca764(props) {
let { filter: filter } = props;
let selectionState = (0, $jitug$reactstatelyselection.useMultipleSelectionState)(props);
let disabledKeys = (0, $jitug$react.useMemo)(()=>props.disabledKeys ? new Set(props.disabledKeys) : new Set(), [
props.disabledKeys
]);
let factory = (0, $jitug$react.useCallback)((nodes)=>filter ? new (0, $c9aa5a224613c979$export$d085fb9e920b5ca7)(filter(nodes)) : new (0, $c9aa5a224613c979$export$d085fb9e920b5ca7)(nodes), [
filter
]);
let context = (0, $jitug$react.useMemo)(()=>({
suppressTextValueWarning: props.suppressTextValueWarning
}), [
props.suppressTextValueWarning
]);
let collection = (0, $jitug$reactstatelycollections.useCollection)(props, factory, context);
let selectionManager = (0, $jitug$react.useMemo)(()=>new (0, $jitug$reactstatelyselection.SelectionManager)(collection, selectionState), [
collection,
selectionState
]);
// Reset focused key if that item is deleted from the collection.
const cachedCollection = (0, $jitug$react.useRef)(null);
(0, $jitug$react.useEffect)(()=>{
if (selectionState.focusedKey != null && !collection.getItem(selectionState.focusedKey)) {
const startItem = cachedCollection.current.getItem(selectionState.focusedKey);
const cachedItemNodes = [
...cachedCollection.current.getKeys()
].map((key)=>{
const itemNode = cachedCollection.current.getItem(key);
return itemNode.type === "item" ? itemNode : null;
}).filter((node)=>node !== null);
const itemNodes = [
...collection.getKeys()
].map((key)=>{
const itemNode = collection.getItem(key);
return itemNode.type === "item" ? itemNode : null;
}).filter((node)=>node !== null);
const diff = cachedItemNodes.length - itemNodes.length;
let index = Math.min(diff > 1 ? Math.max(startItem.index - diff + 1, 0) : startItem.index, itemNodes.length - 1);
let newNode;
while(index >= 0){
if (!selectionManager.isDisabled(itemNodes[index].key)) {
newNode = itemNodes[index];
break;
}
// Find next, not disabled item.
if (index < itemNodes.length - 1) index++;
else {
if (index > startItem.index) index = startItem.index;
index--;
}
}
selectionState.setFocusedKey(newNode ? newNode.key : null);
}
cachedCollection.current = collection;
}, [
collection,
selectionManager,
selectionState,
selectionState.focusedKey
]);
return {
collection: collection,
disabledKeys: disabledKeys,
selectionManager: selectionManager
};
}
/*
* Copyright 2020 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
function $b9e99587a092d199$export$e7f05e985daf4b5f(props) {
var _props_defaultSelectedKey;
let [selectedKey, setSelectedKey] = (0, $jitug$reactstatelyutils.useControlledState)(props.selectedKey, (_props_defaultSelectedKey = props.defaultSelectedKey) !== null && _props_defaultSelectedKey !== void 0 ? _props_defaultSelectedKey : null, props.onSelectionChange);
let selectedKeys = (0, $jitug$react.useMemo)(()=>selectedKey != null ? [
selectedKey
] : [], [
selectedKey
]);
let { collection: collection, disabledKeys: disabledKeys, selectionManager: selectionManager } = (0, $5450691d3629f6ea$export$2f645645f7bca764)({
...props,
selectionMode: "single",
disallowEmptySelection: true,
allowDuplicateSelectionEvents: true,
selectedKeys: selectedKeys,
onSelectionChange: (keys)=>{
var _keys_values_next_value;
let key = (_keys_values_next_value = keys.values().next().value) !== null && _keys_values_next_value !== void 0 ? _keys_values_next_value : null;
// Always fire onSelectionChange, even if the key is the same
// as the current key (useControlledState does not).
if (key === selectedKey && props.onSelectionChange) props.onSelectionChange(key);
setSelectedKey(key);
}
});
let selectedItem = selectedKey != null ? collection.getItem(selectedKey) : null;
return {
collection: collection,
disabledKeys: disabledKeys,
selectionManager: selectionManager,
selectedKey: selectedKey,
setSelectedKey: setSelectedKey,
selectedItem: selectedItem
};
}
//# sourceMappingURL=main.js.map