@dudousxd/nestjs-catalog-react 0.18.0 → 0.19.0-preview.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.
Files changed (40) hide show
  1. package/dist/CatalogManager.d.ts +23 -1
  2. package/dist/CatalogManager.js +76 -13
  3. package/dist/ConnectionPanel.js +15 -123
  4. package/dist/LoadedBySection.d.ts +39 -0
  5. package/dist/LoadedBySection.js +143 -0
  6. package/dist/WorkflowCanvas.d.ts +16 -0
  7. package/dist/WorkflowCanvas.js +705 -77
  8. package/dist/connection-form.d.ts +241 -0
  9. package/dist/connection-form.js +235 -0
  10. package/dist/context.d.ts +78 -4
  11. package/dist/context.js +11 -0
  12. package/dist/index.d.ts +5 -1
  13. package/dist/index.js +23 -0
  14. package/dist/routes.d.ts +30 -0
  15. package/dist/routes.js +2 -0
  16. package/dist/schema-discovery.d.ts +17 -1
  17. package/dist/schema-discovery.js +3 -3
  18. package/dist/source-connection.d.ts +82 -0
  19. package/dist/source-connection.js +176 -0
  20. package/dist/source-fields.d.ts +15 -2
  21. package/dist/source-fields.js +15 -2
  22. package/dist/ui/combobox.d.ts +97 -0
  23. package/dist/ui/combobox.js +80 -0
  24. package/dist/workflow/edges.d.ts +110 -0
  25. package/dist/workflow/edges.js +112 -0
  26. package/dist/workflow/graph.d.ts +39 -1
  27. package/dist/workflow/graph.js +181 -43
  28. package/dist/workflow/index.d.ts +7 -1
  29. package/dist/workflow/index.js +10 -5
  30. package/dist/workflow/lifecycle.d.ts +0 -29
  31. package/dist/workflow/lifecycle.js +2 -35
  32. package/dist/workflow/model.d.ts +17 -3
  33. package/dist/workflow/model.js +7 -2
  34. package/dist/workflow/nodes.d.ts +4 -1
  35. package/dist/workflow/nodes.js +190 -11
  36. package/dist/workflow/templates.js +10 -0
  37. package/dist/workflow/validate.js +11 -0
  38. package/dist/workflow/wiring.d.ts +84 -0
  39. package/dist/workflow/wiring.js +254 -0
  40. package/package.json +9 -9
