1- import LogicFlow from '@logicflow/core'
1+ import LogicFlow , { GraphModel } from '@logicflow/core'
22import { VueNodeView } from './view'
33import { VueNodeModel } from './model'
44
@@ -10,13 +10,32 @@ export type VueNodeConfig = {
1010 effect ?: ( keyof LogicFlow . PropertiesType ) [ ]
1111} & Partial < RegisterConfig >
1212
13- export const vueNodesMap : Record <
14- string ,
15- {
16- component : any
17- effect ?: ( keyof LogicFlow . PropertiesType ) [ ]
18- }
19- > = { }
13+ type VueNodeEntry = {
14+ component : any
15+ effect ?: ( keyof LogicFlow . PropertiesType ) [ ]
16+ }
17+
18+ // Per-instance map: automatically garbage-collected when the GraphModel is destroyed
19+ const vueNodesMaps = new WeakMap < GraphModel , Map < string , VueNodeEntry > > ( )
20+
21+ /**
22+ * @deprecated Use {@link getVueNodeConfig} instead for multi-instance support.
23+ * This global map is still populated for backward compatibility but does NOT
24+ * isolate registrations across different LogicFlow instances.
25+ */
26+ export const vueNodesMap : Record < string , VueNodeEntry > = Object . create (
27+ null ,
28+ ) as Record < string , VueNodeEntry >
29+
30+ /**
31+ * Retrieve the Vue node configuration scoped to a specific LogicFlow instance.
32+ */
33+ export function getVueNodeConfig (
34+ type : string ,
35+ graphModel : GraphModel ,
36+ ) : VueNodeEntry | undefined {
37+ return vueNodesMaps . get ( graphModel ) ?. get ( type )
38+ }
2039
2140export function register ( config : VueNodeConfig , lf : LogicFlow ) {
2241 const {
@@ -30,10 +49,19 @@ export function register(config: VueNodeConfig, lf: LogicFlow) {
3049 if ( ! type ) {
3150 throw new Error ( 'You should specify type in config' )
3251 }
33- vueNodesMap [ type ] = {
34- component,
35- effect,
52+
53+ const entry : VueNodeEntry = { component, effect }
54+
55+ // Scope to this LogicFlow instance
56+ let map = vueNodesMaps . get ( lf . graphModel )
57+ if ( ! map ) {
58+ map = new Map < string , VueNodeEntry > ( )
59+ vueNodesMaps . set ( lf . graphModel , map )
3660 }
61+ map . set ( type , entry )
62+
63+ // Also populate global map for backward compatibility
64+ vueNodesMap [ type ] = entry
3765
3866 lf . register ( {
3967 type,
0 commit comments