(key: Key, toParentKey: Key | null, index: number)
| 376 | this.remove(...selectedKeys); |
| 377 | }, |
| 378 | move(key: Key, toParentKey: Key | null, index: number) { |
| 379 | setItems(({items, nodeMap: originalMap}) => { |
| 380 | let node = originalMap.get(key); |
| 381 | if (!node) { |
| 382 | return {items, nodeMap: originalMap}; |
| 383 | } |
| 384 | |
| 385 | let {items: newItems, nodeMap: newMap} = updateTree(items, key, () => null, originalMap); |
| 386 | |
| 387 | const movedNode = { |
| 388 | ...node, |
| 389 | parentKey: toParentKey |
| 390 | }; |
| 391 | |
| 392 | // If parentKey is null, insert into the root. |
| 393 | if (toParentKey == null) { |
| 394 | addNode(movedNode, newMap); |
| 395 | return { |
| 396 | items: [...newItems.slice(0, index), movedNode, ...newItems.slice(index)], |
| 397 | nodeMap: newMap |
| 398 | }; |
| 399 | } |
| 400 | |
| 401 | // Otherwise, update the parent node and its ancestors. |
| 402 | return updateTree( |
| 403 | newItems, |
| 404 | toParentKey, |
| 405 | parentNode => ({ |
| 406 | key: parentNode.key, |
| 407 | parentKey: parentNode.parentKey, |
| 408 | value: parentNode.value, |
| 409 | children: [ |
| 410 | ...parentNode.children!.slice(0, index), |
| 411 | movedNode, |
| 412 | ...parentNode.children!.slice(index) |
| 413 | ] |
| 414 | }), |
| 415 | newMap |
| 416 | ); |
| 417 | }); |
| 418 | }, |
| 419 | moveBefore(key: Key, keys: Iterable<Key>) { |
| 420 | setItems(prevState => { |
| 421 | let {items, nodeMap} = prevState; |
nothing calls this directly
no test coverage detected