forked from diogofcunha/react-virtualized-tree
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
162 lines (129 loc) · 4.24 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
// Type definitions for react-virtualized-tree
// Definitions by: Diogo Cunha
import * as React from 'react';
type NodeId = number | string;
interface BasicNode {
id: NodeId;
name: string;
state?: {[stateKey: string]: any};
}
export interface Node extends BasicNode {
children?: BasicNode[];
}
export interface FlattenedNode extends Node {
deepness: number;
parents: number[];
}
interface NodeAction {
type: string;
node: FlattenedNode;
}
type onChange = (nodes: Node[], node: Node) => Node[];
export interface Extensions {
updateTypeHandlers: {[type: number]: onChange};
}
export interface TreeProps {
extensions?: Extensions;
nodes: Node[];
onChange: (nodes: Node[]) => void;
children: <T = any>(props: RendererProps<T>) => JSX.Element;
nodeMarginLeft?: number;
width?: number;
scrollToId?: number;
scrollToAlignment?: string;
}
export default class Tree extends React.Component<TreeProps> {}
export type Omit<T, K> = Pick<T, Exclude<keyof T, K>>;
export interface RendererProps<T> {
measure: () => void;
index: number;
onChange: (updateParams: NodeAction) => void;
node: FlattenedNode;
iconsClassNameMap?: T;
style: React.CSSProperties;
children?: React.ReactNode;
}
export type InjectedRendererProps<T> = Omit<RendererProps<T>, 'iconsClassNameMap'>;
export type CustomRendererProps<T> = Omit<RendererProps<T>, 'style'>;
type DeletableRenderProps = CustomRendererProps<{delete?: string}>;
type ExpandableRenderProps = CustomRendererProps<{
expanded?: string;
collapsed?: string;
lastChild?: string;
}>;
type FavoriteRenderProps = CustomRendererProps<{
favorite?: string;
notFavorite?: string;
}>;
declare const Deletable: React.SFC<DeletableRenderProps>;
declare const Expandable: React.SFC<ExpandableRenderProps>;
declare const Favorite: React.SFC<FavoriteRenderProps>;
interface Renderers {
Deletable: React.SFC<DeletableRenderProps>;
Expandable: React.SFC<ExpandableRenderProps>;
Favorite: React.SFC<FavoriteRenderProps>;
}
export const renderers: Renderers;
export interface Group {
filter: (node: Node) => boolean;
name: string;
}
interface GroupRendererProps {
onChange: (c: string) => void;
groups: {[g: string]: Group};
selectedGroup: string;
}
export interface FilteringContainerProps {
nodes: Node[];
children: (params: {nodes: Node[]; nodeParentMappings: {[id: NodeId]: NodeId[]}}) => JSX.Element;
debouncer?: (func: (...p: any[]) => any, timeout: number) => void;
groups?: {[g: string]: Group};
selectedGroup?: string;
groupRenderer?: React.StatelessComponent<GroupRendererProps> | React.Component<GroupRendererProps>;
onSelectedGroupChange?: (c: string) => void;
indexSearch: (searchTerm: string, nodes: FlattenedNode[]) => (node: FlattenedNode) => boolean;
}
export class FilteringContainer extends React.Component<FilteringContainerProps> {}
export enum UPDATE_TYPE {
ADD = 0,
DELETE = 1,
UPDATE = 2,
}
interface Constants {
UPDATE_TYPE: UPDATE_TYPE;
}
export const constants: Constants;
interface NodeRenderOptions {
hasChildren: boolean;
isExpanded: boolean;
isFavorite: boolean;
isDeletable: boolean;
}
export enum NODE_CHANGE_OPERATIONS {
CHANGE_NODE = 'CHANGE_NODE',
DELETE_NODE = 'DELETE_NODE',
}
interface Selectors {
getNodeRenderOptions: (node: FlattenedNode) => NodeRenderOptions;
replaceNodeFromTree: (nodes: Node[], updatedNode: FlattenedNode, operation?: NODE_CHANGE_OPERATIONS) => Node[];
deleteNodeFromTree: (nodes: Node[], nodeToDelete: FlattenedNode) => Node[];
deleteNode: (node: FlattenedNode[]) => NodeAction;
addNode: (node: FlattenedNode[]) => NodeAction;
updateNode: (node: FlattenedNode, state: {[stateKey: string]: any}) => NodeAction;
}
interface State {
flattenedTree: Array<number | string>[];
tree: Node[];
}
export interface TreeState {
getNodeAt: (state: State, index: number) => Node;
getTree: (state: State) => Node[];
createFromTree: (tree: Node[]) => State;
getNumberOfVisibleDescendants: (state: State, index: number) => number;
getNodeDeepness: (state: State, index: number) => number;
}
export interface TreeStateModifiers {
editNodeAt: (state: State, index: number, updateNode: ((oldNode: Node) => Node) | Node) => State;
deleteNodeAt: (state: State, index: number) => State;
}
export const selectors: Selectors;