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";
|
|
|
|
|
|
|
|
export const actionAddToLibrary = register({
|
|
|
|
name: "addToLibrary",
|
2021-04-21 23:38:24 +05:30
|
|
|
perform: (elements, appState, _, app) => {
|
2020-07-10 02:20:23 -07:00
|
|
|
const selectedElements = getSelectedElements(
|
|
|
|
getNonDeletedElements(elements),
|
|
|
|
appState,
|
|
|
|
);
|
|
|
|
|
2021-04-21 23:38:24 +05:30
|
|
|
app.library.loadLibrary().then((items) => {
|
|
|
|
app.library.saveLibrary([
|
|
|
|
...items,
|
|
|
|
selectedElements.map(deepCopyElement),
|
|
|
|
]);
|
2020-07-10 02:20:23 -07:00
|
|
|
});
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
contextItemLabel: "labels.addToLibrary",
|
|
|
|
});
|