43 lines
1.3 KiB
TypeScript
43 lines
1.3 KiB
TypeScript
import RuleProvider from 'diagram-js/lib/features/rules/RuleProvider';
|
|
export default class CustomGlobalConnectRules extends RuleProvider {
|
|
static $inject = ['eventBus'];
|
|
|
|
constructor(eventBus: any) {
|
|
super(eventBus);
|
|
}
|
|
|
|
init(): void {
|
|
// Правило для начала соединения
|
|
this.addRule('connection.start', (context) => {
|
|
return true;
|
|
const { source } = context;
|
|
|
|
if (source?.businessObject?.type === 'custom:connectable') {
|
|
return true; // Разрешить соединение
|
|
}
|
|
|
|
return false; // Запретить соединение
|
|
});
|
|
|
|
// Правило для создания соединения
|
|
this.addRule('connection.create', (context) => {
|
|
//return true;
|
|
const { source, target } = context;
|
|
// console.log(typeof source);
|
|
// console.log(source.constructor.name)
|
|
// instanceof Shape);
|
|
|
|
//if (source?.type === Shape)
|
|
|
|
//if (
|
|
// source?.businessObject?.type === 'custom:connectable' &&
|
|
// target?.businessObject?.type === 'custom:connectable'
|
|
//) {
|
|
return { type: 'Connection' };
|
|
// { type: 'Connection' }; // Тип соединения
|
|
// }
|
|
|
|
return false; // Запретить соединение
|
|
});
|
|
}
|
|
}
|