This reverts commit abbc04df0e5a3b9265ada12a73bc9b8a810a329c.
This commit is contained in:
parent
db973c61e8
commit
f2665408fc
@ -13,4 +13,3 @@ export { hitTest } from "./collision";
|
|||||||
export { resizeTest } from "./resizeTest";
|
export { resizeTest } from "./resizeTest";
|
||||||
export { generateDraw } from "./generateDraw";
|
export { generateDraw } from "./generateDraw";
|
||||||
export { isTextElement } from "./typeChecks";
|
export { isTextElement } from "./typeChecks";
|
||||||
export { textWysiwyg } from "./textWysiwyg";
|
|
||||||
|
@ -1,54 +0,0 @@
|
|||||||
import { KEYS } from "../index";
|
|
||||||
|
|
||||||
export function textWysiwyg(
|
|
||||||
x: number,
|
|
||||||
y: number,
|
|
||||||
onSubmit: (text: string) => void
|
|
||||||
) {
|
|
||||||
const input = document.createElement("input");
|
|
||||||
|
|
||||||
Object.assign(input.style, {
|
|
||||||
position: "absolute",
|
|
||||||
top: y - 8 + "px",
|
|
||||||
left: x + "px",
|
|
||||||
transform: "translate(-50%, -50%)",
|
|
||||||
boxShadow: "none",
|
|
||||||
textAlign: "center",
|
|
||||||
width: (window.innerWidth - x) * 2 + "px",
|
|
||||||
fontSize: "20px",
|
|
||||||
fontFamily: "Virgil",
|
|
||||||
border: "none",
|
|
||||||
background: "transparent"
|
|
||||||
});
|
|
||||||
|
|
||||||
input.onkeydown = ev => {
|
|
||||||
if (ev.key === KEYS.ESCAPE) {
|
|
||||||
cleanup();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (ev.key === KEYS.ENTER) {
|
|
||||||
handleSubmit();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
input.onblur = handleSubmit;
|
|
||||||
|
|
||||||
function stopEvent(ev: Event) {
|
|
||||||
ev.stopPropagation();
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleSubmit() {
|
|
||||||
if (input.value) {
|
|
||||||
onSubmit(input.value);
|
|
||||||
}
|
|
||||||
cleanup();
|
|
||||||
}
|
|
||||||
|
|
||||||
function cleanup() {
|
|
||||||
window.removeEventListener("wheel", stopEvent, true);
|
|
||||||
document.body.removeChild(input);
|
|
||||||
}
|
|
||||||
|
|
||||||
window.addEventListener("wheel", stopEvent, true);
|
|
||||||
document.body.appendChild(input);
|
|
||||||
input.focus();
|
|
||||||
}
|
|
@ -4,13 +4,7 @@ import rough from "roughjs/bin/wrappers/rough";
|
|||||||
|
|
||||||
import { moveOneLeft, moveAllLeft, moveOneRight, moveAllRight } from "./zindex";
|
import { moveOneLeft, moveAllLeft, moveOneRight, moveAllRight } from "./zindex";
|
||||||
import { randomSeed } from "./random";
|
import { randomSeed } from "./random";
|
||||||
import {
|
import { newElement, resizeTest, generateDraw, isTextElement } from "./element";
|
||||||
newElement,
|
|
||||||
resizeTest,
|
|
||||||
generateDraw,
|
|
||||||
isTextElement,
|
|
||||||
textWysiwyg
|
|
||||||
} from "./element";
|
|
||||||
import {
|
import {
|
||||||
renderScene,
|
renderScene,
|
||||||
clearSelection,
|
clearSelection,
|
||||||
@ -54,13 +48,12 @@ const DEFAULT_PROJECT_NAME = `excalidraw-${getDateTime()}`;
|
|||||||
const CANVAS_WINDOW_OFFSET_LEFT = 250;
|
const CANVAS_WINDOW_OFFSET_LEFT = 250;
|
||||||
const CANVAS_WINDOW_OFFSET_TOP = 0;
|
const CANVAS_WINDOW_OFFSET_TOP = 0;
|
||||||
|
|
||||||
export const KEYS = {
|
const KEYS = {
|
||||||
ARROW_LEFT: "ArrowLeft",
|
ARROW_LEFT: "ArrowLeft",
|
||||||
ARROW_RIGHT: "ArrowRight",
|
ARROW_RIGHT: "ArrowRight",
|
||||||
ARROW_DOWN: "ArrowDown",
|
ARROW_DOWN: "ArrowDown",
|
||||||
ARROW_UP: "ArrowUp",
|
ARROW_UP: "ArrowUp",
|
||||||
ESCAPE: "Escape",
|
ESCAPE: "Escape",
|
||||||
ENTER: "Enter",
|
|
||||||
DELETE: "Delete",
|
DELETE: "Delete",
|
||||||
BACKSPACE: "Backspace"
|
BACKSPACE: "Backspace"
|
||||||
};
|
};
|
||||||
@ -84,8 +77,9 @@ function resetCursor() {
|
|||||||
document.documentElement.style.cursor = "";
|
document.documentElement.style.cursor = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
function addTextElement(element: ExcalidrawTextElement, text = "") {
|
function addTextElement(element: ExcalidrawTextElement) {
|
||||||
resetCursor();
|
resetCursor();
|
||||||
|
const text = prompt("What text do you want?");
|
||||||
if (text === null || text === "") {
|
if (text === null || text === "") {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -737,23 +731,22 @@ class App extends React.Component<{}, AppState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isTextElement(element)) {
|
if (isTextElement(element)) {
|
||||||
textWysiwyg(e.clientX, e.clientY, text => {
|
if (!addTextElement(element)) {
|
||||||
addTextElement(element, text);
|
|
||||||
generateDraw(element);
|
|
||||||
elements.push(element);
|
|
||||||
element.isSelected = true;
|
|
||||||
|
|
||||||
this.setState({
|
|
||||||
draggingElement: null,
|
|
||||||
elementType: "selection"
|
|
||||||
});
|
|
||||||
});
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
generateDraw(element);
|
generateDraw(element);
|
||||||
elements.push(element);
|
elements.push(element);
|
||||||
|
if (this.state.elementType === "text") {
|
||||||
|
this.setState({
|
||||||
|
draggingElement: null,
|
||||||
|
elementType: "selection"
|
||||||
|
});
|
||||||
|
element.isSelected = true;
|
||||||
|
} else {
|
||||||
this.setState({ draggingElement: element });
|
this.setState({ draggingElement: element });
|
||||||
|
}
|
||||||
|
|
||||||
let lastX = x;
|
let lastX = x;
|
||||||
let lastY = y;
|
let lastY = y;
|
||||||
@ -974,17 +967,20 @@ class App extends React.Component<{}, AppState> {
|
|||||||
100
|
100
|
||||||
);
|
);
|
||||||
|
|
||||||
textWysiwyg(e.clientX, e.clientY, text => {
|
if (!addTextElement(element as ExcalidrawTextElement)) {
|
||||||
addTextElement(element as ExcalidrawTextElement, text);
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
generateDraw(element);
|
generateDraw(element);
|
||||||
elements.push(element);
|
elements.push(element);
|
||||||
element.isSelected = true;
|
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
draggingElement: null,
|
draggingElement: null,
|
||||||
elementType: "selection"
|
elementType: "selection"
|
||||||
});
|
});
|
||||||
});
|
element.isSelected = true;
|
||||||
|
|
||||||
|
this.forceUpdate();
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user