@katlux/toolkit 0.1.1-alpha.116 → 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.
- package/bin/cli.mjs +72 -0
- package/bin/create-preset.mjs +233 -0
- package/dist/module.json +1 -1
- package/dist/runtime/components/KTabs/KTabs.global.d.vue.ts +1 -0
- package/dist/runtime/components/KTabs/KTabs.global.vue +5 -3
- package/dist/runtime/components/KTabs/KTabs.global.vue.d.ts +1 -0
- package/dist/runtime/components/KTabs/KTabs.logic.d.ts +1 -0
- package/dist/runtime/components/KTabs/KTabs.logic.js +32 -1
- package/dist/runtime/presets/default/components/KContextMenu/KContextMenu.vue +86 -4
- package/dist/runtime/presets/default/components/KTabs/KTabs.d.vue.ts +1 -0
- package/dist/runtime/presets/default/components/KTabs/KTabs.vue +23 -0
- package/dist/runtime/presets/default/components/KTabs/KTabs.vue.d.ts +1 -0
- 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
|
+
}
|
package/dist/module.json
CHANGED
|
@@ -11,6 +11,7 @@ declare const __VLS_export: import("vue").DefineComponent<import("vue").ExtractP
|
|
|
11
11
|
openIndexes: import("vue").Ref<number[], number[]>;
|
|
12
12
|
toggleItem: (index: number) => void;
|
|
13
13
|
isOpen: (index: number) => boolean;
|
|
14
|
+
onTabKeyDown: (e: KeyboardEvent, index: number) => number | void;
|
|
14
15
|
}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
|
|
15
16
|
"update:modelValue": (value: string | number) => any;
|
|
16
17
|
change: (value: string | number) => any;
|
|
@@ -5,20 +5,22 @@ import { computed } from "vue";
|
|
|
5
5
|
import KTabsDefault from "../../presets/default/components/KTabs/KTabs.vue";
|
|
6
6
|
const props = defineProps(KTabsDefaultProps);
|
|
7
7
|
const emit = defineEmits(["update:modelValue", "update:activeTab", "change"]);
|
|
8
|
-
const { items, openIndexes, toggleItem, isOpen } = useKTabsLogic(
|
|
8
|
+
const { items, openIndexes, toggleItem, isOpen, onTabKeyDown } = useKTabsLogic(
|
|
9
9
|
props,
|
|
10
10
|
emit
|
|
11
11
|
);
|
|
12
12
|
defineExpose({
|
|
13
13
|
openIndexes,
|
|
14
14
|
toggleItem,
|
|
15
|
-
isOpen
|
|
15
|
+
isOpen,
|
|
16
|
+
onTabKeyDown
|
|
16
17
|
});
|
|
17
18
|
const presetComponent = usePresetComponent("KTabs", KTabsDefault);
|
|
18
19
|
const templateProps = computed(() => ({
|
|
19
20
|
items: items.value,
|
|
20
21
|
toggleItem,
|
|
21
|
-
isOpen
|
|
22
|
+
isOpen,
|
|
23
|
+
onTabKeyDown
|
|
22
24
|
}));
|
|
23
25
|
</script>
|
|
24
26
|
|
|
@@ -11,6 +11,7 @@ declare const __VLS_export: import("vue").DefineComponent<import("vue").ExtractP
|
|
|
11
11
|
openIndexes: import("vue").Ref<number[], number[]>;
|
|
12
12
|
toggleItem: (index: number) => void;
|
|
13
13
|
isOpen: (index: number) => boolean;
|
|
14
|
+
onTabKeyDown: (e: KeyboardEvent, index: number) => number | void;
|
|
14
15
|
}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
|
|
15
16
|
"update:modelValue": (value: string | number) => any;
|
|
16
17
|
change: (value: string | number) => any;
|
|
@@ -24,4 +24,5 @@ export declare function useKTabsLogic(props?: KTabsProps, emit?: KTabsEmits): {
|
|
|
24
24
|
openIndexes: import("vue").Ref<number[], number[]>;
|
|
25
25
|
toggleItem: (index: number) => void;
|
|
26
26
|
isOpen: (index: number) => boolean;
|
|
27
|
+
onTabKeyDown: (e: KeyboardEvent, index: number) => number | void;
|
|
27
28
|
};
|
|
@@ -146,10 +146,41 @@ export function useKTabsLogic(props = {}, emit) {
|
|
|
146
146
|
provide("tabIsControlled", isControlled);
|
|
147
147
|
} catch (e) {
|
|
148
148
|
}
|
|
149
|
+
function onTabKeyDown(e, index) {
|
|
150
|
+
const allItems = items.value.length > 0 ? items.value : registeredItems.value;
|
|
151
|
+
const total = allItems.length;
|
|
152
|
+
if (total <= 1) return;
|
|
153
|
+
let targetIndex = -1;
|
|
154
|
+
switch (e.key) {
|
|
155
|
+
case "ArrowRight":
|
|
156
|
+
e.preventDefault();
|
|
157
|
+
targetIndex = (index + 1) % total;
|
|
158
|
+
break;
|
|
159
|
+
case "ArrowLeft":
|
|
160
|
+
e.preventDefault();
|
|
161
|
+
targetIndex = (index - 1 + total) % total;
|
|
162
|
+
break;
|
|
163
|
+
case "Home":
|
|
164
|
+
e.preventDefault();
|
|
165
|
+
targetIndex = 0;
|
|
166
|
+
break;
|
|
167
|
+
case "End":
|
|
168
|
+
e.preventDefault();
|
|
169
|
+
targetIndex = total - 1;
|
|
170
|
+
break;
|
|
171
|
+
default:
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
if (targetIndex !== -1 && targetIndex !== index) {
|
|
175
|
+
toggleItem(targetIndex);
|
|
176
|
+
return targetIndex;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
149
179
|
return {
|
|
150
180
|
items,
|
|
151
181
|
openIndexes,
|
|
152
182
|
toggleItem,
|
|
153
|
-
isOpen
|
|
183
|
+
isOpen,
|
|
184
|
+
onTabKeyDown
|
|
154
185
|
};
|
|
155
186
|
}
|
|
@@ -6,6 +6,10 @@
|
|
|
6
6
|
ref="internalMenuRef"
|
|
7
7
|
v-click-outside="clickoutside"
|
|
8
8
|
:style="menuStyle"
|
|
9
|
+
role="menu"
|
|
10
|
+
aria-orientation="vertical"
|
|
11
|
+
tabindex="-1"
|
|
12
|
+
@keydown="handleKeydown"
|
|
9
13
|
v-bind="$attrs"
|
|
10
14
|
)
|
|
11
15
|
KPanel.KContextMenu-container(:style="containerStyle")
|
|
@@ -13,7 +17,7 @@
|
|
|
13
17
|
</template>
|
|
14
18
|
|
|
15
19
|
<script lang="ts" setup>
|
|
16
|
-
import { ref, computed, watch, onBeforeUnmount } from 'vue'
|
|
20
|
+
import { ref, computed, watch, nextTick, onBeforeUnmount } from 'vue'
|
|
17
21
|
import KPanel from '../KPanel/KPanel.vue'
|
|
18
22
|
|
|
19
23
|
defineOptions({
|
|
@@ -42,8 +46,78 @@ const containerStyle = computed(() => ({
|
|
|
42
46
|
maxHeight: `${props.menuRect.maxHeight}px`
|
|
43
47
|
}))
|
|
44
48
|
|
|
49
|
+
const getFocusableItems = (): HTMLElement[] => {
|
|
50
|
+
if (!internalMenuRef.value) return []
|
|
51
|
+
return Array.from(
|
|
52
|
+
internalMenuRef.value.querySelectorAll<HTMLElement>(
|
|
53
|
+
'a[href], button:not([disabled]), [role="menuitem"], [tabindex]:not([tabindex="-1"])'
|
|
54
|
+
)
|
|
55
|
+
).filter(el => el.offsetParent !== null)
|
|
56
|
+
}
|
|
57
|
+
|
|
45
58
|
const handleKeydown = (e: KeyboardEvent) => {
|
|
59
|
+
if (!props.open) return
|
|
60
|
+
|
|
61
|
+
if (e.key === 'Escape') {
|
|
62
|
+
e.preventDefault()
|
|
63
|
+
e.stopPropagation()
|
|
64
|
+
props.clickoutside()
|
|
65
|
+
return
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (e.key === 'Tab') {
|
|
69
|
+
e.stopPropagation()
|
|
70
|
+
props.clickoutside()
|
|
71
|
+
return
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const items = getFocusableItems()
|
|
75
|
+
if (items.length === 0) return
|
|
76
|
+
|
|
77
|
+
const activeEl = typeof document !== 'undefined' ? (document.activeElement as HTMLElement) : null
|
|
78
|
+
const currentIndex = activeEl ? items.indexOf(activeEl) : -1
|
|
79
|
+
|
|
80
|
+
switch (e.key) {
|
|
81
|
+
case 'ArrowDown': {
|
|
82
|
+
e.preventDefault()
|
|
83
|
+
e.stopPropagation()
|
|
84
|
+
const nextIndex = currentIndex < items.length - 1 ? currentIndex + 1 : 0
|
|
85
|
+
items[nextIndex]?.focus()
|
|
86
|
+
break
|
|
87
|
+
}
|
|
88
|
+
case 'ArrowUp': {
|
|
89
|
+
e.preventDefault()
|
|
90
|
+
e.stopPropagation()
|
|
91
|
+
const prevIndex = currentIndex > 0 ? currentIndex - 1 : items.length - 1
|
|
92
|
+
items[prevIndex]?.focus()
|
|
93
|
+
break
|
|
94
|
+
}
|
|
95
|
+
case 'Home': {
|
|
96
|
+
e.preventDefault()
|
|
97
|
+
e.stopPropagation()
|
|
98
|
+
items[0]?.focus()
|
|
99
|
+
break
|
|
100
|
+
}
|
|
101
|
+
case 'End': {
|
|
102
|
+
e.preventDefault()
|
|
103
|
+
e.stopPropagation()
|
|
104
|
+
items[items.length - 1]?.focus()
|
|
105
|
+
break
|
|
106
|
+
}
|
|
107
|
+
case ' ': {
|
|
108
|
+
if (activeEl && activeEl.tagName === 'A') {
|
|
109
|
+
e.preventDefault()
|
|
110
|
+
e.stopPropagation()
|
|
111
|
+
activeEl.click()
|
|
112
|
+
}
|
|
113
|
+
break
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const handleWindowKeydown = (e: KeyboardEvent) => {
|
|
46
119
|
if (e.key === 'Escape' && props.open) {
|
|
120
|
+
e.preventDefault()
|
|
47
121
|
props.clickoutside()
|
|
48
122
|
}
|
|
49
123
|
}
|
|
@@ -51,16 +125,24 @@ const handleKeydown = (e: KeyboardEvent) => {
|
|
|
51
125
|
watch(() => props.open, (isOpen) => {
|
|
52
126
|
if (typeof window !== 'undefined') {
|
|
53
127
|
if (isOpen) {
|
|
54
|
-
window.addEventListener('keydown',
|
|
128
|
+
window.addEventListener('keydown', handleWindowKeydown)
|
|
129
|
+
nextTick(() => {
|
|
130
|
+
const items = getFocusableItems()
|
|
131
|
+
if (items.length > 0) {
|
|
132
|
+
items[0].focus()
|
|
133
|
+
} else if (internalMenuRef.value) {
|
|
134
|
+
internalMenuRef.value.focus()
|
|
135
|
+
}
|
|
136
|
+
})
|
|
55
137
|
} else {
|
|
56
|
-
window.removeEventListener('keydown',
|
|
138
|
+
window.removeEventListener('keydown', handleWindowKeydown)
|
|
57
139
|
}
|
|
58
140
|
}
|
|
59
141
|
}, { immediate: true })
|
|
60
142
|
|
|
61
143
|
onBeforeUnmount(() => {
|
|
62
144
|
if (typeof window !== 'undefined') {
|
|
63
|
-
window.removeEventListener('keydown',
|
|
145
|
+
window.removeEventListener('keydown', handleWindowKeydown)
|
|
64
146
|
}
|
|
65
147
|
})
|
|
66
148
|
|
|
@@ -2,6 +2,7 @@ type __VLS_Props = {
|
|
|
2
2
|
items: any[];
|
|
3
3
|
toggleItem: (index: number) => void;
|
|
4
4
|
isOpen: (index: number) => boolean;
|
|
5
|
+
onTabKeyDown?: (e: KeyboardEvent, index: number) => number | void;
|
|
5
6
|
};
|
|
6
7
|
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
7
8
|
declare const _default: typeof __VLS_export;
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
v-for="(item, index) of items"
|
|
11
11
|
:key="index"
|
|
12
12
|
@click="toggleItem(index)"
|
|
13
|
+
@keydown="handleTabKeyDown($event, index)"
|
|
13
14
|
size="small"
|
|
14
15
|
:type="isOpen(index) ? 'primary' : 'default'"
|
|
15
16
|
:class="{ 'is-active': isOpen(index) }"
|
|
@@ -31,12 +32,34 @@ const props = defineProps<{
|
|
|
31
32
|
items: any[]
|
|
32
33
|
toggleItem: (index: number) => void
|
|
33
34
|
isOpen: (index: number) => boolean
|
|
35
|
+
onTabKeyDown?: (e: KeyboardEvent, index: number) => number | void
|
|
34
36
|
}>()
|
|
35
37
|
|
|
36
38
|
const scrollArea = ref<HTMLElement | null>(null)
|
|
37
39
|
const hasOverflow = ref(false)
|
|
38
40
|
let resizeObserver: ResizeObserver | null = null
|
|
39
41
|
|
|
42
|
+
const focusTab = (index: number) => {
|
|
43
|
+
if (!scrollArea.value) return
|
|
44
|
+
const buttons = scrollArea.value.querySelectorAll<HTMLElement>('.k-tab-btn')
|
|
45
|
+
const targetBtn = buttons[index]
|
|
46
|
+
if (targetBtn) {
|
|
47
|
+
targetBtn.focus()
|
|
48
|
+
targetBtn.scrollIntoView({ behavior: 'smooth', block: 'nearest', inline: 'nearest' })
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const handleTabKeyDown = (e: KeyboardEvent, index: number) => {
|
|
53
|
+
if (props.onTabKeyDown) {
|
|
54
|
+
const newIndex = props.onTabKeyDown(e, index)
|
|
55
|
+
if (typeof newIndex === 'number') {
|
|
56
|
+
nextTick(() => {
|
|
57
|
+
focusTab(newIndex)
|
|
58
|
+
})
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
40
63
|
const checkOverflow = () => {
|
|
41
64
|
if (!scrollArea.value) return
|
|
42
65
|
const el = scrollArea.value
|
|
@@ -2,6 +2,7 @@ type __VLS_Props = {
|
|
|
2
2
|
items: any[];
|
|
3
3
|
toggleItem: (index: number) => void;
|
|
4
4
|
isOpen: (index: number) => boolean;
|
|
5
|
+
onTabKeyDown?: (e: KeyboardEvent, index: number) => number | void;
|
|
5
6
|
};
|
|
6
7
|
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
7
8
|
declare const _default: typeof __VLS_export;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@katlux/toolkit",
|
|
3
|
-
"version": "0.1.1-alpha.
|
|
3
|
+
"version": "0.1.1-alpha.117",
|
|
4
4
|
"description": "Core UI toolkit and utilities for the Katlux ecosystem",
|
|
5
5
|
"author": "Katlux",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -9,6 +9,10 @@
|
|
|
9
9
|
},
|
|
10
10
|
"main": "./dist/module.mjs",
|
|
11
11
|
"bin": {
|
|
12
|
+
"@katlux/toolkit": "./bin/cli.mjs",
|
|
13
|
+
"katlux": "./bin/cli.mjs",
|
|
14
|
+
"katlux-toolkit": "./bin/cli.mjs",
|
|
15
|
+
"create-preset": "./bin/create-preset.mjs",
|
|
12
16
|
"katlux-add-ref": "./bin/add-ai-reference.mjs"
|
|
13
17
|
},
|
|
14
18
|
"scripts": {
|