Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load from file #13

Merged
merged 4 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ yarn publish

## Change Log

### Alkemio fork of Excalidraw v0.17.0-alkemio-8
- Version bump to `0.17.1-alkemio-8`
- `addElementsFromPasteOrLibrary` exposed to the public API
- opening a file now inserts elements in the current scene. Does not overwrite them anymore.

### Alkemio fork of Excalidraw v0.17.0-alkemio-4
- Added `hideLibraryButton` to the appState to be able to hide the button from outside.
- Changed the toolbar Lock button behavior. Now it locks/unlocks elements instead of the tool in use
Expand Down
12 changes: 9 additions & 3 deletions packages/excalidraw/actions/actionExport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { Theme } from "../element/types";

import "../components/ToolIcon.scss";
import { StoreAction } from "../store";
import {reconcileElements, RemoteExcalidrawElement} from "../data/reconcile";

export const actionChangeProjectName = register({
name: "changeProjectName",
Expand Down Expand Up @@ -253,14 +254,19 @@ export const actionLoadScene = register({
try {
const {
elements: loadedElements,
appState: loadedAppState,
files,
} = await loadFromJSON(appState, elements);
return {

app.addElementsFromPasteOrLibrary({
elements: loadedElements,
appState: loadedAppState,
files,
position: "cursor",
fitToContent: true,
});

return {
storeAction: StoreAction.CAPTURE,
replaceFiles: false,
};
} catch (error: any) {
if (error?.name === "AbortError") {
Expand Down
1 change: 1 addition & 0 deletions packages/excalidraw/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,7 @@ class App extends React.Component<AppProps, AppState> {
setCursor: this.setCursor,
resetCursor: this.resetCursor,
updateFrameRendering: this.updateFrameRendering,
addElementsFromPasteOrLibrary: this.addElementsFromPasteOrLibrary,
toggleSidebar: this.toggleSidebar,
onChange: (cb) => this.onChangeEmitter.on(cb),
onPointerDown: (cb) => this.onPointerDownEmitter.on(cb),
Expand Down
2 changes: 1 addition & 1 deletion packages/excalidraw/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@
"loadFromFile": {
"title": "Load from file",
"button": "Load from file",
"description": "Loading from a file will <bold>replace your existing content</bold>.<br></br>You can back up your drawing first using one of the options below."
"description": "Loading from a file will <bold>insert content on top of your existing content</bold>.<br></br>You can back up your drawing first using one of the options below."
},
"shareableLink": {
"title": "Load from link",
Expand Down
2 changes: 1 addition & 1 deletion packages/excalidraw/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@alkemio/excalidraw",
"version": "0.17.1-alkemio-7",
"version": "0.17.1-alkemio-8",
"main": "./dist/prod/index.js",
"type": "module",
"module": "./dist/prod/index.js",
Expand Down
1 change: 1 addition & 0 deletions packages/excalidraw/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,7 @@ export interface ExcalidrawImperativeAPI {
* used in conjunction with view mode (props.viewModeEnabled).
*/
updateFrameRendering: InstanceType<typeof App>["updateFrameRendering"];
addElementsFromPasteOrLibrary: InstanceType<typeof App>["addElementsFromPasteOrLibrary"];
onChange: (
callback: (
elements: readonly ExcalidrawElement[],
Expand Down
Loading