2020-02-01 15:49:18 +04:00
|
|
|
import { Action } from "./types";
|
|
|
|
import { KEYS } from "../keys";
|
|
|
|
import { clearSelection } from "../scene";
|
2020-02-05 22:47:10 +04:00
|
|
|
import { isInvisiblySmallElement } from "../element";
|
2020-02-01 15:49:18 +04:00
|
|
|
|
|
|
|
export const actionFinalize: Action = {
|
|
|
|
name: "finalize",
|
|
|
|
perform: (elements, appState) => {
|
2020-02-05 22:47:10 +04:00
|
|
|
let newElements = clearSelection(elements);
|
2020-02-01 15:49:18 +04:00
|
|
|
if (window.document.activeElement instanceof HTMLElement) {
|
|
|
|
window.document.activeElement.blur();
|
|
|
|
}
|
2020-02-04 17:39:08 +04:00
|
|
|
if (appState.multiElement) {
|
|
|
|
appState.multiElement.points = appState.multiElement.points.slice(
|
|
|
|
0,
|
|
|
|
appState.multiElement.points.length - 1,
|
|
|
|
);
|
2020-02-05 22:47:10 +04:00
|
|
|
if (isInvisiblySmallElement(appState.multiElement)) {
|
|
|
|
newElements = newElements.slice(0, -1);
|
|
|
|
}
|
2020-02-04 17:39:08 +04:00
|
|
|
appState.multiElement.shape = null;
|
|
|
|
}
|
2020-02-01 15:49:18 +04:00
|
|
|
return {
|
2020-02-05 22:47:10 +04:00
|
|
|
elements: newElements,
|
2020-02-01 15:49:18 +04:00
|
|
|
appState: {
|
|
|
|
...appState,
|
|
|
|
elementType: "selection",
|
|
|
|
draggingElement: null,
|
|
|
|
multiElement: null,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
|
|
|
keyTest: (event, appState) =>
|
|
|
|
(event.key === KEYS.ESCAPE &&
|
|
|
|
!appState.draggingElement &&
|
|
|
|
appState.multiElement === null) ||
|
|
|
|
((event.key === KEYS.ESCAPE || event.key === KEYS.ENTER) &&
|
|
|
|
appState.multiElement !== null),
|
|
|
|
};
|