pi-interview 0.8.4 → 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 CHANGED
@@ -930,7 +930,7 @@
930
930
  }
931
931
 
932
932
  function applyQuestionValue(question, value) {
933
- populateForm({ [question.id]: value }, { preserveChoiceNotes: true });
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 populateForm(saved, options = {}) {
3398
+ function populateQuestion(question, saved, options = {}) {
3399
3399
  const { preserveChoiceNotes = false } = options;
3400
- if (!saved) return;
3401
- questions.forEach((question) => {
3402
- const hasSavedValue = Object.prototype.hasOwnProperty.call(saved, question.id);
3403
- const value = saved[question.id];
3404
- if (question.type === "single") {
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
- if (!hasSavedValue) return;
3415
- const choiceValue = getSavedSingleChoiceValue(value);
3416
- if (!choiceValue) return;
3417
- if (choiceValue.option !== "") {
3418
- const input = formEl.querySelector(
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
- checkboxes.forEach((checkbox) => {
3446
- checkbox.checked = false;
3447
- });
3448
- if (!preserveChoiceNotes) {
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 = otherValue;
3434
+ otherInput.value = choiceValue.option;
3477
3435
  otherInput.dispatchEvent(new Event("input", { bubbles: true }));
3478
3436
  }
3479
3437
  }
3480
3438
  }
3481
- if (question.type === "text" && typeof value === "string") {
3482
- const textarea = formEl.querySelector(
3483
- `textarea[data-question-id="${escapeSelector(question.id)}"]`
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
- if (textarea) textarea.value = value;
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/form/styles.css CHANGED
@@ -356,22 +356,17 @@ input[type="checkbox"] {
356
356
 
357
357
  input[type="radio"] {
358
358
  border-radius: 50%;
359
+ background-image: radial-gradient(circle, var(--accent) 0 45%, transparent 55%);
360
+ background-repeat: no-repeat;
361
+ background-position: center;
362
+ background-size: 0 0;
363
+ transition: background-size 120ms ease-out, border-color 120ms ease-out;
359
364
  }
360
365
 
361
366
  input[type="checkbox"] {
362
367
  border-radius: 3px;
363
368
  }
364
369
 
365
- input[type="radio"]::before {
366
- content: "";
367
- width: 8px;
368
- height: 8px;
369
- border-radius: 50%;
370
- transform: scale(0);
371
- background: var(--accent);
372
- transition: transform 120ms ease-out;
373
- }
374
-
375
370
  input[type="checkbox"]::before {
376
371
  content: "";
377
372
  width: 9px;
@@ -382,13 +377,13 @@ input[type="checkbox"]::before {
382
377
  transition: transform 120ms ease-out;
383
378
  }
384
379
 
385
- input[type="radio"]:checked::before,
386
- input[type="checkbox"]:checked::before {
387
- transform: rotate(-45deg) scale(1);
380
+ input[type="radio"]:checked {
381
+ border-color: var(--accent);
382
+ background-size: 8px 8px;
388
383
  }
389
384
 
390
- input[type="radio"]:checked::before {
391
- transform: scale(1);
385
+ input[type="checkbox"]:checked::before {
386
+ transform: rotate(-45deg) scale(1);
392
387
  }
393
388
 
394
389
  input[type="radio"]:focus-visible,
package/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Type } from "@sinclair/typebox";
1
+ import { Type } from "typebox";
2
2
  import { StringEnum, complete, type Api, type AssistantMessage, type Model } from "@mariozechner/pi-ai";
3
3
  import { Text } from "@mariozechner/pi-tui";
4
4
  import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-interview",
3
- "version": "0.8.4",
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"