footprint-explainable-ui 0.11.2 → 0.11.4

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/index.cjs CHANGED
@@ -2442,16 +2442,43 @@ function StoryNarrative({
2442
2442
  const fs = fontSize[size];
2443
2443
  const pad = padding[size];
2444
2444
  const revealedCount = (0, import_react11.useMemo)(() => {
2445
+ const isRevealed = (e) => e.stageId && revealedStages.has(e.stageId) || e.subflowId && revealedStages.has(e.subflowId) || e.stageName && revealedStages.has(e.stageName);
2446
+ let lastIdentifiedWasRevealed = true;
2445
2447
  for (let i = 0; i < entries.length; i++) {
2446
2448
  const e = entries[i];
2447
- const key = e.stageId ?? e.stageName;
2448
- if (key && !revealedStages.has(key)) {
2449
- return i;
2449
+ const hasKey = e.stageId || e.subflowId || e.stageName;
2450
+ if (hasKey) {
2451
+ lastIdentifiedWasRevealed = !!isRevealed(e);
2452
+ if (!lastIdentifiedWasRevealed) return i;
2453
+ } else {
2454
+ if (!lastIdentifiedWasRevealed) return i;
2450
2455
  }
2451
2456
  }
2452
2457
  return entries.length;
2453
2458
  }, [entries, revealedStages]);
2454
- const revealed = entries.slice(0, revealedCount);
2459
+ const revealed = (0, import_react11.useMemo)(() => {
2460
+ const raw = entries.slice(0, revealedCount);
2461
+ const root = [];
2462
+ const groups = /* @__PURE__ */ new Map();
2463
+ const groupOrder = [];
2464
+ for (const e of raw) {
2465
+ const sfId = e.subflowId;
2466
+ if (sfId) {
2467
+ if (!groups.has(sfId)) {
2468
+ groups.set(sfId, []);
2469
+ groupOrder.push(sfId);
2470
+ }
2471
+ groups.get(sfId).push(e);
2472
+ } else {
2473
+ root.push(e);
2474
+ }
2475
+ }
2476
+ const result = [...root];
2477
+ for (const sfId of groupOrder) {
2478
+ result.push(...groups.get(sfId));
2479
+ }
2480
+ return result;
2481
+ }, [entries, revealedCount]);
2455
2482
  const future = entries.slice(revealedCount);
2456
2483
  const latestRef = (0, import_react11.useRef)(null);
2457
2484
  (0, import_react11.useEffect)(() => {
@@ -2481,52 +2508,65 @@ function StoryNarrative({
2481
2508
  const isDecision = entry.type === "condition";
2482
2509
  const isError = entry.type === "error";
2483
2510
  const isLast = i === revealed.length - 1;
2484
- return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(
2485
- "div",
2486
- {
2487
- ref: isLast ? latestRef : void 0,
2488
- style: {
2489
- display: "flex",
2490
- gap: 8,
2491
- padding: isStage ? `${pad - 4}px 0` : `2px 0`,
2492
- marginLeft: entry.depth * 16,
2493
- borderBottom: isStage ? `1px solid ${theme.border}` : void 0,
2494
- marginTop: isStage && i > 0 ? 8 : 0
2495
- },
2496
- children: [
2497
- /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
2498
- "span",
2499
- {
2500
- style: {
2501
- color: meta.color,
2502
- fontWeight: 700,
2503
- fontSize: isStage ? fs.body : fs.small,
2504
- width: 16,
2505
- textAlign: "center",
2506
- flexShrink: 0
2507
- },
2508
- title: meta.label,
2509
- "aria-label": meta.label,
2510
- children: meta.icon
2511
- }
2512
- ),
2513
- /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
2514
- "span",
2515
- {
2516
- style: {
2517
- fontSize: isStage ? fs.body : fs.small,
2518
- fontWeight: isStage ? 600 : 400,
2519
- color: isError ? theme.error : isDecision ? theme.warning : isStage ? theme.textPrimary : theme.textSecondary,
2520
- lineHeight: 1.6,
2521
- fontFamily: entry.type === "step" ? theme.fontMono : theme.fontSans
2522
- },
2523
- children: entry.text
2524
- }
2525
- )
2526
- ]
2527
- },
2528
- i
2529
- );
2511
+ const sfId = entry.subflowId;
2512
+ const prevSfId = i > 0 ? revealed[i - 1].subflowId : void 0;
2513
+ const subflowChanged = sfId && sfId !== prevSfId;
2514
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { ref: isLast ? latestRef : void 0, children: [
2515
+ subflowChanged && /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { style: {
2516
+ fontSize: fs.small,
2517
+ fontWeight: 600,
2518
+ color: theme.textSecondary,
2519
+ padding: `6px 0 2px`,
2520
+ marginTop: 8,
2521
+ borderTop: `1px solid ${theme.border}`,
2522
+ textTransform: "uppercase",
2523
+ letterSpacing: "0.05em"
2524
+ }, children: sfId }),
2525
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(
2526
+ "div",
2527
+ {
2528
+ style: {
2529
+ display: "flex",
2530
+ gap: 8,
2531
+ padding: isStage ? `${pad - 4}px 0` : `2px 0`,
2532
+ marginLeft: sfId ? 12 : entry.depth * 16,
2533
+ borderBottom: isStage && !sfId ? `1px solid ${theme.border}` : void 0,
2534
+ marginTop: isStage && i > 0 && !subflowChanged ? 8 : 0
2535
+ },
2536
+ children: [
2537
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
2538
+ "span",
2539
+ {
2540
+ style: {
2541
+ color: meta.color,
2542
+ fontWeight: 700,
2543
+ fontSize: isStage ? fs.body : fs.small,
2544
+ width: 16,
2545
+ textAlign: "center",
2546
+ flexShrink: 0
2547
+ },
2548
+ title: meta.label,
2549
+ "aria-label": meta.label,
2550
+ children: meta.icon
2551
+ }
2552
+ ),
2553
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
2554
+ "span",
2555
+ {
2556
+ style: {
2557
+ fontSize: isStage ? fs.body : fs.small,
2558
+ fontWeight: isStage ? 600 : 400,
2559
+ color: isError ? theme.error : isDecision ? theme.warning : isStage ? theme.textPrimary : theme.textSecondary,
2560
+ lineHeight: 1.6,
2561
+ fontFamily: entry.type === "step" ? theme.fontMono : theme.fontSans
2562
+ },
2563
+ children: entry.text
2564
+ }
2565
+ )
2566
+ ]
2567
+ }
2568
+ )
2569
+ ] }, i);
2530
2570
  }),
2531
2571
  future.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { style: {
2532
2572
  opacity: 0.3,
@@ -2588,8 +2628,10 @@ function NarrativePanel({
2588
2628
  const revealedStages = (0, import_react12.useMemo)(() => {
2589
2629
  const labels = /* @__PURE__ */ new Set();
2590
2630
  for (let i = 0; i <= selectedIndex && i < snapshots.length; i++) {
2591
- if (snapshots[i].stageLabel) labels.add(snapshots[i].stageLabel);
2592
- if (snapshots[i].stageName) labels.add(snapshots[i].stageName);
2631
+ const s = snapshots[i];
2632
+ if (s.stageLabel) labels.add(s.stageLabel);
2633
+ if (s.stageName) labels.add(s.stageName);
2634
+ if (s.subflowId) labels.add(s.subflowId);
2593
2635
  }
2594
2636
  return labels;
2595
2637
  }, [snapshots, selectedIndex]);