@bjj/nuxt-layer-shadcn-ui 0.12.14 → 0.12.16

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.
@@ -275,6 +275,7 @@ const headerCellClass = 'h-auto bg-border px-4 py-3 text-xs font-normal text-for
275
275
  const headerDividerClass = 'relative after:absolute after:top-1/2 after:right-0 after:h-4 after:w-px after:-translate-y-1/2 after:bg-muted-foreground/25'
276
276
  const stickyLeftClass = 'sticky left-0 z-10'
277
277
  const emptyCellClass = 'h-0.5 w-2.5 bg-muted-foreground/50 inline-block rounded-full align-middle'
278
+ const footerViewportClass = 'sticky left-0 box-border w-[100cqw] px-4 py-2'
278
279
 
279
280
  const selectionColumnClass = '[&:has([role=checkbox])]:pr-4'
280
281
  const selectionColumnStyle = { width: '1%' }
@@ -291,7 +292,10 @@ defineExpose({
291
292
  <template>
292
293
  <div
293
294
  :class="cn(
294
- 'rounded-lg bg-border px-1 text-foreground relative overflow-hidden',
295
+ `
296
+ rounded-lg bg-border px-1 text-foreground @container relative
297
+ overflow-hidden
298
+ `,
295
299
  !$slots.footer && 'pb-1',
296
300
  height && 'has-sticky-bounds',
297
301
  )"
@@ -505,9 +509,11 @@ defineExpose({
505
509
  <TableRow>
506
510
  <TableCell
507
511
  :colspan="totalColumns"
508
- class="bg-border"
512
+ class="bg-border p-0!"
509
513
  >
510
- <slot name="footer" />
514
+ <div :class="footerViewportClass">
515
+ <slot name="footer" />
516
+ </div>
511
517
  </TableCell>
512
518
  </TableRow>
513
519
  </TableFooter>
@@ -1,9 +1,10 @@
1
1
  import type { Meta, StoryObj } from '@storybook/vue3'
2
- import type { TagColor, TagVariant } from './types'
2
+ import type { TagColor, TagSize, TagVariant } from './types'
3
3
  import Tag from './index.vue'
4
4
 
5
5
  const colors: TagColor[] = [ 'default', 'primary', 'success', 'info', 'help', 'warn', 'danger' ]
6
6
  const variants: TagVariant[] = [ 'solid', 'soft', 'bordered', 'flat' ]
7
+ const sizes: TagSize[] = [ 'sm', 'md' ]
7
8
 
8
9
  const meta = {
9
10
  title: 'UI/Tag',
@@ -11,10 +12,12 @@ const meta = {
11
12
  argTypes: {
12
13
  color: { control: 'select', options: colors },
13
14
  variant: { control: 'select', options: variants },
15
+ size: { control: 'select', options: sizes },
14
16
  },
15
17
  args: {
16
18
  color: 'default',
17
19
  variant: 'soft',
20
+ size: 'md',
18
21
  },
19
22
  render: args => ({
20
23
  components: { Tag },
@@ -82,6 +85,32 @@ export const Variants: Story = {
82
85
  }),
83
86
  }
84
87
 
88
+ export const Sizes: Story = {
89
+ parameters: {
90
+ ...noControls,
91
+ docs: {
92
+ source: {
93
+ code: `
94
+ <template>
95
+ <div class="flex flex-wrap items-center gap-3">
96
+ <Tag v-for="s in sizes" :key="s" :size="s">{{ s }}</Tag>
97
+ </div>
98
+ </template>
99
+ `.trim(),
100
+ },
101
+ },
102
+ },
103
+ render: () => ({
104
+ components: { Tag },
105
+ setup: () => ({ sizes }),
106
+ template: `
107
+ <div class="flex flex-wrap items-center gap-3">
108
+ <Tag v-for="s in sizes" :key="s" :size="s">{{ s }}</Tag>
109
+ </div>
110
+ `,
111
+ }),
112
+ }
113
+
85
114
  export const VariantColorMatrix: Story = {
86
115
  parameters: {
87
116
  ...noControls,
@@ -3,9 +3,13 @@ import { cva } from 'class-variance-authority'
3
3
  import type { TagProps } from './types'
4
4
 
5
5
  const tagVariants = cva(
6
- 'gap-1 rounded-md px-2 py-1 text-xs font-medium inline-flex items-center',
6
+ 'font-medium inline-flex items-center',
7
7
  {
8
8
  variants: {
9
+ size: {
10
+ sm: 'gap-0.5 rounded-sm px-1.5 py-0.5 text-[10px]',
11
+ md: 'gap-1 rounded-md px-2 py-1 text-xs',
12
+ },
9
13
  variant: {
10
14
  solid: 'border',
11
15
  soft: 'border',
@@ -97,6 +101,7 @@ const tagVariants = cva(
97
101
  defaultVariants: {
98
102
  variant: 'soft',
99
103
  color: 'default',
104
+ size: 'md',
100
105
  },
101
106
  },
102
107
  )
@@ -104,6 +109,7 @@ const tagVariants = cva(
104
109
  const props = withDefaults(defineProps<TagProps>(), {
105
110
  color: 'default',
106
111
  variant: 'soft',
112
+ size: 'md',
107
113
  class: undefined,
108
114
  })
109
115
 
@@ -112,7 +118,7 @@ defineSlots<{
112
118
  }>()
113
119
 
114
120
  const mergedClass = computed(() =>
115
- cn(tagVariants({ color: props.color, variant: props.variant }), props.class),
121
+ cn(tagVariants({ color: props.color, variant: props.variant, size: props.size }), props.class),
116
122
  )
117
123
  </script>
118
124
 
@@ -1,8 +1,10 @@
1
1
  export type TagColor = 'default' | 'primary' | 'success' | 'info' | 'help' | 'warn' | 'danger'
2
2
  export type TagVariant = 'solid' | 'soft' | 'bordered' | 'flat'
3
+ export type TagSize = 'sm' | 'md'
3
4
 
4
5
  export interface TagProps {
5
6
  color?: TagColor
6
7
  variant?: TagVariant
8
+ size?: TagSize
7
9
  class?: ClassValue
8
10
  }
@@ -21,6 +21,7 @@
21
21
  },
22
22
  "preview": "Preview",
23
23
  "remove": "Remove",
24
+ "sort": "Drag to reorder",
24
25
  "upload": "Upload",
25
26
  "uploadDirectory": "Upload Directory",
26
27
  "uploading": "Uploading"
@@ -28,6 +28,7 @@ const meta = {
28
28
  hideTriggerOnMax: { control: 'boolean' },
29
29
  hideHint: { control: 'boolean' },
30
30
  directory: { control: 'boolean' },
31
+ sortable: { control: 'boolean' },
31
32
  text: { control: 'text' },
32
33
  icon: { control: 'text' },
33
34
  },
@@ -43,6 +44,7 @@ const meta = {
43
44
  hideTriggerOnMax: false,
44
45
  hideHint: false,
45
46
  directory: false,
47
+ sortable: false,
46
48
  text: '',
47
49
  icon: '',
48
50
  },
@@ -215,6 +217,35 @@ export const Directory: Story = {
215
217
  }),
216
218
  }
217
219
 
220
+ export const Sortable: Story = {
221
+ parameters: {
222
+ ...noControls,
223
+ docs: {
224
+ source: {
225
+ code: `
226
+ <template>
227
+ <Upload v-model:fileList="fileList" variant="box" sortable multiple accept="image/*" />
228
+ </template>
229
+ `.trim(),
230
+ },
231
+ },
232
+ },
233
+ render: () => ({
234
+ components: { Upload },
235
+ setup () {
236
+ const boxList = ref<UploadFile[]>([ ...sampleImages ])
237
+ const rowList = ref<UploadFile[]>([ ...sampleImages ])
238
+ return { boxList, rowList }
239
+ },
240
+ template: `
241
+ <div class="max-w-2xl space-y-6">
242
+ <Upload v-model:fileList="boxList" variant="box" sortable multiple accept="image/*" />
243
+ <Upload v-model:fileList="rowList" variant="drag" sortable multiple accept="image/*" />
244
+ </div>
245
+ `,
246
+ }),
247
+ }
248
+
218
249
  // --- States ---
219
250
 
220
251
  export const Disabled: Story = {
@@ -18,6 +18,7 @@ const props = withDefaults(defineProps<UploadProps>(), {
18
18
  hideTriggerOnMax: false,
19
19
  hideHint: false,
20
20
  directory: false,
21
+ sortable: false,
21
22
  class: undefined,
22
23
  })
23
24
 
@@ -42,6 +43,12 @@ const internalFileList = ref<UploadFile[]>([])
42
43
  const previewVisible = ref(false)
43
44
  const previewFileItem = ref<UploadFile | null>(null)
44
45
 
46
+ const draggingUid = ref<string | number | null>(null)
47
+ // Items are draggable only while the grip handle is pressed, so a drag can
48
+ // only begin from the handle and not from the whole row/thumb.
49
+ const dragHandleArmed = ref(false)
50
+ const didReorder = ref(false)
51
+
45
52
  const objectUrls = new Set<string>()
46
53
  function trackObjectUrl (url: string | undefined) {
47
54
  if (url) objectUrls.add(url)
@@ -76,6 +83,13 @@ const canPickMore = computed(() =>
76
83
 
77
84
  const canRemove = computed(() => !props.disabled && !props.readonly)
78
85
 
86
+ const canSort = computed(() => props.sortable && !props.disabled && !props.readonly)
87
+
88
+ // Uploading entries are transient and stay pinned; only committed files sort.
89
+ function isSortable (file: UploadFile) {
90
+ return canSort.value && file.status !== 'uploading'
91
+ }
92
+
79
93
  const showTrigger = computed(() =>
80
94
  !props.readonly && !(props.hideTriggerOnMax && reachedMax.value),
81
95
  )
@@ -212,12 +226,20 @@ const rowItemBase = `
212
226
 
213
227
  function thumbClass (file: UploadFile) {
214
228
  const isError = file.status === 'error' || isInvalid.value
215
- return cn(thumbBase, isError ? 'border-danger' : 'border-border')
229
+ return cn(
230
+ thumbBase,
231
+ isError ? 'border-danger' : 'border-border',
232
+ draggingUid.value === file.uid && 'opacity-50',
233
+ )
216
234
  }
217
235
 
218
236
  function rowItemClass (file: UploadFile) {
219
237
  const isError = file.status === 'error' || isInvalid.value
220
- return cn(rowItemBase, isError && 'text-danger')
238
+ return cn(
239
+ rowItemBase,
240
+ isError && 'text-danger',
241
+ draggingUid.value === file.uid && 'opacity-50',
242
+ )
221
243
  }
222
244
 
223
245
  function isImageFile (file: UploadFile) {
@@ -334,6 +356,12 @@ async function processFiles (files: File[]) {
334
356
  }
335
357
  }
336
358
 
359
+ function setFileList (next: UploadFile[], emitChange = true) {
360
+ if (!isControlled.value) internalFileList.value = next
361
+ emit('update:fileList', next)
362
+ if (emitChange) emit('change', next)
363
+ }
364
+
337
365
  function finishUpload (entries: UploadFile[], ok: boolean) {
338
366
  const entryUids = new Set(entries.map(e => e.uid))
339
367
  uploadingFiles.value = uploadingFiles.value.filter(e => !entryUids.has(e.uid))
@@ -344,10 +372,7 @@ function finishUpload (entries: UploadFile[], ok: boolean) {
344
372
  }
345
373
 
346
374
  const done = entries.map(e => ({ ...e, status: 'done' as const }))
347
- const next = [ ...effectiveFileList.value, ...done ]
348
- if (!isControlled.value) internalFileList.value = next
349
- emit('update:fileList', next)
350
- emit('change', next)
375
+ setFileList([ ...effectiveFileList.value, ...done ])
351
376
  }
352
377
 
353
378
  function onInputChange (e: Event) {
@@ -366,14 +391,48 @@ function removeFile (file: UploadFile) {
366
391
  if (inUploading) {
367
392
  uploadingFiles.value = uploadingFiles.value.filter(f => f.uid !== file.uid)
368
393
  } else {
369
- const next = effectiveFileList.value.filter(f => f.uid !== file.uid)
370
- if (!isControlled.value) internalFileList.value = next
371
- emit('update:fileList', next)
372
- emit('change', next)
394
+ setFileList(effectiveFileList.value.filter(f => f.uid !== file.uid))
373
395
  }
374
396
  emit('remove', file)
375
397
  }
376
398
 
399
+ function onItemDragStart (e: DragEvent, file: UploadFile) {
400
+ if (!isSortable(file) || !dragHandleArmed.value) {
401
+ e.preventDefault()
402
+ return
403
+ }
404
+ draggingUid.value = file.uid ?? null
405
+ didReorder.value = false
406
+ // Firefox only initiates a drag once data is set.
407
+ if (e.dataTransfer) {
408
+ e.dataTransfer.effectAllowed = 'move'
409
+ e.dataTransfer.setData('text/plain', String(file.uid ?? ''))
410
+ }
411
+ }
412
+
413
+ // Reorder live while hovering, moving the dragged file into the hovered file's
414
+ // slot. Tracking by uid keeps it identified as positions shift mid-drag.
415
+ function onItemDragOver (e: DragEvent, file: UploadFile) {
416
+ const from = draggingUid.value
417
+ if (from == null || !isSortable(file)) return
418
+ e.preventDefault()
419
+ if (from === file.uid) return
420
+ const next = [ ...effectiveFileList.value ]
421
+ const fromIdx = next.findIndex(f => f.uid === from)
422
+ const toIdx = next.findIndex(f => f.uid === file.uid)
423
+ if (fromIdx === -1 || toIdx === -1) return
424
+ next.splice(toIdx, 0, ...next.splice(fromIdx, 1))
425
+ didReorder.value = true
426
+ setFileList(next, false)
427
+ }
428
+
429
+ function onItemDragEnd () {
430
+ if (didReorder.value) emit('change', effectiveFileList.value)
431
+ draggingUid.value = null
432
+ dragHandleArmed.value = false
433
+ didReorder.value = false
434
+ }
435
+
377
436
  function previewFile (file: UploadFile) {
378
437
  emit('preview', file)
379
438
  if (isImageFile(file) && file.url) {
@@ -537,7 +596,26 @@ async function onDrop (e: DragEvent) {
537
596
  v-for="file in displayList"
538
597
  :key="file.uid"
539
598
  :class="rowItemClass(file)"
599
+ :draggable="isSortable(file) && dragHandleArmed"
600
+ @dragstart="onItemDragStart($event, file)"
601
+ @dragover="onItemDragOver($event, file)"
602
+ @dragend="onItemDragEnd"
540
603
  >
604
+ <span
605
+ v-if="isSortable(file)"
606
+ class="
607
+ text-muted-foreground shrink-0 cursor-grab
608
+ active:cursor-grabbing
609
+ "
610
+ :aria-label="T('sort')"
611
+ @mousedown="dragHandleArmed = true"
612
+ @mouseup="dragHandleArmed = false"
613
+ >
614
+ <Icon
615
+ name="grip-vertical"
616
+ class="size-4"
617
+ />
618
+ </span>
541
619
  <Icon
542
620
  name="paperclip"
543
621
  class="size-4 shrink-0"
@@ -584,12 +662,34 @@ async function onDrop (e: DragEvent) {
584
662
  v-for="file in displayList"
585
663
  :key="file.uid"
586
664
  :class="thumbClass(file)"
665
+ :draggable="isSortable(file) && dragHandleArmed"
666
+ @dragstart="onItemDragStart($event, file)"
667
+ @dragover="onItemDragOver($event, file)"
668
+ @dragend="onItemDragEnd"
587
669
  >
670
+ <div
671
+ v-if="isSortable(file)"
672
+ class="
673
+ left-1 top-1 rounded-sm bg-black/50 p-0.5 text-white/90 absolute
674
+ z-10 cursor-grab opacity-0 transition
675
+ group-hover/thumb:opacity-100
676
+ active:cursor-grabbing
677
+ "
678
+ :aria-label="T('sort')"
679
+ @mousedown="dragHandleArmed = true"
680
+ @mouseup="dragHandleArmed = false"
681
+ >
682
+ <Icon
683
+ name="grip-vertical"
684
+ class="size-3.5"
685
+ />
686
+ </div>
588
687
  <img
589
688
  v-if="isImageFile(file) && file.url"
590
689
  :src="file.url"
591
690
  :alt="file.name"
592
691
  class="size-full object-cover"
692
+ :draggable="false"
593
693
  @error="onImageError(file)"
594
694
  >
595
695
  <div
@@ -50,6 +50,8 @@ export interface UploadProps {
50
50
  hideHint?: boolean
51
51
  /** Allow selecting a directory and upload its contents */
52
52
  directory?: boolean
53
+ /** Allow reordering the file list by drag and drop */
54
+ sortable?: boolean
53
55
  /** Class of the root element */
54
56
  class?: ClassValue
55
57
  }
@@ -104,6 +104,7 @@
104
104
  },
105
105
  "preview": "معاينة",
106
106
  "remove": "إزالة",
107
+ "sort": "اسحب لإعادة الترتيب",
107
108
  "upload": "تحميل",
108
109
  "uploadDirectory": "تحميل الدليل",
109
110
  "uploading": "جاري التحميل"
@@ -104,6 +104,7 @@
104
104
  },
105
105
  "preview": "Vorschau",
106
106
  "remove": "Entfernen",
107
+ "sort": "Zum Umordnen ziehen",
107
108
  "upload": "Hochladen",
108
109
  "uploadDirectory": "Verzeichnis hochladen",
109
110
  "uploading": "Wird hochgeladen"
@@ -104,6 +104,7 @@
104
104
  },
105
105
  "preview": "Preview",
106
106
  "remove": "Remove",
107
+ "sort": "Drag to reorder",
107
108
  "upload": "Upload",
108
109
  "uploadDirectory": "Upload Directory",
109
110
  "uploading": "Uploading"
@@ -104,6 +104,7 @@
104
104
  },
105
105
  "preview": "Vista previa",
106
106
  "remove": "Eliminar",
107
+ "sort": "Arrastra para reordenar",
107
108
  "upload": "Subir",
108
109
  "uploadDirectory": "Subir carpeta",
109
110
  "uploading": "Subiendo"
@@ -104,6 +104,7 @@
104
104
  },
105
105
  "preview": "Aperçu",
106
106
  "remove": "Supprimer",
107
+ "sort": "Glisser pour réorganiser",
107
108
  "upload": "Télécharger",
108
109
  "uploadDirectory": "Télécharger le répertoire",
109
110
  "uploading": "Téléchargement en cours"
@@ -104,6 +104,7 @@
104
104
  },
105
105
  "preview": "पूर्वावलोकन",
106
106
  "remove": "हटाएं",
107
+ "sort": "पुनः व्यवस्थित करने के लिए खींचें",
107
108
  "upload": "अपलोड",
108
109
  "uploadDirectory": "निर्देशिका अपलोड करें",
109
110
  "uploading": "अपलोड जारी है"
@@ -104,6 +104,7 @@
104
104
  },
105
105
  "preview": "Pratinjau",
106
106
  "remove": "Hapus",
107
+ "sort": "Seret untuk mengurutkan kembali",
107
108
  "upload": "Unggah",
108
109
  "uploadDirectory": "Direktori Unggah",
109
110
  "uploading": "Mengunggah"
@@ -104,6 +104,7 @@
104
104
  },
105
105
  "preview": "Anteprima",
106
106
  "remove": "Rimuovi",
107
+ "sort": "Trascinare per riordinare",
107
108
  "upload": "Carica",
108
109
  "uploadDirectory": "Carica Cartella",
109
110
  "uploading": "Caricamento in corso"
@@ -104,6 +104,7 @@
104
104
  },
105
105
  "preview": "プレビュー",
106
106
  "remove": "削除",
107
+ "sort": "ドラッグして順序を変更",
107
108
  "upload": "アップロード",
108
109
  "uploadDirectory": "ディレクトリをアップロード",
109
110
  "uploading": "アップロード中"
@@ -104,6 +104,7 @@
104
104
  },
105
105
  "preview": "미리보기",
106
106
  "remove": "제거",
107
+ "sort": "드래그하여 다시 정렬하세요",
107
108
  "upload": "업로드",
108
109
  "uploadDirectory": "디렉토리 업로드",
109
110
  "uploading": "업로드 중"
@@ -104,6 +104,7 @@
104
104
  },
105
105
  "preview": "Voorbeeld",
106
106
  "remove": "Verwijderen",
107
+ "sort": "Slepen om opnieuw in te delen",
107
108
  "upload": "Uploaden",
108
109
  "uploadDirectory": "Map uploaden",
109
110
  "uploading": "Uploaden in uitvoering"
@@ -104,6 +104,7 @@
104
104
  },
105
105
  "preview": "Podgląd",
106
106
  "remove": "Usuń",
107
+ "sort": "Przeciągnij, aby zmienić kolejność",
107
108
  "upload": "Przesłaj",
108
109
  "uploadDirectory": "Przesłaj katalog",
109
110
  "uploading": "Przesyłanie"
@@ -104,6 +104,7 @@
104
104
  },
105
105
  "preview": "Visualizar",
106
106
  "remove": "Remover",
107
+ "sort": "Arrastar para reordenar",
107
108
  "upload": "Upload",
108
109
  "uploadDirectory": "Diretório de Upload",
109
110
  "uploading": "Enviando"
@@ -104,6 +104,7 @@
104
104
  },
105
105
  "preview": "Предпросмотр",
106
106
  "remove": "Удалить",
107
+ "sort": "Перетащите для переупорядочения",
107
108
  "upload": "Загрузить",
108
109
  "uploadDirectory": "Загрузить папку",
109
110
  "uploading": "Загрузка"
@@ -104,6 +104,7 @@
104
104
  },
105
105
  "preview": "ดูตัวอย่าง",
106
106
  "remove": "ลบ",
107
+ "sort": "ลากเพื่อจัดเรียงใหม่",
107
108
  "upload": "อัปโหลด",
108
109
  "uploadDirectory": "อัปโหลดโฟลเดอร์",
109
110
  "uploading": "กำลังอัปโหลด"
@@ -104,6 +104,7 @@
104
104
  },
105
105
  "preview": "Önizleme",
106
106
  "remove": "Kaldır",
107
+ "sort": "Sıramak için sürükleyin",
107
108
  "upload": "Yükle",
108
109
  "uploadDirectory": "Dizin Yükle",
109
110
  "uploading": "Yükleniyor"
@@ -104,6 +104,7 @@
104
104
  },
105
105
  "preview": "Xem trước",
106
106
  "remove": "Xóa",
107
+ "sort": "Kéo để sắp xếp lại",
107
108
  "upload": "Tải lên",
108
109
  "uploadDirectory": "Thư mục tải lên",
109
110
  "uploading": "Đang tải lên"
@@ -104,6 +104,7 @@
104
104
  },
105
105
  "preview": "预览",
106
106
  "remove": "移除",
107
+ "sort": "拖拽排序",
107
108
  "upload": "上传",
108
109
  "uploadDirectory": "上传目录",
109
110
  "uploading": "上传中"
@@ -104,6 +104,7 @@
104
104
  },
105
105
  "preview": "預覽",
106
106
  "remove": "移除",
107
+ "sort": "拖曳以重新排序",
107
108
  "upload": "上傳",
108
109
  "uploadDirectory": "上傳資料夾",
109
110
  "uploading": "上傳中"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bjj/nuxt-layer-shadcn-ui",
3
- "version": "0.12.14",
3
+ "version": "0.12.16",
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": "cdedf91b5298fdb1f48097aebe86b9f87defa5ea"
45
+ "gitHead": "e4a930eee97e686f984f1970ec4cb4e6baec363e"
46
46
  }