@bagelink/vue 1.4.184 → 1.5.3
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/components/RouterWrapper.vue.d.ts +16 -1
- package/dist/components/RouterWrapper.vue.d.ts.map +1 -1
- package/dist/components/form/inputs/RichText/index.vue.d.ts.map +1 -1
- package/dist/components/form/inputs/SelectBtn.vue.d.ts.map +1 -1
- package/dist/components/form/inputs/SelectInput.vue.d.ts.map +1 -1
- package/dist/components/form/inputs/Upload/upload.d.ts.map +1 -1
- package/dist/components/layout/AppSidebar.vue.d.ts +4 -4
- package/dist/components/layout/AppSidebar.vue.d.ts.map +1 -1
- package/dist/index.cjs +31 -25
- package/dist/index.mjs +31 -25
- package/dist/plugins/bagel.d.ts +1 -0
- package/dist/plugins/bagel.d.ts.map +1 -1
- package/dist/style.css +1 -1
- package/dist/utils/BagelFormUtils.d.ts +16 -0
- package/dist/utils/BagelFormUtils.d.ts.map +1 -1
- package/dist/utils/useSearch.d.ts +18 -1
- package/dist/utils/useSearch.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/components/RouterWrapper.vue +13 -12
- package/src/components/form/inputs/RichText/index.vue +14 -8
- package/src/components/form/inputs/SelectBtn.vue +3 -8
- package/src/components/form/inputs/SelectInput.vue +1 -0
- package/src/components/form/inputs/Upload/upload.ts +25 -10
- package/src/components/layout/AppSidebar.vue +8 -21
- package/src/plugins/bagel.ts +7 -1
- package/src/styles/layout.css +82 -2
- package/src/styles/mobilLayout.css +91 -1
- package/src/utils/BagelFormUtils.ts +43 -0
- package/src/utils/useSearch.ts +57 -2
package/src/utils/useSearch.ts
CHANGED
|
@@ -129,6 +129,7 @@ export interface SearchResult<T> {
|
|
|
129
129
|
hasResults: ComputedRef<boolean>
|
|
130
130
|
isSearching: ComputedRef<boolean>
|
|
131
131
|
isLoading: ComputedRef<boolean> // New property to track server-side loading state
|
|
132
|
+
searchTerm?: import('vue').Ref<string> // Optional searchTerm ref for simplified usage
|
|
132
133
|
}
|
|
133
134
|
|
|
134
135
|
/**
|
|
@@ -349,12 +350,59 @@ export function searchItems<T>(params: SearchItemParams<T>): T[] {
|
|
|
349
350
|
/**
|
|
350
351
|
* Vue composable for searching items with reactive results
|
|
351
352
|
* Supports both client-side filtering and server-side search
|
|
352
|
-
*
|
|
353
|
+
*
|
|
354
|
+
* Usage 1 - Simplified: Pass items directly and get searchTerm ref back
|
|
355
|
+
* ```ts
|
|
356
|
+
* const { results, searchTerm } = useSearch(itemList)
|
|
357
|
+
* ```
|
|
358
|
+
*
|
|
359
|
+
* Usage 2 - Advanced: Pass full params object with custom search term
|
|
360
|
+
* ```ts
|
|
361
|
+
* const searchTerm = ref('')
|
|
362
|
+
* const { results } = useSearch({ searchTerm, items: itemList, keysToSearch: ['name'] })
|
|
363
|
+
* ```
|
|
364
|
+
*
|
|
365
|
+
* @param paramsOrItems Search parameters object or array of items for simplified usage
|
|
366
|
+
* @param options Optional additional search parameters (only used with simplified usage)
|
|
353
367
|
* @returns Reactive search results and metadata
|
|
354
368
|
*/
|
|
369
|
+
export function useSearch<T>(
|
|
370
|
+
items: MaybeRefOrGetter<T[]>,
|
|
371
|
+
options?: Omit<SearchItemParams<T>, 'items' | 'searchTerm'>
|
|
372
|
+
): SearchResult<T> & { searchTerm: import('vue').Ref<string> }
|
|
355
373
|
export function useSearch<T>(
|
|
356
374
|
params: SearchItemParams<T>
|
|
375
|
+
): SearchResult<T>
|
|
376
|
+
export function useSearch<T>(
|
|
377
|
+
paramsOrItems: SearchItemParams<T> | MaybeRefOrGetter<T[]>,
|
|
378
|
+
options?: Omit<SearchItemParams<T>, 'items' | 'searchTerm'>
|
|
357
379
|
): SearchResult<T> {
|
|
380
|
+
// Normalize inputs - detect if first argument is items array or params object
|
|
381
|
+
let params: SearchItemParams<T>
|
|
382
|
+
let ownedSearchTerm: import('vue').Ref<string> | undefined
|
|
383
|
+
|
|
384
|
+
// Check if first argument is an array or ref (simplified usage)
|
|
385
|
+
// If it's a params object, it won't have these characteristics
|
|
386
|
+
const isArray = Array.isArray(paramsOrItems)
|
|
387
|
+
const isFunction = typeof paramsOrItems === 'function'
|
|
388
|
+
const isObject = typeof paramsOrItems === 'object' && paramsOrItems !== null
|
|
389
|
+
const isRef = isObject && 'value' in paramsOrItems && !('items' in paramsOrItems)
|
|
390
|
+
|
|
391
|
+
const isSimplifiedUsage = isArray || isFunction || isRef
|
|
392
|
+
|
|
393
|
+
if (isSimplifiedUsage) {
|
|
394
|
+
// Simplified usage: useSearch(items, options)
|
|
395
|
+
ownedSearchTerm = ref('')
|
|
396
|
+
params = {
|
|
397
|
+
items: paramsOrItems as MaybeRefOrGetter<T[]>,
|
|
398
|
+
searchTerm: ownedSearchTerm,
|
|
399
|
+
...options
|
|
400
|
+
}
|
|
401
|
+
} else {
|
|
402
|
+
// Advanced usage: useSearch(params)
|
|
403
|
+
params = paramsOrItems as SearchItemParams<T>
|
|
404
|
+
}
|
|
405
|
+
|
|
358
406
|
const { searchTerm, minChars = 2, serverSearch, debounceMs = 300 } = params
|
|
359
407
|
|
|
360
408
|
// For tracking server-side loading state
|
|
@@ -425,11 +473,18 @@ export function useSearch<T>(
|
|
|
425
473
|
return !!term && typeof term === 'string' && term.length >= minChars
|
|
426
474
|
})
|
|
427
475
|
|
|
428
|
-
|
|
476
|
+
const result: SearchResult<T> = {
|
|
429
477
|
results,
|
|
430
478
|
resultCount,
|
|
431
479
|
hasResults,
|
|
432
480
|
isSearching,
|
|
433
481
|
isLoading: computed(() => isLoading.value),
|
|
434
482
|
}
|
|
483
|
+
|
|
484
|
+
// Include searchTerm in result if we created it (simplified usage)
|
|
485
|
+
if (ownedSearchTerm) {
|
|
486
|
+
result.searchTerm = ownedSearchTerm
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
return result
|
|
435
490
|
}
|