@dxos/react-ui-editor 0.3.11-main.008b7c6 → 0.3.11-main.00a28cb

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 (92) hide show
  1. package/dist/lib/browser/index.mjs +558 -629
  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 +12 -5
  5. package/dist/types/src/components/TextEditor/MarkdownEditor.stories.d.ts.map +1 -1
  6. package/dist/types/src/components/TextEditor/TextEditor.d.ts +12 -17
  7. package/dist/types/src/components/TextEditor/TextEditor.d.ts.map +1 -1
  8. package/dist/types/src/components/TextEditor/TextEditor.stories.d.ts +6 -6
  9. package/dist/types/src/components/TextEditor/TextEditor.stories.d.ts.map +1 -1
  10. package/dist/types/src/components/TextEditor/comments.stories.d.ts +26 -0
  11. package/dist/types/src/components/TextEditor/comments.stories.d.ts.map +1 -0
  12. package/dist/types/src/components/TextEditor/yjs.stories.d.ts +1 -1
  13. package/dist/types/src/extensions/autocomplete.d.ts.map +1 -1
  14. package/dist/types/src/extensions/automerge/automerge.d.ts.map +1 -1
  15. package/dist/types/src/extensions/automerge/cursor.d.ts +1 -1
  16. package/dist/types/src/extensions/automerge/cursor.d.ts.map +1 -1
  17. package/dist/types/src/extensions/automerge/defs.d.ts +4 -4
  18. package/dist/types/src/extensions/automerge/defs.d.ts.map +1 -1
  19. package/dist/types/src/extensions/automerge/semaphore.d.ts +4 -9
  20. package/dist/types/src/extensions/automerge/semaphore.d.ts.map +1 -1
  21. package/dist/types/src/extensions/code.d.ts.map +1 -1
  22. package/dist/types/src/extensions/comments.d.ts +14 -5
  23. package/dist/types/src/extensions/comments.d.ts.map +1 -1
  24. package/dist/types/src/{util → extensions}/cursor.d.ts +9 -1
  25. package/dist/types/src/extensions/cursor.d.ts.map +1 -0
  26. package/dist/types/src/extensions/hr.d.ts.map +1 -1
  27. package/dist/types/src/extensions/image.d.ts.map +1 -1
  28. package/dist/types/src/extensions/index.d.ts +2 -1
  29. package/dist/types/src/extensions/index.d.ts.map +1 -1
  30. package/dist/types/src/extensions/link.d.ts.map +1 -1
  31. package/dist/types/src/extensions/markdown/highlight.d.ts.map +1 -1
  32. package/dist/types/src/extensions/outliner.d.ts +4 -0
  33. package/dist/types/src/extensions/outliner.d.ts.map +1 -0
  34. package/dist/types/src/extensions/tasklist.d.ts +5 -1
  35. package/dist/types/src/extensions/tasklist.d.ts.map +1 -1
  36. package/dist/types/src/extensions/yjs/cursor.d.ts +1 -1
  37. package/dist/types/src/extensions/yjs/cursor.d.ts.map +1 -1
  38. package/dist/types/src/hooks/index.d.ts +1 -1
  39. package/dist/types/src/hooks/index.d.ts.map +1 -1
  40. package/dist/types/src/hooks/useTextModel.d.ts +0 -5
  41. package/dist/types/src/hooks/useTextModel.d.ts.map +1 -1
  42. package/dist/types/src/hooks/yjs.d.ts.map +1 -1
  43. package/dist/types/src/index.d.ts +3 -0
  44. package/dist/types/src/index.d.ts.map +1 -1
  45. package/dist/types/src/styles/markdown.d.ts.map +1 -1
  46. package/dist/types/src/styles/tokens.d.ts +1 -0
  47. package/dist/types/src/styles/tokens.d.ts.map +1 -1
  48. package/dist/types/src/themes/default.d.ts.map +1 -1
  49. package/dist/types/src/util.d.ts.map +1 -0
  50. package/package.json +25 -24
  51. package/src/components/TextEditor/MarkdownEditor.stories.tsx +41 -37
  52. package/src/components/TextEditor/TextEditor.stories.tsx +12 -46
  53. package/src/components/TextEditor/TextEditor.tsx +71 -67
  54. package/src/components/TextEditor/comments.stories.tsx +355 -0
  55. package/src/extensions/autocomplete.ts +18 -17
  56. package/src/extensions/automerge/automerge.ts +12 -14
  57. package/src/extensions/automerge/cursor.ts +2 -1
  58. package/src/extensions/automerge/defs.ts +13 -9
  59. package/src/extensions/automerge/semaphore.ts +10 -12
  60. package/src/extensions/awareness.ts +27 -33
  61. package/src/extensions/code.ts +28 -23
  62. package/src/extensions/comments.ts +131 -144
  63. package/src/extensions/cursor.ts +46 -0
  64. package/src/extensions/hr.ts +10 -12
  65. package/src/extensions/image.ts +40 -22
  66. package/src/extensions/index.ts +2 -1
  67. package/src/extensions/link.ts +86 -88
  68. package/src/extensions/markdown/highlight.ts +3 -12
  69. package/src/extensions/outliner.ts +12 -0
  70. package/src/extensions/table.ts +10 -4
  71. package/src/extensions/tasklist.ts +54 -79
  72. package/src/extensions/yjs/cursor.ts +2 -1
  73. package/src/extensions/yjs/yjs.test.ts +1 -1
  74. package/src/extensions/yjs/yjs.ts +2 -2
  75. package/src/hooks/index.ts +2 -1
  76. package/src/hooks/useTextModel.ts +4 -7
  77. package/src/hooks/yjs.ts +1 -23
  78. package/src/index.ts +3 -0
  79. package/src/styles/markdown.ts +0 -2
  80. package/src/styles/tokens.ts +3 -0
  81. package/src/themes/default.ts +51 -78
  82. package/dist/types/src/extensions/mermaid.d.ts +0 -3
  83. package/dist/types/src/extensions/mermaid.d.ts.map +0 -1
  84. package/dist/types/src/util/cursor.d.ts.map +0 -1
  85. package/dist/types/src/util/index.d.ts +0 -3
  86. package/dist/types/src/util/index.d.ts.map +0 -1
  87. package/dist/types/src/util/util.d.ts.map +0 -1
  88. package/src/extensions/mermaid.ts +0 -11
  89. package/src/util/cursor.ts +0 -29
  90. package/src/util/index.ts +0 -6
  91. /package/dist/types/src/{util/util.d.ts → util.d.ts} +0 -0
  92. /package/src/{util/util.ts → util.ts} +0 -0
