@react-aria/autocomplete 3.0.0-alpha.9 → 3.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (196) hide show
  1. package/dist/ar-AE.main.js +6 -0
  2. package/dist/ar-AE.main.js.map +1 -0
  3. package/dist/ar-AE.mjs +8 -0
  4. package/dist/ar-AE.module.js +8 -0
  5. package/dist/ar-AE.module.js.map +1 -0
  6. package/dist/bg-BG.main.js +6 -0
  7. package/dist/bg-BG.main.js.map +1 -0
  8. package/dist/bg-BG.mjs +8 -0
  9. package/dist/bg-BG.module.js +8 -0
  10. package/dist/bg-BG.module.js.map +1 -0
  11. package/dist/cs-CZ.main.js +6 -0
  12. package/dist/cs-CZ.main.js.map +1 -0
  13. package/dist/cs-CZ.mjs +8 -0
  14. package/dist/cs-CZ.module.js +8 -0
  15. package/dist/cs-CZ.module.js.map +1 -0
  16. package/dist/da-DK.main.js +6 -0
  17. package/dist/da-DK.main.js.map +1 -0
  18. package/dist/da-DK.mjs +8 -0
  19. package/dist/da-DK.module.js +8 -0
  20. package/dist/da-DK.module.js.map +1 -0
  21. package/dist/de-DE.main.js +6 -0
  22. package/dist/de-DE.main.js.map +1 -0
  23. package/dist/de-DE.mjs +8 -0
  24. package/dist/de-DE.module.js +8 -0
  25. package/dist/de-DE.module.js.map +1 -0
  26. package/dist/el-GR.main.js +6 -0
  27. package/dist/el-GR.main.js.map +1 -0
  28. package/dist/el-GR.mjs +8 -0
  29. package/dist/el-GR.module.js +8 -0
  30. package/dist/el-GR.module.js.map +1 -0
  31. package/dist/en-US.main.js +6 -0
  32. package/dist/en-US.main.js.map +1 -0
  33. package/dist/en-US.mjs +8 -0
  34. package/dist/en-US.module.js +8 -0
  35. package/dist/en-US.module.js.map +1 -0
  36. package/dist/es-ES.main.js +6 -0
  37. package/dist/es-ES.main.js.map +1 -0
  38. package/dist/es-ES.mjs +8 -0
  39. package/dist/es-ES.module.js +8 -0
  40. package/dist/es-ES.module.js.map +1 -0
  41. package/dist/et-EE.main.js +6 -0
  42. package/dist/et-EE.main.js.map +1 -0
  43. package/dist/et-EE.mjs +8 -0
  44. package/dist/et-EE.module.js +8 -0
  45. package/dist/et-EE.module.js.map +1 -0
  46. package/dist/fi-FI.main.js +6 -0
  47. package/dist/fi-FI.main.js.map +1 -0
  48. package/dist/fi-FI.mjs +8 -0
  49. package/dist/fi-FI.module.js +8 -0
  50. package/dist/fi-FI.module.js.map +1 -0
  51. package/dist/fr-FR.main.js +6 -0
  52. package/dist/fr-FR.main.js.map +1 -0
  53. package/dist/fr-FR.mjs +8 -0
  54. package/dist/fr-FR.module.js +8 -0
  55. package/dist/fr-FR.module.js.map +1 -0
  56. package/dist/he-IL.main.js +6 -0
  57. package/dist/he-IL.main.js.map +1 -0
  58. package/dist/he-IL.mjs +8 -0
  59. package/dist/he-IL.module.js +8 -0
  60. package/dist/he-IL.module.js.map +1 -0
  61. package/dist/hr-HR.main.js +6 -0
  62. package/dist/hr-HR.main.js.map +1 -0
  63. package/dist/hr-HR.mjs +8 -0
  64. package/dist/hr-HR.module.js +8 -0
  65. package/dist/hr-HR.module.js.map +1 -0
  66. package/dist/hu-HU.main.js +6 -0
  67. package/dist/hu-HU.main.js.map +1 -0
  68. package/dist/hu-HU.mjs +8 -0
  69. package/dist/hu-HU.module.js +8 -0
  70. package/dist/hu-HU.module.js.map +1 -0
  71. package/dist/import.mjs +19 -0
  72. package/dist/intlStrings.main.js +108 -0
  73. package/dist/intlStrings.main.js.map +1 -0
  74. package/dist/intlStrings.mjs +110 -0
  75. package/dist/intlStrings.module.js +110 -0
  76. package/dist/intlStrings.module.js.map +1 -0
  77. package/dist/it-IT.main.js +6 -0
  78. package/dist/it-IT.main.js.map +1 -0
  79. package/dist/it-IT.mjs +8 -0
  80. package/dist/it-IT.module.js +8 -0
  81. package/dist/it-IT.module.js.map +1 -0
  82. package/dist/ja-JP.main.js +6 -0
  83. package/dist/ja-JP.main.js.map +1 -0
  84. package/dist/ja-JP.mjs +8 -0
  85. package/dist/ja-JP.module.js +8 -0
  86. package/dist/ja-JP.module.js.map +1 -0
  87. package/dist/ko-KR.main.js +6 -0
  88. package/dist/ko-KR.main.js.map +1 -0
  89. package/dist/ko-KR.mjs +8 -0
  90. package/dist/ko-KR.module.js +8 -0
  91. package/dist/ko-KR.module.js.map +1 -0
  92. package/dist/lt-LT.main.js +6 -0
  93. package/dist/lt-LT.main.js.map +1 -0
  94. package/dist/lt-LT.mjs +8 -0
  95. package/dist/lt-LT.module.js +8 -0
  96. package/dist/lt-LT.module.js.map +1 -0
  97. package/dist/lv-LV.main.js +6 -0
  98. package/dist/lv-LV.main.js.map +1 -0
  99. package/dist/lv-LV.mjs +8 -0
  100. package/dist/lv-LV.module.js +8 -0
  101. package/dist/lv-LV.module.js.map +1 -0
  102. package/dist/main.js +16 -42
  103. package/dist/main.js.map +1 -1
  104. package/dist/module.js +14 -42
  105. package/dist/module.js.map +1 -1
  106. package/dist/nb-NO.main.js +6 -0
  107. package/dist/nb-NO.main.js.map +1 -0
  108. package/dist/nb-NO.mjs +8 -0
  109. package/dist/nb-NO.module.js +8 -0
  110. package/dist/nb-NO.module.js.map +1 -0
  111. package/dist/nl-NL.main.js +6 -0
  112. package/dist/nl-NL.main.js.map +1 -0
  113. package/dist/nl-NL.mjs +8 -0
  114. package/dist/nl-NL.module.js +8 -0
  115. package/dist/nl-NL.module.js.map +1 -0
  116. package/dist/pl-PL.main.js +6 -0
  117. package/dist/pl-PL.main.js.map +1 -0
  118. package/dist/pl-PL.mjs +8 -0
  119. package/dist/pl-PL.module.js +8 -0
  120. package/dist/pl-PL.module.js.map +1 -0
  121. package/dist/pt-BR.main.js +6 -0
  122. package/dist/pt-BR.main.js.map +1 -0
  123. package/dist/pt-BR.mjs +8 -0
  124. package/dist/pt-BR.module.js +8 -0
  125. package/dist/pt-BR.module.js.map +1 -0
  126. package/dist/pt-PT.main.js +6 -0
  127. package/dist/pt-PT.main.js.map +1 -0
  128. package/dist/pt-PT.mjs +8 -0
  129. package/dist/pt-PT.module.js +8 -0
  130. package/dist/pt-PT.module.js.map +1 -0
  131. package/dist/ro-RO.main.js +6 -0
  132. package/dist/ro-RO.main.js.map +1 -0
  133. package/dist/ro-RO.mjs +8 -0
  134. package/dist/ro-RO.module.js +8 -0
  135. package/dist/ro-RO.module.js.map +1 -0
  136. package/dist/ru-RU.main.js +6 -0
  137. package/dist/ru-RU.main.js.map +1 -0
  138. package/dist/ru-RU.mjs +8 -0
  139. package/dist/ru-RU.module.js +8 -0
  140. package/dist/ru-RU.module.js.map +1 -0
  141. package/dist/sk-SK.main.js +6 -0
  142. package/dist/sk-SK.main.js.map +1 -0
  143. package/dist/sk-SK.mjs +8 -0
  144. package/dist/sk-SK.module.js +8 -0
  145. package/dist/sk-SK.module.js.map +1 -0
  146. package/dist/sl-SI.main.js +6 -0
  147. package/dist/sl-SI.main.js.map +1 -0
  148. package/dist/sl-SI.mjs +8 -0
  149. package/dist/sl-SI.module.js +8 -0
  150. package/dist/sl-SI.module.js.map +1 -0
  151. package/dist/sr-SP.main.js +6 -0
  152. package/dist/sr-SP.main.js.map +1 -0
  153. package/dist/sr-SP.mjs +8 -0
  154. package/dist/sr-SP.module.js +8 -0
  155. package/dist/sr-SP.module.js.map +1 -0
  156. package/dist/sv-SE.main.js +6 -0
  157. package/dist/sv-SE.main.js.map +1 -0
  158. package/dist/sv-SE.mjs +8 -0
  159. package/dist/sv-SE.module.js +8 -0
  160. package/dist/sv-SE.module.js.map +1 -0
  161. package/dist/tr-TR.main.js +6 -0
  162. package/dist/tr-TR.main.js.map +1 -0
  163. package/dist/tr-TR.mjs +8 -0
  164. package/dist/tr-TR.module.js +8 -0
  165. package/dist/tr-TR.module.js.map +1 -0
  166. package/dist/types.d.ts +69 -15
  167. package/dist/types.d.ts.map +1 -1
  168. package/dist/uk-UA.main.js +6 -0
  169. package/dist/uk-UA.main.js.map +1 -0
  170. package/dist/uk-UA.mjs +8 -0
  171. package/dist/uk-UA.module.js +8 -0
  172. package/dist/uk-UA.module.js.map +1 -0
  173. package/dist/useAutocomplete.main.js +273 -0
  174. package/dist/useAutocomplete.main.js.map +1 -0
  175. package/dist/useAutocomplete.mjs +268 -0
  176. package/dist/useAutocomplete.module.js +268 -0
  177. package/dist/useAutocomplete.module.js.map +1 -0
  178. package/dist/useSearchAutocomplete.main.js +73 -0
  179. package/dist/useSearchAutocomplete.main.js.map +1 -0
  180. package/dist/useSearchAutocomplete.mjs +68 -0
  181. package/dist/useSearchAutocomplete.module.js +68 -0
  182. package/dist/useSearchAutocomplete.module.js.map +1 -0
  183. package/dist/zh-CN.main.js +6 -0
  184. package/dist/zh-CN.main.js.map +1 -0
  185. package/dist/zh-CN.mjs +8 -0
  186. package/dist/zh-CN.module.js +8 -0
  187. package/dist/zh-CN.module.js.map +1 -0
  188. package/dist/zh-TW.main.js +6 -0
  189. package/dist/zh-TW.main.js.map +1 -0
  190. package/dist/zh-TW.mjs +8 -0
  191. package/dist/zh-TW.module.js +8 -0
  192. package/dist/zh-TW.module.js.map +1 -0
  193. package/package.json +23 -21
  194. package/src/index.ts +5 -1
  195. package/src/useAutocomplete.ts +364 -0
  196. package/src/useSearchAutocomplete.ts +62 -27
