@airalogy/aimd-recorder 1.14.1

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.
Files changed (178) hide show
  1. package/README.md +240 -0
  2. package/README.zh-CN.md +224 -0
  3. package/dist/AimdCodeField-DC3DPvgc.js +172 -0
  4. package/dist/AimdDnaSequenceField-__jdnFS9.js +59466 -0
  5. package/dist/AimdEditor.vue_vue_type_style_index_0_lang-Bq79rKNw.js +28370 -0
  6. package/dist/AimdMarkdownField-98ImHGbc.js +66 -0
  7. package/dist/AimdMarkdownNoteField-CuUJZkgT.js +185 -0
  8. package/dist/_.contribution-IP0cDNhs.js +38 -0
  9. package/dist/_commonjsHelpers-CZXJ37nu.js +40 -0
  10. package/dist/abap-Bs8kvjsq.js +1398 -0
  11. package/dist/aimd-recorder.css +1 -0
  12. package/dist/apex-Dspwrl5m.js +326 -0
  13. package/dist/assets/css.worker-Dmf38jDD.js +79 -0
  14. package/dist/assets/editor.worker-CpuX8TSY.js +12 -0
  15. package/dist/assets/html.worker-DotaEs7v.js +456 -0
  16. package/dist/assets/json.worker-B4VHhH6h.js +44 -0
  17. package/dist/assets/ts.worker-sl17zBDo.js +51316 -0
  18. package/dist/azcli-k1BiOau1.js +68 -0
  19. package/dist/bat-BIP72KWc.js +100 -0
  20. package/dist/bicep-VhQeYhS3.js +102 -0
  21. package/dist/cameligo-DnuAXtHg.js +174 -0
  22. package/dist/clojure-BAuDPsal.js +761 -0
  23. package/dist/coffee-BV06qSnj.js +232 -0
  24. package/dist/components.js +3595 -0
  25. package/dist/composables.js +72 -0
  26. package/dist/cpp-Cz8Jeyrf.js +389 -0
  27. package/dist/csharp-F6hhlXFb.js +326 -0
  28. package/dist/csp-KzlEHCyI.js +53 -0
  29. package/dist/css-e4FKntZ3.js +187 -0
  30. package/dist/cssMode-uz9U6SUU.js +1571 -0
  31. package/dist/cypher-CpvDGKRr.js +263 -0
  32. package/dist/dart-DdHeFWR0.js +281 -0
  33. package/dist/dockerfile-aoNXDcio.js +130 -0
  34. package/dist/ecl-C4Q0DYuA.js +456 -0
  35. package/dist/editor.api-CgD9w0gG.js +77091 -0
  36. package/dist/editor.main-Du02abDl.js +33783 -0
  37. package/dist/elixir-C9X42b0T.js +569 -0
  38. package/dist/flow9-Bff42pfB.js +142 -0
  39. package/dist/freemarker2-DFLX4iQ-.js +989 -0
  40. package/dist/fsharp-C6vPAsHG.js +217 -0
  41. package/dist/go-DEr8zx9f.js +218 -0
  42. package/dist/graphql-BiNBBRFh.js +151 -0
  43. package/dist/handlebars-aiZbIuWY.js +419 -0
  44. package/dist/hcl-2T9lKuFg.js +183 -0
  45. package/dist/html-phzTMObN.js +308 -0
  46. package/dist/htmlMode-BF7wMi3N.js +1581 -0
  47. package/dist/index.js +89 -0
  48. package/dist/ini-CZGtssYM.js +71 -0
  49. package/dist/ini.contribution-DyWtiacL.js +8 -0
  50. package/dist/java-B260NeH3.js +232 -0
  51. package/dist/javascript-BKKOItMi.js +70 -0
  52. package/dist/jsonMode-CDYK4B5l.js +1996 -0
  53. package/dist/julia-kuNLM9c5.js +511 -0
  54. package/dist/kotlin-Bz6kAefA.js +253 -0
  55. package/dist/less-AZUtS89I.js +162 -0
  56. package/dist/lexon-BcmgnyRb.js +157 -0
  57. package/dist/liquid-B2eRz5SA.js +240 -0
  58. package/dist/lua-Dz1RbATg.js +162 -0
  59. package/dist/m3-CIMooLFn.js +210 -0
  60. package/dist/markdown-C1BsCK9P.js +229 -0
  61. package/dist/markdown.contribution-DYYk6zUU.js +7 -0
  62. package/dist/mdx-BfV1HDRG.js +165 -0
  63. package/dist/mips-BovsnfLQ.js +198 -0
  64. package/dist/monaco.contribution-C-bQhUTI.js +114 -0
  65. package/dist/monaco.contribution-CCVvl3Jx.js +72 -0
  66. package/dist/monaco.contribution-Col-f0XR.js +164 -0
  67. package/dist/monaco.contribution-b5xkgQ-s.js +112 -0
  68. package/dist/msdax-CiRB2ZB-.js +375 -0
  69. package/dist/mysql-BwdpPE19.js +878 -0
  70. package/dist/objective-c-D4nfHfso.js +183 -0
  71. package/dist/pascal--j5-PYtz.js +251 -0
  72. package/dist/pascaligo-C7TcJxNL.js +164 -0
  73. package/dist/perl-BzEWqUb5.js +626 -0
  74. package/dist/pgsql-B_KZ0mGX.js +851 -0
  75. package/dist/php-A19QHzQV.js +500 -0
  76. package/dist/pla-COeKY1hA.js +137 -0
  77. package/dist/postiats-BfMp7zJL.js +907 -0
  78. package/dist/powerquery-B0TS_5Gb.js +890 -0
  79. package/dist/powershell-5jSbKdYB.js +239 -0
  80. package/dist/protobuf-YgnOutn3.js +420 -0
  81. package/dist/pug-DLej6kn5.js +402 -0
  82. package/dist/python-CQrZx9mR.js +301 -0
  83. package/dist/python.contribution-CcKs2Ktm.js +8 -0
  84. package/dist/qsharp-AhjqtSHB.js +301 -0
  85. package/dist/r-D-F4P80w.js +243 -0
  86. package/dist/razor-DWmpHMcx.js +550 -0
  87. package/dist/redis-hwwIlMnV.js +302 -0
  88. package/dist/redshift-Bcm_kjEG.js +809 -0
  89. package/dist/restructuredtext-CrdzfPP-.js +174 -0
  90. package/dist/ruby-QC2UNm1s.js +511 -0
  91. package/dist/rust-5aqiQ3L5.js +343 -0
  92. package/dist/sb-B1g1ZfLJ.js +115 -0
  93. package/dist/scala-C2U4R5Gb.js +370 -0
  94. package/dist/scheme-DeFRbslr.js +108 -0
  95. package/dist/scss-RSTCiCmI.js +262 -0
  96. package/dist/shell-BpF-iNu8.js +221 -0
  97. package/dist/shell.contribution-B80NZ3iO.js +7 -0
  98. package/dist/solidity-C00r2mbQ.js +1367 -0
  99. package/dist/sophia-DVW5ZKDB.js +199 -0
  100. package/dist/sparql-B0nmpxeX.js +201 -0
  101. package/dist/sql-CJwKPERn.js +853 -0
  102. package/dist/sql.contribution-DQy36aE5.js +7 -0
  103. package/dist/st-DPlKG5DT.js +416 -0
  104. package/dist/swift-YZBAbVHV.js +309 -0
  105. package/dist/systemverilog-CDQSaH63.js +576 -0
  106. package/dist/tcl-Dlu8sp6Q.js +232 -0
  107. package/dist/tsMode-Bh-v12OL.js +887 -0
  108. package/dist/twig-C5TO7-kw.js +392 -0
  109. package/dist/typescript-c7y6IZVP.js +343 -0
  110. package/dist/typespec-BsmjDEu7.js +117 -0
  111. package/dist/useFieldRendering-BIqeE3qo.js +6083 -0
  112. package/dist/vb-ChHvIDrk.js +372 -0
  113. package/dist/wgsl-XEp1ju8c.js +439 -0
  114. package/dist/xml-MAEprTnF.js +95 -0
  115. package/dist/xml.contribution-XMOaon8i.js +27 -0
  116. package/dist/yaml-C1p8rXG7.js +206 -0
  117. package/dist/yaml.contribution-DRRVhJmJ.js +8 -0
  118. package/package.json +88 -0
  119. package/src/__tests__/client-assigner.test.ts +341 -0
  120. package/src/__tests__/code-types.test.ts +30 -0
  121. package/src/__tests__/markdown-field.test.ts +34 -0
  122. package/src/__tests__/markdown-note-field.test.ts +135 -0
  123. package/src/__tests__/quiz-recorder.test.ts +195 -0
  124. package/src/__tests__/recorder-editor-content-sync.test.ts +172 -0
  125. package/src/__tests__/recorder-editor.test.ts +143 -0
  126. package/src/__tests__/recorder-render.test.ts +57 -0
  127. package/src/__tests__/recorder-wysiwyg-field-host.test.ts +33 -0
  128. package/src/__tests__/step-field.test.ts +270 -0
  129. package/src/__tests__/type-plugins.test.ts +59 -0
  130. package/src/__tests__/var-field-render.test.ts +26 -0
  131. package/src/client-assigner.ts +269 -0
  132. package/src/code-types.ts +94 -0
  133. package/src/components/AimdCodeField.vue +228 -0
  134. package/src/components/AimdDnaSequenceField.vue +983 -0
  135. package/src/components/AimdMarkdownField.vue +168 -0
  136. package/src/components/AimdMarkdownNoteField.vue +457 -0
  137. package/src/components/AimdQuizRecorder.vue +792 -0
  138. package/src/components/AimdRecorder.vue +1959 -0
  139. package/src/components/AimdRecorderEditor.vue +2281 -0
  140. package/src/components/AimdRecorderWysiwygFieldHost.vue +93 -0
  141. package/src/components/AimdRecorderWysiwygSurface.vue +487 -0
  142. package/src/components/AimdSeqVizViewer.vue +122 -0
  143. package/src/components/AimdStepCheckField.vue +453 -0
  144. package/src/components/AimdVarField.vue +213 -0
  145. package/src/components/AimdVarTableField.vue +516 -0
  146. package/src/components/DnaAnnotationEditor.vue +477 -0
  147. package/src/components/DnaSequenceEditor.vue +44 -0
  148. package/src/components/DnaSequenceToolbar.vue +98 -0
  149. package/src/components/DnaSequenceViewer.vue +162 -0
  150. package/src/components/index.ts +21 -0
  151. package/src/components/recorderMilkdownPlugin.ts +632 -0
  152. package/src/composables/__tests__/useDnaSequence.test.ts +467 -0
  153. package/src/composables/__tests__/useFieldAdapters.test.ts +115 -0
  154. package/src/composables/__tests__/useFocusManagement.test.ts +66 -0
  155. package/src/composables/__tests__/useRecordState.test.ts +586 -0
  156. package/src/composables/__tests__/useStepTimers.test.ts +64 -0
  157. package/src/composables/__tests__/useVarHelpers.test.ts +424 -0
  158. package/src/composables/__tests__/workbenchFieldEditing.test.ts +97 -0
  159. package/src/composables/index.ts +94 -0
  160. package/src/composables/useClientAssignerRunner.ts +74 -0
  161. package/src/composables/useDnaSequence.ts +400 -0
  162. package/src/composables/useDnaSequenceField.ts +316 -0
  163. package/src/composables/useFieldAdapters.ts +61 -0
  164. package/src/composables/useFieldRendering.ts +269 -0
  165. package/src/composables/useFocusManagement.ts +144 -0
  166. package/src/composables/useRecordState.ts +429 -0
  167. package/src/composables/useStepTimers.ts +243 -0
  168. package/src/composables/useVarHelpers.ts +545 -0
  169. package/src/composables/useVarTableDragDrop.ts +236 -0
  170. package/src/composables/workbenchFieldEditing.ts +705 -0
  171. package/src/css.d.ts +9 -0
  172. package/src/index.ts +65 -0
  173. package/src/locales.ts +559 -0
  174. package/src/monaco-code.ts +75 -0
  175. package/src/styles/aimd.css +994 -0
  176. package/src/type-plugins.ts +132 -0
  177. package/src/type-utils.ts +3 -0
  178. package/src/types.ts +191 -0