@@ -39,10 +39,8 @@ export const codeBlock = 'mlb-2 font-mono bg-neutral-500/10 p-3 rounded';
39
39
 
40
40
  export const inlineUrl = mx(code, 'px-1');
41
41
 
42
- // TODO(burdon): Replace with widget.
43
42
  export const blockquote = mx('pl-1 mr-1 border-is-4 border-primary-500/70 dark:border-primary-500/30', light);
44
43
 
45
- // TODO(burdon): Replace with widget.
46
44
  export const horizontalRule =
47
45
  'flex mlb-4 border-b text-neutral-100 dark:text-neutral-900 border-neutral-200 dark:border-neutral-800';
48
46
 
@@ -2,6 +2,7 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
+ import get from 'lodash.get';
5
6
  import type { StyleSpec } from 'style-mod';
6
7
 
7
8
  import { tailwindConfig, type TailwindConfig } from '@dxos/react-ui-theme';
@@ -12,3 +13,5 @@ export type ThemeStyles = {
12
13
 
13
14
  // TODO(thure): Why export the whole theme? Can this be done differently?
14
15
  export const tokens: TailwindConfig['theme'] = tailwindConfig({}).theme;
16
+
17
+ export const getToken = (path: string, defaultValue: any = undefined) => get(tokens, path, defaultValue);
@@ -6,8 +6,8 @@ import get from 'lodash.get';
6
6
 
7
7
  import { type ThemeStyles, tokens } from '../styles';
8
8
 
9
- // TODO(burdon): Can we erase All of the default CM styles?
10
- // TODO(burdon): Theme styles seem to be added multiple times?
9
+ // TODO(burdon): Can we use @apply and import css file?
10
+ // https://tailwindcss.com/docs/reusing-styles#extracting-classes-with-apply?
11
11
 
12
12
  /**
13
13
  * Minimal styles.
@@ -49,12 +49,12 @@ export const defaultTheme: ThemeStyles = {
49
49
  '&.cm-focused': {
50
50
  outline: 'none',
51
51
  },
52
- '& .cm-scroller': {
52
+ '.cm-scroller': {
53
53
  overflow: 'visible',
54
54
  fontFamily: get(tokens, 'fontFamily.mono', []).join(','),
55
55
  },
56
56
 
57
- '& .cm-content': {
57
+ '.cm-content': {
58
58
  padding: 0,
59
59
  // NOTE: Base font size (otherwise defined by HTML tag, which might be different for storybook).
60
60
  fontSize: '16px',
@@ -77,17 +77,19 @@ export const defaultTheme: ThemeStyles = {
77
77
  '&dark .cm-cursor, &dark .cm-dropCursor': {
78
78
  borderLeft: '2px solid white',
79
79
  },
80
- '& .cm-placeholder': {
80
+ '.cm-placeholder': {
81
81
  fontWeight: 100,
82
82
  },
83
83
 
84
84
  //
85
85
  // line
86
86
  //
87
- '& .cm-line': {
87
+ '.cm-line': {
88
88
  paddingInline: 0,
89
+ // TODO(burdon): Other values leave gaps between lines when highlighted.
90
+ // lineHeight: 'normal',
89
91
  },
90
- '& .cm-activeLine': {
92
+ '.cm-activeLine': {
91
93
  background: 'inherit',
92
94
  },
93
95
 
@@ -119,40 +121,10 @@ export const defaultTheme: ThemeStyles = {
119
121
  backgroundColor: get(tokens, 'extend.colors.yellow.700'),
120
122
  },
121
123
 
122
- //
123
- // collaboration
124
- // TODO(burdon): Review classnames (YJS dependent?) Note: e2e tests depend on this class.
125
- //
126
-
127
- '&light .cm-ySelection, &light .cm-yLineSelection': {
128
- mixBlendMode: 'multiply',
129
- },
130
- '&dark .cm-ySelection, &dark .cm-yLineSelection': {
131
- mixBlendMode: 'screen',
132
- },
133
-
134
- '& .cm-ySelectionInfo': {
135
- padding: '2px 4px',
136
- marginBlockStart: '-4px',
137
- },
138
- '& .cm-ySelection, & .cm-selectionMatch': {
139
- paddingBlockStart: '.15em',
140
- paddingBlockEnd: '.15em',
141
- },
142
- '& .cm-ySelectionCaret': {
143
- display: 'inline-block',
144
- insetBlockStart: '.1em',
145
- blockSize: '1.4em',
146
- verticalAlign: 'top',
147
- },
148
- '& .cm-yLineSelection': {
149
- margin: 0,
150
- },
151
-
152
124
  //
153
125
  // link
154
126
  //
155
- '& .cm-link': {
127
+ '.cm-link': {
156
128
  color: get(tokens, 'extend.colors.primary.500'),
157
129
  textDecorationLine: 'underline',
158
130
  textDecorationThickness: '1px',
@@ -164,75 +136,74 @@ export const defaultTheme: ThemeStyles = {
164
136
  //
165
137
  // tooltip
166
138
  //
167
- '& .cm-tooltip': {
139
+ '.cm-tooltip': {
168
140
  border: 'none',
169
141
  },
170
- '& .cm-tooltip-below': {},
142
+ '.cm-tooltip-below': {},
171
143
 
172
144
  //
173
145
  // autocomplete
174
146
  //
175
- '& .cm-tooltip-autocomplete': {
147
+ '.cm-tooltip-autocomplete': {
176
148
  marginTop: '4px',
177
149
  marginLeft: '-3px',
178
150
  },
179
- '& .cm-tooltip-autocomplete ul li': {},
180
- '& .cm-tooltip-autocomplete ul li[aria-selected]': {},
181
- '& .cm-completionIcon': {
151
+ '.cm-tooltip-autocomplete ul li': {},
152
+ '.cm-tooltip-autocomplete ul li[aria-selected]': {},
153
+ '.cm-completionIcon': {
182
154
  display: 'none',
183
155
  },
184
- '& .cm-completionLabel': {
156
+ '.cm-completionLabel': {
185
157
  fontFamily: get(tokens, 'fontFamily.body', []).join(','),
186
158
  },
187
- '& .cm-completionMatchedText': {
159
+ '.cm-completionMatchedText': {
188
160
  textDecoration: 'none',
189
161
  },
190
162
 
191
- //
192
- // widgets
193
- //
194
- '& .cm-widgetBuffer': {
195
- display: 'none',
196
- height: 0,
197
- },
198
-
199
163
  //
200
164
  // table
201
165
  //
202
- '& .cm-table *': {
166
+ '.cm-table *': {
203
167
  fontFamily: `${get(tokens, 'fontFamily.mono', []).join(',')} !important`,
204
168
  textDecoration: 'none !important',
205
169
  },
206
- '& .cm-table-head': {
170
+ '.cm-table-head': {
207
171
  padding: '2px 16px 2px 0px',
208
172
  borderBottom: `1px solid ${get(tokens, 'extend.colors.neutral.500')}`,
209
173
  fontWeight: 100,
210
174
  textAlign: 'left',
211
175
  color: get(tokens, 'extend.colors.neutral.500'),
212
176
  },
213
- '& .cm-table-cell': {
177
+ '.cm-table-cell': {
214
178
  padding: '2px 16px 2px 0px',
215
179
  },
216
180
 
217
181
  //
218
182
  // image
219
183
  //
220
- '& .cm-image': {
221
- margin: '0.5rem 0',
184
+ '.cm-image': {
185
+ display: 'block',
186
+ height: '0',
187
+ },
188
+ '.cm-image.cm-loaded-image': {
189
+ height: 'auto',
190
+ borderTop: '0.5rem solid transparent',
191
+ borderBottom: '0.5rem solid transparent',
222
192
  },
223
193
 
224
194
  //
225
195
  // font size
226
- // TODO(thure): This appears to be the best or only way to set selection caret heights, but it's far more verbose than it needs to be.
196
+ // TODO(thure): This appears to be the best or only way to set selection caret heights,
197
+ // but it's far more verbose than it needs to be.
227
198
  //
228
- ...Object.keys(get(tokens, 'extend.fontSize', {})).reduce((acc: Record<string, any>, fontSize) => {
229
- const height = get(tokens, ['extend', 'fontSize', fontSize, 1, 'lineHeight']);
230
-
231
- acc[`& .text-${fontSize} + .cm-ySelectionCaret`] = { height };
232
- acc[`& .text-${fontSize} + .cm-ySelection + .cm-ySelectionCaret`] = { height };
233
- acc[`& .text-${fontSize} + .cm-widgetBuffer + .cm-ySelectionCaret`] = { height };
234
- return acc;
235
- }, {}),
199
+ // ...Object.keys(get(tokens, 'extend.fontSize', {})).reduce((acc: Record<string, any>, fontSize) => {
200
+ // const height = get(tokens, ['extend', 'fontSize', fontSize, 1, 'lineHeight']);
201
+ //
202
+ // acc[`& .text-${fontSize} + .cm-ySelectionCaret`] = { height };
203
+ // acc[`& .text-${fontSize} + .cm-ySelection + .cm-ySelectionCaret`] = { height };
204
+ // acc[`& .text-${fontSize} + .cm-widgetBuffer + .cm-ySelectionCaret`] = { height };
205
+ // return acc;
206
+ // }, {}),
236
207
 
237
208
  /**
238
209
  * Panels
@@ -250,14 +221,14 @@ export const defaultTheme: ThemeStyles = {
250
221
  * </div>
251
222
  * </div
252
223
  */
253
- '& .cm-panels': {
224
+ '.cm-panels': {
254
225
  border: `1px solid ${get(tokens, 'extend.colors.neutral.200')}`,
255
226
  },
256
- '& .cm-panel': {
227
+ '.cm-panel': {
257
228
  background: get(tokens, 'extend.colors.neutral.50'),
258
229
  fontFamily: get(tokens, 'fontFamily.body', []).join(','),
259
230
  },
260
- '& .cm-button': {
231
+ '.cm-button': {
261
232
  margin: '4px',
262
233
  fontFamily: get(tokens, 'fontFamily.body', []).join(','),
263
234
  background: get(tokens, 'extend.colors.neutral.100'),
@@ -271,32 +242,34 @@ export const defaultTheme: ThemeStyles = {
271
242
  backgroundImage: 'none',
272
243
  },
273
244
  },
274
- '& .cm-panel input[type=checkbox]': {
245
+ '.cm-panel input[type=checkbox]': {
275
246
  marginRight: '0.4rem !important',
276
247
  },
277
248
  };
278
249
 
279
250
  export const textTheme: ThemeStyles = {
280
- '& .cm-scroller': {
251
+ '.cm-scroller': {
281
252
  fontFamily: get(tokens, 'fontFamily.body', []).join(','),
282
253
  },
283
- '& .cm-placeholder': {
254
+ '.cm-placeholder': {
284
255
  fontFamily: get(tokens, 'fontFamily.body', []).join(','),
285
256
  },
286
257
  };
287
258
 
288
259
  export const markdownTheme: ThemeStyles = {
289
- // NOTE: Must leave base font family as is (i.e., monospace) due to fenced code blocks.
290
- '& .cm-placeholder': {
260
+ '.cm-scroller': {
261
+ fontFamily: get(tokens, 'fontFamily.body', []).join(','),
262
+ },
263
+ '.cm-placeholder': {
291
264
  fontFamily: get(tokens, 'fontFamily.body', []).join(','),
292
265
  },
293
266
  };
294
267
 
295
268
  export const codeTheme: ThemeStyles = {
296
- '& .cm-scroller': {
269
+ '.cm-scroller': {
297
270
  fontFamily: get(tokens, 'fontFamily.mono', []).join(','),
298
271
  },
299
- '& .cm-placeholder': {
272
+ '.cm-placeholder': {
300
273
  fontFamily: get(tokens, 'fontFamily.mono', []).join(','),
301
274
  },
302
275
  };
@@ -1,3 +0,0 @@
1
- import { type Extension } from '@codemirror/state';
2
- export declare const mermaid: () => Extension;
3
- //# sourceMappingURL=mermaid.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mermaid.d.ts","sourceRoot":"","sources":["../../../../src/extensions/mermaid.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAInD,eAAO,MAAM,OAAO,QAAO,SAE1B,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"cursor.d.ts","sourceRoot":"","sources":["../../../../src/util/cursor.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE1C;;;;;;;;;GASG;AACH,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,GAAG,SAAS,GAAG,MAAM,CAAC;IAC/D,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;CACpC;AAOD,eAAO,MAAM,eAAe,yCAE1B,CAAC"}
@@ -1,3 +0,0 @@
1
- export * from './cursor';
2
- export * from './util';
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/util/index.ts"],"names":[],"mappings":"AAIA,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../../../src/util/util.ts"],"names":[],"mappings":"AAMA;;GAEG;AAEH,eAAO,MAAM,eAAe,kCAOR,CAAC"}
@@ -1,11 +0,0 @@
1
- //
2
- // Copyright 2024 DXOS.org
3
- //
4
-
5
- import { type Extension } from '@codemirror/state';
6
-
7
- // TODO(burdon): How will this interact with the code extension?
8
- // TODO(burdon): Move to mermaid-plugin (which should contribute this extension).
9
- export const mermaid = (): Extension => {
10
- return [];
11
- };
@@ -1,29 +0,0 @@
1
- //
2
- // Copyright 2024 DXOS.org
3
- //
4
-
5
- import { Facet } from '@codemirror/state';
6
-
7
- /**
8
- * Converts indexes into the text document into stable peer-independent cursors.
9
- *
10
- * See:
11
- * - https://automerge.org/automerge/api-docs/js/functions/next.getCursor.html
12
- * - https://github.com/yjs/yjs?tab=readme-ov-file#relative-positions
13
- *
14
- * @param {assoc} number Negative values will associate the cursor with the previous character
15
- * while positive - with the next one.
16
- */
17
- export interface CursorConverter {
18
- toCursor(position: number, assoc?: -1 | 1 | undefined): string;
19
- fromCursor(cursor: string): number;
20
- }
21
-
22
- const DEFAULT_CURSOR_CONVERTER: CursorConverter = {
23
- toCursor: (position) => position.toString(),
24
- fromCursor: (cursor) => parseInt(cursor),
25
- };
26
-
27
- export const CursorConverter = Facet.define<CursorConverter, CursorConverter>({
28
- combine: (providers) => providers[0] ?? DEFAULT_CURSOR_CONVERTER,
29
- });
package/src/util/index.ts DELETED
@@ -1,6 +0,0 @@
1
- //
2
- // Copyright 2024 DXOS.org
3
- //
4
-
5
- export * from './cursor';
6
- export * from './util';
File without changes
File without changes