@wyxos/vibe 1.2.12 → 1.2.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/Masonry.vue +37 -12
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wyxos/vibe",
3
- "version": "1.2.12",
3
+ "version": "1.2.14",
4
4
  "main": "index.js",
5
5
  "module": "index.js",
6
6
  "type": "module",
package/src/Masonry.vue CHANGED
@@ -28,6 +28,10 @@ const props = defineProps({
28
28
  skipInitialLoad: {
29
29
  type: Boolean,
30
30
  default: false
31
+ },
32
+ maxItems: {
33
+ type: Number,
34
+ default: 100
31
35
  }
32
36
  })
33
37
 
@@ -98,15 +102,32 @@ async function onScroll() {
98
102
  if ((whitespaceVisible || reachedContainerBottom) && !isLoading.value) {
99
103
  isLoading.value = true
100
104
 
101
- if (paginationHistory.value.length > 3) {
102
- // get first item
105
+ if (masonry.value.length > props.maxItems) {
106
+ // get first item - only proceed if it exists
103
107
  const firstItem = masonry.value[0]
108
+
109
+ if (!firstItem) {
110
+ // Skip removal logic if there are no items
111
+ await loadNext()
112
+ await nextTick()
113
+ isLoading.value = false
114
+ return
115
+ }
104
116
 
105
117
  // get page number
106
118
  const page = firstItem.page
107
119
 
108
120
  // find all item with this page
109
121
  const removedItems = masonry.value.filter(i => i.page !== page)
122
+
123
+ // Only proceed with removal if there are actually items to remove
124
+ if (removedItems.length === masonry.value.length) {
125
+ // All items belong to the same page, skip removal logic
126
+ await loadNext()
127
+ await nextTick()
128
+ isLoading.value = false
129
+ return
130
+ }
110
131
 
111
132
  refreshLayout(removedItems)
112
133
 
@@ -116,16 +137,20 @@ async function onScroll() {
116
137
 
117
138
  // find the last item in that column
118
139
  const lastItemInColumn = masonry.value.filter((_, index) => index % columns.value === lowestColumnIndex).pop()
119
- const lastItemInColumnTop = lastItemInColumn.top + lastItemInColumn.columnHeight
120
- const lastItemInColumnBottom = lastItemInColumnTop + lastItemInColumn.columnHeight
121
- const containerTop = container.value.scrollTop
122
- const containerBottom = containerTop + container.value.clientHeight
123
- const itemInView = lastItemInColumnTop >= containerTop && lastItemInColumnBottom <= containerBottom
124
- if (!itemInView) {
125
- container.value.scrollTo({
126
- top: lastItemInColumnTop - 10,
127
- behavior: 'smooth'
128
- })
140
+
141
+ // Only proceed with scroll adjustment if we have a valid item
142
+ if (lastItemInColumn) {
143
+ const lastItemInColumnTop = lastItemInColumn.top + lastItemInColumn.columnHeight
144
+ const lastItemInColumnBottom = lastItemInColumnTop + lastItemInColumn.columnHeight
145
+ const containerTop = container.value.scrollTop
146
+ const containerBottom = containerTop + container.value.clientHeight
147
+ const itemInView = lastItemInColumnTop >= containerTop && lastItemInColumnBottom <= containerBottom
148
+ if (!itemInView) {
149
+ container.value.scrollTo({
150
+ top: lastItemInColumnTop - 10,
151
+ behavior: 'smooth'
152
+ })
153
+ }
129
154
  }
130
155
  }
131
156