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

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 (130) hide show
  1. package/bin/cli.mjs +72 -0
  2. package/bin/create-preset.mjs +233 -0
  3. package/dist/compiled/composables/useDataProvider.mjs +176 -21
  4. package/dist/compiled/composables/useDataProvider.spec.mjs +52 -0
  5. package/dist/module.json +1 -1
  6. package/dist/runtime/components/KAccordion/KAccordion.global.d.vue.ts +23 -2
  7. package/dist/runtime/components/KAccordion/KAccordion.global.vue +7 -1
  8. package/dist/runtime/components/KAccordion/KAccordion.global.vue.d.ts +23 -2
  9. package/dist/runtime/components/KAccordion/KAccordion.logic.d.ts +12 -1
  10. package/dist/runtime/components/KAccordion/KAccordion.logic.js +32 -4
  11. package/dist/runtime/components/KAlert/KAlert.global.d.vue.ts +4 -1
  12. package/dist/runtime/components/KAlert/KAlert.global.vue +8 -2
  13. package/dist/runtime/components/KAlert/KAlert.global.vue.d.ts +4 -1
  14. package/dist/runtime/components/KAlert/KAlert.logic.d.ts +6 -1
  15. package/dist/runtime/components/KAlert/KAlert.logic.js +12 -2
  16. package/dist/runtime/components/KButton/KButton.global.d.vue.ts +1 -1
  17. package/dist/runtime/components/KButton/KButton.global.vue.d.ts +1 -1
  18. package/dist/runtime/components/KButton/KButton.logic.d.ts +1 -1
  19. package/dist/runtime/components/KCalendar/KCalendar.global.d.vue.ts +11 -0
  20. package/dist/runtime/components/KCalendar/KCalendar.global.vue +1 -1
  21. package/dist/runtime/components/KCalendar/KCalendar.global.vue.d.ts +11 -0
  22. package/dist/runtime/components/KCalendar/KCalendar.logic.d.ts +6 -0
  23. package/dist/runtime/components/KCalendar/KCalendar.logic.js +13 -4
  24. package/dist/runtime/components/KCheckbox/KCheckbox.global.d.vue.ts +1 -1
  25. package/dist/runtime/components/KCheckbox/KCheckbox.global.vue.d.ts +1 -1
  26. package/dist/runtime/components/KCombobox/KCombobox.global.d.vue.ts +40 -5
  27. package/dist/runtime/components/KCombobox/KCombobox.global.vue +11 -2
  28. package/dist/runtime/components/KCombobox/KCombobox.global.vue.d.ts +40 -5
  29. package/dist/runtime/components/KCombobox/KCombobox.logic.d.ts +18 -0
  30. package/dist/runtime/components/KCombobox/KCombobox.logic.js +24 -2
  31. package/dist/runtime/components/KCompositeInput/KCompositeInput.global.d.vue.ts +12 -12
  32. package/dist/runtime/components/KCompositeInput/KCompositeInput.global.vue.d.ts +12 -12
  33. package/dist/runtime/components/KCompositeInput/KCompositeInput.logic.d.ts +3 -3
  34. package/dist/runtime/components/KContextMenu/KContextMenu.global.d.vue.ts +1 -1
  35. package/dist/runtime/components/KContextMenu/KContextMenu.global.vue.d.ts +1 -1
  36. package/dist/runtime/components/KDatatable/KDataIterator.global.d.vue.ts +30 -2
  37. package/dist/runtime/components/KDatatable/KDataIterator.global.vue +29 -4
  38. package/dist/runtime/components/KDatatable/KDataIterator.global.vue.d.ts +30 -2
  39. package/dist/runtime/components/KDatatable/KDataIterator.logic.d.ts +21 -2
  40. package/dist/runtime/components/KDatatable/KDataIterator.logic.js +66 -31
  41. package/dist/runtime/components/KDatatable/KDatatable.global.d.vue.ts +35 -3
  42. package/dist/runtime/components/KDatatable/KDatatable.global.vue +44 -4
  43. package/dist/runtime/components/KDatatable/KDatatable.global.vue.d.ts +35 -3
  44. package/dist/runtime/components/KDatatable/KDatatable.logic.d.ts +27 -2
  45. package/dist/runtime/components/KDatatable/KDatatable.logic.js +77 -5
  46. package/dist/runtime/components/KDatePicker/KDatePicker.global.d.vue.ts +8 -8
  47. package/dist/runtime/components/KDatePicker/KDatePicker.global.vue.d.ts +8 -8
  48. package/dist/runtime/components/KDatePicker/KDatePicker.logic.d.ts +2 -2
  49. package/dist/runtime/components/KDateTimePicker/KDateTimePicker.global.d.vue.ts +8 -8
  50. package/dist/runtime/components/KDateTimePicker/KDateTimePicker.global.vue.d.ts +8 -8
  51. package/dist/runtime/components/KDateTimePicker/KDateTimePicker.logic.d.ts +2 -2
  52. package/dist/runtime/components/KDropdown/KDropdown.global.d.vue.ts +2 -2
  53. package/dist/runtime/components/KDropdown/KDropdown.global.vue.d.ts +2 -2
  54. package/dist/runtime/components/KGantt/KGantt.global.d.vue.ts +8 -8
  55. package/dist/runtime/components/KGantt/KGantt.global.vue.d.ts +8 -8
  56. package/dist/runtime/components/KGantt/KGantt.logic.d.ts +4 -4
  57. package/dist/runtime/components/KHourPicker/KHourPicker.global.d.vue.ts +1 -1
  58. package/dist/runtime/components/KHourPicker/KHourPicker.global.vue.d.ts +1 -1
  59. package/dist/runtime/components/KHourSelect/KHourSelect.global.d.vue.ts +1 -1
  60. package/dist/runtime/components/KHourSelect/KHourSelect.global.vue.d.ts +1 -1
  61. package/dist/runtime/components/KMaskTextbox/KMaskTextbox.global.d.vue.ts +1 -1
  62. package/dist/runtime/components/KMaskTextbox/KMaskTextbox.global.vue.d.ts +1 -1
  63. package/dist/runtime/components/KPagination/KPagination.global.d.vue.ts +24 -2
  64. package/dist/runtime/components/KPagination/KPagination.global.vue +8 -2
  65. package/dist/runtime/components/KPagination/KPagination.global.vue.d.ts +24 -2
  66. package/dist/runtime/components/KPagination/KPagination.logic.d.ts +18 -4
  67. package/dist/runtime/components/KPagination/KPagination.logic.js +59 -10
  68. package/dist/runtime/components/KRangeSlider/KRangeSlider.global.d.vue.ts +15 -4
  69. package/dist/runtime/components/KRangeSlider/KRangeSlider.global.vue +22 -4
  70. package/dist/runtime/components/KRangeSlider/KRangeSlider.global.vue.d.ts +15 -4
  71. package/dist/runtime/components/KRangeSlider/KRangeSlider.logic.d.ts +6 -0
  72. package/dist/runtime/components/KRangeSlider/KRangeSlider.logic.js +12 -6
  73. package/dist/runtime/components/KSlider/KSlider.global.d.vue.ts +14 -3
  74. package/dist/runtime/components/KSlider/KSlider.global.vue +9 -3
  75. package/dist/runtime/components/KSlider/KSlider.global.vue.d.ts +14 -3
  76. package/dist/runtime/components/KSlider/KSlider.logic.d.ts +5 -0
  77. package/dist/runtime/components/KSlider/KSlider.logic.js +5 -1
  78. package/dist/runtime/components/KTabs/KTabItem.global.d.vue.ts +18 -0
  79. package/dist/runtime/components/KTabs/KTabItem.global.vue.d.ts +18 -0
  80. package/dist/runtime/components/KTabs/KTabItem.logic.d.ts +11 -0
  81. package/dist/runtime/components/KTabs/KTabItem.logic.js +10 -1
  82. package/dist/runtime/components/KTabs/KTabs.global.d.vue.ts +35 -1
  83. package/dist/runtime/components/KTabs/KTabs.global.vue +13 -2
  84. package/dist/runtime/components/KTabs/KTabs.global.vue.d.ts +35 -1
  85. package/dist/runtime/components/KTabs/KTabs.logic.d.ts +22 -2
  86. package/dist/runtime/components/KTabs/KTabs.logic.js +118 -4
  87. package/dist/runtime/components/KTextarea/KTextarea.global.d.vue.ts +1 -1
  88. package/dist/runtime/components/KTextarea/KTextarea.global.vue.d.ts +1 -1
  89. package/dist/runtime/components/KTextbox/KTextbox.global.d.vue.ts +2 -2
  90. package/dist/runtime/components/KTextbox/KTextbox.global.vue.d.ts +2 -2
  91. package/dist/runtime/components/KToast/KToast.global.d.vue.ts +3 -3
  92. package/dist/runtime/components/KToast/KToast.global.vue.d.ts +3 -3
  93. package/dist/runtime/components/KTree/KTree.global.d.vue.ts +50 -4
  94. package/dist/runtime/components/KTree/KTree.global.vue +13 -2
  95. package/dist/runtime/components/KTree/KTree.global.vue.d.ts +50 -4
  96. package/dist/runtime/components/KTree/KTree.logic.d.ts +26 -2
  97. package/dist/runtime/components/KTree/KTree.logic.js +41 -6
  98. package/dist/runtime/components/KTreePicker/KTreePicker.global.d.vue.ts +30 -8
  99. package/dist/runtime/components/KTreePicker/KTreePicker.global.vue +1 -1
  100. package/dist/runtime/components/KTreePicker/KTreePicker.global.vue.d.ts +30 -8
  101. package/dist/runtime/components/KTreePicker/KTreePicker.logic.d.ts +16 -0
  102. package/dist/runtime/components/KTreePicker/KTreePicker.logic.js +8 -0
  103. package/dist/runtime/components/KTreeView/KTreeView.global.d.vue.ts +7 -3
  104. package/dist/runtime/components/KTreeView/KTreeView.global.vue +5 -2
  105. package/dist/runtime/components/KTreeView/KTreeView.global.vue.d.ts +7 -3
  106. package/dist/runtime/components/KTreeView/KTreeView.logic.d.ts +4 -1
  107. package/dist/runtime/components/KTreeView/KTreeView.logic.js +7 -1
  108. package/dist/runtime/composables/useDataProvider.d.ts +15 -4
  109. package/dist/runtime/composables/useDataProvider.js +176 -21
  110. package/dist/runtime/presets/default/assets/scss/css-variables.css +1 -0
  111. package/dist/runtime/presets/default/assets/scss/css-variables.scss +1 -0
  112. package/dist/runtime/presets/default/assets/scss/index.css +5 -3
  113. package/dist/runtime/presets/default/assets/scss/index.scss +4 -3
  114. package/dist/runtime/presets/default/components/KAlert/KAlert.d.vue.ts +3 -1
  115. package/dist/runtime/presets/default/components/KAlert/KAlert.vue +3 -3
  116. package/dist/runtime/presets/default/components/KAlert/KAlert.vue.d.ts +3 -1
  117. package/dist/runtime/presets/default/components/KContextMenu/KContextMenu.vue +86 -4
  118. package/dist/runtime/presets/default/components/KDatatable/KDatatable.d.vue.ts +6 -0
  119. package/dist/runtime/presets/default/components/KDatatable/KDatatable.vue +5 -1
  120. package/dist/runtime/presets/default/components/KDatatable/KDatatable.vue.d.ts +6 -0
  121. package/dist/runtime/presets/default/components/KRangeSlider/KRangeSlider.vue +9 -0
  122. package/dist/runtime/presets/default/components/KSlider/KSlider.vue +9 -0
  123. package/dist/runtime/presets/default/components/KTabs/KTabs.d.vue.ts +1 -0
  124. package/dist/runtime/presets/default/components/KTabs/KTabs.vue +23 -0
  125. package/dist/runtime/presets/default/components/KTabs/KTabs.vue.d.ts +1 -0
  126. package/dist/runtime/presets/default/components/KToast/KToast.d.vue.ts +2 -2
  127. package/dist/runtime/presets/default/components/KToast/KToast.vue.d.ts +2 -2
  128. package/dist/runtime/presets/default/components/KTree/KTree.d.vue.ts +1 -1
  129. package/dist/runtime/presets/default/components/KTree/KTree.vue.d.ts +1 -1
  130. package/package.json +5 -1
