@@ -8,92 +8,7 @@ import {DatatypeService} from "@edition/datatype/services/Datatype.service";
88import { FunctionNodeComponentProps } from "@edition/function/components/nodes/FunctionNodeComponent" ;
99import { DataTypeVariant , getTypesFromFunction , getTypesFromNode , getTypeVariant } from "@code0-tech/triangulum" ;
1010
11- const packageNodes = new Map < string , string > ( [
12- [ 'std' , 'default' ] ,
13- ] ) ;
14-
15- /**
16- * Returns the value of the best-matching key from a Map<string, string>.
17- *
18- * Matching priority:
19- * 1) Exact match
20- * 2) Longest prefix match (with bonus if the prefix ends at a token boundary)
21- * 3) Largest common prefix length (with small boundary bonus)
22- *
23- * Token boundaries are characters in /[:._\-\/\s]+/ (e.g., "::", ".", "_", "-", "/", whitespace).
24- *
25- * Performance:
26- * - O(N * M), where N = number of keys, M = average key length (string comparisons only).
27- *
28- */
29- const bestMatchValue = ( map : Map < string , string > , input : string ) : string => {
30- if ( ! input || map . size === 0 ) return ""
31-
32- const SEP = / [: ._ \- \/ \s ] + / ;
33- const normInput = input . trim ( ) . toLowerCase ( ) ;
34-
35- let bestKey : string | null = null ;
36- let bestScore = - Infinity ;
37-
38- for ( const [ key , value ] of map . entries ( ) ) {
39- const normKey = key . trim ( ) . toLowerCase ( ) ;
40-
41- // (1) Exact match → immediately return (strongest possible score)
42- if ( normInput === normKey ) {
43- return value ;
44- }
45-
46- let score = 0 ;
47-
48- // (2) Prefix match
49- if ( normInput . startsWith ( normKey ) ) {
50- score = 2000 + normKey . length * 2 ;
51-
52- // Bonus if the prefix ends at a clean token boundary (or equals the whole input)
53- const boundaryChar = normInput . charAt ( normKey . length ) ; // '' if out of range
54- if ( boundaryChar === "" || SEP . test ( boundaryChar ) ) {
55- score += 200 ;
56- }
57- } else {
58- // (3) Largest common prefix (LCP)
59- const max = Math . min ( normInput . length , normKey . length ) ;
60- let lcp = 0 ;
61- while ( lcp < max && normInput . charCodeAt ( lcp ) === normKey . charCodeAt ( lcp ) ) {
62- lcp ++ ;
63- }
64- if ( lcp > 0 ) {
65- score = 1000 + lcp ;
66-
67- // Small bonus if LCP ends at a boundary on either side
68- const inBoundaryChar = normInput . charAt ( lcp ) ;
69- const keyBoundaryChar = normKey . charAt ( lcp ) ;
70- if (
71- inBoundaryChar === "" ||
72- SEP . test ( inBoundaryChar ) ||
73- keyBoundaryChar === "" ||
74- SEP . test ( keyBoundaryChar )
75- ) {
76- score += 50 ;
77- }
78- }
79- }
80-
81- // Best candidate so far? Tie-breaker favors longer key (more specific)
82- if ( score > bestScore ) {
83- bestScore = score ;
84- bestKey = key ;
85- } else if ( score === bestScore && bestKey !== null && key . length > bestKey . length ) {
86- bestKey = key ;
87- } else if ( score === bestScore && bestKey === null ) {
88- bestKey = key ;
89- }
90- }
91-
92- return bestKey !== null ? map . get ( bestKey ) ! : "" ;
93- } ;
94-
95- // @ts -ignore
96- export const useFlowNodes = ( flowId : Flow [ "id" ] , namespaceId ?: Namespace [ "id" ] , projectId ?: NamespaceProject [ "id" ] ) : Node < DFlowNodeProps > [ ] => {
11+ export const useFlowNodes = ( flowId : Flow [ "id" ] , namespaceId ?: Namespace [ "id" ] , projectId ?: NamespaceProject [ "id" ] ) : Node < FunctionNodeComponentProps > [ ] => {
9712
9813 const flowService = useService ( FlowService )
9914 const flowStore = useStore ( FlowService )
@@ -136,14 +51,15 @@ export const useFlowNodes = (flowId: Flow["id"], namespaceId?: Namespace["id"],
13651 ) => {
13752 if ( ! node ?. id ) return ;
13853
54+ const functionDefinition = functionService . getById ( node . functionDefinition ?. id )
13955 const nodeId = node . id ;
14056
14157 if ( ! visited . has ( nodeId ) ) {
14258 visited . add ( nodeId ) ;
14359
14460 nodes . push ( {
14561 id : nodeId ,
146- type : bestMatchValue ( packageNodes , node . functionDefinition ?. identifier ?? "" ) ,
62+ type : functionDefinition && "design" in functionDefinition ? functionDefinition ?. design as string : "default" ,
14763 position : { x : 0 , y : 0 } ,
14864 draggable : false ,
14965 parentId : parentGroup ,
@@ -159,7 +75,7 @@ export const useFlowNodes = (flowId: Flow["id"], namespaceId?: Namespace["id"],
15975 } ) ;
16076 }
16177
162- const types = getTypesFromFunction ( functionService . getById ( node . functionDefinition ?. id ) ! ) ;
78+ const types = getTypesFromFunction ( functionDefinition ! ) ;
16379
16480 node . parameters ?. nodes ?. forEach ( ( param , index ) => {
16581 const value = param ?. value ;
0 commit comments