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 +1 -0
- package/image/confirm-demo.gif +0 -0
- package/image/multiselect-demo.gif +0 -0
- package/image/rating-demo.gif +0 -0
- package/image/select-demo.gif +0 -0
- package/image/text-demo.gif +0 -0
- package/index.ts +11 -3
- package/input.ts +11 -3
- package/modules/text.ts +1 -1
- package/package.json +1 -1
- package/render.ts +2 -1
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
|
|
package/image/confirm-demo.gif
CHANGED
|
Binary file
|
|
Binary file
|
package/image/rating-demo.gif
CHANGED
|
Binary file
|
package/image/select-demo.gif
CHANGED
|
Binary file
|
package/image/text-demo.gif
CHANGED
|
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
|
-
|
|
181
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
package/package.json
CHANGED
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 = " ✓
|
|
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) {
|