Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
refactor(canvas): remove use of any
Elian Doranbb762cfab6fb
diff --git a/apps/client/src/widgets/type_widgets/canvas.ts b/apps/client/src/widgets/type_widgets/canvas.tsindex 9a0d6e34fd..8971ed6e2d 100644--- a/apps/client/src/widgets/type_widgets/canvas.ts+++ b/apps/client/src/widgets/type_widgets/canvas.ts@@ -2,9 +2,10 @@ import TypeWidget from "./type_widget.js";import server from "../../services/server.js";import type FNote from "../../entities/fnote.js";import options from "../../services/options.js";-import type { AppState, BinaryFileData, LibraryItem } from "@excalidraw/excalidraw/types";-import type { ExcalidrawElement, Theme } from "@excalidraw/excalidraw/element/types";+import type { LibraryItem } from "@excalidraw/excalidraw/types";+import type { Theme } from "@excalidraw/excalidraw/element/types";import type Canvas from "./canvas_el.js";+import { CanvasContent } from "./canvas_el.js";const TPL = /*html*/`<div class="canvas-widget note-detail-canvas note-detail-printable note-detail">@@ -46,11 +47,7 @@ const TPL = /*html*/`</div>`;-interface CanvasContent {- elements: ExcalidrawElement[];- files: BinaryFileData[];- appState: Partial<AppState>;-}+interface AttachmentMetadata {title: string;diff --git a/apps/client/src/widgets/type_widgets/canvas_el.ts b/apps/client/src/widgets/type_widgets/canvas_el.tsindex c90d4f035b..1af6d89408 100644--- a/apps/client/src/widgets/type_widgets/canvas_el.ts+++ b/apps/client/src/widgets/type_widgets/canvas_el.ts@@ -1,9 +1,15 @@import "@excalidraw/excalidraw/index.css";import { Excalidraw, getSceneVersion, exportToSvg } from "@excalidraw/excalidraw";import { createElement, render } from "preact/compat";-import { AppState, BinaryFileData, ExcalidrawImperativeAPI, ExcalidrawProps, LibraryItem, SceneData } from "@excalidraw/excalidraw/types";+import { AppState, BinaryFileData, ExcalidrawImperativeAPI, ExcalidrawProps, LibraryItem } from "@excalidraw/excalidraw/types";import type { ComponentType } from "preact";-import { Theme } from "@excalidraw/excalidraw/element/types";+import { ExcalidrawElement, NonDeletedExcalidrawElement, Theme } from "@excalidraw/excalidraw/element/types";++export interface CanvasContent {+ elements: ExcalidrawElement[];+ files: BinaryFileData[];+ appState: Partial<AppState>;+}/** Indicates that it is fresh. excalidraw scene version is always >0 */const SCENE_VERSION_INITIAL = -1;@@ -85,17 +91,11 @@ export default class Canvas {});}- loadData(content: any, theme: any) {+ loadData(content: CanvasContent, theme: Theme) {const { elements, files } = content;const appState: Partial<AppState> = content.appState ?? {};-appState.theme = theme;- const sceneData: SceneData = {- elements,- appState- };-// files are expected in an array when loading. they are stored as a key-index object// see example for loading here:// https://github.com/excalidraw/excalidraw/blob/c5a7723185f6ca05e0ceb0b0d45c4e3fbcb81b2a/src/packages/excalidraw/example/App.js#L68@@ -111,7 +111,10 @@ export default class Canvas {// Update the scene// TODO: Fix type of sceneData- this.excalidrawApi.updateScene(sceneData as any);+ this.excalidrawApi.updateScene({+ elements,+ appState: appState as AppState+ });this.excalidrawApi.addFiles(fileArray);this.excalidrawApi.history.clear();}@@ -135,8 +138,7 @@ export default class Canvas {const svgString = svg.outerHTML;const activeFiles: Record<string, BinaryFileData> = {};- // TODO: Used any where upstream typings appear to be broken.- elements.forEach((element: any) => {+ elements.forEach((element: NonDeletedExcalidrawElement) => {if ("fileId" in element && element.fileId) {activeFiles[element.fileId] = files[element.fileId];}