Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@react-stately/grid

Package Overview
Dependencies
Maintainers
2
Versions
773
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.1.1-nightly.3040 to 3.1.1-nightly.3047

363

dist/main.js

@@ -1,225 +0,178 @@

var _babelRuntimeHelpersExtends = $parcel$interopDefault(require("@babel/runtime/helpers/extends"));
var $3Qct6$react = require("react");
var $3Qct6$reactstatelyselection = require("@react-stately/selection");
var {
SelectionManager,
useMultipleSelectionState
} = require("@react-stately/selection");
function $parcel$exportWildcard(dest, source) {
Object.keys(source).forEach(function(key) {
if (key === 'default' || key === '__esModule' || dest.hasOwnProperty(key)) {
return;
}
var {
useEffect,
useMemo
} = require("react");
function $parcel$interopDefault(a) {
return a && a.__esModule ? a.default : a;
}
/**
* Provides state management for a grid component. Handles row selection and focusing a grid cell's focusable child if applicable.
*/
function useGridState(props) {
let {
collection,
focusMode
} = props;
let selectionState = useMultipleSelectionState(props);
let disabledKeys = 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 ? void 0 : item.type) === 'item') {
let children = [...item.childNodes];
if (child === 'last') {
var _children;
key = (_children = children[children.length - 1]) == null ? void 0 : _children.key;
} else {
var _children$;
key = (_children$ = children[0]) == null ? void 0 : _children$.key;
}
Object.defineProperty(dest, key, {
enumerable: true,
get: function get() {
return source[key];
}
}
});
});
setFocusedKey(key, child);
}; // Reset focused key if that item is deleted from the collection.
useEffect(() => {
if (selectionState.focusedKey != null && !collection.getItem(selectionState.focusedKey)) {
selectionState.setFocusedKey(null);
}
}, [collection, selectionState.focusedKey]);
return {
collection,
disabledKeys,
selectionManager: new SelectionManager(collection, selectionState)
};
return dest;
}
function $parcel$export(e, n, v, s) {
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
}
var $805edb38a3079ec2$exports = {};
exports.useGridState = useGridState;
let $b9f358a1a5a44d4c3a26859$var$_Symbol$iterator;
$b9f358a1a5a44d4c3a26859$var$_Symbol$iterator = Symbol.iterator;
$parcel$export($805edb38a3079ec2$exports, "useGridState", () => $805edb38a3079ec2$export$4007ac09ff9c68ed);
/*
* 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 GridCollection {
constructor(opts) {
this.keyMap = new Map();
this.columnCount = void 0;
this.rows = void 0;
this.keyMap = new Map();
this.columnCount = opts == null ? 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;
function $805edb38a3079ec2$export$4007ac09ff9c68ed(props) {
let { collection: collection , focusMode: focusMode } = props;
let selectionState = $3Qct6$reactstatelyselection.useMultipleSelectionState(props);
let disabledKeys = $3Qct6$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?.type === 'item') {
let children = [
...item.childNodes
];
if (child === 'last') key = children[children.length - 1]?.key;
else key = children[0]?.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);
}
}
}
setFocusedKey(key, child);
};
let remove = node => {
this.keyMap.delete(node.key);
for (let child of node.childNodes) {
if (this.keyMap.get(child.key) === child) {
remove(child);
}
}
// Reset focused key if that item is deleted from the collection.
$3Qct6$react.useEffect(()=>{
if (selectionState.focusedKey != null && !collection.getItem(selectionState.focusedKey)) selectionState.setFocusedKey(null);
}, [
collection,
selectionState.focusedKey
]);
return {
collection: collection,
disabledKeys: disabledKeys,
selectionManager: new $3Qct6$reactstatelyselection.SelectionManager(collection, selectionState)
};
}
let last;
opts.items.forEach((node, i) => {
let rowNode = _babelRuntimeHelpersExtends({
level: 0,
key: 'row-' + i,
type: 'row',
value: undefined,
hasChildNodes: true,
childNodes: [...node.childNodes],
rendered: undefined,
textValue: undefined
}, node, {
index: i
});
if (last) {
last.nextKey = rowNode.key;
rowNode.prevKey = last.key;
} else {
rowNode.prevKey = null;
}
var $ca89265eb29da87b$exports = {};
this.rows.push(rowNode);
visit(rowNode);
last = rowNode;
});
if (last) {
last.nextKey = null;
$parcel$export($ca89265eb29da87b$exports, "GridCollection", () => $ca89265eb29da87b$export$de3fdf6493c353d);
class $ca89265eb29da87b$export$de3fdf6493c353d {
constructor(opts){
this.keyMap = new Map();
this.keyMap = new Map();
this.columnCount = 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 last1;
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,
index: i
};
if (last1) {
last1.nextKey = rowNode.key;
rowNode.prevKey = last1.key;
} else rowNode.prevKey = null;
this.rows.push(rowNode);
visit(rowNode);
last1 = rowNode;
});
if (last1) last1.nextKey = null;
}
}
*[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() {
return [
...this.rows
][0]?.key;
}
getLastKey() {
let rows = [
...this.rows
];
return rows[rows.length - 1]?.key;
}
getItem(key) {
return this.keyMap.get(key);
}
at(idx) {
const keys = [
...this.getKeys()
];
return this.getItem(keys[idx]);
}
}
*[$b9f358a1a5a44d4c3a26859$var$_Symbol$iterator]() {
yield* [...this.rows];
}
get size() {
return [...this.rows].length;
}
$parcel$exportWildcard(module.exports, $805edb38a3079ec2$exports);
$parcel$exportWildcard(module.exports, $ca89265eb29da87b$exports);
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 : _.key;
}
getLastKey() {
var _rows;
let rows = [...this.rows];
return (_rows = rows[rows.length - 1]) == null ? void 0 : _rows.key;
}
getItem(key) {
return this.keyMap.get(key);
}
at(idx) {
const keys = [...this.getKeys()];
return this.getItem(keys[idx]);
}
}
exports.GridCollection = GridCollection;
//# sourceMappingURL=main.js.map

@@ -1,209 +0,161 @@

import _babelRuntimeHelpersEsmExtends from "@babel/runtime/helpers/esm/extends";
import { SelectionManager, useMultipleSelectionState } from "@react-stately/selection";
import { useEffect, useMemo } from "react";
import {useMemo as $be5ec$useMemo, useEffect as $be5ec$useEffect} from "react";
import {useMultipleSelectionState as $be5ec$useMultipleSelectionState, SelectionManager as $be5ec$SelectionManager} from "@react-stately/selection";
/**
* Provides state management for a grid component. Handles row selection and focusing a grid cell's focusable child if applicable.
*/
export function useGridState(props) {
let {
collection,
focusMode
} = props;
let selectionState = useMultipleSelectionState(props);
let disabledKeys = 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 ? void 0 : item.type) === 'item') {
let children = [...item.childNodes];
if (child === 'last') {
var _children;
key = (_children = children[children.length - 1]) == null ? void 0 : _children.key;
} else {
var _children$;
key = (_children$ = children[0]) == null ? void 0 : _children$.key;
}
}
}
setFocusedKey(key, child);
}; // Reset focused key if that item is deleted from the collection.
useEffect(() => {
if (selectionState.focusedKey != null && !collection.getItem(selectionState.focusedKey)) {
selectionState.setFocusedKey(null);
}
}, [collection, selectionState.focusedKey]);
return {
collection,
disabledKeys,
selectionManager: new SelectionManager(collection, selectionState)
};
function $parcel$export(e, n, v, s) {
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
}
let $a681bbd8853a1e20321bd2b414f7894f$var$_Symbol$iterator;
$a681bbd8853a1e20321bd2b414f7894f$var$_Symbol$iterator = Symbol.iterator;
var $c40bc2996decec31$exports = {};
/*
* 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.
*/
export class GridCollection {
constructor(opts) {
this.keyMap = new Map();
this.columnCount = void 0;
this.rows = void 0;
this.keyMap = new Map();
this.columnCount = opts == null ? void 0 : opts.columnCount;
this.rows = [];
$parcel$export($c40bc2996decec31$exports, "useGridState", () => $c40bc2996decec31$export$4007ac09ff9c68ed);
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;
function $c40bc2996decec31$export$4007ac09ff9c68ed(props) {
let { collection: collection , focusMode: focusMode } = props;
let selectionState = $be5ec$useMultipleSelectionState(props);
let disabledKeys = $be5ec$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?.type === 'item') {
let children = [
...item.childNodes
];
if (child === 'last') key = children[children.length - 1]?.key;
else key = children[0]?.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);
}
}
}
setFocusedKey(key, child);
};
let remove = node => {
this.keyMap.delete(node.key);
for (let child of node.childNodes) {
if (this.keyMap.get(child.key) === child) {
remove(child);
}
}
// Reset focused key if that item is deleted from the collection.
$be5ec$useEffect(()=>{
if (selectionState.focusedKey != null && !collection.getItem(selectionState.focusedKey)) selectionState.setFocusedKey(null);
}, [
collection,
selectionState.focusedKey
]);
return {
collection: collection,
disabledKeys: disabledKeys,
selectionManager: new $be5ec$SelectionManager(collection, selectionState)
};
}
let last;
opts.items.forEach((node, i) => {
let rowNode = _babelRuntimeHelpersEsmExtends({
level: 0,
key: 'row-' + i,
type: 'row',
value: undefined,
hasChildNodes: true,
childNodes: [...node.childNodes],
rendered: undefined,
textValue: undefined
}, node, {
index: i
});
if (last) {
last.nextKey = rowNode.key;
rowNode.prevKey = last.key;
} else {
rowNode.prevKey = null;
}
var $8c07656437c834f0$exports = {};
this.rows.push(rowNode);
visit(rowNode);
last = rowNode;
});
if (last) {
last.nextKey = null;
$parcel$export($8c07656437c834f0$exports, "GridCollection", () => $8c07656437c834f0$export$de3fdf6493c353d);
class $8c07656437c834f0$export$de3fdf6493c353d {
constructor(opts){
this.keyMap = new Map();
this.keyMap = new Map();
this.columnCount = 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 last1;
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,
index: i
};
if (last1) {
last1.nextKey = rowNode.key;
rowNode.prevKey = last1.key;
} else rowNode.prevKey = null;
this.rows.push(rowNode);
visit(rowNode);
last1 = rowNode;
});
if (last1) last1.nextKey = null;
}
}
*[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() {
return [
...this.rows
][0]?.key;
}
getLastKey() {
let rows = [
...this.rows
];
return rows[rows.length - 1]?.key;
}
getItem(key) {
return this.keyMap.get(key);
}
at(idx) {
const keys = [
...this.getKeys()
];
return this.getItem(keys[idx]);
}
}
*[$a681bbd8853a1e20321bd2b414f7894f$var$_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 : _.key;
}
getLastKey() {
var _rows;
let rows = [...this.rows];
return (_rows = rows[rows.length - 1]) == null ? void 0 : _rows.key;
}
getItem(key) {
return this.keyMap.get(key);
}
at(idx) {
const keys = [...this.getKeys()];
return this.getItem(keys[idx]);
}
}
export {$c40bc2996decec31$export$4007ac09ff9c68ed as useGridState, $8c07656437c834f0$export$de3fdf6493c353d as GridCollection};
//# sourceMappingURL=module.js.map