@@ -0,0 +1,268 @@
1
+ import $4ELxY$intlStringsmodulejs from "./intlStrings.module.js";
2
+ import {useId as $4ELxY$useId, useEffectEvent as $4ELxY$useEffectEvent, getActiveElement as $4ELxY$getActiveElement, getOwnerDocument as $4ELxY$getOwnerDocument, useObjectRef as $4ELxY$useObjectRef, mergeRefs as $4ELxY$mergeRefs, FOCUS_EVENT as $4ELxY$FOCUS_EVENT, CLEAR_FOCUS_EVENT as $4ELxY$CLEAR_FOCUS_EVENT, isCtrlKeyPressed as $4ELxY$isCtrlKeyPressed, useLabels as $4ELxY$useLabels, mergeProps as $4ELxY$mergeProps} from "@react-aria/utils";
3
+ import {moveVirtualFocus as $4ELxY$moveVirtualFocus, dispatchVirtualBlur as $4ELxY$dispatchVirtualBlur, dispatchVirtualFocus as $4ELxY$dispatchVirtualFocus} from "@react-aria/focus";
4
+ import {getInteractionModality as $4ELxY$getInteractionModality} from "@react-aria/interactions";
5
+ import {useRef as $4ELxY$useRef, useEffect as $4ELxY$useEffect, useCallback as $4ELxY$useCallback, useMemo as $4ELxY$useMemo} from "react";
6
+ import {useLocalizedStringFormatter as $4ELxY$useLocalizedStringFormatter} from "@react-aria/i18n";
7
+
8
+
9
+ function $parcel$interopDefault(a) {
10
+ return a && a.__esModule ? a.default : a;
11
+ }
12
+ /*
13
+ * Copyright 2024 Adobe. All rights reserved.
14
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
15
+ * you may not use this file except in compliance with the License. You may obtain a copy
16
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
17
+ *
18
+ * Unless required by applicable law or agreed to in writing, software distributed under
19
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
20
+ * OF ANY KIND, either express or implied. See the License for the specific language
21
+ * governing permissions and limitations under the License.
22
+ */
23
+
24
+
25
+
26
+
27
+
28
+ function $48f6ba390f8c5b59$export$1e40b3ca02d92d21(props, state) {
29
+ let { inputRef: inputRef, collectionRef: collectionRef, filter: filter, disableAutoFocusFirst: disableAutoFocusFirst = false } = props;
30
+ let collectionId = (0, $4ELxY$useId)();
31
+ let timeout = (0, $4ELxY$useRef)(undefined);
32
+ let delayNextActiveDescendant = (0, $4ELxY$useRef)(false);
33
+ let queuedActiveDescendant = (0, $4ELxY$useRef)(null);
34
+ let lastCollectionNode = (0, $4ELxY$useRef)(null);
35
+ // For mobile screen readers, we don't want virtual focus, instead opting to disable FocusScope's restoreFocus and manually
36
+ // moving focus back to the subtriggers
37
+ let shouldUseVirtualFocus = (0, $4ELxY$getInteractionModality)() !== 'virtual';
38
+ (0, $4ELxY$useEffect)(()=>{
39
+ return ()=>clearTimeout(timeout.current);
40
+ }, []);
41
+ let updateActiveDescendant = (0, $4ELxY$useEffectEvent)((e)=>{
42
+ // Ensure input is focused if the user clicks on the collection directly.
43
+ if (!e.isTrusted && shouldUseVirtualFocus && inputRef.current && (0, $4ELxY$getActiveElement)((0, $4ELxY$getOwnerDocument)(inputRef.current)) !== inputRef.current) inputRef.current.focus();
44
+ let target = e.target;
45
+ if (e.isTrusted || !target || queuedActiveDescendant.current === target.id) return;
46
+ clearTimeout(timeout.current);
47
+ if (target !== collectionRef.current) {
48
+ if (delayNextActiveDescendant.current) {
49
+ queuedActiveDescendant.current = target.id;
50
+ timeout.current = setTimeout(()=>{
51
+ state.setFocusedNodeId(target.id);
52
+ }, 500);
53
+ } else {
54
+ queuedActiveDescendant.current = target.id;
55
+ state.setFocusedNodeId(target.id);
56
+ }
57
+ } else {
58
+ queuedActiveDescendant.current = null;
59
+ state.setFocusedNodeId(null);
60
+ }
61
+ delayNextActiveDescendant.current = false;
62
+ });
63
+ let callbackRef = (0, $4ELxY$useCallback)((collectionNode)=>{
64
+ var _lastCollectionNode_current;
65
+ if (collectionNode != null) {
66
+ var // When typing forward, we want to delay the setting of active descendant to not interrupt the native screen reader announcement
67
+ // of the letter you just typed. If we recieve another focus event then we clear the queued update
68
+ // We track lastCollectionNode to do proper cleanup since callbackRefs just pass null when unmounting. This also handles
69
+ // React 19's extra call of the callback ref in strict mode
70
+ _lastCollectionNode_current1;
71
+ (_lastCollectionNode_current1 = lastCollectionNode.current) === null || _lastCollectionNode_current1 === void 0 ? void 0 : _lastCollectionNode_current1.removeEventListener('focusin', updateActiveDescendant);
72
+ lastCollectionNode.current = collectionNode;
73
+ collectionNode.addEventListener('focusin', updateActiveDescendant);
74
+ } else (_lastCollectionNode_current = lastCollectionNode.current) === null || _lastCollectionNode_current === void 0 ? void 0 : _lastCollectionNode_current.removeEventListener('focusin', updateActiveDescendant);
75
+ }, [
76
+ updateActiveDescendant
77
+ ]);
78
+ // Make sure to memo so that React doesn't keep registering a new event listeners on every rerender of the wrapped collection
79
+ let mergedCollectionRef = (0, $4ELxY$useObjectRef)((0, $4ELxY$useMemo)(()=>(0, $4ELxY$mergeRefs)(collectionRef, callbackRef), [
80
+ collectionRef,
81
+ callbackRef
82
+ ]));
83
+ let focusFirstItem = (0, $4ELxY$useEffectEvent)(()=>{
84
+ var _collectionRef_current;
85
+ delayNextActiveDescendant.current = true;
86
+ (_collectionRef_current = collectionRef.current) === null || _collectionRef_current === void 0 ? void 0 : _collectionRef_current.dispatchEvent(new CustomEvent((0, $4ELxY$FOCUS_EVENT), {
87
+ cancelable: true,
88
+ bubbles: true,
89
+ detail: {
90
+ focusStrategy: 'first'
91
+ }
92
+ }));
93
+ });
94
+ let clearVirtualFocus = (0, $4ELxY$useEffectEvent)((clearFocusKey)=>{
95
+ var _collectionRef_current;
96
+ (0, $4ELxY$moveVirtualFocus)((0, $4ELxY$getActiveElement)());
97
+ queuedActiveDescendant.current = null;
98
+ state.setFocusedNodeId(null);
99
+ let clearFocusEvent = new CustomEvent((0, $4ELxY$CLEAR_FOCUS_EVENT), {
100
+ cancelable: true,
101
+ bubbles: true,
102
+ detail: {
103
+ clearFocusKey: clearFocusKey
104
+ }
105
+ });
106
+ clearTimeout(timeout.current);
107
+ delayNextActiveDescendant.current = false;
108
+ (_collectionRef_current = collectionRef.current) === null || _collectionRef_current === void 0 ? void 0 : _collectionRef_current.dispatchEvent(clearFocusEvent);
109
+ });
110
+ // TODO: update to see if we can tell what kind of event (paste vs backspace vs typing) is happening instead
111
+ let onChange = (value)=>{
112
+ // Tell wrapped collection to focus the first element in the list when typing forward and to clear focused key when deleting text
113
+ // for screen reader announcements
114
+ if (state.inputValue !== value && state.inputValue.length <= value.length && !disableAutoFocusFirst) focusFirstItem();
115
+ else // Fully clear focused key when backspacing since the list may change and thus we'd want to start fresh again
116
+ clearVirtualFocus(true);
117
+ state.setInputValue(value);
118
+ };
119
+ let keyDownTarget = (0, $4ELxY$useRef)(null);
120
+ // For textfield specific keydown operations
121
+ let onKeyDown = (e)=>{
122
+ var _collectionRef_current;
123
+ keyDownTarget.current = e.target;
124
+ if (e.nativeEvent.isComposing) return;
125
+ let focusedNodeId = queuedActiveDescendant.current;
126
+ switch(e.key){
127
+ case 'a':
128
+ if ((0, $4ELxY$isCtrlKeyPressed)(e)) return;
129
+ break;
130
+ case 'Escape':
131
+ // Early return for Escape here so it doesn't leak the Escape event from the simulated collection event below and
132
+ // close the dialog prematurely. Ideally that should be up to the discretion of the input element hence the check
133
+ // for isPropagationStopped
134
+ if (e.isDefaultPrevented()) return;
135
+ break;
136
+ case ' ':
137
+ // Space shouldn't trigger onAction so early return.
138
+ return;
139
+ case 'Tab':
140
+ // Don't propogate Tab down to the collection, otherwise we will try to focus the collection via useSelectableCollection's Tab handler (aka shift tab logic)
141
+ // We want FocusScope to handle Tab if one exists (aka sub dialog), so special casepropogate
142
+ if ('continuePropagation' in e) e.continuePropagation();
143
+ return;
144
+ case 'Home':
145
+ case 'End':
146
+ case 'PageDown':
147
+ case 'PageUp':
148
+ case 'ArrowUp':
149
+ case 'ArrowDown':
150
+ {
151
+ var _collectionRef_current1;
152
+ if ((e.key === 'Home' || e.key === 'End') && focusedNodeId == null && e.shiftKey) return;
153
+ // Prevent these keys from moving the text cursor in the input
154
+ e.preventDefault();
155
+ // Move virtual focus into the wrapped collection
156
+ let focusCollection = new CustomEvent((0, $4ELxY$FOCUS_EVENT), {
157
+ cancelable: true,
158
+ bubbles: true
159
+ });
160
+ (_collectionRef_current1 = collectionRef.current) === null || _collectionRef_current1 === void 0 ? void 0 : _collectionRef_current1.dispatchEvent(focusCollection);
161
+ break;
162
+ }
163
+ }
164
+ // Emulate the keyboard events that happen in the input field in the wrapped collection. This is for triggering things like onAction via Enter
165
+ // or moving focus from one item to another. Stop propagation on the input event if it isn't already stopped so it doesn't leak out. For events
166
+ // like ESC, the dispatched event below will bubble out of the collection and be stopped if handled by useSelectableCollection, otherwise will bubble
167
+ // as expected
168
+ if (!e.isPropagationStopped()) e.stopPropagation();
169
+ let shouldPerformDefaultAction = true;
170
+ if (focusedNodeId == null) shouldPerformDefaultAction = ((_collectionRef_current = collectionRef.current) === null || _collectionRef_current === void 0 ? void 0 : _collectionRef_current.dispatchEvent(new KeyboardEvent(e.nativeEvent.type, e.nativeEvent))) || false;
171
+ else {
172
+ let item = document.getElementById(focusedNodeId);
173
+ shouldPerformDefaultAction = (item === null || item === void 0 ? void 0 : item.dispatchEvent(new KeyboardEvent(e.nativeEvent.type, e.nativeEvent))) || false;
174
+ }
175
+ if (shouldPerformDefaultAction) switch(e.key){
176
+ case 'ArrowLeft':
177
+ case 'ArrowRight':
178
+ // Clear the activedescendant so NVDA announcements aren't interrupted but retain the focused key in the collection so the
179
+ // user's keyboard navigation restarts from where they left off
180
+ clearVirtualFocus();
181
+ break;
182
+ }
183
+ };
184
+ let onKeyUpCapture = (0, $4ELxY$useEffectEvent)((e)=>{
185
+ // Dispatch simulated key up events for things like triggering links in listbox
186
+ // Make sure to stop the propagation of the input keyup event so that the simulated keyup/down pair
187
+ // is detected by usePress instead of the original keyup originating from the input
188
+ if (e.target === keyDownTarget.current) {
189
+ var _collectionRef_current;
190
+ e.stopImmediatePropagation();
191
+ let focusedNodeId = queuedActiveDescendant.current;
192
+ if (focusedNodeId == null) (_collectionRef_current = collectionRef.current) === null || _collectionRef_current === void 0 ? void 0 : _collectionRef_current.dispatchEvent(new KeyboardEvent(e.type, e));
193
+ else {
194
+ let item = document.getElementById(focusedNodeId);
195
+ item === null || item === void 0 ? void 0 : item.dispatchEvent(new KeyboardEvent(e.type, e));
196
+ }
197
+ }
198
+ });
199
+ (0, $4ELxY$useEffect)(()=>{
200
+ document.addEventListener('keyup', onKeyUpCapture, true);
201
+ return ()=>{
202
+ document.removeEventListener('keyup', onKeyUpCapture, true);
203
+ };
204
+ }, [
205
+ onKeyUpCapture
206
+ ]);
207
+ let stringFormatter = (0, $4ELxY$useLocalizedStringFormatter)((0, ($parcel$interopDefault($4ELxY$intlStringsmodulejs))), '@react-aria/autocomplete');
208
+ let collectionProps = (0, $4ELxY$useLabels)({
209
+ id: collectionId,
210
+ 'aria-label': stringFormatter.format('collectionLabel')
211
+ });
212
+ let filterFn = (0, $4ELxY$useCallback)((nodeTextValue)=>{
213
+ if (filter) return filter(nodeTextValue, state.inputValue);
214
+ return true;
215
+ }, [
216
+ state.inputValue,
217
+ filter
218
+ ]);
219
+ // Be sure to clear/restore the virtual + collection focus when blurring/refocusing the field so we only show the
220
+ // focus ring on the virtually focused collection when are actually interacting with the Autocomplete
221
+ let onBlur = (e)=>{
222
+ if (!e.isTrusted) return;
223
+ let lastFocusedNode = queuedActiveDescendant.current ? document.getElementById(queuedActiveDescendant.current) : null;
224
+ if (lastFocusedNode) (0, $4ELxY$dispatchVirtualBlur)(lastFocusedNode, e.relatedTarget);
225
+ };
226
+ let onFocus = (e)=>{
227
+ if (!e.isTrusted) return;
228
+ let curFocusedNode = queuedActiveDescendant.current ? document.getElementById(queuedActiveDescendant.current) : null;
229
+ if (curFocusedNode) {
230
+ let target = e.target;
231
+ queueMicrotask(()=>{
232
+ (0, $4ELxY$dispatchVirtualBlur)(target, curFocusedNode);
233
+ (0, $4ELxY$dispatchVirtualFocus)(curFocusedNode, target);
234
+ });
235
+ }
236
+ };
237
+ var _state_focusedNodeId;
238
+ return {
239
+ textFieldProps: {
240
+ value: state.inputValue,
241
+ onChange: onChange,
242
+ onKeyDown: onKeyDown,
243
+ autoComplete: 'off',
244
+ 'aria-haspopup': 'listbox',
245
+ 'aria-controls': collectionId,
246
+ // TODO: readd proper logic for completionMode = complete (aria-autocomplete: both)
247
+ 'aria-autocomplete': 'list',
248
+ 'aria-activedescendant': (_state_focusedNodeId = state.focusedNodeId) !== null && _state_focusedNodeId !== void 0 ? _state_focusedNodeId : undefined,
249
+ // This disable's iOS's autocorrect suggestions, since the autocomplete provides its own suggestions.
250
+ autoCorrect: 'off',
251
+ // This disable's the macOS Safari spell check auto corrections.
252
+ spellCheck: 'false',
253
+ enterKeyHint: 'go',
254
+ onBlur: onBlur,
255
+ onFocus: onFocus
256
+ },
257
+ collectionProps: (0, $4ELxY$mergeProps)(collectionProps, {
258
+ shouldUseVirtualFocus: shouldUseVirtualFocus,
259
+ disallowTypeAhead: true
260
+ }),
261
+ collectionRef: mergedCollectionRef,
262
+ filter: filter != null ? filterFn : undefined
263
+ };
264
+ }
265
+
266
+
267
+ export {$48f6ba390f8c5b59$export$1e40b3ca02d92d21 as useAutocomplete};
268
+ //# sourceMappingURL=useAutocomplete.module.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;AAyDM,SAAS,0CAAgB,KAA8B,EAAE,KAAwB;IACtF,IAAI,YACF,QAAQ,iBACR,aAAa,UACb,MAAM,yBACN,wBAAwB,OACzB,GAAG;IAEJ,IAAI,eAAe,CAAA,GAAA,YAAI;IACvB,IAAI,UAAU,CAAA,GAAA,aAAK,EAA6C;IAChE,IAAI,4BAA4B,CAAA,GAAA,aAAK,EAAE;IACvC,IAAI,yBAAyB,CAAA,GAAA,aAAK,EAAiB;IACnD,IAAI,qBAAqB,CAAA,GAAA,aAAK,EAAe;IAE7C,2HAA2H;IAC3H,uCAAuC;IACvC,IAAI,wBAAwB,CAAA,GAAA,6BAAqB,QAAQ;IAEzD,CAAA,GAAA,gBAAQ,EAAE;QACR,OAAO,IAAM,aAAa,QAAQ,OAAO;IAC3C,GAAG,EAAE;IAEL,IAAI,yBAAyB,CAAA,GAAA,qBAAa,EAAE,CAAC;QAC3C,yEAAyE;QACzE,IAAI,CAAC,EAAE,SAAS,IAAI,yBAAyB,SAAS,OAAO,IAAI,CAAA,GAAA,uBAAe,EAAE,CAAA,GAAA,uBAAe,EAAE,SAAS,OAAO,OAAO,SAAS,OAAO,EACxI,SAAS,OAAO,CAAC,KAAK;QAGxB,IAAI,SAAS,EAAE,MAAM;QACrB,IAAI,EAAE,SAAS,IAAI,CAAC,UAAU,uBAAuB,OAAO,KAAK,OAAO,EAAE,EACxE;QAGF,aAAa,QAAQ,OAAO;QAC5B,IAAI,WAAW,cA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GAAqG;YACrG,aAAa;YACb,gEAAgE;YAChE,YAAY;YACZ,cAAc;oBACd;qBACA;QACF;QACA,iBAAiB,CAAA,GAAA,iBAAS,EAAE,iBAAiB;mCAC3C;YACA,mBAAmB;QACrB;QACA,eAAe;QACf,QAAQ,UAAU,OAAO,WAAW;IACtC;AACF","sources":["packages/@react-aria/autocomplete/src/useAutocomplete.ts"],"sourcesContent":["/*\n * Copyright 2024 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaLabelingProps, BaseEvent, DOMProps, RefObject} from '@react-types/shared';\nimport {AriaTextFieldProps} from '@react-aria/textfield';\nimport {AutocompleteProps, AutocompleteState} from '@react-stately/autocomplete';\nimport {CLEAR_FOCUS_EVENT, FOCUS_EVENT, getActiveElement, getOwnerDocument, isCtrlKeyPressed, mergeProps, mergeRefs, useEffectEvent, useId, useLabels, useObjectRef} from '@react-aria/utils';\nimport {dispatchVirtualBlur, dispatchVirtualFocus, moveVirtualFocus} from '@react-aria/focus';\nimport {getInteractionModality} from '@react-aria/interactions';\n// @ts-ignore\nimport intlMessages from '../intl/*.json';\nimport {FocusEvent as ReactFocusEvent, KeyboardEvent as ReactKeyboardEvent, useCallback, useEffect, useMemo, useRef} from 'react';\nimport {useLocalizedStringFormatter} from '@react-aria/i18n';\n\nexport interface CollectionOptions extends DOMProps, AriaLabelingProps {\n /** Whether the collection items should use virtual focus instead of being focused directly. */\n shouldUseVirtualFocus: boolean,\n /** Whether typeahead is disabled. */\n disallowTypeAhead: boolean\n}\nexport interface AriaAutocompleteProps extends AutocompleteProps {\n /**\n * An optional filter function used to determine if a option should be included in the autocomplete list.\n * Include this if the items you are providing to your wrapped collection aren't filtered by default.\n */\n filter?: (textValue: string, inputValue: string) => boolean,\n\n /**\n * Whether or not to focus the first item in the collection after a filter is performed.\n * @default false\n */\n disableAutoFocusFirst?: boolean\n}\n\nexport interface AriaAutocompleteOptions extends Omit<AriaAutocompleteProps, 'children'> {\n /** The ref for the wrapped collection element. */\n inputRef: RefObject<HTMLInputElement | null>,\n /** The ref for the wrapped collection element. */\n collectionRef: RefObject<HTMLElement | null>\n}\n\nexport interface AutocompleteAria {\n /** Props for the autocomplete textfield/searchfield element. These should be passed to the textfield/searchfield aria hooks respectively. */\n textFieldProps: AriaTextFieldProps,\n /** Props for the collection, to be passed to collection's respective aria hook (e.g. useMenu). */\n collectionProps: CollectionOptions,\n /** Ref to attach to the wrapped collection. */\n collectionRef: RefObject<HTMLElement | null>,\n /** A filter function that returns if the provided collection node should be filtered out of the collection. */\n filter?: (nodeTextValue: string) => boolean\n}\n\n/**\n * Provides the behavior and accessibility implementation for an autocomplete component.\n * An autocomplete combines a text input with a collection, allowing users to filter the collection's contents match a query.\n * @param props - Props for the autocomplete.\n * @param state - State for the autocomplete, as returned by `useAutocompleteState`.\n */\nexport function useAutocomplete(props: AriaAutocompleteOptions, state: AutocompleteState): AutocompleteAria {\n let {\n inputRef,\n collectionRef,\n filter,\n disableAutoFocusFirst = false\n } = props;\n\n let collectionId = useId();\n let timeout = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);\n let delayNextActiveDescendant = useRef(false);\n let queuedActiveDescendant = useRef<string | null>(null);\n let lastCollectionNode = useRef<HTMLElement>(null);\n\n // For mobile screen readers, we don't want virtual focus, instead opting to disable FocusScope's restoreFocus and manually\n // moving focus back to the subtriggers\n let shouldUseVirtualFocus = getInteractionModality() !== 'virtual';\n\n useEffect(() => {\n return () => clearTimeout(timeout.current);\n }, []);\n\n let updateActiveDescendant = useEffectEvent((e: Event) => {\n // Ensure input is focused if the user clicks on the collection directly.\n if (!e.isTrusted && shouldUseVirtualFocus && inputRef.current && getActiveElement(getOwnerDocument(inputRef.current)) !== inputRef.current) {\n inputRef.current.focus();\n }\n\n let target = e.target as Element | null;\n if (e.isTrusted || !target || queuedActiveDescendant.current === target.id) {\n return;\n }\n\n clearTimeout(timeout.current);\n if (target !== collectionRef.current) {\n if (delayNextActiveDescendant.current) {\n queuedActiveDescendant.current = target.id;\n timeout.current = setTimeout(() => {\n state.setFocusedNodeId(target.id);\n }, 500);\n } else {\n queuedActiveDescendant.current = target.id;\n state.setFocusedNodeId(target.id);\n }\n } else {\n queuedActiveDescendant.current = null;\n state.setFocusedNodeId(null);\n }\n\n delayNextActiveDescendant.current = false;\n });\n\n let callbackRef = useCallback((collectionNode) => {\n if (collectionNode != null) {\n // When typing forward, we want to delay the setting of active descendant to not interrupt the native screen reader announcement\n // of the letter you just typed. If we recieve another focus event then we clear the queued update\n // We track lastCollectionNode to do proper cleanup since callbackRefs just pass null when unmounting. This also handles\n // React 19's extra call of the callback ref in strict mode\n lastCollectionNode.current?.removeEventListener('focusin', updateActiveDescendant);\n lastCollectionNode.current = collectionNode;\n collectionNode.addEventListener('focusin', updateActiveDescendant);\n } else {\n lastCollectionNode.current?.removeEventListener('focusin', updateActiveDescendant);\n }\n }, [updateActiveDescendant]);\n\n // Make sure to memo so that React doesn't keep registering a new event listeners on every rerender of the wrapped collection\n let mergedCollectionRef = useObjectRef(useMemo(() => mergeRefs(collectionRef, callbackRef), [collectionRef, callbackRef]));\n\n let focusFirstItem = useEffectEvent(() => {\n delayNextActiveDescendant.current = true;\n collectionRef.current?.dispatchEvent(\n new CustomEvent(FOCUS_EVENT, {\n cancelable: true,\n bubbles: true,\n detail: {\n focusStrategy: 'first'\n }\n })\n );\n });\n\n let clearVirtualFocus = useEffectEvent((clearFocusKey?: boolean) => {\n moveVirtualFocus(getActiveElement());\n queuedActiveDescendant.current = null;\n state.setFocusedNodeId(null);\n let clearFocusEvent = new CustomEvent(CLEAR_FOCUS_EVENT, {\n cancelable: true,\n bubbles: true,\n detail: {\n clearFocusKey\n }\n });\n clearTimeout(timeout.current);\n delayNextActiveDescendant.current = false;\n collectionRef.current?.dispatchEvent(clearFocusEvent);\n });\n\n // TODO: update to see if we can tell what kind of event (paste vs backspace vs typing) is happening instead\n let onChange = (value: string) => {\n // Tell wrapped collection to focus the first element in the list when typing forward and to clear focused key when deleting text\n // for screen reader announcements\n if (state.inputValue !== value && state.inputValue.length <= value.length && !disableAutoFocusFirst) {\n focusFirstItem();\n } else {\n // Fully clear focused key when backspacing since the list may change and thus we'd want to start fresh again\n clearVirtualFocus(true);\n }\n\n state.setInputValue(value);\n };\n\n let keyDownTarget = useRef<Element | null>(null);\n // For textfield specific keydown operations\n let onKeyDown = (e: BaseEvent<ReactKeyboardEvent<any>>) => {\n keyDownTarget.current = e.target as Element;\n if (e.nativeEvent.isComposing) {\n return;\n }\n\n let focusedNodeId = queuedActiveDescendant.current;\n switch (e.key) {\n case 'a':\n if (isCtrlKeyPressed(e)) {\n return;\n }\n break;\n case 'Escape':\n // Early return for Escape here so it doesn't leak the Escape event from the simulated collection event below and\n // close the dialog prematurely. Ideally that should be up to the discretion of the input element hence the check\n // for isPropagationStopped\n if (e.isDefaultPrevented()) {\n return;\n }\n break;\n case ' ':\n // Space shouldn't trigger onAction so early return.\n return;\n case 'Tab':\n // Don't propogate Tab down to the collection, otherwise we will try to focus the collection via useSelectableCollection's Tab handler (aka shift tab logic)\n // We want FocusScope to handle Tab if one exists (aka sub dialog), so special casepropogate\n if ('continuePropagation' in e) {\n e.continuePropagation();\n }\n return;\n case 'Home':\n case 'End':\n case 'PageDown':\n case 'PageUp':\n case 'ArrowUp':\n case 'ArrowDown': {\n if ((e.key === 'Home' || e.key === 'End') && focusedNodeId == null && e.shiftKey) {\n return;\n }\n\n // Prevent these keys from moving the text cursor in the input\n e.preventDefault();\n // Move virtual focus into the wrapped collection\n let focusCollection = new CustomEvent(FOCUS_EVENT, {\n cancelable: true,\n bubbles: true\n });\n\n collectionRef.current?.dispatchEvent(focusCollection);\n break;\n }\n }\n\n // Emulate the keyboard events that happen in the input field in the wrapped collection. This is for triggering things like onAction via Enter\n // or moving focus from one item to another. Stop propagation on the input event if it isn't already stopped so it doesn't leak out. For events\n // like ESC, the dispatched event below will bubble out of the collection and be stopped if handled by useSelectableCollection, otherwise will bubble\n // as expected\n if (!e.isPropagationStopped()) {\n e.stopPropagation();\n }\n\n let shouldPerformDefaultAction = true;\n if (focusedNodeId == null) {\n shouldPerformDefaultAction = collectionRef.current?.dispatchEvent(\n new KeyboardEvent(e.nativeEvent.type, e.nativeEvent)\n ) || false;\n } else {\n let item = document.getElementById(focusedNodeId);\n shouldPerformDefaultAction = item?.dispatchEvent(\n new KeyboardEvent(e.nativeEvent.type, e.nativeEvent)\n ) || false;\n }\n\n if (shouldPerformDefaultAction) {\n switch (e.key) {\n case 'ArrowLeft':\n case 'ArrowRight': {\n // Clear the activedescendant so NVDA announcements aren't interrupted but retain the focused key in the collection so the\n // user's keyboard navigation restarts from where they left off\n clearVirtualFocus();\n break;\n }\n }\n }\n };\n\n let onKeyUpCapture = useEffectEvent((e) => {\n // Dispatch simulated key up events for things like triggering links in listbox\n // Make sure to stop the propagation of the input keyup event so that the simulated keyup/down pair\n // is detected by usePress instead of the original keyup originating from the input\n if (e.target === keyDownTarget.current) {\n e.stopImmediatePropagation();\n let focusedNodeId = queuedActiveDescendant.current;\n if (focusedNodeId == null) {\n collectionRef.current?.dispatchEvent(\n new KeyboardEvent(e.type, e)\n );\n } else {\n let item = document.getElementById(focusedNodeId);\n item?.dispatchEvent(\n new KeyboardEvent(e.type, e)\n );\n }\n }\n });\n\n useEffect(() => {\n document.addEventListener('keyup', onKeyUpCapture, true);\n return () => {\n document.removeEventListener('keyup', onKeyUpCapture, true);\n };\n }, [onKeyUpCapture]);\n\n let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/autocomplete');\n let collectionProps = useLabels({\n id: collectionId,\n 'aria-label': stringFormatter.format('collectionLabel')\n });\n\n let filterFn = useCallback((nodeTextValue: string) => {\n if (filter) {\n return filter(nodeTextValue, state.inputValue);\n }\n\n return true;\n }, [state.inputValue, filter]);\n\n // Be sure to clear/restore the virtual + collection focus when blurring/refocusing the field so we only show the\n // focus ring on the virtually focused collection when are actually interacting with the Autocomplete\n let onBlur = (e: ReactFocusEvent) => {\n if (!e.isTrusted) {\n return;\n }\n\n let lastFocusedNode = queuedActiveDescendant.current ? document.getElementById(queuedActiveDescendant.current) : null;\n if (lastFocusedNode) {\n dispatchVirtualBlur(lastFocusedNode, e.relatedTarget);\n }\n };\n\n let onFocus = (e: ReactFocusEvent) => {\n if (!e.isTrusted) {\n return;\n }\n\n let curFocusedNode = queuedActiveDescendant.current ? document.getElementById(queuedActiveDescendant.current) : null;\n if (curFocusedNode) {\n let target = e.target;\n queueMicrotask(() => {\n dispatchVirtualBlur(target, curFocusedNode);\n dispatchVirtualFocus(curFocusedNode, target);\n });\n }\n };\n\n return {\n textFieldProps: {\n value: state.inputValue,\n onChange,\n onKeyDown,\n autoComplete: 'off',\n 'aria-haspopup': 'listbox',\n 'aria-controls': collectionId,\n // TODO: readd proper logic for completionMode = complete (aria-autocomplete: both)\n 'aria-autocomplete': 'list',\n 'aria-activedescendant': state.focusedNodeId ?? undefined,\n // This disable's iOS's autocorrect suggestions, since the autocomplete provides its own suggestions.\n autoCorrect: 'off',\n // This disable's the macOS Safari spell check auto corrections.\n spellCheck: 'false',\n enterKeyHint: 'go',\n onBlur,\n onFocus\n },\n collectionProps: mergeProps(collectionProps, {\n shouldUseVirtualFocus,\n disallowTypeAhead: true\n }),\n collectionRef: mergedCollectionRef,\n filter: filter != null ? filterFn : undefined\n };\n}\n"],"names":[],"version":3,"file":"useAutocomplete.module.js.map"}
@@ -0,0 +1,73 @@
1
+ var $2rg0a$reactariautils = require("@react-aria/utils");
2
+ var $2rg0a$reactariacombobox = require("@react-aria/combobox");
3
+ var $2rg0a$reactariasearchfield = require("@react-aria/searchfield");
4
+
5
+
6
+ function $parcel$export(e, n, v, s) {
7
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
8
+ }
9
+
10
+ $parcel$export(module.exports, "useSearchAutocomplete", () => $3c40871f8cc2eb01$export$da7ade746446be1f);
11
+ /*
12
+ * Copyright 2020 Adobe. All rights reserved.
13
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
14
+ * you may not use this file except in compliance with the License. You may obtain a copy
15
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
16
+ *
17
+ * Unless required by applicable law or agreed to in writing, software distributed under
18
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
19
+ * OF ANY KIND, either express or implied. See the License for the specific language
20
+ * governing permissions and limitations under the License.
21
+ */
22
+
23
+
24
+ function $3c40871f8cc2eb01$export$da7ade746446be1f(props, state) {
25
+ let { popoverRef: popoverRef, inputRef: inputRef, listBoxRef: listBoxRef, keyboardDelegate: keyboardDelegate, layoutDelegate: layoutDelegate, onSubmit: onSubmit = ()=>{}, onClear: onClear, onKeyDown: onKeyDown, onKeyUp: onKeyUp, isInvalid: isInvalid, validationState: validationState, validationBehavior: validationBehavior, isRequired: isRequired, ...otherProps } = props;
26
+ let { inputProps: inputProps, clearButtonProps: clearButtonProps } = (0, $2rg0a$reactariasearchfield.useSearchField)({
27
+ ...otherProps,
28
+ value: state.inputValue,
29
+ onChange: state.setInputValue,
30
+ autoComplete: 'off',
31
+ onClear: ()=>{
32
+ state.setInputValue('');
33
+ if (onClear) onClear();
34
+ },
35
+ onSubmit: (value)=>{
36
+ // Prevent submission from search field if menu item was selected
37
+ if (state.selectionManager.focusedKey === null) onSubmit(value, null);
38
+ },
39
+ onKeyDown: onKeyDown,
40
+ onKeyUp: onKeyUp
41
+ }, {
42
+ value: state.inputValue,
43
+ setValue: state.setInputValue
44
+ }, inputRef);
45
+ let { listBoxProps: listBoxProps, labelProps: labelProps, inputProps: comboBoxInputProps, ...validation } = (0, $2rg0a$reactariacombobox.useComboBox)({
46
+ ...otherProps,
47
+ keyboardDelegate: keyboardDelegate,
48
+ layoutDelegate: layoutDelegate,
49
+ popoverRef: popoverRef,
50
+ listBoxRef: listBoxRef,
51
+ inputRef: inputRef,
52
+ onFocus: undefined,
53
+ onFocusChange: undefined,
54
+ onBlur: undefined,
55
+ onKeyDown: undefined,
56
+ onKeyUp: undefined,
57
+ isInvalid: isInvalid,
58
+ validationState: validationState,
59
+ validationBehavior: validationBehavior,
60
+ isRequired: isRequired,
61
+ validate: undefined
62
+ }, state);
63
+ return {
64
+ labelProps: labelProps,
65
+ inputProps: (0, $2rg0a$reactariautils.mergeProps)(inputProps, comboBoxInputProps),
66
+ listBoxProps: listBoxProps,
67
+ clearButtonProps: clearButtonProps,
68
+ ...validation
69
+ };
70
+ }
71
+
72
+
73
+ //# sourceMappingURL=useSearchAutocomplete.main.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;AAkDM,SAAS,0CAAyB,KAAuC,EAAE,KAAuB;IACvG,IAAI,cACF,UAAU,YACV,QAAQ,cACR,UAAU,oBACV,gBAAgB,kBAChB,cAAc,YACd,WAAW,KAAO,YAClB,OAAO,aACP,SAAS,WACT,OAAO,aACP,SAAS,mBACT,eAAe,sBACf,kBAAkB,cAClB,UAAU,EACV,GAAG,YACJ,GAAG;IAEJ,IAAI,cAAC,UAAU,oBAAE,gBAAgB,EAAC,GAAG,CAAA,GAAA,0CAAa,EAAE;QAClD,GAAG,UAAU;QACb,OAAO,MAAM,UAAU;QACvB,UAAU,MAAM,aAAa;QAC7B,cAAc;QACd,SAAS;YACP,MAAM,aAAa,CAAC;YACpB,IAAI,SACF;QAEJ;QACA,UAAU,CAAC;YACT,iEAAiE;YACjE,IAAI,MAAM,gBAAgB,CAAC,UAAU,KAAK,MACxC,SAAS,OAAO;QAEpB;mBACA;iBACA;IACF,GAAG;QACD,OAAO,MAAM,UAAU;QACvB,UAAU,MAAM,aAAa;IAC/B,GAAG;IAGH,IAAI,gBAAC,YAAY,cAAE,UAAU,EAAE,YAAY,kBAAkB,EAAE,GAAG,YAAW,GAAG,CAAA,GAAA,oCAAU,EACxF;QACE,GAAG,UAAU;0BACb;wBACA;oBACA;oBACA;kBACA;QACA,SAAS;QACT,eAAe;QACf,QAAQ;QACR,WAAW;QACX,SAAS;mBACT;yBACA;4BACA;oBACA;QACA,UAAU;IACZ,GACA;IAGF,OAAO;oBACL;QACA,YAAY,CAAA,GAAA,gCAAS,EAAE,YAAY;sBACnC;0BACA;QACA,GAAG,UAAU;IACf;AACF","sources":["packages/@react-aria/autocomplete/src/useSearchAutocomplete.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaButtonProps} from '@react-types/button';\nimport {AriaListBoxOptions} from '@react-aria/listbox';\nimport {AriaSearchAutocompleteProps} from '@react-types/autocomplete';\nimport {ComboBoxState} from '@react-stately/combobox';\nimport {DOMAttributes, KeyboardDelegate, LayoutDelegate, RefObject, ValidationResult} from '@react-types/shared';\nimport {InputHTMLAttributes} from 'react';\nimport {mergeProps} from '@react-aria/utils';\nimport {useComboBox} from '@react-aria/combobox';\nimport {useSearchField} from '@react-aria/searchfield';\n\nexport interface SearchAutocompleteAria<T> extends ValidationResult {\n /** Props for the label element. */\n labelProps: DOMAttributes,\n /** Props for the search input element. */\n inputProps: InputHTMLAttributes<HTMLInputElement>,\n /** Props for the list box, to be passed to [useListBox](useListBox.html). */\n listBoxProps: AriaListBoxOptions<T>,\n /** Props for the search input's clear button. */\n clearButtonProps: AriaButtonProps,\n /** Props for the search autocomplete description element, if any. */\n descriptionProps: DOMAttributes,\n /** Props for the search autocomplete error message element, if any. */\n errorMessageProps: DOMAttributes\n}\n\nexport interface AriaSearchAutocompleteOptions<T> extends AriaSearchAutocompleteProps<T> {\n /** The ref for the input element. */\n inputRef: RefObject<HTMLInputElement | null>,\n /** The ref for the list box popover. */\n popoverRef: RefObject<HTMLDivElement | null>,\n /** The ref for the list box. */\n listBoxRef: RefObject<HTMLElement | null>,\n /** An optional keyboard delegate implementation, to override the default. */\n keyboardDelegate?: KeyboardDelegate,\n /**\n * A delegate object that provides layout information for items in the collection.\n * By default this uses the DOM, but this can be overridden to implement things like\n * virtualized scrolling.\n */\n layoutDelegate?: LayoutDelegate\n}\n\n/**\n * Provides the behavior and accessibility implementation for a search autocomplete component.\n * A search autocomplete combines a combobox with a searchfield, allowing users to filter a list of options to items matching a query.\n * @param props - Props for the search autocomplete.\n * @param state - State for the search autocomplete, as returned by `useSearchAutocomplete`.\n */\nexport function useSearchAutocomplete<T>(props: AriaSearchAutocompleteOptions<T>, state: ComboBoxState<T>): SearchAutocompleteAria<T> {\n let {\n popoverRef,\n inputRef,\n listBoxRef,\n keyboardDelegate,\n layoutDelegate,\n onSubmit = () => {},\n onClear,\n onKeyDown,\n onKeyUp,\n isInvalid,\n validationState,\n validationBehavior,\n isRequired,\n ...otherProps\n } = props;\n\n let {inputProps, clearButtonProps} = useSearchField({\n ...otherProps,\n value: state.inputValue,\n onChange: state.setInputValue,\n autoComplete: 'off',\n onClear: () => {\n state.setInputValue('');\n if (onClear) {\n onClear();\n }\n },\n onSubmit: (value) => {\n // Prevent submission from search field if menu item was selected\n if (state.selectionManager.focusedKey === null) {\n onSubmit(value, null);\n }\n },\n onKeyDown,\n onKeyUp\n }, {\n value: state.inputValue,\n setValue: state.setInputValue\n }, inputRef);\n\n\n let {listBoxProps, labelProps, inputProps: comboBoxInputProps, ...validation} = useComboBox(\n {\n ...otherProps,\n keyboardDelegate,\n layoutDelegate,\n popoverRef,\n listBoxRef,\n inputRef,\n onFocus: undefined,\n onFocusChange: undefined,\n onBlur: undefined,\n onKeyDown: undefined,\n onKeyUp: undefined,\n isInvalid,\n validationState,\n validationBehavior,\n isRequired,\n validate: undefined\n },\n state\n );\n\n return {\n labelProps,\n inputProps: mergeProps(inputProps, comboBoxInputProps),\n listBoxProps,\n clearButtonProps,\n ...validation\n };\n}\n"],"names":[],"version":3,"file":"useSearchAutocomplete.main.js.map"}
@@ -0,0 +1,68 @@
1
+ import {mergeProps as $3Hzop$mergeProps} from "@react-aria/utils";
2
+ import {useComboBox as $3Hzop$useComboBox} from "@react-aria/combobox";
3
+ import {useSearchField as $3Hzop$useSearchField} from "@react-aria/searchfield";
4
+
5
+ /*
6
+ * Copyright 2020 Adobe. All rights reserved.
7
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License. You may obtain a copy
9
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software distributed under
12
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
13
+ * OF ANY KIND, either express or implied. See the License for the specific language
14
+ * governing permissions and limitations under the License.
15
+ */
16
+
17
+
18
+ function $c04f11f368135585$export$da7ade746446be1f(props, state) {
19
+ let { popoverRef: popoverRef, inputRef: inputRef, listBoxRef: listBoxRef, keyboardDelegate: keyboardDelegate, layoutDelegate: layoutDelegate, onSubmit: onSubmit = ()=>{}, onClear: onClear, onKeyDown: onKeyDown, onKeyUp: onKeyUp, isInvalid: isInvalid, validationState: validationState, validationBehavior: validationBehavior, isRequired: isRequired, ...otherProps } = props;
20
+ let { inputProps: inputProps, clearButtonProps: clearButtonProps } = (0, $3Hzop$useSearchField)({
21
+ ...otherProps,
22
+ value: state.inputValue,
23
+ onChange: state.setInputValue,
24
+ autoComplete: 'off',
25
+ onClear: ()=>{
26
+ state.setInputValue('');
27
+ if (onClear) onClear();
28
+ },
29
+ onSubmit: (value)=>{
30
+ // Prevent submission from search field if menu item was selected
31
+ if (state.selectionManager.focusedKey === null) onSubmit(value, null);
32
+ },
33
+ onKeyDown: onKeyDown,
34
+ onKeyUp: onKeyUp
35
+ }, {
36
+ value: state.inputValue,
37
+ setValue: state.setInputValue
38
+ }, inputRef);
39
+ let { listBoxProps: listBoxProps, labelProps: labelProps, inputProps: comboBoxInputProps, ...validation } = (0, $3Hzop$useComboBox)({
40
+ ...otherProps,
41
+ keyboardDelegate: keyboardDelegate,
42
+ layoutDelegate: layoutDelegate,
43
+ popoverRef: popoverRef,
44
+ listBoxRef: listBoxRef,
45
+ inputRef: inputRef,
46
+ onFocus: undefined,
47
+ onFocusChange: undefined,
48
+ onBlur: undefined,
49
+ onKeyDown: undefined,
50
+ onKeyUp: undefined,
51
+ isInvalid: isInvalid,
52
+ validationState: validationState,
53
+ validationBehavior: validationBehavior,
54
+ isRequired: isRequired,
55
+ validate: undefined
56
+ }, state);
57
+ return {
58
+ labelProps: labelProps,
59
+ inputProps: (0, $3Hzop$mergeProps)(inputProps, comboBoxInputProps),
60
+ listBoxProps: listBoxProps,
61
+ clearButtonProps: clearButtonProps,
62
+ ...validation
63
+ };
64
+ }
65
+
66
+
67
+ export {$c04f11f368135585$export$da7ade746446be1f as useSearchAutocomplete};
68
+ //# sourceMappingURL=useSearchAutocomplete.module.js.map
@@ -0,0 +1,68 @@
1
+ import {mergeProps as $3Hzop$mergeProps} from "@react-aria/utils";
2
+ import {useComboBox as $3Hzop$useComboBox} from "@react-aria/combobox";
3
+ import {useSearchField as $3Hzop$useSearchField} from "@react-aria/searchfield";
4
+
5
+ /*
6
+ * Copyright 2020 Adobe. All rights reserved.
7
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License. You may obtain a copy
9
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software distributed under
12
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
13
+ * OF ANY KIND, either express or implied. See the License for the specific language
14
+ * governing permissions and limitations under the License.
15
+ */
16
+
17
+
18
+ function $c04f11f368135585$export$da7ade746446be1f(props, state) {
19
+ let { popoverRef: popoverRef, inputRef: inputRef, listBoxRef: listBoxRef, keyboardDelegate: keyboardDelegate, layoutDelegate: layoutDelegate, onSubmit: onSubmit = ()=>{}, onClear: onClear, onKeyDown: onKeyDown, onKeyUp: onKeyUp, isInvalid: isInvalid, validationState: validationState, validationBehavior: validationBehavior, isRequired: isRequired, ...otherProps } = props;
20
+ let { inputProps: inputProps, clearButtonProps: clearButtonProps } = (0, $3Hzop$useSearchField)({
21
+ ...otherProps,
22
+ value: state.inputValue,
23
+ onChange: state.setInputValue,
24
+ autoComplete: 'off',
25
+ onClear: ()=>{
26
+ state.setInputValue('');
27
+ if (onClear) onClear();
28
+ },
29
+ onSubmit: (value)=>{
30
+ // Prevent submission from search field if menu item was selected
31
+ if (state.selectionManager.focusedKey === null) onSubmit(value, null);
32
+ },
33
+ onKeyDown: onKeyDown,
34
+ onKeyUp: onKeyUp
35
+ }, {
36
+ value: state.inputValue,
37
+ setValue: state.setInputValue
38
+ }, inputRef);
39
+ let { listBoxProps: listBoxProps, labelProps: labelProps, inputProps: comboBoxInputProps, ...validation } = (0, $3Hzop$useComboBox)({
40
+ ...otherProps,
41
+ keyboardDelegate: keyboardDelegate,
42
+ layoutDelegate: layoutDelegate,
43
+ popoverRef: popoverRef,
44
+ listBoxRef: listBoxRef,
45
+ inputRef: inputRef,
46
+ onFocus: undefined,
47
+ onFocusChange: undefined,
48
+ onBlur: undefined,
49
+ onKeyDown: undefined,
50
+ onKeyUp: undefined,
51
+ isInvalid: isInvalid,
52
+ validationState: validationState,
53
+ validationBehavior: validationBehavior,
54
+ isRequired: isRequired,
55
+ validate: undefined
56
+ }, state);
57
+ return {
58
+ labelProps: labelProps,
59
+ inputProps: (0, $3Hzop$mergeProps)(inputProps, comboBoxInputProps),
60
+ listBoxProps: listBoxProps,
61
+ clearButtonProps: clearButtonProps,
62
+ ...validation
63
+ };
64
+ }
65
+
66
+
67
+ export {$c04f11f368135585$export$da7ade746446be1f as useSearchAutocomplete};
68
+ //# sourceMappingURL=useSearchAutocomplete.module.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;AAAA;;;;;;;;;;CAUC;;;AAkDM,SAAS,0CAAyB,KAAuC,EAAE,KAAuB;IACvG,IAAI,cACF,UAAU,YACV,QAAQ,cACR,UAAU,oBACV,gBAAgB,kBAChB,cAAc,YACd,WAAW,KAAO,YAClB,OAAO,aACP,SAAS,WACT,OAAO,aACP,SAAS,mBACT,eAAe,sBACf,kBAAkB,cAClB,UAAU,EACV,GAAG,YACJ,GAAG;IAEJ,IAAI,cAAC,UAAU,oBAAE,gBAAgB,EAAC,GAAG,CAAA,GAAA,qBAAa,EAAE;QAClD,GAAG,UAAU;QACb,OAAO,MAAM,UAAU;QACvB,UAAU,MAAM,aAAa;QAC7B,cAAc;QACd,SAAS;YACP,MAAM,aAAa,CAAC;YACpB,IAAI,SACF;QAEJ;QACA,UAAU,CAAC;YACT,iEAAiE;YACjE,IAAI,MAAM,gBAAgB,CAAC,UAAU,KAAK,MACxC,SAAS,OAAO;QAEpB;mBACA;iBACA;IACF,GAAG;QACD,OAAO,MAAM,UAAU;QACvB,UAAU,MAAM,aAAa;IAC/B,GAAG;IAGH,IAAI,gBAAC,YAAY,cAAE,UAAU,EAAE,YAAY,kBAAkB,EAAE,GAAG,YAAW,GAAG,CAAA,GAAA,kBAAU,EACxF;QACE,GAAG,UAAU;0BACb;wBACA;oBACA;oBACA;kBACA;QACA,SAAS;QACT,eAAe;QACf,QAAQ;QACR,WAAW;QACX,SAAS;mBACT;yBACA;4BACA;oBACA;QACA,UAAU;IACZ,GACA;IAGF,OAAO;oBACL;QACA,YAAY,CAAA,GAAA,iBAAS,EAAE,YAAY;sBACnC;0BACA;QACA,GAAG,UAAU;IACf;AACF","sources":["packages/@react-aria/autocomplete/src/useSearchAutocomplete.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaButtonProps} from '@react-types/button';\nimport {AriaListBoxOptions} from '@react-aria/listbox';\nimport {AriaSearchAutocompleteProps} from '@react-types/autocomplete';\nimport {ComboBoxState} from '@react-stately/combobox';\nimport {DOMAttributes, KeyboardDelegate, LayoutDelegate, RefObject, ValidationResult} from '@react-types/shared';\nimport {InputHTMLAttributes} from 'react';\nimport {mergeProps} from '@react-aria/utils';\nimport {useComboBox} from '@react-aria/combobox';\nimport {useSearchField} from '@react-aria/searchfield';\n\nexport interface SearchAutocompleteAria<T> extends ValidationResult {\n /** Props for the label element. */\n labelProps: DOMAttributes,\n /** Props for the search input element. */\n inputProps: InputHTMLAttributes<HTMLInputElement>,\n /** Props for the list box, to be passed to [useListBox](useListBox.html). */\n listBoxProps: AriaListBoxOptions<T>,\n /** Props for the search input's clear button. */\n clearButtonProps: AriaButtonProps,\n /** Props for the search autocomplete description element, if any. */\n descriptionProps: DOMAttributes,\n /** Props for the search autocomplete error message element, if any. */\n errorMessageProps: DOMAttributes\n}\n\nexport interface AriaSearchAutocompleteOptions<T> extends AriaSearchAutocompleteProps<T> {\n /** The ref for the input element. */\n inputRef: RefObject<HTMLInputElement | null>,\n /** The ref for the list box popover. */\n popoverRef: RefObject<HTMLDivElement | null>,\n /** The ref for the list box. */\n listBoxRef: RefObject<HTMLElement | null>,\n /** An optional keyboard delegate implementation, to override the default. */\n keyboardDelegate?: KeyboardDelegate,\n /**\n * A delegate object that provides layout information for items in the collection.\n * By default this uses the DOM, but this can be overridden to implement things like\n * virtualized scrolling.\n */\n layoutDelegate?: LayoutDelegate\n}\n\n/**\n * Provides the behavior and accessibility implementation for a search autocomplete component.\n * A search autocomplete combines a combobox with a searchfield, allowing users to filter a list of options to items matching a query.\n * @param props - Props for the search autocomplete.\n * @param state - State for the search autocomplete, as returned by `useSearchAutocomplete`.\n */\nexport function useSearchAutocomplete<T>(props: AriaSearchAutocompleteOptions<T>, state: ComboBoxState<T>): SearchAutocompleteAria<T> {\n let {\n popoverRef,\n inputRef,\n listBoxRef,\n keyboardDelegate,\n layoutDelegate,\n onSubmit = () => {},\n onClear,\n onKeyDown,\n onKeyUp,\n isInvalid,\n validationState,\n validationBehavior,\n isRequired,\n ...otherProps\n } = props;\n\n let {inputProps, clearButtonProps} = useSearchField({\n ...otherProps,\n value: state.inputValue,\n onChange: state.setInputValue,\n autoComplete: 'off',\n onClear: () => {\n state.setInputValue('');\n if (onClear) {\n onClear();\n }\n },\n onSubmit: (value) => {\n // Prevent submission from search field if menu item was selected\n if (state.selectionManager.focusedKey === null) {\n onSubmit(value, null);\n }\n },\n onKeyDown,\n onKeyUp\n }, {\n value: state.inputValue,\n setValue: state.setInputValue\n }, inputRef);\n\n\n let {listBoxProps, labelProps, inputProps: comboBoxInputProps, ...validation} = useComboBox(\n {\n ...otherProps,\n keyboardDelegate,\n layoutDelegate,\n popoverRef,\n listBoxRef,\n inputRef,\n onFocus: undefined,\n onFocusChange: undefined,\n onBlur: undefined,\n onKeyDown: undefined,\n onKeyUp: undefined,\n isInvalid,\n validationState,\n validationBehavior,\n isRequired,\n validate: undefined\n },\n state\n );\n\n return {\n labelProps,\n inputProps: mergeProps(inputProps, comboBoxInputProps),\n listBoxProps,\n clearButtonProps,\n ...validation\n };\n}\n"],"names":[],"version":3,"file":"useSearchAutocomplete.module.js.map"}
@@ -0,0 +1,6 @@
1
+ module.exports = {
2
+ "collectionLabel": `\u{5EFA}\u{8BAE}`
3
+ };
4
+
5
+
6
+ //# sourceMappingURL=zh-CN.main.js.map
@@ -0,0 +1 @@
1
+ {"mappings":"AAAA,iBAAiB;IAAG,mBAAmB,CAAC,gBAAE,CAAC;AAC3C","sources":["packages/@react-aria/autocomplete/intl/zh-CN.json"],"sourcesContent":["{\n \"collectionLabel\": \"建议\"\n}\n"],"names":[],"version":3,"file":"zh-CN.main.js.map"}
package/dist/zh-CN.mjs ADDED
@@ -0,0 +1,8 @@
1
+ var $e98983e40b8886ed$exports = {};
2
+ $e98983e40b8886ed$exports = {
3
+ "collectionLabel": `\u{5EFA}\u{8BAE}`
4
+ };
5
+
6
+
7
+ export {$e98983e40b8886ed$exports as default};
8
+ //# sourceMappingURL=zh-CN.module.js.map
@@ -0,0 +1,8 @@
1
+ var $e98983e40b8886ed$exports = {};
2
+ $e98983e40b8886ed$exports = {
3
+ "collectionLabel": `\u{5EFA}\u{8BAE}`
4
+ };
5
+
6
+
7
+ export {$e98983e40b8886ed$exports as default};
8
+ //# sourceMappingURL=zh-CN.module.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";AAAA,4BAAiB;IAAG,mBAAmB,CAAC,gBAAE,CAAC;AAC3C","sources":["packages/@react-aria/autocomplete/intl/zh-CN.json"],"sourcesContent":["{\n \"collectionLabel\": \"建议\"\n}\n"],"names":[],"version":3,"file":"zh-CN.module.js.map"}
@@ -0,0 +1,6 @@
1
+ module.exports = {
2
+ "collectionLabel": `\u{5EFA}\u{8B70}`
3
+ };
4
+
5
+
6
+ //# sourceMappingURL=zh-TW.main.js.map
@@ -0,0 +1 @@
1
+ {"mappings":"AAAA,iBAAiB;IAAG,mBAAmB,CAAC,gBAAE,CAAC;AAC3C","sources":["packages/@react-aria/autocomplete/intl/zh-TW.json"],"sourcesContent":["{\n \"collectionLabel\": \"建議\"\n}\n"],"names":[],"version":3,"file":"zh-TW.main.js.map"}
package/dist/zh-TW.mjs ADDED
@@ -0,0 +1,8 @@
1
+ var $5bfd172db1a18268$exports = {};
2
+ $5bfd172db1a18268$exports = {
3
+ "collectionLabel": `\u{5EFA}\u{8B70}`
4
+ };
5
+
6
+
7
+ export {$5bfd172db1a18268$exports as default};
8
+ //# sourceMappingURL=zh-TW.module.js.map
@@ -0,0 +1,8 @@
1
+ var $5bfd172db1a18268$exports = {};
2
+ $5bfd172db1a18268$exports = {
3
+ "collectionLabel": `\u{5EFA}\u{8B70}`
4
+ };
5
+
6
+
7
+ export {$5bfd172db1a18268$exports as default};
8
+ //# sourceMappingURL=zh-TW.module.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";AAAA,4BAAiB;IAAG,mBAAmB,CAAC,gBAAE,CAAC;AAC3C","sources":["packages/@react-aria/autocomplete/intl/zh-TW.json"],"sourcesContent":["{\n \"collectionLabel\": \"建議\"\n}\n"],"names":[],"version":3,"file":"zh-TW.module.js.map"}