forked from N00ts/vue3-treeview
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstore.ts
38 lines (33 loc) · 1.11 KB
/
store.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
import { INode } from "../structure/INode";
import { IConfiguration } from '../structure/IConfiguration';
import { toRefs, computed, ComputedRef, Ref, ref } from 'vue';
import { ITreeProps } from '../structure/ITreeProps';
import { IDragContext } from '../structure/IDragContext';
import uniqueId from "lodash.uniqueid";
export interface IState {
id: string;
nodes: ComputedRef<{ [id: string]: INode }>;
config: ComputedRef<IConfiguration>;
dragged: Ref<IDragContext>;
focusable: Ref<string>;
focusFunc: Map<string, Function>,
}
export const states: Map<string, IState> = new Map();
export function createState(props: ITreeProps): string {
const { nodes, config } = toRefs(props);
const state: IState = {
id: uniqueId(),
nodes: computed(() => nodes.value),
config: computed(() => config.value),
focusable: ref(null),
focusFunc: new Map<string, Function>(),
dragged: ref({
node: null,
element: null,
wrapper: null,
parentId: null
}),
};
states.set(state.id, state);
return state.id;
}