@metadev/daga 4.0.0 → 4.0.2

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 (29) hide show
  1. package/Changelog.md +21 -0
  2. package/index.cjs.js +349 -221
  3. package/index.esm.js +349 -221
  4. package/package.json +1 -1
  5. package/src/index.d.ts +8 -4
  6. package/src/lib/diagram/canvas/diagram-canvas-util.d.ts +10 -0
  7. package/src/lib/diagram/canvas/diagram-canvas.d.ts +2 -0
  8. package/src/lib/diagram/canvas/diagram-context-menu.d.ts +6 -1
  9. package/src/lib/diagram/canvas/diagram-user-selection.d.ts +1 -1
  10. package/src/lib/diagram/collab/collab-action.d.ts +1 -1
  11. package/src/lib/diagram/config/diagram-canvas-config.d.ts +103 -0
  12. package/src/lib/diagram/config/diagram-components-config.d.ts +249 -0
  13. package/src/lib/diagram/config/diagram-config.d.ts +35 -312
  14. package/src/lib/diagram/model/diagram-connection.d.ts +3 -2
  15. package/src/lib/diagram/model/diagram-decorator.d.ts +0 -1
  16. package/src/lib/diagram/model/diagram-field.d.ts +0 -1
  17. package/src/lib/diagram/model/diagram-model.d.ts +2 -1
  18. package/src/lib/diagram/model/diagram-node.d.ts +6 -3
  19. package/src/lib/diagram/model/diagram-object.d.ts +0 -1
  20. package/src/lib/diagram/model/diagram-port.d.ts +1 -1
  21. package/src/lib/diagram/model/diagram-section.d.ts +1 -1
  22. package/src/lib/diagram/property/property-util.d.ts +61 -0
  23. package/src/lib/diagram/property/property.d.ts +146 -0
  24. package/src/lib/diagram/property/value.d.ts +163 -0
  25. package/src/lib/interfaces/canvas.d.ts +6 -0
  26. package/src/lib/interfaces/property-editor.d.ts +1 -1
  27. package/src/lib/util/html-util.d.ts +1 -0
  28. package/src/lib/diagram/model/diagram-property.d.ts +0 -368
  29. /package/src/lib/diagram/config/{diagram-look.d.ts → diagram-look-config.d.ts} +0 -0
@@ -1,8 +1,10 @@
1
1
  import { Point } from '../../util/canvas-util';
2
- import { Corner, HorizontalAlign, Side, VerticalAlign } from '../../util/svg-util';
2
+ import { HorizontalAlign, Side, VerticalAlign } from '../../util/svg-util';
3
3
  import { DiagramActions } from '../diagram-action';
4
- import { Property } from '../model/diagram-property';
5
- import { ConnectionLookConfig, ImageLookConfig, MarkerImageLookConfig, ShapedLookConfig, StretchableImageLookConfig } from './diagram-look';
4
+ import { Property } from '../property/property';
5
+ import { CanvasConfig } from './diagram-canvas-config';
6
+ import { ConnectionLookConfig, ImageLookConfig, MarkerImageLookConfig, ShapedLookConfig, StretchableImageLookConfig } from './diagram-look-config';
7
+ import { ComponentsConfig } from './diagram-components-config';
6
8
  /**
7
9
  * The configuration for a diagram.
8
10
  * @public
@@ -86,69 +88,6 @@ export interface DiagramConfig {
86
88
  */
87
89
  properties?: Property[];
88
90
  }
