New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@react-stately/data

Package Overview
Dependencies
Maintainers
2
Versions
898
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@react-stately/data - npm Package Compare versions

Comparing version 3.0.0-nightly-e37ad74f5-241101 to 3.0.0-nightly-e3ed3c7f6-250130

16

dist/types.d.ts

@@ -29,3 +29,3 @@ import { Key, Selection, LoadingState, SortDescriptor } from "@react-types/shared";

*/
getItem(key: Key): T;
getItem(key: Key): T | undefined;
/**

@@ -114,5 +114,7 @@ * Inserts items into the list at the given index.

*/
sort?: AsyncListLoadFunction<T, C>;
sort?: AsyncListLoadFunction<T, C, AsyncListLoadOptions<T, C> & {
sortDescriptor: SortDescriptor;
}>;
}
type AsyncListLoadFunction<T, C> = (state: AsyncListLoadOptions<T, C>) => AsyncListStateUpdate<T, C> | Promise<AsyncListStateUpdate<T, C>>;
type AsyncListLoadFunction<T, C, S extends AsyncListLoadOptions<T, C> = AsyncListLoadOptions<T, C>> = (state: S) => AsyncListStateUpdate<T, C> | Promise<AsyncListStateUpdate<T, C>>;
interface AsyncListLoadOptions<T, C> {

@@ -124,3 +126,3 @@ /** The items currently in the list. */

/** The current sort descriptor for the list. */
sortDescriptor: SortDescriptor;
sortDescriptor?: SortDescriptor;
/** An abort signal used to notify the load function that the request has been aborted. */

@@ -182,7 +184,7 @@ signal: AbortSignal;

/** The key of the parent node. */
parentKey: Key;
parentKey?: Key | null;
/** The value object for the tree node. */
value: T;
/** Children of the tree node. */
children: TreeNode<T>[];
children: TreeNode<T>[] | null;
}

