@juicesharp/rpiv-ask-user-question 1.0.2 → 1.0.3

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.
@@ -1,20 +1,25 @@
1
1
  import type { Component } from "@mariozechner/pi-tui";
2
2
  import { truncateToWidth, visibleWidth, wrapTextWithAnsi } from "@mariozechner/pi-tui";
3
3
 
4
- export interface WrappingSelectItem {
5
- label: string;
6
- description?: string;
7
- /** Sentinel: the inline free-text input row. */
8
- isOther?: boolean;
9
- /** Sentinel: the "chat about this question" row. */
10
- isChat?: boolean;
11
- /**
12
- * Sentinel: the "Next" row appended to multi-select questions. Acts as the explicit
13
- * commit-and-advance affordance so `Enter` on regular option rows can be repurposed as
14
- * a per-row toggle (matching `Space`). Mirrors `isOther` / `isChat` in spirit.
15
- */
16
- isNext?: boolean;
17
- }
4
+ /**
5
+ * Row-intent discriminated union. `kind` replaces the legacy boolean-flag
6
+ * discriminators (`isOther`/`isChat`/`isNext`). Modeled after `QuestionnaireAction`
7
+ * (`dispatch.ts:13-32`) and `Effect` (`apply-action.ts:26-32`) — pure literal-tagged
8
+ * variants, no shared base, exhaustive-`switch` enforcement via non-`void` returns.
9
+ *
10
+ * Variant semantics:
11
+ * - `option`: a regular author-defined option row.
12
+ * - `other`: the inline free-text input row appended to single-select questions
13
+ * (label is "Type something."). Renders as inline `Input` when active.
14
+ * - `chat`: the abandon-questionnaire escape-hatch row (label is "Chat about this").
15
+ * - `next`: the explicit commit-and-advance row appended to multi-select questions
16
+ * (label is "Next"). Renders without a number / checkbox.
17
+ */
18
+ export type WrappingSelectItem =
19
+ | { kind: "option"; label: string; description?: string }
20
+ | { kind: "other"; label: string; description?: string }
21
+ | { kind: "chat"; label: string; description?: string }
22
+ | { kind: "next"; label: string; description?: string };
18
23
 
19
24
  export interface WrappingSelectTheme {
20
25
  selectedText: (text: string) => string;
@@ -63,8 +68,8 @@ export class WrappingSelect implements Component {
63
68
  private confirmedIndex: number | undefined = undefined;
64
69
  /**
65
70
  * When set together with `confirmedIndex`, replaces the row's static label at render time.
66
- * Used for the `isOther` sentinel — its label is "Type something." but if the user's prior
67
- * answer was custom text, we render that text instead (e.g. `4. Hello ✔`).
71
+ * Used for the `kind: "other"` sentinel — its label is "Type something." but if the user's
72
+ * prior answer was custom text, we render that text instead (e.g. `4. Hello ✔`).
68
73
  */
69
74
  private confirmedLabelOverride: string | undefined = undefined;
70
75
 
@@ -101,8 +106,9 @@ export class WrappingSelect implements Component {
101
106
 
102
107
  /**
103
108
  * Mark a previously-confirmed row. Pass `undefined` to clear. `labelOverride` replaces
104
- * the row's static `item.label` at render time — used for the `isOther` sentinel so the
105
- * row reads `Hello ✔` instead of `Type something. ✔` when the prior answer was custom text.
109
+ * the row's static `item.label` at render time — used for the `kind: "other"` sentinel so
110
+ * the row reads `Hello ✔` instead of `Type something. ✔` when the prior answer was custom
111
+ * text.
106
112
  */
107
113
  setConfirmedIndex(index: number | undefined, labelOverride?: string): void {
108
114
  if (index === undefined) {
@@ -191,8 +197,8 @@ export class WrappingSelect implements Component {
191
197
  // (still ❯ when active). When `index === confirmedIndex` AND `isActive`, both `❯` and
192
198
  // `✔` appear on the same row — load-bearing for the case where the prior answer was
193
199
  // row 0 (cursor resets to 0 on tab-back, so the confirmed row IS the active row).
194
- // Optional `confirmedLabelOverride` replaces the static label (used for `isOther` +
195
- // `wasCustom`); the inline-input branch above still wins for `isOther + isActive`.
200
+ // Optional `confirmedLabelOverride` replaces the static label (used for `kind: "other"`
201
+ // + `kind: "custom"` answer); the inline-input branch above still wins for `kind: "other" + isActive`.
196
202
  const isConfirmed = index === this.confirmedIndex;
197
203
  const label = isConfirmed
198
204
  ? `${this.confirmedLabelOverride ?? item.label}${WrappingSelect.CONFIRMED_MARK}`
@@ -213,7 +219,7 @@ export class WrappingSelect implements Component {
213
219
  }
214
220
 
215
221
  private shouldRenderAsInlineInput(item: WrappingSelectItem, isActive: boolean): boolean {
216
- return !!item.isOther && isActive;
222
+ return item.kind === "other" && isActive;
217
223
  }
218
224
 
219
225
  private renderInlineInputRow(rowPrefix: string, width: number): string {