@focus.matters/diagrams 0.2.1 → 0.2.20

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.
@@ -1,9 +1,9 @@
1
1
  import { default as React } from 'react';
2
- import { Coordinates } from '../../../store/primitives/Coordinates';
3
- import { EdgeArrowHead, EdgeLineStyle, EdgePathType } from '../../../store/types';
4
- import { EdgePoint } from '../../../store/elements/EdgePoint';
5
2
  import { Edge } from '../../../store/elements/Edge';
3
+ import { EdgePoint } from '../../../store/elements/EdgePoint';
6
4
  import { AnyMouseEvent } from '../../../store/elements/Events';
5
+ import { Coordinates } from '../../../store/primitives/Coordinates';
6
+ import { EdgeArrowHead, EdgeLineStyle, EdgePathType } from '../../../store/types';
7
7
  export interface RenderEdgeProps {
8
8
  edge?: Edge;
9
9
  points: (Coordinates | EdgePoint)[];
@@ -18,13 +18,16 @@ export interface RenderEdgeProps {
18
18
  lineStyle?: EdgeLineStyle;
19
19
  pathType?: EdgePathType;
20
20
  draggable?: boolean;
21
+ selected?: boolean;
21
22
  onMidpointMouseDown?: (p: Midpoint, ev: React.MouseEvent) => void;
22
23
  onEndpointMouseDown?: (endpoint: "from" | "to", ev: React.MouseEvent) => void;
23
24
  }
25
+ /** Represents the editable midpoint between two consecutive routed edge points. */
24
26
  export declare class Midpoint extends Coordinates {
25
27
  id: string;
26
28
  edge: Edge;
27
29
  points: [Coordinates, Coordinates];
28
30
  constructor(id: string, edge: Edge, points: [Coordinates, Coordinates], items?: AnyMouseEvent | Event | Coordinates | number[]);
31
+ /** Creates an independent midpoint while preserving its edge and segment data. */
29
32
  copy(): Midpoint;
30
33
  }
@@ -1,4 +1,7 @@
1
1
  import { Edge } from '../../store/elements/Edge';
2
2
  import { Coordinates } from '../../store/primitives/Coordinates';
3
3
  /** Places a new label beside the clicked route segment instead of over its stroke. */
4
- export declare function positionEdgeLabelBesideRoute(edge: Edge, clicked: Coordinates, clearance?: number): Coordinates;
4
+ export declare function positionEdgeLabelBesideRoute(edge: Edge, clicked: Coordinates, size?: {
5
+ height: number;
6
+ width: number;
7
+ }, clearance?: number): Coordinates;
@@ -0,0 +1,11 @@
1
+ /** Keeps contained toolbar gestures out of the canvas without swallowing portalled control events. */
2
+ export declare function stopDiagramControlEvent(event: {
3
+ target: EventTarget | null;
4
+ currentTarget: {
5
+ contains(target: EventTarget | null): boolean;
6
+ };
7
+ stopPropagation(): void;
8
+ nativeEvent?: {
9
+ stopImmediatePropagation?(): void;
10
+ };
11
+ }): void;
@@ -0,0 +1,14 @@
1
+ import { PointerEvent } from 'react';
2
+ import { Diagram } from '../store/Diagram';
3
+ /** Captures diagram gestures safely while keeping embedded controls and portalled menus interactive. */
4
+ export declare function useDiagramPointerCapture(diagram?: Diagram, controls?: string): {
5
+ ref: import('react').RefObject<HTMLDivElement | null>;
6
+ onPointerDownCapture(event: PointerEvent<HTMLDivElement>): void;
7
+ onPointerMove(event: PointerEvent<HTMLDivElement>): void;
8
+ onPointerUp: () => void;
9
+ onPointerCancel: () => void;
10
+ onLostPointerCapture: () => void;
11
+ onDragStart(event: {
12
+ preventDefault(): void;
13
+ }): void;
14
+ };
@@ -0,0 +1,3 @@
1
+ import { MRDiagram } from './MRDiagram';
2
+ /** Highlights connections and adjacent tables for hovered attributes, including custom table renderers. */
3
+ export declare function bindAttributeRelationshipHover(root: HTMLElement, diagram: MRDiagram): () => void;
@@ -10,11 +10,23 @@ export type ScaleEvent = {
10
10
  /** Owns viewport scale, displacement, interaction sessions, and rendered canvas bounds. */
11
11
  export declare class Canvas extends Element {
12
12
  private unbindDocumentEvents;
13
+ private readonly detachHandlers;
13
14
  private mouseSessionStartedInFrame;
15
+ private keyboardSessionActive;
14
16
  private centerAnimationFrame;
15
17
  protected _displacement: Coordinates;
16
18
  _scale: number;
17
19
  private gridSize;
20
+ private minimumScale;
21
+ private maximumScale;
22
+ private wheelSensitivity;
23
+ private animatedZoom;
24
+ private zoomFrame;
25
+ private zoomTarget;
26
+ private zoomDeadline;
27
+ private zoomLastFrame;
28
+ private zoomCenter;
29
+ private applyingZoomFrame;
18
30
  size: Coordinates;
19
31
  get scale(): number;
20
32
  element: HTMLElement | null;
@@ -26,6 +38,8 @@ export declare class Canvas extends Element {
26
38
  constructor(parent: Diagram);
27
39
  /** Releases document listeners and cancels any viewport animation still in flight. */
28
40
  dispose(): void;
41
+ /** Registers cleanup for decorations owned by a currently attached canvas surface. */
42
+ onDetach(callback: () => void): () => void;
29
43
  /** Marks programmatic pointer sessions as eligible for the canvas drag lifecycle. */
30
44
  markMouseSessionStartedInFrame(): void;
31
45
  get dragging(): boolean;
@@ -35,6 +49,11 @@ export declare class Canvas extends Element {
35
49
  protected bound(): void;
36
50
  /** Centers a world point in the viewport and optionally animates the pan. */
37
51
  centerOnPoint(c: Coordinates, animated?: boolean): void;
52
+ /**
53
+ * Minimally pans the viewport until a world-space box has the requested margin.
54
+ */
55
+ ensureVisible(box: Dimensions, padding?: number, animated?: boolean): boolean;
56
+ private visibleOriginForInterval;
38
57
  private animateDisplacement;
39
58
  private cancelCenterAnimation;
40
59
  private applyDisplacement;
@@ -42,6 +61,27 @@ export declare class Canvas extends Element {
42
61
  displace(c: Coordinates): Coordinates;
43
62
  /** Replaces the viewport displacement while respecting configured canvas bounds. */
44
63
  setDisplacement(c: Coordinates): void;
64
+ /** Configures validated viewport limits and a constant scale increment per wheel pixel. */
65
+ configureZoom(options: {
66
+ minimumScale?: number;
67
+ maximumScale?: number;
68
+ wheelSensitivity?: number;
69
+ animated?: boolean;
70
+ }): void;
71
+ /** Applies the same configured limits to manual zoom, fitted content and restored cameras. */
72
+ clampScale(value: number): number;
73
+ /** Captures serializable camera coordinates without choosing an application storage backend. */
74
+ getCamera(): {
75
+ x: number;
76
+ y: number;
77
+ scale: number;
78
+ };
79
+ /** Restores a validated camera snapshot using the same limits as interactive viewport zoom. */
80
+ restoreCamera(camera: {
81
+ x: number;
82
+ y: number;
83
+ scale: number;
84
+ }): void;
45
85
  /** Changes viewport scale around a screen-space focus point and preserves alignment. */
46
86
  setScale(newScale: number, zoomCenter?: Coordinates): void;
47
87
  /**
@@ -72,8 +112,13 @@ export declare class Canvas extends Element {
72
112
  protected handleClick(originalEvent: MouseEvent): void;
73
113
  protected handleMouseUp(originalEvent: MouseEvent): void;
74
114
  protected handleMouseDown(originalEvent: MouseEvent): void;
115
+ protected handleFocusIn(originalEvent: FocusEvent): void;
75
116
  protected handleKeyDown(originalEvent: KeyboardEvent): void;
76
117
  protected handleKeyUp(originalEvent: KeyboardEvent): void;
77
118
  protected handleKeyPress(originalEvent: KeyboardEvent): void;
119
+ private cancelZoomAnimation;
120
+ private animateWheelZoom;
121
+ private advanceWheelZoom;
122
+ private applyWheelZoom;
78
123
  protected handleWheel(originalEvent: WheelEvent): void;
79
124
  }
@@ -48,6 +48,12 @@ export type TDefaultExensions = {
48
48
  };
49
49
  export type TDiagramSettings = Partial<{
50
50
  extensions: TDefaultExensions;
51
+ zoom: {
52
+ minimumScale?: number;
53
+ maximumScale?: number;
54
+ wheelSensitivity?: number;
55
+ animated?: boolean;
56
+ };
51
57
  }>;
52
58
  /** Owns diagram elements, extensions, camera state, and application interactions. */
53
59
  export declare class Diagram extends Element {
@@ -0,0 +1,10 @@
1
+ import { Diagram } from './Diagram';
2
+ import { Node } from './elements/Node';
3
+ import { Coordinates } from './primitives/Coordinates';
4
+ /** Selects, frames and persistently highlights a reference destination until a click outside it. */
5
+ export declare function revealDiagramNode(diagram: Diagram, node: Node, options?: {
6
+ point?: Coordinates;
7
+ attributeId?: string;
8
+ padding?: number;
9
+ preferredScale?: number;
10
+ }): boolean;
@@ -29,3 +29,9 @@ export { MRTableNode } from './Diagrams/custom/mr/nodes/MRTableNode';
29
29
  export type * from './Diagrams/custom/mr/types';
30
30
  export { DiagramEditor } from './Diagrams/DiagramEditor';
31
31
  export { Diagram } from './Diagrams/store/Diagram';
32
+ export { customRendererProps } from './Diagrams/components/objects/customRendererProps';
33
+ export { stopDiagramControlEvent } from './Diagrams/components/stopDiagramControlEvent';
34
+ export { useDiagramPointerCapture } from './Diagrams/components/useDiagramPointerCapture';
35
+ export { bindAttributeRelationshipHover } from './Diagrams/custom/mr/bindAttributeRelationshipHover';
36
+ export { Coordinates } from './Diagrams/store/primitives/Coordinates';
37
+ export { revealDiagramNode } from './Diagrams/store/revealDiagramNode';
package/package.json CHANGED
@@ -1,48 +1,50 @@
1
- {
2
- "name": "@focus.matters/diagrams",
3
- "version": "0.2.1",
4
- "type": "module",
5
- "files": [
6
- "dist"
7
- ],
8
- "main": "./dist/index.umd.js",
9
- "module": "./dist/index.es.js",
10
- "types": "./dist/index.d.ts",
11
- "exports": {
12
- ".": {
13
- "types": "./dist/index.d.ts",
14
- "import": "./dist/index.es.js",
15
- "require": "./dist/index.umd.js"
16
- },
17
- "./diagrams.css": "./dist/diagrams.css"
18
- },
19
- "publishConfig": {
20
- "access": "public"
21
- },
22
- "peerDependencies": {
23
- "html2canvas": "^1.4.1",
24
- "mobx": "^6.13.7",
25
- "mobx-react-lite": "^4.1.0",
26
- "react": "^19.0.0",
27
- "react-dom": "^19.0.0",
28
- "react-icons": "^5.0.0",
29
- "svg-path-bbox": "^2.1.0"
30
- },
31
- "devDependencies": {
32
- "html2canvas": "^1.4.1",
33
- "mobx": "^6.13.7",
34
- "mobx-react-lite": "^4.1.0",
35
- "react": "^19.0.0",
36
- "react-dom": "^19.0.0",
37
- "react-icons": "^5.0.0",
38
- "svg-path-bbox": "^2.1.0"
39
- },
40
- "gitHead": "f866b7ee0e0b98b4d9525fcb71185029df8a4996",
41
- "dependencies": {
42
- "@dagrejs/dagre": "^3.0.0"
43
- },
44
- "scripts": {
45
- "build": "vite build",
46
- "typecheck": "tsc --noEmit -p tsconfig.json"
47
- }
48
- }
1
+ {
2
+ "name": "@focus.matters/diagrams",
3
+ "version": "0.2.20",
4
+ "private": false,
5
+ "type": "module",
6
+ "files": [
7
+ "dist"
8
+ ],
9
+ "main": "./dist/index.umd.js",
10
+ "module": "./dist/index.es.js",
11
+ "types": "./dist/index.d.ts",
12
+ "exports": {
13
+ ".": {
14
+ "types": "./dist/index.d.ts",
15
+ "import": "./dist/index.es.js",
16
+ "require": "./dist/index.umd.js"
17
+ },
18
+ "./diagrams.css": "./dist/diagrams.css"
19
+ },
20
+ "publishConfig": {
21
+ "access": "public"
22
+ },
23
+ "scripts": {
24
+ "build": "vite build",
25
+ "typecheck": "tsc --noEmit -p tsconfig.json"
26
+ },
27
+ "peerDependencies": {
28
+ "html2canvas": "^1.4.1",
29
+ "mobx": "^6.13.7",
30
+ "mobx-react-lite": "^4.1.0",
31
+ "react": "^19.0.0",
32
+ "react-dom": "^19.0.0",
33
+ "react-icons": "^5.0.0",
34
+ "svg-path-bbox": "^2.1.0"
35
+ },
36
+ "devDependencies": {
37
+ "html2canvas": "^1.4.1",
38
+ "mobx": "^6.13.7",
39
+ "mobx-react-lite": "^4.1.0",
40
+ "react": "^19.0.0",
41
+ "react-dom": "^19.0.0",
42
+ "react-icons": "^5.0.0",
43
+ "svg-path-bbox": "^2.1.0"
44
+ },
45
+ "gitHead": "f866b7ee0e0b98b4d9525fcb71185029df8a4996",
46
+ "dependencies": {
47
+ "@dagrejs/dagre": "^3.0.0"
48
+ },
49
+ "candidateSourceCommit": "f71a92ce06888e913044f4ef56d1680b0b19ce70"
50
+ }
@@ -1 +0,0 @@
1
- {"version":3,"file":"DirectedPoint-BSGh_PUt.js","sources":["../src/Diagrams/store/primitives/DirectedPoint.ts"],"sourcesContent":["import type { TOrientation } from \"../types\";\nimport { Coordinates } from \"./Coordinates\";\n\nexport class DirectedPoint extends Coordinates {\n direction: TOrientation = \"left\";\n\n get rawDirectedPoint() {\n return {\n x: this.x,\n y: this.y,\n direction: this.direction,\n };\n }\n\n stepBack() {\n switch (this.direction) {\n case \"down\":\n this.y--;\n break;\n case \"left\":\n this.x++;\n break;\n case \"right\":\n this.x--;\n break;\n case \"up\":\n this.y++;\n break;\n }\n return this;\n }\n\n stepForward() {\n switch (this.direction) {\n case \"down\":\n this.y++;\n break;\n case \"left\":\n this.x--;\n break;\n case \"right\":\n this.x++;\n break;\n case \"up\":\n this.y--;\n break;\n }\n return this;\n }\n}\n"],"names":["_DirectedPoint","Coordinates","__name","DirectedPoint"],"mappings":";;;AAGO,MAAMA,IAAN,MAAMA,UAAsBC,EAAY;AAAA,EAC7C,YAA0B;AAAA,EAE1B,IAAI,mBAAmB;AACrB,WAAO;AAAA,MACL,GAAG,KAAK;AAAA,MACR,GAAG,KAAK;AAAA,MACR,WAAW,KAAK;AAAA,IAAA;AAAA,EAEpB;AAAA,EAEA,WAAW;AACT,YAAQ,KAAK,WAAA;AAAA,MACX,KAAK;AACH,aAAK;AACL;AAAA,MACF,KAAK;AACH,aAAK;AACL;AAAA,MACF,KAAK;AACH,aAAK;AACL;AAAA,MACF,KAAK;AACH,aAAK;AACL;AAAA,IAAA;AAEJ,WAAO;AAAA,EACT;AAAA,EAEA,cAAc;AACZ,YAAQ,KAAK,WAAA;AAAA,MACX,KAAK;AACH,aAAK;AACL;AAAA,MACF,KAAK;AACH,aAAK;AACL;AAAA,MACF,KAAK;AACH,aAAK;AACL;AAAA,MACF,KAAK;AACH,aAAK;AACL;AAAA,IAAA;AAEJ,WAAO;AAAA,EACT;AACF;AA9C+CC,EAAAF,GAAA;AAAxC,IAAMG,IAANH;"}