@@ -0,0 +1,34 @@
1
+ import { readFileSync } from 'node:fs'
2
+ import { dirname, resolve } from 'node:path'
3
+ import { fileURLToPath } from 'node:url'
4
+ import { describe, expect, it } from 'vitest'
5
+
6
+ const __filename = fileURLToPath(import.meta.url)
7
+ const __dirname = dirname(__filename)
8
+ const source = readFileSync(resolve(__dirname, '../components/AimdMarkdownField.vue'), 'utf8')
9
+
10
+ describe('AimdMarkdownField', () => {
11
+ it('embeds the full AimdEditor so toolbar controls remain available', () => {
12
+ expect(source).toMatch(/import \{ AimdEditor \} from '@airalogy\/aimd-editor\/vue'/)
13
+ expect(source).toMatch(/<AimdEditor/)
14
+ expect(source).toMatch(/mode="source"/)
15
+ expect(source).toMatch(/:show-top-bar="true"/)
16
+ expect(source).toMatch(/:show-toolbar="!disabled"/)
17
+ expect(source).toMatch(/:show-md-toolbar="true"/)
18
+ expect(source).toMatch(/:show-aimd-toolbar="true"/)
19
+ })
20
+
21
+ it('renders as an embedded block editor instead of using a trigger dialog', () => {
22
+ expect(source).not.toMatch(/<Teleport to="body">/)
23
+ expect(source).toMatch(/aimd-rec-inline--var-markdown/)
24
+ expect(source).toMatch(/aimd-markdown-field__editor-shell/)
25
+ expect(source).toMatch(/aimd-markdown-field__editor/)
26
+ })
27
+
28
+ it('keeps a local draft so parent v-model echoes do not reset the editor session', () => {
29
+ expect(source).toMatch(/const draftValue = ref\(normalizeMarkdownModelValue\(props\.modelValue\)\)/)
30
+ expect(source).toMatch(/watch\(\(\) => props\.modelValue, \(value\) => \{/)
31
+ expect(source).toMatch(/if \(nextValue === draftValue\.value\)/)
32
+ expect(source).toMatch(/emitDraftValue/)
33
+ })
34
+ })
@@ -0,0 +1,135 @@
1
+ import { mount } from '@vue/test-utils'
2
+ import { defineComponent, h, nextTick } from 'vue'
3
+ import { describe, expect, it, vi } from 'vitest'
4
+
5
+ const { renderToVueMock } = vi.hoisted(() => ({
6
+ renderToVueMock: vi.fn(),
7
+ }))
8
+
9
+ vi.mock('@airalogy/aimd-editor/vue', () => ({
10
+ AimdEditor: defineComponent({
11
+ name: 'AimdEditorMock',
12
+ props: {
13
+ modelValue: {
14
+ type: String,
15
+ default: '',
16
+ },
17
+ },
18
+ emits: ['update:modelValue'],
19
+ setup(props, { emit }) {
20
+ return () => h('textarea', {
21
+ class: 'aimd-editor-mock',
22
+ value: props.modelValue,
23
+ onInput: (event: Event) => emit('update:modelValue', (event.target as HTMLTextAreaElement).value),
24
+ })
25
+ },
26
+ }),
27
+ }))
28
+
29
+ vi.mock('@airalogy/aimd-renderer', () => ({
30
+ renderToVue: renderToVueMock,
31
+ }))
32
+
33
+ import AimdMarkdownNoteField from '../components/AimdMarkdownNoteField.vue'
34
+
35
+ async function flushUi() {
36
+ await Promise.resolve()
37
+ await new Promise(resolve => setTimeout(resolve, 0))
38
+ await nextTick()
39
+ }
40
+
41
+ describe('AimdMarkdownNoteField', () => {
42
+ it('renders saved notes as compact markdown preview by default', async () => {
43
+ renderToVueMock.mockImplementation(async (content: string) => ({
44
+ nodes: [h('div', { class: 'aimd-rendered-note' }, `rendered:${content}`)],
45
+ fields: {},
46
+ }))
47
+
48
+ const wrapper = mount(AimdMarkdownNoteField, {
49
+ props: {
50
+ modelValue: '**keep cold**',
51
+ locale: 'en-US',
52
+ },
53
+ })
54
+
55
+ await flushUi()
56
+
57
+ expect(renderToVueMock).toHaveBeenCalledWith('**keep cold**', { locale: 'en-US' })
58
+ expect(wrapper.find('.aimd-markdown-note-field__preview').exists()).toBe(true)
59
+ expect(wrapper.find('.aimd-rendered-note').text()).toContain('rendered:**keep cold**')
60
+ expect(wrapper.find('.aimd-editor-mock').exists()).toBe(false)
61
+ })
62
+
63
+ it('switches to editor mode only when the user asks to edit', async () => {
64
+ renderToVueMock.mockImplementation(async (content: string) => ({
65
+ nodes: [h('div', { class: 'aimd-rendered-note' }, `rendered:${content}`)],
66
+ fields: {},
67
+ }))
68
+
69
+ const wrapper = mount(AimdMarkdownNoteField, {
70
+ props: {
71
+ modelValue: '- add buffer',
72
+ locale: 'en-US',
73
+ },
74
+ })
75
+
76
+ await flushUi()
77
+ await wrapper.find('.aimd-markdown-note-field__preview-edit').trigger('click')
78
+ await nextTick()
79
+
80
+ expect(wrapper.find('.aimd-editor-mock').exists()).toBe(true)
81
+ expect(wrapper.find('.aimd-markdown-note-field__preview').exists()).toBe(false)
82
+ })
83
+
84
+ it('opens empty notes directly in editor mode', () => {
85
+ const wrapper = mount(AimdMarkdownNoteField, {
86
+ props: {
87
+ modelValue: '',
88
+ locale: 'en-US',
89
+ },
90
+ })
91
+
92
+ expect(wrapper.find('.aimd-editor-mock').exists()).toBe(true)
93
+ expect(wrapper.find('.aimd-markdown-note-field__preview').exists()).toBe(false)
94
+ })
95
+
96
+ it('returns to preview mode after blur when the note has content', async () => {
97
+ renderToVueMock.mockImplementation(async (content: string) => ({
98
+ nodes: [h('div', { class: 'aimd-rendered-note' }, `rendered:${content}`)],
99
+ fields: {},
100
+ }))
101
+
102
+ const wrapper = mount(AimdMarkdownNoteField, {
103
+ props: {
104
+ modelValue: '',
105
+ locale: 'en-US',
106
+ },
107
+ attachTo: document.body,
108
+ })
109
+
110
+ await wrapper.find('.aimd-editor-mock').setValue('Use **fresh** tip')
111
+ await wrapper.trigger('focusout', { relatedTarget: document.body })
112
+ await flushUi()
113
+
114
+ expect(wrapper.emitted('update:modelValue')?.[0]).toEqual(['Use **fresh** tip'])
115
+ expect(wrapper.emitted('blur')).toBeTruthy()
116
+ expect(wrapper.find('.aimd-markdown-note-field__preview').exists()).toBe(true)
117
+ expect(wrapper.find('.aimd-editor-mock').exists()).toBe(false)
118
+
119
+ wrapper.unmount()
120
+ })
121
+
122
+ it('offers an explicit close action while editing notes', async () => {
123
+ const wrapper = mount(AimdMarkdownNoteField, {
124
+ props: {
125
+ modelValue: '',
126
+ locale: 'en-US',
127
+ },
128
+ })
129
+
130
+ await wrapper.find('.aimd-markdown-note-field__editor-close').trigger('click')
131
+
132
+ expect(wrapper.emitted('close')).toBeTruthy()
133
+ expect(wrapper.emitted('blur')).toBeTruthy()
134
+ })
135
+ })
@@ -0,0 +1,195 @@
1
+ import { mount } from '@vue/test-utils'
2
+ import { describe, expect, it } from 'vitest'
3
+
4
+ import AimdQuizRecorder from '../components/AimdQuizRecorder.vue'
5
+
6
+ describe('AimdQuizRecorder', () => {
7
+ it('renders quiz grading feedback when a grade result is provided', () => {
8
+ const wrapper = mount(AimdQuizRecorder, {
9
+ props: {
10
+ locale: 'en-US',
11
+ quiz: {
12
+ id: 'quiz_open_1',
13
+ type: 'open',
14
+ stem: 'Explain why this happens',
15
+ score: 5,
16
+ },
17
+ modelValue: 'Because of reaction rate and stability.',
18
+ grade: {
19
+ quiz_id: 'quiz_open_1',
20
+ earned_score: 4,
21
+ max_score: 5,
22
+ status: 'partial',
23
+ method: 'keyword_rubric',
24
+ review_required: true,
25
+ feedback: 'Mentioned rate but missed one rubric item.',
26
+ },
27
+ },
28
+ })
29
+
30
+ expect(wrapper.text()).toContain('Partial')
31
+ expect(wrapper.text()).toContain('Score: 4 / 5')
32
+ expect(wrapper.text()).toContain('Review required')
33
+ expect(wrapper.text()).toContain('Mentioned rate but missed one rubric item.')
34
+ })
35
+
36
+ it('applies status-specific grading classes for quick visual distinction', () => {
37
+ const wrapper = mount(AimdQuizRecorder, {
38
+ props: {
39
+ locale: 'en-US',
40
+ quiz: {
41
+ id: 'quiz_single_1',
42
+ type: 'choice',
43
+ stem: 'Pick one',
44
+ score: 2,
45
+ mode: 'single',
46
+ options: [
47
+ { key: 'A', text: 'A' },
48
+ { key: 'B', text: 'B' },
49
+ ],
50
+ },
51
+ modelValue: 'A',
52
+ grade: {
53
+ quiz_id: 'quiz_single_1',
54
+ earned_score: 0,
55
+ max_score: 2,
56
+ status: 'incorrect',
57
+ method: 'exact_match',
58
+ },
59
+ },
60
+ })
61
+
62
+ expect(wrapper.find('.aimd-quiz__grade-panel').classes()).toContain('aimd-quiz__grade-panel--incorrect')
63
+ expect(wrapper.find('.aimd-quiz__grade-status').classes()).toContain('aimd-quiz__grade-status--incorrect')
64
+ expect(wrapper.find('.aimd-quiz__grade-score').classes()).toContain('aimd-quiz__grade-score--incorrect')
65
+ })
66
+
67
+ it('hides the grade panel for unanswered ungraded quizzes', () => {
68
+ const wrapper = mount(AimdQuizRecorder, {
69
+ props: {
70
+ locale: 'en-US',
71
+ quiz: {
72
+ id: 'quiz_single_1',
73
+ type: 'choice',
74
+ stem: 'Pick one',
75
+ score: 2,
76
+ mode: 'single',
77
+ options: [
78
+ { key: 'A', text: 'A' },
79
+ { key: 'B', text: 'B' },
80
+ ],
81
+ },
82
+ modelValue: undefined,
83
+ grade: {
84
+ quiz_id: 'quiz_single_1',
85
+ earned_score: 0,
86
+ max_score: 2,
87
+ status: 'ungraded',
88
+ method: 'manual',
89
+ },
90
+ },
91
+ })
92
+
93
+ expect(wrapper.find('.aimd-quiz__grade-panel').exists()).toBe(false)
94
+ })
95
+
96
+ it('shows selected choice option explanations when enabled', () => {
97
+ const wrapper = mount(AimdQuizRecorder, {
98
+ props: {
99
+ locale: 'en-US',
100
+ quiz: {
101
+ id: 'quiz_single_explained',
102
+ type: 'choice',
103
+ stem: 'Pick one',
104
+ score: 2,
105
+ mode: 'single',
106
+ options: [
107
+ { key: 'A', text: 'Option A', explanation: 'Not the best answer.' },
108
+ { key: 'B', text: 'Option B', explanation: 'Correct because it matches the requirement.' },
109
+ ],
110
+ },
111
+ modelValue: 'B',
112
+ choiceOptionExplanationMode: 'selected',
113
+ },
114
+ })
115
+
116
+ expect(wrapper.text()).toContain('Correct because it matches the requirement.')
117
+ expect(wrapper.text()).not.toContain('Not the best answer.')
118
+ })
119
+
120
+ it('shows selected choice option explanations only after submission when configured', async () => {
121
+ const wrapper = mount(AimdQuizRecorder, {
122
+ props: {
123
+ locale: 'en-US',
124
+ quiz: {
125
+ id: 'quiz_single_submitted',
126
+ type: 'choice',
127
+ stem: 'Pick one',
128
+ score: 2,
129
+ mode: 'single',
130
+ options: [
131
+ { key: 'A', text: 'Option A', explanation: 'Not the best answer.' },
132
+ { key: 'B', text: 'Option B', explanation: 'Correct because it matches the requirement.' },
133
+ ],
134
+ },
135
+ modelValue: 'B',
136
+ choiceOptionExplanationMode: 'submitted',
137
+ submitted: false,
138
+ },
139
+ })
140
+
141
+ expect(wrapper.text()).not.toContain('Correct because it matches the requirement.')
142
+
143
+ await wrapper.setProps({ submitted: true })
144
+
145
+ expect(wrapper.text()).toContain('Correct because it matches the requirement.')
146
+ expect(wrapper.text()).not.toContain('Not the best answer.')
147
+ })
148
+
149
+ it('shows local scale grading only after submission when configured', async () => {
150
+ const wrapper = mount(AimdQuizRecorder, {
151
+ props: {
152
+ locale: 'en-US',
153
+ quiz: {
154
+ id: 'quiz_scale_1',
155
+ type: 'scale',
156
+ title: 'GAD-7',
157
+ stem: 'How often have you been bothered by the following problems?',
158
+ display: 'list',
159
+ items: [
160
+ { key: 's1', stem: 'Feeling nervous' },
161
+ { key: 's2', stem: 'Unable to relax' },
162
+ ],
163
+ options: [
164
+ { key: '0', text: 'Not at all', points: 0 },
165
+ { key: '1', text: 'Several days', points: 1 },
166
+ { key: '2', text: 'More than half the days', points: 2 },
167
+ ],
168
+ grading: {
169
+ strategy: 'sum',
170
+ bands: [
171
+ { min: 0, max: 1, label: 'Low' },
172
+ { min: 2, max: 4, label: 'Moderate', interpretation: 'Consider follow-up.' },
173
+ ],
174
+ },
175
+ },
176
+ modelValue: {
177
+ s1: '1',
178
+ s2: '2',
179
+ },
180
+ scaleGradeDisplayMode: 'submitted',
181
+ submitted: false,
182
+ },
183
+ })
184
+
185
+ expect(wrapper.text()).not.toContain('Score: 3 / 4')
186
+ expect(wrapper.text()).not.toContain('Moderate')
187
+
188
+ await wrapper.setProps({ submitted: true })
189
+
190
+ expect(wrapper.text()).toContain('Scored')
191
+ expect(wrapper.text()).toContain('Score: 3 / 4')
192
+ expect(wrapper.text()).toContain('Classification: Moderate')
193
+ expect(wrapper.text()).toContain('Interpretation: Consider follow-up.')
194
+ })
195
+ })
@@ -0,0 +1,172 @@
1
+ import { mount } from '@vue/test-utils'
2
+ import { defineComponent, h, nextTick } from 'vue'
3
+ import { describe, expect, it, vi } from 'vitest'
4
+
5
+ vi.mock('@airalogy/aimd-editor/vue', () => ({
6
+ AimdEditor: defineComponent({
7
+ name: 'AimdEditorMock',
8
+ props: {
9
+ modelValue: {
10
+ type: String,
11
+ default: '',
12
+ },
13
+ mode: {
14
+ type: String,
15
+ default: 'source',
16
+ },
17
+ },
18
+ emits: ['update:modelValue', 'update:mode', 'ready'],
19
+ setup(props, { emit }) {
20
+ return () => h('textarea', {
21
+ class: 'aimd-editor-mock',
22
+ value: props.modelValue,
23
+ 'data-mode': props.mode,
24
+ onInput: (event: Event) => emit('update:modelValue', (event.target as HTMLTextAreaElement).value),
25
+ })
26
+ },
27
+ }),
28
+ }))
29
+
30
+ vi.mock('../components/AimdRecorder.vue', () => ({
31
+ default: defineComponent({
32
+ name: 'AimdRecorderMock',
33
+ props: {
34
+ content: {
35
+ type: String,
36
+ default: '',
37
+ },
38
+ },
39
+ setup(props) {
40
+ return () => h('div', {
41
+ class: 'aimd-recorder-mock',
42
+ 'data-content': props.content,
43
+ })
44
+ },
45
+ }),
46
+ }))
47
+
48
+ vi.mock('../components/AimdRecorderWysiwygSurface.vue', () => ({
49
+ default: defineComponent({
50
+ name: 'AimdRecorderWysiwygSurfaceMock',
51
+ props: {
52
+ content: {
53
+ type: String,
54
+ default: '',
55
+ },
56
+ },
57
+ emits: ['update:content'],
58
+ setup(props) {
59
+ return () => h('div', {
60
+ class: 'aimd-recorder-wysiwyg-surface-mock',
61
+ 'data-content': props.content,
62
+ })
63
+ },
64
+ }),
65
+ }))
66
+
67
+ import AimdRecorderEditor from '../components/AimdRecorderEditor.vue'
68
+
69
+ async function flushUi() {
70
+ await Promise.resolve()
71
+ await nextTick()
72
+ }
73
+
74
+ describe('AimdRecorderEditor content sync', () => {
75
+ it('keeps the source editor on the latest local draft while parent content echoes catch up', async () => {
76
+ const wrapper = mount(AimdRecorderEditor, {
77
+ props: {
78
+ content: '',
79
+ locale: 'en-US',
80
+ },
81
+ })
82
+
83
+ const sourceEditor = () => wrapper.find('.aimd-editor-mock')
84
+
85
+ await sourceEditor().setValue('a')
86
+ await flushUi()
87
+ await sourceEditor().setValue('ab')
88
+ await flushUi()
89
+
90
+ expect((sourceEditor().element as HTMLTextAreaElement).value).toBe('ab')
91
+ expect(wrapper.emitted('update:content')?.map(event => event[0])).toEqual(['a', 'ab'])
92
+
93
+ await wrapper.setProps({ content: 'a' })
94
+ await flushUi()
95
+ expect((sourceEditor().element as HTMLTextAreaElement).value).toBe('ab')
96
+
97
+ await wrapper.setProps({ content: 'ab' })
98
+ await flushUi()
99
+ expect((sourceEditor().element as HTMLTextAreaElement).value).toBe('ab')
100
+ expect(wrapper.find('.aimd-recorder-mock').attributes('data-content')).toBe('ab')
101
+ })
102
+
103
+ it('debounces source-to-visual syncing so the recorder-aware WYSIWYG does not rebuild on every keystroke', async () => {
104
+ vi.useFakeTimers()
105
+
106
+ try {
107
+ const wrapper = mount(AimdRecorderEditor, {
108
+ props: {
109
+ content: '',
110
+ locale: 'en-US',
111
+ initialVisualEditMode: true,
112
+ },
113
+ })
114
+
115
+ const sourceEditor = () => wrapper.find('.aimd-editor-mock')
116
+ const visualSurface = () => wrapper.find('.aimd-recorder-wysiwyg-surface-mock')
117
+
118
+ expect(visualSurface().attributes('data-content')).toBe('')
119
+
120
+ await sourceEditor().setValue('a')
121
+ await flushUi()
122
+ expect(visualSurface().attributes('data-content')).toBe('')
123
+
124
+ await sourceEditor().setValue('ab')
125
+ await flushUi()
126
+ expect(visualSurface().attributes('data-content')).toBe('')
127
+
128
+ await vi.advanceTimersByTimeAsync(120)
129
+ await flushUi()
130
+
131
+ expect(visualSurface().attributes('data-content')).toBe('ab')
132
+ } finally {
133
+ vi.useRealTimers()
134
+ }
135
+ })
136
+
137
+ it('ignores stale visual echoes while the source editor is the active content surface', async () => {
138
+ vi.useFakeTimers()
139
+
140
+ try {
141
+ const wrapper = mount(AimdRecorderEditor, {
142
+ attachTo: document.body,
143
+ props: {
144
+ content: '',
145
+ locale: 'en-US',
146
+ initialVisualEditMode: true,
147
+ },
148
+ })
149
+
150
+ const sourceEditor = () => wrapper.find('.aimd-editor-mock')
151
+ const visualSurface = () => wrapper.findComponent({ name: 'AimdRecorderWysiwygSurfaceMock' })
152
+
153
+ await sourceEditor().trigger('focusin')
154
+ await sourceEditor().setValue('a')
155
+ await flushUi()
156
+ await sourceEditor().setValue('ab')
157
+ await flushUi()
158
+
159
+ await visualSurface().vm.$emit('update:content', 'a')
160
+ await flushUi()
161
+
162
+ expect((sourceEditor().element as HTMLTextAreaElement).value).toBe('ab')
163
+ expect(wrapper.emitted('update:content')?.map(event => event[0])).toEqual(['a', 'ab'])
164
+
165
+ await vi.advanceTimersByTimeAsync(120)
166
+ await flushUi()
167
+ expect(visualSurface().attributes('data-content')).toBe('ab')
168
+ } finally {
169
+ vi.useRealTimers()
170
+ }
171
+ })
172
+ })
@@ -0,0 +1,143 @@
1
+ import { readFileSync } from 'node:fs'
2
+ import { dirname, resolve } from 'node:path'
3
+ import { fileURLToPath } from 'node:url'
4
+ import { describe, expect, it } from 'vitest'
5
+
6
+ const __filename = fileURLToPath(import.meta.url)
7
+ const __dirname = dirname(__filename)
8
+ const source = readFileSync(resolve(__dirname, '../components/AimdRecorderEditor.vue'), 'utf8')
9
+ const wysiwygSurfaceSource = readFileSync(resolve(__dirname, '../components/AimdRecorderWysiwygSurface.vue'), 'utf8')
10
+ const recorderMilkdownSource = readFileSync(resolve(__dirname, '../components/recorderMilkdownPlugin.ts'), 'utf8')
11
+ const componentExports = readFileSync(resolve(__dirname, '../components/index.ts'), 'utf8')
12
+ const rootExports = readFileSync(resolve(__dirname, '../index.ts'), 'utf8')
13
+
14
+ describe('AimdRecorderEditor', () => {
15
+ it('combines the package editor and recorder around the same content and record models', () => {
16
+ expect(source).toMatch(/import \{ AimdEditor \} from '@airalogy\/aimd-editor\/vue'/)
17
+ expect(source).toMatch(/import AimdRecorder from '\.\/AimdRecorder\.vue'/)
18
+ expect(source).toMatch(/const contentDraft = ref\(props\.content \|\| ''\)/)
19
+ expect(source).toMatch(/const visualContentDraft = ref\(props\.content \|\| ''\)/)
20
+ expect(source).toMatch(/const activeContentSurface = ref<'source' \| 'visual' \| null>\(null\)/)
21
+ expect(source).toMatch(/const VISUAL_CONTENT_SYNC_DELAY_MS = 120/)
22
+ expect(source).toMatch(/trackRecentSourceDraft\(value\)/)
23
+ expect(source).toMatch(/recentVisualProgrammaticValues\.has\(value\)/)
24
+ expect(source).toMatch(/recentSourceDraftValues\.has\(value\)/)
25
+ expect(source).toMatch(/function handleEditorContentUpdate\(value: string\) \{\s*activeContentSurface\.value = 'source'/)
26
+ expect(source).toMatch(/function handleVisualContentUpdate\(value: string\) \{/)
27
+ expect(source).toMatch(/activeContentSurface\.value = 'visual'/)
28
+ expect(source).toMatch(/function handleSourceSurfaceFocusIn\(\)/)
29
+ expect(source).toMatch(/function handleVisualSurfaceFocusIn\(\)/)
30
+ expect(source).toMatch(/function handleContentSurfaceFocusOut\(/)
31
+ expect(source).toMatch(/scheduleVisualContentSync/)
32
+ expect(source).toMatch(/function syncContentDraftFromProp\(value: string \| undefined\)/)
33
+ expect(source).toMatch(/pendingContentEchoes: string\[\] = \[\]/)
34
+ expect(source).toMatch(/emit\('update:modelValue', value\)/)
35
+ expect(source).toMatch(/emit\('update:editorMode', \$event\)/)
36
+ expect(source).toMatch(/<AimdEditor/)
37
+ expect(source).toMatch(/<AimdRecorder/)
38
+ })
39
+
40
+ it('surfaces detached record values after protocol structure changes so users can migrate data into new fields', () => {
41
+ expect(source).toMatch(/function collectDetachedRecordData\(/)
42
+ expect(source).toMatch(/showDetachedData/)
43
+ expect(source).toMatch(/hasDetachedData/)
44
+ expect(source).toMatch(/detachedDataDescriptionLabel/)
45
+ expect(source).toMatch(/detachedRecordJson/)
46
+ })
47
+
48
+ it('includes a structure editor for adding, deleting, retagging, and dragging recorder fields', () => {
49
+ expect(source).toMatch(/showFieldStructure/)
50
+ expect(source).toMatch(/showFieldStructure: false/)
51
+ expect(source).toMatch(/scanWorkbenchFields/)
52
+ expect(source).toMatch(/handleAddField/)
53
+ expect(source).toMatch(/handleDeleteField/)
54
+ expect(source).toMatch(/handleFieldKindCommit/)
55
+ expect(source).toMatch(/handleFieldIdCommit/)
56
+ expect(source).toMatch(/handleFieldDragStart/)
57
+ expect(source).toMatch(/handleFieldDrop/)
58
+ expect(source).toMatch(/aimd-recorder-workbench__field-list/)
59
+ expect(source).toMatch(/draggable="!readonly"/)
60
+ })
61
+
62
+ it('keeps recorder-side helper panels in a tabbed workspace instead of only rendering them below the main layout', () => {
63
+ expect(source).toMatch(/type WorkbenchSideTab = 'recorder' \| 'structure' \| 'record' \| 'detached'/)
64
+ expect(source).toMatch(/const activeSideTab = ref<WorkbenchSideTab>\('recorder'\)/)
65
+ expect(source).toMatch(/const sideTabs = computed\(\(\) =>/)
66
+ expect(source).toMatch(/const sidePanelBodyStyle = computed\(\(\) => \(\{/)
67
+ expect(source).toMatch(/aimd-recorder-workbench__side-tabs/)
68
+ expect(source).toMatch(/aimd-recorder-workbench__side-tab--active/)
69
+ expect(source).toMatch(/aimd-recorder-workbench__panel-body--recorder \{[\s\S]*overflow: auto;/)
70
+ })
71
+
72
+ it('can fit both columns to the remaining viewport height while still exposing a fixed-height opt-out', () => {
73
+ expect(source).toMatch(/fitViewport\?: boolean/)
74
+ expect(source).toMatch(/viewportOffset\?: number/)
75
+ expect(source).toMatch(/fitViewport: true/)
76
+ expect(source).toMatch(/viewportOffset: 24/)
77
+ expect(source).toMatch(/function getViewportHeight\(\)/)
78
+ expect(source).toMatch(/return window\.visualViewport\?\.height \?\? window\.innerHeight/)
79
+ expect(source).toMatch(/function updateViewportPanelHeights\(/)
80
+ expect(source).toMatch(/const viewportVisualEditorMinHeight = ref/)
81
+ expect(source).toMatch(/const recorderToolbarHeight = getElementHeight\(recorderToolbarRef\.value\)/)
82
+ expect(source).toMatch(/const visualEditorToolbarHeight = getElementHeight\(sidePanelBodyRef\.value\?\.querySelector\('\.aimd-editor-toolbar'\)\)/)
83
+ expect(source).toMatch(/workbenchRef\.value\?\.getBoundingClientRect\(\)\.top/)
84
+ expect(source).toMatch(/window\.addEventListener\('resize', scheduleViewportPanelHeights/)
85
+ })
86
+
87
+ it('supports recorder-side visual editing so field controls can be changed around live recorder widgets', () => {
88
+ expect(source).toMatch(/visualEditMode/)
89
+ expect(source).toMatch(/import AimdRecorderWysiwygSurface from '\.\/AimdRecorderWysiwygSurface\.vue'/)
90
+ expect(source).toMatch(/renderVisualEditWrapper/)
91
+ expect(source).toMatch(/renderVisualInsertEntry/)
92
+ expect(source).toMatch(/showVisualEditToggle/)
93
+ expect(source).toMatch(/initialVisualEditMode/)
94
+ expect(source).toMatch(/activeFieldEditor/)
95
+ expect(source).toMatch(/fieldEditorRawDraft/)
96
+ expect(source).toMatch(/aimd-recorder-workbench__visual-toggle/)
97
+ expect(source).toMatch(/aimd-recorder-workbench__panel-body--visual-editor/)
98
+ expect(source).toMatch(/@edit-field="handleVisualFieldEdit"/)
99
+ expect(source).toMatch(/@delete-field="handleVisualFieldDelete"/)
100
+ expect(source).toMatch(/AimdRecorderWysiwygSurface/)
101
+ expect(source).toMatch(/aimd-recorder-workbench__dialog/)
102
+ expect(source).toMatch(/WYSIWYG AIMD editor|所见即所得编辑器/)
103
+ })
104
+
105
+ it('reuses base AIMD parsing while overriding recorder-editable node views with real recorder widgets', () => {
106
+ expect(wysiwygSurfaceSource).not.toMatch(/aimdMilkdownPlugins/)
107
+ expect(wysiwygSurfaceSource).toMatch(/\.\.\.createRecorderMilkdownPlugins\(/)
108
+ expect(recorderMilkdownSource).toMatch(/aimdRemarkPlugin/)
109
+ expect(recorderMilkdownSource).toMatch(/aimdFieldNode/)
110
+ expect(recorderMilkdownSource).toMatch(/aimdFieldInputRule/)
111
+ expect(recorderMilkdownSource).toMatch(/RECORDER_EDITABLE_INLINE_FIELD_TYPES = new Set\(\['var', 'var_table', 'step', 'check'\]\)/)
112
+ expect(recorderMilkdownSource).toMatch(/RECORDER_QUIZ_MDAST_TYPE = 'aimdRecorderQuizBlock'/)
113
+ expect(recorderMilkdownSource).toMatch(/dropCursor/)
114
+ expect(recorderMilkdownSource).toMatch(/class: 'aimd-recorder-dropcursor'/)
115
+ expect(recorderMilkdownSource).toMatch(/new RecorderWidgetNodeView\(node, view, getPos, options, false\)/)
116
+ expect(recorderMilkdownSource).toMatch(/new AimdFieldChipNodeView\(node, view, getPos\)/)
117
+ expect(recorderMilkdownSource).toMatch(/setAttribute\('data-drag-handle', 'true'\)/)
118
+ expect(recorderMilkdownSource).toMatch(/if \(this\.dragHandleEl\?\.contains\(target\)\) \{\s*return false\s*\}/)
119
+ expect(recorderMilkdownSource).toMatch(/state\.addNode\('code', undefined, String\(node\.attrs\.fieldContent \|\| ''\), \{ lang: 'quiz' \}\)/)
120
+ expect(wysiwygSurfaceSource).toMatch(/--aimd-recorder-drop-label/)
121
+ expect(wysiwygSurfaceSource).toMatch(/\.aimd-recorder-dropcursor/)
122
+ expect(wysiwygSurfaceSource).toMatch(/:global\(\.aimd-recorder-dropcursor/)
123
+ expect(wysiwygSurfaceSource).toMatch(/\.aimd-editor-wysiwyg-mode\) \{\s*position: relative;/)
124
+ expect(wysiwygSurfaceSource).toMatch(/Drop here|拖到这里/)
125
+ })
126
+
127
+ it('can disable raw AIMD snippet editing inside the recorder-side field dialog', () => {
128
+ expect(source).toMatch(/allowRawFieldSourceEditing\?: boolean/)
129
+ expect(source).toMatch(/allowRawFieldSourceEditing: true/)
130
+ expect(source).toMatch(/if \(!props\.allowRawFieldSourceEditing \|\| !activeFieldEditor\.value\)/)
131
+ expect(source).toMatch(/v-if="allowRawFieldSourceEditing"/)
132
+ })
133
+
134
+ it('re-exposes manual client assigner controls from the inner recorder', () => {
135
+ expect(source).toMatch(/runClientAssigner: \(id: string\) => recorderRef\.value\?\.runClientAssigner\(id\)/)
136
+ expect(source).toMatch(/runManualClientAssigners: \(\) => recorderRef\.value\?\.runManualClientAssigners\(\)/)
137
+ })
138
+
139
+ it('is exported from both the component entry and the root package entry', () => {
140
+ expect(componentExports).toMatch(/AimdRecorderEditor/)
141
+ expect(rootExports).toMatch(/AimdRecorderEditor/)
142
+ })
143
+ })