@dxos/react-ui-editor 0.3.11-main.8a2cfe6 → 0.3.11-main.8a9dd1e
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 +305 -385
- 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 +6 -2
- package/dist/types/src/components/TextEditor/MarkdownEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/TextEditor.d.ts +12 -17
- package/dist/types/src/components/TextEditor/TextEditor.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/TextEditor.stories.d.ts +6 -6
- 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/components/TextEditor/yjs.stories.d.ts +1 -1
- package/dist/types/src/extensions/autocomplete.d.ts.map +1 -1
- 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/automerge/index.d.ts +1 -0
- package/dist/types/src/extensions/automerge/index.d.ts.map +1 -1
- package/dist/types/src/extensions/code.d.ts.map +1 -1
- package/dist/types/src/extensions/comments.d.ts +6 -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/tasklist.d.ts +5 -1
- package/dist/types/src/extensions/tasklist.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/index.d.ts +2 -0
- package/dist/types/src/index.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 +24 -23
- package/src/components/TextEditor/MarkdownEditor.stories.tsx +19 -16
- package/src/components/TextEditor/TextEditor.stories.tsx +12 -46
- package/src/components/TextEditor/TextEditor.tsx +68 -64
- package/src/components/TextEditor/comments.stories.tsx +329 -0
- package/src/extensions/autocomplete.ts +18 -17
- package/src/extensions/automerge/automerge.ts +2 -2
- package/src/extensions/automerge/cursor.ts +2 -1
- package/src/extensions/automerge/index.ts +1 -0
- package/src/extensions/awareness.ts +25 -32
- package/src/extensions/code.ts +10 -2
- package/src/extensions/comments.ts +86 -116
- 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 +6 -3
- package/src/extensions/tasklist.ts +53 -77
- package/src/extensions/yjs/cursor.ts +2 -1
- package/src/extensions/yjs/yjs.test.ts +1 -1
- package/src/extensions/yjs/yjs.ts +2 -2
- package/src/hooks/useTextModel.ts +4 -7
- package/src/hooks/yjs.ts +1 -23
- package/src/index.ts +2 -0
- 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
|
@@ -12,7 +12,7 @@ import { type YText } from '@dxos/text-model';
|
|
|
12
12
|
describe('YJS', () => {
|
|
13
13
|
// https://docs.yjs.dev/api/shared-types/y.text
|
|
14
14
|
// https://github.com/yjs/yjs?tab=readme-ov-file#relative-positions
|
|
15
|
-
test('absolute position', () => {
|
|
15
|
+
test.skip('absolute position', () => {
|
|
16
16
|
const obj = new TextObject('hello world');
|
|
17
17
|
const index = obj.text.indexOf('world');
|
|
18
18
|
const relPos = Y.encodeRelativePosition(Y.createRelativePositionFromTypeIndex(obj.content as YText, index));
|
|
@@ -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 {
|
|
11
|
+
import { Cursor } from '../cursor';
|
|
12
12
|
|
|
13
13
|
export const yjs = (content: YText, awareness?: YP.Awareness) => [
|
|
14
|
-
|
|
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;
|
|
@@ -66,7 +63,7 @@ export type UseTextModelProps = {
|
|
|
66
63
|
// TODO(wittjosiah): Factor out to common package? @dxos/react-client?
|
|
67
64
|
export const useTextModel = (props: UseTextModelProps): EditorModel | undefined => {
|
|
68
65
|
const { identity, space, text } = props;
|
|
69
|
-
const [model, setModel] = useState<EditorModel | undefined>(
|
|
66
|
+
const [model, setModel] = useState<EditorModel | undefined>();
|
|
70
67
|
useEffect(() => setModel(createModel(props)), [identity, space, text]);
|
|
71
68
|
return model;
|
|
72
69
|
};
|
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/index.ts
CHANGED
|
@@ -5,9 +5,11 @@
|
|
|
5
5
|
export { TextKind } from '@dxos/protocols/proto/dxos/echo/model/text';
|
|
6
6
|
export { Doc, YText, YXmlFragment } from '@dxos/text-model';
|
|
7
7
|
export { type Extension } from '@codemirror/state';
|
|
8
|
+
export { type EditorView } from '@codemirror/view';
|
|
8
9
|
|
|
9
10
|
export * from './components';
|
|
10
11
|
export * from './extensions';
|
|
11
12
|
export * from './hooks';
|
|
12
13
|
export { getToken } from './styles';
|
|
13
14
|
export * from './themes';
|
|
15
|
+
export * from './util';
|
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
|