@dxos/app-framework 0.3.10-main.dcfebef → 0.3.10-main.e948ee0

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.
@@ -0,0 +1,100 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ import { DotOutline } from '@phosphor-icons/react';
6
+ import React, { useMemo, useRef } from 'react';
7
+
8
+ import { type Action, type Graph, type Label } from '@dxos/app-graph';
9
+ import { Keyboard, keySymbols } from '@dxos/keyboard';
10
+ import { Button, Dialog, useTranslation } from '@dxos/react-ui';
11
+ import { SearchList } from '@dxos/react-ui-searchlist';
12
+ import { descriptionText, getSize, mx } from '@dxos/react-ui-theme';
13
+
14
+ export const CommandsDialogContent = ({ graph }: { graph?: Graph }) => {
15
+ const { t } = useTranslation('os');
16
+
17
+ // TODO(burdon): Factor out.
18
+ // TODO(burdon): How to access all translations across plugins?
19
+ const toString = (label: Label) => (Array.isArray(label) ? t(...label) : label);
20
+
21
+ // Traverse graph.
22
+ // TODO(burdon): Factor out commonality with shortcut dialog.
23
+ const actions = useMemo(() => {
24
+ // TODO(burdon): Get from navtree (not keyboard).
25
+ const current = Keyboard.singleton.getCurrentContext();
26
+ const actionMap = new Set<string>();
27
+ const actions: Action[] = [];
28
+ graph?.traverse({
29
+ visitor: (node, path) => {
30
+ if (current.startsWith(path.join('/'))) {
31
+ node.actions.forEach((action) => {
32
+ if (!actionMap.has(action.id)) {
33
+ actionMap.add(action.id);
34
+ actions.push(action);
35
+ }
36
+ });
37
+ }
38
+ },
39
+ });
40
+
41
+ actions.sort(({ label: a }, { label: b }) => {
42
+ return toString(a)?.toLowerCase().localeCompare(toString(b)?.toLowerCase());
43
+ });
44
+
45
+ // console.log(JSON.stringify(actions, undefined, 2));
46
+ return actions;
47
+ }, [graph]);
48
+
49
+ // TODO(burdon): Remove.
50
+ const buttonRef = useRef<HTMLButtonElement>(null);
51
+
52
+ return (
53
+ <Dialog.Content classNames={['md:max-is-[30rem] overflow-hidden']}>
54
+ <Dialog.Title>{t('commands dialog title', { ns: 'os' })}</Dialog.Title>
55
+
56
+ {/* TODO(burdon): BUG: Overscrolls container. */}
57
+ <SearchList.Root label={t('commandlist input placeholder')} classNames='flex flex-col grow overflow-hidden my-2'>
58
+ <SearchList.Input placeholder={t('commandlist input placeholder')} classNames={mx('px-1 my-2')} />
59
+ <SearchList.Content classNames={['max-bs-[30rem] overflow-auto']}>
60
+ {actions?.map((action) => {
61
+ const label = toString(action.label);
62
+ const Icon = action.icon ?? DotOutline;
63
+ return (
64
+ <SearchList.Item
65
+ value={label}
66
+ key={action.id}
67
+ onSelect={() => {
68
+ if (action.properties.disabled) {
69
+ return;
70
+ }
71
+
72
+ // TODO(burdon): Remove hack to close dialog (via hook?)
73
+ buttonRef.current?.click();
74
+ setTimeout(() => {
75
+ void action.invoke();
76
+ });
77
+ }}
78
+ classNames='flex items-center gap-2'
79
+ disabled={action.properties.disabled}
80
+ {...(action.properties?.testId && { 'data-testid': action.properties.testId })}
81
+ >
82
+ <Icon className={mx(getSize(4), 'shrink-0', !action.icon && 'invisible')} />
83
+ <span className='grow truncate'>{label}</span>
84
+ {action.keyBinding && (
85
+ <span className={mx('shrink-0', descriptionText)}>{keySymbols(action.keyBinding).join('')}</span>
86
+ )}
87
+ </SearchList.Item>
88
+ );
89
+ })}
90
+ </SearchList.Content>
91
+ </SearchList.Root>
92
+
93
+ <Dialog.Close asChild>
94
+ <Button ref={buttonRef} variant='primary' classNames='mbs-2'>
95
+ {t('close label', { ns: 'os' })}
96
+ </Button>
97
+ </Dialog.Close>
98
+ </Dialog.Content>
99
+ );
100
+ };
@@ -4,7 +4,7 @@
4
4
 
