@opendaw/lib-dom 0.0.64 → 0.0.66
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.
|
@@ -57,5 +57,11 @@ type ShortcutEntry = {
|
|
|
57
57
|
readonly consume: Provider<Maybe<boolean> | unknown>;
|
|
58
58
|
readonly options: ShortcutOptions;
|
|
59
59
|
};
|
|
60
|
+
export declare namespace ReservedShortcuts {
|
|
61
|
+
const Copy: Shortcut;
|
|
62
|
+
const Cut: Shortcut;
|
|
63
|
+
const Paste: Shortcut;
|
|
64
|
+
const isReserved: (shortcut: Shortcut) => boolean;
|
|
65
|
+
}
|
|
60
66
|
export {};
|
|
61
67
|
//# sourceMappingURL=shortcut-manager.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shortcut-manager.d.ts","sourceRoot":"","sources":["../src/shortcut-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAGH,GAAG,EAEH,SAAS,EAET,KAAK,EAGL,QAAQ,EACR,MAAM,EACN,SAAS,EAET,QAAQ,EACR,YAAY,EACZ,UAAU,EAEb,MAAM,kBAAkB,CAAA;AAMzB,qBAAa,eAAe;;IAExB,MAAM,CAAC,GAAG,IAAI,eAAe;IAE7B,QAAQ,CAAC,MAAM,EAAE,eAAe,CAAA;IAIhC,OAAO;IAKP,aAAa,CAAC,UAAU,EAAE,SAAS,CAAC,IAAI,CAAC,GAAG,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,GAAG,GAAG,eAAe;IAanG,WAAW,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO;IAIxC,WAAW,CAAC,KAAK,EAAE,aAAa,GAAG,IAAI;CAoB1C;AAED,qBAAa,eAAgB,YAAW,UAAU;;gBAOlC,QAAQ,EAAE,SAAS,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG;IAMlE,IAAI,MAAM,IAAI,OA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O,CAAA;IACjC,QAAQ,CAAC,WAAW,CAAC,EAAE,OAAO,CAAA;IAC9B,QAAQ,CAAC,iBAAiB,CAAC,EAAE,OAAO,CAAA;IACpC,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAC7B,CAAA;AAED,yBAAiB,eAAe,CAAC;IACtB,MAAM,OAAO,EAAE,eAKrB,CAAA;CACJ;AAED,KAAK,aAAa,GAAG;IACjB,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAA;IAC3B,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,CAAA;IACpD,QAAQ,CAAC,OAAO,EAAE,eAAe,CAAA;CACpC,CAAA;AAED,yBAAiB,iBAAiB,CAAC;IACxB,MAAM,IAAI,UAAsC,CAAA;IAChD,MAAM,GAAG,UAAsC,CAAA;IAC/C,MAAM,KAAK,UAAsC,CAAA;IAIjD,MAAM,UAAU,GAAI,UAAU,QAAQ,KAAG,OAA0D,CAAA;CAC7G"}
|
package/dist/shortcut-manager.js
CHANGED
|
@@ -84,6 +84,10 @@ export class ShortcutContext {
|
|
|
84
84
|
get priority() { return this.#priority; }
|
|
85
85
|
get entries() { return this.#entries; }
|
|
86
86
|
register(shortcut, consume, options) {
|
|
87
|
+
if (ReservedShortcuts.isReserved(shortcut)) {
|
|
88
|
+
console.warn(`Shortcut ${shortcut.format().join("")} is reserved and cannot be overridden`);
|
|
89
|
+
return Terminable.Empty;
|
|
90
|
+
}
|
|
87
91
|
const entry = { shortcut, consume, options: options ?? ShortcutOptions.Default };
|
|
88
92
|
const index = BinarySearch.leftMostMapped(this.#entries, entry.options.priority ?? 0, NumberComparator, ({ options: { priority } }) => priority ?? 0);
|
|
89
93
|
this.#entries.splice(index, 0, entry);
|
|
@@ -128,7 +132,15 @@ export class Shortcut {
|
|
|
128
132
|
|| code === Key.Enter) {
|
|
129
133
|
return Option.None;
|
|
130
134
|
}
|
|
131
|
-
|
|
135
|
+
// For letters, use event.key to get the layout-independent character
|
|
136
|
+
const effectiveCode = code.startsWith("Key")
|
|
137
|
+
? `Key${event.key.toUpperCase()}`
|
|
138
|
+
: code;
|
|
139
|
+
const shortcut = new Shortcut(effectiveCode, Keyboard.isControlKey(event), event.shiftKey, event.altKey);
|
|
140
|
+
if (ReservedShortcuts.isReserved(shortcut)) {
|
|
141
|
+
return Option.None;
|
|
142
|
+
}
|
|
143
|
+
return Option.wrap(shortcut);
|
|
132
144
|
}
|
|
133
145
|
static #keyNames = {
|
|
134
146
|
[Key.Escape]: ["⎋", "Esc"],
|
|
@@ -194,8 +206,16 @@ export class Shortcut {
|
|
|
194
206
|
&& this.#alt === other.#alt;
|
|
195
207
|
}
|
|
196
208
|
matches(event) {
|
|
197
|
-
|
|
198
|
-
|
|
209
|
+
let codeMatches;
|
|
210
|
+
if (this.#code.startsWith("Key")) {
|
|
211
|
+
// For letters, use event.key to respect keyboard layout (e.g. QWERTZ)
|
|
212
|
+
const expectedLetter = this.#code.slice(3).toLowerCase();
|
|
213
|
+
codeMatches = event.key.toLowerCase() === expectedLetter;
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
codeMatches = event.code === this.#code
|
|
217
|
+
|| (this.#code === Key.DeleteAction && Keyboard.isDelete(event));
|
|
218
|
+
}
|
|
199
219
|
return codeMatches
|
|
200
220
|
&& this.#ctrl === Keyboard.isControlKey(event)
|
|
201
221
|
&& this.#shift === event.shiftKey
|
|
@@ -252,3 +272,11 @@ export var ShortcutOptions;
|
|
|
252
272
|
priority: 0
|
|
253
273
|
};
|
|
254
274
|
})(ShortcutOptions || (ShortcutOptions = {}));
|
|
275
|
+
export var ReservedShortcuts;
|
|
276
|
+
(function (ReservedShortcuts) {
|
|
277
|
+
ReservedShortcuts.Copy = Shortcut.of(Key.KeyC, { ctrl: true });
|
|
278
|
+
ReservedShortcuts.Cut = Shortcut.of(Key.KeyX, { ctrl: true });
|
|
279
|
+
ReservedShortcuts.Paste = Shortcut.of(Key.KeyV, { ctrl: true });
|
|
280
|
+
const all = [ReservedShortcuts.Copy, ReservedShortcuts.Cut, ReservedShortcuts.Paste];
|
|
281
|
+
ReservedShortcuts.isReserved = (shortcut) => all.some(reserved => reserved.equals(shortcut));
|
|
282
|
+
})(ReservedShortcuts || (ReservedShortcuts = {}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opendaw/lib-dom",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.66",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -23,13 +23,13 @@
|
|
|
23
23
|
"test": "vitest run"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@opendaw/lib-runtime": "^0.0.
|
|
27
|
-
"@opendaw/lib-std": "^0.0.
|
|
26
|
+
"@opendaw/lib-runtime": "^0.0.64",
|
|
27
|
+
"@opendaw/lib-std": "^0.0.64",
|
|
28
28
|
"@types/wicg-file-system-access": "^2023.10.6"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@opendaw/eslint-config": "^0.0.27",
|
|
32
32
|
"@opendaw/typescript-config": "^0.0.28"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "191f202a971b57e16938aa308d818b0a8b8f3587"
|
|
35
35
|
}
|