@adea-ai/app-framework 0.29.3 → 0.31.0
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/README.md +6 -3
- package/dist/app/application.js +4 -2
- package/dist/app/create-application.d.ts +2 -0
- package/dist/app/create-application.js +6 -0
- package/dist/appearance/appearance-host.js +6 -0
- package/dist/appearance/appearance-preferences.js +6 -2
- package/dist/appearance/composition.d.ts +1 -1
- package/dist/appearance/custom-theme-import.js +12 -19
- package/dist/appearance/custom-theme-library.d.ts +5 -4
- package/dist/appearance/custom-theme-library.js +20 -2
- package/dist/appearance/editor.js +4 -1
- package/dist/appearance/legacy-imported-theme-token-projection.d.ts +84 -0
- package/dist/appearance/legacy-imported-theme-token-projection.js +142 -0
- package/dist/appearance/theme-record-adapter.js +37 -9
- package/dist/cli/create-application-cli.js +6 -4
- package/dist/framework-source.json +1 -1
- package/dist/shell/app-shell.js +76 -48
- package/dist/shell/app-utilities.d.ts +5 -3
- package/dist/shell/app-utilities.js +15 -7
- package/dist/shell/help-shortcuts.d.ts +4 -0
- package/dist/shell/help-shortcuts.js +38 -7
- package/dist/shell/keyboard-target.d.ts +2 -0
- package/dist/shell/keyboard-target.js +54 -0
- package/dist/shell/settings-sections.d.ts +5 -0
- package/dist/shell/settings-shortcuts.d.ts +10 -0
- package/dist/shell/settings-shortcuts.js +67 -0
- package/dist/views/app-help.js +2 -1
- package/dist/views/app-settings.js +5 -2
- package/dist/views/appearance-surface.js +33 -19
- package/package.json +6 -4
- package/src/app/application.tsx +3 -1
- package/src/appearance/appearance-host.tsx +6 -0
- package/src/appearance/appearance-preferences.ts +7 -1
- package/src/appearance/composition.ts +3 -1
- package/src/appearance/custom-theme-import.ts +21 -37
- package/src/appearance/custom-theme-library.ts +21 -5
- package/src/appearance/editor.ts +7 -6
- package/src/appearance/legacy-imported-theme-token-projection.ts +51 -0
- package/src/appearance/theme-record-adapter.ts +58 -11
- package/src/shell/app-shell.tsx +88 -58
- package/src/shell/app-utilities.tsx +29 -17
- package/src/shell/help-shortcuts.ts +77 -6
- package/src/shell/keyboard-target.ts +74 -0
- package/src/shell/settings-sections.ts +5 -0
- package/src/shell/settings-shortcuts.ts +116 -0
- package/src/views/app-settings.tsx +5 -3
- package/src/views/appearance-surface.tsx +63 -27
- package/templates/application/.gitlab-ci.yml +19 -0
- package/templates/application/README.md +9 -0
package/src/shell/app-shell.tsx
CHANGED
|
@@ -16,15 +16,18 @@ import { SideRailItem, SideRailSection } from '@adea-ai/ui/components/layout/sid
|
|
|
16
16
|
import { ActionButton } from '@adea-ai/ui/components/composites/action-button'
|
|
17
17
|
import { TooltipProvider } from '@adea-ai/ui/components/ui/tooltip'
|
|
18
18
|
import { PanelLeftClose, PanelLeftIcon, PanelLeftOpen } from 'lucide-solid'
|
|
19
|
+
import { hasEditableKeyboardTarget } from './keyboard-target'
|
|
19
20
|
import {
|
|
20
21
|
For,
|
|
21
22
|
Show,
|
|
22
23
|
Suspense,
|
|
24
|
+
createComputed,
|
|
23
25
|
createEffect,
|
|
24
26
|
createSignal,
|
|
25
27
|
lazy,
|
|
26
28
|
onCleanup,
|
|
27
29
|
onMount,
|
|
30
|
+
untrack,
|
|
28
31
|
type JSX,
|
|
29
32
|
} from 'solid-js'
|
|
30
33
|
|
|
@@ -100,60 +103,13 @@ function createNarrow(query: () => string | undefined) {
|
|
|
100
103
|
return narrow
|
|
101
104
|
}
|
|
102
105
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
'
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
'hidden',
|
|
109
|
-
'image',
|
|
110
|
-
'radio',
|
|
111
|
-
'range',
|
|
112
|
-
'reset',
|
|
113
|
-
'submit',
|
|
114
|
-
])
|
|
115
|
-
|
|
116
|
-
/** Whether an element or an ancestor in its composed path accepts text editing. */
|
|
117
|
-
function isEditableElementPath(path: readonly EventTarget[]) {
|
|
118
|
-
let inheritedEditable = false
|
|
119
|
-
for (const target of path) {
|
|
120
|
-
if (!(target instanceof Element)) continue
|
|
121
|
-
|
|
122
|
-
if (target instanceof HTMLInputElement) {
|
|
123
|
-
if (!target.disabled && !target.readOnly && !nonTextInputTypes.has(target.type)) return true
|
|
124
|
-
} else if (target instanceof HTMLTextAreaElement) {
|
|
125
|
-
if (!target.disabled && !target.readOnly) return true
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
const contentEditable = target.getAttribute('contenteditable')?.toLowerCase()
|
|
129
|
-
if (contentEditable === 'false') return false
|
|
130
|
-
if (
|
|
131
|
-
contentEditable === '' ||
|
|
132
|
-
contentEditable === 'true' ||
|
|
133
|
-
contentEditable === 'plaintext-only'
|
|
134
|
-
)
|
|
135
|
-
return true
|
|
136
|
-
|
|
137
|
-
if (target instanceof HTMLElement && target.isContentEditable) inheritedEditable = true
|
|
138
|
-
if (target.ownerDocument.designMode?.toLowerCase() === 'on') inheritedEditable = true
|
|
106
|
+
function getSidebarResponsiveMode(sidebar: ContextualSidebarProps | undefined) {
|
|
107
|
+
// `responsiveMode` was added after the oldest UI versions supported by Framework.
|
|
108
|
+
if (sidebar && 'responsiveMode' in sidebar) {
|
|
109
|
+
const mode = sidebar.responsiveMode
|
|
110
|
+
if (mode === 'auto' || mode === 'desktop' || mode === 'mobile') return mode
|
|
139
111
|
}
|
|
140
|
-
|
|
141
|
-
return inheritedEditable
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
function hasEditableTarget(event: KeyboardEvent) {
|
|
145
|
-
const path = event.composedPath()
|
|
146
|
-
if (path.some((target) => target instanceof Element)) return isEditableElementPath(path)
|
|
147
|
-
|
|
148
|
-
// Synthetic events dispatched at window have no element in their path; use the
|
|
149
|
-
// focused element, following open shadow roots where the browser exposes them.
|
|
150
|
-
const activePath: EventTarget[] = []
|
|
151
|
-
let activeElement: Element | null = document.activeElement
|
|
152
|
-
while (activeElement) {
|
|
153
|
-
activePath.push(activeElement)
|
|
154
|
-
activeElement = activeElement.shadowRoot?.activeElement ?? null
|
|
155
|
-
}
|
|
156
|
-
return isEditableElementPath(activePath)
|
|
112
|
+
return undefined
|
|
157
113
|
}
|
|
158
114
|
|
|
159
115
|
/** Shared chrome and navigation composition; applications own routes and services. */
|
|
@@ -165,6 +121,77 @@ export function ApplicationShell(props: ApplicationShellProps) {
|
|
|
165
121
|
const sidebarMobile = createNarrow(() =>
|
|
166
122
|
!props.drawer && props.sidebar ? '(max-width: 48rem)' : undefined
|
|
167
123
|
)
|
|
124
|
+
const [sidebarElementMobile, setSidebarElementMobile] = createSignal<boolean>()
|
|
125
|
+
// The shared callback's cleanup supplies the mode but not the detached element.
|
|
126
|
+
const sidebarElements = new Map<boolean, HTMLElement>()
|
|
127
|
+
const sidebarElementCallbacks = new Map<boolean, ContextualSidebarProps['onSidebarElement']>()
|
|
128
|
+
createEffect(() => {
|
|
129
|
+
const nextCallback = props.sidebar?.onSidebarElement
|
|
130
|
+
for (const [mobile, element] of sidebarElements) {
|
|
131
|
+
const previousCallback = sidebarElementCallbacks.get(mobile)
|
|
132
|
+
if (previousCallback === nextCallback) continue
|
|
133
|
+
previousCallback?.(undefined, mobile)
|
|
134
|
+
nextCallback?.(element, mobile)
|
|
135
|
+
sidebarElementCallbacks.set(mobile, nextCallback)
|
|
136
|
+
}
|
|
137
|
+
})
|
|
138
|
+
const isSidebarMobile = () => {
|
|
139
|
+
const mountedMode = sidebarElementMobile()
|
|
140
|
+
if (mountedMode !== undefined) return mountedMode
|
|
141
|
+
const mode = getSidebarResponsiveMode(props.sidebar)
|
|
142
|
+
if (mode === 'mobile') return true
|
|
143
|
+
if (mode === 'desktop') return false
|
|
144
|
+
return sidebarMobile()
|
|
145
|
+
}
|
|
146
|
+
const restoreSidebarFocus = (sidebar: HTMLElement | undefined) => {
|
|
147
|
+
const active = sidebar?.ownerDocument.activeElement
|
|
148
|
+
if (
|
|
149
|
+
!props.sidebar ||
|
|
150
|
+
sidebar?.dataset.open !== 'true' ||
|
|
151
|
+
!sidebar.isConnected ||
|
|
152
|
+
!active ||
|
|
153
|
+
!sidebar.contains(active)
|
|
154
|
+
)
|
|
155
|
+
return
|
|
156
|
+
const target = props.sidebar.restoreFocusRef ? props.sidebar.restoreFocusRef() : sidebarToggle
|
|
157
|
+
if (target?.isConnected) target.focus({ preventScroll: true })
|
|
158
|
+
}
|
|
159
|
+
let requestedModeInitialized = false
|
|
160
|
+
let previousRequestedMode: ReturnType<typeof getSidebarResponsiveMode>
|
|
161
|
+
createComputed(() => {
|
|
162
|
+
const next = getSidebarResponsiveMode(props.sidebar)
|
|
163
|
+
const shouldRestore =
|
|
164
|
+
requestedModeInitialized && next === 'mobile' && previousRequestedMode !== 'mobile'
|
|
165
|
+
previousRequestedMode = next
|
|
166
|
+
requestedModeInitialized = true
|
|
167
|
+
if (shouldRestore) untrack(() => restoreSidebarFocus(sidebarElements.get(false)))
|
|
168
|
+
})
|
|
169
|
+
const handleSidebarModeTransition: NonNullable<
|
|
170
|
+
ContextualSidebarProps['onResponsiveModeTransition']
|
|
171
|
+
> = (event) => {
|
|
172
|
+
props.sidebar?.onResponsiveModeTransition?.(event)
|
|
173
|
+
if (event.phase === 'before' && event.from === 'desktop' && event.to === 'mobile')
|
|
174
|
+
restoreSidebarFocus(event.desktopSidebar)
|
|
175
|
+
}
|
|
176
|
+
const handleSidebarElement: NonNullable<ContextualSidebarProps['onSidebarElement']> = (
|
|
177
|
+
element,
|
|
178
|
+
mobile
|
|
179
|
+
) => {
|
|
180
|
+
if (element) {
|
|
181
|
+
sidebarElements.set(mobile, element)
|
|
182
|
+
const callback = props.sidebar?.onSidebarElement
|
|
183
|
+
sidebarElementCallbacks.set(mobile, callback)
|
|
184
|
+
setSidebarElementMobile(mobile)
|
|
185
|
+
callback?.(element, mobile)
|
|
186
|
+
return
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const callback = sidebarElementCallbacks.get(mobile)
|
|
190
|
+
sidebarElements.delete(mobile)
|
|
191
|
+
sidebarElementCallbacks.delete(mobile)
|
|
192
|
+
setSidebarElementMobile(undefined)
|
|
193
|
+
callback?.(undefined, mobile)
|
|
194
|
+
}
|
|
168
195
|
const [drawerOpen, setDrawerOpen] = createSignal(false)
|
|
169
196
|
// The drawer mounts (and its chunk loads) the first time the window is narrow, and
|
|
170
197
|
// stays mounted after that so its close animation and focus return keep working.
|
|
@@ -194,11 +221,11 @@ export function ApplicationShell(props: ApplicationShellProps) {
|
|
|
194
221
|
event.altKey ||
|
|
195
222
|
event.shiftKey ||
|
|
196
223
|
event.key.toLowerCase() !== 'b' ||
|
|
197
|
-
|
|
224
|
+
hasEditableKeyboardTarget(event)
|
|
198
225
|
)
|
|
199
226
|
return
|
|
200
227
|
event.preventDefault()
|
|
201
|
-
toggle()
|
|
228
|
+
if (!event.repeat) toggle()
|
|
202
229
|
}
|
|
203
230
|
const handleSearch = (event: KeyboardEvent) => {
|
|
204
231
|
if (
|
|
@@ -211,7 +238,7 @@ export function ApplicationShell(props: ApplicationShellProps) {
|
|
|
211
238
|
)
|
|
212
239
|
return
|
|
213
240
|
event.preventDefault()
|
|
214
|
-
props.onSearch()
|
|
241
|
+
if (!event.repeat) props.onSearch()
|
|
215
242
|
}
|
|
216
243
|
onMount(() => {
|
|
217
244
|
window.addEventListener('keydown', handleSearch)
|
|
@@ -229,7 +256,8 @@ export function ApplicationShell(props: ApplicationShellProps) {
|
|
|
229
256
|
aria-label={`${props.name} toolbar`}
|
|
230
257
|
navigation={props.navigation}
|
|
231
258
|
workspace={props.workspace}
|
|
232
|
-
sidebarOpen={!narrow() && leading()?.open}
|
|
259
|
+
sidebarOpen={!narrow() && leading()?.open && !isSidebarMobile()}
|
|
260
|
+
alignSidebarAtNarrow={getSidebarResponsiveMode(props.sidebar) === 'desktop'}
|
|
233
261
|
sidebarWidth={leading()?.width}
|
|
234
262
|
breadcrumb={props.title}
|
|
235
263
|
search={props.search}
|
|
@@ -306,12 +334,14 @@ export function ApplicationShell(props: ApplicationShellProps) {
|
|
|
306
334
|
{(sidebar) => (
|
|
307
335
|
<PixelPane
|
|
308
336
|
class="overflow-visible"
|
|
309
|
-
hidden={narrow() ||
|
|
337
|
+
hidden={narrow() || isSidebarMobile()}
|
|
310
338
|
width={sidebar().open ? sidebar().width : 0}
|
|
311
339
|
>
|
|
312
340
|
<Show when={!props.drawer || !narrow()}>
|
|
313
341
|
<ContextualSidebar
|
|
314
342
|
{...sidebar()}
|
|
343
|
+
onSidebarElement={handleSidebarElement}
|
|
344
|
+
onResponsiveModeTransition={handleSidebarModeTransition}
|
|
315
345
|
restoreFocusRef={sidebar().restoreFocusRef ?? (() => sidebarToggle)}
|
|
316
346
|
/>
|
|
317
347
|
</Show>
|
|
@@ -18,13 +18,15 @@ import {
|
|
|
18
18
|
Suspense,
|
|
19
19
|
type JSX,
|
|
20
20
|
} from 'solid-js'
|
|
21
|
-
import type
|
|
21
|
+
import { DEFAULT_SETTINGS_KEYSHORTCUTS, type HelpLink, type HelpShortcut } from './help-shortcuts'
|
|
22
|
+
import { matchesSettingsKeyshortcuts, parseSettingsKeyshortcuts } from './settings-shortcuts'
|
|
22
23
|
import {
|
|
23
24
|
defineSettingsSections,
|
|
24
25
|
settingsSectionFromHash,
|
|
25
26
|
type ApplicationSettingsSection,
|
|
26
27
|
} from './settings-sections'
|
|
27
28
|
import { resolveShortcutPlatform, type ShortcutPlatform } from './shortcut-platform'
|
|
29
|
+
import { hasEditableKeyboardTarget } from './keyboard-target'
|
|
28
30
|
import { browserUpdateAdapter, type UpdateChannelSource } from '../updates/update-adapter'
|
|
29
31
|
|
|
30
32
|
export * from './shortcut-platform'
|
|
@@ -110,8 +112,10 @@ export type ApplicationHelpConfig = Readonly<{
|
|
|
110
112
|
links: readonly HelpLink[]
|
|
111
113
|
/** App-specific shortcuts, listed before the ones the framework binds. */
|
|
112
114
|
shortcuts?: readonly HelpShortcut[]
|
|
113
|
-
/** Whether
|
|
115
|
+
/** Whether Help lists Open search; defaults to whether the Application binds it. */
|
|
114
116
|
search?: boolean
|
|
117
|
+
/** Whether the enclosing Application shell consumes Meta/Ctrl+K despite hiding its help row. */
|
|
118
|
+
searchBinding?: boolean
|
|
115
119
|
}>
|
|
116
120
|
|
|
117
121
|
export type ApplicationAccountMenuConfig = Readonly<{
|
|
@@ -123,7 +127,7 @@ export type ApplicationAccountMenuConfig = Readonly<{
|
|
|
123
127
|
onIntent?(): void
|
|
124
128
|
/** A chord drawn on the Settings row, e.g. `settingsShortcutLabel('mac')`. */
|
|
125
129
|
settingsShortcut?: string
|
|
126
|
-
/**
|
|
130
|
+
/** Space-separated ARIA chords behind `settingsShortcut`; defaults to `Meta+, Control+,`. */
|
|
127
131
|
settingsKeyshortcuts?: string
|
|
128
132
|
/** Show the Appearance item (the default). Apps with their own control can hide it. */
|
|
129
133
|
appearance?: boolean
|
|
@@ -168,18 +172,6 @@ export type ApplicationUtilitiesProps = {
|
|
|
168
172
|
}
|
|
169
173
|
|
|
170
174
|
const appearanceSectionId = 'appearance'
|
|
171
|
-
const settingsKeyshortcuts = 'Meta+, Control+,'
|
|
172
|
-
|
|
173
|
-
function isSettingsChord(event: KeyboardEvent) {
|
|
174
|
-
return (
|
|
175
|
-
!event.defaultPrevented &&
|
|
176
|
-
(event.metaKey || event.ctrlKey) &&
|
|
177
|
-
!event.altKey &&
|
|
178
|
-
!event.shiftKey &&
|
|
179
|
-
event.key === ','
|
|
180
|
-
)
|
|
181
|
-
}
|
|
182
|
-
|
|
183
175
|
function placeAppearance(
|
|
184
176
|
sections: readonly ApplicationSettingsSection[],
|
|
185
177
|
appearance: ApplicationSettingsSection,
|
|
@@ -299,8 +291,22 @@ export function ApplicationUtilities(props: ApplicationUtilitiesProps) {
|
|
|
299
291
|
openUpdates: () => openUpdates(),
|
|
300
292
|
})
|
|
301
293
|
)
|
|
294
|
+
const settingsKeyshortcuts = createMemo(() => {
|
|
295
|
+
const value = props.accountMenu?.settingsKeyshortcuts ?? DEFAULT_SETTINGS_KEYSHORTCUTS
|
|
296
|
+
return { value, chords: parseSettingsKeyshortcuts(value) }
|
|
297
|
+
})
|
|
302
298
|
const onKeyDown = (event: KeyboardEvent) => {
|
|
303
|
-
|
|
299
|
+
const { value, chords } = settingsKeyshortcuts()
|
|
300
|
+
if (
|
|
301
|
+
!props.settings ||
|
|
302
|
+
!matchesSettingsKeyshortcuts(
|
|
303
|
+
event,
|
|
304
|
+
chords,
|
|
305
|
+
value === DEFAULT_SETTINGS_KEYSHORTCUTS,
|
|
306
|
+
hasEditableKeyboardTarget
|
|
307
|
+
)
|
|
308
|
+
)
|
|
309
|
+
return
|
|
304
310
|
event.preventDefault()
|
|
305
311
|
if (!event.repeat) openSettings()
|
|
306
312
|
}
|
|
@@ -337,7 +343,10 @@ export function ApplicationUtilities(props: ApplicationUtilitiesProps) {
|
|
|
337
343
|
onFeedback: props.onFeedback,
|
|
338
344
|
}).map((item) => {
|
|
339
345
|
if (item.id === 'settings' && item.shortcut)
|
|
340
|
-
return {
|
|
346
|
+
return {
|
|
347
|
+
...item,
|
|
348
|
+
keyshortcuts: menu?.settingsKeyshortcuts ?? DEFAULT_SETTINGS_KEYSHORTCUTS,
|
|
349
|
+
}
|
|
341
350
|
if (item.id === 'updates' && updatesAlways()) return { ...item, platform: undefined }
|
|
342
351
|
return item
|
|
343
352
|
})
|
|
@@ -401,7 +410,10 @@ export function ApplicationUtilities(props: ApplicationUtilitiesProps) {
|
|
|
401
410
|
shortcuts={help().shortcuts ?? []}
|
|
402
411
|
standard={{
|
|
403
412
|
search: help().search,
|
|
413
|
+
searchBinding: help().searchBinding,
|
|
404
414
|
settings: Boolean(props.settings),
|
|
415
|
+
settingsKeyshortcuts:
|
|
416
|
+
props.accountMenu?.settingsKeyshortcuts ?? DEFAULT_SETTINGS_KEYSHORTCUTS,
|
|
405
417
|
shortcutPlatform: resolveShortcutPlatform(props.identity),
|
|
406
418
|
}}
|
|
407
419
|
links={help().links}
|
|
@@ -1,24 +1,95 @@
|
|
|
1
1
|
import type { HelpLink, HelpShortcut } from '@adea-ai/ui/components/composites/help-center'
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import {
|
|
3
|
+
resolveShortcutPlatform,
|
|
4
|
+
shortcutModifierKey,
|
|
5
|
+
type ShortcutPlatform,
|
|
6
|
+
} from './shortcut-platform'
|
|
7
|
+
import { DEFAULT_SETTINGS_KEYSHORTCUTS, parseSettingsKeyshortcuts } from './settings-shortcuts'
|
|
4
8
|
|
|
5
9
|
export type { HelpLink, HelpShortcut }
|
|
6
10
|
|
|
11
|
+
function shortcutKeyLabel(key: string) {
|
|
12
|
+
if (key === 'Space') return 'Space'
|
|
13
|
+
if (key === 'Plus') return '+'
|
|
14
|
+
return /^[a-z]$/i.test(key) ? key.toUpperCase() : key
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function modifierKeyLabel(modifier: string, platform: ShortcutPlatform) {
|
|
18
|
+
switch (modifier) {
|
|
19
|
+
case 'Meta':
|
|
20
|
+
return platform === 'mac' ? shortcutModifierKey(platform) : 'Meta'
|
|
21
|
+
case 'Control':
|
|
22
|
+
return 'Ctrl'
|
|
23
|
+
case 'Alt':
|
|
24
|
+
return platform === 'mac' ? '⌥' : 'Alt'
|
|
25
|
+
case 'Shift':
|
|
26
|
+
return platform === 'mac' ? '⇧' : 'Shift'
|
|
27
|
+
case 'AltGraph':
|
|
28
|
+
return 'AltGr'
|
|
29
|
+
case 'FnLock':
|
|
30
|
+
return 'Fn Lock'
|
|
31
|
+
case 'NumLock':
|
|
32
|
+
return 'Num Lock'
|
|
33
|
+
case 'ScrollLock':
|
|
34
|
+
return 'Scroll Lock'
|
|
35
|
+
case 'SymbolLock':
|
|
36
|
+
return 'Symbol Lock'
|
|
37
|
+
default:
|
|
38
|
+
return modifier
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function settingsShortcuts(
|
|
43
|
+
keyshortcuts: string,
|
|
44
|
+
platform: ShortcutPlatform,
|
|
45
|
+
searchBinding: boolean
|
|
46
|
+
) {
|
|
47
|
+
const seen = new Set<string>()
|
|
48
|
+
return parseSettingsKeyshortcuts(keyshortcuts).flatMap(({ key, modifiers }) => {
|
|
49
|
+
const conflictsWithSearch =
|
|
50
|
+
key.toLowerCase() === 'k' &&
|
|
51
|
+
searchBinding &&
|
|
52
|
+
modifiers.some((modifier) => modifier === 'Meta' || modifier === 'Control') &&
|
|
53
|
+
!modifiers.includes('Alt') &&
|
|
54
|
+
!modifiers.includes('Shift')
|
|
55
|
+
if (conflictsWithSearch) return []
|
|
56
|
+
|
|
57
|
+
const keys = [
|
|
58
|
+
...modifiers.map((modifier) => modifierKeyLabel(modifier, platform)),
|
|
59
|
+
shortcutKeyLabel(key),
|
|
60
|
+
]
|
|
61
|
+
// Modifier order does not affect matching; keep the first spelling for display.
|
|
62
|
+
const identity = JSON.stringify([modifiers.toSorted(), shortcutKeyLabel(key)])
|
|
63
|
+
if (seen.has(identity)) return []
|
|
64
|
+
seen.add(identity)
|
|
65
|
+
return [{ label: 'Open settings', keys }]
|
|
66
|
+
})
|
|
67
|
+
}
|
|
68
|
+
|
|
7
69
|
/** Shortcuts the framework binds itself, drawn with the running platform's modifier. */
|
|
8
70
|
export function standardShortcuts(options: {
|
|
9
71
|
search?: boolean
|
|
72
|
+
/** Whether the enclosing application shell actually consumes its search chord. */
|
|
73
|
+
searchBinding?: boolean
|
|
10
74
|
settings?: boolean
|
|
75
|
+
settingsKeyshortcuts?: string
|
|
11
76
|
/** A navigator-style platform string; ignored when `shortcutPlatform` is supplied. */
|
|
12
77
|
platform?: string
|
|
13
78
|
shortcutPlatform?: ShortcutPlatform
|
|
14
79
|
}): HelpShortcut[] {
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
: platformModifierKey(options.platform)
|
|
80
|
+
const platform = resolveShortcutPlatform(options)
|
|
81
|
+
const mod = shortcutModifierKey(platform)
|
|
18
82
|
return [
|
|
19
83
|
...(options.search ? [{ label: 'Open search', keys: [mod, 'K'] }] : []),
|
|
20
|
-
...(options.settings
|
|
84
|
+
...(options.settings
|
|
85
|
+
? settingsShortcuts(
|
|
86
|
+
options.settingsKeyshortcuts ?? DEFAULT_SETTINGS_KEYSHORTCUTS,
|
|
87
|
+
platform,
|
|
88
|
+
options.searchBinding ?? Boolean(options.search)
|
|
89
|
+
)
|
|
90
|
+
: []),
|
|
21
91
|
{ label: 'Close panels and dialogs', keys: ['Esc'] },
|
|
22
92
|
]
|
|
23
93
|
}
|
|
94
|
+
export { DEFAULT_SETTINGS_KEYSHORTCUTS } from './settings-shortcuts'
|
|
24
95
|
export * from './shortcut-platform'
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
const nonTextInputTypes = new Set([
|
|
2
|
+
'button',
|
|
3
|
+
'checkbox',
|
|
4
|
+
'color',
|
|
5
|
+
'file',
|
|
6
|
+
'hidden',
|
|
7
|
+
'image',
|
|
8
|
+
'radio',
|
|
9
|
+
'range',
|
|
10
|
+
'reset',
|
|
11
|
+
'submit',
|
|
12
|
+
])
|
|
13
|
+
|
|
14
|
+
const textEntryRoles = new Set(['combobox', 'searchbox', 'spinbutton', 'textbox'])
|
|
15
|
+
|
|
16
|
+
/** Whether an element or an ancestor in its composed path accepts text editing. */
|
|
17
|
+
function isEditableElementPath(path: readonly EventTarget[]) {
|
|
18
|
+
let inheritedEditable = false
|
|
19
|
+
for (const target of path) {
|
|
20
|
+
if (!(target instanceof Element)) continue
|
|
21
|
+
|
|
22
|
+
if (target instanceof HTMLInputElement) {
|
|
23
|
+
if (!target.disabled && !target.readOnly && !nonTextInputTypes.has(target.type)) return true
|
|
24
|
+
} else if (target instanceof HTMLTextAreaElement) {
|
|
25
|
+
if (!target.disabled && !target.readOnly) return true
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const contentEditable = target.getAttribute('contenteditable')?.toLowerCase()
|
|
29
|
+
if (contentEditable === 'false') return false
|
|
30
|
+
if (
|
|
31
|
+
contentEditable === '' ||
|
|
32
|
+
contentEditable === 'true' ||
|
|
33
|
+
contentEditable === 'plaintext-only'
|
|
34
|
+
)
|
|
35
|
+
return true
|
|
36
|
+
|
|
37
|
+
const role = target.getAttribute('role')?.trim().toLowerCase().split(/\s+/)[0]
|
|
38
|
+
if (
|
|
39
|
+
role &&
|
|
40
|
+
textEntryRoles.has(role) &&
|
|
41
|
+
target.getAttribute('aria-readonly')?.toLowerCase() !== 'true' &&
|
|
42
|
+
target.getAttribute('aria-disabled')?.toLowerCase() !== 'true'
|
|
43
|
+
)
|
|
44
|
+
return true
|
|
45
|
+
|
|
46
|
+
if (target instanceof HTMLElement && target.isContentEditable) inheritedEditable = true
|
|
47
|
+
if (target.ownerDocument.designMode?.toLowerCase() === 'on') inheritedEditable = true
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return inheritedEditable
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Whether a keyboard event originated in a control that accepts text editing. */
|
|
54
|
+
export function hasEditableKeyboardTarget(event: KeyboardEvent) {
|
|
55
|
+
const path = event.composedPath()
|
|
56
|
+
if (path.some((target) => target instanceof Element)) return isEditableElementPath(path)
|
|
57
|
+
|
|
58
|
+
// Synthetic events dispatched at window have no element in their path. Start at
|
|
59
|
+
// the deepest exposed focused element, then walk outward in composed-path order.
|
|
60
|
+
const activePath: EventTarget[] = []
|
|
61
|
+
let activeElement: Element | null = document.activeElement
|
|
62
|
+
while (activeElement?.shadowRoot?.activeElement) {
|
|
63
|
+
activeElement = activeElement.shadowRoot.activeElement
|
|
64
|
+
}
|
|
65
|
+
while (activeElement) {
|
|
66
|
+
activePath.push(activeElement)
|
|
67
|
+
const root = activeElement.getRootNode()
|
|
68
|
+
activeElement =
|
|
69
|
+
activeElement.assignedSlot ??
|
|
70
|
+
activeElement.parentElement ??
|
|
71
|
+
(root instanceof ShadowRoot ? root.host : null)
|
|
72
|
+
}
|
|
73
|
+
return isEditableElementPath(activePath)
|
|
74
|
+
}
|
|
@@ -8,6 +8,11 @@ export type ApplicationSettingsSection = Readonly<{
|
|
|
8
8
|
group: string
|
|
9
9
|
icon?: JSX.Element
|
|
10
10
|
description?: string
|
|
11
|
+
/**
|
|
12
|
+
* Creates the active panel. Rebuilding the section list with the same id keeps
|
|
13
|
+
* that panel mounted and does not invoke a replacement renderer. Pass changing
|
|
14
|
+
* context through reactive values in the returned view.
|
|
15
|
+
*/
|
|
11
16
|
render(): JSX.Element
|
|
12
17
|
}>
|
|
13
18
|
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
export const DEFAULT_SETTINGS_KEYSHORTCUTS = 'Meta+, Control+,'
|
|
2
|
+
|
|
3
|
+
const settingsShortcutModifiers = [
|
|
4
|
+
'Alt',
|
|
5
|
+
'AltGraph',
|
|
6
|
+
'CapsLock',
|
|
7
|
+
'Control',
|
|
8
|
+
'Fn',
|
|
9
|
+
'FnLock',
|
|
10
|
+
'Hyper',
|
|
11
|
+
'Meta',
|
|
12
|
+
'NumLock',
|
|
13
|
+
'ScrollLock',
|
|
14
|
+
'Shift',
|
|
15
|
+
'Super',
|
|
16
|
+
'Symbol',
|
|
17
|
+
'SymbolLock',
|
|
18
|
+
] as const
|
|
19
|
+
|
|
20
|
+
type SettingsShortcutModifier = (typeof settingsShortcutModifiers)[number]
|
|
21
|
+
|
|
22
|
+
export type ParsedSettingsShortcut = Readonly<{
|
|
23
|
+
key: string
|
|
24
|
+
modifiers: readonly SettingsShortcutModifier[]
|
|
25
|
+
}>
|
|
26
|
+
|
|
27
|
+
const supportedModifiers = new Set<string>(settingsShortcutModifiers)
|
|
28
|
+
const exactSettingsShortcutModifiers: readonly SettingsShortcutModifier[] = [
|
|
29
|
+
'Alt',
|
|
30
|
+
'AltGraph',
|
|
31
|
+
'Control',
|
|
32
|
+
'Fn',
|
|
33
|
+
'Hyper',
|
|
34
|
+
'Meta',
|
|
35
|
+
'Shift',
|
|
36
|
+
'Super',
|
|
37
|
+
'Symbol',
|
|
38
|
+
]
|
|
39
|
+
|
|
40
|
+
function parseSettingsShortcutChord(chord: string): ParsedSettingsShortcut | undefined {
|
|
41
|
+
const parts = chord.split('+')
|
|
42
|
+
const key = parts.pop()
|
|
43
|
+
if (!key || key.trim() !== key || supportedModifiers.has(key)) return
|
|
44
|
+
|
|
45
|
+
const modifiers: SettingsShortcutModifier[] = []
|
|
46
|
+
for (const part of parts) {
|
|
47
|
+
if (!supportedModifiers.has(part) || modifiers.includes(part as SettingsShortcutModifier))
|
|
48
|
+
return
|
|
49
|
+
modifiers.push(part as SettingsShortcutModifier)
|
|
50
|
+
}
|
|
51
|
+
return { key, modifiers }
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function parseSettingsKeyshortcuts(value: string): ParsedSettingsShortcut[] {
|
|
55
|
+
return value
|
|
56
|
+
.trim()
|
|
57
|
+
.split(/\s+/)
|
|
58
|
+
.filter(Boolean)
|
|
59
|
+
.flatMap((chord) => {
|
|
60
|
+
const parsed = parseSettingsShortcutChord(chord)
|
|
61
|
+
return parsed ? [parsed] : []
|
|
62
|
+
})
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function normalizeShortcutKey(key: string) {
|
|
66
|
+
if (key === 'Space') return ' '
|
|
67
|
+
if (key === 'Plus') return '+'
|
|
68
|
+
return /^[a-z]$/i.test(key) ? key.toLowerCase() : key
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function matchesSettingsShortcut(
|
|
72
|
+
event: KeyboardEvent,
|
|
73
|
+
chord: ParsedSettingsShortcut,
|
|
74
|
+
allowDefaultMetaControlOverlap: boolean,
|
|
75
|
+
hasEditableTarget: (event: KeyboardEvent) => boolean
|
|
76
|
+
) {
|
|
77
|
+
if (normalizeShortcutKey(event.key) !== normalizeShortcutKey(chord.key)) return false
|
|
78
|
+
const requiredModifiers = new Set(chord.modifiers)
|
|
79
|
+
const allowMetaControlOverlap =
|
|
80
|
+
allowDefaultMetaControlOverlap &&
|
|
81
|
+
event.metaKey &&
|
|
82
|
+
event.ctrlKey &&
|
|
83
|
+
(requiredModifiers.has('Meta') || requiredModifiers.has('Control'))
|
|
84
|
+
if (
|
|
85
|
+
exactSettingsShortcutModifiers.some(
|
|
86
|
+
(modifier) =>
|
|
87
|
+
!(allowMetaControlOverlap && (modifier === 'Meta' || modifier === 'Control')) &&
|
|
88
|
+
event.getModifierState(modifier) !== requiredModifiers.has(modifier)
|
|
89
|
+
)
|
|
90
|
+
)
|
|
91
|
+
return false
|
|
92
|
+
if (
|
|
93
|
+
chord.modifiers.some(
|
|
94
|
+
(modifier) =>
|
|
95
|
+
!exactSettingsShortcutModifiers.includes(modifier) && !event.getModifierState(modifier)
|
|
96
|
+
)
|
|
97
|
+
)
|
|
98
|
+
return false
|
|
99
|
+
if (requiredModifiers.size === 0 && hasEditableTarget(event)) return false
|
|
100
|
+
|
|
101
|
+
return true
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export function matchesSettingsKeyshortcuts(
|
|
105
|
+
event: KeyboardEvent,
|
|
106
|
+
value: string | readonly ParsedSettingsShortcut[],
|
|
107
|
+
allowDefaultMetaControlOverlap: boolean,
|
|
108
|
+
hasEditableTarget: (event: KeyboardEvent) => boolean
|
|
109
|
+
) {
|
|
110
|
+
return (
|
|
111
|
+
!event.defaultPrevented &&
|
|
112
|
+
(typeof value === 'string' ? parseSettingsKeyshortcuts(value) : value).some((chord) =>
|
|
113
|
+
matchesSettingsShortcut(event, chord, allowDefaultMetaControlOverlap, hasEditableTarget)
|
|
114
|
+
)
|
|
115
|
+
)
|
|
116
|
+
}
|
|
@@ -2,7 +2,7 @@ import { SettingsLayout } from '@adea-ai/ui/components/composites/settings'
|
|
|
2
2
|
import { ModalDialog } from '@adea-ai/ui/components/ui/modal-dialog'
|
|
3
3
|
import { TabsContent } from '@adea-ai/ui/components/ui/tabs'
|
|
4
4
|
import { Text } from '@adea-ai/ui/components/ui/typography'
|
|
5
|
-
import { For, Show, untrack, type Accessor, type JSX } from 'solid-js'
|
|
5
|
+
import { createMemo, For, Show, untrack, type Accessor, type JSX } from 'solid-js'
|
|
6
6
|
|
|
7
7
|
import { settingsGroups, type ApplicationSettingsSection } from '../shell/settings-sections'
|
|
8
8
|
|
|
@@ -31,8 +31,10 @@ export type ApplicationSettingsPanelProps = {
|
|
|
31
31
|
* settings as a page. `ApplicationSettings` shows the same panel in a dialog.
|
|
32
32
|
*/
|
|
33
33
|
export function ApplicationSettingsPanel(props: ApplicationSettingsPanelProps) {
|
|
34
|
-
const active = () =>
|
|
35
|
-
|
|
34
|
+
const active = createMemo(() => {
|
|
35
|
+
const selected = props.section
|
|
36
|
+
return props.sections.find((section) => section.id === selected) ?? props.sections[0]
|
|
37
|
+
})
|
|
36
38
|
// Panels are keyed by section id, not by section object, so a caller that rebuilds its
|
|
37
39
|
// section list (an inline config read again) keeps the open panel mounted with its state;
|
|
38
40
|
// only the description follows the list. Panels are built inside the layout, whose tabs
|