@airalogy/aimd-recorder 1.24.5 → 1.25.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 (86) hide show
  1. package/README.md +13 -1
  2. package/README.zh-CN.md +13 -1
  3. package/dist/{AimdDnaSequenceField-CxFtD5Au.js → AimdDnaSequenceField-BHV1_c2o.js} +1 -1
  4. package/dist/{AimdEditor.vue_vue_type_style_index_0_lang-B0n0inzY.js → AimdEditor.vue_vue_type_style_index_0_lang-phvUVTHV.js} +643 -605
  5. package/dist/AimdEntityRefField-COzwbHwr.js +4 -0
  6. package/dist/{AimdEntityRefField-DCE79vca.js → AimdEntityRefField.vue_vue_type_script_setup_true_lang-BIvUuZFV.js} +2 -2
  7. package/dist/{AimdMarkdownField-Du0Fh5sG.js → AimdMarkdownField-t8hqazDv.js} +3 -3
  8. package/dist/{AimdMarkdownNoteField-YnyNmBvM.js → AimdMarkdownNoteField-BGjkSXEY.js} +2 -2
  9. package/dist/AimdResourceRefField-BBaRSLcL.js +264 -0
  10. package/dist/aimd-recorder.css +1 -1
  11. package/dist/{arc-B0vwJ3nm.js → arc-CsBMJYPv.js} +1 -1
  12. package/dist/{architectureDiagram-3BPJPVTR-B5niz6cr.js → architectureDiagram-3BPJPVTR-BeKUSqHO.js} +2 -2
  13. package/dist/{blockDiagram-GPEHLZMM-Qtk9HFm8.js → blockDiagram-GPEHLZMM-CJeAC_1p.js} +4 -4
  14. package/dist/{c4Diagram-AAUBKEIU-DfTlAW2e.js → c4Diagram-AAUBKEIU-LoQMp4kW.js} +2 -2
  15. package/dist/{channel-CTIJccfL.js → channel-BoLQO6Dk.js} +1 -1
  16. package/dist/{chunk-2J33WTMH-9xMy_Pgx.js → chunk-2J33WTMH-D1vw38h5.js} +1 -1
  17. package/dist/{chunk-4BX2VUAB-BYosfXC9.js → chunk-4BX2VUAB-BFSVnsyi.js} +1 -1
  18. package/dist/{chunk-55IACEB6-B8fHTImy.js → chunk-55IACEB6-D13UaCP1.js} +1 -1
  19. package/dist/{chunk-727SXJPM-C83DIicG.js → chunk-727SXJPM-BCcz4POX.js} +5 -5
  20. package/dist/{chunk-AQP2D5EJ-C-IOiRzH.js → chunk-AQP2D5EJ-DTOfpg2m.js} +3 -3
  21. package/dist/{chunk-FMBD7UC4-BtkEX_DM.js → chunk-FMBD7UC4-XGRN-sFg.js} +1 -1
  22. package/dist/{chunk-ND2GUHAM-DIB3ib7j.js → chunk-ND2GUHAM-DSgp1I9F.js} +1 -1
  23. package/dist/{chunk-QZHKN3VN-BRsoqg2B.js → chunk-QZHKN3VN-DQl3-kKo.js} +1 -1
  24. package/dist/{classDiagram-v2-Q7XG4LA2-D39GKFwR.js → classDiagram-4FO5ZUOK-CI-4bhme.js} +2 -2
  25. package/dist/{classDiagram-4FO5ZUOK-D39GKFwR.js → classDiagram-v2-Q7XG4LA2-CI-4bhme.js} +2 -2
  26. package/dist/components.js +2222 -2110
  27. package/dist/composables.js +2 -2
  28. package/dist/{cose-bilkent-S5V4N54A-CyRaJD1S.js → cose-bilkent-S5V4N54A-CU1K-fx3.js} +1 -1
  29. package/dist/{dagre-BM42HDAG-K85xJEFU.js → dagre-BM42HDAG-HIHsvvPF.js} +3 -3
  30. package/dist/{diagram-2AECGRRQ-DET7fuM5.js → diagram-2AECGRRQ-XlYRVMia.js} +2 -2
  31. package/dist/{diagram-5GNKFQAL-Dlba-FRw.js → diagram-5GNKFQAL-BeA9dVE2.js} +3 -3
  32. package/dist/{diagram-KO2AKTUF-J4PMcx3F.js → diagram-KO2AKTUF-D501LuyG.js} +2 -2
  33. package/dist/{diagram-LMA3HP47-ldR5Az83.js → diagram-LMA3HP47-ClkmdOf_.js} +2 -2
  34. package/dist/{diagram-OG6HWLK6-UM1_l5na.js → diagram-OG6HWLK6-30O5epks.js} +3 -3
  35. package/dist/{erDiagram-TEJ5UH35-eGmNSbi1.js → erDiagram-TEJ5UH35-Dk5azNFu.js} +4 -4
  36. package/dist/{flowDiagram-I6XJVG4X-rHTJn3LZ.js → flowDiagram-I6XJVG4X-C4K9bB2d.js} +6 -6
  37. package/dist/{ganttDiagram-6RSMTGT7-DKmi_hWM.js → ganttDiagram-6RSMTGT7-sFuSkRH3.js} +2 -2
  38. package/dist/{gitGraphDiagram-PVQCEYII-DpQ1cu5h.js → gitGraphDiagram-PVQCEYII-CC4Kf_0S.js} +3 -3
  39. package/dist/{graph-CSRKgcbg.js → graph-BBr12s4M.js} +1 -1
  40. package/dist/index.js +124 -122
  41. package/dist/{infoDiagram-5YYISTIA-v8jIxUL5.js → infoDiagram-5YYISTIA-PObcwLKW.js} +1 -1
  42. package/dist/{ishikawaDiagram-YF4QCWOH-BaV5bCe8.js → ishikawaDiagram-YF4QCWOH-B93dpm60.js} +1 -1
  43. package/dist/{journeyDiagram-JHISSGLW-DeU65SpU.js → journeyDiagram-JHISSGLW-Z0_jIQ5z.js} +4 -4
  44. package/dist/{kanban-definition-UN3LZRKU-TGHAcp6_.js → kanban-definition-UN3LZRKU-BicW7pfZ.js} +2 -2
  45. package/dist/{layout-D_sj0Eed.js → layout-jm5q2dTB.js} +2 -2
  46. package/dist/{linear-TldV7C5w.js → linear-Bv4EbUf4.js} +1 -1
  47. package/dist/{mermaid.core-CRSTqrrD.js → mermaid.core-BN0BM26i.js} +34 -34
  48. package/dist/{mindmap-definition-RKZ34NQL-CejyEBat.js → mindmap-definition-RKZ34NQL-Ba85mo62.js} +3 -3
  49. package/dist/{pieDiagram-4H26LBE5-CWLZWcAW.js → pieDiagram-4H26LBE5-CfU3ahlI.js} +3 -3
  50. package/dist/{quadrantDiagram-W4KKPZXB-CYidUieH.js → quadrantDiagram-W4KKPZXB-BPTjR1PA.js} +2 -2
  51. package/dist/record.js +2 -2
  52. package/dist/{requirementDiagram-4Y6WPE33-Cw4ko-tB.js → requirementDiagram-4Y6WPE33-DVfyUAUL.js} +3 -3
  53. package/dist/{sankeyDiagram-5OEKKPKP-BnX4Evuh.js → sankeyDiagram-5OEKKPKP-B_9c0VJt.js} +1 -1
  54. package/dist/{sequenceDiagram-3UESZ5HK-BiGVMmS5.js → sequenceDiagram-3UESZ5HK-BFSDCMig.js} +3 -3
  55. package/dist/{stateDiagram-AJRCARHV-DIaBI1Uq.js → stateDiagram-AJRCARHV-DNCya3UT.js} +4 -4
  56. package/dist/{stateDiagram-v2-BHNVJYJU-BgfV-ldT.js → stateDiagram-v2-BHNVJYJU-BlmsFnk2.js} +2 -2
  57. package/dist/{timeline-definition-PNZ67QCA-C0_5OwxD.js → timeline-definition-PNZ67QCA-B297WQKg.js} +2 -2
  58. package/dist/{useFieldRendering-B2iMfsEA.js → useFieldRendering-DQN_MbSg.js} +1 -1
  59. package/dist/{useVarHelpers-CSogsd1T.js → useVarHelpers-D00Za8e6.js} +975 -934
  60. package/dist/validation-Dn_j1py1.js +5712 -0
  61. package/dist/{vennDiagram-CIIHVFJN-_ktbUOEm.js → vennDiagram-CIIHVFJN-gDmDgx6K.js} +1 -1
  62. package/dist/{wardleyDiagram-YWT4CUSO-iwftOr4-.js → wardleyDiagram-YWT4CUSO-ek5B-FUl.js} +2 -2
  63. package/dist/{xychartDiagram-2RQKCTM6-C_h9QW07.js → xychartDiagram-2RQKCTM6-DRtlxacH.js} +2 -2
  64. package/package.json +3 -3
  65. package/src/__tests__/record-validation.test.ts +121 -0
  66. package/src/__tests__/required-marker.test.ts +4 -0
  67. package/src/__tests__/resource-form.test.ts +20 -0
  68. package/src/__tests__/resource-ref-field.test.ts +125 -0
  69. package/src/__tests__/var-field-render.test.ts +39 -1
  70. package/src/components/AimdRecorder.vue +11 -1
  71. package/src/components/AimdRecorderEditor.vue +5 -0
  72. package/src/components/AimdRecorderWysiwygFieldHost.vue +1 -0
  73. package/src/components/AimdRecorderWysiwygSurface.vue +5 -0
  74. package/src/components/AimdResourceForm.vue +129 -0
  75. package/src/components/AimdResourceRefField.vue +393 -0
  76. package/src/components/AimdVarField.vue +39 -2
  77. package/src/components/index.ts +4 -0
  78. package/src/components/recorderMilkdownPlugin.ts +2 -0
  79. package/src/composables/__tests__/useVarHelpers.test.ts +53 -4
  80. package/src/composables/useVarHelpers.ts +82 -3
  81. package/src/index.ts +12 -1
  82. package/src/locales.ts +57 -0
  83. package/src/record/validation.ts +145 -11
  84. package/src/styles/recorder.css +7 -0
  85. package/src/types.ts +30 -1
  86. package/dist/validation-BYjlufCM.js +0 -5629
