@dxos/react-ui-editor 0.3.11-main.8be6c8a → 0.3.11-main.8feb6a5

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 (63) hide show
  1. package/dist/lib/browser/index.mjs +250 -333
  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.map +1 -1
  5. package/dist/types/src/components/TextEditor/TextEditor.d.ts +2 -7
  6. package/dist/types/src/components/TextEditor/TextEditor.d.ts.map +1 -1
  7. package/dist/types/src/components/TextEditor/TextEditor.stories.d.ts +4 -4
  8. package/dist/types/src/components/TextEditor/TextEditor.stories.d.ts.map +1 -1
  9. package/dist/types/src/components/TextEditor/comments.stories.d.ts +26 -0
  10. package/dist/types/src/components/TextEditor/comments.stories.d.ts.map +1 -0
  11. package/dist/types/src/extensions/automerge/cursor.d.ts +1 -1
  12. package/dist/types/src/extensions/automerge/cursor.d.ts.map +1 -1
  13. package/dist/types/src/extensions/code.d.ts.map +1 -1
  14. package/dist/types/src/extensions/comments.d.ts +6 -2
  15. package/dist/types/src/extensions/comments.d.ts.map +1 -1
  16. package/dist/types/src/{util → extensions}/cursor.d.ts +9 -1
  17. package/dist/types/src/extensions/cursor.d.ts.map +1 -0
  18. package/dist/types/src/extensions/index.d.ts +1 -0
  19. package/dist/types/src/extensions/index.d.ts.map +1 -1
  20. package/dist/types/src/extensions/markdown/highlight.d.ts.map +1 -1
  21. package/dist/types/src/extensions/tasklist.d.ts +5 -1
  22. package/dist/types/src/extensions/tasklist.d.ts.map +1 -1
  23. package/dist/types/src/extensions/yjs/cursor.d.ts +1 -1
  24. package/dist/types/src/extensions/yjs/cursor.d.ts.map +1 -1
  25. package/dist/types/src/hooks/useTextModel.d.ts +0 -5
  26. package/dist/types/src/hooks/useTextModel.d.ts.map +1 -1
  27. package/dist/types/src/hooks/yjs.d.ts.map +1 -1
  28. package/dist/types/src/styles/markdown.d.ts.map +1 -1
  29. package/dist/types/src/themes/default.d.ts.map +1 -1
  30. package/dist/types/src/util.d.ts.map +1 -0
  31. package/package.json +24 -23
  32. package/src/components/TextEditor/MarkdownEditor.stories.tsx +12 -12
  33. package/src/components/TextEditor/TextEditor.stories.tsx +10 -43
  34. package/src/components/TextEditor/TextEditor.tsx +21 -31
  35. package/src/components/TextEditor/comments.stories.tsx +329 -0
  36. package/src/extensions/automerge/automerge.ts +2 -2
  37. package/src/extensions/automerge/cursor.ts +2 -1
  38. package/src/extensions/awareness.ts +25 -32
  39. package/src/extensions/code.ts +10 -2
  40. package/src/extensions/comments.ts +86 -116
  41. package/src/extensions/cursor.ts +46 -0
  42. package/src/extensions/hr.ts +2 -2
  43. package/src/extensions/image.ts +2 -2
  44. package/src/extensions/index.ts +1 -0
  45. package/src/extensions/link.ts +4 -4
  46. package/src/extensions/markdown/highlight.ts +0 -8
  47. package/src/extensions/table.ts +2 -2
  48. package/src/extensions/tasklist.ts +53 -77
  49. package/src/extensions/yjs/cursor.ts +2 -1
  50. package/src/extensions/yjs/yjs.test.ts +1 -1
  51. package/src/extensions/yjs/yjs.ts +2 -2
  52. package/src/hooks/useTextModel.ts +3 -6
  53. package/src/hooks/yjs.ts +1 -23
  54. package/src/styles/markdown.ts +0 -2
  55. package/src/themes/default.ts +17 -50
  56. package/dist/types/src/util/cursor.d.ts.map +0 -1
  57. package/dist/types/src/util/index.d.ts +0 -3
  58. package/dist/types/src/util/index.d.ts.map +0 -1
  59. package/dist/types/src/util/util.d.ts.map +0 -1
  60. package/src/util/cursor.ts +0 -29
  61. package/src/util/index.ts +0 -6
  62. /package/dist/types/src/{util/util.d.ts → util.d.ts} +0 -0
  63. /package/src/{util/util.ts → util.ts} +0 -0
@@ -8,9 +8,9 @@ import type * as YP from 'y-protocols/awareness';
8
8
  import type { YText } from '@dxos/text-model';
9
9
 
10
10
  import { cursorConverter } from './cursor';
11
- import { CursorConverter } from '../../util';
11
+ import { Cursor } from '../cursor';
12
12
 
13
13
  export const yjs = (content: YText, awareness?: YP.Awareness) => [
14
- CursorConverter.of(cursorConverter(content)),
14
+ Cursor.converter.of(cursorConverter(content)),
15
15
  yCollab(content, awareness),
16
16
  ];