@@ -0,0 +1,80 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Autocomplete } from '@base-ui/react/autocomplete';
3
+ import { Check, ChevronsUpDown } from 'lucide-react';
4
+ import { useState } from 'react';
5
+ import { cn } from '../cn';
6
+ const CONTROL = cn('w-full rounded-md border py-1.5 pl-2 pr-7 text-xs outline-none', 'border-zinc-200 bg-white text-zinc-900 placeholder:text-zinc-400', 'dark:border-zinc-800 dark:bg-zinc-900 dark:text-zinc-100 dark:placeholder:text-zinc-600', 'focus-visible:border-sky-500 focus-visible:ring-2 focus-visible:ring-sky-500/15', 'disabled:opacity-40');
7
+ export function Combobox({ value, onValueChange, onSelect, options, emptyMessage = 'Nothing here matches that.', placeholder, disabled, ariaLabel, className, }) {
8
+ /**
9
+ * The query, which is NOT the value.
10
+ *
11
+ * `undefined` means "nothing has been typed since this opened", and the whole
12
+ * list shows. That distinction is the difference between a usable field and
13
+ * an infuriating one: the box holds a committed value, so filtering by it
14
+ * would open the popup onto the single row somebody already chose, and the
15
+ * only way to see the other versions would be to delete what is there.
16
+ */
17
+ const [query, setQuery] = useState(undefined);
18
+ const filtered = query === undefined ? options : options.filter((o) => matches(o, query));
19
+ return (_jsxs(Autocomplete.Root
20
+ // `items` is what `Autocomplete.Empty` counts, and `filteredItems` is
21
+ // what the list navigates. Both are given the SAME array, because the
22
+ // filtering above is ours: Base UI's own is a collator over the label,
23
+ // and it cannot see `keywords`.
24
+ , {
25
+ // `items` is what `Autocomplete.Empty` counts, and `filteredItems` is
26
+ // what the list navigates. Both are given the SAME array, because the
27
+ // filtering above is ours: Base UI's own is a collator over the label,
28
+ // and it cannot see `keywords`.
29
+ items: filtered, filteredItems: filtered, value: value, onValueChange: (next, details) => {
30
+ // See the docblock: Base UI fills the input on an item press, and that
31
+ // arrives here as though somebody had typed it. `onSelect` has already
32
+ // told the caller, in full, what the row meant.
33
+ if (details.reason === 'item-press')
34
+ return;
35
+ setQuery(next);
36
+ onValueChange(next);
37
+ },
38
+ // Re-arm the "show everything" state on open AND on close, so the next
39
+ // opening is not still filtered by the last thing typed into it.
40
+ onOpenChange: () => setQuery(undefined), openOnInputClick: true, disabled: disabled, children: [_jsxs("div", { className: cn('relative', className), children: [_jsx(Autocomplete.Input, { "aria-label": ariaLabel, placeholder: placeholder, spellCheck: false, className: CONTROL }), _jsx(Autocomplete.Icon, { className: "pointer-events-none absolute inset-y-0 right-2 flex items-center", children: _jsx(ChevronsUpDown, { size: 12, className: "shrink-0 text-zinc-400" }) })] }), _jsx(Autocomplete.Portal, { children: _jsx(Autocomplete.Positioner, { sideOffset: 4, className: "z-50", children: _jsxs(Autocomplete.Popup, { className: cn('max-h-72 w-[var(--anchor-width)] overflow-y-auto rounded-md border p-1 shadow-md', 'border-zinc-200 bg-white dark:border-zinc-800 dark:bg-zinc-900',
41
+ // The house animation, and then the fallback. `motion-reduce` is
42
+ // the ceiling for people who asked for less, not for everyone.
43
+ 'origin-[var(--transform-origin)] transition-[opacity,transform] duration-100 ease-out', 'data-[starting-style]:scale-95 data-[starting-style]:opacity-0', 'data-[ending-style]:scale-95 data-[ending-style]:opacity-0', 'motion-reduce:transition-none motion-reduce:data-[starting-style]:scale-100 motion-reduce:data-[ending-style]:scale-100'), children: [_jsx(Autocomplete.Empty, { className: "px-2 py-1.5 text-[11px] leading-relaxed text-zinc-400 dark:text-zinc-500", children: filtered.length === 0 ? emptyMessage : null }), _jsx(Autocomplete.List, { children: filtered.map((option) => (_jsxs(Autocomplete.Item, { value: option, disabled: option.disabled, onClick: () => {
44
+ // The rendering says a row is disabled; this says it again
45
+ // at the moment of commit. A `disabled` attribute is a
46
+ // rendering decision and the rule about what may be
47
+ // committed is not one.
48
+ if (option.disabled)
49
+ return;
50
+ onSelect?.(option);
51
+ }, className: cn('flex cursor-default items-start gap-2 rounded-sm px-2 py-1.5 text-xs outline-none', 'data-[highlighted]:bg-zinc-100 dark:data-[highlighted]:bg-zinc-800', 'data-[disabled]:opacity-40'), children: [_jsx("span", { className: "mt-0.5 w-3 shrink-0", children: option.value === value && !option.disabled && (_jsx(Check, { size: 11, className: "text-sky-600" })) }), _jsxs("span", { className: "min-w-0 flex-1", children: [_jsx("span", { className: "block truncate", title: option.label, children: option.label }), option.hint && (_jsx("span", { className: "mt-0.5 block truncate font-mono text-[10px] text-zinc-400 dark:text-zinc-500", children: option.hint }))] })] }, option.value))) })] }) }) })] }));
52
+ }
53
+ /**
54
+ * Case-insensitive substring, over the label and whatever else the row said to
55
+ * search.
56
+ *
57
+ * Substring rather than prefix on purpose: workflow names are dotted and
58
+ * namespaced, and somebody looking for `billing.reconcile` types `reconcile`
59
+ * about as often as they type `billing`.
60
+ */
61
+ function matches(option, query) {
62
+ const needle = query.trim().toLowerCase();
63
+ if (needle.length === 0)
64
+ return true;
65
+ const haystack = `${option.label} ${option.keywords ?? ''}`.toLowerCase();
66
+ return haystack.includes(needle);
67
+ }
68
+ /**
69
+ * A {@link Combobox} with a label above it, matching `TextField` — and a real
70
+ * `<label>`, because unlike `Select` this renders an `<input>` and a label
71
+ * therefore names it natively.
72
+ */
73
+ export function ComboboxField({ label, hint, ...props }) {
74
+ return (
75
+ // `Combobox` renders a real `<input>`, so wrapping it names it natively and
76
+ // no `aria-label` is needed — unlike `SelectField`, whose control is a
77
+ // button. Biome cannot see the input through the component boundary.
78
+ // biome-ignore lint/a11y/noLabelWithoutControl: see above
79
+ _jsxs("label", { className: "block", children: [_jsx("span", { className: "mb-1 block font-mono text-[10px] uppercase tracking-[0.14em] text-zinc-400 dark:text-zinc-500", children: label }), _jsx(Combobox, { ...props }), hint && (_jsx("span", { className: "mt-1 block text-[11px] leading-relaxed text-zinc-400 dark:text-zinc-500", children: hint }))] }));
80
+ }
@@ -0,0 +1,110 @@
1
+ import { type EdgeProps } from '@xyflow/react';
2
+ import { type ReactNode } from 'react';
3
+ import type { WorkflowEdge } from './model';
4
+ /**
5
+ * The edge, and the one gesture it was missing.
6
+ *
7
+ * ## Why this file exists
8
+ *
9
+ * Removing a connection was already wired — `onDisconnect(edge)` has been on the
10
+ * canvas since the wiring menu was added — but every way of *reaching* it went
11
+ * through something else: a menu hanging off a node, a row in the wiring rail,
12
+ * or selecting the line and knowing that Delete is a key. The thing somebody
13
+ * reaches for first is the connection itself, and clicking it did nothing
14
+ * visible. So this is not a new capability; it is the missing gesture on one
15
+ * that already existed.
16
+ *
17
+ * ## Selection, not hover
18
+ *
19
+ * The × appears when the edge is **selected**, which React Flow does on click
20
+ * and also on Enter or Space when the edge has keyboard focus. Hover would have
21
+ * been fractionally quicker with a mouse and unreachable without one, and it
22
+ * would put a delete button under the pointer of somebody who is only tracing
23
+ * where a line goes. Selection is a decision; hover is a coincidence.
24
+ *
25
+ * ## What the keyboard gets
26
+ *
27
+ * All of it, by two routes. React Flow renders the edge as a focusable element
28
+ * with `edgesFocusable`, so Tab reaches it and Enter or Space selects it — at
29
+ * which point the × exists in the document and is an ordinary `<button>` in the
30
+ * tab order. And the route that predates this is untouched: the wiring rail
31
+ * beside the canvas lists every connection as a row with its own Disconnect
32
+ * button, reachable without going near the canvas at all. The × is an
33
+ * affordance, never the only way through, and `workflow-edge-delete.spec.tsx`
34
+ * holds both halves of that so neither can quietly become the other.
35
+ *
36
+ * ## What reduced motion gets
37
+ *
38
+ * The same button, in the same place, doing the same thing — it simply arrives
39
+ * without the scale-and-fade. Nothing here is revealed *by* an animation: the ×
40
+ * is mounted by `selected`, and `AnimatePresence` only decides how it comes and
41
+ * goes. Somebody with `prefers-reduced-motion` loses a flourish, not a control.
42
+ *
43
+ * ## Why the placement and the animation are on two different elements
44
+ *
45
+ * They used to be on one, and that is the bug this file was reopened for. The ×
46
+ * was a `motion.div` that both carried
47
+ * `transform: translate(-50%, -140%) translate(Xpx, Ypx)` in its `style` and
48
+ * animated `scale`. Motion owns the WHOLE `transform` property of anything it
49
+ * animates a transform component of: it composes the property from its own
50
+ * values every frame and writes the result, so the hand-written translate was
51
+ * overwritten — and at rest, with `scale: 1` and nothing else to compose, what
52
+ * it wrote was `transform: none`. The control then sat at the untranslated
53
+ * origin of `.react-flow__edgelabel-renderer`, which is the top-left of the
54
+ * graph, underneath the first node. Measured in a browser: the button 414px
55
+ * left and 42px above the line's midpoint, and `elementFromPoint` at its centre
56
+ * returning the source node's header. It was present, labelled, opacity 1, and
57
+ * unreachable.
58
+ *
59
+ * So the two jobs are split. A plain `<div>` does the positioning and Motion
60
+ * never touches it; the `motion.div` inside it animates opacity and scale only,
61
+ * about an origin the outer div has already put in the right place. The outer
62
+ * div stays mounted whether or not the × is offered, because it is what
63
+ * `AnimatePresence` needs to be rendered inside for the exit to play at all.
64
+ * `workflow-edge-delete.spec.tsx` pins the translate onto that outer element.
65
+ */
66
+ /**
67
+ * What an edge can reach without being handed a callback through `data`.
68
+ *
69
+ * A context for the same reason `WorkflowNodeContext` is one: React Flow
70
+ * compares an edge's `data` between renders, and a function in there is a new
71
+ * identity every time the screen renders, which invalidates every edge at once.
72
+ *
73
+ * The default throws rather than no-oping. An edge rendered outside the canvas
74
+ * would otherwise look entirely normal and quietly ignore every click on its ×,
75
+ * which is a far worse bug to find than an error naming the missing provider.
76
+ */
77
+ interface WorkflowEdgeHandlers {
78
+ /** Remove this connection. Same callback the wiring menu and the rail use. */
79
+ onDisconnect(edge: WorkflowEdge): void;
80
+ /** Whether editing is offered at all. Read-only viewers get no ×. */
81
+ canEdit: boolean;
82
+ }
83
+ export declare function WorkflowEdgeProvider({ handlers, children, }: {
84
+ handlers: WorkflowEdgeHandlers;
85
+ children: ReactNode;
86
+ }): import("react/jsx-runtime").JSX.Element;
87
+ /**
88
+ * What an edge carries for its own sake, beyond the two node ids.
89
+ *
90
+ * The labels rather than the ids, because the accessible name of the delete
91
+ * button has to say which connection it removes in the words on the canvas —
92
+ * "Remove the connection from src_1 to snk_1" names two things nobody can see.
93
+ */
94
+ export interface WorkflowEdgeData extends Record<string, unknown> {
95
+ fromLabel: string;
96
+ toLabel: string;
97
+ }
98
+ export declare function WorkflowEdgeBody({ id, source, target, sourceX, sourceY, targetX, targetY, sourcePosition, targetPosition, markerEnd, style, selected, data, }: EdgeProps): import("react/jsx-runtime").JSX.Element;
99
+ /**
100
+ * Declared once, at module scope, for the same reason `workflowNodeTypes` is.
101
+ *
102
+ * React Flow compares `edgeTypes` by identity and warns — then remounts every
103
+ * edge — when it changes. An object literal written inline in the screen is a new
104
+ * object on every render, so the canvas would tear down and rebuild every
105
+ * connection on each keystroke in the name field.
106
+ */
107
+ export declare const workflowEdgeTypes: {
108
+ workflowEdge: typeof WorkflowEdgeBody;
109
+ };
110
+ export {};
@@ -0,0 +1,112 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { BaseEdge, EdgeLabelRenderer, getSmoothStepPath, useReactFlow, } from '@xyflow/react';
3
+ import { X } from 'lucide-react';
4
+ import { AnimatePresence, motion, useReducedMotion } from 'motion/react';
5
+ import { createContext, useContext } from 'react';
6
+ import { Button } from '../ui/button';
7
+ const WorkflowEdgeContext = createContext(null);
8
+ export function WorkflowEdgeProvider({ handlers, children, }) {
9
+ return _jsx(WorkflowEdgeContext.Provider, { value: handlers, children: children });
10
+ }
11
+ function useWorkflowEdgeHandlers() {
12
+ const handlers = useContext(WorkflowEdgeContext);
13
+ if (!handlers) {
14
+ throw new Error('A workflow edge was rendered outside <WorkflowEdgeProvider>.');
15
+ }
16
+ return handlers;
17
+ }
18
+ function readLabels(data) {
19
+ // Narrowed rather than asserted: `data` is React Flow's open bag, and an edge
20
+ // built by anything other than `toFlowEdges` would otherwise render a button
21
+ // whose accessible name is the word "undefined".
22
+ if (typeof data === 'object' && data !== null && 'fromLabel' in data && 'toLabel' in data) {
23
+ const { fromLabel, toLabel } = data;
24
+ if (typeof fromLabel === 'string' && typeof toLabel === 'string')
25
+ return { fromLabel, toLabel };
26
+ }
27
+ return { fromLabel: '', toLabel: '' };
28
+ }
29
+ /**
30
+ * How the × comes and goes.
31
+ *
32
+ * A spring rather than a tween, so it settles rather than stopping — the control
33
+ * is appearing at a point somebody just clicked, and a linear pop reads as a
34
+ * tooltip rather than as something they summoned. Short and stiff enough that it
35
+ * is finished before the hand moves.
36
+ */
37
+ const APPEAR = { type: 'spring', stiffness: 520, damping: 30, mass: 0.6 };
38
+ export function WorkflowEdgeBody({ id, source, target, sourceX, sourceY, targetX, targetY, sourcePosition, targetPosition, markerEnd, style, selected, data, }) {
39
+ const { onDisconnect, canEdit } = useWorkflowEdgeHandlers();
40
+ const reduced = useReducedMotion();
41
+ const { setEdges } = useReactFlow();
42
+ const { fromLabel, toLabel } = readLabels(data);
43
+ const [path, labelX, labelY] = getSmoothStepPath({
44
+ sourceX,
45
+ sourceY,
46
+ targetX,
47
+ targetY,
48
+ sourcePosition,
49
+ targetPosition,
50
+ // Rounder than React Flow's 5px default. The corners are the only part of a
51
+ // smoothstep edge with any character, and at 5px they read as a mitre.
52
+ borderRadius: 12,
53
+ });
54
+ const offered = Boolean(selected) && canEdit;
55
+ return (_jsxs(_Fragment, { children: [selected && (_jsx("path", { d: path, fill: "none", stroke: "var(--xy-edge-stroke-selected)", strokeWidth: 10, strokeOpacity: 0.18, strokeLinecap: "round",
56
+ // Never a click target: the interaction path below is what catches
57
+ // the pointer, and a second wide path that also did would make the
58
+ // selected edge harder to click *past* than an unselected one.
59
+ style: { pointerEvents: 'none' } })), _jsx(BaseEdge, { id: id, path: path, markerEnd: markerEnd, style: {
60
+ ...style,
61
+ // Only the width is set here. The colour stays on React Flow's own
62
+ // `--xy-edge-stroke` variables, which `CANVAS_THEME` already themes for
63
+ // light and dark — restating a hex here would be a third place for the
64
+ // canvas's palette to live, and the one that forgets dark mode.
65
+ strokeWidth: selected ? 2.5 : (style?.strokeWidth ?? 1.5),
66
+ },
67
+ // Wider than the 20px default. This is the invisible path that catches
68
+ // the click, and the whole complaint was that clicking the line did
69
+ // nothing — which is at least as often "missed it" as "nothing happened".
70
+ interactionWidth: 26 }), _jsx(EdgeLabelRenderer, { children: _jsx("div", { className: "nodrag nopan", style: {
71
+ position: 'absolute',
72
+ transform: `translate(-50%, -140%) translate(${labelX}px, ${labelY}px)`,
73
+ // The label layer has no pointer events by default, which is what
74
+ // keeps edge labels from eating drags. This wrapper does not want
75
+ // them either — only the button inside it does.
76
+ pointerEvents: 'none',
77
+ }, children: _jsx(AnimatePresence, { children: offered && (_jsx(motion.div
78
+ // Opacity and scale ONLY. Motion composes the entire `transform`
79
+ // property from the values it animates, so a translate written
80
+ // here would be overwritten the moment `scale` moves — which is
81
+ // exactly how this control ended up at the origin, under a node.
82
+ // The translate lives on the parent, where nothing composes it.
83
+ , {
84
+ // Opacity and scale ONLY. Motion composes the entire `transform`
85
+ // property from the values it animates, so a translate written
86
+ // here would be overwritten the moment `scale` moves — which is
87
+ // exactly how this control ended up at the origin, under a node.
88
+ // The translate lives on the parent, where nothing composes it.
89
+ style: { pointerEvents: 'all' }, initial: reduced ? false : { opacity: 0, scale: 0.6 }, animate: { opacity: 1, scale: 1 }, exit: reduced ? { opacity: 1, scale: 1 } : { opacity: 0, scale: 0.6 }, transition: reduced ? { duration: 0 } : APPEAR, children: _jsx(Button, { variant: "outline", size: "icon",
90
+ // Round, small, and red on hover — the shape says "close this
91
+ // one thing" and the colour arrives only once the pointer has
92
+ // committed, so a row of edges is not a row of red buttons.
93
+ className: "h-6 w-6 rounded-full shadow-sm transition-colors hover:border-rose-400 hover:bg-rose-50 hover:text-rose-600 dark:hover:border-rose-800 dark:hover:bg-rose-950 dark:hover:text-rose-400", "aria-label": `Remove the connection from ${fromLabel || source} to ${toLabel || target}`, onClick: () => {
94
+ // Deselected first, so the button is gone by the time the
95
+ // graph re-renders. Without this the id stays in React
96
+ // Flow's selection and a *new* edge later given the same id
97
+ // — same two nodes rewired — would come back already
98
+ // selected, with an × floating over a connection nobody
99
+ // clicked.
100
+ setEdges((edges) => edges.map((edge) => (edge.id === id ? { ...edge, selected: false } : edge)));
101
+ onDisconnect({ from: source, to: target });
102
+ }, children: _jsx(X, { size: 12 }) }) })) }) }) })] }));
103
+ }
104
+ /**
105
+ * Declared once, at module scope, for the same reason `workflowNodeTypes` is.
106
+ *
107
+ * React Flow compares `edgeTypes` by identity and warns — then remounts every
108
+ * edge — when it changes. An object literal written inline in the screen is a new
109
+ * object on every render, so the canvas would tear down and rebuild every
110
+ * connection on each keystroke in the name field.
111
+ */
112
+ export const workflowEdgeTypes = { workflowEdge: WorkflowEdgeBody };
@@ -18,6 +18,15 @@ import { type WorkflowProblem } from './validate';
18
18
  * measured anything — on a graph loaded from the server, or one somebody just