89
- /**
90
- * The configuration for the visual behavior of a diagram in the user interface.
91
- * @public
92
- */
93
- export interface CanvasConfig {
94
- /**
95
- * Configuration for the grid in the canvas.
96
- * If left undefined, it is interpreted as disabling the grid,
97
- * same as if the attribute `enabled` in its configuration was set to `false`.
98
- */
99
- grid?: GridConfig;
100
- /**
101
- * Background color of this diagram.
102
- * @default "#FFFFFF"
103
- */
104
- backgroundColor?: string;
105
- /**
106
- * The factor by which the zoom level increases or decreases when the user users buttons or keys to zoom in or out. Should be above 1.
107
- * @default 2
108
- */
109
- zoomFactor?: number;
110
- /**
111
- * The rate by which the view of the canvas moves when the user users buttons or keys to pan at a default zoom level in diagram units. Should be above 1.
112
- * @default 100
113
- */
114
- panRate?: number;
115
- /**
116
- * Possible values of the priority threshold that the user can toggle between to hide nodes whose priority value is below it.
117
- * If it is possible to toggle the priority threshold via the filter button, it should have at least two values.
118
- * @default []
119
- */
120
- priorityThresholds?: number[];
121
- }
122
- /**
123
- * Configuration of the guide grid in the background of the diagram.
124
- */
125
- export interface GridConfig {
126
- /**
127
- * Whether the grid is present in the diagram.
128
- * @default true
129
- */
130
- enabled?: boolean;
131
- /**
132
- * Color of grid elements such as the points or axes.
133
- * @default "rgba(0, 0, 0, 0.1)"
134
- */
135
- color?: string;
136
- /**
137
- * When true, the user moving or stretching nodes will cause their corners to automatically snap to the closest grid point.
138
- * @default false
139
- */
140
- snap?: boolean;
141
- /**
142
- * Distance between each point of the grid of this diagram in diagram units.
143
- * @default 10
144
- */
145
- spacing?: number;
146
- /**
147
- * In a range between 0 and 1, how thick the points of the grid are relative to the distance between them.
148
- * @default 0.05
149
- */
150
- thickness?: number;
151
- }
152
91
  /**
153
92
  * Configuration for which user actions are allowed in a diagram.
154
93
  * @public
@@ -156,252 +95,6 @@ export interface GridConfig {
156
95
  export type UserActionConfig = {
157
96
  [key in DiagramActions]?: boolean;
158
97
  };
159
- /**
160
- * Configuration for the components of the diagram.
161
- * @public
162
- */
163
- export type ComponentsConfig = {
164
- /**
165
- * Configuration for the buttons component in the diagram.
166
- * If left undefined, it is interpreted as disabling the buttons component,
167
- * same as if the attribute `enabled` in its configuration was set to `false`.
168
- */
169
- buttons?: ButtonsComponentConfig;
170
- /**
171
- * Configuration for the errors component in the diagram.
172
- * If left undefined, it is interpreted as disabling the errors component,
173
- * same as if the attribute `enabled` in its configuration was set to `false`.
174
- */
175
- errors?: ErrorsComponentConfig;
176
- /**
177
- * Configuration for the palette component in the diagram.
178
- * If left undefined, it is interpreted as disabling the palette component,
179
- * same as if the attribute `enabled` in its configuration was set to `false`.
180
- */
181
- palette?: PaletteComponentConfig;
182
- /**
183
- * Configuration for the property editor component in the diagram.
184
- * If left undefined, it is interpreted as disabling the property editor component,
185
- * same as if the attribute `enabled` in its configuration was set to `false`.
186
- */
187
- propertyEditor?: PropertyEditorComponentConfig;
188
- };
189
- /**
190
- * Configuration for the buttons component in a diagram.
191
- * @public
192
- * @see DiagramButtonsComponent
193
- */
194
- export interface ButtonsComponentConfig {
195
- /**
196
- * Whether this component is present in the diagram.
197
- * @default true
198
- */
199
- enabled?: boolean;
200
- /**
201
- * Location of this component in the screen.
202
- * @default 'bottom-right'
203
- */
204
- location?: Corner;
205
- /**
206
- * Direction that this component extends towards.
207
- * @default 'top'
208
- */
209
- direction?: Side;
210
- /**
211
- * Whether to enable the user action (undo, redo) buttons in this component.
212
- * @default true
213
- */
214
- enableAction?: boolean;
215
- /**
216
- * Whether to enable the filter button in this component.
217
- * @default false
218
- */
219
- enableFilter?: boolean;
220
- /**
221
- * Whether to enable the layout button in this component.
222
- * @default false
223
- */
224
- enableLayout?: boolean;
225
- /**
226
- * Whether to enable the user selection (copy, paste, cut, delete) buttons in this component.
227
- * @default true
228
- */
229
- enableSelection?: boolean;
230
- /**
231
- * Whether to enable the zoom buttons in this component.
232
- * @default true
233
- */
234
- enableZoom?: boolean;
235
- }
236
- /**
237
- * Configuration for the errors component in a diagram.
238
- * @public
239
- * @see ErrorsComponent
240
- */
241
- export interface ErrorsComponentConfig {
242
- /**
243
- * Whether this component is present in the diagram.
244
- * @default true
245
- */
246
- enabled?: boolean;
247
- }
248
- /**
249
- * Configuration for the palette component in a diagram.
250
- * @public
251
- * @see PaletteComponent
252
- */
253
- export interface PaletteComponentConfig {
254
- /**
255
- * Whether this component is present in the diagram.
256
- * @default true
257
- */
258
- enabled?: boolean;
259
- /**
260
- * Location of this component in the screen.
261
- * @default 'top-left'
262
- */
263
- location?: Corner;
264
- /**
265
- * Direction that this component extends towards.
266
- * @default 'bottom'
267
- */
268
- direction?: Side;
269
- /**
270
- * Dimension of this component in the direction perpendicular to the direction that it extends towards.
271
- * @default '12rem'
272
- */
273
- width?: string;
274
- /**
275
- * Gap between the templates in this palette.
276
- * @default '1rem'
277
- */
278
- gap?: string;
279
- /**
280
- * Configuration for the sections of this palette. By default, no sections are created.
281
- * @default undefined
282
- */
283
- sections?: PaletteSectionConfig[];
284
- }
285
- /**
286
- * Configuration for the property editor component in a diagram.
287
- * @public
288
- * @see PropertyEditorComponent
289
- */
290
- export interface PropertyEditorComponentConfig {
291
- /**
292
- * Whether this component is present in the diagram.
293
- * @default true
294
- */
295
- enabled?: boolean;
296
- /**
297
- * Location of this component in the screen.
298
- * @default 'top-right'
299
- */
300
- location?: Corner;
301
- /**
302
- * Direction that this component extends towards.
303
- * @default 'bottom'
304
- */
305
- direction?: Side;
306
- /**
307
- * Dimension of this component in the direction perpendicular to the direction that it extends towards.
308
- * @default '24rem'
309
- */
310
- width?: string;
311
- }
312
- /**
313
- * Configuration for a palette.
314
- * @public
315
- * @see PaletteComponent
316
- */
317
- export interface PaletteSectionConfig {
318
- /**
319
- * 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.
320
- */
321
- name?: string;
322
- /**
323
- * 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.
324
- */
325
- categories?: {
326
- [key: string]: (NodeTemplateConfig | ConnectionTemplateConfig)[];
327
- };
328
- /**
329
- * List of templates that are always displayed in this palette. Can be left undefined.
330
- */
331
- templates?: (NodeTemplateConfig | ConnectionTemplateConfig)[];
332
- }
333
- /**
334
- * Configuration for a template of a node in a palette.
335
- * @public
336
- * @see PaletteComponent
337
- */
338
- export interface NodeTemplateConfig {
339
- /**
340
- * String used to indicate that this is a template of a node.
341
- */
342
- templateType: 'node';
343
- /**
344
- * Id of the type of node of this template. Must correspond to the id of a type of node defined in the nodeTypes list.
345
- */
346
- type: string;
347
- /**
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.
349
- */
350
- look?: ShapedLookConfig | ImageLookConfig | StretchableImageLookConfig;
351
- /**
352
- * Label of this template as it appears on the palette and label that will be given to nodes created from this template.
353
- */
354
- label?: string;
355
- /**
356
- * Look of the label of this template as it appears on the palette. By default, the label of the type of node is used.
357
- */
358
- labelLook?: FieldConfig | null;
359
- /**
360
- * Default values of the properties of nodes created from this template.
361
- */
362
- values?: {
363
- [key: string]: unknown;
364
- };
365
- }
366
- /**
367
- * Configuration for a template of a connection in a palette.
368
- * @public
369
- * @see PaletteComponent
370
- */
371
- export interface ConnectionTemplateConfig {
372
- /**
373
- * String used to indicate that this is a template of a connection.
374
- */
375
- templateType: 'connection';
376
- /**
377
- * Id of the type of connection of this template. Must correspond to the id of a type of connection defined in the connectionTypes list.
378
- */
379
- type: string;
380
- /**
381
- * Label of this template as it appears on the palette.
382
- */
383
- label: string;
384
- /**
385
- * Background color of this template as it appears on the palette.
386
- */
387
- backgroundColor: string;
388
- /**
389
- * File path of the background image of this template as it appears on the palette.
390
- */
391
- icon: string;
392
- /**
393
- * File path of the background image of this template as it appears on the palette when this connection type is selected.
394
- */
395
- selectedIcon: string;
396
- /**
397
- * Width of this template in diagram units as it appears on the palette.
398
- */
399
- width: number;
400
- /**
401
- * Height of this template in diagram units as it appears on the palette.
402
- */
403
- height: number;
404
- }
405
98
  /**
406
99
  * Configuration for a type of node.
407
100
  * @public
@@ -466,6 +159,11 @@ export interface NodeTypeConfig {
466
159
  * @default []
467
160
  */
