@airalogy/aimd-recorder 1.22.0 → 1.24.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 +80 -0
- package/README.zh-CN.md +80 -0
- package/dist/{AimdCodeField-BN_0UQMx.js → AimdCodeField-CPjcXY4D.js} +1 -1
- package/dist/{AimdDnaSequenceField-Bhj28fP8.js → AimdDnaSequenceField-Dz-IONoA.js} +5 -4
- package/dist/{AimdEditor.vue_vue_type_style_index_0_lang-D7c01UqN.js → AimdEditor.vue_vue_type_style_index_0_lang-JAD--qFs.js} +1999 -1900
- package/dist/AimdEntityRefField-BE0s2o5T.js +229 -0
- package/dist/{AimdMarkdownField-GS15pv4z.js → AimdMarkdownField-BeD2t9JY.js} +5 -5
- package/dist/{AimdMarkdownNoteField-H9WP8tR6.js → AimdMarkdownNoteField-DIgGEYpj.js} +16 -16
- package/dist/{_commonjsHelpers-B5RozER-.js → _commonjsHelpers-ByX85dGu.js} +12 -19
- package/dist/_plugin-vue_export-helper-CHgC5LLL.js +9 -0
- package/dist/aimd-recorder.css +1 -1
- package/dist/{arc-B50G9-kH.js → arc-CLJJdrm0.js} +1 -1
- package/dist/{architectureDiagram-3BPJPVTR-D9mBEbpY.js → architectureDiagram-3BPJPVTR-BizrFPnS.js} +3 -3
- package/dist/{blockDiagram-GPEHLZMM-Cs4swgto.js → blockDiagram-GPEHLZMM-IHDih8JW.js} +4 -4
- package/dist/{c4Diagram-AAUBKEIU-C12HKS3r.js → c4Diagram-AAUBKEIU-BQtg8m_M.js} +2 -2
- package/dist/{channel-D69VnjVz.js → channel-D8q7AX1Z.js} +1 -1
- package/dist/{chunk-2J33WTMH-oc-89G5c.js → chunk-2J33WTMH-C24lbKon.js} +1 -1
- package/dist/{chunk-4BX2VUAB-BDJS9G3r.js → chunk-4BX2VUAB-1m_lB_xe.js} +1 -1
- package/dist/{chunk-55IACEB6-BPl3uHcA.js → chunk-55IACEB6-BE5Nj-sd.js} +1 -1
- package/dist/{chunk-727SXJPM-pWe-vDGf.js → chunk-727SXJPM-Cg-Xw_d_.js} +5 -5
- package/dist/{chunk-AQP2D5EJ-D-R5sIr1.js → chunk-AQP2D5EJ-BvRpPCiY.js} +3 -3
- package/dist/{chunk-FMBD7UC4-bo6Qyom1.js → chunk-FMBD7UC4-D_44MTsg.js} +1 -1
- package/dist/{chunk-ND2GUHAM-DQMvtYV7.js → chunk-ND2GUHAM-tVBIo4LA.js} +1 -1
- package/dist/{chunk-QZHKN3VN-DlCn3HON.js → chunk-QZHKN3VN-B91HYLks.js} +1 -1
- package/dist/{classDiagram-v2-Q7XG4LA2-DzUwWFwr.js → classDiagram-4FO5ZUOK-CkejvTAN.js} +2 -2
- package/dist/{classDiagram-4FO5ZUOK-DzUwWFwr.js → classDiagram-v2-Q7XG4LA2-CkejvTAN.js} +2 -2
- package/dist/components.js +3869 -3359
- package/dist/composables.js +98 -93
- package/dist/{cose-bilkent-S5V4N54A-BXLMzfpO.js → cose-bilkent-S5V4N54A-CNcuriOF.js} +2 -2
- package/dist/{dagre-BM42HDAG-DHnofIh9.js → dagre-BM42HDAG-DMqFGafq.js} +3 -3
- package/dist/{diagram-2AECGRRQ-BqTTVPsm.js → diagram-2AECGRRQ-Cksd3pP3.js} +2 -2
- package/dist/{diagram-5GNKFQAL-D5p1UVbw.js → diagram-5GNKFQAL-SVjLnDJG.js} +3 -3
- package/dist/{diagram-KO2AKTUF-Uuoz9cFn.js → diagram-KO2AKTUF-DfNIAG6w.js} +2 -2
- package/dist/{diagram-LMA3HP47-W001U31X.js → diagram-LMA3HP47-DPOyCMGB.js} +2 -2
- package/dist/{diagram-OG6HWLK6-DL516LDr.js → diagram-OG6HWLK6-BDURmT37.js} +3 -3
- package/dist/{erDiagram-TEJ5UH35-CCxgMb67.js → erDiagram-TEJ5UH35-N991qII9.js} +4 -4
- package/dist/{flowDiagram-I6XJVG4X-nXGdmC0O.js → flowDiagram-I6XJVG4X-BABRFuk-.js} +6 -6
- package/dist/{ganttDiagram-6RSMTGT7-Bi9Ro7_Z.js → ganttDiagram-6RSMTGT7-BMDnK96S.js} +3 -3
- package/dist/{gitGraphDiagram-PVQCEYII-w1kNAy4E.js → gitGraphDiagram-PVQCEYII-cEvL7Dss.js} +3 -3
- package/dist/{graph-CpOkL_eZ.js → graph-BA09aCvZ.js} +1 -1
- package/dist/index.js +125 -113
- package/dist/{infoDiagram-5YYISTIA-Bde_w9T1.js → infoDiagram-5YYISTIA-DpC1Zthd.js} +1 -1
- package/dist/{ishikawaDiagram-YF4QCWOH-x5M1KR0l.js → ishikawaDiagram-YF4QCWOH-CMEt_f-x.js} +1 -1
- package/dist/{journeyDiagram-JHISSGLW-CIDQP8Zm.js → journeyDiagram-JHISSGLW-C0Qw169C.js} +4 -4
- package/dist/{kanban-definition-UN3LZRKU-CKgO7sG8.js → kanban-definition-UN3LZRKU-caROmSUy.js} +2 -2
- package/dist/{layout-BZYprqYR.js → layout-CH65__O4.js} +2 -2
- package/dist/{linear-ClSH2F_v.js → linear-B1VXpcsy.js} +1 -1
- package/dist/{mermaid.core-CcRV6K2R.js → mermaid.core-Cbmwvfvk.js} +35 -35
- package/dist/{mindmap-definition-RKZ34NQL-s3h6uszV.js → mindmap-definition-RKZ34NQL-DpTR5ilS.js} +3 -3
- package/dist/{pieDiagram-4H26LBE5-CgiazyWv.js → pieDiagram-4H26LBE5-Cb_KrmWC.js} +3 -3
- package/dist/{quadrantDiagram-W4KKPZXB-DCPVgHoW.js → quadrantDiagram-W4KKPZXB-B5_NswmK.js} +2 -2
- package/dist/record.js +77 -72
- package/dist/{requirementDiagram-4Y6WPE33-DE6F9oSB.js → requirementDiagram-4Y6WPE33-OFwfat5D.js} +3 -3
- package/dist/{sankeyDiagram-5OEKKPKP-DZZoFFr-.js → sankeyDiagram-5OEKKPKP-BaawdZEE.js} +1 -1
- package/dist/{sequenceDiagram-3UESZ5HK-DaYEOl60.js → sequenceDiagram-3UESZ5HK-DLv8X8ef.js} +3 -3
- package/dist/{stateDiagram-AJRCARHV-BmgpHJlH.js → stateDiagram-AJRCARHV-B6F3wrsd.js} +4 -4
- package/dist/{stateDiagram-v2-BHNVJYJU-D49CHQD6.js → stateDiagram-v2-BHNVJYJU-BcNEoshv.js} +2 -2
- package/dist/{timeline-definition-PNZ67QCA-DdVLoCkC.js → timeline-definition-PNZ67QCA-CvdHJ4eQ.js} +2 -2
- package/dist/useCodeBlockRendering-D2viVPtA.js +3158 -0
- package/dist/useFieldRendering-Co4DOOvL.js +1120 -0
- package/dist/useVarHelpers-Du2obGza.js +3474 -0
- package/dist/validation-oyqyD7Jp.js +5601 -0
- package/dist/{vennDiagram-CIIHVFJN-CCcMKcd7.js → vennDiagram-CIIHVFJN-U0GlQDjX.js} +1 -1
- package/dist/{wardleyDiagram-YWT4CUSO-R4UGgGWY.js → wardleyDiagram-YWT4CUSO-CzF_KMcn.js} +2 -2
- package/dist/{xychartDiagram-2RQKCTM6-DyFhCubk.js → xychartDiagram-2RQKCTM6-Cljki2Vk.js} +2 -2
- package/package.json +6 -4
- package/src/__tests__/collector-field.test.ts +269 -0
- package/src/__tests__/record-search-render.test.ts +1 -0
- package/src/__tests__/record-validation.test.ts +378 -0
- package/src/__tests__/recorder-wysiwyg-field-host.test.ts +26 -0
- package/src/__tests__/var-field-render.test.ts +64 -2
- package/src/components/AimdCollectorField.vue +233 -0
- package/src/components/AimdEntityRefField.vue +314 -0
- package/src/components/AimdRecorder.vue +285 -7
- package/src/components/AimdRecorderEditor.vue +51 -1
- package/src/components/AimdRecorderWysiwygFieldHost.vue +10 -0
- package/src/components/AimdRecorderWysiwygSurface.vue +166 -4
- package/src/components/AimdVarField.vue +39 -2
- package/src/components/AimdVarTableField.vue +38 -21
- package/src/components/index.ts +4 -0
- package/src/components/recorderMilkdownPlugin.ts +16 -0
- package/src/composables/__tests__/useVarHelpers.test.ts +32 -0
- package/src/composables/index.ts +12 -0
- package/src/composables/useCollectors.ts +399 -0
- package/src/composables/useVarHelpers.ts +130 -2
- package/src/index.ts +32 -2
- package/src/locales.ts +140 -2
- package/src/record/index.ts +14 -0
- package/src/record/validation.ts +772 -0
- package/src/styles/collector-field.css +281 -0
- package/src/styles/recorder-surface.css +163 -0
- package/src/styles/recorder.css +33 -0
- package/src/types.ts +168 -1
- package/dist/index-Dkrf2LJl.js +0 -1308
- package/dist/useCodeBlockRendering-CCuoP52e.js +0 -6103
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed, ref, watch } from "vue"
|
|
3
|
+
import { getAimdFieldDisplayLabel } from "@airalogy/aimd-core/utils"
|
|
4
|
+
import type { AimdVarNode } from "@airalogy/aimd-core/types"
|
|
5
|
+
import type { AimdRecorderMessages } from "../locales"
|
|
6
|
+
import { getAimdRecorderScopeLabel } from "../locales"
|
|
7
|
+
import type {
|
|
8
|
+
AimdCollectorObservation,
|
|
9
|
+
AimdCollectorRuntimeState,
|
|
10
|
+
AimdFieldMeta,
|
|
11
|
+
} from "../types"
|
|
12
|
+
import type { AimdCollectorBinding } from "../composables/useCollectors"
|
|
13
|
+
import {
|
|
14
|
+
getAimdCollectorManualValueType,
|
|
15
|
+
parseAimdCollectorManualValue,
|
|
16
|
+
} from "../composables/useCollectors"
|
|
17
|
+
|
|
18
|
+
const props = defineProps<{
|
|
19
|
+
node: AimdVarNode
|
|
20
|
+
binding: AimdCollectorBinding
|
|
21
|
+
value?: unknown
|
|
22
|
+
state: AimdCollectorRuntimeState
|
|
23
|
+
disabled?: boolean
|
|
24
|
+
providerAvailable: boolean
|
|
25
|
+
messages: AimdRecorderMessages
|
|
26
|
+
fieldMeta?: AimdFieldMeta
|
|
27
|
+
extraClasses?: string[]
|
|
28
|
+
}>()
|
|
29
|
+
|
|
30
|
+
const emit = defineEmits<{
|
|
31
|
+
(event: "start"): void
|
|
32
|
+
(event: "stop"): void
|
|
33
|
+
(event: "manual", payload: { value: unknown; reason: string }): void
|
|
34
|
+
(event: "blur"): void
|
|
35
|
+
}>()
|
|
36
|
+
|
|
37
|
+
const showManual = ref(false)
|
|
38
|
+
const manualValue = ref("")
|
|
39
|
+
const manualReason = ref("")
|
|
40
|
+
const manualError = ref("")
|
|
41
|
+
|
|
42
|
+
const type = computed(() => props.node.definition?.type || "Observation[str]")
|
|
43
|
+
const manualValueType = computed(() => getAimdCollectorManualValueType(type.value))
|
|
44
|
+
const title = computed(() => props.fieldMeta?.title || getAimdFieldDisplayLabel(props.node.id, props.node.definition))
|
|
45
|
+
const isBusy = computed(() => ["waiting_for_permission", "connecting", "collecting", "stopping"].includes(props.state.status))
|
|
46
|
+
const canStart = computed(() => (
|
|
47
|
+
!props.disabled
|
|
48
|
+
&& props.providerAvailable
|
|
49
|
+
&& !isBusy.value
|
|
50
|
+
&& props.state.status !== "unsupported"
|
|
51
|
+
&& !props.binding.isSeries
|
|
52
|
+
&& props.binding.collector.mode !== "stream"
|
|
53
|
+
))
|
|
54
|
+
const canStop = computed(() => !props.disabled && ["connecting", "collecting"].includes(props.state.status))
|
|
55
|
+
|
|
56
|
+
const observations = computed<AimdCollectorObservation[]>(() => {
|
|
57
|
+
const values = Array.isArray(props.value) ? props.value : [props.value]
|
|
58
|
+
return values.filter((value): value is AimdCollectorObservation => Boolean(
|
|
59
|
+
value
|
|
60
|
+
&& typeof value === "object"
|
|
61
|
+
&& !Array.isArray(value)
|
|
62
|
+
&& Object.prototype.hasOwnProperty.call(value, "value"),
|
|
63
|
+
))
|
|
64
|
+
})
|
|
65
|
+
const latestObservation = computed(() => observations.value[observations.value.length - 1])
|
|
66
|
+
const displayedValue = computed(() => formatValue(latestObservation.value?.value))
|
|
67
|
+
const displayedUnit = computed(() => latestObservation.value?.unit || String(props.node.definition?.kwargs?.unit ?? ""))
|
|
68
|
+
const displayedObservedAt = computed(() => {
|
|
69
|
+
const value = latestObservation.value?.observed_at || props.state.lastObservedAt
|
|
70
|
+
if (!value) return ""
|
|
71
|
+
const date = new Date(value)
|
|
72
|
+
return Number.isNaN(date.getTime()) ? value : date.toLocaleString()
|
|
73
|
+
})
|
|
74
|
+
const issueMessage = computed(() => {
|
|
75
|
+
if (!props.providerAvailable) return props.messages.collector.providerUnavailable
|
|
76
|
+
if (props.state.status === "unsupported") return props.messages.collector.unsupported
|
|
77
|
+
if (props.state.error === "provider_unavailable") return props.messages.collector.providerUnavailable
|
|
78
|
+
if (props.state.error === "permission_denied") return props.messages.collector.permissionDenied
|
|
79
|
+
return props.state.error || ""
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
watch(
|
|
83
|
+
() => props.disabled,
|
|
84
|
+
disabled => {
|
|
85
|
+
if (disabled) showManual.value = false
|
|
86
|
+
},
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
function formatValue(value: unknown): string {
|
|
90
|
+
if (value === undefined || value === null) return ""
|
|
91
|
+
if (typeof value === "string") return value
|
|
92
|
+
if (["number", "boolean", "bigint"].includes(typeof value)) return String(value)
|
|
93
|
+
try {
|
|
94
|
+
return JSON.stringify(value)
|
|
95
|
+
} catch {
|
|
96
|
+
return String(value)
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function start(): void {
|
|
101
|
+
manualError.value = ""
|
|
102
|
+
emit("start")
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function toggleManual(): void {
|
|
106
|
+
showManual.value = !showManual.value
|
|
107
|
+
manualError.value = ""
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function submitManual(): void {
|
|
111
|
+
if (!manualReason.value.trim()) {
|
|
112
|
+
manualError.value = props.messages.collector.reasonRequired
|
|
113
|
+
return
|
|
114
|
+
}
|
|
115
|
+
const parsed = parseAimdCollectorManualValue(type.value, manualValue.value)
|
|
116
|
+
if (!parsed.ok) {
|
|
117
|
+
manualError.value = props.messages.collector.invalidValue
|
|
118
|
+
return
|
|
119
|
+
}
|
|
120
|
+
emit("manual", { value: parsed.value, reason: manualReason.value.trim() })
|
|
121
|
+
manualValue.value = ""
|
|
122
|
+
manualReason.value = ""
|
|
123
|
+
manualError.value = ""
|
|
124
|
+
showManual.value = false
|
|
125
|
+
}
|
|
126
|
+
</script>
|
|
127
|
+
|
|
128
|
+
<template>
|
|
129
|
+
<span
|
|
130
|
+
class="aimd-rec-collector aimd-field-wrapper aimd-field-wrapper--inline"
|
|
131
|
+
:class="[
|
|
132
|
+
`aimd-rec-collector--${state.status}`,
|
|
133
|
+
...(extraClasses ?? []),
|
|
134
|
+
]"
|
|
135
|
+
:data-rec-collector="binding.collector.id"
|
|
136
|
+
>
|
|
137
|
+
<span class="aimd-rec-collector__header">
|
|
138
|
+
<span class="aimd-field__scope aimd-field__scope--var">{{ getAimdRecorderScopeLabel("var", messages) }}</span>
|
|
139
|
+
<span class="aimd-rec-collector__identity">
|
|
140
|
+
<span class="aimd-rec-collector__title">{{ title }}</span>
|
|
141
|
+
<span v-if="title !== node.id" class="aimd-rec-collector__key">{{ node.id }}</span>
|
|
142
|
+
</span>
|
|
143
|
+
<span class="aimd-rec-collector__source" :title="binding.connector.id">
|
|
144
|
+
{{ binding.collector.title || binding.collector.id }}
|
|
145
|
+
</span>
|
|
146
|
+
<span class="aimd-rec-collector__status" :class="`aimd-rec-collector__status--${state.status}`">
|
|
147
|
+
<span class="aimd-rec-collector__status-dot" aria-hidden="true" />
|
|
148
|
+
{{ messages.collector.status[state.status] }}
|
|
149
|
+
</span>
|
|
150
|
+
</span>
|
|
151
|
+
|
|
152
|
+
<span class="aimd-rec-collector__body">
|
|
153
|
+
<span class="aimd-rec-collector__reading">
|
|
154
|
+
<span v-if="displayedValue" class="aimd-rec-collector__value" :title="displayedValue">{{ displayedValue }}</span>
|
|
155
|
+
<span v-else class="aimd-rec-collector__empty">{{ messages.common.emptyValue }}</span>
|
|
156
|
+
<span v-if="displayedUnit" class="aimd-rec-collector__unit">{{ displayedUnit }}</span>
|
|
157
|
+
</span>
|
|
158
|
+
|
|
159
|
+
<span class="aimd-rec-collector__meta">
|
|
160
|
+
<span v-if="binding.isList">{{ messages.collector.sampleCount(observations.length) }}</span>
|
|
161
|
+
<span v-if="displayedObservedAt">{{ messages.collector.lastObserved(displayedObservedAt) }}</span>
|
|
162
|
+
</span>
|
|
163
|
+
|
|
164
|
+
<span class="aimd-rec-collector__actions">
|
|
165
|
+
<button
|
|
166
|
+
v-if="canStop"
|
|
167
|
+
type="button"
|
|
168
|
+
class="aimd-rec-collector__button aimd-rec-collector__button--danger"
|
|
169
|
+
:disabled="disabled"
|
|
170
|
+
@click="emit('stop')"
|
|
171
|
+
>
|
|
172
|
+
{{ messages.collector.stop }}
|
|
173
|
+
</button>
|
|
174
|
+
<button
|
|
175
|
+
v-else
|
|
176
|
+
type="button"
|
|
177
|
+
class="aimd-rec-collector__button aimd-rec-collector__button--primary"
|
|
178
|
+
:disabled="!canStart"
|
|
179
|
+
@click="start"
|
|
180
|
+
>
|
|
181
|
+
{{ state.status === "error"
|
|
182
|
+
? messages.collector.retry
|
|
183
|
+
: binding.collector.mode === "snapshot"
|
|
184
|
+
? messages.collector.snapshot
|
|
185
|
+
: messages.collector.start }}
|
|
186
|
+
</button>
|
|
187
|
+
<button
|
|
188
|
+
v-if="binding.collector.manual_fallback"
|
|
189
|
+
type="button"
|
|
190
|
+
class="aimd-rec-collector__button"
|
|
191
|
+
:disabled="disabled || isBusy"
|
|
192
|
+
:aria-expanded="showManual"
|
|
193
|
+
@click="toggleManual"
|
|
194
|
+
>
|
|
195
|
+
{{ showManual ? messages.collector.cancelManual : messages.collector.manualEntry }}
|
|
196
|
+
</button>
|
|
197
|
+
</span>
|
|
198
|
+
</span>
|
|
199
|
+
|
|
200
|
+
<span v-if="issueMessage" class="aimd-rec-collector__message" role="status">{{ issueMessage }}</span>
|
|
201
|
+
|
|
202
|
+
<span v-if="showManual" class="aimd-rec-collector__manual">
|
|
203
|
+
<textarea
|
|
204
|
+
v-model="manualValue"
|
|
205
|
+
:data-rec-focus-key="`var:${node.id}`"
|
|
206
|
+
class="aimd-rec-collector__manual-value"
|
|
207
|
+
rows="1"
|
|
208
|
+
:placeholder="`${messages.collector.valuePlaceholder} (${manualValueType})`"
|
|
209
|
+
:disabled="disabled"
|
|
210
|
+
@blur="emit('blur')"
|
|
211
|
+
/>
|
|
212
|
+
<input
|
|
213
|
+
v-model="manualReason"
|
|
214
|
+
class="aimd-rec-collector__manual-reason"
|
|
215
|
+
type="text"
|
|
216
|
+
:placeholder="messages.collector.reasonPlaceholder"
|
|
217
|
+
:disabled="disabled"
|
|
218
|
+
@blur="emit('blur')"
|
|
219
|
+
>
|
|
220
|
+
<button
|
|
221
|
+
type="button"
|
|
222
|
+
class="aimd-rec-collector__button aimd-rec-collector__button--primary"
|
|
223
|
+
:disabled="disabled"
|
|
224
|
+
@click="submitManual"
|
|
225
|
+
>
|
|
226
|
+
{{ messages.collector.saveManual }}
|
|
227
|
+
</button>
|
|
228
|
+
<span v-if="manualError" class="aimd-rec-collector__message aimd-rec-collector__message--error" role="alert">
|
|
229
|
+
{{ manualError }}
|
|
230
|
+
</span>
|
|
231
|
+
</span>
|
|
232
|
+
</span>
|
|
233
|
+
</template>
|
|
@@ -0,0 +1,314 @@
|
|
|
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
|
+
AimdEntityRefOption,
|
|
6
|
+
AimdEntityRefValue,
|
|
7
|
+
AimdEntityResolverEntry,
|
|
8
|
+
AimdEntityResolverMap,
|
|
9
|
+
AimdFieldMeta,
|
|
10
|
+
AimdProtocolRecordData,
|
|
11
|
+
} from "../types"
|
|
12
|
+
import type { AimdRecorderMessages } from "../locales"
|
|
13
|
+
import type { EntityRefTypeConfig } from "../composables/useVarHelpers"
|
|
14
|
+
import { normalizeVarTypeName } from "../composables/useVarHelpers"
|
|
15
|
+
|
|
16
|
+
const props = defineProps<{
|
|
17
|
+
node: AimdVarNode
|
|
18
|
+
value?: unknown
|
|
19
|
+
disabled?: boolean
|
|
20
|
+
messages: AimdRecorderMessages
|
|
21
|
+
fieldMeta?: AimdFieldMeta
|
|
22
|
+
type: string
|
|
23
|
+
entityConfig: EntityRefTypeConfig
|
|
24
|
+
entityResolvers?: AimdEntityResolverMap
|
|
25
|
+
record: AimdProtocolRecordData
|
|
26
|
+
}>()
|
|
27
|
+
|
|
28
|
+
const emit = defineEmits<{
|
|
29
|
+
(e: "change", payload: { value: unknown }): void
|
|
30
|
+
(e: "blur"): void
|
|
31
|
+
}>()
|
|
32
|
+
|
|
33
|
+
const query = ref("")
|
|
34
|
+
const options = ref<AimdEntityRefOption[]>([])
|
|
35
|
+
const searching = ref(false)
|
|
36
|
+
const searchError = ref("")
|
|
37
|
+
let searchRequestId = 0
|
|
38
|
+
|
|
39
|
+
const fieldKey = computed(() => `var:${props.node.id}`)
|
|
40
|
+
const entityName = computed(() => props.entityConfig.entity || "entity")
|
|
41
|
+
const resolver = computed<AimdEntityResolverEntry | undefined>(() => {
|
|
42
|
+
const resolvers = props.entityResolvers
|
|
43
|
+
if (!resolvers) return undefined
|
|
44
|
+
return (props.entityConfig.source ? resolvers[props.entityConfig.source] : undefined)
|
|
45
|
+
?? (props.entityConfig.entity ? resolvers[props.entityConfig.entity] : undefined)
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
function normalizeEntityString(value: unknown): string | undefined {
|
|
49
|
+
if (typeof value !== "string") return undefined
|
|
50
|
+
const trimmed = value.trim()
|
|
51
|
+
return trimmed || undefined
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function normalizeEntityRefValue(value: unknown): AimdEntityRefValue | null {
|
|
55
|
+
if (typeof value === "string") {
|
|
56
|
+
const id = value.trim()
|
|
57
|
+
if (!id) return null
|
|
58
|
+
return {
|
|
59
|
+
entity: entityName.value,
|
|
60
|
+
source: props.entityConfig.source,
|
|
61
|
+
id,
|
|
62
|
+
label: id,
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
67
|
+
return null
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const record = value as Record<string, unknown>
|
|
71
|
+
const id = normalizeEntityString(record.id)
|
|
72
|
+
?? normalizeEntityString(record.value)
|
|
73
|
+
?? normalizeEntityString(record.key)
|
|
74
|
+
if (!id) return null
|
|
75
|
+
|
|
76
|
+
const label = normalizeEntityString(record.label)
|
|
77
|
+
?? normalizeEntityString(record.name)
|
|
78
|
+
?? normalizeEntityString(record.title)
|
|
79
|
+
?? id
|
|
80
|
+
const entity = normalizeEntityString(record.entity) ?? entityName.value
|
|
81
|
+
const source = normalizeEntityString(record.source) ?? props.entityConfig.source
|
|
82
|
+
|
|
83
|
+
const normalizedRecord = { ...record }
|
|
84
|
+
delete normalizedRecord.disabled
|
|
85
|
+
|
|
86
|
+
return {
|
|
87
|
+
...normalizedRecord,
|
|
88
|
+
entity,
|
|
89
|
+
id,
|
|
90
|
+
source,
|
|
91
|
+
label,
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const selectedRefs = computed<AimdEntityRefValue[]>(() => {
|
|
96
|
+
if (props.entityConfig.multiple) {
|
|
97
|
+
const values = Array.isArray(props.value) ? props.value : (props.value ? [props.value] : [])
|
|
98
|
+
return values
|
|
99
|
+
.map(item => normalizeEntityRefValue(item))
|
|
100
|
+
.filter((item): item is AimdEntityRefValue => item !== null)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const normalized = normalizeEntityRefValue(props.value)
|
|
104
|
+
return normalized ? [normalized] : []
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
const selectedKeySet = computed(() => new Set(
|
|
108
|
+
selectedRefs.value.map(item => `${item.source ?? ""}:${item.entity}:${item.id}`),
|
|
109
|
+
))
|
|
110
|
+
|
|
111
|
+
function makeSearchContext() {
|
|
112
|
+
return {
|
|
113
|
+
type: props.type,
|
|
114
|
+
normalizedType: normalizeVarTypeName(props.type),
|
|
115
|
+
fieldKey: fieldKey.value,
|
|
116
|
+
node: props.node,
|
|
117
|
+
fieldMeta: props.fieldMeta,
|
|
118
|
+
entity: props.entityConfig.entity,
|
|
119
|
+
source: props.entityConfig.source,
|
|
120
|
+
query: query.value,
|
|
121
|
+
multiple: props.entityConfig.multiple,
|
|
122
|
+
record: props.record,
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
async function runSearch(): Promise<void> {
|
|
127
|
+
const currentQuery = query.value.trim()
|
|
128
|
+
const currentResolver = resolver.value
|
|
129
|
+
const requestId = ++searchRequestId
|
|
130
|
+
options.value = []
|
|
131
|
+
searchError.value = ""
|
|
132
|
+
if (!currentResolver || !currentQuery) {
|
|
133
|
+
searching.value = false
|
|
134
|
+
return
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
searching.value = true
|
|
138
|
+
try {
|
|
139
|
+
const search = typeof currentResolver === "function"
|
|
140
|
+
? currentResolver
|
|
141
|
+
: currentResolver.search
|
|
142
|
+
const result = await search(currentQuery, makeSearchContext())
|
|
143
|
+
if (requestId === searchRequestId) {
|
|
144
|
+
options.value = result
|
|
145
|
+
.map(item => normalizeEntityRefValue(item))
|
|
146
|
+
.filter((item): item is AimdEntityRefValue => item !== null)
|
|
147
|
+
.map((item) => {
|
|
148
|
+
const raw = result.find(candidate => normalizeEntityRefValue(candidate)?.id === item.id)
|
|
149
|
+
return {
|
|
150
|
+
...(raw ?? item),
|
|
151
|
+
...item,
|
|
152
|
+
disabled: Boolean((raw as AimdEntityRefOption | undefined)?.disabled),
|
|
153
|
+
description: (raw as AimdEntityRefOption | undefined)?.description,
|
|
154
|
+
}
|
|
155
|
+
})
|
|
156
|
+
}
|
|
157
|
+
} catch {
|
|
158
|
+
if (requestId === searchRequestId) {
|
|
159
|
+
searchError.value = props.messages.entityRef.searchFailed
|
|
160
|
+
}
|
|
161
|
+
} finally {
|
|
162
|
+
if (requestId === searchRequestId) {
|
|
163
|
+
searching.value = false
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
watch(
|
|
169
|
+
() => [
|
|
170
|
+
query.value,
|
|
171
|
+
props.entityResolvers,
|
|
172
|
+
props.entityConfig.entity,
|
|
173
|
+
props.entityConfig.source,
|
|
174
|
+
] as const,
|
|
175
|
+
() => {
|
|
176
|
+
void runSearch()
|
|
177
|
+
},
|
|
178
|
+
{ immediate: true },
|
|
179
|
+
)
|
|
180
|
+
|
|
181
|
+
function emitSelected(nextRefs: AimdEntityRefValue[]): void {
|
|
182
|
+
emit("change", {
|
|
183
|
+
value: props.entityConfig.multiple
|
|
184
|
+
? nextRefs
|
|
185
|
+
: nextRefs[0] ?? null,
|
|
186
|
+
})
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function selectRef(value: unknown): void {
|
|
190
|
+
const normalized = normalizeEntityRefValue(value)
|
|
191
|
+
if (!normalized) return
|
|
192
|
+
|
|
193
|
+
if (props.entityConfig.multiple) {
|
|
194
|
+
const key = `${normalized.source ?? ""}:${normalized.entity}:${normalized.id}`
|
|
195
|
+
if (!selectedKeySet.value.has(key)) {
|
|
196
|
+
emitSelected([...selectedRefs.value, normalized])
|
|
197
|
+
}
|
|
198
|
+
} else {
|
|
199
|
+
emitSelected([normalized])
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
query.value = ""
|
|
203
|
+
options.value = []
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function selectManualQuery(): void {
|
|
207
|
+
const id = query.value.trim()
|
|
208
|
+
if (!id) return
|
|
209
|
+
selectRef(id)
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function removeRef(index: number): void {
|
|
213
|
+
const nextRefs = selectedRefs.value.filter((_, itemIndex) => itemIndex !== index)
|
|
214
|
+
emitSelected(nextRefs)
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function clearSingle(): void {
|
|
218
|
+
emitSelected([])
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
function optionKey(option: AimdEntityRefOption): string {
|
|
222
|
+
return `${option.source ?? ""}:${option.entity}:${option.id}`
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function displayLabel(value: AimdEntityRefValue): string {
|
|
226
|
+
return value.label || value.id
|
|
227
|
+
}
|
|
228
|
+
</script>
|
|
229
|
+
|
|
230
|
+
<template>
|
|
231
|
+
<span class="aimd-rec-entity-ref">
|
|
232
|
+
<span v-if="selectedRefs.length" class="aimd-rec-entity-ref__selected">
|
|
233
|
+
<span
|
|
234
|
+
v-for="(item, index) in selectedRefs"
|
|
235
|
+
:key="`${item.source ?? ''}:${item.entity}:${item.id}:${index}`"
|
|
236
|
+
class="aimd-rec-entity-ref__chip"
|
|
237
|
+
>
|
|
238
|
+
<span class="aimd-rec-entity-ref__entity">{{ item.entity }}</span>
|
|
239
|
+
<span class="aimd-rec-entity-ref__label" :title="displayLabel(item)">
|
|
240
|
+
{{ displayLabel(item) }}
|
|
241
|
+
</span>
|
|
242
|
+
<span class="aimd-rec-entity-ref__id" :title="item.id">{{ item.id }}</span>
|
|
243
|
+
<button
|
|
244
|
+
v-if="!disabled"
|
|
245
|
+
type="button"
|
|
246
|
+
class="aimd-rec-entity-ref__chip-remove"
|
|
247
|
+
:aria-label="messages.entityRef.remove"
|
|
248
|
+
:title="messages.entityRef.remove"
|
|
249
|
+
@click="removeRef(index)"
|
|
250
|
+
>
|
|
251
|
+
×
|
|
252
|
+
</button>
|
|
253
|
+
</span>
|
|
254
|
+
</span>
|
|
255
|
+
|
|
256
|
+
<span class="aimd-rec-entity-ref__search-row">
|
|
257
|
+
<input
|
|
258
|
+
v-model="query"
|
|
259
|
+
:data-rec-focus-key="fieldKey"
|
|
260
|
+
class="aimd-rec-inline__value-control aimd-rec-inline__input aimd-rec-inline__input--stacked aimd-rec-entity-ref__input"
|
|
261
|
+
:disabled="disabled"
|
|
262
|
+
:placeholder="resolver ? messages.entityRef.searchPlaceholder(entityName) : messages.entityRef.manualIdPlaceholder"
|
|
263
|
+
@keydown.enter.prevent="selectManualQuery"
|
|
264
|
+
@blur="emit('blur')"
|
|
265
|
+
>
|
|
266
|
+
<button
|
|
267
|
+
v-if="query.trim() && !disabled"
|
|
268
|
+
type="button"
|
|
269
|
+
class="aimd-rec-entity-ref__action"
|
|
270
|
+
@click="selectManualQuery"
|
|
271
|
+
>
|
|
272
|
+
{{ entityConfig.multiple ? messages.entityRef.add : messages.entityRef.select }}
|
|
273
|
+
</button>
|
|
274
|
+
<button
|
|
275
|
+
v-if="!entityConfig.multiple && selectedRefs.length && !disabled"
|
|
276
|
+
type="button"
|
|
277
|
+
class="aimd-rec-entity-ref__action aimd-rec-entity-ref__action--secondary"
|
|
278
|
+
@click="clearSingle"
|
|
279
|
+
>
|
|
280
|
+
{{ messages.entityRef.clear }}
|
|
281
|
+
</button>
|
|
282
|
+
</span>
|
|
283
|
+
|
|
284
|
+
<span v-if="!resolver" class="aimd-rec-entity-ref__hint">
|
|
285
|
+
{{ messages.entityRef.noResolver }}
|
|
286
|
+
</span>
|
|
287
|
+
<span v-else-if="searchError" class="aimd-rec-entity-ref__error">
|
|
288
|
+
{{ searchError }}
|
|
289
|
+
</span>
|
|
290
|
+
<span
|
|
291
|
+
v-else-if="query.trim() && !searching && options.length === 0"
|
|
292
|
+
class="aimd-rec-entity-ref__hint"
|
|
293
|
+
>
|
|
294
|
+
{{ messages.entityRef.noMatches }}
|
|
295
|
+
</span>
|
|
296
|
+
|
|
297
|
+
<span v-if="options.length" class="aimd-rec-entity-ref__options">
|
|
298
|
+
<button
|
|
299
|
+
v-for="option in options"
|
|
300
|
+
:key="optionKey(option)"
|
|
301
|
+
type="button"
|
|
302
|
+
class="aimd-rec-entity-ref__option"
|
|
303
|
+
:disabled="disabled || option.disabled || selectedKeySet.has(optionKey(option))"
|
|
304
|
+
@click="selectRef(option)"
|
|
305
|
+
>
|
|
306
|
+
<span class="aimd-rec-entity-ref__option-label">{{ displayLabel(option) }}</span>
|
|
307
|
+
<span class="aimd-rec-entity-ref__option-id">{{ option.id }}</span>
|
|
308
|
+
<span v-if="option.description" class="aimd-rec-entity-ref__option-description">
|
|
309
|
+
{{ option.description }}
|
|
310
|
+
</span>
|
|
311
|
+
</button>
|
|
312
|
+
</span>
|
|
313
|
+
</span>
|
|
314
|
+
</template>
|