@dxos/react-ui-editor 0.8.4-main.c85a9c8dae → 0.8.4-main.cb12b3f963

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 (143) hide show
  1. package/dist/lib/browser/index.mjs +754 -728
  2. package/dist/lib/browser/index.mjs.map +4 -4
  3. package/dist/lib/browser/meta.json +1 -1
  4. package/dist/lib/browser/translations.mjs +39 -0
  5. package/dist/lib/browser/translations.mjs.map +7 -0
  6. package/dist/lib/node-esm/index.mjs +754 -728
  7. package/dist/lib/node-esm/index.mjs.map +4 -4
  8. package/dist/lib/node-esm/meta.json +1 -1
  9. package/dist/lib/node-esm/translations.mjs +41 -0
  10. package/dist/lib/node-esm/translations.mjs.map +7 -0
  11. package/dist/types/src/components/Editor/Editor.d.ts +36 -25
  12. package/dist/types/src/components/Editor/Editor.d.ts.map +1 -1
  13. package/dist/types/src/components/Editor/Editor.stories.d.ts +4 -4
  14. package/dist/types/src/components/Editor/Editor.stories.d.ts.map +1 -1
  15. package/dist/types/src/components/{EditorContent/EditorContent.d.ts → Editor/EditorView.d.ts} +5 -5
  16. package/dist/types/src/components/Editor/EditorView.d.ts.map +1 -0
  17. package/dist/types/src/components/Editor/controller.d.ts.map +1 -0
  18. package/dist/types/src/components/EditorMenuProvider/EditorMenuProvider.d.ts +1 -3
  19. package/dist/types/src/components/EditorMenuProvider/EditorMenuProvider.d.ts.map +1 -1
  20. package/dist/types/src/components/EditorMenuProvider/menu-presets.d.ts.map +1 -1
  21. package/dist/types/src/components/EditorMenuProvider/menu.d.ts.map +1 -1
  22. package/dist/types/src/components/EditorMenuProvider/popover.d.ts +2 -1
  23. package/dist/types/src/components/EditorMenuProvider/popover.d.ts.map +1 -1
  24. package/dist/types/src/components/EditorMenuProvider/useEditorMenu.d.ts.map +1 -1
  25. package/dist/types/src/components/EditorPreviewProvider/EditorPreviewProvider.d.ts.map +1 -1
  26. package/dist/types/src/components/EditorToolbar/EditorToolbar.d.ts +2 -2
  27. package/dist/types/src/components/EditorToolbar/EditorToolbar.d.ts.map +1 -1
  28. package/dist/types/src/components/EditorToolbar/blocks.d.ts +4 -19
  29. package/dist/types/src/components/EditorToolbar/blocks.d.ts.map +1 -1
  30. package/dist/types/src/components/EditorToolbar/formatting.d.ts +4 -19
  31. package/dist/types/src/components/EditorToolbar/formatting.d.ts.map +1 -1
  32. package/dist/types/src/components/EditorToolbar/headings.d.ts +4 -19
  33. package/dist/types/src/components/EditorToolbar/headings.d.ts.map +1 -1
  34. package/dist/types/src/components/EditorToolbar/image.d.ts +3 -9
  35. package/dist/types/src/components/EditorToolbar/image.d.ts.map +1 -1
  36. package/dist/types/src/components/EditorToolbar/index.d.ts +1 -2
  37. package/dist/types/src/components/EditorToolbar/index.d.ts.map +1 -1
  38. package/dist/types/src/components/EditorToolbar/lists.d.ts +6 -0
  39. package/dist/types/src/components/EditorToolbar/lists.d.ts.map +1 -0
  40. package/dist/types/src/components/EditorToolbar/search.d.ts +3 -9
  41. package/dist/types/src/components/EditorToolbar/search.d.ts.map +1 -1
  42. package/dist/types/src/components/EditorToolbar/types.d.ts +6 -0
  43. package/dist/types/src/components/EditorToolbar/types.d.ts.map +1 -0
  44. package/dist/types/src/components/EditorToolbar/view-mode.d.ts +5 -20
  45. package/dist/types/src/components/EditorToolbar/view-mode.d.ts.map +1 -1
  46. package/dist/types/src/components/index.d.ts +0 -2
  47. package/dist/types/src/components/index.d.ts.map +1 -1
  48. package/dist/types/src/extensions/Assistant.stories.d.ts +10 -0
  49. package/dist/types/src/extensions/Assistant.stories.d.ts.map +1 -0
  50. package/dist/types/src/extensions/assistant-extension.d.ts +24 -0
  51. package/dist/types/src/extensions/assistant-extension.d.ts.map +1 -0
  52. package/dist/types/src/extensions/index.d.ts +2 -0
  53. package/dist/types/src/extensions/index.d.ts.map +1 -0
  54. package/dist/types/src/hooks/index.d.ts +1 -0
  55. package/dist/types/src/hooks/index.d.ts.map +1 -1
  56. package/dist/types/src/hooks/useBasicMarkdownExtensions.d.ts +25 -0
  57. package/dist/types/src/hooks/useBasicMarkdownExtensions.d.ts.map +1 -0
  58. package/dist/types/src/hooks/useTextEditor.d.ts.map +1 -1
  59. package/dist/types/src/index.d.ts +1 -2
  60. package/dist/types/src/index.d.ts.map +1 -1
  61. package/dist/types/src/stories/Automerge.stories.d.ts +24 -24
  62. package/dist/types/src/stories/Automerge.stories.d.ts.map +1 -1
  63. package/dist/types/src/stories/Comments.stories.d.ts +1 -1
  64. package/dist/types/src/stories/Comments.stories.d.ts.map +1 -1
  65. package/dist/types/src/stories/EditorToolbar.stories.d.ts +28 -26
  66. package/dist/types/src/stories/EditorToolbar.stories.d.ts.map +1 -1
  67. package/dist/types/src/stories/Experimental.stories.d.ts +2 -2
  68. package/dist/types/src/stories/Experimental.stories.d.ts.map +1 -1
  69. package/dist/types/src/stories/Markdown.stories.d.ts +1 -1
  70. package/dist/types/src/stories/Markdown.stories.d.ts.map +1 -1
  71. package/dist/types/src/stories/Outliner.stories.d.ts +2 -2
  72. package/dist/types/src/stories/Outliner.stories.d.ts.map +1 -1
  73. package/dist/types/src/stories/Popover.stories.d.ts +2 -2
  74. package/dist/types/src/stories/Popover.stories.d.ts.map +1 -1
  75. package/dist/types/src/stories/Preview.stories.d.ts +1 -1
  76. package/dist/types/src/stories/Preview.stories.d.ts.map +1 -1
  77. package/dist/types/src/stories/Tags.stories.d.ts.map +1 -1
  78. package/dist/types/src/stories/TextEditor.stories.d.ts +1 -1
  79. package/dist/types/src/stories/TextEditor.stories.d.ts.map +1 -1
  80. package/dist/types/src/stories/Theme.stories.d.ts.map +1 -1
  81. package/dist/types/src/stories/components/EditorStory.d.ts +2 -2
  82. package/dist/types/src/stories/components/EditorStory.d.ts.map +1 -1
  83. package/dist/types/src/stories/components/util.d.ts +2 -1
  84. package/dist/types/src/stories/components/util.d.ts.map +1 -1
  85. package/dist/types/src/translations.d.ts +24 -24
  86. package/dist/types/src/translations.d.ts.map +1 -1
  87. package/dist/types/src/util/react.d.ts +1 -1
  88. package/dist/types/src/util/react.d.ts.map +1 -1
  89. package/dist/types/tsconfig.tsbuildinfo +1 -1
  90. package/package.json +56 -47
  91. package/src/components/Editor/Editor.stories.tsx +15 -21
  92. package/src/components/Editor/Editor.tsx +53 -48
  93. package/src/components/Editor/EditorView.tsx +103 -0
  94. package/src/components/EditorMenuProvider/EditorMenuProvider.tsx +2 -4
  95. package/src/components/EditorMenuProvider/menu-presets.ts +1 -0
  96. package/src/components/EditorMenuProvider/popover.ts +2 -1
  97. package/src/components/EditorMenuProvider/useEditorMenu.ts +2 -1
  98. package/src/components/EditorToolbar/EditorToolbar.tsx +29 -48
  99. package/src/components/EditorToolbar/blocks.ts +54 -46
  100. package/src/components/EditorToolbar/formatting.ts +44 -45
  101. package/src/components/EditorToolbar/headings.ts +44 -50
  102. package/src/components/EditorToolbar/image.ts +16 -21
  103. package/src/components/EditorToolbar/index.ts +2 -3
  104. package/src/components/EditorToolbar/lists.ts +58 -0
  105. package/src/components/EditorToolbar/search.ts +16 -21
  106. package/src/components/EditorToolbar/types.ts +8 -0
  107. package/src/components/EditorToolbar/view-mode.ts +37 -43
  108. package/src/components/index.ts +0 -3
  109. package/src/extensions/Assistant.stories.tsx +112 -0
  110. package/src/extensions/assistant-extension.tsx +223 -0
  111. package/src/extensions/index.ts +5 -0
  112. package/src/hooks/index.ts +1 -0
  113. package/src/hooks/useBasicMarkdownExtensions.ts +55 -0
  114. package/src/index.ts +1 -4
  115. package/src/stories/Automerge.stories.tsx +8 -8
  116. package/src/stories/Comments.stories.tsx +2 -2
  117. package/src/stories/EditorToolbar.stories.tsx +36 -64
  118. package/src/stories/Experimental.stories.tsx +10 -10
  119. package/src/stories/Outliner.stories.tsx +3 -4
  120. package/src/stories/Popover.stories.tsx +6 -7
  121. package/src/stories/Preview.stories.tsx +6 -7
  122. package/src/stories/Theme.stories.tsx +2 -2
  123. package/src/stories/components/EditorStory.tsx +17 -8
  124. package/src/stories/components/util.tsx +37 -35
  125. package/src/translations.ts +29 -24
  126. package/src/util/react.tsx +1 -1
  127. package/dist/types/src/components/EditorContent/EditorContent.d.ts.map +0 -1
  128. package/dist/types/src/components/EditorContent/controller.d.ts.map +0 -1
  129. package/dist/types/src/components/EditorContent/index.d.ts +0 -3
  130. package/dist/types/src/components/EditorContent/index.d.ts.map +0 -1
  131. package/dist/types/src/components/EditorToolbar/actions.d.ts +0 -25
  132. package/dist/types/src/components/EditorToolbar/actions.d.ts.map +0 -1
  133. package/dist/types/src/components/EditorToolbar/useEditorToolbar.d.ts +0 -11
  134. package/dist/types/src/components/EditorToolbar/useEditorToolbar.d.ts.map +0 -1
  135. package/dist/types/src/stories/CommandDialog.stories.d.ts +0 -14
  136. package/dist/types/src/stories/CommandDialog.stories.d.ts.map +0 -1
  137. package/src/components/EditorContent/EditorContent.tsx +0 -83
  138. package/src/components/EditorContent/index.ts +0 -6
  139. package/src/components/EditorToolbar/actions.ts +0 -87
  140. package/src/components/EditorToolbar/useEditorToolbar.ts +0 -20
  141. package/src/stories/CommandDialog.stories.tsx +0 -81
  142. /package/dist/types/src/components/{EditorContent → Editor}/controller.d.ts +0 -0
  143. /package/src/components/{EditorContent → Editor}/controller.ts +0 -0
