@teammodlr/ui-kit 2.1.41 → 2.1.43
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/env.d.ts +1 -1
- package/lib/components/checkbox/Checkbox.vue.d.ts +1 -0
- package/lib/components/checkbox/style/Checkbox.css.d.ts +1 -0
- package/lib/index.cjs.js +8 -8
- package/lib/index.es.js +1352 -1342
- package/lib/nuxt.js +35 -35
- package/lib/nuxt.plugin.js +8 -8
- package/lib/style.css +1 -1
- package/package.json +89 -89
- package/src/__storybook__/argTypes.ts +53 -53
- package/src/__storybook__/createStory.ts +15 -15
- package/src/__storybook__/index.ts +2 -2
- package/src/call.ts +34 -34
- package/src/components/avatar/Avatar.vue +110 -110
- package/src/components/avatar/examples/basic.vue +6 -6
- package/src/components/avatar/examples/custom-size.vue +7 -7
- package/src/components/avatar/examples/index.ts +5 -5
- package/src/components/avatar/examples/sizes.vue +33 -33
- package/src/components/avatar/examples/slots.vue +8 -8
- package/src/components/avatar/examples/variants.vue +18 -18
- package/src/components/avatar/style/Avatar.css.ts +92 -92
- package/src/components/avatar/style/index.ts +1 -1
- package/src/components/avatargroup/AvatarGroup.vue +72 -72
- package/src/components/avatargroup/examples/basic.vue +37 -37
- package/src/components/avatargroup/examples/index.ts +1 -1
- package/src/components/avatargroup/style/AvatarGroup.css.ts +26 -26
- package/src/components/avatargroup/style/index.ts +1 -1
- package/src/components/avatargroup/symbol.ts +17 -17
- package/src/components/badge/Badge.vue +43 -43
- package/src/components/badge/examples/basic.vue +10 -10
- package/src/components/badge/examples/index.ts +1 -1
- package/src/components/badge/style/Badge.css.ts +135 -135
- package/src/components/badge/style/index.ts +1 -1
- package/src/components/breadcrumb/Breadcrumb.vue +54 -54
- package/src/components/breadcrumb/BreadcrumbItem.vue +72 -72
- package/src/components/breadcrumb/examples/basic.vue +7 -7
- package/src/components/breadcrumb/examples/index.ts +1 -1
- package/src/components/breadcrumb/style/Breadcrumb.css.ts +40 -40
- package/src/components/breadcrumb/style/index.ts +1 -1
- package/src/components/breadcrumb/symbol.ts +18 -18
- package/src/components/button/Button.vue +203 -203
- package/src/components/button/examples/basic.vue +3 -3
- package/src/components/button/examples/disabled.vue +3 -3
- package/src/components/button/examples/icon-left.vue +12 -12
- package/src/components/button/examples/icon.vue +9 -9
- package/src/components/button/examples/index.ts +9 -9
- package/src/components/button/examples/link.vue +3 -3
- package/src/components/button/examples/rounded.vue +7 -7
- package/src/components/button/examples/size.vue +7 -7
- package/src/components/button/examples/variants-secondary.vue +10 -10
- package/src/components/button/examples/variants.vue +10 -10
- package/src/components/button/style/Button.css.ts +695 -695
- package/src/components/button/style/index.ts +1 -1
- package/src/components/buttongroup/ButtonGroup.vue +36 -36
- package/src/components/buttongroup/examples/basic.vue +9 -9
- package/src/components/buttongroup/examples/icon-group.vue +21 -21
- package/src/components/buttongroup/examples/index.ts +2 -2
- package/src/components/buttongroup/style/ButtonGroup.css.ts +42 -42
- package/src/components/buttongroup/style/index.ts +1 -1
- package/src/components/buttongroup/symbol.ts +9 -9
- package/src/components/checkbox/Checkbox.vue +149 -145
- package/src/components/checkbox/examples/basic.vue +9 -9
- package/src/components/checkbox/examples/index.ts +2 -2
- package/src/components/checkbox/examples/slot.vue +14 -11
- package/src/components/checkbox/style/Checkbox.css.ts +178 -161
- package/src/components/checkbox/style/index.ts +1 -1
- package/src/components/colorpicker/ColorPicker.vue +333 -333
- package/src/components/colorpicker/examples/basic.vue +2 -2
- package/src/components/colorpicker/examples/index.ts +1 -1
- package/src/components/colorpicker/style/ColorPicker.css.ts +127 -127
- package/src/components/colorpicker/style/index.ts +1 -1
- package/src/components/colorpicker/utils.ts +206 -206
- package/src/components/confirm/Confirm.vue +65 -65
- package/src/components/confirm/ConfirmProvider.vue +83 -83
- package/src/components/confirm/examples/basic.vue +48 -48
- package/src/components/confirm/examples/index.ts +1 -1
- package/src/components/confirm/examples/wrapper.vue +9 -9
- package/src/components/confirm/props.ts +24 -24
- package/src/components/confirm/providerProps.ts +10 -10
- package/src/components/confirm/types.ts +33 -33
- package/src/components/confirm/useConfirm.ts +14 -14
- package/src/components/dialog/Dialog.vue +118 -118
- package/src/components/dialog/examples/basic.vue +16 -16
- package/src/components/dialog/examples/index.ts +1 -1
- package/src/components/dialog/style/Dialog.css.ts +100 -100
- package/src/components/dialog/style/index.ts +1 -1
- package/src/components/dropdown/Dropdown.vue +308 -308
- package/src/components/dropdown/DropdownHeading.vue +23 -23
- package/src/components/dropdown/DropdownItem.vue +151 -151
- package/src/components/dropdown/DropdownList.vue +20 -20
- package/src/components/dropdown/DropdownSeperator.vue +22 -22
- package/src/components/dropdown/DropdownWrapper.vue +18 -18
- package/src/components/dropdown/examples/basic.vue +119 -119
- package/src/components/dropdown/examples/context.vue +71 -71
- package/src/components/dropdown/examples/index.ts +3 -3
- package/src/components/dropdown/hooks.ts +30 -30
- package/src/components/dropdown/style/Dropdown.css.ts +158 -158
- package/src/components/dropdown/style/index.ts +1 -1
- package/src/components/dropdown/symbol.ts +9 -9
- package/src/components/form/Form.vue +153 -153
- package/src/components/form/examples/basic.vue +75 -75
- package/src/components/form/examples/index.ts +1 -1
- package/src/components/form/style/Form.css.ts +28 -28
- package/src/components/form/style/index.ts +2 -2
- package/src/components/form/symbol.ts +16 -16
- package/src/components/image/Image.vue +71 -71
- package/src/components/image/examples/basic.vue +5 -5
- package/src/components/image/examples/index.ts +1 -1
- package/src/components/index.ts +47 -47
- package/src/components/input/Input.vue +233 -233
- package/src/components/input/examples/basic.vue +21 -21
- package/src/components/input/examples/index.ts +6 -6
- package/src/components/input/examples/left-icon.vue +9 -9
- package/src/components/input/examples/prefix.vue +5 -5
- package/src/components/input/examples/right-icon.vue +9 -9
- package/src/components/input/examples/sizes.vue +9 -9
- package/src/components/input/examples/suffix.vue +7 -7
- package/src/components/input/style/Input.css.ts +294 -294
- package/src/components/input/style/index.ts +1 -1
- package/src/components/link/Link.vue +53 -53
- package/src/components/link/examples/basic.vue +3 -3
- package/src/components/link/examples/index.ts +1 -1
- package/src/components/messageprovider/Message.vue +135 -135
- package/src/components/messageprovider/MessageProvider.vue +156 -156
- package/src/components/messageprovider/examples/basic.vue +70 -70
- package/src/components/messageprovider/examples/index.ts +2 -2
- package/src/components/messageprovider/examples/update.vue +34 -34
- package/src/components/messageprovider/examples/wrapper.vue +9 -9
- package/src/components/messageprovider/style/Message.css.ts +111 -111
- package/src/components/messageprovider/style/index.ts +1 -1
- package/src/components/messageprovider/types.ts +56 -56
- package/src/components/messageprovider/useMessage.ts +14 -14
- package/src/components/modal/Modal.vue +310 -310
- package/src/components/modal/examples/basic.vue +80 -80
- package/src/components/modal/examples/index.ts +3 -3
- package/src/components/modal/examples/modal-form.vue +99 -99
- package/src/components/modal/examples/sidebar.vue +79 -79
- package/src/components/modal/style/Modal.css.ts +318 -318
- package/src/components/modal/style/index.ts +1 -1
- package/src/components/pagination/Pagination.vue +296 -296
- package/src/components/pagination/examples/basic.vue +17 -17
- package/src/components/pagination/examples/index.ts +1 -1
- package/src/components/pagination/style/Pagination.css.ts +93 -93
- package/src/components/pagination/style/index.ts +1 -1
- package/src/components/radio/Radio.vue +136 -136
- package/src/components/radio/examples/basic.vue +8 -8
- package/src/components/radio/examples/group.vue +15 -15
- package/src/components/radio/examples/index.ts +2 -2
- package/src/components/radio/style/Checkbox.css.ts +130 -130
- package/src/components/radio/style/index.ts +1 -1
- package/src/components/radiobutton/RadioButton.vue +131 -131
- package/src/components/radiobutton/style/RadioButton.css.ts +189 -189
- package/src/components/radiobutton/style/index.ts +1 -1
- package/src/components/radiobuttongroup/RadioButtonGroup.vue +74 -74
- package/src/components/radiobuttongroup/examples/basic.vue +16 -16
- package/src/components/radiobuttongroup/examples/index.ts +1 -1
- package/src/components/radiobuttongroup/style/RadioButtonGroup.css.ts +37 -37
- package/src/components/radiobuttongroup/style/index.ts +1 -1
- package/src/components/radiobuttongroup/symbol.ts +12 -12
- package/src/components/renderer/examlpes/basic.vue +23 -23
- package/src/components/renderer/examlpes/index.ts +1 -1
- package/src/components/renderer/props.ts +14 -14
- package/src/components/renderer/renderer.ts +16 -16
- package/src/components/select/Select.vue +781 -781
- package/src/components/select/examples/basic.vue +21 -21
- package/src/components/select/examples/index.ts +3 -3
- package/src/components/select/examples/multiple.vue +21 -21
- package/src/components/select/examples/searchable.vue +20 -20
- package/src/components/select/style/Select.css.ts +368 -368
- package/src/components/select/style/index.ts +1 -1
- package/src/components/skeleton/Skeleton.vue +55 -55
- package/src/components/skeleton/examples/basic.vue +3 -3
- package/src/components/skeleton/examples/index.ts +2 -2
- package/src/components/skeleton/examples/post.vue +8 -8
- package/src/components/skeleton/style/Skeleton.css.ts +72 -72
- package/src/components/skeleton/style/index.ts +2 -2
- package/src/components/slider/Slider.vue +76 -76
- package/src/components/slider/style/Slider.css.ts +50 -50
- package/src/components/slider/style/index.ts +1 -1
- package/src/components/switch/Switch.vue +132 -132
- package/src/components/switch/examples/basic.vue +9 -9
- package/src/components/switch/examples/index.ts +2 -2
- package/src/components/switch/examples/slot.vue +11 -11
- package/src/components/switch/style/Switch.css.ts +135 -135
- package/src/components/switch/style/index.ts +1 -1
- package/src/components/tab/Tab.css +113 -113
- package/src/components/tab/Tab.vue +98 -98
- package/src/components/tab/TabGroup.vue +90 -90
- package/src/components/tab/examples/basic.vue +19 -19
- package/src/components/tab/examples/index.ts +2 -2
- package/src/components/tab/examples/vertical.vue +19 -19
- package/src/components/table/Table.vue +198 -198
- package/src/components/table/TableBody.vue +13 -13
- package/src/components/table/TableCell.vue +13 -13
- package/src/components/table/TableHead.vue +46 -46
- package/src/components/table/TableHeadRow.vue +15 -15
- package/src/components/table/TableRow.vue +19 -19
- package/src/components/table/examples/basic.vue +61 -61
- package/src/components/table/examples/empty.vue +44 -44
- package/src/components/table/examples/index.ts +3 -3
- package/src/components/table/examples/selected.vue +68 -68
- package/src/components/table/style/Table.css.ts +62 -62
- package/src/components/table/style/index.ts +1 -1
- package/src/components/table/types/index.ts +6 -6
- package/src/components/tag/Tag.vue +72 -72
- package/src/components/tag/examples/basic.vue +5 -5
- package/src/components/tag/examples/index.ts +1 -1
- package/src/components/tag/style/Tag.css.ts +83 -83
- package/src/components/tag/style/index.ts +1 -1
- package/src/components/textarea/Textarea.vue +180 -180
- package/src/components/textarea/examples/basic.vue +8 -8
- package/src/components/textarea/examples/index.ts +1 -1
- package/src/components/textarea/style/Textarea.css.ts +191 -191
- package/src/components/textarea/style/index.ts +1 -1
- package/src/components/tooltip/Tooltip.vue +196 -196
- package/src/components/tooltip/examples/basic.vue +5 -5
- package/src/components/tooltip/examples/index.ts +2 -2
- package/src/components/tooltip/examples/placement.vue +9 -9
- package/src/components/tooltip/style/Tooltip.css.ts +90 -90
- package/src/components/tooltip/style/index.ts +1 -1
- package/src/components/transfer/Transfer.vue +145 -145
- package/src/components/transfer/examples/basic.vue +21 -21
- package/src/components/transfer/examples/index.ts +1 -1
- package/src/components/transfer/style/Transfer.css.ts +81 -81
- package/src/components/transfer/style/index.ts +1 -1
- package/src/components/tree/Tree.vue +138 -138
- package/src/components/tree/TreeNode.vue +109 -109
- package/src/components/tree/TreeNodeToggle.vue +48 -48
- package/src/components/tree/examples/basic.vue +458 -458
- package/src/components/tree/examples/index.ts +1 -1
- package/src/components/tree/props.ts +97 -97
- package/src/components/tree/style/Tree.css.ts +75 -75
- package/src/components/tree/style/index.ts +1 -1
- package/src/components/tree/types.ts +103 -103
- package/src/components/virtualscroll/VirtualScroll.css +13 -13
- package/src/components/virtualscroll/VirtualScroll.vue +166 -166
- package/src/components/virtualscroll/examples/basic.vue +31 -31
- package/src/components/virtualscroll/examples/index.ts +1 -1
- package/src/components/virtualscroll/style/VirtualScroll.css.ts +17 -17
- package/src/components/virtualscroll/style/index.ts +1 -1
- package/src/composables/element.ts +13 -13
- package/src/composables/index.ts +4 -4
- package/src/composables/useCachedUid.ts +49 -49
- package/src/composables/useEventListener.ts +19 -19
- package/src/composables/useInput.ts +151 -151
- package/src/composables/useInteractive.ts +19 -19
- package/src/composables/useIsServer.ts +7 -7
- package/src/composables/useMergedState.ts +18 -18
- package/src/composables/useMount.ts +43 -43
- package/src/composables/usePopper.ts +215 -215
- package/src/composables/useZIndex.ts +33 -33
- package/src/create.ts +38 -38
- package/src/css/components.css +16 -16
- package/src/css/index.css +4 -4
- package/src/css/transitions.css +40 -40
- package/src/css/variables.css +80 -80
- package/src/examples/cards/sidebar.vue +262 -262
- package/src/examples/modal/modal.vue +52 -52
- package/src/exports/nuxt.js +35 -35
- package/src/exports/nuxt.plugin.js +8 -8
- package/src/index.ts +5 -5
- package/src/install.ts +8 -8
- package/src/shims-vue.d.ts +6 -6
- package/src/styles/theme.css.ts +181 -181
- package/src/styles/transitions.css.ts +97 -97
- package/src/types/props.ts +19 -19
- package/src/utils/injection.ts +5 -5
- package/volar.d.ts +16 -16
|
@@ -1,167 +1,167 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div
|
|
3
|
-
ref="scroller"
|
|
4
|
-
:class="style.container"
|
|
5
|
-
@scroll.passive="onScroll"
|
|
6
|
-
>
|
|
7
|
-
<div
|
|
8
|
-
ref="contentWrapper"
|
|
9
|
-
:style="{ width: `${totalWidth}px`, height: `${totalHeight}px` }"
|
|
10
|
-
>
|
|
11
|
-
<div
|
|
12
|
-
:style="{ transform: `translate(${offsetX}px, ${offsetY}px)` }"
|
|
13
|
-
>
|
|
14
|
-
<template v-for="(row, rowIndex) in renderedItems" :key="rowIndex">
|
|
15
|
-
<div
|
|
16
|
-
:style="{ display: 'flex' }"
|
|
17
|
-
>
|
|
18
|
-
<template v-for="(item, colIndex) in row" :key="colIndex">
|
|
19
|
-
<div
|
|
20
|
-
:style="{ width: `${itemWidth}px`, height: `${itemHeight}px` }"
|
|
21
|
-
>
|
|
22
|
-
<slot name="item" :item="item" />
|
|
23
|
-
</div>
|
|
24
|
-
</template>
|
|
25
|
-
</div>
|
|
26
|
-
</template>
|
|
27
|
-
</div>
|
|
28
|
-
</div>
|
|
29
|
-
</div>
|
|
30
|
-
</template>
|
|
31
|
-
|
|
32
|
-
<script lang="ts">
|
|
33
|
-
import {defineComponent, computed, onMounted, ref, watchEffect, toRef} from 'vue';
|
|
34
|
-
import * as style from "./style";
|
|
35
|
-
export default defineComponent({
|
|
36
|
-
name: "VirtualScroll",
|
|
37
|
-
props: {
|
|
38
|
-
items: {
|
|
39
|
-
type: Array,
|
|
40
|
-
default: () => []
|
|
41
|
-
},
|
|
42
|
-
itemHeight: {
|
|
43
|
-
type: Number,
|
|
44
|
-
default: 30
|
|
45
|
-
},
|
|
46
|
-
itemWidth: {
|
|
47
|
-
type: Number,
|
|
48
|
-
default: 140
|
|
49
|
-
},
|
|
50
|
-
buffer: {
|
|
51
|
-
type: Number,
|
|
52
|
-
default: 5
|
|
53
|
-
},
|
|
54
|
-
delay: {
|
|
55
|
-
type: Number,
|
|
56
|
-
default: 15
|
|
57
|
-
}
|
|
58
|
-
},
|
|
59
|
-
setup(props, {emit}) {
|
|
60
|
-
const contentWrapper = ref();
|
|
61
|
-
const scroller = ref();
|
|
62
|
-
const scrollerHeight = ref(0);
|
|
63
|
-
const scrollerWidth = ref(0);
|
|
64
|
-
const scrollTop = ref(0);
|
|
65
|
-
const scrollLeft = ref(0);
|
|
66
|
-
const totalHeight = computed(() => props.items.length * props.itemHeight);
|
|
67
|
-
// @ts-ignore
|
|
68
|
-
const totalWidth = computed(() => props.items[0].length * props.itemWidth);
|
|
69
|
-
|
|
70
|
-
const startPosition = computed(() => {
|
|
71
|
-
const row = Math.max(
|
|
72
|
-
0,
|
|
73
|
-
Math.floor(scrollTop.value / props.itemHeight) - 2 * props.buffer
|
|
74
|
-
);
|
|
75
|
-
const col = Math.max(
|
|
76
|
-
0,
|
|
77
|
-
Math.floor(scrollLeft.value / props.itemWidth) - 2 * props.buffer
|
|
78
|
-
);
|
|
79
|
-
return { row, col };
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
const endPosition = computed(() => {
|
|
83
|
-
const row = Math.min(
|
|
84
|
-
props.items.length,
|
|
85
|
-
Math.ceil(
|
|
86
|
-
(scrollTop.value + scrollerHeight.value) / props.itemHeight
|
|
87
|
-
) + 2 * props.buffer
|
|
88
|
-
);
|
|
89
|
-
const col = Math.min(
|
|
90
|
-
// @ts-ignore
|
|
91
|
-
props.items[0].length,
|
|
92
|
-
Math.ceil(
|
|
93
|
-
(scrollLeft.value + scrollerWidth.value) / props.itemWidth
|
|
94
|
-
) + 2 * props.buffer
|
|
95
|
-
);
|
|
96
|
-
return { row, col };
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
const offsetX = computed(() => {
|
|
100
|
-
return startPosition.value.col * props.itemWidth;
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
const offsetY = computed(() => {
|
|
104
|
-
return startPosition.value.row * props.itemHeight;
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
const visibleRows = computed(() =>
|
|
108
|
-
Math.ceil(scrollerHeight.value / props.itemHeight)
|
|
109
|
-
);
|
|
110
|
-
const visibleCols = computed(() =>
|
|
111
|
-
Math.ceil(scrollerWidth.value / props.itemWidth)
|
|
112
|
-
);
|
|
113
|
-
|
|
114
|
-
const renderedItems = ref([]);
|
|
115
|
-
|
|
116
|
-
const onScroll = () => {
|
|
117
|
-
scrollTop.value = scroller.value.scrollTop;
|
|
118
|
-
scrollLeft.value = scroller.value.scrollLeft;
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
watchEffect(() => {
|
|
122
|
-
const numRows = Math.min(
|
|
123
|
-
props.items.length - startPosition.value.row,
|
|
124
|
-
visibleRows.value + 2 * Math.round(props.buffer + props.buffer / 2)
|
|
125
|
-
);
|
|
126
|
-
const numCols = Math.min(
|
|
127
|
-
// @ts-ignore
|
|
128
|
-
props.items[0].length - startPosition.value.col,
|
|
129
|
-
visibleCols.value + 2 * Math.round(props.buffer + props.buffer / 2)
|
|
130
|
-
);
|
|
131
|
-
const rows = props.items.slice(
|
|
132
|
-
startPosition.value.row,
|
|
133
|
-
startPosition.value.row + numRows
|
|
134
|
-
);
|
|
135
|
-
const slicedRows = rows.map((row) =>
|
|
136
|
-
// @ts-ignore
|
|
137
|
-
row.slice(startPosition.value.col, startPosition.value.col + numCols)
|
|
138
|
-
);
|
|
139
|
-
// @ts-ignore
|
|
140
|
-
renderedItems.value = slicedRows;
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
onMounted(() => {
|
|
144
|
-
scrollerHeight.value = scroller.value.clientHeight;
|
|
145
|
-
scrollerWidth.value = scroller.value.clientWidth;
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
return {
|
|
149
|
-
contentWrapper,
|
|
150
|
-
scroller,
|
|
151
|
-
scrollerHeight,
|
|
152
|
-
scrollerWidth,
|
|
153
|
-
scrollTop,
|
|
154
|
-
scrollLeft,
|
|
155
|
-
totalHeight,
|
|
156
|
-
totalWidth,
|
|
157
|
-
startPosition,
|
|
158
|
-
endPosition,
|
|
159
|
-
renderedItems,
|
|
160
|
-
offsetX,
|
|
161
|
-
offsetY,
|
|
162
|
-
onScroll,
|
|
163
|
-
style
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
});
|
|
1
|
+
<template>
|
|
2
|
+
<div
|
|
3
|
+
ref="scroller"
|
|
4
|
+
:class="style.container"
|
|
5
|
+
@scroll.passive="onScroll"
|
|
6
|
+
>
|
|
7
|
+
<div
|
|
8
|
+
ref="contentWrapper"
|
|
9
|
+
:style="{ width: `${totalWidth}px`, height: `${totalHeight}px` }"
|
|
10
|
+
>
|
|
11
|
+
<div
|
|
12
|
+
:style="{ transform: `translate(${offsetX}px, ${offsetY}px)` }"
|
|
13
|
+
>
|
|
14
|
+
<template v-for="(row, rowIndex) in renderedItems" :key="rowIndex">
|
|
15
|
+
<div
|
|
16
|
+
:style="{ display: 'flex' }"
|
|
17
|
+
>
|
|
18
|
+
<template v-for="(item, colIndex) in row" :key="colIndex">
|
|
19
|
+
<div
|
|
20
|
+
:style="{ width: `${itemWidth}px`, height: `${itemHeight}px` }"
|
|
21
|
+
>
|
|
22
|
+
<slot name="item" :item="item" />
|
|
23
|
+
</div>
|
|
24
|
+
</template>
|
|
25
|
+
</div>
|
|
26
|
+
</template>
|
|
27
|
+
</div>
|
|
28
|
+
</div>
|
|
29
|
+
</div>
|
|
30
|
+
</template>
|
|
31
|
+
|
|
32
|
+
<script lang="ts">
|
|
33
|
+
import {defineComponent, computed, onMounted, ref, watchEffect, toRef} from 'vue';
|
|
34
|
+
import * as style from "./style";
|
|
35
|
+
export default defineComponent({
|
|
36
|
+
name: "VirtualScroll",
|
|
37
|
+
props: {
|
|
38
|
+
items: {
|
|
39
|
+
type: Array,
|
|
40
|
+
default: () => []
|
|
41
|
+
},
|
|
42
|
+
itemHeight: {
|
|
43
|
+
type: Number,
|
|
44
|
+
default: 30
|
|
45
|
+
},
|
|
46
|
+
itemWidth: {
|
|
47
|
+
type: Number,
|
|
48
|
+
default: 140
|
|
49
|
+
},
|
|
50
|
+
buffer: {
|
|
51
|
+
type: Number,
|
|
52
|
+
default: 5
|
|
53
|
+
},
|
|
54
|
+
delay: {
|
|
55
|
+
type: Number,
|
|
56
|
+
default: 15
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
setup(props, {emit}) {
|
|
60
|
+
const contentWrapper = ref();
|
|
61
|
+
const scroller = ref();
|
|
62
|
+
const scrollerHeight = ref(0);
|
|
63
|
+
const scrollerWidth = ref(0);
|
|
64
|
+
const scrollTop = ref(0);
|
|
65
|
+
const scrollLeft = ref(0);
|
|
66
|
+
const totalHeight = computed(() => props.items.length * props.itemHeight);
|
|
67
|
+
// @ts-ignore
|
|
68
|
+
const totalWidth = computed(() => props.items[0].length * props.itemWidth);
|
|
69
|
+
|
|
70
|
+
const startPosition = computed(() => {
|
|
71
|
+
const row = Math.max(
|
|
72
|
+
0,
|
|
73
|
+
Math.floor(scrollTop.value / props.itemHeight) - 2 * props.buffer
|
|
74
|
+
);
|
|
75
|
+
const col = Math.max(
|
|
76
|
+
0,
|
|
77
|
+
Math.floor(scrollLeft.value / props.itemWidth) - 2 * props.buffer
|
|
78
|
+
);
|
|
79
|
+
return { row, col };
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
const endPosition = computed(() => {
|
|
83
|
+
const row = Math.min(
|
|
84
|
+
props.items.length,
|
|
85
|
+
Math.ceil(
|
|
86
|
+
(scrollTop.value + scrollerHeight.value) / props.itemHeight
|
|
87
|
+
) + 2 * props.buffer
|
|
88
|
+
);
|
|
89
|
+
const col = Math.min(
|
|
90
|
+
// @ts-ignore
|
|
91
|
+
props.items[0].length,
|
|
92
|
+
Math.ceil(
|
|
93
|
+
(scrollLeft.value + scrollerWidth.value) / props.itemWidth
|
|
94
|
+
) + 2 * props.buffer
|
|
95
|
+
);
|
|
96
|
+
return { row, col };
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
const offsetX = computed(() => {
|
|
100
|
+
return startPosition.value.col * props.itemWidth;
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
const offsetY = computed(() => {
|
|
104
|
+
return startPosition.value.row * props.itemHeight;
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
const visibleRows = computed(() =>
|
|
108
|
+
Math.ceil(scrollerHeight.value / props.itemHeight)
|
|
109
|
+
);
|
|
110
|
+
const visibleCols = computed(() =>
|
|
111
|
+
Math.ceil(scrollerWidth.value / props.itemWidth)
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
const renderedItems = ref([]);
|
|
115
|
+
|
|
116
|
+
const onScroll = () => {
|
|
117
|
+
scrollTop.value = scroller.value.scrollTop;
|
|
118
|
+
scrollLeft.value = scroller.value.scrollLeft;
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
watchEffect(() => {
|
|
122
|
+
const numRows = Math.min(
|
|
123
|
+
props.items.length - startPosition.value.row,
|
|
124
|
+
visibleRows.value + 2 * Math.round(props.buffer + props.buffer / 2)
|
|
125
|
+
);
|
|
126
|
+
const numCols = Math.min(
|
|
127
|
+
// @ts-ignore
|
|
128
|
+
props.items[0].length - startPosition.value.col,
|
|
129
|
+
visibleCols.value + 2 * Math.round(props.buffer + props.buffer / 2)
|
|
130
|
+
);
|
|
131
|
+
const rows = props.items.slice(
|
|
132
|
+
startPosition.value.row,
|
|
133
|
+
startPosition.value.row + numRows
|
|
134
|
+
);
|
|
135
|
+
const slicedRows = rows.map((row) =>
|
|
136
|
+
// @ts-ignore
|
|
137
|
+
row.slice(startPosition.value.col, startPosition.value.col + numCols)
|
|
138
|
+
);
|
|
139
|
+
// @ts-ignore
|
|
140
|
+
renderedItems.value = slicedRows;
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
onMounted(() => {
|
|
144
|
+
scrollerHeight.value = scroller.value.clientHeight;
|
|
145
|
+
scrollerWidth.value = scroller.value.clientWidth;
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
return {
|
|
149
|
+
contentWrapper,
|
|
150
|
+
scroller,
|
|
151
|
+
scrollerHeight,
|
|
152
|
+
scrollerWidth,
|
|
153
|
+
scrollTop,
|
|
154
|
+
scrollLeft,
|
|
155
|
+
totalHeight,
|
|
156
|
+
totalWidth,
|
|
157
|
+
startPosition,
|
|
158
|
+
endPosition,
|
|
159
|
+
renderedItems,
|
|
160
|
+
offsetX,
|
|
161
|
+
offsetY,
|
|
162
|
+
onScroll,
|
|
163
|
+
style
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
167
|
</script>
|
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
<script lang="ts" setup>
|
|
2
|
-
import {ref} from "vue";
|
|
3
|
-
|
|
4
|
-
const items = ref(
|
|
5
|
-
Array.from({ length: 1000 }, (_, i) =>
|
|
6
|
-
Array.from({ length: 1000 }, (_, j) => i + j + 1)
|
|
7
|
-
)
|
|
8
|
-
);
|
|
9
|
-
</script>
|
|
10
|
-
|
|
11
|
-
<template>
|
|
12
|
-
<div>
|
|
13
|
-
<MVirtualScroll
|
|
14
|
-
:items="items"
|
|
15
|
-
:item-size="[50, 100]"
|
|
16
|
-
autoSize
|
|
17
|
-
orientation="both"
|
|
18
|
-
style="width: 970px; height: 600px; overflow: auto"
|
|
19
|
-
>
|
|
20
|
-
<template v-slot:item="{ item }">
|
|
21
|
-
{{ item }}
|
|
22
|
-
</template>
|
|
23
|
-
</MVirtualScroll>
|
|
24
|
-
</div>
|
|
25
|
-
</template>
|
|
26
|
-
|
|
27
|
-
<style>
|
|
28
|
-
.odd {
|
|
29
|
-
background-color: #f5f5f5;
|
|
30
|
-
}
|
|
31
|
-
</style>
|
|
1
|
+
<script lang="ts" setup>
|
|
2
|
+
import {ref} from "vue";
|
|
3
|
+
|
|
4
|
+
const items = ref(
|
|
5
|
+
Array.from({ length: 1000 }, (_, i) =>
|
|
6
|
+
Array.from({ length: 1000 }, (_, j) => i + j + 1)
|
|
7
|
+
)
|
|
8
|
+
);
|
|
9
|
+
</script>
|
|
10
|
+
|
|
11
|
+
<template>
|
|
12
|
+
<div>
|
|
13
|
+
<MVirtualScroll
|
|
14
|
+
:items="items"
|
|
15
|
+
:item-size="[50, 100]"
|
|
16
|
+
autoSize
|
|
17
|
+
orientation="both"
|
|
18
|
+
style="width: 970px; height: 600px; overflow: auto"
|
|
19
|
+
>
|
|
20
|
+
<template v-slot:item="{ item }">
|
|
21
|
+
{{ item }}
|
|
22
|
+
</template>
|
|
23
|
+
</MVirtualScroll>
|
|
24
|
+
</div>
|
|
25
|
+
</template>
|
|
26
|
+
|
|
27
|
+
<style>
|
|
28
|
+
.odd {
|
|
29
|
+
background-color: #f5f5f5;
|
|
30
|
+
}
|
|
31
|
+
</style>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { default as MVirtualScrollBasic } from './basic.vue';
|
|
1
|
+
export { default as MVirtualScrollBasic } from './basic.vue';
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { globalStyle, style } from '@vanilla-extract/css';
|
|
2
|
-
|
|
3
|
-
export const container = style({
|
|
4
|
-
overflow: 'auto',
|
|
5
|
-
willChange: 'transform',
|
|
6
|
-
contain: 'strict'
|
|
7
|
-
});
|
|
8
|
-
|
|
9
|
-
globalStyle(`${container} > div`, {
|
|
10
|
-
overflow: 'hidden',
|
|
11
|
-
willChange: 'transform'
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
globalStyle(`${container} > div > div`, {
|
|
15
|
-
willChange: 'transform',
|
|
16
|
-
backfaceVisibility: 'hidden'
|
|
17
|
-
});
|
|
1
|
+
import { globalStyle, style } from '@vanilla-extract/css';
|
|
2
|
+
|
|
3
|
+
export const container = style({
|
|
4
|
+
overflow: 'auto',
|
|
5
|
+
willChange: 'transform',
|
|
6
|
+
contain: 'strict'
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
globalStyle(`${container} > div`, {
|
|
10
|
+
overflow: 'hidden',
|
|
11
|
+
willChange: 'transform'
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
globalStyle(`${container} > div > div`, {
|
|
15
|
+
willChange: 'transform',
|
|
16
|
+
backfaceVisibility: 'hidden'
|
|
17
|
+
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './VirtualScroll.css';
|
|
1
|
+
export * from './VirtualScroll.css';
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import type { Ref } from 'vue';
|
|
2
|
-
|
|
3
|
-
export function getElement(ref: Ref) {
|
|
4
|
-
if (ref === null) {
|
|
5
|
-
return null;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
if (ref.value === null) {
|
|
9
|
-
return null;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
return '$el' in ref.value ? ref.value.$el : ref.value;
|
|
13
|
-
}
|
|
1
|
+
import type { Ref } from 'vue';
|
|
2
|
+
|
|
3
|
+
export function getElement(ref: Ref) {
|
|
4
|
+
if (ref === null) {
|
|
5
|
+
return null;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
if (ref.value === null) {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return '$el' in ref.value ? ref.value.$el : ref.value;
|
|
13
|
+
}
|
package/src/composables/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { useMessage } from '../components/messageprovider/useMessage';
|
|
2
|
-
export { useConfirm } from '../components/confirm/useConfirm';
|
|
3
|
-
export { usePopper } from './usePopper';
|
|
4
|
-
export { useZIndex } from './useZIndex';
|
|
1
|
+
export { useMessage } from '../components/messageprovider/useMessage';
|
|
2
|
+
export { useConfirm } from '../components/confirm/useConfirm';
|
|
3
|
+
export { usePopper } from './usePopper';
|
|
4
|
+
export { useZIndex } from './useZIndex';
|
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
// https://github.com/liip/chusho/blob/main/packages/chusho/lib/composables/useCachedUid.ts#L20-L41 - Legend :D
|
|
2
|
-
import { onMounted, readonly, ref } from 'vue';
|
|
3
|
-
import { getElement } from './element';
|
|
4
|
-
import type { ComponentPublicInstance, Ref } from 'vue';
|
|
5
|
-
|
|
6
|
-
const UID_CACHE_ATTR = 'data-modlr-ssr-uid';
|
|
7
|
-
|
|
8
|
-
// @ts-nocheck
|
|
9
|
-
type CacheElement = HTMLElement | SVGElement | ComponentPublicInstance | null;
|
|
10
|
-
|
|
11
|
-
export function uid(prefix = ''): string {
|
|
12
|
-
const id =
|
|
13
|
-
Date.now().toString(36) + Math.random().toString(36).substring(2);
|
|
14
|
-
return prefix ? `${prefix}-${id}` : id;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export interface IUseCacheUid {
|
|
18
|
-
id: Readonly<Ref<string>>;
|
|
19
|
-
cacheAttrs: {
|
|
20
|
-
ref: Ref<CacheElement>;
|
|
21
|
-
[UID_CACHE_ATTR]?: string;
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export function useCachedUid(prefix?: string): IUseCacheUid {
|
|
26
|
-
const id = ref(uid(prefix));
|
|
27
|
-
const cacheElement = ref<CacheElement>(null);
|
|
28
|
-
|
|
29
|
-
onMounted(() => {
|
|
30
|
-
if (cacheElement.value) {
|
|
31
|
-
const element = getElement(cacheElement);
|
|
32
|
-
const serverId = element?.getAttribute(UID_CACHE_ATTR);
|
|
33
|
-
|
|
34
|
-
if (serverId) {
|
|
35
|
-
id.value = serverId;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
element?.removeAttribute(UID_CACHE_ATTR);
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
return {
|
|
43
|
-
id: readonly(id),
|
|
44
|
-
cacheAttrs: {
|
|
45
|
-
ref: cacheElement,
|
|
46
|
-
[UID_CACHE_ATTR]: typeof window === undefined ? id.value : undefined
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
}
|
|
1
|
+
// https://github.com/liip/chusho/blob/main/packages/chusho/lib/composables/useCachedUid.ts#L20-L41 - Legend :D
|
|
2
|
+
import { onMounted, readonly, ref } from 'vue';
|
|
3
|
+
import { getElement } from './element';
|
|
4
|
+
import type { ComponentPublicInstance, Ref } from 'vue';
|
|
5
|
+
|
|
6
|
+
const UID_CACHE_ATTR = 'data-modlr-ssr-uid';
|
|
7
|
+
|
|
8
|
+
// @ts-nocheck
|
|
9
|
+
type CacheElement = HTMLElement | SVGElement | ComponentPublicInstance | null;
|
|
10
|
+
|
|
11
|
+
export function uid(prefix = ''): string {
|
|
12
|
+
const id =
|
|
13
|
+
Date.now().toString(36) + Math.random().toString(36).substring(2);
|
|
14
|
+
return prefix ? `${prefix}-${id}` : id;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface IUseCacheUid {
|
|
18
|
+
id: Readonly<Ref<string>>;
|
|
19
|
+
cacheAttrs: {
|
|
20
|
+
ref: Ref<CacheElement>;
|
|
21
|
+
[UID_CACHE_ATTR]?: string;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function useCachedUid(prefix?: string): IUseCacheUid {
|
|
26
|
+
const id = ref(uid(prefix));
|
|
27
|
+
const cacheElement = ref<CacheElement>(null);
|
|
28
|
+
|
|
29
|
+
onMounted(() => {
|
|
30
|
+
if (cacheElement.value) {
|
|
31
|
+
const element = getElement(cacheElement);
|
|
32
|
+
const serverId = element?.getAttribute(UID_CACHE_ATTR);
|
|
33
|
+
|
|
34
|
+
if (serverId) {
|
|
35
|
+
id.value = serverId;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
element?.removeAttribute(UID_CACHE_ATTR);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
return {
|
|
43
|
+
id: readonly(id),
|
|
44
|
+
cacheAttrs: {
|
|
45
|
+
ref: cacheElement,
|
|
46
|
+
[UID_CACHE_ATTR]: typeof window === undefined ? id.value : undefined
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import { watchEffect } from 'vue';
|
|
2
|
-
|
|
3
|
-
export function useEventListener<
|
|
4
|
-
T extends EventTarget | HTMLElement,
|
|
5
|
-
E extends EventListener
|
|
6
|
-
>(element: T, type: string, listener: E, options: boolean) {
|
|
7
|
-
if (typeof window === undefined) {
|
|
8
|
-
return;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
watchEffect(onInvalidate => {
|
|
12
|
-
element = element ?? window;
|
|
13
|
-
|
|
14
|
-
element.addEventListener(type, listener, options);
|
|
15
|
-
onInvalidate(() =>
|
|
16
|
-
element.removeEventListener(type, listener, options)
|
|
17
|
-
);
|
|
18
|
-
});
|
|
19
|
-
}
|
|
1
|
+
import { watchEffect } from 'vue';
|
|
2
|
+
|
|
3
|
+
export function useEventListener<
|
|
4
|
+
T extends EventTarget | HTMLElement,
|
|
5
|
+
E extends EventListener
|
|
6
|
+
>(element: T, type: string, listener: E, options: boolean) {
|
|
7
|
+
if (typeof window === undefined) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
watchEffect(onInvalidate => {
|
|
12
|
+
element = element ?? window;
|
|
13
|
+
|
|
14
|
+
element.addEventListener(type, listener, options);
|
|
15
|
+
onInvalidate(() =>
|
|
16
|
+
element.removeEventListener(type, listener, options)
|
|
17
|
+
);
|
|
18
|
+
});
|
|
19
|
+
}
|