|
|
@ -67,6 +67,7 @@ import {
|
|
|
|
resetCursor,
|
|
|
|
resetCursor,
|
|
|
|
viewportCoordsToSceneCoords,
|
|
|
|
viewportCoordsToSceneCoords,
|
|
|
|
sceneCoordsToViewportCoords,
|
|
|
|
sceneCoordsToViewportCoords,
|
|
|
|
|
|
|
|
setCursorForShape,
|
|
|
|
} from "../utils";
|
|
|
|
} from "../utils";
|
|
|
|
import { KEYS, isArrowKey } from "../keys";
|
|
|
|
import { KEYS, isArrowKey } from "../keys";
|
|
|
|
|
|
|
|
|
|
|
@ -146,15 +147,6 @@ const gesture: Gesture = {
|
|
|
|
initialScale: null,
|
|
|
|
initialScale: null,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
function setCursorForShape(shape: string) {
|
|
|
|
|
|
|
|
if (shape === "selection") {
|
|
|
|
|
|
|
|
resetCursor();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
document.documentElement.style.cursor =
|
|
|
|
|
|
|
|
shape === "text" ? CURSOR_TYPE.TEXT : CURSOR_TYPE.CROSSHAIR;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export class App extends React.Component<any, AppState> {
|
|
|
|
export class App extends React.Component<any, AppState> {
|
|
|
|
canvas: HTMLCanvasElement | null = null;
|
|
|
|
canvas: HTMLCanvasElement | null = null;
|
|
|
|
rc: RoughCanvas | null = null;
|
|
|
|
rc: RoughCanvas | null = null;
|
|
|
@ -1110,10 +1102,7 @@ export class App extends React.Component<any, AppState> {
|
|
|
|
if (this.state.elementType === "selection") {
|
|
|
|
if (this.state.elementType === "selection") {
|
|
|
|
resetCursor();
|
|
|
|
resetCursor();
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
document.documentElement.style.cursor =
|
|
|
|
setCursorForShape(this.state.elementType);
|
|
|
|
this.state.elementType === "text"
|
|
|
|
|
|
|
|
? CURSOR_TYPE.TEXT
|
|
|
|
|
|
|
|
: CURSOR_TYPE.CROSSHAIR;
|
|
|
|
|
|
|
|
this.setState({ selectedElementIds: {} });
|
|
|
|
this.setState({ selectedElementIds: {} });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
isHoldingSpace = false;
|
|
|
|
isHoldingSpace = false;
|
|
|
@ -1483,7 +1472,11 @@ export class App extends React.Component<any, AppState> {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const hasDeselectedButton = Boolean(event.buttons);
|
|
|
|
const hasDeselectedButton = Boolean(event.buttons);
|
|
|
|
if (hasDeselectedButton || this.state.elementType !== "selection") {
|
|
|
|
if (
|
|
|
|
|
|
|
|
hasDeselectedButton ||
|
|
|
|
|
|
|
|
(this.state.elementType !== "selection" &&
|
|
|
|
|
|
|
|
this.state.elementType !== "text")
|
|
|
|
|
|
|
|
) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -1513,8 +1506,14 @@ export class App extends React.Component<any, AppState> {
|
|
|
|
y,
|
|
|
|
y,
|
|
|
|
this.state.zoom,
|
|
|
|
this.state.zoom,
|
|
|
|
);
|
|
|
|
);
|
|
|
|
document.documentElement.style.cursor =
|
|
|
|
if (this.state.elementType === "text") {
|
|
|
|
hitElement && !isOverScrollBar ? "move" : "";
|
|
|
|
document.documentElement.style.cursor = isTextElement(hitElement)
|
|
|
|
|
|
|
|
? CURSOR_TYPE.TEXT
|
|
|
|
|
|
|
|
: CURSOR_TYPE.CROSSHAIR;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
document.documentElement.style.cursor =
|
|
|
|
|
|
|
|
hitElement && !isOverScrollBar ? "move" : "";
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
private handleCanvasPointerDown = (
|
|
|
|
private handleCanvasPointerDown = (
|
|
|
@ -1790,48 +1789,26 @@ export class App extends React.Component<any, AppState> {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const snappedToCenterPosition = event.altKey
|
|
|
|
const { x, y } = viewportCoordsToSceneCoords(
|
|
|
|
? null
|
|
|
|
event,
|
|
|
|
: this.getTextWysiwygSnappedToCenterPosition(
|
|
|
|
this.state,
|
|
|
|
x,
|
|
|
|
this.canvas,
|
|
|
|
y,
|
|
|
|
window.devicePixelRatio,
|
|
|
|
this.state,
|
|
|
|
);
|
|
|
|
this.canvas,
|
|
|
|
|
|
|
|
window.devicePixelRatio,
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const element = newTextElement({
|
|
|
|
this.startTextEditing({
|
|
|
|
x: snappedToCenterPosition?.elementCenterX ?? x,
|
|
|
|
x: x,
|
|
|
|
y: snappedToCenterPosition?.elementCenterY ?? y,
|
|
|
|
y: y,
|
|
|
|
strokeColor: this.state.currentItemStrokeColor,
|
|
|
|
clientX: event.clientX,
|
|
|
|
backgroundColor: this.state.currentItemBackgroundColor,
|
|
|
|
clientY: event.clientY,
|
|
|
|
fillStyle: this.state.currentItemFillStyle,
|
|
|
|
centerIfPossible: !event.altKey,
|
|
|
|
strokeWidth: this.state.currentItemStrokeWidth,
|
|
|
|
|
|
|
|
roughness: this.state.currentItemRoughness,
|
|
|
|
|
|
|
|
opacity: this.state.currentItemOpacity,
|
|
|
|
|
|
|
|
text: "",
|
|
|
|
|
|
|
|
font: this.state.currentItemFont,
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
globalSceneState.replaceAllElements([
|
|
|
|
|
|
|
|
...globalSceneState.getAllElements(),
|
|
|
|
|
|
|
|
element,
|
|
|
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.handleTextWysiwyg(element, {
|
|
|
|
|
|
|
|
x: snappedToCenterPosition?.wysiwygX ?? event.clientX,
|
|
|
|
|
|
|
|
y: snappedToCenterPosition?.wysiwygY ?? event.clientY,
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
resetCursor();
|
|
|
|
resetCursor();
|
|
|
|
if (!this.state.elementLocked) {
|
|
|
|
if (!this.state.elementLocked) {
|
|
|
|
this.setState({
|
|
|
|
this.setState({
|
|
|
|
editingElement: element,
|
|
|
|
|
|
|
|
elementType: "selection",
|
|
|
|
elementType: "selection",
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
|
|
|
|
this.setState({
|
|
|
|
|
|
|
|
editingElement: element,
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
} else if (
|
|
|
|
} else if (
|
|
|
|