@@ -12,6 +12,7 @@ import '@shoelace-style/shoelace/dist/components/button-group/button-group.js';
12
12
import '@shoelace-style/shoelace/dist/components/tooltip/tooltip.js' ;
13
13
14
14
import type { Jsf , Path , UiSchema } from '../json-schema-form.js' ;
15
+ import { debuggerInline } from './utils.js' ;
15
16
16
17
export const arrayField = (
17
18
schema : JSONSchema7 ,
@@ -27,20 +28,24 @@ export const arrayField = (
27
28
28
29
return html ` <!-- -->
29
30
< fieldset part ="array " class ="array ">
30
- ${ JSON . stringify ( schemaPath ) } arr
31
+ ${ debuggerInline ( { schemaPath, path } ) }
31
32
<!-- -->
32
33
< legend > ${ schema . title } </ legend >
34
+
33
35
${ dataLevel ?. map ?.( ( _item , index ) => {
34
36
if (
35
37
typeof schema . items !== 'object' ||
36
38
Array . isArray ( schema . items ) ||
37
39
! Array . isArray ( dataLevel )
38
40
)
39
41
return '' ;
42
+ const schemaPathAugmented = [ ...schemaPath ] ;
43
+ schemaPathAugmented . push ( 'items' ) ;
44
+
40
45
return html ` < sl-card
41
46
@dragover =${ ( event : DragEvent ) => {
42
47
event . preventDefault ( ) ;
43
- // event.stopPropagation();
48
+ event . stopPropagation ( ) ;
44
49
const dataTransfer = event . dataTransfer ;
45
50
if ( dataTransfer ) dataTransfer . dropEffect = 'move' ;
46
51
@@ -49,29 +54,32 @@ export const arrayField = (
49
54
// ?.setAttribute('data-dropzone', '');
50
55
} }
51
56
@dragenter =${ ( event : DragEvent ) => {
52
- // event.stopPropagation();
57
+ event . stopPropagation ( ) ;
53
58
( event . target as HTMLElement )
54
59
. closest ( 'sl-card' )
55
60
?. setAttribute ( 'data-dropzone' , '' ) ;
56
61
} }
57
62
@dragleave=${ ( event : DragEvent ) => {
58
- // event.stopPropagation();
63
+ event . stopPropagation ( ) ;
59
64
( event . target as HTMLElement )
60
65
. closest ( 'sl-card' )
61
66
?. removeAttribute ( 'data-dropzone' ) ;
62
67
} }
63
68
@drop=${ ( event : DragEvent ) => {
64
- // event.stopPropagation();
69
+ event . stopPropagation ( ) ;
65
70
const idx = event . dataTransfer ?. getData ( 'integer' ) ;
66
71
if ( ! idx ) return ;
67
72
const originIndex = Number . parseInt ( idx , 10 ) ;
73
+ // dataLevel ||= [];
68
74
if ( ! Array . isArray ( dataLevel ) ) return ;
69
75
const hold = dataLevel [ index ] as unknown ;
70
76
// eslint-disable-next-line no-param-reassign
71
77
dataLevel [ index ] = dataLevel [ originIndex ] as unknown ;
72
78
// eslint-disable-next-line no-param-reassign
73
79
dataLevel [ originIndex ] = hold ;
74
- handleChange ( [ ...path ] , dataLevel , schemaPath ) ;
80
+ handleChange ( [ ...path ] , dataLevel , schemaPathAugmented ) ;
81
+
82
+ console . log ( { originIndex, idx } ) ;
75
83
76
84
( event . target as HTMLElement )
77
85
. closest ( 'sl-card' )
@@ -84,7 +92,7 @@ export const arrayField = (
84
92
[ ...path , index ] ,
85
93
uiState ,
86
94
uiSchema ,
87
- schemaPath ,
95
+ schemaPathAugmented ,
88
96
) }
89
97
90
98
< div slot ="header " class ="array-card-header ">
@@ -184,7 +192,13 @@ export const arrayField = (
184
192
dataLevel . push ( schema . items ?. default || [ ] ) ;
185
193
}
186
194
187
- handleChange ( [ ...path ] , dataLevel , schemaPath ) ;
195
+ // const schemaPathAugmented = [...schemaPath];
196
+ // schemaPathAugmented.push('items');
197
+ handleChange (
198
+ [ ...path , dataLevel . length - 1 ] ,
199
+ dataLevel [ dataLevel . length - 1 ] ,
200
+ schemaPath ,
201
+ ) ;
188
202
} }
189
203
size ="large"
190
204
>
0 commit comments