Skip to content

Instantly share code, notes, and snippets.

@timdeschryver
Last active October 11, 2019 12:02
Show Gist options
  • Select an option

  • Save timdeschryver/f8ded4c4d9d89096ec6a346d57005d15 to your computer and use it in GitHub Desktop.

Select an option

Save timdeschryver/f8ded4c4d9d89096ec6a346d57005d15 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const dragMachine = Machine(
{
key: 'ngx-drag-to-select',
initial: 'clickMode',
context: {
shortcuts: {},
selectWithShortcut: false,
x1: 0,
y1: 0,
x2: 0,
y2: 0,
selectedDirectiveIds: []
},
states: {
clickMode: {
on: {
click: [
{
actions: ['clickItemAppend'],
cond: 'appendItem'
},
{
actions: ['clickItem']
}
]
}
},
dragMode: {
initial: 'idle',
states: {
idle: {
on: {
mousedown: {
target: 'dragging',
actions: ['clearSelection', 'startDrag']
}
}
},
dragging: {
on: {
mousemove: {
actions: ['drag', 'drawSelectbox', 'updateSelectedItems']
},
mouseup: { target: 'idle', actions: ['resetDrag', 'drawSelectbox'] }
}
}
}
},
selectMode: {
on: {
click: {
actions: ['clickItemAppend']
}
}
},
shortcutMode: {
on: {
click: {
actions: ['clickItemAppend'],
cond: 'isShortcutPressed'
}
}
},
disabled: {}
},
on: {
toggleDragMode: 'dragMode',
toggleSelectMode: 'selectMode',
toggleClickMode: 'clickMode',
toggleSelectWithShortcut: 'shortcutMode',
toggleDisabledMode: 'disabled',
selectItems: {
actions: 'selectItems'
},
clearAll: {
actions: 'clearAll'
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment