@xleddyl/443-components-vue 0.16.89 → 0.16.91
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/CATALOG.md +20 -19
- package/README.md +35 -5
- package/dist/components/core/Input.vue +1 -1
- package/dist/components/core/Input.vue.d.ts +1 -0
- package/dist/components/core/Textarea.vue +1 -1
- package/dist/components/core/Textarea.vue.d.ts +1 -0
- package/dist/components/data/Tree.vue +10 -18
- package/dist/components/data/Tree.vue.d.ts +2 -0
- package/dist/components/forms/Checkbox.vue +1 -1
- package/dist/components/forms/CheckboxGroup.vue +1 -1
- package/dist/components/forms/ColorInput.vue +1 -1
- package/dist/components/forms/ColorInput.vue.d.ts +1 -0
- package/dist/components/forms/Combobox.vue +1 -1
- package/dist/components/forms/DateInput.vue +1 -1
- package/dist/components/forms/DateInput.vue.d.ts +1 -0
- package/dist/components/forms/DatePicker.vue +1 -1
- package/dist/components/forms/DatePicker.vue.d.ts +1 -0
- package/dist/components/forms/FileInput.vue +1 -1
- package/dist/components/forms/FileInput.vue.d.ts +1 -0
- package/dist/components/forms/NumberInput.vue +1 -1
- package/dist/components/forms/NumberInput.vue.d.ts +1 -0
- package/dist/components/forms/PaletteSelect.vue +1 -1
- package/dist/components/forms/PaletteSelect.vue.d.ts +1 -0
- package/dist/components/forms/PasswordInput.vue +1 -1
- package/dist/components/forms/PasswordInput.vue.d.ts +1 -0
- package/dist/components/forms/PinInput.vue +1 -1
- package/dist/components/forms/PinInput.vue.d.ts +1 -0
- package/dist/components/forms/RadioGroup.vue +1 -1
- package/dist/components/forms/SegmentedControl.vue +1 -1
- package/dist/components/forms/Select.vue +1 -1
- package/dist/components/forms/Slider.vue +1 -1
- package/dist/components/forms/Slider.vue.d.ts +1 -0
- package/dist/components/forms/Switch.vue +1 -1
- package/dist/components/forms/Switch.vue.d.ts +1 -0
- package/dist/components/forms/TimeInput.vue +1 -1
- package/dist/components/forms/TimeInput.vue.d.ts +1 -0
- package/dist/components/forms/TreeSelect.vue +1 -1
- package/dist/components/forms/TreeSelect.vue.d.ts +1 -0
- package/dist/components/overlays/CommandList.vue +423 -0
- package/dist/components/overlays/CommandList.vue.d.ts +255 -0
- package/dist/components/overlays/CommandPalette.vue +48 -315
- package/dist/components/overlays/CommandPalette.vue.d.ts +2 -1
- package/dist/components/overlays/Popover.vue +24 -5
- package/dist/components/overlays/Popover.vue.d.ts +4 -1
- package/dist/components/overlays/index.d.ts +1 -0
- package/dist/components/overlays/index.mjs +1 -0
- package/dist/components/overlays/types.d.ts +1 -0
- package/dist/composables/useField.mjs +1 -1
- package/dist/editor/RichTextEditor.vue +1 -1
- package/dist/editor/RichTextEditor.vue.d.ts +1 -0
- package/dist/editor/TemplateEditor.vue +1 -1
- package/dist/editor/TemplateEditor.vue.d.ts +1 -0
- package/dist/internal/core/DivElement.d.ts +2 -0
- package/dist/internal/core/DivElement.mjs +8 -0
- package/dist/internal/floating/layer.d.ts +1 -0
- package/dist/internal/floating/layer.mjs +56 -7
- package/dist/internal/floating/position.d.ts +2 -0
- package/dist/internal/floating/position.mjs +25 -0
- package/dist/internal/overlays/HintTooltip.vue +10 -2
- package/dist/internal/overlays/HintTooltip.vue.d.ts +2 -0
- package/dist/styles/data/tree.css +29 -5
- package/dist/styles/overlays/command.css +22 -0
- package/dist/styles/overlays/floating.css +1 -0
- package/package.json +1 -1
|
@@ -81,7 +81,7 @@ const props = defineProps({
|
|
|
81
81
|
block: { type: Boolean, required: false },
|
|
82
82
|
iconOnly: { type: Boolean, required: false },
|
|
83
83
|
invalid: { type: Boolean, required: false, default: void 0 },
|
|
84
|
-
disabled: { type: Boolean, required: false },
|
|
84
|
+
disabled: { type: Boolean, required: false, default: void 0 },
|
|
85
85
|
readonly: { type: Boolean, required: false },
|
|
86
86
|
required: { type: null, required: false }
|
|
87
87
|
});
|
|
@@ -79,7 +79,7 @@ const props = defineProps({
|
|
|
79
79
|
size: { type: String, required: false, default: "md" },
|
|
80
80
|
icon: { type: null, required: false },
|
|
81
81
|
invalid: { type: Boolean, required: false, default: void 0 },
|
|
82
|
-
disabled: { type: Boolean, required: false },
|
|
82
|
+
disabled: { type: Boolean, required: false, default: void 0 },
|
|
83
83
|
required: { type: Boolean, required: false },
|
|
84
84
|
class: { type: null, required: false },
|
|
85
85
|
style: { type: null, required: false }
|
|
@@ -69,7 +69,7 @@ const props = defineProps({
|
|
|
69
69
|
format: { type: Function, required: false, default: (value) => String(value) },
|
|
70
70
|
size: { type: String, required: false, default: "md" },
|
|
71
71
|
invalid: { type: Boolean, required: false, default: void 0 },
|
|
72
|
-
disabled: { type: Boolean, required: false },
|
|
72
|
+
disabled: { type: Boolean, required: false, default: void 0 },
|
|
73
73
|
readonly: { type: Boolean, required: false },
|
|
74
74
|
class: { type: null, required: false },
|
|
75
75
|
style: { type: null, required: false }
|
|
@@ -70,7 +70,7 @@ const props = defineProps({
|
|
|
70
70
|
uncheckedIcon: { type: null, required: false },
|
|
71
71
|
nativeValue: { type: String, required: false, default: "on" },
|
|
72
72
|
invalid: { type: Boolean, required: false, default: void 0 },
|
|
73
|
-
disabled: { type: Boolean, required: false },
|
|
73
|
+
disabled: { type: Boolean, required: false, default: void 0 },
|
|
74
74
|
readonly: { type: Boolean, required: false },
|
|
75
75
|
required: { type: Boolean, required: false },
|
|
76
76
|
class: { type: null, required: false },
|
|
@@ -450,6 +450,7 @@ declare const __VLS_base: import("vue").DefineComponent<{
|
|
|
450
450
|
}>, {
|
|
451
451
|
size: FieldSize;
|
|
452
452
|
invalid: boolean;
|
|
453
|
+
disabled: boolean;
|
|
453
454
|
labelPosition: "start" | "end";
|
|
454
455
|
nativeValue: string;
|
|
455
456
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
@@ -27,7 +27,7 @@ const props = defineProps({
|
|
|
27
27
|
seconds: { type: Boolean, required: false },
|
|
28
28
|
clearable: { type: Boolean, required: false },
|
|
29
29
|
invalid: { type: Boolean, required: false, default: void 0 },
|
|
30
|
-
disabled: { type: Boolean, required: false },
|
|
30
|
+
disabled: { type: Boolean, required: false, default: void 0 },
|
|
31
31
|
readonly: { type: Boolean, required: false },
|
|
32
32
|
required: { type: Boolean, required: false }
|
|
33
33
|
});
|
|
@@ -498,6 +498,7 @@ declare const __VLS_export: import("vue").DefineComponent<{
|
|
|
498
498
|
}>, {
|
|
499
499
|
size: FieldSize;
|
|
500
500
|
invalid: boolean;
|
|
501
|
+
disabled: boolean;
|
|
501
502
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
502
503
|
declare const _default: typeof __VLS_export;
|
|
503
504
|
export default _default;
|
|
@@ -223,7 +223,7 @@ const props = defineProps({
|
|
|
223
223
|
listLabel: { type: String, required: false },
|
|
224
224
|
resultsText: { type: Function, required: false },
|
|
225
225
|
invalid: { type: Boolean, required: false, default: void 0 },
|
|
226
|
-
disabled: { type: Boolean, required: false },
|
|
226
|
+
disabled: { type: Boolean, required: false, default: void 0 },
|
|
227
227
|
readonly: { type: Boolean, required: false },
|
|
228
228
|
required: { type: Boolean, required: false },
|
|
229
229
|
class: { type: null, required: false },
|
|
@@ -476,6 +476,7 @@ declare const __VLS_base: import("vue").DefineComponent<{
|
|
|
476
476
|
size: FieldSize;
|
|
477
477
|
invalid: boolean;
|
|
478
478
|
separator: string;
|
|
479
|
+
disabled: boolean;
|
|
479
480
|
nodes: TreeNode[];
|
|
480
481
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
481
482
|
declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
|
|
@@ -0,0 +1,423 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<DivElement v-bind="$attrs" class="k-command-list">
|
|
3
|
+
<div class="k-command-bar">
|
|
4
|
+
<label :id="labelId" :for="inputId" class="k-visually-hidden">{{ labelText }}</label>
|
|
5
|
+
<Icon name="magnifying-glass" class="k-command-bar-icon" />
|
|
6
|
+
<input
|
|
7
|
+
:id="inputId"
|
|
8
|
+
ref="inputRef"
|
|
9
|
+
v-model="query"
|
|
10
|
+
:autofocus="autofocus"
|
|
11
|
+
type="text"
|
|
12
|
+
role="combobox"
|
|
13
|
+
class="k-command-input"
|
|
14
|
+
:placeholder="placeholderText"
|
|
15
|
+
autocomplete="off"
|
|
16
|
+
autocapitalize="off"
|
|
17
|
+
spellcheck="false"
|
|
18
|
+
aria-autocomplete="list"
|
|
19
|
+
:aria-controls="listId"
|
|
20
|
+
:aria-expanded="flat.length > 0 ? 'true' : 'false'"
|
|
21
|
+
:aria-activedescendant="activeId"
|
|
22
|
+
@keydown="onKeydown"
|
|
23
|
+
/>
|
|
24
|
+
<Spinner v-if="busy" size="xs" decorative />
|
|
25
|
+
<span aria-hidden="true"><Kbd size="sm">Esc</Kbd></span>
|
|
26
|
+
</div>
|
|
27
|
+
<div ref="bodyRef" class="k-command-body">
|
|
28
|
+
<div
|
|
29
|
+
v-show="flat.length"
|
|
30
|
+
:id="listId"
|
|
31
|
+
role="listbox"
|
|
32
|
+
:aria-labelledby="labelId"
|
|
33
|
+
class="k-command-results"
|
|
34
|
+
>
|
|
35
|
+
<div
|
|
36
|
+
v-for="(group, groupIndex) in rendered"
|
|
37
|
+
:key="group.key"
|
|
38
|
+
role="group"
|
|
39
|
+
:aria-labelledby="hasLabel(group) ? `${listId}-group-${groupIndex}` : void 0"
|
|
40
|
+
class="k-command-group"
|
|
41
|
+
:class="{ 'is-pinned': group.pinned }"
|
|
42
|
+
>
|
|
43
|
+
<div
|
|
44
|
+
v-if="hasLabel(group)"
|
|
45
|
+
:id="`${listId}-group-${groupIndex}`"
|
|
46
|
+
class="k-command-group-label"
|
|
47
|
+
>
|
|
48
|
+
<slot
|
|
49
|
+
name="group-label"
|
|
50
|
+
:group="group.source"
|
|
51
|
+
:label="group.label"
|
|
52
|
+
:description="group.description"
|
|
53
|
+
:recent="group.recent"
|
|
54
|
+
>
|
|
55
|
+
<span class="k-command-group-title">{{ group.label }}</span>
|
|
56
|
+
<span v-if="group.description" class="k-command-group-description">
|
|
57
|
+
{{ group.description }}
|
|
58
|
+
</span>
|
|
59
|
+
</slot>
|
|
60
|
+
</div>
|
|
61
|
+
<div
|
|
62
|
+
v-for="entry in group.items"
|
|
63
|
+
:id="optionId(entry.index)"
|
|
64
|
+
:key="entry.key"
|
|
65
|
+
role="option"
|
|
66
|
+
class="k-command-option"
|
|
67
|
+
:class="{ 'is-active': entry.index === active }"
|
|
68
|
+
:aria-selected="entry.index === active ? 'true' : 'false'"
|
|
69
|
+
:aria-disabled="entry.item.disabled ? 'true' : void 0"
|
|
70
|
+
:aria-describedby="reasonOf(entry.item) ? reasonId(entry.index) : void 0"
|
|
71
|
+
@pointermove="onOptionPointerMove(entry.index)"
|
|
72
|
+
@click="select(entry)"
|
|
73
|
+
>
|
|
74
|
+
<slot name="item" :item="entry.item" :active="entry.index === active">
|
|
75
|
+
<Icon
|
|
76
|
+
:name="
|
|
77
|
+
entry.item.icon ?? group.icon ?? (group.recent ? 'arrow-path' : group.pinned ? 'plus' : 'arrow-right')
|
|
78
|
+
"
|
|
79
|
+
class="k-command-option-icon"
|
|
80
|
+
/>
|
|
81
|
+
<span class="k-command-option-text">
|
|
82
|
+
<span class="k-command-option-label">{{ entry.item.label }}</span>
|
|
83
|
+
<span v-if="entry.item.description" class="k-command-option-description">
|
|
84
|
+
{{ entry.item.description }}
|
|
85
|
+
</span>
|
|
86
|
+
</span>
|
|
87
|
+
<Badge
|
|
88
|
+
v-if="entry.item.badge"
|
|
89
|
+
v-bind="badgeProps(entry.item.badge)"
|
|
90
|
+
size="sm"
|
|
91
|
+
class="k-command-option-badge"
|
|
92
|
+
/>
|
|
93
|
+
<span
|
|
94
|
+
v-if="entry.item.shortcut"
|
|
95
|
+
class="k-command-option-shortcut"
|
|
96
|
+
aria-hidden="true"
|
|
97
|
+
>
|
|
98
|
+
<Kbd
|
|
99
|
+
v-for="(key, keyIndex) in formatHotkey(entry.item.shortcut, apple)"
|
|
100
|
+
:key="keyIndex"
|
|
101
|
+
size="sm"
|
|
102
|
+
>
|
|
103
|
+
{{ key }}
|
|
104
|
+
</Kbd>
|
|
105
|
+
</span>
|
|
106
|
+
</slot>
|
|
107
|
+
<HintTooltip
|
|
108
|
+
v-if="reasonOf(entry.item)"
|
|
109
|
+
:id="reasonId(entry.index)"
|
|
110
|
+
:text="reasonOf(entry.item)"
|
|
111
|
+
:active="keyboardActive && entry.index === active"
|
|
112
|
+
placement="right"
|
|
113
|
+
/>
|
|
114
|
+
</div>
|
|
115
|
+
</div>
|
|
116
|
+
</div>
|
|
117
|
+
<p v-if="hint" class="k-command-hint">
|
|
118
|
+
<slot name="empty" :query="query">{{ hint }}</slot>
|
|
119
|
+
</p>
|
|
120
|
+
<div v-if="resultCount && (notice || $slots['after-results'])" class="k-command-notice">
|
|
121
|
+
<slot name="after-results" :query="query" :count="resultCount">{{ notice }}</slot>
|
|
122
|
+
</div>
|
|
123
|
+
</div>
|
|
124
|
+
<div v-if="footer" class="k-command-footer" aria-hidden="true">
|
|
125
|
+
<span><Kbd size="sm">↑</Kbd><Kbd size="sm">↓</Kbd> {{ moveText }}</span>
|
|
126
|
+
<span><Kbd size="sm">↵</Kbd> {{ selectText }}</span>
|
|
127
|
+
<span><Kbd size="sm">Esc</Kbd> {{ closeText }}</span>
|
|
128
|
+
</div>
|
|
129
|
+
<LiveRegion :message="status" />
|
|
130
|
+
</DivElement>
|
|
131
|
+
</template>
|
|
132
|
+
|
|
133
|
+
<script setup>
|
|
134
|
+
import { computed, nextTick, onMounted, ref, shallowRef, useId, useTemplateRef, watch } from "vue";
|
|
135
|
+
import { formatHotkey } from "../../composables/useHotkey";
|
|
136
|
+
import { useApplePlatform } from "../../internal/core/env";
|
|
137
|
+
import { useLocale } from "../../composables/useLocale";
|
|
138
|
+
import { nextEnabledIndex } from "../../internal/core/roving";
|
|
139
|
+
import { useAsyncSearch } from "../../internal/core/search";
|
|
140
|
+
import { matchesSearch } from "../../internal/core/text";
|
|
141
|
+
import { readStorageJson, writeStorageJson } from "../../internal/core/storage";
|
|
142
|
+
import { useRouterLike } from "../../internal/layout/route";
|
|
143
|
+
import { DivElement } from "../../internal/core/DivElement";
|
|
144
|
+
import LiveRegion from "../../internal/core/LiveRegion.vue";
|
|
145
|
+
import HintTooltip from "../../internal/overlays/HintTooltip.vue";
|
|
146
|
+
import Icon from "../core/Icon.vue";
|
|
147
|
+
import Badge from "../data/Badge.vue";
|
|
148
|
+
import Kbd from "../core/Kbd.vue";
|
|
149
|
+
import Spinner from "../core/Spinner.vue";
|
|
150
|
+
import { provideFieldBoundary } from "../../composables/useFieldBoundary";
|
|
151
|
+
defineOptions({ inheritAttrs: false });
|
|
152
|
+
provideFieldBoundary();
|
|
153
|
+
const props = defineProps({
|
|
154
|
+
groups: { type: Array, required: false, default: () => [] },
|
|
155
|
+
search: { type: Function, required: false },
|
|
156
|
+
pinned: { type: [Array, Function], required: false },
|
|
157
|
+
debounce: { type: Number, required: false, default: 150 },
|
|
158
|
+
minQueryLength: { type: Number, required: false, default: 0 },
|
|
159
|
+
filter: { type: Boolean, required: false, default: true },
|
|
160
|
+
loading: { type: Boolean, required: false },
|
|
161
|
+
placeholder: { type: String, required: false },
|
|
162
|
+
label: { type: String, required: false },
|
|
163
|
+
autofocus: { type: Boolean, required: false, default: true },
|
|
164
|
+
recentKey: { type: String, required: false },
|
|
165
|
+
recentLimit: { type: Number, required: false, default: 5 },
|
|
166
|
+
recentLabel: { type: String, required: false },
|
|
167
|
+
emptyText: { type: [String, Function], required: false },
|
|
168
|
+
minQueryText: { type: String, required: false },
|
|
169
|
+
errorText: { type: String, required: false },
|
|
170
|
+
loadingText: { type: String, required: false },
|
|
171
|
+
resultsText: { type: Function, required: false },
|
|
172
|
+
footer: { type: Boolean, required: false },
|
|
173
|
+
footerMove: { type: String, required: false },
|
|
174
|
+
footerSelect: { type: String, required: false },
|
|
175
|
+
footerClose: { type: String, required: false },
|
|
176
|
+
notice: { type: String, required: false }
|
|
177
|
+
});
|
|
178
|
+
const { t } = useLocale();
|
|
179
|
+
const apple = useApplePlatform();
|
|
180
|
+
const placeholderText = computed(() => props.placeholder ?? t("commandPalette.placeholder"));
|
|
181
|
+
const labelText = computed(() => props.label ?? t("commandPalette.label"));
|
|
182
|
+
const recentText = computed(() => props.recentLabel ?? t("commandPalette.recent"));
|
|
183
|
+
const emptyLabel = computed(() => {
|
|
184
|
+
const text = props.emptyText;
|
|
185
|
+
if (typeof text === "function") return text(term.value);
|
|
186
|
+
return text ?? t("common.noResults");
|
|
187
|
+
});
|
|
188
|
+
const minQueryLabel = computed(() => props.minQueryText ?? t("commandPalette.minQuery"));
|
|
189
|
+
const errorLabel = computed(() => props.errorText ?? t("commandPalette.error"));
|
|
190
|
+
const loadingLabel = computed(() => props.loadingText ?? t("common.loading"));
|
|
191
|
+
const moveText = computed(() => props.footerMove ?? t("commandPalette.move"));
|
|
192
|
+
const selectText = computed(() => props.footerSelect ?? t("commandPalette.select"));
|
|
193
|
+
const closeText = computed(() => props.footerClose ?? t("commandPalette.close"));
|
|
194
|
+
const emit = defineEmits(["select", "close"]);
|
|
195
|
+
const slots = defineSlots();
|
|
196
|
+
const query = defineModel("query", { type: String, ...{ default: "" } });
|
|
197
|
+
const baseId = useId();
|
|
198
|
+
const labelId = `${baseId}-label`;
|
|
199
|
+
const inputId = `${baseId}-input`;
|
|
200
|
+
const listId = `${baseId}-list`;
|
|
201
|
+
const bodyRef = useTemplateRef("bodyRef");
|
|
202
|
+
const inputRef = useTemplateRef("inputRef");
|
|
203
|
+
const router = useRouterLike();
|
|
204
|
+
const active = ref(0);
|
|
205
|
+
const keyboardActive = ref(false);
|
|
206
|
+
const remote = shallowRef(null);
|
|
207
|
+
const recent = shallowRef([]);
|
|
208
|
+
const term = computed(() => query.value.trim());
|
|
209
|
+
const busy = computed(() => props.loading || search.searching.value);
|
|
210
|
+
const belowMinimum = computed(
|
|
211
|
+
() => Boolean(props.search) && term.value.length > 0 && term.value.length < props.minQueryLength
|
|
212
|
+
);
|
|
213
|
+
const pinnedItems = computed(() => {
|
|
214
|
+
const pinned = props.pinned;
|
|
215
|
+
if (!pinned) return [];
|
|
216
|
+
return typeof pinned === "function" ? pinned(term.value) : pinned;
|
|
217
|
+
});
|
|
218
|
+
const resultGroups = computed(() => {
|
|
219
|
+
if (props.search && term.value) return remote.value ?? [];
|
|
220
|
+
if (!props.filter || !term.value || props.search) return props.groups;
|
|
221
|
+
return props.groups.map((group) => ({
|
|
222
|
+
...group,
|
|
223
|
+
items: group.items.filter(
|
|
224
|
+
(item) => matchesSearch([item.label, item.description, ...item.keywords ?? []], term.value)
|
|
225
|
+
)
|
|
226
|
+
})).filter((group) => group.items.length);
|
|
227
|
+
});
|
|
228
|
+
const allItems = computed(() => props.groups.flatMap((group) => group.items));
|
|
229
|
+
const rendered = computed(() => {
|
|
230
|
+
const list = [];
|
|
231
|
+
let index = 0;
|
|
232
|
+
if (pinnedItems.value.length) {
|
|
233
|
+
list.push({
|
|
234
|
+
key: "pinned",
|
|
235
|
+
recent: false,
|
|
236
|
+
pinned: true,
|
|
237
|
+
items: pinnedItems.value.map((item) => ({
|
|
238
|
+
key: `pinned-${item.id}`,
|
|
239
|
+
index: index++,
|
|
240
|
+
item,
|
|
241
|
+
pinned: true
|
|
242
|
+
}))
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
if (!term.value && props.recentKey && recent.value.length) {
|
|
246
|
+
list.push({
|
|
247
|
+
key: "recent",
|
|
248
|
+
label: recentText.value,
|
|
249
|
+
recent: true,
|
|
250
|
+
pinned: false,
|
|
251
|
+
items: recent.value.map((snapshot) => {
|
|
252
|
+
const item = allItems.value.find((candidate) => candidate.id === snapshot.id) ?? snapshot;
|
|
253
|
+
return { key: `recent-${snapshot.id}`, index: index++, item, pinned: false };
|
|
254
|
+
})
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
for (const group of resultGroups.value) {
|
|
258
|
+
const items = group.more ? [
|
|
259
|
+
...group.items,
|
|
260
|
+
{
|
|
261
|
+
icon: "arrow-right",
|
|
262
|
+
...group.more,
|
|
263
|
+
id: group.more.id ?? `${group.id}:more`
|
|
264
|
+
}
|
|
265
|
+
] : group.items;
|
|
266
|
+
list.push({
|
|
267
|
+
key: `group-${group.id}`,
|
|
268
|
+
label: group.label,
|
|
269
|
+
description: group.description,
|
|
270
|
+
icon: group.icon,
|
|
271
|
+
source: group,
|
|
272
|
+
recent: false,
|
|
273
|
+
pinned: false,
|
|
274
|
+
items: items.map((item) => ({
|
|
275
|
+
key: `${group.id}-${item.id}`,
|
|
276
|
+
index: index++,
|
|
277
|
+
item,
|
|
278
|
+
pinned: false
|
|
279
|
+
}))
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
return list;
|
|
283
|
+
});
|
|
284
|
+
const flat = computed(() => rendered.value.flatMap((group) => group.items));
|
|
285
|
+
const resultCount = computed(() => flat.value.filter((entry) => !entry.pinned).length);
|
|
286
|
+
const activeId = computed(() => flat.value.length ? optionId(active.value) : void 0);
|
|
287
|
+
const hint = computed(() => {
|
|
288
|
+
if (belowMinimum.value) return minQueryLabel.value;
|
|
289
|
+
if (search.failed.value) return errorLabel.value;
|
|
290
|
+
if (!busy.value && !resultCount.value && (term.value || !props.search)) return emptyLabel.value;
|
|
291
|
+
return "";
|
|
292
|
+
});
|
|
293
|
+
const status = computed(() => {
|
|
294
|
+
if (hint.value) return hint.value;
|
|
295
|
+
if (busy.value) return loadingLabel.value;
|
|
296
|
+
const count = resultCount.value;
|
|
297
|
+
return props.resultsText ? props.resultsText(count) : t("commandPalette.results", { count });
|
|
298
|
+
});
|
|
299
|
+
function hasLabel(group) {
|
|
300
|
+
return !group.pinned && Boolean(group.label || slots["group-label"]);
|
|
301
|
+
}
|
|
302
|
+
function optionId(index) {
|
|
303
|
+
return `${listId}-option-${index}`;
|
|
304
|
+
}
|
|
305
|
+
function reasonId(index) {
|
|
306
|
+
return `${optionId(index)}-reason`;
|
|
307
|
+
}
|
|
308
|
+
function reasonOf(item) {
|
|
309
|
+
return item.disabled && item.disabledReason ? item.disabledReason : void 0;
|
|
310
|
+
}
|
|
311
|
+
const search = useAsyncSearch({
|
|
312
|
+
search: () => props.search,
|
|
313
|
+
onResults: (groups) => remote.value = groups,
|
|
314
|
+
onError: () => remote.value = []
|
|
315
|
+
});
|
|
316
|
+
function firstEnabled() {
|
|
317
|
+
return Math.max(0, nextEnabledIndex(flat.value.length, 0, 1, isDisabled));
|
|
318
|
+
}
|
|
319
|
+
watch(term, (value) => {
|
|
320
|
+
active.value = firstEnabled();
|
|
321
|
+
if (!props.search) return;
|
|
322
|
+
if (!value || value.length < props.minQueryLength) {
|
|
323
|
+
search.cancel();
|
|
324
|
+
remote.value = null;
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
search.schedule(value, props.debounce);
|
|
328
|
+
});
|
|
329
|
+
watch(flat, (items) => {
|
|
330
|
+
if (active.value >= items.length || isDisabled(active.value)) active.value = firstEnabled();
|
|
331
|
+
});
|
|
332
|
+
watch(active, (index) => {
|
|
333
|
+
nextTick(() => {
|
|
334
|
+
const option = document.getElementById(optionId(index));
|
|
335
|
+
if (option && bodyRef.value?.contains(option)) option.scrollIntoView({ block: "nearest" });
|
|
336
|
+
});
|
|
337
|
+
});
|
|
338
|
+
function badgeProps(badge) {
|
|
339
|
+
return typeof badge === "string" ? { label: badge } : badge;
|
|
340
|
+
}
|
|
341
|
+
function readRecent() {
|
|
342
|
+
if (!props.recentKey) return;
|
|
343
|
+
const stored = readStorageJson(props.recentKey);
|
|
344
|
+
recent.value = Array.isArray(stored) ? stored.slice(0, props.recentLimit) : [];
|
|
345
|
+
}
|
|
346
|
+
function saveRecent(item) {
|
|
347
|
+
if (!props.recentKey) return;
|
|
348
|
+
const snapshot = {
|
|
349
|
+
id: item.id,
|
|
350
|
+
label: item.label,
|
|
351
|
+
description: item.description,
|
|
352
|
+
icon: item.icon,
|
|
353
|
+
to: item.to,
|
|
354
|
+
href: item.href
|
|
355
|
+
};
|
|
356
|
+
recent.value = [snapshot, ...recent.value.filter((entry) => entry.id !== item.id)].slice(
|
|
357
|
+
0,
|
|
358
|
+
props.recentLimit
|
|
359
|
+
);
|
|
360
|
+
writeStorageJson(props.recentKey, recent.value);
|
|
361
|
+
}
|
|
362
|
+
function navigate(item) {
|
|
363
|
+
if (item.to !== void 0 && router) {
|
|
364
|
+
router.push(item.to);
|
|
365
|
+
return;
|
|
366
|
+
}
|
|
367
|
+
const href = item.href ?? (typeof item.to === "string" ? item.to : void 0);
|
|
368
|
+
if (href) window.location.assign(href);
|
|
369
|
+
}
|
|
370
|
+
function select(entry) {
|
|
371
|
+
const item = entry?.item;
|
|
372
|
+
if (!item || item.disabled) return;
|
|
373
|
+
if (!entry.pinned) saveRecent(item);
|
|
374
|
+
emit("select", item);
|
|
375
|
+
item.onSelect?.(item);
|
|
376
|
+
if (!item.onSelect) navigate(item);
|
|
377
|
+
}
|
|
378
|
+
function isDisabled(index) {
|
|
379
|
+
return Boolean(flat.value[index]?.item.disabled);
|
|
380
|
+
}
|
|
381
|
+
function isSkipped(index) {
|
|
382
|
+
const item = flat.value[index]?.item;
|
|
383
|
+
return Boolean(item?.disabled && !reasonOf(item));
|
|
384
|
+
}
|
|
385
|
+
function onOptionPointerMove(index) {
|
|
386
|
+
keyboardActive.value = false;
|
|
387
|
+
active.value = index;
|
|
388
|
+
}
|
|
389
|
+
function onKeydown(event) {
|
|
390
|
+
const count = flat.value.length;
|
|
391
|
+
if (event.key === "ArrowDown" || event.key === "ArrowUp") {
|
|
392
|
+
event.preventDefault();
|
|
393
|
+
if (!count) return;
|
|
394
|
+
const step = event.key === "ArrowDown" ? 1 : -1;
|
|
395
|
+
const next = nextEnabledIndex(count, active.value + step, step, isSkipped);
|
|
396
|
+
keyboardActive.value = true;
|
|
397
|
+
if (next !== -1) active.value = next;
|
|
398
|
+
} else if ((event.key === "Home" || event.key === "End") && event.ctrlKey && count) {
|
|
399
|
+
event.preventDefault();
|
|
400
|
+
const next = event.key === "Home" ? nextEnabledIndex(count, 0, 1, isSkipped) : nextEnabledIndex(count, count - 1, -1, isSkipped);
|
|
401
|
+
keyboardActive.value = true;
|
|
402
|
+
if (next !== -1) active.value = next;
|
|
403
|
+
} else if (event.key === "Enter" && !event.isComposing) {
|
|
404
|
+
event.preventDefault();
|
|
405
|
+
select(flat.value[active.value]);
|
|
406
|
+
} else if (event.key === "Escape" && !event.isComposing) {
|
|
407
|
+
emit("close");
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
function focus() {
|
|
411
|
+
inputRef.value?.focus({ preventScroll: true });
|
|
412
|
+
inputRef.value?.select();
|
|
413
|
+
}
|
|
414
|
+
function refresh() {
|
|
415
|
+
readRecent();
|
|
416
|
+
active.value = firstEnabled();
|
|
417
|
+
}
|
|
418
|
+
onMounted(() => {
|
|
419
|
+
readRecent();
|
|
420
|
+
if (props.autofocus) inputRef.value?.focus({ preventScroll: true });
|
|
421
|
+
});
|
|
422
|
+
defineExpose({ focus, refresh });
|
|
423
|
+
</script>
|