pi-interview 0.8.5 → 0.8.6
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/form/script.js +82 -73
- package/package.json +4 -4
package/form/script.js
CHANGED
|
@@ -930,7 +930,7 @@
|
|
|
930
930
|
}
|
|
931
931
|
|
|
932
932
|
function applyQuestionValue(question, value) {
|
|
933
|
-
|
|
933
|
+
populateQuestion(question, { [question.id]: value }, { preserveChoiceNotes: true });
|
|
934
934
|
if (question.type === "multi") {
|
|
935
935
|
updateDoneState(question.id);
|
|
936
936
|
}
|
|
@@ -3395,76 +3395,34 @@
|
|
|
3395
3395
|
return value.map((item) => normalizeChoiceResponseValue(item)).filter(Boolean);
|
|
3396
3396
|
}
|
|
3397
3397
|
|
|
3398
|
-
function
|
|
3398
|
+
function populateQuestion(question, saved, options = {}) {
|
|
3399
3399
|
const { preserveChoiceNotes = false } = options;
|
|
3400
|
-
|
|
3401
|
-
|
|
3402
|
-
|
|
3403
|
-
|
|
3404
|
-
if (
|
|
3405
|
-
|
|
3406
|
-
|
|
3407
|
-
|
|
3408
|
-
|
|
3409
|
-
|
|
3410
|
-
|
|
3411
|
-
|
|
3412
|
-
|
|
3413
|
-
|
|
3414
|
-
|
|
3415
|
-
|
|
3416
|
-
|
|
3417
|
-
|
|
3418
|
-
|
|
3419
|
-
`input[name="${escapeSelector(question.id)}"][value="${escapeSelector(choiceValue.option)}"]`
|
|
3420
|
-
);
|
|
3421
|
-
if (input) {
|
|
3422
|
-
input.checked = true;
|
|
3423
|
-
if (questionSupportsOptionInsights(question) && choiceValue.note) {
|
|
3424
|
-
setChoiceNote(question.id, choiceValue.option, choiceValue.note);
|
|
3425
|
-
}
|
|
3426
|
-
} else {
|
|
3427
|
-
const otherCheck = formEl.querySelector(
|
|
3428
|
-
`input[name="${escapeSelector(question.id)}"][value="__other__"]`
|
|
3429
|
-
);
|
|
3430
|
-
const otherInput = formEl.querySelector(
|
|
3431
|
-
`.other-input[data-question-id="${escapeSelector(question.id)}"]`
|
|
3432
|
-
);
|
|
3433
|
-
if (otherCheck && otherInput) {
|
|
3434
|
-
otherCheck.checked = true;
|
|
3435
|
-
otherInput.value = choiceValue.option;
|
|
3436
|
-
otherInput.dispatchEvent(new Event("input", { bubbles: true }));
|
|
3437
|
-
}
|
|
3438
|
-
}
|
|
3439
|
-
}
|
|
3440
|
-
}
|
|
3441
|
-
if (question.type === "multi") {
|
|
3442
|
-
const checkboxes = formEl.querySelectorAll(
|
|
3443
|
-
`input[name="${escapeSelector(question.id)}"]`
|
|
3400
|
+
const hasSavedValue = saved && Object.prototype.hasOwnProperty.call(saved, question.id);
|
|
3401
|
+
const value = hasSavedValue ? saved[question.id] : undefined;
|
|
3402
|
+
|
|
3403
|
+
if (question.type === "single") {
|
|
3404
|
+
if (!hasSavedValue) return;
|
|
3405
|
+
const radios = formEl.querySelectorAll(
|
|
3406
|
+
`input[name="${escapeSelector(question.id)}"]`
|
|
3407
|
+
);
|
|
3408
|
+
radios.forEach((radio) => {
|
|
3409
|
+
radio.checked = false;
|
|
3410
|
+
});
|
|
3411
|
+
if (!preserveChoiceNotes) {
|
|
3412
|
+
clearChoiceNotes(question.id);
|
|
3413
|
+
}
|
|
3414
|
+
const choiceValue = getSavedSingleChoiceValue(value);
|
|
3415
|
+
if (!choiceValue) return;
|
|
3416
|
+
if (choiceValue.option !== "") {
|
|
3417
|
+
const input = formEl.querySelector(
|
|
3418
|
+
`input[name="${escapeSelector(question.id)}"][value="${escapeSelector(choiceValue.option)}"]`
|
|
3444
3419
|
);
|
|
3445
|
-
|
|
3446
|
-
|
|
3447
|
-
|
|
3448
|
-
|
|
3449
|
-
clearChoiceNotes(question.id);
|
|
3450
|
-
}
|
|
3451
|
-
if (!hasSavedValue) return;
|
|
3452
|
-
const choiceValues = getSavedMultiChoiceValues(value);
|
|
3453
|
-
let otherValue = "";
|
|
3454
|
-
choiceValues.forEach((choiceValue) => {
|
|
3455
|
-
const input = formEl.querySelector(
|
|
3456
|
-
`input[name="${escapeSelector(question.id)}"][value="${escapeSelector(choiceValue.option)}"]`
|
|
3457
|
-
);
|
|
3458
|
-
if (input) {
|
|
3459
|
-
input.checked = true;
|
|
3460
|
-
if (questionSupportsOptionInsights(question) && choiceValue.note) {
|
|
3461
|
-
setChoiceNote(question.id, choiceValue.option, choiceValue.note);
|
|
3462
|
-
}
|
|
3463
|
-
} else if (choiceValue.option) {
|
|
3464
|
-
otherValue = choiceValue.option;
|
|
3420
|
+
if (input) {
|
|
3421
|
+
input.checked = true;
|
|
3422
|
+
if (questionSupportsOptionInsights(question) && choiceValue.note) {
|
|
3423
|
+
setChoiceNote(question.id, choiceValue.option, choiceValue.note);
|
|
3465
3424
|
}
|
|
3466
|
-
}
|
|
3467
|
-
if (otherValue) {
|
|
3425
|
+
} else {
|
|
3468
3426
|
const otherCheck = formEl.querySelector(
|
|
3469
3427
|
`input[name="${escapeSelector(question.id)}"][value="__other__"]`
|
|
3470
3428
|
);
|
|
@@ -3473,17 +3431,68 @@
|
|
|
3473
3431
|
);
|
|
3474
3432
|
if (otherCheck && otherInput) {
|
|
3475
3433
|
otherCheck.checked = true;
|
|
3476
|
-
otherInput.value =
|
|
3434
|
+
otherInput.value = choiceValue.option;
|
|
3477
3435
|
otherInput.dispatchEvent(new Event("input", { bubbles: true }));
|
|
3478
3436
|
}
|
|
3479
3437
|
}
|
|
3480
3438
|
}
|
|
3481
|
-
|
|
3482
|
-
|
|
3483
|
-
|
|
3439
|
+
return;
|
|
3440
|
+
}
|
|
3441
|
+
|
|
3442
|
+
if (question.type === "multi") {
|
|
3443
|
+
if (!hasSavedValue) return;
|
|
3444
|
+
const checkboxes = formEl.querySelectorAll(
|
|
3445
|
+
`input[name="${escapeSelector(question.id)}"]`
|
|
3446
|
+
);
|
|
3447
|
+
checkboxes.forEach((checkbox) => {
|
|
3448
|
+
checkbox.checked = false;
|
|
3449
|
+
});
|
|
3450
|
+
if (!preserveChoiceNotes) {
|
|
3451
|
+
clearChoiceNotes(question.id);
|
|
3452
|
+
}
|
|
3453
|
+
const choiceValues = getSavedMultiChoiceValues(value);
|
|
3454
|
+
let otherValue = "";
|
|
3455
|
+
choiceValues.forEach((choiceValue) => {
|
|
3456
|
+
const input = formEl.querySelector(
|
|
3457
|
+
`input[name="${escapeSelector(question.id)}"][value="${escapeSelector(choiceValue.option)}"]`
|
|
3458
|
+
);
|
|
3459
|
+
if (input) {
|
|
3460
|
+
input.checked = true;
|
|
3461
|
+
if (questionSupportsOptionInsights(question) && choiceValue.note) {
|
|
3462
|
+
setChoiceNote(question.id, choiceValue.option, choiceValue.note);
|
|
3463
|
+
}
|
|
3464
|
+
} else if (choiceValue.option) {
|
|
3465
|
+
otherValue = choiceValue.option;
|
|
3466
|
+
}
|
|
3467
|
+
});
|
|
3468
|
+
if (otherValue) {
|
|
3469
|
+
const otherCheck = formEl.querySelector(
|
|
3470
|
+
`input[name="${escapeSelector(question.id)}"][value="__other__"]`
|
|
3484
3471
|
);
|
|
3485
|
-
|
|
3472
|
+
const otherInput = formEl.querySelector(
|
|
3473
|
+
`.other-input[data-question-id="${escapeSelector(question.id)}"]`
|
|
3474
|
+
);
|
|
3475
|
+
if (otherCheck && otherInput) {
|
|
3476
|
+
otherCheck.checked = true;
|
|
3477
|
+
otherInput.value = otherValue;
|
|
3478
|
+
otherInput.dispatchEvent(new Event("input", { bubbles: true }));
|
|
3479
|
+
}
|
|
3486
3480
|
}
|
|
3481
|
+
return;
|
|
3482
|
+
}
|
|
3483
|
+
|
|
3484
|
+
if (question.type === "text" && hasSavedValue && typeof value === "string") {
|
|
3485
|
+
const textarea = formEl.querySelector(
|
|
3486
|
+
`textarea[data-question-id="${escapeSelector(question.id)}"]`
|
|
3487
|
+
);
|
|
3488
|
+
if (textarea) textarea.value = value;
|
|
3489
|
+
}
|
|
3490
|
+
}
|
|
3491
|
+
|
|
3492
|
+
function populateForm(saved, options = {}) {
|
|
3493
|
+
if (!saved) return;
|
|
3494
|
+
questions.forEach((question) => {
|
|
3495
|
+
populateQuestion(question, saved, options);
|
|
3487
3496
|
});
|
|
3488
3497
|
}
|
|
3489
3498
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-interview",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.6",
|
|
4
4
|
"description": "Interactive interview form extension for pi coding agent",
|
|
5
5
|
"author": "Nico Bailon",
|
|
6
6
|
"license": "MIT",
|
|
@@ -32,6 +32,9 @@
|
|
|
32
32
|
"scripts": {
|
|
33
33
|
"test": "vitest run"
|
|
34
34
|
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"typebox": "^1.1.24"
|
|
37
|
+
},
|
|
35
38
|
"pi": {
|
|
36
39
|
"extensions": [
|
|
37
40
|
"./index.ts"
|
|
@@ -39,8 +42,5 @@
|
|
|
39
42
|
},
|
|
40
43
|
"devDependencies": {
|
|
41
44
|
"vitest": "^4.0.18"
|
|
42
|
-
},
|
|
43
|
-
"dependencies": {
|
|
44
|
-
"typebox": "^1.1.31"
|
|
45
45
|
}
|
|
46
46
|
}
|