@katlux/toolkit 0.1.1-alpha.117 → 0.1.1-alpha.119

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (118) hide show
  1. package/bin/create-preset.mjs +373 -21
  2. package/dist/compiled/composables/useKatluxContext.mjs +6 -3
  3. package/dist/compiled/composables/useKatluxForm.mjs +268 -0
  4. package/dist/compiled/composables/useToast.mjs +164 -0
  5. package/dist/compiled/composables/useVirtualScroll.mjs +176 -0
  6. package/dist/module.cjs +1 -0
  7. package/dist/module.json +1 -1
  8. package/dist/module.mjs +1 -0
  9. package/dist/runtime/components/KBulkActions/KBulkActions.global.d.vue.ts +6 -2
  10. package/dist/runtime/components/KBulkActions/KBulkActions.global.vue +3 -3
  11. package/dist/runtime/components/KBulkActions/KBulkActions.global.vue.d.ts +6 -2
  12. package/dist/runtime/components/KBulkActions/KBulkActions.logic.js +9 -0
  13. package/dist/runtime/components/KCombobox/KCombobox.global.d.vue.ts +9 -0
  14. package/dist/runtime/components/KCombobox/KCombobox.global.vue +2 -1
  15. package/dist/runtime/components/KCombobox/KCombobox.global.vue.d.ts +9 -0
  16. package/dist/runtime/components/KCombobox/KCombobox.logic.d.ts +5 -0
  17. package/dist/runtime/components/KCombobox/KCombobox.logic.js +22 -3
  18. package/dist/runtime/components/KDatatable/KDataIterator.global.d.vue.ts +8 -0
  19. package/dist/runtime/components/KDatatable/KDataIterator.global.vue +10 -2
  20. package/dist/runtime/components/KDatatable/KDataIterator.global.vue.d.ts +8 -0
  21. package/dist/runtime/components/KDatatable/KDataIterator.logic.d.ts +8 -0
  22. package/dist/runtime/components/KDatatable/KDataIterator.logic.js +10 -2
  23. package/dist/runtime/components/KDatatable/KDatatable.global.d.vue.ts +8 -0
  24. package/dist/runtime/components/KDatatable/KDatatable.global.vue +12 -4
  25. package/dist/runtime/components/KDatatable/KDatatable.global.vue.d.ts +8 -0
  26. package/dist/runtime/components/KDatatable/KDatatable.logic.d.ts +8 -0
  27. package/dist/runtime/components/KDatatable/KDatatable.logic.js +11 -3
  28. package/dist/runtime/components/KDatePicker/KDatePicker.global.d.vue.ts +2 -0
  29. package/dist/runtime/components/KDatePicker/KDatePicker.global.vue +5 -1
  30. package/dist/runtime/components/KDatePicker/KDatePicker.global.vue.d.ts +2 -0
  31. package/dist/runtime/components/KDatePicker/KDatePicker.logic.js +7 -6
  32. package/dist/runtime/components/KDateTimePicker/KDateTimePicker.logic.js +7 -6
  33. package/dist/runtime/components/KDropdown/KDropdown.global.d.vue.ts +9 -0
  34. package/dist/runtime/components/KDropdown/KDropdown.global.vue +2 -1
  35. package/dist/runtime/components/KDropdown/KDropdown.global.vue.d.ts +9 -0
  36. package/dist/runtime/components/KDropdown/KDropdown.logic.d.ts +5 -0
  37. package/dist/runtime/components/KDropdown/KDropdown.logic.js +10 -7
  38. package/dist/runtime/components/KGantt/KGantt.logic.js +11 -4
  39. package/dist/runtime/components/KPagination/KPagination.logic.js +7 -4
  40. package/dist/runtime/components/KToast/KToast.global.d.vue.ts +24 -1
  41. package/dist/runtime/components/KToast/KToast.global.vue +12 -2
  42. package/dist/runtime/components/KToast/KToast.global.vue.d.ts +24 -1
  43. package/dist/runtime/components/KToast/KToast.logic.d.ts +13 -0
  44. package/dist/runtime/components/KToast/KToast.logic.js +45 -5
  45. package/dist/runtime/components/KToastContainer/KToastContainer.global.d.vue.ts +3 -0
  46. package/dist/runtime/components/KToastContainer/KToastContainer.global.vue +11 -0
  47. package/dist/runtime/components/KToastContainer/KToastContainer.global.vue.d.ts +3 -0
  48. package/dist/runtime/components/KTree/KTree.global.d.vue.ts +38 -0
  49. package/dist/runtime/components/KTree/KTree.global.vue +7 -3
  50. package/dist/runtime/components/KTree/KTree.global.vue.d.ts +38 -0
  51. package/dist/runtime/components/KTree/KTree.logic.d.ts +21 -0
  52. package/dist/runtime/components/KTree/KTree.logic.js +17 -0
  53. package/dist/runtime/components/KTreePicker/KTreePicker.global.d.vue.ts +52 -1
  54. package/dist/runtime/components/KTreePicker/KTreePicker.global.vue +30 -3
  55. package/dist/runtime/components/KTreePicker/KTreePicker.global.vue.d.ts +52 -1
  56. package/dist/runtime/components/KTreePicker/KTreePicker.logic.d.ts +20 -0
  57. package/dist/runtime/components/KTreePicker/KTreePicker.logic.js +16 -0
  58. package/dist/runtime/components/KTreeView/KTreeView.global.d.vue.ts +36 -0
  59. package/dist/runtime/components/KTreeView/KTreeView.global.vue +5 -1
  60. package/dist/runtime/components/KTreeView/KTreeView.global.vue.d.ts +36 -0
  61. package/dist/runtime/components/KTreeView/KTreeView.logic.d.ts +20 -0
  62. package/dist/runtime/components/KTreeView/KTreeView.logic.js +16 -0
  63. package/dist/runtime/composables/useKatluxContext.js +6 -3
  64. package/dist/runtime/composables/useKatluxForm.d.ts +143 -0
  65. package/dist/runtime/composables/useKatluxForm.js +268 -0
  66. package/dist/runtime/composables/useToast.d.ts +49 -0
  67. package/dist/runtime/composables/useToast.js +164 -0
  68. package/dist/runtime/composables/useVirtualScroll.d.ts +34 -0
  69. package/dist/runtime/composables/useVirtualScroll.js +176 -0
  70. package/dist/runtime/plugins/PresetPlugin.js +9 -1
  71. package/dist/runtime/plugins/nuxtCompatPlugin.js +0 -1
  72. package/dist/runtime/plugins/toastPlugin.client.d.ts +2 -0
  73. package/dist/runtime/plugins/toastPlugin.client.js +16 -0
  74. package/dist/runtime/presets/default/components/KBulkActions/KBulkActions.vue +1 -0
  75. package/dist/runtime/presets/default/components/KCheckbox/KCheckbox.vue +36 -7
  76. package/dist/runtime/presets/default/components/KCombobox/KCombobox.d.vue.ts +1 -0
  77. package/dist/runtime/presets/default/components/KCombobox/KCombobox.vue +10 -4
  78. package/dist/runtime/presets/default/components/KCombobox/KCombobox.vue.d.ts +1 -0
  79. package/dist/runtime/presets/default/components/KCombobox/KComboboxList.d.vue.ts +1 -0
  80. package/dist/runtime/presets/default/components/KCombobox/KComboboxList.vue +7 -2
  81. package/dist/runtime/presets/default/components/KCombobox/KComboboxList.vue.d.ts +1 -0
  82. package/dist/runtime/presets/default/components/KDataIterator/KDataIterator.d.vue.ts +10 -1
  83. package/dist/runtime/presets/default/components/KDataIterator/KDataIterator.vue +128 -6
  84. package/dist/runtime/presets/default/components/KDataIterator/KDataIterator.vue.d.ts +10 -1
  85. package/dist/runtime/presets/default/components/KDatatable/KDatatable.d.vue.ts +12 -1
  86. package/dist/runtime/presets/default/components/KDatatable/KDatatable.vue +206 -27
  87. package/dist/runtime/presets/default/components/KDatatable/KDatatable.vue.d.ts +12 -1
  88. package/dist/runtime/presets/default/components/KDropdown/KDropdown.d.vue.ts +1 -0
  89. package/dist/runtime/presets/default/components/KDropdown/KDropdown.vue +23 -2
  90. package/dist/runtime/presets/default/components/KDropdown/KDropdown.vue.d.ts +1 -0
  91. package/dist/runtime/presets/default/components/KLayout/KLayout.vue +4 -2
  92. package/dist/runtime/presets/default/components/KModal/KModal.vue +8 -1
  93. package/dist/runtime/presets/default/components/KTabs/KTabItem.vue +1 -1
  94. package/dist/runtime/presets/default/components/KTextbox/KTextbox.vue +6 -4
  95. package/dist/runtime/presets/default/components/KToast/KToast.d.vue.ts +6 -0
  96. package/dist/runtime/presets/default/components/KToast/KToast.vue +22 -4
  97. package/dist/runtime/presets/default/components/KToast/KToast.vue.d.ts +6 -0
  98. package/dist/runtime/presets/default/components/KToastContainer/KToastContainer.d.vue.ts +11 -0
  99. package/dist/runtime/presets/default/components/KToastContainer/KToastContainer.vue +207 -0
  100. package/dist/runtime/presets/default/components/KToastContainer/KToastContainer.vue.d.ts +11 -0
  101. package/dist/runtime/presets/default/components/KTree/KTree.d.vue.ts +15 -5
  102. package/dist/runtime/presets/default/components/KTree/KTree.vue +232 -13
  103. package/dist/runtime/presets/default/components/KTree/KTree.vue.d.ts +15 -5
  104. package/dist/runtime/presets/default/components/KTreePicker/KTreePicker.d.vue.ts +14 -1
  105. package/dist/runtime/presets/default/components/KTreePicker/KTreePicker.vue +118 -13
  106. package/dist/runtime/presets/default/components/KTreePicker/KTreePicker.vue.d.ts +14 -1
  107. package/dist/runtime/presets/default/components/KTreeView/KTreeCell.vue +12 -3
  108. package/dist/runtime/presets/default/components/KTreeView/KTreeView.d.vue.ts +4 -0
  109. package/dist/runtime/presets/default/components/KTreeView/KTreeView.vue +8 -0
  110. package/dist/runtime/presets/default/components/KTreeView/KTreeView.vue.d.ts +4 -0
  111. package/dist/runtime/server/middleware/session.js +1 -1
  112. package/package.json +3 -4
  113. package/dist/compiled/composables/useDataProvider.spec.mjs +0 -157
  114. package/dist/compiled/composables/useKatluxContext.spec.mjs +0 -63
  115. package/dist/compiled/composables/useKatluxI18n.spec.mjs +0 -10
  116. package/dist/compiled/composables/usePresetComponent.spec.mjs +0 -106
  117. package/dist/compiled/composables/useTemplate.spec.mjs +0 -30
  118. package/dist/compiled/utils/PresetResolver.spec.mjs +0 -68
