@dxos/react-ui-editor 0.3.10-main.92d1f2c → 0.3.10-main.9bbf73f

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 (51) hide show
  1. package/dist/lib/browser/index.mjs +381 -174
  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 +6 -3
  5. package/dist/types/src/components/TextEditor/MarkdownEditor.stories.d.ts.map +1 -1
  6. package/dist/types/src/components/TextEditor/TextEditor.d.ts.map +1 -1
  7. package/dist/types/src/components/TextEditor/TextEditor.stories.d.ts +3 -0
  8. package/dist/types/src/components/TextEditor/TextEditor.stories.d.ts.map +1 -1
  9. package/dist/types/src/components/TextEditor/extensions/basic.d.ts.map +1 -1
  10. package/dist/types/src/components/TextEditor/extensions/blast.d.ts +1 -1
  11. package/dist/types/src/components/TextEditor/extensions/blast.d.ts.map +1 -1
  12. package/dist/types/src/components/TextEditor/extensions/code.d.ts +2 -0
  13. package/dist/types/src/components/TextEditor/extensions/code.d.ts.map +1 -0
  14. package/dist/types/src/components/TextEditor/extensions/comments.d.ts +1 -1
  15. package/dist/types/src/components/TextEditor/extensions/comments.d.ts.map +1 -1
  16. package/dist/types/src/components/TextEditor/extensions/highlight.d.ts +24 -0
  17. package/dist/types/src/components/TextEditor/extensions/highlight.d.ts.map +1 -0
  18. package/dist/types/src/components/TextEditor/extensions/index.d.ts +2 -0
  19. package/dist/types/src/components/TextEditor/extensions/index.d.ts.map +1 -1
  20. package/dist/types/src/components/TextEditor/extensions/markdown/bundle.d.ts +8 -0
  21. package/dist/types/src/components/TextEditor/extensions/markdown/bundle.d.ts.map +1 -1
  22. package/dist/types/src/components/TextEditor/extensions/markdown/highlight.d.ts.map +1 -1
  23. package/dist/types/src/components/TextEditor/themes/default.d.ts.map +1 -1
  24. package/dist/types/src/hooks/automerge/automerge.stories.d.ts.map +1 -1
  25. package/dist/types/src/hooks/useTextModel.d.ts +6 -0
  26. package/dist/types/src/hooks/useTextModel.d.ts.map +1 -1
  27. package/dist/types/src/hooks/yjs/yjs.stories.d.ts +1 -1
  28. package/dist/types/src/hooks/yjs/yjs.stories.d.ts.map +1 -1
  29. package/dist/types/src/styles/markdown.d.ts.map +1 -1
  30. package/dist/types/src/testing/replicator.d.ts.map +1 -1
  31. package/package.json +22 -20
  32. package/src/components/TextEditor/MarkdownEditor.stories.tsx +41 -24
  33. package/src/components/TextEditor/TextEditor.stories.tsx +12 -1
  34. package/src/components/TextEditor/TextEditor.tsx +18 -1
  35. package/src/components/TextEditor/extensions/basic.ts +4 -3
  36. package/src/components/TextEditor/extensions/blast.ts +14 -28
  37. package/src/components/TextEditor/extensions/code.ts +99 -0
  38. package/src/components/TextEditor/extensions/comments.ts +9 -8
  39. package/src/components/TextEditor/extensions/experimental.tsx +1 -1
  40. package/src/components/TextEditor/extensions/highlight.ts +128 -0
  41. package/src/components/TextEditor/extensions/index.ts +2 -0
  42. package/src/components/TextEditor/extensions/markdown/bundle.ts +17 -17
  43. package/src/components/TextEditor/extensions/markdown/highlight.ts +1 -0
  44. package/src/components/TextEditor/extensions/table.ts +2 -5
  45. package/src/components/TextEditor/extensions/tasklist.ts +1 -1
  46. package/src/components/TextEditor/themes/default.ts +43 -2
  47. package/src/hooks/automerge/automerge.stories.tsx +1 -0
  48. package/src/hooks/useTextModel.ts +9 -0
  49. package/src/hooks/yjs/yjs.stories.tsx +1 -1
  50. package/src/styles/markdown.ts +5 -4
  51. package/src/testing/replicator.ts +1 -0
