@metadev/daga 4.1.0 → 4.2.1

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": "4.1.0",
3
+ "version": "4.2.1",
4
4
  "dependencies": {},
5
5
  "peerDependencies": {
6
6
  "d3": "^7.9.0",
@@ -27,11 +27,11 @@
27
27
  "./package.json": "./package.json",
28
28
  ".": {
29
29
  "module": "./index.esm.js",
30
- "types": "./index.esm.d.ts",
30
+ "types": "./index.d.ts",
31
31
  "import": "./index.cjs.mjs",
32
32
  "default": "./index.cjs.js"
33
33
  }
34
34
  },
35
35
  "module": "./index.esm.js",
36
- "types": "./index.esm.d.ts"
36
+ "types": "./index.d.ts"
37
37
  }
@@ -118,7 +118,7 @@ export declare class DiagramCanvas implements Canvas {
118
118
  private updateConnectionMarkersInView;
119
119
  fieldRootFitsInView(id: string): boolean;
120
120
  fitFieldRootInView(id: string, shrink?: boolean): void;
121
- fitNodeInView(id: string): void;
121
+ fitNodeInView(id: string, shrink?: boolean): void;
122
122
  selectRoot(): d3.Selection<HTMLDivElement, unknown, null, unknown>;
123
123
  selectSVGElement(): d3.Selection<SVGElement, unknown, null, unknown>;
124
124
  selectCanvasView(): d3.Selection<SVGGElement, unknown, null, unknown>;
@@ -65,10 +65,12 @@ export declare class DiagramUserSelection extends DiagramElementSet<DiagramEleme
65
65
  * Opens the value set of a diagram model or a diagram element in the property editor.
66
66
  * @public
67
67
  * @param selection A diagram model or a diagram element with a value set.
68
+ * @param makeUpdateValuesAction Whether the method should create an UpdateValuesAction.
68
69
  * @see PropertyEditor
70
+ * @see UpdateValuesAction
69
71
  */
70
72
  openInPropertyEditor(selection?: {
71
73
  valueSet: ValueSet;
72
- } & (DiagramElement | DiagramModel)): void;
74
+ } & (DiagramElement | DiagramModel), makeUpdateValuesAction?: boolean): void;
73
75
  private makeUpdateValuesAction;
74
76
  }
@@ -189,6 +189,14 @@ export interface NodeTemplateConfig {
189
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
190
  */
191
191
  type: string;
192
+ /**
193
+ * Width of this template as it appears on the palette. By default, the width of the type of node is used.
194
+ */
195
+ width?: number | null;
196
+ /**
197
+ * Height of this template as it appears on the palette. By default, the height of the type of node is used.
198
+ */
199
+ height?: number | null;
192
200
  /**
193
201
  * 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
202
  */
@@ -1,4 +1,4 @@
1
- import { Point } from '../../util/canvas-util';
1
+ import { AnchorPoint, Point } from '../../util/canvas-util';
2
2
  import { HorizontalAlign, Side, VerticalAlign } from '../../util/svg-util';
3
3
  import { DiagramActions } from '../diagram-action';
4
4
  import { Property } from '../property/property';
@@ -258,6 +258,24 @@ export interface PortConfig {
258
258
  * Direction that the connections passing by this port follow at the point of the port.
259
259
  */
260
260
  direction: Side;
261
+ /**
262
+ * Horizontal anchor point for this port. Determines how the port behaves when its root element is resized.
263
+ * - 'start': Always maintains the same distance from the left edge
264
+ * - 'middle': Always maintains the same relative position from the center
265
+ * - 'end': Always maintains the same distance from the right edge
266
+ * - 'floating': Scales proportionally with the element (default behavior)
267
+ * @default 'floating'
268
+ */
269
+ anchorPointX?: AnchorPoint;
270
+ /**
271
+ * Vertical anchor point for this port. Determines how the port behaves when its root element is resized.
272
+ * - 'start': Always maintains the same distance from the top edge
273
+ * - 'middle': Always maintains the same relative position from the center
274
+ * - 'end': Always maintains the same distance from the bottom edge
275
+ * - 'floating': Scales proportionally with the element (default behavior)
276
+ * @default 'floating'
277
+ */
278
+ anchorPointY?: AnchorPoint;
261
279
  }
262
280
  /**
263
281
  * Configuration for a field that is part of another element.
@@ -311,12 +329,22 @@ export interface FieldConfig {
311
329
  * @default 'center'
312
330
  */
313
331
  verticalAlign?: VerticalAlign;
332
+ /**
333
+ * The orientation of the text of this field. It may be a side or a number of degrees.
334
+ * @default 'top'
335
+ */
336
+ orientation?: Side | number;
314
337
  /**
315
338
  * Whether this field and its root element should be resized automatically if the size of the text increases.
316
339
  * Setting this to true should also entail setting reasonable `minWidth` and `minHeight` values for the configuration of any nodes or sections that contain this field.
317
340
  * @default false
318
341
  */
319
342
  fit?: boolean;
343
+ /**
344
+ * Whether when `fit` is enabled should the root element of the field also shrink if there is excess space.
345
+ * @default true
346
+ */
347
+ shrink?: boolean;
320
348
  }
