@whity/ui 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +106 -2
- package/package.json +219 -4
- package/src/access-denied.stories.tsx +179 -0
- package/src/access-denied.tsx +305 -0
- package/src/action-proposal.tsx +338 -0
- package/src/actor-chip.tsx +71 -0
- package/src/agent-activity.tsx +163 -0
- package/src/agent-collaboration.stories.tsx +156 -0
- package/src/agent-run-status.tsx +196 -0
- package/src/alert-dialog.stories.tsx +45 -0
- package/src/alert-dialog.tsx +147 -0
- package/src/alert.stories.tsx +91 -0
- package/src/alert.tsx +89 -0
- package/src/app-sidebar.stories.tsx +195 -0
- package/src/app-sidebar.tsx +604 -0
- package/src/approval-queue.tsx +109 -0
- package/src/audience-group-picker.stories.tsx +198 -0
- package/src/audience-group-picker.tsx +362 -0
- package/src/audience-people-picker.stories.tsx +102 -0
- package/src/audience-people-picker.tsx +279 -0
- package/src/avatar-pattern.ts +138 -0
- package/src/avatar.tsx +125 -0
- package/src/badge.stories.tsx +105 -0
- package/src/badge.tsx +68 -0
- package/src/beta-warning.stories.tsx +79 -0
- package/src/beta-warning.tsx +189 -0
- package/src/bilingual-input.stories.tsx +82 -0
- package/src/bilingual-input.tsx +188 -0
- package/src/board.tsx +216 -0
- package/src/breadcrumb.stories.tsx +51 -0
- package/src/breadcrumb.tsx +90 -0
- package/src/built-on-whity.tsx +52 -0
- package/src/button.stories.tsx +87 -0
- package/src/button.tsx +123 -0
- package/src/card.stories.tsx +423 -0
- package/src/card.tsx +180 -0
- package/src/chart.stories.tsx +66 -0
- package/src/chart.tsx +228 -0
- package/src/checkbox.stories.tsx +62 -0
- package/src/checkbox.tsx +54 -0
- package/src/collapsible.stories.tsx +48 -0
- package/src/collapsible.tsx +34 -0
- package/src/color-card.stories.tsx +61 -0
- package/src/color-card.tsx +270 -0
- package/src/color-picker.stories.tsx +65 -0
- package/src/color-picker.tsx +425 -0
- package/src/column-matcher.tsx +84 -0
- package/src/command-palette.tsx +398 -0
- package/src/confirm-action.tsx +98 -0
- package/src/copy-block.stories.tsx +38 -0
- package/src/copy-block.tsx +85 -0
- package/src/data-table.stories.tsx +200 -0
- package/src/data-table.tsx +1686 -0
- package/src/date-picker.stories.tsx +61 -0
- package/src/date-picker.tsx +456 -0
- package/src/design-cards.stories.tsx +551 -0
- package/src/dialog.stories.tsx +48 -0
- package/src/dialog.tsx +179 -0
- package/src/display-preferences.tsx +50 -0
- package/src/documents/barcode-svg.stories.tsx +72 -0
- package/src/documents/barcode-svg.tsx +79 -0
- package/src/dropdown-menu.stories.tsx +77 -0
- package/src/dropdown-menu.tsx +271 -0
- package/src/editor/agent-panel.tsx +222 -0
- package/src/editor/agents.stories.tsx +81 -0
- package/src/editor/agents.ts +55 -0
- package/src/editor/behaviour.ts +279 -0
- package/src/editor/block-ids.ts +44 -0
- package/src/editor/block-list.tsx +104 -0
- package/src/editor/block-toolbar.tsx +490 -0
- package/src/editor/bubble.tsx +119 -0
- package/src/editor/catalogue.ts +169 -0
- package/src/editor/collab-rail.tsx +746 -0
- package/src/editor/collab.stories.tsx +207 -0
- package/src/editor/collab.ts +87 -0
- package/src/editor/contract.ts +476 -0
- package/src/editor/convert.ts +414 -0
- package/src/editor/doc-editor.stories.tsx +98 -0
- package/src/editor/doc-editor.tsx +1492 -0
- package/src/editor/editor.css +636 -0
- package/src/editor/extensions.ts +86 -0
- package/src/editor/field-bar.tsx +154 -0
- package/src/editor/field-picker.tsx +109 -0
- package/src/editor/fields.ts +100 -0
- package/src/editor/gutter.tsx +443 -0
- package/src/editor/index.ts +23 -0
- package/src/editor/label-sheet.tsx +289 -0
- package/src/editor/labels.ts +394 -0
- package/src/editor/link-tools.tsx +141 -0
- package/src/editor/node-views.tsx +461 -0
- package/src/editor/page-view.tsx +372 -0
- package/src/editor/phone.tsx +310 -0
- package/src/editor/plugin-block-view.tsx +230 -0
- package/src/editor/plugin-blocks.stories.tsx +96 -0
- package/src/editor/plugin-blocks.ts +52 -0
- package/src/editor/publish-check.tsx +201 -0
- package/src/editor/rich-blocks.stories.tsx +146 -0
- package/src/editor/sample.ts +40 -0
- package/src/editor/save-block-dialog.tsx +141 -0
- package/src/editor/saved-block-view.tsx +205 -0
- package/src/editor/saved-blocks.stories.tsx +105 -0
- package/src/editor/saved-parts.ts +192 -0
- package/src/editor/schema-rich.ts +156 -0
- package/src/editor/schema.ts +368 -0
- package/src/editor/services.tsx +205 -0
- package/src/editor/slash.ts +64 -0
- package/src/editor/suggesting.ts +372 -0
- package/src/editor/suggestions.ts +763 -0
- package/src/editor/table-keys.ts +66 -0
- package/src/editor/templates.stories.tsx +324 -0
- package/src/editor/toolbar.tsx +364 -0
- package/src/empty-state.stories.tsx +51 -0
- package/src/empty-state.tsx +126 -0
- package/src/empty-state.usage-notes.md +30 -0
- package/src/form.stories.tsx +112 -0
- package/src/form.tsx +176 -0
- package/src/globals.css +20 -0
- package/src/icon-button.tsx +85 -0
- package/src/icon-map.ts +335 -0
- package/src/icon.tsx +41 -0
- package/src/index.ts +90 -0
- package/src/input.stories.tsx +157 -0
- package/src/input.tsx +768 -0
- package/src/kpi-strip.tsx +47 -0
- package/src/localized-text.ts +76 -0
- package/src/locked-screen.stories.tsx +29 -0
- package/src/locked-screen.tsx +75 -0
- package/src/lockup.tsx +42 -0
- package/src/lottie.tsx +441 -0
- package/src/mark.tsx +62 -0
- package/src/math-text.stories.tsx +33 -0
- package/src/math-text.tsx +43 -0
- package/src/menu-bar.stories.tsx +198 -0
- package/src/menu-bar.tsx +373 -0
- package/src/message-thread.tsx +181 -0
- package/src/money/currency.ts +244 -0
- package/src/money/money-input.tsx +131 -0
- package/src/money/money.tsx +33 -0
- package/src/open-on-computer.tsx +150 -0
- package/src/otp-input.tsx +161 -0
- package/src/page-header.stories.tsx +95 -0
- package/src/page-header.tsx +122 -0
- package/src/page-shell.stories.tsx +42 -0
- package/src/page-shell.tsx +32 -0
- package/src/page-states.tsx +277 -0
- package/src/pagination.stories.tsx +45 -0
- package/src/pagination.tsx +98 -0
- package/src/paper-sheet.stories.tsx +88 -0
- package/src/paper-sheet.tsx +85 -0
- package/src/phone-tab-bar.tsx +152 -0
- package/src/plugin-card.stories.tsx +208 -0
- package/src/plugin-card.tsx +931 -0
- package/src/popover.stories.tsx +48 -0
- package/src/popover.tsx +55 -0
- package/src/radio-group.stories.tsx +26 -0
- package/src/radio-group.tsx +44 -0
- package/src/route-flow/editor.tsx +1087 -0
- package/src/route-flow/model.ts +771 -0
- package/src/save-bar.tsx +94 -0
- package/src/scope-grant.tsx +139 -0
- package/src/screen-too-small.stories.tsx +61 -0
- package/src/screen-too-small.tsx +104 -0
- package/src/search-field.tsx +65 -0
- package/src/select.stories.tsx +44 -0
- package/src/select.tsx +197 -0
- package/src/separator.stories.tsx +34 -0
- package/src/separator.tsx +34 -0
- package/src/sheet.stories.tsx +49 -0
- package/src/sheet.tsx +168 -0
- package/src/skeleton.stories.tsx +28 -0
- package/src/skeleton.tsx +19 -0
- package/src/slider.stories.tsx +78 -0
- package/src/slider.tsx +300 -0
- package/src/spinner.stories.tsx +33 -0
- package/src/spinner.tsx +55 -0
- package/src/stepper.tsx +85 -0
- package/src/switch.stories.tsx +42 -0
- package/src/switch.tsx +41 -0
- package/src/switcher.stories.tsx +111 -0
- package/src/switcher.tsx +131 -0
- package/src/system-state.tsx +55 -0
- package/src/table.stories.tsx +48 -0
- package/src/table.tsx +121 -0
- package/src/tabs.stories.tsx +74 -0
- package/src/tabs.tsx +90 -0
- package/src/tag-input.stories.tsx +67 -0
- package/src/tag-input.tsx +117 -0
- package/src/tenant-logo.tsx +63 -0
- package/src/tenant-switcher.stories.tsx +38 -0
- package/src/tenant-switcher.tsx +164 -0
- package/src/textarea.stories.tsx +27 -0
- package/src/textarea.tsx +18 -0
- package/src/theme-mode.ts +52 -0
- package/src/time-grid.tsx +163 -0
- package/src/time-picker.stories.tsx +62 -0
- package/src/time-picker.tsx +615 -0
- package/src/toggle-group.tsx +138 -0
- package/src/tooltip.stories.tsx +43 -0
- package/src/tooltip.tsx +73 -0
- package/src/top-nav.stories.tsx +58 -0
- package/src/top-nav.tsx +324 -0
- package/src/undo-bar.tsx +107 -0
- package/src/utils.ts +45 -0
- package/src/view-toggle.stories.tsx +84 -0
- package/src/view-toggle.tsx +110 -0
|
@@ -0,0 +1,1087 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import {
|
|
5
|
+
Background,
|
|
6
|
+
BackgroundVariant,
|
|
7
|
+
BaseEdge,
|
|
8
|
+
Controls,
|
|
9
|
+
Handle,
|
|
10
|
+
MarkerType,
|
|
11
|
+
Panel,
|
|
12
|
+
Position,
|
|
13
|
+
ReactFlow,
|
|
14
|
+
getBezierPath,
|
|
15
|
+
useNodesState,
|
|
16
|
+
type Connection,
|
|
17
|
+
type Edge,
|
|
18
|
+
type EdgeProps,
|
|
19
|
+
type EdgeTypes,
|
|
20
|
+
type Node,
|
|
21
|
+
type NodeProps,
|
|
22
|
+
type NodeTypes,
|
|
23
|
+
type ReactFlowInstance,
|
|
24
|
+
} from '@xyflow/react';
|
|
25
|
+
import '@xyflow/react/dist/style.css';
|
|
26
|
+
import { cn } from '../utils';
|
|
27
|
+
import {
|
|
28
|
+
ROUTE_FLOW_MAX_NODES,
|
|
29
|
+
ROUTE_FLOW_MAX_NOTES,
|
|
30
|
+
ROUTE_FLOW_NODE_HEIGHT,
|
|
31
|
+
ROUTE_FLOW_NODE_WIDTH,
|
|
32
|
+
autoLayout,
|
|
33
|
+
effectiveQuorum,
|
|
34
|
+
handleFaces,
|
|
35
|
+
needsAutoLayout,
|
|
36
|
+
nextSlot,
|
|
37
|
+
notesFor,
|
|
38
|
+
renumber,
|
|
39
|
+
resolveTransitions,
|
|
40
|
+
stepsInOrder,
|
|
41
|
+
type RouteFlowAudience,
|
|
42
|
+
type RouteFlowDirection,
|
|
43
|
+
type RouteFlowGraph,
|
|
44
|
+
type RouteFlowOrientation,
|
|
45
|
+
type RouteFlowStep,
|
|
46
|
+
type RouteFlowVerdict,
|
|
47
|
+
} from './model';
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* The node-based editor for document route flows (#1027).
|
|
51
|
+
*
|
|
52
|
+
* ─────────────────────────────────────────────────────────────────────────
|
|
53
|
+
* WHY THIS IS NOT THE `flow` BLOCK
|
|
54
|
+
* ─────────────────────────────────────────────────────────────────────────
|
|
55
|
+
* #950 already ships a `flow` block, and it was the first thing checked. It is
|
|
56
|
+
* not reusable here, for reasons that are properties of its contract rather than
|
|
57
|
+
* gaps in its implementation:
|
|
58
|
+
*
|
|
59
|
+
* - IT IS READ-ONLY BY DESIGN. Its canvas sets `nodesConnectable={false}` and
|
|
60
|
+
* `elementsSelectable={false}`, and its own comment says why: "`flow` is
|
|
61
|
+
* read-only, so a drag must never be able to look like it created an edge."
|
|
62
|
+
* Making it editable would not extend it; it would retire the guarantee.
|
|
63
|
+
* - IT IS DATA-BOUND TO A URL. A block declares a `source` and renders whatever
|
|
64
|
+
* comes back. An editor's graph is local, mutable state that is saved as one
|
|
65
|
+
* document, which is a different lifecycle, not a different fetch.
|
|
66
|
+
* - IT LIVES IN `web/components/plugin/blocks/`, so it ships to one of three
|
|
67
|
+
* clients. A graph editor is precisely the component the second one wants.
|
|
68
|
+
*
|
|
69
|
+
* What it DID give, and what is taken from it rather than re-decided: the
|
|
70
|
+
* composition that works (custom node cards, dotted background, `Controls`,
|
|
71
|
+
* attribution hidden, `minZoom` low enough that `fitView` does not clip), and
|
|
72
|
+
* the node ceiling — {@link ROUTE_FLOW_MAX_NODES} mirrors its
|
|
73
|
+
* `BlockContract::FLOW_MAX_NODES` rather than inventing a second number for the
|
|
74
|
+
* same question.
|
|
75
|
+
*
|
|
76
|
+
* ─────────────────────────────────────────────────────────────────────────
|
|
77
|
+
* A NODE IS A TYPE, AND THIS COMPONENT CANNOT MAKE IT ANYTHING ELSE
|
|
78
|
+
* ─────────────────────────────────────────────────────────────────────────
|
|
79
|
+
* One node per RULE. "Everyone holding Instructor" is one card whether it
|
|
80
|
+
* resolves to four people or four thousand, and there is no code path here that
|
|
81
|
+
* expands a rule into people — {@link RouteFlowStep} has no field that could hold
|
|
82
|
+
* them.
|
|
83
|
+
*
|
|
84
|
+
* How big a node is comes in through {@link RouteFlowEditorProps.audienceFor},
|
|
85
|
+
* which a HOST answers from the server's existing preview. The card shows the
|
|
86
|
+
* COUNT and never a roster, and where the host cannot resolve one it shows the
|
|
87
|
+
* host's reason instead of a zero — a zero would read as "this reaches nobody",
|
|
88
|
+
* which is a different and much more alarming statement than "you cannot see
|
|
89
|
+
* this".
|
|
90
|
+
*
|
|
91
|
+
* ─────────────────────────────────────────────────────────────────────────
|
|
92
|
+
* NO TRANSLATOR, NO FETCH, NO ROUTER
|
|
93
|
+
* ─────────────────────────────────────────────────────────────────────────
|
|
94
|
+
* Every string a person reads is a prop with an English default
|
|
95
|
+
* ({@link RouteFlowEditorLabels}), because a kit component that imported a
|
|
96
|
+
* translator would bind three clients to one app's i18n runtime. Rule kinds are
|
|
97
|
+
* turned into human labels by {@link RouteFlowEditorProps.ruleLabelFor}, because
|
|
98
|
+
* the catalogue of kinds is a server fact and includes whatever plugins the host
|
|
99
|
+
* has installed.
|
|
100
|
+
*
|
|
101
|
+
* The INSPECTOR — choosing a rule kind, picking a group, setting a quorum — is
|
|
102
|
+
* deliberately not here. Those need pickers bound to the host's own APIs, and one
|
|
103
|
+
* of them (the group picker) is being built as its own kit component. This
|
|
104
|
+
* component owns the CANVAS and reports selection; the host renders the panel.
|
|
105
|
+
*/
|
|
106
|
+
|
|
107
|
+
export interface RouteFlowEditorLabels {
|
|
108
|
+
/** Shown on the canvas when the flow has no steps at all. */
|
|
109
|
+
empty: string;
|
|
110
|
+
addStep: string;
|
|
111
|
+
deleteStep: string;
|
|
112
|
+
/** Badge on a step that demands a verdict. */
|
|
113
|
+
decision: string;
|
|
114
|
+
/**
|
|
115
|
+
* Badge on a step that TELLS its people rather than asking them (#1054).
|
|
116
|
+
*
|
|
117
|
+
* Worded as what the stage does to the reader's document, not as the wire
|
|
118
|
+
* value: "delivery" is the engine's word for the mechanism, and a canvas that
|
|
119
|
+
* printed it would make an author guess whether it meant postage.
|
|
120
|
+
*/
|
|
121
|
+
delivery: string;
|
|
122
|
+
/**
|
|
123
|
+
* Badge on the stage that makes the final document (WHIT-921). Optional so a
|
|
124
|
+
* host that offers no such stage need not translate it.
|
|
125
|
+
*/
|
|
126
|
+
finalise?: string;
|
|
127
|
+
/** Prefix for the resolved audience, e.g. "reaches 1,043 people". */
|
|
128
|
+
reaches: string;
|
|
129
|
+
people: string;
|
|
130
|
+
/**
|
|
131
|
+
* The singular of {@link RouteFlowEditorLabels.people}.
|
|
132
|
+
*
|
|
133
|
+
* A separate label rather than a rule applied to `people`, because which
|
|
134
|
+
* counts take which form is a property of the LANGUAGE and not of this
|
|
135
|
+
* component: English splits at one, Arabic splits at one, two and eleven. A
|
|
136
|
+
* host with a plural-aware translator passes the form its own rules chose;
|
|
137
|
+
* this only ever asks for "the word for a count of 1".
|
|
138
|
+
*/
|
|
139
|
+
person: string;
|
|
140
|
+
/** Shown in place of a count the host could not resolve and gave no reason for. */
|
|
141
|
+
audienceUnavailable: string;
|
|
142
|
+
approved: string;
|
|
143
|
+
rejected: string;
|
|
144
|
+
/** The unconditional advance out of a non-decision step. */
|
|
145
|
+
continues: string;
|
|
146
|
+
/** Marker on a transition the engine takes that nobody drew. */
|
|
147
|
+
implicit: string;
|
|
148
|
+
/** Marker where a chain stops. */
|
|
149
|
+
ends: string;
|
|
150
|
+
/** The pill at the top: where a document enters the route. */
|
|
151
|
+
start?: string;
|
|
152
|
+
/**
|
|
153
|
+
* Marker on a stage that more than one path reaches.
|
|
154
|
+
*
|
|
155
|
+
* Says that arrivals MERGE, and states the RULE by which they do: the engine
|
|
156
|
+
* de-duplicates PER PERSON, so a stage holds one item per person no matter
|
|
157
|
+
* how many paths reached them. Without the marker, two arrows entering a box
|
|
158
|
+
* read as two things carrying on through it, which is not what happens.
|
|
159
|
+
*
|
|
160
|
+
* IT USED TO SAY "settles once", WHICH WAS FALSE HALF THE TIME (#1058). That
|
|
161
|
+
* holds only while both arrivals reach the SAME people — then the second
|
|
162
|
+
* de-duplicates against an item they already hold and the stage settles once.
|
|
163
|
+
* When the stage's rule is actor-relative the arrivals reach DIFFERENT people,
|
|
164
|
+
* nothing de-duplicates, and the stage settles twice, each settlement opening
|
|
165
|
+
* its own continuation.
|
|
166
|
+
*
|
|
167
|
+
* And that is the likely case, not the exotic one: an actor-relative rule
|
|
168
|
+
* upstream is usually what put two chains there to begin with. So the canvas
|
|
169
|
+
* was most confident exactly where it was least accurate — the same failure
|
|
170
|
+
* as #1042, a picture becoming false by compression, in a shape a reviewer
|
|
171
|
+
* will not question because it looks authoritative.
|
|
172
|
+
*
|
|
173
|
+
* Per-person is true in BOTH cases and is the mechanism rather than one of its
|
|
174
|
+
* outcomes, so an author can work out which case they are in: if the two paths
|
|
175
|
+
* reach the same people it settles once, and if they do not it settles once
|
|
176
|
+
* each. `RouteFlowResolution.merges` says the same thing as "once per COHORT";
|
|
177
|
+
* this is that sentence in words an author of a route already has.
|
|
178
|
+
*
|
|
179
|
+
* WHY THIS LABEL IS NOT CONDITIONAL, WHICH WAS #1058's PREFERRED FIX. The
|
|
180
|
+
* canvas would have to know whether the stage's rule resolves against the
|
|
181
|
+
* ACTOR, and no truthful version of that flag exists to pass it:
|
|
182
|
+
*
|
|
183
|
+
* - Per KIND is wrong for a kind core already ships. `group` dereferences a
|
|
184
|
+
* stored user group, and a group whose own definition is `role_below_actor`
|
|
185
|
+
* is actor-relative while one defined as `role` is not — so the answer for
|
|
186
|
+
* `group` lives in another tenant record, behind `groups:read`, which an
|
|
187
|
+
* author of a route does not necessarily hold. A per-kind boolean would
|
|
188
|
+
* have to lie about `group` in one direction or the other.
|
|
189
|
+
* - The other branch would be wrong too, and not rarely. De-duplication is
|
|
190
|
+
* over OPEN items (migration 112's partial unique index), so even a rule
|
|
191
|
+
* that never reads the actor settles TWICE when the second arrival lands
|
|
192
|
+
* after the first cohort closed — a fan-out where one recipient approves
|
|
193
|
+
* straight into the merge and another rejects the long way round does
|
|
194
|
+
* exactly that. "Not actor-relative, therefore settles once" is the same
|
|
195
|
+
* compression as "settles once", one level down.
|
|
196
|
+
*
|
|
197
|
+
* So a conditional card note would replace one confident falsehood with two
|
|
198
|
+
* quieter ones. The mechanism is the only claim that survives both, and the
|
|
199
|
+
* CASE DISTINCTION is stated where there is room to hedge it honestly: the
|
|
200
|
+
* host's stage inspector (`routeTemplates.inspector.merges`), which is open on
|
|
201
|
+
* the very stage in question at the moment its rule is being chosen.
|
|
202
|
+
*
|
|
203
|
+
* LENGTH IS LOAD-BEARING. Notes are joined into one span clamped to
|
|
204
|
+
* {@link ROUTE_FLOW_MAX_NOTES} lines, so a longer string here pushes a later
|
|
205
|
+
* note off the card — which is #1042 exactly. The replacement is the same
|
|
206
|
+
* length as what it replaces.
|
|
207
|
+
*/
|
|
208
|
+
arrivalsMerge: string;
|
|
209
|
+
/**
|
|
210
|
+
* Marker on a stage a document can come back round to.
|
|
211
|
+
*
|
|
212
|
+
* Says a LOOP exists in the design — not that any document has gone round it,
|
|
213
|
+
* which the canvas cannot know. Worth stating because a rework loop is
|
|
214
|
+
* authored deliberately and is invisible afterwards: nothing counts laps
|
|
215
|
+
* (#1037), so a document on its ninth rejection looks like one on its first.
|
|
216
|
+
*/
|
|
217
|
+
inCycle: string;
|
|
218
|
+
/** Prefix for the effective quorum, e.g. "all must approve". */
|
|
219
|
+
quorumAll: string;
|
|
220
|
+
quorumAny: string;
|
|
221
|
+
quorumMajority: string;
|
|
222
|
+
/** Optional so older callers keep working; falls back to the English. */
|
|
223
|
+
quorumFirst?: string;
|
|
224
|
+
/** Shown when the graph is larger than the ceiling and has been cut. */
|
|
225
|
+
tooManyNodes: string;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
const DEFAULT_LABELS: RouteFlowEditorLabels = {
|
|
229
|
+
empty: 'No stages yet. Add the first one to start the flow.',
|
|
230
|
+
addStep: 'Add stage',
|
|
231
|
+
deleteStep: 'Delete stage',
|
|
232
|
+
decision: 'Decision',
|
|
233
|
+
delivery: 'Sent, not asked',
|
|
234
|
+
reaches: 'Reaches',
|
|
235
|
+
people: 'people',
|
|
236
|
+
person: 'person',
|
|
237
|
+
audienceUnavailable: 'Audience size unavailable',
|
|
238
|
+
approved: 'Approved',
|
|
239
|
+
rejected: 'Rejected',
|
|
240
|
+
continues: 'Continues',
|
|
241
|
+
implicit: 'implicit',
|
|
242
|
+
ends: 'Ends here',
|
|
243
|
+
start: 'A document is sent',
|
|
244
|
+
arrivalsMerge: 'Paths merge — 1 item per person',
|
|
245
|
+
inCycle: 'Can come back round — loops',
|
|
246
|
+
quorumAll: 'all must approve',
|
|
247
|
+
quorumAny: 'any one may approve',
|
|
248
|
+
quorumMajority: 'a majority must approve',
|
|
249
|
+
tooManyNodes: 'This flow is larger than the canvas will draw. Showing the first stages only.',
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
export interface RouteFlowEditorProps {
|
|
253
|
+
graph: RouteFlowGraph;
|
|
254
|
+
/**
|
|
255
|
+
* Called with the whole next graph on every edit.
|
|
256
|
+
*
|
|
257
|
+
* The whole graph, not a patch: the editor's unit of work is the canvas, and a
|
|
258
|
+
* patch would ask the host to re-apply changes it did not make.
|
|
259
|
+
*/
|
|
260
|
+
onGraphChange?: (graph: RouteFlowGraph) => void;
|
|
261
|
+
/** The step the host's inspector is editing, by `position`. */
|
|
262
|
+
selectedPosition?: number | null;
|
|
263
|
+
onSelectStep?: (position: number | null) => void;
|
|
264
|
+
/**
|
|
265
|
+
* Direction-NEUTRAL by default. See `positionStep` in the model for the full
|
|
266
|
+
* argument: a top-to-bottom flow reads identically in Arabic and English.
|
|
267
|
+
*/
|
|
268
|
+
orientation?: RouteFlowOrientation;
|
|
269
|
+
/**
|
|
270
|
+
* The reading direction. Mirrors every horizontal axis, including the handles,
|
|
271
|
+
* so an arrow leaves the face a reader expects it to leave.
|
|
272
|
+
*
|
|
273
|
+
* "Including the handles" is load-bearing and was, for a while, untrue.
|
|
274
|
+
* `@xyflow/react` sets `direction: ltr` on its own container — deliberately,
|
|
275
|
+
* because its transforms are computed in one coordinate system — and that
|
|
276
|
+
* neutralises `insetInlineStart` on anything inside it. The verdict handles
|
|
277
|
+
* were positioned with exactly that property, so they stayed at 30% and 70%
|
|
278
|
+
* from the LEFT in Arabic while {@link slotAt} put the reject lane on the
|
|
279
|
+
* left, which is the "mirrored layout, unmirrored handles" failure
|
|
280
|
+
* {@link handleFaces} warns about: the reject arrow left the far side of its
|
|
281
|
+
* own card and crossed back underneath it.
|
|
282
|
+
*
|
|
283
|
+
* They are placed with a physical `left`, mirrored arithmetically from this
|
|
284
|
+
* prop, so the mirroring does not depend on a container's inherited direction.
|
|
285
|
+
* The card carries its own `dir` for the same reason — `text-start` inside the
|
|
286
|
+
* canvas would otherwise resolve to "left" and left-align Arabic.
|
|
287
|
+
*/
|
|
288
|
+
direction?: RouteFlowDirection;
|
|
289
|
+
/**
|
|
290
|
+
* The most nodes to draw. Defaults to {@link ROUTE_FLOW_MAX_NODES}; a host that
|
|
291
|
+
* knows its tenant's `documents.routing_max_steps` should pass it, because THAT
|
|
292
|
+
* is the authoritative limit on how many steps may be saved.
|
|
293
|
+
*/
|
|
294
|
+
maxNodes?: number;
|
|
295
|
+
readOnly?: boolean;
|
|
296
|
+
/** How many people a step's rule currently reaches, resolved by the host. */
|
|
297
|
+
audienceFor?: (step: RouteFlowStep) => RouteFlowAudience | undefined;
|
|
298
|
+
/** A human label for a rule kind — the catalogue is a server fact. */
|
|
299
|
+
ruleLabelFor?: (step: RouteFlowStep) => string;
|
|
300
|
+
labels?: Partial<RouteFlowEditorLabels>;
|
|
301
|
+
className?: string;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
interface RouteFlowNodeData extends Record<string, unknown> {
|
|
305
|
+
step: RouteFlowStep;
|
|
306
|
+
quorumText: string;
|
|
307
|
+
ruleLabel: string;
|
|
308
|
+
audience: RouteFlowAudience | undefined;
|
|
309
|
+
selected: boolean;
|
|
310
|
+
readOnly: boolean;
|
|
311
|
+
notes: string[];
|
|
312
|
+
labels: RouteFlowEditorLabels;
|
|
313
|
+
direction: RouteFlowDirection;
|
|
314
|
+
sourceFace: Position;
|
|
315
|
+
targetFace: Position;
|
|
316
|
+
onSelect: (position: number) => void;
|
|
317
|
+
onDelete: (position: number) => void;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* How big a handle is drawn.
|
|
322
|
+
*
|
|
323
|
+
* `@xyflow/react`'s default is 6×6 CSS px, which the canvas zoom then shrinks:
|
|
324
|
+
* at the zoom a four-stage flow fits at, the measured target was 5.4px on
|
|
325
|
+
* screen. Starting an edge meant hitting a 5px dot, and the alternative gesture
|
|
326
|
+
* a person tries first — dropping on the target CARD — does nothing, because a
|
|
327
|
+
* connection has to end on a handle. 12px is a target a hand can find, and it is
|
|
328
|
+
* still small enough that two of them sit on one 224px face without touching.
|
|
329
|
+
*
|
|
330
|
+
* The other half of that fix is {@link CONNECTION_RADIUS}.
|
|
331
|
+
*/
|
|
332
|
+
const HANDLE_CLASS = '!h-3 !w-3 !border-2 !border-card !bg-muted-foreground/60';
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* How far from a handle a drop still counts as landing on it.
|
|
336
|
+
*
|
|
337
|
+
* `@xyflow/react` defaults to 20px, so a connection had to be released within
|
|
338
|
+
* 20px of a 5px dot; releasing over the target CARD — the gesture people try
|
|
339
|
+
* first — did nothing at all, and did it silently.
|
|
340
|
+
*
|
|
341
|
+
* Widened to reach from the target handle (top-centre of a card) across most of
|
|
342
|
+
* the card it belongs to, so dropping ON the node connects. Deliberately NOT
|
|
343
|
+
* wide enough to span the gap to the next node: {@link ROUTE_FLOW_NODE_HEIGHT}
|
|
344
|
+
* plus its layout gap is the distance between two stages, and this is well
|
|
345
|
+
* inside half of that, so a drop is never claimed by the card an author was not
|
|
346
|
+
* pointing at.
|
|
347
|
+
*/
|
|
348
|
+
const CONNECTION_RADIUS = 80;
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* Where a verdict handle sits along the source face, as a physical inset.
|
|
352
|
+
*
|
|
353
|
+
* PHYSICAL, not logical. `insetInlineStart` would be the idiomatic choice and it
|
|
354
|
+
* is the one that was here; it does not work, because `@xyflow/react` forces
|
|
355
|
+
* `direction: ltr` on its container and a logical inset resolves against that
|
|
356
|
+
* rather than against the document. So the mirroring is done here, from the
|
|
357
|
+
* direction the host passed, where nothing can quietly undo it.
|
|
358
|
+
*/
|
|
359
|
+
function verdictInset(
|
|
360
|
+
direction: RouteFlowDirection,
|
|
361
|
+
percentFromReadingStart: number
|
|
362
|
+
): React.CSSProperties {
|
|
363
|
+
// Mirrored by arithmetic and still written as `left`, NOT by switching to
|
|
364
|
+
// `right`. `@xyflow/react` centres a handle on its inset with a
|
|
365
|
+
// `translateX(-50%)` of its own; anchoring from the other edge leaves that
|
|
366
|
+
// translation pulling the wrong way and lands the handle half its own width
|
|
367
|
+
// off — measured 0.65 where 0.70 was meant. One physical property, one
|
|
368
|
+
// percentage, nothing left for a transform to disagree with.
|
|
369
|
+
const fromLeft = direction === 'rtl' ? 100 - percentFromReadingStart : percentFromReadingStart;
|
|
370
|
+
|
|
371
|
+
return { left: `${fromLeft}%` };
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
const FACE: Record<string, Position> = {
|
|
375
|
+
top: Position.Top,
|
|
376
|
+
bottom: Position.Bottom,
|
|
377
|
+
left: Position.Left,
|
|
378
|
+
right: Position.Right,
|
|
379
|
+
};
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* One stage.
|
|
383
|
+
*
|
|
384
|
+
* A DECISION step carries TWO source handles — one per verdict — and an ordinary
|
|
385
|
+
* step carries one. That is what makes "draw the approve edge and the reject
|
|
386
|
+
* edge from one node" a gesture rather than a form: which handle a drag starts
|
|
387
|
+
* from IS the verdict, so an author never picks it from a menu afterwards and
|
|
388
|
+
* the two arrows are visibly different before they are drawn.
|
|
389
|
+
*
|
|
390
|
+
* A non-decision step gets no verdict handles at all, because an edge leaving one
|
|
391
|
+
* could never fire — the server refuses it, and an affordance that produces a
|
|
392
|
+
* refusal is worse than no affordance.
|
|
393
|
+
*/
|
|
394
|
+
function RouteFlowNodeCard({ data }: NodeProps<Node<RouteFlowNodeData>>) {
|
|
395
|
+
const {
|
|
396
|
+
step,
|
|
397
|
+
quorumText,
|
|
398
|
+
ruleLabel,
|
|
399
|
+
audience,
|
|
400
|
+
selected,
|
|
401
|
+
readOnly,
|
|
402
|
+
notes,
|
|
403
|
+
labels,
|
|
404
|
+
direction,
|
|
405
|
+
sourceFace,
|
|
406
|
+
targetFace,
|
|
407
|
+
onSelect,
|
|
408
|
+
onDelete,
|
|
409
|
+
} = data;
|
|
410
|
+
|
|
411
|
+
const title = step.label !== null && step.label !== '' ? step.label : ruleLabel;
|
|
412
|
+
|
|
413
|
+
return (
|
|
414
|
+
<div
|
|
415
|
+
// The card carries its OWN `dir`. `@xyflow/react` forces `direction: ltr`
|
|
416
|
+
// on its container, so without this every `text-start` and every `end-*`
|
|
417
|
+
// inside a node resolves to the left-to-right answer and Arabic labels sit
|
|
418
|
+
// left-aligned in a right-to-left page.
|
|
419
|
+
dir={direction}
|
|
420
|
+
className={cn(
|
|
421
|
+
'flex flex-col gap-1 rounded-lg border bg-card px-3 py-2 text-start shadow-sm transition-colors',
|
|
422
|
+
selected ? 'border-primary ring-2 ring-primary/30' : 'border-border'
|
|
423
|
+
)}
|
|
424
|
+
style={{ width: ROUTE_FLOW_NODE_WIDTH, height: ROUTE_FLOW_NODE_HEIGHT }}
|
|
425
|
+
data-slot="route-flow-node"
|
|
426
|
+
data-position={step.position}
|
|
427
|
+
data-decision={step.decision ? 'true' : 'false'}
|
|
428
|
+
data-satisfied-by={step.satisfiedBy}
|
|
429
|
+
data-kind={step.kind ?? undefined}
|
|
430
|
+
>
|
|
431
|
+
<Handle type="target" position={targetFace} className={HANDLE_CLASS} />
|
|
432
|
+
|
|
433
|
+
<button
|
|
434
|
+
type="button"
|
|
435
|
+
onClick={() => onSelect(step.position)}
|
|
436
|
+
className="flex min-w-0 flex-col text-start outline-none focus-visible:ring-2 focus-visible:ring-ring/40"
|
|
437
|
+
>
|
|
438
|
+
<span className="flex items-center gap-1.5">
|
|
439
|
+
<span className="truncate text-sm font-medium text-foreground">{title}</span>
|
|
440
|
+
{step.decision && (
|
|
441
|
+
<span className="shrink-0 rounded bg-primary/10 px-1 text-xs font-medium uppercase text-primary">
|
|
442
|
+
{labels.decision}
|
|
443
|
+
</span>
|
|
444
|
+
)}
|
|
445
|
+
{/* A BADGE, NOT A NOTE, and that is a height decision rather than a
|
|
446
|
+
style one. The card's height is DERIVED from its rows and the note
|
|
447
|
+
clamp is derived from ROUTE_FLOW_MAX_NOTES, whose value is a
|
|
448
|
+
PROVEN maximum over what notesFor() can emit — a fourth note would
|
|
449
|
+
make the card silently drop one, which is exactly the #1042 defect
|
|
450
|
+
those derivations were built to prevent.
|
|
451
|
+
|
|
452
|
+
A delivery stage is never a decision stage (the server refuses the
|
|
453
|
+
pair at three layers), so the two badges can never both appear and
|
|
454
|
+
the title row cannot grow because of this. */}
|
|
455
|
+
{step.satisfiedBy === 'delivery' && (
|
|
456
|
+
<span
|
|
457
|
+
className="shrink-0 rounded bg-muted px-1 text-xs font-medium uppercase text-muted-foreground"
|
|
458
|
+
data-slot="route-flow-node-delivery-badge"
|
|
459
|
+
>
|
|
460
|
+
{labels.delivery}
|
|
461
|
+
</span>
|
|
462
|
+
)}
|
|
463
|
+
{/* WHIT-921: never a decision and never a delivery, so this badge
|
|
464
|
+
cannot share the row with either. */}
|
|
465
|
+
{step.kind === 'finalise' && labels.finalise !== undefined && (
|
|
466
|
+
<span
|
|
467
|
+
className="shrink-0 rounded bg-muted px-1 text-xs font-medium uppercase text-muted-foreground"
|
|
468
|
+
data-slot="route-flow-node-finalise-badge"
|
|
469
|
+
>
|
|
470
|
+
{labels.finalise}
|
|
471
|
+
</span>
|
|
472
|
+
)}
|
|
473
|
+
</span>
|
|
474
|
+
{/* The RULE, always visible. A card that showed only an author's label
|
|
475
|
+
would let "Dean" sit on a node that actually reaches every registrar,
|
|
476
|
+
and nothing on screen would say so. */}
|
|
477
|
+
<span className="truncate text-xs text-muted-foreground">{ruleLabel}</span>
|
|
478
|
+
</button>
|
|
479
|
+
|
|
480
|
+
{/* THE COUNT, NEVER A ROSTER — the line that makes a type-node honest: one
|
|
481
|
+
card, and the number of people behind it. */}
|
|
482
|
+
<span className="truncate text-xs text-muted-foreground">
|
|
483
|
+
{audience === undefined
|
|
484
|
+
? ' '
|
|
485
|
+
: audience.count !== null
|
|
486
|
+
? `${labels.reaches} ${audience.count.toLocaleString()} ${
|
|
487
|
+
audience.count === 1 ? labels.person : labels.people
|
|
488
|
+
}`
|
|
489
|
+
: (audience.unavailableReason ?? labels.audienceUnavailable)}
|
|
490
|
+
</span>
|
|
491
|
+
|
|
492
|
+
{/* THE QUORUM, on its own row.
|
|
493
|
+
|
|
494
|
+
It is shown for every decision stage, INDEPENDENTLY of whether the
|
|
495
|
+
count resolved. It used to be rendered inside the count branch, so a
|
|
496
|
+
viewer who could not preview audiences (a 403 there is ordinary — the
|
|
497
|
+
draft preview needs `groups:write`, which designing a flow does not
|
|
498
|
+
imply) saw a gate with no indication of what would satisfy it. The two
|
|
499
|
+
facts have different sources and only one of them can fail; binding
|
|
500
|
+
them together made the reliable one vanish with the unreliable one.
|
|
501
|
+
|
|
502
|
+
It was then joined onto the COUNT's line with a separator, and the pair
|
|
503
|
+
overflowed one 224px row: "Reaches 1 people · all must appr…" — a
|
|
504
|
+
quorum made unconditionally visible and then truncated mid-word, which
|
|
505
|
+
is the same disappearance by a slower route (#1042). Its own row costs
|
|
506
|
+
16px of a height that is now derived from the rows it holds, and no
|
|
507
|
+
audience string can crowd it out. */}
|
|
508
|
+
<span className="truncate text-xs text-muted-foreground">
|
|
509
|
+
{step.decision ? quorumText : ' '}
|
|
510
|
+
</span>
|
|
511
|
+
|
|
512
|
+
{notes.length > 0 && (
|
|
513
|
+
<span
|
|
514
|
+
data-slot="route-flow-notes"
|
|
515
|
+
// Clamped from the SAME constant the card's height is budgeted against
|
|
516
|
+
// (see ROUTE_FLOW_MAX_NOTES). Tailwind's `line-clamp-N` is a static
|
|
517
|
+
// class and could only repeat the number as a literal, which is
|
|
518
|
+
// precisely how the two drifted apart: the height was raised to hold
|
|
519
|
+
// three lines while the clamp stayed at two, and a stage carrying
|
|
520
|
+
// merge + loop + "Rejected: Ends here" dropped the last of them.
|
|
521
|
+
style={{
|
|
522
|
+
display: '-webkit-box',
|
|
523
|
+
WebkitBoxOrient: 'vertical',
|
|
524
|
+
WebkitLineClamp: ROUTE_FLOW_MAX_NOTES,
|
|
525
|
+
overflow: 'hidden',
|
|
526
|
+
}}
|
|
527
|
+
className="text-xs uppercase leading-tight tracking-wide text-muted-foreground"
|
|
528
|
+
>
|
|
529
|
+
{notes.join(' · ')}
|
|
530
|
+
</span>
|
|
531
|
+
)}
|
|
532
|
+
|
|
533
|
+
{!readOnly && (
|
|
534
|
+
<button
|
|
535
|
+
type="button"
|
|
536
|
+
onClick={() => onDelete(step.position)}
|
|
537
|
+
aria-label={labels.deleteStep}
|
|
538
|
+
className="nodrag absolute end-1 top-1 rounded px-1 text-xs text-muted-foreground hover:text-destructive"
|
|
539
|
+
>
|
|
540
|
+
×
|
|
541
|
+
</button>
|
|
542
|
+
)}
|
|
543
|
+
|
|
544
|
+
{/* A decision step's two verdict handles are stacked on the source face and
|
|
545
|
+
coloured, so the gesture and the picture agree before an edge exists.
|
|
546
|
+
|
|
547
|
+
On a horizontal face the two are offset along the VERTICAL axis, which
|
|
548
|
+
no reading direction mirrors, so only the top/bottom case consults
|
|
549
|
+
`direction`. */}
|
|
550
|
+
{step.decision ? (
|
|
551
|
+
<>
|
|
552
|
+
<Handle
|
|
553
|
+
id="approved"
|
|
554
|
+
type="source"
|
|
555
|
+
position={sourceFace}
|
|
556
|
+
style={
|
|
557
|
+
sourceFace === Position.Bottom || sourceFace === Position.Top
|
|
558
|
+
? verdictInset(direction, 30)
|
|
559
|
+
: { top: '35%' }
|
|
560
|
+
}
|
|
561
|
+
className={cn(HANDLE_CLASS, '!bg-emerald-500')}
|
|
562
|
+
data-testid={`approve-handle-${step.position}`}
|
|
563
|
+
/>
|
|
564
|
+
<Handle
|
|
565
|
+
id="rejected"
|
|
566
|
+
type="source"
|
|
567
|
+
position={sourceFace}
|
|
568
|
+
style={
|
|
569
|
+
sourceFace === Position.Bottom || sourceFace === Position.Top
|
|
570
|
+
? verdictInset(direction, 70)
|
|
571
|
+
: { top: '70%' }
|
|
572
|
+
}
|
|
573
|
+
className={cn(HANDLE_CLASS, '!bg-rose-500')}
|
|
574
|
+
data-testid={`reject-handle-${step.position}`}
|
|
575
|
+
/>
|
|
576
|
+
</>
|
|
577
|
+
) : (
|
|
578
|
+
<Handle type="source" position={sourceFace} className={HANDLE_CLASS} />
|
|
579
|
+
)}
|
|
580
|
+
</div>
|
|
581
|
+
);
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
const nodeTypes: NodeTypes = { routeFlowStep: RouteFlowNodeCard };
|
|
585
|
+
|
|
586
|
+
/** The app's own theme (the `dark` class on the page), followed live. */
|
|
587
|
+
function useAppColorMode(): 'light' | 'dark' {
|
|
588
|
+
const [mode, setMode] = React.useState<'light' | 'dark'>('light');
|
|
589
|
+
React.useEffect(() => {
|
|
590
|
+
const root = document.documentElement;
|
|
591
|
+
const read = () => setMode(root.classList.contains('dark') ? 'dark' : 'light');
|
|
592
|
+
read();
|
|
593
|
+
const observer = new MutationObserver(read);
|
|
594
|
+
observer.observe(root, { attributes: true, attributeFilter: ['class'] });
|
|
595
|
+
return () => observer.disconnect();
|
|
596
|
+
}, []);
|
|
597
|
+
return mode;
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
interface RouteFlowEdgeData extends Record<string, unknown> {
|
|
601
|
+
kind: 'drawn' | 'derived';
|
|
602
|
+
on: RouteFlowVerdict | 'continue';
|
|
603
|
+
text: string;
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
/**
|
|
607
|
+
* How far a transition's label is nudged off the middle of its own curve, by
|
|
608
|
+
* verdict.
|
|
609
|
+
*
|
|
610
|
+
* ─────────────────────────────────────────────────────────────────────────
|
|
611
|
+
* WHY A LABEL NEEDS AN OFFSET AT ALL
|
|
612
|
+
* ─────────────────────────────────────────────────────────────────────────
|
|
613
|
+
* Two transitions running BETWEEN THE SAME PAIR OF STAGES in opposite
|
|
614
|
+
* directions have, to within a few pixels, the same midpoint — and a built-in
|
|
615
|
+
* edge draws its label at exactly that midpoint. So a rework loop, which is the
|
|
616
|
+
* commonest real design there is, printed both labels on top of each other:
|
|
617
|
+
* "Approved (imp Rejected" (#1042).
|
|
618
|
+
*
|
|
619
|
+
* That is an anti-parallel PAIR, not "two edges leaving one node" — two edges
|
|
620
|
+
* leaving one node diverge, and their labels separate on their own. The pair is
|
|
621
|
+
* always a pair of DIFFERENT verdicts (one destination per verdict per stage is
|
|
622
|
+
* enforced by the schema and by `onConnect`), so nudging by verdict is enough to
|
|
623
|
+
* separate any pair that can exist, and it does it deterministically rather than
|
|
624
|
+
* by a collision search whose answer would move as nodes are dragged.
|
|
625
|
+
*
|
|
626
|
+
* Bigger than a label's own line box, so the two clear rather than touch.
|
|
627
|
+
*/
|
|
628
|
+
const LABEL_NUDGE: Record<RouteFlowVerdict | 'continue', number> = {
|
|
629
|
+
approved: -22,
|
|
630
|
+
continue: 0,
|
|
631
|
+
rejected: 22,
|
|
632
|
+
};
|
|
633
|
+
|
|
634
|
+
/**
|
|
635
|
+
* One transition.
|
|
636
|
+
*
|
|
637
|
+
* A custom edge only so the label can be moved; everything else is
|
|
638
|
+
* `@xyflow/react`'s own, including the invisible interaction path that makes an
|
|
639
|
+
* edge selectable and therefore deletable.
|
|
640
|
+
*
|
|
641
|
+
* The label is drawn on a background chip because it sits over a dotted
|
|
642
|
+
* background and, in a loop, over the other arrow.
|
|
643
|
+
*/
|
|
644
|
+
function RouteFlowTransitionEdge({
|
|
645
|
+
sourceX,
|
|
646
|
+
sourceY,
|
|
647
|
+
sourcePosition,
|
|
648
|
+
targetX,
|
|
649
|
+
targetY,
|
|
650
|
+
targetPosition,
|
|
651
|
+
markerEnd,
|
|
652
|
+
style,
|
|
653
|
+
data,
|
|
654
|
+
}: EdgeProps<Edge<RouteFlowEdgeData>>) {
|
|
655
|
+
const [path, labelX, labelY] = getBezierPath({
|
|
656
|
+
sourceX,
|
|
657
|
+
sourceY,
|
|
658
|
+
sourcePosition,
|
|
659
|
+
targetX,
|
|
660
|
+
targetY,
|
|
661
|
+
targetPosition,
|
|
662
|
+
});
|
|
663
|
+
|
|
664
|
+
return (
|
|
665
|
+
<BaseEdge
|
|
666
|
+
path={path}
|
|
667
|
+
markerEnd={markerEnd}
|
|
668
|
+
style={style}
|
|
669
|
+
label={data?.text}
|
|
670
|
+
labelX={labelX}
|
|
671
|
+
labelY={labelY + LABEL_NUDGE[data?.on ?? 'continue']}
|
|
672
|
+
// SVG text defaults to black and `@xyflow/react` sets no fill of its own,
|
|
673
|
+
// so an edge label was black on a near-black canvas in dark mode. Both
|
|
674
|
+
// colours come from the theme, so the chip and its text move together.
|
|
675
|
+
// `--text-xs` (13px, the floor, A.1), and it grows with Larger text.
|
|
676
|
+
labelStyle={{ fontSize: 'var(--text-xs)', fill: 'var(--color-muted-foreground, #64748b)' }}
|
|
677
|
+
labelShowBg
|
|
678
|
+
labelBgPadding={[4, 2]}
|
|
679
|
+
labelBgBorderRadius={3}
|
|
680
|
+
labelBgStyle={{ fill: 'var(--color-card, #ffffff)', fillOpacity: 0.92 }}
|
|
681
|
+
/>
|
|
682
|
+
);
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
const edgeTypes: EdgeTypes = { routeFlowTransition: RouteFlowTransitionEdge };
|
|
686
|
+
|
|
687
|
+
/**
|
|
688
|
+
* How the canvas frames itself.
|
|
689
|
+
*
|
|
690
|
+
* `maxZoom` is the important one and it was missing. `@xyflow/react` defaults a
|
|
691
|
+
* fit to a maximum of 2×, and `fitView` runs on MOUNT — which, for a template
|
|
692
|
+
* being authored from nothing, is the moment the FIRST node appears. One node
|
|
693
|
+
* fits at 2×, the viewport froze there, and stages 2, 3 and 4 were then added
|
|
694
|
+
* off-screen: the measured result was `scale(2)` with one of four nodes visible,
|
|
695
|
+
* for every new flow anybody made (#1042).
|
|
696
|
+
*
|
|
697
|
+
* Capped at 1 rather than at some larger number because a node card is designed
|
|
698
|
+
* at a fixed pixel size and a magnified one is not more legible, only bigger.
|
|
699
|
+
* This bounds the automatic fit ONLY — the `maxZoom` prop is left at its default
|
|
700
|
+
* so a person can still zoom in past this by hand.
|
|
701
|
+
*/
|
|
702
|
+
// More room above than around: the start pill sits over the first stage.
|
|
703
|
+
const FIT_VIEW = { maxZoom: 1, padding: { top: '56px', right: '24px', bottom: '24px', left: '24px' } as const };
|
|
704
|
+
|
|
705
|
+
export function RouteFlowEditor({
|
|
706
|
+
graph,
|
|
707
|
+
onGraphChange,
|
|
708
|
+
selectedPosition = null,
|
|
709
|
+
onSelectStep,
|
|
710
|
+
orientation = 'vertical',
|
|
711
|
+
direction = 'ltr',
|
|
712
|
+
maxNodes = ROUTE_FLOW_MAX_NODES,
|
|
713
|
+
readOnly = false,
|
|
714
|
+
audienceFor,
|
|
715
|
+
ruleLabelFor,
|
|
716
|
+
labels: labelOverrides,
|
|
717
|
+
className,
|
|
718
|
+
}: RouteFlowEditorProps) {
|
|
719
|
+
const labels = React.useMemo<RouteFlowEditorLabels>(
|
|
720
|
+
() => ({ ...DEFAULT_LABELS, ...labelOverrides }),
|
|
721
|
+
[labelOverrides]
|
|
722
|
+
);
|
|
723
|
+
|
|
724
|
+
const faces = handleFaces(orientation, direction);
|
|
725
|
+
const sourceFace = FACE[faces.source] ?? Position.Bottom;
|
|
726
|
+
const targetFace = FACE[faces.target] ?? Position.Top;
|
|
727
|
+
|
|
728
|
+
const ordered = React.useMemo(() => stepsInOrder(graph.steps), [graph.steps]);
|
|
729
|
+
const cut = ordered.length > maxNodes;
|
|
730
|
+
const drawn = cut ? ordered.slice(0, maxNodes) : ordered;
|
|
731
|
+
|
|
732
|
+
const resolution = React.useMemo(() => resolveTransitions(graph), [graph]);
|
|
733
|
+
const { transitions } = resolution;
|
|
734
|
+
|
|
735
|
+
const quorumLabel = React.useCallback(
|
|
736
|
+
(step: RouteFlowStep): string => {
|
|
737
|
+
switch (effectiveQuorum(step, graph)) {
|
|
738
|
+
case 'any':
|
|
739
|
+
return labels.quorumAny;
|
|
740
|
+
case 'majority':
|
|
741
|
+
return labels.quorumMajority;
|
|
742
|
+
case 'first':
|
|
743
|
+
return labels.quorumFirst ?? 'the first answer decides';
|
|
744
|
+
default:
|
|
745
|
+
return labels.quorumAll;
|
|
746
|
+
}
|
|
747
|
+
},
|
|
748
|
+
[graph, labels]
|
|
749
|
+
);
|
|
750
|
+
|
|
751
|
+
const emit = React.useCallback(
|
|
752
|
+
(next: RouteFlowGraph) => {
|
|
753
|
+
onGraphChange?.(next);
|
|
754
|
+
},
|
|
755
|
+
[onGraphChange]
|
|
756
|
+
);
|
|
757
|
+
|
|
758
|
+
const handleDelete = React.useCallback(
|
|
759
|
+
(position: number) => {
|
|
760
|
+
// Renumber and rewrite edges in the same pass — see `renumber`. `position`
|
|
761
|
+
// is also the FALLTHROUGH order, so a delete that left a gap would leave
|
|
762
|
+
// an author reading arrows that no longer match the list.
|
|
763
|
+
emit(
|
|
764
|
+
renumber({
|
|
765
|
+
...graph,
|
|
766
|
+
steps: graph.steps.filter((s) => s.position !== position),
|
|
767
|
+
edges: graph.edges.filter((e) => e.from !== position && e.to !== position),
|
|
768
|
+
})
|
|
769
|
+
);
|
|
770
|
+
if (selectedPosition === position) {
|
|
771
|
+
onSelectStep?.(null);
|
|
772
|
+
}
|
|
773
|
+
},
|
|
774
|
+
[emit, graph, onSelectStep, selectedPosition]
|
|
775
|
+
);
|
|
776
|
+
|
|
777
|
+
const [nodes, setNodes, onNodesChange] = useNodesState<Node<RouteFlowNodeData>>([]);
|
|
778
|
+
|
|
779
|
+
React.useEffect(() => {
|
|
780
|
+
// A graph nothing has ever arranged gets one tidy layout; anything an author
|
|
781
|
+
// has touched keeps the arrangement they made. See `needsAutoLayout` for why
|
|
782
|
+
// the test is deliberately narrow.
|
|
783
|
+
const placed = needsAutoLayout(drawn)
|
|
784
|
+
? autoLayout({ ...graph, steps: drawn }, orientation, direction)
|
|
785
|
+
: drawn;
|
|
786
|
+
|
|
787
|
+
setNodes(
|
|
788
|
+
placed.map((step) => {
|
|
789
|
+
// WHICH notes a stage carries is decided in the model, by `notesFor`,
|
|
790
|
+
// and only the wording is decided here. That split is what lets
|
|
791
|
+
// ROUTE_FLOW_MAX_NOTES — the number the card's height is budgeted
|
|
792
|
+
// against — be an assertion a test can make.
|
|
793
|
+
const notes = notesFor(step.position, resolution).map((note) => {
|
|
794
|
+
if (note.kind === 'merge') return labels.arrivalsMerge;
|
|
795
|
+
if (note.kind === 'cycle') return labels.inCycle;
|
|
796
|
+
const on =
|
|
797
|
+
note.on === 'approved'
|
|
798
|
+
? labels.approved
|
|
799
|
+
: note.on === 'rejected'
|
|
800
|
+
? labels.rejected
|
|
801
|
+
: labels.continues;
|
|
802
|
+
return `${on}: ${labels.ends}`;
|
|
803
|
+
});
|
|
804
|
+
|
|
805
|
+
return {
|
|
806
|
+
id: String(step.position),
|
|
807
|
+
type: 'routeFlowStep',
|
|
808
|
+
position: { x: step.canvasX, y: step.canvasY },
|
|
809
|
+
draggable: !readOnly,
|
|
810
|
+
data: {
|
|
811
|
+
step,
|
|
812
|
+
quorumText: quorumLabel(step),
|
|
813
|
+
ruleLabel: ruleLabelFor?.(step) ?? step.ruleKind,
|
|
814
|
+
audience: audienceFor?.(step),
|
|
815
|
+
selected: selectedPosition === step.position,
|
|
816
|
+
readOnly,
|
|
817
|
+
notes,
|
|
818
|
+
labels,
|
|
819
|
+
direction,
|
|
820
|
+
sourceFace,
|
|
821
|
+
targetFace,
|
|
822
|
+
onSelect: (p: number) => onSelectStep?.(p),
|
|
823
|
+
onDelete: handleDelete,
|
|
824
|
+
},
|
|
825
|
+
};
|
|
826
|
+
})
|
|
827
|
+
);
|
|
828
|
+
}, [
|
|
829
|
+
audienceFor,
|
|
830
|
+
direction,
|
|
831
|
+
drawn,
|
|
832
|
+
graph,
|
|
833
|
+
handleDelete,
|
|
834
|
+
labels,
|
|
835
|
+
onSelectStep,
|
|
836
|
+
orientation,
|
|
837
|
+
quorumLabel,
|
|
838
|
+
readOnly,
|
|
839
|
+
ruleLabelFor,
|
|
840
|
+
resolution,
|
|
841
|
+
selectedPosition,
|
|
842
|
+
setNodes,
|
|
843
|
+
sourceFace,
|
|
844
|
+
targetFace,
|
|
845
|
+
]);
|
|
846
|
+
|
|
847
|
+
const edges = React.useMemo<Edge[]>(() => {
|
|
848
|
+
const visible = new Set(drawn.map((s) => s.position));
|
|
849
|
+
|
|
850
|
+
return transitions
|
|
851
|
+
.filter((t) => visible.has(t.from) && visible.has(t.to))
|
|
852
|
+
.map((t) => {
|
|
853
|
+
const isReject = t.on === 'rejected';
|
|
854
|
+
const isApprove = t.on === 'approved';
|
|
855
|
+
const label =
|
|
856
|
+
t.on === 'approved'
|
|
857
|
+
? labels.approved
|
|
858
|
+
: t.on === 'rejected'
|
|
859
|
+
? labels.rejected
|
|
860
|
+
: labels.continues;
|
|
861
|
+
|
|
862
|
+
return {
|
|
863
|
+
id: `${t.from}-${t.on}-${t.to}`,
|
|
864
|
+
source: String(t.from),
|
|
865
|
+
target: String(t.to),
|
|
866
|
+
sourceHandle: isApprove || isReject ? t.on : undefined,
|
|
867
|
+
type: 'routeFlowTransition',
|
|
868
|
+
// A DERIVED transition is dashed and says so. It is a real arrow — the
|
|
869
|
+
// engine will take it — but it is not one the author drew, and it
|
|
870
|
+
// cannot be deleted except by reordering the steps that imply it.
|
|
871
|
+
animated: false,
|
|
872
|
+
style: {
|
|
873
|
+
strokeDasharray: t.kind === 'derived' ? '4 3' : undefined,
|
|
874
|
+
stroke: isReject
|
|
875
|
+
? 'var(--color-rose-500, #f43f5e)'
|
|
876
|
+
: isApprove
|
|
877
|
+
? 'var(--color-emerald-500, #10b981)'
|
|
878
|
+
: undefined,
|
|
879
|
+
},
|
|
880
|
+
markerEnd: { type: MarkerType.ArrowClosed },
|
|
881
|
+
// The label travels in `data` rather than in `label`, because the
|
|
882
|
+
// custom edge draws it at a nudged position — see LABEL_NUDGE.
|
|
883
|
+
data: {
|
|
884
|
+
kind: t.kind,
|
|
885
|
+
on: t.on,
|
|
886
|
+
text: t.kind === 'derived' ? `${label} (${labels.implicit})` : label,
|
|
887
|
+
},
|
|
888
|
+
} satisfies Edge;
|
|
889
|
+
});
|
|
890
|
+
}, [drawn, labels, transitions]);
|
|
891
|
+
|
|
892
|
+
/**
|
|
893
|
+
* A drag between two handles becomes a stored edge.
|
|
894
|
+
*
|
|
895
|
+
* The verdict is the SOURCE HANDLE's id, never a guess: an author who dragged
|
|
896
|
+
* from the green handle drew an approve edge, and there is no second place that
|
|
897
|
+
* decision could be made differently. A drag from a plain (non-decision) handle
|
|
898
|
+
* is dropped, because such an edge could never fire and the server would refuse
|
|
899
|
+
* it — better to have the gesture do nothing visible than to save something
|
|
900
|
+
* that comes back as an error.
|
|
901
|
+
*/
|
|
902
|
+
const onConnect = React.useCallback(
|
|
903
|
+
(connection: Connection) => {
|
|
904
|
+
if (readOnly) return;
|
|
905
|
+
|
|
906
|
+
const verdict = connection.sourceHandle;
|
|
907
|
+
if (verdict !== 'approved' && verdict !== 'rejected') return;
|
|
908
|
+
|
|
909
|
+
const from = Number(connection.source);
|
|
910
|
+
const to = Number(connection.target);
|
|
911
|
+
if (!Number.isFinite(from) || !Number.isFinite(to) || from === to) return;
|
|
912
|
+
|
|
913
|
+
// One destination per verdict per node — the same uniqueness the schema
|
|
914
|
+
// enforces. Re-drawing replaces rather than adding a second arrow, which
|
|
915
|
+
// is what an author dragging again means.
|
|
916
|
+
const kept = graph.edges.filter((e) => !(e.from === from && e.verdict === verdict));
|
|
917
|
+
emit({ ...graph, edges: [...kept, { from, to, verdict: verdict as RouteFlowVerdict }] });
|
|
918
|
+
},
|
|
919
|
+
[emit, graph, readOnly]
|
|
920
|
+
);
|
|
921
|
+
|
|
922
|
+
const onEdgesDelete = React.useCallback(
|
|
923
|
+
(removed: Edge[]) => {
|
|
924
|
+
if (readOnly) return;
|
|
925
|
+
// Only DRAWN edges can be removed. A derived one is a consequence of the
|
|
926
|
+
// step order; deleting the arrow without deleting the cause would show a
|
|
927
|
+
// canvas the engine disagrees with.
|
|
928
|
+
const drawnIds = new Set(removed.filter((e) => (e.data as { kind?: string })?.kind === 'drawn').map((e) => e.id));
|
|
929
|
+
if (drawnIds.size === 0) return;
|
|
930
|
+
|
|
931
|
+
emit({
|
|
932
|
+
...graph,
|
|
933
|
+
edges: graph.edges.filter((e) => !drawnIds.has(`${e.from}-${e.verdict}-${e.to}`)),
|
|
934
|
+
});
|
|
935
|
+
},
|
|
936
|
+
[emit, graph, readOnly]
|
|
937
|
+
);
|
|
938
|
+
|
|
939
|
+
/**
|
|
940
|
+
* Re-frame the canvas when the flow gains or loses a stage.
|
|
941
|
+
*
|
|
942
|
+
* `fitView` alone only ever fires once, on mount. Everything an author does
|
|
943
|
+
* after that — and on a new template, everything they do at all — happens to a
|
|
944
|
+
* viewport that was framed for a graph with one node in it.
|
|
945
|
+
*
|
|
946
|
+
* Keyed on the node COUNT and nothing else, deliberately. Re-fitting on every
|
|
947
|
+
* graph change would yank the canvas out from under someone who had panned to
|
|
948
|
+
* a corner and was renaming a stage; adding or deleting a stage is the one
|
|
949
|
+
* edit that changes what there is to look at.
|
|
950
|
+
*
|
|
951
|
+
* `requestAnimationFrame` because the fit needs the new node MEASURED, and
|
|
952
|
+
* this effect runs in the same commit that first renders it.
|
|
953
|
+
*/
|
|
954
|
+
const instance = React.useRef<ReactFlowInstance<Node<RouteFlowNodeData>, Edge> | null>(null);
|
|
955
|
+
const onInit = React.useCallback(
|
|
956
|
+
(next: ReactFlowInstance<Node<RouteFlowNodeData>, Edge>) => {
|
|
957
|
+
instance.current = next;
|
|
958
|
+
},
|
|
959
|
+
[]
|
|
960
|
+
);
|
|
961
|
+
|
|
962
|
+
const colorMode = useAppColorMode();
|
|
963
|
+
|
|
964
|
+
const nodeCount = drawn.length;
|
|
965
|
+
React.useEffect(() => {
|
|
966
|
+
if (nodeCount === 0) return undefined;
|
|
967
|
+
const frame = requestAnimationFrame(() => {
|
|
968
|
+
void instance.current?.fitView(FIT_VIEW);
|
|
969
|
+
});
|
|
970
|
+
return () => cancelAnimationFrame(frame);
|
|
971
|
+
}, [nodeCount]);
|
|
972
|
+
|
|
973
|
+
const onNodeDragStop = React.useCallback(
|
|
974
|
+
(_event: MouseEvent | TouchEvent, node: Node) => {
|
|
975
|
+
if (readOnly) return;
|
|
976
|
+
const position = Number(node.id);
|
|
977
|
+
emit({
|
|
978
|
+
...graph,
|
|
979
|
+
steps: graph.steps.map((s) =>
|
|
980
|
+
s.position === position
|
|
981
|
+
? { ...s, canvasX: Math.round(node.position.x), canvasY: Math.round(node.position.y) }
|
|
982
|
+
: s
|
|
983
|
+
),
|
|
984
|
+
});
|
|
985
|
+
},
|
|
986
|
+
[emit, graph, readOnly]
|
|
987
|
+
);
|
|
988
|
+
|
|
989
|
+
return (
|
|
990
|
+
<div className={cn('relative h-[32rem] w-full rounded-lg border border-border bg-card', className)}>
|
|
991
|
+
{cut && (
|
|
992
|
+
<p
|
|
993
|
+
className="absolute inset-x-0 top-0 z-10 bg-amber-500/10 px-3 py-1 text-xs text-foreground"
|
|
994
|
+
role="status"
|
|
995
|
+
>
|
|
996
|
+
{labels.tooManyNodes}
|
|
997
|
+
</p>
|
|
998
|
+
)}
|
|
999
|
+
{drawn.length === 0 ? (
|
|
1000
|
+
<p className="flex h-full items-center justify-center px-6 text-center text-sm text-muted-foreground">
|
|
1001
|
+
{labels.empty}
|
|
1002
|
+
</p>
|
|
1003
|
+
) : (
|
|
1004
|
+
<ReactFlow
|
|
1005
|
+
nodes={nodes}
|
|
1006
|
+
edges={edges}
|
|
1007
|
+
nodeTypes={nodeTypes}
|
|
1008
|
+
edgeTypes={edgeTypes}
|
|
1009
|
+
onInit={onInit}
|
|
1010
|
+
onNodesChange={onNodesChange}
|
|
1011
|
+
onNodeDragStop={onNodeDragStop}
|
|
1012
|
+
onConnect={onConnect}
|
|
1013
|
+
onEdgesDelete={onEdgesDelete}
|
|
1014
|
+
nodesDraggable={!readOnly}
|
|
1015
|
+
nodesConnectable={!readOnly}
|
|
1016
|
+
elementsSelectable
|
|
1017
|
+
connectionRadius={CONNECTION_RADIUS}
|
|
1018
|
+
fitView
|
|
1019
|
+
fitViewOptions={FIT_VIEW}
|
|
1020
|
+
// react-flow's default minZoom (0.5) defeats fitView on anything wider
|
|
1021
|
+
// than about twice the canvas: the fit clamps at 0.5 and centres,
|
|
1022
|
+
// silently clipping the outermost nodes. The OU hub hit this first and
|
|
1023
|
+
// the `flow` block records it; a route flow with a reject lane is wide
|
|
1024
|
+
// enough to hit it sooner.
|
|
1025
|
+
minZoom={0.1}
|
|
1026
|
+
// `@xyflow/react` defaults to its own `light` class, and the design
|
|
1027
|
+
// tokens also define a `.light` theme, so in dark mode every card
|
|
1028
|
+
// came out white. The canvas follows the app's theme instead.
|
|
1029
|
+
colorMode={colorMode}
|
|
1030
|
+
proOptions={{ hideAttribution: true }}
|
|
1031
|
+
>
|
|
1032
|
+
<Panel position="top-center">
|
|
1033
|
+
<span
|
|
1034
|
+
className="whitespace-nowrap rounded-full border border-border bg-card px-3 py-1 text-sm text-foreground"
|
|
1035
|
+
data-slot="route-flow-start"
|
|
1036
|
+
>
|
|
1037
|
+
{labels.start}
|
|
1038
|
+
</span>
|
|
1039
|
+
</Panel>
|
|
1040
|
+
<Background variant={BackgroundVariant.Dots} gap={16} size={1} />
|
|
1041
|
+
<Controls showInteractive={false} />
|
|
1042
|
+
</ReactFlow>
|
|
1043
|
+
)}
|
|
1044
|
+
</div>
|
|
1045
|
+
);
|
|
1046
|
+
}
|
|
1047
|
+
|
|
1048
|
+
/**
|
|
1049
|
+
* Append a stage to a flow, placed in the next free slot.
|
|
1050
|
+
*
|
|
1051
|
+
* Exported beside the editor rather than living inside it because ADDING a stage
|
|
1052
|
+
* needs a rule, and choosing one is the host's inspector's job. The host builds
|
|
1053
|
+
* the step and calls this to get the placement and the numbering right.
|
|
1054
|
+
*/
|
|
1055
|
+
export function appendStep(
|
|
1056
|
+
graph: RouteFlowGraph,
|
|
1057
|
+
step: Omit<RouteFlowStep, 'position' | 'canvasX' | 'canvasY'>,
|
|
1058
|
+
orientation: RouteFlowOrientation = 'vertical',
|
|
1059
|
+
direction: RouteFlowDirection = 'ltr'
|
|
1060
|
+
): RouteFlowGraph {
|
|
1061
|
+
const positions = graph.steps.map((s) => s.position);
|
|
1062
|
+
const position = positions.length === 0 ? 1 : Math.max(...positions) + 1;
|
|
1063
|
+
const slot = nextSlot(graph, orientation, direction);
|
|
1064
|
+
|
|
1065
|
+
// WHIT-921: the final document stage is always last, so a stage added after
|
|
1066
|
+
// it takes its place and it moves down one. Edges name positions, so the
|
|
1067
|
+
// ones arriving at it follow it.
|
|
1068
|
+
const last = graph.steps.find((s) => s.position === position - 1);
|
|
1069
|
+
if (step.kind !== 'finalise' && last !== undefined && last.kind === 'finalise') {
|
|
1070
|
+
const moved = last.position;
|
|
1071
|
+
return {
|
|
1072
|
+
...graph,
|
|
1073
|
+
steps: [
|
|
1074
|
+
...graph.steps.map((s) =>
|
|
1075
|
+
s.position === moved ? { ...s, position, canvasX: slot.canvasX, canvasY: slot.canvasY } : s
|
|
1076
|
+
),
|
|
1077
|
+
{ ...step, position: moved, canvasX: last.canvasX, canvasY: last.canvasY },
|
|
1078
|
+
],
|
|
1079
|
+
edges: graph.edges.map((e) => (e.to === moved ? { ...e, to: position } : e)),
|
|
1080
|
+
};
|
|
1081
|
+
}
|
|
1082
|
+
|
|
1083
|
+
return {
|
|
1084
|
+
...graph,
|
|
1085
|
+
steps: [...graph.steps, { ...step, position, ...slot }],
|
|
1086
|
+
};
|
|
1087
|
+
}
|