@airalogy/aimd-recorder 1.16.0 → 1.18.0

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 (110) hide show
  1. package/README.md +11 -10
  2. package/README.zh-CN.md +11 -10
  3. package/dist/AimdCodeField-BQUuM-EF.js +182 -0
  4. package/dist/{AimdDnaSequenceField-CPyMqIVh.js → AimdDnaSequenceField-KZU2Zj3E.js} +2 -2
  5. package/dist/{AimdEditor.vue_vue_type_style_index_0_lang-lyHIpch9.js → AimdEditor.vue_vue_type_style_index_0_lang-CzfYPp5r.js} +3924 -3831
  6. package/dist/AimdMarkdownField-t2d8uOeU.js +254 -0
  7. package/dist/AimdMarkdownNoteField-_h1oZSwH.js +259 -0
  8. package/dist/{_commonjsHelpers-CZXJ37nu.js → _commonjsHelpers-B5RozER-.js} +2 -2
  9. package/dist/aimd-recorder.css +1 -1
  10. package/dist/arc-DS_ocYoe.js +83 -0
  11. package/dist/architectureDiagram-3BPJPVTR-Dq2W8_tb.js +4692 -0
  12. package/dist/blockDiagram-GPEHLZMM-B4hnSAF_.js +2425 -0
  13. package/dist/c4Diagram-AAUBKEIU-CbffqNLY.js +1577 -0
  14. package/dist/channel-CtXnYrAk.js +5 -0
  15. package/dist/chunk-2J33WTMH-CROScrt5.js +19 -0
  16. package/dist/chunk-4BX2VUAB-DTmsQu5_.js +8 -0
  17. package/dist/chunk-55IACEB6-B5wDJzeX.js +8 -0
  18. package/dist/chunk-727SXJPM-CfyltY6o.js +1528 -0
  19. package/dist/chunk-AQP2D5EJ-B8274EYy.js +1387 -0
  20. package/dist/chunk-FMBD7UC4-CT_FK-SH.js +19 -0
  21. package/dist/chunk-ND2GUHAM-g9GulPi-.js +68 -0
  22. package/dist/chunk-QZHKN3VN-Di5HEktz.js +15 -0
  23. package/dist/classDiagram-4FO5ZUOK-BVUr246k.js +16 -0
  24. package/dist/classDiagram-v2-Q7XG4LA2-BVUr246k.js +16 -0
  25. package/dist/components.js +3365 -2216
  26. package/dist/composables.js +92 -68
  27. package/dist/cose-bilkent-S5V4N54A-GJ4IOO6v.js +2609 -0
  28. package/dist/cytoscape.esm-r59gEWFs.js +18710 -0
  29. package/dist/dagre-BM42HDAG-oL7Br44o.js +445 -0
  30. package/dist/defaultLocale-BgPVtth8.js +171 -0
  31. package/dist/diagram-2AECGRRQ-DtoCG_N4.js +217 -0
  32. package/dist/diagram-5GNKFQAL-f8QNdS7L.js +123 -0
  33. package/dist/diagram-KO2AKTUF-CsJOW_AX.js +461 -0
  34. package/dist/diagram-LMA3HP47-xmEKNZ7y.js +142 -0
  35. package/dist/diagram-OG6HWLK6-unpC7vo8.js +528 -0
  36. package/dist/erDiagram-TEJ5UH35-BGzFnCJD.js +899 -0
  37. package/dist/flowDiagram-I6XJVG4X-LBFhDnOs.js +1628 -0
  38. package/dist/ganttDiagram-6RSMTGT7-CFBc-jPD.js +2707 -0
  39. package/dist/gitGraphDiagram-PVQCEYII-BLduh-Rb.js +815 -0
  40. package/dist/graph-DdlKE625.js +1510 -0
  41. package/dist/index.js +104 -80
  42. package/dist/infoDiagram-5YYISTIA-CLQQI6zM.js +24 -0
  43. package/dist/init-DjUOC4st.js +16 -0
  44. package/dist/ishikawaDiagram-YF4QCWOH-CStdYBmW.js +621 -0
  45. package/dist/journeyDiagram-JHISSGLW-B6mRTzoE.js +834 -0
  46. package/dist/kanban-definition-UN3LZRKU-C-vnN5v4.js +724 -0
  47. package/dist/katex-DNob3HGn.js +11690 -0
  48. package/dist/layout-DDt0fz-M.js +1703 -0
  49. package/dist/linear-C-IAFdOt.js +259 -0
  50. package/dist/mermaid.core-CuZ3nINf.js +15940 -0
  51. package/dist/mindmap-definition-RKZ34NQL-TSZ1Vb3z.js +827 -0
  52. package/dist/ordinal-B6-f3MAq.js +61 -0
  53. package/dist/pieDiagram-4H26LBE5-DYok-1-k.js +163 -0
  54. package/dist/quadrantDiagram-W4KKPZXB-Cg856sbH.js +1024 -0
  55. package/dist/requirementDiagram-4Y6WPE33-BN9fGdlJ.js +882 -0
  56. package/dist/sankeyDiagram-5OEKKPKP-CDqTgonY.js +847 -0
  57. package/dist/sequenceDiagram-3UESZ5HK-Chjrc0-W.js +2891 -0
  58. package/dist/stateDiagram-AJRCARHV-DRyLHrdr.js +263 -0
  59. package/dist/stateDiagram-v2-BHNVJYJU-CZTIDHid.js +16 -0
  60. package/dist/timeline-definition-PNZ67QCA-Bc3D9AAG.js +1055 -0
  61. package/dist/{useFieldRendering-Dh6Kib_0.js → useCodeBlockRendering-qA6gj4vz.js} +3041 -2255
  62. package/dist/useMonacoAutoHeight-D4T-El3J.js +66 -0
  63. package/dist/vennDiagram-CIIHVFJN-CYAul48m.js +1557 -0
  64. package/dist/wardley-L42UT6IY-D7b2ujEZ.js +22512 -0
  65. package/dist/wardleyDiagram-YWT4CUSO-B7Tg0MG9.js +675 -0
  66. package/dist/xychartDiagram-2RQKCTM6-xWYVEqth.js +1342 -0
  67. package/package.json +8 -7
  68. package/src/__tests__/assigner-runner-dependent-data.test.ts +32 -0
  69. package/src/__tests__/markdown-field.test.ts +150 -1
  70. package/src/__tests__/markdown-note-field.test.ts +86 -3
  71. package/src/__tests__/quiz-recorder.test.ts +47 -0
  72. package/src/__tests__/recorder-assigner-control.test.ts +844 -0
  73. package/src/__tests__/recorder-check-field.test.ts +103 -0
  74. package/src/__tests__/recorder-editor.test.ts +17 -0
  75. package/src/__tests__/recorder-markdown-assigner-integration.test.ts +49 -0
  76. package/src/__tests__/step-field.test.ts +87 -4
  77. package/src/__tests__/type-plugins.test.ts +1 -0
  78. package/src/__tests__/var-field-render.test.ts +741 -1
  79. package/src/components/AimdCodeField.vue +24 -5
  80. package/src/components/AimdMarkdownField.vue +548 -11
  81. package/src/components/AimdMarkdownNoteField.vue +241 -30
  82. package/src/components/AimdQuizOptionFollowups.vue +121 -0
  83. package/src/components/AimdQuizRecorder.vue +79 -148
  84. package/src/components/AimdRecorder.vue +1620 -98
  85. package/src/components/AimdRecorderEditor.vue +276 -8
  86. package/src/components/AimdRecorderWysiwygFieldHost.vue +6 -0
  87. package/src/components/AimdRecorderWysiwygSurface.vue +32 -0
  88. package/src/components/AimdStepCheckField.vue +205 -51
  89. package/src/components/AimdVarField.vue +694 -25
  90. package/src/components/AimdVarTableField.vue +283 -110
  91. package/src/components/icons/AimdAssignerCalculatorIcon.vue +18 -0
  92. package/src/components/icons/AimdAssignerCloudStatusIcon.vue +22 -0
  93. package/src/components/recorderMilkdownPlugin.ts +14 -0
  94. package/src/composables/__tests__/useRecordState.test.ts +114 -0
  95. package/src/composables/__tests__/useVarHelpers.test.ts +133 -0
  96. package/src/composables/index.ts +27 -1
  97. package/src/composables/useAssignerRunner.ts +376 -0
  98. package/src/composables/useCodeBlockRendering.ts +51 -0
  99. package/src/composables/useFieldRendering.ts +32 -4
  100. package/src/composables/useMonacoAutoHeight.ts +127 -0
  101. package/src/composables/useRecordState.ts +40 -14
  102. package/src/composables/useVarHelpers.ts +377 -9
  103. package/src/index.ts +13 -0
  104. package/src/locales.ts +47 -2
  105. package/src/styles/aimd.css +171 -6
  106. package/src/type-plugins.ts +7 -0
  107. package/src/types.ts +93 -2
  108. package/dist/AimdCodeField-DC3DPvgc.js +0 -172
  109. package/dist/AimdMarkdownField-CX71bOdX.js +0 -67
  110. package/dist/AimdMarkdownNoteField--ssNIQfG.js +0 -186
