UNPKG

@aurigma/design-atoms

Version:

Design Atoms is a part of Customer's Canvas SDK which allows for manipulating individual design elements through your code.

62 lines 3.92 kB
import { Exception } from "@aurigma/design-atoms-model/Exception"; import { EventObject } from "@aurigma/design-atoms-model/EventObject"; import { InputState } from "./../../../Input/InputManager/IInputManager"; var CreateInputHandlerStateMachine = /** @class */ (function () { function CreateInputHandlerStateMachine() { this._stateChanged = new EventObject(); this._currentState = CreateInputHandlerState.Initial; this._allowedTransitions = new Map([ [CreateInputHandlerState.Initial, [CreateInputHandlerState.PointSelected, CreateInputHandlerState.RectangleSelectionStarted]], [CreateInputHandlerState.RectangleSelectionStarted, [CreateInputHandlerState.RectangleSelected, CreateInputHandlerState.RectangleSelectionChanged]], [CreateInputHandlerState.RectangleSelectionChanged, [CreateInputHandlerState.RectangleSelected, CreateInputHandlerState.RectangleSelectionChanged]], [CreateInputHandlerState.RectangleSelected, [CreateInputHandlerState.Initial]], [CreateInputHandlerState.PointSelected, [CreateInputHandlerState.Initial]], ]); } CreateInputHandlerStateMachine.prototype.onMove = function (params) { switch (params.state) { case InputState.Started: this._changeState(CreateInputHandlerState.RectangleSelectionStarted, params.startWorkspace); this._changeState(CreateInputHandlerState.RectangleSelectionChanged, params.workspace); // TODO: It's strange decision, but there is no time to change logic. Need to refactor to new Input System break; case InputState.InProgress: this._changeState(CreateInputHandlerState.RectangleSelectionChanged, params.workspace); break; case InputState.Finished: this._changeState(CreateInputHandlerState.RectangleSelected, params.workspace); this._changeState(CreateInputHandlerState.Initial, params.workspace); break; } }; CreateInputHandlerStateMachine.prototype.onLongTap = function (params) { this._changeState(CreateInputHandlerState.PointSelected, params.workspace); this._changeState(CreateInputHandlerState.Initial, params.workspace); }; CreateInputHandlerStateMachine.prototype.onClick = function (params) { this._changeState(CreateInputHandlerState.PointSelected, params.workspace); this._changeState(CreateInputHandlerState.Initial, params.workspace); }; CreateInputHandlerStateMachine.prototype.addStateChanged = function (handler) { this._stateChanged.add(handler); }; CreateInputHandlerStateMachine.prototype.removeStateChanged = function (handler) { this._stateChanged.remove(handler); }; CreateInputHandlerStateMachine.prototype._changeState = function (state, point) { if (!this._allowedTransitions.get(this._currentState).includes(state)) throw new Exception(this._currentState + " to " + state + " transition is restricted"); this._currentState = state; this._stateChanged.notify({ state: state, point: point }); }; return CreateInputHandlerStateMachine; }()); export { CreateInputHandlerStateMachine }; export var CreateInputHandlerState; (function (CreateInputHandlerState) { CreateInputHandlerState["Initial"] = "Initial"; CreateInputHandlerState["PointSelected"] = "PointSelected"; CreateInputHandlerState["RectangleSelectionStarted"] = "RectangleSelectionStarted"; CreateInputHandlerState["RectangleSelectionChanged"] = "RectangleSelectionChanged"; CreateInputHandlerState["RectangleSelected"] = "RectangleSelected"; })(CreateInputHandlerState || (CreateInputHandlerState = {})); //# sourceMappingURL=CreateInputHandlerStateMachine.js.map