proper-base 0.2.7 → 0.3.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.
@@ -267,7 +267,7 @@ function renderCollapsed(
267
267
  ) {
268
268
  group.push(child);
269
269
  } else {
270
- lines.push(...child.render(width));
270
+ lines.push(...renderExpandable(child, width, state));
271
271
  }
272
272
  }
273
273
  flush();
@@ -364,10 +364,36 @@ function renderGroup(
364
364
  continue;
365
365
  }
366
366
  if (!state.owned.has(child)) {
367
- lines.push(...child.render(width));
367
+ lines.push(...renderExpandable(child, width, state));
368
368
  continue;
369
369
  }
370
- lines.push(...withVerticalSpacing(child.render(width)));
370
+ lines.push(...withVerticalSpacing(renderExpandable(child, width, state)));
371
+ }
372
+ return lines;
373
+ }
374
+
375
+ /**
376
+ * Extension entry renderers draw their own disclosure marker from Pi's global
377
+ * tool-expansion state, so without a hit row the marker is decoration that only
378
+ * `app.tools.expand` moves. Drive the same per-item state the tool summaries use
379
+ * and register the header row, so one entry opens on click.
380
+ */
381
+ function renderExpandable(
382
+ child: Component,
383
+ width: number,
384
+ state: State,
385
+ ): string[] {
386
+ const expandable = child as ToolComponent;
387
+ if (typeof expandable.setExpanded !== "function") return child.render(width);
388
+ expandable.setExpanded(state.expanded.get(child) ?? state.globalExpanded);
389
+ const lines = child.render(width);
390
+ const header = lines.find((line) => stripTerminalSequences(line).trim());
391
+ if (header) {
392
+ state.pendingHits.push({
393
+ owner: child,
394
+ line: header,
395
+ end: visibleWidth(stripTerminalSequences(header).trimEnd()),
396
+ });
371
397
  }
372
398
  return lines;
373
399
  }
@@ -524,10 +550,10 @@ function handleClick(
524
550
  const row = Number.parseInt(match[3] ?? "", 10) - 1;
525
551
  const point = contentPoint(state.tui, column, row);
526
552
  if (!point) return undefined;
527
- const hit = state.hits.get(point.row);
528
- if (!hit || point.col < 0 || point.col >= hit.end) return undefined;
529
553
  const screenLine = screenLines(state.tui)[row];
530
- if (!screenLine || !sameHitText(screenLine, hit)) return undefined;
554
+ if (!screenLine) return undefined;
555
+ const hit = findHit(state, point.row, screenLine);
556
+ if (!hit || point.col < 0 || point.col >= hit.end) return undefined;
531
557
  if (match[4] === "M") {
532
558
  state.expanded.set(
533
559
  hit.owner,
@@ -538,6 +564,28 @@ function handleClick(
538
564
  return { consume: true };
539
565
  }
540
566
 
567
+ /**
568
+ * A wheel or keyboard scroll moves `scrollTop` immediately while the repaint
569
+ * is throttled, so the mapped content row can name a different item than the
570
+ * frame the click landed on. Fall back to the painted screen text whenever it
571
+ * identifies exactly one control.
572
+ */
573
+ function findHit(
574
+ state: State,
575
+ contentRow: number,
576
+ screenLine: string,
577
+ ): DetailHit | undefined {
578
+ const direct = state.hits.get(contentRow);
579
+ if (direct && sameHitText(screenLine, direct)) return direct;
580
+ let match: DetailHit | undefined;
581
+ for (const hit of state.hits.values()) {
582
+ if (!sameHitText(screenLine, hit)) continue;
583
+ if (match) return undefined;
584
+ match = hit;
585
+ }
586
+ return match;
587
+ }
588
+
541
589
  function contentPoint(
542
590
  tui: TUI,
543
591
  column: number,