@shware/workflow-ui 2.2.8 → 2.2.9

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shware/workflow-ui",
3
- "version": "2.2.8",
3
+ "version": "2.2.9",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/ShwareHQ/shware-sdk.git"
@@ -40,7 +40,7 @@
40
40
  "@floating-ui/react": "^0.27.20",
41
41
  "@fontsource-variable/inter": "^5.3.0",
42
42
  "@react-email/render": "^2.3.1",
43
- "@shware/workflow": "12.0.6",
43
+ "@shware/workflow": "12.0.7",
44
44
  "@tailwindcss/vite": "^4.3.5",
45
45
  "@tanstack/react-query": "^5.108.3",
46
46
  "@tanstack/react-router": "^1.170.46",
@@ -191,6 +191,19 @@ export const workflowDetailRoute = createRoute({
191
191
 
192
192
  const SELECTION_KEY = 'workflow-ui:canvas-selection';
193
193
 
194
+ /** The node last selected on `workflowId`'s canvas in this tab, if any. */
195
+ export function rememberedSelection(workflowId: string): string | undefined {
196
+ if (typeof sessionStorage === 'undefined') return undefined;
197
+ return sessionStorage.getItem(`${SELECTION_KEY}:${workflowId}`) ?? undefined;
198
+ }
199
+
200
+ /** Keep (or, with no node, forget) the selection of `workflowId`'s canvas: each workflow remembers its own. */
201
+ export function rememberSelection(workflowId: string, nodeId: string | undefined): void {
202
+ const key = `${SELECTION_KEY}:${workflowId}`;
203
+ if (nodeId === undefined) sessionStorage.removeItem(key);
204
+ else sessionStorage.setItem(key, nodeId);
205
+ }
206
+
194
207
  function CanvasTab() {
195
208
  const { id } = workflowDetailRoute.useParams();
196
209
  const { config } = workflowDetailRoute.useRouteContext();
@@ -201,17 +214,11 @@ function CanvasTab() {
201
214
  * full-reload the page; without this the panel you were reading vanishes and
202
215
  * you lose your place.
203
216
  */
204
- const [selectedId, setSelectedId] = useState<string | undefined>(() =>
205
- typeof sessionStorage === 'undefined'
206
- ? undefined
207
- : (sessionStorage.getItem(`${SELECTION_KEY}:${id}`) ?? undefined)
208
- );
217
+ const [selectedId, setSelectedId] = useState<string | undefined>(() => rememberedSelection(id));
209
218
  const select = useCallback(
210
- (id: string | undefined) => {
211
- setSelectedId(id);
212
- const key = `${SELECTION_KEY}:${id}`;
213
- if (id === undefined) sessionStorage.removeItem(key);
214
- else sessionStorage.setItem(key, id);
219
+ (nodeId: string | undefined) => {
220
+ setSelectedId(nodeId);
221
+ rememberSelection(id, nodeId);
215
222
  },
216
223
  [id]
217
224
  );
@@ -65,8 +65,13 @@ export interface CanvasEdge {
65
65
  source: string;
66
66
  target: string;
67
67
  label?: string;
68
- /** Label anchor: `target` = the arm's entry corner (real arm); `source` = just below the deciding node (empty pass-through arm). */
69
- data?: { anchor: 'source' | 'target' };
68
+ /**
69
+ * Label anchor: `target` = the arm's entry corner (real arm); `source` = just below the deciding node (empty pass-through arm).
70
+ * `lane` is the x of the empty arm's own column, set when the straight way down from the
71
+ * deciding node is taken by another arm's cards: the connector then runs down that column and
72
+ * turns back to its target below the arms, with its label hanging in the column.
73
+ */
74
+ data?: { anchor: 'source' | 'target'; lane?: number };
70
75
  }
71
76
 
72
77
  /**
@@ -279,6 +284,7 @@ interface Tail {
279
284
  id: string;
280
285
  label?: string;
281
286
  anchor?: 'source' | 'target';
287
+ lane?: number;
282
288
  }
283
289
 
284
290
  export function layout(
@@ -306,7 +312,9 @@ export function layout(
306
312
  source: t.id,
307
313
  target,
308
314
  ...(t.label !== undefined ? { label: t.label } : {}),
309
- ...(t.anchor !== undefined ? { data: { anchor: t.anchor } } : {}),
315
+ ...(t.anchor !== undefined
316
+ ? { data: { anchor: t.anchor, ...(t.lane !== undefined ? { lane: t.lane } : {}) } }
317
+ : {}),
310
318
  });
311
319
  }
312
320
  };
@@ -349,12 +357,27 @@ export function layout(
349
357
  const groupTop = bottom + FORK_GAP;
350
358
  let maxBottom = groupTop;
351
359
  const groupTails: Tail[] = [];
360
+ // An empty group rejoins straight down the centre line. With an odd number of arms (a
361
+ // three-way branch with no `otherwise`) an arm's column sits on that line, and the
362
+ // connector would be drawn through its cards: it takes the empty group's own column then
363
+ let left = gx;
364
+ const blocked = groups.some((g, gi) => {
365
+ const right = left + (widths[gi] ?? W);
366
+ const across = g.nodes.length > 0 && left < cx && cx < right;
367
+ left = right + HGAP;
368
+ return across;
369
+ });
352
370
 
353
371
  groups.forEach((g, gi) => {
354
372
  const center = gx + (widths[gi] ?? W) / 2;
355
373
  if (g.nodes.length === 0) {
356
374
  // Empty group: the parent rejoins straight down, so anchor the label right below it
357
- groupTails.push({ id: n.id, label: g.label, anchor: 'source' });
375
+ groupTails.push({
376
+ id: n.id,
377
+ label: g.label,
378
+ anchor: 'source',
379
+ ...(blocked ? { lane: center } : {}),
380
+ });
358
381
  } else {
359
382
  const r = layoutSeq(g.nodes, center, groupTop, [
360
383
  { id: n.id, label: g.label, anchor: 'target' },
@@ -303,7 +303,7 @@ const edgeLabelStyle: CSSProperties = {
303
303
  pointerEvents: 'none',
304
304
  };
305
305
 
306
- type WfEdge = Edge<{ anchor?: 'source' | 'target' }, 'wf'>;
306
+ type WfEdge = Edge<{ anchor?: 'source' | 'target'; lane?: number }, 'wf'>;
307
307
 
308
308
  /* ----------------------------- Connector routing ---------------------------- */
309
309
 
@@ -311,6 +311,12 @@ type WfEdge = Edge<{ anchor?: 'source' | 'target' }, 'wf'>;
311
311
  const BEND = 16;
312
312
  /** How far a labelled fork runs straight down before it turns. */
313
313
  const FORK_STEM = 28;
314
+ /**
315
+ * How far above its target a lane connector turns back. The layout keeps the arms' last card 72
316
+ * above the node they rejoin at, and that arm's own connector turns halfway down: the lane
317
+ * joins it on the same line.
318
+ */
319
+ const LANE_REJOIN = 36;
314
320
  /** Where a label pill hangs below the deciding node. */
315
321
  const LABEL_DROP = 56;
316
322
  const DOT_R = 3.5;
@@ -367,6 +373,39 @@ function orthogonalPath(sx: number, sy: number, tx: number, ty: number, splitY:
367
373
  ].join(' ');
368
374
  }
369
375
 
376
+ /**
377
+ * A pass-through arm's route when the straight way down is taken by another arm's cards (see
378
+ * `CanvasEdge.data.lane`): out to the arm's own empty column like any fork, down that column
379
+ * past the arms, and back in to the target.
380
+ */
381
+ export function lanePath(
382
+ sx: number,
383
+ sy: number,
384
+ tx: number,
385
+ ty: number,
386
+ lane: number,
387
+ splitY: number
388
+ ): string {
389
+ const rejoinY = Math.max(splitY, ty - LANE_REJOIN);
390
+ const out = Math.sign(lane - sx);
391
+ const back = Math.sign(tx - lane);
392
+ const drop = rejoinY - splitY;
393
+ const r1 = Math.max(0, Math.min(BEND, Math.abs(lane - sx) / 2, splitY - sy, drop / 2));
394
+ const r2 = Math.max(0, Math.min(BEND, Math.abs(tx - lane) / 2, drop / 2, ty - rejoinY));
395
+ return [
396
+ `M ${sx} ${sy}`,
397
+ `L ${sx} ${splitY - r1}`,
398
+ corner(sx, splitY - r1, sx, splitY, sx + out * r1, splitY),
399
+ `L ${lane - out * r1} ${splitY}`,
400
+ corner(lane - out * r1, splitY, lane, splitY, lane, splitY + r1),
401
+ `L ${lane} ${rejoinY - r2}`,
402
+ corner(lane, rejoinY - r2, lane, rejoinY, lane + back * r2, rejoinY),
403
+ `L ${tx - back * r2} ${rejoinY}`,
404
+ corner(tx - back * r2, rejoinY, tx, rejoinY, tx, rejoinY + r2),
405
+ `L ${tx} ${ty}`,
406
+ ].join(' ');
407
+ }
408
+
370
409
  /**
371
410
  * Custom edge with an HTML label: SVG EdgeText's height floats with the font's
372
411
  * bounding box, and only HTML can be pinned to exact pixels.
@@ -393,21 +432,23 @@ function WorkflowEdge({
393
432
  * descends through. A source anchor hangs directly under the deciding node,
394
433
  * where the path has already turned away at FORK_STEM, leaving the pill
395
434
  * stranded in open space; so for those the stem runs all the way down to the
396
- * pill and turns behind it.
435
+ * pill and turns behind it. A pass-through arm sent down its own column (a
436
+ * lane) is in the first case: the pill hangs in that column, on the line.
397
437
  */
398
- const anchoredAtSource = data?.anchor === 'source';
438
+ const lane = data?.lane;
439
+ const anchoredAtSource = data?.anchor === 'source' && lane === undefined;
399
440
  const splitY = label
400
441
  ? sourceY + (anchoredAtSource ? LABEL_DROP : FORK_STEM)
401
442
  : (sourceY + targetY) / 2;
402
- const path = orthogonalPath(
403
- sourceX,
404
- sourceY - HANDLE_INSET,
405
- targetX,
406
- targetY + HANDLE_INSET,
407
- splitY
408
- );
443
+ const path =
444
+ lane === undefined
445
+ ? orthogonalPath(sourceX, sourceY - HANDLE_INSET, targetX, targetY + HANDLE_INSET, splitY)
446
+ : lanePath(sourceX, sourceY - HANDLE_INSET, targetX, targetY + HANDLE_INSET, lane, splitY);
409
447
  // The label hangs below the split line, pinned to its own arm's column
410
- const labelPos = { x: anchoredAtSource ? sourceX : targetX, y: sourceY + LABEL_DROP };
448
+ const labelPos = {
449
+ x: lane ?? (anchoredAtSource ? sourceX : targetX),
450
+ y: sourceY + LABEL_DROP,
451
+ };
411
452
  return (
412
453
  <>
413
454
  <BaseEdge id={id} path={path} style={style} />
package/src/server.ts CHANGED
@@ -442,15 +442,24 @@ const VITE_DEFAULT_DENY = ['.env', '.env.*', '*.{crt,pem}', '**/.git/**'];
442
442
  * journey project keeps beside its code. `fs.allow` spans the project and its linked workspace
443
443
  * packages (see {@link studioFsAllow}), so without these
444
444
  * `/@fs/<path>/.dev.vars` (wrangler's secrets), an APNs `.p8` or a Firebase service account would
445
- * be one request away for any page that can reach the port.
445
+ * be one request away for any page that can reach the port. The same goes for what sits beside
446
+ * any project: registry and network tokens (`.npmrc`, `.netrc`), direnv's `.envrc` (which
447
+ * `.env.*` does not match), key stores, and the wrangler config with its `vars`.
446
448
  */
447
449
  export const STUDIO_FS_DENY: readonly string[] = [
448
450
  ...VITE_DEFAULT_DENY,
449
451
  '**/.dev.vars*',
452
+ '**/.envrc',
453
+ '**/.npmrc',
454
+ '**/.netrc',
455
+ '**/wrangler.{toml,json,jsonc}',
450
456
  '**/*.p8',
451
457
  '**/*.plist',
452
458
  '**/google-services.json',
453
459
  '**/*.pfx',
460
+ '**/*.p12',
461
+ '**/*.jks',
462
+ '**/*.keystore',
454
463
  '**/*.pem',
455
464
  '**/*.key',
456
465
  ];