prevent pasting svg copied from excalidraw (#1288)
* prevent pasting svg copied from excalidraw * remove unnecessary template
This commit is contained in:
parent
e9b4700bba
commit
729aeacc47
@ -1,6 +1,7 @@
|
|||||||
import { ExcalidrawElement } from "./element/types";
|
import { ExcalidrawElement } from "./element/types";
|
||||||
import { getSelectedElements } from "./scene";
|
import { getSelectedElements } from "./scene";
|
||||||
import { AppState } from "./types";
|
import { AppState } from "./types";
|
||||||
|
import { SVG_EXPORT_TAG } from "./scene/export";
|
||||||
|
|
||||||
let CLIPBOARD = "";
|
let CLIPBOARD = "";
|
||||||
let PREFER_APP_CLIPBOARD = false;
|
let PREFER_APP_CLIPBOARD = false;
|
||||||
@ -39,6 +40,10 @@ export async function copyToAppClipboard(
|
|||||||
export function getAppClipboard(): {
|
export function getAppClipboard(): {
|
||||||
elements?: readonly ExcalidrawElement[];
|
elements?: readonly ExcalidrawElement[];
|
||||||
} {
|
} {
|
||||||
|
if (!CLIPBOARD) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const clipboardElements = JSON.parse(CLIPBOARD);
|
const clipboardElements = JSON.parse(CLIPBOARD);
|
||||||
|
|
||||||
@ -68,7 +73,7 @@ export async function getClipboardContent(
|
|||||||
: probablySupportsClipboardReadText &&
|
: probablySupportsClipboardReadText &&
|
||||||
(await navigator.clipboard.readText());
|
(await navigator.clipboard.readText());
|
||||||
|
|
||||||
if (text && !PREFER_APP_CLIPBOARD) {
|
if (text && !PREFER_APP_CLIPBOARD && !text.includes(SVG_EXPORT_TAG)) {
|
||||||
return { text };
|
return { text };
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -6,6 +6,8 @@ import { distance, SVG_NS } from "../utils";
|
|||||||
import { normalizeScroll } from "./scroll";
|
import { normalizeScroll } from "./scroll";
|
||||||
import { AppState } from "../types";
|
import { AppState } from "../types";
|
||||||
|
|
||||||
|
export const SVG_EXPORT_TAG = `<!-- svg-source:excalidraw -->`;
|
||||||
|
|
||||||
export function exportToCanvas(
|
export function exportToCanvas(
|
||||||
elements: readonly ExcalidrawElement[],
|
elements: readonly ExcalidrawElement[],
|
||||||
appState: AppState,
|
appState: AppState,
|
||||||
@ -86,6 +88,7 @@ export function exportToSvg(
|
|||||||
svgRoot.setAttribute("viewBox", `0 0 ${width} ${height}`);
|
svgRoot.setAttribute("viewBox", `0 0 ${width} ${height}`);
|
||||||
|
|
||||||
svgRoot.innerHTML = `
|
svgRoot.innerHTML = `
|
||||||
|
${SVG_EXPORT_TAG}
|
||||||
<defs>
|
<defs>
|
||||||
<style>
|
<style>
|
||||||
@font-face {
|
@font-face {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user