@dxos/react-ui-editor 0.8.4-main.d05673bc65 → 0.8.4-main.d9fc60f731
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/LICENSE +102 -5
- package/README.md +1 -1
- package/dist/lib/browser/index.mjs +754 -731
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/translations.mjs +39 -0
- package/dist/lib/browser/translations.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +754 -731
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/translations.mjs +41 -0
- package/dist/lib/node-esm/translations.mjs.map +7 -0
- package/dist/types/src/components/Editor/Editor.d.ts +36 -25
- package/dist/types/src/components/Editor/Editor.d.ts.map +1 -1
- package/dist/types/src/components/Editor/Editor.stories.d.ts +4 -4
- package/dist/types/src/components/Editor/Editor.stories.d.ts.map +1 -1
- package/dist/types/src/components/{EditorContent/EditorContent.d.ts → Editor/EditorView.d.ts} +5 -5
- package/dist/types/src/components/Editor/EditorView.d.ts.map +1 -0
- package/dist/types/src/components/Editor/controller.d.ts.map +1 -0
- package/dist/types/src/components/EditorMenuProvider/EditorMenuProvider.d.ts +1 -3
- package/dist/types/src/components/EditorMenuProvider/EditorMenuProvider.d.ts.map +1 -1
- package/dist/types/src/components/EditorMenuProvider/menu-presets.d.ts.map +1 -1
- package/dist/types/src/components/EditorMenuProvider/menu.d.ts.map +1 -1
- package/dist/types/src/components/EditorMenuProvider/popover.d.ts +2 -1
- package/dist/types/src/components/EditorMenuProvider/popover.d.ts.map +1 -1
- package/dist/types/src/components/EditorMenuProvider/useEditorMenu.d.ts.map +1 -1
- package/dist/types/src/components/EditorPreviewProvider/EditorPreviewProvider.d.ts.map +1 -1
- package/dist/types/src/components/EditorToolbar/EditorToolbar.d.ts +2 -2
- package/dist/types/src/components/EditorToolbar/EditorToolbar.d.ts.map +1 -1
- package/dist/types/src/components/EditorToolbar/blocks.d.ts +4 -19
- package/dist/types/src/components/EditorToolbar/blocks.d.ts.map +1 -1
- package/dist/types/src/components/EditorToolbar/formatting.d.ts +4 -19
- package/dist/types/src/components/EditorToolbar/formatting.d.ts.map +1 -1
- package/dist/types/src/components/EditorToolbar/headings.d.ts +4 -19
- package/dist/types/src/components/EditorToolbar/headings.d.ts.map +1 -1
- package/dist/types/src/components/EditorToolbar/image.d.ts +3 -9
- package/dist/types/src/components/EditorToolbar/image.d.ts.map +1 -1
- package/dist/types/src/components/EditorToolbar/index.d.ts +1 -2
- package/dist/types/src/components/EditorToolbar/index.d.ts.map +1 -1
- package/dist/types/src/components/EditorToolbar/lists.d.ts +6 -0
- package/dist/types/src/components/EditorToolbar/lists.d.ts.map +1 -0
- package/dist/types/src/components/EditorToolbar/search.d.ts +3 -9
- package/dist/types/src/components/EditorToolbar/search.d.ts.map +1 -1
- package/dist/types/src/components/EditorToolbar/types.d.ts +6 -0
- package/dist/types/src/components/EditorToolbar/types.d.ts.map +1 -0
- package/dist/types/src/components/EditorToolbar/view-mode.d.ts +5 -20
- package/dist/types/src/components/EditorToolbar/view-mode.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +0 -2
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/extensions/Assistant.stories.d.ts +10 -0
- package/dist/types/src/extensions/Assistant.stories.d.ts.map +1 -0
- package/dist/types/src/extensions/assistant-extension.d.ts +24 -0
- package/dist/types/src/extensions/assistant-extension.d.ts.map +1 -0
- package/dist/types/src/extensions/index.d.ts +2 -0
- package/dist/types/src/extensions/index.d.ts.map +1 -0
- package/dist/types/src/hooks/index.d.ts +1 -0
- package/dist/types/src/hooks/index.d.ts.map +1 -1
- package/dist/types/src/hooks/useBasicMarkdownExtensions.d.ts +25 -0
- package/dist/types/src/hooks/useBasicMarkdownExtensions.d.ts.map +1 -0
- package/dist/types/src/hooks/useTextEditor.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +1 -2
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/stories/Automerge.stories.d.ts +24 -24
- package/dist/types/src/stories/Automerge.stories.d.ts.map +1 -1
- package/dist/types/src/stories/Comments.stories.d.ts +1 -1
- package/dist/types/src/stories/Comments.stories.d.ts.map +1 -1
- package/dist/types/src/stories/EditorToolbar.stories.d.ts +28 -26
- package/dist/types/src/stories/EditorToolbar.stories.d.ts.map +1 -1
- package/dist/types/src/stories/Experimental.stories.d.ts +2 -2
- package/dist/types/src/stories/Experimental.stories.d.ts.map +1 -1
- package/dist/types/src/stories/Markdown.stories.d.ts +1 -1
- package/dist/types/src/stories/Markdown.stories.d.ts.map +1 -1
- package/dist/types/src/stories/Outliner.stories.d.ts +2 -2
- package/dist/types/src/stories/Outliner.stories.d.ts.map +1 -1
- package/dist/types/src/stories/Popover.stories.d.ts +2 -2
- package/dist/types/src/stories/Popover.stories.d.ts.map +1 -1
- package/dist/types/src/stories/Preview.stories.d.ts +1 -1
- package/dist/types/src/stories/Preview.stories.d.ts.map +1 -1
- package/dist/types/src/stories/Tags.stories.d.ts.map +1 -1
- package/dist/types/src/stories/TextEditor.stories.d.ts +1 -1
- package/dist/types/src/stories/TextEditor.stories.d.ts.map +1 -1
- package/dist/types/src/stories/Theme.stories.d.ts.map +1 -1
- package/dist/types/src/stories/components/EditorStory.d.ts +2 -2
- package/dist/types/src/stories/components/EditorStory.d.ts.map +1 -1
- package/dist/types/src/stories/components/util.d.ts +2 -1
- package/dist/types/src/stories/components/util.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +24 -24
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/util/react.d.ts +1 -1
- package/dist/types/src/util/react.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +77 -68
- package/src/components/Editor/Editor.stories.tsx +15 -21
- package/src/components/Editor/Editor.tsx +54 -53
- package/src/components/Editor/EditorView.tsx +99 -0
- package/src/components/EditorMenuProvider/EditorMenuProvider.tsx +3 -5
- package/src/components/EditorMenuProvider/menu-presets.ts +1 -0
- package/src/components/EditorMenuProvider/popover.ts +3 -1
- package/src/components/EditorMenuProvider/useEditorMenu.ts +2 -1
- package/src/components/EditorPreviewProvider/EditorPreviewProvider.tsx +1 -1
- package/src/components/EditorToolbar/EditorToolbar.tsx +29 -48
- package/src/components/EditorToolbar/blocks.ts +54 -46
- package/src/components/EditorToolbar/formatting.ts +44 -45
- package/src/components/EditorToolbar/headings.ts +44 -50
- package/src/components/EditorToolbar/image.ts +16 -21
- package/src/components/EditorToolbar/index.ts +2 -3
- package/src/components/EditorToolbar/lists.ts +58 -0
- package/src/components/EditorToolbar/search.ts +16 -21
- package/src/components/EditorToolbar/types.ts +8 -0
- package/src/components/EditorToolbar/view-mode.ts +37 -43
- package/src/components/index.ts +0 -3
- package/src/extensions/Assistant.stories.tsx +112 -0
- package/src/extensions/assistant-extension.tsx +223 -0
- package/src/extensions/index.ts +5 -0
- package/src/hooks/index.ts +1 -0
- package/src/hooks/useBasicMarkdownExtensions.ts +55 -0
- package/src/index.ts +1 -4
- package/src/stories/Automerge.stories.tsx +10 -6
- package/src/stories/Comments.stories.tsx +2 -2
- package/src/stories/EditorToolbar.stories.tsx +36 -64
- package/src/stories/Experimental.stories.tsx +10 -10
- package/src/stories/Outliner.stories.tsx +3 -4
- package/src/stories/Popover.stories.tsx +7 -8
- package/src/stories/Preview.stories.tsx +11 -12
- package/src/stories/Theme.stories.tsx +2 -2
- package/src/stories/components/EditorStory.tsx +17 -8
- package/src/stories/components/util.tsx +38 -36
- package/src/translations.ts +29 -24
- package/src/util/react.tsx +2 -2
- package/dist/types/src/components/EditorContent/EditorContent.d.ts.map +0 -1
- package/dist/types/src/components/EditorContent/controller.d.ts.map +0 -1
- package/dist/types/src/components/EditorContent/index.d.ts +0 -3
- package/dist/types/src/components/EditorContent/index.d.ts.map +0 -1
- package/dist/types/src/components/EditorToolbar/actions.d.ts +0 -25
- package/dist/types/src/components/EditorToolbar/actions.d.ts.map +0 -1
- package/dist/types/src/components/EditorToolbar/useEditorToolbar.d.ts +0 -11
- package/dist/types/src/components/EditorToolbar/useEditorToolbar.d.ts.map +0 -1
- package/dist/types/src/stories/CommandDialog.stories.d.ts +0 -14
- package/dist/types/src/stories/CommandDialog.stories.d.ts.map +0 -1
- package/src/components/EditorContent/EditorContent.tsx +0 -83
- package/src/components/EditorContent/index.ts +0 -6
- package/src/components/EditorToolbar/actions.ts +0 -87
- package/src/components/EditorToolbar/useEditorToolbar.ts +0 -20
- package/src/stories/CommandDialog.stories.tsx +0 -81
- /package/dist/types/src/components/{EditorContent → Editor}/controller.d.ts +0 -0
- /package/src/components/{EditorContent → Editor}/controller.ts +0 -0
package/src/util/react.tsx
CHANGED
|
@@ -6,8 +6,8 @@ import React, { type FC } from 'react';
|
|
|
6
6
|
import { createRoot } from 'react-dom/client';
|
|
7
7
|
|
|
8
8
|
import { ThemeProvider, Tooltip } from '@dxos/react-ui';
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
9
|
+
import { defaultTx } from '@dxos/react-ui';
|
|
10
|
+
import { type RenderCallback } from '@dxos/ui-editor/types';
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* @deprecated Use `trim` from `@dxos/util`.
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"EditorContent.d.ts","sourceRoot":"","sources":["../../../../../src/components/EditorContent/EditorContent.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAqD,MAAM,OAAO,CAAC;AAE1E,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAItD,OAAO,EAAE,KAAK,kBAAkB,EAAiB,MAAM,aAAa,CAAC;AAErE,OAAO,EAAE,KAAK,gBAAgB,EAA0B,MAAM,cAAc,CAAC;AAE7E,MAAM,MAAM,kBAAkB,GAAG,eAAe,CAC9C;IACE,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACpC,GAAG,kBAAkB,CACvB,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,aAAa;gBAXV,OAAO;YACX,MAAM;eACH,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI;;;;;;;;;;;;0CA8DrC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../../../../src/components/EditorContent/controller.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD,MAAM,WAAW,gBAAgB;IAC/B,IAAI,IAAI,IAAI,UAAU,GAAG,IAAI,CAAC;IAC9B,OAAO,EAAE,MAAM,MAAM,CAAC;IACtB,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;IACjD,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB;AAED,eAAO,MAAM,cAAc,EAAE,gBAO5B,CAAC;AAEF,eAAO,MAAM,sBAAsB,GAAI,MAAM,UAAU,GAAG,IAAI,KAAG,gBA2BhE,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/components/EditorContent/index.ts"],"names":[],"mappings":"AAIA,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC"}
|
|
@@ -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,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 = ``;
|
|
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 = {};
|
|
File without changes
|
|
File without changes
|