@metadev/daga 4.0.1 → 4.1.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.
Files changed (30) hide show
  1. package/Changelog.md +25 -0
  2. package/index.cjs.js +478 -194
  3. package/index.esm.js +478 -194
  4. package/package.json +1 -1
  5. package/src/index.d.ts +8 -5
  6. package/src/lib/diagram/canvas/diagram-canvas-util.d.ts +10 -0
  7. package/src/lib/diagram/canvas/diagram-canvas.d.ts +4 -1
  8. package/src/lib/diagram/canvas/diagram-user-selection.d.ts +1 -1
  9. package/src/lib/diagram/collab/collab-action.d.ts +32 -2
  10. package/src/lib/diagram/config/diagram-canvas-config.d.ts +6 -0
  11. package/src/lib/diagram/config/diagram-components-config.d.ts +249 -0
  12. package/src/lib/diagram/config/diagram-config.d.ts +33 -248
  13. package/src/lib/diagram/diagram-action.d.ts +23 -0
  14. package/src/lib/diagram/layout/adjacency-layout.d.ts +2 -0
  15. package/src/lib/diagram/layout/breadth-adjacency-layout.d.ts +2 -0
  16. package/src/lib/diagram/layout/breadth-layout.d.ts +2 -0
  17. package/src/lib/diagram/layout/force-layout.d.ts +2 -0
  18. package/src/lib/diagram/layout/horizontal-layout.d.ts +2 -0
  19. package/src/lib/diagram/layout/priority-layout.d.ts +2 -0
  20. package/src/lib/diagram/layout/tree-layout.d.ts +2 -0
  21. package/src/lib/diagram/layout/vertical-layout.d.ts +2 -0
  22. package/src/lib/diagram/model/diagram-connection.d.ts +2 -1
  23. package/src/lib/diagram/model/diagram-model.d.ts +2 -1
  24. package/src/lib/diagram/model/diagram-node.d.ts +25 -2
  25. package/src/lib/diagram/property/property-util.d.ts +61 -0
  26. package/src/lib/diagram/property/property.d.ts +146 -0
  27. package/src/lib/diagram/property/value.d.ts +163 -0
  28. package/src/lib/interfaces/canvas.d.ts +14 -1
  29. package/src/lib/interfaces/property-editor.d.ts +1 -1
  30. package/src/lib/diagram/model/diagram-property.d.ts +0 -368
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metadev/daga",
3
- "version": "4.0.1",
3
+ "version": "4.1.0",
4
4
  "dependencies": {},
