@dxos/react-ui-editor 0.3.9-main.d5f3fd3 → 0.3.9-main.de60860
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/dist/lib/browser/index.mjs +401 -48
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/types/src/automerge/automerge-plugin/index.d.ts +1 -1
- package/dist/types/src/automerge/automerge-plugin/index.d.ts.map +1 -1
- package/dist/types/src/automerge/automerge.stories.d.ts.map +1 -1
- package/dist/types/src/components/Editor/Editor.d.ts +0 -1
- package/dist/types/src/components/Editor/Editor.d.ts.map +1 -1
- package/dist/types/src/components/Editor/Editor.stories.d.ts +3 -8
- package/dist/types/src/components/Editor/Editor.stories.d.ts.map +1 -1
- package/dist/types/src/components/Markdown/Markdown.d.ts +4 -2
- package/dist/types/src/components/Markdown/Markdown.d.ts.map +1 -1
- package/dist/types/src/components/Markdown/Markdown.stories.d.ts +1 -1
- package/dist/types/src/components/Markdown/Markdown.stories.d.ts.map +1 -1
- package/dist/types/src/components/Markdown/markdownTheme.d.ts +10 -17
- package/dist/types/src/components/Markdown/markdownTheme.d.ts.map +1 -1
- package/dist/types/src/components/RichText/RichText.stories.d.ts +2 -3
- package/dist/types/src/components/RichText/RichText.stories.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/TextEditor.d.ts +39 -0
- package/dist/types/src/components/TextEditor/TextEditor.d.ts.map +1 -0
- package/dist/types/src/components/TextEditor/TextEditor.stories.d.ts +18 -0
- package/dist/types/src/components/TextEditor/TextEditor.stories.d.ts.map +1 -0
- package/dist/types/src/components/TextEditor/extensions/hyperlinkDecoration.d.ts +11 -0
- package/dist/types/src/components/TextEditor/extensions/hyperlinkDecoration.d.ts.map +1 -0
- package/dist/types/src/components/TextEditor/extensions/hyperlinkTooltip.d.ts +8 -0
- package/dist/types/src/components/TextEditor/extensions/hyperlinkTooltip.d.ts.map +1 -0
- package/dist/types/src/components/TextEditor/extensions/hyperlinkWidget.d.ts +10 -0
- package/dist/types/src/components/TextEditor/extensions/hyperlinkWidget.d.ts.map +1 -0
- package/dist/types/src/components/TextEditor/extensions/index.d.ts +4 -0
- package/dist/types/src/components/TextEditor/extensions/index.d.ts.map +1 -0
- package/dist/types/src/components/TextEditor/index.d.ts +6 -0
- package/dist/types/src/components/TextEditor/index.d.ts.map +1 -0
- package/dist/types/src/components/TextEditor/theme.d.ts +9 -0
- package/dist/types/src/components/TextEditor/theme.d.ts.map +1 -0
- package/dist/types/src/components/index.d.ts +1 -0
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/package.json +20 -16
- package/src/automerge/automerge-plugin/index.ts +1 -1
- package/src/automerge/automerge.stories.tsx +1 -2
- package/src/components/Editor/Editor.stories.tsx +5 -5
- package/src/components/Editor/Editor.tsx +4 -1
- package/src/components/Markdown/Markdown.stories.tsx +38 -25
- package/src/components/Markdown/Markdown.tsx +53 -24
- package/src/components/Markdown/markdownTheme.ts +32 -17
- package/src/components/RichText/RichText.stories.tsx +37 -33
- package/src/components/TextEditor/TextEditor.stories.tsx +72 -0
- package/src/components/TextEditor/TextEditor.tsx +131 -0
- package/src/components/TextEditor/extensions/hyperlinkDecoration.ts +99 -0
- package/src/components/TextEditor/extensions/hyperlinkTooltip.tsx +61 -0
- package/src/components/TextEditor/extensions/hyperlinkWidget.tsx +119 -0
- package/src/components/TextEditor/extensions/index.ts +7 -0
- package/src/components/TextEditor/index.ts +11 -0
- package/src/components/TextEditor/theme.ts +35 -0
- package/src/components/index.ts +1 -0
|
@@ -2,6 +2,7 @@ import '@dxosTheme';
|
|
|
2
2
|
import React from 'react';
|
|
3
3
|
declare const _default: {
|
|
4
4
|
component: React.ForwardRefExoticComponent<import("./Markdown").MarkdownEditorProps & React.RefAttributes<import("./Markdown").MarkdownEditorRef>>;
|
|
5
|
+
decorators: import("@storybook/react").Decorator[];
|
|
5
6
|
};
|
|
6
7
|
export default _default;
|
|
7
8
|
export declare const Default: {
|
|
@@ -14,6 +15,5 @@ export declare const Default: {
|
|
|
14
15
|
};
|
|
15
16
|
export declare const WithYjs: {
|
|
16
17
|
render: () => JSX.Element;
|
|
17
|
-
decorators: import("@storybook/csf").DecoratorFunction<import("@storybook/react/dist/types-0a347bb9").R, any>[];
|
|
18
18
|
};
|
|
19
19
|
//# sourceMappingURL=Markdown.stories.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Markdown.stories.d.ts","sourceRoot":"","sources":["../../../../../src/components/Markdown/Markdown.stories.tsx"],"names":[],"mappings":"AAIA,OAAO,YAAY,CAAC;AAEpB,OAAO,KAAmB,MAAM,OAAO,CAAC
|
|
1
|
+
{"version":3,"file":"Markdown.stories.d.ts","sourceRoot":"","sources":["../../../../../src/components/Markdown/Markdown.stories.tsx"],"names":[],"mappings":"AAIA,OAAO,YAAY,CAAC;AAEpB,OAAO,KAAmB,MAAM,OAAO,CAAC;;;;;AAWxC,wBAGE;AAYF,eAAO,MAAM,OAAO;;;;;;;CAOnB,CAAC;AA2BF,eAAO,MAAM,OAAO;;CAGnB,CAAC"}
|
|
@@ -13,23 +13,9 @@ export declare const highlightBackground = "#2c313a";
|
|
|
13
13
|
export declare const tooltipBackground = "#353a42";
|
|
14
14
|
export declare const cursor = "#ffffff";
|
|
15
15
|
export declare const markdownTheme: {
|
|
16
|
-
'.
|
|
17
|
-
border: string;
|
|
16
|
+
'.cm-tooltip': {
|
|
18
17
|
backgroundColor: string;
|
|
19
|
-
|
|
20
|
-
'.dark & .cm-tooltip .cm-tooltip-arrow:before': {
|
|
21
|
-
borderTopColor: string;
|
|
22
|
-
borderBottomColor: string;
|
|
23
|
-
};
|
|
24
|
-
'.dark & .cm-tooltip .cm-tooltip-arrow:after': {
|
|
25
|
-
borderTopColor: string;
|
|
26
|
-
borderBottomColor: string;
|
|
27
|
-
};
|
|
28
|
-
'.dark & .cm-tooltip-autocomplete': {
|
|
29
|
-
'& > ul > li[aria-selected]': {
|
|
30
|
-
backgroundColor: string;
|
|
31
|
-
color: string;
|
|
32
|
-
};
|
|
18
|
+
border: string;
|
|
33
19
|
};
|
|
34
20
|
'&.cm-focused': {
|
|
35
21
|
outline: string;
|
|
@@ -102,6 +88,13 @@ export declare const markdownTheme: {
|
|
|
102
88
|
'& .cm-yLineSelection': {
|
|
103
89
|
margin: string;
|
|
104
90
|
};
|
|
91
|
+
'.cm-link': {
|
|
92
|
+
color: string;
|
|
93
|
+
textDecorationLine: string;
|
|
94
|
+
textDecorationThickness: string;
|
|
95
|
+
textUnderlineOffset: string;
|
|
96
|
+
borderRadius: string;
|
|
97
|
+
};
|
|
105
98
|
};
|
|
106
|
-
export declare const
|
|
99
|
+
export declare const markdownHighlightStyle: HighlightStyle;
|
|
107
100
|
//# sourceMappingURL=markdownTheme.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"markdownTheme.d.ts","sourceRoot":"","sources":["../../../../../src/components/Markdown/markdownTheme.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAUtD,eAAO,MAAM,MAAM,YAAY,CAAC;AAChC,eAAO,MAAM,KAAK,YAAY,CAAC;AAC/B,eAAO,MAAM,IAAI,YAAY,CAAC;AAC9B,eAAO,MAAM,OAAO,YAAY,CAAC;AACjC,eAAO,MAAM,KAAK,YAAY,CAAC;AAC/B,eAAO,MAAM,KAAK,YAAY,CAAC;AAC/B,eAAO,MAAM,MAAM,YAAY,CAAC;AAChC,eAAO,MAAM,IAAI,YAAY,CAAC;AAC9B,eAAO,MAAM,OAAO,YAAY,CAAC;AACjC,eAAO,MAAM,MAAM,YAAY,CAAC;AAEhC,eAAO,MAAM,mBAAmB,YAAY,CAAC;AAE7C,eAAO,MAAM,iBAAiB,YAAY,CAAC;AAE3C,eAAO,MAAM,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"markdownTheme.d.ts","sourceRoot":"","sources":["../../../../../src/components/Markdown/markdownTheme.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAUtD,eAAO,MAAM,MAAM,YAAY,CAAC;AAChC,eAAO,MAAM,KAAK,YAAY,CAAC;AAC/B,eAAO,MAAM,IAAI,YAAY,CAAC;AAC9B,eAAO,MAAM,OAAO,YAAY,CAAC;AACjC,eAAO,MAAM,KAAK,YAAY,CAAC;AAC/B,eAAO,MAAM,KAAK,YAAY,CAAC;AAC/B,eAAO,MAAM,MAAM,YAAY,CAAC;AAChC,eAAO,MAAM,IAAI,YAAY,CAAC;AAC9B,eAAO,MAAM,OAAO,YAAY,CAAC;AACjC,eAAO,MAAM,MAAM,YAAY,CAAC;AAEhC,eAAO,MAAM,mBAAmB,YAAY,CAAC;AAE7C,eAAO,MAAM,iBAAiB,YAAY,CAAC;AAE3C,eAAO,MAAM,MAAM,YAAY,CAAC;AAQhC,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmJzB,CAAC;AAEF,eAAO,MAAM,sBAAsB,gBA6ElC,CAAC"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import '@dxosTheme';
|
|
2
2
|
import React from 'react';
|
|
3
|
-
import { type RichTextEditorProps } from './RichText';
|
|
4
3
|
declare const _default: {
|
|
5
4
|
component: React.ForwardRefExoticComponent<{
|
|
6
5
|
model?: import("../..").EditorModel | undefined;
|
|
@@ -9,6 +8,7 @@ declare const _default: {
|
|
|
9
8
|
} & {
|
|
10
9
|
slots?: import("../..").EditorSlots | undefined;
|
|
11
10
|
} & React.RefAttributes<import("@tiptap/react").Editor | null>>;
|
|
11
|
+
decorators: import("@storybook/react").Decorator[];
|
|
12
12
|
};
|
|
13
13
|
export default _default;
|
|
14
14
|
export declare const Default: {
|
|
@@ -20,7 +20,6 @@ export declare const Default: {
|
|
|
20
20
|
};
|
|
21
21
|
};
|
|
22
22
|
export declare const WithYjs: {
|
|
23
|
-
render: (
|
|
24
|
-
decorators: import("@storybook/csf").DecoratorFunction<import("@storybook/react/dist/types-0a347bb9").R, any>[];
|
|
23
|
+
render: () => JSX.Element;
|
|
25
24
|
};
|
|
26
25
|
//# sourceMappingURL=RichText.stories.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RichText.stories.d.ts","sourceRoot":"","sources":["../../../../../src/components/RichText/RichText.stories.tsx"],"names":[],"mappings":"AAIA,OAAO,YAAY,CAAC;AAEpB,OAAO,KAAmB,MAAM,OAAO,CAAC
|
|
1
|
+
{"version":3,"file":"RichText.stories.d.ts","sourceRoot":"","sources":["../../../../../src/components/RichText/RichText.stories.tsx"],"names":[],"mappings":"AAIA,OAAO,YAAY,CAAC;AAEpB,OAAO,KAAmB,MAAM,OAAO,CAAC;;;;;;;;;;;AAYxC,wBAGE;AAEF,eAAO,MAAM,OAAO;;;;;;;CAOnB,CAAC;AAsCF,eAAO,MAAM,OAAO;;CAGnB,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { EditorState, type Extension } from '@codemirror/state';
|
|
2
|
+
import { EditorView } from '@codemirror/view';
|
|
3
|
+
import React, { type KeyboardEvent, type HTMLAttributes } from 'react';
|
|
4
|
+
import { type StyleSpec } from 'style-mod';
|
|
5
|
+
import { type EditorModel, type EditorSlots } from '../../model';
|
|
6
|
+
export type CursorInfo = {
|
|
7
|
+
from: number;
|
|
8
|
+
to: number;
|
|
9
|
+
line: number;
|
|
10
|
+
lines: number;
|
|
11
|
+
after?: string;
|
|
12
|
+
};
|
|
13
|
+
export type TextEditorRef = {
|
|
14
|
+
editor: HTMLDivElement | null;
|
|
15
|
+
state?: EditorState;
|
|
16
|
+
view?: EditorView;
|
|
17
|
+
};
|
|
18
|
+
export type TextEditorProps = {
|
|
19
|
+
model?: EditorModel;
|
|
20
|
+
extensions?: Extension[];
|
|
21
|
+
theme?: {
|
|
22
|
+
[selector: string]: StyleSpec;
|
|
23
|
+
};
|
|
24
|
+
slots?: EditorSlots;
|
|
25
|
+
onKeyDown?: (event: KeyboardEvent, info: CursorInfo) => void;
|
|
26
|
+
} & Pick<HTMLAttributes<HTMLDivElement>, 'onBlur' | 'onFocus'>;
|
|
27
|
+
/**
|
|
28
|
+
* Simple text editor.
|
|
29
|
+
*/
|
|
30
|
+
export declare const TextEditor: React.ForwardRefExoticComponent<{
|
|
31
|
+
model?: EditorModel | undefined;
|
|
32
|
+
extensions?: Extension[] | undefined;
|
|
33
|
+
theme?: {
|
|
34
|
+
[selector: string]: StyleSpec;
|
|
35
|
+
} | undefined;
|
|
36
|
+
slots?: EditorSlots | undefined;
|
|
37
|
+
onKeyDown?: ((event: KeyboardEvent, info: CursorInfo) => void) | undefined;
|
|
38
|
+
} & Pick<React.HTMLAttributes<HTMLDivElement>, "onFocus" | "onBlur"> & React.RefAttributes<TextEditorRef>>;
|
|
39
|
+
//# sourceMappingURL=TextEditor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TextEditor.d.ts","sourceRoot":"","sources":["../../../../../src/components/TextEditor/TextEditor.tsx"],"names":[],"mappings":"AAMA,OAAO,EAAE,WAAW,EAAE,KAAK,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEhE,OAAO,EAAE,UAAU,EAAe,MAAM,kBAAkB,CAAC;AAC3D,OAAO,KAAK,EAAE,EACZ,KAAK,aAAa,EAMlB,KAAK,cAAc,EACpB,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,WAAW,CAAC;AAO3C,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AAEjE,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,MAAM,EAAE,cAAc,GAAG,IAAI,CAAC;IAC9B,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,IAAI,CAAC,EAAE,UAAU,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,UAAU,CAAC,EAAE,SAAS,EAAE,CAAC;IACzB,KAAK,CAAC,EAAE;QACN,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;KAC/B,CAAC;IACF,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,EAAE,IAAI,EAAE,UAAU,KAAK,IAAI,CAAC;CAC9D,GAAG,IAAI,CAAC,cAAc,CAAC,cAAc,CAAC,EAAE,QAAQ,GAAG,SAAS,CAAC,CAAC;AAE/D;;GAEG;AACH,eAAO,MAAM,UAAU;;;;;;;yBAND,aAAa,QAAQ,UAAU,KAAK,IAAI;0GAkF7D,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import '@dxosTheme';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
declare const _default: {
|
|
4
|
+
component: React.ForwardRefExoticComponent<{
|
|
5
|
+
model?: import("../../model").EditorModel | undefined;
|
|
6
|
+
extensions?: import("@codemirror/state").Extension[] | undefined;
|
|
7
|
+
theme?: {
|
|
8
|
+
[selector: string]: import("style-mod").StyleSpec;
|
|
9
|
+
} | undefined;
|
|
10
|
+
slots?: import("../../model").EditorSlots | undefined;
|
|
11
|
+
onKeyDown?: ((event: React.KeyboardEvent<Element>, info: import("./TextEditor").CursorInfo) => void) | undefined;
|
|
12
|
+
} & Pick<React.HTMLAttributes<HTMLDivElement>, "onFocus" | "onBlur"> & React.RefAttributes<import("./TextEditor").TextEditorRef>>;
|
|
13
|
+
decorators: import("@storybook/react").Decorator[];
|
|
14
|
+
render: () => JSX.Element;
|
|
15
|
+
};
|
|
16
|
+
export default _default;
|
|
17
|
+
export declare const Default: {};
|
|
18
|
+
//# sourceMappingURL=TextEditor.stories.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TextEditor.stories.d.ts","sourceRoot":"","sources":["../../../../../src/components/TextEditor/TextEditor.stories.tsx"],"names":[],"mappings":"AAIA,OAAO,YAAY,CAAC;AAGpB,OAAO,KAA+B,MAAM,OAAO,CAAC;;;;;;;;;;;;;;AA0DpD,wBAIE;AAEF,eAAO,MAAM,OAAO,IAAK,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type RangeSet, StateField } from '@codemirror/state';
|
|
2
|
+
type HyperlinkDecorationConfig = {
|
|
3
|
+
link?: boolean;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* Creates a state field to replace AST elements with a hyperlink widget.
|
|
7
|
+
* https://codemirror.net/docs/ref/#state.StateField
|
|
8
|
+
*/
|
|
9
|
+
export declare const hyperlinkDecoration: ({ link }?: HyperlinkDecorationConfig) => StateField<RangeSet<any>>;
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=hyperlinkDecoration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hyperlinkDecoration.d.ts","sourceRoot":"","sources":["../../../../../../src/components/TextEditor/extensions/hyperlinkDecoration.ts"],"names":[],"mappings":"AAMA,OAAO,EAAoB,KAAK,QAAQ,EAAmB,UAAU,EAAoB,MAAM,mBAAmB,CAAC;AA6CnH,KAAK,yBAAyB,GAAG;IAC/B,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,mBAAmB,cAAc,yBAAyB,8BAMtE,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type OnHyperlinkHover = (el: Element, url: string) => void;
|
|
2
|
+
/**
|
|
3
|
+
* https://codemirror.net/examples/tooltip
|
|
4
|
+
* https://codemirror.net/docs/ref/#view.hoverTooltip
|
|
5
|
+
* https://github.com/codemirror/view/blob/main/src/tooltip.ts
|
|
6
|
+
*/
|
|
7
|
+
export declare const createHyperlinkTooltip: (onHover: OnHyperlinkHover, regexp?: RegExp) => import("@codemirror/state").Extension;
|
|
8
|
+
//# sourceMappingURL=hyperlinkTooltip.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hyperlinkTooltip.d.ts","sourceRoot":"","sources":["../../../../../../src/components/TextEditor/extensions/hyperlinkTooltip.tsx"],"names":[],"mappings":"AAUA,MAAM,MAAM,gBAAgB,GAAG,CAAC,EAAE,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;AAElE;;;;GAIG;AAEH,eAAO,MAAM,sBAAsB,YAAa,gBAAgB,2DA0C5D,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type Extension } from '@codemirror/state';
|
|
2
|
+
import { type DecorationSet, MatchDecorator, ViewPlugin, type ViewUpdate } from '@codemirror/view';
|
|
3
|
+
export declare function hyperLinkExtension(): ViewPlugin<{
|
|
4
|
+
readonly decorator: MatchDecorator;
|
|
5
|
+
decorations: DecorationSet;
|
|
6
|
+
update(update: ViewUpdate): void;
|
|
7
|
+
}>;
|
|
8
|
+
export declare const hyperlinkStyle: Extension;
|
|
9
|
+
export declare const hyperlinkWidget: Extension;
|
|
10
|
+
//# sourceMappingURL=hyperlinkWidget.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hyperlinkWidget.d.ts","sourceRoot":"","sources":["../../../../../../src/components/TextEditor/extensions/hyperlinkWidget.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAEL,KAAK,aAAa,EAElB,cAAc,EACd,UAAU,EACV,KAAK,UAAU,EAChB,MAAM,kBAAkB,CAAC;AAuD1B,wBAAgB,kBAAkB;wBAGR,cAAc;;mBAOnB,UAAU;GAwB9B;AAED,eAAO,MAAM,cAAc,WAYzB,CAAC;AAEH,eAAO,MAAM,eAAe,EAAE,SAAkD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/components/TextEditor/extensions/index.ts"],"names":[],"mappings":"AAIA,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/components/TextEditor/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAExC,cAAc,cAAc,CAAC;AAE7B,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"theme.d.ts","sourceRoot":"","sources":["../../../../../src/components/TextEditor/theme.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,WAAW,CAAC;AAM3C;;;GAGG;AAEH,eAAO,MAAM,aAAa,EAAE;IAC1B,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;CAiB/B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/index.ts"],"names":[],"mappings":"AAIA,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/index.ts"],"names":[],"mappings":"AAIA,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/react-ui-editor",
|
|
3
|
-
"version": "0.3.9-main.
|
|
3
|
+
"version": "0.3.9-main.de60860",
|
|
4
4
|
"description": "Document editing experience within a DXOS shell.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -43,38 +43,42 @@
|
|
|
43
43
|
"prosemirror-model": "^1.19.0",
|
|
44
44
|
"prosemirror-state": "^1.4.2",
|
|
45
45
|
"prosemirror-view": "^1.30.1",
|
|
46
|
+
"style-mod": "^4.1.0",
|
|
46
47
|
"y-codemirror.next": "^0.3.2",
|
|
47
48
|
"y-prosemirror": "~1.0.20",
|
|
48
49
|
"y-protocols": "^1.0.5",
|
|
49
50
|
"yjs": "^13.6.10",
|
|
50
|
-
"@dxos/debug": "0.3.9-main.
|
|
51
|
-
"@dxos/display-name": "0.3.9-main.
|
|
52
|
-
"@dxos/
|
|
53
|
-
"@dxos/
|
|
54
|
-
"@dxos/react-
|
|
55
|
-
"@dxos/react-
|
|
56
|
-
"@dxos/
|
|
57
|
-
"@dxos/util": "0.3.9-main.
|
|
58
|
-
"@dxos/
|
|
51
|
+
"@dxos/debug": "0.3.9-main.de60860",
|
|
52
|
+
"@dxos/display-name": "0.3.9-main.de60860",
|
|
53
|
+
"@dxos/log": "0.3.9-main.de60860",
|
|
54
|
+
"@dxos/protocols": "0.3.9-main.de60860",
|
|
55
|
+
"@dxos/react-ui": "0.3.9-main.de60860",
|
|
56
|
+
"@dxos/react-async": "0.3.9-main.de60860",
|
|
57
|
+
"@dxos/text-model": "0.3.9-main.de60860",
|
|
58
|
+
"@dxos/util": "0.3.9-main.de60860",
|
|
59
|
+
"@dxos/react-ui-theme": "0.3.9-main.de60860"
|
|
59
60
|
},
|
|
60
61
|
"devDependencies": {
|
|
61
62
|
"@codemirror/basic-setup": "^0.20.0",
|
|
63
|
+
"@phosphor-icons/react": "^2.0.5",
|
|
62
64
|
"@types/codemirror": "^5.60.14",
|
|
63
65
|
"@types/lodash.get": "^4.4.7",
|
|
64
66
|
"@types/react": "^18.0.21",
|
|
65
67
|
"@types/react-dom": "^18.0.6",
|
|
66
68
|
"react": "^18.2.0",
|
|
67
69
|
"react-dom": "^18.2.0",
|
|
68
|
-
"@dxos/config": "0.3.9-main.
|
|
69
|
-
"@dxos/automerge": "0.3.9-main.
|
|
70
|
-
"@dxos/echo-schema": "0.3.9-main.
|
|
71
|
-
"@dxos/
|
|
72
|
-
"@dxos/
|
|
70
|
+
"@dxos/config": "0.3.9-main.de60860",
|
|
71
|
+
"@dxos/automerge": "0.3.9-main.de60860",
|
|
72
|
+
"@dxos/echo-schema": "0.3.9-main.de60860",
|
|
73
|
+
"@dxos/echo-typegen": "0.3.9-main.de60860",
|
|
74
|
+
"@dxos/react-client": "0.3.9-main.de60860",
|
|
75
|
+
"@dxos/storybook-utils": "0.3.9-main.de60860"
|
|
73
76
|
},
|
|
74
77
|
"peerDependencies": {
|
|
78
|
+
"@phosphor-icons/react": "^2.0.5",
|
|
75
79
|
"react": "^18.2.0",
|
|
76
80
|
"react-dom": "^18.2.0",
|
|
77
|
-
"@dxos/react-client": "0.3.9-main.
|
|
81
|
+
"@dxos/react-client": "0.3.9-main.de60860"
|
|
78
82
|
},
|
|
79
83
|
"publishConfig": {
|
|
80
84
|
"access": "public"
|
|
@@ -8,8 +8,7 @@ import React, { useEffect, useRef, useState } from 'react';
|
|
|
8
8
|
|
|
9
9
|
import { type Prop, next as automerge } from '@dxos/automerge/automerge';
|
|
10
10
|
|
|
11
|
-
import { plugin as amgPlugin } from './automerge-plugin';
|
|
12
|
-
import { reconcile } from './automerge-plugin/plugin';
|
|
11
|
+
import { plugin as amgPlugin, reconcile } from './automerge-plugin';
|
|
13
12
|
import { Peer } from './demo';
|
|
14
13
|
|
|
15
14
|
type EditorProps = {
|
|
@@ -9,14 +9,16 @@ import React, { useState } from 'react';
|
|
|
9
9
|
import { type PublicKey } from '@dxos/react-client';
|
|
10
10
|
import { TextObject, TextKind, useQuery, useSpace } from '@dxos/react-client/echo';
|
|
11
11
|
import { useIdentity } from '@dxos/react-client/halo';
|
|
12
|
-
import {
|
|
12
|
+
import { setupPeersInSpace, textGenerator, useDataGenerator, ClientRepeater } from '@dxos/react-client/testing';
|
|
13
13
|
import { useId } from '@dxos/react-ui';
|
|
14
|
+
import { withTheme } from '@dxos/storybook-utils';
|
|
14
15
|
|
|
15
16
|
import { Editor, type EditorProps } from './Editor';
|
|
16
17
|
import { EditorDocument, types as schema } from '../../testing';
|
|
17
18
|
|
|
18
19
|
export default {
|
|
19
20
|
component: Editor,
|
|
21
|
+
decorators: [withTheme],
|
|
20
22
|
};
|
|
21
23
|
|
|
22
24
|
const Story = ({ spaceKey, ...params }: Pick<EditorProps, 'slots'> & { spaceKey: PublicKey }) => {
|
|
@@ -54,8 +56,7 @@ const { spaceKey: markdownSpaceKey, clients: markdownClients } = await setupPeer
|
|
|
54
56
|
});
|
|
55
57
|
|
|
56
58
|
export const Markdown = {
|
|
57
|
-
render: (
|
|
58
|
-
decorators: [ClientDecorator({ clients: markdownClients })],
|
|
59
|
+
render: () => <ClientRepeater Component={Story} clients={markdownClients} args={{ spaceKey: markdownSpaceKey }} />,
|
|
59
60
|
};
|
|
60
61
|
|
|
61
62
|
const { spaceKey: richSpaceKey, clients: richClients } = await setupPeersInSpace({
|
|
@@ -68,7 +69,7 @@ const { spaceKey: richSpaceKey, clients: richClients } = await setupPeersInSpace
|
|
|
68
69
|
});
|
|
69
70
|
|
|
70
71
|
export const Rich = {
|
|
71
|
-
render: (
|
|
72
|
+
render: () => <ClientRepeater Component={Story} clients={richClients} args={{ spaceKey: richSpaceKey }} />,
|
|
72
73
|
args: {
|
|
73
74
|
slots: {
|
|
74
75
|
editor: {
|
|
@@ -76,5 +77,4 @@ export const Rich = {
|
|
|
76
77
|
},
|
|
77
78
|
},
|
|
78
79
|
},
|
|
79
|
-
decorators: [ClientDecorator({ clients: richClients })],
|
|
80
80
|
};
|
|
@@ -16,7 +16,6 @@ export type EditorProps = UseTextModelOptions & {
|
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* Memoized editor which depends on DXOS platform.
|
|
19
|
-
*
|
|
20
19
|
* Determines which editor to render based on the kind of text.
|
|
21
20
|
*/
|
|
22
21
|
// NOTE: Without `memo`, if parent component uses `observer` the editor re-renders excessively.
|
|
@@ -24,6 +23,10 @@ export type EditorProps = UseTextModelOptions & {
|
|
|
24
23
|
export const Editor = memo(
|
|
25
24
|
forwardRef<TipTapEditor | MarkdownEditorRef, EditorProps>(({ slots, ...params }, forwardedRef) => {
|
|
26
25
|
const model = useTextModel(params);
|
|
26
|
+
if (!model) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
|
|
27
30
|
if (model?.content instanceof YXmlFragment) {
|
|
28
31
|
return <RichTextEditor ref={forwardedRef as Ref<TipTapEditor>} model={model} slots={slots} />;
|
|
29
32
|
} else {
|
|
@@ -8,50 +8,63 @@ import React, { useState } from 'react';
|
|
|
8
8
|
|
|
9
9
|
import { PublicKey } from '@dxos/react-client';
|
|
10
10
|
import { TextKind } from '@dxos/react-client/echo';
|
|
11
|
-
import {
|
|
11
|
+
import { ClientRepeater, textGenerator, useDataGenerator } from '@dxos/react-client/testing';
|
|
12
12
|
import { useId } from '@dxos/react-ui';
|
|
13
|
+
import { withTheme } from '@dxos/storybook-utils';
|
|
13
14
|
|
|
14
15
|
import { MarkdownEditor } from './Markdown';
|
|
15
16
|
import { Replicator, useYjsModel } from '../../testing';
|
|
16
17
|
|
|
17
18
|
export default {
|
|
18
19
|
component: MarkdownEditor,
|
|
20
|
+
decorators: [withTheme],
|
|
19
21
|
};
|
|
20
22
|
|
|
23
|
+
const content = [
|
|
24
|
+
'',
|
|
25
|
+
'',
|
|
26
|
+
'This is all about [DXOS](https://dxos.org); read more [here](https://docs.dxos.org/guide/getting-started.html).',
|
|
27
|
+
'',
|
|
28
|
+
'This is a link: https://www.dxos.org',
|
|
29
|
+
'',
|
|
30
|
+
'',
|
|
31
|
+
].join('\n');
|
|
32
|
+
|
|
21
33
|
export const Default = {
|
|
22
34
|
args: {
|
|
23
35
|
model: {
|
|
24
36
|
id: 'editor',
|
|
25
|
-
content
|
|
37
|
+
content,
|
|
26
38
|
},
|
|
27
39
|
},
|
|
28
40
|
};
|
|
29
41
|
|
|
30
42
|
const replicator = new Replicator(TextKind.PLAIN);
|
|
31
43
|
|
|
44
|
+
const Story = () => {
|
|
45
|
+
const [generate, setGenerate] = useState(false);
|
|
46
|
+
const generateId = useId('generate');
|
|
47
|
+
|
|
48
|
+
const [id] = useState(PublicKey.random().toHex());
|
|
49
|
+
const model = useYjsModel({ id, replicator });
|
|
50
|
+
|
|
51
|
+
useDataGenerator({
|
|
52
|
+
generator: generate ? textGenerator : undefined,
|
|
53
|
+
options: { text: typeof model?.content !== 'string' ? model?.content : undefined },
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<main className='flex-1 min-w-0 p-4'>
|
|
58
|
+
<div id={generateId} className='flex'>
|
|
59
|
+
<input type='checkbox' onChange={(event) => setGenerate(event.target.checked)} />
|
|
60
|
+
Generate Data
|
|
61
|
+
</div>
|
|
62
|
+
<MarkdownEditor model={model} />
|
|
63
|
+
</main>
|
|
64
|
+
);
|
|
65
|
+
};
|
|
66
|
+
|
|
32
67
|
export const WithYjs = {
|
|
33
|
-
render: () => {
|
|
34
|
-
const [generate, setGenerate] = useState(false);
|
|
35
|
-
const generateId = useId('generate');
|
|
36
|
-
|
|
37
|
-
const [id] = useState(PublicKey.random().toHex());
|
|
38
|
-
const model = useYjsModel({ id, replicator });
|
|
39
|
-
|
|
40
|
-
useDataGenerator({
|
|
41
|
-
generator: generate ? textGenerator : undefined,
|
|
42
|
-
options: { text: typeof model?.content !== 'string' ? model?.content : undefined },
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
return (
|
|
46
|
-
<main className='flex-1 min-w-0 p-4'>
|
|
47
|
-
<div id={generateId} className='flex'>
|
|
48
|
-
<input type='checkbox' onChange={(event) => setGenerate(event.target.checked)} />
|
|
49
|
-
Generate Data
|
|
50
|
-
</div>
|
|
51
|
-
<MarkdownEditor model={model} />
|
|
52
|
-
</main>
|
|
53
|
-
);
|
|
54
|
-
},
|
|
55
68
|
// TODO(wittjosiah): Decorator for doing this without clients being initialized?
|
|
56
|
-
|
|
69
|
+
render: () => <ClientRepeater count={2} Component={Story} />,
|
|
57
70
|
};
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
import { languages } from '@codemirror/language-data';
|
|
16
16
|
import { lintKeymap } from '@codemirror/lint';
|
|
17
17
|
import { searchKeymap, highlightSelectionMatches } from '@codemirror/search';
|
|
18
|
-
import { EditorState, StateField, type Text } from '@codemirror/state';
|
|
18
|
+
import { EditorState, type Extension, StateField, type Text } from '@codemirror/state';
|
|
19
19
|
import { oneDarkHighlightStyle } from '@codemirror/theme-one-dark';
|
|
20
20
|
import {
|
|
21
21
|
keymap,
|
|
@@ -30,6 +30,7 @@ import {
|
|
|
30
30
|
EditorView,
|
|
31
31
|
} from '@codemirror/view';
|
|
32
32
|
import { useFocusableGroup } from '@fluentui/react-tabster';
|
|
33
|
+
// import { GFM } from '@lezer/markdown';
|
|
33
34
|
import { vim } from '@replit/codemirror-vim';
|
|
34
35
|
import React, {
|
|
35
36
|
type KeyboardEvent,
|
|
@@ -48,16 +49,18 @@ import { getColorForValue } from '@dxos/react-ui-theme';
|
|
|
48
49
|
import { YText } from '@dxos/text-model';
|
|
49
50
|
|
|
50
51
|
import { markdownTagsExtension } from './markdownTags';
|
|
51
|
-
import {
|
|
52
|
+
import { markdownHighlightStyle, markdownTheme } from './markdownTheme';
|
|
52
53
|
import { type EditorModel, type EditorSlots } from '../../model';
|
|
53
54
|
|
|
54
55
|
export const EditorModes = ['default', 'vim'] as const;
|
|
55
56
|
export type EditorMode = (typeof EditorModes)[number];
|
|
56
57
|
|
|
57
58
|
export type MarkdownEditorProps = {
|
|
58
|
-
model
|
|
59
|
+
model: EditorModel;
|
|
59
60
|
slots?: EditorSlots;
|
|
60
61
|
editorMode?: EditorMode;
|
|
62
|
+
showWidgets?: boolean;
|
|
63
|
+
extensions?: Extension[];
|
|
61
64
|
onChange?: (content: string | Text) => void;
|
|
62
65
|
};
|
|
63
66
|
|
|
@@ -68,7 +71,7 @@ export type MarkdownEditorRef = {
|
|
|
68
71
|
};
|
|
69
72
|
|
|
70
73
|
export const MarkdownEditor = forwardRef<MarkdownEditorRef, MarkdownEditorProps>(
|
|
71
|
-
({ model, slots = {}, editorMode, onChange }, forwardedRef) => {
|
|
74
|
+
({ model, slots = {}, editorMode, extensions = [], onChange }, forwardedRef) => {
|
|
72
75
|
const { id, content, provider, peer } = model ?? {};
|
|
73
76
|
const { themeMode } = useThemeContext();
|
|
74
77
|
const tabsterDOMAttribute = useFocusableGroup({ tabBehavior: 'limited' });
|
|
@@ -115,51 +118,77 @@ export const MarkdownEditor = forwardRef<MarkdownEditorRef, MarkdownEditorProps>
|
|
|
115
118
|
const state = EditorState.create({
|
|
116
119
|
doc: content?.toString(),
|
|
117
120
|
extensions: [
|
|
118
|
-
// Based on https://github.com/codemirror/dev/issues/44#issuecomment-789093799
|
|
121
|
+
// Based on https://github.com/codemirror/dev/issues/44#issuecomment-789093799
|
|
119
122
|
listenChangesExtension,
|
|
120
123
|
|
|
121
|
-
|
|
122
|
-
|
|
124
|
+
// TODO(burdon): Create custom bundle to make this class more reusable and retire simpler TextEditor component.
|
|
123
125
|
// All of https://github.com/codemirror/basic-setup minus line numbers and fold gutter.
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
history(),
|
|
127
|
-
drawSelection(),
|
|
128
|
-
dropCursor(),
|
|
129
|
-
EditorState.allowMultipleSelections.of(true),
|
|
130
|
-
indentOnInput(),
|
|
131
|
-
syntaxHighlighting(defaultHighlightStyle, { fallback: true }),
|
|
126
|
+
// https://codemirror.net/docs/ref/#codemirror.basicSetup
|
|
127
|
+
autocompletion(),
|
|
132
128
|
bracketMatching(),
|
|
133
129
|
closeBrackets(),
|
|
134
|
-
autocompletion(),
|
|
135
|
-
rectangularSelection(),
|
|
136
130
|
crosshairCursor(),
|
|
131
|
+
dropCursor(),
|
|
132
|
+
drawSelection(),
|
|
137
133
|
highlightActiveLine(),
|
|
134
|
+
highlightActiveLineGutter(),
|
|
138
135
|
highlightSelectionMatches(),
|
|
136
|
+
highlightSpecialChars(),
|
|
137
|
+
history(),
|
|
138
|
+
indentOnInput(),
|
|
139
139
|
placeholder(slots.editor?.placeholder ?? ''), // TODO(burdon): Needs consistent styling.
|
|
140
|
+
rectangularSelection(),
|
|
141
|
+
syntaxHighlighting(defaultHighlightStyle, { fallback: true }),
|
|
142
|
+
EditorState.allowMultipleSelections.of(true),
|
|
143
|
+
EditorView.lineWrapping,
|
|
144
|
+
|
|
140
145
|
keymap.of([
|
|
141
146
|
...closeBracketsKeymap,
|
|
147
|
+
...completionKeymap,
|
|
142
148
|
...defaultKeymap,
|
|
143
|
-
...searchKeymap,
|
|
144
|
-
...historyKeymap,
|
|
145
149
|
...foldKeymap,
|
|
146
|
-
...
|
|
150
|
+
...historyKeymap,
|
|
147
151
|
...lintKeymap,
|
|
152
|
+
...searchKeymap,
|
|
148
153
|
indentWithTab,
|
|
149
154
|
]),
|
|
150
|
-
EditorView.lineWrapping,
|
|
151
155
|
|
|
152
|
-
//
|
|
153
|
-
markdown
|
|
156
|
+
// Main extension.
|
|
157
|
+
// https://github.com/codemirror/lang-markdown
|
|
158
|
+
markdown({
|
|
159
|
+
base: markdownLanguage,
|
|
160
|
+
codeLanguages: languages,
|
|
161
|
+
extensions: [
|
|
162
|
+
// TODO(burdon): This seems to upgrade the parser.
|
|
163
|
+
// GitHub flavored markdown bundle: Table, TaskList, Strikethrough, and Autolink.
|
|
164
|
+
// https://github.com/lezer-parser/markdown?tab=readme-ov-file#github-flavored-markdown
|
|
165
|
+
// https://github.github.com/gfm
|
|
166
|
+
// GFM,
|
|
167
|
+
|
|
168
|
+
// Custom styling.
|
|
169
|
+
markdownTagsExtension,
|
|
170
|
+
],
|
|
171
|
+
}),
|
|
172
|
+
|
|
173
|
+
// Theme.
|
|
154
174
|
EditorView.theme({ ...markdownTheme, ...slots.editor?.markdownTheme }),
|
|
155
175
|
...(themeMode === 'dark'
|
|
156
176
|
? [syntaxHighlighting(oneDarkHighlightStyle)]
|
|
157
177
|
: [syntaxHighlighting(defaultHighlightStyle)]),
|
|
178
|
+
|
|
158
179
|
// TODO(thure): All but one rule here apply to both themes; rename or refactor.
|
|
159
|
-
syntaxHighlighting(
|
|
180
|
+
syntaxHighlighting(markdownHighlightStyle),
|
|
181
|
+
|
|
182
|
+
// Settings.
|
|
183
|
+
...(editorMode === 'vim' ? [vim()] : []),
|
|
160
184
|
|
|
185
|
+
// TODO(burdon): Move to extensions.
|
|
161
186
|
// Replication and awareness (incl. remote selection).
|
|
187
|
+
// https://codemirror.net/docs/ref/#collab
|
|
162
188
|
...(content instanceof YText ? [yCollab(content, provider?.awareness)] : []),
|
|
189
|
+
|
|
190
|
+
// Custom.
|
|
191
|
+
...extensions,
|
|
163
192
|
],
|
|
164
193
|
});
|
|
165
194
|
|