@airalogy/aimd-recorder 1.24.4 → 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.
- package/README.md +13 -1
- package/README.zh-CN.md +13 -1
- package/dist/{AimdDnaSequenceField-Opgy07Gt.js → AimdDnaSequenceField-BHV1_c2o.js} +1 -1
- package/dist/{AimdEditor.vue_vue_type_style_index_0_lang-DHckC0bq.js → AimdEditor.vue_vue_type_style_index_0_lang-phvUVTHV.js} +643 -605
- package/dist/AimdEntityRefField-COzwbHwr.js +4 -0
- package/dist/{AimdEntityRefField-GA6-mhGU.js → AimdEntityRefField.vue_vue_type_script_setup_true_lang-BIvUuZFV.js} +2 -2
- package/dist/{AimdMarkdownField-jagZIbKc.js → AimdMarkdownField-t8hqazDv.js} +3 -3
- package/dist/{AimdMarkdownNoteField-BUq4fRcZ.js → AimdMarkdownNoteField-BGjkSXEY.js} +2 -2
- package/dist/AimdResourceRefField-BBaRSLcL.js +264 -0
- package/dist/aimd-recorder.css +1 -1
- package/dist/{arc-CR1cpc2k.js → arc-CsBMJYPv.js} +1 -1
- package/dist/{architectureDiagram-3BPJPVTR-B8OoiHF6.js → architectureDiagram-3BPJPVTR-BeKUSqHO.js} +2 -2
- package/dist/{blockDiagram-GPEHLZMM-Ddq40SrW.js → blockDiagram-GPEHLZMM-CJeAC_1p.js} +4 -4
- package/dist/{c4Diagram-AAUBKEIU-Cf3cjJMq.js → c4Diagram-AAUBKEIU-LoQMp4kW.js} +2 -2
- package/dist/{channel-C8Vd7nOK.js → channel-BoLQO6Dk.js} +1 -1
- package/dist/{chunk-2J33WTMH-Ck31ftjD.js → chunk-2J33WTMH-D1vw38h5.js} +1 -1
- package/dist/{chunk-4BX2VUAB-BJOkbq4i.js → chunk-4BX2VUAB-BFSVnsyi.js} +1 -1
- package/dist/{chunk-55IACEB6-lNZxrJyO.js → chunk-55IACEB6-D13UaCP1.js} +1 -1
- package/dist/{chunk-727SXJPM-mEDRtdd4.js → chunk-727SXJPM-BCcz4POX.js} +5 -5
- package/dist/{chunk-AQP2D5EJ-C1MU-m_K.js → chunk-AQP2D5EJ-DTOfpg2m.js} +3 -3
- package/dist/{chunk-FMBD7UC4-Pmfg_1nq.js → chunk-FMBD7UC4-XGRN-sFg.js} +1 -1
- package/dist/{chunk-ND2GUHAM-CipPchY0.js → chunk-ND2GUHAM-DSgp1I9F.js} +1 -1
- package/dist/{chunk-QZHKN3VN-BvE9EC7r.js → chunk-QZHKN3VN-DQl3-kKo.js} +1 -1
- package/dist/{classDiagram-v2-Q7XG4LA2-BM5OaktU.js → classDiagram-4FO5ZUOK-CI-4bhme.js} +2 -2
- package/dist/{classDiagram-4FO5ZUOK-BM5OaktU.js → classDiagram-v2-Q7XG4LA2-CI-4bhme.js} +2 -2
- package/dist/components.js +2222 -2110
- package/dist/composables.js +2 -2
- package/dist/{cose-bilkent-S5V4N54A-nmO7LFhz.js → cose-bilkent-S5V4N54A-CU1K-fx3.js} +1 -1
- package/dist/{dagre-BM42HDAG-D3xhjRxX.js → dagre-BM42HDAG-HIHsvvPF.js} +3 -3
- package/dist/{diagram-2AECGRRQ-kCJcuZOT.js → diagram-2AECGRRQ-XlYRVMia.js} +2 -2
- package/dist/{diagram-5GNKFQAL-Bdr1oGkv.js → diagram-5GNKFQAL-BeA9dVE2.js} +3 -3
- package/dist/{diagram-KO2AKTUF-CeBpcrbw.js → diagram-KO2AKTUF-D501LuyG.js} +2 -2
- package/dist/{diagram-LMA3HP47-C5oYYzCp.js → diagram-LMA3HP47-ClkmdOf_.js} +2 -2
- package/dist/{diagram-OG6HWLK6-CNzZuxZL.js → diagram-OG6HWLK6-30O5epks.js} +3 -3
- package/dist/{erDiagram-TEJ5UH35-MWNh4yWB.js → erDiagram-TEJ5UH35-Dk5azNFu.js} +4 -4
- package/dist/{flowDiagram-I6XJVG4X-DcREbXha.js → flowDiagram-I6XJVG4X-C4K9bB2d.js} +6 -6
- package/dist/{ganttDiagram-6RSMTGT7-DGZUsfa4.js → ganttDiagram-6RSMTGT7-sFuSkRH3.js} +2 -2
- package/dist/{gitGraphDiagram-PVQCEYII-DhpcTOAS.js → gitGraphDiagram-PVQCEYII-CC4Kf_0S.js} +3 -3
- package/dist/{graph-CXU7Rv38.js → graph-BBr12s4M.js} +1 -1
- package/dist/index.js +124 -122
- package/dist/{infoDiagram-5YYISTIA-CVZBlZ8R.js → infoDiagram-5YYISTIA-PObcwLKW.js} +1 -1
- package/dist/{ishikawaDiagram-YF4QCWOH-Bjyc47Lv.js → ishikawaDiagram-YF4QCWOH-B93dpm60.js} +1 -1
- package/dist/{journeyDiagram-JHISSGLW-e2G_PVGF.js → journeyDiagram-JHISSGLW-Z0_jIQ5z.js} +4 -4
- package/dist/{kanban-definition-UN3LZRKU-CKOBjcK9.js → kanban-definition-UN3LZRKU-BicW7pfZ.js} +2 -2
- package/dist/{layout-CBS27QDo.js → layout-jm5q2dTB.js} +2 -2
- package/dist/{linear-UyXZcrYY.js → linear-Bv4EbUf4.js} +1 -1
- package/dist/{mermaid.core-BeKK51C9.js → mermaid.core-BN0BM26i.js} +34 -34
- package/dist/{mindmap-definition-RKZ34NQL-T6_bnhal.js → mindmap-definition-RKZ34NQL-Ba85mo62.js} +3 -3
- package/dist/{pieDiagram-4H26LBE5-GGANuPvf.js → pieDiagram-4H26LBE5-CfU3ahlI.js} +3 -3
- package/dist/{quadrantDiagram-W4KKPZXB-BAtVKEgW.js → quadrantDiagram-W4KKPZXB-BPTjR1PA.js} +2 -2
- package/dist/record.js +2 -2
- package/dist/{requirementDiagram-4Y6WPE33-C2oozBsJ.js → requirementDiagram-4Y6WPE33-DVfyUAUL.js} +3 -3
- package/dist/{sankeyDiagram-5OEKKPKP-Bfc4Y-JM.js → sankeyDiagram-5OEKKPKP-B_9c0VJt.js} +1 -1
- package/dist/{sequenceDiagram-3UESZ5HK-e9yMBU3K.js → sequenceDiagram-3UESZ5HK-BFSDCMig.js} +3 -3
- package/dist/{stateDiagram-AJRCARHV-D1vciiPs.js → stateDiagram-AJRCARHV-DNCya3UT.js} +4 -4
- package/dist/{stateDiagram-v2-BHNVJYJU-DMXm3rUm.js → stateDiagram-v2-BHNVJYJU-BlmsFnk2.js} +2 -2
- package/dist/{timeline-definition-PNZ67QCA-Cg7TL_0Q.js → timeline-definition-PNZ67QCA-B297WQKg.js} +2 -2
- package/dist/{useFieldRendering-JFnqNEWH.js → useFieldRendering-DQN_MbSg.js} +1 -1
- package/dist/{useVarHelpers-CQQ-zhL0.js → useVarHelpers-D00Za8e6.js} +978 -932
- package/dist/validation-Dn_j1py1.js +5712 -0
- package/dist/{vennDiagram-CIIHVFJN-BEJdgPK5.js → vennDiagram-CIIHVFJN-gDmDgx6K.js} +1 -1
- package/dist/{wardleyDiagram-YWT4CUSO-DLxpx6Lm.js → wardleyDiagram-YWT4CUSO-ek5B-FUl.js} +2 -2
- package/dist/{xychartDiagram-2RQKCTM6-CG-K6knD.js → xychartDiagram-2RQKCTM6-DRtlxacH.js} +2 -2
- package/package.json +4 -4
- package/src/__tests__/record-validation.test.ts +121 -0
- package/src/__tests__/required-marker.test.ts +14 -0
- package/src/__tests__/resource-form.test.ts +20 -0
- package/src/__tests__/resource-ref-field.test.ts +125 -0
- package/src/__tests__/var-field-render.test.ts +87 -1
- package/src/components/AimdRecorder.vue +11 -1
- package/src/components/AimdRecorderEditor.vue +5 -0
- package/src/components/AimdRecorderWysiwygFieldHost.vue +1 -0
- package/src/components/AimdRecorderWysiwygSurface.vue +5 -0
- package/src/components/AimdResourceForm.vue +129 -0
- package/src/components/AimdResourceRefField.vue +393 -0
- package/src/components/AimdVarField.vue +41 -3
- package/src/components/index.ts +4 -0
- package/src/components/recorderMilkdownPlugin.ts +2 -0
- package/src/composables/__tests__/useVarHelpers.test.ts +96 -0
- package/src/composables/useVarHelpers.ts +91 -4
- package/src/index.ts +12 -1
- package/src/locales.ts +57 -0
- package/src/record/validation.ts +145 -11
- package/src/styles/recorder.css +8 -0
- package/src/types.ts +30 -1
- package/dist/validation-DSn_Ttx_.js +0 -5629
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { ref, useAttrs } from "vue"
|
|
3
|
+
import type { ExtractedAimdFields } from "@airalogy/aimd-core/types"
|
|
4
|
+
import {
|
|
5
|
+
validateAimdProtocolContract,
|
|
6
|
+
type AimdResourceValidationIssue,
|
|
7
|
+
} from "@airalogy/aimd-core"
|
|
8
|
+
import type {
|
|
9
|
+
AimdProtocolRecordData,
|
|
10
|
+
AimdRecorderValidationResult,
|
|
11
|
+
AimdResourceResolverMap,
|
|
12
|
+
} from "../types"
|
|
13
|
+
import AimdRecorder from "./AimdRecorder.vue"
|
|
14
|
+
|
|
15
|
+
defineOptions({ inheritAttrs: false })
|
|
16
|
+
|
|
17
|
+
const props = withDefaults(defineProps<{
|
|
18
|
+
content: string
|
|
19
|
+
modelValue?: Partial<AimdProtocolRecordData>
|
|
20
|
+
readonly?: boolean
|
|
21
|
+
locale?: string
|
|
22
|
+
resourceResolvers?: AimdResourceResolverMap
|
|
23
|
+
title?: string
|
|
24
|
+
description?: string
|
|
25
|
+
}>(), {
|
|
26
|
+
modelValue: undefined,
|
|
27
|
+
readonly: false,
|
|
28
|
+
locale: undefined,
|
|
29
|
+
resourceResolvers: undefined,
|
|
30
|
+
title: undefined,
|
|
31
|
+
description: undefined,
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
const emit = defineEmits<{
|
|
35
|
+
(event: "update:modelValue", value: AimdProtocolRecordData): void
|
|
36
|
+
(event: "fields-change", fields: ExtractedAimdFields): void
|
|
37
|
+
(event: "error", message: string): void
|
|
38
|
+
(event: "validation", result: AimdRecorderValidationResult): void
|
|
39
|
+
(event: "contract-error", issues: AimdResourceValidationIssue[]): void
|
|
40
|
+
}>()
|
|
41
|
+
|
|
42
|
+
const attrs = useAttrs()
|
|
43
|
+
const recorder = ref<InstanceType<typeof AimdRecorder> | null>(null)
|
|
44
|
+
|
|
45
|
+
function handleFieldsChange(fields: ExtractedAimdFields): void {
|
|
46
|
+
emit("fields-change", fields)
|
|
47
|
+
const issues = validateAimdProtocolContract(
|
|
48
|
+
{ kind: "resource_definition" },
|
|
49
|
+
fields,
|
|
50
|
+
)
|
|
51
|
+
if (issues.length > 0) emit("contract-error", issues)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function validate(options?: { focus?: boolean }): Promise<AimdRecorderValidationResult> {
|
|
55
|
+
if (!recorder.value) {
|
|
56
|
+
return Promise.resolve({
|
|
57
|
+
valid: true,
|
|
58
|
+
issues: [],
|
|
59
|
+
fieldState: {},
|
|
60
|
+
})
|
|
61
|
+
}
|
|
62
|
+
return recorder.value.validate(options)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
defineExpose({
|
|
66
|
+
validate,
|
|
67
|
+
validateField: (...args: Parameters<NonNullable<typeof recorder.value>["validateField"]>) =>
|
|
68
|
+
recorder.value?.validateField(...args),
|
|
69
|
+
clearValidation: (...args: Parameters<NonNullable<typeof recorder.value>["clearValidation"]>) =>
|
|
70
|
+
recorder.value?.clearValidation(...args),
|
|
71
|
+
focusFirstInvalidField: () => recorder.value?.focusFirstInvalidField() ?? false,
|
|
72
|
+
})
|
|
73
|
+
</script>
|
|
74
|
+
|
|
75
|
+
<template>
|
|
76
|
+
<section class="aimd-resource-form">
|
|
77
|
+
<header v-if="title || description" class="aimd-resource-form__header">
|
|
78
|
+
<h2 v-if="title" class="aimd-resource-form__title">{{ title }}</h2>
|
|
79
|
+
<p v-if="description" class="aimd-resource-form__description">{{ description }}</p>
|
|
80
|
+
</header>
|
|
81
|
+
<AimdRecorder
|
|
82
|
+
ref="recorder"
|
|
83
|
+
v-bind="attrs"
|
|
84
|
+
:content="content"
|
|
85
|
+
:model-value="modelValue"
|
|
86
|
+
:readonly="readonly"
|
|
87
|
+
:locale="locale"
|
|
88
|
+
:resource-resolvers="resourceResolvers"
|
|
89
|
+
:show-search="false"
|
|
90
|
+
@update:model-value="emit('update:modelValue', $event)"
|
|
91
|
+
@fields-change="handleFieldsChange"
|
|
92
|
+
@error="emit('error', $event)"
|
|
93
|
+
@validation="emit('validation', $event)"
|
|
94
|
+
/>
|
|
95
|
+
</section>
|
|
96
|
+
</template>
|
|
97
|
+
|
|
98
|
+
<style scoped>
|
|
99
|
+
.aimd-resource-form {
|
|
100
|
+
display: flex;
|
|
101
|
+
flex-direction: column;
|
|
102
|
+
gap: 1rem;
|
|
103
|
+
width: 100%;
|
|
104
|
+
min-width: 0;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
.aimd-resource-form__header {
|
|
108
|
+
padding-bottom: 0.75rem;
|
|
109
|
+
border-bottom: 1px solid var(--aimd-rec-border, #d8e2ef);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
.aimd-resource-form__title,
|
|
113
|
+
.aimd-resource-form__description {
|
|
114
|
+
margin: 0;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
.aimd-resource-form__title {
|
|
118
|
+
color: var(--aimd-rec-text, #172b4d);
|
|
119
|
+
font-size: 1.125rem;
|
|
120
|
+
line-height: 1.35;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
.aimd-resource-form__description {
|
|
124
|
+
margin-top: 0.25rem;
|
|
125
|
+
color: var(--aimd-rec-text-muted, #64748b);
|
|
126
|
+
font-size: 0.875rem;
|
|
127
|
+
line-height: 1.55;
|
|
128
|
+
}
|
|
129
|
+
</style>
|
|
@@ -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,8 +38,10 @@ import {
|
|
|
37
38
|
getScalarListInputItems,
|
|
38
39
|
getScalarListItemType,
|
|
39
40
|
getEntityRefTypeConfig,
|
|
41
|
+
getResourceRefTypeConfig,
|
|
40
42
|
getVarEnumSelectValue,
|
|
41
43
|
getVarEnumValueFromSelectValue,
|
|
44
|
+
isIntegerVarType,
|
|
42
45
|
isNullableVarType,
|
|
43
46
|
normalizeScalarListInputItems,
|
|
44
47
|
type NumericInputAttributes,
|
|
@@ -49,6 +52,7 @@ import AimdRequiredMarker from "./AimdRequiredMarker.vue"
|
|
|
49
52
|
|
|
50
53
|
const AimdCodeField = defineAsyncComponent(() => import("./AimdCodeField.vue"))
|
|
51
54
|
const AimdEntityRefField = defineAsyncComponent(() => import("./AimdEntityRefField.vue"))
|
|
55
|
+
const AimdResourceRefField = defineAsyncComponent(() => import("./AimdResourceRefField.vue"))
|
|
52
56
|
|
|
53
57
|
function normalizeMetaString(value: unknown): string | undefined {
|
|
54
58
|
return typeof value === "string" && value.trim() ? value.trim() : undefined
|
|
@@ -501,6 +505,7 @@ export default defineComponent({
|
|
|
501
505
|
resolveFile: { type: Function as PropType<((src: string) => string | null) | undefined>, default: undefined },
|
|
502
506
|
resolveFileInfo: { type: Function as PropType<AimdFileInfoResolver | undefined>, default: undefined },
|
|
503
507
|
entityResolvers: { type: Object as PropType<AimdEntityResolverMap | undefined>, default: undefined },
|
|
508
|
+
resourceResolvers: { type: Object as PropType<AimdResourceResolverMap | undefined>, default: undefined },
|
|
504
509
|
record: {
|
|
505
510
|
type: Object as PropType<AimdProtocolRecordData>,
|
|
506
511
|
default: () => ({ var: {}, step: {}, check: {}, quiz: {} }),
|
|
@@ -652,7 +657,7 @@ export default defineComponent({
|
|
|
652
657
|
const type = node.definition?.type || "str"
|
|
653
658
|
const normalizedType = normalizeVarTypeName(type)
|
|
654
659
|
const inputKind = props.inputKind
|
|
655
|
-
const isIntegerInput =
|
|
660
|
+
const isIntegerInput = isIntegerVarType(type)
|
|
656
661
|
const usesDecimalTextInput = inputKind === "number" && !isIntegerInput
|
|
657
662
|
const meta = props.fieldMeta
|
|
658
663
|
const disabled = props.disabled
|
|
@@ -781,8 +786,10 @@ export default defineComponent({
|
|
|
781
786
|
tabindex: hasHelp ? 0 : undefined,
|
|
782
787
|
"aria-label": help.tooltip || undefined,
|
|
783
788
|
}, [
|
|
784
|
-
h("span", { class: "aimd-field__title"
|
|
785
|
-
|
|
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
|
+
]),
|
|
786
793
|
hasCustomTitle ? h("span", { class: "aimd-field__key", title: id }, id) : null,
|
|
787
794
|
renderFieldMetadataPopover(help),
|
|
788
795
|
]),
|
|
@@ -966,6 +973,37 @@ export default defineComponent({
|
|
|
966
973
|
)
|
|
967
974
|
}
|
|
968
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
|
+
|
|
969
1007
|
if (inputKind === "file") {
|
|
970
1008
|
const fileConfig = getFileInputConfig(type, node.definition?.kwargs, meta)
|
|
971
1009
|
const fileId = getFileValueId(props.value)
|
package/src/components/index.ts
CHANGED
|
@@ -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
|