@katlux/toolkit 0.1.1-alpha.117 → 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.
Files changed (118) hide show
  1. package/bin/create-preset.mjs +373 -21
  2. package/dist/compiled/composables/useKatluxContext.mjs +6 -3
  3. package/dist/compiled/composables/useKatluxForm.mjs +268 -0
  4. package/dist/compiled/composables/useToast.mjs +164 -0
  5. package/dist/compiled/composables/useVirtualScroll.mjs +176 -0
  6. package/dist/module.cjs +1 -0
  7. package/dist/module.json +1 -1
  8. package/dist/module.mjs +1 -0
  9. package/dist/runtime/components/KBulkActions/KBulkActions.global.d.vue.ts +6 -2
  10. package/dist/runtime/components/KBulkActions/KBulkActions.global.vue +3 -3
  11. package/dist/runtime/components/KBulkActions/KBulkActions.global.vue.d.ts +6 -2
  12. package/dist/runtime/components/KBulkActions/KBulkActions.logic.js +9 -0
  13. package/dist/runtime/components/KCombobox/KCombobox.global.d.vue.ts +9 -0
  14. package/dist/runtime/components/KCombobox/KCombobox.global.vue +2 -1
  15. package/dist/runtime/components/KCombobox/KCombobox.global.vue.d.ts +9 -0
  16. package/dist/runtime/components/KCombobox/KCombobox.logic.d.ts +5 -0
  17. package/dist/runtime/components/KCombobox/KCombobox.logic.js +22 -3
  18. package/dist/runtime/components/KDatatable/KDataIterator.global.d.vue.ts +8 -0
  19. package/dist/runtime/components/KDatatable/KDataIterator.global.vue +10 -2
  20. package/dist/runtime/components/KDatatable/KDataIterator.global.vue.d.ts +8 -0
  21. package/dist/runtime/components/KDatatable/KDataIterator.logic.d.ts +8 -0
  22. package/dist/runtime/components/KDatatable/KDataIterator.logic.js +10 -2
  23. package/dist/runtime/components/KDatatable/KDatatable.global.d.vue.ts +8 -0
  24. package/dist/runtime/components/KDatatable/KDatatable.global.vue +12 -4
  25. package/dist/runtime/components/KDatatable/KDatatable.global.vue.d.ts +8 -0
  26. package/dist/runtime/components/KDatatable/KDatatable.logic.d.ts +8 -0
  27. package/dist/runtime/components/KDatatable/KDatatable.logic.js +11 -3
  28. package/dist/runtime/components/KDatePicker/KDatePicker.global.d.vue.ts +2 -0
  29. package/dist/runtime/components/KDatePicker/KDatePicker.global.vue +5 -1
  30. package/dist/runtime/components/KDatePicker/KDatePicker.global.vue.d.ts +2 -0
  31. package/dist/runtime/components/KDatePicker/KDatePicker.logic.js +7 -6
  32. package/dist/runtime/components/KDateTimePicker/KDateTimePicker.logic.js +7 -6
  33. package/dist/runtime/components/KDropdown/KDropdown.global.d.vue.ts +9 -0
  34. package/dist/runtime/components/KDropdown/KDropdown.global.vue +2 -1
  35. package/dist/runtime/components/KDropdown/KDropdown.global.vue.d.ts +9 -0
  36. package/dist/runtime/components/KDropdown/KDropdown.logic.d.ts +5 -0
  37. package/dist/runtime/components/KDropdown/KDropdown.logic.js +10 -7
  38. package/dist/runtime/components/KGantt/KGantt.logic.js +11 -4
  39. package/dist/runtime/components/KPagination/KPagination.logic.js +7 -4
  40. package/dist/runtime/components/KToast/KToast.global.d.vue.ts +24 -1
  41. package/dist/runtime/components/KToast/KToast.global.vue +12 -2
  42. package/dist/runtime/components/KToast/KToast.global.vue.d.ts +24 -1
  43. package/dist/runtime/components/KToast/KToast.logic.d.ts +13 -0
  44. package/dist/runtime/components/KToast/KToast.logic.js +45 -5
  45. package/dist/runtime/components/KToastContainer/KToastContainer.global.d.vue.ts +3 -0
  46. package/dist/runtime/components/KToastContainer/KToastContainer.global.vue +11 -0
  47. package/dist/runtime/components/KToastContainer/KToastContainer.global.vue.d.ts +3 -0
  48. package/dist/runtime/components/KTree/KTree.global.d.vue.ts +38 -0
  49. package/dist/runtime/components/KTree/KTree.global.vue +7 -3
  50. package/dist/runtime/components/KTree/KTree.global.vue.d.ts +38 -0
  51. package/dist/runtime/components/KTree/KTree.logic.d.ts +21 -0
  52. package/dist/runtime/components/KTree/KTree.logic.js +17 -0
  53. package/dist/runtime/components/KTreePicker/KTreePicker.global.d.vue.ts +52 -1
  54. package/dist/runtime/components/KTreePicker/KTreePicker.global.vue +30 -3
  55. package/dist/runtime/components/KTreePicker/KTreePicker.global.vue.d.ts +52 -1
  56. package/dist/runtime/components/KTreePicker/KTreePicker.logic.d.ts +20 -0
  57. package/dist/runtime/components/KTreePicker/KTreePicker.logic.js +16 -0
  58. package/dist/runtime/components/KTreeView/KTreeView.global.d.vue.ts +36 -0
  59. package/dist/runtime/components/KTreeView/KTreeView.global.vue +5 -1
  60. package/dist/runtime/components/KTreeView/KTreeView.global.vue.d.ts +36 -0
  61. package/dist/runtime/components/KTreeView/KTreeView.logic.d.ts +20 -0
  62. package/dist/runtime/components/KTreeView/KTreeView.logic.js +16 -0
  63. package/dist/runtime/composables/useKatluxContext.js +6 -3
  64. package/dist/runtime/composables/useKatluxForm.d.ts +143 -0
  65. package/dist/runtime/composables/useKatluxForm.js +268 -0
  66. package/dist/runtime/composables/useToast.d.ts +49 -0
  67. package/dist/runtime/composables/useToast.js +164 -0
  68. package/dist/runtime/composables/useVirtualScroll.d.ts +34 -0
  69. package/dist/runtime/composables/useVirtualScroll.js +176 -0
  70. package/dist/runtime/plugins/PresetPlugin.js +9 -1
  71. package/dist/runtime/plugins/nuxtCompatPlugin.js +0 -1
  72. package/dist/runtime/plugins/toastPlugin.client.d.ts +2 -0
  73. package/dist/runtime/plugins/toastPlugin.client.js +16 -0
  74. package/dist/runtime/presets/default/components/KBulkActions/KBulkActions.vue +1 -0
  75. package/dist/runtime/presets/default/components/KCheckbox/KCheckbox.vue +36 -7
  76. package/dist/runtime/presets/default/components/KCombobox/KCombobox.d.vue.ts +1 -0
  77. package/dist/runtime/presets/default/components/KCombobox/KCombobox.vue +10 -4
  78. package/dist/runtime/presets/default/components/KCombobox/KCombobox.vue.d.ts +1 -0
  79. package/dist/runtime/presets/default/components/KCombobox/KComboboxList.d.vue.ts +1 -0
  80. package/dist/runtime/presets/default/components/KCombobox/KComboboxList.vue +7 -2
  81. package/dist/runtime/presets/default/components/KCombobox/KComboboxList.vue.d.ts +1 -0
  82. package/dist/runtime/presets/default/components/KDataIterator/KDataIterator.d.vue.ts +10 -1
  83. package/dist/runtime/presets/default/components/KDataIterator/KDataIterator.vue +128 -6
  84. package/dist/runtime/presets/default/components/KDataIterator/KDataIterator.vue.d.ts +10 -1
  85. package/dist/runtime/presets/default/components/KDatatable/KDatatable.d.vue.ts +12 -1
  86. package/dist/runtime/presets/default/components/KDatatable/KDatatable.vue +206 -27
  87. package/dist/runtime/presets/default/components/KDatatable/KDatatable.vue.d.ts +12 -1
  88. package/dist/runtime/presets/default/components/KDropdown/KDropdown.d.vue.ts +1 -0
  89. package/dist/runtime/presets/default/components/KDropdown/KDropdown.vue +23 -2
  90. package/dist/runtime/presets/default/components/KDropdown/KDropdown.vue.d.ts +1 -0
  91. package/dist/runtime/presets/default/components/KLayout/KLayout.vue +4 -2
  92. package/dist/runtime/presets/default/components/KModal/KModal.vue +8 -1
  93. package/dist/runtime/presets/default/components/KTabs/KTabItem.vue +1 -1
  94. package/dist/runtime/presets/default/components/KTextbox/KTextbox.vue +6 -4
  95. package/dist/runtime/presets/default/components/KToast/KToast.d.vue.ts +6 -0
  96. package/dist/runtime/presets/default/components/KToast/KToast.vue +22 -4
  97. package/dist/runtime/presets/default/components/KToast/KToast.vue.d.ts +6 -0
  98. package/dist/runtime/presets/default/components/KToastContainer/KToastContainer.d.vue.ts +11 -0
  99. package/dist/runtime/presets/default/components/KToastContainer/KToastContainer.vue +207 -0
  100. package/dist/runtime/presets/default/components/KToastContainer/KToastContainer.vue.d.ts +11 -0
  101. package/dist/runtime/presets/default/components/KTree/KTree.d.vue.ts +15 -5
  102. package/dist/runtime/presets/default/components/KTree/KTree.vue +232 -13
  103. package/dist/runtime/presets/default/components/KTree/KTree.vue.d.ts +15 -5
  104. package/dist/runtime/presets/default/components/KTreePicker/KTreePicker.d.vue.ts +14 -1
  105. package/dist/runtime/presets/default/components/KTreePicker/KTreePicker.vue +118 -13
  106. package/dist/runtime/presets/default/components/KTreePicker/KTreePicker.vue.d.ts +14 -1
  107. package/dist/runtime/presets/default/components/KTreeView/KTreeCell.vue +12 -3
  108. package/dist/runtime/presets/default/components/KTreeView/KTreeView.d.vue.ts +4 -0
  109. package/dist/runtime/presets/default/components/KTreeView/KTreeView.vue +8 -0
  110. package/dist/runtime/presets/default/components/KTreeView/KTreeView.vue.d.ts +4 -0
  111. package/dist/runtime/server/middleware/session.js +1 -1
  112. package/package.json +3 -4
  113. package/dist/compiled/composables/useDataProvider.spec.mjs +0 -157
  114. package/dist/compiled/composables/useKatluxContext.spec.mjs +0 -63
  115. package/dist/compiled/composables/useKatluxI18n.spec.mjs +0 -10
  116. package/dist/compiled/composables/usePresetComponent.spec.mjs +0 -106
  117. package/dist/compiled/composables/useTemplate.spec.mjs +0 -30
  118. package/dist/compiled/utils/PresetResolver.spec.mjs +0 -68