19
19
  * pasted — and a layout that waits for measurements draws every node stacked at
20
20
  * the origin for one frame, which reads as a broken canvas.
21
+ *
22
+ * **Re-exported from core rather than declared here**, and that is the point of
23
+ * the change that moved them. The server also writes positions —
24
+ * `adoptConnector` wraps a connector into a graph and has to space its columns —
25
+ * and while these numbers lived only in this file it had nothing to derive from,
26
+ * so it used a literal that was four pixels narrower than the node. Every
27
+ * adopted graph drew its boxes overlapping. Sharing the constant is what stops
28
+ * the two from being able to disagree; the names stay `NODE_WIDTH`/`NODE_HEIGHT`
29
+ * because they are part of this package's published `/workflow` surface.
21
30
  */
22
31
  export declare const NODE_WIDTH = 224;
23
32
  export declare const NODE_HEIGHT = 80;
@@ -53,7 +62,17 @@ export interface NodeDescriptions {
53
62
  }
54
63
  export declare function toFlowNodes(nodes: WorkflowNode[], edges: WorkflowEdge[], describe: NodeDescriptions, problemsFor: Map<string, WorkflowProblem[]>, runFor: Map<string, WorkflowRunNode>): WorkflowFlowNode[];
55
64
  export declare function defaultLabel(kind: WorkflowNodeKind): string;
