@refraction-ui/astro 0.4.6 → 0.4.8

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.
@@ -131,7 +131,10 @@ function makeState(
131
131
  // ---------------------------------------------------------------------------
132
132
 
133
133
  export function createAppShell(config?: AppShellConfig): AppShellAPI {
134
- const resolved: Required<AppShellConfig> = { ...DEFAULTS, ...config }
134
+ const resolved: Required<AppShellConfig> = {
135
+ ...DEFAULTS,
136
+ ...(config ? Object.fromEntries(Object.entries(config).filter(([_, v]) => v !== undefined)) : {})
137
+ } as Required<AppShellConfig>
135
138
 
136
139
  // Internal mutable state
137
140
  let sidebarOpen = false
@@ -47,7 +47,10 @@ const MAX_WIDTH_CLASSES: Record<AuthShellConfig['maxWidth'] & string, string> =
47
47
  // ---------------------------------------------------------------------------
48
48
 
49
49
  export function createAuthShell(config?: AuthShellConfig): AuthShellAPI {
50
- const resolved: Required<AuthShellConfig> = { ...DEFAULTS, ...config }
50
+ const resolved: Required<AuthShellConfig> = {
51
+ ...DEFAULTS,
52
+ ...(config ? Object.fromEntries(Object.entries(config).filter(([_, v]) => v !== undefined)) : {})
53
+ } as Required<AuthShellConfig>
51
54
 
52
55
  const containerParts: string[] = ['min-h-screen', 'flex', 'w-full']
53
56
 
@@ -67,7 +67,10 @@ const BACKGROUND_CLASSES: Record<NonNullable<SectionConfig['background']>, strin
67
67
  // ---------------------------------------------------------------------------
68
68
 
69
69
  export function createPageShell(config?: PageShellConfig): PageShellAPI {
70
- const resolved: Required<PageShellConfig> = { ...DEFAULTS, ...config }
70
+ const resolved: Required<PageShellConfig> = {
71
+ ...DEFAULTS,
72
+ ...(config ? Object.fromEntries(Object.entries(config).filter(([_, v]) => v !== undefined)) : {})
73
+ } as Required<PageShellConfig>
71
74
 
72
75
  function getSectionClasses(sectionConfig?: SectionConfig): string {
73
76
  const {
@@ -1 +1 @@
1
- export * from './astro-file-tree';
1
+ export { default as FileTree } from './astro-file-tree.astro';
@@ -1 +1 @@
1
- export * from './astro-icon-system';
1
+ export { default as IconSystem } from './astro-icon-system.astro';
@@ -1 +1,2 @@
1
- export {}
1
+ export { default as ThemeScript } from './ThemeScript.astro'
2
+ export { default as ThemeToggle } from './ThemeToggle.astro'
@@ -1 +1 @@
1
- export * from './callout';
1
+ export * from './callout.ts';
@@ -1 +1 @@
1
- export * from './card-grid.js'
1
+ export * from './card-grid.ts'
@@ -1 +1 @@
1
- export * from './code-block';
1
+ export * from './code-block.ts';
@@ -1 +1 @@
1
- export * from './command-input'
1
+ export * from './command-input.ts'
@@ -90,23 +90,23 @@ export function createDropdownMenu(props: DropdownMenuProps = {}): DropdownMenuA
90
90
  }
91
91
 
92
92
  const keyboardHandlers: KeyboardHandlerMap = {
93
- [Keys.Escape]: (e) => {
93
+ [Keys.Escape]: (e: KeyboardEvent) => {
94
94
  e.preventDefault()
95
95
  closeMenu()
96
96
  },
97
- [Keys.ArrowDown]: (e) => {
97
+ [Keys.ArrowDown]: (e: KeyboardEvent) => {
98
98
  e.preventDefault()
99
99
  },
100
- [Keys.ArrowUp]: (e) => {
100
+ [Keys.ArrowUp]: (e: KeyboardEvent) => {
101
101
  e.preventDefault()
102
102
  },
103
- [Keys.Enter]: (e) => {
103
+ [Keys.Enter]: (e: KeyboardEvent) => {
104
104
  e.preventDefault()
105
105
  },
106
- [Keys.Home]: (e) => {
106
+ [Keys.Home]: (e: KeyboardEvent) => {
107
107
  e.preventDefault()
108
108
  },
109
- [Keys.End]: (e) => {
109
+ [Keys.End]: (e: KeyboardEvent) => {
110
110
  e.preventDefault()
111
111
  },
112
112
  }
@@ -3,6 +3,11 @@ export {
3
3
  formatShortcut,
4
4
  type ShortcutProps,
5
5
  type KeyboardShortcutAPI,
6
+ SANE_DEFAULTS,
7
+ globalShortcutRegistry,
8
+ ShortcutRegistry,
9
+ altHintState,
10
+ AltHintState,
6
11
  } from './keyboard-shortcut.js'
7
12
 
8
13
  export {
@@ -1,5 +1,3 @@
1
- import type { AccessibilityProps } from '../shared/index.ts'
2
-
3
1
  export interface ShortcutProps {
4
2
  /** Key combination (e.g., ['Ctrl', 'K'] or ['Meta', 'Shift', 'P']) */
5
3
  keys: string[]
@@ -151,3 +149,90 @@ export function createKeyboardShortcut(props: ShortcutProps): KeyboardShortcutAP
151
149
  badgeAriaProps,
152
150
  }
153
151
  }
152
+
153
+ export const SANE_DEFAULTS: Record<string, string[]> = {
154
+ save: ['Meta', 's'],
155
+ search: ['Meta', 'k'],
156
+ close: ['Escape'],
157
+ submit: ['Meta', 'Enter'],
158
+ undo: ['Meta', 'z'],
159
+ redo: ['Meta', 'Shift', 'z'],
160
+ copy: ['Meta', 'c'],
161
+ paste: ['Meta', 'v'],
162
+ cut: ['Meta', 'x'],
163
+ new: ['Meta', 'n'],
164
+ print: ['Meta', 'p'],
165
+ help: ['?'],
166
+ };
167
+
168
+ export class ShortcutRegistry {
169
+ private shortcuts: Map<string, () => void> = new Map();
170
+
171
+ register(keys: string[], handler: () => void) {
172
+ const keyStr = keys.map(k => k.toLowerCase()).sort().join('+');
173
+ if (this.shortcuts.has(keyStr)) {
174
+ console.warn(`Shortcut ${keyStr} is already registered.`);
175
+ }
176
+ this.shortcuts.set(keyStr, handler);
177
+ }
178
+
179
+ unregister(keys: string[]) {
180
+ const keyStr = keys.map(k => k.toLowerCase()).sort().join('+');
181
+ this.shortcuts.delete(keyStr);
182
+ }
183
+ }
184
+
185
+ export const globalShortcutRegistry = new ShortcutRegistry();
186
+
187
+ export class AltHintState {
188
+ private showHints = false;
189
+ private listeners: Set<(show: boolean) => void> = new Set();
190
+ private initialized = false;
191
+
192
+ init() {
193
+ if (this.initialized || typeof window === 'undefined') return;
194
+ this.initialized = true;
195
+
196
+ const handleKeyDown = (e: KeyboardEvent) => {
197
+ if (e.key === 'Alt') {
198
+ this.setShowHints(true);
199
+ }
200
+ };
201
+
202
+ const handleKeyUp = (e: KeyboardEvent) => {
203
+ if (e.key === 'Alt') {
204
+ this.setShowHints(false);
205
+ }
206
+ };
207
+
208
+ const handleBlur = () => {
209
+ this.setShowHints(false);
210
+ };
211
+
212
+ window.addEventListener('keydown', handleKeyDown);
213
+ window.addEventListener('keyup', handleKeyUp);
214
+ window.addEventListener('blur', handleBlur);
215
+ }
216
+
217
+ private setShowHints(value: boolean) {
218
+ if (this.showHints !== value) {
219
+ this.showHints = value;
220
+ this.listeners.forEach((listener) => listener(value));
221
+ }
222
+ }
223
+
224
+ subscribe(listener: (show: boolean) => void) {
225
+ this.listeners.add(listener);
226
+ listener(this.showHints);
227
+ return () => {
228
+ this.listeners.delete(listener);
229
+ };
230
+ }
231
+
232
+ get snapshot() {
233
+ return this.showHints;
234
+ }
235
+ }
236
+
237
+ export const altHintState = new AltHintState();
238
+
@@ -1 +1 @@
1
- export * from './link-card.js'
1
+ export * from './link-card.ts'
@@ -1 +1 @@
1
- export * from './payment.js';
1
+ export * from './payment.ts';
@@ -1 +1 @@
1
- export * from './skip-to-content';
1
+ export * from './skip-to-content.ts';
@@ -1 +1 @@
1
- export * from './slider.js'
1
+ export * from './slider.ts'
@@ -1 +1 @@
1
- export * from './steps';
1
+ export * from './steps.ts';
@@ -1 +1 @@
1
- export * from './table-of-contents'
1
+ export * from './table-of-contents.ts'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@refraction-ui/astro",
3
- "version": "0.4.6",
3
+ "version": "0.4.8",
4
4
  "description": "All Refraction UI Astro components in one package",
5
5
  "type": "module",
6
6
  "exports": {