37d513ad59
* feat: dnt share library & attach to the excalidraw instance * fix * Add addToLibrary, resetLibrary and libraryItems in initialData * remove comment * handle errors & improve types * remove resetLibrary and addToLibrary and add onLibraryChange prop * set library cache to empty arrary on reset * Add i18n for remove/add library * Update src/locales/en.json Co-authored-by: David Luzar <luzar.david@gmail.com> * update docs * Assign unique ID to each excalidraw component and remove csrfToken from library as its not needed * tweaks Co-authored-by: David Luzar <luzar.david@gmail.com> * update * tweak Co-authored-by: dwelle <luzar.david@gmail.com>
24 lines
657 B
TypeScript
24 lines
657 B
TypeScript
import { register } from "./register";
|
|
import { getSelectedElements } from "../scene";
|
|
import { getNonDeletedElements } from "../element";
|
|
import { deepCopyElement } from "../element/newElement";
|
|
|
|
export const actionAddToLibrary = register({
|
|
name: "addToLibrary",
|
|
perform: (elements, appState, _, app) => {
|
|
const selectedElements = getSelectedElements(
|
|
getNonDeletedElements(elements),
|
|
appState,
|
|
);
|
|
|
|
app.library.loadLibrary().then((items) => {
|
|
app.library.saveLibrary([
|
|
...items,
|
|
selectedElements.map(deepCopyElement),
|
|
]);
|
|
});
|
|
return false;
|
|
},
|
|
contextItemLabel: "labels.addToLibrary",
|
|
});
|