lite-questionnaire 1.0.5 → 1.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/core.ts CHANGED
@@ -183,6 +183,7 @@ export class Core {
183
183
  * 优先检查持久化答案;没有答案时再检查当前 UI 草稿/默认值。
184
184
  */
185
185
  hasAnyValue(q: FlatQuestion, state?: QuestionUIState): boolean {
186
+ if (q.id === "__lq_notes__") return true;
186
187
  const answer = this.answers.get(q.id);
187
188
  if (this.answerHasValue(answer)) return true;
188
189
 
Binary file
Binary file
Binary file
Binary file
Binary file
package/index.ts CHANGED
@@ -14,7 +14,7 @@ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
14
14
  import { Type } from "typebox";
15
15
  import { Editor, type EditorTheme, Text, truncateToWidth } from "@earendil-works/pi-tui";
16
16
  import { Core } from "./core";
17
- import type { Answer, CancelledResult, QuestionnaireParams, QuestionnaireResult } from "./types";
17
+ import type { Answer, CancelledResult, QuestionnaireParams, QuestionnaireResult, Question } from "./types";
18
18
  import {
19
19
  panelTop,
20
20
  panelBottom,
@@ -177,8 +177,16 @@ export default function questionnaire(pi: ExtensionAPI) {
177
177
  }
178
178
 
179
179
  const core = new Core();
180
- core.init(input.questions);
181
- const originalQuestions = input.questions;
180
+ const notesQuestion: Question = {
181
+ id: "__lq_notes__",
182
+ label: "备注",
183
+ prompt: "有什么需要补充说明的吗?",
184
+ type: "text",
185
+ placeholder: "输入备注内容(可选)...",
186
+ };
187
+ const allQuestions = [...input.questions, notesQuestion];
188
+ core.init(allQuestions);
189
+ const originalQuestions = allQuestions;
182
190
  const snapshotKey = questionnaireKey(originalQuestions);
183
191
  const snapshot = loadSnapshot(
184
192
  ctx.sessionManager.getBranch() as Array<{ type: string; customType?: string; data?: unknown }>,
package/input.ts CHANGED
@@ -126,7 +126,7 @@ export function createInputHandler(
126
126
 
127
127
  if (!text) {
128
128
  core.deleteAnswer(q.id);
129
- if (options.allowEmpty) {
129
+ if (options.allowEmpty || q.id === "__lq_notes__") {
130
130
  return true;
131
131
  }
132
132
  core.leaveCurrentQuestion();
@@ -315,7 +315,10 @@ export function createInputHandler(
315
315
  return;
316
316
  }
317
317
  if (matchesKey(data, Key.enter)) {
318
- advance();
318
+ core.inputMode = false;
319
+ core.inputQuestionId = null;
320
+ saveFn();
321
+ onUpdate();
319
322
  return;
320
323
  }
321
324
  return;
@@ -323,7 +326,12 @@ export function createInputHandler(
323
326
 
324
327
  if (q.type === "text") {
325
328
  if (matchesKey(data, Key.enter)) {
326
- advance();
329
+ saveTextDraft(core, editor);
330
+ core.inputMode = false;
331
+ core.inputQuestionId = null;
332
+ editor.setText("");
333
+ saveFn();
334
+ onUpdate();
327
335
  return;
328
336
  }
329
337
  editor.handleInput(data);
package/modules/text.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  * 文本输入问题模块
3
3
  *
4
4
  * 默认显示只读摘要;按 Tab 进入内联编辑。
5
- * 编辑态 Enter 提交并前进,Esc 退出编辑。
5
+ * 编辑态 Enter 保存并返回阅读模式,Esc 退出编辑。
6
6
  */
7
7
 
8
8
  import { truncateToWidth } from "@earendil-works/pi-tui";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lite-questionnaire",
3
- "version": "1.0.5",
3
+ "version": "1.1.1",
4
4
  "description": "轻量级交互式问卷工具 — 单选、多选、文本、确认、评分,带条件子问题和声明式校验",
5
5
  "keywords": [
6
6
  "pi-package",
package/render.ts CHANGED
@@ -108,7 +108,7 @@ export function renderTabBar(
108
108
  // 提交 Tab
109
109
  const isSubmit = core.isSubmitTab();
110
110
  const allDone = core.allAnswered();
111
- let submitText = " ✓ Submit ";
111
+ let submitText = " ✓ 提交 ";
112
112
  if (isSubmit) {
113
113
  submitText = theme.bg("selectedBg", allDone ? theme.fg("success", submitText) : theme.fg("text", submitText));
114
114
  } else if (allDone) {
@@ -190,6 +190,7 @@ export function renderSubmitPage(
190
190
 
191
191
  for (const q of core.questions) {
192
192
  const answer = core.answers.get(q.id);
193
+ if (q.id === "__lq_notes__" && !answer) continue;
193
194
  if (!answer) {
194
195
  lines.push(` ⚠ ${theme.fg("error", q.label)}: ${theme.fg("dim", "(未回答)")}`);
195
196
  } else if ('text' in answer) {