Skip to content

Commit a60d341

Browse files
committed
feat: release 0.0.1
1 parent 75ac08c commit a60d341

18 files changed

+5603
-0
lines changed

.editorconfig

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# EditorConfig is awesome: https://EditorConfig.org
2+
3+
# top-most EditorConfig file
4+
root = true
5+
6+
[*]
7+
indent_style = space
8+
indent_size = 2
9+
end_of_line = lf
10+
charset = utf-8
11+
trim_trailing_whitespace = true
12+
insert_final_newline = true

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dist/

.eslintrc.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
module.exports = {
2+
root: true,
3+
env: {
4+
browser: true,
5+
es2021: true,
6+
node: true,
7+
},
8+
extends: [
9+
'plugin:vue/vue3-recommended',
10+
'eslint:recommended',
11+
'@vue/typescript/recommended',
12+
'@vue/prettier',
13+
'@vue/prettier/@typescript-eslint',
14+
],
15+
parserOptions: {
16+
ecmaVersion: 2021,
17+
},
18+
plugins: [],
19+
rules: {},
20+
};

.husky/commit-msg

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
4+
npx --no-install commitlint --edit "$1"

.husky/pre-commit

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
4+
npx lint-staged

.lintstagedrc.json

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"src/**/*.{ts,tsx}": "eslint --fix",
3+
"*.{ts,tsx,js,json,md}": "prettier --write"
4+
}

.prettierrc.json

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"singleQuote": true,
3+
"trailingComma": "all"
4+
}

babel.config.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
presets: ['@babel/preset-typescript', '@babel/preset-env'],
3+
plugins: [
4+
// https://github.com/vuejs/jsx-next
5+
['@vue/babel-plugin-jsx', { mergeProps: false, enableObjectSlots: false }],
6+
],
7+
};

commitlint.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = { extends: ['@commitlint/config-conventional'] };

package-lock.json

+4,474
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{
2+
"name": "vue3-virtual-scroll-list",
3+
"version": "0.0.1",
4+
"description": "A vue3 component support big amount data list with high scroll performance.",
5+
"main": "dist/index.js",
6+
"scripts": {
7+
"build:dev": "cross-env mode=development rollup -c rollup.config.js -w",
8+
"build": "cross-env mode=production rollup -c rollup.config.js",
9+
"prepare": "husky install"
10+
},
11+
"repository": {
12+
"type": "git",
13+
"url": "git+https://github.com/reactjser/vue3-virtual-scroll-list.git"
14+
},
15+
"keywords": [
16+
"vue3",
17+
"big-data",
18+
"big-list",
19+
"scroll-list",
20+
"virtual-list"
21+
],
22+
"author": "reactjser",
23+
"license": "MIT",
24+
"bugs": {
25+
"url": "https://github.com/reactjser/vue3-virtual-scroll-list/issues"
26+
},
27+
"homepage": "https://github.com/reactjser/vue3-virtual-scroll-list#readme",
28+
"peerDependencies": {
29+
"vue": ">=3.0.0"
30+
},
31+
"devDependencies": {
32+
"@babel/core": "^7.15.0",
33+
"@babel/preset-env": "^7.15.0",
34+
"@babel/preset-typescript": "^7.15.0",
35+
"@commitlint/cli": "^13.1.0",
36+
"@commitlint/config-conventional": "^13.1.0",
37+
"@rollup/plugin-babel": "^5.3.0",
38+
"@rollup/plugin-commonjs": "^20.0.0",
39+
"@rollup/plugin-node-resolve": "^13.0.4",
40+
"@typescript-eslint/eslint-plugin": "^4.29.1",
41+
"@typescript-eslint/parser": "^4.29.1",
42+
"@vue/babel-plugin-jsx": "^1.0.6",
43+
"@vue/eslint-config-prettier": "^6.0.0",
44+
"@vue/eslint-config-typescript": "^7.0.0",
45+
"cross-env": "^7.0.3",
46+
"eslint": "^7.32.0",
47+
"eslint-plugin-prettier": "^3.4.0",
48+
"eslint-plugin-vue": "^7.16.0",
49+
"husky": "^7.0.0",
50+
"lint-staged": "^11.1.2",
51+
"prettier": "^2.3.2",
52+
"rollup": "^2.56.2",
53+
"tiny-emitter": "^2.1.0",
54+
"typescript": "^4.3.5",
55+
"vue": "^3.2.2"
56+
}
57+
}