@@ -1,25 +0,0 @@
1
- import { type EditorView } from '@codemirror/view';
2
- import { type Node } from '@dxos/app-graph';
3
- import { type MenuItemGroup, type ToolbarMenuActionGroupProperties } from '@dxos/react-ui-menu';
4
- import { type MenuActionProperties } from '@dxos/ui-types';
5
- import { type EditorToolbarState } from './useEditorToolbar';
6
- export declare const createLists: (state: EditorToolbarState, getView: () => EditorView) => {
7
- nodes: (Node.NodeArg<any, Record<string, any>> | Readonly<Omit<Readonly<{
8
- id: string;
9
- type: string;
10
- cacheable?: string[];
11
- properties: Readonly<MenuActionProperties>;
12
- data: Node.ActionData<never>;
13
- }>, "properties"> & {
14
- properties: Readonly<MenuActionProperties>;
15
- _actionContext?: Node.ActionContext;
16
- }>)[];
17
- edges: {
18
- source: string;
19
- target: string;
20
- relation: string;
21
- }[];
22
- };
23
- export declare const createEditorAction: (id: string, props: Partial<MenuActionProperties>, invoke: () => void) => Node.Action<MenuActionProperties>;
24
- export declare const createEditorActionGroup: (id: string, props: Omit<ToolbarMenuActionGroupProperties, "icon">, icon?: string) => MenuItemGroup<ToolbarMenuActionGroupProperties>;
25
- //# sourceMappingURL=actions.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../../../../../src/components/EditorToolbar/actions.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,gCAAgC,EAGtC,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAI3D,OAAO,EAAE,KAAK,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAQ7D,eAAO,MAAM,WAAW,GAAI,OAAO,kBAAkB,EAAE,SAAS,MAAM,UAAU;;;;;;;;;;;;;;;;CAW/E,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAAI,IAAI,MAAM,EAAE,OAAO,OAAO,CAAC,oBAAoB,CAAC,EAAE,QAAQ,MAAM,IAAI,KAM/F,IAAI,CAAC,MAAM,CAAC,oBAAoB,CACvC,CAAC;AAEF,eAAO,MAAM,uBAAuB,GAClC,IAAI,MAAM,EACV,OAAO,IAAI,CAAC,gCAAgC,EAAE,MAAM,CAAC,EACrD,OAAO,MAAM,KACZ,aAAa,CAAC,gCAAgC,CAShD,CAAC"}
@@ -1,11 +0,0 @@
1
- import { Atom } from '@effect-atom/atom-react';
2
- import { type EditorViewMode, type Formatting } from '@dxos/ui-editor';
3
- export type EditorToolbarState = {
4
- viewMode?: EditorViewMode;
5
- } & Formatting;
6
- /**
7
- * Creates an atom for editor toolbar state.
8
- * @deprecated Use Editor.Root
9
- */
10
- export declare const useEditorToolbar: (initialState?: EditorToolbarState) => Atom.Writable<EditorToolbarState>;
11
- //# sourceMappingURL=useEditorToolbar.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useEditorToolbar.d.ts","sourceRoot":"","sources":["../../../../../src/components/EditorToolbar/useEditorToolbar.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAG/C,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAGvE,MAAM,MAAM,kBAAkB,GAAG;IAAE,QAAQ,CAAC,EAAE,cAAc,CAAA;CAAE,GAAG,UAAU,CAAC;AAE5E;;;GAGG;AACH,eAAO,MAAM,gBAAgB,GAAI,eAAc,kBAAuB,KAAG,IAAI,CAAC,QAAQ,CAAC,kBAAkB,CAGxG,CAAC"}
@@ -1,14 +0,0 @@
1
- import { type StoryObj } from '@storybook/react-vite';
2
- import React from 'react';
3
- declare const meta: {
4
- title: string;
5
- render: () => React.JSX.Element;
6
- decorators: import("@storybook/react").Decorator[];
7
- parameters: {
8
- layout: string;
9
- };
10
- };
11
- export default meta;
12
- type Story = StoryObj<typeof meta>;
13
- export declare const Default: Story;
14
- //# sourceMappingURL=CommandDialog.stories.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"CommandDialog.stories.d.ts","sourceRoot":"","sources":["../../../../src/stories/CommandDialog.stories.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAa,KAAK,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjE,OAAO,KAAuC,MAAM,OAAO,CAAC;AA8D5D,QAAA,MAAM,IAAI;;;;;;;CAOqB,CAAC;AAEhC,eAAe,IAAI,CAAC;AAEpB,KAAK,KAAK,GAAG,QAAQ,CAAC,OAAO,IAAI,CAAC,CAAC;AAEnC,eAAO,MAAM,OAAO,EAAE,KAAU,CAAC"}
@@ -1,83 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- import { Transaction } from '@codemirror/state';
6
- import { EditorView } from '@codemirror/view';
7
- import React, { forwardRef, useEffect, useImperativeHandle } from 'react';
8
-
9
- import { type ThemedClassName } from '@dxos/react-ui';
10
- import { initialSync } from '@dxos/ui-editor';
11
- import { mx } from '@dxos/ui-theme';
12
-
13
- import { type UseTextEditorProps, useTextEditor } from '../../hooks';
14
-
15
- import { type EditorController, createEditorController } from './controller';
16
-
17
- export type EditorContentProps = ThemedClassName<
18
- {
19
- focusable?: boolean;
20
- value?: string;
21
- onChange?: (value: string) => void;
22
- } & UseTextEditorProps
23
- >;
24
-
25
- /**
26
- * Minimal text editor.
27
- * NOTE: This shouold not be used with the automerge extension.
28
- * @deprecated Use Editor.Content
29
- */
30
- export const EditorContent = forwardRef<EditorController, EditorContentProps>(
31
- ({ classNames, id, extensions, selectionEnd, focusable = true, value, onChange, ...props }, forwardedRef) => {
32
- const { parentRef, focusAttributes, view } = useTextEditor(
33
- () => ({
34
- id,
35
- initialValue: value,
36
- selectionEnd,
37
- extensions: [
38
- extensions ?? [],
39
- EditorView.updateListener.of(({ view, docChanged, transactions }) => {
40
- const isInitialSync = transactions.some((tr) => tr.annotation(Transaction.userEvent) === initialSync.value);
41
- if (!isInitialSync && docChanged) {
42
- onChange?.(view.state.doc.toString());
43
- }
44
- }),
45
- ],
46
- ...props,
47
- }),
48
- [id, extensions, selectionEnd, onChange],
49
- );
50
-
51
- // External controller.
52
- useImperativeHandle(forwardedRef, () => {
53
- return createEditorController(view);
54
- }, [id, view]);
55
-
56
- // Set initial value and cursor position.
57
- useEffect(() => {
58
- requestAnimationFrame(() => {
59
- view?.dispatch({
60
- annotations: initialSync,
61
- changes: value ? [{ from: 0, to: view?.state.doc.length ?? 0, insert: value ?? '' }] : [],
62
- selection: selectionEnd ? { anchor: view?.state.doc.length ?? 0 } : undefined,
63
- });
64
-
65
- if (selectionEnd) {
66
- view?.focus();
67
- }
68
- });
69
- }, [view, value, selectionEnd]);
70
-
71
- return (
72
- <div
73
- role='none'
74
- className={mx(
75
- 'w-full outline-hidden focus:border-accent-surface focus-within:border-neutral-focus-indicator',
76
- classNames,
77
- )}
78
- ref={parentRef}
79
- {...(focusable ? focusAttributes : {})}
80
- />
81
- );
82
- },
83
- );
@@ -1,6 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- export * from './controller';
6
- export * from './EditorContent';
@@ -1,87 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- import { type EditorView } from '@codemirror/view';
6
-
7
- import { type Node } from '@dxos/app-graph';
8
- import {
9
- type MenuItemGroup,
10
- type ToolbarMenuActionGroupProperties,
11
- createMenuAction,
12
- createMenuItemGroup,
13
- } from '@dxos/react-ui-menu';
14
- import { List, addList, removeList } from '@dxos/ui-editor';
15
- import { type MenuActionProperties } from '@dxos/ui-types';
16
-
17
- import { translationKey } from '../../translations';
18
-
19
- import { type EditorToolbarState } from './useEditorToolbar';
20
-
21
- const listStyles = {
22
- bullet: 'ph--list-bullets--regular',
23
- ordered: 'ph--list-numbers--regular',
24
- task: 'ph--list-checks--regular',
25
- };
26
-
27
- export const createLists = (state: EditorToolbarState, getView: () => EditorView) => {
28
- const value = state.listStyle ?? '';
29
- const listGroupAction = createListGroupAction(value);
30
- const listActionsMap = createListActions(value, getView);
31
- return {
32
- nodes: [listGroupAction as Node.NodeArg<any>, ...listActionsMap],
33
- edges: [
34
- { source: 'root', target: 'list', relation: 'child' },
35
- ...listActionsMap.map(({ id }) => ({ source: listGroupAction.id, target: id, relation: 'child' })),
36
- ],
37
- };
38
- };
39
-
40
- export const createEditorAction = (id: string, props: Partial<MenuActionProperties>, invoke: () => void) => {
41
- const { label = [`${id} label`, { ns: translationKey }], ...rest } = props;
42
-
43
- return createMenuAction(id, invoke, {
44
- label,
45
- ...rest,
46
- }) as Node.Action<MenuActionProperties>;
47
- };
48
-
49
- export const createEditorActionGroup = (
50
- id: string,
51
- props: Omit<ToolbarMenuActionGroupProperties, 'icon'>,
52
- icon?: string,
53
- ): MenuItemGroup<ToolbarMenuActionGroupProperties> => {
54
- const { label = [`${id} label`, { ns: translationKey }], ...rest } = props;
55
-
56
- return createMenuItemGroup(id, {
57
- label,
58
- icon,
59
- iconOnly: true,
60
- ...rest,
61
- }) as MenuItemGroup<ToolbarMenuActionGroupProperties>;
62
- };
63
-
64
- const createListGroupAction = (value: string) =>
65
- createEditorActionGroup('list', {
66
- variant: 'toggleGroup',
67
- selectCardinality: 'single',
68
- value,
69
- } as ToolbarMenuActionGroupProperties);
70
-
71
- const createListActions = (value: string, getView: () => EditorView) =>
72
- Object.entries(listStyles).map(([listStyle, icon]) => {
73
- const checked = value === listStyle;
74
- return createEditorAction(`list-${listStyle}`, { checked, icon }, () => {
75
- const view = getView();
76
- if (!view) {
77
- return;
78
- }
79
-
80
- const listType = listStyle === 'ordered' ? List.Ordered : listStyle === 'bullet' ? List.Bullet : List.Task;
81
- if (checked) {
82
- removeList(listType)(view);
83
- } else {
84
- addList(listType)(view);
85
- }
86
- });
87
- });
@@ -1,20 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- import { Atom } from '@effect-atom/atom-react';
6
- import { useMemo } from 'react';
7
-
8
- import { type EditorViewMode, type Formatting } from '@dxos/ui-editor';
9
-
10
- // TODO(burdon): Move to extensions.
11
- export type EditorToolbarState = { viewMode?: EditorViewMode } & Formatting;
12
-
13
- /**
14
- * Creates an atom for editor toolbar state.
15
- * @deprecated Use Editor.Root
16
- */
17
- export const useEditorToolbar = (initialState: EditorToolbarState = {}): Atom.Writable<EditorToolbarState> => {
18
- // TODO(wittjosiah): Including initialState in the deps causes reactivity issues.
19
- return useMemo(() => Atom.make<EditorToolbarState>(initialState), []);
20
- };
@@ -1,81 +0,0 @@
1
- //
2
- // Copyright 2023 DXOS.org
3
- //
4
-
5
- import { type Meta, type StoryObj } from '@storybook/react-vite';
6
- import React, { type KeyboardEvent, useState } from 'react';
7
-
8
- import { type Button, IconButton, Input } from '@dxos/react-ui';
9
- import { withLayout, withTheme } from '@dxos/react-ui/testing';
10
- import { editorWidth, join } from '@dxos/ui-editor';
11
- import { mx } from '@dxos/ui-theme';
12
-
13
- import { EditorStory } from './components';
14
-
15
- // TODO(burdon): Reimplement with Popover.
16
- const CommandDialog = ({ onAction }: { onAction: (action?: any) => void }) => {
17
- const [text, setText] = useState('');
18
-
19
- const handleInsert = () => {
20
- // TODO(burdon): Use queue ref.
21
- const link = `![${text}](dxn:queue:data:123)`;
22
- onAction(text.length ? { type: 'insert', text: link } : undefined);
23
- };
24
-
25
- const handleKeyDown = (event: KeyboardEvent<HTMLInputElement>) => {
26
- switch (event.key) {
27
- case 'Enter': {
28
- handleInsert();
29
- break;
30
- }
31
- case 'Escape': {
32
- onAction();
33
- break;
34
- }
35
- }
36
- };
37
-
38
- return (
39
- <div className='flex w-full justify-center'>
40
- <div
41
- className={mx(
42
- 'flex w-full p-2 gap-2 items-center bg-modal-surface border border-separator rounded-md',
43
- editorWidth,
44
- )}
45
- >
46
- <Input.Root>
47
- <Input.TextInput
48
- autoFocus={true}
49
- placeholder='Ask a question...'
50
- value={text}
51
- onChange={(ev) => setText(ev.target.value)}
52
- onKeyDown={handleKeyDown}
53
- />
54
- </Input.Root>
55
- <IconButton
56
- icon='ph--x--regular'
57
- label='Cancel'
58
- iconOnly
59
- variant='ghost'
60
- classNames='px-0'
61
- onClick={() => onAction({ type: 'cancel' })}
62
- />
63
- </div>
64
- </div>
65
- );
66
- };
67
-
68
- const meta = {
69
- title: 'ui/react-ui-editor/CommandDialog',
70
- render: () => <EditorStory text={join('# Command', '', '')} extensions={[]} />,
71
- decorators: [withTheme(), withLayout({ layout: 'fullscreen' })],
72
- parameters: {
73
- layout: 'fullscreen',
74
- },
75
- } satisfies Meta<typeof Button>;
76
-
77
- export default meta;
78
-
79
- type Story = StoryObj<typeof meta>;
80
-
81
- export const Default: Story = {};