Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
design_shortcuts.hpp
Go to the documentation of this file.
1#pragma once
2
8
9#include <pulp/view/design_ir.hpp> // AudioWidgetType (detect_audio_widget return)
10#include <string>
11#include <vector>
12
13namespace pulp::view {
14
15// ── Keyboard shortcut import (UX best-practice default) ─────────────────
16//
17// React designs commonly declare keyboard shortcuts inline via
18// `onKeyDown={e => { if (e.key === 'Escape') ... }}`,
19// `window.addEventListener('keydown', e => { if (e.metaKey && e.key === 's') ... })`,
20// or `useHotkeys('cmd+s', ...)`. The design-import path scans the bundled
21// React source for these patterns and emits a manifest the runtime can
22// register via `registerShortcut(key, modifiers, callback)`. Default-on;
23// opt out with `--no-import-shortcuts` (CLI) for designs where the host
24// owns shortcut handling.
25
30 std::string pattern;
31
35 std::string key;
36
41 std::vector<std::string> modifiers;
42
46 std::string source_location;
47
51 std::string handler_excerpt;
52};
53
66std::vector<DetectedShortcut> extract_keyboard_shortcuts(
67 const std::string& source, const std::string& filename = "");
68
72std::string serialize_detected_shortcuts(const std::vector<DetectedShortcut>& shortcuts);
73
74// ── Default shortcuts (source-matched only) ─────────────────────────────
75//
76// On top of the explicit-source extractor (which captures shortcuts the
77// developer *already wrote*), the default-shortcuts pass adds bindings the
78// developer *would expect* per platform convention but didn't write: `Cmd+,` for
79// Settings, `Cmd+?` / `F1` for Help, bare `?` for a shortcut cheatsheet,
80// `Cmd+S` for Save, etc.
81//
82// Hard rule: a wrong auto-binding is worse than no binding. The detector
83// requires AT LEAST TWO independent signals (component name, canonical name,
84// ARIA role/label, modal heading, content shape) before firing, and emits a
85// `default_collision` entry instead of a binding when multiple modals look like
86// the same pattern.
87//
88// What this pass does NOT cover: Pulp-framework-provided surfaces (Audio /
89// MIDI Settings tabs in standalone). Those need a separate codegen path that
90// drives the TabPanel select-tab API and is gated on the build mode.
91
96 settings, // Settings / Preferences modal
97 help, // Help / About / Documentation modal (prose-style)
98 cheatsheet, // Shortcut cheatsheet modal (<kbd>-list style)
99 new_file, // "New" button
100 open_file, // "Open" button
101 save_file, // "Save" button
102 find, // Find / Search input
103};
104
114 std::string target;
117 std::string confidence;
120 std::vector<std::string> signals;
121};
122
128 std::vector<std::string> candidates; // component names
129 std::string reason;
130};
131
137 std::vector<DefaultShortcutCandidate> accepted;
138 std::vector<DefaultShortcutCollision> collisions;
139};
140
155 const std::string& source,
156 const std::vector<DetectedShortcut>& existing_extracted);
157
165
166std::vector<DetectedShortcut> apply_default_shortcuts(
167 const std::vector<DefaultShortcutCandidate>& accepted,
169
175
176
185bool looks_like_bundler_entry(const std::string& html);
186
188AudioWidgetType detect_audio_widget(const std::string& name);
189
190} // namespace pulp::view
Normalized intermediate representation (IR) for imported designs: the IR value model (style,...
Device capability vocabulary: one tier ladder, one thermal ladder, and the projection from observed i...
Definition child_process.hpp:15
Hover-cursor tracking for platform window hosts.
Definition fwd.hpp:27
DefaultShortcutScan detect_default_shortcuts(const std::string &source, const std::vector< DetectedShortcut > &existing_extracted)
Static-scan a TSX/JS source string for components matching the platform-convention defaults table.
std::vector< DetectedShortcut > apply_default_shortcuts(const std::vector< DefaultShortcutCandidate > &accepted, TargetPlatform platform)
DefaultShortcutPattern
Which platform-convention surface a default binding maps to.
Definition design_shortcuts.hpp:95
@ new_file
Definition design_shortcuts.hpp:99
@ settings
Definition design_shortcuts.hpp:96
@ help
Definition design_shortcuts.hpp:97
@ save_file
Definition design_shortcuts.hpp:101
@ cheatsheet
Definition design_shortcuts.hpp:98
@ find
Definition design_shortcuts.hpp:102
@ open_file
Definition design_shortcuts.hpp:100
bool looks_like_bundler_entry(const std::string &html)
Heuristic: does this HTML look like a JS-bundler entry (React, Vue, Svelte, @pulp/react,...
std::string serialize_default_shortcut_scan(const DefaultShortcutScan &scan)
Render the auto-bound defaults + collisions into JSON for emission alongside the extracted-shortcuts ...
TargetPlatform
Convert accepted candidates from detect_default_shortcuts into the DetectedShortcut form that V2 code...
Definition design_shortcuts.hpp:164
@ macos
Definition design_shortcuts.hpp:164
@ win_linux
Definition design_shortcuts.hpp:164
std::string serialize_detected_shortcuts(const std::vector< DetectedShortcut > &shortcuts)
Serialize a list of DetectedShortcuts to JSON in the caller-provided order.
AudioWidgetType
Audio widget type detected from naming conventions or annotations.
Definition design_ir.hpp:258
std::vector< DetectedShortcut > extract_keyboard_shortcuts(const std::string &source, const std::string &filename="")
Static-scan a TSX/JS source string for keyboard-shortcut patterns.
@ html
Definition design_ir.hpp:46
AudioWidgetType detect_audio_widget(const std::string &name)
Detect audio widget type from a node name.
One default-binding emission produced by the source heuristic.
Definition design_shortcuts.hpp:110
std::string target
Component name / identifier that won the match — for traceability in shortcuts.json and for the devel...
Definition design_shortcuts.hpp:114
DefaultShortcutPattern pattern
Definition design_shortcuts.hpp:111
std::vector< std::string > signals
Source signals that fired, in order.
Definition design_shortcuts.hpp:120
std::string confidence
"high" (≥3 signals) or "medium" (exactly 2).
Definition design_shortcuts.hpp:117
One unresolved candidate set — emitted when multiple components match the same pattern with comparabl...
Definition design_shortcuts.hpp:126
std::string reason
Definition design_shortcuts.hpp:129
std::vector< std::string > candidates
Definition design_shortcuts.hpp:128
DefaultShortcutPattern pattern
Definition design_shortcuts.hpp:127
Result of running detect_default_shortcuts.
Definition design_shortcuts.hpp:136
std::vector< DefaultShortcutCollision > collisions
Definition design_shortcuts.hpp:138
std::vector< DefaultShortcutCandidate > accepted
Definition design_shortcuts.hpp:137
Definition design_shortcuts.hpp:26
std::vector< std::string > modifiers
Modifier names normalized to the extractor's emission order: "meta", "ctrl", "alt",...
Definition design_shortcuts.hpp:41
std::string source_location
Best-effort source location for the matched pattern, in <file>:<line> form when the input source carr...
Definition design_shortcuts.hpp:46
std::string key
Human-readable key name in DOM-spec form: "Escape", "s", "ArrowLeft".
Definition design_shortcuts.hpp:35
std::string pattern
Verbatim pattern as it appeared in source — "e.key === 'Escape'", "e.metaKey && e....
Definition design_shortcuts.hpp:30
std::string handler_excerpt
Best-effort handler-body excerpt — the first ~80 chars after the condition match.
Definition design_shortcuts.hpp:51