mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-04 04:16:17 +01:00 
			
		
		
		
	fix(canvas): links not working on desktop (fixes #6606)
This commit is contained in:
		@@ -2,6 +2,8 @@ import "@excalidraw/excalidraw/index.css";
 | 
				
			|||||||
import { Excalidraw, getSceneVersion, exportToSvg } from "@excalidraw/excalidraw";
 | 
					import { Excalidraw, getSceneVersion, exportToSvg } from "@excalidraw/excalidraw";
 | 
				
			||||||
import { AppState, BinaryFileData, ExcalidrawImperativeAPI, ExcalidrawProps, LibraryItem } from "@excalidraw/excalidraw/types";
 | 
					import { AppState, BinaryFileData, ExcalidrawImperativeAPI, ExcalidrawProps, LibraryItem } from "@excalidraw/excalidraw/types";
 | 
				
			||||||
import { ExcalidrawElement, NonDeletedExcalidrawElement, Theme } from "@excalidraw/excalidraw/element/types";
 | 
					import { ExcalidrawElement, NonDeletedExcalidrawElement, Theme } from "@excalidraw/excalidraw/element/types";
 | 
				
			||||||
 | 
					import { useCallback } from "preact/hooks";
 | 
				
			||||||
 | 
					import linkService from "../../services/link.js";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export interface CanvasContent {
 | 
					export interface CanvasContent {
 | 
				
			||||||
    elements: ExcalidrawElement[];
 | 
					    elements: ExcalidrawElement[];
 | 
				
			||||||
@@ -32,17 +34,13 @@ export default class Canvas {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    createCanvasElement() {
 | 
					    createCanvasElement() {
 | 
				
			||||||
        return (
 | 
					        return <CanvasElement
 | 
				
			||||||
            <div className="excalidraw-wrapper">
 | 
					 | 
				
			||||||
                <Excalidraw
 | 
					 | 
				
			||||||
            {...this.opts}
 | 
					            {...this.opts}
 | 
				
			||||||
            excalidrawAPI={api => {
 | 
					            excalidrawAPI={api => {
 | 
				
			||||||
                this.excalidrawApi = api;
 | 
					                this.excalidrawApi = api;
 | 
				
			||||||
                this.initializedPromise.resolve();
 | 
					                this.initializedPromise.resolve();
 | 
				
			||||||
            }}
 | 
					            }}
 | 
				
			||||||
        />
 | 
					        />
 | 
				
			||||||
            </div>
 | 
					 | 
				
			||||||
        );
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
@@ -173,3 +171,27 @@ export default class Canvas {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function CanvasElement(opts: ExcalidrawProps) {
 | 
				
			||||||
 | 
					    return (
 | 
				
			||||||
 | 
					        <div className="excalidraw-wrapper">
 | 
				
			||||||
 | 
					            <Excalidraw
 | 
				
			||||||
 | 
					                {...opts}
 | 
				
			||||||
 | 
					                onLinkOpen={useCallback((element: NonDeletedExcalidrawElement, event: CustomEvent) => {
 | 
				
			||||||
 | 
					                    let link = element.link;
 | 
				
			||||||
 | 
					                    if (!link) {
 | 
				
			||||||
 | 
					                        return false;
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    if (link.startsWith("root/")) {
 | 
				
			||||||
 | 
					                        link = "#" + link;
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    const { nativeEvent } = event.detail;
 | 
				
			||||||
 | 
					                    event.preventDefault();
 | 
				
			||||||
 | 
					                    return linkService.goToLinkExt(nativeEvent, link, null);
 | 
				
			||||||
 | 
					                }, [])}
 | 
				
			||||||
 | 
					            />
 | 
				
			||||||
 | 
					        </div>
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user