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