@katlux/toolkit 0.1.1-alpha.118 → 0.1.1-alpha.119
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/create-preset.mjs +5 -4
- package/dist/compiled/composables/useKatluxContext.mjs +6 -3
- package/dist/compiled/composables/useKatluxForm.mjs +268 -0
- package/dist/compiled/composables/useToast.mjs +164 -0
- package/dist/compiled/composables/useVirtualScroll.mjs +176 -0
- package/dist/module.cjs +1 -0
- package/dist/module.json +1 -1
- package/dist/module.mjs +1 -0
- package/dist/runtime/components/KBulkActions/KBulkActions.global.d.vue.ts +6 -2
- package/dist/runtime/components/KBulkActions/KBulkActions.global.vue +3 -3
- package/dist/runtime/components/KBulkActions/KBulkActions.global.vue.d.ts +6 -2
- package/dist/runtime/components/KBulkActions/KBulkActions.logic.js +9 -0
- package/dist/runtime/components/KCombobox/KCombobox.global.d.vue.ts +9 -0
- package/dist/runtime/components/KCombobox/KCombobox.global.vue +2 -1
- package/dist/runtime/components/KCombobox/KCombobox.global.vue.d.ts +9 -0
- package/dist/runtime/components/KCombobox/KCombobox.logic.d.ts +5 -0
- package/dist/runtime/components/KCombobox/KCombobox.logic.js +22 -3
- package/dist/runtime/components/KDatatable/KDataIterator.global.d.vue.ts +8 -0
- package/dist/runtime/components/KDatatable/KDataIterator.global.vue +10 -2
- package/dist/runtime/components/KDatatable/KDataIterator.global.vue.d.ts +8 -0
- package/dist/runtime/components/KDatatable/KDataIterator.logic.d.ts +8 -0
- package/dist/runtime/components/KDatatable/KDataIterator.logic.js +10 -2
- package/dist/runtime/components/KDatatable/KDatatable.global.d.vue.ts +8 -0
- package/dist/runtime/components/KDatatable/KDatatable.global.vue +12 -4
- package/dist/runtime/components/KDatatable/KDatatable.global.vue.d.ts +8 -0
- package/dist/runtime/components/KDatatable/KDatatable.logic.d.ts +8 -0
- package/dist/runtime/components/KDatatable/KDatatable.logic.js +11 -3
- package/dist/runtime/components/KDatePicker/KDatePicker.global.d.vue.ts +2 -0
- package/dist/runtime/components/KDatePicker/KDatePicker.global.vue +5 -1
- package/dist/runtime/components/KDatePicker/KDatePicker.global.vue.d.ts +2 -0
- package/dist/runtime/components/KDatePicker/KDatePicker.logic.js +7 -6
- package/dist/runtime/components/KDateTimePicker/KDateTimePicker.logic.js +7 -6
- package/dist/runtime/components/KDropdown/KDropdown.global.d.vue.ts +9 -0
- package/dist/runtime/components/KDropdown/KDropdown.global.vue +2 -1
- package/dist/runtime/components/KDropdown/KDropdown.global.vue.d.ts +9 -0
- package/dist/runtime/components/KDropdown/KDropdown.logic.d.ts +5 -0
- package/dist/runtime/components/KDropdown/KDropdown.logic.js +10 -7
- package/dist/runtime/components/KGantt/KGantt.logic.js +11 -4
- package/dist/runtime/components/KPagination/KPagination.logic.js +7 -4
- package/dist/runtime/components/KToast/KToast.global.d.vue.ts +24 -1
- package/dist/runtime/components/KToast/KToast.global.vue +12 -2
- package/dist/runtime/components/KToast/KToast.global.vue.d.ts +24 -1
- package/dist/runtime/components/KToast/KToast.logic.d.ts +13 -0
- package/dist/runtime/components/KToast/KToast.logic.js +45 -5
- package/dist/runtime/components/KToastContainer/KToastContainer.global.d.vue.ts +3 -0
- package/dist/runtime/components/KToastContainer/KToastContainer.global.vue +11 -0
- package/dist/runtime/components/KToastContainer/KToastContainer.global.vue.d.ts +3 -0
- package/dist/runtime/components/KTooltip/KTooltip.global.d.vue.ts +1 -1
- package/dist/runtime/components/KTooltip/KTooltip.global.vue.d.ts +1 -1
- package/dist/runtime/components/KTree/KTree.global.d.vue.ts +38 -0
- package/dist/runtime/components/KTree/KTree.global.vue +7 -3
- package/dist/runtime/components/KTree/KTree.global.vue.d.ts +38 -0
- package/dist/runtime/components/KTree/KTree.logic.d.ts +21 -0
- package/dist/runtime/components/KTree/KTree.logic.js +17 -0
- package/dist/runtime/components/KTreePicker/KTreePicker.global.d.vue.ts +52 -1
- package/dist/runtime/components/KTreePicker/KTreePicker.global.vue +30 -3
- package/dist/runtime/components/KTreePicker/KTreePicker.global.vue.d.ts +52 -1
- package/dist/runtime/components/KTreePicker/KTreePicker.logic.d.ts +20 -0
- package/dist/runtime/components/KTreePicker/KTreePicker.logic.js +16 -0
- package/dist/runtime/components/KTreeView/KTreeView.global.d.vue.ts +36 -0
- package/dist/runtime/components/KTreeView/KTreeView.global.vue +5 -1
- package/dist/runtime/components/KTreeView/KTreeView.global.vue.d.ts +36 -0
- package/dist/runtime/components/KTreeView/KTreeView.logic.d.ts +20 -0
- package/dist/runtime/components/KTreeView/KTreeView.logic.js +16 -0
- package/dist/runtime/composables/useKatluxContext.js +6 -3
- package/dist/runtime/composables/useKatluxForm.d.ts +143 -0
- package/dist/runtime/composables/useKatluxForm.js +268 -0
- package/dist/runtime/composables/useToast.d.ts +49 -0
- package/dist/runtime/composables/useToast.js +164 -0
- package/dist/runtime/composables/useVirtualScroll.d.ts +34 -0
- package/dist/runtime/composables/useVirtualScroll.js +176 -0
- package/dist/runtime/plugins/PresetPlugin.js +9 -1
- package/dist/runtime/plugins/nuxtCompatPlugin.js +0 -1
- package/dist/runtime/plugins/toastPlugin.client.d.ts +2 -0
- package/dist/runtime/plugins/toastPlugin.client.js +16 -0
- package/dist/runtime/presets/default/components/KBulkActions/KBulkActions.vue +1 -0
- package/dist/runtime/presets/default/components/KCheckbox/KCheckbox.vue +36 -7
- package/dist/runtime/presets/default/components/KCombobox/KCombobox.d.vue.ts +1 -0
- package/dist/runtime/presets/default/components/KCombobox/KCombobox.vue +10 -4
- package/dist/runtime/presets/default/components/KCombobox/KCombobox.vue.d.ts +1 -0
- package/dist/runtime/presets/default/components/KCombobox/KComboboxList.d.vue.ts +1 -0
- package/dist/runtime/presets/default/components/KCombobox/KComboboxList.vue +7 -2
- package/dist/runtime/presets/default/components/KCombobox/KComboboxList.vue.d.ts +1 -0
- package/dist/runtime/presets/default/components/KDataIterator/KDataIterator.d.vue.ts +10 -1
- package/dist/runtime/presets/default/components/KDataIterator/KDataIterator.vue +128 -6
- package/dist/runtime/presets/default/components/KDataIterator/KDataIterator.vue.d.ts +10 -1
- package/dist/runtime/presets/default/components/KDatatable/KDatatable.d.vue.ts +12 -1
- package/dist/runtime/presets/default/components/KDatatable/KDatatable.vue +206 -27
- package/dist/runtime/presets/default/components/KDatatable/KDatatable.vue.d.ts +12 -1
- package/dist/runtime/presets/default/components/KDropdown/KDropdown.d.vue.ts +1 -0
- package/dist/runtime/presets/default/components/KDropdown/KDropdown.vue +23 -2
- package/dist/runtime/presets/default/components/KDropdown/KDropdown.vue.d.ts +1 -0
- package/dist/runtime/presets/default/components/KLayout/KLayout.vue +4 -2
- package/dist/runtime/presets/default/components/KModal/KModal.vue +8 -1
- package/dist/runtime/presets/default/components/KTabs/KTabItem.vue +1 -1
- package/dist/runtime/presets/default/components/KTextbox/KTextbox.vue +6 -4
- package/dist/runtime/presets/default/components/KToast/KToast.d.vue.ts +6 -0
- package/dist/runtime/presets/default/components/KToast/KToast.vue +22 -4
- package/dist/runtime/presets/default/components/KToast/KToast.vue.d.ts +6 -0
- package/dist/runtime/presets/default/components/KToastContainer/KToastContainer.d.vue.ts +11 -0
- package/dist/runtime/presets/default/components/KToastContainer/KToastContainer.vue +207 -0
- package/dist/runtime/presets/default/components/KToastContainer/KToastContainer.vue.d.ts +11 -0
- package/dist/runtime/presets/default/components/KTree/KTree.d.vue.ts +15 -5
- package/dist/runtime/presets/default/components/KTree/KTree.vue +232 -13
- package/dist/runtime/presets/default/components/KTree/KTree.vue.d.ts +15 -5
- package/dist/runtime/presets/default/components/KTreePicker/KTreePicker.d.vue.ts +14 -1
- package/dist/runtime/presets/default/components/KTreePicker/KTreePicker.vue +118 -13
- package/dist/runtime/presets/default/components/KTreePicker/KTreePicker.vue.d.ts +14 -1
- package/dist/runtime/presets/default/components/KTreeView/KTreeCell.vue +12 -3
- package/dist/runtime/presets/default/components/KTreeView/KTreeView.d.vue.ts +4 -0
- package/dist/runtime/presets/default/components/KTreeView/KTreeView.vue +8 -0
- package/dist/runtime/presets/default/components/KTreeView/KTreeView.vue.d.ts +4 -0
- package/dist/runtime/server/middleware/session.js +1 -1
- package/package.json +3 -4
- package/dist/compiled/composables/useDataProvider.spec.mjs +0 -157
- package/dist/compiled/composables/useKatluxContext.spec.mjs +0 -63
- package/dist/compiled/composables/useKatluxI18n.spec.mjs +0 -10
- package/dist/compiled/composables/usePresetComponent.spec.mjs +0 -106
- package/dist/compiled/composables/useTemplate.spec.mjs +0 -30
- package/dist/compiled/utils/PresetResolver.spec.mjs +0 -68
package/bin/create-preset.mjs
CHANGED
|
@@ -482,13 +482,14 @@ ${BOLD}Examples:${RESET}
|
|
|
482
482
|
let presetName = null
|
|
483
483
|
let basePreset = null
|
|
484
484
|
|
|
485
|
-
for (
|
|
485
|
+
for (let i = 0; i < args.length; i++) {
|
|
486
|
+
const arg = args[i]
|
|
486
487
|
if (arg.startsWith('--base=')) {
|
|
487
488
|
basePreset = arg.slice('--base='.length)
|
|
488
489
|
} else if (arg === '-b' || arg === '--base') {
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
490
|
+
if (i + 1 < args.length) {
|
|
491
|
+
basePreset = args[i + 1]
|
|
492
|
+
i++ // advance index so value is not consumed as presetName
|
|
492
493
|
}
|
|
493
494
|
} else if (!arg.startsWith('-') && !presetName) {
|
|
494
495
|
presetName = arg
|
|
@@ -11,9 +11,12 @@ export function useKatluxContext() {
|
|
|
11
11
|
return { event: evt };
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
|
-
const
|
|
15
|
-
if (
|
|
16
|
-
|
|
14
|
+
const getNuxtApp = globalThis.useNuxtApp;
|
|
15
|
+
if (typeof getNuxtApp === "function") {
|
|
16
|
+
const app = getNuxtApp();
|
|
17
|
+
if (app?.ssrContext?.event) {
|
|
18
|
+
return { event: app.ssrContext.event };
|
|
19
|
+
}
|
|
17
20
|
}
|
|
18
21
|
} catch {
|
|
19
22
|
}
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
import { ref, reactive, computed, nextTick } from "vue";
|
|
2
|
+
function getByPath(obj, path) {
|
|
3
|
+
if (!obj || !path) return void 0;
|
|
4
|
+
const parts = path.replace(/\[(\w+)\]/g, ".$1").split(".");
|
|
5
|
+
let current = obj;
|
|
6
|
+
for (const part of parts) {
|
|
7
|
+
if (current == null) return void 0;
|
|
8
|
+
current = current[part];
|
|
9
|
+
}
|
|
10
|
+
return current;
|
|
11
|
+
}
|
|
12
|
+
function setByPath(obj, path, value) {
|
|
13
|
+
if (!obj || !path) return;
|
|
14
|
+
const parts = path.replace(/\[(\w+)\]/g, ".$1").split(".");
|
|
15
|
+
let current = obj;
|
|
16
|
+
for (let i = 0; i < parts.length - 1; i++) {
|
|
17
|
+
const part = parts[i];
|
|
18
|
+
if (!(part in current) || current[part] == null || typeof current[part] !== "object") {
|
|
19
|
+
const nextPart = parts[i + 1];
|
|
20
|
+
current[part] = /^\d+$/.test(nextPart) ? [] : {};
|
|
21
|
+
}
|
|
22
|
+
current = current[part];
|
|
23
|
+
}
|
|
24
|
+
current[parts[parts.length - 1]] = value;
|
|
25
|
+
}
|
|
26
|
+
function deepClone(val) {
|
|
27
|
+
if (val === null || typeof val !== "object") return val;
|
|
28
|
+
if (Array.isArray(val)) return val.map(deepClone);
|
|
29
|
+
const copy = {};
|
|
30
|
+
for (const key of Object.keys(val)) {
|
|
31
|
+
copy[key] = deepClone(val[key]);
|
|
32
|
+
}
|
|
33
|
+
return copy;
|
|
34
|
+
}
|
|
35
|
+
export function useKatluxForm(options = {}) {
|
|
36
|
+
const initialValues = deepClone(options.initialValues || {});
|
|
37
|
+
const values = reactive(deepClone(initialValues));
|
|
38
|
+
const mode = options.mode || "onBlur";
|
|
39
|
+
const reValidateMode = options.reValidateMode || "onChange";
|
|
40
|
+
const focusOnError = options.focusOnError !== false;
|
|
41
|
+
const errors = ref({});
|
|
42
|
+
const touched = ref({});
|
|
43
|
+
const dirtyFields = ref({});
|
|
44
|
+
const isSubmitting = ref(false);
|
|
45
|
+
const submitCount = ref(0);
|
|
46
|
+
const isDirty = computed(() => Object.values(dirtyFields.value).some(Boolean));
|
|
47
|
+
const isValid = computed(() => Object.keys(errors.value).length === 0);
|
|
48
|
+
function parseValidationResult(rawResult, schemaType, dataToValidate) {
|
|
49
|
+
if (schemaType === "standard") {
|
|
50
|
+
if (rawResult.issues && rawResult.issues.length > 0) {
|
|
51
|
+
const errorMap = {};
|
|
52
|
+
for (const issue of rawResult.issues) {
|
|
53
|
+
const pathStr = issue.path && issue.path.length > 0 ? issue.path.map((seg) => typeof seg === "object" && seg !== null && "key" in seg ? seg.key : seg).join(".") : "";
|
|
54
|
+
if (!errorMap[pathStr]) {
|
|
55
|
+
errorMap[pathStr] = issue.message;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return { valid: false, output: dataToValidate, errors: errorMap };
|
|
59
|
+
}
|
|
60
|
+
return { valid: true, output: rawResult.value ?? dataToValidate, errors: {} };
|
|
61
|
+
}
|
|
62
|
+
if (schemaType === "zod") {
|
|
63
|
+
if (!rawResult.success) {
|
|
64
|
+
const errorMap = {};
|
|
65
|
+
for (const issue of rawResult.error.issues) {
|
|
66
|
+
const pathStr = issue.path ? issue.path.join(".") : "";
|
|
67
|
+
if (!errorMap[pathStr]) {
|
|
68
|
+
errorMap[pathStr] = issue.message;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return { valid: false, output: dataToValidate, errors: errorMap };
|
|
72
|
+
}
|
|
73
|
+
return { valid: true, output: rawResult.data ?? dataToValidate, errors: {} };
|
|
74
|
+
}
|
|
75
|
+
if (schemaType === "custom") {
|
|
76
|
+
const errorMap = rawResult || {};
|
|
77
|
+
const valid = Object.keys(errorMap).length === 0;
|
|
78
|
+
return { valid, output: dataToValidate, errors: errorMap };
|
|
79
|
+
}
|
|
80
|
+
return { valid: true, output: dataToValidate, errors: {} };
|
|
81
|
+
}
|
|
82
|
+
function runValidation(dataToValidate) {
|
|
83
|
+
const schema = options.schema;
|
|
84
|
+
if (!schema) {
|
|
85
|
+
return { valid: true, output: dataToValidate, errors: {} };
|
|
86
|
+
}
|
|
87
|
+
if ("~standard" in schema && typeof schema["~standard"]?.validate === "function") {
|
|
88
|
+
const res = schema["~standard"].validate(dataToValidate);
|
|
89
|
+
if (res && typeof res.then === "function") {
|
|
90
|
+
return res.then((r) => parseValidationResult(r, "standard", dataToValidate));
|
|
91
|
+
}
|
|
92
|
+
return parseValidationResult(res, "standard", dataToValidate);
|
|
93
|
+
}
|
|
94
|
+
if (typeof schema.safeParse === "function") {
|
|
95
|
+
const res = schema.safeParse(dataToValidate);
|
|
96
|
+
return parseValidationResult(res, "zod", dataToValidate);
|
|
97
|
+
}
|
|
98
|
+
if (typeof schema.safeParseAsync === "function") {
|
|
99
|
+
return schema.safeParseAsync(dataToValidate).then((res) => parseValidationResult(res, "zod", dataToValidate));
|
|
100
|
+
}
|
|
101
|
+
if (typeof schema === "function") {
|
|
102
|
+
const res = schema(dataToValidate);
|
|
103
|
+
if (res && typeof res.then === "function") {
|
|
104
|
+
return res.then((r) => parseValidationResult(r, "custom", dataToValidate));
|
|
105
|
+
}
|
|
106
|
+
return parseValidationResult(res, "custom", dataToValidate);
|
|
107
|
+
}
|
|
108
|
+
return { valid: true, output: dataToValidate, errors: {} };
|
|
109
|
+
}
|
|
110
|
+
function applyErrors(targetPath, newErrors) {
|
|
111
|
+
if (targetPath) {
|
|
112
|
+
if (newErrors[targetPath]) {
|
|
113
|
+
errors.value = { ...errors.value, [targetPath]: newErrors[targetPath] };
|
|
114
|
+
return false;
|
|
115
|
+
} else {
|
|
116
|
+
const nextErrors = { ...errors.value };
|
|
117
|
+
delete nextErrors[targetPath];
|
|
118
|
+
errors.value = nextErrors;
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
121
|
+
} else {
|
|
122
|
+
errors.value = newErrors;
|
|
123
|
+
return Object.keys(newErrors).length === 0;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
function validate(targetPath) {
|
|
127
|
+
const result = runValidation(values);
|
|
128
|
+
if (result && typeof result.then === "function") {
|
|
129
|
+
return result.then(({ errors: newErrors }) => applyErrors(targetPath, newErrors));
|
|
130
|
+
}
|
|
131
|
+
return applyErrors(targetPath, result.errors);
|
|
132
|
+
}
|
|
133
|
+
function setValue(path, val, opts = {}) {
|
|
134
|
+
setByPath(values, path, val);
|
|
135
|
+
if (opts.shouldDirty !== false) {
|
|
136
|
+
dirtyFields.value = { ...dirtyFields.value, [path]: true };
|
|
137
|
+
}
|
|
138
|
+
if (opts.shouldValidate) {
|
|
139
|
+
validate(path);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
function getValue(path) {
|
|
143
|
+
return getByPath(values, path);
|
|
144
|
+
}
|
|
145
|
+
function setError(path, message) {
|
|
146
|
+
errors.value = { ...errors.value, [path]: message };
|
|
147
|
+
}
|
|
148
|
+
function clearErrors(path) {
|
|
149
|
+
if (path) {
|
|
150
|
+
const nextErrors = { ...errors.value };
|
|
151
|
+
delete nextErrors[path];
|
|
152
|
+
errors.value = nextErrors;
|
|
153
|
+
} else {
|
|
154
|
+
errors.value = {};
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
function setTouched(path, isTouchedVal = true) {
|
|
158
|
+
touched.value = { ...touched.value, [path]: isTouchedVal };
|
|
159
|
+
}
|
|
160
|
+
function reset(newValues) {
|
|
161
|
+
const targetValues = newValues ? deepClone(newValues) : deepClone(initialValues);
|
|
162
|
+
for (const key of Object.keys(values)) {
|
|
163
|
+
delete values[key];
|
|
164
|
+
}
|
|
165
|
+
Object.assign(values, targetValues);
|
|
166
|
+
errors.value = {};
|
|
167
|
+
touched.value = {};
|
|
168
|
+
dirtyFields.value = {};
|
|
169
|
+
submitCount.value = 0;
|
|
170
|
+
isSubmitting.value = false;
|
|
171
|
+
}
|
|
172
|
+
function register(path, regOptions = {}) {
|
|
173
|
+
return {
|
|
174
|
+
name: path,
|
|
175
|
+
get modelValue() {
|
|
176
|
+
return getByPath(values, path);
|
|
177
|
+
},
|
|
178
|
+
"onUpdate:modelValue": (newVal) => {
|
|
179
|
+
const transformed = regOptions.transform ? regOptions.transform(newVal) : newVal;
|
|
180
|
+
setByPath(values, path, transformed);
|
|
181
|
+
dirtyFields.value = { ...dirtyFields.value, [path]: true };
|
|
182
|
+
const hasActiveError = !!errors.value[path];
|
|
183
|
+
if (mode === "onChange" || hasActiveError && reValidateMode === "onChange") {
|
|
184
|
+
validate(path);
|
|
185
|
+
}
|
|
186
|
+
},
|
|
187
|
+
get validation() {
|
|
188
|
+
if (regOptions.validation !== void 0) {
|
|
189
|
+
return regOptions.validation;
|
|
190
|
+
}
|
|
191
|
+
return errors.value[path] ? "error" : null;
|
|
192
|
+
},
|
|
193
|
+
get validationText() {
|
|
194
|
+
if (regOptions.validationText !== void 0) {
|
|
195
|
+
return regOptions.validationText;
|
|
196
|
+
}
|
|
197
|
+
return errors.value[path] || "";
|
|
198
|
+
},
|
|
199
|
+
onBlur: () => {
|
|
200
|
+
touched.value = { ...touched.value, [path]: true };
|
|
201
|
+
const hasActiveError = !!errors.value[path];
|
|
202
|
+
if (mode === "onBlur" || hasActiveError && reValidateMode === "onBlur") {
|
|
203
|
+
validate(path);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
function focusFirstInvalid(fieldPath) {
|
|
209
|
+
if (typeof document === "undefined") return;
|
|
210
|
+
nextTick(() => {
|
|
211
|
+
const selector = `[name="${fieldPath}"], #${CSS.escape(fieldPath)}, [data-field="${CSS.escape(fieldPath)}"]`;
|
|
212
|
+
let el = document.querySelector(selector);
|
|
213
|
+
if (el) {
|
|
214
|
+
if (!["INPUT", "SELECT", "TEXTAREA", "BUTTON"].includes(el.tagName)) {
|
|
215
|
+
const inner = el.querySelector("input, select, textarea, [tabindex]");
|
|
216
|
+
if (inner) el = inner;
|
|
217
|
+
}
|
|
218
|
+
el.focus?.();
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
function handleSubmit(onValid, onInvalid) {
|
|
223
|
+
return async (event) => {
|
|
224
|
+
if (event && typeof event.preventDefault === "function") {
|
|
225
|
+
event.preventDefault();
|
|
226
|
+
}
|
|
227
|
+
submitCount.value += 1;
|
|
228
|
+
isSubmitting.value = true;
|
|
229
|
+
try {
|
|
230
|
+
const res = await runValidation(values);
|
|
231
|
+
const { valid, output, errors: newErrors } = res;
|
|
232
|
+
errors.value = newErrors;
|
|
233
|
+
if (!valid) {
|
|
234
|
+
const firstErrorKey = Object.keys(newErrors)[0];
|
|
235
|
+
if (focusOnError && firstErrorKey) {
|
|
236
|
+
focusFirstInvalid(firstErrorKey);
|
|
237
|
+
}
|
|
238
|
+
if (onInvalid) {
|
|
239
|
+
await onInvalid(newErrors, values);
|
|
240
|
+
}
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
await onValid(output, event);
|
|
244
|
+
} finally {
|
|
245
|
+
isSubmitting.value = false;
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
return {
|
|
250
|
+
values,
|
|
251
|
+
errors,
|
|
252
|
+
touched,
|
|
253
|
+
dirtyFields,
|
|
254
|
+
isDirty,
|
|
255
|
+
isValid,
|
|
256
|
+
isSubmitting,
|
|
257
|
+
submitCount,
|
|
258
|
+
register,
|
|
259
|
+
validate,
|
|
260
|
+
setValue,
|
|
261
|
+
getValue,
|
|
262
|
+
setError,
|
|
263
|
+
clearErrors,
|
|
264
|
+
setTouched,
|
|
265
|
+
reset,
|
|
266
|
+
handleSubmit
|
|
267
|
+
};
|
|
268
|
+
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { ref } from "vue";
|
|
2
|
+
const toastQueue = ref([]);
|
|
3
|
+
const isQueuePaused = ref(false);
|
|
4
|
+
let idCounter = 0;
|
|
5
|
+
export function useToast() {
|
|
6
|
+
const isClient = typeof window !== "undefined" && !import.meta?.server;
|
|
7
|
+
const dismiss = (id) => {
|
|
8
|
+
if (!isClient) return;
|
|
9
|
+
const index = toastQueue.value.findIndex((item) => item.id === id);
|
|
10
|
+
if (index !== -1) {
|
|
11
|
+
const item = toastQueue.value[index];
|
|
12
|
+
if (item.timerId) {
|
|
13
|
+
clearTimeout(item.timerId);
|
|
14
|
+
item.timerId = null;
|
|
15
|
+
}
|
|
16
|
+
if (typeof item.onClose === "function") {
|
|
17
|
+
try {
|
|
18
|
+
item.onClose();
|
|
19
|
+
} catch (e) {
|
|
20
|
+
console.error("[Katlux Toast] Error in onClose callback:", e);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
toastQueue.value.splice(index, 1);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
const clear = (position) => {
|
|
27
|
+
if (!isClient) return;
|
|
28
|
+
if (position) {
|
|
29
|
+
const itemsToRemove = toastQueue.value.filter((item) => item.position === position);
|
|
30
|
+
itemsToRemove.forEach((item) => dismiss(item.id));
|
|
31
|
+
} else {
|
|
32
|
+
toastQueue.value.forEach((item) => {
|
|
33
|
+
if (item.timerId) clearTimeout(item.timerId);
|
|
34
|
+
if (typeof item.onClose === "function") {
|
|
35
|
+
try {
|
|
36
|
+
item.onClose();
|
|
37
|
+
} catch (e) {
|
|
38
|
+
console.error("[Katlux Toast] Error in onClose callback:", e);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
toastQueue.value = [];
|
|
43
|
+
}
|
|
44
|
+
isQueuePaused.value = false;
|
|
45
|
+
};
|
|
46
|
+
const pauseAll = (position) => {
|
|
47
|
+
if (!isClient) return;
|
|
48
|
+
isQueuePaused.value = true;
|
|
49
|
+
const items = position ? toastQueue.value.filter((item) => item.position === position) : toastQueue.value;
|
|
50
|
+
items.forEach((item) => {
|
|
51
|
+
if (!item.pauseOnHover || item.paused || item.duration <= 0) return;
|
|
52
|
+
if (item.timerId) {
|
|
53
|
+
clearTimeout(item.timerId);
|
|
54
|
+
item.timerId = null;
|
|
55
|
+
}
|
|
56
|
+
const elapsed = Date.now() - item.startedAt;
|
|
57
|
+
item.remaining = Math.max(0, item.remaining - elapsed);
|
|
58
|
+
item.paused = true;
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
const resumeAll = (position) => {
|
|
62
|
+
if (!isClient) return;
|
|
63
|
+
isQueuePaused.value = false;
|
|
64
|
+
const items = position ? toastQueue.value.filter((item) => item.position === position) : toastQueue.value;
|
|
65
|
+
items.forEach((item) => {
|
|
66
|
+
if (!item.pauseOnHover || !item.paused || item.duration <= 0) return;
|
|
67
|
+
item.paused = false;
|
|
68
|
+
if (item.remaining > 0) {
|
|
69
|
+
item.startedAt = Date.now();
|
|
70
|
+
item.timerId = setTimeout(() => {
|
|
71
|
+
dismiss(item.id);
|
|
72
|
+
}, item.remaining);
|
|
73
|
+
} else {
|
|
74
|
+
dismiss(item.id);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
const pause = (_id, position) => {
|
|
79
|
+
pauseAll(position);
|
|
80
|
+
};
|
|
81
|
+
const resume = (_id, position) => {
|
|
82
|
+
resumeAll(position);
|
|
83
|
+
};
|
|
84
|
+
const show = (messageOrOptions, opts) => {
|
|
85
|
+
if (!isClient) return 0;
|
|
86
|
+
let options = {};
|
|
87
|
+
if (typeof messageOrOptions === "string") {
|
|
88
|
+
options = { text: messageOrOptions, ...opts };
|
|
89
|
+
} else {
|
|
90
|
+
options = { ...messageOrOptions, ...opts };
|
|
91
|
+
}
|
|
92
|
+
const id = options.id ?? `katlux-toast-${Date.now()}-${++idCounter}`;
|
|
93
|
+
const duration = options.duration ?? options.timeout ?? 3e3;
|
|
94
|
+
const position = options.position ?? "top-right";
|
|
95
|
+
const pauseOnHover = options.pauseOnHover ?? true;
|
|
96
|
+
const closeable = options.closeable ?? true;
|
|
97
|
+
const type = options.type ?? "info";
|
|
98
|
+
const text = options.text ?? "";
|
|
99
|
+
const title = options.title;
|
|
100
|
+
dismiss(id);
|
|
101
|
+
const item = {
|
|
102
|
+
id,
|
|
103
|
+
text,
|
|
104
|
+
title,
|
|
105
|
+
type,
|
|
106
|
+
duration,
|
|
107
|
+
position,
|
|
108
|
+
pauseOnHover,
|
|
109
|
+
closeable,
|
|
110
|
+
createdAt: Date.now(),
|
|
111
|
+
remaining: duration,
|
|
112
|
+
startedAt: Date.now(),
|
|
113
|
+
timerId: null,
|
|
114
|
+
paused: isQueuePaused.value,
|
|
115
|
+
onClose: options.onClose
|
|
116
|
+
};
|
|
117
|
+
if (isClient && duration > 0 && !isQueuePaused.value) {
|
|
118
|
+
item.timerId = setTimeout(() => {
|
|
119
|
+
dismiss(item.id);
|
|
120
|
+
}, duration);
|
|
121
|
+
}
|
|
122
|
+
toastQueue.value.push(item);
|
|
123
|
+
return id;
|
|
124
|
+
};
|
|
125
|
+
const success = (message, options) => {
|
|
126
|
+
return show(message, { ...options, type: "success" });
|
|
127
|
+
};
|
|
128
|
+
const error = (message, options) => {
|
|
129
|
+
return show(message, { ...options, type: "error" });
|
|
130
|
+
};
|
|
131
|
+
const danger = (message, options) => {
|
|
132
|
+
return show(message, { ...options, type: "danger" });
|
|
133
|
+
};
|
|
134
|
+
const warning = (message, options) => {
|
|
135
|
+
return show(message, { ...options, type: "warning" });
|
|
136
|
+
};
|
|
137
|
+
const info = (message, options) => {
|
|
138
|
+
return show(message, { ...options, type: "info" });
|
|
139
|
+
};
|
|
140
|
+
const primary = (message, options) => {
|
|
141
|
+
return show(message, { ...options, type: "primary" });
|
|
142
|
+
};
|
|
143
|
+
const defaultToast = (message, options) => {
|
|
144
|
+
return show(message, { ...options, type: "default" });
|
|
145
|
+
};
|
|
146
|
+
return {
|
|
147
|
+
toasts: toastQueue,
|
|
148
|
+
isQueuePaused,
|
|
149
|
+
show,
|
|
150
|
+
success,
|
|
151
|
+
error,
|
|
152
|
+
danger,
|
|
153
|
+
warning,
|
|
154
|
+
info,
|
|
155
|
+
primary,
|
|
156
|
+
default: defaultToast,
|
|
157
|
+
dismiss,
|
|
158
|
+
clear,
|
|
159
|
+
pause,
|
|
160
|
+
resume,
|
|
161
|
+
pauseAll,
|
|
162
|
+
resumeAll
|
|
163
|
+
};
|
|
164
|
+
}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { ref, computed, unref, watch, getCurrentScope, onScopeDispose } from "vue";
|
|
2
|
+
export function useVirtualScroll(options) {
|
|
3
|
+
const containerRef = ref(null);
|
|
4
|
+
const scrollTop = ref(0);
|
|
5
|
+
const resolveItems = () => {
|
|
6
|
+
if (typeof options.items === "function") {
|
|
7
|
+
return options.items();
|
|
8
|
+
}
|
|
9
|
+
return unref(options.items) || [];
|
|
10
|
+
};
|
|
11
|
+
const allItems = computed(() => resolveItems());
|
|
12
|
+
const totalCount = computed(() => allItems.value.length);
|
|
13
|
+
const isVirtual = computed(() => {
|
|
14
|
+
if (options.virtualScroll === void 0) return false;
|
|
15
|
+
return unref(options.virtualScroll) === true;
|
|
16
|
+
});
|
|
17
|
+
const colCount = computed(() => {
|
|
18
|
+
const c = unref(options.columns);
|
|
19
|
+
return typeof c === "number" && c > 1 ? c : 1;
|
|
20
|
+
});
|
|
21
|
+
const buf = computed(() => {
|
|
22
|
+
const b = unref(options.buffer);
|
|
23
|
+
return typeof b === "number" ? b : 5;
|
|
24
|
+
});
|
|
25
|
+
const defaultHeight = 40;
|
|
26
|
+
const getItemHeight = (item, index) => {
|
|
27
|
+
if (typeof options.itemHeight === "function") {
|
|
28
|
+
return options.itemHeight(item, index);
|
|
29
|
+
}
|
|
30
|
+
const h = unref(options.itemHeight);
|
|
31
|
+
return typeof h === "number" && h > 0 ? h : defaultHeight;
|
|
32
|
+
};
|
|
33
|
+
const baseItemHeight = computed(() => {
|
|
34
|
+
const h = unref(options.itemHeight);
|
|
35
|
+
if (typeof h === "number" && h > 0) return h;
|
|
36
|
+
return defaultHeight;
|
|
37
|
+
});
|
|
38
|
+
const resolveContainerHeight = () => {
|
|
39
|
+
if (typeof options.containerHeight === "function") {
|
|
40
|
+
return options.containerHeight() || 400;
|
|
41
|
+
}
|
|
42
|
+
const val = unref(options.containerHeight);
|
|
43
|
+
return typeof val === "number" && val > 0 ? val : 400;
|
|
44
|
+
};
|
|
45
|
+
const viewportHeight = ref(resolveContainerHeight());
|
|
46
|
+
watch(
|
|
47
|
+
() => resolveContainerHeight(),
|
|
48
|
+
(newH) => {
|
|
49
|
+
if (typeof newH === "number" && newH > 0) {
|
|
50
|
+
viewportHeight.value = newH;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
);
|
|
54
|
+
watch(containerRef, (el, oldEl) => {
|
|
55
|
+
if (typeof window === "undefined" || typeof ResizeObserver === "undefined") return;
|
|
56
|
+
if (oldEl && oldEl.__vsObserver) {
|
|
57
|
+
oldEl.__vsObserver.disconnect();
|
|
58
|
+
delete oldEl.__vsObserver;
|
|
59
|
+
}
|
|
60
|
+
if (el) {
|
|
61
|
+
const ro = new ResizeObserver((entries) => {
|
|
62
|
+
for (const entry of entries) {
|
|
63
|
+
const h = Math.round(entry.contentRect.height || el.clientHeight);
|
|
64
|
+
if (h > 0 && h !== viewportHeight.value) {
|
|
65
|
+
viewportHeight.value = h;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
ro.observe(el);
|
|
70
|
+
el.__vsObserver = ro;
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
if (getCurrentScope()) {
|
|
74
|
+
onScopeDispose(() => {
|
|
75
|
+
if (containerRef.value && containerRef.value.__vsObserver) {
|
|
76
|
+
containerRef.value.__vsObserver.disconnect();
|
|
77
|
+
delete containerRef.value.__vsObserver;
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
const totalRows = computed(() => {
|
|
82
|
+
if (colCount.value <= 1) return totalCount.value;
|
|
83
|
+
return Math.ceil(totalCount.value / colCount.value);
|
|
84
|
+
});
|
|
85
|
+
const startRowIndex = computed(() => {
|
|
86
|
+
if (!isVirtual.value) return 0;
|
|
87
|
+
const rawRow = Math.floor(scrollTop.value / baseItemHeight.value);
|
|
88
|
+
return Math.max(0, rawRow - buf.value);
|
|
89
|
+
});
|
|
90
|
+
const visibleRowsCount = computed(() => {
|
|
91
|
+
if (!isVirtual.value) return totalRows.value;
|
|
92
|
+
const rowsInView = Math.ceil(viewportHeight.value / baseItemHeight.value);
|
|
93
|
+
return rowsInView + 2 * buf.value + 1;
|
|
94
|
+
});
|
|
95
|
+
const endRowIndex = computed(() => {
|
|
96
|
+
if (!isVirtual.value) return totalRows.value;
|
|
97
|
+
return Math.min(totalRows.value, startRowIndex.value + visibleRowsCount.value);
|
|
98
|
+
});
|
|
99
|
+
const startIndex = computed(() => {
|
|
100
|
+
if (!isVirtual.value) return 0;
|
|
101
|
+
return Math.max(0, startRowIndex.value * colCount.value);
|
|
102
|
+
});
|
|
103
|
+
const endIndex = computed(() => {
|
|
104
|
+
if (!isVirtual.value) return totalCount.value;
|
|
105
|
+
return Math.min(totalCount.value, endRowIndex.value * colCount.value);
|
|
106
|
+
});
|
|
107
|
+
const visibleItems = computed(() => {
|
|
108
|
+
if (!isVirtual.value) return allItems.value;
|
|
109
|
+
return allItems.value.slice(startIndex.value, endIndex.value);
|
|
110
|
+
});
|
|
111
|
+
const topSpacerHeight = computed(() => {
|
|
112
|
+
if (!isVirtual.value) return 0;
|
|
113
|
+
return Math.max(0, startRowIndex.value * baseItemHeight.value);
|
|
114
|
+
});
|
|
115
|
+
const bottomSpacerHeight = computed(() => {
|
|
116
|
+
if (!isVirtual.value) return 0;
|
|
117
|
+
const remainingRows = Math.max(0, totalRows.value - endRowIndex.value);
|
|
118
|
+
return remainingRows * baseItemHeight.value;
|
|
119
|
+
});
|
|
120
|
+
const totalHeight = computed(() => {
|
|
121
|
+
return totalRows.value * baseItemHeight.value;
|
|
122
|
+
});
|
|
123
|
+
watch(totalHeight, (newTotal) => {
|
|
124
|
+
if (scrollTop.value > newTotal) {
|
|
125
|
+
scrollTop.value = Math.max(0, newTotal - viewportHeight.value);
|
|
126
|
+
if (containerRef.value) {
|
|
127
|
+
containerRef.value.scrollTop = scrollTop.value;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
const containerCssVars = computed(() => ({
|
|
132
|
+
"--virtual-spacer-top": `${topSpacerHeight.value}px`,
|
|
133
|
+
"--virtual-spacer-bottom": `${bottomSpacerHeight.value}px`,
|
|
134
|
+
"--virtual-total-height": `${totalHeight.value}px`,
|
|
135
|
+
"--virtual-item-height": `${baseItemHeight.value}px`,
|
|
136
|
+
"--virtual-container-height": `${viewportHeight.value}px`
|
|
137
|
+
}));
|
|
138
|
+
const scrollThreshold = options.scrollThreshold ?? 100;
|
|
139
|
+
const onScroll = (e) => {
|
|
140
|
+
const target = e.target;
|
|
141
|
+
if (!target) return;
|
|
142
|
+
scrollTop.value = target.scrollTop;
|
|
143
|
+
if (target.clientHeight && target.clientHeight !== viewportHeight.value) {
|
|
144
|
+
viewportHeight.value = target.clientHeight;
|
|
145
|
+
}
|
|
146
|
+
const distanceToBottom = target.scrollHeight - (target.scrollTop + target.clientHeight);
|
|
147
|
+
if (distanceToBottom <= scrollThreshold && typeof options.onThresholdReach === "function") {
|
|
148
|
+
options.onThresholdReach();
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
const scrollToIndex = (index, behavior = "auto") => {
|
|
152
|
+
const targetRow = colCount.value <= 1 ? index : Math.floor(index / colCount.value);
|
|
153
|
+
const targetScrollTop = targetRow * baseItemHeight.value;
|
|
154
|
+
scrollTop.value = targetScrollTop;
|
|
155
|
+
if (containerRef.value) {
|
|
156
|
+
containerRef.value.scrollTo({
|
|
157
|
+
top: targetScrollTop,
|
|
158
|
+
behavior
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
return {
|
|
163
|
+
startIndex,
|
|
164
|
+
endIndex,
|
|
165
|
+
visibleItems,
|
|
166
|
+
topSpacerHeight,
|
|
167
|
+
bottomSpacerHeight,
|
|
168
|
+
totalHeight,
|
|
169
|
+
scrollTop,
|
|
170
|
+
viewportHeight,
|
|
171
|
+
containerRef,
|
|
172
|
+
onScroll,
|
|
173
|
+
scrollToIndex,
|
|
174
|
+
containerCssVars
|
|
175
|
+
};
|
|
176
|
+
}
|
package/dist/module.cjs
CHANGED
|
@@ -42,6 +42,7 @@ const module$1 = kit.defineNuxtModule({
|
|
|
42
42
|
kit.addPlugin(resolve("./runtime/plugins/registerDirectives"));
|
|
43
43
|
kit.addPlugin(resolve("./runtime/plugins/PresetPlugin"));
|
|
44
44
|
kit.addPlugin(resolve("./runtime/plugins/nuxtCompatPlugin"));
|
|
45
|
+
kit.addPlugin(resolve("./runtime/plugins/toastPlugin.client"));
|
|
45
46
|
kit.addServerHandler({
|
|
46
47
|
handler: resolve("./runtime/server/middleware/session")
|
|
47
48
|
});
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -39,6 +39,7 @@ const module$1 = defineNuxtModule({
|
|
|
39
39
|
addPlugin(resolve("./runtime/plugins/registerDirectives"));
|
|
40
40
|
addPlugin(resolve("./runtime/plugins/PresetPlugin"));
|
|
41
41
|
addPlugin(resolve("./runtime/plugins/nuxtCompatPlugin"));
|
|
42
|
+
addPlugin(resolve("./runtime/plugins/toastPlugin.client"));
|
|
42
43
|
addServerHandler({
|
|
43
44
|
handler: resolve("./runtime/server/middleware/session")
|
|
44
45
|
});
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import type { IKDatatableAction, TDataRow } from '@katlux/providers';
|
|
2
2
|
interface Props {
|
|
3
|
+
bulkActions?: IKDatatableAction[];
|
|
4
|
+
selectedRows?: TDataRow[];
|
|
5
|
+
selectAll?: boolean;
|
|
6
|
+
}
|
|
7
|
+
declare const __VLS_export: import("vue").DefineComponent<Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<Props> & Readonly<{}>, {
|
|
3
8
|
bulkActions: IKDatatableAction[];
|
|
4
9
|
selectedRows: TDataRow[];
|
|
5
10
|
selectAll: boolean;
|
|
6
|
-
}
|
|
7
|
-
declare const __VLS_export: import("vue").DefineComponent<Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
11
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
8
12
|
declare const _default: typeof __VLS_export;
|
|
9
13
|
export default _default;
|