@v1nt1248/3nclient-lib 0.0.41 → 0.1.0
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 +4 -4
- package/dist/components/index.d.ts +22 -38
- package/dist/components/ui3n-badge-simple.vue.d.ts +3 -3
- package/dist/components/ui3n-badge.vue.d.ts +2 -2
- package/dist/components/ui3n-breadcrumb.vue.d.ts +7 -7
- package/dist/components/ui3n-breadcrumbs.vue.d.ts +3 -3
- package/dist/components/ui3n-button.vue.d.ts +29 -4
- package/dist/components/ui3n-checkbox.vue.d.ts +3 -3
- package/dist/components/ui3n-chip.vue.d.ts +3 -3
- package/dist/components/ui3n-dialog.vue.d.ts +6 -5
- package/dist/components/ui3n-drop-files.vue.d.ts +23 -3
- package/dist/components/ui3n-emoji.vue.d.ts +3 -3
- package/dist/components/ui3n-icon.vue.d.ts +29 -3
- package/dist/components/ui3n-input.vue.d.ts +9 -9
- package/dist/components/ui3n-list.vue.d.ts +4 -4
- package/dist/components/ui3n-menu.vue.d.ts +3 -3
- package/dist/components/ui3n-notification.vue.d.ts +32 -2
- package/dist/components/ui3n-switch.vue.d.ts +55 -0
- package/dist/components/ui3n-table-sort-icon.vue.d.ts +1 -1
- package/dist/components/ui3n-table.vue.d.ts +4 -3
- package/dist/components/ui3n-tabs.vue.d.ts +3 -3
- package/dist/components/ui3n-text.vue.d.ts +29 -3
- package/dist/components/ui3n-virtual-scroll.vue.d.ts +12 -9
- package/dist/constants/types.d.ts +2 -4
- package/dist/directives/index.d.ts +3 -2
- package/dist/directives/ui3n-click-outside.d.ts +2 -1
- package/dist/directives/ui3n-html.d.ts +1 -0
- package/dist/index.d.ts +27 -29
- package/dist/plugins/dialogs.d.ts +3 -3
- package/dist/plugins/i18n.d.ts +2 -2
- package/dist/plugins/icons.d.ts +1 -0
- package/dist/plugins/index.d.ts +5 -8
- package/dist/plugins/notifications.d.ts +2 -2
- package/dist/plugins/store-dialogs.d.ts +2 -1
- package/dist/plugins/store-notifications.d.ts +2 -1
- package/dist/plugins/store-vue-bus.d.ts +2 -1
- package/dist/plugins/vue-bus.d.ts +3 -3
- package/dist/style.css +1 -1
- package/dist/tools/sqlite-on-3nstorage/index.d.ts +3 -2
- package/dist/tools/ui.helpers.d.ts +1 -0
- package/dist/ui-3n-lib.js +6953 -6615
- package/package.json +57 -58
- package/src/components/index.ts +47 -41
- package/src/components/ui3n-badge-simple.vue +35 -38
- package/src/components/ui3n-badge.vue +25 -25
- package/src/components/ui3n-breadcrumb.vue +44 -44
- package/src/components/ui3n-breadcrumbs.vue +19 -19
- package/src/components/ui3n-button.vue +240 -150
- package/src/components/ui3n-checkbox.vue +199 -158
- package/src/components/ui3n-chip.vue +96 -98
- package/src/components/ui3n-dialog.vue +225 -235
- package/src/components/ui3n-drop-files.vue +146 -154
- package/src/components/ui3n-emoji.vue +62 -64
- package/src/components/ui3n-icon.vue +32 -13
- package/src/components/ui3n-input.vue +239 -221
- package/src/components/ui3n-list.vue +92 -111
- package/src/components/ui3n-menu.vue +101 -100
- package/src/components/ui3n-notification.vue +182 -113
- package/src/components/ui3n-switch.vue +146 -0
- package/src/components/ui3n-table-sort-icon.vue +1 -2
- package/src/components/ui3n-table.vue +229 -223
- package/src/components/ui3n-tabs.vue +141 -148
- package/src/components/ui3n-text.vue +235 -146
- package/src/components/ui3n-virtual-scroll.vue +68 -68
- package/dist/stories/Ui3nBadge.stories.d.ts +0 -124
- package/dist/stories/Ui3nBreadcrumbs.stories.d.ts +0 -252
- package/dist/stories/Ui3nButton.stories.d.ts +0 -152
- package/dist/stories/Ui3nCheckbox.stories.d.ts +0 -186
- package/dist/stories/Ui3nChip.stories.d.ts +0 -562
- package/dist/stories/Ui3nDialog.stories.d.ts +0 -41
- package/dist/stories/Ui3nDropFiles.stories.d.ts +0 -73
- package/dist/stories/Ui3nEmoji.stories.d.ts +0 -39
- package/dist/stories/Ui3nIcon.stories.d.ts +0 -80
- package/dist/stories/Ui3nInput.stories.d.ts +0 -456
- package/dist/stories/Ui3nList.stories.d.ts +0 -54
- package/dist/stories/Ui3nTabs.stories.d.ts +0 -177
- package/dist/stories/data/data-to-list.d.ts +0 -8
- package/dist/stories/data/icons.d.ts +0 -1
|
@@ -1,115 +1,111 @@
|
|
|
1
1
|
<script lang="ts" setup>
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export interface Ui3nTextProps {
|
|
7
|
-
text: string;
|
|
8
|
-
rows?: number;
|
|
9
|
-
maxRows?: number;
|
|
10
|
-
label?: string;
|
|
11
|
-
placeholder?: string;
|
|
12
|
-
rules?: Array<(v: string) => any>;
|
|
13
|
-
disabled?: boolean;
|
|
14
|
-
}
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
|
+
import { computed, onMounted, ref, watch } from 'vue';
|
|
4
|
+
import { patchTextareaMaxRowsSupport } from '../tools';
|
|
15
5
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
6
|
+
export interface Ui3nTextProps {
|
|
7
|
+
text: string;
|
|
8
|
+
rows?: number;
|
|
9
|
+
maxRows?: number;
|
|
10
|
+
label?: string;
|
|
11
|
+
placeholder?: string;
|
|
12
|
+
rules?: Array<(v: string) => any>;
|
|
13
|
+
disabled?: boolean;
|
|
14
|
+
}
|
|
24
15
|
|
|
25
|
-
|
|
26
|
-
|
|
16
|
+
export interface Ui3nTextEmits {
|
|
17
|
+
(ev: 'init', value: HTMLTextAreaElement): void;
|
|
18
|
+
(ev: 'input', value: string): void;
|
|
19
|
+
(ev: 'focus', value: Event): void;
|
|
20
|
+
(ev: 'blur', value: Event): void;
|
|
21
|
+
(ev: 'update:text', value: string): void;
|
|
22
|
+
(ev: 'update:valid', value: boolean): void;
|
|
23
|
+
}
|
|
27
24
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
25
|
+
const props = withDefaults(
|
|
26
|
+
defineProps<Ui3nTextProps>(),
|
|
27
|
+
{
|
|
28
|
+
rows: 6,
|
|
29
|
+
maxRows: 6,
|
|
30
|
+
label: '',
|
|
31
|
+
placeholder: '',
|
|
32
|
+
disabled: false,
|
|
33
|
+
},
|
|
34
|
+
);
|
|
35
|
+
const emit = defineEmits<Ui3nTextEmits>();
|
|
31
36
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
})
|
|
37
|
+
const textareaElement = ref<HTMLTextAreaElement | null>(null);
|
|
38
|
+
const isFocused = ref(false);
|
|
39
|
+
const errorMessage = ref('');
|
|
36
40
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
+
const isValid = computed(() => {
|
|
42
|
+
if (!props.text) {
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
41
45
|
|
|
42
|
-
|
|
43
|
-
|
|
46
|
+
return !errorMessage.value;
|
|
47
|
+
});
|
|
44
48
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
49
|
+
onMounted(() => {
|
|
50
|
+
if (textareaElement.value) {
|
|
51
|
+
patchTextareaMaxRowsSupport(textareaElement.value!);
|
|
52
|
+
emit('init', textareaElement.value!);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
watch(
|
|
57
|
+
() => isValid.value,
|
|
58
|
+
val => emit('update:valid', val),
|
|
59
|
+
{ immediate: true },
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
const validate = (text: string) => {
|
|
63
|
+
errorMessage.value = '';
|
|
64
|
+
if (props.rules && props.rules.length) {
|
|
65
|
+
for (const validateFunction of props.rules) {
|
|
66
|
+
if (typeof validateFunction === 'function') {
|
|
67
|
+
const res = validateFunction(text);
|
|
68
|
+
if (typeof res === 'string') {
|
|
69
|
+
errorMessage.value += res;
|
|
67
70
|
}
|
|
68
71
|
}
|
|
69
72
|
}
|
|
70
73
|
}
|
|
74
|
+
};
|
|
71
75
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
+
const onFocus = (event: Event) => {
|
|
77
|
+
isFocused.value = true;
|
|
78
|
+
emit('focus', event);
|
|
79
|
+
};
|
|
76
80
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
+
const onBlur = (event: Event) => {
|
|
82
|
+
isFocused.value = false;
|
|
83
|
+
emit('blur', event);
|
|
84
|
+
};
|
|
81
85
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
86
|
+
const onInput = (ev: Event) => {
|
|
87
|
+
const value = (ev.target as HTMLInputElement).value;
|
|
88
|
+
validate(value);
|
|
89
|
+
emit('update:text', value);
|
|
90
|
+
emit('input', value);
|
|
91
|
+
};
|
|
88
92
|
</script>
|
|
89
93
|
|
|
90
94
|
<template>
|
|
91
|
-
<div
|
|
92
|
-
:class="
|
|
93
|
-
|
|
94
|
-
{ 'ui3n-text--disabled': props.disabled, 'ui3n-text--focused': isFocused },
|
|
95
|
-
]"
|
|
96
|
-
>
|
|
97
|
-
<label
|
|
98
|
-
v-if="componentProps.label"
|
|
99
|
-
class="ui3n-text__label"
|
|
100
|
-
>
|
|
101
|
-
{{ componentProps.label }}
|
|
95
|
+
<div :class="[$style.text, disabled && $style.disabled, isFocused && $style.focused]">
|
|
96
|
+
<label v-if="label" :class="$style.label">
|
|
97
|
+
{{ label }}
|
|
102
98
|
</label>
|
|
103
|
-
<div class="
|
|
99
|
+
<div :class="$style.body">
|
|
104
100
|
<textarea
|
|
105
101
|
ref="textareaElement"
|
|
106
|
-
:
|
|
107
|
-
:
|
|
108
|
-
:
|
|
109
|
-
:
|
|
110
|
-
:
|
|
111
|
-
:
|
|
112
|
-
|
|
102
|
+
:class="$style.content"
|
|
103
|
+
:value="text"
|
|
104
|
+
:placeholder="placeholder"
|
|
105
|
+
:readonly="disabled"
|
|
106
|
+
:rows="rows"
|
|
107
|
+
:max-rows="maxRows"
|
|
108
|
+
:disabled="disabled"
|
|
113
109
|
v-bind="$attrs"
|
|
114
110
|
@input="onInput"
|
|
115
111
|
@focusin="onFocus"
|
|
@@ -119,67 +115,160 @@
|
|
|
119
115
|
</div>
|
|
120
116
|
</template>
|
|
121
117
|
|
|
122
|
-
<style lang="scss"
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
display: block;
|
|
129
|
-
width: 100%;
|
|
130
|
-
font-size: var(--font-12, 12px);
|
|
131
|
-
font-weight: 600;
|
|
132
|
-
color: var(--black-90, #212121);
|
|
133
|
-
margin-bottom: calc(var(--base-size, 8px) / 2);
|
|
134
|
-
}
|
|
118
|
+
<style lang="scss" module>
|
|
119
|
+
.text {
|
|
120
|
+
position: relative;
|
|
121
|
+
width: 100%;
|
|
122
|
+
border-radius: var(--spacing-xs);
|
|
123
|
+
}
|
|
135
124
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
125
|
+
.label {
|
|
126
|
+
display: block;
|
|
127
|
+
width: 100%;
|
|
128
|
+
font-size: var(--font-12);
|
|
129
|
+
line-height: var(--font-16);
|
|
130
|
+
font-weight: 600;
|
|
131
|
+
color: var(--color-text-control-primary-default);
|
|
132
|
+
margin-bottom: var(--spacing-xs);
|
|
133
|
+
}
|
|
143
134
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
background-color: var(--gray-50, #f2f2f2);
|
|
152
|
-
padding: 0 var(--base-size, 8px);
|
|
153
|
-
font-family: OpenSans, sans-serif;
|
|
154
|
-
font-size: var(--font-13, 13px);
|
|
155
|
-
font-weight: 400;
|
|
156
|
-
line-height: var(--font-16, 16px);
|
|
157
|
-
color: var(--black-90, #212121);
|
|
158
|
-
border: none;
|
|
159
|
-
|
|
160
|
-
&::placeholder {
|
|
161
|
-
font-size: var(--font-13, 13px);
|
|
162
|
-
font-weight: 300;
|
|
163
|
-
font-style: italic;
|
|
164
|
-
color: var(--gray-90, #212121);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
135
|
+
.body {
|
|
136
|
+
position: relative;
|
|
137
|
+
width: 100%;
|
|
138
|
+
padding: var(--spacing-s) 0;
|
|
139
|
+
background-color: var(--color-bg-control-secondary-default);
|
|
140
|
+
border-radius: var(--spacing-xs);
|
|
141
|
+
transition: all 0.2s ease-in-out;
|
|
167
142
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
opacity: 0.5;
|
|
172
|
-
}
|
|
143
|
+
&:hover {
|
|
144
|
+
&:not(:focus-within) {
|
|
145
|
+
background-color: var(--color-bg-control-secondary-hover);
|
|
173
146
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
border: none;
|
|
147
|
+
.content {
|
|
148
|
+
background-color: var(--color-bg-control-secondary-hover);
|
|
149
|
+
|
|
150
|
+
&::placeholder {
|
|
151
|
+
color: var(--color-text-control-secondary-hover);
|
|
180
152
|
}
|
|
181
153
|
}
|
|
182
154
|
}
|
|
183
155
|
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
.content {
|
|
159
|
+
resize: none;
|
|
160
|
+
display: block;
|
|
161
|
+
border: none;
|
|
162
|
+
box-sizing: border-box;
|
|
163
|
+
position: relative;
|
|
164
|
+
width: 100%;
|
|
165
|
+
border-radius: var(--spacing-xs);
|
|
166
|
+
background-color: var(--color-bg-control-secondary-default);
|
|
167
|
+
padding: 0 var(--spacing-s);
|
|
168
|
+
font-family: Manrope, sans-serif;
|
|
169
|
+
font-size: var(--font-13);
|
|
170
|
+
line-height: var(--font-16);
|
|
171
|
+
font-weight: 400;
|
|
172
|
+
color: var(--color-text-control-primary-default);
|
|
173
|
+
transition: all 0.2s ease-in-out;
|
|
174
|
+
|
|
175
|
+
&::placeholder {
|
|
176
|
+
color: var(--color-text-control-secondary-default);
|
|
177
|
+
font-style: italic;
|
|
178
|
+
font-size: var(--font-13);
|
|
179
|
+
line-height: var(--font-16);
|
|
180
|
+
font-weight: 400;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
&:focus-within {
|
|
184
|
+
outline: none;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
.disabled {
|
|
189
|
+
pointer-events: none;
|
|
190
|
+
user-select: none;
|
|
191
|
+
|
|
192
|
+
.body {
|
|
193
|
+
background-color: var(--color-bg-control-secondary-disabled);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
.content {
|
|
197
|
+
background-color: var(--color-bg-control-secondary-disabled);
|
|
198
|
+
color: var(--color-text-control-secondary-disabled);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
.focused {
|
|
203
|
+
.body {
|
|
204
|
+
background-color: var(--color-bg-control-secondary-focused);
|
|
205
|
+
outline: 1px solid var(--color-border-control-accent-focused);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
.content {
|
|
209
|
+
background-color: var(--color-bg-control-secondary-focused);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
//.ui3n-text {
|
|
214
|
+
// position: relative;
|
|
215
|
+
// width: 100%;
|
|
216
|
+
//
|
|
217
|
+
// &__label {
|
|
218
|
+
// display: block;
|
|
219
|
+
// width: 100%;
|
|
220
|
+
// font-size: var(--font-12, 12px);
|
|
221
|
+
// font-weight: 600;
|
|
222
|
+
// color: var(--black-90, #212121);
|
|
223
|
+
// margin-bottom: calc(var(--base-size, 8px) / 2);
|
|
224
|
+
// }
|
|
225
|
+
//
|
|
226
|
+
// &__body {
|
|
227
|
+
// position: relative;
|
|
228
|
+
// width: 100%;
|
|
229
|
+
// padding: var(--base-size, 8px) 0;
|
|
230
|
+
// background-color: var(--gray-50, #f2f2f2);
|
|
231
|
+
// border-radius: 4px;
|
|
232
|
+
// }
|
|
233
|
+
//
|
|
234
|
+
// &__content {
|
|
235
|
+
// resize: none;
|
|
236
|
+
// display: block;
|
|
237
|
+
// box-sizing: border-box;
|
|
238
|
+
// position: relative;
|
|
239
|
+
// width: 100%;
|
|
240
|
+
// border-radius: 4px;
|
|
241
|
+
// background-color: var(--gray-50, #f2f2f2);
|
|
242
|
+
// padding: 0 var(--base-size, 8px);
|
|
243
|
+
// font-family: OpenSans, sans-serif;
|
|
244
|
+
// font-size: var(--font-13, 13px);
|
|
245
|
+
// font-weight: 400;
|
|
246
|
+
// line-height: var(--font-16, 16px);
|
|
247
|
+
// color: var(--black-90, #212121);
|
|
248
|
+
// border: none;
|
|
249
|
+
//
|
|
250
|
+
// &::placeholder {
|
|
251
|
+
// font-size: var(--font-13, 13px);
|
|
252
|
+
// font-weight: 300;
|
|
253
|
+
// font-style: italic;
|
|
254
|
+
// color: var(--gray-90, #212121);
|
|
255
|
+
// }
|
|
256
|
+
// }
|
|
257
|
+
//
|
|
258
|
+
// &--disabled {
|
|
259
|
+
// pointer-events: none;
|
|
260
|
+
// user-select: none;
|
|
261
|
+
// opacity: 0.5;
|
|
262
|
+
// }
|
|
263
|
+
//
|
|
264
|
+
// &--focused {
|
|
265
|
+
// .ui3n-text {
|
|
266
|
+
// &__body, &__content {
|
|
267
|
+
// background-color: var(--blue-main-20, #d8edfd);
|
|
268
|
+
// outline: none;
|
|
269
|
+
// border: none;
|
|
270
|
+
// }
|
|
271
|
+
// }
|
|
272
|
+
// }
|
|
273
|
+
//}
|
|
184
274
|
</style>
|
|
185
|
-
../tools/textarea-max-rows
|
|
@@ -1,80 +1,80 @@
|
|
|
1
1
|
<script lang="ts" setup generic="T extends { id?: string }">
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
|
+
import { computed, onMounted, ref } from 'vue';
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
export interface Ui3nVirtualScrollProps<T> {
|
|
6
|
+
items: T[];
|
|
7
|
+
minChildHeight: number;
|
|
8
|
+
renderAhead?: number;
|
|
9
|
+
}
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
export interface Ui3nVirtualScrollSlots<T> {
|
|
12
|
+
item: ({ value, index }: { value: T, index: number}) => any;
|
|
13
|
+
}
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
const props = withDefaults(defineProps<Ui3nVirtualScrollProps<T>>(), {
|
|
16
|
+
renderAhead: 20,
|
|
17
|
+
});
|
|
18
|
+
defineSlots<Ui3nVirtualScrollSlots<T>>();
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
20
|
+
const scrollTop = ref(0);
|
|
21
|
+
const animationFrame = ref<number | undefined>();
|
|
22
|
+
const wrapElement = ref<HTMLDivElement | null>(null);
|
|
23
|
+
const wrapElementHeight = computed(() => wrapElement.value
|
|
24
|
+
? wrapElement.value.clientHeight
|
|
25
|
+
: 0,
|
|
26
|
+
);
|
|
27
|
+
const itemCount = computed(() => props.items.length);
|
|
28
|
+
const totalHeight = computed(() => itemCount.value * props.minChildHeight);
|
|
29
|
+
const startNode = computed(() => {
|
|
30
|
+
const val = Math.floor(scrollTop.value / props.minChildHeight) - props.renderAhead;
|
|
31
|
+
return Math.max(0, val);
|
|
32
|
+
});
|
|
33
|
+
const visibleNodeCount = computed(() => {
|
|
34
|
+
const val = Math.ceil(wrapElementHeight.value / props.minChildHeight) + 2 * props.renderAhead;
|
|
35
|
+
return Math.min(itemCount.value - startNode.value, val);
|
|
36
|
+
});
|
|
37
|
+
const offsetY = computed(() => startNode.value * props.minChildHeight);
|
|
38
|
+
const visibleChildren = computed(() => props.items.slice(startNode.value, startNode.value + visibleNodeCount.value));
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
animationFrame.value = requestAnimationFrame(() => scrollTop.value = (event.target as HTMLDivElement).scrollTop)
|
|
40
|
+
const onScroll = (event: Event) => {
|
|
41
|
+
if (animationFrame.value) {
|
|
42
|
+
cancelAnimationFrame(animationFrame.value);
|
|
46
43
|
}
|
|
47
44
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
45
|
+
animationFrame.value = requestAnimationFrame(() => scrollTop.value = (event.target as HTMLDivElement).scrollTop);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
onMounted(() => {
|
|
49
|
+
if (wrapElement.value) {
|
|
50
|
+
scrollTop.value = wrapElement.value.scrollTop;
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
53
|
</script>
|
|
54
54
|
|
|
55
55
|
<template>
|
|
56
56
|
<div
|
|
57
57
|
ref="wrapElement"
|
|
58
|
-
class="
|
|
58
|
+
:class="$style.virtualScroll"
|
|
59
59
|
@scroll="onScroll"
|
|
60
60
|
>
|
|
61
61
|
<div
|
|
62
|
-
class="
|
|
62
|
+
:class="$style.viewport"
|
|
63
63
|
:style="{ height: `${totalHeight}px` }"
|
|
64
64
|
>
|
|
65
65
|
<div
|
|
66
|
-
class="
|
|
66
|
+
:class="$style.content"
|
|
67
67
|
:style="{ transform: `translateY(${offsetY}px)` }"
|
|
68
68
|
>
|
|
69
69
|
<div
|
|
70
70
|
v-for="(item, index) in visibleChildren"
|
|
71
71
|
:key="item.id"
|
|
72
72
|
:data-sid="item.id ?? index"
|
|
73
|
-
class="
|
|
73
|
+
:class="$style.item"
|
|
74
74
|
>
|
|
75
75
|
<slot
|
|
76
76
|
name="item"
|
|
77
|
-
:
|
|
77
|
+
:value="item"
|
|
78
78
|
:index="startNode + index"
|
|
79
79
|
/>
|
|
80
80
|
</div>
|
|
@@ -83,26 +83,26 @@
|
|
|
83
83
|
</div>
|
|
84
84
|
</template>
|
|
85
85
|
|
|
86
|
-
<style lang="scss"
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
86
|
+
<style lang="scss" module>
|
|
87
|
+
.virtualScroll {
|
|
88
|
+
position: relative;
|
|
89
|
+
width: 100%;
|
|
90
|
+
height: 100%;
|
|
91
|
+
overflow-y: auto;
|
|
92
|
+
}
|
|
92
93
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
94
|
+
.viewport {
|
|
95
|
+
position: relative;
|
|
96
|
+
overflow: hidden;
|
|
97
|
+
will-change: transform;
|
|
98
|
+
}
|
|
98
99
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
100
|
+
.content {
|
|
101
|
+
will-change: transform;
|
|
102
|
+
}
|
|
102
103
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
}
|
|
104
|
+
.item {
|
|
105
|
+
position: relative;
|
|
106
|
+
min-height: 16px;
|
|
107
|
+
}
|
|
108
108
|
</style>
|