@airalogy/aimd-recorder 1.21.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.
Files changed (71) hide show
  1. package/README.md +1 -0
  2. package/README.zh-CN.md +1 -0
  3. package/dist/{AimdDnaSequenceField-Cp0cgBYl.js → AimdDnaSequenceField-Bhj28fP8.js} +1 -1
  4. package/dist/{AimdEditor.vue_vue_type_style_index_0_lang-Dj5y1p3U.js → AimdEditor.vue_vue_type_style_index_0_lang-D7c01UqN.js} +26 -2
  5. package/dist/{AimdMarkdownField-Vp72mf5d.js → AimdMarkdownField-GS15pv4z.js} +4 -4
  6. package/dist/{AimdMarkdownNoteField-8AHO9zwW.js → AimdMarkdownNoteField-H9WP8tR6.js} +3 -3
  7. package/dist/aimd-recorder.css +1 -1
  8. package/dist/{arc-YTgUVhxi.js → arc-B50G9-kH.js} +1 -1
  9. package/dist/{architectureDiagram-3BPJPVTR-BFddgj3h.js → architectureDiagram-3BPJPVTR-D9mBEbpY.js} +2 -2
  10. package/dist/{blockDiagram-GPEHLZMM-BNFU64lo.js → blockDiagram-GPEHLZMM-Cs4swgto.js} +4 -4
  11. package/dist/{c4Diagram-AAUBKEIU-DDg-ymRq.js → c4Diagram-AAUBKEIU-C12HKS3r.js} +2 -2
  12. package/dist/{channel-Cswcnlp1.js → channel-D69VnjVz.js} +1 -1
  13. package/dist/{chunk-2J33WTMH-CP2V6jff.js → chunk-2J33WTMH-oc-89G5c.js} +1 -1
  14. package/dist/{chunk-4BX2VUAB-CbWr2vv6.js → chunk-4BX2VUAB-BDJS9G3r.js} +1 -1
  15. package/dist/{chunk-55IACEB6-DQOKhaUL.js → chunk-55IACEB6-BPl3uHcA.js} +1 -1
  16. package/dist/{chunk-727SXJPM-4VuCu0m8.js → chunk-727SXJPM-pWe-vDGf.js} +5 -5
  17. package/dist/{chunk-AQP2D5EJ-D7Pq-oug.js → chunk-AQP2D5EJ-D-R5sIr1.js} +3 -3
  18. package/dist/{chunk-FMBD7UC4-slF0wbDn.js → chunk-FMBD7UC4-bo6Qyom1.js} +1 -1
  19. package/dist/{chunk-ND2GUHAM-BrNrmeyL.js → chunk-ND2GUHAM-DQMvtYV7.js} +1 -1
  20. package/dist/{chunk-QZHKN3VN-CII3oQmH.js → chunk-QZHKN3VN-DlCn3HON.js} +1 -1
  21. package/dist/{classDiagram-v2-Q7XG4LA2-skT5SNaU.js → classDiagram-4FO5ZUOK-DzUwWFwr.js} +2 -2
  22. package/dist/{classDiagram-4FO5ZUOK-skT5SNaU.js → classDiagram-v2-Q7XG4LA2-DzUwWFwr.js} +2 -2
  23. package/dist/components.js +3669 -3168
  24. package/dist/composables.js +2 -2
  25. package/dist/{cose-bilkent-S5V4N54A-CiwUUHaz.js → cose-bilkent-S5V4N54A-BXLMzfpO.js} +1 -1
  26. package/dist/{dagre-BM42HDAG-BzaKejHz.js → dagre-BM42HDAG-DHnofIh9.js} +3 -3
  27. package/dist/{diagram-2AECGRRQ-B7jPt7Sf.js → diagram-2AECGRRQ-BqTTVPsm.js} +2 -2
  28. package/dist/{diagram-5GNKFQAL-z6ygEwZY.js → diagram-5GNKFQAL-D5p1UVbw.js} +3 -3
  29. package/dist/{diagram-KO2AKTUF-BBQMMIgY.js → diagram-KO2AKTUF-Uuoz9cFn.js} +2 -2
  30. package/dist/{diagram-LMA3HP47-IFDVFs2m.js → diagram-LMA3HP47-W001U31X.js} +2 -2
  31. package/dist/{diagram-OG6HWLK6-DjEAxof0.js → diagram-OG6HWLK6-DL516LDr.js} +3 -3
  32. package/dist/{erDiagram-TEJ5UH35-DxMYC2Iw.js → erDiagram-TEJ5UH35-CCxgMb67.js} +4 -4
  33. package/dist/{flowDiagram-I6XJVG4X-EIHEHG32.js → flowDiagram-I6XJVG4X-nXGdmC0O.js} +6 -6
  34. package/dist/{ganttDiagram-6RSMTGT7-TEOWSxVA.js → ganttDiagram-6RSMTGT7-Bi9Ro7_Z.js} +2 -2
  35. package/dist/{gitGraphDiagram-PVQCEYII-Cwzy4bEc.js → gitGraphDiagram-PVQCEYII-w1kNAy4E.js} +3 -3
  36. package/dist/{graph-Cyx6ry93.js → graph-CpOkL_eZ.js} +1 -1
  37. package/dist/{index-Dtvv88SS.js → index-Dkrf2LJl.js} +51 -51
  38. package/dist/index.js +3 -3
  39. package/dist/{infoDiagram-5YYISTIA-DNv6Z1ol.js → infoDiagram-5YYISTIA-Bde_w9T1.js} +1 -1
  40. package/dist/{ishikawaDiagram-YF4QCWOH-D3eaxgy9.js → ishikawaDiagram-YF4QCWOH-x5M1KR0l.js} +1 -1
  41. package/dist/{journeyDiagram-JHISSGLW-D5g7q2RP.js → journeyDiagram-JHISSGLW-CIDQP8Zm.js} +4 -4
  42. package/dist/{kanban-definition-UN3LZRKU-C0hUSCKH.js → kanban-definition-UN3LZRKU-CKgO7sG8.js} +2 -2
  43. package/dist/{layout-CpB8OqeJ.js → layout-BZYprqYR.js} +2 -2
  44. package/dist/{linear-D55SCqYq.js → linear-ClSH2F_v.js} +1 -1
  45. package/dist/{mermaid.core-wqUqC7-u.js → mermaid.core-CcRV6K2R.js} +34 -34
  46. package/dist/{mindmap-definition-RKZ34NQL-tCWbcVMf.js → mindmap-definition-RKZ34NQL-s3h6uszV.js} +3 -3
  47. package/dist/{pieDiagram-4H26LBE5-JtTllP1a.js → pieDiagram-4H26LBE5-CgiazyWv.js} +3 -3
  48. package/dist/{quadrantDiagram-W4KKPZXB-CLL79FuD.js → quadrantDiagram-W4KKPZXB-DCPVgHoW.js} +2 -2
  49. package/dist/record.js +19 -19
  50. package/dist/{requirementDiagram-4Y6WPE33-3BVAevi9.js → requirementDiagram-4Y6WPE33-DE6F9oSB.js} +3 -3
  51. package/dist/{sankeyDiagram-5OEKKPKP-BfUuX3gj.js → sankeyDiagram-5OEKKPKP-DZZoFFr-.js} +1 -1
  52. package/dist/{sequenceDiagram-3UESZ5HK-vTd4YJPb.js → sequenceDiagram-3UESZ5HK-DaYEOl60.js} +3 -3
  53. package/dist/{stateDiagram-AJRCARHV-BzlMdp-U.js → stateDiagram-AJRCARHV-BmgpHJlH.js} +4 -4
  54. package/dist/{stateDiagram-v2-BHNVJYJU-Ciwlhuza.js → stateDiagram-v2-BHNVJYJU-D49CHQD6.js} +2 -2
  55. package/dist/{timeline-definition-PNZ67QCA-CySiSuYS.js → timeline-definition-PNZ67QCA-DdVLoCkC.js} +2 -2
  56. package/dist/{useCodeBlockRendering-DtcAJyK9.js → useCodeBlockRendering-CCuoP52e.js} +2 -2
  57. package/dist/{vennDiagram-CIIHVFJN-Bbf0BSAq.js → vennDiagram-CIIHVFJN-CCcMKcd7.js} +1 -1
  58. package/dist/{wardleyDiagram-YWT4CUSO-J0jnd8EV.js → wardleyDiagram-YWT4CUSO-R4UGgGWY.js} +2 -2
  59. package/dist/{xychartDiagram-2RQKCTM6-XCPLxT4O.js → xychartDiagram-2RQKCTM6-DyFhCubk.js} +2 -2
  60. package/package.json +4 -4
  61. package/src/__tests__/record-search-render.test.ts +108 -0
  62. package/src/__tests__/var-field-render.test.ts +62 -60
  63. package/src/components/AimdQuizRecorder.vue +3 -1
  64. package/src/components/AimdRecorder.vue +51 -2343
  65. package/src/components/AimdRecorderSearchToolbar.vue +258 -0
  66. package/src/components/AimdVarTableField.vue +2 -1
  67. package/src/components/index.ts +1 -0
  68. package/src/composables/useRecordSearch.ts +299 -0
  69. package/src/locales.ts +36 -0
  70. package/src/styles/recorder-surface.css +2374 -0
  71. package/src/styles/recorder.css +1 -0
