@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,424 @@
1
+ import { afterEach, describe, expect, it, vi } from 'vitest'
2
+
3
+ import {
4
+ normalizeVarTypeName,
5
+ getVarInputKind,
6
+ unwrapStructuredValue,
7
+ toBooleanValue,
8
+ toDateValue,
9
+ formatDateTimeWithTimezone,
10
+ normalizeDateTimeValueWithTimezone,
11
+ formatDateForInput,
12
+ getVarInputDisplayValue,
13
+ parseVarInputValue,
14
+ calculateVarStackWidth,
15
+ syncAutoWrapTextareaHeight,
16
+ } from '../useVarHelpers'
17
+
18
+ // ---------------------------------------------------------------------------
19
+ // normalizeVarTypeName
20
+ // ---------------------------------------------------------------------------
21
+
22
+ describe('normalizeVarTypeName', () => {
23
+ it('defaults to str for undefined', () => {
24
+ expect(normalizeVarTypeName(undefined)).toBe('str')
25
+ })
26
+
27
+ it('defaults to str for empty string', () => {
28
+ expect(normalizeVarTypeName('')).toBe('str')
29
+ })
30
+
31
+ it('lowercases', () => {
32
+ expect(normalizeVarTypeName('Float')).toBe('float')
33
+ })
34
+
35
+ it('removes spaces, underscores, hyphens', () => {
36
+ expect(normalizeVarTypeName('dna_sequence')).toBe('dnasequence')
37
+ expect(normalizeVarTypeName('dna-sequence')).toBe('dnasequence')
38
+ expect(normalizeVarTypeName('dna sequence')).toBe('dnasequence')
39
+ })
40
+
41
+ it('trims whitespace', () => {
42
+ expect(normalizeVarTypeName(' int ')).toBe('int')
43
+ })
44
+ })
45
+
46
+ // ---------------------------------------------------------------------------
47
+ // getVarInputKind
48
+ // ---------------------------------------------------------------------------
49
+
50
+ describe('getVarInputKind', () => {
51
+ it('returns "text" for undefined', () => {
52
+ expect(getVarInputKind(undefined)).toBe('text')
53
+ })
54
+
55
+ it('returns "text" for str', () => {
56
+ expect(getVarInputKind('str')).toBe('text')
57
+ })
58
+
59
+ it('returns "number" for numeric types', () => {
60
+ expect(getVarInputKind('float')).toBe('number')
61
+ expect(getVarInputKind('int')).toBe('number')
62
+ expect(getVarInputKind('integer')).toBe('number')
63
+ expect(getVarInputKind('number')).toBe('number')
64
+ })
65
+
66
+ it('returns "checkbox" for boolean types', () => {
67
+ expect(getVarInputKind('bool')).toBe('checkbox')
68
+ expect(getVarInputKind('boolean')).toBe('checkbox')
69
+ expect(getVarInputKind('checkbox')).toBe('checkbox')
70
+ })
71
+
72
+ it('returns "date" for date', () => {
73
+ expect(getVarInputKind('date')).toBe('date')
74
+ })
75
+
76
+ it('returns "datetime" for datetime types', () => {
77
+ expect(getVarInputKind('datetime')).toBe('datetime')
78
+ expect(getVarInputKind('currenttime')).toBe('datetime')
79
+ })
80
+
81
+ it('returns "time" for time types', () => {
82
+ expect(getVarInputKind('time')).toBe('time')
83
+ expect(getVarInputKind('duration')).toBe('time')
84
+ })
85
+
86
+ it('returns "dna" for dna_sequence', () => {
87
+ expect(getVarInputKind('dna_sequence')).toBe('dna')
88
+ })
89
+
90
+ it('returns "textarea" for markdown types', () => {
91
+ expect(getVarInputKind('md')).toBe('textarea')
92
+ expect(getVarInputKind('markdown')).toBe('textarea')
93
+ expect(getVarInputKind('airalogymarkdown')).toBe('textarea')
94
+ })
95
+
96
+ it('returns "code" for built-in CodeStr aliases', () => {
97
+ expect(getVarInputKind('PyStr')).toBe('code')
98
+ expect(getVarInputKind('JsStr')).toBe('code')
99
+ expect(getVarInputKind('TsStr')).toBe('code')
100
+ expect(getVarInputKind('JsonStr')).toBe('code')
101
+ expect(getVarInputKind('YamlStr')).toBe('code')
102
+ expect(getVarInputKind('TomlStr')).toBe('code')
103
+ expect(getVarInputKind('CodeStr')).toBe('code')
104
+ })
105
+
106
+ it('returns "code" when field metadata forces a code editor language', () => {
107
+ expect(getVarInputKind('str', { inputType: 'code', codeLanguage: 'python' })).toBe('code')
108
+ expect(getVarInputKind('str', { inputType: 'yaml' })).toBe('code')
109
+ expect(getVarInputKind('str', { codeLanguage: 'sql' })).toBe('code')
110
+ })
111
+ })
112
+
113
+ // ---------------------------------------------------------------------------
114
+ // unwrapStructuredValue
115
+ // ---------------------------------------------------------------------------
116
+
117
+ describe('unwrapStructuredValue', () => {
118
+ it('unwraps { value: x }', () => {
119
+ expect(unwrapStructuredValue({ value: 42 })).toBe(42)
120
+ })
121
+
122
+ it('passes through non-structured', () => {
123
+ expect(unwrapStructuredValue('hello')).toBe('hello')
124
+ expect(unwrapStructuredValue(42)).toBe(42)
125
+ expect(unwrapStructuredValue(null)).toBe(null)
126
+ })
127
+
128
+ it('passes through arrays', () => {
129
+ expect(unwrapStructuredValue([1, 2])).toEqual([1, 2])
130
+ })
131
+
132
+ it('passes through objects without value key', () => {
133
+ expect(unwrapStructuredValue({ name: 'test' })).toEqual({ name: 'test' })
134
+ })
135
+ })
136
+
137
+ // ---------------------------------------------------------------------------
138
+ // toBooleanValue
139
+ // ---------------------------------------------------------------------------
140
+
141
+ describe('toBooleanValue', () => {
142
+ it('handles boolean values', () => {
143
+ expect(toBooleanValue(true)).toBe(true)
144
+ expect(toBooleanValue(false)).toBe(false)
145
+ })
146
+
147
+ it('handles numeric values', () => {
148
+ expect(toBooleanValue(1)).toBe(true)
149
+ expect(toBooleanValue(0)).toBe(false)
150
+ expect(toBooleanValue(42)).toBe(true)
151
+ })
152
+
153
+ it('handles string truthy values', () => {
154
+ expect(toBooleanValue('true')).toBe(true)
155
+ expect(toBooleanValue('1')).toBe(true)
156
+ expect(toBooleanValue('yes')).toBe(true)
157
+ expect(toBooleanValue('on')).toBe(true)
158
+ })
159
+
160
+ it('handles string falsy values', () => {
161
+ expect(toBooleanValue('false')).toBe(false)
162
+ expect(toBooleanValue('0')).toBe(false)
163
+ expect(toBooleanValue('no')).toBe(false)
164
+ expect(toBooleanValue('off')).toBe(false)
165
+ expect(toBooleanValue('')).toBe(false)
166
+ })
167
+
168
+ it('is case-insensitive', () => {
169
+ expect(toBooleanValue('TRUE')).toBe(true)
170
+ expect(toBooleanValue('False')).toBe(false)
171
+ })
172
+
173
+ it('unwraps structured values', () => {
174
+ expect(toBooleanValue({ value: true })).toBe(true)
175
+ expect(toBooleanValue({ value: 'false' })).toBe(false)
176
+ })
177
+
178
+ it('handles null/undefined', () => {
179
+ expect(toBooleanValue(null)).toBe(false)
180
+ expect(toBooleanValue(undefined)).toBe(false)
181
+ })
182
+ })
183
+
184
+ // ---------------------------------------------------------------------------
185
+ // toDateValue
186
+ // ---------------------------------------------------------------------------
187
+
188
+ describe('toDateValue', () => {
189
+ it('returns null for null/undefined', () => {
190
+ expect(toDateValue(null)).toBe(null)
191
+ expect(toDateValue(undefined)).toBe(null)
192
+ })
193
+
194
+ it('returns null for empty string', () => {
195
+ expect(toDateValue('')).toBe(null)
196
+ })
197
+
198
+ it('parses ISO date string', () => {
199
+ const date = toDateValue('2024-01-15')
200
+ expect(date).toBeInstanceOf(Date)
201
+ expect(date!.getFullYear()).toBe(2024)
202
+ })
203
+
204
+ it('parses timestamp number', () => {
205
+ const timestamp = new Date('2024-06-15').getTime()
206
+ const date = toDateValue(timestamp)
207
+ expect(date).toBeInstanceOf(Date)
208
+ })
209
+
210
+ it('returns null for invalid date string', () => {
211
+ expect(toDateValue('not-a-date')).toBe(null)
212
+ })
213
+
214
+ it('returns Date as-is if valid', () => {
215
+ const d = new Date('2024-01-01')
216
+ expect(toDateValue(d)).toBe(d)
217
+ })
218
+
219
+ it('returns null for invalid Date object', () => {
220
+ expect(toDateValue(new Date('invalid'))).toBe(null)
221
+ })
222
+
223
+ it('unwraps structured values', () => {
224
+ const date = toDateValue({ value: '2024-06-15' })
225
+ expect(date).toBeInstanceOf(Date)
226
+ })
227
+ })
228
+
229
+ // ---------------------------------------------------------------------------
230
+ // formatDateTimeWithTimezone
231
+ // ---------------------------------------------------------------------------
232
+
233
+ describe('formatDateTimeWithTimezone', () => {
234
+ it('formats date with timezone offset', () => {
235
+ const date = new Date('2024-06-15T10:30:00')
236
+ const result = formatDateTimeWithTimezone(date)
237
+ expect(result).toMatch(/^2024-06-15T10:30[+-]\d{2}:\d{2}$/)
238
+ })
239
+ })
240
+
241
+ // ---------------------------------------------------------------------------
242
+ // normalizeDateTimeValueWithTimezone
243
+ // ---------------------------------------------------------------------------
244
+
245
+ describe('normalizeDateTimeValueWithTimezone', () => {
246
+ it('returns empty string for empty input', () => {
247
+ expect(normalizeDateTimeValueWithTimezone('')).toBe('')
248
+ })
249
+
250
+ it('returns empty string for null', () => {
251
+ expect(normalizeDateTimeValueWithTimezone(null)).toBe('')
252
+ })
253
+
254
+ it('passes through valid ISO datetime', () => {
255
+ const iso = '2024-06-15T10:30:00+08:00'
256
+ expect(normalizeDateTimeValueWithTimezone(iso)).toBe(iso)
257
+ })
258
+
259
+ it('normalizes space-separated datetime', () => {
260
+ const result = normalizeDateTimeValueWithTimezone('2024-06-15 10:30:00+08:00')
261
+ expect(result).toBe('2024-06-15T10:30:00+08:00')
262
+ })
263
+ })
264
+
265
+ // ---------------------------------------------------------------------------
266
+ // formatDateForInput
267
+ // ---------------------------------------------------------------------------
268
+
269
+ describe('formatDateForInput', () => {
270
+ it('formats date kind', () => {
271
+ expect(formatDateForInput('2024-06-15T10:30:00', 'date')).toBe('2024-06-15')
272
+ })
273
+
274
+ it('formats datetime kind', () => {
275
+ expect(formatDateForInput('2024-06-15T10:30:00', 'datetime')).toBe('2024-06-15T10:30')
276
+ })
277
+
278
+ it('formats time kind', () => {
279
+ expect(formatDateForInput('14:30:00', 'time')).toBe('14:30:00')
280
+ })
281
+
282
+ it('returns empty string for empty value', () => {
283
+ expect(formatDateForInput('', 'date')).toBe('')
284
+ expect(formatDateForInput(null, 'date')).toBe('')
285
+ })
286
+ })
287
+
288
+ // ---------------------------------------------------------------------------
289
+ // getVarInputDisplayValue
290
+ // ---------------------------------------------------------------------------
291
+
292
+ describe('getVarInputDisplayValue', () => {
293
+ it('returns string values as-is for text kind', () => {
294
+ expect(getVarInputDisplayValue('hello', 'text')).toBe('hello')
295
+ })
296
+
297
+ it('returns number for number kind', () => {
298
+ expect(getVarInputDisplayValue(42, 'number')).toBe(42)
299
+ })
300
+
301
+ it('returns string number for number kind', () => {
302
+ expect(getVarInputDisplayValue('3.14', 'number')).toBe('3.14')
303
+ })
304
+
305
+ it('returns empty string for null/undefined', () => {
306
+ expect(getVarInputDisplayValue(null, 'text')).toBe('')
307
+ expect(getVarInputDisplayValue(undefined, 'text')).toBe('')
308
+ })
309
+
310
+ it('unwraps structured values', () => {
311
+ expect(getVarInputDisplayValue({ value: 'wrapped' }, 'text')).toBe('wrapped')
312
+ })
313
+
314
+ it('stringifies non-string for dna kind', () => {
315
+ expect(getVarInputDisplayValue({ seq: 'ATCG' }, 'dna')).toBe(JSON.stringify({ seq: 'ATCG' }))
316
+ })
317
+ })
318
+
319
+ // ---------------------------------------------------------------------------
320
+ // parseVarInputValue
321
+ // ---------------------------------------------------------------------------
322
+
323
+ describe('parseVarInputValue', () => {
324
+ it('returns string for text type', () => {
325
+ expect(parseVarInputValue('hello', 'str', 'text')).toBe('hello')
326
+ })
327
+
328
+ it('parses integer', () => {
329
+ expect(parseVarInputValue('42', 'int', 'number')).toBe(42)
330
+ })
331
+
332
+ it('parses float', () => {
333
+ expect(parseVarInputValue('3.14', 'float', 'number')).toBeCloseTo(3.14)
334
+ })
335
+
336
+ it('returns raw value for invalid number', () => {
337
+ expect(parseVarInputValue('abc', 'int', 'number')).toBe('abc')
338
+ })
339
+
340
+ it('returns empty string for empty number input', () => {
341
+ expect(parseVarInputValue('', 'int', 'number')).toBe('')
342
+ })
343
+
344
+ it('normalizes datetime input', () => {
345
+ const result = parseVarInputValue('2024-06-15T10:30', undefined, 'datetime')
346
+ expect(typeof result).toBe('string')
347
+ })
348
+ })
349
+
350
+ // ---------------------------------------------------------------------------
351
+ // calculateVarStackWidth
352
+ // ---------------------------------------------------------------------------
353
+
354
+ describe('calculateVarStackWidth', () => {
355
+ it('returns pixel value', () => {
356
+ const result = calculateVarStackWidth('temperature', 'text')
357
+ expect(result).toMatch(/^\d+px$/)
358
+ })
359
+
360
+ it('respects minimum width for textarea', () => {
361
+ const result = calculateVarStackWidth('x', 'textarea')
362
+ const px = parseInt(result)
363
+ expect(px).toBeGreaterThanOrEqual(160)
364
+ })
365
+
366
+ it('respects minimum width for dna', () => {
367
+ const result = calculateVarStackWidth('x', 'dna')
368
+ const px = parseInt(result)
369
+ expect(px).toBeGreaterThanOrEqual(160)
370
+ })
371
+ })
372
+
373
+ // ---------------------------------------------------------------------------
374
+ // syncAutoWrapTextareaHeight
375
+ // ---------------------------------------------------------------------------
376
+
377
+ describe('syncAutoWrapTextareaHeight', () => {
378
+ afterEach(() => {
379
+ vi.restoreAllMocks()
380
+ document.body.innerHTML = ''
381
+ })
382
+
383
+ it('keeps compact textareas at the single-line control height when empty', () => {
384
+ const textarea = document.createElement('textarea')
385
+ textarea.className = 'aimd-rec-inline__textarea--stacked-text'
386
+ document.body.appendChild(textarea)
387
+
388
+ vi.spyOn(window, 'getComputedStyle').mockImplementation(() => ({
389
+ getPropertyValue: (name: string) => (name === '--rec-var-control-height' ? '30px' : ''),
390
+ height: '30px',
391
+ minHeight: '0px',
392
+ borderTopWidth: '1px',
393
+ borderBottomWidth: '1px',
394
+ } as CSSStyleDeclaration))
395
+
396
+ syncAutoWrapTextareaHeight(textarea)
397
+
398
+ expect(textarea.style.height).toBe('30px')
399
+ })
400
+
401
+ it('grows compact textareas as wrapped content needs more height', () => {
402
+ const textarea = document.createElement('textarea')
403
+ textarea.className = 'aimd-rec-inline__textarea--stacked-text'
404
+ textarea.value = 'sample name that should wrap onto another visual line'
405
+ document.body.appendChild(textarea)
406
+
407
+ Object.defineProperty(textarea, 'scrollHeight', {
408
+ configurable: true,
409
+ get: () => 64,
410
+ })
411
+
412
+ vi.spyOn(window, 'getComputedStyle').mockImplementation(() => ({
413
+ getPropertyValue: (name: string) => (name === '--rec-var-control-height' ? '30px' : ''),
414
+ height: '30px',
415
+ minHeight: '0px',
416
+ borderTopWidth: '1px',
417
+ borderBottomWidth: '1px',
418
+ } as CSSStyleDeclaration))
419
+
420
+ syncAutoWrapTextareaHeight(textarea)
421
+
422
+ expect(textarea.style.height).toBe('66px')
423
+ })
424
+ })
@@ -0,0 +1,97 @@
1
+ import { describe, expect, it } from 'vitest'
2
+ import {
3
+ appendWorkbenchField,
4
+ deleteWorkbenchField,
5
+ generateNextWorkbenchFieldId,
6
+ moveWorkbenchField,
7
+ scanWorkbenchFields,
8
+ updateWorkbenchFieldId,
9
+ updateWorkbenchFieldKind,
10
+ updateWorkbenchVarValueType,
11
+ } from '../workbenchFieldEditing'
12
+
13
+ describe('workbenchFieldEditing', () => {
14
+ it('scans recorder-editable field descriptors from inline AIMD tags and quiz blocks', () => {
15
+ const content = [
16
+ 'Sample: {{var|sample_name: str = "abc", title = "Sample"}}',
17
+ '{{var_table|measurements, subvars=[temp: float, pressure: float]}}',
18
+ '{{step|prepare}}',
19
+ '{{check|done}}',
20
+ '```quiz',
21
+ 'id: quiz_1',
22
+ 'type: choice',
23
+ 'stem: |',
24
+ ' Pick one',
25
+ 'mode: single',
26
+ 'options:',
27
+ ' - key: A',
28
+ ' text: Option A',
29
+ '```',
30
+ ].join('\n')
31
+
32
+ const fields = scanWorkbenchFields(content)
33
+ expect(fields.map(field => field.fieldType)).toEqual(['var', 'var_table', 'step', 'check', 'quiz'])
34
+ expect(fields[0]).toMatchObject({ id: 'sample_name', valueType: 'str' })
35
+ expect(fields[1]).toMatchObject({ id: 'measurements', subvarsText: 'temp, pressure' })
36
+ expect(fields[4]).toMatchObject({ id: 'quiz_1', quizType: 'choice', sourceKind: 'block' })
37
+ })
38
+
39
+ it('updates var ids and var value types without dropping defaults or kwargs', () => {
40
+ const content = 'Sample: {{var|sample_name: str = "abc", title = "Sample"}}'
41
+ const [field] = scanWorkbenchFields(content)
42
+ const nextIdContent = updateWorkbenchFieldId(content, field, 'specimen_name')
43
+ expect(nextIdContent).toContain('{{var|specimen_name: str = "abc", title = "Sample"}}')
44
+
45
+ const nextTypeField = scanWorkbenchFields(nextIdContent)[0]
46
+ const nextTypeContent = updateWorkbenchVarValueType(nextIdContent, nextTypeField, 'float')
47
+ expect(nextTypeContent).toContain('{{var|specimen_name: float = "abc", title = "Sample"}}')
48
+ })
49
+
50
+ it('switches recorder field kinds by rebuilding the source snippet around the current id', () => {
51
+ const content = '{{check|done}}'
52
+ const [field] = scanWorkbenchFields(content)
53
+ const nextContent = updateWorkbenchFieldKind(content, field, 'var')
54
+ expect(nextContent).toContain('{{var|done: str}}')
55
+ })
56
+
57
+ it('updates quiz ids in fenced quiz blocks', () => {
58
+ const content = [
59
+ '```quiz',
60
+ 'id: quiz_1',
61
+ 'type: open',
62
+ 'stem: |',
63
+ ' Explain.',
64
+ '```',
65
+ ].join('\n')
66
+
67
+ const [field] = scanWorkbenchFields(content)
68
+ const nextContent = updateWorkbenchFieldId(content, field, 'quiz_protocol_2')
69
+ expect(nextContent).toContain('id: quiz_protocol_2')
70
+ expect(nextContent).toContain('type: open')
71
+ })
72
+
73
+ it('adds, deletes, and reorders standalone field segments in source order', () => {
74
+ const content = [
75
+ '{{var|alpha: str}}',
76
+ '',
77
+ '{{var|beta: str}}',
78
+ ].join('\n')
79
+
80
+ const appended = appendWorkbenchField(content, 'check', { id: 'done' })
81
+ expect(appended).toContain('{{check|done}}')
82
+
83
+ const appendedFields = scanWorkbenchFields(appended)
84
+ const deleted = deleteWorkbenchField(appended, appendedFields[1])
85
+ expect(deleted).not.toContain('{{var|beta: str}}')
86
+
87
+ const deletedFields = scanWorkbenchFields(deleted)
88
+ const moved = moveWorkbenchField(deleted, deletedFields, deletedFields[1].uid, 0)
89
+ expect(moved.trimStart().startsWith('{{check|done}}')).toBe(true)
90
+ })
91
+
92
+ it('generates non-conflicting default ids for new fields', () => {
93
+ const fields = scanWorkbenchFields('{{var|new_var: str}}\n\n{{var|new_var_2: str}}')
94
+ expect(generateNextWorkbenchFieldId(fields, 'var')).toBe('new_var_3')
95
+ expect(generateNextWorkbenchFieldId(fields, 'step')).toBe('new_step')
96
+ })
97
+ })
@@ -0,0 +1,94 @@
1
+ export { captureFocusSnapshot, restoreFocusSnapshot } from './useFocusManagement'
2
+ export type { FocusSnapshot } from './useFocusManagement'
3
+
4
+ export {
5
+ cloneRecordData,
6
+ normalizeCheckLike,
7
+ normalizeStepLike,
8
+ normalizeIncomingRecord,
9
+ replaceSection,
10
+ applyNormalizedRecord,
11
+ applyIncomingRecord,
12
+ normalizeStepFields,
13
+ normalizeCheckFields,
14
+ normalizeQuizFields,
15
+ normalizeVarTableFields,
16
+ getQuizDefaultValue,
17
+ ensureDefaultsFromFields,
18
+ createEmptyVarTableRow,
19
+ normalizeVarTableRows,
20
+ } from './useRecordState'
21
+
22
+ export {
23
+ createEmptyCheckRecordItem,
24
+ createEmptyStepRecordItem,
25
+ normalizeStepTimerState,
26
+ isStepTimerRunning,
27
+ getStepElapsedMs,
28
+ startStepTimer,
29
+ pauseStepTimer,
30
+ resetStepTimer,
31
+ setStepChecked,
32
+ formatStepDuration,
33
+ resolveStepTimerMode,
34
+ getStepRemainingMs,
35
+ isStepTimerWarning,
36
+ getProtocolEstimatedDurationMs,
37
+ getProtocolRecordedDurationMs,
38
+ hasRecordedStepDuration,
39
+ } from './useStepTimers'
40
+
41
+ export {
42
+ normalizeVarTypeName,
43
+ getVarInputKind,
44
+ unwrapStructuredValue,
45
+ toBooleanValue,
46
+ toDateValue,
47
+ formatDateTimeWithTimezone,
48
+ normalizeDateTimeValueWithTimezone,
49
+ formatDateForInput,
50
+ getVarInputDisplayValue,
51
+ parseVarInputValue,
52
+ calculateVarStackWidth,
53
+ measureVarLabelWidth,
54
+ measureSingleLineControlWidth,
55
+ syncAutoWrapTextareaHeight,
56
+ applyVarStackWidth,
57
+ } from './useVarHelpers'
58
+ export type { VarInputKind } from './useVarHelpers'
59
+
60
+ export {
61
+ AIMD_DNA_SEQUENCE_FORMAT,
62
+ normalizeDnaSequenceText,
63
+ collectInvalidDnaSequenceCharacters,
64
+ createEmptyDnaSequenceAnnotation,
65
+ createEmptyDnaSequenceQualifier,
66
+ createEmptyDnaSequenceSegment,
67
+ getNextDnaSequenceAnnotationId,
68
+ normalizeDnaSequenceAnnotation,
69
+ normalizeDnaSequenceQualifier,
70
+ normalizeDnaSequenceSegment,
71
+ normalizeDnaSequenceValue,
72
+ calculateDnaSequenceGcPercent,
73
+ getDnaSequenceSegmentIssue,
74
+ serializeDnaSequenceToGenBank,
75
+ } from './useDnaSequence'
76
+
77
+ export { useClientAssignerRunner } from './useClientAssignerRunner'
78
+ export type { ClientAssignerRunnerOptions } from './useClientAssignerRunner'
79
+
80
+ export {
81
+ useVarTableDragDrop,
82
+ getVarTableRowKey,
83
+ getVarTableColumns,
84
+ } from './useVarTableDragDrop'
85
+ export type { VarTableDragState, VarTableDragDropOptions } from './useVarTableDragDrop'
86
+
87
+ export { useFieldRendering } from './useFieldRendering'
88
+ export type { VarInputDisplayOverride, FieldRenderingOptions } from './useFieldRendering'
89
+
90
+ export {
91
+ buildAimdRecorderFieldAdapterContext,
92
+ resolveAimdRecorderFieldVNode,
93
+ } from './useFieldAdapters'
94
+ export type { RecorderFieldAdapterResolverOptions } from './useFieldAdapters'
@@ -0,0 +1,74 @@
1
+ import { type Ref } from "vue"
2
+ import type { AimdClientAssignerField } from "@airalogy/aimd-core/types"
3
+ import { applyClientAssigners } from "../client-assigner"
4
+ import type { AimdProtocolRecordData } from "../types"
5
+
6
+ export interface ClientAssignerRunnerOptions {
7
+ readonly: () => boolean
8
+ clientAssigners: Ref<AimdClientAssignerField[]>
9
+ localRecord: AimdProtocolRecordData
10
+ onError: (message: string) => void
11
+ emitRecordUpdate: () => void
12
+ scheduleInlineRebuild: () => void
13
+ }
14
+
15
+ export function useClientAssignerRunner(options: ClientAssignerRunnerOptions) {
16
+ const {
17
+ readonly: isReadonly,
18
+ clientAssigners,
19
+ localRecord,
20
+ onError,
21
+ emitRecordUpdate,
22
+ scheduleInlineRebuild,
23
+ } = options
24
+
25
+ function runClientAssigners(opts?: { triggerIds?: string[] }): boolean {
26
+ if (isReadonly() || clientAssigners.value.length === 0) {
27
+ return false
28
+ }
29
+
30
+ try {
31
+ return applyClientAssigners(clientAssigners.value, localRecord.var, opts).changed
32
+ }
33
+ catch (error) {
34
+ const message = error instanceof Error ? error.message : String(error)
35
+ onError(`Client assigner error: ${message}`)
36
+ return false
37
+ }
38
+ }
39
+
40
+ function applyCurrentClientAssigners(): boolean {
41
+ return runClientAssigners()
42
+ }
43
+
44
+ function triggerClientAssigner(id: string): boolean {
45
+ const changed = runClientAssigners({ triggerIds: [id] })
46
+ if (changed) {
47
+ emitRecordUpdate()
48
+ scheduleInlineRebuild()
49
+ }
50
+ return changed
51
+ }
52
+
53
+ function triggerManualClientAssigners(ids?: string[]): boolean {
54
+ const manualIds = ids?.length
55
+ ? ids
56
+ : clientAssigners.value.filter(assigner => assigner.mode === "manual").map(assigner => assigner.id)
57
+ if (manualIds.length === 0) {
58
+ return false
59
+ }
60
+ const changed = runClientAssigners({ triggerIds: manualIds })
61
+ if (changed) {
62
+ emitRecordUpdate()
63
+ scheduleInlineRebuild()
64
+ }
65
+ return changed
66
+ }
67
+
68
+ return {
69
+ runClientAssigners,
70
+ applyCurrentClientAssigners,
71
+ triggerClientAssigner,
72
+ triggerManualClientAssigners,
73
+ }
74
+ }