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