56
- export declare function toFlowEdges(edges: WorkflowEdge[], nodes: WorkflowNode[], brokenEdgeIds: ReadonlySet<string>): WorkflowFlowEdge[];
65
+ /**
66
+ * The stored edges, as React Flow draws them.
67
+ *
68
+ * `flowing` is the set of edge ids whose upstream node is running right now, and
69
+ * it is a parameter rather than something derived here because this module knows
70
+ * nothing about runs. It is also **the caller's job to pass an empty set when
71
+ * motion is unwanted** — see `WorkflowCanvas`, which reads `prefers-reduced-motion`
72
+ * — because React Flow's `animated` flag is a CSS keyframe in its own stylesheet
73
+ * and there is nothing this package can turn off from the outside.
74
+ */
75
+ export declare function toFlowEdges(edges: WorkflowEdge[], nodes: WorkflowNode[], brokenEdgeIds: ReadonlySet<string>, flowing?: ReadonlySet<string>): WorkflowFlowEdge[];
57
76
  /**
58
77
  * Lay the graph out left to right, one column per dependency depth.
59
78
  *
@@ -99,6 +118,25 @@ export declare function layout(nodes: WorkflowNode[], edges: WorkflowEdge[]): Wo
99
118
  * who then drags a node has authored a layout, and that one is saved.
100
119
  */
