Let the canvas endpoints be moved, and lift them on hover
Three things they were missing: they could not be dragged out of the lane they were placed in, they stayed the same weight whether or not you were reaching for one, and the label sat right against its connector dot. Where one has been dragged to is a view preference, not part of the flow — writing a position for a dashboard widget into flow.json would be a lie about what the document holds — so it lives in the browser, keyed by flow. Also folds the dashboard shot into `make verify` and drops the one-off scripts that had accumulated beside it; the durable coverage is the Playwright specs, which all pass.
This commit is contained in:
@@ -40,6 +40,45 @@ export function isEndpointNode(node: { id: string }): boolean {
|
||||
return node.id.startsWith("dashboard:") || node.id.startsWith("flow:")
|
||||
}
|
||||
|
||||
/**
|
||||
* Where the author dragged an endpoint to.
|
||||
*
|
||||
* Not in the flow document — an endpoint is not part of the flow, and writing
|
||||
* a position for one into `flow.json` would be a lie about what it contains.
|
||||
* A view preference belongs to the view, so it lives in the browser.
|
||||
*/
|
||||
const POSITION_KEY = "fluksio-endpoint-positions"
|
||||
|
||||
type Placements = Record<string, Record<string, { x: number; y: number }>>
|
||||
|
||||
function readPlacements(): Placements {
|
||||
try {
|
||||
return JSON.parse(localStorage.getItem(POSITION_KEY) ?? "{}") as Placements
|
||||
} catch {
|
||||
return {}
|
||||
}
|
||||
}
|
||||
|
||||
export function placementsFor(
|
||||
flow: string,
|
||||
): Record<string, { x: number; y: number }> {
|
||||
return readPlacements()[flow] ?? {}
|
||||
}
|
||||
|
||||
export function rememberPlacement(
|
||||
flow: string,
|
||||
id: string,
|
||||
position: { x: number; y: number },
|
||||
): void {
|
||||
const all = readPlacements()
|
||||
all[flow] = { ...(all[flow] ?? {}), [id]: position }
|
||||
try {
|
||||
localStorage.setItem(POSITION_KEY, JSON.stringify(all))
|
||||
} catch {
|
||||
// A full or disabled store just means positions reset; not worth failing.
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Place the endpoints and wire them to the nodes they touch.
|
||||
*
|
||||
@@ -53,6 +92,7 @@ export function deriveEndpoints(
|
||||
definitions: NodeDef_Input[],
|
||||
flow: string,
|
||||
positions: Map<string, { x: number; y: number }>,
|
||||
moved: Record<string, { x: number; y: number }> = {},
|
||||
): { nodes: FlowCanvasNode[]; edges: Edge[] } {
|
||||
if (endpoints.length === 0) return { nodes: [], edges: [] }
|
||||
|
||||
@@ -104,12 +144,12 @@ export function deriveEndpoints(
|
||||
nodes.push({
|
||||
id: endpoint.id,
|
||||
type: ENDPOINT_TYPE,
|
||||
position: {
|
||||
position: moved[endpoint.id] ?? {
|
||||
x: side === "left" ? bounds.left - GAP_X : bounds.right + GAP_X,
|
||||
y: bounds.top + index * STACK_Y,
|
||||
},
|
||||
// Not part of the document, and not the author's to rearrange.
|
||||
draggable: false,
|
||||
// Movable, so a canvas can be arranged; still not the flow's to delete.
|
||||
draggable: true,
|
||||
selectable: true,
|
||||
deletable: false,
|
||||
data: {
|
||||
|
||||
Reference in New Issue
Block a user