5
5
  import React, { useState } from 'react';
6
6
 
7
- import { Button, DensityProvider, Dialog, List, ListItem, useTranslation } from '@dxos/react-ui';
7
+ import { Button, Dialog, List, ListItem, useTranslation } from '@dxos/react-ui';
8
8
  import { ghostHover, ghostSelected, groupBorder, mx } from '@dxos/react-ui-theme';
9
9
 
10
10
  import { type Plugin, usePlugins } from '../PluginHost';
@@ -31,41 +31,39 @@ export const SettingsDialogContent = () => {
31
31
  .map((plugin) => plugin!.meta)
32
32
  .sort(({ name: a }, { name: b }) => a?.localeCompare(b ?? '') ?? 0);
33
33
 
34
- // TODO(burdon): Vertical layout if mobile (pattern).
34
+ // TODO(burdon): Common treatment for dialogs (e.g., shrink height to fit, mobile, etc.)
35
35
  return (
36
- <DensityProvider density='fine'>
37
- <Dialog.Content classNames={['h-[90%] md:max-is-[40rem] overflow-hidden']}>
38
- <Dialog.Title>{t('settings dialog title', { ns: 'os' })}</Dialog.Title>
36
+ <Dialog.Content classNames={['h-full md:max-is-[40rem] overflow-hidden']}>
37
+ <Dialog.Title>{t('settings dialog title', { ns: 'os' })}</Dialog.Title>
39
38
 
40
- <div className='flex grow mlb-4 overflow-hidden'>
41
- <div className={mx('flex flex-col w-[200px] space-y-4 pr-4 border-r overflow-y-auto', groupBorder)}>
42
- <PluginList
43
- title='Options'
44
- plugins={core.map((id) => plugins.find((p) => p.meta.id === id)!.meta)}
45
- selected={plugin}
46
- onSelect={(plugin) => setPlugin(plugin)}
47
- />
39
+ <div className='flex grow mlb-4 overflow-hidden'>
40
+ <div className={mx('flex flex-col w-[200px] space-y-4 pr-4 border-r overflow-y-auto', groupBorder)}>
41
+ <PluginList
42
+ title='Options'
43
+ plugins={core.map((id) => plugins.find((p) => p.meta.id === id)!.meta)}
44
+ selected={plugin}
45
+ onSelect={(plugin) => setPlugin(plugin)}
46
+ />
48
47
 
49
- <PluginList
50
- title='Plugins'
51
- plugins={filteredPlugins}
52
- selected={plugin}
53
- onSelect={(plugin) => setPlugin(plugin)}
54
- />
55
- </div>
48
+ <PluginList
49
+ title='Plugins'
50
+ plugins={filteredPlugins}
51
+ selected={plugin}
52
+ onSelect={(plugin) => setPlugin(plugin)}
53
+ />
54
+ </div>
56
55
 
57
- <div className={mx('flex flex-col w-full md:px-4 divide-y overflow-y-auto', groupBorder)}>
58
- <Surface role='settings' data={{ plugin }} />
59
- </div>
56
+ <div className={mx('flex flex-col w-full md:px-4 divide-y overflow-y-auto', groupBorder)}>
57
+ <Surface role='settings' data={{ plugin }} />
60
58
  </div>
59
+ </div>
61
60
 
62
- <Dialog.Close asChild>
63
- <Button variant='primary' classNames='mbs-2'>
64
- {t('done label', { ns: 'os' })}
65
- </Button>
66
- </Dialog.Close>
67
- </Dialog.Content>
68
- </DensityProvider>
61
+ <Dialog.Close asChild>
62
+ <Button variant='primary' classNames='mbs-2' autoFocus>
63
+ {t('done label', { ns: 'os' })}
64
+ </Button>
65
+ </Dialog.Close>
66
+ </Dialog.Content>
69
67
  );
70
68
  };