101
120
  export declare function layoutIfUnarranged(nodes: WorkflowNode[], edges: WorkflowEdge[]): WorkflowNode[];
121
+ /**
122
+ * Which edges should show their work moving, and when that is none of them.
123
+ *
124
+ * An edge flows while the node feeding it is running. That is the one thing a
125
+ * picture can say about a run which the per-node status list cannot: not what
126
+ * each step's outcome was, but where the work *is* right now.
127
+ *
128
+ * `reducedMotion` short-circuits to the empty set, and this function exists
129
+ * largely so that decision is a value rather than a branch inside a render.
130
+ * React Flow's `animated` is a CSS keyframe in its own stylesheet — there is no
131
+ * prop to soften it and no way to reach it from here — so the only honest
132
+ * accommodation is not to mark the edge at all. Nothing is lost by it: a running
133
+ * node still spins its own badge and the run panel still lists every step, which
134
+ * is the test for whether an animation was carrying information or decorating
135
+ * it.
136
+ */
137
+ export declare function flowingEdgeIds(edges: WorkflowEdge[], runNodes: readonly WorkflowRunNode[], options: {
138
+ reducedMotion: boolean;
139
+ }): ReadonlySet<string>;
102
140
  /**
103
141
  * Where to drop a node somebody just added.
104
142
  *
@@ -1,6 +1,6 @@
1
- import { workflowRunOrder } from '@dudousxd/nestjs-catalog/client';
1
+ import { WORKFLOW_NODE_HEIGHT, WORKFLOW_NODE_WIDTH, workflowColumnX, workflowRowY, workflowRunOrder, } from '@dudousxd/nestjs-catalog/client';
2
2
  import { MarkerType } from '@xyflow/react';
3
- import { nodeName, } from './model';
3
+ import { nodeName, unreachableNodeKind, unreachablePredicateKind, } from './model';
4
4
  import { edgeId } from './validate';
5
5
  /**
6
6
  * Turning the stored graph into what React Flow draws, and back.
@@ -19,11 +19,18 @@ import { edgeId } from './validate';
19
19
  * measured anything — on a graph loaded from the server, or one somebody just
20
20
  * pasted — and a layout that waits for measurements draws every node stacked at
21
21
  * the origin for one frame, which reads as a broken canvas.
22
+ *
23
+ * **Re-exported from core rather than declared here**, and that is the point of
24
+ * the change that moved them. The server also writes positions —
25
+ * `adoptConnector` wraps a connector into a graph and has to space its columns —
26
+ * and while these numbers lived only in this file it had nothing to derive from,
27
+ * so it used a literal that was four pixels narrower than the node. Every
28
+ * adopted graph drew its boxes overlapping. Sharing the constant is what stops
29
+ * the two from being able to disagree; the names stay `NODE_WIDTH`/`NODE_HEIGHT`
30
+ * because they are part of this package's published `/workflow` surface.
22
31
  */
