react-arborist 3.0.0 → 3.0.2
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/README.md +1 -6
- package/dist/components/tree.d.ts +5 -1
- package/dist/index.js +8 -7
- package/dist/index.js.map +1 -1
- package/dist/module.js +8 -7
- package/dist/module.js.map +1 -1
- package/jest.config.js +5 -0
- package/package.json +19 -12
- package/src/components/tree.tsx +6 -2
- package/src/interfaces/tree-api.test.ts +15 -0
- package/src/interfaces/tree-api.ts +7 -7
package/jest.config.js
ADDED
package/package.json
CHANGED
|
@@ -1,12 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-arborist",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"source": "src/index.ts",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"module": "dist/module.js",
|
|
8
8
|
"types": "dist/index.d.ts",
|
|
9
|
-
"
|
|
9
|
+
"scripts": {
|
|
10
|
+
"start": "run-p 'watch:**'",
|
|
11
|
+
"build": "npm-run-all clean -p 'build:**'",
|
|
12
|
+
"test": "jest",
|
|
13
|
+
"build:js": "parcel build --target main --target module",
|
|
14
|
+
"build:types": "tsc --outDir dist",
|
|
15
|
+
"clean": "rimraf dist",
|
|
16
|
+
"start:js": "parcel watch --target main --target module --no-hmr --no-cache",
|
|
17
|
+
"start:types": "tsc --outDir dist --watch",
|
|
18
|
+
"prepack": "yarn build"
|
|
19
|
+
},
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "https://github.com/brimdata/react-arborist.git"
|
|
23
|
+
},
|
|
10
24
|
"homepage": "https://react-arborist.netlify.app",
|
|
11
25
|
"bugs": "https://github.com/brimdata/react-arborist/issues",
|
|
12
26
|
"keywords": [
|
|
@@ -27,15 +41,6 @@
|
|
|
27
41
|
"redux": "^4.1.1",
|
|
28
42
|
"use-sync-external-store": "^1.2.0"
|
|
29
43
|
},
|
|
30
|
-
"scripts": {
|
|
31
|
-
"build": "run-p 'build:**'",
|
|
32
|
-
"build:js": "parcel build --target main --target module",
|
|
33
|
-
"build:types": "tsc --outDir dist",
|
|
34
|
-
"watch:js": "parcel watch --target main --target module --no-hmr --no-cache",
|
|
35
|
-
"watch:types": "tsc --outDir dist --watch",
|
|
36
|
-
"watch": "run-p 'watch:**'",
|
|
37
|
-
"prepack": "yarn build"
|
|
38
|
-
},
|
|
39
44
|
"peerDependencies": {
|
|
40
45
|
"react": ">= 16.14",
|
|
41
46
|
"react-dom": ">= 16.14"
|
|
@@ -46,9 +51,11 @@
|
|
|
46
51
|
"@types/react": "^18.0.0",
|
|
47
52
|
"@types/react-window": "^1.8.5",
|
|
48
53
|
"@types/use-sync-external-store": "^0.0.3",
|
|
49
|
-
"jest": "^
|
|
54
|
+
"jest": "^29.4.1",
|
|
50
55
|
"npm-run-all": "^4.1.5",
|
|
51
56
|
"parcel": "^2.3.2",
|
|
57
|
+
"rimraf": "^4.1.2",
|
|
58
|
+
"ts-jest": "^29.0.5",
|
|
52
59
|
"typescript": "^4.6.2"
|
|
53
60
|
}
|
|
54
61
|
}
|
package/src/components/tree.tsx
CHANGED
|
@@ -8,7 +8,7 @@ import { TreeProps } from "../types/tree-props";
|
|
|
8
8
|
import { IdObj } from "../types/utils";
|
|
9
9
|
import { useValidatedProps } from "../hooks/use-validated-props";
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
function TreeComponent<T>(
|
|
12
12
|
props: TreeProps<T>,
|
|
13
13
|
ref: React.Ref<TreeApi<T> | undefined>
|
|
14
14
|
) {
|
|
@@ -21,4 +21,8 @@ export const Tree = forwardRef(function Tree<T>(
|
|
|
21
21
|
<DragPreviewContainer />
|
|
22
22
|
</TreeProvider>
|
|
23
23
|
);
|
|
24
|
-
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const Tree = forwardRef(TreeComponent) as <T>(
|
|
27
|
+
props: TreeProps<T> & { ref?: React.ForwardedRef<TreeApi<T> | undefined> }
|
|
28
|
+
) => ReturnType<typeof TreeComponent>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { createStore } from "redux";
|
|
2
|
+
import { rootReducer } from "../state/root-reducer";
|
|
3
|
+
import { TreeProps } from "../types/tree-props";
|
|
4
|
+
import { TreeApi } from "./tree-api";
|
|
5
|
+
|
|
6
|
+
function setupApi(props: TreeProps<any>) {
|
|
7
|
+
const store = createStore(rootReducer);
|
|
8
|
+
return new TreeApi(store, props, { current: null }, { current: null });
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
test("tree.canDrop()", () => {
|
|
12
|
+
expect(setupApi({ disableDrop: true }).canDrop()).toBe(false);
|
|
13
|
+
expect(setupApi({ disableDrop: () => false }).canDrop()).toBe(true);
|
|
14
|
+
expect(setupApi({ disableDrop: false }).canDrop()).toBe(true);
|
|
15
|
+
});
|
|
@@ -408,7 +408,7 @@ export class TreeApi<T> {
|
|
|
408
408
|
if (this.isFiltered) return false;
|
|
409
409
|
const parentNode = this.get(this.state.dnd.parentId) ?? this.root;
|
|
410
410
|
const dragNodes = this.dragNodes;
|
|
411
|
-
const
|
|
411
|
+
const isDisabled = this.props.disableDrop;
|
|
412
412
|
|
|
413
413
|
for (const drag of dragNodes) {
|
|
414
414
|
if (!drag) return false;
|
|
@@ -417,17 +417,17 @@ export class TreeApi<T> {
|
|
|
417
417
|
}
|
|
418
418
|
|
|
419
419
|
// Allow the user to insert their own logic
|
|
420
|
-
if (typeof
|
|
421
|
-
return
|
|
420
|
+
if (typeof isDisabled == "function") {
|
|
421
|
+
return !isDisabled({
|
|
422
422
|
parentNode,
|
|
423
423
|
dragNodes: this.dragNodes,
|
|
424
424
|
index: this.state.dnd.index,
|
|
425
425
|
});
|
|
426
|
-
} else if (typeof
|
|
426
|
+
} else if (typeof isDisabled == "string") {
|
|
427
427
|
// @ts-ignore
|
|
428
|
-
return
|
|
429
|
-
} else if (typeof
|
|
430
|
-
return
|
|
428
|
+
return !parentNode.data[isDisabled];
|
|
429
|
+
} else if (typeof isDisabled === "boolean") {
|
|
430
|
+
return !isDisabled;
|
|
431
431
|
} else {
|
|
432
432
|
return true;
|
|
433
433
|
}
|