@dxos/app-framework 0.3.10-main.ec4f2f4 → 0.3.10-main.f460bb8

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,16 +4,18 @@
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';
11
11
  import { Surface } from '../SurfacePlugin';
12
12
 
13
+ // TODO(burdon): Move into separate plugin.
13
14
  export const SettingsDialogContent = () => {
15
+ const { t } = useTranslation('os');
16
+
14
17
  // TODO(burdon): Store preview tab.
15
18
  const [plugin, setPlugin] = useState<string>('dxos.org/plugin/registry');
16
- const { t } = useTranslation('os');
17
19
  const { plugins, enabled } = usePlugins();
18
20
 
19
21
  const core = [
@@ -29,41 +31,39 @@ export const SettingsDialogContent = () => {
29
31
  .map((plugin) => plugin!.meta)
30
32
  .sort(({ name: a }, { name: b }) => a?.localeCompare(b ?? '') ?? 0);
31
33
 
32
- // TODO(burdon): Vertical layout if mobile.
34
+ // TODO(burdon): Common treatment for dialogs (e.g., shrink height to fit, mobile, etc.)
33
35
  return (
34
- <DensityProvider density='fine'>
35
- <Dialog.Content classNames={['h-[90%] md:max-is-[40rem] overflow-hidden']}>
36
- <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>
37
38
 
38
- <div className='flex grow mlb-4 overflow-hidden'>
39
- <div className={mx('flex flex-col w-[200px] space-y-4 pr-4 border-r overflow-y-auto', groupBorder)}>
40
- <PluginList
41
- title='Options'
42
- plugins={core.map((id) => plugins.find((p) => p.meta.id === id)!.meta)}
43
- selected={plugin}
44
- onSelect={(plugin) => setPlugin(plugin)}
45
- />
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
+ />
46
47
 
47
- <PluginList
48
- title='Plugins'
49
- plugins={filteredPlugins}
50
- selected={plugin}
51
- onSelect={(plugin) => setPlugin(plugin)}
52
- />
53
- </div>
48
+ <PluginList
49
+ title='Plugins'
50
+ plugins={filteredPlugins}
51
+ selected={plugin}
52
+ onSelect={(plugin) => setPlugin(plugin)}
53
+ />
54
+ </div>
54
55
 
55
- <div className={mx('flex flex-col w-full md:px-4 divide-y overflow-y-auto', groupBorder)}>
56
- <Surface role='settings' data={{ plugin }} />
57
- </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 }} />
58
58
  </div>
59
+ </div>
59
60
 
60
- <Dialog.Close asChild>
61
- <Button variant='primary' classNames='mbs-2'>
62
- {t('done label', { ns: 'os' })}
63
- </Button>
64
- </Dialog.Close>
65
- </Dialog.Content>
66
- </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>
67
67
  );
68
68
  };
69
69
 
@@ -2,5 +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';
package/tsconfig.json CHANGED
@@ -26,6 +26,9 @@
26
26
  {
27
27
  "path": "../../common/invariant"
28
28
  },
29
+ {
30
+ "path": "../../common/keyboard"
31
+ },
29
32
  {
30
33
  "path": "../../common/local-storage"
31
34
  },
@@ -35,9 +38,15 @@
35
38
  {
36
39
  "path": "../../ui/react-ui"
37
40
  },
41
+ {
42
+ "path": "../../ui/react-ui-searchlist"
43
+ },
38
44
  {
39
45
  "path": "../../ui/react-ui-theme"
40
46
  },
47
+ {
48
+ "path": "../../ui/storybook-utils"
49
+ },
41
50
  {
42
51
  "path": "../app-graph"
43
52
  }