chore(canvas): missing API endpoint

This commit is contained in:
Elian Doran 2025-06-10 22:50:39 +03:00
parent 3e0f420eec
commit 5ad3d7d077
No known key found for this signature in database
2 changed files with 11 additions and 7 deletions

View File

@ -3,6 +3,7 @@ import utils from "../../services/utils.js";
import server from "../../services/server.js"; import server from "../../services/server.js";
import type FNote from "../../entities/fnote.js"; import type FNote from "../../entities/fnote.js";
import options from "../../services/options.js"; import options from "../../services/options.js";
import { ExcalidrawImperativeAPI } from "@excalidraw/excalidraw/types";
const TPL = /*html*/` const TPL = /*html*/`
<div class="canvas-widget note-detail-canvas note-detail-printable note-detail"> <div class="canvas-widget note-detail-canvas note-detail-printable note-detail">
@ -184,7 +185,11 @@ export default class ExcalidrawTypeWidget extends TypeWidget {
(window.process.env as any).PREACT = false; (window.process.env as any).PREACT = false;
const renderCanvas = (await import("./canvas_el.js")).default; const renderCanvas = (await import("./canvas_el.js")).default;
renderCanvas(renderElement); renderCanvas(renderElement, {
excalidrawAPI: (api: ExcalidrawImperativeAPI) => {
this.excalidrawApi = api;
},
});
} }
/** /**

View File

@ -1,12 +1,13 @@
import "@excalidraw/excalidraw/index.css"; import "@excalidraw/excalidraw/index.css";
import { Excalidraw } from "@excalidraw/excalidraw"; import { Excalidraw } from "@excalidraw/excalidraw";
import { createElement, createRef, Fragment, render } from "preact/compat"; import { createElement, createRef, Fragment, render } from "preact/compat";
import { ExcalidrawProps } from "@excalidraw/excalidraw/types";
export default function renderCanvas(targetEl: HTMLElement) { export default function renderCanvas(targetEl: HTMLElement, opts: ExcalidrawProps) {
render(createCanvasElement(), targetEl); render(createCanvasElement(opts), targetEl);
} }
function createCanvasElement() { function createCanvasElement(opts: ExcalidrawProps) {
const excalidrawWrapperRef = createRef<HTMLElement>(); const excalidrawWrapperRef = createRef<HTMLElement>();
return createElement(Fragment, null, return createElement(Fragment, null,
@ -16,8 +17,6 @@ function createCanvasElement() {
className: "excalidraw-wrapper", className: "excalidraw-wrapper",
ref: excalidrawWrapperRef ref: excalidrawWrapperRef
}, },
createElement(Excalidraw, { createElement(Excalidraw, opts)
})
)); ));
} }