@metadev/daga 3.1.4 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metadev/daga",
3
- "version": "3.1.4",
3
+ "version": "4.0.0",
4
4
  "dependencies": {},
5
5
  "peerDependencies": {
6
6
  "d3": "^7.9.0",
package/src/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export { Corner, HorizontalAlign, Side, VerticalAlign } from '../../daga/src/lib/util/svg-util';
2
- export { ACTION_STACK_SIZE, DiagramCanvas, setCursorStyle } from './lib/diagram/canvas/diagram-canvas';
2
+ export { ACTION_STACK_SIZE, DiagramCanvas } from './lib/diagram/canvas/diagram-canvas';
3
+ export { setCursorStyle } from './lib/diagram/canvas/diagram-canvas-util';
3
4
  export { DiagramContextMenu } from './lib/diagram/canvas/diagram-context-menu';
4
5
  export { DiagramUserHighlight } from './lib/diagram/canvas/diagram-user-highlight';
5
6
  export { DiagramUserSelection } from './lib/diagram/canvas/diagram-user-selection';
@@ -13,7 +14,8 @@ export type { DiagramModelExporter } from './lib/diagram/converters/diagram-mode
13
14
  export type { DiagramModelImporter } from './lib/diagram/converters/diagram-model-importer';
14
15
  export { ActionStack, AddConnectionAction, AddNodeAction, ApplyLayoutAction, DiagramActionMethod, DiagramActions, EditFieldAction, MoveAction, PasteAction, RemoveAction, SetGeometryAction, SetParentAction, UpdateValuesAction } from './lib/diagram/diagram-action';
15
16
  export type { DiagramAction } from './lib/diagram/diagram-action';
16
- export type { ButtonsComponentConfig, CanvasConfig, ComponentsConfig, ConnectionMarkerLook, ConnectionTemplateConfig, ConnectionTypeConfig, DiagramConfig, ErrorsComponentConfig, FieldConfig, GridConfig, NodeImageLook, NodeShapedLook, NodeStretchableImageLook, NodeTemplateConfig, NodeTypeConfig, PaletteComponentConfig, PaletteSectionConfig, PortConfig, PropertyEditorComponentConfig, SectionConfig, SectionGridConfig, UserActionConfig } from './lib/diagram/diagram-config';
17
+ export type { ButtonsComponentConfig, CanvasConfig, ComponentsConfig, ConnectionTemplateConfig, ConnectionTypeConfig, DiagramConfig, ErrorsComponentConfig, FieldConfig, GridConfig, NodeTemplateConfig, NodeTypeConfig, PaletteComponentConfig, PaletteSectionConfig, PortConfig, PortTypeConfig, PropertyEditorComponentConfig, SectionConfig, SectionGridConfig, UserActionConfig } from './lib/diagram/config/diagram-config';
18
+ export type { MarkerImageLook, StretchableImageLook, ImageLook, ShapedLook, Look, MarkerImageLookConfig, StretchableImageLookConfig, ImageLookConfig, ShapedLookConfig, LookConfig } from './lib/diagram/config/diagram-look';
17
19
  export { DiagramDoubleClickEvent, DiagramEvent, DiagramEvents, DiagramHighlightedEvent, DiagramSecondaryClickEvent, DiagramSelectionEvent } from './lib/diagram/diagram-event';
18
20
  export { AdjacencyLayout } from './lib/diagram/layout/adjacency-layout';
19
21
  export { BreadthAdjacencyLayout } from './lib/diagram/layout/breadth-adjacency-layout';
@@ -35,7 +37,7 @@ export { DiagramModel } from './lib/diagram/model/diagram-model';
35
37
  export { DiagramNode, DiagramNodeSet, DiagramNodeType, filterByOnlyAncestors, filterByOnlyDescendants } from './lib/diagram/model/diagram-node';
36
38
  export type { DiagramNodeGeometry } from './lib/diagram/model/diagram-node';
37
39
  export { DiagramObject, DiagramObjectSet } from './lib/diagram/model/diagram-object';
38
- export { DiagramPort, DiagramPortSet } from './lib/diagram/model/diagram-port';
40
+ export { DiagramPort, DiagramPortSet, DiagramPortType } from './lib/diagram/model/diagram-port';
39
41
  export { diff, equals, isObject, Property, PropertySet, Type, ValueSet } from './lib/diagram/model/diagram-property';
40
42
  export type { Option } from './lib/diagram/model/diagram-property';
41
43
  export { DiagramSection, DiagramSectionSet } from './lib/diagram/model/diagram-section';
@@ -0,0 +1,26 @@
1
+ import * as d3 from 'd3';
2
+ import { Point } from '../../util/canvas-util';
3
+ import { LineFunction, LineShape } from '../../util/line';
4
+ import { CursorStyle } from '../../util/style';
5
+ import { Side } from '../../util/svg-util';
6
+ import { DiagramField } from '../model/diagram-field';
7
+ import { DiagramNode } from '../model/diagram-node';
8
+ import { DiagramPort } from '../model/diagram-port';
9
+ import { DiagramSection } from '../model/diagram-section';
10
+ /**
11
+ * Checks if the given mouse event was produced with a secondary button press.
12
+ * @private
13
+ * @param event A mouse event.
14
+ * @returns `true` if the given mouse event was produced with a secondary button press, `false` otherwise.
15
+ */
16
+ export declare const isSecondaryButton: (event: MouseEvent) => boolean;
17
+ /**
18
+ * Get the SVG path of a diagram connection.
19
+ * @private
20
+ * @see linePath
21
+ */
22
+ export declare const getConnectionPath: (shape: LineShape | LineFunction, startCoords: Point, endCoords: Point, startDirection: Side | undefined, endDirection: Side | undefined, width: number, startMarkerWidth: number | undefined, endMarkerWidth: number | undefined) => string;
23
+ export declare const setCursorStyle: (style?: CursorStyle) => void;
24
+ export declare const getRelatedNodeOrItself: (element: DiagramNode | DiagramSection | DiagramPort | DiagramField) => DiagramNode | DiagramSection | DiagramPort | DiagramField;
25
+ export declare const initializeLook: (selection: d3.Selection<SVGGElement, DiagramNode | DiagramSection | DiagramPort, d3.BaseType, unknown>) => void;
26
+ export declare const updateLook: (selection: d3.Selection<SVGGElement, DiagramNode | DiagramSection | DiagramPort, d3.BaseType, unknown>) => void;
@@ -4,10 +4,9 @@ import { DiagramValidator } from '../../errors/diagram-validator';
4
4
  import { Canvas } from '../../interfaces/canvas';
5
5
  import { DiagramEditor } from '../../interfaces/diagram-editor';
6
6
  import { Point } from '../../util/canvas-util';
7
- import { CursorStyle } from '../../util/style';
8
7
  import { CollabEngine } from '../collab/collab-engine';
8
+ import { DiagramConfig } from '../config/diagram-config';
9
9
  import { ActionStack, DiagramAction, DiagramActionMethod, DiagramActions } from '../diagram-action';
10
- import { DiagramConfig } from '../diagram-config';
11
10
  import { DiagramEvent } from '../diagram-event';
12
11
  import { DiagramConnectionType } from '../model/diagram-connection';
13
12
  import { DiagramModel } from '../model/diagram-model';
@@ -145,4 +144,3 @@ export declare class DiagramCanvas implements Canvas {
145
144
  private continueMultipleSelection;
146
145
  private finishMultipleSelection;
147
146
  }
148
- export declare const setCursorStyle: (style?: CursorStyle) => void;
@@ -1,9 +1,8 @@
1
- import { Point } from '../util/canvas-util';
2
- import { LineFunction, LineShape, LineStyle } from '../util/line';
3
- import { ClosedShape, ShapeFunction } from '../util/shape';
4
- import { Corner, HorizontalAlign, Side, VerticalAlign } from '../util/svg-util';
5
- import { DiagramActions } from './diagram-action';
6
- import { Property } from './model/diagram-property';
1
+ import { Point } from '../../util/canvas-util';
2
+ import { Corner, HorizontalAlign, Side, VerticalAlign } from '../../util/svg-util';
3
+ import { DiagramActions } from '../diagram-action';
4
+ import { Property } from '../model/diagram-property';
5
+ import { ConnectionLookConfig, ImageLookConfig, MarkerImageLookConfig, ShapedLookConfig, StretchableImageLookConfig } from './diagram-look';
7
6
  /**
8
7
  * The configuration for a diagram.
9
8
  * @public
@@ -60,6 +59,16 @@ export interface DiagramConfig {
60
59
  * @default undefined
61
60
  */
62
61
  nodeTypes?: NodeTypeConfig[];
62
+ /**
63
+ * Default attributes for each of the types of port of this diagram. By default, no attributes are set.
64
+ * @default undefined
65
+ */
66
+ portTypeDefaults?: Partial<PortTypeConfig>;
67
+ /**
68
+ * List of the types of port that can be used in this diagram. By default, no types are created.
69
+ * @default undefined
70
+ */
71
+ portTypes?: PortTypeConfig[];
63
72
  /**
64
73
  * Default attributes for each of the types of connection of this diagram. By default, no attributes are set.
65
74
  * @default undefined
@@ -338,7 +347,7 @@ export interface NodeTemplateConfig {
338
347
  /**
339
348
  * Look of this template as it appears on the palette which can be used to override the default look of the nodes of this type.
340
349
  */
341
- look?: NodeShapedLook | NodeImageLook | NodeStretchableImageLook;
350
+ look?: ShapedLookConfig | ImageLookConfig | StretchableImageLookConfig;
342
351
  /**
343
352
  * Label of this template as it appears on the palette and label that will be given to nodes created from this template.
344
353
  */
@@ -458,10 +467,9 @@ export interface NodeTypeConfig {
458
467
  */
459
468
  ports?: PortConfig[];
460
469
  /**
461
- * Configuration of the look of nodes of this type as it should appear to the user.
462
- * @default {lookType: 'shaped-look', shape: ClosedShape.Rectangle, fillColor: '#FFFFFF', borderColor: '#000000', selectedFillColor: '#FFFFFF', selectedBorderColor: '#000000'}
470
+ * Configuration of the look of nodes of this type as they should appear to the user.
463
471
  */
464
- look?: NodeShapedLook | NodeImageLook | NodeStretchableImageLook;
472
+ look?: ShapedLookConfig | ImageLookConfig | StretchableImageLookConfig;
465
473
  /**
466
474
  * If true and a node of this type already exists in the diagram, the user can't create more nodes of this type.
467
475
  * @default false
@@ -489,6 +497,70 @@ export interface NodeTypeConfig {
489
497
  */
490
498
  properties?: Property[];
491
499
  }
500
+ /**
501
+ * Configuration for a type of port.
502
+ * @public
503
+ * @see DiagramPortType
504
+ */
505
+ export interface PortTypeConfig {
506
+ /**
507
+ * Id of this type of port used to reference this type of port internally.
508
+ */
509
+ id: string;
510
+ /**
511
+ * Name of this type of port as displayed to the user.
512
+ */
513
+ name?: string;
514
+ /**
515
+ * Whether this type of port can be used as a connection start point.
516
+ * @default true
517
+ */
518
+ allowsOutgoing?: boolean;
519
+ /**
520
+ * Whether this type of port can be used as a connection end point.
521
+ * @default true
522
+ */
523
+ allowsIncoming?: boolean;
524
+ /**
525
+ * Configuration for the label of ports of this type.
526
+ * @default null
527
+ */
528
+ label?: FieldConfig | null;
529
+ /**
530
+ * Width of this type of port as it appears in the diagram in diagram units.
531
+ * @default 24
532
+ */
533
+ width?: number;
534
+ /**
535
+ * Configuration of the look of ports of this type as they should appear to the user.
536
+ */
537
+ look?: ShapedLookConfig | ImageLookConfig;
538
+ }
539
+ /**
540
+ * Configuration for a port that is part of another element.
541
+ * @public
542
+ * @see DiagramPort
543
+ */
544
+ export interface PortConfig {
545
+ /**
546
+ * Id of the type of this port. May be left `undefined` to use the default look. If set, it must correspond to the id of a type of port defined in the portTypes list.
547
+ * @default undefined
548
+ */
549
+ type?: string;
550
+ /**
551
+ * Coordinates of this port relative to its root element's coordinates.
552
+ */
553
+ coords: Point;
554
+ /**
555
+ * Optional coordinates of the point where connections start and end within this port relative to its root element's coordinates.
556
+ * By default, it is the same as the port's coordinates.
557
+ */
558
+ connectionPoint?: Point;
559
+ /**
560
+ * Direction that the connections passing by this port follow at the point of the port.
561
+ */
562
+ direction: Side;
563
+ }
492
564
  /**
493
565
  * Configuration for a field that is part of another element.
494
566
  * @public
@@ -548,26 +620,6 @@ export interface FieldConfig {
548
620
  */
549
621
  fit?: boolean;
550
622
  }