@@ -7,7 +7,7 @@ import { history, historyKeymap, indentWithTab, standardKeymap } from '@codemirr
7
7
  import { markdownLanguage, markdown } from '@codemirror/lang-markdown';
8
8
  import { bracketMatching, defaultHighlightStyle, indentOnInput, syntaxHighlighting } from '@codemirror/language';
9
9
  import { languages } from '@codemirror/language-data';
10
- import { highlightSelectionMatches, searchKeymap } from '@codemirror/search';
10
+ import { searchKeymap } from '@codemirror/search';
11
11
  import { EditorState, type Extension } from '@codemirror/state';
12
12
  import { oneDarkHighlightStyle } from '@codemirror/theme-one-dark';
13
13
  import {
@@ -16,11 +16,8 @@ import {
16
16
  dropCursor,
17
17
  EditorView,
18
18
  highlightActiveLine,
19
- highlightActiveLineGutter,
20
- highlightSpecialChars,
21
19
  keymap,
22
20
  placeholder,
23
- rectangularSelection,
24
21
  } from '@codemirror/view';
25
22
 
26
23
  import type { ThemeMode } from '@dxos/react-ui';
@@ -33,33 +30,36 @@ export type MarkdownBundleOptions = {
33
30
  placeholder?: string;
34
31
  };
35
32
 
33
+ /**
34
+ * Markdown bundle.
35
+ * Refs:
36
+ * https://github.com/codemirror/basic-setup
37
+ * https://github.com/codemirror/basic-setup/blob/main/src/codemirror.ts#L50
38
+ * https://codemirror.net/docs/community
39
+ * https://codemirror.net/docs/ref/#codemirror.basicSetup
40
+ */
41
+ // TODO(burdon): Add Composer here: https://codemirror.net/docs/community
36
42
  export const markdownBundle = ({
37
43
  readonly,
38
44
  themeMode,
39
45
  placeholder: _placeholder,
40
46
  }: MarkdownBundleOptions): Extension[] => {
41
- // All of https://github.com/codemirror/basic-setup minus line numbers and fold gutter.
42
- // https://codemirror.net/docs/ref/#codemirror.basicSetup
43
47
  return [
44
- bracketMatching(),
45
- closeBrackets(),
46
- _placeholder && placeholder(_placeholder),
47
-
48
48
  EditorState.allowMultipleSelections.of(true),
49
+ EditorState.tabSize.of(2),
49
50
  EditorView.lineWrapping,
50
51
 
52
+ customKeymap(),
53
+
54
+ bracketMatching(),
55
+ closeBrackets(),
51
56
  crosshairCursor(),
52
57
  dropCursor(),
53
58
  drawSelection(),
54
59
  highlightActiveLine(),
55
- highlightActiveLineGutter(),
56
- highlightSelectionMatches(),
57
- highlightSpecialChars(),
58
60
  history(),
59
61
  indentOnInput(),
60
- rectangularSelection(),
61
-
62
- customkeymap(),
62
+ _placeholder && placeholder(_placeholder),
63
63
 
64
64
  // Main extension.
65
65
  // https://github.com/codemirror/lang-markdown
@@ -91,7 +91,7 @@ export const markdownBundle = ({
91
91
  };
92
92
 
93
93
  // https://codemirror.net/docs/ref/#view.keymap
94
- const customkeymap = () =>
94
+ const customKeymap = () =>
95
95
  keymap.of([
96
96
  // https://codemirror.net/docs/ref/#commands.indentWithTab
97
97
  indentWithTab,
@@ -181,6 +181,7 @@ export const markdownHighlightStyle = (readonly?: boolean) => {
181
181
  class: blockquote,
182
182
  },
183
183
 
184
+ // TODO(burdon): Replace with extension.
184
185
  {
185
186
  tag: [markdownTags.HorizontalRule],
186
187
  class: mx(horizontalRule, readonly && '-indent-[100rem]'),
@@ -42,10 +42,6 @@ const update = (state: EditorState, options: TableOptions) => {
42
42
  };
43
43
 
44
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
45
  syntaxTree(state).iterate({
50
46
  enter: (node) => {
51
47
  // Check if cursor is inside text.
@@ -77,7 +73,8 @@ const update = (state: EditorState, options: TableOptions) => {
77
73
 
78
74
  tables.forEach((table) => {
79
75
  const hide = state.readOnly || cursor < table.from || cursor > table.to;
80
- hide && builder.add(table.from, table.to!, Decoration.replace({ widget: new TableWidget(table) }));
76
+ hide && builder.add(table.from, table.to, Decoration.replace({ widget: new TableWidget(table) }));
77
+ builder.add(table.from, table.to, Decoration.mark({ class: 'cm-table' }));
81
78
  });
82
79
 
83
80
  return builder.finish();
@@ -109,7 +109,7 @@ export const tasklist = (options: TasklistOptions = {}) => {
109
109
  }
110
110
  },
111
111
  {
112
- decorations: (instance) => instance.tasks,
112
+ decorations: (value) => value.tasks,
113
113
  provide: (plugin) =>
114
114
  EditorView.atomicRanges.of((view) => {
115
115
  return view.plugin(plugin)?.tasks || Decoration.none;
@@ -55,10 +55,10 @@ export const defaultTheme: {
55
55
  //
56
56
  // Cursor
57
57
  //
58
- '&light .cm-cursor': {
58
+ '&light .cm-cursor, &light .cm-dropCursor': {
59
59
  borderLeft: '2px solid black',
60
60
  },
61
- '&dark .cm-cursor': {
61
+ '&dark .cm-cursor, &dark .cm-dropCursor': {
62
62
  borderLeft: '2px solid white',
63
63
  },
64
64
  '& .cm-placeholder': {
@@ -173,6 +173,10 @@ export const defaultTheme: {
173
173
  //
174
174
  // table
175
175
  //
176
+ '& .cm-table *': {
177
+ fontFamily: `${get(tokens, 'fontFamily.mono', []).join(',')} !important`,
178
+ textDecoration: 'none !important',
179
+ },
176
180
  '& .cm-table-head': {
177
181
  padding: '2px 16px 2px 0px',
178
182
  borderBottom: `1px solid ${get(tokens, 'extend.colors.neutral.500')}`,
@@ -203,6 +207,43 @@ export const defaultTheme: {
203
207
  acc[`& .text-${fontSize} + .cm-widgetBuffer + .cm-ySelectionCaret`] = { height };
204
208
  return acc;
205
209
  }, {}),
210
+
211
+ /**
212
+ * Panels
213
+ * https://github.com/codemirror/search/blob/main/src/search.ts#L745
214
+ *
215
+ * Find/replace panel.
216
+ * <div class="cm-announced">...</div>
217
+ * <div class="cm-scroller">...</div>
218
+ * <div class="cm-panels cm-panels-bottom">
219
+ * <div class="cm-search cm-panel">
220
+ * <input class="cm-textfield" />
221
+ * <button class="cm-button">...</button>
222
+ * <label><input type="checkbox" />...</label>
223
+ * </div>
224
+ * </div
225
+ */
226
+ '& .cm-panels': {
227
+ border: `1px solid ${get(tokens, 'extend.colors.neutral.200')}`,
228
+ borderBottom: 'none',
229
+ },
230
+ '& .cm-panel': {
231
+ background: get(tokens, 'extend.colors.neutral.50'),
232
+ fontFamily: get(tokens, 'fontFamily.body', []).join(','),
233
+ },
234
+ '& .cm-button': {
235
+ margin: '4px',
236
+ fontFamily: get(tokens, 'fontFamily.body', []).join(','),
237
+ background: get(tokens, 'extend.colors.neutral.100'),
238
+ border: 'none',
239
+ },
240
+
241
+ '& .cm-searchMatch': {
242
+ backgroundColor: get(tokens, 'extend.colors.yellow.100'),
243
+ },
244
+ '& .cm-searchMatch.cm-searchMatch-selected': {
245
+ backgroundColor: get(tokens, 'extend.colors.primary.100'),
246
+ },
206
247
  };
207
248
 
208
249
  export const textTheme: {
@@ -9,6 +9,7 @@ import { basicSetup } from 'codemirror';
9
9
  import get from 'lodash.get';
10
10
  import React, { useEffect, useRef, useState } from 'react';
11
11
 
12
+ // TODO(burdon): Why separate imports?
12
13
  import { type Prop } from '@dxos/automerge/automerge';
13
14
  import { type DocHandle, Repo } from '@dxos/automerge/automerge-repo';
14
15
 
@@ -26,12 +26,19 @@ import { SpaceAwarenessProvider } from './yjs';
26
26
  // TODO(burdon): Move.
27
27
  type Awareness = awarenessProtocol.Awareness;
28
28
 
29
+ export type DocumentRange = {
30
+ id: string;
31
+ from: number;
32
+ to: number;
33
+ };
34
+
29
35
  // TODO(wittjosiah): Factor out to common package? @dxos/react-client?
30
36
  export type EditorModel = {
31
37
  id: string;
32
38
  // TODO(burdon): Remove.
33
39
  content: string | YText | YXmlFragment | DocAccessor;
34
40
  text: () => string;
41
+ ranges: DocumentRange[];
35
42
  extension?: Extension;
36
43
  awareness?: Awareness;
37
44
  peer?: {
@@ -80,6 +87,7 @@ const createYjsModel = ({ identity, space, text }: UseTextModelOptions): EditorM
80
87
  id: text.doc.guid,
81
88
  content: text.content,
82
89
  text: () => text.content!.toString(),
90
+ ranges: [],
83
91
  extension: yCollab(text.content as YText, provider?.awareness),
84
92
  awareness: provider?.awareness,
85
93
  peer: identity
@@ -99,6 +107,7 @@ const createAutomergeModel = ({ identity, text }: UseTextModelOptions): EditorMo
99
107
  id: obj.id,
100
108
  content: doc,
101
109
  text: () => get(doc.handle.docSync(), doc.path),
110
+ ranges: [],
102
111
  extension: automergePlugin(doc.handle, doc.path),
103
112
  peer: identity
104
113
  ? {
@@ -16,6 +16,7 @@ import { MarkdownEditor } from '../../components';
16
16
  import { Replicator, useYjsModel } from '../../testing';
17
17
 
18
18
  export default {
19
+ title: 'react-ui-editor/YJS',
19
20
  component: MarkdownEditor,
20
21
  decorators: [withTheme],
21
22
  };
@@ -50,7 +51,6 @@ const Story = () => {
50
51
  };
51
52
 
52
53
  export const Default = {
53
- title: 'react-ui-editor/YJS',
54
54
  // TODO(wittjosiah): Decorator for doing this without clients being initialized?
55
55
  render: () => <ClientRepeater count={2} Component={Story} />,
56
56
  };
@@ -6,12 +6,13 @@ import { mx } from '@dxos/react-ui-theme';
6
6
 
7
7
  export type HeadingLevel = 1 | 2 | 3 | 4 | 5 | 6;
8
8
 
9
+ // TODO(burdon): Better way to align vertically than negative margin? Font-specific?
9
10
  // https://tailwindcss.com/docs/font-weight
10
11
  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]'],
12
+ 1: ['mbs-4 mbe-2 font-medium text-inherit no-underline text-4xl', '-ml-[10px]'],
13
+ 2: ['mbs-4 mbe-2 font-medium text-inherit no-underline text-3xl', '-ml-[8px]'],
14
+ 3: ['mbs-4 mbe-2 font-medium text-inherit no-underline text-2xl', '-ml-[7px]'],
15
+ 4: ['mbs-4 mbe-2 font-medium text-inherit no-underline text-xl', '-ml-[6px]'],
15
16
  5: ['mbs-4 mbe-2 font-medium text-inherit no-underline text-lg', '-ml-[5px]'],
16
17
  6: ['mbs-4 mbe-2 font-medium text-inherit no-underline', '-ml-[4px]'],
17
18
  };
@@ -169,6 +169,7 @@ export class Replicator {
169
169
  id: doc.guid,
170
170
  text: () => content.toString(),
171
171
  content,
172
+ ranges: [],
172
173
  awareness: provider.awareness,
173
174
  peer: { id },
174
175
  };