23
- export const NODE_WIDTH = 224;
24
- export const NODE_HEIGHT = 80;
25
- const COLUMN_GAP = 96;
26
- const ROW_GAP = 32;
32
+ export const NODE_WIDTH = WORKFLOW_NODE_WIDTH;
33
+ export const NODE_HEIGHT = WORKFLOW_NODE_HEIGHT;
27
34
  /**
28
35
  * The second line on a node, per kind.
29
36
  *
@@ -41,7 +48,45 @@ function subtitleFor(node, describe) {
41
48
  }
42
49
  if (node.kind === 'call')
43
50
  return callSubtitle(node);
44
- return describe.transformName(node.transformId) ?? 'no transform chosen';
51
+ if (node.kind === 'if')
52
+ return ifSubtitle(node);
53
+ if (node.kind === 'transform') {
54
+ return describe.transformName(node.transformId) ?? 'no transform chosen';
55
+ }
56
+ return unreachableNodeKind(node, 'subtitleFor');
57
+ }
58
+ /**
59
+ * The test, on the face of the node.
60
+ *
61
+ * Written as the condition rather than as the variable alone, because the whole
62
+ * question somebody reads a branch to answer is "which way does this go here",
63
+ * and `CLICKHOUSE_URL` on its own does not say whether it is being tested for
64
+ * presence or for a value. The name is shown; a value never is — the node stores
65
+ * the name of a variable and this screen has no more than that.
66
+ *
67
+ * The predicate is read into a variable that admits `undefined` before it is
68
+ * narrowed, even though the type says it is always there. This runs on whatever
69
+ * a server sent, and a canvas that throws while drawing a node is a screen
70
+ * nobody can use to fix the node — a subtitle saying the gate has no test is.
71
+ */
72
+ function ifSubtitle(node) {
73
+ const predicate = node.predicate;
74
+ if (!predicate)
75
+ return 'nothing to decide on';
76
+ if (predicate.kind === 'env') {
77
+ const name = typeof predicate.envVar === 'string' ? predicate.envVar.trim() : '';
78
+ if (name.length === 0)
79
+ return 'no variable chosen';
80
+ return predicate.equals === undefined
81
+ ? `if ${name} is set`
82
+ : `if ${name} = ${predicate.equals}`;
83
+ }
84
+ if (predicate.kind === 'rowCount') {
85
+ return predicate.atLeast === 1
86
+ ? 'if any rows arrived'
87
+ : `if ${predicate.atLeast} rows or more arrived`;
88
+ }
89
+ return unreachablePredicateKind(predicate, 'ifSubtitle');
45
90
  }
46
91
  /** What a source reads from: its kind, and the connection or mode that narrows it. */
