@katlux/toolkit 0.1.1-alpha.100 → 0.1.1-alpha.108
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/compiled/composables/useDataProvider.mjs +140 -0
- package/dist/compiled/composables/useDataProvider.spec.mjs +86 -0
- package/dist/compiled/composables/useDebounce.mjs +3 -11
- package/dist/compiled/composables/useFilterLogic.mjs +23 -169
- package/dist/compiled/composables/usePresetComponent.mjs +62 -38
- package/dist/compiled/composables/usePresetComponent.spec.mjs +106 -0
- package/dist/compiled/composables/useRequestProvider.mjs +9 -0
- package/dist/compiled/composables/useSortLogic.mjs +3 -55
- package/dist/compiled/composables/useTemplate.spec.mjs +30 -0
- package/dist/compiled/composables/useUnregisterProvider.mjs +4 -0
- package/dist/compiled/utils/PresetResolver.mjs +1 -1
- package/dist/compiled/utils/TemplateResolver.mjs +32 -0
- package/dist/module.cjs +1 -0
- package/dist/module.json +1 -1
- package/dist/module.mjs +1 -0
- package/dist/runtime/components/KAlert/KAlert.global.d.vue.ts +2 -0
- package/dist/runtime/components/KAlert/KAlert.global.vue +3 -1
- package/dist/runtime/components/KAlert/KAlert.global.vue.d.ts +2 -0
- package/dist/runtime/components/KAlert/KAlert.logic.d.ts +4 -2
- package/dist/runtime/components/KAlert/KAlert.logic.js +12 -6
- package/dist/runtime/components/KCalendar/KCalendar.logic.js +13 -6
- package/dist/runtime/components/KCalendar/KCalendarMonth.global.d.vue.ts +13 -13
- package/dist/runtime/components/KCalendar/KCalendarMonth.global.vue.d.ts +13 -13
- package/dist/runtime/components/KCalendar/KCalendarMonth.logic.d.ts +6 -5
- package/dist/runtime/components/KCalendar/KCalendarMonth.logic.js +4 -1
- package/dist/runtime/components/KCheckbox/KCheckbox.global.d.vue.ts +1 -1
- package/dist/runtime/components/KCheckbox/KCheckbox.global.vue.d.ts +1 -1
- package/dist/runtime/components/KCombobox/KCombobox.global.d.vue.ts +3 -3
- package/dist/runtime/components/KCombobox/KCombobox.global.vue.d.ts +3 -3
- package/dist/runtime/components/KCombobox/KCombobox.logic.d.ts +2 -2
- package/dist/runtime/components/KCombobox/KCombobox.logic.js +6 -9
- package/dist/runtime/components/KCompositeInput/KCompositeInput.global.d.vue.ts +1 -1
- package/dist/runtime/components/KCompositeInput/KCompositeInput.global.vue +0 -1
- package/dist/runtime/components/KCompositeInput/KCompositeInput.global.vue.d.ts +1 -1
- package/dist/runtime/components/KDatatable/KDataIterator.logic.d.ts +2 -2
- package/dist/runtime/components/KDatatable/KDataIterator.logic.js +1 -1
- package/dist/runtime/components/KDatatable/KDatatable.logic.d.ts +4 -2
- package/dist/runtime/components/KDatatable/KDatatable.logic.js +45 -6
- package/dist/runtime/components/KDatePicker/KDatePicker.global.d.vue.ts +5 -5
- package/dist/runtime/components/KDatePicker/KDatePicker.global.vue.d.ts +5 -5
- package/dist/runtime/components/KDatePicker/KDatePicker.logic.d.ts +2 -2
- package/dist/runtime/components/KDateTimePicker/KDateTimePicker.global.d.vue.ts +5 -5
- package/dist/runtime/components/KDateTimePicker/KDateTimePicker.global.vue.d.ts +5 -5
- package/dist/runtime/components/KDateTimePicker/KDateTimePicker.logic.d.ts +2 -2
- package/dist/runtime/components/KDropdown/KDropdown.global.d.vue.ts +1 -1
- package/dist/runtime/components/KDropdown/KDropdown.global.vue.d.ts +1 -1
- package/dist/runtime/components/KGantt/KGantt.global.d.vue.ts +8 -8
- package/dist/runtime/components/KGantt/KGantt.global.vue.d.ts +8 -8
- package/dist/runtime/components/KGantt/KGantt.logic.d.ts +4 -4
- package/dist/runtime/components/KGantt/KGantt.logic.js +21 -25
- package/dist/runtime/components/KGrid/KGrid.global.d.vue.ts +1 -1
- package/dist/runtime/components/KGrid/KGrid.global.vue.d.ts +1 -1
- package/dist/runtime/components/KGrid/KGrid.logic.d.ts +1 -0
- package/dist/runtime/components/KHourPicker/KHourPicker.global.d.vue.ts +1 -1
- package/dist/runtime/components/KHourPicker/KHourPicker.global.vue.d.ts +1 -1
- package/dist/runtime/components/KIcon/KIcon.logic.d.ts +14 -0
- package/dist/runtime/components/KIcon/KIcon.logic.js +74 -17
- package/dist/runtime/components/KMaskTextbox/KMaskTextbox.global.d.vue.ts +1 -1
- package/dist/runtime/components/KMaskTextbox/KMaskTextbox.global.vue.d.ts +1 -1
- package/dist/runtime/components/KRadiobox/KRadiobox.global.d.vue.ts +1 -1
- package/dist/runtime/components/KRadiobox/KRadiobox.global.vue.d.ts +1 -1
- package/dist/runtime/components/KTextarea/KTextarea.global.d.vue.ts +1 -1
- package/dist/runtime/components/KTextarea/KTextarea.global.vue.d.ts +1 -1
- package/dist/runtime/components/KTextbox/KTextbox.global.d.vue.ts +1 -1
- package/dist/runtime/components/KTextbox/KTextbox.global.vue.d.ts +1 -1
- package/dist/runtime/components/KTreePicker/KTreePicker.global.d.vue.ts +1 -1
- package/dist/runtime/components/KTreePicker/KTreePicker.global.vue.d.ts +1 -1
- package/dist/runtime/components/KTreePicker/KTreePicker.logic.d.ts +1 -1
- package/dist/runtime/components/MultiTabs/MultiTabs.logic.d.ts +1 -1
- package/dist/runtime/components/MultiTabs/MultiTabs.logic.js +25 -14
- package/dist/runtime/composables/useDataProvider.d.ts +37 -0
- package/dist/runtime/composables/useDataProvider.js +140 -0
- package/dist/runtime/composables/useDebounce.d.ts +2 -6
- package/dist/runtime/composables/useDebounce.js +3 -11
- package/dist/runtime/composables/useFilterLogic.d.ts +5 -4
- package/dist/runtime/composables/useFilterLogic.js +23 -169
- package/dist/runtime/composables/usePresetComponent.d.ts +14 -3
- package/dist/runtime/composables/usePresetComponent.js +62 -38
- package/dist/runtime/composables/useRequestProvider.d.ts +23 -0
- package/dist/runtime/composables/useRequestProvider.js +9 -0
- package/dist/runtime/composables/useSortLogic.d.ts +3 -2
- package/dist/runtime/composables/useSortLogic.js +3 -55
- package/dist/runtime/composables/useTemplate.d.ts +1 -1
- package/dist/runtime/composables/useTemplate.js +1 -1
- package/dist/runtime/composables/useUnregisterProvider.d.ts +25 -0
- package/dist/runtime/composables/useUnregisterProvider.js +4 -0
- package/dist/runtime/plugins/nuxtCompatPlugin.d.ts +9 -0
- package/dist/runtime/plugins/nuxtCompatPlugin.js +11 -0
- package/dist/runtime/presets/default/assets/scss/css-variables.css +2 -0
- package/dist/runtime/presets/default/assets/scss/css-variables.scss +2 -0
- package/dist/runtime/presets/default/assets/scss/index.css +2 -0
- package/dist/runtime/presets/default/components/KAlert/KAlert.d.vue.ts +1 -1
- package/dist/runtime/presets/default/components/KAlert/KAlert.vue +16 -9
- package/dist/runtime/presets/default/components/KAlert/KAlert.vue.d.ts +1 -1
- package/dist/runtime/presets/default/components/KCalendar/KCalendarMonth.vue +1 -1
- package/dist/runtime/presets/default/components/KContextMenu/KContextMenu.vue +45 -3
- package/dist/runtime/presets/default/components/KDatatable/KDatatable.vue +22 -4
- package/dist/runtime/presets/default/components/KDropdown/KDropdown.vue +28 -2
- package/dist/runtime/presets/default/components/KGantt/KGantt.vue +11 -2
- package/dist/runtime/presets/default/components/KLoader/KLoader.vue +1 -1
- package/dist/runtime/utils/PresetResolver.js +1 -1
- package/dist/runtime/utils/TemplateResolver.d.ts +14 -0
- package/dist/runtime/utils/TemplateResolver.js +32 -0
- package/package.json +1 -1
- package/dist/runtime/components/KThree/KThree.global.d.vue.ts +0 -3
- package/dist/runtime/components/KThree/KThree.global.vue +0 -7
- package/dist/runtime/components/KThree/KThree.global.vue.d.ts +0 -3
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { computed } from "vue";
|
|
1
|
+
import { computed, watch, shallowRef } from "vue";
|
|
2
2
|
export const KIconDefaultProps = {
|
|
3
3
|
iconname: {
|
|
4
4
|
type: String,
|
|
@@ -17,27 +17,84 @@ export const KIconDefaultProps = {
|
|
|
17
17
|
default: 0
|
|
18
18
|
}
|
|
19
19
|
};
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
const _svgCache = /* @__PURE__ */ new Map();
|
|
21
|
+
const _asyncSvgLoaders = /* @__PURE__ */ new Map();
|
|
22
|
+
const _defaultSvgModules = import.meta.glob("../../presets/default/assets/svg/*.svg", {
|
|
23
|
+
eager: true,
|
|
24
|
+
query: "?raw",
|
|
25
|
+
import: "default"
|
|
26
|
+
});
|
|
27
|
+
for (const path in _defaultSvgModules) {
|
|
28
|
+
const match = path.match(/([^/]+)\.svg$/);
|
|
29
|
+
if (match) {
|
|
30
|
+
_svgCache.set(match[1], _defaultSvgModules[path]);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export function registerSvgIcon(name, svgOrLoader) {
|
|
34
|
+
if (typeof svgOrLoader === "string") {
|
|
35
|
+
_svgCache.set(name, svgOrLoader);
|
|
36
|
+
} else {
|
|
37
|
+
_asyncSvgLoaders.set(name, svgOrLoader);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
export function getCachedSvgIcon(name) {
|
|
41
|
+
return _svgCache.get(name);
|
|
42
|
+
}
|
|
43
|
+
export function clearSvgCache() {
|
|
44
|
+
_svgCache.clear();
|
|
45
|
+
_asyncSvgLoaders.clear();
|
|
46
|
+
for (const path in _defaultSvgModules) {
|
|
24
47
|
const match = path.match(/([^/]+)\.svg$/);
|
|
25
48
|
if (match) {
|
|
26
|
-
|
|
49
|
+
_svgCache.set(match[1], _defaultSvgModules[path]);
|
|
27
50
|
}
|
|
28
51
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
52
|
+
}
|
|
53
|
+
export function formatIconSize(val) {
|
|
54
|
+
if (val === void 0 || val === null || val === "") return void 0;
|
|
55
|
+
if (typeof val === "number") return `${val}px`;
|
|
56
|
+
if (typeof val === "string") {
|
|
57
|
+
if (/^\d+$/.test(val)) return `${val}px`;
|
|
36
58
|
return val;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
59
|
+
}
|
|
60
|
+
return String(val);
|
|
61
|
+
}
|
|
62
|
+
export function useKIconLogic(props) {
|
|
63
|
+
const widthPx = computed(() => formatIconSize(props.width));
|
|
64
|
+
const heightPx = computed(() => formatIconSize(props.height) || "12px");
|
|
65
|
+
const asyncLoadedSvg = shallowRef(null);
|
|
66
|
+
watch(
|
|
67
|
+
() => props.iconname,
|
|
68
|
+
(name) => {
|
|
69
|
+
if (!name || name.startsWith("<svg") || _svgCache.has(name)) {
|
|
70
|
+
asyncLoadedSvg.value = null;
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const loader = _asyncSvgLoaders.get(name);
|
|
74
|
+
if (loader) {
|
|
75
|
+
loader().then((raw) => {
|
|
76
|
+
_svgCache.set(name, raw);
|
|
77
|
+
if (props.iconname === name) {
|
|
78
|
+
asyncLoadedSvg.value = raw;
|
|
79
|
+
}
|
|
80
|
+
}).catch((err) => {
|
|
81
|
+
console.warn(`[KIcon] Failed to load icon: ${name}`, err);
|
|
82
|
+
asyncLoadedSvg.value = null;
|
|
83
|
+
});
|
|
84
|
+
} else {
|
|
85
|
+
asyncLoadedSvg.value = null;
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
{ immediate: true }
|
|
89
|
+
);
|
|
90
|
+
const iconComponent = computed(() => {
|
|
91
|
+
const name = props.iconname;
|
|
92
|
+
if (!name) return null;
|
|
93
|
+
if (name.startsWith("<svg")) return name;
|
|
94
|
+
const cached = _svgCache.get(name);
|
|
95
|
+
if (cached) return cached;
|
|
96
|
+
return asyncLoadedSvg.value;
|
|
97
|
+
});
|
|
41
98
|
return {
|
|
42
99
|
widthPx,
|
|
43
100
|
heightPx,
|
|
@@ -65,7 +65,7 @@ declare const __VLS_export: import("vue").DefineComponent<import("vue").ExtractP
|
|
|
65
65
|
"onUpdate:modelValue"?: ((value: string) => any) | undefined;
|
|
66
66
|
}>, {
|
|
67
67
|
label: string;
|
|
68
|
-
validation: "
|
|
68
|
+
validation: "error" | "success" | "warning" | null | undefined;
|
|
69
69
|
validationText: string;
|
|
70
70
|
modelValue: string;
|
|
71
71
|
placeholder: string;
|
|
@@ -65,7 +65,7 @@ declare const __VLS_export: import("vue").DefineComponent<import("vue").ExtractP
|
|
|
65
65
|
"onUpdate:modelValue"?: ((value: string) => any) | undefined;
|
|
66
66
|
}>, {
|
|
67
67
|
label: string;
|
|
68
|
-
validation: "
|
|
68
|
+
validation: "error" | "success" | "warning" | null | undefined;
|
|
69
69
|
validationText: string;
|
|
70
70
|
modelValue: string;
|
|
71
71
|
placeholder: string;
|
|
@@ -51,7 +51,7 @@ declare const __VLS_export: import("vue").DefineComponent<import("vue").ExtractP
|
|
|
51
51
|
"onUpdate:modelValue"?: ((value: any) => any) | undefined;
|
|
52
52
|
}>, {
|
|
53
53
|
disabled: boolean;
|
|
54
|
-
validation: "
|
|
54
|
+
validation: "error" | "success" | "warning" | null | undefined;
|
|
55
55
|
validationText: string;
|
|
56
56
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
57
57
|
declare const _default: typeof __VLS_export;
|
|
@@ -51,7 +51,7 @@ declare const __VLS_export: import("vue").DefineComponent<import("vue").ExtractP
|
|
|
51
51
|
"onUpdate:modelValue"?: ((value: any) => any) | undefined;
|
|
52
52
|
}>, {
|
|
53
53
|
disabled: boolean;
|
|
54
|
-
validation: "
|
|
54
|
+
validation: "error" | "success" | "warning" | null | undefined;
|
|
55
55
|
validationText: string;
|
|
56
56
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
57
57
|
declare const _default: typeof __VLS_export;
|
|
@@ -57,7 +57,7 @@ declare const __VLS_export: import("vue").DefineComponent<import("vue").ExtractP
|
|
|
57
57
|
"onUpdate:modelValue"?: ((value: string) => any) | undefined;
|
|
58
58
|
}>, {
|
|
59
59
|
label: string;
|
|
60
|
-
validation: "
|
|
60
|
+
validation: "error" | "success" | "warning" | null | undefined;
|
|
61
61
|
validationText: string;
|
|
62
62
|
placeholder: string;
|
|
63
63
|
rows: number;
|
|
@@ -57,7 +57,7 @@ declare const __VLS_export: import("vue").DefineComponent<import("vue").ExtractP
|
|
|
57
57
|
"onUpdate:modelValue"?: ((value: string) => any) | undefined;
|
|
58
58
|
}>, {
|
|
59
59
|
label: string;
|
|
60
|
-
validation: "
|
|
60
|
+
validation: "error" | "success" | "warning" | null | undefined;
|
|
61
61
|
validationText: string;
|
|
62
62
|
placeholder: string;
|
|
63
63
|
rows: number;
|
|
@@ -68,7 +68,7 @@ declare const __VLS_export: import("vue").DefineComponent<import("vue").ExtractP
|
|
|
68
68
|
}>, {
|
|
69
69
|
type: "number" | "url" | "search" | "text" | "password" | "email" | "tel" | undefined;
|
|
70
70
|
label: string;
|
|
71
|
-
validation: "
|
|
71
|
+
validation: "error" | "success" | "warning" | null | undefined;
|
|
72
72
|
validationText: string;
|
|
73
73
|
modelValue: string;
|
|
74
74
|
placeholder: string;
|
|
@@ -68,7 +68,7 @@ declare const __VLS_export: import("vue").DefineComponent<import("vue").ExtractP
|
|
|
68
68
|
}>, {
|
|
69
69
|
type: "number" | "url" | "search" | "text" | "password" | "email" | "tel" | undefined;
|
|
70
70
|
label: string;
|
|
71
|
-
validation: "
|
|
71
|
+
validation: "error" | "success" | "warning" | null | undefined;
|
|
72
72
|
validationText: string;
|
|
73
73
|
modelValue: string;
|
|
74
74
|
placeholder: string;
|
|
@@ -167,7 +167,7 @@ declare const __VLS_export: import("vue").DefineComponent<import("vue").ExtractP
|
|
|
167
167
|
label: string;
|
|
168
168
|
disabled: boolean;
|
|
169
169
|
loading: boolean;
|
|
170
|
-
validation: "
|
|
170
|
+
validation: "error" | "success" | "warning" | null | undefined;
|
|
171
171
|
validationText: string;
|
|
172
172
|
modelValue: any;
|
|
173
173
|
searchbox: boolean;
|
|
@@ -167,7 +167,7 @@ declare const __VLS_export: import("vue").DefineComponent<import("vue").ExtractP
|
|
|
167
167
|
label: string;
|
|
168
168
|
disabled: boolean;
|
|
169
169
|
loading: boolean;
|
|
170
|
-
validation: "
|
|
170
|
+
validation: "error" | "success" | "warning" | null | undefined;
|
|
171
171
|
validationText: string;
|
|
172
172
|
modelValue: any;
|
|
173
173
|
searchbox: boolean;
|
|
@@ -110,5 +110,5 @@ export declare function useKTreePickerLogic(props: KTreePickerProps, emit: any):
|
|
|
110
110
|
toggleDropdown: () => void;
|
|
111
111
|
closeDropdown: () => void;
|
|
112
112
|
filteredOptions: import("vue").ComputedRef<import("@katlux/providers").TDataRow[]>;
|
|
113
|
-
loading: import("vue").
|
|
113
|
+
loading: import("vue").Ref<boolean, boolean>;
|
|
114
114
|
};
|
|
@@ -18,7 +18,7 @@ export declare const MultiTabsDefaultProps: {
|
|
|
18
18
|
};
|
|
19
19
|
};
|
|
20
20
|
export declare function useMultiTabsLogic(props: any, emit: any): {
|
|
21
|
-
groups: import("vue").WritableComputedRef<
|
|
21
|
+
groups: import("vue").WritableComputedRef<MultiTabsGroup[], MultiTabsGroup[]>;
|
|
22
22
|
addTab: (tab: MultiTabsTab, groupId?: string) => void;
|
|
23
23
|
splitScreen: (initialTab?: MultiTabsTab) => string;
|
|
24
24
|
closeSplit: (groupId: string) => void;
|
|
@@ -17,31 +17,42 @@ export function useMultiTabsLogic(props, emit) {
|
|
|
17
17
|
}
|
|
18
18
|
});
|
|
19
19
|
const addTab = (tab, groupId) => {
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
if (group) {
|
|
24
|
-
group.tabs.forEach((t) => t.isOpen = false);
|
|
20
|
+
const targetGroupId = groupId || groups.value[0]?.id;
|
|
21
|
+
const newGroups = groups.value.map((group) => {
|
|
22
|
+
if (group.id !== targetGroupId) return group;
|
|
25
23
|
const existingTabIndex = group.tabs.findIndex((t) => t.id === tab.id);
|
|
24
|
+
let newTabs;
|
|
26
25
|
if (existingTabIndex >= 0) {
|
|
27
|
-
group.tabs
|
|
26
|
+
newTabs = group.tabs.map((t, idx) => ({
|
|
27
|
+
...t,
|
|
28
|
+
isOpen: idx === existingTabIndex
|
|
29
|
+
}));
|
|
28
30
|
} else {
|
|
29
|
-
|
|
31
|
+
newTabs = [
|
|
32
|
+
...group.tabs.map((t) => ({ ...t, isOpen: false })),
|
|
33
|
+
{ ...tab, isOpen: true }
|
|
34
|
+
];
|
|
30
35
|
}
|
|
31
|
-
|
|
32
|
-
|
|
36
|
+
return {
|
|
37
|
+
...group,
|
|
38
|
+
tabs: newTabs
|
|
39
|
+
};
|
|
40
|
+
});
|
|
41
|
+
groups.value = newGroups;
|
|
33
42
|
};
|
|
34
43
|
const splitScreen = (initialTab) => {
|
|
35
|
-
const gs = [...groups.value];
|
|
36
44
|
const newId = `group-${Date.now()}`;
|
|
37
45
|
const tabs = initialTab ? [{ ...initialTab, isOpen: true }] : [];
|
|
38
|
-
|
|
39
|
-
|
|
46
|
+
const newGroups = [
|
|
47
|
+
...groups.value.map((g) => ({ ...g, tabs: [...g.tabs] })),
|
|
48
|
+
{ id: newId, tabs }
|
|
49
|
+
];
|
|
50
|
+
groups.value = newGroups;
|
|
40
51
|
return newId;
|
|
41
52
|
};
|
|
42
53
|
const closeSplit = (groupId) => {
|
|
43
|
-
const
|
|
44
|
-
groups.value =
|
|
54
|
+
const filtered = groups.value.filter((g) => g.id !== groupId).map((g) => ({ ...g, tabs: [...g.tabs] }));
|
|
55
|
+
groups.value = filtered.length > 0 ? filtered : [{ id: "default", tabs: [] }];
|
|
45
56
|
};
|
|
46
57
|
return {
|
|
47
58
|
groups,
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type Ref } from 'vue';
|
|
2
|
+
import type { IDataFilter, IDataSort, TDataRow } from '@katlux/providers';
|
|
3
|
+
export interface IUseDataProviderReturn<T = TDataRow> {
|
|
4
|
+
rawProvider: any;
|
|
5
|
+
pageData: Ref<T[]>;
|
|
6
|
+
rowCount: Ref<number>;
|
|
7
|
+
currentPage: Ref<number>;
|
|
8
|
+
pageSize: Ref<number>;
|
|
9
|
+
loading: Ref<boolean>;
|
|
10
|
+
initialLoad: Ref<boolean>;
|
|
11
|
+
error: Ref<any>;
|
|
12
|
+
filter: Ref<IDataFilter | null>;
|
|
13
|
+
sortList: Ref<IDataSort[]>;
|
|
14
|
+
selectedRows: Ref<any[]>;
|
|
15
|
+
selectAll: Ref<boolean>;
|
|
16
|
+
setCurrentPage: (page: number) => void;
|
|
17
|
+
setPageSize: (size: number) => void;
|
|
18
|
+
setFilter: (filter: IDataFilter | null) => void;
|
|
19
|
+
setSortList: (sortList: IDataSort[]) => void;
|
|
20
|
+
refresh: (hardRefresh?: boolean) => Promise<void>;
|
|
21
|
+
loadPageData: (options?: {
|
|
22
|
+
disableCache?: boolean;
|
|
23
|
+
}) => Promise<void> | void;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* useDataProvider
|
|
27
|
+
*
|
|
28
|
+
* Idiomatic Vue 3 composable bridge for Katlux DataProviders.
|
|
29
|
+
* Connects any standalone framework-agnostic ADataProvider (or legacy provider)
|
|
30
|
+
* to Vue 3's reactivity system.
|
|
31
|
+
*
|
|
32
|
+
* Features:
|
|
33
|
+
* - Subscribes to provider updates and syncs reactive refs automatically.
|
|
34
|
+
* - Cleans up listeners automatically with onScopeDispose (zero SSR memory leaks).
|
|
35
|
+
* - Bi-directional syncing for currentPage, pageSize, and filter.
|
|
36
|
+
*/
|
|
37
|
+
export declare function useDataProvider<T = TDataRow>(provider: any): IUseDataProviderReturn<T>;
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { ref, shallowRef, onScopeDispose, isRef } from "vue";
|
|
2
|
+
export function useDataProvider(provider) {
|
|
3
|
+
if (!provider) {
|
|
4
|
+
const emptyArray = shallowRef([]);
|
|
5
|
+
return {
|
|
6
|
+
rawProvider: null,
|
|
7
|
+
pageData: emptyArray,
|
|
8
|
+
rowCount: ref(0),
|
|
9
|
+
currentPage: ref(1),
|
|
10
|
+
pageSize: ref(10),
|
|
11
|
+
loading: ref(false),
|
|
12
|
+
initialLoad: ref(false),
|
|
13
|
+
error: ref(null),
|
|
14
|
+
filter: ref(null),
|
|
15
|
+
sortList: ref([]),
|
|
16
|
+
selectedRows: ref([]),
|
|
17
|
+
selectAll: ref(false),
|
|
18
|
+
setCurrentPage: () => {
|
|
19
|
+
},
|
|
20
|
+
setPageSize: () => {
|
|
21
|
+
},
|
|
22
|
+
setFilter: () => {
|
|
23
|
+
},
|
|
24
|
+
setSortList: () => {
|
|
25
|
+
},
|
|
26
|
+
refresh: async () => {
|
|
27
|
+
},
|
|
28
|
+
loadPageData: () => {
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
const extractVal = (prop, fallback) => {
|
|
33
|
+
if (prop === void 0 || prop === null) return fallback;
|
|
34
|
+
if (isRef(prop) || typeof prop === "object" && "value" in prop) {
|
|
35
|
+
return prop.value !== void 0 ? prop.value : fallback;
|
|
36
|
+
}
|
|
37
|
+
return prop;
|
|
38
|
+
};
|
|
39
|
+
const pageData = shallowRef(
|
|
40
|
+
Array.isArray(provider.pageData) ? [...provider.pageData] : extractVal(provider.pageData, [])
|
|
41
|
+
);
|
|
42
|
+
const rowCount = ref(extractVal(provider.rowCount, 0));
|
|
43
|
+
const currentPage = ref(extractVal(provider.currentPage, 1));
|
|
44
|
+
const pageSize = ref(extractVal(provider.pageSize, 10));
|
|
45
|
+
const loading = ref(extractVal(provider.loading, false));
|
|
46
|
+
const initialLoad = ref(extractVal(provider.initialLoad, false));
|
|
47
|
+
const error = ref(extractVal(provider.error, null));
|
|
48
|
+
const filter = ref(extractVal(provider.filter, null));
|
|
49
|
+
const sortList = ref(extractVal(provider.sortList, []));
|
|
50
|
+
const selectedRows = ref(extractVal(provider.selectedRows, []));
|
|
51
|
+
const selectAll = ref(extractVal(provider.selectAll, false));
|
|
52
|
+
const syncFromProvider = () => {
|
|
53
|
+
pageData.value = Array.isArray(provider.pageData) ? [...provider.pageData] : extractVal(provider.pageData, []);
|
|
54
|
+
rowCount.value = extractVal(provider.rowCount, 0);
|
|
55
|
+
currentPage.value = extractVal(provider.currentPage, 1);
|
|
56
|
+
pageSize.value = extractVal(provider.pageSize, 10);
|
|
57
|
+
loading.value = extractVal(provider.loading, false);
|
|
58
|
+
initialLoad.value = extractVal(provider.initialLoad, false);
|
|
59
|
+
error.value = extractVal(provider.error, null);
|
|
60
|
+
filter.value = extractVal(provider.filter, null);
|
|
61
|
+
sortList.value = extractVal(provider.sortList, []);
|
|
62
|
+
selectedRows.value = extractVal(provider.selectedRows, []);
|
|
63
|
+
selectAll.value = extractVal(provider.selectAll, false);
|
|
64
|
+
};
|
|
65
|
+
if (typeof provider.subscribe === "function") {
|
|
66
|
+
const unsubscribe = provider.subscribe(() => {
|
|
67
|
+
syncFromProvider();
|
|
68
|
+
});
|
|
69
|
+
try {
|
|
70
|
+
onScopeDispose(unsubscribe);
|
|
71
|
+
} catch {
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
const setCurrentPage = (page) => {
|
|
75
|
+
if (typeof provider.setCurrentPage === "function") {
|
|
76
|
+
provider.setCurrentPage(page);
|
|
77
|
+
} else if (provider.currentPage) {
|
|
78
|
+
provider.currentPage.value = page;
|
|
79
|
+
}
|
|
80
|
+
currentPage.value = page;
|
|
81
|
+
};
|
|
82
|
+
const setPageSize = (size) => {
|
|
83
|
+
if (typeof provider.setPageSize === "function") {
|
|
84
|
+
provider.setPageSize(size);
|
|
85
|
+
} else if (provider.pageSize) {
|
|
86
|
+
provider.pageSize.value = size;
|
|
87
|
+
}
|
|
88
|
+
pageSize.value = size;
|
|
89
|
+
};
|
|
90
|
+
const setFilter = (f) => {
|
|
91
|
+
if (typeof provider.setFilter === "function") {
|
|
92
|
+
provider.setFilter(f);
|
|
93
|
+
} else if (provider.filter) {
|
|
94
|
+
provider.filter.value = f;
|
|
95
|
+
}
|
|
96
|
+
filter.value = f;
|
|
97
|
+
};
|
|
98
|
+
const setSortList = (s) => {
|
|
99
|
+
if (typeof provider.setSortList === "function") {
|
|
100
|
+
provider.setSortList(s);
|
|
101
|
+
} else if (provider.sortList) {
|
|
102
|
+
provider.sortList.value = s;
|
|
103
|
+
}
|
|
104
|
+
sortList.value = s;
|
|
105
|
+
};
|
|
106
|
+
const refresh = async (hardRefresh = false) => {
|
|
107
|
+
if (typeof provider.refresh === "function") {
|
|
108
|
+
await provider.refresh(hardRefresh);
|
|
109
|
+
} else if (typeof provider.loadPageData === "function") {
|
|
110
|
+
await provider.loadPageData({ disableCache: hardRefresh });
|
|
111
|
+
}
|
|
112
|
+
syncFromProvider();
|
|
113
|
+
};
|
|
114
|
+
const loadPageData = (options) => {
|
|
115
|
+
if (typeof provider.loadPageData === "function") {
|
|
116
|
+
provider.loadPageData(options);
|
|
117
|
+
}
|
|
118
|
+
syncFromProvider();
|
|
119
|
+
};
|
|
120
|
+
return {
|
|
121
|
+
rawProvider: provider,
|
|
122
|
+
pageData,
|
|
123
|
+
rowCount,
|
|
124
|
+
currentPage,
|
|
125
|
+
pageSize,
|
|
126
|
+
loading,
|
|
127
|
+
initialLoad,
|
|
128
|
+
error,
|
|
129
|
+
filter,
|
|
130
|
+
sortList,
|
|
131
|
+
selectedRows,
|
|
132
|
+
selectAll,
|
|
133
|
+
setCurrentPage,
|
|
134
|
+
setPageSize,
|
|
135
|
+
setFilter,
|
|
136
|
+
setSortList,
|
|
137
|
+
refresh,
|
|
138
|
+
loadPageData
|
|
139
|
+
};
|
|
140
|
+
}
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
* Creates a debounced version of a function.
|
|
3
|
-
* @param callback The function to debounce.
|
|
4
|
-
* @param delay The delay in milliseconds.
|
|
5
|
-
* @returns A debounced function that calls the original callback after the delay.
|
|
6
|
-
*/
|
|
1
|
+
import { debounce } from '@katlux/providers';
|
|
7
2
|
export declare const useDebounce: <T extends (...args: any[]) => any>(callback: T, delay: number) => ((...args: Parameters<T>) => void);
|
|
3
|
+
export { debounce };
|
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
if (timeoutId !== null) {
|
|
5
|
-
clearTimeout(timeoutId);
|
|
6
|
-
}
|
|
7
|
-
timeoutId = setTimeout(() => {
|
|
8
|
-
callback.apply(this, args);
|
|
9
|
-
}, delay);
|
|
10
|
-
};
|
|
11
|
-
};
|
|
1
|
+
import { useDebounce as providersUseDebounce, debounce } from "@katlux/providers";
|
|
2
|
+
export const useDebounce = providersUseDebounce;
|
|
3
|
+
export { debounce };
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { evaluateFilter, filterTreeData, filterData, applyOperator, compareAnd, compareOr, compareIn, compareEqual, compareValues } from '@katlux/providers';
|
|
2
2
|
export declare const useFilterLogic: () => {
|
|
3
|
-
evaluateFilter: (filter: IDataFilter, row: TDataRow) => boolean;
|
|
4
|
-
filterTreeData: (nodes: any[], filter: IDataFilter, options: {
|
|
3
|
+
evaluateFilter: (filter: import("@katlux/providers").IDataFilter, row: import("@katlux/providers").TDataRow) => boolean;
|
|
4
|
+
filterTreeData: (nodes: any[], filter: import("@katlux/providers").IDataFilter, options: {
|
|
5
5
|
idKey: string;
|
|
6
6
|
parentKey: string;
|
|
7
7
|
}) => {
|
|
8
8
|
visibleNodes: any[];
|
|
9
9
|
expandedNodes: Set<string | number>;
|
|
10
10
|
};
|
|
11
|
-
filterData: (data: any[], filter: IDataFilter, options?: {
|
|
11
|
+
filterData: (data: any[], filter: import("@katlux/providers").IDataFilter, options?: {
|
|
12
12
|
treeOptions?: {
|
|
13
13
|
idKey: string;
|
|
14
14
|
parentKey: string;
|
|
@@ -18,3 +18,4 @@ export declare const useFilterLogic: () => {
|
|
|
18
18
|
expandedNodes?: Set<string | number>;
|
|
19
19
|
};
|
|
20
20
|
};
|
|
21
|
+
export { evaluateFilter, filterTreeData, filterData, applyOperator, compareAnd, compareOr, compareIn, compareEqual, compareValues };
|