import { ActionSerialized } from './ActionSerialized' ; import { Action } from "./Action" ; import { MagnetManager } from './magnetManager' ; export class ActionMagnetNew extends Action { magnet : HTMLElement ; get xMax ( ) : number { return 0 ; } serializeData ( ) { return { type : "magnetnew" , pause : this . pause , userid : this . userid , magnet : this . magnet . outerHTML } ; } constructor ( userid , magnet ) { super ( userid ) ; this . magnet = < HTMLElement > magnet . cloneNode ( true ) ; this . magnet . onclick = magnet . onclick ; this . isDirectlyUndoable = true ; } createOverviewImage ( ) { return "url(img/icons/1F9F2.svg)" ; } param magnet description setMagnet ( magnet ) { this . magnet = < HTMLElement > magnet . cloneNode ( true ) ; this . magnet . onclick = magnet . onclick ; } async redo ( ) { const previousElement = document . getElementById ( this . magnet . id ) ; if ( previousElement ) { /**
             * if the element to add is already here with exactly the same properties, just do nothing
             * This is important for text magnet! Indeed, if the previousElement would have been removed and replaced,
             * then the text magnet would have lost the focus...
             */ if ( previousElement . isEqualNode ( this . magnet ) ) return ; previousElement . remove ( ) ; } this . _addMagnet ( this . magnet ) ; } param magnet description private _addMagnet ( magnet ) { const copyMagnet = < HTMLElement > magnet . cloneNode ( true ) ; copyMagnet . onclick = magnet . onclick ; document . getElementById ( "magnets" ) . appendChild ( copyMagnet ) ; MagnetManager . _installMagnet ( copyMagnet ) ; } async undo ( ) { const previousElement = document . getElementById ( this . magnet . id ) ; if ( previousElement ) previousElement . remove ( ) ; } }