@headless-tree/core 0.0.0-20250322153940 → 0.0.0-20250330164609
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -1
- package/lib/cjs/features/drag-and-drop/feature.js +11 -11
- package/lib/cjs/features/drag-and-drop/types.d.ts +11 -11
- package/lib/cjs/features/drag-and-drop/types.js +7 -7
- package/lib/cjs/features/drag-and-drop/utils.d.ts +18 -3
- package/lib/cjs/features/drag-and-drop/utils.js +42 -30
- package/lib/cjs/features/hotkeys-core/feature.js +1 -0
- package/lib/cjs/features/keyboard-drag-and-drop/feature.d.ts +2 -0
- package/lib/cjs/features/keyboard-drag-and-drop/feature.js +207 -0
- package/lib/cjs/features/keyboard-drag-and-drop/types.d.ts +27 -0
- package/lib/cjs/features/keyboard-drag-and-drop/types.js +11 -0
- package/lib/cjs/index.d.ts +2 -0
- package/lib/cjs/index.js +2 -0
- package/lib/cjs/mddocs-entry.d.ts +10 -0
- package/lib/cjs/test-utils/test-tree-expect.d.ts +5 -3
- package/lib/cjs/test-utils/test-tree-expect.js +3 -0
- package/lib/cjs/types/core.d.ts +2 -1
- package/lib/cjs/utilities/create-on-drop-handler.d.ts +2 -2
- package/lib/cjs/utilities/insert-items-at-target.d.ts +2 -2
- package/lib/esm/features/drag-and-drop/feature.js +12 -12
- package/lib/esm/features/drag-and-drop/types.d.ts +11 -11
- package/lib/esm/features/drag-and-drop/types.js +6 -6
- package/lib/esm/features/drag-and-drop/utils.d.ts +18 -3
- package/lib/esm/features/drag-and-drop/utils.js +37 -28
- package/lib/esm/features/hotkeys-core/feature.js +1 -0
- package/lib/esm/features/keyboard-drag-and-drop/feature.d.ts +2 -0
- package/lib/esm/features/keyboard-drag-and-drop/feature.js +204 -0
- package/lib/esm/features/keyboard-drag-and-drop/types.d.ts +27 -0
- package/lib/esm/features/keyboard-drag-and-drop/types.js +8 -0
- package/lib/esm/index.d.ts +2 -0
- package/lib/esm/index.js +2 -0
- package/lib/esm/mddocs-entry.d.ts +10 -0
- package/lib/esm/test-utils/test-tree-expect.d.ts +5 -3
- package/lib/esm/test-utils/test-tree-expect.js +3 -0
- package/lib/esm/types/core.d.ts +2 -1
- package/lib/esm/utilities/create-on-drop-handler.d.ts +2 -2
- package/lib/esm/utilities/insert-items-at-target.d.ts +2 -2
- package/package.json +1 -1
- package/src/features/drag-and-drop/drag-and-drop.spec.ts +6 -6
- package/src/features/drag-and-drop/feature.ts +12 -12
- package/src/features/drag-and-drop/types.ts +11 -11
- package/src/features/drag-and-drop/utils.ts +64 -39
- package/src/features/hotkeys-core/feature.ts +1 -0
- package/src/features/keyboard-drag-and-drop/feature.ts +255 -0
- package/src/features/keyboard-drag-and-drop/keyboard-drag-and-drop.spec.ts +401 -0
- package/src/features/keyboard-drag-and-drop/types.ts +30 -0
- package/src/index.ts +2 -0
- package/src/mddocs-entry.ts +16 -0
- package/src/test-utils/test-tree-expect.ts +7 -2
- package/src/types/core.ts +2 -0
- package/src/utilities/create-on-drop-handler.ts +2 -2
- package/src/utilities/insert-items-at-target.ts +2 -2
package/src/mddocs-entry.ts
CHANGED
|
@@ -9,6 +9,7 @@ import { SelectionFeatureDef } from "./features/selection/types";
|
|
|
9
9
|
import { SyncDataLoaderFeatureDef } from "./features/sync-data-loader/types";
|
|
10
10
|
import { TreeFeatureDef } from "./features/tree/types";
|
|
11
11
|
import { PropMemoizationFeatureDef } from "./features/prop-memoization/types";
|
|
12
|
+
import { KeyboardDragAndDropFeatureDef } from "./features/keyboard-drag-and-drop/types";
|
|
12
13
|
|
|
13
14
|
export * from ".";
|
|
14
15
|
|
|
@@ -49,6 +50,21 @@ export type DragAndDropFeatureItemInstance<T> =
|
|
|
49
50
|
DragAndDropFeatureDef<T>["itemInstance"];
|
|
50
51
|
export type DragAndDropFeatureHotkeys<T> = DragAndDropFeatureDef<T>["hotkeys"];
|
|
51
52
|
|
|
53
|
+
/** @interface */
|
|
54
|
+
export type KeyboardDragAndDropFeatureConfig<T> =
|
|
55
|
+
KeyboardDragAndDropFeatureDef<T>["config"];
|
|
56
|
+
/** @interface */
|
|
57
|
+
export type KeyboardDragAndDropFeatureState<T> =
|
|
58
|
+
KeyboardDragAndDropFeatureDef<T>["state"];
|
|
59
|
+
/** @interface */
|
|
60
|
+
export type KeyboardDragAndDropFeatureTreeInstance<T> =
|
|
61
|
+
KeyboardDragAndDropFeatureDef<T>["treeInstance"];
|
|
62
|
+
/** @interface */
|
|
63
|
+
export type KeyboardDragAndDropFeatureItemInstance<T> =
|
|
64
|
+
KeyboardDragAndDropFeatureDef<T>["itemInstance"];
|
|
65
|
+
export type KeyboardDragAndDropFeatureHotkeys<T> =
|
|
66
|
+
KeyboardDragAndDropFeatureDef<T>["hotkeys"];
|
|
67
|
+
|
|
52
68
|
/** @interface */
|
|
53
69
|
export type ExpandAllFeatureConfig = ExpandAllFeatureDef["config"];
|
|
54
70
|
/** @interface */
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
import { Mock, expect } from "vitest";
|
|
3
3
|
import { DragEvent } from "react";
|
|
4
4
|
import { TestTree } from "./test-tree";
|
|
5
|
-
import {
|
|
5
|
+
import { DragTarget } from "../features/drag-and-drop/types";
|
|
6
|
+
import { TreeState } from "../types/core";
|
|
6
7
|
|
|
7
8
|
export class TestTreeExpect<T> {
|
|
8
9
|
protected itemInstance(itemId: string) {
|
|
@@ -39,7 +40,11 @@ export class TestTreeExpect<T> {
|
|
|
39
40
|
expect(itemChildren).toEqual(children);
|
|
40
41
|
}
|
|
41
42
|
|
|
42
|
-
|
|
43
|
+
substate<K extends keyof TreeState<T>>(key: K, value: TreeState<T>[K]) {
|
|
44
|
+
expect(this.tree.instance.getState()[key]).toEqual(value);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
dropped(draggedItems: string[], target: DragTarget<any>) {
|
|
43
48
|
expect(this.tree.instance.getConfig().onDrop).toBeCalledWith(
|
|
44
49
|
draggedItems.map((id) => this.tree.item(id)),
|
|
45
50
|
target,
|
package/src/types/core.ts
CHANGED
|
@@ -12,6 +12,7 @@ import { SearchFeatureDef } from "../features/search/types";
|
|
|
12
12
|
import { RenamingFeatureDef } from "../features/renaming/types";
|
|
13
13
|
import { ExpandAllFeatureDef } from "../features/expand-all/types";
|
|
14
14
|
import { PropMemoizationFeatureDef } from "../features/prop-memoization/types";
|
|
15
|
+
import { KeyboardDragAndDropFeatureDef } from "../features/keyboard-drag-and-drop/types";
|
|
15
16
|
|
|
16
17
|
export type Updater<T> = T | ((old: T) => T);
|
|
17
18
|
export type SetStateFn<T> = (updaterOrValue: Updater<T>) => void;
|
|
@@ -53,6 +54,7 @@ export type RegisteredFeatures<T> =
|
|
|
53
54
|
| TreeFeatureDef<T>
|
|
54
55
|
| SelectionFeatureDef<T>
|
|
55
56
|
| DragAndDropFeatureDef<T>
|
|
57
|
+
| KeyboardDragAndDropFeatureDef<T>
|
|
56
58
|
| HotkeysCoreFeatureDef<T>
|
|
57
59
|
| SyncDataLoaderFeatureDef<T>
|
|
58
60
|
| AsyncDataLoaderFeatureDef<T>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ItemInstance } from "../types/core";
|
|
2
|
-
import {
|
|
2
|
+
import { DragTarget } from "../features/drag-and-drop/types";
|
|
3
3
|
import { removeItemsFromParents } from "./remove-items-from-parents";
|
|
4
4
|
import { insertItemsAtTarget } from "./insert-items-at-target";
|
|
5
5
|
|
|
@@ -7,7 +7,7 @@ export const createOnDropHandler =
|
|
|
7
7
|
<T>(
|
|
8
8
|
onChangeChildren: (item: ItemInstance<T>, newChildren: string[]) => void,
|
|
9
9
|
) =>
|
|
10
|
-
async (items: ItemInstance<T>[], target:
|
|
10
|
+
async (items: ItemInstance<T>[], target: DragTarget<T>) => {
|
|
11
11
|
const itemIds = items.map((item) => item.getId());
|
|
12
12
|
await removeItemsFromParents(items, onChangeChildren);
|
|
13
13
|
await insertItemsAtTarget(itemIds, target, onChangeChildren);
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { ItemInstance } from "../types/core";
|
|
2
|
-
import {
|
|
2
|
+
import { DragTarget } from "../features/drag-and-drop/types";
|
|
3
3
|
|
|
4
4
|
export const insertItemsAtTarget = async <T>(
|
|
5
5
|
itemIds: string[],
|
|
6
|
-
target:
|
|
6
|
+
target: DragTarget<T>,
|
|
7
7
|
onChangeChildren: (
|
|
8
8
|
item: ItemInstance<T>,
|
|
9
9
|
newChildrenIds: string[],
|