@@ -1,7 +1,22 @@
1
1
  <script lang="ts">
2
- import { defineAsyncComponent, defineComponent, h, type PropType, type VNode } from "vue"
2
+ import { defineAsyncComponent, defineComponent, h, ref, watch, type PropType, type VNode } from "vue"
3
3
  import type { AimdVarNode } from "@airalogy/aimd-core/types"
4
- import type { AimdFieldMeta, AimdTypePlugin, AimdVarInputKind } from "../types"
4
+ import {
5
+ formatAimdExampleValue,
6
+ getAimdFieldDescription,
7
+ getAimdFieldDisplayLabel,
8
+ getAimdFieldExamples,
9
+ getAimdFieldTitle,
10
+ } from "@airalogy/aimd-core/utils"
11
+ import type {
12
+ AimdFieldMeta,
13
+ AimdFileInfoResolver,
14
+ AimdFileResolveContext,
15
+ AimdFileUploadHandler,
16
+ AimdResolvedFileInfo,
17
+ AimdTypePlugin,
18
+ AimdVarInputKind,
19
+ } from "../types"
5
20
  import type { AimdRecorderMessages } from "../locales"
6
21
  import { getAimdRecorderScopeLabel } from "../locales"
7
22
  import { resolveAimdCodeEditorLanguage } from "../code-types"
@@ -13,11 +28,240 @@ import {
13
28
  getNumericInputAttributes,
14
29
  syncAutoWrapTextareaHeight,
15
30
  toBooleanValue,
31
+ createSelectedFileValue,
32
+ getFileValueId,
33
+ getFileDisplayName,
34
+ getFileInputConfig,
35
+ getVarEnumSelectValue,
36
+ getVarEnumValueFromSelectValue,
16
37
  type NumericInputAttributes,
17
38
  } from "../composables/useVarHelpers"
18
39
 
19
40
  const AimdCodeField = defineAsyncComponent(() => import("./AimdCodeField.vue"))
20
41
 
