95 lines
3.5 KiB
Plaintext
95 lines
3.5 KiB
Plaintext
|
|
function $parcel$export(e, n, v, s) {
|
|
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
}
|
|
|
|
$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.
|
|
*/ class $c9aa5a224613c979$export$d085fb9e920b5ca7 {
|
|
*[Symbol.iterator]() {
|
|
yield* this.iterable;
|
|
}
|
|
get size() {
|
|
return this._size;
|
|
}
|
|
getKeys() {
|
|
return this.keyMap.keys();
|
|
}
|
|
getKeyBefore(key) {
|
|
let node = this.keyMap.get(key);
|
|
var _node_prevKey;
|
|
return node ? (_node_prevKey = node.prevKey) !== null && _node_prevKey !== void 0 ? _node_prevKey : null : null;
|
|
}
|
|
getKeyAfter(key) {
|
|
let node = this.keyMap.get(key);
|
|
var _node_nextKey;
|
|
return node ? (_node_nextKey = node.nextKey) !== null && _node_nextKey !== void 0 ? _node_nextKey : null : null;
|
|
}
|
|
getFirstKey() {
|
|
return this.firstKey;
|
|
}
|
|
getLastKey() {
|
|
return this.lastKey;
|
|
}
|
|
getItem(key) {
|
|
var _this_keyMap_get;
|
|
return (_this_keyMap_get = this.keyMap.get(key)) !== null && _this_keyMap_get !== void 0 ? _this_keyMap_get : null;
|
|
}
|
|
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.firstKey = null;
|
|
this.lastKey = null;
|
|
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 = null;
|
|
let index = 0;
|
|
let size = 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++;
|
|
// Only count sections and items when determining size so that
|
|
// loaders and separators in RAC/S2 don't influence the emptyState determination
|
|
if (node.type === 'section' || node.type === 'item') size++;
|
|
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._size = size;
|
|
var _last_key;
|
|
this.lastKey = (_last_key = last === null || last === void 0 ? void 0 : last.key) !== null && _last_key !== void 0 ? _last_key : null;
|
|
}
|
|
}
|
|
|
|
|
|
//# sourceMappingURL=ListCollection.main.js.map
|