551
- /**
552
- * Configuration for a port that is part of another element.
553
- * @public
554
- * @see DiagramPort
555
- */
556
- export interface PortConfig {
557
- /**
558
- * Coordinates of this port relative to its root element's coordinates.
559
- */
560
- coords: Point;
561
- /**
562
- * Direction that the connections passing by this port follow at the point of the port.
563
- */
564
- direction: Side;
565
- /**
566
- * Configuration for the label of this port.
567
- * @default null
568
- */
569
- label?: FieldConfig | null;
570
- }
571
623
  /**
572
624
  * Configuration for the grid of sections of a node.
573
625
  * @public
@@ -596,7 +648,7 @@ export interface SectionGridConfig {
596
648
  */
597
649
  margin?: number;
598
650
  /**
599
- * Configuration for the sections of this grid.
651
+ * Configuration for the look of each section of this grid.
600
652
  * @default [[]]
601
653
  */
602
654
  sections: SectionConfig[][];
@@ -618,162 +670,15 @@ export interface SectionConfig {
618
670
  */
619
671
  ports?: PortConfig[];
620
672
  /**
621
- * Configuration of the look of the sections as it should appear to the user.
622
- * @default {lookType: 'shaped-look', shape: ClosedShape.Rectangle, color: '#FFFFFF', borderColor: '#000000', selectedColor: '#FFFFFF', selectedBorderColor: '#000000'}
673
+ * Configuration of the look of nodes of this type as they should appear to the user.
623
674
  */
624
- look?: NodeShapedLook | NodeImageLook | NodeStretchableImageLook;
675
+ look?: ShapedLookConfig | ImageLookConfig | StretchableImageLookConfig;
625
676
  /**
626
677
  * The priority of this section when filtering out sections below a given threshold.
627
678
  * @default 0
628
679
  */
629
680
  priority?: number;
630
681
  }
