excalidraw/src/actions/actionDeleteSelected.tsx
Pete Hunt df0613d8ac
Add NonDeleted<ExcalidrawElement> (#1068)
* add NonDeleted

* make test:all script run tests without prompt

* rename helper

* replace with helper

* make element contructors return nonDeleted elements

* cache filtered elements where appliacable for better perf

* rename manager element getter

* remove unnecessary assertion

* fix test

* make element types in resizeElement into nonDeleted

Co-authored-by: dwelle <luzar.david@gmail.com>
2020-04-08 18:49:52 +02:00

44 lines
1.3 KiB
TypeScript

import { deleteSelectedElements, isSomeElementSelected } from "../scene";
import { KEYS } from "../keys";
import { ToolButton } from "../components/ToolButton";
import React from "react";
import { trash } from "../components/icons";
import { t } from "../i18n";
import { register } from "./register";
import { getNonDeletedElements } from "../element";
export const actionDeleteSelected = register({
name: "deleteSelectedElements",
perform: (elements, appState) => {
const {
elements: nextElements,
appState: nextAppState,
} = deleteSelectedElements(elements, appState);
return {
elements: nextElements,
appState: {
...nextAppState,
elementType: "selection",
multiElement: null,
},
commitToHistory: isSomeElementSelected(
getNonDeletedElements(elements),
appState,
),
};
},
contextItemLabel: "labels.delete",
contextMenuOrder: 3,
keyTest: (event) => event.key === KEYS.BACKSPACE || event.key === KEYS.DELETE,
PanelComponent: ({ elements, appState, updateData }) => (
<ToolButton
type="button"
icon={trash}
title={t("labels.delete")}
aria-label={t("labels.delete")}
onClick={() => updateData(null)}
visible={isSomeElementSelected(getNonDeletedElements(elements), appState)}
/>
),
});