@katlux/toolkit 0.1.1-alpha.114 → 0.1.1-alpha.116

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 (122) hide show
  1. package/dist/compiled/composables/useDataProvider.mjs +176 -21
  2. package/dist/compiled/composables/useDataProvider.spec.mjs +52 -0
  3. package/dist/module.json +1 -1
  4. package/dist/runtime/components/KAccordion/KAccordion.global.d.vue.ts +23 -2
  5. package/dist/runtime/components/KAccordion/KAccordion.global.vue +7 -1
  6. package/dist/runtime/components/KAccordion/KAccordion.global.vue.d.ts +23 -2
  7. package/dist/runtime/components/KAccordion/KAccordion.logic.d.ts +12 -1
  8. package/dist/runtime/components/KAccordion/KAccordion.logic.js +32 -4
  9. package/dist/runtime/components/KAlert/KAlert.global.d.vue.ts +4 -1
  10. package/dist/runtime/components/KAlert/KAlert.global.vue +8 -2
  11. package/dist/runtime/components/KAlert/KAlert.global.vue.d.ts +4 -1
  12. package/dist/runtime/components/KAlert/KAlert.logic.d.ts +6 -1
  13. package/dist/runtime/components/KAlert/KAlert.logic.js +12 -2
  14. package/dist/runtime/components/KButton/KButton.logic.d.ts +1 -1
  15. package/dist/runtime/components/KCalendar/KCalendar.global.d.vue.ts +11 -0
  16. package/dist/runtime/components/KCalendar/KCalendar.global.vue +1 -1
  17. package/dist/runtime/components/KCalendar/KCalendar.global.vue.d.ts +11 -0
  18. package/dist/runtime/components/KCalendar/KCalendar.logic.d.ts +6 -0
  19. package/dist/runtime/components/KCalendar/KCalendar.logic.js +13 -4
  20. package/dist/runtime/components/KCheckbox/KCheckbox.global.d.vue.ts +1 -1
  21. package/dist/runtime/components/KCheckbox/KCheckbox.global.vue.d.ts +1 -1
  22. package/dist/runtime/components/KCombobox/KCombobox.global.d.vue.ts +38 -3
  23. package/dist/runtime/components/KCombobox/KCombobox.global.vue +11 -2
  24. package/dist/runtime/components/KCombobox/KCombobox.global.vue.d.ts +38 -3
  25. package/dist/runtime/components/KCombobox/KCombobox.logic.d.ts +18 -0
  26. package/dist/runtime/components/KCombobox/KCombobox.logic.js +24 -2
  27. package/dist/runtime/components/KCompositeInput/KCompositeInput.global.d.vue.ts +7 -7
  28. package/dist/runtime/components/KCompositeInput/KCompositeInput.global.vue.d.ts +7 -7
  29. package/dist/runtime/components/KCompositeInput/KCompositeInput.logic.d.ts +3 -3
  30. package/dist/runtime/components/KDatatable/KDataIterator.global.d.vue.ts +29 -1
  31. package/dist/runtime/components/KDatatable/KDataIterator.global.vue +29 -4
  32. package/dist/runtime/components/KDatatable/KDataIterator.global.vue.d.ts +29 -1
  33. package/dist/runtime/components/KDatatable/KDataIterator.logic.d.ts +21 -2
  34. package/dist/runtime/components/KDatatable/KDataIterator.logic.js +66 -31
  35. package/dist/runtime/components/KDatatable/KDatatable.global.d.vue.ts +35 -3
  36. package/dist/runtime/components/KDatatable/KDatatable.global.vue +44 -4
  37. package/dist/runtime/components/KDatatable/KDatatable.global.vue.d.ts +35 -3
  38. package/dist/runtime/components/KDatatable/KDatatable.logic.d.ts +27 -2
  39. package/dist/runtime/components/KDatatable/KDatatable.logic.js +77 -5
  40. package/dist/runtime/components/KDatePicker/KDatePicker.global.d.vue.ts +6 -6
  41. package/dist/runtime/components/KDatePicker/KDatePicker.global.vue.d.ts +6 -6
  42. package/dist/runtime/components/KDatePicker/KDatePicker.logic.d.ts +2 -2
  43. package/dist/runtime/components/KDateTimePicker/KDateTimePicker.global.d.vue.ts +6 -6
  44. package/dist/runtime/components/KDateTimePicker/KDateTimePicker.global.vue.d.ts +6 -6
  45. package/dist/runtime/components/KDateTimePicker/KDateTimePicker.logic.d.ts +2 -2
  46. package/dist/runtime/components/KGantt/KGantt.global.d.vue.ts +8 -8
  47. package/dist/runtime/components/KGantt/KGantt.global.vue.d.ts +8 -8
  48. package/dist/runtime/components/KGantt/KGantt.logic.d.ts +4 -4
  49. package/dist/runtime/components/KHourPicker/KHourPicker.global.d.vue.ts +2 -2
  50. package/dist/runtime/components/KHourPicker/KHourPicker.global.vue.d.ts +2 -2
  51. package/dist/runtime/components/KHourSelect/KHourSelect.global.d.vue.ts +1 -1
  52. package/dist/runtime/components/KHourSelect/KHourSelect.global.vue.d.ts +1 -1
  53. package/dist/runtime/components/KLayout/KLayout.global.d.vue.ts +3 -0
  54. package/dist/runtime/components/KLayout/KLayout.global.vue +11 -0
  55. package/dist/runtime/components/KLayout/KLayout.global.vue.d.ts +3 -0
  56. package/dist/runtime/components/KMaskTextbox/KMaskTextbox.global.d.vue.ts +2 -2
  57. package/dist/runtime/components/KMaskTextbox/KMaskTextbox.global.vue.d.ts +2 -2
  58. package/dist/runtime/components/KPagination/KPagination.global.d.vue.ts +24 -2
  59. package/dist/runtime/components/KPagination/KPagination.global.vue +8 -2
  60. package/dist/runtime/components/KPagination/KPagination.global.vue.d.ts +24 -2
  61. package/dist/runtime/components/KPagination/KPagination.logic.d.ts +18 -4
  62. package/dist/runtime/components/KPagination/KPagination.logic.js +59 -10
  63. package/dist/runtime/components/KRangeSlider/KRangeSlider.global.d.vue.ts +15 -4
  64. package/dist/runtime/components/KRangeSlider/KRangeSlider.global.vue +22 -4
  65. package/dist/runtime/components/KRangeSlider/KRangeSlider.global.vue.d.ts +15 -4
  66. package/dist/runtime/components/KRangeSlider/KRangeSlider.logic.d.ts +6 -0
  67. package/dist/runtime/components/KRangeSlider/KRangeSlider.logic.js +12 -6
  68. package/dist/runtime/components/KSlider/KSlider.global.d.vue.ts +13 -2
  69. package/dist/runtime/components/KSlider/KSlider.global.vue +9 -3
  70. package/dist/runtime/components/KSlider/KSlider.global.vue.d.ts +13 -2
  71. package/dist/runtime/components/KSlider/KSlider.logic.d.ts +5 -0
  72. package/dist/runtime/components/KSlider/KSlider.logic.js +5 -1
  73. package/dist/runtime/components/KTabs/KTabItem.global.d.vue.ts +18 -0
  74. package/dist/runtime/components/KTabs/KTabItem.global.vue.d.ts +18 -0
  75. package/dist/runtime/components/KTabs/KTabItem.logic.d.ts +11 -0
  76. package/dist/runtime/components/KTabs/KTabItem.logic.js +10 -1
  77. package/dist/runtime/components/KTabs/KTabs.global.d.vue.ts +34 -1
  78. package/dist/runtime/components/KTabs/KTabs.global.vue +10 -1
  79. package/dist/runtime/components/KTabs/KTabs.global.vue.d.ts +34 -1
  80. package/dist/runtime/components/KTabs/KTabs.logic.d.ts +21 -2
  81. package/dist/runtime/components/KTabs/KTabs.logic.js +86 -3
  82. package/dist/runtime/components/KTextarea/KTextarea.global.d.vue.ts +1 -1
  83. package/dist/runtime/components/KTextarea/KTextarea.global.vue.d.ts +1 -1
  84. package/dist/runtime/components/KTextbox/KTextbox.global.d.vue.ts +3 -3
  85. package/dist/runtime/components/KTextbox/KTextbox.global.vue.d.ts +3 -3
  86. package/dist/runtime/components/KToast/KToast.global.d.vue.ts +3 -3
  87. package/dist/runtime/components/KToast/KToast.global.vue.d.ts +3 -3
  88. package/dist/runtime/components/KTree/KTree.global.d.vue.ts +48 -2
  89. package/dist/runtime/components/KTree/KTree.global.vue +13 -2
  90. package/dist/runtime/components/KTree/KTree.global.vue.d.ts +48 -2
  91. package/dist/runtime/components/KTree/KTree.logic.d.ts +26 -2
  92. package/dist/runtime/components/KTree/KTree.logic.js +41 -6
  93. package/dist/runtime/components/KTreePicker/KTreePicker.global.d.vue.ts +26 -4
  94. package/dist/runtime/components/KTreePicker/KTreePicker.global.vue +1 -1
  95. package/dist/runtime/components/KTreePicker/KTreePicker.global.vue.d.ts +26 -4
  96. package/dist/runtime/components/KTreePicker/KTreePicker.logic.d.ts +16 -0
  97. package/dist/runtime/components/KTreePicker/KTreePicker.logic.js +8 -0
  98. package/dist/runtime/components/KTreeView/KTreeView.global.d.vue.ts +4 -0
  99. package/dist/runtime/components/KTreeView/KTreeView.global.vue +5 -2
  100. package/dist/runtime/components/KTreeView/KTreeView.global.vue.d.ts +4 -0
  101. package/dist/runtime/components/KTreeView/KTreeView.logic.d.ts +4 -1
  102. package/dist/runtime/components/KTreeView/KTreeView.logic.js +7 -1
  103. package/dist/runtime/composables/useDataProvider.d.ts +15 -4
  104. package/dist/runtime/composables/useDataProvider.js +176 -21
  105. package/dist/runtime/presets/default/assets/scss/css-variables.css +1 -0
  106. package/dist/runtime/presets/default/assets/scss/css-variables.scss +1 -0
  107. package/dist/runtime/presets/default/assets/scss/index.css +5 -3
  108. package/dist/runtime/presets/default/assets/scss/index.scss +4 -3
  109. package/dist/runtime/presets/default/components/KAlert/KAlert.d.vue.ts +3 -1
  110. package/dist/runtime/presets/default/components/KAlert/KAlert.vue +3 -3
  111. package/dist/runtime/presets/default/components/KAlert/KAlert.vue.d.ts +3 -1
  112. package/dist/runtime/presets/default/components/KDatatable/KDatatable.d.vue.ts +6 -0
  113. package/dist/runtime/presets/default/components/KDatatable/KDatatable.vue +5 -1
  114. package/dist/runtime/presets/default/components/KDatatable/KDatatable.vue.d.ts +6 -0
  115. package/dist/runtime/presets/default/components/KLayout/KLayout.d.vue.ts +3 -0
  116. package/dist/runtime/presets/default/components/KLayout/KLayout.vue +66 -0
  117. package/dist/runtime/presets/default/components/KLayout/KLayout.vue.d.ts +3 -0
  118. package/dist/runtime/presets/default/components/KRangeSlider/KRangeSlider.vue +9 -0
  119. package/dist/runtime/presets/default/components/KSlider/KSlider.vue +9 -0
  120. package/dist/runtime/presets/default/components/KToast/KToast.d.vue.ts +2 -2
  121. package/dist/runtime/presets/default/components/KToast/KToast.vue.d.ts +2 -2
  122. package/package.json +1 -1