631
- /**
632
- * Configuration for the look of a node given by shape and color.
633
- * @public
634
- */
635
- export interface NodeShapedLook {
636
- /**
637
- * String used to discern the type of node look this is.
638
- */
639
- lookType: 'shaped-look';
640
- /**
641
- * Shape of nodes using this look.
642
- */
643
- shape: ClosedShape | ShapeFunction;
644
- /**
645
- * Background color of nodes using this look.
646
- */
647
- fillColor: string;
648
- /**
649
- * Border color of nodes using this look.
650
- */
651
- borderColor: string;
652
- /**
653
- * Background color of nodes using this look when selected.
654
- */
655
- selectedFillColor: string;
656
- /**
657
- * Border color of nodes using this look when selected.
658
- */
659
- selectedBorderColor: string;
660
- }
661
- /**
662
- * Configuration for the look of a node given by an image.
663
- * @public
664
- */
665
- export interface NodeImageLook {
666
- /**
667
- * String used to discern the type of node look this is.
668
- */
669
- lookType: 'image-look';
670
- /**
671
- * File path to the background image used by nodes using this look.
672
- */
673
- backgroundImage: string;
674
- /**
675
- * File path to the background image used by nodes using this look when selected.
676
- */
677
- selectedBackgroundImage: string;
678
- }
679
- /**
680
- * Configuration for the look of a node given by fixed size images in the corners and stretchable images in the middle.
681
- * @public
682
- */
683
- export interface NodeStretchableImageLook {
684
- /**
685
- * String used to discern the type of node look this is.
686
- */
687
- lookType: 'stretchable-image-look';
688
- /**
689
- * Width taken up by the images at the left of nodes using this look in diagram units.
690
- */
691
- leftMargin: number;
692
- /**
693
- * Width taken up by the images at the right of nodes using this look in diagram units.
694
- */
695
- rightMargin: number;
696
- /**
697
- * Width taken up by the images at the top of nodes using this look in diagram units.
698
- */
699
- topMargin: number;
700
- /**
701
- * Width taken up by the images at the bottom of nodes using this look in diagram units.
702
- */
703
- bottomMargin: number;
704
- /**
705
- * File path to the background image used at the top left of nodes using this look.
706
- */
707
- backgroundImageTopLeft: string;
708
- /**
709
- * File path to the background image used at the top of nodes using this look.
710
- */
711
- backgroundImageTop: string;
712
- /**
713
- * File path to the background image used at the top right of nodes using this look.
714
- */
715
- backgroundImageTopRight: string;
716
- /**
717
- * File path to the background image used at the left of nodes using this look.
718
- */
719
- backgroundImageLeft: string;
720
- /**
721
- * File path to the background image used at the center of nodes using this look.
722
- */
723
- backgroundImageCenter: string;
724
- /**
725
- * File path to the background image used at the right of nodes using this look.
726
- */
727
- backgroundImageRight: string;
728
- /**
729
- * File path to the background image used at the bottom left of nodes using this look.
730
- */
731
- backgroundImageBottomLeft: string;
732
- /**
733
- * File path to the background image used at the bottom of nodes using this look.
734
- */
735
- backgroundImageBottom: string;
736
- /**
737
- * File path to the background image used at the bottom right of nodes using this look.
738
- */
739
- backgroundImageBottomRight: string;
740
- /**
741
- * File path to the background image used at the top left of nodes using this look when selected.
742
- */
743
- selectedBackgroundImageTopLeft: string;
744
- /**
745
- * File path to the background image used at the top of nodes using this look when selected.
746
- */
747
- selectedBackgroundImageTop: string;
748
- /**
749
- * File path to the background image used at the top right of nodes using this look when selected.
750
- */
751
- selectedBackgroundImageTopRight: string;
752
- /**
753
- * File path to the background image used at the left of nodes using this look when selected.
754
- */
755
- selectedBackgroundImageLeft: string;
756
- /**
757
- * File path to the background image used at the center of nodes using this look when selected.
758
- */
759
- selectedBackgroundImageCenter: string;
760
- /**
761
- * File path to the background image used at the right of nodes using this look when selected.
762
- */
763
- selectedBackgroundImageRight: string;
764
- /**
765
- * File path to the background image used at the bottom left of nodes using this look when selected.
766
- */
767
- selectedBackgroundImageBottomLeft: string;
768
- /**
769
- * File path to the background image used at the bottom of nodes using this look when selected.
770
- */
771
- selectedBackgroundImageBottom: string;
772
- /**
773
- * File path to the background image used at the bottom right of nodes using this look when selected.
774
- */
775
- selectedBackgroundImageBottomRight: string;
776
- }
777
682
  /**
778
683
  * Configuration for a type of connection.
779
684
  * @public
@@ -788,45 +693,24 @@ export interface ConnectionTypeConfig {
788
693
  * Name of this type of connection as displayed to the user.
789
694
  */
