@dxos/plugin-help 0.6.8-main.046e6cf

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.
Files changed (70) hide show
  1. package/LICENSE +8 -0
  2. package/README.md +15 -0
  3. package/dist/lib/browser/chunk-DI4HXWTJ.mjs +23 -0
  4. package/dist/lib/browser/chunk-DI4HXWTJ.mjs.map +7 -0
  5. package/dist/lib/browser/index.mjs +551 -0
  6. package/dist/lib/browser/index.mjs.map +7 -0
  7. package/dist/lib/browser/meta.json +1 -0
  8. package/dist/lib/browser/meta.mjs +11 -0
  9. package/dist/lib/browser/meta.mjs.map +7 -0
  10. package/dist/types/src/HelpPlugin.d.ts +11 -0
  11. package/dist/types/src/HelpPlugin.d.ts.map +1 -0
  12. package/dist/types/src/components/HelpContextProvider/HelpContextProvider.d.ts +10 -0
  13. package/dist/types/src/components/HelpContextProvider/HelpContextProvider.d.ts.map +1 -0
  14. package/dist/types/src/components/HelpContextProvider/HelpContextProvider.stories.d.ts +31 -0
  15. package/dist/types/src/components/HelpContextProvider/HelpContextProvider.stories.d.ts.map +1 -0
  16. package/dist/types/src/components/HelpContextProvider/index.d.ts +2 -0
  17. package/dist/types/src/components/HelpContextProvider/index.d.ts.map +1 -0
  18. package/dist/types/src/components/Shortcuts/Key.d.ts +5 -0
  19. package/dist/types/src/components/Shortcuts/Key.d.ts.map +1 -0
  20. package/dist/types/src/components/Shortcuts/ShortcutsDialog.d.ts +3 -0
  21. package/dist/types/src/components/Shortcuts/ShortcutsDialog.d.ts.map +1 -0
  22. package/dist/types/src/components/Shortcuts/ShortcutsHints.d.ts +5 -0
  23. package/dist/types/src/components/Shortcuts/ShortcutsHints.d.ts.map +1 -0
  24. package/dist/types/src/components/Shortcuts/ShortcutsList.d.ts +3 -0
  25. package/dist/types/src/components/Shortcuts/ShortcutsList.d.ts.map +1 -0
  26. package/dist/types/src/components/Shortcuts/ShortcutsSection.d.ts +3 -0
  27. package/dist/types/src/components/Shortcuts/ShortcutsSection.d.ts.map +1 -0
  28. package/dist/types/src/components/Shortcuts/index.d.ts +6 -0
  29. package/dist/types/src/components/Shortcuts/index.d.ts.map +1 -0
  30. package/dist/types/src/components/Shortcuts/styles.d.ts +2 -0
  31. package/dist/types/src/components/Shortcuts/styles.d.ts.map +1 -0
  32. package/dist/types/src/components/Tooltip/Tooltip.d.ts +44 -0
  33. package/dist/types/src/components/Tooltip/Tooltip.d.ts.map +1 -0
  34. package/dist/types/src/components/Tooltip/index.d.ts +2 -0
  35. package/dist/types/src/components/Tooltip/index.d.ts.map +1 -0
  36. package/dist/types/src/components/index.d.ts +4 -0
  37. package/dist/types/src/components/index.d.ts.map +1 -0
  38. package/dist/types/src/hooks/index.d.ts +2 -0
  39. package/dist/types/src/hooks/index.d.ts.map +1 -0
  40. package/dist/types/src/hooks/useHelp.d.ts +2 -0
  41. package/dist/types/src/hooks/useHelp.d.ts.map +1 -0
  42. package/dist/types/src/index.d.ts +8 -0
  43. package/dist/types/src/index.d.ts.map +1 -0
  44. package/dist/types/src/meta.d.ts +18 -0
  45. package/dist/types/src/meta.d.ts.map +1 -0
  46. package/dist/types/src/translations.d.ts +12 -0
  47. package/dist/types/src/translations.d.ts.map +1 -0
  48. package/dist/types/src/types.d.ts +20 -0
  49. package/dist/types/src/types.d.ts.map +1 -0
  50. package/package.json +71 -0
  51. package/src/HelpPlugin.tsx +140 -0
  52. package/src/components/HelpContextProvider/HelpContextProvider.stories.tsx +112 -0
  53. package/src/components/HelpContextProvider/HelpContextProvider.tsx +176 -0
  54. package/src/components/HelpContextProvider/index.ts +5 -0
  55. package/src/components/Shortcuts/Key.tsx +21 -0
  56. package/src/components/Shortcuts/ShortcutsDialog.tsx +30 -0
  57. package/src/components/Shortcuts/ShortcutsHints.tsx +43 -0
  58. package/src/components/Shortcuts/ShortcutsList.tsx +35 -0
  59. package/src/components/Shortcuts/ShortcutsSection.tsx +16 -0
  60. package/src/components/Shortcuts/index.ts +9 -0
  61. package/src/components/Shortcuts/styles.ts +10 -0
  62. package/src/components/Tooltip/Tooltip.tsx +111 -0
  63. package/src/components/Tooltip/index.ts +5 -0
  64. package/src/components/index.ts +7 -0
  65. package/src/hooks/index.ts +5 -0
  66. package/src/hooks/useHelp.tsx +13 -0
  67. package/src/index.ts +15 -0
  68. package/src/meta.tsx +23 -0
  69. package/src/translations.ts +18 -0
  70. package/src/types.ts +38 -0
