@dxos/react-ui-editor 0.3.11-main.3f845e1 → 0.3.11-main.463e5cd
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 +2578 -1622
- 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 +14 -15
- package/dist/types/src/components/TextEditor/MarkdownEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/TextEditor.d.ts +20 -17
- package/dist/types/src/components/TextEditor/TextEditor.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/TextEditor.stories.d.ts +6 -3
- package/dist/types/src/components/TextEditor/TextEditor.stories.d.ts.map +1 -1
- package/dist/types/src/{hooks/automerge → components/TextEditor}/automerge.stories.d.ts +6 -1
- package/dist/types/src/components/TextEditor/automerge.stories.d.ts.map +1 -0
- package/dist/types/src/components/TextEditor/hooks.stories.d.ts +23 -0
- package/dist/types/src/components/TextEditor/hooks.stories.d.ts.map +1 -0
- package/dist/types/src/components/TextEditor/index.d.ts +0 -2
- package/dist/types/src/components/TextEditor/index.d.ts.map +1 -1
- package/dist/types/src/components/Toolbar/Toolbar.d.ts +25 -0
- package/dist/types/src/components/Toolbar/Toolbar.d.ts.map +1 -0
- package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts +23 -0
- package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts.map +1 -0
- package/dist/types/src/components/Toolbar/index.d.ts +2 -0
- package/dist/types/src/components/Toolbar/index.d.ts.map +1 -0
- package/dist/types/src/components/index.d.ts +1 -0
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/extensions/autocomplete.d.ts.map +1 -0
- package/dist/types/src/extensions/automerge/automerge.d.ts +9 -0
- package/dist/types/src/extensions/automerge/automerge.d.ts.map +1 -0
- package/dist/types/src/extensions/automerge/automerge.spec.d.ts +2 -0
- package/dist/types/src/extensions/automerge/automerge.spec.d.ts.map +1 -0
- package/dist/types/src/extensions/automerge/automerge.test.d.ts +2 -0
- package/dist/types/src/extensions/automerge/automerge.test.d.ts.map +1 -0
- package/dist/types/src/extensions/automerge/cursor.d.ts +5 -0
- package/dist/types/src/extensions/automerge/cursor.d.ts.map +1 -0
- package/dist/types/src/extensions/automerge/defs.d.ts +24 -0
- package/dist/types/src/extensions/automerge/defs.d.ts.map +1 -0
- package/dist/types/src/extensions/automerge/index.d.ts +3 -0
- package/dist/types/src/extensions/automerge/index.d.ts.map +1 -0
- package/dist/types/src/extensions/automerge/semaphore.d.ts +15 -0
- package/dist/types/src/extensions/automerge/semaphore.d.ts.map +1 -0
- package/dist/types/src/extensions/automerge/update-automerge.d.ts +5 -0
- package/dist/types/src/extensions/automerge/update-automerge.d.ts.map +1 -0
- package/dist/types/src/extensions/automerge/update-codemirror.d.ts.map +1 -0
- package/dist/types/src/extensions/awareness.d.ts +46 -0
- package/dist/types/src/extensions/awareness.d.ts.map +1 -0
- package/dist/types/src/extensions/basic.d.ts +8 -0
- package/dist/types/src/extensions/basic.d.ts.map +1 -0
- package/dist/types/src/extensions/blast.d.ts.map +1 -0
- package/dist/types/src/extensions/comments.d.ts +67 -0
- package/dist/types/src/extensions/comments.d.ts.map +1 -0
- package/dist/types/src/extensions/cursor.d.ts +25 -0
- package/dist/types/src/extensions/cursor.d.ts.map +1 -0
- package/dist/types/src/extensions/index.d.ts +13 -0
- package/dist/types/src/extensions/index.d.ts.map +1 -0
- package/dist/types/src/extensions/listener.d.ts +10 -0
- package/dist/types/src/extensions/listener.d.ts.map +1 -0
- package/dist/types/src/extensions/markdown/bundle.d.ts +14 -0
- package/dist/types/src/extensions/markdown/bundle.d.ts.map +1 -0
- package/dist/types/src/extensions/markdown/code.d.ts.map +1 -0
- package/dist/types/src/extensions/markdown/formatting.d.ts +13 -0
- package/dist/types/src/extensions/markdown/formatting.d.ts.map +1 -0
- package/dist/types/src/extensions/markdown/heading.d.ts +6 -0
- package/dist/types/src/extensions/markdown/heading.d.ts.map +1 -0
- package/dist/types/src/extensions/markdown/highlight.d.ts.map +1 -0
- package/dist/types/src/extensions/markdown/hr.d.ts.map +1 -0
- package/dist/types/src/extensions/markdown/image.d.ts.map +1 -0
- package/dist/types/src/extensions/markdown/index.d.ts +11 -0
- package/dist/types/src/extensions/markdown/index.d.ts.map +1 -0
- package/dist/types/src/{components/TextEditor/extensions → extensions/markdown}/link.d.ts +1 -0
- package/dist/types/src/extensions/markdown/link.d.ts.map +1 -0
- package/dist/types/src/extensions/markdown/table.d.ts.map +1 -0
- package/dist/types/src/extensions/markdown/tasklist.d.ts.map +1 -0
- package/dist/types/src/extensions/mention.d.ts.map +1 -0
- package/dist/types/src/extensions/outliner.d.ts +4 -0
- package/dist/types/src/extensions/outliner.d.ts.map +1 -0
- package/dist/types/src/extensions/typewriter.d.ts.map +1 -0
- package/dist/types/src/hooks/awareness-provider.d.ts +31 -0
- package/dist/types/src/hooks/awareness-provider.d.ts.map +1 -0
- package/dist/types/src/hooks/defs.d.ts +25 -0
- package/dist/types/src/hooks/defs.d.ts.map +1 -0
- package/dist/types/src/hooks/index.d.ts +5 -1
- package/dist/types/src/hooks/index.d.ts.map +1 -1
- package/dist/types/src/hooks/useActionHandler.d.ts +4 -0
- package/dist/types/src/hooks/useActionHandler.d.ts.map +1 -0
- package/dist/types/src/hooks/useEditorView.d.ts +17 -0
- package/dist/types/src/hooks/useEditorView.d.ts.map +1 -0
- package/dist/types/src/hooks/useTextEditor.d.ts +39 -0
- package/dist/types/src/hooks/useTextEditor.d.ts.map +1 -0
- package/dist/types/src/hooks/useTextModel.d.ts +14 -31
- package/dist/types/src/hooks/useTextModel.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +5 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/styles/cursors.d.ts.map +1 -0
- package/dist/types/src/styles/index.d.ts +1 -0
- package/dist/types/src/styles/index.d.ts.map +1 -1
- package/dist/types/src/styles/markdown.d.ts +2 -2
- package/dist/types/src/styles/markdown.d.ts.map +1 -1
- package/dist/types/src/styles/tokens.d.ts +1 -0
- package/dist/types/src/styles/tokens.d.ts.map +1 -1
- package/dist/types/src/{components/TextEditor/themes → themes}/default.d.ts +1 -1
- package/dist/types/src/themes/default.d.ts.map +1 -0
- package/dist/types/src/themes/index.d.ts.map +1 -0
- package/dist/types/src/util.d.ts +7 -0
- package/dist/types/src/util.d.ts.map +1 -0
- package/package.json +48 -36
- package/src/components/TextEditor/MarkdownEditor.stories.tsx +93 -102
- package/src/components/TextEditor/TextEditor.stories.tsx +13 -34
- package/src/components/TextEditor/TextEditor.tsx +137 -97
- package/src/{hooks/automerge → components/TextEditor}/automerge.stories.tsx +65 -6
- package/src/components/TextEditor/hooks.stories.tsx +106 -0
- package/src/components/TextEditor/index.ts +0 -3
- package/src/components/Toolbar/Toolbar.stories.tsx +90 -0
- package/src/components/Toolbar/Toolbar.tsx +166 -0
- package/src/components/Toolbar/index.ts +5 -0
- package/src/components/index.ts +1 -0
- package/src/{components/TextEditor/extensions → extensions}/autocomplete.ts +23 -19
- package/src/extensions/automerge/automerge.spec.tsx +76 -0
- package/src/extensions/automerge/automerge.test.ts +13 -0
- package/src/extensions/automerge/automerge.ts +103 -0
- package/src/extensions/automerge/cursor.ts +52 -0
- package/src/extensions/automerge/defs.ts +41 -0
- package/src/extensions/automerge/index.ts +6 -0
- package/src/extensions/automerge/semaphore.ts +81 -0
- package/src/extensions/automerge/update-automerge.ts +49 -0
- package/src/{hooks → extensions}/automerge/update-codemirror.ts +17 -9
- package/src/extensions/awareness.ts +313 -0
- package/src/{components/TextEditor/extensions → extensions}/basic.ts +17 -10
- package/src/{components/TextEditor/extensions → extensions}/blast.ts +4 -1
- package/src/extensions/comments.ts +476 -0
- package/src/extensions/cursor.ts +50 -0
- package/src/{components/TextEditor/extensions → extensions}/index.ts +4 -8
- package/src/extensions/listener.ts +35 -0
- package/src/{components/TextEditor/extensions → extensions}/markdown/bundle.ts +23 -28
- package/src/extensions/markdown/code.ts +150 -0
- package/src/extensions/markdown/formatting.ts +188 -0
- package/src/extensions/markdown/heading.ts +59 -0
- package/src/{components/TextEditor/extensions → extensions}/markdown/highlight.ts +12 -27
- package/src/extensions/markdown/hr.ts +71 -0
- package/src/extensions/markdown/image.ts +87 -0
- package/src/extensions/markdown/index.ts +14 -0
- package/src/{components/TextEditor/extensions → extensions/markdown}/link.ts +121 -58
- package/src/{components/TextEditor/extensions → extensions/markdown}/table.ts +10 -4
- package/src/extensions/markdown/tasklist.ts +110 -0
- package/src/{components/TextEditor/extensions → extensions}/mention.ts +9 -2
- package/src/extensions/outliner.ts +12 -0
- package/src/{components/TextEditor/extensions → extensions}/typewriter.ts +1 -1
- package/src/hooks/awareness-provider.ts +124 -0
- package/src/hooks/defs.ts +42 -0
- package/src/hooks/index.ts +6 -1
- package/src/hooks/useActionHandler.ts +62 -0
- package/src/hooks/useEditorView.ts +29 -0
- package/src/hooks/useTextEditor.ts +153 -0
- package/src/hooks/useTextModel.ts +48 -114
- package/src/index.ts +5 -0
- package/src/styles/index.ts +1 -0
- package/src/styles/markdown.ts +9 -12
- package/src/styles/tokens.ts +3 -0
- package/src/{components/TextEditor/themes → themes}/default.ts +58 -82
- package/src/util.ts +41 -0
- package/dist/types/src/components/TextEditor/codemirror.stories.d.ts +0 -12
- package/dist/types/src/components/TextEditor/codemirror.stories.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/autocomplete.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/basic.d.ts +0 -9
- package/dist/types/src/components/TextEditor/extensions/basic.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/blast.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/code.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/comments.d.ts +0 -48
- package/dist/types/src/components/TextEditor/extensions/comments.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/hr.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/image.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/index.d.ts +0 -17
- package/dist/types/src/components/TextEditor/extensions/index.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/link.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/listener.d.ts +0 -9
- package/dist/types/src/components/TextEditor/extensions/listener.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/markdown/bundle.d.ts +0 -17
- package/dist/types/src/components/TextEditor/extensions/markdown/bundle.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/markdown/highlight.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/markdown/index.d.ts +0 -3
- package/dist/types/src/components/TextEditor/extensions/markdown/index.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/mention.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/mermaid.d.ts +0 -3
- package/dist/types/src/components/TextEditor/extensions/mermaid.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/table.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/tasklist.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/tooltip.d.ts +0 -12
- package/dist/types/src/components/TextEditor/extensions/tooltip.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/typewriter.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/util.d.ts +0 -5
- package/dist/types/src/components/TextEditor/extensions/util.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/themes/default.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/themes/index.d.ts.map +0 -1
- package/dist/types/src/hooks/automerge/automerge.stories.d.ts.map +0 -1
- package/dist/types/src/hooks/automerge/handle.d.ts +0 -9
- package/dist/types/src/hooks/automerge/handle.d.ts.map +0 -1
- package/dist/types/src/hooks/automerge/index.d.ts +0 -3
- package/dist/types/src/hooks/automerge/index.d.ts.map +0 -1
- package/dist/types/src/hooks/automerge/plugin.d.ts +0 -26
- package/dist/types/src/hooks/automerge/plugin.d.ts.map +0 -1
- package/dist/types/src/hooks/automerge/semaphore.d.ts +0 -19
- package/dist/types/src/hooks/automerge/semaphore.d.ts.map +0 -1
- package/dist/types/src/hooks/automerge/update-automerge.d.ts +0 -6
- package/dist/types/src/hooks/automerge/update-automerge.d.ts.map +0 -1
- package/dist/types/src/hooks/automerge/update-codemirror.d.ts.map +0 -1
- package/dist/types/src/hooks/yjs/cursors.d.ts.map +0 -1
- package/dist/types/src/hooks/yjs/index.d.ts +0 -3
- package/dist/types/src/hooks/yjs/index.d.ts.map +0 -1
- package/dist/types/src/hooks/yjs/space-provider.d.ts +0 -27
- package/dist/types/src/hooks/yjs/space-provider.d.ts.map +0 -1
- package/dist/types/src/hooks/yjs/yjs.stories.d.ts +0 -12
- package/dist/types/src/hooks/yjs/yjs.stories.d.ts.map +0 -1
- package/dist/types/src/hooks/yjs/yjs.test.d.ts +0 -2
- package/dist/types/src/hooks/yjs/yjs.test.d.ts.map +0 -1
- package/dist/types/src/testing/index.d.ts +0 -3
- package/dist/types/src/testing/index.d.ts.map +0 -1
- package/dist/types/src/testing/proto/gen/schema.d.ts +0 -15
- package/dist/types/src/testing/proto/gen/schema.d.ts.map +0 -1
- package/dist/types/src/testing/proto/index.d.ts +0 -2
- package/dist/types/src/testing/proto/index.d.ts.map +0 -1
- package/dist/types/src/testing/replicator.d.ts +0 -45
- package/dist/types/src/testing/replicator.d.ts.map +0 -1
- package/src/components/TextEditor/codemirror.stories.ts +0 -114
- package/src/components/TextEditor/extensions/code.ts +0 -99
- package/src/components/TextEditor/extensions/comments.ts +0 -388
- package/src/components/TextEditor/extensions/hr.ts +0 -74
- package/src/components/TextEditor/extensions/image.ts +0 -69
- package/src/components/TextEditor/extensions/listener.ts +0 -23
- package/src/components/TextEditor/extensions/markdown/index.ts +0 -6
- package/src/components/TextEditor/extensions/mermaid.ts +0 -11
- package/src/components/TextEditor/extensions/tasklist.ts +0 -121
- package/src/components/TextEditor/extensions/tooltip.ts +0 -61
- package/src/components/TextEditor/extensions/util.ts +0 -18
- package/src/hooks/automerge/handle.ts +0 -14
- package/src/hooks/automerge/index.ts +0 -6
- package/src/hooks/automerge/plugin.ts +0 -134
- package/src/hooks/automerge/semaphore.ts +0 -78
- package/src/hooks/automerge/update-automerge.ts +0 -44
- package/src/hooks/yjs/index.ts +0 -6
- package/src/hooks/yjs/space-provider.ts +0 -126
- package/src/hooks/yjs/yjs.stories.tsx +0 -56
- package/src/hooks/yjs/yjs.test.ts +0 -59
- package/src/testing/index.ts +0 -6
- package/src/testing/proto/gen/schema.ts +0 -49
- package/src/testing/proto/index.ts +0 -5
- package/src/testing/proto/schema.proto +0 -15
- package/src/testing/replicator.ts +0 -189
- /package/dist/types/src/{components/TextEditor/extensions → extensions}/autocomplete.d.ts +0 -0
- /package/dist/types/src/{hooks → extensions}/automerge/update-codemirror.d.ts +0 -0
- /package/dist/types/src/{components/TextEditor/extensions → extensions}/blast.d.ts +0 -0
- /package/dist/types/src/{components/TextEditor/extensions → extensions/markdown}/code.d.ts +0 -0
- /package/dist/types/src/{components/TextEditor/extensions → extensions}/markdown/highlight.d.ts +0 -0
- /package/dist/types/src/{components/TextEditor/extensions → extensions/markdown}/hr.d.ts +0 -0
- /package/dist/types/src/{components/TextEditor/extensions → extensions/markdown}/image.d.ts +0 -0
- /package/dist/types/src/{components/TextEditor/extensions → extensions/markdown}/table.d.ts +0 -0
- /package/dist/types/src/{components/TextEditor/extensions → extensions/markdown}/tasklist.d.ts +0 -0
- /package/dist/types/src/{components/TextEditor/extensions → extensions}/mention.d.ts +0 -0
- /package/dist/types/src/{components/TextEditor/extensions → extensions}/typewriter.d.ts +0 -0
- /package/dist/types/src/{hooks/yjs → styles}/cursors.d.ts +0 -0
- /package/dist/types/src/{components/TextEditor/themes → themes}/index.d.ts +0 -0
- /package/src/{hooks/yjs → styles}/cursors.ts +0 -0
- /package/src/{components/TextEditor/themes → themes}/index.ts +0 -0
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2023 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { type Extension } from '@codemirror/state';
|
|
6
|
-
import { hoverTooltip } from '@codemirror/view';
|
|
7
|
-
|
|
8
|
-
import { tooltipContent } from '@dxos/react-ui-theme';
|
|
9
|
-
|
|
10
|
-
const markdownLinkRegexp = /\[([^\]]+)]\(([^)]+)\)/;
|
|
11
|
-
|
|
12
|
-
export type TooltipOptions = {
|
|
13
|
-
onHover: (el: Element, url: string) => void;
|
|
14
|
-
regexp?: RegExp;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* https://codemirror.net/examples/tooltip
|
|
19
|
-
* https://codemirror.net/docs/ref/#view.hoverTooltip
|
|
20
|
-
* https://github.com/codemirror/view/blob/main/src/tooltip.ts
|
|
21
|
-
*/
|
|
22
|
-
export const tooltip = ({ onHover, regexp = markdownLinkRegexp }: TooltipOptions): Extension =>
|
|
23
|
-
hoverTooltip((view, pos) => {
|
|
24
|
-
const { from, text } = view.state.doc.lineAt(pos);
|
|
25
|
-
const p = pos - from;
|
|
26
|
-
|
|
27
|
-
let idx = 0;
|
|
28
|
-
let match;
|
|
29
|
-
do {
|
|
30
|
-
match = text.substring(idx).match(regexp);
|
|
31
|
-
if (!match) {
|
|
32
|
-
match = undefined;
|
|
33
|
-
break;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
idx = text.indexOf(match[0]);
|
|
37
|
-
if (p >= idx && p < idx + match[0].length) {
|
|
38
|
-
break;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
idx += match[0].length;
|
|
42
|
-
} while (true);
|
|
43
|
-
|
|
44
|
-
if (!match) {
|
|
45
|
-
return null;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const [, , url] = match ?? [];
|
|
49
|
-
|
|
50
|
-
return {
|
|
51
|
-
pos: idx + from,
|
|
52
|
-
end: idx + from + match[0].length,
|
|
53
|
-
above: true,
|
|
54
|
-
create: () => {
|
|
55
|
-
const el = document.createElement('div');
|
|
56
|
-
el.className = tooltipContent({}, 'pli-2 plb-1');
|
|
57
|
-
onHover(el, url);
|
|
58
|
-
return { dom: el, offset: { x: 0, y: 4 } };
|
|
59
|
-
},
|
|
60
|
-
};
|
|
61
|
-
});
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2024 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { log } from '@dxos/log';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* CodeMirror callbacks swallow errors so wrap handlers.
|
|
9
|
-
*/
|
|
10
|
-
// TODO(burdon): Figure out how to systematize this.
|
|
11
|
-
export const callbackWrapper = <T extends Function>(fn: T): T =>
|
|
12
|
-
((...args: any[]) => {
|
|
13
|
-
try {
|
|
14
|
-
return fn(...args);
|
|
15
|
-
} catch (error) {
|
|
16
|
-
log.catch(error);
|
|
17
|
-
}
|
|
18
|
-
}) as unknown as T;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2023 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import type * as A from '@dxos/automerge/automerge';
|
|
6
|
-
|
|
7
|
-
export type IDocHandle<T = any> = {
|
|
8
|
-
docSync(): A.Doc<T> | undefined;
|
|
9
|
-
change(callback: A.ChangeFn<T>, options?: A.ChangeOptions<T>): void;
|
|
10
|
-
changeAt(heads: A.Heads, callback: A.ChangeFn<T>, options?: A.ChangeOptions<T>): string[] | undefined;
|
|
11
|
-
|
|
12
|
-
addListener(event: 'change', listener: () => void): void;
|
|
13
|
-
removeListener(event: 'change', listener: () => void): void;
|
|
14
|
-
};
|
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2023 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
Annotation,
|
|
7
|
-
type EditorState,
|
|
8
|
-
type Extension,
|
|
9
|
-
Facet,
|
|
10
|
-
StateEffect,
|
|
11
|
-
StateField,
|
|
12
|
-
type Transaction,
|
|
13
|
-
type TransactionSpec,
|
|
14
|
-
} from '@codemirror/state';
|
|
15
|
-
import { ViewPlugin, type EditorView, type PluginValue, type ViewUpdate } from '@codemirror/view';
|
|
16
|
-
|
|
17
|
-
import * as automerge from '@dxos/automerge/automerge';
|
|
18
|
-
import { type Heads, type Prop } from '@dxos/automerge/automerge';
|
|
19
|
-
|
|
20
|
-
import { type IDocHandle } from './handle';
|
|
21
|
-
import { PatchSemaphore } from './semaphore';
|
|
22
|
-
|
|
23
|
-
export type Value = {
|
|
24
|
-
lastHeads: Heads;
|
|
25
|
-
path: Prop[];
|
|
26
|
-
unreconciledTransactions: Transaction[];
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
type UpdateHeads = {
|
|
30
|
-
newHeads: Heads;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export const effectType = StateEffect.define<UpdateHeads>({});
|
|
34
|
-
|
|
35
|
-
export const updateHeads = (newHeads: Heads): StateEffect<UpdateHeads> => effectType.of({ newHeads });
|
|
36
|
-
|
|
37
|
-
export const getLastHeads = (state: EditorState, field: Field): Heads => state.field(field).lastHeads;
|
|
38
|
-
|
|
39
|
-
export const getPath = (state: EditorState, field: Field): Prop[] => state.field(field).path;
|
|
40
|
-
|
|
41
|
-
export type Field = StateField<Value>;
|
|
42
|
-
|
|
43
|
-
const semaphoreFacet = Facet.define<PatchSemaphore, PatchSemaphore>({
|
|
44
|
-
combine: (values) => values.at(-1)!, // Take last.
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
export type AutomergePlugin = {
|
|
48
|
-
extension: Extension;
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
export const automergePlugin = (handle: IDocHandle, path: Prop[]): AutomergePlugin => {
|
|
52
|
-
const stateField: StateField<Value> = StateField.define({
|
|
53
|
-
create: () => ({
|
|
54
|
-
lastHeads: automerge.getHeads(handle.docSync()!),
|
|
55
|
-
unreconciledTransactions: [],
|
|
56
|
-
path: path.slice(),
|
|
57
|
-
}),
|
|
58
|
-
update: (value: Value, tr: Transaction) => {
|
|
59
|
-
const result: Value = {
|
|
60
|
-
lastHeads: value.lastHeads,
|
|
61
|
-
unreconciledTransactions: value.unreconciledTransactions.slice(),
|
|
62
|
-
path: path.slice(),
|
|
63
|
-
};
|
|
64
|
-
let clearUnreconciled = false;
|
|
65
|
-
for (const effect of tr.effects) {
|
|
66
|
-
if (effect.is(effectType)) {
|
|
67
|
-
result.lastHeads = effect.value.newHeads;
|
|
68
|
-
clearUnreconciled = true;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
if (clearUnreconciled) {
|
|
72
|
-
result.unreconciledTransactions = [];
|
|
73
|
-
} else {
|
|
74
|
-
if (!isReconcileTx(tr)) {
|
|
75
|
-
result.unreconciledTransactions.push(tr);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
return result;
|
|
79
|
-
},
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
const semaphore = new PatchSemaphore(stateField);
|
|
83
|
-
|
|
84
|
-
const viewPlugin = ViewPlugin.fromClass(
|
|
85
|
-
class AutomergeCodemirrorViewPlugin implements PluginValue {
|
|
86
|
-
private _view: EditorView;
|
|
87
|
-
|
|
88
|
-
constructor(view: EditorView) {
|
|
89
|
-
this._view = view;
|
|
90
|
-
handle.addListener('change', this._handleChange);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
update(update: ViewUpdate) {
|
|
94
|
-
if (update.transactions.length > 0 && update.transactions.some((t) => !isReconcileTx(t))) {
|
|
95
|
-
queueMicrotask(() => {
|
|
96
|
-
this._view.state.facet(semaphoreFacet).reconcile(handle, this._view);
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
destroy() {
|
|
102
|
-
handle.addListener('change', this._handleChange);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
private _handleChange = () => {
|
|
106
|
-
this._view.state.facet(semaphoreFacet).reconcile(handle, this._view);
|
|
107
|
-
};
|
|
108
|
-
},
|
|
109
|
-
);
|
|
110
|
-
|
|
111
|
-
return {
|
|
112
|
-
extension: [stateField, semaphoreFacet.of(semaphore), viewPlugin],
|
|
113
|
-
};
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
export const reconcileAnnotationType = Annotation.define<unknown>();
|
|
117
|
-
|
|
118
|
-
export const isReconcileTx = (tr: Transaction): boolean => !!tr.annotation(reconcileAnnotationType);
|
|
119
|
-
|
|
120
|
-
export const makeReconcile = (tr: TransactionSpec) => {
|
|
121
|
-
if (tr.annotations != null) {
|
|
122
|
-
if (tr.annotations instanceof Array) {
|
|
123
|
-
tr.annotations = [...tr.annotations, reconcileAnnotationType.of({})];
|
|
124
|
-
} else {
|
|
125
|
-
tr.annotations = [tr.annotations, reconcileAnnotationType.of({})];
|
|
126
|
-
}
|
|
127
|
-
} else {
|
|
128
|
-
tr.annotations = [reconcileAnnotationType.of({})];
|
|
129
|
-
}
|
|
130
|
-
// return {
|
|
131
|
-
// ...tr,
|
|
132
|
-
// annotations: reconcileAnnotationType.of({})
|
|
133
|
-
// }
|
|
134
|
-
};
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2023 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
// TODO(burdon): Additional copyright?
|
|
6
|
-
|
|
7
|
-
import { type EditorView } from '@codemirror/view';
|
|
8
|
-
|
|
9
|
-
import { next as automerge } from '@dxos/automerge/automerge';
|
|
10
|
-
|
|
11
|
-
import { type IDocHandle } from './handle';
|
|
12
|
-
import { type Field, isReconcileTx, getPath, reconcileAnnotationType, updateHeads, getLastHeads } from './plugin';
|
|
13
|
-
import { updateAutomerge } from './update-automerge';
|
|
14
|
-
import { updateCodeMirror } from './update-codemirror';
|
|
15
|
-
|
|
16
|
-
type Doc<T> = automerge.Doc<T>;
|
|
17
|
-
type Heads = automerge.Heads;
|
|
18
|
-
|
|
19
|
-
type ChangeFn = (atHeads: Heads, change: (doc: Doc<unknown>) => void) => Heads | undefined;
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* TODO(burdon): Comment.
|
|
23
|
-
*/
|
|
24
|
-
export class PatchSemaphore {
|
|
25
|
-
_field!: Field;
|
|
26
|
-
_inReconcile = false;
|
|
27
|
-
_queue: Array<ChangeFn> = [];
|
|
28
|
-
|
|
29
|
-
constructor(field?: Field) {
|
|
30
|
-
if (field !== undefined) {
|
|
31
|
-
this._field = field;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
reconcile = (handle: IDocHandle, view: EditorView) => {
|
|
36
|
-
if (this._inReconcile) {
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
this._inReconcile = true;
|
|
40
|
-
|
|
41
|
-
const path = getPath(view.state, this._field);
|
|
42
|
-
const oldHeads = getLastHeads(view.state, this._field);
|
|
43
|
-
let selection = view.state.selection;
|
|
44
|
-
|
|
45
|
-
const transactions = view.state.field(this._field).unreconciledTransactions.filter((tx) => !isReconcileTx(tx));
|
|
46
|
-
|
|
47
|
-
// First undo all the unreconciled transactions.
|
|
48
|
-
const toInvert = transactions.slice().reverse();
|
|
49
|
-
for (const tx of toInvert) {
|
|
50
|
-
const inverted = tx.changes.invert(tx.startState.doc);
|
|
51
|
-
selection = selection.map(inverted);
|
|
52
|
-
view.dispatch({
|
|
53
|
-
changes: inverted,
|
|
54
|
-
annotations: reconcileAnnotationType.of(true),
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// Apply the unreconciled transactions to the document.
|
|
59
|
-
let newHeads = updateAutomerge(this._field, handle, transactions, view.state);
|
|
60
|
-
|
|
61
|
-
// NOTE: null and undefined each come from automerge and repo respectively.
|
|
62
|
-
if (newHeads === null || newHeads === undefined) {
|
|
63
|
-
// TODO: @alexjg this is the call that's resetting the editor state on click
|
|
64
|
-
newHeads = automerge.getHeads(handle.docSync()!);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// Now get the diff between the updated state of the document and the heads and apply that to the codemirror doc.
|
|
68
|
-
const diff = automerge.equals(oldHeads, newHeads) ? [] : automerge.diff(handle.docSync()!, oldHeads, newHeads);
|
|
69
|
-
updateCodeMirror(view, selection, path, diff);
|
|
70
|
-
|
|
71
|
-
view.dispatch({
|
|
72
|
-
effects: updateHeads(newHeads),
|
|
73
|
-
annotations: reconcileAnnotationType.of({}),
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
this._inReconcile = false;
|
|
77
|
-
};
|
|
78
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2023 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
// TODO(burdon): Additional copyright?
|
|
6
|
-
|
|
7
|
-
import { type EditorState, type Text, type Transaction } from '@codemirror/state';
|
|
8
|
-
|
|
9
|
-
import { next as am, type Heads } from '@dxos/automerge/automerge';
|
|
10
|
-
|
|
11
|
-
import { type IDocHandle } from './handle';
|
|
12
|
-
import { type Field } from './plugin';
|
|
13
|
-
|
|
14
|
-
export const updateAutomerge = (
|
|
15
|
-
field: Field,
|
|
16
|
-
handle: IDocHandle,
|
|
17
|
-
transactions: Transaction[],
|
|
18
|
-
state: EditorState,
|
|
19
|
-
): Heads | undefined => {
|
|
20
|
-
const { lastHeads, path } = state.field(field);
|
|
21
|
-
|
|
22
|
-
// We don't want to call `automerge.updateAt` if there are no changes.
|
|
23
|
-
// Otherwise, later on `automerge.diff` will return empty patches that result in a no-op but still mess up the selection.
|
|
24
|
-
let hasChanges = false;
|
|
25
|
-
for (const tr of transactions) {
|
|
26
|
-
tr.changes.iterChanges(() => {
|
|
27
|
-
hasChanges = true;
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (!hasChanges) {
|
|
32
|
-
return undefined;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const newHeads = handle.changeAt(lastHeads, (doc: am.Doc<unknown>) => {
|
|
36
|
-
for (const tr of transactions) {
|
|
37
|
-
tr.changes.iterChanges((fromA: number, toA: number, _fromB: number, _toB: number, inserted: Text) => {
|
|
38
|
-
am.splice(doc, path, fromA, toA - fromA, inserted.toString());
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
return newHeads ?? undefined;
|
|
44
|
-
};
|
package/src/hooks/yjs/index.ts
DELETED
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2023 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import * as decoding from 'lib0/decoding';
|
|
6
|
-
import * as encoding from 'lib0/encoding';
|
|
7
|
-
import { Observable } from 'lib0/observable';
|
|
8
|
-
import * as awarenessProtocol from 'y-protocols/awareness';
|
|
9
|
-
import { type Doc } from 'yjs';
|
|
10
|
-
|
|
11
|
-
import { log } from '@dxos/log';
|
|
12
|
-
import { type Space } from '@dxos/react-client/echo';
|
|
13
|
-
import { type GossipMessage } from '@dxos/react-client/mesh';
|
|
14
|
-
|
|
15
|
-
type Awareness = awarenessProtocol.Awareness;
|
|
16
|
-
|
|
17
|
-
// Based on https://github.com/yjs/y-webrtc/blob/88baab2/src/y-webrtc.js.
|
|
18
|
-
|
|
19
|
-
const messageAwareness = 1;
|
|
20
|
-
const messageQueryAwareness = 3;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Yjs awareness provider on top of a DXOS space.
|
|
24
|
-
*/
|
|
25
|
-
export class SpaceAwarenessProvider extends Observable<any> {
|
|
26
|
-
private readonly _space: Space;
|
|
27
|
-
private readonly _awareness: Awareness;
|
|
28
|
-
private readonly _clientId: number;
|
|
29
|
-
private readonly _channel: string;
|
|
30
|
-
|
|
31
|
-
constructor({ space, doc, channel, awareness }: { space: Space; doc: Doc; channel: string; awareness?: Awareness }) {
|
|
32
|
-
super();
|
|
33
|
-
this._space = space;
|
|
34
|
-
this._awareness = awareness ?? new awarenessProtocol.Awareness(doc);
|
|
35
|
-
this._channel = channel;
|
|
36
|
-
this._clientId = doc.clientID;
|
|
37
|
-
|
|
38
|
-
this._awareness.on('update', this._handleAwarenessUpdate.bind(this));
|
|
39
|
-
this._space.listen(this._channel, this._handleSpaceMessage.bind(this));
|
|
40
|
-
|
|
41
|
-
if (typeof window !== 'undefined') {
|
|
42
|
-
window.addEventListener('beforeunload', this._handleBeforeUnload.bind(this));
|
|
43
|
-
} else if (typeof process !== 'undefined') {
|
|
44
|
-
process.on('exit', this._handleBeforeUnload.bind(this));
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
// Post queryAwareness.
|
|
48
|
-
const encoderAwarenessQuery = encoding.createEncoder();
|
|
49
|
-
encoding.writeVarUint(encoderAwarenessQuery, messageQueryAwareness);
|
|
50
|
-
void this._space.postMessage(this._channel, encoding.toUint8Array(encoderAwarenessQuery));
|
|
51
|
-
|
|
52
|
-
// Post local awareness state.
|
|
53
|
-
const encoderAwarenessState = encoding.createEncoder();
|
|
54
|
-
encoding.writeVarUint(encoderAwarenessState, messageAwareness);
|
|
55
|
-
encoding.writeVarUint8Array(
|
|
56
|
-
encoderAwarenessState,
|
|
57
|
-
awarenessProtocol.encodeAwarenessUpdate(this.awareness, [this._clientId]),
|
|
58
|
-
);
|
|
59
|
-
void this._space.postMessage(this._channel, encoding.toUint8Array(encoderAwarenessState));
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
get awareness(): Awareness {
|
|
63
|
-
return this._awareness;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
private _handleAwarenessUpdate({ added, updated, removed }: any, origin: any) {
|
|
67
|
-
log('awareness update', { added, updated, removed, origin });
|
|
68
|
-
const changedClients = added.concat(updated).concat(removed);
|
|
69
|
-
const encoderAwareness = encoding.createEncoder();
|
|
70
|
-
encoding.writeVarUint(encoderAwareness, messageAwareness);
|
|
71
|
-
encoding.writeVarUint8Array(
|
|
72
|
-
encoderAwareness,
|
|
73
|
-
awarenessProtocol.encodeAwarenessUpdate(this._awareness, changedClients),
|
|
74
|
-
);
|
|
75
|
-
void this._space.postMessage(this._channel, encoding.toUint8Array(encoderAwareness));
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
private _handleSpaceMessage({ payload }: GossipMessage) {
|
|
79
|
-
log('space message', payload);
|
|
80
|
-
const data = new Uint8Array(Array.from(Object.values(payload)));
|
|
81
|
-
const encoder = this._readMessage(data);
|
|
82
|
-
if (encoder) {
|
|
83
|
-
void this._space.postMessage(this._channel, encoding.toUint8Array(encoder));
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
private _readMessage(message: Uint8Array) {
|
|
88
|
-
const decoder = decoding.createDecoder(message);
|
|
89
|
-
const encoder = encoding.createEncoder();
|
|
90
|
-
const messageType = decoding.readVarUint(decoder);
|
|
91
|
-
|
|
92
|
-
let sendReply = false;
|
|
93
|
-
switch (messageType) {
|
|
94
|
-
case messageAwareness: {
|
|
95
|
-
awarenessProtocol.applyAwarenessUpdate(this._awareness, decoding.readVarUint8Array(decoder), this);
|
|
96
|
-
break;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
case messageQueryAwareness: {
|
|
100
|
-
encoding.writeVarUint(encoder, messageAwareness);
|
|
101
|
-
encoding.writeVarUint8Array(
|
|
102
|
-
encoder,
|
|
103
|
-
awarenessProtocol.encodeAwarenessUpdate(this._awareness, Array.from(this._awareness.getStates().keys())),
|
|
104
|
-
);
|
|
105
|
-
sendReply = true;
|
|
106
|
-
break;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
default: {
|
|
110
|
-
console.error('Invalid message:', messageType);
|
|
111
|
-
return encoder;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
if (!sendReply) {
|
|
116
|
-
// Nothing has been written, no answer created.
|
|
117
|
-
return null;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
return encoder;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
private _handleBeforeUnload() {
|
|
124
|
-
awarenessProtocol.removeAwarenessStates(this._awareness, [this._clientId], 'window unload');
|
|
125
|
-
}
|
|
126
|
-
}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2023 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import '@dxosTheme';
|
|
6
|
-
|
|
7
|
-
import React, { useState } from 'react';
|
|
8
|
-
|
|
9
|
-
import { PublicKey } from '@dxos/react-client';
|
|
10
|
-
import { TextKind } from '@dxos/react-client/echo';
|
|
11
|
-
import { ClientRepeater, textGenerator, useDataGenerator } from '@dxos/react-client/testing';
|
|
12
|
-
import { useId, Input } from '@dxos/react-ui';
|
|
13
|
-
import { withTheme } from '@dxos/storybook-utils';
|
|
14
|
-
|
|
15
|
-
import { MarkdownEditor } from '../../components';
|
|
16
|
-
import { Replicator, useYjsModel } from '../../testing';
|
|
17
|
-
|
|
18
|
-
export default {
|
|
19
|
-
title: 'react-ui-editor/YJS',
|
|
20
|
-
component: MarkdownEditor,
|
|
21
|
-
decorators: [withTheme],
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
const replicator = new Replicator(TextKind.PLAIN);
|
|
25
|
-
|
|
26
|
-
const Story = () => {
|
|
27
|
-
const [generate, setGenerate] = useState(false);
|
|
28
|
-
const generateId = useId('generate');
|
|
29
|
-
|
|
30
|
-
const [id] = useState(PublicKey.random().toHex());
|
|
31
|
-
const model = useYjsModel({ id, replicator });
|
|
32
|
-
|
|
33
|
-
useDataGenerator({
|
|
34
|
-
generator: generate ? textGenerator : undefined,
|
|
35
|
-
options: { text: typeof model?.content !== 'string' ? (model?.content as any) : undefined },
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
return (
|
|
39
|
-
<main className='flex flex-col flex-1 p-4 gap-4'>
|
|
40
|
-
<div id={generateId} className='flex gap-2'>
|
|
41
|
-
<Input.Root>
|
|
42
|
-
<Input.Checkbox checked={generate} onCheckedChange={(checked) => setGenerate(!!checked)} />
|
|
43
|
-
<Input.Label>Start</Input.Label>
|
|
44
|
-
</Input.Root>
|
|
45
|
-
</div>
|
|
46
|
-
<div className='border'>
|
|
47
|
-
<MarkdownEditor model={model} />
|
|
48
|
-
</div>
|
|
49
|
-
</main>
|
|
50
|
-
);
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
export const Default = {
|
|
54
|
-
// TODO(wittjosiah): Decorator for doing this without clients being initialized?
|
|
55
|
-
render: () => <ClientRepeater count={2} Component={Story} />,
|
|
56
|
-
};
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2024 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { effect } from '@preact/signals-react';
|
|
6
|
-
import { expect } from 'chai';
|
|
7
|
-
import * as Y from 'yjs';
|
|
8
|
-
|
|
9
|
-
import { Trigger } from '@dxos/async';
|
|
10
|
-
import { Expando, setGlobalAutomergePreference, TextObject } from '@dxos/echo-schema';
|
|
11
|
-
import { registerSignalFactory } from '@dxos/echo-signals';
|
|
12
|
-
import { describe, test } from '@dxos/test';
|
|
13
|
-
import { type YText } from '@dxos/text-model';
|
|
14
|
-
|
|
15
|
-
describe('YJS', () => {
|
|
16
|
-
// https://docs.yjs.dev/api/shared-types/y.text
|
|
17
|
-
// https://github.com/yjs/yjs?tab=readme-ov-file#relative-positions
|
|
18
|
-
test('absolute position', () => {
|
|
19
|
-
const obj = new TextObject('hello world');
|
|
20
|
-
const index = obj.text.indexOf('world');
|
|
21
|
-
const relPos = Y.encodeRelativePosition(Y.createRelativePositionFromTypeIndex(obj.content as YText, index));
|
|
22
|
-
|
|
23
|
-
{
|
|
24
|
-
const cursor = Y.createAbsolutePositionFromRelativePosition(Y.decodeRelativePosition(relPos), obj.doc!);
|
|
25
|
-
expect(cursor!.index).to.equal(index);
|
|
26
|
-
expect(obj.text.substring(cursor!.index)).to.equal('world');
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
(obj.content as YText).insert(index, 'cruel ');
|
|
30
|
-
expect(obj.text).to.equal('hello cruel world');
|
|
31
|
-
|
|
32
|
-
{
|
|
33
|
-
const cursor = Y.createAbsolutePositionFromRelativePosition(Y.decodeRelativePosition(relPos), obj.doc!);
|
|
34
|
-
expect(cursor!.index).not.to.equal(index);
|
|
35
|
-
expect(obj.text.substring(cursor!.index)).to.equal('world');
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
// TODO(burdon): Test deleting end character.
|
|
40
|
-
|
|
41
|
-
test.skip('effect', async () => {
|
|
42
|
-
setGlobalAutomergePreference(true);
|
|
43
|
-
registerSignalFactory();
|
|
44
|
-
const obj = new Expando({ comments: [] });
|
|
45
|
-
|
|
46
|
-
const trigger = new Trigger();
|
|
47
|
-
const unsubscribe = effect(() => {
|
|
48
|
-
// TODO(burdon): BUG: doesn't work with YJS.
|
|
49
|
-
console.log(obj.comments);
|
|
50
|
-
if (obj.comments.length > 0) {
|
|
51
|
-
trigger.wake();
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
obj.comments.push({ message: 'hello' });
|
|
56
|
-
await trigger.wait();
|
|
57
|
-
unsubscribe();
|
|
58
|
-
});
|
|
59
|
-
});
|
package/src/testing/index.ts
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @generated @dxos/echo-typegen src/testing/proto/schema.proto
|
|
3
|
-
**/
|
|
4
|
-
|
|
5
|
-
import * as dxos_echo_schema from "@dxos/echo-schema";
|
|
6
|
-
|
|
7
|
-
export const types = new dxos_echo_schema.TypeCollection();
|
|
8
|
-
|
|
9
|
-
export type EditorDocumentProps = {
|
|
10
|
-
content: dxos_echo_schema.Text;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export class EditorDocument extends dxos_echo_schema.TypedObject<EditorDocumentProps> {
|
|
14
|
-
declare static readonly schema: dxos_echo_schema.Schema;
|
|
15
|
-
|
|
16
|
-
static filter(
|
|
17
|
-
filter?:
|
|
18
|
-
| Partial<EditorDocumentProps>
|
|
19
|
-
| dxos_echo_schema.OperatorFilter<EditorDocument>
|
|
20
|
-
): dxos_echo_schema.Filter<EditorDocument> {
|
|
21
|
-
return dxos_echo_schema.Filter.typename(
|
|
22
|
-
"dxos.testing.editor.EditorDocument",
|
|
23
|
-
filter
|
|
24
|
-
);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
constructor(
|
|
28
|
-
initValues?: Partial<EditorDocumentProps>,
|
|
29
|
-
opts?: dxos_echo_schema.TypedObjectOptions
|
|
30
|
-
) {
|
|
31
|
-
super({ ...initValues }, { schema: EditorDocument.schema, ...opts });
|
|
32
|
-
}
|
|
33
|
-
declare content: dxos_echo_schema.Text;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
types.registerPrototype(EditorDocument, {
|
|
37
|
-
typename: "dxos.testing.editor.EditorDocument",
|
|
38
|
-
props: [
|
|
39
|
-
{
|
|
40
|
-
id: "content",
|
|
41
|
-
type: 5,
|
|
42
|
-
repeated: false,
|
|
43
|
-
refName: "dxos.schema.Text",
|
|
44
|
-
refModelType: "dxos.org/model/text",
|
|
45
|
-
},
|
|
46
|
-
],
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
types.link();
|