@katlux/toolkit 0.1.1-alpha.123 → 0.1.1-alpha.124
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/bin/cli.mjs +0 -0
- package/bin/create-preset.mjs +0 -0
- package/dist/compiled/composables/useDataProvider.mjs +6 -6
- package/dist/compiled/composables/useKatluxForm.mjs +23 -4
- package/dist/compiled/composables/usePresetComponent.mjs +1 -1
- package/dist/compiled/composables/useVirtualScroll.mjs +24 -11
- package/dist/compiled/utils/sanitize.mjs +39 -0
- package/dist/module.json +1 -1
- package/dist/runtime/components/KCheckbox/KCheckbox.global.d.vue.ts +11 -0
- package/dist/runtime/components/KCheckbox/KCheckbox.global.vue +4 -3
- package/dist/runtime/components/KCheckbox/KCheckbox.global.vue.d.ts +11 -0
- package/dist/runtime/components/KCheckbox/KCheckbox.logic.d.ts +5 -0
- package/dist/runtime/components/KCheckbox/KCheckbox.logic.js +4 -0
- package/dist/runtime/components/KCombobox/KCombobox.logic.js +3 -1
- package/dist/runtime/components/KDatatable/KDatatable.logic.d.ts +1 -1
- package/dist/runtime/components/KMaskTextbox/KMaskTextbox.logic.js +2 -0
- package/dist/runtime/components/KRadiobox/KRadiobox.global.vue +1 -1
- package/dist/runtime/components/KRangeSlider/KRangeSlider.global.vue +1 -1
- package/dist/runtime/components/KSlider/KSlider.global.vue +1 -1
- package/dist/runtime/components/KTextarea/KTextarea.global.vue +1 -1
- package/dist/runtime/components/KToast/KToast.global.d.vue.ts +1 -1
- package/dist/runtime/components/KToast/KToast.global.vue.d.ts +1 -1
- package/dist/runtime/components/KTree/KTree.global.d.vue.ts +1 -1
- package/dist/runtime/components/KTree/KTree.global.vue +2 -0
- package/dist/runtime/components/KTree/KTree.global.vue.d.ts +1 -1
- package/dist/runtime/components/KTree/KTree.logic.js +38 -12
- package/dist/runtime/composables/useDataProvider.d.ts +1 -1
- package/dist/runtime/composables/useDataProvider.js +6 -6
- package/dist/runtime/composables/useKatluxForm.js +23 -4
- package/dist/runtime/composables/usePresetComponent.js +1 -1
- package/dist/runtime/composables/useVirtualScroll.js +24 -11
- package/dist/runtime/presets/default/components/KCheckbox/KCheckbox.d.vue.ts +9 -3
- package/dist/runtime/presets/default/components/KCheckbox/KCheckbox.vue +35 -12
- package/dist/runtime/presets/default/components/KCheckbox/KCheckbox.vue.d.ts +9 -3
- package/dist/runtime/presets/default/components/KDatatable/KDatatable.vue +109 -19
- package/dist/runtime/presets/default/components/KIcon/KIcon.vue +5 -2
- package/dist/runtime/presets/default/components/KRadiobox/KRadiobox.vue +1 -0
- package/dist/runtime/presets/default/components/KTree/KTree.d.vue.ts +3 -3
- package/dist/runtime/presets/default/components/KTree/KTree.vue +245 -115
- package/dist/runtime/presets/default/components/KTree/KTree.vue.d.ts +3 -3
- package/dist/runtime/presets/default/components/KTree/KTreeNodeItem.d.vue.ts +27 -0
- package/dist/runtime/presets/default/components/KTree/KTreeNodeItem.vue +179 -0
- package/dist/runtime/presets/default/components/KTree/KTreeNodeItem.vue.d.ts +27 -0
- package/dist/runtime/utils/sanitize.d.ts +5 -0
- package/dist/runtime/utils/sanitize.js +39 -0
- package/package.json +6 -3
|
@@ -144,6 +144,7 @@ export function useKatluxForm(options = {}) {
|
|
|
144
144
|
}
|
|
145
145
|
}
|
|
146
146
|
let validationSeq = 0;
|
|
147
|
+
let submitSeq = 0;
|
|
147
148
|
function validate(targetPath) {
|
|
148
149
|
const seq = ++validationSeq;
|
|
149
150
|
const result = runValidation(values);
|
|
@@ -195,6 +196,8 @@ export function useKatluxForm(options = {}) {
|
|
|
195
196
|
dirtyFields.value = {};
|
|
196
197
|
submitCount.value = 0;
|
|
197
198
|
isSubmitting.value = false;
|
|
199
|
+
submitSeq++;
|
|
200
|
+
validationSeq++;
|
|
198
201
|
}
|
|
199
202
|
function register(path, regOptions = {}) {
|
|
200
203
|
return {
|
|
@@ -267,25 +270,41 @@ export function useKatluxForm(options = {}) {
|
|
|
267
270
|
if (event && typeof event.preventDefault === "function") {
|
|
268
271
|
event.preventDefault();
|
|
269
272
|
}
|
|
273
|
+
const currentSubmitId = ++submitSeq;
|
|
270
274
|
submitCount.value += 1;
|
|
271
275
|
isSubmitting.value = true;
|
|
272
276
|
try {
|
|
273
|
-
const
|
|
277
|
+
const snapshotValues = deepClone(values);
|
|
278
|
+
const res = await runValidation(snapshotValues);
|
|
279
|
+
if (currentSubmitId !== submitSeq) {
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
274
282
|
const { valid, output, errors: newErrors } = res;
|
|
275
|
-
errors.value = newErrors;
|
|
276
283
|
if (!valid) {
|
|
284
|
+
const errorsToApply = {};
|
|
285
|
+
for (const [errPath, errMsg] of Object.entries(newErrors)) {
|
|
286
|
+
const currentVal = getByPath(values, errPath);
|
|
287
|
+
const snapVal = getByPath(snapshotValues, errPath);
|
|
288
|
+
if (JSON.stringify(currentVal) === JSON.stringify(snapVal)) {
|
|
289
|
+
errorsToApply[errPath] = errMsg;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
errors.value = errorsToApply;
|
|
277
293
|
const firstErrorKey = Object.keys(newErrors)[0];
|
|
278
294
|
if (focusOnError && firstErrorKey) {
|
|
279
295
|
focusFirstInvalid(firstErrorKey);
|
|
280
296
|
}
|
|
281
297
|
if (onInvalid) {
|
|
282
|
-
await onInvalid(newErrors,
|
|
298
|
+
await onInvalid(newErrors, snapshotValues);
|
|
283
299
|
}
|
|
284
300
|
return;
|
|
285
301
|
}
|
|
302
|
+
errors.value = {};
|
|
286
303
|
await onValid(output, event);
|
|
287
304
|
} finally {
|
|
288
|
-
|
|
305
|
+
if (currentSubmitId === submitSeq) {
|
|
306
|
+
isSubmitting.value = false;
|
|
307
|
+
}
|
|
289
308
|
}
|
|
290
309
|
};
|
|
291
310
|
}
|
|
@@ -48,7 +48,7 @@ export function usePresetComponent(componentBaseName, defaultComponent) {
|
|
|
48
48
|
const externalLoaders = _loadersRegistry[presetName];
|
|
49
49
|
if (externalLoaders) {
|
|
50
50
|
const key = `./components/${componentBaseName}/${componentBaseName}.vue`;
|
|
51
|
-
const candidate = externalLoaders[key];
|
|
51
|
+
const candidate = externalLoaders[key] || externalLoaders[componentBaseName] || externalLoaders[`${componentBaseName}.vue`];
|
|
52
52
|
if (candidate) {
|
|
53
53
|
if (isDirectComponent(candidate)) {
|
|
54
54
|
return candidate;
|
|
@@ -179,9 +179,10 @@ export function useVirtualScroll(options) {
|
|
|
179
179
|
const remainingRows = Math.max(0, totalRows.value - endRowIndex.value);
|
|
180
180
|
return remainingRows * baseItemHeight.value;
|
|
181
181
|
});
|
|
182
|
-
watch(totalHeight, (newTotal) => {
|
|
183
|
-
|
|
184
|
-
|
|
182
|
+
watch([totalHeight, viewportHeight], ([newTotal, newVp]) => {
|
|
183
|
+
const maxScroll = Math.max(0, newTotal - newVp);
|
|
184
|
+
if (scrollTop.value > maxScroll) {
|
|
185
|
+
scrollTop.value = maxScroll;
|
|
185
186
|
if (containerRef.value) {
|
|
186
187
|
containerRef.value.scrollTop = scrollTop.value;
|
|
187
188
|
}
|
|
@@ -212,10 +213,16 @@ export function useVirtualScroll(options) {
|
|
|
212
213
|
const targetScrollTop2 = Math.max(0, (rowOffsets.value[index] || 0) - offset);
|
|
213
214
|
scrollTop.value = targetScrollTop2;
|
|
214
215
|
if (containerRef.value) {
|
|
215
|
-
containerRef.value.
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
216
|
+
containerRef.value.scrollTop = targetScrollTop2;
|
|
217
|
+
if (typeof containerRef.value.scrollTo === "function") {
|
|
218
|
+
try {
|
|
219
|
+
containerRef.value.scrollTo({
|
|
220
|
+
top: targetScrollTop2,
|
|
221
|
+
behavior
|
|
222
|
+
});
|
|
223
|
+
} catch {
|
|
224
|
+
}
|
|
225
|
+
}
|
|
219
226
|
}
|
|
220
227
|
return;
|
|
221
228
|
}
|
|
@@ -223,10 +230,16 @@ export function useVirtualScroll(options) {
|
|
|
223
230
|
const targetScrollTop = Math.max(0, targetRow * baseItemHeight.value - offset);
|
|
224
231
|
scrollTop.value = targetScrollTop;
|
|
225
232
|
if (containerRef.value) {
|
|
226
|
-
containerRef.value.
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
233
|
+
containerRef.value.scrollTop = targetScrollTop;
|
|
234
|
+
if (typeof containerRef.value.scrollTo === "function") {
|
|
235
|
+
try {
|
|
236
|
+
containerRef.value.scrollTo({
|
|
237
|
+
top: targetScrollTop,
|
|
238
|
+
behavior
|
|
239
|
+
});
|
|
240
|
+
} catch {
|
|
241
|
+
}
|
|
242
|
+
}
|
|
230
243
|
}
|
|
231
244
|
};
|
|
232
245
|
return {
|
|
@@ -1,18 +1,24 @@
|
|
|
1
1
|
type __VLS_Props = {
|
|
2
|
-
model
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
model?: any;
|
|
3
|
+
modelValue?: any;
|
|
4
|
+
checkboxValue?: any;
|
|
5
|
+
isDisabled?: boolean;
|
|
5
6
|
label?: string;
|
|
6
7
|
validation?: 'success' | 'warning' | 'error' | null;
|
|
7
8
|
validationText?: string;
|
|
8
9
|
idKey?: string;
|
|
10
|
+
indeterminate?: boolean;
|
|
9
11
|
};
|
|
10
12
|
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
|
|
13
|
+
"update:modelValue": (value: any) => any;
|
|
11
14
|
blur: (event: FocusEvent) => any;
|
|
12
15
|
"update:model": (value: any) => any;
|
|
16
|
+
"update:indeterminate": (value: boolean) => any;
|
|
13
17
|
}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
|
|
18
|
+
"onUpdate:modelValue"?: ((value: any) => any) | undefined;
|
|
14
19
|
onBlur?: ((event: FocusEvent) => any) | undefined;
|
|
15
20
|
"onUpdate:model"?: ((value: any) => any) | undefined;
|
|
21
|
+
"onUpdate:indeterminate"?: ((value: boolean) => any) | undefined;
|
|
16
22
|
}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
17
23
|
declare const _default: typeof __VLS_export;
|
|
18
24
|
export default _default;
|
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
.KCheckbox-wrapper
|
|
3
3
|
label.KCheckbox(
|
|
4
4
|
role="checkbox"
|
|
5
|
-
:aria-checked="isChecked"
|
|
5
|
+
:aria-checked="props.indeterminate ? 'mixed' : isChecked"
|
|
6
6
|
:aria-disabled="isDisabled"
|
|
7
7
|
tabindex="0"
|
|
8
8
|
@keydown.space.prevent="handleSpaceKey"
|
|
9
9
|
@blur="emit('blur', $event)"
|
|
10
10
|
)
|
|
11
|
-
input(type="checkbox" :checked="isChecked" :disabled="isDisabled" tabindex="-1" @change="toggleCheckbox")
|
|
12
|
-
.icon-container(:class="validation ? `is-${validation}` : ''")
|
|
13
|
-
KIcon.icon(iconname="check")
|
|
11
|
+
input(ref="inputRef" type="checkbox" :checked="isChecked" :indeterminate.prop="props.indeterminate" :disabled="isDisabled" tabindex="-1" @change="toggleCheckbox")
|
|
12
|
+
.icon-container(:class="[validation ? `is-${validation}` : '', { 'is-indeterminate': props.indeterminate }]")
|
|
13
|
+
KIcon.icon(:iconname="props.indeterminate ? 'minus' : 'check'")
|
|
14
14
|
span
|
|
15
15
|
slot(name="label")
|
|
16
16
|
slot
|
|
@@ -19,29 +19,43 @@
|
|
|
19
19
|
</template>
|
|
20
20
|
|
|
21
21
|
<script lang="ts" setup>
|
|
22
|
-
import { computed } from 'vue'
|
|
22
|
+
import { ref, computed, watch } from 'vue'
|
|
23
23
|
|
|
24
24
|
// Default template for KCheckbox
|
|
25
25
|
const props = defineProps<{
|
|
26
|
-
model
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
model?: any
|
|
27
|
+
modelValue?: any
|
|
28
|
+
checkboxValue?: any
|
|
29
|
+
isDisabled?: boolean
|
|
29
30
|
label?: string
|
|
30
31
|
validation?: 'success' | 'warning' | 'error' | null
|
|
31
32
|
validationText?: string
|
|
32
33
|
idKey?: string
|
|
34
|
+
indeterminate?: boolean
|
|
33
35
|
}>()
|
|
34
36
|
|
|
35
37
|
const emit = defineEmits<{
|
|
36
38
|
(e: 'update:model', value: any): void
|
|
39
|
+
(e: 'update:modelValue', value: any): void
|
|
40
|
+
(e: 'update:indeterminate', value: boolean): void
|
|
37
41
|
(e: 'blur', event: FocusEvent): void
|
|
38
42
|
}>()
|
|
39
43
|
|
|
40
44
|
const internalModel = computed({
|
|
41
|
-
get: () => props.model,
|
|
42
|
-
set: (value) =>
|
|
45
|
+
get: () => (props.modelValue !== undefined ? props.modelValue : props.model),
|
|
46
|
+
set: (value) => {
|
|
47
|
+
emit('update:model', value)
|
|
48
|
+
emit('update:modelValue', value)
|
|
49
|
+
}
|
|
43
50
|
})
|
|
44
51
|
|
|
52
|
+
const inputRef = ref<HTMLInputElement | null>(null)
|
|
53
|
+
watch(() => props.indeterminate, (val) => {
|
|
54
|
+
if (inputRef.value) {
|
|
55
|
+
inputRef.value.indeterminate = !!val
|
|
56
|
+
}
|
|
57
|
+
}, { immediate: true, flush: 'post' })
|
|
58
|
+
|
|
45
59
|
const getId = (item: any) => {
|
|
46
60
|
if (item && typeof item === 'object') {
|
|
47
61
|
const key = props.idKey
|
|
@@ -77,6 +91,9 @@ const isChecked = computed(() => {
|
|
|
77
91
|
|
|
78
92
|
function toggleCheckbox() {
|
|
79
93
|
if (props.isDisabled) return
|
|
94
|
+
if (props.indeterminate) {
|
|
95
|
+
emit('update:indeterminate', false)
|
|
96
|
+
}
|
|
80
97
|
if (Array.isArray(internalModel.value)) {
|
|
81
98
|
const val = props.checkboxValue
|
|
82
99
|
const arr = [...internalModel.value]
|
|
@@ -88,7 +105,11 @@ function toggleCheckbox() {
|
|
|
88
105
|
}
|
|
89
106
|
internalModel.value = arr
|
|
90
107
|
} else {
|
|
91
|
-
|
|
108
|
+
if (props.indeterminate) {
|
|
109
|
+
internalModel.value = true
|
|
110
|
+
} else {
|
|
111
|
+
internalModel.value = !internalModel.value
|
|
112
|
+
}
|
|
92
113
|
}
|
|
93
114
|
}
|
|
94
115
|
|
|
@@ -131,7 +152,9 @@ function handleSpaceKey() {
|
|
|
131
152
|
display: none;
|
|
132
153
|
}
|
|
133
154
|
|
|
134
|
-
:checked + .icon-container > .icon
|
|
155
|
+
:checked + .icon-container > .icon,
|
|
156
|
+
:indeterminate + .icon-container > .icon,
|
|
157
|
+
.icon-container.is-indeterminate > .icon {
|
|
135
158
|
display: block;
|
|
136
159
|
}
|
|
137
160
|
}
|
|
@@ -1,18 +1,24 @@
|
|
|
1
1
|
type __VLS_Props = {
|
|
2
|
-
model
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
model?: any;
|
|
3
|
+
modelValue?: any;
|
|
4
|
+
checkboxValue?: any;
|
|
5
|
+
isDisabled?: boolean;
|
|
5
6
|
label?: string;
|
|
6
7
|
validation?: 'success' | 'warning' | 'error' | null;
|
|
7
8
|
validationText?: string;
|
|
8
9
|
idKey?: string;
|
|
10
|
+
indeterminate?: boolean;
|
|
9
11
|
};
|
|
10
12
|
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
|
|
13
|
+
"update:modelValue": (value: any) => any;
|
|
11
14
|
blur: (event: FocusEvent) => any;
|
|
12
15
|
"update:model": (value: any) => any;
|
|
16
|
+
"update:indeterminate": (value: boolean) => any;
|
|
13
17
|
}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
|
|
18
|
+
"onUpdate:modelValue"?: ((value: any) => any) | undefined;
|
|
14
19
|
onBlur?: ((event: FocusEvent) => any) | undefined;
|
|
15
20
|
"onUpdate:model"?: ((value: any) => any) | undefined;
|
|
21
|
+
"onUpdate:indeterminate"?: ((value: boolean) => any) | undefined;
|
|
16
22
|
}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
17
23
|
declare const _default: typeof __VLS_export;
|
|
18
24
|
export default _default;
|
|
@@ -17,7 +17,11 @@
|
|
|
17
17
|
thead
|
|
18
18
|
tr
|
|
19
19
|
th.check(v-if="props.bulkActions && props.bulkActions.length > 0")
|
|
20
|
-
KCheckbox(
|
|
20
|
+
KCheckbox(
|
|
21
|
+
:model-value="isAllSelected"
|
|
22
|
+
:indeterminate="isIndeterminate"
|
|
23
|
+
@update:model-value="handleSelectAll"
|
|
24
|
+
)
|
|
21
25
|
th(
|
|
22
26
|
v-for="field in visibleFields || props.dataProvider.fields"
|
|
23
27
|
:key="field"
|
|
@@ -174,12 +178,57 @@ const isRowSelected = (row: any) => {
|
|
|
174
178
|
return selectedRowIds.value.has(rowId) || selectedRowIds.value.has(row)
|
|
175
179
|
}
|
|
176
180
|
|
|
181
|
+
const selectedCount = computed(() => {
|
|
182
|
+
if (selectAll.value) return datatableItems.value.length
|
|
183
|
+
let count = 0
|
|
184
|
+
const ids = selectedRowIds.value
|
|
185
|
+
const idKey = (props.dataProvider as any)?.idKey || 'id'
|
|
186
|
+
for (const r of datatableItems.value) {
|
|
187
|
+
const id = r?.[idKey] ?? r?.id ?? r?._id ?? r
|
|
188
|
+
if (ids.has(id) || ids.has(r)) count++
|
|
189
|
+
}
|
|
190
|
+
return count
|
|
191
|
+
})
|
|
192
|
+
|
|
193
|
+
const isAllSelected = computed(() => {
|
|
194
|
+
const total = datatableItems.value.length
|
|
195
|
+
if (total === 0) return false
|
|
196
|
+
if (selectAll.value) return true
|
|
197
|
+
return selectedCount.value === total
|
|
198
|
+
})
|
|
199
|
+
|
|
200
|
+
const isIndeterminate = computed(() => {
|
|
201
|
+
const total = datatableItems.value.length
|
|
202
|
+
if (total === 0) return false
|
|
203
|
+
if (isAllSelected.value) return false
|
|
204
|
+
return selectedCount.value > 0 || (selectedRows.value && selectedRows.value.length > 0)
|
|
205
|
+
})
|
|
206
|
+
|
|
207
|
+
const handleSelectAll = () => {
|
|
208
|
+
const total = datatableItems.value.length
|
|
209
|
+
if (total === 0) return
|
|
210
|
+
|
|
211
|
+
if (isAllSelected.value) {
|
|
212
|
+
selectAll.value = false
|
|
213
|
+
selectedRows.value = []
|
|
214
|
+
} else {
|
|
215
|
+
const isFiltered = !!((dpFilter as any)?.active || (dpFilter as any)?.value?.active || (props.dataProvider as any)?.filter?.active || (props.dataProvider as any)?.filter?.value?.active)
|
|
216
|
+
if (isFiltered) {
|
|
217
|
+
selectAll.value = false
|
|
218
|
+
selectedRows.value = [...datatableItems.value]
|
|
219
|
+
} else {
|
|
220
|
+
selectAll.value = true
|
|
221
|
+
selectedRows.value = [...datatableItems.value]
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
177
226
|
const toggleRow = (row: any) => {
|
|
178
227
|
const idKey = (props.dataProvider as any)?.idKey || 'id'
|
|
179
228
|
const rowId = row?.[idKey] ?? row?.id ?? row?._id ?? row
|
|
180
229
|
if (selectAll.value) {
|
|
181
230
|
selectAll.value = false
|
|
182
|
-
const activeRows =
|
|
231
|
+
const activeRows = datatableItems.value
|
|
183
232
|
selectedRows.value = activeRows.filter((r: any) => {
|
|
184
233
|
const rId = r?.[idKey] ?? r?.id ?? r?._id ?? r
|
|
185
234
|
return rId !== rowId && r !== row
|
|
@@ -187,12 +236,17 @@ const toggleRow = (row: any) => {
|
|
|
187
236
|
} else {
|
|
188
237
|
const isSelected = isRowSelected(row)
|
|
189
238
|
if (isSelected) {
|
|
190
|
-
|
|
239
|
+
const next = (selectedRows.value || []).filter((r: any) => {
|
|
191
240
|
const rId = r?.[idKey] ?? r?.id ?? r?._id ?? r
|
|
192
241
|
return rId !== rowId && r !== row
|
|
193
242
|
})
|
|
243
|
+
selectedRows.value = next
|
|
194
244
|
} else {
|
|
195
|
-
|
|
245
|
+
const next = [...(selectedRows.value || []), row]
|
|
246
|
+
selectedRows.value = next
|
|
247
|
+
if (next.length === datatableItems.value.length && datatableItems.value.length > 0) {
|
|
248
|
+
selectAll.value = true
|
|
249
|
+
}
|
|
196
250
|
}
|
|
197
251
|
}
|
|
198
252
|
}
|
|
@@ -234,9 +288,9 @@ const datatableItems = computed(() => {
|
|
|
234
288
|
const currentRows = pageRows.value
|
|
235
289
|
const dp = props.dataProvider as any
|
|
236
290
|
if (props.virtualScroll) {
|
|
291
|
+
if (Array.isArray(virtualRows?.value)) return virtualRows.value
|
|
237
292
|
if (Array.isArray(dp?.rowMap)) return dp.rowMap
|
|
238
293
|
if (Array.isArray(dp?.rowMap?.value)) return dp.rowMap.value
|
|
239
|
-
if (Array.isArray(virtualRows?.value) && virtualRows.value.length > 0) return virtualRows.value
|
|
240
294
|
if (Array.isArray(dp?.allVisibleRows)) return dp.allVisibleRows
|
|
241
295
|
if (Array.isArray(dp?.allVisibleRows?.value)) return dp.allVisibleRows.value
|
|
242
296
|
if (Array.isArray(dp?.allVisibleNodes)) return dp.allVisibleNodes
|
|
@@ -257,12 +311,13 @@ const {
|
|
|
257
311
|
containerRef,
|
|
258
312
|
onScroll,
|
|
259
313
|
scrollToIndex,
|
|
260
|
-
containerCssVars
|
|
314
|
+
containerCssVars,
|
|
315
|
+
scrollTop
|
|
261
316
|
} = useVirtualScroll({
|
|
262
317
|
items: datatableItems,
|
|
263
|
-
itemHeight: props.itemHeight || 40,
|
|
264
|
-
containerHeight: props.viewportHeight || 500,
|
|
265
|
-
buffer: props.buffer ?? 5,
|
|
318
|
+
itemHeight: computed(() => props.itemHeight || 40),
|
|
319
|
+
containerHeight: computed(() => props.viewportHeight || 500),
|
|
320
|
+
buffer: computed(() => props.buffer ?? 5),
|
|
266
321
|
virtualScroll: computed(() => !!props.virtualScroll),
|
|
267
322
|
onThresholdReach: () => {
|
|
268
323
|
const dp = props.dataProvider as any
|
|
@@ -295,24 +350,59 @@ const handleKeyDown = (e: KeyboardEvent) => {
|
|
|
295
350
|
const total = datatableItems.value.length
|
|
296
351
|
if (total === 0) return
|
|
297
352
|
|
|
353
|
+
const itemH = props.itemHeight || 40
|
|
354
|
+
const vpH = props.viewportHeight || 500
|
|
355
|
+
const firstInView = Math.floor(scrollTop.value / itemH)
|
|
356
|
+
const lastInView = Math.min(total - 1, Math.floor((scrollTop.value + vpH) / itemH) - 1)
|
|
357
|
+
|
|
358
|
+
const ensureVisible = (index: number) => {
|
|
359
|
+
const rowTop = index * itemH
|
|
360
|
+
const rowBottom = rowTop + itemH
|
|
361
|
+
if (rowTop < scrollTop.value) {
|
|
362
|
+
scrollToIndex(index, 'auto', index > 0 ? theadStickyOffset : 0)
|
|
363
|
+
} else if (rowBottom > scrollTop.value + vpH) {
|
|
364
|
+
const targetScroll = Math.max(0, rowBottom - vpH)
|
|
365
|
+
scrollTop.value = targetScroll
|
|
366
|
+
if (containerRef.value) {
|
|
367
|
+
containerRef.value.scrollTop = targetScroll
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
|
|
298
372
|
if (e.key === 'ArrowDown') {
|
|
299
373
|
e.preventDefault()
|
|
300
|
-
focusedIndex.value
|
|
301
|
-
|
|
374
|
+
if (focusedIndex.value < firstInView || focusedIndex.value > lastInView) {
|
|
375
|
+
focusedIndex.value = Math.min(total - 1, firstInView)
|
|
376
|
+
} else {
|
|
377
|
+
focusedIndex.value = Math.min(total - 1, focusedIndex.value + 1)
|
|
378
|
+
}
|
|
379
|
+
ensureVisible(focusedIndex.value)
|
|
302
380
|
} else if (e.key === 'ArrowUp') {
|
|
303
381
|
e.preventDefault()
|
|
304
|
-
focusedIndex.value
|
|
305
|
-
|
|
382
|
+
if (focusedIndex.value < firstInView || focusedIndex.value > lastInView) {
|
|
383
|
+
focusedIndex.value = Math.max(0, lastInView)
|
|
384
|
+
} else {
|
|
385
|
+
focusedIndex.value = Math.max(0, focusedIndex.value - 1)
|
|
386
|
+
}
|
|
387
|
+
ensureVisible(focusedIndex.value)
|
|
306
388
|
} else if (e.key === 'PageDown') {
|
|
307
389
|
e.preventDefault()
|
|
308
|
-
const step = Math.floor(
|
|
309
|
-
focusedIndex.value
|
|
310
|
-
|
|
390
|
+
const step = Math.max(1, Math.floor(vpH / itemH))
|
|
391
|
+
if (focusedIndex.value < firstInView || focusedIndex.value > lastInView) {
|
|
392
|
+
focusedIndex.value = Math.min(total - 1, firstInView + step)
|
|
393
|
+
} else {
|
|
394
|
+
focusedIndex.value = Math.min(total - 1, focusedIndex.value + step)
|
|
395
|
+
}
|
|
396
|
+
ensureVisible(focusedIndex.value)
|
|
311
397
|
} else if (e.key === 'PageUp') {
|
|
312
398
|
e.preventDefault()
|
|
313
|
-
const step = Math.floor(
|
|
314
|
-
focusedIndex.value
|
|
315
|
-
|
|
399
|
+
const step = Math.max(1, Math.floor(vpH / itemH))
|
|
400
|
+
if (focusedIndex.value < firstInView || focusedIndex.value > lastInView) {
|
|
401
|
+
focusedIndex.value = Math.max(0, lastInView - step)
|
|
402
|
+
} else {
|
|
403
|
+
focusedIndex.value = Math.max(0, focusedIndex.value - step)
|
|
404
|
+
}
|
|
405
|
+
ensureVisible(focusedIndex.value)
|
|
316
406
|
} else if (e.key === 'Home') {
|
|
317
407
|
e.preventDefault()
|
|
318
408
|
focusedIndex.value = 0
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
<template lang="pug">
|
|
2
2
|
span.KIcon(
|
|
3
|
-
v-if="
|
|
3
|
+
v-if="sanitizedIcon"
|
|
4
4
|
:style="iconStyle"
|
|
5
|
-
v-html="
|
|
5
|
+
v-html="sanitizedIcon"
|
|
6
6
|
)
|
|
7
7
|
</template>
|
|
8
8
|
|
|
9
9
|
<script lang="ts" setup>
|
|
10
10
|
import { computed } from 'vue'
|
|
11
|
+
import { sanitizeHtml } from '../../../../utils/sanitize'
|
|
11
12
|
|
|
12
13
|
const props = defineProps<{
|
|
13
14
|
widthPx?: string
|
|
@@ -16,6 +17,8 @@ const props = defineProps<{
|
|
|
16
17
|
rotate: number | string
|
|
17
18
|
}>()
|
|
18
19
|
|
|
20
|
+
const sanitizedIcon = computed(() => sanitizeHtml(props.iconComponent))
|
|
21
|
+
|
|
19
22
|
const iconStyle = computed(() => ({
|
|
20
23
|
width: props.widthPx,
|
|
21
24
|
height: props.heightPx,
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
:aria-disabled="disabled"
|
|
7
7
|
tabindex="0"
|
|
8
8
|
@keydown.space.prevent="model = value"
|
|
9
|
+
@click="!disabled && (model = value)"
|
|
9
10
|
)
|
|
10
11
|
input(type="radio" v-model="model" :disabled="disabled" :value="value" tabindex="-1")
|
|
11
12
|
.icon-container(:class="validation ? `is-${validation}` : ''")
|
|
@@ -13,6 +13,8 @@ type __VLS_Props = {
|
|
|
13
13
|
selectable?: boolean;
|
|
14
14
|
dataProvider?: any;
|
|
15
15
|
searchtext?: string;
|
|
16
|
+
modelValue?: any;
|
|
17
|
+
selectedNode?: any;
|
|
16
18
|
virtualScroll?: boolean;
|
|
17
19
|
itemHeight?: number;
|
|
18
20
|
viewportHeight?: number;
|
|
@@ -20,10 +22,8 @@ type __VLS_Props = {
|
|
|
20
22
|
};
|
|
21
23
|
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
|
|
22
24
|
select: (row: TTreeRow) => any;
|
|
23
|
-
"node-toggle": (id: string | number) => any;
|
|
24
25
|
}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
|
|
25
26
|
onSelect?: ((row: TTreeRow) => any) | undefined;
|
|
26
|
-
"onNode-toggle"?: ((id: string | number) => any) | undefined;
|
|
27
27
|
}>, {
|
|
28
28
|
disabled: boolean;
|
|
29
29
|
idKey: string;
|
|
@@ -35,8 +35,8 @@ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {
|
|
|
35
35
|
multiSelect: boolean;
|
|
36
36
|
viewportHeight: number;
|
|
37
37
|
iconField: string;
|
|
38
|
-
isNodeSelected: (node: any) => boolean;
|
|
39
38
|
selectable: boolean;
|
|
39
|
+
isNodeSelected: (node: any) => boolean;
|
|
40
40
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
41
41
|
declare const _default: typeof __VLS_export;
|
|
42
42
|
export default _default;
|