@airalogy/aimd-recorder 1.23.0 → 1.24.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 (81) hide show
  1. package/README.md +19 -0
  2. package/README.zh-CN.md +19 -0
  3. package/dist/{AimdCodeField-BN_0UQMx.js → AimdCodeField-CPjcXY4D.js} +1 -1
  4. package/dist/{AimdDnaSequenceField-JzxsGmRf.js → AimdDnaSequenceField-Dz-IONoA.js} +5 -4
  5. package/dist/{AimdEditor.vue_vue_type_style_index_0_lang-v82TdP_I.js → AimdEditor.vue_vue_type_style_index_0_lang-JAD--qFs.js} +23 -3
  6. package/dist/{AimdEntityRefField-O0FwJDC0.js → AimdEntityRefField-BE0s2o5T.js} +10 -10
  7. package/dist/{AimdMarkdownField-Dd6M3zOI.js → AimdMarkdownField-BeD2t9JY.js} +19 -19
  8. package/dist/{AimdMarkdownNoteField-DCkJg80X.js → AimdMarkdownNoteField-DIgGEYpj.js} +13 -13
  9. package/dist/{_commonjsHelpers-B5RozER-.js → _commonjsHelpers-ByX85dGu.js} +12 -19
  10. package/dist/_plugin-vue_export-helper-CHgC5LLL.js +9 -0
  11. package/dist/aimd-recorder.css +1 -1
  12. package/dist/{arc-Bw7VOW6S.js → arc-CLJJdrm0.js} +1 -1
  13. package/dist/{architectureDiagram-3BPJPVTR-B4RdL02h.js → architectureDiagram-3BPJPVTR-BizrFPnS.js} +3 -3
  14. package/dist/{blockDiagram-GPEHLZMM-B5skMgx6.js → blockDiagram-GPEHLZMM-IHDih8JW.js} +4 -4
  15. package/dist/{c4Diagram-AAUBKEIU-DDxL4a7C.js → c4Diagram-AAUBKEIU-BQtg8m_M.js} +2 -2
  16. package/dist/{channel-CQ1fnqoz.js → channel-D8q7AX1Z.js} +1 -1
  17. package/dist/{chunk-2J33WTMH-B08Yr5NK.js → chunk-2J33WTMH-C24lbKon.js} +1 -1
  18. package/dist/{chunk-4BX2VUAB-CyCffaPa.js → chunk-4BX2VUAB-1m_lB_xe.js} +1 -1
  19. package/dist/{chunk-55IACEB6-CztHyBOI.js → chunk-55IACEB6-BE5Nj-sd.js} +1 -1
  20. package/dist/{chunk-727SXJPM-CEVNkjmn.js → chunk-727SXJPM-Cg-Xw_d_.js} +5 -5
  21. package/dist/{chunk-AQP2D5EJ-C9t9hFOg.js → chunk-AQP2D5EJ-BvRpPCiY.js} +3 -3
  22. package/dist/{chunk-FMBD7UC4-ulCTg3qb.js → chunk-FMBD7UC4-D_44MTsg.js} +1 -1
  23. package/dist/{chunk-ND2GUHAM-D4Cbj52r.js → chunk-ND2GUHAM-tVBIo4LA.js} +1 -1
  24. package/dist/{chunk-QZHKN3VN-Rpw3UPGi.js → chunk-QZHKN3VN-B91HYLks.js} +1 -1
  25. package/dist/{classDiagram-v2-Q7XG4LA2-D8dNLFoj.js → classDiagram-4FO5ZUOK-CkejvTAN.js} +2 -2
  26. package/dist/{classDiagram-4FO5ZUOK-D8dNLFoj.js → classDiagram-v2-Q7XG4LA2-CkejvTAN.js} +2 -2
  27. package/dist/components.js +3662 -3465
  28. package/dist/composables.js +104 -103
  29. package/dist/{cose-bilkent-S5V4N54A-CzjADqxr.js → cose-bilkent-S5V4N54A-CNcuriOF.js} +2 -2
  30. package/dist/{dagre-BM42HDAG-C79MwQe7.js → dagre-BM42HDAG-DMqFGafq.js} +3 -3
  31. package/dist/{diagram-2AECGRRQ-DaQ7DMBK.js → diagram-2AECGRRQ-Cksd3pP3.js} +2 -2
  32. package/dist/{diagram-5GNKFQAL-BpWKnfL3.js → diagram-5GNKFQAL-SVjLnDJG.js} +3 -3
  33. package/dist/{diagram-KO2AKTUF-CedxET4p.js → diagram-KO2AKTUF-DfNIAG6w.js} +2 -2
  34. package/dist/{diagram-LMA3HP47-FKe9tb0g.js → diagram-LMA3HP47-DPOyCMGB.js} +2 -2
  35. package/dist/{diagram-OG6HWLK6-Bmb8IKvp.js → diagram-OG6HWLK6-BDURmT37.js} +3 -3
  36. package/dist/{erDiagram-TEJ5UH35-Chalz_c9.js → erDiagram-TEJ5UH35-N991qII9.js} +4 -4
  37. package/dist/{flowDiagram-I6XJVG4X-DPelWotf.js → flowDiagram-I6XJVG4X-BABRFuk-.js} +6 -6
  38. package/dist/{ganttDiagram-6RSMTGT7-o_Jm8a5l.js → ganttDiagram-6RSMTGT7-BMDnK96S.js} +3 -3
  39. package/dist/{gitGraphDiagram-PVQCEYII-BiwDVfiM.js → gitGraphDiagram-PVQCEYII-cEvL7Dss.js} +3 -3
  40. package/dist/{graph-_GsibXVP.js → graph-BA09aCvZ.js} +1 -1
  41. package/dist/index.js +118 -112
  42. package/dist/{infoDiagram-5YYISTIA-CaVHW6oJ.js → infoDiagram-5YYISTIA-DpC1Zthd.js} +1 -1
  43. package/dist/{ishikawaDiagram-YF4QCWOH--qCCMUuo.js → ishikawaDiagram-YF4QCWOH-CMEt_f-x.js} +1 -1
  44. package/dist/{journeyDiagram-JHISSGLW-BsT-p1ex.js → journeyDiagram-JHISSGLW-C0Qw169C.js} +4 -4
  45. package/dist/{kanban-definition-UN3LZRKU-oCTOaobR.js → kanban-definition-UN3LZRKU-caROmSUy.js} +2 -2
  46. package/dist/{layout-CAhsv4x8.js → layout-CH65__O4.js} +2 -2
  47. package/dist/{linear-CumggsyF.js → linear-B1VXpcsy.js} +1 -1
  48. package/dist/{mermaid.core-D4wVfZ2X.js → mermaid.core-Cbmwvfvk.js} +35 -35
  49. package/dist/{mindmap-definition-RKZ34NQL-NTgweVec.js → mindmap-definition-RKZ34NQL-DpTR5ilS.js} +3 -3
  50. package/dist/{pieDiagram-4H26LBE5-C1UJkrIn.js → pieDiagram-4H26LBE5-Cb_KrmWC.js} +3 -3
  51. package/dist/{quadrantDiagram-W4KKPZXB-rCJc8QbP.js → quadrantDiagram-W4KKPZXB-B5_NswmK.js} +2 -2
  52. package/dist/record.js +77 -72
  53. package/dist/{requirementDiagram-4Y6WPE33-BzHGaPaB.js → requirementDiagram-4Y6WPE33-OFwfat5D.js} +3 -3
  54. package/dist/{sankeyDiagram-5OEKKPKP-B--uus9e.js → sankeyDiagram-5OEKKPKP-BaawdZEE.js} +1 -1
  55. package/dist/{sequenceDiagram-3UESZ5HK-D7javnYQ.js → sequenceDiagram-3UESZ5HK-DLv8X8ef.js} +3 -3
  56. package/dist/{stateDiagram-AJRCARHV-DPsstQ8f.js → stateDiagram-AJRCARHV-B6F3wrsd.js} +4 -4
  57. package/dist/{stateDiagram-v2-BHNVJYJU-BhhRcq6R.js → stateDiagram-v2-BHNVJYJU-BcNEoshv.js} +2 -2
  58. package/dist/{timeline-definition-PNZ67QCA-DgnJrK74.js → timeline-definition-PNZ67QCA-CvdHJ4eQ.js} +2 -2
  59. package/dist/useCodeBlockRendering-D2viVPtA.js +3158 -0
  60. package/dist/useFieldRendering-Co4DOOvL.js +1120 -0
  61. package/dist/{index-CGb0O6x4.js → useVarHelpers-Du2obGza.js} +1663 -849
  62. package/dist/validation-oyqyD7Jp.js +5601 -0
  63. package/dist/{vennDiagram-CIIHVFJN-D1Q51ENl.js → vennDiagram-CIIHVFJN-U0GlQDjX.js} +1 -1
  64. package/dist/{wardleyDiagram-YWT4CUSO-DMfLoeaa.js → wardleyDiagram-YWT4CUSO-CzF_KMcn.js} +2 -2
  65. package/dist/{xychartDiagram-2RQKCTM6-DzF8t-UA.js → xychartDiagram-2RQKCTM6-Cljki2Vk.js} +2 -2
  66. package/package.json +7 -5
  67. package/src/__tests__/record-validation.test.ts +378 -0
  68. package/src/__tests__/recorder-wysiwyg-field-host.test.ts +26 -0
  69. package/src/components/AimdRecorder.vue +176 -5
  70. package/src/components/AimdRecorderEditor.vue +28 -1
  71. package/src/components/AimdRecorderWysiwygFieldHost.vue +4 -0
  72. package/src/components/AimdRecorderWysiwygSurface.vue +135 -4
  73. package/src/components/AimdVarTableField.vue +38 -21
  74. package/src/components/recorderMilkdownPlugin.ts +7 -0
  75. package/src/index.ts +12 -0
  76. package/src/locales.ts +30 -0
  77. package/src/record/index.ts +14 -0
  78. package/src/record/validation.ts +772 -0
  79. package/src/styles/recorder.css +32 -0
  80. package/src/types.ts +41 -0
  81. package/dist/useCodeBlockRendering-f5pBgZ96.js +0 -5083
