@katlux/toolkit 0.1.1-alpha.118 → 0.1.1-alpha.120

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 (139) hide show
  1. package/bin/create-preset.mjs +5 -4
  2. package/dist/compiled/composables/useDataProvider.mjs +20 -0
  3. package/dist/compiled/composables/useKatluxContext.mjs +6 -3
  4. package/dist/compiled/composables/useKatluxForm.mjs +311 -0
  5. package/dist/compiled/composables/useToast.mjs +164 -0
  6. package/dist/compiled/composables/useVirtualScroll.mjs +246 -0
  7. package/dist/module.cjs +1 -0
  8. package/dist/module.json +1 -1
  9. package/dist/module.mjs +1 -0
  10. package/dist/runtime/components/KBulkActions/KBulkActions.global.d.vue.ts +6 -2
  11. package/dist/runtime/components/KBulkActions/KBulkActions.global.vue +3 -3
  12. package/dist/runtime/components/KBulkActions/KBulkActions.global.vue.d.ts +6 -2
  13. package/dist/runtime/components/KBulkActions/KBulkActions.logic.js +21 -6
  14. package/dist/runtime/components/KCheckbox/KCheckbox.global.d.vue.ts +12 -0
  15. package/dist/runtime/components/KCheckbox/KCheckbox.global.vue +4 -2
  16. package/dist/runtime/components/KCheckbox/KCheckbox.global.vue.d.ts +12 -0
  17. package/dist/runtime/components/KCheckbox/KCheckbox.logic.d.ts +5 -0
  18. package/dist/runtime/components/KCheckbox/KCheckbox.logic.js +4 -0
  19. package/dist/runtime/components/KCombobox/KCombobox.global.d.vue.ts +11 -0
  20. package/dist/runtime/components/KCombobox/KCombobox.global.vue +4 -3
  21. package/dist/runtime/components/KCombobox/KCombobox.global.vue.d.ts +11 -0
  22. package/dist/runtime/components/KCombobox/KCombobox.logic.d.ts +6 -0
  23. package/dist/runtime/components/KCombobox/KCombobox.logic.js +22 -3
  24. package/dist/runtime/components/KDatatable/KDataIterator.global.d.vue.ts +8 -0
  25. package/dist/runtime/components/KDatatable/KDataIterator.global.vue +10 -2
  26. package/dist/runtime/components/KDatatable/KDataIterator.global.vue.d.ts +8 -0
  27. package/dist/runtime/components/KDatatable/KDataIterator.logic.d.ts +8 -0
  28. package/dist/runtime/components/KDatatable/KDataIterator.logic.js +10 -2
  29. package/dist/runtime/components/KDatatable/KDatatable.global.d.vue.ts +8 -0
  30. package/dist/runtime/components/KDatatable/KDatatable.global.vue +12 -4
  31. package/dist/runtime/components/KDatatable/KDatatable.global.vue.d.ts +8 -0
  32. package/dist/runtime/components/KDatatable/KDatatable.logic.d.ts +8 -0
  33. package/dist/runtime/components/KDatatable/KDatatable.logic.js +28 -5
  34. package/dist/runtime/components/KDatePicker/KDatePicker.global.d.vue.ts +4 -0
  35. package/dist/runtime/components/KDatePicker/KDatePicker.global.vue +6 -1
  36. package/dist/runtime/components/KDatePicker/KDatePicker.global.vue.d.ts +4 -0
  37. package/dist/runtime/components/KDatePicker/KDatePicker.logic.js +7 -6
  38. package/dist/runtime/components/KDateTimePicker/KDateTimePicker.logic.js +7 -6
  39. package/dist/runtime/components/KDropdown/KDropdown.global.d.vue.ts +9 -0
  40. package/dist/runtime/components/KDropdown/KDropdown.global.vue +2 -1
  41. package/dist/runtime/components/KDropdown/KDropdown.global.vue.d.ts +9 -0
  42. package/dist/runtime/components/KDropdown/KDropdown.logic.d.ts +5 -0
  43. package/dist/runtime/components/KDropdown/KDropdown.logic.js +10 -7
  44. package/dist/runtime/components/KGantt/KGantt.logic.js +5 -3
  45. package/dist/runtime/components/KPagination/KPagination.global.d.vue.ts +2 -0
  46. package/dist/runtime/components/KPagination/KPagination.global.vue +1 -1
  47. package/dist/runtime/components/KPagination/KPagination.global.vue.d.ts +2 -0
  48. package/dist/runtime/components/KPagination/KPagination.logic.d.ts +1 -0
  49. package/dist/runtime/components/KPagination/KPagination.logic.js +11 -3
  50. package/dist/runtime/components/KToast/KToast.global.d.vue.ts +24 -1
  51. package/dist/runtime/components/KToast/KToast.global.vue +12 -2
  52. package/dist/runtime/components/KToast/KToast.global.vue.d.ts +24 -1
  53. package/dist/runtime/components/KToast/KToast.logic.d.ts +13 -0
  54. package/dist/runtime/components/KToast/KToast.logic.js +45 -5
  55. package/dist/runtime/components/KToastContainer/KToastContainer.global.d.vue.ts +3 -0
  56. package/dist/runtime/components/KToastContainer/KToastContainer.global.vue +11 -0
  57. package/dist/runtime/components/KToastContainer/KToastContainer.global.vue.d.ts +3 -0
  58. package/dist/runtime/components/KTooltip/KTooltip.global.d.vue.ts +1 -1
  59. package/dist/runtime/components/KTooltip/KTooltip.global.vue.d.ts +1 -1
  60. package/dist/runtime/components/KTree/KTree.global.d.vue.ts +39 -1
  61. package/dist/runtime/components/KTree/KTree.global.vue +7 -4
  62. package/dist/runtime/components/KTree/KTree.global.vue.d.ts +39 -1
  63. package/dist/runtime/components/KTree/KTree.logic.d.ts +21 -0
  64. package/dist/runtime/components/KTree/KTree.logic.js +17 -0
  65. package/dist/runtime/components/KTreePicker/KTreePicker.global.d.vue.ts +53 -2
  66. package/dist/runtime/components/KTreePicker/KTreePicker.global.vue +30 -3
  67. package/dist/runtime/components/KTreePicker/KTreePicker.global.vue.d.ts +53 -2
  68. package/dist/runtime/components/KTreePicker/KTreePicker.logic.d.ts +20 -0
  69. package/dist/runtime/components/KTreePicker/KTreePicker.logic.js +16 -0
  70. package/dist/runtime/components/KTreeView/KTreeView.global.d.vue.ts +37 -1
  71. package/dist/runtime/components/KTreeView/KTreeView.global.vue +5 -1
  72. package/dist/runtime/components/KTreeView/KTreeView.global.vue.d.ts +37 -1
  73. package/dist/runtime/components/KTreeView/KTreeView.logic.d.ts +20 -0
  74. package/dist/runtime/components/KTreeView/KTreeView.logic.js +16 -0
  75. package/dist/runtime/composables/useDataProvider.d.ts +1 -0
  76. package/dist/runtime/composables/useDataProvider.js +20 -0
  77. package/dist/runtime/composables/useKatluxContext.js +6 -3
  78. package/dist/runtime/composables/useKatluxForm.d.ts +145 -0
  79. package/dist/runtime/composables/useKatluxForm.js +311 -0
  80. package/dist/runtime/composables/useToast.d.ts +49 -0
  81. package/dist/runtime/composables/useToast.js +164 -0
  82. package/dist/runtime/composables/useVirtualScroll.d.ts +34 -0
  83. package/dist/runtime/composables/useVirtualScroll.js +246 -0
  84. package/dist/runtime/plugins/PresetPlugin.js +9 -1
  85. package/dist/runtime/plugins/nuxtCompatPlugin.js +0 -1
  86. package/dist/runtime/plugins/toastPlugin.client.d.ts +2 -0
  87. package/dist/runtime/plugins/toastPlugin.client.js +16 -0
  88. package/dist/runtime/presets/default/components/KBulkActions/KBulkActions.vue +1 -0
  89. package/dist/runtime/presets/default/components/KCheckbox/KCheckbox.d.vue.ts +3 -0
  90. package/dist/runtime/presets/default/components/KCheckbox/KCheckbox.vue +43 -7
  91. package/dist/runtime/presets/default/components/KCheckbox/KCheckbox.vue.d.ts +3 -0
  92. package/dist/runtime/presets/default/components/KCombobox/KCombobox.d.vue.ts +3 -0
  93. package/dist/runtime/presets/default/components/KCombobox/KCombobox.vue +12 -4
  94. package/dist/runtime/presets/default/components/KCombobox/KCombobox.vue.d.ts +3 -0
  95. package/dist/runtime/presets/default/components/KCombobox/KComboboxList.d.vue.ts +1 -0
  96. package/dist/runtime/presets/default/components/KCombobox/KComboboxList.vue +7 -2
  97. package/dist/runtime/presets/default/components/KCombobox/KComboboxList.vue.d.ts +1 -0
  98. package/dist/runtime/presets/default/components/KDataIterator/KDataIterator.d.vue.ts +12 -1
  99. package/dist/runtime/presets/default/components/KDataIterator/KDataIterator.vue +143 -7
  100. package/dist/runtime/presets/default/components/KDataIterator/KDataIterator.vue.d.ts +12 -1
  101. package/dist/runtime/presets/default/components/KDatatable/KDatatable.d.vue.ts +12 -1
  102. package/dist/runtime/presets/default/components/KDatatable/KDatatable.vue +228 -32
  103. package/dist/runtime/presets/default/components/KDatatable/KDatatable.vue.d.ts +12 -1
  104. package/dist/runtime/presets/default/components/KDatePicker/KDatePicker.d.vue.ts +3 -1
  105. package/dist/runtime/presets/default/components/KDatePicker/KDatePicker.vue +3 -1
  106. package/dist/runtime/presets/default/components/KDatePicker/KDatePicker.vue.d.ts +3 -1
  107. package/dist/runtime/presets/default/components/KDropdown/KDropdown.d.vue.ts +1 -0
  108. package/dist/runtime/presets/default/components/KDropdown/KDropdown.vue +23 -2
  109. package/dist/runtime/presets/default/components/KDropdown/KDropdown.vue.d.ts +1 -0
  110. package/dist/runtime/presets/default/components/KLayout/KLayout.d.vue.ts +6 -1
  111. package/dist/runtime/presets/default/components/KLayout/KLayout.vue +37 -3
  112. package/dist/runtime/presets/default/components/KLayout/KLayout.vue.d.ts +6 -1
  113. package/dist/runtime/presets/default/components/KModal/KModal.vue +8 -1
  114. package/dist/runtime/presets/default/components/KTabs/KTabItem.vue +1 -1
  115. package/dist/runtime/presets/default/components/KTextbox/KTextbox.vue +6 -4
  116. package/dist/runtime/presets/default/components/KToast/KToast.d.vue.ts +6 -0
  117. package/dist/runtime/presets/default/components/KToast/KToast.vue +21 -4
  118. package/dist/runtime/presets/default/components/KToast/KToast.vue.d.ts +6 -0
  119. package/dist/runtime/presets/default/components/KToastContainer/KToastContainer.d.vue.ts +11 -0
  120. package/dist/runtime/presets/default/components/KToastContainer/KToastContainer.vue +206 -0
  121. package/dist/runtime/presets/default/components/KToastContainer/KToastContainer.vue.d.ts +11 -0
  122. package/dist/runtime/presets/default/components/KTree/KTree.d.vue.ts +15 -6
  123. package/dist/runtime/presets/default/components/KTree/KTree.vue +235 -14
  124. package/dist/runtime/presets/default/components/KTree/KTree.vue.d.ts +15 -6
  125. package/dist/runtime/presets/default/components/KTreePicker/KTreePicker.d.vue.ts +14 -1
  126. package/dist/runtime/presets/default/components/KTreePicker/KTreePicker.vue +118 -13
  127. package/dist/runtime/presets/default/components/KTreePicker/KTreePicker.vue.d.ts +14 -1
  128. package/dist/runtime/presets/default/components/KTreeView/KTreeCell.vue +12 -3
  129. package/dist/runtime/presets/default/components/KTreeView/KTreeView.d.vue.ts +4 -0
  130. package/dist/runtime/presets/default/components/KTreeView/KTreeView.vue +8 -0
  131. package/dist/runtime/presets/default/components/KTreeView/KTreeView.vue.d.ts +4 -0
  132. package/dist/runtime/server/middleware/session.js +1 -1
  133. package/package.json +3 -4
  134. package/dist/compiled/composables/useDataProvider.spec.mjs +0 -157
  135. package/dist/compiled/composables/useKatluxContext.spec.mjs +0 -63
  136. package/dist/compiled/composables/useKatluxI18n.spec.mjs +0 -10
  137. package/dist/compiled/composables/usePresetComponent.spec.mjs +0 -106
  138. package/dist/compiled/composables/useTemplate.spec.mjs +0 -30
  139. package/dist/compiled/utils/PresetResolver.spec.mjs +0 -68
