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

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 (84) hide show
  1. package/bin/add-ai-reference.mjs +152 -39
  2. package/bin/cli.mjs +20 -1
  3. package/dist/compiled/composables/useDataProvider.mjs +20 -0
  4. package/dist/compiled/composables/useKatluxForm.mjs +55 -12
  5. package/dist/compiled/composables/useVirtualScroll.mjs +78 -8
  6. package/dist/module.json +1 -1
  7. package/dist/runtime/components/KBulkActions/KBulkActions.logic.js +26 -17
  8. package/dist/runtime/components/KCheckbox/KCheckbox.global.d.vue.ts +12 -0
  9. package/dist/runtime/components/KCheckbox/KCheckbox.global.vue +4 -2
  10. package/dist/runtime/components/KCheckbox/KCheckbox.global.vue.d.ts +12 -0
  11. package/dist/runtime/components/KCheckbox/KCheckbox.logic.d.ts +5 -0
  12. package/dist/runtime/components/KCheckbox/KCheckbox.logic.js +4 -0
  13. package/dist/runtime/components/KCombobox/KCombobox.global.d.vue.ts +2 -0
  14. package/dist/runtime/components/KCombobox/KCombobox.global.vue +2 -2
  15. package/dist/runtime/components/KCombobox/KCombobox.global.vue.d.ts +2 -0
  16. package/dist/runtime/components/KCombobox/KCombobox.logic.d.ts +1 -0
  17. package/dist/runtime/components/KDatatable/KDataIterator.logic.js +5 -33
  18. package/dist/runtime/components/KDatatable/KDatatable.logic.js +30 -31
  19. package/dist/runtime/components/KDatePicker/KDatePicker.global.d.vue.ts +4 -2
  20. package/dist/runtime/components/KDatePicker/KDatePicker.global.vue +2 -1
  21. package/dist/runtime/components/KDatePicker/KDatePicker.global.vue.d.ts +4 -2
  22. package/dist/runtime/components/KDateTimePicker/KDateTimePicker.global.d.vue.ts +2 -2
  23. package/dist/runtime/components/KDateTimePicker/KDateTimePicker.global.vue.d.ts +2 -2
  24. package/dist/runtime/components/KDropdown/KDropdown.global.d.vue.ts +1 -1
  25. package/dist/runtime/components/KDropdown/KDropdown.global.vue.d.ts +1 -1
  26. package/dist/runtime/components/KGantt/KGantt.global.d.vue.ts +36 -0
  27. package/dist/runtime/components/KGantt/KGantt.global.vue +5 -1
  28. package/dist/runtime/components/KGantt/KGantt.global.vue.d.ts +36 -0
  29. package/dist/runtime/components/KGantt/KGantt.logic.d.ts +20 -0
  30. package/dist/runtime/components/KGantt/KGantt.logic.js +17 -6
  31. package/dist/runtime/components/KPagination/KPagination.global.d.vue.ts +2 -0
  32. package/dist/runtime/components/KPagination/KPagination.global.vue +1 -1
  33. package/dist/runtime/components/KPagination/KPagination.global.vue.d.ts +2 -0
  34. package/dist/runtime/components/KPagination/KPagination.logic.d.ts +1 -0
  35. package/dist/runtime/components/KPagination/KPagination.logic.js +6 -1
  36. package/dist/runtime/components/KTooltip/KTooltip.global.d.vue.ts +1 -1
  37. package/dist/runtime/components/KTooltip/KTooltip.global.vue.d.ts +1 -1
  38. package/dist/runtime/components/KTree/KTree.global.d.vue.ts +1 -1
  39. package/dist/runtime/components/KTree/KTree.global.vue +0 -1
  40. package/dist/runtime/components/KTree/KTree.global.vue.d.ts +1 -1
  41. package/dist/runtime/components/KTreePicker/KTreePicker.global.d.vue.ts +1 -1
  42. package/dist/runtime/components/KTreePicker/KTreePicker.global.vue.d.ts +1 -1
  43. package/dist/runtime/components/KTreeView/KTreeView.global.d.vue.ts +1 -1
  44. package/dist/runtime/components/KTreeView/KTreeView.global.vue.d.ts +1 -1
  45. package/dist/runtime/composables/useDataProvider.d.ts +1 -0
  46. package/dist/runtime/composables/useDataProvider.js +20 -0
  47. package/dist/runtime/composables/useFilterLogic.d.ts +1 -0
  48. package/dist/runtime/composables/useKatluxForm.d.ts +2 -0
  49. package/dist/runtime/composables/useKatluxForm.js +55 -12
  50. package/dist/runtime/composables/useVirtualScroll.d.ts +1 -1
  51. package/dist/runtime/composables/useVirtualScroll.js +78 -8
  52. package/dist/runtime/presets/default/assets/scss/css-variables.css +1 -0
  53. package/dist/runtime/presets/default/assets/scss/css-variables.scss +1 -0
  54. package/dist/runtime/presets/default/assets/scss/index.css +1 -0
  55. package/dist/runtime/presets/default/components/KBulkActions/KBulkActions.vue +4 -4
  56. package/dist/runtime/presets/default/components/KCheckbox/KCheckbox.d.vue.ts +3 -0
  57. package/dist/runtime/presets/default/components/KCheckbox/KCheckbox.vue +7 -0
  58. package/dist/runtime/presets/default/components/KCheckbox/KCheckbox.vue.d.ts +3 -0
  59. package/dist/runtime/presets/default/components/KCombobox/KCombobox.d.vue.ts +2 -0
  60. package/dist/runtime/presets/default/components/KCombobox/KCombobox.vue +3 -1
  61. package/dist/runtime/presets/default/components/KCombobox/KCombobox.vue.d.ts +2 -0
  62. package/dist/runtime/presets/default/components/KDataIterator/KDataIterator.d.vue.ts +2 -0
  63. package/dist/runtime/presets/default/components/KDataIterator/KDataIterator.vue +20 -6
  64. package/dist/runtime/presets/default/components/KDataIterator/KDataIterator.vue.d.ts +2 -0
  65. package/dist/runtime/presets/default/components/KDatatable/KDatatable.vue +85 -15
  66. package/dist/runtime/presets/default/components/KDatePicker/KDatePicker.d.vue.ts +3 -1
  67. package/dist/runtime/presets/default/components/KDatePicker/KDatePicker.vue +3 -1
  68. package/dist/runtime/presets/default/components/KDatePicker/KDatePicker.vue.d.ts +3 -1
  69. package/dist/runtime/presets/default/components/KGantt/KGantt.d.vue.ts +4 -0
  70. package/dist/runtime/presets/default/components/KGantt/KGantt.vue +16 -2
  71. package/dist/runtime/presets/default/components/KGantt/KGantt.vue.d.ts +4 -0
  72. package/dist/runtime/presets/default/components/KGrid/KGrid.vue +1 -0
  73. package/dist/runtime/presets/default/components/KLayout/KLayout.d.vue.ts +6 -1
  74. package/dist/runtime/presets/default/components/KLayout/KLayout.vue +53 -5
  75. package/dist/runtime/presets/default/components/KLayout/KLayout.vue.d.ts +6 -1
  76. package/dist/runtime/presets/default/components/KPagination/KPagination.vue +29 -7
  77. package/dist/runtime/presets/default/components/KTextarea/KTextarea.vue +1 -0
  78. package/dist/runtime/presets/default/components/KTextbox/KTextbox.vue +1 -1
  79. package/dist/runtime/presets/default/components/KToast/KToast.vue +0 -1
  80. package/dist/runtime/presets/default/components/KToastContainer/KToastContainer.vue +0 -1
  81. package/dist/runtime/presets/default/components/KTree/KTree.d.vue.ts +2 -3
  82. package/dist/runtime/presets/default/components/KTree/KTree.vue +7 -5
  83. package/dist/runtime/presets/default/components/KTree/KTree.vue.d.ts +2 -3
  84. package/package.json +2 -2
