Skip to content

Build your personal knowledge base with Trilium Notes

chore(react/type_widget): add more options to canvas

Elian Doran8c85aa343c7e
diff --git a/apps/client/src/widgets/type_widgets/Canvas.tsx b/apps/client/src/widgets/type_widgets/Canvas.tsx
index 0ed6cb7b7d..85d67b114b 100644
--- a/apps/client/src/widgets/type_widgets/Canvas.tsx
+++ b/apps/client/src/widgets/type_widgets/Canvas.tsx
@@ -2,18 +2,21 @@ import { Excalidraw } from "@excalidraw/excalidraw";
import { TypeWidgetProps } from "./type_widget";
import "@excalidraw/excalidraw/index.css";
import { useNoteBlob } from "../react/hooks";
-import { useEffect, useRef } from "preact/hooks";
-import type { ExcalidrawImperativeAPI, Theme } from "@excalidraw/excalidraw/types";
+import { useEffect, useMemo, useRef } from "preact/hooks";
+import type { ExcalidrawImperativeAPI, AppState } from "@excalidraw/excalidraw/types";
+import options from "../../services/options";
import "./Canvas.css";
export default function Canvas({ note }: TypeWidgetProps) {
const apiRef = useRef<ExcalidrawImperativeAPI>(null);
const blob = useNoteBlob(note);
-
- useEffect(() => {
+ const viewModeEnabled = options.is("databaseReadonly");
+ const themeStyle = useMemo(() => {
const documentStyle = window.getComputedStyle(document.documentElement);
- const themeStyle = documentStyle.getPropertyValue("--theme-style")?.trim() as Theme;
+ return documentStyle.getPropertyValue("--theme-style")?.trim() as AppState["theme"];
+ }, []);
+ useEffect(() => {
const api = apiRef.current;
const content = blob?.content;
if (!api) return;
@@ -33,6 +36,19 @@ export default function Canvas({ note }: TypeWidgetProps) {
<div className="excalidraw-wrapper">
<Excalidraw
excalidrawAPI={api => apiRef.current = api}
+ theme={themeStyle}
+ viewModeEnabled={viewModeEnabled}
+ zenModeEnabled={false}
+ isCollaborating={false}
+ detectScroll={false}
+ handleKeyboardGlobally={false}
+ autoFocus={false}
+ UIOptions={{
+ canvasActions: {
+ saveToActiveFile: false,
+ export: false
+ }
+ }}
/>
</div>
</div>
diff --git a/apps/client/src/widgets/type_widgets_old/canvas.ts b/apps/client/src/widgets/type_widgets_old/canvas.ts
index 4e72a776bc..b1b625412e 100644
--- a/apps/client/src/widgets/type_widgets_old/canvas.ts
+++ b/apps/client/src/widgets/type_widgets_old/canvas.ts
@@ -134,20 +134,7 @@ export default class ExcalidrawTypeWidget extends TypeWidget {
const Canvas = (await import("./canvas_el.js")).default;
this.canvasInstance = new Canvas({
// this makes sure that 1) manual theme switch button is hidden 2) theme stays as it should after opening menu
- theme: this.themeStyle,
onChange: () => this.onChangeHandler(),
- viewModeEnabled: options.is("databaseReadonly"),
- zenModeEnabled: false,
- isCollaborating: false,
- detectScroll: false,
- handleKeyboardGlobally: false,
- autoFocus: false,
- UIOptions: {
- canvasActions: {
- saveToActiveFile: false,
- export: false
- }
- },
onLibraryChange: () => {
this.libraryChanged = true;