@astryx-vue/core 0.26.1 → 0.28.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/AlertDialog/index.js +1 -1
- package/dist/{AlertDialog-CGGkPG4T.js → AlertDialog-B195FgtL.js} +2 -2
- package/dist/AppShell/index.js +1 -1
- package/dist/{AppShell-DGJgCvS6.js → AppShell-Da255Ktm.js} +3 -3
- 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/Breadcrumbs/index.d.ts +2 -2
- package/dist/Breadcrumbs/index.js +2 -2
- package/dist/{Breadcrumbs-BZsjHn_5.js → Breadcrumbs-CmtcXM4e.js} +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/Center/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/CheckboxList/index.js +1 -1
- package/dist/{CheckboxList-CWHlG8Jq.js → CheckboxList-DGM-cgX5.js} +2 -2
- package/dist/ClickableCard/index.d.ts +1 -1
- package/dist/ClickableCard/index.js +1 -1
- package/dist/Collapsible/index.js +1 -1
- package/dist/{Collapsible-BSRdsb6w.js → Collapsible-B2vrr_YP.js} +2 -2
- package/dist/ComplexSelector/index.js +1 -1
- package/dist/{ComplexSelector-DI3J30Ho.js → ComplexSelector-Dq9esodQ.js} +1 -1
- package/dist/ContextMenu/index.d.ts +2 -2
- package/dist/ContextMenu/index.js +2 -2
- package/dist/{ContextMenu-CVf4OqJP.js → ContextMenu-DB4XcNKf.js} +1 -1
- package/dist/DateInput/index.d.ts +1 -1
- package/dist/DateInput/index.js +1 -1
- package/dist/{DateInput-DK-FI37x.js → DateInput-DNqm49AX.js} +1 -1
- package/dist/DateRangeInput/index.d.ts +1 -1
- package/dist/DateRangeInput/index.js +1 -1
- package/dist/{DateRangeInput-ClriBc4F.js → DateRangeInput-Bch513M0.js} +1 -1
- package/dist/DateTimeInput/index.d.ts +1 -1
- package/dist/DateTimeInput/index.js +1 -1
- package/dist/{DateTimeInput-BdXkBBYi.js → DateTimeInput-BCFgCeNy.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/DropdownMenu/index.d.ts +2 -2
- package/dist/DropdownMenu/index.js +3 -3
- package/dist/{DropdownMenu-CdwEvDld.js → DropdownMenu-D9swCben.js} +3 -3
- package/dist/{DropdownMenu-q5euMYv-.js → DropdownMenu-DlfMGzZ2.js} +3 -33
- package/dist/{DropdownMenuRadioItem.vue-DINRx71W.d.ts → DropdownMenuRadioItem.vue-C8rePTyz.d.ts} +1 -1
- package/dist/HoverCard/index.d.ts +1 -1
- package/dist/InfoTip/index.d.ts +1 -1
- package/dist/InternationalizationProvider/index.d.ts +1 -1
- package/dist/InternationalizationProvider/index.js +1 -1
- package/dist/{InternationalizationProvider-8qllKdVk.js → InternationalizationProvider-CEmlN48L.js} +1 -1
- package/dist/{Item-DUI1Qnnd.js → Item-C8UAQwFQ.js} +193 -111
- package/dist/Link/index.d.ts +1 -1
- package/dist/List/index.d.ts +2 -2
- package/dist/List/index.js +2 -2
- package/dist/{ListItem-C8SqSrU6.js → ListItem-BlrEngDO.js} +11 -3
- package/dist/MetadataList/index.d.ts +1 -1
- package/dist/MoreMenu/index.d.ts +1 -1
- package/dist/MoreMenu/index.js +1 -1
- package/dist/{MoreMenu-DAq29azZ.js → MoreMenu-GPcHAauX.js} +3 -1
- package/dist/MultiSelector/index.d.ts +1 -1
- package/dist/NavItem/index.d.ts +1 -1
- package/dist/NavItem/index.js +1 -1
- package/dist/NumberInput/index.d.ts +1 -1
- package/dist/Outline/index.js +1 -1
- package/dist/{Outline-DvQbXc_H.js → Outline-DI9MZnuQ.js} +106 -50
- 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-CRrou1P-.js → Pagination-BNPBvFW1.js} +2 -2
- package/dist/Popover/index.d.ts +1 -1
- package/dist/Popover/index.js +1 -1
- package/dist/{Popover-sERt08TR.js → Popover-MJQZog5m.js} +2 -2
- package/dist/PowerSearch/index.d.ts +1 -1
- package/dist/PowerSearch/index.js +1 -1
- package/dist/{PowerSearch-CiVIW13b.js → PowerSearch-Bv-yUo6C.js} +10 -8
- 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/SelectableCard/index.d.ts +1 -1
- package/dist/Selector/index.d.ts +1 -1
- package/dist/Selector/index.js +1 -1
- package/dist/SideNav/index.d.ts +1 -1
- package/dist/SideNav/index.js +2 -2
- package/dist/{SideNav-CHSwzwTt.js → SideNav-B_0Fv-ZU.js} +4 -4
- package/dist/Stack/index.d.ts +1 -1
- package/dist/Stepper/index.d.ts +1 -1
- package/dist/Switch/index.d.ts +1 -1
- package/dist/TabList/index.d.ts +1 -1
- package/dist/Table/index.d.ts +1 -1
- package/dist/Table/index.js +1 -1
- package/dist/{Table-DEqfIA3q.js → Table-B0Aj43zB.js} +9 -9
- package/dist/TextArea/index.d.ts +1 -1
- package/dist/TextInput/index.d.ts +1 -1
- package/dist/TimeInput/index.d.ts +1 -1
- package/dist/Timestamp/index.d.ts +1 -1
- package/dist/ToggleButton/index.d.ts +1 -1
- package/dist/Token/index.d.ts +1 -1
- package/dist/Tokenizer/index.d.ts +2 -2
- package/dist/Tokenizer/index.js +1 -1
- package/dist/Tokenizer-iJb-WZ55.js +2067 -0
- 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/TopNav/index.js +1 -1
- package/dist/{TopNav-Ce79A3zT.js → TopNav-ctvKlpxf.js} +1 -1
- package/dist/TreeList/index.d.ts +1 -1
- package/dist/TreeList/index.js +1 -1
- package/dist/{TreeList-BEPHdVYu.js → TreeList-Dh0uAj2B.js} +48 -7
- package/dist/Typeahead/index.d.ts +1 -1
- package/dist/Typeahead/index.js +2 -2
- package/dist/{Typeahead-CBrUdbHv.js → Typeahead-D2O3n477.js} +1 -1
- package/dist/{animator-BooLoGyI.js → animator-BGq5a6vT.js} +4 -300
- package/dist/{batch-CM-vJhQg.js → batch-BhaAWUIt.js} +3 -2
- package/dist/{bezier-Cts7gENO.js → bezier-Df-yGuNZ.js} +1 -90
- package/dist/composables/index.js +2 -1
- package/dist/{composables-BtqijTIO.js → composables-BTRbNgmR.js} +4 -41
- package/dist/{context-DH8E-qjm.js → context-jtpQfR6F.js} +1 -1
- package/dist/{edge-BYXwSggM.js → edge-CJIswPTX.js} +1 -1
- package/dist/{edgeRide-B5mlN2Q4.js → edgeRide-Drk4V-MC.js} +2 -2
- package/dist/{index-ZbNwGVkS.d.ts → index-BKnyTWPM.d.ts} +1 -1
- package/dist/{index-DeZ11MNP.d.ts → index-BLsYMZgA.d.ts} +4 -4
- package/dist/{index-D7ShT2c-.d.ts → index-BgT6mH3U.d.ts} +1 -1
- package/dist/{index-BD-Pxni9.d.ts → index-BhxqUt3y.d.ts} +1 -1
- package/dist/{index-LqFjvL4C.d.ts → index-Bu4R0WZA.d.ts} +21 -5
- package/dist/{index-B5aHF0Ml.d.ts → index-C0nKJSA2.d.ts} +1 -1
- package/dist/{index-DlKz3dB1.d.ts → index-C6IcBhAn.d.ts} +2 -2
- package/dist/{index-Cm36VS1A.d.ts → index-C9uW39Mj.d.ts} +1 -1
- package/dist/{index-CnOH43-f.d.ts → index-CBH9Gyte.d.ts} +1 -1
- package/dist/{index-CRtGmCHi.d.ts → index-CEtFUoIm.d.ts} +1 -1
- package/dist/{index-C4S65SAW.d.ts → index-CKnr0JlT.d.ts} +1 -1
- package/dist/{index-BdhQpERn.d.ts → index-CMZnO7VU.d.ts} +4 -4
- package/dist/{index-DY1kpap1.d.ts → index-CkzTX9pb.d.ts} +42 -42
- package/dist/{index-DSMv6W8s.d.ts → index-Ct6SEtjd.d.ts} +4 -4
- package/dist/{index-C8wfe0Mr.d.ts → index-D05JGsT3.d.ts} +1 -1
- package/dist/{index-FeZXsFO-.d.ts → index-DDrL_-hJ.d.ts} +1 -1
- package/dist/{index-DDVCVpnG.d.ts → index-DE-QPNz0.d.ts} +1 -1
- package/dist/{index-BxWCX2pJ.d.ts → index-DFLPv9io.d.ts} +3 -3
- package/dist/{index-CB6VQETg.d.ts → index-DIw5D3zj.d.ts} +2 -2
- package/dist/{index-eCp-ElSp.d.ts → index-DYabo8TI.d.ts} +1 -1
- package/dist/{index-Otl047R1.d.ts → index-DofC9Rll.d.ts} +1 -1
- package/dist/{index-C2zWUiJ1.d.ts → index-DogWVRJi.d.ts} +1 -1
- package/dist/{index-aHC2C89h.d.ts → index-Ea2V_FSK.d.ts} +4 -4
- package/dist/{index-DPklTi3o.d.ts → index-Q1oG9yIT.d.ts} +1 -1
- package/dist/{index-NOXYEdOI.d.ts → index-utZGF4GR.d.ts} +1 -1
- package/dist/index.d.ts +30 -30
- package/dist/index.js +39 -37
- package/dist/{landing-B9Uvex6x.js → landing-CBaXCGEg.js} +2 -2
- package/dist/{loadCatalog-BRd5XCbW.js → loadCatalog-Blm5sm1o.js} +36 -8
- package/dist/{loadCatalog-CLm4V7mm.d.ts → loadCatalog-DDLjLKYA.d.ts} +21 -0
- package/dist/locale/index.d.ts +2 -2
- package/dist/locale/index.js +3 -3
- package/dist/{locale-BkAezFog.js → locale-Y7dHbjs4.js} +1 -1
- package/dist/resolveMotion-CurhYTVC.js +307 -0
- package/dist/{themeTiming-CWEvdh31.js → themeTiming-BFDOPRjK.js} +1 -1
- package/dist/timing-CSHWQbTJ.js +90 -0
- package/dist/tokenizer-C1y-55Ft.js +72 -0
- package/dist/{types-Gw2OjSK9.d.ts → types-ClOMFbqC.d.ts} +2 -2
- package/dist/useAnimatedLayout-DC2l3WrE.js +40 -0
- package/dist/{useMenuDrillIn-CP0P49ej.js → useMenuDrillIn-BQx6lQMz.js} +1 -1
- package/dist/useMenuEntranceHold-buV5S9yk.js +33 -0
- package/dist/{useTypeaheadMenuConfig-DeDGVR8S.js → useTypeaheadMenuConfig-Do0jOyEm.js} +35 -35
- package/package.json +1 -1
- package/styles/list.css +102 -5
- package/styles/metadata-list.css +6 -1
- package/styles/more-menu.css +42 -35
- package/styles/outline.css +2 -1
- package/styles/sheet-confirmation.css +8 -0
- package/styles/tokenizer-sheet.css +203 -0
- package/styles.css +2 -0
- package/dist/Tokenizer-2zj57yDt.js +0 -888
- package/dist/tokenizer-ChiAuPN-.js +0 -34
- package/dist/{Chat-RE_6Ez79.js → Chat-Bg1IuDMt.js} +1 -1
- package/dist/{ClickableCard-CwGxO0GU.js → ClickableCard-ChmOwgYq.js} +1 -1
- package/dist/{NavItem-c1ScHEJY.js → NavItem-kj9FbbFS.js} +1 -1
- package/dist/{Selector-Bj4q6aT5.js → Selector-BrNA4sLV.js} +1 -1
- package/dist/{index-J6YRJ7Ul.d.ts → index-CHx33xGa.d.ts} +1 -1
|
@@ -0,0 +1,2067 @@
|
|
|
1
|
+
import { t as _sfc_main$4 } from "./Icon-Dk0jccgU.js";
|
|
2
|
+
import { i as useSize } from "./SizeContext-BbaF-SEx.js";
|
|
3
|
+
import { t as _sfc_main$5 } from "./Button-yJiHoWps.js";
|
|
4
|
+
import { s as isImeKeyEvent } from "./layerDepth-D3Rh8T5C.js";
|
|
5
|
+
import { a as trackInteractionModality, t as getInteractionModality } from "./interactionModality-4Km2ibsq.js";
|
|
6
|
+
import { t as _sfc_main$6 } from "./ButtonTooltip-CNKOQHYR.js";
|
|
7
|
+
import { t as useButtonTooltip } from "./useButtonTooltip-DjCaZMp_.js";
|
|
8
|
+
import { n as isDevBuild, t as devPropError } from "./devBuild-G249YcdZ.js";
|
|
9
|
+
import { t as devWarn } from "./useDevWarning-B2fsk2B-.js";
|
|
10
|
+
import { t as useAnnounce } from "./announce-GU01Oix2.js";
|
|
11
|
+
import { t as useInputStatusIcon } from "./useInputStatusIcon-CGj9gMj8.js";
|
|
12
|
+
import { o as useComponentMessages } from "./context-B8IEFCDR.js";
|
|
13
|
+
import { t as useOverflow } from "./useOverflow-GU0pxGaU.js";
|
|
14
|
+
import { t as useResolvedLabelHidden } from "./useResolvedLabelHidden-B2rlWiaI.js";
|
|
15
|
+
import { t as _sfc_main$7 } from "./Dialog-DjhG_vpE.js";
|
|
16
|
+
import { t as _sfc_main$8 } from "./Heading-BG1PBVkf.js";
|
|
17
|
+
import { t as useScrollbars } from "./useScrollbars-Ch0xqJWO.js";
|
|
18
|
+
import { t as _sfc_main$9 } from "./Stack-DPB-Ztf7.js";
|
|
19
|
+
import { t as _sfc_main$10 } from "./Text-DkSHitKh.js";
|
|
20
|
+
import { t as _sfc_main$11 } from "./CheckboxIndicator-fH4d-JE1.js";
|
|
21
|
+
import { t as useHeldPresentation } from "./useHeldPresentation-7MH-RlSF.js";
|
|
22
|
+
import { n as preloadBottomSheet, t as LazyBottomSheet } from "./lazyBottomSheet-CxEu25bK.js";
|
|
23
|
+
import { t as useBusyAnnouncement } from "./busyAnnouncement-CExubuYm.js";
|
|
24
|
+
import { t as _sfc_main$12 } from "./Spinner-DEVPDsD0.js";
|
|
25
|
+
import { t as _sfc_main$13 } from "./Field-DrUMz0oj.js";
|
|
26
|
+
import { t as useFieldPartStyling } from "./fieldParts-CuE5V12i.js";
|
|
27
|
+
import { n as alertDialogMessages, t as tokenizerMessages } from "./tokenizer-C1y-55Ft.js";
|
|
28
|
+
import { t as _sfc_main$14 } from "./EmptyState-DNjqNAT3.js";
|
|
29
|
+
import { t as _sfc_main$15 } from "./Token-C7Dt5ygK.js";
|
|
30
|
+
import { n as scrollOptionIntoView, r as useAnchoredListbox } from "./stillPointerGate-D3loXLh7.js";
|
|
31
|
+
import { i as _sfc_main$16, n as useTypeaheadAnnouncement, o as useTypeaheadMenu, r as useLatchedOptionGrid, t as useTypeaheadMenuConfig } from "./useTypeaheadMenuConfig-Do0jOyEm.js";
|
|
32
|
+
import { t as _sfc_main$17 } from "./TextInput-BvQQTG75.js";
|
|
33
|
+
import { Fragment, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createSlots, createTextVNode, createVNode, defineComponent, guardReactiveProps, isRef, mergeModels, mergeProps, nextTick, normalizeClass, normalizeProps, normalizeStyle, onBeforeUnmount, onMounted, openBlock, ref, renderList, renderSlot, resolveDynamicComponent, shallowRef, toDisplayString, unref, useAttrs, useId, useModel, useSlots, useTemplateRef, watch, withCtx } from "vue";
|
|
34
|
+
import "../styles/layer.css";
|
|
35
|
+
import "../styles/alert-dialog.css";
|
|
36
|
+
import "../styles/visually-hidden-utility.css";
|
|
37
|
+
import "../styles/typeahead.css";
|
|
38
|
+
import "../styles/sheet-confirmation.css";
|
|
39
|
+
import "../styles/tokenizer-sheet.css";
|
|
40
|
+
import "../styles/tokenizer.css";
|
|
41
|
+
//#region src/composables/internal/useTokenRemoveTap.ts
|
|
42
|
+
/**
|
|
43
|
+
* 手指点 Token 自带的删除按钮时,别把触屏键盘弹起来。
|
|
44
|
+
*
|
|
45
|
+
* 触屏浏览器在一次点按里聚焦输入框就会弹出键盘。标签输入框删掉一个标签后
|
|
46
|
+
* 默认把焦点交回输入框,于是手指每删一个标签都要再收一次键盘。这里记下
|
|
47
|
+
* 字段里最近一次按下:手指按在删除按钮上、而输入框当时没有焦点(键盘是收着的)
|
|
48
|
+
* 时,删除后焦点留在原处,被按的删除按钮也不接焦点。鼠标、笔、按键删除,
|
|
49
|
+
* 以及键盘已经弹起时的点按,都照旧把焦点交回输入框。
|
|
50
|
+
*/
|
|
51
|
+
/** Token 自带的删除按钮。自定义插槽画的删除控件不算。 */
|
|
52
|
+
const TOKEN_REMOVE_SELECTOR = ".astryx-token-remove";
|
|
53
|
+
function removeControlOf(target) {
|
|
54
|
+
return target instanceof Element ? target.closest(TOKEN_REMOVE_SELECTOR) : null;
|
|
55
|
+
}
|
|
56
|
+
function useTokenRemoveTap(options) {
|
|
57
|
+
trackInteractionModality();
|
|
58
|
+
let press = null;
|
|
59
|
+
let endTimer;
|
|
60
|
+
/** 键盘是收着的:最近一次是手指按下,当时输入框没有焦点,之后也没按过键。 */
|
|
61
|
+
function wasKeyboardDown() {
|
|
62
|
+
return press != null && press.isFinger && !press.inputHadFocus && getInteractionModality() === "pointer";
|
|
63
|
+
}
|
|
64
|
+
function onPointerDown(event) {
|
|
65
|
+
clearTimeout(endTimer);
|
|
66
|
+
const input = options.input.value;
|
|
67
|
+
press = {
|
|
68
|
+
inputHadFocus: input != null && input.ownerDocument.activeElement === input,
|
|
69
|
+
isFinger: event.pointerType === "touch",
|
|
70
|
+
pressedRemove: removeControlOf(event.target)
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
/** 手指点按后浏览器补发的 mousedown 会让按钮抢到焦点,键盘收着时取消它。 */
|
|
74
|
+
function onMouseDown(event) {
|
|
75
|
+
if (removeControlOf(event.target) != null && wasKeyboardDown()) event.preventDefault();
|
|
76
|
+
}
|
|
77
|
+
/** 这次按下的记录随点按结束:click 所在的任务跑完,或者浏览器把按下接管成滚动。 */
|
|
78
|
+
function onClick() {
|
|
79
|
+
clearTimeout(endTimer);
|
|
80
|
+
endTimer = setTimeout(() => {
|
|
81
|
+
press = null;
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
function onPointerCancel() {
|
|
85
|
+
press = null;
|
|
86
|
+
}
|
|
87
|
+
const listeners = [
|
|
88
|
+
["pointerdown", onPointerDown],
|
|
89
|
+
["mousedown", onMouseDown],
|
|
90
|
+
["click", onClick],
|
|
91
|
+
["pointercancel", onPointerCancel]
|
|
92
|
+
];
|
|
93
|
+
let boundTo = null;
|
|
94
|
+
function bindTo(element) {
|
|
95
|
+
if (element === boundTo) return;
|
|
96
|
+
for (const [type, listener] of listeners) {
|
|
97
|
+
boundTo?.removeEventListener(type, listener, true);
|
|
98
|
+
element?.addEventListener(type, listener, true);
|
|
99
|
+
}
|
|
100
|
+
boundTo = element;
|
|
101
|
+
}
|
|
102
|
+
onMounted(() => bindTo(options.root.value));
|
|
103
|
+
watch(options.root, (element) => bindTo(element), { flush: "post" });
|
|
104
|
+
onBeforeUnmount(() => {
|
|
105
|
+
clearTimeout(endTimer);
|
|
106
|
+
bindTo(null);
|
|
107
|
+
});
|
|
108
|
+
function shouldFocusInputAfterRemove() {
|
|
109
|
+
const pressed = wasKeyboardDown() ? press?.pressedRemove ?? null : null;
|
|
110
|
+
if (pressed == null) return true;
|
|
111
|
+
const active = pressed.ownerDocument.activeElement;
|
|
112
|
+
const token = pressed.closest(options.tokenSelector) ?? pressed;
|
|
113
|
+
return active != null && token.contains(active);
|
|
114
|
+
}
|
|
115
|
+
return { shouldFocusInputAfterRemove };
|
|
116
|
+
}
|
|
117
|
+
//#endregion
|
|
118
|
+
//#region src/Tokenizer/inputAttrs.ts
|
|
119
|
+
/**
|
|
120
|
+
* 这些属性由组件自己算,不能让外面透传的值盖掉。
|
|
121
|
+
* 其余的原生属性和事件监听(@keydown / @focus / @blur …)原样落到输入框上。
|
|
122
|
+
*/
|
|
123
|
+
const controlledAttrs = /* @__PURE__ */ new Set([
|
|
124
|
+
"id",
|
|
125
|
+
"type",
|
|
126
|
+
"role",
|
|
127
|
+
"value",
|
|
128
|
+
"class",
|
|
129
|
+
"style",
|
|
130
|
+
"disabled",
|
|
131
|
+
"readonly",
|
|
132
|
+
"autofocus",
|
|
133
|
+
"placeholder",
|
|
134
|
+
"tabindex",
|
|
135
|
+
"autocomplete",
|
|
136
|
+
"aria-labelledby",
|
|
137
|
+
"aria-describedby",
|
|
138
|
+
"aria-invalid",
|
|
139
|
+
"aria-expanded",
|
|
140
|
+
"aria-controls",
|
|
141
|
+
"aria-activedescendant",
|
|
142
|
+
"aria-autocomplete",
|
|
143
|
+
"aria-disabled",
|
|
144
|
+
"aria-required"
|
|
145
|
+
]);
|
|
146
|
+
/** 去掉组件自己控制的属性,剩下的落到输入框上。 */
|
|
147
|
+
function pickInputAttrs(attrs) {
|
|
148
|
+
return Object.fromEntries(Object.entries(attrs).filter(([key]) => !controlledAttrs.has(key)));
|
|
149
|
+
}
|
|
150
|
+
//#endregion
|
|
151
|
+
//#region src/composables/internal/dismissSearchOnTouchDrag.ts
|
|
152
|
+
/**
|
|
153
|
+
* 在结果列表上用手指上下拖动时,把焦点从搜索框挪开(上游
|
|
154
|
+
* internal/useDismissSearchOnTouchDrag.ts)。
|
|
155
|
+
*
|
|
156
|
+
* 搜索框失去焦点,屏幕键盘就收起来,下面的行露出来;输入的文字保留。焦点交给调用方
|
|
157
|
+
* 给的目标(弹层自己的面板),不会落到弹层后面的页面上。不监听 scroll:过滤结果会
|
|
158
|
+
* 把 scrollTop 收回来,打字时也会触发 scroll。小幅移动、轻点、多指手势都不动焦点。
|
|
159
|
+
*/
|
|
160
|
+
const DRAG_THRESHOLD_PX = 8;
|
|
161
|
+
function dismissSearchOnTouchDrag(getSearchInputs, getFocusTarget) {
|
|
162
|
+
let startY = null;
|
|
163
|
+
const reset = () => {
|
|
164
|
+
startY = null;
|
|
165
|
+
};
|
|
166
|
+
return {
|
|
167
|
+
onTouchstart(event) {
|
|
168
|
+
startY = event.touches.length === 1 ? event.touches[0].clientY : null;
|
|
169
|
+
},
|
|
170
|
+
onTouchmove(event) {
|
|
171
|
+
if (event.touches.length !== 1) {
|
|
172
|
+
reset();
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
if (startY == null || Math.abs(event.touches[0].clientY - startY) < DRAG_THRESHOLD_PX) return;
|
|
176
|
+
reset();
|
|
177
|
+
const focused = getSearchInputs().find((input) => input != null && input === input.ownerDocument.activeElement);
|
|
178
|
+
if (focused == null) return;
|
|
179
|
+
const target = getFocusTarget?.();
|
|
180
|
+
if (target != null) target.focus({ preventScroll: true });
|
|
181
|
+
else focused.blur();
|
|
182
|
+
},
|
|
183
|
+
onTouchend: reset,
|
|
184
|
+
onTouchcancel: reset
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
//#endregion
|
|
188
|
+
//#region src/composables/internal/sheetDraft.ts
|
|
189
|
+
/** 两份选择是否是同一组条目,不看顺序。 */
|
|
190
|
+
function hasSameSelection(a, b) {
|
|
191
|
+
if (a.length !== b.length) return false;
|
|
192
|
+
const ids = new Set(a.map((item) => item.id));
|
|
193
|
+
return b.every((item) => ids.has(item.id));
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* 草稿和打开时的选择不同时,「保存」要报的那条变化;没有不同时是 null。
|
|
197
|
+
*
|
|
198
|
+
* 最后一次编辑还成立(加的那项还在、打开时没有;删的那项打开时有、现在没了)就报它。
|
|
199
|
+
* 否则:最后一次是删除并且确实少了某项,报那项的删除;再否则多了某项就报添加(最后
|
|
200
|
+
* 一次正是新建它时报 `create`);再否则报少了的那项。
|
|
201
|
+
*/
|
|
202
|
+
function nameSheetDraftChange(valueAtOpen, draftValue, lastDraftChange) {
|
|
203
|
+
const wasSelected = (id) => valueAtOpen.some((item) => item.id === id);
|
|
204
|
+
const isSelected = (id) => draftValue.some((item) => item.id === id);
|
|
205
|
+
const added = draftValue.find((item) => !wasSelected(item.id));
|
|
206
|
+
const removed = valueAtOpen.find((item) => !isSelected(item.id));
|
|
207
|
+
if (lastDraftChange != null && (lastDraftChange.type === "remove" ? wasSelected(lastDraftChange.item.id) && !isSelected(lastDraftChange.item.id) : isSelected(lastDraftChange.item.id) && !wasSelected(lastDraftChange.item.id))) return lastDraftChange;
|
|
208
|
+
if (lastDraftChange?.type === "remove" && removed != null) return {
|
|
209
|
+
item: removed,
|
|
210
|
+
type: "remove"
|
|
211
|
+
};
|
|
212
|
+
if (added != null) return {
|
|
213
|
+
item: added,
|
|
214
|
+
type: lastDraftChange?.item.id === added.id && lastDraftChange.type === "create" ? "create" : "add"
|
|
215
|
+
};
|
|
216
|
+
if (removed != null) return {
|
|
217
|
+
item: removed,
|
|
218
|
+
type: "remove"
|
|
219
|
+
};
|
|
220
|
+
return null;
|
|
221
|
+
}
|
|
222
|
+
//#endregion
|
|
223
|
+
//#region src/layer/SheetConfirmation.vue
|
|
224
|
+
const _hoisted_1$3 = { class: "astryx-alert-dialog__content" };
|
|
225
|
+
const _hoisted_2$3 = { class: "astryx-alert-dialog__footer" };
|
|
226
|
+
const _sfc_main$3 = /*@__PURE__*/ defineComponent({
|
|
227
|
+
name: "AstryxSheetConfirmation",
|
|
228
|
+
__name: "SheetConfirmation",
|
|
229
|
+
props: {
|
|
230
|
+
isOpen: { type: Boolean },
|
|
231
|
+
title: {},
|
|
232
|
+
description: {},
|
|
233
|
+
cancelLabel: {},
|
|
234
|
+
actionLabel: {}
|
|
235
|
+
},
|
|
236
|
+
emits: ["openChange", "action"],
|
|
237
|
+
setup(__props, { emit: __emit }) {
|
|
238
|
+
/**
|
|
239
|
+
* 触屏底部弹层盖在自己上面的确认框:「全部清除」和「放弃改动」共用(上游
|
|
240
|
+
* internal/SheetConfirmation.tsx)。
|
|
241
|
+
*
|
|
242
|
+
* 和 AlertDialog 不同:能点遮罩关闭;两个大号按钮占满整行、上下排开、隔开一点,
|
|
243
|
+
* 危险操作在阅读顺序里排前面,安全操作先拿到焦点。保留 alert-dialog 的主题挂点。
|
|
244
|
+
*/
|
|
245
|
+
const emit = __emit;
|
|
246
|
+
const titleId = `astryx-sheet-confirmation-${useId()}`;
|
|
247
|
+
const descriptionId = `${titleId}-description`;
|
|
248
|
+
return (_ctx, _cache) => {
|
|
249
|
+
return openBlock(), createBlock(_sfc_main$7, {
|
|
250
|
+
class: "astryx-alert-dialog astryx-sheet-confirmation",
|
|
251
|
+
"is-open": __props.isOpen,
|
|
252
|
+
purpose: "info",
|
|
253
|
+
role: "alertdialog",
|
|
254
|
+
"aria-labelledby": titleId,
|
|
255
|
+
"aria-describedby": descriptionId,
|
|
256
|
+
width: 400,
|
|
257
|
+
onOpenChange: _cache[2] || (_cache[2] = ($event) => emit("openChange", $event))
|
|
258
|
+
}, {
|
|
259
|
+
default: withCtx(() => [createElementVNode("div", _hoisted_1$3, [createVNode(_sfc_main$8, {
|
|
260
|
+
id: titleId,
|
|
261
|
+
class: "astryx-alert-dialog__title astryx-alert-dialog-title",
|
|
262
|
+
level: 2
|
|
263
|
+
}, {
|
|
264
|
+
default: withCtx(() => [createTextVNode(toDisplayString(__props.title), 1)]),
|
|
265
|
+
_: 1
|
|
266
|
+
}), createVNode(_sfc_main$10, {
|
|
267
|
+
id: descriptionId,
|
|
268
|
+
as: "div",
|
|
269
|
+
class: "astryx-alert-dialog__description astryx-alert-dialog-description",
|
|
270
|
+
color: "secondary",
|
|
271
|
+
type: "body"
|
|
272
|
+
}, {
|
|
273
|
+
default: withCtx(() => [createTextVNode(toDisplayString(__props.description), 1)]),
|
|
274
|
+
_: 1
|
|
275
|
+
})]), createElementVNode("div", _hoisted_2$3, [createVNode(_sfc_main$9, {
|
|
276
|
+
class: "astryx-alert-dialog__actions",
|
|
277
|
+
direction: "vertical",
|
|
278
|
+
gap: 4,
|
|
279
|
+
"h-align": "stretch"
|
|
280
|
+
}, {
|
|
281
|
+
default: withCtx(() => [createVNode(_sfc_main$5, {
|
|
282
|
+
class: "astryx-sheet-confirmation__action",
|
|
283
|
+
label: __props.actionLabel,
|
|
284
|
+
variant: "destructive",
|
|
285
|
+
size: "lg",
|
|
286
|
+
onClick: _cache[0] || (_cache[0] = ($event) => emit("action"))
|
|
287
|
+
}, null, 8, ["label"]), createVNode(_sfc_main$5, {
|
|
288
|
+
class: "astryx-sheet-confirmation__action",
|
|
289
|
+
label: __props.cancelLabel,
|
|
290
|
+
variant: "secondary",
|
|
291
|
+
size: "lg",
|
|
292
|
+
"data-autofocus": "",
|
|
293
|
+
onClick: _cache[1] || (_cache[1] = ($event) => emit("openChange", false))
|
|
294
|
+
}, null, 8, ["label"])]),
|
|
295
|
+
_: 1
|
|
296
|
+
})])]),
|
|
297
|
+
_: 1
|
|
298
|
+
}, 8, ["is-open"]);
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
/** 离列表底部这么近就画下一批。 */
|
|
303
|
+
const LOAD_MORE_THRESHOLD_PX = 200;
|
|
304
|
+
/**
|
|
305
|
+
* Tokenizer 底部弹层的搜索状态(上游 TokenizerBottomSheet 的 sheet session)。
|
|
306
|
+
*
|
|
307
|
+
* 列表顺序:打开时选中的排最前(按选中顺序),然后是草稿里新选、结果里没有的,最后是
|
|
308
|
+
* 搜索结果。勾选一行不会让它跳走,下次打开才重新分组。空查询立即请求 `bootstrap`,
|
|
309
|
+
* 打字的查询等 `debounceMs`;同步返回的搜索源在这次渲染之前就落定,不会闪「加载中」。
|
|
310
|
+
* 新请求作废旧请求,关闭和卸载时取消还没回来的请求。
|
|
311
|
+
*/
|
|
312
|
+
function useTokenizerSheetSearch(options) {
|
|
313
|
+
const query = ref(options.initialQuery);
|
|
314
|
+
const sourceResults = shallowRef([]);
|
|
315
|
+
const sourceHidden = shallowRef([]);
|
|
316
|
+
const renderedCount = ref(50);
|
|
317
|
+
const settledCount = ref(0);
|
|
318
|
+
let lastLoadHeight = null;
|
|
319
|
+
let sequence = 0;
|
|
320
|
+
const willSearchFor = (trimmed) => trimmed === "" || trimmed.length >= options.minQueryLength();
|
|
321
|
+
const isPending = ref(options.isOpen() && willSearchFor(options.initialQuery.trim()));
|
|
322
|
+
const isBelowMinQuery = computed(() => !willSearchFor(query.value.trim()));
|
|
323
|
+
const results = computed(() => isBelowMinQuery.value ? [] : sourceResults.value);
|
|
324
|
+
function resetWindow() {
|
|
325
|
+
lastLoadHeight = null;
|
|
326
|
+
renderedCount.value = 50;
|
|
327
|
+
}
|
|
328
|
+
function setQuery(next) {
|
|
329
|
+
resetWindow();
|
|
330
|
+
isPending.value = willSearchFor(next.trim());
|
|
331
|
+
query.value = next;
|
|
332
|
+
}
|
|
333
|
+
watch(options.isOpen, (open) => {
|
|
334
|
+
if (!open) return;
|
|
335
|
+
resetWindow();
|
|
336
|
+
isPending.value = willSearchFor(query.value.trim());
|
|
337
|
+
});
|
|
338
|
+
watch([
|
|
339
|
+
options.isOpen,
|
|
340
|
+
query,
|
|
341
|
+
options.minQueryLength,
|
|
342
|
+
options.maxMenuItems,
|
|
343
|
+
options.debounceMs
|
|
344
|
+
], ([open, current], _previous, onCleanup) => {
|
|
345
|
+
const seq = ++sequence;
|
|
346
|
+
if (!open) return;
|
|
347
|
+
const trimmed = current.trim();
|
|
348
|
+
if (!willSearchFor(trimmed)) return;
|
|
349
|
+
let unanswered = null;
|
|
350
|
+
const settle = (items) => {
|
|
351
|
+
unanswered = null;
|
|
352
|
+
if (sequence !== seq) return;
|
|
353
|
+
const max = options.maxMenuItems();
|
|
354
|
+
sourceResults.value = items.slice(0, max);
|
|
355
|
+
sourceHidden.value = items.slice(max);
|
|
356
|
+
isPending.value = false;
|
|
357
|
+
settledCount.value += 1;
|
|
358
|
+
};
|
|
359
|
+
const run = () => {
|
|
360
|
+
const source = options.searchSource();
|
|
361
|
+
let answer;
|
|
362
|
+
try {
|
|
363
|
+
answer = trimmed === "" ? source.bootstrap?.() ?? [] : source.search(current);
|
|
364
|
+
} catch {
|
|
365
|
+
answer = [];
|
|
366
|
+
}
|
|
367
|
+
if (Array.isArray(answer)) {
|
|
368
|
+
settle(answer);
|
|
369
|
+
return;
|
|
370
|
+
}
|
|
371
|
+
unanswered = source;
|
|
372
|
+
Promise.resolve(answer).then(settle, () => settle([]));
|
|
373
|
+
};
|
|
374
|
+
const delay = options.debounceMs();
|
|
375
|
+
const timer = trimmed !== "" && delay > 0 ? setTimeout(run, delay) : null;
|
|
376
|
+
if (timer == null) run();
|
|
377
|
+
onCleanup(() => {
|
|
378
|
+
if (timer != null) clearTimeout(timer);
|
|
379
|
+
const source = unanswered;
|
|
380
|
+
unanswered = null;
|
|
381
|
+
source?.cancel?.();
|
|
382
|
+
});
|
|
383
|
+
}, { immediate: true });
|
|
384
|
+
const visibleItems = computed(() => {
|
|
385
|
+
const normalized = query.value.trim().toLowerCase();
|
|
386
|
+
const matches = (item) => normalized === "" || item.label.toLowerCase().includes(normalized);
|
|
387
|
+
const atOpen = options.selectedAtOpen().filter(matches);
|
|
388
|
+
const atOpenIds = new Set(atOpen.map((item) => item.id));
|
|
389
|
+
const resultIds = new Set(results.value.map((item) => item.id));
|
|
390
|
+
const missing = options.draft().filter((item) => !atOpenIds.has(item.id) && !resultIds.has(item.id) && matches(item));
|
|
391
|
+
return [
|
|
392
|
+
...atOpen,
|
|
393
|
+
...missing,
|
|
394
|
+
...results.value.filter((item) => !atOpenIds.has(item.id))
|
|
395
|
+
];
|
|
396
|
+
});
|
|
397
|
+
const renderedItems = computed(() => visibleItems.value.slice(0, renderedCount.value));
|
|
398
|
+
const hiddenMatchCount = computed(() => {
|
|
399
|
+
if (isBelowMinQuery.value) return 0;
|
|
400
|
+
const listed = new Set(visibleItems.value.map((item) => item.id));
|
|
401
|
+
return sourceHidden.value.filter((item) => !listed.has(item.id)).length;
|
|
402
|
+
});
|
|
403
|
+
function renderMore() {
|
|
404
|
+
renderedCount.value = Math.min(renderedCount.value + 50, visibleItems.value.length);
|
|
405
|
+
}
|
|
406
|
+
function onScroll(event) {
|
|
407
|
+
const list = event.currentTarget;
|
|
408
|
+
if (list == null) return;
|
|
409
|
+
if (list.scrollHeight - list.scrollTop - list.clientHeight > LOAD_MORE_THRESHOLD_PX || lastLoadHeight === list.scrollHeight) return;
|
|
410
|
+
lastLoadHeight = list.scrollHeight;
|
|
411
|
+
renderMore();
|
|
412
|
+
}
|
|
413
|
+
return {
|
|
414
|
+
query,
|
|
415
|
+
setQuery,
|
|
416
|
+
results,
|
|
417
|
+
isPending,
|
|
418
|
+
isBelowMinQuery,
|
|
419
|
+
visibleItems,
|
|
420
|
+
renderedItems,
|
|
421
|
+
hiddenMatchCount,
|
|
422
|
+
settledCount,
|
|
423
|
+
renderMore,
|
|
424
|
+
onScroll
|
|
425
|
+
};
|
|
426
|
+
}
|
|
427
|
+
//#endregion
|
|
428
|
+
//#region src/Tokenizer/TokenizerBottomSheet.vue
|
|
429
|
+
const _hoisted_1$2 = { class: "astryx-tokenizer-sheet" };
|
|
430
|
+
const _hoisted_2$2 = { class: "astryx-tokenizer-sheet__search" };
|
|
431
|
+
const _hoisted_3$2 = [
|
|
432
|
+
"aria-busy",
|
|
433
|
+
"data-rendered-count",
|
|
434
|
+
"data-total-count"
|
|
435
|
+
];
|
|
436
|
+
const _hoisted_4$2 = {
|
|
437
|
+
key: 0,
|
|
438
|
+
class: "astryx-tokenizer-sheet__create-row"
|
|
439
|
+
};
|
|
440
|
+
const _hoisted_5$2 = {
|
|
441
|
+
key: 1,
|
|
442
|
+
class: "astryx-tokenizer-sheet__pending"
|
|
443
|
+
};
|
|
444
|
+
const _hoisted_6$2 = {
|
|
445
|
+
key: 2,
|
|
446
|
+
class: "astryx-tokenizer-sheet__empty"
|
|
447
|
+
};
|
|
448
|
+
const _hoisted_7$2 = {
|
|
449
|
+
key: 3,
|
|
450
|
+
role: "list",
|
|
451
|
+
class: "astryx-tokenizer-sheet__rows"
|
|
452
|
+
};
|
|
453
|
+
const _hoisted_8 = ["aria-setsize", "aria-posinset"];
|
|
454
|
+
const _hoisted_9 = [
|
|
455
|
+
"aria-checked",
|
|
456
|
+
"aria-label",
|
|
457
|
+
"aria-disabled",
|
|
458
|
+
"onFocus",
|
|
459
|
+
"onClick"
|
|
460
|
+
];
|
|
461
|
+
const _hoisted_10 = { class: "astryx-tokenizer-sheet__footer" };
|
|
462
|
+
const CREATABLE_ID_PREFIX = "__xds_create__";
|
|
463
|
+
const _sfc_main$2 = /*@__PURE__*/ defineComponent({
|
|
464
|
+
name: "AstryxTokenizerBottomSheet",
|
|
465
|
+
__name: "TokenizerBottomSheet",
|
|
466
|
+
props: {
|
|
467
|
+
isOpen: { type: Boolean },
|
|
468
|
+
label: {},
|
|
469
|
+
finalFocus: {},
|
|
470
|
+
initialQuery: {},
|
|
471
|
+
searchSource: {},
|
|
472
|
+
value: {},
|
|
473
|
+
maxEntries: {},
|
|
474
|
+
hasCreate: { type: Boolean },
|
|
475
|
+
maxMenuItems: {},
|
|
476
|
+
minQueryLength: {},
|
|
477
|
+
debounceMs: {},
|
|
478
|
+
emptySearchText: {}
|
|
479
|
+
},
|
|
480
|
+
emits: [
|
|
481
|
+
"close",
|
|
482
|
+
"commit",
|
|
483
|
+
"changeQuery",
|
|
484
|
+
"motionComplete"
|
|
485
|
+
],
|
|
486
|
+
setup(__props, { emit: __emit }) {
|
|
487
|
+
const props = __props;
|
|
488
|
+
const emit = __emit;
|
|
489
|
+
const messages = useComponentMessages({
|
|
490
|
+
tokenizer: tokenizerMessages,
|
|
491
|
+
alertDialog: alertDialogMessages
|
|
492
|
+
});
|
|
493
|
+
const announce = useAnnounce();
|
|
494
|
+
const searchInput = useTemplateRef("searchInput");
|
|
495
|
+
const listRef = useTemplateRef("listRef");
|
|
496
|
+
const clearAllButton = useTemplateRef("clearAllButton");
|
|
497
|
+
const valueAtOpen = shallowRef([...props.value]);
|
|
498
|
+
const draft = shallowRef([...props.value]);
|
|
499
|
+
const selectedAtOpen = shallowRef([...props.value]);
|
|
500
|
+
let lastDraftChange = null;
|
|
501
|
+
const isDraftDirty = computed(() => !hasSameSelection(valueAtOpen.value, draft.value));
|
|
502
|
+
const selectedIds = computed(() => new Set(draft.value.map((item) => item.id)));
|
|
503
|
+
const isAtMax = computed(() => props.maxEntries != null && draft.value.length >= props.maxEntries);
|
|
504
|
+
const isDraftOverMax = computed(() => props.maxEntries != null && draft.value.length > props.maxEntries);
|
|
505
|
+
const isClearConfirmationOpen = ref(false);
|
|
506
|
+
const isDiscardConfirmationOpen = ref(false);
|
|
507
|
+
const search = useTokenizerSheetSearch({
|
|
508
|
+
isOpen: () => props.isOpen,
|
|
509
|
+
initialQuery: props.initialQuery,
|
|
510
|
+
searchSource: () => props.searchSource,
|
|
511
|
+
minQueryLength: () => props.minQueryLength,
|
|
512
|
+
maxMenuItems: () => props.maxMenuItems,
|
|
513
|
+
debounceMs: () => props.debounceMs,
|
|
514
|
+
selectedAtOpen: () => selectedAtOpen.value,
|
|
515
|
+
draft: () => draft.value
|
|
516
|
+
});
|
|
517
|
+
const { query, isPending, visibleItems, renderedItems } = search;
|
|
518
|
+
const trimmedQuery = computed(() => query.value.trim());
|
|
519
|
+
watch(() => props.isOpen, (open) => {
|
|
520
|
+
if (!open) return;
|
|
521
|
+
selectedAtOpen.value = [...props.value];
|
|
522
|
+
valueAtOpen.value = [...props.value];
|
|
523
|
+
draft.value = [...props.value];
|
|
524
|
+
lastDraftChange = null;
|
|
525
|
+
isClearConfirmationOpen.value = false;
|
|
526
|
+
isDiscardConfirmationOpen.value = false;
|
|
527
|
+
}, { flush: "sync" });
|
|
528
|
+
/** 输入的文字不在任何选项里时,给一行「创建 …」和后面的「添加」按钮。等这次搜索落定再判断。 */
|
|
529
|
+
const createItem = computed(() => {
|
|
530
|
+
const trimmed = trimmedQuery.value;
|
|
531
|
+
if (!props.hasCreate || trimmed === "" || isAtMax.value || isPending.value) return null;
|
|
532
|
+
const lowered = trimmed.toLowerCase();
|
|
533
|
+
if (selectedIds.value.has(trimmed) || draft.value.some((item) => item.label.toLowerCase() === lowered) || search.results.value.some((item) => item.label.toLowerCase() === lowered)) return null;
|
|
534
|
+
return {
|
|
535
|
+
id: `${CREATABLE_ID_PREFIX}${trimmed}`,
|
|
536
|
+
label: messages.value.tokenizer.create(trimmed)
|
|
537
|
+
};
|
|
538
|
+
});
|
|
539
|
+
const isSettledEmpty = computed(() => !isPending.value && !search.isBelowMinQuery.value && trimmedQuery.value !== "" && visibleItems.value.length === 0 && createItem.value == null);
|
|
540
|
+
const isSettledBlank = computed(() => !isPending.value && !search.isBelowMinQuery.value && trimmedQuery.value === "" && visibleItems.value.length === 0 && createItem.value == null);
|
|
541
|
+
useBusyAnnouncement(() => props.isOpen && isPending.value, () => messages.value.tokenizer.loading, () => listRef.value);
|
|
542
|
+
watch(search.settledCount, () => {
|
|
543
|
+
if (!props.isOpen || isSettledEmpty.value || trimmedQuery.value === "") return;
|
|
544
|
+
announce(messages.value.tokenizer.resultCount(visibleItems.value.length + (createItem.value ? 1 : 0) + search.hiddenMatchCount.value));
|
|
545
|
+
}, { flush: "post" });
|
|
546
|
+
function changeQuery(next) {
|
|
547
|
+
search.setQuery(next);
|
|
548
|
+
emit("changeQuery", next);
|
|
549
|
+
}
|
|
550
|
+
function closeSheet() {
|
|
551
|
+
if (query.value !== "") changeQuery("");
|
|
552
|
+
emit("close");
|
|
553
|
+
}
|
|
554
|
+
/** 下滑、点遮罩、Escape:草稿改过时先问。 */
|
|
555
|
+
function onSheetOpenChange(open) {
|
|
556
|
+
if (open !== false) return;
|
|
557
|
+
if (isDraftDirty.value) isDiscardConfirmationOpen.value = true;
|
|
558
|
+
else closeSheet();
|
|
559
|
+
}
|
|
560
|
+
function toggle(item) {
|
|
561
|
+
const selected = selectedIds.value.has(item.id);
|
|
562
|
+
if (!selected && isAtMax.value) return;
|
|
563
|
+
if (selected) {
|
|
564
|
+
draft.value = draft.value.filter((entry) => entry.id !== item.id);
|
|
565
|
+
lastDraftChange = {
|
|
566
|
+
item,
|
|
567
|
+
type: "remove"
|
|
568
|
+
};
|
|
569
|
+
announce(messages.value.tokenizer.removed(item.label));
|
|
570
|
+
} else {
|
|
571
|
+
draft.value = [...draft.value, item];
|
|
572
|
+
lastDraftChange = {
|
|
573
|
+
item,
|
|
574
|
+
type: "add"
|
|
575
|
+
};
|
|
576
|
+
announce(messages.value.tokenizer.added(item.label));
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
function create() {
|
|
580
|
+
const value = trimmedQuery.value;
|
|
581
|
+
const created = {
|
|
582
|
+
id: value,
|
|
583
|
+
label: value
|
|
584
|
+
};
|
|
585
|
+
draft.value = [...draft.value, created];
|
|
586
|
+
lastDraftChange = {
|
|
587
|
+
item: created,
|
|
588
|
+
type: "create"
|
|
589
|
+
};
|
|
590
|
+
announce(messages.value.tokenizer.added(value));
|
|
591
|
+
changeQuery("");
|
|
592
|
+
searchInput.value?.focus();
|
|
593
|
+
}
|
|
594
|
+
function save() {
|
|
595
|
+
if (isDraftOverMax.value) return;
|
|
596
|
+
const change = isDraftDirty.value ? nameSheetDraftChange(valueAtOpen.value, draft.value, lastDraftChange) : null;
|
|
597
|
+
if (change != null) emit("commit", [...draft.value], change);
|
|
598
|
+
closeSheet();
|
|
599
|
+
}
|
|
600
|
+
function closeClearConfirmation(confirmed) {
|
|
601
|
+
isClearConfirmationOpen.value = false;
|
|
602
|
+
nextTick(() => {
|
|
603
|
+
clearAllButton.value?.element?.focus();
|
|
604
|
+
if (confirmed) announce(messages.value.tokenizer.allRemoved);
|
|
605
|
+
});
|
|
606
|
+
}
|
|
607
|
+
function confirmClear() {
|
|
608
|
+
const last = draft.value.at(-1);
|
|
609
|
+
if (last != null) {
|
|
610
|
+
draft.value = [];
|
|
611
|
+
lastDraftChange = {
|
|
612
|
+
item: last,
|
|
613
|
+
type: "remove"
|
|
614
|
+
};
|
|
615
|
+
}
|
|
616
|
+
closeClearConfirmation(true);
|
|
617
|
+
}
|
|
618
|
+
/** 「继续编辑」:确认框没了,焦点回到搜索框,弹层自己的阅读顺序从那里开始。 */
|
|
619
|
+
function keepEditing() {
|
|
620
|
+
isDiscardConfirmationOpen.value = false;
|
|
621
|
+
nextTick(() => searchInput.value?.focus({ preventScroll: true }));
|
|
622
|
+
}
|
|
623
|
+
function discard() {
|
|
624
|
+
isDiscardConfirmationOpen.value = false;
|
|
625
|
+
closeSheet();
|
|
626
|
+
}
|
|
627
|
+
let isRowFocused = false;
|
|
628
|
+
watch(renderedItems, () => {
|
|
629
|
+
if (!props.isOpen || isPending.value || !isRowFocused) return;
|
|
630
|
+
const active = document.activeElement;
|
|
631
|
+
if (active == null || active === document.body) {
|
|
632
|
+
isRowFocused = false;
|
|
633
|
+
searchInput.value?.focus();
|
|
634
|
+
}
|
|
635
|
+
}, { flush: "post" });
|
|
636
|
+
function onListFocusIn(event) {
|
|
637
|
+
isRowFocused = event.target instanceof HTMLElement && event.target.getAttribute("role") === "checkbox";
|
|
638
|
+
}
|
|
639
|
+
function onListFocusOut(event) {
|
|
640
|
+
if (event.relatedTarget != null) isRowFocused = false;
|
|
641
|
+
}
|
|
642
|
+
/** 焦点走到最后一行就画下一批:Tab 和方向键不用滚动也能走到每一行。 */
|
|
643
|
+
function onRowFocus(index) {
|
|
644
|
+
if (index === renderedItems.value.length - 1 && renderedItems.value.length < visibleItems.value.length) search.renderMore();
|
|
645
|
+
}
|
|
646
|
+
const listDrag = dismissSearchOnTouchDrag(() => [searchInput.value?.element], () => listRef.value?.closest("[tabindex=\"-1\"]"));
|
|
647
|
+
const searchLabel = computed(() => messages.value.tokenizer.search(props.label));
|
|
648
|
+
return (_ctx, _cache) => {
|
|
649
|
+
return openBlock(), createBlock(unref(LazyBottomSheet), {
|
|
650
|
+
"is-open": __props.isOpen,
|
|
651
|
+
label: __props.label,
|
|
652
|
+
height: "tall",
|
|
653
|
+
padding: 0,
|
|
654
|
+
"final-focus-ref": __props.finalFocus,
|
|
655
|
+
"onUpdate:isOpen": onSheetOpenChange,
|
|
656
|
+
onMotionComplete: _cache[9] || (_cache[9] = ($event) => emit("motionComplete", $event))
|
|
657
|
+
}, {
|
|
658
|
+
default: withCtx(() => [createElementVNode("div", _hoisted_1$2, [
|
|
659
|
+
createElementVNode("div", _hoisted_2$2, [createVNode(_sfc_main$17, {
|
|
660
|
+
ref_key: "searchInput",
|
|
661
|
+
ref: searchInput,
|
|
662
|
+
"model-value": unref(query),
|
|
663
|
+
label: searchLabel.value,
|
|
664
|
+
"is-label-hidden": "",
|
|
665
|
+
placeholder: unref(messages).tokenizer.searchPlaceholder,
|
|
666
|
+
"start-icon": "search",
|
|
667
|
+
size: "lg",
|
|
668
|
+
width: "100%",
|
|
669
|
+
"has-clear": "",
|
|
670
|
+
"onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => changeQuery($event ?? ""))
|
|
671
|
+
}, null, 8, [
|
|
672
|
+
"model-value",
|
|
673
|
+
"label",
|
|
674
|
+
"placeholder"
|
|
675
|
+
])]),
|
|
676
|
+
createCommentVNode(" 弹层内容区已经用标签命名了,列表再叫同一个名字会念两遍。 "),
|
|
677
|
+
createElementVNode("div", {
|
|
678
|
+
ref_key: "listRef",
|
|
679
|
+
ref: listRef,
|
|
680
|
+
class: "astryx-tokenizer-sheet__list",
|
|
681
|
+
"aria-busy": unref(isPending) || void 0,
|
|
682
|
+
"data-rendered-count": unref(renderedItems).length,
|
|
683
|
+
"data-total-count": unref(visibleItems).length,
|
|
684
|
+
onTouchstart: _cache[1] || (_cache[1] = (...args) => unref(listDrag).onTouchstart && unref(listDrag).onTouchstart(...args)),
|
|
685
|
+
onTouchmove: _cache[2] || (_cache[2] = (...args) => unref(listDrag).onTouchmove && unref(listDrag).onTouchmove(...args)),
|
|
686
|
+
onTouchend: _cache[3] || (_cache[3] = (...args) => unref(listDrag).onTouchend && unref(listDrag).onTouchend(...args)),
|
|
687
|
+
onTouchcancel: _cache[4] || (_cache[4] = (...args) => unref(listDrag).onTouchcancel && unref(listDrag).onTouchcancel(...args)),
|
|
688
|
+
onFocusin: onListFocusIn,
|
|
689
|
+
onFocusout: onListFocusOut,
|
|
690
|
+
onScroll: _cache[5] || (_cache[5] = (...args) => unref(search).onScroll && unref(search).onScroll(...args))
|
|
691
|
+
}, [
|
|
692
|
+
createItem.value ? (openBlock(), createElementBlock("div", _hoisted_4$2, [createVNode(_sfc_main$10, {
|
|
693
|
+
class: "astryx-tokenizer-sheet__create-label",
|
|
694
|
+
type: "body"
|
|
695
|
+
}, {
|
|
696
|
+
default: withCtx(() => [createTextVNode(toDisplayString(createItem.value.label), 1)]),
|
|
697
|
+
_: 1
|
|
698
|
+
}), createVNode(_sfc_main$5, {
|
|
699
|
+
label: unref(messages).tokenizer.add,
|
|
700
|
+
"aria-label": unref(messages).tokenizer.addValue(trimmedQuery.value),
|
|
701
|
+
variant: "secondary",
|
|
702
|
+
size: "lg",
|
|
703
|
+
onClick: create
|
|
704
|
+
}, null, 8, ["label", "aria-label"])])) : createCommentVNode("v-if", true),
|
|
705
|
+
unref(isPending) ? (openBlock(), createElementBlock("div", _hoisted_5$2, [createVNode(_sfc_main$12, {
|
|
706
|
+
size: "md",
|
|
707
|
+
label: unref(messages).tokenizer.loading
|
|
708
|
+
}, null, 8, ["label"])])) : createCommentVNode("v-if", true),
|
|
709
|
+
isSettledEmpty.value ? (openBlock(), createElementBlock("div", _hoisted_6$2, [renderSlot(_ctx.$slots, "empty", {}, () => [createVNode(_sfc_main$14, {
|
|
710
|
+
title: __props.emptySearchText ?? unref(messages).tokenizer.empty,
|
|
711
|
+
description: unref(messages).tokenizer.noResultsDescription,
|
|
712
|
+
"is-compact": ""
|
|
713
|
+
}, {
|
|
714
|
+
icon: withCtx(() => [createVNode(_sfc_main$4, {
|
|
715
|
+
icon: "search",
|
|
716
|
+
size: "lg",
|
|
717
|
+
color: "secondary"
|
|
718
|
+
})]),
|
|
719
|
+
_: 1
|
|
720
|
+
}, 8, ["title", "description"])])])) : !isSettledBlank.value ? (openBlock(), createElementBlock("div", _hoisted_7$2, [(openBlock(true), createElementBlock(Fragment, null, renderList(unref(renderedItems), (item, index) => {
|
|
721
|
+
return openBlock(), createElementBlock("div", {
|
|
722
|
+
key: item.id,
|
|
723
|
+
role: "listitem",
|
|
724
|
+
class: "astryx-tokenizer-sheet__row-item",
|
|
725
|
+
"aria-setsize": unref(visibleItems).length,
|
|
726
|
+
"aria-posinset": index + 1
|
|
727
|
+
}, [createElementVNode("button", {
|
|
728
|
+
type: "button",
|
|
729
|
+
role: "checkbox",
|
|
730
|
+
class: "astryx-tokenizer-sheet__row",
|
|
731
|
+
"aria-checked": selectedIds.value.has(item.id),
|
|
732
|
+
"aria-label": item.label,
|
|
733
|
+
"aria-disabled": !selectedIds.value.has(item.id) && isAtMax.value || void 0,
|
|
734
|
+
onFocus: ($event) => onRowFocus(index),
|
|
735
|
+
onClick: ($event) => toggle(item)
|
|
736
|
+
}, [createVNode(_sfc_main$10, {
|
|
737
|
+
class: "astryx-tokenizer-sheet__row-label",
|
|
738
|
+
type: "body"
|
|
739
|
+
}, {
|
|
740
|
+
default: withCtx(() => [createTextVNode(toDisplayString(item.label), 1)]),
|
|
741
|
+
_: 2
|
|
742
|
+
}, 1024), createVNode(_sfc_main$11, {
|
|
743
|
+
state: selectedIds.value.has(item.id) ? "checked" : "unchecked",
|
|
744
|
+
size: "md",
|
|
745
|
+
"is-disabled": !selectedIds.value.has(item.id) && isAtMax.value
|
|
746
|
+
}, null, 8, ["state", "is-disabled"])], 40, _hoisted_9)], 8, _hoisted_8);
|
|
747
|
+
}), 128))])) : createCommentVNode("v-if", true)
|
|
748
|
+
], 40, _hoisted_3$2),
|
|
749
|
+
createElementVNode("div", _hoisted_10, [createVNode(_sfc_main$5, {
|
|
750
|
+
ref_key: "clearAllButton",
|
|
751
|
+
ref: clearAllButton,
|
|
752
|
+
class: "astryx-tokenizer-sheet__footer-action",
|
|
753
|
+
label: unref(messages).tokenizer.clear,
|
|
754
|
+
variant: "secondary",
|
|
755
|
+
size: "lg",
|
|
756
|
+
"is-disabled": draft.value.length === 0,
|
|
757
|
+
tooltip: draft.value.length === 0 ? unref(messages).tokenizer.nothingToClear : void 0,
|
|
758
|
+
onClick: _cache[6] || (_cache[6] = ($event) => isClearConfirmationOpen.value = true)
|
|
759
|
+
}, null, 8, [
|
|
760
|
+
"label",
|
|
761
|
+
"is-disabled",
|
|
762
|
+
"tooltip"
|
|
763
|
+
]), createVNode(_sfc_main$5, {
|
|
764
|
+
class: "astryx-tokenizer-sheet__footer-action",
|
|
765
|
+
label: unref(messages).tokenizer.save,
|
|
766
|
+
variant: "primary",
|
|
767
|
+
size: "lg",
|
|
768
|
+
"is-disabled": isDraftOverMax.value,
|
|
769
|
+
tooltip: isDraftOverMax.value ? unref(messages).tokenizer.selectionLimit(__props.maxEntries ?? 0) : void 0,
|
|
770
|
+
onClick: save
|
|
771
|
+
}, null, 8, [
|
|
772
|
+
"label",
|
|
773
|
+
"is-disabled",
|
|
774
|
+
"tooltip"
|
|
775
|
+
])]),
|
|
776
|
+
createVNode(_sfc_main$3, {
|
|
777
|
+
"is-open": isClearConfirmationOpen.value,
|
|
778
|
+
title: unref(messages).tokenizer.clearAllTitle,
|
|
779
|
+
description: unref(messages).tokenizer.clearAllDescription(__props.label),
|
|
780
|
+
"cancel-label": unref(messages).alertDialog.cancel,
|
|
781
|
+
"action-label": unref(messages).tokenizer.clearSelection,
|
|
782
|
+
onOpenChange: _cache[7] || (_cache[7] = ($event) => $event || closeClearConfirmation(false)),
|
|
783
|
+
onAction: confirmClear
|
|
784
|
+
}, null, 8, [
|
|
785
|
+
"is-open",
|
|
786
|
+
"title",
|
|
787
|
+
"description",
|
|
788
|
+
"cancel-label",
|
|
789
|
+
"action-label"
|
|
790
|
+
]),
|
|
791
|
+
createVNode(_sfc_main$3, {
|
|
792
|
+
"is-open": isDiscardConfirmationOpen.value,
|
|
793
|
+
title: unref(messages).tokenizer.discardChangesTitle,
|
|
794
|
+
description: unref(messages).tokenizer.discardChangesDescription(__props.label),
|
|
795
|
+
"cancel-label": unref(messages).tokenizer.keepEditing,
|
|
796
|
+
"action-label": unref(messages).tokenizer.discardChanges,
|
|
797
|
+
onOpenChange: _cache[8] || (_cache[8] = ($event) => $event || keepEditing()),
|
|
798
|
+
onAction: discard
|
|
799
|
+
}, null, 8, [
|
|
800
|
+
"is-open",
|
|
801
|
+
"title",
|
|
802
|
+
"description",
|
|
803
|
+
"cancel-label",
|
|
804
|
+
"action-label"
|
|
805
|
+
])
|
|
806
|
+
])]),
|
|
807
|
+
_: 3
|
|
808
|
+
}, 8, [
|
|
809
|
+
"is-open",
|
|
810
|
+
"label",
|
|
811
|
+
"final-focus-ref"
|
|
812
|
+
]);
|
|
813
|
+
};
|
|
814
|
+
}
|
|
815
|
+
});
|
|
816
|
+
//#endregion
|
|
817
|
+
//#region src/Tokenizer/TokenizerSheetField.vue
|
|
818
|
+
const _hoisted_1$1 = {
|
|
819
|
+
key: 0,
|
|
820
|
+
class: "astryx-tokenizer-icon",
|
|
821
|
+
"aria-hidden": "true"
|
|
822
|
+
};
|
|
823
|
+
const _hoisted_2$1 = { class: "astryx-tokenizer-tokens" };
|
|
824
|
+
const _hoisted_3$1 = [
|
|
825
|
+
"id",
|
|
826
|
+
"aria-expanded",
|
|
827
|
+
"aria-disabled",
|
|
828
|
+
"aria-labelledby",
|
|
829
|
+
"aria-describedby"
|
|
830
|
+
];
|
|
831
|
+
const _hoisted_4$1 = {
|
|
832
|
+
key: 0,
|
|
833
|
+
class: "astryx-tokenizer-sheet-trigger__placeholder"
|
|
834
|
+
};
|
|
835
|
+
const _hoisted_5$1 = ["id"];
|
|
836
|
+
const _hoisted_6$1 = [
|
|
837
|
+
"name",
|
|
838
|
+
"value",
|
|
839
|
+
"disabled"
|
|
840
|
+
];
|
|
841
|
+
const _hoisted_7$1 = ["id"];
|
|
842
|
+
const _sfc_main$1 = /*@__PURE__*/ defineComponent({
|
|
843
|
+
name: "AstryxTokenizerSheetField",
|
|
844
|
+
inheritAttrs: false,
|
|
845
|
+
__name: "TokenizerSheetField",
|
|
846
|
+
props: /*@__PURE__*/ mergeModels({
|
|
847
|
+
values: {},
|
|
848
|
+
inputId: {},
|
|
849
|
+
label: {},
|
|
850
|
+
labelledBy: {},
|
|
851
|
+
describedBy: {},
|
|
852
|
+
placeholder: {},
|
|
853
|
+
size: {},
|
|
854
|
+
isDisabled: { type: Boolean },
|
|
855
|
+
name: {},
|
|
856
|
+
controlClass: {},
|
|
857
|
+
controlStyle: {},
|
|
858
|
+
statusIcon: {},
|
|
859
|
+
statusIconProps: {},
|
|
860
|
+
searchSource: {},
|
|
861
|
+
maxEntries: {},
|
|
862
|
+
hasCreate: { type: Boolean },
|
|
863
|
+
maxMenuItems: {},
|
|
864
|
+
minQueryLength: {},
|
|
865
|
+
debounceMs: {},
|
|
866
|
+
emptySearchText: {}
|
|
867
|
+
}, {
|
|
868
|
+
"isOpen": {
|
|
869
|
+
type: Boolean,
|
|
870
|
+
required: true
|
|
871
|
+
},
|
|
872
|
+
"isOpenModifiers": {}
|
|
873
|
+
}),
|
|
874
|
+
emits: /*@__PURE__*/ mergeModels([
|
|
875
|
+
"commit",
|
|
876
|
+
"remove",
|
|
877
|
+
"changeQuery",
|
|
878
|
+
"motionComplete",
|
|
879
|
+
"focus",
|
|
880
|
+
"blur"
|
|
881
|
+
], ["update:isOpen"]),
|
|
882
|
+
setup(__props, { expose: __expose, emit: __emit }) {
|
|
883
|
+
/**
|
|
884
|
+
* Tokenizer 底部弹层呈现里的字段:沿用行内字段的框、主题挂点和聚焦描边,里面是
|
|
885
|
+
* 触发器、标签和末尾内容(上游 Tokenizer 的 sheet field)。
|
|
886
|
+
*
|
|
887
|
+
* 按钮里不能放控件,所以触发器、标签、末尾内容在框里是兄弟元素。有标签时触发器
|
|
888
|
+
* 铺满整个框,点标签或空白处都打开弹层;自定义标签里的控件、末尾内容自己处理点击。
|
|
889
|
+
* 默认标签只展示不能删,要删在弹层里取消勾选。
|
|
890
|
+
*
|
|
891
|
+
* 焦点从外面进入框时报 `focus`,离开整个字段时报 `blur`;进到自己的弹层、从弹层
|
|
892
|
+
* 回到触发器都还算在字段里。弹层从按下那一刻挂上,直到退场播完、焦点回到触发器。
|
|
893
|
+
*/
|
|
894
|
+
const props = __props;
|
|
895
|
+
const emit = __emit;
|
|
896
|
+
const isOpen = useModel(__props, "isOpen");
|
|
897
|
+
const messages = useComponentMessages({ tokenizer: tokenizerMessages });
|
|
898
|
+
const boxRef = useTemplateRef("boxRef");
|
|
899
|
+
const triggerRef = useTemplateRef("triggerRef");
|
|
900
|
+
const laneRef = useTemplateRef("laneRef");
|
|
901
|
+
const statusIconRef = useTemplateRef("statusIconRef");
|
|
902
|
+
const countId = `astryx-tokenizer-sheet-${useId()}-count`;
|
|
903
|
+
const tokenId = (index) => `${countId}-token-${index}`;
|
|
904
|
+
/** 弹层从按下挂到退场播完;平时字段只有触发器,没有关着的对话框、行和确认框。 */
|
|
905
|
+
const isSheetMounted = ref(false);
|
|
906
|
+
/** 字段替弹层保管查询:用户关闭会清空它,字段被禁用而强制关上时留着。 */
|
|
907
|
+
const sheetQuery = ref("");
|
|
908
|
+
let hasReportedFocus = false;
|
|
909
|
+
const describedBy = computed(() => [
|
|
910
|
+
props.describedBy,
|
|
911
|
+
props.values.length > 0 ? countId : null,
|
|
912
|
+
...props.values.map((_, index) => tokenId(index))
|
|
913
|
+
].filter(Boolean).join(" ") || void 0);
|
|
914
|
+
watch(isOpen, (open) => {
|
|
915
|
+
if (open) isSheetMounted.value = true;
|
|
916
|
+
}, { immediate: true });
|
|
917
|
+
watch(() => props.isDisabled, (disabled) => {
|
|
918
|
+
if (disabled && isOpen.value) isOpen.value = false;
|
|
919
|
+
});
|
|
920
|
+
function open() {
|
|
921
|
+
if (props.isDisabled) return;
|
|
922
|
+
isOpen.value = true;
|
|
923
|
+
}
|
|
924
|
+
function onMotionComplete(motion) {
|
|
925
|
+
if (motion === "exiting" && !isOpen.value) isSheetMounted.value = false;
|
|
926
|
+
emit("motionComplete", motion);
|
|
927
|
+
}
|
|
928
|
+
function onQueryChange(query) {
|
|
929
|
+
sheetQuery.value = query;
|
|
930
|
+
emit("changeQuery", query);
|
|
931
|
+
}
|
|
932
|
+
/** 点标签、占位文字、空白或纯展示的状态图标,和点触发器一样打开弹层。 */
|
|
933
|
+
function onBoxClick(event) {
|
|
934
|
+
const trigger = triggerRef.value;
|
|
935
|
+
const target = event.target;
|
|
936
|
+
if (trigger == null || !(target instanceof Element)) return;
|
|
937
|
+
const isInLane = laneRef.value?.contains(target) === true;
|
|
938
|
+
const isOnStatusIcon = statusIconRef.value?.contains(target) === true;
|
|
939
|
+
const interactive = target.closest("button, a, input, select, textarea, [tabindex]");
|
|
940
|
+
if (trigger.contains(target) || isInLane && !isOnStatusIcon || interactive != null && boxRef.value?.contains(interactive)) return;
|
|
941
|
+
trigger.click();
|
|
942
|
+
}
|
|
943
|
+
function onFocusIn(event) {
|
|
944
|
+
const related = event.relatedTarget;
|
|
945
|
+
if (related instanceof Node && boxRef.value?.contains(related)) return;
|
|
946
|
+
if (hasReportedFocus) return;
|
|
947
|
+
hasReportedFocus = true;
|
|
948
|
+
emit("focus", event);
|
|
949
|
+
}
|
|
950
|
+
function onFocusOut(event) {
|
|
951
|
+
const related = event.relatedTarget;
|
|
952
|
+
if (isOpen.value || related instanceof Node && boxRef.value?.contains(related)) return;
|
|
953
|
+
hasReportedFocus = false;
|
|
954
|
+
emit("blur", event);
|
|
955
|
+
}
|
|
956
|
+
__expose({
|
|
957
|
+
element: boxRef,
|
|
958
|
+
focus: (options) => triggerRef.value?.focus(options),
|
|
959
|
+
blur: () => triggerRef.value?.blur(),
|
|
960
|
+
/** 换呈现交来的焦点:之后的聚焦都算在字段里。 */
|
|
961
|
+
adoptFocus: () => {
|
|
962
|
+
hasReportedFocus = true;
|
|
963
|
+
}
|
|
964
|
+
});
|
|
965
|
+
return (_ctx, _cache) => {
|
|
966
|
+
return openBlock(), createElementBlock(Fragment, null, [
|
|
967
|
+
createCommentVNode(" eslint-disable-next-line vue-a11y/click-events-have-key-events, vue-a11y/no-static-element-interactions -- 点空白处只是转给触发器;键盘直接操作触发器。 "),
|
|
968
|
+
createElementVNode("div", {
|
|
969
|
+
ref_key: "boxRef",
|
|
970
|
+
ref: boxRef,
|
|
971
|
+
class: normalizeClass(["astryx-tokenizer-control astryx-tokenizer-sheet-field", [__props.controlClass, {
|
|
972
|
+
"is-disabled": __props.isDisabled,
|
|
973
|
+
"has-tokens": __props.values.length > 0,
|
|
974
|
+
"is-open": isOpen.value
|
|
975
|
+
}]]),
|
|
976
|
+
style: normalizeStyle(__props.controlStyle),
|
|
977
|
+
onClick: onBoxClick,
|
|
978
|
+
onFocusin: onFocusIn,
|
|
979
|
+
onFocusout: onFocusOut
|
|
980
|
+
}, [
|
|
981
|
+
_ctx.$slots.icon ? (openBlock(), createElementBlock("span", _hoisted_1$1, [renderSlot(_ctx.$slots, "icon")])) : createCommentVNode("v-if", true),
|
|
982
|
+
createElementVNode("span", _hoisted_2$1, [createElementVNode("button", mergeProps(_ctx.$attrs, {
|
|
983
|
+
id: __props.inputId,
|
|
984
|
+
ref_key: "triggerRef",
|
|
985
|
+
ref: triggerRef,
|
|
986
|
+
type: "button",
|
|
987
|
+
class: ["astryx-tokenizer-sheet-trigger", { "has-tokens": __props.values.length > 0 }],
|
|
988
|
+
"aria-haspopup": "dialog",
|
|
989
|
+
"aria-expanded": isOpen.value,
|
|
990
|
+
"aria-disabled": __props.isDisabled || void 0,
|
|
991
|
+
"aria-labelledby": __props.labelledBy,
|
|
992
|
+
"aria-describedby": describedBy.value,
|
|
993
|
+
onClick: open
|
|
994
|
+
}), [__props.values.length === 0 ? (openBlock(), createElementBlock("span", _hoisted_4$1, toDisplayString(__props.placeholder), 1)) : createCommentVNode("v-if", true)], 16, _hoisted_3$1), (openBlock(true), createElementBlock(Fragment, null, renderList(__props.values, (item, index) => {
|
|
995
|
+
return openBlock(), createElementBlock("span", {
|
|
996
|
+
id: _ctx.$slots.token ? void 0 : tokenId(index),
|
|
997
|
+
key: item.id,
|
|
998
|
+
class: "astryx-tokenizer-token"
|
|
999
|
+
}, [renderSlot(_ctx.$slots, "token", {
|
|
1000
|
+
item,
|
|
1001
|
+
remove: () => emit("remove", item)
|
|
1002
|
+
}, () => [createVNode(_sfc_main$15, {
|
|
1003
|
+
label: item.label,
|
|
1004
|
+
size: __props.size,
|
|
1005
|
+
disabled: __props.isDisabled
|
|
1006
|
+
}, null, 8, [
|
|
1007
|
+
"label",
|
|
1008
|
+
"size",
|
|
1009
|
+
"disabled"
|
|
1010
|
+
])])], 8, _hoisted_5$1);
|
|
1011
|
+
}), 128))]),
|
|
1012
|
+
_ctx.$slots.end || __props.statusIcon ? (openBlock(), createElementBlock("span", {
|
|
1013
|
+
key: 1,
|
|
1014
|
+
ref_key: "laneRef",
|
|
1015
|
+
ref: laneRef,
|
|
1016
|
+
class: "astryx-tokenizer-sheet-field__end"
|
|
1017
|
+
}, [renderSlot(_ctx.$slots, "end"), createElementVNode("span", {
|
|
1018
|
+
ref_key: "statusIconRef",
|
|
1019
|
+
ref: statusIconRef,
|
|
1020
|
+
class: "astryx-tokenizer-sheet-field__status"
|
|
1021
|
+
}, [__props.statusIcon ? (openBlock(), createBlock(resolveDynamicComponent(__props.statusIcon), normalizeProps(mergeProps({ key: 0 }, __props.statusIconProps)), null, 16)) : createCommentVNode("v-if", true)], 512)], 512)) : createCommentVNode("v-if", true),
|
|
1022
|
+
(openBlock(true), createElementBlock(Fragment, null, renderList(__props.isDisabled ? [] : __props.values, (item) => {
|
|
1023
|
+
return openBlock(), createElementBlock("input", {
|
|
1024
|
+
key: `${__props.name}-${item.id}`,
|
|
1025
|
+
type: "hidden",
|
|
1026
|
+
name: __props.name,
|
|
1027
|
+
value: item.id,
|
|
1028
|
+
disabled: !__props.name
|
|
1029
|
+
}, null, 8, _hoisted_6$1);
|
|
1030
|
+
}), 128))
|
|
1031
|
+
], 38),
|
|
1032
|
+
__props.values.length > 0 ? (openBlock(), createElementBlock("span", {
|
|
1033
|
+
key: 0,
|
|
1034
|
+
id: countId,
|
|
1035
|
+
class: "astryx-visually-hidden"
|
|
1036
|
+
}, toDisplayString(unref(messages).tokenizer.selectedCount(__props.values.length)), 1)) : createCommentVNode("v-if", true),
|
|
1037
|
+
_ctx.$slots.token ? (openBlock(true), createElementBlock(Fragment, { key: 1 }, renderList(__props.values, (item, index) => {
|
|
1038
|
+
return openBlock(), createElementBlock("span", {
|
|
1039
|
+
id: tokenId(index),
|
|
1040
|
+
key: item.id,
|
|
1041
|
+
hidden: ""
|
|
1042
|
+
}, toDisplayString(item.label), 9, _hoisted_7$1);
|
|
1043
|
+
}), 128)) : createCommentVNode("v-if", true),
|
|
1044
|
+
isSheetMounted.value ? (openBlock(), createBlock(_sfc_main$2, {
|
|
1045
|
+
key: 2,
|
|
1046
|
+
"is-open": isOpen.value,
|
|
1047
|
+
label: __props.label,
|
|
1048
|
+
"final-focus": triggerRef.value,
|
|
1049
|
+
"initial-query": sheetQuery.value,
|
|
1050
|
+
"search-source": __props.searchSource,
|
|
1051
|
+
value: __props.values,
|
|
1052
|
+
"max-entries": __props.maxEntries,
|
|
1053
|
+
"has-create": __props.hasCreate,
|
|
1054
|
+
"max-menu-items": __props.maxMenuItems,
|
|
1055
|
+
"min-query-length": __props.minQueryLength,
|
|
1056
|
+
"debounce-ms": __props.debounceMs,
|
|
1057
|
+
"empty-search-text": __props.emptySearchText,
|
|
1058
|
+
onClose: _cache[0] || (_cache[0] = ($event) => isOpen.value = false),
|
|
1059
|
+
onCommit: _cache[1] || (_cache[1] = (items, change) => emit("commit", items, change)),
|
|
1060
|
+
onChangeQuery: onQueryChange,
|
|
1061
|
+
onMotionComplete
|
|
1062
|
+
}, createSlots({ _: 2 }, [_ctx.$slots.empty ? {
|
|
1063
|
+
name: "empty",
|
|
1064
|
+
fn: withCtx(() => [renderSlot(_ctx.$slots, "empty")]),
|
|
1065
|
+
key: "0"
|
|
1066
|
+
} : void 0]), 1032, [
|
|
1067
|
+
"is-open",
|
|
1068
|
+
"label",
|
|
1069
|
+
"final-focus",
|
|
1070
|
+
"initial-query",
|
|
1071
|
+
"search-source",
|
|
1072
|
+
"value",
|
|
1073
|
+
"max-entries",
|
|
1074
|
+
"has-create",
|
|
1075
|
+
"max-menu-items",
|
|
1076
|
+
"min-query-length",
|
|
1077
|
+
"debounce-ms",
|
|
1078
|
+
"empty-search-text"
|
|
1079
|
+
])) : createCommentVNode("v-if", true)
|
|
1080
|
+
], 64);
|
|
1081
|
+
};
|
|
1082
|
+
}
|
|
1083
|
+
});
|
|
1084
|
+
//#endregion
|
|
1085
|
+
//#region src/Tokenizer/useTokenizerDisabled.ts
|
|
1086
|
+
/**
|
|
1087
|
+
* 禁用的 Tokenizer 仍是 Tab 停点:输入框用 aria-disabled 加只读,不用原生 disabled,
|
|
1088
|
+
* 有禁用说明时悬停和键盘聚焦都能读到它。
|
|
1089
|
+
* 例外是 `overflow="unfocused-layer"` 且没有说明:输入框在失焦时才展开的浮层里,
|
|
1090
|
+
* 禁用的字段打不开那层,此时仍用原生 disabled。
|
|
1091
|
+
*/
|
|
1092
|
+
function useTokenizerDisabled(props) {
|
|
1093
|
+
/** 新名 disabledMessage 优先,旧名 disabledReason 继续可用。 */
|
|
1094
|
+
const disabledMessage = computed(() => {
|
|
1095
|
+
const message = props.disabledMessage?.trim() ? props.disabledMessage : props.disabledReason;
|
|
1096
|
+
return message?.trim() ? message : void 0;
|
|
1097
|
+
});
|
|
1098
|
+
const showsDisabledMessage = computed(() => Boolean(props.disabled) && Boolean(disabledMessage.value));
|
|
1099
|
+
return {
|
|
1100
|
+
disabledMessage,
|
|
1101
|
+
showsDisabledMessage,
|
|
1102
|
+
focusableDisabled: computed(() => Boolean(props.disabled) && (showsDisabledMessage.value || props.overflow !== "unfocused-layer")),
|
|
1103
|
+
disabledTooltip: useButtonTooltip(showsDisabledMessage)
|
|
1104
|
+
};
|
|
1105
|
+
}
|
|
1106
|
+
//#endregion
|
|
1107
|
+
//#region src/Tokenizer/useTokenizerFieldAria.ts
|
|
1108
|
+
/** 输入框的名字、说明和状态图标。 */
|
|
1109
|
+
function useTokenizerFieldAria(options) {
|
|
1110
|
+
const { props, attrs, inputId, fieldLabelId, disabledId, hasDisabledDescription } = options;
|
|
1111
|
+
const fieldStatus = computed(() => {
|
|
1112
|
+
if (!props.statusMessage || props.status === "default") return void 0;
|
|
1113
|
+
return {
|
|
1114
|
+
type: props.status,
|
|
1115
|
+
message: props.statusMessage
|
|
1116
|
+
};
|
|
1117
|
+
});
|
|
1118
|
+
/** 调用方的 aria-labelledby 接在字段自己的标签后面,不取代它。 */
|
|
1119
|
+
const labelledBy = computed(() => {
|
|
1120
|
+
const external = attrs["aria-labelledby"];
|
|
1121
|
+
return typeof external === "string" && external !== "" ? `${fieldLabelId} ${external}` : void 0;
|
|
1122
|
+
});
|
|
1123
|
+
const { statusIcon, statusIconProps } = useInputStatusIcon({
|
|
1124
|
+
status: () => fieldStatus.value,
|
|
1125
|
+
statusVariant: () => props.statusVariant ?? "attached"
|
|
1126
|
+
});
|
|
1127
|
+
return {
|
|
1128
|
+
fieldStatus,
|
|
1129
|
+
labelledBy,
|
|
1130
|
+
statusIcon,
|
|
1131
|
+
statusIconProps,
|
|
1132
|
+
describedBy: computed(() => {
|
|
1133
|
+
return [
|
|
1134
|
+
typeof attrs["aria-describedby"] === "string" ? attrs["aria-describedby"] : void 0,
|
|
1135
|
+
props.description ? `${inputId}-description` : void 0,
|
|
1136
|
+
props.statusMessage ? `${inputId}-status` : void 0,
|
|
1137
|
+
hasDisabledDescription.value ? disabledId : void 0
|
|
1138
|
+
].filter(Boolean).join(" ") || void 0;
|
|
1139
|
+
})
|
|
1140
|
+
};
|
|
1141
|
+
}
|
|
1142
|
+
//#endregion
|
|
1143
|
+
//#region src/Tokenizer/useTokenizerKeys.ts
|
|
1144
|
+
/** 输入框和标签上的按键:退格删最后一个、方向键在标签和输入框之间移动焦点。 */
|
|
1145
|
+
function useTokenizerKeys(options) {
|
|
1146
|
+
const { values, menu, optionGrid, inputRef, remove, focusToken } = options;
|
|
1147
|
+
function onInputKeyDown(event) {
|
|
1148
|
+
if (event.defaultPrevented || isImeKeyEvent(event)) return;
|
|
1149
|
+
if (optionGrid.actionGrid.onKeyDown(event)) return;
|
|
1150
|
+
const input = inputRef.value;
|
|
1151
|
+
if (event.key === "Backspace" && menu.query.value === "" && values.value.length > 0) {
|
|
1152
|
+
event.preventDefault();
|
|
1153
|
+
const last = values.value[values.value.length - 1];
|
|
1154
|
+
if (last) remove(last);
|
|
1155
|
+
return;
|
|
1156
|
+
}
|
|
1157
|
+
if (event.key === "ArrowLeft" && input && input.selectionStart === 0 && input.selectionEnd === 0 && values.value.length > 0) {
|
|
1158
|
+
event.preventDefault();
|
|
1159
|
+
focusToken(values.value.length - 1);
|
|
1160
|
+
return;
|
|
1161
|
+
}
|
|
1162
|
+
menu.onKeyDown(event);
|
|
1163
|
+
}
|
|
1164
|
+
function onTokenKeyDown(event, item, index) {
|
|
1165
|
+
if (event.key === "ArrowLeft" && index > 0) {
|
|
1166
|
+
event.preventDefault();
|
|
1167
|
+
focusToken(index - 1);
|
|
1168
|
+
} else if (event.key === "ArrowRight") {
|
|
1169
|
+
event.preventDefault();
|
|
1170
|
+
if (index < values.value.length - 1) focusToken(index + 1);
|
|
1171
|
+
else inputRef.value?.focus();
|
|
1172
|
+
} else if (event.key === "Escape") inputRef.value?.focus();
|
|
1173
|
+
else if (!options.disabled() && (event.key === "Backspace" || event.key === "Delete")) {
|
|
1174
|
+
event.preventDefault();
|
|
1175
|
+
remove(item);
|
|
1176
|
+
if (index > 0) focusToken(index - 1);
|
|
1177
|
+
}
|
|
1178
|
+
}
|
|
1179
|
+
return {
|
|
1180
|
+
onInputKeyDown,
|
|
1181
|
+
onTokenKeyDown
|
|
1182
|
+
};
|
|
1183
|
+
}
|
|
1184
|
+
//#endregion
|
|
1185
|
+
//#region src/Tokenizer/useTokenizerMenu.ts
|
|
1186
|
+
/** 行内呈现的结果菜单:搜索、播报、菜单配置、锚定位置和选项网格。 */
|
|
1187
|
+
function useTokenizerMenu(options) {
|
|
1188
|
+
const { props, values, atMax, showsEntriesOnFocus, inputRef } = options;
|
|
1189
|
+
const listboxRef = computed(() => options.popupEl());
|
|
1190
|
+
useScrollbars(listboxRef);
|
|
1191
|
+
const menu = useTypeaheadMenu({
|
|
1192
|
+
source: () => props.searchSource,
|
|
1193
|
+
debounceMs: () => props.debounceMs ?? 150,
|
|
1194
|
+
showOnFocus: () => showsEntriesOnFocus.value && !atMax.value,
|
|
1195
|
+
minQueryLength: () => props.minQueryLength ?? 1,
|
|
1196
|
+
maxItems: () => props.maxMenuItems ?? 10,
|
|
1197
|
+
disabled: () => Boolean(props.disabled) || atMax.value || props.menu?.role === "dialog",
|
|
1198
|
+
excludeIds: () => values.value.map((item) => item.id),
|
|
1199
|
+
blockedLabels: () => values.value.map((item) => item.label),
|
|
1200
|
+
creatable: () => options.isCreatable.value && !atMax.value,
|
|
1201
|
+
createLabel: (query) => options.messages().create(query),
|
|
1202
|
+
onSelect: options.onSelect,
|
|
1203
|
+
onQueryChange: options.onQueryChange
|
|
1204
|
+
});
|
|
1205
|
+
/** 搜索忙碌时由输入框念一次「加载中」;列表里的转圈只是装饰。 */
|
|
1206
|
+
const settleBusy = useBusyAnnouncement(() => menu.status.value === "loading", () => options.messages().loading, inputRef);
|
|
1207
|
+
useTypeaheadAnnouncement({
|
|
1208
|
+
menu,
|
|
1209
|
+
settleBusy,
|
|
1210
|
+
emptyText: () => options.emptyText.value,
|
|
1211
|
+
emptySearchText: () => options.emptyText.value,
|
|
1212
|
+
resultCount: (count) => options.messages().resultCount(count)
|
|
1213
|
+
});
|
|
1214
|
+
const menuConfig = useTypeaheadMenuConfig({
|
|
1215
|
+
config: () => props.menu,
|
|
1216
|
+
popupEl: () => listboxRef.value,
|
|
1217
|
+
inputEl: () => inputRef.value,
|
|
1218
|
+
listbox: {
|
|
1219
|
+
isOpen: menu.combobox.isOpen,
|
|
1220
|
+
open: () => menu.open(),
|
|
1221
|
+
close: () => menu.close()
|
|
1222
|
+
},
|
|
1223
|
+
isDisabled: () => Boolean(props.disabled),
|
|
1224
|
+
canOpenList: () => showsEntriesOnFocus.value || menu.query.value !== ""
|
|
1225
|
+
});
|
|
1226
|
+
const anchored = useAnchoredListbox({
|
|
1227
|
+
anchor: options.anchorRef,
|
|
1228
|
+
layer: listboxRef,
|
|
1229
|
+
isOpen: menuConfig.popupOpen,
|
|
1230
|
+
menuWidth: () => props.menuWidth,
|
|
1231
|
+
onDismiss: () => menuConfig.isDialog.value ? menuConfig.dismiss() : menu.close()
|
|
1232
|
+
});
|
|
1233
|
+
watch(menuConfig.popupOpen, (isOpen) => options.onOpenChange(isOpen));
|
|
1234
|
+
watch(() => menu.combobox.activeIndex.value, (index) => {
|
|
1235
|
+
if (!menu.combobox.isOpen.value || index < 0) return;
|
|
1236
|
+
nextTick(() => scrollOptionIntoView(listboxRef.value, menu.entries.value[index]?.id));
|
|
1237
|
+
});
|
|
1238
|
+
const optionGrid = useLatchedOptionGrid({
|
|
1239
|
+
entries: () => menu.entries.value,
|
|
1240
|
+
isOpen: () => menu.combobox.isOpen.value,
|
|
1241
|
+
activeIndex: menu.combobox.activeIndex,
|
|
1242
|
+
getListbox: () => listboxRef.value,
|
|
1243
|
+
listboxId: () => options.listboxId
|
|
1244
|
+
});
|
|
1245
|
+
function highlight(index) {
|
|
1246
|
+
const entry = menu.entries.value[index];
|
|
1247
|
+
if (entry && !entry.disabled) menu.combobox.activeIndex.value = index;
|
|
1248
|
+
}
|
|
1249
|
+
function selectById(id) {
|
|
1250
|
+
const entry = menu.entries.value.find((item) => item.id === id);
|
|
1251
|
+
if (entry && !entry.disabled) options.onSelect(entry);
|
|
1252
|
+
}
|
|
1253
|
+
return {
|
|
1254
|
+
menu,
|
|
1255
|
+
menuConfig,
|
|
1256
|
+
anchored,
|
|
1257
|
+
optionGrid,
|
|
1258
|
+
listboxRef,
|
|
1259
|
+
highlight,
|
|
1260
|
+
selectById
|
|
1261
|
+
};
|
|
1262
|
+
}
|
|
1263
|
+
//#endregion
|
|
1264
|
+
//#region src/Tokenizer/useTokenizerPresentation.ts
|
|
1265
|
+
const warnedInertSets = /* @__PURE__ */ new Set();
|
|
1266
|
+
/** 在底部弹层呈现里没有地方生效的属性名。 */
|
|
1267
|
+
function inertSheetProps(props, hasItemSlot) {
|
|
1268
|
+
return [
|
|
1269
|
+
["item slot", hasItemSlot],
|
|
1270
|
+
["hasClear", Boolean(props.hasClear || props.clearable)],
|
|
1271
|
+
["hasEntriesOnFocus", Boolean(props.hasEntriesOnFocus || props.showOnFocus)],
|
|
1272
|
+
["menuWidth", props.menuWidth != null],
|
|
1273
|
+
["menu", props.menu != null],
|
|
1274
|
+
["overflow", props.overflow != null && props.overflow !== "none"],
|
|
1275
|
+
["hasAutoFocus", Boolean(props.hasAutoFocus)]
|
|
1276
|
+
].filter(([, isSet]) => isSet).map(([name]) => name);
|
|
1277
|
+
}
|
|
1278
|
+
/**
|
|
1279
|
+
* Tokenizer 的呈现:行内浮层还是触屏底部弹层(上游 isSheetPresented 闩锁)。
|
|
1280
|
+
*
|
|
1281
|
+
* 换呈现时焦点在旧控件上,就交给新控件(输入框和触发器互换),不掉回页面。
|
|
1282
|
+
* 底部弹层可能成为呈现时先把它的模块加载好。只描述行内菜单的属性在底部弹层里
|
|
1283
|
+
* 没有地方生效,开发期提示一次。
|
|
1284
|
+
*/
|
|
1285
|
+
function useTokenizerPresentation(options) {
|
|
1286
|
+
const { props } = options;
|
|
1287
|
+
const sheetOpen = ref(false);
|
|
1288
|
+
let isHandingOff = false;
|
|
1289
|
+
const { isSheet, settle } = useHeldPresentation(() => props.presentation ?? "adaptive", sheetOpen);
|
|
1290
|
+
watch(isSheet, (sheet) => {
|
|
1291
|
+
if (sheet) preloadBottomSheet();
|
|
1292
|
+
const root = options.root();
|
|
1293
|
+
const active = root?.ownerDocument.activeElement;
|
|
1294
|
+
if (root == null || active == null || !root.contains(active)) return;
|
|
1295
|
+
nextTick(() => {
|
|
1296
|
+
isHandingOff = true;
|
|
1297
|
+
try {
|
|
1298
|
+
options.focusControl();
|
|
1299
|
+
} finally {
|
|
1300
|
+
isHandingOff = false;
|
|
1301
|
+
}
|
|
1302
|
+
});
|
|
1303
|
+
}, { flush: "pre" });
|
|
1304
|
+
if (isDevBuild()) {
|
|
1305
|
+
const inert = computed(() => isSheet.value ? inertSheetProps(props, options.hasItemSlot()) : []);
|
|
1306
|
+
watch(inert, (names) => {
|
|
1307
|
+
const key = names.join(",");
|
|
1308
|
+
if (key === "" || warnedInertSets.has(key)) return;
|
|
1309
|
+
warnedInertSets.add(key);
|
|
1310
|
+
devWarn("Tokenizer", `\`${names.join("`, `")}\` ${names.length === 1 ? "has" : "have"} no surface in the bottom-sheet presentation and ${names.length === 1 ? "is" : "are"} not rendered there. Pass \`presentation="popover"\` to keep the inline field on every device.`);
|
|
1311
|
+
}, { immediate: true });
|
|
1312
|
+
}
|
|
1313
|
+
return {
|
|
1314
|
+
sheetOpen,
|
|
1315
|
+
isSheet,
|
|
1316
|
+
onSheetMotionComplete: (motion) => {
|
|
1317
|
+
if (motion === "exiting") settle();
|
|
1318
|
+
},
|
|
1319
|
+
isHandingOffFocus: () => isHandingOff
|
|
1320
|
+
};
|
|
1321
|
+
}
|
|
1322
|
+
//#endregion
|
|
1323
|
+
//#region src/Tokenizer/useTokenizerSelection.ts
|
|
1324
|
+
/** Tokenizer 选择的增删:两种呈现共用提交和播报,行内菜单的焦点与清单去留也在这里。 */
|
|
1325
|
+
function useTokenizerSelection(options) {
|
|
1326
|
+
const { values, menu, menuConfig, inputRef } = options;
|
|
1327
|
+
function commit(next, change) {
|
|
1328
|
+
options.emitChange(next, change);
|
|
1329
|
+
}
|
|
1330
|
+
function add(item, type) {
|
|
1331
|
+
if (options.isDisabled() || options.atMax.value || values.value.some((entry) => entry.id === item.id)) return;
|
|
1332
|
+
const fromFocusList = options.showsEntriesOnFocus.value && type === "add" && menu.query.value === "";
|
|
1333
|
+
const pickedIndex = Math.max(0, menu.entries.value.findIndex((entry) => entry.item.id === item.id));
|
|
1334
|
+
menuConfig.beginPick();
|
|
1335
|
+
commit([...values.value, item], {
|
|
1336
|
+
type,
|
|
1337
|
+
item
|
|
1338
|
+
});
|
|
1339
|
+
options.announce(options.messages().added(item.label));
|
|
1340
|
+
menu.resetQuery();
|
|
1341
|
+
if (!fromFocusList && !menuConfig.endPick()) menu.close();
|
|
1342
|
+
nextTick(() => {
|
|
1343
|
+
inputRef.value?.focus();
|
|
1344
|
+
if (!fromFocusList) return;
|
|
1345
|
+
const remaining = menu.entries.value;
|
|
1346
|
+
if (remaining.length === 0 || options.atMax.value || options.isDisabled()) menu.close();
|
|
1347
|
+
else menu.combobox.activeIndex.value = Math.min(pickedIndex, remaining.length - 1);
|
|
1348
|
+
});
|
|
1349
|
+
}
|
|
1350
|
+
function remove(item) {
|
|
1351
|
+
if (options.isDisabled()) return false;
|
|
1352
|
+
commit(values.value.filter((entry) => entry.id !== item.id), {
|
|
1353
|
+
type: "remove",
|
|
1354
|
+
item
|
|
1355
|
+
});
|
|
1356
|
+
options.announce(options.messages().removed(item.label));
|
|
1357
|
+
return true;
|
|
1358
|
+
}
|
|
1359
|
+
function clearAll(event) {
|
|
1360
|
+
event?.stopPropagation();
|
|
1361
|
+
if (options.isDisabled() || values.value.length === 0) return;
|
|
1362
|
+
commit([], { type: "clear" });
|
|
1363
|
+
options.announce(options.messages().allRemoved);
|
|
1364
|
+
menu.close();
|
|
1365
|
+
inputRef.value?.focus();
|
|
1366
|
+
}
|
|
1367
|
+
return {
|
|
1368
|
+
commit,
|
|
1369
|
+
add,
|
|
1370
|
+
remove,
|
|
1371
|
+
clearAll
|
|
1372
|
+
};
|
|
1373
|
+
}
|
|
1374
|
+
//#endregion
|
|
1375
|
+
//#region src/Tokenizer/Tokenizer.vue
|
|
1376
|
+
const _hoisted_1 = {
|
|
1377
|
+
key: 0,
|
|
1378
|
+
class: "astryx-tokenizer-icon",
|
|
1379
|
+
"aria-hidden": "true"
|
|
1380
|
+
};
|
|
1381
|
+
const _hoisted_2 = ["onKeydown"];
|
|
1382
|
+
const _hoisted_3 = {
|
|
1383
|
+
key: 0,
|
|
1384
|
+
class: "astryx-tokenizer-more"
|
|
1385
|
+
};
|
|
1386
|
+
const _hoisted_4 = {
|
|
1387
|
+
class: "astryx-tokenizer-more",
|
|
1388
|
+
"data-overflow-indicator": ""
|
|
1389
|
+
};
|
|
1390
|
+
const _hoisted_5 = [
|
|
1391
|
+
"data-autofocus",
|
|
1392
|
+
"placeholder",
|
|
1393
|
+
"value",
|
|
1394
|
+
"disabled",
|
|
1395
|
+
"readonly",
|
|
1396
|
+
"aria-disabled",
|
|
1397
|
+
"aria-expanded",
|
|
1398
|
+
"aria-haspopup",
|
|
1399
|
+
"aria-activedescendant",
|
|
1400
|
+
"aria-labelledby",
|
|
1401
|
+
"aria-describedby",
|
|
1402
|
+
"aria-required",
|
|
1403
|
+
"aria-invalid"
|
|
1404
|
+
];
|
|
1405
|
+
const _hoisted_6 = ["aria-label"];
|
|
1406
|
+
const _hoisted_7 = [
|
|
1407
|
+
"name",
|
|
1408
|
+
"value",
|
|
1409
|
+
"disabled"
|
|
1410
|
+
];
|
|
1411
|
+
const _sfc_main = /*@__PURE__*/ defineComponent({
|
|
1412
|
+
name: "AstryxTokenizer",
|
|
1413
|
+
inheritAttrs: false,
|
|
1414
|
+
__name: "Tokenizer",
|
|
1415
|
+
props: {
|
|
1416
|
+
modelValue: { default: () => [] },
|
|
1417
|
+
menu: {},
|
|
1418
|
+
searchSource: {},
|
|
1419
|
+
label: {},
|
|
1420
|
+
isLabelHidden: { type: Boolean },
|
|
1421
|
+
labelHidden: {
|
|
1422
|
+
type: Boolean,
|
|
1423
|
+
default: false
|
|
1424
|
+
},
|
|
1425
|
+
description: {},
|
|
1426
|
+
labelTooltip: {},
|
|
1427
|
+
placeholder: {},
|
|
1428
|
+
disabled: {
|
|
1429
|
+
type: Boolean,
|
|
1430
|
+
default: false
|
|
1431
|
+
},
|
|
1432
|
+
disabledReason: {},
|
|
1433
|
+
disabledMessage: {},
|
|
1434
|
+
status: { default: "default" },
|
|
1435
|
+
statusMessage: {},
|
|
1436
|
+
statusVariant: { default: "attached" },
|
|
1437
|
+
size: {},
|
|
1438
|
+
clearable: {
|
|
1439
|
+
type: Boolean,
|
|
1440
|
+
default: false
|
|
1441
|
+
},
|
|
1442
|
+
hasClear: {
|
|
1443
|
+
type: Boolean,
|
|
1444
|
+
default: false
|
|
1445
|
+
},
|
|
1446
|
+
debounceMs: { default: 150 },
|
|
1447
|
+
maxMenuItems: { default: 10 },
|
|
1448
|
+
menuWidth: {},
|
|
1449
|
+
minQueryLength: { default: 1 },
|
|
1450
|
+
showOnFocus: {
|
|
1451
|
+
type: Boolean,
|
|
1452
|
+
default: false
|
|
1453
|
+
},
|
|
1454
|
+
hasEntriesOnFocus: { type: Boolean },
|
|
1455
|
+
hasAutoFocus: {
|
|
1456
|
+
type: Boolean,
|
|
1457
|
+
default: false
|
|
1458
|
+
},
|
|
1459
|
+
emptyText: {},
|
|
1460
|
+
emptySearchText: {},
|
|
1461
|
+
maxEntries: {},
|
|
1462
|
+
creatable: {
|
|
1463
|
+
type: Boolean,
|
|
1464
|
+
default: false
|
|
1465
|
+
},
|
|
1466
|
+
hasCreate: {
|
|
1467
|
+
type: Boolean,
|
|
1468
|
+
default: false
|
|
1469
|
+
},
|
|
1470
|
+
overflow: { default: "none" },
|
|
1471
|
+
required: {
|
|
1472
|
+
type: Boolean,
|
|
1473
|
+
default: false
|
|
1474
|
+
},
|
|
1475
|
+
optional: {
|
|
1476
|
+
type: Boolean,
|
|
1477
|
+
default: false
|
|
1478
|
+
},
|
|
1479
|
+
name: {},
|
|
1480
|
+
width: {},
|
|
1481
|
+
presentation: { default: "adaptive" },
|
|
1482
|
+
containerClass: { type: [
|
|
1483
|
+
Boolean,
|
|
1484
|
+
null,
|
|
1485
|
+
String,
|
|
1486
|
+
Object,
|
|
1487
|
+
Array
|
|
1488
|
+
] },
|
|
1489
|
+
containerStyle: { type: [
|
|
1490
|
+
Boolean,
|
|
1491
|
+
null,
|
|
1492
|
+
String,
|
|
1493
|
+
Object,
|
|
1494
|
+
Array
|
|
1495
|
+
] },
|
|
1496
|
+
controlClass: { type: [
|
|
1497
|
+
Boolean,
|
|
1498
|
+
null,
|
|
1499
|
+
String,
|
|
1500
|
+
Object,
|
|
1501
|
+
Array
|
|
1502
|
+
] },
|
|
1503
|
+
controlStyle: { type: [
|
|
1504
|
+
Boolean,
|
|
1505
|
+
null,
|
|
1506
|
+
String,
|
|
1507
|
+
Object,
|
|
1508
|
+
Array
|
|
1509
|
+
] }
|
|
1510
|
+
},
|
|
1511
|
+
emits: [
|
|
1512
|
+
"update:modelValue",
|
|
1513
|
+
"change",
|
|
1514
|
+
"search",
|
|
1515
|
+
"changeQuery",
|
|
1516
|
+
"openChange",
|
|
1517
|
+
"focus",
|
|
1518
|
+
"blur"
|
|
1519
|
+
],
|
|
1520
|
+
setup(__props, { expose: __expose, emit: __emit }) {
|
|
1521
|
+
const props = __props;
|
|
1522
|
+
const emit = __emit;
|
|
1523
|
+
if (isDevBuild() && props.modelValue != null && !Array.isArray(props.modelValue)) throw devPropError("Tokenizer", "modelValue", "must be an array of the selected items, for example v-model=\"selected\" with const selected = ref([]).");
|
|
1524
|
+
const size = useSize(() => props.size, "md");
|
|
1525
|
+
const attrs = useAttrs();
|
|
1526
|
+
const parts = useFieldPartStyling({
|
|
1527
|
+
component: "Tokenizer",
|
|
1528
|
+
props,
|
|
1529
|
+
attrs,
|
|
1530
|
+
reservedAttrs: [
|
|
1531
|
+
"id",
|
|
1532
|
+
"role",
|
|
1533
|
+
"aria-label",
|
|
1534
|
+
"aria-labelledby",
|
|
1535
|
+
"aria-describedby",
|
|
1536
|
+
"aria-expanded",
|
|
1537
|
+
"aria-controls",
|
|
1538
|
+
"aria-haspopup",
|
|
1539
|
+
"aria-activedescendant",
|
|
1540
|
+
"aria-autocomplete",
|
|
1541
|
+
"aria-disabled",
|
|
1542
|
+
"aria-required"
|
|
1543
|
+
]
|
|
1544
|
+
});
|
|
1545
|
+
const messages = useComponentMessages({ tokenizer: tokenizerMessages });
|
|
1546
|
+
/** 正名 isLabelHidden,旧名 labelHidden 任一为真就藏起标签。 */
|
|
1547
|
+
const hideLabel = useResolvedLabelHidden(() => props.isLabelHidden, () => props.labelHidden);
|
|
1548
|
+
const inputId = `astryx-tokenizer-${useId()}`;
|
|
1549
|
+
const listboxId = `${inputId}-listbox`;
|
|
1550
|
+
const fieldLabelId = `${inputId}-label`;
|
|
1551
|
+
const disabledId = `${inputId}-disabled`;
|
|
1552
|
+
const disabledTooltipId = `${inputId}-disabled-tooltip`;
|
|
1553
|
+
const values = computed(() => props.modelValue ?? []);
|
|
1554
|
+
const focused = ref(false);
|
|
1555
|
+
const placeholderHeight = ref(0);
|
|
1556
|
+
const announce = useAnnounce();
|
|
1557
|
+
const anchorRef = useTemplateRef("anchorRef");
|
|
1558
|
+
const popupRef = useTemplateRef("popupRef");
|
|
1559
|
+
const inputRef = useTemplateRef("inputRef");
|
|
1560
|
+
const tokenEls = /* @__PURE__ */ new Map();
|
|
1561
|
+
const sheetFieldRef = useTemplateRef("sheetFieldRef");
|
|
1562
|
+
const slots = useSlots();
|
|
1563
|
+
const { sheetOpen, isSheet, onSheetMotionComplete, isHandingOffFocus } = useTokenizerPresentation({
|
|
1564
|
+
props,
|
|
1565
|
+
hasItemSlot: () => slots.item != null,
|
|
1566
|
+
root: () => anchorRef.value ?? sheetFieldRef.value?.element,
|
|
1567
|
+
focusControl: () => {
|
|
1568
|
+
sheetFieldRef.value?.adoptFocus();
|
|
1569
|
+
focusControl();
|
|
1570
|
+
}
|
|
1571
|
+
});
|
|
1572
|
+
const placeholder = computed(() => props.placeholder ?? messages.value.tokenizer.placeholder);
|
|
1573
|
+
const emptyText = computed(() => props.emptySearchText ?? props.emptyText ?? messages.value.tokenizer.empty);
|
|
1574
|
+
const { disabledMessage, showsDisabledMessage, focusableDisabled, disabledTooltip } = useTokenizerDisabled(props);
|
|
1575
|
+
/** 两个名字任一为真就画清除按钮。 */
|
|
1576
|
+
const showsClear = computed(() => props.hasClear || props.clearable);
|
|
1577
|
+
/** 两个名字任一为真就在聚焦时先展开。 */
|
|
1578
|
+
const showsEntriesOnFocus = computed(() => props.hasEntriesOnFocus || props.showOnFocus);
|
|
1579
|
+
/** 两个名字任一为真就能从输入的文字新建标签。 */
|
|
1580
|
+
const isCreatable = computed(() => props.hasCreate || props.creatable);
|
|
1581
|
+
/** 禁用的字段不向表单交值:不渲染隐藏输入,而不是渲染一个原生禁用的。 */
|
|
1582
|
+
const hiddenCarrierItems = computed(() => props.disabled ? [] : values.value);
|
|
1583
|
+
const atMax = computed(() => props.maxEntries != null && values.value.length >= props.maxEntries);
|
|
1584
|
+
const collapsed = computed(() => props.overflow !== "none" && !focused.value);
|
|
1585
|
+
const floating = computed(() => props.overflow === "unfocused-layer" && focused.value);
|
|
1586
|
+
const { fieldStatus, labelledBy, statusIcon, statusIconProps, describedBy } = useTokenizerFieldAria({
|
|
1587
|
+
props,
|
|
1588
|
+
attrs,
|
|
1589
|
+
inputId,
|
|
1590
|
+
fieldLabelId,
|
|
1591
|
+
disabledId,
|
|
1592
|
+
hasDisabledDescription: computed(() => focusableDisabled.value && Boolean(disabledMessage.value))
|
|
1593
|
+
});
|
|
1594
|
+
function inputAttrs() {
|
|
1595
|
+
return pickInputAttrs(attrs);
|
|
1596
|
+
}
|
|
1597
|
+
const { menu, menuConfig, anchored, optionGrid, listboxRef, highlight, selectById } = useTokenizerMenu({
|
|
1598
|
+
props,
|
|
1599
|
+
values,
|
|
1600
|
+
atMax,
|
|
1601
|
+
showsEntriesOnFocus,
|
|
1602
|
+
isCreatable,
|
|
1603
|
+
emptyText,
|
|
1604
|
+
messages: () => messages.value.tokenizer,
|
|
1605
|
+
listboxId,
|
|
1606
|
+
anchorRef,
|
|
1607
|
+
inputRef,
|
|
1608
|
+
popupEl: () => popupRef.value?.el ?? null,
|
|
1609
|
+
onSelect: addEntry,
|
|
1610
|
+
onQueryChange: (query) => {
|
|
1611
|
+
emit("search", query);
|
|
1612
|
+
emit("changeQuery", query);
|
|
1613
|
+
},
|
|
1614
|
+
onOpenChange: (isOpen) => emit("openChange", isOpen)
|
|
1615
|
+
});
|
|
1616
|
+
onMounted(() => {
|
|
1617
|
+
if (props.hasAutoFocus) inputRef.value?.focus();
|
|
1618
|
+
});
|
|
1619
|
+
const removeTap = useTokenRemoveTap({
|
|
1620
|
+
root: anchorRef,
|
|
1621
|
+
input: inputRef,
|
|
1622
|
+
tokenSelector: ".astryx-tokenizer-token"
|
|
1623
|
+
});
|
|
1624
|
+
const tokenCount = computed(() => values.value.length);
|
|
1625
|
+
const overflow = useOverflow(tokenCount, { gap: 4 });
|
|
1626
|
+
const visibleCount = computed(() => collapsed.value ? overflow.visibleCount.value : tokenCount.value);
|
|
1627
|
+
const hiddenCount = computed(() => Math.max(0, tokenCount.value - visibleCount.value));
|
|
1628
|
+
const measureMoreLabel = computed(() => messages.value.tokenizer.more(Math.max(hiddenCount.value, 1)));
|
|
1629
|
+
const visibleItems = computed(() => values.value.slice(0, visibleCount.value));
|
|
1630
|
+
watch(collapsed, () => void nextTick(() => overflow.remeasure()));
|
|
1631
|
+
const selection = useTokenizerSelection({
|
|
1632
|
+
values,
|
|
1633
|
+
isDisabled: () => props.disabled,
|
|
1634
|
+
atMax,
|
|
1635
|
+
showsEntriesOnFocus,
|
|
1636
|
+
menu,
|
|
1637
|
+
menuConfig,
|
|
1638
|
+
inputRef,
|
|
1639
|
+
messages: () => messages.value.tokenizer,
|
|
1640
|
+
announce,
|
|
1641
|
+
emitChange: (next, change) => {
|
|
1642
|
+
emit("update:modelValue", next);
|
|
1643
|
+
emit("change", next, change);
|
|
1644
|
+
}
|
|
1645
|
+
});
|
|
1646
|
+
function remove(item) {
|
|
1647
|
+
if (!selection.remove(item)) return;
|
|
1648
|
+
if (isSheet.value) nextTick(() => sheetFieldRef.value?.focus());
|
|
1649
|
+
else if (removeTap.shouldFocusInputAfterRemove()) nextTick(() => inputRef.value?.focus());
|
|
1650
|
+
}
|
|
1651
|
+
function setTokenEl(index, element) {
|
|
1652
|
+
if (element instanceof HTMLElement) tokenEls.set(index, element);
|
|
1653
|
+
else tokenEls.delete(index);
|
|
1654
|
+
}
|
|
1655
|
+
function focusToken(index) {
|
|
1656
|
+
nextTick(() => tokenEls.get(index)?.focus());
|
|
1657
|
+
}
|
|
1658
|
+
function onInput(event) {
|
|
1659
|
+
if (props.disabled || atMax.value) return;
|
|
1660
|
+
menu.setQuery(event.target.value);
|
|
1661
|
+
}
|
|
1662
|
+
/** 焦点从外面进来(而不是在字段内部换元素)才算。 */
|
|
1663
|
+
function onFocusIn(event) {
|
|
1664
|
+
const comingFromOutside = !isInsideTokenizer(event.relatedTarget);
|
|
1665
|
+
disabledTooltip.onTooltipPointerEnter();
|
|
1666
|
+
if (!focused.value && props.overflow === "unfocused-layer") placeholderHeight.value = anchorRef.value?.offsetHeight ?? 0;
|
|
1667
|
+
focused.value = true;
|
|
1668
|
+
if (event.target === inputRef.value && showsEntriesOnFocus.value && !props.disabled && !atMax.value) menu.open();
|
|
1669
|
+
if (comingFromOutside && !isHandingOffFocus()) emit("focus", event);
|
|
1670
|
+
}
|
|
1671
|
+
function onFocusOut(event) {
|
|
1672
|
+
disabledTooltip.onBlur();
|
|
1673
|
+
if (isInsideTokenizer(event.relatedTarget)) return;
|
|
1674
|
+
focused.value = false;
|
|
1675
|
+
menu.close();
|
|
1676
|
+
emit("blur", event);
|
|
1677
|
+
}
|
|
1678
|
+
function isInsideTokenizer(node) {
|
|
1679
|
+
if (!(node instanceof Node)) return false;
|
|
1680
|
+
return Boolean(anchorRef.value?.contains(node) || listboxRef.value?.contains(node));
|
|
1681
|
+
}
|
|
1682
|
+
const { onInputKeyDown: onListKeyDown, onTokenKeyDown } = useTokenizerKeys({
|
|
1683
|
+
values,
|
|
1684
|
+
disabled: () => props.disabled,
|
|
1685
|
+
menu,
|
|
1686
|
+
optionGrid,
|
|
1687
|
+
inputRef,
|
|
1688
|
+
remove,
|
|
1689
|
+
focusToken
|
|
1690
|
+
});
|
|
1691
|
+
function onInputKeyDown(event) {
|
|
1692
|
+
if (!menuConfig.closeOnEscape(event)) onListKeyDown(event);
|
|
1693
|
+
}
|
|
1694
|
+
function onFieldClick(event) {
|
|
1695
|
+
if (props.disabled) return;
|
|
1696
|
+
const target = event.target;
|
|
1697
|
+
if (target instanceof Element && target.closest("button, a")) return;
|
|
1698
|
+
inputRef.value?.focus();
|
|
1699
|
+
}
|
|
1700
|
+
function addEntry(entry) {
|
|
1701
|
+
selection.add(entry.item, entry.create ? "create" : "add");
|
|
1702
|
+
}
|
|
1703
|
+
/** 焦点交给当前呈现的控件:行内输入框,或底部弹层呈现的触发器。 */
|
|
1704
|
+
function focusControl() {
|
|
1705
|
+
if (isSheet.value) sheetFieldRef.value?.focus();
|
|
1706
|
+
else inputRef.value?.focus();
|
|
1707
|
+
}
|
|
1708
|
+
__expose({
|
|
1709
|
+
focus: focusControl,
|
|
1710
|
+
blur: () => isSheet.value ? sheetFieldRef.value?.blur() : inputRef.value?.blur(),
|
|
1711
|
+
open: () => {
|
|
1712
|
+
if (!isSheet.value) menuConfig.open();
|
|
1713
|
+
else if (!props.disabled) sheetOpen.value = true;
|
|
1714
|
+
},
|
|
1715
|
+
close: () => {
|
|
1716
|
+
if (isSheet.value) sheetOpen.value = false;
|
|
1717
|
+
else menuConfig.close();
|
|
1718
|
+
}
|
|
1719
|
+
});
|
|
1720
|
+
return (_ctx, _cache) => {
|
|
1721
|
+
return openBlock(), createElementBlock(Fragment, null, [
|
|
1722
|
+
createVNode(_sfc_main$13, {
|
|
1723
|
+
class: normalizeClass(["astryx-tokenizer", [
|
|
1724
|
+
unref(parts).containerClass.value,
|
|
1725
|
+
`size-${unref(size)}`,
|
|
1726
|
+
{ "is-floating": floating.value }
|
|
1727
|
+
]]),
|
|
1728
|
+
style: normalizeStyle(unref(parts).containerStyle.value),
|
|
1729
|
+
label: props.label,
|
|
1730
|
+
"input-id": inputId,
|
|
1731
|
+
description: props.description,
|
|
1732
|
+
"label-tooltip": props.labelTooltip,
|
|
1733
|
+
"is-label-hidden": unref(hideLabel),
|
|
1734
|
+
"is-disabled": props.disabled,
|
|
1735
|
+
"is-required": props.required,
|
|
1736
|
+
"is-optional": props.optional,
|
|
1737
|
+
status: unref(fieldStatus),
|
|
1738
|
+
"status-variant": props.statusVariant,
|
|
1739
|
+
width: props.width
|
|
1740
|
+
}, {
|
|
1741
|
+
default: withCtx(() => [unref(isSheet) ? (openBlock(), createBlock(_sfc_main$1, mergeProps({
|
|
1742
|
+
key: 0,
|
|
1743
|
+
ref_key: "sheetFieldRef",
|
|
1744
|
+
ref: sheetFieldRef,
|
|
1745
|
+
"is-open": unref(sheetOpen),
|
|
1746
|
+
"onUpdate:isOpen": _cache[0] || (_cache[0] = ($event) => isRef(sheetOpen) ? sheetOpen.value = $event : null)
|
|
1747
|
+
}, inputAttrs(), {
|
|
1748
|
+
values: values.value,
|
|
1749
|
+
"input-id": inputId,
|
|
1750
|
+
label: props.label,
|
|
1751
|
+
"labelled-by": unref(labelledBy),
|
|
1752
|
+
"described-by": unref(describedBy),
|
|
1753
|
+
placeholder: placeholder.value,
|
|
1754
|
+
size: unref(size),
|
|
1755
|
+
"is-disabled": props.disabled,
|
|
1756
|
+
name: props.name,
|
|
1757
|
+
"control-class": [unref(parts).controlClass(), `status-${props.status}`],
|
|
1758
|
+
"control-style": unref(parts).controlStyle(),
|
|
1759
|
+
"status-icon": unref(statusIcon),
|
|
1760
|
+
"status-icon-props": unref(statusIconProps),
|
|
1761
|
+
"search-source": props.searchSource,
|
|
1762
|
+
"max-entries": props.maxEntries,
|
|
1763
|
+
"has-create": isCreatable.value,
|
|
1764
|
+
"max-menu-items": props.maxMenuItems,
|
|
1765
|
+
"min-query-length": props.minQueryLength,
|
|
1766
|
+
"debounce-ms": props.debounceMs,
|
|
1767
|
+
"empty-search-text": props.emptySearchText ?? props.emptyText,
|
|
1768
|
+
onCommit: unref(selection).commit,
|
|
1769
|
+
onRemove: remove,
|
|
1770
|
+
onChangeQuery: _cache[1] || (_cache[1] = (query) => {
|
|
1771
|
+
emit("search", query);
|
|
1772
|
+
emit("changeQuery", query);
|
|
1773
|
+
}),
|
|
1774
|
+
onMotionComplete: unref(onSheetMotionComplete),
|
|
1775
|
+
onFocus: _cache[2] || (_cache[2] = ($event) => emit("focus", $event)),
|
|
1776
|
+
onBlur: _cache[3] || (_cache[3] = ($event) => emit("blur", $event))
|
|
1777
|
+
}), createSlots({ _: 2 }, [
|
|
1778
|
+
_ctx.$slots.icon ? {
|
|
1779
|
+
name: "icon",
|
|
1780
|
+
fn: withCtx(() => [renderSlot(_ctx.$slots, "icon")]),
|
|
1781
|
+
key: "0"
|
|
1782
|
+
} : void 0,
|
|
1783
|
+
_ctx.$slots.end ? {
|
|
1784
|
+
name: "end",
|
|
1785
|
+
fn: withCtx(() => [renderSlot(_ctx.$slots, "end")]),
|
|
1786
|
+
key: "1"
|
|
1787
|
+
} : void 0,
|
|
1788
|
+
_ctx.$slots.token ? {
|
|
1789
|
+
name: "token",
|
|
1790
|
+
fn: withCtx((tokenProps) => [renderSlot(_ctx.$slots, "token", normalizeProps(guardReactiveProps(tokenProps)))]),
|
|
1791
|
+
key: "2"
|
|
1792
|
+
} : void 0,
|
|
1793
|
+
_ctx.$slots.empty ? {
|
|
1794
|
+
name: "empty",
|
|
1795
|
+
fn: withCtx(() => [renderSlot(_ctx.$slots, "empty")]),
|
|
1796
|
+
key: "3"
|
|
1797
|
+
} : void 0
|
|
1798
|
+
]), 1040, [
|
|
1799
|
+
"is-open",
|
|
1800
|
+
"values",
|
|
1801
|
+
"label",
|
|
1802
|
+
"labelled-by",
|
|
1803
|
+
"described-by",
|
|
1804
|
+
"placeholder",
|
|
1805
|
+
"size",
|
|
1806
|
+
"is-disabled",
|
|
1807
|
+
"name",
|
|
1808
|
+
"control-class",
|
|
1809
|
+
"control-style",
|
|
1810
|
+
"status-icon",
|
|
1811
|
+
"status-icon-props",
|
|
1812
|
+
"search-source",
|
|
1813
|
+
"max-entries",
|
|
1814
|
+
"has-create",
|
|
1815
|
+
"max-menu-items",
|
|
1816
|
+
"min-query-length",
|
|
1817
|
+
"debounce-ms",
|
|
1818
|
+
"empty-search-text",
|
|
1819
|
+
"onCommit",
|
|
1820
|
+
"onMotionComplete"
|
|
1821
|
+
])) : (openBlock(), createElementBlock(Fragment, { key: 1 }, [
|
|
1822
|
+
floating.value ? (openBlock(), createElementBlock("div", {
|
|
1823
|
+
key: 0,
|
|
1824
|
+
class: "astryx-tokenizer-placeholder",
|
|
1825
|
+
style: normalizeStyle({ height: `${placeholderHeight.value}px` })
|
|
1826
|
+
}, null, 4)) : createCommentVNode("v-if", true),
|
|
1827
|
+
createCommentVNode(" eslint-disable-next-line vue-a11y/click-events-have-key-events, vue-a11y/no-static-element-interactions -- 点空白处只是把焦点交给输入框;方向键和删除由输入框与标签处理。 "),
|
|
1828
|
+
createElementVNode("div", {
|
|
1829
|
+
ref_key: "anchorRef",
|
|
1830
|
+
ref: anchorRef,
|
|
1831
|
+
class: normalizeClass(["astryx-tokenizer-control", [
|
|
1832
|
+
unref(parts).controlClass(),
|
|
1833
|
+
`status-${props.status}`,
|
|
1834
|
+
{
|
|
1835
|
+
"is-open": unref(menu).combobox.isOpen.value,
|
|
1836
|
+
"is-disabled": props.disabled,
|
|
1837
|
+
"is-floating": floating.value,
|
|
1838
|
+
"has-tokens": values.value.length > 0
|
|
1839
|
+
}
|
|
1840
|
+
]]),
|
|
1841
|
+
style: normalizeStyle(unref(parts).controlStyle()),
|
|
1842
|
+
onClick: onFieldClick,
|
|
1843
|
+
onFocusin: onFocusIn,
|
|
1844
|
+
onFocusout: onFocusOut,
|
|
1845
|
+
onPointerenter: _cache[5] || (_cache[5] = (...args) => unref(disabledTooltip).onPointerEnter && unref(disabledTooltip).onPointerEnter(...args)),
|
|
1846
|
+
onPointerleave: _cache[6] || (_cache[6] = (...args) => unref(disabledTooltip).onPointerLeave && unref(disabledTooltip).onPointerLeave(...args))
|
|
1847
|
+
}, [
|
|
1848
|
+
_ctx.$slots.icon ? (openBlock(), createElementBlock("span", _hoisted_1, [renderSlot(_ctx.$slots, "icon")])) : createCommentVNode("v-if", true),
|
|
1849
|
+
createElementVNode("span", {
|
|
1850
|
+
ref: unref(overflow).containerRef,
|
|
1851
|
+
class: normalizeClass(["astryx-tokenizer-tokens", { "is-collapsed": collapsed.value }])
|
|
1852
|
+
}, [
|
|
1853
|
+
createCommentVNode(" eslint-disable-next-line vue-a11y/no-static-element-interactions -- 方向键在标签容器上移动焦点,删除由内部按钮处理。 "),
|
|
1854
|
+
(openBlock(true), createElementBlock(Fragment, null, renderList(visibleItems.value, (item, index) => {
|
|
1855
|
+
return openBlock(), createElementBlock("span", {
|
|
1856
|
+
key: item.id,
|
|
1857
|
+
ref_for: true,
|
|
1858
|
+
ref: (element) => setTokenEl(index, element),
|
|
1859
|
+
class: "astryx-tokenizer-token",
|
|
1860
|
+
tabindex: "-1",
|
|
1861
|
+
onKeydown: ($event) => unref(onTokenKeyDown)($event, item, index)
|
|
1862
|
+
}, [renderSlot(_ctx.$slots, "token", {
|
|
1863
|
+
item,
|
|
1864
|
+
remove: () => remove(item)
|
|
1865
|
+
}, () => [createVNode(_sfc_main$15, {
|
|
1866
|
+
label: item.label,
|
|
1867
|
+
size: unref(size),
|
|
1868
|
+
disabled: props.disabled,
|
|
1869
|
+
removable: "",
|
|
1870
|
+
onRemove: ($event) => remove(item)
|
|
1871
|
+
}, null, 8, [
|
|
1872
|
+
"label",
|
|
1873
|
+
"size",
|
|
1874
|
+
"disabled",
|
|
1875
|
+
"onRemove"
|
|
1876
|
+
])])], 40, _hoisted_2);
|
|
1877
|
+
}), 128)),
|
|
1878
|
+
collapsed.value && hiddenCount.value > 0 ? (openBlock(), createElementBlock("span", _hoisted_3, toDisplayString(unref(messages).tokenizer.more(hiddenCount.value)), 1)) : createCommentVNode("v-if", true)
|
|
1879
|
+
], 2),
|
|
1880
|
+
createElementVNode("span", {
|
|
1881
|
+
ref: unref(overflow).measureRef,
|
|
1882
|
+
class: "astryx-tokenizer-measure",
|
|
1883
|
+
"aria-hidden": "true"
|
|
1884
|
+
}, [(openBlock(true), createElementBlock(Fragment, null, renderList(values.value, (item) => {
|
|
1885
|
+
return openBlock(), createElementBlock("span", {
|
|
1886
|
+
key: item.id,
|
|
1887
|
+
class: "astryx-tokenizer-token"
|
|
1888
|
+
}, [createVNode(_sfc_main$15, {
|
|
1889
|
+
label: item.label,
|
|
1890
|
+
size: unref(size),
|
|
1891
|
+
removable: ""
|
|
1892
|
+
}, null, 8, ["label", "size"])]);
|
|
1893
|
+
}), 128)), createElementVNode("span", _hoisted_4, toDisplayString(measureMoreLabel.value), 1)], 512),
|
|
1894
|
+
createElementVNode("input", mergeProps(inputAttrs(), {
|
|
1895
|
+
id: inputId,
|
|
1896
|
+
ref_key: "inputRef",
|
|
1897
|
+
ref: inputRef,
|
|
1898
|
+
class: ["astryx-tokenizer-input", { "is-empty": unref(menu).query.value === "" }],
|
|
1899
|
+
type: "text",
|
|
1900
|
+
role: "combobox",
|
|
1901
|
+
autocomplete: "off",
|
|
1902
|
+
autocapitalize: "off",
|
|
1903
|
+
autocorrect: "off",
|
|
1904
|
+
enterkeyhint: "search",
|
|
1905
|
+
"data-autofocus": props.hasAutoFocus || void 0,
|
|
1906
|
+
placeholder: values.value.length === 0 ? placeholder.value : void 0,
|
|
1907
|
+
value: unref(menu).query.value,
|
|
1908
|
+
disabled: props.disabled && !unref(focusableDisabled),
|
|
1909
|
+
readonly: unref(focusableDisabled) || atMax.value || void 0,
|
|
1910
|
+
"aria-disabled": unref(focusableDisabled) ? "true" : void 0,
|
|
1911
|
+
"aria-expanded": unref(menuConfig).popupOpen.value,
|
|
1912
|
+
"aria-haspopup": unref(menuConfig).isDialog.value ? "dialog" : unref(optionGrid).popupKind.value,
|
|
1913
|
+
"aria-controls": listboxId,
|
|
1914
|
+
"aria-autocomplete": "list",
|
|
1915
|
+
"aria-activedescendant": unref(menuConfig).isDialog.value ? void 0 : unref(optionGrid).gridMode.value ? unref(optionGrid).actionGrid.activeDescendant.value : unref(menu).activeId.value ? `${listboxId}-option-${unref(menu).combobox.activeIndex.value}` : void 0,
|
|
1916
|
+
"aria-labelledby": unref(labelledBy),
|
|
1917
|
+
"aria-describedby": unref(describedBy),
|
|
1918
|
+
"aria-required": props.required || void 0,
|
|
1919
|
+
"aria-invalid": props.status === "error" ? true : void 0,
|
|
1920
|
+
onInput,
|
|
1921
|
+
onKeydown: onInputKeyDown
|
|
1922
|
+
}), null, 16, _hoisted_5),
|
|
1923
|
+
renderSlot(_ctx.$slots, "end"),
|
|
1924
|
+
showsClear.value && values.value.length > 0 && !props.disabled ? (openBlock(), createElementBlock("button", {
|
|
1925
|
+
key: 1,
|
|
1926
|
+
type: "button",
|
|
1927
|
+
class: "astryx-tokenizer-clear",
|
|
1928
|
+
"aria-label": unref(messages).tokenizer.clear,
|
|
1929
|
+
onClick: _cache[4] || (_cache[4] = (...args) => unref(selection).clearAll && unref(selection).clearAll(...args))
|
|
1930
|
+
}, [..._cache[7] || (_cache[7] = [createElementVNode("svg", {
|
|
1931
|
+
width: "16",
|
|
1932
|
+
height: "16",
|
|
1933
|
+
viewBox: "0 0 16 16",
|
|
1934
|
+
fill: "none",
|
|
1935
|
+
"aria-hidden": "true"
|
|
1936
|
+
}, [createElementVNode("path", {
|
|
1937
|
+
d: "M12 4L4 12M4 4L12 12",
|
|
1938
|
+
stroke: "currentColor",
|
|
1939
|
+
"stroke-width": "1.5",
|
|
1940
|
+
"stroke-linecap": "round"
|
|
1941
|
+
})], -1)])], 8, _hoisted_6)) : createCommentVNode("v-if", true),
|
|
1942
|
+
unref(statusIcon) ? (openBlock(), createBlock(resolveDynamicComponent(unref(statusIcon)), normalizeProps(mergeProps({ key: 2 }, unref(statusIconProps))), null, 16)) : createCommentVNode("v-if", true),
|
|
1943
|
+
unref(focusableDisabled) && unref(disabledMessage) ? (openBlock(), createElementBlock("span", {
|
|
1944
|
+
key: 3,
|
|
1945
|
+
id: disabledId,
|
|
1946
|
+
class: "astryx-visually-hidden"
|
|
1947
|
+
}, toDisplayString(unref(disabledMessage)), 1)) : createCommentVNode("v-if", true),
|
|
1948
|
+
(openBlock(true), createElementBlock(Fragment, null, renderList(hiddenCarrierItems.value, (item) => {
|
|
1949
|
+
return openBlock(), createElementBlock("input", {
|
|
1950
|
+
key: `${props.name}-${item.id}`,
|
|
1951
|
+
type: "hidden",
|
|
1952
|
+
name: props.name,
|
|
1953
|
+
value: item.id,
|
|
1954
|
+
disabled: !props.name
|
|
1955
|
+
}, null, 8, _hoisted_7);
|
|
1956
|
+
}), 128))
|
|
1957
|
+
], 38)
|
|
1958
|
+
], 64))]),
|
|
1959
|
+
_: 3
|
|
1960
|
+
}, 8, [
|
|
1961
|
+
"class",
|
|
1962
|
+
"style",
|
|
1963
|
+
"label",
|
|
1964
|
+
"description",
|
|
1965
|
+
"label-tooltip",
|
|
1966
|
+
"is-label-hidden",
|
|
1967
|
+
"is-disabled",
|
|
1968
|
+
"is-required",
|
|
1969
|
+
"is-optional",
|
|
1970
|
+
"status",
|
|
1971
|
+
"status-variant",
|
|
1972
|
+
"width"
|
|
1973
|
+
]),
|
|
1974
|
+
unref(showsDisabledMessage) ? (openBlock(), createBlock(_sfc_main$6, {
|
|
1975
|
+
key: 0,
|
|
1976
|
+
id: disabledTooltipId,
|
|
1977
|
+
anchor: unref(isSheet) ? sheetFieldRef.value?.element ?? null : anchorRef.value,
|
|
1978
|
+
open: unref(disabledTooltip).isOpen.value,
|
|
1979
|
+
text: unref(disabledMessage) ?? "",
|
|
1980
|
+
onPointerEnter: unref(disabledTooltip).onTooltipPointerEnter,
|
|
1981
|
+
onPointerLeave: unref(disabledTooltip).onTooltipPointerLeave
|
|
1982
|
+
}, null, 8, [
|
|
1983
|
+
"anchor",
|
|
1984
|
+
"open",
|
|
1985
|
+
"text",
|
|
1986
|
+
"onPointerEnter",
|
|
1987
|
+
"onPointerLeave"
|
|
1988
|
+
])) : createCommentVNode("v-if", true),
|
|
1989
|
+
!unref(isSheet) ? (openBlock(), createBlock(_sfc_main$16, {
|
|
1990
|
+
key: 1,
|
|
1991
|
+
id: listboxId,
|
|
1992
|
+
ref_key: "popupRef",
|
|
1993
|
+
ref: popupRef,
|
|
1994
|
+
"is-open": unref(menuConfig).popupOpen.value,
|
|
1995
|
+
config: props.menu,
|
|
1996
|
+
label: unref(messages).tokenizer.results,
|
|
1997
|
+
grid: unref(optionGrid).gridMode.value,
|
|
1998
|
+
placement: unref(anchored).position.value.placement,
|
|
1999
|
+
"popup-style": unref(anchored).style.value,
|
|
2000
|
+
entries: unref(menu).entries.value.map((entry) => ({
|
|
2001
|
+
id: entry.id,
|
|
2002
|
+
label: entry.label,
|
|
2003
|
+
description: entry.description,
|
|
2004
|
+
disabled: entry.disabled,
|
|
2005
|
+
group: entry.group,
|
|
2006
|
+
action: entry.action,
|
|
2007
|
+
selected: values.value.some((item) => item.id === entry.item.id)
|
|
2008
|
+
})),
|
|
2009
|
+
"active-index": unref(menu).combobox.activeIndex.value,
|
|
2010
|
+
"action-index": unref(optionGrid).actionGrid.column.value === "action" ? unref(menu).combobox.activeIndex.value : -1,
|
|
2011
|
+
status: unref(menu).menuStatus.value,
|
|
2012
|
+
"empty-text": emptyText.value,
|
|
2013
|
+
"loading-text": unref(messages).tokenizer.loading,
|
|
2014
|
+
"error-text": unref(messages).tokenizer.error,
|
|
2015
|
+
query: unref(menu).query.value,
|
|
2016
|
+
"is-settled": unref(menu).isSettled.value,
|
|
2017
|
+
onSelect: unref(selectById),
|
|
2018
|
+
onHighlight: unref(highlight),
|
|
2019
|
+
onClose: unref(menuConfig).close,
|
|
2020
|
+
onKeydown: unref(menuConfig).closeOnEscape
|
|
2021
|
+
}, createSlots({ _: 2 }, [
|
|
2022
|
+
_ctx.$slots.item ? {
|
|
2023
|
+
name: "item",
|
|
2024
|
+
fn: withCtx((slotProps) => [renderSlot(_ctx.$slots, "item", {
|
|
2025
|
+
item: unref(menu).entries.value.find((entry) => entry.id === slotProps.entry.id).item,
|
|
2026
|
+
isActive: slotProps.isActive,
|
|
2027
|
+
isSelected: slotProps.isSelected
|
|
2028
|
+
})]),
|
|
2029
|
+
key: "0"
|
|
2030
|
+
} : void 0,
|
|
2031
|
+
_ctx.$slots.empty ? {
|
|
2032
|
+
name: "empty",
|
|
2033
|
+
fn: withCtx(() => [renderSlot(_ctx.$slots, "empty")]),
|
|
2034
|
+
key: "1"
|
|
2035
|
+
} : void 0,
|
|
2036
|
+
_ctx.$slots.menu ? {
|
|
2037
|
+
name: "menu",
|
|
2038
|
+
fn: withCtx((menuProps) => [renderSlot(_ctx.$slots, "menu", normalizeProps(guardReactiveProps(menuProps)))]),
|
|
2039
|
+
key: "2"
|
|
2040
|
+
} : void 0
|
|
2041
|
+
]), 1032, [
|
|
2042
|
+
"is-open",
|
|
2043
|
+
"config",
|
|
2044
|
+
"label",
|
|
2045
|
+
"grid",
|
|
2046
|
+
"placement",
|
|
2047
|
+
"popup-style",
|
|
2048
|
+
"entries",
|
|
2049
|
+
"active-index",
|
|
2050
|
+
"action-index",
|
|
2051
|
+
"status",
|
|
2052
|
+
"empty-text",
|
|
2053
|
+
"loading-text",
|
|
2054
|
+
"error-text",
|
|
2055
|
+
"query",
|
|
2056
|
+
"is-settled",
|
|
2057
|
+
"onSelect",
|
|
2058
|
+
"onHighlight",
|
|
2059
|
+
"onClose",
|
|
2060
|
+
"onKeydown"
|
|
2061
|
+
])) : createCommentVNode("v-if", true)
|
|
2062
|
+
], 64);
|
|
2063
|
+
};
|
|
2064
|
+
}
|
|
2065
|
+
});
|
|
2066
|
+
//#endregion
|
|
2067
|
+
export { useTokenRemoveTap as n, _sfc_main as t };
|