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

@react-stately/collections

Package Overview
Dependencies
Maintainers
2
Versions
812
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@react-stately/collections - npm Package Compare versions

Comparing version 3.0.0-nightly-a98da553e-241116 to 3.0.0-nightly-b3a4d6c11-241119

53

dist/CollectionBuilder.main.js

@@ -37,11 +37,16 @@ var $ioO2y$react = require("react");

if (!items) throw new Error('props.children was a function but props.items is missing');
for (let item of props.items)yield* this.getFullNode({
value: item
}, {
renderer: children
});
let index = 0;
for (let item of items){
yield* this.getFullNode({
value: item,
index: index
}, {
renderer: children
});
index++;
}
} else {
let items = [];
(0, ($parcel$interopDefault($ioO2y$react))).Children.forEach(children, (child)=>{
items.push(child);
if (child) items.push(child);
});

@@ -84,3 +89,4 @@ let index = 0;

});
let index = partialNode.index;
var _partialNode_index;
let index = (_partialNode_index = partialNode.index) !== null && _partialNode_index !== void 0 ? _partialNode_index : 0;
for (const child of children)yield* this.getFullNode({

@@ -110,7 +116,8 @@ element: child,

if (typeof type !== 'function' && typeof type.getCollectionNode !== 'function') {
let name = typeof element.type === 'function' ? element.type.name : element.type;
let name = element.type;
throw new Error(`Unknown element <${name}> in collection.`);
}
let childNodes = type.getCollectionNode(element.props, this.context);
let index = partialNode.index;
var _partialNode_index1;
let index = (_partialNode_index1 = partialNode.index) !== null && _partialNode_index1 !== void 0 ? _partialNode_index1 : 0;
let result = childNodes.next();

@@ -120,4 +127,5 @@ while(!result.done && result.value){

partialNode.index = index;
let nodeKey = childNode.key;
if (!nodeKey) nodeKey = childNode.element ? null : this.getKey(element, partialNode, state, parentKey);
var _childNode_key;
let nodeKey = (_childNode_key = childNode.key) !== null && _childNode_key !== void 0 ? _childNode_key : null;
if (nodeKey == null) nodeKey = childNode.element ? null : this.getKey(element, partialNode, state, parentKey);
let nodes = this.getFullNode({

@@ -133,8 +141,10 @@ ...childNode,

for (let node of children){
var _childNode_value, _ref;
// Cache the node based on its value
node.value = childNode.value || partialNode.value;
node.value = (_ref = (_childNode_value = childNode.value) !== null && _childNode_value !== void 0 ? _childNode_value : partialNode.value) !== null && _ref !== void 0 ? _ref : null;
if (node.value) this.cache.set(node.value, node);
var _parentNode_type;
// The partial node may have specified a type for the child in order to specify a constraint.
// Verify that the full node that was built recursively matches this type.
if (partialNode.type && node.type !== partialNode.type) throw new Error(`Unsupported type <${$51588fd411aace25$var$capitalize(node.type)}> in <${$51588fd411aace25$var$capitalize(parentNode.type)}>. Only <${$51588fd411aace25$var$capitalize(partialNode.type)}> is supported.`);
if (partialNode.type && node.type !== partialNode.type) throw new Error(`Unsupported type <${$51588fd411aace25$var$capitalize(node.type)}> in <${$51588fd411aace25$var$capitalize((_parentNode_type = parentNode === null || parentNode === void 0 ? void 0 : parentNode.type) !== null && _parentNode_type !== void 0 ? _parentNode_type : 'unknown parent type')}>. Only <${$51588fd411aace25$var$capitalize(partialNode.type)}> is supported.`);
index++;

@@ -148,5 +158,6 @@ yield node;

// Ignore invalid elements
if (partialNode.key == null) return;
if (partialNode.key == null || partialNode.type == null) return;
// Create full node
let builder = this;
var _partialNode_value, _partialNode_textValue;
let node = {

@@ -157,13 +168,13 @@ type: partialNode.type,

parentKey: parentNode ? parentNode.key : null,
value: partialNode.value,
value: (_partialNode_value = partialNode.value) !== null && _partialNode_value !== void 0 ? _partialNode_value : null,
level: parentNode ? parentNode.level + 1 : 0,
index: partialNode.index,
rendered: partialNode.rendered,
textValue: partialNode.textValue,
textValue: (_partialNode_textValue = partialNode.textValue) !== null && _partialNode_textValue !== void 0 ? _partialNode_textValue : '',
'aria-label': partialNode['aria-label'],
wrapper: partialNode.wrapper,
shouldInvalidate: partialNode.shouldInvalidate,
hasChildNodes: partialNode.hasChildNodes,
hasChildNodes: partialNode.hasChildNodes || false,
childNodes: $51588fd411aace25$var$iterable(function*() {
if (!partialNode.hasChildNodes) return;
if (!partialNode.hasChildNodes || !partialNode.childNodes) return;
let index = 0;

@@ -177,4 +188,6 @@ for (let child of partialNode.childNodes()){

child.key = `${node.key}${child.key}`;
child.index = index;
let nodes = builder.getFullNode(child, builder.getChildState(state, child), node.key, node);
let nodes = builder.getFullNode({
...child,
index: index
}, builder.getChildState(state, child), node.key, node);
for (let node of nodes){

@@ -181,0 +194,0 @@ index++;

@@ -27,11 +27,16 @@ import $fzaAv$react from "react";

if (!items) throw new Error('props.children was a function but props.items is missing');
for (let item of props.items)yield* this.getFullNode({
value: item
}, {
renderer: children
});
let index = 0;
for (let item of items){
yield* this.getFullNode({
value: item,
index: index
}, {
renderer: children
});
index++;
}
} else {
let items = [];
(0, $fzaAv$react).Children.forEach(children, (child)=>{
items.push(child);
if (child) items.push(child);
});

@@ -74,3 +79,4 @@ let index = 0;

});
let index = partialNode.index;
var _partialNode_index;
let index = (_partialNode_index = partialNode.index) !== null && _partialNode_index !== void 0 ? _partialNode_index : 0;
for (const child of children)yield* this.getFullNode({

@@ -100,7 +106,8 @@ element: child,

if (typeof type !== 'function' && typeof type.getCollectionNode !== 'function') {
let name = typeof element.type === 'function' ? element.type.name : element.type;
let name = element.type;
throw new Error(`Unknown element <${name}> in collection.`);
}
let childNodes = type.getCollectionNode(element.props, this.context);
let index = partialNode.index;
var _partialNode_index1;
let index = (_partialNode_index1 = partialNode.index) !== null && _partialNode_index1 !== void 0 ? _partialNode_index1 : 0;
let result = childNodes.next();

@@ -110,4 +117,5 @@ while(!result.done && result.value){

partialNode.index = index;
let nodeKey = childNode.key;
if (!nodeKey) nodeKey = childNode.element ? null : this.getKey(element, partialNode, state, parentKey);
var _childNode_key;
let nodeKey = (_childNode_key = childNode.key) !== null && _childNode_key !== void 0 ? _childNode_key : null;
if (nodeKey == null) nodeKey = childNode.element ? null : this.getKey(element, partialNode, state, parentKey);
let nodes = this.getFullNode({

@@ -123,8 +131,10 @@ ...childNode,

for (let node of children){
var _childNode_value, _ref;
// Cache the node based on its value
node.value = childNode.value || partialNode.value;
node.value = (_ref = (_childNode_value = childNode.value) !== null && _childNode_value !== void 0 ? _childNode_value : partialNode.value) !== null && _ref !== void 0 ? _ref : null;
if (node.value) this.cache.set(node.value, node);
var _parentNode_type;
// The partial node may have specified a type for the child in order to specify a constraint.
// Verify that the full node that was built recursively matches this type.
if (partialNode.type && node.type !== partialNode.type) throw new Error(`Unsupported type <${$eb2240fc39a57fa5$var$capitalize(node.type)}> in <${$eb2240fc39a57fa5$var$capitalize(parentNode.type)}>. Only <${$eb2240fc39a57fa5$var$capitalize(partialNode.type)}> is supported.`);
if (partialNode.type && node.type !== partialNode.type) throw new Error(`Unsupported type <${$eb2240fc39a57fa5$var$capitalize(node.type)}> in <${$eb2240fc39a57fa5$var$capitalize((_parentNode_type = parentNode === null || parentNode === void 0 ? void 0 : parentNode.type) !== null && _parentNode_type !== void 0 ? _parentNode_type : 'unknown parent type')}>. Only <${$eb2240fc39a57fa5$var$capitalize(partialNode.type)}> is supported.`);
index++;

@@ -138,5 +148,6 @@ yield node;

// Ignore invalid elements
if (partialNode.key == null) return;
if (partialNode.key == null || partialNode.type == null) return;
// Create full node
let builder = this;
var _partialNode_value, _partialNode_textValue;
let node = {

@@ -147,13 +158,13 @@ type: partialNode.type,

parentKey: parentNode ? parentNode.key : null,
value: partialNode.value,
value: (_partialNode_value = partialNode.value) !== null && _partialNode_value !== void 0 ? _partialNode_value : null,
level: parentNode ? parentNode.level + 1 : 0,
index: partialNode.index,
rendered: partialNode.rendered,
textValue: partialNode.textValue,
textValue: (_partialNode_textValue = partialNode.textValue) !== null && _partialNode_textValue !== void 0 ? _partialNode_textValue : '',
'aria-label': partialNode['aria-label'],
wrapper: partialNode.wrapper,
shouldInvalidate: partialNode.shouldInvalidate,
hasChildNodes: partialNode.hasChildNodes,
hasChildNodes: partialNode.hasChildNodes || false,
childNodes: $eb2240fc39a57fa5$var$iterable(function*() {
if (!partialNode.hasChildNodes) return;
if (!partialNode.hasChildNodes || !partialNode.childNodes) return;
let index = 0;

@@ -167,4 +178,6 @@ for (let child of partialNode.childNodes()){

child.key = `${node.key}${child.key}`;
child.index = index;
let nodes = builder.getFullNode(child, builder.getChildState(state, child), node.key, node);
let nodes = builder.getFullNode({
...child,
index: index
}, builder.getChildState(state, child), node.key, node);
for (let node of nodes){

@@ -171,0 +184,0 @@ index++;

@@ -72,5 +72,6 @@

let parents = [];
while((node === null || node === void 0 ? void 0 : node.parentKey) != null){
node = collection.getItem(node.parentKey);
parents.unshift(node);
let currNode = node;
while((currNode === null || currNode === void 0 ? void 0 : currNode.parentKey) != null){
currNode = collection.getItem(currNode.parentKey);
if (currNode) parents.unshift(currNode);
}

@@ -77,0 +78,0 @@ return parents;

@@ -62,5 +62,6 @@ /*

let parents = [];
while((node === null || node === void 0 ? void 0 : node.parentKey) != null){
node = collection.getItem(node.parentKey);
parents.unshift(node);
let currNode = node;
while((currNode === null || currNode === void 0 ? void 0 : currNode.parentKey) != null){
currNode = collection.getItem(currNode.parentKey);
if (currNode) parents.unshift(currNode);
}

@@ -67,0 +68,0 @@ return parents;

@@ -24,10 +24,11 @@ var $7a155683b0d79a6a$exports = require("./getChildNodes.main.js");

if (count != null) return count;
count = 0;
// TS isn't smart enough to know we've ensured count is a number, so use a new variable
let counter = 0;
let countItems = (items)=>{
for (let item of items)if (item.type === 'section') countItems((0, $7a155683b0d79a6a$exports.getChildNodes)(item, collection));
else count++;
else counter++;
};
countItems(collection);
$e749fe52977fe2c2$var$cache.set(collection, count);
return count;
$e749fe52977fe2c2$var$cache.set(collection, counter);
return counter;
}

@@ -34,0 +35,0 @@

@@ -18,10 +18,11 @@ import {getChildNodes as $c5a24bc478652b5f$export$1005530eda016c13} from "./getChildNodes.module.js";

if (count != null) return count;
count = 0;
// TS isn't smart enough to know we've ensured count is a number, so use a new variable
let counter = 0;
let countItems = (items)=>{
for (let item of items)if (item.type === 'section') countItems((0, $c5a24bc478652b5f$export$1005530eda016c13)(item, collection));
else count++;
else counter++;
};
countItems(collection);
$453cc9f0df89c0a5$var$cache.set(collection, count);
return count;
$453cc9f0df89c0a5$var$cache.set(collection, counter);
return counter;
}

@@ -28,0 +29,0 @@

@@ -5,5 +5,5 @@ import { Key, ItemProps, SectionProps, CollectionBase, Node, Collection, CollectionStateBase } from "@react-types/shared";

type?: string;
key?: Key;
key?: Key | null;
value?: T;
element?: ReactElement;
element?: ReactElement | null;
wrapper?: (element: ReactElement) => ReactElement;

@@ -14,7 +14,7 @@ rendered?: ReactNode;

index?: number;
renderer?: (item: T) => ReactElement;
renderer?: (item: T) => ReactElement | null;
hasChildNodes?: boolean;
childNodes?: () => IterableIterator<PartialNode<T>>;
props?: any;
shouldInvalidate?: (context: unknown) => boolean;
shouldInvalidate?: (context: any) => boolean;
}

@@ -24,6 +24,6 @@ export let Item: <T>(props: ItemProps<T>) => JSX.Element;

export class CollectionBuilder<T extends object> {
build(props: CollectionBase<T>, context?: unknown): Iterable<Node<T>>;
build(props: Partial<CollectionBase<T>>, context?: unknown): Iterable<Node<T>>;
}
interface CollectionOptions<T, C extends Collection<Node<T>>> extends Omit<CollectionStateBase<T, C>, 'children'> {
children?: ReactElement<any> | ReactElement<any>[] | ((item: T) => ReactElement<any>);
children?: ReactElement<any> | null | (ReactElement<any> | null)[] | ((item: T) => ReactElement<any> | null);
}

@@ -30,0 +30,0 @@ type CollectionFactory<T, C extends Collection<Node<T>>> = (node: Iterable<Node<T>>) => C;

{
"name": "@react-stately/collections",
"version": "3.0.0-nightly-a98da553e-241116",
"version": "3.0.0-nightly-b3a4d6c11-241119",
"description": "Spectrum UI components in React",

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

"dependencies": {
"@react-types/shared": "^3.0.0-nightly-a98da553e-241116",
"@react-types/shared": "^3.0.0-nightly-b3a4d6c11-241119",
"@swc/helpers": "^0.5.0"
},
"peerDependencies": {
"react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0"
"react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1"
},

@@ -32,0 +32,0 @@ "publishConfig": {

@@ -18,5 +18,9 @@ /*

interface CollectionBuilderState {
renderer?: (value: any) => ReactElement
renderer?: (value: any) => ReactElement | null
}
interface CollectReactElement<T> extends ReactElement {
getCollectionNode(props: any, context: any): Generator<PartialNode<T>, void, Node<T>[]>
}
export class CollectionBuilder<T extends object> {

@@ -26,3 +30,3 @@ private context?: unknown;

build(props: CollectionBase<T>, context?: unknown) {
build(props: Partial<CollectionBase<T>>, context?: unknown) {
this.context = context;

@@ -32,3 +36,3 @@ return iterable(() => this.iterateCollection(props));

private *iterateCollection(props: CollectionBase<T>): Generator<Node<T>> {
private *iterateCollection(props: Partial<CollectionBase<T>>): Generator<Node<T>> {
let {children, items} = props;

@@ -46,6 +50,9 @@

for (let item of props.items) {
let index = 0;
for (let item of items) {
yield* this.getFullNode({
value: item
value: item,
index
}, {renderer: children});
index++;
}

@@ -55,3 +62,5 @@ } else {

React.Children.forEach(children, child => {
items.push(child);
if (child) {
items.push(child);
}
});

@@ -74,3 +83,3 @@

private getKey(item: CollectionElement<T>, partialNode: PartialNode<T>, state: CollectionBuilderState, parentKey?: Key): Key {
private getKey(item: NonNullable<CollectionElement<T>>, partialNode: PartialNode<T>, state: CollectionBuilderState, parentKey?: Key | null): Key {
if (item.key != null) {

@@ -103,3 +112,3 @@ return item.key;

private *getFullNode(partialNode: PartialNode<T>, state: CollectionBuilderState, parentKey?: Key, parentNode?: Node<T>): Generator<Node<T>> {
private *getFullNode(partialNode: PartialNode<T> & {index: number}, state: CollectionBuilderState, parentKey?: Key | null, parentNode?: Node<T>): Generator<Node<T>> {
if (React.isValidElement<{children: CollectionElement<T>}>(partialNode.element) && partialNode.element.type === React.Fragment) {

@@ -112,3 +121,3 @@ let children: CollectionElement<T>[] = [];

let index = partialNode.index;
let index = partialNode.index ?? 0;

@@ -143,5 +152,5 @@ for (const child of children) {

if (React.isValidElement(element)) {
let type = element.type as any;
let type = element.type as unknown as CollectReactElement<T>;
if (typeof type !== 'function' && typeof type.getCollectionNode !== 'function') {
let name = typeof element.type === 'function' ? element.type.name : element.type;
let name = element.type;
throw new Error(`Unknown element <${name}> in collection.`);

@@ -151,3 +160,3 @@ }

let childNodes = type.getCollectionNode(element.props, this.context) as Generator<PartialNode<T>, void, Node<T>[]>;
let index = partialNode.index;
let index = partialNode.index ?? 0;
let result = childNodes.next();

@@ -159,5 +168,5 @@ while (!result.done && result.value) {

let nodeKey = childNode.key;
if (!nodeKey) {
nodeKey = childNode.element ? null : this.getKey(element as CollectionElement<T>, partialNode, state, parentKey);
let nodeKey = childNode.key ?? null;
if (nodeKey == null) {
nodeKey = childNode.element ? null : this.getKey(element as NonNullable<CollectionElement<T>>, partialNode, state, parentKey);
}

@@ -175,3 +184,3 @@

// Cache the node based on its value
node.value = childNode.value || partialNode.value;
node.value = childNode.value ?? partialNode.value ?? null;
if (node.value) {

@@ -184,3 +193,3 @@ this.cache.set(node.value, node);

if (partialNode.type && node.type !== partialNode.type) {
throw new Error(`Unsupported type <${capitalize(node.type)}> in <${capitalize(parentNode.type)}>. Only <${capitalize(partialNode.type)}> is supported.`);
throw new Error(`Unsupported type <${capitalize(node.type)}> in <${capitalize(parentNode?.type ?? 'unknown parent type')}>. Only <${capitalize(partialNode.type)}> is supported.`);
}

@@ -199,3 +208,3 @@

// Ignore invalid elements
if (partialNode.key == null) {
if (partialNode.key == null || partialNode.type == null) {
return;

@@ -211,13 +220,13 @@ }

parentKey: parentNode ? parentNode.key : null,
value: partialNode.value,
value: partialNode.value ?? null,
level: parentNode ? parentNode.level + 1 : 0,
index: partialNode.index,
rendered: partialNode.rendered,
textValue: partialNode.textValue,
textValue: partialNode.textValue ?? '',
'aria-label': partialNode['aria-label'],
wrapper: partialNode.wrapper,
shouldInvalidate: partialNode.shouldInvalidate,
hasChildNodes: partialNode.hasChildNodes,
hasChildNodes: partialNode.hasChildNodes || false,
childNodes: iterable(function *() {
if (!partialNode.hasChildNodes) {
if (!partialNode.hasChildNodes || !partialNode.childNodes) {
return;

@@ -237,4 +246,3 @@ }

child.index = index;
let nodes = builder.getFullNode(child, builder.getChildState(state, child), node.key, node);
let nodes = builder.getFullNode({...child, index}, builder.getChildState(state, child), node.key, node);
for (let node of nodes) {

@@ -254,4 +262,4 @@ index++;

function iterable<T>(iterator: () => IterableIterator<Node<T>>): Iterable<Node<T>> {
let cache = [];
let iterable = null;
let cache: Array<Node<T>> = [];
let iterable: null | IterableIterator<Node<T>> = null;
return {

@@ -276,3 +284,3 @@ *[Symbol.iterator]() {

type Wrapper = (element: ReactElement) => ReactElement;
function compose(outer: Wrapper | void, inner: Wrapper | void): Wrapper {
function compose(outer: Wrapper | void, inner: Wrapper | void): Wrapper | undefined {
if (outer && inner) {

@@ -279,0 +287,0 @@ return (element) => outer(inner(element));

@@ -45,3 +45,3 @@ /*

export function getLastItem<T>(iterable: Iterable<T>): T | undefined {
let lastItem = undefined;
let lastItem: T | undefined = undefined;
for (let value of iterable) {

@@ -85,7 +85,10 @@ lastItem = value;

function getAncestors<T>(collection: Collection<Node<T>>, node: Node<T>): Node<T>[] {
let parents = [];
let parents: Node<T>[] = [];
while (node?.parentKey != null) {
node = collection.getItem(node.parentKey);
parents.unshift(node);
let currNode: Node<T> | null = node;
while (currNode?.parentKey != null) {
currNode = collection.getItem(currNode.parentKey);
if (currNode) {
parents.unshift(currNode);
}
}

@@ -92,0 +95,0 @@

@@ -24,3 +24,4 @@ /*

count = 0;
// TS isn't smart enough to know we've ensured count is a number, so use a new variable
let counter = 0;
let countItems = (items: Iterable<Node<T>>) => {

@@ -31,3 +32,3 @@ for (let item of items) {

} else {
count++;
counter++;
}

@@ -38,4 +39,4 @@ }

countItems(collection);
cache.set(collection, count);
return count;
cache.set(collection, counter);
return counter;
}

@@ -17,3 +17,3 @@ /*

function Item<T>(props: ItemProps<T>): ReactElement { // eslint-disable-line @typescript-eslint/no-unused-vars
function Item<T>(props: ItemProps<T>): ReactElement | null { // eslint-disable-line @typescript-eslint/no-unused-vars
return null;

@@ -20,0 +20,0 @@ }

@@ -17,3 +17,3 @@ /*

function Section<T>(props: SectionProps<T>): ReactElement { // eslint-disable-line @typescript-eslint/no-unused-vars
function Section<T>(props: SectionProps<T>): ReactElement | null { // eslint-disable-line @typescript-eslint/no-unused-vars
return null;

@@ -20,0 +20,0 @@ }

@@ -18,5 +18,5 @@ /*

type?: string,
key?: Key,
key?: Key | null,
value?: T,
element?: ReactElement,
element?: ReactElement | null,
wrapper?: (element: ReactElement) => ReactElement,

@@ -27,7 +27,7 @@ rendered?: ReactNode,

index?: number,
renderer?: (item: T) => ReactElement,
renderer?: (item: T) => ReactElement | null,
hasChildNodes?: boolean,
childNodes?: () => IterableIterator<PartialNode<T>>,
props?: any,
shouldInvalidate?: (context: unknown) => boolean
shouldInvalidate?: (context: any) => boolean
}

@@ -18,3 +18,3 @@ /*

interface CollectionOptions<T, C extends Collection<Node<T>>> extends Omit<CollectionStateBase<T, C>, 'children'> {
children?: ReactElement<any> | ReactElement<any>[] | ((item: T) => ReactElement<any>)
children?: ReactElement<any> | null | (ReactElement<any> | null)[] | ((item: T) => ReactElement<any> | null)
}

@@ -21,0 +21,0 @@

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

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

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

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

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

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