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

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 (60) hide show
  1. package/dist/lib/browser/index.mjs +146 -275
  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 +2 -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/yjs/cursor.d.ts +1 -1
  22. package/dist/types/src/extensions/yjs/cursor.d.ts.map +1 -1
  23. package/dist/types/src/hooks/useTextModel.d.ts +0 -5
  24. package/dist/types/src/hooks/useTextModel.d.ts.map +1 -1
  25. package/dist/types/src/hooks/yjs.d.ts.map +1 -1
  26. package/dist/types/src/styles/markdown.d.ts.map +1 -1
  27. package/dist/types/src/themes/default.d.ts.map +1 -1
  28. package/dist/types/src/util.d.ts.map +1 -0
  29. package/package.json +23 -22
  30. package/src/components/TextEditor/MarkdownEditor.stories.tsx +12 -12
  31. package/src/components/TextEditor/TextEditor.stories.tsx +10 -43
  32. package/src/components/TextEditor/TextEditor.tsx +21 -31
  33. package/src/components/TextEditor/comments.stories.tsx +315 -0
  34. package/src/extensions/automerge/automerge.ts +2 -2
  35. package/src/extensions/automerge/cursor.ts +2 -1
  36. package/src/extensions/awareness.ts +25 -32
  37. package/src/extensions/code.ts +10 -2
  38. package/src/extensions/comments.ts +20 -115
  39. package/src/extensions/cursor.ts +46 -0
  40. package/src/extensions/hr.ts +2 -2
  41. package/src/extensions/image.ts +2 -2
  42. package/src/extensions/index.ts +1 -0
  43. package/src/extensions/link.ts +4 -4
  44. package/src/extensions/markdown/highlight.ts +0 -8
  45. package/src/extensions/table.ts +2 -2
  46. package/src/extensions/tasklist.ts +2 -2
  47. package/src/extensions/yjs/cursor.ts +2 -1
  48. package/src/extensions/yjs/yjs.ts +2 -2
  49. package/src/hooks/useTextModel.ts +3 -6
  50. package/src/hooks/yjs.ts +1 -23
  51. package/src/styles/markdown.ts +0 -2
  52. package/src/themes/default.ts +17 -42
  53. package/dist/types/src/util/cursor.d.ts.map +0 -1
  54. package/dist/types/src/util/index.d.ts +0 -3
  55. package/dist/types/src/util/index.d.ts.map +0 -1
  56. package/dist/types/src/util/util.d.ts.map +0 -1
  57. package/src/util/cursor.ts +0 -29
  58. package/src/util/index.ts +0 -6
  59. /package/dist/types/src/{util/util.d.ts → util.d.ts} +0 -0
  60. /package/src/{util/util.ts → util.ts} +0 -0
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
  //
@@ -229,16 +201,17 @@ export const defaultTheme: ThemeStyles = {
229
201
 
230
202
  //
231
203
  // 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.
204
+ // TODO(thure): This appears to be the best or only way to set selection caret heights,
205
+ // but it's far more verbose than it needs to be.
233
206
  //
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
- }, {}),
207
+ // ...Object.keys(get(tokens, 'extend.fontSize', {})).reduce((acc: Record<string, any>, fontSize) => {
208
+ // const height = get(tokens, ['extend', 'fontSize', fontSize, 1, 'lineHeight']);
209
+ //
210
+ // acc[`& .text-${fontSize} + .cm-ySelectionCaret`] = { height };
211
+ // acc[`& .text-${fontSize} + .cm-ySelection + .cm-ySelectionCaret`] = { height };
212
+ // acc[`& .text-${fontSize} + .cm-widgetBuffer + .cm-ySelectionCaret`] = { height };
213
+ // return acc;
214
+ // }, {}),
242
215
 
243
216
  /**
244
217
  * Panels
@@ -292,7 +265,9 @@ export const textTheme: ThemeStyles = {
292
265
  };
293
266
 
294
267
  export const markdownTheme: ThemeStyles = {
295
- // NOTE: Must leave base font family as is (i.e., monospace) due to fenced code blocks.
268
+ '.cm-scroller': {
269
+ fontFamily: get(tokens, 'fontFamily.body', []).join(','),
270
+ },
296
271
  '.cm-placeholder': {
297
272
  fontFamily: get(tokens, 'fontFamily.body', []).join(','),
298
273
  },
@@ -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