@@ -0,0 +1,258 @@
1
+ <script setup lang="ts">
2
+ import { nextTick, ref, watch } from "vue"
3
+ import type { AimdRecordFieldRef } from "@airalogy/aimd-core/utils"
4
+ import type { AimdRecorderMessages } from "../locales"
5
+
6
+ const props = defineProps<{
7
+ fieldKey: string
8
+ fieldRefs: AimdRecordFieldRef[]
9
+ matchCount: number
10
+ messages: AimdRecorderMessages
11
+ panelVisible: boolean
12
+ query: string
13
+ resultLabel: string
14
+ }>()
15
+
16
+ const emit = defineEmits<{
17
+ (event: "clear"): void
18
+ (event: "collapse"): void
19
+ (event: "expand"): void
20
+ (event: "next"): void
21
+ (event: "previous"): void
22
+ (event: "update:fieldKey", value: string): void
23
+ (event: "update:query", value: string): void
24
+ }>()
25
+
26
+ const searchInputRef = ref<HTMLInputElement | null>(null)
27
+
28
+ watch(
29
+ () => props.panelVisible,
30
+ async (panelVisible) => {
31
+ if (!panelVisible) {
32
+ return
33
+ }
34
+ await nextTick()
35
+ searchInputRef.value?.focus()
36
+ },
37
+ )
38
+ </script>
39
+
40
+ <template>
41
+ <div
42
+ class="aimd-protocol-recorder__search-shell"
43
+ :class="{ 'aimd-protocol-recorder__search-shell--expanded': panelVisible }"
44
+ >
45
+ <button
46
+ v-if="!panelVisible"
47
+ type="button"
48
+ class="aimd-protocol-recorder__search-toggle"
49
+ data-rec-search-toggle
50
+ :aria-label="messages.search.label"
51
+ @click="emit('expand')"
52
+ >
53
+ {{ messages.search.label }}
54
+ </button>
55
+ <div v-else class="aimd-protocol-recorder__search">
56
+ <select
57
+ class="aimd-protocol-recorder__search-field"
58
+ :aria-label="messages.search.fieldLabel"
59
+ :value="fieldKey"
60
+ @change="emit('update:fieldKey', ($event.target as HTMLSelectElement).value)"
61
+ >
62
+ <option value="">{{ messages.search.allFields }}</option>
63
+ <option
64
+ v-for="field in fieldRefs"
65
+ :key="field.key"
66
+ :value="field.key"
67
+ >
68
+ {{ field.label }}
69
+ </option>
70
+ </select>
71
+ <input
72
+ ref="searchInputRef"
73
+ class="aimd-protocol-recorder__search-input"
74
+ type="search"
75
+ :value="query"
76
+ :placeholder="messages.search.placeholder"
77
+ :aria-label="messages.search.label"
78
+ @input="emit('update:query', ($event.target as HTMLInputElement).value)"
79
+ @keydown.enter.prevent="emit('next')"
80
+ >
81
+ <span v-if="resultLabel" class="aimd-protocol-recorder__search-count">
82
+ {{ resultLabel }}
83
+ </span>
84
+ <button
85
+ type="button"
86
+ class="aimd-protocol-recorder__search-button"
87
+ :disabled="matchCount === 0"
88
+ :aria-label="messages.search.previous"
89
+ :title="messages.search.previous"
90
+ @click="emit('previous')"
91
+ >
92
+ &lt;
93
+ </button>
94
+ <button
95
+ type="button"
96
+ class="aimd-protocol-recorder__search-button"
97
+ :disabled="matchCount === 0"
98
+ :aria-label="messages.search.next"
99
+ :title="messages.search.next"
100
+ @click="emit('next')"
101
+ >
102
+ &gt;
103
+ </button>
104
+ <button
105
+ v-if="query || fieldKey"
106
+ type="button"
107
+ class="aimd-protocol-recorder__search-button aimd-protocol-recorder__search-button--clear"
108
+ :aria-label="messages.search.clear"
109
+ :title="messages.search.clear"
110
+ @click="emit('clear')"
111
+ >
112
+ x
113
+ </button>
114
+ <button
115
+ v-else
116
+ type="button"
117
+ class="aimd-protocol-recorder__search-button aimd-protocol-recorder__search-button--collapse"
118
+ data-rec-search-collapse
119
+ :aria-label="messages.search.collapse"
120
+ :title="messages.search.collapse"
121
+ @click="emit('collapse')"
122
+ >
123
+ {{ messages.search.collapse }}
124
+ </button>
125
+ </div>
126
+ </div>
127
+ </template>
128
+
129
+ <style scoped>
130
+ .aimd-protocol-recorder__search-shell {
131
+ position: sticky;
132
+ top: var(--aimd-recorder-search-sticky-top, 0px);
133
+ z-index: 30;
134
+ display: flex;
135
+ justify-content: flex-end;
136
+ box-sizing: border-box;
137
+ margin-inline: calc(-1 * var(--aimd-recorder-gutter-x));
138
+ margin-bottom: 0;
139
+ padding: 0 var(--aimd-recorder-gutter-x);
140
+ background: transparent;
141
+ pointer-events: none;
142
+ }
143
+
144
+ .aimd-protocol-recorder__search-shell--expanded {
145
+ justify-content: stretch;
146
+ margin-bottom: 8px;
147
+ padding-block: 0;
148
+ padding-inline: var(--aimd-recorder-gutter-x);
149
+ border: 1px solid #d8e4f2;
150
+ border-radius: 0 0 10px 10px;
151
+ background: #f8fbff;
152
+ backdrop-filter: blur(4px);
153
+ box-shadow: 0 1px 0 rgba(23, 45, 77, 0.06);
154
+ pointer-events: auto;
155
+ }
156
+
157
+ .aimd-protocol-recorder__search {
158
+ display: flex;
159
+ flex: 1 1 auto;
160
+ flex-wrap: wrap;
161
+ align-items: center;
162
+ gap: 8px;
163
+ padding: 8px;
164
+ border: 0;
165
+ border-radius: 0;
166
+ background: transparent;
167
+ box-shadow: none;
168
+ pointer-events: auto;
169
+ }
170
+
171
+ .aimd-protocol-recorder__search-toggle {
172
+ display: inline-flex;
173
+ align-items: center;
174
+ justify-content: center;
175
+ min-height: 32px;
176
+ padding: 0 12px;
177
+ border: 1px solid #c8d4e3;
178
+ border-radius: 8px;
179
+ background: #fff;
180
+ color: #0b63c7;
181
+ font: inherit;
182
+ font-weight: 700;
183
+ cursor: pointer;
184
+ box-shadow: 0 2px 8px rgba(23, 45, 77, 0.06);
185
+ pointer-events: auto;
186
+ }
187
+
188
+ .aimd-protocol-recorder__search-field,
189
+ .aimd-protocol-recorder__search-input {
190
+ min-height: 32px;
191
+ border: 1px solid #c8d4e3;
192
+ border-radius: 8px;
193
+ background: #fff;
194
+ color: var(--rec-text);
195
+ font: inherit;
196
+ }
197
+
198
+ .aimd-protocol-recorder__search-field {
199
+ max-width: min(240px, 100%);
200
+ padding: 0 28px 0 10px;
201
+ }
202
+
203
+ .aimd-protocol-recorder__search-input {
204
+ flex: 1 1 240px;
205
+ min-width: min(220px, 100%);
206
+ padding: 0 10px;
207
+ }
208
+
209
+ .aimd-protocol-recorder__search-field:focus,
210
+ .aimd-protocol-recorder__search-input:focus,
211
+ .aimd-protocol-recorder__search-toggle:focus,
212
+ .aimd-protocol-recorder__search-button:focus {
213
+ outline: 2px solid color-mix(in srgb, var(--rec-focus) 26%, transparent);
214
+ outline-offset: 1px;
215
+ border-color: #75b7ff;
216
+ }
217
+
218
+ .aimd-protocol-recorder__search-count {
219
+ min-width: 72px;
220
+ color: var(--rec-muted);
221
+ font-size: 12px;
222
+ font-weight: 600;
223
+ text-align: center;
224
+ }
225
+
226
+ .aimd-protocol-recorder__search-button {
227
+ display: inline-flex;
228
+ align-items: center;
229
+ justify-content: center;
230
+ width: 32px;
231
+ height: 32px;
232
+ border: 1px solid #c8d4e3;
233
+ border-radius: 8px;
234
+ background: #fff;
235
+ color: #0b63c7;
236
+ font: inherit;
237
+ font-weight: 700;
238
+ cursor: pointer;
239
+ }
240
+
241
+ .aimd-protocol-recorder__search-button:disabled {
242
+ color: #98a2b3;
243
+ cursor: default;
244
+ opacity: 0.65;
245
+ }
246
+
247
+ .aimd-protocol-recorder__search-button--clear {
248
+ color: #475467;
249
+ }
250
+
251
+ .aimd-protocol-recorder__search-button--collapse {
252
+ width: auto;
253
+ min-width: 48px;
254
+ padding: 0 10px;
255
+ color: #475467;
256
+ font-size: 12px;
257
+ }
258
+ </style>
@@ -143,6 +143,7 @@ export default defineComponent({
143
143
  columns: { type: Array as PropType<string[]>, required: true },
144
144
  disabled: { type: Boolean, default: false },
145
145
  readonly: { type: Boolean, default: false },
146
+ extraClasses: { type: Array as PropType<string[]>, default: () => [] },
146
147
  settlingRowKey: { type: String as PropType<string | null>, default: null },
147
148
  messages: { type: Object as PropType<AimdRecorderMessages>, required: true },
148
149
  fieldMeta: { type: Object as PropType<Record<string, AimdFieldMeta> | undefined>, default: undefined },
@@ -534,7 +535,7 @@ export default defineComponent({
534
535
 
535
536
  return h("div", {
536
537
  ref: wrapperRef,
537
- class: "aimd-field aimd-field--var-table aimd-rec-inline-table",
538
+ class: ["aimd-field aimd-field--var-table aimd-rec-inline-table", ...props.extraClasses],
538
539
  "data-aimd-table-name": tableName,
539
540
  "data-aimd-table-layout": layoutReady.value && isOverflow.value ? "cards" : "table",
540
541
  }, [
@@ -6,6 +6,7 @@
6
6
  */
7
7
 
8
8
  import { defineAsyncComponent } from "vue"
9
+ import "../styles/recorder.css"
9
10
  import AimdAssignerGraph from "./AimdAssignerGraph.vue"
10
11
  import AimdRecorder from "./AimdRecorder.vue"
11
12
  import AimdRecorderEditor from "./AimdRecorderEditor.vue"
@@ -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
+ }
package/src/locales.ts CHANGED
@@ -112,6 +112,18 @@ export interface AimdRecorderMessages {
112
112
  true: string
113
113
  false: string
114
114
  }
115
+ search: {
116
+ label: string
117
+ fieldLabel: string
118
+ placeholder: string
119
+ allFields: string
120
+ previous: string
121
+ next: string
122
+ clear: string
123
+ collapse: string
124
+ noMatches: string
125
+ matchCount: (current: number, total: number) => string
126
+ }
115
127
  dna: {
116
128
  editMode: string
117
129
  interactiveMode: string
@@ -314,6 +326,18 @@ const EN_US_MESSAGES: AimdRecorderMessages = {
314
326
  true: "True",
315
327
  false: "False",
316
328
  },
329
+ search: {
330
+ label: "Search record",
331
+ fieldLabel: "Search field",
332
+ placeholder: "Search this record",
333
+ allFields: "All fields",
334
+ previous: "Previous match",
335
+ next: "Next match",
336
+ clear: "Clear search",
337
+ collapse: "Hide",
338
+ noMatches: "No matches",
339
+ matchCount: (current, total) => `${current} / ${total}`,
340
+ },
317
341
  dna: {
318
342
  editMode: "Edit mode",
319
343
  interactiveMode: "Interactive",
@@ -489,6 +513,18 @@ const ZH_CN_MESSAGES: AimdRecorderMessages = {
489
513
  true: "是",
490
514
  false: "否",
491
515
  },
516
+ search: {
517
+ label: "搜索记录",
518
+ fieldLabel: "搜索字段",
519
+ placeholder: "搜索当前记录",
520
+ allFields: "全部字段",
521
+ previous: "上一个匹配",
522
+ next: "下一个匹配",
523
+ clear: "清除搜索",
524
+ collapse: "收起",
525
+ noMatches: "无匹配",
526
+ matchCount: (current, total) => `${current} / ${total}`,
527
+ },
492
528
  dna: {
493
529
  editMode: "编辑模式",
494
530
  interactiveMode: "交互式",