@@ -482,13 +482,14 @@ ${BOLD}Examples:${RESET}
482
482
  let presetName = null
483
483
  let basePreset = null
484
484
 
485
- for (const arg of args) {
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
- const idx = args.indexOf(arg)
490
- if (idx !== -1 && args[idx + 1]) {
491
- basePreset = args[idx + 1]
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
@@ -15,6 +15,22 @@ export function useDataProvider(provider, options) {
15
15
  const pageData = shallowRef(
16
16
  activeProvider ? activeProvider.pageData?.value !== void 0 ? activeProvider.pageData.value : Array.isArray(activeProvider.pageData) ? activeProvider.pageData : extractVal(activeProvider.pageData, []) : []
17
17
  );
18
+ const getFullData = () => {
19
+ if (!activeProvider) return [];
20
+ if (Array.isArray(activeProvider.allVisibleRows) && activeProvider.allVisibleRows.length > 0) return activeProvider.allVisibleRows;
21
+ if (Array.isArray(activeProvider.allVisibleRows?.value) && activeProvider.allVisibleRows.value.length > 0) return activeProvider.allVisibleRows.value;
22
+ if (Array.isArray(activeProvider.rowMap) && activeProvider.rowMap.length > 0) return activeProvider.rowMap;
23
+ if (Array.isArray(activeProvider.rowMap?.value) && activeProvider.rowMap.value.length > 0) return activeProvider.rowMap.value;
24
+ if (Array.isArray(activeProvider.allVisibleNodes) && activeProvider.allVisibleNodes.length > 0) return activeProvider.allVisibleNodes;
25
+ if (Array.isArray(activeProvider.allVisibleNodes?.value) && activeProvider.allVisibleNodes.value.length > 0) return activeProvider.allVisibleNodes.value;
26
+ if (Array.isArray(activeProvider.allData) && activeProvider.allData.length > 0) return activeProvider.allData;
27
+ if (Array.isArray(activeProvider.allData?.value) && activeProvider.allData.value.length > 0) return activeProvider.allData.value;
28
+ if (Array.isArray(activeProvider.data) && activeProvider.data.length > 0) return activeProvider.data;
29
+ if (Array.isArray(activeProvider.rowMap)) return activeProvider.rowMap;
30
+ if (Array.isArray(activeProvider.allVisibleRows)) return activeProvider.allVisibleRows;
31
+ return pageData.value;
32
+ };
33
+ const virtualRows = shallowRef(activeProvider ? getFullData() : []);
18
34
  const rowCount = ref(activeProvider ? extractVal(activeProvider.rowCount, 0) : 0);
19
35
  const currentPage = options?.currentPage || ref(activeProvider ? extractVal(activeProvider.currentPage, 1) : 1);
20
36
  const pageSize = options?.pageSize || ref(activeProvider ? extractVal(activeProvider.pageSize, 10) : 10);
@@ -30,6 +46,7 @@ export function useDataProvider(provider, options) {
30
46
  const syncFromProvider = () => {
31
47
  if (!activeProvider) {
32
48
  pageData.value = [];
49
+ virtualRows.value = [];
33
50
  rowCount.value = 0;
34
51
  currentPage.value = 1;
35
52
  pageSize.value = 10;
@@ -46,6 +63,7 @@ export function useDataProvider(provider, options) {
46
63
  try {
47
64
  pageData.value = activeProvider.pageData?.value !== void 0 ? activeProvider.pageData.value : Array.isArray(activeProvider.pageData) ? activeProvider.pageData : extractVal(activeProvider.pageData, []);
48
65
  rowCount.value = extractVal(activeProvider.rowCount, 0);
66
+ virtualRows.value = getFullData();
49
67
  const newPage = extractVal(activeProvider.currentPage, 1);
50
68
  if (currentPage.value !== newPage) {
51
69
  currentPage.value = newPage;
@@ -93,6 +111,7 @@ export function useDataProvider(provider, options) {
93
111
  }
94
112
  };
95
113
  attachListener();
114
+ syncFromProvider();
96
115
  try {
97
116
  onScopeDispose(() => {
98
117
  if (unsubscribe) {
@@ -320,6 +339,7 @@ export function useDataProvider(provider, options) {
320
339
  return activeProvider;
321
340
  },
322
341
  pageData,
342
+ virtualRows,
323
343
  rowCount,
324
344
  currentPage,
325
345
  pageSize,
@@ -11,9 +11,12 @@ export function useKatluxContext() {
11
11
  return { event: evt };
12
12
  }
13
13
  }
14
- const app = globalThis.__KATLUX_APP__ || (globalThis.useNuxtApp ? globalThis.useNuxtApp() : null);
15
- if (app?.ssrContext?.event) {
16
- return { event: app.ssrContext.event };
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,311 @@
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 registerErrorPaths(errorMap, pathStr, message) {
49
+ if (!pathStr) {
50
+ errorMap[""] = message;
51
+ return;
52
+ }
53
+ errorMap[pathStr] = message;
54
+ const bracketPath = pathStr.replace(/\.(\d+)(?=\.|$)/g, "[$1]");
55
+ if (bracketPath !== pathStr && !errorMap[bracketPath]) {
56
+ errorMap[bracketPath] = message;
57
+ }
58
+ const dotPath = pathStr.replace(/\[(\d+)\]/g, ".$1");
59
+ if (dotPath !== pathStr && !errorMap[dotPath]) {
60
+ errorMap[dotPath] = message;
61
+ }
62
+ }
63
+ function parseValidationResult(rawResult, schemaType, dataToValidate) {
64
+ if (schemaType === "standard") {
65
+ if (rawResult.issues && rawResult.issues.length > 0) {
66
+ const errorMap = {};
67
+ for (const issue of rawResult.issues) {
68
+ const pathStr = issue.path && issue.path.length > 0 ? issue.path.map((seg) => typeof seg === "object" && seg !== null && "key" in seg ? seg.key : seg).join(".") : "";
69
+ registerErrorPaths(errorMap, pathStr, issue.message);
70
+ }
71
+ return { valid: false, output: dataToValidate, errors: errorMap };
72
+ }
73
+ return { valid: true, output: rawResult.value ?? dataToValidate, errors: {} };
74
+ }
75
+ if (schemaType === "zod") {
76
+ if (!rawResult.success) {
77
+ const errorMap = {};
78
+ for (const issue of rawResult.error.issues) {
79
+ const pathStr = issue.path ? issue.path.join(".") : "";
80
+ registerErrorPaths(errorMap, pathStr, issue.message);
81
+ }
82
+ return { valid: false, output: dataToValidate, errors: errorMap };
83
+ }
84
+ return { valid: true, output: rawResult.data ?? dataToValidate, errors: {} };
85
+ }
86
+ if (schemaType === "custom") {
87
+ const errorMap = {};
88
+ const rawErrors = rawResult || {};
89
+ for (const [key, msg] of Object.entries(rawErrors)) {
90
+ registerErrorPaths(errorMap, key, String(msg));
91
+ }
92
+ const valid = Object.keys(errorMap).length === 0;
93
+ return { valid, output: dataToValidate, errors: errorMap };
94
+ }
95
+ return { valid: true, output: dataToValidate, errors: {} };
96
+ }
97
+ function runValidation(dataToValidate) {
98
+ const schema = options.schema;
99
+ if (!schema) {
100
+ return { valid: true, output: dataToValidate, errors: {} };
101
+ }
102
+ if ("~standard" in schema && typeof schema["~standard"]?.validate === "function") {
103
+ const res = schema["~standard"].validate(dataToValidate);
104
+ if (res && typeof res.then === "function") {
105
+ return res.then((r) => parseValidationResult(r, "standard", dataToValidate));
106
+ }
107
+ return parseValidationResult(res, "standard", dataToValidate);
108
+ }
109
+ if (typeof schema.safeParse === "function") {
110
+ const res = schema.safeParse(dataToValidate);
111
+ return parseValidationResult(res, "zod", dataToValidate);
112
+ }
113
+ if (typeof schema.safeParseAsync === "function") {
114
+ return schema.safeParseAsync(dataToValidate).then((res) => parseValidationResult(res, "zod", dataToValidate));
115
+ }
116
+ if (typeof schema === "function") {
117
+ const res = schema(dataToValidate);
118
+ if (res && typeof res.then === "function") {
119
+ return res.then((r) => parseValidationResult(r, "custom", dataToValidate));
120
+ }
121
+ return parseValidationResult(res, "custom", dataToValidate);
122
+ }
123
+ return { valid: true, output: dataToValidate, errors: {} };
124
+ }
125
+ function applyErrors(targetPath, newErrors) {
126
+ if (targetPath) {
127
+ const bracketPath = targetPath.replace(/\.(\d+)(?=\.|$)/g, "[$1]");
128
+ const dotPath = targetPath.replace(/\[(\d+)\]/g, ".$1");
129
+ const err = newErrors[targetPath] || newErrors[bracketPath] || newErrors[dotPath];
130
+ if (err) {
131
+ errors.value = { ...errors.value, [targetPath]: err };
132
+ return false;
133
+ } else {
134
+ const nextErrors = { ...errors.value };
135
+ delete nextErrors[targetPath];
136
+ delete nextErrors[bracketPath];
137
+ delete nextErrors[dotPath];
138
+ errors.value = nextErrors;
139
+ return true;
140
+ }
141
+ } else {
142
+ errors.value = newErrors;
143
+ return Object.keys(newErrors).length === 0;
144
+ }
145
+ }
146
+ let validationSeq = 0;
147
+ function validate(targetPath) {
148
+ const seq = ++validationSeq;
149
+ const result = runValidation(values);
150
+ if (result && typeof result.then === "function") {
151
+ return result.then(({ errors: newErrors }) => {
152
+ if (seq !== validationSeq) {
153
+ return Object.keys(errors.value).length === 0;
154
+ }
155
+ return applyErrors(targetPath, newErrors);
156
+ });
157
+ }
158
+ return applyErrors(targetPath, result.errors);
159
+ }
160
+ function setValue(path, val, opts = {}) {
161
+ setByPath(values, path, val);
162
+ if (opts.shouldDirty !== false) {
163
+ dirtyFields.value = { ...dirtyFields.value, [path]: true };
164
+ }
165
+ if (opts.shouldValidate) {
166
+ validate(path);
167
+ }
168
+ }
169
+ function getValue(path) {
170
+ return getByPath(values, path);
171
+ }
172
+ function setError(path, message) {
173
+ errors.value = { ...errors.value, [path]: message };
174
+ }
175
+ function clearErrors(path) {
176
+ if (path) {
177
+ const nextErrors = { ...errors.value };
178
+ delete nextErrors[path];
179
+ errors.value = nextErrors;
180
+ } else {
181
+ errors.value = {};
182
+ }
183
+ }
184
+ function setTouched(path, isTouchedVal = true) {
185
+ touched.value = { ...touched.value, [path]: isTouchedVal };
186
+ }
187
+ function reset(newValues) {
188
+ const targetValues = newValues ? deepClone(newValues) : deepClone(initialValues);
189
+ for (const key of Object.keys(values)) {
190
+ delete values[key];
191
+ }
192
+ Object.assign(values, targetValues);
193
+ errors.value = {};
194
+ touched.value = {};
195
+ dirtyFields.value = {};
196
+ submitCount.value = 0;
197
+ isSubmitting.value = false;
198
+ }
199
+ function register(path, regOptions = {}) {
200
+ return {
201
+ name: path,
202
+ get modelValue() {
203
+ return getByPath(values, path);
204
+ },
205
+ "onUpdate:modelValue": (newVal) => {
206
+ let transformed = newVal;
207
+ if (regOptions.transform) {
208
+ if (regOptions.transform === Number) {
209
+ transformed = newVal === "" || newVal === null || newVal === void 0 ? "" : Number(newVal);
210
+ } else {
211
+ transformed = regOptions.transform(newVal);
212
+ }
213
+ }
214
+ setByPath(values, path, transformed);
215
+ const initialVal = getByPath(initialValues, path);
216
+ const isFieldDirty = JSON.stringify(transformed) !== JSON.stringify(initialVal);
217
+ dirtyFields.value = { ...dirtyFields.value, [path]: isFieldDirty };
218
+ const hasActiveError = !!errors.value[path];
219
+ if (mode === "onChange" || hasActiveError && reValidateMode === "onChange") {
220
+ validate(path);
221
+ }
222
+ },
223
+ get validation() {
224
+ if (regOptions.validation !== void 0) {
225
+ return regOptions.validation;
226
+ }
227
+ return errors.value[path] ? "error" : null;
228
+ },
229
+ get validationText() {
230
+ if (regOptions.validationText !== void 0) {
231
+ return regOptions.validationText;
232
+ }
233
+ return errors.value[path] || "";
234
+ },
235
+ get "aria-invalid"() {
236
+ return !!errors.value[path];
237
+ },
238
+ get "aria-describedby"() {
239
+ return errors.value[path] ? `${path}-error` : void 0;
240
+ },
241
+ onBlur: () => {
242
+ touched.value = { ...touched.value, [path]: true };
243
+ const hasActiveError = !!errors.value[path];
244
+ if (mode === "onBlur" || hasActiveError && reValidateMode === "onBlur") {
245
+ validate(path);
246
+ }
247
+ }
248
+ };
249
+ }
250
+ function focusFirstInvalid(fieldPath) {
251
+ if (typeof document === "undefined") return;
252
+ nextTick(() => {
253
+ const selector = `[name="${fieldPath}"], #${CSS.escape(fieldPath)}, [data-field="${CSS.escape(fieldPath)}"]`;
254
+ let el = document.querySelector(selector);
255
+ if (el) {
256
+ if (!["INPUT", "SELECT", "TEXTAREA", "BUTTON"].includes(el.tagName)) {
257
+ const inner = el.querySelector("input, select, textarea, [tabindex]");
258
+ if (inner) el = inner;
259
+ }
260
+ el.focus?.();
261
+ }
262
+ });
263
+ }
264
+ function handleSubmit(onValid, onInvalid) {
265
+ return async (event) => {
266
+ if (isSubmitting.value) return;
267
+ if (event && typeof event.preventDefault === "function") {
268
+ event.preventDefault();
269
+ }
270
+ submitCount.value += 1;
271
+ isSubmitting.value = true;
272
+ try {
273
+ const res = await runValidation(values);
274
+ const { valid, output, errors: newErrors } = res;
275
+ errors.value = newErrors;
276
+ if (!valid) {
277
+ const firstErrorKey = Object.keys(newErrors)[0];
278
+ if (focusOnError && firstErrorKey) {
279
+ focusFirstInvalid(firstErrorKey);
280
+ }
281
+ if (onInvalid) {
282
+ await onInvalid(newErrors, values);
283
+ }
284
+ return;
285
+ }
286
+ await onValid(output, event);
287
+ } finally {
288
+ isSubmitting.value = false;
289
+ }
290
+ };
291
+ }
292
+ return {
293
+ values,
294
+ errors,
295
+ touched,
296
+ dirtyFields,
297
+ isDirty,
298
+ isValid,
299
+ isSubmitting,
300
+ submitCount,
301
+ register,
302
+ validate,
303
+ setValue,
304
+ getValue,
305
+ setError,
306
+ clearErrors,
307
+ setTouched,
308
+ reset,
309
+ handleSubmit
310
+ };
311
+ }
@@ -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
+ }