package/bin/cli.mjs ADDED
@@ -0,0 +1,72 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * @katlux/toolkit CLI Dispatcher
4
+ *
5
+ * Supported commands:
6
+ * npx @katlux/toolkit create-preset <preset-name> [--base=<base>]
7
+ * npx @katlux/toolkit katlux-add-ref
8
+ */
9
+
10
+ import { spawn } from 'child_process'
11
+ import { resolve, dirname } from 'path'
12
+ import { fileURLToPath } from 'url'
13
+
14
+ const __dirname = dirname(fileURLToPath(import.meta.url))
15
+
16
+ const RESET = '\x1b[0m'
17
+ const CYAN = '\x1b[36m'
18
+ const BOLD = '\x1b[1m'
19
+ const RED = '\x1b[31m'
20
+
21
+ const args = process.argv.slice(2)
22
+ const command = args[0]
23
+
24
+ function printHelp() {
25
+ console.log(`
26
+ ${BOLD}Katlux Toolkit CLI${RESET}
27
+
28
+ ${BOLD}Usage:${RESET}
29
+ npx @katlux/toolkit <command> [options]
30
+
31
+ ${BOLD}Commands:${RESET}
32
+ ${CYAN}create-preset <name> [--base=<base>]${RESET}
33
+ Scaffold a new custom preset (e.g. "cyber-brand --base=modern").
34
+ Any preset can be token-only. Base presets leverage cascading inheritance without copying files.
35
+
36
+ ${CYAN}katlux-add-ref${RESET}
37
+ Download or update the Katlux AI Reference Guide at .agents/skills/KATLUX_AI_REFERENCE.md.
38
+
39
+ ${BOLD}Examples:${RESET}
40
+ npx @katlux/toolkit create-preset cyber-brand --base=modern
41
+ npx @katlux/toolkit create-preset my-theme
42
+ npx @katlux/toolkit katlux-add-ref
43
+ `)
44
+ }
45
+
46
+ if (!command || command === '--help' || command === '-h' || command === 'help') {
47
+ printHelp()
48
+ process.exit(0)
49
+ }
50
+
51
+ let scriptPath = null
52
+ let forwardedArgs = []
53
+
54
+ if (command === 'create-preset') {
55
+ scriptPath = resolve(__dirname, 'create-preset.mjs')
56
+ forwardedArgs = args.slice(1)
57
+ } else if (command === 'katlux-add-ref' || command === 'add-ref') {
58
+ scriptPath = resolve(__dirname, 'add-ai-reference.mjs')
59
+ forwardedArgs = args.slice(1)
60
+ } else {
61
+ console.log(`${RED}${BOLD}[katlux] ✖${RESET} Unknown command: "${command}"`)
62
+ printHelp()
63
+ process.exit(1)
64
+ }
65
+
66
+ const child = spawn(process.execPath, [scriptPath, ...forwardedArgs], {
67
+ stdio: 'inherit',
68
+ })
69
+
70
+ child.on('exit', (code) => {
71
+ process.exit(code ?? 0)
72
+ })
@@ -0,0 +1,233 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * create-preset
4
+ * Scaffolds a new Katlux preset in the consumer's Nuxt project.
5
+ *
6
+ * Usage:
7
+ * npx @katlux/toolkit create-preset <preset-name> [--base=<base-preset>]
8
+ *
9
+ * Example:
10
+ * npx @katlux/toolkit create-preset cyber-brand --base=modern
11
+ */
12
+
13
+ import { existsSync, mkdirSync, writeFileSync } from 'fs'
14
+ import { resolve, join, relative } from 'path'
15
+
16
+ const RESET = '\x1b[0m'
17
+ const GREEN = '\x1b[32m'
18
+ const CYAN = '\x1b[36m'
19
+ const YELLOW = '\x1b[33m'
20
+ const RED = '\x1b[31m'
21
+ const BOLD = '\x1b[1m'
22
+ const DIM = '\x1b[2m'
23
+
24
+ function log(color, prefix, message) {
25
+ console.log(`${color}${BOLD}${prefix}${RESET} ${message}`)
26
+ }
27
+
28
+ function toTitleCase(str) {
29
+ return str
30
+ .split('-')
31
+ .map(word => word.charAt(0).toUpperCase() + word.slice(1))
32
+ .join(' ')
33
+ }
34
+
35
+ /**
36
+ * Core preset scaffolding logic
37
+ */
38
+ export function createPreset({ name, base = null, cwd = process.cwd() }) {
39
+ if (!name || typeof name !== 'string') {
40
+ throw new Error('Preset name is required.')
41
+ }
42
+
43
+ const trimmedName = name.trim().toLowerCase()
44
+ if (!/^[a-z0-9]+(-[a-z0-9]+)*$/.test(trimmedName)) {
45
+ throw new Error(
46
+ `Invalid preset name "${name}". Preset name must be kebab-case (e.g. "cyber-brand", "my-theme").`
47
+ )
48
+ }
49
+
50
+ // Detect if project uses Nuxt 4 / custom srcDir pattern (e.g. "app/" directory)
51
+ const hasAppDir = existsSync(resolve(cwd, 'app'))
52
+ const baseDir = hasAppDir ? resolve(cwd, 'app', 'presets') : resolve(cwd, 'presets')
53
+ const targetDir = resolve(baseDir, trimmedName)
54
+ const assetsDir = resolve(targetDir, 'assets')
55
+ const cssVarsFile = resolve(assetsDir, 'css-variables.scss')
56
+
57
+ if (existsSync(targetDir)) {
58
+ throw new Error(
59
+ `Directory already exists at ${targetDir}. Please choose a different preset name or remove the existing directory.`
60
+ )
61
+ }
62
+
63
+ // Create directory structure: assets/
64
+ mkdirSync(assetsDir, { recursive: true })
65
+
66
+ // Starter CSS variables template
67
+ // NOTE: Any preset can be token-only. Never copy files from base preset because Katlux resolution cascades!
68
+ const scssContent = `// Katlux Preset: ${trimmedName}
69
+ // In Katlux, any preset can be token-only.
70
+ // When based on another preset, tokens & components cascade automatically via app.config.ts.
71
+ // Do not copy files from the base preset.
72
+
73
+ [data-preset~="${trimmedName}"] {
74
+ // Brand & Primary Palette
75
+ // --primary-500: #6366f1;
76
+ // --primary-600: #4f46e5;
77
+
78
+ // Backgrounds & Surfaces
79
+ // --background-color: #0f172a;
80
+ // --background-color-card: #1e293b;
81
+
82
+ // Typography & Font Colors
83
+ // --font-color-primary: #f8fafc;
84
+ // --font-color-secondary: #94a3b8;
85
+
86
+ // Radii & Layout Spacing
87
+ // --border-radius-md: 8px;
88
+ // --gap-md: 1rem;
89
+ }
90
+ `
91
+
92
+ writeFileSync(cssVarsFile, scssContent, 'utf-8')
93
+
94
+ return {
95
+ presetName: trimmedName,
96
+ basePreset: base ? base.trim().toLowerCase() : null,
97
+ targetDir,
98
+ cssVarsFile,
99
+ hasAppDir,
100
+ }
101
+ }
102
+
103
+ // ── CLI Execution ─────────────────────────────────────────────────────────────
104
+
105
+ function runCli() {
106
+ const args = process.argv.slice(2)
107
+
108
+ if (args.includes('--help') || args.includes('-h') || args.length === 0) {
109
+ console.log(`
110
+ ${BOLD}Katlux Preset Scaffolding Tool${RESET}
111
+
112
+ ${BOLD}Usage:${RESET}
113
+ npx @katlux/toolkit create-preset <preset-name> [--base=<base-preset>]
114
+
115
+ ${BOLD}Arguments:${RESET}
116
+ <preset-name> Name of your new preset in kebab-case (e.g. "cyber-brand")
117
+
118
+ ${BOLD}Options:${RESET}
119
+ --base=<base-preset> Base preset to inherit from (e.g. "--base=modern").
120
+ No files are copied; multi-preset cascading inheritance is used.
121
+ -h, --help Show this help message
122
+
123
+ ${BOLD}Examples:${RESET}
124
+ npx @katlux/toolkit create-preset cyber-brand --base=modern
125
+ npx @katlux/toolkit create-preset my-theme
126
+ `)
127
+ if (args.length === 0) {
128
+ process.exit(1)
129
+ }
130
+ process.exit(0)
131
+ }
132
+
133
+ let presetName = null
134
+ let basePreset = null
135
+
136
+ for (const arg of args) {
137
+ if (arg.startsWith('--base=')) {
138
+ basePreset = arg.slice('--base='.length)
139
+ } else if (arg === '-b' || arg === '--base') {
140
+ const idx = args.indexOf(arg)
141
+ if (idx !== -1 && args[idx + 1]) {
142
+ basePreset = args[idx + 1]
143
+ }
144
+ } else if (!arg.startsWith('-') && !presetName) {
145
+ presetName = arg
146
+ }
147
+ }
148
+
149
+ if (!presetName) {
150
+ log(RED, '[create-preset] ✖', 'Preset name is required.')
151
+ console.log('Run with --help for usage instructions.')
152
+ process.exit(1)
153
+ }
154
+
155
+ try {
156
+ console.log()
157
+ log(CYAN, '[create-preset]', `Scaffolding preset "${presetName}"...`)
158
+
159
+ const result = createPreset({
160
+ name: presetName,
161
+ base: basePreset,
162
+ cwd: process.cwd(),
163
+ })
164
+
165
+ const relTarget = relative(process.cwd(), result.targetDir)
166
+ const relFile = relative(process.cwd(), result.cssVarsFile)
167
+
168
+ console.log()
169
+ log(GREEN, '[create-preset] ✔', `Preset created successfully!`)
170
+ console.log(` ${CYAN}Directory:${RESET} ${relTarget}`)
171
+ console.log(` ${CYAN}Tokens File:${RESET} ${relFile}`)
172
+ console.log()
173
+
174
+ const presetTitle = toTitleCase(result.presetName)
175
+
176
+ if (result.basePreset) {
177
+ const baseTitle = toTitleCase(result.basePreset)
178
+ console.log(` ${YELLOW}Inheritance Architecture:${RESET}`)
179
+ console.log(` Preset is based on ${BOLD}"${result.basePreset}"${RESET}.`)
180
+ console.log(` No files were copied from "${result.basePreset}" because Katlux cascades automatically!`)
181
+ console.log(` Any token or component not defined in "${result.presetName}" will fall back to "${result.basePreset}", then "default".`)
182
+ console.log()
183
+ console.log(` ${BOLD}Configure in your app.config.ts:${RESET}`)
184
+ console.log(`${DIM}------------------------------------------------------------${RESET}`)
185
+ console.log(`export default defineAppConfig({
186
+ katluxToolkit: {
187
+ presetList: [
188
+ { name: 'Default', value: 'default' },
189
+ { name: '${baseTitle}', value: '${result.basePreset}' },
190
+ { name: '${presetTitle}', value: ['${result.presetName}', '${result.basePreset}'] }
191
+ ],
192
+ // Multi-preset configuration: '${result.presetName}' overrides '${result.basePreset}'
193
+ activePreset: ['${result.presetName}', '${result.basePreset}']
194
+ }
195
+ })`)
196
+ console.log(`${DIM}------------------------------------------------------------${RESET}`)
197
+ } else {
198
+ console.log(` ${YELLOW}Single Preset Architecture:${RESET}`)
199
+ console.log(` No base preset specified. Any token or component not defined in "${result.presetName}"`)
200
+ console.log(` will automatically fall back to the built-in "default" preset.`)
201
+ console.log()
202
+ console.log(` ${BOLD}Configure in your app.config.ts:${RESET}`)
203
+ console.log(`${DIM}------------------------------------------------------------${RESET}`)
204
+ console.log(`export default defineAppConfig({
205
+ katluxToolkit: {
206
+ presetList: [
207
+ { name: 'Default', value: 'default' },
208
+ { name: '${presetTitle}', value: '${result.presetName}' }
209
+ ],
210
+ // Single preset configuration: falls back directly to 'default'
211
+ activePreset: '${result.presetName}'
212
+ }
213
+ })`)
214
+ console.log(`${DIM}------------------------------------------------------------${RESET}`)
215
+ }
216
+
217
+ console.log()
218
+ } catch (err) {
219
+ console.log()
220
+ log(RED, '[create-preset] ✖', err.message)
221
+ console.log()
222
+ process.exit(1)
223
+ }
224
+ }
225
+
226
+ // Run CLI directly if invoked as script
227
+ const isMain = process.argv[1] && (
228
+ process.argv[1].endsWith('create-preset.mjs') ||
229
+ process.argv[1].endsWith('create-preset')
230
+ )
231
+ if (isMain) {
232
+ runCli()
233
+ }
@@ -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
  }
