@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
package/README.md ADDED
@@ -0,0 +1,240 @@
1
+ # @airalogy/aimd-recorder
2
+
3
+ Reusable recording UI for AIMD, including inline protocol recorder, the combined `AimdRecorderEditor`, quiz answer components, and styles.
4
+
5
+ Built-in variable input types include `CurrentTime`, `UserName`, `AiralogyMarkdown`, and `DNASequence`.
6
+ `AiralogyMarkdown` now uses a full-width embedded AIMD/Markdown editor in recorder mode, opens in `Source` mode by default, keeps the full top toolbar, and still supports switching to `WYSIWYG` instead of a plain textarea.
7
+ In recorder/edit mode, `ref_var` references display current var values as readonly inline content when available.
8
+ Frontend-only `assigner runtime=client` blocks are executed locally for pure var computations.
9
+ For simultaneous protocol restructuring and data entry, `AimdRecorderEditor` keeps the AIMD source editor and recorder bound to the same `content` + `record` state and can surface detached values after field IDs disappear from the current protocol.
10
+
11
+ > Protocol-level AIMD syntax, assigner semantics, and validation rules are normative in Airalogy docs. `@airalogy/aimd-*` docs describe how the frontend parser, renderer, and recorder implement those rules.
12
+
13
+ ## Install
14
+
15
+ ```bash
16
+ pnpm add @airalogy/aimd-recorder @airalogy/aimd-core
17
+ ```
18
+
19
+ ## Quick Start
20
+
21
+ ```vue
22
+ <script setup lang="ts">
23
+ import { ref } from "vue"
24
+ import {
25
+ AimdRecorder,
26
+ createEmptyProtocolRecordData,
27
+ type AimdProtocolRecordData,
28
+ } from "@airalogy/aimd-recorder"
29
+ import "@airalogy/aimd-recorder/styles"
30
+
31
+ const content = ref(`# Protocol
32
+
33
+ Sample: {{var|sample_name: str}}
34
+ Operator: {{var|operator: UserName}}
35
+ Record Time: {{var|current_time: CurrentTime}}
36
+ Temperature: {{var|temperature: float = 25.0}}
37
+ Notes: {{var|notes: AiralogyMarkdown}}
38
+ Plasmid: {{var|plasmid: DNASequence}}`)
39
+ const record = ref<AimdProtocolRecordData>(createEmptyProtocolRecordData())
40
+ </script>
41
+
42
+ <template>
43
+ <AimdRecorder
44
+ v-model="record"
45
+ :content="content"
46
+ locale="en-US"
47
+ current-user-name="Alice"
48
+ />
49
+ </template>
50
+ ```
51
+
52
+ `AiralogyMarkdown` fields render a full-width embedded AIMD/Markdown editor with the full top toolbar, default to `Source` mode, and still support switching to `WYSIWYG`. Even when the field is authored mid-sentence, recorder lifts it into its own block row instead of keeping it as a tiny inline control.
53
+
54
+ `DNASequence` fields render a dedicated DNA editor with:
55
+
56
+ - a default `Interactive` mode focused on the sequence viewer
57
+ - a separate `Raw structure` mode for sequence text and structured cleanup
58
+ - an optional top-level sequence name field for plasmid or construct naming
59
+ - shared toolbar actions for importing FASTA / GenBank sequence files and exporting the current value as a GenBank `.gbk` file
60
+ - interactive onboarding for pasting DNA text
61
+ - sequence input using IUPAC DNA letters
62
+ - topology toggle (`linear` / `circular`)
63
+ - GenBank-aligned feature rows with multi-segment locations
64
+ - partial start / partial end flags per segment
65
+ - qualifier rows such as `gene`, `product`, `label`, and `note`
66
+
67
+ Use `locale` to switch built-in recorder labels (`en-US` / `zh-CN`).
68
+ `AimdProtocolRecorder` is still available as a deprecated compatibility alias, but new code should use `AimdRecorder`.
69
+
70
+ ## Recorder Editor
71
+
72
+ Use `AimdRecorderEditor` when users need to edit the AIMD protocol structure and fill recorder values in the same screen.
73
+
74
+ ```vue
75
+ <script setup lang="ts">
76
+ import { ref } from "vue"
77
+ import {
78
+ AimdRecorderEditor,
79
+ createEmptyProtocolRecordData,
80
+ type AimdProtocolRecordData,
81
+ } from "@airalogy/aimd-recorder"
82
+ import "@airalogy/aimd-recorder/styles"
83
+
84
+ const content = ref(`# Protocol
85
+
86
+ Sample: {{var|sample_name: str}}
87
+ Temperature: {{var|temperature: float}}
88
+ `)
89
+ const record = ref<AimdProtocolRecordData>(createEmptyProtocolRecordData())
90
+ </script>
91
+
92
+ <template>
93
+ <AimdRecorderEditor
94
+ v-model="record"
95
+ v-model:content="content"
96
+ locale="en-US"
97
+ :show-record-data="true"
98
+ :allow-raw-field-source-editing="false"
99
+ />
100
+ </template>
101
+ ```
102
+
103
+ This editor keeps recorder state alive while the AIMD source changes, and it groups `Recorder`, `Record Data`, and detached-data views into one right-side tab workspace so those auxiliary panels do not get pushed below a long AIMD document. By default, it also measures the remaining viewport space below the editor and stretches both columns to fill that space as much as possible, with internal scrolling on each side so the columns stay visually aligned; that balanced scroll behavior also applies when the recorder side is switched into visual editing. If the host still wants the separate `Field Structure` helper panel, pass `:show-field-structure="true"`. Users can:
104
+
105
+ - switch field kinds
106
+ - rename field ids
107
+ - change inline `var` value types
108
+ - add or delete fields
109
+ - drag field source fragments into a different order
110
+
111
+ If a field is renamed or removed, detached values are shown in their own tab so users can copy them into newly created fields instead of losing track of the previous data.
112
+
113
+ For non-technical users, the editor also has a recorder-aware WYSIWYG mode. Turn it on in the recorder panel header and the right side switches into a caret-based AIMD editor where `var`, `var_table`, `step`, `check`, and `quiz` fields are rendered as real recorder widgets instead of inline chips. Users can keep writing headings, lists, and normal Markdown around those widgets, drag the rendered field nodes to any caret-valid position, and follow the visible drop indicator that appears while dragging for more precise placement. The contextual hover/focus toolbar attached to each rendered field also keeps edit, delete, and drag actions on the widget itself. If the host does not want raw AIMD editing inside the recorder-side dialog, set `:allow-raw-field-source-editing="false"` and the dialog keeps only the structured controls. Turn visual edit mode back off to return to normal recorder entry; the current record state stays intact.
114
+
115
+ If the host prefers the previous fixed-height behavior, disable viewport fitting explicitly:
116
+
117
+ ```vue
118
+ <AimdRecorderEditor
119
+ :fit-viewport="false"
120
+ :editor-min-height="640"
121
+ :recorder-min-height="640"
122
+ />
123
+ ```
124
+
125
+ `record` shape:
126
+
127
+ ```json
128
+ {
129
+ "var": {},
130
+ "step": {},
131
+ "check": {},
132
+ "quiz": {}
133
+ }
134
+ ```
135
+
136
+ Client assigner example:
137
+
138
+ ````aimd
139
+ Water: {{var|water_volume_ml: float}}
140
+ Lemon: {{var|lemon_juice_ml: float}}
141
+ Total: {{var|total_liquid_ml: float}}
142
+
143
+ ```assigner runtime=client
144
+ assigner(
145
+ {
146
+ mode: "auto",
147
+ dependent_fields: ["water_volume_ml", "lemon_juice_ml"],
148
+ assigned_fields: ["total_liquid_ml"],
149
+ },
150
+ function calculate_total_liquid_ml({ water_volume_ml, lemon_juice_ml }) {
151
+ return {
152
+ total_liquid_ml: Math.round((water_volume_ml + lemon_juice_ml) * 100) / 100,
153
+ };
154
+ }
155
+ );
156
+ ```
157
+ ````
158
+
159
+ For `mode: "manual"`, the component exposes explicit trigger methods through the Vue ref:
160
+
161
+ ```ts
162
+ recorderRef.value?.runClientAssigner("calculate_total_liquid_ml")
163
+ recorderRef.value?.runManualClientAssigners()
164
+ ```
165
+
166
+ ## Host Field Adapters
167
+
168
+ ```ts
169
+ import { h } from "vue"
170
+
171
+ const fieldAdapters = {
172
+ step: ({ node, defaultVNode }) =>
173
+ h("step-card", {
174
+ "step-id": node.id,
175
+ "step-number": node.step,
176
+ title: node.title || node.id,
177
+ level: String(node.level),
178
+ }, () => [defaultVNode]),
179
+ }
180
+ ```
181
+
182
+ Pass `fieldAdapters` to `AimdRecorder` when the host app needs to replace or wrap built-in recorder field UIs while still using AIMD parsing and record-state management.
183
+
184
+ If the host app needs per-type behavior instead, use `typePlugins`. A type plugin can define the initial value, normalization, display/parsing hooks, and even a dedicated widget for one specific AIMD type token.
185
+
186
+ The built-in `AiralogyMarkdown` editor uses this same extension path, so a host plugin can still replace it if needed.
187
+
188
+ See:
189
+
190
+ - `aimd/docs/en/packages/type-plugins.md`
191
+
192
+ ### Quiz Recorder Only
193
+
194
+ ```vue
195
+ <script setup lang="ts">
196
+ import { ref } from "vue"
197
+ import { AimdQuizRecorder } from "@airalogy/aimd-recorder"
198
+ import "@airalogy/aimd-recorder/styles"
199
+
200
+ const answer = ref("")
201
+ const quiz = {
202
+ id: "quiz_single_1",
203
+ type: "choice",
204
+ mode: "single",
205
+ stem: "Pick one option",
206
+ options: [
207
+ { key: "A", text: "Option A" },
208
+ { key: "B", text: "Option B" },
209
+ ],
210
+ }
211
+ </script>
212
+
213
+ <template>
214
+ <AimdQuizRecorder v-model="answer" :quiz="quiz" locale="en-US" />
215
+ </template>
216
+ ```
217
+
218
+ `AimdQuizRecorder` also supports `scale` quizzes. For deterministic scales, you can either pass an external `grade` result or let the recorder reveal a local score/classification via `scaleGradeDisplayMode="completed"` or `scaleGradeDisplayMode="submitted"`.
219
+
220
+ ## Documentation
221
+
222
+ - EN: <https://airalogy.github.io/aimd/en/packages/aimd-recorder>
223
+ - 中文: <https://airalogy.github.io/aimd/zh/packages/aimd-recorder>
224
+ - Source docs: `aimd/docs/en/packages/aimd-recorder.md`, `aimd/docs/zh/packages/aimd-recorder.md`
225
+
226
+ ## Citation
227
+
228
+ If `@airalogy/aimd-recorder` is useful in your work, please cite the Airalogy paper:
229
+
230
+ ```bibtex
231
+ @misc{yang2025airalogyaiempowereduniversaldata,
232
+ title={Airalogy: AI-empowered universal data digitization for research automation},
233
+ author={Zijie Yang and Qiji Zhou and Fang Guo and Sijie Zhang and Yexun Xi and Jinglei Nie and Yudian Zhu and Liping Huang and Chou Wu and Yonghe Xia and Xiaoyu Ma and Yingming Pu and Panzhong Lu and Junshu Pan and Mingtao Chen and Tiannan Guo and Yanmei Dou and Hongyu Chen and Anping Zeng and Jiaxing Huang and Tian Xu and Yue Zhang},
234
+ year={2025},
235
+ eprint={2506.18586},
236
+ archivePrefix={arXiv},
237
+ primaryClass={cs.AI},
238
+ url={https://arxiv.org/abs/2506.18586},
239
+ }
240
+ ```
@@ -0,0 +1,224 @@
1
+ # @airalogy/aimd-recorder
2
+
3
+ AIMD 记录 UI 组件与样式集合,包含协议内联录入组件、组合式 `AimdRecorderEditor` 与可复用题目作答控件。
4
+
5
+ 内置变量控件支持 `CurrentTime`、`UserName`、`AiralogyMarkdown` 和 `DNASequence`。
6
+ `AiralogyMarkdown` 现在会在 recorder 中以横铺内嵌 AIMD/Markdown 编辑器呈现,默认进入 `源码` 模式,并保留完整顶部工具栏,同时支持切换到 `所见即所得`,而不是普通 textarea。
7
+ 在 recorder/edit 模式下,`ref_var` 如果已经有记录值,会优先以只读内联内容显示该值。
8
+ 前端受限的 `assigner runtime=client` 代码块会在 recorder 中本地执行,用于纯 `var` 计算。
9
+ 如果需要一边改 Protocol 结构、一边继续填写字段数据,可以使用 `AimdRecorderEditor`,它会把源码编辑器和 recorder 绑定到同一份 `content` 与 `record`,并在字段 id 从当前 protocol 里消失后单独展示旧数据。
10
+
11
+ > 协议级 AIMD 语法、assigner 语义与校验规则以 Airalogy 文档为准;`@airalogy/aimd-*` 文档只描述前端 parser、renderer、recorder 如何实现这些规范。
12
+
13
+ ## 安装
14
+
15
+ ```bash
16
+ pnpm add @airalogy/aimd-recorder @airalogy/aimd-core
17
+ ```
18
+
19
+ ## 快速开始
20
+
21
+ ```vue
22
+ <script setup lang="ts">
23
+ import { ref } from "vue"
24
+ import {
25
+ AimdRecorder,
26
+ createEmptyProtocolRecordData,
27
+ type AimdProtocolRecordData,
28
+ } from "@airalogy/aimd-recorder"
29
+ import "@airalogy/aimd-recorder/styles"
30
+
31
+ const content = ref(`# Protocol
32
+
33
+ 样本名:{{var|sample_name: str}}
34
+ 记录者:{{var|operator: UserName}}
35
+ 记录时间:{{var|current_time: CurrentTime}}
36
+ 温度设置:{{var|temperature: float = 25.0}}
37
+ 实验摘要:{{var|summary: AiralogyMarkdown}}
38
+ 质粒:{{var|plasmid: DNASequence}}`)
39
+ const record = ref<AimdProtocolRecordData>(createEmptyProtocolRecordData())
40
+ </script>
41
+
42
+ <template>
43
+ <AimdRecorder
44
+ v-model="record"
45
+ :content="content"
46
+ locale="zh-CN"
47
+ current-user-name="张三"
48
+ />
49
+ </template>
50
+ ```
51
+
52
+ `AiralogyMarkdown` 字段会渲染一个横铺内嵌的 AIMD/Markdown 编辑器,默认进入 `源码` 模式,并保留完整顶部工具栏,同时支持切换到 `所见即所得`。即使它写在一行文字中间,recorder 也会把这个字段提升成下一行的块级编辑区,而不是继续当成段内小控件。
53
+
54
+ `DNASequence` 字段会渲染一个专用 DNA 编辑器,支持:
55
+
56
+ - 默认以 `交互式` 模式进行可视化编辑
57
+ - 单独提供 `原始结构` 模式处理序列原文和结构化精修
58
+ - 可选的顶层序列名称字段,可用于质粒或构建体命名
59
+ - 共享工具栏可导入 FASTA / GenBank 序列文件,并将当前值导出为 GenBank `.gbk` 文件
60
+ - 交互式空状态下可直接粘贴 DNA 文本
61
+ - IUPAC DNA 序列输入
62
+ - 拓扑切换(`linear` / `circular`)
63
+ - GenBank 对齐子集风格的特征编辑
64
+ - 多段位置片段(segments)与每段的 partial 标记
65
+ - `gene`、`product`、`label`、`note` 等限定词行编辑
66
+
67
+ 通过 `locale` 可以切换 recorder 内建标签(`en-US` / `zh-CN`)。
68
+ `AimdProtocolRecorder` 仍保留为已废弃的兼容别名,但新的代码建议直接使用 `AimdRecorder`。
69
+
70
+ ## Recorder Editor
71
+
72
+ 当用户需要在同一个界面里同时修改 AIMD Protocol 结构并继续填写 recorder 数据时,使用 `AimdRecorderEditor`。
73
+
74
+ ```vue
75
+ <script setup lang="ts">
76
+ import { ref } from "vue"
77
+ import {
78
+ AimdRecorderEditor,
79
+ createEmptyProtocolRecordData,
80
+ type AimdProtocolRecordData,
81
+ } from "@airalogy/aimd-recorder"
82
+ import "@airalogy/aimd-recorder/styles"
83
+
84
+ const content = ref(`# Protocol
85
+
86
+ 样本名:{{var|sample_name: str}}
87
+ 温度:{{var|temperature: float}}
88
+ `)
89
+ const record = ref<AimdProtocolRecordData>(createEmptyProtocolRecordData())
90
+ </script>
91
+
92
+ <template>
93
+ <AimdRecorderEditor
94
+ v-model="record"
95
+ v-model:content="content"
96
+ locale="zh-CN"
97
+ :show-record-data="true"
98
+ :allow-raw-field-source-editing="false"
99
+ />
100
+ </template>
101
+ ```
102
+
103
+ 这个 editor 会在 AIMD 源码变化时继续保留 recorder 状态,并把 `Recorder`、`Record Data`、`脱离当前 Protocol 的旧数据` 收到右侧同一组 tab 里,避免 AIMD 很长时这些面板被挤到页面底部。默认情况下,左右两列会根据 editor 在当前页面里的位置和浏览器可用高度自动伸展,尽量撑满视口,并在各自面板内部滚动,避免左右两列高度失衡;这个同高滚动行为也会覆盖 recorder 侧的可视化编辑模式。如果宿主仍然希望保留独立的 `Field 结构编辑` 辅助面板,可以显式传 `:show-field-structure="true"`。同时用户可以直接:
104
+
105
+ - 切换 field kind
106
+ - 修改 field id
107
+ - 修改内联 `var` 的值类型
108
+ - 新增或删除 field
109
+ - 通过拖拽调整 field 源码片段顺序
110
+
111
+ 如果字段被改名或删除,脱离当前 protocol 的旧值会在右侧 `脱离当前 Protocol 的旧数据` tab 里单独显示出来,用户可以再把它们搬到新建 field 里,而不是只能去翻外部 JSON。
112
+
113
+ 对于不理解源码的用户,这个 editor 现在还提供了一个 recorder-aware 的 WYSIWYG 编辑模式。打开 recorder 面板标题栏里的切换后,右侧会直接切到一个可落光标的 AIMD 编辑器,其中 `var`、`var_table`、`step`、`check`、`quiz` 会直接显示成真实的 recorder widget,而不是普通小 chip。用户可以一边继续写标题、列表和普通 Markdown,一边拖动这些渲染后的 field 到任意可落光标的位置;拖动过程中还会出现明确的落点提示,方便更精确地放置。也可以直接通过贴在 field 本体上的 hover / focus 工具条完成编辑、删除和拖动,不需要跳出当前 widget。如果宿主不希望用户在 recorder 侧继续改 raw AIMD,可以设置 `:allow-raw-field-source-editing="false"`,这样字段弹窗里只保留结构化控件。关闭切换后再回到正常 recorder 录入,已有 record 数据会继续保留。
114
+
115
+ 如果宿主不希望跟随浏览器高度自动伸展,可以显式关闭:
116
+
117
+ ```vue
118
+ <AimdRecorderEditor
119
+ :fit-viewport="false"
120
+ :editor-min-height="640"
121
+ :recorder-min-height="640"
122
+ />
123
+ ```
124
+
125
+ `record` 数据结构:
126
+
127
+ ```json
128
+ {
129
+ "var": {},
130
+ "step": {},
131
+ "check": {},
132
+ "quiz": {}
133
+ }
134
+ ```
135
+
136
+ client assigner 示例:
137
+
138
+ ````aimd
139
+ Water: {{var|water_volume_ml: float}}
140
+ Lemon: {{var|lemon_juice_ml: float}}
141
+ Total: {{var|total_liquid_ml: float}}
142
+
143
+ ```assigner runtime=client
144
+ assigner(
145
+ {
146
+ mode: "auto",
147
+ dependent_fields: ["water_volume_ml", "lemon_juice_ml"],
148
+ assigned_fields: ["total_liquid_ml"],
149
+ },
150
+ function calculate_total_liquid_ml({ water_volume_ml, lemon_juice_ml }) {
151
+ return {
152
+ total_liquid_ml: Math.round((water_volume_ml + lemon_juice_ml) * 100) / 100,
153
+ };
154
+ }
155
+ );
156
+ ```
157
+ ````
158
+
159
+ 如果使用 `mode: "manual"`,组件会通过 Vue ref 暴露显式触发方法:
160
+
161
+ ```ts
162
+ recorderRef.value?.runClientAssigner("calculate_total_liquid_ml")
163
+ recorderRef.value?.runManualClientAssigners()
164
+ ```
165
+
166
+ ## 宿主字段适配器
167
+
168
+ ```ts
169
+ import { h } from "vue"
170
+
171
+ const fieldAdapters = {
172
+ step: ({ node, defaultVNode }) =>
173
+ h("step-card", {
174
+ "step-id": node.id,
175
+ "step-number": node.step,
176
+ title: node.title || node.id,
177
+ level: String(node.level),
178
+ }, () => [defaultVNode]),
179
+ }
180
+ ```
181
+
182
+ 当宿主应用需要替换或包裹内建字段 UI,但仍希望继续复用 AIMD 解析和 recorder record-state 管理时,可以把 `fieldAdapters` 传给 `AimdRecorder`。
183
+
184
+ 如果宿主应用需要的是某个具体类型的行为扩展,而不是整体替换某类字段 UI,则应该使用 `typePlugins`。type plugin 可以为单个 AIMD 类型定义初始值、归一化、显示/解析钩子,甚至完整的专用 widget。
185
+
186
+ 内建的 `AiralogyMarkdown` 编辑器也是沿用这条扩展路径实现的,因此宿主应用如果需要不同的源码/所见即所得工作流,仍然可以覆盖它。
187
+
188
+ 参见:
189
+
190
+ - `aimd/docs/zh/packages/type-plugins.md`
191
+
192
+ ### 仅题目控件
193
+
194
+ ```vue
195
+ <script setup lang="ts">
196
+ import { ref } from "vue"
197
+ import { AimdQuizRecorder } from "@airalogy/aimd-recorder"
198
+ import "@airalogy/aimd-recorder/styles"
199
+
200
+ const answer = ref("")
201
+ const quiz = {
202
+ id: "quiz_single_1",
203
+ type: "choice",
204
+ mode: "single",
205
+ stem: "请选择一个选项",
206
+ options: [
207
+ { key: "A", text: "选项 A" },
208
+ { key: "B", text: "选项 B" },
209
+ ],
210
+ }
211
+ </script>
212
+
213
+ <template>
214
+ <AimdQuizRecorder v-model="answer" :quiz="quiz" locale="zh-CN" />
215
+ </template>
216
+ ```
217
+
218
+ `AimdQuizRecorder` 也支持 `scale` 量表题。对于可确定性自动评分的量表,既可以继续传外部 `grade`,也可以通过 `scaleGradeDisplayMode="completed"` 或 `scaleGradeDisplayMode="submitted"` 控制本地总分和分组结果何时显示。
219
+
220
+ ## 文档
221
+
222
+ - EN: <https://airalogy.github.io/aimd/en/packages/aimd-recorder>
223
+ - 中文: <https://airalogy.github.io/aimd/zh/packages/aimd-recorder>
224
+ - 文档源码:`aimd/docs/en/packages/aimd-recorder.md`、`aimd/docs/zh/packages/aimd-recorder.md`
@@ -0,0 +1,172 @@
1
+ import { defineComponent as j, ref as d, onMounted as V, onBeforeUnmount as B, watch as v, openBlock as u, createElementBlock as c, normalizeClass as D, createElementVNode as _, Fragment as L, createCommentVNode as F } from "vue";
2
+ import { _ as z } from "./_commonjsHelpers-CZXJ37nu.js";
3
+ function $(n) {
4
+ return new Worker(
5
+ "/assets/editor.worker-CpuX8TSY.js",
6
+ {
7
+ name: n?.name
8
+ }
9
+ );
10
+ }
11
+ function x(n) {
12
+ return new Worker(
13
+ "/assets/css.worker-Dmf38jDD.js",
14
+ {
15
+ name: n?.name
16
+ }
17
+ );
18
+ }
19
+ function P(n) {
20
+ return new Worker(
21
+ "/assets/html.worker-DotaEs7v.js",
22
+ {
23
+ name: n?.name
24
+ }
25
+ );
26
+ }
27
+ function S(n) {
28
+ return new Worker(
29
+ "/assets/json.worker-B4VHhH6h.js",
30
+ {
31
+ name: n?.name
32
+ }
33
+ );
34
+ }
35
+ function T(n) {
36
+ return new Worker(
37
+ "/assets/ts.worker-sl17zBDo.js",
38
+ {
39
+ name: n?.name
40
+ }
41
+ );
42
+ }
43
+ const I = {
44
+ css: () => import("./monaco.contribution-b5xkgQ-s.js"),
45
+ scss: () => import("./monaco.contribution-b5xkgQ-s.js"),
46
+ less: () => import("./monaco.contribution-b5xkgQ-s.js"),
47
+ html: () => import("./monaco.contribution-C-bQhUTI.js"),
48
+ javascript: () => import("./monaco.contribution-Col-f0XR.js"),
49
+ typescript: () => import("./monaco.contribution-Col-f0XR.js"),
50
+ json: () => import("./monaco.contribution-CCVvl3Jx.js"),
51
+ ini: () => import("./ini.contribution-DyWtiacL.js"),
52
+ markdown: () => import("./markdown.contribution-DYYk6zUU.js"),
53
+ python: () => import("./python.contribution-CcKs2Ktm.js"),
54
+ shell: () => import("./shell.contribution-B80NZ3iO.js"),
55
+ sql: () => import("./sql.contribution-DQy36aE5.js"),
56
+ xml: () => import("./xml.contribution-XMOaon8i.js"),
57
+ yaml: () => import("./yaml.contribution-DRRVhJmJ.js")
58
+ }, b = /* @__PURE__ */ new Map();
59
+ function N() {
60
+ typeof globalThis > "u" || typeof globalThis.MonacoEnvironment?.getWorker == "function" || (globalThis.MonacoEnvironment = {
61
+ getWorker(a, o) {
62
+ return o === "json" ? new S() : o === "css" || o === "scss" || o === "less" ? new x() : o === "html" || o === "handlebars" || o === "razor" ? new P() : o === "typescript" || o === "javascript" ? new T() : new $();
63
+ }
64
+ });
65
+ }
66
+ async function h(n) {
67
+ const a = I[n];
68
+ if (!a)
69
+ return;
70
+ const o = b.get(n);
71
+ if (o)
72
+ return o;
73
+ const r = Promise.resolve(a()).then(() => {
74
+ });
75
+ return b.set(n, r), r;
76
+ }
77
+ const O = {
78
+ key: 0,
79
+ class: "aimd-code-field__fallback-shell"
80
+ }, A = ["value", "disabled"], H = {
81
+ key: 0,
82
+ class: "aimd-code-field__loading"
83
+ }, q = /* @__PURE__ */ j({
84
+ __name: "AimdCodeField",
85
+ props: {
86
+ modelValue: { default: "" },
87
+ language: {},
88
+ disabled: { type: Boolean, default: !1 }
89
+ },
90
+ emits: ["update:modelValue", "blur"],
91
+ setup(n, { emit: a }) {
92
+ const o = n, r = a, m = d(null), f = d(!0), p = d(null), i = d(k(o.modelValue));
93
+ let s = null, t = null, l = null, g = !1;
94
+ function k(e) {
95
+ return typeof e == "string" ? e : typeof e == "number" ? String(e) : "";
96
+ }
97
+ function y(e) {
98
+ e !== i.value && (i.value = e, r("update:modelValue", e));
99
+ }
100
+ async function W(e) {
101
+ !s || !l || (await h(e), s.editor.setModelLanguage(l, e));
102
+ }
103
+ async function C() {
104
+ if (!(!m.value || t)) {
105
+ f.value = !0, p.value = null;
106
+ try {
107
+ N(), s = await import("./editor.main-Du02abDl.js"), await h(o.language), t = s.editor.create(m.value, {
108
+ value: i.value,
109
+ language: o.language,
110
+ theme: "vs",
111
+ minimap: { enabled: !1 },
112
+ scrollBeyondLastLine: !1,
113
+ automaticLayout: !0,
114
+ lineNumbers: "on",
115
+ wordWrap: "on",
116
+ tabSize: 2,
117
+ padding: { top: 12, bottom: 12 },
118
+ readOnly: o.disabled
119
+ }), l = t.getModel(), t.onDidChangeModelContent(() => {
120
+ g || !t || y(t.getValue());
121
+ }), t.onDidBlurEditorWidget(() => {
122
+ r("blur");
123
+ });
124
+ } catch (e) {
125
+ p.value = e instanceof Error ? e.message : "Failed to load Monaco editor.";
126
+ } finally {
127
+ f.value = !1;
128
+ }
129
+ }
130
+ }
131
+ function E(e) {
132
+ i.value = e, !(!t || e === t.getValue()) && (g = !0, t.setValue(e), g = !1);
133
+ }
134
+ function M(e) {
135
+ y(e.target.value);
136
+ }
137
+ return V(() => {
138
+ C();
139
+ }), B(() => {
140
+ t?.dispose(), l?.dispose();
141
+ }), v(() => o.modelValue, (e) => {
142
+ E(k(e));
143
+ }), v(() => o.disabled, (e) => {
144
+ t?.updateOptions({ readOnly: e });
145
+ }), v(() => o.language, async (e) => {
146
+ t && await W(e);
147
+ }), (e, w) => (u(), c("div", {
148
+ class: D(["aimd-code-field", { "aimd-code-field--disabled": n.disabled }])
149
+ }, [
150
+ p.value ? (u(), c("div", O, [
151
+ _("textarea", {
152
+ class: "aimd-code-field__fallback",
153
+ value: i.value,
154
+ disabled: n.disabled,
155
+ spellcheck: "false",
156
+ onInput: M,
157
+ onBlur: w[0] || (w[0] = (U) => r("blur"))
158
+ }, null, 40, A)
159
+ ])) : (u(), c(L, { key: 1 }, [
160
+ f.value ? (u(), c("div", H, "Loading code editor…")) : F("", !0),
161
+ _("div", {
162
+ ref_key: "editorContainer",
163
+ ref: m,
164
+ class: "aimd-code-field__editor"
165
+ }, null, 512)
166
+ ], 64))
167
+ ], 2));
168
+ }
169
+ }), G = /* @__PURE__ */ z(q, [["__scopeId", "data-v-b814be63"]]);
170
+ export {
171
+ G as default
172
+ };