@airalogy/aimd-recorder 1.14.1 → 1.16.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/LICENSE +201 -0
- package/README.md +9 -1
- package/README.zh-CN.md +9 -1
- package/dist/{AimdDnaSequenceField-__jdnFS9.js → AimdDnaSequenceField-CPyMqIVh.js} +1 -1
- package/dist/{AimdEditor.vue_vue_type_style_index_0_lang-Bq79rKNw.js → AimdEditor.vue_vue_type_style_index_0_lang-lyHIpch9.js} +6344 -6073
- package/dist/{AimdMarkdownField-98ImHGbc.js → AimdMarkdownField-CX71bOdX.js} +4 -3
- package/dist/{AimdMarkdownNoteField-CuUJZkgT.js → AimdMarkdownNoteField--ssNIQfG.js} +11 -10
- package/dist/aimd-recorder.css +1 -1
- package/dist/components.js +2128 -1891
- package/dist/composables.js +1 -1
- package/dist/index.js +2 -2
- package/dist/{useFieldRendering-BIqeE3qo.js → useFieldRendering-Dh6Kib_0.js} +1303 -1207
- package/package.json +13 -13
- package/src/__tests__/client-assigner.test.ts +59 -0
- package/src/__tests__/quiz-recorder.test.ts +112 -0
- package/src/__tests__/recorder-quiz-followups.test.ts +97 -0
- package/src/__tests__/step-field.test.ts +47 -3
- package/src/__tests__/var-field-render.test.ts +7 -1
- package/src/client-assigner.ts +47 -3
- package/src/components/AimdQuizRecorder.vue +404 -45
- package/src/components/AimdRecorder.vue +14 -1
- package/src/components/AimdRecorderEditor.vue +3 -2
- package/src/components/AimdVarField.vue +43 -5
- package/src/composables/__tests__/useRecordState.test.ts +41 -0
- package/src/composables/__tests__/useVarHelpers.test.ts +44 -0
- package/src/composables/useClientAssignerRunner.ts +7 -1
- package/src/composables/useRecordState.ts +57 -4
- package/src/composables/useVarHelpers.ts +113 -0
- package/src/composables/workbenchFieldEditing.ts +8 -5
- package/src/locales.ts +3 -0
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
} from "@airalogy/aimd-core"
|
|
7
7
|
import {
|
|
8
8
|
type AimdQuizField,
|
|
9
|
+
type AimdQuizFollowupField,
|
|
9
10
|
type AimdQuizGradeResult,
|
|
10
11
|
} from "@airalogy/aimd-core/types"
|
|
11
12
|
import type { AimdRecorderMessagesInput } from "../locales"
|
|
@@ -27,6 +28,8 @@ interface StemBlankSegment {
|
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
type StemSegment = StemTextSegment | StemBlankSegment
|
|
31
|
+
type ChoiceFollowupPrimitive = string | number | boolean
|
|
32
|
+
type ChoiceFollowupAnswerMap = Record<string, Record<string, ChoiceFollowupPrimitive>>
|
|
30
33
|
|
|
31
34
|
const props = withDefaults(defineProps<{
|
|
32
35
|
quiz: AimdQuizField
|
|
@@ -92,20 +95,134 @@ const stemSegments = computed<StemSegment[]>(() => {
|
|
|
92
95
|
: [{ type: "text", value: stem }]
|
|
93
96
|
})
|
|
94
97
|
|
|
98
|
+
const hasChoiceFollowups = computed(() => (
|
|
99
|
+
props.quiz.type === "choice"
|
|
100
|
+
&& Array.isArray(props.quiz.options)
|
|
101
|
+
&& props.quiz.options.some(option => Array.isArray(option.followups) && option.followups.length > 0)
|
|
102
|
+
))
|
|
103
|
+
|
|
104
|
+
function asObjectRecord(value: unknown): Record<string, unknown> | null {
|
|
105
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
106
|
+
return null
|
|
107
|
+
}
|
|
108
|
+
return value as Record<string, unknown>
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function getChoiceSelectedValue(): unknown {
|
|
112
|
+
if (!hasChoiceFollowups.value) {
|
|
113
|
+
return props.modelValue
|
|
114
|
+
}
|
|
115
|
+
const recordValue = asObjectRecord(props.modelValue)
|
|
116
|
+
if (recordValue && "selected" in recordValue) {
|
|
117
|
+
return recordValue.selected
|
|
118
|
+
}
|
|
119
|
+
return props.modelValue
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function getSelectedChoiceKeys(value: unknown): string[] {
|
|
123
|
+
if (typeof value === "string") {
|
|
124
|
+
return value ? [value] : []
|
|
125
|
+
}
|
|
126
|
+
if (Array.isArray(value)) {
|
|
127
|
+
return value.filter((item): item is string => typeof item === "string" && item.length > 0)
|
|
128
|
+
}
|
|
129
|
+
return []
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function asChoiceFollowupAnswerMap(value: unknown): ChoiceFollowupAnswerMap {
|
|
133
|
+
const source = asObjectRecord(value)
|
|
134
|
+
if (!source) {
|
|
135
|
+
return {}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const normalized: ChoiceFollowupAnswerMap = {}
|
|
139
|
+
for (const [optionKey, rawFields] of Object.entries(source)) {
|
|
140
|
+
const fieldSource = asObjectRecord(rawFields)
|
|
141
|
+
if (!fieldSource) {
|
|
142
|
+
continue
|
|
143
|
+
}
|
|
144
|
+
const fields: Record<string, ChoiceFollowupPrimitive> = {}
|
|
145
|
+
for (const [fieldKey, fieldValue] of Object.entries(fieldSource)) {
|
|
146
|
+
if (
|
|
147
|
+
typeof fieldValue === "string"
|
|
148
|
+
|| typeof fieldValue === "number"
|
|
149
|
+
|| typeof fieldValue === "boolean"
|
|
150
|
+
) {
|
|
151
|
+
fields[fieldKey] = fieldValue
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
if (Object.keys(fields).length > 0) {
|
|
155
|
+
normalized[optionKey] = fields
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return normalized
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function getChoiceFollowupsMap(): ChoiceFollowupAnswerMap {
|
|
162
|
+
if (!hasChoiceFollowups.value) {
|
|
163
|
+
return {}
|
|
164
|
+
}
|
|
165
|
+
return asChoiceFollowupAnswerMap(asObjectRecord(props.modelValue)?.followups)
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function getChoiceOptionFollowupDefaults(optionKey: string): Record<string, ChoiceFollowupPrimitive> {
|
|
169
|
+
const option = props.quiz.options?.find(item => item.key === optionKey)
|
|
170
|
+
const defaults: Record<string, ChoiceFollowupPrimitive> = {}
|
|
171
|
+
for (const followup of option?.followups || []) {
|
|
172
|
+
if (followup.default !== undefined) {
|
|
173
|
+
defaults[followup.key] = followup.default
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return defaults
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function buildStructuredChoiceAnswer(
|
|
180
|
+
selected: unknown,
|
|
181
|
+
followups: ChoiceFollowupAnswerMap = getChoiceFollowupsMap(),
|
|
182
|
+
): Record<string, unknown> {
|
|
183
|
+
const selectedKeys = getSelectedChoiceKeys(selected)
|
|
184
|
+
const nextFollowups: ChoiceFollowupAnswerMap = {}
|
|
185
|
+
|
|
186
|
+
for (const selectedKey of selectedKeys) {
|
|
187
|
+
const values = {
|
|
188
|
+
...getChoiceOptionFollowupDefaults(selectedKey),
|
|
189
|
+
...(followups[selectedKey] || {}),
|
|
190
|
+
}
|
|
191
|
+
if (Object.keys(values).length > 0) {
|
|
192
|
+
nextFollowups[selectedKey] = values
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
return {
|
|
197
|
+
selected,
|
|
198
|
+
followups: nextFollowups,
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function emitChoiceSelectedValue(value: string | string[]): void {
|
|
203
|
+
if (hasChoiceFollowups.value) {
|
|
204
|
+
emit("update:modelValue", buildStructuredChoiceAnswer(value))
|
|
205
|
+
return
|
|
206
|
+
}
|
|
207
|
+
emit("update:modelValue", value)
|
|
208
|
+
}
|
|
209
|
+
|
|
95
210
|
const singleChoiceValue = computed<string>({
|
|
96
211
|
get() {
|
|
97
|
-
|
|
212
|
+
const selected = getChoiceSelectedValue()
|
|
213
|
+
return typeof selected === "string" ? selected : ""
|
|
98
214
|
},
|
|
99
215
|
set(value) {
|
|
100
|
-
|
|
216
|
+
emitChoiceSelectedValue(value)
|
|
101
217
|
},
|
|
102
218
|
})
|
|
103
219
|
|
|
104
220
|
const multipleChoiceValue = computed<string[]>(() => {
|
|
105
|
-
|
|
221
|
+
const selected = getChoiceSelectedValue()
|
|
222
|
+
if (!Array.isArray(selected)) {
|
|
106
223
|
return []
|
|
107
224
|
}
|
|
108
|
-
return
|
|
225
|
+
return selected.filter((item): item is string => typeof item === "string")
|
|
109
226
|
})
|
|
110
227
|
|
|
111
228
|
const selectedChoiceKeys = computed<string[]>(() => {
|
|
@@ -120,6 +237,35 @@ const selectedChoiceKeys = computed<string[]>(() => {
|
|
|
120
237
|
return multipleChoiceValue.value
|
|
121
238
|
})
|
|
122
239
|
|
|
240
|
+
const trueFalseValue = computed<boolean | null>({
|
|
241
|
+
get() {
|
|
242
|
+
return typeof props.modelValue === "boolean" ? props.modelValue : null
|
|
243
|
+
},
|
|
244
|
+
set(value) {
|
|
245
|
+
emit("update:modelValue", value)
|
|
246
|
+
},
|
|
247
|
+
})
|
|
248
|
+
|
|
249
|
+
const resolvedTrueFalseOptions = computed<NonNullable<AimdQuizField["options"]>>(() => {
|
|
250
|
+
if (props.quiz.type !== "true_false") {
|
|
251
|
+
return []
|
|
252
|
+
}
|
|
253
|
+
const options: NonNullable<AimdQuizField["options"]> = Array.isArray(props.quiz.options) && props.quiz.options.length > 0
|
|
254
|
+
? props.quiz.options
|
|
255
|
+
: [
|
|
256
|
+
{ key: "true", text: "True" },
|
|
257
|
+
{ key: "false", text: "False" },
|
|
258
|
+
]
|
|
259
|
+
return options.filter(option => option.key === "true" || option.key === "false")
|
|
260
|
+
})
|
|
261
|
+
|
|
262
|
+
const selectedQuizOptionKeys = computed<string[]>(() => {
|
|
263
|
+
if (props.quiz.type === "true_false") {
|
|
264
|
+
return typeof props.modelValue === "boolean" ? [String(props.modelValue)] : []
|
|
265
|
+
}
|
|
266
|
+
return selectedChoiceKeys.value
|
|
267
|
+
})
|
|
268
|
+
|
|
123
269
|
function isMultipleChecked(key: string): boolean {
|
|
124
270
|
return multipleChoiceValue.value.includes(key)
|
|
125
271
|
}
|
|
@@ -129,7 +275,86 @@ function toggleMultipleChoice(key: string, checked: boolean): void {
|
|
|
129
275
|
const next = checked
|
|
130
276
|
? [...new Set([...current, key])]
|
|
131
277
|
: current.filter(item => item !== key)
|
|
132
|
-
|
|
278
|
+
emitChoiceSelectedValue(next)
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
function shouldShowChoiceFollowups(option: NonNullable<AimdQuizField["options"]>[number]): boolean {
|
|
282
|
+
return Array.isArray(option.followups)
|
|
283
|
+
&& option.followups.length > 0
|
|
284
|
+
&& selectedChoiceKeys.value.includes(option.key)
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
function getFollowupLabel(followup: AimdQuizFollowupField): string {
|
|
288
|
+
return followup.title || followup.key
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
function getFollowupTextValue(optionKey: string, followup: AimdQuizFollowupField): string {
|
|
292
|
+
const value = getChoiceFollowupsMap()[optionKey]?.[followup.key]
|
|
293
|
+
if (typeof value === "string" || typeof value === "number") {
|
|
294
|
+
return String(value)
|
|
295
|
+
}
|
|
296
|
+
return ""
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
function getFollowupBooleanValue(optionKey: string, followup: AimdQuizFollowupField): boolean {
|
|
300
|
+
return getChoiceFollowupsMap()[optionKey]?.[followup.key] === true
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
function normalizeFollowupInputValue(
|
|
304
|
+
followup: AimdQuizFollowupField,
|
|
305
|
+
value: string | boolean,
|
|
306
|
+
): ChoiceFollowupPrimitive | undefined {
|
|
307
|
+
if (followup.type === "bool") {
|
|
308
|
+
return Boolean(value)
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
if (typeof value !== "string") {
|
|
312
|
+
return undefined
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
if (followup.type === "str") {
|
|
316
|
+
return value
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
if (!value.trim()) {
|
|
320
|
+
return undefined
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
const parsed = Number(value)
|
|
324
|
+
if (!Number.isFinite(parsed)) {
|
|
325
|
+
return undefined
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
if (followup.type === "int") {
|
|
329
|
+
return Number.isInteger(parsed) ? parsed : undefined
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
return parsed
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
function setChoiceFollowupValue(
|
|
336
|
+
optionKey: string,
|
|
337
|
+
followup: AimdQuizFollowupField,
|
|
338
|
+
value: string | boolean,
|
|
339
|
+
): void {
|
|
340
|
+
const nextFollowups = getChoiceFollowupsMap()
|
|
341
|
+
const optionFollowups = { ...(nextFollowups[optionKey] || {}) }
|
|
342
|
+
const normalizedValue = normalizeFollowupInputValue(followup, value)
|
|
343
|
+
if (normalizedValue === undefined) {
|
|
344
|
+
delete optionFollowups[followup.key]
|
|
345
|
+
}
|
|
346
|
+
else {
|
|
347
|
+
optionFollowups[followup.key] = normalizedValue
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
if (Object.keys(optionFollowups).length > 0) {
|
|
351
|
+
nextFollowups[optionKey] = optionFollowups
|
|
352
|
+
}
|
|
353
|
+
else {
|
|
354
|
+
delete nextFollowups[optionKey]
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
emit("update:modelValue", buildStructuredChoiceAnswer(getChoiceSelectedValue(), nextFollowups))
|
|
133
358
|
}
|
|
134
359
|
|
|
135
360
|
function asBlankValueMap(value: unknown): Record<string, string> {
|
|
@@ -304,7 +529,7 @@ function shouldShowChoiceOptionExplanation(optionKey: string, explanation?: stri
|
|
|
304
529
|
return false
|
|
305
530
|
}
|
|
306
531
|
|
|
307
|
-
if (!
|
|
532
|
+
if (!selectedQuizOptionKeys.value.includes(optionKey)) {
|
|
308
533
|
return false
|
|
309
534
|
}
|
|
310
535
|
|
|
@@ -360,49 +585,136 @@ function shouldShowChoiceOptionExplanation(optionKey: string, explanation?: stri
|
|
|
360
585
|
{{ quiz.description }}
|
|
361
586
|
</div>
|
|
362
587
|
|
|
588
|
+
<div v-if="quiz.type === 'true_false' && resolvedTrueFalseOptions.length" class="aimd-quiz-recorder__options">
|
|
589
|
+
<div v-for="option in resolvedTrueFalseOptions" :key="`${quiz.id}-true-false-${option.key}`" class="aimd-quiz-recorder__option-frame">
|
|
590
|
+
<label class="aimd-quiz-recorder__option">
|
|
591
|
+
<input
|
|
592
|
+
v-model="trueFalseValue"
|
|
593
|
+
type="radio"
|
|
594
|
+
class="aimd-quiz-recorder__choice-input"
|
|
595
|
+
:data-rec-focus-key="`${focusKeyPrefix || `quiz:${quiz.id}`}:true_false:${option.key}`"
|
|
596
|
+
:name="`${quiz.id}-true-false`"
|
|
597
|
+
:value="option.key === 'true'"
|
|
598
|
+
:disabled="readonly"
|
|
599
|
+
/>
|
|
600
|
+
<span class="aimd-quiz-recorder__option-content">
|
|
601
|
+
<span class="aimd-quiz-recorder__option-label">{{ option.text }}</span>
|
|
602
|
+
<span
|
|
603
|
+
v-if="shouldShowChoiceOptionExplanation(option.key, option.explanation)"
|
|
604
|
+
class="aimd-quiz-recorder__option-explanation"
|
|
605
|
+
>
|
|
606
|
+
{{ option.explanation }}
|
|
607
|
+
</span>
|
|
608
|
+
</span>
|
|
609
|
+
</label>
|
|
610
|
+
</div>
|
|
611
|
+
</div>
|
|
612
|
+
|
|
363
613
|
<div v-if="quiz.type === 'choice' && quiz.mode === 'single' && quiz.options?.length" class="aimd-quiz-recorder__options">
|
|
364
|
-
<
|
|
365
|
-
<
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
<span class="aimd-quiz-recorder__option-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
614
|
+
<div v-for="option in quiz.options" :key="`${quiz.id}-single-${option.key}`" class="aimd-quiz-recorder__option-frame">
|
|
615
|
+
<label class="aimd-quiz-recorder__option">
|
|
616
|
+
<input
|
|
617
|
+
v-model="singleChoiceValue"
|
|
618
|
+
type="radio"
|
|
619
|
+
class="aimd-quiz-recorder__choice-input"
|
|
620
|
+
:data-rec-focus-key="`${focusKeyPrefix || `quiz:${quiz.id}`}:single:${option.key}`"
|
|
621
|
+
:name="`${quiz.id}-single`"
|
|
622
|
+
:value="option.key"
|
|
623
|
+
:disabled="readonly"
|
|
624
|
+
/>
|
|
625
|
+
<span class="aimd-quiz-recorder__option-content">
|
|
626
|
+
<span class="aimd-quiz-recorder__option-label">{{ option.key }}. {{ option.text }}</span>
|
|
627
|
+
<span
|
|
628
|
+
v-if="shouldShowChoiceOptionExplanation(option.key, option.explanation)"
|
|
629
|
+
class="aimd-quiz-recorder__option-explanation"
|
|
630
|
+
>
|
|
631
|
+
{{ option.explanation }}
|
|
632
|
+
</span>
|
|
381
633
|
</span>
|
|
382
|
-
</
|
|
383
|
-
|
|
634
|
+
</label>
|
|
635
|
+
<div v-if="shouldShowChoiceFollowups(option)" class="aimd-quiz-recorder__followups">
|
|
636
|
+
<label
|
|
637
|
+
v-for="followup in option.followups"
|
|
638
|
+
:key="`${quiz.id}-single-${option.key}-followup-${followup.key}`"
|
|
639
|
+
class="aimd-quiz-recorder__followup"
|
|
640
|
+
>
|
|
641
|
+
<span class="aimd-quiz-recorder__followup-label">{{ getFollowupLabel(followup) }}</span>
|
|
642
|
+
<input
|
|
643
|
+
v-if="followup.type === 'bool'"
|
|
644
|
+
type="checkbox"
|
|
645
|
+
class="aimd-quiz-recorder__followup-checkbox"
|
|
646
|
+
:data-rec-focus-key="`${focusKeyPrefix || `quiz:${quiz.id}`}:single:${option.key}:followup:${followup.key}`"
|
|
647
|
+
:checked="getFollowupBooleanValue(option.key, followup)"
|
|
648
|
+
:disabled="readonly"
|
|
649
|
+
@change="setChoiceFollowupValue(option.key, followup, ($event.target as HTMLInputElement).checked)"
|
|
650
|
+
/>
|
|
651
|
+
<input
|
|
652
|
+
v-else
|
|
653
|
+
:type="followup.type === 'str' ? 'text' : 'number'"
|
|
654
|
+
:step="followup.type === 'int' ? '1' : undefined"
|
|
655
|
+
class="aimd-quiz-recorder__followup-input"
|
|
656
|
+
:data-rec-focus-key="`${focusKeyPrefix || `quiz:${quiz.id}`}:single:${option.key}:followup:${followup.key}`"
|
|
657
|
+
:value="getFollowupTextValue(option.key, followup)"
|
|
658
|
+
:readonly="readonly"
|
|
659
|
+
@input="setChoiceFollowupValue(option.key, followup, ($event.target as HTMLInputElement).value)"
|
|
660
|
+
/>
|
|
661
|
+
<span v-if="followup.unit" class="aimd-quiz-recorder__followup-unit">{{ followup.unit }}</span>
|
|
662
|
+
</label>
|
|
663
|
+
</div>
|
|
664
|
+
</div>
|
|
384
665
|
</div>
|
|
385
666
|
|
|
386
667
|
<div v-if="quiz.type === 'choice' && quiz.mode === 'multiple' && quiz.options?.length" class="aimd-quiz-recorder__options">
|
|
387
|
-
<
|
|
388
|
-
<
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
<span class="aimd-quiz-recorder__option-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
668
|
+
<div v-for="option in quiz.options" :key="`${quiz.id}-multiple-${option.key}`" class="aimd-quiz-recorder__option-frame">
|
|
669
|
+
<label class="aimd-quiz-recorder__option">
|
|
670
|
+
<input
|
|
671
|
+
type="checkbox"
|
|
672
|
+
class="aimd-quiz-recorder__choice-input"
|
|
673
|
+
:data-rec-focus-key="`${focusKeyPrefix || `quiz:${quiz.id}`}:multiple:${option.key}`"
|
|
674
|
+
:disabled="readonly"
|
|
675
|
+
:checked="isMultipleChecked(option.key)"
|
|
676
|
+
@change="toggleMultipleChoice(option.key, ($event.target as HTMLInputElement).checked)"
|
|
677
|
+
/>
|
|
678
|
+
<span class="aimd-quiz-recorder__option-content">
|
|
679
|
+
<span class="aimd-quiz-recorder__option-label">{{ option.key }}. {{ option.text }}</span>
|
|
680
|
+
<span
|
|
681
|
+
v-if="shouldShowChoiceOptionExplanation(option.key, option.explanation)"
|
|
682
|
+
class="aimd-quiz-recorder__option-explanation"
|
|
683
|
+
>
|
|
684
|
+
{{ option.explanation }}
|
|
685
|
+
</span>
|
|
403
686
|
</span>
|
|
404
|
-
</
|
|
405
|
-
|
|
687
|
+
</label>
|
|
688
|
+
<div v-if="shouldShowChoiceFollowups(option)" class="aimd-quiz-recorder__followups">
|
|
689
|
+
<label
|
|
690
|
+
v-for="followup in option.followups"
|
|
691
|
+
:key="`${quiz.id}-multiple-${option.key}-followup-${followup.key}`"
|
|
692
|
+
class="aimd-quiz-recorder__followup"
|
|
693
|
+
>
|
|
694
|
+
<span class="aimd-quiz-recorder__followup-label">{{ getFollowupLabel(followup) }}</span>
|
|
695
|
+
<input
|
|
696
|
+
v-if="followup.type === 'bool'"
|
|
697
|
+
type="checkbox"
|
|
698
|
+
class="aimd-quiz-recorder__followup-checkbox"
|
|
699
|
+
:data-rec-focus-key="`${focusKeyPrefix || `quiz:${quiz.id}`}:multiple:${option.key}:followup:${followup.key}`"
|
|
700
|
+
:checked="getFollowupBooleanValue(option.key, followup)"
|
|
701
|
+
:disabled="readonly"
|
|
702
|
+
@change="setChoiceFollowupValue(option.key, followup, ($event.target as HTMLInputElement).checked)"
|
|
703
|
+
/>
|
|
704
|
+
<input
|
|
705
|
+
v-else
|
|
706
|
+
:type="followup.type === 'str' ? 'text' : 'number'"
|
|
707
|
+
:step="followup.type === 'int' ? '1' : undefined"
|
|
708
|
+
class="aimd-quiz-recorder__followup-input"
|
|
709
|
+
:data-rec-focus-key="`${focusKeyPrefix || `quiz:${quiz.id}`}:multiple:${option.key}:followup:${followup.key}`"
|
|
710
|
+
:value="getFollowupTextValue(option.key, followup)"
|
|
711
|
+
:readonly="readonly"
|
|
712
|
+
@input="setChoiceFollowupValue(option.key, followup, ($event.target as HTMLInputElement).value)"
|
|
713
|
+
/>
|
|
714
|
+
<span v-if="followup.unit" class="aimd-quiz-recorder__followup-unit">{{ followup.unit }}</span>
|
|
715
|
+
</label>
|
|
716
|
+
</div>
|
|
717
|
+
</div>
|
|
406
718
|
</div>
|
|
407
719
|
|
|
408
720
|
<textarea
|
|
@@ -573,6 +885,12 @@ function shouldShowChoiceOptionExplanation(optionKey: string, explanation?: stri
|
|
|
573
885
|
margin-top: 0;
|
|
574
886
|
}
|
|
575
887
|
|
|
888
|
+
.aimd-quiz-recorder__option-frame {
|
|
889
|
+
display: flex;
|
|
890
|
+
flex-direction: column;
|
|
891
|
+
gap: 6px;
|
|
892
|
+
}
|
|
893
|
+
|
|
576
894
|
.aimd-quiz-recorder__option {
|
|
577
895
|
display: flex;
|
|
578
896
|
align-items: flex-start;
|
|
@@ -605,8 +923,48 @@ function shouldShowChoiceOptionExplanation(optionKey: string, explanation?: stri
|
|
|
605
923
|
accent-color: #4181fd;
|
|
606
924
|
}
|
|
607
925
|
|
|
926
|
+
.aimd-quiz-recorder__followups {
|
|
927
|
+
display: flex;
|
|
928
|
+
flex-direction: column;
|
|
929
|
+
gap: 6px;
|
|
930
|
+
margin-left: 22px;
|
|
931
|
+
padding: 8px 10px;
|
|
932
|
+
border-left: 2px solid #dbeafe;
|
|
933
|
+
background: #f8fbff;
|
|
934
|
+
}
|
|
935
|
+
|
|
936
|
+
.aimd-quiz-recorder__followup {
|
|
937
|
+
display: grid;
|
|
938
|
+
grid-template-columns: minmax(92px, max-content) minmax(120px, 1fr) auto;
|
|
939
|
+
gap: 6px;
|
|
940
|
+
align-items: center;
|
|
941
|
+
font-size: 13px;
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
.aimd-quiz-recorder__followup-label {
|
|
945
|
+
color: #344054;
|
|
946
|
+
font-weight: 500;
|
|
947
|
+
}
|
|
948
|
+
|
|
949
|
+
.aimd-quiz-recorder__followup-input {
|
|
950
|
+
min-width: 0;
|
|
951
|
+
width: 100%;
|
|
952
|
+
}
|
|
953
|
+
|
|
954
|
+
.aimd-quiz-recorder__followup-checkbox {
|
|
955
|
+
justify-self: start;
|
|
956
|
+
width: 16px;
|
|
957
|
+
height: 16px;
|
|
958
|
+
accent-color: #4181fd;
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
.aimd-quiz-recorder__followup-unit {
|
|
962
|
+
color: #667085;
|
|
963
|
+
}
|
|
964
|
+
|
|
608
965
|
.aimd-quiz-recorder__open-input,
|
|
609
|
-
.aimd-quiz-recorder__blank-input
|
|
966
|
+
.aimd-quiz-recorder__blank-input,
|
|
967
|
+
.aimd-quiz-recorder__followup-input {
|
|
610
968
|
border: 1px solid #d0d7de;
|
|
611
969
|
border-radius: 6px;
|
|
612
970
|
padding: 6px 8px;
|
|
@@ -631,7 +989,8 @@ function shouldShowChoiceOptionExplanation(optionKey: string, explanation?: stri
|
|
|
631
989
|
}
|
|
632
990
|
|
|
633
991
|
.aimd-quiz-recorder__open-input:focus,
|
|
634
|
-
.aimd-quiz-recorder__blank-input:focus
|
|
992
|
+
.aimd-quiz-recorder__blank-input:focus,
|
|
993
|
+
.aimd-quiz-recorder__followup-input:focus {
|
|
635
994
|
border-color: #4181fd;
|
|
636
995
|
box-shadow: 0 0 0 2px rgba(65, 129, 253, 0.1);
|
|
637
996
|
}
|
|
@@ -52,6 +52,7 @@ import {
|
|
|
52
52
|
} from "../composables/useFocusManagement"
|
|
53
53
|
import type { FocusSnapshot } from "../composables/useFocusManagement"
|
|
54
54
|
import { useClientAssignerRunner } from "../composables/useClientAssignerRunner"
|
|
55
|
+
import type { ClientAssignerFieldDefinitions } from "../client-assigner"
|
|
55
56
|
import { resolveAimdRecorderFieldVNode } from "../composables/useFieldAdapters"
|
|
56
57
|
import { useVarTableDragDrop, getVarTableColumns } from "../composables/useVarTableDragDrop"
|
|
57
58
|
import { useFieldRendering } from "../composables/useFieldRendering"
|
|
@@ -244,6 +245,7 @@ function applyFieldAdapter<TFieldType extends "var" | "var_table" | "step" | "ch
|
|
|
244
245
|
|
|
245
246
|
const EMPTY_FIELDS: ExtractedAimdFields = {
|
|
246
247
|
var: [],
|
|
248
|
+
var_definitions: [],
|
|
247
249
|
var_table: [],
|
|
248
250
|
client_assigner: [],
|
|
249
251
|
quiz: [],
|
|
@@ -258,6 +260,16 @@ const EMPTY_FIELDS: ExtractedAimdFields = {
|
|
|
258
260
|
|
|
259
261
|
const extractedFields = ref<ExtractedAimdFields>(EMPTY_FIELDS)
|
|
260
262
|
const clientAssigners = ref<AimdClientAssignerField[]>([])
|
|
263
|
+
const clientAssignerFieldDefinitions = computed<ClientAssignerFieldDefinitions>(() => {
|
|
264
|
+
const definitions: ClientAssignerFieldDefinitions = {}
|
|
265
|
+
for (const field of extractedFields.value.var_definitions ?? []) {
|
|
266
|
+
definitions[field.id] = {
|
|
267
|
+
type: field.type,
|
|
268
|
+
kwargs: field.kwargs,
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
return definitions
|
|
272
|
+
})
|
|
261
273
|
const protocolEstimatedDurationMs = computed(() => getProtocolEstimatedDurationMs(extractedFields.value.step_hierarchy ?? []))
|
|
262
274
|
const protocolRecordedDurationMs = computed(() => getProtocolRecordedDurationMs(localRecord.step, timerNowMs.value))
|
|
263
275
|
const showProtocolTimingSummary = computed(() => protocolEstimatedDurationMs.value > 0 || protocolRecordedDurationMs.value > 0)
|
|
@@ -326,6 +338,7 @@ function markRecordChanged(options?: { rebuild?: boolean, runClientAssigners?: b
|
|
|
326
338
|
const assignerRunner = useClientAssignerRunner({
|
|
327
339
|
readonly: () => props.readonly,
|
|
328
340
|
clientAssigners,
|
|
341
|
+
fieldDefinitions: () => clientAssignerFieldDefinitions.value,
|
|
329
342
|
localRecord,
|
|
330
343
|
onError: (message) => emit("error", message),
|
|
331
344
|
emitRecordUpdate,
|
|
@@ -799,7 +812,7 @@ function renderInlineQuiz(node: AimdQuizNode): VNode {
|
|
|
799
812
|
scaleGradeDisplayMode: props.scaleGradeDisplayMode,
|
|
800
813
|
"onUpdate:modelValue": (value: unknown) => {
|
|
801
814
|
localRecord.quiz[quizId] = value
|
|
802
|
-
markRecordChanged()
|
|
815
|
+
markRecordChanged({ rebuild: true })
|
|
803
816
|
emit("field-change", { section: "quiz", fieldKey: quizId, value })
|
|
804
817
|
},
|
|
805
818
|
})
|
|
@@ -133,6 +133,7 @@ const emit = defineEmits<{
|
|
|
133
133
|
|
|
134
134
|
const EMPTY_FIELDS: ExtractedAimdFields = {
|
|
135
135
|
var: [],
|
|
136
|
+
var_definitions: [],
|
|
136
137
|
var_table: [],
|
|
137
138
|
client_assigner: [],
|
|
138
139
|
quiz: [],
|
|
@@ -794,7 +795,7 @@ function handleFieldsChange(fields: ExtractedAimdFields) {
|
|
|
794
795
|
}
|
|
795
796
|
|
|
796
797
|
function handleAddField(fieldType: AimdWorkbenchFieldType) {
|
|
797
|
-
const nextId = generateNextWorkbenchFieldId(editableFields.value, fieldType)
|
|
798
|
+
const nextId = generateNextWorkbenchFieldId(editableFields.value, fieldType, fieldType === 'quiz' ? 'choice' : undefined)
|
|
798
799
|
emitWorkbenchContentChange(appendWorkbenchField(contentDraft.value, fieldType, {
|
|
799
800
|
id: nextId,
|
|
800
801
|
valueType: fieldType === 'var' ? 'str' : undefined,
|
|
@@ -867,7 +868,7 @@ function toggleFieldInsertMenu(insertionIndex: number) {
|
|
|
867
868
|
}
|
|
868
869
|
|
|
869
870
|
function handleInsertField(fieldType: AimdWorkbenchFieldType, insertionIndex: number) {
|
|
870
|
-
const nextId = generateNextWorkbenchFieldId(editableFields.value, fieldType)
|
|
871
|
+
const nextId = generateNextWorkbenchFieldId(editableFields.value, fieldType, fieldType === 'quiz' ? 'choice' : undefined)
|
|
871
872
|
fieldInsertMenuIndex.value = null
|
|
872
873
|
emitWorkbenchContentChange(insertWorkbenchField(
|
|
873
874
|
contentDraft.value,
|