@opendesign-plus-test/components 0.0.1-rc.54 → 0.0.1-rc.56

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opendesign-plus-test/components",
3
- "version": "0.0.1-rc.54",
3
+ "version": "0.0.1-rc.56",
4
4
  "type": "module",
5
5
  "publishConfig": {
6
6
  "access": "public",
@@ -176,11 +176,11 @@ const handleBlur = () => {
176
176
  emit('blur');
177
177
  };
178
178
 
179
- const runSearch = async () => {
179
+ const runSearch = async (overrideKeyword?: string) => {
180
180
  if (inputRef.value?.getIsUploading?.()) {
181
181
  await inputRef.value.awaitUpload?.();
182
182
  }
183
- const keyword = innerValue.value.trim();
183
+ const keyword = overrideKeyword !== undefined ? overrideKeyword.trim() : innerValue.value.trim();
184
184
  const imageUrl = internalImageUrl.value || inputRef.value?.getUploadedUrl?.() || props.imageUrl;
185
185
 
186
186
  if (!keyword && !imageUrl) return;
@@ -219,8 +219,7 @@ const handleSuggestClick = (item: OSearchRecommendItem) => {
219
219
 
220
220
  const handleRecommendClick = (val: string) => {
221
221
  emit('recommend-click', val);
222
- innerValue.value = val;
223
- runSearch();
222
+ runSearch(val);
224
223
  };
225
224
 
226
225
  const handleOnestepClick = (item: OSearchRecommendItem) => {
@@ -232,14 +231,12 @@ const handleOnestepClick = (item: OSearchRecommendItem) => {
232
231
 
233
232
  const handleHistoryClick = (val: string) => {
234
233
  emit('history-click', val);
235
- innerValue.value = val;
236
- runSearch();
234
+ runSearch(val);
237
235
  };
238
236
 
239
237
  const handleHotClick = (val: string) => {
240
238
  emit('hot-click', val);
241
- innerValue.value = val;
242
- runSearch();
239
+ runSearch(val);
243
240
  };
244
241
 
245
242
  const handleHistoryRemove = (val: string) => {
@@ -47,6 +47,10 @@ export interface OSearchInputPropsT {
47
47
  /** Auto-record history on search; default true */
48
48
  autoSaveHistory?: boolean;
49
49
 
50
+ /** ---- Hot searches (shown alongside history when no keyword) ---- */
51
+ hotItems?: string[];
52
+ hotTitle?: string;
53
+
50
54
  /** ---- "Did you mean" list (below input) ---- */
51
55
  suggestList?: string[];
52
56
  suggestListLabel?: string;
@@ -78,6 +82,7 @@ const props = withDefaults(defineProps<OSearchInputPropsT>(), {
78
82
  storeHistory: false,
79
83
  storageKey: 'search-history',
80
84
  autoSaveHistory: true,
85
+ hotItems: () => [],
81
86
  suggestList: () => [],
82
87
  clearable: true,
83
88
  closeOnSearch: true,
@@ -97,6 +102,7 @@ const emit = defineEmits<{
97
102
  (e: 'recommend-click', item: OSearchRecommendItem): void;
98
103
  (e: 'onestep-click', item: OSearchRecommendItem): void;
99
104
  (e: 'history-click', val: string): void;
105
+ (e: 'hot-click', val: string): void;
100
106
  (e: 'suggest-list-click', val: string): void;
101
107
  (e: 'delete-history', items: string[]): void;
102
108
  (e: 'delete-history-item', val: string): void;
@@ -143,8 +149,9 @@ const showDropdown = computed(() => {
143
149
  !!innerValue.value &&
144
150
  (props.suggestItems.length > 0 || props.onestepItems.length > 0 || props.showSuggestEmpty);
145
151
  const hasHistory = props.enableHistory && history.items.value.length > 0 && !innerValue.value;
152
+ const hasHot = props.hotItems.length > 0 && !innerValue.value;
146
153
  if (hasSuggest) return true;
147
- if (props.openOnFocus && hasHistory) return true;
154
+ if (props.openOnFocus && (hasHistory || hasHot)) return true;
148
155
  return false;
149
156
  });
150
157
 
@@ -163,7 +170,14 @@ const history = useSearchHistory({
163
170
  });
164
171
 
165
172
  // debounced input event
173
+ // suppressNextInput: set to true before programmatic value assignments (history/suggest
174
+ // clicks) so the watcher-triggered debounce doesn't fire the input event.
175
+ let suppressNextInput = false;
166
176
  const emitInputDebounced = useDebounceFn((val: string) => {
177
+ if (suppressNextInput) {
178
+ suppressNextInput = false;
179
+ return;
180
+ }
167
181
  emit('input', val);
168
182
  }, () => props.debounce);
169
183
 
@@ -187,11 +201,11 @@ const handleBlur = () => {
187
201
  emit('blur');
188
202
  };
189
203
 
190
- const runSearch = async () => {
204
+ const runSearch = async (overrideKeyword?: string) => {
191
205
  if (inputRef.value?.getIsUploading?.()) {
192
206
  await inputRef.value.awaitUpload?.();
193
207
  }
194
- const keyword = innerValue.value.trim();
208
+ const keyword = overrideKeyword !== undefined ? overrideKeyword.trim() : innerValue.value.trim();
195
209
  const imageUrl = inputRef.value?.getUploadedUrl?.() || props.imageUrl;
196
210
 
197
211
  if (!keyword && !imageUrl) return;
@@ -214,6 +228,7 @@ const handleClear = () => {
214
228
 
215
229
  const handleSuggestClick = (item: OSearchRecommendItem) => {
216
230
  emit('recommend-click', item);
231
+ suppressNextInput = true;
217
232
  innerValue.value = item.key;
218
233
  runSearch();
219
234
  };
@@ -228,8 +243,12 @@ const handleOnestepClick = (item: OSearchRecommendItem) => {
228
243
 
229
244
  const handleHistoryClick = (val: string) => {
230
245
  emit('history-click', val);
231
- innerValue.value = val;
232
- runSearch();
246
+ runSearch(val);
247
+ };
248
+
249
+ const handleHotClick = (val: string) => {
250
+ emit('hot-click', val);
251
+ runSearch(val);
233
252
  };
234
253
 
235
254
  const handleHistoryRemove = (val: string) => {
@@ -246,6 +265,7 @@ const handleHistoryClear = () => {
246
265
  const handleSuggestListClick = (val: string) => {
247
266
  const text = val.replace(/<[^>]+>/g, '');
248
267
  emit('suggest-list-click', text);
268
+ suppressNextInput = true;
249
269
  innerValue.value = text;
250
270
  runSearch();
251
271
  };
@@ -336,6 +356,8 @@ defineExpose({
336
356
  :suggest-title="suggestTitle"
337
357
  :history-items="enableHistory ? history.items.value : []"
338
358
  :history-title="historyTitle"
359
+ :hot-items="hotItems"
360
+ :hot-title="hotTitle"
339
361
  :no-data-text="noDataText"
340
362
  :highlight-keyword="highlightKeyword"
341
363
  :hide-on-keyword="true"
@@ -346,6 +368,7 @@ defineExpose({
346
368
  @history-click="handleHistoryClick"
347
369
  @history-remove="handleHistoryRemove"
348
370
  @history-clear="handleHistoryClear"
371
+ @hot-click="handleHotClick"
349
372
  >
350
373
  <template v-if="$slots['onestep-header']" #onestep-header="slotProps">
351
374
  <slot name="onestep-header" v-bind="slotProps" />