@@ -18,8 +18,12 @@ KCombobox(
18
18
  :fullWidth="fullWidth"
19
19
  :validation="validation"
20
20
  :validationText="validationText"
21
+ :maxHeight="dropdownMaxHeight"
21
22
  )
22
- .KTreePicker__tree-container
23
+ .KTreePicker__tree-container(
24
+ :class="{ 'is-virtual': virtualScroll }"
25
+ :style="containerStyle"
26
+ )
23
27
  .KTreePicker__search(v-if="searchbox")
24
28
  KTextbox(
25
29
  v-model="searchtextModel"
@@ -37,12 +41,19 @@ KCombobox(
37
41
  :isNodeSelected="isSelected"
38
42
  :searchtext="searchtext"
39
43
  :selectable="true"
44
+ :virtualScroll="virtualScroll"
45
+ :itemHeight="itemHeight"
46
+ :viewportHeight="treeViewportHeight"
47
+ :buffer="buffer"
40
48
  @select="onTreeSelect"
49
+ @node-toggle="onNodeToggle"
50
+ @update:expandedNodes="onExpandedNodesUpdate"
41
51
  )
42
52
  </template>
43
53
 
44
54
  <script lang="ts" setup>
45
- import { computed } from 'vue'
55
+ import { computed, ref, watch, onMounted, onBeforeUnmount, nextTick } from 'vue'
56
+
46
57
  // Props passed from global component (which handles the logic)
47
58
  const props = defineProps<{
48
59
  label?: string
@@ -72,11 +83,17 @@ const props = defineProps<{
72
83
  fullWidth: boolean
73
84
  validation?: 'success' | 'warning' | 'error' | null
74
85
  validationText?: string
86
+ virtualScroll?: boolean
87
+ itemHeight?: number
88
+ viewportHeight?: number
89
+ buffer?: number
75
90
  }>()
76
91
 
77
92
  const emit = defineEmits<{
78
93
  (e: 'update:searchtext', value: string): void
79
94
  (e: 'update:isOptionsOpen', value: boolean): void
95
+ (e: 'node-toggle', nodeId: string | number): void
96
+ (e: 'update:expandedNodes', value: any): void
80
97
  }>()
81
98
 
82
99
  const searchtextModel = computed({
@@ -90,17 +107,103 @@ const isOptionsOpenModel = computed({
90
107
  })
91
108
 
92
109
  function onTreeSelect(node: any) {
93
- // Call the selectItem method from logic
94
110
  props.selectItem(node)
95
-
96
- // If closeOnSelect is true, we should close the dropdown
97
- // but selectItem might have already toggled it if it was a distinct action?
98
- // In KCombobox.logic.ts: selectItem sets isOptionsOpen = !closeOnSelect
99
- // So it should be handled there!
100
-
101
- // However, selectItem expects a ComboboxItem (TDataRow).
102
- // KTree returns a node object which should be compatible.
103
111
  }
112
+
113
+ function getVisibleCount(): number {
114
+ const dp = props.dataProvider as any
115
+ if (!dp) return 0
116
+ if (Array.isArray(dp.allVisibleRows)) return dp.allVisibleRows.length
117
+ if (Array.isArray(dp.allVisibleRows?.value)) return dp.allVisibleRows.value.length
118
+ if (Array.isArray(dp.allVisibleNodes)) return dp.allVisibleNodes.length
119
+ if (Array.isArray(dp.allVisibleNodes?.value)) return dp.allVisibleNodes.value.length
120
+ if (Array.isArray(dp.visibleRows)) return dp.visibleRows.length
121
+ if (Array.isArray(dp.visibleRows?.value)) return dp.visibleRows.value.length
122
+ if (Array.isArray(dp.pageData)) return dp.pageData.length
123
+ if (Array.isArray(dp.pageData?.value)) return dp.pageData.value.length
124
+ return 0
125
+ }
126
+
127
+ const calculatedHeight = ref<number>(props.viewportHeight || 300)
128
+
129
+ function recalculateHeight() {
130
+ const count = getVisibleCount()
131
+ const itemH = props.itemHeight || 32
132
+ const maxH = props.viewportHeight || 300
133
+
134
+ if (count <= 0) {
135
+ calculatedHeight.value = Math.min(maxH, itemH * 2)
136
+ return
137
+ }
138
+
139
+ const rawHeight = count * itemH
140
+ calculatedHeight.value = Math.min(maxH, rawHeight)
141
+ }
142
+
143
+ const treeViewportHeight = computed(() => calculatedHeight.value)
144
+
145
+ const containerStyle = computed(() => {
146
+ const searchH = props.searchbox ? 44 : 0
147
+ const padding = 20
148
+ const totalH = calculatedHeight.value + searchH + padding
149
+ return {
150
+ maxHeight: `${totalH}px`,
151
+ height: props.virtualScroll ? `${totalH}px` : 'auto'
152
+ }
153
+ })
154
+
155
+ const dropdownMaxHeight = computed(() => {
156
+ return (props.viewportHeight || 300) + (props.searchbox ? 44 : 0) + 40
157
+ })
158
+
159
+ function onNodeToggle(nodeId: string | number) {
160
+ recalculateHeight()
161
+ nextTick(() => recalculateHeight())
162
+ emit('node-toggle', nodeId)
163
+ }
164
+
165
+ function onExpandedNodesUpdate(val: any) {
166
+ recalculateHeight()
167
+ nextTick(() => recalculateHeight())
168
+ emit('update:expandedNodes', val)
169
+ }
170
+
171
+ let unsubscribe: (() => void) | null = null
172
+
173
+ onMounted(() => {
174
+ recalculateHeight()
175
+ if (props.dataProvider?.subscribe) {
176
+ unsubscribe = props.dataProvider.subscribe(() => {
177
+ recalculateHeight()
178
+ })
179
+ }
180
+ })
181
+
182
+ onBeforeUnmount(() => {
183
+ if (typeof unsubscribe === 'function') {
184
+ unsubscribe()
185
+ }
186
+ })
187
+
188
+ watch(() => props.isOptionsOpen, (open) => {
189
+ if (open) {
190
+ nextTick(recalculateHeight)
191
+ }
192
+ })
193
+
194
+ watch(() => props.searchtext, () => {
195
+ nextTick(recalculateHeight)
196
+ })
197
+
198
+ watch(() => props.viewportHeight, () => {
199
+ recalculateHeight()
200
+ })
201
+
202
+ defineExpose({
203
+ recalculateHeight,
204
+ calculatedHeight,
205
+ treeViewportHeight
206
+ })
104
207
  </script>
105
208
 
106
209
  <style lang="scss" scoped>
@@ -115,7 +218,9 @@ function onTreeSelect(node: any) {
115
218
  min-width: 250px;
116
219
  background-color: var(--panel-bg-default);
117
220
  color: var(--font-color-primary);
118
- }
119
-
120
221
 
222
+ &.is-virtual {
223
+ overflow-y: hidden;
224
+ }
225
+ }
121
226
  </style>
@@ -23,13 +23,26 @@ type __VLS_Props = {
23
23
  fullWidth: boolean;
24
24
  validation?: 'success' | 'warning' | 'error' | null;
25
25
  validationText?: string;
26
+ virtualScroll?: boolean;
27
+ itemHeight?: number;
28
+ viewportHeight?: number;
29
+ buffer?: number;
26
30
  };
27
- declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
31
+ declare function recalculateHeight(): void;
32
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {
33
+ recalculateHeight: typeof recalculateHeight;
34
+ calculatedHeight: import("vue").Ref<number, number>;
35
+ treeViewportHeight: import("vue").ComputedRef<number>;
36
+ }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
28
37
  "update:isOptionsOpen": (value: boolean) => any;
29
38
  "update:searchtext": (value: string) => any;
39
+ "update:expandedNodes": (value: any) => any;
40
+ "node-toggle": (nodeId: string | number) => any;
30
41
  }, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
31
42
  "onUpdate:isOptionsOpen"?: ((value: boolean) => any) | undefined;
32
43
  "onUpdate:searchtext"?: ((value: string) => any) | undefined;
44
+ "onUpdate:expandedNodes"?: ((value: any) => any) | undefined;
45
+ "onNode-toggle"?: ((nodeId: string | number) => any) | undefined;
33
46
  }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
34
47
  declare const _default: typeof __VLS_export;
35
48
  export default _default;
@@ -1,6 +1,15 @@
1
1
  <template lang="pug">
2
- .tree-cell(:style="{ '--tree-depth': depth }")
3
- .tree-toggle(v-if="hasChildren" @click.stop="toggle")
2
+ .tree-cell(:style="{ '--tree-node-depth': depth, '--tree-depth': depth }")
3
+ .tree-toggle(
4
+ v-if="hasChildren"
5
+ role="button"
6
+ tabindex="0"
7
+ :aria-expanded="isExpanded"
8
+ aria-label="Toggle node"
9
+ @click.stop="toggle"
10
+ @keydown.enter.prevent.stop="toggle"
11
+ @keydown.space.prevent.stop="toggle"
12
+ )
4
13
  KIcon(iconname="chevron" :width="12" :height="12" :rotate="isExpanded ? '90' : '0'")
5
14
  .tree-spacer(v-else)
6
15
  span.tree-content {{ value }}
@@ -21,7 +30,7 @@ defineProps<{
21
30
  display: flex;
22
31
  align-items: center;
23
32
  gap: 4px;
24
- padding-left: calc(var(--tree-depth, 0) * var(--tree-indent, 24px));
33
+ padding-left: calc(var(--tree-node-depth, var(--tree-depth, 0)) * var(--tree-indent, 24px));
25
34
  }
26
35
 
27
36
  .tree-toggle {
@@ -18,6 +18,10 @@ type __VLS_Props = {
18
18
  headerSlots?: Record<string, any>;
19
19
  columnHeaders?: Record<string, string>;
20
20
  columnWidths?: Record<string, string>;
21
+ virtualScroll?: boolean;
22
+ itemHeight?: number;
23
+ viewportHeight?: number;
24
+ buffer?: number;
21
25
  };
22
26
  declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
23
27
  "update:selectedRows": (value: any[]) => any;
@@ -11,6 +11,10 @@
11
11
  :columnWidths="columnWidths"
12
12
  :selectedRows="selectedRows"
13
13
  :selectAll="selectAll"
14
+ :virtualScroll="virtualScroll"
15
+ :itemHeight="itemHeight"
16
+ :viewportHeight="viewportHeight"
17
+ :buffer="buffer"
14
18
  @update:selectedRows="$emit('update:selectedRows', $event)"
15
19
  @update:selectAll="$emit('update:selectAll', $event)"
16
20
  )
@@ -50,6 +54,10 @@ const props = defineProps<{
50
54
  headerSlots?: Record<string, any>
51
55
  columnHeaders?: Record<string, string>
52
56
  columnWidths?: Record<string, string>
57
+ virtualScroll?: boolean
58
+ itemHeight?: number
59
+ viewportHeight?: number
60
+ buffer?: number
53
61
  }>()
54
62
 
55
63
  const emit = defineEmits<{
@@ -18,6 +18,10 @@ type __VLS_Props = {
18
18
  headerSlots?: Record<string, any>;
19
19
  columnHeaders?: Record<string, string>;
20
20
  columnWidths?: Record<string, string>;
21
+ virtualScroll?: boolean;
22
+ itemHeight?: number;
23
+ viewportHeight?: number;
24
+ buffer?: number;
21
25
  };
22
26
  declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
23
27
  "update:selectedRows": (value: any[]) => any;
@@ -27,7 +27,7 @@ export default defineEventHandler((event) => {
27
27
  path: "/",
28
28
  maxAge: 365 * 24 * 60 * 60,
29
29
  sameSite: "lax",
30
- httpOnly: false
30
+ httpOnly: true
31
31
  });
32
32
  } catch {
33
33
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@katlux/toolkit",
3
- "version": "0.1.1-alpha.117",
3
+ "version": "0.1.1-alpha.119",
4
4
  "description": "Core UI toolkit and utilities for the Katlux ecosystem",
5
5
  "author": "Katlux",
6
6
  "license": "Apache-2.0",
@@ -9,14 +9,13 @@
9
9
  },
10
10
  "main": "./dist/module.mjs",
11
11
  "bin": {
12
- "@katlux/toolkit": "./bin/cli.mjs",
13
12
  "katlux": "./bin/cli.mjs",
14
13
  "katlux-toolkit": "./bin/cli.mjs",
15
14
  "create-preset": "./bin/create-preset.mjs",
16
15
  "katlux-add-ref": "./bin/add-ai-reference.mjs"
17
16
  },
18
17
  "scripts": {
19
- "build": "nuxt-module-build build && unbuild && mkdir -p dist/runtime && cp -r src/runtime/presets dist/runtime/",
18
+ "build": "nuxt-module-build build && unbuild && node -e \"const fs=require('fs'); fs.mkdirSync('dist/runtime', {recursive:true}); fs.cpSync('src/runtime/presets', 'dist/runtime/presets', {recursive:true}); const clean=(d)=>{if(!fs.existsSync(d))return;for(const f of fs.readdirSync(d,{withFileTypes:true})){const p=d+'/'+f.name;if(f.isDirectory())clean(p);else if(f.name.includes('.spec.'))fs.unlinkSync(p);}};clean('dist');\"",
20
19
  "dev": "nuxt-module-build build --stub",
21
20
  "prepare": "nuxi prepare",
22
21
  "prepublishOnly": "npm run build"
@@ -42,7 +41,7 @@
42
41
  "./dist/runtime/presets/*": "./dist/runtime/presets/*"
43
42
  },
44
43
  "dependencies": {
45
- "@katlux/providers": "^0.1.1-alpha.100",
44
+ "@katlux/providers": "^0.1.1-alpha.105",
46
45
  "@nuxt/kit": "^3.12.0",
47
46
  "@nuxtjs/i18n": "^10.4.0",
48
47
  "pug": "^3.0.0",
@@ -1,157 +0,0 @@
1
- import { describe, it, expect } from "vitest";
2
- import { effectScope, ref, nextTick } from "vue";
3
- import { CFlatClientDataProvider, EDataFilterOperator } from "@katlux/providers";
4
- import { useDataProvider } from "./useDataProvider.mjs";
5
- describe("useDataProvider Composable Adapter", () => {
6
- it("should sync state from standalone CFlatClientDataProvider", () => {
7
- const scope = effectScope();
8
- scope.run(() => {
9
- const provider = new CFlatClientDataProvider({ pageSize: 5 });
10
- provider.setData([
11
- { id: 1, name: "Alice" },
12
- { id: 2, name: "Bob" },
13
- { id: 3, name: "Charlie" },
14
- { id: 4, name: "Dave" },
15
- { id: 5, name: "Eve" },
16
- { id: 6, name: "Frank" }
17
- ]);
18
- const { pageData, rowCount, currentPage, pageSize, loading } = useDataProvider(provider);
19
- expect(rowCount.value).toBe(6);
20
- expect(currentPage.value).toBe(1);
21
- expect(pageSize.value).toBe(5);
22
- expect(pageData.value.length).toBe(5);
23
- expect(pageData.value[0].name).toBe("Alice");
24
- expect(loading.value).toBe(false);
25
- });
26
- scope.stop();
27
- });
28
- it("should reactively update when provider data changes", () => {
29
- const scope = effectScope();
30
- scope.run(() => {
31
- const provider = new CFlatClientDataProvider({ pageSize: 10 });
32
- const { pageData, rowCount } = useDataProvider(provider);
33
- expect(pageData.value.length).toBe(0);
34
- expect(rowCount.value).toBe(0);
35
- provider.setData([
36
- { id: 10, title: "Item 1" },
37
- { id: 20, title: "Item 2" }
38
- ]);
39
- expect(pageData.value.length).toBe(2);
40
- expect(rowCount.value).toBe(2);
41
- expect(pageData.value[1].title).toBe("Item 2");
42
- });
43
- scope.stop();
44
- });
45
- it("should support pagination and filtering via composable methods", () => {
46
- const scope = effectScope();
47
- scope.run(() => {
48
- const provider = new CFlatClientDataProvider({ pageSize: 2 });
49
- provider.setData([
50
- { id: 1, tag: "dev" },
51
- { id: 2, tag: "qa" },
52
- { id: 3, tag: "dev" },
53
- { id: 4, tag: "prod" }
54
- ]);
55
- const { pageData, currentPage, setCurrentPage, setFilter, loadPageData } = useDataProvider(provider);
56
- expect(pageData.value.length).toBe(2);
57
- expect(pageData.value[0].id).toBe(1);
58
- setCurrentPage(2);
59
- expect(currentPage.value).toBe(2);
60
- expect(pageData.value[0].id).toBe(3);
61
- setFilter({
62
- operator: EDataFilterOperator.Equal,
63
- field: { tag: "dev" },
64
- active: true
65
- });
66
- setCurrentPage(1);
67
- expect(pageData.value.length).toBe(2);
68
- expect(pageData.value.map((i) => i.id)).toEqual([1, 3]);
69
- });
70
- scope.stop();
71
- });
72
- it("should clean up subscription on scope disposal", () => {
73
- let provider;
74
- let pageDataRef;
75
- const scope = effectScope();
76
- scope.run(() => {
77
- provider = new CFlatClientDataProvider();
78
- const { pageData } = useDataProvider(provider);
79
- pageDataRef = pageData;
80
- provider.setData([{ id: 1 }]);
81
- expect(pageDataRef.value.length).toBe(1);
82
- });
83
- scope.stop();
84
- provider.setData([{ id: 1 }, { id: 2 }]);
85
- });
86
- it("should reactively switch providers when passed a getter function", async () => {
87
- const providerA = new CFlatClientDataProvider();
88
- providerA.setData([{ id: 1, title: "Old 1" }, { id: 2, title: "Old 2" }]);
89
- const providerB = new CFlatClientDataProvider();
90
- providerB.setData([{ id: 10, title: "New 1" }, { id: 20, title: "New 2" }, { id: 30, title: "New 3" }]);
91
- const active = ref(providerA);
92
- const scope = effectScope();
93
- await scope.run(async () => {
94
- const { pageData, rowCount } = useDataProvider(() => active.value);
95
- expect(pageData.value.length).toBe(2);
96
- expect(rowCount.value).toBe(2);
97
- active.value = providerB;
98
- await nextTick();
99
- expect(pageData.value.length).toBe(3);
100
- expect(rowCount.value).toBe(3);
101
- expect(pageData.value[0].id).toBe(10);
102
- });
103
- scope.stop();
104
- });
105
- it("should support two-way binding with external reactive refs (Pinia-ready pattern)", async () => {
106
- const provider = new CFlatClientDataProvider({ pageSize: 2 });
107
- provider.setData([
108
- { id: 1, name: "Item 1" },
109
- { id: 2, name: "Item 2" },
110
- { id: 3, name: "Item 3" },
111
- { id: 4, name: "Item 4" }
112
- ]);
113
- const externalPage = ref(1);
114
- const externalPageSize = ref(2);
115
- const externalSelected = ref([]);
116
- const scope = effectScope();
117
- await scope.run(async () => {
118
- const { pageData, currentPage, pageSize } = useDataProvider(provider, {
119
- currentPage: externalPage,
120
- pageSize: externalPageSize,
121
- selectedRows: externalSelected
122
- });
123
- expect(currentPage.value).toBe(1);
124
- expect(pageData.value[0].id).toBe(1);
125
- externalPage.value = 2;
126
- await nextTick();
127
- expect(provider.currentPage).toBe(2);
128
- expect(pageData.value[0].id).toBe(3);
129
- provider.setCurrentPage(1);
130
- await nextTick();
131
- expect(externalPage.value).toBe(1);
132
- expect(pageData.value[0].id).toBe(1);
133
- externalSelected.value = [{ id: 1, name: "Item 1" }];
134
- await nextTick();
135
- expect(provider.selectedRows).toEqual([{ id: 1, name: "Item 1" }]);
136
- externalPageSize.value = 4;
137
- await nextTick();
138
- expect(provider.pageSize).toBe(4);
139
- expect(pageData.value.length).toBe(4);
140
- });
141
- scope.stop();
142
- });
143
- it("should expose getState() and setState() helpers", () => {
144
- const provider = new CFlatClientDataProvider({ pageSize: 5 });
145
- provider.setData([{ id: 10 }, { id: 20 }, { id: 30 }]);
146
- const scope = effectScope();
147
- scope.run(() => {
148
- const { getState, setState, currentPage, pageSize } = useDataProvider(provider);
149
- expect(getState().rowCount).toBe(3);
150
- expect(getState().currentPage).toBe(1);
151
- setState({ currentPage: 2, pageSize: 2 });
152
- expect(currentPage.value).toBe(2);
153
- expect(pageSize.value).toBe(2);
154
- });
155
- scope.stop();
156
- });
157
- });
@@ -1,63 +0,0 @@
1
- import { describe, it, expect, beforeEach, afterEach, vi } from "vitest";
2
- import { useKatluxContext } from "./useKatluxContext.mjs";
3
- describe("useKatluxContext Composable", () => {
4
- const originalWindow = globalThis.window;
5
- const originalKatluxApp = globalThis.__KATLUX_APP__;
6
- const originalUseRequestEvent = globalThis.useRequestEvent;
7
- beforeEach(() => {
8
- vi.restoreAllMocks();
9
- delete globalThis.__KATLUX_APP__;
10
- delete globalThis.useRequestEvent;
11
- });
12
- afterEach(() => {
13
- if (originalKatluxApp !== void 0) {
14
- ;
15
- globalThis.__KATLUX_APP__ = originalKatluxApp;
16
- } else {
17
- delete globalThis.__KATLUX_APP__;
18
- }
19
- if (originalUseRequestEvent !== void 0) {
20
- ;
21
- globalThis.useRequestEvent = originalUseRequestEvent;
22
- } else {
23
- delete globalThis.useRequestEvent;
24
- }
25
- if (originalWindow !== void 0) {
26
- ;
27
- globalThis.window = originalWindow;
28
- }
29
- });
30
- it("returns null on client environment", () => {
31
- const clientContext = useKatluxContext();
32
- expect(clientContext).toBeNull();
33
- });
34
- it("returns { event } on server via useRequestEvent", () => {
35
- const mockEvent = { req: { url: "/test" }, context: {} };
36
- globalThis.useRequestEvent = () => mockEvent;
37
- const win = globalThis.window;
38
- delete globalThis.window;
39
- try {
40
- const ctx = useKatluxContext();
41
- expect(ctx).toEqual({ event: mockEvent });
42
- } finally {
43
- ;
44
- globalThis.window = win;
45
- }
46
- });
47
- it("returns { event } on server via __KATLUX_APP__.ssrContext.event", () => {
48
- delete globalThis.useRequestEvent;
49
- const mockSsrEvent = { id: "ssr-event-999" };
50
- globalThis.__KATLUX_APP__ = {
51
- ssrContext: { event: mockSsrEvent }
52
- };
53
- const win = globalThis.window;
54
- delete globalThis.window;
55
- try {
56
- const ctx = useKatluxContext();
57
- expect(ctx).toEqual({ event: mockSsrEvent });
58
- } finally {
59
- ;
60
- globalThis.window = win;
61
- }
62
- });
63
- });
@@ -1,10 +0,0 @@
1
- import { describe, it, expect } from "vitest";
2
- import { defaultKatluxTranslations } from "./useKatluxI18n.mjs";
3
- describe("useKatluxI18n defaults", () => {
4
- it("has required fallback keys defined in defaultKatluxTranslations", () => {
5
- expect(defaultKatluxTranslations["Dismiss"]).toBe("Dismiss");
6
- expect(defaultKatluxTranslations["No result"]).toBe("No result");
7
- expect(defaultKatluxTranslations["Select an action"]).toBe("Select an action");
8
- expect(defaultKatluxTranslations["Selected {count} items"]).toBe("Selected {count} items");
9
- });
10
- });
@@ -1,106 +0,0 @@
1
- import { describe, it, expect, beforeEach, vi } from "vitest";
2
- import { defineComponent, h } from "vue";
3
- import * as appMock from "#app";
4
- import {
5
- usePresetComponent,
6
- registerPresetComponents,
7
- clearPresetComponentCache
8
- } from "./usePresetComponent.mjs";
9
- describe("usePresetComponent", () => {
10
- const DefaultButton = defineComponent({
11
- name: "DefaultButton",
12
- render() {
13
- return h("button", "default");
14
- }
15
- });
16
- const CustomSyncButton = defineComponent({
17
- name: "CustomSyncButton",
18
- render() {
19
- return h("button", "custom-sync");
20
- }
21
- });
22
- const CustomAsyncButton = defineComponent({
23
- name: "CustomAsyncButton",
24
- render() {
25
- return h("button", "custom-async");
26
- }
27
- });
28
- beforeEach(() => {
29
- clearPresetComponentCache();
30
- vi.restoreAllMocks();
31
- });
32
- it("returns defaultComponent immediately when activePreset is default", () => {
33
- vi.spyOn(appMock, "useAppConfig").mockReturnValue({
34
- katluxToolkit: {
35
- activePreset: ["default"]
36
- }
37
- });
38
- const comp = usePresetComponent("KButton", DefaultButton);
39
- expect(comp.value).toBe(DefaultButton);
40
- });
41
- it("returns defaultComponent when activePreset is empty or undefined", () => {
42
- vi.spyOn(appMock, "useAppConfig").mockReturnValue({
43
- katluxToolkit: {
44
- activePreset: []
45
- }
46
- });
47
- const comp = usePresetComponent("KButton", DefaultButton);
48
- expect(comp.value).toBe(DefaultButton);
49
- });
50
- it("resolves synchronous preset component directly without defineAsyncComponent wrapper", () => {
51
- vi.spyOn(appMock, "useAppConfig").mockReturnValue({
52
- katluxToolkit: {
53
- activePreset: ["tenantAcme", "default"]
54
- }
55
- });
56
- registerPresetComponents("tenantAcme", {
57
- "./components/KButton/KButton.vue": CustomSyncButton
58
- });
59
- const comp = usePresetComponent("KButton", DefaultButton);
60
- expect(comp.value).toBe(CustomSyncButton);
61
- });
62
- it("resolves async loader preset component and caches the wrapper instance", () => {
63
- vi.spyOn(appMock, "useAppConfig").mockReturnValue({
64
- katluxToolkit: {
65
- activePreset: ["tenantAsync", "default"]
66
- }
67
- });
68
- const loader = vi.fn().mockResolvedValue({ default: CustomAsyncButton });
69
- registerPresetComponents("tenantAsync", {
70
- "./components/KButton/KButton.vue": loader
71
- });
72
- const comp1 = usePresetComponent("KButton", DefaultButton);
73
- const comp2 = usePresetComponent("KButton", DefaultButton);
74
- expect(comp1.value).toBeDefined();
75
- expect(comp1.value).toBe(comp2.value);
76
- });
77
- it("resolves according to preset cascade order", () => {
78
- vi.spyOn(appMock, "useAppConfig").mockReturnValue({
79
- katluxToolkit: {
80
- activePreset: ["tenantCustom", "modern", "default"]
81
- }
82
- });
83
- const ModernButton = defineComponent({
84
- name: "ModernButton",
85
- render: () => h("button", "modern")
86
- });
87
- registerPresetComponents("tenantCustom", {});
88
- registerPresetComponents("modern", {
89
- "./components/KButton/KButton.vue": ModernButton
90
- });
91
- const comp = usePresetComponent("KButton", DefaultButton);
92
- expect(comp.value).toBe(ModernButton);
93
- });
94
- it("falls back to defaultComponent if no active preset provides the component", () => {
95
- vi.spyOn(appMock, "useAppConfig").mockReturnValue({
96
- katluxToolkit: {
97
- activePreset: ["customTheme", "default"]
98
- }
99
- });
100
- registerPresetComponents("customTheme", {
101
- "./components/KOther/KOther.vue": CustomSyncButton
102
- });
103
- const comp = usePresetComponent("KButton", DefaultButton);
104
- expect(comp.value).toBe(DefaultButton);
105
- });
106
- });