790
695
  name?: string;
791
- /**
792
- * Color of the line of connections of this type.
793
- * @default '#000000'
794
- */
795
- color?: string;
796
- /**
797
- * Color of the line of connections of this type when selected.
798
- * @default '#000000'
799
- */
800
- selectedColor?: string;
801
- /**
802
- * Width of the line of connections of this type in diagram units.
803
- * @default 1
804
- */
805
- width?: number;
806
- /**
807
- * Shape of the line of connections of this type.
808
- * @default 'straight'
809
- */
810
- shape?: LineShape | LineFunction;
811
- /**
812
- * Style of the line of connections of this type.
813
- * @default 'solid'
814
- */
815
- style?: LineStyle;
816
696
  /**
817
697
  * Configuration of the labels of connections of this type.
818
698
  */
819
699
  label?: FieldConfig | null;
700
+ /**
701
+ * Configuration of the look of connections of this type as they should appear to the user.
702
+ */
703
+ look?: ConnectionLookConfig;
820
704
  /**
821
705
  * Configuration of the look of the marker at the start of connections of this type as it should appear to the user. Undefined for no marker.
822
- * @default null
706
+ * @default undefined
823
707
  */
824
- defaultStartMarkerLook?: ConnectionMarkerLook | null;
708
+ startMarkerLook?: MarkerImageLookConfig;
825
709
  /**
826
710
  * Configuration of the look of the marker at the end of connections of this type as it should appear to the user. Undefined for no marker.
827
- * @default null
711
+ * @default undefined
828
712
  */
