@bjj/nuxt-layer-shadcn-ui 0.12.12 → 0.12.14
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.
|
@@ -12,12 +12,9 @@ const formatOptions = computed<Intl.NumberFormatOptions>(() => ({
|
|
|
12
12
|
currencyDisplay: props.currencyDisplay,
|
|
13
13
|
}))
|
|
14
14
|
|
|
15
|
-
//
|
|
15
|
+
// Step matches the currency's minor unit (JPY→1, USD→0.01, BHD→0.001).
|
|
16
16
|
const defaultStep = computed(() => {
|
|
17
|
-
const { minimumFractionDigits } = new Intl.NumberFormat('en',
|
|
18
|
-
style: 'currency',
|
|
19
|
-
currency: props.currency,
|
|
20
|
-
}).resolvedOptions()
|
|
17
|
+
const { minimumFractionDigits } = new Intl.NumberFormat('en', formatOptions.value).resolvedOptions()
|
|
21
18
|
return 1 / (10 ** (minimumFractionDigits ?? 0))
|
|
22
19
|
})
|
|
23
20
|
</script>
|
|
@@ -27,5 +24,6 @@ const defaultStep = computed(() => {
|
|
|
27
24
|
:formatOptions="formatOptions"
|
|
28
25
|
:min="0"
|
|
29
26
|
:step="defaultStep"
|
|
27
|
+
@beforeinput="guardSymbolDeletion"
|
|
30
28
|
/>
|
|
31
29
|
</template>
|
|
@@ -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"
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// A symbol is letters / currency signs / percent; digits and separators (",.' "…)
|
|
2
|
+
// belong to the number and stay editable.
|
|
3
|
+
const LEADING_SYMBOL = /^[\p{L}\p{Sc}%]*/u
|
|
4
|
+
const TRAILING_SYMBOL = /[\p{L}\p{Sc}%]*$/u
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* `beforeinput` handler for InputNumber-based fields (currency, percent, unit …) that
|
|
8
|
+
* blocks deletions which would erase part of the value's symbol, keeping it intact.
|
|
9
|
+
* The symbol is the run of symbol characters at each edge of the displayed value, so
|
|
10
|
+
* it works for any currency, format, and locale. A full-selection delete that clears
|
|
11
|
+
* the field is allowed. Bind via `@beforeinput`; the event bubbles up from the inner input.
|
|
12
|
+
*/
|
|
13
|
+
export function guardSymbolDeletion (event: Event) {
|
|
14
|
+
const e = event as InputEvent
|
|
15
|
+
const input = e.target as HTMLInputElement | null
|
|
16
|
+
if (!input || !e.inputType.startsWith('delete')) return
|
|
17
|
+
|
|
18
|
+
const { value } = input
|
|
19
|
+
const start = input.selectionStart ?? 0
|
|
20
|
+
const end = input.selectionEnd ?? start
|
|
21
|
+
|
|
22
|
+
// Clearing the whole field via a full selection is always allowed.
|
|
23
|
+
if (start !== end && start === 0 && end === value.length) return
|
|
24
|
+
|
|
25
|
+
const symbolEnd = value.match(LEADING_SYMBOL)![0].length
|
|
26
|
+
const symbolStart = value.length - value.match(TRAILING_SYMBOL)![0].length
|
|
27
|
+
|
|
28
|
+
// Expand a collapsed caret to the character the deletion would remove.
|
|
29
|
+
let from = start
|
|
30
|
+
let to = end
|
|
31
|
+
if (start === end) {
|
|
32
|
+
if (e.inputType.endsWith('Forward')) to = start + 1
|
|
33
|
+
else from = start - 1
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const hitsPrefix = from < symbolEnd && to > 0
|
|
37
|
+
const hitsSuffix = from < value.length && to > symbolStart
|
|
38
|
+
if (hitsPrefix || hitsSuffix) e.preventDefault()
|
|
39
|
+
}
|
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.14",
|
|
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": "cdedf91b5298fdb1f48097aebe86b9f87defa5ea"
|
|
46
46
|
}
|