2020-07-10 02:20:23 -07:00
|
|
|
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-07-10 02:20:23 -07:00
|
|
|
|
|
|
|
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-07-10 02:20:23 -07:00
|
|
|
});
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
contextMenuOrder: 6,
|
|
|
|
contextItemLabel: "labels.addToLibrary",
|
|
|
|
});
|