@@ -200,3 +202,3 @@ export interface TreeData<T extends object> {

*/
getItem(key: Key): TreeNode<T>;
getItem(key: Key): TreeNode<T> | undefined;
/**

@@ -203,0 +205,0 @@ * Inserts an item into a parent node as a child.

@@ -43,5 +43,6 @@ var $fbc1d750f520c94e$exports = require("./useListData.main.js");

case 'update':
var _action_updater;
return {
...data,
...action.updater(data)
...(_action_updater = action.updater) === null || _action_updater === void 0 ? void 0 : _action_updater.call(action, data)
};

@@ -65,3 +66,3 @@ case 'success':

selectedKeys = (_action_selectedKeys = action.selectedKeys) !== null && _action_selectedKeys !== void 0 ? _action_selectedKeys : data.selectedKeys;
var _action_filterText1, _action_sortDescriptor1;
var _action_filterText1, _action_items, _action_sortDescriptor1;
return {

@@ -72,7 +73,7 @@ ...data,

items: [
...action.items
...(_action_items = action.items) !== null && _action_items !== void 0 ? _action_items : []
],
selectedKeys: selectedKeys === 'all' ? 'all' : new Set(selectedKeys),
sortDescriptor: (_action_sortDescriptor1 = action.sortDescriptor) !== null && _action_sortDescriptor1 !== void 0 ? _action_sortDescriptor1 : data.sortDescriptor,
abortController: null,
abortController: undefined,
cursor: action.cursor

@@ -86,3 +87,3 @@ };

error: action.error,
abortController: null
abortController: undefined
};

@@ -93,5 +94,6 @@ case 'loading':

case 'filtering':
// We're already loading, and another load was triggered at the same time.
var // We're already loading, and another load was triggered at the same time.
// We need to abort the previous load and start a new one.
data.abortController.abort();
_data_abortController;
(_data_abortController = data.abortController) === null || _data_abortController === void 0 ? void 0 : _data_abortController.abort();
var _action_filterText2;

@@ -107,2 +109,3 @@ return {

case 'update':
var _action_updater1;
// We're already loading, and an update happened at the same time (e.g. selectedKey changed).

@@ -112,3 +115,3 @@ // Update data but don't abort previous load.

...data,
...action.updater(data)
...(_action_updater1 = action.updater) === null || _action_updater1 === void 0 ? void 0 : _action_updater1.call(action, data)
};

@@ -126,3 +129,3 @@ default:

]);
var _action_sortDescriptor2;
var _action_items1, _action_sortDescriptor2;
// Append the new items

@@ -134,7 +137,7 @@ return {

...data.items,
...action.items
...(_action_items1 = action.items) !== null && _action_items1 !== void 0 ? _action_items1 : []
],
selectedKeys: selectedKeys,
sortDescriptor: (_action_sortDescriptor2 = action.sortDescriptor) !== null && _action_sortDescriptor2 !== void 0 ? _action_sortDescriptor2 : data.sortDescriptor,
abortController: null,
abortController: undefined,
cursor: action.cursor

@@ -152,5 +155,6 @@ };

case 'filtering':
// We're already loading more, and another load was triggered at the same time.
var // We're already loading more, and another load was triggered at the same time.
// We need to abort the previous load more and start a new one.
data.abortController.abort();
_data_abortController1;
(_data_abortController1 = data.abortController) === null || _data_abortController1 === void 0 ? void 0 : _data_abortController1.abort();
var _action_filterText3;

@@ -166,8 +170,10 @@ return {

case 'loadingMore':
// If already loading more and another loading more is triggered, abort the new load more since
var // If already loading more and another loading more is triggered, abort the new load more since
// it is a duplicate request since the cursor hasn't been updated.
// Do not overwrite the data.abortController
action.abortController.abort();
_action_abortController;
(_action_abortController = action.abortController) === null || _action_abortController === void 0 ? void 0 : _action_abortController.abort();
return data;
case 'update':
var _action_updater2;
// We're already loading, and an update happened at the same time (e.g. selectedKey changed).

@@ -177,3 +183,3 @@ // Update data but don't abort previous load.

...data,
...action.updater(data)
...(_action_updater2 = action.updater) === null || _action_updater2 === void 0 ? void 0 : _action_updater2.call(action, data)
};

@@ -191,3 +197,3 @@ default:

state: 'idle',
error: null,
error: undefined,
items: [],

@@ -213,3 +219,3 @@ selectedKeys: initialSelectedKeys === 'all' ? 'all' : new Set(initialSelectedKeys),

signal: abortController.signal,
cursor: action.type === 'loadingMore' ? data.cursor : null,
cursor: action.type === 'loadingMore' ? data.cursor : undefined,
filterText: previousFilterText

@@ -216,0 +222,0 @@ });

@@ -37,5 +37,6 @@ import {createListActions as $0d86e9c8f07f9a7b$export$79c0c687a5963b0a} from "./useListData.module.js";

case 'update':
var _action_updater;
return {
...data,
...action.updater(data)
...(_action_updater = action.updater) === null || _action_updater === void 0 ? void 0 : _action_updater.call(action, data)
};

@@ -59,3 +60,3 @@ case 'success':

selectedKeys = (_action_selectedKeys = action.selectedKeys) !== null && _action_selectedKeys !== void 0 ? _action_selectedKeys : data.selectedKeys;
var _action_filterText1, _action_sortDescriptor1;
var _action_filterText1, _action_items, _action_sortDescriptor1;
return {

@@ -66,7 +67,7 @@ ...data,

items: [
...action.items
...(_action_items = action.items) !== null && _action_items !== void 0 ? _action_items : []
],
selectedKeys: selectedKeys === 'all' ? 'all' : new Set(selectedKeys),
sortDescriptor: (_action_sortDescriptor1 = action.sortDescriptor) !== null && _action_sortDescriptor1 !== void 0 ? _action_sortDescriptor1 : data.sortDescriptor,
abortController: null,
abortController: undefined,
cursor: action.cursor

@@ -80,3 +81,3 @@ };

error: action.error,
abortController: null
abortController: undefined
};

@@ -87,5 +88,6 @@ case 'loading':

case 'filtering':
// We're already loading, and another load was triggered at the same time.
var // We're already loading, and another load was triggered at the same time.
// We need to abort the previous load and start a new one.
data.abortController.abort();
_data_abortController;
(_data_abortController = data.abortController) === null || _data_abortController === void 0 ? void 0 : _data_abortController.abort();
var _action_filterText2;

@@ -101,2 +103,3 @@ return {

case 'update':
var _action_updater1;
// We're already loading, and an update happened at the same time (e.g. selectedKey changed).

@@ -106,3 +109,3 @@ // Update data but don't abort previous load.

...data,
...action.updater(data)
...(_action_updater1 = action.updater) === null || _action_updater1 === void 0 ? void 0 : _action_updater1.call(action, data)
};

@@ -120,3 +123,3 @@ default:

]);
var _action_sortDescriptor2;
var _action_items1, _action_sortDescriptor2;
// Append the new items

@@ -128,7 +131,7 @@ return {

...data.items,
...action.items
...(_action_items1 = action.items) !== null && _action_items1 !== void 0 ? _action_items1 : []
],
selectedKeys: selectedKeys,
sortDescriptor: (_action_sortDescriptor2 = action.sortDescriptor) !== null && _action_sortDescriptor2 !== void 0 ? _action_sortDescriptor2 : data.sortDescriptor,
abortController: null,
abortController: undefined,
cursor: action.cursor

@@ -146,5 +149,6 @@ };

case 'filtering':
// We're already loading more, and another load was triggered at the same time.
var // We're already loading more, and another load was triggered at the same time.
// We need to abort the previous load more and start a new one.
data.abortController.abort();
_data_abortController1;
(_data_abortController1 = data.abortController) === null || _data_abortController1 === void 0 ? void 0 : _data_abortController1.abort();
var _action_filterText3;

@@ -160,8 +164,10 @@ return {

case 'loadingMore':
// If already loading more and another loading more is triggered, abort the new load more since
var // If already loading more and another loading more is triggered, abort the new load more since
// it is a duplicate request since the cursor hasn't been updated.
// Do not overwrite the data.abortController
action.abortController.abort();
_action_abortController;
(_action_abortController = action.abortController) === null || _action_abortController === void 0 ? void 0 : _action_abortController.abort();
return data;
case 'update':
var _action_updater2;
// We're already loading, and an update happened at the same time (e.g. selectedKey changed).

@@ -171,3 +177,3 @@ // Update data but don't abort previous load.

...data,
...action.updater(data)
...(_action_updater2 = action.updater) === null || _action_updater2 === void 0 ? void 0 : _action_updater2.call(action, data)
};

@@ -185,3 +191,3 @@ default:

state: 'idle',
error: null,
error: undefined,
items: [],

@@ -207,3 +213,3 @@ selectedKeys: initialSelectedKeys === 'all' ? 'all' : new Set(initialSelectedKeys),

signal: abortController.signal,
cursor: action.type === 'loadingMore' ? data.cursor : null,
cursor: action.type === 'loadingMore' ? data.cursor : undefined,
filterText: previousFilterText

@@ -210,0 +216,0 @@ });

@@ -68,3 +68,3 @@ var $1nAKR$react = require("react");

dispatch((state)=>{
let index = state.items.findIndex((item)=>getKey(item) === key);
let index = state.items.findIndex((item)=>(getKey === null || getKey === void 0 ? void 0 : getKey(item)) === key);
if (index === -1) {

@@ -79,3 +79,3 @@ if (state.items.length === 0) index = 0;

dispatch((state)=>{
let index = state.items.findIndex((item)=>getKey(item) === key);
let index = state.items.findIndex((item)=>(getKey === null || getKey === void 0 ? void 0 : getKey(item)) === key);
if (index === -1) {

@@ -82,0 +82,0 @@ if (state.items.length === 0) index = 0;

@@ -61,3 +61,3 @@ import {useState as $bc4N1$useState, useMemo as $bc4N1$useMemo} from "react";

dispatch((state)=>{
let index = state.items.findIndex((item)=>getKey(item) === key);
let index = state.items.findIndex((item)=>(getKey === null || getKey === void 0 ? void 0 : getKey(item)) === key);
if (index === -1) {

@@ -72,3 +72,3 @@ if (state.items.length === 0) index = 0;

dispatch((state)=>{
let index = state.items.findIndex((item)=>getKey(item) === key);
let index = state.items.findIndex((item)=>(getKey === null || getKey === void 0 ? void 0 : getKey(item)) === key);
if (index === -1) {

@@ -75,0 +75,0 @@ if (state.items.length === 0) index = 0;

@@ -58,3 +58,3 @@ var $aMaLn$react = require("react");

// Walk up the tree and update each parent to refer to the new children.
while(node.parentKey){
while(node && node.parentKey){
let nextParent = map.get(node.parentKey);

@@ -68,7 +68,9 @@ let copy = {

let children = nextParent.children;
if (newNode == null) children = children.filter((c)=>c !== node);
copy.children = children.map((child)=>{
if (child === node) return newNode;
if (newNode == null && children) children = children.filter((c)=>c !== node);
var _children_map;
copy.children = (_children_map = children === null || children === void 0 ? void 0 : children.map((child)=>{
if (child === node) // newNode cannot be null here due to the above filter.
return newNode;
return child;
});
})) !== null && _children_map !== void 0 ? _children_map : null;
map.set(copy.key, copy);

@@ -81,3 +83,4 @@ newNode = copy;

items: items.map((item)=>{
if (item === node) return newNode;
if (item === node) // newNode cannot be null here due to the above filter.
return newNode;
return item;

@@ -90,7 +93,7 @@ }),

map.set(node.key, node);
for (let child of node.children)addNode(child, map);
if (node.children) for (let child of node.children)addNode(child, map);
}
function deleteNode(node, map) {
map.delete(node.key);
for (let child of node.children)deleteNode(child, map);
if (node.children) for (let child of node.children)deleteNode(child, map);
}

@@ -135,3 +138,4 @@ return {

let index = nodes.indexOf(node);
this.insert(parentNode === null || parentNode === void 0 ? void 0 : parentNode.key, index, ...values);
var _parentNode_key;
this.insert((_parentNode_key = parentNode === null || parentNode === void 0 ? void 0 : parentNode.key) !== null && _parentNode_key !== void 0 ? _parentNode_key : null, index, ...values);
},

@@ -144,3 +148,4 @@ insertAfter (key, ...values) {

let index = nodes.indexOf(node);
this.insert(parentNode === null || parentNode === void 0 ? void 0 : parentNode.key, index + 1, ...values);
var _parentNode_key;
this.insert((_parentNode_key = parentNode === null || parentNode === void 0 ? void 0 : parentNode.key) !== null && _parentNode_key !== void 0 ? _parentNode_key : null, index + 1, ...values);
},

@@ -147,0 +152,0 @@ prepend (parentKey, ...values) {

@@ -52,3 +52,3 @@ import {useState as $3pPTd$useState} from "react";

// Walk up the tree and update each parent to refer to the new children.
while(node.parentKey){
while(node && node.parentKey){
let nextParent = map.get(node.parentKey);

@@ -62,7 +62,9 @@ let copy = {

let children = nextParent.children;
if (newNode == null) children = children.filter((c)=>c !== node);
copy.children = children.map((child)=>{
if (child === node) return newNode;
if (newNode == null && children) children = children.filter((c)=>c !== node);
var _children_map;
copy.children = (_children_map = children === null || children === void 0 ? void 0 : children.map((child)=>{
if (child === node) // newNode cannot be null here due to the above filter.
return newNode;
return child;
});
})) !== null && _children_map !== void 0 ? _children_map : null;
map.set(copy.key, copy);

@@ -75,3 +77,4 @@ newNode = copy;

items: items.map((item)=>{
if (item === node) return newNode;
if (item === node) // newNode cannot be null here due to the above filter.
return newNode;
return item;

@@ -84,7 +87,7 @@ }),

map.set(node.key, node);
for (let child of node.children)addNode(child, map);
if (node.children) for (let child of node.children)addNode(child, map);
}
function deleteNode(node, map) {
map.delete(node.key);
for (let child of node.children)deleteNode(child, map);
if (node.children) for (let child of node.children)deleteNode(child, map);
}

@@ -129,3 +132,4 @@ return {

let index = nodes.indexOf(node);
this.insert(parentNode === null || parentNode === void 0 ? void 0 : parentNode.key, index, ...values);
var _parentNode_key;
this.insert((_parentNode_key = parentNode === null || parentNode === void 0 ? void 0 : parentNode.key) !== null && _parentNode_key !== void 0 ? _parentNode_key : null, index, ...values);
},

@@ -138,3 +142,4 @@ insertAfter (key, ...values) {

let index = nodes.indexOf(node);
this.insert(parentNode === null || parentNode === void 0 ? void 0 : parentNode.key, index + 1, ...values);
var _parentNode_key;
this.insert((_parentNode_key = parentNode === null || parentNode === void 0 ? void 0 : parentNode.key) !== null && _parentNode_key !== void 0 ? _parentNode_key : null, index + 1, ...values);
},

@@ -141,0 +146,0 @@ prepend (parentKey, ...values) {

{
"name": "@react-stately/data",
"version": "3.0.0-nightly-e37ad74f5-241101",
"version": "3.0.0-nightly-e3ed3c7f6-250130",
"description": "Spectrum UI components in React",

@@ -25,12 +25,11 @@ "license": "Apache-2.0",

"dependencies": {
"@react-types/shared": "^3.0.0-nightly-e37ad74f5-241101",
"@react-types/shared": "3.0.0-nightly-e3ed3c7f6-250130",
"@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"
},
"publishConfig": {
"access": "public"
},
"stableVersion": "3.11.7"
}
}

@@ -32,6 +32,6 @@ /*

*/
sort?: AsyncListLoadFunction<T, C>
sort?: AsyncListLoadFunction<T, C, AsyncListLoadOptions<T, C> & {sortDescriptor: SortDescriptor}>
}
type AsyncListLoadFunction<T, C> = (state: AsyncListLoadOptions<T, C>) => AsyncListStateUpdate<T, C> | Promise<AsyncListStateUpdate<T, C>>;
type AsyncListLoadFunction<T, C, S extends AsyncListLoadOptions<T, C> = AsyncListLoadOptions<T, C>> = (state: S) => AsyncListStateUpdate<T, C> | Promise<AsyncListStateUpdate<T, C>>;

