Skip to content

Instantly share code, notes, and snippets.

@davidkpiano
Created September 6, 2019 16:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save davidkpiano/ce04b90539f6d9a4aec2121f1212a0e7 to your computer and use it in GitHub Desktop.
Save davidkpiano/ce04b90539f6d9a4aec2121f1212a0e7 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const machine = Machine({
initial: "start",
context: {
selected: [],
x1: 0,
y1: 0,
x2: 0,
y2: 0,
drag: {
x1: 0,
y1: 0,
x2: 0,
y2: 0
},
grabIndex: undefined,
stretch: {},
centers: []
},
invoke: [{ src: 'mouseUp$' }, { src: 'mouseMove$' }, { src: 'dispose$' }],
states: {
start: {
invoke: {
src: 'mouseDown$'
},
on: {
mousedown: {
target: 'selecting',
actions: 'startSelection'
}
}
},
selecting: {
invoke: [{ src: 'mouseUp$' }, { src: 'mouseMove$' }],
on: {
mouseup: "selected",
mousemove: {
target: 'selecting',
actions: 'updateSelection'
}
}
},
selected: {
invoke: [{ src: 'mouseDown$' }, { src: 'mouseMove$' }],
on: {
mousedown: {
target: 'selecting',
actions: 'startSelection'
},
drag: {
target: 'dragging',
actions: 'startDrag'
}
}
},
dragging: {
on: {
mousemove: {
target: 'dragging',
actions: 'drag'
},
mouseup: [
{ target: "selected", cond: 'isNotTrashElement' },
{ target: "disposed", actions: 'showDaysRemoved' }
]
}
},
disposed: {
on: {
startGrab: {
target: 'grabbing',
actions: 'initGrab'
}
}
},
grabbing: {
on: {
mousemove: {
target: 'grabbing',
actions: 'updateGrab'
},
mouseup: {
target: 'disposed',
actions: 'resetGrab'
}
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment