excalidraw/src/actions/actionAddToLibrary.ts

25 lines
778 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";
2020-12-04 19:18:20 +02:00
import { EVENT_LIBRARY, trackEvent } from "../analytics";
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)]);
});
2020-12-04 19:18:20 +02:00
trackEvent(EVENT_LIBRARY, "add");
return false;
},
contextMenuOrder: 6,
contextItemLabel: "labels.addToLibrary",
});