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",
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue