1- import { block , insertAfter , clearSelection , prepend } from "../../domUtils" ;
1+ import { block , insertAfter , clearSelection , prepend , detach } from "../../domUtils" ;
22import { updateGrid } from "../index" ;
33import { addChange } from "../changes" ;
4+ import { Toast } from "../../toast" ;
45
56let MANIFEST = {
67 Class : {
@@ -310,7 +311,10 @@ export function enableItem ({headerElement, classData, classBlockName, classBloc
310311
311312 let isClass = ! classBlockName ,
312313 opened = false ,
313- container , controls ;
314+ container , controls ,
315+ savePath = isClass
316+ ? [ classData [ "Name" ] ]
317+ : [ classData [ "Name" ] , classBlockName , classBlockPropName ] ;
314318
315319 headerElement . addEventListener ( `click` , ( ) => {
316320 if ( ! container ) {
@@ -322,6 +326,7 @@ export function enableItem ({headerElement, classData, classBlockName, classBloc
322326 del = block ( `div` , `interactive normal icon delete` ) ;
323327 controls . appendChild ( add ) ;
324328 controls . appendChild ( del ) ;
329+
325330 add . addEventListener ( `mousedown` , ( ) => { // form the list of not present properties
326331 while ( add . firstChild )
327332 add . removeChild ( add . firstChild ) ;
@@ -348,11 +353,22 @@ export function enableItem ({headerElement, classData, classBlockName, classBloc
348353 propManifest : propManifest ,
349354 propName : propName ,
350355 propData : propManifest . default || "" ,
351- savePath : isClass
352- ? [ classData [ "Name" ] ]
353- : [ classData [ "Name" ] , classBlockName , classBlockPropName ]
356+ savePath : savePath
354357 } ) )
355358 } ) ;
359+
360+ let lastTimeDelClicked = 0 ;
361+ del . addEventListener ( `click` , e => e . stopPropagation ( ) ) ;
362+ del . addEventListener ( `click` , ( ) => {
363+ let delta = ( - lastTimeDelClicked + ( lastTimeDelClicked = ( new Date ( ) ) . getTime ( ) ) ) ;
364+ if ( delta > 5000 ) { // > 5 sec - show message "click again to delete"
365+ new Toast ( Toast . TYPE_INFO , `Click again to delete` ) ;
366+ } else { // delete
367+ addChange ( savePath . concat ( `$delete` ) , true ) ;
368+ detach ( headerElement ) ;
369+ detach ( container ) ;
370+ }
371+ } ) ;
356372 }
357373 if ( opened = ! opened ) {
358374 insertAfter ( container , headerElement ) ;
0 commit comments