42
+ function normalizeMetaString(value: unknown): string | undefined {
43
+ return typeof value === "string" && value.trim() ? value.trim() : undefined
44
+ }
45
+
46
+ function getFieldMetaExamples(meta?: AimdFieldMeta): unknown[] {
47
+ if (!meta) return []
48
+ if (Array.isArray(meta.examples)) {
49
+ return meta.examples.filter(value => value !== undefined && value !== null)
50
+ }
51
+ const singleExample = (meta as { example?: unknown }).example
52
+ return singleExample === undefined || singleExample === null ? [] : [singleExample]
53
+ }
54
+
55
+ interface FieldMetadataHelp {
56
+ tooltip: string
57
+ description?: string
58
+ examples: string[]
59
+ }
60
+
61
+ interface CsvPreviewState {
62
+ url: string
63
+ rows: string[][]
64
+ }
65
+
66
+ interface FileDisplayInfo {
67
+ id?: string
68
+ name?: string
69
+ url?: string
70
+ thumbnailUrl?: string
71
+ type?: string
72
+ size?: number
73
+ }
74
+
75
+ function parseCsvPreviewLine(line: string): string[] {
76
+ const cells: string[] = []
77
+ let current = ""
78
+ let inQuotes = false
79
+
80
+ for (let index = 0; index < line.length; index += 1) {
81
+ const char = line[index]
82
+ const nextChar = line[index + 1]
83
+ if (char === '"' && inQuotes && nextChar === '"') {
84
+ current += '"'
85
+ index += 1
86
+ } else if (char === '"') {
87
+ inQuotes = !inQuotes
88
+ } else if (char === "," && !inQuotes) {
89
+ cells.push(current.trim())
90
+ current = ""
91
+ } else {
92
+ current += char
93
+ }
94
+ }
95
+
96
+ cells.push(current.trim())
97
+ return cells
98
+ }
99
+
100
+ function parseCsvPreviewRows(text: string): string[][] {
101
+ return text
102
+ .split(/\r?\n/)
103
+ .map(line => line.trim())
104
+ .filter(Boolean)
105
+ .slice(0, 4)
106
+ .map(parseCsvPreviewLine)
107
+ }
108
+
109
+ function getFileRecordString(value: unknown, keys: string[]): string | undefined {
110
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
111
+ return undefined
112
+ }
113
+ const record = value as Record<string, unknown>
114
+ for (const key of keys) {
115
+ const item = record[key]
116
+ if (typeof item === "string" && item.trim()) {
117
+ return item.trim()
118
+ }
119
+ }
120
+ return undefined
121
+ }
122
+
123
+ function getFileRecordNumber(value: unknown, keys: string[]): number | undefined {
124
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
125
+ return undefined
126
+ }
127
+ const record = value as Record<string, unknown>
128
+ for (const key of keys) {
129
+ const item = record[key]
130
+ if (typeof item === "number" && Number.isFinite(item)) {
131
+ return item
132
+ }
133
+ }
134
+ return undefined
135
+ }
136
+
137
+ function normalizeResolvedFileInfo(
138
+ value: AimdResolvedFileInfo | string | null | undefined,
139
+ fallback: FileDisplayInfo = {},
140
+ ): FileDisplayInfo {
141
+ if (typeof value === "string") {
142
+ const trimmed = value.trim()
143
+ return /^(https?:|blob:|data:|\/)/i.test(trimmed)
144
+ ? { ...fallback, url: trimmed || fallback.url }
145
+ : fallback
146
+ }
147
+ if (!value || typeof value !== "object") {
148
+ return fallback
149
+ }
150
+ return {
151
+ id: getFileRecordString(value, ["id", "file_id", "fileId", "src"]) ?? fallback.id,
152
+ name: getFileRecordString(value, ["name", "fileName", "file_name", "filename", "originalName", "original_name"]) ?? fallback.name,
153
+ url: getFileRecordString(value, ["url", "downloadUrl", "src"]) ?? fallback.url,
154
+ thumbnailUrl: getFileRecordString(value, ["thumbnailUrl", "thumbnail_url"]) ?? fallback.thumbnailUrl,
155
+ type: getFileRecordString(value, ["type", "contentType", "content_type", "mimeType"]) ?? fallback.type,
156
+ size: getFileRecordNumber(value, ["size", "byteSize", "byte_size"]) ?? fallback.size,
157
+ }
158
+ }
159
+
160
+ function formatFileSize(size: number | undefined): string {
161
+ if (!Number.isFinite(size) || size === undefined || size < 0) {
162
+ return ""
163
+ }
164
+ if (size < 1024) {
165
+ return `${size} B`
166
+ }
167
+ const units = ["KB", "MB", "GB"]
168
+ let value = size / 1024
169
+ let unitIndex = 0
170
+ while (value >= 1024 && unitIndex < units.length - 1) {
171
+ value /= 1024
172
+ unitIndex += 1
173
+ }
174
+ return `${value >= 10 ? value.toFixed(0) : value.toFixed(1)} ${units[unitIndex]}`
175
+ }
176
+
177
+ function renderUtilityIcon(kind: "download" | "open" | "clear" | "replace" | "preview"): VNode {
178
+ const common = {
179
+ viewBox: "0 0 24 24",
180
+ width: "1em",
181
+ height: "1em",
182
+ fill: "none",
183
+ stroke: "currentColor",
184
+ "stroke-width": "2",
185
+ "stroke-linecap": "round",
186
+ "stroke-linejoin": "round",
187
+ "aria-hidden": "true",
188
+ }
189
+ if (kind === "download") {
190
+ return h("svg", common, [
191
+ h("path", { d: "M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4" }),
192
+ h("path", { d: "M7 10l5 5 5-5" }),
193
+ h("path", { d: "M12 15V3" }),
194
+ ])
195
+ }
196
+ if (kind === "open") {
197
+ return h("svg", common, [
198
+ h("path", { d: "M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6" }),
199
+ h("path", { d: "M15 3h6v6" }),
200
+ h("path", { d: "M10 14L21 3" }),
201
+ ])
202
+ }
203
+ if (kind === "replace") {
204
+ return h("svg", common, [
205
+ h("path", { d: "M21 12a9 9 0 0 1-15.5 6.2" }),
206
+ h("path", { d: "M3 12A9 9 0 0 1 18.5 5.8" }),
207
+ h("path", { d: "M18 2v4h-4" }),
208
+ h("path", { d: "M6 22v-4h4" }),
209
+ ])
210
+ }
211
+ if (kind === "preview") {
212
+ return h("svg", common, [
213
+ h("path", { d: "M2 12s4-7 10-7 10 7 10 7-4 7-10 7-10-7-10-7Z" }),
214
+ h("circle", { cx: "12", cy: "12", r: "3" }),
215
+ ])
216
+ }
217
+ return h("svg", common, [
218
+ h("path", { d: "M3 6h18" }),
219
+ h("path", { d: "M8 6V4h8v2" }),
220
+ h("path", { d: "M19 6l-1 14H6L5 6" }),
221
+ h("path", { d: "M10 11v5" }),
222
+ h("path", { d: "M14 11v5" }),
223
+ ])
224
+ }
225
+
226
+ function createFieldMetadataHelp(description: string | undefined, examples: unknown[]): FieldMetadataHelp {
227
+ const formattedExamples = examples
228
+ .map(formatAimdExampleValue)
229
+ .map(example => example.trim())
230
+ .filter(Boolean)
231
+ const exampleText = formattedExamples.length > 0 ? `e.g. ${formattedExamples.join(", ")}` : undefined
232
+ const tooltipLines = [description, exampleText].filter((value): value is string => Boolean(value))
233
+ return {
234
+ tooltip: tooltipLines.join("\n"),
235
+ description,
236
+ examples: formattedExamples,
237
+ }
238
+ }
239
+
240
+ function renderFieldMetadataPopover(help: FieldMetadataHelp): VNode | null {
241
+ if (!help.description && help.examples.length === 0) {
242
+ return null
243
+ }
244
+ const children: VNode[] = []
245
+ if (help.description) {
246
+ children.push(h("span", {
247
+ class: "aimd-field__metadata-popover-line",
248
+ }, help.description))
249
+ }
250
+ if (help.examples.length > 0) {
251
+ children.push(h("span", { class: "aimd-field__metadata-examples" }, [
252
+ h("span", { class: "aimd-field__metadata-examples-label" }, "e.g."),
253
+ ...help.examples.map((example, index) => h("span", {
254
+ key: `${index}-${example}`,
255
+ class: "aimd-field__metadata-example",
256
+ }, example)),
257
+ ]))
258
+ }
259
+ return h("span", {
260
+ class: "aimd-field__metadata-popover",
261
+ role: "tooltip",
262
+ }, children)
263
+ }
264
+
21
265
  export default defineComponent({
22
266
  name: "AimdVarField",
23
267
  props: {
@@ -31,9 +275,116 @@ export default defineComponent({
31
275
  inputKind: { type: String as PropType<AimdVarInputKind>, required: true },
32
276
  typePlugin: { type: Object as PropType<AimdTypePlugin | undefined>, default: undefined },
33
277
  initialized: { type: Boolean, default: false },
278
+ assignerControl: { type: Object as PropType<VNode | undefined>, default: undefined },
279
+ assignerStatus: { type: Object as PropType<VNode | undefined>, default: undefined },
280
+ assignerError: { type: String, default: undefined },
281
+ uploadFile: { type: Function as PropType<AimdFileUploadHandler | undefined>, default: undefined },
282
+ resolveFile: { type: Function as PropType<((src: string) => string | null) | undefined>, default: undefined },
283
+ resolveFileInfo: { type: Function as PropType<AimdFileInfoResolver | undefined>, default: undefined },
34
284
  },
35
285
  emits: ["change", "blur"],
36
286
  setup(props, { emit }) {
287
+ const fileUploadError = ref("")
288
+ const csvPreview = ref<CsvPreviewState | null>(null)
289
+ const resolvedFileInfo = ref<FileDisplayInfo | null>(null)
290
+ const lastSelectedFileInfo = ref<FileDisplayInfo | null>(null)
291
+ let csvPreviewRequestId = 0
292
+
293
+ watch(
294
+ () => {
295
+ const type = props.node.definition?.type || "str"
296
+ const normalizedType = normalizeVarTypeName(type)
297
+ const fileConfig = getFileInputConfig(type, props.node.definition?.kwargs, props.fieldMeta)
298
+ const fileId = getFileValueId(props.value)
299
+ const resolvedUrl = resolvedFileInfo.value?.url || (fileId && props.resolveFile ? props.resolveFile(fileId) : null)
300
+ return fileConfig.kind === "csv" && resolvedUrl
301
+ ? `${normalizedType}\n${resolvedUrl}`
302
+ : ""
303
+ },
304
+ (key) => {
305
+ const requestId = ++csvPreviewRequestId
306
+ const [, resolvedUrl] = key.split("\n")
307
+ csvPreview.value = null
308
+ if (!resolvedUrl || typeof fetch !== "function") {
309
+ return
310
+ }
311
+
312
+ void fetch(resolvedUrl)
313
+ .then(response => (response.ok ? response.text() : ""))
314
+ .then((text) => {
315
+ if (requestId !== csvPreviewRequestId || !text) return
316
+ const rows = parseCsvPreviewRows(text)
317
+ if (rows.length > 0) {
318
+ csvPreview.value = { url: resolvedUrl, rows }
319
+ }
320
+ })
321
+ .catch(() => undefined)
322
+ },
323
+ { immediate: true },
324
+ )
325
+
326
+ watch(
327
+ () => {
328
+ const type = props.node.definition?.type || "str"
329
+ const normalizedType = normalizeVarTypeName(type)
330
+ const fileConfig = getFileInputConfig(type, props.node.definition?.kwargs, props.fieldMeta)
331
+ const fileId = getFileValueId(props.value)
332
+ const fallbackUrl = fileId && props.resolveFile ? props.resolveFile(fileId) : null
333
+ return {
334
+ fileId: fileId ?? "",
335
+ fallbackUrl: fallbackUrl ?? "",
336
+ kind: fileConfig.kind,
337
+ type,
338
+ normalizedType,
339
+ }
340
+ },
341
+ async ({ fileId, fallbackUrl, kind, type, normalizedType }) => {
342
+ if (!fileId) {
343
+ resolvedFileInfo.value = null
344
+ return
345
+ }
346
+
347
+ const localInfo = lastSelectedFileInfo.value?.id === fileId
348
+ ? lastSelectedFileInfo.value
349
+ : null
350
+ const baseInfo: FileDisplayInfo = {
351
+ id: fileId,
352
+ name: getFileDisplayName(props.value) || localInfo?.name,
353
+ url: fallbackUrl || localInfo?.url,
354
+ thumbnailUrl: localInfo?.thumbnailUrl,
355
+ type: getFileRecordString(props.value, ["type", "contentType", "content_type", "mimeType"]) ?? localInfo?.type,
356
+ size: getFileRecordNumber(props.value, ["size", "byteSize", "byte_size"]) ?? localInfo?.size,
357
+ }
358
+ resolvedFileInfo.value = normalizeResolvedFileInfo(
359
+ props.value as AimdResolvedFileInfo | string | null | undefined,
360
+ baseInfo,
361
+ )
362
+
363
+ if (!props.resolveFileInfo) {
364
+ return
365
+ }
366
+
367
+ const requestContext: AimdFileResolveContext = {
368
+ type,
369
+ normalizedType,
370
+ fieldKey: `var:${props.node.id}`,
371
+ node: props.node,
372
+ fieldMeta: props.fieldMeta,
373
+ kind,
374
+ }
375
+ try {
376
+ const resolved = await props.resolveFileInfo(fileId, requestContext)
377
+ if (getFileValueId(props.value) !== fileId) {
378
+ return
379
+ }
380
+ resolvedFileInfo.value = normalizeResolvedFileInfo(resolved, resolvedFileInfo.value ?? baseInfo)
381
+ } catch {
382
+ // Keep the URL-only fallback. Hosts may choose to surface resolver errors elsewhere.
383
+ }
384
+ },
385
+ { immediate: true },
386
+ )
387
+
37
388
  return () => {
38
389
  const node = props.node
39
390
  const id = node.id
@@ -45,7 +396,7 @@ export default defineComponent({
45
396
  const meta = props.fieldMeta
46
397
  const disabled = props.disabled
47
398
  const extraClasses = props.extraClasses
48
- const placeholder = meta?.placeholder ?? getVarPlaceholder(node)
399
+ const placeholder = meta?.placeholder ?? getVarPlaceholder(node, meta)
49
400
  const displayValue = props.displayValue
50
401
  const codeLanguage = resolveAimdCodeEditorLanguage(type, meta) ?? "plaintext"
51
402
  const numericInputAttributes: NumericInputAttributes = inputKind === "number"
@@ -73,42 +424,175 @@ export default defineComponent({
73
424
  }
74
425
  }
75
426
 
427
+ function syncFileControlLayout(control: HTMLElement) {
428
+ applyVarStackWidth(control, inputKind)
429
+ }
430
+
431
+ async function onFileChange(event: Event) {
432
+ const input = event.target as HTMLInputElement
433
+ const file = input.files?.[0]
434
+ input.value = ""
435
+ if (!file) {
436
+ return
437
+ }
438
+
439
+ fileUploadError.value = ""
440
+ const fileConfig = getFileInputConfig(type, node.definition?.kwargs, meta)
441
+ try {
442
+ const uploadedValue = props.uploadFile
443
+ ? await props.uploadFile(file, {
444
+ type,
445
+ normalizedType,
446
+ fieldKey: `var:${id}`,
447
+ node,
448
+ fieldMeta: meta,
449
+ accept: fileConfig.accept,
450
+ })
451
+ : undefined
452
+ const nextValue = uploadedValue ?? createSelectedFileValue(file)
453
+ const uploadedId = getFileValueId(nextValue)
454
+ lastSelectedFileInfo.value = {
455
+ id: uploadedId,
456
+ name: file.name,
457
+ url: uploadedId && props.resolveFile ? props.resolveFile(uploadedId) ?? undefined : undefined,
458
+ type: file.type,
459
+ size: file.size,
460
+ }
461
+ emit("change", {
462
+ id,
463
+ value: nextValue,
464
+ type,
465
+ inputKind,
466
+ })
467
+ } catch {
468
+ fileUploadError.value = props.messages.file.uploadFailed
469
+ }
470
+ }
471
+
472
+ const renderHeaderAssignerActions = (): VNode | null => {
473
+ if (!["file", "code"].includes(inputKind) || (!props.assignerControl && !props.assignerStatus)) {
474
+ return null
475
+ }
476
+
477
+ return h("span", { class: "aimd-rec-inline__header-assigner-actions" }, [
478
+ props.assignerControl
479
+ ? h("span", { class: "aimd-rec-inline__header-assigner-action" }, [props.assignerControl])
480
+ : null,
481
+ props.assignerStatus
482
+ ? h("span", { class: "aimd-rec-inline__header-assigner-state" }, [props.assignerStatus])
483
+ : null,
484
+ ])
485
+ }
486
+
487
+ const renderVarLabel = (): VNode => {
488
+ const metaTitle = normalizeMetaString(meta?.title)
489
+ const definitionTitle = getAimdFieldTitle(node.definition)
490
+ const displayTitle = metaTitle ?? getAimdFieldDisplayLabel(id, node.definition)
491
+ const hasCustomTitle = (metaTitle ?? definitionTitle) !== undefined && displayTitle !== id
492
+ const description = normalizeMetaString(meta?.description) ?? getAimdFieldDescription(node.definition)
493
+ const metaExamples = getFieldMetaExamples(meta)
494
+ const examples = metaExamples.length > 0 ? metaExamples : getAimdFieldExamples(node.definition)
495
+ const help = createFieldMetadataHelp(description, examples)
496
+ const hasHelp = Boolean(help.description) || help.examples.length > 0
497
+
498
+ return h("span", {
499
+ class: [
500
+ "aimd-field",
501
+ "aimd-field--no-style",
502
+ "aimd-field__label",
503
+ hasHelp ? "aimd-field__label--has-metadata" : undefined,
504
+ ],
505
+ }, [
506
+ h("span", { class: "aimd-field__scope aimd-field__scope--var" }, getAimdRecorderScopeLabel("var", props.messages)),
507
+ h("span", {
508
+ class: [
509
+ "aimd-field__name",
510
+ (hasCustomTitle || hasHelp) ? "aimd-field__name--with-metadata" : undefined,
511
+ hasHelp ? "aimd-field__metadata-host" : undefined,
512
+ ],
513
+ tabindex: hasHelp ? 0 : undefined,
514
+ "aria-label": help.tooltip || undefined,
515
+ }, [
516
+ h("span", { class: "aimd-field__title" }, displayTitle),
517
+ hasCustomTitle ? h("span", { class: "aimd-field__key" }, id) : null,
518
+ renderFieldMetadataPopover(help),
519
+ ]),
520
+ renderHeaderAssignerActions(),
521
+ ])
522
+ }
523
+
524
+ const renderControlRow = (control: VNode): VNode => {
525
+ if (!props.assignerControl && !props.assignerStatus) {
526
+ return control
527
+ }
528
+
529
+ return h("span", { class: "aimd-rec-inline__control-row" }, [
530
+ props.assignerControl
531
+ ? h("span", { class: "aimd-rec-inline__assigner-prefix" }, [props.assignerControl])
532
+ : null,
533
+ h("span", { class: "aimd-rec-inline__control-main" }, [control]),
534
+ props.assignerStatus
535
+ ? h("span", { class: "aimd-rec-inline__assigner-status" }, [props.assignerStatus])
536
+ : null,
537
+ ])
538
+ }
539
+
540
+ const renderAssignerError = (): VNode | null => (
541
+ props.assignerError
542
+ ? h("span", { class: "aimd-rec-inline__assigner-error" }, props.assignerError)
543
+ : null
544
+ )
545
+
76
546
  // Enum select (from fieldMeta override)
77
547
  const enumOptions = meta?.enumOptions ?? []
78
548
  if (enumOptions.length) {
549
+ const selectedEnumValue = getVarEnumSelectValue(enumOptions, props.value)
79
550
  return h("span", {
80
- class: ["aimd-rec-inline aimd-rec-inline--var-stacked aimd-field-wrapper", ...extraClasses],
551
+ class: [
552
+ "aimd-rec-inline aimd-rec-inline--var-stacked aimd-field-wrapper",
553
+ (props.assignerControl || props.assignerStatus) ? "aimd-rec-inline--has-assigner-control" : undefined,
554
+ ...extraClasses,
555
+ ],
81
556
  }, [
82
- h("span", { class: "aimd-field aimd-field--no-style aimd-field__label" }, [
83
- h("span", { class: "aimd-field__scope aimd-field__scope--var" }, "var"),
84
- h("span", { class: "aimd-field__id" }, id),
85
- ]),
86
- h("select", {
557
+ renderVarLabel(),
558
+ renderControlRow(h("select", {
87
559
  "data-rec-focus-key": `var:${id}`,
88
- class: "aimd-rec-inline__input aimd-rec-inline__input--stacked aimd-rec-inline__select",
560
+ class: "aimd-rec-inline__value-control aimd-rec-inline__input aimd-rec-inline__input--stacked aimd-rec-inline__select",
89
561
  disabled,
90
- value: props.value,
91
- onChange: (e: Event) => onVarChange((e.target as HTMLSelectElement).value),
562
+ value: selectedEnumValue,
563
+ onChange: (e: Event) => {
564
+ const value = getVarEnumValueFromSelectValue(enumOptions, (e.target as HTMLSelectElement).value)
565
+ emit("change", { id, value, type, inputKind })
566
+ },
92
567
  onBlur: onVarBlur,
93
- }, enumOptions.map(opt => h("option", { key: String(opt.value), value: opt.value }, opt.label))),
568
+ }, [
569
+ selectedEnumValue === ""
570
+ ? h("option", { value: "" }, placeholder ?? "")
571
+ : null,
572
+ ...enumOptions.map((opt, index) => h("option", { key: `${index}:${String(opt.value)}`, value: String(index) }, opt.label)),
573
+ ])),
574
+ renderAssignerError(),
94
575
  ])
95
576
  }
96
577
 
97
578
  // Default stacked widget
98
- const renderStackedVar = (control: VNode, variantClass?: string | string[]): VNode =>
579
+ const renderStackedVar = (
580
+ control: VNode,
581
+ variantClass?: string | string[],
582
+ options: { controlRow?: boolean } = {},
583
+ ): VNode =>
99
584
  h("span", {
100
585
  class: [
101
586
  "aimd-rec-inline aimd-rec-inline--var-stacked aimd-field-wrapper aimd-field-wrapper--inline",
587
+ (props.assignerControl || props.assignerStatus) ? "aimd-rec-inline--has-assigner-control" : undefined,
102
588
  variantClass,
103
589
  numericConstraintViolation ? "aimd-rec-inline--error" : undefined,
104
590
  ...extraClasses,
105
591
  ],
106
592
  }, [
107
- h("span", { class: "aimd-field aimd-field--no-style aimd-field__label" }, [
108
- h("span", { class: "aimd-field__scope aimd-field__scope--var" }, getAimdRecorderScopeLabel("var", props.messages)),
109
- h("span", { class: "aimd-field__id" }, id),
110
- ]),
111
- control,
593
+ renderVarLabel(),
594
+ options.controlRow === false ? control : renderControlRow(control),
595
+ renderAssignerError(),
112
596
  ])
113
597
 
114
598
  if (inputKind === "checkbox") {
@@ -136,7 +620,7 @@ export default defineComponent({
136
620
  return renderStackedVar(
137
621
  h("textarea", {
138
622
  "data-rec-focus-key": `var:${id}`,
139
- class: "aimd-rec-inline__textarea aimd-rec-inline__textarea--stacked",
623
+ class: "aimd-rec-inline__value-control aimd-rec-inline__textarea aimd-rec-inline__textarea--stacked",
140
624
  disabled,
141
625
  placeholder,
142
626
  value: displayValue,
@@ -159,6 +643,181 @@ export default defineComponent({
159
643
  onBlur: onVarBlur,
160
644
  }),
161
645
  "aimd-rec-inline--var-stacked--code",
646
+ { controlRow: false },
647
+ )
648
+ }
649
+
650
+ if (inputKind === "file") {
651
+ const fileConfig = getFileInputConfig(type, node.definition?.kwargs, meta)
652
+ const fileId = getFileValueId(props.value)
653
+ const displayInfo = resolvedFileInfo.value
654
+ const fileName = displayInfo?.name || getFileDisplayName(props.value)
655
+ const hasFileValue = Boolean(fileId || fileName)
656
+ const displayName = fileName || (hasFileValue ? props.messages.file.selected : placeholder || props.messages.file.choose)
657
+ const resolvedUrl = displayInfo?.url || (fileId && props.resolveFile
658
+ ? props.resolveFile(fileId)
659
+ : null)
660
+ const previewUrl = displayInfo?.thumbnailUrl || resolvedUrl
661
+ const fileSizeLabel = formatFileSize(displayInfo?.size)
662
+ const fileMetaLabel = [fileConfig.badge, fileSizeLabel].filter(Boolean).join(" · ")
663
+ const fileInput = h("input", {
664
+ "data-rec-focus-key": `var:${id}`,
665
+ class: "aimd-rec-file-field__input",
666
+ type: "file",
667
+ accept: fileConfig.accept,
668
+ disabled,
669
+ onChange: onFileChange,
670
+ onBlur: onVarBlur,
671
+ })
672
+ const fileBadge = h("span", {
673
+ class: [
674
+ "aimd-rec-file-field__badge",
675
+ `aimd-rec-file-field__badge--${fileConfig.kind}`,
676
+ ],
677
+ "aria-hidden": "true",
678
+ }, fileConfig.badge)
679
+ const fileTitle = h("span", {
680
+ class: [
681
+ "aimd-rec-file-field__name",
682
+ fileName ? undefined : "aimd-rec-file-field__name--placeholder",
683
+ ],
684
+ }, displayName)
685
+ const clearFile = (event: Event) => {
686
+ event.stopPropagation()
687
+ fileUploadError.value = ""
688
+ lastSelectedFileInfo.value = null
689
+ resolvedFileInfo.value = null
690
+ emit("change", { id, value: "", type, inputKind })
691
+ }
692
+ const actionButton = (
693
+ kind: "download" | "open" | "clear" | "replace" | "preview",
694
+ label: string,
695
+ attrs: Record<string, unknown> = {},
696
+ ) => h("button", {
697
+ type: "button",
698
+ class: [
699
+ "aimd-rec-file-card__action",
700
+ kind === "clear" ? "aimd-rec-file-card__action--danger" : undefined,
701
+ ],
702
+ "aria-label": label,
703
+ title: label,
704
+ ...attrs,
705
+ }, [renderUtilityIcon(kind), h("span", { class: "aimd-rec-file-card__action-label" }, label)])
706
+
707
+ return renderStackedVar(
708
+ h("span", {
709
+ class: "aimd-rec-inline__value-control aimd-rec-inline__file-control",
710
+ "data-file-kind": fileConfig.kind,
711
+ onVnodeMounted: (vnode: any) => syncFileControlLayout(vnode.el as HTMLElement),
712
+ onVnodeUpdated: (vnode: any) => syncFileControlLayout(vnode.el as HTMLElement),
713
+ }, [
714
+ hasFileValue
715
+ ? h("span", { class: "aimd-rec-file-card" }, [
716
+ h("span", { class: "aimd-rec-file-card__header" }, [
717
+ h("span", { class: "aimd-rec-file-card__identity", title: displayName }, [
718
+ fileBadge,
719
+ h("span", { class: "aimd-rec-file-card__text" }, [
720
+ fileTitle,
721
+ fileMetaLabel
722
+ ? h("span", { class: "aimd-rec-file-card__meta" }, fileMetaLabel)
723
+ : null,
724
+ ]),
725
+ ]),
726
+ h("span", { class: "aimd-rec-file-card__actions" }, [
727
+ !disabled
728
+ ? h("label", {
729
+ class: "aimd-rec-file-card__action aimd-rec-file-card__replace",
730
+ title: props.messages.file.replace,
731
+ }, [
732
+ fileInput,
733
+ renderUtilityIcon("replace"),
734
+ h("span", { class: "aimd-rec-file-card__action-label" }, props.messages.file.replace),
735
+ ])
736
+ : null,
737
+ resolvedUrl
738
+ ? h("a", {
739
+ class: "aimd-rec-file-card__action",
740
+ href: resolvedUrl,
741
+ download: displayName,
742
+ title: props.messages.file.download,
743
+ "aria-label": props.messages.file.download,
744
+ onClick: (event: Event) => event.stopPropagation(),
745
+ }, [
746
+ renderUtilityIcon("download"),
747
+ h("span", { class: "aimd-rec-file-card__action-label" }, props.messages.file.download),
748
+ ])
749
+ : null,
750
+ resolvedUrl
751
+ ? h("a", {
752
+ class: "aimd-rec-file-card__action",
753
+ href: resolvedUrl,
754
+ target: "_blank",
755
+ rel: "noopener noreferrer",
756
+ title: props.messages.file.open,
757
+ "aria-label": props.messages.file.open,
758
+ onClick: (event: Event) => event.stopPropagation(),
759
+ }, [
760
+ renderUtilityIcon("open"),
761
+ h("span", { class: "aimd-rec-file-card__action-label" }, props.messages.file.open),
762
+ ])
763
+ : null,
764
+ !disabled
765
+ ? actionButton("clear", props.messages.file.clear, { onClick: clearFile })
766
+ : null,
767
+ ]),
768
+ ]),
769
+ previewUrl && fileConfig.kind === "image"
770
+ ? h("a", {
771
+ class: "aimd-rec-file-field__preview",
772
+ href: resolvedUrl ?? previewUrl,
773
+ target: "_blank",
774
+ rel: "noopener noreferrer",
775
+ title: props.messages.file.preview,
776
+ onClick: (event: Event) => event.stopPropagation(),
777
+ }, [
778
+ h("img", {
779
+ src: previewUrl,
780
+ alt: displayName,
781
+ loading: "lazy",
782
+ }),
783
+ ])
784
+ : null,
785
+ resolvedUrl
786
+ && fileConfig.kind === "csv"
787
+ && csvPreview.value?.url === resolvedUrl
788
+ ? h("span", { class: "aimd-rec-file-field__csv-preview" }, [
789
+ h("span", { class: "aimd-rec-file-field__csv-grid" }, csvPreview.value.rows.map((row, rowIndex) => (
790
+ h("span", {
791
+ key: rowIndex,
792
+ class: [
793
+ "aimd-rec-file-field__csv-row",
794
+ rowIndex === 0 ? "aimd-rec-file-field__csv-row--head" : undefined,
795
+ ],
796
+ }, row.slice(0, 4).map((cell, cellIndex) => h("span", {
797
+ key: `${rowIndex}-${cellIndex}`,
798
+ class: "aimd-rec-file-field__csv-cell",
799
+ }, cell || " ")))
800
+ ))),
801
+ ])
802
+ : null,
803
+ ])
804
+ : h("label", {
805
+ class: [
806
+ "aimd-rec-file-field__trigger",
807
+ disabled ? "aimd-rec-file-field__trigger--disabled" : undefined,
808
+ ],
809
+ title: displayName,
810
+ }, [
811
+ fileInput,
812
+ fileBadge,
813
+ fileTitle,
814
+ ]),
815
+ fileUploadError.value
816
+ ? h("span", { class: "aimd-rec-file-field__error" }, fileUploadError.value)
817
+ : null,
818
+ ]),
819
+ "aimd-rec-inline--var-stacked--file",
820
+ { controlRow: false },
162
821
  )
163
822
  }
164
823
 
@@ -166,7 +825,7 @@ export default defineComponent({
166
825
  return renderStackedVar(
167
826
  h("textarea", {
168
827
  "data-rec-focus-key": `var:${id}`,
169
- class: "aimd-rec-inline__textarea aimd-rec-inline__textarea--stacked aimd-rec-inline__textarea--stacked-text",
828
+ class: "aimd-rec-inline__value-control aimd-rec-inline__textarea aimd-rec-inline__textarea--stacked aimd-rec-inline__textarea--stacked-text",
170
829
  rows: 1,
171
830
  disabled,
172
831
  placeholder,
@@ -208,7 +867,7 @@ export default defineComponent({
208
867
  return renderStackedVar(
209
868
  h("input", {
210
869
  "data-rec-focus-key": `var:${id}`,
211
- class: "aimd-rec-inline__input aimd-rec-inline__input--stacked",
870
+ class: "aimd-rec-inline__value-control aimd-rec-inline__input aimd-rec-inline__input--stacked",
212
871
  type: htmlInputType,
213
872
  inputmode: inputKind === "number" ? (isIntegerInput ? "numeric" : "decimal") : undefined,
214
873
  min: nativeNumericAttrs.min,
@@ -244,8 +903,18 @@ export default defineComponent({
244
903
  },
245
904
  })
246
905
 
247
- function getVarPlaceholder(node: AimdVarNode): string | undefined {
248
- const title = node.definition?.kwargs?.title
249
- return typeof title === "string" && title.trim() ? title.trim() : undefined
906
+ function getVarPlaceholder(node: AimdVarNode, meta?: AimdFieldMeta): string | undefined {
907
+ const placeholder = node.definition?.kwargs?.placeholder
908
+ if (typeof placeholder === "string" && placeholder.trim()) {
909
+ return placeholder.trim()
910
+ }
911
+
912
+ const metaExamples = getFieldMetaExamples(meta)
913
+ const [example] = metaExamples.length > 0 ? metaExamples : getAimdFieldExamples(node.definition)
914
+ if (example !== undefined && example !== null && typeof example !== "object") {
915
+ return formatAimdExampleValue(example)
916
+ }
917
+
918
+ return undefined
250
919
  }
251
920
  </script>