@@ -0,0 +1,393 @@
1
+ <script setup lang="ts">
2
+ import { computed, ref, watch } from "vue"
3
+ import type { AimdVarNode } from "@airalogy/aimd-core/types"
4
+ import type {
5
+ AimdEntityResolverMap,
6
+ AimdFieldMeta,
7
+ AimdProtocolRecordData,
8
+ AimdResourceAvailability,
9
+ AimdResourceRefValue,
10
+ AimdResourceResolver,
11
+ AimdResourceResolverMap,
12
+ } from "../types"
13
+ import type { AimdRecorderMessages } from "../locales"
14
+ import type { ResourceRefTypeConfig } from "../composables/useVarHelpers"
15
+ import { normalizeVarTypeName } from "../composables/useVarHelpers"
16
+ import AimdEntityRefField from "./AimdEntityRefField.vue"
17
+
18
+ const props = defineProps<{
19
+ node: AimdVarNode
20
+ value?: unknown
21
+ disabled?: boolean
22
+ messages: AimdRecorderMessages
23
+ fieldMeta?: AimdFieldMeta
24
+ type: string
25
+ resourceConfig: ResourceRefTypeConfig
26
+ resourceResolvers?: AimdResourceResolverMap
27
+ record: AimdProtocolRecordData
28
+ }>()
29
+
30
+ const emit = defineEmits<{
31
+ (e: "change", payload: { value: unknown }): void
32
+ (e: "blur"): void
33
+ }>()
34
+
35
+ const availability = ref<AimdResourceAvailability | null>(null)
36
+ const availabilityError = ref("")
37
+ const availabilityLoading = ref(false)
38
+ let availabilityRequest = 0
39
+ let outputRequest = 0
40
+
41
+ const resolver = computed<AimdResourceResolver | undefined>(() => {
42
+ const resolvers = props.resourceResolvers
43
+ if (!resolvers) return undefined
44
+ return (props.resourceConfig.source ? resolvers[props.resourceConfig.source] : undefined)
45
+ ?? (props.resourceConfig.entity ? resolvers[props.resourceConfig.entity] : undefined)
46
+ ?? resolvers.resource
47
+ })
48
+
49
+ const entityResolvers = computed<AimdEntityResolverMap | undefined>(() => {
50
+ if (!resolver.value) return undefined
51
+ const adapter = {
52
+ search: resolver.value.search,
53
+ resolve: resolver.value.resolve,
54
+ }
55
+ const result: AimdEntityResolverMap = {}
56
+ if (props.resourceConfig.source) result[props.resourceConfig.source] = adapter
57
+ if (props.resourceConfig.entity) result[props.resourceConfig.entity] = adapter
58
+ return result
59
+ })
60
+
61
+ function asResourceRef(value: unknown): AimdResourceRefValue | null {
62
+ if (!value || typeof value !== "object" || Array.isArray(value)) return null
63
+ const item = value as Record<string, unknown>
64
+ if (typeof item.id !== "string" || !item.id.trim()) return null
65
+ return {
66
+ ...item,
67
+ entity: typeof item.entity === "string" && item.entity.trim()
68
+ ? item.entity
69
+ : props.resourceConfig.entity ?? "resource",
70
+ id: item.id.trim(),
71
+ } as AimdResourceRefValue
72
+ }
73
+
74
+ const selected = computed(() => {
75
+ if (props.resourceConfig.multiple) {
76
+ const values = Array.isArray(props.value) ? props.value : []
77
+ return values.map(asResourceRef).filter((item): item is AimdResourceRefValue => item !== null)
78
+ }
79
+ const value = asResourceRef(props.value)
80
+ return value ? [value] : []
81
+ })
82
+
83
+ function resourceContext() {
84
+ return {
85
+ type: props.type,
86
+ normalizedType: normalizeVarTypeName(props.type),
87
+ fieldKey: `var:${props.node.id}`,
88
+ node: props.node,
89
+ fieldMeta: props.fieldMeta,
90
+ entity: props.resourceConfig.entity,
91
+ source: props.resourceConfig.source,
92
+ multiple: props.resourceConfig.multiple,
93
+ record: props.record,
94
+ role: props.resourceConfig.role,
95
+ quantityField: props.resourceConfig.quantityField,
96
+ containerRequired: props.resourceConfig.containerRequired,
97
+ bookingRequired: props.resourceConfig.bookingRequired,
98
+ }
99
+ }
100
+
101
+ async function loadAvailability(): Promise<void> {
102
+ const resource = selected.value[0]
103
+ const currentResolver = resolver.value
104
+ const request = ++availabilityRequest
105
+ availability.value = null
106
+ availabilityError.value = ""
107
+ if (!resource || !currentResolver?.getAvailability || props.resourceConfig.multiple) return
108
+ availabilityLoading.value = true
109
+ try {
110
+ const result = await currentResolver.getAvailability(resource, resourceContext())
111
+ if (request === availabilityRequest) availability.value = result
112
+ }
113
+ catch {
114
+ if (request === availabilityRequest) {
115
+ availabilityError.value = props.messages.resourceRef.availabilityFailed
116
+ }
117
+ }
118
+ finally {
119
+ if (request === availabilityRequest) availabilityLoading.value = false
120
+ }
121
+ }
122
+
123
+ watch(
124
+ () => [
125
+ selected.value[0]?.id,
126
+ selected.value[0]?.lot_id,
127
+ props.resourceResolvers,
128
+ ],
129
+ () => void loadAvailability(),
130
+ { immediate: true },
131
+ )
132
+
133
+ function emitSinglePatch(patch: Partial<AimdResourceRefValue>): void {
134
+ const current = selected.value[0]
135
+ if (!current) return
136
+ emit("change", { value: { ...current, ...patch } })
137
+ }
138
+
139
+ async function prepareOutputValue(value: unknown): Promise<unknown> {
140
+ const currentResolver = resolver.value
141
+ if (props.resourceConfig.role !== "output" || !currentResolver?.prepareOutput) {
142
+ return value
143
+ }
144
+ const values = props.resourceConfig.multiple
145
+ ? (Array.isArray(value) ? value : [])
146
+ : [value]
147
+ const preparedValues: AimdResourceRefValue[] = []
148
+ for (const item of values) {
149
+ const draft = asResourceRef(item)
150
+ if (!draft) continue
151
+ const prepared = await currentResolver.prepareOutput(draft, resourceContext())
152
+ preparedValues.push({
153
+ ...prepared.value,
154
+ prepared_output: prepared.payload,
155
+ })
156
+ }
157
+ return props.resourceConfig.multiple ? preparedValues : preparedValues[0] ?? value
158
+ }
159
+
160
+ async function onBaseChange(value: unknown): Promise<void> {
161
+ const request = ++outputRequest
162
+ availabilityError.value = ""
163
+ try {
164
+ const prepared = await prepareOutputValue(value)
165
+ if (request === outputRequest) emit("change", { value: prepared })
166
+ }
167
+ catch {
168
+ if (request === outputRequest) {
169
+ availabilityError.value = props.messages.resourceRef.prepareOutputFailed
170
+ }
171
+ }
172
+ }
173
+
174
+ function slotValue(slot: NonNullable<AimdResourceAvailability["equipment_slots"]>[number]): string {
175
+ return slot.id ?? `${slot.starts_at}/${slot.ends_at}`
176
+ }
177
+
178
+ function onBookingChange(value: string): void {
179
+ const slot = availability.value?.equipment_slots?.find(item => slotValue(item) === value)
180
+ emitSinglePatch({
181
+ booking_id: value || undefined,
182
+ snapshot: slot
183
+ ? { ...(selected.value[0]?.snapshot ?? {}), booking_slot: slot }
184
+ : selected.value[0]?.snapshot,
185
+ })
186
+ }
187
+ </script>
188
+
189
+ <template>
190
+ <span class="aimd-rec-resource-ref">
191
+ <AimdEntityRefField
192
+ :node="node"
193
+ :value="value"
194
+ :disabled="disabled"
195
+ :messages="messages"
196
+ :field-meta="fieldMeta"
197
+ :type="type"
198
+ :entity-config="resourceConfig"
199
+ :entity-resolvers="entityResolvers"
200
+ :record="record"
201
+ @change="onBaseChange($event.value)"
202
+ @blur="emit('blur')"
203
+ />
204
+
205
+ <span
206
+ v-if="selected.length === 1 && !resourceConfig.multiple"
207
+ class="aimd-rec-resource-ref__details"
208
+ >
209
+ <span
210
+ v-if="availabilityLoading || availability?.available !== undefined"
211
+ class="aimd-rec-resource-ref__available"
212
+ >
213
+ {{ messages.resourceRef.available }}:
214
+ {{ availabilityLoading ? "…" : availability?.available }}
215
+ {{ availability?.unit || "" }}
216
+ </span>
217
+ <span v-if="availabilityError" class="aimd-rec-resource-ref__error">
218
+ {{ availabilityError }}
219
+ </span>
220
+
221
+ <label v-if="availability?.lots?.length" class="aimd-rec-resource-ref__field">
222
+ <span>{{ messages.resourceRef.lot }}</span>
223
+ <select
224
+ :disabled="disabled"
225
+ :value="selected[0].lot_id || ''"
226
+ @change="emitSinglePatch({ lot_id: ($event.target as HTMLSelectElement).value || undefined, container_id: undefined })"
227
+ @blur="emit('blur')"
228
+ >
229
+ <option value="">{{ messages.resourceRef.selectLot }}</option>
230
+ <option
231
+ v-for="lot in availability.lots"
232
+ :key="lot.id"
233
+ :value="lot.id"
234
+ :disabled="lot.disabled"
235
+ >
236
+ {{ lot.label || lot.id }}
237
+ <template v-if="lot.available !== undefined">
238
+ — {{ lot.available }} {{ lot.unit || availability.unit || "" }}
239
+ </template>
240
+ </option>
241
+ </select>
242
+ </label>
243
+
244
+ <label
245
+ v-if="availability?.containers?.length || resourceConfig.containerRequired"
246
+ class="aimd-rec-resource-ref__field"
247
+ >
248
+ <span>{{ messages.resourceRef.container }}</span>
249
+ <select
250
+ :disabled="disabled"
251
+ :value="selected[0].container_id || ''"
252
+ @change="emitSinglePatch({ container_id: ($event.target as HTMLSelectElement).value || undefined })"
253
+ @blur="emit('blur')"
254
+ >
255
+ <option value="">{{ messages.resourceRef.selectContainer }}</option>
256
+ <option
257
+ v-for="container in availability?.containers || []"
258
+ :key="container.id"
259
+ :value="container.id"
260
+ :disabled="container.disabled || Boolean(selected[0].lot_id && container.lot_id && container.lot_id !== selected[0].lot_id)"
261
+ >
262
+ {{ container.label || container.id }}
263
+ <template v-if="container.location"> — {{ container.location }}</template>
264
+ </option>
265
+ </select>
266
+ </label>
267
+
268
+ <span
269
+ v-if="resourceConfig.role === 'input' || resourceConfig.role === 'output'"
270
+ class="aimd-rec-resource-ref__quantity-row"
271
+ >
272
+ <label v-if="!resourceConfig.quantityField" class="aimd-rec-resource-ref__field">
273
+ <span>{{ messages.resourceRef.quantity }}</span>
274
+ <input
275
+ type="number"
276
+ min="0"
277
+ step="any"
278
+ :disabled="disabled"
279
+ :value="selected[0].quantity ?? ''"
280
+ @input="emitSinglePatch({ quantity: ($event.target as HTMLInputElement).value || undefined })"
281
+ @blur="emit('blur')"
282
+ >
283
+ </label>
284
+ <label class="aimd-rec-resource-ref__field aimd-rec-resource-ref__field--unit">
285
+ <span>{{ messages.resourceRef.unit }}</span>
286
+ <input
287
+ type="text"
288
+ :disabled="disabled"
289
+ :value="selected[0].unit || availability?.unit || ''"
290
+ @input="emitSinglePatch({ unit: ($event.target as HTMLInputElement).value || undefined })"
291
+ @blur="emit('blur')"
292
+ >
293
+ </label>
294
+ </span>
295
+
296
+ <span
297
+ v-if="resourceConfig.quantityField"
298
+ class="aimd-rec-resource-ref__binding"
299
+ >
300
+ {{ messages.resourceRef.quantityFrom(resourceConfig.quantityField) }}
301
+ </span>
302
+
303
+ <label
304
+ v-if="resourceConfig.role === 'equipment' && (availability?.equipment_slots?.length || resourceConfig.bookingRequired)"
305
+ class="aimd-rec-resource-ref__field"
306
+ >
307
+ <span>{{ messages.resourceRef.booking }}</span>
308
+ <select
309
+ :disabled="disabled"
310
+ :value="selected[0].booking_id || ''"
311
+ @change="onBookingChange(($event.target as HTMLSelectElement).value)"
312
+ @blur="emit('blur')"
313
+ >
314
+ <option value="">{{ messages.resourceRef.selectBooking }}</option>
315
+ <option
316
+ v-for="slot in availability?.equipment_slots || []"
317
+ :key="slotValue(slot)"
318
+ :value="slotValue(slot)"
319
+ :disabled="slot.available === false"
320
+ >
321
+ {{ slot.label || `${slot.starts_at} – ${slot.ends_at}` }}
322
+ </option>
323
+ </select>
324
+ </label>
325
+ </span>
326
+ </span>
327
+ </template>
328
+
329
+ <style scoped>
330
+ .aimd-rec-resource-ref,
331
+ .aimd-rec-resource-ref__details {
332
+ display: flex;
333
+ min-width: 0;
334
+ width: 100%;
335
+ flex-direction: column;
336
+ gap: 0.5rem;
337
+ }
338
+
339
+ .aimd-rec-resource-ref__details {
340
+ padding: 0.625rem;
341
+ border: 1px solid color-mix(in srgb, var(--aimd-rec-accent, #1473e6) 18%, transparent);
342
+ border-radius: 0.625rem;
343
+ background: color-mix(in srgb, var(--aimd-rec-accent, #1473e6) 4%, transparent);
344
+ }
345
+
346
+ .aimd-rec-resource-ref__available {
347
+ color: var(--aimd-rec-text-muted, #64748b);
348
+ font-size: 0.8125rem;
349
+ }
350
+
351
+ .aimd-rec-resource-ref__error {
352
+ color: var(--aimd-rec-danger, #dc2626);
353
+ font-size: 0.8125rem;
354
+ }
355
+
356
+ .aimd-rec-resource-ref__binding {
357
+ color: var(--aimd-rec-text-muted, #64748b);
358
+ font-size: 0.75rem;
359
+ }
360
+
361
+ .aimd-rec-resource-ref__field {
362
+ display: grid;
363
+ min-width: 0;
364
+ grid-template-columns: minmax(5rem, max-content) minmax(0, 1fr);
365
+ align-items: center;
366
+ gap: 0.5rem;
367
+ color: var(--aimd-rec-text-muted, #64748b);
368
+ font-size: 0.8125rem;
369
+ }
370
+
371
+ .aimd-rec-resource-ref__field select,
372
+ .aimd-rec-resource-ref__field input {
373
+ min-width: 0;
374
+ height: 2rem;
375
+ padding: 0 0.5rem;
376
+ border: 1px solid var(--aimd-rec-border, #cbd5e1);
377
+ border-radius: 0.375rem;
378
+ color: var(--aimd-rec-text, #0f172a);
379
+ background: var(--aimd-rec-surface, #fff);
380
+ }
381
+
382
+ .aimd-rec-resource-ref__quantity-row {
383
+ display: grid;
384
+ grid-template-columns: minmax(0, 1fr) minmax(8rem, 0.45fr);
385
+ gap: 0.5rem;
386
+ }
387
+
388
+ @media (max-width: 640px) {
389
+ .aimd-rec-resource-ref__quantity-row {
390
+ grid-template-columns: 1fr;
391
+ }
392
+ }
393
+ </style>
@@ -11,6 +11,7 @@ import {
11
11
  import type {
12
12
  AimdFieldMeta,
13
13
  AimdEntityResolverMap,
14
+ AimdResourceResolverMap,
14
15
  AimdFileInfoResolver,
15
16
  AimdFileResolveContext,
16
17
  AimdFileUploadHandler,
@@ -37,6 +38,7 @@ import {
37
38
  getScalarListInputItems,
38
39
  getScalarListItemType,
39
40
  getEntityRefTypeConfig,
41
+ getResourceRefTypeConfig,
40
42
  getVarEnumSelectValue,
41
43
  getVarEnumValueFromSelectValue,
42
44
  isIntegerVarType,
@@ -50,6 +52,7 @@ import AimdRequiredMarker from "./AimdRequiredMarker.vue"
50
52
 
51
53
  const AimdCodeField = defineAsyncComponent(() => import("./AimdCodeField.vue"))
52
54
  const AimdEntityRefField = defineAsyncComponent(() => import("./AimdEntityRefField.vue"))
55
+ const AimdResourceRefField = defineAsyncComponent(() => import("./AimdResourceRefField.vue"))
53
56
 
54
57
  function normalizeMetaString(value: unknown): string | undefined {
55
58
  return typeof value === "string" && value.trim() ? value.trim() : undefined
@@ -502,6 +505,7 @@ export default defineComponent({
502
505
  resolveFile: { type: Function as PropType<((src: string) => string | null) | undefined>, default: undefined },
503
506
  resolveFileInfo: { type: Function as PropType<AimdFileInfoResolver | undefined>, default: undefined },
504
507
  entityResolvers: { type: Object as PropType<AimdEntityResolverMap | undefined>, default: undefined },
508
+ resourceResolvers: { type: Object as PropType<AimdResourceResolverMap | undefined>, default: undefined },
505
509
  record: {
506
510
  type: Object as PropType<AimdProtocolRecordData>,
507
511
  default: () => ({ var: {}, step: {}, check: {}, quiz: {} }),
@@ -782,8 +786,10 @@ export default defineComponent({
782
786
  tabindex: hasHelp ? 0 : undefined,
783
787
  "aria-label": help.tooltip || undefined,
784
788
  }, [
785
- h("span", { class: "aimd-field__title", title: displayTitle }, displayTitle),
786
- props.required ? h(AimdRequiredMarker, { label: props.messages.common.required }) : null,
789
+ h("span", { class: "aimd-field__title-row" }, [
790
+ h("span", { class: "aimd-field__title", title: displayTitle }, displayTitle),
791
+ props.required ? h(AimdRequiredMarker, { label: props.messages.common.required }) : null,
792
+ ]),
787
793
  hasCustomTitle ? h("span", { class: "aimd-field__key", title: id }, id) : null,
788
794
  renderFieldMetadataPopover(help),
789
795
  ]),
@@ -967,6 +973,37 @@ export default defineComponent({
967
973
  )
968
974
  }
969
975
 
976
+ if (inputKind === "resource-ref") {
977
+ const resourceConfig = getResourceRefTypeConfig(type, node.definition?.kwargs, meta)
978
+ ?? {
979
+ multiple: false,
980
+ role: "reference" as const,
981
+ containerRequired: false,
982
+ bookingRequired: false,
983
+ }
984
+ return renderStackedVar(
985
+ h(AimdResourceRefField, {
986
+ node,
987
+ value: props.value,
988
+ disabled,
989
+ messages: props.messages,
990
+ fieldMeta: meta,
991
+ type,
992
+ resourceConfig,
993
+ resourceResolvers: props.resourceResolvers,
994
+ record: props.record,
995
+ onVnodeMounted: (vnode: any) => syncCompositeControlLayout(vnode.el as HTMLElement),
996
+ onVnodeUpdated: (vnode: any) => syncCompositeControlLayout(vnode.el as HTMLElement),
997
+ onChange: (payload: { value: unknown }) => {
998
+ emit("change", { id, value: payload.value, type, inputKind })
999
+ },
1000
+ onBlur: onVarBlur,
1001
+ }),
1002
+ "aimd-rec-inline--var-stacked--resource-ref",
1003
+ { controlRow: false },
1004
+ )
1005
+ }
1006
+
970
1007
  if (inputKind === "file") {
971
1008
  const fileConfig = getFileInputConfig(type, node.definition?.kwargs, meta)
972
1009
  const fileId = getFileValueId(props.value)
@@ -13,10 +13,12 @@ import AimdRecorder from "./AimdRecorder.vue"
13
13
  import AimdRecorderEditor from "./AimdRecorderEditor.vue"
14
14
  import AimdQuizRecorder from "./AimdQuizRecorder.vue"
15
15
  import AimdRequiredMarker from "./AimdRequiredMarker.vue"
16
+ import AimdResourceForm from "./AimdResourceForm.vue"
16
17
 
17
18
  const AimdDnaSequenceField = defineAsyncComponent(() => import("./AimdDnaSequenceField.vue"))
18
19
  const AimdMarkdownField = defineAsyncComponent(() => import("./AimdMarkdownField.vue"))
19
20
  const AimdEntityRefField = defineAsyncComponent(() => import("./AimdEntityRefField.vue"))
21
+ const AimdResourceRefField = defineAsyncComponent(() => import("./AimdResourceRefField.vue"))
20
22
 
21
23
  export {
22
24
  AimdAssignerGraph,
@@ -25,7 +27,9 @@ export {
25
27
  AimdRecorderEditor,
26
28
  AimdQuizRecorder,
27
29
  AimdRequiredMarker,
30
+ AimdResourceForm,
28
31
  AimdEntityRefField,
32
+ AimdResourceRefField,
29
33
  AimdDnaSequenceField,
30
34
  AimdMarkdownField,
31
35
  }
@@ -24,6 +24,7 @@ import type {
24
24
  AimdServerAssignerMap,
25
25
  AimdServerAssignerRunner,
26
26
  AimdEntityResolverMap,
27
+ AimdResourceResolverMap,
27
28
  AimdFileInfoResolver,
28
29
  AimdFileUploadHandler,
29
30
  AimdFieldMeta,
@@ -73,6 +74,7 @@ export interface RecorderMilkdownSurfaceState {
73
74
  customRenderers?: Partial<Record<string, AimdComponentRenderer>>
74
75
  fieldAdapters?: AimdRecorderFieldAdapters
75
76
  entityResolvers?: AimdEntityResolverMap
77
+ resourceResolvers?: AimdResourceResolverMap
76
78
  collectorProviders?: AimdCollectorProviderMap
77
79
  requestCollectorPermission?: AimdCollectorPermissionHandler
78
80
  collectorActorId?: string
@@ -7,9 +7,11 @@ import {
7
7
  getScalarListInputItems,
8
8
  getScalarListItemType,
9
9
  getEntityRefTypeConfig,
10
+ getResourceRefTypeConfig,
10
11
  isIntegerVarType,
11
12
  isNullableVarType,
12
13
  isEntityRefVarType,
14
+ isResourceRefVarType,
13
15
  isScalarListVarType,
14
16
  isStructuredVarType,
15
17
  normalizeScalarListInputItems,
@@ -146,6 +148,12 @@ describe('getVarInputKind', () => {
146
148
  expect(getVarInputKind('list[EntityRef["plasmid"]]')).toBe('entity-ref')
147
149
  })
148
150
 
151
+ it('returns "resource-ref" for ResourceRef types before structured fallbacks', () => {
152
+ expect(getVarInputKind('ResourceRef')).toBe('resource-ref')
153
+ expect(getVarInputKind('ResourceRef["plasmid"] | None')).toBe('resource-ref')
154
+ expect(getVarInputKind('list[ResourceRef["sample"]]')).toBe('resource-ref')
155
+ })
156
+
149
157
  it('returns "textarea" for structured non-scalar list and object types', () => {
150
158
  expect(getVarInputKind('list')).toBe('textarea')
151
159
  expect(getVarInputKind('list[bool]')).toBe('textarea')
@@ -203,6 +211,48 @@ describe('EntityRef helpers', () => {
203
211
  })
204
212
  })
205
213
 
214
+ describe('ResourceRef helpers', () => {
215
+ it('detects ResourceRef annotations and normalizes inventory metadata', () => {
216
+ expect(isResourceRefVarType('ResourceRef["plasmid"] | None')).toBe(true)
217
+ expect(isResourceRefVarType('EntityRef["plasmid"]')).toBe(false)
218
+ expect(getResourceRefTypeConfig(
219
+ 'ResourceRef["plasmid"]',
220
+ {
221
+ resource_role: 'input',
222
+ quantity_field: 'amount',
223
+ container_required: true,
224
+ },
225
+ )).toEqual({
226
+ multiple: false,
227
+ entity: 'plasmid',
228
+ source: undefined,
229
+ role: 'input',
230
+ quantityField: 'amount',
231
+ containerRequired: true,
232
+ bookingRequired: false,
233
+ })
234
+ })
235
+
236
+ it('supports equipment and list ResourceRef metadata', () => {
237
+ expect(getResourceRefTypeConfig(
238
+ 'list[ResourceRef["equipment"]] | None',
239
+ {
240
+ resource_role: 'equipment',
241
+ booking_required: true,
242
+ source: 'lab-equipment',
243
+ },
244
+ )).toEqual({
245
+ multiple: true,
246
+ entity: 'equipment',
247
+ source: 'lab-equipment',
248
+ role: 'equipment',
249
+ quantityField: undefined,
250
+ containerRequired: false,
251
+ bookingRequired: true,
252
+ })
253
+ })
254
+ })
255
+
206
256
  // ---------------------------------------------------------------------------
207
257
  // File-like vars
208
258
  // ---------------------------------------------------------------------------
@@ -906,10 +956,9 @@ describe('measureVarLabelWidth', () => {
906
956
  </span>
907
957
  `
908
958
  const requiredWrapper = optionalWrapper.cloneNode(true) as HTMLElement
909
- requiredWrapper.querySelector('.aimd-field__name')?.insertAdjacentHTML(
910
- 'beforeend',
911
- '<span class="aimd-field__required-marker">*</span>',
912
- )
959
+ const requiredTitle = requiredWrapper.querySelector('.aimd-field__title')
960
+ requiredTitle?.insertAdjacentHTML('afterend', '<span class="aimd-field__required-marker">*</span>')
961
+ requiredTitle?.parentElement?.classList.add('aimd-field__title-row')
913
962
  document.body.append(optionalWrapper, requiredWrapper)
914
963
 
915
964
  expect(measureVarLabelWidth(requiredWrapper)).toBeGreaterThan(measureVarLabelWidth(optionalWrapper))