@m3ui-vue/m3ui-vue 1.3.3 → 1.3.4

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,4 +1,4 @@
1
- import { type FlowConnection, type FlowContext, type FlowInternals, type FlowViewport, type FlowXY } from '../composables/useFlow';
1
+ import { type FlowConnection, type FlowContext, type FlowInternals, type FlowPosition, type FlowViewport, type FlowXY } from '../composables/useFlow';
2
2
  import { type FlowLayout, type FlowLayoutOptions } from '../composables/flowLayout';
3
3
  import type { FlowEdge, FlowNode, FlowSelection } from '../composables/useFlow';
4
4
  declare const _default: typeof __VLS_export;
@@ -34,6 +34,11 @@ declare const __VLS_export: __VLS_WithSlots<import("vue").DefineComponent<{
34
34
  nodesConnectable?: boolean;
35
35
  elementsSelectable?: boolean;
36
36
  edgesReconnectable?: boolean;
37
+ /**
38
+ * The segments of a selected `smoothstep`/`step` edge get grips: drag one sideways to reroute the edge (it keeps
39
+ * the route in `edge.route`), or drag a leg at either end to add a jog. Default off
40
+ */
41
+ edgesReroutable?: boolean;
37
42
  /** Merged into edges made by connecting (`type`, `animated`, `markerEnd`…) */
38
43
  defaultEdgeOptions?: Partial<FlowEdge>;
39
44
  /** Adds an edge to `edges` when a connection is made; off, only `connect` fires */
@@ -75,9 +80,11 @@ declare const __VLS_export: __VLS_WithSlots<import("vue").DefineComponent<{
75
80
  /**
76
81
  * A drag that starts on an edge draws a new edge from the same source, a branch, as in a circuit editor (the
77
82
  * preview leaves from where you grabbed it). A click still selects the edge; with a finger, only a selected edge
78
- * branches, so a swipe across one still pans
83
+ * branches, so a swipe across one still pans. `'junction'`: the branch leaves from the very point you grabbed,
84
+ * as in Logisim: nothing is added, `branch` fires with that point on the edge, and you split the edge there with a
85
+ * junction node of your own (or leave a loose end where it was dropped on nothing)
79
86
  */
80
- edgeBranching?: boolean;
87
+ edgeBranching?: boolean | "junction";
81
88
  /**
82
89
  * Let the browser's own context menu open on the canvas (right click, or a long press on a phone). Off by default:
83
90
  * the `*-contextmenu` events still fire, for a menu of your own (MContextMenu's `showAt`). Text fields inside
@@ -107,6 +114,17 @@ declare const __VLS_export: __VLS_WithSlots<import("vue").DefineComponent<{
107
114
  handleId: string | null;
108
115
  type: "source" | "target";
109
116
  }) => any;
117
+ branch: (args_0: {
118
+ edge: FlowEdge;
119
+ connection: FlowConnection | null;
120
+ position: FlowXY;
121
+ direction: FlowPosition;
122
+ end: FlowXY;
123
+ routes?: {
124
+ before: number[];
125
+ after: number[];
126
+ };
127
+ }) => any;
110
128
  "connect-end": (args_0: {
111
129
  connection: FlowConnection | null;
112
130
  position: FlowXY;
@@ -120,6 +138,7 @@ declare const __VLS_export: __VLS_WithSlots<import("vue").DefineComponent<{
120
138
  edge: FlowEdge;
121
139
  connection: FlowConnection;
122
140
  }) => any;
141
+ reroute: (edge: FlowEdge<any>) => any;
123
142
  "node-click": (args_0: FlowNode<any>, args_1: MouseEvent) => any;
124
143
  "node-dblclick": (args_0: FlowNode<any>, args_1: MouseEvent) => any;
125
144
  "node-contextmenu": (args_0: FlowNode<any>, args_1: MouseEvent) => any;
@@ -168,6 +187,11 @@ declare const __VLS_export: __VLS_WithSlots<import("vue").DefineComponent<{
168
187
  nodesConnectable?: boolean;
169
188
  elementsSelectable?: boolean;
170
189
  edgesReconnectable?: boolean;
190
+ /**
191
+ * The segments of a selected `smoothstep`/`step` edge get grips: drag one sideways to reroute the edge (it keeps
192
+ * the route in `edge.route`), or drag a leg at either end to add a jog. Default off
193
+ */
194
+ edgesReroutable?: boolean;
171
195
  /** Merged into edges made by connecting (`type`, `animated`, `markerEnd`…) */
172
196
  defaultEdgeOptions?: Partial<FlowEdge>;
173
197
  /** Adds an edge to `edges` when a connection is made; off, only `connect` fires */
@@ -209,9 +233,11 @@ declare const __VLS_export: __VLS_WithSlots<import("vue").DefineComponent<{
209
233
  /**
210
234
  * A drag that starts on an edge draws a new edge from the same source, a branch, as in a circuit editor (the
211
235
  * preview leaves from where you grabbed it). A click still selects the edge; with a finger, only a selected edge
212
- * branches, so a swipe across one still pans
236
+ * branches, so a swipe across one still pans. `'junction'`: the branch leaves from the very point you grabbed,
237
+ * as in Logisim: nothing is added, `branch` fires with that point on the edge, and you split the edge there with a
238
+ * junction node of your own (or leave a loose end where it was dropped on nothing)
213
239
  */
214
- edgeBranching?: boolean;
240
+ edgeBranching?: boolean | "junction";
215
241
  /**
216
242
  * Let the browser's own context menu open on the canvas (right click, or a long press on a phone). Off by default:
217
243
  * the `*-contextmenu` events still fire, for a menu of your own (MContextMenu's `showAt`). Text fields inside
@@ -241,6 +267,17 @@ declare const __VLS_export: __VLS_WithSlots<import("vue").DefineComponent<{
241
267
  handleId: string | null;
242
268
  type: "source" | "target";
243
269
  }) => any) | undefined;
270
+ onBranch?: ((args_0: {
271
+ edge: FlowEdge;
272
+ connection: FlowConnection | null;
273
+ position: FlowXY;
274
+ direction: FlowPosition;
275
+ end: FlowXY;
276
+ routes?: {
277
+ before: number[];
278
+ after: number[];
279
+ };
280
+ }) => any) | undefined;
244
281
  "onConnect-end"?: ((args_0: {
245
282
  connection: FlowConnection | null;
246
283
  position: FlowXY;
@@ -254,6 +291,7 @@ declare const __VLS_export: __VLS_WithSlots<import("vue").DefineComponent<{
254
291
  edge: FlowEdge;
255
292
  connection: FlowConnection;
256
293
  }) => any) | undefined;
294
+ onReroute?: ((edge: FlowEdge<any>) => any) | undefined;
257
295
  "onNode-click"?: ((args_0: FlowNode<any>, args_1: MouseEvent) => any) | undefined;
258
296
  "onNode-dblclick"?: ((args_0: FlowNode<any>, args_1: MouseEvent) => any) | undefined;
259
297
  "onNode-contextmenu"?: ((args_0: FlowNode<any>, args_1: MouseEvent) => any) | undefined;
@@ -296,13 +334,14 @@ declare const __VLS_export: __VLS_WithSlots<import("vue").DefineComponent<{
296
334
  nodesConnectable: boolean;
297
335
  elementsSelectable: boolean;
298
336
  edgesReconnectable: boolean;
337
+ edgesReroutable: boolean;
299
338
  autoConnect: boolean;
300
339
  connectionRadius: number;
301
340
  deleteKeys: string[] | null;
302
341
  guides: boolean;
303
342
  insertOnEdge: boolean;
304
343
  dropIntoGroups: boolean;
305
- edgeBranching: boolean;
344
+ edgeBranching: boolean | "junction";
306
345
  nativeContextMenu: boolean;
307
346
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>, {
308
347
  empty?: (props: {}) => any;
@@ -2,14 +2,15 @@ import { type FlowPosition } from '../composables/useFlow';
2
2
  type __VLS_Props = {
3
3
  /** `source`: edges leave from it; `target`: they arrive */
4
4
  type?: 'source' | 'target';
5
- position?: FlowPosition;
5
+ /** Its side; `'auto'` sits in the node's middle (or where you put it) and each edge leaves or arrives on the side facing its other end */
6
+ position?: FlowPosition | 'auto';
6
7
  id?: string;
7
8
  connectable?: boolean;
8
9
  };
9
10
  declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
10
11
  type: "source" | "target";
11
12
  id: string;
12
- position: FlowPosition;
13
+ position: FlowPosition | "auto";
13
14
  connectable: boolean;
14
15
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
15
16
  declare const _default: typeof __VLS_export;
@@ -32,6 +32,22 @@ type Pt = [number, number];
32
32
  export declare function smoothStepPoints(p: FlowEdgePathParams & {
33
33
  offset?: number;
34
34
  }): Pt[];
35
+ /**
36
+ * The corners of an orthogonal edge routed through `route`: the positions of its segments after the first, alternately
37
+ * x and y, starting with where the leg leaving the source ends (an x when the source's side is left or right). The
38
+ * legs at the ends stretch to wherever the nodes are, and a corner is added before the target when it's needed to
39
+ * arrive square to its side, so the route stays orthogonal as the nodes move.
40
+ */
41
+ export declare function routePoints(p: FlowEdgePathParams & {
42
+ route: number[];
43
+ }): Pt[];
44
+ /** The other way round: the `route` that runs an orthogonal edge through these corners (its ends first and last) */
45
+ export declare function pointsToRoute(points: Pt[], sourcePosition?: FlowPosition, targetPosition?: FlowPosition): number[];
46
+ /** Right-angled steps through `route` (see `routePoints`), rounded like `getSmoothStepPath` */
47
+ export declare function getRoutedPath(p: FlowEdgePathParams & {
48
+ route: number[];
49
+ borderRadius?: number;
50
+ }): FlowEdgePath;
35
51
  /** Right-angled steps with rounded corners (`borderRadius`, default 8; 0 gives sharp steps). `offset` (default 20) is how far it leaves a node before turning */
36
52
  export declare function getSmoothStepPath(p: FlowEdgePathParams & {
37
53
  borderRadius?: number;
@@ -41,12 +57,15 @@ export declare function getSmoothStepPath(p: FlowEdgePathParams & {
41
57
  * Points along an edge's path, close enough together to measure how far something is from it (bezier curves are
42
58
  * sampled; step paths are their corners)
43
59
  */
44
- export declare function edgePathPoints(type: string | undefined, p: FlowEdgePathParams): [number, number][];
60
+ export declare function edgePathPoints(type: string | undefined, p: FlowEdgePathParams & {
61
+ route?: number[];
62
+ }): [number, number][];
45
63
  /** The distance from a point to a polyline */
46
64
  export declare function distanceToPoints(x: number, y: number, pts: [number, number][]): number;
47
65
  /** `getSmoothStepPath` with sharp corners */
48
66
  export declare function getStepPath(p: FlowEdgePathParams & {
49
67
  offset?: number;
68
+ route?: number[];
50
69
  }): FlowEdgePath;
51
70
  /** An arrowhead's path at (x, y) pointing along `angle`: open (two strokes) or closed (a filled triangle's outline) */
52
71
  export declare function arrowPath(x: number, y: number, angle: number, size?: number, closed?: boolean): string;
@@ -40,6 +40,11 @@ export interface FlowNode<D = any> {
40
40
  deletable?: boolean;
41
41
  /** `false` keeps it from splicing into an edge when dropped onto one */
42
42
  insertable?: boolean;
43
+ /**
44
+ * With snapToGrid, what lands on the grid is its position plus this (default its corner): `{ x: w / 2, y: h / 2 }`
45
+ * puts its middle on the grid, e.g. a junction dot whose wires run along the grid lines
46
+ */
47
+ gridOffset?: FlowXY;
43
48
  class?: string;
44
49
  }
45
50
  /** What a `circle` node shows */
@@ -89,8 +94,30 @@ export interface FlowEdge<D = any> {
89
94
  deletable?: boolean;
90
95
  /** Its ends can be dragged to other handles once selected; default MFlow's `edgesReconnectable` */
91
96
  reconnectable?: boolean;
97
+ /**
98
+ * A `smoothstep`/`step` edge's own route: where its segments after the first run, alternately x and y (see
99
+ * `routePoints`). Dragging a selected edge's segments writes it (MFlow's `edgesReroutable`); without one it's
100
+ * routed automatically
101
+ */
102
+ route?: number[];
103
+ /** Its segments can be dragged once selected; default MFlow's `edgesReroutable` */
104
+ reroutable?: boolean;
105
+ /** The side it leaves an `'auto'` handle by (default the side facing its other end) */
106
+ sourcePosition?: FlowPosition;
107
+ /** The side it arrives at an `'auto'` handle by (default the side facing its other end) */
108
+ targetPosition?: FlowPosition;
92
109
  class?: string;
93
110
  }
111
+ /** An edge found under a point (`getEdgeAt`) */
112
+ export interface FlowEdgeHit {
113
+ edge: FlowEdge;
114
+ position: FlowXY;
115
+ direction: FlowPosition;
116
+ routes?: {
117
+ before: number[];
118
+ after: number[];
119
+ };
120
+ }
94
121
  /** The view: `x`/`y` in px, where the flow's origin is on the canvas, and the zoom */
95
122
  export interface FlowViewport {
96
123
  x: number;
@@ -112,7 +139,8 @@ export interface FlowSelection {
112
139
  export interface FlowHandleBounds {
113
140
  id: string | null;
114
141
  type: 'source' | 'target';
115
- position: FlowPosition;
142
+ /** 'auto': each edge leaves or arrives on the side that faces its other end */
143
+ position: FlowPosition | 'auto';
116
144
  x: number;
117
145
  y: number;
118
146
  connectable: boolean;
@@ -157,6 +185,16 @@ export interface FlowContext {
157
185
  width: number;
158
186
  height: number;
159
187
  }): FlowNode[];
188
+ /**
189
+ * The edge passing within `radius` (flow units, default 8) of a flow point, nearest first, skipping the ones
190
+ * `ignore` returns true for: where on it the point falls (on the grid along it with snapToGrid), the way it runs
191
+ * there toward its target, and for an edge with its own route, the routes that keep each half's shape if it's split
192
+ * there (as the `branch` event gives). For dropping something onto an edge, e.g. a junction
193
+ */
194
+ getEdgeAt(p: FlowXY, opts?: {
195
+ radius?: number;
196
+ ignore?: (e: FlowEdge) => boolean;
197
+ }): FlowEdgeHit | null;
160
198
  /** Page (client) coordinates → flow coordinates */
161
199
  screenToFlow(p: {
162
200
  x: number;
@@ -182,6 +220,11 @@ export interface FlowContext {
182
220
  }): void;
183
221
  addNodes(nodes: FlowNode | FlowNode[]): void;
184
222
  addEdges(edges: FlowEdge | FlowEdge[]): void;
223
+ /** Several changes as one undoable step (nodes and edges added, changed or removed together): each list given replaces the current one */
224
+ change(next: {
225
+ nodes?: FlowNode[];
226
+ edges?: FlowEdge[];
227
+ }): void;
185
228
  updateNode(id: string, patch: Partial<FlowNode> | ((n: FlowNode) => FlowNode)): void;
186
229
  updateEdge(id: string, patch: Partial<FlowEdge> | ((e: FlowEdge) => FlowEdge)): void;
187
230
  /** Deletes nodes (with their edges and children) and edges by id */
@@ -231,6 +274,9 @@ export interface FlowInternals extends FlowContext {
231
274
  zIndexOf(id: string): number;
232
275
  edgeGeometry(e: FlowEdge): FlowEdgeGeometry | null;
233
276
  isReconnectable(e: FlowEdge): boolean;
277
+ isReroutable(e: FlowEdge): boolean;
278
+ /** The corners of an orthogonal edge (its ends first and last), or null for a curve or a straight line */
279
+ edgeCorners(e: FlowEdge): [number, number][] | null;
234
280
  sidePositions(n: FlowNode): {
235
281
  source: FlowPosition;
236
282
  target: FlowPosition;
package/dist/flow.d.ts CHANGED
@@ -4,8 +4,8 @@ export { default as MFlowHandle } from './components/MFlowHandle.vue';
4
4
  export { default as MFlowControls } from './components/MFlowControls.vue';
5
5
  export { default as MFlowMinimap } from './components/MFlowMinimap.vue';
6
6
  export { useFlow, useFlowNode } from './composables/useFlow';
7
- export type { FlowCircleData, FlowConnection, FlowContext, FlowEdge, FlowFitOptions, FlowHandleBounds, FlowMarker, FlowNode, FlowSelection, FlowViewport, FlowXY, } from './composables/useFlow';
8
- export { getBezierPath, getSmoothStepPath, getStepPath, getStraightPath, smoothStepPoints, arrowPath } from './composables/flowPaths';
7
+ export type { FlowCircleData, FlowConnection, FlowContext, FlowEdge, FlowEdgeHit, FlowFitOptions, FlowHandleBounds, FlowMarker, FlowNode, FlowSelection, FlowViewport, FlowXY, } from './composables/useFlow';
8
+ export { getBezierPath, getSmoothStepPath, getStepPath, getStraightPath, smoothStepPoints, routePoints, pointsToRoute, getRoutedPath, arrowPath } from './composables/flowPaths';
9
9
  export type { FlowEdgePath, FlowEdgePathParams, FlowPosition } from './composables/flowPaths';
10
10
  export { layoutTree, layoutLayered } from './composables/flowLayout';
11
11
  export type { FlowLayout, FlowLayoutDirection, FlowLayoutOptions, FlowLayoutResult } from './composables/flowLayout';