@xleddyl/443-components-vue 0.16.88 → 0.16.90
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 +33 -4
- 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 +87 -17
- package/dist/components/data/Tree.vue.d.ts +19 -3
- package/dist/components/data/types.d.ts +1 -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 +397 -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/locale/de.mjs +2 -1
- package/dist/locale/en.mjs +2 -1
- package/dist/locale/it.mjs +2 -1
- package/dist/locale/types.d.ts +1 -0
- package/dist/styles/data/tree.css +23 -4
- package/dist/styles/forced-colors.css +6 -1
- package/dist/styles/overlays/command.css +22 -0
- package/package.json +1 -1
|
@@ -496,6 +496,7 @@ declare const __VLS_export: import("vue").DefineComponent<{
|
|
|
496
496
|
}>, {
|
|
497
497
|
size: FieldSize;
|
|
498
498
|
invalid: boolean;
|
|
499
|
+
disabled: boolean;
|
|
499
500
|
type: "month" | "week" | "date" | "datetime-local";
|
|
500
501
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
501
502
|
declare const _default: typeof __VLS_export;
|
|
@@ -117,7 +117,7 @@ const props = defineProps({
|
|
|
117
117
|
closeOnSelect: { type: Boolean, required: false, default: true },
|
|
118
118
|
level: { type: Number, required: false },
|
|
119
119
|
invalid: { type: Boolean, required: false, default: void 0 },
|
|
120
|
-
disabled: { type: Boolean, required: false },
|
|
120
|
+
disabled: { type: Boolean, required: false, default: void 0 },
|
|
121
121
|
readonly: { type: Boolean, required: false },
|
|
122
122
|
required: { type: Boolean, required: false },
|
|
123
123
|
class: { type: null, required: false },
|
|
@@ -464,6 +464,7 @@ declare const __VLS_base: import("vue").DefineComponent<{
|
|
|
464
464
|
}>, {
|
|
465
465
|
size: FieldSize;
|
|
466
466
|
invalid: boolean;
|
|
467
|
+
disabled: boolean;
|
|
467
468
|
format: Intl.DateTimeFormatOptions;
|
|
468
469
|
closeOnSelect: boolean;
|
|
469
470
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
@@ -180,7 +180,7 @@ const props = defineProps({
|
|
|
180
180
|
locale: { type: String, required: false },
|
|
181
181
|
announce: { type: Function, required: false },
|
|
182
182
|
invalid: { type: Boolean, required: false, default: void 0 },
|
|
183
|
-
disabled: { type: Boolean, required: false },
|
|
183
|
+
disabled: { type: Boolean, required: false, default: void 0 },
|
|
184
184
|
readonly: { type: Boolean, required: false },
|
|
185
185
|
required: { type: Boolean, required: false },
|
|
186
186
|
class: { type: null, required: false },
|
|
@@ -502,6 +502,7 @@ declare const __VLS_base: import("vue").DefineComponent<{
|
|
|
502
502
|
size: FieldSize;
|
|
503
503
|
invalid: boolean;
|
|
504
504
|
list: boolean;
|
|
505
|
+
disabled: boolean;
|
|
505
506
|
acceptMode: FileInputAcceptMode;
|
|
506
507
|
previews: boolean;
|
|
507
508
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
@@ -101,7 +101,7 @@ const props = defineProps({
|
|
|
101
101
|
incrementLabel: { type: String, required: false },
|
|
102
102
|
decrementLabel: { type: String, required: false },
|
|
103
103
|
invalid: { type: Boolean, required: false, default: void 0 },
|
|
104
|
-
disabled: { type: Boolean, required: false },
|
|
104
|
+
disabled: { type: Boolean, required: false, default: void 0 },
|
|
105
105
|
readonly: { type: Boolean, required: false },
|
|
106
106
|
required: { type: Boolean, required: false },
|
|
107
107
|
class: { type: null, required: false },
|
|
@@ -492,6 +492,7 @@ declare const __VLS_export: import("vue").DefineComponent<{
|
|
|
492
492
|
stepper: boolean;
|
|
493
493
|
invalid: boolean;
|
|
494
494
|
align: "start" | "end";
|
|
495
|
+
disabled: boolean;
|
|
495
496
|
step: number;
|
|
496
497
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
497
498
|
declare const _default: typeof __VLS_export;
|
|
@@ -40,7 +40,7 @@ const props = defineProps({
|
|
|
40
40
|
placeholder: { type: String, required: false },
|
|
41
41
|
customLabel: { type: String, required: false },
|
|
42
42
|
size: { type: String, required: false, default: "md" },
|
|
43
|
-
disabled: { type: Boolean, required: false },
|
|
43
|
+
disabled: { type: Boolean, required: false, default: void 0 },
|
|
44
44
|
readonly: { type: Boolean, required: false },
|
|
45
45
|
invalid: { type: Boolean, required: false, default: void 0 },
|
|
46
46
|
class: { type: null, required: false },
|
|
@@ -545,6 +545,7 @@ declare const __VLS_export: import("vue").DefineComponent<{
|
|
|
545
545
|
}>, {
|
|
546
546
|
size: FieldSize;
|
|
547
547
|
invalid: boolean;
|
|
548
|
+
disabled: boolean;
|
|
548
549
|
colors: readonly PaletteColor[];
|
|
549
550
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
550
551
|
declare const _default: typeof __VLS_export;
|
|
@@ -108,7 +108,7 @@ const props = defineProps({
|
|
|
108
108
|
copiedLabel: { type: String, required: false },
|
|
109
109
|
strengthLabel: { type: String, required: false },
|
|
110
110
|
invalid: { type: Boolean, required: false, default: void 0 },
|
|
111
|
-
disabled: { type: Boolean, required: false },
|
|
111
|
+
disabled: { type: Boolean, required: false, default: void 0 },
|
|
112
112
|
readonly: { type: Boolean, required: false },
|
|
113
113
|
required: { type: Boolean, required: false },
|
|
114
114
|
class: { type: null, required: false },
|
|
@@ -524,6 +524,7 @@ declare const __VLS_export: import("vue").DefineComponent<{
|
|
|
524
524
|
size: FieldSize;
|
|
525
525
|
minLength: number;
|
|
526
526
|
invalid: boolean;
|
|
527
|
+
disabled: boolean;
|
|
527
528
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
528
529
|
declare const _default: typeof __VLS_export;
|
|
529
530
|
export default _default;
|
|
@@ -89,7 +89,7 @@ const props = defineProps({
|
|
|
89
89
|
noAutofill: { type: Boolean, required: false },
|
|
90
90
|
size: { type: String, required: false, default: "md" },
|
|
91
91
|
invalid: { type: Boolean, required: false, default: void 0 },
|
|
92
|
-
disabled: { type: Boolean, required: false },
|
|
92
|
+
disabled: { type: Boolean, required: false, default: void 0 },
|
|
93
93
|
readonly: { type: Boolean, required: false },
|
|
94
94
|
required: { type: Boolean, required: false },
|
|
95
95
|
class: { type: null, required: false },
|
|
@@ -53,7 +53,7 @@ const props = defineProps({
|
|
|
53
53
|
size: { type: String, required: false, default: "md" },
|
|
54
54
|
name: { type: String, required: false },
|
|
55
55
|
invalid: { type: Boolean, required: false, default: void 0 },
|
|
56
|
-
disabled: { type: Boolean, required: false },
|
|
56
|
+
disabled: { type: Boolean, required: false, default: void 0 },
|
|
57
57
|
readonly: { type: Boolean, required: false },
|
|
58
58
|
required: { type: Boolean, required: false }
|
|
59
59
|
});
|
|
@@ -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,397 @@
|
|
|
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
|
+
@pointermove="active = entry.index"
|
|
71
|
+
@click="select(entry)"
|
|
72
|
+
>
|
|
73
|
+
<slot name="item" :item="entry.item" :active="entry.index === active">
|
|
74
|
+
<Icon
|
|
75
|
+
:name="
|
|
76
|
+
entry.item.icon ?? group.icon ?? (group.recent ? 'arrow-path' : group.pinned ? 'plus' : 'arrow-right')
|
|
77
|
+
"
|
|
78
|
+
class="k-command-option-icon"
|
|
79
|
+
/>
|
|
80
|
+
<span class="k-command-option-text">
|
|
81
|
+
<span class="k-command-option-label">{{ entry.item.label }}</span>
|
|
82
|
+
<span v-if="entry.item.description" class="k-command-option-description">
|
|
83
|
+
{{ entry.item.description }}
|
|
84
|
+
</span>
|
|
85
|
+
</span>
|
|
86
|
+
<Badge
|
|
87
|
+
v-if="entry.item.badge"
|
|
88
|
+
v-bind="badgeProps(entry.item.badge)"
|
|
89
|
+
size="sm"
|
|
90
|
+
class="k-command-option-badge"
|
|
91
|
+
/>
|
|
92
|
+
<span
|
|
93
|
+
v-if="entry.item.shortcut"
|
|
94
|
+
class="k-command-option-shortcut"
|
|
95
|
+
aria-hidden="true"
|
|
96
|
+
>
|
|
97
|
+
<Kbd
|
|
98
|
+
v-for="(key, keyIndex) in formatHotkey(entry.item.shortcut, apple)"
|
|
99
|
+
:key="keyIndex"
|
|
100
|
+
size="sm"
|
|
101
|
+
>
|
|
102
|
+
{{ key }}
|
|
103
|
+
</Kbd>
|
|
104
|
+
</span>
|
|
105
|
+
</slot>
|
|
106
|
+
</div>
|
|
107
|
+
</div>
|
|
108
|
+
</div>
|
|
109
|
+
<p v-if="hint" class="k-command-hint">
|
|
110
|
+
<slot name="empty" :query="query">{{ hint }}</slot>
|
|
111
|
+
</p>
|
|
112
|
+
<div v-if="resultCount && (notice || $slots['after-results'])" class="k-command-notice">
|
|
113
|
+
<slot name="after-results" :query="query" :count="resultCount">{{ notice }}</slot>
|
|
114
|
+
</div>
|
|
115
|
+
</div>
|
|
116
|
+
<div v-if="footer" class="k-command-footer" aria-hidden="true">
|
|
117
|
+
<span><Kbd size="sm">↑</Kbd><Kbd size="sm">↓</Kbd> {{ moveText }}</span>
|
|
118
|
+
<span><Kbd size="sm">↵</Kbd> {{ selectText }}</span>
|
|
119
|
+
<span><Kbd size="sm">Esc</Kbd> {{ closeText }}</span>
|
|
120
|
+
</div>
|
|
121
|
+
<LiveRegion :message="status" />
|
|
122
|
+
</DivElement>
|
|
123
|
+
</template>
|
|
124
|
+
|
|
125
|
+
<script setup>
|
|
126
|
+
import { computed, nextTick, onMounted, ref, shallowRef, useId, useTemplateRef, watch } from "vue";
|
|
127
|
+
import { formatHotkey } from "../../composables/useHotkey";
|
|
128
|
+
import { useApplePlatform } from "../../internal/core/env";
|
|
129
|
+
import { useLocale } from "../../composables/useLocale";
|
|
130
|
+
import { nextEnabledIndex } from "../../internal/core/roving";
|
|
131
|
+
import { useAsyncSearch } from "../../internal/core/search";
|
|
132
|
+
import { matchesSearch } from "../../internal/core/text";
|
|
133
|
+
import { readStorageJson, writeStorageJson } from "../../internal/core/storage";
|
|
134
|
+
import { useRouterLike } from "../../internal/layout/route";
|
|
135
|
+
import { DivElement } from "../../internal/core/DivElement";
|
|
136
|
+
import LiveRegion from "../../internal/core/LiveRegion.vue";
|
|
137
|
+
import Icon from "../core/Icon.vue";
|
|
138
|
+
import Badge from "../data/Badge.vue";
|
|
139
|
+
import Kbd from "../core/Kbd.vue";
|
|
140
|
+
import Spinner from "../core/Spinner.vue";
|
|
141
|
+
import { provideFieldBoundary } from "../../composables/useFieldBoundary";
|
|
142
|
+
defineOptions({ inheritAttrs: false });
|
|
143
|
+
provideFieldBoundary();
|
|
144
|
+
const props = defineProps({
|
|
145
|
+
groups: { type: Array, required: false, default: () => [] },
|
|
146
|
+
search: { type: Function, required: false },
|
|
147
|
+
pinned: { type: [Array, Function], required: false },
|
|
148
|
+
debounce: { type: Number, required: false, default: 150 },
|
|
149
|
+
minQueryLength: { type: Number, required: false, default: 0 },
|
|
150
|
+
filter: { type: Boolean, required: false, default: true },
|
|
151
|
+
loading: { type: Boolean, required: false },
|
|
152
|
+
placeholder: { type: String, required: false },
|
|
153
|
+
label: { type: String, required: false },
|
|
154
|
+
autofocus: { type: Boolean, required: false, default: true },
|
|
155
|
+
recentKey: { type: String, required: false },
|
|
156
|
+
recentLimit: { type: Number, required: false, default: 5 },
|
|
157
|
+
recentLabel: { type: String, required: false },
|
|
158
|
+
emptyText: { type: [String, Function], required: false },
|
|
159
|
+
minQueryText: { type: String, required: false },
|
|
160
|
+
errorText: { type: String, required: false },
|
|
161
|
+
loadingText: { type: String, required: false },
|
|
162
|
+
resultsText: { type: Function, required: false },
|
|
163
|
+
footer: { type: Boolean, required: false },
|
|
164
|
+
footerMove: { type: String, required: false },
|
|
165
|
+
footerSelect: { type: String, required: false },
|
|
166
|
+
footerClose: { type: String, required: false },
|
|
167
|
+
notice: { type: String, required: false }
|
|
168
|
+
});
|
|
169
|
+
const { t } = useLocale();
|
|
170
|
+
const apple = useApplePlatform();
|
|
171
|
+
const placeholderText = computed(() => props.placeholder ?? t("commandPalette.placeholder"));
|
|
172
|
+
const labelText = computed(() => props.label ?? t("commandPalette.label"));
|
|
173
|
+
const recentText = computed(() => props.recentLabel ?? t("commandPalette.recent"));
|
|
174
|
+
const emptyLabel = computed(() => {
|
|
175
|
+
const text = props.emptyText;
|
|
176
|
+
if (typeof text === "function") return text(term.value);
|
|
177
|
+
return text ?? t("common.noResults");
|
|
178
|
+
});
|
|
179
|
+
const minQueryLabel = computed(() => props.minQueryText ?? t("commandPalette.minQuery"));
|
|
180
|
+
const errorLabel = computed(() => props.errorText ?? t("commandPalette.error"));
|
|
181
|
+
const loadingLabel = computed(() => props.loadingText ?? t("common.loading"));
|
|
182
|
+
const moveText = computed(() => props.footerMove ?? t("commandPalette.move"));
|
|
183
|
+
const selectText = computed(() => props.footerSelect ?? t("commandPalette.select"));
|
|
184
|
+
const closeText = computed(() => props.footerClose ?? t("commandPalette.close"));
|
|
185
|
+
const emit = defineEmits(["select", "close"]);
|
|
186
|
+
const slots = defineSlots();
|
|
187
|
+
const query = defineModel("query", { type: String, ...{ default: "" } });
|
|
188
|
+
const baseId = useId();
|
|
189
|
+
const labelId = `${baseId}-label`;
|
|
190
|
+
const inputId = `${baseId}-input`;
|
|
191
|
+
const listId = `${baseId}-list`;
|
|
192
|
+
const bodyRef = useTemplateRef("bodyRef");
|
|
193
|
+
const inputRef = useTemplateRef("inputRef");
|
|
194
|
+
const router = useRouterLike();
|
|
195
|
+
const active = ref(0);
|
|
196
|
+
const remote = shallowRef(null);
|
|
197
|
+
const recent = shallowRef([]);
|
|
198
|
+
const term = computed(() => query.value.trim());
|
|
199
|
+
const busy = computed(() => props.loading || search.searching.value);
|
|
200
|
+
const belowMinimum = computed(
|
|
201
|
+
() => Boolean(props.search) && term.value.length > 0 && term.value.length < props.minQueryLength
|
|
202
|
+
);
|
|
203
|
+
const pinnedItems = computed(() => {
|
|
204
|
+
const pinned = props.pinned;
|
|
205
|
+
if (!pinned) return [];
|
|
206
|
+
return typeof pinned === "function" ? pinned(term.value) : pinned;
|
|
207
|
+
});
|
|
208
|
+
const resultGroups = computed(() => {
|
|
209
|
+
if (props.search && term.value) return remote.value ?? [];
|
|
210
|
+
if (!props.filter || !term.value || props.search) return props.groups;
|
|
211
|
+
return props.groups.map((group) => ({
|
|
212
|
+
...group,
|
|
213
|
+
items: group.items.filter(
|
|
214
|
+
(item) => matchesSearch([item.label, item.description, ...item.keywords ?? []], term.value)
|
|
215
|
+
)
|
|
216
|
+
})).filter((group) => group.items.length);
|
|
217
|
+
});
|
|
218
|
+
const allItems = computed(() => props.groups.flatMap((group) => group.items));
|
|
219
|
+
const rendered = computed(() => {
|
|
220
|
+
const list = [];
|
|
221
|
+
let index = 0;
|
|
222
|
+
if (pinnedItems.value.length) {
|
|
223
|
+
list.push({
|
|
224
|
+
key: "pinned",
|
|
225
|
+
recent: false,
|
|
226
|
+
pinned: true,
|
|
227
|
+
items: pinnedItems.value.map((item) => ({
|
|
228
|
+
key: `pinned-${item.id}`,
|
|
229
|
+
index: index++,
|
|
230
|
+
item,
|
|
231
|
+
pinned: true
|
|
232
|
+
}))
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
if (!term.value && props.recentKey && recent.value.length) {
|
|
236
|
+
list.push({
|
|
237
|
+
key: "recent",
|
|
238
|
+
label: recentText.value,
|
|
239
|
+
recent: true,
|
|
240
|
+
pinned: false,
|
|
241
|
+
items: recent.value.map((snapshot) => {
|
|
242
|
+
const item = allItems.value.find((candidate) => candidate.id === snapshot.id) ?? snapshot;
|
|
243
|
+
return { key: `recent-${snapshot.id}`, index: index++, item, pinned: false };
|
|
244
|
+
})
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
for (const group of resultGroups.value) {
|
|
248
|
+
const items = group.more ? [
|
|
249
|
+
...group.items,
|
|
250
|
+
{
|
|
251
|
+
icon: "arrow-right",
|
|
252
|
+
...group.more,
|
|
253
|
+
id: group.more.id ?? `${group.id}:more`
|
|
254
|
+
}
|
|
255
|
+
] : group.items;
|
|
256
|
+
list.push({
|
|
257
|
+
key: `group-${group.id}`,
|
|
258
|
+
label: group.label,
|
|
259
|
+
description: group.description,
|
|
260
|
+
icon: group.icon,
|
|
261
|
+
source: group,
|
|
262
|
+
recent: false,
|
|
263
|
+
pinned: false,
|
|
264
|
+
items: items.map((item) => ({
|
|
265
|
+
key: `${group.id}-${item.id}`,
|
|
266
|
+
index: index++,
|
|
267
|
+
item,
|
|
268
|
+
pinned: false
|
|
269
|
+
}))
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
return list;
|
|
273
|
+
});
|
|
274
|
+
const flat = computed(() => rendered.value.flatMap((group) => group.items));
|
|
275
|
+
const resultCount = computed(() => flat.value.filter((entry) => !entry.pinned).length);
|
|
276
|
+
const activeId = computed(() => flat.value.length ? optionId(active.value) : void 0);
|
|
277
|
+
const hint = computed(() => {
|
|
278
|
+
if (belowMinimum.value) return minQueryLabel.value;
|
|
279
|
+
if (search.failed.value) return errorLabel.value;
|
|
280
|
+
if (!busy.value && !resultCount.value && (term.value || !props.search)) return emptyLabel.value;
|
|
281
|
+
return "";
|
|
282
|
+
});
|
|
283
|
+
const status = computed(() => {
|
|
284
|
+
if (hint.value) return hint.value;
|
|
285
|
+
if (busy.value) return loadingLabel.value;
|
|
286
|
+
const count = resultCount.value;
|
|
287
|
+
return props.resultsText ? props.resultsText(count) : t("commandPalette.results", { count });
|
|
288
|
+
});
|
|
289
|
+
function hasLabel(group) {
|
|
290
|
+
return !group.pinned && Boolean(group.label || slots["group-label"]);
|
|
291
|
+
}
|
|
292
|
+
function optionId(index) {
|
|
293
|
+
return `${listId}-option-${index}`;
|
|
294
|
+
}
|
|
295
|
+
const search = useAsyncSearch({
|
|
296
|
+
search: () => props.search,
|
|
297
|
+
onResults: (groups) => remote.value = groups,
|
|
298
|
+
onError: () => remote.value = []
|
|
299
|
+
});
|
|
300
|
+
function firstEnabled() {
|
|
301
|
+
return Math.max(0, nextEnabledIndex(flat.value.length, 0, 1, isDisabled));
|
|
302
|
+
}
|
|
303
|
+
watch(term, (value) => {
|
|
304
|
+
active.value = firstEnabled();
|
|
305
|
+
if (!props.search) return;
|
|
306
|
+
if (!value || value.length < props.minQueryLength) {
|
|
307
|
+
search.cancel();
|
|
308
|
+
remote.value = null;
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
search.schedule(value, props.debounce);
|
|
312
|
+
});
|
|
313
|
+
watch(flat, (items) => {
|
|
314
|
+
if (active.value >= items.length || isDisabled(active.value)) active.value = firstEnabled();
|
|
315
|
+
});
|
|
316
|
+
watch(active, (index) => {
|
|
317
|
+
nextTick(() => {
|
|
318
|
+
const option = document.getElementById(optionId(index));
|
|
319
|
+
if (option && bodyRef.value?.contains(option)) option.scrollIntoView({ block: "nearest" });
|
|
320
|
+
});
|
|
321
|
+
});
|
|
322
|
+
function badgeProps(badge) {
|
|
323
|
+
return typeof badge === "string" ? { label: badge } : badge;
|
|
324
|
+
}
|
|
325
|
+
function readRecent() {
|
|
326
|
+
if (!props.recentKey) return;
|
|
327
|
+
const stored = readStorageJson(props.recentKey);
|
|
328
|
+
recent.value = Array.isArray(stored) ? stored.slice(0, props.recentLimit) : [];
|
|
329
|
+
}
|
|
330
|
+
function saveRecent(item) {
|
|
331
|
+
if (!props.recentKey) return;
|
|
332
|
+
const snapshot = {
|
|
333
|
+
id: item.id,
|
|
334
|
+
label: item.label,
|
|
335
|
+
description: item.description,
|
|
336
|
+
icon: item.icon,
|
|
337
|
+
to: item.to,
|
|
338
|
+
href: item.href
|
|
339
|
+
};
|
|
340
|
+
recent.value = [snapshot, ...recent.value.filter((entry) => entry.id !== item.id)].slice(
|
|
341
|
+
0,
|
|
342
|
+
props.recentLimit
|
|
343
|
+
);
|
|
344
|
+
writeStorageJson(props.recentKey, recent.value);
|
|
345
|
+
}
|
|
346
|
+
function navigate(item) {
|
|
347
|
+
if (item.to !== void 0 && router) {
|
|
348
|
+
router.push(item.to);
|
|
349
|
+
return;
|
|
350
|
+
}
|
|
351
|
+
const href = item.href ?? (typeof item.to === "string" ? item.to : void 0);
|
|
352
|
+
if (href) window.location.assign(href);
|
|
353
|
+
}
|
|
354
|
+
function select(entry) {
|
|
355
|
+
const item = entry?.item;
|
|
356
|
+
if (!item || item.disabled) return;
|
|
357
|
+
if (!entry.pinned) saveRecent(item);
|
|
358
|
+
emit("select", item);
|
|
359
|
+
item.onSelect?.(item);
|
|
360
|
+
if (!item.onSelect) navigate(item);
|
|
361
|
+
}
|
|
362
|
+
function isDisabled(index) {
|
|
363
|
+
return Boolean(flat.value[index]?.item.disabled);
|
|
364
|
+
}
|
|
365
|
+
function onKeydown(event) {
|
|
366
|
+
const count = flat.value.length;
|
|
367
|
+
if (event.key === "ArrowDown" || event.key === "ArrowUp") {
|
|
368
|
+
event.preventDefault();
|
|
369
|
+
if (!count) return;
|
|
370
|
+
const step = event.key === "ArrowDown" ? 1 : -1;
|
|
371
|
+
const next = nextEnabledIndex(count, active.value + step, step, isDisabled);
|
|
372
|
+
if (next !== -1) active.value = next;
|
|
373
|
+
} else if ((event.key === "Home" || event.key === "End") && event.ctrlKey && count) {
|
|
374
|
+
event.preventDefault();
|
|
375
|
+
const next = event.key === "Home" ? nextEnabledIndex(count, 0, 1, isDisabled) : nextEnabledIndex(count, count - 1, -1, isDisabled);
|
|
376
|
+
if (next !== -1) active.value = next;
|
|
377
|
+
} else if (event.key === "Enter" && !event.isComposing) {
|
|
378
|
+
event.preventDefault();
|
|
379
|
+
select(flat.value[active.value]);
|
|
380
|
+
} else if (event.key === "Escape" && !event.isComposing) {
|
|
381
|
+
emit("close");
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
function focus() {
|
|
385
|
+
inputRef.value?.focus({ preventScroll: true });
|
|
386
|
+
inputRef.value?.select();
|
|
387
|
+
}
|
|
388
|
+
function refresh() {
|
|
389
|
+
readRecent();
|
|
390
|
+
active.value = firstEnabled();
|
|
391
|
+
}
|
|
392
|
+
onMounted(() => {
|
|
393
|
+
readRecent();
|
|
394
|
+
if (props.autofocus) inputRef.value?.focus({ preventScroll: true });
|
|
395
|
+
});
|
|
396
|
+
defineExpose({ focus, refresh });
|
|
397
|
+
</script>
|