829
- defaultEndMarkerLook?: ConnectionMarkerLook | null;
713
+ endMarkerLook?: MarkerImageLookConfig;
830
714
  /**
831
715
  * Ids of the types of nodes that connections of this type can start from. Must correspond to the ids of types of node defined in the nodeTypes list. Should list one id at minimum.
832
716
  * @default []
@@ -844,41 +728,3 @@ export interface ConnectionTypeConfig {
844
728
  */
845
729
  properties?: Property[];
846
730
  }
847
- /**
848
- * Configuration for the look of the markers at the start and end of a connection.
849
- * @public
850
- */
851
- export interface ConnectionMarkerLook {
852
- /**
853
- * File path to the image used for the marker.
854
- */
855
- image: string;
856
- /**
857
- * File path to the image used for the marker when selected.
858
- */
859
- selectedImage: string;
860
- /**
861
- * The width of the marker in diagram units.
862
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/SVG/Element/marker |marker}
863
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/markerWidth |markerWidth}
864
- */
865
- markerWidth: number;
866
- /**
867
- * The height of the marker in diagram units.
868
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/SVG/Element/marker |marker}
869
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/markerHeight |markerHeight}
870
- */
871
- markerHeight: number;
872
- /**
873
- * The x coordinate of the reference point of the image used for the marker.
874
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/SVG/Element/marker |marker}
875
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/refX |refX}
876
- */
877
- markerRefX: number;
878
- /**
879
- * The y coordinate of the reference point of the image used for the marker.
880
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/SVG/Element/marker |marker}
881
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/refY |refY}
882
- */
883
- markerRefY: number;
884
- }