@airalogy/aimd-recorder 1.20.0 → 1.22.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 +5 -0
- package/README.zh-CN.md +5 -0
- package/dist/{AimdCodeField-BQUuM-EF.js → AimdCodeField-BN_0UQMx.js} +34 -32
- package/dist/{AimdDnaSequenceField-Cp0cgBYl.js → AimdDnaSequenceField-Bhj28fP8.js} +1 -1
- package/dist/{AimdEditor.vue_vue_type_style_index_0_lang-DTdcoNs1.js → AimdEditor.vue_vue_type_style_index_0_lang-D7c01UqN.js} +1040 -976
- package/dist/{AimdMarkdownField-D4AEz_mB.js → AimdMarkdownField-GS15pv4z.js} +4 -4
- package/dist/{AimdMarkdownNoteField-CSGaShKi.js → AimdMarkdownNoteField-H9WP8tR6.js} +15 -15
- package/dist/aimd-recorder.css +1 -1
- package/dist/{arc-jL17V0L2.js → arc-B50G9-kH.js} +1 -1
- package/dist/{architectureDiagram-3BPJPVTR-CijadmFI.js → architectureDiagram-3BPJPVTR-D9mBEbpY.js} +2 -2
- package/dist/{blockDiagram-GPEHLZMM-BPqvb85_.js → blockDiagram-GPEHLZMM-Cs4swgto.js} +4 -4
- package/dist/{c4Diagram-AAUBKEIU-i4fqlMXu.js → c4Diagram-AAUBKEIU-C12HKS3r.js} +2 -2
- package/dist/{channel-DnnUQTdl.js → channel-D69VnjVz.js} +1 -1
- package/dist/{chunk-2J33WTMH-DKKEpdr1.js → chunk-2J33WTMH-oc-89G5c.js} +1 -1
- package/dist/{chunk-4BX2VUAB-WvuuiYYH.js → chunk-4BX2VUAB-BDJS9G3r.js} +1 -1
- package/dist/{chunk-55IACEB6-B_UkHTnd.js → chunk-55IACEB6-BPl3uHcA.js} +1 -1
- package/dist/{chunk-727SXJPM-CR6Pb04P.js → chunk-727SXJPM-pWe-vDGf.js} +5 -5
- package/dist/{chunk-AQP2D5EJ-B68Ie417.js → chunk-AQP2D5EJ-D-R5sIr1.js} +3 -3
- package/dist/{chunk-FMBD7UC4-CeCGT6rb.js → chunk-FMBD7UC4-bo6Qyom1.js} +1 -1
- package/dist/{chunk-ND2GUHAM-BYN-eC_q.js → chunk-ND2GUHAM-DQMvtYV7.js} +1 -1
- package/dist/{chunk-QZHKN3VN-BNSp120j.js → chunk-QZHKN3VN-DlCn3HON.js} +1 -1
- package/dist/{classDiagram-v2-Q7XG4LA2-Cgbn4w3f.js → classDiagram-4FO5ZUOK-DzUwWFwr.js} +2 -2
- package/dist/{classDiagram-4FO5ZUOK-Cgbn4w3f.js → classDiagram-v2-Q7XG4LA2-DzUwWFwr.js} +2 -2
- package/dist/components.js +3757 -2910
- package/dist/composables.js +84 -80
- package/dist/{cose-bilkent-S5V4N54A-TfrsQ2c3.js → cose-bilkent-S5V4N54A-BXLMzfpO.js} +1 -1
- package/dist/{dagre-BM42HDAG-BAyvB_JI.js → dagre-BM42HDAG-DHnofIh9.js} +3 -3
- package/dist/{diagram-2AECGRRQ-Bijq8bHO.js → diagram-2AECGRRQ-BqTTVPsm.js} +2 -2
- package/dist/{diagram-5GNKFQAL-B3ZuTuxm.js → diagram-5GNKFQAL-D5p1UVbw.js} +3 -3
- package/dist/{diagram-KO2AKTUF-DrqLeGCI.js → diagram-KO2AKTUF-Uuoz9cFn.js} +2 -2
- package/dist/{diagram-LMA3HP47-CCSQH8O0.js → diagram-LMA3HP47-W001U31X.js} +2 -2
- package/dist/{diagram-OG6HWLK6-DM5cUEjW.js → diagram-OG6HWLK6-DL516LDr.js} +3 -3
- package/dist/{erDiagram-TEJ5UH35-DQhmDdAF.js → erDiagram-TEJ5UH35-CCxgMb67.js} +4 -4
- package/dist/{flowDiagram-I6XJVG4X-DrqiPSHI.js → flowDiagram-I6XJVG4X-nXGdmC0O.js} +6 -6
- package/dist/{ganttDiagram-6RSMTGT7-DpX_Y2vA.js → ganttDiagram-6RSMTGT7-Bi9Ro7_Z.js} +2 -2
- package/dist/{gitGraphDiagram-PVQCEYII-3isOhIyZ.js → gitGraphDiagram-PVQCEYII-w1kNAy4E.js} +3 -3
- package/dist/{graph-C30SJlSk.js → graph-CpOkL_eZ.js} +1 -1
- package/dist/{index-Dtvv88SS.js → index-Dkrf2LJl.js} +51 -51
- package/dist/index.js +62 -58
- package/dist/{infoDiagram-5YYISTIA-Cr_MlPvz.js → infoDiagram-5YYISTIA-Bde_w9T1.js} +1 -1
- package/dist/{ishikawaDiagram-YF4QCWOH-DydyFn3h.js → ishikawaDiagram-YF4QCWOH-x5M1KR0l.js} +1 -1
- package/dist/{journeyDiagram-JHISSGLW-V_5MmeOu.js → journeyDiagram-JHISSGLW-CIDQP8Zm.js} +4 -4
- package/dist/{kanban-definition-UN3LZRKU-C_XXCuvp.js → kanban-definition-UN3LZRKU-CKgO7sG8.js} +2 -2
- package/dist/{layout-85j-z7Lr.js → layout-BZYprqYR.js} +2 -2
- package/dist/{linear-DMtodz-6.js → linear-ClSH2F_v.js} +1 -1
- package/dist/{mermaid.core-CkanUCyS.js → mermaid.core-CcRV6K2R.js} +34 -34
- package/dist/{mindmap-definition-RKZ34NQL-CyikmuF2.js → mindmap-definition-RKZ34NQL-s3h6uszV.js} +3 -3
- package/dist/{pieDiagram-4H26LBE5-CesqzEGg.js → pieDiagram-4H26LBE5-CgiazyWv.js} +3 -3
- package/dist/{quadrantDiagram-W4KKPZXB-BsPKPfNd.js → quadrantDiagram-W4KKPZXB-DCPVgHoW.js} +2 -2
- package/dist/record.js +19 -19
- package/dist/{requirementDiagram-4Y6WPE33-BwB1tQvi.js → requirementDiagram-4Y6WPE33-DE6F9oSB.js} +3 -3
- package/dist/{sankeyDiagram-5OEKKPKP-CfSNbWMY.js → sankeyDiagram-5OEKKPKP-DZZoFFr-.js} +1 -1
- package/dist/{sequenceDiagram-3UESZ5HK-DZZlUNys.js → sequenceDiagram-3UESZ5HK-DaYEOl60.js} +3 -3
- package/dist/{stateDiagram-AJRCARHV-DNJmz_op.js → stateDiagram-AJRCARHV-BmgpHJlH.js} +4 -4
- package/dist/{stateDiagram-v2-BHNVJYJU-DVfDNM6l.js → stateDiagram-v2-BHNVJYJU-D49CHQD6.js} +2 -2
- package/dist/{timeline-definition-PNZ67QCA-DEUCAg_N.js → timeline-definition-PNZ67QCA-DdVLoCkC.js} +2 -2
- package/dist/{useCodeBlockRendering-DF6zm7nf.js → useCodeBlockRendering-CCuoP52e.js} +1241 -1074
- package/dist/{vennDiagram-CIIHVFJN-DVDP__od.js → vennDiagram-CIIHVFJN-CCcMKcd7.js} +1 -1
- package/dist/{wardleyDiagram-YWT4CUSO-sEtxBd33.js → wardleyDiagram-YWT4CUSO-R4UGgGWY.js} +2 -2
- package/dist/{xychartDiagram-2RQKCTM6-DM8QeR5M.js → xychartDiagram-2RQKCTM6-DyFhCubk.js} +2 -2
- package/package.json +3 -3
- package/src/__tests__/record-search-render.test.ts +108 -0
- package/src/__tests__/recorder-assigner-control.test.ts +4 -1
- package/src/__tests__/var-field-render.test.ts +556 -43
- package/src/components/AimdCodeField.vue +11 -3
- package/src/components/AimdQuizRecorder.vue +3 -1
- package/src/components/AimdRecorder.vue +52 -1882
- package/src/components/AimdRecorderSearchToolbar.vue +258 -0
- package/src/components/AimdVarField.vue +589 -17
- package/src/components/AimdVarTableField.vue +12 -6
- package/src/components/index.ts +1 -0
- package/src/composables/__tests__/useVarHelpers.test.ts +214 -7
- package/src/composables/index.ts +6 -0
- package/src/composables/useFieldRendering.ts +28 -0
- package/src/composables/useRecordSearch.ts +299 -0
- package/src/composables/useVarHelpers.ts +285 -14
- package/src/locales.ts +96 -0
- package/src/styles/recorder-surface.css +2374 -0
- package/src/styles/recorder.css +1 -0
- package/src/types.ts +1 -1
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
import { computed, nextTick, onBeforeUnmount, ref, watch, type Ref } from "vue"
|
|
2
|
+
import type { ExtractedAimdFields } from "@airalogy/aimd-core/types"
|
|
3
|
+
import {
|
|
4
|
+
collectAimdRecordFieldRefs,
|
|
5
|
+
searchAimdRecordFields,
|
|
6
|
+
type AimdRecordFieldRef,
|
|
7
|
+
type AimdRecordSearchMatch,
|
|
8
|
+
} from "@airalogy/aimd-core/utils"
|
|
9
|
+
import type { AimdRecorderMessages } from "../locales"
|
|
10
|
+
import type { AimdProtocolRecordData } from "../types"
|
|
11
|
+
|
|
12
|
+
interface UseRecordSearchOptions {
|
|
13
|
+
contentRoot: Ref<HTMLElement | null>
|
|
14
|
+
defaultExpanded: boolean
|
|
15
|
+
fields: Ref<ExtractedAimdFields>
|
|
16
|
+
messages: Ref<AimdRecorderMessages>
|
|
17
|
+
onVisualStateChange: () => void
|
|
18
|
+
record: AimdProtocolRecordData
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function getMatchFieldKeys(match: AimdRecordSearchMatch): string[] {
|
|
22
|
+
return match.field.parentKey ? [match.field.key, match.field.parentKey] : [match.field.key]
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function isTextControl(element: Element | null): element is HTMLInputElement | HTMLTextAreaElement {
|
|
26
|
+
return (
|
|
27
|
+
(typeof HTMLInputElement !== "undefined" && element instanceof HTMLInputElement)
|
|
28
|
+
|| (typeof HTMLTextAreaElement !== "undefined" && element instanceof HTMLTextAreaElement)
|
|
29
|
+
)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function getFocusableElement(target: HTMLElement): HTMLElement {
|
|
33
|
+
if (target.matches("input, textarea, select, button, [tabindex]:not([tabindex='-1'])")) {
|
|
34
|
+
return target
|
|
35
|
+
}
|
|
36
|
+
return target.querySelector<HTMLElement>("input, textarea, select, button, [tabindex]:not([tabindex='-1'])") ?? target
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function getTextControl(target: HTMLElement): HTMLInputElement | HTMLTextAreaElement | null {
|
|
40
|
+
if (isTextControl(target)) {
|
|
41
|
+
return target
|
|
42
|
+
}
|
|
43
|
+
return target.querySelector<HTMLInputElement | HTMLTextAreaElement>("textarea, input")
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function useRecordSearch(options: UseRecordSearchOptions) {
|
|
47
|
+
const query = ref("")
|
|
48
|
+
const fieldKey = ref("")
|
|
49
|
+
const activeMatchIndex = ref(0)
|
|
50
|
+
const expanded = ref(options.defaultExpanded)
|
|
51
|
+
const pulseFieldKeys = ref<Set<string>>(new Set())
|
|
52
|
+
let pulseTimer: ReturnType<typeof setTimeout> | null = null
|
|
53
|
+
|
|
54
|
+
const fieldRefs = computed<AimdRecordFieldRef[]>(() => collectAimdRecordFieldRefs(options.fields.value))
|
|
55
|
+
const hasCriteria = computed(() => Boolean(query.value.trim() || fieldKey.value))
|
|
56
|
+
const panelVisible = computed(() => expanded.value || hasCriteria.value)
|
|
57
|
+
const matches = computed(() => searchAimdRecordFields(
|
|
58
|
+
options.record,
|
|
59
|
+
query.value,
|
|
60
|
+
fieldRefs.value,
|
|
61
|
+
{
|
|
62
|
+
fieldKeys: fieldKey.value ? [fieldKey.value] : undefined,
|
|
63
|
+
includeFieldLabels: true,
|
|
64
|
+
},
|
|
65
|
+
))
|
|
66
|
+
const activeMatch = computed(() => {
|
|
67
|
+
if (matches.value.length === 0) {
|
|
68
|
+
return null
|
|
69
|
+
}
|
|
70
|
+
const index = Math.min(Math.max(activeMatchIndex.value, 0), matches.value.length - 1)
|
|
71
|
+
return matches.value[index] ?? null
|
|
72
|
+
})
|
|
73
|
+
const matchedFieldKeys = computed(() => {
|
|
74
|
+
const keys = new Set<string>()
|
|
75
|
+
for (const match of matches.value) {
|
|
76
|
+
for (const key of getMatchFieldKeys(match)) {
|
|
77
|
+
keys.add(key)
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return keys
|
|
81
|
+
})
|
|
82
|
+
const activeFieldKeys = computed(() => {
|
|
83
|
+
const keys = new Set<string>()
|
|
84
|
+
const match = activeMatch.value
|
|
85
|
+
if (match) {
|
|
86
|
+
for (const key of getMatchFieldKeys(match)) {
|
|
87
|
+
keys.add(key)
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return keys
|
|
91
|
+
})
|
|
92
|
+
const resultLabel = computed(() => {
|
|
93
|
+
const total = matches.value.length
|
|
94
|
+
if (!query.value.trim()) {
|
|
95
|
+
return ""
|
|
96
|
+
}
|
|
97
|
+
if (total === 0) {
|
|
98
|
+
return options.messages.value.search.noMatches
|
|
99
|
+
}
|
|
100
|
+
return options.messages.value.search.matchCount(activeMatchIndex.value + 1, total)
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
function getFieldClasses(targetFieldKey: string): string[] {
|
|
104
|
+
if (!query.value.trim()) {
|
|
105
|
+
return []
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const classes: string[] = []
|
|
109
|
+
if (matchedFieldKeys.value.has(targetFieldKey)) {
|
|
110
|
+
classes.push("aimd-field--record-search-match")
|
|
111
|
+
}
|
|
112
|
+
if (activeFieldKeys.value.has(targetFieldKey)) {
|
|
113
|
+
classes.push("aimd-field--record-search-active")
|
|
114
|
+
}
|
|
115
|
+
if (pulseFieldKeys.value.has(targetFieldKey)) {
|
|
116
|
+
classes.push("aimd-field--record-search-pulse")
|
|
117
|
+
}
|
|
118
|
+
return classes
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function findFocusTarget(focusKey: string): HTMLElement | null {
|
|
122
|
+
if (!options.contentRoot.value) {
|
|
123
|
+
return null
|
|
124
|
+
}
|
|
125
|
+
const candidates = options.contentRoot.value.querySelectorAll<HTMLElement>("[data-rec-focus-key]")
|
|
126
|
+
for (let index = 0; index < candidates.length; index += 1) {
|
|
127
|
+
if (candidates[index].dataset.recFocusKey === focusKey) {
|
|
128
|
+
return candidates[index]
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
for (let index = 0; index < candidates.length; index += 1) {
|
|
132
|
+
const candidateKey = candidates[index].dataset.recFocusKey
|
|
133
|
+
if (candidateKey?.startsWith(`${focusKey}:`)) {
|
|
134
|
+
return candidates[index]
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return null
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function selectTextMatch(target: HTMLElement, match: AimdRecordSearchMatch) {
|
|
141
|
+
const control = getTextControl(target)
|
|
142
|
+
if (!control) {
|
|
143
|
+
return
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const needle = query.value.trim()
|
|
147
|
+
if (!needle) {
|
|
148
|
+
return
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const sourceText = control.value || match.text
|
|
152
|
+
const haystack = sourceText.toLocaleLowerCase()
|
|
153
|
+
const start = haystack.indexOf(needle.toLocaleLowerCase())
|
|
154
|
+
if (start < 0) {
|
|
155
|
+
return
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
try {
|
|
159
|
+
control.setSelectionRange(start, start + needle.length)
|
|
160
|
+
}
|
|
161
|
+
catch {
|
|
162
|
+
// Some input types do not support text selection. Focusing the control is still useful.
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function pulseMatch(match: AimdRecordSearchMatch) {
|
|
167
|
+
if (pulseTimer) {
|
|
168
|
+
clearTimeout(pulseTimer)
|
|
169
|
+
pulseTimer = null
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
pulseFieldKeys.value = new Set()
|
|
173
|
+
void nextTick().then(() => {
|
|
174
|
+
pulseFieldKeys.value = new Set(getMatchFieldKeys(match))
|
|
175
|
+
pulseTimer = setTimeout(() => {
|
|
176
|
+
pulseFieldKeys.value = new Set()
|
|
177
|
+
pulseTimer = null
|
|
178
|
+
}, 680)
|
|
179
|
+
})
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
async function focusMatch(index: number) {
|
|
183
|
+
if (matches.value.length === 0) {
|
|
184
|
+
return
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const total = matches.value.length
|
|
188
|
+
activeMatchIndex.value = ((index % total) + total) % total
|
|
189
|
+
await nextTick()
|
|
190
|
+
|
|
191
|
+
const match = matches.value[activeMatchIndex.value]
|
|
192
|
+
if (!match) {
|
|
193
|
+
return
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const target = findFocusTarget(match.field.focusKey)
|
|
197
|
+
pulseMatch(match)
|
|
198
|
+
if (!target) {
|
|
199
|
+
return
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
target.scrollIntoView?.({ block: "center", inline: "nearest", behavior: "smooth" })
|
|
203
|
+
const focusTarget = getFocusableElement(target)
|
|
204
|
+
try {
|
|
205
|
+
focusTarget.focus({ preventScroll: true })
|
|
206
|
+
}
|
|
207
|
+
catch {
|
|
208
|
+
focusTarget.focus()
|
|
209
|
+
}
|
|
210
|
+
selectTextMatch(focusTarget, match)
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
function expand() {
|
|
214
|
+
expanded.value = true
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function collapse() {
|
|
218
|
+
if (hasCriteria.value) {
|
|
219
|
+
return
|
|
220
|
+
}
|
|
221
|
+
expanded.value = false
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
function focusPreviousMatch() {
|
|
225
|
+
void focusMatch(activeMatchIndex.value - 1)
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function focusNextMatch() {
|
|
229
|
+
void focusMatch(activeMatchIndex.value + 1)
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function clear() {
|
|
233
|
+
query.value = ""
|
|
234
|
+
fieldKey.value = ""
|
|
235
|
+
activeMatchIndex.value = 0
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
watch([query, fieldKey], () => {
|
|
239
|
+
activeMatchIndex.value = 0
|
|
240
|
+
options.onVisualStateChange()
|
|
241
|
+
})
|
|
242
|
+
|
|
243
|
+
watch(fieldRefs, (refs) => {
|
|
244
|
+
if (fieldKey.value && !refs.some(ref => ref.key === fieldKey.value)) {
|
|
245
|
+
fieldKey.value = ""
|
|
246
|
+
}
|
|
247
|
+
}, { deep: true })
|
|
248
|
+
|
|
249
|
+
watch(matches, (nextMatches) => {
|
|
250
|
+
if (nextMatches.length === 0) {
|
|
251
|
+
activeMatchIndex.value = 0
|
|
252
|
+
if (query.value.trim()) {
|
|
253
|
+
options.onVisualStateChange()
|
|
254
|
+
}
|
|
255
|
+
return
|
|
256
|
+
}
|
|
257
|
+
if (activeMatchIndex.value >= nextMatches.length) {
|
|
258
|
+
activeMatchIndex.value = nextMatches.length - 1
|
|
259
|
+
}
|
|
260
|
+
if (query.value.trim()) {
|
|
261
|
+
options.onVisualStateChange()
|
|
262
|
+
}
|
|
263
|
+
}, { deep: true })
|
|
264
|
+
|
|
265
|
+
watch(activeMatchIndex, () => {
|
|
266
|
+
if (query.value.trim()) {
|
|
267
|
+
options.onVisualStateChange()
|
|
268
|
+
}
|
|
269
|
+
})
|
|
270
|
+
|
|
271
|
+
watch(pulseFieldKeys, () => {
|
|
272
|
+
if (query.value.trim()) {
|
|
273
|
+
options.onVisualStateChange()
|
|
274
|
+
}
|
|
275
|
+
}, { deep: true })
|
|
276
|
+
|
|
277
|
+
onBeforeUnmount(() => {
|
|
278
|
+
if (pulseTimer) {
|
|
279
|
+
clearTimeout(pulseTimer)
|
|
280
|
+
pulseTimer = null
|
|
281
|
+
}
|
|
282
|
+
})
|
|
283
|
+
|
|
284
|
+
return {
|
|
285
|
+
activeMatchIndex,
|
|
286
|
+
clear,
|
|
287
|
+
collapse,
|
|
288
|
+
expand,
|
|
289
|
+
fieldKey,
|
|
290
|
+
fieldRefs,
|
|
291
|
+
focusNextMatch,
|
|
292
|
+
focusPreviousMatch,
|
|
293
|
+
getFieldClasses,
|
|
294
|
+
matches,
|
|
295
|
+
panelVisible,
|
|
296
|
+
query,
|
|
297
|
+
resultLabel,
|
|
298
|
+
}
|
|
299
|
+
}
|