23
src/actions/actionAddToLibrary.ts
Normal file
23
src/actions/actionAddToLibrary.ts
Normal file
@ -0,0 +1,23 @@
|
||||
import { register } from "./register";
|
||||
import { getSelectedElements } from "../scene";
|
||||
import { getNonDeletedElements } from "../element";
|
||||
import { deepCopyElement } from "../element/newElement";
|
||||
import { loadLibrary, saveLibrary } from "../data/localStorage";
|
||||
|
||||
export const actionAddToLibrary = register({
|
||||
name: "addToLibrary",
|
||||
perform: (elements, appState) => {
|
||||
const selectedElements = getSelectedElements(
|
||||
getNonDeletedElements(elements),
|
||||
appState,
|
||||
);
|
||||
|
||||
loadLibrary().then((items) => {
|
||||
saveLibrary([...items, selectedElements.map(deepCopyElement)]);
|
||||
});
|
||||
|
||||
return false;
|
||||
},
|
||||
contextMenuOrder: 6,
|
||||
contextItemLabel: "labels.addToLibrary",
|
||||
});
|
@ -49,3 +49,5 @@ export {
|
||||
export { actionGroup, actionUngroup } from "./actionGroup";
|
||||
|
||||
export { actionGoToCollaborator } from "./actionNavigate";
|
||||
|
||||
export { actionAddToLibrary } from "./actionAddToLibrary";
|
||||
|
@ -62,7 +62,8 @@ export type ActionName =
|
||||
| "toggleShortcuts"
|
||||
| "group"
|
||||
| "ungroup"
|
||||
| "goToCollaborator";
|
||||
| "goToCollaborator"
|
||||
| "addToLibrary";
|
||||
|
||||
export interface Action {
|
||||
name: ActionName;
|
||||
|
Reference in New Issue
Block a user