@dxos/react-ui-editor 0.3.10-main.cb1d9e2 → 0.3.10-main.cbe7692

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/dist/lib/browser/index.mjs +704 -135
  2. package/dist/lib/browser/index.mjs.map +4 -4
  3. package/dist/lib/browser/meta.json +1 -1
  4. package/dist/types/src/components/TextEditor/MarkdownEditor.stories.d.ts +19 -1
  5. package/dist/types/src/components/TextEditor/MarkdownEditor.stories.d.ts.map +1 -1
  6. package/dist/types/src/components/TextEditor/TextEditor.d.ts +2 -1
  7. package/dist/types/src/components/TextEditor/TextEditor.d.ts.map +1 -1
  8. package/dist/types/src/components/TextEditor/extensions/autocomplete.d.ts.map +1 -1
  9. package/dist/types/src/components/TextEditor/extensions/basic.d.ts +2 -1
  10. package/dist/types/src/components/TextEditor/extensions/basic.d.ts.map +1 -1
  11. package/dist/types/src/components/TextEditor/extensions/blast.d.ts +25 -0
  12. package/dist/types/src/components/TextEditor/extensions/blast.d.ts.map +1 -0
  13. package/dist/types/src/components/TextEditor/extensions/demo.d.ts +2 -1
  14. package/dist/types/src/components/TextEditor/extensions/demo.d.ts.map +1 -1
  15. package/dist/types/src/components/TextEditor/extensions/image.d.ts +4 -0
  16. package/dist/types/src/components/TextEditor/extensions/image.d.ts.map +1 -0
  17. package/dist/types/src/components/TextEditor/extensions/index.d.ts +4 -0
  18. package/dist/types/src/components/TextEditor/extensions/index.d.ts.map +1 -1
  19. package/dist/types/src/components/TextEditor/extensions/link.d.ts.map +1 -1
  20. package/dist/types/src/components/TextEditor/extensions/listener.d.ts.map +1 -1
  21. package/dist/types/src/components/TextEditor/extensions/markdown/bundle.d.ts +2 -1
  22. package/dist/types/src/components/TextEditor/extensions/markdown/bundle.d.ts.map +1 -1
  23. package/dist/types/src/components/TextEditor/extensions/markdown/highlight.d.ts +6 -2
  24. package/dist/types/src/components/TextEditor/extensions/markdown/highlight.d.ts.map +1 -1
  25. package/dist/types/src/components/TextEditor/extensions/mention.d.ts +6 -0
  26. package/dist/types/src/components/TextEditor/extensions/mention.d.ts.map +1 -0
  27. package/dist/types/src/components/TextEditor/extensions/table.d.ts +8 -0
  28. package/dist/types/src/components/TextEditor/extensions/table.d.ts.map +1 -0
  29. package/dist/types/src/components/TextEditor/extensions/tasklist.d.ts +2 -1
  30. package/dist/types/src/components/TextEditor/extensions/tasklist.d.ts.map +1 -1
  31. package/dist/types/src/components/TextEditor/themes/default.d.ts +5 -0
  32. package/dist/types/src/components/TextEditor/themes/default.d.ts.map +1 -1
  33. package/dist/types/src/hooks/automerge/PatchSemaphore.d.ts +3 -0
  34. package/dist/types/src/hooks/automerge/PatchSemaphore.d.ts.map +1 -1
  35. package/dist/types/src/hooks/automerge/automerge.stories.d.ts +8 -1
  36. package/dist/types/src/hooks/automerge/automerge.stories.d.ts.map +1 -1
  37. package/dist/types/src/hooks/automerge/index.d.ts +1 -1
  38. package/dist/types/src/hooks/automerge/index.d.ts.map +1 -1
  39. package/dist/types/src/hooks/automerge/plugin.d.ts.map +1 -1
  40. package/dist/types/src/hooks/automerge/translation/automerge-to-codemirror.d.ts +5 -0
  41. package/dist/types/src/hooks/automerge/translation/automerge-to-codemirror.d.ts.map +1 -0
  42. package/dist/types/src/hooks/automerge/translation/codemirror-to-automerge.d.ts +6 -0
  43. package/dist/types/src/hooks/automerge/translation/codemirror-to-automerge.d.ts.map +1 -0
  44. package/dist/types/src/hooks/automerge/translation/index.d.ts +3 -0
  45. package/dist/types/src/hooks/automerge/translation/index.d.ts.map +1 -0
  46. package/dist/types/src/{components/TextEditor → hooks/yjs}/yjs.stories.d.ts +1 -1
  47. package/dist/types/src/hooks/yjs/yjs.stories.d.ts.map +1 -0
  48. package/dist/types/src/styles/markdown.d.ts +3 -2
  49. package/dist/types/src/styles/markdown.d.ts.map +1 -1
  50. package/package.json +20 -20
  51. package/src/components/TextEditor/MarkdownEditor.stories.tsx +98 -25
  52. package/src/components/TextEditor/TextEditor.tsx +16 -7
  53. package/src/components/TextEditor/extensions/autocomplete.ts +5 -20
  54. package/src/components/TextEditor/extensions/basic.ts +2 -1
  55. package/src/components/TextEditor/extensions/blast.ts +375 -0
  56. package/src/components/TextEditor/extensions/demo.ts +4 -1
  57. package/src/components/TextEditor/extensions/image.ts +68 -0
  58. package/src/components/TextEditor/extensions/index.ts +4 -0
  59. package/src/components/TextEditor/extensions/link.ts +15 -23
  60. package/src/components/TextEditor/extensions/listener.ts +3 -3
  61. package/src/components/TextEditor/extensions/markdown/bundle.ts +19 -11
  62. package/src/components/TextEditor/extensions/markdown/highlight.ts +118 -104
  63. package/src/components/TextEditor/extensions/mention.ts +31 -0
  64. package/src/components/TextEditor/extensions/table.ts +123 -0
  65. package/src/components/TextEditor/extensions/tasklist.ts +34 -20
  66. package/src/components/TextEditor/themes/default.ts +54 -2
  67. package/src/hooks/automerge/PatchSemaphore.ts +12 -9
  68. package/src/hooks/automerge/automerge.stories.tsx +3 -2
  69. package/src/hooks/automerge/index.ts +1 -1
  70. package/src/hooks/automerge/plugin.ts +1 -0
  71. package/src/hooks/automerge/{amToCodemirror.ts → translation/automerge-to-codemirror.ts} +10 -2
  72. package/src/hooks/automerge/{codeMirrorToAm.ts → translation/codemirror-to-automerge.ts} +7 -4
  73. package/src/hooks/automerge/translation/index.ts +6 -0
  74. package/src/{components/TextEditor → hooks/yjs}/yjs.stories.tsx +1 -1
  75. package/src/styles/markdown.ts +14 -8
  76. package/dist/types/src/components/TextEditor/yjs.stories.d.ts.map +0 -1
  77. package/dist/types/src/hooks/automerge/amToCodemirror.d.ts +0 -6
  78. package/dist/types/src/hooks/automerge/amToCodemirror.d.ts.map +0 -1
  79. package/dist/types/src/hooks/automerge/codeMirrorToAm.d.ts +0 -7
  80. package/dist/types/src/hooks/automerge/codeMirrorToAm.d.ts.map +0 -1