321
349
  /**
322
350
  * Configuration for a decorator that is part of another element.
@@ -342,6 +370,24 @@ export interface DecoratorConfig {
342
370
  * Inner HTML of this decorator.
343
371
  */
344
372
  html: string;
373
+ /**
374
+ * Horizontal anchor point for this decorator. Determines how the decorator behaves when its root element is resized.
375
+ * - 'start': Always maintains the same distance from the left edge
376
+ * - 'middle': Always maintains the same relative position from the center
377
+ * - 'end': Always maintains the same distance from the right edge
378
+ * - 'floating': Scales proportionally with the element (default behavior)
379
+ * @default 'floating'
380
+ */
381
+ anchorPointX?: AnchorPoint;
382
+ /**
383
+ * Vertical anchor point for this decorator. Determines how the decorator behaves when its root element is resized.
384
+ * - 'start': Always maintains the same distance from the top edge
385
+ * - 'middle': Always maintains the same relative position from the center
386
+ * - 'end': Always maintains the same distance from the bottom edge
387
+ * - 'floating': Scales proportionally with the element (default behavior)
388
+ * @default 'floating'
389
+ */
390
+ anchorPointY?: AnchorPoint;
345
391
  }
346
392
  /**
347
393
  * Configuration for the grid of sections of a node.
@@ -401,6 +447,18 @@ export interface SectionConfig {
401
447
  * @default 0
402
448
  */
403
449
  priority?: number;
450
+ /**
451
+ * Whether this section can be resized horizontally.
452
+ * If undefined, inherits from the parent node's resizableX setting.
453
+ * @default undefined
454
+ */
455
+ resizableX?: boolean;
456
+ /**
457
+ * Whether this section can be resized vertically.
458
+ * If undefined, inherits from the parent node's resizableY setting.
459
+ * @default undefined
460
+ */
461
+ resizableY?: boolean;
404
462
  }
405
463
  /**
406
464
  * Configuration for a type of connection.
@@ -1,4 +1,4 @@
1
- import { Point } from '../../util/canvas-util';
1
+ import { AnchorPoint, Point } from '../../util/canvas-util';
2
2
  import { DiagramElement, DiagramElementSet } from './diagram-element';
3
3
  import { DiagramModel } from './diagram-model';
4
4
  import { DiagramNode } from './diagram-node';
@@ -35,7 +35,17 @@ export declare class DiagramDecorator extends DiagramElement {
35
35
  height: number;
36
36
  priority: number;
37
37
  html: string;
38
- constructor(model: DiagramModel, rootElement: DiagramNode | DiagramSection | undefined, coords: Point, width: number, height: number, priority: number, html: string, id: string);
38
+ /**
39
+ * Horizontal anchor point for this decorator. Determines how the decorator behaves when its root element is resized.
40
+ * @public
41
+ */
42
+ anchorPointX: AnchorPoint;
43
+ /**
44
+ * Vertical anchor point for this decorator. Determines how the decorator behaves when its root element is resized.
45
+ * @public
46
+ */
47
+ anchorPointY: AnchorPoint;
48
+ constructor(model: DiagramModel, rootElement: DiagramNode | DiagramSection | undefined, coords: Point, width: number, height: number, priority: number, html: string, id: string, anchorPointX?: AnchorPoint, anchorPointY?: AnchorPoint);
39
49
  get removed(): boolean;