@@ -1,5 +1,13 @@
1
1
  import { type KTreePickerProps } from './KTreePicker.logic.js';
2
2
  declare const __VLS_export: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
3
+ searchtext: {
4
+ type: StringConstructor;
5
+ default: string;
6
+ };
7
+ expandedNodes: {
8
+ type: import("vue").PropType<any>;
9
+ default: undefined;
10
+ };
3
11
  label: {
4
12
  type: StringConstructor;
5
13
  default: string;
@@ -78,10 +86,20 @@ declare const __VLS_export: import("vue").DefineComponent<import("vue").ExtractP
78
86
  default: boolean;
79
87
  };
80
88
  }>, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
81
- change: (value: any) => any;
82
89
  "update:modelValue": (value: any) => any;
90
+ change: (value: any) => any;
83
91
  "update:isOptionsOpen": (value: boolean) => any;
92
+ "update:searchtext": (value: string) => any;
93
+ "update:expandedNodes": (value: any) => any;
84
94
  }, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
95
+ searchtext: {
96
+ type: StringConstructor;
97
+ default: string;
98
+ };
99
+ expandedNodes: {
100
+ type: import("vue").PropType<any>;
101
+ default: undefined;
102
+ };
85
103
  label: {
86
104
  type: StringConstructor;
87
105
  default: string;
@@ -160,24 +178,28 @@ declare const __VLS_export: import("vue").DefineComponent<import("vue").ExtractP
160
178
  default: boolean;
161
179
  };
