mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
Add new type excalidraw-api/clipboard for programmatic api
This commit is contained in:
parent
bb778892dc
commit
7a94ee3191
4 changed files with 12 additions and 1 deletions
|
@ -24,6 +24,7 @@ export interface ClipboardData {
|
||||||
files?: BinaryFiles;
|
files?: BinaryFiles;
|
||||||
text?: string;
|
text?: string;
|
||||||
errorMessage?: string;
|
errorMessage?: string;
|
||||||
|
programmaticAPI?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
let CLIPBOARD = "";
|
let CLIPBOARD = "";
|
||||||
|
@ -48,6 +49,7 @@ const clipboardContainsElements = (
|
||||||
[
|
[
|
||||||
EXPORT_DATA_TYPES.excalidraw,
|
EXPORT_DATA_TYPES.excalidraw,
|
||||||
EXPORT_DATA_TYPES.excalidrawClipboard,
|
EXPORT_DATA_TYPES.excalidrawClipboard,
|
||||||
|
EXPORT_DATA_TYPES.excalidrawClipboardWithAPI,
|
||||||
].includes(contents?.type) &&
|
].includes(contents?.type) &&
|
||||||
Array.isArray(contents.elements)
|
Array.isArray(contents.elements)
|
||||||
) {
|
) {
|
||||||
|
@ -191,6 +193,8 @@ export const parseClipboard = async (
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const systemClipboardData = JSON.parse(systemClipboard);
|
const systemClipboardData = JSON.parse(systemClipboard);
|
||||||
|
const programmaticAPI =
|
||||||
|
systemClipboardData.type === EXPORT_DATA_TYPES.excalidrawClipboardWithAPI;
|
||||||
if (clipboardContainsElements(systemClipboardData)) {
|
if (clipboardContainsElements(systemClipboardData)) {
|
||||||
return {
|
return {
|
||||||
elements: systemClipboardData.elements,
|
elements: systemClipboardData.elements,
|
||||||
|
@ -198,6 +202,7 @@ export const parseClipboard = async (
|
||||||
text: isPlainPaste
|
text: isPlainPaste
|
||||||
? JSON.stringify(systemClipboardData.elements, null, 2)
|
? JSON.stringify(systemClipboardData.elements, null, 2)
|
||||||
: undefined,
|
: undefined,
|
||||||
|
programmaticAPI,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
|
|
|
@ -330,6 +330,7 @@ import { activeConfirmDialogAtom } from "./ActiveConfirmDialog";
|
||||||
import { actionWrapTextInContainer } from "../actions/actionBoundText";
|
import { actionWrapTextInContainer } from "../actions/actionBoundText";
|
||||||
import BraveMeasureTextError from "./BraveMeasureTextError";
|
import BraveMeasureTextError from "./BraveMeasureTextError";
|
||||||
import { activeEyeDropperAtom } from "./EyeDropper";
|
import { activeEyeDropperAtom } from "./EyeDropper";
|
||||||
|
import { convertToExcalidrawElements } from "../data/transform";
|
||||||
|
|
||||||
const AppContext = React.createContext<AppClassProperties>(null!);
|
const AppContext = React.createContext<AppClassProperties>(null!);
|
||||||
const AppPropsContext = React.createContext<AppProps>(null!);
|
const AppPropsContext = React.createContext<AppProps>(null!);
|
||||||
|
@ -1933,9 +1934,12 @@ class App extends React.Component<AppProps, AppState> {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
} else if (data.elements) {
|
} else if (data.elements) {
|
||||||
|
const elements = data.programmaticAPI
|
||||||
|
? convertToExcalidrawElements(data.elements)
|
||||||
|
: data.elements;
|
||||||
// TODO remove formatting from elements if isPlainPaste
|
// TODO remove formatting from elements if isPlainPaste
|
||||||
this.addElementsFromPasteOrLibrary({
|
this.addElementsFromPasteOrLibrary({
|
||||||
elements: data.elements,
|
elements,
|
||||||
files: data.files || null,
|
files: data.files || null,
|
||||||
position: "cursor",
|
position: "cursor",
|
||||||
retainSeed: isPlainPaste,
|
retainSeed: isPlainPaste,
|
||||||
|
|
|
@ -153,6 +153,7 @@ export const EXPORT_DATA_TYPES = {
|
||||||
excalidraw: "excalidraw",
|
excalidraw: "excalidraw",
|
||||||
excalidrawClipboard: "excalidraw/clipboard",
|
excalidrawClipboard: "excalidraw/clipboard",
|
||||||
excalidrawLibrary: "excalidrawlib",
|
excalidrawLibrary: "excalidrawlib",
|
||||||
|
excalidrawClipboardWithAPI: "excalidraw-api/clipboard",
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
export const EXPORT_SOURCE =
|
export const EXPORT_SOURCE =
|
||||||
|
|
|
@ -136,6 +136,7 @@ export interface ExcalidrawProgrammaticAPI {
|
||||||
| ExcalidrawSelectionElement
|
| ExcalidrawSelectionElement
|
||||||
| ExcalidrawImageElement
|
| ExcalidrawImageElement
|
||||||
| ExcalidrawFreeDrawElement
|
| ExcalidrawFreeDrawElement
|
||||||
|
| ExcalidrawFrameElement
|
||||||
>
|
>
|
||||||
| ({
|
| ({
|
||||||
type: Extract<ExcalidrawLinearElement["type"], "line">;
|
type: Extract<ExcalidrawLinearElement["type"], "line">;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue