index.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import OutlineProvider from 'bpmn-js/lib/features/outline/OutlineProvider.js';
  2. import { attr as svgAttr, create as svgCreate } from 'tiny-svg';
  3. import { isLabel } from 'bpmn-js/lib/util/LabelUtil';
  4. import { typeConfig } from '../config';
  5. import { typeCondition, typeConfluence } from '../config/variableName';
  6. class YmOutlineProvider extends OutlineProvider {
  7. private offset: number = 0;
  8. private _styles;
  9. private _type;
  10. constructor(outline: any, styles: any, type: any) {
  11. super(outline, styles);
  12. this._styles = styles;
  13. this._type = type;
  14. }
  15. getOutline(element: any) {
  16. const OUTLINE_STYLE = this._styles.cls('djs-outline', ['no-fill']);
  17. var outline;
  18. if (isLabel(element)) return;
  19. let { renderer } = typeConfig[element.type];
  20. const { attr } = renderer;
  21. outline = svgCreate('rect');
  22. svgAttr(
  23. outline,
  24. Object.assign(
  25. {
  26. x: attr.x,
  27. y: attr.y,
  28. rx: attr.rx ? attr.rx : 3,
  29. width: (this._type === 0 || element.wnType === typeCondition) && isLabel(element) ? 128 : element.wnType === typeConfluence ? 0 : attr.width,
  30. height: (this._type === 0 || element.wnType === typeCondition) && isLabel(element) ? 28 : element.wnType === typeConfluence ? 0 : attr.height,
  31. },
  32. OUTLINE_STYLE,
  33. ),
  34. );
  35. return outline;
  36. }
  37. updateOutline(element: any, outline: any): any {
  38. svgAttr(outline, {
  39. x: 0,
  40. y: 0,
  41. width: (this._type === 0 || element.wnType === typeCondition) && isLabel(element) ? 128 : element.width + this.offset * 2,
  42. height: (this._type === 0 || element.wnType === typeCondition) && isLabel(element) ? 28 : element.height + this.offset * 2,
  43. });
  44. return outline;
  45. }
  46. }
  47. // 注入的依赖项
  48. YmOutlineProvider.$inject = ['outline', 'styles', 'config.type'];
  49. export default YmOutlineProvider;