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