@dxos/react-ui-editor 0.3.10-main.8fd45da → 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 +986 -296
- 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 +10 -6
- package/dist/types/src/components/TextEditor/extensions/comments.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/extensions/demo.d.ts +11 -0
- package/dist/types/src/components/TextEditor/extensions/demo.d.ts.map +1 -0
- 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 +5 -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 +4 -2
- 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/PatchSemaphore.d.ts +3 -0
- package/dist/types/src/hooks/automerge/PatchSemaphore.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/hooks/automerge/index.d.ts +1 -1
- package/dist/types/src/hooks/automerge/index.d.ts.map +1 -1
- package/dist/types/src/hooks/automerge/plugin.d.ts.map +1 -1
- package/dist/types/src/hooks/automerge/translation/automerge-to-codemirror.d.ts +5 -0
- package/dist/types/src/hooks/automerge/translation/automerge-to-codemirror.d.ts.map +1 -0
- package/dist/types/src/hooks/automerge/translation/codemirror-to-automerge.d.ts +6 -0
- package/dist/types/src/hooks/automerge/translation/codemirror-to-automerge.d.ts.map +1 -0
- package/dist/types/src/hooks/automerge/translation/index.d.ts +3 -0
- package/dist/types/src/hooks/automerge/translation/index.d.ts.map +1 -0
- 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 -19
- package/src/components/TextEditor/MarkdownEditor.stories.tsx +106 -29
- package/src/components/TextEditor/TextEditor.tsx +12 -8
- 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 +59 -60
- package/src/components/TextEditor/extensions/demo.ts +69 -0
- 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 +5 -0
- package/src/components/TextEditor/extensions/link.ts +17 -25
- package/src/components/TextEditor/extensions/listener.ts +4 -4
- 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/PatchSemaphore.ts +12 -9
- package/src/hooks/automerge/automerge.stories.tsx +3 -2
- package/src/hooks/automerge/index.ts +1 -1
- package/src/hooks/automerge/plugin.ts +1 -0
- package/src/hooks/automerge/{amToCodemirror.ts → translation/automerge-to-codemirror.ts} +10 -2
- package/src/hooks/automerge/{codeMirrorToAm.ts → translation/codemirror-to-automerge.ts} +7 -4
- package/src/hooks/automerge/translation/index.ts +6 -0
- 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
- package/dist/types/src/hooks/automerge/amToCodemirror.d.ts +0 -6
- package/dist/types/src/hooks/automerge/amToCodemirror.d.ts.map +0 -1
- package/dist/types/src/hooks/automerge/codeMirrorToAm.d.ts +0 -7
- package/dist/types/src/hooks/automerge/codeMirrorToAm.d.ts.map +0 -1
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2023 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { syntaxTree } from '@codemirror/language';
|
|
6
|
+
import { type EditorState, type RangeSet, RangeSetBuilder, StateField, type Transaction } from '@codemirror/state';
|
|
7
|
+
import { Decoration, EditorView, WidgetType } from '@codemirror/view';
|
|
8
|
+
|
|
9
|
+
// TODO(burdon): Snippet to create basic table.
|
|
10
|
+
// https://codemirror.net/docs/ref/#autocomplete.snippet
|
|
11
|
+
|
|
12
|
+
export type TableOptions = {};
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* GFM tables.
|
|
16
|
+
* https://github.github.com/gfm/#tables-extension
|
|
17
|
+
*/
|
|
18
|
+
export const table = (options: TableOptions = {}) => {
|
|
19
|
+
return StateField.define<RangeSet<any>>({
|
|
20
|
+
create: (state) => update(state, options),
|
|
21
|
+
update: (_: RangeSet<any>, tr: Transaction) => update(tr.state, options),
|
|
22
|
+
provide: (field) => EditorView.decorations.from(field),
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
type Table = {
|
|
27
|
+
from: number;
|
|
28
|
+
to: number;
|
|
29
|
+
header?: string[];
|
|
30
|
+
rows?: string[][];
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const update = (state: EditorState, options: TableOptions) => {
|
|
34
|
+
const builder = new RangeSetBuilder();
|
|
35
|
+
const cursor = state.selection.main.head;
|
|
36
|
+
|
|
37
|
+
const tables: Table[] = [];
|
|
38
|
+
const getTable = () => tables[tables.length - 1];
|
|
39
|
+
const getRow = () => {
|
|
40
|
+
const table = getTable();
|
|
41
|
+
return table.rows?.[table.rows.length - 1];
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
// Parse table.
|
|
45
|
+
// TODO(burdon): Use remark?: https://www.npmjs.com/package/remark-gfm
|
|
46
|
+
// TODO(burdon): Style in monospace:
|
|
47
|
+
// https://discuss.codemirror.net/t/markdown-table-highlighting/658
|
|
48
|
+
// https://github.com/lezer-parser/markdown/blob/main/src/extension.ts
|
|
49
|
+
syntaxTree(state).iterate({
|
|
50
|
+
enter: (node) => {
|
|
51
|
+
// Check if cursor is inside text.
|
|
52
|
+
switch (node.name) {
|
|
53
|
+
case 'Table': {
|
|
54
|
+
tables.push({ from: node.from, to: node.to });
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
case 'TableHeader': {
|
|
58
|
+
getTable().header = [];
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
case 'TableRow': {
|
|
62
|
+
(getTable().rows ??= []).push([]);
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
case 'TableCell': {
|
|
66
|
+
const row = getRow();
|
|
67
|
+
if (row) {
|
|
68
|
+
row.push(state.sliceDoc(node.from, node.to));
|
|
69
|
+
} else {
|
|
70
|
+
getTable().header?.push(state.sliceDoc(node.from, node.to));
|
|
71
|
+
}
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
tables.forEach((table) => {
|
|
79
|
+
const hide = state.readOnly || cursor < table.from || cursor > table.to;
|
|
80
|
+
hide && builder.add(table.from, table.to!, Decoration.replace({ widget: new TableWidget(table) }));
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
return builder.finish();
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
class TableWidget extends WidgetType {
|
|
87
|
+
constructor(readonly _table: Table) {
|
|
88
|
+
super();
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
override eq(other: WidgetType) {
|
|
92
|
+
return this._table.from === (other as any as TableWidget)?._table?.from;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
toDOM(view: EditorView) {
|
|
96
|
+
const table = document.createElement('table');
|
|
97
|
+
|
|
98
|
+
{
|
|
99
|
+
const header = table.appendChild(document.createElement('thead'));
|
|
100
|
+
const tr = header.appendChild(document.createElement('tr'));
|
|
101
|
+
this._table.header?.forEach((cell) => {
|
|
102
|
+
const th = document.createElement('th');
|
|
103
|
+
th.setAttribute('class', 'cm-table-head');
|
|
104
|
+
tr.appendChild(th).textContent = cell;
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
{
|
|
109
|
+
const body = table.appendChild(document.createElement('tbody'));
|
|
110
|
+
this._table.rows?.forEach((row) => {
|
|
111
|
+
const tr = body.appendChild(document.createElement('tr'));
|
|
112
|
+
row.forEach((cell) => {
|
|
113
|
+
const td = document.createElement('td');
|
|
114
|
+
td.setAttribute('class', 'cm-table-cell');
|
|
115
|
+
tr.appendChild(td).textContent = cell;
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return table;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
@@ -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
|
|
@@ -2,20 +2,24 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
// TODO(burdon): Additional copyright?
|
|
6
|
+
|
|
5
7
|
import { type EditorView } from '@codemirror/view';
|
|
6
8
|
|
|
7
9
|
import { next as automerge } from '@dxos/automerge/automerge';
|
|
8
10
|
|
|
9
|
-
import amToCodemirror from './amToCodemirror';
|
|
10
|
-
import codeMirrorToAm from './codeMirrorToAm';
|
|
11
11
|
import { type IDocHandle } from './handle';
|
|
12
12
|
import { type Field, isReconcileTx, getPath, reconcileAnnotationType, updateHeads, getLastHeads } from './plugin';
|
|
13
|
+
import { automergeToCodemirror, codemirrorToAutomerge } from './translation';
|
|
13
14
|
|
|
14
15
|
type Doc<T> = automerge.Doc<T>;
|
|
15
16
|
type Heads = automerge.Heads;
|
|
16
17
|
|
|
17
18
|
type ChangeFn = (atHeads: Heads, change: (doc: Doc<unknown>) => void) => Heads | undefined;
|
|
18
19
|
|
|
20
|
+
/**
|
|
21
|
+
* TODO(burdon): Comment.
|
|
22
|
+
*/
|
|
19
23
|
export class PatchSemaphore {
|
|
20
24
|
_field!: Field;
|
|
21
25
|
_inReconcile = false;
|
|
@@ -39,7 +43,7 @@ export class PatchSemaphore {
|
|
|
39
43
|
|
|
40
44
|
const transactions = view.state.field(this._field).unreconciledTransactions.filter((tx) => !isReconcileTx(tx));
|
|
41
45
|
|
|
42
|
-
// First undo all the unreconciled transactions
|
|
46
|
+
// First undo all the unreconciled transactions.
|
|
43
47
|
const toInvert = transactions.slice().reverse();
|
|
44
48
|
for (const tx of toInvert) {
|
|
45
49
|
const inverted = tx.changes.invert(tx.startState.doc);
|
|
@@ -50,19 +54,18 @@ export class PatchSemaphore {
|
|
|
50
54
|
});
|
|
51
55
|
}
|
|
52
56
|
|
|
53
|
-
//
|
|
54
|
-
let newHeads =
|
|
57
|
+
// Apply the unreconciled transactions to the document.
|
|
58
|
+
let newHeads = codemirrorToAutomerge(this._field, handle, transactions, view.state);
|
|
55
59
|
|
|
56
|
-
// NOTE: null and undefined each come from automerge and repo respectively
|
|
60
|
+
// NOTE: null and undefined each come from automerge and repo respectively.
|
|
57
61
|
if (newHeads === null || newHeads === undefined) {
|
|
58
62
|
// TODO: @alexjg this is the call that's resetting the editor state on click
|
|
59
63
|
newHeads = automerge.getHeads(handle.docSync()!);
|
|
60
64
|
}
|
|
61
65
|
|
|
62
|
-
//
|
|
63
|
-
// and apply that to the codemirror doc
|
|
66
|
+
// Now get the diff between the updated state of the document and the heads and apply that to the codemirror doc.
|
|
64
67
|
const diff = automerge.equals(oldHeads, newHeads) ? [] : automerge.diff(handle.docSync()!, oldHeads, newHeads);
|
|
65
|
-
|
|
68
|
+
automergeToCodemirror(view, selection, path, diff);
|
|
66
69
|
|
|
67
70
|
view.dispatch({
|
|
68
71
|
effects: updateHeads(newHeads),
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
// TODO(burdon): Additional copyright?
|
|
6
|
+
|
|
5
7
|
import { ChangeSet, type ChangeSpec, type EditorSelection, type EditorState } from '@codemirror/state';
|
|
6
8
|
import { type EditorView } from '@codemirror/view';
|
|
7
9
|
|
|
@@ -14,9 +16,14 @@ import {
|
|
|
14
16
|
type SpliceTextPatch,
|
|
15
17
|
} from '@dxos/automerge/automerge';
|
|
16
18
|
|
|
17
|
-
import { reconcileAnnotationType } from '
|
|
19
|
+
import { reconcileAnnotationType } from '../plugin';
|
|
18
20
|
|
|
19
|
-
export
|
|
21
|
+
export const automergeToCodemirror = (
|
|
22
|
+
view: EditorView,
|
|
23
|
+
selection: EditorSelection,
|
|
24
|
+
target: Prop[],
|
|
25
|
+
patches: Patch[],
|
|
26
|
+
) => {
|
|
20
27
|
for (const patch of patches) {
|
|
21
28
|
const changeSpec = handlePatch(patch, target, view.state);
|
|
22
29
|
if (changeSpec != null) {
|
|
@@ -28,6 +35,7 @@ export default (view: EditorView, selection: EditorSelection, target: Prop[], pa
|
|
|
28
35
|
});
|
|
29
36
|
}
|
|
30
37
|
}
|
|
38
|
+
|
|
31
39
|
view.dispatch({
|
|
32
40
|
selection,
|
|
33
41
|
annotations: reconcileAnnotationType.of({}),
|
|
@@ -2,14 +2,16 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
// TODO(burdon): Additional copyright?
|
|
6
|
+
|
|
5
7
|
import { type EditorState, type Text, type Transaction } from '@codemirror/state';
|
|
6
8
|
|
|
7
9
|
import { next as am, type Heads } from '@dxos/automerge/automerge';
|
|
8
10
|
|
|
9
|
-
import { type IDocHandle } from '
|
|
10
|
-
import { type Field } from '
|
|
11
|
+
import { type IDocHandle } from '../handle';
|
|
12
|
+
import { type Field } from '../plugin';
|
|
11
13
|
|
|
12
|
-
export
|
|
14
|
+
export const codemirrorToAutomerge = (
|
|
13
15
|
field: Field,
|
|
14
16
|
handle: IDocHandle,
|
|
15
17
|
transactions: Transaction[],
|
|
@@ -18,7 +20,7 @@ export default (
|
|
|
18
20
|
const { lastHeads, path } = state.field(field);
|
|
19
21
|
|
|
20
22
|
// We don't want to call `automerge.updateAt` if there are no changes.
|
|
21
|
-
// Otherwise later on `automerge.diff` will return empty patches that result in a no-op but still mess up the selection.
|
|
23
|
+
// Otherwise, later on `automerge.diff` will return empty patches that result in a no-op but still mess up the selection.
|
|
22
24
|
let hasChanges = false;
|
|
23
25
|
for (const tr of transactions) {
|
|
24
26
|
tr.changes.iterChanges(() => {
|
|
@@ -37,5 +39,6 @@ export default (
|
|
|
37
39
|
});
|
|
38
40
|
}
|
|
39
41
|
});
|
|
42
|
+
|
|
40
43
|
return newHeads ?? undefined;
|
|
41
44
|
};
|
|
@@ -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"}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { type EditorSelection } from '@codemirror/state';
|
|
2
|
-
import { type EditorView } from '@codemirror/view';
|
|
3
|
-
import { type Patch, type Prop } from '@dxos/automerge/automerge';
|
|
4
|
-
declare const _default: (view: EditorView, selection: EditorSelection, target: Prop[], patches: Patch[]) => void;
|
|
5
|
-
export default _default;
|
|
6
|
-
//# sourceMappingURL=amToCodemirror.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"amToCodemirror.d.ts","sourceRoot":"","sources":["../../../../../src/hooks/automerge/amToCodemirror.ts"],"names":[],"mappings":"AAIA,OAAO,EAA8B,KAAK,eAAe,EAAoB,MAAM,mBAAmB,CAAC;AACvG,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD,OAAO,EAGL,KAAK,KAAK,EACV,KAAK,IAAI,EAGV,MAAM,2BAA2B,CAAC;+BAIb,UAAU,aAAa,eAAe,UAAU,IAAI,EAAE,WAAW,KAAK,EAAE;AAA9F,wBAgBE"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { type EditorState, type Transaction } from '@codemirror/state';
|
|
2
|
-
import { type Heads } from '@dxos/automerge/automerge';
|
|
3
|
-
import { type IDocHandle } from './handle';
|
|
4
|
-
import { type Field } from './plugin';
|
|
5
|
-
declare const _default: (field: Field, handle: IDocHandle, transactions: Transaction[], state: EditorState) => Heads | undefined;
|
|
6
|
-
export default _default;
|
|
7
|
-
//# sourceMappingURL=codeMirrorToAm.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"codeMirrorToAm.d.ts","sourceRoot":"","sources":["../../../../../src/hooks/automerge/codeMirrorToAm.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,WAAW,EAAa,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAElF,OAAO,EAAc,KAAK,KAAK,EAAE,MAAM,2BAA2B,CAAC;AAEnE,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,UAAU,CAAC;+CAI5B,UAAU,gBACJ,WAAW,EAAE,SACpB,WAAW,KACjB,KAAK,GAAG,SAAS;AALpB,wBA6BE"}
|