@dxos/react-ui-editor 0.3.11-main.3f845e1 → 0.3.11-main.47875f3
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 +1796 -1376
- 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 +9 -8
- package/dist/types/src/components/TextEditor/MarkdownEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/TextEditor.d.ts +14 -19
- 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/codemirror.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/index.d.ts +0 -2
- package/dist/types/src/components/TextEditor/index.d.ts.map +1 -1
- package/dist/types/src/{hooks/yjs → components/TextEditor}/yjs.stories.d.ts +1 -1
- package/dist/types/src/components/TextEditor/yjs.stories.d.ts.map +1 -0
- 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/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 +26 -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/{hooks → extensions}/automerge/semaphore.d.ts +4 -4
- 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.map +1 -0
- package/dist/types/src/extensions/blast.d.ts.map +1 -0
- package/dist/types/src/extensions/code.d.ts.map +1 -0
- package/dist/types/src/{components/TextEditor/extensions → extensions}/comments.d.ts +10 -4
- 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/hr.d.ts.map +1 -0
- package/dist/types/src/extensions/image.d.ts.map +1 -0
- package/dist/types/src/{components/TextEditor/extensions → extensions}/index.d.ts +4 -2
- package/dist/types/src/extensions/index.d.ts.map +1 -0
- package/dist/types/src/{components/TextEditor/extensions → extensions}/link.d.ts +1 -0
- package/dist/types/src/extensions/link.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.map +1 -0
- package/dist/types/src/extensions/markdown/highlight.d.ts.map +1 -0
- package/dist/types/src/extensions/markdown/index.d.ts.map +1 -0
- package/dist/types/src/extensions/mention.d.ts.map +1 -0
- package/dist/types/src/extensions/table.d.ts.map +1 -0
- package/dist/types/src/extensions/tasklist.d.ts +7 -0
- package/dist/types/src/extensions/tasklist.d.ts.map +1 -0
- package/dist/types/src/extensions/typewriter.d.ts.map +1 -0
- package/dist/types/src/extensions/yjs/cursor.d.ts +4 -0
- package/dist/types/src/extensions/yjs/cursor.d.ts.map +1 -0
- package/dist/types/src/extensions/yjs/index.d.ts +2 -0
- package/dist/types/src/extensions/yjs/index.d.ts.map +1 -0
- package/dist/types/src/extensions/yjs/yjs.d.ts +4 -0
- package/dist/types/src/extensions/yjs/yjs.d.ts.map +1 -0
- package/dist/types/src/extensions/yjs/yjs.test.d.ts.map +1 -0
- package/dist/types/src/hooks/automerge.d.ts +3 -0
- package/dist/types/src/hooks/automerge.d.ts.map +1 -0
- package/dist/types/src/hooks/awareness-provider.d.ts +28 -0
- package/dist/types/src/hooks/awareness-provider.d.ts.map +1 -0
- package/dist/types/src/hooks/index.d.ts +2 -0
- package/dist/types/src/hooks/index.d.ts.map +1 -1
- package/dist/types/src/hooks/useTextModel.d.ts +4 -8
- package/dist/types/src/hooks/useTextModel.d.ts.map +1 -1
- package/dist/types/src/hooks/{yjs/space-provider.d.ts → yjs.d.ts} +8 -8
- package/dist/types/src/hooks/yjs.d.ts.map +1 -0
- 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.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/testing/replicator.d.ts +2 -2
- package/dist/types/src/testing/replicator.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.map +1 -0
- package/package.json +25 -23
- package/src/components/TextEditor/MarkdownEditor.stories.tsx +36 -36
- package/src/components/TextEditor/TextEditor.stories.tsx +13 -34
- package/src/components/TextEditor/TextEditor.tsx +74 -70
- package/src/{hooks/automerge → components/TextEditor}/automerge.stories.tsx +66 -6
- package/src/components/TextEditor/codemirror.stories.ts +3 -2
- package/src/components/TextEditor/comments.stories.tsx +329 -0
- package/src/components/TextEditor/index.ts +0 -3
- package/src/{hooks/yjs → components/TextEditor}/yjs.stories.tsx +1 -1
- package/src/{components/TextEditor/extensions → extensions}/autocomplete.ts +18 -17
- package/src/extensions/automerge/automerge.ts +94 -0
- package/src/extensions/automerge/cursor.ts +52 -0
- package/src/extensions/automerge/defs.ts +62 -0
- package/src/extensions/automerge/index.ts +6 -0
- package/src/{hooks → extensions}/automerge/semaphore.ts +14 -12
- package/src/{hooks → extensions}/automerge/update-automerge.ts +5 -6
- package/src/{hooks → extensions}/automerge/update-codemirror.ts +13 -5
- package/src/extensions/awareness.ts +309 -0
- package/src/{components/TextEditor/extensions → extensions}/code.ts +14 -7
- package/src/{components/TextEditor/extensions → extensions}/comments.ts +116 -114
- package/src/extensions/cursor.ts +46 -0
- package/src/{components/TextEditor/extensions → extensions}/hr.ts +4 -5
- package/src/extensions/image.ts +87 -0
- package/src/{components/TextEditor/extensions → extensions}/index.ts +4 -2
- package/src/{components/TextEditor/extensions → extensions}/link.ts +116 -62
- package/src/extensions/listener.ts +35 -0
- package/src/{components/TextEditor/extensions → extensions}/markdown/highlight.ts +4 -13
- package/src/{components/TextEditor/extensions → extensions}/table.ts +10 -4
- package/src/extensions/tasklist.ts +95 -0
- package/src/{components/TextEditor/extensions → extensions}/typewriter.ts +1 -1
- package/src/extensions/yjs/cursor.ts +22 -0
- package/src/extensions/yjs/index.ts +5 -0
- package/src/{hooks → extensions}/yjs/yjs.test.ts +2 -26
- package/src/extensions/yjs/yjs.ts +16 -0
- package/src/hooks/automerge.ts +52 -0
- package/src/hooks/awareness-provider.ts +120 -0
- package/src/hooks/index.ts +2 -0
- package/src/hooks/useTextModel.ts +20 -96
- package/src/hooks/{yjs/space-provider.ts → yjs.ts} +49 -19
- package/src/index.ts +5 -0
- package/src/styles/index.ts +1 -0
- package/src/styles/markdown.ts +0 -2
- package/src/styles/tokens.ts +3 -0
- package/src/testing/replicator.ts +10 -15
- package/src/{components/TextEditor/themes → themes}/default.ts +52 -79
- package/dist/types/src/components/TextEditor/extensions/autocomplete.d.ts.map +0 -1
- 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.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.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.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.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 +0 -3
- 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.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.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.map +0 -1
- package/dist/types/src/hooks/yjs/yjs.stories.d.ts.map +0 -1
- package/dist/types/src/hooks/yjs/yjs.test.d.ts.map +0 -1
- package/src/components/TextEditor/extensions/image.ts +0 -69
- package/src/components/TextEditor/extensions/listener.ts +0 -23
- 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/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/yjs/index.ts +0 -6
- /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}/basic.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}/code.d.ts +0 -0
- /package/dist/types/src/{components/TextEditor/extensions → extensions}/hr.d.ts +0 -0
- /package/dist/types/src/{components/TextEditor/extensions → extensions}/image.d.ts +0 -0
- /package/dist/types/src/{components/TextEditor/extensions → extensions}/markdown/bundle.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/index.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}/table.d.ts +0 -0
- /package/dist/types/src/{components/TextEditor/extensions → extensions}/typewriter.d.ts +0 -0
- /package/dist/types/src/{hooks → extensions}/yjs/yjs.test.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/dist/types/src/{components/TextEditor/extensions/util.d.ts → util.d.ts} +0 -0
- /package/src/{components/TextEditor/extensions → extensions}/basic.ts +0 -0
- /package/src/{components/TextEditor/extensions → extensions}/blast.ts +0 -0
- /package/src/{components/TextEditor/extensions → extensions}/markdown/bundle.ts +0 -0
- /package/src/{components/TextEditor/extensions → extensions}/markdown/index.ts +0 -0
- /package/src/{components/TextEditor/extensions → extensions}/mention.ts +0 -0
- /package/src/{hooks/yjs → styles}/cursors.ts +0 -0
- /package/src/{components/TextEditor/themes → themes}/index.ts +0 -0
- /package/src/{components/TextEditor/extensions/util.ts → util.ts} +0 -0
|
@@ -5,774 +5,939 @@ import { Doc, YText, YXmlFragment } from "@dxos/text-model";
|
|
|
5
5
|
// packages/ui/react-ui-editor/src/components/TextEditor/index.ts
|
|
6
6
|
import { tags as tags2 } from "@lezer/highlight";
|
|
7
7
|
|
|
8
|
-
// packages/ui/react-ui-editor/src/components/TextEditor/
|
|
8
|
+
// packages/ui/react-ui-editor/src/components/TextEditor/TextEditor.tsx
|
|
9
|
+
import { EditorState as EditorState2 } from "@codemirror/state";
|
|
10
|
+
import { EditorView as EditorView12 } from "@codemirror/view";
|
|
11
|
+
import { useFocusableGroup } from "@fluentui/react-tabster";
|
|
12
|
+
import { vim } from "@replit/codemirror-vim";
|
|
13
|
+
import defaultsDeep2 from "lodash.defaultsdeep";
|
|
14
|
+
import React, { forwardRef, useCallback, useEffect, useImperativeHandle, useState, useRef } from "react";
|
|
15
|
+
import { generateName } from "@dxos/display-name";
|
|
16
|
+
import { useThemeContext } from "@dxos/react-ui";
|
|
17
|
+
import { getColorForValue, inputSurface, mx as mx3 } from "@dxos/react-ui-theme";
|
|
18
|
+
|
|
19
|
+
// packages/ui/react-ui-editor/src/extensions/autocomplete.ts
|
|
9
20
|
import { autocompletion, completionKeymap } from "@codemirror/autocomplete";
|
|
21
|
+
import { markdownLanguage } from "@codemirror/lang-markdown";
|
|
10
22
|
import { keymap } from "@codemirror/view";
|
|
11
23
|
var autocomplete = ({ onSearch }) => {
|
|
12
24
|
return [
|
|
13
25
|
// https://codemirror.net/docs/ref/#view.keymap
|
|
14
26
|
// https://discuss.codemirror.net/t/how-can-i-replace-the-default-autocompletion-keymap-v6/3322
|
|
27
|
+
// TODO(burdon): Set custom keymap.
|
|
15
28
|
keymap.of(completionKeymap),
|
|
16
29
|
// https://codemirror.net/examples/autocompletion
|
|
17
30
|
// https://codemirror.net/docs/ref/#autocomplete.autocompletion
|
|
18
31
|
autocompletion({
|
|
19
|
-
|
|
20
|
-
// defaultKeymap: false,
|
|
32
|
+
defaultKeymap: false,
|
|
21
33
|
// Don't start unless key press.
|
|
22
|
-
activateOnTyping: false
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return {
|
|
32
|
-
from: match.from,
|
|
33
|
-
options: onSearch(match.text.toLowerCase())
|
|
34
|
-
};
|
|
34
|
+
activateOnTyping: false
|
|
35
|
+
}),
|
|
36
|
+
// TODO(burdon): Option to create new page?
|
|
37
|
+
// TODO(burdon): Optional decoration via addToOptions
|
|
38
|
+
markdownLanguage.data.of({
|
|
39
|
+
autocomplete: (context) => {
|
|
40
|
+
const match = context.matchBefore(/\w*/);
|
|
41
|
+
if (!match || match.from === match.to && !context.explicit) {
|
|
42
|
+
return null;
|
|
35
43
|
}
|
|
36
|
-
|
|
44
|
+
return {
|
|
45
|
+
from: match.from,
|
|
46
|
+
options: onSearch(match.text.toLowerCase())
|
|
47
|
+
};
|
|
48
|
+
}
|
|
37
49
|
})
|
|
38
50
|
];
|
|
39
51
|
};
|
|
40
52
|
|
|
41
|
-
// packages/ui/react-ui-editor/src/
|
|
42
|
-
import {
|
|
43
|
-
import {
|
|
44
|
-
import {
|
|
45
|
-
import { drawSelection, EditorView, placeholder } from "@codemirror/view";
|
|
46
|
-
var basicBundle = ({ readonly, themeMode, placeholder: _placeholder }) => [
|
|
47
|
-
EditorView.lineWrapping,
|
|
48
|
-
// TODO(burdon): Compare with minimalSetup.
|
|
49
|
-
// https://codemirror.net/docs/ref/#codemirror.minimalSetup
|
|
50
|
-
bracketMatching(),
|
|
51
|
-
closeBrackets(),
|
|
52
|
-
drawSelection(),
|
|
53
|
-
_placeholder && placeholder(_placeholder),
|
|
54
|
-
// TODO(burdon): Is this required?
|
|
55
|
-
themeMode === "dark" ? syntaxHighlighting(oneDarkHighlightStyle) : syntaxHighlighting(defaultHighlightStyle)
|
|
56
|
-
].filter(Boolean);
|
|
53
|
+
// packages/ui/react-ui-editor/src/extensions/automerge/automerge.ts
|
|
54
|
+
import { Facet as Facet2, StateField } from "@codemirror/state";
|
|
55
|
+
import { ViewPlugin } from "@codemirror/view";
|
|
56
|
+
import { next as A } from "@dxos/automerge/automerge";
|
|
57
57
|
|
|
58
|
-
// packages/ui/react-ui-editor/src/
|
|
59
|
-
import
|
|
60
|
-
import
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
min: 5,
|
|
74
|
-
max: 10
|
|
75
|
-
},
|
|
76
|
-
particleVelocityRange: {
|
|
77
|
-
x: [
|
|
78
|
-
-1,
|
|
79
|
-
1
|
|
80
|
-
],
|
|
81
|
-
y: [
|
|
82
|
-
-3.5,
|
|
83
|
-
-1.5
|
|
84
|
-
]
|
|
58
|
+
// packages/ui/react-ui-editor/src/extensions/automerge/cursor.ts
|
|
59
|
+
import get from "lodash.get";
|
|
60
|
+
import { next as automerge } from "@dxos/automerge/automerge";
|
|
61
|
+
var cursorConverter = (handle, path) => ({
|
|
62
|
+
// TODO(burdon): Handle assoc to associate with a previous character.
|
|
63
|
+
toCursor: (pos) => {
|
|
64
|
+
const doc = handle.docSync();
|
|
65
|
+
if (!doc) {
|
|
66
|
+
return "";
|
|
67
|
+
}
|
|
68
|
+
const value = get(doc, path);
|
|
69
|
+
if (typeof value === "string" && value.length <= pos) {
|
|
70
|
+
return "end";
|
|
71
|
+
}
|
|
72
|
+
return automerge.getCursor(doc, path.slice(), pos);
|
|
85
73
|
},
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
y: y - top
|
|
99
|
-
};
|
|
100
|
-
return {
|
|
101
|
-
element,
|
|
102
|
-
point
|
|
103
|
-
};
|
|
104
|
-
};
|
|
105
|
-
return [
|
|
106
|
-
// Cursor moved.
|
|
107
|
-
EditorView2.updateListener.of((update4) => {
|
|
108
|
-
if (blaster?.node !== update4.view.scrollDOM) {
|
|
109
|
-
if (blaster) {
|
|
110
|
-
blaster.destroy();
|
|
111
|
-
}
|
|
112
|
-
blaster = new Blaster(update4.view.scrollDOM, defaultsDeep({
|
|
113
|
-
particleGravity: 0.2,
|
|
114
|
-
particleShrinkRate: 0.995,
|
|
115
|
-
color: () => [
|
|
116
|
-
100 + Math.random() * 100,
|
|
117
|
-
0,
|
|
118
|
-
0
|
|
119
|
-
]
|
|
120
|
-
}, options, defaultOptions));
|
|
121
|
-
blaster.initialize();
|
|
122
|
-
blaster.start();
|
|
74
|
+
fromCursor: (cursor) => {
|
|
75
|
+
if (cursor === "") {
|
|
76
|
+
return 0;
|
|
77
|
+
}
|
|
78
|
+
const doc = handle.docSync();
|
|
79
|
+
if (!doc) {
|
|
80
|
+
return 0;
|
|
81
|
+
}
|
|
82
|
+
if (cursor === "end") {
|
|
83
|
+
const value = get(doc, path);
|
|
84
|
+
if (typeof value === "string") {
|
|
85
|
+
return value.length;
|
|
123
86
|
} else {
|
|
124
|
-
|
|
125
|
-
}
|
|
126
|
-
const current = update4.state.selection.main.head;
|
|
127
|
-
if (current !== last) {
|
|
128
|
-
last = current;
|
|
129
|
-
const { element, point } = getPoint(update4.view, current - 1);
|
|
130
|
-
if (element && point) {
|
|
131
|
-
blaster.spawn({
|
|
132
|
-
element,
|
|
133
|
-
point
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}),
|
|
138
|
-
keymap2.of([
|
|
139
|
-
{
|
|
140
|
-
any: (_, event) => {
|
|
141
|
-
if (blaster) {
|
|
142
|
-
if (event.key === "Enter" && event.shiftKey) {
|
|
143
|
-
blaster.shake({
|
|
144
|
-
time: 0.8
|
|
145
|
-
});
|
|
146
|
-
return true;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
return false;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
])
|
|
153
|
-
];
|
|
154
|
-
};
|
|
155
|
-
var Blaster = class {
|
|
156
|
-
constructor(_node, _options) {
|
|
157
|
-
this._node = _node;
|
|
158
|
-
this._options = _options;
|
|
159
|
-
this._running = false;
|
|
160
|
-
this._shakeTime = 0;
|
|
161
|
-
this._shakeTimeMax = 0;
|
|
162
|
-
this._particles = [];
|
|
163
|
-
this._particlePointer = 0;
|
|
164
|
-
this._lastPoint = {
|
|
165
|
-
x: 0,
|
|
166
|
-
y: 0
|
|
167
|
-
};
|
|
168
|
-
this.shake = throttle(({ time }) => {
|
|
169
|
-
this._shakeTime = this._shakeTimeMax || time;
|
|
170
|
-
this._shakeTimeMax = time;
|
|
171
|
-
}, 100);
|
|
172
|
-
this.spawn = throttle(({ element, point }) => {
|
|
173
|
-
const color = getRGBComponents(element, this._options.color);
|
|
174
|
-
const numParticles = random(this._options.particleNumRange.min, this._options.particleNumRange.max);
|
|
175
|
-
const dir = this._lastPoint.x === point.x ? 0 : this._lastPoint.x < point.x ? 1 : -1;
|
|
176
|
-
this._lastPoint = point;
|
|
177
|
-
for (let i = numParticles; i--; i > 0) {
|
|
178
|
-
this._particles[this._particlePointer] = this._effect.create(point.x - dir * 16, point.y, color);
|
|
179
|
-
this._particlePointer = (this._particlePointer + 1) % this._options.maxParticles;
|
|
87
|
+
return 0;
|
|
180
88
|
}
|
|
181
|
-
}, 100);
|
|
182
|
-
this._effect = this._options.effect === 1 ? new Effect1(_options) : new Effect2(_options);
|
|
183
|
-
}
|
|
184
|
-
get node() {
|
|
185
|
-
return this._node;
|
|
186
|
-
}
|
|
187
|
-
initialize() {
|
|
188
|
-
invariant(!this._canvas && !this._ctx, void 0, {
|
|
189
|
-
F: __dxlog_file,
|
|
190
|
-
L: 138,
|
|
191
|
-
S: this,
|
|
192
|
-
A: [
|
|
193
|
-
"!this._canvas && !this._ctx",
|
|
194
|
-
""
|
|
195
|
-
]
|
|
196
|
-
});
|
|
197
|
-
this._canvas = document.createElement("canvas");
|
|
198
|
-
this._canvas.id = "code-blast-canvas";
|
|
199
|
-
this._canvas.style.position = "absolute";
|
|
200
|
-
this._canvas.style.zIndex = "0";
|
|
201
|
-
this._canvas.style.pointerEvents = "none";
|
|
202
|
-
this._ctx = this._canvas.getContext("2d");
|
|
203
|
-
const parent = this._node.parentElement?.parentElement;
|
|
204
|
-
parent?.appendChild(this._canvas);
|
|
205
|
-
this.resize();
|
|
206
|
-
}
|
|
207
|
-
destroy() {
|
|
208
|
-
this.stop();
|
|
209
|
-
if (this._canvas) {
|
|
210
|
-
this._canvas.remove();
|
|
211
|
-
this._canvas = void 0;
|
|
212
|
-
this._ctx = void 0;
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
resize() {
|
|
216
|
-
if (this._node.parentElement && this._canvas) {
|
|
217
|
-
const { offsetLeft: x, offsetTop: y, offsetWidth: width, offsetHeight: height } = this._node.parentElement;
|
|
218
|
-
this._canvas.style.top = `${y}px`;
|
|
219
|
-
this._canvas.style.left = `${x}px`;
|
|
220
|
-
this._canvas.width = width;
|
|
221
|
-
this._canvas.height = height;
|
|
222
89
|
}
|
|
90
|
+
return automerge.getCursorPosition(doc, path.slice(), cursor);
|
|
223
91
|
}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
// packages/ui/react-ui-editor/src/extensions/automerge/defs.ts
|
|
95
|
+
import { Annotation, StateEffect } from "@codemirror/state";
|
|
96
|
+
var effectType = StateEffect.define({});
|
|
97
|
+
var updateHeads = (newHeads) => effectType.of({
|
|
98
|
+
newHeads
|
|
99
|
+
});
|
|
100
|
+
var getLastHeads = (state, field) => state.field(field).lastHeads;
|
|
101
|
+
var getPath = (state, field) => state.field(field).path;
|
|
102
|
+
var reconcileAnnotationType = Annotation.define();
|
|
103
|
+
var isReconcileTx = (tr) => !!tr.annotation(reconcileAnnotationType);
|
|
104
|
+
|
|
105
|
+
// packages/ui/react-ui-editor/src/extensions/automerge/semaphore.ts
|
|
106
|
+
import { next as automerge2 } from "@dxos/automerge/automerge";
|
|
107
|
+
|
|
108
|
+
// packages/ui/react-ui-editor/src/extensions/automerge/update-automerge.ts
|
|
109
|
+
import { next as am } from "@dxos/automerge/automerge";
|
|
110
|
+
var updateAutomerge = (field, handle, transactions, state) => {
|
|
111
|
+
const { lastHeads, path } = state.field(field);
|
|
112
|
+
let hasChanges = false;
|
|
113
|
+
for (const tr of transactions) {
|
|
114
|
+
tr.changes.iterChanges(() => {
|
|
115
|
+
hasChanges = true;
|
|
233
116
|
});
|
|
234
|
-
this._running = true;
|
|
235
|
-
this.loop();
|
|
236
117
|
}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
this._node.style.transform = "translate(0px, 0px)";
|
|
118
|
+
if (!hasChanges) {
|
|
119
|
+
return void 0;
|
|
240
120
|
}
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
const now = (/* @__PURE__ */ new Date()).getTime();
|
|
247
|
-
this._lastTime ??= now;
|
|
248
|
-
const dt = (now - this._lastTime) / 1e3;
|
|
249
|
-
this._lastTime = now;
|
|
250
|
-
if (this._shakeTime > 0) {
|
|
251
|
-
this._shakeTime -= dt;
|
|
252
|
-
const magnitude = this._shakeTime / this._shakeTimeMax * this._options.shakeIntensity;
|
|
253
|
-
const shakeX = random(-magnitude, magnitude);
|
|
254
|
-
const shakeY = random(-magnitude, magnitude);
|
|
255
|
-
this._node.style.transform = `translate(${shakeX}px,${shakeY}px)`;
|
|
121
|
+
const newHeads = handle.changeAt(lastHeads, (doc) => {
|
|
122
|
+
for (const tr of transactions) {
|
|
123
|
+
tr.changes.iterChanges((fromA, toA, _fromB, _toB, inserted) => {
|
|
124
|
+
am.splice(doc, path, fromA, toA - fromA, inserted.toString());
|
|
125
|
+
});
|
|
256
126
|
}
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
127
|
+
});
|
|
128
|
+
return newHeads ?? void 0;
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
// packages/ui/react-ui-editor/src/extensions/automerge/update-codemirror.ts
|
|
132
|
+
import { ChangeSet } from "@codemirror/state";
|
|
133
|
+
var updateCodeMirror = (view, selection, target, patches) => {
|
|
134
|
+
for (const patch of patches) {
|
|
135
|
+
const changeSpec = handlePatch(patch, target, view.state);
|
|
136
|
+
if (changeSpec != null) {
|
|
137
|
+
const changeSet = ChangeSet.of(changeSpec, view.state.doc.length, "\n");
|
|
138
|
+
selection = selection.map(changeSet, 1);
|
|
139
|
+
view.dispatch({
|
|
140
|
+
changes: changeSet,
|
|
141
|
+
annotations: reconcileAnnotationType.of({})
|
|
142
|
+
});
|
|
270
143
|
}
|
|
271
144
|
}
|
|
145
|
+
view.dispatch({
|
|
146
|
+
selection,
|
|
147
|
+
annotations: reconcileAnnotationType.of({})
|
|
148
|
+
});
|
|
272
149
|
};
|
|
273
|
-
var
|
|
274
|
-
|
|
275
|
-
|
|
150
|
+
var handlePatch = (patch, target, state) => {
|
|
151
|
+
if (patch.action === "insert") {
|
|
152
|
+
return handleInsert(target, patch);
|
|
153
|
+
} else if (patch.action === "splice") {
|
|
154
|
+
return handleSplice(target, patch);
|
|
155
|
+
} else if (patch.action === "del") {
|
|
156
|
+
return handleDel(target, patch);
|
|
157
|
+
} else if (patch.action === "put") {
|
|
158
|
+
return handlePut(target, patch, state);
|
|
159
|
+
} else {
|
|
160
|
+
return null;
|
|
276
161
|
}
|
|
277
162
|
};
|
|
278
|
-
var
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
y: y + 10,
|
|
283
|
-
vx: random(this._options.particleVelocityRange.x[0], this._options.particleVelocityRange.x[1]),
|
|
284
|
-
vy: random(this._options.particleVelocityRange.y[0], this._options.particleVelocityRange.y[1]),
|
|
285
|
-
size: random(this._options.particleSize.min, this._options.particleSize.max),
|
|
286
|
-
color,
|
|
287
|
-
alpha: 1
|
|
288
|
-
};
|
|
289
|
-
}
|
|
290
|
-
update(ctx, particle) {
|
|
291
|
-
particle.vy += this._options.particleGravity;
|
|
292
|
-
particle.x += particle.vx;
|
|
293
|
-
particle.y += particle.vy;
|
|
294
|
-
particle.alpha *= this._options.particleAlphaFadeout;
|
|
295
|
-
ctx.fillStyle = `rgba(${particle.color[0]},${particle.color[1]},${particle.color[2]},${particle.alpha})`;
|
|
296
|
-
ctx.fillRect(Math.round(particle.x - 1), Math.round(particle.y - 1), particle.size, particle.size);
|
|
163
|
+
var handleInsert = (target, patch) => {
|
|
164
|
+
const index = charPath(target, patch.path);
|
|
165
|
+
if (index == null) {
|
|
166
|
+
return [];
|
|
297
167
|
}
|
|
168
|
+
const text = patch.values.map((v) => v ? v.toString() : "").join("");
|
|
169
|
+
return [
|
|
170
|
+
{
|
|
171
|
+
from: index,
|
|
172
|
+
to: index,
|
|
173
|
+
insert: text
|
|
174
|
+
}
|
|
175
|
+
];
|
|
298
176
|
};
|
|
299
|
-
var
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
y: y + 10,
|
|
304
|
-
vx: random(this._options.particleVelocityRange.x[0], this._options.particleVelocityRange.x[1]),
|
|
305
|
-
vy: random(this._options.particleVelocityRange.y[0], this._options.particleVelocityRange.y[1]),
|
|
306
|
-
size: random(this._options.particleSize.min, this._options.particleSize.max),
|
|
307
|
-
color,
|
|
308
|
-
alpha: 1,
|
|
309
|
-
theta: random(0, 360) * Math.PI / 180,
|
|
310
|
-
drag: 0.92,
|
|
311
|
-
wander: 0.15
|
|
312
|
-
};
|
|
313
|
-
}
|
|
314
|
-
update(ctx, particle) {
|
|
315
|
-
particle.vy += this._options.particleGravity;
|
|
316
|
-
particle.x += particle.vx;
|
|
317
|
-
particle.y += particle.vy;
|
|
318
|
-
particle.vx *= particle.drag;
|
|
319
|
-
particle.vy *= particle.drag;
|
|
320
|
-
particle.theta += random(-0.5, 0.5);
|
|
321
|
-
particle.vx += Math.sin(particle.theta) * 0.1;
|
|
322
|
-
particle.vy += Math.cos(particle.theta) * 0.1;
|
|
323
|
-
particle.size *= this._options.particleShrinkRate;
|
|
324
|
-
particle.alpha *= this._options.particleAlphaFadeout;
|
|
325
|
-
ctx.fillStyle = `rgba(${particle.color[0]},${particle.color[1]},${particle.color[2]},${particle.alpha})`;
|
|
326
|
-
ctx.beginPath();
|
|
327
|
-
ctx.arc(Math.round(particle.x - 1), Math.round(particle.y - 1), particle.size, 0, 2 * Math.PI);
|
|
328
|
-
ctx.fill();
|
|
177
|
+
var handleSplice = (target, patch) => {
|
|
178
|
+
const index = charPath(target, patch.path);
|
|
179
|
+
if (index == null) {
|
|
180
|
+
return [];
|
|
329
181
|
}
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
if (!wait) {
|
|
335
|
-
callback.apply(this, args);
|
|
336
|
-
wait = true;
|
|
337
|
-
setTimeout(() => {
|
|
338
|
-
wait = false;
|
|
339
|
-
}, limit);
|
|
182
|
+
return [
|
|
183
|
+
{
|
|
184
|
+
from: index,
|
|
185
|
+
insert: patch.value
|
|
340
186
|
}
|
|
341
|
-
|
|
342
|
-
}
|
|
343
|
-
var
|
|
344
|
-
|
|
345
|
-
|
|
187
|
+
];
|
|
188
|
+
};
|
|
189
|
+
var handleDel = (target, patch) => {
|
|
190
|
+
const index = charPath(target, patch.path);
|
|
191
|
+
if (index == null) {
|
|
192
|
+
return [];
|
|
346
193
|
}
|
|
347
|
-
const
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
194
|
+
const length = patch.length || 1;
|
|
195
|
+
return [
|
|
196
|
+
{
|
|
197
|
+
from: index,
|
|
198
|
+
to: index + length
|
|
352
199
|
}
|
|
200
|
+
];
|
|
201
|
+
};
|
|
202
|
+
var handlePut = (target, patch, state) => {
|
|
203
|
+
const index = charPath(target, [
|
|
204
|
+
...patch.path,
|
|
205
|
+
0
|
|
206
|
+
]);
|
|
207
|
+
if (index == null) {
|
|
208
|
+
return [];
|
|
209
|
+
}
|
|
210
|
+
const length = state.doc.length;
|
|
211
|
+
if (typeof patch.value !== "string") {
|
|
212
|
+
return [];
|
|
353
213
|
}
|
|
354
214
|
return [
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
215
|
+
{
|
|
216
|
+
from: 0,
|
|
217
|
+
to: length,
|
|
218
|
+
insert: patch.value
|
|
219
|
+
}
|
|
358
220
|
];
|
|
359
221
|
};
|
|
360
|
-
var
|
|
361
|
-
if (
|
|
362
|
-
|
|
363
|
-
min = 0;
|
|
222
|
+
var charPath = (textPath, candidatePath) => {
|
|
223
|
+
if (candidatePath.length !== textPath.length + 1) {
|
|
224
|
+
return null;
|
|
364
225
|
}
|
|
365
|
-
|
|
226
|
+
for (let i = 0; i < textPath.length; i++) {
|
|
227
|
+
if (textPath[i] !== candidatePath[i]) {
|
|
228
|
+
return null;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
const index = candidatePath[candidatePath.length - 1];
|
|
232
|
+
if (typeof index === "number") {
|
|
233
|
+
return index;
|
|
234
|
+
}
|
|
235
|
+
return null;
|
|
366
236
|
};
|
|
367
237
|
|
|
368
|
-
// packages/ui/react-ui-editor/src/
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
238
|
+
// packages/ui/react-ui-editor/src/extensions/automerge/semaphore.ts
|
|
239
|
+
var PatchSemaphore = class {
|
|
240
|
+
constructor(_field) {
|
|
241
|
+
this._field = _field;
|
|
242
|
+
this._inReconcile = false;
|
|
243
|
+
this._queue = [];
|
|
244
|
+
this.reconcile = (handle, view) => {
|
|
245
|
+
if (this._inReconcile) {
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
this._inReconcile = true;
|
|
249
|
+
const path = getPath(view.state, this._field);
|
|
250
|
+
const oldHeads = getLastHeads(view.state, this._field);
|
|
251
|
+
let selection = view.state.selection;
|
|
252
|
+
const transactions = view.state.field(this._field).unreconciledTransactions.filter((tx) => !isReconcileTx(tx));
|
|
253
|
+
const toInvert = transactions.slice().reverse();
|
|
254
|
+
for (const tx of toInvert) {
|
|
255
|
+
const inverted = tx.changes.invert(tx.startState.doc);
|
|
256
|
+
selection = selection.map(inverted);
|
|
257
|
+
view.dispatch({
|
|
258
|
+
changes: inverted,
|
|
259
|
+
annotations: reconcileAnnotationType.of(true)
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
let newHeads = updateAutomerge(this._field, handle, transactions, view.state);
|
|
263
|
+
if (newHeads === null || newHeads === void 0) {
|
|
264
|
+
newHeads = automerge2.getHeads(handle.docSync());
|
|
265
|
+
}
|
|
266
|
+
const diff = automerge2.equals(oldHeads, newHeads) ? [] : automerge2.diff(handle.docSync(), oldHeads, newHeads);
|
|
267
|
+
updateCodeMirror(view, selection, path, diff);
|
|
268
|
+
view.dispatch({
|
|
269
|
+
effects: updateHeads(newHeads),
|
|
270
|
+
annotations: reconcileAnnotationType.of({})
|
|
271
|
+
});
|
|
272
|
+
this._inReconcile = false;
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
};
|
|
372
276
|
|
|
373
|
-
// packages/ui/react-ui-editor/src/
|
|
374
|
-
import {
|
|
375
|
-
var
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
"-ml-[10px]"
|
|
379
|
-
],
|
|
380
|
-
2: [
|
|
381
|
-
"mbs-4 mbe-2 font-medium text-inherit no-underline text-3xl",
|
|
382
|
-
"-ml-[8px]"
|
|
383
|
-
],
|
|
384
|
-
3: [
|
|
385
|
-
"mbs-4 mbe-2 font-medium text-inherit no-underline text-2xl",
|
|
386
|
-
"-ml-[7px]"
|
|
387
|
-
],
|
|
388
|
-
4: [
|
|
389
|
-
"mbs-4 mbe-2 font-medium text-inherit no-underline text-xl",
|
|
390
|
-
"-ml-[6px]"
|
|
391
|
-
],
|
|
392
|
-
5: [
|
|
393
|
-
"mbs-4 mbe-2 font-medium text-inherit no-underline text-lg",
|
|
394
|
-
"-ml-[5px]"
|
|
395
|
-
],
|
|
396
|
-
6: [
|
|
397
|
-
"mbs-4 mbe-2 font-medium text-inherit no-underline",
|
|
398
|
-
"-ml-[4px]"
|
|
399
|
-
]
|
|
277
|
+
// packages/ui/react-ui-editor/src/extensions/cursor.ts
|
|
278
|
+
import { Facet } from "@codemirror/state";
|
|
279
|
+
var defaultCursorConverter = {
|
|
280
|
+
toCursor: (position) => position.toString(),
|
|
281
|
+
fromCursor: (cursor) => parseInt(cursor)
|
|
400
282
|
};
|
|
401
|
-
var
|
|
402
|
-
|
|
403
|
-
|
|
283
|
+
var Cursor = class {
|
|
284
|
+
static {
|
|
285
|
+
this.converter = Facet.define({
|
|
286
|
+
combine: (providers) => providers[0] ?? defaultCursorConverter
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
static {
|
|
290
|
+
this.getCursorFromRange = (cursorConverter3, range) => {
|
|
291
|
+
const from = cursorConverter3.toCursor(range.from);
|
|
292
|
+
const to = cursorConverter3.toCursor(range.to, -1);
|
|
293
|
+
return [
|
|
294
|
+
from,
|
|
295
|
+
to
|
|
296
|
+
].join(":");
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
static {
|
|
300
|
+
this.getRangeFromCursor = (cursorConverter3, cursor) => {
|
|
301
|
+
const parts = cursor.split(":");
|
|
302
|
+
const from = cursorConverter3.fromCursor(parts[0]);
|
|
303
|
+
const to = cursorConverter3.fromCursor(parts[1]);
|
|
304
|
+
return from !== void 0 && to !== void 0 ? {
|
|
305
|
+
from,
|
|
306
|
+
to
|
|
307
|
+
} : void 0;
|
|
308
|
+
};
|
|
309
|
+
}
|
|
404
310
|
};
|
|
405
|
-
var light = "text-neutral-200 dark:text-neutral-800";
|
|
406
|
-
var mark = mx("!font-normal !no-underline !text-inherit opacity-40", light);
|
|
407
|
-
var bold = "font-bold";
|
|
408
|
-
var italic = "italic";
|
|
409
|
-
var strikethrough = "line-through";
|
|
410
|
-
var code = "font-mono !no-underline text-neutral-700 dark:text-neutral-300";
|
|
411
|
-
var codeMark = "font-mono text-primary-500";
|
|
412
|
-
var inlineUrl = mx(code, "px-1");
|
|
413
|
-
var blockquote = mx("pl-1 mr-1 border-is-4 border-primary-500/70 dark:border-primary-500/30", light);
|
|
414
|
-
|
|
415
|
-
// packages/ui/react-ui-editor/src/styles/tokens.ts
|
|
416
|
-
import { tailwindConfig } from "@dxos/react-ui-theme";
|
|
417
|
-
var tokens = tailwindConfig({}).theme;
|
|
418
311
|
|
|
419
|
-
// packages/ui/react-ui-editor/src/
|
|
420
|
-
var
|
|
421
|
-
|
|
422
|
-
"& .cm-codeblock": {
|
|
423
|
-
fontFamily: get(tokens, "fontFamily.mono", []).join(",")
|
|
424
|
-
},
|
|
425
|
-
'&light [aria-readonly="true"] .cm-codeblock': {
|
|
426
|
-
background: get(tokens, "extend.colors.neutral.50")
|
|
427
|
-
},
|
|
428
|
-
'&dark [aria-readonly="true"] .cm-codeblock': {
|
|
429
|
-
background: get(tokens, "extend.colors.neutral.850")
|
|
430
|
-
},
|
|
431
|
-
'& [aria-readonly="true"] .cm-codeblock': {
|
|
432
|
-
display: "block",
|
|
433
|
-
paddingInline: "4px !important"
|
|
434
|
-
},
|
|
435
|
-
'& [aria-readonly="true"] .cm-codeblock-first': {
|
|
436
|
-
paddingTop: "4px !important",
|
|
437
|
-
borderTopLeftRadius: "4px",
|
|
438
|
-
borderTopRightRadius: "4px"
|
|
439
|
-
},
|
|
440
|
-
'& [aria-readonly="true"] .cm-codeblock-last': {
|
|
441
|
-
paddingBottom: "4px !important",
|
|
442
|
-
borderBottomLeftRadius: "4px",
|
|
443
|
-
borderBottomRightRadius: "4px"
|
|
444
|
-
}
|
|
312
|
+
// packages/ui/react-ui-editor/src/extensions/automerge/automerge.ts
|
|
313
|
+
var semaphoreFacet = Facet2.define({
|
|
314
|
+
combine: (values) => values.at(-1)
|
|
445
315
|
});
|
|
446
|
-
var
|
|
447
|
-
const
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
const
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
316
|
+
var automerge3 = ({ handle, path }) => {
|
|
317
|
+
const stateField = StateField.define({
|
|
318
|
+
create: () => ({
|
|
319
|
+
lastHeads: A.getHeads(handle.docSync()),
|
|
320
|
+
unreconciledTransactions: [],
|
|
321
|
+
path: path.slice()
|
|
322
|
+
}),
|
|
323
|
+
update: (value, tr) => {
|
|
324
|
+
const result = {
|
|
325
|
+
lastHeads: value.lastHeads,
|
|
326
|
+
unreconciledTransactions: value.unreconciledTransactions.slice(),
|
|
327
|
+
path: path.slice()
|
|
328
|
+
};
|
|
329
|
+
let clearUnreconciled = false;
|
|
330
|
+
for (const effect of tr.effects) {
|
|
331
|
+
if (effect.is(effectType)) {
|
|
332
|
+
result.lastHeads = effect.value.newHeads;
|
|
333
|
+
clearUnreconciled = true;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
if (clearUnreconciled) {
|
|
337
|
+
result.unreconciledTransactions = [];
|
|
338
|
+
} else {
|
|
339
|
+
if (!isReconcileTx(tr)) {
|
|
340
|
+
result.unreconciledTransactions.push(tr);
|
|
468
341
|
}
|
|
469
342
|
}
|
|
343
|
+
return result;
|
|
344
|
+
}
|
|
345
|
+
});
|
|
346
|
+
const semaphore = new PatchSemaphore(stateField);
|
|
347
|
+
const viewPlugin = ViewPlugin.fromClass(class AutomergeCodemirrorViewPlugin {
|
|
348
|
+
constructor(_view) {
|
|
349
|
+
this._view = _view;
|
|
350
|
+
this._handleChange = () => {
|
|
351
|
+
this._view.state.facet(semaphoreFacet).reconcile(handle, this._view);
|
|
352
|
+
};
|
|
353
|
+
handle.addListener("change", this._handleChange);
|
|
354
|
+
}
|
|
355
|
+
update(update2) {
|
|
356
|
+
if (update2.transactions.length > 0 && update2.transactions.some((tr) => !isReconcileTx(tr))) {
|
|
357
|
+
queueMicrotask(() => {
|
|
358
|
+
this._view.state.facet(semaphoreFacet).reconcile(handle, this._view);
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
destroy() {
|
|
363
|
+
handle.addListener("change", this._handleChange);
|
|
470
364
|
}
|
|
471
|
-
|
|
365
|
+
});
|
|
366
|
+
return {
|
|
367
|
+
extension: [
|
|
368
|
+
Cursor.converter.of(cursorConverter(handle, path)),
|
|
369
|
+
semaphoreFacet.of(semaphore),
|
|
370
|
+
stateField,
|
|
371
|
+
viewPlugin
|
|
372
|
+
]
|
|
472
373
|
};
|
|
374
|
+
};
|
|
375
|
+
|
|
376
|
+
// packages/ui/react-ui-editor/src/extensions/awareness.ts
|
|
377
|
+
import { Annotation as Annotation2, Facet as Facet3, RangeSet } from "@codemirror/state";
|
|
378
|
+
import { Decoration, EditorView, ViewPlugin as ViewPlugin2, WidgetType } from "@codemirror/view";
|
|
379
|
+
import { Event } from "@dxos/async";
|
|
380
|
+
import { Context } from "@dxos/context";
|
|
381
|
+
var dummyProvider = {
|
|
382
|
+
remoteStateChange: new Event(),
|
|
383
|
+
open: () => {
|
|
384
|
+
},
|
|
385
|
+
close: () => {
|
|
386
|
+
},
|
|
387
|
+
update: () => {
|
|
388
|
+
},
|
|
389
|
+
getRemoteStates: () => []
|
|
390
|
+
};
|
|
391
|
+
var AwarenessProvider = Facet3.define({
|
|
392
|
+
combine: (providers) => providers[0] ?? dummyProvider
|
|
393
|
+
});
|
|
394
|
+
var RemoteSelectionChangedAnnotation = Annotation2.define();
|
|
395
|
+
var awareness = (provider = dummyProvider) => {
|
|
473
396
|
return [
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
this.decorations = getDecorations(view);
|
|
477
|
-
}
|
|
478
|
-
update(update4) {
|
|
479
|
-
if (update4.docChanged || update4.viewportChanged) {
|
|
480
|
-
this.decorations = getDecorations(update4.view);
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
}, {
|
|
397
|
+
AwarenessProvider.of(provider),
|
|
398
|
+
ViewPlugin2.fromClass(RemoteSelectionsDecorator, {
|
|
484
399
|
decorations: (value) => value.decorations
|
|
485
400
|
}),
|
|
486
401
|
styles
|
|
487
402
|
];
|
|
488
403
|
};
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
return fn(...args);
|
|
505
|
-
} catch (error) {
|
|
506
|
-
log.catch(error, void 0, {
|
|
507
|
-
F: __dxlog_file2,
|
|
508
|
-
L: 16,
|
|
509
|
-
S: void 0,
|
|
510
|
-
C: (f, a) => f(...a)
|
|
404
|
+
var RemoteSelectionsDecorator = class {
|
|
405
|
+
constructor(view) {
|
|
406
|
+
this.decorations = RangeSet.of([]);
|
|
407
|
+
this._ctx = new Context();
|
|
408
|
+
this._lastAnchor = void 0;
|
|
409
|
+
this._lastHead = void 0;
|
|
410
|
+
this._cursorConverter = view.state.facet(Cursor.converter);
|
|
411
|
+
this._provider = view.state.facet(AwarenessProvider);
|
|
412
|
+
this._provider.open();
|
|
413
|
+
this._provider.remoteStateChange.on(this._ctx, () => {
|
|
414
|
+
view.dispatch({
|
|
415
|
+
annotations: [
|
|
416
|
+
RemoteSelectionChangedAnnotation.of([])
|
|
417
|
+
]
|
|
418
|
+
});
|
|
511
419
|
});
|
|
512
420
|
}
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
import { StateField as StateField2 } from "@codemirror/state";
|
|
517
|
-
import get2 from "lodash.get";
|
|
518
|
-
import { useEffect, useState } from "react";
|
|
519
|
-
import { yCollab } from "y-codemirror.next";
|
|
520
|
-
import * as Y from "yjs";
|
|
521
|
-
import { invariant as invariant2 } from "@dxos/invariant";
|
|
522
|
-
import { getRawDoc, isActualAutomergeObject } from "@dxos/react-client/echo";
|
|
523
|
-
import { arrayToString, stringToArray } from "@dxos/util";
|
|
524
|
-
|
|
525
|
-
// packages/ui/react-ui-editor/src/hooks/automerge/plugin.ts
|
|
526
|
-
import { Annotation, Facet, StateEffect, StateField } from "@codemirror/state";
|
|
527
|
-
import { ViewPlugin as ViewPlugin2 } from "@codemirror/view";
|
|
528
|
-
import * as automerge2 from "@dxos/automerge/automerge";
|
|
529
|
-
|
|
530
|
-
// packages/ui/react-ui-editor/src/hooks/automerge/semaphore.ts
|
|
531
|
-
import { next as automerge } from "@dxos/automerge/automerge";
|
|
532
|
-
|
|
533
|
-
// packages/ui/react-ui-editor/src/hooks/automerge/update-automerge.ts
|
|
534
|
-
import { next as am } from "@dxos/automerge/automerge";
|
|
535
|
-
var updateAutomerge = (field, handle, transactions, state) => {
|
|
536
|
-
const { lastHeads, path } = state.field(field);
|
|
537
|
-
let hasChanges = false;
|
|
538
|
-
for (const tr of transactions) {
|
|
539
|
-
tr.changes.iterChanges(() => {
|
|
540
|
-
hasChanges = true;
|
|
541
|
-
});
|
|
421
|
+
destroy() {
|
|
422
|
+
void this._ctx.dispose();
|
|
423
|
+
this._provider.close();
|
|
542
424
|
}
|
|
543
|
-
|
|
544
|
-
|
|
425
|
+
update(update2) {
|
|
426
|
+
this._updateLocalSelection(update2);
|
|
427
|
+
this._updateRemoteSelections(update2);
|
|
545
428
|
}
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
429
|
+
_updateLocalSelection(update2) {
|
|
430
|
+
const hasFocus = update2.view.hasFocus && update2.view.dom.ownerDocument.hasFocus();
|
|
431
|
+
const { anchor = void 0, head = void 0 } = hasFocus ? update2.state.selection.main : {};
|
|
432
|
+
if (this._lastAnchor === anchor && this._lastHead === head) {
|
|
433
|
+
return;
|
|
551
434
|
}
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
const
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
435
|
+
this._lastAnchor = anchor;
|
|
436
|
+
this._lastHead = head;
|
|
437
|
+
this._provider.update(anchor !== void 0 && head !== void 0 ? {
|
|
438
|
+
anchor: this._cursorConverter.toCursor(anchor),
|
|
439
|
+
head: this._cursorConverter.toCursor(head)
|
|
440
|
+
} : void 0);
|
|
441
|
+
}
|
|
442
|
+
_updateRemoteSelections(update2) {
|
|
443
|
+
const decorations = [];
|
|
444
|
+
const awarenessStates = this._provider.getRemoteStates();
|
|
445
|
+
for (const state of awarenessStates) {
|
|
446
|
+
const anchor = state.position?.anchor ? this._cursorConverter.fromCursor(state.position.anchor) : null;
|
|
447
|
+
const head = state.position?.head ? this._cursorConverter.fromCursor(state.position.head) : null;
|
|
448
|
+
if (anchor == null || head == null) {
|
|
449
|
+
continue;
|
|
450
|
+
}
|
|
451
|
+
const start = Math.min(Math.min(anchor, head), update2.view.state.doc.length);
|
|
452
|
+
const end = Math.min(Math.max(anchor, head), update2.view.state.doc.length);
|
|
453
|
+
const startLine = update2.view.state.doc.lineAt(start);
|
|
454
|
+
const endLine = update2.view.state.doc.lineAt(end);
|
|
455
|
+
const color = state.info.color ?? "#30bced";
|
|
456
|
+
const lightColor = state.info.lightColor ?? color + "33";
|
|
457
|
+
if (startLine.number === endLine.number) {
|
|
458
|
+
decorations.push({
|
|
459
|
+
from: start,
|
|
460
|
+
to: end,
|
|
461
|
+
value: Decoration.mark({
|
|
462
|
+
attributes: {
|
|
463
|
+
style: `background-color: ${lightColor}`
|
|
464
|
+
},
|
|
465
|
+
class: "cm-collab-selection"
|
|
466
|
+
})
|
|
467
|
+
});
|
|
468
|
+
} else {
|
|
469
|
+
decorations.push({
|
|
470
|
+
from: start,
|
|
471
|
+
to: startLine.from + startLine.length,
|
|
472
|
+
value: Decoration.mark({
|
|
473
|
+
attributes: {
|
|
474
|
+
style: `background-color: ${color}`
|
|
475
|
+
},
|
|
476
|
+
class: "cm-collab-selection"
|
|
477
|
+
})
|
|
478
|
+
});
|
|
479
|
+
decorations.push({
|
|
480
|
+
from: endLine.from,
|
|
481
|
+
to: end,
|
|
482
|
+
value: Decoration.mark({
|
|
483
|
+
attributes: {
|
|
484
|
+
style: `background-color: ${color}`
|
|
485
|
+
},
|
|
486
|
+
class: "cm-collab-selection"
|
|
487
|
+
})
|
|
488
|
+
});
|
|
489
|
+
for (let i = startLine.number + 1; i < endLine.number; i++) {
|
|
490
|
+
const linePos = update2.view.state.doc.line(i).from;
|
|
491
|
+
decorations.push({
|
|
492
|
+
from: linePos,
|
|
493
|
+
to: linePos,
|
|
494
|
+
value: Decoration.line({
|
|
495
|
+
attributes: {
|
|
496
|
+
style: `background-color: ${color}`,
|
|
497
|
+
class: "cm-collab-selectionLine"
|
|
498
|
+
}
|
|
499
|
+
})
|
|
500
|
+
});
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
decorations.push({
|
|
504
|
+
from: head,
|
|
505
|
+
to: head,
|
|
506
|
+
value: Decoration.widget({
|
|
507
|
+
side: head - anchor > 0 ? -1 : 1,
|
|
508
|
+
block: false,
|
|
509
|
+
widget: new RemoteCaretWidget(state.info.displayName ?? "Anonymous", color)
|
|
510
|
+
})
|
|
567
511
|
});
|
|
568
512
|
}
|
|
513
|
+
this.decorations = Decoration.set(decorations, true);
|
|
569
514
|
}
|
|
570
|
-
view.dispatch({
|
|
571
|
-
selection,
|
|
572
|
-
annotations: reconcileAnnotationType.of({})
|
|
573
|
-
});
|
|
574
515
|
};
|
|
575
|
-
var
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
} else if (patch.action === "del") {
|
|
581
|
-
return handleDel(target, patch);
|
|
582
|
-
} else if (patch.action === "put") {
|
|
583
|
-
return handlePut(target, patch, state);
|
|
584
|
-
} else {
|
|
585
|
-
return null;
|
|
516
|
+
var RemoteCaretWidget = class extends WidgetType {
|
|
517
|
+
constructor(_name, _color) {
|
|
518
|
+
super();
|
|
519
|
+
this._name = _name;
|
|
520
|
+
this._color = _color;
|
|
586
521
|
}
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
522
|
+
toDOM() {
|
|
523
|
+
const span = document.createElement("span");
|
|
524
|
+
span.className = "cm-collab-selectionCaret";
|
|
525
|
+
span.style.backgroundColor = this._color;
|
|
526
|
+
span.style.borderColor = this._color;
|
|
527
|
+
const dot = document.createElement("div");
|
|
528
|
+
dot.className = "cm-collab-selectionCaretDot";
|
|
529
|
+
const info = document.createElement("div");
|
|
530
|
+
info.className = "cm-collab-selectionInfo";
|
|
531
|
+
info.innerText = this._name;
|
|
532
|
+
span.appendChild(document.createTextNode("\u2060"));
|
|
533
|
+
span.appendChild(dot);
|
|
534
|
+
span.appendChild(document.createTextNode("\u2060"));
|
|
535
|
+
span.appendChild(info);
|
|
536
|
+
span.appendChild(document.createTextNode("\u2060"));
|
|
537
|
+
return span;
|
|
592
538
|
}
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
{
|
|
596
|
-
from: index,
|
|
597
|
-
to: index,
|
|
598
|
-
insert: text
|
|
599
|
-
}
|
|
600
|
-
];
|
|
601
|
-
};
|
|
602
|
-
var handleSplice = (target, patch) => {
|
|
603
|
-
const index = charPath(target, patch.path);
|
|
604
|
-
if (index == null) {
|
|
605
|
-
return [];
|
|
539
|
+
updateDOM() {
|
|
540
|
+
return false;
|
|
606
541
|
}
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
from: index,
|
|
610
|
-
insert: patch.value
|
|
611
|
-
}
|
|
612
|
-
];
|
|
613
|
-
};
|
|
614
|
-
var handleDel = (target, patch) => {
|
|
615
|
-
const index = charPath(target, patch.path);
|
|
616
|
-
if (index == null) {
|
|
617
|
-
return [];
|
|
542
|
+
eq(widget) {
|
|
543
|
+
return widget._color === this._color;
|
|
618
544
|
}
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
{
|
|
622
|
-
from: index,
|
|
623
|
-
to: index + length
|
|
624
|
-
}
|
|
625
|
-
];
|
|
626
|
-
};
|
|
627
|
-
var handlePut = (target, patch, state) => {
|
|
628
|
-
const index = charPath(target, [
|
|
629
|
-
...patch.path,
|
|
630
|
-
0
|
|
631
|
-
]);
|
|
632
|
-
if (index == null) {
|
|
633
|
-
return [];
|
|
545
|
+
get estimatedHeight() {
|
|
546
|
+
return -1;
|
|
634
547
|
}
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
return [];
|
|
548
|
+
ignoreEvent() {
|
|
549
|
+
return true;
|
|
638
550
|
}
|
|
639
|
-
return [
|
|
640
|
-
{
|
|
641
|
-
from: 0,
|
|
642
|
-
to: length,
|
|
643
|
-
insert: patch.value
|
|
644
|
-
}
|
|
645
|
-
];
|
|
646
551
|
};
|
|
647
|
-
var
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
552
|
+
var styles = EditorView.baseTheme({
|
|
553
|
+
".cm-collab-selection": {},
|
|
554
|
+
".cm-collab-selectionLine": {
|
|
555
|
+
padding: 0,
|
|
556
|
+
margin: "0px 2px 0px 4px"
|
|
557
|
+
},
|
|
558
|
+
".cm-collab-selectionCaret": {
|
|
559
|
+
position: "relative",
|
|
560
|
+
borderLeft: "1px solid black",
|
|
561
|
+
borderRight: "1px solid black",
|
|
562
|
+
marginLeft: "-1px",
|
|
563
|
+
marginRight: "-1px",
|
|
564
|
+
boxSizing: "border-box",
|
|
565
|
+
display: "inline"
|
|
566
|
+
},
|
|
567
|
+
".cm-collab-selectionCaretDot": {
|
|
568
|
+
borderRadius: "50%",
|
|
569
|
+
position: "absolute",
|
|
570
|
+
width: ".4em",
|
|
571
|
+
height: ".4em",
|
|
572
|
+
top: "-.2em",
|
|
573
|
+
left: "-.2em",
|
|
574
|
+
backgroundColor: "inherit",
|
|
575
|
+
transition: "transform .3s ease-in-out",
|
|
576
|
+
boxSizing: "border-box"
|
|
577
|
+
},
|
|
578
|
+
".cm-collab-selectionCaret:hover > .cm-collab-selectionCaretDot": {
|
|
579
|
+
transformOrigin: "bottom center",
|
|
580
|
+
transform: "scale(0)"
|
|
581
|
+
},
|
|
582
|
+
".cm-collab-selectionInfo": {
|
|
583
|
+
position: "absolute",
|
|
584
|
+
top: "-1.05em",
|
|
585
|
+
left: "-1px",
|
|
586
|
+
fontSize: ".75em",
|
|
587
|
+
fontFamily: "serif",
|
|
588
|
+
fontStyle: "normal",
|
|
589
|
+
fontWeight: "normal",
|
|
590
|
+
lineHeight: "normal",
|
|
591
|
+
userSelect: "none",
|
|
592
|
+
color: "white",
|
|
593
|
+
paddingLeft: "2px",
|
|
594
|
+
paddingRight: "2px",
|
|
595
|
+
zIndex: 101,
|
|
596
|
+
transition: "opacity .3s ease-in-out",
|
|
597
|
+
backgroundColor: "inherit",
|
|
598
|
+
// these should be separate
|
|
599
|
+
opacity: 0,
|
|
600
|
+
transitionDelay: "0s",
|
|
601
|
+
whiteSpace: "nowrap"
|
|
602
|
+
},
|
|
603
|
+
".cm-collab-selectionCaret:hover > .cm-collab-selectionInfo": {
|
|
604
|
+
opacity: 1,
|
|
605
|
+
transitionDelay: "0s"
|
|
659
606
|
}
|
|
660
|
-
|
|
661
|
-
};
|
|
607
|
+
});
|
|
662
608
|
|
|
663
|
-
// packages/ui/react-ui-editor/src/
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
609
|
+
// packages/ui/react-ui-editor/src/extensions/basic.ts
|
|
610
|
+
import { closeBrackets } from "@codemirror/autocomplete";
|
|
611
|
+
import { bracketMatching, defaultHighlightStyle, syntaxHighlighting } from "@codemirror/language";
|
|
612
|
+
import { oneDarkHighlightStyle } from "@codemirror/theme-one-dark";
|
|
613
|
+
import { drawSelection, EditorView as EditorView2, placeholder } from "@codemirror/view";
|
|
614
|
+
var basicBundle = ({ readonly, themeMode, placeholder: _placeholder }) => [
|
|
615
|
+
EditorView2.lineWrapping,
|
|
616
|
+
// TODO(burdon): Compare with minimalSetup.
|
|
617
|
+
// https://codemirror.net/docs/ref/#codemirror.minimalSetup
|
|
618
|
+
bracketMatching(),
|
|
619
|
+
closeBrackets(),
|
|
620
|
+
drawSelection(),
|
|
621
|
+
_placeholder && placeholder(_placeholder),
|
|
622
|
+
// TODO(burdon): Is this required?
|
|
623
|
+
themeMode === "dark" ? syntaxHighlighting(oneDarkHighlightStyle) : syntaxHighlighting(defaultHighlightStyle)
|
|
624
|
+
].filter(Boolean);
|
|
625
|
+
|
|
626
|
+
// packages/ui/react-ui-editor/src/extensions/blast.ts
|
|
627
|
+
import { EditorView as EditorView3, keymap as keymap2 } from "@codemirror/view";
|
|
628
|
+
import defaultsDeep from "lodash.defaultsdeep";
|
|
629
|
+
import { invariant } from "@dxos/invariant";
|
|
630
|
+
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/extensions/blast.ts";
|
|
631
|
+
var defaultOptions = {
|
|
632
|
+
effect: 2,
|
|
633
|
+
maxParticles: 200,
|
|
634
|
+
particleGravity: 0.08,
|
|
635
|
+
particleAlphaFadeout: 0.996,
|
|
636
|
+
particleSize: {
|
|
637
|
+
min: 2,
|
|
638
|
+
max: 8
|
|
639
|
+
},
|
|
640
|
+
particleNumRange: {
|
|
641
|
+
min: 5,
|
|
642
|
+
max: 10
|
|
643
|
+
},
|
|
644
|
+
particleVelocityRange: {
|
|
645
|
+
x: [
|
|
646
|
+
-1,
|
|
647
|
+
1
|
|
648
|
+
],
|
|
649
|
+
y: [
|
|
650
|
+
-3.5,
|
|
651
|
+
-1.5
|
|
652
|
+
]
|
|
653
|
+
},
|
|
654
|
+
particleShrinkRate: 0.95,
|
|
655
|
+
shakeIntensity: 5
|
|
656
|
+
};
|
|
657
|
+
var blast = (options = defaultOptions) => {
|
|
658
|
+
let blaster;
|
|
659
|
+
let last = 0;
|
|
660
|
+
const getPoint = (view, pos) => {
|
|
661
|
+
const { left: x = 0, top: y = 0 } = view.coordsForChar(pos) ?? {};
|
|
662
|
+
const element = document.elementFromPoint(x, y);
|
|
663
|
+
const { offsetLeft: left = 0, offsetTop: top = 0 } = view.scrollDOM.parentElement ?? {};
|
|
664
|
+
const point = {
|
|
665
|
+
x: x - left,
|
|
666
|
+
y: y - top
|
|
667
|
+
};
|
|
668
|
+
return {
|
|
669
|
+
element,
|
|
670
|
+
point
|
|
671
|
+
};
|
|
672
|
+
};
|
|
673
|
+
return [
|
|
674
|
+
// Cursor moved.
|
|
675
|
+
EditorView3.updateListener.of((update2) => {
|
|
676
|
+
if (blaster?.node !== update2.view.scrollDOM) {
|
|
677
|
+
if (blaster) {
|
|
678
|
+
blaster.destroy();
|
|
679
|
+
}
|
|
680
|
+
blaster = new Blaster(update2.view.scrollDOM, defaultsDeep({
|
|
681
|
+
particleGravity: 0.2,
|
|
682
|
+
particleShrinkRate: 0.995,
|
|
683
|
+
color: () => [
|
|
684
|
+
100 + Math.random() * 100,
|
|
685
|
+
0,
|
|
686
|
+
0
|
|
687
|
+
]
|
|
688
|
+
}, options, defaultOptions));
|
|
689
|
+
blaster.initialize();
|
|
690
|
+
blaster.start();
|
|
691
|
+
} else {
|
|
692
|
+
blaster.resize();
|
|
685
693
|
}
|
|
686
|
-
|
|
687
|
-
if (
|
|
688
|
-
|
|
694
|
+
const current = update2.state.selection.main.head;
|
|
695
|
+
if (current !== last) {
|
|
696
|
+
last = current;
|
|
697
|
+
const { element, point } = getPoint(update2.view, current - 1);
|
|
698
|
+
if (element && point) {
|
|
699
|
+
blaster.spawn({
|
|
700
|
+
element,
|
|
701
|
+
point
|
|
702
|
+
});
|
|
703
|
+
}
|
|
689
704
|
}
|
|
690
|
-
const diff = automerge.equals(oldHeads, newHeads) ? [] : automerge.diff(handle.docSync(), oldHeads, newHeads);
|
|
691
|
-
updateCodeMirror(view, selection, path, diff);
|
|
692
|
-
view.dispatch({
|
|
693
|
-
effects: updateHeads(newHeads),
|
|
694
|
-
annotations: reconcileAnnotationType.of({})
|
|
695
|
-
});
|
|
696
|
-
this._inReconcile = false;
|
|
697
|
-
};
|
|
698
|
-
if (field !== void 0) {
|
|
699
|
-
this._field = field;
|
|
700
|
-
}
|
|
701
|
-
}
|
|
702
|
-
};
|
|
703
|
-
|
|
704
|
-
// packages/ui/react-ui-editor/src/hooks/automerge/plugin.ts
|
|
705
|
-
var effectType = StateEffect.define({});
|
|
706
|
-
var updateHeads = (newHeads) => effectType.of({
|
|
707
|
-
newHeads
|
|
708
|
-
});
|
|
709
|
-
var getLastHeads = (state, field) => state.field(field).lastHeads;
|
|
710
|
-
var getPath = (state, field) => state.field(field).path;
|
|
711
|
-
var semaphoreFacet = Facet.define({
|
|
712
|
-
combine: (values) => values.at(-1)
|
|
713
|
-
});
|
|
714
|
-
var automergePlugin = (handle, path) => {
|
|
715
|
-
const stateField = StateField.define({
|
|
716
|
-
create: () => ({
|
|
717
|
-
lastHeads: automerge2.getHeads(handle.docSync()),
|
|
718
|
-
unreconciledTransactions: [],
|
|
719
|
-
path: path.slice()
|
|
720
705
|
}),
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
706
|
+
keymap2.of([
|
|
707
|
+
{
|
|
708
|
+
any: (_, event) => {
|
|
709
|
+
if (blaster) {
|
|
710
|
+
if (event.key === "Enter" && event.shiftKey) {
|
|
711
|
+
blaster.shake({
|
|
712
|
+
time: 0.8
|
|
713
|
+
});
|
|
714
|
+
return true;
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
return false;
|
|
732
718
|
}
|
|
733
719
|
}
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
720
|
+
])
|
|
721
|
+
];
|
|
722
|
+
};
|
|
723
|
+
var Blaster = class {
|
|
724
|
+
constructor(_node, _options) {
|
|
725
|
+
this._node = _node;
|
|
726
|
+
this._options = _options;
|
|
727
|
+
this._running = false;
|
|
728
|
+
this._shakeTime = 0;
|
|
729
|
+
this._shakeTimeMax = 0;
|
|
730
|
+
this._particles = [];
|
|
731
|
+
this._particlePointer = 0;
|
|
732
|
+
this._lastPoint = {
|
|
733
|
+
x: 0,
|
|
734
|
+
y: 0
|
|
735
|
+
};
|
|
736
|
+
this.shake = throttle(({ time }) => {
|
|
737
|
+
this._shakeTime = this._shakeTimeMax || time;
|
|
738
|
+
this._shakeTimeMax = time;
|
|
739
|
+
}, 100);
|
|
740
|
+
this.spawn = throttle(({ element, point }) => {
|
|
741
|
+
const color = getRGBComponents(element, this._options.color);
|
|
742
|
+
const numParticles = random(this._options.particleNumRange.min, this._options.particleNumRange.max);
|
|
743
|
+
const dir = this._lastPoint.x === point.x ? 0 : this._lastPoint.x < point.x ? 1 : -1;
|
|
744
|
+
this._lastPoint = point;
|
|
745
|
+
for (let i = numParticles; i--; i > 0) {
|
|
746
|
+
this._particles[this._particlePointer] = this._effect.create(point.x - dir * 16, point.y, color);
|
|
747
|
+
this._particlePointer = (this._particlePointer + 1) % this._options.maxParticles;
|
|
740
748
|
}
|
|
741
|
-
|
|
749
|
+
}, 100);
|
|
750
|
+
this._effect = this._options.effect === 1 ? new Effect1(_options) : new Effect2(_options);
|
|
751
|
+
}
|
|
752
|
+
get node() {
|
|
753
|
+
return this._node;
|
|
754
|
+
}
|
|
755
|
+
initialize() {
|
|
756
|
+
invariant(!this._canvas && !this._ctx, void 0, {
|
|
757
|
+
F: __dxlog_file,
|
|
758
|
+
L: 138,
|
|
759
|
+
S: this,
|
|
760
|
+
A: [
|
|
761
|
+
"!this._canvas && !this._ctx",
|
|
762
|
+
""
|
|
763
|
+
]
|
|
764
|
+
});
|
|
765
|
+
this._canvas = document.createElement("canvas");
|
|
766
|
+
this._canvas.id = "code-blast-canvas";
|
|
767
|
+
this._canvas.style.position = "absolute";
|
|
768
|
+
this._canvas.style.zIndex = "0";
|
|
769
|
+
this._canvas.style.pointerEvents = "none";
|
|
770
|
+
this._ctx = this._canvas.getContext("2d");
|
|
771
|
+
const parent = this._node.parentElement?.parentElement;
|
|
772
|
+
parent?.appendChild(this._canvas);
|
|
773
|
+
this.resize();
|
|
774
|
+
}
|
|
775
|
+
destroy() {
|
|
776
|
+
this.stop();
|
|
777
|
+
if (this._canvas) {
|
|
778
|
+
this._canvas.remove();
|
|
779
|
+
this._canvas = void 0;
|
|
780
|
+
this._ctx = void 0;
|
|
742
781
|
}
|
|
743
|
-
}
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
this.
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
this.
|
|
751
|
-
handle.addListener("change", this._handleChange);
|
|
782
|
+
}
|
|
783
|
+
resize() {
|
|
784
|
+
if (this._node.parentElement && this._canvas) {
|
|
785
|
+
const { offsetLeft: x, offsetTop: y, offsetWidth: width, offsetHeight: height } = this._node.parentElement;
|
|
786
|
+
this._canvas.style.top = `${y}px`;
|
|
787
|
+
this._canvas.style.left = `${x}px`;
|
|
788
|
+
this._canvas.width = width;
|
|
789
|
+
this._canvas.height = height;
|
|
752
790
|
}
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
791
|
+
}
|
|
792
|
+
start() {
|
|
793
|
+
invariant(this._canvas && this._ctx, void 0, {
|
|
794
|
+
F: __dxlog_file,
|
|
795
|
+
L: 177,
|
|
796
|
+
S: this,
|
|
797
|
+
A: [
|
|
798
|
+
"this._canvas && this._ctx",
|
|
799
|
+
""
|
|
800
|
+
]
|
|
801
|
+
});
|
|
802
|
+
this._running = true;
|
|
803
|
+
this.loop();
|
|
804
|
+
}
|
|
805
|
+
stop() {
|
|
806
|
+
this._running = false;
|
|
807
|
+
this._node.style.transform = "translate(0px, 0px)";
|
|
808
|
+
}
|
|
809
|
+
loop() {
|
|
810
|
+
if (!this._running || !this._canvas || !this._ctx) {
|
|
811
|
+
return;
|
|
812
|
+
}
|
|
813
|
+
this._ctx.clearRect(0, 0, this._canvas.width ?? 0, this._canvas.height ?? 0);
|
|
814
|
+
const now = (/* @__PURE__ */ new Date()).getTime();
|
|
815
|
+
this._lastTime ??= now;
|
|
816
|
+
const dt = (now - this._lastTime) / 1e3;
|
|
817
|
+
this._lastTime = now;
|
|
818
|
+
if (this._shakeTime > 0) {
|
|
819
|
+
this._shakeTime -= dt;
|
|
820
|
+
const magnitude = this._shakeTime / this._shakeTimeMax * this._options.shakeIntensity;
|
|
821
|
+
const shakeX = random(-magnitude, magnitude);
|
|
822
|
+
const shakeY = random(-magnitude, magnitude);
|
|
823
|
+
this._node.style.transform = `translate(${shakeX}px,${shakeY}px)`;
|
|
824
|
+
}
|
|
825
|
+
this.drawParticles();
|
|
826
|
+
requestAnimationFrame(this.loop.bind(this));
|
|
827
|
+
}
|
|
828
|
+
drawParticles() {
|
|
829
|
+
for (let i = this._particles.length; i--; i > 0) {
|
|
830
|
+
const particle = this._particles[i];
|
|
831
|
+
if (!particle) {
|
|
832
|
+
continue;
|
|
758
833
|
}
|
|
834
|
+
if (particle.alpha < 0.01 || particle.size <= 0.5) {
|
|
835
|
+
continue;
|
|
836
|
+
}
|
|
837
|
+
this._effect.update(this._ctx, particle);
|
|
759
838
|
}
|
|
760
|
-
|
|
761
|
-
|
|
839
|
+
}
|
|
840
|
+
};
|
|
841
|
+
var Effect = class {
|
|
842
|
+
constructor(_options) {
|
|
843
|
+
this._options = _options;
|
|
844
|
+
}
|
|
845
|
+
};
|
|
846
|
+
var Effect1 = class extends Effect {
|
|
847
|
+
create(x, y, color) {
|
|
848
|
+
return {
|
|
849
|
+
x,
|
|
850
|
+
y: y + 10,
|
|
851
|
+
vx: random(this._options.particleVelocityRange.x[0], this._options.particleVelocityRange.x[1]),
|
|
852
|
+
vy: random(this._options.particleVelocityRange.y[0], this._options.particleVelocityRange.y[1]),
|
|
853
|
+
size: random(this._options.particleSize.min, this._options.particleSize.max),
|
|
854
|
+
color,
|
|
855
|
+
alpha: 1
|
|
856
|
+
};
|
|
857
|
+
}
|
|
858
|
+
update(ctx, particle) {
|
|
859
|
+
particle.vy += this._options.particleGravity;
|
|
860
|
+
particle.x += particle.vx;
|
|
861
|
+
particle.y += particle.vy;
|
|
862
|
+
particle.alpha *= this._options.particleAlphaFadeout;
|
|
863
|
+
ctx.fillStyle = `rgba(${particle.color[0]},${particle.color[1]},${particle.color[2]},${particle.alpha})`;
|
|
864
|
+
ctx.fillRect(Math.round(particle.x - 1), Math.round(particle.y - 1), particle.size, particle.size);
|
|
865
|
+
}
|
|
866
|
+
};
|
|
867
|
+
var Effect2 = class extends Effect {
|
|
868
|
+
create(x, y, color) {
|
|
869
|
+
return {
|
|
870
|
+
x,
|
|
871
|
+
y: y + 10,
|
|
872
|
+
vx: random(this._options.particleVelocityRange.x[0], this._options.particleVelocityRange.x[1]),
|
|
873
|
+
vy: random(this._options.particleVelocityRange.y[0], this._options.particleVelocityRange.y[1]),
|
|
874
|
+
size: random(this._options.particleSize.min, this._options.particleSize.max),
|
|
875
|
+
color,
|
|
876
|
+
alpha: 1,
|
|
877
|
+
theta: random(0, 360) * Math.PI / 180,
|
|
878
|
+
drag: 0.92,
|
|
879
|
+
wander: 0.15
|
|
880
|
+
};
|
|
881
|
+
}
|
|
882
|
+
update(ctx, particle) {
|
|
883
|
+
particle.vy += this._options.particleGravity;
|
|
884
|
+
particle.x += particle.vx;
|
|
885
|
+
particle.y += particle.vy;
|
|
886
|
+
particle.vx *= particle.drag;
|
|
887
|
+
particle.vy *= particle.drag;
|
|
888
|
+
particle.theta += random(-0.5, 0.5);
|
|
889
|
+
particle.vx += Math.sin(particle.theta) * 0.1;
|
|
890
|
+
particle.vy += Math.cos(particle.theta) * 0.1;
|
|
891
|
+
particle.size *= this._options.particleShrinkRate;
|
|
892
|
+
particle.alpha *= this._options.particleAlphaFadeout;
|
|
893
|
+
ctx.fillStyle = `rgba(${particle.color[0]},${particle.color[1]},${particle.color[2]},${particle.alpha})`;
|
|
894
|
+
ctx.beginPath();
|
|
895
|
+
ctx.arc(Math.round(particle.x - 1), Math.round(particle.y - 1), particle.size, 0, 2 * Math.PI);
|
|
896
|
+
ctx.fill();
|
|
897
|
+
}
|
|
898
|
+
};
|
|
899
|
+
function throttle(callback, limit) {
|
|
900
|
+
let wait = false;
|
|
901
|
+
return function(...args) {
|
|
902
|
+
if (!wait) {
|
|
903
|
+
callback.apply(this, args);
|
|
904
|
+
wait = true;
|
|
905
|
+
setTimeout(() => {
|
|
906
|
+
wait = false;
|
|
907
|
+
}, limit);
|
|
762
908
|
}
|
|
763
|
-
});
|
|
764
|
-
return {
|
|
765
|
-
extension: [
|
|
766
|
-
stateField,
|
|
767
|
-
semaphoreFacet.of(semaphore),
|
|
768
|
-
viewPlugin
|
|
769
|
-
]
|
|
770
909
|
};
|
|
910
|
+
}
|
|
911
|
+
var getRGBComponents = (node, color) => {
|
|
912
|
+
if (typeof color === "function") {
|
|
913
|
+
return color();
|
|
914
|
+
}
|
|
915
|
+
const bgColor = getComputedStyle(node).color;
|
|
916
|
+
if (bgColor) {
|
|
917
|
+
const x = bgColor.match(/(\d+), (\d+), (\d+)/)?.slice(1);
|
|
918
|
+
if (x) {
|
|
919
|
+
return x;
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
return [
|
|
923
|
+
50,
|
|
924
|
+
50,
|
|
925
|
+
50
|
|
926
|
+
];
|
|
927
|
+
};
|
|
928
|
+
var random = (min, max) => {
|
|
929
|
+
if (!max) {
|
|
930
|
+
max = min;
|
|
931
|
+
min = 0;
|
|
932
|
+
}
|
|
933
|
+
return min + ~~(Math.random() * (max - min + 1));
|
|
771
934
|
};
|
|
772
|
-
var reconcileAnnotationType = Annotation.define();
|
|
773
|
-
var isReconcileTx = (tr) => !!tr.annotation(reconcileAnnotationType);
|
|
774
935
|
|
|
775
|
-
// packages/ui/react-ui-editor/src/
|
|
936
|
+
// packages/ui/react-ui-editor/src/extensions/code.ts
|
|
937
|
+
import { ViewPlugin as ViewPlugin3, EditorView as EditorView4, Decoration as Decoration2 } from "@codemirror/view";
|
|
938
|
+
import { mx as mx2 } from "@dxos/react-ui-theme";
|
|
939
|
+
|
|
940
|
+
// packages/ui/react-ui-editor/src/styles/cursors.ts
|
|
776
941
|
import * as random2 from "lib0/random";
|
|
777
942
|
var cursorColors = [
|
|
778
943
|
{
|
|
@@ -810,239 +975,197 @@ var cursorColors = [
|
|
|
810
975
|
];
|
|
811
976
|
var cursorColor = cursorColors[random2.uint32() % cursorColors.length];
|
|
812
977
|
|
|
813
|
-
// packages/ui/react-ui-editor/src/
|
|
814
|
-
import
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
encoding.writeVarUint(encoderAwarenessState, messageAwareness);
|
|
841
|
-
encoding.writeVarUint8Array(encoderAwarenessState, awarenessProtocol.encodeAwarenessUpdate(this.awareness, [
|
|
842
|
-
this._clientId
|
|
843
|
-
]));
|
|
844
|
-
void this._space.postMessage(this._channel, encoding.toUint8Array(encoderAwarenessState));
|
|
845
|
-
}
|
|
846
|
-
get awareness() {
|
|
847
|
-
return this._awareness;
|
|
848
|
-
}
|
|
849
|
-
_handleAwarenessUpdate({ added, updated, removed }, origin) {
|
|
850
|
-
log2("awareness update", {
|
|
851
|
-
added,
|
|
852
|
-
updated,
|
|
853
|
-
removed,
|
|
854
|
-
origin
|
|
855
|
-
}, {
|
|
856
|
-
F: __dxlog_file3,
|
|
857
|
-
L: 67,
|
|
858
|
-
S: this,
|
|
859
|
-
C: (f, a) => f(...a)
|
|
860
|
-
});
|
|
861
|
-
const changedClients = added.concat(updated).concat(removed);
|
|
862
|
-
const encoderAwareness = encoding.createEncoder();
|
|
863
|
-
encoding.writeVarUint(encoderAwareness, messageAwareness);
|
|
864
|
-
encoding.writeVarUint8Array(encoderAwareness, awarenessProtocol.encodeAwarenessUpdate(this._awareness, changedClients));
|
|
865
|
-
void this._space.postMessage(this._channel, encoding.toUint8Array(encoderAwareness));
|
|
866
|
-
}
|
|
867
|
-
_handleSpaceMessage({ payload }) {
|
|
868
|
-
log2("space message", payload, {
|
|
869
|
-
F: __dxlog_file3,
|
|
870
|
-
L: 79,
|
|
871
|
-
S: this,
|
|
872
|
-
C: (f, a) => f(...a)
|
|
873
|
-
});
|
|
874
|
-
const data = new Uint8Array(Array.from(Object.values(payload)));
|
|
875
|
-
const encoder = this._readMessage(data);
|
|
876
|
-
if (encoder) {
|
|
877
|
-
void this._space.postMessage(this._channel, encoding.toUint8Array(encoder));
|
|
878
|
-
}
|
|
879
|
-
}
|
|
880
|
-
_readMessage(message) {
|
|
881
|
-
const decoder = decoding.createDecoder(message);
|
|
882
|
-
const encoder = encoding.createEncoder();
|
|
883
|
-
const messageType = decoding.readVarUint(decoder);
|
|
884
|
-
let sendReply = false;
|
|
885
|
-
switch (messageType) {
|
|
886
|
-
case messageAwareness: {
|
|
887
|
-
awarenessProtocol.applyAwarenessUpdate(this._awareness, decoding.readVarUint8Array(decoder), this);
|
|
888
|
-
break;
|
|
889
|
-
}
|
|
890
|
-
case messageQueryAwareness: {
|
|
891
|
-
encoding.writeVarUint(encoder, messageAwareness);
|
|
892
|
-
encoding.writeVarUint8Array(encoder, awarenessProtocol.encodeAwarenessUpdate(this._awareness, Array.from(this._awareness.getStates().keys())));
|
|
893
|
-
sendReply = true;
|
|
894
|
-
break;
|
|
895
|
-
}
|
|
896
|
-
default: {
|
|
897
|
-
console.error("Invalid message:", messageType);
|
|
898
|
-
return encoder;
|
|
899
|
-
}
|
|
900
|
-
}
|
|
901
|
-
if (!sendReply) {
|
|
902
|
-
return null;
|
|
903
|
-
}
|
|
904
|
-
return encoder;
|
|
905
|
-
}
|
|
906
|
-
_handleBeforeUnload() {
|
|
907
|
-
awarenessProtocol.removeAwarenessStates(this._awareness, [
|
|
908
|
-
this._clientId
|
|
909
|
-
], "window unload");
|
|
910
|
-
}
|
|
978
|
+
// packages/ui/react-ui-editor/src/styles/markdown.ts
|
|
979
|
+
import { mx } from "@dxos/react-ui-theme";
|
|
980
|
+
var headings = {
|
|
981
|
+
1: [
|
|
982
|
+
"mbs-4 mbe-2 font-medium text-inherit no-underline text-4xl",
|
|
983
|
+
"-ml-[10px]"
|
|
984
|
+
],
|
|
985
|
+
2: [
|
|
986
|
+
"mbs-4 mbe-2 font-medium text-inherit no-underline text-3xl",
|
|
987
|
+
"-ml-[8px]"
|
|
988
|
+
],
|
|
989
|
+
3: [
|
|
990
|
+
"mbs-4 mbe-2 font-medium text-inherit no-underline text-2xl",
|
|
991
|
+
"-ml-[7px]"
|
|
992
|
+
],
|
|
993
|
+
4: [
|
|
994
|
+
"mbs-4 mbe-2 font-medium text-inherit no-underline text-xl",
|
|
995
|
+
"-ml-[6px]"
|
|
996
|
+
],
|
|
997
|
+
5: [
|
|
998
|
+
"mbs-4 mbe-2 font-medium text-inherit no-underline text-lg",
|
|
999
|
+
"-ml-[5px]"
|
|
1000
|
+
],
|
|
1001
|
+
6: [
|
|
1002
|
+
"mbs-4 mbe-2 font-medium text-inherit no-underline",
|
|
1003
|
+
"-ml-[4px]"
|
|
1004
|
+
]
|
|
911
1005
|
};
|
|
1006
|
+
var heading = (level, readonly) => {
|
|
1007
|
+
const [style, offset] = headings[level];
|
|
1008
|
+
return mx(style, readonly && offset);
|
|
1009
|
+
};
|
|
1010
|
+
var light = "text-neutral-200 dark:text-neutral-800";
|
|
1011
|
+
var mark = mx("!font-normal !no-underline !text-inherit opacity-40", light);
|
|
1012
|
+
var bold = "font-bold";
|
|
1013
|
+
var italic = "italic";
|
|
1014
|
+
var strikethrough = "line-through";
|
|
1015
|
+
var code = "font-mono !no-underline text-neutral-700 dark:text-neutral-300";
|
|
1016
|
+
var codeMark = "font-mono text-primary-500";
|
|
1017
|
+
var inlineUrl = mx(code, "px-1");
|
|
1018
|
+
var blockquote = mx("pl-1 mr-1 border-is-4 border-primary-500/70 dark:border-primary-500/30", light);
|
|
912
1019
|
|
|
913
|
-
// packages/ui/react-ui-editor/src/
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
1020
|
+
// packages/ui/react-ui-editor/src/styles/tokens.ts
|
|
1021
|
+
import get2 from "lodash.get";
|
|
1022
|
+
import { tailwindConfig } from "@dxos/react-ui-theme";
|
|
1023
|
+
var tokens = tailwindConfig({}).theme;
|
|
1024
|
+
var getToken = (path, defaultValue = void 0) => get2(tokens, path, defaultValue);
|
|
1025
|
+
|
|
1026
|
+
// packages/ui/react-ui-editor/src/extensions/code.ts
|
|
1027
|
+
var CODE_REGEX = /```[\s\S]*?```/gs;
|
|
1028
|
+
var styles2 = EditorView4.baseTheme({
|
|
1029
|
+
"& .cm-codeblock": {
|
|
1030
|
+
fontFamily: getToken("fontFamily.mono", []).join(",")
|
|
1031
|
+
},
|
|
1032
|
+
'&light [aria-readonly="true"] .cm-codeblock': {
|
|
1033
|
+
background: getToken("extend.colors.neutral.50")
|
|
1034
|
+
},
|
|
1035
|
+
'&dark [aria-readonly="true"] .cm-codeblock': {
|
|
1036
|
+
background: getToken("extend.colors.neutral.850")
|
|
1037
|
+
},
|
|
1038
|
+
'& [aria-readonly="true"] .cm-codeblock': {
|
|
1039
|
+
display: "block",
|
|
1040
|
+
paddingInline: "4px !important"
|
|
1041
|
+
},
|
|
1042
|
+
'& [aria-readonly="true"] .cm-codeblock-first': {
|
|
1043
|
+
paddingTop: "4px !important",
|
|
1044
|
+
borderTopLeftRadius: "4px",
|
|
1045
|
+
borderTopRightRadius: "4px"
|
|
1046
|
+
},
|
|
1047
|
+
'& [aria-readonly="true"] .cm-codeblock-last': {
|
|
1048
|
+
paddingBottom: "4px !important",
|
|
1049
|
+
borderBottomLeftRadius: "4px",
|
|
1050
|
+
borderBottomRightRadius: "4px"
|
|
1051
|
+
}
|
|
918
1052
|
});
|
|
919
|
-
var
|
|
920
|
-
const
|
|
921
|
-
const
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
]);
|
|
927
|
-
return model;
|
|
1053
|
+
var getLineRange = (lines, from, to) => {
|
|
1054
|
+
const start = lines.findIndex((line) => line.from >= from);
|
|
1055
|
+
const end = lines.findIndex((line) => line.to >= to);
|
|
1056
|
+
return [
|
|
1057
|
+
start,
|
|
1058
|
+
end
|
|
1059
|
+
];
|
|
928
1060
|
};
|
|
929
|
-
var
|
|
930
|
-
const
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
1061
|
+
var code2 = () => {
|
|
1062
|
+
const getDecorations = (view) => {
|
|
1063
|
+
const decorations = [];
|
|
1064
|
+
if (!view.hasFocus || view.state.readOnly) {
|
|
1065
|
+
const text = view.state.doc.sliceString(0);
|
|
1066
|
+
const matches = text.matchAll(CODE_REGEX);
|
|
1067
|
+
const blocks = view.viewportLineBlocks;
|
|
1068
|
+
for (const match of matches) {
|
|
1069
|
+
const range = getLineRange(blocks, match.index, match.index + match[0].length);
|
|
1070
|
+
for (let i = range[0]; i <= range[1]; i++) {
|
|
1071
|
+
const block = blocks[i];
|
|
1072
|
+
decorations.push(Decoration2.line({
|
|
1073
|
+
class: mx2("cm-codeblock", i === range[0] && "cm-codeblock-first", i === range[1] && "cm-codeblock-last")
|
|
1074
|
+
}).range(block.from));
|
|
1075
|
+
}
|
|
1076
|
+
}
|
|
936
1077
|
}
|
|
937
|
-
return
|
|
938
|
-
}
|
|
939
|
-
};
|
|
940
|
-
var createYjsModel = ({ identity, space, text }) => {
|
|
941
|
-
invariant2(text?.doc && text?.content, void 0, {
|
|
942
|
-
F: __dxlog_file4,
|
|
943
|
-
L: 97,
|
|
944
|
-
S: void 0,
|
|
945
|
-
A: [
|
|
946
|
-
"text?.doc && text?.content",
|
|
947
|
-
""
|
|
948
|
-
]
|
|
949
|
-
});
|
|
950
|
-
const provider = space ? new SpaceAwarenessProvider({
|
|
951
|
-
space,
|
|
952
|
-
doc: text.doc,
|
|
953
|
-
channel: `yjs.awareness.${text.id}`
|
|
954
|
-
}) : void 0;
|
|
955
|
-
const model = {
|
|
956
|
-
id: text.doc.guid,
|
|
957
|
-
content: text.content,
|
|
958
|
-
text: () => text.content.toString(),
|
|
959
|
-
// https://github.com/yjs/yjs?tab=readme-ov-file#relative-positions
|
|
960
|
-
getCursorFromRange: (range) => {
|
|
961
|
-
const from = Y.encodeRelativePosition(Y.createRelativePositionFromTypeIndex(text.content, range.from));
|
|
962
|
-
const to = Y.encodeRelativePosition(Y.createRelativePositionFromTypeIndex(text.content, range.to, -1));
|
|
963
|
-
return [
|
|
964
|
-
arrayToString(from),
|
|
965
|
-
arrayToString(to)
|
|
966
|
-
].join(":");
|
|
967
|
-
},
|
|
968
|
-
getRangeFromCursor: (cursor) => {
|
|
969
|
-
const parts = cursor.split(":");
|
|
970
|
-
const from = Y.createAbsolutePositionFromRelativePosition(Y.decodeRelativePosition(stringToArray(parts[0])), text.doc);
|
|
971
|
-
const to = Y.createAbsolutePositionFromRelativePosition(Y.decodeRelativePosition(stringToArray(parts[1])), text.doc);
|
|
972
|
-
return {
|
|
973
|
-
from: from.index,
|
|
974
|
-
to: to.index
|
|
975
|
-
};
|
|
976
|
-
},
|
|
977
|
-
extension: [
|
|
978
|
-
yCollab(text.content, provider?.awareness),
|
|
979
|
-
modelState.init(() => model)
|
|
980
|
-
],
|
|
981
|
-
awareness: provider?.awareness,
|
|
982
|
-
peer: identity ? {
|
|
983
|
-
id: identity.identityKey.toHex(),
|
|
984
|
-
name: identity.profile?.displayName
|
|
985
|
-
} : void 0
|
|
1078
|
+
return Decoration2.set(decorations);
|
|
986
1079
|
};
|
|
987
|
-
return
|
|
1080
|
+
return [
|
|
1081
|
+
ViewPlugin3.fromClass(class {
|
|
1082
|
+
constructor(view) {
|
|
1083
|
+
this.hasFocus = false;
|
|
1084
|
+
this.decorations = getDecorations(view);
|
|
1085
|
+
}
|
|
1086
|
+
update(update2) {
|
|
1087
|
+
if (
|
|
1088
|
+
// TODO(burdon): Generalize for other extensions.
|
|
1089
|
+
this.hasFocus !== update2.view.hasFocus || update2.startState.readOnly !== update2.view.state.readOnly || update2.docChanged || update2.viewportChanged
|
|
1090
|
+
) {
|
|
1091
|
+
this.hasFocus = update2.view.hasFocus;
|
|
1092
|
+
this.decorations = getDecorations(update2.view);
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1095
|
+
}, {
|
|
1096
|
+
decorations: (value) => value.decorations
|
|
1097
|
+
}),
|
|
1098
|
+
styles2
|
|
1099
|
+
];
|
|
988
1100
|
};
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1101
|
+
|
|
1102
|
+
// packages/ui/react-ui-editor/src/extensions/comments.ts
|
|
1103
|
+
import { StateEffect as StateEffect2, StateField as StateField2 } from "@codemirror/state";
|
|
1104
|
+
import { hoverTooltip, keymap as keymap3, Decoration as Decoration3, EditorView as EditorView5 } from "@codemirror/view";
|
|
1105
|
+
import sortBy from "lodash.sortby";
|
|
1106
|
+
import { debounce } from "@dxos/async";
|
|
1107
|
+
import { invariant as invariant2 } from "@dxos/invariant";
|
|
1108
|
+
import { log as log2 } from "@dxos/log";
|
|
1109
|
+
import { nonNullable } from "@dxos/util";
|
|
1110
|
+
|
|
1111
|
+
// packages/ui/react-ui-editor/src/util.ts
|
|
1112
|
+
import { log } from "@dxos/log";
|
|
1113
|
+
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/util.ts";
|
|
1114
|
+
var callbackWrapper = (fn) => (...args) => {
|
|
1115
|
+
try {
|
|
1116
|
+
return fn(...args);
|
|
1117
|
+
} catch (error) {
|
|
1118
|
+
log.catch(error, void 0, {
|
|
1119
|
+
F: __dxlog_file2,
|
|
1120
|
+
L: 16,
|
|
1121
|
+
S: void 0,
|
|
1122
|
+
C: (f, a) => f(...a)
|
|
1123
|
+
});
|
|
1124
|
+
}
|
|
1009
1125
|
};
|
|
1010
1126
|
|
|
1011
|
-
// packages/ui/react-ui-editor/src/
|
|
1012
|
-
var
|
|
1013
|
-
var
|
|
1014
|
-
"& .cm-bookmark": {
|
|
1015
|
-
cursor: "pointer",
|
|
1016
|
-
margin: "4px",
|
|
1017
|
-
padding: "4px",
|
|
1018
|
-
backgroundColor: "yellow"
|
|
1019
|
-
},
|
|
1020
|
-
"& .cm-bookmark-selected": {
|
|
1021
|
-
backgroundColor: "orange"
|
|
1022
|
-
},
|
|
1127
|
+
// packages/ui/react-ui-editor/src/extensions/comments.ts
|
|
1128
|
+
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/extensions/comments.ts";
|
|
1129
|
+
var styles3 = EditorView5.baseTheme({
|
|
1023
1130
|
"& .cm-comment": {
|
|
1024
|
-
backgroundColor: "yellow"
|
|
1131
|
+
backgroundColor: getToken("extend.colors.yellow.50")
|
|
1025
1132
|
},
|
|
1026
1133
|
"& .cm-comment-active": {
|
|
1027
|
-
backgroundColor: "
|
|
1134
|
+
backgroundColor: getToken("extend.colors.yellow.100")
|
|
1028
1135
|
}
|
|
1029
1136
|
});
|
|
1030
1137
|
var marks = {
|
|
1031
|
-
highlight:
|
|
1138
|
+
highlight: Decoration3.mark({
|
|
1032
1139
|
class: "cm-comment"
|
|
1033
1140
|
}),
|
|
1034
|
-
highlightActive:
|
|
1141
|
+
highlightActive: Decoration3.mark({
|
|
1035
1142
|
class: "cm-comment-active"
|
|
1036
1143
|
})
|
|
1037
1144
|
};
|
|
1145
|
+
var setFocus = (view, thread) => {
|
|
1146
|
+
const range = view.state.field(commentsStateField).ranges.find((range2) => range2.id === thread);
|
|
1147
|
+
if (!range) {
|
|
1148
|
+
return;
|
|
1149
|
+
}
|
|
1150
|
+
view.dispatch({
|
|
1151
|
+
effects: setSelection.of({
|
|
1152
|
+
active: thread
|
|
1153
|
+
}),
|
|
1154
|
+
selection: {
|
|
1155
|
+
anchor: range.from
|
|
1156
|
+
},
|
|
1157
|
+
scrollIntoView: true
|
|
1158
|
+
});
|
|
1159
|
+
};
|
|
1038
1160
|
var setCommentRange = StateEffect2.define();
|
|
1039
1161
|
var setSelection = StateEffect2.define();
|
|
1040
1162
|
var setCommentState = StateEffect2.define();
|
|
1041
|
-
var commentsStateField =
|
|
1163
|
+
var commentsStateField = StateField2.define({
|
|
1042
1164
|
create: () => ({
|
|
1043
1165
|
ranges: []
|
|
1044
1166
|
}),
|
|
1045
1167
|
update: (value, tr) => {
|
|
1168
|
+
const cursorConverter3 = tr.state.facet(Cursor.converter);
|
|
1046
1169
|
for (const effect of tr.effects) {
|
|
1047
1170
|
if (effect.is(setSelection)) {
|
|
1048
1171
|
return {
|
|
@@ -1051,14 +1174,14 @@ var commentsStateField = StateField3.define({
|
|
|
1051
1174
|
};
|
|
1052
1175
|
}
|
|
1053
1176
|
if (effect.is(setCommentRange)) {
|
|
1054
|
-
const {
|
|
1177
|
+
const { comments: comments2 } = effect.value;
|
|
1055
1178
|
const ranges = comments2.map((comment) => {
|
|
1056
|
-
const range =
|
|
1057
|
-
return {
|
|
1179
|
+
const range = Cursor.getRangeFromCursor(cursorConverter3, comment.cursor);
|
|
1180
|
+
return range && {
|
|
1058
1181
|
...comment,
|
|
1059
1182
|
...range
|
|
1060
1183
|
};
|
|
1061
|
-
});
|
|
1184
|
+
}).filter(nonNullable);
|
|
1062
1185
|
return {
|
|
1063
1186
|
...value,
|
|
1064
1187
|
ranges
|
|
@@ -1071,7 +1194,7 @@ var commentsStateField = StateField3.define({
|
|
|
1071
1194
|
return value;
|
|
1072
1195
|
}
|
|
1073
1196
|
});
|
|
1074
|
-
var highlightDecorations =
|
|
1197
|
+
var highlightDecorations = EditorView5.decorations.compute([
|
|
1075
1198
|
commentsStateField
|
|
1076
1199
|
], (state) => {
|
|
1077
1200
|
const { active, ranges } = state.field(commentsStateField);
|
|
@@ -1089,43 +1212,70 @@ var highlightDecorations = EditorView4.decorations.compute([
|
|
|
1089
1212
|
return marks.highlight.range(range.from, range.to);
|
|
1090
1213
|
}
|
|
1091
1214
|
}).filter(nonNullable) ?? [];
|
|
1092
|
-
return
|
|
1215
|
+
return Decoration3.set(decorations);
|
|
1093
1216
|
});
|
|
1094
|
-
var
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
return this._anchor === other._anchor && this._id === other._id;
|
|
1112
|
-
}
|
|
1113
|
-
toDOM() {
|
|
1114
|
-
const span = document.createElement("span");
|
|
1115
|
-
span.className = "cm-bookmark";
|
|
1116
|
-
span.textContent = "\u203B";
|
|
1117
|
-
if (this._handleClick) {
|
|
1118
|
-
span.onclick = () => this._handleClick();
|
|
1217
|
+
var trackPastedComments = (onMove) => {
|
|
1218
|
+
let tracked = null;
|
|
1219
|
+
const registerCopy = (event, view) => {
|
|
1220
|
+
const comments2 = view.state.field(commentsStateField);
|
|
1221
|
+
const { main } = view.state.selection;
|
|
1222
|
+
const inSel = comments2.ranges.filter((range) => range.from >= main.from && range.to <= main.to && range.from < range.to);
|
|
1223
|
+
if (!inSel.length) {
|
|
1224
|
+
tracked = null;
|
|
1225
|
+
} else {
|
|
1226
|
+
tracked = {
|
|
1227
|
+
text: view.state.doc.slice(main.from, main.to),
|
|
1228
|
+
comments: inSel.map((range) => ({
|
|
1229
|
+
from: range.from - main.from,
|
|
1230
|
+
to: range.to - main.from,
|
|
1231
|
+
id: range.id
|
|
1232
|
+
}))
|
|
1233
|
+
};
|
|
1119
1234
|
}
|
|
1120
|
-
|
|
1121
|
-
|
|
1235
|
+
};
|
|
1236
|
+
return [
|
|
1237
|
+
EditorView5.domEventHandlers({
|
|
1238
|
+
cut: registerCopy,
|
|
1239
|
+
copy: registerCopy
|
|
1240
|
+
}),
|
|
1241
|
+
EditorView5.updateListener.of((update2) => {
|
|
1242
|
+
if (tracked) {
|
|
1243
|
+
const paste = update2.transactions.find((tr) => tr.isUserEvent("input.paste"));
|
|
1244
|
+
if (paste) {
|
|
1245
|
+
let found = -1;
|
|
1246
|
+
paste.changes.iterChanges((fromA, toA, fromB, toB, text) => {
|
|
1247
|
+
if (text.eq(tracked.text)) {
|
|
1248
|
+
for (let i = update2.transactions.indexOf(paste) + 1; i < update2.transactions.length; i++) {
|
|
1249
|
+
fromB = update2.transactions[i].changes.mapPos(fromB);
|
|
1250
|
+
}
|
|
1251
|
+
found = fromB;
|
|
1252
|
+
}
|
|
1253
|
+
});
|
|
1254
|
+
if (found > -1) {
|
|
1255
|
+
const active = update2.view.state.field(commentsStateField).ranges;
|
|
1256
|
+
for (const moved of tracked.comments) {
|
|
1257
|
+
if (active.some((range) => range.id === moved.id && range.from === range.to)) {
|
|
1258
|
+
onMove(moved.id, Cursor.getCursorFromRange(update2.view.state.facet(Cursor.converter), {
|
|
1259
|
+
from: found + moved.from,
|
|
1260
|
+
to: found + moved.to
|
|
1261
|
+
}));
|
|
1262
|
+
}
|
|
1263
|
+
}
|
|
1264
|
+
}
|
|
1265
|
+
tracked = null;
|
|
1266
|
+
}
|
|
1267
|
+
}
|
|
1268
|
+
})
|
|
1269
|
+
];
|
|
1122
1270
|
};
|
|
1123
1271
|
var comments = (options = {}) => {
|
|
1272
|
+
const { key: shortcut = "meta-'" } = options;
|
|
1124
1273
|
const handleSelect = debounce((state) => options.onSelect?.(state), 200);
|
|
1125
1274
|
const createCommentThread = (view) => {
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1275
|
+
const cursorConverter3 = view.state.facet(Cursor.converter);
|
|
1276
|
+
invariant2(options.onCreate, void 0, {
|
|
1277
|
+
F: __dxlog_file3,
|
|
1278
|
+
L: 240,
|
|
1129
1279
|
S: void 0,
|
|
1130
1280
|
A: [
|
|
1131
1281
|
"options.onCreate",
|
|
@@ -1136,13 +1286,12 @@ var comments = (options = {}) => {
|
|
|
1136
1286
|
if (from === to) {
|
|
1137
1287
|
return false;
|
|
1138
1288
|
}
|
|
1139
|
-
const
|
|
1140
|
-
const relPos = model?.getCursorFromRange?.({
|
|
1289
|
+
const cursor = Cursor.getCursorFromRange(cursorConverter3, {
|
|
1141
1290
|
from,
|
|
1142
1291
|
to
|
|
1143
1292
|
});
|
|
1144
|
-
if (
|
|
1145
|
-
const id = callbackWrapper(options.onCreate)(
|
|
1293
|
+
if (cursor) {
|
|
1294
|
+
const id = callbackWrapper(options.onCreate)(cursor, view.coordsAtPos(from));
|
|
1146
1295
|
if (id) {
|
|
1147
1296
|
view.dispatch({
|
|
1148
1297
|
effects: setSelection.of({
|
|
@@ -1169,45 +1318,17 @@ var comments = (options = {}) => {
|
|
|
1169
1318
|
}
|
|
1170
1319
|
return false;
|
|
1171
1320
|
};
|
|
1172
|
-
const bookmarksViewPlugin = ViewPlugin3.fromClass(class BookmarkViewPlugin {
|
|
1173
|
-
static {
|
|
1174
|
-
// Match markdown footnotes (option).
|
|
1175
|
-
// https://www.markdownguide.org/extended-syntax/#footnotes
|
|
1176
|
-
this.bookmarkMatcher = new MatchDecorator({
|
|
1177
|
-
regexp: /\[\^(\w+)\]/g,
|
|
1178
|
-
decoration: (match, view, pos) => {
|
|
1179
|
-
const id = match[1];
|
|
1180
|
-
return Decoration2.replace({
|
|
1181
|
-
id,
|
|
1182
|
-
widget: new BookmarkWidget(pos, id)
|
|
1183
|
-
});
|
|
1184
|
-
}
|
|
1185
|
-
});
|
|
1186
|
-
}
|
|
1187
|
-
constructor(view) {
|
|
1188
|
-
this.bookmarks = BookmarkViewPlugin.bookmarkMatcher.createDeco(view);
|
|
1189
|
-
}
|
|
1190
|
-
update(update4) {
|
|
1191
|
-
this.bookmarks = BookmarkViewPlugin.bookmarkMatcher.updateDeco(update4, this.bookmarks);
|
|
1192
|
-
}
|
|
1193
|
-
}, {
|
|
1194
|
-
decorations: (instance) => instance.bookmarks,
|
|
1195
|
-
provide: (plugin) => EditorView4.atomicRanges.of((view) => {
|
|
1196
|
-
return view.plugin(plugin)?.bookmarks || Decoration2.none;
|
|
1197
|
-
})
|
|
1198
|
-
});
|
|
1199
1321
|
return [
|
|
1200
|
-
bookmarksViewPlugin,
|
|
1201
1322
|
commentsStateField,
|
|
1202
1323
|
highlightDecorations,
|
|
1203
|
-
|
|
1324
|
+
styles3,
|
|
1204
1325
|
//
|
|
1205
1326
|
// Keymap.
|
|
1206
1327
|
//
|
|
1207
1328
|
options.onCreate ? keymap3.of([
|
|
1208
1329
|
{
|
|
1209
|
-
key:
|
|
1210
|
-
run: createCommentThread
|
|
1330
|
+
key: shortcut,
|
|
1331
|
+
run: callbackWrapper(createCommentThread)
|
|
1211
1332
|
}
|
|
1212
1333
|
]) : [],
|
|
1213
1334
|
//
|
|
@@ -1223,7 +1344,7 @@ var comments = (options = {}) => {
|
|
|
1223
1344
|
above: true,
|
|
1224
1345
|
create: () => {
|
|
1225
1346
|
const el = document.createElement("div");
|
|
1226
|
-
options.onHover?.(el);
|
|
1347
|
+
options.onHover?.(el, shortcut);
|
|
1227
1348
|
return {
|
|
1228
1349
|
dom: el,
|
|
1229
1350
|
offset: {
|
|
@@ -1243,37 +1364,28 @@ var comments = (options = {}) => {
|
|
|
1243
1364
|
// Monitor cursor movement and text updates.
|
|
1244
1365
|
// TODO(burdon): Is there a better (finer grained) way to do this?
|
|
1245
1366
|
//
|
|
1246
|
-
|
|
1367
|
+
EditorView5.updateListener.of(({ view, state, changes }) => {
|
|
1368
|
+
const cursorConverter3 = view.state.facet(Cursor.converter);
|
|
1247
1369
|
{
|
|
1248
1370
|
let mod = false;
|
|
1249
|
-
const model = state.field(modelState);
|
|
1250
1371
|
const { active, ranges } = state.field(commentsStateField);
|
|
1251
1372
|
changes.iterChanges((from, to, from2, to2) => {
|
|
1252
|
-
invariant3(model, void 0, {
|
|
1253
|
-
F: __dxlog_file5,
|
|
1254
|
-
L: 333,
|
|
1255
|
-
S: void 0,
|
|
1256
|
-
A: [
|
|
1257
|
-
"model",
|
|
1258
|
-
""
|
|
1259
|
-
]
|
|
1260
|
-
});
|
|
1261
1373
|
ranges.forEach((range) => {
|
|
1262
1374
|
if (from2 === to2) {
|
|
1263
|
-
const newRange =
|
|
1264
|
-
if (newRange.to - newRange.from === 0) {
|
|
1265
|
-
|
|
1375
|
+
const newRange = Cursor.getRangeFromCursor(cursorConverter3, range.cursor);
|
|
1376
|
+
if (!newRange || newRange.to - newRange.from === 0) {
|
|
1377
|
+
log2.info("deleted comment", {
|
|
1266
1378
|
thread: range.id
|
|
1267
1379
|
}, {
|
|
1268
|
-
F:
|
|
1269
|
-
L:
|
|
1380
|
+
F: __dxlog_file3,
|
|
1381
|
+
L: 337,
|
|
1270
1382
|
S: void 0,
|
|
1271
1383
|
C: (f, a) => f(...a)
|
|
1272
1384
|
});
|
|
1273
1385
|
}
|
|
1274
1386
|
}
|
|
1275
1387
|
if (from <= range.to) {
|
|
1276
|
-
const newRange =
|
|
1388
|
+
const newRange = Cursor.getRangeFromCursor(cursorConverter3, range.cursor);
|
|
1277
1389
|
Object.assign(range, newRange);
|
|
1278
1390
|
mod = true;
|
|
1279
1391
|
}
|
|
@@ -1319,18 +1431,18 @@ var comments = (options = {}) => {
|
|
|
1319
1431
|
});
|
|
1320
1432
|
}
|
|
1321
1433
|
}
|
|
1322
|
-
})
|
|
1434
|
+
}),
|
|
1435
|
+
options.onMove ? trackPastedComments(options.onMove) : []
|
|
1323
1436
|
];
|
|
1324
1437
|
};
|
|
1325
1438
|
|
|
1326
|
-
// packages/ui/react-ui-editor/src/
|
|
1327
|
-
import { Decoration as
|
|
1328
|
-
|
|
1329
|
-
var styles3 = EditorView5.baseTheme({
|
|
1439
|
+
// packages/ui/react-ui-editor/src/extensions/hr.ts
|
|
1440
|
+
import { Decoration as Decoration4, EditorView as EditorView6, MatchDecorator, ViewPlugin as ViewPlugin4, WidgetType as WidgetType2 } from "@codemirror/view";
|
|
1441
|
+
var styles4 = EditorView6.baseTheme({
|
|
1330
1442
|
"& .cm-hr": {
|
|
1331
1443
|
// TODO(burdon): ???
|
|
1332
1444
|
// Note that block-level decorations should not have vertical margins,
|
|
1333
|
-
borderBottom: `1px solid ${
|
|
1445
|
+
borderBottom: `1px solid ${getToken("extend.colors.neutral.200")}`
|
|
1334
1446
|
}
|
|
1335
1447
|
});
|
|
1336
1448
|
var HorizontalRuleWidget = class extends WidgetType2 {
|
|
@@ -1347,43 +1459,65 @@ var HorizontalRuleWidget = class extends WidgetType2 {
|
|
|
1347
1459
|
return el;
|
|
1348
1460
|
}
|
|
1349
1461
|
};
|
|
1350
|
-
var placeholderMatcher = new
|
|
1462
|
+
var placeholderMatcher = new MatchDecorator({
|
|
1351
1463
|
regexp: /^---$/g,
|
|
1352
|
-
decoration: (match, view, pos) =>
|
|
1464
|
+
decoration: (match, view, pos) => Decoration4.replace({
|
|
1353
1465
|
widget: new HorizontalRuleWidget(pos)
|
|
1354
1466
|
})
|
|
1355
1467
|
});
|
|
1356
1468
|
var hr = () => [
|
|
1357
|
-
|
|
1469
|
+
styles4,
|
|
1358
1470
|
ViewPlugin4.fromClass(class {
|
|
1359
1471
|
constructor(view) {
|
|
1360
1472
|
this.rules = placeholderMatcher.createDeco(view);
|
|
1361
1473
|
}
|
|
1362
|
-
update(
|
|
1363
|
-
this.rules = placeholderMatcher.updateDeco(
|
|
1474
|
+
update(update2) {
|
|
1475
|
+
this.rules = placeholderMatcher.updateDeco(update2, this.rules);
|
|
1364
1476
|
}
|
|
1365
1477
|
}, {
|
|
1366
1478
|
decorations: (instance) => instance.rules,
|
|
1367
1479
|
// TODO(burdon): Is this really atomic (cursor can move into ---).
|
|
1368
|
-
provide: (plugin) =>
|
|
1369
|
-
return view.plugin(plugin)?.rules ||
|
|
1480
|
+
provide: (plugin) => EditorView6.atomicRanges.of((view) => {
|
|
1481
|
+
return view.plugin(plugin)?.rules || Decoration4.none;
|
|
1370
1482
|
})
|
|
1371
1483
|
})
|
|
1372
1484
|
];
|
|
1373
1485
|
|
|
1374
|
-
// packages/ui/react-ui-editor/src/
|
|
1486
|
+
// packages/ui/react-ui-editor/src/extensions/image.ts
|
|
1375
1487
|
import { syntaxTree } from "@codemirror/language";
|
|
1376
|
-
import {
|
|
1377
|
-
import { Decoration as
|
|
1488
|
+
import { StateField as StateField3 } from "@codemirror/state";
|
|
1489
|
+
import { Decoration as Decoration5, EditorView as EditorView7, WidgetType as WidgetType3 } from "@codemirror/view";
|
|
1378
1490
|
var image = (options = {}) => {
|
|
1379
|
-
return
|
|
1380
|
-
create: (state) =>
|
|
1381
|
-
|
|
1382
|
-
|
|
1491
|
+
return StateField3.define({
|
|
1492
|
+
create: (state) => {
|
|
1493
|
+
return Decoration5.set(buildDecorations(0, state.doc.length, state));
|
|
1494
|
+
},
|
|
1495
|
+
update: (value, tr) => {
|
|
1496
|
+
if (!tr.docChanged && !tr.selection) {
|
|
1497
|
+
return value;
|
|
1498
|
+
}
|
|
1499
|
+
const cursor = tr.state.selection.main.head;
|
|
1500
|
+
const oldCursor = tr.changes.mapPos(tr.startState.selection.main.head);
|
|
1501
|
+
let from = Math.min(cursor, oldCursor);
|
|
1502
|
+
let to = Math.max(cursor, oldCursor);
|
|
1503
|
+
tr.changes.iterChangedRanges((fromA, toA, fromB, toB) => {
|
|
1504
|
+
from = Math.min(from, fromB);
|
|
1505
|
+
to = Math.max(to, toB);
|
|
1506
|
+
});
|
|
1507
|
+
from = tr.state.doc.lineAt(from).from;
|
|
1508
|
+
to = tr.state.doc.lineAt(to).to;
|
|
1509
|
+
return value.map(tr.changes).update({
|
|
1510
|
+
filterFrom: from,
|
|
1511
|
+
filterTo: to,
|
|
1512
|
+
filter: () => false,
|
|
1513
|
+
add: buildDecorations(from, to, tr.state)
|
|
1514
|
+
});
|
|
1515
|
+
},
|
|
1516
|
+
provide: (field) => EditorView7.decorations.from(field)
|
|
1383
1517
|
});
|
|
1384
1518
|
};
|
|
1385
|
-
var
|
|
1386
|
-
const
|
|
1519
|
+
var buildDecorations = (from, to, state) => {
|
|
1520
|
+
const decorations = [];
|
|
1387
1521
|
const cursor = state.selection.main.head;
|
|
1388
1522
|
syntaxTree(state).iterate({
|
|
1389
1523
|
enter: (node) => {
|
|
@@ -1392,22 +1526,23 @@ var update = (state, options) => {
|
|
|
1392
1526
|
if (urlNode) {
|
|
1393
1527
|
const hide = state.readOnly || cursor < node.from || cursor > node.to;
|
|
1394
1528
|
const url = state.sliceDoc(urlNode.from, urlNode.to);
|
|
1395
|
-
|
|
1529
|
+
decorations.push(Decoration5.replace({
|
|
1396
1530
|
block: true,
|
|
1397
1531
|
widget: new ImageWidget(url)
|
|
1398
|
-
}));
|
|
1532
|
+
}).range(hide ? node.from : node.to, node.to));
|
|
1399
1533
|
}
|
|
1400
1534
|
}
|
|
1401
|
-
}
|
|
1535
|
+
},
|
|
1536
|
+
from,
|
|
1537
|
+
to
|
|
1402
1538
|
});
|
|
1403
|
-
return
|
|
1539
|
+
return decorations;
|
|
1404
1540
|
};
|
|
1405
1541
|
var ImageWidget = class extends WidgetType3 {
|
|
1406
1542
|
constructor(_url) {
|
|
1407
1543
|
super();
|
|
1408
1544
|
this._url = _url;
|
|
1409
1545
|
}
|
|
1410
|
-
// TODO(burdon): Does this need to be unique for each position?
|
|
1411
1546
|
eq(other) {
|
|
1412
1547
|
return this._url === other._url;
|
|
1413
1548
|
}
|
|
@@ -1415,30 +1550,77 @@ var ImageWidget = class extends WidgetType3 {
|
|
|
1415
1550
|
const img = document.createElement("img");
|
|
1416
1551
|
img.setAttribute("src", this._url);
|
|
1417
1552
|
img.setAttribute("class", "cm-image");
|
|
1553
|
+
img.onload = () => img.classList.add("cm-loaded-image");
|
|
1418
1554
|
return img;
|
|
1419
1555
|
}
|
|
1420
1556
|
};
|
|
1421
1557
|
|
|
1422
|
-
// packages/ui/react-ui-editor/src/
|
|
1558
|
+
// packages/ui/react-ui-editor/src/extensions/link.ts
|
|
1423
1559
|
import { syntaxTree as syntaxTree2 } from "@codemirror/language";
|
|
1424
|
-
import { RangeSetBuilder
|
|
1425
|
-
import { Decoration as
|
|
1560
|
+
import { RangeSetBuilder } from "@codemirror/state";
|
|
1561
|
+
import { Decoration as Decoration6, WidgetType as WidgetType4, hoverTooltip as hoverTooltip2, ViewPlugin as ViewPlugin5 } from "@codemirror/view";
|
|
1562
|
+
import { tooltipContent } from "@dxos/react-ui-theme";
|
|
1426
1563
|
var link = (options = {}) => {
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1564
|
+
const extensions = [
|
|
1565
|
+
ViewPlugin5.fromClass(class {
|
|
1566
|
+
constructor(view) {
|
|
1567
|
+
this.decorations = buildDecorations2(view, options);
|
|
1568
|
+
}
|
|
1569
|
+
update(update2) {
|
|
1570
|
+
if (update2.docChanged || update2.viewportChanged || update2.selectionSet) {
|
|
1571
|
+
this.decorations = buildDecorations2(update2.view, options);
|
|
1572
|
+
}
|
|
1573
|
+
}
|
|
1574
|
+
}, {
|
|
1575
|
+
decorations: (v) => v.decorations
|
|
1576
|
+
})
|
|
1577
|
+
];
|
|
1578
|
+
if (options.onHover) {
|
|
1579
|
+
extensions.push(
|
|
1580
|
+
// https://codemirror.net/examples/tooltip
|
|
1581
|
+
// https://codemirror.net/docs/ref/#view.hoverTooltip
|
|
1582
|
+
// https://github.com/codemirror/view/blob/main/src/tooltip.ts
|
|
1583
|
+
hoverTooltip2((view, pos, side) => {
|
|
1584
|
+
const syntax = syntaxTree2(view.state).resolveInner(pos, side);
|
|
1585
|
+
let link2 = null;
|
|
1586
|
+
for (let i = 0, node = syntax; !link2 && node && i < 5; node = node.parent, i++) {
|
|
1587
|
+
link2 = node.name === "Link" ? node : null;
|
|
1588
|
+
}
|
|
1589
|
+
const url = link2 && link2.getChild("URL");
|
|
1590
|
+
if (!url || !link2) {
|
|
1591
|
+
return null;
|
|
1592
|
+
}
|
|
1593
|
+
const urlText = view.state.sliceDoc(url.from, url.to);
|
|
1594
|
+
return {
|
|
1595
|
+
pos: link2.from,
|
|
1596
|
+
end: link2.to,
|
|
1597
|
+
above: true,
|
|
1598
|
+
create: () => {
|
|
1599
|
+
const el = document.createElement("div");
|
|
1600
|
+
el.className = tooltipContent({}, "pli-2 plb-1");
|
|
1601
|
+
options.onHover(el, urlText);
|
|
1602
|
+
return {
|
|
1603
|
+
dom: el,
|
|
1604
|
+
offset: {
|
|
1605
|
+
x: 0,
|
|
1606
|
+
y: 4
|
|
1607
|
+
}
|
|
1608
|
+
};
|
|
1609
|
+
}
|
|
1610
|
+
};
|
|
1611
|
+
})
|
|
1612
|
+
);
|
|
1613
|
+
}
|
|
1614
|
+
return extensions;
|
|
1432
1615
|
};
|
|
1433
1616
|
var LinkButton = class extends WidgetType4 {
|
|
1434
|
-
constructor(
|
|
1617
|
+
constructor(_url, _onAttach) {
|
|
1435
1618
|
super();
|
|
1436
|
-
this._pos = _pos;
|
|
1437
1619
|
this._url = _url;
|
|
1438
1620
|
this._onAttach = _onAttach;
|
|
1439
1621
|
}
|
|
1440
1622
|
eq(other) {
|
|
1441
|
-
return this.
|
|
1623
|
+
return this._url === other._url;
|
|
1442
1624
|
}
|
|
1443
1625
|
toDOM(view) {
|
|
1444
1626
|
const el = document.createElement("span");
|
|
@@ -1447,14 +1629,13 @@ var LinkButton = class extends WidgetType4 {
|
|
|
1447
1629
|
}
|
|
1448
1630
|
};
|
|
1449
1631
|
var LinkText = class extends WidgetType4 {
|
|
1450
|
-
constructor(
|
|
1632
|
+
constructor(_text, _url) {
|
|
1451
1633
|
super();
|
|
1452
|
-
this._pos = _pos;
|
|
1453
1634
|
this._text = _text;
|
|
1454
1635
|
this._url = _url;
|
|
1455
1636
|
}
|
|
1456
1637
|
eq(other) {
|
|
1457
|
-
return this.
|
|
1638
|
+
return this._url === other._url;
|
|
1458
1639
|
}
|
|
1459
1640
|
toDOM(view) {
|
|
1460
1641
|
const link2 = document.createElement("a");
|
|
@@ -1468,7 +1649,7 @@ var LinkText = class extends WidgetType4 {
|
|
|
1468
1649
|
link2.onclick = () => {
|
|
1469
1650
|
view.dispatch({
|
|
1470
1651
|
selection: {
|
|
1471
|
-
anchor:
|
|
1652
|
+
anchor: view.posAtDOM(link2)
|
|
1472
1653
|
}
|
|
1473
1654
|
});
|
|
1474
1655
|
};
|
|
@@ -1476,74 +1657,77 @@ var LinkText = class extends WidgetType4 {
|
|
|
1476
1657
|
return link2;
|
|
1477
1658
|
}
|
|
1478
1659
|
};
|
|
1479
|
-
var
|
|
1480
|
-
const builder = new
|
|
1660
|
+
var buildDecorations2 = (view, options) => {
|
|
1661
|
+
const builder = new RangeSetBuilder();
|
|
1662
|
+
const { state } = view;
|
|
1481
1663
|
const cursor = state.selection.main.head;
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1664
|
+
for (const { from, to } of view.visibleRanges) {
|
|
1665
|
+
syntaxTree2(state).iterate({
|
|
1666
|
+
enter: (node) => {
|
|
1667
|
+
if (node.name === "Link") {
|
|
1668
|
+
const marks2 = node.node.getChildren("LinkMark");
|
|
1669
|
+
const text = marks2.length >= 2 ? state.sliceDoc(marks2[0].to, marks2[1].from) : "";
|
|
1670
|
+
const urlNode = node.node.getChild("URL");
|
|
1671
|
+
const url = urlNode ? state.sliceDoc(urlNode.from, urlNode.to) : "";
|
|
1672
|
+
if (!url) {
|
|
1673
|
+
return false;
|
|
1674
|
+
}
|
|
1675
|
+
if (!view.hasFocus || state.readOnly || cursor < node.from || cursor > node.to) {
|
|
1676
|
+
builder.add(node.from, node.to, Decoration6.replace({
|
|
1677
|
+
widget: new LinkText(text, options.link ? url : void 0)
|
|
1678
|
+
}));
|
|
1679
|
+
}
|
|
1680
|
+
if (options.onRender) {
|
|
1681
|
+
builder.add(node.to, node.to, Decoration6.replace({
|
|
1682
|
+
widget: new LinkButton(url, options.onRender)
|
|
1683
|
+
}));
|
|
1684
|
+
}
|
|
1490
1685
|
return false;
|
|
1491
1686
|
}
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
if (options.onRender) {
|
|
1498
|
-
builder.add(node.to, node.to, Decoration5.replace({
|
|
1499
|
-
widget: new LinkButton(node.from, url, options.onRender)
|
|
1500
|
-
}));
|
|
1501
|
-
}
|
|
1502
|
-
return false;
|
|
1503
|
-
}
|
|
1504
|
-
}
|
|
1505
|
-
});
|
|
1687
|
+
},
|
|
1688
|
+
from,
|
|
1689
|
+
to
|
|
1690
|
+
});
|
|
1691
|
+
}
|
|
1506
1692
|
return builder.finish();
|
|
1507
1693
|
};
|
|
1508
1694
|
|
|
1509
|
-
// packages/ui/react-ui-editor/src/
|
|
1510
|
-
import {
|
|
1511
|
-
var listener = ({ onChange }) => {
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1695
|
+
// packages/ui/react-ui-editor/src/extensions/listener.ts
|
|
1696
|
+
import { EditorView as EditorView8 } from "@codemirror/view";
|
|
1697
|
+
var listener = ({ onFocus, onChange }) => {
|
|
1698
|
+
const extensions = [];
|
|
1699
|
+
onFocus && extensions.push(EditorView8.focusChangeEffect.of((_, focused) => {
|
|
1700
|
+
onFocus(focused);
|
|
1701
|
+
return null;
|
|
1702
|
+
}));
|
|
1703
|
+
onChange && extensions.push(EditorView8.updateListener.of((update2) => {
|
|
1704
|
+
onChange(update2.state.doc.toString());
|
|
1705
|
+
}));
|
|
1706
|
+
return extensions;
|
|
1521
1707
|
};
|
|
1522
1708
|
|
|
1523
|
-
// packages/ui/react-ui-editor/src/
|
|
1709
|
+
// packages/ui/react-ui-editor/src/extensions/markdown/bundle.ts
|
|
1524
1710
|
import { closeBrackets as closeBrackets2, closeBracketsKeymap } from "@codemirror/autocomplete";
|
|
1525
1711
|
import { history, historyKeymap, indentWithTab, standardKeymap } from "@codemirror/commands";
|
|
1526
|
-
import { markdownLanguage as
|
|
1712
|
+
import { markdownLanguage as markdownLanguage3, markdown } from "@codemirror/lang-markdown";
|
|
1527
1713
|
import { bracketMatching as bracketMatching2, defaultHighlightStyle as defaultHighlightStyle2, indentOnInput, syntaxHighlighting as syntaxHighlighting2 } from "@codemirror/language";
|
|
1528
1714
|
import { languages } from "@codemirror/language-data";
|
|
1529
1715
|
import { searchKeymap } from "@codemirror/search";
|
|
1530
1716
|
import { EditorState } from "@codemirror/state";
|
|
1531
1717
|
import { oneDarkHighlightStyle as oneDarkHighlightStyle2 } from "@codemirror/theme-one-dark";
|
|
1532
|
-
import { crosshairCursor, drawSelection as drawSelection2, dropCursor, EditorView as
|
|
1718
|
+
import { crosshairCursor, drawSelection as drawSelection2, dropCursor, EditorView as EditorView9, highlightActiveLine, keymap as keymap4, placeholder as placeholder2 } from "@codemirror/view";
|
|
1533
1719
|
|
|
1534
|
-
// packages/ui/react-ui-editor/src/
|
|
1535
|
-
import { markdownLanguage } from "@codemirror/lang-markdown";
|
|
1720
|
+
// packages/ui/react-ui-editor/src/extensions/markdown/highlight.ts
|
|
1721
|
+
import { markdownLanguage as markdownLanguage2 } from "@codemirror/lang-markdown";
|
|
1536
1722
|
import { HighlightStyle } from "@codemirror/language";
|
|
1537
1723
|
import { tags, styleTags, Tag } from "@lezer/highlight";
|
|
1538
1724
|
import { Table } from "@lezer/markdown";
|
|
1539
|
-
import get4 from "lodash.get";
|
|
1540
1725
|
var markdownTags = {
|
|
1541
1726
|
Blockquote: Tag.define(),
|
|
1542
1727
|
CodeMark: Tag.define(),
|
|
1543
1728
|
CodeText: Tag.define(),
|
|
1544
1729
|
EmphasisMark: Tag.define(),
|
|
1545
1730
|
HeaderMark: Tag.define(),
|
|
1546
|
-
// HorizontalRule: Tag.define(),
|
|
1547
1731
|
InlineCode: Tag.define(),
|
|
1548
1732
|
LinkLabel: Tag.define(),
|
|
1549
1733
|
LinkReference: Tag.define(),
|
|
@@ -1707,12 +1891,6 @@ var markdownHighlightStyle = (readonly) => {
|
|
|
1707
1891
|
],
|
|
1708
1892
|
class: blockquote
|
|
1709
1893
|
},
|
|
1710
|
-
// TODO(burdon): Replace with extension.
|
|
1711
|
-
// {
|
|
1712
|
-
// tag: [markdownTags.HorizontalRule],
|
|
1713
|
-
// class: mx(horizontalRule, readonly && '-indent-[100rem]'),
|
|
1714
|
-
// },
|
|
1715
|
-
// TODO(burdon): Only if being edited.
|
|
1716
1894
|
{
|
|
1717
1895
|
tag: [
|
|
1718
1896
|
markdownTags.TableCell
|
|
@@ -1720,19 +1898,19 @@ var markdownHighlightStyle = (readonly) => {
|
|
|
1720
1898
|
class: "font-mono"
|
|
1721
1899
|
}
|
|
1722
1900
|
], {
|
|
1723
|
-
scope:
|
|
1901
|
+
scope: markdownLanguage2,
|
|
1724
1902
|
all: {
|
|
1725
|
-
fontFamily:
|
|
1903
|
+
fontFamily: getToken("fontFamily.body", []).join(",")
|
|
1726
1904
|
}
|
|
1727
1905
|
});
|
|
1728
1906
|
};
|
|
1729
1907
|
|
|
1730
|
-
// packages/ui/react-ui-editor/src/
|
|
1908
|
+
// packages/ui/react-ui-editor/src/extensions/markdown/bundle.ts
|
|
1731
1909
|
var markdownBundle = ({ readonly, themeMode, placeholder: _placeholder }) => {
|
|
1732
1910
|
return [
|
|
1733
1911
|
EditorState.allowMultipleSelections.of(true),
|
|
1734
1912
|
EditorState.tabSize.of(2),
|
|
1735
|
-
|
|
1913
|
+
EditorView9.lineWrapping,
|
|
1736
1914
|
customKeymap(),
|
|
1737
1915
|
bracketMatching2(),
|
|
1738
1916
|
closeBrackets2(),
|
|
@@ -1752,7 +1930,7 @@ var markdownBundle = ({ readonly, themeMode, placeholder: _placeholder }) => {
|
|
|
1752
1930
|
// NOTE: This extends the parser; it doesn't affect rendering.
|
|
1753
1931
|
// https://github.github.com/gfm
|
|
1754
1932
|
// https://github.com/lezer-parser/markdown?tab=readme-ov-file#github-flavored-markdown
|
|
1755
|
-
base:
|
|
1933
|
+
base: markdownLanguage3,
|
|
1756
1934
|
// Languages for syntax highlighting fenced code blocks.
|
|
1757
1935
|
codeLanguages: languages,
|
|
1758
1936
|
// Parser extensions.
|
|
@@ -1780,7 +1958,7 @@ var customKeymap = () => keymap4.of([
|
|
|
1780
1958
|
...searchKeymap
|
|
1781
1959
|
]);
|
|
1782
1960
|
|
|
1783
|
-
// packages/ui/react-ui-editor/src/
|
|
1961
|
+
// packages/ui/react-ui-editor/src/extensions/mention.ts
|
|
1784
1962
|
import { autocompletion as autocompletion2 } from "@codemirror/autocomplete";
|
|
1785
1963
|
var mention = ({ onSearch }) => {
|
|
1786
1964
|
return autocompletion2({
|
|
@@ -1803,24 +1981,19 @@ var mention = ({ onSearch }) => {
|
|
|
1803
1981
|
});
|
|
1804
1982
|
};
|
|
1805
1983
|
|
|
1806
|
-
// packages/ui/react-ui-editor/src/
|
|
1807
|
-
var mermaid = () => {
|
|
1808
|
-
return [];
|
|
1809
|
-
};
|
|
1810
|
-
|
|
1811
|
-
// packages/ui/react-ui-editor/src/components/TextEditor/extensions/table.ts
|
|
1984
|
+
// packages/ui/react-ui-editor/src/extensions/table.ts
|
|
1812
1985
|
import { syntaxTree as syntaxTree3 } from "@codemirror/language";
|
|
1813
|
-
import { RangeSetBuilder as
|
|
1814
|
-
import { Decoration as
|
|
1986
|
+
import { RangeSetBuilder as RangeSetBuilder2, StateField as StateField4 } from "@codemirror/state";
|
|
1987
|
+
import { Decoration as Decoration7, EditorView as EditorView10, WidgetType as WidgetType5 } from "@codemirror/view";
|
|
1815
1988
|
var table = (options = {}) => {
|
|
1816
|
-
return
|
|
1817
|
-
create: (state) =>
|
|
1818
|
-
update: (_, tr) =>
|
|
1819
|
-
provide: (field) =>
|
|
1989
|
+
return StateField4.define({
|
|
1990
|
+
create: (state) => update(state, options),
|
|
1991
|
+
update: (_, tr) => update(tr.state, options),
|
|
1992
|
+
provide: (field) => EditorView10.decorations.from(field)
|
|
1820
1993
|
});
|
|
1821
1994
|
};
|
|
1822
|
-
var
|
|
1823
|
-
const builder = new
|
|
1995
|
+
var update = (state, options) => {
|
|
1996
|
+
const builder = new RangeSetBuilder2();
|
|
1824
1997
|
const cursor = state.selection.main.head;
|
|
1825
1998
|
const tables = [];
|
|
1826
1999
|
const getTable = () => tables[tables.length - 1];
|
|
@@ -1860,11 +2033,10 @@ var update3 = (state, options) => {
|
|
|
1860
2033
|
});
|
|
1861
2034
|
tables.forEach((table2) => {
|
|
1862
2035
|
const hide = state.readOnly || cursor < table2.from || cursor > table2.to;
|
|
1863
|
-
hide && builder.add(table2.from, table2.to,
|
|
1864
|
-
block: true,
|
|
2036
|
+
hide && builder.add(table2.from, table2.to, Decoration7.replace({
|
|
1865
2037
|
widget: new TableWidget(table2)
|
|
1866
2038
|
}));
|
|
1867
|
-
builder.add(table2.from, table2.to,
|
|
2039
|
+
builder.add(table2.from, table2.to, Decoration7.mark({
|
|
1868
2040
|
class: "cm-table"
|
|
1869
2041
|
}));
|
|
1870
2042
|
});
|
|
@@ -1876,7 +2048,7 @@ var TableWidget = class extends WidgetType5 {
|
|
|
1876
2048
|
this._table = _table;
|
|
1877
2049
|
}
|
|
1878
2050
|
eq(other) {
|
|
1879
|
-
return this._table.
|
|
2051
|
+
return this._table.header?.join() === other._table.header?.join() && this._table.rows?.join() === other._table.rows?.join();
|
|
1880
2052
|
}
|
|
1881
2053
|
toDOM(view) {
|
|
1882
2054
|
const table2 = document.createElement("table");
|
|
@@ -1902,138 +2074,94 @@ var TableWidget = class extends WidgetType5 {
|
|
|
1902
2074
|
}
|
|
1903
2075
|
return table2;
|
|
1904
2076
|
}
|
|
2077
|
+
ignoreEvent(e) {
|
|
2078
|
+
return !/^mouse/.test(e.type);
|
|
2079
|
+
}
|
|
1905
2080
|
};
|
|
1906
2081
|
|
|
1907
|
-
// packages/ui/react-ui-editor/src/
|
|
1908
|
-
import {
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
paddingLeft: "4px",
|
|
1912
|
-
paddingRight: "8px"
|
|
1913
|
-
}
|
|
1914
|
-
});
|
|
2082
|
+
// packages/ui/react-ui-editor/src/extensions/tasklist.ts
|
|
2083
|
+
import { syntaxTree as syntaxTree4 } from "@codemirror/language";
|
|
2084
|
+
import { RangeSetBuilder as RangeSetBuilder3 } from "@codemirror/state";
|
|
2085
|
+
import { EditorView as EditorView11, Decoration as Decoration8, WidgetType as WidgetType6, ViewPlugin as ViewPlugin6 } from "@codemirror/view";
|
|
1915
2086
|
var CheckboxWidget = class extends WidgetType6 {
|
|
1916
|
-
constructor(
|
|
2087
|
+
constructor(_checked) {
|
|
1917
2088
|
super();
|
|
1918
|
-
this._pos = _pos;
|
|
1919
2089
|
this._checked = _checked;
|
|
1920
|
-
this._indent = _indent;
|
|
1921
|
-
this._onCheck = _onCheck;
|
|
1922
2090
|
}
|
|
1923
2091
|
eq(other) {
|
|
1924
|
-
return this.
|
|
2092
|
+
return this._checked === other._checked;
|
|
1925
2093
|
}
|
|
1926
2094
|
toDOM(view) {
|
|
1927
|
-
const
|
|
1928
|
-
wrap.className = "cm-task-item";
|
|
1929
|
-
wrap.setAttribute("aria-hidden", "true");
|
|
1930
|
-
wrap.style.setProperty("margin-left", this._indent * 24 + "px");
|
|
1931
|
-
const input = wrap.appendChild(document.createElement("input"));
|
|
2095
|
+
const input = document.createElement("input");
|
|
1932
2096
|
input.type = "checkbox";
|
|
1933
2097
|
input.checked = this._checked;
|
|
1934
|
-
if (
|
|
2098
|
+
if (view.state.readOnly) {
|
|
1935
2099
|
input.setAttribute("disabled", "true");
|
|
1936
|
-
}
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
2100
|
+
} else {
|
|
2101
|
+
input.onmousedown = (event) => {
|
|
2102
|
+
const pos = view.posAtDOM(input);
|
|
2103
|
+
const text = view.state.sliceDoc(pos, pos + 3);
|
|
2104
|
+
if (text === (this._checked ? "[x]" : "[ ]")) {
|
|
2105
|
+
view.dispatch({
|
|
2106
|
+
changes: {
|
|
2107
|
+
from: pos + 1,
|
|
2108
|
+
to: pos + 2,
|
|
2109
|
+
insert: this._checked ? " " : "x"
|
|
2110
|
+
}
|
|
2111
|
+
});
|
|
2112
|
+
event.preventDefault();
|
|
2113
|
+
}
|
|
1941
2114
|
};
|
|
1942
2115
|
}
|
|
1943
|
-
return
|
|
2116
|
+
return input;
|
|
1944
2117
|
}
|
|
1945
2118
|
ignoreEvent() {
|
|
1946
2119
|
return false;
|
|
1947
2120
|
}
|
|
1948
2121
|
};
|
|
2122
|
+
var checkedDeco = Decoration8.replace({
|
|
2123
|
+
widget: new CheckboxWidget(true)
|
|
2124
|
+
});
|
|
2125
|
+
var uncheckedDeco = Decoration8.replace({
|
|
2126
|
+
widget: new CheckboxWidget(false)
|
|
2127
|
+
});
|
|
1949
2128
|
var tasklist = (options = {}) => {
|
|
1950
|
-
|
|
1951
|
-
regexp: /^(\s*)- \[([ xX])\]\s/g,
|
|
1952
|
-
decoration: (match, view, pos) => {
|
|
1953
|
-
const indent = Math.floor(match[1].length / 2);
|
|
1954
|
-
const checked = match[2] === "x" || match[2] === "X";
|
|
1955
|
-
return Decoration7.replace({
|
|
1956
|
-
widget: new CheckboxWidget(pos, checked, indent, view.state.readOnly ? void 0 : (checked2) => {
|
|
1957
|
-
const idx = pos + match[0].indexOf("[") + 1;
|
|
1958
|
-
view.dispatch({
|
|
1959
|
-
changes: {
|
|
1960
|
-
from: idx,
|
|
1961
|
-
to: idx + 1,
|
|
1962
|
-
insert: checked2 ? "x" : " "
|
|
1963
|
-
},
|
|
1964
|
-
// TODO(burdon): Restore cursor position? More useful to move to end of line (can indent).
|
|
1965
|
-
selection: {
|
|
1966
|
-
anchor: idx + 3
|
|
1967
|
-
}
|
|
1968
|
-
});
|
|
1969
|
-
})
|
|
1970
|
-
});
|
|
1971
|
-
}
|
|
1972
|
-
});
|
|
1973
|
-
const tasks = ViewPlugin5.fromClass(class {
|
|
2129
|
+
return ViewPlugin6.fromClass(class {
|
|
1974
2130
|
constructor(view) {
|
|
1975
|
-
this.
|
|
1976
|
-
}
|
|
1977
|
-
update(update4) {
|
|
1978
|
-
this.tasks = taskMatcher.updateDeco(update4, this.tasks);
|
|
1979
|
-
}
|
|
1980
|
-
}, {
|
|
1981
|
-
decorations: (value) => value.tasks,
|
|
1982
|
-
provide: (plugin) => EditorView10.atomicRanges.of((view) => {
|
|
1983
|
-
return view.plugin(plugin)?.tasks || Decoration7.none;
|
|
1984
|
-
})
|
|
1985
|
-
});
|
|
1986
|
-
return [
|
|
1987
|
-
tasks,
|
|
1988
|
-
styles4
|
|
1989
|
-
];
|
|
1990
|
-
};
|
|
1991
|
-
|
|
1992
|
-
// packages/ui/react-ui-editor/src/components/TextEditor/extensions/tooltip.ts
|
|
1993
|
-
import { hoverTooltip as hoverTooltip2 } from "@codemirror/view";
|
|
1994
|
-
import { tooltipContent } from "@dxos/react-ui-theme";
|
|
1995
|
-
var markdownLinkRegexp = /\[([^\]]+)]\(([^)]+)\)/;
|
|
1996
|
-
var tooltip = ({ onHover, regexp = markdownLinkRegexp }) => hoverTooltip2((view, pos) => {
|
|
1997
|
-
const { from, text } = view.state.doc.lineAt(pos);
|
|
1998
|
-
const p = pos - from;
|
|
1999
|
-
let idx = 0;
|
|
2000
|
-
let match;
|
|
2001
|
-
do {
|
|
2002
|
-
match = text.substring(idx).match(regexp);
|
|
2003
|
-
if (!match) {
|
|
2004
|
-
match = void 0;
|
|
2005
|
-
break;
|
|
2131
|
+
this.decorations = buildDecorations3(view);
|
|
2006
2132
|
}
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2133
|
+
update(update2) {
|
|
2134
|
+
if (update2.docChanged || update2.viewportChanged || update2.selectionSet) {
|
|
2135
|
+
this.decorations = buildDecorations3(update2.view);
|
|
2136
|
+
}
|
|
2010
2137
|
}
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
x: 0,
|
|
2029
|
-
y: 4
|
|
2138
|
+
}, {
|
|
2139
|
+
decorations: (v) => v.decorations,
|
|
2140
|
+
provide: (plugin) => EditorView11.atomicRanges.of((view) => {
|
|
2141
|
+
return view.plugin(plugin)?.decorations || Decoration8.none;
|
|
2142
|
+
})
|
|
2143
|
+
});
|
|
2144
|
+
};
|
|
2145
|
+
var buildDecorations3 = (view) => {
|
|
2146
|
+
const builder = new RangeSetBuilder3();
|
|
2147
|
+
const { state } = view;
|
|
2148
|
+
const cursor = state.selection.main.head;
|
|
2149
|
+
for (const { from, to } of view.visibleRanges) {
|
|
2150
|
+
syntaxTree4(state).iterate({
|
|
2151
|
+
enter: (node) => {
|
|
2152
|
+
if (node.name === "TaskMarker" && (cursor < node.from || cursor > node.to)) {
|
|
2153
|
+
const checked = state.doc.sliceString(node.from + 1, node.to - 1) === "x";
|
|
2154
|
+
builder.add(node.from, node.to, checked ? checkedDeco : uncheckedDeco);
|
|
2030
2155
|
}
|
|
2031
|
-
}
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
});
|
|
2156
|
+
},
|
|
2157
|
+
from,
|
|
2158
|
+
to
|
|
2159
|
+
});
|
|
2160
|
+
}
|
|
2161
|
+
return builder.finish();
|
|
2162
|
+
};
|
|
2035
2163
|
|
|
2036
|
-
// packages/ui/react-ui-editor/src/
|
|
2164
|
+
// packages/ui/react-ui-editor/src/extensions/typewriter.ts
|
|
2037
2165
|
import { keymap as keymap5 } from "@codemirror/view";
|
|
2038
2166
|
var defaultItems = [
|
|
2039
2167
|
"hello world!",
|
|
@@ -2090,8 +2218,29 @@ var typewriter = ({ delay = 75, items = defaultItems } = {}) => {
|
|
|
2090
2218
|
];
|
|
2091
2219
|
};
|
|
2092
2220
|
|
|
2093
|
-
// packages/ui/react-ui-editor/src/
|
|
2094
|
-
import
|
|
2221
|
+
// packages/ui/react-ui-editor/src/extensions/yjs/yjs.ts
|
|
2222
|
+
import { yCollab } from "y-codemirror.next";
|
|
2223
|
+
|
|
2224
|
+
// packages/ui/react-ui-editor/src/extensions/yjs/cursor.ts
|
|
2225
|
+
import * as Y from "yjs";
|
|
2226
|
+
import { arrayToString, stringToArray } from "@dxos/util";
|
|
2227
|
+
var cursorConverter2 = (text) => ({
|
|
2228
|
+
toCursor: (index, assoc) => {
|
|
2229
|
+
return arrayToString(Y.encodeRelativePosition(Y.createRelativePositionFromTypeIndex(text, index, assoc)));
|
|
2230
|
+
},
|
|
2231
|
+
fromCursor: (cursor) => {
|
|
2232
|
+
return Y.createAbsolutePositionFromRelativePosition(Y.decodeRelativePosition(stringToArray(cursor)), text.doc)?.index ?? 0;
|
|
2233
|
+
}
|
|
2234
|
+
});
|
|
2235
|
+
|
|
2236
|
+
// packages/ui/react-ui-editor/src/extensions/yjs/yjs.ts
|
|
2237
|
+
var yjs = (content, awareness2) => [
|
|
2238
|
+
Cursor.converter.of(cursorConverter2(content)),
|
|
2239
|
+
yCollab(content, awareness2)
|
|
2240
|
+
];
|
|
2241
|
+
|
|
2242
|
+
// packages/ui/react-ui-editor/src/themes/default.ts
|
|
2243
|
+
import get3 from "lodash.get";
|
|
2095
2244
|
var defaultTheme = {
|
|
2096
2245
|
//
|
|
2097
2246
|
// Main layout:
|
|
@@ -2120,21 +2269,21 @@ var defaultTheme = {
|
|
|
2120
2269
|
"&.cm-focused": {
|
|
2121
2270
|
outline: "none"
|
|
2122
2271
|
},
|
|
2123
|
-
"
|
|
2272
|
+
".cm-scroller": {
|
|
2124
2273
|
overflow: "visible",
|
|
2125
|
-
fontFamily:
|
|
2274
|
+
fontFamily: get3(tokens, "fontFamily.mono", []).join(",")
|
|
2126
2275
|
},
|
|
2127
|
-
"
|
|
2276
|
+
".cm-content": {
|
|
2128
2277
|
padding: 0,
|
|
2129
2278
|
// NOTE: Base font size (otherwise defined by HTML tag, which might be different for storybook).
|
|
2130
2279
|
fontSize: "16px"
|
|
2131
2280
|
},
|
|
2132
2281
|
"&light .cm-content": {
|
|
2133
|
-
color:
|
|
2282
|
+
color: get3(tokens, "extend.colors.neutral.900", "black"),
|
|
2134
2283
|
caretColor: "black"
|
|
2135
2284
|
},
|
|
2136
2285
|
"&dark .cm-content": {
|
|
2137
|
-
color:
|
|
2286
|
+
color: get3(tokens, "extend.colors.neutral.100", "white"),
|
|
2138
2287
|
caretColor: "white"
|
|
2139
2288
|
},
|
|
2140
2289
|
//
|
|
@@ -2146,158 +2295,120 @@ var defaultTheme = {
|
|
|
2146
2295
|
"&dark .cm-cursor, &dark .cm-dropCursor": {
|
|
2147
2296
|
borderLeft: "2px solid white"
|
|
2148
2297
|
},
|
|
2149
|
-
"
|
|
2298
|
+
".cm-placeholder": {
|
|
2150
2299
|
fontWeight: 100
|
|
2151
2300
|
},
|
|
2152
2301
|
//
|
|
2153
2302
|
// line
|
|
2154
2303
|
//
|
|
2155
|
-
"
|
|
2304
|
+
".cm-line": {
|
|
2156
2305
|
paddingInline: 0
|
|
2157
2306
|
},
|
|
2158
|
-
"
|
|
2307
|
+
".cm-activeLine": {
|
|
2159
2308
|
background: "inherit"
|
|
2160
2309
|
},
|
|
2161
2310
|
//
|
|
2162
2311
|
// Selection
|
|
2163
2312
|
//
|
|
2164
2313
|
"&light .cm-selectionBackground": {
|
|
2165
|
-
background:
|
|
2314
|
+
background: get3(tokens, "extend.colors.primary.100")
|
|
2166
2315
|
},
|
|
2167
2316
|
"&light.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground": {
|
|
2168
|
-
background:
|
|
2317
|
+
background: get3(tokens, "extend.colors.primary.200")
|
|
2169
2318
|
},
|
|
2170
2319
|
"&dark .cm-selectionBackground": {
|
|
2171
|
-
background:
|
|
2320
|
+
background: get3(tokens, "extend.colors.primary.700")
|
|
2172
2321
|
},
|
|
2173
2322
|
"&dark.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground": {
|
|
2174
|
-
background:
|
|
2323
|
+
background: get3(tokens, "extend.colors.primary.600")
|
|
2175
2324
|
},
|
|
2176
2325
|
//
|
|
2177
2326
|
// Search
|
|
2178
2327
|
//
|
|
2179
2328
|
"&light .cm-searchMatch": {
|
|
2180
|
-
backgroundColor:
|
|
2329
|
+
backgroundColor: get3(tokens, "extend.colors.yellow.100")
|
|
2181
2330
|
},
|
|
2182
2331
|
"&dark .cm-searchMatch": {
|
|
2183
|
-
backgroundColor:
|
|
2184
|
-
},
|
|
2185
|
-
//
|
|
2186
|
-
// collaboration
|
|
2187
|
-
// TODO(burdon): Review classnames (YJS dependent?) Note: e2e tests depend on this class.
|
|
2188
|
-
//
|
|
2189
|
-
"&light .cm-ySelection, &light .cm-yLineSelection": {
|
|
2190
|
-
mixBlendMode: "multiply"
|
|
2191
|
-
},
|
|
2192
|
-
"&dark .cm-ySelection, &dark .cm-yLineSelection": {
|
|
2193
|
-
mixBlendMode: "screen"
|
|
2194
|
-
},
|
|
2195
|
-
"& .cm-ySelectionInfo": {
|
|
2196
|
-
padding: "2px 4px",
|
|
2197
|
-
marginBlockStart: "-4px"
|
|
2198
|
-
},
|
|
2199
|
-
"& .cm-ySelection, & .cm-selectionMatch": {
|
|
2200
|
-
paddingBlockStart: ".15em",
|
|
2201
|
-
paddingBlockEnd: ".15em"
|
|
2202
|
-
},
|
|
2203
|
-
"& .cm-ySelectionCaret": {
|
|
2204
|
-
display: "inline-block",
|
|
2205
|
-
insetBlockStart: ".1em",
|
|
2206
|
-
blockSize: "1.4em",
|
|
2207
|
-
verticalAlign: "top"
|
|
2208
|
-
},
|
|
2209
|
-
"& .cm-yLineSelection": {
|
|
2210
|
-
margin: 0
|
|
2332
|
+
backgroundColor: get3(tokens, "extend.colors.yellow.700")
|
|
2211
2333
|
},
|
|
2212
2334
|
//
|
|
2213
2335
|
// link
|
|
2214
2336
|
//
|
|
2215
|
-
"
|
|
2216
|
-
color:
|
|
2337
|
+
".cm-link": {
|
|
2338
|
+
color: get3(tokens, "extend.colors.primary.500"),
|
|
2217
2339
|
textDecorationLine: "underline",
|
|
2218
2340
|
textDecorationThickness: "1px",
|
|
2219
2341
|
textUnderlineOffset: "2px",
|
|
2220
2342
|
borderRadius: ".125rem",
|
|
2221
|
-
fontFamily:
|
|
2343
|
+
fontFamily: get3(tokens, "fontFamily.body", []).join(",")
|
|
2222
2344
|
},
|
|
2223
2345
|
//
|
|
2224
2346
|
// tooltip
|
|
2225
2347
|
//
|
|
2226
|
-
"
|
|
2348
|
+
".cm-tooltip": {
|
|
2227
2349
|
border: "none"
|
|
2228
2350
|
},
|
|
2229
|
-
"
|
|
2351
|
+
".cm-tooltip-below": {},
|
|
2230
2352
|
//
|
|
2231
2353
|
// autocomplete
|
|
2232
2354
|
//
|
|
2233
|
-
"
|
|
2355
|
+
".cm-tooltip-autocomplete": {
|
|
2234
2356
|
marginTop: "4px",
|
|
2235
2357
|
marginLeft: "-3px"
|
|
2236
2358
|
},
|
|
2237
|
-
"
|
|
2238
|
-
"
|
|
2239
|
-
"
|
|
2359
|
+
".cm-tooltip-autocomplete ul li": {},
|
|
2360
|
+
".cm-tooltip-autocomplete ul li[aria-selected]": {},
|
|
2361
|
+
".cm-completionIcon": {
|
|
2240
2362
|
display: "none"
|
|
2241
2363
|
},
|
|
2242
|
-
"
|
|
2243
|
-
fontFamily:
|
|
2364
|
+
".cm-completionLabel": {
|
|
2365
|
+
fontFamily: get3(tokens, "fontFamily.body", []).join(",")
|
|
2244
2366
|
},
|
|
2245
|
-
"
|
|
2367
|
+
".cm-completionMatchedText": {
|
|
2246
2368
|
textDecoration: "none"
|
|
2247
2369
|
},
|
|
2248
2370
|
//
|
|
2249
|
-
// widgets
|
|
2250
|
-
//
|
|
2251
|
-
"& .cm-widgetBuffer": {
|
|
2252
|
-
display: "none",
|
|
2253
|
-
height: 0
|
|
2254
|
-
},
|
|
2255
|
-
//
|
|
2256
2371
|
// table
|
|
2257
2372
|
//
|
|
2258
|
-
"
|
|
2259
|
-
fontFamily: `${
|
|
2373
|
+
".cm-table *": {
|
|
2374
|
+
fontFamily: `${get3(tokens, "fontFamily.mono", []).join(",")} !important`,
|
|
2260
2375
|
textDecoration: "none !important"
|
|
2261
2376
|
},
|
|
2262
|
-
"
|
|
2377
|
+
".cm-table-head": {
|
|
2263
2378
|
padding: "2px 16px 2px 0px",
|
|
2264
|
-
borderBottom: `1px solid ${
|
|
2379
|
+
borderBottom: `1px solid ${get3(tokens, "extend.colors.neutral.500")}`,
|
|
2265
2380
|
fontWeight: 100,
|
|
2266
2381
|
textAlign: "left",
|
|
2267
|
-
color:
|
|
2382
|
+
color: get3(tokens, "extend.colors.neutral.500")
|
|
2268
2383
|
},
|
|
2269
|
-
"
|
|
2384
|
+
".cm-table-cell": {
|
|
2270
2385
|
padding: "2px 16px 2px 0px"
|
|
2271
2386
|
},
|
|
2272
2387
|
//
|
|
2273
2388
|
// image
|
|
2274
2389
|
//
|
|
2275
|
-
"
|
|
2276
|
-
|
|
2390
|
+
".cm-image": {
|
|
2391
|
+
display: "block",
|
|
2392
|
+
height: "0"
|
|
2393
|
+
},
|
|
2394
|
+
".cm-image.cm-loaded-image": {
|
|
2395
|
+
height: "auto",
|
|
2396
|
+
borderTop: "0.5rem solid transparent",
|
|
2397
|
+
borderBottom: "0.5rem solid transparent"
|
|
2277
2398
|
},
|
|
2278
2399
|
//
|
|
2279
2400
|
// font size
|
|
2280
|
-
// TODO(thure): This appears to be the best or only way to set selection caret heights,
|
|
2401
|
+
// TODO(thure): This appears to be the best or only way to set selection caret heights,
|
|
2402
|
+
// but it's far more verbose than it needs to be.
|
|
2281
2403
|
//
|
|
2282
|
-
...Object.keys(
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
acc[`& .text-${fontSize} + .cm-ySelectionCaret`] = {
|
|
2291
|
-
height
|
|
2292
|
-
};
|
|
2293
|
-
acc[`& .text-${fontSize} + .cm-ySelection + .cm-ySelectionCaret`] = {
|
|
2294
|
-
height
|
|
2295
|
-
};
|
|
2296
|
-
acc[`& .text-${fontSize} + .cm-widgetBuffer + .cm-ySelectionCaret`] = {
|
|
2297
|
-
height
|
|
2298
|
-
};
|
|
2299
|
-
return acc;
|
|
2300
|
-
}, {}),
|
|
2404
|
+
// ...Object.keys(get(tokens, 'extend.fontSize', {})).reduce((acc: Record<string, any>, fontSize) => {
|
|
2405
|
+
// const height = get(tokens, ['extend', 'fontSize', fontSize, 1, 'lineHeight']);
|
|
2406
|
+
//
|
|
2407
|
+
// acc[`& .text-${fontSize} + .cm-ySelectionCaret`] = { height };
|
|
2408
|
+
// acc[`& .text-${fontSize} + .cm-ySelection + .cm-ySelectionCaret`] = { height };
|
|
2409
|
+
// acc[`& .text-${fontSize} + .cm-widgetBuffer + .cm-ySelectionCaret`] = { height };
|
|
2410
|
+
// return acc;
|
|
2411
|
+
// }, {}),
|
|
2301
2412
|
/**
|
|
2302
2413
|
* Panels
|
|
2303
2414
|
* TODO(burdon): Needs styling attention (esp. dark mode).
|
|
@@ -2314,88 +2425,83 @@ var defaultTheme = {
|
|
|
2314
2425
|
* </div>
|
|
2315
2426
|
* </div
|
|
2316
2427
|
*/
|
|
2317
|
-
"
|
|
2318
|
-
border: `1px solid ${
|
|
2428
|
+
".cm-panels": {
|
|
2429
|
+
border: `1px solid ${get3(tokens, "extend.colors.neutral.200")}`
|
|
2319
2430
|
},
|
|
2320
|
-
"
|
|
2321
|
-
background:
|
|
2322
|
-
fontFamily:
|
|
2431
|
+
".cm-panel": {
|
|
2432
|
+
background: get3(tokens, "extend.colors.neutral.50"),
|
|
2433
|
+
fontFamily: get3(tokens, "fontFamily.body", []).join(",")
|
|
2323
2434
|
},
|
|
2324
|
-
"
|
|
2435
|
+
".cm-button": {
|
|
2325
2436
|
margin: "4px",
|
|
2326
|
-
fontFamily:
|
|
2327
|
-
background:
|
|
2437
|
+
fontFamily: get3(tokens, "fontFamily.body", []).join(","),
|
|
2438
|
+
background: get3(tokens, "extend.colors.neutral.100"),
|
|
2328
2439
|
backgroundImage: "none",
|
|
2329
2440
|
border: "none",
|
|
2330
2441
|
"&:hover": {
|
|
2331
|
-
background:
|
|
2442
|
+
background: get3(tokens, "extend.colors.neutral.200")
|
|
2332
2443
|
},
|
|
2333
2444
|
"&:active": {
|
|
2334
|
-
background:
|
|
2445
|
+
background: get3(tokens, "extend.colors.neutral.300"),
|
|
2335
2446
|
backgroundImage: "none"
|
|
2336
2447
|
}
|
|
2337
2448
|
},
|
|
2338
|
-
"
|
|
2449
|
+
".cm-panel input[type=checkbox]": {
|
|
2339
2450
|
marginRight: "0.4rem !important"
|
|
2340
2451
|
}
|
|
2341
2452
|
};
|
|
2342
2453
|
var textTheme = {
|
|
2343
|
-
"
|
|
2344
|
-
fontFamily:
|
|
2454
|
+
".cm-scroller": {
|
|
2455
|
+
fontFamily: get3(tokens, "fontFamily.body", []).join(",")
|
|
2345
2456
|
},
|
|
2346
|
-
"
|
|
2347
|
-
fontFamily:
|
|
2457
|
+
".cm-placeholder": {
|
|
2458
|
+
fontFamily: get3(tokens, "fontFamily.body", []).join(",")
|
|
2348
2459
|
}
|
|
2349
2460
|
};
|
|
2350
2461
|
var markdownTheme = {
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2462
|
+
".cm-scroller": {
|
|
2463
|
+
fontFamily: get3(tokens, "fontFamily.body", []).join(",")
|
|
2464
|
+
},
|
|
2465
|
+
".cm-placeholder": {
|
|
2466
|
+
fontFamily: get3(tokens, "fontFamily.body", []).join(",")
|
|
2354
2467
|
}
|
|
2355
2468
|
};
|
|
2356
2469
|
var codeTheme = {
|
|
2357
|
-
"
|
|
2358
|
-
fontFamily:
|
|
2470
|
+
".cm-scroller": {
|
|
2471
|
+
fontFamily: get3(tokens, "fontFamily.mono", []).join(",")
|
|
2359
2472
|
},
|
|
2360
|
-
"
|
|
2361
|
-
fontFamily:
|
|
2473
|
+
".cm-placeholder": {
|
|
2474
|
+
fontFamily: get3(tokens, "fontFamily.mono", []).join(",")
|
|
2362
2475
|
}
|
|
2363
2476
|
};
|
|
2364
2477
|
|
|
2365
2478
|
// packages/ui/react-ui-editor/src/components/TextEditor/TextEditor.tsx
|
|
2366
|
-
import { EditorState as EditorState2 } from "@codemirror/state";
|
|
2367
|
-
import { EditorView as EditorView11 } from "@codemirror/view";
|
|
2368
|
-
import { useFocusableGroup } from "@fluentui/react-tabster";
|
|
2369
|
-
import { vim } from "@replit/codemirror-vim";
|
|
2370
|
-
import defaultsDeep2 from "lodash.defaultsdeep";
|
|
2371
|
-
import React, { forwardRef, useCallback, useEffect as useEffect2, useImperativeHandle, useState as useState2 } from "react";
|
|
2372
|
-
import { generateName } from "@dxos/display-name";
|
|
2373
|
-
import { useThemeContext } from "@dxos/react-ui";
|
|
2374
|
-
import { getColorForValue, inputSurface, mx as mx3 } from "@dxos/react-ui-theme";
|
|
2375
2479
|
var EditorModes = [
|
|
2376
2480
|
"default",
|
|
2377
2481
|
"vim"
|
|
2378
2482
|
];
|
|
2379
|
-
var BaseTextEditor = /* @__PURE__ */ forwardRef(({ model,
|
|
2380
|
-
const { themeMode } = useThemeContext();
|
|
2483
|
+
var BaseTextEditor = /* @__PURE__ */ forwardRef(({ model, focus, selection, readonly, comments: comments2, extensions = [], editorMode, theme, slots = defaultSlots }, forwardedRef) => {
|
|
2381
2484
|
const tabsterDOMAttribute = useFocusableGroup({
|
|
2382
2485
|
tabBehavior: "limited"
|
|
2383
2486
|
});
|
|
2384
|
-
const
|
|
2385
|
-
const
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
state,
|
|
2487
|
+
const { themeMode } = useThemeContext();
|
|
2488
|
+
const rootRef = useRef(null);
|
|
2489
|
+
const [view, setView] = useState(null);
|
|
2490
|
+
useImperativeHandle(forwardedRef, () => view, [
|
|
2389
2491
|
view
|
|
2390
|
-
|
|
2492
|
+
]);
|
|
2493
|
+
useEffect(() => {
|
|
2494
|
+
if (view && focus) {
|
|
2495
|
+
view.focus();
|
|
2496
|
+
}
|
|
2497
|
+
}, [
|
|
2391
2498
|
view,
|
|
2392
|
-
|
|
2393
|
-
root
|
|
2499
|
+
focus
|
|
2394
2500
|
]);
|
|
2395
|
-
const { awareness, peer } = model;
|
|
2396
|
-
|
|
2397
|
-
if (
|
|
2398
|
-
|
|
2501
|
+
const { awareness: awareness2, peer } = model;
|
|
2502
|
+
useEffect(() => {
|
|
2503
|
+
if (awareness2 && peer) {
|
|
2504
|
+
awareness2.setLocalStateField("user", {
|
|
2399
2505
|
name: peer.name ?? generateName(peer.id),
|
|
2400
2506
|
color: getColorForValue({
|
|
2401
2507
|
value: peer.id,
|
|
@@ -2409,12 +2515,12 @@ var BaseTextEditor = /* @__PURE__ */ forwardRef(({ model, comments: comments2, r
|
|
|
2409
2515
|
});
|
|
2410
2516
|
}
|
|
2411
2517
|
}, [
|
|
2412
|
-
|
|
2518
|
+
awareness2,
|
|
2413
2519
|
peer,
|
|
2414
2520
|
themeMode
|
|
2415
2521
|
]);
|
|
2416
|
-
|
|
2417
|
-
if (view && comments2
|
|
2522
|
+
useEffect(() => {
|
|
2523
|
+
if (view && comments2 !== void 0) {
|
|
2418
2524
|
view.dispatch({
|
|
2419
2525
|
effects: setCommentRange.of({
|
|
2420
2526
|
model,
|
|
@@ -2426,21 +2532,23 @@ var BaseTextEditor = /* @__PURE__ */ forwardRef(({ model, comments: comments2, r
|
|
|
2426
2532
|
view,
|
|
2427
2533
|
comments2
|
|
2428
2534
|
]);
|
|
2429
|
-
|
|
2430
|
-
if (!
|
|
2535
|
+
useEffect(() => {
|
|
2536
|
+
if (!model || !rootRef.current) {
|
|
2431
2537
|
return;
|
|
2432
2538
|
}
|
|
2433
|
-
const
|
|
2539
|
+
const state = EditorState2.create({
|
|
2434
2540
|
doc: model.text(),
|
|
2541
|
+
// TODO(burdon): Composer should store and set selection when switching documents.
|
|
2542
|
+
selection,
|
|
2435
2543
|
extensions: [
|
|
2436
2544
|
readonly && EditorState2.readOnly.of(readonly),
|
|
2437
2545
|
// TODO(burdon): Factor out VIM mode? (manage via MarkdownPlugin).
|
|
2438
2546
|
editorMode === "vim" && vim(),
|
|
2439
2547
|
// Theme.
|
|
2440
2548
|
// TODO(burdon): Make theme configurable.
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2549
|
+
EditorView12.baseTheme(defaultTheme),
|
|
2550
|
+
EditorView12.theme(theme ?? {}),
|
|
2551
|
+
EditorView12.darkTheme.of(themeMode === "dark"),
|
|
2444
2552
|
// Storage and replication.
|
|
2445
2553
|
model.extension,
|
|
2446
2554
|
// Custom.
|
|
@@ -2448,19 +2556,17 @@ var BaseTextEditor = /* @__PURE__ */ forwardRef(({ model, comments: comments2, r
|
|
|
2448
2556
|
].filter(Boolean)
|
|
2449
2557
|
});
|
|
2450
2558
|
view?.destroy();
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
state: state2,
|
|
2455
|
-
parent: root
|
|
2456
|
-
})
|
|
2559
|
+
const newView = new EditorView12({
|
|
2560
|
+
parent: rootRef.current,
|
|
2561
|
+
state
|
|
2457
2562
|
});
|
|
2563
|
+
setView(newView);
|
|
2458
2564
|
return () => {
|
|
2459
|
-
|
|
2460
|
-
|
|
2565
|
+
newView?.destroy();
|
|
2566
|
+
setView(null);
|
|
2461
2567
|
};
|
|
2462
2568
|
}, [
|
|
2463
|
-
|
|
2569
|
+
rootRef,
|
|
2464
2570
|
model,
|
|
2465
2571
|
readonly,
|
|
2466
2572
|
editorMode,
|
|
@@ -2469,12 +2575,8 @@ var BaseTextEditor = /* @__PURE__ */ forwardRef(({ model, comments: comments2, r
|
|
|
2469
2575
|
const handleKeyUp = useCallback((event) => {
|
|
2470
2576
|
const { key, altKey, shiftKey, metaKey, ctrlKey } = event;
|
|
2471
2577
|
switch (key) {
|
|
2472
|
-
case "Enter": {
|
|
2473
|
-
view?.contentDOM.focus();
|
|
2474
|
-
break;
|
|
2475
|
-
}
|
|
2476
2578
|
case "Escape": {
|
|
2477
|
-
editorMode === "vim" && (altKey || shiftKey || metaKey || ctrlKey) &&
|
|
2579
|
+
editorMode === "vim" && (altKey || shiftKey || metaKey || ctrlKey) && rootRef.current?.focus();
|
|
2478
2580
|
break;
|
|
2479
2581
|
}
|
|
2480
2582
|
}
|
|
@@ -2484,16 +2586,17 @@ var BaseTextEditor = /* @__PURE__ */ forwardRef(({ model, comments: comments2, r
|
|
|
2484
2586
|
]);
|
|
2485
2587
|
return /* @__PURE__ */ React.createElement("div", {
|
|
2486
2588
|
key: model.id,
|
|
2487
|
-
|
|
2589
|
+
role: "none",
|
|
2590
|
+
ref: rootRef,
|
|
2488
2591
|
tabIndex: 0,
|
|
2489
|
-
|
|
2490
|
-
...
|
|
2491
|
-
|
|
2592
|
+
onKeyUp: handleKeyUp,
|
|
2593
|
+
...slots.root,
|
|
2594
|
+
...editorMode !== "vim" && tabsterDOMAttribute
|
|
2492
2595
|
});
|
|
2493
2596
|
});
|
|
2494
|
-
var TextEditor = /* @__PURE__ */ forwardRef(({ readonly, extensions = [],
|
|
2597
|
+
var TextEditor = /* @__PURE__ */ forwardRef(({ readonly, placeholder: placeholder3, extensions = [], theme = textTheme, slots, ...props }, forwardedRef) => {
|
|
2495
2598
|
const { themeMode } = useThemeContext();
|
|
2496
|
-
const
|
|
2599
|
+
const updatedSlots = defaultsDeep2({}, slots, defaultTextSlots);
|
|
2497
2600
|
return /* @__PURE__ */ React.createElement(BaseTextEditor, {
|
|
2498
2601
|
ref: forwardedRef,
|
|
2499
2602
|
readonly,
|
|
@@ -2501,17 +2604,18 @@ var TextEditor = /* @__PURE__ */ forwardRef(({ readonly, extensions = [], slots:
|
|
|
2501
2604
|
basicBundle({
|
|
2502
2605
|
readonly,
|
|
2503
2606
|
themeMode,
|
|
2504
|
-
placeholder:
|
|
2607
|
+
placeholder: placeholder3
|
|
2505
2608
|
}),
|
|
2506
2609
|
...extensions
|
|
2507
2610
|
],
|
|
2508
|
-
|
|
2611
|
+
theme,
|
|
2612
|
+
slots: updatedSlots,
|
|
2509
2613
|
...props
|
|
2510
2614
|
});
|
|
2511
2615
|
});
|
|
2512
|
-
var MarkdownEditor = /* @__PURE__ */ forwardRef(({ readonly, extensions = [],
|
|
2616
|
+
var MarkdownEditor = /* @__PURE__ */ forwardRef(({ readonly, placeholder: placeholder3, extensions = [], theme = markdownTheme, slots, ...props }, forwardedRef) => {
|
|
2513
2617
|
const { themeMode } = useThemeContext();
|
|
2514
|
-
const
|
|
2618
|
+
const updatedSlots = defaultsDeep2({}, slots, defaultMarkdownSlots);
|
|
2515
2619
|
return /* @__PURE__ */ React.createElement(BaseTextEditor, {
|
|
2516
2620
|
ref: forwardedRef,
|
|
2517
2621
|
readonly,
|
|
@@ -2519,53 +2623,368 @@ var MarkdownEditor = /* @__PURE__ */ forwardRef(({ readonly, extensions = [], sl
|
|
|
2519
2623
|
markdownBundle({
|
|
2520
2624
|
readonly,
|
|
2521
2625
|
themeMode,
|
|
2522
|
-
placeholder:
|
|
2626
|
+
placeholder: placeholder3
|
|
2523
2627
|
}),
|
|
2524
2628
|
...extensions
|
|
2525
2629
|
],
|
|
2526
|
-
|
|
2630
|
+
theme,
|
|
2631
|
+
slots: updatedSlots,
|
|
2527
2632
|
...props
|
|
2528
2633
|
});
|
|
2529
2634
|
});
|
|
2530
2635
|
var defaultSlots = {
|
|
2531
2636
|
root: {
|
|
2532
|
-
className: mx3("p-2", inputSurface)
|
|
2637
|
+
className: mx3("p-2 overflow-y-auto", inputSurface)
|
|
2533
2638
|
}
|
|
2534
2639
|
};
|
|
2535
2640
|
var defaultTextSlots = {
|
|
2536
|
-
...defaultSlots
|
|
2537
|
-
editor: {
|
|
2538
|
-
theme: textTheme
|
|
2539
|
-
}
|
|
2641
|
+
...defaultSlots
|
|
2540
2642
|
};
|
|
2541
2643
|
var defaultMarkdownSlots = {
|
|
2542
|
-
...defaultSlots
|
|
2543
|
-
|
|
2544
|
-
|
|
2644
|
+
...defaultSlots
|
|
2645
|
+
};
|
|
2646
|
+
|
|
2647
|
+
// packages/ui/react-ui-editor/src/hooks/automerge.ts
|
|
2648
|
+
import get4 from "lodash.get";
|
|
2649
|
+
import { getRawDoc } from "@dxos/echo-schema";
|
|
2650
|
+
import { isNotNullOrUndefined } from "@dxos/util";
|
|
2651
|
+
|
|
2652
|
+
// packages/ui/react-ui-editor/src/hooks/awareness-provider.ts
|
|
2653
|
+
import { DeferredTask, Event as Event2, sleep } from "@dxos/async";
|
|
2654
|
+
import { Context as Context2 } from "@dxos/context";
|
|
2655
|
+
import { invariant as invariant3 } from "@dxos/invariant";
|
|
2656
|
+
import { log as log3 } from "@dxos/log";
|
|
2657
|
+
var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/hooks/awareness-provider.ts";
|
|
2658
|
+
var DEBOUNCE_INTERVAL = 100;
|
|
2659
|
+
var SpaceAwarenessProvider = class {
|
|
2660
|
+
constructor(params) {
|
|
2661
|
+
this.remoteStateChange = new Event2();
|
|
2662
|
+
this._remoteStates = /* @__PURE__ */ new Map();
|
|
2663
|
+
this._space = params.space;
|
|
2664
|
+
this._channel = params.channel;
|
|
2665
|
+
this._peerId = params.peerId;
|
|
2666
|
+
this._info = params.info;
|
|
2667
|
+
}
|
|
2668
|
+
open() {
|
|
2669
|
+
this._ctx = new Context2();
|
|
2670
|
+
this._postTask = new DeferredTask(this._ctx, async () => {
|
|
2671
|
+
if (this._localState) {
|
|
2672
|
+
await this._space.postMessage(this._channel, {
|
|
2673
|
+
kind: "post",
|
|
2674
|
+
state: this._localState
|
|
2675
|
+
});
|
|
2676
|
+
await sleep(DEBOUNCE_INTERVAL);
|
|
2677
|
+
}
|
|
2678
|
+
});
|
|
2679
|
+
const unsubscribe = this._space.listen(this._channel, (message) => {
|
|
2680
|
+
switch (message.payload.kind) {
|
|
2681
|
+
case "query": {
|
|
2682
|
+
this._handleQueryMessage();
|
|
2683
|
+
break;
|
|
2684
|
+
}
|
|
2685
|
+
case "post": {
|
|
2686
|
+
this._handlePostMessage(message.payload);
|
|
2687
|
+
break;
|
|
2688
|
+
}
|
|
2689
|
+
}
|
|
2690
|
+
});
|
|
2691
|
+
this._ctx.onDispose(unsubscribe);
|
|
2692
|
+
void this._space.postMessage(this._channel, {
|
|
2693
|
+
kind: "query"
|
|
2694
|
+
}).catch((err) => {
|
|
2695
|
+
log3.debug("failed to query awareness", {
|
|
2696
|
+
err
|
|
2697
|
+
}, {
|
|
2698
|
+
F: __dxlog_file4,
|
|
2699
|
+
L: 85,
|
|
2700
|
+
S: this,
|
|
2701
|
+
C: (f, a) => f(...a)
|
|
2702
|
+
});
|
|
2703
|
+
});
|
|
2704
|
+
}
|
|
2705
|
+
close() {
|
|
2706
|
+
void this._ctx?.dispose();
|
|
2707
|
+
this._ctx = void 0;
|
|
2708
|
+
this._postTask = void 0;
|
|
2709
|
+
}
|
|
2710
|
+
update(position) {
|
|
2711
|
+
invariant3(this._postTask, void 0, {
|
|
2712
|
+
F: __dxlog_file4,
|
|
2713
|
+
L: 96,
|
|
2714
|
+
S: this,
|
|
2715
|
+
A: [
|
|
2716
|
+
"this._postTask",
|
|
2717
|
+
""
|
|
2718
|
+
]
|
|
2719
|
+
});
|
|
2720
|
+
this._localState = {
|
|
2721
|
+
peerId: this._peerId,
|
|
2722
|
+
position,
|
|
2723
|
+
info: this._info
|
|
2724
|
+
};
|
|
2725
|
+
this._postTask.schedule();
|
|
2726
|
+
}
|
|
2727
|
+
getRemoteStates() {
|
|
2728
|
+
return Array.from(this._remoteStates.values());
|
|
2729
|
+
}
|
|
2730
|
+
_handleQueryMessage() {
|
|
2731
|
+
invariant3(this._postTask, void 0, {
|
|
2732
|
+
F: __dxlog_file4,
|
|
2733
|
+
L: 111,
|
|
2734
|
+
S: this,
|
|
2735
|
+
A: [
|
|
2736
|
+
"this._postTask",
|
|
2737
|
+
""
|
|
2738
|
+
]
|
|
2739
|
+
});
|
|
2740
|
+
this._postTask.schedule();
|
|
2741
|
+
}
|
|
2742
|
+
_handlePostMessage(message) {
|
|
2743
|
+
invariant3(message.kind === "post", void 0, {
|
|
2744
|
+
F: __dxlog_file4,
|
|
2745
|
+
L: 116,
|
|
2746
|
+
S: this,
|
|
2747
|
+
A: [
|
|
2748
|
+
"message.kind === 'post'",
|
|
2749
|
+
""
|
|
2750
|
+
]
|
|
2751
|
+
});
|
|
2752
|
+
this._remoteStates.set(message.state.peerId, message.state);
|
|
2753
|
+
this.remoteStateChange.emit();
|
|
2754
|
+
}
|
|
2755
|
+
};
|
|
2756
|
+
|
|
2757
|
+
// packages/ui/react-ui-editor/src/hooks/useTextModel.ts
|
|
2758
|
+
import { StateField as StateField5 } from "@codemirror/state";
|
|
2759
|
+
import { useEffect as useEffect2, useState as useState2 } from "react";
|
|
2760
|
+
import { isAutomergeObject } from "@dxos/react-client/echo";
|
|
2761
|
+
|
|
2762
|
+
// packages/ui/react-ui-editor/src/hooks/yjs.ts
|
|
2763
|
+
import * as decoding from "lib0/decoding";
|
|
2764
|
+
import * as encoding from "lib0/encoding";
|
|
2765
|
+
import { Observable } from "lib0/observable";
|
|
2766
|
+
import * as YP from "y-protocols/awareness";
|
|
2767
|
+
import { invariant as invariant4 } from "@dxos/invariant";
|
|
2768
|
+
import { log as log4 } from "@dxos/log";
|
|
2769
|
+
var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/hooks/yjs.ts";
|
|
2770
|
+
var createYjsModel = ({ identity, space, text }) => {
|
|
2771
|
+
invariant4(text?.doc && text?.content, void 0, {
|
|
2772
|
+
F: __dxlog_file5,
|
|
2773
|
+
L: 21,
|
|
2774
|
+
S: void 0,
|
|
2775
|
+
A: [
|
|
2776
|
+
"text?.doc && text?.content",
|
|
2777
|
+
""
|
|
2778
|
+
]
|
|
2779
|
+
});
|
|
2780
|
+
const provider = space ? new YAwarenessProvider({
|
|
2781
|
+
space,
|
|
2782
|
+
doc: text.doc,
|
|
2783
|
+
channel: `yjs.awareness.${text.id}`
|
|
2784
|
+
}) : void 0;
|
|
2785
|
+
const model = {
|
|
2786
|
+
id: text.doc.guid,
|
|
2787
|
+
content: text.content,
|
|
2788
|
+
text: () => text.content.toString(),
|
|
2789
|
+
extension: [
|
|
2790
|
+
modelState.init(() => model),
|
|
2791
|
+
yjs(text.content, provider?.awareness)
|
|
2792
|
+
],
|
|
2793
|
+
awareness: provider?.awareness,
|
|
2794
|
+
peer: identity ? {
|
|
2795
|
+
id: identity.identityKey.toHex(),
|
|
2796
|
+
name: identity.profile?.displayName
|
|
2797
|
+
} : void 0
|
|
2798
|
+
};
|
|
2799
|
+
return model;
|
|
2800
|
+
};
|
|
2801
|
+
var messageAwareness = 1;
|
|
2802
|
+
var messageQueryAwareness = 3;
|
|
2803
|
+
var YAwarenessProvider = class extends Observable {
|
|
2804
|
+
constructor({ space, doc, channel, awareness: awareness2 }) {
|
|
2805
|
+
super();
|
|
2806
|
+
this._space = space;
|
|
2807
|
+
this._awareness = awareness2 ?? new YP.Awareness(doc);
|
|
2808
|
+
this._channel = channel;
|
|
2809
|
+
this._clientId = doc.clientID;
|
|
2810
|
+
this._awareness.on("update", this._handleAwarenessUpdate.bind(this));
|
|
2811
|
+
this._space.listen(this._channel, this._handleSpaceMessage.bind(this));
|
|
2812
|
+
if (typeof window !== "undefined") {
|
|
2813
|
+
window.addEventListener("beforeunload", this._handleBeforeUnload.bind(this));
|
|
2814
|
+
} else if (typeof process !== "undefined") {
|
|
2815
|
+
process.on("exit", this._handleBeforeUnload.bind(this));
|
|
2816
|
+
}
|
|
2817
|
+
const encoderAwarenessQuery = encoding.createEncoder();
|
|
2818
|
+
encoding.writeVarUint(encoderAwarenessQuery, messageQueryAwareness);
|
|
2819
|
+
void this._space.postMessage(this._channel, encoding.toUint8Array(encoderAwarenessQuery));
|
|
2820
|
+
const encoderAwarenessState = encoding.createEncoder();
|
|
2821
|
+
encoding.writeVarUint(encoderAwarenessState, messageAwareness);
|
|
2822
|
+
encoding.writeVarUint8Array(encoderAwarenessState, YP.encodeAwarenessUpdate(this.awareness, [
|
|
2823
|
+
this._clientId
|
|
2824
|
+
]));
|
|
2825
|
+
void this._space.postMessage(this._channel, encoding.toUint8Array(encoderAwarenessState));
|
|
2826
|
+
}
|
|
2827
|
+
get awareness() {
|
|
2828
|
+
return this._awareness;
|
|
2829
|
+
}
|
|
2830
|
+
_handleAwarenessUpdate({ added, updated, removed }, origin) {
|
|
2831
|
+
log4("awareness update", {
|
|
2832
|
+
added,
|
|
2833
|
+
updated,
|
|
2834
|
+
removed,
|
|
2835
|
+
origin
|
|
2836
|
+
}, {
|
|
2837
|
+
F: __dxlog_file5,
|
|
2838
|
+
L: 100,
|
|
2839
|
+
S: this,
|
|
2840
|
+
C: (f, a) => f(...a)
|
|
2841
|
+
});
|
|
2842
|
+
const changedClients = added.concat(updated).concat(removed);
|
|
2843
|
+
const encoderAwareness = encoding.createEncoder();
|
|
2844
|
+
encoding.writeVarUint(encoderAwareness, messageAwareness);
|
|
2845
|
+
encoding.writeVarUint8Array(encoderAwareness, YP.encodeAwarenessUpdate(this._awareness, changedClients));
|
|
2846
|
+
void this._space.postMessage(this._channel, encoding.toUint8Array(encoderAwareness));
|
|
2847
|
+
}
|
|
2848
|
+
_handleSpaceMessage({ payload }) {
|
|
2849
|
+
log4("space message", payload, {
|
|
2850
|
+
F: __dxlog_file5,
|
|
2851
|
+
L: 109,
|
|
2852
|
+
S: this,
|
|
2853
|
+
C: (f, a) => f(...a)
|
|
2854
|
+
});
|
|
2855
|
+
const data = new Uint8Array(Array.from(Object.values(payload)));
|
|
2856
|
+
const encoder = this._readMessage(data);
|
|
2857
|
+
if (encoder) {
|
|
2858
|
+
void this._space.postMessage(this._channel, encoding.toUint8Array(encoder));
|
|
2859
|
+
}
|
|
2860
|
+
}
|
|
2861
|
+
_readMessage(message) {
|
|
2862
|
+
const decoder = decoding.createDecoder(message);
|
|
2863
|
+
const encoder = encoding.createEncoder();
|
|
2864
|
+
const messageType = decoding.readVarUint(decoder);
|
|
2865
|
+
let sendReply = false;
|
|
2866
|
+
switch (messageType) {
|
|
2867
|
+
case messageAwareness: {
|
|
2868
|
+
YP.applyAwarenessUpdate(this._awareness, decoding.readVarUint8Array(decoder), this);
|
|
2869
|
+
break;
|
|
2870
|
+
}
|
|
2871
|
+
case messageQueryAwareness: {
|
|
2872
|
+
encoding.writeVarUint(encoder, messageAwareness);
|
|
2873
|
+
encoding.writeVarUint8Array(encoder, YP.encodeAwarenessUpdate(this._awareness, Array.from(this._awareness.getStates().keys())));
|
|
2874
|
+
sendReply = true;
|
|
2875
|
+
break;
|
|
2876
|
+
}
|
|
2877
|
+
default: {
|
|
2878
|
+
console.error("Invalid message:", messageType);
|
|
2879
|
+
return encoder;
|
|
2880
|
+
}
|
|
2881
|
+
}
|
|
2882
|
+
if (!sendReply) {
|
|
2883
|
+
return null;
|
|
2884
|
+
}
|
|
2885
|
+
return encoder;
|
|
2886
|
+
}
|
|
2887
|
+
_handleBeforeUnload() {
|
|
2888
|
+
YP.removeAwarenessStates(this._awareness, [
|
|
2889
|
+
this._clientId
|
|
2890
|
+
], "window unload");
|
|
2891
|
+
}
|
|
2892
|
+
};
|
|
2893
|
+
|
|
2894
|
+
// packages/ui/react-ui-editor/src/hooks/useTextModel.ts
|
|
2895
|
+
var modelState = StateField5.define({
|
|
2896
|
+
create: () => void 0,
|
|
2897
|
+
update: (model) => model
|
|
2898
|
+
});
|
|
2899
|
+
var useTextModel = (props) => {
|
|
2900
|
+
const { identity, space, text } = props;
|
|
2901
|
+
const [model, setModel] = useState2();
|
|
2902
|
+
useEffect2(() => setModel(createModel(props)), [
|
|
2903
|
+
identity,
|
|
2904
|
+
space,
|
|
2905
|
+
text
|
|
2906
|
+
]);
|
|
2907
|
+
return model;
|
|
2908
|
+
};
|
|
2909
|
+
var createModel = (props) => {
|
|
2910
|
+
const { text } = props;
|
|
2911
|
+
if (isAutomergeObject(text)) {
|
|
2912
|
+
return createAutomergeModel(props);
|
|
2913
|
+
} else if (text?.doc) {
|
|
2914
|
+
return createYjsModel(props);
|
|
2915
|
+
} else {
|
|
2916
|
+
return void 0;
|
|
2545
2917
|
}
|
|
2546
2918
|
};
|
|
2919
|
+
|
|
2920
|
+
// packages/ui/react-ui-editor/src/hooks/automerge.ts
|
|
2921
|
+
var createAutomergeModel = ({ space, identity, text }) => {
|
|
2922
|
+
const obj = text;
|
|
2923
|
+
const doc = getRawDoc(obj, [
|
|
2924
|
+
obj.field
|
|
2925
|
+
]);
|
|
2926
|
+
const awarenessProvider = space && new SpaceAwarenessProvider({
|
|
2927
|
+
space,
|
|
2928
|
+
channel: `automerge.awareness.${obj.id}`,
|
|
2929
|
+
info: {
|
|
2930
|
+
displayName: identity?.profile?.displayName ?? "",
|
|
2931
|
+
color: cursorColor.color,
|
|
2932
|
+
lightColor: cursorColor.light
|
|
2933
|
+
},
|
|
2934
|
+
peerId: identity?.identityKey.toHex() ?? "Anonymous"
|
|
2935
|
+
});
|
|
2936
|
+
const model = {
|
|
2937
|
+
id: obj.id,
|
|
2938
|
+
content: doc,
|
|
2939
|
+
text: () => get4(doc.handle.docSync(), doc.path),
|
|
2940
|
+
// TODO(burdon): https://automerge.org/automerge/api-docs/js/functions/next.getCursor.html
|
|
2941
|
+
extension: [
|
|
2942
|
+
modelState.init(() => model),
|
|
2943
|
+
automerge3({
|
|
2944
|
+
handle: doc.handle,
|
|
2945
|
+
path: doc.path
|
|
2946
|
+
}),
|
|
2947
|
+
awarenessProvider && AwarenessProvider.of(awarenessProvider),
|
|
2948
|
+
awareness()
|
|
2949
|
+
].filter(isNotNullOrUndefined),
|
|
2950
|
+
peer: identity ? {
|
|
2951
|
+
id: identity.identityKey.toHex(),
|
|
2952
|
+
name: identity.profile?.displayName
|
|
2953
|
+
} : void 0
|
|
2954
|
+
};
|
|
2955
|
+
return model;
|
|
2956
|
+
};
|
|
2547
2957
|
export {
|
|
2958
|
+
AwarenessProvider,
|
|
2548
2959
|
BaseTextEditor,
|
|
2960
|
+
Cursor,
|
|
2549
2961
|
Doc,
|
|
2550
2962
|
EditorModes,
|
|
2551
2963
|
MarkdownEditor,
|
|
2964
|
+
RemoteSelectionsDecorator,
|
|
2552
2965
|
SpaceAwarenessProvider,
|
|
2553
2966
|
TextEditor,
|
|
2554
2967
|
TextKind,
|
|
2968
|
+
YAwarenessProvider,
|
|
2555
2969
|
YText,
|
|
2556
2970
|
YXmlFragment,
|
|
2557
2971
|
autocomplete,
|
|
2972
|
+
automerge3 as automerge,
|
|
2973
|
+
awareness,
|
|
2558
2974
|
basicBundle,
|
|
2559
2975
|
blast,
|
|
2976
|
+
callbackWrapper,
|
|
2560
2977
|
code2 as code,
|
|
2561
2978
|
codeTheme,
|
|
2562
2979
|
comments,
|
|
2563
|
-
|
|
2980
|
+
createAutomergeModel,
|
|
2981
|
+
createYjsModel,
|
|
2564
2982
|
defaultMarkdownSlots,
|
|
2565
2983
|
defaultOptions,
|
|
2566
2984
|
defaultSlots,
|
|
2567
2985
|
defaultTextSlots,
|
|
2568
2986
|
defaultTheme,
|
|
2987
|
+
getToken,
|
|
2569
2988
|
hr,
|
|
2570
2989
|
image,
|
|
2571
2990
|
link,
|
|
@@ -2576,15 +2995,16 @@ export {
|
|
|
2576
2995
|
markdownTagsExtensions,
|
|
2577
2996
|
markdownTheme,
|
|
2578
2997
|
mention,
|
|
2579
|
-
mermaid,
|
|
2580
2998
|
modelState,
|
|
2581
2999
|
setCommentRange,
|
|
3000
|
+
setFocus,
|
|
3001
|
+
setSelection,
|
|
2582
3002
|
table,
|
|
2583
3003
|
tags2 as tags,
|
|
2584
3004
|
tasklist,
|
|
2585
3005
|
textTheme,
|
|
2586
|
-
tooltip,
|
|
2587
3006
|
typewriter,
|
|
2588
|
-
useTextModel
|
|
3007
|
+
useTextModel,
|
|
3008
|
+
yjs
|
|
2589
3009
|
};
|
|
2590
3010
|
//# sourceMappingURL=index.mjs.map
|