47
92
  function sourceSubtitle(node, describe) {
@@ -80,8 +125,17 @@ function ariaLabelFor(node, data, incoming, outgoing) {
80
125
  const parts = [`${node.kind} node, ${data.label}, ${data.subtitle}`];
81
126
  parts.push(incoming.length === 0 ? 'nothing feeds it' : `fed by ${incoming.join(', ')}`);
82
127
  parts.push(outgoing.length === 0 ? 'feeds nothing' : `feeds ${outgoing.join(', ')}`);
83
- if (data.run)
84
- parts.push(`last run ${data.run.status}`);
128
+ // The branch and the reason for a skip are in here as well as in the tooltip,
129
+ // because on a canvas this string is the only thing a screen reader gets — and
130
+ // "skipped" alone cannot distinguish a node a branch stood down from a node a
131
+ // failure stranded, which is the one distinction this feature adds.
132
+ if (data.run) {
133
+ const branch = data.run.branch ? `, took the ${data.run.branch} branch` : '';
134
+ const because = data.run.skippedBecause === 'branch-not-taken'
135
+ ? ', because it is on the branch that was not taken, so it committed nothing'
136
+ : '';
137
+ parts.push(`last run ${data.run.status}${branch}${because}`);
138
+ }
85
139
  for (const problem of data.problems)
86
140
  parts.push(problem.message);
87
141
  return parts.join('. ');
@@ -133,31 +187,97 @@ export function defaultLabel(kind) {
133
187
  return 'Sink';
134
188
  if (kind === 'call')
135
189
  return 'Call';
136
- return 'Transform';
190
+ if (kind === 'if')
191
+ return 'If';
192
+ if (kind === 'transform')
193
+ return 'Transform';
194
+ return unreachableNodeKind(kind, 'defaultLabel');
137
195
  }
138
- export function toFlowEdges(edges, nodes, brokenEdgeIds) {
196
+ /**
197
+ * How a branch is drawn: a word on the wire, and a colour that means it.
198
+ *
199
+ * A **label**, not only a colour, and that is the accessibility half rather than
200
+ * a stylistic one — two lines leaving one box differing by hue alone are one
201
+ * line as far as a colour-blind reader is concerned, and this particular
202
+ * distinction decides which half of a pipeline runs. Emerald for the branch
203
+ * taken when the test passes and zinc for the other reads as "the positive one
204
+ * and the fallback", which is what a then and an else are.
205
+ *
206
+ * Kept as a `Record` keyed by the label union so a third branch label added to
207
+ * core without a line here is a type error rather than an unlabelled grey wire.
208
+ */
209
+ const BRANCH_STYLE = {
210
+ else: { stroke: '#a1a1aa', text: '#71717a' },
211
+ // biome-ignore lint/suspicious/noThenProperty: the rule guards against an object being mistaken for a thenable by `await`; the key here is one of core's two branch labels and this record is only ever indexed by one of them, never awaited nor returned from anything async. Keying it by the label union is what makes a third label a compile error rather than an unlabelled grey wire, which is the whole reason it is a record and not a function.
212
+ then: { stroke: '#10b981', text: '#059669' },
213
+ };
214
+ /**
215
+ * The stored edges, as React Flow draws them.
216
+ *
217
+ * `flowing` is the set of edge ids whose upstream node is running right now, and
218
+ * it is a parameter rather than something derived here because this module knows
219
+ * nothing about runs. It is also **the caller's job to pass an empty set when
220
+ * motion is unwanted** — see `WorkflowCanvas`, which reads `prefers-reduced-motion`
221
+ * — because React Flow's `animated` flag is a CSS keyframe in its own stylesheet
222
+ * and there is nothing this package can turn off from the outside.
223
+ */
224
+ export function toFlowEdges(edges, nodes, brokenEdgeIds, flowing = new Set()) {
139
225
  const labelOf = new Map(nodes.map((node) => [node.id, nodeName(node)]));
140
- return edges.map((edge) => {
141
- const from = labelOf.get(edge.from) ?? edge.from;
142
- const to = labelOf.get(edge.to) ?? edge.to;
143
- const id = edgeId(edge);
144
- const broken = brokenEdgeIds.has(id);
145
- return {
146
- id,
147
- source: edge.from,
148
- target: edge.to,
149
- type: 'smoothstep',
150
- // An arrowhead, because "the output of this feeds that" is directional and
151
- // a plain line says only that two nodes are related.
152
- markerEnd: { type: MarkerType.ArrowClosed, width: 14, height: 14 },
153
- ariaLabel: `the output of ${from} feeds ${to}${broken ? ', part of a loop' : ''}`,
154
- // An inline stroke rather than a class, because the stroke lands on an
155
- // SVG `<path>` React Flow owns: a Tailwind class on the edge wrapper does
156
- // not reach it, and inventing a stylesheet rule would mean this package
157
- // ships CSS for the first time just to colour one line.
158
- style: broken ? { stroke: '#ef4444', strokeWidth: 2 } : undefined,
159
- };
160
- });
226
+ return edges.map((edge) => toFlowEdge(edge, {
227
+ from: labelOf.get(edge.from) ?? edge.from,
228
+ to: labelOf.get(edge.to) ?? edge.to,
229
+ broken: brokenEdgeIds.has(edgeId(edge)),
230
+ flowing: flowing.has(edgeId(edge)),
231
+ }));
232
+ }
233
+ /**
234
+ * One wire, drawn.
235
+ *
236
+ * Split out of the `map` above so the styling decisions — arrowhead, branch
237
+ * colour, the red a loop wears — sit in one function that is about a wire,
238
+ * rather than in a closure that is also about resolving names.
239
+ */
240
+ function toFlowEdge(edge, context) {
241
+ const branch = edge.branch === undefined ? undefined : BRANCH_STYLE[edge.branch];
242
+ return {
243
+ id: edgeId(edge),
244
+ source: edge.from,
245
+ target: edge.to,
246
+ // This package's own edge rather than the built-in `smoothstep`, because
247
+ // clicking a connection has to offer to remove it. See `workflow/edges.tsx`.
248
+ type: 'workflowEdge',
249
+ // The names, not the ids: they become the accessible name of the delete
250
+ // button, which has to say which connection it removes in the words that
251
+ // are on the canvas.
252
+ data: { fromLabel: context.from, toLabel: context.to },
253
+ // Marching ants while the node feeding this edge is actually running. The
254
+ // one thing a canvas can say about a run that a list of statuses cannot:
255
+ // where the work currently is.
256
+ animated: context.flowing,
257
+ // An arrowhead, because "the output of this feeds that" is directional and
258
+ // a plain line says only that two nodes are related.
259
+ markerEnd: { type: MarkerType.ArrowClosed, width: 14, height: 14 },
260
+ label: edge.branch,
261
+ labelStyle: branch ? { fill: branch.text, fontSize: 10, fontWeight: 600 } : undefined,
262
+ // The word sits on the wire, so it takes the canvas behind it rather than a
263
+ // filled plate that would blank out whatever the wire crosses.
264
+ labelBgStyle: branch ? { fill: 'transparent' } : undefined,
265
+ ariaLabel: `the output of ${context.from} feeds ${context.to}${edge.branch ? `, on the ${edge.branch} branch` : ''}${context.broken ? ', part of a loop' : ''}`,
266
+ // An inline stroke rather than a class, because the stroke lands on an
267
+ // SVG `<path>` React Flow owns: a Tailwind class on the edge wrapper does
268
+ // not reach it, and inventing a stylesheet rule would mean this package
269
+ // ships CSS for the first time just to colour one line.
270
+ //
271
+ // Broken wins over branch: a wire in a loop is a graph that will not run at
272
+ // all, which is a bigger fact than which side of a decision it is on.
273
+ style: edgeStroke(context, branch),
274
+ };
275
+ }
276
+ /** Red for a loop, the branch's colour for a branch, React Flow's default otherwise. */
277
+ function edgeStroke(context, branch) {
278
+ if (context.broken)
279
+ return { stroke: '#ef4444', strokeWidth: 2 };
280
+ return branch ? { stroke: branch.stroke, strokeWidth: 2 } : undefined;
161
281
  }
162
282
  /** Who feeds each node, by node id. Every node gets an entry, most of them empty. */
163
283
  function feedersByNode(nodes, edges) {
@@ -258,13 +378,7 @@ export function layout(nodes, edges) {
258
378
  const placed = node.kind === 'sink' ? sinkColumn : (column.get(node.id) ?? 0);
259
379
  const row = rows.get(placed) ?? 0;
260
380
  rows.set(placed, row + 1);
261
- return {
262
- ...node,
263
- position: {
264
- x: placed * (NODE_WIDTH + COLUMN_GAP),
265
- y: row * (NODE_HEIGHT + ROW_GAP),
266
- },
267
- };
381
+ return { ...node, position: { x: workflowColumnX(placed), y: workflowRowY(row) } };
268
382
  });
269
383
  }
270
384
  /**
@@ -315,6 +429,30 @@ export function layoutIfUnarranged(nodes, edges) {
315
429
  }
316
430
  return arranged ? nodes : layout(nodes, edges);
317
431
  }
432
+ /**
433
+ * Which edges should show their work moving, and when that is none of them.
434
+ *
435
+ * An edge flows while the node feeding it is running. That is the one thing a
436
+ * picture can say about a run which the per-node status list cannot: not what
437
+ * each step's outcome was, but where the work *is* right now.
438
+ *
439
+ * `reducedMotion` short-circuits to the empty set, and this function exists
440
+ * largely so that decision is a value rather than a branch inside a render.
441
+ * React Flow's `animated` is a CSS keyframe in its own stylesheet — there is no
442
+ * prop to soften it and no way to reach it from here — so the only honest
443
+ * accommodation is not to mark the edge at all. Nothing is lost by it: a running
444
+ * node still spins its own badge and the run panel still lists every step, which
445
+ * is the test for whether an animation was carrying information or decorating
446
+ * it.
447
+ */
448
+ export function flowingEdgeIds(edges, runNodes, options) {
449
+ if (options.reducedMotion)
450
+ return new Set();
451
+ const running = new Set(runNodes.filter((node) => node.status === 'running').map((node) => node.nodeId));
452
+ if (running.size === 0)
453
+ return new Set();
454
+ return new Set(edges.filter((edge) => running.has(edge.from)).map((edge) => edgeId(edge)));
455
+ }
318
456
  /**
319
457
  * Where to drop a node somebody just added.
320
458
  *
@@ -328,8 +466,8 @@ export function nextPosition(nodes) {
328
466
  const xs = nodes.map((node) => node.position?.x ?? 0);
329
467
  const right = Math.max(...xs);
330
468
  const inColumn = xs.filter((x) => x === right);
331
- return {
332
- x: right + NODE_WIDTH + COLUMN_GAP,
333
- y: inColumn.length * (NODE_HEIGHT + ROW_GAP),
334
- };
469
+ // `workflowColumnX(1)` is one whole column — the node's width plus the gap —
470
+ // added to wherever the rightmost node happens to be, which need not sit on a
471
+ // column boundary once somebody has dragged things around.
472
+ return { x: right + workflowColumnX(1), y: workflowRowY(inColumn.length) };
335
473
  }