|
|
@ -38,6 +38,7 @@ export const textWysiwyg = ({
|
|
|
|
onSubmit,
|
|
|
|
onSubmit,
|
|
|
|
getViewportCoords,
|
|
|
|
getViewportCoords,
|
|
|
|
element,
|
|
|
|
element,
|
|
|
|
|
|
|
|
canvas,
|
|
|
|
}: {
|
|
|
|
}: {
|
|
|
|
id: ExcalidrawElement["id"];
|
|
|
|
id: ExcalidrawElement["id"];
|
|
|
|
appState: AppState;
|
|
|
|
appState: AppState;
|
|
|
@ -45,6 +46,7 @@ export const textWysiwyg = ({
|
|
|
|
onSubmit: (text: string) => void;
|
|
|
|
onSubmit: (text: string) => void;
|
|
|
|
getViewportCoords: (x: number, y: number) => [number, number];
|
|
|
|
getViewportCoords: (x: number, y: number) => [number, number];
|
|
|
|
element: ExcalidrawElement;
|
|
|
|
element: ExcalidrawElement;
|
|
|
|
|
|
|
|
canvas: HTMLCanvasElement | null;
|
|
|
|
}) => {
|
|
|
|
}) => {
|
|
|
|
const updateWysiwygStyle = () => {
|
|
|
|
const updateWysiwygStyle = () => {
|
|
|
|
const updatedElement = Scene.getScene(element)?.getElement(id);
|
|
|
|
const updatedElement = Scene.getScene(element)?.getElement(id);
|
|
|
@ -151,6 +153,10 @@ export const textWysiwyg = ({
|
|
|
|
editable.oninput = null;
|
|
|
|
editable.oninput = null;
|
|
|
|
editable.onkeydown = null;
|
|
|
|
editable.onkeydown = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (observer) {
|
|
|
|
|
|
|
|
observer.disconnect();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
window.removeEventListener("resize", updateWysiwygStyle);
|
|
|
|
window.removeEventListener("resize", updateWysiwygStyle);
|
|
|
|
window.removeEventListener("wheel", stopEvent, true);
|
|
|
|
window.removeEventListener("wheel", stopEvent, true);
|
|
|
|
window.removeEventListener("pointerdown", onPointerDown);
|
|
|
|
window.removeEventListener("pointerdown", onPointerDown);
|
|
|
@ -197,9 +203,19 @@ export const textWysiwyg = ({
|
|
|
|
let isDestroyed = false;
|
|
|
|
let isDestroyed = false;
|
|
|
|
|
|
|
|
|
|
|
|
editable.onblur = handleSubmit;
|
|
|
|
editable.onblur = handleSubmit;
|
|
|
|
// reposition wysiwyg in case of window resize. Happens on mobile when
|
|
|
|
|
|
|
|
// device keyboard is opened.
|
|
|
|
// reposition wysiwyg in case of canvas is resized. Using ResizeObserver
|
|
|
|
|
|
|
|
// is preferred so we catch changes from host, where window may not resize.
|
|
|
|
|
|
|
|
let observer: ResizeObserver | null = null;
|
|
|
|
|
|
|
|
if (canvas && "ResizeObserver" in window) {
|
|
|
|
|
|
|
|
observer = new window.ResizeObserver(() => {
|
|
|
|
|
|
|
|
updateWysiwygStyle();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
observer.observe(canvas);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
window.addEventListener("resize", updateWysiwygStyle);
|
|
|
|
window.addEventListener("resize", updateWysiwygStyle);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
window.addEventListener("pointerdown", onPointerDown);
|
|
|
|
window.addEventListener("pointerdown", onPointerDown);
|
|
|
|
window.addEventListener("wheel", stopEvent, {
|
|
|
|
window.addEventListener("wheel", stopEvent, {
|
|
|
|
passive: false,
|
|
|
|
passive: false,
|
|
|
|