mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
Excalicharts MVP (#1723)
Co-authored-by: David Luzar <luzar.david@gmail.com>
This commit is contained in:
parent
d1be2a5481
commit
f7c4efbd35
4 changed files with 288 additions and 2 deletions
|
@ -5,6 +5,7 @@ import {
|
|||
import { getSelectedElements } from "./scene";
|
||||
import { AppState } from "./types";
|
||||
import { SVG_EXPORT_TAG } from "./scene/export";
|
||||
import { tryParseSpreadsheet, renderSpreadsheet } from "./charts";
|
||||
|
||||
let CLIPBOARD = "";
|
||||
let PREFER_APP_CLIPBOARD = false;
|
||||
|
@ -65,10 +66,14 @@ export const getAppClipboard = (): {
|
|||
};
|
||||
|
||||
export const getClipboardContent = async (
|
||||
appState: AppState,
|
||||
cursorX: number,
|
||||
cursorY: number,
|
||||
event: ClipboardEvent | null,
|
||||
): Promise<{
|
||||
text?: string;
|
||||
elements?: readonly ExcalidrawElement[];
|
||||
error?: string;
|
||||
}> => {
|
||||
try {
|
||||
const text = event
|
||||
|
@ -77,6 +82,19 @@ export const getClipboardContent = async (
|
|||
(await navigator.clipboard.readText());
|
||||
|
||||
if (text && !PREFER_APP_CLIPBOARD && !text.includes(SVG_EXPORT_TAG)) {
|
||||
const result = tryParseSpreadsheet(text);
|
||||
if (result.type === "spreadsheet") {
|
||||
return {
|
||||
elements: renderSpreadsheet(
|
||||
appState,
|
||||
result.spreadsheet,
|
||||
cursorX,
|
||||
cursorY,
|
||||
),
|
||||
};
|
||||
} else if (result.type === "malformed spreadsheet") {
|
||||
return { error: result.error };
|
||||
}
|
||||
return { text };
|
||||
}
|
||||
} catch (error) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue