@@ -12,6 +12,7 @@ import '@shoelace-style/shoelace/dist/components/button-group/button-group.js';
1212import '@shoelace-style/shoelace/dist/components/tooltip/tooltip.js' ;
1313
1414import type { Jsf , Path , UiSchema } from '../json-schema-form.js' ;
15+ import { debuggerInline } from './utils.js' ;
1516
1617export const arrayField = (
1718 schema : JSONSchema7 ,
@@ -27,20 +28,24 @@ export const arrayField = (
2728
2829 return html ` <!-- -->
2930 < fieldset part ="array " class ="array ">
30- ${ JSON . stringify ( schemaPath ) } arr
31+ ${ debuggerInline ( { schemaPath, path } ) }
3132 <!-- -->
3233 < legend > ${ schema . title } </ legend >
34+
3335 ${ dataLevel ?. map ?.( ( _item , index ) => {
3436 if (
3537 typeof schema . items !== 'object' ||
3638 Array . isArray ( schema . items ) ||
3739 ! Array . isArray ( dataLevel )
3840 )
3941 return '' ;
42+ const schemaPathAugmented = [ ...schemaPath ] ;
43+ schemaPathAugmented . push ( 'items' ) ;
44+
4045 return html ` < sl-card
4146 @dragover =${ ( event : DragEvent ) => {
4247 event . preventDefault ( ) ;
43- // event.stopPropagation();
48+ event . stopPropagation ( ) ;
4449 const dataTransfer = event . dataTransfer ;
4550 if ( dataTransfer ) dataTransfer . dropEffect = 'move' ;
4651
@@ -49,29 +54,32 @@ export const arrayField = (
4954 // ?.setAttribute('data-dropzone', '');
5055 } }
5156 @dragenter =${ ( event : DragEvent ) => {
52- // event.stopPropagation();
57+ event . stopPropagation ( ) ;
5358 ( event . target as HTMLElement )
5459 . closest ( 'sl-card' )
5560 ?. setAttribute ( 'data-dropzone' , '' ) ;
5661 } }
5762 @dragleave=${ ( event : DragEvent ) => {
58- // event.stopPropagation();
63+ event . stopPropagation ( ) ;
5964 ( event . target as HTMLElement )
6065 . closest ( 'sl-card' )
6166 ?. removeAttribute ( 'data-dropzone' ) ;
6267 } }
6368 @drop=${ ( event : DragEvent ) => {
64- // event.stopPropagation();
69+ event . stopPropagation ( ) ;
6570 const idx = event . dataTransfer ?. getData ( 'integer' ) ;
6671 if ( ! idx ) return ;
6772 const originIndex = Number . parseInt ( idx , 10 ) ;
73+ // dataLevel ||= [];
6874 if ( ! Array . isArray ( dataLevel ) ) return ;
6975 const hold = dataLevel [ index ] as unknown ;
7076 // eslint-disable-next-line no-param-reassign
7177 dataLevel [ index ] = dataLevel [ originIndex ] as unknown ;
7278 // eslint-disable-next-line no-param-reassign
7379 dataLevel [ originIndex ] = hold ;
74- handleChange ( [ ...path ] , dataLevel , schemaPath ) ;
80+ handleChange ( [ ...path ] , dataLevel , schemaPathAugmented ) ;
81+
82+ console . log ( { originIndex, idx } ) ;
7583
7684 ( event . target as HTMLElement )
7785 . closest ( 'sl-card' )
@@ -84,7 +92,7 @@ export const arrayField = (
8492 [ ...path , index ] ,
8593 uiState ,
8694 uiSchema ,
87- schemaPath ,
95+ schemaPathAugmented ,
8896 ) }
8997
9098 < div slot ="header " class ="array-card-header ">
@@ -184,7 +192,13 @@ export const arrayField = (
184192 dataLevel . push ( schema . items ?. default || [ ] ) ;
185193 }
186194
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+ ) ;
188202 } }
189203 size ="large"
190204 >
0 commit comments