excalidraw/src/actions/actionAddToLibrary.ts

23 lines
682 B
TypeScript
Raw Normal View History

import { register } from "./register";
import { getSelectedElements } from "../scene";
import { getNonDeletedElements } from "../element";
import { deepCopyElement } from "../element/newElement";
2020-10-30 21:01:41 +01:00
import { Library } from "../data/library";
export const actionAddToLibrary = register({
name: "addToLibrary",
perform: (elements, appState) => {
const selectedElements = getSelectedElements(
getNonDeletedElements(elements),
appState,
);
2020-10-30 21:01:41 +01:00
Library.loadLibrary().then((items) => {
Library.saveLibrary([...items, selectedElements.map(deepCopyElement)]);
});
return false;
},
contextMenuOrder: 6,
contextItemLabel: "labels.addToLibrary",
});