@wyxos/vibe 1.2.4 → 1.2.6
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/package.json +1 -1
- package/src/Masonry.vue +43 -53
- package/src/calculateLayout.js +9 -1
package/package.json
CHANGED
package/src/Masonry.vue
CHANGED
|
@@ -17,41 +17,30 @@ const props = defineProps({
|
|
|
17
17
|
type: Array,
|
|
18
18
|
default: () => []
|
|
19
19
|
},
|
|
20
|
-
|
|
20
|
+
layout: {
|
|
21
21
|
type: Object,
|
|
22
22
|
default: () => ({
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
23
|
+
sizes: {
|
|
24
|
+
base: 1, // mobile-first default
|
|
25
|
+
sm: 2, // ≥ 640px
|
|
26
|
+
md: 3, // ≥ 768px
|
|
27
|
+
lg: 4, // ≥ 1024px
|
|
28
|
+
xl: 5, // ≥ 1280px
|
|
29
|
+
'2xl': 6 // ≥ 1536px
|
|
30
|
+
},
|
|
31
|
+
gutterX: 10,
|
|
32
|
+
gutterY: 10,
|
|
33
|
+
header: 0,
|
|
34
|
+
footer: 0,
|
|
35
|
+
paddingLeft: 0,
|
|
36
|
+
paddingRight: 0
|
|
29
37
|
})
|
|
30
38
|
},
|
|
31
|
-
|
|
32
|
-
type:
|
|
33
|
-
default:
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
type: Number,
|
|
37
|
-
default: 10
|
|
38
|
-
},
|
|
39
|
-
header: {
|
|
40
|
-
type: Number,
|
|
41
|
-
default: 0
|
|
42
|
-
},
|
|
43
|
-
footer: {
|
|
44
|
-
type: Number,
|
|
45
|
-
default: 0
|
|
46
|
-
},
|
|
47
|
-
paddingLeft: {
|
|
48
|
-
type: Number,
|
|
49
|
-
default: 0
|
|
50
|
-
},
|
|
51
|
-
paddingRight: {
|
|
52
|
-
type: Number,
|
|
53
|
-
default: 0
|
|
54
|
-
},
|
|
39
|
+
paginationType: {
|
|
40
|
+
type: String,
|
|
41
|
+
default: 'page', // or 'cursor'
|
|
42
|
+
validator: v => ['page', 'cursor'].includes(v)
|
|
43
|
+
}
|
|
55
44
|
})
|
|
56
45
|
|
|
57
46
|
const emits = defineEmits(['update:items'])
|
|
@@ -65,7 +54,7 @@ const columns = ref(7)
|
|
|
65
54
|
|
|
66
55
|
const container = ref(null)
|
|
67
56
|
|
|
68
|
-
const
|
|
57
|
+
const paginationHistory = ref([])
|
|
69
58
|
|
|
70
59
|
const nextPage = ref(null)
|
|
71
60
|
|
|
@@ -99,7 +88,7 @@ async function onScroll() {
|
|
|
99
88
|
if (whitespaceVisible && !isLoading.value) {
|
|
100
89
|
isLoading.value = true
|
|
101
90
|
|
|
102
|
-
if (
|
|
91
|
+
if (paginationHistory.value > 3) {
|
|
103
92
|
// get first item
|
|
104
93
|
const firstItem = masonry.value[0]
|
|
105
94
|
|
|
@@ -141,12 +130,21 @@ async function onScroll() {
|
|
|
141
130
|
function getColumnCount() {
|
|
142
131
|
const width = window.innerWidth
|
|
143
132
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
133
|
+
const sizes = props.layout.sizes || {
|
|
134
|
+
base: 1, // mobile-first default
|
|
135
|
+
sm: 2, // ≥ 640px
|
|
136
|
+
md: 3, // ≥ 768px
|
|
137
|
+
lg: 4, // ≥ 1024px
|
|
138
|
+
xl: 5, // ≥ 1280px
|
|
139
|
+
'2xl': 6 // ≥ 1536px
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (width >= 1536 && sizes['2xl']) return sizes['2xl']
|
|
143
|
+
if (width >= 1280 && sizes.xl) return sizes.xl
|
|
144
|
+
if (width >= 1024 && sizes.lg) return sizes.lg
|
|
145
|
+
if (width >= 768 && sizes.md) return sizes.md
|
|
146
|
+
if (width >= 640 && sizes.sm) return sizes.sm
|
|
147
|
+
return sizes.base
|
|
150
148
|
}
|
|
151
149
|
|
|
152
150
|
function calculateHeight(layout) {
|
|
@@ -156,14 +154,7 @@ function calculateHeight(layout) {
|
|
|
156
154
|
}
|
|
157
155
|
|
|
158
156
|
function refreshLayout(items) {
|
|
159
|
-
const layout = calculateLayout(items, container.value, columns.value,
|
|
160
|
-
gutterX: props.gutterX,
|
|
161
|
-
gutterY: props.gutterY,
|
|
162
|
-
header: props.header,
|
|
163
|
-
footer: props.footer,
|
|
164
|
-
paddingLeft: props.paddingLeft,
|
|
165
|
-
paddingRight: props.paddingRight,
|
|
166
|
-
});
|
|
157
|
+
const layout = calculateLayout(items, container.value, columns.value, props.layout);
|
|
167
158
|
|
|
168
159
|
calculateHeight(layout)
|
|
169
160
|
|
|
@@ -179,9 +170,8 @@ async function getContent(page) {
|
|
|
179
170
|
}
|
|
180
171
|
|
|
181
172
|
async function loadNext() {
|
|
182
|
-
const response = await getContent(
|
|
183
|
-
|
|
184
|
-
nextPage.value = response.nextPage
|
|
173
|
+
const response = await getContent(paginationHistory.value[paginationHistory.value.length - 1])
|
|
174
|
+
paginationHistory.value.push(response.nextPage)
|
|
185
175
|
}
|
|
186
176
|
|
|
187
177
|
const getItemStyle = (item) => {
|
|
@@ -249,11 +239,11 @@ onMounted(async () => {
|
|
|
249
239
|
|
|
250
240
|
columns.value = getColumnCount()
|
|
251
241
|
|
|
252
|
-
|
|
242
|
+
paginationHistory.value = [props.loadAtPage]
|
|
253
243
|
|
|
254
|
-
const response = await getContent(
|
|
244
|
+
const response = await getContent(paginationHistory.value[0])
|
|
255
245
|
|
|
256
|
-
|
|
246
|
+
paginationHistory.value.push(response.nextPage)
|
|
257
247
|
|
|
258
248
|
isLoading.value = false
|
|
259
249
|
|
package/src/calculateLayout.js
CHANGED
|
@@ -30,7 +30,15 @@ export default function calculateLayout(items, container, columnCount, options =
|
|
|
30
30
|
header = 0,
|
|
31
31
|
footer = 0,
|
|
32
32
|
paddingLeft = 0,
|
|
33
|
-
paddingRight = 0
|
|
33
|
+
paddingRight = 0,
|
|
34
|
+
sizes = {
|
|
35
|
+
base: 1, // mobile-first default
|
|
36
|
+
sm: 2, // ≥ 640px
|
|
37
|
+
md: 3, // ≥ 768px
|
|
38
|
+
lg: 4, // ≥ 1024px
|
|
39
|
+
xl: 5, // ≥ 1280px
|
|
40
|
+
'2xl': 6 // ≥ 1536px
|
|
41
|
+
}
|
|
34
42
|
} = options;
|
|
35
43
|
|
|
36
44
|
const measuredScrollbarWidth = container.offsetWidth - container.clientWidth;
|