@@ -102,4 +102,56 @@ describe("useDataProvider Composable Adapter", () => {
102
102
  });
103
103
  scope.stop();
104
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
+ });
105
157
  });
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@katlux/toolkit",
3
3
  "configKey": "katluxToolkit",
4
- "version": "0.1.1-alpha.115",
4
+ "version": "0.1.1-alpha.117",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.1"
@@ -1,13 +1,34 @@
1
1
  declare const __VLS_export: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
2
2
  multiOpen: {
3
3
  type: BooleanConstructor;
4
+ default: boolean;
4
5
  };
5
- }>, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
6
+ modelValue: {
7
+ type: import("vue").PropType<string | string[] | number | number[]>;
8
+ default: undefined;
9
+ };
10
+ }>, {
11
+ openIds: import("vue").Ref<string[], string[]>;
12
+ toggleItem: (id: string) => void;
13
+ isOpen: (id: string) => boolean;
14
+ }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
15
+ "update:modelValue": (value: any) => any;
16
+ change: (value: any) => any;
17
+ }, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
6
18
  multiOpen: {
7
19
  type: BooleanConstructor;
20
+ default: boolean;
21
+ };
22
+ modelValue: {
23
+ type: import("vue").PropType<string | string[] | number | number[]>;
24
+ default: undefined;
8
25
  };
9
- }>> & Readonly<{}>, {
26
+ }>> & Readonly<{
27
+ "onUpdate:modelValue"?: ((value: any) => any) | undefined;
28
+ onChange?: ((value: any) => any) | undefined;
29
+ }>, {
10
30
  multiOpen: boolean;
31
+ modelValue: string | number | string[] | number[];
11
32
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
12
33
  declare const _default: typeof __VLS_export;
13
34
  export default _default;
@@ -4,7 +4,13 @@ import { usePresetComponent } from "../../composables/usePresetComponent";
4
4
  import { computed } from "vue";
5
5
  import KAccordionDefault from "../../presets/default/components/KAccordion/KAccordion.vue";
6
6
  const props = defineProps(KAccordionDefaultProps);
7
- useKAccordionLogic(props);
7
+ const emit = defineEmits(["update:modelValue", "change"]);
8
+ const { openIds, toggleItem, isOpen } = useKAccordionLogic(props, emit);
9
+ defineExpose({
10
+ openIds,
11
+ toggleItem,
12
+ isOpen
13
+ });
8
14
  const presetComponent = usePresetComponent("KAccordion", KAccordionDefault);
9
15
  </script>
10
16