@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,983 @@
1
+ <script setup lang="ts">
2
+ import { computed, nextTick, ref, watch } from "vue"
3
+ import type { AimdRecorderMessages } from "../locales"
4
+ import type {
5
+ AimdDnaSequenceAnnotation,
6
+ AimdDnaSequenceQualifier,
7
+ AimdDnaSequenceSegment,
8
+ AimdDnaSequenceValue,
9
+ } from "../types"
10
+ import {
11
+ calculateDnaSequenceGcPercent,
12
+ collectInvalidDnaSequenceCharacters,
13
+ createEmptyDnaSequenceAnnotation,
14
+ createEmptyDnaSequenceQualifier,
15
+ createEmptyDnaSequenceSegment,
16
+ getNextDnaSequenceAnnotationId,
17
+ normalizeDnaSequenceValue,
18
+ } from "../composables/useDnaSequence"
19
+ import {
20
+ buildViewerAnnotationId,
21
+ buildViewerAnnotations,
22
+ createExternalSelectionFromSegment,
23
+ createExternalSelectionFromSelection,
24
+ createSegmentsFromSelection,
25
+ detectImportedName,
26
+ detectImportedTopology,
27
+ downloadGenBankFile,
28
+ formatSegment,
29
+ normalizeImportedSequenceText,
30
+ normalizeViewerSelection,
31
+ parseViewerAnnotationId,
32
+ stripFileExtension,
33
+ } from "../composables/useDnaSequenceField"
34
+ import type {
35
+ DnaEditorMode,
36
+ ViewerExternalSelection,
37
+ ViewerSelection,
38
+ } from "../composables/useDnaSequenceField"
39
+
40
+ import DnaSequenceToolbar from "./DnaSequenceToolbar.vue"
41
+ import DnaSequenceViewer from "./DnaSequenceViewer.vue"
42
+ import DnaSequenceEditor from "./DnaSequenceEditor.vue"
43
+ import DnaAnnotationEditor from "./DnaAnnotationEditor.vue"
44
+
45
+ // ---- Props & Emits (public API — unchanged) ----
46
+
47
+ const props = withDefaults(defineProps<{
48
+ modelValue?: unknown
49
+ varId: string
50
+ disabled?: boolean
51
+ placeholder?: string
52
+ messages: Pick<AimdRecorderMessages, "scope" | "dna">
53
+ }>(), {
54
+ modelValue: undefined,
55
+ disabled: false,
56
+ placeholder: undefined,
57
+ })
58
+
59
+ const emit = defineEmits<{
60
+ (e: "update:modelValue", value: AimdDnaSequenceValue): void
61
+ (e: "blur"): void
62
+ }>()
63
+
64
+ // ---- Core reactive state ----
65
+
66
+ const value = computed(() => normalizeDnaSequenceValue(props.modelValue))
67
+ const sequenceLength = computed(() => value.value.sequence.length)
68
+ const gcPercent = computed(() => calculateDnaSequenceGcPercent(value.value.sequence))
69
+ const invalidCharacters = computed(() => collectInvalidDnaSequenceCharacters(value.value.sequence))
70
+
71
+ const editorMode = ref<DnaEditorMode>("interactive")
72
+ const activeAnnotationId = ref<string | null>(null)
73
+ const activeSegmentIndex = ref(0)
74
+ const selection = ref<ViewerSelection | null>(null)
75
+ const viewerSelection = ref<ViewerExternalSelection | null>(null)
76
+ const interactiveSequenceDraft = ref("")
77
+ const importFileInputRef = ref<HTMLInputElement | null>(null)
78
+ const importErrorMessage = ref<string | null>(null)
79
+ const annotationEditorRef = ref<InstanceType<typeof DnaAnnotationEditor> | null>(null)
80
+
81
+ const isInteractiveMode = computed(() => editorMode.value === "interactive")
82
+ const hasInteractiveSequenceDraft = computed(() => interactiveSequenceDraft.value.trim().length > 0)
83
+
84
+ const activeAnnotationIndex = computed(() =>
85
+ value.value.annotations.findIndex(a => a.id === activeAnnotationId.value))
86
+
87
+ const activeAnnotation = computed(() =>
88
+ activeAnnotationIndex.value >= 0 ? value.value.annotations[activeAnnotationIndex.value] : null)
89
+
90
+ const viewerAnnotations = computed(() =>
91
+ buildViewerAnnotations(value.value.annotations, sequenceLength.value))
92
+
93
+ const selectionSegments = computed(() =>
94
+ createSegmentsFromSelection(selection.value, value.value.topology, sequenceLength.value))
95
+
96
+ const selectionRangeLabel = computed(() => {
97
+ if (selectionSegments.value.length === 0) return ""
98
+ return props.messages.dna.selectionRange(selectionSegments.value.map(formatSegment).join(", "))
99
+ })
100
+
101
+ const selectionTargetLabel = computed(() => {
102
+ if (!selection.value) return ""
103
+ if (selection.value.type === "ANNOTATION" && selection.value.name) {
104
+ return props.messages.dna.selectionTarget(selection.value.name)
105
+ }
106
+ return props.messages.dna.selectionTarget(props.messages.dna.selectionModeSequence)
107
+ })
108
+
109
+ // ---- Value mutation helpers ----
110
+
111
+ function commit(nextValue: unknown) {
112
+ emit("update:modelValue", normalizeDnaSequenceValue(nextValue))
113
+ }
114
+
115
+ function patchValue(patch: Partial<AimdDnaSequenceValue>) {
116
+ commit({ ...value.value, ...patch })
117
+ }
118
+
119
+ function patchAnnotation(index: number, patch: Partial<AimdDnaSequenceAnnotation>) {
120
+ const annotations = value.value.annotations.map((annotation, i) =>
121
+ i === index ? { ...annotation, ...patch } : annotation)
122
+ patchValue({ annotations })
123
+ }
124
+
125
+ function patchSegment(
126
+ annotationIndex: number,
127
+ segmentIndex: number,
128
+ patch: Partial<AimdDnaSequenceSegment>,
129
+ ) {
130
+ const annotation = value.value.annotations[annotationIndex]
131
+ if (!annotation) return
132
+ const segments = annotation.segments.map((s, i) =>
133
+ i === segmentIndex ? { ...s, ...patch } : s)
134
+ patchAnnotation(annotationIndex, { segments })
135
+ }
136
+
137
+ function patchQualifier(
138
+ annotationIndex: number,
139
+ qualifierIndex: number,
140
+ patch: Partial<AimdDnaSequenceQualifier>,
141
+ ) {
142
+ const annotation = value.value.annotations[annotationIndex]
143
+ if (!annotation) return
144
+ const qualifiers = annotation.qualifiers.map((q, i) =>
145
+ i === qualifierIndex ? { ...q, ...patch } : q)
146
+ patchAnnotation(annotationIndex, { qualifiers })
147
+ }
148
+
149
+ // ---- Selection helpers ----
150
+
151
+ function clearSelection() {
152
+ selection.value = null
153
+ viewerSelection.value = null
154
+ }
155
+
156
+ function selectAnnotation(annotationId: string, segmentIndex = 0) {
157
+ const annotation = value.value.annotations.find(a => a.id === annotationId)
158
+ const segment = annotation?.segments[segmentIndex]
159
+ if (!annotation || !segment) return
160
+
161
+ activeAnnotationId.value = annotationId
162
+ activeSegmentIndex.value = segmentIndex
163
+ selection.value = {
164
+ type: "ANNOTATION",
165
+ id: buildViewerAnnotationId(annotationId, segmentIndex),
166
+ name: annotation.name,
167
+ start: Math.max(segment.start - 1, 0),
168
+ end: segment.end,
169
+ length: Math.max(segment.end - segment.start + 1, 0),
170
+ direction: annotation.strand,
171
+ viewer: value.value.topology === "circular" ? "CIRCULAR" : "LINEAR",
172
+ }
173
+ viewerSelection.value = createExternalSelectionFromSegment(segment)
174
+ }
175
+
176
+ // ---- Editor mode helpers ----
177
+
178
+ function openRawEditor() {
179
+ editorMode.value = "raw"
180
+ }
181
+
182
+ function openInteractiveEditor() {
183
+ editorMode.value = "interactive"
184
+ }
185
+
186
+ // ---- Annotation CRUD ----
187
+
188
+ function createAnnotationFromSelection() {
189
+ const segments = createSegmentsFromSelection(selection.value, value.value.topology, sequenceLength.value)
190
+ if (segments.length === 0) return
191
+
192
+ const nextId = getNextDnaSequenceAnnotationId(value.value.annotations)
193
+ const annotation = createEmptyDnaSequenceAnnotation(nextId)
194
+ annotation.strand = selection.value?.direction === -1 ? -1 : 1
195
+ annotation.segments = segments
196
+
197
+ patchValue({ annotations: [...value.value.annotations, annotation] })
198
+ activeAnnotationId.value = annotation.id
199
+ activeSegmentIndex.value = 0
200
+ }
201
+
202
+ function addAnnotation() {
203
+ if (isInteractiveMode.value && selectionSegments.value.length > 0) {
204
+ createAnnotationFromSelection()
205
+ return
206
+ }
207
+
208
+ const nextId = getNextDnaSequenceAnnotationId(value.value.annotations)
209
+ const annotation = createEmptyDnaSequenceAnnotation(nextId)
210
+
211
+ if (sequenceLength.value > 0) {
212
+ annotation.segments = [{
213
+ start: 1,
214
+ end: Math.min(sequenceLength.value, 1),
215
+ partial_start: false,
216
+ partial_end: false,
217
+ }]
218
+ }
219
+
220
+ patchValue({ annotations: [...value.value.annotations, annotation] })
221
+ activeAnnotationId.value = annotation.id
222
+ activeSegmentIndex.value = 0
223
+ }
224
+
225
+ function removeAnnotation(index: number) {
226
+ const removed = value.value.annotations[index]
227
+ patchValue({
228
+ annotations: value.value.annotations.filter((_, i) => i !== index),
229
+ })
230
+
231
+ if (removed && activeAnnotationId.value === removed.id) {
232
+ activeAnnotationId.value = null
233
+ activeSegmentIndex.value = 0
234
+ selection.value = null
235
+ viewerSelection.value = null
236
+ }
237
+ }
238
+
239
+ function addSegment(annotationIndex: number) {
240
+ const annotation = value.value.annotations[annotationIndex]
241
+ if (!annotation) return
242
+ patchAnnotation(annotationIndex, {
243
+ segments: [...annotation.segments, createEmptyDnaSequenceSegment()],
244
+ })
245
+ }
246
+
247
+ function removeSegment(annotationIndex: number, segmentIndex: number) {
248
+ const annotation = value.value.annotations[annotationIndex]
249
+ if (!annotation) return
250
+
251
+ const nextSegments = annotation.segments.length <= 1
252
+ ? [createEmptyDnaSequenceSegment()]
253
+ : annotation.segments.filter((_, i) => i !== segmentIndex)
254
+
255
+ patchAnnotation(annotationIndex, { segments: nextSegments })
256
+
257
+ if (annotation.id === activeAnnotationId.value) {
258
+ activeSegmentIndex.value = Math.min(activeSegmentIndex.value, nextSegments.length - 1)
259
+ }
260
+ }
261
+
262
+ function addQualifier(annotationIndex: number) {
263
+ const annotation = value.value.annotations[annotationIndex]
264
+ if (!annotation) return
265
+ patchAnnotation(annotationIndex, {
266
+ qualifiers: [
267
+ ...annotation.qualifiers,
268
+ createEmptyDnaSequenceQualifier(annotation.qualifiers.length === 0 ? "note" : "qualifier"),
269
+ ],
270
+ })
271
+ }
272
+
273
+ function removeQualifier(annotationIndex: number, qualifierIndex: number) {
274
+ const annotation = value.value.annotations[annotationIndex]
275
+ if (!annotation) return
276
+ patchAnnotation(annotationIndex, {
277
+ qualifiers: annotation.qualifiers.filter((_, i) => i !== qualifierIndex),
278
+ })
279
+ }
280
+
281
+ function applySelectionToActiveSegment() {
282
+ const annotationIndex = value.value.annotations.findIndex(a => a.id === activeAnnotationId.value)
283
+ if (annotationIndex < 0) return
284
+
285
+ const annotation = value.value.annotations[annotationIndex]
286
+ const segments = createSegmentsFromSelection(selection.value, value.value.topology, sequenceLength.value)
287
+ if (!annotation || segments.length === 0) return
288
+
289
+ const currentIndex = Math.min(activeSegmentIndex.value, annotation.segments.length - 1)
290
+ const nextSegments = annotation.segments.flatMap((s, i) =>
291
+ i === currentIndex ? segments : [s])
292
+
293
+ patchAnnotation(annotationIndex, { segments: nextSegments })
294
+ activeSegmentIndex.value = currentIndex
295
+ }
296
+
297
+ function focusAnnotationInInteractive(annotationId: string, segmentIndex = 0) {
298
+ selectAnnotation(annotationId, segmentIndex)
299
+ openInteractiveEditor()
300
+ }
301
+
302
+ function handleAnnotationPrimaryAction(annotationId: string) {
303
+ if (editorMode.value === "interactive") {
304
+ focusAnnotationInInteractive(annotationId)
305
+ return
306
+ }
307
+ selectAnnotation(annotationId)
308
+ }
309
+
310
+ // ---- Viewer selection handler ----
311
+
312
+ function onViewerSelection(nextSelection: ViewerSelection) {
313
+ const normalized = normalizeViewerSelection(nextSelection)
314
+ selection.value = normalized
315
+ viewerSelection.value = createExternalSelectionFromSelection(normalized)
316
+
317
+ const parsedId = parseViewerAnnotationId(normalized?.id)
318
+ if (parsedId) {
319
+ activeAnnotationId.value = parsedId.annotationId
320
+ activeSegmentIndex.value = parsedId.segmentIndex
321
+ }
322
+ }
323
+
324
+ // ---- Import / export ----
325
+
326
+ function confirmImportReplacement(): boolean {
327
+ if (sequenceLength.value <= 0 && value.value.annotations.length === 0) return true
328
+ if (typeof window === "undefined" || typeof window.confirm !== "function") return true
329
+ return window.confirm(props.messages.dna.importReplaceConfirm)
330
+ }
331
+
332
+ function applyImportedSequenceText(rawText: string, fallbackName = ""): boolean {
333
+ const nextSequence = normalizeImportedSequenceText(rawText)
334
+ if (!nextSequence) {
335
+ importErrorMessage.value = props.messages.dna.onboardingNoSequenceDetected
336
+ return false
337
+ }
338
+
339
+ const invalid = collectInvalidDnaSequenceCharacters(nextSequence)
340
+ if (invalid.length > 0) {
341
+ importErrorMessage.value = props.messages.dna.invalidCharacters(invalid.join(", "))
342
+ return false
343
+ }
344
+
345
+ if (!confirmImportReplacement()) return false
346
+
347
+ const nextName = detectImportedName(rawText, fallbackName) || value.value.name
348
+ commit({
349
+ ...value.value,
350
+ name: nextName,
351
+ sequence: nextSequence,
352
+ topology: detectImportedTopology(rawText) ?? value.value.topology,
353
+ annotations: [],
354
+ })
355
+ interactiveSequenceDraft.value = ""
356
+ importErrorMessage.value = null
357
+ activeAnnotationId.value = null
358
+ activeSegmentIndex.value = 0
359
+ clearSelection()
360
+ return true
361
+ }
362
+
363
+ function openImportPicker() {
364
+ importFileInputRef.value?.click()
365
+ }
366
+
367
+ async function onImportChange(event: Event) {
368
+ const input = event.target as HTMLInputElement
369
+ const file = input.files?.[0]
370
+ input.value = ""
371
+ if (!file) return
372
+
373
+ try {
374
+ const text = await file.text()
375
+ applyImportedSequenceText(text, stripFileExtension(file.name))
376
+ } catch {
377
+ importErrorMessage.value = props.messages.dna.onboardingImportReadError
378
+ }
379
+ }
380
+
381
+ function downloadGenBank() {
382
+ downloadGenBankFile(value.value, props.varId)
383
+ }
384
+
385
+ // ---- Toolbar event handlers ----
386
+
387
+ function onEditorModeChange(mode: DnaEditorMode) {
388
+ editorMode.value = mode
389
+ }
390
+
391
+ function onTopologyChange(topology: "linear" | "circular") {
392
+ patchValue({ topology })
393
+ }
394
+
395
+ // ---- Viewer event handlers ----
396
+
397
+ function onSequenceDraftInput(draft: string) {
398
+ interactiveSequenceDraft.value = draft
399
+ importErrorMessage.value = null
400
+ }
401
+
402
+ function applyInteractiveSequenceDraft() {
403
+ applyImportedSequenceText(interactiveSequenceDraft.value)
404
+ }
405
+
406
+ async function focusActiveAnnotationEditor() {
407
+ if (!activeAnnotation.value) return
408
+ await nextTick()
409
+ annotationEditorRef.value?.focusNameInput()
410
+ }
411
+
412
+ // ---- Raw editor handler ----
413
+
414
+ function onSequenceUpdate(seq: string) {
415
+ patchValue({ sequence: seq })
416
+ }
417
+
418
+ // ---- Watchers ----
419
+
420
+ watch(() => value.value.annotations, annotations => {
421
+ if (annotations.length === 0) {
422
+ activeAnnotationId.value = null
423
+ activeSegmentIndex.value = 0
424
+ return
425
+ }
426
+
427
+ const found = annotations.find(a => a.id === activeAnnotationId.value)
428
+ if (!found) {
429
+ activeAnnotationId.value = annotations[0].id
430
+ activeSegmentIndex.value = 0
431
+ return
432
+ }
433
+
434
+ activeSegmentIndex.value = Math.min(activeSegmentIndex.value, found.segments.length - 1)
435
+ }, { deep: true, immediate: true })
436
+
437
+ watch(() => value.value.sequence, seq => {
438
+ if (seq.length > 0) {
439
+ interactiveSequenceDraft.value = ""
440
+ importErrorMessage.value = null
441
+ }
442
+ })
443
+ </script>
444
+
445
+ <template>
446
+ <span class="aimd-rec-inline aimd-rec-inline--var-dna aimd-field-wrapper aimd-field-wrapper--dna">
447
+ <span class="aimd-field aimd-field--no-style aimd-field__label">
448
+ <span class="aimd-field__scope aimd-field__scope--var">{{ props.messages.scope.var }}</span>
449
+ <span class="aimd-field__id">{{ props.varId }}</span>
450
+ </span>
451
+
452
+ <span class="aimd-dna-field">
453
+ <DnaSequenceToolbar
454
+ :editor-mode="editorMode"
455
+ :topology="value.topology"
456
+ :sequence-length="sequenceLength"
457
+ :gc-percent="gcPercent"
458
+ :disabled="props.disabled"
459
+ :import-error-message="importErrorMessage"
460
+ :is-interactive-mode="isInteractiveMode"
461
+ :messages="props.messages"
462
+ @update:editor-mode="onEditorModeChange"
463
+ @update:topology="onTopologyChange"
464
+ @import-file="openImportPicker"
465
+ @export-gen-bank="downloadGenBank"
466
+ @blur="emit('blur')"
467
+ />
468
+
469
+ <input
470
+ ref="importFileInputRef"
471
+ class="aimd-dna-field__hidden-file"
472
+ type="file"
473
+ accept=".txt,.seq,.fa,.fna,.fasta,.gb,.gbk,text/plain"
474
+ @change="onImportChange"
475
+ >
476
+
477
+ <span class="aimd-dna-field__metadata-grid">
478
+ <label class="aimd-dna-field__annotation-field aimd-dna-field__annotation-field--metadata">
479
+ <span>{{ props.messages.dna.sequenceName }}</span>
480
+ <input
481
+ class="aimd-dna-field__input"
482
+ :disabled="props.disabled"
483
+ :placeholder="props.messages.dna.sequenceNamePlaceholder"
484
+ :value="value.name"
485
+ @input="patchValue({ name: ($event.target as HTMLInputElement).value })"
486
+ @blur="emit('blur')"
487
+ />
488
+ </label>
489
+ </span>
490
+
491
+ <DnaSequenceViewer
492
+ v-if="isInteractiveMode"
493
+ :name="value.name || props.varId"
494
+ :sequence="value.sequence"
495
+ :topology="value.topology"
496
+ :sequence-length="sequenceLength"
497
+ :viewer-annotations="viewerAnnotations"
498
+ :viewer-selection="viewerSelection"
499
+ :selection-segments="selectionSegments"
500
+ :selection-range-label="selectionRangeLabel"
501
+ :selection-target-label="selectionTargetLabel"
502
+ :has-active-annotation="!!activeAnnotation"
503
+ :is-annotation-selection="selection?.type === 'ANNOTATION'"
504
+ :interactive-sequence-draft="interactiveSequenceDraft"
505
+ :has-interactive-sequence-draft="hasInteractiveSequenceDraft"
506
+ :import-error-message="importErrorMessage"
507
+ :disabled="props.disabled"
508
+ :placeholder="props.placeholder"
509
+ :messages="props.messages"
510
+ @viewer-selection="onViewerSelection"
511
+ @create-from-selection="createAnnotationFromSelection"
512
+ @apply-selection-to-segment="applySelectionToActiveSegment"
513
+ @edit-annotation="focusActiveAnnotationEditor"
514
+ @clear-selection="clearSelection"
515
+ @sequence-draft-input="onSequenceDraftInput"
516
+ @apply-sequence-draft="applyInteractiveSequenceDraft"
517
+ @open-raw-editor="openRawEditor"
518
+ @blur="emit('blur')"
519
+ />
520
+
521
+ <DnaSequenceEditor
522
+ v-else
523
+ :sequence="value.sequence"
524
+ :invalid-characters="invalidCharacters"
525
+ :disabled="props.disabled"
526
+ :placeholder="props.placeholder"
527
+ :messages="props.messages"
528
+ @update:sequence="onSequenceUpdate"
529
+ @blur="emit('blur')"
530
+ />
531
+
532
+ <DnaAnnotationEditor
533
+ ref="annotationEditorRef"
534
+ :annotations="value.annotations"
535
+ :active-annotation-id="activeAnnotationId"
536
+ :active-annotation-index="activeAnnotationIndex"
537
+ :active-annotation="activeAnnotation"
538
+ :active-segment-index="activeSegmentIndex"
539
+ :sequence-length="sequenceLength"
540
+ :is-interactive-mode="isInteractiveMode"
541
+ :selection-has-segments="selectionSegments.length > 0"
542
+ :disabled="props.disabled"
543
+ :messages="props.messages"
544
+ @add-annotation="addAnnotation"
545
+ @remove-annotation="removeAnnotation"
546
+ @patch-annotation="patchAnnotation"
547
+ @patch-segment="patchSegment"
548
+ @patch-qualifier="patchQualifier"
549
+ @add-segment="addSegment"
550
+ @remove-segment="removeSegment"
551
+ @add-qualifier="addQualifier"
552
+ @remove-qualifier="removeQualifier"
553
+ @handle-annotation-primary-action="handleAnnotationPrimaryAction"
554
+ @focus-annotation-in-interactive="focusAnnotationInInteractive"
555
+ @open-raw-editor="openRawEditor"
556
+ @blur="emit('blur')"
557
+ />
558
+ </span>
559
+ </span>
560
+ </template>
561
+
562
+ <style>
563
+ .aimd-rec-inline--var-dna {
564
+ display: inline-flex;
565
+ flex-direction: column;
566
+ align-items: stretch;
567
+ width: min(100%, 920px);
568
+ min-width: min(100%, 340px);
569
+ margin: 8px 4px;
570
+ vertical-align: top;
571
+ border: 1px solid var(--aimd-border-color, #90caf9);
572
+ border-radius: 10px;
573
+ overflow: hidden;
574
+ background: #fff;
575
+ }
576
+
577
+ .aimd-rec-inline--var-dna:focus-within {
578
+ border-color: var(--aimd-border-color-focus, #4181fd);
579
+ box-shadow: 0 0 0 2px rgba(65, 129, 253, 0.14);
580
+ }
581
+
582
+ .aimd-rec-inline--var-dna > .aimd-field--no-style.aimd-field__label {
583
+ align-self: stretch;
584
+ width: calc(100% + 2px);
585
+ border: none;
586
+ border-bottom: 1px solid var(--aimd-border-color, #90caf9);
587
+ border-radius: 10px 10px 0 0;
588
+ min-height: 30px;
589
+ background: var(--aimd-var-bg, #e3f2fd);
590
+ margin: -1px -1px 0 -1px;
591
+ box-sizing: border-box;
592
+ }
593
+
594
+ .aimd-rec-inline--var-dna > .aimd-field--no-style.aimd-field__label .aimd-field__scope {
595
+ align-self: center;
596
+ height: 22px;
597
+ margin-left: 3px;
598
+ padding: 0 7px;
599
+ border-radius: 6px;
600
+ }
601
+
602
+ .aimd-rec-inline--var-dna > .aimd-field--no-style.aimd-field__label .aimd-field__id {
603
+ display: flex;
604
+ flex: 1;
605
+ align-items: center;
606
+ min-width: 0;
607
+ padding: 0 10px 0 6px;
608
+ font-size: 13px;
609
+ font-weight: 500;
610
+ color: var(--aimd-var-text, #1565c0);
611
+ white-space: nowrap;
612
+ }
613
+
614
+ .aimd-dna-field {
615
+ display: flex;
616
+ flex-direction: column;
617
+ width: 100%;
618
+ box-sizing: border-box;
619
+ gap: 14px;
620
+ padding: 12px;
621
+ background: #fff;
622
+ }
623
+
624
+ .aimd-dna-field__toolbar {
625
+ display: flex;
626
+ flex-wrap: wrap;
627
+ align-items: center;
628
+ gap: 10px;
629
+ }
630
+
631
+ .aimd-dna-field__hint--toolbar {
632
+ margin-top: -4px;
633
+ }
634
+
635
+ .aimd-dna-field__metadata-grid {
636
+ display: grid;
637
+ grid-template-columns: minmax(220px, 420px);
638
+ }
639
+
640
+ .aimd-dna-field__toolbar-item {
641
+ display: inline-flex;
642
+ align-items: center;
643
+ gap: 8px;
644
+ }
645
+
646
+ .aimd-dna-field__toolbar-spacer {
647
+ flex: 1 1 auto;
648
+ }
649
+
650
+ .aimd-dna-field__toolbar-item--mode {
651
+ margin-right: 8px;
652
+ }
653
+
654
+ .aimd-dna-field__toolbar-label {
655
+ font-size: 12px;
656
+ font-weight: 600;
657
+ color: #3b5b86;
658
+ }
659
+
660
+ .aimd-dna-field__mode-switch {
661
+ display: inline-flex;
662
+ padding: 3px;
663
+ border-radius: 999px;
664
+ background: #edf4ff;
665
+ border: 1px solid #cdddf6;
666
+ }
667
+
668
+ .aimd-dna-field__mode-button {
669
+ height: 30px;
670
+ padding: 0 12px;
671
+ border: none;
672
+ border-radius: 999px;
673
+ background: transparent;
674
+ color: #476788;
675
+ font-size: 12px;
676
+ font-weight: 700;
677
+ cursor: pointer;
678
+ }
679
+
680
+ .aimd-dna-field__mode-button:disabled {
681
+ opacity: 0.55;
682
+ cursor: not-allowed;
683
+ }
684
+
685
+ .aimd-dna-field__mode-button--active {
686
+ background: #fff;
687
+ color: #245eb0;
688
+ box-shadow: 0 1px 2px rgba(37, 94, 176, 0.18);
689
+ }
690
+
691
+ .aimd-dna-field__stat,
692
+ .aimd-dna-field__meta-pill {
693
+ display: inline-flex;
694
+ align-items: center;
695
+ padding: 4px 8px;
696
+ border-radius: 999px;
697
+ background: #edf4ff;
698
+ color: #35517c;
699
+ font-size: 12px;
700
+ font-weight: 600;
701
+ }
702
+
703
+ .aimd-dna-field__section,
704
+ .aimd-dna-field__subsection {
705
+ display: flex;
706
+ flex-direction: column;
707
+ gap: 8px;
708
+ }
709
+
710
+ .aimd-dna-field__section-header,
711
+ .aimd-dna-field__subsection-header {
712
+ display: flex;
713
+ align-items: center;
714
+ justify-content: space-between;
715
+ gap: 12px;
716
+ }
717
+
718
+ .aimd-dna-field__section-title {
719
+ font-size: 13px;
720
+ font-weight: 700;
721
+ color: #25466c;
722
+ }
723
+
724
+ .aimd-dna-field__section-meta,
725
+ .aimd-dna-field__subsection-title {
726
+ font-size: 12px;
727
+ font-weight: 700;
728
+ color: #41618b;
729
+ }
730
+
731
+ .aimd-dna-field__sequence {
732
+ min-height: 124px;
733
+ padding: 10px 12px;
734
+ border: 1px solid #c8d7eb;
735
+ border-radius: 8px;
736
+ background: #fdfefe;
737
+ color: #19324d;
738
+ font: 600 13px/1.6 "SFMono-Regular", Menlo, Consolas, monospace;
739
+ resize: vertical;
740
+ }
741
+
742
+ .aimd-dna-field__sequence--onboarding {
743
+ min-height: 96px;
744
+ }
745
+
746
+ .aimd-dna-field__viewer-shell {
747
+ overflow: hidden;
748
+ border: 1px solid #d7e4f4;
749
+ border-radius: 12px;
750
+ background:
751
+ radial-gradient(circle at top right, rgba(59, 130, 246, 0.08), transparent 30%),
752
+ linear-gradient(180deg, #fcfdff 0%, #f5f9ff 100%);
753
+ }
754
+
755
+ .aimd-dna-field__selection-card,
756
+ .aimd-dna-field__annotation-card,
757
+ .aimd-dna-field__row-card,
758
+ .aimd-dna-field__empty {
759
+ display: flex;
760
+ flex-direction: column;
761
+ gap: 10px;
762
+ padding: 10px;
763
+ border-radius: 10px;
764
+ border: 1px solid #d7e4f4;
765
+ background: #fbfdff;
766
+ }
767
+
768
+ .aimd-dna-field__selection-card--muted {
769
+ background: #fcfdff;
770
+ }
771
+
772
+ .aimd-dna-field__selection-title {
773
+ font-size: 12px;
774
+ font-weight: 700;
775
+ color: #35517c;
776
+ }
777
+
778
+ .aimd-dna-field__selection-meta,
779
+ .aimd-dna-field__advanced-copy,
780
+ .aimd-dna-field__hint {
781
+ font-size: 12px;
782
+ color: #4c6b8c;
783
+ }
784
+
785
+ .aimd-dna-field__selection-actions,
786
+ .aimd-dna-field__annotation-actions,
787
+ .aimd-dna-field__row-actions,
788
+ .aimd-dna-field__empty-actions {
789
+ display: flex;
790
+ flex-wrap: wrap;
791
+ justify-content: flex-end;
792
+ gap: 8px;
793
+ }
794
+
795
+ .aimd-dna-field__annotation-list {
796
+ display: grid;
797
+ gap: 10px;
798
+ }
799
+
800
+ .aimd-dna-field__annotation-card {
801
+ flex-direction: row;
802
+ align-items: flex-start;
803
+ justify-content: space-between;
804
+ gap: 12px;
805
+ }
806
+
807
+ .aimd-dna-field__annotation-card--active,
808
+ .aimd-dna-field__row-card--active {
809
+ border-color: #97bbff;
810
+ box-shadow: 0 0 0 2px rgba(65, 129, 253, 0.08);
811
+ }
812
+
813
+ .aimd-dna-field__annotation-card-main {
814
+ display: flex;
815
+ min-width: 0;
816
+ gap: 10px;
817
+ }
818
+
819
+ .aimd-dna-field__annotation-swatch {
820
+ width: 10px;
821
+ min-width: 10px;
822
+ align-self: stretch;
823
+ border-radius: 999px;
824
+ }
825
+
826
+ .aimd-dna-field__annotation-copy {
827
+ display: flex;
828
+ min-width: 0;
829
+ flex-direction: column;
830
+ gap: 4px;
831
+ }
832
+
833
+ .aimd-dna-field__annotation-name {
834
+ font-size: 13px;
835
+ font-weight: 700;
836
+ color: #1f3d63;
837
+ }
838
+
839
+ .aimd-dna-field__annotation-meta {
840
+ font-size: 12px;
841
+ color: #5e7897;
842
+ }
843
+
844
+ .aimd-dna-field__annotation-grid,
845
+ .aimd-dna-field__segment-grid,
846
+ .aimd-dna-field__qualifier-grid {
847
+ display: grid;
848
+ gap: 10px;
849
+ }
850
+
851
+ .aimd-dna-field__annotation-grid {
852
+ grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
853
+ }
854
+
855
+ .aimd-dna-field__segment-grid {
856
+ grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
857
+ }
858
+
859
+ .aimd-dna-field__qualifier-grid {
860
+ grid-template-columns: minmax(140px, 220px) minmax(180px, 1fr);
861
+ }
862
+
863
+ .aimd-dna-field__annotation-field {
864
+ display: flex;
865
+ flex-direction: column;
866
+ gap: 6px;
867
+ font-size: 12px;
868
+ color: #486683;
869
+ font-weight: 600;
870
+ }
871
+
872
+ .aimd-dna-field__annotation-field--wide {
873
+ min-width: 0;
874
+ }
875
+
876
+ .aimd-dna-field__annotation-field--metadata {
877
+ min-width: 0;
878
+ }
879
+
880
+ .aimd-dna-field__input,
881
+ .aimd-dna-field__select {
882
+ min-width: 0;
883
+ height: 34px;
884
+ padding: 0 10px;
885
+ border: 1px solid #c8d7eb;
886
+ border-radius: 8px;
887
+ background: #fff;
888
+ color: #1e3854;
889
+ font-size: 13px;
890
+ transition: border-color 0.16s ease, box-shadow 0.16s ease;
891
+ }
892
+
893
+ .aimd-dna-field__input--color {
894
+ padding: 4px;
895
+ }
896
+
897
+ .aimd-dna-field__sequence:focus,
898
+ .aimd-dna-field__input:focus,
899
+ .aimd-dna-field__select:focus {
900
+ outline: none;
901
+ border-color: #5d92f8;
902
+ box-shadow: 0 0 0 2px rgba(93, 146, 248, 0.14);
903
+ }
904
+
905
+ .aimd-dna-field__toggle {
906
+ display: inline-flex;
907
+ align-items: center;
908
+ gap: 8px;
909
+ padding: 6px 10px;
910
+ border-radius: 8px;
911
+ background: #eef5ff;
912
+ color: #35517c;
913
+ font-size: 12px;
914
+ font-weight: 600;
915
+ }
916
+
917
+ .aimd-dna-field__toggle input {
918
+ margin: 0;
919
+ }
920
+
921
+ .aimd-dna-field__hint--error {
922
+ color: #c0392b;
923
+ }
924
+
925
+ .aimd-dna-field__hidden-file {
926
+ display: none;
927
+ }
928
+
929
+ .aimd-dna-field__meta-pills {
930
+ display: flex;
931
+ flex-wrap: wrap;
932
+ gap: 8px;
933
+ }
934
+
935
+ .aimd-dna-field__action {
936
+ display: inline-flex;
937
+ align-items: center;
938
+ justify-content: center;
939
+ height: 30px;
940
+ padding: 0 10px;
941
+ border: 1px solid #b6cdf5;
942
+ border-radius: 999px;
943
+ background: #edf4ff;
944
+ color: #2b61b7;
945
+ font-size: 12px;
946
+ font-weight: 700;
947
+ cursor: pointer;
948
+ }
949
+
950
+ .aimd-dna-field__action:disabled {
951
+ opacity: 0.55;
952
+ cursor: not-allowed;
953
+ }
954
+
955
+ .aimd-dna-field__action--danger {
956
+ border-color: #efc4c4;
957
+ background: #fff5f5;
958
+ color: #c0392b;
959
+ }
960
+
961
+ .aimd-dna-field__action--toolbar {
962
+ flex: 0 0 auto;
963
+ }
964
+
965
+ @media (max-width: 640px) {
966
+ .aimd-rec-inline--var-dna {
967
+ min-width: 100%;
968
+ width: 100%;
969
+ }
970
+
971
+ .aimd-dna-field__toolbar {
972
+ align-items: flex-start;
973
+ }
974
+
975
+ .aimd-dna-field__annotation-card {
976
+ flex-direction: column;
977
+ }
978
+
979
+ .aimd-dna-field__qualifier-grid {
980
+ grid-template-columns: 1fr;
981
+ }
982
+ }
983
+ </style>