@dxos/react-ui-editor 0.3.11-main.bd26370 → 0.3.11-main.cf6cc01
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 +1706 -1338
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/types/src/components/TextEditor/MarkdownEditor.stories.d.ts +9 -8
- package/dist/types/src/components/TextEditor/MarkdownEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/TextEditor.d.ts +14 -19
- package/dist/types/src/components/TextEditor/TextEditor.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/TextEditor.stories.d.ts +6 -3
- package/dist/types/src/components/TextEditor/TextEditor.stories.d.ts.map +1 -1
- package/dist/types/src/{hooks/automerge → components/TextEditor}/automerge.stories.d.ts +6 -1
- package/dist/types/src/components/TextEditor/automerge.stories.d.ts.map +1 -0
- package/dist/types/src/components/TextEditor/codemirror.stories.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/comments.stories.d.ts +26 -0
- package/dist/types/src/components/TextEditor/comments.stories.d.ts.map +1 -0
- package/dist/types/src/components/TextEditor/index.d.ts +0 -2
- package/dist/types/src/components/TextEditor/index.d.ts.map +1 -1
- package/dist/types/src/{hooks/yjs → components/TextEditor}/yjs.stories.d.ts +1 -1
- package/dist/types/src/components/TextEditor/yjs.stories.d.ts.map +1 -0
- package/dist/types/src/extensions/autocomplete.d.ts.map +1 -0
- package/dist/types/src/extensions/automerge/automerge.d.ts +9 -0
- package/dist/types/src/extensions/automerge/automerge.d.ts.map +1 -0
- package/dist/types/src/extensions/automerge/cursor.d.ts +5 -0
- package/dist/types/src/extensions/automerge/cursor.d.ts.map +1 -0
- package/dist/types/src/extensions/automerge/defs.d.ts +26 -0
- package/dist/types/src/extensions/automerge/defs.d.ts.map +1 -0
- package/dist/types/src/extensions/automerge/index.d.ts +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 -2
- package/dist/types/src/extensions/index.d.ts.map +1 -0
- package/dist/types/src/{components/TextEditor/extensions → extensions}/link.d.ts +1 -0
- package/dist/types/src/extensions/link.d.ts.map +1 -0
- package/dist/types/src/extensions/listener.d.ts +10 -0
- package/dist/types/src/extensions/listener.d.ts.map +1 -0
- package/dist/types/src/extensions/markdown/bundle.d.ts.map +1 -0
- package/dist/types/src/extensions/markdown/highlight.d.ts.map +1 -0
- package/dist/types/src/extensions/markdown/index.d.ts.map +1 -0
- package/dist/types/src/extensions/mention.d.ts.map +1 -0
- package/dist/types/src/extensions/table.d.ts.map +1 -0
- package/dist/types/src/extensions/tasklist.d.ts.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 +36 -36
- package/src/components/TextEditor/TextEditor.stories.tsx +13 -34
- package/src/components/TextEditor/TextEditor.tsx +74 -70
- package/src/{hooks/automerge → components/TextEditor}/automerge.stories.tsx +66 -6
- package/src/components/TextEditor/codemirror.stories.ts +3 -2
- package/src/components/TextEditor/comments.stories.tsx +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 +50 -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 -2
- package/src/{components/TextEditor/extensions → extensions}/link.ts +116 -62
- package/src/extensions/listener.ts +35 -0
- package/src/{components/TextEditor/extensions → extensions}/markdown/highlight.ts +4 -13
- package/src/{components/TextEditor/extensions → extensions}/table.ts +10 -4
- package/src/{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 +52 -79
- package/dist/types/src/components/TextEditor/extensions/autocomplete.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/basic.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/blast.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/code.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/comments.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/hr.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/image.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/index.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/link.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/listener.d.ts +0 -9
- package/dist/types/src/components/TextEditor/extensions/listener.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/markdown/bundle.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/markdown/highlight.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/markdown/index.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/mention.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/mermaid.d.ts +0 -3
- package/dist/types/src/components/TextEditor/extensions/mermaid.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/table.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/tasklist.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/tooltip.d.ts +0 -12
- package/dist/types/src/components/TextEditor/extensions/tooltip.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/typewriter.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/util.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/themes/default.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/themes/index.d.ts.map +0 -1
- package/dist/types/src/hooks/automerge/automerge.stories.d.ts.map +0 -1
- package/dist/types/src/hooks/automerge/handle.d.ts +0 -9
- package/dist/types/src/hooks/automerge/handle.d.ts.map +0 -1
- package/dist/types/src/hooks/automerge/index.d.ts +0 -3
- package/dist/types/src/hooks/automerge/index.d.ts.map +0 -1
- package/dist/types/src/hooks/automerge/plugin.d.ts +0 -26
- package/dist/types/src/hooks/automerge/plugin.d.ts.map +0 -1
- package/dist/types/src/hooks/automerge/semaphore.d.ts.map +0 -1
- package/dist/types/src/hooks/automerge/update-automerge.d.ts +0 -6
- package/dist/types/src/hooks/automerge/update-automerge.d.ts.map +0 -1
- package/dist/types/src/hooks/automerge/update-codemirror.d.ts.map +0 -1
- package/dist/types/src/hooks/yjs/cursors.d.ts.map +0 -1
- package/dist/types/src/hooks/yjs/index.d.ts +0 -3
- package/dist/types/src/hooks/yjs/index.d.ts.map +0 -1
- package/dist/types/src/hooks/yjs/space-provider.d.ts.map +0 -1
- package/dist/types/src/hooks/yjs/yjs.stories.d.ts.map +0 -1
- package/dist/types/src/hooks/yjs/yjs.test.d.ts.map +0 -1
- package/src/components/TextEditor/extensions/image.ts +0 -69
- package/src/components/TextEditor/extensions/listener.ts +0 -23
- package/src/components/TextEditor/extensions/mermaid.ts +0 -11
- package/src/components/TextEditor/extensions/tooltip.ts +0 -61
- package/src/hooks/automerge/handle.ts +0 -14
- package/src/hooks/automerge/index.ts +0 -6
- package/src/hooks/automerge/plugin.ts +0 -134
- package/src/hooks/yjs/index.ts +0 -6
- /package/dist/types/src/{components/TextEditor/extensions → extensions}/autocomplete.d.ts +0 -0
- /package/dist/types/src/{hooks → extensions}/automerge/update-codemirror.d.ts +0 -0
- /package/dist/types/src/{components/TextEditor/extensions → extensions}/basic.d.ts +0 -0
- /package/dist/types/src/{components/TextEditor/extensions → extensions}/blast.d.ts +0 -0
- /package/dist/types/src/{components/TextEditor/extensions → extensions}/code.d.ts +0 -0
- /package/dist/types/src/{components/TextEditor/extensions → extensions}/hr.d.ts +0 -0
- /package/dist/types/src/{components/TextEditor/extensions → extensions}/image.d.ts +0 -0
- /package/dist/types/src/{components/TextEditor/extensions → extensions}/markdown/bundle.d.ts +0 -0
- /package/dist/types/src/{components/TextEditor/extensions → extensions}/markdown/highlight.d.ts +0 -0
- /package/dist/types/src/{components/TextEditor/extensions → extensions}/markdown/index.d.ts +0 -0
- /package/dist/types/src/{components/TextEditor/extensions → extensions}/mention.d.ts +0 -0
- /package/dist/types/src/{components/TextEditor/extensions → extensions}/table.d.ts +0 -0
- /package/dist/types/src/{components/TextEditor/extensions → extensions}/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}/markdown/bundle.ts +0 -0
- /package/src/{components/TextEditor/extensions → extensions}/markdown/index.ts +0 -0
- /package/src/{components/TextEditor/extensions → extensions}/mention.ts +0 -0
- /package/src/{hooks/yjs → styles}/cursors.ts +0 -0
- /package/src/{components/TextEditor/themes → themes}/index.ts +0 -0
- /package/src/{components/TextEditor/extensions/util.ts → util.ts} +0 -0
|
@@ -5,774 +5,939 @@ import { Doc, YText, YXmlFragment } from "@dxos/text-model";
|
|
|
5
5
|
// packages/ui/react-ui-editor/src/components/TextEditor/index.ts
|
|
6
6
|
import { tags as tags2 } from "@lezer/highlight";
|
|
7
7
|
|
|
8
|
-
// packages/ui/react-ui-editor/src/components/TextEditor/
|
|
8
|
+
// packages/ui/react-ui-editor/src/components/TextEditor/TextEditor.tsx
|
|
9
|
+
import { EditorState as EditorState2 } from "@codemirror/state";
|
|
10
|
+
import { EditorView as EditorView12 } from "@codemirror/view";
|
|
11
|
+
import { useFocusableGroup } from "@fluentui/react-tabster";
|
|
12
|
+
import { vim } from "@replit/codemirror-vim";
|
|
13
|
+
import defaultsDeep2 from "lodash.defaultsdeep";
|
|
14
|
+
import React, { forwardRef, useCallback, useEffect, useImperativeHandle, useState, useRef } from "react";
|
|
15
|
+
import { generateName } from "@dxos/display-name";
|
|
16
|
+
import { useThemeContext } from "@dxos/react-ui";
|
|
17
|
+
import { getColorForValue, inputSurface, mx as mx3 } from "@dxos/react-ui-theme";
|
|
18
|
+
|
|
19
|
+
// packages/ui/react-ui-editor/src/extensions/autocomplete.ts
|
|
9
20
|
import { autocompletion, completionKeymap } from "@codemirror/autocomplete";
|
|
21
|
+
import { markdownLanguage } from "@codemirror/lang-markdown";
|
|
10
22
|
import { keymap } from "@codemirror/view";
|
|
11
23
|
var autocomplete = ({ onSearch }) => {
|
|
12
24
|
return [
|
|
13
25
|
// https://codemirror.net/docs/ref/#view.keymap
|
|
14
26
|
// https://discuss.codemirror.net/t/how-can-i-replace-the-default-autocompletion-keymap-v6/3322
|
|
27
|
+
// TODO(burdon): Set custom keymap.
|
|
15
28
|
keymap.of(completionKeymap),
|
|
16
29
|
// https://codemirror.net/examples/autocompletion
|
|
17
30
|
// https://codemirror.net/docs/ref/#autocomplete.autocompletion
|
|
18
31
|
autocompletion({
|
|
19
|
-
|
|
20
|
-
// defaultKeymap: false,
|
|
32
|
+
defaultKeymap: false,
|
|
21
33
|
// Don't start unless key press.
|
|
22
|
-
activateOnTyping: false
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return {
|
|
32
|
-
from: match.from,
|
|
33
|
-
options: onSearch(match.text.toLowerCase())
|
|
34
|
-
};
|
|
34
|
+
activateOnTyping: false
|
|
35
|
+
}),
|
|
36
|
+
// TODO(burdon): Option to create new page?
|
|
37
|
+
// TODO(burdon): Optional decoration via addToOptions
|
|
38
|
+
markdownLanguage.data.of({
|
|
39
|
+
autocomplete: (context) => {
|
|
40
|
+
const match = context.matchBefore(/\w*/);
|
|
41
|
+
if (!match || match.from === match.to && !context.explicit) {
|
|
42
|
+
return null;
|
|
35
43
|
}
|
|
36
|
-
|
|
44
|
+
return {
|
|
45
|
+
from: match.from,
|
|
46
|
+
options: onSearch(match.text.toLowerCase())
|
|
47
|
+
};
|
|
48
|
+
}
|
|
37
49
|
})
|
|
38
50
|
];
|
|
39
51
|
};
|
|
40
52
|
|
|
41
|
-
// packages/ui/react-ui-editor/src/
|
|
42
|
-
import {
|
|
43
|
-
import {
|
|
44
|
-
import {
|
|
45
|
-
import { drawSelection, EditorView, placeholder } from "@codemirror/view";
|
|
46
|
-
var basicBundle = ({ readonly, themeMode, placeholder: _placeholder }) => [
|
|
47
|
-
EditorView.lineWrapping,
|
|
48
|
-
// TODO(burdon): Compare with minimalSetup.
|
|
49
|
-
// https://codemirror.net/docs/ref/#codemirror.minimalSetup
|
|
50
|
-
bracketMatching(),
|
|
51
|
-
closeBrackets(),
|
|
52
|
-
drawSelection(),
|
|
53
|
-
_placeholder && placeholder(_placeholder),
|
|
54
|
-
// TODO(burdon): Is this required?
|
|
55
|
-
themeMode === "dark" ? syntaxHighlighting(oneDarkHighlightStyle) : syntaxHighlighting(defaultHighlightStyle)
|
|
56
|
-
].filter(Boolean);
|
|
53
|
+
// packages/ui/react-ui-editor/src/extensions/automerge/automerge.ts
|
|
54
|
+
import { Facet as Facet2, StateField } from "@codemirror/state";
|
|
55
|
+
import { ViewPlugin } from "@codemirror/view";
|
|
56
|
+
import { next as A } from "@dxos/automerge/automerge";
|
|
57
57
|
|
|
58
|
-
// packages/ui/react-ui-editor/src/
|
|
59
|
-
import
|
|
60
|
-
import
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
min: 5,
|
|
74
|
-
max: 10
|
|
75
|
-
},
|
|
76
|
-
particleVelocityRange: {
|
|
77
|
-
x: [
|
|
78
|
-
-1,
|
|
79
|
-
1
|
|
80
|
-
],
|
|
81
|
-
y: [
|
|
82
|
-
-3.5,
|
|
83
|
-
-1.5
|
|
84
|
-
]
|
|
58
|
+
// packages/ui/react-ui-editor/src/extensions/automerge/cursor.ts
|
|
59
|
+
import get from "lodash.get";
|
|
60
|
+
import { next as automerge } from "@dxos/automerge/automerge";
|
|
61
|
+
var cursorConverter = (handle, path) => ({
|
|
62
|
+
// TODO(burdon): Handle assoc to associate with a previous character.
|
|
63
|
+
toCursor: (pos) => {
|
|
64
|
+
const doc = handle.docSync();
|
|
65
|
+
if (!doc) {
|
|
66
|
+
return "";
|
|
67
|
+
}
|
|
68
|
+
const value = get(doc, path);
|
|
69
|
+
if (typeof value === "string" && value.length <= pos) {
|
|
70
|
+
return "end";
|
|
71
|
+
}
|
|
72
|
+
return automerge.getCursor(doc, path.slice(), pos);
|
|
85
73
|
},
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
y: y - top
|
|
99
|
-
};
|
|
100
|
-
return {
|
|
101
|
-
element,
|
|
102
|
-
point
|
|
103
|
-
};
|
|
104
|
-
};
|
|
105
|
-
return [
|
|
106
|
-
// Cursor moved.
|
|
107
|
-
EditorView2.updateListener.of((update4) => {
|
|
108
|
-
if (blaster?.node !== update4.view.scrollDOM) {
|
|
109
|
-
if (blaster) {
|
|
110
|
-
blaster.destroy();
|
|
111
|
-
}
|
|
112
|
-
blaster = new Blaster(update4.view.scrollDOM, defaultsDeep({
|
|
113
|
-
particleGravity: 0.2,
|
|
114
|
-
particleShrinkRate: 0.995,
|
|
115
|
-
color: () => [
|
|
116
|
-
100 + Math.random() * 100,
|
|
117
|
-
0,
|
|
118
|
-
0
|
|
119
|
-
]
|
|
120
|
-
}, options, defaultOptions));
|
|
121
|
-
blaster.initialize();
|
|
122
|
-
blaster.start();
|
|
74
|
+
fromCursor: (cursor) => {
|
|
75
|
+
if (cursor === "") {
|
|
76
|
+
return 0;
|
|
77
|
+
}
|
|
78
|
+
const doc = handle.docSync();
|
|
79
|
+
if (!doc) {
|
|
80
|
+
return 0;
|
|
81
|
+
}
|
|
82
|
+
if (cursor === "end") {
|
|
83
|
+
const value = get(doc, path);
|
|
84
|
+
if (typeof value === "string") {
|
|
85
|
+
return value.length;
|
|
123
86
|
} else {
|
|
124
|
-
|
|
125
|
-
}
|
|
126
|
-
const current = update4.state.selection.main.head;
|
|
127
|
-
if (current !== last) {
|
|
128
|
-
last = current;
|
|
129
|
-
const { element, point } = getPoint(update4.view, current - 1);
|
|
130
|
-
if (element && point) {
|
|
131
|
-
blaster.spawn({
|
|
132
|
-
element,
|
|
133
|
-
point
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}),
|
|
138
|
-
keymap2.of([
|
|
139
|
-
{
|
|
140
|
-
any: (_, event) => {
|
|
141
|
-
if (blaster) {
|
|
142
|
-
if (event.key === "Enter" && event.shiftKey) {
|
|
143
|
-
blaster.shake({
|
|
144
|
-
time: 0.8
|
|
145
|
-
});
|
|
146
|
-
return true;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
return false;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
])
|
|
153
|
-
];
|
|
154
|
-
};
|
|
155
|
-
var Blaster = class {
|
|
156
|
-
constructor(_node, _options) {
|
|
157
|
-
this._node = _node;
|
|
158
|
-
this._options = _options;
|
|
159
|
-
this._running = false;
|
|
160
|
-
this._shakeTime = 0;
|
|
161
|
-
this._shakeTimeMax = 0;
|
|
162
|
-
this._particles = [];
|
|
163
|
-
this._particlePointer = 0;
|
|
164
|
-
this._lastPoint = {
|
|
165
|
-
x: 0,
|
|
166
|
-
y: 0
|
|
167
|
-
};
|
|
168
|
-
this.shake = throttle(({ time }) => {
|
|
169
|
-
this._shakeTime = this._shakeTimeMax || time;
|
|
170
|
-
this._shakeTimeMax = time;
|
|
171
|
-
}, 100);
|
|
172
|
-
this.spawn = throttle(({ element, point }) => {
|
|
173
|
-
const color = getRGBComponents(element, this._options.color);
|
|
174
|
-
const numParticles = random(this._options.particleNumRange.min, this._options.particleNumRange.max);
|
|
175
|
-
const dir = this._lastPoint.x === point.x ? 0 : this._lastPoint.x < point.x ? 1 : -1;
|
|
176
|
-
this._lastPoint = point;
|
|
177
|
-
for (let i = numParticles; i--; i > 0) {
|
|
178
|
-
this._particles[this._particlePointer] = this._effect.create(point.x - dir * 16, point.y, color);
|
|
179
|
-
this._particlePointer = (this._particlePointer + 1) % this._options.maxParticles;
|
|
87
|
+
return 0;
|
|
180
88
|
}
|
|
181
|
-
}, 100);
|
|
182
|
-
this._effect = this._options.effect === 1 ? new Effect1(_options) : new Effect2(_options);
|
|
183
|
-
}
|
|
184
|
-
get node() {
|
|
185
|
-
return this._node;
|
|
186
|
-
}
|
|
187
|
-
initialize() {
|
|
188
|
-
invariant(!this._canvas && !this._ctx, void 0, {
|
|
189
|
-
F: __dxlog_file,
|
|
190
|
-
L: 138,
|
|
191
|
-
S: this,
|
|
192
|
-
A: [
|
|
193
|
-
"!this._canvas && !this._ctx",
|
|
194
|
-
""
|
|
195
|
-
]
|
|
196
|
-
});
|
|
197
|
-
this._canvas = document.createElement("canvas");
|
|
198
|
-
this._canvas.id = "code-blast-canvas";
|
|
199
|
-
this._canvas.style.position = "absolute";
|
|
200
|
-
this._canvas.style.zIndex = "0";
|
|
201
|
-
this._canvas.style.pointerEvents = "none";
|
|
202
|
-
this._ctx = this._canvas.getContext("2d");
|
|
203
|
-
const parent = this._node.parentElement?.parentElement;
|
|
204
|
-
parent?.appendChild(this._canvas);
|
|
205
|
-
this.resize();
|
|
206
|
-
}
|
|
207
|
-
destroy() {
|
|
208
|
-
this.stop();
|
|
209
|
-
if (this._canvas) {
|
|
210
|
-
this._canvas.remove();
|
|
211
|
-
this._canvas = void 0;
|
|
212
|
-
this._ctx = void 0;
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
resize() {
|
|
216
|
-
if (this._node.parentElement && this._canvas) {
|
|
217
|
-
const { offsetLeft: x, offsetTop: y, offsetWidth: width, offsetHeight: height } = this._node.parentElement;
|
|
218
|
-
this._canvas.style.top = `${y}px`;
|
|
219
|
-
this._canvas.style.left = `${x}px`;
|
|
220
|
-
this._canvas.width = width;
|
|
221
|
-
this._canvas.height = height;
|
|
222
89
|
}
|
|
90
|
+
return automerge.getCursorPosition(doc, path.slice(), cursor);
|
|
223
91
|
}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
// packages/ui/react-ui-editor/src/extensions/automerge/defs.ts
|
|
95
|
+
import { Annotation, StateEffect } from "@codemirror/state";
|
|
96
|
+
var effectType = StateEffect.define({});
|
|
97
|
+
var updateHeads = (newHeads) => effectType.of({
|
|
98
|
+
newHeads
|
|
99
|
+
});
|
|
100
|
+
var getLastHeads = (state, field) => state.field(field).lastHeads;
|
|
101
|
+
var getPath = (state, field) => state.field(field).path;
|
|
102
|
+
var reconcileAnnotationType = Annotation.define();
|
|
103
|
+
var isReconcileTx = (tr) => !!tr.annotation(reconcileAnnotationType);
|
|
104
|
+
|
|
105
|
+
// packages/ui/react-ui-editor/src/extensions/automerge/semaphore.ts
|
|
106
|
+
import { next as automerge2 } from "@dxos/automerge/automerge";
|
|
107
|
+
|
|
108
|
+
// packages/ui/react-ui-editor/src/extensions/automerge/update-automerge.ts
|
|
109
|
+
import { next as am } from "@dxos/automerge/automerge";
|
|
110
|
+
var updateAutomerge = (field, handle, transactions, state) => {
|
|
111
|
+
const { lastHeads, path } = state.field(field);
|
|
112
|
+
let hasChanges = false;
|
|
113
|
+
for (const tr of transactions) {
|
|
114
|
+
tr.changes.iterChanges(() => {
|
|
115
|
+
hasChanges = true;
|
|
233
116
|
});
|
|
234
|
-
this._running = true;
|
|
235
|
-
this.loop();
|
|
236
117
|
}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
this._node.style.transform = "translate(0px, 0px)";
|
|
118
|
+
if (!hasChanges) {
|
|
119
|
+
return void 0;
|
|
240
120
|
}
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
const now = (/* @__PURE__ */ new Date()).getTime();
|
|
247
|
-
this._lastTime ??= now;
|
|
248
|
-
const dt = (now - this._lastTime) / 1e3;
|
|
249
|
-
this._lastTime = now;
|
|
250
|
-
if (this._shakeTime > 0) {
|
|
251
|
-
this._shakeTime -= dt;
|
|
252
|
-
const magnitude = this._shakeTime / this._shakeTimeMax * this._options.shakeIntensity;
|
|
253
|
-
const shakeX = random(-magnitude, magnitude);
|
|
254
|
-
const shakeY = random(-magnitude, magnitude);
|
|
255
|
-
this._node.style.transform = `translate(${shakeX}px,${shakeY}px)`;
|
|
121
|
+
const newHeads = handle.changeAt(lastHeads, (doc) => {
|
|
122
|
+
for (const tr of transactions) {
|
|
123
|
+
tr.changes.iterChanges((fromA, toA, _fromB, _toB, inserted) => {
|
|
124
|
+
am.splice(doc, path, fromA, toA - fromA, inserted.toString());
|
|
125
|
+
});
|
|
256
126
|
}
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
127
|
+
});
|
|
128
|
+
return newHeads ?? void 0;
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
// packages/ui/react-ui-editor/src/extensions/automerge/update-codemirror.ts
|
|
132
|
+
import { ChangeSet } from "@codemirror/state";
|
|
133
|
+
var updateCodeMirror = (view, selection, target, patches) => {
|
|
134
|
+
for (const patch of patches) {
|
|
135
|
+
const changeSpec = handlePatch(patch, target, view.state);
|
|
136
|
+
if (changeSpec != null) {
|
|
137
|
+
const changeSet = ChangeSet.of(changeSpec, view.state.doc.length, "\n");
|
|
138
|
+
selection = selection.map(changeSet, 1);
|
|
139
|
+
view.dispatch({
|
|
140
|
+
changes: changeSet,
|
|
141
|
+
annotations: reconcileAnnotationType.of({})
|
|
142
|
+
});
|
|
270
143
|
}
|
|
271
144
|
}
|
|
145
|
+
view.dispatch({
|
|
146
|
+
selection,
|
|
147
|
+
annotations: reconcileAnnotationType.of({})
|
|
148
|
+
});
|
|
272
149
|
};
|
|
273
|
-
var
|
|
274
|
-
|
|
275
|
-
|
|
150
|
+
var handlePatch = (patch, target, state) => {
|
|
151
|
+
if (patch.action === "insert") {
|
|
152
|
+
return handleInsert(target, patch);
|
|
153
|
+
} else if (patch.action === "splice") {
|
|
154
|
+
return handleSplice(target, patch);
|
|
155
|
+
} else if (patch.action === "del") {
|
|
156
|
+
return handleDel(target, patch);
|
|
157
|
+
} else if (patch.action === "put") {
|
|
158
|
+
return handlePut(target, patch, state);
|
|
159
|
+
} else {
|
|
160
|
+
return null;
|
|
276
161
|
}
|
|
277
162
|
};
|
|
278
|
-
var
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
y: y + 10,
|
|
283
|
-
vx: random(this._options.particleVelocityRange.x[0], this._options.particleVelocityRange.x[1]),
|
|
284
|
-
vy: random(this._options.particleVelocityRange.y[0], this._options.particleVelocityRange.y[1]),
|
|
285
|
-
size: random(this._options.particleSize.min, this._options.particleSize.max),
|
|
286
|
-
color,
|
|
287
|
-
alpha: 1
|
|
288
|
-
};
|
|
289
|
-
}
|
|
290
|
-
update(ctx, particle) {
|
|
291
|
-
particle.vy += this._options.particleGravity;
|
|
292
|
-
particle.x += particle.vx;
|
|
293
|
-
particle.y += particle.vy;
|
|
294
|
-
particle.alpha *= this._options.particleAlphaFadeout;
|
|
295
|
-
ctx.fillStyle = `rgba(${particle.color[0]},${particle.color[1]},${particle.color[2]},${particle.alpha})`;
|
|
296
|
-
ctx.fillRect(Math.round(particle.x - 1), Math.round(particle.y - 1), particle.size, particle.size);
|
|
163
|
+
var handleInsert = (target, patch) => {
|
|
164
|
+
const index = charPath(target, patch.path);
|
|
165
|
+
if (index == null) {
|
|
166
|
+
return [];
|
|
297
167
|
}
|
|
168
|
+
const text = patch.values.map((v) => v ? v.toString() : "").join("");
|
|
169
|
+
return [
|
|
170
|
+
{
|
|
171
|
+
from: index,
|
|
172
|
+
to: index,
|
|
173
|
+
insert: text
|
|
174
|
+
}
|
|
175
|
+
];
|
|
298
176
|
};
|
|
299
|
-
var
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
y: y + 10,
|
|
304
|
-
vx: random(this._options.particleVelocityRange.x[0], this._options.particleVelocityRange.x[1]),
|
|
305
|
-
vy: random(this._options.particleVelocityRange.y[0], this._options.particleVelocityRange.y[1]),
|
|
306
|
-
size: random(this._options.particleSize.min, this._options.particleSize.max),
|
|
307
|
-
color,
|
|
308
|
-
alpha: 1,
|
|
309
|
-
theta: random(0, 360) * Math.PI / 180,
|
|
310
|
-
drag: 0.92,
|
|
311
|
-
wander: 0.15
|
|
312
|
-
};
|
|
313
|
-
}
|
|
314
|
-
update(ctx, particle) {
|
|
315
|
-
particle.vy += this._options.particleGravity;
|
|
316
|
-
particle.x += particle.vx;
|
|
317
|
-
particle.y += particle.vy;
|
|
318
|
-
particle.vx *= particle.drag;
|
|
319
|
-
particle.vy *= particle.drag;
|
|
320
|
-
particle.theta += random(-0.5, 0.5);
|
|
321
|
-
particle.vx += Math.sin(particle.theta) * 0.1;
|
|
322
|
-
particle.vy += Math.cos(particle.theta) * 0.1;
|
|
323
|
-
particle.size *= this._options.particleShrinkRate;
|
|
324
|
-
particle.alpha *= this._options.particleAlphaFadeout;
|
|
325
|
-
ctx.fillStyle = `rgba(${particle.color[0]},${particle.color[1]},${particle.color[2]},${particle.alpha})`;
|
|
326
|
-
ctx.beginPath();
|
|
327
|
-
ctx.arc(Math.round(particle.x - 1), Math.round(particle.y - 1), particle.size, 0, 2 * Math.PI);
|
|
328
|
-
ctx.fill();
|
|
177
|
+
var handleSplice = (target, patch) => {
|
|
178
|
+
const index = charPath(target, patch.path);
|
|
179
|
+
if (index == null) {
|
|
180
|
+
return [];
|
|
329
181
|
}
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
if (!wait) {
|
|
335
|
-
callback.apply(this, args);
|
|
336
|
-
wait = true;
|
|
337
|
-
setTimeout(() => {
|
|
338
|
-
wait = false;
|
|
339
|
-
}, limit);
|
|
182
|
+
return [
|
|
183
|
+
{
|
|
184
|
+
from: index,
|
|
185
|
+
insert: patch.value
|
|
340
186
|
}
|
|
341
|
-
|
|
342
|
-
}
|
|
343
|
-
var
|
|
344
|
-
|
|
345
|
-
|
|
187
|
+
];
|
|
188
|
+
};
|
|
189
|
+
var handleDel = (target, patch) => {
|
|
190
|
+
const index = charPath(target, patch.path);
|
|
191
|
+
if (index == null) {
|
|
192
|
+
return [];
|
|
346
193
|
}
|
|
347
|
-
const
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
194
|
+
const length = patch.length || 1;
|
|
195
|
+
return [
|
|
196
|
+
{
|
|
197
|
+
from: index,
|
|
198
|
+
to: index + length
|
|
352
199
|
}
|
|
200
|
+
];
|
|
201
|
+
};
|
|
202
|
+
var handlePut = (target, patch, state) => {
|
|
203
|
+
const index = charPath(target, [
|
|
204
|
+
...patch.path,
|
|
205
|
+
0
|
|
206
|
+
]);
|
|
207
|
+
if (index == null) {
|
|
208
|
+
return [];
|
|
209
|
+
}
|
|
210
|
+
const length = state.doc.length;
|
|
211
|
+
if (typeof patch.value !== "string") {
|
|
212
|
+
return [];
|
|
353
213
|
}
|
|
354
214
|
return [
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
215
|
+
{
|
|
216
|
+
from: 0,
|
|
217
|
+
to: length,
|
|
218
|
+
insert: patch.value
|
|
219
|
+
}
|
|
358
220
|
];
|
|
359
221
|
};
|
|
360
|
-
var
|
|
361
|
-
if (
|
|
362
|
-
|
|
363
|
-
min = 0;
|
|
222
|
+
var charPath = (textPath, candidatePath) => {
|
|
223
|
+
if (candidatePath.length !== textPath.length + 1) {
|
|
224
|
+
return null;
|
|
364
225
|
}
|
|
365
|
-
|
|
226
|
+
for (let i = 0; i < textPath.length; i++) {
|
|
227
|
+
if (textPath[i] !== candidatePath[i]) {
|
|
228
|
+
return null;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
const index = candidatePath[candidatePath.length - 1];
|
|
232
|
+
if (typeof index === "number") {
|
|
233
|
+
return index;
|
|
234
|
+
}
|
|
235
|
+
return null;
|
|
366
236
|
};
|
|
367
237
|
|
|
368
|
-
// packages/ui/react-ui-editor/src/
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
238
|
+
// packages/ui/react-ui-editor/src/extensions/automerge/semaphore.ts
|
|
239
|
+
var PatchSemaphore = class {
|
|
240
|
+
constructor(_field) {
|
|
241
|
+
this._field = _field;
|
|
242
|
+
this._inReconcile = false;
|
|
243
|
+
this._queue = [];
|
|
244
|
+
this.reconcile = (handle, view) => {
|
|
245
|
+
if (this._inReconcile) {
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
this._inReconcile = true;
|
|
249
|
+
const path = getPath(view.state, this._field);
|
|
250
|
+
const oldHeads = getLastHeads(view.state, this._field);
|
|
251
|
+
let selection = view.state.selection;
|
|
252
|
+
const transactions = view.state.field(this._field).unreconciledTransactions.filter((tx) => !isReconcileTx(tx));
|
|
253
|
+
const toInvert = transactions.slice().reverse();
|
|
254
|
+
for (const tx of toInvert) {
|
|
255
|
+
const inverted = tx.changes.invert(tx.startState.doc);
|
|
256
|
+
selection = selection.map(inverted);
|
|
257
|
+
view.dispatch({
|
|
258
|
+
changes: inverted,
|
|
259
|
+
annotations: reconcileAnnotationType.of(true)
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
let newHeads = updateAutomerge(this._field, handle, transactions, view.state);
|
|
263
|
+
if (newHeads === null || newHeads === void 0) {
|
|
264
|
+
newHeads = automerge2.getHeads(handle.docSync());
|
|
265
|
+
}
|
|
266
|
+
const diff = automerge2.equals(oldHeads, newHeads) ? [] : automerge2.diff(handle.docSync(), oldHeads, newHeads);
|
|
267
|
+
updateCodeMirror(view, selection, path, diff);
|
|
268
|
+
view.dispatch({
|
|
269
|
+
effects: updateHeads(newHeads),
|
|
270
|
+
annotations: reconcileAnnotationType.of({})
|
|
271
|
+
});
|
|
272
|
+
this._inReconcile = false;
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
};
|
|
372
276
|
|
|
373
|
-
// packages/ui/react-ui-editor/src/
|
|
374
|
-
import {
|
|
375
|
-
var
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
"-ml-[10px]"
|
|
379
|
-
],
|
|
380
|
-
2: [
|
|
381
|
-
"mbs-4 mbe-2 font-medium text-inherit no-underline text-3xl",
|
|
382
|
-
"-ml-[8px]"
|
|
383
|
-
],
|
|
384
|
-
3: [
|
|
385
|
-
"mbs-4 mbe-2 font-medium text-inherit no-underline text-2xl",
|
|
386
|
-
"-ml-[7px]"
|
|
387
|
-
],
|
|
388
|
-
4: [
|
|
389
|
-
"mbs-4 mbe-2 font-medium text-inherit no-underline text-xl",
|
|
390
|
-
"-ml-[6px]"
|
|
391
|
-
],
|
|
392
|
-
5: [
|
|
393
|
-
"mbs-4 mbe-2 font-medium text-inherit no-underline text-lg",
|
|
394
|
-
"-ml-[5px]"
|
|
395
|
-
],
|
|
396
|
-
6: [
|
|
397
|
-
"mbs-4 mbe-2 font-medium text-inherit no-underline",
|
|
398
|
-
"-ml-[4px]"
|
|
399
|
-
]
|
|
277
|
+
// packages/ui/react-ui-editor/src/extensions/cursor.ts
|
|
278
|
+
import { Facet } from "@codemirror/state";
|
|
279
|
+
var defaultCursorConverter = {
|
|
280
|
+
toCursor: (position) => position.toString(),
|
|
281
|
+
fromCursor: (cursor) => parseInt(cursor)
|
|
400
282
|
};
|
|
401
|
-
var
|
|
402
|
-
|
|
403
|
-
|
|
283
|
+
var Cursor = class {
|
|
284
|
+
static {
|
|
285
|
+
this.converter = Facet.define({
|
|
286
|
+
combine: (providers) => providers[0] ?? defaultCursorConverter
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
static {
|
|
290
|
+
this.getCursorFromRange = (cursorConverter3, range) => {
|
|
291
|
+
const from = cursorConverter3.toCursor(range.from);
|
|
292
|
+
const to = cursorConverter3.toCursor(range.to, -1);
|
|
293
|
+
return [
|
|
294
|
+
from,
|
|
295
|
+
to
|
|
296
|
+
].join(":");
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
static {
|
|
300
|
+
this.getRangeFromCursor = (cursorConverter3, cursor) => {
|
|
301
|
+
const parts = cursor.split(":");
|
|
302
|
+
const from = cursorConverter3.fromCursor(parts[0]);
|
|
303
|
+
const to = cursorConverter3.fromCursor(parts[1]);
|
|
304
|
+
return from !== void 0 && to !== void 0 ? {
|
|
305
|
+
from,
|
|
306
|
+
to
|
|
307
|
+
} : void 0;
|
|
308
|
+
};
|
|
309
|
+
}
|
|
404
310
|
};
|
|
405
|
-
var light = "text-neutral-200 dark:text-neutral-800";
|
|
406
|
-
var mark = mx("!font-normal !no-underline !text-inherit opacity-40", light);
|
|
407
|
-
var bold = "font-bold";
|
|
408
|
-
var italic = "italic";
|
|
409
|
-
var strikethrough = "line-through";
|
|
410
|
-
var code = "font-mono !no-underline text-neutral-700 dark:text-neutral-300";
|
|
411
|
-
var codeMark = "font-mono text-primary-500";
|
|
412
|
-
var inlineUrl = mx(code, "px-1");
|
|
413
|
-
var blockquote = mx("pl-1 mr-1 border-is-4 border-primary-500/70 dark:border-primary-500/30", light);
|
|
414
|
-
|
|
415
|
-
// packages/ui/react-ui-editor/src/styles/tokens.ts
|
|
416
|
-
import { tailwindConfig } from "@dxos/react-ui-theme";
|
|
417
|
-
var tokens = tailwindConfig({}).theme;
|
|
418
311
|
|
|
419
|
-
// packages/ui/react-ui-editor/src/
|
|
420
|
-
var
|
|
421
|
-
|
|
422
|
-
"& .cm-codeblock": {
|
|
423
|
-
fontFamily: get(tokens, "fontFamily.mono", []).join(",")
|
|
424
|
-
},
|
|
425
|
-
'&light [aria-readonly="true"] .cm-codeblock': {
|
|
426
|
-
background: get(tokens, "extend.colors.neutral.50")
|
|
427
|
-
},
|
|
428
|
-
'&dark [aria-readonly="true"] .cm-codeblock': {
|
|
429
|
-
background: get(tokens, "extend.colors.neutral.850")
|
|
430
|
-
},
|
|
431
|
-
'& [aria-readonly="true"] .cm-codeblock': {
|
|
432
|
-
display: "block",
|
|
433
|
-
paddingInline: "4px !important"
|
|
434
|
-
},
|
|
435
|
-
'& [aria-readonly="true"] .cm-codeblock-first': {
|
|
436
|
-
paddingTop: "4px !important",
|
|
437
|
-
borderTopLeftRadius: "4px",
|
|
438
|
-
borderTopRightRadius: "4px"
|
|
439
|
-
},
|
|
440
|
-
'& [aria-readonly="true"] .cm-codeblock-last': {
|
|
441
|
-
paddingBottom: "4px !important",
|
|
442
|
-
borderBottomLeftRadius: "4px",
|
|
443
|
-
borderBottomRightRadius: "4px"
|
|
444
|
-
}
|
|
312
|
+
// packages/ui/react-ui-editor/src/extensions/automerge/automerge.ts
|
|
313
|
+
var semaphoreFacet = Facet2.define({
|
|
314
|
+
combine: (values) => values.at(-1)
|
|
445
315
|
});
|
|
446
|
-
var
|
|
447
|
-
const
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
const
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
316
|
+
var automerge3 = ({ handle, path }) => {
|
|
317
|
+
const stateField = StateField.define({
|
|
318
|
+
create: () => ({
|
|
319
|
+
lastHeads: A.getHeads(handle.docSync()),
|
|
320
|
+
unreconciledTransactions: [],
|
|
321
|
+
path: path.slice()
|
|
322
|
+
}),
|
|
323
|
+
update: (value, tr) => {
|
|
324
|
+
const result = {
|
|
325
|
+
lastHeads: value.lastHeads,
|
|
326
|
+
unreconciledTransactions: value.unreconciledTransactions.slice(),
|
|
327
|
+
path: path.slice()
|
|
328
|
+
};
|
|
329
|
+
let clearUnreconciled = false;
|
|
330
|
+
for (const effect of tr.effects) {
|
|
331
|
+
if (effect.is(effectType)) {
|
|
332
|
+
result.lastHeads = effect.value.newHeads;
|
|
333
|
+
clearUnreconciled = true;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
if (clearUnreconciled) {
|
|
337
|
+
result.unreconciledTransactions = [];
|
|
338
|
+
} else {
|
|
339
|
+
if (!isReconcileTx(tr)) {
|
|
340
|
+
result.unreconciledTransactions.push(tr);
|
|
468
341
|
}
|
|
469
342
|
}
|
|
343
|
+
return result;
|
|
344
|
+
}
|
|
345
|
+
});
|
|
346
|
+
const semaphore = new PatchSemaphore(stateField);
|
|
347
|
+
const viewPlugin = ViewPlugin.fromClass(class AutomergeCodemirrorViewPlugin {
|
|
348
|
+
constructor(_view) {
|
|
349
|
+
this._view = _view;
|
|
350
|
+
this._handleChange = () => {
|
|
351
|
+
this._view.state.facet(semaphoreFacet).reconcile(handle, this._view);
|
|
352
|
+
};
|
|
353
|
+
handle.addListener("change", this._handleChange);
|
|
354
|
+
}
|
|
355
|
+
update(update2) {
|
|
356
|
+
if (update2.transactions.length > 0 && update2.transactions.some((tr) => !isReconcileTx(tr))) {
|
|
357
|
+
queueMicrotask(() => {
|
|
358
|
+
this._view.state.facet(semaphoreFacet).reconcile(handle, this._view);
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
destroy() {
|
|
363
|
+
handle.addListener("change", this._handleChange);
|
|
470
364
|
}
|
|
471
|
-
|
|
365
|
+
});
|
|
366
|
+
return {
|
|
367
|
+
extension: [
|
|
368
|
+
Cursor.converter.of(cursorConverter(handle, path)),
|
|
369
|
+
semaphoreFacet.of(semaphore),
|
|
370
|
+
stateField,
|
|
371
|
+
viewPlugin
|
|
372
|
+
]
|
|
472
373
|
};
|
|
374
|
+
};
|
|
375
|
+
|
|
376
|
+
// packages/ui/react-ui-editor/src/extensions/awareness.ts
|
|
377
|
+
import { Annotation as Annotation2, Facet as Facet3, RangeSet } from "@codemirror/state";
|
|
378
|
+
import { Decoration, EditorView, ViewPlugin as ViewPlugin2, WidgetType } from "@codemirror/view";
|
|
379
|
+
import { Event } from "@dxos/async";
|
|
380
|
+
import { Context } from "@dxos/context";
|
|
381
|
+
var dummyProvider = {
|
|
382
|
+
remoteStateChange: new Event(),
|
|
383
|
+
open: () => {
|
|
384
|
+
},
|
|
385
|
+
close: () => {
|
|
386
|
+
},
|
|
387
|
+
update: () => {
|
|
388
|
+
},
|
|
389
|
+
getRemoteStates: () => []
|
|
390
|
+
};
|
|
391
|
+
var AwarenessProvider = Facet3.define({
|
|
392
|
+
combine: (providers) => providers[0] ?? dummyProvider
|
|
393
|
+
});
|
|
394
|
+
var RemoteSelectionChangedAnnotation = Annotation2.define();
|
|
395
|
+
var awareness = (provider = dummyProvider) => {
|
|
473
396
|
return [
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
this.decorations = getDecorations(view);
|
|
477
|
-
}
|
|
478
|
-
update(update4) {
|
|
479
|
-
if (update4.docChanged || update4.viewportChanged) {
|
|
480
|
-
this.decorations = getDecorations(update4.view);
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
}, {
|
|
397
|
+
AwarenessProvider.of(provider),
|
|
398
|
+
ViewPlugin2.fromClass(RemoteSelectionsDecorator, {
|
|
484
399
|
decorations: (value) => value.decorations
|
|
485
400
|
}),
|
|
486
401
|
styles
|
|
487
402
|
];
|
|
488
403
|
};
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
return fn(...args);
|
|
505
|
-
} catch (error) {
|
|
506
|
-
log.catch(error, void 0, {
|
|
507
|
-
F: __dxlog_file2,
|
|
508
|
-
L: 16,
|
|
509
|
-
S: void 0,
|
|
510
|
-
C: (f, a) => f(...a)
|
|
404
|
+
var RemoteSelectionsDecorator = class {
|
|
405
|
+
constructor(view) {
|
|
406
|
+
this.decorations = RangeSet.of([]);
|
|
407
|
+
this._ctx = new Context();
|
|
408
|
+
this._lastAnchor = void 0;
|
|
409
|
+
this._lastHead = void 0;
|
|
410
|
+
this._cursorConverter = view.state.facet(Cursor.converter);
|
|
411
|
+
this._provider = view.state.facet(AwarenessProvider);
|
|
412
|
+
this._provider.open();
|
|
413
|
+
this._provider.remoteStateChange.on(this._ctx, () => {
|
|
414
|
+
view.dispatch({
|
|
415
|
+
annotations: [
|
|
416
|
+
RemoteSelectionChangedAnnotation.of([])
|
|
417
|
+
]
|
|
418
|
+
});
|
|
511
419
|
});
|
|
512
420
|
}
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
import { StateField as StateField2 } from "@codemirror/state";
|
|
517
|
-
import get2 from "lodash.get";
|
|
518
|
-
import { useEffect, useState } from "react";
|
|
519
|
-
import { yCollab } from "y-codemirror.next";
|
|
520
|
-
import * as Y from "yjs";
|
|
521
|
-
import { invariant as invariant2 } from "@dxos/invariant";
|
|
522
|
-
import { getRawDoc, isActualAutomergeObject } from "@dxos/react-client/echo";
|
|
523
|
-
import { arrayToString, stringToArray } from "@dxos/util";
|
|
524
|
-
|
|
525
|
-
// packages/ui/react-ui-editor/src/hooks/automerge/plugin.ts
|
|
526
|
-
import { Annotation, Facet, StateEffect, StateField } from "@codemirror/state";
|
|
527
|
-
import { ViewPlugin as ViewPlugin2 } from "@codemirror/view";
|
|
528
|
-
import * as automerge2 from "@dxos/automerge/automerge";
|
|
529
|
-
|
|
530
|
-
// packages/ui/react-ui-editor/src/hooks/automerge/semaphore.ts
|
|
531
|
-
import { next as automerge } from "@dxos/automerge/automerge";
|
|
532
|
-
|
|
533
|
-
// packages/ui/react-ui-editor/src/hooks/automerge/update-automerge.ts
|
|
534
|
-
import { next as am } from "@dxos/automerge/automerge";
|
|
535
|
-
var updateAutomerge = (field, handle, transactions, state) => {
|
|
536
|
-
const { lastHeads, path } = state.field(field);
|
|
537
|
-
let hasChanges = false;
|
|
538
|
-
for (const tr of transactions) {
|
|
539
|
-
tr.changes.iterChanges(() => {
|
|
540
|
-
hasChanges = true;
|
|
541
|
-
});
|
|
421
|
+
destroy() {
|
|
422
|
+
void this._ctx.dispose();
|
|
423
|
+
this._provider.close();
|
|
542
424
|
}
|
|
543
|
-
|
|
544
|
-
|
|
425
|
+
update(update2) {
|
|
426
|
+
this._updateLocalSelection(update2);
|
|
427
|
+
this._updateRemoteSelections(update2);
|
|
545
428
|
}
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
429
|
+
_updateLocalSelection(update2) {
|
|
430
|
+
const hasFocus = update2.view.hasFocus && update2.view.dom.ownerDocument.hasFocus();
|
|
431
|
+
const { anchor = void 0, head = void 0 } = hasFocus ? update2.state.selection.main : {};
|
|
432
|
+
if (this._lastAnchor === anchor && this._lastHead === head) {
|
|
433
|
+
return;
|
|
551
434
|
}
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
const
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
435
|
+
this._lastAnchor = anchor;
|
|
436
|
+
this._lastHead = head;
|
|
437
|
+
this._provider.update(anchor !== void 0 && head !== void 0 ? {
|
|
438
|
+
anchor: this._cursorConverter.toCursor(anchor),
|
|
439
|
+
head: this._cursorConverter.toCursor(head)
|
|
440
|
+
} : void 0);
|
|
441
|
+
}
|
|
442
|
+
_updateRemoteSelections(update2) {
|
|
443
|
+
const decorations = [];
|
|
444
|
+
const awarenessStates = this._provider.getRemoteStates();
|
|
445
|
+
for (const state of awarenessStates) {
|
|
446
|
+
const anchor = state.position?.anchor ? this._cursorConverter.fromCursor(state.position.anchor) : null;
|
|
447
|
+
const head = state.position?.head ? this._cursorConverter.fromCursor(state.position.head) : null;
|
|
448
|
+
if (anchor == null || head == null) {
|
|
449
|
+
continue;
|
|
450
|
+
}
|
|
451
|
+
const start = Math.min(Math.min(anchor, head), update2.view.state.doc.length);
|
|
452
|
+
const end = Math.min(Math.max(anchor, head), update2.view.state.doc.length);
|
|
453
|
+
const startLine = update2.view.state.doc.lineAt(start);
|
|
454
|
+
const endLine = update2.view.state.doc.lineAt(end);
|
|
455
|
+
const color = state.info.color ?? "#30bced";
|
|
456
|
+
const lightColor = state.info.lightColor ?? color + "33";
|
|
457
|
+
if (startLine.number === endLine.number) {
|
|
458
|
+
decorations.push({
|
|
459
|
+
from: start,
|
|
460
|
+
to: end,
|
|
461
|
+
value: Decoration.mark({
|
|
462
|
+
attributes: {
|
|
463
|
+
style: `background-color: ${lightColor}`
|
|
464
|
+
},
|
|
465
|
+
class: "cm-collab-selection"
|
|
466
|
+
})
|
|
467
|
+
});
|
|
468
|
+
} else {
|
|
469
|
+
decorations.push({
|
|
470
|
+
from: start,
|
|
471
|
+
to: startLine.from + startLine.length,
|
|
472
|
+
value: Decoration.mark({
|
|
473
|
+
attributes: {
|
|
474
|
+
style: `background-color: ${color}`
|
|
475
|
+
},
|
|
476
|
+
class: "cm-collab-selection"
|
|
477
|
+
})
|
|
478
|
+
});
|
|
479
|
+
decorations.push({
|
|
480
|
+
from: endLine.from,
|
|
481
|
+
to: end,
|
|
482
|
+
value: Decoration.mark({
|
|
483
|
+
attributes: {
|
|
484
|
+
style: `background-color: ${color}`
|
|
485
|
+
},
|
|
486
|
+
class: "cm-collab-selection"
|
|
487
|
+
})
|
|
488
|
+
});
|
|
489
|
+
for (let i = startLine.number + 1; i < endLine.number; i++) {
|
|
490
|
+
const linePos = update2.view.state.doc.line(i).from;
|
|
491
|
+
decorations.push({
|
|
492
|
+
from: linePos,
|
|
493
|
+
to: linePos,
|
|
494
|
+
value: Decoration.line({
|
|
495
|
+
attributes: {
|
|
496
|
+
style: `background-color: ${color}`,
|
|
497
|
+
class: "cm-collab-selectionLine"
|
|
498
|
+
}
|
|
499
|
+
})
|
|
500
|
+
});
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
decorations.push({
|
|
504
|
+
from: head,
|
|
505
|
+
to: head,
|
|
506
|
+
value: Decoration.widget({
|
|
507
|
+
side: head - anchor > 0 ? -1 : 1,
|
|
508
|
+
block: false,
|
|
509
|
+
widget: new RemoteCaretWidget(state.info.displayName ?? "Anonymous", color)
|
|
510
|
+
})
|
|
567
511
|
});
|
|
568
512
|
}
|
|
513
|
+
this.decorations = Decoration.set(decorations, true);
|
|
569
514
|
}
|
|
570
|
-
view.dispatch({
|
|
571
|
-
selection,
|
|
572
|
-
annotations: reconcileAnnotationType.of({})
|
|
573
|
-
});
|
|
574
515
|
};
|
|
575
|
-
var
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
} else if (patch.action === "del") {
|
|
581
|
-
return handleDel(target, patch);
|
|
582
|
-
} else if (patch.action === "put") {
|
|
583
|
-
return handlePut(target, patch, state);
|
|
584
|
-
} else {
|
|
585
|
-
return null;
|
|
516
|
+
var RemoteCaretWidget = class extends WidgetType {
|
|
517
|
+
constructor(_name, _color) {
|
|
518
|
+
super();
|
|
519
|
+
this._name = _name;
|
|
520
|
+
this._color = _color;
|
|
586
521
|
}
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
522
|
+
toDOM() {
|
|
523
|
+
const span = document.createElement("span");
|
|
524
|
+
span.className = "cm-collab-selectionCaret";
|
|
525
|
+
span.style.backgroundColor = this._color;
|
|
526
|
+
span.style.borderColor = this._color;
|
|
527
|
+
const dot = document.createElement("div");
|
|
528
|
+
dot.className = "cm-collab-selectionCaretDot";
|
|
529
|
+
const info = document.createElement("div");
|
|
530
|
+
info.className = "cm-collab-selectionInfo";
|
|
531
|
+
info.innerText = this._name;
|
|
532
|
+
span.appendChild(document.createTextNode("\u2060"));
|
|
533
|
+
span.appendChild(dot);
|
|
534
|
+
span.appendChild(document.createTextNode("\u2060"));
|
|
535
|
+
span.appendChild(info);
|
|
536
|
+
span.appendChild(document.createTextNode("\u2060"));
|
|
537
|
+
return span;
|
|
592
538
|
}
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
{
|
|
596
|
-
from: index,
|
|
597
|
-
to: index,
|
|
598
|
-
insert: text
|
|
599
|
-
}
|
|
600
|
-
];
|
|
601
|
-
};
|
|
602
|
-
var handleSplice = (target, patch) => {
|
|
603
|
-
const index = charPath(target, patch.path);
|
|
604
|
-
if (index == null) {
|
|
605
|
-
return [];
|
|
539
|
+
updateDOM() {
|
|
540
|
+
return false;
|
|
606
541
|
}
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
from: index,
|
|
610
|
-
insert: patch.value
|
|
611
|
-
}
|
|
612
|
-
];
|
|
613
|
-
};
|
|
614
|
-
var handleDel = (target, patch) => {
|
|
615
|
-
const index = charPath(target, patch.path);
|
|
616
|
-
if (index == null) {
|
|
617
|
-
return [];
|
|
542
|
+
eq(widget) {
|
|
543
|
+
return widget._color === this._color;
|
|
618
544
|
}
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
{
|
|
622
|
-
from: index,
|
|
623
|
-
to: index + length
|
|
624
|
-
}
|
|
625
|
-
];
|
|
626
|
-
};
|
|
627
|
-
var handlePut = (target, patch, state) => {
|
|
628
|
-
const index = charPath(target, [
|
|
629
|
-
...patch.path,
|
|
630
|
-
0
|
|
631
|
-
]);
|
|
632
|
-
if (index == null) {
|
|
633
|
-
return [];
|
|
545
|
+
get estimatedHeight() {
|
|
546
|
+
return -1;
|
|
634
547
|
}
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
return [];
|
|
548
|
+
ignoreEvent() {
|
|
549
|
+
return true;
|
|
638
550
|
}
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
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
|
+
};
|
|
672
|
+
};
|
|
673
|
+
return [
|
|
674
|
+
// Cursor moved.
|
|
675
|
+
EditorView3.updateListener.of((update2) => {
|
|
676
|
+
if (blaster?.node !== update2.view.scrollDOM) {
|
|
677
|
+
if (blaster) {
|
|
678
|
+
blaster.destroy();
|
|
679
|
+
}
|
|
680
|
+
blaster = new Blaster(update2.view.scrollDOM, defaultsDeep({
|
|
681
|
+
particleGravity: 0.2,
|
|
682
|
+
particleShrinkRate: 0.995,
|
|
683
|
+
color: () => [
|
|
684
|
+
100 + Math.random() * 100,
|
|
685
|
+
0,
|
|
686
|
+
0
|
|
687
|
+
]
|
|
688
|
+
}, options, defaultOptions));
|
|
689
|
+
blaster.initialize();
|
|
690
|
+
blaster.start();
|
|
691
|
+
} else {
|
|
692
|
+
blaster.resize();
|
|
693
|
+
}
|
|
694
|
+
const current = update2.state.selection.main.head;
|
|
695
|
+
if (current !== last) {
|
|
696
|
+
last = current;
|
|
697
|
+
const { element, point } = getPoint(update2.view, current - 1);
|
|
698
|
+
if (element && point) {
|
|
699
|
+
blaster.spawn({
|
|
700
|
+
element,
|
|
701
|
+
point
|
|
702
|
+
});
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
}),
|
|
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
|
+
])
|
|
721
|
+
];
|
|
722
|
+
};
|
|
723
|
+
var Blaster = class {
|
|
724
|
+
constructor(_node, _options) {
|
|
725
|
+
this._node = _node;
|
|
726
|
+
this._options = _options;
|
|
727
|
+
this._running = false;
|
|
728
|
+
this._shakeTime = 0;
|
|
729
|
+
this._shakeTimeMax = 0;
|
|
730
|
+
this._particles = [];
|
|
731
|
+
this._particlePointer = 0;
|
|
732
|
+
this._lastPoint = {
|
|
733
|
+
x: 0,
|
|
734
|
+
y: 0
|
|
735
|
+
};
|
|
736
|
+
this.shake = throttle(({ time }) => {
|
|
737
|
+
this._shakeTime = this._shakeTimeMax || time;
|
|
738
|
+
this._shakeTimeMax = time;
|
|
739
|
+
}, 100);
|
|
740
|
+
this.spawn = throttle(({ element, point }) => {
|
|
741
|
+
const color = getRGBComponents(element, this._options.color);
|
|
742
|
+
const numParticles = random(this._options.particleNumRange.min, this._options.particleNumRange.max);
|
|
743
|
+
const dir = this._lastPoint.x === point.x ? 0 : this._lastPoint.x < point.x ? 1 : -1;
|
|
744
|
+
this._lastPoint = point;
|
|
745
|
+
for (let i = numParticles; i--; i > 0) {
|
|
746
|
+
this._particles[this._particlePointer] = this._effect.create(point.x - dir * 16, point.y, color);
|
|
747
|
+
this._particlePointer = (this._particlePointer + 1) % this._options.maxParticles;
|
|
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
|
+
]
|
|
764
|
+
});
|
|
765
|
+
this._canvas = document.createElement("canvas");
|
|
766
|
+
this._canvas.id = "code-blast-canvas";
|
|
767
|
+
this._canvas.style.position = "absolute";
|
|
768
|
+
this._canvas.style.zIndex = "0";
|
|
769
|
+
this._canvas.style.pointerEvents = "none";
|
|
770
|
+
this._ctx = this._canvas.getContext("2d");
|
|
771
|
+
const parent = this._node.parentElement?.parentElement;
|
|
772
|
+
parent?.appendChild(this._canvas);
|
|
773
|
+
this.resize();
|
|
774
|
+
}
|
|
775
|
+
destroy() {
|
|
776
|
+
this.stop();
|
|
777
|
+
if (this._canvas) {
|
|
778
|
+
this._canvas.remove();
|
|
779
|
+
this._canvas = void 0;
|
|
780
|
+
this._ctx = void 0;
|
|
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
|
+
]
|
|
801
|
+
});
|
|
802
|
+
this._running = true;
|
|
803
|
+
this.loop();
|
|
804
|
+
}
|
|
805
|
+
stop() {
|
|
806
|
+
this._running = false;
|
|
807
|
+
this._node.style.transform = "translate(0px, 0px)";
|
|
808
|
+
}
|
|
809
|
+
loop() {
|
|
810
|
+
if (!this._running || !this._canvas || !this._ctx) {
|
|
811
|
+
return;
|
|
812
|
+
}
|
|
813
|
+
this._ctx.clearRect(0, 0, this._canvas.width ?? 0, this._canvas.height ?? 0);
|
|
814
|
+
const now = (/* @__PURE__ */ new Date()).getTime();
|
|
815
|
+
this._lastTime ??= now;
|
|
816
|
+
const dt = (now - this._lastTime) / 1e3;
|
|
817
|
+
this._lastTime = now;
|
|
818
|
+
if (this._shakeTime > 0) {
|
|
819
|
+
this._shakeTime -= dt;
|
|
820
|
+
const magnitude = this._shakeTime / this._shakeTimeMax * this._options.shakeIntensity;
|
|
821
|
+
const shakeX = random(-magnitude, magnitude);
|
|
822
|
+
const shakeY = random(-magnitude, magnitude);
|
|
823
|
+
this._node.style.transform = `translate(${shakeX}px,${shakeY}px)`;
|
|
824
|
+
}
|
|
825
|
+
this.drawParticles();
|
|
826
|
+
requestAnimationFrame(this.loop.bind(this));
|
|
827
|
+
}
|
|
828
|
+
drawParticles() {
|
|
829
|
+
for (let i = this._particles.length; i--; i > 0) {
|
|
830
|
+
const particle = this._particles[i];
|
|
831
|
+
if (!particle) {
|
|
832
|
+
continue;
|
|
833
|
+
}
|
|
834
|
+
if (particle.alpha < 0.01 || particle.size <= 0.5) {
|
|
835
|
+
continue;
|
|
836
|
+
}
|
|
837
|
+
this._effect.update(this._ctx, particle);
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
};
|
|
841
|
+
var Effect = class {
|
|
842
|
+
constructor(_options) {
|
|
843
|
+
this._options = _options;
|
|
844
|
+
}
|
|
845
|
+
};
|
|
846
|
+
var Effect1 = class extends Effect {
|
|
847
|
+
create(x, y, color) {
|
|
848
|
+
return {
|
|
849
|
+
x,
|
|
850
|
+
y: y + 10,
|
|
851
|
+
vx: random(this._options.particleVelocityRange.x[0], this._options.particleVelocityRange.x[1]),
|
|
852
|
+
vy: random(this._options.particleVelocityRange.y[0], this._options.particleVelocityRange.y[1]),
|
|
853
|
+
size: random(this._options.particleSize.min, this._options.particleSize.max),
|
|
854
|
+
color,
|
|
855
|
+
alpha: 1
|
|
856
|
+
};
|
|
857
|
+
}
|
|
858
|
+
update(ctx, particle) {
|
|
859
|
+
particle.vy += this._options.particleGravity;
|
|
860
|
+
particle.x += particle.vx;
|
|
861
|
+
particle.y += particle.vy;
|
|
862
|
+
particle.alpha *= this._options.particleAlphaFadeout;
|
|
863
|
+
ctx.fillStyle = `rgba(${particle.color[0]},${particle.color[1]},${particle.color[2]},${particle.alpha})`;
|
|
864
|
+
ctx.fillRect(Math.round(particle.x - 1), Math.round(particle.y - 1), particle.size, particle.size);
|
|
865
|
+
}
|
|
866
|
+
};
|
|
867
|
+
var Effect2 = class extends Effect {
|
|
868
|
+
create(x, y, color) {
|
|
869
|
+
return {
|
|
870
|
+
x,
|
|
871
|
+
y: y + 10,
|
|
872
|
+
vx: random(this._options.particleVelocityRange.x[0], this._options.particleVelocityRange.x[1]),
|
|
873
|
+
vy: random(this._options.particleVelocityRange.y[0], this._options.particleVelocityRange.y[1]),
|
|
874
|
+
size: random(this._options.particleSize.min, this._options.particleSize.max),
|
|
875
|
+
color,
|
|
876
|
+
alpha: 1,
|
|
877
|
+
theta: random(0, 360) * Math.PI / 180,
|
|
878
|
+
drag: 0.92,
|
|
879
|
+
wander: 0.15
|
|
880
|
+
};
|
|
881
|
+
}
|
|
882
|
+
update(ctx, particle) {
|
|
883
|
+
particle.vy += this._options.particleGravity;
|
|
884
|
+
particle.x += particle.vx;
|
|
885
|
+
particle.y += particle.vy;
|
|
886
|
+
particle.vx *= particle.drag;
|
|
887
|
+
particle.vy *= particle.drag;
|
|
888
|
+
particle.theta += random(-0.5, 0.5);
|
|
889
|
+
particle.vx += Math.sin(particle.theta) * 0.1;
|
|
890
|
+
particle.vy += Math.cos(particle.theta) * 0.1;
|
|
891
|
+
particle.size *= this._options.particleShrinkRate;
|
|
892
|
+
particle.alpha *= this._options.particleAlphaFadeout;
|
|
893
|
+
ctx.fillStyle = `rgba(${particle.color[0]},${particle.color[1]},${particle.color[2]},${particle.alpha})`;
|
|
894
|
+
ctx.beginPath();
|
|
895
|
+
ctx.arc(Math.round(particle.x - 1), Math.round(particle.y - 1), particle.size, 0, 2 * Math.PI);
|
|
896
|
+
ctx.fill();
|
|
897
|
+
}
|
|
898
|
+
};
|
|
899
|
+
function throttle(callback, limit) {
|
|
900
|
+
let wait = false;
|
|
901
|
+
return function(...args) {
|
|
902
|
+
if (!wait) {
|
|
903
|
+
callback.apply(this, args);
|
|
904
|
+
wait = true;
|
|
905
|
+
setTimeout(() => {
|
|
906
|
+
wait = false;
|
|
907
|
+
}, limit);
|
|
644
908
|
}
|
|
645
|
-
|
|
646
|
-
}
|
|
647
|
-
var
|
|
648
|
-
if (
|
|
649
|
-
return
|
|
909
|
+
};
|
|
910
|
+
}
|
|
911
|
+
var getRGBComponents = (node, color) => {
|
|
912
|
+
if (typeof color === "function") {
|
|
913
|
+
return color();
|
|
650
914
|
}
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
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;
|
|
654
920
|
}
|
|
655
921
|
}
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
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
|
{
|
|
@@ -810,239 +975,197 @@ var cursorColors = [
|
|
|
810
975
|
];
|
|
811
976
|
var cursorColor = cursorColors[random2.uint32() % cursorColors.length];
|
|
812
977
|
|
|
813
|
-
// packages/ui/react-ui-editor/src/
|
|
814
|
-
import
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
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
|
-
}
|
|
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);
|
|
1019
|
+
|
|
1020
|
+
// packages/ui/react-ui-editor/src/styles/tokens.ts
|
|
1021
|
+
import get2 from "lodash.get";
|
|
1022
|
+
import { tailwindConfig } from "@dxos/react-ui-theme";
|
|
1023
|
+
var tokens = tailwindConfig({}).theme;
|
|
1024
|
+
var getToken = (path, defaultValue = void 0) => get2(tokens, path, defaultValue);
|
|
912
1025
|
|
|
913
|
-
// packages/ui/react-ui-editor/src/
|
|
914
|
-
var
|
|
915
|
-
var
|
|
916
|
-
|
|
917
|
-
|
|
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: 150,
|
|
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,45 +1264,17 @@ 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:
|
|
1210
|
-
run: createCommentThread
|
|
1276
|
+
key: shortcut,
|
|
1277
|
+
run: callbackWrapper(createCommentThread)
|
|
1211
1278
|
}
|
|
1212
1279
|
]) : [],
|
|
1213
1280
|
//
|
|
@@ -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: 333,
|
|
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,30 +1495,77 @@ 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";
|
|
1507
|
+
import { tooltipContent } from "@dxos/react-ui-theme";
|
|
1426
1508
|
var link = (options = {}) => {
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1509
|
+
const extensions = [
|
|
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
|
|
1521
|
+
})
|
|
1522
|
+
];
|
|
1523
|
+
if (options.onHover) {
|
|
1524
|
+
extensions.push(
|
|
1525
|
+
// https://codemirror.net/examples/tooltip
|
|
1526
|
+
// https://codemirror.net/docs/ref/#view.hoverTooltip
|
|
1527
|
+
// https://github.com/codemirror/view/blob/main/src/tooltip.ts
|
|
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) {
|
|
1536
|
+
return null;
|
|
1537
|
+
}
|
|
1538
|
+
const urlText = view.state.sliceDoc(url.from, url.to);
|
|
1539
|
+
return {
|
|
1540
|
+
pos: link2.from,
|
|
1541
|
+
end: link2.to,
|
|
1542
|
+
above: true,
|
|
1543
|
+
create: () => {
|
|
1544
|
+
const el = document.createElement("div");
|
|
1545
|
+
el.className = tooltipContent({}, "pli-2 plb-1");
|
|
1546
|
+
options.onHover(el, urlText);
|
|
1547
|
+
return {
|
|
1548
|
+
dom: el,
|
|
1549
|
+
offset: {
|
|
1550
|
+
x: 0,
|
|
1551
|
+
y: 4
|
|
1552
|
+
}
|
|
1553
|
+
};
|
|
1554
|
+
}
|
|
1555
|
+
};
|
|
1556
|
+
})
|
|
1557
|
+
);
|
|
1558
|
+
}
|
|
1559
|
+
return extensions;
|
|
1432
1560
|
};
|
|
1433
1561
|
var LinkButton = class extends WidgetType4 {
|
|
1434
|
-
constructor(
|
|
1562
|
+
constructor(_url, _onAttach) {
|
|
1435
1563
|
super();
|
|
1436
|
-
this._pos = _pos;
|
|
1437
1564
|
this._url = _url;
|
|
1438
1565
|
this._onAttach = _onAttach;
|
|
1439
1566
|
}
|
|
1440
1567
|
eq(other) {
|
|
1441
|
-
return this.
|
|
1568
|
+
return this._url === other._url;
|
|
1442
1569
|
}
|
|
1443
1570
|
toDOM(view) {
|
|
1444
1571
|
const el = document.createElement("span");
|
|
@@ -1447,14 +1574,13 @@ var LinkButton = class extends WidgetType4 {
|
|
|
1447
1574
|
}
|
|
1448
1575
|
};
|
|
1449
1576
|
var LinkText = class extends WidgetType4 {
|
|
1450
|
-
constructor(
|
|
1577
|
+
constructor(_text, _url) {
|
|
1451
1578
|
super();
|
|
1452
|
-
this._pos = _pos;
|
|
1453
1579
|
this._text = _text;
|
|
1454
1580
|
this._url = _url;
|
|
1455
1581
|
}
|
|
1456
1582
|
eq(other) {
|
|
1457
|
-
return this.
|
|
1583
|
+
return this._url === other._url;
|
|
1458
1584
|
}
|
|
1459
1585
|
toDOM(view) {
|
|
1460
1586
|
const link2 = document.createElement("a");
|
|
@@ -1468,7 +1594,7 @@ var LinkText = class extends WidgetType4 {
|
|
|
1468
1594
|
link2.onclick = () => {
|
|
1469
1595
|
view.dispatch({
|
|
1470
1596
|
selection: {
|
|
1471
|
-
anchor:
|
|
1597
|
+
anchor: view.posAtDOM(link2)
|
|
1472
1598
|
}
|
|
1473
1599
|
});
|
|
1474
1600
|
};
|
|
@@ -1476,74 +1602,77 @@ var LinkText = class extends WidgetType4 {
|
|
|
1476
1602
|
return link2;
|
|
1477
1603
|
}
|
|
1478
1604
|
};
|
|
1479
|
-
var
|
|
1480
|
-
const builder = new
|
|
1605
|
+
var buildDecorations2 = (view, options) => {
|
|
1606
|
+
const builder = new RangeSetBuilder();
|
|
1607
|
+
const { state } = view;
|
|
1481
1608
|
const cursor = state.selection.main.head;
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
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
|
+
}
|
|
1490
1630
|
return false;
|
|
1491
1631
|
}
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
if (options.onRender) {
|
|
1498
|
-
builder.add(node.to, node.to, Decoration5.replace({
|
|
1499
|
-
widget: new LinkButton(node.from, url, options.onRender)
|
|
1500
|
-
}));
|
|
1501
|
-
}
|
|
1502
|
-
return false;
|
|
1503
|
-
}
|
|
1504
|
-
}
|
|
1505
|
-
});
|
|
1632
|
+
},
|
|
1633
|
+
from,
|
|
1634
|
+
to
|
|
1635
|
+
});
|
|
1636
|
+
}
|
|
1506
1637
|
return builder.finish();
|
|
1507
1638
|
};
|
|
1508
1639
|
|
|
1509
|
-
// packages/ui/react-ui-editor/src/
|
|
1510
|
-
import {
|
|
1511
|
-
var listener = ({ onChange }) => {
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1640
|
+
// packages/ui/react-ui-editor/src/extensions/listener.ts
|
|
1641
|
+
import { EditorView as EditorView8 } from "@codemirror/view";
|
|
1642
|
+
var listener = ({ onFocus, onChange }) => {
|
|
1643
|
+
const extensions = [];
|
|
1644
|
+
onFocus && extensions.push(EditorView8.focusChangeEffect.of((_, focused) => {
|
|
1645
|
+
onFocus(focused);
|
|
1646
|
+
return null;
|
|
1647
|
+
}));
|
|
1648
|
+
onChange && extensions.push(EditorView8.updateListener.of((update2) => {
|
|
1649
|
+
onChange(update2.state.doc.toString());
|
|
1650
|
+
}));
|
|
1651
|
+
return extensions;
|
|
1521
1652
|
};
|
|
1522
1653
|
|
|
1523
|
-
// packages/ui/react-ui-editor/src/
|
|
1654
|
+
// packages/ui/react-ui-editor/src/extensions/markdown/bundle.ts
|
|
1524
1655
|
import { closeBrackets as closeBrackets2, closeBracketsKeymap } from "@codemirror/autocomplete";
|
|
1525
1656
|
import { history, historyKeymap, indentWithTab, standardKeymap } from "@codemirror/commands";
|
|
1526
|
-
import { markdownLanguage as
|
|
1657
|
+
import { markdownLanguage as markdownLanguage3, markdown } from "@codemirror/lang-markdown";
|
|
1527
1658
|
import { bracketMatching as bracketMatching2, defaultHighlightStyle as defaultHighlightStyle2, indentOnInput, syntaxHighlighting as syntaxHighlighting2 } from "@codemirror/language";
|
|
1528
1659
|
import { languages } from "@codemirror/language-data";
|
|
1529
1660
|
import { searchKeymap } from "@codemirror/search";
|
|
1530
1661
|
import { EditorState } from "@codemirror/state";
|
|
1531
1662
|
import { oneDarkHighlightStyle as oneDarkHighlightStyle2 } from "@codemirror/theme-one-dark";
|
|
1532
|
-
import { crosshairCursor, drawSelection as drawSelection2, dropCursor, EditorView as
|
|
1663
|
+
import { crosshairCursor, drawSelection as drawSelection2, dropCursor, EditorView as EditorView9, highlightActiveLine, keymap as keymap4, placeholder as placeholder2 } from "@codemirror/view";
|
|
1533
1664
|
|
|
1534
|
-
// packages/ui/react-ui-editor/src/
|
|
1535
|
-
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";
|
|
1536
1667
|
import { HighlightStyle } from "@codemirror/language";
|
|
1537
1668
|
import { tags, styleTags, Tag } from "@lezer/highlight";
|
|
1538
1669
|
import { Table } from "@lezer/markdown";
|
|
1539
|
-
import get4 from "lodash.get";
|
|
1540
1670
|
var markdownTags = {
|
|
1541
1671
|
Blockquote: Tag.define(),
|
|
1542
1672
|
CodeMark: Tag.define(),
|
|
1543
1673
|
CodeText: Tag.define(),
|
|
1544
1674
|
EmphasisMark: Tag.define(),
|
|
1545
1675
|
HeaderMark: Tag.define(),
|
|
1546
|
-
// HorizontalRule: Tag.define(),
|
|
1547
1676
|
InlineCode: Tag.define(),
|
|
1548
1677
|
LinkLabel: Tag.define(),
|
|
1549
1678
|
LinkReference: Tag.define(),
|
|
@@ -1707,12 +1836,6 @@ var markdownHighlightStyle = (readonly) => {
|
|
|
1707
1836
|
],
|
|
1708
1837
|
class: blockquote
|
|
1709
1838
|
},
|
|
1710
|
-
// TODO(burdon): Replace with extension.
|
|
1711
|
-
// {
|
|
1712
|
-
// tag: [markdownTags.HorizontalRule],
|
|
1713
|
-
// class: mx(horizontalRule, readonly && '-indent-[100rem]'),
|
|
1714
|
-
// },
|
|
1715
|
-
// TODO(burdon): Only if being edited.
|
|
1716
1839
|
{
|
|
1717
1840
|
tag: [
|
|
1718
1841
|
markdownTags.TableCell
|
|
@@ -1720,19 +1843,19 @@ var markdownHighlightStyle = (readonly) => {
|
|
|
1720
1843
|
class: "font-mono"
|
|
1721
1844
|
}
|
|
1722
1845
|
], {
|
|
1723
|
-
scope:
|
|
1846
|
+
scope: markdownLanguage2,
|
|
1724
1847
|
all: {
|
|
1725
|
-
fontFamily:
|
|
1848
|
+
fontFamily: getToken("fontFamily.body", []).join(",")
|
|
1726
1849
|
}
|
|
1727
1850
|
});
|
|
1728
1851
|
};
|
|
1729
1852
|
|
|
1730
|
-
// packages/ui/react-ui-editor/src/
|
|
1853
|
+
// packages/ui/react-ui-editor/src/extensions/markdown/bundle.ts
|
|
1731
1854
|
var markdownBundle = ({ readonly, themeMode, placeholder: _placeholder }) => {
|
|
1732
1855
|
return [
|
|
1733
1856
|
EditorState.allowMultipleSelections.of(true),
|
|
1734
1857
|
EditorState.tabSize.of(2),
|
|
1735
|
-
|
|
1858
|
+
EditorView9.lineWrapping,
|
|
1736
1859
|
customKeymap(),
|
|
1737
1860
|
bracketMatching2(),
|
|
1738
1861
|
closeBrackets2(),
|
|
@@ -1752,7 +1875,7 @@ var markdownBundle = ({ readonly, themeMode, placeholder: _placeholder }) => {
|
|
|
1752
1875
|
// NOTE: This extends the parser; it doesn't affect rendering.
|
|
1753
1876
|
// https://github.github.com/gfm
|
|
1754
1877
|
// https://github.com/lezer-parser/markdown?tab=readme-ov-file#github-flavored-markdown
|
|
1755
|
-
base:
|
|
1878
|
+
base: markdownLanguage3,
|
|
1756
1879
|
// Languages for syntax highlighting fenced code blocks.
|
|
1757
1880
|
codeLanguages: languages,
|
|
1758
1881
|
// Parser extensions.
|
|
@@ -1780,7 +1903,7 @@ var customKeymap = () => keymap4.of([
|
|
|
1780
1903
|
...searchKeymap
|
|
1781
1904
|
]);
|
|
1782
1905
|
|
|
1783
|
-
// packages/ui/react-ui-editor/src/
|
|
1906
|
+
// packages/ui/react-ui-editor/src/extensions/mention.ts
|
|
1784
1907
|
import { autocompletion as autocompletion2 } from "@codemirror/autocomplete";
|
|
1785
1908
|
var mention = ({ onSearch }) => {
|
|
1786
1909
|
return autocompletion2({
|
|
@@ -1803,24 +1926,19 @@ var mention = ({ onSearch }) => {
|
|
|
1803
1926
|
});
|
|
1804
1927
|
};
|
|
1805
1928
|
|
|
1806
|
-
// packages/ui/react-ui-editor/src/
|
|
1807
|
-
var mermaid = () => {
|
|
1808
|
-
return [];
|
|
1809
|
-
};
|
|
1810
|
-
|
|
1811
|
-
// packages/ui/react-ui-editor/src/components/TextEditor/extensions/table.ts
|
|
1929
|
+
// packages/ui/react-ui-editor/src/extensions/table.ts
|
|
1812
1930
|
import { syntaxTree as syntaxTree3 } from "@codemirror/language";
|
|
1813
|
-
import { RangeSetBuilder as
|
|
1814
|
-
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";
|
|
1815
1933
|
var table = (options = {}) => {
|
|
1816
|
-
return
|
|
1817
|
-
create: (state) =>
|
|
1818
|
-
update: (_, tr) =>
|
|
1819
|
-
provide: (field) =>
|
|
1934
|
+
return StateField4.define({
|
|
1935
|
+
create: (state) => update(state, options),
|
|
1936
|
+
update: (_, tr) => update(tr.state, options),
|
|
1937
|
+
provide: (field) => EditorView10.decorations.from(field)
|
|
1820
1938
|
});
|
|
1821
1939
|
};
|
|
1822
|
-
var
|
|
1823
|
-
const builder = new
|
|
1940
|
+
var update = (state, options) => {
|
|
1941
|
+
const builder = new RangeSetBuilder2();
|
|
1824
1942
|
const cursor = state.selection.main.head;
|
|
1825
1943
|
const tables = [];
|
|
1826
1944
|
const getTable = () => tables[tables.length - 1];
|
|
@@ -1860,11 +1978,10 @@ var update3 = (state, options) => {
|
|
|
1860
1978
|
});
|
|
1861
1979
|
tables.forEach((table2) => {
|
|
1862
1980
|
const hide = state.readOnly || cursor < table2.from || cursor > table2.to;
|
|
1863
|
-
hide && builder.add(table2.from, table2.to,
|
|
1864
|
-
block: true,
|
|
1981
|
+
hide && builder.add(table2.from, table2.to, Decoration7.replace({
|
|
1865
1982
|
widget: new TableWidget(table2)
|
|
1866
1983
|
}));
|
|
1867
|
-
builder.add(table2.from, table2.to,
|
|
1984
|
+
builder.add(table2.from, table2.to, Decoration7.mark({
|
|
1868
1985
|
class: "cm-table"
|
|
1869
1986
|
}));
|
|
1870
1987
|
});
|
|
@@ -1876,7 +1993,7 @@ var TableWidget = class extends WidgetType5 {
|
|
|
1876
1993
|
this._table = _table;
|
|
1877
1994
|
}
|
|
1878
1995
|
eq(other) {
|
|
1879
|
-
return this._table.
|
|
1996
|
+
return this._table.header?.join() === other._table.header?.join() && this._table.rows?.join() === other._table.rows?.join();
|
|
1880
1997
|
}
|
|
1881
1998
|
toDOM(view) {
|
|
1882
1999
|
const table2 = document.createElement("table");
|
|
@@ -1902,26 +2019,28 @@ var TableWidget = class extends WidgetType5 {
|
|
|
1902
2019
|
}
|
|
1903
2020
|
return table2;
|
|
1904
2021
|
}
|
|
2022
|
+
ignoreEvent(e) {
|
|
2023
|
+
return !/^mouse/.test(e.type);
|
|
2024
|
+
}
|
|
1905
2025
|
};
|
|
1906
2026
|
|
|
1907
|
-
// packages/ui/react-ui-editor/src/
|
|
1908
|
-
import { EditorView as
|
|
1909
|
-
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({
|
|
1910
2030
|
"& .cm-task-item": {
|
|
1911
2031
|
paddingLeft: "4px",
|
|
1912
2032
|
paddingRight: "8px"
|
|
1913
2033
|
}
|
|
1914
2034
|
});
|
|
1915
2035
|
var CheckboxWidget = class extends WidgetType6 {
|
|
1916
|
-
constructor(
|
|
2036
|
+
constructor(_checked, _indent, _onCheck) {
|
|
1917
2037
|
super();
|
|
1918
|
-
this._pos = _pos;
|
|
1919
2038
|
this._checked = _checked;
|
|
1920
2039
|
this._indent = _indent;
|
|
1921
2040
|
this._onCheck = _onCheck;
|
|
1922
2041
|
}
|
|
1923
2042
|
eq(other) {
|
|
1924
|
-
return this.
|
|
2043
|
+
return this._checked === other._checked && this._indent === other._indent;
|
|
1925
2044
|
}
|
|
1926
2045
|
toDOM(view) {
|
|
1927
2046
|
const wrap = document.createElement("span");
|
|
@@ -1947,13 +2066,13 @@ var CheckboxWidget = class extends WidgetType6 {
|
|
|
1947
2066
|
}
|
|
1948
2067
|
};
|
|
1949
2068
|
var tasklist = (options = {}) => {
|
|
1950
|
-
const taskMatcher = new
|
|
2069
|
+
const taskMatcher = new MatchDecorator2({
|
|
1951
2070
|
regexp: /^(\s*)- \[([ xX])\]\s/g,
|
|
1952
2071
|
decoration: (match, view, pos) => {
|
|
1953
2072
|
const indent = Math.floor(match[1].length / 2);
|
|
1954
2073
|
const checked = match[2] === "x" || match[2] === "X";
|
|
1955
|
-
return
|
|
1956
|
-
widget: new CheckboxWidget(
|
|
2074
|
+
return Decoration8.replace({
|
|
2075
|
+
widget: new CheckboxWidget(checked, indent, view.state.readOnly ? void 0 : (checked2) => {
|
|
1957
2076
|
const idx = pos + match[0].indexOf("[") + 1;
|
|
1958
2077
|
view.dispatch({
|
|
1959
2078
|
changes: {
|
|
@@ -1970,70 +2089,26 @@ var tasklist = (options = {}) => {
|
|
|
1970
2089
|
});
|
|
1971
2090
|
}
|
|
1972
2091
|
});
|
|
1973
|
-
const tasks =
|
|
2092
|
+
const tasks = ViewPlugin6.fromClass(class {
|
|
1974
2093
|
constructor(view) {
|
|
1975
2094
|
this.tasks = taskMatcher.createDeco(view);
|
|
1976
2095
|
}
|
|
1977
|
-
update(
|
|
1978
|
-
this.tasks = taskMatcher.updateDeco(
|
|
2096
|
+
update(update2) {
|
|
2097
|
+
this.tasks = taskMatcher.updateDeco(update2, this.tasks);
|
|
1979
2098
|
}
|
|
1980
2099
|
}, {
|
|
1981
2100
|
decorations: (value) => value.tasks,
|
|
1982
|
-
provide: (plugin) =>
|
|
1983
|
-
return view.plugin(plugin)?.tasks ||
|
|
2101
|
+
provide: (plugin) => EditorView11.atomicRanges.of((view) => {
|
|
2102
|
+
return view.plugin(plugin)?.tasks || Decoration8.none;
|
|
1984
2103
|
})
|
|
1985
2104
|
});
|
|
1986
2105
|
return [
|
|
1987
2106
|
tasks,
|
|
1988
|
-
|
|
2107
|
+
styles5
|
|
1989
2108
|
];
|
|
1990
2109
|
};
|
|
1991
2110
|
|
|
1992
|
-
// packages/ui/react-ui-editor/src/
|
|
1993
|
-
import { hoverTooltip as hoverTooltip2 } from "@codemirror/view";
|
|
1994
|
-
import { tooltipContent } from "@dxos/react-ui-theme";
|
|
1995
|
-
var markdownLinkRegexp = /\[([^\]]+)]\(([^)]+)\)/;
|
|
1996
|
-
var tooltip = ({ onHover, regexp = markdownLinkRegexp }) => hoverTooltip2((view, pos) => {
|
|
1997
|
-
const { from, text } = view.state.doc.lineAt(pos);
|
|
1998
|
-
const p = pos - from;
|
|
1999
|
-
let idx = 0;
|
|
2000
|
-
let match;
|
|
2001
|
-
do {
|
|
2002
|
-
match = text.substring(idx).match(regexp);
|
|
2003
|
-
if (!match) {
|
|
2004
|
-
match = void 0;
|
|
2005
|
-
break;
|
|
2006
|
-
}
|
|
2007
|
-
idx = text.indexOf(match[0]);
|
|
2008
|
-
if (p >= idx && p < idx + match[0].length) {
|
|
2009
|
-
break;
|
|
2010
|
-
}
|
|
2011
|
-
idx += match[0].length;
|
|
2012
|
-
} while (true);
|
|
2013
|
-
if (!match) {
|
|
2014
|
-
return null;
|
|
2015
|
-
}
|
|
2016
|
-
const [, , url] = match ?? [];
|
|
2017
|
-
return {
|
|
2018
|
-
pos: idx + from,
|
|
2019
|
-
end: idx + from + match[0].length,
|
|
2020
|
-
above: true,
|
|
2021
|
-
create: () => {
|
|
2022
|
-
const el = document.createElement("div");
|
|
2023
|
-
el.className = tooltipContent({}, "pli-2 plb-1");
|
|
2024
|
-
onHover(el, url);
|
|
2025
|
-
return {
|
|
2026
|
-
dom: el,
|
|
2027
|
-
offset: {
|
|
2028
|
-
x: 0,
|
|
2029
|
-
y: 4
|
|
2030
|
-
}
|
|
2031
|
-
};
|
|
2032
|
-
}
|
|
2033
|
-
};
|
|
2034
|
-
});
|
|
2035
|
-
|
|
2036
|
-
// packages/ui/react-ui-editor/src/components/TextEditor/extensions/typewriter.ts
|
|
2111
|
+
// packages/ui/react-ui-editor/src/extensions/typewriter.ts
|
|
2037
2112
|
import { keymap as keymap5 } from "@codemirror/view";
|
|
2038
2113
|
var defaultItems = [
|
|
2039
2114
|
"hello world!",
|
|
@@ -2090,8 +2165,29 @@ var typewriter = ({ delay = 75, items = defaultItems } = {}) => {
|
|
|
2090
2165
|
];
|
|
2091
2166
|
};
|
|
2092
2167
|
|
|
2093
|
-
// packages/ui/react-ui-editor/src/
|
|
2094
|
-
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";
|
|
2095
2191
|
var defaultTheme = {
|
|
2096
2192
|
//
|
|
2097
2193
|
// Main layout:
|
|
@@ -2120,21 +2216,21 @@ var defaultTheme = {
|
|
|
2120
2216
|
"&.cm-focused": {
|
|
2121
2217
|
outline: "none"
|
|
2122
2218
|
},
|
|
2123
|
-
"
|
|
2219
|
+
".cm-scroller": {
|
|
2124
2220
|
overflow: "visible",
|
|
2125
|
-
fontFamily:
|
|
2221
|
+
fontFamily: get3(tokens, "fontFamily.mono", []).join(",")
|
|
2126
2222
|
},
|
|
2127
|
-
"
|
|
2223
|
+
".cm-content": {
|
|
2128
2224
|
padding: 0,
|
|
2129
2225
|
// NOTE: Base font size (otherwise defined by HTML tag, which might be different for storybook).
|
|
2130
2226
|
fontSize: "16px"
|
|
2131
2227
|
},
|
|
2132
2228
|
"&light .cm-content": {
|
|
2133
|
-
color:
|
|
2229
|
+
color: get3(tokens, "extend.colors.neutral.900", "black"),
|
|
2134
2230
|
caretColor: "black"
|
|
2135
2231
|
},
|
|
2136
2232
|
"&dark .cm-content": {
|
|
2137
|
-
color:
|
|
2233
|
+
color: get3(tokens, "extend.colors.neutral.100", "white"),
|
|
2138
2234
|
caretColor: "white"
|
|
2139
2235
|
},
|
|
2140
2236
|
//
|
|
@@ -2146,158 +2242,120 @@ var defaultTheme = {
|
|
|
2146
2242
|
"&dark .cm-cursor, &dark .cm-dropCursor": {
|
|
2147
2243
|
borderLeft: "2px solid white"
|
|
2148
2244
|
},
|
|
2149
|
-
"
|
|
2245
|
+
".cm-placeholder": {
|
|
2150
2246
|
fontWeight: 100
|
|
2151
2247
|
},
|
|
2152
2248
|
//
|
|
2153
2249
|
// line
|
|
2154
2250
|
//
|
|
2155
|
-
"
|
|
2251
|
+
".cm-line": {
|
|
2156
2252
|
paddingInline: 0
|
|
2157
2253
|
},
|
|
2158
|
-
"
|
|
2254
|
+
".cm-activeLine": {
|
|
2159
2255
|
background: "inherit"
|
|
2160
2256
|
},
|
|
2161
2257
|
//
|
|
2162
2258
|
// Selection
|
|
2163
2259
|
//
|
|
2164
2260
|
"&light .cm-selectionBackground": {
|
|
2165
|
-
background:
|
|
2261
|
+
background: get3(tokens, "extend.colors.primary.100")
|
|
2166
2262
|
},
|
|
2167
2263
|
"&light.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground": {
|
|
2168
|
-
background:
|
|
2264
|
+
background: get3(tokens, "extend.colors.primary.200")
|
|
2169
2265
|
},
|
|
2170
2266
|
"&dark .cm-selectionBackground": {
|
|
2171
|
-
background:
|
|
2267
|
+
background: get3(tokens, "extend.colors.primary.700")
|
|
2172
2268
|
},
|
|
2173
2269
|
"&dark.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground": {
|
|
2174
|
-
background:
|
|
2270
|
+
background: get3(tokens, "extend.colors.primary.600")
|
|
2175
2271
|
},
|
|
2176
2272
|
//
|
|
2177
2273
|
// Search
|
|
2178
2274
|
//
|
|
2179
2275
|
"&light .cm-searchMatch": {
|
|
2180
|
-
backgroundColor:
|
|
2276
|
+
backgroundColor: get3(tokens, "extend.colors.yellow.100")
|
|
2181
2277
|
},
|
|
2182
2278
|
"&dark .cm-searchMatch": {
|
|
2183
|
-
backgroundColor:
|
|
2184
|
-
},
|
|
2185
|
-
//
|
|
2186
|
-
// collaboration
|
|
2187
|
-
// TODO(burdon): Review classnames (YJS dependent?) Note: e2e tests depend on this class.
|
|
2188
|
-
//
|
|
2189
|
-
"&light .cm-ySelection, &light .cm-yLineSelection": {
|
|
2190
|
-
mixBlendMode: "multiply"
|
|
2191
|
-
},
|
|
2192
|
-
"&dark .cm-ySelection, &dark .cm-yLineSelection": {
|
|
2193
|
-
mixBlendMode: "screen"
|
|
2194
|
-
},
|
|
2195
|
-
"& .cm-ySelectionInfo": {
|
|
2196
|
-
padding: "2px 4px",
|
|
2197
|
-
marginBlockStart: "-4px"
|
|
2198
|
-
},
|
|
2199
|
-
"& .cm-ySelection, & .cm-selectionMatch": {
|
|
2200
|
-
paddingBlockStart: ".15em",
|
|
2201
|
-
paddingBlockEnd: ".15em"
|
|
2202
|
-
},
|
|
2203
|
-
"& .cm-ySelectionCaret": {
|
|
2204
|
-
display: "inline-block",
|
|
2205
|
-
insetBlockStart: ".1em",
|
|
2206
|
-
blockSize: "1.4em",
|
|
2207
|
-
verticalAlign: "top"
|
|
2208
|
-
},
|
|
2209
|
-
"& .cm-yLineSelection": {
|
|
2210
|
-
margin: 0
|
|
2279
|
+
backgroundColor: get3(tokens, "extend.colors.yellow.700")
|
|
2211
2280
|
},
|
|
2212
2281
|
//
|
|
2213
2282
|
// link
|
|
2214
2283
|
//
|
|
2215
|
-
"
|
|
2216
|
-
color:
|
|
2284
|
+
".cm-link": {
|
|
2285
|
+
color: get3(tokens, "extend.colors.primary.500"),
|
|
2217
2286
|
textDecorationLine: "underline",
|
|
2218
2287
|
textDecorationThickness: "1px",
|
|
2219
2288
|
textUnderlineOffset: "2px",
|
|
2220
2289
|
borderRadius: ".125rem",
|
|
2221
|
-
fontFamily:
|
|
2290
|
+
fontFamily: get3(tokens, "fontFamily.body", []).join(",")
|
|
2222
2291
|
},
|
|
2223
2292
|
//
|
|
2224
2293
|
// tooltip
|
|
2225
2294
|
//
|
|
2226
|
-
"
|
|
2295
|
+
".cm-tooltip": {
|
|
2227
2296
|
border: "none"
|
|
2228
2297
|
},
|
|
2229
|
-
"
|
|
2298
|
+
".cm-tooltip-below": {},
|
|
2230
2299
|
//
|
|
2231
2300
|
// autocomplete
|
|
2232
2301
|
//
|
|
2233
|
-
"
|
|
2302
|
+
".cm-tooltip-autocomplete": {
|
|
2234
2303
|
marginTop: "4px",
|
|
2235
2304
|
marginLeft: "-3px"
|
|
2236
2305
|
},
|
|
2237
|
-
"
|
|
2238
|
-
"
|
|
2239
|
-
"
|
|
2306
|
+
".cm-tooltip-autocomplete ul li": {},
|
|
2307
|
+
".cm-tooltip-autocomplete ul li[aria-selected]": {},
|
|
2308
|
+
".cm-completionIcon": {
|
|
2240
2309
|
display: "none"
|
|
2241
2310
|
},
|
|
2242
|
-
"
|
|
2243
|
-
fontFamily:
|
|
2311
|
+
".cm-completionLabel": {
|
|
2312
|
+
fontFamily: get3(tokens, "fontFamily.body", []).join(",")
|
|
2244
2313
|
},
|
|
2245
|
-
"
|
|
2314
|
+
".cm-completionMatchedText": {
|
|
2246
2315
|
textDecoration: "none"
|
|
2247
2316
|
},
|
|
2248
2317
|
//
|
|
2249
|
-
// widgets
|
|
2250
|
-
//
|
|
2251
|
-
"& .cm-widgetBuffer": {
|
|
2252
|
-
display: "none",
|
|
2253
|
-
height: 0
|
|
2254
|
-
},
|
|
2255
|
-
//
|
|
2256
2318
|
// table
|
|
2257
2319
|
//
|
|
2258
|
-
"
|
|
2259
|
-
fontFamily: `${
|
|
2320
|
+
".cm-table *": {
|
|
2321
|
+
fontFamily: `${get3(tokens, "fontFamily.mono", []).join(",")} !important`,
|
|
2260
2322
|
textDecoration: "none !important"
|
|
2261
2323
|
},
|
|
2262
|
-
"
|
|
2324
|
+
".cm-table-head": {
|
|
2263
2325
|
padding: "2px 16px 2px 0px",
|
|
2264
|
-
borderBottom: `1px solid ${
|
|
2326
|
+
borderBottom: `1px solid ${get3(tokens, "extend.colors.neutral.500")}`,
|
|
2265
2327
|
fontWeight: 100,
|
|
2266
2328
|
textAlign: "left",
|
|
2267
|
-
color:
|
|
2329
|
+
color: get3(tokens, "extend.colors.neutral.500")
|
|
2268
2330
|
},
|
|
2269
|
-
"
|
|
2331
|
+
".cm-table-cell": {
|
|
2270
2332
|
padding: "2px 16px 2px 0px"
|
|
2271
2333
|
},
|
|
2272
2334
|
//
|
|
2273
2335
|
// image
|
|
2274
2336
|
//
|
|
2275
|
-
"
|
|
2276
|
-
|
|
2337
|
+
".cm-image": {
|
|
2338
|
+
display: "block",
|
|
2339
|
+
height: "0"
|
|
2340
|
+
},
|
|
2341
|
+
".cm-image.cm-loaded-image": {
|
|
2342
|
+
height: "auto",
|
|
2343
|
+
borderTop: "0.5rem solid transparent",
|
|
2344
|
+
borderBottom: "0.5rem solid transparent"
|
|
2277
2345
|
},
|
|
2278
2346
|
//
|
|
2279
2347
|
// font size
|
|
2280
|
-
// TODO(thure): This appears to be the best or only way to set selection caret heights,
|
|
2348
|
+
// TODO(thure): This appears to be the best or only way to set selection caret heights,
|
|
2349
|
+
// but it's far more verbose than it needs to be.
|
|
2281
2350
|
//
|
|
2282
|
-
...Object.keys(
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
acc[`& .text-${fontSize} + .cm-ySelectionCaret`] = {
|
|
2291
|
-
height
|
|
2292
|
-
};
|
|
2293
|
-
acc[`& .text-${fontSize} + .cm-ySelection + .cm-ySelectionCaret`] = {
|
|
2294
|
-
height
|
|
2295
|
-
};
|
|
2296
|
-
acc[`& .text-${fontSize} + .cm-widgetBuffer + .cm-ySelectionCaret`] = {
|
|
2297
|
-
height
|
|
2298
|
-
};
|
|
2299
|
-
return acc;
|
|
2300
|
-
}, {}),
|
|
2351
|
+
// ...Object.keys(get(tokens, 'extend.fontSize', {})).reduce((acc: Record<string, any>, fontSize) => {
|
|
2352
|
+
// const height = get(tokens, ['extend', 'fontSize', fontSize, 1, 'lineHeight']);
|
|
2353
|
+
//
|
|
2354
|
+
// acc[`& .text-${fontSize} + .cm-ySelectionCaret`] = { height };
|
|
2355
|
+
// acc[`& .text-${fontSize} + .cm-ySelection + .cm-ySelectionCaret`] = { height };
|
|
2356
|
+
// acc[`& .text-${fontSize} + .cm-widgetBuffer + .cm-ySelectionCaret`] = { height };
|
|
2357
|
+
// return acc;
|
|
2358
|
+
// }, {}),
|
|
2301
2359
|
/**
|
|
2302
2360
|
* Panels
|
|
2303
2361
|
* TODO(burdon): Needs styling attention (esp. dark mode).
|
|
@@ -2314,88 +2372,83 @@ var defaultTheme = {
|
|
|
2314
2372
|
* </div>
|
|
2315
2373
|
* </div
|
|
2316
2374
|
*/
|
|
2317
|
-
"
|
|
2318
|
-
border: `1px solid ${
|
|
2375
|
+
".cm-panels": {
|
|
2376
|
+
border: `1px solid ${get3(tokens, "extend.colors.neutral.200")}`
|
|
2319
2377
|
},
|
|
2320
|
-
"
|
|
2321
|
-
background:
|
|
2322
|
-
fontFamily:
|
|
2378
|
+
".cm-panel": {
|
|
2379
|
+
background: get3(tokens, "extend.colors.neutral.50"),
|
|
2380
|
+
fontFamily: get3(tokens, "fontFamily.body", []).join(",")
|
|
2323
2381
|
},
|
|
2324
|
-
"
|
|
2382
|
+
".cm-button": {
|
|
2325
2383
|
margin: "4px",
|
|
2326
|
-
fontFamily:
|
|
2327
|
-
background:
|
|
2384
|
+
fontFamily: get3(tokens, "fontFamily.body", []).join(","),
|
|
2385
|
+
background: get3(tokens, "extend.colors.neutral.100"),
|
|
2328
2386
|
backgroundImage: "none",
|
|
2329
2387
|
border: "none",
|
|
2330
2388
|
"&:hover": {
|
|
2331
|
-
background:
|
|
2389
|
+
background: get3(tokens, "extend.colors.neutral.200")
|
|
2332
2390
|
},
|
|
2333
2391
|
"&:active": {
|
|
2334
|
-
background:
|
|
2392
|
+
background: get3(tokens, "extend.colors.neutral.300"),
|
|
2335
2393
|
backgroundImage: "none"
|
|
2336
2394
|
}
|
|
2337
2395
|
},
|
|
2338
|
-
"
|
|
2396
|
+
".cm-panel input[type=checkbox]": {
|
|
2339
2397
|
marginRight: "0.4rem !important"
|
|
2340
2398
|
}
|
|
2341
2399
|
};
|
|
2342
2400
|
var textTheme = {
|
|
2343
|
-
"
|
|
2344
|
-
fontFamily:
|
|
2401
|
+
".cm-scroller": {
|
|
2402
|
+
fontFamily: get3(tokens, "fontFamily.body", []).join(",")
|
|
2345
2403
|
},
|
|
2346
|
-
"
|
|
2347
|
-
fontFamily:
|
|
2404
|
+
".cm-placeholder": {
|
|
2405
|
+
fontFamily: get3(tokens, "fontFamily.body", []).join(",")
|
|
2348
2406
|
}
|
|
2349
2407
|
};
|
|
2350
2408
|
var markdownTheme = {
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2409
|
+
".cm-scroller": {
|
|
2410
|
+
fontFamily: get3(tokens, "fontFamily.body", []).join(",")
|
|
2411
|
+
},
|
|
2412
|
+
".cm-placeholder": {
|
|
2413
|
+
fontFamily: get3(tokens, "fontFamily.body", []).join(",")
|
|
2354
2414
|
}
|
|
2355
2415
|
};
|
|
2356
2416
|
var codeTheme = {
|
|
2357
|
-
"
|
|
2358
|
-
fontFamily:
|
|
2417
|
+
".cm-scroller": {
|
|
2418
|
+
fontFamily: get3(tokens, "fontFamily.mono", []).join(",")
|
|
2359
2419
|
},
|
|
2360
|
-
"
|
|
2361
|
-
fontFamily:
|
|
2420
|
+
".cm-placeholder": {
|
|
2421
|
+
fontFamily: get3(tokens, "fontFamily.mono", []).join(",")
|
|
2362
2422
|
}
|
|
2363
2423
|
};
|
|
2364
2424
|
|
|
2365
2425
|
// packages/ui/react-ui-editor/src/components/TextEditor/TextEditor.tsx
|
|
2366
|
-
import { EditorState as EditorState2 } from "@codemirror/state";
|
|
2367
|
-
import { EditorView as EditorView11 } from "@codemirror/view";
|
|
2368
|
-
import { useFocusableGroup } from "@fluentui/react-tabster";
|
|
2369
|
-
import { vim } from "@replit/codemirror-vim";
|
|
2370
|
-
import defaultsDeep2 from "lodash.defaultsdeep";
|
|
2371
|
-
import React, { forwardRef, useCallback, useEffect as useEffect2, useImperativeHandle, useState as useState2 } from "react";
|
|
2372
|
-
import { generateName } from "@dxos/display-name";
|
|
2373
|
-
import { useThemeContext } from "@dxos/react-ui";
|
|
2374
|
-
import { getColorForValue, inputSurface, mx as mx3 } from "@dxos/react-ui-theme";
|
|
2375
2426
|
var EditorModes = [
|
|
2376
2427
|
"default",
|
|
2377
2428
|
"vim"
|
|
2378
2429
|
];
|
|
2379
|
-
var BaseTextEditor = /* @__PURE__ */ forwardRef(({ model,
|
|
2380
|
-
const { themeMode } = useThemeContext();
|
|
2430
|
+
var BaseTextEditor = /* @__PURE__ */ forwardRef(({ model, focus, selection, readonly, comments: comments2, extensions = [], editorMode, theme, slots = defaultSlots }, forwardedRef) => {
|
|
2381
2431
|
const tabsterDOMAttribute = useFocusableGroup({
|
|
2382
2432
|
tabBehavior: "limited"
|
|
2383
2433
|
});
|
|
2384
|
-
const
|
|
2385
|
-
const
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
state,
|
|
2434
|
+
const { themeMode } = useThemeContext();
|
|
2435
|
+
const rootRef = useRef(null);
|
|
2436
|
+
const [view, setView] = useState(null);
|
|
2437
|
+
useImperativeHandle(forwardedRef, () => view, [
|
|
2389
2438
|
view
|
|
2390
|
-
|
|
2439
|
+
]);
|
|
2440
|
+
useEffect(() => {
|
|
2441
|
+
if (view && focus) {
|
|
2442
|
+
view.focus();
|
|
2443
|
+
}
|
|
2444
|
+
}, [
|
|
2391
2445
|
view,
|
|
2392
|
-
|
|
2393
|
-
root
|
|
2446
|
+
focus
|
|
2394
2447
|
]);
|
|
2395
|
-
const { awareness, peer } = model;
|
|
2396
|
-
|
|
2397
|
-
if (
|
|
2398
|
-
|
|
2448
|
+
const { awareness: awareness2, peer } = model;
|
|
2449
|
+
useEffect(() => {
|
|
2450
|
+
if (awareness2 && peer) {
|
|
2451
|
+
awareness2.setLocalStateField("user", {
|
|
2399
2452
|
name: peer.name ?? generateName(peer.id),
|
|
2400
2453
|
color: getColorForValue({
|
|
2401
2454
|
value: peer.id,
|
|
@@ -2409,12 +2462,12 @@ var BaseTextEditor = /* @__PURE__ */ forwardRef(({ model, comments: comments2, r
|
|
|
2409
2462
|
});
|
|
2410
2463
|
}
|
|
2411
2464
|
}, [
|
|
2412
|
-
|
|
2465
|
+
awareness2,
|
|
2413
2466
|
peer,
|
|
2414
2467
|
themeMode
|
|
2415
2468
|
]);
|
|
2416
|
-
|
|
2417
|
-
if (view && comments2
|
|
2469
|
+
useEffect(() => {
|
|
2470
|
+
if (view && comments2 !== void 0) {
|
|
2418
2471
|
view.dispatch({
|
|
2419
2472
|
effects: setCommentRange.of({
|
|
2420
2473
|
model,
|
|
@@ -2426,21 +2479,23 @@ var BaseTextEditor = /* @__PURE__ */ forwardRef(({ model, comments: comments2, r
|
|
|
2426
2479
|
view,
|
|
2427
2480
|
comments2
|
|
2428
2481
|
]);
|
|
2429
|
-
|
|
2430
|
-
if (!
|
|
2482
|
+
useEffect(() => {
|
|
2483
|
+
if (!model || !rootRef.current) {
|
|
2431
2484
|
return;
|
|
2432
2485
|
}
|
|
2433
|
-
const
|
|
2486
|
+
const state = EditorState2.create({
|
|
2434
2487
|
doc: model.text(),
|
|
2488
|
+
// TODO(burdon): Composer should store and set selection when switching documents.
|
|
2489
|
+
selection,
|
|
2435
2490
|
extensions: [
|
|
2436
2491
|
readonly && EditorState2.readOnly.of(readonly),
|
|
2437
2492
|
// TODO(burdon): Factor out VIM mode? (manage via MarkdownPlugin).
|
|
2438
2493
|
editorMode === "vim" && vim(),
|
|
2439
2494
|
// Theme.
|
|
2440
2495
|
// TODO(burdon): Make theme configurable.
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2496
|
+
EditorView12.baseTheme(defaultTheme),
|
|
2497
|
+
EditorView12.theme(theme ?? {}),
|
|
2498
|
+
EditorView12.darkTheme.of(themeMode === "dark"),
|
|
2444
2499
|
// Storage and replication.
|
|
2445
2500
|
model.extension,
|
|
2446
2501
|
// Custom.
|
|
@@ -2448,19 +2503,17 @@ var BaseTextEditor = /* @__PURE__ */ forwardRef(({ model, comments: comments2, r
|
|
|
2448
2503
|
].filter(Boolean)
|
|
2449
2504
|
});
|
|
2450
2505
|
view?.destroy();
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
state: state2,
|
|
2455
|
-
parent: root
|
|
2456
|
-
})
|
|
2506
|
+
const newView = new EditorView12({
|
|
2507
|
+
parent: rootRef.current,
|
|
2508
|
+
state
|
|
2457
2509
|
});
|
|
2510
|
+
setView(newView);
|
|
2458
2511
|
return () => {
|
|
2459
|
-
|
|
2460
|
-
|
|
2512
|
+
newView?.destroy();
|
|
2513
|
+
setView(null);
|
|
2461
2514
|
};
|
|
2462
2515
|
}, [
|
|
2463
|
-
|
|
2516
|
+
rootRef,
|
|
2464
2517
|
model,
|
|
2465
2518
|
readonly,
|
|
2466
2519
|
editorMode,
|
|
@@ -2469,12 +2522,8 @@ var BaseTextEditor = /* @__PURE__ */ forwardRef(({ model, comments: comments2, r
|
|
|
2469
2522
|
const handleKeyUp = useCallback((event) => {
|
|
2470
2523
|
const { key, altKey, shiftKey, metaKey, ctrlKey } = event;
|
|
2471
2524
|
switch (key) {
|
|
2472
|
-
case "Enter": {
|
|
2473
|
-
view?.contentDOM.focus();
|
|
2474
|
-
break;
|
|
2475
|
-
}
|
|
2476
2525
|
case "Escape": {
|
|
2477
|
-
editorMode === "vim" && (altKey || shiftKey || metaKey || ctrlKey) &&
|
|
2526
|
+
editorMode === "vim" && (altKey || shiftKey || metaKey || ctrlKey) && rootRef.current?.focus();
|
|
2478
2527
|
break;
|
|
2479
2528
|
}
|
|
2480
2529
|
}
|
|
@@ -2484,16 +2533,17 @@ var BaseTextEditor = /* @__PURE__ */ forwardRef(({ model, comments: comments2, r
|
|
|
2484
2533
|
]);
|
|
2485
2534
|
return /* @__PURE__ */ React.createElement("div", {
|
|
2486
2535
|
key: model.id,
|
|
2487
|
-
|
|
2536
|
+
role: "none",
|
|
2537
|
+
ref: rootRef,
|
|
2488
2538
|
tabIndex: 0,
|
|
2489
|
-
|
|
2490
|
-
...
|
|
2491
|
-
|
|
2539
|
+
onKeyUp: handleKeyUp,
|
|
2540
|
+
...slots.root,
|
|
2541
|
+
...editorMode !== "vim" && tabsterDOMAttribute
|
|
2492
2542
|
});
|
|
2493
2543
|
});
|
|
2494
|
-
var TextEditor = /* @__PURE__ */ forwardRef(({ readonly, extensions = [],
|
|
2544
|
+
var TextEditor = /* @__PURE__ */ forwardRef(({ readonly, placeholder: placeholder3, extensions = [], theme = textTheme, slots, ...props }, forwardedRef) => {
|
|
2495
2545
|
const { themeMode } = useThemeContext();
|
|
2496
|
-
const
|
|
2546
|
+
const updatedSlots = defaultsDeep2({}, slots, defaultTextSlots);
|
|
2497
2547
|
return /* @__PURE__ */ React.createElement(BaseTextEditor, {
|
|
2498
2548
|
ref: forwardedRef,
|
|
2499
2549
|
readonly,
|
|
@@ -2501,17 +2551,18 @@ var TextEditor = /* @__PURE__ */ forwardRef(({ readonly, extensions = [], slots:
|
|
|
2501
2551
|
basicBundle({
|
|
2502
2552
|
readonly,
|
|
2503
2553
|
themeMode,
|
|
2504
|
-
placeholder:
|
|
2554
|
+
placeholder: placeholder3
|
|
2505
2555
|
}),
|
|
2506
2556
|
...extensions
|
|
2507
2557
|
],
|
|
2508
|
-
|
|
2558
|
+
theme,
|
|
2559
|
+
slots: updatedSlots,
|
|
2509
2560
|
...props
|
|
2510
2561
|
});
|
|
2511
2562
|
});
|
|
2512
|
-
var MarkdownEditor = /* @__PURE__ */ forwardRef(({ readonly, extensions = [],
|
|
2563
|
+
var MarkdownEditor = /* @__PURE__ */ forwardRef(({ readonly, placeholder: placeholder3, extensions = [], theme = markdownTheme, slots, ...props }, forwardedRef) => {
|
|
2513
2564
|
const { themeMode } = useThemeContext();
|
|
2514
|
-
const
|
|
2565
|
+
const updatedSlots = defaultsDeep2({}, slots, defaultMarkdownSlots);
|
|
2515
2566
|
return /* @__PURE__ */ React.createElement(BaseTextEditor, {
|
|
2516
2567
|
ref: forwardedRef,
|
|
2517
2568
|
readonly,
|
|
@@ -2519,53 +2570,369 @@ var MarkdownEditor = /* @__PURE__ */ forwardRef(({ readonly, extensions = [], sl
|
|
|
2519
2570
|
markdownBundle({
|
|
2520
2571
|
readonly,
|
|
2521
2572
|
themeMode,
|
|
2522
|
-
placeholder:
|
|
2573
|
+
placeholder: placeholder3
|
|
2523
2574
|
}),
|
|
2524
2575
|
...extensions
|
|
2525
2576
|
],
|
|
2526
|
-
|
|
2577
|
+
theme,
|
|
2578
|
+
slots: updatedSlots,
|
|
2527
2579
|
...props
|
|
2528
2580
|
});
|
|
2529
2581
|
});
|
|
2530
2582
|
var defaultSlots = {
|
|
2531
2583
|
root: {
|
|
2532
|
-
className: mx3("p-2", inputSurface)
|
|
2584
|
+
className: mx3("p-2 overflow-y-auto", inputSurface)
|
|
2533
2585
|
}
|
|
2534
2586
|
};
|
|
2535
2587
|
var defaultTextSlots = {
|
|
2536
|
-
...defaultSlots
|
|
2537
|
-
editor: {
|
|
2538
|
-
theme: textTheme
|
|
2539
|
-
}
|
|
2588
|
+
...defaultSlots
|
|
2540
2589
|
};
|
|
2541
2590
|
var defaultMarkdownSlots = {
|
|
2542
|
-
...defaultSlots
|
|
2543
|
-
|
|
2544
|
-
|
|
2591
|
+
...defaultSlots
|
|
2592
|
+
};
|
|
2593
|
+
|
|
2594
|
+
// packages/ui/react-ui-editor/src/hooks/automerge.ts
|
|
2595
|
+
import get4 from "lodash.get";
|
|
2596
|
+
import { getRawDoc } from "@dxos/echo-schema";
|
|
2597
|
+
import { isNotNullOrUndefined } from "@dxos/util";
|
|
2598
|
+
|
|
2599
|
+
// packages/ui/react-ui-editor/src/hooks/awareness-provider.ts
|
|
2600
|
+
import { DeferredTask, Event as Event2, sleep } from "@dxos/async";
|
|
2601
|
+
import { Context as Context2 } from "@dxos/context";
|
|
2602
|
+
import { invariant as invariant3 } from "@dxos/invariant";
|
|
2603
|
+
import { log as log3 } from "@dxos/log";
|
|
2604
|
+
var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/hooks/awareness-provider.ts";
|
|
2605
|
+
var DEBOUNCE_INTERVAL = 100;
|
|
2606
|
+
var SpaceAwarenessProvider = class {
|
|
2607
|
+
constructor(params) {
|
|
2608
|
+
this.remoteStateChange = new Event2();
|
|
2609
|
+
this._remoteStates = /* @__PURE__ */ new Map();
|
|
2610
|
+
this._space = params.space;
|
|
2611
|
+
this._channel = params.channel;
|
|
2612
|
+
this._peerId = params.peerId;
|
|
2613
|
+
this._info = params.info;
|
|
2614
|
+
}
|
|
2615
|
+
open() {
|
|
2616
|
+
this._ctx = new Context2();
|
|
2617
|
+
this._postTask = new DeferredTask(this._ctx, async () => {
|
|
2618
|
+
if (this._localState) {
|
|
2619
|
+
await this._space.postMessage(this._channel, {
|
|
2620
|
+
kind: "post",
|
|
2621
|
+
state: this._localState
|
|
2622
|
+
});
|
|
2623
|
+
await sleep(DEBOUNCE_INTERVAL);
|
|
2624
|
+
}
|
|
2625
|
+
});
|
|
2626
|
+
const unsubscribe = this._space.listen(this._channel, (message) => {
|
|
2627
|
+
switch (message.payload.kind) {
|
|
2628
|
+
case "query": {
|
|
2629
|
+
this._handleQueryMessage();
|
|
2630
|
+
break;
|
|
2631
|
+
}
|
|
2632
|
+
case "post": {
|
|
2633
|
+
this._handlePostMessage(message.payload);
|
|
2634
|
+
break;
|
|
2635
|
+
}
|
|
2636
|
+
}
|
|
2637
|
+
});
|
|
2638
|
+
this._ctx.onDispose(unsubscribe);
|
|
2639
|
+
void this._space.postMessage(this._channel, {
|
|
2640
|
+
kind: "query"
|
|
2641
|
+
}).catch((err) => {
|
|
2642
|
+
log3.debug("failed to query awareness", {
|
|
2643
|
+
err
|
|
2644
|
+
}, {
|
|
2645
|
+
F: __dxlog_file4,
|
|
2646
|
+
L: 85,
|
|
2647
|
+
S: this,
|
|
2648
|
+
C: (f, a) => f(...a)
|
|
2649
|
+
});
|
|
2650
|
+
});
|
|
2651
|
+
}
|
|
2652
|
+
close() {
|
|
2653
|
+
void this._ctx?.dispose();
|
|
2654
|
+
this._ctx = void 0;
|
|
2655
|
+
this._postTask = void 0;
|
|
2656
|
+
}
|
|
2657
|
+
update(position) {
|
|
2658
|
+
invariant3(this._postTask, void 0, {
|
|
2659
|
+
F: __dxlog_file4,
|
|
2660
|
+
L: 96,
|
|
2661
|
+
S: this,
|
|
2662
|
+
A: [
|
|
2663
|
+
"this._postTask",
|
|
2664
|
+
""
|
|
2665
|
+
]
|
|
2666
|
+
});
|
|
2667
|
+
this._localState = {
|
|
2668
|
+
peerId: this._peerId,
|
|
2669
|
+
position,
|
|
2670
|
+
info: this._info
|
|
2671
|
+
};
|
|
2672
|
+
this._postTask.schedule();
|
|
2673
|
+
}
|
|
2674
|
+
getRemoteStates() {
|
|
2675
|
+
return Array.from(this._remoteStates.values());
|
|
2676
|
+
}
|
|
2677
|
+
_handleQueryMessage() {
|
|
2678
|
+
invariant3(this._postTask, void 0, {
|
|
2679
|
+
F: __dxlog_file4,
|
|
2680
|
+
L: 111,
|
|
2681
|
+
S: this,
|
|
2682
|
+
A: [
|
|
2683
|
+
"this._postTask",
|
|
2684
|
+
""
|
|
2685
|
+
]
|
|
2686
|
+
});
|
|
2687
|
+
this._postTask.schedule();
|
|
2688
|
+
}
|
|
2689
|
+
_handlePostMessage(message) {
|
|
2690
|
+
invariant3(message.kind === "post", void 0, {
|
|
2691
|
+
F: __dxlog_file4,
|
|
2692
|
+
L: 116,
|
|
2693
|
+
S: this,
|
|
2694
|
+
A: [
|
|
2695
|
+
"message.kind === 'post'",
|
|
2696
|
+
""
|
|
2697
|
+
]
|
|
2698
|
+
});
|
|
2699
|
+
this._remoteStates.set(message.state.peerId, message.state);
|
|
2700
|
+
this.remoteStateChange.emit();
|
|
2701
|
+
}
|
|
2702
|
+
};
|
|
2703
|
+
|
|
2704
|
+
// packages/ui/react-ui-editor/src/hooks/useTextModel.ts
|
|
2705
|
+
import { StateField as StateField5 } from "@codemirror/state";
|
|
2706
|
+
import { useEffect as useEffect2, useState as useState2 } from "react";
|
|
2707
|
+
import { isAutomergeObject } from "@dxos/react-client/echo";
|
|
2708
|
+
|
|
2709
|
+
// packages/ui/react-ui-editor/src/hooks/yjs.ts
|
|
2710
|
+
import * as decoding from "lib0/decoding";
|
|
2711
|
+
import * as encoding from "lib0/encoding";
|
|
2712
|
+
import { Observable } from "lib0/observable";
|
|
2713
|
+
import * as YP from "y-protocols/awareness";
|
|
2714
|
+
import { invariant as invariant4 } from "@dxos/invariant";
|
|
2715
|
+
import { log as log4 } from "@dxos/log";
|
|
2716
|
+
var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/hooks/yjs.ts";
|
|
2717
|
+
var createYjsModel = ({ identity, space, text }) => {
|
|
2718
|
+
invariant4(text?.doc && text?.content, void 0, {
|
|
2719
|
+
F: __dxlog_file5,
|
|
2720
|
+
L: 21,
|
|
2721
|
+
S: void 0,
|
|
2722
|
+
A: [
|
|
2723
|
+
"text?.doc && text?.content",
|
|
2724
|
+
""
|
|
2725
|
+
]
|
|
2726
|
+
});
|
|
2727
|
+
const provider = space ? new YAwarenessProvider({
|
|
2728
|
+
space,
|
|
2729
|
+
doc: text.doc,
|
|
2730
|
+
channel: `yjs.awareness.${text.id}`
|
|
2731
|
+
}) : void 0;
|
|
2732
|
+
const model = {
|
|
2733
|
+
id: text.doc.guid,
|
|
2734
|
+
content: text.content,
|
|
2735
|
+
text: () => text.content.toString(),
|
|
2736
|
+
extension: [
|
|
2737
|
+
modelState.init(() => model),
|
|
2738
|
+
yjs(text.content, provider?.awareness)
|
|
2739
|
+
],
|
|
2740
|
+
awareness: provider?.awareness,
|
|
2741
|
+
peer: identity ? {
|
|
2742
|
+
id: identity.identityKey.toHex(),
|
|
2743
|
+
name: identity.profile?.displayName
|
|
2744
|
+
} : void 0
|
|
2745
|
+
};
|
|
2746
|
+
return model;
|
|
2747
|
+
};
|
|
2748
|
+
var messageAwareness = 1;
|
|
2749
|
+
var messageQueryAwareness = 3;
|
|
2750
|
+
var YAwarenessProvider = class extends Observable {
|
|
2751
|
+
constructor({ space, doc, channel, awareness: awareness2 }) {
|
|
2752
|
+
super();
|
|
2753
|
+
this._space = space;
|
|
2754
|
+
this._awareness = awareness2 ?? new YP.Awareness(doc);
|
|
2755
|
+
this._channel = channel;
|
|
2756
|
+
this._clientId = doc.clientID;
|
|
2757
|
+
this._awareness.on("update", this._handleAwarenessUpdate.bind(this));
|
|
2758
|
+
this._space.listen(this._channel, this._handleSpaceMessage.bind(this));
|
|
2759
|
+
if (typeof window !== "undefined") {
|
|
2760
|
+
window.addEventListener("beforeunload", this._handleBeforeUnload.bind(this));
|
|
2761
|
+
} else if (typeof process !== "undefined") {
|
|
2762
|
+
process.on("exit", this._handleBeforeUnload.bind(this));
|
|
2763
|
+
}
|
|
2764
|
+
const encoderAwarenessQuery = encoding.createEncoder();
|
|
2765
|
+
encoding.writeVarUint(encoderAwarenessQuery, messageQueryAwareness);
|
|
2766
|
+
void this._space.postMessage(this._channel, encoding.toUint8Array(encoderAwarenessQuery));
|
|
2767
|
+
const encoderAwarenessState = encoding.createEncoder();
|
|
2768
|
+
encoding.writeVarUint(encoderAwarenessState, messageAwareness);
|
|
2769
|
+
encoding.writeVarUint8Array(encoderAwarenessState, YP.encodeAwarenessUpdate(this.awareness, [
|
|
2770
|
+
this._clientId
|
|
2771
|
+
]));
|
|
2772
|
+
void this._space.postMessage(this._channel, encoding.toUint8Array(encoderAwarenessState));
|
|
2773
|
+
}
|
|
2774
|
+
get awareness() {
|
|
2775
|
+
return this._awareness;
|
|
2776
|
+
}
|
|
2777
|
+
_handleAwarenessUpdate({ added, updated, removed }, origin) {
|
|
2778
|
+
log4("awareness update", {
|
|
2779
|
+
added,
|
|
2780
|
+
updated,
|
|
2781
|
+
removed,
|
|
2782
|
+
origin
|
|
2783
|
+
}, {
|
|
2784
|
+
F: __dxlog_file5,
|
|
2785
|
+
L: 100,
|
|
2786
|
+
S: this,
|
|
2787
|
+
C: (f, a) => f(...a)
|
|
2788
|
+
});
|
|
2789
|
+
const changedClients = added.concat(updated).concat(removed);
|
|
2790
|
+
const encoderAwareness = encoding.createEncoder();
|
|
2791
|
+
encoding.writeVarUint(encoderAwareness, messageAwareness);
|
|
2792
|
+
encoding.writeVarUint8Array(encoderAwareness, YP.encodeAwarenessUpdate(this._awareness, changedClients));
|
|
2793
|
+
void this._space.postMessage(this._channel, encoding.toUint8Array(encoderAwareness));
|
|
2794
|
+
}
|
|
2795
|
+
_handleSpaceMessage({ payload }) {
|
|
2796
|
+
log4("space message", payload, {
|
|
2797
|
+
F: __dxlog_file5,
|
|
2798
|
+
L: 109,
|
|
2799
|
+
S: this,
|
|
2800
|
+
C: (f, a) => f(...a)
|
|
2801
|
+
});
|
|
2802
|
+
const data = new Uint8Array(Array.from(Object.values(payload)));
|
|
2803
|
+
const encoder = this._readMessage(data);
|
|
2804
|
+
if (encoder) {
|
|
2805
|
+
void this._space.postMessage(this._channel, encoding.toUint8Array(encoder));
|
|
2806
|
+
}
|
|
2807
|
+
}
|
|
2808
|
+
_readMessage(message) {
|
|
2809
|
+
const decoder = decoding.createDecoder(message);
|
|
2810
|
+
const encoder = encoding.createEncoder();
|
|
2811
|
+
const messageType = decoding.readVarUint(decoder);
|
|
2812
|
+
let sendReply = false;
|
|
2813
|
+
switch (messageType) {
|
|
2814
|
+
case messageAwareness: {
|
|
2815
|
+
YP.applyAwarenessUpdate(this._awareness, decoding.readVarUint8Array(decoder), this);
|
|
2816
|
+
break;
|
|
2817
|
+
}
|
|
2818
|
+
case messageQueryAwareness: {
|
|
2819
|
+
encoding.writeVarUint(encoder, messageAwareness);
|
|
2820
|
+
encoding.writeVarUint8Array(encoder, YP.encodeAwarenessUpdate(this._awareness, Array.from(this._awareness.getStates().keys())));
|
|
2821
|
+
sendReply = true;
|
|
2822
|
+
break;
|
|
2823
|
+
}
|
|
2824
|
+
default: {
|
|
2825
|
+
console.error("Invalid message:", messageType);
|
|
2826
|
+
return encoder;
|
|
2827
|
+
}
|
|
2828
|
+
}
|
|
2829
|
+
if (!sendReply) {
|
|
2830
|
+
return null;
|
|
2831
|
+
}
|
|
2832
|
+
return encoder;
|
|
2833
|
+
}
|
|
2834
|
+
_handleBeforeUnload() {
|
|
2835
|
+
YP.removeAwarenessStates(this._awareness, [
|
|
2836
|
+
this._clientId
|
|
2837
|
+
], "window unload");
|
|
2838
|
+
}
|
|
2839
|
+
};
|
|
2840
|
+
|
|
2841
|
+
// packages/ui/react-ui-editor/src/hooks/useTextModel.ts
|
|
2842
|
+
var modelState = StateField5.define({
|
|
2843
|
+
create: () => void 0,
|
|
2844
|
+
update: (model) => model
|
|
2845
|
+
});
|
|
2846
|
+
var useTextModel = (props) => {
|
|
2847
|
+
const { identity, space, text } = props;
|
|
2848
|
+
const [model, setModel] = useState2();
|
|
2849
|
+
useEffect2(() => setModel(createModel(props)), [
|
|
2850
|
+
identity,
|
|
2851
|
+
space,
|
|
2852
|
+
text
|
|
2853
|
+
]);
|
|
2854
|
+
return model;
|
|
2855
|
+
};
|
|
2856
|
+
var createModel = (props) => {
|
|
2857
|
+
const { text } = props;
|
|
2858
|
+
if (isAutomergeObject(text)) {
|
|
2859
|
+
return createAutomergeModel(props);
|
|
2860
|
+
} else if (text?.doc) {
|
|
2861
|
+
return createYjsModel(props);
|
|
2862
|
+
} else {
|
|
2863
|
+
return void 0;
|
|
2545
2864
|
}
|
|
2546
2865
|
};
|
|
2866
|
+
|
|
2867
|
+
// packages/ui/react-ui-editor/src/hooks/automerge.ts
|
|
2868
|
+
var createAutomergeModel = ({ space, identity, text }) => {
|
|
2869
|
+
const obj = text;
|
|
2870
|
+
const doc = getRawDoc(obj, [
|
|
2871
|
+
obj.field
|
|
2872
|
+
]);
|
|
2873
|
+
const awarenessProvider = space && new SpaceAwarenessProvider({
|
|
2874
|
+
space,
|
|
2875
|
+
channel: `automerge.awareness.${obj.id}`,
|
|
2876
|
+
info: {
|
|
2877
|
+
displayName: identity?.profile?.displayName ?? "",
|
|
2878
|
+
color: cursorColor.color,
|
|
2879
|
+
lightColor: cursorColor.light
|
|
2880
|
+
},
|
|
2881
|
+
peerId: identity?.identityKey.toHex() ?? "Anonymous"
|
|
2882
|
+
});
|
|
2883
|
+
const model = {
|
|
2884
|
+
id: obj.id,
|
|
2885
|
+
content: doc,
|
|
2886
|
+
text: () => get4(doc.handle.docSync(), doc.path),
|
|
2887
|
+
// TODO(burdon): https://automerge.org/automerge/api-docs/js/functions/next.getCursor.html
|
|
2888
|
+
extension: [
|
|
2889
|
+
modelState.init(() => model),
|
|
2890
|
+
automerge3({
|
|
2891
|
+
handle: doc.handle,
|
|
2892
|
+
path: doc.path
|
|
2893
|
+
}),
|
|
2894
|
+
awarenessProvider && AwarenessProvider.of(awarenessProvider),
|
|
2895
|
+
awareness()
|
|
2896
|
+
].filter(isNotNullOrUndefined),
|
|
2897
|
+
peer: identity ? {
|
|
2898
|
+
id: identity.identityKey.toHex(),
|
|
2899
|
+
name: identity.profile?.displayName
|
|
2900
|
+
} : void 0
|
|
2901
|
+
};
|
|
2902
|
+
return model;
|
|
2903
|
+
};
|
|
2547
2904
|
export {
|
|
2905
|
+
AwarenessProvider,
|
|
2548
2906
|
BaseTextEditor,
|
|
2907
|
+
Cursor,
|
|
2549
2908
|
Doc,
|
|
2550
2909
|
EditorModes,
|
|
2551
2910
|
MarkdownEditor,
|
|
2911
|
+
RemoteSelectionsDecorator,
|
|
2552
2912
|
SpaceAwarenessProvider,
|
|
2553
2913
|
TextEditor,
|
|
2554
2914
|
TextKind,
|
|
2915
|
+
YAwarenessProvider,
|
|
2555
2916
|
YText,
|
|
2556
2917
|
YXmlFragment,
|
|
2557
2918
|
autocomplete,
|
|
2919
|
+
automerge3 as automerge,
|
|
2920
|
+
awareness,
|
|
2558
2921
|
basicBundle,
|
|
2559
2922
|
blast,
|
|
2923
|
+
callbackWrapper,
|
|
2560
2924
|
code2 as code,
|
|
2561
2925
|
codeTheme,
|
|
2562
2926
|
comments,
|
|
2563
|
-
|
|
2927
|
+
createAutomergeModel,
|
|
2928
|
+
createYjsModel,
|
|
2929
|
+
cursorConverter,
|
|
2564
2930
|
defaultMarkdownSlots,
|
|
2565
2931
|
defaultOptions,
|
|
2566
2932
|
defaultSlots,
|
|
2567
2933
|
defaultTextSlots,
|
|
2568
2934
|
defaultTheme,
|
|
2935
|
+
getToken,
|
|
2569
2936
|
hr,
|
|
2570
2937
|
image,
|
|
2571
2938
|
link,
|
|
@@ -2576,15 +2943,16 @@ export {
|
|
|
2576
2943
|
markdownTagsExtensions,
|
|
2577
2944
|
markdownTheme,
|
|
2578
2945
|
mention,
|
|
2579
|
-
mermaid,
|
|
2580
2946
|
modelState,
|
|
2581
2947
|
setCommentRange,
|
|
2948
|
+
setFocus,
|
|
2949
|
+
setSelection,
|
|
2582
2950
|
table,
|
|
2583
2951
|
tags2 as tags,
|
|
2584
2952
|
tasklist,
|
|
2585
2953
|
textTheme,
|
|
2586
|
-
tooltip,
|
|
2587
2954
|
typewriter,
|
|
2588
|
-
useTextModel
|
|
2955
|
+
useTextModel,
|
|
2956
|
+
yjs
|
|
2589
2957
|
};
|
|
2590
2958
|
//# sourceMappingURL=index.mjs.map
|