@joewinke/jatui 0.22.0 → 0.23.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/CLAUDE.md +41 -1
- package/dist/actions/reveal.d.ts +37 -0
- package/dist/actions/reveal.js +42 -0
- package/dist/components/AudioRecorder.svelte +749 -0
- package/dist/components/AudioRecorder.svelte.d.ts +36 -0
- package/dist/components/IconSelector.svelte +417 -0
- package/dist/components/IconSelector.svelte.d.ts +55 -0
- package/dist/components/InfiniteGrid.svelte +305 -0
- package/dist/components/InfiniteGrid.svelte.d.ts +71 -0
- package/dist/components/InfiniteSearchGrid.svelte +131 -0
- package/dist/components/InfiniteSearchGrid.svelte.d.ts +67 -0
- package/dist/components/KeyboardShortcutsOverlay.svelte +40 -3
- package/dist/components/KeyboardShortcutsOverlay.svelte.d.ts +31 -16
- package/dist/components/MediaCaptureIcon.svelte +23 -0
- package/dist/components/MediaCaptureIcon.svelte.d.ts +1 -1
- package/dist/components/ThumbnailGrid.svelte +137 -0
- package/dist/components/ThumbnailGrid.svelte.d.ts +42 -0
- package/dist/components/batch/BatchJobTable.svelte +549 -0
- package/dist/components/batch/BatchJobTable.svelte.d.ts +114 -0
- package/dist/components/batch/QuotaMeter.svelte +78 -0
- package/dist/components/batch/QuotaMeter.svelte.d.ts +16 -0
- package/dist/components/batch/batchQueue.d.ts +56 -0
- package/dist/components/batch/batchQueue.js +81 -0
- package/dist/components/batch/elapsedEstimate.d.ts +24 -0
- package/dist/components/batch/elapsedEstimate.js +25 -0
- package/dist/components/batch/pollOperation.d.ts +45 -0
- package/dist/components/batch/pollOperation.js +80 -0
- package/dist/components/batch/useElapsedEstimate.d.ts +10 -0
- package/dist/components/batch/useElapsedEstimate.js +38 -0
- package/dist/components/infiniteGridLoader.d.ts +70 -0
- package/dist/components/infiniteGridLoader.js +141 -0
- package/dist/components/table/columnResize.d.ts +38 -0
- package/dist/components/table/columnResize.js +117 -0
- package/dist/components/table/index.d.ts +2 -0
- package/dist/components/table/index.js +1 -0
- package/dist/components/variant/VariantMatrixPicker.svelte +181 -0
- package/dist/components/variant/VariantMatrixPicker.svelte.d.ts +37 -0
- package/dist/components/variant/variantCombinations.d.ts +75 -0
- package/dist/components/variant/variantCombinations.js +100 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.js +25 -0
- package/dist/styles/motion.css +100 -0
- package/dist/utils/keyboardShortcutRegistry.d.ts +152 -0
- package/dist/utils/keyboardShortcutRegistry.js +365 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -73,6 +73,10 @@ export { default as PresenceStack } from './components/PresenceStack.svelte';
|
|
|
73
73
|
export { default as DirtyFormHost } from './components/DirtyFormHost.svelte';
|
|
74
74
|
export { createDirtyGuard } from './utils/dirtyGuard';
|
|
75
75
|
export { default as MediaLightbox } from './components/MediaLightbox.svelte';
|
|
76
|
+
// Cursor-paged infinite-scroll grids, harvested from chimaro (jatui-m4uz3.4).
|
|
77
|
+
export { default as InfiniteGrid } from './components/InfiniteGrid.svelte';
|
|
78
|
+
export { default as InfiniteSearchGrid } from './components/InfiniteSearchGrid.svelte';
|
|
79
|
+
export { createInfiniteLoader } from './components/infiniteGridLoader';
|
|
76
80
|
// Components — from Flush
|
|
77
81
|
export { default as Button } from './components/Button.svelte';
|
|
78
82
|
export { default as Badge } from './components/Badge.svelte';
|
|
@@ -97,6 +101,7 @@ export { default as LazyImage } from './components/LazyImage.svelte';
|
|
|
97
101
|
export { default as ResizablePanel } from './components/ResizablePanel.svelte';
|
|
98
102
|
export { default as VoicePlayer } from './components/VoicePlayer.svelte';
|
|
99
103
|
export { default as SpeechForm } from './components/SpeechForm.svelte';
|
|
104
|
+
export { default as AudioRecorder } from './components/AudioRecorder.svelte';
|
|
100
105
|
// Components — from Headcount
|
|
101
106
|
export { default as ThemeSelector } from './components/ThemeSelector.svelte';
|
|
102
107
|
export { default as Sparkline } from './components/Sparkline.svelte';
|
|
@@ -112,6 +117,8 @@ export { default as EntityPreviewCard } from './components/EntityPreviewCard.sve
|
|
|
112
117
|
export { default as VariablePicker } from './components/VariablePicker.svelte';
|
|
113
118
|
// Components — Emoji
|
|
114
119
|
export { default as EmojiPicker } from './components/EmojiPicker.svelte';
|
|
120
|
+
// Components — Icon selection
|
|
121
|
+
export { default as IconSelector } from './components/IconSelector.svelte';
|
|
115
122
|
// Emoji data
|
|
116
123
|
export { EMOJI_DATA, ALL_EMOJIS, searchEmojis } from './data/emojis';
|
|
117
124
|
// Components — from Meadow
|
|
@@ -183,6 +190,7 @@ export { default as AnnotationPanel } from './components/AnnotationPanel.svelte'
|
|
|
183
190
|
export { MARKUP_COLORS, DEFAULT_STROKE_WIDTH, renderShape, renderAllShapes, nextShapeId, } from './components/markup';
|
|
184
191
|
// Components — Keyboard Navigation
|
|
185
192
|
export { default as KeyboardShortcutsOverlay } from './components/KeyboardShortcutsOverlay.svelte';
|
|
193
|
+
export { createShortcutRegistry, getShortcutRegistry, formatShortcut, parseCombo as parseShortcutCombo, isTypingTarget, detectPlatform as detectShortcutPlatform, SIDEBAR_TOGGLE_KEY, } from './utils/keyboardShortcutRegistry';
|
|
186
194
|
// Components — Google Maps (DispatchMap fork + location primitives)
|
|
187
195
|
export { default as MapView } from './components/MapView.svelte';
|
|
188
196
|
export { default as LocationMap } from './components/LocationMap.svelte';
|
|
@@ -202,6 +210,13 @@ export { loadGoogleMapsAPI, isGoogleMapsLoaded, isPlacesLoaded, isGeometryLoaded
|
|
|
202
210
|
export { tooltip } from './actions/tooltip';
|
|
203
211
|
export { staggerEntrance } from './actions/staggerEntrance';
|
|
204
212
|
export { attention } from './actions/attention';
|
|
213
|
+
// Scroll-reveal (jatui-m4uz3.3, chimaro port): IntersectionObserver
|
|
214
|
+
// scroll-reveal whose variants live in styles/motion.css as jatui-reveal-*
|
|
215
|
+
// classes on the --motion-* tokens — no shipped animista.css.
|
|
216
|
+
export { reveal, REVEAL_HIDDEN_CLASS, REVEAL_BASE_CLASS } from './actions/reveal';
|
|
217
|
+
// Thumbnail grid (jatui-m4uz3.3, chimaro port): generic {id,url,alt} strip
|
|
218
|
+
// with overflow counter, remove/add affordances and a cell snippet override.
|
|
219
|
+
export { default as ThumbnailGrid } from './components/ThumbnailGrid.svelte';
|
|
205
220
|
export { floating, makeVirtualAnchor } from './actions/floating';
|
|
206
221
|
export { glide } from './transitions/glide';
|
|
207
222
|
// View Transitions kit
|
|
@@ -262,3 +277,13 @@ export { default as Slider } from './components/basic/Slider.svelte';
|
|
|
262
277
|
export { default as Pagination } from './components/basic/Pagination.svelte';
|
|
263
278
|
// Snapshot undo/redo history (wayflow-core) — also importable as 'jatui/history' (jatui-00jfh).
|
|
264
279
|
export { MAX_UNDO_DEPTH, createHistory, pushState, beginChange, endChange, untracked, undo, redo, clearHistory } from './history';
|
|
280
|
+
// Batch queue runner (harvested from vid-gen BatchGenerator — jatui-m4uz3.7).
|
|
281
|
+
export { default as BatchJobTable } from './components/batch/BatchJobTable.svelte';
|
|
282
|
+
export { default as QuotaMeter } from './components/batch/QuotaMeter.svelte';
|
|
283
|
+
export { toJobRows, nextJobsToStart, isProcessLimitReached, moveJob, summarizeJobs, formatElapsed } from './components/batch/batchQueue';
|
|
284
|
+
export { rollingAverage, estimateRemainingMs } from './components/batch/elapsedEstimate';
|
|
285
|
+
export { useElapsedEstimate } from './components/batch/useElapsedEstimate';
|
|
286
|
+
export { pollOperation, PollTimeoutError } from './components/batch/pollOperation';
|
|
287
|
+
// Variant matrix picker + combination algebra (harvested from vid-gen FrameVariantGenerator — jatui-m4uz3.8).
|
|
288
|
+
export { default as VariantMatrixPicker } from './components/variant/VariantMatrixPicker.svelte';
|
|
289
|
+
export { countCombinations, generateCombinations, generateVariantFilename, findVariantOption, variantCategoryMode } from './components/variant/variantCombinations';
|
package/dist/styles/motion.css
CHANGED
|
@@ -44,3 +44,103 @@
|
|
|
44
44
|
scroll-behavior: auto !important;
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
|
+
|
|
48
|
+
/*
|
|
49
|
+
* Scroll-reveal (use:reveal) — ported from chimaro's animista-powered reveal
|
|
50
|
+
* action (jatui-m4uz3.3). The action toggles `.jatui-reveal-hidden` off and
|
|
51
|
+
* `.jatui-reveal jatui-reveal-<variant>` on when the element first intersects
|
|
52
|
+
* the viewport. Every class here reads ONLY the tokens above — animista.css
|
|
53
|
+
* is deliberately NOT shipped; the variants below are the remap.
|
|
54
|
+
*/
|
|
55
|
+
.jatui-reveal-hidden {
|
|
56
|
+
opacity: 0;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.jatui-reveal {
|
|
60
|
+
animation-duration: var(--motion-move);
|
|
61
|
+
animation-timing-function: var(--motion-glide);
|
|
62
|
+
animation-fill-mode: both; /* holds the from-state through any animation-delay */
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.jatui-reveal-fade-in {
|
|
66
|
+
animation-name: jatui-reveal-fade-in;
|
|
67
|
+
}
|
|
68
|
+
.jatui-reveal-fade-in-bottom {
|
|
69
|
+
animation-name: jatui-reveal-fade-in-bottom;
|
|
70
|
+
}
|
|
71
|
+
.jatui-reveal-fade-in-top {
|
|
72
|
+
animation-name: jatui-reveal-fade-in-top;
|
|
73
|
+
}
|
|
74
|
+
.jatui-reveal-fade-in-left {
|
|
75
|
+
animation-name: jatui-reveal-fade-in-left;
|
|
76
|
+
}
|
|
77
|
+
.jatui-reveal-fade-in-right {
|
|
78
|
+
animation-name: jatui-reveal-fade-in-right;
|
|
79
|
+
}
|
|
80
|
+
.jatui-reveal-scale-in-center {
|
|
81
|
+
animation-name: jatui-reveal-scale-in-center;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
@keyframes jatui-reveal-fade-in {
|
|
85
|
+
from {
|
|
86
|
+
opacity: 0;
|
|
87
|
+
}
|
|
88
|
+
to {
|
|
89
|
+
opacity: 1;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
@keyframes jatui-reveal-fade-in-bottom {
|
|
94
|
+
from {
|
|
95
|
+
transform: translateY(24px);
|
|
96
|
+
opacity: 0;
|
|
97
|
+
}
|
|
98
|
+
to {
|
|
99
|
+
transform: translateY(0);
|
|
100
|
+
opacity: 1;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
@keyframes jatui-reveal-fade-in-top {
|
|
105
|
+
from {
|
|
106
|
+
transform: translateY(-24px);
|
|
107
|
+
opacity: 0;
|
|
108
|
+
}
|
|
109
|
+
to {
|
|
110
|
+
transform: translateY(0);
|
|
111
|
+
opacity: 1;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
@keyframes jatui-reveal-fade-in-left {
|
|
116
|
+
from {
|
|
117
|
+
transform: translateX(-24px);
|
|
118
|
+
opacity: 0;
|
|
119
|
+
}
|
|
120
|
+
to {
|
|
121
|
+
transform: translateX(0);
|
|
122
|
+
opacity: 1;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
@keyframes jatui-reveal-fade-in-right {
|
|
127
|
+
from {
|
|
128
|
+
transform: translateX(24px);
|
|
129
|
+
opacity: 0;
|
|
130
|
+
}
|
|
131
|
+
to {
|
|
132
|
+
transform: translateX(0);
|
|
133
|
+
opacity: 1;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
@keyframes jatui-reveal-scale-in-center {
|
|
138
|
+
from {
|
|
139
|
+
transform: scale(0.6);
|
|
140
|
+
opacity: 0;
|
|
141
|
+
}
|
|
142
|
+
to {
|
|
143
|
+
transform: scale(1);
|
|
144
|
+
opacity: 1;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Keyboard shortcut registry — the data source `KeyboardShortcutsOverlay`
|
|
3
|
+
* was always missing (jatui-m4uz3.6, harvested from chimaro's
|
|
4
|
+
* keyboardShortcutManager with its app-specific default registrations
|
|
5
|
+
* stripped).
|
|
6
|
+
*
|
|
7
|
+
* One registry per app (or use the lazy `getShortcutRegistry()` singleton).
|
|
8
|
+
* Components register shortcuts against a CONTEXT and get back an
|
|
9
|
+
* unregister function, which is exactly what a Svelte `$effect` wants to
|
|
10
|
+
* return:
|
|
11
|
+
*
|
|
12
|
+
* $effect(() => registry.register([
|
|
13
|
+
* { key: 'j', description: 'Next item', context: 'list', action: next },
|
|
14
|
+
* { key: 'mod+k', description: 'Search', action: openPalette, allowInInput: true },
|
|
15
|
+
* ]));
|
|
16
|
+
*
|
|
17
|
+
* Contexts form a STACK. `global` is always the bottom. `pushContext()`
|
|
18
|
+
* returns a pop function. When a key is pressed the stack is walked from
|
|
19
|
+
* the top down and the first matching, enabled shortcut wins — so a
|
|
20
|
+
* context higher up shadows the same combo lower down. A context pushed
|
|
21
|
+
* with `{ modal: true }` stops the walk: everything beneath it (including
|
|
22
|
+
* `global`) is suppressed while it is on the stack — that is how a dialog
|
|
23
|
+
* keeps page shortcuts from firing behind it.
|
|
24
|
+
*
|
|
25
|
+
* Sharp edges handled here so every app doesn't re-learn them:
|
|
26
|
+
* - Input focus: shortcuts don't fire while typing in a text input,
|
|
27
|
+
* textarea, select or contenteditable (checkboxes/buttons/ranges don't
|
|
28
|
+
* count as typing). Opt back in per shortcut with `allowInInput`.
|
|
29
|
+
* - IME composition and already-handled (`defaultPrevented`) events are
|
|
30
|
+
* ignored.
|
|
31
|
+
* - Modifiers: `mod` is ⌘ on macOS and Ctrl elsewhere. Matching is exact —
|
|
32
|
+
* `mod+k` does not fire on `mod+shift+k`. Shift is implied by printable
|
|
33
|
+
* symbols (`?` is Shift+/ on most layouts), so `key: '?'` matches without
|
|
34
|
+
* listing `shift`. macOS Option rewrites `event.key` (Alt+K → "˚"), so
|
|
35
|
+
* alt combos fall back to `event.code`.
|
|
36
|
+
* - Browser-reserved combos: Ctrl+B / Ctrl+T / Ctrl+W / Ctrl+N belong to the
|
|
37
|
+
* browser (Chrome won't hand some of them to the page at all). The sidebar
|
|
38
|
+
* convention across JAT apps is `mod+\` — see `SIDEBAR_TOGGLE_KEY`.
|
|
39
|
+
*
|
|
40
|
+
* Pure TypeScript, no Svelte runes and no DOM globals at import time, so it
|
|
41
|
+
* is SSR-safe and unit-testable under plain node.
|
|
42
|
+
*/
|
|
43
|
+
export type ShortcutModifier = 'mod' | 'meta' | 'ctrl' | 'shift' | 'alt' | 'cmd';
|
|
44
|
+
export type ShortcutPlatform = 'mac' | 'other';
|
|
45
|
+
export interface ShortcutDefinition {
|
|
46
|
+
/**
|
|
47
|
+
* `KeyboardEvent.key` value (case-insensitive for letters), optionally
|
|
48
|
+
* prefixed with modifiers: `'k'`, `'mod+k'`, `'shift+ArrowDown'`, `'?'`,
|
|
49
|
+
* `'mod+\\'`. Use `'+'` / `'mod++'` for the plus key itself.
|
|
50
|
+
*/
|
|
51
|
+
key: string;
|
|
52
|
+
/** Extra modifiers, merged with any parsed from `key`. `cmd` is an alias of `mod`. */
|
|
53
|
+
modifiers?: ShortcutModifier | ShortcutModifier[];
|
|
54
|
+
/** Shown in the overlay. */
|
|
55
|
+
description: string;
|
|
56
|
+
action: (event: KeyboardEvent) => void | Promise<void>;
|
|
57
|
+
/** Context this shortcut belongs to. Default `'global'`. */
|
|
58
|
+
context?: string;
|
|
59
|
+
/** Live predicate — a disabled shortcut is skipped and the walk continues. */
|
|
60
|
+
enabled?: () => boolean;
|
|
61
|
+
/** Fire even while focus is in a text field. Default false. */
|
|
62
|
+
allowInInput?: boolean;
|
|
63
|
+
/** Fire on auto-repeat keydowns (held key). Default true. */
|
|
64
|
+
allowRepeat?: boolean;
|
|
65
|
+
/** Call `preventDefault()` when this shortcut fires. Default true. */
|
|
66
|
+
preventDefault?: boolean;
|
|
67
|
+
/** Overlay section title. Defaults to the context's label. */
|
|
68
|
+
group?: string;
|
|
69
|
+
/** Register but leave out of the overlay. */
|
|
70
|
+
hidden?: boolean;
|
|
71
|
+
/** Overrides the computed keycap label in the overlay (e.g. `'j / ↓'`). */
|
|
72
|
+
label?: string;
|
|
73
|
+
}
|
|
74
|
+
export interface PushContextOptions {
|
|
75
|
+
/** Suppress every context beneath this one (including `global`) while pushed. */
|
|
76
|
+
modal?: boolean;
|
|
77
|
+
/** Overlay section title for this context. Default: the context name. */
|
|
78
|
+
label?: string;
|
|
79
|
+
}
|
|
80
|
+
/** Same shape as `KeyboardShortcutsOverlay`'s `ShortcutSection`. */
|
|
81
|
+
export interface RegistrySection {
|
|
82
|
+
title: string;
|
|
83
|
+
shortcuts: {
|
|
84
|
+
key: string;
|
|
85
|
+
description: string;
|
|
86
|
+
}[];
|
|
87
|
+
}
|
|
88
|
+
export interface ToSectionsOptions {
|
|
89
|
+
/**
|
|
90
|
+
* `'active'` (default) lists only contexts that can fire right now —
|
|
91
|
+
* the live part of the stack, top first. `'all'` lists every context
|
|
92
|
+
* with registrations.
|
|
93
|
+
*/
|
|
94
|
+
scope?: 'active' | 'all';
|
|
95
|
+
/** Drop shortcuts whose `enabled()` currently returns false. Default false. */
|
|
96
|
+
onlyEnabled?: boolean;
|
|
97
|
+
}
|
|
98
|
+
export interface ShortcutRegistryOptions {
|
|
99
|
+
/** Force the platform (tests, SSR). Default: sniffed from `navigator`. */
|
|
100
|
+
platform?: ShortcutPlatform;
|
|
101
|
+
/** Overlay labels for contexts. `global` defaults to `'General'`. */
|
|
102
|
+
contextLabels?: Record<string, string>;
|
|
103
|
+
/** Called when an action throws or rejects. Default: `console.error`. */
|
|
104
|
+
onError?: (error: unknown, shortcut: ShortcutDefinition) => void;
|
|
105
|
+
}
|
|
106
|
+
/** Minimal event-target shape `attach()` needs (window, document, an element). */
|
|
107
|
+
export interface ShortcutEventTarget {
|
|
108
|
+
addEventListener(type: 'keydown', listener: (e: KeyboardEvent) => void): void;
|
|
109
|
+
removeEventListener(type: 'keydown', listener: (e: KeyboardEvent) => void): void;
|
|
110
|
+
}
|
|
111
|
+
export interface ShortcutRegistry {
|
|
112
|
+
/** Register one or many shortcuts. Returns an unregister function. */
|
|
113
|
+
register(shortcuts: ShortcutDefinition | ShortcutDefinition[]): () => void;
|
|
114
|
+
/** Push a context onto the stack. Returns a pop function (idempotent). */
|
|
115
|
+
pushContext(name: string, options?: PushContextOptions): () => void;
|
|
116
|
+
/** Context names that can currently fire, top of stack first. */
|
|
117
|
+
activeContexts(): string[];
|
|
118
|
+
/** Listen for keydown on `target` (default `window`). Returns a detach function. */
|
|
119
|
+
attach(target?: ShortcutEventTarget): () => void;
|
|
120
|
+
/** Dispatch an event by hand. Returns true when a shortcut fired. */
|
|
121
|
+
handleKeydown(event: KeyboardEvent): boolean;
|
|
122
|
+
/** Shortcuts grouped for `KeyboardShortcutsOverlay`'s `sections` prop. */
|
|
123
|
+
toSections(options?: ToSectionsOptions): RegistrySection[];
|
|
124
|
+
/** Every registration, in registration order. */
|
|
125
|
+
list(): ShortcutDefinition[];
|
|
126
|
+
/** Keycap label for a shortcut on this registry's platform (`⌘K`, `Ctrl+K`). */
|
|
127
|
+
format(shortcut: ShortcutDefinition | string): string;
|
|
128
|
+
/** Notified after every register/unregister/push/pop. Returns unsubscribe. */
|
|
129
|
+
subscribe(listener: () => void): () => void;
|
|
130
|
+
readonly platform: ShortcutPlatform;
|
|
131
|
+
}
|
|
132
|
+
/** The sidebar-toggle convention. Ctrl+B is reserved by Chrome (bookmarks bar). */
|
|
133
|
+
export declare const SIDEBAR_TOGGLE_KEY = "mod+\\";
|
|
134
|
+
interface ParsedCombo {
|
|
135
|
+
key: string;
|
|
136
|
+
mod: boolean;
|
|
137
|
+
meta: boolean;
|
|
138
|
+
ctrl: boolean;
|
|
139
|
+
shift: boolean;
|
|
140
|
+
alt: boolean;
|
|
141
|
+
}
|
|
142
|
+
export declare function detectPlatform(): ShortcutPlatform;
|
|
143
|
+
/** Parse `'mod+shift+k'` (plus any extra modifiers) into a normalized combo. */
|
|
144
|
+
export declare function parseCombo(key: string, extra?: ShortcutModifier | ShortcutModifier[]): ParsedCombo;
|
|
145
|
+
/** True when keystrokes on `target` are text entry (so bare-key shortcuts must not fire). */
|
|
146
|
+
export declare function isTypingTarget(target: EventTarget | null | undefined): boolean;
|
|
147
|
+
/** Keycap label: `⌘⇧K` on macOS, `Ctrl+Shift+K` elsewhere. */
|
|
148
|
+
export declare function formatShortcut(shortcut: ShortcutDefinition | string, platform?: ShortcutPlatform): string;
|
|
149
|
+
export declare function createShortcutRegistry(options?: ShortcutRegistryOptions): ShortcutRegistry;
|
|
150
|
+
/** Lazily-created app-wide registry, for apps that want one without threading it through props. */
|
|
151
|
+
export declare function getShortcutRegistry(): ShortcutRegistry;
|
|
152
|
+
export {};
|
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Keyboard shortcut registry — the data source `KeyboardShortcutsOverlay`
|
|
3
|
+
* was always missing (jatui-m4uz3.6, harvested from chimaro's
|
|
4
|
+
* keyboardShortcutManager with its app-specific default registrations
|
|
5
|
+
* stripped).
|
|
6
|
+
*
|
|
7
|
+
* One registry per app (or use the lazy `getShortcutRegistry()` singleton).
|
|
8
|
+
* Components register shortcuts against a CONTEXT and get back an
|
|
9
|
+
* unregister function, which is exactly what a Svelte `$effect` wants to
|
|
10
|
+
* return:
|
|
11
|
+
*
|
|
12
|
+
* $effect(() => registry.register([
|
|
13
|
+
* { key: 'j', description: 'Next item', context: 'list', action: next },
|
|
14
|
+
* { key: 'mod+k', description: 'Search', action: openPalette, allowInInput: true },
|
|
15
|
+
* ]));
|
|
16
|
+
*
|
|
17
|
+
* Contexts form a STACK. `global` is always the bottom. `pushContext()`
|
|
18
|
+
* returns a pop function. When a key is pressed the stack is walked from
|
|
19
|
+
* the top down and the first matching, enabled shortcut wins — so a
|
|
20
|
+
* context higher up shadows the same combo lower down. A context pushed
|
|
21
|
+
* with `{ modal: true }` stops the walk: everything beneath it (including
|
|
22
|
+
* `global`) is suppressed while it is on the stack — that is how a dialog
|
|
23
|
+
* keeps page shortcuts from firing behind it.
|
|
24
|
+
*
|
|
25
|
+
* Sharp edges handled here so every app doesn't re-learn them:
|
|
26
|
+
* - Input focus: shortcuts don't fire while typing in a text input,
|
|
27
|
+
* textarea, select or contenteditable (checkboxes/buttons/ranges don't
|
|
28
|
+
* count as typing). Opt back in per shortcut with `allowInInput`.
|
|
29
|
+
* - IME composition and already-handled (`defaultPrevented`) events are
|
|
30
|
+
* ignored.
|
|
31
|
+
* - Modifiers: `mod` is ⌘ on macOS and Ctrl elsewhere. Matching is exact —
|
|
32
|
+
* `mod+k` does not fire on `mod+shift+k`. Shift is implied by printable
|
|
33
|
+
* symbols (`?` is Shift+/ on most layouts), so `key: '?'` matches without
|
|
34
|
+
* listing `shift`. macOS Option rewrites `event.key` (Alt+K → "˚"), so
|
|
35
|
+
* alt combos fall back to `event.code`.
|
|
36
|
+
* - Browser-reserved combos: Ctrl+B / Ctrl+T / Ctrl+W / Ctrl+N belong to the
|
|
37
|
+
* browser (Chrome won't hand some of them to the page at all). The sidebar
|
|
38
|
+
* convention across JAT apps is `mod+\` — see `SIDEBAR_TOGGLE_KEY`.
|
|
39
|
+
*
|
|
40
|
+
* Pure TypeScript, no Svelte runes and no DOM globals at import time, so it
|
|
41
|
+
* is SSR-safe and unit-testable under plain node.
|
|
42
|
+
*/
|
|
43
|
+
/** The sidebar-toggle convention. Ctrl+B is reserved by Chrome (bookmarks bar). */
|
|
44
|
+
export const SIDEBAR_TOGGLE_KEY = 'mod+\\';
|
|
45
|
+
const GLOBAL = 'global';
|
|
46
|
+
export function detectPlatform() {
|
|
47
|
+
if (typeof navigator === 'undefined')
|
|
48
|
+
return 'other';
|
|
49
|
+
const nav = navigator;
|
|
50
|
+
const p = nav.userAgentData?.platform || nav.platform || nav.userAgent || '';
|
|
51
|
+
return /mac|iphone|ipad|ipod/i.test(p) ? 'mac' : 'other';
|
|
52
|
+
}
|
|
53
|
+
/** Parse `'mod+shift+k'` (plus any extra modifiers) into a normalized combo. */
|
|
54
|
+
export function parseCombo(key, extra) {
|
|
55
|
+
const combo = { key: '', mod: false, meta: false, ctrl: false, shift: false, alt: false };
|
|
56
|
+
const mods = extra === undefined ? [] : Array.isArray(extra) ? [...extra] : [extra];
|
|
57
|
+
let base = key;
|
|
58
|
+
if (key.length > 1) {
|
|
59
|
+
// `mod++` → modifiers 'mod', key '+'. A lone '+' never splits.
|
|
60
|
+
const parts = key.endsWith('++') ? [...key.slice(0, -2).split('+'), '+'] : key.split('+');
|
|
61
|
+
base = parts.pop() ?? '';
|
|
62
|
+
for (const p of parts) {
|
|
63
|
+
const m = p.trim().toLowerCase();
|
|
64
|
+
if (m === 'mod' || m === 'cmd' || m === 'meta' || m === 'ctrl' || m === 'shift' || m === 'alt') {
|
|
65
|
+
mods.push(m);
|
|
66
|
+
}
|
|
67
|
+
else if (m === 'control')
|
|
68
|
+
mods.push('ctrl');
|
|
69
|
+
else if (m === 'option')
|
|
70
|
+
mods.push('alt');
|
|
71
|
+
else if (m)
|
|
72
|
+
throw new Error(`keyboardShortcutRegistry: unknown modifier "${p}" in "${key}"`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
for (const m of mods) {
|
|
76
|
+
if (m === 'mod' || m === 'cmd')
|
|
77
|
+
combo.mod = true;
|
|
78
|
+
else
|
|
79
|
+
combo[m] = true;
|
|
80
|
+
}
|
|
81
|
+
combo.key = normalizeKey(base);
|
|
82
|
+
return combo;
|
|
83
|
+
}
|
|
84
|
+
function normalizeKey(key) {
|
|
85
|
+
if (key === 'Esc')
|
|
86
|
+
return 'escape';
|
|
87
|
+
if (key === 'Space' || key === 'Spacebar')
|
|
88
|
+
return ' ';
|
|
89
|
+
if (key === 'Del')
|
|
90
|
+
return 'delete';
|
|
91
|
+
return key.toLowerCase();
|
|
92
|
+
}
|
|
93
|
+
/** A single printable non-letter (`?`, `/`, `\`, `1`): its shift state is baked into the char. */
|
|
94
|
+
function isSymbolKey(key) {
|
|
95
|
+
return key.length === 1 && key.toLowerCase() === key.toUpperCase() && key !== ' ';
|
|
96
|
+
}
|
|
97
|
+
function codeToKey(code) {
|
|
98
|
+
if (!code)
|
|
99
|
+
return null;
|
|
100
|
+
if (/^Key[A-Z]$/.test(code))
|
|
101
|
+
return code.slice(3).toLowerCase();
|
|
102
|
+
if (/^Digit\d$/.test(code))
|
|
103
|
+
return code.slice(5);
|
|
104
|
+
if (code === 'Backslash')
|
|
105
|
+
return '\\';
|
|
106
|
+
if (code === 'Slash')
|
|
107
|
+
return '/';
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
function matches(event, combo, platform) {
|
|
111
|
+
const evKey = normalizeKey(event.key ?? '');
|
|
112
|
+
let keyHit = evKey === combo.key;
|
|
113
|
+
// macOS Option (and some layouts) rewrite event.key for alt combos — fall
|
|
114
|
+
// back to the physical key when alt is part of the shortcut.
|
|
115
|
+
if (!keyHit && combo.alt)
|
|
116
|
+
keyHit = codeToKey(event.code) === combo.key;
|
|
117
|
+
if (!keyHit)
|
|
118
|
+
return false;
|
|
119
|
+
const wantMeta = combo.meta || (combo.mod && platform === 'mac');
|
|
120
|
+
const wantCtrl = combo.ctrl || (combo.mod && platform !== 'mac');
|
|
121
|
+
if (!!event.metaKey !== wantMeta)
|
|
122
|
+
return false;
|
|
123
|
+
if (!!event.ctrlKey !== wantCtrl)
|
|
124
|
+
return false;
|
|
125
|
+
if (!!event.altKey !== combo.alt)
|
|
126
|
+
return false;
|
|
127
|
+
// `?` arrives as Shift+/ — don't demand the shortcut spell that out.
|
|
128
|
+
if (!combo.shift && isSymbolKey(combo.key))
|
|
129
|
+
return true;
|
|
130
|
+
return !!event.shiftKey === combo.shift;
|
|
131
|
+
}
|
|
132
|
+
const NON_TEXT_INPUT_TYPES = new Set([
|
|
133
|
+
'button', 'checkbox', 'color', 'file', 'hidden', 'image', 'radio', 'range', 'reset', 'submit'
|
|
134
|
+
]);
|
|
135
|
+
/** True when keystrokes on `target` are text entry (so bare-key shortcuts must not fire). */
|
|
136
|
+
export function isTypingTarget(target) {
|
|
137
|
+
const el = target;
|
|
138
|
+
if (!el || typeof el !== 'object')
|
|
139
|
+
return false;
|
|
140
|
+
if (el.isContentEditable)
|
|
141
|
+
return true;
|
|
142
|
+
const tag = typeof el.tagName === 'string' ? el.tagName.toUpperCase() : '';
|
|
143
|
+
if (tag === 'TEXTAREA' || tag === 'SELECT')
|
|
144
|
+
return true;
|
|
145
|
+
if (tag === 'INPUT')
|
|
146
|
+
return !NON_TEXT_INPUT_TYPES.has(String(el.type ?? 'text').toLowerCase());
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
const KEY_GLYPHS = {
|
|
150
|
+
escape: 'Esc',
|
|
151
|
+
' ': 'Space',
|
|
152
|
+
delete: 'Del',
|
|
153
|
+
backspace: '⌫',
|
|
154
|
+
enter: 'Enter',
|
|
155
|
+
tab: 'Tab',
|
|
156
|
+
arrowup: '↑',
|
|
157
|
+
arrowdown: '↓',
|
|
158
|
+
arrowleft: '←',
|
|
159
|
+
arrowright: '→',
|
|
160
|
+
pageup: 'PgUp',
|
|
161
|
+
pagedown: 'PgDn',
|
|
162
|
+
home: 'Home',
|
|
163
|
+
end: 'End'
|
|
164
|
+
};
|
|
165
|
+
/** Keycap label: `⌘⇧K` on macOS, `Ctrl+Shift+K` elsewhere. */
|
|
166
|
+
export function formatShortcut(shortcut, platform = detectPlatform()) {
|
|
167
|
+
const def = typeof shortcut === 'string' ? null : shortcut;
|
|
168
|
+
if (def?.label)
|
|
169
|
+
return def.label;
|
|
170
|
+
const combo = def ? parseCombo(def.key, def.modifiers) : parseCombo(shortcut);
|
|
171
|
+
const k = combo.key;
|
|
172
|
+
const keyLabel = KEY_GLYPHS[k] ?? (/^f\d{1,2}$/.test(k) ? k.toUpperCase() : k.length === 1 ? k.toUpperCase() : k);
|
|
173
|
+
if (platform === 'mac') {
|
|
174
|
+
let s = '';
|
|
175
|
+
if (combo.ctrl)
|
|
176
|
+
s += '⌃';
|
|
177
|
+
if (combo.alt)
|
|
178
|
+
s += '⌥';
|
|
179
|
+
if (combo.shift)
|
|
180
|
+
s += '⇧';
|
|
181
|
+
if (combo.mod || combo.meta)
|
|
182
|
+
s += '⌘';
|
|
183
|
+
return s + keyLabel;
|
|
184
|
+
}
|
|
185
|
+
const parts = [];
|
|
186
|
+
if (combo.ctrl || combo.mod)
|
|
187
|
+
parts.push('Ctrl');
|
|
188
|
+
if (combo.meta)
|
|
189
|
+
parts.push('Win');
|
|
190
|
+
if (combo.alt)
|
|
191
|
+
parts.push('Alt');
|
|
192
|
+
if (combo.shift)
|
|
193
|
+
parts.push('Shift');
|
|
194
|
+
parts.push(keyLabel);
|
|
195
|
+
return parts.join('+');
|
|
196
|
+
}
|
|
197
|
+
export function createShortcutRegistry(options = {}) {
|
|
198
|
+
const platform = options.platform ?? detectPlatform();
|
|
199
|
+
const labels = { [GLOBAL]: 'General', ...options.contextLabels };
|
|
200
|
+
const onError = options.onError ??
|
|
201
|
+
((error) => console.error('keyboardShortcutRegistry: shortcut action failed', error));
|
|
202
|
+
const entries = [];
|
|
203
|
+
const stack = [];
|
|
204
|
+
const listeners = new Set();
|
|
205
|
+
let seq = 0;
|
|
206
|
+
function notify() {
|
|
207
|
+
for (const l of [...listeners])
|
|
208
|
+
l();
|
|
209
|
+
}
|
|
210
|
+
function activeContexts() {
|
|
211
|
+
const live = [];
|
|
212
|
+
for (let i = stack.length - 1; i >= 0; i--) {
|
|
213
|
+
const f = stack[i];
|
|
214
|
+
if (!live.includes(f.name))
|
|
215
|
+
live.push(f.name);
|
|
216
|
+
if (f.modal)
|
|
217
|
+
return live;
|
|
218
|
+
}
|
|
219
|
+
if (!live.includes(GLOBAL))
|
|
220
|
+
live.push(GLOBAL);
|
|
221
|
+
return live;
|
|
222
|
+
}
|
|
223
|
+
function register(shortcuts) {
|
|
224
|
+
const defs = Array.isArray(shortcuts) ? shortcuts : [shortcuts];
|
|
225
|
+
const added = defs.map((def) => {
|
|
226
|
+
const entry = {
|
|
227
|
+
def,
|
|
228
|
+
combo: parseCombo(def.key, def.modifiers),
|
|
229
|
+
context: def.context ?? GLOBAL,
|
|
230
|
+
seq: seq++
|
|
231
|
+
};
|
|
232
|
+
entries.push(entry);
|
|
233
|
+
return entry;
|
|
234
|
+
});
|
|
235
|
+
notify();
|
|
236
|
+
let done = false;
|
|
237
|
+
return () => {
|
|
238
|
+
if (done)
|
|
239
|
+
return;
|
|
240
|
+
done = true;
|
|
241
|
+
for (const e of added) {
|
|
242
|
+
const i = entries.indexOf(e);
|
|
243
|
+
if (i !== -1)
|
|
244
|
+
entries.splice(i, 1);
|
|
245
|
+
}
|
|
246
|
+
notify();
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
function pushContext(name, opts = {}) {
|
|
250
|
+
const frame = { name, modal: !!opts.modal, token: {} };
|
|
251
|
+
if (opts.label)
|
|
252
|
+
labels[name] = opts.label;
|
|
253
|
+
stack.push(frame);
|
|
254
|
+
notify();
|
|
255
|
+
return () => {
|
|
256
|
+
// Pop THIS frame even if it is no longer on top (out-of-order
|
|
257
|
+
// teardown is normal when sibling components unmount together).
|
|
258
|
+
const i = stack.indexOf(frame);
|
|
259
|
+
if (i === -1)
|
|
260
|
+
return;
|
|
261
|
+
stack.splice(i, 1);
|
|
262
|
+
notify();
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
function handleKeydown(event) {
|
|
266
|
+
if (event.defaultPrevented || event.isComposing || event.key === 'Process')
|
|
267
|
+
return false;
|
|
268
|
+
const path = typeof event.composedPath === 'function' ? event.composedPath() : [];
|
|
269
|
+
const typing = isTypingTarget(path[0] ?? event.target);
|
|
270
|
+
for (const ctx of activeContexts()) {
|
|
271
|
+
// Later registrations shadow earlier ones within a context.
|
|
272
|
+
for (let i = entries.length - 1; i >= 0; i--) {
|
|
273
|
+
const e = entries[i];
|
|
274
|
+
if (e.context !== ctx)
|
|
275
|
+
continue;
|
|
276
|
+
if (!matches(event, e.combo, platform))
|
|
277
|
+
continue;
|
|
278
|
+
if (typing && !e.def.allowInInput)
|
|
279
|
+
continue;
|
|
280
|
+
if (event.repeat && e.def.allowRepeat === false)
|
|
281
|
+
continue;
|
|
282
|
+
if (e.def.enabled && !e.def.enabled())
|
|
283
|
+
continue;
|
|
284
|
+
if (e.def.preventDefault !== false)
|
|
285
|
+
event.preventDefault();
|
|
286
|
+
try {
|
|
287
|
+
const result = e.def.action(event);
|
|
288
|
+
if (result && typeof result.catch === 'function') {
|
|
289
|
+
result.catch((err) => onError(err, e.def));
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
catch (err) {
|
|
293
|
+
onError(err, e.def);
|
|
294
|
+
}
|
|
295
|
+
return true;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
return false;
|
|
299
|
+
}
|
|
300
|
+
function attach(target) {
|
|
301
|
+
const t = target ?? (typeof window !== 'undefined' ? window : null);
|
|
302
|
+
if (!t)
|
|
303
|
+
return () => { };
|
|
304
|
+
const listener = (e) => {
|
|
305
|
+
handleKeydown(e);
|
|
306
|
+
};
|
|
307
|
+
t.addEventListener('keydown', listener);
|
|
308
|
+
return () => t.removeEventListener('keydown', listener);
|
|
309
|
+
}
|
|
310
|
+
function toSections(opts = {}) {
|
|
311
|
+
const contexts = opts.scope === 'all'
|
|
312
|
+
? [...new Set(entries.map((e) => e.context))].sort((a, b) => a === GLOBAL ? 1 : b === GLOBAL ? -1 : 0)
|
|
313
|
+
: activeContexts();
|
|
314
|
+
const sections = new Map();
|
|
315
|
+
const seen = new Set();
|
|
316
|
+
for (const ctx of contexts) {
|
|
317
|
+
// Walk newest-first so a shadowed combo (same context, or a lower
|
|
318
|
+
// context) is the one dropped, then restore registration order.
|
|
319
|
+
const kept = [];
|
|
320
|
+
for (let i = entries.length - 1; i >= 0; i--) {
|
|
321
|
+
const e = entries[i];
|
|
322
|
+
if (e.context !== ctx || e.def.hidden)
|
|
323
|
+
continue;
|
|
324
|
+
if (opts.onlyEnabled && e.def.enabled && !e.def.enabled())
|
|
325
|
+
continue;
|
|
326
|
+
const comboId = JSON.stringify(e.combo);
|
|
327
|
+
if (opts.scope !== 'all' && seen.has(comboId))
|
|
328
|
+
continue;
|
|
329
|
+
seen.add(comboId);
|
|
330
|
+
kept.unshift(e);
|
|
331
|
+
}
|
|
332
|
+
for (const e of kept) {
|
|
333
|
+
const title = e.def.group ?? labels[ctx] ?? ctx;
|
|
334
|
+
let section = sections.get(title);
|
|
335
|
+
if (!section) {
|
|
336
|
+
section = { title, shortcuts: [] };
|
|
337
|
+
sections.set(title, section);
|
|
338
|
+
}
|
|
339
|
+
section.shortcuts.push({ key: formatShortcut(e.def, platform), description: e.def.description });
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
return [...sections.values()];
|
|
343
|
+
}
|
|
344
|
+
return {
|
|
345
|
+
register,
|
|
346
|
+
pushContext,
|
|
347
|
+
activeContexts,
|
|
348
|
+
attach,
|
|
349
|
+
handleKeydown,
|
|
350
|
+
toSections,
|
|
351
|
+
list: () => [...entries].sort((a, b) => a.seq - b.seq).map((e) => e.def),
|
|
352
|
+
format: (s) => formatShortcut(s, platform),
|
|
353
|
+
subscribe(listener) {
|
|
354
|
+
listeners.add(listener);
|
|
355
|
+
return () => listeners.delete(listener);
|
|
356
|
+
},
|
|
357
|
+
platform
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
let defaultRegistry = null;
|
|
361
|
+
/** Lazily-created app-wide registry, for apps that want one without threading it through props. */
|
|
362
|
+
export function getShortcutRegistry() {
|
|
363
|
+
defaultRegistry ??= createShortcutRegistry();
|
|
364
|
+
return defaultRegistry;
|
|
365
|
+
}
|