@dudousxd/nestjs-catalog-react 0.20.0 → 0.22.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/dist/WorkflowCanvas.js +895 -287
- package/dist/context.d.ts +123 -1
- package/dist/context.js +17 -0
- package/dist/index.d.ts +1 -1
- package/dist/routes.d.ts +48 -0
- package/dist/routes.js +5 -0
- package/dist/workflow/canvas-menu.d.ts +161 -0
- package/dist/workflow/canvas-menu.js +359 -0
- package/dist/workflow/create.d.ts +127 -0
- package/dist/workflow/create.js +238 -0
- package/dist/workflow/menu.d.ts +73 -0
- package/dist/workflow/menu.js +174 -0
- package/dist/workflow/place.d.ts +79 -0
- package/dist/workflow/place.js +89 -0
- package/dist/workflow/removal.d.ts +27 -0
- package/dist/workflow/removal.js +81 -0
- package/package.json +2 -2
package/dist/WorkflowCanvas.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
-
import { Background, BackgroundVariant, ConnectionLineType, Controls, MiniMap,
|
|
2
|
+
import { Background, BackgroundVariant, ConnectionLineType, Controls, MiniMap, Panel, ReactFlow, ReactFlowProvider, useReactFlow, } from '@xyflow/react';
|
|
3
3
|
// React Flow ships its own stylesheet and renders as an unstyled pile of divs
|
|
4
4
|
// without it — no edges, every node at the top-left corner. Imported by the
|
|
5
5
|
// component that needs it rather than left to the host, because a missing
|
|
@@ -7,7 +7,7 @@ import { Background, BackgroundVariant, ConnectionLineType, Controls, MiniMap, N
|
|
|
7
7
|
// See src/styles.d.ts for why `tsc` tolerates this import.
|
|
8
8
|
import '@xyflow/react/dist/style.css';
|
|
9
9
|
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
|
10
|
-
import { ArrowRight, CircleAlert, CircleDashed, Code2, Database, ExternalLink, Filter, GitBranch, Info, LayoutGrid,
|
|
10
|
+
import { ArrowRight, ChevronDown, CircleAlert, CircleDashed, Code2, Database, ExternalLink, Filter, GitBranch, Info, LayoutGrid, Loader2, Maximize2, Minimize2, PanelRight, Plug, Plus, Repeat, Save, Trash2, TriangleAlert, Unplug, X, } from 'lucide-react';
|
|
11
11
|
import { AnimatePresence, motion, useReducedMotion } from 'motion/react';
|
|
12
12
|
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
13
13
|
import { connectionOptionsFor } from './ConnectionPanel';
|
|
@@ -25,13 +25,18 @@ import { Select, SelectField } from './ui/select';
|
|
|
25
25
|
import { Sheet } from './ui/sheet';
|
|
26
26
|
import { Switch } from './ui/switch';
|
|
27
27
|
import { Tooltip, TooltipProvider } from './ui/tooltip';
|
|
28
|
+
import { buildCanvasMenu, deleteCost, } from './workflow/canvas-menu';
|
|
29
|
+
import { graphWithNodeBetween, newEdge, newKindsFrom, newNodeOfKind, nodeBetween, uniqueName, } from './workflow/create';
|
|
28
30
|
import { WorkflowEdgeProvider, workflowEdgeTypes } from './workflow/edges';
|
|
29
|
-
import {
|
|
31
|
+
import { defaultLabel, describeFilterPredicate, flowingEdgeIds, layout, layoutIfUnarranged, nextPosition, toFlowEdges, toFlowNodes, } from './workflow/graph';
|
|
30
32
|
import { HistoryControls, keepKnown, namesOf, nodeEditAction, reverted, snapshotOf, undone, useUndoShortcut, useUnsavedGuard, withEdit, } from './workflow/history';
|
|
31
33
|
import { PublishControls, RunControls, SchedulePanel, ShrinkRefusalNote, WorkflowStatusBadge, } from './workflow/lifecycle';
|
|
34
|
+
import { CanvasContextMenu, NodeActionsToolbar } from './workflow/menu';
|
|
32
35
|
import { WORKFLOW_BRANCH_LABELS, WORKFLOW_FILTER_MAX_DEPTH, WORKFLOW_FILTER_MAX_VALUES, WORKFLOW_FILTER_OPERATORS, WORKFLOW_NODE_KINDS, callableWorkflowBlock, describeDurability, isWorkflowBranchLabel, isWorkflowFilterOperator, isWorkflowFilterPredicateKind, isWorkflowNodeKind, isWorkflowPredicateKind, newLocalId, nodeName, producedTypes, unreachableFilterPredicateKind, unreachableNodeKind, unreachablePredicateKind, workflowNarrowedTypes, } from './workflow/model';
|
|
33
36
|
import { WORKFLOW_NAME } from './workflow/name';
|
|
34
37
|
import { WorkflowNodeProvider, workflowNodeTypes } from './workflow/nodes';
|
|
38
|
+
import { freeSpot, placeNextTo } from './workflow/place';
|
|
39
|
+
import { removeNodes, wiresOn } from './workflow/removal';
|
|
35
40
|
import { RunsAsPanel } from './workflow/runs';
|
|
36
41
|
import { canConnect, edgeId, hasBlockingProblem, problemsByNode, validateWorkflow, } from './workflow/validate';
|
|
37
42
|
import { PendingWireLine, WiringHint, useClickWiring, } from './workflow/wiring';
|
|
@@ -76,11 +81,28 @@ const CHROME = {
|
|
|
76
81
|
side: 28,
|
|
77
82
|
/** The rail's width plus its gutter, when it is open. */
|
|
78
83
|
rail: 336,
|
|
84
|
+
/**
|
|
85
|
+
* The top inset once the workflow card is collapsed to its head.
|
|
86
|
+
*
|
|
87
|
+
* The card is the tallest thing on this screen and the only one focus mode
|
|
88
|
+
* changes the height of, so it is the only inset that moves with the mode.
|
|
89
|
+
* The dock is still at the bottom and the actions are untouched, so those two
|
|
90
|
+
* keep their numbers.
|
|
91
|
+
*/
|
|
92
|
+
topFocused: 76,
|
|
79
93
|
};
|
|
80
|
-
/**
|
|
81
|
-
|
|
94
|
+
/**
|
|
95
|
+
* {@link CHROME} as the padding `fitView` wants.
|
|
96
|
+
*
|
|
97
|
+
* Two sides move, and only two: the right, because the rail comes and goes, and
|
|
98
|
+
* the top, because focus mode collapses the card to its head. The whole reason
|
|
99
|
+
* this function exists is that a fit which ignored either would put a node under
|
|
100
|
+
* a panel — so a mode that makes the chrome smaller has to say so here, or the
|
|
101
|
+
* canvas it just bought would go unused.
|
|
102
|
+
*/
|
|
103
|
+
function chromeFitPadding(railOpen, cardCollapsed) {
|
|
82
104
|
return {
|
|
83
|
-
top: `${CHROME.top}px`,
|
|
105
|
+
top: `${cardCollapsed ? CHROME.topFocused : CHROME.top}px`,
|
|
84
106
|
bottom: `${CHROME.bottom}px`,
|
|
85
107
|
left: `${CHROME.side}px`,
|
|
86
108
|
right: `${railOpen ? CHROME.rail : CHROME.side}px`,
|
|
@@ -99,9 +121,293 @@ function chromeFitPadding(railOpen) {
|
|
|
99
121
|
* answer there: it is what hydrates into on a desktop, and a panel that appears
|
|
100
122
|
* after hydration is a worse first paint than one that was always there.
|
|
101
123
|
*/
|
|
102
|
-
function
|
|
124
|
+
function railOpenByWidth() {
|
|
103
125
|
return typeof window === 'undefined' ? true : window.innerWidth >= 1024;
|
|
104
126
|
}
|
|
127
|
+
/**
|
|
128
|
+
* Whether this is a pointer that can hover at all.
|
|
129
|
+
*
|
|
130
|
+
* The whole shrink-and-expand idea below is built on hover, and hover is not a
|
|
131
|
+
* thing every pointer has. On a touch screen there is no state between "not
|
|
132
|
+
* touching" and "touching": the first contact with a pannable minimap IS a pan,
|
|
133
|
+
* so a map that expanded on touch would turn a navigation gesture into a resize
|
|
134
|
+
* gesture and move the viewport while doing it. There is no version of
|
|
135
|
+
* hover-to-expand that works there, so the honest answer is not to shrink at
|
|
136
|
+
* all — a finger gets the map exactly as it is today.
|
|
137
|
+
*
|
|
138
|
+
* `pointer: fine` as well as `hover: hover`, because the pair is what excludes a
|
|
139
|
+
* TV remote and a Wii-style pointer: those report `hover: hover` with a coarse
|
|
140
|
+
* pointer, and a 96px target you have to wave at is worse than a 200px one.
|
|
141
|
+
*
|
|
142
|
+
* Every failure answers `false` — no window, no `matchMedia` (jsdom does not
|
|
143
|
+
* implement it), or a throw. `false` means "do not shrink", which is the answer
|
|
144
|
+
* that takes nothing away, and that is the same rule
|
|
145
|
+
* {@link focusModeAtMount} follows for the same reason.
|
|
146
|
+
*/
|
|
147
|
+
const HOVER_POINTER_QUERY = '(hover: hover) and (pointer: fine)';
|
|
148
|
+
function hoverCapablePointer() {
|
|
149
|
+
if (typeof window === 'undefined' || typeof window.matchMedia !== 'function')
|
|
150
|
+
return false;
|
|
151
|
+
try {
|
|
152
|
+
return window.matchMedia(HOVER_POINTER_QUERY).matches;
|
|
153
|
+
}
|
|
154
|
+
catch {
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* How much of its size the overview keeps while focus mode has the screen.
|
|
160
|
+
*
|
|
161
|
+
* React Flow's minimap is 200×150, and 0.48 of that is 96×72 — whole pixels on
|
|
162
|
+
* both axes, which a rounder-looking 0.5 would also give but 0.45 would not. A
|
|
163
|
+
* fractional height puts the mask's bottom edge on a half-pixel and the
|
|
164
|
+
* viewport box picks up a grey seam that reads as a border it does not have.
|
|
165
|
+
*
|
|
166
|
+
* WHAT SURVIVES AT THIS SIZE, which is the only question that matters — a
|
|
167
|
+
* shrunk minimap that reads as decoration has taken the navigation aid away and
|
|
168
|
+
* kept the pixels. At 96×72 the map still carries the one thing it is for: WHERE
|
|
169
|
+
* THE VIEWPORT IS IN THE GRAPH. That is drawn as a hole in a tinted mask, so it
|
|
170
|
+
* is an area rather than a detail, and area survives scaling — the box keeps its
|
|
171
|
+
* position and its proportion of the whole, which is the entire "am I looking at
|
|
172
|
+
* the middle of this graph or the far edge" question. The node dots keep their
|
|
173
|
+
* kind colours (see {@link miniMapColor}), so a cluster and a lone box on the
|
|
174
|
+
* other side of the graph are still two different pictures.
|
|
175
|
+
*
|
|
176
|
+
* WHAT IS SACRIFICED: reading an individual node's position precisely, and any
|
|
177
|
+
* hope of telling two adjacent nodes apart. Both are recovered by hovering, and
|
|
178
|
+
* neither was ever a gesture here — no `onNodeClick` is passed to the minimap,
|
|
179
|
+
* so a dot has never been a target.
|
|
180
|
+
*
|
|
181
|
+
* A single scale rather than a smaller `style={{ width, height }}`, and that is
|
|
182
|
+
* NOT a shortcut — see {@link FocusMiniMap} for why it is the only version of
|
|
183
|
+
* this that cannot make a drag jump under the finger.
|
|
184
|
+
*
|
|
185
|
+
* SPELLED AS A LITERAL CLASS, and it has to be. This package ships as compiled
|
|
186
|
+
* JS and the console's stylesheet points Tailwind at `dist/**\/*.js` to find the
|
|
187
|
+
* classes in it. Tailwind emits only what it can SEE in that text, so a class
|
|
188
|
+
* built as `scale-[${scale}]` survives compilation as an un-evaluated template
|
|
189
|
+
* and the rule is never generated — no error, no warning, and a focus mode
|
|
190
|
+
* whose minimap simply never shrinks. Hence one string, and the arithmetic in
|
|
191
|
+
* this comment rather than in the code: 200×150 × 0.48 = 96×72.
|
|
192
|
+
*/
|
|
193
|
+
const MINIMAP_FOCUSED_CLASS = 'scale-[0.48]';
|
|
194
|
+
/* ---------------------------------------------------------------------------
|
|
195
|
+
* Focus mode.
|
|
196
|
+
* ------------------------------------------------------------------------- */
|
|
197
|
+
/**
|
|
198
|
+
* The key focus mode is remembered under, and — deliberately — `sessionStorage`.
|
|
199
|
+
*
|
|
200
|
+
* ## Why it is remembered at all
|
|
201
|
+
*
|
|
202
|
+
* A mode somebody has to re-enter after every reload is a mode nobody uses. The
|
|
203
|
+
* person this exists for is the one drawing a forty-node graph, and that person
|
|
204
|
+
* reloads: a deploy lands, a query is retried, a tab is restored. Losing the
|
|
205
|
+
* layout each time makes the gesture a novelty.
|
|
206
|
+
*
|
|
207
|
+
* ## Why it is not `localStorage`
|
|
208
|
+
*
|
|
209
|
+
* This mode HIDES things — the workflow picker, the name field, the description.
|
|
210
|
+
* A preference that hides controls and is restored silently a week later is
|
|
211
|
+
* somebody opening the console, finding a screen with fewer controls than they
|
|
212
|
+
* remember, and having no way to connect that to a keypress from last Tuesday.
|
|
213
|
+
* That is the exact confusion a persisted hiding-mode causes, and it is worse
|
|
214
|
+
* than re-pressing a key.
|
|
215
|
+
*
|
|
216
|
+
* `sessionStorage` is the honest middle: the mode lives exactly as long as the
|
|
217
|
+
* TAB that chose it. A reload keeps it, because a reload is the same working
|
|
218
|
+
* session and is usually not even deliberate. A new tab, or tomorrow, starts
|
|
219
|
+
* with the chrome present. Nobody inherits a hidden control from a decision they
|
|
220
|
+
* cannot remember making.
|
|
221
|
+
*
|
|
222
|
+
* It is per-tab rather than per-workflow on purpose: focus is a statement about
|
|
223
|
+
* how somebody wants to WORK, not about a particular graph, and re-entering it
|
|
224
|
+
* on every switch of the picker would make it feel like a property of the
|
|
225
|
+
* document.
|
|
226
|
+
*/
|
|
227
|
+
const FOCUS_STORAGE_KEY = 'catalog.workflowCanvas.focus';
|
|
228
|
+
/**
|
|
229
|
+
* Whether focus mode was on in this tab.
|
|
230
|
+
*
|
|
231
|
+
* Every failure answers `false` — no window (a host rendering this on a server),
|
|
232
|
+
* no storage (Safari's private mode throws on `sessionStorage` access rather
|
|
233
|
+
* than returning null), or anything stored that is not exactly `'1'`. The chrome
|
|
234
|
+
* being present is the state that hides nothing, so it is the only safe answer
|
|
235
|
+
* to "I could not tell".
|
|
236
|
+
*/
|
|
237
|
+
function focusModeAtMount() {
|
|
238
|
+
if (typeof window === 'undefined')
|
|
239
|
+
return false;
|
|
240
|
+
try {
|
|
241
|
+
return window.sessionStorage.getItem(FOCUS_STORAGE_KEY) === '1';
|
|
242
|
+
}
|
|
243
|
+
catch {
|
|
244
|
+
return false;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Whether the details rail starts on screen, once focus mode has had its say.
|
|
249
|
+
*
|
|
250
|
+
* A mount that restores focus (see {@link focusModeAtMount}) has to start with
|
|
251
|
+
* the rail away, or a reload puts back the one panel the mode had just taken and
|
|
252
|
+
* focus arrives half-applied. Measured in a browser before this existed: press
|
|
253
|
+
* F, reload, and the rail was open again with the toggle still reading "Turn off
|
|
254
|
+
* focus mode" — a screen making two claims about itself.
|
|
255
|
+
*/
|
|
256
|
+
function railOpenByDefault() {
|
|
257
|
+
return !focusModeAtMount() && railOpenByWidth();
|
|
258
|
+
}
|
|
259
|
+
/** Remember it, or fail silently — a mode is not worth an exception. */
|
|
260
|
+
function rememberFocusMode(on) {
|
|
261
|
+
if (typeof window === 'undefined')
|
|
262
|
+
return;
|
|
263
|
+
try {
|
|
264
|
+
window.sessionStorage.setItem(FOCUS_STORAGE_KEY, on ? '1' : '0');
|
|
265
|
+
}
|
|
266
|
+
catch {
|
|
267
|
+
// A browser that refuses storage still gets the mode, for this render.
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* The key that toggles focus mode.
|
|
272
|
+
*
|
|
273
|
+
* A bare letter rather than a chord, because this is a drawing surface and the
|
|
274
|
+
* hand that would reach for a modifier is the hand on the pointer. `f` is the
|
|
275
|
+
* mnemonic and nothing else on this screen claims it: React Flow binds only
|
|
276
|
+
* Delete/Backspace and the arrows, and Escape already means "put the half-drawn
|
|
277
|
+
* wire away" (see `workflow/wiring.tsx`), which is why this is not Escape.
|
|
278
|
+
*
|
|
279
|
+
* Discoverable rather than folklore: the toggle renders the letter beside its
|
|
280
|
+
* icon and its tooltip names it, so the shortcut is learnable from the control
|
|
281
|
+
* it duplicates instead of from a changelog.
|
|
282
|
+
*/
|
|
283
|
+
const FOCUS_SHORTCUT = 'f';
|
|
284
|
+
/**
|
|
285
|
+
* Whether a keypress belongs to whatever the person is typing into.
|
|
286
|
+
*
|
|
287
|
+
* The failure this prevents is specific and would be reported as "the panels
|
|
288
|
+
* vanish while I name a node": this screen is covered in text fields — the name
|
|
289
|
+
* field, the inspector's config editor, the transform's code surface — and a
|
|
290
|
+
* bare-letter shortcut that did not ask would fire on the `f` of "fleet".
|
|
291
|
+
*
|
|
292
|
+
* Narrowed with `instanceof` rather than by reading `tagName` off an `EventTarget`,
|
|
293
|
+
* because a target can be a document or a window and neither has one.
|
|
294
|
+
* `isContentEditable` covers the code editor, which is a `div`.
|
|
295
|
+
*/
|
|
296
|
+
function typingInto(target) {
|
|
297
|
+
if (!(target instanceof HTMLElement))
|
|
298
|
+
return false;
|
|
299
|
+
if (target.isContentEditable)
|
|
300
|
+
return true;
|
|
301
|
+
return (target instanceof HTMLInputElement ||
|
|
302
|
+
target instanceof HTMLTextAreaElement ||
|
|
303
|
+
target instanceof HTMLSelectElement);
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Whether the chrome is compacted so the graph gets the screen, and the one
|
|
307
|
+
* gesture that changes it.
|
|
308
|
+
*
|
|
309
|
+
* ## What the mode does, and what it deliberately does not
|
|
310
|
+
*
|
|
311
|
+
* ON: the workflow card collapses to its head, the node dock drops its labels
|
|
312
|
+
* (the form it already takes on a phone — see `AddButton` — rather than a second
|
|
313
|
+
* compact form invented for this), and the rail goes away.
|
|
314
|
+
*
|
|
315
|
+
* OFF-LIMITS: the action cluster. That is not an oversight, it is the reason the
|
|
316
|
+
* mode is safe. Every signal on this screen that prevents a mistake lives in that
|
|
317
|
+
* cluster or hangs off it — Save doubles as the unsaved indicator, the refusal
|
|
318
|
+
* notes appear beneath the button that caused them, the shrink refusal with its
|
|
319
|
+
* acknowledge control is one of those notes, and the rail toggle carries the
|
|
320
|
+
* problem count and its colour while the rail is away. It is also the smallest of
|
|
321
|
+
* the three groups, so hiding it would buy the least canvas for the most risk.
|
|
322
|
+
* What is left in focus is a graph plus the things that can tell you the graph is
|
|
323
|
+
* wrong.
|
|
324
|
+
*
|
|
325
|
+
* ## Why one gesture rather than three
|
|
326
|
+
*
|
|
327
|
+
* Because the ask was "compactar os menus" for "real estate", and real estate is
|
|
328
|
+
* a property of the whole screen. Three independent collapses is three decisions
|
|
329
|
+
* and six states to be in; a person who wants the room wants the room. The rail
|
|
330
|
+
* keeps its own toggle because it had one before this and closing it alone is a
|
|
331
|
+
* legitimate smaller wish.
|
|
332
|
+
*
|
|
333
|
+
* ## Why the rail is passed in rather than owned here
|
|
334
|
+
*
|
|
335
|
+
* Because it existed first and is still operable on its own. This hook borrows
|
|
336
|
+
* it for the duration of the mode and gives it back; it does not become the
|
|
337
|
+
* rail's owner, which is what taking the `useState` would have meant.
|
|
338
|
+
*/
|
|
339
|
+
function useFocusMode(railOpen, setRailOpen) {
|
|
340
|
+
const [focused, setFocused] = useState(focusModeAtMount);
|
|
341
|
+
/**
|
|
342
|
+
* Whether the rail was open before focus took it away.
|
|
343
|
+
*
|
|
344
|
+
* A ref rather than state: nothing renders from it, and leaving focus should
|
|
345
|
+
* put the screen back the way it was found rather than assert a default. A
|
|
346
|
+
* person who had closed the rail themselves and then used focus would
|
|
347
|
+
* otherwise get a panel they never asked for on the way out.
|
|
348
|
+
*
|
|
349
|
+
* Seeded from the WIDTH rather than from `railOpen`, and the two differ in
|
|
350
|
+
* exactly one case: a mount that restored focus, where `railOpen` is already
|
|
351
|
+
* false because focus put it there. Seeding from it would mean leaving focus
|
|
352
|
+
* after a reload left the rail away too — restoring a state that focus itself
|
|
353
|
+
* created rather than the one it displaced.
|
|
354
|
+
*/
|
|
355
|
+
const railBeforeFocus = useRef(railOpenByWidth());
|
|
356
|
+
const toggleFocus = useCallback(() => {
|
|
357
|
+
const next = !focused;
|
|
358
|
+
rememberFocusMode(next);
|
|
359
|
+
if (next)
|
|
360
|
+
railBeforeFocus.current = railOpen;
|
|
361
|
+
setRailOpen(next ? false : railBeforeFocus.current);
|
|
362
|
+
setFocused(next);
|
|
363
|
+
}, [focused, railOpen, setRailOpen]);
|
|
364
|
+
/**
|
|
365
|
+
* The keyboard way in and out. See {@link FOCUS_SHORTCUT}.
|
|
366
|
+
*
|
|
367
|
+
* On `window` rather than on the canvas container, because the point of the
|
|
368
|
+
* shortcut is that it works while the hands are on the graph — and React
|
|
369
|
+
* Flow's pane is not a focusable element, so a container-scoped handler would
|
|
370
|
+
* only fire after somebody had tabbed to something.
|
|
371
|
+
*
|
|
372
|
+
* Every modifier is refused rather than ignored: `Ctrl+F` is find, `Cmd+F` is
|
|
373
|
+
* find, and a shortcut that swallowed either would be a bug reported as "the
|
|
374
|
+
* browser's search is broken on this screen".
|
|
375
|
+
*/
|
|
376
|
+
useEffect(() => {
|
|
377
|
+
function onKeyDown(event) {
|
|
378
|
+
if (event.altKey || event.ctrlKey || event.metaKey || event.shiftKey)
|
|
379
|
+
return;
|
|
380
|
+
if (event.key.toLowerCase() !== FOCUS_SHORTCUT)
|
|
381
|
+
return;
|
|
382
|
+
if (typingInto(event.target))
|
|
383
|
+
return;
|
|
384
|
+
event.preventDefault();
|
|
385
|
+
toggleFocus();
|
|
386
|
+
}
|
|
387
|
+
window.addEventListener('keydown', onKeyDown);
|
|
388
|
+
return () => window.removeEventListener('keydown', onKeyDown);
|
|
389
|
+
}, [toggleFocus]);
|
|
390
|
+
return { focused, toggleFocus };
|
|
391
|
+
}
|
|
392
|
+
/**
|
|
393
|
+
* Whether the workflow card actually folds — because focus mode REFUSES to fold
|
|
394
|
+
* it while the graph has no name.
|
|
395
|
+
*
|
|
396
|
+
* The one place this mode could become a trap. Save is disabled on an empty name
|
|
397
|
+
* (see `CanvasActions`), and the field that fills it in is inside the card — so a
|
|
398
|
+
* focus mode that collapsed the card unconditionally would leave somebody who had
|
|
399
|
+
* just picked "New workflow" with a dead Save button, a tooltip about a field
|
|
400
|
+
* they cannot see, and no way to connect the two.
|
|
401
|
+
*
|
|
402
|
+
* So the card is chrome that is quiet when it has nothing to report and asserts
|
|
403
|
+
* itself when it does: it stays open, in focus mode, exactly while the only
|
|
404
|
+
* control that can unblock Save is the one it holds. {@link FocusToggle} says so
|
|
405
|
+
* rather than appearing broken, and `WorkflowCard` additionally declines to fold
|
|
406
|
+
* while the caret is still in the field.
|
|
407
|
+
*/
|
|
408
|
+
function focusCollapsesTheCard(focused, draftName) {
|
|
409
|
+
return focused && draftName.trim().length > 0;
|
|
410
|
+
}
|
|
105
411
|
/**
|
|
106
412
|
* Every kind of node, and how it is offered.
|
|
107
413
|
*
|
|
@@ -255,92 +561,6 @@ function nextSelection(current, changes) {
|
|
|
255
561
|
}
|
|
256
562
|
return next;
|
|
257
563
|
}
|
|
258
|
-
/**
|
|
259
|
-
* A fresh node of one kind, carrying only the fields that kind has.
|
|
260
|
-
*
|
|
261
|
-
* Built per kind rather than as one shape with optional fields, because the
|
|
262
|
-
* executable model is a discriminated union: a source carries a source kind and
|
|
263
|
-
* a config, a transform carries a transform, a sink carries the type it commits,
|
|
264
|
-
* and nothing carries a field belonging to another kind.
|
|
265
|
-
*/
|
|
266
|
-
function newNodeOfKind(kind, id, position, name) {
|
|
267
|
-
if (kind === 'source') {
|
|
268
|
-
return { id, name, kind: 'source', sourceKind: 'http', config: {}, position };
|
|
269
|
-
}
|
|
270
|
-
if (kind === 'transform') {
|
|
271
|
-
return { id, name, kind: 'transform', transformId: '', position };
|
|
272
|
-
}
|
|
273
|
-
if (kind === 'call') {
|
|
274
|
-
// Both empty, and the graph is invalid until they are not — deliberately.
|
|
275
|
-
// There is no list of workflows to default from (see `CallableWorkflowRef`
|
|
276
|
-
// in core), and defaulting a *version* to "1" would be the one guess that
|
|
277
|
-
// matters: it would silently pin whichever code happens to be registered as
|
|
278
|
-
// version 1 in whatever deployment this graph is promoted into.
|
|
279
|
-
return { id, name, kind: 'call', callName: '', callVersion: '', config: {}, position };
|
|
280
|
-
}
|
|
281
|
-
if (kind === 'if') {
|
|
282
|
-
// No variable, so the graph is invalid until somebody names one. There is
|
|
283
|
-
// nothing to guess: which variable tells this deployment apart from another
|
|
284
|
-
// is the entire content of the node, and a default would be a decision the
|
|
285
|
-
// graph appears to make and nobody authored.
|
|
286
|
-
//
|
|
287
|
-
// The *kind* of test does get a default, and it is the deployment one,
|
|
288
|
-
// because a predicate has to be one of them and an empty variable name is a
|
|
289
|
-
// gate that visibly refuses to publish. A row-count gate with its default
|
|
290
|
-
// threshold would publish happily while testing something nobody chose.
|
|
291
|
-
return { id, name, kind: 'if', predicate: { kind: 'env', envVar: '' }, position };
|
|
292
|
-
}
|
|
293
|
-
if (kind === 'filter') {
|
|
294
|
-
// One empty comparison rather than an empty `all`, and rather than nothing.
|
|
295
|
-
//
|
|
296
|
-
// Nothing is not available: the model has no "no predicate yet" state, on
|
|
297
|
-
// purpose, because a filter whose test is absent has to be given one by
|
|
298
|
-
// somebody and every default is a rule about rows nobody wrote. An empty
|
|
299
|
-
// `all` *is* representable and is refused by the validator, which is exactly
|
|
300
|
-
// why it is not the starting point — a group with no conditions keeps every
|
|
301
|
-
// row, so a filter that started that way would draw as a working node that
|
|
302
|
-
// does nothing.
|
|
303
|
-
//
|
|
304
|
-
// So it starts as one comparison with no column, which the validator refuses
|
|
305
|
-
// by name: the node says "needs a column" on the canvas from the moment it
|
|
306
|
-
// is dropped. The operator defaults to `equals` because it is the only one
|
|
307
|
-
// that is a guess about *form* rather than about data — every other choice
|
|
308
|
-
// implies something about the column's type before a column is chosen.
|
|
309
|
-
return {
|
|
310
|
-
id,
|
|
311
|
-
name,
|
|
312
|
-
kind: 'filter',
|
|
313
|
-
predicate: { kind: 'compare', column: '', operator: 'equals', value: '' },
|
|
314
|
-
position,
|
|
315
|
-
};
|
|
316
|
-
}
|
|
317
|
-
if (kind === 'sink') {
|
|
318
|
-
return { id, name, kind: 'sink', targetType: '', position };
|
|
319
|
-
}
|
|
320
|
-
return unreachableNodeKind(kind, 'newNodeOfKind');
|
|
321
|
-
}
|
|
322
|
-
/**
|
|
323
|
-
* A wire, with its branch already decided when it leaves an `if`.
|
|
324
|
-
*
|
|
325
|
-
* Assigned here rather than left blank for somebody to fill in, because a blank
|
|
326
|
-
* one is refused by `validateWorkflow` and the refusal would fire on the very
|
|
327
|
-
* first wire out of a node somebody just created — the premature-error problem
|
|
328
|
-
* `partitionProblems` exists to describe, arrived at from a different direction.
|
|
329
|
-
*
|
|
330
|
-
* The first wire out of a gate is the `then`, the second is the `else`, and
|
|
331
|
-
* after that it is `then` again. That ordering is not arbitrary: those are the
|
|
332
|
-
* two somebody is drawing when they draw a gate, in that order, and a third wire
|
|
333
|
-
* is fan-out on a side they then choose in the inspector. Every one of them is
|
|
334
|
-
* editable there, so this is a default and never a decision.
|
|
335
|
-
*/
|
|
336
|
-
function newEdge(nodes, edges, from, to) {
|
|
337
|
-
const source = nodes.find((node) => node.id === from);
|
|
338
|
-
if (source?.kind !== 'if')
|
|
339
|
-
return { from, to };
|
|
340
|
-
const taken = edges.filter((edge) => edge.from === from).map((edge) => edge.branch);
|
|
341
|
-
const free = WORKFLOW_BRANCH_LABELS.find((label) => !taken.includes(label));
|
|
342
|
-
return { from, to, branch: free ?? 'then' };
|
|
343
|
-
}
|
|
344
564
|
/** The same graph with one wire moved onto the other side of its gate. */
|
|
345
565
|
function edgeOnBranch(edges, moving, branch) {
|
|
346
566
|
const id = edgeId(moving);
|
|
@@ -408,94 +628,6 @@ function nodeWiredFrom(draft, fromId, kind) {
|
|
|
408
628
|
function runningTransform(nodes, nodeId, transformId) {
|
|
409
629
|
return nodes.map((node) => node.id === nodeId && node.kind === 'transform' ? { ...node, transformId } : node);
|
|
410
630
|
}
|
|
411
|
-
/**
|
|
412
|
-
* A name nobody has used yet, so the fourth transform is not also "Transform".
|
|
413
|
-
*
|
|
414
|
-
* Every node used to be born called exactly `defaultLabel(kind)`, which is how
|
|
415
|
-
* a graph ends up with three boxes called "Transform" and a problem message
|
|
416
|
-
* that has to fall back to naming the id — `Sink (sink_3b5a…)` — because the
|
|
417
|
-
* name it was given identifies nothing. A message that names an id is a message
|
|
418
|
-
* whose reader has to go hunting for which box it means.
|
|
419
|
-
*
|
|
420
|
-
* Compared against what nodes are *called* rather than against a counter, so
|
|
421
|
-
* renaming "Transform 2" to "Join" frees the number again, and so a name typed
|
|
422
|
-
* by hand is never duplicated by one generated afterwards. `nodeName` is what
|
|
423
|
-
* the rest of the screen displays, so it is what has to be unique.
|
|
424
|
-
*/
|
|
425
|
-
function uniqueName(nodes, kind) {
|
|
426
|
-
const base = defaultLabel(kind);
|
|
427
|
-
const taken = new Set(nodes.map((node) => nodeName(node)));
|
|
428
|
-
if (!taken.has(base))
|
|
429
|
-
return base;
|
|
430
|
-
// `taken.size + 1` candidates for `taken.size` names: one of them is free, so
|
|
431
|
-
// this always returns from inside the loop.
|
|
432
|
-
for (let n = 2; n <= taken.size + 1; n += 1) {
|
|
433
|
-
const candidate = `${base} ${n}`;
|
|
434
|
-
if (!taken.has(candidate))
|
|
435
|
-
return candidate;
|
|
436
|
-
}
|
|
437
|
-
return `${base} ${taken.size + 2}`;
|
|
438
|
-
}
|
|
439
|
-
/**
|
|
440
|
-
* The grid `layout` uses, restated because it keeps its gaps to itself.
|
|
441
|
-
*
|
|
442
|
-
* `NODE_WIDTH` and `NODE_HEIGHT` are exported from `workflow/graph`; the column
|
|
443
|
-
* and row gaps are not. They are repeated here so that a node created by wiring
|
|
444
|
-
* from another one lands on the same grid Tidy would have put it on — otherwise
|
|
445
|
-
* the two disagree and pressing Tidy shuffles everything by a few pixels for no
|
|
446
|
-
* reason a reader can see. If they ever drift, the consequence is spacing that
|
|
447
|
-
* looks slightly off, never a node in the wrong place: the placement below is
|
|
448
|
-
* defined by what is *occupied*, not by these numbers.
|
|
449
|
-
*/
|
|
450
|
-
const COLUMN_STEP = NODE_WIDTH + 96;
|
|
451
|
-
const ROW_STEP = NODE_HEIGHT + 32;
|
|
452
|
-
/**
|
|
453
|
-
* Where a node created *by wiring from another node* goes.
|
|
454
|
-
*
|
|
455
|
-
* One column to the right of the node that spawned it, because that is exactly
|
|
456
|
-
* what the canvas's arrangement means: `layout` puts a node one column past the
|
|
457
|
-
* deepest thing feeding it, and a node created by this action is fed by that
|
|
458
|
-
* node and nothing else. So the position that matches the picture is not a
|
|
459
|
-
* guess — it is the position the layout would have chosen anyway.
|
|
460
|
-
*
|
|
461
|
-
* Then down a row at a time until the spot is free. The three obvious
|
|
462
|
-
* alternatives are each wrong in their own way: under the cursor puts a node
|
|
463
|
-
* wherever a menu happened to be dismissed, on top of an existing node reads as
|
|
464
|
-
* "the button did nothing", and off-screen — which is what `nextPosition` does,
|
|
465
|
-
* correctly, for the toolbar's add buttons, since those have no parent to sit
|
|
466
|
-
* beside — leaves somebody looking at an unchanged canvas. Sitting beside its
|
|
467
|
-
* parent means it is on screen whenever its parent is, which is the only
|
|
468
|
-
* guarantee available without measuring the viewport.
|
|
469
|
-
*/
|
|
470
|
-
function placeNextTo(from, nodes) {
|
|
471
|
-
const taken = new Set(nodes.map((node) => `${node.position?.x ?? 0},${node.position?.y ?? 0}`));
|
|
472
|
-
const x = (from.position?.x ?? 0) + COLUMN_STEP;
|
|
473
|
-
let y = from.position?.y ?? 0;
|
|
474
|
-
while (taken.has(`${x},${y}`))
|
|
475
|
-
y += ROW_STEP;
|
|
476
|
-
return { x, y };
|
|
477
|
-
}
|
|
478
|
-
/**
|
|
479
|
-
* Which kinds of new node this one could legally feed — asked, never restated.
|
|
480
|
-
*
|
|
481
|
-
* The menu must offer only edges the graph allows, and the temptation is to
|
|
482
|
-
* write that down: "a source may feed a transform or a sink; nothing follows a
|
|
483
|
-
* sink". Writing it down is how the canvas ends up with a second copy of rules
|
|
484
|
-
* that live in `canConnect`, and the first time the two disagree the menu either
|
|
485
|
-
* offers an edge that is then refused or hides one that was always fine.
|
|
486
|
-
*
|
|
487
|
-
* So this builds a throwaway node of each kind, drops it into a copy of the
|
|
488
|
-
* graph, and asks `canConnect` — the same function the drag uses, the same one
|
|
489
|
-
* the "send its output to" picker filters with. The probe is never stored and
|
|
490
|
-
* its id never leaves this function. When a rule changes, this follows.
|
|
491
|
-
*/
|
|
492
|
-
function newKindsFrom(from, nodes, edges) {
|
|
493
|
-
const probeId = '__probe__';
|
|
494
|
-
return WORKFLOW_NODE_KINDS.filter((kind) => {
|
|
495
|
-
const probe = newNodeOfKind(kind, probeId, { x: 0, y: 0 }, probeId);
|
|
496
|
-
return canConnect([...nodes, probe], edges, from.id, probeId).ok;
|
|
497
|
-
});
|
|
498
|
-
}
|
|
499
631
|
/**
|
|
500
632
|
* Problems about a node nobody has finished, held back from the error list.
|
|
501
633
|
*
|
|
@@ -688,8 +820,8 @@ function CanvasActions({ draft, stored, canEdit, blocked, unfinished, saving, ru
|
|
|
688
820
|
* the dock cannot fall behind the model — see the note on `ADD_NODE` for the bug
|
|
689
821
|
* that made that necessary.
|
|
690
822
|
*/
|
|
691
|
-
function AddNodeBar({ refreshing, onAdd, onTidy, }) {
|
|
692
|
-
return (_jsxs("div", { className: cn('pointer-events-auto flex max-w-full items-center gap-1 overflow-x-auto p-1.5', FLOATING), children: [WORKFLOW_NODE_KINDS.map((kind) => (_jsx(AddButton, { kind: kind, onClick: () => onAdd(kind) }, kind))), _jsx("span", { className: cn('mx-1 h-6 w-px shrink-0 bg-zinc-200 dark:bg-zinc-800'), "aria-hidden": true }), _jsx(Tooltip, { content: "Lay the nodes out left to right by dependency, with every sink in the last column.", children: _jsxs(Button, { variant: "ghost", size: "sm", onClick: onTidy, "aria-label": "Tidy the layout", className: "shrink-0", children: [_jsx(LayoutGrid, { size: 12 }), _jsx("span", { className:
|
|
823
|
+
function AddNodeBar({ refreshing, compact, onAdd, onTidy, }) {
|
|
824
|
+
return (_jsxs("div", { className: cn('pointer-events-auto flex max-w-full items-center gap-1 overflow-x-auto p-1.5', FLOATING), children: [WORKFLOW_NODE_KINDS.map((kind) => (_jsx(AddButton, { kind: kind, compact: compact, onClick: () => onAdd(kind) }, kind))), _jsx("span", { className: cn('mx-1 h-6 w-px shrink-0 bg-zinc-200 dark:bg-zinc-800'), "aria-hidden": true }), _jsx(Tooltip, { content: "Lay the nodes out left to right by dependency, with every sink in the last column.", children: _jsxs(Button, { variant: "ghost", size: "sm", onClick: onTidy, "aria-label": "Tidy the layout", className: "shrink-0", children: [_jsx(LayoutGrid, { size: 12 }), _jsx("span", { className: compact ? 'hidden' : 'hidden md:inline', children: "Tidy" })] }) }), refreshing && (
|
|
693
825
|
// A background refetch says so without replacing anything: the graph on
|
|
694
826
|
// screen stays exactly where it is.
|
|
695
827
|
_jsx("span", { className: cn('shrink-0 px-1 font-mono text-[10px]', MUTED), children: "refreshing\u2026" }))] }));
|
|
@@ -743,6 +875,252 @@ function miniMapColor(data) {
|
|
|
743
875
|
return '#f43f5e';
|
|
744
876
|
return '#8b5cf6';
|
|
745
877
|
}
|
|
878
|
+
/**
|
|
879
|
+
* The overview, and the one thing focus mode does to it.
|
|
880
|
+
*
|
|
881
|
+
* WHY IT SHRINKS RATHER THAN GOES
|
|
882
|
+
* -------------------------------
|
|
883
|
+
* Focus mode's argument everywhere else is that the chrome it hides is chrome
|
|
884
|
+
* you do not need while drawing. The minimap is the exception: it is a
|
|
885
|
+
* navigation aid for exactly the big graph that made somebody want the room in
|
|
886
|
+
* the first place, so taking it away is taking away the thing the mode is FOR.
|
|
887
|
+
* It shrinks to the size at which it still answers "where am I", and hovering
|
|
888
|
+
* it brings the rest back. See {@link MINIMAP_FOCUSED_CLASS} for what survives
|
|
889
|
+
* at that size and what does not.
|
|
890
|
+
*
|
|
891
|
+
* WHY A TRANSFORM AND NOT A SMALLER MINIMAP
|
|
892
|
+
* -----------------------------------------
|
|
893
|
+
* React Flow sizes the minimap from `style.width`/`style.height` (defaulting to
|
|
894
|
+
* 200×150) and derives `viewScale` from them — `boundingRect.width /
|
|
895
|
+
* elementWidth`. Its pan handler then moves the viewport by `rawClientDelta *
|
|
896
|
+
* viewScale`, reading `viewScale` LIVE from a ref on every mousemove.
|
|
897
|
+
*
|
|
898
|
+
* So shrinking the honest way — passing a smaller width and height — would
|
|
899
|
+
* change the pan gain, and change it on every frame of an animation between the
|
|
900
|
+
* two sizes. A drag that started while the map was small and expanded mid-
|
|
901
|
+
* gesture would have the viewport accelerate under the finger, continuously,
|
|
902
|
+
* for the length of the animation. That is the exact failure worth avoiding.
|
|
903
|
+
*
|
|
904
|
+
* Scaling has none of it: `style.width` stays 200 in both states, so `viewScale`
|
|
905
|
+
* is a constant and the pan gain is IDENTICAL small, large, and every frame in
|
|
906
|
+
* between. Scale is a compositor property, so the animation never touches
|
|
907
|
+
* layout, never re-renders React Flow, and never resolves against `height:
|
|
908
|
+
* auto` — which is the shape of animation that never settled under jsdom and
|
|
909
|
+
* left the card body mounted forever in a test. There is nothing here for that
|
|
910
|
+
* to happen to: the element is always mounted, always 200×150 in layout, and
|
|
911
|
+
* the only thing moving is one compositor property.
|
|
912
|
+
*
|
|
913
|
+
* (Tailwind v4 emits `scale-*` as the INDEPENDENT `scale` property rather than
|
|
914
|
+
* as `transform: scale(...)`, so the computed `transform` here reads `none` and
|
|
915
|
+
* the size lives in `scale`. It honours `transform-origin` exactly the same
|
|
916
|
+
* way, and `transition-transform` in v4 expands to `transform, translate,
|
|
917
|
+
* scale, rotate` — so the transition below does cover it. Both checked in a
|
|
918
|
+
* browser rather than assumed, because a transition that silently covers
|
|
919
|
+
* nothing is a snap that looks like a missing animation.)
|
|
920
|
+
*
|
|
921
|
+
* The residue is that while shrunk the pan gain is calibrated for the large map
|
|
922
|
+
* — a drag would move the viewport less than the small drawing suggests. On a
|
|
923
|
+
* fine pointer that state is unreachable: a drag needs a press, a press needs
|
|
924
|
+
* the pointer over the element, and the pointer being over the element is what
|
|
925
|
+
* expands it. Every drag begins on a settled, full-size map. On a touch screen
|
|
926
|
+
* there is no shrinking at all ({@link hoverCapablePointer}), so it cannot
|
|
927
|
+
* arise there either. Expand-then-pan, arrived at by geometry rather than by
|
|
928
|
+
* disabling anything.
|
|
929
|
+
*
|
|
930
|
+
* WHY IT CANNOT FLICKER
|
|
931
|
+
* ---------------------
|
|
932
|
+
* Both states are anchored at the same bottom-left corner and the transform
|
|
933
|
+
* origin is that corner, so the small box is a strict sub-rectangle of the
|
|
934
|
+
* large one. A pointer that enters the small box is therefore still inside the
|
|
935
|
+
* large box once it expands, and expansion can never move the element out from
|
|
936
|
+
* under the pointer that caused it. The one geometry that oscillates — expand,
|
|
937
|
+
* pointer now outside, collapse, repeat — needs the two boxes to disagree about
|
|
938
|
+
* a region, and containment is what rules that out.
|
|
939
|
+
*
|
|
940
|
+
* It also cannot collide with the zoom controls above it, because the expanded
|
|
941
|
+
* size is the size the minimap already is today: the gap the shrink opens up is
|
|
942
|
+
* space that was always reserved for this element, so growing back into it
|
|
943
|
+
* covers nothing that was not already covered.
|
|
944
|
+
*/
|
|
945
|
+
function FocusMiniMap({ focused }) {
|
|
946
|
+
/*
|
|
947
|
+
* Read once at mount rather than subscribed to, which is the same call
|
|
948
|
+
* `railOpenByWidth` makes and for the same reason: a live query would re-shrink
|
|
949
|
+
* the map under a pointer that is resting on it because a tablet was docked.
|
|
950
|
+
* The cost of being wrong is one session on the size it booted with.
|
|
951
|
+
*/
|
|
952
|
+
const [canHover] = useState(hoverCapablePointer);
|
|
953
|
+
const shrinks = focused && canHover;
|
|
954
|
+
return (
|
|
955
|
+
/*
|
|
956
|
+
* React Flow's own `Panel`, so this wrapper IS the panel: it takes the
|
|
957
|
+
* absolute positioning, the 15px margin, the z-index and — the reason it is
|
|
958
|
+
* `Panel` rather than a hand-rolled div — the rule that switches
|
|
959
|
+
* `pointer-events` off while a box-selection is being dragged across the
|
|
960
|
+
* canvas. The minimap inside is switched to `static` so it stops being the
|
|
961
|
+
* positioned element and becomes this one's content; without that there
|
|
962
|
+
* would be two absolutely-positioned boxes fighting over one corner.
|
|
963
|
+
*/
|
|
964
|
+
_jsx(Panel, { position: "bottom-left",
|
|
965
|
+
/*
|
|
966
|
+
* THE KEYBOARD PATH, and it exists only while the map is shrunk.
|
|
967
|
+
*
|
|
968
|
+
* A minimap that expands on hover cannot be expanded by somebody who has
|
|
969
|
+
* no pointer, and `focus-within` is only an answer if something in here
|
|
970
|
+
* can hold a caret — React Flow's minimap is an `svg` with `role="img"`,
|
|
971
|
+
* which cannot. So the panel itself becomes the focus stop.
|
|
972
|
+
*
|
|
973
|
+
* Conditional on `shrinks`, and that is the whole reason this is safe:
|
|
974
|
+
* outside focus mode the tab order is byte-for-byte the one the previous
|
|
975
|
+
* round measured and settled — app nav, card, actions, rail toggle, dock,
|
|
976
|
+
* rail, canvas — because `undefined` puts no stop here at all. Inside
|
|
977
|
+
* focus mode there is one extra stop, at the end, on the element that
|
|
978
|
+
* needs it. That is a net gain for a keyboard: the minimap was never
|
|
979
|
+
* reachable before, in either mode.
|
|
980
|
+
*/
|
|
981
|
+
tabIndex: shrinks ? 0 : undefined, role: shrinks ? 'group' : undefined, "aria-label": shrinks
|
|
982
|
+
? 'Graph overview, reduced. Hold focus here, or hover it, to see it full size.'
|
|
983
|
+
: undefined, className: cn(
|
|
984
|
+
// An overview is worth least on the screen with least room for it:
|
|
985
|
+
// below `lg` it would cover a sixth of the canvas to describe the other
|
|
986
|
+
// five. Moved here from the minimap itself along with the positioning.
|
|
987
|
+
'hidden lg:block',
|
|
988
|
+
// The corner both states share. `scale` alone would shrink about the
|
|
989
|
+
// centre and unpin the map from the corner it is anchored to, which is
|
|
990
|
+
// also what makes the containment argument above hold.
|
|
991
|
+
'origin-bottom-left',
|
|
992
|
+
/*
|
|
993
|
+
* A tween on a transform, matching the duration and the curve the card
|
|
994
|
+
* body folds on, so the two halves of one gesture move as one gesture.
|
|
995
|
+
*
|
|
996
|
+
* `prefers-reduced-motion` gets the same end state and no transition —
|
|
997
|
+
* a CSS variant rather than the `useReducedMotion()` hook the motion
|
|
998
|
+
* components here use, because this animation is CSS and the media
|
|
999
|
+
* query is the direct expression of it. There is no state to keep in
|
|
1000
|
+
* step and nothing to settle.
|
|
1001
|
+
*/
|
|
1002
|
+
'transition-transform duration-200 ease-[cubic-bezier(0.32,0.72,0,1)]', 'motion-reduce:transition-none',
|
|
1003
|
+
// `focus` as well as `focus-within`: the stop is on this element, so it
|
|
1004
|
+
// is `focus` that fires today. `focus-within` is here so that a control
|
|
1005
|
+
// added inside later expands the map rather than being drawn at half
|
|
1006
|
+
// size under somebody's caret.
|
|
1007
|
+
shrinks && MINIMAP_FOCUSED_CLASS, shrinks && 'hover:scale-100 focus:scale-100 focus-within:scale-100',
|
|
1008
|
+
// The focus ring goes on the panel, because the panel is the focus stop.
|
|
1009
|
+
shrinks && 'rounded-lg outline-none focus-visible:ring-2 focus-visible:ring-sky-500'), children: _jsx(MiniMap, { pannable: true, zoomable: true,
|
|
1010
|
+
// Positioning now belongs to the panel above, so the minimap stops
|
|
1011
|
+
// claiming a corner and just draws in the box it is given.
|
|
1012
|
+
position: "bottom-left", nodeColor: (node) => miniMapColor(node.data), className: cn('!static !m-0', '!overflow-hidden !rounded-lg !border !border-zinc-200 !shadow-sm dark:!border-zinc-800') }) }));
|
|
1013
|
+
}
|
|
1014
|
+
/**
|
|
1015
|
+
* What the hover toolbar's delete button says it will do.
|
|
1016
|
+
*
|
|
1017
|
+
* The whole warning, on the tooltip, because that button is an unlabelled icon
|
|
1018
|
+
* and the gesture behind it does not stop to ask. It names the node, counts the
|
|
1019
|
+
* wires that go with it, adds the published-graph consequence where there is
|
|
1020
|
+
* one, and points at the undo that makes the whole trade defensible.
|
|
1021
|
+
*/
|
|
1022
|
+
function deleteHint(node, draft, stored) {
|
|
1023
|
+
if (!node)
|
|
1024
|
+
return 'Remove this node';
|
|
1025
|
+
const cost = deleteCost(wiresOn(draft.edges, [node.id]), stored?.status === 'ready') ??
|
|
1026
|
+
'Nothing is wired to it.';
|
|
1027
|
+
return `Delete "${nodeName(node)}". ${cost} Ctrl+Z takes it back.`;
|
|
1028
|
+
}
|
|
1029
|
+
/**
|
|
1030
|
+
* The menu for a target, or nothing at all when there is no target.
|
|
1031
|
+
*
|
|
1032
|
+
* A free function rather than a ternary in the canvas, and the same for
|
|
1033
|
+
* {@link nodeTarget} and {@link idsOf} below. Each of them replaces one branch
|
|
1034
|
+
* inside a component that is the largest thing in this package and is held to a
|
|
1035
|
+
* complexity ceiling for exactly that reason — and each reads better as a named
|
|
1036
|
+
* thing than as a `?:` in the middle of a render.
|
|
1037
|
+
*/
|
|
1038
|
+
function sectionsFor(target, context) {
|
|
1039
|
+
return target ? buildCanvasMenu(target, context) : [];
|
|
1040
|
+
}
|
|
1041
|
+
/** The hovered or selected node as a menu target, when there is one. */
|
|
1042
|
+
function nodeTarget(node) {
|
|
1043
|
+
return node ? { kind: 'node', nodeId: node.id } : undefined;
|
|
1044
|
+
}
|
|
1045
|
+
/** One node's id as a list, or an empty list. What `dropNodes` wants either way. */
|
|
1046
|
+
function idsOf(node) {
|
|
1047
|
+
return node ? [node.id] : [];
|
|
1048
|
+
}
|
|
1049
|
+
/**
|
|
1050
|
+
* A menu about to open, with a wire turned back into the graph's own edge.
|
|
1051
|
+
*
|
|
1052
|
+
* React Flow's edge carries `source`/`target` and no branch, and the branch is
|
|
1053
|
+
* the one thing an edge menu has to know: offering "move it to the else branch"
|
|
1054
|
+
* on a wire that is on no branch would be offering a change `validateWorkflow`
|
|
1055
|
+
* refuses, and offering nothing on a wire that IS on one would hide the largest
|
|
1056
|
+
* single change anybody can make from a menu.
|
|
1057
|
+
*
|
|
1058
|
+
* `null` when the wire is not in the draft at all — a stale click, which happens
|
|
1059
|
+
* when a menu is opened on the frame a graph is being replaced. Nothing is a
|
|
1060
|
+
* better answer there than a menu about an edge that no longer exists.
|
|
1061
|
+
*/
|
|
1062
|
+
function menuOpening(target, anchor, edges) {
|
|
1063
|
+
if (target.kind !== 'edge')
|
|
1064
|
+
return { target, anchor };
|
|
1065
|
+
const found = edges.find((edge) => edge.from === target.edge.from && edge.to === target.edge.to);
|
|
1066
|
+
return found ? { target: { kind: 'edge', edge: found }, anchor } : null;
|
|
1067
|
+
}
|
|
1068
|
+
/**
|
|
1069
|
+
* What the menu is about, said for somebody who cannot see where it opened.
|
|
1070
|
+
*
|
|
1071
|
+
* A context menu is normally identified by the thing under the pointer, and a
|
|
1072
|
+
* screen reader user has no pointer — so "Menu" would be the whole of what they
|
|
1073
|
+
* were told about a popup with fourteen items in it. Every branch names the node
|
|
1074
|
+
* or nodes in the words that are on the canvas.
|
|
1075
|
+
*/
|
|
1076
|
+
function describeMenuTarget(target, nodes) {
|
|
1077
|
+
if (!target)
|
|
1078
|
+
return 'Canvas menu';
|
|
1079
|
+
if (target.kind === 'node')
|
|
1080
|
+
return `Actions for ${nodeLabelIn(nodes, target.nodeId)}`;
|
|
1081
|
+
if (target.kind === 'edge') {
|
|
1082
|
+
const from = nodeLabelIn(nodes, target.edge.from);
|
|
1083
|
+
return `Actions for the connection from ${from} to ${nodeLabelIn(nodes, target.edge.to)}`;
|
|
1084
|
+
}
|
|
1085
|
+
if (target.kind === 'selection')
|
|
1086
|
+
return `Actions for ${target.nodeIds.length} selected nodes`;
|
|
1087
|
+
return 'Canvas menu';
|
|
1088
|
+
}
|
|
1089
|
+
/**
|
|
1090
|
+
* Where a context menu should hang, given the event that asked for one.
|
|
1091
|
+
*
|
|
1092
|
+
* A `contextmenu` event is not always a right-click. Pressing the dedicated
|
|
1093
|
+
* context-menu key, or Shift+F10, makes the browser dispatch exactly the same
|
|
1094
|
+
* event type at whatever has focus — which is what gives this canvas keyboard
|
|
1095
|
+
* parity for free, and is also the case that goes wrong if the coordinates on
|
|
1096
|
+
* the event are trusted.
|
|
1097
|
+
*
|
|
1098
|
+
* So a pointer is detected rather than assumed, and when there is not one the
|
|
1099
|
+
* anchor is the focused element's own box. That is better than a corner and
|
|
1100
|
+
* better than the viewport centre: the menu appears attached to the thing it
|
|
1101
|
+
* acts on, which is the same promise the pointer version makes.
|
|
1102
|
+
*
|
|
1103
|
+
* `currentTarget` is read synchronously, inside the dispatch, which is the only
|
|
1104
|
+
* time React guarantees it is set.
|
|
1105
|
+
*/
|
|
1106
|
+
function anchorFor(event) {
|
|
1107
|
+
// `button === 2` and nothing else, which is a correction made in a browser
|
|
1108
|
+
// rather than a guess. The first version of this also accepted "the
|
|
1109
|
+
// coordinates are not (0, 0)" as evidence of a pointer, on the theory that a
|
|
1110
|
+
// keyboard-fired event carries none — and Chrome carries the LAST MOUSE
|
|
1111
|
+
// POSITION instead, measured: Shift+F10 on a node at (28, 443) produced a
|
|
1112
|
+
// `contextmenu` with `button: -1` and `clientX/Y` of (188, 500), left over
|
|
1113
|
+
// from a right-click somewhere else entirely. A keyboard user would have got
|
|
1114
|
+
// the menu wherever they last happened to click.
|
|
1115
|
+
if (event.button === 2)
|
|
1116
|
+
return { x: event.clientX, y: event.clientY, width: 0, height: 0 };
|
|
1117
|
+
const on = event.currentTarget;
|
|
1118
|
+
if (on instanceof Element) {
|
|
1119
|
+
const box = on.getBoundingClientRect();
|
|
1120
|
+
return { x: box.x, y: box.y, width: box.width, height: box.height };
|
|
1121
|
+
}
|
|
1122
|
+
return { x: 0, y: 0, width: 0, height: 0 };
|
|
1123
|
+
}
|
|
746
1124
|
/**
|
|
747
1125
|
* The graph itself, and the two states in which there is no graph to draw.
|
|
748
1126
|
*
|
|
@@ -750,7 +1128,7 @@ function miniMapColor(data) {
|
|
|
750
1128
|
* place of the screen, so the header and its controls stay put while a refetch
|
|
751
1129
|
* resolves — and a failed read never looks like an empty workflow.
|
|
752
1130
|
*/
|
|
753
|
-
function GraphSurface({ loading, failed, error, onRetry, canEdit, draft, flowNodes, flowEdges, onInspect, onEditCode, onNodesChange, onEdgesChange, onConnect, isValidConnection, onConnectEnd, onNodeEnter, onNodeLeave, onPaneClick, onDisconnect, wiring, wiringRefusal, nodeMenu, fitPadding, }) {
|
|
1131
|
+
function GraphSurface({ loading, failed, error, onRetry, canEdit, draft, flowNodes, flowEdges, onInspect, onEditCode, onNodesChange, onEdgesChange, onConnect, isValidConnection, onConnectEnd, onNodeEnter, onNodeLeave, onPaneClick, onDisconnect, onOpenMenu, wiring, wiringRefusal, nodeMenu, fitPadding, focused, }) {
|
|
754
1132
|
/*
|
|
755
1133
|
* Memoised because they are context values read by every node and every edge
|
|
756
1134
|
* on the canvas. Written inline, as they were, each of these was a fresh
|
|
@@ -761,6 +1139,21 @@ function GraphSurface({ loading, failed, error, onRetry, canEdit, draft, flowNod
|
|
|
761
1139
|
*/
|
|
762
1140
|
const nodeHandlers = useMemo(() => ({ onInspect, onEditCode, canEdit, wiring }), [onInspect, onEditCode, canEdit, wiring]);
|
|
763
1141
|
const edgeHandlers = useMemo(() => ({ onDisconnect, canEdit }), [onDisconnect, canEdit]);
|
|
1142
|
+
const { screenToFlowPosition } = useReactFlow();
|
|
1143
|
+
/**
|
|
1144
|
+
* One place that turns a `contextmenu` event into "this thing, anchored here".
|
|
1145
|
+
*
|
|
1146
|
+
* `preventDefault` is what takes the browser's own menu off the table, and it
|
|
1147
|
+
* is called ONLY from the four React Flow handlers below — a node, a wire, a
|
|
1148
|
+
* selection, and the pane. Every other right-click on the screen, including
|
|
1149
|
+
* every text field in the chrome floating over this canvas, is left entirely
|
|
1150
|
+
* alone, because a canvas has nothing better than cut/copy/paste to offer
|
|
1151
|
+
* inside an input.
|
|
1152
|
+
*/
|
|
1153
|
+
const openMenu = useCallback((event, target) => {
|
|
1154
|
+
event.preventDefault();
|
|
1155
|
+
onOpenMenu(target, anchorFor(event));
|
|
1156
|
+
}, [onOpenMenu]);
|
|
764
1157
|
return (
|
|
765
1158
|
/*
|
|
766
1159
|
* The surface IS the screen: pinned to all four edges, with the chrome
|
|
@@ -768,7 +1161,20 @@ function GraphSurface({ loading, failed, error, onRetry, canEdit, draft, flowNod
|
|
|
768
1161
|
* so there is no border and no rounded corner — a full-bleed canvas that
|
|
769
1162
|
* draws its own frame is a canvas pretending to still be a widget.
|
|
770
1163
|
*/
|
|
771
|
-
_jsxs("div", { className: "absolute inset-0", children: [loading && _jsx(CanvasSkeleton, {}), failed && _jsx(CanvasFailure, { error: error, onRetry: onRetry }), !loading && !failed && (_jsx(WorkflowNodeProvider, { handlers: nodeHandlers, children: _jsx(WorkflowEdgeProvider, { handlers: edgeHandlers, children: _jsxs(ReactFlow, { className: CANVAS_THEME, nodes: flowNodes, edges: flowEdges, nodeTypes: workflowNodeTypes, edgeTypes: workflowEdgeTypes, onNodesChange: onNodesChange, onEdgesChange: onEdgesChange, onConnect: onConnect, isValidConnection: isValidConnection, onConnectEnd: onConnectEnd, onNodeMouseEnter: (_event, node) => onNodeEnter(node.id), onNodeMouseLeave: onNodeLeave, onPaneClick: onPaneClick,
|
|
1164
|
+
_jsxs("div", { className: "absolute inset-0", children: [loading && _jsx(CanvasSkeleton, {}), failed && _jsx(CanvasFailure, { error: error, onRetry: onRetry }), !loading && !failed && (_jsx(WorkflowNodeProvider, { handlers: nodeHandlers, children: _jsx(WorkflowEdgeProvider, { handlers: edgeHandlers, children: _jsxs(ReactFlow, { className: CANVAS_THEME, nodes: flowNodes, edges: flowEdges, nodeTypes: workflowNodeTypes, edgeTypes: workflowEdgeTypes, onNodesChange: onNodesChange, onEdgesChange: onEdgesChange, onConnect: onConnect, isValidConnection: isValidConnection, onConnectEnd: onConnectEnd, onNodeMouseEnter: (_event, node) => onNodeEnter(node.id), onNodeMouseLeave: onNodeLeave, onPaneClick: onPaneClick, onNodeContextMenu: (event, node) => openMenu(event, { kind: 'node', nodeId: node.id }), onEdgeContextMenu: (event, edge) => openMenu(event, { kind: 'edge', edge: { from: edge.source, to: edge.target } }),
|
|
1165
|
+
// Several nodes at once gets its own target rather than falling
|
|
1166
|
+
// through to whichever node happened to be under the pointer: a
|
|
1167
|
+
// menu offering "send its output to" against five boxes would be
|
|
1168
|
+
// offering an action whose "its" has no referent.
|
|
1169
|
+
onSelectionContextMenu: (event, nodes) => openMenu(event, { kind: 'selection', nodeIds: nodes.map((node) => node.id) }),
|
|
1170
|
+
// The point is converted to GRAPH coordinates here and not later,
|
|
1171
|
+
// because "here" is only meaningful while the viewport is what it
|
|
1172
|
+
// was when the click happened — and a menu can sit open across a
|
|
1173
|
+
// pan. What the menu carries is the spot, not the pixel.
|
|
1174
|
+
onPaneContextMenu: (event) => openMenu(event, {
|
|
1175
|
+
kind: 'pane',
|
|
1176
|
+
at: screenToFlowPosition({ x: event.clientX, y: event.clientY }),
|
|
1177
|
+
}), connectionLineType: ConnectionLineType.SmoothStep,
|
|
772
1178
|
// Off, so there is exactly ONE click path through a handle and it
|
|
773
1179
|
// is the one in `workflow/wiring.tsx`. React Flow's own click
|
|
774
1180
|
// wiring connects but draws nothing while it is open and cannot
|
|
@@ -781,85 +1187,7 @@ function GraphSurface({ loading, failed, error, onRetry, canEdit, draft, flowNod
|
|
|
781
1187
|
connectionRadius: 28, proOptions: { hideAttribution: false }, ariaLabelConfig: ARIA_LABELS, "aria-label": `${WORKFLOW_NAME.title} canvas. ${draft.nodes.length} nodes, ${draft.edges.length} connections.`, fitView: true, fitViewOptions: { padding: fitPadding }, children: [_jsx(Background, { variant: BackgroundVariant.Dots, gap: 18, size: 1 }), _jsx(Controls, { showInteractive: false, position: "bottom-left", className: cn('!bottom-[9.5rem] !overflow-hidden !rounded-lg !border !border-zinc-200', '!shadow-sm dark:!border-zinc-800 [&>button]:!border-none',
|
|
782
1188
|
// Below `lg` the minimap is gone, so the zoom controls drop
|
|
783
1189
|
// back down into the corner it vacated.
|
|
784
|
-
'!bottom-0 lg:!bottom-[9.5rem]') }), _jsx(
|
|
785
|
-
// An overview is worth least on the screen with least room for
|
|
786
|
-
// it: below `lg` it would cover a sixth of the canvas to
|
|
787
|
-
// describe the other five.
|
|
788
|
-
className: cn('!hidden lg:!block', '!overflow-hidden !rounded-lg !border !border-zinc-200 !shadow-sm dark:!border-zinc-800') }), _jsx(PendingWireLine, { pending: wiring.pending }), _jsx(WiringHint, { pending: wiring.pending, refusal: wiringRefusal, nodes: draft.nodes, onCancel: wiring.cancel }), nodeMenu] }) }) }))] }));
|
|
789
|
-
}
|
|
790
|
-
/**
|
|
791
|
-
* The wiring control that lives on a node, and the menu behind it.
|
|
792
|
-
*
|
|
793
|
-
* WHY THIS EXISTS
|
|
794
|
-
* ---------------
|
|
795
|
-
* Until this, the only way to make an edge on this canvas was to drag from one
|
|
796
|
-
* handle to another. That is React Flow's gesture, it is perfectly good, and it
|
|
797
|
-
* is invisible: nothing on the screen says the small circles are draggable, so
|
|
798
|
-
* the canvas worked for people who had used a node editor before and read as
|
|
799
|
-
* broken to everybody else. The wiring rail and the inspector's picker were the
|
|
800
|
-
* answers for keyboard users — they are still the answers for keyboard users —
|
|
801
|
-
* but reaching either means knowing to open a panel first.
|
|
802
|
-
*
|
|
803
|
-
* A control on the node, offering "connect to something that exists" and "make
|
|
804
|
-
* the next thing and connect it", is the ordinary affordance for this kind of
|
|
805
|
-
* editor. Its absence was the whole complaint.
|
|
806
|
-
*
|
|
807
|
-
* WHAT IT OFFERS
|
|
808
|
-
* --------------
|
|
809
|
-
* Only edges the graph allows, and it does not know which those are. Every
|
|
810
|
-
* option — existing target, new kind, all of it — is filtered by `canConnect`,
|
|
811
|
-
* the same function the drag is refused by. Offering an edge that is then
|
|
812
|
-
* rejected teaches somebody the menu is a guess; restating the node-kind rules
|
|
813
|
-
* here so the menu could be "smart" would be the same rules in a second place,
|
|
814
|
-
* which is how they drift.
|
|
815
|
-
*
|
|
816
|
-
* Disconnect is here too. Removing a wire otherwise means finding a two-pixel
|
|
817
|
-
* line on a canvas and pressing Delete, or scrolling the rail to the right row;
|
|
818
|
-
* the node is where somebody knows *which* wire they mean, so it is where the
|
|
819
|
-
* offer belongs.
|
|
820
|
-
*
|
|
821
|
-
* HOW IT IS PLACED
|
|
822
|
-
* ----------------
|
|
823
|
-
* `NodeToolbar` with an explicit `nodeId`, which is React Flow's documented way
|
|
824
|
-
* of rendering a toolbar for a node from outside that node's own component. So
|
|
825
|
-
* the position comes from the same measurements the canvas draws with, and this
|
|
826
|
-
* file does not do arithmetic on a viewport transform.
|
|
827
|
-
*/
|
|
828
|
-
function NodeWiringMenu({ node, draft, canEdit, open, onOpenChange, onHoverChange, onConnect, onConnectToNew, onDisconnect, }) {
|
|
829
|
-
if (!node || !canEdit)
|
|
830
|
-
return null;
|
|
831
|
-
const targets = draft.nodes.filter((candidate) => canConnect(draft.nodes, draft.edges, node.id, candidate.id).ok);
|
|
832
|
-
const kinds = newKindsFrom(node, draft.nodes, draft.edges);
|
|
833
|
-
const wires = draft.edges.filter((edge) => edge.from === node.id || edge.to === node.id);
|
|
834
|
-
const label = (id) => nodeLabelIn(draft.nodes, id);
|
|
835
|
-
return (_jsxs(NodeToolbar, { nodeId: node.id, isVisible: true, position: Position.Top, align: "end",
|
|
836
|
-
// Flush against the node. The pointer has to travel from the node to this
|
|
837
|
-
// toolbar to use it, and any gap is canvas — which means `onNodeMouseLeave`
|
|
838
|
-
// fires with nothing to catch it and the control vanishes on the way to
|
|
839
|
-
// itself. Touching, the leave and the enter land in the same React batch.
|
|
840
|
-
offset: 0, onMouseEnter: () => onHoverChange(true), onMouseLeave: () => onHoverChange(false), className: "flex flex-col items-end gap-1", children: [_jsx(Tooltip, { content: `Wire ${nodeName(node)} to something, or make the next node from it.`, children: _jsxs("button", { type: "button", onClick: () => onOpenChange(!open), "aria-expanded": open, "aria-haspopup": "menu", "aria-label": `Wire ${nodeName(node)}`, className: cn('flex items-center gap-1 rounded-md border px-1.5 py-1 text-[10px] shadow-sm', RULE, PANEL, 'hover:bg-zinc-50 dark:hover:bg-zinc-800'), children: [_jsx(Link2, { size: 11 }), "Wire"] }) }), open && (_jsxs("div", { role: "menu", "aria-label": `Wiring for ${nodeName(node)}`, onKeyDown: (event) => {
|
|
841
|
-
if (event.key === 'Escape')
|
|
842
|
-
onOpenChange(false);
|
|
843
|
-
}, className: cn('w-60 rounded-md border p-1 text-left shadow-lg', RULE, PANEL,
|
|
844
|
-
// Above the nodes, which React Flow gives a z-index of their own.
|
|
845
|
-
'z-10'), children: [_jsx(MenuGroup, { title: "Send its output to", children: targets.length === 0 ? (_jsx(MenuNote, { children: node.kind === 'sink'
|
|
846
|
-
? 'A sink commits its rows. Nothing runs after one.'
|
|
847
|
-
: 'Nothing on the canvas can take its output yet. Make one below.' })) : (targets.map((target) => (_jsx(MenuItem, { onClick: () => {
|
|
848
|
-
onConnect(node.id, target.id);
|
|
849
|
-
onOpenChange(false);
|
|
850
|
-
}, icon: _jsx(ArrowRight, { size: 11, className: MUTED }), hint: target.kind, children: nodeName(target) }, target.id)))) }), kinds.length > 0 && (_jsx(MenuGroup, { title: "Or make one", children: kinds.map((kind) => (_jsxs(MenuItem, { onClick: () => onConnectToNew(node.id, kind), icon: _jsx(Plus, { size: 11, className: MUTED }), hint: "added and wired", children: ["New ", kind] }, kind))) })), wires.length > 0 && (_jsx(MenuGroup, { title: "Already wired", children: wires.map((edge) => (_jsxs(MenuItem, { onClick: () => {
|
|
851
|
-
onDisconnect(edge);
|
|
852
|
-
onOpenChange(false);
|
|
853
|
-
}, icon: _jsx(Unplug, { size: 11, className: MUTED }), hint: edge.from === node.id ? 'feeds' : 'fed by', children: ["Disconnect ", label(edge.from === node.id ? edge.to : edge.from)] }, edgeId(edge)))) }))] }))] }));
|
|
854
|
-
}
|
|
855
|
-
function MenuGroup({ title, children }) {
|
|
856
|
-
return (_jsxs("div", { className: "py-0.5", children: [_jsx("p", { className: cn('px-1.5 pb-0.5 font-mono text-[9px] uppercase tracking-[0.14em]', MUTED), children: title }), children] }));
|
|
857
|
-
}
|
|
858
|
-
function MenuNote({ children }) {
|
|
859
|
-
return _jsx("p", { className: cn('px-1.5 py-0.5 text-[11px] leading-relaxed', MUTED), children: children });
|
|
860
|
-
}
|
|
861
|
-
function MenuItem({ onClick, icon, hint, children, }) {
|
|
862
|
-
return (_jsxs("button", { type: "button", role: "menuitem", onClick: onClick, className: cn('flex w-full items-center gap-1.5 rounded px-1.5 py-1 text-left text-[11px]', 'hover:bg-zinc-100 dark:hover:bg-zinc-800'), children: [icon, _jsx("span", { className: "truncate", children: children }), _jsx("span", { className: cn('ml-auto shrink-0 font-mono text-[9px]', MUTED), children: hint })] }));
|
|
1190
|
+
'!bottom-0 lg:!bottom-[9.5rem]') }), _jsx(FocusMiniMap, { focused: focused }), _jsx(PendingWireLine, { pending: wiring.pending }), _jsx(WiringHint, { pending: wiring.pending, refusal: wiringRefusal, nodes: draft.nodes, onCancel: wiring.cancel }), nodeMenu] }) }) }))] }));
|
|
863
1191
|
}
|
|
864
1192
|
/**
|
|
865
1193
|
* Which node the wiring control is attached to right now.
|
|
@@ -1094,23 +1422,28 @@ function Canvas({ title = WORKFLOW_NAME.titlePlural, eyebrow = 'Ingestion', intr
|
|
|
1094
1422
|
* SSR, and a bare `window` there is a crash rather than a layout bug.
|
|
1095
1423
|
*/
|
|
1096
1424
|
const [railOpen, setRailOpen] = useState(railOpenByDefault);
|
|
1425
|
+
const { focused, toggleFocus } = useFocusMode(railOpen, setRailOpen);
|
|
1426
|
+
const cardCollapsed = focusCollapsesTheCard(focused, draft.name);
|
|
1097
1427
|
/**
|
|
1098
1428
|
* The region of the viewport the graph should be fitted into.
|
|
1099
1429
|
*
|
|
1100
|
-
* See {@link CHROME}.
|
|
1101
|
-
*
|
|
1430
|
+
* See {@link CHROME}. Two sides move: the right with the rail, the top with
|
|
1431
|
+
* the card's collapse.
|
|
1102
1432
|
*
|
|
1103
1433
|
* Declared up here with the state rather than beside its use, because both
|
|
1104
1434
|
* `fitView` call sites below name it in a dependency array — and a `const` read
|
|
1105
1435
|
* by a hook that runs earlier in the body is a temporal-dead-zone crash, not a
|
|
1106
1436
|
* lint warning.
|
|
1107
1437
|
*
|
|
1108
|
-
* Toggling the rail deliberately does NOT re-fit
|
|
1109
|
-
* viewport somebody had panned to, in response
|
|
1110
|
-
* new padding applies at the next fit that was
|
|
1111
|
-
* opening a graph, or pressing Tidy.
|
|
1438
|
+
* Toggling the rail deliberately does NOT re-fit, and neither does entering
|
|
1439
|
+
* focus. That would throw away a viewport somebody had panned to, in response
|
|
1440
|
+
* to an action about a panel; the new padding applies at the next fit that was
|
|
1441
|
+
* going to happen anyway — opening a graph, or pressing Tidy. Focus is the
|
|
1442
|
+
* stronger case for the same rule: somebody who has just asked for room is
|
|
1443
|
+
* looking at a particular part of the graph, and jumping the viewport is the
|
|
1444
|
+
* one thing that would lose it.
|
|
1112
1445
|
*/
|
|
1113
|
-
const fitPadding = useMemo(() => chromeFitPadding(railOpen), [railOpen]);
|
|
1446
|
+
const fitPadding = useMemo(() => chromeFitPadding(railOpen, cardCollapsed), [railOpen, cardCollapsed]);
|
|
1114
1447
|
/**
|
|
1115
1448
|
* Whether the "this load is expected to shrink" dialog is open.
|
|
1116
1449
|
*
|
|
@@ -1153,6 +1486,14 @@ function Canvas({ title = WORKFLOW_NAME.titlePlural, eyebrow = 'Ingestion', intr
|
|
|
1153
1486
|
* screen is silence too.
|
|
1154
1487
|
*/
|
|
1155
1488
|
const [announcement, setAnnouncement] = useState('');
|
|
1489
|
+
/**
|
|
1490
|
+
* What was right-clicked, and where the menu should hang.
|
|
1491
|
+
*
|
|
1492
|
+
* One piece of state for both, because they are one event: the anchor is the
|
|
1493
|
+
* pointer for a right-click and the focused element's box for the context-menu
|
|
1494
|
+
* key, and neither survives the event that carried it.
|
|
1495
|
+
*/
|
|
1496
|
+
const [contextMenu, setContextMenu] = useState(null);
|
|
1156
1497
|
const menu = useWiringMenu(draft.nodes, selectedNodeIds);
|
|
1157
1498
|
/**
|
|
1158
1499
|
* Which workflow the draft was built from.
|
|
@@ -1184,6 +1525,9 @@ function Canvas({ title = WORKFLOW_NAME.titlePlural, eyebrow = 'Ingestion', intr
|
|
|
1184
1525
|
// not cross graphs. Keeping the map would be this screen holding one graph's
|
|
1185
1526
|
// columns while drawing another's — silence is the right state on arrival.
|
|
1186
1527
|
setShapesByNode(new Map());
|
|
1528
|
+
// A menu is about something in the graph that was on screen. Left open
|
|
1529
|
+
// across a swap it would offer to disconnect wires that no longer exist.
|
|
1530
|
+
setContextMenu(null);
|
|
1187
1531
|
menu.reset();
|
|
1188
1532
|
}, [workflows.data, selected, menu.reset]);
|
|
1189
1533
|
// Fit after the graph swaps, on the frame after the new nodes have been laid
|
|
@@ -1391,6 +1735,36 @@ function Canvas({ title = WORKFLOW_NAME.titlePlural, eyebrow = 'Ingestion', intr
|
|
|
1391
1735
|
markStarted(edge.from, edge.to);
|
|
1392
1736
|
setAnnouncement('Connection removed.');
|
|
1393
1737
|
}, [edit, markStarted]);
|
|
1738
|
+
/**
|
|
1739
|
+
* Take nodes out, and say what went with them.
|
|
1740
|
+
*
|
|
1741
|
+
* The one path every deliberate node removal goes through — the hover
|
|
1742
|
+
* toolbar's button, the context menu's item, the selection menu, and the
|
|
1743
|
+
* inspector's "Remove this node". The Delete key reaches the same graph change
|
|
1744
|
+
* through React Flow's own change stream above, which labels its undo entry
|
|
1745
|
+
* the same way.
|
|
1746
|
+
*
|
|
1747
|
+
* The label is the FUNCTION form so it can name the node out of `current`, and
|
|
1748
|
+
* a deletion always opens its own entry rather than folding into whatever came
|
|
1749
|
+
* before it — it is the change somebody is most likely to want back, and it
|
|
1750
|
+
* must not disappear into the drag that happened a moment earlier.
|
|
1751
|
+
*
|
|
1752
|
+
* What this adds over the graph change itself is the sentence. Undo makes a
|
|
1753
|
+
* removal recoverable; it does not make it *visible* that a node took two
|
|
1754
|
+
* other nodes' wiring with it, and nothing else on the screen says so.
|
|
1755
|
+
*/
|
|
1756
|
+
const dropNodes = useCallback((ids) => {
|
|
1757
|
+
const { said } = removeNodes(draft.nodes, draft.edges, ids);
|
|
1758
|
+
if (ids.length === 0)
|
|
1759
|
+
return;
|
|
1760
|
+
edit((current) => {
|
|
1761
|
+
const after = removeNodes(current.nodes, current.edges, ids);
|
|
1762
|
+
return { ...current, nodes: after.nodes, edges: after.edges };
|
|
1763
|
+
}, (current) => ({ label: `deleting ${namesOf(current.nodes, ids)}` }));
|
|
1764
|
+
setUnstarted((current) => without(current, ids));
|
|
1765
|
+
setAnnouncement(`${said} Ctrl+Z takes it back.`);
|
|
1766
|
+
}, [draft.nodes, draft.edges, edit]);
|
|
1767
|
+
const forgetMenu = useCallback(() => setContextMenu(null), []);
|
|
1394
1768
|
/**
|
|
1395
1769
|
* Put a wire on the other side of its gate.
|
|
1396
1770
|
*
|
|
@@ -1591,10 +1965,24 @@ function Canvas({ title = WORKFLOW_NAME.titlePlural, eyebrow = 'Ingestion', intr
|
|
|
1591
1965
|
queryClient.invalidateQueries({ queryKey: catalogQueryKeys.workflows });
|
|
1592
1966
|
},
|
|
1593
1967
|
});
|
|
1594
|
-
|
|
1968
|
+
/**
|
|
1969
|
+
* Add a node, somewhere.
|
|
1970
|
+
*
|
|
1971
|
+
* `at` is what the right-click menu supplies and the dock does not, and the
|
|
1972
|
+
* difference is the whole reason "add a node here" is worth having: the dock's
|
|
1973
|
+
* buttons have no idea where anybody is looking, so `nextPosition` correctly
|
|
1974
|
+
* puts a node past the right-hand edge of everything that exists. Somebody who
|
|
1975
|
+
* has just pointed at a patch of empty canvas has said exactly where they want
|
|
1976
|
+
* it, and putting it anywhere else reads as the menu ignoring them.
|
|
1977
|
+
*
|
|
1978
|
+
* `freeSpot` still applies to the pointer position, so a click on a spot that
|
|
1979
|
+
* is already occupied — easy to do at low zoom — drops the node below it
|
|
1980
|
+
* rather than on top of it.
|
|
1981
|
+
*/
|
|
1982
|
+
const addNode = useCallback((kind, at) => {
|
|
1595
1983
|
const id = newLocalId(kind);
|
|
1596
1984
|
edit((current) => {
|
|
1597
|
-
const node = newNodeOfKind(kind, id, nextPosition(current.nodes), uniqueName(current.nodes, kind));
|
|
1985
|
+
const node = newNodeOfKind(kind, id, at ? freeSpot(current.nodes, at) : nextPosition(current.nodes), uniqueName(current.nodes, kind));
|
|
1598
1986
|
return { ...current, nodes: [...current.nodes, node] };
|
|
1599
1987
|
}, { label: `adding a ${kind} node` });
|
|
1600
1988
|
setUnstarted((current) => new Set([...current, id]));
|
|
@@ -1640,6 +2028,39 @@ function Canvas({ title = WORKFLOW_NAME.titlePlural, eyebrow = 'Ingestion', intr
|
|
|
1640
2028
|
setInspecting(node.id);
|
|
1641
2029
|
setAnnouncement(`${nodeName(node)} was added and ${nodeName(from)} now feeds it. Its inspector is open.`);
|
|
1642
2030
|
}, [draft, edit, menu.close]);
|
|
2031
|
+
/**
|
|
2032
|
+
* Put a node in the middle of a wire that already exists.
|
|
2033
|
+
*
|
|
2034
|
+
* `A → B` becomes `A → new → B` in one action. Four gestures before this, one
|
|
2035
|
+
* of which was undoing the connection you already had — and the graph passed
|
|
2036
|
+
* through a state in which it was broken, so the checks fired at somebody
|
|
2037
|
+
* halfway through a perfectly ordinary edit.
|
|
2038
|
+
*
|
|
2039
|
+
* All the care lives in `graphWithNodeBetween`: the branch label travels with
|
|
2040
|
+
* the first half, and the two new wires go in at the index the old one held so
|
|
2041
|
+
* the order of a join's inputs is not silently swapped. ONE undo entry, for
|
|
2042
|
+
* three graph changes, on the argument `connectToNew` already makes — it is
|
|
2043
|
+
* one gesture, and taking the pieces back separately would leave a node
|
|
2044
|
+
* nobody asked for stranded on a wire that no longer exists.
|
|
2045
|
+
*/
|
|
2046
|
+
const insertBetween = useCallback((edge, kind) => {
|
|
2047
|
+
// Made once, out here. An updater React chose to replay would otherwise
|
|
2048
|
+
// mint a second node with a second id, and the one this function then
|
|
2049
|
+
// announced and opened would not be the one on the canvas.
|
|
2050
|
+
const node = nodeBetween(edge, kind, draft.nodes);
|
|
2051
|
+
edit((current) => {
|
|
2052
|
+
const next = graphWithNodeBetween(edge, node, current.nodes, current.edges);
|
|
2053
|
+
return { ...current, nodes: next.nodes, edges: next.edges };
|
|
2054
|
+
}, (current) => ({
|
|
2055
|
+
label: `putting ${nodeName(node)} between ${namesOf(current.nodes, [
|
|
2056
|
+
edge.from,
|
|
2057
|
+
])} and ${namesOf(current.nodes, [edge.to])}`,
|
|
2058
|
+
}));
|
|
2059
|
+
setUnstarted((current) => new Set([...current, node.id]));
|
|
2060
|
+
markStarted(edge.from, edge.to);
|
|
2061
|
+
setInspecting(node.id);
|
|
2062
|
+
setAnnouncement(`${nodeName(node)} was put between ${nodeLabelIn(draft.nodes, edge.from)} and ${nodeLabelIn(draft.nodes, edge.to)}. Its inspector is open.`);
|
|
2063
|
+
}, [draft.nodes, edit, markStarted]);
|
|
1643
2064
|
const tidy = useCallback(() => {
|
|
1644
2065
|
edit((current) => ({
|
|
1645
2066
|
...current,
|
|
@@ -1741,6 +2162,63 @@ function Canvas({ title = WORKFLOW_NAME.titlePlural, eyebrow = 'Ingestion', intr
|
|
|
1741
2162
|
* away nodes somebody has moved since.
|
|
1742
2163
|
*/
|
|
1743
2164
|
const stored = useMemo(() => storedWorkflow(workflows.data, draft.id), [workflows.data, draft.id]);
|
|
2165
|
+
/**
|
|
2166
|
+
* Everything the menus can ask for, in one object.
|
|
2167
|
+
*
|
|
2168
|
+
* Every entry is a callback that already exists on this screen with its own
|
|
2169
|
+
* announcement, its own undo label and its own `markStarted` bookkeeping. A
|
|
2170
|
+
* menu that reimplemented any of them would be a second path with one of those
|
|
2171
|
+
* steps quietly missing — which is exactly the class of bug that produced a
|
|
2172
|
+
* canvas with two things called "wire".
|
|
2173
|
+
*
|
|
2174
|
+
* Deliberately NOT memoised, along with the two lists below it. Everything
|
|
2175
|
+
* here is already a `useCallback`, so a dependency array would be ten entries
|
|
2176
|
+
* long and would say nothing a re-render does not; what it would buy is
|
|
2177
|
+
* skipping `buildCanvasMenu`, which is six `canConnect` probes over a graph
|
|
2178
|
+
* with tens of nodes in it. The memo would cost more to keep right than the
|
|
2179
|
+
* work it saves.
|
|
2180
|
+
*/
|
|
2181
|
+
const menuActions = {
|
|
2182
|
+
inspect: setInspecting,
|
|
2183
|
+
editCode: setEditingCodeFor,
|
|
2184
|
+
connect,
|
|
2185
|
+
connectToNew,
|
|
2186
|
+
insertBetween,
|
|
2187
|
+
setBranch,
|
|
2188
|
+
disconnect,
|
|
2189
|
+
removeNodes: dropNodes,
|
|
2190
|
+
addAt: addNode,
|
|
2191
|
+
tidy,
|
|
2192
|
+
fitAll: () => fitView({ padding: fitPadding, duration: 200 }),
|
|
2193
|
+
// Fitted to the selection rather than to the graph, which is the only useful
|
|
2194
|
+
// reading of "bring these into view" when the reason somebody selected them
|
|
2195
|
+
// is that the graph is too big to see at once.
|
|
2196
|
+
fitNodes: (ids) => fitView({ nodes: ids.map((id) => ({ id })), padding: fitPadding, duration: 200 }),
|
|
2197
|
+
};
|
|
2198
|
+
const menuContext = {
|
|
2199
|
+
nodes: draft.nodes,
|
|
2200
|
+
edges: draft.edges,
|
|
2201
|
+
// Core's list, never a copy. See the note on `ADD_NODE` for the kind that
|
|
2202
|
+
// shipped complete and could not be added from this screen at all.
|
|
2203
|
+
kinds: WORKFLOW_NODE_KINDS,
|
|
2204
|
+
canEdit,
|
|
2205
|
+
published: stored?.status === 'ready',
|
|
2206
|
+
actions: menuActions,
|
|
2207
|
+
};
|
|
2208
|
+
/**
|
|
2209
|
+
* What the right-click menu is showing, and what the hover pill's menu is.
|
|
2210
|
+
*
|
|
2211
|
+
* Two lists built by one function from one model, which is the point: the pill
|
|
2212
|
+
* used to own a bespoke dropdown, and the moment a context menu existed the
|
|
2213
|
+
* two would have started answering "what can this node do" differently.
|
|
2214
|
+
*/
|
|
2215
|
+
const contextSections = sectionsFor(contextMenu?.target, menuContext);
|
|
2216
|
+
const toolbarSections = sectionsFor(nodeTarget(menu.anchor), menuContext);
|
|
2217
|
+
const contextLabel = describeMenuTarget(contextMenu?.target, draft.nodes);
|
|
2218
|
+
/** Open the menu on whatever was right-clicked. See {@link menuOpening}. */
|
|
2219
|
+
const openMenuFor = useCallback((target, anchor) => {
|
|
2220
|
+
setContextMenu(menuOpening(target, anchor, draft.edges));
|
|
2221
|
+
}, [draft.edges]);
|
|
1744
2222
|
/**
|
|
1745
2223
|
* A publish, an unpublish or a schedule, written straight into the list.
|
|
1746
2224
|
*
|
|
@@ -1823,7 +2301,7 @@ function Canvas({ title = WORKFLOW_NAME.titlePlural, eyebrow = 'Ingestion', intr
|
|
|
1823
2301
|
* covers rather than into the raw viewport — which is what stops a node
|
|
1824
2302
|
* being centred underneath the action cluster.
|
|
1825
2303
|
*/
|
|
1826
|
-
_jsxs("div", { className: "relative h-full min-h-0 w-full overflow-hidden", children: [_jsxs("div", { className: "pointer-events-none absolute inset-0 z-20 flex flex-col gap-3 p-3 sm:p-4", children: [_jsxs("div", { className: "flex flex-wrap items-start justify-between gap-3", children: [_jsx(WorkflowCard, { eyebrow: eyebrow, title: title, intro: intro, stored: stored, produces: produces, durability: durability, selected: selected, workflowOptions: workflowOptions, workflowsPending: workflows.isPending, draftName: draft.name, canEdit: canEdit, onSelect: (value) => {
|
|
2304
|
+
_jsxs("div", { className: "relative h-full min-h-0 w-full overflow-hidden", children: [_jsxs("div", { className: "pointer-events-none absolute inset-0 z-20 flex flex-col gap-3 p-3 sm:p-4", children: [_jsxs("div", { className: "flex flex-wrap items-start justify-between gap-3", children: [_jsx(WorkflowCard, { eyebrow: eyebrow, title: title, intro: intro, stored: stored, produces: produces, durability: durability, selected: selected, workflowOptions: workflowOptions, workflowsPending: workflows.isPending, draftName: draft.name, canEdit: canEdit, collapsed: cardCollapsed, reducedMotion: reducedMotion, onExpand: toggleFocus, onSelect: (value) => {
|
|
1827
2305
|
loadedRef.current = null;
|
|
1828
2306
|
setSelected(value);
|
|
1829
2307
|
},
|
|
@@ -1833,15 +2311,19 @@ function Canvas({ title = WORKFLOW_NAME.titlePlural, eyebrow = 'Ingestion', intr
|
|
|
1833
2311
|
onRename: (name) => edit((current) => ({ ...current, name }), {
|
|
1834
2312
|
label: 'renaming this workflow',
|
|
1835
2313
|
run: 'rename',
|
|
1836
|
-
}) }), _jsxs("div", { className: "flex max-w-full flex-col items-end gap-2", children: [_jsxs("div", { className: cn('pointer-events-auto flex items-start gap-2 p-1.5', FLOATING), children: [_jsx(CanvasActions, { draft: draft, stored: stored, canEdit: canEdit, blocked: blocked, unfinished: unfinished, saving: save.isPending, running: runIt.isPending, durabilityDetail: durability.detail, acknowledging: acknowledging, reducedMotion: reducedMotion, resetting: resetting, onAcknowledgingChange: setAcknowledging, onResettingChange: setResetting, onUndo: undo, onReset: reset, onSave: saveNow, onRun: runNow, onLifecycleChange: onLifecycleChange, onAskDelete: () => setConfirmingDelete(true) }), _jsx("span", { className: "h-6 w-px shrink-0 bg-zinc-200 dark:bg-zinc-800", "aria-hidden": true }), _jsx(RailToggle, { open: railOpen, problems: live, onToggle: () => setRailOpen((o) => !o) })] }), _jsxs("div", { className: "pointer-events-auto w-[min(26rem,100%)] empty:hidden", children: [save.error && _jsx(RefusalNote, { lead: "The server refused it:", error: save.error }), runIt.error && _jsx(RefusalNote, { lead: "The run could not start:", error: runIt.error }), _jsx(ShrinkRefusalNote, { run: run, error: runIt.error, onAcknowledge: () => setAcknowledging(true) })] })] })] }), canEdit && (_jsx("div", { className: "absolute inset-x-0 bottom-3 flex justify-center px-3 sm:bottom-4 sm:px-4", children: _jsx(AddNodeBar, { refreshing: workflows.isFetching && !workflows.isPending, onAdd: addNode, onTidy: tidy }) })), _jsx("div", { className: "flex min-h-0 flex-1 justify-end pb-14", children: _jsx(AnimatePresence, { initial: false, children: railOpen && (_jsx(WiringRail, { draft: draft, problems: live, pending: pending, run: run, canEdit: canEdit, reducedMotion: reducedMotion, onInspect: setInspecting, onDisconnect: disconnect, onClose: () => setRailOpen(false), children: stored && (_jsxs(_Fragment, { children: [_jsx(SchedulePanel, { workflow: stored, canEdit: canEdit, onScheduled: onLifecycleChange }, stored.id), _jsx(RunsAsPanel, { workflowId: stored.id, status: stored.status, transforms: graphTransforms })] })) })) }) })] }), _jsx(GraphSurface, { loading: workflows.isPending, failed: workflows.isError, error: workflows.error, onRetry: () => workflows.refetch(), canEdit: canEdit, draft: draft, flowNodes: flowNodes, flowEdges: flowEdges, onInspect: setInspecting, onEditCode: setEditingCodeFor, onNodesChange: onNodesChange, onEdgesChange: onEdgesChange, onConnect: onConnect, isValidConnection: isValidConnection, onConnectEnd: announceRefusedDrop, onNodeEnter: menu.onNodeEnter, onNodeLeave: menu.onNodeLeave,
|
|
2314
|
+
}) }), _jsxs("div", { className: "flex max-w-full flex-col items-end gap-2", children: [_jsxs("div", { className: cn('pointer-events-auto flex items-start gap-2 p-1.5', FLOATING), children: [_jsx(CanvasActions, { draft: draft, stored: stored, canEdit: canEdit, blocked: blocked, unfinished: unfinished, saving: save.isPending, running: runIt.isPending, durabilityDetail: durability.detail, acknowledging: acknowledging, reducedMotion: reducedMotion, resetting: resetting, onAcknowledgingChange: setAcknowledging, onResettingChange: setResetting, onUndo: undo, onReset: reset, onSave: saveNow, onRun: runNow, onLifecycleChange: onLifecycleChange, onAskDelete: () => setConfirmingDelete(true) }), _jsx("span", { className: "h-6 w-px shrink-0 bg-zinc-200 dark:bg-zinc-800", "aria-hidden": true }), _jsx(RailToggle, { open: railOpen, problems: live, onToggle: () => setRailOpen((o) => !o) }), _jsx(FocusToggle, { on: focused, cardCollapsed: cardCollapsed, onToggle: toggleFocus })] }), _jsxs("div", { className: "pointer-events-auto w-[min(26rem,100%)] empty:hidden", children: [save.error && _jsx(RefusalNote, { lead: "The server refused it:", error: save.error }), runIt.error && _jsx(RefusalNote, { lead: "The run could not start:", error: runIt.error }), _jsx(ShrinkRefusalNote, { run: run, error: runIt.error, onAcknowledge: () => setAcknowledging(true) })] })] })] }), canEdit && (_jsx("div", { className: "absolute inset-x-0 bottom-3 flex justify-center px-3 sm:bottom-4 sm:px-4", children: _jsx(AddNodeBar, { refreshing: workflows.isFetching && !workflows.isPending, compact: focused, onAdd: addNode, onTidy: tidy }) })), _jsx("div", { className: "flex min-h-0 flex-1 justify-end pb-14", children: _jsx(AnimatePresence, { initial: false, children: railOpen && (_jsx(WiringRail, { draft: draft, problems: live, pending: pending, run: run, canEdit: canEdit, reducedMotion: reducedMotion, onInspect: setInspecting, onDisconnect: disconnect, onClose: () => setRailOpen(false), children: stored && (_jsxs(_Fragment, { children: [_jsx(SchedulePanel, { workflow: stored, canEdit: canEdit, onScheduled: onLifecycleChange }, stored.id), _jsx(RunsAsPanel, { workflowId: stored.id, status: stored.status, transforms: graphTransforms })] })) })) }) })] }), _jsx(GraphSurface, { focused: focused, loading: workflows.isPending, failed: workflows.isError, error: workflows.error, onRetry: () => workflows.refetch(), canEdit: canEdit, draft: draft, flowNodes: flowNodes, flowEdges: flowEdges, onInspect: setInspecting, onEditCode: setEditingCodeFor, onNodesChange: onNodesChange, onEdgesChange: onEdgesChange, onConnect: onConnect, isValidConnection: isValidConnection, onConnectEnd: announceRefusedDrop, onNodeEnter: menu.onNodeEnter, onNodeLeave: menu.onNodeLeave,
|
|
1837
2315
|
// Clicking empty canvas puts away everything that is half-open: the
|
|
1838
2316
|
// wiring menu, and a wire that was started and never landed. React
|
|
1839
2317
|
// Flow only fires this for clicks on the pane ITSELF, so finishing a
|
|
1840
2318
|
// wire on a handle does not also cancel it on the way past.
|
|
1841
2319
|
onPaneClick: () => {
|
|
1842
2320
|
menu.close();
|
|
2321
|
+
forgetMenu();
|
|
1843
2322
|
wiring.cancel();
|
|
1844
|
-
}, onDisconnect: disconnect, wiring: wiring, wiringRefusal: wiringRefusal, nodeMenu: _jsx(
|
|
2323
|
+
}, onDisconnect: disconnect, onOpenMenu: openMenuFor, wiring: wiring, wiringRefusal: wiringRefusal, nodeMenu: _jsx(NodeActionsToolbar, { node: menu.anchor, canEdit: canEdit, open: menu.open, sections: toolbarSections, deleteHint: deleteHint(menu.anchor, draft, stored), onOpenChange: menu.onOpenChange, onHoverChange: menu.onHoverChange, onDelete: () => {
|
|
2324
|
+
dropNodes(idsOf(menu.anchor));
|
|
2325
|
+
menu.reset();
|
|
2326
|
+
} }), fitPadding: fitPadding }), _jsx(CanvasContextMenu, { opening: contextMenu, sections: contextSections, label: contextLabel, onClose: forgetMenu }), workflows.isSuccess && workflows.data.length === 0 && _jsx(NothingDrawnYet, {}), _jsx("output", { "aria-live": "polite", className: "sr-only", children: announcement }), _jsx(NodeInspector, { node: inspectingNode, draft: draft, transforms: transforms, connections: connections, typeOptions: typeOptions, canEdit: canEdit, modelHref: modelHref, problems: problemsOf(problemsFor, inspectingNode), pending: problemsOf(pendingFor, inspectingNode), discovery: discovery, discoverable: { ...discoveryTarget(draft), onSave: saveNow, saving: save.isPending }, onDiscovered: rememberShape, onClose: () => setInspecting(null), onChange: (next) => {
|
|
1845
2327
|
// Editing any field is the clearest statement there is that somebody
|
|
1846
2328
|
// is working on this node rather than looking at one they just made.
|
|
1847
2329
|
markStarted(next.id);
|
|
@@ -1865,14 +2347,13 @@ function Canvas({ title = WORKFLOW_NAME.titlePlural, eyebrow = 'Ingestion', intr
|
|
|
1865
2347
|
...current,
|
|
1866
2348
|
nodes: current.nodes.map((node) => (node.id === next.id ? next : node)),
|
|
1867
2349
|
}), nodeEditAction(before, next));
|
|
1868
|
-
}, onConnect: connect, onConnectToNew: connectToNew, onDisconnect: disconnect, onBranch: setBranch, onCreateTransform: (nodeId) => createTransform.mutate(nodeId), creatingTransform: createTransform.isPending, createTransformError: createTransform.error,
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
2350
|
+
}, onConnect: connect, onConnectToNew: connectToNew, onDisconnect: disconnect, onBranch: setBranch, onCreateTransform: (nodeId) => createTransform.mutate(nodeId), creatingTransform: createTransform.isPending, createTransformError: createTransform.error,
|
|
2351
|
+
// The same path the hover button, the context menu and the selection
|
|
2352
|
+
// menu take. It was the only way to remove a node before those existed,
|
|
2353
|
+
// and it was the only one that did not say what the removal cost.
|
|
2354
|
+
onDelete: (nodeId) => {
|
|
2355
|
+
dropNodes([nodeId]);
|
|
1874
2356
|
setInspecting(null);
|
|
1875
|
-
setAnnouncement('Node removed, along with its connections.');
|
|
1876
2357
|
}, onEditCode: (nodeId) => setEditingCodeFor(nodeId) }), _jsx(Sheet, { open: editingCodeFor !== null, onOpenChange: (open) => {
|
|
1877
2358
|
if (!open)
|
|
1878
2359
|
setEditingCodeFor(null);
|
|
@@ -1894,10 +2375,10 @@ function Canvas({ title = WORKFLOW_NAME.titlePlural, eyebrow = 'Ingestion', intr
|
|
|
1894
2375
|
function article(word) {
|
|
1895
2376
|
return /^[aeiou]/i.test(word) ? 'an' : 'a';
|
|
1896
2377
|
}
|
|
1897
|
-
function AddButton({ kind, onClick }) {
|
|
2378
|
+
function AddButton({ kind, compact, onClick, }) {
|
|
1898
2379
|
const { icon: Icon, label, hint } = ADD_NODE[kind];
|
|
1899
2380
|
const noun = label.toLowerCase();
|
|
1900
|
-
return (_jsx(Tooltip, { content: hint, children: _jsxs(Button, { variant: "ghost", size: "sm", onClick: onClick, "aria-label": `Add ${article(noun)} ${noun} node`, className: "shrink-0 text-zinc-600 dark:text-zinc-300", children: [_jsx(Plus, { size: 11 }), _jsx(Icon, { size: 12 }), _jsx("span", { className:
|
|
2381
|
+
return (_jsx(Tooltip, { content: hint, children: _jsxs(Button, { variant: "ghost", size: "sm", onClick: onClick, "aria-label": `Add ${article(noun)} ${noun} node`, className: "shrink-0 text-zinc-600 dark:text-zinc-300", children: [_jsx(Plus, { size: 11 }), _jsx(Icon, { size: 12 }), _jsx("span", { className: compact ? 'hidden' : 'hidden md:inline', children: label })] }) }));
|
|
1901
2382
|
}
|
|
1902
2383
|
/**
|
|
1903
2384
|
* Whether a failed run resumes or restarts, stated on the screen that implies
|
|
@@ -1979,6 +2460,55 @@ function problemBadge(problems) {
|
|
|
1979
2460
|
}
|
|
1980
2461
|
return null;
|
|
1981
2462
|
}
|
|
2463
|
+
/**
|
|
2464
|
+
* Give the canvas the screen, or give the chrome back.
|
|
2465
|
+
*
|
|
2466
|
+
* ## What this control promises, and what it does not
|
|
2467
|
+
*
|
|
2468
|
+
* It promises room, and it says exactly what it takes to get it — "the card and
|
|
2469
|
+
* the dock labels" — rather than "focus mode", because a mode named after a
|
|
2470
|
+
* feeling is a mode nobody can predict. What it explicitly does not promise is
|
|
2471
|
+
* that the screen goes quiet: the action cluster it sits inside stays whole, so
|
|
2472
|
+
* Save, the refusals and the problem count are all still here after it is
|
|
2473
|
+
* pressed. Somebody reading the tooltip should come away knowing that nothing
|
|
2474
|
+
* which can stop a mistake is about to disappear.
|
|
2475
|
+
*
|
|
2476
|
+
* ## The refusal
|
|
2477
|
+
*
|
|
2478
|
+
* The refusal is the case where the mode is ON and the card stayed open anyway,
|
|
2479
|
+
* because the graph has no name and the field that fixes that is inside it (see
|
|
2480
|
+
* `cardCollapsed`). A control that had been pressed and visibly done nothing
|
|
2481
|
+
* would read as broken, so it says which of the two things it is. The word is in
|
|
2482
|
+
* the accessible name too, not only in the tooltip — a tooltip is a pointer
|
|
2483
|
+
* affordance and this is the one state where the button's behaviour differs
|
|
2484
|
+
* from its label.
|
|
2485
|
+
*
|
|
2486
|
+
* ## The shortcut
|
|
2487
|
+
*
|
|
2488
|
+
* Rendered as a letter beside the icon rather than mentioned only in prose. A
|
|
2489
|
+
* keyboard shortcut nobody can see is a shortcut for whoever read the commit,
|
|
2490
|
+
* and this screen's whole argument is that the hands stay on the canvas.
|
|
2491
|
+
* `aria-hidden` on the glyph because the accessible name already spells it out
|
|
2492
|
+
* as a sentence, and "F" read aloud in the middle of one is noise.
|
|
2493
|
+
*/
|
|
2494
|
+
function FocusToggle({ on, cardCollapsed, onToggle, }) {
|
|
2495
|
+
const refusing = on && !cardCollapsed;
|
|
2496
|
+
const hint = refusing
|
|
2497
|
+
? `Focus is on, but the card is staying until this ${WORKFLOW_NAME.singular} has a name — the field that gives it one is in there, and Save is held back without it. Press ${FOCUS_SHORTCUT.toUpperCase()} or this button to turn focus off.`
|
|
2498
|
+
: on
|
|
2499
|
+
? `Bring back the ${WORKFLOW_NAME.singular} card and the dock's labels. Shortcut: ${FOCUS_SHORTCUT.toUpperCase()}.`
|
|
2500
|
+
: `Collapse the ${WORKFLOW_NAME.singular} card, drop the dock to icons and put the details panel away, so the graph gets the screen. Save, the refusals and the problem count stay exactly where they are. Shortcut: ${FOCUS_SHORTCUT.toUpperCase()}.`;
|
|
2501
|
+
const name = refusing
|
|
2502
|
+
? 'Turn off focus mode (the card is staying: this workflow has no name yet)'
|
|
2503
|
+
: on
|
|
2504
|
+
? `Turn off focus mode, shortcut ${FOCUS_SHORTCUT.toUpperCase()}`
|
|
2505
|
+
: `Turn on focus mode and give the canvas the room, shortcut ${FOCUS_SHORTCUT.toUpperCase()}`;
|
|
2506
|
+
return (_jsx(Tooltip, { content: hint, children: _jsxs(Button, { variant: "ghost", size: "sm", onClick: onToggle, "aria-pressed": on, "aria-label": name, className: cn('shrink-0',
|
|
2507
|
+
// On, the control is the only thing on screen saying so — the chrome
|
|
2508
|
+
// it collapsed cannot say it is missing. So it carries the state in
|
|
2509
|
+
// its own colour rather than relying on a panel that is gone.
|
|
2510
|
+
on && 'bg-sky-100 text-sky-700 dark:bg-sky-950 dark:text-sky-300'), children: [on ? _jsx(Minimize2, { size: 12 }) : _jsx(Maximize2, { size: 12 }), _jsx("span", { "aria-hidden": true, className: "rounded border border-current/30 px-1 font-mono text-[10px] leading-4 opacity-70", children: FOCUS_SHORTCUT.toUpperCase() })] }) }));
|
|
2511
|
+
}
|
|
1982
2512
|
/**
|
|
1983
2513
|
* Which graph this is, and the two fields that name it — top-left, floating.
|
|
1984
2514
|
*
|
|
@@ -1988,9 +2518,87 @@ function problemBadge(problems) {
|
|
|
1988
2518
|
* costs three lines of canvas forever to be read once. It is still reachable
|
|
1989
2519
|
* from the button beside the title, and still read out in full to a screen
|
|
1990
2520
|
* reader, which is the one audience a tooltip would have failed.
|
|
2521
|
+
*
|
|
2522
|
+
* ## Collapsed
|
|
2523
|
+
*
|
|
2524
|
+
* The tallest panel on the screen, so the one focus mode is really about: ~400
|
|
2525
|
+
* by ~270 of the canvas, most of it two fields and a paragraph about durability
|
|
2526
|
+
* that nobody reads twice. Collapsed, what is left is the head — and the head
|
|
2527
|
+
* gains something rather than only losing things, because the name that was in
|
|
2528
|
+
* the field has to go somewhere: it moves up beside the title, truncated, so the
|
|
2529
|
+
* card still answers "which graph am I looking at" while it is small.
|
|
2530
|
+
*
|
|
2531
|
+
* What SURVIVES the collapse is the point. The status badges stay, so a graph
|
|
2532
|
+
* that is `adopted`, unpublished or disabled still says so; the commits badge
|
|
2533
|
+
* stays, so which type this writes is still on screen. Those are the two facts
|
|
2534
|
+
* on this card that can stop a mistake, and neither of them is worth the height
|
|
2535
|
+
* that the fields cost.
|
|
2536
|
+
*
|
|
2537
|
+
* The `h1` is in both states, at the same level, so collapsing does not knock a
|
|
2538
|
+
* heading out of the document outline — a screen whose only `h1` comes and goes
|
|
2539
|
+
* with a display preference is a screen that reads differently to a screen
|
|
2540
|
+
* reader depending on a decision made about pixels.
|
|
1991
2541
|
*/
|
|
1992
|
-
function WorkflowCard({ eyebrow, title, intro, stored, produces, durability, selected, workflowOptions, workflowsPending, draftName, canEdit, onSelect, onRename, }) {
|
|
1993
|
-
|
|
2542
|
+
function WorkflowCard({ eyebrow, title, intro, stored, produces, durability, selected, workflowOptions, workflowsPending, draftName, canEdit, collapsed, reducedMotion, onExpand, onSelect, onRename, }) {
|
|
2543
|
+
/**
|
|
2544
|
+
* Whether something inside this card currently has the keyboard.
|
|
2545
|
+
*
|
|
2546
|
+
* The card will not fold while it does, and that is a correctness fix rather
|
|
2547
|
+
* than a nicety. The refusal above holds the card open while the graph has no
|
|
2548
|
+
* name — so the very next thing that happens is somebody typing one, and the
|
|
2549
|
+
* condition that was holding the card open stops being true on the FIRST
|
|
2550
|
+
* character. Without this, the field disappears out from under the caret
|
|
2551
|
+
* mid-word and the rest of the name is typed into nothing.
|
|
2552
|
+
*
|
|
2553
|
+
* Tracked by bubbling rather than by handlers on each field: `focusin` and
|
|
2554
|
+
* `focusout` bubble (unlike `focus` and `blur`), which React exposes as
|
|
2555
|
+
* `onFocus`/`onBlur` on any ancestor, so this works for the picker, the name
|
|
2556
|
+
* field and anything added to the card later without threading a prop.
|
|
2557
|
+
*
|
|
2558
|
+
* `relatedTarget` is where the focus WENT. Still inside the card — Tab from
|
|
2559
|
+
* the picker to the name field — is not a departure. `null` is a departure:
|
|
2560
|
+
* it is what a click on something unfocusable produces, and the card folding
|
|
2561
|
+
* then is right.
|
|
2562
|
+
*/
|
|
2563
|
+
const [holdsFocus, setHoldsFocus] = useState(false);
|
|
2564
|
+
const folded = collapsed && !holdsFocus;
|
|
2565
|
+
return (
|
|
2566
|
+
/*
|
|
2567
|
+
* `layout` rather than a CSS transition, because the box goes from a fixed
|
|
2568
|
+
* 24rem to whatever its head needs and there is no width to transition TO —
|
|
2569
|
+
* `auto` is not an animatable value. Motion measures both states and
|
|
2570
|
+
* interpolates the real numbers, which is the difference between a panel
|
|
2571
|
+
* that folds and one that snaps and then re-renders at the new size.
|
|
2572
|
+
*/
|
|
2573
|
+
_jsxs(motion.div, { layout: !reducedMotion, transition: reducedMotion ? { duration: 0 } : { type: 'spring', stiffness: 420, damping: 34 }, onFocus: () => setHoldsFocus(true), onBlur: (event) => {
|
|
2574
|
+
if (!event.currentTarget.contains(event.relatedTarget))
|
|
2575
|
+
setHoldsFocus(false);
|
|
2576
|
+
}, className: cn('pointer-events-auto p-3',
|
|
2577
|
+
// Collapsed it is allowed to be WIDER than the 24rem it is fixed at
|
|
2578
|
+
// open, and that is not a slip. Wrapping the head onto a second line
|
|
2579
|
+
// costs 23px of height across the full width of the panel; letting it
|
|
2580
|
+
// run to 30rem costs a strip of canvas beside a title, at the top-left
|
|
2581
|
+
// corner where a graph laid out left-to-right has nothing yet. Height is
|
|
2582
|
+
// the expensive axis here, so the trade goes that way.
|
|
2583
|
+
folded ? 'w-auto max-w-[min(30rem,100%)] py-2' : 'w-[min(24rem,100%)]', FLOATING), children: [_jsxs("div", { className: "flex flex-wrap items-baseline gap-x-2 gap-y-1", children: [!folded && (_jsx("p", { className: cn('font-mono text-[10px] uppercase tracking-[0.18em]', MUTED), children: eyebrow })), _jsx("h1", { className: "text-sm font-semibold tracking-tight", children: title }), folded && (_jsx("p", { className: cn('max-w-[12rem] truncate text-xs', MUTED), title: draftName, children: draftName })), stored && _jsx(WorkflowStatusBadge, { workflow: stored }), _jsx(CommitsBadge, { produces: produces }), folded ? (_jsx(Tooltip, { content: `Bring the ${WORKFLOW_NAME.singular} picker, the name field and the checkpointing note back, and leave focus mode. Shortcut: ${FOCUS_SHORTCUT.toUpperCase()}.`, children: _jsx(Button, { variant: "ghost", size: "icon", onClick: onExpand, "aria-expanded": false, "aria-label": "Show the workflow card and leave focus mode", className: "ml-auto h-5 w-5", children: _jsx(ChevronDown, { size: 11 }) }) })) : (_jsx(Tooltip, { content: intro, children: _jsx(Button, { variant: "ghost", size: "icon", "aria-label": "What this screen is for", className: "ml-auto h-5 w-5", children: _jsx(Info, { size: 11 }) }) }))] }), _jsx("p", { className: "sr-only", children: intro }), _jsx(AnimatePresence, { initial: false, children: !folded && (_jsxs(motion.div, { initial: reducedMotion ? false : { height: 0, opacity: 0 }, animate: { height: 'auto', opacity: 1 }, exit: reducedMotion ? { opacity: 0 } : { height: 0, opacity: 0 },
|
|
2584
|
+
/*
|
|
2585
|
+
* A tween, and NOT the spring the rail and the outer box use.
|
|
2586
|
+
*
|
|
2587
|
+
* Two reasons, one aesthetic and one that cost an afternoon. A
|
|
2588
|
+
* spring overshoots, and a height overshooting past zero is a panel
|
|
2589
|
+
* that clips itself against its own border on the way down — the
|
|
2590
|
+
* one place on this screen where bounce reads as a glitch rather
|
|
2591
|
+
* than as life. And a spring on a height resolved from `auto` has
|
|
2592
|
+
* no analytic end: it settles by threshold, on frames. Under jsdom,
|
|
2593
|
+
* which reports no layout, it never settled at all and
|
|
2594
|
+
* `AnimatePresence` therefore never unmounted the body — so focus
|
|
2595
|
+
* mode "worked" in a browser and left the picker and the name field
|
|
2596
|
+
* in the document forever in a test. A tween ends on a clock.
|
|
2597
|
+
*/
|
|
2598
|
+
transition: reducedMotion ? { duration: 0 } : { duration: 0.22, ease: [0.32, 0.72, 0, 1] },
|
|
2599
|
+
// Or the fields spill out of the box on the way down: the height is
|
|
2600
|
+
// being animated from zero and their own height is not.
|
|
2601
|
+
className: "overflow-hidden", children: [_jsxs("div", { className: "mt-2.5 grid gap-2", children: [_jsx(SelectField, { label: WORKFLOW_NAME.title, ariaLabel: `Which ${WORKFLOW_NAME.singular} to edit`, value: selected, onValueChange: onSelect, options: workflowOptions, disabled: workflowsPending }), _jsx(TextField, { label: "Name", value: draftName, onChange: onRename, placeholder: "Fleet readiness", disabled: !canEdit })] }), _jsx(DurabilityBanner, { durability: durability })] }, "body")) })] }));
|
|
1994
2602
|
}
|
|
1995
2603
|
/**
|
|
1996
2604
|
* That there are none, said rather than drawn as a blank canvas.
|