@dxos/keyboard 0.8.4-main.b97322e → 0.8.4-main.bc2380dfbc

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/LICENSE CHANGED
@@ -1,8 +1,105 @@
1
- MIT License
2
- Copyright (c) 2022 DXOS
1
+ # Functional Source License, Version 1.1, ALv2 Future License
3
2
 
4
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
3
+ ## Abbreviation
5
4
 
6
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
5
+ FSL-1.1-Apache-2.0
7
6
 
8
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
7
+ ## Notice
8
+
9
+ Copyright 2026 DXOS
10
+
11
+ ## Terms and Conditions
12
+
13
+ ### Licensor ("We")
14
+
15
+ The party offering the Software under these Terms and Conditions.
16
+
17
+ ### The Software
18
+
19
+ The "Software" is each version of the software that we make available under
20
+ these Terms and Conditions, as indicated by our inclusion of these Terms and
21
+ Conditions with the Software.
22
+
23
+ ### License Grant
24
+
25
+ Subject to your compliance with this License Grant and the Patents,
26
+ Redistribution and Trademark clauses below, we hereby grant you the right to
27
+ use, copy, modify, create derivative works, publicly perform, publicly display
28
+ and redistribute the Software for any Permitted Purpose identified below.
29
+
30
+ ### Permitted Purpose
31
+
32
+ A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
33
+ means making the Software available to others in a commercial product or
34
+ service that:
35
+
36
+ 1. substitutes for the Software;
37
+
38
+ 2. substitutes for any other product or service we offer using the Software
39
+ that exists as of the date we make the Software available; or
40
+
41
+ 3. offers the same or substantially similar functionality as the Software.
42
+
43
+ Permitted Purposes specifically include using the Software:
44
+
45
+ 1. for your internal use and access;
46
+
47
+ 2. for non-commercial education;
48
+
49
+ 3. for non-commercial research; and
50
+
51
+ 4. in connection with professional services that you provide to a licensee
52
+ using the Software in accordance with these Terms and Conditions.
53
+
54
+ ### Patents
55
+
56
+ To the extent your use for a Permitted Purpose would necessarily infringe our
57
+ patents, the license grant above includes a license under our patents. If you
58
+ make a claim against any party that the Software infringes or contributes to
59
+ the infringement of any patent, then your patent license to the Software ends
60
+ immediately.
61
+
62
+ ### Redistribution
63
+
64
+ The Terms and Conditions apply to all copies, modifications and derivatives of
65
+ the Software.
66
+
67
+ If you redistribute any copies, modifications or derivatives of the Software,
68
+ you must include a copy of or a link to these Terms and Conditions and not
69
+ remove any copyright notices provided in or with the Software.
70
+
71
+ ### Disclaimer
72
+
73
+ THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
74
+ IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
75
+ PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
76
+
77
+ IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
78
+ SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
79
+ EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
80
+
81
+ ### Trademarks
82
+
83
+ Except for displaying the License Details and identifying us as the origin of
84
+ the Software, you have no right under these Terms and Conditions to use our
85
+ trademarks, trade names, service marks or product names.
86
+
87
+ ## Grant of Future License
88
+
89
+ We hereby irrevocably grant you an additional license to use the Software under
90
+ the Apache License, Version 2.0 that is effective on the second anniversary of
91
+ the date we make the Software available. On or after that date, you may use the
92
+ Software under the Apache License, Version 2.0, in which case the following
93
+ will apply:
94
+
95
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use
96
+ this file except in compliance with the License.
97
+
98
+ You may obtain a copy of the License at
99
+
100
+ http://www.apache.org/licenses/LICENSE-2.0
101
+
102
+ Unless required by applicable law or agreed to in writing, software distributed
103
+ under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
104
+ CONDITIONS OF ANY KIND, either express or implied. See the License for the
105
+ specific language governing permissions and limitations under the License.
package/README.md CHANGED
@@ -9,7 +9,7 @@ Utility for managing contextual keyboard bindings.
9
9
  - Tip: Use https://tableconvert.com/markdown-to-markdown to edit the table.
10
10
 
11
11
  | | macos | windows | chrome (macos) | chrome (windows) |
12
- |-------------------|------------------------------------------|----------------------------------------------------------------------------------------------------------------|----------------|-----------------------------------------------------------------------------------|
12
+ | ----------------- | ---------------------------------------- | -------------------------------------------------------------------------------------------------------------- | -------------- | --------------------------------------------------------------------------------- |
13
13
  | | https://support.apple.com/en-us/HT201236 | https://support.microsoft.com/en-us/windows/keyboard-shortcuts-in-windows-dcc61a57-8ff0-cffe-9796-cb9706c75eec | | https://support.google.com/chrome/answer/157179?hl=en&co=GENIE.Platform%3DDesktop |
14
14
  | Alt-Tab | | x | | |
15
15
  | Alt-F4 | | x | | |
@@ -12,24 +12,14 @@ var modifiers = [
12
12
  var parseShortcut = (shortcut, delimiter = /[+-]/) => {
13
13
  const parts = shortcut.toLowerCase().split(delimiter);
14
14
  const mods = modifiers.filter((key) => parts.includes(key));
15
- invariant(mods.length === 0 || mods.length === parts.length - 1, void 0, {
16
- F: __dxlog_file,
17
- L: 31,
18
- S: void 0,
19
- A: [
20
- "mods.length === 0 || mods.length === parts.length - 1",
21
- ""
22
- ]
23
- });
15
+ invariant(mods.length === 0 || mods.length === parts.length - 1, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 17, S: void 0, A: ["mods.length === 0 || mods.length === parts.length - 1", ""] });
24
16
  return mods.length ? [
25
17
  ...mods,
26
18
  parts[parts.length - 1]
27
19
  ].join("+") : shortcut;
28
20
  };