@@ -0,0 +1,140 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ import { type IconProps, Keyboard as KeyboardIcon, Info } from '@phosphor-icons/react';
6
+ import React from 'react';
7
+
8
+ import { resolvePlugin, type PluginDefinition, parseIntentPlugin, LayoutAction } from '@dxos/app-framework';
9
+ import { createExtension, type Node } from '@dxos/app-graph';
10
+ import { create } from '@dxos/echo-schema';
11
+ import { LocalStorageStore } from '@dxos/local-storage';
12
+
13
+ import { HelpContextProvider, ShortcutsDialogContent, ShortcutsHints, ShortcutsList } from './components';
14
+ import meta, { HelpAction, HELP_PLUGIN } from './meta';
15
+ import translations from './translations';
16
+ import { type Step, type HelpPluginProvides } from './types';
17
+
18
+ export type HelpSettingsProps = { showHints?: boolean; showWelcome?: boolean };
19
+
20
+ export type HelpPluginOptions = { steps?: Step[] };
21
+
22
+ export const HelpPlugin = ({ steps = [] }: HelpPluginOptions): PluginDefinition<HelpPluginProvides> => {
23
+ const settings = new LocalStorageStore<HelpSettingsProps>(HELP_PLUGIN, { showHints: true, showWelcome: true });
24
+ const state = create<{ running: boolean }>({ running: false });
25
+ return {
26
+ meta,
27
+ ready: async () => {
28
+ settings
29
+ .prop({ key: 'showHints', storageKey: 'show-hints', type: LocalStorageStore.bool({ allowUndefined: true }) })
30
+ .prop({
31
+ key: 'showWelcome',
32
+ storageKey: 'show-welcome',
33
+ type: LocalStorageStore.bool({ allowUndefined: true }),
34
+ });
35
+ },
36
+ provides: {
37
+ context: ({ children }) => {
38
+ return (
39
+ <HelpContextProvider
40
+ steps={steps}
41
+ running={state.running}
42
+ onRunningChanged={(newState) => {
43
+ state.running = newState;
44
+ if (!newState) {
45
+ settings.values.showHints = false;
46
+ }
47
+ }}
48
+ >
49
+ {children}
50
+ </HelpContextProvider>
51
+ );
52
+ },
53
+ translations,
54
+ graph: {
55
+ builder: (plugins) => {
56
+ const intentPlugin = resolvePlugin(plugins, parseIntentPlugin)!;
57
+
58
+ return createExtension({
59
+ id: HELP_PLUGIN,
60
+ filter: (node): node is Node<null> => node.id === 'root',
61
+ actions: () => [
62
+ {
63
+ id: HelpAction.START,
64
+ data: async () => {
65
+ settings.values.showHints = true;
66
+ await intentPlugin?.provides.intent.dispatch({
67
+ plugin: HELP_PLUGIN,
68
+ action: HelpAction.START,
69
+ });
70
+ },
71
+ properties: {
72
+ label: ['open help tour', { ns: HELP_PLUGIN }],
73
+ icon: (props: IconProps) => <Info {...props} />,
74
+ iconSymbol: 'ph--info--regular',
75
+ keyBinding: {
76
+ macos: 'shift+meta+/',
77
+ // TODO(wittjosiah): Test on windows to see if it behaves the same as linux.
78
+ windows: 'shift+ctrl+/',
79
+ linux: 'shift+ctrl+?',
80
+ },
81
+ testId: 'helpPlugin.openHelp',
82
+ },
83
+ },
84
+ {
85
+ id: 'dxos.org/plugin/help/open-shortcuts',
86
+ data: async () => {
87
+ settings.values.showHints = true;
88
+ await intentPlugin?.provides.intent.dispatch({
89
+ action: LayoutAction.SET_LAYOUT,
90
+ data: {
91
+ element: 'dialog',
92
+ component: `${HELP_PLUGIN}/Shortcuts`,
93
+ },
94
+ });
95
+ },
96
+ properties: {
97
+ label: ['open shortcuts label', { ns: HELP_PLUGIN }],
98
+ icon: (props: IconProps) => <KeyboardIcon {...props} />,
99
+ iconSymbol: 'ph--keyboard--regular',
100
+ keyBinding: {
101
+ macos: 'meta+/',
102
+ windows: 'ctrl+/',
103
+ },
104
+ },
105
+ },
106
+ ],
107
+ });
108
+ },
109
+ },
110
+ surface: {
111
+ component: ({ data, role }) => {
112
+ switch (role) {
113
+ case 'hints':
114
+ return settings.values.showHints ? (
115
+ <ShortcutsHints onClose={() => (settings.values.showHints = false)} />
116
+ ) : null;
117
+ case 'keyshortcuts':
118
+ return <ShortcutsList />;
119
+ }
120
+
121
+ switch (data.component) {
122
+ case `${HELP_PLUGIN}/Shortcuts`:
123
+ return <ShortcutsDialogContent />;
124
+ }
125
+
126
+ return null;
127
+ },
128
+ },
129
+ intent: {
130
+ resolver: async (intent) => {
131
+ switch (intent.action) {
132
+ case HelpAction.START:
133
+ state.running = true;
134
+ break;
135
+ }
136
+ },
137
+ },
138
+ },
139
+ };
140
+ };
@@ -0,0 +1,112 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ import '@dxosTheme';
6
+
7
+ import { Circle } from '@phosphor-icons/react';
8
+ import React, { type FC, useState } from 'react';
9
+ import { type Step } from 'react-joyride';
10
+
11
+ import { faker } from '@dxos/random';
12
+ import { Button } from '@dxos/react-ui';
13
+ import { type Meta, withTheme } from '@dxos/storybook-utils';
14
+
15
+ import { HelpContextProvider } from './HelpContextProvider';
16
+ import { useHelp } from '../../hooks';
17
+
18
+ const App = () => {
19
+ const { running, start } = useHelp();
20
+ const [items, setItems] = useState(() => Array.from({ length: 5 }).map(() => faker.lorem.sentence()));
21
+ const handleAdd = () => {
22
+ setItems((items) => [...items, faker.lorem.sentence()]);
23
+ };
24
+
25
+ return (
26
+ <div className='flex flex-col h-full p-4 space-y-8'>
27
+ <div className='flex items-center gap-2 py-2'>
28
+ <Button data-joyride='basic/1' onClick={() => start()}>
29
+ Start
30
+ </Button>
31
+ <div className='grow' />
32
+ <div>{String(running)}</div>
33
+ </div>
34
+ <div>
35
+ <ul className='p-2 border border-blue-500 rounded-md' data-joyride='basic/2'>
36
+ {items.map((item, i) => (
37
+ <li key={i} className='flex items-center gap-2'>
38
+ <Circle />
39
+ <span>{item}</span>
40
+ </li>
41
+ ))}
42
+ </ul>
43
+ </div>
44
+ <div className='flex items-center gap-2 py-2'>
45
+ <Button data-joyride='basic/3' onClick={handleAdd}>
46
+ Add
47
+ </Button>
48
+ </div>
49
+ <div className='flex grow' />
50
+ <div className='flex items-center py-2'>
51
+ <div className='grow' />
52
+ <Circle data-joyride='basic/4' />
53
+ <Circle />
54
+ <Circle />
55
+ </div>
56
+ </div>
57
+ );
58
+ };
59
+
60
+ const Story: FC<{ steps?: Step[] }> = ({ steps = [] }) => (
61
+ <HelpContextProvider steps={steps}>
62
+ <div className='fixed inset-0 overflow-hidden'>
63
+ <App />
64
+ </div>
65
+ </HelpContextProvider>
66
+ );
67
+
68
+ /**
69
+ * IMPORTANT: Storybook must be run in separate tab.
70
+ */
71
+ const meta: Meta = {
72
+ title: 'plugin-help/Joyride',
73
+ render: (args: any) => <Story {...args} />,
74
+ decorators: [withTheme],
75
+ };
76
+
77
+ export default meta;
78
+
79
+ // TODO(burdon): Tour should prompt user to create a Stack -- and respond to it being created.
80
+ // Use beacon to simulate click.
81
+
82
+ export const Default = {
83
+ args: {
84
+ // https://docs.react-joyride.com/step#options
85
+ steps: [
86
+ {
87
+ target: '[data-joyride="basic/1"]',
88
+ title: 'Step 1',
89
+ content: faker.lorem.paragraph(),
90
+ disableBeacon: true,
91
+ placement: 'right',
92
+ },
93
+ {
94
+ target: '[data-joyride="basic/2"]',
95
+ title: 'Step 2',
96
+ content: faker.lorem.paragraph(),
97
+ },
98
+ {
99
+ target: '[data-joyride="basic/3"]',
100
+ title: 'Step 3',
101
+ content: faker.lorem.paragraph(),
102
+ placement: 'right',
103
+ },
104
+ {
105
+ target: '[data-joyride="basic/4"]',
106
+ title: 'Step 4',
107
+ content: faker.lorem.paragraph(),
108
+ placement: 'top-end',
109
+ },
110
+ ],
111
+ },
112
+ };
@@ -0,0 +1,176 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ import React, { type PropsWithChildren, useState, useEffect } from 'react';
6
+ import Joyride, { ACTIONS, EVENTS } from 'react-joyride';
7
+
8
+ import { usePlugins, resolvePlugin, parseLayoutPlugin } from '@dxos/app-framework';
9
+ import { useShellDisplay, ShellDisplay } from '@dxos/react-client';
10
+ // import { useThemeContext } from '@dxos/react-ui';
11
+ import { tailwindConfig, type TailwindConfig } from '@dxos/react-ui-theme';
12
+
13
+ import { type Step, HelpContext } from '../../types';
14
+ import { floaterProps, Tooltip } from '../Tooltip';
15
+
16
+ export const tokens: TailwindConfig['theme'] = tailwindConfig({}).theme;
17
+
18
+ const addStepClass = (target: string | HTMLElement) => {
19
+ const element = typeof target === 'string' ? document.querySelector(target) : target;
20
+ if (element) {
21
+ element.classList.add('joyride-target');
22
+ }
23
+ };
24
+
25
+ const removeTargetClass = (target: string | HTMLElement) => {
26
+ const element = typeof target === 'string' ? document.querySelector(target) : target;
27
+ if (element) {
28
+ element.classList.remove('joyride-target');
29
+ }
30
+ };
31
+
32
+ const getTarget = (step: Step) => {
33
+ return typeof step.target === 'string' ? document.querySelector(step.target) : step.target;
34
+ };
35
+
36
+ /**
37
+ * Wait for the target element to be in the document.
38
+ */
39
+ const waitForTarget = async (step: Step) => {
40
+ if (typeof step.target === 'string') {
41
+ const target = step.target;
42
+ const element = document.querySelector(target);
43
+ if (element) {
44
+ return;
45
+ }
46
+
47
+ await new Promise<void>((resolve) => {
48
+ const observer = new MutationObserver((mutations) => {
49
+ mutations.forEach((mutation) => {
50
+ if (mutation.addedNodes.length > 0) {
51
+ const element = document.querySelector(target);
52
+ if (element) {
53
+ observer.disconnect();
54
+ resolve();
55
+ }
56
+ }
57
+ });
58
+ });
59
+
60
+ observer.observe(document.body, { childList: true, subtree: true });
61
+ });
62
+ }
63
+ };
64
+
65
+ export const HelpContextProvider = ({
66
+ children,
67
+ steps: initialSteps,
68
+ running: runningProp,
69
+ onRunningChanged,
70
+ }: PropsWithChildren<{ steps: Step[]; running?: boolean; onRunningChanged?: (state: boolean) => any }>) => {
71
+ const shellDisplay = useShellDisplay();
72
+ const { plugins } = usePlugins();
73
+ const layoutPlugin = resolvePlugin(plugins, parseLayoutPlugin);
74
+ const [running, setRunning] = useState(!!runningProp && !!getTarget(initialSteps[0]));
75
+ const [stepIndex, _setStepIndex] = useState(0);
76
+ const [steps, setSteps] = useState(initialSteps);
77
+
78
+ const paused = shellDisplay !== ShellDisplay.NONE || layoutPlugin?.provides.layout.dialogOpen;
79
+
80
+ const setStepIndex = (index: number) => {
81
+ if (runningProp) {
82
+ const step = steps[index];
83
+ step?.before?.({ plugins, step });
84
+ }
85
+ _setStepIndex(index);
86
+ };
87
+
88
+ const setRunningChanged = (state: boolean) => {
89
+ if (typeof runningProp !== 'undefined') {
90
+ onRunningChanged?.(state);
91
+ } else {
92
+ if (state) {
93
+ setStepIndex(0);
94
+ setRunning(true);
95
+ } else {
96
+ setRunning(false);
97
+ }
98
+ }
99
+ };
100
+
101
+ useEffect(() => {
102
+ const timeout = setTimeout(async () => {
103
+ if (runningProp) {
104
+ // This handles the case when the target is not yet in the document.
105
+ // If the target is not in the document, when the joyride is turned on, it will not show the tooltip.
106
+ await waitForTarget(steps[stepIndex]);
107
+ setStepIndex(0);
108
+ setRunning(true);
109
+ } else if (typeof runningProp !== 'undefined') {
110
+ setRunning(false);
111
+ }
112
+ });
113
+
114
+ return () => clearTimeout(timeout);
115
+ }, [runningProp]);
116
+
117
+ // https://docs.react-joyride.com/callback
118
+ const callback: Joyride['callback'] = async (options) => {
119
+ const { type, action, index, size } = options;
120
+ switch (type) {
121
+ case EVENTS.STEP_BEFORE:
122
+ addStepClass(options.step.target);
123
+ break;
124
+ case EVENTS.TOUR_END:
125
+ break;
126
+ case EVENTS.STEP_AFTER:
127
+ removeTargetClass(options.step.target);
128
+ switch (action) {
129
+ case ACTIONS.NEXT:
130
+ if (index < size - 1) {
131
+ setStepIndex(index + 1);
132
+ }
133
+ break;
134
+ case ACTIONS.PREV:
135
+ if (index > 0) {
136
+ setStepIndex(index - 1);
137
+ }
138
+ break;
139
+ case ACTIONS.CLOSE:
140
+ setRunningChanged(false);
141
+ setStepIndex(0);
142
+ break;
143
+ }
144
+ break;
145
+ }
146
+ };
147
+
148
+ return (
149
+ <HelpContext.Provider
150
+ value={{
151
+ running: running && !paused,
152
+ steps,
153
+ setSteps,
154
+ setIndex: setStepIndex,
155
+ start: () => setRunningChanged(true),
156
+ stop: () => setRunningChanged(false),
157
+ }}
158
+ >
159
+ <style>
160
+ {`.joyride-target {
161
+ --controls-opacity: 1;
162
+ }`}
163
+ </style>
164
+ <Joyride
165
+ continuous={true}
166
+ steps={steps}
167
+ stepIndex={stepIndex}
168
+ run={running && !paused}
169
+ callback={callback}
170
+ floaterProps={floaterProps}
171
+ tooltipComponent={Tooltip}
172
+ />
173
+ {children}
174
+ </HelpContext.Provider>
175
+ );
176
+ };
@@ -0,0 +1,5 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ export * from './HelpContextProvider';
@@ -0,0 +1,21 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ import React from 'react';
6
+
7
+ import { keySymbols } from '@dxos/keyboard';
8
+
9
+ import { shortcutKey } from './styles';
10
+
11
+ export const Key = ({ binding }: { binding: string }) => {
12
+ return (
13
+ <span role='term' className='inline-flex gap-1' aria-label={binding} id={binding}>
14
+ {keySymbols(binding).map((c, i) => (
15
+ <span key={i} className={shortcutKey}>
16
+ {c}
17
+ </span>
18
+ ))}
19
+ </span>
20
+ );
21
+ };
@@ -0,0 +1,30 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ import React from 'react';
6
+
7
+ import { Button, Dialog, useTranslation } from '@dxos/react-ui';
8
+
9
+ import { ShortcutsList } from './ShortcutsList';
10
+ import { HELP_PLUGIN } from '../../meta';
11
+
12
+ export const ShortcutsDialogContent = () => {
13
+ const { t } = useTranslation(HELP_PLUGIN);
14
+
15
+ return (
16
+ <Dialog.Content classNames={'max-bs-[40rem] md:is-auto overflow-hidden'}>
17
+ <Dialog.Title>{t('shortcuts dialog title')}</Dialog.Title>
18
+
19
+ <div className='grow overflow-y-auto py-2'>
20
+ <ShortcutsList />
21
+ </div>
22
+
23
+ <Dialog.Close asChild>
24
+ <Button variant='primary' classNames='mbs-2'>
25
+ {t('close label', { ns: 'os' })}
26
+ </Button>
27
+ </Dialog.Close>
28
+ </Dialog.Content>
29
+ );
30
+ };
@@ -0,0 +1,43 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ import { X } from '@phosphor-icons/react';
6
+ import React from 'react';
7
+
8
+ import { type KeyBinding, Keyboard } from '@dxos/keyboard';
9
+ import { Button, DensityProvider, toLocalizedString, useTranslation } from '@dxos/react-ui';
10
+ import { fixedBorder, groupSurface, mx } from '@dxos/react-ui-theme';
11
+
12
+ import { Key } from './Key';
13
+
14
+ export const ShortcutsHints = ({ onClose }: { onClose: () => void }) => {
15
+ const { t } = useTranslation('os');
16
+
17
+ // TODO(burdon): Display by context/weight/cycle.
18
+ const defaults = ['meta+k', 'meta+/', 'meta+,'];
19
+ const bindings = Keyboard.singleton.getBindings();
20
+ const hints = bindings.filter((binding) => defaults.includes(binding.shortcut));
21
+
22
+ const Shortcut = ({ binding }: { binding: KeyBinding }) => {
23
+ return (
24
+ <div role='none' className='flex items-center gap-2'>
25
+ <Key binding={binding.shortcut} />
26
+ <span className='text-sm'>{toLocalizedString(binding.data, t)}</span>
27
+ </div>
28
+ );
29
+ };
30
+
31
+ return (
32
+ <DensityProvider density='fine'>
33
+ <div className={mx('flex items-center border rounded px-2 gap-4', fixedBorder, groupSurface)}>
34
+ {hints.map((binding) => (
35
+ <Shortcut key={binding.shortcut} binding={binding} />
36
+ ))}
37
+ <Button variant='ghost' classNames='p-0 cursor-pointer' onClick={onClose}>
38
+ <X />
39
+ </Button>
40
+ </div>
41
+ </DensityProvider>
42
+ );
43
+ };
@@ -0,0 +1,35 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ import React, { Fragment } from 'react';
6
+
7
+ import { Keyboard } from '@dxos/keyboard';
8
+ import { toLocalizedString, useTranslation } from '@dxos/react-ui';
9
+ import { mx } from '@dxos/react-ui-theme';
10
+
11
+ import { Key } from './Key';
12
+ import { HELP_PLUGIN } from '../../meta';
13
+
14
+ export const ShortcutsList = () => {
15
+ const { t } = useTranslation(HELP_PLUGIN);
16
+ const bindings = Keyboard.singleton.getBindings();
17
+
18
+ // TODO(burdon): Get shortcuts from TextEditor.
19
+ bindings.sort((a, b) => {
20
+ return toLocalizedString(a.data, t)?.toLowerCase().localeCompare(toLocalizedString(b.data, t)?.toLowerCase());
21
+ });
22
+
23
+ return (
24
+ <dl className={mx('is-fit grid grid-cols-[min-content_minmax(12rem,1fr)] gap-2 mlb-4 fg-subdued')}>
25
+ {bindings.map((binding, i) => (
26
+ <Fragment key={i}>
27
+ <Key binding={binding.shortcut} />
28
+ <span role='definition' className='mis-4' aria-labelledby={binding.shortcut}>
29
+ {toLocalizedString(binding.data, t)}
30
+ </span>
31
+ </Fragment>
32
+ ))}
33
+ </dl>
34
+ );
35
+ };
@@ -0,0 +1,16 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+ import React from 'react';
5
+
6
+ import { descriptionText } from '@dxos/react-ui-theme';
7
+
8
+ import { ShortcutsList } from './ShortcutsList';
9
+
10
+ export const ShortcutsSection = () => {
11
+ return (
12
+ <section className={descriptionText}>
13
+ <ShortcutsList />
14
+ </section>
15
+ );
16
+ };
@@ -0,0 +1,9 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ export * from './ShortcutsDialog';
6
+ export * from './ShortcutsHints';
7
+ export * from './ShortcutsList';
8
+ export * from './ShortcutsSection';
9
+ export * from './Key';
@@ -0,0 +1,10 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ import { mx } from '@dxos/react-ui-theme';
6
+
7
+ export const shortcutKey = mx(
8
+ 'inline-flex min-is-[24px] bs-[24px] pli-0.5 justify-center items-center text-xs',
9
+ 'rounded bg-neutral-100 dark:bg-neutral-900',
10
+ );