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/jest.config.js ADDED
@@ -0,0 +1,5 @@
1
+ /** @type {import('ts-jest').JestConfigWithTsJest} */
2
+ module.exports = {
3
+ preset: 'ts-jest',
4
+ testEnvironment: 'node',
5
+ };
package/package.json CHANGED
@@ -1,12 +1,26 @@
1
1
  {
2
2
  "name": "react-arborist",
3
- "version": "3.0.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
- "repository": "github:brimdata/react-arborist",
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": "^27.5.1",
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
  }
@@ -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
- export const Tree = forwardRef(function Tree<T>(
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 check = this.props.disableDrop;
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 check == "function") {
421
- return check({
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 check == "string") {
426
+ } else if (typeof isDisabled == "string") {
427
427
  // @ts-ignore
428
- return !!parentNode.data[check];
429
- } else if (typeof check === "boolean") {
430
- return check;
428
+ return !parentNode.data[isDisabled];
429
+ } else if (typeof isDisabled === "boolean") {
430
+ return !isDisabled;
431
431
  } else {
432
432
  return true;
433
433
  }