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