@@ -1,22 +1,33 @@
1
1
  #!/usr/bin/env node
2
2
  /**
3
3
  * katlux-add-ref
4
- * Downloads the Katlux AI Reference Guide from the official showcase and installs
5
- * it into the current project at .agents/skills/KATLUX_AI_REFERENCE.md.
4
+ * Downloads Katlux AI skill files from the official showcase and installs them
5
+ * into the current project. Safe to re-run at any time to update to the latest.
6
+ *
7
+ * What it does:
8
+ * 1. Downloads .agents/skills/KATLUX_INDEX.md (always overwritten, auto-maintained)
9
+ * 2. Downloads .agents/skills/katlux-[skill]/SKILL.md (always overwritten, auto-maintained)
10
+ * 3. Scaffolds AGENTS.md (created once, never overwritten)
11
+ * 4. Scaffolds .agents/rules/rules.md (created once, never overwritten)
6
12
  *
7
13
  * Usage:
8
14
  * npx @katlux/toolkit katlux-add-ref
9
15
  */
10
16
 
11
- import { existsSync, mkdirSync, writeFileSync } from 'fs'
17
+ import { existsSync, mkdirSync, writeFileSync, readFileSync } from 'fs'
12
18
  import { resolve, join } from 'path'
13
19
 
14
- // Official showcase endpoint — always serves the latest reference guide.
15
- const REFERENCE_URL = 'https://katlux.dev/ai-reference.md'
20
+ const BASE_URL = 'https://katlux.dev/ai-reference'
16
21
 
17
- // Target: project root / .agents/skills/KATLUX_AI_REFERENCE.md
18
- const targetDir = resolve(process.cwd(), '.agents', 'skills')
19
- const targetFile = join(targetDir, 'KATLUX_AI_REFERENCE.md')
22
+ // Skills to download — script is the only place this list lives on the client side.
23
+ // The server-generated KATLUX_INDEX.md is the canonical skill routing table for agents.
24
+ const SKILLS = [
25
+ 'katlux-config',
26
+ 'katlux-components',
27
+ 'katlux-providers',
28
+ 'katlux-presets',
29
+ 'katlux-tokens',
30
+ ]
20
31
 
21
32
  const RESET = '\x1b[0m'
22
33
  const GREEN = '\x1b[32m'
@@ -30,55 +41,157 @@ function log(color, prefix, message) {
30
41
  console.log(`${color}${BOLD}${prefix}${RESET} ${message}`)
31
42
  }
32
43
 
33
- // ── Fetch the reference file ────────────────────────────────────────────────
44
+ async function fetchText(url) {
45
+ const response = await fetch(url)
46
+ if (!response.ok) throw new Error(`${response.status} ${response.statusText} — ${url}`)
47
+ return response.text()
48
+ }
49
+
50
+ // ── Start ────────────────────────────────────────────────────────────────────
34
51
  console.log()
