@@ -52,9 +52,6 @@ import {
5252 StateNode ,
5353 DefaultSpinner ,
5454 Box ,
55- MigrationSequence ,
56- TLAnyBindingUtilConstructor ,
57- TLAnyShapeUtilConstructor ,
5855} from "tldraw" ;
5956import "tldraw/tldraw.css" ;
6057import tldrawStyles from "./tldrawStyles" ;
@@ -71,7 +68,6 @@ import {
7168 BaseDiscourseNodeUtil ,
7269 DiscourseNodeShape ,
7370 createNodeShapeTools ,
74- createNodeShapeUtils ,
7571} from "./DiscourseNodeUtil" ;
7672import { useRoamStore } from "./useRoamStore" ;
7773import {
@@ -87,21 +83,12 @@ import isLiveBlock from "roamjs-components/queries/isLiveBlock";
8783import openBlockInSidebar from "roamjs-components/writes/openBlockInSidebar" ;
8884import getPageTitleByPageUid from "roamjs-components/queries/getPageTitleByPageUid" ;
8985import renderToast from "roamjs-components/components/Toast" ;
90- import {
91- createAllReferencedNodeUtils ,
92- createAllRelationShapeUtils ,
93- } from "./DiscourseRelationShape/DiscourseRelationUtil" ;
9486import {
9587 AddReferencedNodeType ,
9688 createAllReferencedNodeTools ,
9789 createAllRelationShapeTools ,
9890} from "./DiscourseRelationShape/DiscourseRelationTool" ;
99- import {
100- createAllReferencedNodeBindings ,
101- createAllRelationBindings ,
102- } from "./DiscourseRelationShape/DiscourseRelationBindings" ;
10391import ConvertToDialog from "./ConvertToDialog" ;
104- import { createMigrations } from "./DiscourseRelationShape/discourseRelationMigrations" ;
10592import ToastListener , { dispatchToastEvent } from "./ToastListener" ;
10693import { CanvasDrawerPanel } from "./CanvasDrawer" ;
10794import { ClipboardPanel , ClipboardProvider } from "./Clipboard" ;
@@ -121,6 +108,10 @@ import {
121108 getEffectiveCanvasSyncMode ,
122109 setCanvasSyncMode ,
123110} from "./canvasSyncMode" ;
111+ import {
112+ CanvasStoreAdapterArgs ,
113+ useCanvasStoreAdapterArgs ,
114+ } from "./useCanvasStoreAdapterArgs" ;
124115import posthog from "posthog-js" ;
125116
126117declare global {
@@ -269,15 +260,6 @@ const TldrawCanvas = ({ title }: { title: string }) => {
269260 ) ;
270261} ;
271262
272- type CanvasStoreAdapterArgs = {
273- pageUid : string ;
274- migrations : MigrationSequence [ ] ;
275- customShapeUtils : readonly TLAnyShapeUtilConstructor [ ] ;
276- customBindingUtils : readonly TLAnyBindingUtilConstructor [ ] ;
277- customShapeTypes : string [ ] ;
278- customBindingTypes : string [ ] ;
279- } ;
280-
281263type CanvasStoreAdapterResult = {
282264 store : TLStore | TLStoreWithStatus | null ;
283265 needsUpgrade : boolean ;
@@ -715,17 +697,19 @@ const TldrawCanvasShared = ({
715697 onCanvasSyncModeChange,
716698 } ) ;
717699
718- // UTILS
719- const discourseNodeUtils = createNodeShapeUtils ( allNodes ) ;
720- const discourseRelationUtils = createAllRelationShapeUtils ( allRelationIds ) ;
721- const referencedNodeUtils = createAllReferencedNodeUtils (
700+ const storeAdapterArgs = useCanvasStoreAdapterArgs ( {
701+ pageUid,
702+ isCloudflareSync,
703+ allNodes,
704+ allRelationIds,
722705 allAddReferencedNodeByAction,
723- ) ;
724- const customShapeUtils = [
725- ...discourseNodeUtils ,
726- ...discourseRelationUtils ,
727- ...referencedNodeUtils ,
728- ] ;
706+ } ) ;
707+ const {
708+ customShapeUtils,
709+ customBindingUtils,
710+ customShapeTypes,
711+ customBindingTypes,
712+ } = storeAdapterArgs ;
729713
730714 // TOOLS
731715 const discourseGraphTool = class DiscourseGraphTool extends StateNode {
@@ -744,19 +728,6 @@ const TldrawCanvasShared = ({
744728 ...referencedNodeTools ,
745729 ] ;
746730
747- // BINDINGS
748- const relationBindings = createAllRelationBindings ( allRelationIds ) ;
749- const referencedNodeBindings = createAllReferencedNodeBindings (
750- allAddReferencedNodeByAction ,
751- ) ;
752- const customBindingUtils = [ ...relationBindings , ...referencedNodeBindings ] ;
753- const customShapeTypes = customShapeUtils
754- . map ( ( s ) => ( s as unknown as { type ?: string } ) . type )
755- . filter ( ( t ) : t is string => ! ! t ) ;
756- const customBindingTypes = customBindingUtils
757- . map ( ( b ) => ( b as unknown as { type ?: string } ) . type )
758- . filter ( ( t ) : t is string => ! ! t ) ;
759-
760731 // UI OVERRIDES
761732 const uiOverrides = createUiOverrides ( {
762733 allNodes,
@@ -774,26 +745,8 @@ const TldrawCanvasShared = ({
774745 inSidebar : ! ! containerRef . current ?. closest ( ".rm-sidebar-outline" ) ,
775746 } ) ;
776747 } , [ pageUid ] ) ;
777- const arrowShapeMigrations = useMemo (
778- ( ) =>
779- createMigrations ( {
780- allRelationIds,
781- allAddReferencedNodeActions,
782- allNodeTypes : allNodes . map ( ( node ) => node . type ) ,
783- } ) ,
784- [ allRelationIds , allAddReferencedNodeActions , allNodes ] ,
785- ) ;
786-
787- const migrations = [ arrowShapeMigrations ] ;
788748 const { store, needsUpgrade, performUpgrade, error, isLoading } =
789- useStoreAdapter ( {
790- migrations,
791- customShapeUtils,
792- customBindingUtils,
793- customShapeTypes,
794- customBindingTypes,
795- pageUid,
796- } ) ;
749+ useStoreAdapter ( storeAdapterArgs ) ;
797750
798751 // ASSETS
799752 const assetLoading = usePreloadAssets ( defaultEditorAssetUrls ) ;
0 commit comments