@@ -32,7 +32,7 @@ import { GridCollection as _GridCollection1, GridNode, GridRow } from "@react-types/grid";

get size(): number;
getKeys(): IterableIterator<string | number>;
getKeyBefore(key: Key): string | number;
getKeyAfter(key: Key): string | number;
getFirstKey(): string | number;
getLastKey(): string | number;
getKeys(): IterableIterator<Key>;
getKeyBefore(key: Key): Key;
getKeyAfter(key: Key): Key;
getFirstKey(): Key;
getLastKey(): Key;
getItem(key: Key): GridNode<T>;

@@ -39,0 +39,0 @@ at(idx: number): GridNode<T>;

{
"name": "@react-stately/grid",
"version": "3.1.1-nightly.3040+e2b459ab9",
"version": "3.1.1-nightly.3047+87960ad25",
"description": "Spectrum UI components in React",

@@ -21,5 +21,5 @@ "license": "Apache-2.0",

"@babel/runtime": "^7.6.2",
"@react-stately/selection": "3.0.0-nightly.1349+e2b459ab9",
"@react-types/grid": "3.0.1-nightly.3040+e2b459ab9",
"@react-types/shared": "3.0.0-nightly.1349+e2b459ab9"
"@react-stately/selection": "3.0.0-nightly.1356+87960ad25",
"@react-types/grid": "3.0.1-nightly.3047+87960ad25",
"@react-types/shared": "3.0.0-nightly.1356+87960ad25"
},

@@ -32,3 +32,3 @@ "peerDependencies": {

},
"gitHead": "e2b459ab996abd06b0913942e9801b88493ed940"
"gitHead": "87960ad25c26bc4cd6af506bb5e7e0f06621556c"
}

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