@@ -0,0 +1,143 @@
1
+ import { type Ref, type ComputedRef } from 'vue';
2
+ /**
3
+ * Standard Schema V1 Specification interface (Lightweight definition)
4
+ * Compatible with @standard-schema/spec without forcing a runtime dependency.
5
+ */
6
+ export interface StandardSchemaV1<Input = unknown, Output = Input> {
7
+ readonly '~standard': {
8
+ readonly version: 1;
9
+ readonly vendor: string;
10
+ readonly validate: (value: unknown) => StandardSchemaV1.Result<Output> | Promise<StandardSchemaV1.Result<Output>>;
11
+ readonly types?: {
12
+ readonly input: Input;
13
+ readonly output: Output;
14
+ };
15
+ };
16
+ }
17
+ export declare namespace StandardSchemaV1 {
18
+ type Result<Output> = SuccessResult<Output> | FailureResult;
19
+ interface SuccessResult<Output> {
20
+ readonly value: Output;
21
+ readonly issues?: undefined;
22
+ }
23
+ interface FailureResult {
24
+ readonly issues: ReadonlyArray<Issue>;
25
+ }
26
+ interface Issue {
27
+ readonly message: string;
28
+ readonly path?: ReadonlyArray<PropertyKey | PathSegment>;
29
+ }
30
+ interface PathSegment {
31
+ readonly key: PropertyKey;
32
+ }
33
+ }
34
+ /**
35
+ * Zod-compatible schema interface
36
+ */
37
+ export interface ZodLikeSchema<TOutput = any> {
38
+ safeParse?: (data: unknown) => {
39
+ success: true;
40
+ data: TOutput;
41
+ } | {
42
+ success: false;
43
+ error: {
44
+ issues: Array<{
45
+ path: Array<string | number>;
46
+ message: string;
47
+ }>;
48
+ };
49
+ };
50
+ safeParseAsync?: (data: unknown) => Promise<{
51
+ success: true;
52
+ data: TOutput;
53
+ } | {
54
+ success: false;
55
+ error: {
56
+ issues: Array<{
57
+ path: Array<string | number>;
58
+ message: string;
59
+ }>;
60
+ };
61
+ }>;
62
+ }
63
+ /**
64
+ * Custom validation function
65
+ */
66
+ export type CustomValidator<T = any> = (values: T) => Record<string, string> | Promise<Record<string, string>>;
67
+ export type KatluxFormSchema<T = any> = StandardSchemaV1<any, T> | ZodLikeSchema<T> | CustomValidator<T>;
68
+ export type ValidationMode = 'onBlur' | 'onChange' | 'onSubmit';
69
+ export interface UseKatluxFormOptions<TValues extends Record<string, any> = Record<string, any>> {
70
+ /**
71
+ * Initial form values
72
+ */
73
+ initialValues?: TValues;
74
+ /**
75
+ * Schema or validator function (Standard Schema, Zod, or custom callback)
76
+ */
77
+ schema?: KatluxFormSchema<TValues>;
78
+ /**
79
+ * When to trigger validation for fields
80
+ * @default 'onBlur'
81
+ */
82
+ mode?: ValidationMode;
83
+ /**
84
+ * When to re-validate fields that currently have an active error
85
+ * @default 'onChange'
86
+ */
87
+ reValidateMode?: ValidationMode;
88
+ /**
89
+ * Automatically focus the first invalid field upon failed submission
90
+ * @default true
91
+ */
92
+ focusOnError?: boolean;
93
+ }
94
+ export interface RegisterOptions {
95
+ /**
96
+ * Transform value before saving to form state
97
+ */
98
+ transform?: (value: any) => any;
99
+ /**
100
+ * Custom validation state override (e.g. 'warning')
101
+ */
102
+ validation?: 'error' | 'warning' | 'success' | null;
103
+ /**
104
+ * Custom validation text override
105
+ */
106
+ validationText?: string;
107
+ }
108
+ export interface FieldBinding<T = any> {
109
+ name: string;
110
+ modelValue: T;
111
+ 'onUpdate:modelValue': (value: T) => void;
112
+ validation: 'error' | 'warning' | 'success' | null;
113
+ validationText: string;
114
+ onBlur: () => void;
115
+ }
116
+ /**
117
+ * Schema-based Form Validation Composable
118
+ *
119
+ * Provides reactive form state, zero-boilerplate component binding (`v-bind="register('fieldName')"`),
120
+ * standard schema / Zod validation interoperability, granular triggers, and error focus handling.
121
+ */
122
+ export declare function useKatluxForm<TValues extends Record<string, any> = Record<string, any>, TOutput = TValues>(options?: UseKatluxFormOptions<TValues>): {
123
+ values: import("vue").Reactive<TValues>;
124
+ errors: Ref<Record<string, string>, Record<string, string>>;
125
+ touched: Ref<Record<string, boolean>, Record<string, boolean>>;
126
+ dirtyFields: Ref<Record<string, boolean>, Record<string, boolean>>;
127
+ isDirty: ComputedRef<boolean>;
128
+ isValid: ComputedRef<boolean>;
129
+ isSubmitting: Ref<boolean, boolean>;
130
+ submitCount: Ref<number, number>;
131
+ register: <T = any>(path: string, regOptions?: RegisterOptions) => FieldBinding<T>;
132
+ validate: (targetPath?: string) => boolean | Promise<boolean>;
133
+ setValue: (path: string, val: any, opts?: {
134
+ shouldDirty?: boolean;
135
+ shouldValidate?: boolean;
136
+ }) => void;
137
+ getValue: (path: string) => any;
138
+ setError: (path: string, message: string) => void;
139
+ clearErrors: (path?: string) => void;
140
+ setTouched: (path: string, isTouchedVal?: boolean) => void;
141
+ reset: (newValues?: Partial<TValues>) => void;
142
+ handleSubmit: (onValid: (values: TOutput, event?: Event) => any | Promise<any>, onInvalid?: (errors: Record<string, string>, values: TValues) => any | Promise<any>) => (event?: Event) => Promise<void>;
143
+ };
@@ -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,49 @@
1
+ import { type Ref } from 'vue';
2
+ import type { KToastType, KToastPosition } from '../components/KToast/KToast.logic.js';
3
+ export type { KToastType, KToastPosition };
4
+ export interface KToastOptions {
5
+ id?: string | number;
6
+ text?: string;
7
+ title?: string;
8
+ type?: KToastType;
9
+ duration?: number;
10
+ timeout?: number;
11
+ position?: KToastPosition;
12
+ pauseOnHover?: boolean;
13
+ closeable?: boolean;
14
+ onClose?: () => void;
15
+ }
16
+ export interface KToastItem {
17
+ id: string | number;
18
+ text: string;
19
+ title?: string;
20
+ type: KToastType;
21
+ duration: number;
22
+ position: KToastPosition;
23
+ pauseOnHover: boolean;
24
+ closeable: boolean;
25
+ createdAt: number;
26
+ remaining: number;
27
+ startedAt: number;
28
+ timerId: any;
29
+ paused: boolean;
30
+ onClose?: () => void;
31
+ }
32
+ export declare function useToast(): {
33
+ toasts: Ref<KToastItem[], KToastItem[]>;
34
+ isQueuePaused: Ref<boolean, boolean>;
35
+ show: (messageOrOptions: string | KToastOptions, opts?: Partial<KToastOptions>) => string | number;
36
+ success: (message: string, options?: Partial<KToastOptions>) => string | number;
37
+ error: (message: string, options?: Partial<KToastOptions>) => string | number;
38
+ danger: (message: string, options?: Partial<KToastOptions>) => string | number;
39
+ warning: (message: string, options?: Partial<KToastOptions>) => string | number;
40
+ info: (message: string, options?: Partial<KToastOptions>) => string | number;
41
+ primary: (message: string, options?: Partial<KToastOptions>) => string | number;
42
+ default: (message: string, options?: Partial<KToastOptions>) => string | number;
43
+ dismiss: (id: string | number) => void;
44
+ clear: (position?: KToastPosition) => void;
45
+ pause: (_id?: string | number, position?: KToastPosition) => void;
46
+ resume: (_id?: string | number, position?: KToastPosition) => void;
47
+ pauseAll: (position?: KToastPosition) => void;
48
+ resumeAll: (position?: KToastPosition) => void;
49
+ };
@@ -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,34 @@
1
+ import { type Ref, type ComputedRef } from 'vue';
2
+ export interface IUseVirtualScrollOptions<T> {
3
+ /** Reactive array, computed ref, or getter function for items */
4
+ items: Ref<T[]> | ComputedRef<T[]> | (() => T[]);
5
+ /** Height of each item in px (default: 40) */
6
+ itemHeight?: number | Ref<number> | ((item: T, index: number) => number);
7
+ /** Viewport height of the scroll container in px (default: 400) */
8
+ containerHeight?: number | Ref<number> | ComputedRef<number> | (() => number);
9
+ /** Number of buffer items above and below the visible window (default: 5) */
10
+ buffer?: number | Ref<number>;
11
+ /** Parametric opt-in flag. When false, returns all items with 0 spacers (default: false) */
12
+ virtualScroll?: boolean | Ref<boolean>;
13
+ /** Number of columns for grid virtualization (default: 1) */
14
+ columns?: number | Ref<number>;
15
+ /** Distance from bottom in px to trigger infinite/streaming load (default: 100) */
16
+ scrollThreshold?: number;
17
+ /** Callback fired when user scrolls near the bottom */
18
+ onThresholdReach?: () => void;
19
+ }
20
+ export interface IUseVirtualScrollReturn<T> {
21
+ startIndex: ComputedRef<number>;
22
+ endIndex: ComputedRef<number>;
23
+ visibleItems: ComputedRef<T[]>;
24
+ topSpacerHeight: ComputedRef<number>;
25
+ bottomSpacerHeight: ComputedRef<number>;
26
+ totalHeight: ComputedRef<number>;
27
+ scrollTop: Ref<number>;
28
+ viewportHeight: Ref<number>;
29
+ containerRef: Ref<HTMLElement | null>;
30
+ onScroll: (e: Event | UIEvent) => void;
31
+ scrollToIndex: (index: number, behavior?: ScrollBehavior) => void;
32
+ containerCssVars: ComputedRef<Record<string, string>>;
33
+ }
34
+ export declare function useVirtualScroll<T = any>(options: IUseVirtualScrollOptions<T>): IUseVirtualScrollReturn<T>;