@react-stately/grid
Advanced tools
Comparing version 3.0.0-nightly-e60fb427c-240930 to 3.0.0-nightly-e94e36431-241203
@@ -33,7 +33,9 @@ | ||
let node = this.keyMap.get(key); | ||
return node ? node.prevKey : null; | ||
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); | ||
return node ? node.nextKey : null; | ||
var _node_nextKey; | ||
return node ? (_node_nextKey = node.nextKey) !== null && _node_nextKey !== void 0 ? _node_nextKey : null : null; | ||
} | ||
@@ -54,3 +56,4 @@ getFirstKey() { | ||
getItem(key) { | ||
return this.keyMap.get(key); | ||
var _this_keyMap_get; | ||
return (_this_keyMap_get = this.keyMap.get(key)) !== null && _this_keyMap_get !== void 0 ? _this_keyMap_get : null; | ||
} | ||
@@ -80,3 +83,3 @@ at(idx) { | ||
let childKeys = new Set(); | ||
let last; | ||
let last = null; | ||
for (let child of node.childNodes){ | ||
@@ -103,9 +106,11 @@ 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 | ||
}; | ||
let last; | ||
opts.items.forEach((node, i)=>{ | ||
let last = null; | ||
for (let [i, node] of opts.items.entries()){ | ||
var _node_level, _node_key, _node_type, _node_value, _node_textValue, _node_index; | ||
let rowNode = { | ||
level: 0, | ||
key: 'row-' + i, | ||
type: 'row', | ||
value: undefined, | ||
...node, | ||
level: (_node_level = node.level) !== null && _node_level !== void 0 ? _node_level : 0, | ||
key: (_node_key = node.key) !== null && _node_key !== void 0 ? _node_key : 'row-' + i, | ||
type: (_node_type = node.type) !== null && _node_type !== void 0 ? _node_type : 'row', | ||
value: (_node_value = node.value) !== null && _node_value !== void 0 ? _node_value : null, | ||
hasChildNodes: true, | ||
@@ -115,5 +120,5 @@ childNodes: [ | ||
], | ||
rendered: undefined, | ||
textValue: undefined, | ||
...node | ||
rendered: node.rendered, | ||
textValue: (_node_textValue = node.textValue) !== null && _node_textValue !== void 0 ? _node_textValue : '', | ||
index: (_node_index = node.index) !== null && _node_index !== void 0 ? _node_index : i | ||
}; | ||
@@ -127,3 +132,3 @@ if (last) { | ||
last = rowNode; | ||
}); | ||
} | ||
if (last) last.nextKey = null; | ||
@@ -130,0 +135,0 @@ } |
@@ -27,7 +27,9 @@ /* | ||
let node = this.keyMap.get(key); | ||
return node ? node.prevKey : null; | ||
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); | ||
return node ? node.nextKey : null; | ||
var _node_nextKey; | ||
return node ? (_node_nextKey = node.nextKey) !== null && _node_nextKey !== void 0 ? _node_nextKey : null : null; | ||
} | ||
@@ -48,3 +50,4 @@ getFirstKey() { | ||
getItem(key) { | ||
return this.keyMap.get(key); | ||
var _this_keyMap_get; | ||
return (_this_keyMap_get = this.keyMap.get(key)) !== null && _this_keyMap_get !== void 0 ? _this_keyMap_get : null; | ||
} | ||
@@ -74,3 +77,3 @@ at(idx) { | ||
let childKeys = new Set(); | ||
let last; | ||
let last = null; | ||
for (let child of node.childNodes){ | ||
@@ -97,9 +100,11 @@ 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 | ||
}; | ||
let last; | ||
opts.items.forEach((node, i)=>{ | ||
let last = null; | ||
for (let [i, node] of opts.items.entries()){ | ||
var _node_level, _node_key, _node_type, _node_value, _node_textValue, _node_index; | ||
let rowNode = { | ||
level: 0, | ||
key: 'row-' + i, | ||
type: 'row', | ||
value: undefined, | ||
...node, | ||
level: (_node_level = node.level) !== null && _node_level !== void 0 ? _node_level : 0, | ||
key: (_node_key = node.key) !== null && _node_key !== void 0 ? _node_key : 'row-' + i, | ||
type: (_node_type = node.type) !== null && _node_type !== void 0 ? _node_type : 'row', | ||
value: (_node_value = node.value) !== null && _node_value !== void 0 ? _node_value : null, | ||
hasChildNodes: true, | ||
@@ -109,5 +114,5 @@ childNodes: [ | ||
], | ||
rendered: undefined, | ||
textValue: undefined, | ||
...node | ||
rendered: node.rendered, | ||
textValue: (_node_textValue = node.textValue) !== null && _node_textValue !== void 0 ? _node_textValue : '', | ||
index: (_node_index = node.index) !== null && _node_index !== void 0 ? _node_index : i | ||
}; | ||
@@ -121,3 +126,3 @@ if (last) { | ||
last = rowNode; | ||
}); | ||
} | ||
if (last) last.nextKey = null; | ||
@@ -124,0 +129,0 @@ } |
@@ -33,12 +33,12 @@ import { GridCollection as _GridCollection1, GridNode, GridRow } from "@react-types/grid"; | ||
rows: GridNode<T>[]; | ||
constructor(opts?: GridCollectionOptions<T>); | ||
constructor(opts: GridCollectionOptions<T>); | ||
[Symbol.iterator](): Generator<GridNode<T>, void, undefined>; | ||
get size(): number; | ||
getKeys(): IterableIterator<Key>; | ||
getKeyBefore(key: Key): Key; | ||
getKeyAfter(key: Key): Key; | ||
getFirstKey(): Key; | ||
getLastKey(): Key; | ||
getItem(key: Key): GridNode<T>; | ||
at(idx: number): GridNode<T>; | ||
getKeyBefore(key: Key): Key | null; | ||
getKeyAfter(key: Key): Key | null; | ||
getFirstKey(): Key | null; | ||
getLastKey(): Key | null; | ||
getItem(key: Key): GridNode<T> | null; | ||
at(idx: number): GridNode<T> | null; | ||
getChildren(key: Key): Iterable<GridNode<T>>; | ||
@@ -45,0 +45,0 @@ } |
@@ -29,4 +29,5 @@ var $5Cus8$reactstatelycollections = require("@react-stately/collections"); | ||
let children = (0, $5Cus8$reactstatelycollections.getChildNodes)(item, collection); | ||
if (child === 'last') key = (_getLastItem = (0, $5Cus8$reactstatelycollections.getLastItem)(children)) === null || _getLastItem === void 0 ? void 0 : _getLastItem.key; | ||
else key = (_getFirstItem = (0, $5Cus8$reactstatelycollections.getFirstItem)(children)) === null || _getFirstItem === void 0 ? void 0 : _getFirstItem.key; | ||
var _getLastItem_key, _getFirstItem_key; | ||
if (child === 'last') key = (_getLastItem_key = (_getLastItem = (0, $5Cus8$reactstatelycollections.getLastItem)(children)) === null || _getLastItem === void 0 ? void 0 : _getLastItem.key) !== null && _getLastItem_key !== void 0 ? _getLastItem_key : null; | ||
else key = (_getFirstItem_key = (_getFirstItem = (0, $5Cus8$reactstatelycollections.getFirstItem)(children)) === null || _getFirstItem === void 0 ? void 0 : _getFirstItem.key) !== null && _getFirstItem_key !== void 0 ? _getFirstItem_key : null; | ||
} | ||
@@ -43,5 +44,9 @@ } | ||
(0, $5Cus8$react.useEffect)(()=>{ | ||
if (selectionState.focusedKey != null && !collection.getItem(selectionState.focusedKey)) { | ||
if (selectionState.focusedKey != null && cachedCollection.current && !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 parentNode = (node === null || node === void 0 ? void 0 : node.parentKey) != null && (node.type === 'cell' || node.type === 'rowheader' || node.type === 'column') ? cachedCollection.current.getItem(node.parentKey) : node; | ||
if (!parentNode) { | ||
selectionState.setFocusedKey(null); | ||
return; | ||
} | ||
const cachedRows = cachedCollection.current.rows; | ||
@@ -51,3 +56,3 @@ const rows = collection.rows; | ||
let index = Math.min(diff > 1 ? Math.max(parentNode.index - diff + 1, 0) : parentNode.index, rows.length - 1); | ||
let newRow; | ||
let newRow = null; | ||
while(index >= 0){ | ||
@@ -69,3 +74,3 @@ if (!selectionManager.isDisabled(rows[index].key) && rows[index].type !== 'headerrow') { | ||
] : []; | ||
const keyToFocus = newRow.hasChildNodes && parentNode !== node && node.index < childNodes.length ? childNodes[node.index].key : newRow.key; | ||
const keyToFocus = newRow.hasChildNodes && parentNode !== node && node && node.index < childNodes.length ? childNodes[node.index].key : newRow.key; | ||
selectionState.setFocusedKey(keyToFocus); | ||
@@ -72,0 +77,0 @@ } else selectionState.setFocusedKey(null); |
@@ -23,4 +23,5 @@ import {getChildNodes as $7nPCv$getChildNodes, getLastItem as $7nPCv$getLastItem, getFirstItem as $7nPCv$getFirstItem} from "@react-stately/collections"; | ||
let children = (0, $7nPCv$getChildNodes)(item, collection); | ||
if (child === 'last') key = (_getLastItem = (0, $7nPCv$getLastItem)(children)) === null || _getLastItem === void 0 ? void 0 : _getLastItem.key; | ||
else key = (_getFirstItem = (0, $7nPCv$getFirstItem)(children)) === null || _getFirstItem === void 0 ? void 0 : _getFirstItem.key; | ||
var _getLastItem_key, _getFirstItem_key; | ||
if (child === 'last') key = (_getLastItem_key = (_getLastItem = (0, $7nPCv$getLastItem)(children)) === null || _getLastItem === void 0 ? void 0 : _getLastItem.key) !== null && _getLastItem_key !== void 0 ? _getLastItem_key : null; | ||
else key = (_getFirstItem_key = (_getFirstItem = (0, $7nPCv$getFirstItem)(children)) === null || _getFirstItem === void 0 ? void 0 : _getFirstItem.key) !== null && _getFirstItem_key !== void 0 ? _getFirstItem_key : null; | ||
} | ||
@@ -37,5 +38,9 @@ } | ||
(0, $7nPCv$useEffect)(()=>{ | ||
if (selectionState.focusedKey != null && !collection.getItem(selectionState.focusedKey)) { | ||
if (selectionState.focusedKey != null && cachedCollection.current && !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 parentNode = (node === null || node === void 0 ? void 0 : node.parentKey) != null && (node.type === 'cell' || node.type === 'rowheader' || node.type === 'column') ? cachedCollection.current.getItem(node.parentKey) : node; | ||
if (!parentNode) { | ||
selectionState.setFocusedKey(null); | ||
return; | ||
} | ||
const cachedRows = cachedCollection.current.rows; | ||
@@ -45,3 +50,3 @@ const rows = collection.rows; | ||
let index = Math.min(diff > 1 ? Math.max(parentNode.index - diff + 1, 0) : parentNode.index, rows.length - 1); | ||
let newRow; | ||
let newRow = null; | ||
while(index >= 0){ | ||
@@ -63,3 +68,3 @@ if (!selectionManager.isDisabled(rows[index].key) && rows[index].type !== 'headerrow') { | ||
] : []; | ||
const keyToFocus = newRow.hasChildNodes && parentNode !== node && node.index < childNodes.length ? childNodes[node.index].key : newRow.key; | ||
const keyToFocus = newRow.hasChildNodes && parentNode !== node && node && node.index < childNodes.length ? childNodes[node.index].key : newRow.key; | ||
selectionState.setFocusedKey(keyToFocus); | ||
@@ -66,0 +71,0 @@ } else selectionState.setFocusedKey(null); |
{ | ||
"name": "@react-stately/grid", | ||
"version": "3.0.0-nightly-e60fb427c-240930", | ||
"version": "3.0.0-nightly-e94e36431-241203", | ||
"description": "Spectrum UI components in React", | ||
@@ -25,10 +25,10 @@ "license": "Apache-2.0", | ||
"dependencies": { | ||
"@react-stately/collections": "^3.0.0-nightly-e60fb427c-240930", | ||
"@react-stately/selection": "^3.0.0-nightly-e60fb427c-240930", | ||
"@react-types/grid": "^3.0.0-nightly-e60fb427c-240930", | ||
"@react-types/shared": "^3.0.0-nightly-e60fb427c-240930", | ||
"@react-stately/collections": "^3.0.0-nightly-e94e36431-241203", | ||
"@react-stately/selection": "^3.0.0-nightly-e94e36431-241203", | ||
"@react-types/grid": "^3.0.0-nightly-e94e36431-241203", | ||
"@react-types/shared": "^3.0.0-nightly-e94e36431-241203", | ||
"@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" | ||
}, | ||
@@ -38,3 +38,3 @@ "publishConfig": { | ||
}, | ||
"stableVersion": "3.9.2" | ||
"stableVersion": "3.10.0" | ||
} |
@@ -27,3 +27,3 @@ /* | ||
constructor(opts?: GridCollectionOptions<T>) { | ||
constructor(opts: GridCollectionOptions<T>) { | ||
this.keyMap = new Map(); | ||
@@ -45,3 +45,3 @@ this.columnCount = opts?.columnCount; | ||
let childKeys = new Set(); | ||
let last: GridNode<T>; | ||
let last: GridNode<T> | null = null; | ||
for (let child of node.childNodes) { | ||
@@ -88,15 +88,16 @@ if (child.type === 'cell' && child.parentKey == null) { | ||
let last: GridNode<T>; | ||
opts.items.forEach((node, i) => { | ||
let rowNode = { | ||
level: 0, | ||
key: 'row-' + i, | ||
type: 'row', | ||
value: undefined, | ||
let last: GridNode<T> | null = null; | ||
for (let [i, node] of opts.items.entries()) { | ||
let rowNode: GridNode<T> = { | ||
...node, | ||
level: node.level ?? 0, | ||
key: node.key ?? 'row-' + i, | ||
type: node.type ?? 'row', | ||
value: node.value ?? null, | ||
hasChildNodes: true, | ||
childNodes: [...node.childNodes], | ||
rendered: undefined, | ||
textValue: undefined, | ||
...node | ||
} as GridNode<T>; | ||
rendered: node.rendered, | ||
textValue: node.textValue ?? '', | ||
index: node.index ?? i | ||
}; | ||
@@ -114,3 +115,3 @@ if (last) { | ||
last = rowNode; | ||
}); | ||
} | ||
@@ -136,3 +137,3 @@ if (last) { | ||
let node = this.keyMap.get(key); | ||
return node ? node.prevKey : null; | ||
return node ? node.prevKey ?? null : null; | ||
} | ||
@@ -142,10 +143,10 @@ | ||
let node = this.keyMap.get(key); | ||
return node ? node.nextKey : null; | ||
return node ? node.nextKey ?? null : null; | ||
} | ||
getFirstKey() { | ||
getFirstKey(): Key | null { | ||
return [...this.rows][0]?.key; | ||
} | ||
getLastKey() { | ||
getLastKey(): Key | null { | ||
let rows = [...this.rows]; | ||
@@ -156,3 +157,3 @@ return rows[rows.length - 1]?.key; | ||
getItem(key: Key) { | ||
return this.keyMap.get(key); | ||
return this.keyMap.get(key) ?? null; | ||
} | ||
@@ -159,0 +160,0 @@ |
@@ -44,5 +44,5 @@ import {getChildNodes, getFirstItem, getLastItem} from '@react-stately/collections'; | ||
if (child === 'last') { | ||
key = getLastItem(children)?.key; | ||
key = getLastItem(children)?.key ?? null; | ||
} else { | ||
key = getFirstItem(children)?.key; | ||
key = getFirstItem(children)?.key ?? null; | ||
} | ||
@@ -61,10 +61,14 @@ } | ||
// Reset focused key if that item is deleted from the collection. | ||
const cachedCollection = useRef(null); | ||
const cachedCollection = useRef<C | null>(null); | ||
useEffect(() => { | ||
if (selectionState.focusedKey != null && !collection.getItem(selectionState.focusedKey)) { | ||
if (selectionState.focusedKey != null && cachedCollection.current && !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') ? | ||
node?.parentKey != null && (node.type === 'cell' || node.type === 'rowheader' || node.type === 'column') ? | ||
cachedCollection.current.getItem(node.parentKey) : | ||
node; | ||
if (!parentNode) { | ||
selectionState.setFocusedKey(null); | ||
return; | ||
} | ||
const cachedRows = cachedCollection.current.rows; | ||
@@ -80,3 +84,3 @@ const rows = collection.rows; | ||
rows.length - 1); | ||
let newRow:GridNode<T>; | ||
let newRow: GridNode<T> | null = null; | ||
while (index >= 0) { | ||
@@ -103,2 +107,3 @@ if (!selectionManager.isDisabled(rows[index].key) && rows[index].type !== 'headerrow') { | ||
parentNode !== node && | ||
node && | ||
node.index < childNodes.length ? | ||
@@ -105,0 +110,0 @@ childNodes[node.index].key : |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
79436
982