@astryx-vue/core 0.16.5 → 0.18.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/dist/AppShell/index.d.ts +1 -1
- package/dist/AvatarGroup/index.d.ts +1 -1
- package/dist/Banner/index.d.ts +1 -1
- package/dist/BottomSheet/index.d.ts +1 -1
- package/dist/Button/index.d.ts +1 -1
- package/dist/ButtonGroup/index.d.ts +1 -1
- package/dist/Calendar/index.d.ts +1 -1
- package/dist/Carousel/index.d.ts +1 -1
- package/dist/Chat/index.d.ts +1 -1
- package/dist/Chat/index.js +1 -1
- package/dist/CheckboxInput/index.d.ts +1 -1
- package/dist/CheckboxList/index.d.ts +1 -1
- package/dist/ClickableCard/index.d.ts +1 -1
- package/dist/Code/index.d.ts +1 -1
- package/dist/Code/index.js +1 -1
- package/dist/Collapsible/index.d.ts +1 -1
- package/dist/Collapsible/index.js +1 -1
- package/dist/{Collapsible-Dk9BQQbT.js → Collapsible-ExzU7vC0.js} +104 -40
- package/dist/CommandPalette/index.d.ts +1 -1
- package/dist/CommandPalette/index.js +1 -1
- package/dist/{CommandPalette-mNR6dV0B.js → CommandPalette-CECjNvGB.js} +1 -1
- package/dist/ComplexSelector/index.js +1 -1
- package/dist/{ComplexSelector-CR9XbpTa.js → ComplexSelector-Dmaag1wm.js} +5 -1
- package/dist/ContextMenu/index.d.ts +1 -1
- package/dist/DateInput/index.d.ts +1 -1
- package/dist/DateInput/index.js +1 -1
- package/dist/DateRangeInput/index.d.ts +1 -1
- package/dist/DateRangeInput/index.js +1 -1
- package/dist/DateTimeInput/index.d.ts +1 -1
- package/dist/DateTimeInput/index.js +1 -1
- package/dist/{DateTimeInput-ChGin5zS.js → DateTimeInput-Cfkuec_h.js} +1 -1
- package/dist/Dialog/index.d.ts +1 -1
- package/dist/Divider/index.d.ts +1 -1
- package/dist/Drawer/index.d.ts +1 -1
- package/dist/Field/index.d.ts +1 -1
- package/dist/FileInput/index.d.ts +1 -1
- package/dist/HoverCard/index.d.ts +1 -1
- package/dist/Indicator/index.d.ts +2 -2
- package/dist/InfoTip/index.d.ts +1 -1
- package/dist/InputGroup/index.d.ts +1 -1
- package/dist/InternationalizationProvider/index.d.ts +1 -1
- package/dist/InternationalizationProvider/index.js +1 -1
- package/dist/{InternationalizationProvider-7rA65NO7.js → InternationalizationProvider-Dr5GE6f0.js} +1 -1
- package/dist/Link/index.d.ts +1 -1
- package/dist/List/index.d.ts +1 -1
- package/dist/Markdown/index.js +1 -1
- package/dist/{Markdown-BNVd70jg.js → Markdown-DnnWjJGX.js} +1 -1
- package/dist/{MediaTheme-Bkj-_DFN.js → MediaTheme-DfcdEWx-.js} +2 -36
- package/dist/MoreMenu/index.d.ts +1 -1
- package/dist/MultiSelector/index.d.ts +1 -1
- package/dist/MultiSelector/index.js +1 -1
- package/dist/{MultiSelector-CXX1Hsty.js → MultiSelector-BK6nZweN.js} +26 -14
- package/dist/NavItem/index.d.ts +1 -1
- package/dist/NumberInput/index.d.ts +1 -1
- package/dist/OverflowList/index.d.ts +1 -1
- package/dist/Pagination/index.d.ts +1 -1
- package/dist/Pagination/index.js +1 -1
- package/dist/{Pagination-BvZFvwso.js → Pagination-DFQNX_Mb.js} +1 -1
- package/dist/Popover/index.d.ts +1 -1
- package/dist/PowerSearch/index.d.ts +1 -1
- package/dist/PowerSearch/index.js +1 -1
- package/dist/{PowerSearch-BiupstfT.js → PowerSearch-BAOqpQag.js} +10 -10
- package/dist/ProgressBar/index.d.ts +1 -1
- package/dist/Radio/index.d.ts +1 -1
- package/dist/RadioList/index.d.ts +1 -1
- package/dist/ScrollableArea/index.d.ts +1 -1
- package/dist/SegmentedControl/index.d.ts +1 -1
- package/dist/SelectableCard/index.d.ts +1 -1
- package/dist/Selector/index.d.ts +1 -1
- package/dist/Selector/index.js +1 -1
- package/dist/{Selector-DiSLNzl8.js → Selector-Bo7qkt1P.js} +157 -62
- package/dist/SideNav/index.d.ts +1 -1
- package/dist/Stepper/index.d.ts +1 -1
- package/dist/Switch/index.d.ts +1 -1
- package/dist/Table/index.d.ts +1 -1
- package/dist/Table/index.js +1 -1
- package/dist/{Table-BD8MugZo.js → Table-iemur_3E.js} +378 -7
- package/dist/TextArea/index.d.ts +1 -1
- package/dist/TextInput/index.d.ts +1 -1
- package/dist/Theme/index.d.ts +3 -3
- package/dist/Theme/index.js +3 -2
- package/dist/{Theme-8bDq2nud.js → Theme-1RJVaRgz.js} +329 -40
- package/dist/TimeInput/index.d.ts +1 -1
- package/dist/Timer/index.d.ts +1 -1
- package/dist/Timestamp/index.d.ts +1 -1
- package/dist/Toast/index.js +1 -1
- package/dist/{Toast-CzbqvHDN.js → Toast-D4Q6wvYu.js} +1 -1
- package/dist/ToggleButton/index.d.ts +1 -1
- package/dist/Tokenizer/index.d.ts +1 -1
- package/dist/Tokenizer/index.js +1 -1
- package/dist/{Tokenizer-mu0Sak58.js → Tokenizer-CsFiYUJ_.js} +171 -103
- package/dist/Toolbar/index.d.ts +1 -1
- package/dist/Tooltip/index.d.ts +1 -1
- package/dist/TopNav/index.d.ts +1 -1
- package/dist/TreeList/index.d.ts +1 -1
- package/dist/TreeList/index.js +1 -1
- package/dist/{TreeList-CNj4KnHH.js → TreeList-ugSF9DWj.js} +117 -2
- package/dist/Typeahead/index.d.ts +2 -1
- package/dist/Typeahead/index.js +2 -2
- package/dist/{Typeahead-Db8Tu27Z.js → Typeahead--kEp21ut.js} +159 -71
- package/dist/{useKeyboardHighlight-CGCf1O57.js → assertOptions-CK_gJ0d3.js} +12 -1
- package/dist/composables/index.d.ts +4 -3
- package/dist/composables/index.js +5 -5
- package/dist/composables-BgfubKnk.js +5437 -0
- package/dist/handle-BPXdHbkr.js +458 -0
- package/dist/{index-sXu15K4j.d.ts → index-B-3EGjfQ.d.ts} +2 -2
- package/dist/{index-TXcNH86P.d.ts → index-B1eCxBCY.d.ts} +1 -1
- package/dist/{index-9eluGe3a.d.ts → index-BBTU-TKb.d.ts} +1 -1
- package/dist/{index-CE74Qsbn.d.ts → index-BKpnfdq1.d.ts} +9 -9
- package/dist/{index-D_xBhUV5.d.ts → index-B_PKY-Wn.d.ts} +11 -11
- package/dist/{index-Bfm6mF-r.d.ts → index-BfoazhEu.d.ts} +1 -1
- package/dist/{index-BWzEt0gT.d.ts → index-BhxqUt3y.d.ts} +1 -1
- package/dist/{index-CJdOt5Cc.d.ts → index-BtqvPjAf.d.ts} +3 -3
- package/dist/{index-ChqMaV6N.d.ts → index-Bzi3A980.d.ts} +1 -1
- package/dist/{index-DBwEz4M9.d.ts → index-BzmcDJau.d.ts} +11 -11
- package/dist/{index-CQ1bsxLC.d.ts → index-C1qJlC65.d.ts} +1 -1
- package/dist/{index-CMLnSg3T.d.ts → index-C4S65SAW.d.ts} +8 -1
- package/dist/{index-D05JGsT3.d.ts → index-C8wfe0Mr.d.ts} +1 -1
- package/dist/{index-gmY3A_Iw.d.ts → index-C93nwgTW.d.ts} +1 -1
- package/dist/{index-BvWBeoa8.d.ts → index-CEjvYAUZ.d.ts} +1 -1
- package/dist/{index-B0R5CLPF.d.ts → index-CsYDrQ9R.d.ts} +1 -1
- package/dist/{index-C2cH8OLC.d.ts → index-D31bgBoy.d.ts} +1 -1
- package/dist/{index-BxWCX2pJ.d.ts → index-DFLPv9io.d.ts} +3 -3
- package/dist/index-DGXCnzOL.d.ts +69 -0
- package/dist/{index-BPf_jmME.d.ts → index-DMcf0QeR.d.ts} +3 -3
- package/dist/{index-SWw-WMTO.d.ts → index-DPhQZXYw.d.ts} +3 -3
- package/dist/{index-B-Jla56c.d.ts → index-DmAEpn5E.d.ts} +1 -1
- package/dist/{index-B0yaHi__.d.ts → index-DtZUOyCy.d.ts} +12 -5
- package/dist/{index-BQ3cm7mP.d.ts → index-FeZXsFO-.d.ts} +1 -1
- package/dist/{index-Byan7Dad.d.ts → index-GmoeIuhl.d.ts} +1 -1
- package/dist/{index-ygmRS6Np.d.ts → index-KcCNhdAw.d.ts} +1 -1
- package/dist/{index-BPHqOCfp.d.ts → index-PffxihMx.d.ts} +4 -4
- package/dist/{index-unAZVFGz.d.ts → index-Qdbssopn.d.ts} +2 -2
- package/dist/{index-LHvLg1Pv.d.ts → index-Y4H4X6Vy.d.ts} +88 -82
- package/dist/{index-Xc3q9f84.d.ts → index-YKCx03zD.d.ts} +2 -2
- package/dist/{index-BXDqyk2_.d.ts → index-gu5EvbE0.d.ts} +170 -2
- package/dist/{index-BFZxzCYu.d.ts → index-o00Upzjp.d.ts} +3 -3
- package/dist/{index-BEZ4ezJk.d.ts → index-ql9ApSTF.d.ts} +7 -0
- package/dist/index.d.ts +39 -37
- package/dist/index.js +31 -30
- package/dist/landing-Bs0aMIsR.js +2049 -0
- package/dist/{loadCatalog-DFyDz_4e.d.ts → loadCatalog-BJwcyX8i.d.ts} +2 -0
- package/dist/{loadCatalog-C3MSknfx.js → loadCatalog-C1kms5sO.js} +5 -1
- package/dist/locale/index.d.ts +2 -2
- package/dist/locale/index.js +3 -3
- package/dist/{locale-OCGw4bi6.js → locale-CHhsd9Mq.js} +1 -1
- package/dist/motionTokenDefaults-EFzpiAF5.js +38 -0
- package/dist/tokenName-0U-WEH09.js +36 -0
- package/dist/{typeahead-RkZw0Ktn.js → typeahead-BgfLP7vR.js} +2 -0
- package/dist/{index-DbFIQDoa.d.ts → types-C1ydeFiu.d.ts} +43 -65
- package/dist/{types-uWxXh1Jm.d.ts → types-fRasDCe4.d.ts} +47 -6
- package/dist/useAnimatedLayout-C0koWm4a.d.ts +56 -0
- package/dist/{useAsyncSource-Gk0VtE7_.js → useAsyncSource-7GTcK8ep.js} +31 -1
- package/dist/{useAsyncSource-aGzrvRkI.d.ts → useAsyncSource-DbG2FSuI.d.ts} +19 -2
- package/dist/{useCombobox-D374_pT8.js → useCombobox-DIR9yoEu.js} +150 -3
- package/dist/{useTypeaheadAnnouncement-CSikDlpK.js → useTypeaheadMenuConfig--4f7jR6G.js} +264 -20
- package/package.json +1 -1
- package/styles/motion.css +10 -0
- package/styles/selector.css +10 -0
- package/styles/table.css +19 -0
- package/dist/composables-CCsHfpCS.js +0 -1256
- package/dist/{Chat-PEkZTrQE.js → Chat-Wq7e98zS.js} +1 -1
- package/dist/{CodeBlock-9Lfec8C8.js → CodeBlock-CLVXVlB7.js} +1 -1
- package/dist/{DateInput-kXAc_r5m.js → DateInput-BitZfGEY.js} +1 -1
- package/dist/{DateRangeInput-DW7IzFQM.js → DateRangeInput-kxXBsUTU.js} +1 -1
|
@@ -1,4 +1,100 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { p as isImeKeyEvent } from "./interactionModality-B5dR7nnb.js";
|
|
2
|
+
import { computed, nextTick, onScopeDispose, ref, useId, watch } from "vue";
|
|
3
|
+
//#region src/composables/internal/comboboxFieldProps.ts
|
|
4
|
+
function hasModifier(event) {
|
|
5
|
+
return event.altKey || event.ctrlKey || event.metaKey || event.shiftKey;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* 调用方自己渲染输入框、列表和选项时,把组合框语义、按键和指针模型接上去的属性生成器。
|
|
9
|
+
* 焦点始终留在输入框里,高亮的选项由 `aria-activedescendant` 指出;输入框保留列表用不到的所有按键。
|
|
10
|
+
*/
|
|
11
|
+
function createComboboxFieldProps(host) {
|
|
12
|
+
const getItemId = (index) => `${host.listboxId}-option-${index}`;
|
|
13
|
+
/** 列表只在有选项时才渲染:打开了但一个选项也没有时显示的是调用方的空状态,它不是 listbox。 */
|
|
14
|
+
const isShown = () => host.isOpen.value && host.options.value.length > 0;
|
|
15
|
+
function enabledIndices() {
|
|
16
|
+
return host.options.value.flatMap((option, index) => option.disabled ? [] : [index]);
|
|
17
|
+
}
|
|
18
|
+
function onFieldKeyDown(event) {
|
|
19
|
+
if (!host.isEnabled.value || isImeKeyEvent(event) || hasModifier(event) && event.key !== "Escape") return;
|
|
20
|
+
const enabled = enabledIndices();
|
|
21
|
+
if (!host.isOpen.value) {
|
|
22
|
+
if (event.key === "ArrowDown" && host.options.value.length > 0) {
|
|
23
|
+
event.preventDefault();
|
|
24
|
+
host.open();
|
|
25
|
+
host.activeIndex.value = enabled[0] ?? -1;
|
|
26
|
+
}
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
switch (event.key) {
|
|
30
|
+
case "ArrowDown":
|
|
31
|
+
case "ArrowUp": {
|
|
32
|
+
event.preventDefault();
|
|
33
|
+
if (enabled.length === 0) break;
|
|
34
|
+
const position = enabled.indexOf(host.activeIndex.value);
|
|
35
|
+
const next = event.key === "ArrowDown" ? (position + 1) % enabled.length : position < 0 ? enabled.length - 1 : (position - 1 + enabled.length) % enabled.length;
|
|
36
|
+
host.activeIndex.value = enabled[next];
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
case "Enter": {
|
|
40
|
+
const option = host.activeIndex.value >= 0 ? host.options.value[host.activeIndex.value] : void 0;
|
|
41
|
+
if (option && !option.disabled) {
|
|
42
|
+
event.preventDefault();
|
|
43
|
+
host.select(option.value);
|
|
44
|
+
}
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
case "Escape":
|
|
48
|
+
event.preventDefault();
|
|
49
|
+
host.close();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
function getFieldProps(handlers = {}) {
|
|
53
|
+
const shown = isShown();
|
|
54
|
+
const active = host.activeIndex.value;
|
|
55
|
+
return {
|
|
56
|
+
"role": "combobox",
|
|
57
|
+
"aria-autocomplete": "list",
|
|
58
|
+
"aria-expanded": shown,
|
|
59
|
+
"aria-controls": shown ? host.listboxId : void 0,
|
|
60
|
+
"aria-activedescendant": shown && active >= 0 && active < host.options.value.length ? getItemId(active) : void 0,
|
|
61
|
+
"onKeydown": (event) => {
|
|
62
|
+
onFieldKeyDown(event);
|
|
63
|
+
if (!event.defaultPrevented) handlers.onKeydown?.(event);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function getListboxProps() {
|
|
68
|
+
return {
|
|
69
|
+
id: host.listboxId,
|
|
70
|
+
role: "listbox",
|
|
71
|
+
onMousedown: (event) => event.preventDefault()
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
function getOptionProps(index) {
|
|
75
|
+
const option = host.options.value[index];
|
|
76
|
+
const isDisabled = option?.disabled === true;
|
|
77
|
+
return {
|
|
78
|
+
"id": getItemId(index),
|
|
79
|
+
"role": "option",
|
|
80
|
+
"aria-selected": index === host.activeIndex.value,
|
|
81
|
+
...isDisabled ? { "aria-disabled": true } : {},
|
|
82
|
+
"onMousemove": () => {
|
|
83
|
+
if (option && !isDisabled && index !== host.activeIndex.value) host.activeIndex.value = index;
|
|
84
|
+
},
|
|
85
|
+
"onClick": () => {
|
|
86
|
+
if (option && !isDisabled) host.select(option.value);
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
return {
|
|
91
|
+
getItemId,
|
|
92
|
+
getFieldProps,
|
|
93
|
+
getListboxProps,
|
|
94
|
+
getOptionProps
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
//#endregion
|
|
2
98
|
//#region src/composables/internal/typeaheadText.ts
|
|
3
99
|
/**
|
|
4
100
|
* 类型跳转(type-to-select)用的文字折叠:忽略大小写、组合符号(U+0300–U+036F)、
|
|
@@ -21,6 +117,15 @@ function foldTypeaheadText(text) {
|
|
|
21
117
|
function startsWithTypeahead(label, prefix) {
|
|
22
118
|
return foldTypeaheadText(label).startsWith(prefix);
|
|
23
119
|
}
|
|
120
|
+
/**
|
|
121
|
+
* 按键是不是 Control 或 Command 快捷键,而不是键入的字符。
|
|
122
|
+
* Windows 上 AltGr 也会报 Control,同时带 AltGraph 修饰;它给出的是用户键入的字母,比如 ł。
|
|
123
|
+
* 单独的 Alt 不算:macOS 的 Option 加字母会组出字符(Option+a 得到 å)。
|
|
124
|
+
*/
|
|
125
|
+
function isShortcutChord(event) {
|
|
126
|
+
if (event.metaKey) return true;
|
|
127
|
+
return event.ctrlKey && event.getModifierState?.("AltGraph") !== true;
|
|
128
|
+
}
|
|
24
129
|
//#endregion
|
|
25
130
|
//#region src/composables/useCombobox.ts
|
|
26
131
|
const TYPEAHEAD_RESET_MS = 750;
|
|
@@ -29,9 +134,11 @@ const TYPEAHEAD_RESET_MS = 750;
|
|
|
29
134
|
* 供 Selector、MultiSelector、Typeahead、CommandPalette 等组件复用。
|
|
30
135
|
*/
|
|
31
136
|
function useCombobox(options) {
|
|
32
|
-
const { options: optionsList, modelValue, isEnabled = ref(true), isSearchable = ref(false), onChange, onOpenChange } = options;
|
|
137
|
+
const { options: optionsList, modelValue, isEnabled = ref(true), isSearchable = ref(false), onChange, onOpenChange, listboxId = `astryx-combobox-${useId()}` } = options;
|
|
33
138
|
const isOpen = ref(false);
|
|
34
139
|
const activeIndex = ref(-1);
|
|
140
|
+
/** 查询变化带来的列表变化由查询自己处理高亮,不走「跟着选项走」。 */
|
|
141
|
+
let queryChanging = false;
|
|
35
142
|
const searchQuery = ref("");
|
|
36
143
|
let typeaheadBuffer = "";
|
|
37
144
|
let typeaheadTimer;
|
|
@@ -65,6 +172,7 @@ function useCombobox(options) {
|
|
|
65
172
|
else open();
|
|
66
173
|
}
|
|
67
174
|
function select(value) {
|
|
175
|
+
if (!isEnabled.value) return;
|
|
68
176
|
onChange(value);
|
|
69
177
|
close();
|
|
70
178
|
}
|
|
@@ -106,6 +214,11 @@ function useCombobox(options) {
|
|
|
106
214
|
}
|
|
107
215
|
function setSearchQuery(query) {
|
|
108
216
|
searchQuery.value = query;
|
|
217
|
+
queryChanging = true;
|
|
218
|
+
nextTick(() => {
|
|
219
|
+
queryChanging = false;
|
|
220
|
+
});
|
|
221
|
+
activeIndex.value = -1;
|
|
109
222
|
if (query && filteredOptions.value.length > 0) highlightFirst();
|
|
110
223
|
}
|
|
111
224
|
function jumpToMatch(char) {
|
|
@@ -177,7 +290,7 @@ function useCombobox(options) {
|
|
|
177
290
|
selectHighlighted();
|
|
178
291
|
}
|
|
179
292
|
break;
|
|
180
|
-
default: if (!isSearchInput && event.key.length === 1 && !event
|
|
293
|
+
default: if (!isSearchInput && event.key.length === 1 && !isShortcutChord(event)) {
|
|
181
294
|
event.preventDefault();
|
|
182
295
|
if (!isOpen.value) open();
|
|
183
296
|
jumpToMatch(event.key);
|
|
@@ -190,6 +303,30 @@ function useCombobox(options) {
|
|
|
190
303
|
if (index >= 0) activeIndex.value = index;
|
|
191
304
|
}
|
|
192
305
|
});
|
|
306
|
+
watch(filteredOptions, (next, previous) => {
|
|
307
|
+
if (queryChanging || !isOpen.value || activeIndex.value < 0 || next === previous) return;
|
|
308
|
+
const enabledIndexOf = (value) => value === void 0 ? -1 : next.findIndex((option) => option.value === value && !option.disabled);
|
|
309
|
+
const stayed = enabledIndexOf(previous[activeIndex.value]?.value);
|
|
310
|
+
if (stayed >= 0) {
|
|
311
|
+
activeIndex.value = stayed;
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
for (let after = activeIndex.value + 1; after < previous.length; after++) {
|
|
315
|
+
const found = enabledIndexOf(previous[after]?.value);
|
|
316
|
+
if (found >= 0) {
|
|
317
|
+
activeIndex.value = found;
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
for (let before = Math.min(activeIndex.value, previous.length) - 1; before >= 0; before--) {
|
|
322
|
+
const found = enabledIndexOf(previous[before]?.value);
|
|
323
|
+
if (found >= 0) {
|
|
324
|
+
activeIndex.value = found;
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
activeIndex.value = -1;
|
|
329
|
+
});
|
|
193
330
|
onScopeDispose(() => {
|
|
194
331
|
if (typeaheadTimer !== void 0) clearTimeout(typeaheadTimer);
|
|
195
332
|
});
|
|
@@ -198,6 +335,16 @@ function useCombobox(options) {
|
|
|
198
335
|
activeIndex,
|
|
199
336
|
searchQuery,
|
|
200
337
|
filteredOptions,
|
|
338
|
+
...createComboboxFieldProps({
|
|
339
|
+
listboxId,
|
|
340
|
+
isOpen,
|
|
341
|
+
isEnabled,
|
|
342
|
+
activeIndex,
|
|
343
|
+
options: filteredOptions,
|
|
344
|
+
open,
|
|
345
|
+
close,
|
|
346
|
+
select: (value) => select(value)
|
|
347
|
+
}),
|
|
201
348
|
open,
|
|
202
349
|
close,
|
|
203
350
|
toggle,
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { t as characterCount } from "./characters-wTnzjkkR.js";
|
|
2
|
-
import { t as useAnnounce } from "./announce-GU01Oix2.js";
|
|
3
|
-
import { n as useAsyncSource } from "./useAsyncSource-Gk0VtE7_.js";
|
|
4
|
-
import { t as useCombobox } from "./useCombobox-D374_pT8.js";
|
|
5
2
|
import { n as isDevBuild, t as devPropError } from "./devBuild-G249YcdZ.js";
|
|
6
|
-
import { t as
|
|
3
|
+
import { t as devWarn } from "./useDevWarning-B2fsk2B-.js";
|
|
4
|
+
import { t as useAnnounce } from "./announce-GU01Oix2.js";
|
|
5
|
+
import { n as useAsyncSource } from "./useAsyncSource-7GTcK8ep.js";
|
|
6
|
+
import { t as useCombobox } from "./useCombobox-DIR9yoEu.js";
|
|
7
|
+
import { t as _sfc_main$3 } from "./Spinner-DEVPDsD0.js";
|
|
7
8
|
import { t as createStillPointerGate } from "./stillPointerGate-0vdn-hSa.js";
|
|
8
9
|
import { i as isOptionAction, n as searchResultMessage, r as OptionAction, t as useOptionActionGrid } from "./useOptionActionGrid-C7ibYM_A.js";
|
|
9
|
-
import { Fragment, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createTextVNode, createVNode, defineComponent, normalizeClass, openBlock, ref, renderList, renderSlot, toDisplayString, toValue, unref, watch, withModifiers } from "vue";
|
|
10
|
+
import { Fragment, Teleport, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createSlots, createTextVNode, createVNode, defineComponent, guardReactiveProps, h, mergeProps, nextTick, normalizeClass, normalizeProps, normalizeStyle, openBlock, ref, renderList, renderSlot, toDisplayString, toValue, unref, useSlots, useTemplateRef, vShow, watch, withCtx, withDirectives, withModifiers } from "vue";
|
|
11
|
+
import "../styles/layer.css";
|
|
10
12
|
import "../styles/typeahead.css";
|
|
11
13
|
//#region src/Typeahead/queryLength.ts
|
|
12
14
|
/**
|
|
@@ -49,6 +51,11 @@ function useTypeaheadMenu(options) {
|
|
|
49
51
|
if (source === previous || asyncSource.status.value !== "loading") return;
|
|
50
52
|
asyncSource.status.value = "idle";
|
|
51
53
|
}, { flush: "sync" });
|
|
54
|
+
const isSettled = computed(() => asyncSource.status.value !== "loading" && asyncSource.searchedQuery.value === query.value);
|
|
55
|
+
const menuStatus = computed(() => {
|
|
56
|
+
const status = asyncSource.status.value;
|
|
57
|
+
return status === "empty" && asyncSource.searchedQuery.value !== query.value ? "idle" : status;
|
|
58
|
+
});
|
|
52
59
|
const matchCount = computed(() => {
|
|
53
60
|
if (belowMinQueryLength.value) return 0;
|
|
54
61
|
const excluded = new Set(toValue(options.excludeIds) ?? []);
|
|
@@ -106,6 +113,14 @@ function useTypeaheadMenu(options) {
|
|
|
106
113
|
const current = list[combobox.activeIndex.value];
|
|
107
114
|
if (!current || current.disabled) combobox.highlightFirst();
|
|
108
115
|
});
|
|
116
|
+
watch([
|
|
117
|
+
isSettled,
|
|
118
|
+
() => asyncSource.status.value,
|
|
119
|
+
() => entries.value.length
|
|
120
|
+
], () => {
|
|
121
|
+
if (!combobox.isOpen.value || !isSettled.value || query.value.trim() !== "") return;
|
|
122
|
+
if ((asyncSource.status.value === "empty" || asyncSource.status.value === "error") && entries.value.length === 0) close();
|
|
123
|
+
});
|
|
109
124
|
/**
|
|
110
125
|
* 太短的查询没东西可展示,此时不让下拉打开。
|
|
111
126
|
* 只有从文字自己派生的条目(比如「创建 xxx」)还值得看一眼。
|
|
@@ -134,14 +149,27 @@ function useTypeaheadMenu(options) {
|
|
|
134
149
|
if (value.length > 0 || toValue(options.showOnFocus)) open();
|
|
135
150
|
else close();
|
|
136
151
|
}
|
|
152
|
+
function resetQuery() {
|
|
153
|
+
const changed = query.value !== "";
|
|
154
|
+
query.value = "";
|
|
155
|
+
if (changed) options.onQueryChange?.("");
|
|
156
|
+
}
|
|
137
157
|
function selectHighlighted() {
|
|
138
158
|
const entry = entries.value[combobox.activeIndex.value];
|
|
139
159
|
if (entry && !entry.disabled) options.onSelect(entry);
|
|
140
160
|
}
|
|
141
161
|
function onKeyDown(event) {
|
|
142
162
|
if (event.isComposing || event.key === "Process") return;
|
|
143
|
-
if (toValue(options.disabled)) return;
|
|
144
163
|
const openNow = combobox.isOpen.value;
|
|
164
|
+
if (toValue(options.disabled)) {
|
|
165
|
+
if (openNow && event.key === "Enter") event.preventDefault();
|
|
166
|
+
if (openNow && event.key === "Escape") {
|
|
167
|
+
event.preventDefault();
|
|
168
|
+
close();
|
|
169
|
+
}
|
|
170
|
+
if (openNow && event.key === "Tab") close();
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
145
173
|
const list = entries.value;
|
|
146
174
|
switch (event.key) {
|
|
147
175
|
case "ArrowDown":
|
|
@@ -193,7 +221,6 @@ function useTypeaheadMenu(options) {
|
|
|
193
221
|
if (openNow) {
|
|
194
222
|
event.preventDefault();
|
|
195
223
|
close();
|
|
196
|
-
options.onEscape?.();
|
|
197
224
|
}
|
|
198
225
|
break;
|
|
199
226
|
case "Tab": if (openNow) close();
|
|
@@ -211,8 +238,11 @@ function useTypeaheadMenu(options) {
|
|
|
211
238
|
error: asyncSource.error,
|
|
212
239
|
activeId,
|
|
213
240
|
belowMinQueryLength,
|
|
241
|
+
isSettled,
|
|
242
|
+
menuStatus,
|
|
214
243
|
matchCount,
|
|
215
244
|
setQuery,
|
|
245
|
+
resetQuery,
|
|
216
246
|
open,
|
|
217
247
|
close,
|
|
218
248
|
onKeyDown
|
|
@@ -254,7 +284,7 @@ function useLatchedOptionGrid(options) {
|
|
|
254
284
|
}
|
|
255
285
|
//#endregion
|
|
256
286
|
//#region src/Typeahead/TypeaheadItem.vue
|
|
257
|
-
const _hoisted_1$
|
|
287
|
+
const _hoisted_1$2 = ["data-disabled"];
|
|
258
288
|
const _hoisted_2$1 = {
|
|
259
289
|
key: 0,
|
|
260
290
|
class: "astryx-typeahead-item-icon",
|
|
@@ -266,7 +296,7 @@ const _hoisted_5$1 = {
|
|
|
266
296
|
key: 0,
|
|
267
297
|
class: "astryx-typeahead-option-description"
|
|
268
298
|
};
|
|
269
|
-
const _sfc_main$
|
|
299
|
+
const _sfc_main$2 = /*@__PURE__*/ defineComponent({
|
|
270
300
|
name: "AstryxTypeaheadItem",
|
|
271
301
|
__name: "TypeaheadItem",
|
|
272
302
|
props: {
|
|
@@ -282,16 +312,16 @@ const _sfc_main$1 = /*@__PURE__*/ defineComponent({
|
|
|
282
312
|
return openBlock(), createElementBlock("span", {
|
|
283
313
|
class: "astryx-typeahead-item",
|
|
284
314
|
"data-disabled": props.isDisabled || props.item.disabled || void 0
|
|
285
|
-
}, [_ctx.$slots.icon ? (openBlock(), createElementBlock("span", _hoisted_2$1, [renderSlot(_ctx.$slots, "icon")])) : createCommentVNode("v-if", true), createElementVNode("span", _hoisted_3$1, [createElementVNode("span", _hoisted_4$1, toDisplayString(props.item.label), 1), props.description ?? props.item.description ? (openBlock(), createElementBlock("span", _hoisted_5$1, toDisplayString(props.description ?? props.item.description), 1)) : createCommentVNode("v-if", true)])], 8, _hoisted_1$
|
|
315
|
+
}, [_ctx.$slots.icon ? (openBlock(), createElementBlock("span", _hoisted_2$1, [renderSlot(_ctx.$slots, "icon")])) : createCommentVNode("v-if", true), createElementVNode("span", _hoisted_3$1, [createElementVNode("span", _hoisted_4$1, toDisplayString(props.item.label), 1), props.description ?? props.item.description ? (openBlock(), createElementBlock("span", _hoisted_5$1, toDisplayString(props.description ?? props.item.description), 1)) : createCommentVNode("v-if", true)])], 8, _hoisted_1$2);
|
|
286
316
|
};
|
|
287
317
|
}
|
|
288
318
|
});
|
|
289
319
|
//#endregion
|
|
290
320
|
//#region src/Typeahead/TypeaheadMenu.vue
|
|
291
|
-
const _hoisted_1 = {
|
|
321
|
+
const _hoisted_1$1 = {
|
|
292
322
|
key: 0,
|
|
293
323
|
class: "astryx-typeahead-state",
|
|
294
|
-
|
|
324
|
+
"aria-hidden": "true"
|
|
295
325
|
};
|
|
296
326
|
const _hoisted_2 = {
|
|
297
327
|
key: 1,
|
|
@@ -316,6 +346,9 @@ const _hoisted_7 = [
|
|
|
316
346
|
"aria-selected",
|
|
317
347
|
"aria-disabled",
|
|
318
348
|
"data-option-id",
|
|
349
|
+
"data-highlighted",
|
|
350
|
+
"data-selected",
|
|
351
|
+
"data-disabled",
|
|
319
352
|
"onMouseenter",
|
|
320
353
|
"onClick"
|
|
321
354
|
];
|
|
@@ -344,7 +377,7 @@ const _hoisted_13 = {
|
|
|
344
377
|
fill: "none",
|
|
345
378
|
"aria-hidden": "true"
|
|
346
379
|
};
|
|
347
|
-
const _sfc_main = /*@__PURE__*/ defineComponent({
|
|
380
|
+
const _sfc_main$1 = /*@__PURE__*/ defineComponent({
|
|
348
381
|
name: "AstryxTypeaheadMenu",
|
|
349
382
|
__name: "TypeaheadMenu",
|
|
350
383
|
props: {
|
|
@@ -404,10 +437,10 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
|
|
|
404
437
|
class: "astryx-typeahead-menu",
|
|
405
438
|
role: "presentation",
|
|
406
439
|
onMousemove: _cache[3] || (_cache[3] = (...args) => unref(pointerGate).track && unref(pointerGate).track(...args))
|
|
407
|
-
}, [props.status === "loading" && props.entries.length === 0 ? (openBlock(), createElementBlock("div", _hoisted_1, [createVNode(_sfc_main$
|
|
440
|
+
}, [props.status === "loading" && props.entries.length === 0 ? (openBlock(), createElementBlock("div", _hoisted_1$1, [createVNode(_sfc_main$3, {
|
|
408
441
|
size: "sm",
|
|
409
442
|
label: props.loadingText
|
|
410
|
-
}, null, 8, ["label"])])) : props.status === "error" ? (openBlock(), createElementBlock("div", _hoisted_2, toDisplayString(props.errorText), 1)) : props.entries.length === 0 ? (openBlock(), createElementBlock("div", {
|
|
443
|
+
}, null, 8, ["label"])])) : props.status === "error" ? (openBlock(), createElementBlock("div", _hoisted_2, toDisplayString(props.errorText), 1)) : props.entries.length === 0 && props.status !== "idle" ? (openBlock(), createElementBlock("div", {
|
|
411
444
|
key: 2,
|
|
412
445
|
class: "astryx-typeahead-state",
|
|
413
446
|
role: props.grid ? "presentation" : "option",
|
|
@@ -435,6 +468,9 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
|
|
|
435
468
|
"aria-selected": row.entry.selected ? "true" : "false",
|
|
436
469
|
"aria-disabled": row.entry.disabled || void 0,
|
|
437
470
|
"data-option-id": row.entry.id,
|
|
471
|
+
"data-highlighted": row.index === props.activeIndex ? "highlighted" : void 0,
|
|
472
|
+
"data-selected": row.entry.selected ? "selected" : void 0,
|
|
473
|
+
"data-disabled": row.entry.disabled ? "disabled" : void 0,
|
|
438
474
|
tabindex: "-1",
|
|
439
475
|
onMousedown: _cache[2] || (_cache[2] = withModifiers(() => {}, ["prevent"])),
|
|
440
476
|
onMouseenter: ($event) => onRowEnter($event, row.index),
|
|
@@ -452,7 +488,7 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
|
|
|
452
488
|
entry: row.entry,
|
|
453
489
|
isActive: row.index === props.activeIndex,
|
|
454
490
|
isSelected: Boolean(row.entry.selected)
|
|
455
|
-
}, () => [createVNode(_sfc_main$
|
|
491
|
+
}, () => [createVNode(_sfc_main$2, {
|
|
456
492
|
item: {
|
|
457
493
|
id: row.entry.id,
|
|
458
494
|
label: row.entry.label,
|
|
@@ -483,7 +519,7 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
|
|
|
483
519
|
entry: row.entry,
|
|
484
520
|
isActive: row.index === props.activeIndex,
|
|
485
521
|
isSelected: Boolean(row.entry.selected)
|
|
486
|
-
}, () => [createVNode(_sfc_main$
|
|
522
|
+
}, () => [createVNode(_sfc_main$2, {
|
|
487
523
|
item: {
|
|
488
524
|
id: row.entry.id,
|
|
489
525
|
label: row.entry.label,
|
|
@@ -507,6 +543,117 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
|
|
|
507
543
|
}
|
|
508
544
|
});
|
|
509
545
|
//#endregion
|
|
546
|
+
//#region src/Typeahead/TypeaheadPopup.vue
|
|
547
|
+
const _hoisted_1 = [
|
|
548
|
+
"id",
|
|
549
|
+
"role",
|
|
550
|
+
"aria-label",
|
|
551
|
+
"data-placement"
|
|
552
|
+
];
|
|
553
|
+
const _sfc_main = /*@__PURE__*/ defineComponent({
|
|
554
|
+
name: "AstryxTypeaheadPopup",
|
|
555
|
+
inheritAttrs: false,
|
|
556
|
+
__name: "TypeaheadPopup",
|
|
557
|
+
props: {
|
|
558
|
+
id: {},
|
|
559
|
+
isOpen: { type: Boolean },
|
|
560
|
+
config: {},
|
|
561
|
+
label: {},
|
|
562
|
+
grid: { type: Boolean },
|
|
563
|
+
placement: {},
|
|
564
|
+
popupStyle: {},
|
|
565
|
+
popupClass: {},
|
|
566
|
+
entries: {},
|
|
567
|
+
activeIndex: {},
|
|
568
|
+
actionIndex: {},
|
|
569
|
+
status: {},
|
|
570
|
+
emptyText: {},
|
|
571
|
+
loadingText: {},
|
|
572
|
+
errorText: {},
|
|
573
|
+
query: {},
|
|
574
|
+
isSettled: { type: Boolean }
|
|
575
|
+
},
|
|
576
|
+
emits: [
|
|
577
|
+
"select",
|
|
578
|
+
"highlight",
|
|
579
|
+
"close",
|
|
580
|
+
"keydown"
|
|
581
|
+
],
|
|
582
|
+
setup(__props, { expose: __expose, emit: __emit }) {
|
|
583
|
+
const props = __props;
|
|
584
|
+
const emit = __emit;
|
|
585
|
+
const slots = useSlots();
|
|
586
|
+
const root = useTemplateRef("root");
|
|
587
|
+
__expose({ el: root });
|
|
588
|
+
const isDialog = computed(() => props.config?.role === "dialog");
|
|
589
|
+
const dialogLabel = computed(() => props.config?.role === "dialog" ? props.config.label : void 0);
|
|
590
|
+
/** listbox 角色带 `menu` 插槽:浮层本身不是列表,列表由插槽里的 `listbox` 放在想放的位置。 */
|
|
591
|
+
const wrapsList = computed(() => !isDialog.value && slots.menu != null);
|
|
592
|
+
const listRole = computed(() => props.grid ? "grid" : "listbox");
|
|
593
|
+
const isBusy = computed(() => props.status === "loading");
|
|
594
|
+
const isEmptySearch = computed(() => props.status === "empty" && props.isSettled && props.query.trim() !== "");
|
|
595
|
+
const menuProps = computed(() => ({
|
|
596
|
+
entries: props.entries,
|
|
597
|
+
activeIndex: props.activeIndex,
|
|
598
|
+
grid: props.grid,
|
|
599
|
+
actionIndex: props.actionIndex,
|
|
600
|
+
status: props.status,
|
|
601
|
+
listboxId: props.id,
|
|
602
|
+
emptyText: props.emptyText,
|
|
603
|
+
loadingText: props.loadingText,
|
|
604
|
+
errorText: props.errorText,
|
|
605
|
+
onSelect: (id) => emit("select", id),
|
|
606
|
+
onHighlight: (index) => emit("highlight", index)
|
|
607
|
+
}));
|
|
608
|
+
function menuSlots() {
|
|
609
|
+
return {
|
|
610
|
+
...slots.item ? { item: slots.item } : {},
|
|
611
|
+
...slots.empty ? { empty: slots.empty } : {}
|
|
612
|
+
};
|
|
613
|
+
}
|
|
614
|
+
/** 结果列表:唯一带 listbox 角色的元素,菜单插槽围着它放别的信息。 */
|
|
615
|
+
const Listbox = defineComponent({
|
|
616
|
+
name: "AstryxTypeaheadListbox",
|
|
617
|
+
setup: () => () => h("div", {
|
|
618
|
+
"id": props.id,
|
|
619
|
+
"role": listRole.value,
|
|
620
|
+
"aria-label": props.label
|
|
621
|
+
}, [h(_sfc_main$1, menuProps.value, menuSlots())])
|
|
622
|
+
});
|
|
623
|
+
return (_ctx, _cache) => {
|
|
624
|
+
return openBlock(), createBlock(Teleport, { to: "body" }, [createCommentVNode(" eslint-disable-next-line vue-a11y/no-static-element-interactions -- Escape 关 dialog 菜单:焦点在菜单里的任何地方按下都要接到。 "), withDirectives(createElementVNode("div", {
|
|
625
|
+
id: isDialog.value || !wrapsList.value ? __props.id : void 0,
|
|
626
|
+
ref_key: "root",
|
|
627
|
+
ref: root,
|
|
628
|
+
class: normalizeClass(["astryx-typeahead-listbox astryx-layer", __props.popupClass]),
|
|
629
|
+
role: isDialog.value ? "dialog" : wrapsList.value ? void 0 : listRole.value,
|
|
630
|
+
"aria-label": isDialog.value ? dialogLabel.value : wrapsList.value ? void 0 : __props.label,
|
|
631
|
+
"data-placement": __props.placement,
|
|
632
|
+
style: normalizeStyle(__props.popupStyle),
|
|
633
|
+
tabindex: "-1",
|
|
634
|
+
onKeydown: _cache[0] || (_cache[0] = ($event) => emit("keydown", $event))
|
|
635
|
+
}, [isDialog.value ? renderSlot(_ctx.$slots, "menu", {
|
|
636
|
+
query: __props.query,
|
|
637
|
+
close: () => emit("close")
|
|
638
|
+
}, void 0, void 0, 0) : wrapsList.value ? renderSlot(_ctx.$slots, "menu", {
|
|
639
|
+
listbox: unref(Listbox),
|
|
640
|
+
query: __props.query,
|
|
641
|
+
isBusy: isBusy.value,
|
|
642
|
+
isEmptySearch: isEmptySearch.value,
|
|
643
|
+
close: () => emit("close")
|
|
644
|
+
}, void 0, void 0, 1) : (openBlock(), createBlock(_sfc_main$1, normalizeProps(mergeProps({ key: 2 }, menuProps.value)), createSlots({ _: 2 }, [_ctx.$slots.item ? {
|
|
645
|
+
name: "item",
|
|
646
|
+
fn: withCtx((slotProps) => [renderSlot(_ctx.$slots, "item", normalizeProps(guardReactiveProps(slotProps)))]),
|
|
647
|
+
key: "0"
|
|
648
|
+
} : void 0, _ctx.$slots.empty ? {
|
|
649
|
+
name: "empty",
|
|
650
|
+
fn: withCtx(() => [renderSlot(_ctx.$slots, "empty")]),
|
|
651
|
+
key: "1"
|
|
652
|
+
} : void 0]), 1040))], 46, _hoisted_1), [[vShow, __props.isOpen]])]);
|
|
653
|
+
};
|
|
654
|
+
}
|
|
655
|
+
});
|
|
656
|
+
//#endregion
|
|
510
657
|
//#region src/Typeahead/useTypeaheadAnnouncement.ts
|
|
511
658
|
/**
|
|
512
659
|
* 输入了文字、搜索落定之后,念一句结果数(点名每一条匹配,包括超出 `maxMenuItems`
|
|
@@ -519,7 +666,7 @@ function useTypeaheadAnnouncement(options) {
|
|
|
519
666
|
const createRows = menu.entries.value.filter((entry) => entry.create).length;
|
|
520
667
|
return searchResultMessage({
|
|
521
668
|
isOpen: menu.combobox.isOpen.value,
|
|
522
|
-
isLoading: menu.
|
|
669
|
+
isLoading: !menu.isSettled.value,
|
|
523
670
|
query: menu.query.value,
|
|
524
671
|
matchCount: menu.matchCount.value,
|
|
525
672
|
hasCreateRow: createRows > 0,
|
|
@@ -529,9 +676,106 @@ function useTypeaheadAnnouncement(options) {
|
|
|
529
676
|
});
|
|
530
677
|
});
|
|
531
678
|
watch(message, (next) => {
|
|
532
|
-
if (next)
|
|
679
|
+
if (!next) return;
|
|
680
|
+
options.settleBusy?.();
|
|
681
|
+
announce(next);
|
|
533
682
|
});
|
|
534
683
|
return message;
|
|
535
684
|
}
|
|
536
685
|
//#endregion
|
|
537
|
-
|
|
686
|
+
//#region src/Typeahead/useTypeaheadMenuConfig.ts
|
|
687
|
+
const FOCUSABLE = "a[href], button:not([disabled]), input:not([disabled]):not([type=\"hidden\"]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex=\"-1\"])";
|
|
688
|
+
/**
|
|
689
|
+
* 菜单的角色:结果列表(listbox)或会拿走焦点的内容(dialog),以及用 `open()` 打开它的方法。
|
|
690
|
+
*
|
|
691
|
+
* - dialog 只能由 `open()` 打开,输入、聚焦、方向键都不会;打开后焦点进到里面,
|
|
692
|
+
* Escape 或 `close()` 关掉后焦点回到打开它时的元素,那个元素没了就回到输入框。
|
|
693
|
+
* - listbox 的 `open()` 显示结果,需要时先加载。
|
|
694
|
+
* - 在 `change` 里调用 `open()`:这次选择之后菜单保持打开,换成 dialog 时挂在同一个锚点上不闪。
|
|
695
|
+
*/
|
|
696
|
+
function useTypeaheadMenuConfig(options) {
|
|
697
|
+
const isDialog = computed(() => options.config()?.role === "dialog");
|
|
698
|
+
const dialogOpen = ref(false);
|
|
699
|
+
const popupOpen = computed(() => isDialog.value ? dialogOpen.value : options.listbox.isOpen.value);
|
|
700
|
+
let opener = null;
|
|
701
|
+
let requestedInPick = false;
|
|
702
|
+
function popupHolds(element) {
|
|
703
|
+
return element != null && options.popupEl()?.contains(element) === true;
|
|
704
|
+
}
|
|
705
|
+
/** 焦点掉在菜单里、或没处可去时,才送回打开它的元素。点到别处的焦点不抢。 */
|
|
706
|
+
function restoreFocus() {
|
|
707
|
+
const active = document.activeElement;
|
|
708
|
+
if (active != null && active !== document.body && !popupHolds(active)) return;
|
|
709
|
+
const target = opener?.isConnected ? opener : options.returnTarget?.() ?? options.inputEl();
|
|
710
|
+
opener = null;
|
|
711
|
+
target?.focus();
|
|
712
|
+
}
|
|
713
|
+
function focusInside() {
|
|
714
|
+
const popup = options.popupEl();
|
|
715
|
+
(popup?.querySelector(FOCUSABLE) ?? popup)?.focus();
|
|
716
|
+
}
|
|
717
|
+
function open() {
|
|
718
|
+
if (options.isDisabled()) return;
|
|
719
|
+
const active = document.activeElement;
|
|
720
|
+
opener = active instanceof HTMLElement && !popupHolds(active) ? active : null;
|
|
721
|
+
requestedInPick = true;
|
|
722
|
+
nextTick(() => {
|
|
723
|
+
if (options.isDisabled()) return;
|
|
724
|
+
if (isDialog.value) {
|
|
725
|
+
options.listbox.close();
|
|
726
|
+
dialogOpen.value = true;
|
|
727
|
+
nextTick(focusInside);
|
|
728
|
+
} else if (options.canOpenList()) options.listbox.open();
|
|
729
|
+
});
|
|
730
|
+
}
|
|
731
|
+
function close() {
|
|
732
|
+
if (dialogOpen.value) {
|
|
733
|
+
dialogOpen.value = false;
|
|
734
|
+
nextTick(restoreFocus);
|
|
735
|
+
} else options.listbox.close();
|
|
736
|
+
}
|
|
737
|
+
function dismiss() {
|
|
738
|
+
dialogOpen.value = false;
|
|
739
|
+
opener = null;
|
|
740
|
+
}
|
|
741
|
+
watch(isDialog, (dialog) => {
|
|
742
|
+
if (!dialog) dialogOpen.value = false;
|
|
743
|
+
});
|
|
744
|
+
watch(() => options.isDisabled(), (disabled) => {
|
|
745
|
+
if (disabled) dialogOpen.value = false;
|
|
746
|
+
});
|
|
747
|
+
watch(popupOpen, (isOpen) => {
|
|
748
|
+
if (!isOpen || isDialog.value) return;
|
|
749
|
+
nextTick(() => {
|
|
750
|
+
const popup = options.popupEl();
|
|
751
|
+
const list = popup?.querySelector("[role=\"listbox\"], [role=\"grid\"]");
|
|
752
|
+
if (!popup || !list) return;
|
|
753
|
+
if ([...popup.querySelectorAll(FOCUSABLE)].some((control) => !list.contains(control) && control !== popup)) devWarn("Typeahead", "a control sits outside the result list in the menu. Anything a person acts on belongs in the list as a result, so the arrow keys reach it.");
|
|
754
|
+
});
|
|
755
|
+
});
|
|
756
|
+
function closeOnEscape(event) {
|
|
757
|
+
if (event.key !== "Escape" || !isDialog.value || !popupOpen.value) return false;
|
|
758
|
+
event.preventDefault();
|
|
759
|
+
event.stopPropagation();
|
|
760
|
+
close();
|
|
761
|
+
return true;
|
|
762
|
+
}
|
|
763
|
+
return {
|
|
764
|
+
isDialog,
|
|
765
|
+
popupOpen,
|
|
766
|
+
open,
|
|
767
|
+
close,
|
|
768
|
+
closeOnEscape,
|
|
769
|
+
dismiss,
|
|
770
|
+
beginPick: () => {
|
|
771
|
+
requestedInPick = false;
|
|
772
|
+
},
|
|
773
|
+
endPick: () => {
|
|
774
|
+
const requested = requestedInPick;
|
|
775
|
+
requestedInPick = false;
|
|
776
|
+
return requested;
|
|
777
|
+
}
|
|
778
|
+
};
|
|
779
|
+
}
|
|
780
|
+
//#endregion
|
|
781
|
+
export { useLatchedOptionGrid as a, _sfc_main$2 as i, useTypeaheadAnnouncement as n, useTypeaheadMenu as o, _sfc_main as r, useTypeaheadMenuConfig as t };
|
package/package.json
CHANGED
package/styles/motion.css
CHANGED
|
@@ -5,11 +5,21 @@
|
|
|
5
5
|
* their own animations; these names are for later use and for the theme docs.
|
|
6
6
|
* prefers-reduced-motion collapses the distance, scale, and opacity delta to
|
|
7
7
|
* nothing, without rewriting component duration tokens.
|
|
8
|
+
*
|
|
9
|
+
* Reduce Motion splits by pointer, as UIKit does: under
|
|
10
|
+
* `@media (prefers-reduced-motion: reduce) and (pointer: coarse)` a change
|
|
11
|
+
* cross-fades over `--_astryx-reduced-motion-fade-duration` on
|
|
12
|
+
* `--_astryx-reduced-motion-fade-easing`; under
|
|
13
|
+
* `@media (prefers-reduced-motion: reduce) and (not (pointer: coarse))` it
|
|
14
|
+
* lands at once. The fade is a constant, not a theme token (no theme
|
|
15
|
+
* lengthens it); src/motion/reducedMotionCss.ts holds the same values.
|
|
8
16
|
*/
|
|
9
17
|
@layer astryx.reset, astryx.tokens, astryx.base, astryx.components, astryx.overrides;
|
|
10
18
|
|
|
11
19
|
@layer astryx.tokens {
|
|
12
20
|
:root {
|
|
21
|
+
--_astryx-reduced-motion-fade-duration: 200ms;
|
|
22
|
+
--_astryx-reduced-motion-fade-easing: cubic-bezier(0.42, 0, 0.58, 1);
|
|
13
23
|
--astryx-motion-enter-opacity: 0;
|
|
14
24
|
--astryx-motion-exit-opacity: 1;
|
|
15
25
|
--astryx-motion-scale-from: 0.95;
|
package/styles/selector.css
CHANGED
|
@@ -535,6 +535,16 @@
|
|
|
535
535
|
outline: none;
|
|
536
536
|
}
|
|
537
537
|
|
|
538
|
+
/*
|
|
539
|
+
* 幽灵和次要触发器的外框没有边框和聚焦底纹,焦点环画在真正拿到键盘焦点的那一个上:
|
|
540
|
+
* 触发器聚焦时环画在外框,清除按钮聚焦时环画在它自己身上,不会两个一起圈。
|
|
541
|
+
*/
|
|
542
|
+
.astryx-selector-field:is(.is-ghost, [data-variant='secondary']):has(.astryx-selector-trigger:focus-visible),
|
|
543
|
+
.astryx-selector-field:is(.is-ghost, [data-variant='secondary']) .astryx-selector-clear:focus-visible {
|
|
544
|
+
outline: var(--astryx-focus-outline-width, 2px) var(--astryx-focus-outline-style, solid) var(--astryx-focus-outline-color, currentcolor);
|
|
545
|
+
outline-offset: 2px;
|
|
546
|
+
}
|
|
547
|
+
|
|
538
548
|
/* 强制颜色下焦点只剩边框能表达:聚焦(含可聚焦的禁用字段)的边框取系统 Highlight 色。 */
|
|
539
549
|
@layer astryx.components {
|
|
540
550
|
@media (forced-colors: active) {
|