162
180
  }>> & Readonly<{
163
- onChange?: ((value: any) => any) | undefined;
164
181
  "onUpdate:modelValue"?: ((value: any) => any) | undefined;
182
+ onChange?: ((value: any) => any) | undefined;
165
183
  "onUpdate:isOptionsOpen"?: ((value: boolean) => any) | undefined;
184
+ "onUpdate:searchtext"?: ((value: string) => any) | undefined;
185
+ "onUpdate:expandedNodes"?: ((value: any) => any) | undefined;
166
186
  }>, {
187
+ modelValue: any;
167
188
  label: string;
168
189
  disabled: boolean;
169
190
  loading: boolean;
170
191
  validation: "error" | "success" | "warning" | null | undefined;
192
+ validationText: string;
171
193
  searchbox: boolean;
194
+ searchtext: string;
172
195
  searchPlaceholder: string;
173
196
  isOptionsOpen: boolean;
174
197
  placeholder: string;
175
198
  fullWidth: boolean;
176
- validationText: string;
177
199
  closeOnSelect: boolean;
178
200
  multiSelect: boolean;
179
201
  valueField: string;
180
- modelValue: any;
202
+ expandedNodes: any;
181
203
  parentKey: string;
182
204
  iconField: string;
183
205
  idKey: string;
@@ -16,12 +16,22 @@ export interface KTreePickerProps {
16
16
  multiSelect?: boolean;
17
17
  searchbox?: boolean;
18
18
  searchPlaceholder?: string;
19
+ searchtext?: string;
20
+ expandedNodes?: Set<string | number> | (string | number)[];
19
21
  validation?: 'success' | 'warning' | 'error' | null;
20
22
  validationText?: string;
21
23
  isOptionsOpen?: boolean;
22
24
  fullWidth?: boolean;
23
25
  }
24
26
  export declare const KTreePickerDefaultProps: {
27
+ searchtext: {
28
+ type: StringConstructor;
29
+ default: string;
30
+ };
31
+ expandedNodes: {
32
+ type: PropType<any>;
33
+ default: undefined;
34
+ };
25
35
  label: {
26
36
  type: StringConstructor;
27
37
  default: string;
@@ -121,4 +131,10 @@ export declare function useKTreePickerLogic(props: KTreePickerProps, emit: any):
121
131
  virtualScroll: boolean;
122
132
  itemHeight: number;
123
133
  buffer: number;
134
+ virtualScrollState: import("vue").ComputedRef<{
135
+ loadedCount: number;
136
+ hasMore: boolean;
137
+ lastAppendedPage: number;
138
+ totalCount: number;
139
+ }>;
124
140
  };
@@ -1,4 +1,12 @@
1
1
  export const KTreePickerDefaultProps = {
2
+ searchtext: {
3
+ type: String,
4
+ default: ""
5
+ },
6
+ expandedNodes: {
7
+ type: [Object, Array],
8
+ default: void 0
9
+ },
2
10
  label: {
3
11
  type: String,
4
12
  default: ""
@@ -50,6 +50,8 @@ declare const __VLS_export: import("vue").DefineComponent<import("vue").ExtractP
50
50
  }>, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
51
51
  "update:selectedRows": (value: any[]) => any;
52
52
  "update:selectAll": (value: boolean) => any;
53
+ "update:expandedNodes": (value: any) => any;
54
+ "node-toggle": (nodeId: string | number) => any;
53
55
  }, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
54
56
  dataProvider: {
55
57
  type: import("vue").PropType<import("@katlux/providers").ADataProvider & Partial<import("@katlux/providers").ITreeDataProvider>>;
@@ -102,6 +104,8 @@ declare const __VLS_export: import("vue").DefineComponent<import("vue").ExtractP
102
104
  }>> & Readonly<{
103
105
  "onUpdate:selectedRows"?: ((value: any[]) => any) | undefined;
104
106
  "onUpdate:selectAll"?: ((value: boolean) => any) | undefined;
107
+ "onUpdate:expandedNodes"?: ((value: any) => any) | undefined;
108
+ "onNode-toggle"?: ((nodeId: string | number) => any) | undefined;
105
109
  }>, {
106
110
  bulkActions: import("@katlux/providers").IKDatatableAction[];
107
111
  selectedRows: any[];
@@ -4,6 +4,7 @@ import { useKTreeViewLogic, KTreeViewDefaultProps } from "./KTreeView.logic";
4
4
  import { usePresetComponent } from "#toolkit/composables/usePresetComponent";
5
5
  import KTreeViewDefault from "#toolkit/presets/default/components/KTreeView/KTreeView.vue";
6
6
  const props = defineProps(KTreeViewDefaultProps);
7
+ const emit = defineEmits(["update:selectedRows", "update:selectAll", "update:expandedNodes", "node-toggle"]);
7
8
  const {
8
9
  visibleRows,
9
10
  expandedNodes,
@@ -14,7 +15,7 @@ const {
14
15
  toggleRowSelection,
15
16
  toggleSelectAll,
16
17
  isRowSelected
17
- } = useKTreeViewLogic(props);
18
+ } = useKTreeViewLogic(props, emit);
18
19
  const presetComponent = usePresetComponent("KTreeView", KTreeViewDefault);
19
20
  const slots = useSlots();
20
21
  const columnHeaders = computed(() => {
@@ -56,7 +57,6 @@ const templateProps = computed(() => ({
56
57
  columnWidths: columnWidths.value,
57
58
  headerSlots: props.headerSlots || void 0
58
59
  }));
59
- const emit = defineEmits(["update:selectedRows", "update:selectAll"]);
60
60
  const onUpdateSelectedRows = (val) => {
61
61
  selectedRows.value = val;
62
62
  emit("update:selectedRows", val);
@@ -65,6 +65,9 @@ const onUpdateSelectAll = (val) => {
65
65
  selectAll.value = val;
66
66
  emit("update:selectAll", val);
67
67
  };
68
+ const onToggleNode = (nodeId) => {
69
+ toggleNode(nodeId);
70
+ };
68
71
  </script>
69
72
 
70
73
  <template lang="pug">
@@ -50,6 +50,8 @@ declare const __VLS_export: import("vue").DefineComponent<import("vue").ExtractP
50
50
  }>, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
51
51
  "update:selectedRows": (value: any[]) => any;
52
52
  "update:selectAll": (value: boolean) => any;
53
+ "update:expandedNodes": (value: any) => any;
54
+ "node-toggle": (nodeId: string | number) => any;
53
55
  }, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
54
56
  dataProvider: {
55
57
  type: import("vue").PropType<import("@katlux/providers").ADataProvider & Partial<import("@katlux/providers").ITreeDataProvider>>;
@@ -102,6 +104,8 @@ declare const __VLS_export: import("vue").DefineComponent<import("vue").ExtractP
102
104
  }>> & Readonly<{
103
105
  "onUpdate:selectedRows"?: ((value: any[]) => any) | undefined;
104
106
  "onUpdate:selectAll"?: ((value: boolean) => any) | undefined;
107
+ "onUpdate:expandedNodes"?: ((value: any) => any) | undefined;
108
+ "onNode-toggle"?: ((nodeId: string | number) => any) | undefined;
105
109
  }>, {
106
110
  bulkActions: import("@katlux/providers").IKDatatableAction[];
107
111
  selectedRows: any[];
@@ -21,10 +21,13 @@ export interface KTreeViewProps {
21
21
  cellSlots?: Record<string, any>;
22
22
  selectedRows?: any[];
23
23
  selectAll?: boolean;
24
+ expandedNodes?: Set<string | number> | (string | number)[];
24
25
  }
25
26
  export type KTreeViewEmits = {
26
27
  (e: 'update:selectedRows', value: any[]): void;
27
28
  (e: 'update:selectAll', value: boolean): void;
29
+ (e: 'update:expandedNodes', value: any): void;
30
+ (e: 'node-toggle', nodeId: string | number): void;
28
31
  };
29
32
  export declare const KTreeViewDefaultProps: {
30
33
  dataProvider: {
@@ -76,7 +79,7 @@ export declare const KTreeViewDefaultProps: {
76
79
  default: boolean;
77
80
  };
78
81
  };
79
- export declare function useKTreeViewLogic(props: KTreeViewProps): {
82
+ export declare function useKTreeViewLogic(props: KTreeViewProps, emit?: KTreeViewEmits): {
80
83
  visibleRows: import("vue").ComputedRef<TTreeRow[]>;
81
84
  expandedNodes: any;
82
85
  selectedRows: import("vue").Ref<any[], any[]>;
@@ -50,7 +50,7 @@ export const KTreeViewDefaultProps = {
50
50
  }
51
51
  };
52
52
  import { useDataProvider } from "../../composables/useDataProvider.js";
53
- export function useKTreeViewLogic(props) {
53
+ export function useKTreeViewLogic(props, emit) {
54
54
  const { pageData } = useDataProvider(props.dataProvider);
55
55
  const selectedRows = ref(props.selectedRows || []);
56
56
  const selectAll = ref(props.selectAll || false);
@@ -73,6 +73,12 @@ export function useKTreeViewLogic(props) {
73
73
  } else {
74
74
  console.warn("DataProvider does not support toggleNode");
75
75
  }
76
+ const currentExpanded = props.dataProvider?.expandedNodes;
77
+ const exp = currentExpanded ? "value" in currentExpanded ? currentExpanded.value : currentExpanded : void 0;
78
+ emit?.("node-toggle", nodeId);
79
+ if (exp !== void 0) {
80
+ emit?.("update:expandedNodes", exp);
81
+ }
76
82
  };
77
83
  const toggleRowSelection = (row) => {
78
84
  const index = selectedRows.value.findIndex((r) => r[props.idKey] === row[props.idKey]);
@@ -1,5 +1,13 @@
1
- import { type Ref } from 'vue';
2
- import type { IDataFilter, IDataSort, TDataRow } from '@katlux/providers';
1
+ import { type Ref, type WritableComputedRef } from 'vue';
2
+ import type { IDataFilter, IDataSort, TDataRow, IDataProviderState } from '@katlux/providers';
3
+ export interface IUseDataProviderOptions<TRow = any> {
4
+ currentPage?: Ref<number> | WritableComputedRef<number>;
5
+ pageSize?: Ref<number> | WritableComputedRef<number>;
6
+ filter?: Ref<IDataFilter | null> | WritableComputedRef<IDataFilter | null>;
7
+ sortList?: Ref<IDataSort[]> | WritableComputedRef<IDataSort[]>;
8
+ selectedRows?: Ref<TRow[]> | WritableComputedRef<TRow[]>;
9
+ selectAll?: Ref<boolean> | WritableComputedRef<boolean>;
10
+ }
3
11
  export interface IUseDataProviderReturn<T = TDataRow> {
4
12
  rawProvider: any;
5
13
  pageData: Ref<T[]>;
@@ -21,6 +29,8 @@ export interface IUseDataProviderReturn<T = TDataRow> {
21
29
  loadPageData: (options?: {
22
30
  disableCache?: boolean;
23
31
  }) => Promise<void> | void;
32
+ getState: () => IDataProviderState<T>;
33
+ setState: (partial: Partial<IDataProviderState<T>>) => void;
24
34
  }
25
35
  /**
26
36
  * useDataProvider
@@ -31,7 +41,8 @@ export interface IUseDataProviderReturn<T = TDataRow> {
31
41
  *
32
42
  * Features:
33
43
  * - Subscribes to provider updates and syncs reactive refs automatically.
44
+ * - Supports external reactive bindings (e.g. Pinia stores, route query) via options.
45
+ * - Bidirectional synchronization with recursion-guard protection.
34
46
  * - Cleans up listeners automatically with onScopeDispose (zero SSR memory leaks).
35
- * - Bi-directional syncing for currentPage, pageSize, and filter.
36
47
  */
37
- export declare function useDataProvider<T = TDataRow>(provider: any | Ref<any> | (() => any)): IUseDataProviderReturn<T>;
48
+ export declare function useDataProvider<T = TDataRow>(provider: any | Ref<any> | (() => any), options?: IUseDataProviderOptions<T>): IUseDataProviderReturn<T>;
@@ -1,5 +1,5 @@
1
1
  import { ref, shallowRef, onScopeDispose, isRef, watch } from "vue";
2
- export function useDataProvider(provider) {
2
+ export function useDataProvider(provider, options) {
3
3
  const resolveProvider = () => {
4
4
  if (typeof provider === "function") return provider();
5
5
  return isRef(provider) ? provider.value : provider;
@@ -16,15 +16,17 @@ export function useDataProvider(provider) {
16
16
  activeProvider ? activeProvider.pageData?.value !== void 0 ? activeProvider.pageData.value : Array.isArray(activeProvider.pageData) ? activeProvider.pageData : extractVal(activeProvider.pageData, []) : []
17
17
  );
18
18
  const rowCount = ref(activeProvider ? extractVal(activeProvider.rowCount, 0) : 0);
19
- const currentPage = ref(activeProvider ? extractVal(activeProvider.currentPage, 1) : 1);
20
- const pageSize = ref(activeProvider ? extractVal(activeProvider.pageSize, 10) : 10);
19
+ const currentPage = options?.currentPage || ref(activeProvider ? extractVal(activeProvider.currentPage, 1) : 1);
20
+ const pageSize = options?.pageSize || ref(activeProvider ? extractVal(activeProvider.pageSize, 10) : 10);
21
21
  const loading = ref(activeProvider ? extractVal(activeProvider.loading, false) : false);
22
22
  const initialLoad = ref(activeProvider ? extractVal(activeProvider.initialLoad, false) : false);
23
23
  const error = ref(activeProvider ? extractVal(activeProvider.error, null) : null);
24
- const filter = ref(activeProvider ? extractVal(activeProvider.filter, null) : null);
25
- const sortList = ref(activeProvider ? extractVal(activeProvider.sortList, []) : []);
26
- const selectedRows = ref(activeProvider ? extractVal(activeProvider.selectedRows, []) : []);
27
- const selectAll = ref(activeProvider ? extractVal(activeProvider.selectAll, false) : false);
24
+ const filter = options?.filter || ref(activeProvider ? extractVal(activeProvider.filter, null) : null);
25
+ const sortList = options?.sortList || ref(activeProvider ? extractVal(activeProvider.sortList, []) : []);
26
+ const selectedRows = options?.selectedRows || ref(activeProvider ? extractVal(activeProvider.selectedRows, []) : []);
27
+ const selectAll = options?.selectAll || ref(activeProvider ? extractVal(activeProvider.selectAll, false) : false);
28
+ let isSyncingFromProvider = false;
29
+ let isSyncingToProvider = false;
28
30
  const syncFromProvider = () => {
29
31
  if (!activeProvider) {
30
32
  pageData.value = [];
@@ -40,17 +42,40 @@ export function useDataProvider(provider) {
40
42
  selectAll.value = false;
41
43
  return;
42
44
  }
43
- pageData.value = activeProvider.pageData?.value !== void 0 ? activeProvider.pageData.value : Array.isArray(activeProvider.pageData) ? activeProvider.pageData : extractVal(activeProvider.pageData, []);
44
- rowCount.value = extractVal(activeProvider.rowCount, 0);
45
- currentPage.value = extractVal(activeProvider.currentPage, 1);
46
- pageSize.value = extractVal(activeProvider.pageSize, 10);
47
- loading.value = extractVal(activeProvider.loading, false);
48
- initialLoad.value = extractVal(activeProvider.initialLoad, false);
49
- error.value = extractVal(activeProvider.error, null);
50
- filter.value = extractVal(activeProvider.filter, null);
51
- sortList.value = extractVal(activeProvider.sortList, []);
52
- selectedRows.value = extractVal(activeProvider.selectedRows, []);
53
- selectAll.value = extractVal(activeProvider.selectAll, false);
45
+ isSyncingFromProvider = true;
46
+ try {
47
+ pageData.value = activeProvider.pageData?.value !== void 0 ? activeProvider.pageData.value : Array.isArray(activeProvider.pageData) ? activeProvider.pageData : extractVal(activeProvider.pageData, []);
48
+ rowCount.value = extractVal(activeProvider.rowCount, 0);
49
+ const newPage = extractVal(activeProvider.currentPage, 1);
50
+ if (currentPage.value !== newPage) {
51
+ currentPage.value = newPage;
52
+ }
53
+ const newSize = extractVal(activeProvider.pageSize, 10);
54
+ if (pageSize.value !== newSize) {
55
+ pageSize.value = newSize;
56
+ }
57
+ loading.value = extractVal(activeProvider.loading, false);
58
+ initialLoad.value = extractVal(activeProvider.initialLoad, false);
59
+ error.value = extractVal(activeProvider.error, null);
60
+ const newFilter = extractVal(activeProvider.filter, null);
61
+ if (JSON.stringify(filter.value) !== JSON.stringify(newFilter)) {
62
+ filter.value = newFilter;
63
+ }
64
+ const newSort = extractVal(activeProvider.sortList, []);
65
+ if (JSON.stringify(sortList.value) !== JSON.stringify(newSort)) {
66
+ sortList.value = newSort;
67
+ }
68
+ const newSelected = extractVal(activeProvider.selectedRows, []);
69
+ if (selectedRows.value !== newSelected) {
70
+ selectedRows.value = newSelected;
71
+ }
72
+ const newSelectAll = extractVal(activeProvider.selectAll, false);
73
+ if (selectAll.value !== newSelectAll) {
74
+ selectAll.value = newSelectAll;
75
+ }
76
+ } finally {
77
+ isSyncingFromProvider = false;
78
+ }
54
79
  };
55
80
  let unsubscribe = null;
56
81
  const attachListener = () => {
@@ -146,6 +171,104 @@ export function useDataProvider(provider) {
146
171
  }
147
172
  sortList.value = s;
148
173
  };
174
+ if (options?.currentPage) {
175
+ if (options.currentPage.value !== void 0 && options.currentPage.value !== extractVal(activeProvider?.currentPage, 1)) {
176
+ setCurrentPage(options.currentPage.value);
177
+ }
178
+ watch(options.currentPage, (newVal) => {
179
+ if (isSyncingFromProvider || isSyncingToProvider) return;
180
+ if (activeProvider && extractVal(activeProvider.currentPage, 1) !== newVal) {
181
+ isSyncingToProvider = true;
182
+ try {
183
+ setCurrentPage(newVal);
184
+ } finally {
185
+ isSyncingToProvider = false;
186
+ }
187
+ }
188
+ });
189
+ }
190
+ if (options?.pageSize) {
191
+ if (options.pageSize.value !== void 0 && options.pageSize.value !== extractVal(activeProvider?.pageSize, 10)) {
192
+ setPageSize(options.pageSize.value);
193
+ }
194
+ watch(options.pageSize, (newVal) => {
195
+ if (isSyncingFromProvider || isSyncingToProvider) return;
196
+ if (activeProvider && extractVal(activeProvider.pageSize, 10) !== newVal) {
197
+ isSyncingToProvider = true;
198
+ try {
199
+ setPageSize(newVal);
200
+ } finally {
201
+ isSyncingToProvider = false;
202
+ }
203
+ }
204
+ });
205
+ }
206
+ if (options?.filter) {
207
+ if (options.filter.value !== void 0 && options.filter.value !== null) {
208
+ setFilter(options.filter.value);
209
+ }
210
+ watch(options.filter, (newVal) => {
211
+ if (isSyncingFromProvider || isSyncingToProvider) return;
212
+ if (activeProvider && JSON.stringify(extractVal(activeProvider.filter, null)) !== JSON.stringify(newVal)) {
213
+ isSyncingToProvider = true;
214
+ try {
215
+ setFilter(newVal);
216
+ } finally {
217
+ isSyncingToProvider = false;
218
+ }
219
+ }
220
+ }, { deep: true });
221
+ }
222
+ if (options?.sortList) {
223
+ if (options.sortList.value !== void 0 && options.sortList.value.length > 0) {
224
+ setSortList(options.sortList.value);
225
+ }
226
+ watch(options.sortList, (newVal) => {
227
+ if (isSyncingFromProvider || isSyncingToProvider) return;
228
+ if (activeProvider && JSON.stringify(extractVal(activeProvider.sortList, [])) !== JSON.stringify(newVal)) {
229
+ isSyncingToProvider = true;
230
+ try {
231
+ setSortList(newVal);
232
+ } finally {
233
+ isSyncingToProvider = false;
234
+ }
235
+ }
236
+ }, { deep: true });
237
+ }
238
+ if (options?.selectedRows) {
239
+ watch(options.selectedRows, (newVal) => {
240
+ if (isSyncingFromProvider || isSyncingToProvider) return;
241
+ if (activeProvider) {
242
+ isSyncingToProvider = true;
243
+ try {
244
+ if (typeof activeProvider.setSelectedRows === "function") {
245
+ activeProvider.setSelectedRows(newVal);
246
+ } else {
247
+ activeProvider.selectedRows = newVal;
248
+ }
249
+ } finally {
250
+ isSyncingToProvider = false;
251
+ }
252
+ }
253
+ }, { deep: true });
254
+ }
255
+ if (options?.selectAll) {
256
+ watch(options.selectAll, (newVal) => {
257
+ if (isSyncingFromProvider || isSyncingToProvider) return;
258
+ if (activeProvider && extractVal(activeProvider.selectAll, false) !== newVal) {
259
+ isSyncingToProvider = true;
260
+ try {
261
+ if (typeof activeProvider.setSelectAll === "function") {
262
+ activeProvider.setSelectAll(newVal);
263
+ } else {
264
+ activeProvider.selectAll = newVal;
265
+ }
266
+ } finally {
267
+ isSyncingToProvider = false;
268
+ }
269
+ }
270
+ });
271
+ }
149
272
  const refresh = async (hardRefresh = false) => {
150
273
  if (!activeProvider) return;
151
274
  if (typeof activeProvider.refresh === "function") {
@@ -155,13 +278,43 @@ export function useDataProvider(provider) {
155
278
  }
156
279
  syncFromProvider();
157
280
  };
158
- const loadPageData = (options) => {
281
+ const loadPageData = (options2) => {
159
282
  if (!activeProvider) return;
160
283
  if (typeof activeProvider.loadPageData === "function") {
161
- activeProvider.loadPageData(options);
284
+ activeProvider.loadPageData(options2);
162
285
  }
163
286
  syncFromProvider();
164
287
  };
288
+ const getState = () => {
289
+ if (activeProvider && typeof activeProvider.getState === "function") {
290
+ return activeProvider.getState();
291
+ }
292
+ return {
293
+ pageData: pageData.value,
294
+ rowCount: rowCount.value,
295
+ currentPage: currentPage.value,
296
+ pageSize: pageSize.value,
297
+ loading: loading.value,
298
+ initialLoad: initialLoad.value,
299
+ error: error.value,
300
+ filter: filter.value,
301
+ sortList: sortList.value,
302
+ selectedRows: selectedRows.value,
303
+ selectAll: selectAll.value
304
+ };
305
+ };
306
+ const setState = (partial) => {
307
+ if (activeProvider && typeof activeProvider.setState === "function") {
308
+ activeProvider.setState(partial);
309
+ } else {
310
+ if (partial.currentPage !== void 0) setCurrentPage(partial.currentPage);
311
+ if (partial.pageSize !== void 0) setPageSize(partial.pageSize);
312
+ if (partial.filter !== void 0) setFilter(partial.filter);
313
+ if (partial.sortList !== void 0) setSortList(partial.sortList);
314
+ if (partial.selectedRows !== void 0) selectedRows.value = partial.selectedRows;
315
+ if (partial.selectAll !== void 0) selectAll.value = partial.selectAll;
316
+ }
317
+ };
165
318
  return {
166
319
  get rawProvider() {
167
320
  return activeProvider;
@@ -182,6 +335,8 @@ export function useDataProvider(provider) {
182
335
  setFilter,
183
336
  setSortList,
184
337
  refresh,
185
- loadPageData
338
+ loadPageData,
339
+ getState,
340
+ setState
186
341
  };
187
342
  }
@@ -171,6 +171,7 @@
171
171
  --input-focus-border-color: var(--primary-500);
172
172
  --input-focus-shadow: 0 0 0 3px rgba(33, 150, 243, 0.2);
173
173
  --input-height: 40px;
174
+ --input-label-color: var(--font-color-primary);
174
175
  --table-border-color: var(--neutral-300);
175
176
  --table-header-bg: var(--neutral-200);
176
177
  --table-header-color: var(--neutral-900);
@@ -243,6 +243,7 @@
243
243
  --input-focus-border-color: var(--primary-500);
244
244
  --input-focus-shadow: 0 0 0 3px rgba(33, 150, 243, 0.2);
245
245
  --input-height: 40px;
246
+ --input-label-color: var(--font-color-primary);
246
247
 
247
248
  // Table
248
249
  --table-border-color: var(--neutral-300);
@@ -188,6 +188,7 @@ li {
188
188
  --input-focus-border-color: var(--primary-500);
189
189
  --input-focus-shadow: 0 0 0 3px rgba(33, 150, 243, 0.2);
190
190
  --input-height: 40px;
191
+ --input-label-color: var(--font-color-primary);
191
192
  --table-border-color: var(--neutral-300);
192
193
  --table-header-bg: var(--neutral-200);
193
194
  --table-header-color: var(--neutral-900);
@@ -371,11 +372,12 @@ a:hover {
371
372
  }
372
373
 
373
374
  .k-input-label {
374
- font-size: var(--font-size-xs);
375
- color: var(--font-color-secondary);
376
- margin-bottom: calc(var(--gap-sm) / 2);
375
+ font-size: var(--font-size-sm, 13px);
376
+ color: var(--input-label-color, var(--font-color-primary, currentColor));
377
+ margin-bottom: calc(var(--gap-sm, 8px) / 2);
377
378
  display: block;
378
379
  font-weight: 500;
380
+ line-height: 1.4;
379
381
  }
380
382
 
381
383
  input, textarea, select {
@@ -69,11 +69,12 @@ a {
69
69
  border-color: var(--error-color) !important;
70
70
  }
71
71
  .k-input-label {
72
- font-size: var(--font-size-xs);
73
- color: var(--font-color-secondary);
74
- margin-bottom: calc(var(--gap-sm) / 2);
72
+ font-size: var(--font-size-sm, 13px);
73
+ color: var(--input-label-color, var(--font-color-primary, currentColor));
74
+ margin-bottom: calc(var(--gap-sm, 8px) / 2);
75
75
  display: block;
76
76
  font-weight: 500;
77
+ line-height: 1.4;
77
78
  }
78
79
 
79
80
  input, textarea, select {
@@ -1,7 +1,9 @@
1
1
  import { type KAlertProps } from '#toolkit/components/KAlert/KAlert.logic';
2
- declare const __VLS_export: import("vue").DefineComponent<KAlertProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
2
+ declare const __VLS_export: import("vue").DefineComponent<KAlertProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
3
+ "update:modelValue": (value: boolean) => any;
3
4
  dismiss: () => any;
4
5
  }, string, import("vue").PublicProps, Readonly<KAlertProps> & Readonly<{
6
+ "onUpdate:modelValue"?: ((value: boolean) => any) | undefined;
5
7
  onDismiss?: (() => any) | undefined;
6
8
  }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
7
9
  declare const _default: typeof __VLS_export;
@@ -12,12 +12,12 @@ Transition(name="k-alert-fade")
12
12
  </template>
13
13
 
14
14
  <script lang="ts" setup>
15
- import { useKAlertLogic, type KAlertProps } from '#toolkit/components/KAlert/KAlert.logic'
15
+ import { useKAlertLogic, type KAlertProps, type KAlertEmits } from '#toolkit/components/KAlert/KAlert.logic'
16
16
  import { useKatluxI18n } from '#toolkit/composables/useKatluxI18n'
17
17
 
18
18
  const props = defineProps<KAlertProps>()
19
- const emit = defineEmits<{ dismiss: [] }>()
20
- const { visible, dismiss, icon } = useKAlertLogic(props, () => emit('dismiss'))
19
+ const emit = defineEmits<KAlertEmits>()
20
+ const { visible, dismiss, icon } = useKAlertLogic(props, emit)
21
21
 
22
22
  const { t } = useKatluxI18n()
23
23
  </script>
@@ -1,7 +1,9 @@
1
1
  import { type KAlertProps } from '#toolkit/components/KAlert/KAlert.logic';
2
- declare const __VLS_export: import("vue").DefineComponent<KAlertProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
2
+ declare const __VLS_export: import("vue").DefineComponent<KAlertProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
3
+ "update:modelValue": (value: boolean) => any;
3
4
  dismiss: () => any;
4
5
  }, string, import("vue").PublicProps, Readonly<KAlertProps> & Readonly<{
6
+ "onUpdate:modelValue"?: ((value: boolean) => any) | undefined;
5
7
  onDismiss?: (() => any) | undefined;
6
8
  }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
7
9
  declare const _default: typeof __VLS_export;
@@ -7,6 +7,8 @@ type __VLS_Props = {
7
7
  bulkActions: Array<IKDatatableAction>;
8
8
  selectedRows: any[];
9
9
  selectAll: boolean;
10
+ currentPage?: number;
11
+ pageSize?: number;
10
12
  cellSlots?: Record<string, any>;
11
13
  headerSlots?: Record<string, any>;
12
14
  columnHeaders?: Record<string, string>;
@@ -15,9 +17,13 @@ type __VLS_Props = {
15
17
  emptyFilterStateText?: string;
16
18
  };
17
19
  declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
20
+ "update:currentPage": (value: number) => any;
21
+ "update:pageSize": (value: number) => any;
18
22
  "update:selectedRows": (value: any[]) => any;
19
23
  "update:selectAll": (value: boolean) => any;
20
24
  }, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
25
+ "onUpdate:currentPage"?: ((value: number) => any) | undefined;
26
+ "onUpdate:pageSize"?: ((value: number) => any) | undefined;
21
27
  "onUpdate:selectedRows"?: ((value: any[]) => any) | undefined;
22
28
  "onUpdate:selectAll"?: ((value: boolean) => any) | undefined;
23
29
  }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
@@ -53,7 +53,7 @@
53
53
  template(#default v-if="!rowAction.iconOnly && !rowAction.icon") {{rowAction.label}}
54
54
  .footer
55
55
  KBulkActions.bulk-actions(v-if="props.bulkActions && props.bulkActions.length>0" :bulkActions="props.bulkActions" :selectedRows="selectedRows" :selectAll="selectAll")
56
- KPagination.pagination(:dataProvider="props.dataProvider")
56
+ KPagination.pagination(:dataProvider="props.dataProvider" :currentPage="props.currentPage" :pageSize="props.pageSize" @update:currentPage="emit('update:currentPage', $event)" @update:pageSize="emit('update:pageSize', $event)")
57
57
  </template>
58
58
 
59
59
  <script setup lang="ts">
@@ -72,6 +72,8 @@ const props = defineProps<{
72
72
  bulkActions: Array<IKDatatableAction>
73
73
  selectedRows: any[]
74
74
  selectAll: boolean
75
+ currentPage?: number
76
+ pageSize?: number
75
77
  cellSlots?: Record<string, any>
76
78
  headerSlots?: Record<string, any>
77
79
  columnHeaders?: Record<string, string>
@@ -83,6 +85,8 @@ const props = defineProps<{
83
85
  const emit = defineEmits<{
84
86
  (e: 'update:selectedRows', value: any[]): void
85
87
  (e: 'update:selectAll', value: boolean): void
88
+ (e: 'update:currentPage', value: number): void
89
+ (e: 'update:pageSize', value: number): void
86
90
  }>()
87
91
 
88
92
  // Bi-directional binding helpers