71
69
 
@@ -2,6 +2,6 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
+ export * from './CommandsDialog';
5
6
  export * from './SettingsDialog';
6
7
  export * from './SettingsValue';
7
- export * from './ShortcutsDialog';
package/tsconfig.json CHANGED
@@ -38,6 +38,9 @@
38
38
  {
39
39
  "path": "../../ui/react-ui"
40
40
  },
41
+ {
42
+ "path": "../../ui/react-ui-searchlist"
43
+ },
41
44
  {
42
45
  "path": "../../ui/react-ui-theme"
43
46
  },
@@ -1,2 +0,0 @@
1
- export declare const ShortcutsDialogContent: () => JSX.Element;
2
- //# sourceMappingURL=ShortcutsDialog.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ShortcutsDialog.d.ts","sourceRoot":"","sources":["../../../../../src/plugins/components/ShortcutsDialog.tsx"],"names":[],"mappings":"AAWA,eAAO,MAAM,sBAAsB,mBAiDlC,CAAC"}
@@ -1,61 +0,0 @@
1
- //
2
- // Copyright 2023 DXOS.org
3
- //
4
-
5
- import React from 'react';
6
-
7
- import { type Label } from '@dxos/app-graph';
8
- import { Keyboard, keySymbols } from '@dxos/keyboard';
9
- import { Button, Dialog, DensityProvider, useTranslation } from '@dxos/react-ui';
10
- import { mx } from '@dxos/react-ui-theme';
11
-
12
- export const ShortcutsDialogContent = () => {
13
- const { t } = useTranslation('os');
14
-
15
- const bindings = Keyboard.singleton.getBindings();
16
-
17
- // TODO(burdon): Factor out.
18
- // TODO(burdon): How to access all translations across plugins?
19
- const getLabel = (label: Label) => (Array.isArray(label) ? t(...label) : label);
20
-
21
- return (
22
- <DensityProvider density='fine'>
23
- <Dialog.Content classNames={['md:max-is-[30rem] overflow-hidden']}>
24
- <Dialog.Title>{t('shortcuts dialog title', { ns: 'os' })}</Dialog.Title>
25
-
26
- <table className='table-fixed border-collapse my-4'>
27
- <tbody>
28
- {bindings.map((binding, i) => (
29
- <tr key={i}>
30
- <td className='p-1 w-[120px]'>
31
- <div className='flex gap-1'>
32
- {keySymbols(binding.binding).map((c, i) => (
33
- <span
34
- key={i}
35
- className={mx(
36
- 'inline-flex w-[24px] h-[24px] justify-center items-center text-xs',
37
- 'rounded border border-neutral-300 dark:border-neutral-600 bg-neutral-50 dark:bg-neutral-850',
38
- )}
39
- >
40
- {c}
41
- </span>
42
- ))}
43
- </div>
44
- </td>
45
- <td className='p-1'>
46
- <span className='grow truncate'>{getLabel(binding.data as Label)}</span>
47
- </td>
48
- </tr>
49
- ))}
50
- </tbody>
51
- </table>
52
-
53
- <Dialog.Close asChild>
54
- <Button variant='primary' classNames='mbs-2'>
55
- {t('close label', { ns: 'os' })}
56
- </Button>
57
- </Dialog.Close>
58
- </Dialog.Content>
59
- </DensityProvider>
60
- );
61
- };