@@ -44,3 +44,3 @@ interface AsyncListLoadOptions<T, C> {

/** The current sort descriptor for the list. */
sortDescriptor: SortDescriptor,
sortDescriptor?: SortDescriptor,
/** An abort signal used to notify the load function that the request has been aborted. */

@@ -138,3 +138,3 @@ signal: AbortSignal,

...data,
...action.updater(data)
...action.updater?.(data)
};

@@ -164,6 +164,6 @@ case 'success':

state: 'idle',
items: [...action.items],
items: [...(action.items) ?? []],
selectedKeys: selectedKeys === 'all' ? 'all' : new Set(selectedKeys),
sortDescriptor: action.sortDescriptor ?? data.sortDescriptor,
abortController: null,
abortController: undefined,
cursor: action.cursor

@@ -180,3 +180,3 @@ };

error: action.error,
abortController: null
abortController: undefined
};

@@ -189,3 +189,3 @@ case 'loading':

// We need to abort the previous load and start a new one.
data.abortController.abort();
data.abortController?.abort();
return {

@@ -204,3 +204,3 @@ ...data,

...data,
...action.updater(data)
...action.updater?.(data)
};

@@ -220,6 +220,6 @@ default:

state: 'idle',
items: [...data.items, ...action.items],
items: [...data.items, ...(action.items ?? [])],
selectedKeys,
sortDescriptor: action.sortDescriptor ?? data.sortDescriptor,
abortController: null,
abortController: undefined,
cursor: action.cursor