468
161
  ports?: PortConfig[];
162
+ /**
163
+ * Configuration of the decorators of nodes of this type.
164
+ * @default []
165
+ */
166
+ decorators?: DecoratorConfig[];
469
167
  /**
470
168
  * Configuration of the look of nodes of this type as they should appear to the user.
471
169
  */
@@ -620,6 +318,31 @@ export interface FieldConfig {
620
318
  */
621
319
  fit?: boolean;
622
320
  }
321
+ /**
322
+ * Configuration for a decorator that is part of another element.
323
+ * @public
324
+ * @see DiagramDecorator
325
+ */
326
+ export interface DecoratorConfig {
327
+ /**
328
+ * Coordinates of this decorator relative to its root element's coordinates.
329
+ */
330
+ coords: Point;
331
+ /**
332
+ * Dimension of this decorator along the x axis.
333
+ * @public
334
+ */
335
+ width: number;
336
+ /**
337
+ * Dimension of this decorator along the y axis.
338
+ * @public
339
+ */
340
+ height: number;
341
+ /**
342
+ * Inner HTML of this decorator.
343
+ */
344
+ html: string;
345
+ }
623
346
  /**
624
347
  * Configuration for the grid of sections of a node.
625
348
  * @public
@@ -2,12 +2,13 @@ import { Point } from '../../util/canvas-util';
2
2
  import { LineShape, LineStyle } from '../../util/line';
3
3
  import { Side } from '../../util/svg-util';
4
4
  import { ConnectionTypeConfig, FieldConfig } from '../config/diagram-config';
5
- import { ConnectionLook, ConnectionLookConfig, MarkerImageLook, MarkerImageLookConfig } from '../config/diagram-look';
5
+ import { ConnectionLook, ConnectionLookConfig, MarkerImageLook, MarkerImageLookConfig } from '../config/diagram-look-config';
6
6
  import { DiagramElement, DiagramElementSet } from './diagram-element';
7
7
  import { DiagramEntity, DiagramEntitySet } from './diagram-entity';
8
8
  import { DiagramModel } from './diagram-model';
9
9
  import { DiagramPort } from './diagram-port';
10
- import { PropertySet, ValueSet } from './diagram-property';
10
+ import { PropertySet } from '../property/property';
11
+ import { ValueSet } from '../property/value';
11
12
  /**
12
13
  * Default values of the parameters of a diagram connection.
13
14
  * @private
@@ -36,7 +36,6 @@ export declare class DiagramDecorator extends DiagramElement {
36
36
  priority: number;
37
37
  html: string;
38
38
  constructor(model: DiagramModel, rootElement: DiagramNode | DiagramSection | undefined, coords: Point, width: number, height: number, priority: number, html: string, id: string);
39
- select(): d3.Selection<SVGGElement, unknown, null, unknown> | undefined;
40
39
  get removed(): boolean;
41
40
  updateInView(): void;
42
41
  raise(): void;
@@ -110,7 +110,6 @@ export declare class DiagramField extends DiagramElement {
110
110
  */