29
21
  var KeyboardContext = class {
30
- constructor() {
31
- this._keyMap = /* @__PURE__ */ new Map();
32
- }
22
+ _keyMap = /* @__PURE__ */ new Map();
33
23
  get bindings() {
34
24
  return Array.from(this._keyMap.values());
35
25
  }
@@ -46,31 +36,27 @@ var KeyboardContext = class {
46
36
  };
47
37
  var ROOT = "";
48
38
  var Keyboard = class _Keyboard {
49
- constructor() {
50
- this._root = new KeyboardContext();
51
- this._keyMap = /* @__PURE__ */ new Map([
52
- [
53
- ROOT,
54
- this._root
55
- ]
56
- ]);
57
- this._contexts = [
58
- ROOT
59
- ];
60
- this._keyHandler = this.handleKeyDown.bind(this);
61
- this._path = ROOT;
62
- this.bind = this._root.bind.bind(this._root);
63
- this.unbind = this._root.unbind.bind(this._root);
64
- }
65
- static {
66
- this.singleton = new _Keyboard();
67
- }
39
+ static singleton = new _Keyboard();
40
+ _root = new KeyboardContext();
41
+ _keyMap = /* @__PURE__ */ new Map([
42
+ [
43
+ ROOT,
44
+ this._root
45
+ ]
46
+ ]);
47
+ _contexts = [
48
+ ROOT
49
+ ];
50
+ _keyHandler = this.handleKeyDown.bind(this);
51
+ _path = ROOT;
68
52
  initialize() {
69
53
  document.addEventListener("keydown", this._keyHandler);
70
54
  }
71
55
  destroy() {
72
56
  document.removeEventListener("keydown", this._keyHandler);
73
57
  }
58
+ bind = this._root.bind.bind(this._root);
59
+ unbind = this._root.unbind.bind(this._root);
74
60
  setCurrentContext(path = ROOT) {
75
61
  this._path = path;
76
62
  }
@@ -99,7 +85,7 @@ var Keyboard = class _Keyboard {
99
85
  }
100
86
  return Array.from(bindings.values());
101
87
  }
102
- handleKeyDown(event) {
88
+ async handleKeyDown(event) {
103
89
  const { altKey, ctrlKey, metaKey, shiftKey, key } = event;
104
90
  if (key !== "Alt" && key !== "Control" && key !== "Meta" && key !== "Shift") {
105
91
  const tagName = event.target?.tagName;
@@ -116,7 +102,7 @@ var Keyboard = class _Keyboard {
116
102
  if (this._path.startsWith(path)) {
117
103
  const { data, handler, disableInput } = this.getContext(path).get(str) ?? {};
118
104
  if (handler && (!isInput || !disableInput)) {
119
- const result = handler({
105
+ const result = await handler({
120
106
  context: path,
121
107
  shortcut: str,
122
108
  data,
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/keyboard.ts", "../../../src/util.ts"],
4
- "sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { invariant } from '@dxos/invariant';\n\n// TODO(burdon): Replace with hotkeys-js, react-hotkeys, and react-hotkeys-hook.\n\nexport type KeyHandler = (props: {\n context: string;\n shortcut: string;\n data?: any;\n event: KeyboardEvent;\n}) => boolean | void;\n\nexport type KeyBinding = {\n shortcut: string;\n handler: KeyHandler;\n disableInput?: boolean;\n data?: any;\n};\n\n// Keybinding is normalized to this order.\n// https://support.apple.com/en-us/HT201236\nconst modifiers = ['ctrl', 'shift', 'alt', 'meta'];\n\n// Normalize order and case of modifiers.\nexport const parseShortcut = (shortcut: string, delimiter = /[+-]/): string => {\n const parts = shortcut.toLowerCase().split(delimiter);\n const mods = modifiers.filter((key) => parts.includes(key));\n invariant(mods.length === 0 || mods.length === parts.length - 1);\n // Assume single natural key.\n return mods.length ? [...mods, parts[parts.length - 1]].join('+') : shortcut;\n};\n\nclass KeyboardContext {\n readonly _keyMap = new Map<string, KeyBinding>();\n\n get bindings() {\n return Array.from(this._keyMap.values());\n }\n\n get(binding: string): KeyBinding | undefined {\n return this._keyMap.get(binding);\n }\n\n bind(config: KeyBinding): void {\n config.shortcut = parseShortcut(config.shortcut);\n this._keyMap.set(config.shortcut, config);\n }\n\n unbind(binding: string): void {\n this._keyMap.delete(binding);\n }\n}\n\nconst ROOT = '';\n\n/**\n * Manages context-aware key bindings.\n */\nexport class Keyboard {\n static singleton = new Keyboard();\n\n private readonly _root = new KeyboardContext();\n private readonly _keyMap = new Map<string, KeyboardContext>([[ROOT, this._root]]);\n private readonly _contexts: string[] = [ROOT];\n private readonly _keyHandler = this.handleKeyDown.bind(this);\n private _path = ROOT;\n\n initialize(): void {\n document.addEventListener('keydown', this._keyHandler);\n }\n\n destroy(): void {\n document.removeEventListener('keydown', this._keyHandler);\n }\n\n bind = this._root.bind.bind(this._root);\n unbind = this._root.unbind.bind(this._root);\n\n setCurrentContext(path = ROOT): void {\n this._path = path;\n }\n\n getCurrentContext(): string {\n return this._path;\n }\n\n getContext(path = ROOT): KeyboardContext {\n let context = this._keyMap.get(path);\n if (!context) {\n context = new KeyboardContext();\n this._keyMap.set(path, context);\n this._contexts.push(path);\n this._contexts.sort();\n }\n\n return context;\n }\n\n getBindings(): KeyBinding[] {\n const bindings = new Map<string, KeyBinding>();\n for (let i = 0; i < this._contexts.length; ++i) {\n const path = this._contexts[i];\n if (this._path.startsWith(path)) {\n this.getContext(path).bindings.forEach((binding) => {\n bindings.set(binding.shortcut, binding);\n });\n }\n }\n\n return Array.from(bindings.values());\n }\n\n handleKeyDown(event: KeyboardEvent): void {\n const { altKey, ctrlKey, metaKey, shiftKey, key } = event;\n\n if (key !== 'Alt' && key !== 'Control' && key !== 'Meta' && key !== 'Shift') {\n // Binding option to check for input or contenteditable.\n const tagName = (event.target as any)?.tagName;\n const isInput =\n tagName === 'INPUT' || tagName === 'TEXTAREA' || (event.target as any)?.getAttribute('contenteditable');\n\n // Normalized key binding (order matters, see note above).\n const str = [ctrlKey && 'ctrl', shiftKey && 'shift', altKey && 'alt', metaKey && 'meta', key]\n .filter(Boolean)\n .join('+');\n\n // Scan matching contexts.\n for (let i = this._contexts.length - 1; i >= 0; --i) {\n const path = this._contexts[i];\n if (this._path.startsWith(path)) {\n const { data, handler, disableInput } = this.getContext(path).get(str) ?? {};\n if (handler && (!isInput || !disableInput)) {\n const result = handler({ context: path, shortcut: str, data, event });\n if (result !== false) {\n // TODO(burdon): This doesn't prevent actions in markdown editor.\n // Reference: https://codemirror.net/docs/ref/#view.KeyBinding\n event.preventDefault();\n event.stopPropagation();\n }\n\n return;\n }\n }\n }\n }\n }\n}\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { getHostPlatform } from '@dxos/util';\n\n// Resources.\n// https://www.w3.org/TR/DOM-Level-3-Events/#events-keyboardevents\n// https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key\n// https://developer.apple.com/design/human-interface-guidelines/designing-for-macos\n// https://support.apple.com/en-us/HT201236\n// https://support.apple.com/guide/mac-help/what-are-those-symbols-shown-in-menus-cpmh0011/mac\n\nconst ctrl: Record<string, string> = {\n macos: '⌃',\n ios: '⌃',\n windows: 'Ctrl',\n linux: 'Ctrl',\n unknown: 'Ctrl',\n};\n\nconst alt: Record<string, string> = {\n macos: '⌥',\n ios: '⌥',\n windows: 'Alt',\n linux: 'Alt',\n unknown: 'Alt',\n};\n\nconst meta: Record<string, string> = {\n macos: '⌘',\n ios: '⌘',\n windows: '⊞',\n // TODO(wittjosiah): Use ⌘ or ⊞ instead? Wait for user feedback.\n // From https://en.wikipedia.org/wiki/Super_key_(keyboard_button).\n linux: '❖',\n unknown: '❖',\n};\n\nconst getSymbol = (part: string) => {\n const platform = getHostPlatform();\n switch (part.toLowerCase()) {\n // Mods.\n case 'alt':\n return alt[platform];\n case 'ctrl':\n return ctrl[platform];\n case 'meta':\n return meta[platform];\n case 'shift':\n return '⇧';\n // Special keys.\n case 'backspace':\n return '⌫';\n case 'enter':\n return '⏎';\n case 'escape':\n return '⎋';\n case 'space':\n return '␣';\n case 'tab':\n return '⇥';\n default:\n return part.toUpperCase();\n }\n};\n\nexport const keySymbols = (keyBinding: string): string[] => {\n const parts = keyBinding.split('+');\n return parts.map(getSymbol);\n};\n"],
5
- "mappings": ";;;AAIA,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ACF;AAEO,IAAMC,aAAa,CAACC,eAAAA;AACzB,QAAMC,QAAQD,WAAWE,MAAM,GAAA;AAC/B,SAAOD,MAAME,IAAIV,SAAAA;AACnB;",
6
- "names": ["invariant", "modifiers", "parseShortcut", "shortcut", "delimiter", "parts", "toLowerCase", "split", "mods", "filter", "key", "includes", "length", "join", "KeyboardContext", "_keyMap", "Map", "bindings", "Array", "from", "values", "get", "binding", "bind", "config", "set", "unbind", "delete", "ROOT", "Keyboard", "_root", "_contexts", "_keyHandler", "handleKeyDown", "_path", "singleton", "initialize", "document", "addEventListener", "destroy", "removeEventListener", "setCurrentContext", "path", "getCurrentContext", "getContext", "context", "push", "sort", "getBindings", "i", "startsWith", "forEach", "event", "altKey", "ctrlKey", "metaKey", "shiftKey", "tagName", "target", "isInput", "getAttribute", "str", "Boolean", "data", "handler", "disableInput", "result", "preventDefault", "stopPropagation", "getHostPlatform", "ctrl", "macos", "ios", "windows", "linux", "unknown", "alt", "meta", "getSymbol", "part", "platform", "getHostPlatform", "toLowerCase", "toUpperCase", "keySymbols", "keyBinding", "parts", "split", "map"]
4
+ "sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { invariant } from '@dxos/invariant';\nimport { type MaybePromise } from '@dxos/util';\n\n// TODO(burdon): Replace with hotkeys-js, react-hotkeys, and react-hotkeys-hook.\n\nexport type KeyHandler = (props: {\n context: string;\n shortcut: string;\n data?: any;\n event: KeyboardEvent;\n}) => MaybePromise<boolean | void>;\n\nexport type KeyBinding = {\n shortcut: string;\n handler: KeyHandler;\n disableInput?: boolean;\n data?: any;\n};\n\n// Keybinding is normalized to this order.\n// https://support.apple.com/en-us/HT201236\nconst modifiers = ['ctrl', 'shift', 'alt', 'meta'];\n\n// Normalize order and case of modifiers.\nexport const parseShortcut = (shortcut: string, delimiter = /[+-]/): string => {\n const parts = shortcut.toLowerCase().split(delimiter);\n const mods = modifiers.filter((key) => parts.includes(key));\n invariant(mods.length === 0 || mods.length === parts.length - 1);\n // Assume single natural key.\n return mods.length ? [...mods, parts[parts.length - 1]].join('+') : shortcut;\n};\n\nclass KeyboardContext {\n readonly _keyMap = new Map<string, KeyBinding>();\n\n get bindings() {\n return Array.from(this._keyMap.values());\n }\n\n get(binding: string): KeyBinding | undefined {\n return this._keyMap.get(binding);\n }\n\n bind(config: KeyBinding): void {\n config.shortcut = parseShortcut(config.shortcut);\n this._keyMap.set(config.shortcut, config);\n }\n\n unbind(binding: string): void {\n this._keyMap.delete(binding);\n }\n}\n\nconst ROOT = '';\n\n/**\n * Manages context-aware key bindings.\n */\nexport class Keyboard {\n static singleton = new Keyboard();\n\n private readonly _root = new KeyboardContext();\n private readonly _keyMap = new Map<string, KeyboardContext>([[ROOT, this._root]]);\n private readonly _contexts: string[] = [ROOT];\n private readonly _keyHandler = this.handleKeyDown.bind(this);\n private _path = ROOT;\n\n initialize(): void {\n document.addEventListener('keydown', this._keyHandler);\n }\n\n destroy(): void {\n document.removeEventListener('keydown', this._keyHandler);\n }\n\n bind = this._root.bind.bind(this._root);\n unbind = this._root.unbind.bind(this._root);\n\n setCurrentContext(path = ROOT): void {\n this._path = path;\n }\n\n getCurrentContext(): string {\n return this._path;\n }\n\n getContext(path = ROOT): KeyboardContext {\n let context = this._keyMap.get(path);\n if (!context) {\n context = new KeyboardContext();\n this._keyMap.set(path, context);\n this._contexts.push(path);\n this._contexts.sort();\n }\n\n return context;\n }\n\n getBindings(): KeyBinding[] {\n const bindings = new Map<string, KeyBinding>();\n for (let i = 0; i < this._contexts.length; ++i) {\n const path = this._contexts[i];\n if (this._path.startsWith(path)) {\n this.getContext(path).bindings.forEach((binding) => {\n bindings.set(binding.shortcut, binding);\n });\n }\n }\n\n return Array.from(bindings.values());\n }\n\n async handleKeyDown(event: KeyboardEvent): Promise<void> {\n const { altKey, ctrlKey, metaKey, shiftKey, key } = event;\n\n if (key !== 'Alt' && key !== 'Control' && key !== 'Meta' && key !== 'Shift') {\n // Binding option to check for input or contenteditable.\n const tagName = (event.target as any)?.tagName;\n const isInput =\n tagName === 'INPUT' || tagName === 'TEXTAREA' || (event.target as any)?.getAttribute('contenteditable');\n\n // Normalized key binding (order matters, see note above).\n const str = [ctrlKey && 'ctrl', shiftKey && 'shift', altKey && 'alt', metaKey && 'meta', key]\n .filter(Boolean)\n .join('+');\n\n // Scan matching contexts.\n for (let i = this._contexts.length - 1; i >= 0; --i) {\n const path = this._contexts[i];\n if (this._path.startsWith(path)) {\n const { data, handler, disableInput } = this.getContext(path).get(str) ?? {};\n if (handler && (!isInput || !disableInput)) {\n const result = await handler({ context: path, shortcut: str, data, event });\n if (result !== false) {\n // TODO(burdon): This doesn't prevent actions in markdown editor.\n // Reference: https://codemirror.net/docs/ref/#view.KeyBinding\n event.preventDefault();\n event.stopPropagation();\n }\n\n return;\n }\n }\n }\n }\n }\n}\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { getHostPlatform } from '@dxos/util';\n\n// Resources.\n// https://www.w3.org/TR/DOM-Level-3-Events/#events-keyboardevents\n// https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key\n// https://developer.apple.com/design/human-interface-guidelines/designing-for-macos\n// https://support.apple.com/en-us/HT201236\n// https://support.apple.com/guide/mac-help/what-are-those-symbols-shown-in-menus-cpmh0011/mac\n\nconst ctrl: Record<string, string> = {\n macos: '⌃',\n ios: '⌃',\n windows: 'Ctrl',\n linux: 'Ctrl',\n unknown: 'Ctrl',\n};\n\nconst alt: Record<string, string> = {\n macos: '⌥',\n ios: '⌥',\n windows: 'Alt',\n linux: 'Alt',\n unknown: 'Alt',\n};\n\nconst meta: Record<string, string> = {\n macos: '⌘',\n ios: '⌘',\n windows: '⊞',\n // TODO(wittjosiah): Use ⌘ or ⊞ instead? Wait for user feedback.\n // From https://en.wikipedia.org/wiki/Super_key_(keyboard_button).\n linux: '❖',\n unknown: '❖',\n};\n\nconst getSymbol = (part: string) => {\n const platform = getHostPlatform();\n switch (part.toLowerCase()) {\n // Mods.\n case 'alt':\n return alt[platform];\n case 'ctrl':\n return ctrl[platform];\n case 'meta':\n return meta[platform];\n case 'shift':\n return '⇧';\n // Special keys.\n case 'backspace':\n return '⌫';\n case 'enter':\n return '⏎';\n case 'escape':\n return '⎋';\n case 'space':\n return '␣';\n case 'tab':\n return '⇥';\n default:\n return part.toUpperCase();\n }\n};\n\nexport const keySymbols = (keyBinding: string): string[] => {\n const parts = keyBinding.split('+');\n return parts.map(getSymbol);\n};\n"],
5
+ "mappings": ";;;AAIA,SAASA,iBAAiB;AAmB1B,IAAA,eAAA;IAE2B,YAAA;EAAS;EAAO;EAAO;EAElD;AACA;AAEE,IAAMC,gBAAiBC,CAAAA,UAAQC,YAAcC,WAASD;AACtDH,QAAAA,QAAUC,SAAW,YAAUA,EAAKI,MAAM,SAAKC;AAC/C,QAAA,OAAA,UAAA,OAA6B,CAAA,QAAA,MAAA,SAAA,GAAA,CAAA;AAC7B,YAAOL,KAAKI,WAAS,KAAA,KAAA,WAAA,MAAA,SAAA,GAAA,QAAA,EAAA,YAAA,YAAA,GAAA,cAAA,GAAA,IAAA,GAAA,QAAA,GAAA,CAAA,yDAAA,EAAA,EAAA,CAAA;SAAUC,KAAMA,SAAMD;IAAaE,GAAK;IAC7D,MAAA,MAAA,SAAA,CAAA;EAEF,EAAMC,KAAAA,GAAAA,IAAAA;;IAGJ,wBAAe;YACb,oBAAOC,IAAMC;EACf,IAAA,WAAA;AAEIC,WAAe,MAA0B,KAAA,KAAA,QAAA,OAAA,CAAA;;EAE7C,IAAA,SAAA;AAEAC,WAAuB,KAAQ,QAAA,IAAA,OAAA;;OAE7B,QAAKC;AACP,WAAA,WAAA,cAAA,OAAA,QAAA;AAEAC,SAAOH,QAAuB,IAAA,OAAA,UAAA,MAAA;;EAE9B,OAAA,SAAA;AACF,SAAA,QAAA,OAAA,OAAA;EAEA;AAEA;;AAMmBI,IAAYP,WAAZO,MAAYP,UAAAA;EACZK,OAAAA,YAA2C,IAAA,UAAA;UAAC,IAAA,gBAAA;YAACG,oBAAA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,MAAM,GAAA;AAC/B,SAAOD,MAAME,IAAIT,SAAAA;AACnB;",
6
+ "names": ["invariant", "mods", "filter", "key", "includes", "length", "parts", "join", "KeyboardContext", "Array", "from", "binding", "bind", "_keyMap", "unbind", "_root", "ROOT", "_contexts", "_keyHandler", "_path", "initialize", "document", "destroy", "setCurrentContext", "path", "getCurrentContext", "getContext", "context", "sort", "getBindings", "i", "startsWith", "bindings", "shortcut", "handleKeyDown", "event", "tagName", "target", "str", "shiftKey", "altKey", "metaKey", "Boolean", "data", "handler", "disableInput", "isInput", "result", "getHostPlatform", "ctrl", "macos", "ios", "windows", "linux", "unknown", "alt", "meta", "getSymbol", "part", "platform", "toLowerCase", "toUpperCase", "keySymbols", "keyBinding", "parts", "split", "map"]
7
7
  }
@@ -1 +1 @@
1
- {"inputs":{"src/keyboard.ts":{"bytes":15909,"imports":[{"path":"@dxos/invariant","kind":"import-statement","external":true}],"format":"esm"},"src/util.ts":{"bytes":5655,"imports":[{"path":"@dxos/util","kind":"import-statement","external":true}],"format":"esm"},"src/index.ts":{"bytes":531,"imports":[{"path":"src/keyboard.ts","kind":"import-statement","original":"./keyboard"},{"path":"src/util.ts","kind":"import-statement","original":"./util"}],"format":"esm"}},"outputs":{"dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":10669},"dist/lib/browser/index.mjs":{"imports":[{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"exports":["Keyboard","keySymbols","parseShortcut"],"entryPoint":"src/index.ts","inputs":{"src/keyboard.ts":{"bytesInOutput":3624},"src/index.ts":{"bytesInOutput":0},"src/util.ts":{"bytesInOutput":1184}},"bytes":4966}}}
1
+ {"inputs":{"src/keyboard.ts":{"bytes":15976,"imports":[{"path":"@dxos/invariant","kind":"import-statement","external":true}],"format":"esm"},"src/util.ts":{"bytes":5581,"imports":[{"path":"@dxos/util","kind":"import-statement","external":true}],"format":"esm"},"src/index.ts":{"bytes":456,"imports":[{"path":"src/keyboard.ts","kind":"import-statement","original":"./keyboard"},{"path":"src/util.ts","kind":"import-statement","original":"./util"}],"format":"esm"}},"outputs":{"dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":10173},"dist/lib/browser/index.mjs":{"imports":[{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"exports":["Keyboard","keySymbols","parseShortcut"],"entryPoint":"src/index.ts","inputs":{"src/keyboard.ts":{"bytesInOutput":3495},"src/index.ts":{"bytesInOutput":0},"src/util.ts":{"bytesInOutput":1184}},"bytes":4837}}}
@@ -12,24 +12,14 @@ var modifiers = [
12
12
  var parseShortcut = (shortcut, delimiter = /[+-]/) => {
13
13
  const parts = shortcut.toLowerCase().split(delimiter);
14
14
  const mods = modifiers.filter((key) => parts.includes(key));
15
- invariant(mods.length === 0 || mods.length === parts.length - 1, void 0, {
16
- F: __dxlog_file,
17
- L: 31,
18
- S: void 0,
19
- A: [
20
- "mods.length === 0 || mods.length === parts.length - 1",
21
- ""
22
- ]
23
- });
15
+ invariant(mods.length === 0 || mods.length === parts.length - 1, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 17, S: void 0, A: ["mods.length === 0 || mods.length === parts.length - 1", ""] });
24
16
  return mods.length ? [
25
17
  ...mods,
26
18
  parts[parts.length - 1]
27
19
  ].join("+") : shortcut;
28
20
  };
29
21
  var KeyboardContext = class {
30
- constructor() {
31
- this._keyMap = /* @__PURE__ */ new Map();
32
- }
22
+ _keyMap = /* @__PURE__ */ new Map();
33
23
  get bindings() {
34
24
  return Array.from(this._keyMap.values());
35
25
  }
@@ -46,31 +36,27 @@ var KeyboardContext = class {
46
36
  };
47
37
  var ROOT = "";
48
38
  var Keyboard = class _Keyboard {
49
- constructor() {
50
- this._root = new KeyboardContext();
51
- this._keyMap = /* @__PURE__ */ new Map([
52
- [
53
- ROOT,
54
- this._root
55
- ]
56
- ]);
57
- this._contexts = [
58
- ROOT
59
- ];
60
- this._keyHandler = this.handleKeyDown.bind(this);
61
- this._path = ROOT;
62
- this.bind = this._root.bind.bind(this._root);
63
- this.unbind = this._root.unbind.bind(this._root);
64
- }
65
- static {
66
- this.singleton = new _Keyboard();
67
- }
39
+ static singleton = new _Keyboard();
40
+ _root = new KeyboardContext();
41
+ _keyMap = /* @__PURE__ */ new Map([
42
+ [
43
+ ROOT,
44
+ this._root
45
+ ]
46
+ ]);
47
+ _contexts = [
48
+ ROOT
49
+ ];
50
+ _keyHandler = this.handleKeyDown.bind(this);
51
+ _path = ROOT;
68
52
  initialize() {
69
53
  document.addEventListener("keydown", this._keyHandler);
70
54
  }
71
55
  destroy() {
72
56
  document.removeEventListener("keydown", this._keyHandler);
73
57
  }
58
+ bind = this._root.bind.bind(this._root);
59
+ unbind = this._root.unbind.bind(this._root);
74
60
  setCurrentContext(path = ROOT) {
75
61
  this._path = path;
76
62
  }
@@ -99,7 +85,7 @@ var Keyboard = class _Keyboard {
99
85
  }
100
86
  return Array.from(bindings.values());
101
87
  }
102
- handleKeyDown(event) {
88
+ async handleKeyDown(event) {
103
89
  const { altKey, ctrlKey, metaKey, shiftKey, key } = event;
104
90
  if (key !== "Alt" && key !== "Control" && key !== "Meta" && key !== "Shift") {
105
91
  const tagName = event.target?.tagName;
@@ -116,7 +102,7 @@ var Keyboard = class _Keyboard {
116
102
  if (this._path.startsWith(path)) {
117
103
  const { data, handler, disableInput } = this.getContext(path).get(str) ?? {};
118
104
  if (handler && (!isInput || !disableInput)) {
119
- const result = handler({
105
+ const result = await handler({
120
106
  context: path,
121
107
  shortcut: str,
122
108
  data,
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/keyboard.ts", "../../../src/util.ts"],
4
- "sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { invariant } from '@dxos/invariant';\n\n// TODO(burdon): Replace with hotkeys-js, react-hotkeys, and react-hotkeys-hook.\n\nexport type KeyHandler = (props: {\n context: string;\n shortcut: string;\n data?: any;\n event: KeyboardEvent;\n}) => boolean | void;\n\nexport type KeyBinding = {\n shortcut: string;\n handler: KeyHandler;\n disableInput?: boolean;\n data?: any;\n};\n\n// Keybinding is normalized to this order.\n// https://support.apple.com/en-us/HT201236\nconst modifiers = ['ctrl', 'shift', 'alt', 'meta'];\n\n// Normalize order and case of modifiers.\nexport const parseShortcut = (shortcut: string, delimiter = /[+-]/): string => {\n const parts = shortcut.toLowerCase().split(delimiter);\n const mods = modifiers.filter((key) => parts.includes(key));\n invariant(mods.length === 0 || mods.length === parts.length - 1);\n // Assume single natural key.\n return mods.length ? [...mods, parts[parts.length - 1]].join('+') : shortcut;\n};\n\nclass KeyboardContext {\n readonly _keyMap = new Map<string, KeyBinding>();\n\n get bindings() {\n return Array.from(this._keyMap.values());\n }\n\n get(binding: string): KeyBinding | undefined {\n return this._keyMap.get(binding);\n }\n\n bind(config: KeyBinding): void {\n config.shortcut = parseShortcut(config.shortcut);\n this._keyMap.set(config.shortcut, config);\n }\n\n unbind(binding: string): void {\n this._keyMap.delete(binding);\n }\n}\n\nconst ROOT = '';\n\n/**\n * Manages context-aware key bindings.\n */\nexport class Keyboard {\n static singleton = new Keyboard();\n\n private readonly _root = new KeyboardContext();\n private readonly _keyMap = new Map<string, KeyboardContext>([[ROOT, this._root]]);\n private readonly _contexts: string[] = [ROOT];\n private readonly _keyHandler = this.handleKeyDown.bind(this);\n private _path = ROOT;\n\n initialize(): void {\n document.addEventListener('keydown', this._keyHandler);\n }\n\n destroy(): void {\n document.removeEventListener('keydown', this._keyHandler);\n }\n\n bind = this._root.bind.bind(this._root);\n unbind = this._root.unbind.bind(this._root);\n\n setCurrentContext(path = ROOT): void {\n this._path = path;\n }\n\n getCurrentContext(): string {\n return this._path;\n }\n\n getContext(path = ROOT): KeyboardContext {\n let context = this._keyMap.get(path);\n if (!context) {\n context = new KeyboardContext();\n this._keyMap.set(path, context);\n this._contexts.push(path);\n this._contexts.sort();\n }\n\n return context;\n }\n\n getBindings(): KeyBinding[] {\n const bindings = new Map<string, KeyBinding>();\n for (let i = 0; i < this._contexts.length; ++i) {\n const path = this._contexts[i];\n if (this._path.startsWith(path)) {\n this.getContext(path).bindings.forEach((binding) => {\n bindings.set(binding.shortcut, binding);\n });\n }\n }\n\n return Array.from(bindings.values());\n }\n\n handleKeyDown(event: KeyboardEvent): void {\n const { altKey, ctrlKey, metaKey, shiftKey, key } = event;\n\n if (key !== 'Alt' && key !== 'Control' && key !== 'Meta' && key !== 'Shift') {\n // Binding option to check for input or contenteditable.\n const tagName = (event.target as any)?.tagName;\n const isInput =\n tagName === 'INPUT' || tagName === 'TEXTAREA' || (event.target as any)?.getAttribute('contenteditable');\n\n // Normalized key binding (order matters, see note above).\n const str = [ctrlKey && 'ctrl', shiftKey && 'shift', altKey && 'alt', metaKey && 'meta', key]\n .filter(Boolean)\n .join('+');\n\n // Scan matching contexts.\n for (let i = this._contexts.length - 1; i >= 0; --i) {\n const path = this._contexts[i];\n if (this._path.startsWith(path)) {\n const { data, handler, disableInput } = this.getContext(path).get(str) ?? {};\n if (handler && (!isInput || !disableInput)) {\n const result = handler({ context: path, shortcut: str, data, event });\n if (result !== false) {\n // TODO(burdon): This doesn't prevent actions in markdown editor.\n // Reference: https://codemirror.net/docs/ref/#view.KeyBinding\n event.preventDefault();\n event.stopPropagation();\n }\n\n return;\n }\n }\n }\n }\n }\n}\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { getHostPlatform } from '@dxos/util';\n\n// Resources.\n// https://www.w3.org/TR/DOM-Level-3-Events/#events-keyboardevents\n// https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key\n// https://developer.apple.com/design/human-interface-guidelines/designing-for-macos\n// https://support.apple.com/en-us/HT201236\n// https://support.apple.com/guide/mac-help/what-are-those-symbols-shown-in-menus-cpmh0011/mac\n\nconst ctrl: Record<string, string> = {\n macos: '⌃',\n ios: '⌃',\n windows: 'Ctrl',\n linux: 'Ctrl',\n unknown: 'Ctrl',\n};\n\nconst alt: Record<string, string> = {\n macos: '⌥',\n ios: '⌥',\n windows: 'Alt',\n linux: 'Alt',\n unknown: 'Alt',\n};\n\nconst meta: Record<string, string> = {\n macos: '⌘',\n ios: '⌘',\n windows: '⊞',\n // TODO(wittjosiah): Use ⌘ or ⊞ instead? Wait for user feedback.\n // From https://en.wikipedia.org/wiki/Super_key_(keyboard_button).\n linux: '❖',\n unknown: '❖',\n};\n\nconst getSymbol = (part: string) => {\n const platform = getHostPlatform();\n switch (part.toLowerCase()) {\n // Mods.\n case 'alt':\n return alt[platform];\n case 'ctrl':\n return ctrl[platform];\n case 'meta':\n return meta[platform];\n case 'shift':\n return '⇧';\n // Special keys.\n case 'backspace':\n return '⌫';\n case 'enter':\n return '⏎';\n case 'escape':\n return '⎋';\n case 'space':\n return '␣';\n case 'tab':\n return '⇥';\n default:\n return part.toUpperCase();\n }\n};\n\nexport const keySymbols = (keyBinding: string): string[] => {\n const parts = keyBinding.split('+');\n return parts.map(getSymbol);\n};\n"],
5
- "mappings": ";;;AAIA,SAASA,iBAAiB;;AAoB1B,IAAMC,YAAY;EAAC;EAAQ;EAAS;EAAO;;AAGpC,IAAMC,gBAAgB,CAACC,UAAkBC,YAAY,WAAM;AAChE,QAAMC,QAAQF,SAASG,YAAW,EAAGC,MAAMH,SAAAA;AAC3C,QAAMI,OAAOP,UAAUQ,OAAO,CAACC,QAAQL,MAAMM,SAASD,GAAAA,CAAAA;AACtDV,YAAUQ,KAAKI,WAAW,KAAKJ,KAAKI,WAAWP,MAAMO,SAAS,GAAA,QAAA;;;;;;;;;AAE9D,SAAOJ,KAAKI,SAAS;OAAIJ;IAAMH,MAAMA,MAAMO,SAAS,CAAA;IAAIC,KAAK,GAAA,IAAOV;AACtE;AAEA,IAAMW,kBAAN,MAAMA;EAAN;AACWC,mBAAU,oBAAIC,IAAAA;;EAEvB,IAAIC,WAAW;AACb,WAAOC,MAAMC,KAAK,KAAKJ,QAAQK,OAAM,CAAA;EAC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jJA,SAASC,uBAAuB;AAShC,IAAMC,OAA+B;EACnCC,OAAO;EACPC,KAAK;EACLC,SAAS;EACTC,OAAO;EACPC,SAAS;AACX;AAEA,IAAMC,MAA8B;EAClCL,OAAO;EACPC,KAAK;EACLC,SAAS;EACTC,OAAO;EACPC,SAAS;AACX;AAEA,IAAME,OAA+B;EACnCN,OAAO;EACPC,KAAK;EACLC,SAAS;;;EAGTC,OAAO;EACPC,SAAS;AACX;AAEA,IAAMG,YAAY,CAACC,SAAAA;AACjB,QAAMC,WAAWC,gBAAAA;AACjB,UAAQF,KAAKG,YAAW,GAAA;;IAEtB,KAAK;AACH,aAAON,IAAII,QAAAA;IACb,KAAK;AACH,aAAOV,KAAKU,QAAAA;IACd,KAAK;AACH,aAAOH,KAAKG,QAAAA;IACd,KAAK;AACH,aAAO;;IAET,KAAK;AACH,aAAO;IACT,KAAK;AACH,aAAO;IACT,KAAK;AACH,aAAO;IACT,KAAK;AACH,aAAO;IACT,KAAK;AACH,aAAO;IACT;AACE,aAAOD,KAAKI,YAAW;EAC3B;AACF;AAEO,IAAMC,aAAa,CAACC,eAAAA;AACzB,QAAMC,QAAQD,WAAWE,MAAM,GAAA;AAC/B,SAAOD,MAAME,IAAIV,SAAAA;AACnB;",
6
- "names": ["invariant", "modifiers", "parseShortcut", "shortcut", "delimiter", "parts", "toLowerCase", "split", "mods", "filter", "key", "includes", "length", "join", "KeyboardContext", "_keyMap", "Map", "bindings", "Array", "from", "values", "get", "binding", "bind", "config", "set", "unbind", "delete", "ROOT", "Keyboard", "_root", "_contexts", "_keyHandler", "handleKeyDown", "_path", "singleton", "initialize", "document", "addEventListener", "destroy", "removeEventListener", "setCurrentContext", "path", "getCurrentContext", "getContext", "context", "push", "sort", "getBindings", "i", "startsWith", "forEach", "event", "altKey", "ctrlKey", "metaKey", "shiftKey", "tagName", "target", "isInput", "getAttribute", "str", "Boolean", "data", "handler", "disableInput", "result", "preventDefault", "stopPropagation", "getHostPlatform", "ctrl", "macos", "ios", "windows", "linux", "unknown", "alt", "meta", "getSymbol", "part", "platform", "getHostPlatform", "toLowerCase", "toUpperCase", "keySymbols", "keyBinding", "parts", "split", "map"]
4
+ "sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { invariant } from '@dxos/invariant';\nimport { type MaybePromise } from '@dxos/util';\n\n// TODO(burdon): Replace with hotkeys-js, react-hotkeys, and react-hotkeys-hook.\n\nexport type KeyHandler = (props: {\n context: string;\n shortcut: string;\n data?: any;\n event: KeyboardEvent;\n}) => MaybePromise<boolean | void>;\n\nexport type KeyBinding = {\n shortcut: string;\n handler: KeyHandler;\n disableInput?: boolean;\n data?: any;\n};\n\n// Keybinding is normalized to this order.\n// https://support.apple.com/en-us/HT201236\nconst modifiers = ['ctrl', 'shift', 'alt', 'meta'];\n\n// Normalize order and case of modifiers.\nexport const parseShortcut = (shortcut: string, delimiter = /[+-]/): string => {\n const parts = shortcut.toLowerCase().split(delimiter);\n const mods = modifiers.filter((key) => parts.includes(key));\n invariant(mods.length === 0 || mods.length === parts.length - 1);\n // Assume single natural key.\n return mods.length ? [...mods, parts[parts.length - 1]].join('+') : shortcut;\n};\n\nclass KeyboardContext {\n readonly _keyMap = new Map<string, KeyBinding>();\n\n get bindings() {\n return Array.from(this._keyMap.values());\n }\n\n get(binding: string): KeyBinding | undefined {\n return this._keyMap.get(binding);\n }\n\n bind(config: KeyBinding): void {\n config.shortcut = parseShortcut(config.shortcut);\n this._keyMap.set(config.shortcut, config);\n }\n\n unbind(binding: string): void {\n this._keyMap.delete(binding);\n }\n}\n\nconst ROOT = '';\n\n/**\n * Manages context-aware key bindings.\n */\nexport class Keyboard {\n static singleton = new Keyboard();\n\n private readonly _root = new KeyboardContext();\n private readonly _keyMap = new Map<string, KeyboardContext>([[ROOT, this._root]]);\n private readonly _contexts: string[] = [ROOT];\n private readonly _keyHandler = this.handleKeyDown.bind(this);\n private _path = ROOT;\n\n initialize(): void {\n document.addEventListener('keydown', this._keyHandler);\n }\n\n destroy(): void {\n document.removeEventListener('keydown', this._keyHandler);\n }\n\n bind = this._root.bind.bind(this._root);\n unbind = this._root.unbind.bind(this._root);\n\n setCurrentContext(path = ROOT): void {\n this._path = path;\n }\n\n getCurrentContext(): string {\n return this._path;\n }\n\n getContext(path = ROOT): KeyboardContext {\n let context = this._keyMap.get(path);\n if (!context) {\n context = new KeyboardContext();\n this._keyMap.set(path, context);\n this._contexts.push(path);\n this._contexts.sort();\n }\n\n return context;\n }\n\n getBindings(): KeyBinding[] {\n const bindings = new Map<string, KeyBinding>();\n for (let i = 0; i < this._contexts.length; ++i) {\n const path = this._contexts[i];\n if (this._path.startsWith(path)) {\n this.getContext(path).bindings.forEach((binding) => {\n bindings.set(binding.shortcut, binding);\n });\n }\n }\n\n return Array.from(bindings.values());\n }\n\n async handleKeyDown(event: KeyboardEvent): Promise<void> {\n const { altKey, ctrlKey, metaKey, shiftKey, key } = event;\n\n if (key !== 'Alt' && key !== 'Control' && key !== 'Meta' && key !== 'Shift') {\n // Binding option to check for input or contenteditable.\n const tagName = (event.target as any)?.tagName;\n const isInput =\n tagName === 'INPUT' || tagName === 'TEXTAREA' || (event.target as any)?.getAttribute('contenteditable');\n\n // Normalized key binding (order matters, see note above).\n const str = [ctrlKey && 'ctrl', shiftKey && 'shift', altKey && 'alt', metaKey && 'meta', key]\n .filter(Boolean)\n .join('+');\n\n // Scan matching contexts.\n for (let i = this._contexts.length - 1; i >= 0; --i) {\n const path = this._contexts[i];\n if (this._path.startsWith(path)) {\n const { data, handler, disableInput } = this.getContext(path).get(str) ?? {};\n if (handler && (!isInput || !disableInput)) {\n const result = await handler({ context: path, shortcut: str, data, event });\n if (result !== false) {\n // TODO(burdon): This doesn't prevent actions in markdown editor.\n // Reference: https://codemirror.net/docs/ref/#view.KeyBinding\n event.preventDefault();\n event.stopPropagation();\n }\n\n return;\n }\n }\n }\n }\n }\n}\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { getHostPlatform } from '@dxos/util';\n\n// Resources.\n// https://www.w3.org/TR/DOM-Level-3-Events/#events-keyboardevents\n// https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key\n// https://developer.apple.com/design/human-interface-guidelines/designing-for-macos\n// https://support.apple.com/en-us/HT201236\n// https://support.apple.com/guide/mac-help/what-are-those-symbols-shown-in-menus-cpmh0011/mac\n\nconst ctrl: Record<string, string> = {\n macos: '⌃',\n ios: '⌃',\n windows: 'Ctrl',\n linux: 'Ctrl',\n unknown: 'Ctrl',\n};\n\nconst alt: Record<string, string> = {\n macos: '⌥',\n ios: '⌥',\n windows: 'Alt',\n linux: 'Alt',\n unknown: 'Alt',\n};\n\nconst meta: Record<string, string> = {\n macos: '⌘',\n ios: '⌘',\n windows: '⊞',\n // TODO(wittjosiah): Use ⌘ or ⊞ instead? Wait for user feedback.\n // From https://en.wikipedia.org/wiki/Super_key_(keyboard_button).\n linux: '❖',\n unknown: '❖',\n};\n\nconst getSymbol = (part: string) => {\n const platform = getHostPlatform();\n switch (part.toLowerCase()) {\n // Mods.\n case 'alt':\n return alt[platform];\n case 'ctrl':\n return ctrl[platform];\n case 'meta':\n return meta[platform];\n case 'shift':\n return '⇧';\n // Special keys.\n case 'backspace':\n return '⌫';\n case 'enter':\n return '⏎';\n case 'escape':\n return '⎋';\n case 'space':\n return '␣';\n case 'tab':\n return '⇥';\n default:\n return part.toUpperCase();\n }\n};\n\nexport const keySymbols = (keyBinding: string): string[] => {\n const parts = keyBinding.split('+');\n return parts.map(getSymbol);\n};\n"],
5
+ "mappings": ";;;AAIA,SAASA,iBAAiB;AAmB1B,IAAA,eAAA;IAE2B,YAAA;EAAS;EAAO;EAAO;EAElD;AACA;AAEE,IAAMC,gBAAiBC,CAAAA,UAAQC,YAAcC,WAASD;AACtDH,QAAAA,QAAUC,SAAW,YAAUA,EAAKI,MAAM,SAAKC;AAC/C,QAAA,OAAA,UAAA,OAA6B,CAAA,QAAA,MAAA,SAAA,GAAA,CAAA;AAC7B,YAAOL,KAAKI,WAAS,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;EACLC,SAAS;EACTC,OAAO;EACPC,SAAS;AACX;AAEA,IAAMC,MAA8B;EAClCL,OAAO;EACPC,KAAK;EACLC,SAAS;EACTC,OAAO;EACPC,SAAS;AACX;AAEA,IAAME,OAA+B;EACnCN,OAAO;EACPC,KAAK;EACLC,SAAS;;;EAGTC,OAAO;EACPC,SAAS;AACX;AAEA,IAAMG,YAAY,CAACC,SAAAA;AACjB,QAAMC,WAAWX,gBAAAA;AACjB,UAAQU,KAAKE,YAAW,GAAA;;IAEtB,KAAK;AACH,aAAOL,IAAII,QAAAA;IACb,KAAK;AACH,aAAOV,KAAKU,QAAAA;IACd,KAAK;AACH,aAAOH,KAAKG,QAAAA;IACd,KAAK;AACH,aAAO;;IAET,KAAK;AACH,aAAO;IACT,KAAK;AACH,aAAO;IACT,KAAK;AACH,aAAO;IACT,KAAK;AACH,aAAO;IACT,KAAK;AACH,aAAO;IACT;AACE,aAAOD,KAAKG,YAAW;EAC3B;AACF;AAEO,IAAMC,aAAa,CAACC,eAAAA;AACzB,QAAMC,QAAQD,WAAWE,MAAM,GAAA;AAC/B,SAAOD,MAAME,IAAIT,SAAAA;AACnB;",
6
+ "names": ["invariant", "mods", "filter", "key", "includes", "length", "parts", "join", "KeyboardContext", "Array", "from", "binding", "bind", "_keyMap", "unbind", "_root", "ROOT", "_contexts", "_keyHandler", "_path", "initialize", "document", "destroy", "setCurrentContext", "path", "getCurrentContext", "getContext", "context", "sort", "getBindings", "i", "startsWith", "bindings", "shortcut", "handleKeyDown", "event", "tagName", "target", "str", "shiftKey", "altKey", "metaKey", "Boolean", "data", "handler", "disableInput", "isInput", "result", "getHostPlatform", "ctrl", "macos", "ios", "windows", "linux", "unknown", "alt", "meta", "getSymbol", "part", "platform", "toLowerCase", "toUpperCase", "keySymbols", "keyBinding", "parts", "split", "map"]
7
7
  }
@@ -1 +1 @@
1
- {"inputs":{"src/keyboard.ts":{"bytes":15909,"imports":[{"path":"@dxos/invariant","kind":"import-statement","external":true}],"format":"esm"},"src/util.ts":{"bytes":5655,"imports":[{"path":"@dxos/util","kind":"import-statement","external":true}],"format":"esm"},"src/index.ts":{"bytes":531,"imports":[{"path":"src/keyboard.ts","kind":"import-statement","original":"./keyboard"},{"path":"src/util.ts","kind":"import-statement","original":"./util"}],"format":"esm"}},"outputs":{"dist/lib/node-esm/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":10669},"dist/lib/node-esm/index.mjs":{"imports":[{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"exports":["Keyboard","keySymbols","parseShortcut"],"entryPoint":"src/index.ts","inputs":{"src/keyboard.ts":{"bytesInOutput":3624},"src/index.ts":{"bytesInOutput":0},"src/util.ts":{"bytesInOutput":1184}},"bytes":5025}}}
1
+ {"inputs":{"src/keyboard.ts":{"bytes":15976,"imports":[{"path":"@dxos/invariant","kind":"import-statement","external":true}],"format":"esm"},"src/util.ts":{"bytes":5581,"imports":[{"path":"@dxos/util","kind":"import-statement","external":true}],"format":"esm"},"src/index.ts":{"bytes":456,"imports":[{"path":"src/keyboard.ts","kind":"import-statement","original":"./keyboard"},{"path":"src/util.ts","kind":"import-statement","original":"./util"}],"format":"esm"}},"outputs":{"dist/lib/node-esm/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":10173},"dist/lib/node-esm/index.mjs":{"imports":[{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"exports":["Keyboard","keySymbols","parseShortcut"],"entryPoint":"src/index.ts","inputs":{"src/keyboard.ts":{"bytesInOutput":3495},"src/index.ts":{"bytesInOutput":0},"src/util.ts":{"bytesInOutput":1184}},"bytes":4896}}}
@@ -1,9 +1,10 @@
1
+ import { type MaybePromise } from '@dxos/util';
1
2
  export type KeyHandler = (props: {
2
3
  context: string;
3
4
  shortcut: string;
4
5
  data?: any;
5
6
  event: KeyboardEvent;
6
- }) => boolean | void;
7
+ }) => MaybePromise<boolean | void>;
7
8
  export type KeyBinding = {
8
9
  shortcut: string;
9
10
  handler: KeyHandler;
@@ -36,7 +37,7 @@ export declare class Keyboard {
36
37
  getCurrentContext(): string;
37
38
  getContext(path?: string): KeyboardContext;
38
39
  getBindings(): KeyBinding[];
39
- handleKeyDown(event: KeyboardEvent): void;
40
+ handleKeyDown(event: KeyboardEvent): Promise<void>;
40
41
  }
41
42
  export {};
42
43
  //# sourceMappingURL=keyboard.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"keyboard.d.ts","sourceRoot":"","sources":["../../../src/keyboard.ts"],"names":[],"mappings":"AAQA,MAAM,MAAM,UAAU,GAAG,CAAC,KAAK,EAAE;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,KAAK,EAAE,aAAa,CAAC;CACtB,KAAK,OAAO,GAAG,IAAI,CAAC;AAErB,MAAM,MAAM,UAAU,GAAG;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,UAAU,CAAC;IACpB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,IAAI,CAAC,EAAE,GAAG,CAAC;CACZ,CAAC;AAOF,eAAO,MAAM,aAAa,GAAI,UAAU,MAAM,EAAE,kBAAkB,KAAG,MAMpE,CAAC;AAEF,cAAM,eAAe;IACnB,QAAQ,CAAC,OAAO,0BAAiC;IAEjD,IAAI,QAAQ,iBAEX;IAED,GAAG,CAAC,OAAO,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS;IAI5C,IAAI,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI;IAK9B,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;CAG9B;AAID;;GAEG;AACH,qBAAa,QAAQ;IACnB,MAAM,CAAC,SAAS,WAAkB;IAElC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAyB;IAC/C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA0D;IAClF,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UAAU,GAAG,IAAI,CAG7B;IAED,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAE5B;CACF;AAID;;GAEG;AACH,qBAAa,QAAQ;IACnB,MAAM,CAAC,SAAS,WAAkB;IAElC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAyB;IAC/C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA0D;IAClF,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAoB;IAC9C,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAiC;IAC7D,OAAO,CAAC,KAAK,CAAQ;IAErB,UAAU,IAAI,IAAI,CAEjB;IAED,OAAO,IAAI,IAAI,CAEd;IAED,IAAI,WAhCS,UAAU,KAAG,IAAI,CAgCU;IACxC,MAAM,YA5BU,MAAM,KAAG,IAAI,CA4Be;IAE5C,iBAAiB,CAAC,IAAI,SAAO,GAAG,IAAI,CAEnC;IAED,iBAAiB,IAAI,MAAM,CAE1B;IAED,UAAU,CAAC,IAAI,SAAO,GAAG,eAAe,CAUvC;IAED,WAAW,IAAI,UAAU,EAAE,CAY1B;IAEK,aAAa,CAAC,KAAK,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAiCvD;CACF"}
@@ -1,10 +1,11 @@
1
- import '@dxos-theme';
1
+ import { type StoryObj } from '@storybook/react-vite';
2
2
  import React from 'react';
3
- declare const _default: {
3
+ declare const meta: {
4
4
  title: string;
5
- decorators: import("@storybook/react").Decorator[];
6
5
  render: () => React.JSX.Element;
6
+ decorators: import("@storybook/react").Decorator[];
7
7
  };
8
- export default _default;
9
- export declare const Default: {};
8
+ export default meta;
9
+ type Story = StoryObj<typeof meta>;
10
+ export declare const Default: Story;
10
11
  //# sourceMappingURL=keyboard.stories.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"keyboard.stories.d.ts","sourceRoot":"","sources":["../../../src/keyboard.stories.tsx"],"names":[],"mappings":"AAIA,OAAO,aAAa,CAAC;AAErB,OAAO,KAA8B,MAAM,OAAO,CAAC;;;;;;AA+DnD,wBAIE;AAEF,eAAO,MAAM,OAAO,IAAK,CAAC"}
1
+ {"version":3,"file":"keyboard.stories.d.ts","sourceRoot":"","sources":["../../../src/keyboard.stories.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAa,KAAK,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjE,OAAO,KAA8B,MAAM,OAAO,CAAC;AA+DnD,QAAA,MAAM,IAAI;;;;CAIoB,CAAC;eAEhB,IAAI;AAEnB,KAAK,KAAK,GAAG,QAAQ,CAAC,OAAO,IAAI,CAAC,CAAC;AAEnC,eAAO,MAAM,OAAO,EAAE,KAAU,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../../src/util.ts"],"names":[],"mappings":"AAmEA,eAAO,MAAM,UAAU,GAAI,YAAY,MAAM,KAAG,MAAM,EAGrD,CAAC"}
1
+ {"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../../src/util.ts"],"names":[],"mappings":"AAmEA,eAAO,MAAM,UAAU,eAAgB,MAAM,KAAG,MAAM,EAGrD,CAAC"}