@@ -7,7 +7,7 @@ import { OnloadArgs } from "roamjs-components/types";
77import renderWithUnmount from "roamjs-components/util/renderWithUnmount" ;
88
99import {
10- Editor as TldrawApp ,
10+ Editor ,
1111 TLEditorComponents ,
1212 TLUiComponents ,
1313 TldrawEditor ,
@@ -92,11 +92,12 @@ import { getSetting } from "~/utils/extensionSettings";
9292import { isPluginTimerReady , waitForPluginTimer } from "~/utils/pluginTimer" ;
9393import { HistoryEntry } from "@tldraw/store" ;
9494import { TLRecord } from "@tldraw/tlschema" ;
95- import getCurrentUserDisplayName from "roamjs-components/queries/getCurrentUserDisplayName " ;
95+ import { WHITE_LOGO_SVG } from "~/icons " ;
9696
9797declare global {
98+ // eslint-disable-next-line @typescript-eslint/consistent-type-definitions
9899 interface Window {
99- tldrawApps : Record < string , TldrawApp > ;
100+ tldrawApps : Record < string , Editor > ;
100101 }
101102}
102103export type DiscourseContextType = {
@@ -119,13 +120,15 @@ export const DEFAULT_WIDTH = 160;
119120export const DEFAULT_HEIGHT = 64 ;
120121export const MAX_WIDTH = "400px" ;
121122
123+ const ICON_URL = `data:image/svg+xml;utf8,${ encodeURIComponent ( WHITE_LOGO_SVG ) } ` ;
124+
122125export const isPageUid = ( uid : string ) =>
123126 ! ! window . roamAlphaAPI . pull ( "[:node/title]" , [ ":block/uid" , uid ] ) ?. [
124127 ":node/title"
125128 ] ;
126129
127130const TldrawCanvas = ( { title } : { title : string } ) => {
128- const appRef = useRef < TldrawApp | null > ( null ) ;
131+ const appRef = useRef < Editor | null > ( null ) ;
129132 const lastInsertRef = useRef < VecModel > ( ) ;
130133 const containerRef = useRef < HTMLDivElement > ( null ) ;
131134 const lastActionsRef = useRef < HistoryEntry < TLRecord > [ ] > (
@@ -290,7 +293,7 @@ const TldrawCanvas = ({ title }: { title: string }) => {
290293 isCreating : false ,
291294 } ) ;
292295
293- const handleRelationCreation = ( app : TldrawApp , e : TLPointerEventInfo ) => {
296+ const handleRelationCreation = ( app : Editor , e : TLPointerEventInfo ) => {
294297 // Handle relation creation on pointer_down
295298 if ( e . type === "pointer" && e . name === "pointer_down" ) {
296299 const currentTool = app . getCurrentTool ( ) ;
@@ -334,8 +337,12 @@ const TldrawCanvas = ({ title }: { title: string }) => {
334337 const util = app . getShapeUtil ( relationShape ) ;
335338 if (
336339 util &&
340+ // TODO: fix this
341+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any
337342 typeof ( util as any ) . handleCreateRelationsInRoam === "function"
338343 ) {
344+ // TODO: fix this
345+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any
339346 ( util as any ) . handleCreateRelationsInRoam ( {
340347 arrow : relationShape ,
341348 targetId : shapeAtPoint . id ,
@@ -532,7 +539,7 @@ const TldrawCanvas = ({ title }: { title: string }) => {
532539 handleTldrawError as EventListener ,
533540 ) ;
534541 } ;
535- } , [ ] ) ;
542+ } , [ title ] ) ;
536543
537544 return (
538545 < div
@@ -552,8 +559,8 @@ const TldrawCanvas = ({ title }: { title: string }) => {
552559 < button
553560 className = "rounded bg-blue-500 px-4 py-2 font-bold text-white hover:bg-blue-700"
554561 onClick = { ( ) => {
555- const handleUpgrade = async ( ) => {
556- await performUpgrade ( ) ;
562+ const handleUpgrade = ( ) => {
563+ performUpgrade ( ) ;
557564 renderToast ( {
558565 id : "tldraw-upgrade" ,
559566 intent : "success" ,
@@ -675,13 +682,13 @@ const TldrawCanvas = ({ title }: { title: string }) => {
675682 < TldrawUi
676683 overrides = { uiOverrides }
677684 components = { customUiComponents }
678- assetUrls = { defaultEditorAssetUrls }
685+ assetUrls = { { icons : { discourseNodeIcon : ICON_URL } } }
679686 >
680687 < InsideEditorAndUiContext
681688 extensionAPI = { extensionAPI }
682689 allNodes = { allNodes }
683- allRelationIds = { allRelationIds }
684- allAddReferencedNodeActions = { allAddReferencedNodeActions }
690+ // allRelationIds={allRelationIds}
691+ // allAddReferencedNodeActions={allAddReferencedNodeActions}
685692 />
686693 < CanvasDrawerPanel />
687694 < ClipboardPanel />
@@ -699,41 +706,42 @@ const TldrawCanvas = ({ title }: { title: string }) => {
699706const InsideEditorAndUiContext = ( {
700707 extensionAPI,
701708 allNodes,
702- allRelationIds,
703- allAddReferencedNodeActions,
709+ // allRelationIds,
710+ // allAddReferencedNodeActions,
704711} : {
705712 extensionAPI : OnloadArgs [ "extensionAPI" ] ;
706713 allNodes : DiscourseNode [ ] ;
707- allRelationIds : string [ ] ;
708- allAddReferencedNodeActions : string [ ] ;
714+ // allRelationIds: string[];
715+ // allAddReferencedNodeActions: string[];
709716} ) => {
710717 const editor = useEditor ( ) ;
711718 const toasts = useToasts ( ) ;
712719 const msg = useTranslation ( ) ;
713720
714- // https://tldraw.dev/examples/data/assets/hosted-images
715- const ACCEPTED_IMG_TYPE = [
716- "image/jpeg" ,
717- "image/png" ,
718- "image/gif" ,
719- "image/svg+xml" ,
720- "image/webp" ,
721- ] ;
722- const isImage = ( ext : string ) => ACCEPTED_IMG_TYPE . includes ( ext ) ;
723- const isCustomArrowShape = ( shape : TLShape ) => {
724- // TODO: find a better way to identify custom arrow shapes
725- // possibly migrate to shape.type or shape.name
726- // or add as meta
727- const allRelationIdSet = new Set ( allRelationIds ) ;
728- const allAddReferencedNodeActionsSet = new Set ( allAddReferencedNodeActions ) ;
721+ // const isCustomArrowShape = (shape: TLShape) => {
722+ // // TODO: find a better way to identify custom arrow shapes
723+ // // possibly migrate to shape.type or shape.name
724+ // // or add as meta
725+ // const allRelationIdSet = new Set(allRelationIds);
726+ // const allAddReferencedNodeActionsSet = new Set(allAddReferencedNodeActions);
729727
730- return (
731- allRelationIdSet . has ( shape . type ) ||
732- allAddReferencedNodeActionsSet . has ( shape . type )
733- ) ;
734- } ;
728+ // return (
729+ // allRelationIdSet.has(shape.type) ||
730+ // allAddReferencedNodeActionsSet.has(shape.type)
731+ // );
732+ // };
735733
736734 useEffect ( ( ) => {
735+ // https://tldraw.dev/examples/data/assets/hosted-images
736+ const ACCEPTED_IMG_TYPE = [
737+ "image/jpeg" ,
738+ "image/png" ,
739+ "image/gif" ,
740+ "image/svg+xml" ,
741+ "image/webp" ,
742+ ] ;
743+ const isImage = ( ext : string ) => ACCEPTED_IMG_TYPE . includes ( ext ) ;
744+
737745 registerDefaultExternalContentHandlers (
738746 editor ,
739747 {
0 commit comments