@fragiola/flow-svelte 0.0.0-stage → 0.1.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/CHANGELOG.md +17 -0
- package/LICENSE +21 -0
- package/README.md +20 -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 +106 -3
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { MinimapView, XY } from "@fragiola/flow";
|
|
2
|
+
import type { Snippet } from "svelte";
|
|
3
|
+
import type { SvgPrimitiveProps } from "../utils/render.js";
|
|
4
|
+
export interface MiniMapState {
|
|
5
|
+
/** what it draws: the nodes, the view and the mask, in flow coordinates */
|
|
6
|
+
readonly view: MinimapView;
|
|
7
|
+
}
|
|
8
|
+
export interface MiniMapProps extends Omit<SvgPrimitiveProps<MiniMapState, SVGSVGElement>, "children" | "width" | "height" | "onclick"> {
|
|
9
|
+
/** its width, in pixels; default 200 */
|
|
10
|
+
width?: number | undefined;
|
|
11
|
+
/** its height, in pixels; default 150 */
|
|
12
|
+
height?: number | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* a drag on it moves the view the other way (as grabbing the flow), and a press does not
|
|
15
|
+
* centre the view; default `minimap()`'s `inversePan`
|
|
16
|
+
*/
|
|
17
|
+
inversePan?: boolean | undefined;
|
|
18
|
+
/** how fast its wheel zooms: 10 is the flow's own wheel, 20 twice as fast; default `minimap()`'s `zoomStep` */
|
|
19
|
+
zoomStep?: number | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* a tap on it (`minimap-click`), with the flow point under the pointer on the minimap: center
|
|
22
|
+
* the view there, add a node there
|
|
23
|
+
*/
|
|
24
|
+
onclick?: ((event: MouseEvent, point: XY) => void) | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* what it draws, in flow coordinates (`{#snippet children(view)}`); default a
|
|
27
|
+
* `MiniMapNode` per node, then the `MiniMapMask`
|
|
28
|
+
*/
|
|
29
|
+
children?: Snippet<[MinimapView]> | undefined;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* A small map of the flow (`data-flow-part="minimap"`, `minimap()`): an SVG of `width` × `height`
|
|
33
|
+
* pixels showing every node and what the root shows. With `minimap()`'s options, a drag on it pans
|
|
34
|
+
* and its wheel zooms the flow. Inside `Flow.Root`, outside `Flow.Viewport`; place it with your
|
|
35
|
+
* style.
|
|
36
|
+
*/
|
|
37
|
+
declare const MiniMap: import("svelte").Component<MiniMapProps, {}, "ref">;
|
|
38
|
+
type MiniMap = ReturnType<typeof MiniMap>;
|
|
39
|
+
export default MiniMap;
|
package/dist/parts.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export { default as Background } from "./components/background.svelte";
|
|
2
|
+
export { default as ConnectionLine } from "./components/connection-line.svelte";
|
|
3
|
+
export { default as Controls } from "./components/controls.svelte";
|
|
4
|
+
export { default as Edge } from "./components/edge.svelte";
|
|
5
|
+
export { default as EdgeLabel } from "./components/edge-label.svelte";
|
|
6
|
+
export { default as EdgePath } from "./components/edge-path.svelte";
|
|
7
|
+
export { default as EdgeToolbar } from "./components/edge-toolbar.svelte";
|
|
8
|
+
export { default as Edges } from "./components/edges.svelte";
|
|
9
|
+
export { default as FitView } from "./components/fit-view.svelte";
|
|
10
|
+
export { default as Handle } from "./components/handle.svelte";
|
|
11
|
+
export { default as Node } from "./components/node.svelte";
|
|
12
|
+
export { default as NodeToolbar } from "./components/node-toolbar.svelte";
|
|
13
|
+
export { default as Nodes } from "./components/nodes.svelte";
|
|
14
|
+
export { default as NodesSelection } from "./components/nodes-selection.svelte";
|
|
15
|
+
export { default as ReconnectAnchor } from "./components/reconnect-anchor.svelte";
|
|
16
|
+
export { default as Root } from "./components/root.svelte";
|
|
17
|
+
export { default as SelectionBox } from "./components/selection-box.svelte";
|
|
18
|
+
export { default as ToggleInteractive } from "./components/toggle-interactive.svelte";
|
|
19
|
+
export { default as Viewport } from "./components/viewport.svelte";
|
|
20
|
+
export { default as ZoomIn } from "./components/zoom-in.svelte";
|
|
21
|
+
export { default as ZoomOut } from "./components/zoom-out.svelte";
|
package/dist/parts.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// The `Flow` namespace: `import { Flow } from "@fragiola/flow-svelte"`, then `<Flow.Root>`,
|
|
2
|
+
// `<Flow.Node>`, … The features' primitives are on their entries (`MiniMap` on
|
|
3
|
+
// `@fragiola/flow-svelte/minimap`, `NodeResizer` on `/resize`), so this one never imports them.
|
|
4
|
+
export { default as Background } from "./components/background.svelte";
|
|
5
|
+
export { default as ConnectionLine } from "./components/connection-line.svelte";
|
|
6
|
+
export { default as Controls } from "./components/controls.svelte";
|
|
7
|
+
export { default as Edge } from "./components/edge.svelte";
|
|
8
|
+
export { default as EdgeLabel } from "./components/edge-label.svelte";
|
|
9
|
+
export { default as EdgePath } from "./components/edge-path.svelte";
|
|
10
|
+
export { default as EdgeToolbar } from "./components/edge-toolbar.svelte";
|
|
11
|
+
export { default as Edges } from "./components/edges.svelte";
|
|
12
|
+
export { default as FitView } from "./components/fit-view.svelte";
|
|
13
|
+
export { default as Handle } from "./components/handle.svelte";
|
|
14
|
+
export { default as Node } from "./components/node.svelte";
|
|
15
|
+
export { default as NodeToolbar } from "./components/node-toolbar.svelte";
|
|
16
|
+
export { default as Nodes } from "./components/nodes.svelte";
|
|
17
|
+
export { default as NodesSelection } from "./components/nodes-selection.svelte";
|
|
18
|
+
export { default as ReconnectAnchor } from "./components/reconnect-anchor.svelte";
|
|
19
|
+
export { default as Root } from "./components/root.svelte";
|
|
20
|
+
export { default as SelectionBox } from "./components/selection-box.svelte";
|
|
21
|
+
export { default as ToggleInteractive } from "./components/toggle-interactive.svelte";
|
|
22
|
+
export { default as Viewport } from "./components/viewport.svelte";
|
|
23
|
+
export { default as ZoomIn } from "./components/zoom-in.svelte";
|
|
24
|
+
export { default as ZoomOut } from "./components/zoom-out.svelte";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@fragiola/flow/reconnection";
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export * from "@fragiola/flow/resize";
|
|
2
|
+
export { default as NodeResizer, type NodeResizerProps, type NodeResizerState, } from "./node-resizer.svelte";
|
|
3
|
+
export { default as ResizeHandle, RESIZE_POSITIONS, type ResizeHandleProps, type ResizeHandleState, type ResizePosition, } from "./resize-handle.svelte";
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// The entry of @fragiola/flow-svelte/resize: the core's resize feature (`resize()`) and what
|
|
2
|
+
// draws it: `NodeResizer`, `ResizeHandle`. A flow that never imports it does not ship them.
|
|
3
|
+
export * from "@fragiola/flow/resize";
|
|
4
|
+
export { default as NodeResizer, } from "./node-resizer.svelte";
|
|
5
|
+
export { default as ResizeHandle, RESIZE_POSITIONS, } from "./resize-handle.svelte";
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
<script module lang="ts">
|
|
2
|
+
import type { ResizeDirection } from "@fragiola/flow/resize";
|
|
3
|
+
import type { Snippet } from "svelte";
|
|
4
|
+
import type { DivPrimitiveProps } from "../utils/render.js";
|
|
5
|
+
|
|
6
|
+
export interface NodeResizerState {
|
|
7
|
+
readonly nodeId: string;
|
|
8
|
+
/** its node is being resized: `data-resizing` */
|
|
9
|
+
readonly resizing: boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface NodeResizerProps
|
|
13
|
+
extends Omit<DivPrimitiveProps<NodeResizerState>, "children"> {
|
|
14
|
+
/** its node; default the enclosing `Flow.Node`'s */
|
|
15
|
+
nodeId?: string | undefined;
|
|
16
|
+
/** this node's limits, over `resize()`'s (in flow units) */
|
|
17
|
+
minWidth?: number | undefined;
|
|
18
|
+
minHeight?: number | undefined;
|
|
19
|
+
maxWidth?: number | undefined;
|
|
20
|
+
maxHeight?: number | undefined;
|
|
21
|
+
/** this node keeps its aspect ratio, over `resize()`'s */
|
|
22
|
+
keepAspectRatio?: boolean | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* the sides its handles move: `"horizontal"` only the width (and x), `"vertical"` only the
|
|
25
|
+
* height (and y); default both. A corner then moves its one dimension
|
|
26
|
+
*/
|
|
27
|
+
direction?: ResizeDirection | undefined;
|
|
28
|
+
/** its handles; default a `ResizeHandle` at each corner and side */
|
|
29
|
+
children?: Snippet<[{ state: NodeResizerState }]> | undefined;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const RESIZER_STYLE = {
|
|
33
|
+
position: "absolute",
|
|
34
|
+
inset: "0",
|
|
35
|
+
"pointer-events": "none",
|
|
36
|
+
};
|
|
37
|
+
</script>
|
|
38
|
+
|
|
39
|
+
<!--
|
|
40
|
+
@component
|
|
41
|
+
A node's resizer (`data-flow-part="resizer"`, `resize()`), inside `Flow.Node`: a box over the
|
|
42
|
+
node holding its `ResizeHandle`s; its limits are this node's own (`setPartOptions`). Render it
|
|
43
|
+
only when the node should be resizable (while it is selected, say).
|
|
44
|
+
-->
|
|
45
|
+
<script lang="ts">
|
|
46
|
+
import { useFlowContext, usePartNodeId } from "../context.js";
|
|
47
|
+
import { flowValue, sameValue } from "../runes/internal.svelte.js";
|
|
48
|
+
import {
|
|
49
|
+
elementProps,
|
|
50
|
+
refProps,
|
|
51
|
+
type RenderedProps,
|
|
52
|
+
} from "../utils/render.js";
|
|
53
|
+
import ResizeHandle, { RESIZE_POSITIONS } from "./resize-handle.svelte";
|
|
54
|
+
|
|
55
|
+
let {
|
|
56
|
+
nodeId: nodeIdProp,
|
|
57
|
+
minWidth,
|
|
58
|
+
minHeight,
|
|
59
|
+
maxWidth,
|
|
60
|
+
maxHeight,
|
|
61
|
+
keepAspectRatio,
|
|
62
|
+
direction,
|
|
63
|
+
children,
|
|
64
|
+
render,
|
|
65
|
+
class: className,
|
|
66
|
+
style,
|
|
67
|
+
ref = $bindable(),
|
|
68
|
+
...rest
|
|
69
|
+
}: NodeResizerProps = $props();
|
|
70
|
+
|
|
71
|
+
const nodeIdOf = usePartNodeId("NodeResizer", () => nodeIdProp);
|
|
72
|
+
const nodeId = $derived(nodeIdOf());
|
|
73
|
+
const context = useFlowContext("NodeResizer");
|
|
74
|
+
// this node's limits, on the engine while it is there
|
|
75
|
+
$effect(() => {
|
|
76
|
+
const engine = context.engine;
|
|
77
|
+
const id = nodeId;
|
|
78
|
+
const options = Object.fromEntries(
|
|
79
|
+
Object.entries({
|
|
80
|
+
minWidth,
|
|
81
|
+
minHeight,
|
|
82
|
+
maxWidth,
|
|
83
|
+
maxHeight,
|
|
84
|
+
keepAspectRatio,
|
|
85
|
+
direction,
|
|
86
|
+
}).filter(([, value]) => value !== undefined),
|
|
87
|
+
);
|
|
88
|
+
if (!engine) return;
|
|
89
|
+
engine.adapter.setPartOptions("resizer", id, options);
|
|
90
|
+
return () => engine.adapter.setPartOptions("resizer", id, null);
|
|
91
|
+
});
|
|
92
|
+
const attributes = flowValue(
|
|
93
|
+
context,
|
|
94
|
+
() =>
|
|
95
|
+
context.engine
|
|
96
|
+
? context.engine.adapter.attributes("resizer", { nodeId })
|
|
97
|
+
: { "data-flow-part": "resizer", "data-flow-id": nodeId },
|
|
98
|
+
sameValue,
|
|
99
|
+
{ scope: "entity" },
|
|
100
|
+
);
|
|
101
|
+
const refs = refProps((element) => {
|
|
102
|
+
ref = element as HTMLDivElement | null;
|
|
103
|
+
});
|
|
104
|
+
const partState = $derived<NodeResizerState>({
|
|
105
|
+
nodeId,
|
|
106
|
+
resizing: attributes.current["data-resizing"] !== undefined,
|
|
107
|
+
});
|
|
108
|
+
const attrs: RenderedProps<HTMLDivElement> = $derived(
|
|
109
|
+
elementProps({
|
|
110
|
+
rest,
|
|
111
|
+
className,
|
|
112
|
+
style,
|
|
113
|
+
state: partState,
|
|
114
|
+
own: { ...attributes.current, ...refs },
|
|
115
|
+
structural: RESIZER_STYLE,
|
|
116
|
+
}),
|
|
117
|
+
);
|
|
118
|
+
</script>
|
|
119
|
+
|
|
120
|
+
{#snippet content()}
|
|
121
|
+
{#if children}
|
|
122
|
+
{@render children({ state: partState })}
|
|
123
|
+
{:else}
|
|
124
|
+
{#each RESIZE_POSITIONS as position (position)}
|
|
125
|
+
<ResizeHandle {position} nodeId={partState.nodeId} />
|
|
126
|
+
{/each}
|
|
127
|
+
{/if}
|
|
128
|
+
{/snippet}
|
|
129
|
+
|
|
130
|
+
{#if render}
|
|
131
|
+
{@render render({ props: attrs as never, state: partState, children: content })}
|
|
132
|
+
{:else}
|
|
133
|
+
<div {...attrs}>{@render content()}</div>
|
|
134
|
+
{/if}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { ResizeDirection } from "@fragiola/flow/resize";
|
|
2
|
+
import type { Snippet } from "svelte";
|
|
3
|
+
import type { DivPrimitiveProps } from "../utils/render.js";
|
|
4
|
+
export interface NodeResizerState {
|
|
5
|
+
readonly nodeId: string;
|
|
6
|
+
/** its node is being resized: `data-resizing` */
|
|
7
|
+
readonly resizing: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface NodeResizerProps extends Omit<DivPrimitiveProps<NodeResizerState>, "children"> {
|
|
10
|
+
/** its node; default the enclosing `Flow.Node`'s */
|
|
11
|
+
nodeId?: string | undefined;
|
|
12
|
+
/** this node's limits, over `resize()`'s (in flow units) */
|
|
13
|
+
minWidth?: number | undefined;
|
|
14
|
+
minHeight?: number | undefined;
|
|
15
|
+
maxWidth?: number | undefined;
|
|
16
|
+
maxHeight?: number | undefined;
|
|
17
|
+
/** this node keeps its aspect ratio, over `resize()`'s */
|
|
18
|
+
keepAspectRatio?: boolean | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* the sides its handles move: `"horizontal"` only the width (and x), `"vertical"` only the
|
|
21
|
+
* height (and y); default both. A corner then moves its one dimension
|
|
22
|
+
*/
|
|
23
|
+
direction?: ResizeDirection | undefined;
|
|
24
|
+
/** its handles; default a `ResizeHandle` at each corner and side */
|
|
25
|
+
children?: Snippet<[{
|
|
26
|
+
state: NodeResizerState;
|
|
27
|
+
}]> | undefined;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* A node's resizer (`data-flow-part="resizer"`, `resize()`), inside `Flow.Node`: a box over the
|
|
31
|
+
* node holding its `ResizeHandle`s; its limits are this node's own (`setPartOptions`). Render it
|
|
32
|
+
* only when the node should be resizable (while it is selected, say).
|
|
33
|
+
*/
|
|
34
|
+
declare const NodeResizer: import("svelte").Component<NodeResizerProps, {}, "ref">;
|
|
35
|
+
type NodeResizer = ReturnType<typeof NodeResizer>;
|
|
36
|
+
export default NodeResizer;
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
<script module lang="ts">
|
|
2
|
+
import type {
|
|
3
|
+
ResizeHandleDirection,
|
|
4
|
+
ResizeHandleVariant,
|
|
5
|
+
} from "@fragiola/flow";
|
|
6
|
+
import type { Snippet } from "svelte";
|
|
7
|
+
import type { DivPrimitiveProps } from "../utils/render.js";
|
|
8
|
+
|
|
9
|
+
/** A corner or a side of a node a `ResizeHandle` moves. */
|
|
10
|
+
export type ResizePosition =
|
|
11
|
+
| "top-left"
|
|
12
|
+
| "top"
|
|
13
|
+
| "top-right"
|
|
14
|
+
| "right"
|
|
15
|
+
| "bottom-right"
|
|
16
|
+
| "bottom"
|
|
17
|
+
| "bottom-left"
|
|
18
|
+
| "left";
|
|
19
|
+
|
|
20
|
+
/** Every position, corners then sides. */
|
|
21
|
+
export const RESIZE_POSITIONS: readonly ResizePosition[] = Object.freeze([
|
|
22
|
+
"top-left",
|
|
23
|
+
"top-right",
|
|
24
|
+
"bottom-right",
|
|
25
|
+
"bottom-left",
|
|
26
|
+
"top",
|
|
27
|
+
"right",
|
|
28
|
+
"bottom",
|
|
29
|
+
"left",
|
|
30
|
+
]);
|
|
31
|
+
|
|
32
|
+
export interface ResizeHandleState {
|
|
33
|
+
readonly nodeId: string;
|
|
34
|
+
readonly position: ResizePosition;
|
|
35
|
+
/** its own direction, over its resizer's (`data-direction`); none: the resizer's */
|
|
36
|
+
readonly direction: ResizeHandleDirection | undefined;
|
|
37
|
+
/** how it is drawn (`data-variant`): a corner is always a `handle` */
|
|
38
|
+
readonly variant: ResizeHandleVariant;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface ResizeHandleProps
|
|
42
|
+
extends Omit<DivPrimitiveProps<ResizeHandleState>, "children"> {
|
|
43
|
+
/** the corner or side it moves */
|
|
44
|
+
position: ResizePosition;
|
|
45
|
+
/** its node; default the enclosing `Flow.Node`'s */
|
|
46
|
+
nodeId?: string | undefined;
|
|
47
|
+
/**
|
|
48
|
+
* the sides it moves, over its resizer's `direction` (`data-direction`): `"horizontal"`
|
|
49
|
+
* only the width (and x), `"vertical"` only the height (and y); default the resizer's
|
|
50
|
+
*/
|
|
51
|
+
direction?: ResizeHandleDirection | undefined;
|
|
52
|
+
/**
|
|
53
|
+
* how it is drawn (`data-variant`, for your styles): `"handle"` (default) or `"line"`, a
|
|
54
|
+
* side's whole length; a corner's `"line"` is ignored
|
|
55
|
+
*/
|
|
56
|
+
variant?: ResizeHandleVariant | undefined;
|
|
57
|
+
children?: Snippet<[{ state: ResizeHandleState }]> | undefined;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Where a handle sits: a corner's centre on the corner, a side's along the side. A corner is
|
|
62
|
+
* above the two sides it joins (`z-index`), so a press on it resizes both dimensions, whatever
|
|
63
|
+
* the order of the handles.
|
|
64
|
+
*/
|
|
65
|
+
const PLACE: Record<ResizePosition, Record<string, string>> = {
|
|
66
|
+
"top-left": {
|
|
67
|
+
top: "0",
|
|
68
|
+
left: "0",
|
|
69
|
+
transform: "translate(-50%, -50%)",
|
|
70
|
+
"z-index": "1",
|
|
71
|
+
},
|
|
72
|
+
"top-right": {
|
|
73
|
+
top: "0",
|
|
74
|
+
left: "100%",
|
|
75
|
+
transform: "translate(-50%, -50%)",
|
|
76
|
+
"z-index": "1",
|
|
77
|
+
},
|
|
78
|
+
"bottom-right": {
|
|
79
|
+
top: "100%",
|
|
80
|
+
left: "100%",
|
|
81
|
+
transform: "translate(-50%, -50%)",
|
|
82
|
+
"z-index": "1",
|
|
83
|
+
},
|
|
84
|
+
"bottom-left": {
|
|
85
|
+
top: "100%",
|
|
86
|
+
left: "0",
|
|
87
|
+
transform: "translate(-50%, -50%)",
|
|
88
|
+
"z-index": "1",
|
|
89
|
+
},
|
|
90
|
+
top: { top: "0", left: "0", width: "100%", transform: "translateY(-50%)" },
|
|
91
|
+
bottom: {
|
|
92
|
+
top: "100%",
|
|
93
|
+
left: "0",
|
|
94
|
+
width: "100%",
|
|
95
|
+
transform: "translateY(-50%)",
|
|
96
|
+
},
|
|
97
|
+
left: {
|
|
98
|
+
top: "0",
|
|
99
|
+
left: "0",
|
|
100
|
+
height: "100%",
|
|
101
|
+
transform: "translateX(-50%)",
|
|
102
|
+
},
|
|
103
|
+
right: {
|
|
104
|
+
top: "0",
|
|
105
|
+
left: "100%",
|
|
106
|
+
height: "100%",
|
|
107
|
+
transform: "translateX(-50%)",
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
</script>
|
|
111
|
+
|
|
112
|
+
<!--
|
|
113
|
+
@component
|
|
114
|
+
A grab area of a `NodeResizer` (`data-flow-part="resize-handle"`, `data-position`): a press on
|
|
115
|
+
it resizes its node from that corner or side (`resize()`); with `keyboard()` too it takes focus
|
|
116
|
+
and the arrows move that corner or side. Placed on its corner (centred) or along its side; give
|
|
117
|
+
it its size (a side's thickness) and look. Its `direction` overrides its resizer's;
|
|
118
|
+
`variant="line"` marks a side's handle as a line for your styles.
|
|
119
|
+
-->
|
|
120
|
+
<script lang="ts">
|
|
121
|
+
import { resizeHandleAttributes } from "@fragiola/flow";
|
|
122
|
+
import { useFlowContext, usePartNodeId } from "../context.js";
|
|
123
|
+
import { flowValue, sameValue } from "../runes/internal.svelte.js";
|
|
124
|
+
import {
|
|
125
|
+
elementProps,
|
|
126
|
+
refProps,
|
|
127
|
+
type RenderedProps,
|
|
128
|
+
} from "../utils/render.js";
|
|
129
|
+
|
|
130
|
+
let {
|
|
131
|
+
position,
|
|
132
|
+
nodeId: nodeIdProp,
|
|
133
|
+
direction,
|
|
134
|
+
variant,
|
|
135
|
+
children,
|
|
136
|
+
render,
|
|
137
|
+
class: className,
|
|
138
|
+
style,
|
|
139
|
+
ref = $bindable(),
|
|
140
|
+
...rest
|
|
141
|
+
}: ResizeHandleProps = $props();
|
|
142
|
+
|
|
143
|
+
const nodeIdOf = usePartNodeId("ResizeHandle", () => nodeIdProp);
|
|
144
|
+
const context = useFlowContext("ResizeHandle");
|
|
145
|
+
// the engine's record: `data-position`, `data-variant`, `data-direction`, and `tabindex`
|
|
146
|
+
// with `keyboard()` (arrows resize)
|
|
147
|
+
const attributes = flowValue(context, () =>
|
|
148
|
+
context.engine
|
|
149
|
+
? context.engine.adapter.attributes("resize-handle", {
|
|
150
|
+
nodeId: nodeIdOf(),
|
|
151
|
+
position,
|
|
152
|
+
direction,
|
|
153
|
+
variant,
|
|
154
|
+
})
|
|
155
|
+
: resizeHandleAttributes(position, { direction, variant }),
|
|
156
|
+
sameValue,
|
|
157
|
+
{ scope: "entity" },
|
|
158
|
+
);
|
|
159
|
+
const refs = refProps((element) => {
|
|
160
|
+
ref = element as HTMLDivElement | null;
|
|
161
|
+
});
|
|
162
|
+
const partState = $derived<ResizeHandleState>({
|
|
163
|
+
nodeId: nodeIdOf(),
|
|
164
|
+
position,
|
|
165
|
+
direction: attributes.current["data-direction"] as
|
|
166
|
+
| ResizeHandleDirection
|
|
167
|
+
| undefined,
|
|
168
|
+
variant: attributes.current["data-variant"] as ResizeHandleVariant,
|
|
169
|
+
});
|
|
170
|
+
const attrs: RenderedProps<HTMLDivElement> = $derived(
|
|
171
|
+
elementProps({
|
|
172
|
+
rest,
|
|
173
|
+
className,
|
|
174
|
+
style,
|
|
175
|
+
state: partState,
|
|
176
|
+
own: { ...attributes.current, ...refs },
|
|
177
|
+
structural: {
|
|
178
|
+
position: "absolute",
|
|
179
|
+
"pointer-events": "auto",
|
|
180
|
+
...PLACE[position],
|
|
181
|
+
},
|
|
182
|
+
}),
|
|
183
|
+
);
|
|
184
|
+
</script>
|
|
185
|
+
|
|
186
|
+
{#snippet content()}{@render children?.({ state: partState })}{/snippet}
|
|
187
|
+
|
|
188
|
+
{#if render}
|
|
189
|
+
{@render render({ props: attrs as never, state: partState, children: content })}
|
|
190
|
+
{:else}
|
|
191
|
+
<div {...attrs}>{@render content()}</div>
|
|
192
|
+
{/if}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { ResizeHandleDirection, ResizeHandleVariant } from "@fragiola/flow";
|
|
2
|
+
import type { Snippet } from "svelte";
|
|
3
|
+
import type { DivPrimitiveProps } from "../utils/render.js";
|
|
4
|
+
/** A corner or a side of a node a `ResizeHandle` moves. */
|
|
5
|
+
export type ResizePosition = "top-left" | "top" | "top-right" | "right" | "bottom-right" | "bottom" | "bottom-left" | "left";
|
|
6
|
+
/** Every position, corners then sides. */
|
|
7
|
+
export declare const RESIZE_POSITIONS: readonly ResizePosition[];
|
|
8
|
+
export interface ResizeHandleState {
|
|
9
|
+
readonly nodeId: string;
|
|
10
|
+
readonly position: ResizePosition;
|
|
11
|
+
/** its own direction, over its resizer's (`data-direction`); none: the resizer's */
|
|
12
|
+
readonly direction: ResizeHandleDirection | undefined;
|
|
13
|
+
/** how it is drawn (`data-variant`): a corner is always a `handle` */
|
|
14
|
+
readonly variant: ResizeHandleVariant;
|
|
15
|
+
}
|
|
16
|
+
export interface ResizeHandleProps extends Omit<DivPrimitiveProps<ResizeHandleState>, "children"> {
|
|
17
|
+
/** the corner or side it moves */
|
|
18
|
+
position: ResizePosition;
|
|
19
|
+
/** its node; default the enclosing `Flow.Node`'s */
|
|
20
|
+
nodeId?: string | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* the sides it moves, over its resizer's `direction` (`data-direction`): `"horizontal"`
|
|
23
|
+
* only the width (and x), `"vertical"` only the height (and y); default the resizer's
|
|
24
|
+
*/
|
|
25
|
+
direction?: ResizeHandleDirection | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* how it is drawn (`data-variant`, for your styles): `"handle"` (default) or `"line"`, a
|
|
28
|
+
* side's whole length; a corner's `"line"` is ignored
|
|
29
|
+
*/
|
|
30
|
+
variant?: ResizeHandleVariant | undefined;
|
|
31
|
+
children?: Snippet<[{
|
|
32
|
+
state: ResizeHandleState;
|
|
33
|
+
}]> | undefined;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* A grab area of a `NodeResizer` (`data-flow-part="resize-handle"`, `data-position`): a press on
|
|
37
|
+
* it resizes its node from that corner or side (`resize()`); with `keyboard()` too it takes focus
|
|
38
|
+
* and the arrows move that corner or side. Placed on its corner (centred) or along its side; give
|
|
39
|
+
* it its size (a side's thickness) and look. Its `direction` overrides its resizer's;
|
|
40
|
+
* `variant="line"` marks a side's handle as a line for your styles.
|
|
41
|
+
*/
|
|
42
|
+
declare const ResizeHandle: import("svelte").Component<ResizeHandleProps, {}, "ref">;
|
|
43
|
+
type ResizeHandle = ReturnType<typeof ResizeHandle>;
|
|
44
|
+
export default ResizeHandle;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { AnyTypes, FlowEngine, FlowFeatures, FlowModel, FlowTypes } from "@fragiola/flow";
|
|
2
|
+
/** What a flow ref gives once its `Flow.Root` is mounted: the root's model and engine. */
|
|
3
|
+
export interface FlowRefValue<T extends FlowTypes = AnyTypes, F extends FlowFeatures = readonly []> {
|
|
4
|
+
readonly model: FlowModel<T, F>;
|
|
5
|
+
readonly engine: FlowEngine<T, F>;
|
|
6
|
+
}
|
|
7
|
+
declare const flowRefBrand: unique symbol;
|
|
8
|
+
/**
|
|
9
|
+
* Access to a `Flow.Root` from outside it (a toolbar, a menu, a test): pass it as the root's
|
|
10
|
+
* `flowRef`; `current` is the root's model and engine while it is mounted, `null` otherwise.
|
|
11
|
+
* `current` is reactive: a template that reads it updates when the root mounts or unmounts.
|
|
12
|
+
*/
|
|
13
|
+
export interface FlowRef<T extends FlowTypes = AnyTypes, F extends FlowFeatures = readonly []> {
|
|
14
|
+
/** the root's model and engine while it is mounted, `null` otherwise */
|
|
15
|
+
readonly current: FlowRefValue<T, F> | null;
|
|
16
|
+
/** only `createFlowRef` and `useFlowRef` make a flow ref */
|
|
17
|
+
readonly [flowRefBrand]: true;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Creates a flow ref anywhere (a module, a test, a component's script, where `useFlowRef` says the
|
|
21
|
+
* same).
|
|
22
|
+
*
|
|
23
|
+
* ```ts
|
|
24
|
+
* const flow = createFlowRef<Types, typeof features>();
|
|
25
|
+
* // <Flow.Root flowRef={flow} {features} defaultNodes={nodes}>…</Flow.Root>
|
|
26
|
+
* flow.current?.engine.run("fit-view");
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export declare function createFlowRef<T extends FlowTypes = AnyTypes, F extends FlowFeatures = readonly []>(): FlowRef<T, F>;
|
|
30
|
+
/** @internal what `Flow.Root` calls: attaches (or, with `null`, detaches) its model and engine */
|
|
31
|
+
export declare function setFlowRef(flow: FlowRef<FlowTypes, FlowFeatures>, next: FlowRefValue<FlowTypes, FlowFeatures> | null): void;
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/** the setter behind each flow ref, which only `Flow.Root` calls */
|
|
2
|
+
const setters = new WeakMap();
|
|
3
|
+
/**
|
|
4
|
+
* Creates a flow ref anywhere (a module, a test, a component's script, where `useFlowRef` says the
|
|
5
|
+
* same).
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* const flow = createFlowRef<Types, typeof features>();
|
|
9
|
+
* // <Flow.Root flowRef={flow} {features} defaultNodes={nodes}>…</Flow.Root>
|
|
10
|
+
* flow.current?.engine.run("fit-view");
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export function createFlowRef() {
|
|
14
|
+
let value = $state.raw(null);
|
|
15
|
+
const flow = Object.freeze({
|
|
16
|
+
get current() {
|
|
17
|
+
return value;
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
setters.set(flow, (next) => {
|
|
21
|
+
value = next;
|
|
22
|
+
});
|
|
23
|
+
return flow;
|
|
24
|
+
}
|
|
25
|
+
/** @internal what `Flow.Root` calls: attaches (or, with `null`, detaches) its model and engine */
|
|
26
|
+
export function setFlowRef(flow, next) {
|
|
27
|
+
const set = setters.get(flow);
|
|
28
|
+
if (!set) {
|
|
29
|
+
throw new TypeError("Flow.Root: `flowRef` takes a flow ref from useFlowRef or createFlowRef");
|
|
30
|
+
}
|
|
31
|
+
set(next);
|
|
32
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { FlowContextValue } from "../context.js";
|
|
2
|
+
import type { FlowEntity, FlowValueScope } from "../utils/flow-store.svelte.js";
|
|
3
|
+
/** @internal two values the same for re-rendering: records compared by their entries */
|
|
4
|
+
export declare function sameValue<S>(a: S, b: S): boolean;
|
|
5
|
+
/** A value that follows the flow: read it through `current`. */
|
|
6
|
+
export interface FlowValue<S> {
|
|
7
|
+
readonly current: S;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* @internal what a reader depends on (`flowValue`'s last argument): a scope (`view` by default),
|
|
11
|
+
* and for an `entity` reader of one node or edge, which one (its measurements are told to it alone)
|
|
12
|
+
*/
|
|
13
|
+
export interface FlowValueOptions {
|
|
14
|
+
readonly scope?: FlowValueScope;
|
|
15
|
+
/** the node or the edge it shows (a getter: another id is followed) */
|
|
16
|
+
readonly entity?: () => FlowEntity;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* @internal a value read from the model and the engine (the React adapter's `useFlowValue`), as a
|
|
20
|
+
* `$derived` that notifies its readers only when it changes (`isEqual`; records by their entries
|
|
21
|
+
* by default). It is read again when the root's store tells its scope (`view`: every commit and
|
|
22
|
+
* view change; `entity`: not a viewport-only one, and a measurement only when it changed its node
|
|
23
|
+
* or edge), when the engine is created, and when a reactive value the reader uses changes (a
|
|
24
|
+
* prop); a value equal to the last one keeps the last object, so nothing re-renders. Called while
|
|
25
|
+
* a component initializes (an `entity` reader keeps its record in the store while mounted).
|
|
26
|
+
*/
|
|
27
|
+
export declare function flowValue<S>(context: FlowContextValue, read: () => S, isEqual?: (a: S, b: S) => boolean, options?: FlowValueOptions): FlowValue<S>;
|
|
28
|
+
/** A value, or a getter of it: what a rune takes to follow a prop (`() => node`). */
|
|
29
|
+
export type MaybeGetter<V> = V | (() => V);
|
|
30
|
+
/** @internal the value behind a `MaybeGetter` */
|
|
31
|
+
export declare function read<V>(value: MaybeGetter<V>): V;
|