@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.
Files changed (65) hide show
  1. package/dist/lib/browser/index.mjs +897 -293
  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/comments.d.ts +1 -1
  14. package/dist/types/src/components/TextEditor/extensions/comments.d.ts.map +1 -1
  15. package/dist/types/src/components/TextEditor/extensions/demo.d.ts +2 -1
  16. package/dist/types/src/components/TextEditor/extensions/demo.d.ts.map +1 -1
  17. package/dist/types/src/components/TextEditor/extensions/experimental.d.ts +1 -1
  18. package/dist/types/src/components/TextEditor/extensions/experimental.d.ts.map +1 -1
  19. package/dist/types/src/components/TextEditor/extensions/image.d.ts +4 -0
  20. package/dist/types/src/components/TextEditor/extensions/image.d.ts.map +1 -0
  21. package/dist/types/src/components/TextEditor/extensions/index.d.ts +4 -0
  22. package/dist/types/src/components/TextEditor/extensions/index.d.ts.map +1 -1
  23. package/dist/types/src/components/TextEditor/extensions/link.d.ts.map +1 -1
  24. package/dist/types/src/components/TextEditor/extensions/listener.d.ts.map +1 -1
  25. package/dist/types/src/components/TextEditor/extensions/markdown/bundle.d.ts +2 -1
  26. package/dist/types/src/components/TextEditor/extensions/markdown/bundle.d.ts.map +1 -1
  27. package/dist/types/src/components/TextEditor/extensions/markdown/highlight.d.ts +9 -3
  28. package/dist/types/src/components/TextEditor/extensions/markdown/highlight.d.ts.map +1 -1
  29. package/dist/types/src/components/TextEditor/extensions/mention.d.ts +6 -0
  30. package/dist/types/src/components/TextEditor/extensions/mention.d.ts.map +1 -0
  31. package/dist/types/src/components/TextEditor/extensions/table.d.ts +8 -0
  32. package/dist/types/src/components/TextEditor/extensions/table.d.ts.map +1 -0
  33. package/dist/types/src/components/TextEditor/extensions/tasklist.d.ts +2 -1
  34. package/dist/types/src/components/TextEditor/extensions/tasklist.d.ts.map +1 -1
  35. package/dist/types/src/components/TextEditor/themes/default.d.ts +5 -0
  36. package/dist/types/src/components/TextEditor/themes/default.d.ts.map +1 -1
  37. package/dist/types/src/hooks/automerge/automerge.stories.d.ts +8 -1
  38. package/dist/types/src/hooks/automerge/automerge.stories.d.ts.map +1 -1
  39. package/dist/types/src/{components/TextEditor → hooks/yjs}/yjs.stories.d.ts +1 -1
  40. package/dist/types/src/hooks/yjs/yjs.stories.d.ts.map +1 -0
  41. package/dist/types/src/styles/markdown.d.ts +3 -2
  42. package/dist/types/src/styles/markdown.d.ts.map +1 -1
  43. package/package.json +20 -20
  44. package/src/components/TextEditor/MarkdownEditor.stories.tsx +102 -27
  45. package/src/components/TextEditor/TextEditor.tsx +13 -23
  46. package/src/components/TextEditor/extensions/autocomplete.ts +5 -20
  47. package/src/components/TextEditor/extensions/basic.ts +2 -1
  48. package/src/components/TextEditor/extensions/blast.ts +387 -0
  49. package/src/components/TextEditor/extensions/comments.ts +21 -39
  50. package/src/components/TextEditor/extensions/demo.ts +4 -1
  51. package/src/components/TextEditor/extensions/experimental.tsx +14 -35
  52. package/src/components/TextEditor/extensions/image.ts +67 -0
  53. package/src/components/TextEditor/extensions/index.ts +4 -0
  54. package/src/components/TextEditor/extensions/link.ts +17 -25
  55. package/src/components/TextEditor/extensions/listener.ts +3 -3
  56. package/src/components/TextEditor/extensions/markdown/bundle.ts +30 -19
  57. package/src/components/TextEditor/extensions/markdown/highlight.ts +147 -108
  58. package/src/components/TextEditor/extensions/mention.ts +31 -0
  59. package/src/components/TextEditor/extensions/table.ts +122 -0
  60. package/src/components/TextEditor/extensions/tasklist.ts +41 -27
  61. package/src/components/TextEditor/themes/default.ts +54 -2
  62. package/src/hooks/automerge/automerge.stories.tsx +3 -2
  63. package/src/{components/TextEditor → hooks/yjs}/yjs.stories.tsx +1 -1
  64. package/src/styles/markdown.ts +14 -8
  65. 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: (check: boolean) => void,
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
- input.onchange = (event: Event) => {
39
- this._onCheck((event.target as any).checked);
40
- return true;
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
- // TODO(burdon): Reconcile with theme.
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(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
@@ -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
  };
@@ -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 './TextEditor';
15
+ import { MarkdownEditor } from '../../components';
16
16
  import { Replicator, useYjsModel } from '../../testing';
17
17
 
18
18
  export default {
@@ -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 heading: Record<HeadingLevel, string> = {
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 = 'flex mlb-4 border-b text-neutral-100 dark:text-neutral-900 border-neutral-500/50';
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"}