5
5
  "peerDependencies": {
6
6
  "d3": "^7.9.0",
package/src/index.d.ts CHANGED
@@ -7,9 +7,10 @@ export { DiagramUserSelection } from './lib/diagram/canvas/diagram-user-selectio
7
7
  export type { CollabAction, CollabActionSerialized } from './lib/diagram/collab/collab-action';
8
8
  export { CollabClient } from './lib/diagram/collab/collab-client';
9
9
  export type { CollabTimestamp, CollabTimestampSet } from './lib/diagram/collab/primitives';
10
- export type { CanvasConfig, GridConfig } from './lib/diagram/config/diagram-canvas-config';
11
- export type { ButtonsComponentConfig, ComponentsConfig, ConnectionTemplateConfig, ConnectionTypeConfig, DiagramConfig, ErrorsComponentConfig, FieldConfig, NodeTemplateConfig, NodeTypeConfig, PaletteComponentConfig, PaletteSectionConfig, PortConfig, PortTypeConfig, PropertyEditorComponentConfig, SectionConfig, SectionGridConfig, UserActionConfig } from './lib/diagram/config/diagram-config';
12
- export type { ImageLook, ImageLookConfig, Look, LookConfig, MarkerImageLook, MarkerImageLookConfig, ShapedLook, ShapedLookConfig, StretchableImageLook, StretchableImageLookConfig } from './lib/diagram/config/diagram-look-config';
10
+ export type { CanvasConfig, GridConfig, GridStyle } from './lib/diagram/config/diagram-canvas-config';
11
+ export type { ButtonsComponentConfig, ComponentsConfig, ConnectionTemplateConfig, ErrorsComponentConfig, NodeTemplateConfig, PaletteComponentConfig, PaletteSectionConfig, PropertyEditorComponentConfig } from './lib/diagram/config/diagram-components-config';
12
+ export type { ConnectionTypeConfig, DiagramConfig, FieldConfig, NodeTypeConfig, PortConfig, PortTypeConfig, SectionConfig, SectionGridConfig, UserActionConfig } from './lib/diagram/config/diagram-config';
13
+ export type { ConnectionLook, ConnectionLookConfig, ImageLook, ImageLookConfig, Look, LookConfig, MarkerImageLook, MarkerImageLookConfig, ShapedLook, ShapedLookConfig, StretchableImageLook, StretchableImageLookConfig } from './lib/diagram/config/diagram-look-config';
13
14
  export { DagaExporter } from './lib/diagram/converters/daga-exporter';
14
15
  export { DagaImporter } from './lib/diagram/converters/daga-importer';
15
16
  export type { DagaConnection, DagaModel, DagaNode, DagaPort, DagaSection } from './lib/diagram/converters/daga-model';
@@ -39,10 +40,12 @@ export { DiagramNode, DiagramNodeSet, DiagramNodeType, filterByOnlyAncestors, fi
39
40
  export type { DiagramNodeGeometry } from './lib/diagram/model/diagram-node';
40
41
  export { DiagramObject, DiagramObjectSet } from './lib/diagram/model/diagram-object';
41
42
  export { DiagramPort, DiagramPortSet, DiagramPortType } from './lib/diagram/model/diagram-port';
42
- export { diff, equals, isObject, Property, PropertySet, Type, ValueSet } from './lib/diagram/model/diagram-property';
43
- export type { Option } from './lib/diagram/model/diagram-property';
44
43
  export { DiagramSection, DiagramSectionSet } from './lib/diagram/model/diagram-section';
45
44
  export type { DiagramSectionGeometry } from './lib/diagram/model/diagram-section';
45
+ export { Property, PropertySet, Type } from './lib/diagram/property/property';
46
+ export type { Option } from './lib/diagram/property/property';
47
+ export { diff, equals, isObject } from './lib/diagram/property/property-util';
48
+ export { ValueSet } from './lib/diagram/property/value';
46
49
  export type { DiagramError } from './lib/errors/diagram-error';
47
50
  export type { DiagramValidator } from './lib/errors/diagram-validator';
48
51
  export type { Canvas } from './lib/interfaces/canvas';
@@ -7,6 +7,7 @@ import { DiagramField } from '../model/diagram-field';
7
7
  import { DiagramNode } from '../model/diagram-node';
8
8
  import { DiagramPort } from '../model/diagram-port';
9
9
  import { DiagramSection } from '../model/diagram-section';
10
+ import { DiagramCanvas } from './diagram-canvas';
10
11
  /**
11
12
  * Checks if the given mouse event was produced with a secondary button press.
12
13
  * @private
@@ -24,3 +25,12 @@ export declare const setCursorStyle: (style?: CursorStyle) => void;
24
25
  export declare const getRelatedNodeOrItself: (element: DiagramNode | DiagramSection | DiagramPort | DiagramField) => DiagramNode | DiagramSection | DiagramPort | DiagramField;
25
26
  export declare const initializeLook: (selection: d3.Selection<SVGGElement, DiagramNode | DiagramSection | DiagramPort, d3.BaseType, unknown>) => void;
26
27
  export declare const updateLook: (selection: d3.Selection<SVGGElement, DiagramNode | DiagramSection | DiagramPort, d3.BaseType, unknown>) => void;
28
+ export declare const GRID_DEFAULTS: {
29
+ enabled: boolean;
30
+ style: string;
31
+ color: string;
32
+ snap: boolean;
33
+ spacing: number;
34
+ thickness: number;
35
+ };
36
+ export declare const initializeGrid: (canvas: DiagramCanvas, canvasView: d3.Selection<SVGGElement, unknown, null, unknown>, backgroundPatternId: string) => void;
@@ -5,6 +5,7 @@ import { Canvas } from '../../interfaces/canvas';
5
5
  import { DiagramEditor } from '../../interfaces/diagram-editor';
6
6
  import { Point } from '../../util/canvas-util';
7
7
  import { CollabEngine } from '../collab/collab-engine';
8
+ import { GridStyle } from '../config/diagram-canvas-config';
8
9
  import { DiagramConfig } from '../config/diagram-config';
9
10
  import { ActionStack, DiagramAction, DiagramActionMethod, DiagramActions } from '../diagram-action';
10
11
  import { DiagramEvent } from '../diagram-event';
@@ -40,6 +41,7 @@ export declare class DiagramCanvas implements Canvas {
40
41
  readonly actionStack: ActionStack;
41
42
  readonly collabEngine: CollabEngine;
42
43
  backgroundColor: string;
44
+ gridStyle: GridStyle;
43
45
  gridSize: number;
44
46
  gridThickness: number;
45
47
  gridColor: string;
@@ -114,7 +116,8 @@ export declare class DiagramCanvas implements Canvas {
114
116
  updateDecoratorsInView(...ids: string[]): void;
115
117
  private updateConnectionLabelsInView;
116
118
  private updateConnectionMarkersInView;
117
- fitFieldRootInView(id: string): void;
119
+ fieldRootFitsInView(id: string): boolean;
120
+ fitFieldRootInView(id: string, shrink?: boolean): void;
118
121
  fitNodeInView(id: string): void;
119
122
  selectRoot(): d3.Selection<HTMLDivElement, unknown, null, unknown>;
120
123
  selectSVGElement(): d3.Selection<SVGElement, unknown, null, unknown>;
@@ -2,7 +2,7 @@ import { Canvas } from '../../interfaces/canvas';
2
2
  import { Point } from '../../util/canvas-util';
3
3
  import { DiagramElement, DiagramElementSet } from '../model/diagram-element';
4
4
  import { DiagramModel } from '../model/diagram-model';
5
- import { ValueSet } from '../model/diagram-property';
5
+ import { ValueSet } from '../property/value';
6
6
  /**
7
7
  * Text to display as the title of the property editor when editing the properties of a diagram's value set.
8
8
  * @private
@@ -2,7 +2,7 @@ import { Canvas } from '../../interfaces/canvas';
2
2
  import { Point } from '../../util/canvas-util';
3
3
  import { DagaConnection, DagaNode } from '../converters/daga-model';
4
4
  import { DiagramNodeGeometry } from '../model/diagram-node';
5
- import { ValueSet } from '../model/diagram-property';
5
+ import { ValueSet } from '../property/value';
6
6
  import { CollabTimestamp } from './primitives';
7
7
  /**
8
8
  * An action taken by a local or remote user.
@@ -32,7 +32,7 @@ export interface CollabAction {
32
32
  /**
33
33
  * @private
34
34
  */
35
- export type CollabActionSerialized = AddNodeSerialized | ApplyLayoutSerialized | MoveSerialized | SetGeometrySerialized | SetParentSerialized | AddConnectionSerialized | EditFieldSerialized | UpdateValuesSerialized | SetSelfRemovedSerialized | PasteSerialized;
35
+ export type CollabActionSerialized = AddNodeSerialized | AddSectionSerialized | ApplyLayoutSerialized | MoveSerialized | SetGeometrySerialized | SetParentSerialized | AddConnectionSerialized | EditFieldSerialized | UpdateValuesSerialized | SetSelfRemovedSerialized | PasteSerialized;
36
36
  /**
37
37
  * @private
38
38
  */
@@ -69,6 +69,36 @@ export declare class AddNodeCollabAction implements CollabAction {
69
69
  serialize(): AddNodeSerialized;
70
70
  static deserialize(canvas: Canvas, serialized: AddNodeSerialized): AddNodeCollabAction;
71
71
  }
72
+ /**
73
+ * @private
74
+ */
75
+ export type AddSectionSerialized = {
76
+ type: 'addSection';
77
+ nodeId: string;
78
+ copyColumnIndex: number | undefined;
79
+ copyRowIndex: number | undefined;
80
+ removeColumnIndex: number | undefined;
81
+ removeRowIndex: number | undefined;
82
+ timestamp: CollabTimestamp;
83
+ };
84
+ /**
85
+ * Collaborative action which consists of adding or removing sections in a node.
86
+ * @private
87
+ * @see AddNodeAction
88
+ */
89
+ export declare class AddSectionCollabAction implements CollabAction {
90
+ readonly canvas: Canvas;
91
+ readonly nodeId: string;
92
+ readonly copyColumnIndex: number | undefined;
93
+ readonly copyRowIndex: number | undefined;
94
+ readonly removeColumnIndex: number | undefined;
95
+ readonly removeRowIndex: number | undefined;
96
+ readonly timestamp: CollabTimestamp;
97
+ constructor(canvas: Canvas, nodeId: string, copyColumnIndex: number | undefined, copyRowIndex: number | undefined, removeColumnIndex: number | undefined, removeRowIndex: number | undefined, timestamp: CollabTimestamp);
98
+ do(): void;
99
+ serialize(): AddSectionSerialized;
100
+ static deserialize(canvas: Canvas, serialized: AddSectionSerialized): AddSectionCollabAction;
101
+ }
72
102
  /**
73
103
  * @private
74
104
  */
@@ -37,6 +37,7 @@ export interface CanvasConfig {
37
37
  */
38
38
  priorityThresholds?: number[];
39
39
  }
40
+ export type GridStyle = 'dots' | 'lines';
40
41
  /**
41
42
  * Configuration of the guide grid in the background of the diagram.
42
43
  */
@@ -46,6 +47,11 @@ export interface GridConfig {
46
47
  * @default true
47
48
  */
48
49
  enabled?: boolean;
50
+ /**
51
+ * The style of the grid.
52
+ * @default "dots"
53
+ */
54
+ style?: GridStyle;
49
55
  /**
50
56
  * Color of grid elements such as the points or axes.
51
57
  * @default "rgba(0, 0, 0, 0.1)"
@@ -0,0 +1,249 @@
1
+ import { Corner, Side } from '../../util/svg-util';
2
+ import { FieldConfig } from './diagram-config';
3
+ import { ImageLookConfig, ShapedLookConfig, StretchableImageLookConfig } from './diagram-look-config';
4
+ /**
5
+ * Configuration for the components of the diagram.
6
+ * @public
7
+ */
8
+ export type ComponentsConfig = {
9
+ /**
10
+ * Configuration for the buttons component in the diagram.
11
+ * If left undefined, it is interpreted as disabling the buttons component,
12
+ * same as if the attribute `enabled` in its configuration was set to `false`.
13
+ */
14
+ buttons?: ButtonsComponentConfig;
15
+ /**
16
+ * Configuration for the errors component in the diagram.
17
+ * If left undefined, it is interpreted as disabling the errors component,
18
+ * same as if the attribute `enabled` in its configuration was set to `false`.
19
+ */
20
+ errors?: ErrorsComponentConfig;
21
+ /**
22
+ * Configuration for the palette component in the diagram.
23
+ * If left undefined, it is interpreted as disabling the palette component,
24
+ * same as if the attribute `enabled` in its configuration was set to `false`.
25
+ */
26
+ palette?: PaletteComponentConfig;
27
+ /**
28
+ * Configuration for the property editor component in the diagram.
29
+ * If left undefined, it is interpreted as disabling the property editor component,
30
+ * same as if the attribute `enabled` in its configuration was set to `false`.
31
+ */
32
+ propertyEditor?: PropertyEditorComponentConfig;
33
+ };
34
+ /**
35
+ * Configuration for the buttons component in a diagram.
36
+ * @public
37
+ * @see DiagramButtonsComponent
38
+ */
39
+ export interface ButtonsComponentConfig {
40
+ /**
41
+ * Whether this component is present in the diagram.
42
+ * @default true
43
+ */
44
+ enabled?: boolean;
45
+ /**
46
+ * Location of this component in the screen.
47
+ * @default 'bottom-right'
48
+ */
49
+ location?: Corner;
50
+ /**
51
+ * Direction that this component extends towards.
52
+ * @default 'top'
53
+ */
54
+ direction?: Side;
55
+ /**
56
+ * Whether to enable the user action (undo, redo) buttons in this component.
57
+ * @default true
58
+ */
59
+ enableAction?: boolean;
60
+ /**
61
+ * Whether to enable the filter button in this component.
62
+ * @default false
63
+ */
64
+ enableFilter?: boolean;
65
+ /**
66
+ * Whether to enable the layout button in this component.
67
+ * @default false
68
+ */
69
+ enableLayout?: boolean;
70
+ /**
71
+ * Whether to enable the user selection (copy, paste, cut, delete) buttons in this component.
72
+ * @default true
73
+ */
74
+ enableSelection?: boolean;
75
+ /**
76
+ * Whether to enable the zoom buttons in this component.
77
+ * @default true
78
+ */
79
+ enableZoom?: boolean;
80
+ }
81
+ /**
82
+ * Configuration for the errors component in a diagram.
83
+ * @public
84
+ * @see ErrorsComponent
85
+ */
86
+ export interface ErrorsComponentConfig {
87
+ /**
88
+ * Whether this component is present in the diagram.
89
+ * @default true
90
+ */
91
+ enabled?: boolean;
92
+ }
93
+ /**
94
+ * Configuration for the palette component in a diagram.
95
+ * @public
96
+ * @see PaletteComponent
97
+ */
98
+ export interface PaletteComponentConfig {
99
+ /**
100
+ * Whether this component is present in the diagram.
101
+ * @default true
102
+ */
103
+ enabled?: boolean;
104
+ /**
105
+ * Location of this component in the screen.
106
+ * @default 'top-left'
107
+ */
108
+ location?: Corner;
109
+ /**
110
+ * Direction that this component extends towards.
111
+ * @default 'bottom'
112
+ */
113
+ direction?: Side;
114
+ /**
115
+ * Dimension of this component in the direction perpendicular to the direction that it extends towards.
116
+ * @default '12rem'
117
+ */
118
+ width?: string;
119
+ /**
120
+ * Gap between the templates in this palette.
121
+ * @default '1rem'
122
+ */
123
+ gap?: string;
124
+ /**
125
+ * Configuration for the sections of this palette. By default, no sections are created.
126
+ * @default undefined
127
+ */
128
+ sections?: PaletteSectionConfig[];
129
+ }
130
+ /**
131
+ * Configuration for the property editor component in a diagram.
132
+ * @public
133
+ * @see PropertyEditorComponent
134
+ */
135
+ export interface PropertyEditorComponentConfig {
136
+ /**
137
+ * Whether this component is present in the diagram.
138
+ * @default true
139
+ */
140
+ enabled?: boolean;
141
+ /**
142
+ * Location of this component in the screen.
143
+ * @default 'top-right'
144
+ */
145
+ location?: Corner;
146
+ /**
147
+ * Direction that this component extends towards.
148
+ * @default 'bottom'
149
+ */
150
+ direction?: Side;
151
+ /**
152
+ * Dimension of this component in the direction perpendicular to the direction that it extends towards.
153
+ * @default '24rem'
154
+ */
155
+ width?: string;
156
+ }
157
+ /**
158
+ * Configuration for a palette.
159
+ * @public
160
+ * @see PaletteComponent
161
+ */
162
+ export interface PaletteSectionConfig {
163
+ /**
164
+ * Name of this palette. Displayed in the tab of this palette in the palette component. Can be left undefined if this is the only palette.
165
+ */
166
+ name?: string;
167
+ /**
168
+ * Categories of this palette. Used to enable displaying one of different categories of templates as defined here. Can be left undefined if there are no categories.
169
+ */
170
+ categories?: {
171
+ [key: string]: (NodeTemplateConfig | ConnectionTemplateConfig)[];
172
+ };
173
+ /**
174
+ * List of templates that are always displayed in this palette. Can be left undefined.
175
+ */
176
+ templates?: (NodeTemplateConfig | ConnectionTemplateConfig)[];
177
+ }
178
+ /**
179
+ * Configuration for a template of a node in a palette.
180
+ * @public
181
+ * @see PaletteComponent
182
+ */
183
+ export interface NodeTemplateConfig {
184
+ /**
185
+ * String used to indicate that this is a template of a node.
186
+ */
187
+ templateType: 'node';
188
+ /**
189
+ * Id of the type of node of this template. Must correspond to the id of a type of node defined in the nodeTypes list.
190
+ */
191
+ type: string;
192
+ /**
193
+ * 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.
194
+ */
195
+ look?: ShapedLookConfig | ImageLookConfig | StretchableImageLookConfig;
196
+ /**
197
+ * Label of this template as it appears on the palette and label that will be given to nodes created from this template.
198
+ */
199
+ label?: string;
200
+ /**
201
+ * Look of the label of this template as it appears on the palette. By default, the label of the type of node is used.
202
+ */
203
+ labelLook?: FieldConfig | null;
204
+ /**
205
+ * Default values of the properties of nodes created from this template.
206
+ */
207
+ values?: {
208
+ [key: string]: unknown;
209
+ };
210
+ }
211
+ /**
212
+ * Configuration for a template of a connection in a palette.
213
+ * @public
214
+ * @see PaletteComponent
215
+ */
216
+ export interface ConnectionTemplateConfig {
217
+ /**
218
+ * String used to indicate that this is a template of a connection.
219
+ */
220
+ templateType: 'connection';
221
+ /**
222
+ * Id of the type of connection of this template. Must correspond to the id of a type of connection defined in the connectionTypes list.
223
+ */
224
+ type: string;
225
+ /**
226
+ * Label of this template as it appears on the palette.
227
+ */
228
+ label: string;
229
+ /**
230
+ * Background color of this template as it appears on the palette.
231
+ */
232
+ backgroundColor: string;
233
+ /**
234
+ * File path of the background image of this template as it appears on the palette.
235
+ */
236
+ icon: string;
237
+ /**
238
+ * File path of the background image of this template as it appears on the palette when this connection type is selected.
239
+ */
240
+ selectedIcon: string;
241
+ /**
242
+ * Width of this template in diagram units as it appears on the palette.
243
+ */
244
+ width: number;
245
+ /**
246
+ * Height of this template in diagram units as it appears on the palette.
247
+ */
248
+ height: number;
249
+ }