@dxos/react-ui-editor 0.3.10-main.90b298e → 0.3.10-main.92d1f2c
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 +897 -293
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/types/src/components/TextEditor/MarkdownEditor.stories.d.ts +19 -1
- package/dist/types/src/components/TextEditor/MarkdownEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/TextEditor.d.ts +2 -1
- package/dist/types/src/components/TextEditor/TextEditor.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/extensions/autocomplete.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/extensions/basic.d.ts +2 -1
- package/dist/types/src/components/TextEditor/extensions/basic.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/extensions/blast.d.ts +25 -0
- package/dist/types/src/components/TextEditor/extensions/blast.d.ts.map +1 -0
- package/dist/types/src/components/TextEditor/extensions/comments.d.ts +1 -1
- package/dist/types/src/components/TextEditor/extensions/comments.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/extensions/demo.d.ts +2 -1
- package/dist/types/src/components/TextEditor/extensions/demo.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/extensions/experimental.d.ts +1 -1
- package/dist/types/src/components/TextEditor/extensions/experimental.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/extensions/image.d.ts +4 -0
- package/dist/types/src/components/TextEditor/extensions/image.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 -1
- package/dist/types/src/components/TextEditor/extensions/link.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/extensions/listener.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/extensions/markdown/bundle.d.ts +2 -1
- package/dist/types/src/components/TextEditor/extensions/markdown/bundle.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/extensions/markdown/highlight.d.ts +9 -3
- package/dist/types/src/components/TextEditor/extensions/markdown/highlight.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/extensions/mention.d.ts +6 -0
- package/dist/types/src/components/TextEditor/extensions/mention.d.ts.map +1 -0
- package/dist/types/src/components/TextEditor/extensions/table.d.ts +8 -0
- package/dist/types/src/components/TextEditor/extensions/table.d.ts.map +1 -0
- package/dist/types/src/components/TextEditor/extensions/tasklist.d.ts +2 -1
- package/dist/types/src/components/TextEditor/extensions/tasklist.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/themes/default.d.ts +5 -0
- package/dist/types/src/components/TextEditor/themes/default.d.ts.map +1 -1
- package/dist/types/src/hooks/automerge/automerge.stories.d.ts +8 -1
- package/dist/types/src/hooks/automerge/automerge.stories.d.ts.map +1 -1
- package/dist/types/src/{components/TextEditor → hooks/yjs}/yjs.stories.d.ts +1 -1
- package/dist/types/src/hooks/yjs/yjs.stories.d.ts.map +1 -0
- package/dist/types/src/styles/markdown.d.ts +3 -2
- package/dist/types/src/styles/markdown.d.ts.map +1 -1
- package/package.json +20 -20
- package/src/components/TextEditor/MarkdownEditor.stories.tsx +102 -27
- package/src/components/TextEditor/TextEditor.tsx +13 -23
- package/src/components/TextEditor/extensions/autocomplete.ts +5 -20
- package/src/components/TextEditor/extensions/basic.ts +2 -1
- package/src/components/TextEditor/extensions/blast.ts +387 -0
- package/src/components/TextEditor/extensions/comments.ts +21 -39
- package/src/components/TextEditor/extensions/demo.ts +4 -1
- package/src/components/TextEditor/extensions/experimental.tsx +14 -35
- package/src/components/TextEditor/extensions/image.ts +67 -0
- package/src/components/TextEditor/extensions/index.ts +4 -0
- package/src/components/TextEditor/extensions/link.ts +17 -25
- package/src/components/TextEditor/extensions/listener.ts +3 -3
- package/src/components/TextEditor/extensions/markdown/bundle.ts +30 -19
- package/src/components/TextEditor/extensions/markdown/highlight.ts +147 -108
- package/src/components/TextEditor/extensions/mention.ts +31 -0
- package/src/components/TextEditor/extensions/table.ts +122 -0
- package/src/components/TextEditor/extensions/tasklist.ts +41 -27
- package/src/components/TextEditor/themes/default.ts +54 -2
- package/src/hooks/automerge/automerge.stories.tsx +3 -2
- package/src/{components/TextEditor → hooks/yjs}/yjs.stories.tsx +1 -1
- package/src/styles/markdown.ts +14 -8
- package/dist/types/src/components/TextEditor/yjs.stories.d.ts.map +0 -1
|
@@ -12,12 +12,20 @@ import {
|
|
|
12
12
|
type ViewUpdate,
|
|
13
13
|
} from '@codemirror/view';
|
|
14
14
|
|
|
15
|
+
// TODO(burdon): Reconcile with theme.
|
|
16
|
+
const styles = EditorView.baseTheme({
|
|
17
|
+
'& .cm-task-item': {
|
|
18
|
+
paddingLeft: '4px',
|
|
19
|
+
paddingRight: '8px',
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
|
|
15
23
|
class CheckboxWidget extends WidgetType {
|
|
16
24
|
constructor(
|
|
17
25
|
private readonly _pos: number,
|
|
18
26
|
private _checked: boolean,
|
|
19
27
|
private readonly _indent: number,
|
|
20
|
-
private readonly _onCheck
|
|
28
|
+
private readonly _onCheck?: (check: boolean) => void,
|
|
21
29
|
) {
|
|
22
30
|
super();
|
|
23
31
|
}
|
|
@@ -35,10 +43,15 @@ class CheckboxWidget extends WidgetType {
|
|
|
35
43
|
const input = wrap.appendChild(document.createElement('input'));
|
|
36
44
|
input.type = 'checkbox';
|
|
37
45
|
input.checked = this._checked;
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
46
|
+
if (!this._onCheck) {
|
|
47
|
+
input.setAttribute('disabled', 'true');
|
|
48
|
+
}
|
|
49
|
+
if (this._onCheck) {
|
|
50
|
+
input.onchange = (event: Event) => {
|
|
51
|
+
this._onCheck?.((event.target as any).checked);
|
|
52
|
+
return true;
|
|
53
|
+
};
|
|
54
|
+
}
|
|
42
55
|
|
|
43
56
|
return wrap;
|
|
44
57
|
}
|
|
@@ -48,15 +61,9 @@ class CheckboxWidget extends WidgetType {
|
|
|
48
61
|
}
|
|
49
62
|
}
|
|
50
63
|
|
|
51
|
-
|
|
52
|
-
const styles = EditorView.baseTheme({
|
|
53
|
-
'& .cm-task-item': {
|
|
54
|
-
paddingLeft: '4px',
|
|
55
|
-
paddingRight: '8px',
|
|
56
|
-
},
|
|
57
|
-
});
|
|
64
|
+
export type TasklistOptions = {};
|
|
58
65
|
|
|
59
|
-
export const tasklist = () => {
|
|
66
|
+
export const tasklist = (options: TasklistOptions = {}) => {
|
|
60
67
|
// TODO(burdon): Matcher isn't as precise as syntax tree.
|
|
61
68
|
// Allows for indents to be greater than AST would allow.
|
|
62
69
|
const taskMatcher = new MatchDecorator({
|
|
@@ -65,20 +72,27 @@ export const tasklist = () => {
|
|
|
65
72
|
const indent = Math.floor(match[1].length / 2);
|
|
66
73
|
const checked = match[2] === 'x' || match[2] === 'X';
|
|
67
74
|
return Decoration.replace({
|
|
68
|
-
widget: new CheckboxWidget(
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
75
|
+
widget: new CheckboxWidget(
|
|
76
|
+
pos,
|
|
77
|
+
checked,
|
|
78
|
+
indent,
|
|
79
|
+
view.state.readOnly
|
|
80
|
+
? undefined
|
|
81
|
+
: (checked) => {
|
|
82
|
+
const idx = pos + match[0].indexOf('[') + 1;
|
|
83
|
+
view.dispatch({
|
|
84
|
+
changes: {
|
|
85
|
+
from: idx,
|
|
86
|
+
to: idx + 1,
|
|
87
|
+
insert: checked ? 'x' : ' ',
|
|
88
|
+
},
|
|
89
|
+
// TODO(burdon): Restore cursor position? More useful to move to end of line (can indent).
|
|
90
|
+
selection: {
|
|
91
|
+
anchor: idx + 3,
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
},
|
|
95
|
+
),
|
|
82
96
|
});
|
|
83
97
|
},
|
|
84
98
|
});
|
|
@@ -10,6 +10,11 @@ import { tokens } from '../../../styles';
|
|
|
10
10
|
/**
|
|
11
11
|
* Minimal styles.
|
|
12
12
|
* https://codemirror.net/examples/styling
|
|
13
|
+
*
|
|
14
|
+
* Examples:
|
|
15
|
+
* - https://github.com/codemirror/view/blob/main/src/theme.ts
|
|
16
|
+
* - https://github.com/codemirror/theme-one-dark/blob/main/src/one-dark.ts
|
|
17
|
+
*
|
|
13
18
|
* NOTE: Use one of '&', '&light', and '&dark' prefix to scope instance.
|
|
14
19
|
* NOTE: `light` and `dark` selectors are preprocessed by CodeMirror and can only be in the base theme.
|
|
15
20
|
*/
|
|
@@ -136,8 +141,55 @@ export const defaultTheme: {
|
|
|
136
141
|
'& .cm-tooltip': {
|
|
137
142
|
border: 'none',
|
|
138
143
|
},
|
|
139
|
-
|
|
140
|
-
|
|
144
|
+
'& .cm-tooltip-below': {},
|
|
145
|
+
|
|
146
|
+
//
|
|
147
|
+
// autocomplete
|
|
148
|
+
//
|
|
149
|
+
'& .cm-tooltip-autocomplete': {
|
|
150
|
+
marginTop: '4px',
|
|
151
|
+
marginLeft: '-3px',
|
|
152
|
+
},
|
|
153
|
+
'& .cm-tooltip-autocomplete ul li': {},
|
|
154
|
+
'& .cm-tooltip-autocomplete ul li[aria-selected]': {},
|
|
155
|
+
'& .cm-completionIcon': {
|
|
156
|
+
display: 'none',
|
|
157
|
+
},
|
|
158
|
+
'& .cm-completionLabel': {
|
|
159
|
+
fontFamily: get(tokens, 'fontFamily.body', []).join(','),
|
|
160
|
+
},
|
|
161
|
+
'& .cm-completionMatchedText': {
|
|
162
|
+
textDecoration: 'none',
|
|
163
|
+
},
|
|
164
|
+
|
|
165
|
+
//
|
|
166
|
+
// widgets
|
|
167
|
+
//
|
|
168
|
+
'& .cm-widgetBuffer': {
|
|
169
|
+
display: 'none',
|
|
170
|
+
height: 0,
|
|
171
|
+
},
|
|
172
|
+
|
|
173
|
+
//
|
|
174
|
+
// table
|
|
175
|
+
//
|
|
176
|
+
'& .cm-table-head': {
|
|
177
|
+
padding: '2px 16px 2px 0px',
|
|
178
|
+
borderBottom: `1px solid ${get(tokens, 'extend.colors.neutral.500')}`,
|
|
179
|
+
fontWeight: 100,
|
|
180
|
+
textAlign: 'left',
|
|
181
|
+
color: get(tokens, 'extend.colors.neutral.500'),
|
|
182
|
+
},
|
|
183
|
+
'& .cm-table-cell': {
|
|
184
|
+
padding: '2px 16px 2px 0px',
|
|
185
|
+
},
|
|
186
|
+
|
|
187
|
+
//
|
|
188
|
+
// image
|
|
189
|
+
//
|
|
190
|
+
'& .cm-image': {
|
|
191
|
+
margin: '0.5rem 0',
|
|
192
|
+
},
|
|
141
193
|
|
|
142
194
|
//
|
|
143
195
|
// font size
|
|
@@ -12,7 +12,7 @@ import { ClientRepeater, textGenerator, useDataGenerator } from '@dxos/react-cli
|
|
|
12
12
|
import { useId, Input } from '@dxos/react-ui';
|
|
13
13
|
import { withTheme } from '@dxos/storybook-utils';
|
|
14
14
|
|
|
15
|
-
import { MarkdownEditor } from '
|
|
15
|
+
import { MarkdownEditor } from '../../components';
|
|
16
16
|
import { Replicator, useYjsModel } from '../../testing';
|
|
17
17
|
|
|
18
18
|
export default {
|
package/src/styles/markdown.ts
CHANGED
|
@@ -7,13 +7,18 @@ import { mx } from '@dxos/react-ui-theme';
|
|
|
7
7
|
export type HeadingLevel = 1 | 2 | 3 | 4 | 5 | 6;
|
|
8
8
|
|
|
9
9
|
// https://tailwindcss.com/docs/font-weight
|
|
10
|
-
export const
|
|
11
|
-
1: 'mbs-4 mbe-2 font-medium text-inherit no-underline text-4xl',
|
|
12
|
-
2: 'mbs-4 mbe-2 font-medium text-inherit no-underline text-3xl',
|
|
13
|
-
3: 'mbs-4 mbe-2 font-medium text-inherit no-underline text-2xl',
|
|
14
|
-
4: 'mbs-4 mbe-2 font-medium text-inherit no-underline text-xl',
|
|
15
|
-
5: 'mbs-4 mbe-2 font-medium text-inherit no-underline text-lg',
|
|
16
|
-
6: 'mbs-4 mbe-2 font-medium text-inherit no-underline',
|
|
10
|
+
export const headings: Record<HeadingLevel, string[]> = {
|
|
11
|
+
1: ['mbs-4 mbe-2 font-medium text-inherit no-underline text-4xl', '-ml-1.5'],
|
|
12
|
+
2: ['mbs-4 mbe-2 font-medium text-inherit no-underline text-3xl', '-ml-1.5'],
|
|
13
|
+
3: ['mbs-4 mbe-2 font-medium text-inherit no-underline text-2xl', '-ml-1.5'],
|
|
14
|
+
4: ['mbs-4 mbe-2 font-medium text-inherit no-underline text-xl', '-ml-[5px]'],
|
|
15
|
+
5: ['mbs-4 mbe-2 font-medium text-inherit no-underline text-lg', '-ml-[5px]'],
|
|
16
|
+
6: ['mbs-4 mbe-2 font-medium text-inherit no-underline', '-ml-[4px]'],
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export const heading = (level: HeadingLevel, readonly?: boolean) => {
|
|
20
|
+
const [style, offset] = headings[level];
|
|
21
|
+
return mx(style, readonly && offset);
|
|
17
22
|
};
|
|
18
23
|
|
|
19
24
|
export const text = 'text-neutral-800 dark:text-neutral-200';
|
|
@@ -37,7 +42,8 @@ export const inlineUrl = mx(code, 'px-1');
|
|
|
37
42
|
export const blockquote = mx('pl-1 mr-1 border-is-4 border-primary-500/70 dark:border-primary-500/30', light);
|
|
38
43
|
|
|
39
44
|
// TODO(burdon): Replace with widget.
|
|
40
|
-
export const horizontalRule =
|
|
45
|
+
export const horizontalRule =
|
|
46
|
+
'flex mlb-4 border-b text-neutral-100 dark:text-neutral-900 border-neutral-200 dark:border-neutral-800';
|
|
41
47
|
|
|
42
48
|
// TODO(thure): Tailwind was not seeing `[&>li:before]:content-["•"]` as a utility class, but it would work if instead of `"•"` it was `"X"`… why?
|
|
43
49
|
export const unorderedList =
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"yjs.stories.d.ts","sourceRoot":"","sources":["../../../../../src/components/TextEditor/yjs.stories.tsx"],"names":[],"mappings":"AAIA,OAAO,YAAY,CAAC;AAEpB,OAAO,KAAmB,MAAM,OAAO,CAAC;;;;;AAWxC,wBAGE;AA+BF,eAAO,MAAM,OAAO;;;CAInB,CAAC"}
|