@fragiola/flow-svelte 0.0.0-stage → 0.0.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.
- package/LICENSE +21 -0
- package/README.md +13 -2
- package/dist/components/background.svelte +150 -0
- package/dist/components/background.svelte.d.ts +25 -0
- package/dist/components/connection-line.svelte +120 -0
- package/dist/components/connection-line.svelte.d.ts +25 -0
- package/dist/components/controls.svelte +54 -0
- package/dist/components/controls.svelte.d.ts +17 -0
- package/dist/components/edge-label.svelte +126 -0
- package/dist/components/edge-label.svelte.d.ts +25 -0
- package/dist/components/edge-path.svelte +116 -0
- package/dist/components/edge-path.svelte.d.ts +27 -0
- package/dist/components/edge-toolbar.svelte +137 -0
- package/dist/components/edge-toolbar.svelte.d.ts +39 -0
- package/dist/components/edge.svelte +90 -0
- package/dist/components/edge.svelte.d.ts +41 -0
- package/dist/components/edges.svelte +242 -0
- package/dist/components/edges.svelte.d.ts +49 -0
- package/dist/components/fit-view.svelte +84 -0
- package/dist/components/fit-view.svelte.d.ts +32 -0
- package/dist/components/handle.svelte +96 -0
- package/dist/components/handle.svelte.d.ts +17 -0
- package/dist/components/node-toolbar.svelte +153 -0
- package/dist/components/node-toolbar.svelte.d.ts +42 -0
- package/dist/components/node.svelte +73 -0
- package/dist/components/node.svelte.d.ts +42 -0
- package/dist/components/nodes-selection.svelte +102 -0
- package/dist/components/nodes-selection.svelte.d.ts +26 -0
- package/dist/components/nodes.svelte +108 -0
- package/dist/components/nodes.svelte.d.ts +45 -0
- package/dist/components/reconnect-anchor.svelte +119 -0
- package/dist/components/reconnect-anchor.svelte.d.ts +26 -0
- package/dist/components/root.svelte +698 -0
- package/dist/components/root.svelte.d.ts +106 -0
- package/dist/components/selection-box.svelte +91 -0
- package/dist/components/selection-box.svelte.d.ts +20 -0
- package/dist/components/toggle-interactive.svelte +98 -0
- package/dist/components/toggle-interactive.svelte.d.ts +25 -0
- package/dist/components/viewport.svelte +108 -0
- package/dist/components/viewport.svelte.d.ts +16 -0
- package/dist/components/zoom-in.svelte +65 -0
- package/dist/components/zoom-in.svelte.d.ts +18 -0
- package/dist/components/zoom-out.svelte +65 -0
- package/dist/components/zoom-out.svelte.d.ts +18 -0
- package/dist/connection/index.d.ts +1 -0
- package/dist/connection/index.js +3 -0
- package/dist/context.d.ts +71 -0
- package/dist/context.js +81 -0
- package/dist/drag/index.d.ts +1 -0
- package/dist/drag/index.js +3 -0
- package/dist/index.d.ts +45 -0
- package/dist/index.js +25 -0
- package/dist/keyboard/index.d.ts +1 -0
- package/dist/keyboard/index.js +3 -0
- package/dist/minimap/index.d.ts +4 -0
- package/dist/minimap/index.js +7 -0
- package/dist/minimap/mini-map-context.d.ts +7 -0
- package/dist/minimap/mini-map-context.js +13 -0
- package/dist/minimap/mini-map-mask.svelte +65 -0
- package/dist/minimap/mini-map-mask.svelte.d.ts +19 -0
- package/dist/minimap/mini-map-node.svelte +88 -0
- package/dist/minimap/mini-map-node.svelte.d.ts +17 -0
- package/dist/minimap/mini-map.svelte +188 -0
- package/dist/minimap/mini-map.svelte.d.ts +39 -0
- package/dist/parts.d.ts +21 -0
- package/dist/parts.js +24 -0
- package/dist/reconnection/index.d.ts +1 -0
- package/dist/reconnection/index.js +3 -0
- package/dist/resize/index.d.ts +3 -0
- package/dist/resize/index.js +5 -0
- package/dist/resize/node-resizer.svelte +134 -0
- package/dist/resize/node-resizer.svelte.d.ts +36 -0
- package/dist/resize/resize-handle.svelte +192 -0
- package/dist/resize/resize-handle.svelte.d.ts +44 -0
- package/dist/runes/create-flow-ref.svelte.d.ts +32 -0
- package/dist/runes/create-flow-ref.svelte.js +32 -0
- package/dist/runes/internal.svelte.d.ts +31 -0
- package/dist/runes/internal.svelte.js +63 -0
- package/dist/runes/use-connection.svelte.d.ts +8 -0
- package/dist/runes/use-connection.svelte.js +18 -0
- package/dist/runes/use-control-button.svelte.d.ts +16 -0
- package/dist/runes/use-control-button.svelte.js +41 -0
- package/dist/runes/use-edge.svelte.d.ts +48 -0
- package/dist/runes/use-edge.svelte.js +98 -0
- package/dist/runes/use-edges.svelte.d.ts +4 -0
- package/dist/runes/use-edges.svelte.js +7 -0
- package/dist/runes/use-flow-ref.svelte.d.ts +18 -0
- package/dist/runes/use-flow-ref.svelte.js +19 -0
- package/dist/runes/use-flow-store.svelte.d.ts +13 -0
- package/dist/runes/use-flow-store.svelte.js +18 -0
- package/dist/runes/use-flow.svelte.d.ts +22 -0
- package/dist/runes/use-flow.svelte.js +18 -0
- package/dist/runes/use-handle.svelte.d.ts +56 -0
- package/dist/runes/use-handle.svelte.js +94 -0
- package/dist/runes/use-internal-node.svelte.d.ts +10 -0
- package/dist/runes/use-internal-node.svelte.js +16 -0
- package/dist/runes/use-key-press.svelte.d.ts +16 -0
- package/dist/runes/use-key-press.svelte.js +45 -0
- package/dist/runes/use-node-connections.svelte.d.ts +18 -0
- package/dist/runes/use-node-connections.svelte.js +30 -0
- package/dist/runes/use-node-id.svelte.d.ts +5 -0
- package/dist/runes/use-node-id.svelte.js +8 -0
- package/dist/runes/use-node.svelte.d.ts +47 -0
- package/dist/runes/use-node.svelte.js +122 -0
- package/dist/runes/use-nodes-data.svelte.d.ts +10 -0
- package/dist/runes/use-nodes-data.svelte.js +20 -0
- package/dist/runes/use-nodes.svelte.d.ts +4 -0
- package/dist/runes/use-nodes.svelte.js +7 -0
- package/dist/runes/use-on-viewport-change.svelte.d.ts +17 -0
- package/dist/runes/use-on-viewport-change.svelte.js +28 -0
- package/dist/runes/use-selection.svelte.d.ts +12 -0
- package/dist/runes/use-selection.svelte.js +19 -0
- package/dist/runes/use-viewport.svelte.d.ts +7 -0
- package/dist/runes/use-viewport.svelte.js +10 -0
- package/dist/selection/index.d.ts +1 -0
- package/dist/selection/index.js +3 -0
- package/dist/subflows/index.d.ts +1 -0
- package/dist/subflows/index.js +3 -0
- package/dist/typed.d.ts +32 -0
- package/dist/typed.js +15 -0
- package/dist/utils/engine-facade.d.ts +11 -0
- package/dist/utils/engine-facade.js +64 -0
- package/dist/utils/flow-store.svelte.d.ts +39 -0
- package/dist/utils/flow-store.svelte.js +133 -0
- package/dist/utils/merge-props.d.ts +8 -0
- package/dist/utils/merge-props.js +33 -0
- package/dist/utils/plain.svelte.d.ts +12 -0
- package/dist/utils/plain.svelte.js +44 -0
- package/dist/utils/portal-content.svelte +8 -0
- package/dist/utils/portal-content.svelte.d.ts +7 -0
- package/dist/utils/portal.svelte +34 -0
- package/dist/utils/portal.svelte.d.ts +8 -0
- package/dist/utils/render.d.ts +93 -0
- package/dist/utils/render.js +87 -0
- package/dist/utils/shallow-equal.d.ts +5 -0
- package/dist/utils/shallow-equal.js +32 -0
- package/package.json +105 -3
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
<script module lang="ts">
|
|
2
|
+
import type { EdgePath as EdgePathValue } from "@fragiola/flow";
|
|
3
|
+
import type { Snippet } from "svelte";
|
|
4
|
+
import type { SvgPrimitiveProps } from "../utils/render.js";
|
|
5
|
+
|
|
6
|
+
export interface EdgePathState {
|
|
7
|
+
readonly edgeId: string;
|
|
8
|
+
/** the edge's path, label point and ends */
|
|
9
|
+
readonly path: EdgePathValue;
|
|
10
|
+
/** `data-selected` (`selection()`) */
|
|
11
|
+
readonly selected: boolean;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface EdgePathProps
|
|
15
|
+
extends Omit<
|
|
16
|
+
SvgPrimitiveProps<EdgePathState, SVGPathElement>,
|
|
17
|
+
"children"
|
|
18
|
+
> {
|
|
19
|
+
/** the edge; default the enclosing `Flow.Edge`'s */
|
|
20
|
+
edgeId?: string | undefined;
|
|
21
|
+
/** SVG content inside the `<path>` (an `<animate>`, a `<title>`), given `{ state }` */
|
|
22
|
+
children?: Snippet<[{ state: EdgePathState }]> | undefined;
|
|
23
|
+
}
|
|
24
|
+
</script>
|
|
25
|
+
|
|
26
|
+
<!--
|
|
27
|
+
@component
|
|
28
|
+
An edge's path (`data-flow-part="edge-path"`): an SVG `<path>` whose `d` is the engine's
|
|
29
|
+
(`edge-path-by`, D9; before the engine, the static geometry's), unfilled. A `d` of your own draws an app type (from `state.path`'s ends).
|
|
30
|
+
Several may share an edge: a wide transparent one is a bigger press target. Its `children`
|
|
31
|
+
snippet renders inside the `<path>` (an `<animate>`), given `{ state }`.
|
|
32
|
+
-->
|
|
33
|
+
<script lang="ts">
|
|
34
|
+
import { useEdgeId, useFlowContext } from "../context.js";
|
|
35
|
+
import { flowValue, sameValue } from "../runes/internal.svelte.js";
|
|
36
|
+
import {
|
|
37
|
+
edgePathValue,
|
|
38
|
+
staticAttributes,
|
|
39
|
+
} from "../runes/use-edge.svelte.js";
|
|
40
|
+
import {
|
|
41
|
+
elementProps,
|
|
42
|
+
refProps,
|
|
43
|
+
type RenderedProps,
|
|
44
|
+
} from "../utils/render.js";
|
|
45
|
+
|
|
46
|
+
let {
|
|
47
|
+
edgeId: edgeIdProp,
|
|
48
|
+
children,
|
|
49
|
+
render,
|
|
50
|
+
class: className,
|
|
51
|
+
style,
|
|
52
|
+
ref = $bindable(),
|
|
53
|
+
...rest
|
|
54
|
+
}: EdgePathProps = $props();
|
|
55
|
+
|
|
56
|
+
const edgeIdOf = useEdgeId("EdgePath", () => edgeIdProp);
|
|
57
|
+
const context = useFlowContext("EdgePath");
|
|
58
|
+
const path = edgePathValue(context, edgeIdOf);
|
|
59
|
+
// the engine's attributes, or before it (the server, the first render) the document's
|
|
60
|
+
const attributes = flowValue(context, () => {
|
|
61
|
+
const edgeId = edgeIdOf();
|
|
62
|
+
const { engine, model } = context;
|
|
63
|
+
return engine
|
|
64
|
+
? engine.adapter.attributes("edge-path", { edgeId })
|
|
65
|
+
: staticAttributes(
|
|
66
|
+
"edge-path",
|
|
67
|
+
edgeId,
|
|
68
|
+
model.get("edge-by", { id: edgeId }),
|
|
69
|
+
);
|
|
70
|
+
},
|
|
71
|
+
sameValue,
|
|
72
|
+
{ entity: () => ({ kind: "edge", id: edgeIdOf() }) },
|
|
73
|
+
);
|
|
74
|
+
const refs = refProps((element) => {
|
|
75
|
+
ref = element as SVGPathElement | null;
|
|
76
|
+
});
|
|
77
|
+
const partState = $derived.by((): EdgePathState | undefined => {
|
|
78
|
+
const current = path.current;
|
|
79
|
+
const own = attributes.current;
|
|
80
|
+
return current && own
|
|
81
|
+
? {
|
|
82
|
+
edgeId: edgeIdOf(),
|
|
83
|
+
path: current,
|
|
84
|
+
selected: own["data-selected"] !== undefined,
|
|
85
|
+
}
|
|
86
|
+
: undefined;
|
|
87
|
+
});
|
|
88
|
+
const attrs: RenderedProps<SVGPathElement> = $derived(
|
|
89
|
+
partState
|
|
90
|
+
? elementProps({
|
|
91
|
+
rest,
|
|
92
|
+
className,
|
|
93
|
+
style,
|
|
94
|
+
state: partState,
|
|
95
|
+
own: {
|
|
96
|
+
...attributes.current,
|
|
97
|
+
d: partState.path.path,
|
|
98
|
+
fill: "none",
|
|
99
|
+
...refs,
|
|
100
|
+
},
|
|
101
|
+
})
|
|
102
|
+
: ({} as RenderedProps<SVGPathElement>),
|
|
103
|
+
);
|
|
104
|
+
</script>
|
|
105
|
+
|
|
106
|
+
{#snippet content()}
|
|
107
|
+
{#if partState}{@render children?.({ state: partState })}{/if}
|
|
108
|
+
{/snippet}
|
|
109
|
+
|
|
110
|
+
{#if partState}
|
|
111
|
+
{#if render}
|
|
112
|
+
{@render render({ props: attrs as never, state: partState, children: content })}
|
|
113
|
+
{:else}
|
|
114
|
+
<path {...attrs}>{@render content()}</path>
|
|
115
|
+
{/if}
|
|
116
|
+
{/if}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { EdgePath as EdgePathValue } from "@fragiola/flow";
|
|
2
|
+
import type { Snippet } from "svelte";
|
|
3
|
+
import type { SvgPrimitiveProps } from "../utils/render.js";
|
|
4
|
+
export interface EdgePathState {
|
|
5
|
+
readonly edgeId: string;
|
|
6
|
+
/** the edge's path, label point and ends */
|
|
7
|
+
readonly path: EdgePathValue;
|
|
8
|
+
/** `data-selected` (`selection()`) */
|
|
9
|
+
readonly selected: boolean;
|
|
10
|
+
}
|
|
11
|
+
export interface EdgePathProps extends Omit<SvgPrimitiveProps<EdgePathState, SVGPathElement>, "children"> {
|
|
12
|
+
/** the edge; default the enclosing `Flow.Edge`'s */
|
|
13
|
+
edgeId?: string | undefined;
|
|
14
|
+
/** SVG content inside the `<path>` (an `<animate>`, a `<title>`), given `{ state }` */
|
|
15
|
+
children?: Snippet<[{
|
|
16
|
+
state: EdgePathState;
|
|
17
|
+
}]> | undefined;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* An edge's path (`data-flow-part="edge-path"`): an SVG `<path>` whose `d` is the engine's
|
|
21
|
+
* (`edge-path-by`, D9; before the engine, the static geometry's), unfilled. A `d` of your own draws an app type (from `state.path`'s ends).
|
|
22
|
+
* Several may share an edge: a wide transparent one is a bigger press target. Its `children`
|
|
23
|
+
* snippet renders inside the `<path>` (an `<animate>`), given `{ state }`.
|
|
24
|
+
*/
|
|
25
|
+
declare const EdgePath: import("svelte").Component<EdgePathProps, {}, "ref">;
|
|
26
|
+
type EdgePath = ReturnType<typeof EdgePath>;
|
|
27
|
+
export default EdgePath;
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
<script module lang="ts">
|
|
2
|
+
import type { EdgeToolbarPosition, XY } from "@fragiola/flow";
|
|
3
|
+
import type { Snippet } from "svelte";
|
|
4
|
+
import type { DivPrimitiveProps } from "../utils/render.js";
|
|
5
|
+
|
|
6
|
+
export interface EdgeToolbarState {
|
|
7
|
+
readonly edgeId: string;
|
|
8
|
+
/** the point of the edge it stands at */
|
|
9
|
+
readonly position: "label" | "source" | "target";
|
|
10
|
+
/** where it is anchored (its `alignX` / `alignY` point), in pixels relative to the root */
|
|
11
|
+
readonly anchor: EdgeToolbarPosition;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface EdgeToolbarProps
|
|
15
|
+
extends Omit<DivPrimitiveProps<EdgeToolbarState>, "children"> {
|
|
16
|
+
/** its edge; default the enclosing `Flow.Edge`'s */
|
|
17
|
+
edgeId?: string | undefined;
|
|
18
|
+
/** the point of the edge it stands at: its label point, its source or its target end; default `"label"` */
|
|
19
|
+
position?: "label" | "source" | "target" | undefined;
|
|
20
|
+
/** a flow point it stands at instead (absolute flow coordinates); wins over `position` */
|
|
21
|
+
point?: XY | undefined;
|
|
22
|
+
/** a screen offset from that point, in pixels; default `{ x: 0, y: 0 }` */
|
|
23
|
+
offset?: XY | undefined;
|
|
24
|
+
/** which of its edges goes at the point across: its left (`"start"`), centre (default) or right */
|
|
25
|
+
alignX?: "start" | "center" | "end" | undefined;
|
|
26
|
+
/** which of its edges goes at the point down: its top (`"start"`), centre (default) or bottom */
|
|
27
|
+
alignY?: "start" | "center" | "end" | undefined;
|
|
28
|
+
/** whether it is shown; default while its edge is selected (`selection()`) */
|
|
29
|
+
open?: boolean | undefined;
|
|
30
|
+
/** your buttons */
|
|
31
|
+
children?: Snippet<[{ state: EdgeToolbarState }]> | undefined;
|
|
32
|
+
}
|
|
33
|
+
</script>
|
|
34
|
+
|
|
35
|
+
<!--
|
|
36
|
+
@component
|
|
37
|
+
A toolbar on an edge (`data-flow-part="toolbar"`, `data-flow-id` its edge's id), outside the
|
|
38
|
+
zoom: rendered in `Flow.Root` (a portal), at the point `edge-toolbar-by` gives (the edge's
|
|
39
|
+
label point, one of its ends or its `point`; its centre there, or the side `alignX` / `alignY` say), so it keeps its size at any zoom. Presses and the wheel
|
|
40
|
+
over it are left to it. It renders only its children (your buttons).
|
|
41
|
+
-->
|
|
42
|
+
<script lang="ts">
|
|
43
|
+
import { useEdgeId, useFlowContext } from "../context.js";
|
|
44
|
+
import { flowValue } from "../runes/internal.svelte.js";
|
|
45
|
+
import { plain } from "../utils/plain.svelte.js";
|
|
46
|
+
import Portal from "../utils/portal.svelte";
|
|
47
|
+
import {
|
|
48
|
+
elementProps,
|
|
49
|
+
px,
|
|
50
|
+
refProps,
|
|
51
|
+
type RenderedProps,
|
|
52
|
+
} from "../utils/render.js";
|
|
53
|
+
|
|
54
|
+
let {
|
|
55
|
+
edgeId: edgeIdProp,
|
|
56
|
+
position = "label",
|
|
57
|
+
point,
|
|
58
|
+
offset,
|
|
59
|
+
alignX,
|
|
60
|
+
alignY,
|
|
61
|
+
open,
|
|
62
|
+
children,
|
|
63
|
+
render,
|
|
64
|
+
class: className,
|
|
65
|
+
style,
|
|
66
|
+
ref = $bindable(),
|
|
67
|
+
...rest
|
|
68
|
+
}: EdgeToolbarProps = $props();
|
|
69
|
+
|
|
70
|
+
const edgeIdOf = useEdgeId("EdgeToolbar", () => edgeIdProp);
|
|
71
|
+
const context = useFlowContext("EdgeToolbar");
|
|
72
|
+
// hidden, it reads nothing of the view: a pan or a zoom gives the same value (nothing
|
|
73
|
+
// updates); shown, an equal anchor keeps the last value
|
|
74
|
+
const view = flowValue(context, () => {
|
|
75
|
+
const { engine, model } = context;
|
|
76
|
+
if (!engine) return undefined;
|
|
77
|
+
const edgeId = edgeIdOf();
|
|
78
|
+
if (!(open ?? model.is("edge-selected", { edgeId }))) return undefined;
|
|
79
|
+
const anchor = engine.get("edge-toolbar-by", {
|
|
80
|
+
edgeId,
|
|
81
|
+
position,
|
|
82
|
+
point: plain(point),
|
|
83
|
+
offset: plain(offset),
|
|
84
|
+
alignX,
|
|
85
|
+
alignY,
|
|
86
|
+
});
|
|
87
|
+
return anchor
|
|
88
|
+
? {
|
|
89
|
+
anchor,
|
|
90
|
+
attributes: engine.adapter.attributes("toolbar", { edgeId }),
|
|
91
|
+
}
|
|
92
|
+
: undefined;
|
|
93
|
+
});
|
|
94
|
+
const refs = refProps((element) => {
|
|
95
|
+
ref = element as HTMLDivElement | null;
|
|
96
|
+
});
|
|
97
|
+
const partState = $derived.by((): EdgeToolbarState | undefined =>
|
|
98
|
+
view.current
|
|
99
|
+
? { edgeId: edgeIdOf(), position, anchor: view.current.anchor }
|
|
100
|
+
: undefined,
|
|
101
|
+
);
|
|
102
|
+
const attrs: RenderedProps<HTMLDivElement> = $derived.by(() => {
|
|
103
|
+
if (!partState || !view.current) return {} as RenderedProps<HTMLDivElement>;
|
|
104
|
+
const { x, y, anchorX, anchorY } = partState.anchor;
|
|
105
|
+
return elementProps({
|
|
106
|
+
rest,
|
|
107
|
+
className,
|
|
108
|
+
style,
|
|
109
|
+
state: partState,
|
|
110
|
+
own: { ...view.current.attributes, ...refs },
|
|
111
|
+
structural: {
|
|
112
|
+
position: "absolute",
|
|
113
|
+
top: "0",
|
|
114
|
+
left: "0",
|
|
115
|
+
transform: `translate(${px(x)}, ${px(y)}) translate(${-anchorX * 100}%, ${-anchorY * 100}%)`,
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
</script>
|
|
120
|
+
|
|
121
|
+
{#snippet content()}
|
|
122
|
+
{#if partState}{@render children?.({ state: partState })}{/if}
|
|
123
|
+
{/snippet}
|
|
124
|
+
|
|
125
|
+
{#snippet toolbar()}
|
|
126
|
+
{#if partState}
|
|
127
|
+
{#if render}
|
|
128
|
+
{@render render({ props: attrs as never, state: partState, children: content })}
|
|
129
|
+
{:else}
|
|
130
|
+
<div {...attrs}>{@render content()}</div>
|
|
131
|
+
{/if}
|
|
132
|
+
{/if}
|
|
133
|
+
{/snippet}
|
|
134
|
+
|
|
135
|
+
{#if partState}
|
|
136
|
+
<Portal target={context.rootElement}>{@render toolbar()}</Portal>
|
|
137
|
+
{/if}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { EdgeToolbarPosition, XY } from "@fragiola/flow";
|
|
2
|
+
import type { Snippet } from "svelte";
|
|
3
|
+
import type { DivPrimitiveProps } from "../utils/render.js";
|
|
4
|
+
export interface EdgeToolbarState {
|
|
5
|
+
readonly edgeId: string;
|
|
6
|
+
/** the point of the edge it stands at */
|
|
7
|
+
readonly position: "label" | "source" | "target";
|
|
8
|
+
/** where it is anchored (its `alignX` / `alignY` point), in pixels relative to the root */
|
|
9
|
+
readonly anchor: EdgeToolbarPosition;
|
|
10
|
+
}
|
|
11
|
+
export interface EdgeToolbarProps extends Omit<DivPrimitiveProps<EdgeToolbarState>, "children"> {
|
|
12
|
+
/** its edge; default the enclosing `Flow.Edge`'s */
|
|
13
|
+
edgeId?: string | undefined;
|
|
14
|
+
/** the point of the edge it stands at: its label point, its source or its target end; default `"label"` */
|
|
15
|
+
position?: "label" | "source" | "target" | undefined;
|
|
16
|
+
/** a flow point it stands at instead (absolute flow coordinates); wins over `position` */
|
|
17
|
+
point?: XY | undefined;
|
|
18
|
+
/** a screen offset from that point, in pixels; default `{ x: 0, y: 0 }` */
|
|
19
|
+
offset?: XY | undefined;
|
|
20
|
+
/** which of its edges goes at the point across: its left (`"start"`), centre (default) or right */
|
|
21
|
+
alignX?: "start" | "center" | "end" | undefined;
|
|
22
|
+
/** which of its edges goes at the point down: its top (`"start"`), centre (default) or bottom */
|
|
23
|
+
alignY?: "start" | "center" | "end" | undefined;
|
|
24
|
+
/** whether it is shown; default while its edge is selected (`selection()`) */
|
|
25
|
+
open?: boolean | undefined;
|
|
26
|
+
/** your buttons */
|
|
27
|
+
children?: Snippet<[{
|
|
28
|
+
state: EdgeToolbarState;
|
|
29
|
+
}]> | undefined;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* A toolbar on an edge (`data-flow-part="toolbar"`, `data-flow-id` its edge's id), outside the
|
|
33
|
+
* zoom: rendered in `Flow.Root` (a portal), at the point `edge-toolbar-by` gives (the edge's
|
|
34
|
+
* label point, one of its ends or its `point`; its centre there, or the side `alignX` / `alignY` say), so it keeps its size at any zoom. Presses and the wheel
|
|
35
|
+
* over it are left to it. It renders only its children (your buttons).
|
|
36
|
+
*/
|
|
37
|
+
declare const EdgeToolbar: import("svelte").Component<EdgeToolbarProps, {}, "ref">;
|
|
38
|
+
type EdgeToolbar = ReturnType<typeof EdgeToolbar>;
|
|
39
|
+
export default EdgeToolbar;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
<script module lang="ts">
|
|
2
|
+
import type { AnyTypes, FlowEdge, FlowTypes } from "@fragiola/flow";
|
|
3
|
+
import type { Snippet } from "svelte";
|
|
4
|
+
import type { EdgeState } from "../runes/use-edge.svelte.js";
|
|
5
|
+
import type { SvgPrimitiveProps } from "../utils/render.js";
|
|
6
|
+
|
|
7
|
+
export interface EdgeProps<T extends FlowTypes = AnyTypes>
|
|
8
|
+
extends Omit<SvgPrimitiveProps<EdgeState<T>, SVGGElement>, "children"> {
|
|
9
|
+
/** the edge it draws: the one `Flow.Edges` gives its children snippet */
|
|
10
|
+
edge: FlowEdge<T>;
|
|
11
|
+
/** its parts: default a `Flow.EdgePath` */
|
|
12
|
+
children?: Snippet<[{ state: EdgeState<T> }]> | undefined;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const EDGE_STYLE = { "pointer-events": "visibleStroke" };
|
|
16
|
+
</script>
|
|
17
|
+
|
|
18
|
+
<!--
|
|
19
|
+
@component
|
|
20
|
+
One edge (`data-flow-part="edge"`, `data-flow-id`): an SVG group inside `Flow.Edges`, drawn once
|
|
21
|
+
both its nodes have a size. It renders its children (`Flow.EdgePath` by default,
|
|
22
|
+
`Flow.EdgeLabel`, `Flow.ReconnectAnchor`); a press on its stroke selects it (`selection()`).
|
|
23
|
+
-->
|
|
24
|
+
<script lang="ts" generics="T extends FlowTypes = AnyTypes">
|
|
25
|
+
import { untrack } from "svelte";
|
|
26
|
+
import { type Attachment, createAttachmentKey } from "svelte/attachments";
|
|
27
|
+
import { setEdgeContext, useFlowContext } from "../context.js";
|
|
28
|
+
import { useEdge } from "../runes/use-edge.svelte.js";
|
|
29
|
+
import {
|
|
30
|
+
elementProps,
|
|
31
|
+
refProps,
|
|
32
|
+
type RenderedProps,
|
|
33
|
+
} from "../utils/render.js";
|
|
34
|
+
import EdgePath from "./edge-path.svelte";
|
|
35
|
+
|
|
36
|
+
let {
|
|
37
|
+
edge,
|
|
38
|
+
children,
|
|
39
|
+
render,
|
|
40
|
+
class: className,
|
|
41
|
+
style,
|
|
42
|
+
ref = $bindable(),
|
|
43
|
+
...rest
|
|
44
|
+
}: EdgeProps<T> = $props();
|
|
45
|
+
|
|
46
|
+
const context = useFlowContext("Edge");
|
|
47
|
+
const own = useEdge<T>(() => edge);
|
|
48
|
+
// mounted again (moved to another render level's SVG, keyed by its id): the engine gives it
|
|
49
|
+
// back the focus it had, when the focus was lost meanwhile
|
|
50
|
+
const refocusKey = createAttachmentKey();
|
|
51
|
+
const refocus: Attachment<Element> = (element) => {
|
|
52
|
+
untrack(() => context.engine)?.adapter.refocus(element);
|
|
53
|
+
};
|
|
54
|
+
// the id alone: the parts inside follow another id, not every new edge object
|
|
55
|
+
const edgeId = $derived(edge.id);
|
|
56
|
+
setEdgeContext({
|
|
57
|
+
get edgeId() {
|
|
58
|
+
return edgeId;
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
const refs = refProps((element) => {
|
|
62
|
+
ref = element as SVGGElement | null;
|
|
63
|
+
});
|
|
64
|
+
const attrs: RenderedProps<SVGGElement> = $derived(
|
|
65
|
+
elementProps({
|
|
66
|
+
rest,
|
|
67
|
+
className,
|
|
68
|
+
style,
|
|
69
|
+
state: own.state,
|
|
70
|
+
own: { ...own.props, ...refs, [refocusKey]: refocus },
|
|
71
|
+
structural: EDGE_STYLE,
|
|
72
|
+
}),
|
|
73
|
+
);
|
|
74
|
+
</script>
|
|
75
|
+
|
|
76
|
+
{#snippet content()}
|
|
77
|
+
{#if children}
|
|
78
|
+
{@render children({ state: own.state })}
|
|
79
|
+
{:else}
|
|
80
|
+
<EdgePath />
|
|
81
|
+
{/if}
|
|
82
|
+
{/snippet}
|
|
83
|
+
|
|
84
|
+
{#if own.state.path}
|
|
85
|
+
{#if render}
|
|
86
|
+
{@render render({ props: attrs as never, state: own.state, children: content })}
|
|
87
|
+
{:else}
|
|
88
|
+
<g {...attrs}>{@render content()}</g>
|
|
89
|
+
{/if}
|
|
90
|
+
{/if}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { AnyTypes, FlowEdge, FlowTypes } from "@fragiola/flow";
|
|
2
|
+
import type { Snippet } from "svelte";
|
|
3
|
+
import type { EdgeState } from "../runes/use-edge.svelte.js";
|
|
4
|
+
import type { SvgPrimitiveProps } from "../utils/render.js";
|
|
5
|
+
export interface EdgeProps<T extends FlowTypes = AnyTypes> extends Omit<SvgPrimitiveProps<EdgeState<T>, SVGGElement>, "children"> {
|
|
6
|
+
/** the edge it draws: the one `Flow.Edges` gives its children snippet */
|
|
7
|
+
edge: FlowEdge<T>;
|
|
8
|
+
/** its parts: default a `Flow.EdgePath` */
|
|
9
|
+
children?: Snippet<[{
|
|
10
|
+
state: EdgeState<T>;
|
|
11
|
+
}]> | undefined;
|
|
12
|
+
}
|
|
13
|
+
declare function $$render<T extends FlowTypes = AnyTypes>(): {
|
|
14
|
+
props: EdgeProps<T>;
|
|
15
|
+
exports: {};
|
|
16
|
+
bindings: "ref";
|
|
17
|
+
slots: {};
|
|
18
|
+
events: {};
|
|
19
|
+
};
|
|
20
|
+
declare class __sveltets_Render<T extends FlowTypes = AnyTypes> {
|
|
21
|
+
props(): ReturnType<typeof $$render<T>>['props'];
|
|
22
|
+
events(): ReturnType<typeof $$render<T>>['events'];
|
|
23
|
+
slots(): ReturnType<typeof $$render<T>>['slots'];
|
|
24
|
+
bindings(): "ref";
|
|
25
|
+
exports(): {};
|
|
26
|
+
}
|
|
27
|
+
interface $$IsomorphicComponent {
|
|
28
|
+
new <T extends FlowTypes = AnyTypes>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<T>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<T>['props']>, ReturnType<__sveltets_Render<T>['events']>, ReturnType<__sveltets_Render<T>['slots']>> & {
|
|
29
|
+
$$bindings?: ReturnType<__sveltets_Render<T>['bindings']>;
|
|
30
|
+
} & ReturnType<__sveltets_Render<T>['exports']>;
|
|
31
|
+
<T extends FlowTypes = AnyTypes>(internal: unknown, props: ReturnType<__sveltets_Render<T>['props']> & {}): ReturnType<__sveltets_Render<T>['exports']>;
|
|
32
|
+
z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* One edge (`data-flow-part="edge"`, `data-flow-id`): an SVG group inside `Flow.Edges`, drawn once
|
|
36
|
+
* both its nodes have a size. It renders its children (`Flow.EdgePath` by default,
|
|
37
|
+
* `Flow.EdgeLabel`, `Flow.ReconnectAnchor`); a press on its stroke selects it (`selection()`).
|
|
38
|
+
*/
|
|
39
|
+
declare const Edge: $$IsomorphicComponent;
|
|
40
|
+
type Edge<T extends FlowTypes = AnyTypes> = InstanceType<typeof Edge<T>>;
|
|
41
|
+
export default Edge;
|