111
111
  fit: boolean;
112
112
  constructor(model: DiagramModel, rootElement: (LabeledElement & DiagramElement) | undefined, coords: Point, width: number, height: number, fontSize: number, fontFamily: string | null, color: string, selectedColor: string, horizontalAlign: HorizontalAlign, verticalAlign: VerticalAlign, text: string, editable: boolean, fit: boolean);
113
- select(): d3.Selection<SVGGElement, unknown, null, unknown> | undefined;
114
113
  get removed(): boolean;
115
114
  updateInView(): void;
116
115
  raise(): void;
@@ -1,11 +1,12 @@
1
1
  import { Canvas } from '../../interfaces/canvas';
2
+ import { Property } from '../property/property';
3
+ import { ValueSet } from '../property/value';
2
4
  import { DiagramConnectionSet } from './diagram-connection';
3
5
  import { DiagramDecoratorSet } from './diagram-decorator';
4
6
  import { DiagramFieldSet } from './diagram-field';
5
7
  import { DiagramNodeSet } from './diagram-node';
6
8
  import { DiagramObjectSet } from './diagram-object';
7
9
  import { DiagramPortSet } from './diagram-port';
8
- import { Property, ValueSet } from './diagram-property';
9
10
  import { DiagramSectionSet } from './diagram-section';