rollup.config.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import babel from '@rollup/plugin-babel';
2+
import resolve from '@rollup/plugin-node-resolve';
3+
import commonjs from '@rollup/plugin-commonjs';
4+
import pkg from './package.json';
5+
6+
const extensions = ['.js', '.jsx', '.ts', '.tsx'];
7+
const isDev = process.env.mode !== 'production';
8+
const banner = `/**
9+
* vue3-virtual-scroll-list v${pkg.version}
10+
* open source under the MIT license
11+
* ${pkg.homepage}
12+
*/`;
13+
14+
export default {
15+
external: ['vue'],
16+
input: 'src/index.ts',
17+
output: {
18+
file: 'dist/index.js',
19+
format: 'esm',
20+
banner,
21+
sourcemap: isDev,
22+
},
23+
plugins: [
24+
resolve({
25+
extensions,
26+
}),
27+
commonjs(),
28+
babel({ extensions, babelHelpers: 'bundled' }),
29+
],
30+
};

src/index.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import VirtualList from './virtual-list';
2+
3+
export default VirtualList;

src/item.tsx

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
import { defineComponent, h } from 'vue';
2+
import emitter from 'tiny-emitter/instance';
3+
import { ItemProps, SlotProps } from './props';
4+
5+
const Wrapper = {
6+
created() {
7+
this.shapeKey = this.horizontal ? 'offsetWidth' : 'offsetHeight';
8+
},
9+
10+
mounted() {
11+
if (typeof ResizeObserver !== 'undefined') {
12+
this.resizeObserver = new ResizeObserver(() => {
13+
this.dispatchSizeChange();
14+
});
15+
this.resizeObserver.observe(this.$el);
16+
}
17+
},
18+
19+
// since componet will be reused, so disptach when updated
20+
updated() {
21+
this.dispatchSizeChange();
22+
},
23+
24+
beforeDestroy() {
25+
if (this.resizeObserver) {
26+
this.resizeObserver.disconnect();
27+
this.resizeObserver = null;
28+
}
29+
},
30+
31+
methods: {
32+
getCurrentSize() {
33+
return this.$el ? this.$el[this.shapeKey] : 0;
34+
},
35+
36+
// tell parent current size identify by unqiue key
37+
dispatchSizeChange() {
38+
emitter.emit(
39+
this.event,
40+
this.uniqueKey,
41+
this.getCurrentSize(),
42+
this.hasInitial,
43+
);
44+
// this.$parent.$emit(this.event, this.uniqueKey, this.getCurrentSize(), this.hasInitial)
45+
},
46+
},
47+
};
48+
49+
export const Item = defineComponent({
50+
name: 'VirtualListItem',
51+
mixins: [Wrapper],
52+
props: ItemProps,
53+
render() {
54+
const {
55+
tag,
56+
component,
57+
extraProps = {},
58+
index,
59+
source,
60+
scopedSlots = {},
61+
uniqueKey,
62+
} = this;
63+
const props = {
64+
...extraProps,
65+
source,
66+
index,
67+
};
68+
69+
return h(
70+
tag,
71+
{
72+
key: uniqueKey,
73+
},
74+
[
75+
h(component, {
76+
...props,
77+
scopedSlots: scopedSlots,
78+
}),
79+
],
80+
);
81+
},
82+
});
83+
84+
export const Slot = defineComponent({
85+
mixins: [Wrapper],
86+
props: SlotProps,
87+
setup(props, { slots }) {
88+
return () => {
89+
const { tag, uniqueKey } = props;
90+
91+
return h(
92+
tag,
93+
{
94+
key: uniqueKey,
95+
},
96+
slots.default(),
97+
);
98+
};
99+
},
100+
});

0 commit comments

Comments
 (0)