@dxos/keyboard 0.8.4-main.84f28bd → 0.8.4-main.937b3ca

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/package.json CHANGED
@@ -1,15 +1,20 @@
1
1
  {
2
2
  "name": "@dxos/keyboard",
3
- "version": "0.8.4-main.84f28bd",
3
+ "version": "0.8.4-main.937b3ca",
4
4
  "description": "Keyboard bindings",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/dxos/dxos"
10
+ },
7
11
  "license": "MIT",
8
12
  "author": "DXOS.org",
9
13
  "sideEffects": true,
10
14
  "type": "module",
11
15
  "exports": {
12
16
  ".": {
17
+ "source": "./src/index.ts",
13
18
  "types": "./dist/types/src/index.d.ts",
14
19
  "browser": "./dist/lib/browser/index.mjs",
15
20
  "node": "./dist/lib/node-esm/index.mjs"
@@ -24,16 +29,16 @@
24
29
  "src"
25
30
  ],
26
31
  "dependencies": {
27
- "@dxos/invariant": "0.8.4-main.84f28bd",
28
- "@dxos/node-std": "0.8.4-main.84f28bd",
29
- "@dxos/util": "0.8.4-main.84f28bd"
32
+ "@dxos/invariant": "0.8.4-main.937b3ca",
33
+ "@dxos/node-std": "0.8.4-main.937b3ca",
34
+ "@dxos/util": "0.8.4-main.937b3ca"
30
35
  },
31
36
  "devDependencies": {
32
- "react": "~18.2.0",
33
- "react-dom": "~18.2.0",
34
- "@dxos/react-ui": "0.8.4-main.84f28bd",
35
- "@dxos/react-ui-theme": "0.8.4-main.84f28bd",
36
- "@dxos/storybook-utils": "0.8.4-main.84f28bd"
37
+ "react": "~19.2.3",
38
+ "react-dom": "~19.2.3",
39
+ "@dxos/storybook-utils": "0.8.4-main.937b3ca",
40
+ "@dxos/react-ui": "0.8.4-main.937b3ca",
41
+ "@dxos/ui-theme": "0.8.4-main.937b3ca"
37
42
  },
38
43
  "publishConfig": {
39
44
  "access": "public"
@@ -2,12 +2,11 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- import '@dxos-theme';
6
-
5
+ import { type Meta, type StoryObj } from '@storybook/react-vite';
7
6
  import React, { useEffect, useState } from 'react';
8
7
 
9
- import { Select, Input } from '@dxos/react-ui';
10
- import { withTheme } from '@dxos/storybook-utils';
8
+ import { Input, Select } from '@dxos/react-ui';
9
+ import { withTheme } from '@dxos/react-ui/testing';
11
10
 
12
11
  import { type KeyHandler, Keyboard } from './keyboard';
13
12
 
@@ -67,10 +66,14 @@ const DefaultStory = () => {
67
66
  );
68
67
  };
69
68
 
70
- export default {
69
+ const meta = {
71
70
  title: 'common/keyboard/Keyboard',
72
- decorators: [withTheme],
73
71
  render: DefaultStory,
74
- };
72
+ decorators: [withTheme],
73
+ } satisfies Meta<typeof Input>;
74
+
75
+ export default meta;
76
+
77
+ type Story = StoryObj<typeof meta>;
75
78
 
76
- export const Default = {};
79
+ export const Default: Story = {};
package/src/keyboard.ts CHANGED
@@ -3,6 +3,7 @@
3
3
  //
4
4
 
5
5
  import { invariant } from '@dxos/invariant';
6
+ import { type MaybePromise } from '@dxos/util';
6
7
 
7
8
  // TODO(burdon): Replace with hotkeys-js, react-hotkeys, and react-hotkeys-hook.
8
9
 
@@ -11,7 +12,7 @@ export type KeyHandler = (props: {
11
12
  shortcut: string;
12
13
  data?: any;
13
14
  event: KeyboardEvent;
14
- }) => boolean | void;
15
+ }) => MaybePromise<boolean | void>;
15
16
 
16
17
  export type KeyBinding = {
17
18
  shortcut: string;
@@ -113,7 +114,7 @@ export class Keyboard {
113
114
  return Array.from(bindings.values());
114
115
  }
115
116
 
116
- handleKeyDown(event: KeyboardEvent): void {
117
+ async handleKeyDown(event: KeyboardEvent): Promise<void> {
117
118
  const { altKey, ctrlKey, metaKey, shiftKey, key } = event;
118
119
 
119
120
  if (key !== 'Alt' && key !== 'Control' && key !== 'Meta' && key !== 'Shift') {
@@ -133,7 +134,7 @@ export class Keyboard {
133
134
  if (this._path.startsWith(path)) {
134
135
  const { data, handler, disableInput } = this.getContext(path).get(str) ?? {};
135
136
  if (handler && (!isInput || !disableInput)) {
136
- const result = handler({ context: path, shortcut: str, data, event });
137
+ const result = await handler({ context: path, shortcut: str, data, event });
137
138
  if (result !== false) {
138
139
  // TODO(burdon): This doesn't prevent actions in markdown editor.
139
140
  // Reference: https://codemirror.net/docs/ref/#view.KeyBinding