vc-extras 0.1.0 → 0.1.1
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/README.md +128 -71
- package/agent-install.mjs +159 -0
- package/agents/tester.md +23 -23
- package/install-extras.mjs +41 -109
- package/install-menu.mjs +22 -43
- package/install-skills.mjs +112 -112
- package/package.json +72 -28
- package/plugin-registry.mjs +73 -0
- package/plugins/config-ui/index.ts +159 -159
- package/plugins/config-ui/lib/arguments.mjs +24 -24
- package/plugins/config-ui/lib/documents.mjs +67 -67
- package/plugins/config-ui/lib/frontmatter.mjs +91 -91
- package/plugins/config-ui/lib/open.mjs +16 -16
- package/plugins/config-ui/lib/ownership.mjs +99 -99
- package/plugins/config-ui/lib/page.mjs +11 -11
- package/plugins/config-ui/lib/patch.mjs +35 -35
- package/plugins/config-ui/lib/paths.mjs +14 -14
- package/plugins/config-ui/lib/plugin-fields.mjs +86 -86
- package/plugins/config-ui/lib/plugin-validation.mjs +28 -28
- package/plugins/config-ui/lib/redaction.mjs +8 -8
- package/plugins/config-ui/lib/registry.mjs +282 -282
- package/plugins/config-ui/lib/secrets.mjs +44 -44
- package/plugins/config-ui/lib/server.mjs +250 -250
- package/plugins/config-ui/lib/sources.mjs +96 -96
- package/plugins/config-ui/lib/state.mjs +156 -156
- package/plugins/config-ui/lib/themes.mjs +113 -113
- package/plugins/config-ui/lib/writer.mjs +690 -690
- package/plugins/config-ui/project-local-owner.ts +106 -106
- package/plugins/config-ui/vc-extras.plugin.json +13 -0
- package/plugins/config-ui/web/app.mjs +997 -997
- package/plugins/config-ui/web/index.html +342 -342
- package/plugins/pi-blackhole/vc-extras.plugin.json +12 -0
- package/plugins/pi-btw/vc-extras.plugin.json +12 -0
- package/plugins/pi-claude-code/vc-extras.plugin.json +12 -0
- package/plugins/pi-fff/vc-extras.plugin.json +12 -0
- package/plugins/pi-jev-auto-mode/vc-extras.plugin.json +12 -0
- package/plugins/pi-mcp-adapter/vc-extras.plugin.json +12 -0
- package/plugins/pi-web-access/vc-extras.plugin.json +12 -0
- package/plugins/vc-ask/claude-hook.mjs +37 -0
- package/plugins/vc-ask/codex-native.mjs +28 -0
- package/plugins/vc-ask/host-channel.mjs +75 -0
- package/plugins/vc-ask/index.ts +57 -0
- package/plugins/vc-ask/native-questions.mjs +33 -0
- package/plugins/vc-ask/package.json +10 -0
- package/plugins/vc-ask/payload.ts +170 -0
- package/plugins/vc-ask/questionnaire/LICENSE.ask-user-question +21 -0
- package/plugins/vc-ask/questionnaire/UPSTREAM.md +104 -0
- package/plugins/vc-ask/questionnaire/answer-channel.ts +135 -0
- package/plugins/vc-ask/questionnaire/config.ts +180 -0
- package/plugins/vc-ask/questionnaire/events.ts +154 -0
- package/plugins/vc-ask/questionnaire/execute.ts +688 -0
- package/plugins/vc-ask/questionnaire/i18n.ts +73 -0
- package/plugins/vc-ask/questionnaire/inline-entry.ts +312 -0
- package/plugins/vc-ask/questionnaire/locales/de.json +43 -0
- package/plugins/vc-ask/questionnaire/locales/en.json +42 -0
- package/plugins/vc-ask/questionnaire/locales/es.json +43 -0
- package/plugins/vc-ask/questionnaire/locales/fr.json +43 -0
- package/plugins/vc-ask/questionnaire/locales/pt-BR.json +43 -0
- package/plugins/vc-ask/questionnaire/locales/pt.json +43 -0
- package/plugins/vc-ask/questionnaire/locales/ru.json +43 -0
- package/plugins/vc-ask/questionnaire/locales/uk.json +43 -0
- package/plugins/vc-ask/questionnaire/locales/zh.json +46 -0
- package/plugins/vc-ask/questionnaire/presentation.ts +11 -0
- package/plugins/vc-ask/questionnaire/question-preview.ts +6 -0
- package/plugins/vc-ask/questionnaire/rpc.ts +221 -0
- package/plugins/vc-ask/questionnaire/session-timeout.ts +67 -0
- package/plugins/vc-ask/questionnaire/state/build-questionnaire.ts +144 -0
- package/plugins/vc-ask/questionnaire/state/external-editor.ts +62 -0
- package/plugins/vc-ask/questionnaire/state/geometry.ts +131 -0
- package/plugins/vc-ask/questionnaire/state/key-router.ts +382 -0
- package/plugins/vc-ask/questionnaire/state/panel-router.ts +32 -0
- package/plugins/vc-ask/questionnaire/state/questionnaire-session.ts +642 -0
- package/plugins/vc-ask/questionnaire/state/row-intent.ts +143 -0
- package/plugins/vc-ask/questionnaire/state/selectors/contract.ts +24 -0
- package/plugins/vc-ask/questionnaire/state/selectors/derivations.ts +40 -0
- package/plugins/vc-ask/questionnaire/state/selectors/focus.ts +17 -0
- package/plugins/vc-ask/questionnaire/state/selectors/projections.ts +99 -0
- package/plugins/vc-ask/questionnaire/state/state-reducer.ts +455 -0
- package/plugins/vc-ask/questionnaire/state/state.ts +90 -0
- package/plugins/vc-ask/questionnaire/state/vertical.ts +158 -0
- package/plugins/vc-ask/questionnaire/timeout.ts +59 -0
- package/plugins/vc-ask/questionnaire/tool/external-answer.ts +103 -0
- package/plugins/vc-ask/questionnaire/tool/format-answer.ts +24 -0
- package/plugins/vc-ask/questionnaire/tool/normalize-params.ts +37 -0
- package/plugins/vc-ask/questionnaire/tool/response-envelope.ts +75 -0
- package/plugins/vc-ask/questionnaire/tool/types.ts +74 -0
- package/plugins/vc-ask/questionnaire/tool/validate-questionnaire.ts +75 -0
- package/plugins/vc-ask/questionnaire/view/card-theme.ts +245 -0
- package/plugins/vc-ask/questionnaire/view/components/inline-input.ts +66 -0
- package/plugins/vc-ask/questionnaire/view/components/multi-select-view.ts +177 -0
- package/plugins/vc-ask/questionnaire/view/components/option-list-view.ts +65 -0
- package/plugins/vc-ask/questionnaire/view/components/preview/markdown-content-cache.ts +101 -0
- package/plugins/vc-ask/questionnaire/view/components/preview/preview-block-renderer.ts +130 -0
- package/plugins/vc-ask/questionnaire/view/components/preview/preview-box-renderer.ts +86 -0
- package/plugins/vc-ask/questionnaire/view/components/preview/preview-layout-decider.ts +204 -0
- package/plugins/vc-ask/questionnaire/view/components/preview/preview-pane.ts +257 -0
- package/plugins/vc-ask/questionnaire/view/components/submit-picker.ts +65 -0
- package/plugins/vc-ask/questionnaire/view/components/tab-bar.ts +57 -0
- package/plugins/vc-ask/questionnaire/view/components/wrapping-select.ts +269 -0
- package/plugins/vc-ask/questionnaire/view/dialog-builder.ts +319 -0
- package/plugins/vc-ask/questionnaire/view/document-theme.ts +53 -0
- package/plugins/vc-ask/questionnaire/view/document-view.ts +306 -0
- package/plugins/vc-ask/questionnaire/view/panel-chrome.ts +133 -0
- package/plugins/vc-ask/questionnaire/view/props-adapter.ts +77 -0
- package/plugins/vc-ask/questionnaire/view/stateful-view.ts +24 -0
- package/plugins/vc-ask/questionnaire/view/tab-components.ts +16 -0
- package/plugins/vc-ask/questionnaire/view/tab-content-strategy.ts +280 -0
- package/plugins/vc-ask/questionnaire/view/vertical-view.ts +218 -0
- package/plugins/vc-ask/user-input-events.ts +34 -0
- package/plugins/vc-ask/vc-extras.plugin.json +18 -0
- package/plugins/vc-footer/agents/claude-code/adapter.mjs +29 -0
- package/plugins/vc-footer/agents/claude-code/cli.mjs +23 -0
- package/plugins/vc-footer/agents/claude-code/renderer.mjs +1 -0
- package/plugins/vc-footer/agents/claude-code/types.d.ts +38 -0
- package/plugins/vc-footer/agents/codex/adapter.mjs +13 -0
- package/plugins/vc-footer/agents/codex/mcp.mjs +45 -0
- package/plugins/vc-footer/agents/codex/native.mjs +19 -0
- package/plugins/vc-footer/agents/codex/renderer.mjs +2 -0
- package/plugins/vc-footer/agents/pi/adapter.mjs +23 -0
- package/plugins/vc-footer/agents/pi/index.js +84 -0
- package/plugins/vc-footer/agents/pi/project-local-owner.mjs +97 -0
- package/plugins/vc-footer/agents/pi/renderer.mjs +5 -0
- package/plugins/vc-footer/core/data.mjs +218 -0
- package/plugins/vc-footer/core/render.mjs +291 -0
- package/plugins/vc-footer/core/types.d.ts +29 -0
- package/plugins/vc-footer/package.json +22 -0
- package/plugins/vc-footer/vc-extras.plugin.json +32 -0
- package/skills/animate/LICENSE +21 -21
- package/skills/animate/RECIPES.md +324 -324
- package/skills/animate/SKILL.md +208 -208
- package/skills/animate/UPSTREAM.md +19 -19
- package/skills/animation-performance/LICENSE +21 -21
- package/skills/animation-performance/SKILL.md +223 -223
- package/skills/animation-performance/UPSTREAM.md +19 -19
- package/skills/answer-me-with-html/SKILL.md +174 -174
- package/skills/answer-me-with-html/scripts/am.mjs +12896 -12896
- package/skills/apple-design/LICENSE +21 -21
- package/skills/apple-design/SKILL.md +291 -291
- package/skills/apple-design/UPSTREAM.md +19 -19
- package/skills/bad-smell/SKILL.md +44 -44
- package/skills/commit/SKILL.md +90 -90
- package/skills/emil-design-eng/LICENSE +21 -21
- package/skills/emil-design-eng/SKILL.md +677 -677
- package/skills/emil-design-eng/UPSTREAM.md +19 -19
- package/skills/find-the-truth/SKILL.md +38 -38
- package/skills/find-the-truth/references/trace-method.md +48 -48
- package/skills/find-the-truth/references/truth-method.md +39 -39
- package/skills/gestures/LICENSE +21 -21
- package/skills/gestures/SKILL.md +107 -107
- package/skills/gestures/UPSTREAM.md +19 -19
- package/skills/humanizer-zh/LICENSE +21 -21
- package/skills/humanizer-zh/SKILL.md +409 -409
- package/skills/humanizer-zh/UPSTREAM.md +7 -7
- package/skills/impeccable/LICENSE +191 -191
- package/skills/impeccable/NOTICE.md +11 -11
- package/skills/impeccable/SKILL.md +89 -89
- package/skills/impeccable/licenses/modern-screenshot-MIT.txt +8 -8
- package/skills/impeccable/licenses/platform-design-skills-MIT.txt +21 -21
- package/skills/impeccable/reference/adapt.md +318 -318
- package/skills/impeccable/reference/adapt.native.md +58 -58
- package/skills/impeccable/reference/android.md +46 -46
- package/skills/impeccable/reference/animate.md +89 -89
- package/skills/impeccable/reference/audit.md +139 -139
- package/skills/impeccable/reference/audit.native.md +139 -139
- package/skills/impeccable/reference/bolder.md +33 -33
- package/skills/impeccable/reference/clarify.md +94 -94
- package/skills/impeccable/reference/colorize.md +86 -86
- package/skills/impeccable/reference/component-review.md +63 -63
- package/skills/impeccable/reference/craft-floor.md +44 -44
- package/skills/impeccable/reference/craft.md +5 -5
- package/skills/impeccable/reference/critique.md +819 -819
- package/skills/impeccable/reference/degraded/asset-producer.md +41 -41
- package/skills/impeccable/reference/degraded/documenter.md +23 -23
- package/skills/impeccable/reference/degraded/finish-reviewer.md +37 -37
- package/skills/impeccable/reference/degraded/manual-edit-applier.md +92 -92
- package/skills/impeccable/reference/delight.md +70 -70
- package/skills/impeccable/reference/distill.md +111 -111
- package/skills/impeccable/reference/doctor.md +54 -54
- package/skills/impeccable/reference/document.md +416 -416
- package/skills/impeccable/reference/extract.md +69 -69
- package/skills/impeccable/reference/generate.md +101 -101
- package/skills/impeccable/reference/harden.md +362 -362
- package/skills/impeccable/reference/hooks.md +114 -114
- package/skills/impeccable/reference/init.md +131 -131
- package/skills/impeccable/reference/ios.md +51 -51
- package/skills/impeccable/reference/layout.md +84 -84
- package/skills/impeccable/reference/live-setup.md +104 -104
- package/skills/impeccable/reference/live.md +327 -327
- package/skills/impeccable/reference/mode-operate.md +21 -21
- package/skills/impeccable/reference/mode-persuade.md +19 -19
- package/skills/impeccable/reference/mode-read.md +21 -21
- package/skills/impeccable/reference/new-work.md +152 -152
- package/skills/impeccable/reference/onboard.md +234 -234
- package/skills/impeccable/reference/operate.md +61 -61
- package/skills/impeccable/reference/optimize.md +257 -257
- package/skills/impeccable/reference/overdrive.md +127 -127
- package/skills/impeccable/reference/polish.md +105 -105
- package/skills/impeccable/reference/quieter.md +99 -99
- package/skills/impeccable/reference/region-map.md +26 -26
- package/skills/impeccable/reference/routing.md +24 -24
- package/skills/impeccable/reference/shape.md +59 -59
- package/skills/impeccable/reference/typeset.md +90 -90
- package/skills/impeccable/reference/visualize.md +47 -47
- package/skills/impeccable/scripts/VERSION +1 -1
- package/skills/impeccable/scripts/command-metadata.json +98 -98
- package/skills/impeccable/scripts/data/font-index-failures.json +120 -120
- package/skills/impeccable/scripts/engine-checksums.txt +9 -9
- package/skills/impeccable/scripts/impeccable +249 -249
- package/skills/impeccable/scripts/impeccable.cmd +278 -278
- package/skills/impeccable/scripts/live-browser-dom.js +320 -320
- package/skills/impeccable/scripts/live-browser-ignores.js +246 -246
- package/skills/impeccable/scripts/live-browser-session.js +183 -183
- package/skills/impeccable/scripts/live-browser.js +13862 -13862
- package/skills/impeccable/scripts/modern-screenshot.umd.js +14 -14
- package/skills/improve-animations/AUDIT.md +115 -115
- package/skills/improve-animations/LICENSE +21 -21
- package/skills/improve-animations/PLAN-TEMPLATE.md +73 -73
- package/skills/improve-animations/SKILL.md +110 -110
- package/skills/improve-animations/UPSTREAM.md +19 -19
- package/skills/pick-ui-library/LICENSE +21 -21
- package/skills/pick-ui-library/SKILL.md +85 -85
- package/skills/pick-ui-library/UPSTREAM.md +19 -19
- package/skills/review-animations/LICENSE +21 -21
- package/skills/review-animations/SKILL.md +120 -120
- package/skills/review-animations/STANDARDS.md +187 -187
- package/skills/review-animations/UPSTREAM.md +19 -19
- package/skills/test/SKILL.md +29 -29
- package/skills/test/references/test-method.md +60 -60
- package/skills/write-doc/SKILL.md +115 -115
- package/skills/write-doc/examples/result-report.md +53 -53
- package/skills/write-doc/examples/task-summary.md +45 -45
- package/skills/write-doc/references/terminology.md +147 -147
- package/specs/ask-host-protocol-v1.md +58 -0
- package/specs/design-demo.md +1102 -1102
- package/specs/frontend-immersive.md +28 -28
- package/specs/plugin-install-v2.md +123 -0
- package/specs/plugin-install.md +38 -0
- package/specs/web-modes/explore.md +31 -31
- package/specs/web-modes/risk.md +15 -15
- package/specs/web-modes/verify.md +16 -16
- package/vc-extras.mjs +46 -62
- package/plugins/essrj/context.ts +0 -47
- package/plugins/essrj/data.ts +0 -190
- package/plugins/essrj/index.ts +0 -139
- package/plugins/essrj/package.json +0 -12
- package/plugins/essrj/project-local-owner.ts +0 -106
- package/plugins/essrj/render.ts +0 -217
- package/plugins/essrj/types.ts +0 -40
- package/plugins.json +0 -38
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
import type { Theme } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { type Component, Container, type Editor, Spacer, truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
|
|
3
|
+
import type { QuestionnaireState, QuestionnaireViewport } from "../state/state.js";
|
|
4
|
+
import type { QuestionData } from "../tool/types.js";
|
|
5
|
+
import { hasQuestionLevelPreview } from "../question-preview.js";
|
|
6
|
+
import type { PreviewPaneProps } from "./components/preview/preview-pane.js";
|
|
7
|
+
import type { TabBar } from "./components/tab-bar.js";
|
|
8
|
+
import type { StatefulView } from "./stateful-view.js";
|
|
9
|
+
import type { TabComponents } from "./tab-components.js";
|
|
10
|
+
import { QuestionTabStrategy, SubmitTabStrategy, type TabContentStrategy } from "./tab-content-strategy.js";
|
|
11
|
+
|
|
12
|
+
export const HINT_PART_ENTER = "↵ select";
|
|
13
|
+
export const HINT_PART_NAV = "↑↓ navigate";
|
|
14
|
+
// The ctrl variants are the only paging keys reachable in every host: Pi's full-screen
|
|
15
|
+
// renderer claims the bare keys and the wheel for the transcript viewport, and the
|
|
16
|
+
// main-screen renderer never sees wheel events at all. No `hint.scroll` key exists in any
|
|
17
|
+
// locale, so `t("hint.scroll", …)` falls back to this constant.
|
|
18
|
+
export const HINT_PART_SCROLL = "ctrl+pgup/pgdn scroll";
|
|
19
|
+
export const HINT_PART_NEW_LINE = "⇧↵ newline";
|
|
20
|
+
export const HINT_PART_CLEAR = "⌃u clear";
|
|
21
|
+
export const HINT_PART_TOGGLE = "space toggle";
|
|
22
|
+
export const HINT_PART_NOTES = "n notes";
|
|
23
|
+
export const HINT_PART_TAB = "⇥ questions";
|
|
24
|
+
export const HINT_PART_CANCEL = "esc cancel";
|
|
25
|
+
export const HINT_PART_COLLAPSE = "⌃] collapse";
|
|
26
|
+
export const HINT_PART_EXPAND = "⌃] expand";
|
|
27
|
+
/**
|
|
28
|
+
* `HINT_SINGLE` / `HINT_MULTI` are the resting core hint for NON-multiSelect
|
|
29
|
+
* question tabs only: `buildHintText` drops `NOTES` while the notes editor is
|
|
30
|
+
* open (`state.notesVisible`) or the "Type something." row is capturing text
|
|
31
|
+
* (`state.inputMode`), and on multiSelect tabs it interleaves `TOGGLE` between
|
|
32
|
+
* `NAV` and `NOTES`, so neither composite is a substring there — assert on
|
|
33
|
+
* `HINT_PART_*` constants in those states instead. The collapse affordance is
|
|
34
|
+
* appended AFTER cancel by `buildHintText` so the resting core stays a contiguous
|
|
35
|
+
* prefix substring of the rendered line. On narrow terminals the collapse tail
|
|
36
|
+
* clips with `…` (`OneLineClippedText`); the core is preserved.
|
|
37
|
+
*/
|
|
38
|
+
export const HINT_SINGLE = [HINT_PART_ENTER, HINT_PART_NAV, HINT_PART_NOTES, HINT_PART_CANCEL].join(" · ");
|
|
39
|
+
export const HINT_MULTI = [HINT_PART_ENTER, HINT_PART_NAV, HINT_PART_NOTES, HINT_PART_TAB, HINT_PART_CANCEL].join(
|
|
40
|
+
" · ",
|
|
41
|
+
);
|
|
42
|
+
/** Single-line footer shown by `QuestionnaireSession` when `state.collapsed === true`. Bypasses `buildHintText`. */
|
|
43
|
+
export const COLLAPSED_HINT = [HINT_PART_EXPAND, HINT_PART_CANCEL].join(" · ");
|
|
44
|
+
export const REVIEW_HEADING = "Review your answers";
|
|
45
|
+
export const READY_PROMPT = "Ready to submit your answers?";
|
|
46
|
+
export const INCOMPLETE_WARNING_PREFIX = "⚠ Answer remaining questions before submitting:";
|
|
47
|
+
|
|
48
|
+
const OVERFLOW_UP = "↑";
|
|
49
|
+
const OVERFLOW_DOWN = "↓";
|
|
50
|
+
const OVERFLOW_BOTH = "↕";
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Wrap interior lines in a closed, titled box (CC plan-dialog style):
|
|
54
|
+
* `╭─ title ──…──╮` / `│ … │` / `╰──…──╯`. Adds no rows — replaces the
|
|
55
|
+
* plain DynamicBorder top/bottom lines — so every height computation in
|
|
56
|
+
* DialogView stays valid. Degrades to the raw lines below 8 columns.
|
|
57
|
+
*/
|
|
58
|
+
export function wrapClosedBox(
|
|
59
|
+
lines: readonly string[],
|
|
60
|
+
width: number,
|
|
61
|
+
title: string | undefined,
|
|
62
|
+
colorFn: (s: string) => string,
|
|
63
|
+
): string[] {
|
|
64
|
+
if (width < 8) return [...lines];
|
|
65
|
+
const inner = Math.max(1, width - 4);
|
|
66
|
+
const titleText = title ? `─ ${title} ` : "";
|
|
67
|
+
const topFill = Math.max(0, width - 2 - visibleWidth(titleText));
|
|
68
|
+
const top = colorFn(`╭${titleText}${"─".repeat(topFill)}╮`);
|
|
69
|
+
const bottom = colorFn(`╰${"─".repeat(Math.max(0, width - 2))}╯`);
|
|
70
|
+
const out = [top];
|
|
71
|
+
for (const line of lines) {
|
|
72
|
+
const clipped = truncateToWidth(line, inner, "", true);
|
|
73
|
+
const pad = " ".repeat(Math.max(0, inner - visibleWidth(clipped)));
|
|
74
|
+
out.push(`${colorFn("│")} ${clipped}${pad} ${colorFn("│")}`);
|
|
75
|
+
}
|
|
76
|
+
out.push(bottom);
|
|
77
|
+
return out;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export type DialogState = QuestionnaireState;
|
|
81
|
+
|
|
82
|
+
/** Per-tick projection of dialog state. Written by the adapter; read by the strategy thunk. */
|
|
83
|
+
export interface DialogProps {
|
|
84
|
+
state: DialogState;
|
|
85
|
+
activePreviewPane: StatefulView<PreviewPaneProps>;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** Construction-time config for `DialogView`. Frozen after construction. */
|
|
89
|
+
export interface DialogConfig {
|
|
90
|
+
theme: Theme;
|
|
91
|
+
questions: readonly QuestionData[];
|
|
92
|
+
tabBar: TabBar | undefined;
|
|
93
|
+
notesInput: Editor;
|
|
94
|
+
isMulti: boolean;
|
|
95
|
+
tabsByIndex: ReadonlyArray<TabComponents>;
|
|
96
|
+
/** Optional so single-question mode and non-submit tests can omit it; SubmitTabStrategy falls back to Spacer rows. */
|
|
97
|
+
submitPicker?: Component;
|
|
98
|
+
/** Worst-case body height across all tabs/options. Determines the stable overall dialog footprint. */
|
|
99
|
+
getBodyHeight: (width: number) => number;
|
|
100
|
+
/** Body height of the CURRENTLY active tab/option. The chrome subtracts this from `getBodyHeight` to absorb the residual OUTSIDE the bordered region. */
|
|
101
|
+
getCurrentBodyHeight: (width: number) => number;
|
|
102
|
+
/** Terminal height getter. Mirrors `getTerminalWidth` — reads `tui.terminal.rows` at render time. */
|
|
103
|
+
getTerminalRows: () => number;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* The 7th renderable, promoted from a structural literal to a named class so
|
|
108
|
+
* all view-layer components share one explicit `implements StatefulView<P>`
|
|
109
|
+
* contract. `setProps(DialogProps)` writes the live cell read by the
|
|
110
|
+
* strategy thunk during `render()`. `liveProps.activePreviewPane` is a
|
|
111
|
+
* resolved pane reference threaded by the adapter per tick — the dialog
|
|
112
|
+
* itself does not derive it.
|
|
113
|
+
*/
|
|
114
|
+
export class DialogView implements StatefulView<DialogProps> {
|
|
115
|
+
private liveProps: DialogProps;
|
|
116
|
+
private readonly config: DialogConfig;
|
|
117
|
+
private readonly questionStrategy: TabContentStrategy;
|
|
118
|
+
private readonly submitStrategy: TabContentStrategy | undefined;
|
|
119
|
+
private readonly maxFooterRowCount: number;
|
|
120
|
+
private viewport: QuestionnaireViewport = { scrollStart: 0, pageSize: 0, maxScrollStart: 0 };
|
|
121
|
+
|
|
122
|
+
constructor(config: DialogConfig, initialProps: DialogProps) {
|
|
123
|
+
this.config = config;
|
|
124
|
+
this.liveProps = initialProps;
|
|
125
|
+
this.questionStrategy = new QuestionTabStrategy({
|
|
126
|
+
theme: config.theme,
|
|
127
|
+
questions: config.questions,
|
|
128
|
+
getPreviewPane: () => this.liveProps.activePreviewPane,
|
|
129
|
+
tabsByIndex: config.tabsByIndex,
|
|
130
|
+
notesInput: config.notesInput,
|
|
131
|
+
isMulti: config.isMulti,
|
|
132
|
+
getCurrentBodyHeight: config.getCurrentBodyHeight,
|
|
133
|
+
});
|
|
134
|
+
this.submitStrategy = config.isMulti
|
|
135
|
+
? new SubmitTabStrategy({
|
|
136
|
+
theme: config.theme,
|
|
137
|
+
questions: config.questions,
|
|
138
|
+
submitPicker: config.submitPicker,
|
|
139
|
+
})
|
|
140
|
+
: undefined;
|
|
141
|
+
this.maxFooterRowCount = Math.max(this.questionStrategy.footerRowCount, this.submitStrategy?.footerRowCount ?? 0);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
setProps(props: DialogProps): void {
|
|
145
|
+
this.liveProps = props;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
getViewport(): QuestionnaireViewport {
|
|
149
|
+
return this.viewport;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
handleInput(_data: string): void {}
|
|
153
|
+
|
|
154
|
+
// Invalidation is driven by `QuestionnairePropsAdapter.invalidate()`, which
|
|
155
|
+
// owns the full set of renderables (binding registries + extras like
|
|
156
|
+
// `notesInput`). DialogView has no cached layout of its own.
|
|
157
|
+
invalidate(): void {}
|
|
158
|
+
|
|
159
|
+
render(width: number): string[] {
|
|
160
|
+
const state = this.liveProps.state;
|
|
161
|
+
const onSubmit = this.config.isMulti && state.currentTab === this.config.questions.length;
|
|
162
|
+
const strategy = onSubmit && this.submitStrategy ? this.submitStrategy : this.questionStrategy;
|
|
163
|
+
|
|
164
|
+
// Cache heading rows (avoid double construction in render and container build).
|
|
165
|
+
const headingRowCache = strategy.headingRows(state);
|
|
166
|
+
|
|
167
|
+
// Closed titled box: │, space, space, │ consume 4 columns; the box also supplies
|
|
168
|
+
// the top/bottom border rows (2) that DynamicBorder used to render.
|
|
169
|
+
const interior = Math.max(4, width - 4);
|
|
170
|
+
const boxRows = 2;
|
|
171
|
+
// Pinned heading rows are counted in RENDERED lines, not components: pi-tui `Text`
|
|
172
|
+
// wraps on word boundaries, so a long question renders as 2+ lines while counting
|
|
173
|
+
// as a single component. Undercounting left the wrapped tail in the scrollable
|
|
174
|
+
// middle, where it scrolled out of view or was overwritten by the ↑ marker.
|
|
175
|
+
// `Text` caches by width, so this adds no extra layout work.
|
|
176
|
+
const headingCount = headingRowCache.reduce((count, component) => count + component.render(interior).length, 0);
|
|
177
|
+
let natural = this.buildContainerFromStrategy(strategy, headingRowCache, false).render(interior);
|
|
178
|
+
|
|
179
|
+
// Fixed region sizes (deterministic from structure). TabBar.render() returns
|
|
180
|
+
// [tabLine, ""] — always 2 rows. The heading rows (question text) are pinned too:
|
|
181
|
+
// they used to sit inside the scrollable middle and scrolled out of view once the
|
|
182
|
+
// option list + previews exceeded the terminal height, hiding what was being asked.
|
|
183
|
+
// Border rows live outside `natural` (in the box).
|
|
184
|
+
const topFixed = (this.config.isMulti && this.config.tabBar ? 2 : 0) + 1 + headingCount;
|
|
185
|
+
const bottomFixed = strategy.footerRowCount;
|
|
186
|
+
const middleRows = natural.length - topFixed - bottomFixed;
|
|
187
|
+
|
|
188
|
+
// Residual spacer: equalizes total height across tabs (only needed when no overflow).
|
|
189
|
+
const spacerRows = Math.max(
|
|
190
|
+
0,
|
|
191
|
+
this.config.getBodyHeight(interior) +
|
|
192
|
+
this.maxFooterRowCount -
|
|
193
|
+
strategy.bodyHeight(interior, state) -
|
|
194
|
+
strategy.footerRowCount,
|
|
195
|
+
);
|
|
196
|
+
|
|
197
|
+
const termRows = this.config.getTerminalRows();
|
|
198
|
+
const availableMiddle = Math.max(0, termRows - topFixed - bottomFixed - boxRows);
|
|
199
|
+
const previewScrollable =
|
|
200
|
+
natural.length + spacerRows + boxRows > termRows &&
|
|
201
|
+
Math.max(0, middleRows - availableMiddle) > 0;
|
|
202
|
+
if (previewScrollable) {
|
|
203
|
+
// Footer text is height-stable (one clipped line), so rebuilding it with the
|
|
204
|
+
// current render's overflow result cannot change the viewport calculation.
|
|
205
|
+
natural = this.buildContainerFromStrategy(strategy, headingRowCache, true).render(interior);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
let result: string[];
|
|
209
|
+
if (natural.length + spacerRows + boxRows <= termRows) {
|
|
210
|
+
// No overflow — add residual spacer rows after footer.
|
|
211
|
+
this.viewport = { scrollStart: 0, pageSize: middleRows, maxScrollStart: 0 };
|
|
212
|
+
result = spacerRows > 0 ? [...natural, ...Array<string>(spacerRows).fill("")] : natural;
|
|
213
|
+
} else {
|
|
214
|
+
result = this.renderOverflowed(natural, strategy, state, topFixed, bottomFixed, middleRows, interior, termRows, boxRows);
|
|
215
|
+
}
|
|
216
|
+
const title =
|
|
217
|
+
this.config.questions.find((question) => question.title)?.title ??
|
|
218
|
+
(this.config.isMulti
|
|
219
|
+
? undefined
|
|
220
|
+
: this.config.questions.find((question) => question.header)?.header);
|
|
221
|
+
return wrapClosedBox(result, width, title, (s) => this.config.theme.fg("accent", s));
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
private renderOverflowed(
|
|
225
|
+
natural: string[],
|
|
226
|
+
strategy: TabContentStrategy,
|
|
227
|
+
state: DialogState,
|
|
228
|
+
topFixed: number,
|
|
229
|
+
bottomFixed: number,
|
|
230
|
+
middleRows: number,
|
|
231
|
+
interior: number,
|
|
232
|
+
termRows: number,
|
|
233
|
+
boxRows: number,
|
|
234
|
+
): string[] {
|
|
235
|
+
const availableMiddle = Math.max(0, termRows - topFixed - bottomFixed - boxRows);
|
|
236
|
+
if (availableMiddle === 0) {
|
|
237
|
+
// Terminal too small for any middle content — show just chrome.
|
|
238
|
+
this.viewport = {
|
|
239
|
+
scrollStart: 0,
|
|
240
|
+
pageSize: 0,
|
|
241
|
+
maxScrollStart: Math.max(0, middleRows),
|
|
242
|
+
};
|
|
243
|
+
const chromeOnly = [...natural.slice(0, topFixed), ...natural.slice(natural.length - bottomFixed)];
|
|
244
|
+
return chromeOnly.length + boxRows > termRows ? chromeOnly.slice(0, Math.max(0, termRows - boxRows)) : chromeOnly;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
const bodyRange = strategy.focusedItemRowRange(interior, state);
|
|
248
|
+
const maxScrollStart = Math.max(0, middleRows - availableMiddle);
|
|
249
|
+
|
|
250
|
+
// A question-level preview is a document, not an option teaser. Preserve an
|
|
251
|
+
// explicit viewport for it; option navigation sets the offset back to null and
|
|
252
|
+
// therefore resumes the established focus-following behavior below.
|
|
253
|
+
let scrollStart: number;
|
|
254
|
+
const question = this.config.questions[state.currentTab];
|
|
255
|
+
if (hasQuestionLevelPreview(question) && state.previewScrollOffset !== null) {
|
|
256
|
+
scrollStart = Math.max(0, Math.min(state.previewScrollOffset, maxScrollStart));
|
|
257
|
+
} else if (bodyRange) {
|
|
258
|
+
// Heading rows are pinned into topFixed, so the middle starts at the body —
|
|
259
|
+
// the focused row's offset within the middle is its offset within the body.
|
|
260
|
+
const focusedRowInMiddle = bodyRange[0];
|
|
261
|
+
const focusedHeight = bodyRange[1] - bodyRange[0];
|
|
262
|
+
const idealStart = focusedRowInMiddle - Math.floor(Math.max(0, availableMiddle - focusedHeight) / 2);
|
|
263
|
+
scrollStart = Math.max(0, Math.min(idealStart, maxScrollStart));
|
|
264
|
+
} else {
|
|
265
|
+
// No interactive focus (submit tab) — top-anchor the middle.
|
|
266
|
+
scrollStart = 0;
|
|
267
|
+
}
|
|
268
|
+
this.viewport = { scrollStart, pageSize: availableMiddle, maxScrollStart };
|
|
269
|
+
|
|
270
|
+
const scrollableMiddle = natural.slice(topFixed + scrollStart, topFixed + scrollStart + availableMiddle);
|
|
271
|
+
|
|
272
|
+
const hasUp = scrollStart > 0;
|
|
273
|
+
const hasDown = scrollStart + availableMiddle < middleRows;
|
|
274
|
+
if (hasUp && hasDown && scrollableMiddle.length === 1) {
|
|
275
|
+
// Single-row middle: combined ↕ avoids the prior collision where ↓ overwrote ↑.
|
|
276
|
+
scrollableMiddle[0] = this.config.theme.fg("dim", OVERFLOW_BOTH);
|
|
277
|
+
} else {
|
|
278
|
+
if (hasUp && scrollableMiddle.length > 0) {
|
|
279
|
+
scrollableMiddle[0] = this.config.theme.fg("dim", OVERFLOW_UP);
|
|
280
|
+
}
|
|
281
|
+
if (hasDown && scrollableMiddle.length > 0) {
|
|
282
|
+
scrollableMiddle[scrollableMiddle.length - 1] = this.config.theme.fg("dim", OVERFLOW_DOWN);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
const result = [
|
|
287
|
+
...natural.slice(0, topFixed),
|
|
288
|
+
...scrollableMiddle,
|
|
289
|
+
...natural.slice(natural.length - bottomFixed),
|
|
290
|
+
];
|
|
291
|
+
// Safety: never exceed terminal rows (covers the availableMiddle === 0 case
|
|
292
|
+
// where topFixed + bottomFixed > termRows).
|
|
293
|
+
return result.length > termRows ? result.slice(0, termRows) : result;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
private buildContainerFromStrategy(
|
|
297
|
+
strategy: TabContentStrategy,
|
|
298
|
+
headingRowCache: Component[],
|
|
299
|
+
previewScrollable: boolean,
|
|
300
|
+
): Container {
|
|
301
|
+
const { isMulti, tabBar } = this.config;
|
|
302
|
+
const state = this.liveProps.state;
|
|
303
|
+
const container = new Container();
|
|
304
|
+
// No DynamicBorder children: the closed titled box (wrapClosedBox) supplies the
|
|
305
|
+
// top/bottom border rows and side columns around the whole rendered result.
|
|
306
|
+
if (isMulti && tabBar) container.addChild(tabBar);
|
|
307
|
+
container.addChild(new Spacer(1));
|
|
308
|
+
|
|
309
|
+
for (const c of headingRowCache) container.addChild(c);
|
|
310
|
+
container.addChild(strategy.bodyComponent(state));
|
|
311
|
+
container.addChild(new Spacer(1));
|
|
312
|
+
for (const c of strategy.midRows(state)) container.addChild(c);
|
|
313
|
+
|
|
314
|
+
for (const c of strategy.footerRows(state, previewScrollable)) container.addChild(c);
|
|
315
|
+
|
|
316
|
+
// BodyResidualSpacer moved out of Container — handled in render().
|
|
317
|
+
return container;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { Theme } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import type { MarkdownTheme } from "@earendil-works/pi-tui";
|
|
3
|
+
import { parseFgAnsiRgb } from "./card-theme.js";
|
|
4
|
+
|
|
5
|
+
const PALETTES = {
|
|
6
|
+
light: { panel: "fafafa", text: "292831", muted: "686571", line: "dedce3", selected: "eee8f6" },
|
|
7
|
+
dark: { panel: "161718", text: "e8e8ec", muted: "92939f", line: "36363e", selected: "332e40" },
|
|
8
|
+
};
|
|
9
|
+
const ESC = "\x1b[";
|
|
10
|
+
|
|
11
|
+
/** Colors are local to the document; callbacks resolve the current host appearance. */
|
|
12
|
+
export class DocumentTheme {
|
|
13
|
+
constructor(private readonly base: Theme) {}
|
|
14
|
+
|
|
15
|
+
private color(name: keyof typeof PALETTES.dark, background = false): string {
|
|
16
|
+
const appearance = (this.base as Theme & { appearance?: string }).appearance;
|
|
17
|
+
const rgb = parseFgAnsiRgb(this.base.fg("text", ""));
|
|
18
|
+
const light = appearance ? appearance === "light" : rgb ? (rgb.r + rgb.g + rgb.b) / 3 < 120 : false;
|
|
19
|
+
const values = PALETTES[light ? "light" : "dark"][name].match(/../g)!.map(n => parseInt(n, 16));
|
|
20
|
+
const prefix = background ? 48 : 38;
|
|
21
|
+
if (this.base.getColorMode?.() === "256color") {
|
|
22
|
+
const gray = Math.round(values.reduce((a, b) => a + b, 0) / 3);
|
|
23
|
+
const index = gray > 248 ? 231 : gray < 4 ? 16 :
|
|
24
|
+
Math.max(232, Math.min(255, 232 + Math.round((gray - 8) / 10)));
|
|
25
|
+
return ESC + prefix + ";5;" + index + "m";
|
|
26
|
+
}
|
|
27
|
+
return ESC + prefix + ";2;" + values.join(";") + "m";
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
text(s: string): string {
|
|
31
|
+
const foreground = this.color("text");
|
|
32
|
+
return foreground + s.replace(/\x1b\[39m/g, foreground).replace(/\x1b\[0m/g, ESC + "0m" + foreground) + ESC + "39m";
|
|
33
|
+
}
|
|
34
|
+
muted(s: string): string { return this.color("muted") + s + ESC + "39m"; }
|
|
35
|
+
line(s: string): string { return this.color("line") + s + ESC + "39m"; }
|
|
36
|
+
selected(s: string): string { return this.color("selected", true) + this.text(s) + ESC + "49m"; }
|
|
37
|
+
panel(s: string): string {
|
|
38
|
+
const background = this.color("panel", true);
|
|
39
|
+
return background + s.replace(/\x1b\[49m/g, background).replace(/\x1b\[0m/g, ESC + "0m" + background) + ESC + "49m";
|
|
40
|
+
}
|
|
41
|
+
bold(s: string): string { return this.base.bold(s); }
|
|
42
|
+
|
|
43
|
+
markdown(): MarkdownTheme {
|
|
44
|
+
return {
|
|
45
|
+
heading: s => this.text(this.bold(s)),
|
|
46
|
+
link: s => this.text(this.base.underline(s)), linkUrl: s => this.muted(s),
|
|
47
|
+
code: s => this.selected(s), codeBlock: s => this.text(s), codeBlockBorder: s => this.muted(s),
|
|
48
|
+
quote: s => this.text(s), quoteBorder: s => this.muted(s), hr: s => this.line(s), listBullet: s => this.muted(s),
|
|
49
|
+
bold: s => this.base.bold(s), italic: s => this.base.italic(s),
|
|
50
|
+
strikethrough: s => this.base.strikethrough(s), underline: s => this.base.underline(s),
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
import { CURSOR_MARKER, truncateToWidth, visibleWidth, wrapTextWithAnsi, type Editor } from "@earendil-works/pi-tui";
|
|
2
|
+
import type { Theme } from "@earendil-works/pi-coding-agent";
|
|
3
|
+
import type { QuestionnaireState, QuestionnaireViewport } from "../state/state.js";
|
|
4
|
+
import { bodyHeight, dockPanel, fitsDock, floatPanel, isDocked, type PanelGeometry, type TerminalSize } from "../state/geometry.js";
|
|
5
|
+
import type { QuestionData } from "../tool/types.js";
|
|
6
|
+
import type { WrappingSelectItem } from "./components/wrapping-select.js";
|
|
7
|
+
import { MarkdownContentCache } from "./components/preview/markdown-content-cache.js";
|
|
8
|
+
import { DocumentTheme } from "./document-theme.js";
|
|
9
|
+
import { PanelChrome, panelBlank, panelBottom, panelDivider, panelRow, panelTop, fitHint, type AskPalette } from "./panel-chrome.js";
|
|
10
|
+
import { t } from "../i18n.js";
|
|
11
|
+
|
|
12
|
+
export interface DocumentRect { x: number; y: number; width: number; height: number }
|
|
13
|
+
export const DOCUMENT_HINT = "↑↓ Select | Enter Confirm | Esc Cancel";
|
|
14
|
+
/** Scrollbar idle window: it appears while scrolling and hides again after this pause. */
|
|
15
|
+
export const SCROLLBAR_IDLE_MS = 1200;
|
|
16
|
+
|
|
17
|
+
export type PanelDragKind = "move" | "resize-w" | "resize-h" | "resize-both" | "button" | "dock-resize" | "dock-button";
|
|
18
|
+
|
|
19
|
+
interface DocumentConfig {
|
|
20
|
+
theme: Theme;
|
|
21
|
+
palette?: AskPalette;
|
|
22
|
+
question: QuestionData;
|
|
23
|
+
items: readonly WrappingSelectItem[];
|
|
24
|
+
input: Editor;
|
|
25
|
+
notes: Editor;
|
|
26
|
+
rows: () => number;
|
|
27
|
+
terminalRows: () => number;
|
|
28
|
+
terminalColumns: () => number;
|
|
29
|
+
requestRender: () => void;
|
|
30
|
+
initialState: QuestionnaireState;
|
|
31
|
+
previewLabel?: string;
|
|
32
|
+
/** Called once when docked content turns out not to fit the dock: the host promotes it to a card. */
|
|
33
|
+
onOverflow?: () => void;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** A bounded document and an independent, focus-following action window. */
|
|
37
|
+
export class DocumentView {
|
|
38
|
+
private state: QuestionnaireState;
|
|
39
|
+
private readonly colors: DocumentTheme;
|
|
40
|
+
private readonly cache: MarkdownContentCache;
|
|
41
|
+
private viewport: QuestionnaireViewport = { scrollStart: 0, pageSize: 0, maxScrollStart: 0 };
|
|
42
|
+
private actionOffset = 0;
|
|
43
|
+
private actionPageSize = 1;
|
|
44
|
+
private actionMaxOffset = 0;
|
|
45
|
+
private actionSelection = -1;
|
|
46
|
+
private actionTargets = new Map<number, number>();
|
|
47
|
+
private visibleActionIndexes: number[] = [];
|
|
48
|
+
private customActionRow = -1;
|
|
49
|
+
private customActionHeight = 0;
|
|
50
|
+
private renderSource = false;
|
|
51
|
+
private panel: PanelGeometry = { col: 0, row: 0, w: 0, h: 0 };
|
|
52
|
+
private overflowReported = false;
|
|
53
|
+
private wrappedBody: { lines: string[]; width: number; source: boolean; result: string[] } | undefined;
|
|
54
|
+
private revision = 0;
|
|
55
|
+
private scrolledAt = 0;
|
|
56
|
+
private hideTimer: ReturnType<typeof setTimeout> | undefined;
|
|
57
|
+
bodyRect: DocumentRect = { x: 0, y: 0, width: 0, height: 0 };
|
|
58
|
+
inputRect: DocumentRect = { x: 0, y: 0, width: 0, height: 0 };
|
|
59
|
+
editorWidth = 1;
|
|
60
|
+
actionable = false;
|
|
61
|
+
selectionVisible = false;
|
|
62
|
+
focused = false;
|
|
63
|
+
|
|
64
|
+
constructor(private readonly config: DocumentConfig) {
|
|
65
|
+
this.state = config.initialState;
|
|
66
|
+
this.colors = new DocumentTheme(config.theme);
|
|
67
|
+
this.cache = new MarkdownContentCache(config.question, config.theme, this.colors.markdown(), true);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
setProps(state: QuestionnaireState): void {
|
|
71
|
+
if (state.previewScrollOffset !== this.state.previewScrollOffset) this.markScrolled();
|
|
72
|
+
this.state = state;
|
|
73
|
+
}
|
|
74
|
+
getViewport(): QuestionnaireViewport { return this.viewport; }
|
|
75
|
+
getRenderVersion(): string { return this.revision + ":" + this.scrollbarVisible; }
|
|
76
|
+
reposition(panel: PanelGeometry): void {
|
|
77
|
+
const dx = panel.col - this.panel.col, dy = panel.row - this.panel.row;
|
|
78
|
+
this.panel = panel;
|
|
79
|
+
this.bodyRect = { ...this.bodyRect, x: this.bodyRect.x + dx, y: this.bodyRect.y + dy };
|
|
80
|
+
this.inputRect = { ...this.inputRect, x: this.inputRect.x + dx, y: this.inputRect.y + dy };
|
|
81
|
+
}
|
|
82
|
+
toggleSource(): void { this.renderSource = !this.renderSource; this.revision++; }
|
|
83
|
+
dispose(): void { if (this.hideTimer) clearTimeout(this.hideTimer); }
|
|
84
|
+
invalidate(): void {
|
|
85
|
+
this.cache.invalidate();
|
|
86
|
+
this.wrappedBody = undefined; this.revision++;
|
|
87
|
+
this.config.input.invalidate();
|
|
88
|
+
this.config.notes.invalidate();
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
revealSelection(): void { this.actionSelection = -1; this.revision++; }
|
|
92
|
+
|
|
93
|
+
scrollActions(direction: -1 | 1): void {
|
|
94
|
+
this.revision++;
|
|
95
|
+
this.actionOffset = Math.max(0, Math.min(this.actionMaxOffset,
|
|
96
|
+
this.actionOffset + direction * Math.max(1, this.actionPageSize - 1)));
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** Panel rect in screen cells, as drawn by the last render. */
|
|
100
|
+
panelRect(): PanelGeometry { return this.panel; }
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* The rect mouse events are measured against. A floating panel lives in a full-screen
|
|
104
|
+
* overlay, so its screen rect is the component rect; a docked panel replaces the editor,
|
|
105
|
+
* so Pi delivers component-local coordinates and the rect starts at the origin.
|
|
106
|
+
*/
|
|
107
|
+
hitRect(): PanelGeometry {
|
|
108
|
+
return isDocked(this.state) ? { col: 0, row: 0, w: this.panel.w, h: this.panel.h } : this.panel;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
actionAt(x: number, y: number): number | undefined {
|
|
112
|
+
const p = this.hitRect();
|
|
113
|
+
return x > p.col && x < p.col + p.w - 1 ? this.actionTargets.get(y - p.row) : undefined;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** Which drag a mouse position starts, or `null` when it hits panel content. */
|
|
117
|
+
dragKindAt(x: number, y: number): PanelDragKind | null {
|
|
118
|
+
const p = this.hitRect();
|
|
119
|
+
if (p.w <= 0 || p.h <= 0) return null;
|
|
120
|
+
const inside = x >= p.col && x < p.col + p.w && y >= p.row && y < p.row + p.h;
|
|
121
|
+
if (!inside) return null;
|
|
122
|
+
const docked = isDocked(this.state);
|
|
123
|
+
if (y === p.row) {
|
|
124
|
+
return docked ? "dock-resize" : "move";
|
|
125
|
+
}
|
|
126
|
+
if (docked) return null;
|
|
127
|
+
const onRight = x === p.col + p.w - 1;
|
|
128
|
+
const onBottom = y === p.row + p.h - 1;
|
|
129
|
+
if (onRight && onBottom) return "resize-both";
|
|
130
|
+
if (onRight) return "resize-w";
|
|
131
|
+
if (onBottom) return "resize-h";
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
hitsPanel(x: number, y: number): boolean {
|
|
136
|
+
const p = this.hitRect();
|
|
137
|
+
return p.w > 0 && p.h > 0 && x >= p.col && x < p.col + p.w && y >= p.row && y < p.row + p.h;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
private markScrolled(): void {
|
|
141
|
+
this.scrolledAt = Date.now();
|
|
142
|
+
if (this.hideTimer) clearTimeout(this.hideTimer);
|
|
143
|
+
this.hideTimer = setTimeout(() => this.config.requestRender(), SCROLLBAR_IDLE_MS + 40);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
private get scrollbarVisible(): boolean {
|
|
147
|
+
return Date.now() - this.scrolledAt < SCROLLBAR_IDLE_MS;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
private editorLines(editor: Editor, width: number, budget: number): string[] {
|
|
151
|
+
this.editorWidth = width;
|
|
152
|
+
editor.focused = this.focused;
|
|
153
|
+
const lines = editor.render(width);
|
|
154
|
+
const cursor = Math.max(0, lines.findIndex(line => line.includes(CURSOR_MARKER)));
|
|
155
|
+
const start = Math.max(0, Math.min(cursor - Math.floor(budget / 2), lines.length - budget));
|
|
156
|
+
return lines.slice(start, start + budget);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
private actions(inner: number, budget: number, chrome: PanelChrome): string[] {
|
|
160
|
+
const rows: { row: Parameters<typeof panelRow>[2]; index: number }[] = [];
|
|
161
|
+
this.customActionRow = -1; this.customActionHeight = 0;
|
|
162
|
+
let selectedRow = 0;
|
|
163
|
+
for (const [index, item] of this.config.items.entries()) {
|
|
164
|
+
const selected = index === this.state.optionIndex;
|
|
165
|
+
if (selected) selectedRow = rows.length;
|
|
166
|
+
if (item.kind === "other" && selected && this.state.inputMode) {
|
|
167
|
+
this.editorWidth = Math.max(1, inner - 9);
|
|
168
|
+
this.config.input.focused = this.focused;
|
|
169
|
+
const lines = this.config.input.render(this.editorWidth).slice(1, -1);
|
|
170
|
+
const cursor = Math.max(0, lines.findIndex(line => line.includes(CURSOR_MARKER)));
|
|
171
|
+
const start = Math.max(0, cursor - 2);
|
|
172
|
+
const shown = lines.slice(start, Math.max(start + 3, cursor + 1));
|
|
173
|
+
while (shown.length < 3) shown.push("");
|
|
174
|
+
if (!this.config.input.getText()) shown[0] = (shown[0] ?? "") + chrome.dim("Type Something");
|
|
175
|
+
shown.forEach((line, i) => rows.push({ index, row: { marker: i === 0 ? "›" : " ", text: (i === 0 ? "○ " : " ") + line, colored: true } }));
|
|
176
|
+
} else rows.push({ index, row: { marker: selected ? "›" : " ", text: "○ " + (item.kind === "other" ? "Type Something" : item.label), selected } });
|
|
177
|
+
}
|
|
178
|
+
this.actionPageSize = budget;
|
|
179
|
+
this.actionMaxOffset = Math.max(0, rows.length - budget);
|
|
180
|
+
if (this.actionSelection !== this.state.optionIndex) {
|
|
181
|
+
this.actionSelection = this.state.optionIndex;
|
|
182
|
+
this.actionOffset = Math.max(0, selectedRow - Math.floor(budget / 2));
|
|
183
|
+
}
|
|
184
|
+
this.actionOffset = Math.min(this.actionOffset, this.actionMaxOffset);
|
|
185
|
+
this.selectionVisible = selectedRow >= this.actionOffset && selectedRow < this.actionOffset + budget;
|
|
186
|
+
const slice = rows.slice(this.actionOffset, this.actionOffset + budget);
|
|
187
|
+
this.visibleActionIndexes = slice.map(entry => entry.index);
|
|
188
|
+
const customIndex = this.config.items.findIndex(item => item.kind === "other");
|
|
189
|
+
this.customActionRow = this.visibleActionIndexes.indexOf(customIndex);
|
|
190
|
+
this.customActionHeight = this.visibleActionIndexes.filter(index => index === customIndex).length;
|
|
191
|
+
return slice.map(entry => {
|
|
192
|
+
const marker = entry.row?.marker ?? " ";
|
|
193
|
+
const text = entry.row?.text ?? "";
|
|
194
|
+
const styled = entry.row?.selected ? chrome.accent(chrome.bold(text)) : entry.row?.colored ? text : chrome.text(text);
|
|
195
|
+
return chrome.line(chrome.border("│") + truncateToWidth(" " + chrome.accent(marker) + " " + styled, inner - 2, "", true) + chrome.border("│"), inner);
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/** Hide the hint while the free-text row owns the keyboard. */
|
|
200
|
+
private get customFocused(): boolean {
|
|
201
|
+
const item = this.config.items[this.state.optionIndex];
|
|
202
|
+
return item !== undefined && item.kind !== "option" && item.kind !== "next";
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
render(width: number): string[] {
|
|
206
|
+
const { colors: c, state: s } = this;
|
|
207
|
+
const size: TerminalSize = { columns: this.config.terminalColumns(), rows: Math.max(1, this.config.terminalRows()) };
|
|
208
|
+
if (isDocked(this.state)) size.columns = width;
|
|
209
|
+
const docked = isDocked(s);
|
|
210
|
+
const chrome = new PanelChrome(this.config.theme, docked ? "dock" : "float", true, this.config.palette);
|
|
211
|
+
this.actionTargets.clear();
|
|
212
|
+
this.bodyRect = this.inputRect = { x: 0, y: 0, width: 0, height: 0 };
|
|
213
|
+
this.config.input.focused = this.config.notes.focused = false;
|
|
214
|
+
this.actionable = false;
|
|
215
|
+
this.selectionVisible = false;
|
|
216
|
+
|
|
217
|
+
// Wrapping must use the width the panel will actually draw: the floating rect is fixed
|
|
218
|
+
// by geometry, while the dock is full width and only its height follows the content.
|
|
219
|
+
const floatRect = floatPanel(s, size);
|
|
220
|
+
const innerWidth = Math.max(1, (docked ? size.columns : floatRect.w) - 7);
|
|
221
|
+
const options = this.config.items.length;
|
|
222
|
+
const savedNotes = s.notesByTab.get(0);
|
|
223
|
+
const savedNoteRows = !s.notesVisible && savedNotes ? wrapTextWithAnsi(c.muted(t("notes.header", "Notes:") + " " + savedNotes), innerWidth).slice(0, 2) : [];
|
|
224
|
+
const noteRows = s.notesVisible ? 2 : savedNoteRows.length;
|
|
225
|
+
const stickyRows = options + 5 + (s.inputMode ? 2 : 0);
|
|
226
|
+
const rawBody = this.renderSource ? (this.wrappedBody?.source ? this.wrappedBody.lines : (this.config.question.preview ?? "").split("\n")) : this.cache.questionBodyFor(innerWidth);
|
|
227
|
+
if (!this.wrappedBody || this.wrappedBody.lines !== rawBody || this.wrappedBody.width !== innerWidth || this.wrappedBody.source !== this.renderSource) {
|
|
228
|
+
this.wrappedBody = { lines: rawBody, width: innerWidth, source: this.renderSource, result: rawBody.flatMap(line => wrapTextWithAnsi(line, innerWidth)) };
|
|
229
|
+
}
|
|
230
|
+
const document = this.wrappedBody.result;
|
|
231
|
+
const naturalHeight = document.length + stickyRows + noteRows + 3;
|
|
232
|
+
const maxHeight = s.panelAutoSize === false ? floatRect.h : Math.max(1, size.rows - 2);
|
|
233
|
+
const height = Math.min(maxHeight, naturalHeight);
|
|
234
|
+
const panel = docked ? dockPanel(s, size, document.length + stickyRows) : { ...floatRect, h: s.panelAutoSize === false ? maxHeight : height, row: s.panelAutoSize === false ? Math.min(floatRect.row, size.rows - height) : Math.max(0, Math.floor((size.rows - height) / 2)) };
|
|
235
|
+
this.panel = panel;
|
|
236
|
+
const inner = Math.max(1, panel.w);
|
|
237
|
+
const available = Math.max(0, bodyHeight(panel.h));
|
|
238
|
+
const title = truncateToWidth(c.bold("📄 " + (this.config.previewLabel ?? "阅读方案,选择下一步")), Math.max(1, inner - 8), "", false);
|
|
239
|
+
|
|
240
|
+
if (s.collapsed && width >= 24) {
|
|
241
|
+
return this.place([panelTop(chrome, inner, title, ""), panelBlank(chrome, inner), panelBottom(chrome, inner)], panel, size);
|
|
242
|
+
}
|
|
243
|
+
if (width < 24 || available < 4) {
|
|
244
|
+
const fallback = wrapTextWithAnsi(c.text("Enlarge terminal · Esc Cancel"), Math.max(1, width - 2))
|
|
245
|
+
.map(line => panelRow(chrome, inner, { text: line, colored: true }));
|
|
246
|
+
return this.place([panelTop(chrome, inner, title, ""), panelBlank(chrome, inner), ...fallback, panelBottom(chrome, inner)], panel, size);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
const actions = this.actions(inner, Math.max(1, Math.min(options + (s.inputMode ? 2 : 0), available - 6)), chrome);
|
|
250
|
+
const previewBudget = Math.max(0, available - actions.length - 5 - noteRows);
|
|
251
|
+
const pageSize = Math.min(previewBudget, Math.max(1, document.length));
|
|
252
|
+
const maxScrollStart = Math.max(0, document.length - pageSize);
|
|
253
|
+
const scrollStart = Math.max(0, Math.min(s.previewScrollOffset ?? 0, maxScrollStart));
|
|
254
|
+
this.viewport = { scrollStart, pageSize, maxScrollStart };
|
|
255
|
+
const showTrack = maxScrollStart > 0 && this.scrollbarVisible;
|
|
256
|
+
const thumbSize = Math.max(1, Math.floor(pageSize * pageSize / Math.max(1, document.length)));
|
|
257
|
+
const thumbStart = maxScrollStart ? Math.round((pageSize - thumbSize) * scrollStart / maxScrollStart) : 0;
|
|
258
|
+
const body = Array.from({ length: pageSize }, (_, i) => {
|
|
259
|
+
const track = maxScrollStart > 0 && showTrack ? (i >= thumbStart && i < thumbStart + thumbSize ? "┃" : "│") : undefined;
|
|
260
|
+
return panelRow(chrome, inner, { text: document[scrollStart + i] ?? "", colored: true, track });
|
|
261
|
+
});
|
|
262
|
+
const editor = s.notesVisible ? this.config.notes : this.config.input;
|
|
263
|
+
const input = s.notesVisible ? this.editorLines(editor, inner - 4, 2)
|
|
264
|
+
.map(line => panelRow(chrome, inner, { text: line, colored: true })) :
|
|
265
|
+
savedNoteRows.map(line => panelRow(chrome, inner, { text: line }));
|
|
266
|
+
// Rectangles are measured in the same space as incoming mouse events.
|
|
267
|
+
const origin = docked ? { col: 0, row: 0 } : { col: panel.col, row: panel.row };
|
|
268
|
+
const bodyTop = origin.row + 2;
|
|
269
|
+
this.bodyRect = { x: origin.col + 1, y: bodyTop, width: panel.w - 2, height: pageSize };
|
|
270
|
+
this.inputRect = { x: this.bodyRect.x, y: bodyTop + pageSize, width: this.bodyRect.width, height: input.length };
|
|
271
|
+
// A dock that cannot show the whole document hands itself to the floating form, so the
|
|
272
|
+
// "does not fit ⇒ card" rule holds even when markdown renders taller than the raw text.
|
|
273
|
+
if (docked && !this.overflowReported && !fitsDock(document.length + stickyRows, size) && s.dockRows === null) {
|
|
274
|
+
this.overflowReported = true;
|
|
275
|
+
this.config.onOverflow?.();
|
|
276
|
+
}
|
|
277
|
+
this.actionable = actions.length > 0 && pageSize > 0;
|
|
278
|
+
const actionTop = 2 + body.length + input.length + 2;
|
|
279
|
+
for (let i = 0; i < actions.length; i++) this.actionTargets.set(actionTop + i, this.visibleActionIndexes[i]!);
|
|
280
|
+
if (s.inputMode && this.customActionRow >= 0) this.inputRect = { x: origin.col + 1, y: origin.row + actionTop + this.customActionRow, width: panel.w - 2, height: this.customActionHeight };
|
|
281
|
+
const lines = [
|
|
282
|
+
panelTop(chrome, inner, title, ""),
|
|
283
|
+
panelBlank(chrome, inner),
|
|
284
|
+
...body,
|
|
285
|
+
...input,
|
|
286
|
+
panelBlank(chrome, inner),
|
|
287
|
+
panelDivider(chrome, inner),
|
|
288
|
+
...actions,
|
|
289
|
+
panelBlank(chrome, inner),
|
|
290
|
+
panelRow(chrome, inner, { text: this.customFocused ? fitHint(["Enter 保存反馈 | Shift+Enter 换行 | Esc 返回", "Enter 保存 | Esc 返回", "Esc"], inner - 7) : fitHint(["↑↓ 选择 | Enter 确认 | Ctrl+PgUp/PgDn 翻阅 | Esc Cancel", "Enter Confirm | Esc Cancel", "Esc Cancel", "Esc"], inner - 7) }),
|
|
291
|
+
panelBlank(chrome, inner),
|
|
292
|
+
panelBottom(chrome, inner),
|
|
293
|
+
];
|
|
294
|
+
return this.place(lines, panel, size);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/** Only paint the card. The host overlay owns its screen position, never a blank canvas. */
|
|
298
|
+
private place(lines: string[], panel: PanelGeometry, _size: TerminalSize): string[] {
|
|
299
|
+
return lines.slice(0, panel.h).map(line => truncateToWidth(line, panel.w, "", true));
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* Markdown palette used by the document body; colours resolve per render so a theme
|
|
305
|
+
* switch repaints without rebuilding the view.
|
|
306
|
+
*/
|