@@ -8,6 +8,8 @@ import { tags, styleTags, Tag } from '@lezer/highlight';
8
8
  import { type MarkdownConfig } from '@lezer/markdown';
9
9
  import get from 'lodash.get';
10
10
 
11
+ import { mx } from '@dxos/react-ui-theme';
12
+
11
13
  import {
12
14
  blockquote,
13
15
  bold,
@@ -22,6 +24,11 @@ import {
22
24
  tokens,
23
25
  } from '../../../../styles';
24
26
 
27
+ // TODO(burdon): Style table in monospace.
28
+ // https://discuss.codemirror.net/t/markdown-table-highlighting/658
29
+
30
+ // TODO(burdon): Readonly: use remark rather than hiding markup chars (which cursor can still move into).
31
+
25
32
  /**
26
33
  * Custom tags defined and processed by the GFM lezer extension.
27
34
  * https://github.com/lezer-parser/markdown
@@ -50,118 +57,125 @@ export const markdownTagsExtension: MarkdownConfig = {
50
57
  * Styling based on `lezer` parser tags.
51
58
  * https://codemirror.net/examples/styling
52
59
  * https://github.com/lezer-parser/highlight
53
- * https://lezer.codemirror.net/docs/ref/#highlight (list of tags)
60
+ * https://lezer.codemirror.net/docs/ref/#highlight.tags (list of tags)
61
+ *
62
+ * Examples:
63
+ * - https://github.com/codemirror/language/blob/main/src/highlight.ts#L194
64
+ * - https://github.com/codemirror/theme-one-dark/blob/main/src/one-dark.ts#L115
54
65
  */
55
- export const markdownHighlightStyle = HighlightStyle.define(
56
- [
57
- {
58
- tag: [
59
- tags.keyword,
60
- tags.name,
61
- tags.deleted,
62
- tags.character,
63
- tags.propertyName,
64
- tags.macroName,
65
- tags.color,
66
- tags.constant(tags.name),
67
- tags.standard(tags.name),
68
- tags.definition(tags.name),
69
- tags.separator,
70
- tags.typeName,
71
- tags.className,
72
- tags.number,
73
- tags.changed,
74
- tags.annotation,
75
- tags.modifier,
76
- tags.self,
77
- tags.namespace,
78
- tags.operator,
79
- tags.operatorKeyword,
80
- tags.escape,
81
- tags.regexp,
82
- tags.special(tags.string),
83
- tags.meta,
84
- tags.comment,
85
- tags.atom,
86
- tags.bool,
87
- tags.special(tags.variableName),
88
- tags.processingInstruction,
89
- tags.string,
90
- tags.inserted,
91
- tags.invalid,
92
- ],
93
- color: 'inherit !important',
94
- },
66
+ export const markdownHighlightStyle = (readonly?: boolean) =>
67
+ HighlightStyle.define(
68
+ [
69
+ {
70
+ tag: [
71
+ tags.keyword,
72
+ tags.name,
73
+ tags.deleted,
74
+ tags.character,
75
+ tags.propertyName,
76
+ tags.macroName,
77
+ tags.color,
78
+ tags.constant(tags.name),
79
+ tags.standard(tags.name),
80
+ tags.definition(tags.name),
81
+ tags.separator,
82
+ tags.typeName,
83
+ tags.className,
84
+ tags.number,
85
+ tags.changed,
86
+ tags.annotation,
87
+ tags.modifier,
88
+ tags.self,
89
+ tags.namespace,
90
+ tags.operator,
91
+ tags.operatorKeyword,
92
+ tags.escape,
93
+ tags.regexp,
94
+ tags.special(tags.string),
95
+ tags.meta,
96
+ tags.comment,
97
+ tags.atom,
98
+ tags.bool,
99
+ tags.special(tags.variableName),
100
+ tags.processingInstruction,
101
+ tags.string,
102
+ tags.inserted,
103
+ tags.invalid,
104
+ ],
105
+ color: 'inherit !important',
106
+ },
95
107
 
96
- // Markdown marks.
97
- {
98
- tag: [
99
- tags.meta,
100
- tags.processingInstruction,
101
- markdownTags.CodeMark,
102
- markdownTags.EmphasisMark,
103
- markdownTags.HeaderMark,
104
- markdownTags.LinkLabel,
105
- markdownTags.LinkReference,
106
- markdownTags.ListMark,
107
- markdownTags.QuoteMark,
108
- ],
109
- class: mark,
110
- },
108
+ // Markdown marks.
109
+ {
110
+ tag: [
111
+ tags.meta,
112
+ tags.processingInstruction,
113
+ markdownTags.LinkLabel,
114
+ markdownTags.LinkReference,
115
+ markdownTags.ListMark,
116
+ ],
117
+ class: mark,
118
+ },
111
119
 
112
- // Headings.
113
- { tag: tags.heading1, class: heading[1] },
114
- { tag: tags.heading2, class: heading[2] },
115
- { tag: tags.heading3, class: heading[3] },
116
- { tag: tags.heading4, class: heading[4] },
117
- { tag: tags.heading5, class: heading[5] },
118
- { tag: tags.heading6, class: heading[6] },
120
+ // Markdown marks.
121
+ {
122
+ tag: [markdownTags.CodeMark, markdownTags.HeaderMark, markdownTags.QuoteMark, markdownTags.EmphasisMark],
123
+ class: readonly ? 'hidden' : mark,
124
+ },
119
125
 
120
- // Emphasis.
121
- { tag: tags.emphasis, class: italic },
122
- { tag: tags.strong, class: bold },
123
- { tag: tags.strikethrough, class: strikethrough },
126
+ // E.g., code block language (after ```).
127
+ {
128
+ tag: [tags.function(tags.variableName), tags.labelName],
129
+ class: readonly ? 'hidden' : codeMark,
130
+ },
124
131
 
125
- // Naked URLs.
126
- {
127
- tag: [markdownTags.URL],
128
- class: inlineUrl,
129
- },
132
+ // Headings.
133
+ { tag: tags.heading1, class: heading(1, readonly) },
134
+ { tag: tags.heading2, class: heading(2, readonly) },
135
+ { tag: tags.heading3, class: heading(3, readonly) },
136
+ { tag: tags.heading4, class: heading(4, readonly) },
137
+ { tag: tags.heading5, class: heading(5, readonly) },
138
+ { tag: tags.heading6, class: heading(6, readonly) },
130
139
 
131
- // E.g., code block language (after ```).
132
- {
133
- tag: [tags.function(tags.variableName), tags.labelName],
134
- class: codeMark,
135
- },
140
+ // Emphasis.
141
+ { tag: tags.emphasis, class: italic },
142
+ { tag: tags.strong, class: bold },
143
+ { tag: tags.strikethrough, class: strikethrough },
136
144
 
137
- // NOTE: The `markdown` extension configures extensions for `lezer` to parse markdown tokens (incl. below).
138
- // However, since `codeLanguages` is also defined, the `lezer` will not parse fenced code blocks,
139
- // when a language is specified. In this case, the syntax highlighting extensions will colorize
140
- // the code, but all other CSS properties will be inherited.
141
- // IMPORTANT: Therefore, the fenced code block will use the base editor font.
142
- {
143
- tag: [markdownTags.CodeText, markdownTags.InlineCode],
144
- class: code,
145
- },
145
+ // Naked URLs.
146
+ {
147
+ tag: [markdownTags.URL],
148
+ class: inlineUrl,
149
+ },
146
150
 
147
- {
148
- tag: [markdownTags.QuoteMark],
149
- class: blockquote,
150
- },
151
+ // NOTE: The `markdown` extension configures extensions for `lezer` to parse markdown tokens (incl. below).
152
+ // However, since `codeLanguages` is also defined, the `lezer` will not parse fenced code blocks,
153
+ // when a language is specified. In this case, the syntax highlighting extensions will colorize
154
+ // the code, but all other CSS properties will be inherited.
155
+ // IMPORTANT: Therefore, the fenced code block will use the base editor font.
156
+ {
157
+ tag: [markdownTags.CodeText, markdownTags.InlineCode],
158
+ class: code,
159
+ },
160
+
161
+ {
162
+ tag: [markdownTags.QuoteMark],
163
+ class: blockquote,
164
+ },
151
165
 
166
+ {
167
+ tag: [markdownTags.HorizontalRule],
168
+ class: mx(horizontalRule, readonly && '-indent-[100rem]'),
169
+ },
170
+
171
+ // Main content, paragraphs, etc.
172
+ // {
173
+ // tag: [tags.content],
174
+ // fontFamily: get(tokens, 'fontFamily.body', []).join(','),
175
+ // },
176
+ ],
152
177
  {
153
- tag: [markdownTags.HorizontalRule],
154
- class: horizontalRule,
178
+ scope: markdownLanguage,
179
+ all: { fontFamily: get(tokens, 'fontFamily.body', []).join(',') },
155
180
  },
156
-
157
- // Main content, paragraphs, etc.
158
- // {
159
- // tag: [tags.content],
160
- // fontFamily: get(tokens, 'fontFamily.body', []).join(','),
161
- // },
162
- ],
163
- {
164
- scope: markdownLanguage,
165
- all: { fontFamily: get(tokens, 'fontFamily.body', []).join(',') },
166
- },
167
- );
181
+ );
@@ -0,0 +1,31 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ import { autocompletion, type CompletionContext, type CompletionResult } from '@codemirror/autocomplete';
6
+ import type { Extension } from '@codemirror/state';
7
+
8
+ export type MentionOptions = {
9
+ onSearch: (text: string) => string[];
10
+ };
11
+
12
+ export const mention = ({ onSearch }: MentionOptions): Extension => {
13
+ return autocompletion({
14
+ closeOnBlur: false, // For debugging.
15
+ override: [
16
+ (context: CompletionContext): CompletionResult | null => {
17
+ const match = context.matchBefore(/@(\w+)?/);
18
+ if (!match || (match.from === match.to && !context.explicit)) {
19
+ return null;
20
+ }
21
+
22
+ console.log(match);
23
+
24
+ return {
25
+ from: match.from,
26
+ options: onSearch(match.text.slice(1).toLowerCase()).map((value) => ({ label: `@${value}` })),
27
+ };
28
+ },
29
+ ],
30
+ });
31
+ };
@@ -0,0 +1,123 @@
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
+ if (state.readOnly) {
36
+ const tables: Table[] = [];
37
+ const getTable = () => tables[tables.length - 1];
38
+ const getRow = () => {
39
+ const table = getTable();
40
+ return table.rows?.[table.rows.length - 1];
41
+ };
42
+
43
+ // Parse table.
44
+ // TODO(burdon): Use remark?: https://www.npmjs.com/package/remark-gfm
45
+ syntaxTree(state).iterate({
46
+ enter: (node) => {
47
+ // console.log(node.name);
48
+ // Check if cursor is inside text.
49
+ switch (node.name) {
50
+ case 'Table': {
51
+ tables.push({ from: node.from });
52
+ break;
53
+ }
54
+ case 'TableHeader': {
55
+ getTable().header = [];
56
+ break;
57
+ }
58
+ case 'TableRow': {
59
+ (getTable().rows ??= []).push([]);
60
+ break;
61
+ }
62
+ case 'TableCell': {
63
+ const row = getRow();
64
+ if (row) {
65
+ row.push(state.sliceDoc(node.from, node.to));
66
+ } else {
67
+ getTable().header?.push(state.sliceDoc(node.from, node.to));
68
+ }
69
+ break;
70
+ }
71
+ case 'TableDelimiter': {
72
+ getTable().to = node.to;
73
+ break;
74
+ }
75
+ }
76
+ },
77
+ });
78
+
79
+ tables.forEach((table) =>
80
+ builder.add(table.from, table.to!, Decoration.replace({ widget: new TableWidget(table) })),
81
+ );
82
+ }
83
+
84
+ return builder.finish();
85
+ };
86
+
87
+ class TableWidget extends WidgetType {
88
+ constructor(readonly _table: Table) {
89
+ super();
90
+ }
91
+
92
+ override eq(other: WidgetType) {
93
+ return this._table.from === (other as any as TableWidget)?._table?.from;
94
+ }
95
+
96
+ toDOM(view: EditorView) {
97
+ const table = document.createElement('table');
98
+
99
+ {
100
+ const header = table.appendChild(document.createElement('thead'));
101
+ const row = header.appendChild(document.createElement('tr'));
102
+ this._table.header?.forEach((cell) => {
103
+ const th = document.createElement('th');
104
+ th.setAttribute('class', 'cm-table-head');
105
+ row.appendChild(th).textContent = cell;
106
+ });
107
+ }
108
+
109
+ {
110
+ const body = table.appendChild(document.createElement('tbody'));
111
+ this._table.rows?.forEach((row) => {
112
+ const tr = body.appendChild(document.createElement('tr'));
113
+ row.forEach((cell) => {
114
+ const td = document.createElement('td');
115
+ td.setAttribute('class', 'cm-table-cell');
116
+ tr.appendChild(td).textContent = cell;
117
+ });
118
+ });
119
+ }
120
+
121
+ return table;
122
+ }
123
+ }
@@ -17,7 +17,7 @@ class CheckboxWidget extends WidgetType {
17
17
  private readonly _pos: number,
18
18
  private _checked: boolean,
19
19
  private readonly _indent: number,
20
- private readonly _onCheck: (check: boolean) => void,
20
+ private readonly _onCheck?: (check: boolean) => void,
21
21
  ) {
22
22
  super();
23
23
  }