@@ -242,3 +242,3 @@ };

// We need to abort the previous load more and start a new one.
data.abortController.abort();
data.abortController?.abort();
return {

@@ -256,3 +256,3 @@ ...data,

// Do not overwrite the data.abortController
action.abortController.abort();
action.abortController?.abort();

@@ -265,3 +265,3 @@ return data;

...data,
...action.updater(data)
...action.updater?.(data)
};

@@ -292,3 +292,3 @@ default:

state: 'idle',
error: null,
error: undefined,
items: [],

@@ -311,3 +311,3 @@ selectedKeys: initialSelectedKeys === 'all' ? 'all' : new Set(initialSelectedKeys),

signal: abortController.signal,
cursor: action.type === 'loadingMore' ? data.cursor : null,
cursor: action.type === 'loadingMore' ? data.cursor : undefined,
filterText: previousFilterText

@@ -325,3 +325,3 @@ });

} catch (e) {
dispatch({type: 'error', error: e, abortController});
dispatch({type: 'error', error: e as Error, abortController});
}

@@ -362,3 +362,3 @@ };

sort(sortDescriptor: SortDescriptor) {
dispatchFetch({type: 'sorting', sortDescriptor}, sort || load);
dispatchFetch({type: 'sorting', sortDescriptor}, (sort || load) as AsyncListLoadFunction<T, C>);
},

