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,130 @@
|
|
|
1
|
+
import type { Theme } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import type { MarkdownTheme } from "@earendil-works/pi-tui";
|
|
3
|
+
import { t } from "../../../i18n.js";
|
|
4
|
+
import type { QuestionData } from "../../../tool/types.js";
|
|
5
|
+
import {
|
|
6
|
+
MAX_PREVIEW_HEIGHT_SIDE_BY_SIDE,
|
|
7
|
+
MAX_PREVIEW_HEIGHT_STACKED,
|
|
8
|
+
MarkdownContentCache,
|
|
9
|
+
NOTES_AFFORDANCE_OVERHEAD,
|
|
10
|
+
} from "./markdown-content-cache.js";
|
|
11
|
+
import {
|
|
12
|
+
BORDER_HORIZONTAL_OVERHEAD,
|
|
13
|
+
BORDER_INNER_PADDING_HORIZONTAL,
|
|
14
|
+
BORDER_VERTICAL_OVERHEAD,
|
|
15
|
+
computeBoxDimensions,
|
|
16
|
+
renderBorderedBox,
|
|
17
|
+
} from "./preview-box-renderer.js";
|
|
18
|
+
import type { PreviewLayoutMode } from "./preview-layout-decider.js";
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Affordance text shown below the bordered preview when focused on a preview-bearing option.
|
|
22
|
+
* Re-exported by `preview-pane.ts` for the existing test surface.
|
|
23
|
+
*/
|
|
24
|
+
export const NOTES_AFFORDANCE_TEXT = "Notes: press n to add notes";
|
|
25
|
+
/** Default content-frame label above the question-level inline region (neutral: the CC "Here is Claude's plan:" parity text applies to the plan stage only and is supplied as a stage override). */
|
|
26
|
+
export const PREVIEW_LABEL_TEXT = "Here is Emma's summary:";
|
|
27
|
+
|
|
28
|
+
export interface PreviewBlockRendererConfig {
|
|
29
|
+
question: QuestionData;
|
|
30
|
+
theme: Theme;
|
|
31
|
+
markdownTheme: MarkdownTheme;
|
|
32
|
+
/** Resolved content-frame label for the question-level inline region; defaults to the locale's neutral summary label. */
|
|
33
|
+
previewLabel?: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Renders the bordered markdown preview block for a single question (one block per render call,
|
|
38
|
+
* for the option at `optionIndex`). Owns a per-question `MarkdownContentCache`.
|
|
39
|
+
*
|
|
40
|
+
* NOT a `Component` — pure render-and-measure helper consumed by `PreviewPane`. The layout mode
|
|
41
|
+
* is threaded as an explicit param (never re-derived from column width post-split).
|
|
42
|
+
*
|
|
43
|
+
* The affordance row is always emitted (visually empty when gated) so the preview block's row
|
|
44
|
+
* count is height-stable across affordance-state transitions.
|
|
45
|
+
*/
|
|
46
|
+
export class PreviewBlockRenderer {
|
|
47
|
+
private readonly theme: Theme;
|
|
48
|
+
private readonly previewLabel: string | undefined;
|
|
49
|
+
private readonly cache: MarkdownContentCache;
|
|
50
|
+
|
|
51
|
+
constructor(config: PreviewBlockRendererConfig) {
|
|
52
|
+
this.theme = config.theme;
|
|
53
|
+
this.previewLabel = config.previewLabel;
|
|
54
|
+
this.cache = new MarkdownContentCache(config.question, config.theme, config.markdownTheme);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
hasAnyPreview(): boolean {
|
|
58
|
+
return this.cache.hasAnyPreview();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
has(optionIndex: number): boolean {
|
|
62
|
+
return this.cache.has(optionIndex);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
invalidate(): void {
|
|
66
|
+
this.cache.invalidate();
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Height contribution of the preview block: `BORDER_VERTICAL_OVERHEAD + contentRows +
|
|
71
|
+
* NOTES_AFFORDANCE_OVERHEAD`. Always returns the same value as `renderBlock(...).length`
|
|
72
|
+
* — the affordance overhead is constant, not gated by `focused`/`notesVisible`.
|
|
73
|
+
*/
|
|
74
|
+
blockHeight(width: number, optionIndex: number, mode: PreviewLayoutMode): number {
|
|
75
|
+
const cap = mode === "side-by-side" ? MAX_PREVIEW_HEIGHT_SIDE_BY_SIDE : MAX_PREVIEW_HEIGHT_STACKED;
|
|
76
|
+
const contentBudget = Math.max(1, cap - BORDER_VERTICAL_OVERHEAD - NOTES_AFFORDANCE_OVERHEAD);
|
|
77
|
+
const innerWidth = Math.max(1, width - BORDER_HORIZONTAL_OVERHEAD - 2 * BORDER_INNER_PADDING_HORIZONTAL);
|
|
78
|
+
const rawRows = this.cache.bodyFor(optionIndex, innerWidth).length;
|
|
79
|
+
const contentRows = Math.min(rawRows, contentBudget);
|
|
80
|
+
return BORDER_VERTICAL_OVERHEAD + contentRows + NOTES_AFFORDANCE_OVERHEAD;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* CC plan-dialog style inline region for the question-level preview: fixed label
|
|
85
|
+
* and dashed top/bottom separators with no side borders. The dialog viewport owns
|
|
86
|
+
* vertical clipping so every markdown row remains reachable by scrolling.
|
|
87
|
+
*/
|
|
88
|
+
renderInlineRegion(width: number): string[] {
|
|
89
|
+
const innerWidth = Math.max(1, width);
|
|
90
|
+
const contentLines = this.cache.questionBodyFor(innerWidth);
|
|
91
|
+
if (contentLines.length === 0) return [];
|
|
92
|
+
const colorFn = (s: string) => this.theme.fg("accent", s);
|
|
93
|
+
const label = this.previewLabel ?? t("preview.label", PREVIEW_LABEL_TEXT);
|
|
94
|
+
const separator = colorFn("╌".repeat(innerWidth));
|
|
95
|
+
return [label, separator, ...contentLines, separator];
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Render the full preview block at `width`: bordered box + blank separator + affordance row.
|
|
100
|
+
* `focused` and `notesVisible` together gate the affordance text (visible only when the
|
|
101
|
+
* focused option carries a preview AND notes mode is inactive). The affordance row is ALWAYS
|
|
102
|
+
* emitted (as an empty string when gated) so the row count is invariant.
|
|
103
|
+
*/
|
|
104
|
+
renderBlock(
|
|
105
|
+
width: number,
|
|
106
|
+
optionIndex: number,
|
|
107
|
+
mode: PreviewLayoutMode,
|
|
108
|
+
focused: boolean,
|
|
109
|
+
notesVisible: boolean,
|
|
110
|
+
): string[] {
|
|
111
|
+
const cap = mode === "side-by-side" ? MAX_PREVIEW_HEIGHT_SIDE_BY_SIDE : MAX_PREVIEW_HEIGHT_STACKED;
|
|
112
|
+
const contentBudget = Math.max(1, cap - BORDER_VERTICAL_OVERHEAD - NOTES_AFFORDANCE_OVERHEAD);
|
|
113
|
+
const maxInnerWidth = Math.max(1, width - BORDER_HORIZONTAL_OVERHEAD - 2 * BORDER_INNER_PADDING_HORIZONTAL);
|
|
114
|
+
|
|
115
|
+
const raw = this.cache.bodyFor(optionIndex, maxInnerWidth);
|
|
116
|
+
const truncated = raw.length > contentBudget;
|
|
117
|
+
const hidden = truncated ? raw.length - contentBudget : 0;
|
|
118
|
+
const contentLines = truncated ? raw.slice(0, contentBudget) : raw;
|
|
119
|
+
|
|
120
|
+
const { boxWidth } = computeBoxDimensions(contentLines, maxInnerWidth);
|
|
121
|
+
const colorFn = (s: string) => this.theme.fg("accent", s);
|
|
122
|
+
const boxedLines = renderBorderedBox(contentLines, boxWidth, colorFn, hidden);
|
|
123
|
+
|
|
124
|
+
const showAffordance = focused && !notesVisible && this.cache.has(optionIndex);
|
|
125
|
+
const affordance = showAffordance
|
|
126
|
+
? this.theme.fg("muted", t("preview.notes_affordance", NOTES_AFFORDANCE_TEXT))
|
|
127
|
+
: "";
|
|
128
|
+
return [...boxedLines, "", affordance];
|
|
129
|
+
}
|
|
130
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
|
|
2
|
+
|
|
3
|
+
const ANSI_SGR_RE = /\x1b\[[0-9;]*m/g;
|
|
4
|
+
const ANSI_OSC8_RE = /\x1b\]8;[^\x07\x1b]*(?:\x07|\x1b\\)/g;
|
|
5
|
+
const FENCE_MARKER_RE = /^`{3}/;
|
|
6
|
+
|
|
7
|
+
/** Top + bottom border rows consumed by `renderBorderedBox`. */
|
|
8
|
+
export const BORDER_VERTICAL_OVERHEAD = 2;
|
|
9
|
+
/** Left + right vertical bar columns (`│ ... │`) consumed by `renderBorderedBox`. */
|
|
10
|
+
export const BORDER_HORIZONTAL_OVERHEAD = 2;
|
|
11
|
+
/** Inner horizontal padding (1 col) between each border bar and content area. */
|
|
12
|
+
export const BORDER_INNER_PADDING_HORIZONTAL = 1;
|
|
13
|
+
/** Floor for the preview box's inner content width — CC parity (`PreviewBox.minWidth`). */
|
|
14
|
+
export const BOX_MIN_CONTENT_WIDTH = 40;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Drops fenced-code-block marker lines (` ``` ` opener/closer) from rendered markdown.
|
|
18
|
+
* pi-tui's Markdown emits literal opening ` ```lang ` and closing ` ``` ` lines around
|
|
19
|
+
* code blocks; this strip leaves only the highlighted code body. Inline code
|
|
20
|
+
* (`codespan`) is unaffected — pi-tui already renders it without backticks.
|
|
21
|
+
*/
|
|
22
|
+
export function stripFenceMarkers(lines: readonly string[]): string[] {
|
|
23
|
+
return lines.filter((line) => {
|
|
24
|
+
const clean = line.replace(ANSI_SGR_RE, "").replace(ANSI_OSC8_RE, "");
|
|
25
|
+
return !FENCE_MARKER_RE.test(clean);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Wraps `lines` in a 4-sided ASCII border with 1 col of inner horizontal padding.
|
|
31
|
+
* Layout per content row: `│` + ` ` + content padded to `contentInner` + ` ` + `│`,
|
|
32
|
+
* where `contentInner = width - BORDER_HORIZONTAL_OVERHEAD - 2 * BORDER_INNER_PADDING_HORIZONTAL`.
|
|
33
|
+
* Top/bottom dash runs span corner-to-corner (`width - BORDER_HORIZONTAL_OVERHEAD`). When
|
|
34
|
+
* `hidden > 0`, the bottom-row dash run is replaced with ` ✂ ── N lines hidden ── ` (corners stay).
|
|
35
|
+
*/
|
|
36
|
+
export function renderBorderedBox(
|
|
37
|
+
lines: readonly string[],
|
|
38
|
+
width: number,
|
|
39
|
+
colorFn: (s: string) => string,
|
|
40
|
+
hidden = 0,
|
|
41
|
+
): string[] {
|
|
42
|
+
const dashSpan = Math.max(1, width - BORDER_HORIZONTAL_OVERHEAD);
|
|
43
|
+
const contentInner = Math.max(1, dashSpan - 2 * BORDER_INNER_PADDING_HORIZONTAL);
|
|
44
|
+
const pad = " ".repeat(BORDER_INNER_PADDING_HORIZONTAL);
|
|
45
|
+
const top = colorFn(`┌${"─".repeat(dashSpan)}┐`);
|
|
46
|
+
const out: string[] = [top];
|
|
47
|
+
for (const line of lines) {
|
|
48
|
+
const padded = truncateToWidth(line, contentInner, "", true);
|
|
49
|
+
out.push(`${colorFn("│")}${pad}${padded}${pad}${colorFn("│")}`);
|
|
50
|
+
}
|
|
51
|
+
if (hidden > 0) {
|
|
52
|
+
const indicator = ` ✂ ── ${hidden} lines hidden ── `;
|
|
53
|
+
const space = dashSpan - indicator.length;
|
|
54
|
+
const leftFill = "─".repeat(Math.max(0, Math.floor(space / 2)));
|
|
55
|
+
const rightFill = "─".repeat(Math.max(0, dashSpan - leftFill.length - indicator.length));
|
|
56
|
+
out.push(colorFn(`└${leftFill}${indicator}${rightFill}┘`));
|
|
57
|
+
} else {
|
|
58
|
+
out.push(colorFn(`└${"─".repeat(dashSpan)}┘`));
|
|
59
|
+
}
|
|
60
|
+
return out;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Compute box dimensions from content lines. Pure of args.
|
|
65
|
+
*
|
|
66
|
+
* CC parity:
|
|
67
|
+
* contentWidth = max(minWidth, widestRenderedLine)
|
|
68
|
+
* boxWidth = min(contentWidth + 4, effectiveMaxWidth)
|
|
69
|
+
*
|
|
70
|
+
* Trailing whitespace is stripped before measuring because pi-tui's
|
|
71
|
+
* `Markdown.render(width)` pads every line to `width`, which would otherwise force
|
|
72
|
+
* the box to fill the whole column allocation.
|
|
73
|
+
*/
|
|
74
|
+
export function computeBoxDimensions(
|
|
75
|
+
contentLines: readonly string[],
|
|
76
|
+
maxInnerWidth: number,
|
|
77
|
+
): { innerWidth: number; boxWidth: number } {
|
|
78
|
+
let widest = Math.min(BOX_MIN_CONTENT_WIDTH, maxInnerWidth);
|
|
79
|
+
for (const line of contentLines) {
|
|
80
|
+
const w = visibleWidth(line.replace(/\s+$/, ""));
|
|
81
|
+
if (w > widest) widest = w;
|
|
82
|
+
}
|
|
83
|
+
const innerWidth = Math.min(widest, maxInnerWidth);
|
|
84
|
+
const boxWidth = innerWidth + BORDER_HORIZONTAL_OVERHEAD + 2 * BORDER_INNER_PADDING_HORIZONTAL;
|
|
85
|
+
return { innerWidth, boxWidth };
|
|
86
|
+
}
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import { visibleWidth } from "@earendil-works/pi-tui";
|
|
2
|
+
import type { QuestionData } from "../../../tool/types.js";
|
|
3
|
+
import type { WrappingSelectItem } from "../wrapping-select.js";
|
|
4
|
+
import { BORDER_HORIZONTAL_OVERHEAD, BORDER_INNER_PADDING_HORIZONTAL } from "./preview-box-renderer.js";
|
|
5
|
+
|
|
6
|
+
/** Min terminal/pane width for the side-by-side layout to engage. */
|
|
7
|
+
export const PREVIEW_MIN_WIDTH = 100;
|
|
8
|
+
/** Visual gap between options column and preview column in side-by-side. */
|
|
9
|
+
export const PREVIEW_COLUMN_GAP = 2;
|
|
10
|
+
/** 1 col padding inside the preview column (between gap and `│`). */
|
|
11
|
+
export const PREVIEW_PADDING_LEFT = 1;
|
|
12
|
+
/** Empty rows between options and preview blocks in stacked (narrow) layout. */
|
|
13
|
+
export const STACKED_GAP_ROWS = 1;
|
|
14
|
+
|
|
15
|
+
/** Floor for the adaptive left column width — prevents collapse on short labels. */
|
|
16
|
+
export const MIN_LEFT = 30;
|
|
17
|
+
/** Ceiling ratio: left column never exceeds this fraction of pane width. */
|
|
18
|
+
export const MAX_LEFT_RATIO = 0.5;
|
|
19
|
+
/** Floor for the preview column width — prevents right-side collapse on narrow terminals. */
|
|
20
|
+
export const MIN_PREVIEW_WIDTH = 45;
|
|
21
|
+
/** visibleWidth(" ✔") = 2 (space + ✔ codepoint). Reserved on the longest-label measurement
|
|
22
|
+
* so a confirmed row never gets truncated when MIN_LEFT clamps the column. */
|
|
23
|
+
export const CONFIRMED_OVERHEAD = 2;
|
|
24
|
+
|
|
25
|
+
export type PreviewLayoutMode = "side-by-side" | "stacked";
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Decide layout mode from terminal + pane widths. Pure of inputs.
|
|
29
|
+
*
|
|
30
|
+
* The terminal-width gate is the AND check from the previous `preview-pane.ts` —
|
|
31
|
+
* lifted here so the decision is computed ONCE per render and threaded explicitly
|
|
32
|
+
* through `previewBlockHeight`. Removes the bug class where `previewBlockHeight`
|
|
33
|
+
* re-derived `sideBySide` from a column width (already < pane width post-split),
|
|
34
|
+
* capping height too short.
|
|
35
|
+
*/
|
|
36
|
+
export function decideLayout(terminalWidth: number, paneWidth: number): PreviewLayoutMode {
|
|
37
|
+
return terminalWidth >= PREVIEW_MIN_WIDTH && paneWidth >= PREVIEW_MIN_WIDTH ? "side-by-side" : "stacked";
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Compute the adaptive left column width from option labels.
|
|
42
|
+
* Pure function — deterministic for a given (items, totalForNumbering, paneWidth).
|
|
43
|
+
*
|
|
44
|
+
* Pipeline:
|
|
45
|
+
* 1. Measure: longest visible label width + prefix overhead + confirmed-mark overhead
|
|
46
|
+
* 2. Clamp: floor MIN_LEFT, ceiling paneWidth * MAX_LEFT_RATIO
|
|
47
|
+
* 3. Safety net: never exceed available = paneWidth - GAP - MIN_PREVIEW_WIDTH
|
|
48
|
+
*/
|
|
49
|
+
export function adaptiveLeftWidth(
|
|
50
|
+
items: readonly WrappingSelectItem[],
|
|
51
|
+
totalForNumbering: number,
|
|
52
|
+
paneWidth: number,
|
|
53
|
+
): number {
|
|
54
|
+
const prefixW = String(Math.max(1, totalForNumbering)).length + 4; // digits + "❯ " + ". "
|
|
55
|
+
const confirmedOverhead = CONFIRMED_OVERHEAD; // visibleWidth(" ✔") = 2 (space + ✔ codepoint)
|
|
56
|
+
let maxLabel = 0;
|
|
57
|
+
for (const item of items) {
|
|
58
|
+
const w = visibleWidth(item.label);
|
|
59
|
+
if (w > maxLabel) maxLabel = w;
|
|
60
|
+
}
|
|
61
|
+
const desired = maxLabel + prefixW + confirmedOverhead;
|
|
62
|
+
const ratioCapped = Math.min(desired, Math.floor(paneWidth * MAX_LEFT_RATIO));
|
|
63
|
+
const available = paneWidth - PREVIEW_COLUMN_GAP - MIN_PREVIEW_WIDTH;
|
|
64
|
+
return Math.max(MIN_LEFT, Math.min(ratioCapped, Math.max(1, available)));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Cross-tab maximum left-column width. Aggregates `adaptiveLeftWidth` over every tab
|
|
69
|
+
* and returns the widest result, so the options column stays stable on tab switch.
|
|
70
|
+
*
|
|
71
|
+
* Pure function. Padding uses
|
|
72
|
+
* `items.length` for every tab (the chat row slot that once added +1 on single-select
|
|
73
|
+
* has been removed).
|
|
74
|
+
* Floor is `MIN_LEFT` so an all-empty input still produces a usable column.
|
|
75
|
+
*/
|
|
76
|
+
export function crossTabMaxLeftWidth(
|
|
77
|
+
itemsByTab: ReadonlyArray<readonly WrappingSelectItem[]>,
|
|
78
|
+
paneWidth: number,
|
|
79
|
+
): number {
|
|
80
|
+
let max = MIN_LEFT;
|
|
81
|
+
for (const items of itemsByTab) {
|
|
82
|
+
const totalForNumbering = items.length;
|
|
83
|
+
const tabWidth = adaptiveLeftWidth(items, totalForNumbering, paneWidth);
|
|
84
|
+
if (tabWidth > max) max = tabWidth;
|
|
85
|
+
}
|
|
86
|
+
return max;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Source-line probe: measures the widest source line across all options' previews.
|
|
91
|
+
* Returns 0 when no option carries a preview.
|
|
92
|
+
*
|
|
93
|
+
* V1 heuristic — works well for tree/table/heading/list content where source-line
|
|
94
|
+
* width ≈ rendered width. Paragraphs overstate (source width "wants" the full pane);
|
|
95
|
+
* the worst case is "donation does nothing useful" — fallback to the label-driven path.
|
|
96
|
+
* Upgrade path: replace with a render-width probe that invokes Markdown at a probe width.
|
|
97
|
+
*
|
|
98
|
+
* Pure function — O(total chars) per question; no Markdown invocation, no cache interaction.
|
|
99
|
+
*/
|
|
100
|
+
export function previewSourceWidth(question: QuestionData): number {
|
|
101
|
+
let max = 0;
|
|
102
|
+
for (const option of question.options) {
|
|
103
|
+
const text = option.preview;
|
|
104
|
+
if (!text) continue;
|
|
105
|
+
for (const line of text.split("\n")) {
|
|
106
|
+
const w = visibleWidth(line);
|
|
107
|
+
if (w > max) max = w;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return max;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Cross-tab/cross-option preview budget. Iterates all questions, computes each question's
|
|
115
|
+
* preview appetite via `previewSourceWidth`, adds box + padding overhead (5 cols), and
|
|
116
|
+
* returns the widest result. Floor is `MIN_PREVIEW_WIDTH` so a previewless question still
|
|
117
|
+
* reserves a usable column. Ceiling ensures the left column retains its `MIN_LEFT` floor.
|
|
118
|
+
*
|
|
119
|
+
* Pure function — same cross-tab max pattern as `crossTabMaxLeftWidth`.
|
|
120
|
+
*/
|
|
121
|
+
export function crossTabPreviewBudget(questions: readonly QuestionData[], paneWidth: number): number {
|
|
122
|
+
let max = MIN_PREVIEW_WIDTH;
|
|
123
|
+
for (const question of questions) {
|
|
124
|
+
const rawWidth = previewSourceWidth(question);
|
|
125
|
+
const capped = Math.min(rawWidth, paneWidth - PREVIEW_COLUMN_GAP - MIN_LEFT);
|
|
126
|
+
const budget = capped + BORDER_HORIZONTAL_OVERHEAD + 2 * BORDER_INNER_PADDING_HORIZONTAL + PREVIEW_PADDING_LEFT;
|
|
127
|
+
if (budget > max) max = budget;
|
|
128
|
+
}
|
|
129
|
+
return max;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Cross-tab left-column width with slack donation. Combines the label-driven width
|
|
134
|
+
* (from `crossTabMaxLeftWidth`) with the slack donated by narrow previews.
|
|
135
|
+
*
|
|
136
|
+
* Pipeline:
|
|
137
|
+
* 1. `labelDriven` = `crossTabMaxLeftWidth(itemsByTab, paneWidth)`
|
|
138
|
+
* 2. `previewBudget` = `crossTabPreviewBudget(questions, paneWidth)`
|
|
139
|
+
* 3. `slackDonation` = `paneWidth − GAP − previewBudget`
|
|
140
|
+
* 4. Return `min(max(labelDriven, slackDonation), ceiling)` where `ceiling` is the
|
|
141
|
+
* tighter of the preview-width safety limit and `MAX_LEFT_RATIO`
|
|
142
|
+
*
|
|
143
|
+
* Invariants (hold at side-by-side widths, paneWidth ≥ PREVIEW_MIN_WIDTH — the only
|
|
144
|
+
* mode that consumes this value; narrower panes can pull both ceilings under MIN_LEFT):
|
|
145
|
+
* - Floor: result ≥ MIN_LEFT (ratioCeiling ≥ 50 once paneWidth ≥ 100)
|
|
146
|
+
* - Options cap: left column ≤ paneWidth × MAX_LEFT_RATIO
|
|
147
|
+
* - Preview floor: right column ≥ MIN_PREVIEW_WIDTH — enforced transitively by the
|
|
148
|
+
* MAX_LEFT_RATIO cap (right column keeps ≥ paneWidth/2 − GAP ≥ 48 cols);
|
|
149
|
+
* previewSafetyCeiling is defensive depth that binds only if MAX_LEFT_RATIO
|
|
150
|
+
* ever rises above ~0.53
|
|
151
|
+
* - Cross-tab stability: both reductions are tab-independent
|
|
152
|
+
* - Determinism: pure of (questions, itemsByTab, paneWidth)
|
|
153
|
+
*
|
|
154
|
+
* `crossTabMaxLeftWidth` is NOT replaced — it continues to exist as the primitive.
|
|
155
|
+
* Donation obeys the same `MAX_LEFT_RATIO` cap as the label-driven path; the preview
|
|
156
|
+
* composer right-aligns narrower boxes inside the remaining column.
|
|
157
|
+
*/
|
|
158
|
+
export function crossTabLeftWidthWithDonation(
|
|
159
|
+
itemsByTab: ReadonlyArray<readonly WrappingSelectItem[]>,
|
|
160
|
+
questions: readonly QuestionData[],
|
|
161
|
+
paneWidth: number,
|
|
162
|
+
): number {
|
|
163
|
+
const labelDriven = crossTabMaxLeftWidth(itemsByTab, paneWidth);
|
|
164
|
+
const previewBudget = crossTabPreviewBudget(questions, paneWidth);
|
|
165
|
+
const slackDonation = paneWidth - PREVIEW_COLUMN_GAP - previewBudget;
|
|
166
|
+
// At side-by-side widths the ratio ceiling is always the tighter bound
|
|
167
|
+
// (paneWidth/2 ≤ paneWidth − GAP − MIN_PREVIEW_WIDTH once paneWidth ≥ 94);
|
|
168
|
+
// previewSafetyCeiling stays as defensive depth should MAX_LEFT_RATIO grow.
|
|
169
|
+
const previewSafetyCeiling = paneWidth - PREVIEW_COLUMN_GAP - MIN_PREVIEW_WIDTH;
|
|
170
|
+
const ratioCeiling = Math.floor(paneWidth * MAX_LEFT_RATIO);
|
|
171
|
+
const ceiling = Math.min(previewSafetyCeiling, ratioCeiling);
|
|
172
|
+
return Math.min(Math.max(labelDriven, slackDonation), Math.max(1, ceiling));
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Width allocation for side-by-side mode.
|
|
177
|
+
* `adaptiveLeft` is the pre-computed left column width (from `adaptiveLeftWidth`,
|
|
178
|
+
* cross-tab aggregated). The Math.max(1, ...) calls keep both columns >= 1 col on
|
|
179
|
+
* extreme inputs.
|
|
180
|
+
*/
|
|
181
|
+
export function columnWidths(
|
|
182
|
+
paneWidth: number,
|
|
183
|
+
adaptiveLeft: number,
|
|
184
|
+
): { leftWidth: number; rightWidth: number; gap: number } {
|
|
185
|
+
const gap = PREVIEW_COLUMN_GAP;
|
|
186
|
+
const leftWidth = Math.min(adaptiveLeft, Math.max(1, paneWidth - gap - 1));
|
|
187
|
+
const rightWidth = Math.max(1, paneWidth - leftWidth - gap);
|
|
188
|
+
return { leftWidth, rightWidth, gap };
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Returns the widths actually passed to `options.render` and `previewLines` inside
|
|
193
|
+
* `render()`. Stacked uses the full pane width for both; side-by-side splits via
|
|
194
|
+
* `columnWidths`, with the preview column offset by `PREVIEW_PADDING_LEFT`.
|
|
195
|
+
*/
|
|
196
|
+
export function bodyWidths(
|
|
197
|
+
paneWidth: number,
|
|
198
|
+
mode: PreviewLayoutMode,
|
|
199
|
+
adaptiveLeft: number,
|
|
200
|
+
): { optionsWidth: number; previewWidth: number } {
|
|
201
|
+
if (mode === "stacked") return { optionsWidth: paneWidth, previewWidth: paneWidth };
|
|
202
|
+
const { leftWidth, rightWidth } = columnWidths(paneWidth, adaptiveLeft);
|
|
203
|
+
return { optionsWidth: leftWidth, previewWidth: Math.max(1, rightWidth - PREVIEW_PADDING_LEFT) };
|
|
204
|
+
}
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
import { type Component, truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
|
|
2
|
+
import type { QuestionData } from "../../../tool/types.js";
|
|
3
|
+
import type { StatefulView } from "../../stateful-view.js";
|
|
4
|
+
import type { OptionListView } from "../option-list-view.js";
|
|
5
|
+
import type { PreviewBlockRenderer } from "./preview-block-renderer.js";
|
|
6
|
+
import {
|
|
7
|
+
bodyWidths,
|
|
8
|
+
columnWidths,
|
|
9
|
+
decideLayout,
|
|
10
|
+
PREVIEW_PADDING_LEFT,
|
|
11
|
+
type PreviewLayoutMode,
|
|
12
|
+
STACKED_GAP_ROWS,
|
|
13
|
+
} from "./preview-layout-decider.js";
|
|
14
|
+
|
|
15
|
+
// ----- Re-exports for test imports — keep `./preview-pane.js` as the public surface -----
|
|
16
|
+
export {
|
|
17
|
+
MAX_PREVIEW_HEIGHT_SIDE_BY_SIDE,
|
|
18
|
+
MAX_PREVIEW_HEIGHT_STACKED,
|
|
19
|
+
NO_PREVIEW_TEXT,
|
|
20
|
+
NOTES_AFFORDANCE_OVERHEAD,
|
|
21
|
+
} from "./markdown-content-cache.js";
|
|
22
|
+
export { NOTES_AFFORDANCE_TEXT, PreviewBlockRenderer } from "./preview-block-renderer.js";
|
|
23
|
+
export {
|
|
24
|
+
BORDER_HORIZONTAL_OVERHEAD,
|
|
25
|
+
BORDER_INNER_PADDING_HORIZONTAL,
|
|
26
|
+
BORDER_VERTICAL_OVERHEAD,
|
|
27
|
+
BOX_MIN_CONTENT_WIDTH,
|
|
28
|
+
renderBorderedBox,
|
|
29
|
+
stripFenceMarkers,
|
|
30
|
+
} from "./preview-box-renderer.js";
|
|
31
|
+
export {
|
|
32
|
+
PREVIEW_COLUMN_GAP,
|
|
33
|
+
PREVIEW_MIN_WIDTH,
|
|
34
|
+
PREVIEW_PADDING_LEFT,
|
|
35
|
+
STACKED_GAP_ROWS,
|
|
36
|
+
} from "./preview-layout-decider.js";
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Per-tick projection of PreviewPane state. Replaces the prior
|
|
40
|
+
* `setNotesVisible(boolean)` sliver-setter and the sibling reads of
|
|
41
|
+
* `optionListView.getSelectedIndex()` / `isFocused()`. The pane now reads
|
|
42
|
+
* `selectedIndex` and `focused` from its own props — both derived from
|
|
43
|
+
* canonical state via `selectPreviewPaneProps`. `OptionListView` and
|
|
44
|
+
* `PreviewPane` see the same source of truth without the cross-component
|
|
45
|
+
* live read.
|
|
46
|
+
*/
|
|
47
|
+
export interface PreviewPaneProps {
|
|
48
|
+
notesVisible: boolean;
|
|
49
|
+
selectedIndex: number;
|
|
50
|
+
focused: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* True while the "other" (custom-answer) row is focused and accepting input
|
|
53
|
+
* (`state.inputMode`, set by the reducer via `ROW_INTENT_META.other.activatesInputMode`).
|
|
54
|
+
* Surfaced by `selectPreviewPaneProps` from canonical state; drives the full-width
|
|
55
|
+
* early-returns below so the inline input isn't cramped into the narrow left column.
|
|
56
|
+
*/
|
|
57
|
+
inputMode: boolean;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface PreviewPaneConfig {
|
|
61
|
+
question: QuestionData;
|
|
62
|
+
getTerminalWidth: () => number;
|
|
63
|
+
optionListView: OptionListView;
|
|
64
|
+
previewBlock: PreviewBlockRenderer;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Thin layout composer. Receives `selectedIndex` / `focused` / `notesVisible`
|
|
69
|
+
* via `setProps` per tick (computed by `selectPreviewPaneProps` from canonical
|
|
70
|
+
* state). Delegates option-side rendering to `OptionListView` (which still
|
|
71
|
+
* owns its render-time state — input buffer, confirmedIndex) and preview-side
|
|
72
|
+
* rendering to `PreviewBlockRenderer` (which owns the markdown cache and
|
|
73
|
+
* bordered-box composition).
|
|
74
|
+
*
|
|
75
|
+
* `naturalHeight` and `maxNaturalHeight` query both children's heights; `render`
|
|
76
|
+
* combines them via `decideLayout` (mode threaded into both calls — never
|
|
77
|
+
* re-derived).
|
|
78
|
+
*/
|
|
79
|
+
export class PreviewPane implements StatefulView<PreviewPaneProps>, Component {
|
|
80
|
+
private readonly question: QuestionData;
|
|
81
|
+
private readonly getTerminalWidth: () => number;
|
|
82
|
+
private readonly optionListView: OptionListView;
|
|
83
|
+
private readonly previewBlock: PreviewBlockRenderer;
|
|
84
|
+
private props: PreviewPaneProps;
|
|
85
|
+
/**
|
|
86
|
+
* Cross-tab max left-width getter. Set exactly once by `buildQuestionnaire.injectGlobalLeftWidth`
|
|
87
|
+
* before any render. Initialized to a throwing sentinel so missing injection is a hard fail
|
|
88
|
+
* rather than a silent fallback to a magic constant — render is illegal until injected.
|
|
89
|
+
*/
|
|
90
|
+
private globalLeftWidth: (paneWidth: number) => number = () => {
|
|
91
|
+
throw new Error("PreviewPane.setGlobalLeftWidth must be called before render()");
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
constructor(config: PreviewPaneConfig) {
|
|
95
|
+
this.question = config.question;
|
|
96
|
+
this.getTerminalWidth = config.getTerminalWidth;
|
|
97
|
+
this.optionListView = config.optionListView;
|
|
98
|
+
this.previewBlock = config.previewBlock;
|
|
99
|
+
this.props = { notesVisible: false, selectedIndex: 0, focused: false, inputMode: false };
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
setGlobalLeftWidth(getter: (paneWidth: number) => number): void {
|
|
103
|
+
this.globalLeftWidth = getter;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
private getAdaptiveLeft(paneWidth: number): number {
|
|
107
|
+
return this.globalLeftWidth(paneWidth);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
setProps(props: PreviewPaneProps): void {
|
|
111
|
+
this.props = props;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
handleInput(_data: string): void {}
|
|
115
|
+
|
|
116
|
+
invalidate(): void {
|
|
117
|
+
this.previewBlock.invalidate();
|
|
118
|
+
this.optionListView.invalidate();
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
render(width: number): string[] {
|
|
122
|
+
if (this.question.multiSelect === true) return this.optionListView.render(width);
|
|
123
|
+
// Question-level preview renders inline (CC plan-dialog style): content region above
|
|
124
|
+
// the options, dashed separators, no nested bordered box. Never side-by-side.
|
|
125
|
+
if (this.question.preview && !this.props.inputMode) return this.renderInlinePreview(width);
|
|
126
|
+
// Spec: hide the preview pane entirely when no option carries a `preview`.
|
|
127
|
+
if (!this.previewBlock.hasAnyPreview()) return this.optionListView.render(width);
|
|
128
|
+
// `inputMode` (typing on the "other" custom-answer row): the preview is irrelevant —
|
|
129
|
+
// the row sits at index `options.length`, out of bounds for any option's preview — so
|
|
130
|
+
// render the option list at the full pane width instead of the cramped left column.
|
|
131
|
+
// Side-by-side + preview block resume verbatim on nav-away (inputMode clears).
|
|
132
|
+
if (this.props.inputMode) return this.optionListView.render(width);
|
|
133
|
+
|
|
134
|
+
const mode = decideLayout(this.getTerminalWidth(), width);
|
|
135
|
+
if (mode === "side-by-side") return this.renderSideBySide(width, mode);
|
|
136
|
+
|
|
137
|
+
// Stacked: options + blank gap + preview block.
|
|
138
|
+
return [
|
|
139
|
+
...this.optionListView.render(width),
|
|
140
|
+
...Array(STACKED_GAP_ROWS).fill(""),
|
|
141
|
+
...this.previewBlock.renderBlock(
|
|
142
|
+
width,
|
|
143
|
+
this.props.selectedIndex,
|
|
144
|
+
mode,
|
|
145
|
+
this.props.focused,
|
|
146
|
+
this.props.notesVisible,
|
|
147
|
+
),
|
|
148
|
+
];
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
focusedItemRowRange(width: number): [number, number] {
|
|
152
|
+
if (this.question.multiSelect === true) return this.optionListView.focusedItemRowRange(width);
|
|
153
|
+
if (this.question.preview && !this.props.inputMode) {
|
|
154
|
+
const [start, end] = this.optionListView.focusedItemRowRange(width);
|
|
155
|
+
const offset = this.previewBlock.renderInlineRegion(width).length + 1;
|
|
156
|
+
return [start + offset, end + offset];
|
|
157
|
+
}
|
|
158
|
+
if (!this.previewBlock.hasAnyPreview()) return this.optionListView.focusedItemRowRange(width);
|
|
159
|
+
// `inputMode`: compute the focused row range against the FULL pane width (not the
|
|
160
|
+
// side-by-side leftWidth), mirroring `render`'s full-width option list.
|
|
161
|
+
if (this.props.inputMode) return this.optionListView.focusedItemRowRange(width);
|
|
162
|
+
const mode = decideLayout(this.getTerminalWidth(), width);
|
|
163
|
+
if (mode === "stacked") return this.optionListView.focusedItemRowRange(width);
|
|
164
|
+
const adaptiveLeft = this.getAdaptiveLeft(width);
|
|
165
|
+
const { leftWidth } = columnWidths(width, adaptiveLeft);
|
|
166
|
+
return this.optionListView.focusedItemRowRange(leftWidth);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
naturalHeight(width: number): number {
|
|
170
|
+
if (this.question.multiSelect === true) return this.optionListView.render(width).length;
|
|
171
|
+
if (this.question.preview && !this.props.inputMode)
|
|
172
|
+
return (
|
|
173
|
+
this.previewBlock.renderInlineRegion(width).length + 1 + this.optionListView.render(width).length
|
|
174
|
+
);
|
|
175
|
+
if (!this.previewBlock.hasAnyPreview()) return this.optionListView.render(width).length;
|
|
176
|
+
// `inputMode`: height is the full-width option list only (no preview block) — preserves
|
|
177
|
+
// the `naturalHeight === render.length` parity invariant.
|
|
178
|
+
if (this.props.inputMode) return this.optionListView.render(width).length;
|
|
179
|
+
const mode = decideLayout(this.getTerminalWidth(), width);
|
|
180
|
+
const adaptiveLeft = this.getAdaptiveLeft(width);
|
|
181
|
+
const { optionsWidth, previewWidth } = bodyWidths(width, mode, adaptiveLeft);
|
|
182
|
+
const optionsHeight = this.optionListView.render(optionsWidth).length;
|
|
183
|
+
const previewBlockHeight = this.previewBlock.blockHeight(previewWidth, this.props.selectedIndex, mode);
|
|
184
|
+
if (mode === "side-by-side") return Math.max(optionsHeight, previewBlockHeight);
|
|
185
|
+
return optionsHeight + STACKED_GAP_ROWS + previewBlockHeight;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
maxNaturalHeight(width: number): number {
|
|
189
|
+
if (this.question.multiSelect === true) return this.optionListView.render(width).length;
|
|
190
|
+
if (this.question.preview && !this.props.inputMode)
|
|
191
|
+
return (
|
|
192
|
+
this.previewBlock.renderInlineRegion(width).length + 1 + this.optionListView.render(width).length
|
|
193
|
+
);
|
|
194
|
+
if (!this.previewBlock.hasAnyPreview()) return this.optionListView.render(width).length;
|
|
195
|
+
// `inputMode`: like naturalHeight — full-width option list only, so the
|
|
196
|
+
// `maxNaturalHeight >= naturalHeight` parity invariant holds (both equal the list height).
|
|
197
|
+
if (this.props.inputMode) return this.optionListView.render(width).length;
|
|
198
|
+
const mode = decideLayout(this.getTerminalWidth(), width);
|
|
199
|
+
const adaptiveLeft = this.getAdaptiveLeft(width);
|
|
200
|
+
const { optionsWidth, previewWidth } = bodyWidths(width, mode, adaptiveLeft);
|
|
201
|
+
const optionsHeight = this.optionListView.render(optionsWidth).length;
|
|
202
|
+
let maxPreviewBlock = 0;
|
|
203
|
+
for (let i = 0; i < this.question.options.length; i++) {
|
|
204
|
+
const h = this.previewBlock.blockHeight(previewWidth, i, mode);
|
|
205
|
+
if (h > maxPreviewBlock) maxPreviewBlock = h;
|
|
206
|
+
}
|
|
207
|
+
if (mode === "side-by-side") return Math.max(optionsHeight, maxPreviewBlock);
|
|
208
|
+
return optionsHeight + STACKED_GAP_ROWS + maxPreviewBlock;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
private renderInlinePreview(width: number): string[] {
|
|
212
|
+
return [
|
|
213
|
+
...this.previewBlock.renderInlineRegion(width),
|
|
214
|
+
"",
|
|
215
|
+
...this.optionListView.render(width),
|
|
216
|
+
];
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
private renderSideBySide(width: number, mode: PreviewLayoutMode): string[] {
|
|
220
|
+
const adaptiveLeft = this.getAdaptiveLeft(width);
|
|
221
|
+
const { leftWidth, rightWidth, gap } = columnWidths(width, adaptiveLeft);
|
|
222
|
+
const leftLines = this.optionListView.render(leftWidth);
|
|
223
|
+
const rightLines = this.renderPaddedPreviewLines(rightWidth, mode);
|
|
224
|
+
const rows = Math.max(leftLines.length, rightLines.length);
|
|
225
|
+
const gapStr = " ".repeat(gap);
|
|
226
|
+
const out: string[] = [];
|
|
227
|
+
for (let i = 0; i < rows; i++) {
|
|
228
|
+
const leftRaw = leftLines[i] ?? "";
|
|
229
|
+
const rightRaw = rightLines[i] ?? "";
|
|
230
|
+
const leftClamped = truncateToWidth(leftRaw, leftWidth, "");
|
|
231
|
+
const leftPad = " ".repeat(Math.max(0, leftWidth - visibleWidth(leftClamped)));
|
|
232
|
+
const joined = `${leftClamped}${leftPad}${gapStr}${rightRaw}`;
|
|
233
|
+
out.push(truncateToWidth(joined, width, ""));
|
|
234
|
+
}
|
|
235
|
+
return out;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
private renderPaddedPreviewLines(colWidth: number, mode: PreviewLayoutMode): string[] {
|
|
239
|
+
const inner = Math.max(1, colWidth - PREVIEW_PADDING_LEFT);
|
|
240
|
+
const contentLines = this.previewBlock.renderBlock(
|
|
241
|
+
inner,
|
|
242
|
+
this.props.selectedIndex,
|
|
243
|
+
mode,
|
|
244
|
+
this.props.focused,
|
|
245
|
+
this.props.notesVisible,
|
|
246
|
+
);
|
|
247
|
+
const boxWidth = Math.max(1, visibleWidth(contentLines[0] ?? ""));
|
|
248
|
+
const boxAlignedPad = Math.max(PREVIEW_PADDING_LEFT, colWidth - boxWidth);
|
|
249
|
+
return contentLines.map((line) => {
|
|
250
|
+
if (line === "") return "";
|
|
251
|
+
// A line wider than the box (a long-locale notes affordance) slides left to
|
|
252
|
+
// stay fully visible; truncation engages only when the column itself runs out.
|
|
253
|
+
const pad = Math.max(PREVIEW_PADDING_LEFT, Math.min(boxAlignedPad, colWidth - visibleWidth(line)));
|
|
254
|
+
return `${" ".repeat(pad)}${truncateToWidth(line, colWidth - pad, "")}`;
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
}
|