@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
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Mauro de Souza
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @fragiola/flow-svelte
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Composable, unstyled Svelte 5 primitives for **Flow**, headless node-based editors and diagrams:
|
|
4
|
+
`Flow.Root`, `Flow.Viewport`, `Flow.Nodes`, `Flow.Node`, `Flow.Handle`, `Flow.Edges`, `Flow.Edge`,
|
|
5
|
+
`Flow.Background`, `Flow.Controls`, … over the framework-free core `@fragiola/flow` (re-exported
|
|
6
|
+
whole, so a Svelte app installs this one package). The opt-in features are on their own entries
|
|
7
|
+
(`@fragiola/flow-svelte/selection`, `/drag`, `/connection`, `/reconnection`, `/resize`,
|
|
8
|
+
`/subflows`, `/keyboard`, `/minimap`). No CSS, no icons, no text: you style every part, through
|
|
9
|
+
its `data-flow-part` and state attributes.
|
|
10
|
+
|
|
11
|
+
Not usable yet: version `0.0.0`, nothing is published.
|
|
12
|
+
|
|
13
|
+
Documentation: **<https://fragiola.com/flow>** (coming soon). ESM only. Svelte 5.29 or later
|
|
14
|
+
(runes, snippets, attachments).
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
<script module lang="ts">
|
|
2
|
+
import type { BackgroundPattern, BackgroundVariant } from "@fragiola/flow";
|
|
3
|
+
import type { SvgPrimitiveProps } from "../utils/render.js";
|
|
4
|
+
|
|
5
|
+
export interface BackgroundState {
|
|
6
|
+
/** the pattern's tile on the screen, at the current viewport */
|
|
7
|
+
readonly pattern: BackgroundPattern;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface BackgroundProps
|
|
11
|
+
extends Omit<
|
|
12
|
+
SvgPrimitiveProps<BackgroundState, SVGSVGElement>,
|
|
13
|
+
"children" | "offset"
|
|
14
|
+
> {
|
|
15
|
+
/** the marks: `dots` (default), `lines` or `cross` */
|
|
16
|
+
variant?: BackgroundVariant | undefined;
|
|
17
|
+
/** the distance between two marks, in flow units; default 20 (`[x, y]` for two) */
|
|
18
|
+
gap?: number | readonly [number, number] | undefined;
|
|
19
|
+
/** dots: a dot's diameter (flow units); lines: the stroke width (screen pixels); cross: a bar's length */
|
|
20
|
+
size?: number | undefined;
|
|
21
|
+
/** the pattern's shift from the flow's origin, in flow units */
|
|
22
|
+
offset?: number | readonly [number, number] | undefined;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const BACKGROUND_STYLE = {
|
|
26
|
+
position: "absolute",
|
|
27
|
+
top: "0",
|
|
28
|
+
left: "0",
|
|
29
|
+
width: "100%",
|
|
30
|
+
height: "100%",
|
|
31
|
+
"pointer-events": "none",
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const EMPTY_PATTERN: BackgroundPattern = Object.freeze({
|
|
35
|
+
variant: "dots",
|
|
36
|
+
x: 0,
|
|
37
|
+
y: 0,
|
|
38
|
+
width: 0,
|
|
39
|
+
height: 0,
|
|
40
|
+
dot: undefined,
|
|
41
|
+
path: undefined,
|
|
42
|
+
strokeWidth: 0,
|
|
43
|
+
});
|
|
44
|
+
</script>
|
|
45
|
+
|
|
46
|
+
<!--
|
|
47
|
+
@component
|
|
48
|
+
The flow's background (`data-flow-part="background"`): an SVG pattern of dots, lines or crosses
|
|
49
|
+
that pans and zooms with the viewport (`background-pattern`), inside `Flow.Root` before
|
|
50
|
+
`Flow.Viewport`. The marks are drawn in `currentColor`: set the `color` (and the background
|
|
51
|
+
itself) in your style.
|
|
52
|
+
-->
|
|
53
|
+
<script lang="ts">
|
|
54
|
+
import { partAttributes } from "@fragiola/flow";
|
|
55
|
+
import { useFlowContext } from "../context.js";
|
|
56
|
+
import { flowValue } from "../runes/internal.svelte.js";
|
|
57
|
+
import {
|
|
58
|
+
elementProps,
|
|
59
|
+
refProps,
|
|
60
|
+
type RenderedProps,
|
|
61
|
+
} from "../utils/render.js";
|
|
62
|
+
|
|
63
|
+
let {
|
|
64
|
+
variant,
|
|
65
|
+
gap,
|
|
66
|
+
size,
|
|
67
|
+
offset,
|
|
68
|
+
render,
|
|
69
|
+
class: className,
|
|
70
|
+
style,
|
|
71
|
+
ref = $bindable(),
|
|
72
|
+
...rest
|
|
73
|
+
}: BackgroundProps = $props();
|
|
74
|
+
|
|
75
|
+
const context = useFlowContext("Background");
|
|
76
|
+
const pattern = flowValue(context, () =>
|
|
77
|
+
context.engine
|
|
78
|
+
? context.engine.get("background-pattern", {
|
|
79
|
+
variant,
|
|
80
|
+
gap,
|
|
81
|
+
size,
|
|
82
|
+
offset,
|
|
83
|
+
})
|
|
84
|
+
: undefined,
|
|
85
|
+
);
|
|
86
|
+
const uid = $props.id();
|
|
87
|
+
const id = `flow-background-${uid.replace(/[^a-zA-Z0-9_-]/g, "")}`;
|
|
88
|
+
const refs = refProps((element) => {
|
|
89
|
+
ref = element as SVGSVGElement | null;
|
|
90
|
+
});
|
|
91
|
+
// drawn once the engine is there (a server render has the bare element)
|
|
92
|
+
const partState = $derived<BackgroundState>({
|
|
93
|
+
pattern: pattern.current ?? EMPTY_PATTERN,
|
|
94
|
+
});
|
|
95
|
+
const attrs: RenderedProps<SVGSVGElement> = $derived(
|
|
96
|
+
elementProps({
|
|
97
|
+
rest,
|
|
98
|
+
className,
|
|
99
|
+
style,
|
|
100
|
+
state: partState,
|
|
101
|
+
own: { ...partAttributes("background"), ...refs },
|
|
102
|
+
structural: BACKGROUND_STYLE,
|
|
103
|
+
}),
|
|
104
|
+
);
|
|
105
|
+
</script>
|
|
106
|
+
|
|
107
|
+
{#snippet content()}
|
|
108
|
+
{#if pattern.current}
|
|
109
|
+
{@const tile = pattern.current}
|
|
110
|
+
<pattern
|
|
111
|
+
data-flow-part="background-pattern"
|
|
112
|
+
{id}
|
|
113
|
+
patternUnits="userSpaceOnUse"
|
|
114
|
+
x={tile.x}
|
|
115
|
+
y={tile.y}
|
|
116
|
+
width={tile.width}
|
|
117
|
+
height={tile.height}
|
|
118
|
+
>
|
|
119
|
+
{#if tile.dot}
|
|
120
|
+
<circle
|
|
121
|
+
data-flow-part="background-mark"
|
|
122
|
+
cx={tile.dot.cx}
|
|
123
|
+
cy={tile.dot.cy}
|
|
124
|
+
r={tile.dot.r}
|
|
125
|
+
fill="currentColor"
|
|
126
|
+
/>
|
|
127
|
+
{:else}
|
|
128
|
+
<path
|
|
129
|
+
data-flow-part="background-mark"
|
|
130
|
+
d={tile.path}
|
|
131
|
+
fill="none"
|
|
132
|
+
stroke="currentColor"
|
|
133
|
+
stroke-width={tile.strokeWidth}
|
|
134
|
+
/>
|
|
135
|
+
{/if}
|
|
136
|
+
</pattern>
|
|
137
|
+
<rect
|
|
138
|
+
data-flow-part="background-fill"
|
|
139
|
+
width="100%"
|
|
140
|
+
height="100%"
|
|
141
|
+
fill={`url(#${id})`}
|
|
142
|
+
/>
|
|
143
|
+
{/if}
|
|
144
|
+
{/snippet}
|
|
145
|
+
|
|
146
|
+
{#if render}
|
|
147
|
+
{@render render({ props: attrs as never, state: partState, children: content })}
|
|
148
|
+
{:else}
|
|
149
|
+
<svg {...attrs}>{@render content()}</svg>
|
|
150
|
+
{/if}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { BackgroundPattern, BackgroundVariant } from "@fragiola/flow";
|
|
2
|
+
import type { SvgPrimitiveProps } from "../utils/render.js";
|
|
3
|
+
export interface BackgroundState {
|
|
4
|
+
/** the pattern's tile on the screen, at the current viewport */
|
|
5
|
+
readonly pattern: BackgroundPattern;
|
|
6
|
+
}
|
|
7
|
+
export interface BackgroundProps extends Omit<SvgPrimitiveProps<BackgroundState, SVGSVGElement>, "children" | "offset"> {
|
|
8
|
+
/** the marks: `dots` (default), `lines` or `cross` */
|
|
9
|
+
variant?: BackgroundVariant | undefined;
|
|
10
|
+
/** the distance between two marks, in flow units; default 20 (`[x, y]` for two) */
|
|
11
|
+
gap?: number | readonly [number, number] | undefined;
|
|
12
|
+
/** dots: a dot's diameter (flow units); lines: the stroke width (screen pixels); cross: a bar's length */
|
|
13
|
+
size?: number | undefined;
|
|
14
|
+
/** the pattern's shift from the flow's origin, in flow units */
|
|
15
|
+
offset?: number | readonly [number, number] | undefined;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The flow's background (`data-flow-part="background"`): an SVG pattern of dots, lines or crosses
|
|
19
|
+
* that pans and zooms with the viewport (`background-pattern`), inside `Flow.Root` before
|
|
20
|
+
* `Flow.Viewport`. The marks are drawn in `currentColor`: set the `color` (and the background
|
|
21
|
+
* itself) in your style.
|
|
22
|
+
*/
|
|
23
|
+
declare const Background: import("svelte").Component<BackgroundProps, {}, "ref">;
|
|
24
|
+
type Background = ReturnType<typeof Background>;
|
|
25
|
+
export default Background;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
<script module lang="ts">
|
|
2
|
+
import type { Connection } from "@fragiola/flow";
|
|
3
|
+
import type { Snippet } from "svelte";
|
|
4
|
+
import type { SvgPrimitiveProps } from "../utils/render.js";
|
|
5
|
+
|
|
6
|
+
export interface ConnectionLineState {
|
|
7
|
+
/** the connection being drawn */
|
|
8
|
+
readonly connection: Connection;
|
|
9
|
+
/** the drop would add the edge: `data-valid` */
|
|
10
|
+
readonly valid: boolean;
|
|
11
|
+
/** the drop would be refused (`model.can("edge.add")`, a middleware's veto): `data-invalid` */
|
|
12
|
+
readonly invalid: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface ConnectionLineProps
|
|
16
|
+
extends Omit<
|
|
17
|
+
SvgPrimitiveProps<ConnectionLineState, SVGSVGElement>,
|
|
18
|
+
"children"
|
|
19
|
+
> {
|
|
20
|
+
/**
|
|
21
|
+
* draws the line, in flow coordinates (`{#snippet children(connection)}`); default an
|
|
22
|
+
* unfilled `<path>` of the connection's path (`data-flow-part="connection-path"`)
|
|
23
|
+
*/
|
|
24
|
+
children?: Snippet<[Connection]> | undefined;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const LINE_STYLE = {
|
|
28
|
+
position: "absolute",
|
|
29
|
+
top: "0",
|
|
30
|
+
left: "0",
|
|
31
|
+
width: "100%",
|
|
32
|
+
height: "100%",
|
|
33
|
+
overflow: "visible",
|
|
34
|
+
"pointer-events": "none",
|
|
35
|
+
};
|
|
36
|
+
</script>
|
|
37
|
+
|
|
38
|
+
<!--
|
|
39
|
+
@component
|
|
40
|
+
The connection being drawn (`data-flow-part="connection-line"`, `data-valid` / `data-invalid`,
|
|
41
|
+
`connection()`): an SVG inside `Flow.Viewport`, rendered only while a connection is under way.
|
|
42
|
+
-->
|
|
43
|
+
<script lang="ts">
|
|
44
|
+
import { useFlowContext } from "../context.js";
|
|
45
|
+
import { flowValue } from "../runes/internal.svelte.js";
|
|
46
|
+
import { useConnection } from "../runes/use-connection.svelte.js";
|
|
47
|
+
import {
|
|
48
|
+
elementProps,
|
|
49
|
+
refProps,
|
|
50
|
+
type RenderedProps,
|
|
51
|
+
} from "../utils/render.js";
|
|
52
|
+
|
|
53
|
+
let {
|
|
54
|
+
children,
|
|
55
|
+
render,
|
|
56
|
+
class: className,
|
|
57
|
+
style,
|
|
58
|
+
ref = $bindable(),
|
|
59
|
+
...rest
|
|
60
|
+
}: ConnectionLineProps = $props();
|
|
61
|
+
|
|
62
|
+
const context = useFlowContext("ConnectionLine");
|
|
63
|
+
const connection = useConnection();
|
|
64
|
+
const attributes = flowValue(
|
|
65
|
+
context,
|
|
66
|
+
() => context.engine?.adapter.attributes("connection-line") ?? {},
|
|
67
|
+
);
|
|
68
|
+
const refs = refProps((element) => {
|
|
69
|
+
ref = element as SVGSVGElement | null;
|
|
70
|
+
});
|
|
71
|
+
const partState = $derived.by((): ConnectionLineState | undefined => {
|
|
72
|
+
const current = connection.current;
|
|
73
|
+
const own = attributes.current;
|
|
74
|
+
return current
|
|
75
|
+
? {
|
|
76
|
+
connection: current,
|
|
77
|
+
valid: own["data-valid"] !== undefined,
|
|
78
|
+
invalid: own["data-invalid"] !== undefined,
|
|
79
|
+
}
|
|
80
|
+
: undefined;
|
|
81
|
+
});
|
|
82
|
+
const attrs: RenderedProps<SVGSVGElement> = $derived(
|
|
83
|
+
partState
|
|
84
|
+
? elementProps({
|
|
85
|
+
rest,
|
|
86
|
+
className,
|
|
87
|
+
style,
|
|
88
|
+
state: partState,
|
|
89
|
+
own: {
|
|
90
|
+
...attributes.current,
|
|
91
|
+
"data-flow-part": "connection-line",
|
|
92
|
+
...refs,
|
|
93
|
+
},
|
|
94
|
+
structural: LINE_STYLE,
|
|
95
|
+
})
|
|
96
|
+
: ({} as RenderedProps<SVGSVGElement>),
|
|
97
|
+
);
|
|
98
|
+
</script>
|
|
99
|
+
|
|
100
|
+
{#snippet content()}
|
|
101
|
+
{#if partState}
|
|
102
|
+
{#if children}
|
|
103
|
+
{@render children(partState.connection)}
|
|
104
|
+
{:else}
|
|
105
|
+
<path
|
|
106
|
+
data-flow-part="connection-path"
|
|
107
|
+
d={partState.connection.path}
|
|
108
|
+
fill="none"
|
|
109
|
+
/>
|
|
110
|
+
{/if}
|
|
111
|
+
{/if}
|
|
112
|
+
{/snippet}
|
|
113
|
+
|
|
114
|
+
{#if partState}
|
|
115
|
+
{#if render}
|
|
116
|
+
{@render render({ props: attrs as never, state: partState, children: content })}
|
|
117
|
+
{:else}
|
|
118
|
+
<svg {...attrs}>{@render content()}</svg>
|
|
119
|
+
{/if}
|
|
120
|
+
{/if}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Connection } from "@fragiola/flow";
|
|
2
|
+
import type { Snippet } from "svelte";
|
|
3
|
+
import type { SvgPrimitiveProps } from "../utils/render.js";
|
|
4
|
+
export interface ConnectionLineState {
|
|
5
|
+
/** the connection being drawn */
|
|
6
|
+
readonly connection: Connection;
|
|
7
|
+
/** the drop would add the edge: `data-valid` */
|
|
8
|
+
readonly valid: boolean;
|
|
9
|
+
/** the drop would be refused (`model.can("edge.add")`, a middleware's veto): `data-invalid` */
|
|
10
|
+
readonly invalid: boolean;
|
|
11
|
+
}
|
|
12
|
+
export interface ConnectionLineProps extends Omit<SvgPrimitiveProps<ConnectionLineState, SVGSVGElement>, "children"> {
|
|
13
|
+
/**
|
|
14
|
+
* draws the line, in flow coordinates (`{#snippet children(connection)}`); default an
|
|
15
|
+
* unfilled `<path>` of the connection's path (`data-flow-part="connection-path"`)
|
|
16
|
+
*/
|
|
17
|
+
children?: Snippet<[Connection]> | undefined;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The connection being drawn (`data-flow-part="connection-line"`, `data-valid` / `data-invalid`,
|
|
21
|
+
* `connection()`): an SVG inside `Flow.Viewport`, rendered only while a connection is under way.
|
|
22
|
+
*/
|
|
23
|
+
declare const ConnectionLine: import("svelte").Component<ConnectionLineProps, {}, "ref">;
|
|
24
|
+
type ConnectionLine = ReturnType<typeof ConnectionLine>;
|
|
25
|
+
export default ConnectionLine;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
<script module lang="ts">
|
|
2
|
+
import type { Snippet } from "svelte";
|
|
3
|
+
import type { DivPrimitiveProps } from "../utils/render.js";
|
|
4
|
+
|
|
5
|
+
/** The state of `Flow.Controls` (none: its buttons have their own). */
|
|
6
|
+
export type ControlsState = Record<never, never>;
|
|
7
|
+
|
|
8
|
+
export interface ControlsProps
|
|
9
|
+
extends Omit<DivPrimitiveProps<ControlsState>, "children"> {
|
|
10
|
+
children?: Snippet<[{ state: ControlsState }]> | undefined;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const STATE: ControlsState = Object.freeze({});
|
|
14
|
+
</script>
|
|
15
|
+
|
|
16
|
+
<!--
|
|
17
|
+
@component
|
|
18
|
+
A group of the viewport's buttons (`data-flow-part="controls"`): `Flow.ZoomIn`, `Flow.ZoomOut`,
|
|
19
|
+
`Flow.FitView`, `Flow.ToggleInteractive`, or your own. Inside `Flow.Root`, outside
|
|
20
|
+
`Flow.Viewport`; presses and the wheel over it are left to it. Place it with your style.
|
|
21
|
+
-->
|
|
22
|
+
<script lang="ts">
|
|
23
|
+
import { partAttributes } from "@fragiola/flow";
|
|
24
|
+
import {
|
|
25
|
+
elementProps,
|
|
26
|
+
refProps,
|
|
27
|
+
type RenderedProps,
|
|
28
|
+
} from "../utils/render.js";
|
|
29
|
+
|
|
30
|
+
let {
|
|
31
|
+
children,
|
|
32
|
+
render,
|
|
33
|
+
class: className,
|
|
34
|
+
style,
|
|
35
|
+
ref = $bindable(),
|
|
36
|
+
...rest
|
|
37
|
+
}: ControlsProps = $props();
|
|
38
|
+
|
|
39
|
+
const refs = refProps((element) => {
|
|
40
|
+
ref = element as HTMLDivElement | null;
|
|
41
|
+
});
|
|
42
|
+
const own = { ...partAttributes("controls"), ...refs };
|
|
43
|
+
const attrs: RenderedProps<HTMLDivElement> = $derived(
|
|
44
|
+
elementProps({ rest, className, style, state: STATE, own }),
|
|
45
|
+
);
|
|
46
|
+
</script>
|
|
47
|
+
|
|
48
|
+
{#snippet content()}{@render children?.({ state: STATE })}{/snippet}
|
|
49
|
+
|
|
50
|
+
{#if render}
|
|
51
|
+
{@render render({ props: attrs as never, state: STATE, children: content })}
|
|
52
|
+
{:else}
|
|
53
|
+
<div {...attrs}>{@render content()}</div>
|
|
54
|
+
{/if}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Snippet } from "svelte";
|
|
2
|
+
import type { DivPrimitiveProps } from "../utils/render.js";
|
|
3
|
+
/** The state of `Flow.Controls` (none: its buttons have their own). */
|
|
4
|
+
export type ControlsState = Record<never, never>;
|
|
5
|
+
export interface ControlsProps extends Omit<DivPrimitiveProps<ControlsState>, "children"> {
|
|
6
|
+
children?: Snippet<[{
|
|
7
|
+
state: ControlsState;
|
|
8
|
+
}]> | undefined;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* A group of the viewport's buttons (`data-flow-part="controls"`): `Flow.ZoomIn`, `Flow.ZoomOut`,
|
|
12
|
+
* `Flow.FitView`, `Flow.ToggleInteractive`, or your own. Inside `Flow.Root`, outside
|
|
13
|
+
* `Flow.Viewport`; presses and the wheel over it are left to it. Place it with your style.
|
|
14
|
+
*/
|
|
15
|
+
declare const Controls: import("svelte").Component<ControlsProps, {}, "ref">;
|
|
16
|
+
type Controls = ReturnType<typeof Controls>;
|
|
17
|
+
export default Controls;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
<script module lang="ts">
|
|
2
|
+
import type { EdgePath } from "@fragiola/flow";
|
|
3
|
+
import type { Snippet } from "svelte";
|
|
4
|
+
import type { DivPrimitiveProps } from "../utils/render.js";
|
|
5
|
+
|
|
6
|
+
export interface EdgeLabelState {
|
|
7
|
+
readonly edgeId: string;
|
|
8
|
+
/** the edge's path, label point and ends */
|
|
9
|
+
readonly path: EdgePath;
|
|
10
|
+
/** `data-selected` (`selection()`) */
|
|
11
|
+
readonly selected: boolean;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface EdgeLabelProps
|
|
15
|
+
extends Omit<DivPrimitiveProps<EdgeLabelState>, "children"> {
|
|
16
|
+
/** the edge; default the enclosing `Flow.Edge`'s */
|
|
17
|
+
edgeId?: string | undefined;
|
|
18
|
+
children?: Snippet<[{ state: EdgeLabelState }]> | undefined;
|
|
19
|
+
}
|
|
20
|
+
</script>
|
|
21
|
+
|
|
22
|
+
<!--
|
|
23
|
+
@component
|
|
24
|
+
An edge's label (`data-flow-part="edge-label"`): HTML, centred on the path's label point in
|
|
25
|
+
flow coordinates, in the HTML layer of `Flow.Edges` (a portal: SVG holds no HTML). It renders
|
|
26
|
+
only its children; a press on it selects its edge.
|
|
27
|
+
-->
|
|
28
|
+
<script lang="ts">
|
|
29
|
+
import {
|
|
30
|
+
useEdgeId,
|
|
31
|
+
useEdgeLabelLayer,
|
|
32
|
+
useFlowContext,
|
|
33
|
+
} from "../context.js";
|
|
34
|
+
import { flowValue, sameValue } from "../runes/internal.svelte.js";
|
|
35
|
+
import {
|
|
36
|
+
edgePathValue,
|
|
37
|
+
staticAttributes,
|
|
38
|
+
} from "../runes/use-edge.svelte.js";
|
|
39
|
+
import Portal from "../utils/portal.svelte";
|
|
40
|
+
import {
|
|
41
|
+
elementProps,
|
|
42
|
+
px,
|
|
43
|
+
refProps,
|
|
44
|
+
type RenderedProps,
|
|
45
|
+
} from "../utils/render.js";
|
|
46
|
+
|
|
47
|
+
let {
|
|
48
|
+
edgeId: edgeIdProp,
|
|
49
|
+
children,
|
|
50
|
+
render,
|
|
51
|
+
class: className,
|
|
52
|
+
style,
|
|
53
|
+
ref = $bindable(),
|
|
54
|
+
...rest
|
|
55
|
+
}: EdgeLabelProps = $props();
|
|
56
|
+
|
|
57
|
+
const edgeIdOf = useEdgeId("EdgeLabel", () => edgeIdProp);
|
|
58
|
+
const layer = useEdgeLabelLayer();
|
|
59
|
+
const context = useFlowContext("EdgeLabel");
|
|
60
|
+
const path = edgePathValue(context, edgeIdOf);
|
|
61
|
+
// the engine's attributes, or before it (the server, the first render) the document's
|
|
62
|
+
const attributes = flowValue(context, () => {
|
|
63
|
+
const edgeId = edgeIdOf();
|
|
64
|
+
const { engine, model } = context;
|
|
65
|
+
return engine
|
|
66
|
+
? engine.adapter.attributes("edge-label", { edgeId })
|
|
67
|
+
: staticAttributes(
|
|
68
|
+
"edge-label",
|
|
69
|
+
edgeId,
|
|
70
|
+
model.get("edge-by", { id: edgeId }),
|
|
71
|
+
);
|
|
72
|
+
},
|
|
73
|
+
sameValue,
|
|
74
|
+
{ entity: () => ({ kind: "edge", id: edgeIdOf() }) },
|
|
75
|
+
);
|
|
76
|
+
const refs = refProps((element) => {
|
|
77
|
+
ref = element as HTMLDivElement | null;
|
|
78
|
+
});
|
|
79
|
+
const partState = $derived.by((): EdgeLabelState | undefined => {
|
|
80
|
+
const current = path.current;
|
|
81
|
+
const own = attributes.current;
|
|
82
|
+
return current && own
|
|
83
|
+
? {
|
|
84
|
+
edgeId: edgeIdOf(),
|
|
85
|
+
path: current,
|
|
86
|
+
selected: own["data-selected"] !== undefined,
|
|
87
|
+
}
|
|
88
|
+
: undefined;
|
|
89
|
+
});
|
|
90
|
+
const attrs: RenderedProps<HTMLDivElement> = $derived.by(() => {
|
|
91
|
+
if (!partState) return {} as RenderedProps<HTMLDivElement>;
|
|
92
|
+
const { x, y } = partState.path.label;
|
|
93
|
+
return elementProps({
|
|
94
|
+
rest,
|
|
95
|
+
className,
|
|
96
|
+
style,
|
|
97
|
+
state: partState,
|
|
98
|
+
own: { ...attributes.current, ...refs },
|
|
99
|
+
structural: {
|
|
100
|
+
position: "absolute",
|
|
101
|
+
top: "0",
|
|
102
|
+
left: "0",
|
|
103
|
+
transform: `translate(${px(x)}, ${px(y)}) translate(-50%, -50%)`,
|
|
104
|
+
"pointer-events": "all",
|
|
105
|
+
},
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
</script>
|
|
109
|
+
|
|
110
|
+
{#snippet content()}
|
|
111
|
+
{#if partState}{@render children?.({ state: partState })}{/if}
|
|
112
|
+
{/snippet}
|
|
113
|
+
|
|
114
|
+
{#snippet label()}
|
|
115
|
+
{#if partState}
|
|
116
|
+
{#if render}
|
|
117
|
+
{@render render({ props: attrs as never, state: partState, children: content })}
|
|
118
|
+
{:else}
|
|
119
|
+
<div {...attrs}>{@render content()}</div>
|
|
120
|
+
{/if}
|
|
121
|
+
{/if}
|
|
122
|
+
{/snippet}
|
|
123
|
+
|
|
124
|
+
{#if partState}
|
|
125
|
+
<Portal target={layer?.elementOf(edgeIdOf())}>{@render label()}</Portal>
|
|
126
|
+
{/if}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { EdgePath } from "@fragiola/flow";
|
|
2
|
+
import type { Snippet } from "svelte";
|
|
3
|
+
import type { DivPrimitiveProps } from "../utils/render.js";
|
|
4
|
+
export interface EdgeLabelState {
|
|
5
|
+
readonly edgeId: string;
|
|
6
|
+
/** the edge's path, label point and ends */
|
|
7
|
+
readonly path: EdgePath;
|
|
8
|
+
/** `data-selected` (`selection()`) */
|
|
9
|
+
readonly selected: boolean;
|
|
10
|
+
}
|
|
11
|
+
export interface EdgeLabelProps extends Omit<DivPrimitiveProps<EdgeLabelState>, "children"> {
|
|
12
|
+
/** the edge; default the enclosing `Flow.Edge`'s */
|
|
13
|
+
edgeId?: string | undefined;
|
|
14
|
+
children?: Snippet<[{
|
|
15
|
+
state: EdgeLabelState;
|
|
16
|
+
}]> | undefined;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* An edge's label (`data-flow-part="edge-label"`): HTML, centred on the path's label point in
|
|
20
|
+
* flow coordinates, in the HTML layer of `Flow.Edges` (a portal: SVG holds no HTML). It renders
|
|
21
|
+
* only its children; a press on it selects its edge.
|
|
22
|
+
*/
|
|
23
|
+
declare const EdgeLabel: import("svelte").Component<EdgeLabelProps, {}, "ref">;
|
|
24
|
+
type EdgeLabel = ReturnType<typeof EdgeLabel>;
|
|
25
|
+
export default EdgeLabel;
|