@@ -365,0 +365,0 @@ ...createListActions({...options, getKey, cursor: data.cursor}, fn => {

@@ -49,3 +49,3 @@ /*

*/
getItem(key: Key): T,
getItem(key: Key): T | undefined,

@@ -190,3 +190,3 @@ /**

dispatch(state => {
let index = state.items.findIndex(item => getKey(item) === key);
let index = state.items.findIndex(item => getKey?.(item) === key);
if (index === -1) {

@@ -205,3 +205,3 @@ if (state.items.length === 0) {

dispatch(state => {
let index = state.items.findIndex(item => getKey(item) === key);
let index = state.items.findIndex(item => getKey?.(item) === key);
if (index === -1) {

@@ -227,3 +227,3 @@ if (state.items.length === 0) {

let keySet = new Set(keys);
let items = state.items.filter(item => !keySet.has(getKey(item)));
let items = state.items.filter(item => !keySet.has(getKey!(item)));

@@ -259,3 +259,3 @@ let selection: Selection = 'all';

let selectedKeys = state.selectedKeys;
let items = state.items.filter(item => !selectedKeys.has(getKey(item)));
let items = state.items.filter(item => !selectedKeys.has(getKey!(item)));
return {

@@ -270,3 +270,3 @@ ...state,

dispatch(state => {
let index = state.items.findIndex(item => getKey(item) === key);
let index = state.items.findIndex(item => getKey!(item) === key);
if (index === -1) {

@@ -287,3 +287,3 @@ return state;

dispatch(state => {
let toIndex = state.items.findIndex(item => getKey(item) === key);
let toIndex = state.items.findIndex(item => getKey!(item) === key);
if (toIndex === -1) {

@@ -295,3 +295,3 @@ return state;

let keyArray = Array.isArray(keys) ? keys : [...keys];
let indices = keyArray.map(key => state.items.findIndex(item => getKey(item) === key)).sort((a, b) => a - b);
let indices = keyArray.map(key => state.items.findIndex(item => getKey!(item) === key)).sort((a, b) => a - b);
return move(state, indices, toIndex);

@@ -302,3 +302,3 @@ });

dispatch(state => {
let toIndex = state.items.findIndex(item => getKey(item) === key);
let toIndex = state.items.findIndex(item => getKey!(item) === key);
if (toIndex === -1) {

@@ -309,3 +309,3 @@ return state;

let keyArray = Array.isArray(keys) ? keys : [...keys];
let indices = keyArray.map(key => state.items.findIndex(item => getKey(item) === key)).sort((a, b) => a - b);
let indices = keyArray.map(key => state.items.findIndex(item => getKey!(item) === key)).sort((a, b) => a - b);
return move(state, indices, toIndex + 1);

@@ -316,3 +316,3 @@ });

dispatch(state => {
let index = state.items.findIndex(item => getKey(item) === key);
let index = state.items.findIndex(item => getKey!(item) === key);
if (index === -1) {

@@ -319,0 +319,0 @@ return state;

@@ -31,7 +31,7 @@ /*

/** The key of the parent node. */
parentKey: Key,
parentKey?: Key | null,
/** The value object for the tree node. */
value: T,
/** Children of the tree node. */
children: TreeNode<T>[]
children: TreeNode<T>[] | null
}

@@ -53,3 +53,3 @@

*/
getItem(key: Key): TreeNode<T>,
getItem(key: Key): TreeNode<T> | undefined,

@@ -159,3 +159,3 @@ /**

function updateTree(items: TreeNode<T>[], key: Key, update: (node: TreeNode<T>) => TreeNode<T>, originalMap: Map<Key, TreeNode<T>>) {
function updateTree(items: TreeNode<T>[], key: Key, update: (node: TreeNode<T>) => TreeNode<T> | null, originalMap: Map<Key, TreeNode<T>>) {
let node = originalMap.get(key);

@@ -176,4 +176,4 @@ if (!node) {

// Walk up the tree and update each parent to refer to the new children.
while (node.parentKey) {
let nextParent = map.get(node.parentKey);
while (node && node.parentKey) {
let nextParent = map.get(node.parentKey)!;
let copy: TreeNode<T> = {

@@ -187,13 +187,14 @@ key: nextParent.key,

let children = nextParent.children;
if (newNode == null) {
if (newNode == null && children) {
children = children.filter(c => c !== node);
}
copy.children = children.map(child => {
copy.children = children?.map(child => {
if (child === node) {
return newNode;
// newNode cannot be null here due to the above filter.
return newNode!;
}
return child;
});
}) ?? null;

@@ -213,3 +214,4 @@ map.set(copy.key, copy);

if (item === node) {
return newNode;
// newNode cannot be null here due to the above filter.
return newNode!;
}

@@ -225,4 +227,6 @@

map.set(node.key, node);
for (let child of node.children) {
addNode(child, map);
if (node.children) {
for (let child of node.children) {
addNode(child, map);
}
}

@@ -233,4 +237,6 @@ }

map.delete(node.key);
for (let child of node.children) {
deleteNode(child, map);
if (node.children) {
for (let child of node.children) {
deleteNode(child, map);
}
}

@@ -268,5 +274,5 @@ }

children: [
...parentNode.children.slice(0, index),
...parentNode.children!.slice(0, index),
...newNodes,
...parentNode.children.slice(index)
...parentNode.children!.slice(index)
]

@@ -282,6 +288,6 @@ }), newMap);

let parentNode = nodeMap.get(node.parentKey);
let parentNode = nodeMap.get(node.parentKey!);
let nodes = parentNode ? parentNode.children : items;
let index = nodes.indexOf(node);
this.insert(parentNode?.key, index, ...values);
let index = nodes!.indexOf(node);
this.insert(parentNode?.key ?? null, index, ...values);
},

@@ -294,6 +300,6 @@ insertAfter(key: Key, ...values: T[]): void {

let parentNode = nodeMap.get(node.parentKey);
let parentNode = nodeMap.get(node.parentKey!);
let nodes = parentNode ? parentNode.children : items;
let index = nodes.indexOf(node);
this.insert(parentNode?.key, index + 1, ...values);
let index = nodes!.indexOf(node);
this.insert(parentNode?.key ?? null, index + 1, ...values);
},

@@ -312,3 +318,3 @@ prepend(parentKey: Key | null, ...values: T[]) {

this.insert(parentKey, parentNode.children.length, ...values);
this.insert(parentKey, parentNode.children!.length, ...values);
}

@@ -375,5 +381,5 @@ },

children: [
...parentNode.children.slice(0, index),
...parentNode.children!.slice(0, index),
movedNode,
...parentNode.children.slice(index)
...parentNode.children!.slice(index)
]

@@ -380,0 +386,0 @@ }), newMap);

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