Socket
Socket
Sign inDemoInstall

@react-stately/grid

Package Overview
Dependencies
Maintainers
2
Versions
673
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@react-stately/grid - npm Package Compare versions

Comparing version 3.8.6-nightly.4555 to 3.8.6-nightly.4558

dist/GridCollection.main.js

202

dist/main.js

@@ -1,4 +0,3 @@

var $82f7L$reactstatelycollections = require("@react-stately/collections");
var $82f7L$reactstatelyselection = require("@react-stately/selection");
var $82f7L$react = require("react");
var $38009b28e45912ea$exports = require("./useGridState.main.js");
var $8bb6a9101b052a66$exports = require("./GridCollection.main.js");

@@ -10,4 +9,4 @@

$parcel$export(module.exports, "useGridState", () => $38009b28e45912ea$export$4007ac09ff9c68ed);
$parcel$export(module.exports, "GridCollection", () => $8bb6a9101b052a66$export$de3fdf6493c353d);
$parcel$export(module.exports, "useGridState", () => $38009b28e45912ea$exports.useGridState);
$parcel$export(module.exports, "GridCollection", () => $8bb6a9101b052a66$exports.GridCollection);
/*

@@ -26,196 +25,3 @@ * Copyright 2020 Adobe. All rights reserved.

function $38009b28e45912ea$export$4007ac09ff9c68ed(props) {
let { collection: collection, focusMode: focusMode } = props;
let selectionState = (0, $82f7L$reactstatelyselection.useMultipleSelectionState)(props);
let disabledKeys = (0, $82f7L$react.useMemo)(()=>props.disabledKeys ? new Set(props.disabledKeys) : new Set(), [
props.disabledKeys
]);
let setFocusedKey = selectionState.setFocusedKey;
selectionState.setFocusedKey = (key, child)=>{
// If focusMode is cell and an item is focused, focus a child cell instead.
if (focusMode === "cell" && key != null) {
let item = collection.getItem(key);
if ((item === null || item === void 0 ? void 0 : item.type) === "item") {
var _getLastItem, _getFirstItem;
let children = (0, $82f7L$reactstatelycollections.getChildNodes)(item, collection);
if (child === "last") key = (_getLastItem = (0, $82f7L$reactstatelycollections.getLastItem)(children)) === null || _getLastItem === void 0 ? void 0 : _getLastItem.key;
else key = (_getFirstItem = (0, $82f7L$reactstatelycollections.getFirstItem)(children)) === null || _getFirstItem === void 0 ? void 0 : _getFirstItem.key;
}
}
setFocusedKey(key, child);
};
let selectionManager = (0, $82f7L$react.useMemo)(()=>new (0, $82f7L$reactstatelyselection.SelectionManager)(collection, selectionState), [
collection,
selectionState
]);
// Reset focused key if that item is deleted from the collection.
const cachedCollection = (0, $82f7L$react.useRef)(null);
(0, $82f7L$react.useEffect)(()=>{
if (selectionState.focusedKey != null && !collection.getItem(selectionState.focusedKey)) {
const node = cachedCollection.current.getItem(selectionState.focusedKey);
const parentNode = node.parentKey != null && (node.type === "cell" || node.type === "rowheader" || node.type === "column") ? cachedCollection.current.getItem(node.parentKey) : node;
const cachedRows = cachedCollection.current.rows;
const rows = collection.rows;
const diff = cachedRows.length - rows.length;
let index = Math.min(diff > 1 ? Math.max(parentNode.index - diff + 1, 0) : parentNode.index, rows.length - 1);
let newRow;
while(index >= 0){
if (!selectionManager.isDisabled(rows[index].key) && rows[index].type !== "headerrow") {
newRow = rows[index];
break;
}
// Find next, not disabled row.
if (index < rows.length - 1) index++;
else {
if (index > parentNode.index) index = parentNode.index;
index--;
}
}
if (newRow) {
const childNodes = newRow.hasChildNodes ? [
...(0, $82f7L$reactstatelycollections.getChildNodes)(newRow, collection)
] : [];
const keyToFocus = newRow.hasChildNodes && parentNode !== node && node.index < childNodes.length ? childNodes[node.index].key : newRow.key;
selectionState.setFocusedKey(keyToFocus);
} else selectionState.setFocusedKey(null);
}
cachedCollection.current = collection;
}, [
collection,
selectionManager,
selectionState,
selectionState.focusedKey
]);
return {
collection: collection,
disabledKeys: disabledKeys,
isKeyboardNavigationDisabled: false,
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.
*/ class $8bb6a9101b052a66$export$de3fdf6493c353d {
*[Symbol.iterator]() {
yield* [
...this.rows
];
}
get size() {
return [
...this.rows
].length;
}
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() {
var _;
return (_ = [
...this.rows
][0]) === null || _ === void 0 ? void 0 : _.key;
}
getLastKey() {
var _rows_;
let rows = [
...this.rows
];
return (_rows_ = rows[rows.length - 1]) === null || _rows_ === void 0 ? void 0 : _rows_.key;
}
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(opts){
this.keyMap = new Map();
this.keyMap = new Map();
this.columnCount = opts === null || opts === void 0 ? void 0 : opts.columnCount;
this.rows = [];
let visit = (node)=>{
// If the node is the same object as the previous node for the same key,
// we can skip this node and its children. We always visit columns though,
// because we depend on order to build the columns array.
let prevNode = this.keyMap.get(node.key);
if (opts.visitNode) node = opts.visitNode(node);
this.keyMap.set(node.key, node);
let childKeys = new Set();
let last;
for (let child of node.childNodes){
if (child.type === "cell" && child.parentKey == null) // if child is a cell parent key isn't already established by the collection, match child node to parent row
child.parentKey = node.key;
childKeys.add(child.key);
if (last) {
last.nextKey = child.key;
child.prevKey = last.key;
} else child.prevKey = null;
visit(child);
last = child;
}
if (last) last.nextKey = null;
// Remove deleted nodes and their children from the key map
if (prevNode) {
for (let child of prevNode.childNodes)if (!childKeys.has(child.key)) remove(child);
}
};
let remove = (node)=>{
this.keyMap.delete(node.key);
for (let child of node.childNodes)if (this.keyMap.get(child.key) === child) remove(child);
};
let last;
opts.items.forEach((node, i)=>{
let rowNode = {
level: 0,
key: "row-" + i,
type: "row",
value: undefined,
hasChildNodes: true,
childNodes: [
...node.childNodes
],
rendered: undefined,
textValue: undefined,
...node
};
if (last) {
last.nextKey = rowNode.key;
rowNode.prevKey = last.key;
} else rowNode.prevKey = null;
this.rows.push(rowNode);
visit(rowNode);
last = rowNode;
});
if (last) last.nextKey = null;
}
}
//# sourceMappingURL=main.js.map

