@logicflow/vue-node-registry
Version:
LogicFlow Vue Component Node Registry
42 lines • 1.67 kB
JavaScript
import { VueNodeView } from './view';
import { VueNodeModel } from './model';
// Per-instance map: entries are eligible for garbage collection once the associated GraphModel instance is no longer referenced
var vueNodesMaps = new WeakMap();
/**
* @deprecated Use {@link getVueNodeConfig} instead for multi-instance support.
* This global map is still populated for backward compatibility but does NOT
* isolate registrations across different LogicFlow instances.
*/
export var vueNodesMap = Object.create(null);
/**
* Retrieve the Vue node configuration scoped to a specific LogicFlow instance.
*/
export function getVueNodeConfig(type, graphModel) {
var _a;
if (typeof graphModel !== 'object' || graphModel === null) {
return undefined;
}
return (_a = vueNodesMaps.get(graphModel)) === null || _a === void 0 ? void 0 : _a.get(type);
}
export function register(config, lf) {
var type = config.type, component = config.component, effect = config.effect, CustomNodeView = config.view, CustomNodeModel = config.model;
if (!type) {
throw new Error('You should specify type in config');
}
var entry = { component: component, effect: effect };
// Scope to this LogicFlow instance
var map = vueNodesMaps.get(lf.graphModel);
if (!map) {
map = new Map();
vueNodesMaps.set(lf.graphModel, map);
}
map.set(type, entry);
// Also populate global map for backward compatibility
vueNodesMap[type] = entry;
lf.register({
type: type,
view: CustomNodeView || VueNodeView,
model: CustomNodeModel || VueNodeModel,
});
}
//# sourceMappingURL=registry.js.map