1
- import type { Reactive } from "vue" ;
2
-
1
+ import { toReactive } from "@vueuse/core" ;
3
2
import { v4 } from "uuid" ;
4
3
import { computed , isReactive , reactive } from "vue" ;
5
4
6
5
/* -------------------------------------------------------------------------- */
7
6
8
7
export default (
9
- tree : Reactive < Record < string , unknown > [ ] > | Record < string , unknown > [ ] ,
8
+ tree : Record < string , unknown > [ ] ,
10
9
{
11
10
branch : keyBranch = "branch" ,
12
11
children : keyChildren = "children" ,
@@ -77,14 +76,16 @@ export default (
77
76
78
77
const leaves = computed ( ( ) => getLeaves ( { value } ) ) ;
79
78
80
- const atlas = computed ( ( ) =>
81
- Object . fromEntries (
82
- leaves . value . map ( ( leaf ) => [ leaf [ keyId ] as string , leaf ] ) ,
79
+ const atlas : Record < string , Record < string , unknown > > = toReactive (
80
+ computed ( ( ) =>
81
+ Object . fromEntries (
82
+ leaves . value . map ( ( leaf ) => [ leaf [ keyId ] as string , leaf ] ) ,
83
+ ) ,
83
84
) ,
84
85
) ;
85
86
86
87
const add = ( pId : string ) => {
87
- const the = atlas . value [ pId ] ;
88
+ const the = atlas [ pId ] ;
88
89
if ( the ) {
89
90
const children = the [ keyChildren ] as
90
91
| Record < string , unknown > [ ]
@@ -108,7 +109,7 @@ export default (
108
109
return undefined ;
109
110
} ,
110
111
down = ( pId : string ) => {
111
- const the = atlas . value [ pId ] ;
112
+ const the = atlas [ pId ] ;
112
113
if ( the ) {
113
114
const index = the [ keyIndex ] as number ,
114
115
nextIndex = index + 1 ,
@@ -125,7 +126,7 @@ export default (
125
126
}
126
127
} ,
127
128
left = ( pId : string ) => {
128
- const the = atlas . value [ pId ] ;
129
+ const the = atlas [ pId ] ;
129
130
if ( the ) {
130
131
const parent = the [ keyParent ] as Record < string , unknown > | undefined ;
131
132
if ( parent ?. [ keyParent ] ) {
@@ -145,7 +146,7 @@ export default (
145
146
return undefined ;
146
147
} ,
147
148
remove = ( pId : string ) => {
148
- const the = atlas . value [ pId ] ;
149
+ const the = atlas [ pId ] ;
149
150
if ( the ) {
150
151
const parent = the [ keyParent ] as Record < string , unknown > | undefined ;
151
152
if ( parent ) {
@@ -164,7 +165,7 @@ export default (
164
165
return undefined ;
165
166
} ,
166
167
right = ( pId : string ) => {
167
- const the = atlas . value [ pId ] ;
168
+ const the = atlas [ pId ] ;
168
169
if ( the ) {
169
170
const prev = the [ keyPrev ] as Record < string , unknown > | undefined ;
170
171
if ( prev ) {
@@ -184,7 +185,7 @@ export default (
184
185
return undefined ;
185
186
} ,
186
187
up = ( pId : string ) => {
187
- const the = atlas . value [ pId ] ;
188
+ const the = atlas [ pId ] ;
188
189
if ( the ) {
189
190
const index = the [ keyIndex ] as number ,
190
191
prevIndex = index - 1 ,
0 commit comments