@bjj/nuxt-layer-shadcn-ui 0.12.11 → 0.12.13
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.
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
<script setup lang="ts" generic="TValue extends string | number = string, TMeta = unknown">
|
|
2
2
|
import {
|
|
3
3
|
Command,
|
|
4
|
-
CommandEmpty,
|
|
5
4
|
CommandGroup,
|
|
6
|
-
CommandInput,
|
|
7
5
|
CommandItem,
|
|
8
6
|
CommandList,
|
|
9
7
|
CommandSeparator,
|
|
@@ -18,6 +16,7 @@ import {
|
|
|
18
16
|
PopoverContent,
|
|
19
17
|
PopoverTrigger,
|
|
20
18
|
} from '../../shadcn/popover'
|
|
19
|
+
import { ListboxFilter } from 'reka-ui'
|
|
21
20
|
import type { SelectOption, SelectProps } from './types'
|
|
22
21
|
|
|
23
22
|
type Option = SelectOption<TValue, TMeta>
|
|
@@ -77,9 +76,39 @@ function handleTriggerClickCapture (event: Event) {
|
|
|
77
76
|
}
|
|
78
77
|
|
|
79
78
|
// -- Filter --
|
|
79
|
+
//
|
|
80
|
+
// We render our own ListboxFilter search box instead of shadcn's CommandInput:
|
|
81
|
+
// CommandInput only writes into Command's internal filterState (client-side
|
|
82
|
+
// filtering) and reka's ListboxRoot never emits `update:searchTerm`, so the
|
|
83
|
+
// typed term can't be observed for server-side search. Driving our own term
|
|
84
|
+
// surfaces it via `@search` and keeps filterState idle (no double filtering).
|
|
85
|
+
//
|
|
86
|
+
// `filter === true` matches option labels; a `filter` function is a custom
|
|
87
|
+
// matcher (server search passes `items => items` to show everything and filter
|
|
88
|
+
// on the server instead).
|
|
89
|
+
|
|
90
|
+
const searchTerm = ref('')
|
|
91
|
+
|
|
92
|
+
function handleSearchInput (value: string) {
|
|
93
|
+
searchTerm.value = value
|
|
94
|
+
emit('search', value)
|
|
95
|
+
}
|
|
80
96
|
|
|
81
|
-
|
|
82
|
-
|
|
97
|
+
// Clear the local term when the popover closes so a reopen starts fresh.
|
|
98
|
+
watch(open, value => {
|
|
99
|
+
if (!value) searchTerm.value = ''
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
const visibleOptions = computed<Option[]>(() => {
|
|
103
|
+
const options = props.options ?? []
|
|
104
|
+
const keyword = searchTerm.value
|
|
105
|
+
if (!props.filter || !keyword) return options
|
|
106
|
+
if (typeof props.filter === 'function') {
|
|
107
|
+
const kept = new Set(props.filter(options.map(opt => opt.label), keyword))
|
|
108
|
+
return options.filter(opt => kept.has(opt.label))
|
|
109
|
+
}
|
|
110
|
+
const lower = keyword.toLowerCase()
|
|
111
|
+
return options.filter(opt => opt.label.toLowerCase().includes(lower))
|
|
83
112
|
})
|
|
84
113
|
|
|
85
114
|
// -- Selection --
|
|
@@ -126,7 +155,7 @@ const groupedOptions = computed<OptionGroupEntry[]>(() => {
|
|
|
126
155
|
const groups: OptionGroupEntry[] = []
|
|
127
156
|
const map = new Map<string | undefined, OptionGroupEntry>()
|
|
128
157
|
|
|
129
|
-
for (const opt of
|
|
158
|
+
for (const opt of visibleOptions.value) {
|
|
130
159
|
const key = opt.group
|
|
131
160
|
let group = map.get(key)
|
|
132
161
|
if (!group) {
|
|
@@ -254,19 +283,36 @@ function handleClear (event: MouseEvent) {
|
|
|
254
283
|
<PopoverContent class="p-0 w-(--reka-popover-trigger-width)">
|
|
255
284
|
<Command
|
|
256
285
|
:modelValue="commandModelValue"
|
|
257
|
-
:filterFunction="commandFilterFunction"
|
|
258
286
|
:multiple="multiple"
|
|
259
287
|
highlightOnHover
|
|
260
|
-
@update:searchTerm="(value: string) => emit('search', value)"
|
|
261
288
|
>
|
|
262
|
-
<
|
|
289
|
+
<div
|
|
263
290
|
v-if="!!filter"
|
|
264
|
-
|
|
265
|
-
|
|
291
|
+
class="gap-2 px-3 h-9 flex items-center border-b"
|
|
292
|
+
>
|
|
293
|
+
<Icon
|
|
294
|
+
name="search"
|
|
295
|
+
class="size-4 shrink-0 opacity-50"
|
|
296
|
+
/>
|
|
297
|
+
<ListboxFilter
|
|
298
|
+
:modelValue="searchTerm"
|
|
299
|
+
autoFocus
|
|
300
|
+
:placeholder="searchPlaceholder || T('searchPlaceholder')"
|
|
301
|
+
class="
|
|
302
|
+
py-3 text-sm
|
|
303
|
+
placeholder:text-muted-foreground
|
|
304
|
+
h-10 flex w-full bg-transparent outline-hidden
|
|
305
|
+
"
|
|
306
|
+
@update:modelValue="handleSearchInput"
|
|
307
|
+
/>
|
|
308
|
+
</div>
|
|
266
309
|
<CommandList>
|
|
267
|
-
<
|
|
310
|
+
<div
|
|
311
|
+
v-if="!loading && groupedOptions.length === 0"
|
|
312
|
+
class="py-6 text-sm text-muted-foreground text-center"
|
|
313
|
+
>
|
|
268
314
|
{{ emptyText || T('noItems') }}
|
|
269
|
-
</
|
|
315
|
+
</div>
|
|
270
316
|
|
|
271
317
|
<template
|
|
272
318
|
v-for="(group, index) in groupedOptions"
|
|
@@ -129,7 +129,13 @@ const hintLines = computed(() => {
|
|
|
129
129
|
})
|
|
130
130
|
|
|
131
131
|
defineSlots<{
|
|
132
|
-
hint?: (props: {
|
|
132
|
+
hint?: (props: {
|
|
133
|
+
lines: string[]
|
|
134
|
+
maxSizeLabel: string
|
|
135
|
+
acceptLabel: string
|
|
136
|
+
maxCount?: number
|
|
137
|
+
allowMany: boolean
|
|
138
|
+
}) => any
|
|
133
139
|
}>()
|
|
134
140
|
|
|
135
141
|
const triggerLabel = computed(() => {
|
|
@@ -465,6 +471,10 @@ async function onDrop (e: DragEvent) {
|
|
|
465
471
|
<slot
|
|
466
472
|
name="hint"
|
|
467
473
|
:lines="hintLines"
|
|
474
|
+
:maxSizeLabel="maxSizeLabel"
|
|
475
|
+
:acceptLabel="acceptLabel"
|
|
476
|
+
:maxCount="maxCount"
|
|
477
|
+
:allowMany="allowMany"
|
|
468
478
|
>
|
|
469
479
|
<div
|
|
470
480
|
v-for="line in hintLines"
|
|
@@ -502,6 +512,10 @@ async function onDrop (e: DragEvent) {
|
|
|
502
512
|
<slot
|
|
503
513
|
name="hint"
|
|
504
514
|
:lines="hintLines"
|
|
515
|
+
:maxSizeLabel="maxSizeLabel"
|
|
516
|
+
:acceptLabel="acceptLabel"
|
|
517
|
+
:maxCount="maxCount"
|
|
518
|
+
:allowMany="allowMany"
|
|
505
519
|
>
|
|
506
520
|
<div
|
|
507
521
|
v-for="line in hintLines"
|
|
@@ -672,6 +686,10 @@ async function onDrop (e: DragEvent) {
|
|
|
672
686
|
<slot
|
|
673
687
|
name="hint"
|
|
674
688
|
:lines="hintLines"
|
|
689
|
+
:maxSizeLabel="maxSizeLabel"
|
|
690
|
+
:acceptLabel="acceptLabel"
|
|
691
|
+
:maxCount="maxCount"
|
|
692
|
+
:allowMany="allowMany"
|
|
675
693
|
>
|
|
676
694
|
<div
|
|
677
695
|
v-for="line in hintLines"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bjj/nuxt-layer-shadcn-ui",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.13",
|
|
4
4
|
"description": "Nuxt layer providing shadcn-vue based UI components",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./nuxt.config.ts",
|
|
@@ -42,5 +42,5 @@
|
|
|
42
42
|
"vue-i18n": "^11",
|
|
43
43
|
"vue-router": "^4 || ^5"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "ac169020da6ae2c20d53c89d7c3b628f52d806c9"
|
|
46
46
|
}
|