40
50
  updateInView(): void;
41
51
  raise(): void;
@@ -65,6 +75,6 @@ export declare class DiagramDecoratorSet extends DiagramElementSet<DiagramDecora
65
75
  * @param id The id of the decorator. Cannot be an empty string.
66
76
  * @returns The instanced decorator.
67
77
  */
68
- new(rootElement: DiagramNode | DiagramSection | undefined, coords: Point, width: number, height: number, priority: number, html: string, id: string): DiagramDecorator;
78
+ new(rootElement: DiagramNode | DiagramSection | undefined, coords: Point, width: number, height: number, priority: number, html: string, id: string, anchorPointX?: AnchorPoint, anchorPointY?: AnchorPoint): DiagramDecorator;
69
79
  remove(id: string): void;
70
80
  }
@@ -73,7 +73,7 @@ export declare abstract class DiagramElement implements DiagramEntity {
73
73
  */
74
74
  abstract updateInView(): void;
75
75
  /**
76
- * Put this element above other elements of its kind in the view.
76
+ * Put this element above other elements in the view.
77
77
  * @public
78
78
  */
79
79
  abstract raise(): void;
@@ -1,5 +1,5 @@
1
1
  import { Point } from '../../util/canvas-util';
2
- import { HorizontalAlign, VerticalAlign } from '../../util/svg-util';
2
+ import { HorizontalAlign, Side, VerticalAlign } from '../../util/svg-util';
3
3
  import { CollabTimestamp } from '../collab/primitives';
4
4
  import { FieldConfig } from '../config/diagram-config';
5
5
  import { DiagramElement, DiagramElementSet } from './diagram-element';
@@ -19,7 +19,9 @@ export declare const DIAGRAM_FIELD_DEFAULTS: {
19
19
  selectedColor: string;
20
20
  horizontalAlign: HorizontalAlign;
21
21
  verticalAlign: VerticalAlign;
22
+ orientation: Side;
22
23
  fit: boolean;
24
+ shrink: boolean;
23
25
  };
24
26
  export interface LabeledElement {
25
27
  label?: DiagramField;
@@ -82,6 +84,11 @@ export declare class DiagramField extends DiagramElement {
82
84
  * @public
83
85
  */
84
86
  verticalAlign: VerticalAlign;
87
+ /**
88
+ * Orientation of the text of this field.
89
+ * @public
90
+ */
91
+ orientation: number;
85
92
  private _text;
86
93
  /**
87
94
  * Default text that this field's text resets to when empty.
@@ -109,7 +116,12 @@ export declare class DiagramField extends DiagramElement {
109
116
  * @public
110
117
  */
111
118
  fit: boolean;
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);
119
+ /**
120
+ * Whether when `fit` is enabled should the root element of the field also shrink if there is excess space.
121
+ * @public
122
+ */
123
+ shrink: boolean;
124
+ 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, orientation: Side | number, text: string, editable: boolean, fit: boolean, shrink: boolean);
113
125
  get removed(): boolean;
114
126
  updateInView(): void;
115
127
  raise(): void;
@@ -132,7 +144,7 @@ export declare class DiagramFieldSet extends DiagramElementSet<DiagramField> {
132
144
  * Instance a new field and add it to this set. This method is normally called when instancing an element with a field and it is rarely called by itself.
133
145
  * @private
134
146
  */
135
- new(rootElement: (LabeledElement & DiagramElement) | undefined, coords: Point, fontSize: number, fontFamily: string | null, color: string, selectedColor: string, width: number, height: number, horizontalAlign: HorizontalAlign, verticalAlign: VerticalAlign, text: string, editable: boolean, fit: boolean): DiagramField;
147
+ new(rootElement: (LabeledElement & DiagramElement) | undefined, coords: Point, fontSize: number, fontFamily: string | null, color: string, selectedColor: string, width: number, height: number, horizontalAlign: HorizontalAlign, verticalAlign: VerticalAlign, orientation: Side | number, text: string, editable: boolean, fit: boolean, shrink: boolean): DiagramField;
136
148
  remove(id: string): void;
137
149
  }
138
150
  export declare const getBottomMargin: (config?: FieldConfig | null) => number;
@@ -1,4 +1,4 @@
1
- import { Point } from '../../util/canvas-util';
1
+ import { AnchorPoint, Point } from '../../util/canvas-util';
2
2
  import { Side } from '../../util/svg-util';
3
3
  import { FieldConfig, PortTypeConfig } from '../config/diagram-config';
4
4
  import { ImageLook, ImageLookConfig, ShapedLook, ShapedLookConfig } from '../config/diagram-look-config';
@@ -100,6 +100,16 @@ export declare class DiagramPort extends DiagramElement implements LabeledElemen
100
100
  * @public
101
101
  */
102
102
  direction: Side;
103
+ /**
104
+ * Horizontal anchor point for this port. Determines how the port behaves when its root element is resized.
105
+ * @public
106
+ */
107
+ anchorPointX: AnchorPoint;
108
+ /**
109
+ * Vertical anchor point for this port. Determines how the port behaves when its root element is resized.
110
+ * @public
111
+ */
112
+ anchorPointY: AnchorPoint;
103
113
  /**
104
114
  * Whether this port can be used as a connection start point.
105
115
  */
@@ -149,7 +159,7 @@ export declare class DiagramPort extends DiagramElement implements LabeledElemen
149
159
  * @private
150
160
  */
151
161
  get height(): number;
152
- constructor(model: DiagramModel, type: DiagramPortType | undefined, rootElement: DiagramNode | DiagramSection | undefined, coords: Point, connectionPoint: Point | undefined, direction: Side, id: string);
162
+ constructor(model: DiagramModel, type: DiagramPortType | undefined, rootElement: DiagramNode | DiagramSection | undefined, coords: Point, connectionPoint: Point | undefined, direction: Side, id: string, anchorPointX?: AnchorPoint, anchorPointY?: AnchorPoint);
153
163
  get removed(): boolean;
154
164
  updateInView(): void;
155
165
  raise(): void;
@@ -196,6 +206,6 @@ export declare class DiagramPortSet extends DiagramElementSet<DiagramPort> {
196
206
  * Instance a new port and add it to this set. This method is normally called when instancing an element with a port and it is rarely called by itself.
197
207
  * @private
198
208
  */
199
- new(type: DiagramPortType | undefined, rootElement: DiagramNode | DiagramSection | undefined, coords: Point, connectionPoint: Point | undefined, direction: Side, id: string): DiagramPort;
209
+ new(type: DiagramPortType | undefined, rootElement: DiagramNode | DiagramSection | undefined, coords: Point, connectionPoint: Point | undefined, direction: Side, id: string, anchorPointX?: AnchorPoint, anchorPointY?: AnchorPoint): DiagramPort;
200
210
  remove(id: string): void;
201
211
  }
@@ -61,6 +61,8 @@ export declare class DiagramSectionType {
61
61
  highlightedLook: NodeLook;
62
62
  selectedAndHighlightedLook: NodeLook;
63
63
  priority: number;
64
+ resizableX: boolean | undefined;
65
+ resizableY: boolean | undefined;
64
66
  constructor(options: SectionConfig);
65
67
  }
66
68
  /**
@@ -143,6 +145,20 @@ export declare class DiagramSection extends DiagramElement implements LabeledEle
143
145
  getMinWidth(): number;
144
146
  getMinHeight(): number;
145
147
  getPriority(): number;
148
+ /**
149
+ * Returns whether this section can be resized horizontally.
150
+ * If the section has a specific resizableX setting, it uses that.
151
+ * Otherwise, it inherits from the parent node's resizableX setting.
152
+ * @public
153
+ */
154
+ getResizableX(): boolean;
155
+ /**
156
+ * Returns whether this section can be resized vertically.
157
+ * If the section has a specific resizableY setting, it uses that.
158
+ * Otherwise, it inherits from the parent node's resizableY setting.
159
+ * @public
160
+ */
161
+ getResizableY(): boolean;
146
162
  /**
147
163
  * Get the port of this section which is closest to the given coordinates.
148
164
  * @param coords A point in the diagram.
@@ -299,8 +299,9 @@ export interface Canvas {
299
299
  /**
300
300
  * Fit a node to encompass the totality of its sections.
301
301
  * @param id The id of a node
302
+ * @param shrink Whether the node should shrink if there is excess space; `true` by default
302
303
  */
303
- fitNodeInView(id: string): void;
304
+ fitNodeInView(id: string, shrink?: boolean): void;
304
305
  /**
305
306
  * Get the d3 Selection containing the root html div element of the canvas.
306
307
  * @private
@@ -53,6 +53,24 @@ export declare const translateCoordinate: (oldCoordinate: number, oldCoordinates
53
53
  * @returns A new point.
54
54
  */
55
55
  export declare const translatePoint: (oldPoint: Point, oldCoordsX: [number, number], oldCoordsY: [number, number], newCoordsX: [number, number], newCoordsY: [number, number]) => Point;
56
+ /**
57
+ * Types of anchor points for ports and decorators.
58
+ * @public
59
+ */
60
+ export type AnchorPoint = 'start' | 'middle' | 'end' | 'floating';
61
+ /**
62
+ * Moves the coordinates of the given point according to the given changes in coordinates and anchor points.
63
+ * @public
64
+ * @param oldPoint A point.
65
+ * @param oldCoordsX A range of coordinates along the x axis.
66
+ * @param oldCoordsY A range of coordinates along the y axis.
67
+ * @param newCoordsX A range of coordinates along the x axis.
68
+ * @param newCoordsY A range of coordinates along the y axis.
69
+ * @param anchorPointX The horizontal anchor point behavior.
70
+ * @param anchorPointY The vertical anchor point behavior.
71
+ * @returns A new point.
72
+ */
73
+ export declare const translatePointWithAnchors: (oldPoint: Point, oldCoordsX: [number, number], oldCoordsY: [number, number], newCoordsX: [number, number], newCoordsY: [number, number], anchorPointX: AnchorPoint, anchorPointY: AnchorPoint) => Point;
56
74
  /**
57
75
  * Calculates the result of moving the given point by the given distance in the given direction.
58
76
  * @public
@@ -0,0 +1,20 @@
1
+ export declare const degreesToRadians: (theta: number) => number;
2
+ export declare const radiansToDegrees: (theta: number) => number;
3
+ /**
4
+ * Calculates the size of the bounding box of a rectangle that has been rotated by the given number of degrees.
5
+ *
6
+ * @param width The width of a rectangle.
7
+ * @param height The height of a rectangle.
8
+ * @param orientation A rotation in degrees.
9
+ * @returns The size of the bounding box.
10
+ */
11
+ export declare const rotate: (width: number, height: number, orientation: number) => [number, number];
12
+ /**
13
+ * Calculates the original size of the a rectangle that has been rotated by the given number of degrees resulting in a bounding box of the given size.
14
+ *
15
+ * @param width The width of a bounding box.
16
+ * @param height The height of a bounding box.
17
+ * @param orientation A rotation in degrees.
18
+ * @returns The size of the original rectangle.
19
+ */
20
+ export declare const unrotate: (width: number, height: number, orientation: number) => [number, number];
package/index.cjs.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from "./src\\index";
package/index.esm.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from "./src\\index";