mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
parent
7ab0c1aba8
commit
6428b59ccb
18 changed files with 599 additions and 20 deletions
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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue