@@ -2,9 +2,12 @@ import { StateNode, TLEventHandlers, TLStateNodeConstructor } from "tldraw";
22import { createShapeId } from "tldraw" ;
33import type { TFile } from "obsidian" ;
44import DiscourseGraphPlugin from "~/index" ;
5- import { getRelationTypeById , isAcceptedSchema } from "~/utils/typeUtils" ;
5+ import { getNodeTypeById , getRelationTypeById } from "~/utils/typeUtils" ;
6+ import {
7+ getCompatibleTargetNodeTypeIds ,
8+ getDiscourseNodeTypeId ,
9+ } from "~/components/canvas/utils/relationTypeUtils" ;
610import { DiscourseRelationShape } from "./shapes/DiscourseRelationShape" ;
7- import { getNodeTypeById } from "~/utils/typeUtils" ;
811import { showToast } from "./utils/toastUtils" ;
912import { toTldrawColor } from "~/utils/tldrawColors" ;
1013
@@ -88,40 +91,6 @@ class Pointing extends StateNode {
8891 this . cancel ( ) ;
8992 } ;
9093
91- private getCompatibleNodeTypes = (
92- plugin : DiscourseGraphPlugin ,
93- relationTypeId : string ,
94- sourceNodeTypeId : string ,
95- ) : string [ ] => {
96- const compatibleTypes : string [ ] = [ ] ;
97-
98- // Find all accepted discourse relations that match the relation type and source
99- const relations = plugin . settings . discourseRelations . filter (
100- ( relation ) =>
101- isAcceptedSchema ( relation ) &&
102- relation . relationshipTypeId === relationTypeId &&
103- relation . sourceId === sourceNodeTypeId ,
104- ) ;
105-
106- relations . forEach ( ( relation ) => {
107- compatibleTypes . push ( relation . destinationId ) ;
108- } ) ;
109-
110- // Also check reverse relations (where current node is destination)
111- const reverseRelations = plugin . settings . discourseRelations . filter (
112- ( relation ) =>
113- isAcceptedSchema ( relation ) &&
114- relation . relationshipTypeId === relationTypeId &&
115- relation . destinationId === sourceNodeTypeId ,
116- ) ;
117-
118- reverseRelations . forEach ( ( relation ) => {
119- compatibleTypes . push ( relation . sourceId ) ;
120- } ) ;
121-
122- return [ ...new Set ( compatibleTypes ) ] ; // Remove duplicates
123- } ;
124-
12594 override onEnter = ( ) => {
12695 this . didTimeout = false ;
12796
@@ -143,20 +112,19 @@ class Pointing extends StateNode {
143112 return ;
144113 }
145114
146- const sourceNodeTypeId = ( target as { props ?: { nodeTypeId ?: string } } )
147- . props ?. nodeTypeId ;
115+ const sourceNodeTypeId = getDiscourseNodeTypeId ( target ) ;
148116 if ( ! sourceNodeTypeId ) {
149117 this . showWarning ( "Source node must have a valid node type" ) ;
150118 return ;
151119 }
152120
153121 // Check if this source node type can create relations of this type
154122 if ( sourceNodeTypeId ) {
155- const compatibleTargetTypes = this . getCompatibleNodeTypes (
156- plugin ,
123+ const compatibleTargetTypes = getCompatibleTargetNodeTypeIds ( {
124+ discourseRelations : plugin . settings . discourseRelations ,
157125 relationTypeId,
158126 sourceNodeTypeId,
159- ) ;
127+ } ) ;
160128
161129 if ( compatibleTargetTypes . length === 0 ) {
162130 const sourceNodeType = getNodeTypeById ( plugin , sourceNodeTypeId ) ;
@@ -168,11 +136,7 @@ class Pointing extends StateNode {
168136 }
169137 }
170138
171- if ( ! target ) {
172- this . createArrowShape ( ) ;
173- } else {
174- this . editor . setHintingShapes ( [ target . id ] ) ;
175- }
139+ this . editor . setHintingShapes ( [ target . id ] ) ;
176140
177141 this . startPreciseTimeout ( ) ;
178142 } ;
0 commit comments