@@ -1,4 +1,4 @@
1
- import { aU as Gt, s as Wt, g as Kt, t as Ht, q as Yt, a as Xt, b as Zt, _ as w, F as wt, L as Jt, d as ot, al as Qt, ac as $t, ad as te, ae as ee, e as ne, A as se, H as ie, I as oe } from "./mermaid.core-D4wVfZ2X.js";
1
+ import { aU as Gt, s as Wt, g as Kt, t as Ht, q as Yt, a as Xt, b as Zt, _ as w, F as wt, L as Jt, d as ot, al as Qt, ac as $t, ad as te, ae as ee, e as ne, A as se, H as ie, I as oe } from "./mermaid.core-Cbmwvfvk.js";
2
2
  const kt = (t, n) => Gt(t, "a", -n), _t = 1e-10;
3
3
  function st(t, n) {
4
4
  const s = ae(t), e = s.filter((c) => re(c, t));
@@ -1,5 +1,5 @@
1
- import { s as Mt, g as Nt, t as Lt, q as zt, a as Tt, b as At, _ as u, a1 as Xt, F as Et, H as J, l as Q, L as Yt, e as It, A as Ft, c as V } from "./mermaid.core-D4wVfZ2X.js";
2
- import { p as Bt } from "./chunk-4BX2VUAB-CyCffaPa.js";
1
+ import { s as Mt, g as Nt, t as Lt, q as zt, a as Tt, b as At, _ as u, a1 as Xt, F as Et, H as J, l as Q, L as Yt, e as It, A as Ft, c as V } from "./mermaid.core-Cbmwvfvk.js";
2
+ import { p as Bt } from "./chunk-4BX2VUAB-1m_lB_xe.js";
3
3
  import { p as Rt } from "./wardley-L42UT6IY-D7b2ujEZ.js";
4
4
  var G = /* @__PURE__ */ u((o, r) => {
5
5
  const e = o <= 1 ? o * 100 : o;
@@ -1,7 +1,7 @@
1
- import { s as gi, g as xi, t as Xt, q as di, a as fi, b as pi, _ as a, l as Yt, L as mi, e as yi, A as bi, F as _t, i as Ai, H as Nt, I as wi, a1 as Ci, am as Si, a9 as Wt } from "./mermaid.core-D4wVfZ2X.js";
1
+ import { s as gi, g as xi, t as Xt, q as di, a as fi, b as pi, _ as a, l as Yt, L as mi, e as yi, A as bi, F as _t, i as Ai, H as Nt, I as wi, a1 as Ci, am as Si, a9 as Wt } from "./mermaid.core-Cbmwvfvk.js";
2
2
  import { i as _i } from "./init-DjUOC4st.js";
3
3
  import { o as ki } from "./ordinal-B6-f3MAq.js";
4
- import { l as zt } from "./linear-CumggsyF.js";
4
+ import { l as zt } from "./linear-B1VXpcsy.js";
5
5
  function Ri(e, t, i) {
6
6
  e = +e, t = +t, i = (n = arguments.length) < 2 ? (t = e, e = 0, 1) : n < 3 ? 1 : +i;
7
7
  for (var s = -1, n = Math.max(0, Math.ceil((t - e) / i)) | 0, o = new Array(n); ++s < n; )
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@airalogy/aimd-recorder",
3
3
  "type": "module",
4
- "version": "1.23.0",
4
+ "version": "1.24.1",
5
5
  "description": "AIMD (Airalogy Markdown) recorder Vue components and UI",
6
6
  "license": "Apache-2.0",
7
7
  "repository": {
@@ -58,19 +58,21 @@
58
58
  },
59
59
  "dependencies": {
60
60
  "@milkdown/kit": "^7.18.0",
61
+ "@types/react": "^19.2.14",
62
+ "@types/react-dom": "^19.2.3",
63
+ "ajv": "^8.12.0",
64
+ "ajv-formats": "^2.1.1",
61
65
  "mermaid": "^11.15.0",
62
66
  "monaco-editor": "^0.52.2",
63
67
  "react": "^19.2.4",
64
68
  "react-dom": "^19.2.4",
65
69
  "seqviz": "^3.10.18",
66
70
  "@airalogy/aimd-core": "^2.14.0",
67
- "@airalogy/aimd-renderer": "^2.11.0",
68
- "@airalogy/aimd-editor": "^1.11.0"
71
+ "@airalogy/aimd-editor": "^1.11.0",
72
+ "@airalogy/aimd-renderer": "^2.11.1"
69
73
  },
70
74
  "devDependencies": {
71
75
  "@types/node": "^24.3.0",
72
- "@types/react": "^19.2.14",
73
- "@types/react-dom": "^19.2.3",
74
76
  "@vitejs/plugin-vue": "^6.0.1",
75
77
  "@vueuse/core": "^13.5.0",
76
78
  "naive-ui": "2.41.0",
@@ -0,0 +1,378 @@
1
+ import type { ExtractedAimdFields } from "@airalogy/aimd-core/types"
2
+ import { flushPromises, mount } from "@vue/test-utils"
3
+ import { describe, expect, it, vi } from "vitest"
4
+ import AimdRecorder from "../components/AimdRecorder.vue"
5
+ import { createAimdRecorderMessages } from "../locales"
6
+ import { validateAimdField, validateAimdRecord } from "../record/validation"
7
+ import { createEmptyProtocolRecordData } from "../types"
8
+
9
+ const EMPTY_FIELDS: ExtractedAimdFields = {
10
+ var: [],
11
+ var_definitions: [],
12
+ var_table: [],
13
+ client_assigner: [],
14
+ quiz: [],
15
+ step: [],
16
+ check: [],
17
+ ref_step: [],
18
+ ref_var: [],
19
+ }
20
+
21
+ const messages = createAimdRecorderMessages("en-US").validation
22
+
23
+ describe("AimdRecorder validation", () => {
24
+ it("validates inferred required, pattern, numeric, and every table cell constraint", () => {
25
+ const record = createEmptyProtocolRecordData()
26
+ record.var.code = "bad"
27
+ record.var.temperature = 12
28
+ record.var.samples = [{ concentration: "", sample_id: "" }]
29
+
30
+ const result = validateAimdRecord({
31
+ ...EMPTY_FIELDS,
32
+ var: ["name", "code", "temperature"],
33
+ var_definitions: [
34
+ { id: "name", title: "Name" },
35
+ { id: "code", title: "Code", kwargs: { pattern: "^[A-Z]+$" } },
36
+ { id: "temperature", title: "Temperature", type: "float", kwargs: { lt: 10 } },
37
+ ],
38
+ var_table: [{
39
+ id: "samples",
40
+ scope: "var_table",
41
+ subvars: [
42
+ { id: "concentration", title: "Concentration" },
43
+ { id: "sample_id", title: "Sample ID" },
44
+ ],
45
+ }],
46
+ }, record, {
47
+ fieldMeta: {
48
+ "var_table:samples:concentration": { required: true },
49
+ "var_table:samples:sample_id": { required: true },
50
+ },
51
+ messages,
52
+ })
53
+
54
+ expect(result.valid).toBe(false)
55
+ expect(result.issues.map(issue => [issue.fieldKey, issue.code])).toEqual([
56
+ ["var:name", "required"],
57
+ ["var:code", "pattern"],
58
+ ["var:temperature", "numeric"],
59
+ ["var_table:samples:0:concentration", "required"],
60
+ ["var_table:samples:0:sample_id", "required"],
61
+ ])
62
+ expect(result.fieldState["var_table:samples:0:concentration"]?.validationError).toContain("Row 1")
63
+ })
64
+
65
+ it("consumes Pydantic JSON Schema as the authoritative validation contract", () => {
66
+ const record = createEmptyProtocolRecordData()
67
+ record.var.name = ""
68
+ record.var.age = "17"
69
+ record.var.started_at = "not-a-date"
70
+ record.var.status = "unknown"
71
+ record.var.samples = [{ concentration: "bad", code: "" }]
72
+
73
+ const fields: ExtractedAimdFields = {
74
+ ...EMPTY_FIELDS,
75
+ var: ["name", "age", "started_at", "status"],
76
+ var_definitions: [
77
+ { id: "name", title: "Name", type: "str" },
78
+ { id: "age", title: "Age", type: "int" },
79
+ { id: "started_at", title: "Started at", type: "datetime" },
80
+ { id: "status", title: "Status", type: "str" },
81
+ ],
82
+ var_table: [{
83
+ id: "samples",
84
+ scope: "var_table",
85
+ subvars: [
86
+ { id: "concentration", title: "Concentration", type: "float" },
87
+ { id: "code", title: "Code", type: "str" },
88
+ ],
89
+ }],
90
+ }
91
+
92
+ const result = validateAimdRecord(fields, record, {
93
+ schema: {
94
+ vars: {
95
+ type: "object",
96
+ required: ["name", "age", "started_at", "status", "samples"],
97
+ properties: {
98
+ name: { type: "string", minLength: 1 },
99
+ age: { type: "integer", minimum: 18 },
100
+ started_at: { type: "string", format: "date-time" },
101
+ status: { enum: ["draft", "complete"] },
102
+ samples: {
103
+ type: "array",
104
+ items: {
105
+ type: "object",
106
+ required: ["concentration", "code"],
107
+ properties: {
108
+ concentration: { type: "number", exclusiveMinimum: 0 },
109
+ code: { type: "string", pattern: "^[A-Z]+$" },
110
+ },
111
+ },
112
+ },
113
+ },
114
+ },
115
+ },
116
+ messages,
117
+ })
118
+
119
+ expect(result.valid).toBe(false)
120
+ expect(result.issues).toEqual(expect.arrayContaining([
121
+ expect.objectContaining({ fieldKey: "var:name", code: "required" }),
122
+ expect.objectContaining({ fieldKey: "var:age", code: "numeric" }),
123
+ expect.objectContaining({ fieldKey: "var:started_at", code: "format" }),
124
+ expect.objectContaining({ fieldKey: "var:status", code: "enum" }),
125
+ expect.objectContaining({ fieldKey: "var_table:samples:0:concentration", code: "type" }),
126
+ expect.objectContaining({ fieldKey: "var_table:samples:0:code", code: "required" }),
127
+ ]))
128
+ })
129
+
130
+ it("resolves required table columns through Pydantic local references", () => {
131
+ const record = createEmptyProtocolRecordData()
132
+ record.var.samples = [{ code: "" }]
133
+ const fields: ExtractedAimdFields = {
134
+ ...EMPTY_FIELDS,
135
+ var_table: [{
136
+ id: "samples",
137
+ scope: "var_table",
138
+ subvars: [{ id: "code", type: "str" }],
139
+ }],
140
+ }
141
+
142
+ const result = validateAimdRecord(fields, record, {
143
+ schema: {
144
+ vars: {
145
+ type: "object",
146
+ required: ["samples"],
147
+ properties: {
148
+ samples: { type: "array", items: { $ref: "#/$defs/Sample" } },
149
+ },
150
+ $defs: {
151
+ Sample: {
152
+ type: "object",
153
+ required: ["code"],
154
+ properties: { code: { type: "string" } },
155
+ },
156
+ },
157
+ },
158
+ },
159
+ messages,
160
+ })
161
+
162
+ expect(result.issues).toEqual([
163
+ expect.objectContaining({
164
+ fieldKey: "var_table:samples:0:code",
165
+ code: "required",
166
+ }),
167
+ ])
168
+ })
169
+
170
+ it("reports an empty schema-required numeric input as required instead of a type error", () => {
171
+ const record = createEmptyProtocolRecordData()
172
+ record.var.count = ""
173
+
174
+ const result = validateAimdRecord({
175
+ ...EMPTY_FIELDS,
176
+ var: ["count"],
177
+ var_definitions: [{ id: "count", type: "int" }],
178
+ }, record, {
179
+ schema: {
180
+ vars: {
181
+ type: "object",
182
+ required: ["count"],
183
+ properties: { count: { type: "integer" } },
184
+ },
185
+ },
186
+ messages,
187
+ })
188
+
189
+ expect(result.issues).toEqual([
190
+ expect.objectContaining({ fieldKey: "var:count", code: "required" }),
191
+ ])
192
+ })
193
+
194
+ it("lets a supplied schema override an AIMD annotation without duplicating Python rules", () => {
195
+ const record = createEmptyProtocolRecordData()
196
+ record.var.age = "custom-model-string"
197
+
198
+ const result = validateAimdRecord({
199
+ ...EMPTY_FIELDS,
200
+ var: ["age"],
201
+ var_definitions: [{ id: "age", type: "int", kwargs: { ge: 18 } }],
202
+ }, record, {
203
+ schema: {
204
+ research_variable: {
205
+ type: "object",
206
+ required: ["age"],
207
+ properties: { age: { type: "string" } },
208
+ },
209
+ },
210
+ messages,
211
+ })
212
+
213
+ expect(result).toEqual({ valid: true, issues: [], fieldState: {} })
214
+ })
215
+
216
+ it("normalizes file wrappers and validates ordinary array and object values with the schema", () => {
217
+ const record = createEmptyProtocolRecordData()
218
+ record.var.attachment = { airalogy_file_id: "airalogy.id.file.report.pdf" }
219
+ record.var.tags = ["alpha", "beta"]
220
+ record.var.settings = { enabled: true }
221
+
222
+ const result = validateAimdRecord({
223
+ ...EMPTY_FIELDS,
224
+ var: ["attachment", "tags", "settings"],
225
+ var_definitions: [
226
+ { id: "attachment", type: "FileIdPDF" },
227
+ { id: "tags", type: "list[str]" },
228
+ { id: "settings", type: "dict" },
229
+ ],
230
+ }, record, {
231
+ schema: {
232
+ vars: {
233
+ type: "object",
234
+ required: ["attachment", "tags", "settings"],
235
+ properties: {
236
+ attachment: { type: "string", pattern: "^airalogy\\.id\\.file\\." },
237
+ tags: { type: "array", minItems: 2, items: { type: "string" } },
238
+ settings: {
239
+ type: "object",
240
+ required: ["enabled"],
241
+ properties: { enabled: { type: "boolean" } },
242
+ },
243
+ },
244
+ },
245
+ },
246
+ messages,
247
+ })
248
+
249
+ expect(result.valid).toBe(true)
250
+ })
251
+
252
+ it("can validate and clear one exact table cell without collapsing to the table key", () => {
253
+ const record = createEmptyProtocolRecordData()
254
+ record.var.samples = [{ concentration: "", sample_id: "" }]
255
+ const fields: ExtractedAimdFields = {
256
+ ...EMPTY_FIELDS,
257
+ var_table: [{
258
+ id: "samples",
259
+ scope: "var_table",
260
+ subvars: [{ id: "concentration" }, { id: "sample_id" }],
261
+ }],
262
+ }
263
+
264
+ const result = validateAimdField(fields, record, "var_table:samples:0:sample_id", {
265
+ fieldMeta: {
266
+ "var_table:samples:concentration": { required: true },
267
+ "var_table:samples:sample_id": { required: true },
268
+ },
269
+ messages,
270
+ })
271
+
272
+ expect(result.issues).toHaveLength(1)
273
+ expect(result.issues[0]).toMatchObject({
274
+ fieldKey: "var_table:samples:0:sample_id",
275
+ rowIndex: 0,
276
+ column: "sample_id",
277
+ })
278
+ expect(result.validatedFieldKeys).toEqual(["var_table:samples:0:sample_id"])
279
+ })
280
+
281
+ it("validates on change and preserves errors belonging to other fields", async () => {
282
+ const wrapper = mount(AimdRecorder, {
283
+ attachTo: document.body,
284
+ props: {
285
+ content: "First: {{var|first: str}}\n\nSecond: {{var|second: str}}",
286
+ validationSchema: {
287
+ vars: {
288
+ type: "object",
289
+ required: ["first", "second"],
290
+ properties: {
291
+ first: { type: "string" },
292
+ second: { type: "string" },
293
+ },
294
+ },
295
+ },
296
+ showSearch: false,
297
+ },
298
+ })
299
+ await flushPromises()
300
+
301
+ const recorder = wrapper.vm as unknown as {
302
+ validate: (options?: { focus?: boolean }) => Promise<{ valid: boolean }>
303
+ }
304
+ expect((await recorder.validate({ focus: false })).valid).toBe(false)
305
+ await flushPromises()
306
+ expect(wrapper.findAll(".aimd-rec-validation-message")).toHaveLength(2)
307
+
308
+ await wrapper.get('textarea[data-rec-focus-key="var:first"]').setValue("Alice")
309
+ await flushPromises()
310
+
311
+ const errors = wrapper.findAll(".aimd-rec-validation-message")
312
+ expect(errors).toHaveLength(1)
313
+ expect(errors[0].text()).toContain("second is required")
314
+ wrapper.unmount()
315
+ })
316
+
317
+ it("supports blur-only and submit-only immediate validation policies", async () => {
318
+ const wrapper = mount(AimdRecorder, {
319
+ props: {
320
+ content: "{{var|name: str}}",
321
+ validationTriggers: ["blur"],
322
+ showSearch: false,
323
+ },
324
+ })
325
+ await flushPromises()
326
+
327
+ const input = wrapper.get('textarea[data-rec-focus-key="var:name"]')
328
+ await input.setValue("Alice")
329
+ await input.setValue("")
330
+ await flushPromises()
331
+ expect(wrapper.find(".aimd-rec-validation-message").exists()).toBe(false)
332
+
333
+ await input.trigger("blur")
334
+ await flushPromises()
335
+ expect(wrapper.find(".aimd-rec-validation-message").exists()).toBe(true)
336
+
337
+ await wrapper.setProps({ validationTriggers: ["submit"] })
338
+ const recorder = wrapper.vm as unknown as {
339
+ clearValidation: () => void
340
+ validate: (options?: { focus?: boolean }) => Promise<{ valid: boolean }>
341
+ }
342
+ recorder.clearValidation()
343
+ await flushPromises()
344
+ await input.setValue("Bob")
345
+ await input.setValue("")
346
+ await input.trigger("blur")
347
+ await flushPromises()
348
+ expect(wrapper.find(".aimd-rec-validation-message").exists()).toBe(false)
349
+ expect((await recorder.validate({ focus: false })).valid).toBe(false)
350
+ wrapper.unmount()
351
+ })
352
+
353
+ it("renders and focuses the exact invalid table cell", async () => {
354
+ HTMLElement.prototype.scrollIntoView = vi.fn()
355
+ const wrapper = mount(AimdRecorder, {
356
+ attachTo: document.body,
357
+ props: {
358
+ content: "{{var_table|samples, subvars=[concentration: float, sample_id: str]}}",
359
+ fieldMeta: {
360
+ "var_table:samples:concentration": { required: true },
361
+ "var_table:samples:sample_id": { required: true },
362
+ },
363
+ showSearch: false,
364
+ },
365
+ })
366
+ await flushPromises()
367
+
368
+ const recorder = wrapper.vm as unknown as {
369
+ validate: (options?: { focus?: boolean }) => Promise<{ valid: boolean }>
370
+ }
371
+ expect((await recorder.validate()).valid).toBe(false)
372
+ await flushPromises()
373
+
374
+ expect(wrapper.find('[data-aimd-validation-field="var_table:samples:0:concentration"] .aimd-rec-validation-message').exists()).toBe(true)
375
+ expect(document.activeElement?.getAttribute("data-rec-focus-key")).toBe("var_table:samples:0:concentration")
376
+ wrapper.unmount()
377
+ })
378
+ })
@@ -12,6 +12,8 @@ function createSurfaceState(): RecorderMilkdownSurfaceState {
12
12
  choiceOptionExplanationMode: 'hidden',
13
13
  scaleGradeDisplayMode: 'hidden',
14
14
  stepDetailDisplay: 'auto',
15
+ validationTriggers: ['change', 'blur'],
16
+ validationEpoch: 0,
15
17
  onUpdateRecord: () => {},
16
18
  }
17
19
  }
@@ -33,4 +35,28 @@ describe('AimdRecorderWysiwygFieldHost', () => {
33
35
  expect(wrapper.html()).toContain('data-rec-focus-key="var:sample_name"')
34
36
  expect(wrapper.html()).not.toContain('aimd-field-chip')
35
37
  })
38
+
39
+ it('forwards the shared validation contract into embedded recorders', () => {
40
+ const schema = {
41
+ vars: {
42
+ type: 'object',
43
+ required: ['sample_name'],
44
+ properties: { sample_name: { type: 'string', minLength: 1 } },
45
+ },
46
+ }
47
+ const surfaceState = createSurfaceState()
48
+ surfaceState.validationSchema = schema
49
+ surfaceState.validationTriggers = ['blur']
50
+
51
+ const wrapper = mount(AimdRecorderWysiwygFieldHost, {
52
+ props: {
53
+ surfaceState,
54
+ rawContent: '{{var|sample_name: str}}',
55
+ displayMode: 'inline',
56
+ },
57
+ })
58
+ const recorder = wrapper.getComponent({ name: 'AimdRecorder' })
59
+ expect(recorder.props('validationSchema')).toEqual(schema)
60
+ expect(recorder.props('validationTriggers')).toEqual(['blur'])
61
+ })
36
62
  })