@dxos/react-ui-editor 0.3.10-main.5e11230 → 0.3.10-main.688c6da

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 (49) hide show
  1. package/dist/lib/browser/index.mjs +347 -172
  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 +1 -0
  21. package/dist/types/src/components/TextEditor/extensions/markdown/bundle.d.ts.map +1 -1
  22. package/dist/types/src/components/TextEditor/themes/default.d.ts.map +1 -1
  23. package/dist/types/src/hooks/automerge/automerge.stories.d.ts.map +1 -1
  24. package/dist/types/src/hooks/useTextModel.d.ts +6 -0
  25. package/dist/types/src/hooks/useTextModel.d.ts.map +1 -1
  26. package/dist/types/src/hooks/yjs/yjs.stories.d.ts +1 -1
  27. package/dist/types/src/hooks/yjs/yjs.stories.d.ts.map +1 -1
  28. package/dist/types/src/styles/markdown.d.ts.map +1 -1
  29. package/dist/types/src/testing/replicator.d.ts.map +1 -1
  30. package/package.json +22 -20
  31. package/src/components/TextEditor/MarkdownEditor.stories.tsx +41 -24
  32. package/src/components/TextEditor/TextEditor.stories.tsx +12 -1
  33. package/src/components/TextEditor/TextEditor.tsx +17 -1
  34. package/src/components/TextEditor/extensions/basic.ts +4 -3
  35. package/src/components/TextEditor/extensions/blast.ts +14 -28
  36. package/src/components/TextEditor/extensions/code.ts +99 -0
  37. package/src/components/TextEditor/extensions/comments.ts +9 -8
  38. package/src/components/TextEditor/extensions/experimental.tsx +1 -1
  39. package/src/components/TextEditor/extensions/highlight.ts +128 -0
  40. package/src/components/TextEditor/extensions/index.ts +2 -0
  41. package/src/components/TextEditor/extensions/markdown/bundle.ts +11 -1
  42. package/src/components/TextEditor/extensions/table.ts +2 -5
  43. package/src/components/TextEditor/extensions/tasklist.ts +1 -1
  44. package/src/components/TextEditor/themes/default.ts +7 -2
  45. package/src/hooks/automerge/automerge.stories.tsx +1 -0
  46. package/src/hooks/useTextModel.ts +9 -0
  47. package/src/hooks/yjs/yjs.stories.tsx +1 -1
  48. package/src/styles/markdown.ts +5 -4
  49. package/src/testing/replicator.ts +1 -0
@@ -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;
@@ -37,6 +37,7 @@ export const defaultTheme: {
37
37
  },
38
38
  '& .cm-scroller': {
39
39
  overflow: 'visible',
40
+ fontFamily: get(tokens, 'fontFamily.mono', []).join(','),
40
41
  },
41
42
  '& .cm-content': {
42
43
  padding: 0,
@@ -55,10 +56,10 @@ export const defaultTheme: {
55
56
  //
56
57
  // Cursor
57
58
  //
58
- '&light .cm-cursor': {
59
+ '&light .cm-cursor, &light .cm-dropCursor': {
59
60
  borderLeft: '2px solid black',
60
61
  },
61
- '&dark .cm-cursor': {
62
+ '&dark .cm-cursor, &dark .cm-dropCursor': {
62
63
  borderLeft: '2px solid white',
63
64
  },
64
65
  '& .cm-placeholder': {
@@ -173,6 +174,10 @@ export const defaultTheme: {
173
174
  //
174
175
  // table
175
176
  //
177
+ '& .cm-table *': {
178
+ fontFamily: `${get(tokens, 'fontFamily.mono', []).join(',')} !important`,
179
+ textDecoration: 'none !important',
180
+ },
176
181
  '& .cm-table-head': {
177
182
  padding: '2px 16px 2px 0px',
178
183
  borderBottom: `1px solid ${get(tokens, 'extend.colors.neutral.500')}`,
@@ -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
  };