@@ -17,18 +17,18 @@ const configurable = true;
17
17
/* Functions */
18
18
/* -------------------------------------------------------------------------- */
19
19
20
- const useFlatJsonTree : (
20
+ function useFlatJsonTree (
21
21
tree : Reactive < Record < string , unknown > [ ] > | Record < string , unknown > [ ] ,
22
22
{
23
- branch,
24
- children,
25
- id,
26
- index,
27
- next,
28
- parent,
29
- prev,
30
- siblings,
31
- } ? : {
23
+ branch : keyBranch = "branch" ,
24
+ children : keyChildren = "children" ,
25
+ id : keyId = "id" ,
26
+ index : keyIndex = "index" ,
27
+ next : keyNext = "next" ,
28
+ parent : keyParent = "parent" ,
29
+ prev : keyPrev = "prev" ,
30
+ siblings : keySiblings = "siblings" ,
31
+ } : {
32
32
branch ?: string ;
33
33
children ?: string ;
34
34
id ?: string ;
@@ -37,28 +37,16 @@ const useFlatJsonTree: (
37
37
parent ?: string ;
38
38
prev ?: string ;
39
39
siblings ?: string ;
40
- } ,
41
- ) => {
40
+ } = { } ,
41
+ ) : {
42
42
add : ( pId : string ) => null | string ;
43
43
down : ( pId : string ) => void ;
44
44
leaves : ComputedRef < Record < string , unknown > [ ] > ;
45
45
left : ( pId : string ) => null | string ;
46
46
remove : ( pId : string ) => null | string ;
47
47
right : ( pId : string ) => null | string ;
48
48
up : ( pId : string ) => void ;
49
- } = (
50
- tree ,
51
- {
52
- branch : keyBranch = "branch" ,
53
- children : keyChildren = "children" ,
54
- id : keyId = "id" ,
55
- index : keyIndex = "index" ,
56
- next : keyNext = "next" ,
57
- parent : keyParent = "parent" ,
58
- prev : keyPrev = "prev" ,
59
- siblings : keySiblings = "siblings" ,
60
- } = { } ,
61
- ) => {
49
+ } {
62
50
/* -------------------------------------------------------------------------- */
63
51
/* Constants */
64
52
/* -------------------------------------------------------------------------- */
@@ -103,11 +91,14 @@ const useFlatJsonTree: (
103
91
/* Functions */
104
92
/* -------------------------------------------------------------------------- */
105
93
106
- const getLeaves : (
94
+ function getLeaves (
107
95
siblings : { configurable ?: boolean ; value : Record < string , unknown > [ ] } ,
108
- parent ?: { configurable ?: boolean ; value : null | Record < string , unknown > } ,
109
- ) => Record < string , unknown > [ ] = ( siblings , parent = { value : null } ) =>
110
- siblings . value . flatMap ( ( value ) => {
96
+ parent : {
97
+ configurable ?: boolean ;
98
+ value : null | Record < string , unknown > ;
99
+ } = { value : null } ,
100
+ ) : Record < string , unknown > [ ] {
101
+ return siblings . value . flatMap ( ( value ) => {
111
102
Object . defineProperties ( value , {
112
103
...properties ,
113
104
[ keyParent ] : parent ,
@@ -124,28 +115,28 @@ const useFlatJsonTree: (
124
115
) ,
125
116
] ;
126
117
} ) ;
118
+ }
127
119
128
120
/* -------------------------------------------------------------------------- */
129
- /* Constants */
130
- /* -------------------------------------------------------------------------- */
131
121
132
- const value : Reactive < Record < string , unknown > [ ] > = isReactive ( tree )
133
- ? tree
134
- : reactive ( tree ) ;
122
+ function startLeaves ( ) {
123
+ const value : Reactive < Record < string , unknown > [ ] > = isReactive ( tree )
124
+ ? tree
125
+ : reactive ( tree ) ;
126
+ return getLeaves ( { value } ) ;
127
+ }
135
128
136
129
/* -------------------------------------------------------------------------- */
137
130
/* Computations */
138
131
/* -------------------------------------------------------------------------- */
139
132
140
- const leaves : ComputedRef < Record < string , unknown > [ ] > = computed ( ( ) =>
141
- getLeaves ( { value } ) ,
142
- ) ;
133
+ const leaves : ComputedRef < Record < string , unknown > [ ] > = computed ( startLeaves ) ;
143
134
144
135
/* -------------------------------------------------------------------------- */
145
136
/* Functions */
146
137
/* -------------------------------------------------------------------------- */
147
138
148
- const up : ( pId : string ) => void = ( pId ) => {
139
+ function up ( pId : string ) : void {
149
140
const the : null | Record < string , unknown > =
150
141
leaves . value . find ( ( leaf ) => leaf [ keyId ] === pId ) ?? null ;
151
142
if ( the ) {
@@ -161,11 +152,11 @@ const useFlatJsonTree: (
161
152
siblings [ prevIndex ] ,
162
153
] ;
163
154
}
164
- } ;
155
+ }
165
156
166
157
/* -------------------------------------------------------------------------- */
167
158
168
- const down : ( pId : string ) => void = ( pId ) => {
159
+ function down ( pId : string ) : void {
169
160
const the : null | Record < string , unknown > =
170
161
leaves . value . find ( ( leaf ) => leaf [ keyId ] === pId ) ?? null ;
171
162
if ( the ) {
@@ -181,11 +172,11 @@ const useFlatJsonTree: (
181
172
siblings [ index ] ,
182
173
] ;
183
174
}
184
- } ;
175
+ }
185
176
186
177
/* -------------------------------------------------------------------------- */
187
178
188
- const right : ( pId : string ) => null | string = ( pId : string ) => {
179
+ function right ( pId : string ) : null | string {
189
180
const the : null | Record < string , unknown > =
190
181
leaves . value . find ( ( leaf ) => leaf [ keyId ] === pId ) ?? null ;
191
182
if ( the ) {
@@ -204,11 +195,11 @@ const useFlatJsonTree: (
204
195
}
205
196
}
206
197
return null ;
207
- } ;
198
+ }
208
199
209
200
/* -------------------------------------------------------------------------- */
210
201
211
- const left : ( pId : string ) => null | string = ( pId ) => {
202
+ function left ( pId : string ) : null | string {
212
203
const the : null | Record < string , unknown > =
213
204
leaves . value . find ( ( leaf ) => leaf [ keyId ] === pId ) ?? null ;
214
205
if ( the ) {
@@ -228,11 +219,11 @@ const useFlatJsonTree: (
228
219
}
229
220
}
230
221
return null ;
231
- } ;
222
+ }
232
223
233
224
/* -------------------------------------------------------------------------- */
234
225
235
- const add : ( pId : string ) => null | string = ( pId ) => {
226
+ function add ( pId : string ) : null | string {
236
227
const the : null | Record < string , unknown > =
237
228
leaves . value . find ( ( leaf ) => leaf [ keyId ] === pId ) ?? null ;
238
229
if ( the ) {
@@ -256,11 +247,11 @@ const useFlatJsonTree: (
256
247
return id ;
257
248
}
258
249
return null ;
259
- } ;
250
+ }
260
251
261
252
/* -------------------------------------------------------------------------- */
262
253
263
- const remove : ( pId : string ) => null | string = ( pId ) => {
254
+ function remove ( pId : string ) : null | string {
264
255
const the : null | Record < string , unknown > =
265
256
leaves . value . find ( ( leaf ) => leaf [ keyId ] === pId ) ?? null ;
266
257
if ( the ) {
@@ -288,7 +279,7 @@ const useFlatJsonTree: (
288
279
}
289
280
}
290
281
return null ;
291
- } ;
282
+ }
292
283
293
284
/* -------------------------------------------------------------------------- */
294
285
/* Main */
@@ -297,7 +288,7 @@ const useFlatJsonTree: (
297
288
return { add, down, leaves, left, remove, right, up } ;
298
289
299
290
/* -------------------------------------------------------------------------- */
300
- } ;
291
+ }
301
292
302
293
/* -------------------------------------------------------------------------- */
303
294
/* Exports */
0 commit comments