import { assign, Machine, createMachine, interpret } from 'xstate'; import { EditContext, EditSchema, EditEvent } from '../index.data'; import { actions, guards } from './helper'; /** * @param defaultContext 缺省的context, 目前仅用于测试时预设 context 值 */ function getMachine(defaultContext = {}) { return Machine({ id: 'row-picker-machine', context: { usage: 'row-picker', ...defaultContext } as EditContext, initial: 'idle', states: { idle: { on: { 'MOUSE.DOWN': { target: 'selecting.row', actions: actions.reSelect, }, }, }, selecting: { states: { cell: {}, column: {}, row: { on: { 'MOUSE.DOWN': { cond: guards.hasSelected, actions: actions.reSelect, }, 'MOUSE.MOVE': { cond: guards.hasSelected, actions: actions.appendSelect, }, 'MOUSE.UP': { cond: guards.hasSelected, actions: actions.appendSelect, }, }, }, }, }, editing: {}, }, }); } export default getMachine;