@@ -30,7 +30,7 @@ export type Range = {
30
30
 
31
31
  export type CommentRange = {
32
32
  id: string;
33
- cursor: string;
33
+ cursor: string; // TODO(burdon): Rename range.
34
34
  };
35
35
 
36
36
  // TODO(wittjosiah): Factor out to common package? @dxos/react-client?
@@ -41,13 +41,10 @@ export type EditorModel = {
41
41
 
42
42
  // TODO(burdon): Remove.
43
43
  content: string | YText | YXmlFragment | DocAccessor;
44
- /**
45
- * @deprecated Use CursorConverter.
46
- */
47
- getCursorFromRange?: (value: Range) => string;
48
- getRangeFromCursor?: (cursor: string) => Range | undefined;
44
+
49
45
  // TODO(burdon): Move into extension.
50
46
  awareness?: YP.Awareness;
47
+
51
48
  // TODO(burdon): Remove.
52
49
  peer?: {
53
50
  id: string;
package/src/hooks/yjs.ts CHANGED
@@ -6,7 +6,6 @@ import * as decoding from 'lib0/decoding';
6
6
  import * as encoding from 'lib0/encoding';
7
7
  import { Observable } from 'lib0/observable';
8
8
  import * as YP from 'y-protocols/awareness';
9
- import * as Y from 'yjs';
10
9
  import { type Doc } from 'yjs';
11
10
 
12
11
  import { invariant } from '@dxos/invariant';
@@ -14,9 +13,8 @@ import { log } from '@dxos/log';
14
13
  import { type Space } from '@dxos/react-client/echo';
15
14
  import { type GossipMessage } from '@dxos/react-client/mesh';
16
15
  import type { YText } from '@dxos/text-model';
17
- import { arrayToString, stringToArray } from '@dxos/util';
18
16
 
19
- import { type EditorModel, modelState, type Range, type UseTextModelProps } from './useTextModel';
17
+ import { type EditorModel, modelState, type UseTextModelProps } from './useTextModel';
20
18
  import { yjs } from '../extensions';
21
19
 
22
20
  export const createYjsModel = ({ identity, space, text }: UseTextModelProps): EditorModel => {
@@ -29,26 +27,6 @@ export const createYjsModel = ({ identity, space, text }: UseTextModelProps): Ed
29
27
  id: text.doc.guid,
30
28
  content: text.content,
31
29
  text: () => text.content!.toString(),
32
- // https://github.com/yjs/yjs?tab=readme-ov-file#relative-positions
33
- // TODO(dmaretskyi): Refactor as cursor-converter.
34
- getCursorFromRange: (range: Range) => {
35
- const from = Y.encodeRelativePosition(Y.createRelativePositionFromTypeIndex(text.content as YText, range.from));
36
- const to = Y.encodeRelativePosition(Y.createRelativePositionFromTypeIndex(text.content as YText, range.to, -1));
37
- return [arrayToString(from), arrayToString(to)].join(':');
38
- },
39
- getRangeFromCursor: (cursor: string) => {
40
- invariant(text.doc);
41
- const parts = cursor.split(':');
42
- const from = Y.createAbsolutePositionFromRelativePosition(
43
- Y.decodeRelativePosition(stringToArray(parts[0])),
44
- text.doc,
45
- );
46
- const to = Y.createAbsolutePositionFromRelativePosition(
47
- Y.decodeRelativePosition(stringToArray(parts[1])),
48
- text.doc,
49
- );
50
- return from && to ? { from: from.index, to: to.index } : undefined;
51
- },
52
30
  extension: [modelState.init(() => model), yjs(text.content as YText, provider?.awareness)],
53
31
  awareness: provider?.awareness,
54
32
  peer: identity
@@ -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
 
@@ -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.
@@ -86,6 +86,8 @@ export const defaultTheme: ThemeStyles = {
86
86
  //
87
87
  '.cm-line': {
88
88
  paddingInline: 0,
89
+ // TODO(burdon): Other values leave gaps between lines when highlighted.
90
+ // lineHeight: 'normal',
89
91
  },
90
92
  '.cm-activeLine': {
91
93
  background: 'inherit',
@@ -119,36 +121,6 @@ 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
  //
@@ -188,14 +160,6 @@ export const defaultTheme: ThemeStyles = {
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
  //
@@ -229,16 +193,17 @@ export const defaultTheme: ThemeStyles = {
229
193
 
230
194
  //
231
195
  // font size
232
- // 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.
233
198
  //
234
- ...Object.keys(get(tokens, 'extend.fontSize', {})).reduce((acc: Record<string, any>, fontSize) => {
235
- const height = get(tokens, ['extend', 'fontSize', fontSize, 1, 'lineHeight']);
236
-
237
- acc[`& .text-${fontSize} + .cm-ySelectionCaret`] = { height };
238
- acc[`& .text-${fontSize} + .cm-ySelection + .cm-ySelectionCaret`] = { height };
239
- acc[`& .text-${fontSize} + .cm-widgetBuffer + .cm-ySelectionCaret`] = { height };
240
- return acc;
241
- }, {}),
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
+ // }, {}),
242
207
 
243
208
  /**
244
209
  * Panels
@@ -292,7 +257,9 @@ export const textTheme: ThemeStyles = {
292
257
  };
293
258
 
294
259
  export const markdownTheme: ThemeStyles = {
295
- // NOTE: Must leave base font family as is (i.e., monospace) due to fenced code blocks.
260
+ '.cm-scroller': {
261
+ fontFamily: get(tokens, 'fontFamily.body', []).join(','),
262
+ },
296
263
  '.cm-placeholder': {
297
264
  fontFamily: get(tokens, 'fontFamily.body', []).join(','),
298
265
  },
@@ -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,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