react-arborist
Advanced tools
Comparing version 3.0.2 to 3.1.0
@@ -83,2 +83,3 @@ import { EditResult } from "../types/handlers"; | ||
align?: Align; | ||
focus?: boolean; | ||
}): void; | ||
@@ -85,0 +86,0 @@ deselect(node: Identity): void; |
@@ -8,2 +8,3 @@ import { BoolFunc } from "./utils"; | ||
import { OpenMap } from "../state/open-slice"; | ||
import { useDragDropManager } from "react-dnd"; | ||
export interface TreeProps<T> { | ||
@@ -55,2 +56,3 @@ data?: readonly T[]; | ||
onContextMenu?: MouseEventHandler; | ||
dndManager?: ReturnType<typeof useDragDropManager>; | ||
} |
{ | ||
"name": "react-arborist", | ||
"version": "3.0.2", | ||
"version": "3.1.0", | ||
"license": "MIT", | ||
@@ -9,4 +9,5 @@ "source": "src/index.ts", | ||
"types": "dist/index.d.ts", | ||
"sideEffects": false, | ||
"scripts": { | ||
"start": "run-p 'watch:**'", | ||
"start": "run-p 'start:**'", | ||
"build": "npm-run-all clean -p 'build:**'", | ||
@@ -13,0 +14,0 @@ "test": "jest", |
@@ -330,2 +330,3 @@ ![Logo](https://user-images.githubusercontent.com/3460638/161630636-3512fe81-41c2-4ee5-8f7e-adaad07033b6.svg) | ||
onContextMenu?: MouseEventHandler; | ||
dndManager?: DragDropManager; | ||
} | ||
@@ -332,0 +333,0 @@ ``` |
@@ -32,20 +32,31 @@ import { NodeApi } from "../interfaces/node-api"; | ||
): NodeApi<T>[] { | ||
function collect(node: NodeApi<T>) { | ||
let result: NodeApi<T>[] = []; | ||
const matches: Record<string, boolean> = {}; | ||
const list: NodeApi<T>[] = []; | ||
function markMatch(node: NodeApi<T>) { | ||
const yes = !node.isRoot && isMatch(node); | ||
if (node.children) { | ||
for (let child of node.children) { | ||
result = result.concat(collect(child)); | ||
if (yes) { | ||
matches[node.id] = true; | ||
let parent = node.parent; | ||
while (parent) { | ||
matches[parent.id] = true; | ||
parent = parent.parent; | ||
} | ||
} | ||
if (result.length) { | ||
if (!node.isRoot) result.unshift(node); | ||
return result; | ||
if (node.children) { | ||
for (let child of node.children) markMatch(child); | ||
} | ||
if (yes) return [node]; | ||
else return []; | ||
} | ||
const list = collect(root).filter((n) => n.parent?.isOpen); | ||
function collect(node: NodeApi<T>) { | ||
if (node.level >= 0 && matches[node.id]) { | ||
list.push(node); | ||
} | ||
if (node.isOpen) { | ||
node.children?.forEach(collect); | ||
} | ||
} | ||
markMatch(root); | ||
collect(root); | ||
list.forEach(assignRowIndex); | ||
@@ -52,0 +63,0 @@ return list; |
@@ -326,6 +326,7 @@ import { EditResult } from "../types/handlers"; | ||
select(node: Identity, opts: { align?: Align } = {}) { | ||
select(node: Identity, opts: { align?: Align; focus?: boolean } = {}) { | ||
if (!node) return; | ||
const changeFocus = opts.focus !== false; | ||
const id = identify(node); | ||
this.dispatch(focus(id)); | ||
if (changeFocus) this.dispatch(focus(id)); | ||
this.dispatch(selection.only(id)); | ||
@@ -335,3 +336,5 @@ this.dispatch(selection.anchor(id)); | ||
this.scrollTo(id, opts.align); | ||
if (this.focusedNode) safeRun(this.props.onFocus, this.focusedNode); | ||
if (this.focusedNode && changeFocus) { | ||
safeRun(this.props.onFocus, this.focusedNode); | ||
} | ||
safeRun(this.props.onSelect, this.selectedNodes); | ||
@@ -338,0 +341,0 @@ } |
@@ -8,2 +8,3 @@ import { BoolFunc } from "./utils"; | ||
import { OpenMap } from "../state/open-slice"; | ||
import { useDragDropManager } from "react-dnd" | ||
@@ -79,2 +80,3 @@ export interface TreeProps<T> { | ||
onContextMenu?: MouseEventHandler; | ||
dndManager?: ReturnType<typeof useDragDropManager> | ||
} |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
599298
7858
730