@dxos/react-ui-editor 0.3.11-main.8be6c8a → 0.3.11-main.90a8b71
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.
- package/dist/lib/browser/index.mjs +146 -282
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/types/src/components/TextEditor/MarkdownEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/TextEditor.d.ts +2 -7
- package/dist/types/src/components/TextEditor/TextEditor.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/TextEditor.stories.d.ts +4 -4
- package/dist/types/src/components/TextEditor/TextEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/comments.stories.d.ts +26 -0
- package/dist/types/src/components/TextEditor/comments.stories.d.ts.map +1 -0
- package/dist/types/src/extensions/automerge/cursor.d.ts +1 -1
- package/dist/types/src/extensions/automerge/cursor.d.ts.map +1 -1
- package/dist/types/src/extensions/code.d.ts.map +1 -1
- package/dist/types/src/extensions/comments.d.ts +2 -2
- package/dist/types/src/extensions/comments.d.ts.map +1 -1
- package/dist/types/src/{util → extensions}/cursor.d.ts +9 -1
- package/dist/types/src/extensions/cursor.d.ts.map +1 -0
- package/dist/types/src/extensions/index.d.ts +1 -0
- package/dist/types/src/extensions/index.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/highlight.d.ts.map +1 -1
- package/dist/types/src/extensions/yjs/cursor.d.ts +1 -1
- package/dist/types/src/extensions/yjs/cursor.d.ts.map +1 -1
- package/dist/types/src/hooks/useTextModel.d.ts +0 -5
- package/dist/types/src/hooks/useTextModel.d.ts.map +1 -1
- package/dist/types/src/hooks/yjs.d.ts.map +1 -1
- package/dist/types/src/styles/markdown.d.ts.map +1 -1
- package/dist/types/src/themes/default.d.ts.map +1 -1
- package/dist/types/src/util.d.ts.map +1 -0
- package/package.json +23 -22
- package/src/components/TextEditor/MarkdownEditor.stories.tsx +12 -12
- package/src/components/TextEditor/TextEditor.stories.tsx +10 -43
- package/src/components/TextEditor/TextEditor.tsx +21 -31
- package/src/components/TextEditor/comments.stories.tsx +315 -0
- package/src/extensions/automerge/automerge.ts +2 -2
- package/src/extensions/automerge/cursor.ts +2 -1
- package/src/extensions/awareness.ts +25 -32
- package/src/extensions/code.ts +10 -2
- package/src/extensions/comments.ts +20 -115
- package/src/extensions/cursor.ts +46 -0
- package/src/extensions/hr.ts +2 -2
- package/src/extensions/image.ts +2 -2
- package/src/extensions/index.ts +1 -0
- package/src/extensions/link.ts +4 -4
- package/src/extensions/markdown/highlight.ts +0 -8
- package/src/extensions/table.ts +2 -2
- package/src/extensions/tasklist.ts +2 -2
- package/src/extensions/yjs/cursor.ts +2 -1
- package/src/extensions/yjs/yjs.ts +2 -2
- package/src/hooks/useTextModel.ts +3 -6
- package/src/hooks/yjs.ts +1 -23
- package/src/styles/markdown.ts +0 -2
- package/src/themes/default.ts +17 -50
- package/dist/types/src/util/cursor.d.ts.map +0 -1
- package/dist/types/src/util/index.d.ts +0 -3
- package/dist/types/src/util/index.d.ts.map +0 -1
- package/dist/types/src/util/util.d.ts.map +0 -1
- package/src/util/cursor.ts +0 -29
- package/src/util/index.ts +0 -6
- /package/dist/types/src/{util/util.d.ts → util.d.ts} +0 -0
- /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
|
|
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
|
package/src/styles/markdown.ts
CHANGED
|
@@ -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
|
|
package/src/themes/default.ts
CHANGED
|
@@ -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
|
|
10
|
-
//
|
|
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,
|
|
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
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
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
|
-
|
|
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 +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"}
|
package/src/util/cursor.ts
DELETED
|
@@ -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
|
File without changes
|
|
File without changes
|