35
- log(CYAN, '[katlux-add-ref]', `Fetching reference guide from showcase...`)
36
- console.log(` ${DIM}${REFERENCE_URL}${RESET}`)
52
+ log(CYAN, '[katlux-add-ref]', `Downloading Katlux AI skill files...`)
53
+ console.log(` ${DIM}${BASE_URL}${RESET}`)
37
54
  console.log()
38
55
 
39
- let content
56
+ const projectRoot = process.cwd()
57
+ const agentsDir = resolve(projectRoot, '.agents')
58
+ const skillsDir = resolve(agentsDir, 'skills')
59
+ const rulesDir = resolve(agentsDir, 'rules')
60
+
61
+ // Ensure base directories exist
62
+ if (!existsSync(skillsDir)) mkdirSync(skillsDir, { recursive: true })
63
+ if (!existsSync(rulesDir)) mkdirSync(rulesDir, { recursive: true })
64
+
65
+ // ── 1. Download KATLUX_INDEX.md (always overwrite) ──────────────────────────
66
+ process.stdout.write(` ${DIM}Fetching index...${RESET}`)
67
+ let indexContent
40
68
  try {
41
- const response = await fetch(REFERENCE_URL)
42
- if (!response.ok) {
43
- log(RED, '[katlux-add-ref] ✖', `Server responded with ${response.status} ${response.statusText}`)
44
- console.log(`\n Make sure the Katlux Showcase is reachable:\n ${REFERENCE_URL}`)
45
- process.exit(1)
46
- }
47
- content = await response.text()
69
+ indexContent = await fetchText(`${BASE_URL}/index`)
70
+ process.stdout.write(` ${GREEN}✔${RESET}\n`)
48
71
  } catch (err) {
49
- log(RED, '[katlux-add-ref] ✖', `Network error — could not reach the showcase:`)
72
+ process.stdout.write(` ${RED}✖${RESET}\n`)
73
+ log(RED, '[katlux-add-ref] ✖', `Failed to fetch skill index:`)
50
74
  console.log(` ${err.message}`)
51
75
  console.log(`\n Check your internet connection and try again.`)
52
76
  process.exit(1)
53
77
  }
54
78
 
