@soft-stech/bootsman-ui-shadcn 2.0.20 → 2.0.21

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,5 +1,5 @@
1
1
  <script setup lang="ts">
2
- import { type HTMLAttributes, computed } from 'vue'
2
+ import { type HTMLAttributes, computed, ref } from 'vue'
3
3
  import {
4
4
  ScrollAreaCorner,
5
5
  ScrollAreaRoot,
@@ -16,10 +16,17 @@ const delegatedProps = computed(() => {
16
16
 
17
17
  return delegated
18
18
  })
19
+
20
+ const tableWrapperRef = ref<InstanceType<typeof ScrollAreaRoot> | null>(null)
21
+ defineExpose({ tableWrapperRef })
19
22
  </script>
20
23
 
21
24
  <template>
22
- <ScrollAreaRoot v-bind="delegatedProps" :class="cn('relative overflow-hidden', props.class)">
25
+ <ScrollAreaRoot
26
+ ref="tableWrapperRef"
27
+ v-bind="delegatedProps"
28
+ :class="cn('relative overflow-hidden', props.class)"
29
+ >
23
30
  <ScrollAreaViewport class="h-full w-full rounded-[inherit]">
24
31
  <slot />
25
32
  </ScrollAreaViewport>
@@ -54,11 +54,13 @@ import { isEqual } from 'lodash-es'
54
54
  import { cn, valueUpdater } from '@/lib/utils'
55
55
  import { useResizeColumns } from '@/lib/useResizeColumns'
56
56
  import { useSessionStorage } from '@vueuse/core'
57
+ import { useGlobalCursor } from '@/lib/useGlobalCursor'
57
58
 
58
59
  const NO_GROUP_KEY = '#UNDEFINED#'
59
60
  const defaultColumnContextMenuTranslations = {
60
61
  hideColumn: 'Hide column',
61
- resetSize: 'Reset size',
62
+ resetThisSize: 'Reset size for this column',
63
+ resetSize: 'Reset size for all columns',
62
64
  sortAsc: 'Sort ascending',
63
65
  sortDesc: 'Sort descending'
64
66
  }
@@ -90,6 +92,7 @@ const props = withDefaults(
90
92
  }
91
93
  headerContextMenuTranslations?: {
92
94
  hideColumn?: string
95
+ resetThisSize?: string
93
96
  resetSize?: string
94
97
  sortAsc?: string
95
98
  sortDesc?: string
@@ -152,7 +155,6 @@ const table = useVueTable({
152
155
  await nextTick()
153
156
 
154
157
  resetCells()
155
- setInitialColumnWidths()
156
158
  },
157
159
  onColumnOrderChange: (updaterOrValue) => {
158
160
  valueUpdater(updaterOrValue, columnOrder)
@@ -257,18 +259,20 @@ watch(columnsListIds, () => {
257
259
  })
258
260
 
259
261
  const tableHeaderRef = ref<InstanceType<typeof BuiTableHeader> | null>(null)
262
+ const tableElementRef = ref<InstanceType<typeof BuiTable> | null>(null)
260
263
  const { height } = useElementSize(tableHeaderRef)
261
264
 
262
265
  const {
263
266
  tableHeaderElement,
267
+ tableElement,
264
268
  calculatedColumnSizing,
265
269
  isResizing,
266
270
  resizingCellId,
271
+ resetCell,
267
272
  resetCells,
268
273
  handleResizeControlMouseDown,
269
274
  handleResizeControlMouseUp,
270
275
  setInitialColumnWidths,
271
- setProvidedCellWidths,
272
276
  isMouseDownOnHandler,
273
277
  isMouseUpOnHandler
274
278
  } = useResizeColumns()
@@ -278,10 +282,10 @@ onBeforeMount(() => {
278
282
  })
279
283
 
280
284
  onMounted(() => {
281
- if (tableHeaderRef.value) {
285
+ if (tableElementRef.value && tableHeaderRef.value) {
286
+ tableElement.value = tableElementRef.value
282
287
  tableHeaderElement.value = tableHeaderRef.value
283
288
 
284
- setProvidedCellWidths(columnSizing.value)
285
289
  setInitialColumnWidths()
286
290
  }
287
291
 
@@ -304,7 +308,7 @@ const getHeaderCellSortingButton = (header: Header<TData, unknown>) => {
304
308
  return currentHeaderCell?.querySelector('button[sorting-enabled]')
305
309
  }
306
310
 
307
- type HeaderCellAction = 'hideColumn' | 'resetSize' | 'sortAsc' | 'sortDesc'
311
+ type HeaderCellAction = 'hideColumn' | 'resetThisSize' | 'resetSize' | 'sortAsc' | 'sortDesc'
308
312
  const availableHeaderCellActions = (header: Header<TData, unknown>) => {
309
313
  const out: HeaderCellAction[] = []
310
314
 
@@ -319,6 +323,7 @@ const availableHeaderCellActions = (header: Header<TData, unknown>) => {
319
323
  }
320
324
 
321
325
  if (props.enableColumnResizing) {
326
+ out.push('resetThisSize')
322
327
  out.push('resetSize')
323
328
  }
324
329
 
@@ -329,6 +334,9 @@ const onHeaderCellAction = (header: Header<TData, unknown>, action: HeaderCellAc
329
334
  case 'hideColumn':
330
335
  header.column.toggleVisibility()
331
336
  break
337
+ case 'resetThisSize':
338
+ resetCell(header.id)
339
+ break
332
340
  case 'resetSize':
333
341
  resetCells()
334
342
  break
@@ -399,13 +407,23 @@ const handleHeaderCellMouseDown = (e: Event) => {
399
407
  isMouseDownOnHandler.value =
400
408
  targetHTMLElement.className.includes && targetHTMLElement.className.includes('resize-handler')
401
409
  }
410
+
411
+ const { setCursor, resetCursor } = useGlobalCursor()
412
+
413
+ watch(isResizing, () => {
414
+ if (isResizing.value) {
415
+ setCursor('col-resize')
416
+ } else {
417
+ resetCursor()
418
+ }
419
+ })
402
420
  </script>
403
421
 
404
422
  <template>
405
423
  <div v-if="$slots.caption" class="w-full py-3">
406
424
  <slot name="caption" :table="table" />
407
425
  </div>
408
- <BuiTable>
426
+ <BuiTable ref="tableElementRef">
409
427
  <template v-if="enableColumnListControl" #columnVisibility>
410
428
  <BuiPopover v-model:open="open">
411
429
  <BuiPopoverTrigger as-child>
@@ -449,6 +467,17 @@ const handleHeaderCellMouseDown = (e: Event) => {
449
467
  >
450
468
  {{ columnResetVisibility }}
451
469
  </BuiCommandItem>
470
+ <BuiCommandItem
471
+ value="reset_columns_size"
472
+ key="reset_columns_size"
473
+ class="text-muted-foreground px-2 py-1.5 font-medium"
474
+ @select="resetCells"
475
+ >
476
+ {{
477
+ headerContextMenuTranslations?.['resetSize'] ??
478
+ defaultColumnContextMenuTranslations['resetSize']
479
+ }}
480
+ </BuiCommandItem>
452
481
  </BuiScrollArea>
453
482
  </BuiCommandList>
454
483
  </BuiCommand>
@@ -499,9 +528,8 @@ const handleHeaderCellMouseDown = (e: Event) => {
499
528
  :key="idx"
500
529
  >
501
530
  {{
502
- headerContextMenuTranslations && headerContextMenuTranslations[action]
503
- ? headerContextMenuTranslations[action]
504
- : defaultColumnContextMenuTranslations[action]
531
+ headerContextMenuTranslations?.[action] ??
532
+ defaultColumnContextMenuTranslations[action]
505
533
  }}
506
534
  </BuiContextMenuItem>
507
535
  </BuiContextMenuContent>
@@ -518,7 +546,7 @@ const handleHeaderCellMouseDown = (e: Event) => {
518
546
  v-for="(value, key) in groupedRows"
519
547
  :key="key"
520
548
  v-model:open="groupsOpenStateRef[key]"
521
- @update:open="(value) => handleGroupToggle(value, key)"
549
+ @update:open="(value: boolean) => handleGroupToggle(value, key)"
522
550
  >
523
551
  <BuiTableRow class="bg-foreground/4 border-b-0">
524
552
  <BuiTableCell :colspan="columns.length" class="pb-0!">
@@ -1,15 +1,23 @@
1
1
  <script setup lang="ts">
2
2
  import { BuiScrollArea, BuiScrollBar } from '@/components/scroll-area'
3
3
  import { cn } from '@/lib/utils'
4
+ import { ref } from 'vue'
4
5
 
5
6
  const props = defineProps<{ class?: string }>()
7
+ const tableRef = ref<HTMLTableElement | undefined>(undefined)
8
+ const scrollAreaElementRef = ref<InstanceType<typeof BuiScrollArea> | null>(null)
9
+
10
+ defineExpose({ tableRef, scrollAreaElementRef })
6
11
  </script>
7
12
 
8
13
  <template>
9
- <BuiScrollArea class="border-border/16 w-full grow overflow-auto rounded-sm border">
14
+ <BuiScrollArea
15
+ ref="scrollAreaElementRef"
16
+ class="border-border/16 w-full grow overflow-auto rounded-sm border"
17
+ >
10
18
  <slot name="columnVisibility" />
11
- <div class="flex min-h-[90px] grow flex-col">
12
- <table :class="cn('h-full w-full caption-top text-sm', props.class)">
19
+ <div class="flex min-h-[90px] w-full grow flex-col">
20
+ <table ref="tableRef" :class="cn('h-full caption-top text-sm', props.class)">
13
21
  <slot />
14
22
  </table>
15
23
  </div>
@@ -0,0 +1,17 @@
1
+ import { onUnmounted } from 'vue'
2
+
3
+ export function useGlobalCursor() {
4
+ function setCursor(cursor: string) {
5
+ document.body.style.cursor = cursor
6
+ }
7
+
8
+ function resetCursor() {
9
+ document.body.style.cursor = ''
10
+ }
11
+
12
+ onUnmounted(() => {
13
+ resetCursor()
14
+ })
15
+
16
+ return { setCursor, resetCursor }
17
+ }
@@ -1,20 +1,31 @@
1
- import { ref } from 'vue'
1
+ import { computed, ref } from 'vue'
2
2
  import BuiTableHeader from '@/components/table/BuiTableHeader.vue'
3
+ import BuiTable from '@/components/table/BuiTable.vue'
3
4
  import { useEventListener } from '@vueuse/core'
4
5
 
6
+ const MIN_CELL_WIDTH = 90
7
+ const LAST_CELL_EXTRA_SPACE = 56
8
+ const ACTIONS_CELL_MIN_WIDTH = 10
9
+
5
10
  export function useResizeColumns() {
6
11
  type CELL = {
7
- [key: string]: { cell: HTMLTableCellElement; initialWidth: number; minWidth: number }
12
+ [key: string]: {
13
+ cell: HTMLTableCellElement
14
+ initialWidth: number
15
+ minWidth: number
16
+ baseWidth: number
17
+ isLast: boolean
18
+ }
8
19
  }
9
20
  const isResizing = ref<boolean>(false)
10
21
  const resizingCellId = ref<string>('')
11
22
  const neighborCellId = ref<string>('')
12
23
  const cells = ref<CELL | undefined>(undefined)
13
- const MIN_CELL_WIDTH = 90
14
- const LAST_CELL_EXTRA_SPACE = 56
15
- const ACTIONS_CELL_MIN_WIDTH = 10
16
24
  const calculatedColumnSizing = ref<Record<string, number> | undefined>(undefined)
17
25
  const tableHeaderElement = ref<InstanceType<typeof BuiTableHeader> | null>(null)
26
+ const tableElement = ref<InstanceType<typeof BuiTable> | null>(null)
27
+ const initialTableWidth = ref<number>(0)
28
+ const minTableWidth = ref<number>(0)
18
29
  const unregisterMouseMove = ref<(() => void) | undefined>(undefined)
19
30
 
20
31
  const setProvidedCellWidths = (columnSizing: Record<string, number> | undefined) => {
@@ -25,31 +36,57 @@ export function useResizeColumns() {
25
36
  headerCells.forEach((cell) => {
26
37
  const cellId = getCellId(cell)
27
38
 
28
- if (columnSizing && columnSizing[cellId]) {
29
- cell.style.width = columnSizing[cellId] + 'px'
30
- }
39
+ cell.style.width = columnSizing && columnSizing[cellId] ? columnSizing[cellId] + 'px' : ''
31
40
  })
32
41
  }
33
42
  }
34
43
 
35
44
  const getCells = () => {
36
- if (tableHeaderElement.value && tableHeaderElement.value.headRef) {
45
+ if (
46
+ tableHeaderElement.value &&
47
+ tableHeaderElement.value.headRef &&
48
+ tableElement.value &&
49
+ tableElement.value?.tableRef
50
+ ) {
37
51
  const headerCells = [...tableHeaderElement.value.headRef.querySelectorAll('th')]
38
- const headerCellsWidths: CELL = headerCells.reduce((acc, cell) => {
52
+ const tableInitialWidth = getTableWidth()
53
+
54
+ tableElement.value.tableRef.style.width = 'min-content'
55
+
56
+ const headerCellsWidths: CELL = headerCells.reduce((acc, cell, index, array) => {
39
57
  const cellId = getCellId(cell)
58
+
40
59
  return {
41
60
  ...acc,
42
61
  [cellId]: {
43
62
  cell: cell,
44
- initialWidth: cell.offsetWidth,
63
+ isLast: index === array.length - 1,
64
+ initialWidth: Math.floor(cell.offsetWidth),
65
+ baseWidth: Math.floor(cell.offsetWidth),
45
66
  minWidth:
46
67
  cellId === 'actions'
47
68
  ? ACTIONS_CELL_MIN_WIDTH
48
- : Math.min(cell.offsetWidth, MIN_CELL_WIDTH)
69
+ : cell.offsetWidth < MIN_CELL_WIDTH
70
+ ? MIN_CELL_WIDTH
71
+ : cell.offsetWidth
49
72
  }
50
73
  }
51
74
  }, {})
52
75
 
76
+ tableElement.value.tableRef.style.width = ''
77
+
78
+ Object.values(headerCellsWidths).forEach((cellElement) => {
79
+ cellElement.baseWidth = Math.floor(cellElement.cell.offsetWidth)
80
+ })
81
+
82
+ setProvidedCellWidths(calculatedColumnSizing.value)
83
+ tableElement.value.tableRef.style.width =
84
+ (calculatedColumnSizing.value?.['table'] || tableInitialWidth) + 'px'
85
+
86
+ Object.values(headerCellsWidths).forEach((cellElement) => {
87
+ cellElement.initialWidth = Math.floor(cellElement.cell.offsetWidth)
88
+ })
89
+
53
90
  return headerCellsWidths
54
91
  }
55
92
 
@@ -109,6 +146,10 @@ export function useResizeColumns() {
109
146
  updatedColumnSizingValue[cell] = newWidth
110
147
  }
111
148
 
149
+ if (tableElement.value && tableElement.value?.tableRef) {
150
+ updatedColumnSizingValue['table'] = tableElement.value.tableRef.offsetWidth
151
+ }
152
+
112
153
  calculatedColumnSizing.value = updatedColumnSizingValue
113
154
  }
114
155
  }
@@ -121,16 +162,20 @@ export function useResizeColumns() {
121
162
  return 0
122
163
  }
123
164
 
165
+ const lastCell = computed(() => {
166
+ if (cells.value) {
167
+ return Object.values(cells.value).find((cell) => cell.isLast)
168
+ }
169
+
170
+ return undefined
171
+ })
172
+
124
173
  const getCellId = (cell: HTMLTableCellElement) => {
125
174
  return cell.id.split('_')[0]
126
175
  }
127
176
 
128
- const resizeCells = (
129
- cell: HTMLTableCellElement | null,
130
- neighborCell: HTMLTableCellElement | null,
131
- e: MouseEvent
132
- ) => {
133
- if (!cell || !neighborCell) {
177
+ const resizeCells = (cell: HTMLTableCellElement | null, e: MouseEvent) => {
178
+ if (!cell || !tableElement.value?.tableRef || !lastCell.value) {
134
179
  resizingCellId.value = ''
135
180
  neighborCellId.value = ''
136
181
 
@@ -140,7 +185,9 @@ export function useResizeColumns() {
140
185
  const movementX = e.movementX
141
186
  const direction: 'left' | 'right' = movementX < 0 ? 'left' : 'right'
142
187
  const newCellWidth = Math.floor(parseInt(cell.style.width)) + movementX
143
- const newNeighborCellWidth = Math.floor(parseInt(neighborCell.style.width)) - movementX
188
+ const newTableWidth =
189
+ Math.floor(parseInt(tableElement.value?.tableRef?.style.width)) + movementX
190
+ const newLastCellWidth = Math.floor(parseInt(lastCell.value.cell.style.width)) - movementX
144
191
 
145
192
  if (direction === 'left') {
146
193
  const min =
@@ -148,29 +195,35 @@ export function useResizeColumns() {
148
195
  ? cells.value[getCellId(cell)].minWidth
149
196
  : MIN_CELL_WIDTH
150
197
 
151
- if (newCellWidth <= min || !cell.hasAttribute('can-resize')) {
152
- const nextCell = cell.previousElementSibling as HTMLTableCellElement | null
198
+ if (newCellWidth >= min) {
199
+ cell.style.width = newCellWidth + 'px'
153
200
 
154
- resizeCells(nextCell, neighborCell, e)
201
+ if (newTableWidth >= minTableWidth.value) {
202
+ tableElement.value.tableRef.style.width = newTableWidth + 'px'
203
+ } else {
204
+ tableElement.value.tableRef.style.width = minTableWidth.value + 'px'
205
+ lastCell.value.cell.style.width = newLastCellWidth + 'px'
206
+ }
155
207
  } else {
156
- cell.style.width = newCellWidth + 'px'
157
- neighborCell.style.width = newNeighborCellWidth + 'px'
208
+ return
158
209
  }
159
210
  } else {
160
211
  const min =
161
- cells.value && cells.value[getCellId(neighborCell)]
162
- ? cells.value[getCellId(neighborCell)].minWidth +
163
- getLastCellOnTheRightExtraSpace(neighborCell)
212
+ cells.value && cells.value[getCellId(lastCell.value.cell)]
213
+ ? cells.value[getCellId(lastCell.value.cell)].minWidth +
214
+ getLastCellOnTheRightExtraSpace(lastCell.value.cell)
164
215
  : MIN_CELL_WIDTH
165
216
 
166
- if (newNeighborCellWidth <= min || !neighborCell.hasAttribute('can-resize')) {
167
- const nextNeighborCell = neighborCell.nextElementSibling as HTMLTableCellElement | null
168
-
169
- resizeCells(cell, nextNeighborCell, e)
217
+ if (
218
+ newLastCellWidth >= min &&
219
+ tableElement.value.tableRef.offsetWidth <= minTableWidth.value
220
+ ) {
221
+ lastCell.value.cell.style.width = newLastCellWidth + 'px'
170
222
  } else {
171
- cell.style.width = newCellWidth + 'px'
172
- neighborCell.style.width = newNeighborCellWidth + 'px'
223
+ tableElement.value.tableRef.style.width = newTableWidth + 'px'
173
224
  }
225
+
226
+ cell.style.width = newCellWidth + 'px'
174
227
  }
175
228
  }
176
229
 
@@ -179,27 +232,66 @@ export function useResizeColumns() {
179
232
 
180
233
  if (cells.value) {
181
234
  const resizingCell = cells.value[resizingCellId.value]?.cell
182
- const neighborCell = cells.value[neighborCellId.value]?.cell
183
235
 
184
- resizeCells(resizingCell, neighborCell, e)
236
+ resizeCells(resizingCell, e)
185
237
  }
186
238
  }
187
239
 
188
240
  const resetCells = () => {
189
- if (cells.value) {
190
- const updatedColumnSizingValue: Record<string, number> = {}
241
+ if (cells.value && tableElement.value && tableElement.value?.tableRef) {
242
+ tableElement.value.tableRef.style.width = ''
191
243
 
192
- for (const cell in cells.value) {
193
- const inititalWidth = cells.value[cell].initialWidth
244
+ calculatedColumnSizing.value = {}
245
+ setInitialColumnWidths()
246
+ }
247
+ }
194
248
 
195
- cells.value[cell].cell.style.width = inititalWidth + 'px'
196
- updatedColumnSizingValue[cell] = inititalWidth
249
+ const resetCell = (cellId: string) => {
250
+ if (
251
+ cells.value &&
252
+ calculatedColumnSizing.value &&
253
+ lastCell.value &&
254
+ tableElement.value &&
255
+ tableElement.value?.tableRef
256
+ ) {
257
+ const thisCellBaseWidth = cells.value[cellId].baseWidth
258
+ const thisCellCurrentWidth = calculatedColumnSizing.value[cellId]
259
+ const diff = thisCellBaseWidth - thisCellCurrentWidth
260
+
261
+ let newTableWidth = calculatedColumnSizing.value['table'] + diff
262
+
263
+ if (newTableWidth < minTableWidth.value) {
264
+ const tableWidthDiff = minTableWidth.value - newTableWidth
265
+ const newLastCellWidth =
266
+ calculatedColumnSizing.value[getCellId(lastCell.value.cell)] + tableWidthDiff
267
+
268
+ lastCell.value.cell.style.width = newLastCellWidth + 'px'
269
+ newTableWidth = minTableWidth.value
197
270
  }
198
271
 
199
- calculatedColumnSizing.value = updatedColumnSizingValue
272
+ cells.value[cellId].cell.style.width = thisCellBaseWidth + 'px'
273
+ tableElement.value.tableRef.style.width = newTableWidth + 'px'
274
+ calculatedColumnSizing.value[cellId] = thisCellBaseWidth
275
+ calculatedColumnSizing.value['table'] = newTableWidth
200
276
  }
201
277
  }
202
278
 
279
+ const getTableWrapperWidth = () => {
280
+ if (tableElement.value && tableElement.value.scrollAreaElementRef?.tableWrapperRef) {
281
+ return tableElement.value.scrollAreaElementRef?.tableWrapperRef.$el.offsetWidth - 3
282
+ }
283
+
284
+ return 0
285
+ }
286
+
287
+ const getTableWidth = () => {
288
+ if (tableElement.value && tableElement.value?.tableRef) {
289
+ return tableElement.value.tableRef.offsetWidth
290
+ }
291
+
292
+ return 0
293
+ }
294
+
203
295
  const setInitialColumnWidths = () => {
204
296
  cells.value = getCells()
205
297
 
@@ -211,21 +303,38 @@ export function useResizeColumns() {
211
303
  cells.value[cell].cell.style.width = cells.value[cell].initialWidth + 'px'
212
304
  }
213
305
 
306
+ cells.value[cell].cell.style.minWidth = cells.value[cell].minWidth + 'px'
307
+
214
308
  updatedColumnSizingValue[cell] = cells.value[cell].cell.offsetWidth
215
309
  }
216
310
 
311
+ if (tableElement.value && tableElement.value?.tableRef) {
312
+ const tableOffsetWidth = getTableWidth()
313
+
314
+ if (calculatedColumnSizing.value?.['table'] && !tableElement.value.tableRef.style.width) {
315
+ tableElement.value.tableRef.style.width = calculatedColumnSizing.value['table'] + 'px'
316
+ } else {
317
+ initialTableWidth.value = tableOffsetWidth
318
+ tableElement.value.tableRef.style.width = tableOffsetWidth + 'px'
319
+ updatedColumnSizingValue['table'] = tableOffsetWidth
320
+ }
321
+ }
322
+
323
+ minTableWidth.value = getTableWrapperWidth()
217
324
  calculatedColumnSizing.value = updatedColumnSizingValue
218
325
  }
219
326
  }
220
327
 
221
328
  return {
222
329
  cells,
330
+ tableElement,
223
331
  tableHeaderElement,
224
332
  calculatedColumnSizing,
225
333
  isResizing,
226
334
  resizingCellId,
227
335
  handleResizeControlMouseDown,
228
336
  handleResizeControlMouseUp,
337
+ resetCell,
229
338
  resetCells,
230
339
  setInitialColumnWidths,
231
340
  setProvidedCellWidths,
@@ -115,7 +115,7 @@ function updateSelection(val?: RowSelectionState) {
115
115
  }
116
116
 
117
117
  const columnVisibility = ref<VisibilityState>({ hiddenColumn: false })
118
- const columnSizing = ref<Record<string, number>>({ title: 450 })
118
+ const columnSizing = ref<Record<string, number>>({})
119
119
  const columnOrder = ref<ColumnOrderState>()
120
120
 
121
121
  type GroupBy = 'none' | 'status' | 'priority'
@@ -1,141 +0,0 @@
1
- import { defineComponent as p, ref as m, computed as d, watch as S, createBlock as C, createCommentVNode as k, openBlock as f, unref as r, mergeProps as v, withCtx as u, renderSlot as _, toRefs as $, onMounted as x, createElementBlock as V, Fragment as B, createElementVNode as X, createVNode as i, normalizeStyle as H, createTextVNode as N } from "vue";
2
- import { i as w, S as R, _ as Y } from "./BuiScrollBar.vue_vue_type_script_setup_true_lang-cV0od8j0.js";
3
- import { u as E } from "./useForwardExpose-DmyWSR4F.js";
4
- import { P as b } from "./Primitive-EBuBc72_.js";
5
- import { useResizeObserver as A } from "@vueuse/core";
6
- import { u as q } from "./useNonce-DM9DidHz.js";
7
- import { g as W } from "./utils-DhVytAXN.js";
8
- var P = /* @__PURE__ */ p({
9
- __name: "ScrollAreaCornerImpl",
10
- setup(c) {
11
- const e = w(), l = m(0), o = m(0), s = d(() => !!l.value && !!o.value);
12
- function a() {
13
- const t = e.scrollbarX.value?.offsetHeight || 0;
14
- e.onCornerHeightChange(t), o.value = t;
15
- }
16
- function n() {
17
- const t = e.scrollbarY.value?.offsetWidth || 0;
18
- e.onCornerWidthChange(t), l.value = t;
19
- }
20
- return A(e.scrollbarX.value, a), A(e.scrollbarY.value, n), S(() => e.scrollbarX.value, a), S(() => e.scrollbarY.value, n), (t, y) => s.value ? (f(), C(r(b), v({
21
- key: 0,
22
- style: {
23
- width: `${l.value}px`,
24
- height: `${o.value}px`,
25
- position: "absolute",
26
- right: r(e).dir.value === "ltr" ? 0 : void 0,
27
- left: r(e).dir.value === "rtl" ? 0 : void 0,
28
- bottom: 0
29
- }
30
- }, t.$parent?.$props), {
31
- default: u(() => [_(t.$slots, "default")]),
32
- _: 3
33
- }, 16, ["style"])) : k("v-if", !0);
34
- }
35
- }), z = P, I = /* @__PURE__ */ p({
36
- __name: "ScrollAreaCorner",
37
- props: {
38
- asChild: {
39
- type: Boolean,
40
- required: !1
41
- },
42
- as: {
43
- type: null,
44
- required: !1
45
- }
46
- },
47
- setup(c) {
48
- const e = c, { forwardRef: l } = E(), o = w(), s = d(() => !!o.scrollbarX.value && !!o.scrollbarY.value), a = d(() => o.type.value !== "scroll" && s.value);
49
- return (n, t) => a.value ? (f(), C(z, v({ key: 0 }, e, { ref: r(l) }), {
50
- default: u(() => [_(n.$slots, "default")]),
51
- _: 3
52
- }, 16)) : k("v-if", !0);
53
- }
54
- }), F = I, j = /* @__PURE__ */ p({
55
- inheritAttrs: !1,
56
- __name: "ScrollAreaViewport",
57
- props: {
58
- nonce: {
59
- type: String,
60
- required: !1
61
- },
62
- asChild: {
63
- type: Boolean,
64
- required: !1
65
- },
66
- as: {
67
- type: null,
68
- required: !1
69
- }
70
- },
71
- setup(c, { expose: e }) {
72
- const l = c, { nonce: o } = $(l), s = q(o), a = w(), n = m();
73
- x(() => {
74
- a.onViewportChange(n.value), a.onContentChange(y.value);
75
- }), e({ viewportElement: n });
76
- const { forwardRef: t, currentElement: y } = E();
77
- return (h, g) => (f(), V(B, null, [X("div", v({
78
- ref_key: "viewportElement",
79
- ref: n,
80
- "data-reka-scroll-area-viewport": "",
81
- style: {
82
- overflowX: r(a).scrollbarXEnabled.value ? "scroll" : "hidden",
83
- overflowY: r(a).scrollbarYEnabled.value ? "scroll" : "hidden"
84
- }
85
- }, h.$attrs, { tabindex: 0 }), [i(r(b), {
86
- ref: r(t),
87
- style: H({ minWidth: r(a).scrollbarXEnabled.value ? "fit-content" : void 0 }),
88
- "as-child": l.asChild,
89
- as: h.as
90
- }, {
91
- default: u(() => [_(h.$slots, "default")]),
92
- _: 3
93
- }, 8, [
94
- "style",
95
- "as-child",
96
- "as"
97
- ])], 16), i(r(b), {
98
- as: "style",
99
- nonce: r(s)
100
- }, {
101
- default: u(() => g[0] || (g[0] = [N(" /* Hide scrollbars cross-browser and enable momentum scroll for touch devices */ [data-reka-scroll-area-viewport] { scrollbar-width:none; -ms-overflow-style:none; -webkit-overflow-scrolling:touch; } [data-reka-scroll-area-viewport]::-webkit-scrollbar { display:none; } ")])),
102
- _: 1,
103
- __: [0]
104
- }, 8, ["nonce"])], 64));
105
- }
106
- }), D = j;
107
- const Q = /* @__PURE__ */ p({
108
- __name: "BuiScrollArea",
109
- props: {
110
- type: {},
111
- dir: {},
112
- scrollHideDelay: {},
113
- asChild: { type: Boolean },
114
- as: {},
115
- class: {}
116
- },
117
- setup(c) {
118
- const e = c, l = d(() => {
119
- const { class: o, ...s } = e;
120
- return s;
121
- });
122
- return (o, s) => (f(), C(r(R), v(l.value, {
123
- class: r(W)("relative overflow-hidden", e.class)
124
- }), {
125
- default: u(() => [
126
- i(r(D), { class: "h-full w-full rounded-[inherit]" }, {
127
- default: u(() => [
128
- _(o.$slots, "default")
129
- ]),
130
- _: 3
131
- }),
132
- i(Y),
133
- i(r(F))
134
- ]),
135
- _: 3
136
- }, 16, ["class"]));
137
- }
138
- });
139
- export {
140
- Q as _
141
- };