import { Node } from '@/components/node' ; import { HistoryEventLevel , HistoryNodeEvent , HistoryDiagramEvent , HistoryDiagramBatchEvent , HistoryNodeOptionEvent , HistoryEvent , HistoryEventIcon , HistoryInteractionEvent , HistoryCompositeEvent , HistoryLogType , HistoryLog , } from '@/store/history/types' ; import { DiagramEventType } from '@/store/dataflow/types' ; import { ENVIRONMENT } from '@/common/env' ; export const diagramEvent = ( type , message , data , icon ? ) : HistoryDiagramEvent => { return { level : HistoryEventLevel . DIAGRAM , type , message , data , icon } ; } ; export const diagramBatchEvent = ( type , message , events , icon ? , data ? ) : HistoryDiagramBatchEvent => { return { level : HistoryEventLevel . DIAGRAM , type , message , events , data , icon } ; } ; export const nodeEvent = ( type , message , node , data , icon ? ) : HistoryNodeEvent => { return { level : HistoryEventLevel . NODE , type , message , nodeId : node . id , data , icon } ; } ; export const nodeOptionEvent = ( type , message , node , setter , value , prevValue , icon ? ) : HistoryNodeOptionEvent => { let defaultIconValue = 'fas fa-sliders-h' ; if ( ! icon ) { if ( type . match ( /select/ ) ) { defaultIconValue = 'fas fa-list' ; } else if ( type . match ( /input/ ) ) { defaultIconValue = 'fas fa-edit' ; } else if ( type . match ( /toggle/ ) ) { defaultIconValue = 'fas fa-toggle-on' ; } } const setterName = type ; if ( ENVIRONMENT === 'development' ) { const matchedSetterName = setter . name . match ( /^bound (.*)$/ ) ; if ( matchedSetterName === null ) { console . error ( `cannot parse setter name from ${ setter . name }` ) ; } else if ( matchedSetterName [ 1 ] !== setterName ) { console . error ( `matched setter name ${ matchedSetterName [ 1 ] } does not equal given setter name "${ setterName }"` ) ; } } return { level : HistoryEventLevel . NODE , type , message , nodeId : node . id , setter , setterName , data : { value , prevValue } , icon : icon || { value : defaultIconValue } } ; } ; export const interactionEvent = ( type , message , data , icon ? ) : HistoryInteractionEvent => { return { level : HistoryEventLevel . INTERACTION , type , message , data , icon } ; } ; export const compositeEvent = ( message , events , icon ? , data ? ) : HistoryCompositeEvent => { return { level : HistoryEventLevel . COMPOSITE , message , events , icon , data } ; } ; export const historyLog = ( type , data ) : HistoryLog => { return { type , data , timestamp : new Date ( ) . getTime ( ) } ; } ;