mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
support embedding scene data to PNG/SVG (#2219)
Co-authored-by: Lipis <lipiridis@gmail.com>
This commit is contained in:
parent
7618ca48d7
commit
5950fa9a40
20 changed files with 329 additions and 27 deletions
|
@ -125,6 +125,7 @@ import {
|
|||
DEFAULT_VERTICAL_ALIGN,
|
||||
GRID_SIZE,
|
||||
LOCAL_STORAGE_KEY_COLLAB_FORCE_FLAG,
|
||||
MIME_TYPES,
|
||||
} from "../constants";
|
||||
import {
|
||||
INITIAL_SCENE_UPDATE_TIMEOUT,
|
||||
|
@ -3788,9 +3789,28 @@ class App extends React.Component<ExcalidrawProps, AppState> {
|
|||
private handleCanvasOnDrop = async (
|
||||
event: React.DragEvent<HTMLCanvasElement>,
|
||||
) => {
|
||||
const libraryShapes = event.dataTransfer.getData(
|
||||
"application/vnd.excalidrawlib+json",
|
||||
);
|
||||
try {
|
||||
const file = event.dataTransfer.files[0];
|
||||
if (file?.type === "image/png" || file?.type === "image/svg+xml") {
|
||||
const { elements, appState } = await loadFromBlob(file, this.state);
|
||||
this.syncActionResult({
|
||||
elements,
|
||||
appState: {
|
||||
...(appState || this.state),
|
||||
isLoading: false,
|
||||
},
|
||||
commitToHistory: true,
|
||||
});
|
||||
return;
|
||||
}
|
||||
} catch (error) {
|
||||
return this.setState({
|
||||
isLoading: false,
|
||||
errorMessage: error.message,
|
||||
});
|
||||
}
|
||||
|
||||
const libraryShapes = event.dataTransfer.getData(MIME_TYPES.excalidraw);
|
||||
if (libraryShapes !== "") {
|
||||
this.addElementsFromPasteOrLibrary(
|
||||
JSON.parse(libraryShapes),
|
||||
|
@ -3835,7 +3855,7 @@ class App extends React.Component<ExcalidrawProps, AppState> {
|
|||
this.setState({ isLoading: false, errorMessage: error.message });
|
||||
});
|
||||
} else if (
|
||||
file?.type === "application/vnd.excalidrawlib+json" ||
|
||||
file?.type === MIME_TYPES.excalidrawlib ||
|
||||
file?.name.endsWith(".excalidrawlib")
|
||||
) {
|
||||
Library.importLibrary(file)
|
||||
|
|
|
@ -156,6 +156,7 @@ const ExportModal = ({
|
|||
</Stack.Row>
|
||||
</div>
|
||||
{actionManager.renderAction("changeExportBackground")}
|
||||
{actionManager.renderAction("changeExportEmbedScene")}
|
||||
{someElementIsSelected && (
|
||||
<div>
|
||||
<label>
|
||||
|
|
|
@ -6,6 +6,7 @@ import "./LibraryUnit.scss";
|
|||
import { t } from "../i18n";
|
||||
import useIsMobile from "../is-mobile";
|
||||
import { LibraryItem } from "../types";
|
||||
import { MIME_TYPES } from "../constants";
|
||||
|
||||
// fa-plus
|
||||
const PLUS_ICON = (
|
||||
|
@ -78,7 +79,7 @@ export const LibraryUnit = ({
|
|||
onDragStart={(event) => {
|
||||
setIsHovered(false);
|
||||
event.dataTransfer.setData(
|
||||
"application/vnd.excalidrawlib+json",
|
||||
MIME_TYPES.excalidrawlib,
|
||||
JSON.stringify(elements),
|
||||
);
|
||||
}}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue