@polymarbot/nuxt-layer-shadcn-ui 0.7.6 → 0.7.7

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,6 @@
1
1
  <script setup lang="ts" generic="TData extends Record<string, any>">
2
2
  import type { InfiniteDataTableFetchParams, InfiniteDataTableProps } from './types'
3
+ import { useEventListener } from '@vueuse/core'
3
4
 
4
5
  const props = withDefaults(defineProps<InfiniteDataTableProps<TData>>(), {
5
6
  columns: () => [],
@@ -37,12 +38,28 @@ const isInitialLoad = computed(() => loading.value && internalData.value.length
37
38
  // -- IntersectionObserver root: only when internal scroll is active --
38
39
 
39
40
  const dataTableRef = ref<{ scrollEl?: HTMLElement } | null>(null)
41
+ const scrollEl = computed<HTMLElement | undefined>(() => dataTableRef.value?.scrollEl)
40
42
  const intersectionOptions = computed<IntersectionObserverInit | undefined>(() => { // eslint-disable-line no-undef
41
43
  if (!props.height) return undefined
42
- const root = dataTableRef.value?.scrollEl
44
+ const root = scrollEl.value
43
45
  return root ? { root } : undefined
44
46
  })
45
47
 
48
+ // -- Scroll-to-top availability --
49
+
50
+ const { isOverflowing, atStart } = useScrollState(scrollEl)
51
+ const isWindowAboveTable = ref(false)
52
+
53
+ function updateWindowPosition () {
54
+ const el = scrollEl.value
55
+ isWindowAboveTable.value = !!el && el.getBoundingClientRect().top < 0
56
+ }
57
+
58
+ useEventListener(window, 'scroll', updateWindowPosition, { passive: true })
59
+ onMounted(() => nextTick(updateWindowPosition))
60
+
61
+ const isAtTop = computed(() => isOverflowing.value ? atStart.value : !isWindowAboveTable.value)
62
+
46
63
  // -- Helpers --
47
64
 
48
65
  function getFilters (): Record<string, any> {
@@ -99,9 +116,9 @@ async function refresh () {
99
116
  }
100
117
 
101
118
  function scrollToTop () {
102
- const el = dataTableRef.value?.scrollEl
119
+ const el = scrollEl.value
103
120
  if (!el) return
104
- if (el.scrollHeight > el.clientHeight) {
121
+ if (isOverflowing.value) {
105
122
  el.scrollTo({ top: 0, behavior: 'smooth' })
106
123
  } else {
107
124
  el.scrollIntoView({ behavior: 'smooth', block: 'start' })
@@ -221,7 +238,7 @@ onMounted(() => {
221
238
  variant="ghost"
222
239
  size="icon-sm"
223
240
  icon="arrow-up-to-line"
224
- :disabled="loading || internalData.length === 0"
241
+ :disabled="loading || internalData.length === 0 || isAtTop"
225
242
  @click="scrollToTop"
226
243
  />
227
244
  </Tooltip>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polymarbot/nuxt-layer-shadcn-ui",
3
- "version": "0.7.6",
3
+ "version": "0.7.7",
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": "9303e0b6a75098f94382a178c8ef2bc4dc5e8f88"
45
+ "gitHead": "e053ea4dd7358d5974b1118be8588d88be36e376"
46
46
  }