@bjj/nuxt-layer-shadcn-ui 0.15.6 → 0.15.8
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/app/components/ui/AsyncDataTable/index.vue +10 -0
- package/app/components/ui/AsyncDataTable/types.ts +1 -1
- package/app/components/ui/DataTable/index.vue +6 -4
- package/app/components/ui/StaticDataTable/index.vue +9 -0
- package/app/components/ui/StaticDataTable/types.ts +1 -1
- package/app/components/ui/Textarea/en.json +3 -0
- package/app/components/ui/Textarea/index.stories.ts +19 -0
- package/app/components/ui/Textarea/index.vue +46 -4
- package/app/components/ui/Textarea/types.ts +6 -1
- package/i18n/messages/ar.json +3 -0
- package/i18n/messages/de.json +3 -0
- package/i18n/messages/en.json +3 -0
- package/i18n/messages/es.json +3 -0
- package/i18n/messages/fr.json +3 -0
- package/i18n/messages/hi.json +3 -0
- package/i18n/messages/id.json +3 -0
- package/i18n/messages/it.json +3 -0
- package/i18n/messages/ja.json +3 -0
- package/i18n/messages/ko.json +3 -0
- package/i18n/messages/nl.json +3 -0
- package/i18n/messages/pl.json +3 -0
- package/i18n/messages/pt.json +3 -0
- package/i18n/messages/ru.json +3 -0
- package/i18n/messages/th.json +3 -0
- package/i18n/messages/tr.json +3 -0
- package/i18n/messages/vi.json +3 -0
- package/i18n/messages/zh-CN.json +3 -0
- package/i18n/messages/zh-TW.json +3 -0
- package/package.json +2 -2
|
@@ -46,6 +46,14 @@ function onSelectionChange (value: TData | TData[] | null) {
|
|
|
46
46
|
emit('update:selection', Array.isArray(value) ? value : value ? [ value ] : [])
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
+
// A fetch replaces the rows on screen — a different page, a different filter,
|
|
50
|
+
// or fresh objects for the same records — so nothing picked before it can
|
|
51
|
+
// still be pointed at. Cleared alongside the rows, in the same tick, so the
|
|
52
|
+
// checkboxes and the batch-action count never disagree about what's selected.
|
|
53
|
+
function clearSelection () {
|
|
54
|
+
if (selectionValue.value.length) emit('update:selection', [])
|
|
55
|
+
}
|
|
56
|
+
|
|
49
57
|
// -- Internal state --
|
|
50
58
|
|
|
51
59
|
const loading = ref(false)
|
|
@@ -171,6 +179,7 @@ async function fetchData (page?: number, forceRefresh = false) {
|
|
|
171
179
|
|
|
172
180
|
internalData.value = result.items as TData[]
|
|
173
181
|
pagination.value.total = result.total
|
|
182
|
+
clearSelection()
|
|
174
183
|
} catch (error) {
|
|
175
184
|
if (currentVersion !== requestVersion.value) return
|
|
176
185
|
console.error('AsyncDataTable fetchData failed:', error)
|
|
@@ -178,6 +187,7 @@ async function fetchData (page?: number, forceRefresh = false) {
|
|
|
178
187
|
// previous page's rows on screen while the pagination already moved on.
|
|
179
188
|
errored.value = true
|
|
180
189
|
internalData.value = []
|
|
190
|
+
clearSelection()
|
|
181
191
|
} finally {
|
|
182
192
|
if (currentVersion === requestVersion.value) loading.value = false
|
|
183
193
|
}
|
|
@@ -48,6 +48,6 @@ export interface AsyncDataTableProps<T = Record<string, any>> {
|
|
|
48
48
|
clickable?: boolean
|
|
49
49
|
/** Batch action definitions for selected rows */
|
|
50
50
|
batchActions?: AsyncDataTableBatchAction<T>[]
|
|
51
|
-
/** Selected rows (v-model:selection) */
|
|
51
|
+
/** Selected rows (v-model:selection). Cleared whenever a fetch replaces the rows — paging, sorting, filtering, refresh. */
|
|
52
52
|
selection?: T[]
|
|
53
53
|
}
|
|
@@ -59,13 +59,15 @@ const selectedSet = computed(() => {
|
|
|
59
59
|
return new Set(selection.value.map(r => toRaw(r) as TData))
|
|
60
60
|
})
|
|
61
61
|
|
|
62
|
-
// Header "select all" checkbox
|
|
62
|
+
// Header "select all" checkbox. Derived from the rows on screen rather than
|
|
63
|
+
// from the selection size, so a selection still holding rows from elsewhere
|
|
64
|
+
// can't read as "all selected".
|
|
63
65
|
const allChecked = computed({
|
|
64
66
|
get () {
|
|
65
67
|
if (!props.data?.length) return false
|
|
66
|
-
const
|
|
67
|
-
if (
|
|
68
|
-
if (
|
|
68
|
+
const selectedOnPage = props.data.filter(row => selectedSet.value.has(toRaw(row) as TData)).length
|
|
69
|
+
if (selectedOnPage === props.data.length) return true
|
|
70
|
+
if (selectedOnPage > 0) return 'indeterminate' as const
|
|
69
71
|
return false
|
|
70
72
|
},
|
|
71
73
|
set (val: boolean | 'indeterminate') {
|
|
@@ -42,6 +42,12 @@ function onSelectionChange (value: TData | TData[] | null) {
|
|
|
42
42
|
emit('update:selection', Array.isArray(value) ? value : value ? [ value ] : [])
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
+
// Whatever swaps the visible rows also drops what was picked from them, so the
|
|
46
|
+
// checkboxes and the batch-action count never disagree about what's selected.
|
|
47
|
+
function clearSelection () {
|
|
48
|
+
if (selectionValue.value.length) emit('update:selection', [])
|
|
49
|
+
}
|
|
50
|
+
|
|
45
51
|
// -- Internal state --
|
|
46
52
|
|
|
47
53
|
const pagination = ref<StaticDataTablePagination>({
|
|
@@ -91,6 +97,7 @@ watch(
|
|
|
91
97
|
[ () => props.data, () => sortState.value.sortBy, () => sortState.value.sortOrder ],
|
|
92
98
|
() => {
|
|
93
99
|
pagination.value.page = 1
|
|
100
|
+
clearSelection()
|
|
94
101
|
},
|
|
95
102
|
)
|
|
96
103
|
|
|
@@ -129,12 +136,14 @@ const batchMenuItems = computed<DropdownItem[]>(() =>
|
|
|
129
136
|
function onPageChange (newPage: number) {
|
|
130
137
|
if (newPage === pagination.value.page) return
|
|
131
138
|
pagination.value.page = newPage
|
|
139
|
+
clearSelection()
|
|
132
140
|
}
|
|
133
141
|
|
|
134
142
|
function onPageSizeChange (newSize: number) {
|
|
135
143
|
if (newSize === pagination.value.size) return
|
|
136
144
|
pagination.value.size = newSize
|
|
137
145
|
pagination.value.page = 1
|
|
146
|
+
clearSelection()
|
|
138
147
|
}
|
|
139
148
|
|
|
140
149
|
function onSortByUpdate (value: string | null) {
|
|
@@ -32,6 +32,6 @@ export interface StaticDataTableProps<T = Record<string, any>> {
|
|
|
32
32
|
clickable?: boolean
|
|
33
33
|
/** Batch action definitions for selected rows */
|
|
34
34
|
batchActions?: StaticDataTableBatchAction<T>[]
|
|
35
|
-
/** Selected rows (v-model:selection) */
|
|
35
|
+
/** Selected rows (v-model:selection). Cleared whenever the visible rows are swapped — paging, sorting, new data. */
|
|
36
36
|
selection?: T[]
|
|
37
37
|
}
|
|
@@ -11,6 +11,7 @@ const meta = {
|
|
|
11
11
|
autocomplete: { control: 'text' },
|
|
12
12
|
rows: { control: 'number' },
|
|
13
13
|
maxlength: { control: 'number' },
|
|
14
|
+
maxLines: { control: 'number' },
|
|
14
15
|
showCount: { control: 'boolean' },
|
|
15
16
|
readonly: { control: 'boolean' },
|
|
16
17
|
disabled: { control: 'boolean' },
|
|
@@ -22,6 +23,7 @@ const meta = {
|
|
|
22
23
|
autocomplete: '',
|
|
23
24
|
rows: undefined,
|
|
24
25
|
maxlength: undefined,
|
|
26
|
+
maxLines: undefined,
|
|
25
27
|
showCount: false,
|
|
26
28
|
readonly: false,
|
|
27
29
|
disabled: false,
|
|
@@ -72,6 +74,23 @@ export const WithRows: Story = {
|
|
|
72
74
|
}),
|
|
73
75
|
}
|
|
74
76
|
|
|
77
|
+
export const WithCount: Story = {
|
|
78
|
+
parameters: noControls,
|
|
79
|
+
args: {
|
|
80
|
+
showCount: true,
|
|
81
|
+
maxlength: 200,
|
|
82
|
+
},
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export const WithMaxLines: Story = {
|
|
86
|
+
parameters: noControls,
|
|
87
|
+
args: {
|
|
88
|
+
showCount: true,
|
|
89
|
+
maxLines: 3,
|
|
90
|
+
modelValue: 'Line 1\nLine 2',
|
|
91
|
+
},
|
|
92
|
+
}
|
|
93
|
+
|
|
75
94
|
export const Invalid: Story = {
|
|
76
95
|
parameters: noControls,
|
|
77
96
|
args: {
|
|
@@ -9,6 +9,7 @@ const props = withDefaults(defineProps<TextareaProps>(), {
|
|
|
9
9
|
autocomplete: undefined,
|
|
10
10
|
rows: undefined,
|
|
11
11
|
maxlength: undefined,
|
|
12
|
+
maxLines: undefined,
|
|
12
13
|
showCount: false,
|
|
13
14
|
readonly: false,
|
|
14
15
|
disabled: false,
|
|
@@ -21,6 +22,8 @@ const emit = defineEmits<{
|
|
|
21
22
|
'change': [value: string]
|
|
22
23
|
}>()
|
|
23
24
|
|
|
25
|
+
const { t } = useI18n()
|
|
26
|
+
|
|
24
27
|
const isInvalid = useFormItemInvalid(() => props.invalid)
|
|
25
28
|
|
|
26
29
|
// Internal value tracks the actual textarea content, independent of parent's modelValue
|
|
@@ -31,15 +34,53 @@ watch(() => props.modelValue, value => {
|
|
|
31
34
|
internalValue.value = value
|
|
32
35
|
})
|
|
33
36
|
|
|
37
|
+
// A limit below one line would leave no room for content at all
|
|
38
|
+
const lineLimit = computed(() =>
|
|
39
|
+
props.maxLines !== undefined && props.maxLines >= 1 ? props.maxLines : undefined,
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
function countLines (value: string) {
|
|
43
|
+
return value === '' ? 0 : value.split('\n').length
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Keep the leading lines and drop everything past the line limit */
|
|
47
|
+
function clampLines (value: string) {
|
|
48
|
+
const limit = lineLimit.value
|
|
49
|
+
if (limit === undefined || countLines(value) <= limit) return value
|
|
50
|
+
return value.split('\n').slice(0, limit).join('\n')
|
|
51
|
+
}
|
|
52
|
+
|
|
34
53
|
const countText = computed(() => {
|
|
35
|
-
const
|
|
36
|
-
|
|
54
|
+
const value = internalValue.value ?? ''
|
|
55
|
+
const lines = countLines(value)
|
|
56
|
+
const linesPart = lineLimit.value === undefined ? `${lines}` : `${lines} / ${lineLimit.value}`
|
|
57
|
+
const charsPart = props.maxlength === undefined ? `${value.length}` : `${value.length} / ${props.maxlength}`
|
|
58
|
+
return `${t('components.ui.Textarea.lines', { count: linesPart })} · ${charsPart}`
|
|
37
59
|
})
|
|
38
60
|
|
|
39
61
|
function handleInput (event: Event) {
|
|
40
62
|
const target = event.target as HTMLTextAreaElement
|
|
41
|
-
|
|
42
|
-
|
|
63
|
+
const value = clampLines(target.value)
|
|
64
|
+
if (value !== target.value) {
|
|
65
|
+
const caret = Math.min(target.selectionStart, value.length)
|
|
66
|
+
target.value = value
|
|
67
|
+
target.setSelectionRange(caret, caret)
|
|
68
|
+
// Re-dispatch so the inner textarea's own v-model state follows the trimmed value
|
|
69
|
+
target.dispatchEvent(new Event('input', { bubbles: true }))
|
|
70
|
+
return
|
|
71
|
+
}
|
|
72
|
+
internalValue.value = value
|
|
73
|
+
emit('update:modelValue', value)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Reject line breaks beyond the line limit; overflow from pasting is trimmed in handleInput
|
|
77
|
+
function handleKeydown (event: KeyboardEvent) {
|
|
78
|
+
const limit = lineLimit.value
|
|
79
|
+
// While composing, Enter commits the IME candidate instead of inserting a line break
|
|
80
|
+
if (limit === undefined || event.key !== 'Enter' || event.isComposing) return
|
|
81
|
+
const { value, selectionStart, selectionEnd } = event.target as HTMLTextAreaElement
|
|
82
|
+
const next = `${value.slice(0, selectionStart)}\n${value.slice(selectionEnd)}`
|
|
83
|
+
if (countLines(next) > limit) event.preventDefault()
|
|
43
84
|
}
|
|
44
85
|
|
|
45
86
|
function handleChange (event: Event) {
|
|
@@ -69,6 +110,7 @@ const mergedClass = computed(() =>
|
|
|
69
110
|
:autocomplete="autocomplete || 'off'"
|
|
70
111
|
v-bind="$attrs"
|
|
71
112
|
@input="handleInput"
|
|
113
|
+
@keydown="handleKeydown"
|
|
72
114
|
@change="handleChange"
|
|
73
115
|
/>
|
|
74
116
|
<div
|
|
@@ -5,7 +5,12 @@ export interface TextareaProps {
|
|
|
5
5
|
rows?: number
|
|
6
6
|
/** Maximum number of characters allowed */
|
|
7
7
|
maxlength?: number
|
|
8
|
-
/**
|
|
8
|
+
/** Maximum number of lines allowed: extra line breaks are blocked and pasted overflow is trimmed */
|
|
9
|
+
maxLines?: number
|
|
10
|
+
/**
|
|
11
|
+
* Show line and character count below the textarea, rendered as `lines · count`.
|
|
12
|
+
* Each part gains a ` / limit` suffix when `maxLines` / `maxlength` is set.
|
|
13
|
+
*/
|
|
9
14
|
showCount?: boolean
|
|
10
15
|
readonly?: boolean
|
|
11
16
|
disabled?: boolean
|
package/i18n/messages/ar.json
CHANGED
package/i18n/messages/de.json
CHANGED
package/i18n/messages/en.json
CHANGED
package/i18n/messages/es.json
CHANGED
package/i18n/messages/fr.json
CHANGED
package/i18n/messages/hi.json
CHANGED
package/i18n/messages/id.json
CHANGED
package/i18n/messages/it.json
CHANGED
package/i18n/messages/ja.json
CHANGED
package/i18n/messages/ko.json
CHANGED
package/i18n/messages/nl.json
CHANGED
package/i18n/messages/pl.json
CHANGED
package/i18n/messages/pt.json
CHANGED
package/i18n/messages/ru.json
CHANGED
package/i18n/messages/th.json
CHANGED
package/i18n/messages/tr.json
CHANGED
package/i18n/messages/vi.json
CHANGED
package/i18n/messages/zh-CN.json
CHANGED
package/i18n/messages/zh-TW.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bjj/nuxt-layer-shadcn-ui",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.8",
|
|
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": "853df66033a2d70d58028c251dbe047ee6180944"
|
|
46
46
|
}
|