@yasanchezz/vue-infinite-grid 0.1.9 → 0.1.10
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/README.md +108 -2
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -1,3 +1,109 @@
|
|
|
1
|
-
#
|
|
2
|
-
that placeholder will be replaced by some content soon
|
|
1
|
+
# @yasanchezz/vue-infinite-grid
|
|
3
2
|
|
|
3
|
+
> An infinite (virtualized) grid component for Vue 3.5+
|
|
4
|
+
|
|
5
|
+
`VueGrid` renders only the rows that fit near the visible viewport (plus a
|
|
6
|
+
buffer) and keeps scroll height consistent by measuring each rendered row
|
|
7
|
+
with a `ResizeObserver`. It relies on CSS Grid + [`subgrid`](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_grid_layout/Subgrid),
|
|
8
|
+
so your rows must be laid out as a grid that spans the full width of the
|
|
9
|
+
component.
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
Install the npm package
|
|
14
|
+
|
|
15
|
+
`npm install @yasanchezz/vue-infinite-grid --save`
|
|
16
|
+
|
|
17
|
+
Register it as a global component in `main.js`
|
|
18
|
+
|
|
19
|
+
``` js
|
|
20
|
+
import VueGrid from '@yasanchezz/vue-infinite-grid';
|
|
21
|
+
import '@yasanchezz/vue-infinite-grid/dist/style.css';
|
|
22
|
+
|
|
23
|
+
createApp(App)
|
|
24
|
+
.use(VueGrid)
|
|
25
|
+
.mount('#app');
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Usage
|
|
29
|
+
|
|
30
|
+
``` vue
|
|
31
|
+
<template>
|
|
32
|
+
<VueGrid
|
|
33
|
+
ref="grid"
|
|
34
|
+
:rows="rows"
|
|
35
|
+
:rows-count="10"
|
|
36
|
+
:height="200"
|
|
37
|
+
class="my-grid"
|
|
38
|
+
>
|
|
39
|
+
<template #row="{ row }">
|
|
40
|
+
<SubgridComponent
|
|
41
|
+
class="my-subgrid"
|
|
42
|
+
:row="row"
|
|
43
|
+
/>
|
|
44
|
+
</template>
|
|
45
|
+
</VueGrid>
|
|
46
|
+
</template>
|
|
47
|
+
|
|
48
|
+
<style lang="scss" scoped>
|
|
49
|
+
.my-grid {
|
|
50
|
+
grid-template-columns: repeat(4, 1fr);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.my-subgrid {
|
|
54
|
+
grid-column: 1 / -1;
|
|
55
|
+
display: grid;
|
|
56
|
+
grid-template-columns: subgrid;
|
|
57
|
+
}
|
|
58
|
+
</style>
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Each item in `rows` must have a unique `id: string`, which `VueGrid` uses as
|
|
62
|
+
the `:key` for the row and to track its measured height.
|
|
63
|
+
|
|
64
|
+
## Props
|
|
65
|
+
|
|
66
|
+
| Prop | Type | Required | Default | Description |
|
|
67
|
+
| --- | --- | --- | --- | --- |
|
|
68
|
+
| `rows` | `GridRow[]` (`{ id: string }`) | yes | - | The full list of rows. Only a window of these is actually rendered at a time. |
|
|
69
|
+
| `rowsCount` | `number` | yes | - | How many rows to render at once (the size of the rendered window). |
|
|
70
|
+
| `height` | `number` | yes | - | Estimated row height in px, used for scroll/offset math before a row has actually been measured. |
|
|
71
|
+
| `container` | `Element \| null \| ((container: Element \| null) => Element \| null \| undefined)` | no | `document.documentElement` | The scrollable element to listen to. Can be a function that receives the grid's root element (useful for resolving a custom scroll container after mount). |
|
|
72
|
+
| `autoCalculatedRowsCount` | `boolean` | no | `false` | When `true`, grows the rendered window beyond `rowsCount` based on measured row heights so it always covers the viewport (useful when actual row heights are smaller than the estimated `height`). |
|
|
73
|
+
|
|
74
|
+
## Slots
|
|
75
|
+
|
|
76
|
+
| Slot | Props | Description |
|
|
77
|
+
| --- | --- | --- |
|
|
78
|
+
| `row` | `{ row: GridRow }` | Renders a single row. Required. |
|
|
79
|
+
|
|
80
|
+
## Exposed methods
|
|
81
|
+
|
|
82
|
+
| Method | Signature | Description |
|
|
83
|
+
| --- | --- | --- |
|
|
84
|
+
| `init` | `() => void` | Recalculates the rendered window and layout. Call this after something outside of `rows`/`height` changes the available space, e.g. on window `resize`. |
|
|
85
|
+
| `scrollTo` | `(id: string) => Promise<HTMLElement>` | Scrolls the container to the row with the given `id` and resolves with that row's DOM element once it has been rendered. |
|
|
86
|
+
|
|
87
|
+
### Usage as a ref
|
|
88
|
+
|
|
89
|
+
``` vue
|
|
90
|
+
<script setup>
|
|
91
|
+
import { useTemplateRef } from 'vue'
|
|
92
|
+
|
|
93
|
+
const grid = useTemplateRef('grid')
|
|
94
|
+
|
|
95
|
+
grid.value.scrollTo(rowId) // scroll to a specific row
|
|
96
|
+
window.addEventListener('resize', () => grid.value.init()) // recalculate layout on resize
|
|
97
|
+
</script>
|
|
98
|
+
|
|
99
|
+
<template>
|
|
100
|
+
<VueGrid ref="grid" :rows="rows" :rows-count="10" :height="200" />
|
|
101
|
+
</template>
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## Styling notes
|
|
105
|
+
|
|
106
|
+
`VueGrid` only controls vertical layout - you're expected to define the
|
|
107
|
+
column layout on the root element (e.g. `grid-template-columns`) and have
|
|
108
|
+
each row use `display: grid; grid-template-columns: subgrid;` spanning
|
|
109
|
+
`grid-column: 1 / -1` so it inherits those columns.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yasanchezz/vue-infinite-grid",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.10",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -15,12 +15,12 @@
|
|
|
15
15
|
"devDependencies": {
|
|
16
16
|
"@stylistic/eslint-plugin": "^5.10.0",
|
|
17
17
|
"@tsconfig/node24": "^24.0.4",
|
|
18
|
-
"@types/node": "^24.13.
|
|
19
|
-
"@typescript-eslint/utils": "^8.
|
|
20
|
-
"@vitejs/plugin-vue": "^6.0.
|
|
18
|
+
"@types/node": "^24.13.3",
|
|
19
|
+
"@typescript-eslint/utils": "^8.65.0",
|
|
20
|
+
"@vitejs/plugin-vue": "^6.0.8",
|
|
21
21
|
"@vue/eslint-config-typescript": "^14.9.0",
|
|
22
22
|
"@vue/tsconfig": "^0.9.1",
|
|
23
|
-
"eslint": "^10.
|
|
23
|
+
"eslint": "^10.7.0",
|
|
24
24
|
"eslint-config-prettier": "^10.1.8",
|
|
25
25
|
"eslint-plugin-oxlint": "~1.69.0",
|
|
26
26
|
"eslint-plugin-vue": "~10.9.2",
|
|
@@ -29,11 +29,11 @@
|
|
|
29
29
|
"oxfmt": "^0.54.0",
|
|
30
30
|
"oxlint": "~1.69.0",
|
|
31
31
|
"typescript": "~6.0.3",
|
|
32
|
-
"vite": "^8.1.
|
|
32
|
+
"vite": "^8.1.5",
|
|
33
33
|
"vite-plugin-dts": "^5.0.3",
|
|
34
34
|
"vite-plugin-vue-devtools": "^8.1.5",
|
|
35
35
|
"vue-eslint-parser": "^10.4.1",
|
|
36
|
-
"vue-tsc": "^3.3.
|
|
36
|
+
"vue-tsc": "^3.3.8"
|
|
37
37
|
},
|
|
38
38
|
"engines": {
|
|
39
39
|
"node": ">= 24.12.0",
|