@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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@airalogy/aimd-recorder",
3
3
  "type": "module",
4
- "version": "1.16.0",
4
+ "version": "1.17.0",
5
5
  "description": "AIMD (Airalogy Markdown) recorder Vue components and UI",
6
6
  "license": "Apache-2.0",
7
7
  "repository": {
@@ -58,9 +58,9 @@
58
58
  "react": "^19.2.4",
59
59
  "react-dom": "^19.2.4",
60
60
  "seqviz": "^3.10.18",
61
- "@airalogy/aimd-core": "^2.6.0",
62
- "@airalogy/aimd-renderer": "^2.5.0",
63
- "@airalogy/aimd-editor": "^1.9.0"
61
+ "@airalogy/aimd-editor": "^1.9.0",
62
+ "@airalogy/aimd-core": "^2.7.0",
63
+ "@airalogy/aimd-renderer": "^2.5.0"
64
64
  },
65
65
  "devDependencies": {
66
66
  "@types/node": "^24.3.0",
@@ -178,6 +178,53 @@ describe('AimdQuizRecorder', () => {
178
178
  expect(wrapper.text()).not.toContain('Incorrect.')
179
179
  })
180
180
 
181
+ it('renders selected true/false followups and emits structured updates', async () => {
182
+ const wrapper = mount(AimdQuizRecorder, {
183
+ props: {
184
+ locale: 'en-US',
185
+ quiz: {
186
+ id: 'quiz_precipitate',
187
+ type: 'true_false',
188
+ stem: 'Was precipitate observed?',
189
+ options: [
190
+ {
191
+ key: 'true',
192
+ text: 'Yes',
193
+ followups: [
194
+ { key: 'color', type: 'str', required: true, title: 'Color' },
195
+ ],
196
+ },
197
+ { key: 'false', text: 'No' },
198
+ ],
199
+ },
200
+ modelValue: {
201
+ selected: true,
202
+ followups: {
203
+ true: {
204
+ color: 'white',
205
+ },
206
+ },
207
+ },
208
+ },
209
+ })
210
+
211
+ expect(wrapper.text()).toContain('Color')
212
+
213
+ await wrapper
214
+ .find('input[data-rec-focus-key="quiz:quiz_precipitate:true_false:true:followup:color"]')
215
+ .setValue('yellow')
216
+
217
+ const emitted = wrapper.emitted('update:modelValue') || []
218
+ expect(emitted[emitted.length - 1]?.[0]).toEqual({
219
+ selected: true,
220
+ followups: {
221
+ true: {
222
+ color: 'yellow',
223
+ },
224
+ },
225
+ })
226
+ })
227
+
181
228
  it('renders selected choice followups and emits structured updates', async () => {
182
229
  const wrapper = mount(AimdQuizRecorder, {
183
230
  props: {
@@ -0,0 +1,103 @@
1
+ import { flushPromises, mount } from '@vue/test-utils'
2
+ import { beforeEach, describe, expect, it, vi } from 'vitest'
3
+ import { h, nextTick } from 'vue'
4
+
5
+ const mocks = vi.hoisted(() => ({
6
+ parseAndExtract: vi.fn(),
7
+ renderToVue: vi.fn(),
8
+ }))
9
+
10
+ vi.mock('@airalogy/aimd-renderer', async (importOriginal) => {
11
+ const actual = await importOriginal<typeof import('@airalogy/aimd-renderer')>()
12
+ return {
13
+ ...actual,
14
+ parseAndExtract: mocks.parseAndExtract,
15
+ renderToVue: mocks.renderToVue,
16
+ }
17
+ })
18
+
19
+ import AimdRecorder from '../components/AimdRecorder.vue'
20
+
21
+ const checkNode = {
22
+ type: 'aimd',
23
+ fieldType: 'check',
24
+ id: 'quality_control',
25
+ name: 'quality_control',
26
+ label: 'quality_control',
27
+ raw: '{{check|quality_control}}',
28
+ scope: 'check',
29
+ }
30
+
31
+ function createFields() {
32
+ return {
33
+ var: [],
34
+ var_definitions: [],
35
+ var_table: [],
36
+ client_assigner: [],
37
+ quiz: [],
38
+ step: [],
39
+ check: [{ name: 'quality_control', label: 'quality_control' }],
40
+ ref_step: [],
41
+ ref_var: [],
42
+ ref_fig: [],
43
+ cite: [],
44
+ fig: [],
45
+ }
46
+ }
47
+
48
+ async function mountRecorder(content: string) {
49
+ const wrapper = mount(AimdRecorder, {
50
+ props: {
51
+ content,
52
+ locale: 'zh-CN',
53
+ modelValue: { var: {}, step: {}, check: {}, quiz: {} },
54
+ },
55
+ })
56
+
57
+ await flushPromises()
58
+ await nextTick()
59
+
60
+ return wrapper
61
+ }
62
+
63
+ describe('AimdRecorder check fields', () => {
64
+ beforeEach(() => {
65
+ mocks.parseAndExtract.mockImplementation(() => createFields())
66
+ mocks.renderToVue.mockImplementation(async (
67
+ content: string,
68
+ options: { aimdRenderers: { check: (node: unknown, ctx: unknown, children: unknown[]) => unknown } },
69
+ ) => {
70
+ const children = content.includes('with body')
71
+ ? [
72
+ h('div', { class: 'aimd-check-body', 'data-aimd-check-body': 'true' }, [
73
+ h('span', '数据完整性检查。'),
74
+ ]),
75
+ ]
76
+ : [
77
+ h('input', { type: 'checkbox', class: 'aimd-checkbox', disabled: true }),
78
+ h('span', { class: 'aimd-field__label' }, 'quality_control'),
79
+ ]
80
+
81
+ return {
82
+ fields: createFields(),
83
+ nodes: [options.aimdRenderers.check(checkNode, {}, children)],
84
+ }
85
+ })
86
+ })
87
+
88
+ it('strips the renderer default checkbox from bare check bodies', async () => {
89
+ const wrapper = await mountRecorder('{{check|quality_control}}')
90
+
91
+ expect(wrapper.findAll('.aimd-rec-inline--check input[type="checkbox"]')).toHaveLength(1)
92
+ expect(wrapper.find('.aimd-check-field__body input[type="checkbox"]').exists()).toBe(false)
93
+ expect(wrapper.find('.aimd-check-field__key').text()).toBe('quality_control')
94
+ })
95
+
96
+ it('keeps grouped check body text while using one interactive checkbox', async () => {
97
+ const wrapper = await mountRecorder('{{check|quality_control}} with body')
98
+
99
+ expect(wrapper.findAll('.aimd-rec-inline--check input[type="checkbox"]')).toHaveLength(1)
100
+ expect(wrapper.find('.aimd-check-field__body').text()).toContain('数据完整性检查。')
101
+ expect(wrapper.find('.aimd-check-field__key').exists()).toBe(false)
102
+ })
103
+ })
@@ -251,7 +251,7 @@ describe('AimdStepField', () => {
251
251
  expect(wrapper.text()).toContain('Timer 0s')
252
252
  })
253
253
 
254
- it('renders check cards as lightweight cards that absorb body text and checked state messaging', () => {
254
+ it('renders check cards as lightweight cards that absorb body text and checked state messaging', async () => {
255
255
  const node: AimdCheckNode = {
256
256
  id: 'verify_tube_label',
257
257
  label: 'Verify that the tube label matches the sample name and the processing batch identifier before continuing',
@@ -277,12 +277,16 @@ describe('AimdStepField', () => {
277
277
  },
278
278
  })
279
279
 
280
+ await flushStepFieldAsync()
281
+
280
282
  expect(wrapper.element.tagName).toBe('DIV')
283
+ expect(wrapper.classes()).toContain('aimd-rec-inline--check-passed')
284
+ expect(wrapper.classes()).toContain('aimd-rec-inline--check-with-body')
281
285
  expect(wrapper.find('.aimd-check-field__body').text()).toContain('Verify that the tube label matches the sample name before continuing.')
282
286
  expect(wrapper.find('.aimd-check-field__body--checked').exists()).toBe(true)
283
287
  expect(wrapper.find('.aimd-check-field__banner').text()).toContain('Tube label verified')
284
- expect(wrapper.find('.aimd-rec-inline__input--annotation').exists()).toBe(true)
285
- expect((wrapper.find('.aimd-rec-inline__input--annotation').element as HTMLInputElement).value).toBe('Resolved from assigner context')
288
+ expect(wrapper.find('.aimd-rec-inline__input--annotation').exists()).toBe(false)
289
+ expect(wrapper.find('.aimd-check-field__detail--annotation').exists()).toBe(true)
286
290
  expect(wrapper.find('.aimd-check-field__key').exists()).toBe(false)
287
291
  })
288
292
 
@@ -309,6 +313,39 @@ describe('AimdStepField', () => {
309
313
  },
310
314
  })
311
315
 
316
+ expect(wrapper.classes()).toContain('aimd-rec-inline--check-open')
317
+ expect(wrapper.classes()).toContain('aimd-rec-inline--check-bodyless')
312
318
  expect(wrapper.find('.aimd-check-field__key').text()).toBe('verify_tube_label')
313
319
  })
320
+
321
+ it('opens the check annotation editor on demand', async () => {
322
+ const node: AimdCheckNode = {
323
+ id: 'verify_tube_label',
324
+ label: 'verify_tube_label',
325
+ fieldType: 'check',
326
+ scope: 'check',
327
+ type: 'aimd',
328
+ raw: '{{check|verify_tube_label}}',
329
+ }
330
+ const wrapper = mount(AimdCheckField, {
331
+ props: {
332
+ node,
333
+ state: reactive({
334
+ checked: false,
335
+ annotation: '',
336
+ }),
337
+ bodyNodes: [],
338
+ disabled: false,
339
+ extraClasses: [],
340
+ messages: createAimdRecorderMessages('en-US'),
341
+ },
342
+ })
343
+
344
+ expect(wrapper.find('.aimd-check-field__detail--annotation').exists()).toBe(false)
345
+
346
+ await wrapper.find('.aimd-check-field__toggle-btn').trigger('click')
347
+ await flushStepFieldAsync()
348
+
349
+ expect(wrapper.find('.aimd-check-field__detail--annotation').exists()).toBe(true)
350
+ })
314
351
  })
@@ -0,0 +1,121 @@
1
+ <script setup lang="ts">
2
+ import type { AimdQuizFollowupField } from "@airalogy/aimd-core/types"
3
+
4
+ type FollowupPrimitive = string | number | boolean
5
+ type FollowupInputScope = "true_false" | "single" | "multiple"
6
+
7
+ const props = defineProps<{
8
+ quizId: string
9
+ optionKey: string
10
+ inputScope: FollowupInputScope
11
+ followups: AimdQuizFollowupField[]
12
+ values: Record<string, FollowupPrimitive>
13
+ readonly?: boolean
14
+ focusKeyPrefix?: string
15
+ }>()
16
+
17
+ const emit = defineEmits<{
18
+ (e: "update", followup: AimdQuizFollowupField, value: string | boolean): void
19
+ }>()
20
+
21
+ function getFollowupLabel(followup: AimdQuizFollowupField): string {
22
+ return followup.title || followup.key
23
+ }
24
+
25
+ function getFollowupTextValue(followup: AimdQuizFollowupField): string {
26
+ const value = props.values[followup.key]
27
+ if (typeof value === "string" || typeof value === "number") {
28
+ return String(value)
29
+ }
30
+ return ""
31
+ }
32
+
33
+ function getFollowupBooleanValue(followup: AimdQuizFollowupField): boolean {
34
+ return props.values[followup.key] === true
35
+ }
36
+ </script>
37
+
38
+ <template>
39
+ <div class="aimd-quiz-recorder__followups">
40
+ <label
41
+ v-for="followup in followups"
42
+ :key="`${quizId}-${inputScope}-${optionKey}-followup-${followup.key}`"
43
+ class="aimd-quiz-recorder__followup"
44
+ >
45
+ <span class="aimd-quiz-recorder__followup-label">{{ getFollowupLabel(followup) }}</span>
46
+ <input
47
+ v-if="followup.type === 'bool'"
48
+ type="checkbox"
49
+ class="aimd-quiz-recorder__followup-checkbox"
50
+ :data-rec-focus-key="`${focusKeyPrefix || `quiz:${quizId}`}:${inputScope}:${optionKey}:followup:${followup.key}`"
51
+ :checked="getFollowupBooleanValue(followup)"
52
+ :disabled="readonly"
53
+ @change="emit('update', followup, ($event.target as HTMLInputElement).checked)"
54
+ />
55
+ <input
56
+ v-else
57
+ :type="followup.type === 'str' ? 'text' : 'number'"
58
+ :step="followup.type === 'int' ? '1' : undefined"
59
+ class="aimd-quiz-recorder__followup-input"
60
+ :data-rec-focus-key="`${focusKeyPrefix || `quiz:${quizId}`}:${inputScope}:${optionKey}:followup:${followup.key}`"
61
+ :value="getFollowupTextValue(followup)"
62
+ :readonly="readonly"
63
+ @input="emit('update', followup, ($event.target as HTMLInputElement).value)"
64
+ />
65
+ <span v-if="followup.unit" class="aimd-quiz-recorder__followup-unit">{{ followup.unit }}</span>
66
+ </label>
67
+ </div>
68
+ </template>
69
+
70
+ <style scoped>
71
+ .aimd-quiz-recorder__followups {
72
+ display: flex;
73
+ flex-direction: column;
74
+ gap: 6px;
75
+ margin-left: 22px;
76
+ padding: 8px 10px;
77
+ border-left: 2px solid #dbeafe;
78
+ background: #f8fbff;
79
+ }
80
+
81
+ .aimd-quiz-recorder__followup {
82
+ display: grid;
83
+ grid-template-columns: minmax(92px, max-content) minmax(120px, 1fr) auto;
84
+ gap: 6px;
85
+ align-items: center;
86
+ font-size: 13px;
87
+ }
88
+
89
+ .aimd-quiz-recorder__followup-label {
90
+ color: #344054;
91
+ font-weight: 500;
92
+ }
93
+
94
+ .aimd-quiz-recorder__followup-input {
95
+ min-width: 0;
96
+ width: 100%;
97
+ border: 1px solid #d0d7de;
98
+ border-radius: 6px;
99
+ padding: 6px 8px;
100
+ font-size: 14px;
101
+ line-height: 1.4;
102
+ outline: none;
103
+ transition: border-color 0.2s, box-shadow 0.2s;
104
+ }
105
+
106
+ .aimd-quiz-recorder__followup-input:focus {
107
+ border-color: #4181fd;
108
+ box-shadow: 0 0 0 2px rgba(65, 129, 253, 0.1);
109
+ }
110
+
111
+ .aimd-quiz-recorder__followup-checkbox {
112
+ justify-self: start;
113
+ width: 16px;
114
+ height: 16px;
115
+ accent-color: #4181fd;
116
+ }
117
+
118
+ .aimd-quiz-recorder__followup-unit {
119
+ color: #667085;
120
+ }
121
+ </style>