@@ -35,10 +35,15 @@ class CheckboxWidget extends WidgetType {
35
35
  const input = wrap.appendChild(document.createElement('input'));
36
36
  input.type = 'checkbox';
37
37
  input.checked = this._checked;
38
- input.onchange = (event: Event) => {
39
- this._onCheck((event.target as any).checked);
40
- return true;
41
- };
38
+ if (!this._onCheck) {
39
+ input.setAttribute('disabled', 'true');
40
+ }
41
+ if (this._onCheck) {
42
+ input.onchange = (event: Event) => {
43
+ this._onCheck?.((event.target as any).checked);
44
+ return true;
45
+ };
46
+ }
42
47
 
43
48
  return wrap;
44
49
  }
@@ -56,7 +61,9 @@ const styles = EditorView.baseTheme({
56
61
  },
57
62
  });
58
63
 
59
- export const tasklist = () => {
64
+ export type TasklistOptions = {};
65
+
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(pos, checked, indent, (checked) => {
69
- const idx = pos + match[0].indexOf('[') + 1;
70
- view.dispatch({
71
- changes: {
72
- from: idx,
73
- to: idx + 1,
74
- insert: checked ? 'x' : ' ',
75
- },
76
- // TODO(burdon): Restore cursor position? More useful to move to end of line (can indent).
77
- selection: {
78
- anchor: idx + 3,
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
- // '& .cm-tooltip-below': {},
140
- // '& .cm-tooltip-autocomplete': {},
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
- // now apply the unreconciled transactions to the document
54
- let newHeads = codeMirrorToAm(this._field, handle, transactions, view.state);
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
- // now get the diff between the updated state of the document and the heads
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
- amToCodemirror(view, selection, path, diff);
68
+ automergeToCodemirror(view, selection, path, diff);
66
69
 
67
70
  view.dispatch({
68
71
  effects: updateHeads(newHeads),
@@ -82,9 +82,10 @@ const Story = () => {
82
82
  };
83
83
 
84
84
  export default {
85
- title: 'Automerge',
85
+ title: 'react-ui-editor/Automerge',
86
+ component: Editor,
86
87
  };
87
88
 
88
- export const AutomergeRepo = {
89
+ export const Default = {
89
90
  render: () => <Story />,
90
91
  };
@@ -2,5 +2,5 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- export { automergePlugin, type AutomergePlugin } from './plugin';
6
5
  export { type IDocHandle } from './handle';
6
+ export { automergePlugin, type AutomergePlugin } from './plugin';
@@ -78,6 +78,7 @@ export const automergePlugin = (handle: IDocHandle, path: Prop[]): AutomergePlug
78
78
  return result;
79
79
  },
80
80
  });
81
+
81
82
  const semaphore = new PatchSemaphore(stateField);
82
83
 
83
84
  const viewPlugin = ViewPlugin.fromClass(