@juicesharp/rpiv-ask-user-question 1.0.2 → 1.0.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/apply-action.ts +276 -0
- package/ask-user-question.ts +9 -6
- package/dispatch.ts +9 -6
- package/format-answer.ts +15 -8
- package/multi-select-options.ts +4 -3
- package/option-list-view.ts +93 -0
- package/package.json +5 -1
- package/preview-block-renderer.ts +106 -0
- package/preview-pane.ts +58 -141
- package/questionnaire-session.ts +33 -24
- package/questionnaire-state.ts +7 -7
- package/types.ts +41 -9
- package/view-adapter.ts +133 -0
- package/wrapping-select.ts +27 -21
package/wrapping-select.ts
CHANGED
|
@@ -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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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 `
|
|
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 `
|
|
105
|
-
* row reads `Hello ✔` instead of `Type something. ✔` when the prior answer was custom
|
|
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 `
|
|
195
|
-
// `
|
|
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
|
|
222
|
+
return item.kind === "other" && isActive;
|
|
217
223
|
}
|
|
218
224
|
|
|
219
225
|
private renderInlineInputRow(rowPrefix: string, width: number): string {
|