@dxos/react-ui-editor 0.3.11-main.3f845e1 → 0.3.11-main.42059c4
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 +1804 -1399
- 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/extensions/automerge/semaphore.d.ts +14 -0
- package/dist/types/src/extensions/automerge/semaphore.d.ts.map +1 -0
- package/dist/types/src/extensions/automerge/update-automerge.d.ts +5 -0
- package/dist/types/src/extensions/automerge/update-automerge.d.ts.map +1 -0
- package/dist/types/src/extensions/automerge/update-codemirror.d.ts.map +1 -0
- package/dist/types/src/extensions/awareness.d.ts +46 -0
- package/dist/types/src/extensions/awareness.d.ts.map +1 -0
- package/dist/types/src/extensions/basic.d.ts.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 +18 -7
- 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 +3 -1
- 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 +355 -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 +66 -0
- package/src/extensions/automerge/index.ts +6 -0
- package/src/{hooks → extensions}/automerge/semaphore.ts +23 -23
- 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 +151 -137
- 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 +4 -1
- 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 +0 -19
- package/dist/types/src/hooks/automerge/semaphore.d.ts.map +0 -1
- package/dist/types/src/hooks/automerge/update-automerge.d.ts +0 -6
- package/dist/types/src/hooks/automerge/update-automerge.d.ts.map +0 -1
- package/dist/types/src/hooks/automerge/update-codemirror.d.ts.map +0 -1
- package/dist/types/src/hooks/yjs/cursors.d.ts.map +0 -1
- package/dist/types/src/hooks/yjs/index.d.ts +0 -3
- package/dist/types/src/hooks/yjs/index.d.ts.map +0 -1
- package/dist/types/src/hooks/yjs/space-provider.d.ts.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 { 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, Facet } 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
|
+
var semaphoreFacet = Facet.define({
|
|
105
|
+
combine: (values) => values.at(-1)
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
// packages/ui/react-ui-editor/src/extensions/automerge/semaphore.ts
|
|
109
|
+
import { next as automerge2 } from "@dxos/automerge/automerge";
|
|
110
|
+
|
|
111
|
+
// packages/ui/react-ui-editor/src/extensions/automerge/update-automerge.ts
|
|
112
|
+
import { next as am } from "@dxos/automerge/automerge";
|
|
113
|
+
var updateAutomerge = (field, handle, transactions, state) => {
|
|
114
|
+
const { lastHeads, path } = state.field(field);
|
|
115
|
+
let hasChanges = false;
|
|
116
|
+
for (const tr of transactions) {
|
|
117
|
+
tr.changes.iterChanges(() => {
|
|
118
|
+
hasChanges = true;
|
|
233
119
|
});
|
|
234
|
-
this._running = true;
|
|
235
|
-
this.loop();
|
|
236
120
|
}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
this._node.style.transform = "translate(0px, 0px)";
|
|
121
|
+
if (!hasChanges) {
|
|
122
|
+
return void 0;
|
|
240
123
|
}
|
|
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)`;
|
|
124
|
+
const newHeads = handle.changeAt(lastHeads, (doc) => {
|
|
125
|
+
for (const tr of transactions) {
|
|
126
|
+
tr.changes.iterChanges((fromA, toA, _fromB, _toB, inserted) => {
|
|
127
|
+
am.splice(doc, path, fromA, toA - fromA, inserted.toString());
|
|
128
|
+
});
|
|
256
129
|
}
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
130
|
+
});
|
|
131
|
+
return newHeads ?? void 0;
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
// packages/ui/react-ui-editor/src/extensions/automerge/update-codemirror.ts
|
|
135
|
+
import { ChangeSet } from "@codemirror/state";
|
|
136
|
+
var updateCodeMirror = (view, selection, target, patches) => {
|
|
137
|
+
for (const patch of patches) {
|
|
138
|
+
const changeSpec = handlePatch(patch, target, view.state);
|
|
139
|
+
if (changeSpec != null) {
|
|
140
|
+
const changeSet = ChangeSet.of(changeSpec, view.state.doc.length, "\n");
|
|
141
|
+
selection = selection.map(changeSet, 1);
|
|
142
|
+
view.dispatch({
|
|
143
|
+
changes: changeSet,
|
|
144
|
+
annotations: reconcileAnnotationType.of({})
|
|
145
|
+
});
|
|
270
146
|
}
|
|
271
147
|
}
|
|
148
|
+
view.dispatch({
|
|
149
|
+
selection,
|
|
150
|
+
annotations: reconcileAnnotationType.of({})
|
|
151
|
+
});
|
|
272
152
|
};
|
|
273
|
-
var
|
|
274
|
-
|
|
275
|
-
|
|
153
|
+
var handlePatch = (patch, target, state) => {
|
|
154
|
+
if (patch.action === "insert") {
|
|
155
|
+
return handleInsert(target, patch);
|
|
156
|
+
} else if (patch.action === "splice") {
|
|
157
|
+
return handleSplice(target, patch);
|
|
158
|
+
} else if (patch.action === "del") {
|
|
159
|
+
return handleDel(target, patch);
|
|
160
|
+
} else if (patch.action === "put") {
|
|
161
|
+
return handlePut(target, patch, state);
|
|
162
|
+
} else {
|
|
163
|
+
return null;
|
|
276
164
|
}
|
|
277
165
|
};
|
|
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);
|
|
166
|
+
var handleInsert = (target, patch) => {
|
|
167
|
+
const index = charPath(target, patch.path);
|
|
168
|
+
if (index == null) {
|
|
169
|
+
return [];
|
|
297
170
|
}
|
|
171
|
+
const text = patch.values.map((v) => v ? v.toString() : "").join("");
|
|
172
|
+
return [
|
|
173
|
+
{
|
|
174
|
+
from: index,
|
|
175
|
+
to: index,
|
|
176
|
+
insert: text
|
|
177
|
+
}
|
|
178
|
+
];
|
|
298
179
|
};
|
|
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();
|
|
180
|
+
var handleSplice = (target, patch) => {
|
|
181
|
+
const index = charPath(target, patch.path);
|
|
182
|
+
if (index == null) {
|
|
183
|
+
return [];
|
|
329
184
|
}
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
if (!wait) {
|
|
335
|
-
callback.apply(this, args);
|
|
336
|
-
wait = true;
|
|
337
|
-
setTimeout(() => {
|
|
338
|
-
wait = false;
|
|
339
|
-
}, limit);
|
|
185
|
+
return [
|
|
186
|
+
{
|
|
187
|
+
from: index,
|
|
188
|
+
insert: patch.value
|
|
340
189
|
}
|
|
341
|
-
|
|
342
|
-
}
|
|
343
|
-
var
|
|
344
|
-
|
|
345
|
-
|
|
190
|
+
];
|
|
191
|
+
};
|
|
192
|
+
var handleDel = (target, patch) => {
|
|
193
|
+
const index = charPath(target, patch.path);
|
|
194
|
+
if (index == null) {
|
|
195
|
+
return [];
|
|
346
196
|
}
|
|
347
|
-
const
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
197
|
+
const length = patch.length || 1;
|
|
198
|
+
return [
|
|
199
|
+
{
|
|
200
|
+
from: index,
|
|
201
|
+
to: index + length
|
|
352
202
|
}
|
|
203
|
+
];
|
|
204
|
+
};
|
|
205
|
+
var handlePut = (target, patch, state) => {
|
|
206
|
+
const index = charPath(target, [
|
|
207
|
+
...patch.path,
|
|
208
|
+
0
|
|
209
|
+
]);
|
|
210
|
+
if (index == null) {
|
|
211
|
+
return [];
|
|
212
|
+
}
|
|
213
|
+
const length = state.doc.length;
|
|
214
|
+
if (typeof patch.value !== "string") {
|
|
215
|
+
return [];
|
|
353
216
|
}
|
|
354
217
|
return [
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
218
|
+
{
|
|
219
|
+
from: 0,
|
|
220
|
+
to: length,
|
|
221
|
+
insert: patch.value
|
|
222
|
+
}
|
|
358
223
|
];
|
|
359
224
|
};
|
|
360
|
-
var
|
|
361
|
-
if (
|
|
362
|
-
|
|
363
|
-
min = 0;
|
|
225
|
+
var charPath = (textPath, candidatePath) => {
|
|
226
|
+
if (candidatePath.length !== textPath.length + 1) {
|
|
227
|
+
return null;
|
|
364
228
|
}
|
|
365
|
-
|
|
229
|
+
for (let i = 0; i < textPath.length; i++) {
|
|
230
|
+
if (textPath[i] !== candidatePath[i]) {
|
|
231
|
+
return null;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
const index = candidatePath[candidatePath.length - 1];
|
|
235
|
+
if (typeof index === "number") {
|
|
236
|
+
return index;
|
|
237
|
+
}
|
|
238
|
+
return null;
|
|
366
239
|
};
|
|
367
240
|
|
|
368
|
-
// packages/ui/react-ui-editor/src/
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
241
|
+
// packages/ui/react-ui-editor/src/extensions/automerge/semaphore.ts
|
|
242
|
+
var PatchSemaphore = class {
|
|
243
|
+
constructor(_handle, _field) {
|
|
244
|
+
this._handle = _handle;
|
|
245
|
+
this._field = _field;
|
|
246
|
+
this._inReconcile = false;
|
|
247
|
+
this.reconcile = (view) => {
|
|
248
|
+
if (this._inReconcile) {
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
this._inReconcile = true;
|
|
252
|
+
const path = getPath(view.state, this._field);
|
|
253
|
+
const oldHeads = getLastHeads(view.state, this._field);
|
|
254
|
+
let selection = view.state.selection;
|
|
255
|
+
const transactions = view.state.field(this._field).unreconciledTransactions.filter((tx) => !isReconcileTx(tx));
|
|
256
|
+
const toInvert = transactions.slice().reverse();
|
|
257
|
+
for (const tx of toInvert) {
|
|
258
|
+
const inverted = tx.changes.invert(tx.startState.doc);
|
|
259
|
+
selection = selection.map(inverted);
|
|
260
|
+
view.dispatch({
|
|
261
|
+
changes: inverted,
|
|
262
|
+
annotations: reconcileAnnotationType.of(true)
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
let newHeads = updateAutomerge(this._field, this._handle, transactions, view.state);
|
|
266
|
+
if (newHeads === null || newHeads === void 0) {
|
|
267
|
+
newHeads = automerge2.getHeads(this._handle.docSync());
|
|
268
|
+
}
|
|
269
|
+
const diff = automerge2.equals(oldHeads, newHeads) ? [] : automerge2.diff(this._handle.docSync(), oldHeads, newHeads);
|
|
270
|
+
updateCodeMirror(view, selection, path, diff);
|
|
271
|
+
view.dispatch({
|
|
272
|
+
effects: updateHeads(newHeads),
|
|
273
|
+
annotations: reconcileAnnotationType.of({})
|
|
274
|
+
});
|
|
275
|
+
this._inReconcile = false;
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
};
|
|
372
279
|
|
|
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
|
-
]
|
|
280
|
+
// packages/ui/react-ui-editor/src/extensions/cursor.ts
|
|
281
|
+
import { Facet as Facet2 } from "@codemirror/state";
|
|
282
|
+
var defaultCursorConverter = {
|
|
283
|
+
toCursor: (position) => position.toString(),
|
|
284
|
+
fromCursor: (cursor) => parseInt(cursor)
|
|
400
285
|
};
|
|
401
|
-
var
|
|
402
|
-
|
|
403
|
-
|
|
286
|
+
var Cursor = class {
|
|
287
|
+
static {
|
|
288
|
+
this.converter = Facet2.define({
|
|
289
|
+
combine: (providers) => providers[0] ?? defaultCursorConverter
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
static {
|
|
293
|
+
this.getCursorFromRange = (cursorConverter3, range) => {
|
|
294
|
+
const from = cursorConverter3.toCursor(range.from);
|
|
295
|
+
const to = cursorConverter3.toCursor(range.to, -1);
|
|
296
|
+
return [
|
|
297
|
+
from,
|
|
298
|
+
to
|
|
299
|
+
].join(":");
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
static {
|
|
303
|
+
this.getRangeFromCursor = (cursorConverter3, cursor) => {
|
|
304
|
+
const parts = cursor.split(":");
|
|
305
|
+
const from = cursorConverter3.fromCursor(parts[0]);
|
|
306
|
+
const to = cursorConverter3.fromCursor(parts[1]);
|
|
307
|
+
return from !== void 0 && to !== void 0 ? {
|
|
308
|
+
from,
|
|
309
|
+
to
|
|
310
|
+
} : void 0;
|
|
311
|
+
};
|
|
312
|
+
}
|
|
404
313
|
};
|
|
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
314
|
|
|
415
|
-
// packages/ui/react-ui-editor/src/
|
|
416
|
-
|
|
417
|
-
|
|
315
|
+
// packages/ui/react-ui-editor/src/extensions/automerge/automerge.ts
|
|
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);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
return result;
|
|
344
|
+
}
|
|
345
|
+
});
|
|
346
|
+
const semaphore = new PatchSemaphore(handle, stateField);
|
|
347
|
+
const viewPlugin = ViewPlugin.fromClass(class AutomergeViewPlugin {
|
|
348
|
+
constructor(_view) {
|
|
349
|
+
this._view = _view;
|
|
350
|
+
this._handleChange = () => {
|
|
351
|
+
this._view.state.facet(semaphoreFacet).reconcile(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(this._view);
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
destroy() {
|
|
363
|
+
handle.addListener("change", this._handleChange);
|
|
364
|
+
}
|
|
365
|
+
});
|
|
366
|
+
return {
|
|
367
|
+
extension: [
|
|
368
|
+
Cursor.converter.of(cursorConverter(handle, path)),
|
|
369
|
+
semaphoreFacet.of(semaphore),
|
|
370
|
+
stateField,
|
|
371
|
+
viewPlugin
|
|
372
|
+
]
|
|
373
|
+
};
|
|
374
|
+
};
|
|
418
375
|
|
|
419
|
-
// packages/ui/react-ui-editor/src/
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
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: () => {
|
|
424
384
|
},
|
|
425
|
-
|
|
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"
|
|
385
|
+
close: () => {
|
|
434
386
|
},
|
|
435
|
-
|
|
436
|
-
paddingTop: "4px !important",
|
|
437
|
-
borderTopLeftRadius: "4px",
|
|
438
|
-
borderTopRightRadius: "4px"
|
|
387
|
+
update: () => {
|
|
439
388
|
},
|
|
440
|
-
|
|
441
|
-
paddingBottom: "4px !important",
|
|
442
|
-
borderBottomLeftRadius: "4px",
|
|
443
|
-
borderBottomRightRadius: "4px"
|
|
444
|
-
}
|
|
445
|
-
});
|
|
446
|
-
var getLineRange = (lines, from, to) => {
|
|
447
|
-
const start = lines.findIndex((line) => line.from >= from);
|
|
448
|
-
const end = lines.findIndex((line) => line.to >= to);
|
|
449
|
-
return [
|
|
450
|
-
start,
|
|
451
|
-
end
|
|
452
|
-
];
|
|
389
|
+
getRemoteStates: () => []
|
|
453
390
|
};
|
|
454
|
-
var
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
const matches = text.matchAll(CODE_REGEX);
|
|
460
|
-
const blocks = view.viewportLineBlocks;
|
|
461
|
-
for (const match of matches) {
|
|
462
|
-
const range = getLineRange(blocks, match.index, match.index + match[0].length);
|
|
463
|
-
for (let i = range[0]; i <= range[1]; i++) {
|
|
464
|
-
const block = blocks[i];
|
|
465
|
-
decorations.push(Decoration.line({
|
|
466
|
-
class: mx2("cm-codeblock", i === range[0] && "cm-codeblock-first", i === range[1] && "cm-codeblock-last")
|
|
467
|
-
}).range(block.from));
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
return Decoration.set(decorations);
|
|
472
|
-
};
|
|
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;
|
|
833
|
+
}
|
|
834
|
+
if (particle.alpha < 0.01 || particle.size <= 0.5) {
|
|
835
|
+
continue;
|
|
758
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
|
+
];
|
|
771
927
|
};
|
|
772
|
-
var
|
|
773
|
-
|
|
928
|
+
var random = (min, max) => {
|
|
929
|
+
if (!max) {
|
|
930
|
+
max = min;
|
|
931
|
+
min = 0;
|
|
932
|
+
}
|
|
933
|
+
return min + ~~(Math.random() * (max - min + 1));
|
|
934
|
+
};
|
|
935
|
+
|
|
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";
|
|
774
939
|
|
|
775
|
-
// packages/ui/react-ui-editor/src/
|
|
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,196 @@ 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
|
-
}
|
|
911
|
-
};
|
|
912
|
-
|
|
913
|
-
// packages/ui/react-ui-editor/src/hooks/useTextModel.ts
|
|
914
|
-
var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/hooks/useTextModel.ts";
|
|
915
|
-
var modelState = StateField2.define({
|
|
916
|
-
create: () => void 0,
|
|
917
|
-
update: (model) => model
|
|
918
|
-
});
|
|
919
|
-
var useTextModel = (props) => {
|
|
920
|
-
const { identity, space, text } = props;
|
|
921
|
-
const [model, setModel] = useState(() => createModel(props));
|
|
922
|
-
useEffect(() => setModel(createModel(props)), [
|
|
923
|
-
identity,
|
|
924
|
-
space,
|
|
925
|
-
text
|
|
926
|
-
]);
|
|
927
|
-
return model;
|
|
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
|
+
]
|
|
928
1005
|
};
|
|
929
|
-
var
|
|
930
|
-
const
|
|
931
|
-
|
|
932
|
-
return createAutomergeModel(props);
|
|
933
|
-
} else {
|
|
934
|
-
if (!text?.doc) {
|
|
935
|
-
return void 0;
|
|
936
|
-
}
|
|
937
|
-
return createYjsModel(props);
|
|
938
|
-
}
|
|
1006
|
+
var heading = (level, readonly) => {
|
|
1007
|
+
const [style, offset] = headings[level];
|
|
1008
|
+
return mx(style, readonly && offset);
|
|
939
1009
|
};
|
|
940
|
-
var
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
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);
|
|
1019
|
+
|
|
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
|
+
}
|
|
1052
|
+
});
|
|
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
|
+
];
|
|
988
1060
|
};
|
|
989
|
-
var
|
|
990
|
-
const
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
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
|
+
}
|
|
1077
|
+
}
|
|
1078
|
+
return Decoration2.set(decorations);
|
|
1007
1079
|
};
|
|
1008
|
-
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
|
+
];
|
|
1009
1100
|
};
|
|
1010
1101
|
|
|
1011
|
-
// packages/ui/react-ui-editor/src/
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
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 { nonNullable } from "@dxos/util";
|
|
1109
|
+
|
|
1110
|
+
// packages/ui/react-ui-editor/src/util.ts
|
|
1111
|
+
import { log } from "@dxos/log";
|
|
1112
|
+
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/util.ts";
|
|
1113
|
+
var callbackWrapper = (fn) => (...args) => {
|
|
1114
|
+
try {
|
|
1115
|
+
return fn(...args);
|
|
1116
|
+
} catch (error) {
|
|
1117
|
+
log.catch(error, void 0, {
|
|
1118
|
+
F: __dxlog_file2,
|
|
1119
|
+
L: 16,
|
|
1120
|
+
S: void 0,
|
|
1121
|
+
C: (f, a) => f(...a)
|
|
1122
|
+
});
|
|
1123
|
+
}
|
|
1124
|
+
};
|
|
1125
|
+
|
|
1126
|
+
// packages/ui/react-ui-editor/src/extensions/comments.ts
|
|
1127
|
+
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/extensions/comments.ts";
|
|
1128
|
+
var styles3 = EditorView5.baseTheme({
|
|
1023
1129
|
"& .cm-comment": {
|
|
1024
|
-
backgroundColor: "yellow"
|
|
1130
|
+
backgroundColor: getToken("extend.colors.yellow.50")
|
|
1025
1131
|
},
|
|
1026
1132
|
"& .cm-comment-active": {
|
|
1027
|
-
backgroundColor: "
|
|
1133
|
+
backgroundColor: getToken("extend.colors.yellow.100")
|
|
1028
1134
|
}
|
|
1029
1135
|
});
|
|
1030
1136
|
var marks = {
|
|
1031
|
-
highlight:
|
|
1137
|
+
highlight: Decoration3.mark({
|
|
1032
1138
|
class: "cm-comment"
|
|
1033
1139
|
}),
|
|
1034
|
-
highlightActive:
|
|
1140
|
+
highlightActive: Decoration3.mark({
|
|
1035
1141
|
class: "cm-comment-active"
|
|
1036
1142
|
})
|
|
1037
1143
|
};
|
|
1144
|
+
var setFocus = (view, thread) => {
|
|
1145
|
+
const range = view.state.field(commentsStateField).ranges.find((range2) => range2.id === thread);
|
|
1146
|
+
if (!range) {
|
|
1147
|
+
return;
|
|
1148
|
+
}
|
|
1149
|
+
view.dispatch({
|
|
1150
|
+
effects: setSelection.of({
|
|
1151
|
+
active: thread
|
|
1152
|
+
}),
|
|
1153
|
+
selection: {
|
|
1154
|
+
anchor: range.from
|
|
1155
|
+
},
|
|
1156
|
+
scrollIntoView: true
|
|
1157
|
+
});
|
|
1158
|
+
};
|
|
1038
1159
|
var setCommentRange = StateEffect2.define();
|
|
1039
1160
|
var setSelection = StateEffect2.define();
|
|
1040
1161
|
var setCommentState = StateEffect2.define();
|
|
1041
|
-
var commentsStateField =
|
|
1162
|
+
var commentsStateField = StateField2.define({
|
|
1042
1163
|
create: () => ({
|
|
1043
1164
|
ranges: []
|
|
1044
1165
|
}),
|
|
1045
1166
|
update: (value, tr) => {
|
|
1167
|
+
const cursorConverter3 = tr.state.facet(Cursor.converter);
|
|
1046
1168
|
for (const effect of tr.effects) {
|
|
1047
1169
|
if (effect.is(setSelection)) {
|
|
1048
1170
|
return {
|
|
@@ -1050,15 +1172,15 @@ var commentsStateField = StateField3.define({
|
|
|
1050
1172
|
...effect.value
|
|
1051
1173
|
};
|
|
1052
1174
|
}
|
|
1053
|
-
if (effect.is(setCommentRange)) {
|
|
1054
|
-
const {
|
|
1175
|
+
if (effect.is(setCommentRange) && effect.value.comments.length > 0) {
|
|
1176
|
+
const { comments: comments2 } = effect.value;
|
|
1055
1177
|
const ranges = comments2.map((comment) => {
|
|
1056
|
-
const range =
|
|
1057
|
-
return {
|
|
1178
|
+
const range = Cursor.getRangeFromCursor(cursorConverter3, comment.cursor);
|
|
1179
|
+
return range && {
|
|
1058
1180
|
...comment,
|
|
1059
1181
|
...range
|
|
1060
1182
|
};
|
|
1061
|
-
});
|
|
1183
|
+
}).filter(nonNullable);
|
|
1062
1184
|
return {
|
|
1063
1185
|
...value,
|
|
1064
1186
|
ranges
|
|
@@ -1071,7 +1193,7 @@ var commentsStateField = StateField3.define({
|
|
|
1071
1193
|
return value;
|
|
1072
1194
|
}
|
|
1073
1195
|
});
|
|
1074
|
-
var highlightDecorations =
|
|
1196
|
+
var highlightDecorations = EditorView5.decorations.compute([
|
|
1075
1197
|
commentsStateField
|
|
1076
1198
|
], (state) => {
|
|
1077
1199
|
const { active, ranges } = state.field(commentsStateField);
|
|
@@ -1089,60 +1211,91 @@ var highlightDecorations = EditorView4.decorations.compute([
|
|
|
1089
1211
|
return marks.highlight.range(range.from, range.to);
|
|
1090
1212
|
}
|
|
1091
1213
|
}).filter(nonNullable) ?? [];
|
|
1092
|
-
return
|
|
1214
|
+
return Decoration3.set(decorations);
|
|
1093
1215
|
});
|
|
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();
|
|
1216
|
+
var trackPastedComments = (onUpdate) => {
|
|
1217
|
+
let tracked = null;
|
|
1218
|
+
const handleTrack = (event, view) => {
|
|
1219
|
+
const comments2 = view.state.field(commentsStateField);
|
|
1220
|
+
const { main } = view.state.selection;
|
|
1221
|
+
const selectedRanges = comments2.ranges.filter((range) => range.from >= main.from && range.to <= main.to && range.from < range.to);
|
|
1222
|
+
if (!selectedRanges.length) {
|
|
1223
|
+
tracked = null;
|
|
1224
|
+
} else {
|
|
1225
|
+
tracked = {
|
|
1226
|
+
text: view.state.doc.slice(main.from, main.to),
|
|
1227
|
+
comments: selectedRanges.map((range) => ({
|
|
1228
|
+
id: range.id,
|
|
1229
|
+
from: range.from - main.from,
|
|
1230
|
+
to: range.to - main.from
|
|
1231
|
+
}))
|
|
1232
|
+
};
|
|
1119
1233
|
}
|
|
1120
|
-
|
|
1121
|
-
|
|
1234
|
+
};
|
|
1235
|
+
return [
|
|
1236
|
+
EditorView5.domEventHandlers({
|
|
1237
|
+
cut: handleTrack,
|
|
1238
|
+
copy: handleTrack
|
|
1239
|
+
}),
|
|
1240
|
+
// Handle paste.
|
|
1241
|
+
EditorView5.updateListener.of(({ view, state, transactions }) => {
|
|
1242
|
+
if (tracked) {
|
|
1243
|
+
const paste = 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 = transactions.indexOf(paste) + 1; i < transactions.length; i++) {
|
|
1249
|
+
fromB = transactions[i].changes.mapPos(fromB);
|
|
1250
|
+
}
|
|
1251
|
+
found = fromB;
|
|
1252
|
+
}
|
|
1253
|
+
});
|
|
1254
|
+
if (found > -1) {
|
|
1255
|
+
const comments2 = tracked.comments;
|
|
1256
|
+
view.state.facet(semaphoreFacet).reconcile(view);
|
|
1257
|
+
const active = state.field(commentsStateField).ranges;
|
|
1258
|
+
for (const moved of comments2) {
|
|
1259
|
+
if (active.some((range) => range.id === moved.id && range.from === range.to)) {
|
|
1260
|
+
const range = {
|
|
1261
|
+
from: found + moved.from,
|
|
1262
|
+
to: found + moved.to
|
|
1263
|
+
};
|
|
1264
|
+
const cursor = Cursor.getCursorFromRange(state.facet(Cursor.converter), range);
|
|
1265
|
+
onUpdate(moved.id, cursor);
|
|
1266
|
+
}
|
|
1267
|
+
}
|
|
1268
|
+
}
|
|
1269
|
+
tracked = null;
|
|
1270
|
+
}
|
|
1271
|
+
}
|
|
1272
|
+
})
|
|
1273
|
+
];
|
|
1122
1274
|
};
|
|
1123
1275
|
var comments = (options = {}) => {
|
|
1276
|
+
const { key: shortcut = "meta-'" } = options;
|
|
1124
1277
|
const handleSelect = debounce((state) => options.onSelect?.(state), 200);
|
|
1125
1278
|
const createCommentThread = (view) => {
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1279
|
+
const cursorConverter3 = view.state.facet(Cursor.converter);
|
|
1280
|
+
invariant2(options.onCreate, void 0, {
|
|
1281
|
+
F: __dxlog_file3,
|
|
1282
|
+
L: 262,
|
|
1129
1283
|
S: void 0,
|
|
1130
1284
|
A: [
|
|
1131
1285
|
"options.onCreate",
|
|
1132
1286
|
""
|
|
1133
1287
|
]
|
|
1134
1288
|
});
|
|
1135
|
-
const {
|
|
1289
|
+
const { from, to } = view.state.selection.main;
|
|
1136
1290
|
if (from === to) {
|
|
1137
1291
|
return false;
|
|
1138
1292
|
}
|
|
1139
|
-
const
|
|
1140
|
-
const relPos = model?.getCursorFromRange?.({
|
|
1293
|
+
const cursor = Cursor.getCursorFromRange(cursorConverter3, {
|
|
1141
1294
|
from,
|
|
1142
1295
|
to
|
|
1143
1296
|
});
|
|
1144
|
-
if (
|
|
1145
|
-
const id = callbackWrapper(options.onCreate)(
|
|
1297
|
+
if (cursor) {
|
|
1298
|
+
const id = callbackWrapper(options.onCreate)(cursor, view.coordsAtPos(from));
|
|
1146
1299
|
if (id) {
|
|
1147
1300
|
view.dispatch({
|
|
1148
1301
|
effects: setSelection.of({
|
|
@@ -1152,62 +1305,22 @@ var comments = (options = {}) => {
|
|
|
1152
1305
|
anchor: from
|
|
1153
1306
|
}
|
|
1154
1307
|
});
|
|
1155
|
-
if (options.footnote) {
|
|
1156
|
-
const tag = `[^${id}]`;
|
|
1157
|
-
view.dispatch({
|
|
1158
|
-
changes: {
|
|
1159
|
-
from: head,
|
|
1160
|
-
insert: tag
|
|
1161
|
-
},
|
|
1162
|
-
selection: {
|
|
1163
|
-
anchor: head + tag.length
|
|
1164
|
-
}
|
|
1165
|
-
});
|
|
1166
|
-
}
|
|
1167
1308
|
return true;
|
|
1168
1309
|
}
|
|
1169
1310
|
}
|
|
1170
1311
|
return false;
|
|
1171
1312
|
};
|
|
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
1313
|
return [
|
|
1200
|
-
bookmarksViewPlugin,
|
|
1201
1314
|
commentsStateField,
|
|
1202
1315
|
highlightDecorations,
|
|
1203
|
-
|
|
1316
|
+
styles3,
|
|
1204
1317
|
//
|
|
1205
1318
|
// Keymap.
|
|
1206
1319
|
//
|
|
1207
1320
|
options.onCreate ? keymap3.of([
|
|
1208
1321
|
{
|
|
1209
|
-
key:
|
|
1210
|
-
run: createCommentThread
|
|
1322
|
+
key: shortcut,
|
|
1323
|
+
run: callbackWrapper(createCommentThread)
|
|
1211
1324
|
}
|
|
1212
1325
|
]) : [],
|
|
1213
1326
|
//
|
|
@@ -1223,7 +1336,7 @@ var comments = (options = {}) => {
|
|
|
1223
1336
|
above: true,
|
|
1224
1337
|
create: () => {
|
|
1225
1338
|
const el = document.createElement("div");
|
|
1226
|
-
options.onHover?.(el);
|
|
1339
|
+
options.onHover?.(el, shortcut);
|
|
1227
1340
|
return {
|
|
1228
1341
|
dom: el,
|
|
1229
1342
|
offset: {
|
|
@@ -1243,37 +1356,21 @@ var comments = (options = {}) => {
|
|
|
1243
1356
|
// Monitor cursor movement and text updates.
|
|
1244
1357
|
// TODO(burdon): Is there a better (finer grained) way to do this?
|
|
1245
1358
|
//
|
|
1246
|
-
|
|
1359
|
+
EditorView5.updateListener.of(({ view, state, changes }) => {
|
|
1360
|
+
const cursorConverter3 = view.state.facet(Cursor.converter);
|
|
1247
1361
|
{
|
|
1248
1362
|
let mod = false;
|
|
1249
|
-
const model = state.field(modelState);
|
|
1250
1363
|
const { active, ranges } = state.field(commentsStateField);
|
|
1251
1364
|
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
1365
|
ranges.forEach((range) => {
|
|
1262
1366
|
if (from2 === to2) {
|
|
1263
|
-
const newRange =
|
|
1264
|
-
if (newRange.to - newRange.from === 0) {
|
|
1265
|
-
|
|
1266
|
-
thread: range.id
|
|
1267
|
-
}, {
|
|
1268
|
-
F: __dxlog_file5,
|
|
1269
|
-
L: 339,
|
|
1270
|
-
S: void 0,
|
|
1271
|
-
C: (f, a) => f(...a)
|
|
1272
|
-
});
|
|
1367
|
+
const newRange = Cursor.getRangeFromCursor(cursorConverter3, range.cursor);
|
|
1368
|
+
if (!newRange || newRange.to - newRange.from === 0) {
|
|
1369
|
+
options.onDelete?.(range.id);
|
|
1273
1370
|
}
|
|
1274
1371
|
}
|
|
1275
1372
|
if (from <= range.to) {
|
|
1276
|
-
const newRange =
|
|
1373
|
+
const newRange = Cursor.getRangeFromCursor(cursorConverter3, range.cursor);
|
|
1277
1374
|
Object.assign(range, newRange);
|
|
1278
1375
|
mod = true;
|
|
1279
1376
|
}
|
|
@@ -1319,18 +1416,18 @@ var comments = (options = {}) => {
|
|
|
1319
1416
|
});
|
|
1320
1417
|
}
|
|
1321
1418
|
}
|
|
1322
|
-
})
|
|
1419
|
+
}),
|
|
1420
|
+
options.onUpdate ? trackPastedComments(options.onUpdate) : []
|
|
1323
1421
|
];
|
|
1324
1422
|
};
|
|
1325
1423
|
|
|
1326
|
-
// packages/ui/react-ui-editor/src/
|
|
1327
|
-
import { Decoration as
|
|
1328
|
-
|
|
1329
|
-
var styles3 = EditorView5.baseTheme({
|
|
1424
|
+
// packages/ui/react-ui-editor/src/extensions/hr.ts
|
|
1425
|
+
import { Decoration as Decoration4, EditorView as EditorView6, MatchDecorator, ViewPlugin as ViewPlugin4, WidgetType as WidgetType2 } from "@codemirror/view";
|
|
1426
|
+
var styles4 = EditorView6.baseTheme({
|
|
1330
1427
|
"& .cm-hr": {
|
|
1331
1428
|
// TODO(burdon): ???
|
|
1332
1429
|
// Note that block-level decorations should not have vertical margins,
|
|
1333
|
-
borderBottom: `1px solid ${
|
|
1430
|
+
borderBottom: `1px solid ${getToken("extend.colors.neutral.200")}`
|
|
1334
1431
|
}
|
|
1335
1432
|
});
|
|
1336
1433
|
var HorizontalRuleWidget = class extends WidgetType2 {
|
|
@@ -1347,43 +1444,65 @@ var HorizontalRuleWidget = class extends WidgetType2 {
|
|
|
1347
1444
|
return el;
|
|
1348
1445
|
}
|
|
1349
1446
|
};
|
|
1350
|
-
var placeholderMatcher = new
|
|
1447
|
+
var placeholderMatcher = new MatchDecorator({
|
|
1351
1448
|
regexp: /^---$/g,
|
|
1352
|
-
decoration: (match, view, pos) =>
|
|
1449
|
+
decoration: (match, view, pos) => Decoration4.replace({
|
|
1353
1450
|
widget: new HorizontalRuleWidget(pos)
|
|
1354
1451
|
})
|
|
1355
1452
|
});
|
|
1356
1453
|
var hr = () => [
|
|
1357
|
-
|
|
1454
|
+
styles4,
|
|
1358
1455
|
ViewPlugin4.fromClass(class {
|
|
1359
1456
|
constructor(view) {
|
|
1360
1457
|
this.rules = placeholderMatcher.createDeco(view);
|
|
1361
1458
|
}
|
|
1362
|
-
update(
|
|
1363
|
-
this.rules = placeholderMatcher.updateDeco(
|
|
1459
|
+
update(update2) {
|
|
1460
|
+
this.rules = placeholderMatcher.updateDeco(update2, this.rules);
|
|
1364
1461
|
}
|
|
1365
1462
|
}, {
|
|
1366
1463
|
decorations: (instance) => instance.rules,
|
|
1367
1464
|
// TODO(burdon): Is this really atomic (cursor can move into ---).
|
|
1368
|
-
provide: (plugin) =>
|
|
1369
|
-
return view.plugin(plugin)?.rules ||
|
|
1465
|
+
provide: (plugin) => EditorView6.atomicRanges.of((view) => {
|
|
1466
|
+
return view.plugin(plugin)?.rules || Decoration4.none;
|
|
1370
1467
|
})
|
|
1371
1468
|
})
|
|
1372
1469
|
];
|
|
1373
1470
|
|
|
1374
|
-
// packages/ui/react-ui-editor/src/
|
|
1471
|
+
// packages/ui/react-ui-editor/src/extensions/image.ts
|
|
1375
1472
|
import { syntaxTree } from "@codemirror/language";
|
|
1376
|
-
import {
|
|
1377
|
-
import { Decoration as
|
|
1473
|
+
import { StateField as StateField3 } from "@codemirror/state";
|
|
1474
|
+
import { Decoration as Decoration5, EditorView as EditorView7, WidgetType as WidgetType3 } from "@codemirror/view";
|
|
1378
1475
|
var image = (options = {}) => {
|
|
1379
|
-
return
|
|
1380
|
-
create: (state) =>
|
|
1381
|
-
|
|
1382
|
-
|
|
1476
|
+
return StateField3.define({
|
|
1477
|
+
create: (state) => {
|
|
1478
|
+
return Decoration5.set(buildDecorations(0, state.doc.length, state));
|
|
1479
|
+
},
|
|
1480
|
+
update: (value, tr) => {
|
|
1481
|
+
if (!tr.docChanged && !tr.selection) {
|
|
1482
|
+
return value;
|
|
1483
|
+
}
|
|
1484
|
+
const cursor = tr.state.selection.main.head;
|
|
1485
|
+
const oldCursor = tr.changes.mapPos(tr.startState.selection.main.head);
|
|
1486
|
+
let from = Math.min(cursor, oldCursor);
|
|
1487
|
+
let to = Math.max(cursor, oldCursor);
|
|
1488
|
+
tr.changes.iterChangedRanges((fromA, toA, fromB, toB) => {
|
|
1489
|
+
from = Math.min(from, fromB);
|
|
1490
|
+
to = Math.max(to, toB);
|
|
1491
|
+
});
|
|
1492
|
+
from = tr.state.doc.lineAt(from).from;
|
|
1493
|
+
to = tr.state.doc.lineAt(to).to;
|
|
1494
|
+
return value.map(tr.changes).update({
|
|
1495
|
+
filterFrom: from,
|
|
1496
|
+
filterTo: to,
|
|
1497
|
+
filter: () => false,
|
|
1498
|
+
add: buildDecorations(from, to, tr.state)
|
|
1499
|
+
});
|
|
1500
|
+
},
|
|
1501
|
+
provide: (field) => EditorView7.decorations.from(field)
|
|
1383
1502
|
});
|
|
1384
1503
|
};
|
|
1385
|
-
var
|
|
1386
|
-
const
|
|
1504
|
+
var buildDecorations = (from, to, state) => {
|
|
1505
|
+
const decorations = [];
|
|
1387
1506
|
const cursor = state.selection.main.head;
|
|
1388
1507
|
syntaxTree(state).iterate({
|
|
1389
1508
|
enter: (node) => {
|
|
@@ -1392,22 +1511,23 @@ var update = (state, options) => {
|
|
|
1392
1511
|
if (urlNode) {
|
|
1393
1512
|
const hide = state.readOnly || cursor < node.from || cursor > node.to;
|
|
1394
1513
|
const url = state.sliceDoc(urlNode.from, urlNode.to);
|
|
1395
|
-
|
|
1514
|
+
decorations.push(Decoration5.replace({
|
|
1396
1515
|
block: true,
|
|
1397
1516
|
widget: new ImageWidget(url)
|
|
1398
|
-
}));
|
|
1517
|
+
}).range(hide ? node.from : node.to, node.to));
|
|
1399
1518
|
}
|
|
1400
1519
|
}
|
|
1401
|
-
}
|
|
1520
|
+
},
|
|
1521
|
+
from,
|
|
1522
|
+
to
|
|
1402
1523
|
});
|
|
1403
|
-
return
|
|
1524
|
+
return decorations;
|
|
1404
1525
|
};
|
|
1405
1526
|
var ImageWidget = class extends WidgetType3 {
|
|
1406
1527
|
constructor(_url) {
|
|
1407
1528
|
super();
|
|
1408
1529
|
this._url = _url;
|
|
1409
1530
|
}
|
|
1410
|
-
// TODO(burdon): Does this need to be unique for each position?
|
|
1411
1531
|
eq(other) {
|
|
1412
1532
|
return this._url === other._url;
|
|
1413
1533
|
}
|
|
@@ -1415,30 +1535,77 @@ var ImageWidget = class extends WidgetType3 {
|
|
|
1415
1535
|
const img = document.createElement("img");
|
|
1416
1536
|
img.setAttribute("src", this._url);
|
|
1417
1537
|
img.setAttribute("class", "cm-image");
|
|
1538
|
+
img.onload = () => img.classList.add("cm-loaded-image");
|
|
1418
1539
|
return img;
|
|
1419
1540
|
}
|
|
1420
1541
|
};
|
|
1421
1542
|
|
|
1422
|
-
// packages/ui/react-ui-editor/src/
|
|
1543
|
+
// packages/ui/react-ui-editor/src/extensions/link.ts
|
|
1423
1544
|
import { syntaxTree as syntaxTree2 } from "@codemirror/language";
|
|
1424
|
-
import { RangeSetBuilder
|
|
1425
|
-
import { Decoration as
|
|
1545
|
+
import { RangeSetBuilder } from "@codemirror/state";
|
|
1546
|
+
import { Decoration as Decoration6, WidgetType as WidgetType4, hoverTooltip as hoverTooltip2, ViewPlugin as ViewPlugin5 } from "@codemirror/view";
|
|
1547
|
+
import { tooltipContent } from "@dxos/react-ui-theme";
|
|
1426
1548
|
var link = (options = {}) => {
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1549
|
+
const extensions = [
|
|
1550
|
+
ViewPlugin5.fromClass(class {
|
|
1551
|
+
constructor(view) {
|
|
1552
|
+
this.decorations = buildDecorations2(view, options);
|
|
1553
|
+
}
|
|
1554
|
+
update(update2) {
|
|
1555
|
+
if (update2.docChanged || update2.viewportChanged || update2.selectionSet) {
|
|
1556
|
+
this.decorations = buildDecorations2(update2.view, options);
|
|
1557
|
+
}
|
|
1558
|
+
}
|
|
1559
|
+
}, {
|
|
1560
|
+
decorations: (v) => v.decorations
|
|
1561
|
+
})
|
|
1562
|
+
];
|
|
1563
|
+
if (options.onHover) {
|
|
1564
|
+
extensions.push(
|
|
1565
|
+
// https://codemirror.net/examples/tooltip
|
|
1566
|
+
// https://codemirror.net/docs/ref/#view.hoverTooltip
|
|
1567
|
+
// https://github.com/codemirror/view/blob/main/src/tooltip.ts
|
|
1568
|
+
hoverTooltip2((view, pos, side) => {
|
|
1569
|
+
const syntax = syntaxTree2(view.state).resolveInner(pos, side);
|
|
1570
|
+
let link2 = null;
|
|
1571
|
+
for (let i = 0, node = syntax; !link2 && node && i < 5; node = node.parent, i++) {
|
|
1572
|
+
link2 = node.name === "Link" ? node : null;
|
|
1573
|
+
}
|
|
1574
|
+
const url = link2 && link2.getChild("URL");
|
|
1575
|
+
if (!url || !link2) {
|
|
1576
|
+
return null;
|
|
1577
|
+
}
|
|
1578
|
+
const urlText = view.state.sliceDoc(url.from, url.to);
|
|
1579
|
+
return {
|
|
1580
|
+
pos: link2.from,
|
|
1581
|
+
end: link2.to,
|
|
1582
|
+
above: true,
|
|
1583
|
+
create: () => {
|
|
1584
|
+
const el = document.createElement("div");
|
|
1585
|
+
el.className = tooltipContent({}, "pli-2 plb-1");
|
|
1586
|
+
options.onHover(el, urlText);
|
|
1587
|
+
return {
|
|
1588
|
+
dom: el,
|
|
1589
|
+
offset: {
|
|
1590
|
+
x: 0,
|
|
1591
|
+
y: 4
|
|
1592
|
+
}
|
|
1593
|
+
};
|
|
1594
|
+
}
|
|
1595
|
+
};
|
|
1596
|
+
})
|
|
1597
|
+
);
|
|
1598
|
+
}
|
|
1599
|
+
return extensions;
|
|
1432
1600
|
};
|
|
1433
1601
|
var LinkButton = class extends WidgetType4 {
|
|
1434
|
-
constructor(
|
|
1602
|
+
constructor(_url, _onAttach) {
|
|
1435
1603
|
super();
|
|
1436
|
-
this._pos = _pos;
|
|
1437
1604
|
this._url = _url;
|
|
1438
1605
|
this._onAttach = _onAttach;
|
|
1439
1606
|
}
|
|
1440
1607
|
eq(other) {
|
|
1441
|
-
return this.
|
|
1608
|
+
return this._url === other._url;
|
|
1442
1609
|
}
|
|
1443
1610
|
toDOM(view) {
|
|
1444
1611
|
const el = document.createElement("span");
|
|
@@ -1447,14 +1614,13 @@ var LinkButton = class extends WidgetType4 {
|
|
|
1447
1614
|
}
|
|
1448
1615
|
};
|
|
1449
1616
|
var LinkText = class extends WidgetType4 {
|
|
1450
|
-
constructor(
|
|
1617
|
+
constructor(_text, _url) {
|
|
1451
1618
|
super();
|
|
1452
|
-
this._pos = _pos;
|
|
1453
1619
|
this._text = _text;
|
|
1454
1620
|
this._url = _url;
|
|
1455
1621
|
}
|
|
1456
1622
|
eq(other) {
|
|
1457
|
-
return this.
|
|
1623
|
+
return this._url === other._url;
|
|
1458
1624
|
}
|
|
1459
1625
|
toDOM(view) {
|
|
1460
1626
|
const link2 = document.createElement("a");
|
|
@@ -1468,7 +1634,7 @@ var LinkText = class extends WidgetType4 {
|
|
|
1468
1634
|
link2.onclick = () => {
|
|
1469
1635
|
view.dispatch({
|
|
1470
1636
|
selection: {
|
|
1471
|
-
anchor:
|
|
1637
|
+
anchor: view.posAtDOM(link2)
|
|
1472
1638
|
}
|
|
1473
1639
|
});
|
|
1474
1640
|
};
|
|
@@ -1476,74 +1642,77 @@ var LinkText = class extends WidgetType4 {
|
|
|
1476
1642
|
return link2;
|
|
1477
1643
|
}
|
|
1478
1644
|
};
|
|
1479
|
-
var
|
|
1480
|
-
const builder = new
|
|
1645
|
+
var buildDecorations2 = (view, options) => {
|
|
1646
|
+
const builder = new RangeSetBuilder();
|
|
1647
|
+
const { state } = view;
|
|
1481
1648
|
const cursor = state.selection.main.head;
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1649
|
+
for (const { from, to } of view.visibleRanges) {
|
|
1650
|
+
syntaxTree2(state).iterate({
|
|
1651
|
+
enter: (node) => {
|
|
1652
|
+
if (node.name === "Link") {
|
|
1653
|
+
const marks2 = node.node.getChildren("LinkMark");
|
|
1654
|
+
const text = marks2.length >= 2 ? state.sliceDoc(marks2[0].to, marks2[1].from) : "";
|
|
1655
|
+
const urlNode = node.node.getChild("URL");
|
|
1656
|
+
const url = urlNode ? state.sliceDoc(urlNode.from, urlNode.to) : "";
|
|
1657
|
+
if (!url) {
|
|
1658
|
+
return false;
|
|
1659
|
+
}
|
|
1660
|
+
if (!view.hasFocus || state.readOnly || cursor < node.from || cursor > node.to) {
|
|
1661
|
+
builder.add(node.from, node.to, Decoration6.replace({
|
|
1662
|
+
widget: new LinkText(text, options.link ? url : void 0)
|
|
1663
|
+
}));
|
|
1664
|
+
}
|
|
1665
|
+
if (options.onRender) {
|
|
1666
|
+
builder.add(node.to, node.to, Decoration6.replace({
|
|
1667
|
+
widget: new LinkButton(url, options.onRender)
|
|
1668
|
+
}));
|
|
1669
|
+
}
|
|
1490
1670
|
return false;
|
|
1491
1671
|
}
|
|
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
|
-
});
|
|
1672
|
+
},
|
|
1673
|
+
from,
|
|
1674
|
+
to
|
|
1675
|
+
});
|
|
1676
|
+
}
|
|
1506
1677
|
return builder.finish();
|
|
1507
1678
|
};
|
|
1508
1679
|
|
|
1509
|
-
// packages/ui/react-ui-editor/src/
|
|
1510
|
-
import {
|
|
1511
|
-
var listener = ({ onChange }) => {
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1680
|
+
// packages/ui/react-ui-editor/src/extensions/listener.ts
|
|
1681
|
+
import { EditorView as EditorView8 } from "@codemirror/view";
|
|
1682
|
+
var listener = ({ onFocus, onChange }) => {
|
|
1683
|
+
const extensions = [];
|
|
1684
|
+
onFocus && extensions.push(EditorView8.focusChangeEffect.of((_, focused) => {
|
|
1685
|
+
onFocus(focused);
|
|
1686
|
+
return null;
|
|
1687
|
+
}));
|
|
1688
|
+
onChange && extensions.push(EditorView8.updateListener.of((update2) => {
|
|
1689
|
+
onChange(update2.state.doc.toString());
|
|
1690
|
+
}));
|
|
1691
|
+
return extensions;
|
|
1521
1692
|
};
|
|
1522
1693
|
|
|
1523
|
-
// packages/ui/react-ui-editor/src/
|
|
1694
|
+
// packages/ui/react-ui-editor/src/extensions/markdown/bundle.ts
|
|
1524
1695
|
import { closeBrackets as closeBrackets2, closeBracketsKeymap } from "@codemirror/autocomplete";
|
|
1525
1696
|
import { history, historyKeymap, indentWithTab, standardKeymap } from "@codemirror/commands";
|
|
1526
|
-
import { markdownLanguage as
|
|
1697
|
+
import { markdownLanguage as markdownLanguage3, markdown } from "@codemirror/lang-markdown";
|
|
1527
1698
|
import { bracketMatching as bracketMatching2, defaultHighlightStyle as defaultHighlightStyle2, indentOnInput, syntaxHighlighting as syntaxHighlighting2 } from "@codemirror/language";
|
|
1528
1699
|
import { languages } from "@codemirror/language-data";
|
|
1529
1700
|
import { searchKeymap } from "@codemirror/search";
|
|
1530
1701
|
import { EditorState } from "@codemirror/state";
|
|
1531
1702
|
import { oneDarkHighlightStyle as oneDarkHighlightStyle2 } from "@codemirror/theme-one-dark";
|
|
1532
|
-
import { crosshairCursor, drawSelection as drawSelection2, dropCursor, EditorView as
|
|
1703
|
+
import { crosshairCursor, drawSelection as drawSelection2, dropCursor, EditorView as EditorView9, highlightActiveLine, keymap as keymap4, placeholder as placeholder2 } from "@codemirror/view";
|
|
1533
1704
|
|
|
1534
|
-
// packages/ui/react-ui-editor/src/
|
|
1535
|
-
import { markdownLanguage } from "@codemirror/lang-markdown";
|
|
1705
|
+
// packages/ui/react-ui-editor/src/extensions/markdown/highlight.ts
|
|
1706
|
+
import { markdownLanguage as markdownLanguage2 } from "@codemirror/lang-markdown";
|
|
1536
1707
|
import { HighlightStyle } from "@codemirror/language";
|
|
1537
1708
|
import { tags, styleTags, Tag } from "@lezer/highlight";
|
|
1538
1709
|
import { Table } from "@lezer/markdown";
|
|
1539
|
-
import get4 from "lodash.get";
|
|
1540
1710
|
var markdownTags = {
|
|
1541
1711
|
Blockquote: Tag.define(),
|
|
1542
1712
|
CodeMark: Tag.define(),
|
|
1543
1713
|
CodeText: Tag.define(),
|
|
1544
1714
|
EmphasisMark: Tag.define(),
|
|
1545
1715
|
HeaderMark: Tag.define(),
|
|
1546
|
-
// HorizontalRule: Tag.define(),
|
|
1547
1716
|
InlineCode: Tag.define(),
|
|
1548
1717
|
LinkLabel: Tag.define(),
|
|
1549
1718
|
LinkReference: Tag.define(),
|
|
@@ -1707,12 +1876,6 @@ var markdownHighlightStyle = (readonly) => {
|
|
|
1707
1876
|
],
|
|
1708
1877
|
class: blockquote
|
|
1709
1878
|
},
|
|
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
1879
|
{
|
|
1717
1880
|
tag: [
|
|
1718
1881
|
markdownTags.TableCell
|
|
@@ -1720,19 +1883,19 @@ var markdownHighlightStyle = (readonly) => {
|
|
|
1720
1883
|
class: "font-mono"
|
|
1721
1884
|
}
|
|
1722
1885
|
], {
|
|
1723
|
-
scope:
|
|
1886
|
+
scope: markdownLanguage2,
|
|
1724
1887
|
all: {
|
|
1725
|
-
fontFamily:
|
|
1888
|
+
fontFamily: getToken("fontFamily.body", []).join(",")
|
|
1726
1889
|
}
|
|
1727
1890
|
});
|
|
1728
1891
|
};
|
|
1729
1892
|
|
|
1730
|
-
// packages/ui/react-ui-editor/src/
|
|
1893
|
+
// packages/ui/react-ui-editor/src/extensions/markdown/bundle.ts
|
|
1731
1894
|
var markdownBundle = ({ readonly, themeMode, placeholder: _placeholder }) => {
|
|
1732
1895
|
return [
|
|
1733
1896
|
EditorState.allowMultipleSelections.of(true),
|
|
1734
1897
|
EditorState.tabSize.of(2),
|
|
1735
|
-
|
|
1898
|
+
EditorView9.lineWrapping,
|
|
1736
1899
|
customKeymap(),
|
|
1737
1900
|
bracketMatching2(),
|
|
1738
1901
|
closeBrackets2(),
|
|
@@ -1752,7 +1915,7 @@ var markdownBundle = ({ readonly, themeMode, placeholder: _placeholder }) => {
|
|
|
1752
1915
|
// NOTE: This extends the parser; it doesn't affect rendering.
|
|
1753
1916
|
// https://github.github.com/gfm
|
|
1754
1917
|
// https://github.com/lezer-parser/markdown?tab=readme-ov-file#github-flavored-markdown
|
|
1755
|
-
base:
|
|
1918
|
+
base: markdownLanguage3,
|
|
1756
1919
|
// Languages for syntax highlighting fenced code blocks.
|
|
1757
1920
|
codeLanguages: languages,
|
|
1758
1921
|
// Parser extensions.
|
|
@@ -1780,7 +1943,7 @@ var customKeymap = () => keymap4.of([
|
|
|
1780
1943
|
...searchKeymap
|
|
1781
1944
|
]);
|
|
1782
1945
|
|
|
1783
|
-
// packages/ui/react-ui-editor/src/
|
|
1946
|
+
// packages/ui/react-ui-editor/src/extensions/mention.ts
|
|
1784
1947
|
import { autocompletion as autocompletion2 } from "@codemirror/autocomplete";
|
|
1785
1948
|
var mention = ({ onSearch }) => {
|
|
1786
1949
|
return autocompletion2({
|
|
@@ -1803,24 +1966,19 @@ var mention = ({ onSearch }) => {
|
|
|
1803
1966
|
});
|
|
1804
1967
|
};
|
|
1805
1968
|
|
|
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
|
|
1969
|
+
// packages/ui/react-ui-editor/src/extensions/table.ts
|
|
1812
1970
|
import { syntaxTree as syntaxTree3 } from "@codemirror/language";
|
|
1813
|
-
import { RangeSetBuilder as
|
|
1814
|
-
import { Decoration as
|
|
1971
|
+
import { RangeSetBuilder as RangeSetBuilder2, StateField as StateField4 } from "@codemirror/state";
|
|
1972
|
+
import { Decoration as Decoration7, EditorView as EditorView10, WidgetType as WidgetType5 } from "@codemirror/view";
|
|
1815
1973
|
var table = (options = {}) => {
|
|
1816
|
-
return
|
|
1817
|
-
create: (state) =>
|
|
1818
|
-
update: (_, tr) =>
|
|
1819
|
-
provide: (field) =>
|
|
1974
|
+
return StateField4.define({
|
|
1975
|
+
create: (state) => update(state, options),
|
|
1976
|
+
update: (_, tr) => update(tr.state, options),
|
|
1977
|
+
provide: (field) => EditorView10.decorations.from(field)
|
|
1820
1978
|
});
|
|
1821
1979
|
};
|
|
1822
|
-
var
|
|
1823
|
-
const builder = new
|
|
1980
|
+
var update = (state, options) => {
|
|
1981
|
+
const builder = new RangeSetBuilder2();
|
|
1824
1982
|
const cursor = state.selection.main.head;
|
|
1825
1983
|
const tables = [];
|
|
1826
1984
|
const getTable = () => tables[tables.length - 1];
|
|
@@ -1860,11 +2018,10 @@ var update3 = (state, options) => {
|
|
|
1860
2018
|
});
|
|
1861
2019
|
tables.forEach((table2) => {
|
|
1862
2020
|
const hide = state.readOnly || cursor < table2.from || cursor > table2.to;
|
|
1863
|
-
hide && builder.add(table2.from, table2.to,
|
|
1864
|
-
block: true,
|
|
2021
|
+
hide && builder.add(table2.from, table2.to, Decoration7.replace({
|
|
1865
2022
|
widget: new TableWidget(table2)
|
|
1866
2023
|
}));
|
|
1867
|
-
builder.add(table2.from, table2.to,
|
|
2024
|
+
builder.add(table2.from, table2.to, Decoration7.mark({
|
|
1868
2025
|
class: "cm-table"
|
|
1869
2026
|
}));
|
|
1870
2027
|
});
|
|
@@ -1876,7 +2033,7 @@ var TableWidget = class extends WidgetType5 {
|
|
|
1876
2033
|
this._table = _table;
|
|
1877
2034
|
}
|
|
1878
2035
|
eq(other) {
|
|
1879
|
-
return this._table.
|
|
2036
|
+
return this._table.header?.join() === other._table.header?.join() && this._table.rows?.join() === other._table.rows?.join();
|
|
1880
2037
|
}
|
|
1881
2038
|
toDOM(view) {
|
|
1882
2039
|
const table2 = document.createElement("table");
|
|
@@ -1902,138 +2059,94 @@ var TableWidget = class extends WidgetType5 {
|
|
|
1902
2059
|
}
|
|
1903
2060
|
return table2;
|
|
1904
2061
|
}
|
|
2062
|
+
ignoreEvent(e) {
|
|
2063
|
+
return !/^mouse/.test(e.type);
|
|
2064
|
+
}
|
|
1905
2065
|
};
|
|
1906
2066
|
|
|
1907
|
-
// packages/ui/react-ui-editor/src/
|
|
1908
|
-
import {
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
paddingLeft: "4px",
|
|
1912
|
-
paddingRight: "8px"
|
|
1913
|
-
}
|
|
1914
|
-
});
|
|
2067
|
+
// packages/ui/react-ui-editor/src/extensions/tasklist.ts
|
|
2068
|
+
import { syntaxTree as syntaxTree4 } from "@codemirror/language";
|
|
2069
|
+
import { RangeSetBuilder as RangeSetBuilder3 } from "@codemirror/state";
|
|
2070
|
+
import { EditorView as EditorView11, Decoration as Decoration8, WidgetType as WidgetType6, ViewPlugin as ViewPlugin6 } from "@codemirror/view";
|
|
1915
2071
|
var CheckboxWidget = class extends WidgetType6 {
|
|
1916
|
-
constructor(
|
|
2072
|
+
constructor(_checked) {
|
|
1917
2073
|
super();
|
|
1918
|
-
this._pos = _pos;
|
|
1919
2074
|
this._checked = _checked;
|
|
1920
|
-
this._indent = _indent;
|
|
1921
|
-
this._onCheck = _onCheck;
|
|
1922
2075
|
}
|
|
1923
2076
|
eq(other) {
|
|
1924
|
-
return this.
|
|
2077
|
+
return this._checked === other._checked;
|
|
1925
2078
|
}
|
|
1926
2079
|
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"));
|
|
2080
|
+
const input = document.createElement("input");
|
|
1932
2081
|
input.type = "checkbox";
|
|
1933
2082
|
input.checked = this._checked;
|
|
1934
|
-
if (
|
|
2083
|
+
if (view.state.readOnly) {
|
|
1935
2084
|
input.setAttribute("disabled", "true");
|
|
1936
|
-
}
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
2085
|
+
} else {
|
|
2086
|
+
input.onmousedown = (event) => {
|
|
2087
|
+
const pos = view.posAtDOM(input);
|
|
2088
|
+
const text = view.state.sliceDoc(pos, pos + 3);
|
|
2089
|
+
if (text === (this._checked ? "[x]" : "[ ]")) {
|
|
2090
|
+
view.dispatch({
|
|
2091
|
+
changes: {
|
|
2092
|
+
from: pos + 1,
|
|
2093
|
+
to: pos + 2,
|
|
2094
|
+
insert: this._checked ? " " : "x"
|
|
2095
|
+
}
|
|
2096
|
+
});
|
|
2097
|
+
event.preventDefault();
|
|
2098
|
+
}
|
|
1941
2099
|
};
|
|
1942
2100
|
}
|
|
1943
|
-
return
|
|
2101
|
+
return input;
|
|
1944
2102
|
}
|
|
1945
2103
|
ignoreEvent() {
|
|
1946
2104
|
return false;
|
|
1947
2105
|
}
|
|
1948
2106
|
};
|
|
2107
|
+
var checkedDeco = Decoration8.replace({
|
|
2108
|
+
widget: new CheckboxWidget(true)
|
|
2109
|
+
});
|
|
2110
|
+
var uncheckedDeco = Decoration8.replace({
|
|
2111
|
+
widget: new CheckboxWidget(false)
|
|
2112
|
+
});
|
|
1949
2113
|
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 {
|
|
2114
|
+
return ViewPlugin6.fromClass(class {
|
|
1974
2115
|
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;
|
|
2006
|
-
}
|
|
2007
|
-
idx = text.indexOf(match[0]);
|
|
2008
|
-
if (p >= idx && p < idx + match[0].length) {
|
|
2009
|
-
break;
|
|
2116
|
+
this.decorations = buildDecorations3(view);
|
|
2010
2117
|
}
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
}
|
|
2016
|
-
const [, , url] = match ?? [];
|
|
2017
|
-
return {
|
|
2018
|
-
pos: idx + from,
|
|
2019
|
-
end: idx + from + match[0].length,
|
|
2020
|
-
above: true,
|
|
2021
|
-
create: () => {
|
|
2022
|
-
const el = document.createElement("div");
|
|
2023
|
-
el.className = tooltipContent({}, "pli-2 plb-1");
|
|
2024
|
-
onHover(el, url);
|
|
2025
|
-
return {
|
|
2026
|
-
dom: el,
|
|
2027
|
-
offset: {
|
|
2028
|
-
x: 0,
|
|
2029
|
-
y: 4
|
|
2030
|
-
}
|
|
2031
|
-
};
|
|
2118
|
+
update(update2) {
|
|
2119
|
+
if (update2.docChanged || update2.viewportChanged || update2.selectionSet) {
|
|
2120
|
+
this.decorations = buildDecorations3(update2.view);
|
|
2121
|
+
}
|
|
2032
2122
|
}
|
|
2033
|
-
}
|
|
2034
|
-
|
|
2123
|
+
}, {
|
|
2124
|
+
decorations: (v) => v.decorations,
|
|
2125
|
+
provide: (plugin) => EditorView11.atomicRanges.of((view) => {
|
|
2126
|
+
return view.plugin(plugin)?.decorations || Decoration8.none;
|
|
2127
|
+
})
|
|
2128
|
+
});
|
|
2129
|
+
};
|
|
2130
|
+
var buildDecorations3 = (view) => {
|
|
2131
|
+
const builder = new RangeSetBuilder3();
|
|
2132
|
+
const { state } = view;
|
|
2133
|
+
const cursor = state.selection.main.head;
|
|
2134
|
+
for (const { from, to } of view.visibleRanges) {
|
|
2135
|
+
syntaxTree4(state).iterate({
|
|
2136
|
+
enter: (node) => {
|
|
2137
|
+
if (node.name === "TaskMarker" && (cursor < node.from || cursor > node.to)) {
|
|
2138
|
+
const checked = state.doc.sliceString(node.from + 1, node.to - 1) === "x";
|
|
2139
|
+
builder.add(node.from, node.to, checked ? checkedDeco : uncheckedDeco);
|
|
2140
|
+
}
|
|
2141
|
+
},
|
|
2142
|
+
from,
|
|
2143
|
+
to
|
|
2144
|
+
});
|
|
2145
|
+
}
|
|
2146
|
+
return builder.finish();
|
|
2147
|
+
};
|
|
2035
2148
|
|
|
2036
|
-
// packages/ui/react-ui-editor/src/
|
|
2149
|
+
// packages/ui/react-ui-editor/src/extensions/typewriter.ts
|
|
2037
2150
|
import { keymap as keymap5 } from "@codemirror/view";
|
|
2038
2151
|
var defaultItems = [
|
|
2039
2152
|
"hello world!",
|
|
@@ -2090,8 +2203,29 @@ var typewriter = ({ delay = 75, items = defaultItems } = {}) => {
|
|
|
2090
2203
|
];
|
|
2091
2204
|
};
|
|
2092
2205
|
|
|
2093
|
-
// packages/ui/react-ui-editor/src/
|
|
2094
|
-
import
|
|
2206
|
+
// packages/ui/react-ui-editor/src/extensions/yjs/yjs.ts
|
|
2207
|
+
import { yCollab } from "y-codemirror.next";
|
|
2208
|
+
|
|
2209
|
+
// packages/ui/react-ui-editor/src/extensions/yjs/cursor.ts
|
|
2210
|
+
import * as Y from "yjs";
|
|
2211
|
+
import { arrayToString, stringToArray } from "@dxos/util";
|
|
2212
|
+
var cursorConverter2 = (text) => ({
|
|
2213
|
+
toCursor: (index, assoc) => {
|
|
2214
|
+
return arrayToString(Y.encodeRelativePosition(Y.createRelativePositionFromTypeIndex(text, index, assoc)));
|
|
2215
|
+
},
|
|
2216
|
+
fromCursor: (cursor) => {
|
|
2217
|
+
return Y.createAbsolutePositionFromRelativePosition(Y.decodeRelativePosition(stringToArray(cursor)), text.doc)?.index ?? 0;
|
|
2218
|
+
}
|
|
2219
|
+
});
|
|
2220
|
+
|
|
2221
|
+
// packages/ui/react-ui-editor/src/extensions/yjs/yjs.ts
|
|
2222
|
+
var yjs = (content, awareness2) => [
|
|
2223
|
+
Cursor.converter.of(cursorConverter2(content)),
|
|
2224
|
+
yCollab(content, awareness2)
|
|
2225
|
+
];
|
|
2226
|
+
|
|
2227
|
+
// packages/ui/react-ui-editor/src/themes/default.ts
|
|
2228
|
+
import get3 from "lodash.get";
|
|
2095
2229
|
var defaultTheme = {
|
|
2096
2230
|
//
|
|
2097
2231
|
// Main layout:
|
|
@@ -2120,21 +2254,21 @@ var defaultTheme = {
|
|
|
2120
2254
|
"&.cm-focused": {
|
|
2121
2255
|
outline: "none"
|
|
2122
2256
|
},
|
|
2123
|
-
"
|
|
2257
|
+
".cm-scroller": {
|
|
2124
2258
|
overflow: "visible",
|
|
2125
|
-
fontFamily:
|
|
2259
|
+
fontFamily: get3(tokens, "fontFamily.mono", []).join(",")
|
|
2126
2260
|
},
|
|
2127
|
-
"
|
|
2261
|
+
".cm-content": {
|
|
2128
2262
|
padding: 0,
|
|
2129
2263
|
// NOTE: Base font size (otherwise defined by HTML tag, which might be different for storybook).
|
|
2130
2264
|
fontSize: "16px"
|
|
2131
2265
|
},
|
|
2132
2266
|
"&light .cm-content": {
|
|
2133
|
-
color:
|
|
2267
|
+
color: get3(tokens, "extend.colors.neutral.900", "black"),
|
|
2134
2268
|
caretColor: "black"
|
|
2135
2269
|
},
|
|
2136
2270
|
"&dark .cm-content": {
|
|
2137
|
-
color:
|
|
2271
|
+
color: get3(tokens, "extend.colors.neutral.100", "white"),
|
|
2138
2272
|
caretColor: "white"
|
|
2139
2273
|
},
|
|
2140
2274
|
//
|
|
@@ -2146,158 +2280,120 @@ var defaultTheme = {
|
|
|
2146
2280
|
"&dark .cm-cursor, &dark .cm-dropCursor": {
|
|
2147
2281
|
borderLeft: "2px solid white"
|
|
2148
2282
|
},
|
|
2149
|
-
"
|
|
2283
|
+
".cm-placeholder": {
|
|
2150
2284
|
fontWeight: 100
|
|
2151
2285
|
},
|
|
2152
2286
|
//
|
|
2153
2287
|
// line
|
|
2154
2288
|
//
|
|
2155
|
-
"
|
|
2289
|
+
".cm-line": {
|
|
2156
2290
|
paddingInline: 0
|
|
2157
2291
|
},
|
|
2158
|
-
"
|
|
2292
|
+
".cm-activeLine": {
|
|
2159
2293
|
background: "inherit"
|
|
2160
2294
|
},
|
|
2161
2295
|
//
|
|
2162
2296
|
// Selection
|
|
2163
2297
|
//
|
|
2164
2298
|
"&light .cm-selectionBackground": {
|
|
2165
|
-
background:
|
|
2299
|
+
background: get3(tokens, "extend.colors.primary.100")
|
|
2166
2300
|
},
|
|
2167
2301
|
"&light.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground": {
|
|
2168
|
-
background:
|
|
2302
|
+
background: get3(tokens, "extend.colors.primary.200")
|
|
2169
2303
|
},
|
|
2170
2304
|
"&dark .cm-selectionBackground": {
|
|
2171
|
-
background:
|
|
2305
|
+
background: get3(tokens, "extend.colors.primary.700")
|
|
2172
2306
|
},
|
|
2173
2307
|
"&dark.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground": {
|
|
2174
|
-
background:
|
|
2308
|
+
background: get3(tokens, "extend.colors.primary.600")
|
|
2175
2309
|
},
|
|
2176
2310
|
//
|
|
2177
2311
|
// Search
|
|
2178
2312
|
//
|
|
2179
2313
|
"&light .cm-searchMatch": {
|
|
2180
|
-
backgroundColor:
|
|
2314
|
+
backgroundColor: get3(tokens, "extend.colors.yellow.100")
|
|
2181
2315
|
},
|
|
2182
2316
|
"&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
|
|
2317
|
+
backgroundColor: get3(tokens, "extend.colors.yellow.700")
|
|
2211
2318
|
},
|
|
2212
2319
|
//
|
|
2213
2320
|
// link
|
|
2214
2321
|
//
|
|
2215
|
-
"
|
|
2216
|
-
color:
|
|
2322
|
+
".cm-link": {
|
|
2323
|
+
color: get3(tokens, "extend.colors.primary.500"),
|
|
2217
2324
|
textDecorationLine: "underline",
|
|
2218
2325
|
textDecorationThickness: "1px",
|
|
2219
2326
|
textUnderlineOffset: "2px",
|
|
2220
2327
|
borderRadius: ".125rem",
|
|
2221
|
-
fontFamily:
|
|
2328
|
+
fontFamily: get3(tokens, "fontFamily.body", []).join(",")
|
|
2222
2329
|
},
|
|
2223
2330
|
//
|
|
2224
2331
|
// tooltip
|
|
2225
2332
|
//
|
|
2226
|
-
"
|
|
2333
|
+
".cm-tooltip": {
|
|
2227
2334
|
border: "none"
|
|
2228
2335
|
},
|
|
2229
|
-
"
|
|
2336
|
+
".cm-tooltip-below": {},
|
|
2230
2337
|
//
|
|
2231
2338
|
// autocomplete
|
|
2232
2339
|
//
|
|
2233
|
-
"
|
|
2340
|
+
".cm-tooltip-autocomplete": {
|
|
2234
2341
|
marginTop: "4px",
|
|
2235
2342
|
marginLeft: "-3px"
|
|
2236
2343
|
},
|
|
2237
|
-
"
|
|
2238
|
-
"
|
|
2239
|
-
"
|
|
2344
|
+
".cm-tooltip-autocomplete ul li": {},
|
|
2345
|
+
".cm-tooltip-autocomplete ul li[aria-selected]": {},
|
|
2346
|
+
".cm-completionIcon": {
|
|
2240
2347
|
display: "none"
|
|
2241
2348
|
},
|
|
2242
|
-
"
|
|
2243
|
-
fontFamily:
|
|
2349
|
+
".cm-completionLabel": {
|
|
2350
|
+
fontFamily: get3(tokens, "fontFamily.body", []).join(",")
|
|
2244
2351
|
},
|
|
2245
|
-
"
|
|
2352
|
+
".cm-completionMatchedText": {
|
|
2246
2353
|
textDecoration: "none"
|
|
2247
2354
|
},
|
|
2248
2355
|
//
|
|
2249
|
-
// widgets
|
|
2250
|
-
//
|
|
2251
|
-
"& .cm-widgetBuffer": {
|
|
2252
|
-
display: "none",
|
|
2253
|
-
height: 0
|
|
2254
|
-
},
|
|
2255
|
-
//
|
|
2256
2356
|
// table
|
|
2257
2357
|
//
|
|
2258
|
-
"
|
|
2259
|
-
fontFamily: `${
|
|
2358
|
+
".cm-table *": {
|
|
2359
|
+
fontFamily: `${get3(tokens, "fontFamily.mono", []).join(",")} !important`,
|
|
2260
2360
|
textDecoration: "none !important"
|
|
2261
2361
|
},
|
|
2262
|
-
"
|
|
2362
|
+
".cm-table-head": {
|
|
2263
2363
|
padding: "2px 16px 2px 0px",
|
|
2264
|
-
borderBottom: `1px solid ${
|
|
2364
|
+
borderBottom: `1px solid ${get3(tokens, "extend.colors.neutral.500")}`,
|
|
2265
2365
|
fontWeight: 100,
|
|
2266
2366
|
textAlign: "left",
|
|
2267
|
-
color:
|
|
2367
|
+
color: get3(tokens, "extend.colors.neutral.500")
|
|
2268
2368
|
},
|
|
2269
|
-
"
|
|
2369
|
+
".cm-table-cell": {
|
|
2270
2370
|
padding: "2px 16px 2px 0px"
|
|
2271
2371
|
},
|
|
2272
2372
|
//
|
|
2273
2373
|
// image
|
|
2274
2374
|
//
|
|
2275
|
-
"
|
|
2276
|
-
|
|
2375
|
+
".cm-image": {
|
|
2376
|
+
display: "block",
|
|
2377
|
+
height: "0"
|
|
2378
|
+
},
|
|
2379
|
+
".cm-image.cm-loaded-image": {
|
|
2380
|
+
height: "auto",
|
|
2381
|
+
borderTop: "0.5rem solid transparent",
|
|
2382
|
+
borderBottom: "0.5rem solid transparent"
|
|
2277
2383
|
},
|
|
2278
2384
|
//
|
|
2279
2385
|
// font size
|
|
2280
|
-
// TODO(thure): This appears to be the best or only way to set selection caret heights,
|
|
2386
|
+
// TODO(thure): This appears to be the best or only way to set selection caret heights,
|
|
2387
|
+
// but it's far more verbose than it needs to be.
|
|
2281
2388
|
//
|
|
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
|
-
}, {}),
|
|
2389
|
+
// ...Object.keys(get(tokens, 'extend.fontSize', {})).reduce((acc: Record<string, any>, fontSize) => {
|
|
2390
|
+
// const height = get(tokens, ['extend', 'fontSize', fontSize, 1, 'lineHeight']);
|
|
2391
|
+
//
|
|
2392
|
+
// acc[`& .text-${fontSize} + .cm-ySelectionCaret`] = { height };
|
|
2393
|
+
// acc[`& .text-${fontSize} + .cm-ySelection + .cm-ySelectionCaret`] = { height };
|
|
2394
|
+
// acc[`& .text-${fontSize} + .cm-widgetBuffer + .cm-ySelectionCaret`] = { height };
|
|
2395
|
+
// return acc;
|
|
2396
|
+
// }, {}),
|
|
2301
2397
|
/**
|
|
2302
2398
|
* Panels
|
|
2303
2399
|
* TODO(burdon): Needs styling attention (esp. dark mode).
|
|
@@ -2314,88 +2410,83 @@ var defaultTheme = {
|
|
|
2314
2410
|
* </div>
|
|
2315
2411
|
* </div
|
|
2316
2412
|
*/
|
|
2317
|
-
"
|
|
2318
|
-
border: `1px solid ${
|
|
2413
|
+
".cm-panels": {
|
|
2414
|
+
border: `1px solid ${get3(tokens, "extend.colors.neutral.200")}`
|
|
2319
2415
|
},
|
|
2320
|
-
"
|
|
2321
|
-
background:
|
|
2322
|
-
fontFamily:
|
|
2416
|
+
".cm-panel": {
|
|
2417
|
+
background: get3(tokens, "extend.colors.neutral.50"),
|
|
2418
|
+
fontFamily: get3(tokens, "fontFamily.body", []).join(",")
|
|
2323
2419
|
},
|
|
2324
|
-
"
|
|
2420
|
+
".cm-button": {
|
|
2325
2421
|
margin: "4px",
|
|
2326
|
-
fontFamily:
|
|
2327
|
-
background:
|
|
2422
|
+
fontFamily: get3(tokens, "fontFamily.body", []).join(","),
|
|
2423
|
+
background: get3(tokens, "extend.colors.neutral.100"),
|
|
2328
2424
|
backgroundImage: "none",
|
|
2329
2425
|
border: "none",
|
|
2330
2426
|
"&:hover": {
|
|
2331
|
-
background:
|
|
2427
|
+
background: get3(tokens, "extend.colors.neutral.200")
|
|
2332
2428
|
},
|
|
2333
2429
|
"&:active": {
|
|
2334
|
-
background:
|
|
2430
|
+
background: get3(tokens, "extend.colors.neutral.300"),
|
|
2335
2431
|
backgroundImage: "none"
|
|
2336
2432
|
}
|
|
2337
2433
|
},
|
|
2338
|
-
"
|
|
2434
|
+
".cm-panel input[type=checkbox]": {
|
|
2339
2435
|
marginRight: "0.4rem !important"
|
|
2340
2436
|
}
|
|
2341
2437
|
};
|
|
2342
2438
|
var textTheme = {
|
|
2343
|
-
"
|
|
2344
|
-
fontFamily:
|
|
2439
|
+
".cm-scroller": {
|
|
2440
|
+
fontFamily: get3(tokens, "fontFamily.body", []).join(",")
|
|
2345
2441
|
},
|
|
2346
|
-
"
|
|
2347
|
-
fontFamily:
|
|
2442
|
+
".cm-placeholder": {
|
|
2443
|
+
fontFamily: get3(tokens, "fontFamily.body", []).join(",")
|
|
2348
2444
|
}
|
|
2349
2445
|
};
|
|
2350
2446
|
var markdownTheme = {
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2447
|
+
".cm-scroller": {
|
|
2448
|
+
fontFamily: get3(tokens, "fontFamily.body", []).join(",")
|
|
2449
|
+
},
|
|
2450
|
+
".cm-placeholder": {
|
|
2451
|
+
fontFamily: get3(tokens, "fontFamily.body", []).join(",")
|
|
2354
2452
|
}
|
|
2355
2453
|
};
|
|
2356
2454
|
var codeTheme = {
|
|
2357
|
-
"
|
|
2358
|
-
fontFamily:
|
|
2455
|
+
".cm-scroller": {
|
|
2456
|
+
fontFamily: get3(tokens, "fontFamily.mono", []).join(",")
|
|
2359
2457
|
},
|
|
2360
|
-
"
|
|
2361
|
-
fontFamily:
|
|
2458
|
+
".cm-placeholder": {
|
|
2459
|
+
fontFamily: get3(tokens, "fontFamily.mono", []).join(",")
|
|
2362
2460
|
}
|
|
2363
2461
|
};
|
|
2364
2462
|
|
|
2365
2463
|
// 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
2464
|
var EditorModes = [
|
|
2376
2465
|
"default",
|
|
2377
2466
|
"vim"
|
|
2378
2467
|
];
|
|
2379
|
-
var BaseTextEditor = /* @__PURE__ */ forwardRef(({ model,
|
|
2380
|
-
const { themeMode } = useThemeContext();
|
|
2468
|
+
var BaseTextEditor = /* @__PURE__ */ forwardRef(({ model, autofocus, readonly, selection, comments: comments2, extensions = [], editorMode, theme, slots = defaultSlots }, forwardedRef) => {
|
|
2381
2469
|
const tabsterDOMAttribute = useFocusableGroup({
|
|
2382
2470
|
tabBehavior: "limited"
|
|
2383
2471
|
});
|
|
2384
|
-
const
|
|
2385
|
-
const
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
state,
|
|
2472
|
+
const { themeMode } = useThemeContext();
|
|
2473
|
+
const rootRef = useRef(null);
|
|
2474
|
+
const [view, setView] = useState(null);
|
|
2475
|
+
useImperativeHandle(forwardedRef, () => view, [
|
|
2389
2476
|
view
|
|
2390
|
-
}), [
|
|
2391
|
-
view,
|
|
2392
|
-
state,
|
|
2393
|
-
root
|
|
2394
2477
|
]);
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2478
|
+
useEffect(() => {
|
|
2479
|
+
if (autofocus) {
|
|
2480
|
+
view?.focus();
|
|
2481
|
+
}
|
|
2482
|
+
}, [
|
|
2483
|
+
autofocus,
|
|
2484
|
+
view
|
|
2485
|
+
]);
|
|
2486
|
+
const { awareness: awareness2, peer } = model;
|
|
2487
|
+
useEffect(() => {
|
|
2488
|
+
if (awareness2 && peer) {
|
|
2489
|
+
awareness2.setLocalStateField("user", {
|
|
2399
2490
|
name: peer.name ?? generateName(peer.id),
|
|
2400
2491
|
color: getColorForValue({
|
|
2401
2492
|
value: peer.id,
|
|
@@ -2409,12 +2500,12 @@ var BaseTextEditor = /* @__PURE__ */ forwardRef(({ model, comments: comments2, r
|
|
|
2409
2500
|
});
|
|
2410
2501
|
}
|
|
2411
2502
|
}, [
|
|
2412
|
-
|
|
2503
|
+
awareness2,
|
|
2413
2504
|
peer,
|
|
2414
2505
|
themeMode
|
|
2415
2506
|
]);
|
|
2416
|
-
|
|
2417
|
-
if (view && comments2
|
|
2507
|
+
useEffect(() => {
|
|
2508
|
+
if (view && comments2 !== void 0) {
|
|
2418
2509
|
view.dispatch({
|
|
2419
2510
|
effects: setCommentRange.of({
|
|
2420
2511
|
model,
|
|
@@ -2426,21 +2517,23 @@ var BaseTextEditor = /* @__PURE__ */ forwardRef(({ model, comments: comments2, r
|
|
|
2426
2517
|
view,
|
|
2427
2518
|
comments2
|
|
2428
2519
|
]);
|
|
2429
|
-
|
|
2430
|
-
if (!
|
|
2520
|
+
useEffect(() => {
|
|
2521
|
+
if (!model || !rootRef.current) {
|
|
2431
2522
|
return;
|
|
2432
2523
|
}
|
|
2433
|
-
const
|
|
2524
|
+
const state = EditorState2.create({
|
|
2434
2525
|
doc: model.text(),
|
|
2526
|
+
// TODO(burdon): Composer should store and set selection when switching documents.
|
|
2527
|
+
selection,
|
|
2435
2528
|
extensions: [
|
|
2436
2529
|
readonly && EditorState2.readOnly.of(readonly),
|
|
2437
2530
|
// TODO(burdon): Factor out VIM mode? (manage via MarkdownPlugin).
|
|
2438
2531
|
editorMode === "vim" && vim(),
|
|
2439
2532
|
// Theme.
|
|
2440
2533
|
// TODO(burdon): Make theme configurable.
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2534
|
+
EditorView12.baseTheme(defaultTheme),
|
|
2535
|
+
EditorView12.theme(theme ?? {}),
|
|
2536
|
+
EditorView12.darkTheme.of(themeMode === "dark"),
|
|
2444
2537
|
// Storage and replication.
|
|
2445
2538
|
model.extension,
|
|
2446
2539
|
// Custom.
|
|
@@ -2448,19 +2541,17 @@ var BaseTextEditor = /* @__PURE__ */ forwardRef(({ model, comments: comments2, r
|
|
|
2448
2541
|
].filter(Boolean)
|
|
2449
2542
|
});
|
|
2450
2543
|
view?.destroy();
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
state: state2,
|
|
2455
|
-
parent: root
|
|
2456
|
-
})
|
|
2544
|
+
const newView = new EditorView12({
|
|
2545
|
+
parent: rootRef.current,
|
|
2546
|
+
state
|
|
2457
2547
|
});
|
|
2548
|
+
setView(newView);
|
|
2458
2549
|
return () => {
|
|
2459
|
-
|
|
2460
|
-
|
|
2550
|
+
newView?.destroy();
|
|
2551
|
+
setView(null);
|
|
2461
2552
|
};
|
|
2462
2553
|
}, [
|
|
2463
|
-
|
|
2554
|
+
rootRef,
|
|
2464
2555
|
model,
|
|
2465
2556
|
readonly,
|
|
2466
2557
|
editorMode,
|
|
@@ -2469,12 +2560,8 @@ var BaseTextEditor = /* @__PURE__ */ forwardRef(({ model, comments: comments2, r
|
|
|
2469
2560
|
const handleKeyUp = useCallback((event) => {
|
|
2470
2561
|
const { key, altKey, shiftKey, metaKey, ctrlKey } = event;
|
|
2471
2562
|
switch (key) {
|
|
2472
|
-
case "Enter": {
|
|
2473
|
-
view?.contentDOM.focus();
|
|
2474
|
-
break;
|
|
2475
|
-
}
|
|
2476
2563
|
case "Escape": {
|
|
2477
|
-
editorMode === "vim" && (altKey || shiftKey || metaKey || ctrlKey) &&
|
|
2564
|
+
editorMode === "vim" && (altKey || shiftKey || metaKey || ctrlKey) && rootRef.current?.focus();
|
|
2478
2565
|
break;
|
|
2479
2566
|
}
|
|
2480
2567
|
}
|
|
@@ -2484,16 +2571,17 @@ var BaseTextEditor = /* @__PURE__ */ forwardRef(({ model, comments: comments2, r
|
|
|
2484
2571
|
]);
|
|
2485
2572
|
return /* @__PURE__ */ React.createElement("div", {
|
|
2486
2573
|
key: model.id,
|
|
2487
|
-
|
|
2574
|
+
role: "none",
|
|
2488
2575
|
tabIndex: 0,
|
|
2489
|
-
|
|
2576
|
+
onKeyUp: handleKeyUp,
|
|
2577
|
+
...slots.root,
|
|
2490
2578
|
...editorMode !== "vim" && tabsterDOMAttribute,
|
|
2491
|
-
|
|
2579
|
+
ref: rootRef
|
|
2492
2580
|
});
|
|
2493
2581
|
});
|
|
2494
|
-
var TextEditor = /* @__PURE__ */ forwardRef(({ readonly, extensions = [],
|
|
2582
|
+
var TextEditor = /* @__PURE__ */ forwardRef(({ readonly, placeholder: placeholder3, extensions = [], theme = textTheme, slots, ...props }, forwardedRef) => {
|
|
2495
2583
|
const { themeMode } = useThemeContext();
|
|
2496
|
-
const
|
|
2584
|
+
const updatedSlots = defaultsDeep2({}, slots, defaultTextSlots);
|
|
2497
2585
|
return /* @__PURE__ */ React.createElement(BaseTextEditor, {
|
|
2498
2586
|
ref: forwardedRef,
|
|
2499
2587
|
readonly,
|
|
@@ -2501,17 +2589,18 @@ var TextEditor = /* @__PURE__ */ forwardRef(({ readonly, extensions = [], slots:
|
|
|
2501
2589
|
basicBundle({
|
|
2502
2590
|
readonly,
|
|
2503
2591
|
themeMode,
|
|
2504
|
-
placeholder:
|
|
2592
|
+
placeholder: placeholder3
|
|
2505
2593
|
}),
|
|
2506
2594
|
...extensions
|
|
2507
2595
|
],
|
|
2508
|
-
|
|
2596
|
+
theme,
|
|
2597
|
+
slots: updatedSlots,
|
|
2509
2598
|
...props
|
|
2510
2599
|
});
|
|
2511
2600
|
});
|
|
2512
|
-
var MarkdownEditor = /* @__PURE__ */ forwardRef(({ readonly, extensions = [],
|
|
2601
|
+
var MarkdownEditor = /* @__PURE__ */ forwardRef(({ readonly, placeholder: placeholder3, extensions = [], theme = markdownTheme, slots, ...props }, forwardedRef) => {
|
|
2513
2602
|
const { themeMode } = useThemeContext();
|
|
2514
|
-
const
|
|
2603
|
+
const updatedSlots = defaultsDeep2({}, slots, defaultMarkdownSlots);
|
|
2515
2604
|
return /* @__PURE__ */ React.createElement(BaseTextEditor, {
|
|
2516
2605
|
ref: forwardedRef,
|
|
2517
2606
|
readonly,
|
|
@@ -2519,53 +2608,368 @@ var MarkdownEditor = /* @__PURE__ */ forwardRef(({ readonly, extensions = [], sl
|
|
|
2519
2608
|
markdownBundle({
|
|
2520
2609
|
readonly,
|
|
2521
2610
|
themeMode,
|
|
2522
|
-
placeholder:
|
|
2611
|
+
placeholder: placeholder3
|
|
2523
2612
|
}),
|
|
2524
2613
|
...extensions
|
|
2525
2614
|
],
|
|
2526
|
-
|
|
2615
|
+
theme,
|
|
2616
|
+
slots: updatedSlots,
|
|
2527
2617
|
...props
|
|
2528
2618
|
});
|
|
2529
2619
|
});
|
|
2530
2620
|
var defaultSlots = {
|
|
2531
2621
|
root: {
|
|
2532
|
-
className: mx3("p-2", inputSurface)
|
|
2622
|
+
className: mx3("w-full p-2 overflow-y-auto", inputSurface)
|
|
2533
2623
|
}
|
|
2534
2624
|
};
|
|
2535
2625
|
var defaultTextSlots = {
|
|
2536
|
-
...defaultSlots
|
|
2537
|
-
editor: {
|
|
2538
|
-
theme: textTheme
|
|
2539
|
-
}
|
|
2626
|
+
...defaultSlots
|
|
2540
2627
|
};
|
|
2541
2628
|
var defaultMarkdownSlots = {
|
|
2542
|
-
...defaultSlots
|
|
2543
|
-
|
|
2544
|
-
|
|
2629
|
+
...defaultSlots
|
|
2630
|
+
};
|
|
2631
|
+
|
|
2632
|
+
// packages/ui/react-ui-editor/src/hooks/automerge.ts
|
|
2633
|
+
import get4 from "lodash.get";
|
|
2634
|
+
import { getRawDoc } from "@dxos/echo-schema";
|
|
2635
|
+
import { isNotNullOrUndefined } from "@dxos/util";
|
|
2636
|
+
|
|
2637
|
+
// packages/ui/react-ui-editor/src/hooks/awareness-provider.ts
|
|
2638
|
+
import { DeferredTask, Event as Event2, sleep } from "@dxos/async";
|
|
2639
|
+
import { Context as Context2 } from "@dxos/context";
|
|
2640
|
+
import { invariant as invariant3 } from "@dxos/invariant";
|
|
2641
|
+
import { log as log2 } from "@dxos/log";
|
|
2642
|
+
var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/hooks/awareness-provider.ts";
|
|
2643
|
+
var DEBOUNCE_INTERVAL = 100;
|
|
2644
|
+
var SpaceAwarenessProvider = class {
|
|
2645
|
+
constructor(params) {
|
|
2646
|
+
this.remoteStateChange = new Event2();
|
|
2647
|
+
this._remoteStates = /* @__PURE__ */ new Map();
|
|
2648
|
+
this._space = params.space;
|
|
2649
|
+
this._channel = params.channel;
|
|
2650
|
+
this._peerId = params.peerId;
|
|
2651
|
+
this._info = params.info;
|
|
2652
|
+
}
|
|
2653
|
+
open() {
|
|
2654
|
+
this._ctx = new Context2();
|
|
2655
|
+
this._postTask = new DeferredTask(this._ctx, async () => {
|
|
2656
|
+
if (this._localState) {
|
|
2657
|
+
await this._space.postMessage(this._channel, {
|
|
2658
|
+
kind: "post",
|
|
2659
|
+
state: this._localState
|
|
2660
|
+
});
|
|
2661
|
+
await sleep(DEBOUNCE_INTERVAL);
|
|
2662
|
+
}
|
|
2663
|
+
});
|
|
2664
|
+
const unsubscribe = this._space.listen(this._channel, (message) => {
|
|
2665
|
+
switch (message.payload.kind) {
|
|
2666
|
+
case "query": {
|
|
2667
|
+
this._handleQueryMessage();
|
|
2668
|
+
break;
|
|
2669
|
+
}
|
|
2670
|
+
case "post": {
|
|
2671
|
+
this._handlePostMessage(message.payload);
|
|
2672
|
+
break;
|
|
2673
|
+
}
|
|
2674
|
+
}
|
|
2675
|
+
});
|
|
2676
|
+
this._ctx.onDispose(unsubscribe);
|
|
2677
|
+
void this._space.postMessage(this._channel, {
|
|
2678
|
+
kind: "query"
|
|
2679
|
+
}).catch((err) => {
|
|
2680
|
+
log2.debug("failed to query awareness", {
|
|
2681
|
+
err
|
|
2682
|
+
}, {
|
|
2683
|
+
F: __dxlog_file4,
|
|
2684
|
+
L: 85,
|
|
2685
|
+
S: this,
|
|
2686
|
+
C: (f, a) => f(...a)
|
|
2687
|
+
});
|
|
2688
|
+
});
|
|
2689
|
+
}
|
|
2690
|
+
close() {
|
|
2691
|
+
void this._ctx?.dispose();
|
|
2692
|
+
this._ctx = void 0;
|
|
2693
|
+
this._postTask = void 0;
|
|
2694
|
+
}
|
|
2695
|
+
update(position) {
|
|
2696
|
+
invariant3(this._postTask, void 0, {
|
|
2697
|
+
F: __dxlog_file4,
|
|
2698
|
+
L: 96,
|
|
2699
|
+
S: this,
|
|
2700
|
+
A: [
|
|
2701
|
+
"this._postTask",
|
|
2702
|
+
""
|
|
2703
|
+
]
|
|
2704
|
+
});
|
|
2705
|
+
this._localState = {
|
|
2706
|
+
peerId: this._peerId,
|
|
2707
|
+
position,
|
|
2708
|
+
info: this._info
|
|
2709
|
+
};
|
|
2710
|
+
this._postTask.schedule();
|
|
2711
|
+
}
|
|
2712
|
+
getRemoteStates() {
|
|
2713
|
+
return Array.from(this._remoteStates.values());
|
|
2714
|
+
}
|
|
2715
|
+
_handleQueryMessage() {
|
|
2716
|
+
invariant3(this._postTask, void 0, {
|
|
2717
|
+
F: __dxlog_file4,
|
|
2718
|
+
L: 111,
|
|
2719
|
+
S: this,
|
|
2720
|
+
A: [
|
|
2721
|
+
"this._postTask",
|
|
2722
|
+
""
|
|
2723
|
+
]
|
|
2724
|
+
});
|
|
2725
|
+
this._postTask.schedule();
|
|
2726
|
+
}
|
|
2727
|
+
_handlePostMessage(message) {
|
|
2728
|
+
invariant3(message.kind === "post", void 0, {
|
|
2729
|
+
F: __dxlog_file4,
|
|
2730
|
+
L: 116,
|
|
2731
|
+
S: this,
|
|
2732
|
+
A: [
|
|
2733
|
+
"message.kind === 'post'",
|
|
2734
|
+
""
|
|
2735
|
+
]
|
|
2736
|
+
});
|
|
2737
|
+
this._remoteStates.set(message.state.peerId, message.state);
|
|
2738
|
+
this.remoteStateChange.emit();
|
|
2739
|
+
}
|
|
2740
|
+
};
|
|
2741
|
+
|
|
2742
|
+
// packages/ui/react-ui-editor/src/hooks/useTextModel.ts
|
|
2743
|
+
import { StateField as StateField5 } from "@codemirror/state";
|
|
2744
|
+
import { useEffect as useEffect2, useState as useState2 } from "react";
|
|
2745
|
+
import { isAutomergeObject } from "@dxos/react-client/echo";
|
|
2746
|
+
|
|
2747
|
+
// packages/ui/react-ui-editor/src/hooks/yjs.ts
|
|
2748
|
+
import * as decoding from "lib0/decoding";
|
|
2749
|
+
import * as encoding from "lib0/encoding";
|
|
2750
|
+
import { Observable } from "lib0/observable";
|
|
2751
|
+
import * as YP from "y-protocols/awareness";
|
|
2752
|
+
import { invariant as invariant4 } from "@dxos/invariant";
|
|
2753
|
+
import { log as log3 } from "@dxos/log";
|
|
2754
|
+
var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/hooks/yjs.ts";
|
|
2755
|
+
var createYjsModel = ({ identity, space, text }) => {
|
|
2756
|
+
invariant4(text?.doc && text?.content, void 0, {
|
|
2757
|
+
F: __dxlog_file5,
|
|
2758
|
+
L: 21,
|
|
2759
|
+
S: void 0,
|
|
2760
|
+
A: [
|
|
2761
|
+
"text?.doc && text?.content",
|
|
2762
|
+
""
|
|
2763
|
+
]
|
|
2764
|
+
});
|
|
2765
|
+
const provider = space ? new YAwarenessProvider({
|
|
2766
|
+
space,
|
|
2767
|
+
doc: text.doc,
|
|
2768
|
+
channel: `yjs.awareness.${text.id}`
|
|
2769
|
+
}) : void 0;
|
|
2770
|
+
const model = {
|
|
2771
|
+
id: text.doc.guid,
|
|
2772
|
+
content: text.content,
|
|
2773
|
+
text: () => text.content.toString(),
|
|
2774
|
+
extension: [
|
|
2775
|
+
modelState.init(() => model),
|
|
2776
|
+
yjs(text.content, provider?.awareness)
|
|
2777
|
+
],
|
|
2778
|
+
awareness: provider?.awareness,
|
|
2779
|
+
peer: identity ? {
|
|
2780
|
+
id: identity.identityKey.toHex(),
|
|
2781
|
+
name: identity.profile?.displayName
|
|
2782
|
+
} : void 0
|
|
2783
|
+
};
|
|
2784
|
+
return model;
|
|
2785
|
+
};
|
|
2786
|
+
var messageAwareness = 1;
|
|
2787
|
+
var messageQueryAwareness = 3;
|
|
2788
|
+
var YAwarenessProvider = class extends Observable {
|
|
2789
|
+
constructor({ space, doc, channel, awareness: awareness2 }) {
|
|
2790
|
+
super();
|
|
2791
|
+
this._space = space;
|
|
2792
|
+
this._awareness = awareness2 ?? new YP.Awareness(doc);
|
|
2793
|
+
this._channel = channel;
|
|
2794
|
+
this._clientId = doc.clientID;
|
|
2795
|
+
this._awareness.on("update", this._handleAwarenessUpdate.bind(this));
|
|
2796
|
+
this._space.listen(this._channel, this._handleSpaceMessage.bind(this));
|
|
2797
|
+
if (typeof window !== "undefined") {
|
|
2798
|
+
window.addEventListener("beforeunload", this._handleBeforeUnload.bind(this));
|
|
2799
|
+
} else if (typeof process !== "undefined") {
|
|
2800
|
+
process.on("exit", this._handleBeforeUnload.bind(this));
|
|
2801
|
+
}
|
|
2802
|
+
const encoderAwarenessQuery = encoding.createEncoder();
|
|
2803
|
+
encoding.writeVarUint(encoderAwarenessQuery, messageQueryAwareness);
|
|
2804
|
+
void this._space.postMessage(this._channel, encoding.toUint8Array(encoderAwarenessQuery));
|
|
2805
|
+
const encoderAwarenessState = encoding.createEncoder();
|
|
2806
|
+
encoding.writeVarUint(encoderAwarenessState, messageAwareness);
|
|
2807
|
+
encoding.writeVarUint8Array(encoderAwarenessState, YP.encodeAwarenessUpdate(this.awareness, [
|
|
2808
|
+
this._clientId
|
|
2809
|
+
]));
|
|
2810
|
+
void this._space.postMessage(this._channel, encoding.toUint8Array(encoderAwarenessState));
|
|
2811
|
+
}
|
|
2812
|
+
get awareness() {
|
|
2813
|
+
return this._awareness;
|
|
2814
|
+
}
|
|
2815
|
+
_handleAwarenessUpdate({ added, updated, removed }, origin) {
|
|
2816
|
+
log3("awareness update", {
|
|
2817
|
+
added,
|
|
2818
|
+
updated,
|
|
2819
|
+
removed,
|
|
2820
|
+
origin
|
|
2821
|
+
}, {
|
|
2822
|
+
F: __dxlog_file5,
|
|
2823
|
+
L: 100,
|
|
2824
|
+
S: this,
|
|
2825
|
+
C: (f, a) => f(...a)
|
|
2826
|
+
});
|
|
2827
|
+
const changedClients = added.concat(updated).concat(removed);
|
|
2828
|
+
const encoderAwareness = encoding.createEncoder();
|
|
2829
|
+
encoding.writeVarUint(encoderAwareness, messageAwareness);
|
|
2830
|
+
encoding.writeVarUint8Array(encoderAwareness, YP.encodeAwarenessUpdate(this._awareness, changedClients));
|
|
2831
|
+
void this._space.postMessage(this._channel, encoding.toUint8Array(encoderAwareness));
|
|
2832
|
+
}
|
|
2833
|
+
_handleSpaceMessage({ payload }) {
|
|
2834
|
+
log3("space message", payload, {
|
|
2835
|
+
F: __dxlog_file5,
|
|
2836
|
+
L: 109,
|
|
2837
|
+
S: this,
|
|
2838
|
+
C: (f, a) => f(...a)
|
|
2839
|
+
});
|
|
2840
|
+
const data = new Uint8Array(Array.from(Object.values(payload)));
|
|
2841
|
+
const encoder = this._readMessage(data);
|
|
2842
|
+
if (encoder) {
|
|
2843
|
+
void this._space.postMessage(this._channel, encoding.toUint8Array(encoder));
|
|
2844
|
+
}
|
|
2845
|
+
}
|
|
2846
|
+
_readMessage(message) {
|
|
2847
|
+
const decoder = decoding.createDecoder(message);
|
|
2848
|
+
const encoder = encoding.createEncoder();
|
|
2849
|
+
const messageType = decoding.readVarUint(decoder);
|
|
2850
|
+
let sendReply = false;
|
|
2851
|
+
switch (messageType) {
|
|
2852
|
+
case messageAwareness: {
|
|
2853
|
+
YP.applyAwarenessUpdate(this._awareness, decoding.readVarUint8Array(decoder), this);
|
|
2854
|
+
break;
|
|
2855
|
+
}
|
|
2856
|
+
case messageQueryAwareness: {
|
|
2857
|
+
encoding.writeVarUint(encoder, messageAwareness);
|
|
2858
|
+
encoding.writeVarUint8Array(encoder, YP.encodeAwarenessUpdate(this._awareness, Array.from(this._awareness.getStates().keys())));
|
|
2859
|
+
sendReply = true;
|
|
2860
|
+
break;
|
|
2861
|
+
}
|
|
2862
|
+
default: {
|
|
2863
|
+
console.error("Invalid message:", messageType);
|
|
2864
|
+
return encoder;
|
|
2865
|
+
}
|
|
2866
|
+
}
|
|
2867
|
+
if (!sendReply) {
|
|
2868
|
+
return null;
|
|
2869
|
+
}
|
|
2870
|
+
return encoder;
|
|
2871
|
+
}
|
|
2872
|
+
_handleBeforeUnload() {
|
|
2873
|
+
YP.removeAwarenessStates(this._awareness, [
|
|
2874
|
+
this._clientId
|
|
2875
|
+
], "window unload");
|
|
2876
|
+
}
|
|
2877
|
+
};
|
|
2878
|
+
|
|
2879
|
+
// packages/ui/react-ui-editor/src/hooks/useTextModel.ts
|
|
2880
|
+
var modelState = StateField5.define({
|
|
2881
|
+
create: () => void 0,
|
|
2882
|
+
update: (model) => model
|
|
2883
|
+
});
|
|
2884
|
+
var useTextModel = (props) => {
|
|
2885
|
+
const { identity, space, text } = props;
|
|
2886
|
+
const [model, setModel] = useState2();
|
|
2887
|
+
useEffect2(() => setModel(createModel(props)), [
|
|
2888
|
+
identity,
|
|
2889
|
+
space,
|
|
2890
|
+
text
|
|
2891
|
+
]);
|
|
2892
|
+
return model;
|
|
2893
|
+
};
|
|
2894
|
+
var createModel = (props) => {
|
|
2895
|
+
const { text } = props;
|
|
2896
|
+
if (isAutomergeObject(text)) {
|
|
2897
|
+
return createAutomergeModel(props);
|
|
2898
|
+
} else if (text?.doc) {
|
|
2899
|
+
return createYjsModel(props);
|
|
2900
|
+
} else {
|
|
2901
|
+
return void 0;
|
|
2545
2902
|
}
|
|
2546
2903
|
};
|
|
2904
|
+
|
|
2905
|
+
// packages/ui/react-ui-editor/src/hooks/automerge.ts
|
|
2906
|
+
var createAutomergeModel = ({ space, identity, text }) => {
|
|
2907
|
+
const obj = text;
|
|
2908
|
+
const doc = getRawDoc(obj, [
|
|
2909
|
+
obj.field
|
|
2910
|
+
]);
|
|
2911
|
+
const awarenessProvider = space && new SpaceAwarenessProvider({
|
|
2912
|
+
space,
|
|
2913
|
+
channel: `automerge.awareness.${obj.id}`,
|
|
2914
|
+
info: {
|
|
2915
|
+
displayName: identity?.profile?.displayName ?? "",
|
|
2916
|
+
color: cursorColor.color,
|
|
2917
|
+
lightColor: cursorColor.light
|
|
2918
|
+
},
|
|
2919
|
+
peerId: identity?.identityKey.toHex() ?? "Anonymous"
|
|
2920
|
+
});
|
|
2921
|
+
const model = {
|
|
2922
|
+
id: obj.id,
|
|
2923
|
+
content: doc,
|
|
2924
|
+
text: () => get4(doc.handle.docSync(), doc.path),
|
|
2925
|
+
// TODO(burdon): https://automerge.org/automerge/api-docs/js/functions/next.getCursor.html
|
|
2926
|
+
extension: [
|
|
2927
|
+
modelState.init(() => model),
|
|
2928
|
+
automerge3({
|
|
2929
|
+
handle: doc.handle,
|
|
2930
|
+
path: doc.path
|
|
2931
|
+
}),
|
|
2932
|
+
awarenessProvider && AwarenessProvider.of(awarenessProvider),
|
|
2933
|
+
awareness()
|
|
2934
|
+
].filter(isNotNullOrUndefined),
|
|
2935
|
+
peer: identity ? {
|
|
2936
|
+
id: identity.identityKey.toHex(),
|
|
2937
|
+
name: identity.profile?.displayName
|
|
2938
|
+
} : void 0
|
|
2939
|
+
};
|
|
2940
|
+
return model;
|
|
2941
|
+
};
|
|
2547
2942
|
export {
|
|
2943
|
+
AwarenessProvider,
|
|
2548
2944
|
BaseTextEditor,
|
|
2945
|
+
Cursor,
|
|
2549
2946
|
Doc,
|
|
2550
2947
|
EditorModes,
|
|
2551
2948
|
MarkdownEditor,
|
|
2949
|
+
RemoteSelectionsDecorator,
|
|
2552
2950
|
SpaceAwarenessProvider,
|
|
2553
2951
|
TextEditor,
|
|
2554
2952
|
TextKind,
|
|
2953
|
+
YAwarenessProvider,
|
|
2555
2954
|
YText,
|
|
2556
2955
|
YXmlFragment,
|
|
2557
2956
|
autocomplete,
|
|
2957
|
+
automerge3 as automerge,
|
|
2958
|
+
awareness,
|
|
2558
2959
|
basicBundle,
|
|
2559
2960
|
blast,
|
|
2961
|
+
callbackWrapper,
|
|
2560
2962
|
code2 as code,
|
|
2561
2963
|
codeTheme,
|
|
2562
2964
|
comments,
|
|
2563
|
-
|
|
2965
|
+
createAutomergeModel,
|
|
2966
|
+
createYjsModel,
|
|
2564
2967
|
defaultMarkdownSlots,
|
|
2565
2968
|
defaultOptions,
|
|
2566
2969
|
defaultSlots,
|
|
2567
2970
|
defaultTextSlots,
|
|
2568
2971
|
defaultTheme,
|
|
2972
|
+
getToken,
|
|
2569
2973
|
hr,
|
|
2570
2974
|
image,
|
|
2571
2975
|
link,
|
|
@@ -2576,15 +2980,16 @@ export {
|
|
|
2576
2980
|
markdownTagsExtensions,
|
|
2577
2981
|
markdownTheme,
|
|
2578
2982
|
mention,
|
|
2579
|
-
mermaid,
|
|
2580
2983
|
modelState,
|
|
2581
2984
|
setCommentRange,
|
|
2985
|
+
setFocus,
|
|
2986
|
+
setSelection,
|
|
2582
2987
|
table,
|
|
2583
2988
|
tags2 as tags,
|
|
2584
2989
|
tasklist,
|
|
2585
2990
|
textTheme,
|
|
2586
|
-
tooltip,
|
|
2587
2991
|
typewriter,
|
|
2588
|
-
useTextModel
|
|
2992
|
+
useTextModel,
|
|
2993
|
+
yjs
|
|
2589
2994
|
};
|
|
2590
2995
|
//# sourceMappingURL=index.mjs.map
|