react-arborist 1.1.0 → 1.2.0

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 CHANGED
@@ -29,7 +29,7 @@ Render the tree data structure.
29
29
  ```jsx
30
30
  const data = {
31
31
  id: "A",
32
- name: "Root"
32
+ name: "Root",
33
33
  children: [
34
34
  { id: "B", name: "Node 1" },
35
35
  { id: "C", name: "Node 2" },
@@ -85,22 +85,23 @@ If your data does not look like this, you can provide a `childrenAccessor` prop.
85
85
 
86
86
  Unlike other Tree Components, react-arborist is designed as a [controlled component](https://reactjs.org/docs/forms.html#controlled-components). This means the consumer will provide the tree data and the handlers to update it. The only state managed internally is for drag and drop, selection, and editing.
87
87
 
88
- | Prop | Default | Description |
89
- | ---------------- | ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
90
- | data | (required) | The tree data structure to render as described above. |
91
- | width | 300 | The width of the tree. |
92
- | height | 500 | The height of the tree. To dynamically fill it's container, use a [hook](https://github.com/ZeeCoder/use-resize-observer) or [component](https://github.com/bvaughn/react-virtualized-auto-sizer) to gather the width and height of the Tree's parent. |
93
- | rowHeight | 24 | The height of each row. |
94
- | indent | 24 | The number of pixels to indent child nodes. |
95
- | hideRoot | false | Hide the root node so that the first set of children appear as the roots. |
96
- | onToggle | noop | Handler called when a node is opened or closed. This and the subsequent functions should update the `data` prop for the tree to re-render. |
97
- | onMove | noop | Handler called when a user moves one or more nodes by dragging and dropping. |
98
- | onEdit | noop | Handler called when a user performs an inline edit of the node. |
99
- | childrenAccessor | "children" | Used to get a node's children if they exist on a property other than "children". |
100
- | isOpenAccessor | "isOpen" | Used to get a node's openness state if it exists on a property other than "isOpen". |
101
- | openByDefault | true | Choose if the node should be open or closed when it has an undefined openness state. |
102
- | className | undefined | Adds a class to the containing div. |
103
- | dndRootElement | undefined | The element for react-dnd to bind it's events to. Defaults to window. See https://github.com/brimdata/react-arborist/pull/33 |
88
+ | Prop | Default | Description |
89
+ | ---------------- | ------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
90
+ | data | (required) | The tree data structure to render as described above. |
91
+ | width | 300 | The width of the tree. |
92
+ | height | 500 | The height of the tree. To dynamically fill it's container, use a [hook](https://github.com/ZeeCoder/use-resize-observer) or [component](https://github.com/bvaughn/react-virtualized-auto-sizer) to gather the width and height of the Tree's parent. |
93
+ | rowHeight | 24 | The height of each row. |
94
+ | indent | 24 | The number of pixels to indent child nodes. |
95
+ | hideRoot | false | Hide the root node so that the first set of children appear as the roots. |
96
+ | onToggle | noop | Handler called when a node is opened or closed. This and the subsequent functions should update the `data` prop for the tree to re-render. |
97
+ | onMove | noop | Handler called when a user moves one or more nodes by dragging and dropping. |
98
+ | onEdit | noop | Handler called when a user performs an inline edit of the node. |
99
+ | childrenAccessor | "children" | Used to get a node's children if they exist on a property other than "children". |
100
+ | isOpenAccessor | "isOpen" | Used to get a node's openness state if it exists on a property other than "isOpen". |
101
+ | openByDefault | true | Choose if the node should be open or closed when it has an undefined openness state. |
102
+ | className | undefined | Adds a class to the containing div. |
103
+ | dndRootElement | undefined | The element for react-dnd to bind it's events to. Defaults to window. See https://github.com/brimdata/react-arborist/pull/33 |
104
+ | dropCursor | ({top, left, indent}) => ReactElement | Provide a custom render function for the drop cursor (the line you see as you drag an item around the tree). It recieves props {left, top, indent} which are all numbers. See the [DefaultDropCursor](https://github.com/brimdata/react-arborist/blob/main/packages/react-arborist/src/components/default-drop-cursor.tsx) for an example of how to create a custom one. |
104
105
 
105
106
  The only child of the Tree Component must be a NodeRenderer function as described below.
106
107
 
@@ -0,0 +1,3 @@
1
+ /// <reference types="react" />
2
+ import { DropCursorProps } from "../types";
3
+ export declare function defaultDropCursor(props: DropCursorProps): JSX.Element;
@@ -0,0 +1,2 @@
1
+ /// <reference types="react" />
2
+ export declare const ListOuterElement: (props: import("react").HTMLProps<HTMLDivElement> & import("react").RefAttributes<unknown>) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | null;
@@ -0,0 +1,4 @@
1
+ /// <reference types="react" />
2
+ export declare function List(props: {
3
+ className?: string;
4
+ }): JSX.Element;
@@ -0,0 +1,4 @@
1
+ import { ReactElement } from "react";
2
+ export declare function OuterDrop(props: {
3
+ children: ReactElement;
4
+ }): ReactElement<any, string | import("react").JSXElementConstructor<any>>;
@@ -1,7 +1,8 @@
1
1
  import React from "react";
2
+ import { IdObj } from "../types";
2
3
  declare type Props = {
3
4
  style: React.CSSProperties;
4
5
  index: number;
5
6
  };
6
- export declare const Row: React.NamedExoticComponent<Props>;
7
+ export declare const Row: React.MemoExoticComponent<(<T extends IdObj>({ index, style, }: Props) => JSX.Element)>;
7
8
  export {};
package/dist/context.d.ts CHANGED
@@ -1,18 +1,5 @@
1
- /// <reference types="react" />
2
- import { Cursor } from "./dnd/compute-drop";
3
- import { IdObj, SelectionState, StaticContext } from "./types";
4
- export declare const CursorParentId: import("react").Context<string | null>;
5
- export declare function useCursorParentId(): string | null;
6
- export declare const IsCursorOverFolder: import("react").Context<boolean>;
7
- export declare function useIsCursorOverFolder(): boolean;
8
- export declare const CursorLocationContext: import("react").Context<Cursor | null>;
9
- export declare function useCursorLocation(): Cursor | null;
10
- export declare const Static: import("react").Context<StaticContext<IdObj> | null>;
11
- export declare function useStaticContext(): StaticContext<IdObj>;
12
- export declare const DispatchContext: import("react").Context<null>;
13
- export declare function useDispatch(): never;
14
- export declare const SelectionContext: import("react").Context<SelectionState | null>;
15
- export declare function useSelectedIds(): string[];
16
- export declare function useIsSelected(): (index: number | null) => boolean;
17
- export declare const EditingIdContext: import("react").Context<string | null>;
18
- export declare function useEditingId(): string | null;
1
+ import React from "react";
2
+ import { TreeApi } from "./tree-api";
3
+ import { IdObj } from "./types";
4
+ export declare const TreeApiContext: React.Context<TreeApi<any> | null>;
5
+ export declare function useTreeApi<T extends IdObj>(): TreeApi<T>;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  import { Tree } from "./components/tree";
2
2
  import { TreeApi } from "./tree-api";
3
- import type { NodeRenderer, NodeState, NodeHandlers } from "./types";
4
- export { Tree, TreeApi, NodeRenderer, NodeState, NodeHandlers };
3
+ import type { NodeRenderer, NodeState, NodeHandlers, NodeRendererProps, DropCursorProps } from "./types";
4
+ export { Tree, TreeApi, NodeRenderer, NodeState, NodeHandlers, NodeRendererProps, DropCursorProps, };