@@ -1,4 +0,3 @@

import {getChildNodes as $cAn5f$getChildNodes, getLastItem as $cAn5f$getLastItem, getFirstItem as $cAn5f$getFirstItem} from "@react-stately/collections";
import {useMultipleSelectionState as $cAn5f$useMultipleSelectionState, SelectionManager as $cAn5f$SelectionManager} from "@react-stately/selection";
import {useMemo as $cAn5f$useMemo, useRef as $cAn5f$useRef, useEffect as $cAn5f$useEffect} from "react";
import {useGridState as $62967d126f3aa823$export$4007ac09ff9c68ed} from "./useGridState.module.js";
import {GridCollection as $16805b1b18093c5f$export$de3fdf6493c353d} from "./GridCollection.module.js";

@@ -18,197 +17,4 @@ /*

function $62967d126f3aa823$export$4007ac09ff9c68ed(props) {
let { collection: collection, focusMode: focusMode } = props;
let selectionState = (0, $cAn5f$useMultipleSelectionState)(props);
let disabledKeys = (0, $cAn5f$useMemo)(()=>props.disabledKeys ? new Set(props.disabledKeys) : new Set(), [
props.disabledKeys
]);
let setFocusedKey = selectionState.setFocusedKey;
selectionState.setFocusedKey = (key, child)=>{
// If focusMode is cell and an item is focused, focus a child cell instead.
if (focusMode === "cell" && key != null) {
let item = collection.getItem(key);
if ((item === null || item === void 0 ? void 0 : item.type) === "item") {
var _getLastItem, _getFirstItem;
let children = (0, $cAn5f$getChildNodes)(item, collection);
if (child === "last") key = (_getLastItem = (0, $cAn5f$getLastItem)(children)) === null || _getLastItem === void 0 ? void 0 : _getLastItem.key;
else key = (_getFirstItem = (0, $cAn5f$getFirstItem)(children)) === null || _getFirstItem === void 0 ? void 0 : _getFirstItem.key;
}
}
setFocusedKey(key, child);
};
let selectionManager = (0, $cAn5f$useMemo)(()=>new (0, $cAn5f$SelectionManager)(collection, selectionState), [
collection,
selectionState
]);
// Reset focused key if that item is deleted from the collection.
const cachedCollection = (0, $cAn5f$useRef)(null);
(0, $cAn5f$useEffect)(()=>{
if (selectionState.focusedKey != null && !collection.getItem(selectionState.focusedKey)) {
const node = cachedCollection.current.getItem(selectionState.focusedKey);
const parentNode = node.parentKey != null && (node.type === "cell" || node.type === "rowheader" || node.type === "column") ? cachedCollection.current.getItem(node.parentKey) : node;
const cachedRows = cachedCollection.current.rows;
const rows = collection.rows;
const diff = cachedRows.length - rows.length;
let index = Math.min(diff > 1 ? Math.max(parentNode.index - diff + 1, 0) : parentNode.index, rows.length - 1);
let newRow;
while(index >= 0){
if (!selectionManager.isDisabled(rows[index].key) && rows[index].type !== "headerrow") {
newRow = rows[index];
break;
}
// Find next, not disabled row.
if (index < rows.length - 1) index++;
else {
if (index > parentNode.index) index = parentNode.index;
index--;
}
}
if (newRow) {
const childNodes = newRow.hasChildNodes ? [
...(0, $cAn5f$getChildNodes)(newRow, collection)
] : [];
const keyToFocus = newRow.hasChildNodes && parentNode !== node && node.index < childNodes.length ? childNodes[node.index].key : newRow.key;
selectionState.setFocusedKey(keyToFocus);
} else selectionState.setFocusedKey(null);
}
cachedCollection.current = collection;
}, [
collection,
selectionManager,
selectionState,
selectionState.focusedKey
]);
return {
collection: collection,
disabledKeys: disabledKeys,
isKeyboardNavigationDisabled: false,
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.
*/ class $16805b1b18093c5f$export$de3fdf6493c353d {
*[Symbol.iterator]() {
yield* [
...this.rows
];
}
get size() {
return [
...this.rows
].length;
}
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() {
var _;
return (_ = [
...this.rows
][0]) === null || _ === void 0 ? void 0 : _.key;
}
getLastKey() {
var _rows_;
let rows = [
...this.rows
];
return (_rows_ = rows[rows.length - 1]) === null || _rows_ === void 0 ? void 0 : _rows_.key;
}
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(opts){
this.keyMap = new Map();
this.keyMap = new Map();
this.columnCount = opts === null || opts === void 0 ? void 0 : opts.columnCount;
this.rows = [];
let visit = (node)=>{
// If the node is the same object as the previous node for the same key,
// we can skip this node and its children. We always visit columns though,
// because we depend on order to build the columns array.
let prevNode = this.keyMap.get(node.key);
if (opts.visitNode) node = opts.visitNode(node);
this.keyMap.set(node.key, node);
let childKeys = new Set();
let last;
for (let child of node.childNodes){
if (child.type === "cell" && child.parentKey == null) // if child is a cell parent key isn't already established by the collection, match child node to parent row
child.parentKey = node.key;
childKeys.add(child.key);
if (last) {
last.nextKey = child.key;
child.prevKey = last.key;
} else child.prevKey = null;
visit(child);
last = child;
}
if (last) last.nextKey = null;
// Remove deleted nodes and their children from the key map
if (prevNode) {
for (let child of prevNode.childNodes)if (!childKeys.has(child.key)) remove(child);
}
};
let remove = (node)=>{
this.keyMap.delete(node.key);
for (let child of node.childNodes)if (this.keyMap.get(child.key) === child) remove(child);
};
let last;
opts.items.forEach((node, i)=>{
let rowNode = {
level: 0,
key: "row-" + i,
type: "row",
value: undefined,
hasChildNodes: true,
childNodes: [
...node.childNodes
],
rendered: undefined,
textValue: undefined,
...node
};
if (last) {
last.nextKey = rowNode.key;
rowNode.prevKey = last.key;
} else rowNode.prevKey = null;
this.rows.push(rowNode);
visit(rowNode);
last = rowNode;
});
if (last) last.nextKey = null;
}
}
export {$62967d126f3aa823$export$4007ac09ff9c68ed as useGridState, $16805b1b18093c5f$export$de3fdf6493c353d as GridCollection};
//# sourceMappingURL=module.js.map
{
"name": "@react-stately/grid",
"version": "3.8.6-nightly.4555+81162ea39",
"version": "3.8.6-nightly.4558+c5e4b3701",
"description": "Spectrum UI components in React",

@@ -25,6 +25,6 @@ "license": "Apache-2.0",

"dependencies": {
"@react-stately/collections": "3.0.0-nightly.2843+81162ea39",
"@react-stately/selection": "3.0.0-nightly.2843+81162ea39",
"@react-types/grid": "3.2.5-nightly.4555+81162ea39",
"@react-types/shared": "3.0.0-nightly.2843+81162ea39",
"@react-stately/collections": "3.0.0-nightly.2846+c5e4b3701",
"@react-stately/selection": "3.0.0-nightly.2846+c5e4b3701",
"@react-types/grid": "3.2.5-nightly.4558+c5e4b3701",
"@react-types/shared": "3.0.0-nightly.2846+c5e4b3701",
"@swc/helpers": "^0.5.0"

@@ -38,3 +38,3 @@ },

},
"gitHead": "81162ea392926d06ec3d25c228e6f9b6b5479d59"
"gitHead": "c5e4b3701fdb89eb551f1b3697ac253f06ef68fa"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc