@king-one/antdv 1.0.4 → 1.0.5
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/CHANGELOG.md +7 -0
- package/antdv/package.json +29 -0
- package/components/base/style/index.ts +8 -0
- package/components/form/component/form.ts +21 -0
- package/components/form/component/form.vue +24 -0
- package/components/form/index.ts +6 -0
- package/components/form-item/component/form-item.vue +106 -0
- package/components/form-item/index.ts +0 -0
- package/components/index.ts +10 -0
- package/components/scroll-bar/index.ts +7 -0
- package/components/scroll-bar/src/scroll-bar.tsx +211 -0
- package/components/scroll-bar/src/types.ts +7 -0
- package/components/scroll-bar/style/index.ts +2 -0
- package/components/utils/install.ts +30 -0
- package/components/virtual-list/index.ts +6 -0
- package/components/virtual-list/src/types.ts +29 -0
- package/components/virtual-list/src/virtual-list.vue +47 -0
- package/hooks/use-namespace/index.ts +93 -0
- package/index.ts +4 -0
- package/installer.ts +19 -0
- package/package.json +3 -3
- package/es/components/base/style/index.d.ts +0 -1
- package/es/components/scroll-bar/style/index.d.ts +0 -2
- package/lib/components/base/style/index.d.ts +0 -1
- package/lib/components/scroll-bar/style/index.d.ts +0 -2
- /package/{cdn → antdv/cdn}/index.cdn.js +0 -0
- /package/{cdn → antdv/cdn}/index.cdn.js.map +0 -0
- /package/{cdn → antdv/cdn}/index.cdn.mjs +0 -0
- /package/{cdn → antdv/cdn}/index.cdn.mjs.map +0 -0
- /package/{cdn → antdv/cdn}/index.css +0 -0
- /package/{es → antdv/es}/components/base/style/index.mjs +0 -0
- /package/{es → antdv/es}/components/base/style/index.mjs.map +0 -0
- /package/{es → antdv/es}/components/form/component/form.d.ts +0 -0
- /package/{es → antdv/es}/components/form/component/form.mjs +0 -0
- /package/{es → antdv/es}/components/form/component/form.mjs.map +0 -0
- /package/{es → antdv/es}/components/form/component/form.vue.d.ts +0 -0
- /package/{es → antdv/es}/components/form/component/form.vue.mjs +0 -0
- /package/{es → antdv/es}/components/form/component/form.vue.mjs.map +0 -0
- /package/{es → antdv/es}/components/form/component/form.vue2.mjs +0 -0
- /package/{es → antdv/es}/components/form/component/form.vue2.mjs.map +0 -0
- /package/{es → antdv/es}/components/form/index.d.ts +0 -0
- /package/{es → antdv/es}/components/form/index.mjs +0 -0
- /package/{es → antdv/es}/components/form/index.mjs.map +0 -0
- /package/{es → antdv/es}/components/form-item/component/form-item.vue.d.ts +0 -0
- /package/{es → antdv/es}/components/form-item/component/form-item.vue.mjs +0 -0
- /package/{es → antdv/es}/components/form-item/component/form-item.vue.mjs.map +0 -0
- /package/{es → antdv/es}/components/form-item/component/form-item.vue2.mjs +0 -0
- /package/{es → antdv/es}/components/form-item/component/form-item.vue2.mjs.map +0 -0
- /package/{es → antdv/es}/components/form-item/index.d.ts +0 -0
- /package/{es → antdv/es}/components/form-item/index.mjs +0 -0
- /package/{es → antdv/es}/components/form-item/index.mjs.map +0 -0
- /package/{es → antdv/es}/components/index.d.ts +0 -0
- /package/{es → antdv/es}/components/index.mjs +0 -0
- /package/{es → antdv/es}/components/index.mjs.map +0 -0
- /package/{es → antdv/es}/components/scroll-bar/index.d.ts +0 -0
- /package/{es → antdv/es}/components/scroll-bar/index.mjs +0 -0
- /package/{es → antdv/es}/components/scroll-bar/index.mjs.map +0 -0
- /package/{es → antdv/es}/components/scroll-bar/src/scroll-bar.d.ts +0 -0
- /package/{es → antdv/es}/components/scroll-bar/src/scroll-bar.mjs +0 -0
- /package/{es → antdv/es}/components/scroll-bar/src/scroll-bar.mjs.map +0 -0
- /package/{es → antdv/es}/components/scroll-bar/src/types.d.ts +0 -0
- /package/{es → antdv/es}/components/scroll-bar/src/types.mjs +0 -0
- /package/{es → antdv/es}/components/scroll-bar/src/types.mjs.map +0 -0
- /package/{es → antdv/es}/components/scroll-bar/style/index.mjs +0 -0
- /package/{es → antdv/es}/components/scroll-bar/style/index.mjs.map +0 -0
- /package/{es → antdv/es}/components/utils/install.d.ts +0 -0
- /package/{es → antdv/es}/components/utils/install.mjs +0 -0
- /package/{es → antdv/es}/components/utils/install.mjs.map +0 -0
- /package/{es → antdv/es}/components/virtual-list/index.d.ts +0 -0
- /package/{es → antdv/es}/components/virtual-list/index.mjs +0 -0
- /package/{es → antdv/es}/components/virtual-list/index.mjs.map +0 -0
- /package/{es → antdv/es}/components/virtual-list/src/types.d.ts +0 -0
- /package/{es → antdv/es}/components/virtual-list/src/types.mjs +0 -0
- /package/{es → antdv/es}/components/virtual-list/src/types.mjs.map +0 -0
- /package/{es → antdv/es}/components/virtual-list/src/virtual-list.vue.d.ts +0 -0
- /package/{es → antdv/es}/components/virtual-list/src/virtual-list.vue.mjs +0 -0
- /package/{es → antdv/es}/components/virtual-list/src/virtual-list.vue.mjs.map +0 -0
- /package/{es → antdv/es}/components/virtual-list/src/virtual-list.vue2.mjs +0 -0
- /package/{es → antdv/es}/components/virtual-list/src/virtual-list.vue2.mjs.map +0 -0
- /package/{es → antdv/es}/hooks/use-namespace/index.d.ts +0 -0
- /package/{es → antdv/es}/hooks/use-namespace/index.mjs +0 -0
- /package/{es → antdv/es}/hooks/use-namespace/index.mjs.map +0 -0
- /package/{es → antdv/es}/index.d.ts +0 -0
- /package/{es → antdv/es}/index.mjs +0 -0
- /package/{es → antdv/es}/index.mjs.map +0 -0
- /package/{es → antdv/es}/installer.d.ts +0 -0
- /package/{es → antdv/es}/installer.mjs +0 -0
- /package/{es → antdv/es}/installer.mjs.map +0 -0
- /package/{lib → antdv/lib}/components/base/style/index.js +0 -0
- /package/{lib → antdv/lib}/components/base/style/index.js.map +0 -0
- /package/{lib → antdv/lib}/components/form/component/form.d.ts +0 -0
- /package/{lib → antdv/lib}/components/form/component/form.js +0 -0
- /package/{lib → antdv/lib}/components/form/component/form.js.map +0 -0
- /package/{lib → antdv/lib}/components/form/component/form.vue.d.ts +0 -0
- /package/{lib → antdv/lib}/components/form/component/form.vue.js +0 -0
- /package/{lib → antdv/lib}/components/form/component/form.vue.js.map +0 -0
- /package/{lib → antdv/lib}/components/form/component/form.vue2.js +0 -0
- /package/{lib → antdv/lib}/components/form/component/form.vue2.js.map +0 -0
- /package/{lib → antdv/lib}/components/form/index.d.ts +0 -0
- /package/{lib → antdv/lib}/components/form/index.js +0 -0
- /package/{lib → antdv/lib}/components/form/index.js.map +0 -0
- /package/{lib → antdv/lib}/components/form-item/component/form-item.vue.d.ts +0 -0
- /package/{lib → antdv/lib}/components/form-item/component/form-item.vue.js +0 -0
- /package/{lib → antdv/lib}/components/form-item/component/form-item.vue.js.map +0 -0
- /package/{lib → antdv/lib}/components/form-item/component/form-item.vue2.js +0 -0
- /package/{lib → antdv/lib}/components/form-item/component/form-item.vue2.js.map +0 -0
- /package/{lib → antdv/lib}/components/form-item/index.d.ts +0 -0
- /package/{lib → antdv/lib}/components/form-item/index.js +0 -0
- /package/{lib → antdv/lib}/components/form-item/index.js.map +0 -0
- /package/{lib → antdv/lib}/components/index.d.ts +0 -0
- /package/{lib → antdv/lib}/components/index.js +0 -0
- /package/{lib → antdv/lib}/components/index.js.map +0 -0
- /package/{lib → antdv/lib}/components/scroll-bar/index.d.ts +0 -0
- /package/{lib → antdv/lib}/components/scroll-bar/index.js +0 -0
- /package/{lib → antdv/lib}/components/scroll-bar/index.js.map +0 -0
- /package/{lib → antdv/lib}/components/scroll-bar/src/scroll-bar.d.ts +0 -0
- /package/{lib → antdv/lib}/components/scroll-bar/src/scroll-bar.js +0 -0
- /package/{lib → antdv/lib}/components/scroll-bar/src/scroll-bar.js.map +0 -0
- /package/{lib → antdv/lib}/components/scroll-bar/src/types.d.ts +0 -0
- /package/{lib → antdv/lib}/components/scroll-bar/src/types.js +0 -0
- /package/{lib → antdv/lib}/components/scroll-bar/src/types.js.map +0 -0
- /package/{lib → antdv/lib}/components/scroll-bar/style/index.js +0 -0
- /package/{lib → antdv/lib}/components/scroll-bar/style/index.js.map +0 -0
- /package/{lib → antdv/lib}/components/utils/install.d.ts +0 -0
- /package/{lib → antdv/lib}/components/utils/install.js +0 -0
- /package/{lib → antdv/lib}/components/utils/install.js.map +0 -0
- /package/{lib → antdv/lib}/components/virtual-list/index.d.ts +0 -0
- /package/{lib → antdv/lib}/components/virtual-list/index.js +0 -0
- /package/{lib → antdv/lib}/components/virtual-list/index.js.map +0 -0
- /package/{lib → antdv/lib}/components/virtual-list/src/types.d.ts +0 -0
- /package/{lib → antdv/lib}/components/virtual-list/src/types.js +0 -0
- /package/{lib → antdv/lib}/components/virtual-list/src/types.js.map +0 -0
- /package/{lib → antdv/lib}/components/virtual-list/src/virtual-list.vue.d.ts +0 -0
- /package/{lib → antdv/lib}/components/virtual-list/src/virtual-list.vue.js +0 -0
- /package/{lib → antdv/lib}/components/virtual-list/src/virtual-list.vue.js.map +0 -0
- /package/{lib → antdv/lib}/components/virtual-list/src/virtual-list.vue2.js +0 -0
- /package/{lib → antdv/lib}/components/virtual-list/src/virtual-list.vue2.js.map +0 -0
- /package/{lib → antdv/lib}/hooks/use-namespace/index.d.ts +0 -0
- /package/{lib → antdv/lib}/hooks/use-namespace/index.js +0 -0
- /package/{lib → antdv/lib}/hooks/use-namespace/index.js.map +0 -0
- /package/{lib → antdv/lib}/index.d.ts +0 -0
- /package/{lib → antdv/lib}/index.js +0 -0
- /package/{lib → antdv/lib}/index.js.map +0 -0
- /package/{lib → antdv/lib}/installer.d.ts +0 -0
- /package/{lib → antdv/lib}/installer.js +0 -0
- /package/{lib → antdv/lib}/installer.js.map +0 -0
- /package/{theme-chalk → antdv/theme-chalk}/base.css +0 -0
- /package/{theme-chalk → antdv/theme-chalk}/buttons.css +0 -0
- /package/{theme-chalk → antdv/theme-chalk}/index.css +0 -0
- /package/{theme-chalk → antdv/theme-chalk}/reset.css +0 -0
- /package/{theme-chalk → antdv/theme-chalk}/scroll-bar.css +0 -0
- /package/{theme-chalk → antdv/theme-chalk}/var.css +0 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@king-one/antdv",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"description": "",
|
|
6
|
+
"author": "",
|
|
7
|
+
"license": "ISC",
|
|
8
|
+
"keywords": [],
|
|
9
|
+
"main": "lib/index.js",
|
|
10
|
+
"module": "es/index.mjs",
|
|
11
|
+
"types": "es/index.d.ts",
|
|
12
|
+
"scripts": {
|
|
13
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
14
|
+
},
|
|
15
|
+
"peerDependencies": {
|
|
16
|
+
"ant-design-vue": "^4.2.4",
|
|
17
|
+
"async-validator": "^4.2.5",
|
|
18
|
+
"vue": "^3.4.34"
|
|
19
|
+
},
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public",
|
|
22
|
+
"registry": "https://registry.npmjs.org/"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@king-one/utils": "workspace:^",
|
|
26
|
+
"evtd": "^0.2.4",
|
|
27
|
+
"vueuc": "^0.4.64"
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @Description:
|
|
3
|
+
* @Version: 2.0
|
|
4
|
+
* @Autor: caohao
|
|
5
|
+
* @Date: 2024-09-16 17:25:58
|
|
6
|
+
* @LastEditors: caohao
|
|
7
|
+
* @LastEditTime: 2024-09-16 22:46:07
|
|
8
|
+
*/
|
|
9
|
+
import type {
|
|
10
|
+
RuleItem
|
|
11
|
+
} from 'async-validator'
|
|
12
|
+
import type { PropType } from 'vue'
|
|
13
|
+
|
|
14
|
+
export const formType = {
|
|
15
|
+
model: {
|
|
16
|
+
type: Object
|
|
17
|
+
},
|
|
18
|
+
rules: {
|
|
19
|
+
type: Object as PropType<Record<string, RuleItem[]>>
|
|
20
|
+
}
|
|
21
|
+
} as const
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
* @Description:
|
|
3
|
+
* @Version: 2.0
|
|
4
|
+
* @Autor: caohao
|
|
5
|
+
* @Date: 2024-09-16 17:25:53
|
|
6
|
+
* @LastEditors: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
|
|
7
|
+
* @LastEditTime: 2024-10-15 16:47:20
|
|
8
|
+
-->
|
|
9
|
+
<script setup lang='ts'>
|
|
10
|
+
import { formType } from './form'
|
|
11
|
+
|
|
12
|
+
defineProps(formType)
|
|
13
|
+
</script>
|
|
14
|
+
|
|
15
|
+
<template>
|
|
16
|
+
<form class="king-form">
|
|
17
|
+
<div>伟大的好歌</div>
|
|
18
|
+
<slot />
|
|
19
|
+
</form>
|
|
20
|
+
</template>
|
|
21
|
+
|
|
22
|
+
<style>
|
|
23
|
+
|
|
24
|
+
</style>
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
<!-- eslint-disable no-console -->
|
|
2
|
+
<script lang="ts" setup>
|
|
3
|
+
import type { TableProps } from 'ant-design-vue'
|
|
4
|
+
|
|
5
|
+
const columns: TableProps['columns'] = [
|
|
6
|
+
{
|
|
7
|
+
title: 'Name',
|
|
8
|
+
dataIndex: 'name',
|
|
9
|
+
filters: [
|
|
10
|
+
{
|
|
11
|
+
text: 'Joe',
|
|
12
|
+
value: 'Joe'
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
text: 'Category 1',
|
|
16
|
+
value: 'Category 1',
|
|
17
|
+
children: [
|
|
18
|
+
{
|
|
19
|
+
text: 'Yellow',
|
|
20
|
+
value: 'Yellow'
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
text: 'Pink',
|
|
24
|
+
value: 'Pink'
|
|
25
|
+
}
|
|
26
|
+
]
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
text: 'Category 2',
|
|
30
|
+
value: 'Category 2',
|
|
31
|
+
children: [
|
|
32
|
+
{
|
|
33
|
+
text: 'Green',
|
|
34
|
+
value: 'Green'
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
text: 'Black',
|
|
38
|
+
value: 'Black'
|
|
39
|
+
}
|
|
40
|
+
]
|
|
41
|
+
}
|
|
42
|
+
],
|
|
43
|
+
filterMode: 'tree',
|
|
44
|
+
filterSearch: true,
|
|
45
|
+
onFilter: (value, record) => record.name.includes(value),
|
|
46
|
+
width: '30%'
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
title: 'Age',
|
|
50
|
+
dataIndex: 'age',
|
|
51
|
+
sorter: (a, b) => a.age - b.age
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
title: 'Address',
|
|
55
|
+
dataIndex: 'address',
|
|
56
|
+
filters: [
|
|
57
|
+
{
|
|
58
|
+
text: 'London',
|
|
59
|
+
value: 'London'
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
text: 'New York',
|
|
63
|
+
value: 'New York'
|
|
64
|
+
}
|
|
65
|
+
],
|
|
66
|
+
onFilter: (value, record) => record.address.startsWith(value),
|
|
67
|
+
filterSearch: true,
|
|
68
|
+
width: '40%'
|
|
69
|
+
}
|
|
70
|
+
]
|
|
71
|
+
|
|
72
|
+
const data = [
|
|
73
|
+
{
|
|
74
|
+
key: '1',
|
|
75
|
+
name: 'John Brown',
|
|
76
|
+
age: 32,
|
|
77
|
+
address: 'New York No. 1 Lake Park'
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
key: '2',
|
|
81
|
+
name: 'Jim Green',
|
|
82
|
+
age: 42,
|
|
83
|
+
address: 'London No. 1 Lake Park'
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
key: '3',
|
|
87
|
+
name: 'Joe Black',
|
|
88
|
+
age: 32,
|
|
89
|
+
address: 'Sidney No. 1 Lake Park'
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
key: '4',
|
|
93
|
+
name: 'Jim Red',
|
|
94
|
+
age: 32,
|
|
95
|
+
address: 'London No. 2 Lake Park'
|
|
96
|
+
}
|
|
97
|
+
]
|
|
98
|
+
|
|
99
|
+
function onChange(pagination, filters, sorter, extra) {
|
|
100
|
+
console.log('params', pagination, filters, sorter, extra)
|
|
101
|
+
}
|
|
102
|
+
</script>
|
|
103
|
+
|
|
104
|
+
<template>
|
|
105
|
+
<a-table :columns="columns" :data-source="data" @change="onChange" />
|
|
106
|
+
</template>
|
|
File without changes
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @Description:
|
|
3
|
+
* @Version: 2.0
|
|
4
|
+
* @Autor: caohao
|
|
5
|
+
* @Date: 2024-09-17 00:26:48
|
|
6
|
+
* @LastEditors: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
|
|
7
|
+
* @LastEditTime: 2024-10-15 15:49:07
|
|
8
|
+
*/
|
|
9
|
+
export * from './form'
|
|
10
|
+
export * from './virtual-list'
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import { computed, defineComponent, onMounted, ref } from 'vue'
|
|
2
|
+
import { VResizeObserver } from 'vueuc'
|
|
3
|
+
import { off, on } from 'evtd'
|
|
4
|
+
import { defaultNamespace } from '@king-one/antdv/hooks/use-namespace'
|
|
5
|
+
import { scrollbarProps } from './types'
|
|
6
|
+
|
|
7
|
+
export default defineComponent({
|
|
8
|
+
name: 'KScrollbar',
|
|
9
|
+
props: scrollbarProps,
|
|
10
|
+
inheritAttrs: false,
|
|
11
|
+
setup(props) {
|
|
12
|
+
onMounted(() => {
|
|
13
|
+
if (props.container)
|
|
14
|
+
return
|
|
15
|
+
sync()
|
|
16
|
+
})
|
|
17
|
+
const handleContentResize = () => {
|
|
18
|
+
sync()
|
|
19
|
+
}
|
|
20
|
+
const handleContainerResize = () => {
|
|
21
|
+
sync()
|
|
22
|
+
}
|
|
23
|
+
const contentRef = ref<HTMLElement | null>(null)
|
|
24
|
+
const containerRef = ref<HTMLElement | null>(null)
|
|
25
|
+
const yRailRef = ref<HTMLElement | null>(null)
|
|
26
|
+
const contentHeightRef = ref<Nullable<number>>(null)
|
|
27
|
+
const contentWidthRef = ref<Nullable<number>>(null)
|
|
28
|
+
const containerHeightRef = ref<Nullable<number>>(null)
|
|
29
|
+
const containerWidthRef = ref<Nullable<number>>(null)
|
|
30
|
+
const yRailSizeRef = ref<Nullable<number>>(null)
|
|
31
|
+
const mergedContentRef = computed(() => props.content?.() || contentRef.value)
|
|
32
|
+
const mergedContainerRef = computed(() => props.container?.() || containerRef.value)
|
|
33
|
+
const containerScrollTopRef = ref(0)
|
|
34
|
+
const yBarSizeRef = computed(() => {
|
|
35
|
+
const { value: containerHeight } = containerHeightRef
|
|
36
|
+
const { value: contentHeight } = contentHeightRef
|
|
37
|
+
const { value: yRailSize } = yRailSizeRef
|
|
38
|
+
if (containerHeight === null || contentHeight === null || yRailSize === null) {
|
|
39
|
+
return 0
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
return Math.min(containerHeight, (yRailSize * containerHeight) / contentHeight + 5 * 1.5)
|
|
43
|
+
}
|
|
44
|
+
})
|
|
45
|
+
const yBarTopRef = computed(() => {
|
|
46
|
+
const { value: containerHeight } = containerHeightRef
|
|
47
|
+
const { value: containerScrollTop } = containerScrollTopRef
|
|
48
|
+
const { value: contentHeight } = contentHeightRef
|
|
49
|
+
const { value: yRailSize } = yRailSizeRef
|
|
50
|
+
if (containerHeight === null || contentHeight === null || yRailSize === null) {
|
|
51
|
+
return 0
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
const heightDiff = contentHeight - containerHeight
|
|
55
|
+
if (!heightDiff)
|
|
56
|
+
return 0
|
|
57
|
+
return (containerScrollTop / heightDiff) * (yRailSize - yBarSizeRef.value)
|
|
58
|
+
}
|
|
59
|
+
})
|
|
60
|
+
const yBarTopPxRef = computed(() => {
|
|
61
|
+
return `${yBarTopRef.value}px`
|
|
62
|
+
})
|
|
63
|
+
const needYBarRef = computed(() => {
|
|
64
|
+
const { value: containerHeight } = containerHeightRef
|
|
65
|
+
const { value: contentHeight } = contentHeightRef
|
|
66
|
+
return containerHeight !== null && contentHeight !== null && contentHeight > containerHeight
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
const yBarSizePxRef = computed(() => {
|
|
70
|
+
return `${yBarSizeRef.value}px`
|
|
71
|
+
})
|
|
72
|
+
const syncPositionState = () => {
|
|
73
|
+
const { value: content } = mergedContentRef
|
|
74
|
+
if (content) {
|
|
75
|
+
contentHeightRef.value = content.offsetHeight
|
|
76
|
+
contentWidthRef.value = content.offsetWidth
|
|
77
|
+
}
|
|
78
|
+
const { value: container } = mergedContainerRef
|
|
79
|
+
if (container) {
|
|
80
|
+
containerHeightRef.value = container.offsetHeight
|
|
81
|
+
containerWidthRef.value = container.offsetWidth
|
|
82
|
+
}
|
|
83
|
+
const { value: yRailEl } = yRailRef
|
|
84
|
+
if (yRailEl) {
|
|
85
|
+
yRailSizeRef.value = yRailEl.offsetHeight
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
let yBarPressed = false
|
|
89
|
+
let memoYTop: number = 0
|
|
90
|
+
let memoMouseY: number = 0
|
|
91
|
+
let yBarVanishTimerId: number | undefined
|
|
92
|
+
|
|
93
|
+
const handleYScrollMouseMove = (e: MouseEvent) => {
|
|
94
|
+
if (!yBarPressed)
|
|
95
|
+
return
|
|
96
|
+
|
|
97
|
+
if (yBarVanishTimerId !== undefined) {
|
|
98
|
+
window.clearTimeout(yBarVanishTimerId)
|
|
99
|
+
}
|
|
100
|
+
const { value: containerHeight } = containerHeightRef
|
|
101
|
+
const { value: contentHeight } = contentHeightRef
|
|
102
|
+
const { value: yBarSize } = yBarSizeRef
|
|
103
|
+
if (containerHeight === null || contentHeight === null)
|
|
104
|
+
return
|
|
105
|
+
const dY = e.clientY - memoMouseY
|
|
106
|
+
const dScrollTop = (dY * (contentHeight - containerHeight)) / (containerHeight - yBarSize)
|
|
107
|
+
const toScrollTopUpperBound = contentHeight - containerHeight
|
|
108
|
+
let toScrollTop = memoYTop + dScrollTop
|
|
109
|
+
toScrollTop = Math.min(toScrollTopUpperBound, toScrollTop)
|
|
110
|
+
toScrollTop = Math.max(toScrollTop, 0)
|
|
111
|
+
const { value: container } = mergedContainerRef
|
|
112
|
+
if (container) {
|
|
113
|
+
container.scrollTop = toScrollTop
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
const handleYScrollMouseUp = (e: MouseEvent) => {
|
|
117
|
+
e.preventDefault()
|
|
118
|
+
e.stopPropagation()
|
|
119
|
+
off('mousemove', window, handleYScrollMouseMove, true)
|
|
120
|
+
off('mouseup', window, handleYScrollMouseUp, true)
|
|
121
|
+
yBarPressed = false
|
|
122
|
+
sync()
|
|
123
|
+
}
|
|
124
|
+
const handleYScrollMouseDown = (e: MouseEvent) => {
|
|
125
|
+
e.preventDefault()
|
|
126
|
+
e.stopPropagation()
|
|
127
|
+
on('mousemove', window, handleYScrollMouseMove, true)
|
|
128
|
+
on('mouseup', window, handleYScrollMouseUp, true)
|
|
129
|
+
memoYTop = containerScrollTopRef.value
|
|
130
|
+
memoMouseY = e.clientY
|
|
131
|
+
yBarPressed = true
|
|
132
|
+
}
|
|
133
|
+
function handleScroll(e: Event): void {
|
|
134
|
+
const { onScroll } = props
|
|
135
|
+
if (onScroll)
|
|
136
|
+
onScroll(e)
|
|
137
|
+
syncScrollState()
|
|
138
|
+
}
|
|
139
|
+
function syncScrollState(): void {
|
|
140
|
+
// only collect scroll state, do not trigger any dom event
|
|
141
|
+
const { value: container } = mergedContainerRef
|
|
142
|
+
if (container) {
|
|
143
|
+
containerScrollTopRef.value = container.scrollTop
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
function sync(): void {
|
|
147
|
+
syncPositionState()
|
|
148
|
+
syncScrollState()
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return {
|
|
152
|
+
sync,
|
|
153
|
+
handleContentResize,
|
|
154
|
+
handleContainerResize,
|
|
155
|
+
contentRef,
|
|
156
|
+
yRailRef,
|
|
157
|
+
containerRef,
|
|
158
|
+
contentHeightRef,
|
|
159
|
+
containerHeightRef,
|
|
160
|
+
needYBarRef,
|
|
161
|
+
yBarSizePxRef,
|
|
162
|
+
handleYScrollMouseDown,
|
|
163
|
+
yBarTopPxRef,
|
|
164
|
+
handleScroll
|
|
165
|
+
}
|
|
166
|
+
},
|
|
167
|
+
render() {
|
|
168
|
+
const { $slots } = this
|
|
169
|
+
const createYBar = () => {
|
|
170
|
+
return (
|
|
171
|
+
<div class={`${defaultNamespace}-scrollbar-rail`} ref="yRailRef">
|
|
172
|
+
{this.needYBarRef && (
|
|
173
|
+
<div
|
|
174
|
+
class={`${defaultNamespace}-scrollbar-rail__scrollbar`}
|
|
175
|
+
style={{
|
|
176
|
+
height: this.yBarSizePxRef,
|
|
177
|
+
top: this.yBarTopPxRef
|
|
178
|
+
}}
|
|
179
|
+
onMousedown={this.handleYScrollMouseDown}
|
|
180
|
+
>
|
|
181
|
+
</div>
|
|
182
|
+
)}
|
|
183
|
+
</div>
|
|
184
|
+
)
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const createChildren = () => {
|
|
188
|
+
return (
|
|
189
|
+
<div class={`${defaultNamespace}-scrollbar`} {...this.$attrs}>
|
|
190
|
+
{this.container
|
|
191
|
+
? (
|
|
192
|
+
$slots.default?.()
|
|
193
|
+
)
|
|
194
|
+
: (
|
|
195
|
+
<div class={`${defaultNamespace}-scrollbar-container`} onScroll={this.handleScroll} ref="containerRef">
|
|
196
|
+
<VResizeObserver onResize={this.handleContentResize}>
|
|
197
|
+
<div ref="contentRef" class={`${defaultNamespace}-scrollbar-content`}>
|
|
198
|
+
{$slots.default?.()}
|
|
199
|
+
</div>
|
|
200
|
+
</VResizeObserver>
|
|
201
|
+
</div>
|
|
202
|
+
)}
|
|
203
|
+
|
|
204
|
+
{createYBar()}
|
|
205
|
+
</div>
|
|
206
|
+
)
|
|
207
|
+
}
|
|
208
|
+
const createBarNode = this.container ? createChildren() : <VResizeObserver onResize={this.handleContainerResize}>{createChildren()}</VResizeObserver>
|
|
209
|
+
return createBarNode
|
|
210
|
+
}
|
|
211
|
+
})
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { PropType } from 'vue'
|
|
2
|
+
|
|
3
|
+
export const scrollbarProps = {
|
|
4
|
+
container: Function as PropType<() => HTMLElement | null | undefined>,
|
|
5
|
+
content: Function as PropType<() => HTMLElement | null | undefined>,
|
|
6
|
+
onScroll: Function as PropType<(e: Event) => void>
|
|
7
|
+
} as const
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @Description:
|
|
3
|
+
* @Version: 2.0
|
|
4
|
+
* @Autor: caohao
|
|
5
|
+
* @Date: 2024-09-17 00:15:40
|
|
6
|
+
* @LastEditors: caohao
|
|
7
|
+
* @LastEditTime: 2024-09-17 00:15:43
|
|
8
|
+
*/
|
|
9
|
+
import type { App, Directive, Plugin } from 'vue'
|
|
10
|
+
|
|
11
|
+
export type SFCWithInstall<T> = T & Plugin
|
|
12
|
+
|
|
13
|
+
const defaultNamePrefix: string = 'K'
|
|
14
|
+
export function withInstall<T>(main: T) {
|
|
15
|
+
(main as SFCWithInstall<T>).install = (app): void => {
|
|
16
|
+
const comp: Record<string, any> = main as Record<string, any>
|
|
17
|
+
app.component(defaultNamePrefix + comp.name, comp)
|
|
18
|
+
}
|
|
19
|
+
return main as SFCWithInstall<T>
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// 注册指令
|
|
23
|
+
export function withInstallDirectives<T extends Directive>(main: T, name: string) {
|
|
24
|
+
return {
|
|
25
|
+
install: (app: App): void => {
|
|
26
|
+
app.directive(name, main)
|
|
27
|
+
},
|
|
28
|
+
directive: main
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { VirtualListItemData } from 'vueuc'
|
|
2
|
+
import type { PropType } from 'vue'
|
|
3
|
+
|
|
4
|
+
export const virtualListProps = {
|
|
5
|
+
items: {
|
|
6
|
+
type: Array as PropType<VirtualListItemData[]>,
|
|
7
|
+
default: () => []
|
|
8
|
+
},
|
|
9
|
+
itemSize: {
|
|
10
|
+
type: Number,
|
|
11
|
+
required: true
|
|
12
|
+
},
|
|
13
|
+
itemResizable: Boolean,
|
|
14
|
+
paddingTop: {
|
|
15
|
+
type: [Number, String] as PropType<number | string>,
|
|
16
|
+
default: 0
|
|
17
|
+
},
|
|
18
|
+
paddingBottom: {
|
|
19
|
+
type: [Number, String] as PropType<number | string>,
|
|
20
|
+
default: 0
|
|
21
|
+
},
|
|
22
|
+
keyField: {
|
|
23
|
+
type: String,
|
|
24
|
+
default: 'key'
|
|
25
|
+
},
|
|
26
|
+
onScroll: Function as PropType<() => void>,
|
|
27
|
+
onWheel: Function as PropType<(event: WheelEvent) => void>,
|
|
28
|
+
onResize: Function as PropType<(entry: ResizeObserverEntry) => void>
|
|
29
|
+
} as const
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { ref } from 'vue'
|
|
3
|
+
import { VVirtualList, type VirtualListInst } from 'vueuc'
|
|
4
|
+
import scrollbar from '../../scroll-bar'
|
|
5
|
+
import { virtualListProps } from './types'
|
|
6
|
+
|
|
7
|
+
const props = defineProps(virtualListProps)
|
|
8
|
+
const virtualListInstRef = ref<VirtualListInst | null>(null)
|
|
9
|
+
const scrollbarInstRef = ref<InstanceType<typeof scrollbar> | null>(null)
|
|
10
|
+
function getScrollContainer(): HTMLElement | null | undefined {
|
|
11
|
+
return virtualListInstRef.value?.listElRef
|
|
12
|
+
}
|
|
13
|
+
function getScrollContent(): HTMLElement | null | undefined {
|
|
14
|
+
return virtualListInstRef.value?.itemsElRef
|
|
15
|
+
}
|
|
16
|
+
const syncScrollbar = () => scrollbarInstRef.value?.sync()
|
|
17
|
+
function handleScroll() {
|
|
18
|
+
props.onScroll?.()
|
|
19
|
+
syncScrollbar()
|
|
20
|
+
}
|
|
21
|
+
function handleResize() {
|
|
22
|
+
syncScrollbar()
|
|
23
|
+
}
|
|
24
|
+
</script>
|
|
25
|
+
|
|
26
|
+
<template>
|
|
27
|
+
<scrollbar ref="scrollbarInstRef" style="max-height: 300px" :container="getScrollContainer" :content="getScrollContent">
|
|
28
|
+
<VVirtualList
|
|
29
|
+
ref="virtualListInstRef"
|
|
30
|
+
:items="items"
|
|
31
|
+
style="height: 100%"
|
|
32
|
+
:item-size="itemSize"
|
|
33
|
+
:item-resizable="itemResizable"
|
|
34
|
+
:show-scrollbar="false"
|
|
35
|
+
:padding-bottom="paddingBottom"
|
|
36
|
+
:padding-top="paddingTop"
|
|
37
|
+
:on-scroll="handleScroll"
|
|
38
|
+
:on-resize="handleResize"
|
|
39
|
+
>
|
|
40
|
+
<template #default="{ item, index }">
|
|
41
|
+
<slot :item="item" :index="index" />
|
|
42
|
+
</template>
|
|
43
|
+
</VVirtualList>
|
|
44
|
+
</scrollbar>
|
|
45
|
+
</template>
|
|
46
|
+
|
|
47
|
+
<style></style>
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { computed, getCurrentInstance, inject, ref, unref } from 'vue'
|
|
2
|
+
|
|
3
|
+
import type { InjectionKey, Ref } from 'vue'
|
|
4
|
+
|
|
5
|
+
export const defaultNamespace = 'king'
|
|
6
|
+
const statePrefix = 'is-'
|
|
7
|
+
|
|
8
|
+
function _bem(namespace: string, block: string, blockSuffix: string, element: string, modifier: string) {
|
|
9
|
+
let cls = `${namespace}-${block}`
|
|
10
|
+
if (blockSuffix) {
|
|
11
|
+
cls += `-${blockSuffix}`
|
|
12
|
+
}
|
|
13
|
+
if (element) {
|
|
14
|
+
cls += `__${element}`
|
|
15
|
+
}
|
|
16
|
+
if (modifier) {
|
|
17
|
+
cls += `--${modifier}`
|
|
18
|
+
}
|
|
19
|
+
return cls
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const namespaceContextKey: InjectionKey<Ref<string | undefined>> = Symbol('namespaceContextKey')
|
|
23
|
+
|
|
24
|
+
export function useGetDerivedNamespace(namespaceOverrides?: Ref<string | undefined>) {
|
|
25
|
+
const derivedNamespace = namespaceOverrides || (getCurrentInstance() ? inject(namespaceContextKey, ref(defaultNamespace)) : ref(defaultNamespace))
|
|
26
|
+
const namespace = computed(() => {
|
|
27
|
+
return unref(derivedNamespace) || defaultNamespace
|
|
28
|
+
})
|
|
29
|
+
return namespace
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function useNamespace(block: string, namespaceOverrides?: Ref<string | undefined>) {
|
|
33
|
+
const namespace = useGetDerivedNamespace(namespaceOverrides)
|
|
34
|
+
const b = (blockSuffix = '') => _bem(namespace.value, block, blockSuffix, '', '')
|
|
35
|
+
const e = (element?: string) => (element ? _bem(namespace.value, block, '', element, '') : '')
|
|
36
|
+
const m = (modifier?: string) => (modifier ? _bem(namespace.value, block, '', '', modifier) : '')
|
|
37
|
+
const be = (blockSuffix?: string, element?: string) => (blockSuffix && element ? _bem(namespace.value, block, blockSuffix, element, '') : '')
|
|
38
|
+
const em = (element?: string, modifier?: string) => (element && modifier ? _bem(namespace.value, block, '', element, modifier) : '')
|
|
39
|
+
const bm = (blockSuffix?: string, modifier?: string) => (blockSuffix && modifier ? _bem(namespace.value, block, blockSuffix, '', modifier) : '')
|
|
40
|
+
const bem = (blockSuffix?: string, element?: string, modifier?: string) =>
|
|
41
|
+
blockSuffix && element && modifier ? _bem(namespace.value, block, blockSuffix, element, modifier) : ''
|
|
42
|
+
const is: {
|
|
43
|
+
(name: string, state: boolean | undefined): string
|
|
44
|
+
(name: string): string
|
|
45
|
+
} = (name: string, ...args: [boolean | undefined] | []) => {
|
|
46
|
+
const state = args.length >= 1 ? args[0]! : true
|
|
47
|
+
return name && state ? `${statePrefix}${name}` : ''
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// for css var
|
|
51
|
+
// --el-xxx: value;
|
|
52
|
+
const cssVar = (object: Record<string, string>) => {
|
|
53
|
+
const styles: Record<string, string> = {}
|
|
54
|
+
for (const key in object) {
|
|
55
|
+
if (object[key]) {
|
|
56
|
+
styles[`--${namespace.value}-${key}`] = object[key]
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return styles
|
|
60
|
+
}
|
|
61
|
+
// with block
|
|
62
|
+
const cssVarBlock = (object: Record<string, string>) => {
|
|
63
|
+
const styles: Record<string, string> = {}
|
|
64
|
+
for (const key in object) {
|
|
65
|
+
if (object[key]) {
|
|
66
|
+
styles[`--${namespace.value}-${block}-${key}`] = object[key]
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return styles
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const cssVarName = (name: string) => `--${namespace.value}-${name}`
|
|
73
|
+
const cssVarBlockName = (name: string) => `--${namespace.value}-${block}-${name}`
|
|
74
|
+
|
|
75
|
+
return {
|
|
76
|
+
namespace,
|
|
77
|
+
b,
|
|
78
|
+
e,
|
|
79
|
+
m,
|
|
80
|
+
be,
|
|
81
|
+
em,
|
|
82
|
+
bm,
|
|
83
|
+
bem,
|
|
84
|
+
is,
|
|
85
|
+
// css
|
|
86
|
+
cssVar,
|
|
87
|
+
cssVarName,
|
|
88
|
+
cssVarBlock,
|
|
89
|
+
cssVarBlockName
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export type UseNamespaceReturn = ReturnType<typeof useNamespace>
|
package/index.ts
ADDED