55
- // ── Create target directory if needed ──────────────────────────────────────
56
- const isUpdate = existsSync(targetFile)
57
- if (!existsSync(targetDir)) {
58
- mkdirSync(targetDir, { recursive: true })
79
+ writeFileSync(join(skillsDir, 'KATLUX_INDEX.md'), indexContent, 'utf-8')
80
+ log(GREEN, ' written', '.agents/skills/KATLUX_INDEX.md')
81
+ console.log()
82
+
83
+ // ── 2. Download individual skill files (always overwrite) ────────────────────
84
+ for (const skill of SKILLS) {
85
+ try {
86
+ process.stdout.write(` ${DIM}Fetching ${skill}...${RESET}`)
87
+ const content = await fetchText(`${BASE_URL}/${skill}`)
88
+ process.stdout.write(` ${GREEN}✔${RESET}\n`)
89
+
90
+ const skillDir = join(skillsDir, skill)
91
+ if (!existsSync(skillDir)) mkdirSync(skillDir, { recursive: true })
92
+ writeFileSync(join(skillDir, 'SKILL.md'), content, 'utf-8')
93
+ } catch (err) {
94
+ process.stdout.write(` ${RED}✖${RESET}\n`)
95
+ log(RED, '[katlux-add-ref] ✖', `Failed to fetch ${skill}:`)
96
+ console.log(` ${err.message}`)
97
+ process.exit(1)
98
+ }
59
99
  }
60
100
 
61
- // ── Write the file ──────────────────────────────────────────────────────────
62
- try {
63
- writeFileSync(targetFile, content, 'utf-8')
64
- } catch (err) {
65
- log(RED, '[katlux-add-ref] ✖', `Failed to write the reference file:`)
66
- console.log(` ${err.message}`)
67
- process.exit(1)
101
+ // ── 3. Scaffold AGENTS.md — created once, never overwritten ─────────────────
102
+ // Intentionally minimal: just two stable references that never need updating.
103
+ // KATLUX_INDEX.md (downloaded above) is what carries the skill routing table.
104
+ console.log()
105
+ const agentsMdPath = resolve(projectRoot, 'AGENTS.md')
106
+ if (!existsSync(agentsMdPath)) {
107
+ writeFileSync(agentsMdPath, `# Agent Context and Guidelines
108
+
109
+ This file serves as the main entry point for AI agents to understand the workspace structure and guidelines.
110
+
111
+ - [Project Rules](.agents/rules/rules.md)
112
+ - [Katlux Skills Index](.agents/skills/KATLUX_INDEX.md)
113
+ `, 'utf-8')
114
+ log(GREEN, ' created', `AGENTS.md ${DIM}(edit this to add project-specific context)${RESET}`)
115
+ } else {
116
+ log(DIM, ' skipped', `AGENTS.md already exists`)
68
117
  }
69
118
 
70
- // ── Success output ──────────────────────────────────────────────────────────
71
- if (isUpdate) {
72
- log(GREEN, '[katlux-add-ref] ✔', `Reference guide updated successfully!`)
119
+ // ── 4. Scaffold .agents/rules/rules.md — created once, never overwritten ────
120
+ // Users add their own project rules here. Katlux standards live in KATLUX_INDEX.md.
121
+ const rulesMdPath = join(rulesDir, 'rules.md')
122
+ if (!existsSync(rulesMdPath)) {
123
+ writeFileSync(rulesMdPath, `# Agent Rules
124
+
125
+ ## Project-Specific Rules
126
+
127
+ <!-- Add your own project rules here. -->
128
+ <!-- Example: always use the "users" Pinia store for auth state. -->
129
+
130
+ ## Katlux Code Standards
131
+
132
+ 1. **Template**: Always use **Pug** (\`lang="pug"\`). Use **Tabs** for indentation.
133
+ 2. **Styling**: Use CSS variables (e.g. \`var(--primary-500)\`, \`var(--border-radius-md)\`). Never hardcode colors or sizes.
134
+ 3. **Preset Selectors**: Scope CSS rules under \`[data-preset~="preset-name"]\`. Avoid \`!important\`.
135
+ 4. **Imports**: Use workspace aliases (e.g. \`#toolkit/composables/...\`). Avoid deep relative imports.
136
+ 5. **i18n**: Use \`t('...')\` for all user-facing strings and ARIA labels.
137
+ `, 'utf-8')
138
+ log(GREEN, ' created', `.agents/rules/rules.md ${DIM}(add your project-specific rules here)${RESET}`)
73
139
  } else {
74
- log(GREEN, '[katlux-add-ref] ✔', `Reference guide installed successfully!`)
140
+ log(DIM, ' skipped', `.agents/rules/rules.md already exists`)
141
+ }
142
+
143
+ // ── 5. Auto-configure MCP (Model Context Protocol) ───────────────────────────
144
+ // Enables surgical on-demand tool access for Cursor, Antigravity, and VS Code
145
+ // with zero manual JSON configuration required from the developer.
146
+ const localMcpPath = resolve(projectRoot, 'packages/katlux-mcp/bin/katlux-mcp.mjs')
147
+ const isMonorepo = existsSync(localMcpPath)
148
+
149
+ const KATLUX_MCP_SERVER = isMonorepo
150
+ ? { command: 'node', args: ['packages/katlux-mcp/bin/katlux-mcp.mjs'] }
151
+ : { command: 'npx', args: ['-y', '@katlux/mcp'] }
152
+
153
+ function updateMcpConfigFile(filePath) {
154
+ let config = {}
155
+ if (existsSync(filePath)) {
156
+ try {
157
+ config = JSON.parse(readFileSync(filePath, 'utf-8'))
158
+ } catch {
159
+ config = {}
160
+ }
161
+ }
162
+ if (!config.mcpServers) config.mcpServers = {}
163
+ config.mcpServers.katlux = KATLUX_MCP_SERVER
164
+ writeFileSync(filePath, JSON.stringify(config, null, 2), 'utf-8')
165
+ }
166
+
167
+ // 5a. Antigravity / Agents (.agents/mcp_config.json)
168
+ updateMcpConfigFile(join(agentsDir, 'mcp_config.json'))
169
+ log(GREEN, ' configured', '.agents/mcp_config.json (Antigravity MCP server enabled)')
170
+
171
+ // 5b. Cursor (.cursor/mcp.json)
172
+ const cursorDir = resolve(projectRoot, '.cursor')
173
+ if (existsSync(cursorDir)) {
174
+ updateMcpConfigFile(join(cursorDir, 'mcp.json'))
175
+ log(GREEN, ' configured', '.cursor/mcp.json (Cursor MCP server enabled)')
75
176
  }
177
+
178
+ // 5c. VS Code (.vscode/mcp.json)
179
+ const vscodeDir = resolve(projectRoot, '.vscode')
180
+ if (existsSync(vscodeDir)) {
181
+ updateMcpConfigFile(join(vscodeDir, 'mcp.json'))
182
+ log(GREEN, ' configured', '.vscode/mcp.json (VS Code MCP server enabled)')
183
+ }
184
+
185
+ // ── Done ─────────────────────────────────────────────────────────────────────
186
+ console.log()
187
+ log(GREEN, '[katlux-add-ref] ✔', `Done! ${SKILLS.length} skill files + index installed and MCP server configured.`)
76
188
  console.log()
77
- console.log(` ${CYAN}Location:${RESET} ${targetFile}`)
189
+ console.log(` ${CYAN}Skills:${RESET} .agents/skills/katlux-*/SKILL.md`)
190
+ console.log(` ${CYAN}Index:${RESET} .agents/skills/KATLUX_INDEX.md ${DIM}(auto-updated each run)${RESET}`)
191
+ console.log(` ${CYAN}MCP:${RESET} @katlux/mcp server ready on stdio`)
78
192
  console.log()
79
- console.log(` ${YELLOW}Tip:${RESET} If you use an AI assistant (Cursor, Copilot, Antigravity, etc.),`)
80
- console.log(` point it to this file so it understands the full Katlux component API.`)
193
+ console.log(` ${YELLOW}Next:${RESET} Add your project-specific rules to ${CYAN}.agents/rules/rules.md${RESET}`)
81
194
  console.log()
82
- console.log(` Re-run this command any time to get the latest version:`)
195
+ console.log(` Re-run any time to update to the latest version:`)
83
196
  console.log(` ${CYAN}npx @katlux/toolkit katlux-add-ref${RESET}`)
84
197
  console.log()
package/bin/cli.mjs CHANGED
@@ -5,9 +5,13 @@
5
5
  * Supported commands:
6
6
  * npx @katlux/toolkit create-preset <preset-name> [--base=<base>]
7
7
  * npx @katlux/toolkit katlux-add-ref
8
+ *
9
+ * katlux-add-ref installs 5 focused AI skill files under .agents/skills/katlux-*
10
+ * and scaffolds AGENTS.md + .agents/rules/rules.md if they don't exist.
8
11
  */
9
12
 
10
13
  import { spawn } from 'child_process'
14
+ import { existsSync } from 'fs'
11
15
  import { resolve, dirname } from 'path'
12
16
  import { fileURLToPath } from 'url'
13
17
 
@@ -34,12 +38,17 @@ ${BOLD}Commands:${RESET}
34
38
  Any preset can be token-only. Base presets leverage cascading inheritance without copying files.
35
39
 
36
40
  ${CYAN}katlux-add-ref${RESET}
37
- Download or update the Katlux AI Reference Guide at .agents/skills/KATLUX_AI_REFERENCE.md.
41
+ Download or update 5 focused Katlux AI skill files into .agents/skills/katlux-*/SKILL.md.
42
+ Also scaffolds AGENTS.md, rules, and auto-configures MCP server for your IDE.
43
+
44
+ ${CYAN}mcp${RESET}
45
+ Start the Katlux Model Context Protocol (MCP) server over stdio for AI coding assistants.
38
46
 
39
47
  ${BOLD}Examples:${RESET}
40
48
  npx @katlux/toolkit create-preset cyber-brand --base=modern
41
49
  npx @katlux/toolkit create-preset my-theme
42
50
  npx @katlux/toolkit katlux-add-ref
51
+ npx @katlux/toolkit mcp
43
52
  `)
44
53
  }
45
54
 
@@ -57,6 +66,16 @@ if (command === 'create-preset') {
57
66
  } else if (command === 'katlux-add-ref' || command === 'add-ref') {
58
67
  scriptPath = resolve(__dirname, 'add-ai-reference.mjs')
59
68
  forwardedArgs = args.slice(1)
69
+ } else if (command === 'mcp') {
70
+ const localMcpBin = resolve(__dirname, '../../katlux-mcp/bin/katlux-mcp.mjs')
71
+ if (existsSync(localMcpBin)) {
72
+ scriptPath = localMcpBin
73
+ forwardedArgs = args.slice(1)
74
+ } else {
75
+ const npxCmd = process.platform === 'win32' ? 'npx.cmd' : 'npx'
76
+ const child = spawn(npxCmd, ['-y', '@katlux/mcp', ...args.slice(1)], { stdio: 'inherit' })
77
+ child.on('exit', (code) => process.exit(code ?? 0))
78
+ }
60
79
  } else {
61
80
  console.log(`${RED}${BOLD}[katlux] ✖${RESET} Unknown command: "${command}"`)
62
81
  printHelp()
@@ -15,6 +15,22 @@ export function useDataProvider(provider, options) {
15
15
  const pageData = shallowRef(
16
16
  activeProvider ? activeProvider.pageData?.value !== void 0 ? activeProvider.pageData.value : Array.isArray(activeProvider.pageData) ? activeProvider.pageData : extractVal(activeProvider.pageData, []) : []
17
17
  );
18
+ const getFullData = () => {
19
+ if (!activeProvider) return [];
20
+ if (Array.isArray(activeProvider.allVisibleRows) && activeProvider.allVisibleRows.length > 0) return activeProvider.allVisibleRows;
21
+ if (Array.isArray(activeProvider.allVisibleRows?.value) && activeProvider.allVisibleRows.value.length > 0) return activeProvider.allVisibleRows.value;
22
+ if (Array.isArray(activeProvider.rowMap) && activeProvider.rowMap.length > 0) return activeProvider.rowMap;
23
+ if (Array.isArray(activeProvider.rowMap?.value) && activeProvider.rowMap.value.length > 0) return activeProvider.rowMap.value;
24
+ if (Array.isArray(activeProvider.allVisibleNodes) && activeProvider.allVisibleNodes.length > 0) return activeProvider.allVisibleNodes;
25
+ if (Array.isArray(activeProvider.allVisibleNodes?.value) && activeProvider.allVisibleNodes.value.length > 0) return activeProvider.allVisibleNodes.value;
26
+ if (Array.isArray(activeProvider.allData) && activeProvider.allData.length > 0) return activeProvider.allData;
27
+ if (Array.isArray(activeProvider.allData?.value) && activeProvider.allData.value.length > 0) return activeProvider.allData.value;
28
+ if (Array.isArray(activeProvider.data) && activeProvider.data.length > 0) return activeProvider.data;
29
+ if (Array.isArray(activeProvider.rowMap)) return activeProvider.rowMap;
30
+ if (Array.isArray(activeProvider.allVisibleRows)) return activeProvider.allVisibleRows;
31
+ return pageData.value;
32
+ };
33
+ const virtualRows = shallowRef(activeProvider ? getFullData() : []);
18
34
  const rowCount = ref(activeProvider ? extractVal(activeProvider.rowCount, 0) : 0);
19
35
  const currentPage = options?.currentPage || ref(activeProvider ? extractVal(activeProvider.currentPage, 1) : 1);
20
36
  const pageSize = options?.pageSize || ref(activeProvider ? extractVal(activeProvider.pageSize, 10) : 10);
@@ -30,6 +46,7 @@ export function useDataProvider(provider, options) {
30
46
  const syncFromProvider = () => {
31
47
  if (!activeProvider) {
32
48
  pageData.value = [];
49
+ virtualRows.value = [];
33
50
  rowCount.value = 0;
34
51
  currentPage.value = 1;
35
52
  pageSize.value = 10;
@@ -46,6 +63,7 @@ export function useDataProvider(provider, options) {
46
63
  try {
47
64
  pageData.value = activeProvider.pageData?.value !== void 0 ? activeProvider.pageData.value : Array.isArray(activeProvider.pageData) ? activeProvider.pageData : extractVal(activeProvider.pageData, []);
48
65
  rowCount.value = extractVal(activeProvider.rowCount, 0);
66
+ virtualRows.value = getFullData();
49
67
  const newPage = extractVal(activeProvider.currentPage, 1);
50
68
  if (currentPage.value !== newPage) {
51
69
  currentPage.value = newPage;
@@ -93,6 +111,7 @@ export function useDataProvider(provider, options) {
93
111
  }
94
112
  };
95
113
  attachListener();
114
+ syncFromProvider();
96
115
  try {
97
116
  onScopeDispose(() => {
98
117
  if (unsubscribe) {
@@ -320,6 +339,7 @@ export function useDataProvider(provider, options) {
320
339
  return activeProvider;
321
340
  },
322
341
  pageData,
342
+ virtualRows,
323
343
  rowCount,
324
344
  currentPage,
325
345
  pageSize,
@@ -45,15 +45,28 @@ export function useKatluxForm(options = {}) {
45
45
  const submitCount = ref(0);
46
46
  const isDirty = computed(() => Object.values(dirtyFields.value).some(Boolean));
47
47
  const isValid = computed(() => Object.keys(errors.value).length === 0);
48
+ function registerErrorPaths(errorMap, pathStr, message) {
49
+ if (!pathStr) {
50
+ errorMap[""] = message;
51
+ return;
52
+ }
53
+ errorMap[pathStr] = message;
54
+ const bracketPath = pathStr.replace(/\.(\d+)(?=\.|$)/g, "[$1]");
55
+ if (bracketPath !== pathStr && !errorMap[bracketPath]) {
56
+ errorMap[bracketPath] = message;
57
+ }
58
+ const dotPath = pathStr.replace(/\[(\d+)\]/g, ".$1");
59
+ if (dotPath !== pathStr && !errorMap[dotPath]) {
60
+ errorMap[dotPath] = message;
61
+ }
62
+ }
48
63
  function parseValidationResult(rawResult, schemaType, dataToValidate) {
49
64
  if (schemaType === "standard") {
50
65
  if (rawResult.issues && rawResult.issues.length > 0) {
51
66
  const errorMap = {};
52
67
  for (const issue of rawResult.issues) {
53
68
  const pathStr = issue.path && issue.path.length > 0 ? issue.path.map((seg) => typeof seg === "object" && seg !== null && "key" in seg ? seg.key : seg).join(".") : "";
54
- if (!errorMap[pathStr]) {
55
- errorMap[pathStr] = issue.message;
56
- }
69
+ registerErrorPaths(errorMap, pathStr, issue.message);
57
70
  }
58
71
  return { valid: false, output: dataToValidate, errors: errorMap };
59
72
  }
@@ -64,16 +77,18 @@ export function useKatluxForm(options = {}) {
64
77
  const errorMap = {};
65
78
  for (const issue of rawResult.error.issues) {
66
79
  const pathStr = issue.path ? issue.path.join(".") : "";
67
- if (!errorMap[pathStr]) {
68
- errorMap[pathStr] = issue.message;
69
- }
80
+ registerErrorPaths(errorMap, pathStr, issue.message);
70
81
  }
71
82
  return { valid: false, output: dataToValidate, errors: errorMap };
72
83
  }
73
84
  return { valid: true, output: rawResult.data ?? dataToValidate, errors: {} };
74
85
  }
75
86
  if (schemaType === "custom") {
76
- const errorMap = rawResult || {};
87
+ const errorMap = {};
88
+ const rawErrors = rawResult || {};
89
+ for (const [key, msg] of Object.entries(rawErrors)) {
90
+ registerErrorPaths(errorMap, key, String(msg));
91
+ }
77
92
  const valid = Object.keys(errorMap).length === 0;
78
93
  return { valid, output: dataToValidate, errors: errorMap };
79
94
  }
@@ -109,12 +124,17 @@ export function useKatluxForm(options = {}) {
109
124
  }
110
125
  function applyErrors(targetPath, newErrors) {
111
126
  if (targetPath) {
112
- if (newErrors[targetPath]) {
113
- errors.value = { ...errors.value, [targetPath]: newErrors[targetPath] };
127
+ const bracketPath = targetPath.replace(/\.(\d+)(?=\.|$)/g, "[$1]");
128
+ const dotPath = targetPath.replace(/\[(\d+)\]/g, ".$1");
129
+ const err = newErrors[targetPath] || newErrors[bracketPath] || newErrors[dotPath];
130
+ if (err) {
131
+ errors.value = { ...errors.value, [targetPath]: err };
114
132
  return false;
115
133
  } else {
116
134
  const nextErrors = { ...errors.value };
117
135
  delete nextErrors[targetPath];
136
+ delete nextErrors[bracketPath];
137
+ delete nextErrors[dotPath];
118
138
  errors.value = nextErrors;
119
139
  return true;
120
140
  }
@@ -123,10 +143,17 @@ export function useKatluxForm(options = {}) {
123
143
  return Object.keys(newErrors).length === 0;
124
144
  }
125
145
  }
146
+ let validationSeq = 0;
126
147
  function validate(targetPath) {
148
+ const seq = ++validationSeq;
127
149
  const result = runValidation(values);
128
150
  if (result && typeof result.then === "function") {
129
- return result.then(({ errors: newErrors }) => applyErrors(targetPath, newErrors));
151
+ return result.then(({ errors: newErrors }) => {
152
+ if (seq !== validationSeq) {
153
+ return Object.keys(errors.value).length === 0;
154
+ }
155
+ return applyErrors(targetPath, newErrors);
156
+ });
130
157
  }
131
158
  return applyErrors(targetPath, result.errors);
132
159
  }
@@ -176,9 +203,18 @@ export function useKatluxForm(options = {}) {
176
203
  return getByPath(values, path);
177
204
  },
178
205
  "onUpdate:modelValue": (newVal) => {
179
- const transformed = regOptions.transform ? regOptions.transform(newVal) : newVal;
206
+ let transformed = newVal;
207
+ if (regOptions.transform) {
208
+ if (regOptions.transform === Number) {
209
+ transformed = newVal === "" || newVal === null || newVal === void 0 ? "" : Number(newVal);
210
+ } else {
211
+ transformed = regOptions.transform(newVal);
212
+ }
213
+ }
180
214
  setByPath(values, path, transformed);
181
- dirtyFields.value = { ...dirtyFields.value, [path]: true };
215
+ const initialVal = getByPath(initialValues, path);
216
+ const isFieldDirty = JSON.stringify(transformed) !== JSON.stringify(initialVal);
217
+ dirtyFields.value = { ...dirtyFields.value, [path]: isFieldDirty };
182
218
  const hasActiveError = !!errors.value[path];
183
219
  if (mode === "onChange" || hasActiveError && reValidateMode === "onChange") {
184
220
  validate(path);
@@ -196,6 +232,12 @@ export function useKatluxForm(options = {}) {
196
232
  }
197
233
  return errors.value[path] || "";
198
234
  },
235
+ get "aria-invalid"() {
236
+ return !!errors.value[path];
237
+ },
238
+ get "aria-describedby"() {
239
+ return errors.value[path] ? `${path}-error` : void 0;
240
+ },
199
241
  onBlur: () => {
200
242
  touched.value = { ...touched.value, [path]: true };
201
243
  const hasActiveError = !!errors.value[path];
@@ -221,6 +263,7 @@ export function useKatluxForm(options = {}) {
221
263
  }
222
264
  function handleSubmit(onValid, onInvalid) {
223
265
  return async (event) => {
266
+ if (isSubmitting.value) return;
224
267
  if (event && typeof event.preventDefault === "function") {
225
268
  event.preventDefault();
226
269
  }
@@ -42,6 +42,7 @@ export function useVirtualScroll(options) {
42
42
  const val = unref(options.containerHeight);
43
43
  return typeof val === "number" && val > 0 ? val : 400;
44
44
  };
45
+ const configuredContainerHeight = computed(() => resolveContainerHeight());
45
46
  const viewportHeight = ref(resolveContainerHeight());
46
47
  watch(
47
48
  () => resolveContainerHeight(),
@@ -51,13 +52,13 @@ export function useVirtualScroll(options) {
51
52
  }
52
53
  }
53
54
  );
54
- watch(containerRef, (el, oldEl) => {
55
+ watch([containerRef, isVirtual], ([el, virtual], [oldEl]) => {
55
56
  if (typeof window === "undefined" || typeof ResizeObserver === "undefined") return;
56
57
  if (oldEl && oldEl.__vsObserver) {
57
58
  oldEl.__vsObserver.disconnect();
58
59
  delete oldEl.__vsObserver;
59
60
  }
60
- if (el) {
61
+ if (el && virtual) {
61
62
  const ro = new ResizeObserver((entries) => {
62
63
  for (const entry of entries) {
63
64
  const h = Math.round(entry.contentRect.height || el.clientHeight);
@@ -78,12 +79,42 @@ export function useVirtualScroll(options) {
78
79
  }
79
80
  });
80
81
  }
82
+ const isDynamicHeight = computed(() => typeof options.itemHeight === "function");
83
+ const rowOffsets = computed(() => {
84
+ if (!isDynamicHeight.value || colCount.value > 1) return [];
85
+ const items = allItems.value;
86
+ const offsets = new Array(items.length + 1);
87
+ offsets[0] = 0;
88
+ let current = 0;
89
+ for (let i = 0; i < items.length; i++) {
90
+ current += getItemHeight(items[i], i);
91
+ offsets[i + 1] = current;
92
+ }
93
+ return offsets;
94
+ });
81
95
  const totalRows = computed(() => {
82
96
  if (colCount.value <= 1) return totalCount.value;
83
97
  return Math.ceil(totalCount.value / colCount.value);
84
98
  });
85
99
  const startRowIndex = computed(() => {
86
100
  if (!isVirtual.value) return 0;
101
+ if (isDynamicHeight.value && colCount.value <= 1) {
102
+ const offsets = rowOffsets.value;
103
+ const top = Math.max(0, scrollTop.value);
104
+ let low = 0;
105
+ let high = totalRows.value - 1;
106
+ let idx = 0;
107
+ while (low <= high) {
108
+ const mid = low + high >> 1;
109
+ if (offsets[mid + 1] > top) {
110
+ idx = mid;
111
+ high = mid - 1;
112
+ } else {
113
+ low = mid + 1;
114
+ }
115
+ }
116
+ return Math.max(0, idx - buf.value);
117
+ }
87
118
  const rawRow = Math.floor(scrollTop.value / baseItemHeight.value);
88
119
  return Math.max(0, rawRow - buf.value);
89
120
  });
@@ -94,6 +125,23 @@ export function useVirtualScroll(options) {
94
125
  });
95
126
  const endRowIndex = computed(() => {
96
127
  if (!isVirtual.value) return totalRows.value;
128
+ if (isDynamicHeight.value && colCount.value <= 1) {
129
+ const offsets = rowOffsets.value;
130
+ const bottom = scrollTop.value + viewportHeight.value;
131
+ let low = startRowIndex.value;
132
+ let high = totalRows.value - 1;
133
+ let idx = totalRows.value;
134
+ while (low <= high) {
135
+ const mid = low + high >> 1;
136
+ if (offsets[mid] >= bottom) {
137
+ idx = mid;
138
+ high = mid - 1;
139
+ } else {
140
+ low = mid + 1;
141
+ }
142
+ }
143
+ return Math.min(totalRows.value, idx + buf.value);
144
+ }
97
145
  return Math.min(totalRows.value, startRowIndex.value + visibleRowsCount.value);
98
146
  });
99
147
  const startIndex = computed(() => {
@@ -110,16 +158,27 @@ export function useVirtualScroll(options) {
110
158
  });
111
159
  const topSpacerHeight = computed(() => {
112
160
  if (!isVirtual.value) return 0;
161
+ if (isDynamicHeight.value && colCount.value <= 1) {
162
+ return rowOffsets.value[startRowIndex.value] || 0;
163
+ }
113
164
  return Math.max(0, startRowIndex.value * baseItemHeight.value);
114
165
  });
166
+ const totalHeight = computed(() => {
167
+ if (isDynamicHeight.value && colCount.value <= 1) {
168
+ const offsets = rowOffsets.value;
169
+ return offsets.length > 0 ? offsets[offsets.length - 1] : 0;
170
+ }
171
+ return totalRows.value * baseItemHeight.value;
172
+ });
115
173
  const bottomSpacerHeight = computed(() => {
116
174
  if (!isVirtual.value) return 0;
175
+ if (isDynamicHeight.value && colCount.value <= 1) {
176
+ const endOffset = rowOffsets.value[endRowIndex.value] || totalHeight.value;
177
+ return Math.max(0, totalHeight.value - endOffset);
178
+ }
117
179
  const remainingRows = Math.max(0, totalRows.value - endRowIndex.value);
118
180
  return remainingRows * baseItemHeight.value;
119
181
  });
120
- const totalHeight = computed(() => {
121
- return totalRows.value * baseItemHeight.value;
122
- });
123
182
  watch(totalHeight, (newTotal) => {
124
183
  if (scrollTop.value > newTotal) {
125
184
  scrollTop.value = Math.max(0, newTotal - viewportHeight.value);
@@ -133,7 +192,7 @@ export function useVirtualScroll(options) {
133
192
  "--virtual-spacer-bottom": `${bottomSpacerHeight.value}px`,
134
193
  "--virtual-total-height": `${totalHeight.value}px`,
135
194
  "--virtual-item-height": `${baseItemHeight.value}px`,
136
- "--virtual-container-height": `${viewportHeight.value}px`
195
+ "--virtual-container-height": `${configuredContainerHeight.value}px`
137
196
  }));
138
197
  const scrollThreshold = options.scrollThreshold ?? 100;
139
198
  const onScroll = (e) => {
@@ -148,9 +207,20 @@ export function useVirtualScroll(options) {
148
207
  options.onThresholdReach();
149
208
  }
150
209
  };
151
- const scrollToIndex = (index, behavior = "auto") => {
210
+ const scrollToIndex = (index, behavior = "auto", offset = 0) => {
211
+ if (isDynamicHeight.value && colCount.value <= 1) {
212
+ const targetScrollTop2 = Math.max(0, (rowOffsets.value[index] || 0) - offset);
213
+ scrollTop.value = targetScrollTop2;
214
+ if (containerRef.value) {
215
+ containerRef.value.scrollTo({
216
+ top: targetScrollTop2,
217
+ behavior
218
+ });
219
+ }
220
+ return;
221
+ }
152
222
  const targetRow = colCount.value <= 1 ? index : Math.floor(index / colCount.value);
153
- const targetScrollTop = targetRow * baseItemHeight.value;
223
+ const targetScrollTop = Math.max(0, targetRow * baseItemHeight.value - offset);
154
224
  scrollTop.value = targetScrollTop;
155
225
  if (containerRef.value) {
156
226
  containerRef.value.scrollTo({
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.119",
4
+ "version": "0.1.1-alpha.121",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.1"