@airalogy/aimd-recorder 1.16.0 → 1.17.0
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/dist/{AimdDnaSequenceField-CPyMqIVh.js → AimdDnaSequenceField-D6ZgCDpp.js} +1 -1
- package/dist/{AimdEditor.vue_vue_type_style_index_0_lang-lyHIpch9.js → AimdEditor.vue_vue_type_style_index_0_lang-B5Tq4zPV.js} +3 -3
- package/dist/{AimdMarkdownField-CX71bOdX.js → AimdMarkdownField-BJ20QtO8.js} +2 -2
- package/dist/{AimdMarkdownNoteField--ssNIQfG.js → AimdMarkdownNoteField-DwAQhoyk.js} +2 -2
- package/dist/aimd-recorder.css +1 -1
- package/dist/components.js +2150 -2064
- package/dist/composables.js +1 -1
- package/dist/index.js +2 -2
- package/dist/{useFieldRendering-Dh6Kib_0.js → useFieldRendering-xLajJhyA.js} +350 -345
- package/package.json +4 -4
- package/src/__tests__/quiz-recorder.test.ts +47 -0
- package/src/__tests__/recorder-check-field.test.ts +103 -0
- package/src/__tests__/step-field.test.ts +40 -3
- package/src/components/AimdQuizOptionFollowups.vue +121 -0
- package/src/components/AimdQuizRecorder.vue +79 -148
- package/src/components/AimdRecorder.vue +124 -28
- package/src/components/AimdStepCheckField.vue +125 -35
- package/src/composables/__tests__/useRecordState.test.ts +28 -0
- package/src/composables/useRecordState.ts +18 -11
- package/src/locales.ts +2 -2
- package/src/styles/aimd.css +20 -5
|
@@ -380,10 +380,65 @@ export const AimdCheckField = defineComponent({
|
|
|
380
380
|
bodyNodes: { type: Array as PropType<VNodeChild[]>, default: () => [] },
|
|
381
381
|
disabled: { type: Boolean, default: false },
|
|
382
382
|
extraClasses: { type: Array as PropType<string[]>, default: () => [] },
|
|
383
|
+
locale: { type: String, default: "en-US" },
|
|
383
384
|
messages: { type: Object as PropType<AimdRecorderMessages>, required: true },
|
|
384
385
|
},
|
|
385
386
|
emits: ["check-change", "annotation-change", "blur"],
|
|
386
387
|
setup(props, { emit }) {
|
|
388
|
+
const rootEl = ref<HTMLElement | null>(null)
|
|
389
|
+
const annotationExpanded = ref(false)
|
|
390
|
+
let focusOutCheckTimer: ReturnType<typeof setTimeout> | null = null
|
|
391
|
+
|
|
392
|
+
const hasAnnotation = computed(() => Boolean(props.state.annotation?.trim()))
|
|
393
|
+
const showAnnotationEditor = computed(() => hasAnnotation.value || annotationExpanded.value)
|
|
394
|
+
|
|
395
|
+
function clearPendingFocusOutCheck() {
|
|
396
|
+
if (focusOutCheckTimer) {
|
|
397
|
+
clearTimeout(focusOutCheckTimer)
|
|
398
|
+
focusOutCheckTimer = null
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
function collapseTransientDetails() {
|
|
403
|
+
if (!hasAnnotation.value) {
|
|
404
|
+
annotationExpanded.value = false
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
function handleFocusIn() {
|
|
409
|
+
clearPendingFocusOutCheck()
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
function handleFocusOut(event: FocusEvent) {
|
|
413
|
+
const nextTarget = event.relatedTarget
|
|
414
|
+
if (nextTarget instanceof Node && rootEl.value?.contains(nextTarget)) {
|
|
415
|
+
return
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
clearPendingFocusOutCheck()
|
|
419
|
+
focusOutCheckTimer = setTimeout(() => {
|
|
420
|
+
focusOutCheckTimer = null
|
|
421
|
+
const activeElement = typeof document !== "undefined" ? document.activeElement : null
|
|
422
|
+
if (activeElement instanceof Node && rootEl.value?.contains(activeElement)) {
|
|
423
|
+
return
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
collapseTransientDetails()
|
|
427
|
+
}, 0)
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
function openAnnotationDetail() {
|
|
431
|
+
annotationExpanded.value = true
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
function preventToggleFocus(event: MouseEvent) {
|
|
435
|
+
event.preventDefault()
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
onBeforeUnmount(() => {
|
|
439
|
+
clearPendingFocusOutCheck()
|
|
440
|
+
})
|
|
441
|
+
|
|
387
442
|
return () => {
|
|
388
443
|
const node = props.node
|
|
389
444
|
const id = node.id
|
|
@@ -393,31 +448,77 @@ export const AimdCheckField = defineComponent({
|
|
|
393
448
|
const hasBody = props.bodyNodes.length > 0
|
|
394
449
|
const showCheckedMessage = Boolean(state.checked && node.checked_message)
|
|
395
450
|
const fallbackLabel = node.label || id
|
|
451
|
+
const statusClass = state.checked ? "aimd-rec-inline--check-passed" : "aimd-rec-inline--check-open"
|
|
452
|
+
const bodyClass = hasBody ? "aimd-rec-inline--check-with-body" : "aimd-rec-inline--check-bodyless"
|
|
453
|
+
const headerActionChildren = !disabled && !showAnnotationEditor.value
|
|
454
|
+
? [
|
|
455
|
+
h("button", {
|
|
456
|
+
type: "button",
|
|
457
|
+
class: "aimd-step-timer__btn aimd-step-timer__btn--ghost aimd-check-field__toggle-btn",
|
|
458
|
+
onMousedown: preventToggleFocus,
|
|
459
|
+
onClick: openAnnotationDetail,
|
|
460
|
+
}, props.messages.check.annotationPlaceholder),
|
|
461
|
+
]
|
|
462
|
+
: []
|
|
463
|
+
const detailChildren = showAnnotationEditor.value
|
|
464
|
+
? [
|
|
465
|
+
h("span", {
|
|
466
|
+
class: "aimd-check-field__detail aimd-check-field__detail--annotation",
|
|
467
|
+
}, [
|
|
468
|
+
h(AimdMarkdownNoteField, {
|
|
469
|
+
class: "aimd-check-field__annotation-editor",
|
|
470
|
+
disabled,
|
|
471
|
+
locale: props.locale,
|
|
472
|
+
minHeight: 220,
|
|
473
|
+
modelValue: state.annotation || "",
|
|
474
|
+
"onUpdate:modelValue": (value: string) => {
|
|
475
|
+
emit("annotation-change", {
|
|
476
|
+
id,
|
|
477
|
+
value,
|
|
478
|
+
})
|
|
479
|
+
},
|
|
480
|
+
onClose: () => {
|
|
481
|
+
annotationExpanded.value = false
|
|
482
|
+
emit("blur", { id })
|
|
483
|
+
},
|
|
484
|
+
onBlur: () => emit("blur", { id }),
|
|
485
|
+
}),
|
|
486
|
+
]),
|
|
487
|
+
]
|
|
488
|
+
: []
|
|
396
489
|
|
|
397
490
|
return h("div", {
|
|
398
|
-
|
|
491
|
+
ref: rootEl,
|
|
492
|
+
class: ["aimd-rec-inline aimd-rec-inline--check aimd-field aimd-field--check", statusClass, bodyClass, ...extraClasses],
|
|
493
|
+
onFocusin: handleFocusIn,
|
|
494
|
+
onFocusout: handleFocusOut,
|
|
399
495
|
}, [
|
|
400
496
|
h("div", { class: "aimd-check-field__main" }, [
|
|
401
|
-
h("
|
|
402
|
-
h("
|
|
403
|
-
"
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
497
|
+
h("div", { class: "aimd-check-field__header" }, [
|
|
498
|
+
h("label", { class: "aimd-rec-inline__check-wrap aimd-check-field__toggle" }, [
|
|
499
|
+
h("input", {
|
|
500
|
+
"data-rec-focus-key": `check:${id}:checked`,
|
|
501
|
+
type: "checkbox",
|
|
502
|
+
class: "aimd-checkbox",
|
|
503
|
+
disabled,
|
|
504
|
+
checked: Boolean(state.checked),
|
|
505
|
+
onChange: (event: Event) => {
|
|
506
|
+
emit("check-change", {
|
|
507
|
+
id,
|
|
508
|
+
value: (event.target as HTMLInputElement).checked,
|
|
509
|
+
})
|
|
510
|
+
},
|
|
511
|
+
onBlur: () => emit("blur", { id }),
|
|
512
|
+
}),
|
|
513
|
+
h("span", { class: "aimd-field__scope" }, getAimdRecorderScopeLabel("check", props.messages)),
|
|
514
|
+
!hasBody
|
|
515
|
+
? h("span", { class: "aimd-field__name aimd-check-field__key" }, fallbackLabel)
|
|
516
|
+
: null,
|
|
517
|
+
]),
|
|
518
|
+
headerActionChildren.length > 0
|
|
519
|
+
? h("div", { class: "aimd-check-field__actions" }, headerActionChildren)
|
|
520
|
+
: null,
|
|
521
|
+
]),
|
|
421
522
|
hasBody
|
|
422
523
|
? h("div", {
|
|
423
524
|
class: [
|
|
@@ -430,20 +531,9 @@ export const AimdCheckField = defineComponent({
|
|
|
430
531
|
showCheckedMessage
|
|
431
532
|
? h("div", { class: "aimd-check-field__banner" }, node.checked_message)
|
|
432
533
|
: null,
|
|
433
|
-
|
|
434
|
-
"
|
|
435
|
-
|
|
436
|
-
disabled,
|
|
437
|
-
placeholder: props.messages.check.annotationPlaceholder,
|
|
438
|
-
value: state.annotation || "",
|
|
439
|
-
onInput: (event: Event) => {
|
|
440
|
-
emit("annotation-change", {
|
|
441
|
-
id,
|
|
442
|
-
value: (event.target as HTMLInputElement).value,
|
|
443
|
-
})
|
|
444
|
-
},
|
|
445
|
-
onBlur: () => emit("blur", { id }),
|
|
446
|
-
}),
|
|
534
|
+
detailChildren.length > 0
|
|
535
|
+
? h("div", { class: "aimd-check-field__details" }, detailChildren)
|
|
536
|
+
: null,
|
|
447
537
|
])
|
|
448
538
|
}
|
|
449
539
|
},
|
|
@@ -436,6 +436,34 @@ describe('getQuizDefaultValue', () => {
|
|
|
436
436
|
} as any)).toBe(false)
|
|
437
437
|
})
|
|
438
438
|
|
|
439
|
+
it('returns structured defaults for true/false quiz with followups', () => {
|
|
440
|
+
const quiz = {
|
|
441
|
+
id: 'q1',
|
|
442
|
+
type: 'true_false',
|
|
443
|
+
stem: 'Q?',
|
|
444
|
+
options: [
|
|
445
|
+
{
|
|
446
|
+
key: 'true',
|
|
447
|
+
text: 'Yes',
|
|
448
|
+
followups: [
|
|
449
|
+
{ key: 'color', type: 'str', required: true, default: 'white' },
|
|
450
|
+
],
|
|
451
|
+
},
|
|
452
|
+
{ key: 'false', text: 'No' },
|
|
453
|
+
],
|
|
454
|
+
default: true,
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
expect(getQuizDefaultValue(quiz as any)).toEqual({
|
|
458
|
+
selected: true,
|
|
459
|
+
followups: {
|
|
460
|
+
true: {
|
|
461
|
+
color: 'white',
|
|
462
|
+
},
|
|
463
|
+
},
|
|
464
|
+
})
|
|
465
|
+
})
|
|
466
|
+
|
|
439
467
|
it('returns blank map for blank quiz', () => {
|
|
440
468
|
const quiz = {
|
|
441
469
|
id: 'q1', type: 'blank', stem: 'Fill ____',
|
|
@@ -205,27 +205,27 @@ export function normalizeVarTableFields(raw: unknown): AimdVarTableField[] {
|
|
|
205
205
|
// Quiz default values
|
|
206
206
|
// ---------------------------------------------------------------------------
|
|
207
207
|
|
|
208
|
-
type
|
|
208
|
+
type OptionFollowupPrimitive = string | number | boolean
|
|
209
209
|
|
|
210
|
-
function
|
|
211
|
-
return quiz.type === "choice"
|
|
210
|
+
function quizHasOptionFollowups(quiz: AimdQuizField): boolean {
|
|
211
|
+
return (quiz.type === "choice" || quiz.type === "true_false")
|
|
212
212
|
&& Array.isArray(quiz.options)
|
|
213
213
|
&& quiz.options.some(option => Array.isArray(option.followups) && option.followups.length > 0)
|
|
214
214
|
}
|
|
215
215
|
|
|
216
|
-
function
|
|
216
|
+
function buildOptionFollowupDefaultMap(
|
|
217
217
|
quiz: AimdQuizField,
|
|
218
218
|
selectedKeys: string[],
|
|
219
|
-
): Record<string, Record<string,
|
|
219
|
+
): Record<string, Record<string, OptionFollowupPrimitive>> {
|
|
220
220
|
const selectedKeySet = new Set(selectedKeys)
|
|
221
|
-
const followups: Record<string, Record<string,
|
|
221
|
+
const followups: Record<string, Record<string, OptionFollowupPrimitive>> = {}
|
|
222
222
|
|
|
223
223
|
for (const option of quiz.options || []) {
|
|
224
224
|
if (!selectedKeySet.has(option.key) || !Array.isArray(option.followups)) {
|
|
225
225
|
continue
|
|
226
226
|
}
|
|
227
227
|
|
|
228
|
-
const fieldDefaults: Record<string,
|
|
228
|
+
const fieldDefaults: Record<string, OptionFollowupPrimitive> = {}
|
|
229
229
|
for (const followup of option.followups) {
|
|
230
230
|
if (followup.default !== undefined) {
|
|
231
231
|
fieldDefaults[followup.key] = followup.default
|
|
@@ -242,7 +242,7 @@ function buildChoiceFollowupDefaultMap(
|
|
|
242
242
|
export function getQuizDefaultValue(quiz: AimdQuizField): unknown {
|
|
243
243
|
if (quiz.type === "choice") {
|
|
244
244
|
const optionKeys = new Set((quiz.options || []).map(option => option.key))
|
|
245
|
-
const hasFollowups =
|
|
245
|
+
const hasFollowups = quizHasOptionFollowups(quiz)
|
|
246
246
|
if (quiz.mode === "multiple") {
|
|
247
247
|
let selected: string[] = []
|
|
248
248
|
if (Array.isArray(quiz.default)) {
|
|
@@ -251,7 +251,7 @@ export function getQuizDefaultValue(quiz: AimdQuizField): unknown {
|
|
|
251
251
|
if (hasFollowups) {
|
|
252
252
|
return {
|
|
253
253
|
selected,
|
|
254
|
-
followups:
|
|
254
|
+
followups: buildOptionFollowupDefaultMap(quiz, selected),
|
|
255
255
|
}
|
|
256
256
|
}
|
|
257
257
|
return selected
|
|
@@ -264,14 +264,21 @@ export function getQuizDefaultValue(quiz: AimdQuizField): unknown {
|
|
|
264
264
|
if (hasFollowups) {
|
|
265
265
|
return {
|
|
266
266
|
selected,
|
|
267
|
-
followups:
|
|
267
|
+
followups: buildOptionFollowupDefaultMap(quiz, selected ? [selected] : []),
|
|
268
268
|
}
|
|
269
269
|
}
|
|
270
270
|
return selected
|
|
271
271
|
}
|
|
272
272
|
|
|
273
273
|
if (quiz.type === "true_false") {
|
|
274
|
-
|
|
274
|
+
const selected = typeof quiz.default === "boolean" ? quiz.default : null
|
|
275
|
+
if (selected !== null && quizHasOptionFollowups(quiz)) {
|
|
276
|
+
return {
|
|
277
|
+
selected,
|
|
278
|
+
followups: buildOptionFollowupDefaultMap(quiz, [String(selected)]),
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
return selected
|
|
275
282
|
}
|
|
276
283
|
|
|
277
284
|
if (quiz.type === "blank") {
|
package/src/locales.ts
CHANGED
|
@@ -240,7 +240,7 @@ const EN_US_MESSAGES: AimdRecorderMessages = {
|
|
|
240
240
|
resetTimer: "Reset",
|
|
241
241
|
},
|
|
242
242
|
check: {
|
|
243
|
-
annotationPlaceholder: "
|
|
243
|
+
annotationPlaceholder: "Notes",
|
|
244
244
|
},
|
|
245
245
|
table: {
|
|
246
246
|
actionColumn: "Actions",
|
|
@@ -382,7 +382,7 @@ const ZH_CN_MESSAGES: AimdRecorderMessages = {
|
|
|
382
382
|
resetTimer: "重置",
|
|
383
383
|
},
|
|
384
384
|
check: {
|
|
385
|
-
annotationPlaceholder: "
|
|
385
|
+
annotationPlaceholder: "备注",
|
|
386
386
|
},
|
|
387
387
|
table: {
|
|
388
388
|
actionColumn: "操作",
|
package/src/styles/aimd.css
CHANGED
|
@@ -285,8 +285,8 @@
|
|
|
285
285
|
align-items: center;
|
|
286
286
|
gap: 8px;
|
|
287
287
|
padding: 4px 8px;
|
|
288
|
-
background-color: #
|
|
289
|
-
border: 1px solid
|
|
288
|
+
background-color: #fffafa;
|
|
289
|
+
border: 1px solid rgba(185, 28, 28, 0.2);
|
|
290
290
|
border-radius: 4px;
|
|
291
291
|
color: #333;
|
|
292
292
|
cursor: pointer;
|
|
@@ -294,8 +294,19 @@
|
|
|
294
294
|
}
|
|
295
295
|
|
|
296
296
|
.aimd-field--check:hover {
|
|
297
|
-
background-color: #
|
|
298
|
-
border-color:
|
|
297
|
+
background-color: #fff5f5;
|
|
298
|
+
border-color: rgba(185, 28, 28, 0.32);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
.aimd-field--check.aimd-rec-inline--check-passed {
|
|
302
|
+
background-color: #f6fdf9;
|
|
303
|
+
border-color: rgba(22, 101, 52, 0.22);
|
|
304
|
+
color: #1f3d2a;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
.aimd-field--check.aimd-rec-inline--check-passed:hover {
|
|
308
|
+
background-color: #effcf4;
|
|
309
|
+
border-color: rgba(22, 101, 52, 0.34);
|
|
299
310
|
}
|
|
300
311
|
|
|
301
312
|
.aimd-field--check .aimd-checkbox {
|
|
@@ -303,7 +314,11 @@
|
|
|
303
314
|
cursor: pointer;
|
|
304
315
|
width: 16px;
|
|
305
316
|
height: 16px;
|
|
306
|
-
accent-color: #
|
|
317
|
+
accent-color: #dc2626;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
.aimd-field--check.aimd-rec-inline--check-passed .aimd-checkbox {
|
|
321
|
+
accent-color: #16a34a;
|
|
307
322
|
}
|
|
308
323
|
|
|
309
324
|
.aimd-field--check .aimd-field__label,
|