@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,106 @@
|
|
|
1
|
+
import { type AnyTypes, type CreateId, type DefaultEdgeOptions, ENGINE_EVENT_CALLBACKS, type FitViewPayload, type FlowEdge, type FlowEdgeInput, type FlowEngineEventOf, type FlowEngineOptions, type FlowFeatures, type FlowModel, type FlowNode, type FlowNodeInput, type FlowTypes, type Viewport } from "@fragiola/flow";
|
|
2
|
+
import type { Snippet } from "svelte";
|
|
3
|
+
import type { FlowRef } from "../runes/create-flow-ref.svelte.js";
|
|
4
|
+
import type { DivPrimitiveProps } from "../utils/render.js";
|
|
5
|
+
export interface RootState {
|
|
6
|
+
/** the gestures and keys may change the flow (`set-interactive`, `data-interactive`) */
|
|
7
|
+
interactive: boolean;
|
|
8
|
+
/** the viewport is being panned (`data-panning`) */
|
|
9
|
+
panning: boolean;
|
|
10
|
+
/** nodes are being dragged (`drag()`, `data-dragging`) */
|
|
11
|
+
dragging: boolean;
|
|
12
|
+
/** a connection is being drawn (`connection()`, `data-connecting`) */
|
|
13
|
+
connecting: boolean;
|
|
14
|
+
/** a box selection is being drawn (`selection()`, `data-selecting`) */
|
|
15
|
+
selecting: boolean;
|
|
16
|
+
}
|
|
17
|
+
/** The engine's options a root takes as props: each one that changes applies at once. */
|
|
18
|
+
export type RootEngineProps = Pick<FlowEngineOptions, "minZoom" | "maxZoom" | "translateExtent" | "panOnDrag" | "panOnScroll" | "zoomOnScroll" | "zoomOnPinch" | "zoomOnDoubleClick" | "zoomStep" | "interactive" | "onlyRenderVisible" | "pathOptions" | "autoPan" | "panActivationKey" | "panOnScrollMode" | "panOnScrollSpeed" | "zoomActivationKey" | "easing" | "nodeOrigin" | "nodeExtent" | "elevateNodesOnSelect" | "elevateEdgesOnSelect" | "zIndexMode" | "paneClickDistance" | "nodeClickDistance" | "preventScrolling" | "nodesFocusable" | "edgesFocusable">;
|
|
19
|
+
type Callbacks = typeof ENGINE_EVENT_CALLBACKS;
|
|
20
|
+
/**
|
|
21
|
+
* The root's event callbacks, one per engine event (`ENGINE_EVENT_CALLBACKS`), lowercase as
|
|
22
|
+
* Svelte's event props: `onnodeclick`, `onmovestart`, `onconnectcancel`, … each called with
|
|
23
|
+
* the event.
|
|
24
|
+
*/
|
|
25
|
+
export type RootEventProps = {
|
|
26
|
+
[K in keyof Callbacks as `on${Lowercase<Callbacks[K]>}`]?: ((event: FlowEngineEventOf<K>) => void) | undefined;
|
|
27
|
+
};
|
|
28
|
+
export interface RootProps<T extends FlowTypes = AnyTypes, F extends FlowFeatures = readonly []> extends Omit<DivPrimitiveProps<RootState>, "children">, RootEngineProps, RootEventProps {
|
|
29
|
+
/**
|
|
30
|
+
* the flow model. Its middleware (`model.use`) sees every command the flow runs, and its
|
|
31
|
+
* listeners (`model.subscribe`) every change. Give it, or let the root create one from
|
|
32
|
+
* `nodes` / `defaultNodes` and `edges` / `defaultEdges`. Another model gets another engine
|
|
33
|
+
*/
|
|
34
|
+
model?: FlowModel<T, F> | undefined;
|
|
35
|
+
/** the nodes of the model the root creates (read once, at mount) */
|
|
36
|
+
defaultNodes?: readonly FlowNodeInput<T>[] | undefined;
|
|
37
|
+
/** the edges of the model the root creates (read once, at mount) */
|
|
38
|
+
defaultEdges?: readonly FlowEdgeInput<T>[] | undefined;
|
|
39
|
+
/**
|
|
40
|
+
* controlled nodes (`bind:nodes`, or `nodes` with `onnodeschange`): a new list brings the
|
|
41
|
+
* model to it with the commands a user would run (`model.get("commands-to")`, one
|
|
42
|
+
* `batch`); every change of the model's nodes is written back and told to
|
|
43
|
+
* `onnodeschange`. Give every node its id
|
|
44
|
+
*/
|
|
45
|
+
nodes?: readonly FlowNode<T>[] | undefined;
|
|
46
|
+
/** called with the model's nodes after every command that changes them (a drag step too) */
|
|
47
|
+
onnodeschange?: ((nodes: readonly FlowNode<T>[]) => void) | undefined;
|
|
48
|
+
/** controlled edges (`bind:edges`, or `edges` with `onedgeschange`), as `nodes` */
|
|
49
|
+
edges?: readonly FlowEdge<T>[] | undefined;
|
|
50
|
+
/** called with the model's edges after every command that changes them */
|
|
51
|
+
onedgeschange?: ((edges: readonly FlowEdge<T>[]) => void) | undefined;
|
|
52
|
+
/**
|
|
53
|
+
* the opt-in features of the model the root creates (read once, at mount):
|
|
54
|
+
* `[selection(), drag(), connection()]`, each from its entry
|
|
55
|
+
* (`@fragiola/flow-svelte/drag`). A `model` has its own
|
|
56
|
+
*/
|
|
57
|
+
features?: F | undefined;
|
|
58
|
+
/** the id generator of the model the root creates (read once, at mount) */
|
|
59
|
+
createId?: CreateId | undefined;
|
|
60
|
+
/**
|
|
61
|
+
* the fields every `edge.add` of the model the root creates fills in where it leaves them
|
|
62
|
+
* out (read once, at mount: the model option `defaultEdgeOptions`)
|
|
63
|
+
*/
|
|
64
|
+
defaultEdgeOptions?: DefaultEdgeOptions<T> | undefined;
|
|
65
|
+
/**
|
|
66
|
+
* controlled viewport (`bind:viewport`, or `viewport` with `onviewportchange`): a new value
|
|
67
|
+
* is set on the engine (`set-viewport`), every change is written back
|
|
68
|
+
*/
|
|
69
|
+
viewport?: Viewport | undefined;
|
|
70
|
+
/** the viewport the flow starts at (read once, at mount); default `{ x: 0, y: 0, zoom: 1 }` */
|
|
71
|
+
defaultViewport?: Viewport | undefined;
|
|
72
|
+
/** called on every viewport change, by a gesture (`gesture: true`) or an action */
|
|
73
|
+
onviewportchange?: ((viewport: Viewport, gesture: boolean) => void) | undefined;
|
|
74
|
+
/** fits the nodes once their sizes are known, again once measured (read once, at mount) */
|
|
75
|
+
fitView?: boolean | FitViewPayload | undefined;
|
|
76
|
+
/** access to the model and the engine from outside the root (`useFlowRef`, `createFlowRef`) */
|
|
77
|
+
flowRef?: FlowRef<T, F> | undefined;
|
|
78
|
+
/** the flow: `Flow.Background`, `Flow.Viewport`, `Flow.Controls`, `MiniMap`, … */
|
|
79
|
+
children?: Snippet<[{
|
|
80
|
+
state: RootState;
|
|
81
|
+
}]> | undefined;
|
|
82
|
+
}
|
|
83
|
+
declare function $$render<T extends FlowTypes = AnyTypes, F extends FlowFeatures = readonly []>(): {
|
|
84
|
+
props: RootProps<T, F>;
|
|
85
|
+
exports: {};
|
|
86
|
+
bindings: "ref" | "nodes" | "edges" | "viewport";
|
|
87
|
+
slots: {};
|
|
88
|
+
events: {};
|
|
89
|
+
};
|
|
90
|
+
declare class __sveltets_Render<T extends FlowTypes = AnyTypes, F extends FlowFeatures = readonly []> {
|
|
91
|
+
props(): ReturnType<typeof $$render<T, F>>['props'];
|
|
92
|
+
events(): ReturnType<typeof $$render<T, F>>['events'];
|
|
93
|
+
slots(): ReturnType<typeof $$render<T, F>>['slots'];
|
|
94
|
+
bindings(): "ref" | "nodes" | "edges" | "viewport";
|
|
95
|
+
exports(): {};
|
|
96
|
+
}
|
|
97
|
+
interface $$IsomorphicComponent {
|
|
98
|
+
new <T extends FlowTypes = AnyTypes, F extends FlowFeatures = readonly []>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<T, F>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<T, F>['props']>, ReturnType<__sveltets_Render<T, F>['events']>, ReturnType<__sveltets_Render<T, F>['slots']>> & {
|
|
99
|
+
$$bindings?: ReturnType<__sveltets_Render<T, F>['bindings']>;
|
|
100
|
+
} & ReturnType<__sveltets_Render<T, F>['exports']>;
|
|
101
|
+
<T extends FlowTypes = AnyTypes, F extends FlowFeatures = readonly []>(internal: unknown, props: ReturnType<__sveltets_Render<T, F>['props']> & {}): ReturnType<__sveltets_Render<T, F>['exports']>;
|
|
102
|
+
z_$$bindings?: ReturnType<__sveltets_Render<any, any>['bindings']>;
|
|
103
|
+
}
|
|
104
|
+
declare const Root: $$IsomorphicComponent;
|
|
105
|
+
type Root<T extends FlowTypes = AnyTypes, F extends FlowFeatures = readonly []> = InstanceType<typeof Root<T, F>>;
|
|
106
|
+
export default Root;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
<script module lang="ts">
|
|
2
|
+
import type { Rect } from "@fragiola/flow";
|
|
3
|
+
import type { Snippet } from "svelte";
|
|
4
|
+
import type { DivPrimitiveProps } from "../utils/render.js";
|
|
5
|
+
|
|
6
|
+
export interface SelectionBoxState {
|
|
7
|
+
/** the box, in pixels relative to the root */
|
|
8
|
+
readonly box: Rect;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface SelectionBoxProps
|
|
12
|
+
extends Omit<DivPrimitiveProps<SelectionBoxState>, "children"> {
|
|
13
|
+
children?: Snippet<[{ state: SelectionBoxState }]> | undefined;
|
|
14
|
+
}
|
|
15
|
+
</script>
|
|
16
|
+
|
|
17
|
+
<!--
|
|
18
|
+
@component
|
|
19
|
+
The box selection being drawn (`data-flow-part="selection-box"`, `selection()`): absolutely
|
|
20
|
+
positioned in `Flow.Root` (outside `Flow.Viewport`: it is in screen pixels), rendered only
|
|
21
|
+
while a box is drawn. Give it its look.
|
|
22
|
+
-->
|
|
23
|
+
<script lang="ts">
|
|
24
|
+
import { useFlowContext } from "../context.js";
|
|
25
|
+
import { flowValue } from "../runes/internal.svelte.js";
|
|
26
|
+
import {
|
|
27
|
+
elementProps,
|
|
28
|
+
px,
|
|
29
|
+
refProps,
|
|
30
|
+
type RenderedProps,
|
|
31
|
+
} from "../utils/render.js";
|
|
32
|
+
|
|
33
|
+
let {
|
|
34
|
+
children,
|
|
35
|
+
render,
|
|
36
|
+
class: className,
|
|
37
|
+
style,
|
|
38
|
+
ref = $bindable(),
|
|
39
|
+
...rest
|
|
40
|
+
}: SelectionBoxProps = $props();
|
|
41
|
+
|
|
42
|
+
const context = useFlowContext("SelectionBox");
|
|
43
|
+
const box = flowValue(context, () =>
|
|
44
|
+
context.engine ? context.engine.get("selection-box") : null,
|
|
45
|
+
);
|
|
46
|
+
const attributes = flowValue(
|
|
47
|
+
context,
|
|
48
|
+
() => context.engine?.adapter.attributes("selection-box") ?? {},
|
|
49
|
+
);
|
|
50
|
+
const refs = refProps((element) => {
|
|
51
|
+
ref = element as HTMLDivElement | null;
|
|
52
|
+
});
|
|
53
|
+
const partState = $derived.by((): SelectionBoxState | undefined =>
|
|
54
|
+
box.current ? { box: box.current } : undefined,
|
|
55
|
+
);
|
|
56
|
+
const attrs: RenderedProps<HTMLDivElement> = $derived.by(() => {
|
|
57
|
+
if (!partState) return {} as RenderedProps<HTMLDivElement>;
|
|
58
|
+
const { x, y, width, height } = partState.box;
|
|
59
|
+
return elementProps({
|
|
60
|
+
rest,
|
|
61
|
+
className,
|
|
62
|
+
style,
|
|
63
|
+
state: partState,
|
|
64
|
+
own: {
|
|
65
|
+
...attributes.current,
|
|
66
|
+
"data-flow-part": "selection-box",
|
|
67
|
+
...refs,
|
|
68
|
+
},
|
|
69
|
+
structural: {
|
|
70
|
+
position: "absolute",
|
|
71
|
+
left: px(x),
|
|
72
|
+
top: px(y),
|
|
73
|
+
width: px(width),
|
|
74
|
+
height: px(height),
|
|
75
|
+
"pointer-events": "none",
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
</script>
|
|
80
|
+
|
|
81
|
+
{#snippet content()}
|
|
82
|
+
{#if partState}{@render children?.({ state: partState })}{/if}
|
|
83
|
+
{/snippet}
|
|
84
|
+
|
|
85
|
+
{#if partState}
|
|
86
|
+
{#if render}
|
|
87
|
+
{@render render({ props: attrs as never, state: partState, children: content })}
|
|
88
|
+
{:else}
|
|
89
|
+
<div {...attrs}>{@render content()}</div>
|
|
90
|
+
{/if}
|
|
91
|
+
{/if}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Rect } from "@fragiola/flow";
|
|
2
|
+
import type { Snippet } from "svelte";
|
|
3
|
+
import type { DivPrimitiveProps } from "../utils/render.js";
|
|
4
|
+
export interface SelectionBoxState {
|
|
5
|
+
/** the box, in pixels relative to the root */
|
|
6
|
+
readonly box: Rect;
|
|
7
|
+
}
|
|
8
|
+
export interface SelectionBoxProps extends Omit<DivPrimitiveProps<SelectionBoxState>, "children"> {
|
|
9
|
+
children?: Snippet<[{
|
|
10
|
+
state: SelectionBoxState;
|
|
11
|
+
}]> | undefined;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The box selection being drawn (`data-flow-part="selection-box"`, `selection()`): absolutely
|
|
15
|
+
* positioned in `Flow.Root` (outside `Flow.Viewport`: it is in screen pixels), rendered only
|
|
16
|
+
* while a box is drawn. Give it its look.
|
|
17
|
+
*/
|
|
18
|
+
declare const SelectionBox: import("svelte").Component<SelectionBoxProps, {}, "ref">;
|
|
19
|
+
type SelectionBox = ReturnType<typeof SelectionBox>;
|
|
20
|
+
export default SelectionBox;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
<script module lang="ts">
|
|
2
|
+
import type { Snippet } from "svelte";
|
|
3
|
+
import type { ButtonPrimitiveProps } from "../utils/render.js";
|
|
4
|
+
|
|
5
|
+
/** The switches the lock turns off and on (React Flow's: dragging, connecting, selecting). */
|
|
6
|
+
const LOCKED_KINDS = ["drag", "connect", "select"] as const;
|
|
7
|
+
|
|
8
|
+
export interface ToggleInteractiveState {
|
|
9
|
+
/**
|
|
10
|
+
* the flow is not locked: it is interactive and one of dragging, connecting and selecting
|
|
11
|
+
* at least is on (`interactive-by`)
|
|
12
|
+
*/
|
|
13
|
+
readonly interactive: boolean;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface ToggleInteractiveProps
|
|
17
|
+
extends Omit<
|
|
18
|
+
ButtonPrimitiveProps<ToggleInteractiveState>,
|
|
19
|
+
"children"
|
|
20
|
+
> {
|
|
21
|
+
/** its content (an icon, a label) */
|
|
22
|
+
children?: Snippet<[{ state: ToggleInteractiveState }]> | undefined;
|
|
23
|
+
}
|
|
24
|
+
</script>
|
|
25
|
+
|
|
26
|
+
<!--
|
|
27
|
+
@component
|
|
28
|
+
A toggle button (`data-flow-part="toggle-interactive"`, `aria-pressed` while the flow is
|
|
29
|
+
locked, `data-interactive`): locks and unlocks the flow, React Flow's interactive button:
|
|
30
|
+
locking turns dragging, connecting and selecting off (`set-interactive { drag, connect,
|
|
31
|
+
select }`), unlocking turns them and `interactive` on; pan and zoom stay. It renders only its
|
|
32
|
+
children.
|
|
33
|
+
-->
|
|
34
|
+
<script lang="ts">
|
|
35
|
+
import { useFlowContext } from "../context.js";
|
|
36
|
+
import { flowValue } from "../runes/internal.svelte.js";
|
|
37
|
+
import {
|
|
38
|
+
elementProps,
|
|
39
|
+
refProps,
|
|
40
|
+
type RenderedProps,
|
|
41
|
+
} from "../utils/render.js";
|
|
42
|
+
|
|
43
|
+
let {
|
|
44
|
+
children,
|
|
45
|
+
render,
|
|
46
|
+
class: className,
|
|
47
|
+
style,
|
|
48
|
+
ref = $bindable(),
|
|
49
|
+
...rest
|
|
50
|
+
}: ToggleInteractiveProps = $props();
|
|
51
|
+
|
|
52
|
+
const context = useFlowContext("ToggleInteractive");
|
|
53
|
+
const interactive = flowValue(context, () => {
|
|
54
|
+
const engine = context.engine;
|
|
55
|
+
return engine
|
|
56
|
+
? LOCKED_KINDS.some((kind) => engine.is("interactive-by", { kind }))
|
|
57
|
+
: true;
|
|
58
|
+
});
|
|
59
|
+
const refs = refProps((element) => {
|
|
60
|
+
ref = element as HTMLButtonElement | null;
|
|
61
|
+
});
|
|
62
|
+
const onclick = () => {
|
|
63
|
+
context.engine?.run(
|
|
64
|
+
"set-interactive",
|
|
65
|
+
interactive.current
|
|
66
|
+
? { drag: false, connect: false, select: false }
|
|
67
|
+
: { interactive: true, drag: true, connect: true, select: true },
|
|
68
|
+
);
|
|
69
|
+
};
|
|
70
|
+
const partState = $derived<ToggleInteractiveState>({
|
|
71
|
+
interactive: interactive.current,
|
|
72
|
+
});
|
|
73
|
+
const attrs: RenderedProps<HTMLButtonElement> = $derived(
|
|
74
|
+
elementProps({
|
|
75
|
+
rest,
|
|
76
|
+
className,
|
|
77
|
+
style,
|
|
78
|
+
state: partState,
|
|
79
|
+
own: {
|
|
80
|
+
type: "button",
|
|
81
|
+
"data-flow-part": "toggle-interactive",
|
|
82
|
+
"data-interactive": partState.interactive ? "" : undefined,
|
|
83
|
+
"aria-pressed": !partState.interactive,
|
|
84
|
+
disabled: context.engine === null,
|
|
85
|
+
onclick,
|
|
86
|
+
...refs,
|
|
87
|
+
},
|
|
88
|
+
}),
|
|
89
|
+
);
|
|
90
|
+
</script>
|
|
91
|
+
|
|
92
|
+
{#snippet content()}{@render children?.({ state: partState })}{/snippet}
|
|
93
|
+
|
|
94
|
+
{#if render}
|
|
95
|
+
{@render render({ props: attrs as never, state: partState, children: content })}
|
|
96
|
+
{:else}
|
|
97
|
+
<button {...attrs}>{@render content()}</button>
|
|
98
|
+
{/if}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Snippet } from "svelte";
|
|
2
|
+
import type { ButtonPrimitiveProps } from "../utils/render.js";
|
|
3
|
+
export interface ToggleInteractiveState {
|
|
4
|
+
/**
|
|
5
|
+
* the flow is not locked: it is interactive and one of dragging, connecting and selecting
|
|
6
|
+
* at least is on (`interactive-by`)
|
|
7
|
+
*/
|
|
8
|
+
readonly interactive: boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface ToggleInteractiveProps extends Omit<ButtonPrimitiveProps<ToggleInteractiveState>, "children"> {
|
|
11
|
+
/** its content (an icon, a label) */
|
|
12
|
+
children?: Snippet<[{
|
|
13
|
+
state: ToggleInteractiveState;
|
|
14
|
+
}]> | undefined;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* A toggle button (`data-flow-part="toggle-interactive"`, `aria-pressed` while the flow is
|
|
18
|
+
* locked, `data-interactive`): locks and unlocks the flow, React Flow's interactive button:
|
|
19
|
+
* locking turns dragging, connecting and selecting off (`set-interactive { drag, connect,
|
|
20
|
+
* select }`), unlocking turns them and `interactive` on; pan and zoom stay. It renders only its
|
|
21
|
+
* children.
|
|
22
|
+
*/
|
|
23
|
+
declare const ToggleInteractive: import("svelte").Component<ToggleInteractiveProps, {}, "ref">;
|
|
24
|
+
type ToggleInteractive = ReturnType<typeof ToggleInteractive>;
|
|
25
|
+
export default ToggleInteractive;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
<script module lang="ts">
|
|
2
|
+
import type { Viewport as ViewportValue } from "@fragiola/flow";
|
|
3
|
+
import type { Snippet } from "svelte";
|
|
4
|
+
import type { DivPrimitiveProps } from "../utils/render.js";
|
|
5
|
+
|
|
6
|
+
export interface ViewportState {
|
|
7
|
+
/** the viewport: the pan (`x`, `y`, pixels) and the zoom */
|
|
8
|
+
viewport: ViewportValue;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface ViewportProps
|
|
12
|
+
extends Omit<DivPrimitiveProps<ViewportState>, "children"> {
|
|
13
|
+
/** what is in flow coordinates: `Flow.Edges`, `Flow.Nodes`, `Flow.ConnectionLine` */
|
|
14
|
+
children?: Snippet<[{ state: ViewportState }]> | undefined;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const VIEWPORT_STYLE = {
|
|
18
|
+
position: "absolute",
|
|
19
|
+
top: "0",
|
|
20
|
+
left: "0",
|
|
21
|
+
width: "100%",
|
|
22
|
+
height: "100%",
|
|
23
|
+
// a stacking context of its own before the engine writes its transform (the server's
|
|
24
|
+
// HTML): with several render levels the nodes and edge layers have negative z-indexes
|
|
25
|
+
isolation: "isolate",
|
|
26
|
+
};
|
|
27
|
+
</script>
|
|
28
|
+
|
|
29
|
+
<!--
|
|
30
|
+
The pannable, zoomable layer (`data-flow-part="viewport"`): what is inside is in flow
|
|
31
|
+
coordinates (`Flow.Edges`, `Flow.Nodes`, `Flow.ConnectionLine`). The engine writes its
|
|
32
|
+
`transform` itself (D4), never Svelte: a pan or a zoom re-renders nothing inside it.
|
|
33
|
+
-->
|
|
34
|
+
<script lang="ts">
|
|
35
|
+
import { partAttributes } from "@fragiola/flow";
|
|
36
|
+
import { untrack } from "svelte";
|
|
37
|
+
import { createAttachmentKey } from "svelte/attachments";
|
|
38
|
+
import { useFlowContext } from "../context.js";
|
|
39
|
+
import { useViewport } from "../runes/use-viewport.svelte.js";
|
|
40
|
+
import {
|
|
41
|
+
elementProps,
|
|
42
|
+
refProps,
|
|
43
|
+
type RenderedProps,
|
|
44
|
+
} from "../utils/render.js";
|
|
45
|
+
|
|
46
|
+
let {
|
|
47
|
+
children,
|
|
48
|
+
render,
|
|
49
|
+
class: className,
|
|
50
|
+
style,
|
|
51
|
+
ref = $bindable(),
|
|
52
|
+
...rest
|
|
53
|
+
}: ViewportProps = $props();
|
|
54
|
+
|
|
55
|
+
const context = useFlowContext("Viewport");
|
|
56
|
+
const viewport = useViewport();
|
|
57
|
+
const refs = refProps((element) => {
|
|
58
|
+
ref = element as HTMLDivElement | null;
|
|
59
|
+
});
|
|
60
|
+
const engineKey = createAttachmentKey();
|
|
61
|
+
const own = {
|
|
62
|
+
...partAttributes("viewport"),
|
|
63
|
+
...refs,
|
|
64
|
+
[engineKey]: (element: Element) => {
|
|
65
|
+
const engine = context.engine;
|
|
66
|
+
if (!engine) return;
|
|
67
|
+
engine.adapter.attachViewport(element as HTMLElement);
|
|
68
|
+
return () => engine.adapter.attachViewport(null);
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
// the viewport is read by the state only when a consumer reads it (a pan re-renders nothing)
|
|
72
|
+
const partState: ViewportState = {
|
|
73
|
+
get viewport() {
|
|
74
|
+
return viewport.current;
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
// the engine writes the transform on its element (D4), never Svelte; but a new style string
|
|
78
|
+
// (the consumer's style changed) replaces the element's whole style, so it carries the
|
|
79
|
+
// transform the engine wrote last, read without following it: a pan derives nothing here
|
|
80
|
+
const engineStyle = () =>
|
|
81
|
+
untrack(() => {
|
|
82
|
+
const engine = context.engine;
|
|
83
|
+
if (!engine) return {};
|
|
84
|
+
const { x, y, zoom } = engine.get("viewport");
|
|
85
|
+
return {
|
|
86
|
+
"transform-origin": "0 0",
|
|
87
|
+
transform: `translate(${x}px, ${y}px) scale(${zoom})`,
|
|
88
|
+
};
|
|
89
|
+
});
|
|
90
|
+
const attrs: RenderedProps<HTMLDivElement> = $derived(
|
|
91
|
+
elementProps({
|
|
92
|
+
rest,
|
|
93
|
+
className,
|
|
94
|
+
style,
|
|
95
|
+
state: partState,
|
|
96
|
+
own,
|
|
97
|
+
structural: { ...VIEWPORT_STYLE, ...engineStyle() },
|
|
98
|
+
}),
|
|
99
|
+
);
|
|
100
|
+
</script>
|
|
101
|
+
|
|
102
|
+
{#snippet content()}{@render children?.({ state: partState })}{/snippet}
|
|
103
|
+
|
|
104
|
+
{#if render}
|
|
105
|
+
{@render render({ props: attrs as never, state: partState, children: content })}
|
|
106
|
+
{:else}
|
|
107
|
+
<div {...attrs}>{@render content()}</div>
|
|
108
|
+
{/if}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Viewport as ViewportValue } from "@fragiola/flow";
|
|
2
|
+
import type { Snippet } from "svelte";
|
|
3
|
+
import type { DivPrimitiveProps } from "../utils/render.js";
|
|
4
|
+
export interface ViewportState {
|
|
5
|
+
/** the viewport: the pan (`x`, `y`, pixels) and the zoom */
|
|
6
|
+
viewport: ViewportValue;
|
|
7
|
+
}
|
|
8
|
+
export interface ViewportProps extends Omit<DivPrimitiveProps<ViewportState>, "children"> {
|
|
9
|
+
/** what is in flow coordinates: `Flow.Edges`, `Flow.Nodes`, `Flow.ConnectionLine` */
|
|
10
|
+
children?: Snippet<[{
|
|
11
|
+
state: ViewportState;
|
|
12
|
+
}]> | undefined;
|
|
13
|
+
}
|
|
14
|
+
declare const Viewport: import("svelte").Component<ViewportProps, {}, "ref">;
|
|
15
|
+
type Viewport = ReturnType<typeof Viewport>;
|
|
16
|
+
export default Viewport;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
<script module lang="ts">
|
|
2
|
+
import type { Snippet } from "svelte";
|
|
3
|
+
import type { ControlButtonState } from "../runes/use-control-button.svelte.js";
|
|
4
|
+
import type { ButtonPrimitiveProps } from "../utils/render.js";
|
|
5
|
+
|
|
6
|
+
export interface ZoomInProps
|
|
7
|
+
extends Omit<ButtonPrimitiveProps<ControlButtonState>, "children"> {
|
|
8
|
+
/** how long its viewport change animates, in milliseconds (the root's `easing`); default 0: at once */
|
|
9
|
+
duration?: number | undefined;
|
|
10
|
+
/** its content (an icon, a label) */
|
|
11
|
+
children?: Snippet<[{ state: ControlButtonState }]> | undefined;
|
|
12
|
+
}
|
|
13
|
+
</script>
|
|
14
|
+
|
|
15
|
+
<!--
|
|
16
|
+
@component
|
|
17
|
+
A button (`data-flow-part="zoom-in"`): Zooms in by a step around the root's centre (`zoom-in`), disabled at the greatest zoom. It renders only its
|
|
18
|
+
children (an icon, a label).
|
|
19
|
+
-->
|
|
20
|
+
<script lang="ts">
|
|
21
|
+
import { useControlButton } from "../runes/use-control-button.svelte.js";
|
|
22
|
+
import {
|
|
23
|
+
elementProps,
|
|
24
|
+
refProps,
|
|
25
|
+
type RenderedProps,
|
|
26
|
+
} from "../utils/render.js";
|
|
27
|
+
|
|
28
|
+
let {
|
|
29
|
+
children,
|
|
30
|
+
disabled,
|
|
31
|
+
duration,
|
|
32
|
+
render,
|
|
33
|
+
class: className,
|
|
34
|
+
style,
|
|
35
|
+
ref = $bindable(),
|
|
36
|
+
...rest
|
|
37
|
+
}: ZoomInProps = $props();
|
|
38
|
+
|
|
39
|
+
const button = useControlButton(
|
|
40
|
+
"ZoomIn",
|
|
41
|
+
"zoom-in",
|
|
42
|
+
() => disabled,
|
|
43
|
+
() => ({ duration }),
|
|
44
|
+
);
|
|
45
|
+
const refs = refProps((element) => {
|
|
46
|
+
ref = element as HTMLButtonElement | null;
|
|
47
|
+
});
|
|
48
|
+
const attrs: RenderedProps<HTMLButtonElement> = $derived(
|
|
49
|
+
elementProps({
|
|
50
|
+
rest,
|
|
51
|
+
className,
|
|
52
|
+
style,
|
|
53
|
+
state: button.state,
|
|
54
|
+
own: { ...button.props, ...refs },
|
|
55
|
+
}),
|
|
56
|
+
);
|
|
57
|
+
</script>
|
|
58
|
+
|
|
59
|
+
{#snippet content()}{@render children?.({ state: button.state })}{/snippet}
|
|
60
|
+
|
|
61
|
+
{#if render}
|
|
62
|
+
{@render render({ props: attrs as never, state: button.state, children: content })}
|
|
63
|
+
{:else}
|
|
64
|
+
<button {...attrs}>{@render content()}</button>
|
|
65
|
+
{/if}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Snippet } from "svelte";
|
|
2
|
+
import type { ControlButtonState } from "../runes/use-control-button.svelte.js";
|
|
3
|
+
import type { ButtonPrimitiveProps } from "../utils/render.js";
|
|
4
|
+
export interface ZoomInProps extends Omit<ButtonPrimitiveProps<ControlButtonState>, "children"> {
|
|
5
|
+
/** how long its viewport change animates, in milliseconds (the root's `easing`); default 0: at once */
|
|
6
|
+
duration?: number | undefined;
|
|
7
|
+
/** its content (an icon, a label) */
|
|
8
|
+
children?: Snippet<[{
|
|
9
|
+
state: ControlButtonState;
|
|
10
|
+
}]> | undefined;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* A button (`data-flow-part="zoom-in"`): Zooms in by a step around the root's centre (`zoom-in`), disabled at the greatest zoom. It renders only its
|
|
14
|
+
* children (an icon, a label).
|
|
15
|
+
*/
|
|
16
|
+
declare const ZoomIn: import("svelte").Component<ZoomInProps, {}, "ref">;
|
|
17
|
+
type ZoomIn = ReturnType<typeof ZoomIn>;
|
|
18
|
+
export default ZoomIn;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
<script module lang="ts">
|
|
2
|
+
import type { Snippet } from "svelte";
|
|
3
|
+
import type { ControlButtonState } from "../runes/use-control-button.svelte.js";
|
|
4
|
+
import type { ButtonPrimitiveProps } from "../utils/render.js";
|
|
5
|
+
|
|
6
|
+
export interface ZoomOutProps
|
|
7
|
+
extends Omit<ButtonPrimitiveProps<ControlButtonState>, "children"> {
|
|
8
|
+
/** how long its viewport change animates, in milliseconds (the root's `easing`); default 0: at once */
|
|
9
|
+
duration?: number | undefined;
|
|
10
|
+
/** its content (an icon, a label) */
|
|
11
|
+
children?: Snippet<[{ state: ControlButtonState }]> | undefined;
|
|
12
|
+
}
|
|
13
|
+
</script>
|
|
14
|
+
|
|
15
|
+
<!--
|
|
16
|
+
@component
|
|
17
|
+
A button (`data-flow-part="zoom-out"`): Zooms out by a step around the root's centre (`zoom-out`), disabled at the least zoom. It renders only its
|
|
18
|
+
children (an icon, a label).
|
|
19
|
+
-->
|
|
20
|
+
<script lang="ts">
|
|
21
|
+
import { useControlButton } from "../runes/use-control-button.svelte.js";
|
|
22
|
+
import {
|
|
23
|
+
elementProps,
|
|
24
|
+
refProps,
|
|
25
|
+
type RenderedProps,
|
|
26
|
+
} from "../utils/render.js";
|
|
27
|
+
|
|
28
|
+
let {
|
|
29
|
+
children,
|
|
30
|
+
disabled,
|
|
31
|
+
duration,
|
|
32
|
+
render,
|
|
33
|
+
class: className,
|
|
34
|
+
style,
|
|
35
|
+
ref = $bindable(),
|
|
36
|
+
...rest
|
|
37
|
+
}: ZoomOutProps = $props();
|
|
38
|
+
|
|
39
|
+
const button = useControlButton(
|
|
40
|
+
"ZoomOut",
|
|
41
|
+
"zoom-out",
|
|
42
|
+
() => disabled,
|
|
43
|
+
() => ({ duration }),
|
|
44
|
+
);
|
|
45
|
+
const refs = refProps((element) => {
|
|
46
|
+
ref = element as HTMLButtonElement | null;
|
|
47
|
+
});
|
|
48
|
+
const attrs: RenderedProps<HTMLButtonElement> = $derived(
|
|
49
|
+
elementProps({
|
|
50
|
+
rest,
|
|
51
|
+
className,
|
|
52
|
+
style,
|
|
53
|
+
state: button.state,
|
|
54
|
+
own: { ...button.props, ...refs },
|
|
55
|
+
}),
|
|
56
|
+
);
|
|
57
|
+
</script>
|
|
58
|
+
|
|
59
|
+
{#snippet content()}{@render children?.({ state: button.state })}{/snippet}
|
|
60
|
+
|
|
61
|
+
{#if render}
|
|
62
|
+
{@render render({ props: attrs as never, state: button.state, children: content })}
|
|
63
|
+
{:else}
|
|
64
|
+
<button {...attrs}>{@render content()}</button>
|
|
65
|
+
{/if}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Snippet } from "svelte";
|
|
2
|
+
import type { ControlButtonState } from "../runes/use-control-button.svelte.js";
|
|
3
|
+
import type { ButtonPrimitiveProps } from "../utils/render.js";
|
|
4
|
+
export interface ZoomOutProps extends Omit<ButtonPrimitiveProps<ControlButtonState>, "children"> {
|
|
5
|
+
/** how long its viewport change animates, in milliseconds (the root's `easing`); default 0: at once */
|
|
6
|
+
duration?: number | undefined;
|
|
7
|
+
/** its content (an icon, a label) */
|
|
8
|
+
children?: Snippet<[{
|
|
9
|
+
state: ControlButtonState;
|
|
10
|
+
}]> | undefined;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* A button (`data-flow-part="zoom-out"`): Zooms out by a step around the root's centre (`zoom-out`), disabled at the least zoom. It renders only its
|
|
14
|
+
* children (an icon, a label).
|
|
15
|
+
*/
|
|
16
|
+
declare const ZoomOut: import("svelte").Component<ZoomOutProps, {}, "ref">;
|
|
17
|
+
type ZoomOut = ReturnType<typeof ZoomOut>;
|
|
18
|
+
export default ZoomOut;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@fragiola/flow/connection";
|