10
11
  /**
11
12
  * Stores the data of a diagram.
@@ -1,8 +1,10 @@
1
1
  import { Point } from '../../util/canvas-util';
2
2
  import { Side } from '../../util/svg-util';
3
3
  import { CollabTimestamp } from '../collab/primitives';
4
- import { FieldConfig, NodeTypeConfig, PortConfig } from '../config/diagram-config';
5
- import { ImageLook, ImageLookConfig, ShapedLook, ShapedLookConfig, StretchableImageLook, StretchableImageLookConfig } from '../config/diagram-look';
4
+ import { DecoratorConfig, FieldConfig, NodeTypeConfig, PortConfig } from '../config/diagram-config';
5
+ import { ImageLook, ImageLookConfig, ShapedLook, ShapedLookConfig, StretchableImageLook, StretchableImageLookConfig } from '../config/diagram-look-config';
6
+ import { PropertySet } from '../property/property';
7
+ import { ValueSet } from '../property/value';
6
8
  import { DiagramConnection } from './diagram-connection';
7
9
  import { DiagramDecorator } from './diagram-decorator';
8
10
  import { DiagramElement, DiagramElementSet } from './diagram-element';
@@ -10,7 +12,6 @@ import { DiagramEntity, DiagramEntitySet } from './diagram-entity';
10
12
  import { DiagramField, LabeledElement } from './diagram-field';
11
13
  import { DiagramModel } from './diagram-model';
12
14
  import { DiagramPort } from './diagram-port';
13
- import { PropertySet, ValueSet } from './diagram-property';
14
15
  import { DiagramSection, DiagramSectionGeometry, DiagramSectionGrid } from './diagram-section';
15
16
  /**
16
17
  * Default values of the look of a diagram node.
@@ -34,6 +35,7 @@ export declare const DIAGRAM_NODE_TYPE_DEFAULTS: {
34
35
  padding: number;
35
36
  label: null;
36
37
  ports: never[];
38
+ decorators: never[];
37
39
  sectionGrid: null;
38
40
  look: ShapedLookConfig;
39
41
  isUnique: boolean;
@@ -80,6 +82,7 @@ export declare class DiagramNodeType implements DiagramEntity {
80
82
  topPadding: number;
81
83
  label: FieldConfig | null;
82
84
  ports: PortConfig[];
85
+ decorators: DecoratorConfig[];
83
86
  sectionGrid: DiagramSectionGrid | null;
84
87
  defaultLook: NodeLook;
85
88
  selectedLook: NodeLook;
@@ -25,7 +25,6 @@ export declare class DiagramObject extends DiagramElement {
25
25
  priority: number;
26
26
  html: string;
27
27
  constructor(model: DiagramModel, coords: Point, width: number, height: number, priority: number, html: string, id: string);
28
- select(): d3.Selection<SVGGElement, unknown, null, unknown> | undefined;
29
28
  get removed(): boolean;
30
29
  updateInView(): void;
31
30
  raise(): void;
@@ -1,7 +1,7 @@
1
1
  import { Point } from '../../util/canvas-util';
2
2
  import { Side } from '../../util/svg-util';
3
3
  import { FieldConfig, PortTypeConfig } from '../config/diagram-config';
4
- import { ImageLook, ImageLookConfig, ShapedLook, ShapedLookConfig } from '../config/diagram-look';
4
+ import { ImageLook, ImageLookConfig, ShapedLook, ShapedLookConfig } from '../config/diagram-look-config';
5
5
  import { DiagramConnection } from './diagram-connection';
6
6
  import { DiagramElement, DiagramElementSet } from './diagram-element';
7
7
  import { DiagramEntity, DiagramEntitySet } from './diagram-entity';
@@ -1,7 +1,7 @@
1
1
  import { Point } from '../../util/canvas-util';
2
2
  import { Side } from '../../util/svg-util';
3
3
  import { FieldConfig, PortConfig, SectionConfig, SectionGridConfig } from '../config/diagram-config';
4
- import { ImageLookConfig, ShapedLookConfig, StretchableImageLookConfig } from '../config/diagram-look';
4
+ import { ImageLookConfig, ShapedLookConfig, StretchableImageLookConfig } from '../config/diagram-look-config';
5
5
  import { DiagramConnection } from './diagram-connection';
6
6
  import { DiagramDecorator } from './diagram-decorator';
7
7
  import { DiagramElement, DiagramElementSet } from './diagram-element';
@@ -0,0 +1,61 @@
1
+ import { ValueSet } from './value';
2
+ /**
3
+ * Checks if the given value is not empty.
4
+ * @private
5
+ * @param a A value.
6
+ * @returns `true` if the given value is not `undefined`, `null`, `''`, `[]` or `{}`; `false` otherwise.
7
+ */
8
+ export declare const empty: (a: unknown) => boolean;
9
+ /**
10
+ * Checks whether the given values are equal.
11
+ * @public
12
+ * @param a A value.
13
+ * @param b A value.
14
+ * @returns `true` if the given values are equal, `false` otherwise.
15
+ */
16
+ export declare const equals: (a: unknown, b: unknown) => boolean;
17
+ /**
18
+ * Calculates the differences between the two given objects and returns two objects containing the differences in each relative to the other.
19
+ *
20
+ * For each key that holds a different value in the two objects, the resulting objects will contain the differences in the values under that key.
21
+ *
22
+ * This function is recursive, that is, if the value under the key is an object, the function will be applied to that value recursively.
23
+ *
24
+ * @public
25
+ * @param a An object.
26
+ * @param b An object.
27
+ * @returns A tuple of two objects with each containing the keys that have a different value in the corresponding argument compared to the other argument.
28
+ */
29
+ export declare const diff: (a: {
30
+ [key: string]: unknown;
31
+ }, b: {
32
+ [key: string]: unknown;
33
+ }) => [{
34
+ [key: string]: unknown;
35
+ }, {
36
+ [key: string]: unknown;
37
+ }];
38
+ /**
39
+ * Calculates the differences between the two given values of a valueset and returns two objects containing the differences in each relative to the other.
40
+ *
41
+ * @param a An object.
42
+ * @param b An object.
43
+ * @param valueSet A ValueSet to use as reference for the keys and types of each property.
44
+ * @returns A tuple of two objects with each containing the keys that have a different value in the corresponding argument compared to the other argument.
45
+ */
46
+ export declare const diffProperties: (a: {
47
+ [key: string]: unknown;
48
+ }, b: {
49
+ [key: string]: unknown;
50
+ }, valueSet: ValueSet) => [{
51
+ [key: string]: unknown;
52
+ }, {
53
+ [key: string]: unknown;
54
+ }];
55
+ /**
56
+ * Checks if the given value is an object.
57
+ * @public
58
+ * @param x A value.
59
+ * @returns `true` if the given value is an object, `false` otherwise.
60
+ */
61
+ export declare const isObject: (x: unknown) => boolean;