@dxos/react-ui-editor 0.3.11-main.1caa3af → 0.3.11-main.1d8382a
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 +1492 -989
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/types/src/components/TextEditor/MarkdownEditor.stories.d.ts +9 -8
- package/dist/types/src/components/TextEditor/MarkdownEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/TextEditor.d.ts +8 -12
- package/dist/types/src/components/TextEditor/TextEditor.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/TextEditor.stories.d.ts +5 -2
- 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 +4 -0
- package/dist/types/src/extensions/automerge/index.d.ts.map +1 -0
- package/dist/types/src/{hooks → extensions}/automerge/semaphore.d.ts +4 -4
- package/dist/types/src/extensions/automerge/semaphore.d.ts.map +1 -0
- package/dist/types/src/extensions/automerge/update-automerge.d.ts +5 -0
- package/dist/types/src/extensions/automerge/update-automerge.d.ts.map +1 -0
- package/dist/types/src/extensions/automerge/update-codemirror.d.ts.map +1 -0
- package/dist/types/src/extensions/awareness.d.ts +46 -0
- package/dist/types/src/extensions/awareness.d.ts.map +1 -0
- package/dist/types/src/extensions/basic.d.ts.map +1 -0
- package/dist/types/src/extensions/blast.d.ts.map +1 -0
- package/dist/types/src/extensions/code.d.ts.map +1 -0
- package/dist/types/src/{components/TextEditor/extensions → extensions}/comments.d.ts +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 -2
- package/dist/types/src/extensions/index.d.ts.map +1 -0
- package/dist/types/src/{components/TextEditor/extensions → extensions}/link.d.ts +1 -0
- package/dist/types/src/extensions/link.d.ts.map +1 -0
- package/dist/types/src/extensions/listener.d.ts +10 -0
- package/dist/types/src/extensions/listener.d.ts.map +1 -0
- package/dist/types/src/extensions/markdown/bundle.d.ts.map +1 -0
- package/dist/types/src/extensions/markdown/highlight.d.ts.map +1 -0
- package/dist/types/src/extensions/markdown/index.d.ts.map +1 -0
- package/dist/types/src/extensions/mention.d.ts.map +1 -0
- package/dist/types/src/extensions/table.d.ts.map +1 -0
- package/dist/types/src/extensions/tasklist.d.ts.map +1 -0
- package/dist/types/src/extensions/typewriter.d.ts.map +1 -0
- package/dist/types/src/extensions/yjs/cursor.d.ts +4 -0
- package/dist/types/src/extensions/yjs/cursor.d.ts.map +1 -0
- package/dist/types/src/extensions/yjs/index.d.ts +2 -0
- package/dist/types/src/extensions/yjs/index.d.ts.map +1 -0
- package/dist/types/src/extensions/yjs/yjs.d.ts +4 -0
- package/dist/types/src/extensions/yjs/yjs.d.ts.map +1 -0
- package/dist/types/src/extensions/yjs/yjs.test.d.ts.map +1 -0
- package/dist/types/src/hooks/automerge.d.ts +3 -0
- package/dist/types/src/hooks/automerge.d.ts.map +1 -0
- package/dist/types/src/hooks/awareness-provider.d.ts +28 -0
- package/dist/types/src/hooks/awareness-provider.d.ts.map +1 -0
- package/dist/types/src/hooks/index.d.ts +2 -0
- package/dist/types/src/hooks/index.d.ts.map +1 -1
- package/dist/types/src/hooks/useTextModel.d.ts +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 +5 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/styles/cursors.d.ts.map +1 -0
- package/dist/types/src/styles/index.d.ts +1 -0
- package/dist/types/src/styles/index.d.ts.map +1 -1
- package/dist/types/src/styles/tokens.d.ts +1 -0
- package/dist/types/src/styles/tokens.d.ts.map +1 -1
- package/dist/types/src/testing/replicator.d.ts +2 -2
- package/dist/types/src/testing/replicator.d.ts.map +1 -1
- package/dist/types/src/{components/TextEditor/themes → themes}/default.d.ts +1 -1
- package/dist/types/src/themes/default.d.ts.map +1 -0
- package/dist/types/src/themes/index.d.ts.map +1 -0
- package/dist/types/src/util/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 +24 -24
- package/src/components/TextEditor/TextEditor.stories.tsx +17 -5
- package/src/components/TextEditor/TextEditor.tsx +57 -51
- 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/{components/TextEditor/extensions → extensions}/autocomplete.ts +18 -17
- 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 +7 -0
- package/src/{hooks → extensions}/automerge/semaphore.ts +14 -12
- package/src/{hooks → extensions}/automerge/update-automerge.ts +5 -6
- package/src/{hooks → extensions}/automerge/update-codemirror.ts +13 -5
- package/src/extensions/awareness.ts +316 -0
- package/src/{components/TextEditor/extensions → extensions}/code.ts +4 -5
- package/src/{components/TextEditor/extensions → extensions}/comments.ts +51 -19
- package/src/{components/TextEditor/extensions → extensions}/hr.ts +2 -3
- package/src/extensions/image.ts +87 -0
- package/src/{components/TextEditor/extensions → extensions}/index.ts +3 -2
- 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 +4 -5
- package/src/{components/TextEditor/extensions → extensions}/table.ts +9 -3
- 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 +21 -94
- package/src/hooks/{yjs/space-provider.ts → yjs.ts} +71 -19
- package/src/index.ts +5 -0
- package/src/styles/index.ts +1 -0
- package/src/styles/tokens.ts +3 -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 +0 -3
- package/dist/types/src/components/TextEditor/extensions/mermaid.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/table.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/tasklist.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/tooltip.d.ts +0 -12
- package/dist/types/src/components/TextEditor/extensions/tooltip.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/typewriter.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/util.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/themes/default.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/themes/index.d.ts.map +0 -1
- package/dist/types/src/hooks/automerge/automerge.stories.d.ts.map +0 -1
- package/dist/types/src/hooks/automerge/handle.d.ts +0 -9
- package/dist/types/src/hooks/automerge/handle.d.ts.map +0 -1
- package/dist/types/src/hooks/automerge/index.d.ts +0 -3
- package/dist/types/src/hooks/automerge/index.d.ts.map +0 -1
- package/dist/types/src/hooks/automerge/plugin.d.ts +0 -26
- package/dist/types/src/hooks/automerge/plugin.d.ts.map +0 -1
- package/dist/types/src/hooks/automerge/semaphore.d.ts.map +0 -1
- package/dist/types/src/hooks/automerge/update-automerge.d.ts +0 -6
- package/dist/types/src/hooks/automerge/update-automerge.d.ts.map +0 -1
- package/dist/types/src/hooks/automerge/update-codemirror.d.ts.map +0 -1
- package/dist/types/src/hooks/yjs/cursors.d.ts.map +0 -1
- package/dist/types/src/hooks/yjs/index.d.ts +0 -3
- package/dist/types/src/hooks/yjs/index.d.ts.map +0 -1
- package/dist/types/src/hooks/yjs/space-provider.d.ts.map +0 -1
- package/dist/types/src/hooks/yjs/yjs.stories.d.ts.map +0 -1
- package/dist/types/src/hooks/yjs/yjs.test.d.ts.map +0 -1
- package/src/components/TextEditor/extensions/image.ts +0 -69
- package/src/components/TextEditor/extensions/listener.ts +0 -23
- package/src/components/TextEditor/extensions/mermaid.ts +0 -11
- package/src/components/TextEditor/extensions/tooltip.ts +0 -61
- package/src/hooks/automerge/handle.ts +0 -14
- package/src/hooks/automerge/index.ts +0 -6
- package/src/hooks/automerge/plugin.ts +0 -134
- package/src/hooks/yjs/index.ts +0 -6
- /package/dist/types/src/{components/TextEditor/extensions → extensions}/autocomplete.d.ts +0 -0
- /package/dist/types/src/{hooks → extensions}/automerge/update-codemirror.d.ts +0 -0
- /package/dist/types/src/{components/TextEditor/extensions → extensions}/basic.d.ts +0 -0
- /package/dist/types/src/{components/TextEditor/extensions → extensions}/blast.d.ts +0 -0
- /package/dist/types/src/{components/TextEditor/extensions → extensions}/code.d.ts +0 -0
- /package/dist/types/src/{components/TextEditor/extensions → extensions}/hr.d.ts +0 -0
- /package/dist/types/src/{components/TextEditor/extensions → extensions}/image.d.ts +0 -0
- /package/dist/types/src/{components/TextEditor/extensions → extensions}/markdown/bundle.d.ts +0 -0
- /package/dist/types/src/{components/TextEditor/extensions → extensions}/markdown/highlight.d.ts +0 -0
- /package/dist/types/src/{components/TextEditor/extensions → extensions}/markdown/index.d.ts +0 -0
- /package/dist/types/src/{components/TextEditor/extensions → extensions}/mention.d.ts +0 -0
- /package/dist/types/src/{components/TextEditor/extensions → extensions}/table.d.ts +0 -0
- /package/dist/types/src/{components/TextEditor/extensions → extensions}/tasklist.d.ts +0 -0
- /package/dist/types/src/{components/TextEditor/extensions → extensions}/typewriter.d.ts +0 -0
- /package/dist/types/src/{hooks → extensions}/yjs/yjs.test.d.ts +0 -0
- /package/dist/types/src/{hooks/yjs → styles}/cursors.d.ts +0 -0
- /package/dist/types/src/{components/TextEditor/themes → themes}/index.d.ts +0 -0
- /package/dist/types/src/{components/TextEditor/extensions → util}/util.d.ts +0 -0
- /package/src/{components/TextEditor/extensions → extensions}/basic.ts +0 -0
- /package/src/{components/TextEditor/extensions → extensions}/blast.ts +0 -0
- /package/src/{components/TextEditor/extensions → extensions}/markdown/bundle.ts +0 -0
- /package/src/{components/TextEditor/extensions → extensions}/markdown/index.ts +0 -0
- /package/src/{components/TextEditor/extensions → extensions}/mention.ts +0 -0
- /package/src/{hooks/yjs → styles}/cursors.ts +0 -0
- /package/src/{components/TextEditor/themes → themes}/index.ts +0 -0
- /package/src/{components/TextEditor/extensions → util}/util.ts +0 -0
|
@@ -5,46 +5,610 @@ import { Doc, YText, YXmlFragment } from "@dxos/text-model";
|
|
|
5
5
|
// packages/ui/react-ui-editor/src/components/TextEditor/index.ts
|
|
6
6
|
import { tags as tags2 } from "@lezer/highlight";
|
|
7
7
|
|
|
8
|
-
// packages/ui/react-ui-editor/src/components/TextEditor/
|
|
8
|
+
// packages/ui/react-ui-editor/src/components/TextEditor/TextEditor.tsx
|
|
9
|
+
import { EditorState as EditorState2 } from "@codemirror/state";
|
|
10
|
+
import { EditorView as EditorView12 } from "@codemirror/view";
|
|
11
|
+
import { useFocusableGroup } from "@fluentui/react-tabster";
|
|
12
|
+
import { vim } from "@replit/codemirror-vim";
|
|
13
|
+
import defaultsDeep2 from "lodash.defaultsdeep";
|
|
14
|
+
import React, { forwardRef, useCallback, useEffect, useImperativeHandle, useState, useRef } from "react";
|
|
15
|
+
import { generateName } from "@dxos/display-name";
|
|
16
|
+
import { useThemeContext } from "@dxos/react-ui";
|
|
17
|
+
import { getColorForValue, inputSurface, mx as mx3 } from "@dxos/react-ui-theme";
|
|
18
|
+
|
|
19
|
+
// packages/ui/react-ui-editor/src/extensions/autocomplete.ts
|
|
9
20
|
import { autocompletion, completionKeymap } from "@codemirror/autocomplete";
|
|
21
|
+
import { markdownLanguage } from "@codemirror/lang-markdown";
|
|
10
22
|
import { keymap } from "@codemirror/view";
|
|
11
23
|
var autocomplete = ({ onSearch }) => {
|
|
12
24
|
return [
|
|
13
25
|
// https://codemirror.net/docs/ref/#view.keymap
|
|
14
26
|
// https://discuss.codemirror.net/t/how-can-i-replace-the-default-autocompletion-keymap-v6/3322
|
|
27
|
+
// TODO(burdon): Set custom keymap.
|
|
15
28
|
keymap.of(completionKeymap),
|
|
16
29
|
// https://codemirror.net/examples/autocompletion
|
|
17
30
|
// https://codemirror.net/docs/ref/#autocomplete.autocompletion
|
|
18
31
|
autocompletion({
|
|
19
|
-
|
|
20
|
-
// defaultKeymap: false,
|
|
32
|
+
defaultKeymap: false,
|
|
21
33
|
// Don't start unless key press.
|
|
22
|
-
activateOnTyping: false
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return {
|
|
32
|
-
from: match.from,
|
|
33
|
-
options: onSearch(match.text.toLowerCase())
|
|
34
|
-
};
|
|
34
|
+
activateOnTyping: false
|
|
35
|
+
}),
|
|
36
|
+
// TODO(burdon): Option to create new page?
|
|
37
|
+
// TODO(burdon): Optional decoration via addToOptions
|
|
38
|
+
markdownLanguage.data.of({
|
|
39
|
+
autocomplete: (context) => {
|
|
40
|
+
const match = context.matchBefore(/\w*/);
|
|
41
|
+
if (!match || match.from === match.to && !context.explicit) {
|
|
42
|
+
return null;
|
|
35
43
|
}
|
|
36
|
-
|
|
44
|
+
return {
|
|
45
|
+
from: match.from,
|
|
46
|
+
options: onSearch(match.text.toLowerCase())
|
|
47
|
+
};
|
|
48
|
+
}
|
|
37
49
|
})
|
|
38
50
|
];
|
|
39
51
|
};
|
|
40
52
|
|
|
41
|
-
// packages/ui/react-ui-editor/src/
|
|
53
|
+
// packages/ui/react-ui-editor/src/extensions/automerge/automerge.ts
|
|
54
|
+
import { Facet as Facet2, StateField } from "@codemirror/state";
|
|
55
|
+
import { ViewPlugin } from "@codemirror/view";
|
|
56
|
+
import { next as A } from "@dxos/automerge/automerge";
|
|
57
|
+
|
|
58
|
+
// packages/ui/react-ui-editor/src/extensions/automerge/cursor.ts
|
|
59
|
+
import get from "lodash.get";
|
|
60
|
+
import { next as automerge } from "@dxos/automerge/automerge";
|
|
61
|
+
var cursorConverter = (handle, path) => ({
|
|
62
|
+
// TODO(burdon): Handle assoc to associate with a previous character.
|
|
63
|
+
toCursor: (pos) => {
|
|
64
|
+
const doc = handle.docSync();
|
|
65
|
+
if (!doc) {
|
|
66
|
+
return "";
|
|
67
|
+
}
|
|
68
|
+
const value = get(doc, path);
|
|
69
|
+
if (typeof value === "string" && value.length <= pos) {
|
|
70
|
+
return "end";
|
|
71
|
+
}
|
|
72
|
+
return automerge.getCursor(doc, path.slice(), pos);
|
|
73
|
+
},
|
|
74
|
+
fromCursor: (cursor) => {
|
|
75
|
+
if (cursor === "") {
|
|
76
|
+
return 0;
|
|
77
|
+
}
|
|
78
|
+
const doc = handle.docSync();
|
|
79
|
+
if (!doc) {
|
|
80
|
+
return 0;
|
|
81
|
+
}
|
|
82
|
+
if (cursor === "end") {
|
|
83
|
+
const value = get(doc, path);
|
|
84
|
+
if (typeof value === "string") {
|
|
85
|
+
return value.length;
|
|
86
|
+
} else {
|
|
87
|
+
return 0;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return automerge.getCursorPosition(doc, path.slice(), cursor);
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
// packages/ui/react-ui-editor/src/extensions/automerge/defs.ts
|
|
95
|
+
import { Annotation, StateEffect } from "@codemirror/state";
|
|
96
|
+
var effectType = StateEffect.define({});
|
|
97
|
+
var updateHeads = (newHeads) => effectType.of({
|
|
98
|
+
newHeads
|
|
99
|
+
});
|
|
100
|
+
var getLastHeads = (state, field) => state.field(field).lastHeads;
|
|
101
|
+
var getPath = (state, field) => state.field(field).path;
|
|
102
|
+
var reconcileAnnotationType = Annotation.define();
|
|
103
|
+
var isReconcileTx = (tr) => !!tr.annotation(reconcileAnnotationType);
|
|
104
|
+
|
|
105
|
+
// packages/ui/react-ui-editor/src/extensions/automerge/semaphore.ts
|
|
106
|
+
import { next as automerge2 } from "@dxos/automerge/automerge";
|
|
107
|
+
|
|
108
|
+
// packages/ui/react-ui-editor/src/extensions/automerge/update-automerge.ts
|
|
109
|
+
import { next as am } from "@dxos/automerge/automerge";
|
|
110
|
+
var updateAutomerge = (field, handle, transactions, state) => {
|
|
111
|
+
const { lastHeads, path } = state.field(field);
|
|
112
|
+
let hasChanges = false;
|
|
113
|
+
for (const tr of transactions) {
|
|
114
|
+
tr.changes.iterChanges(() => {
|
|
115
|
+
hasChanges = true;
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
if (!hasChanges) {
|
|
119
|
+
return void 0;
|
|
120
|
+
}
|
|
121
|
+
const newHeads = handle.changeAt(lastHeads, (doc) => {
|
|
122
|
+
for (const tr of transactions) {
|
|
123
|
+
tr.changes.iterChanges((fromA, toA, _fromB, _toB, inserted) => {
|
|
124
|
+
am.splice(doc, path, fromA, toA - fromA, inserted.toString());
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
return newHeads ?? void 0;
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
// packages/ui/react-ui-editor/src/extensions/automerge/update-codemirror.ts
|
|
132
|
+
import { ChangeSet } from "@codemirror/state";
|
|
133
|
+
var updateCodeMirror = (view, selection, target, patches) => {
|
|
134
|
+
for (const patch of patches) {
|
|
135
|
+
const changeSpec = handlePatch(patch, target, view.state);
|
|
136
|
+
if (changeSpec != null) {
|
|
137
|
+
const changeSet = ChangeSet.of(changeSpec, view.state.doc.length, "\n");
|
|
138
|
+
selection = selection.map(changeSet, 1);
|
|
139
|
+
view.dispatch({
|
|
140
|
+
changes: changeSet,
|
|
141
|
+
annotations: reconcileAnnotationType.of({})
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
view.dispatch({
|
|
146
|
+
selection,
|
|
147
|
+
annotations: reconcileAnnotationType.of({})
|
|
148
|
+
});
|
|
149
|
+
};
|
|
150
|
+
var handlePatch = (patch, target, state) => {
|
|
151
|
+
if (patch.action === "insert") {
|
|
152
|
+
return handleInsert(target, patch);
|
|
153
|
+
} else if (patch.action === "splice") {
|
|
154
|
+
return handleSplice(target, patch);
|
|
155
|
+
} else if (patch.action === "del") {
|
|
156
|
+
return handleDel(target, patch);
|
|
157
|
+
} else if (patch.action === "put") {
|
|
158
|
+
return handlePut(target, patch, state);
|
|
159
|
+
} else {
|
|
160
|
+
return null;
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
var handleInsert = (target, patch) => {
|
|
164
|
+
const index = charPath(target, patch.path);
|
|
165
|
+
if (index == null) {
|
|
166
|
+
return [];
|
|
167
|
+
}
|
|
168
|
+
const text = patch.values.map((v) => v ? v.toString() : "").join("");
|
|
169
|
+
return [
|
|
170
|
+
{
|
|
171
|
+
from: index,
|
|
172
|
+
to: index,
|
|
173
|
+
insert: text
|
|
174
|
+
}
|
|
175
|
+
];
|
|
176
|
+
};
|
|
177
|
+
var handleSplice = (target, patch) => {
|
|
178
|
+
const index = charPath(target, patch.path);
|
|
179
|
+
if (index == null) {
|
|
180
|
+
return [];
|
|
181
|
+
}
|
|
182
|
+
return [
|
|
183
|
+
{
|
|
184
|
+
from: index,
|
|
185
|
+
insert: patch.value
|
|
186
|
+
}
|
|
187
|
+
];
|
|
188
|
+
};
|
|
189
|
+
var handleDel = (target, patch) => {
|
|
190
|
+
const index = charPath(target, patch.path);
|
|
191
|
+
if (index == null) {
|
|
192
|
+
return [];
|
|
193
|
+
}
|
|
194
|
+
const length = patch.length || 1;
|
|
195
|
+
return [
|
|
196
|
+
{
|
|
197
|
+
from: index,
|
|
198
|
+
to: index + length
|
|
199
|
+
}
|
|
200
|
+
];
|
|
201
|
+
};
|
|
202
|
+
var handlePut = (target, patch, state) => {
|
|
203
|
+
const index = charPath(target, [
|
|
204
|
+
...patch.path,
|
|
205
|
+
0
|
|
206
|
+
]);
|
|
207
|
+
if (index == null) {
|
|
208
|
+
return [];
|
|
209
|
+
}
|
|
210
|
+
const length = state.doc.length;
|
|
211
|
+
if (typeof patch.value !== "string") {
|
|
212
|
+
return [];
|
|
213
|
+
}
|
|
214
|
+
return [
|
|
215
|
+
{
|
|
216
|
+
from: 0,
|
|
217
|
+
to: length,
|
|
218
|
+
insert: patch.value
|
|
219
|
+
}
|
|
220
|
+
];
|
|
221
|
+
};
|
|
222
|
+
var charPath = (textPath, candidatePath) => {
|
|
223
|
+
if (candidatePath.length !== textPath.length + 1) {
|
|
224
|
+
return null;
|
|
225
|
+
}
|
|
226
|
+
for (let i = 0; i < textPath.length; i++) {
|
|
227
|
+
if (textPath[i] !== candidatePath[i]) {
|
|
228
|
+
return null;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
const index = candidatePath[candidatePath.length - 1];
|
|
232
|
+
if (typeof index === "number") {
|
|
233
|
+
return index;
|
|
234
|
+
}
|
|
235
|
+
return null;
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
// packages/ui/react-ui-editor/src/extensions/automerge/semaphore.ts
|
|
239
|
+
var PatchSemaphore = class {
|
|
240
|
+
constructor(_field) {
|
|
241
|
+
this._field = _field;
|
|
242
|
+
this._inReconcile = false;
|
|
243
|
+
this._queue = [];
|
|
244
|
+
this.reconcile = (handle, view) => {
|
|
245
|
+
if (this._inReconcile) {
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
this._inReconcile = true;
|
|
249
|
+
const path = getPath(view.state, this._field);
|
|
250
|
+
const oldHeads = getLastHeads(view.state, this._field);
|
|
251
|
+
let selection = view.state.selection;
|
|
252
|
+
const transactions = view.state.field(this._field).unreconciledTransactions.filter((tx) => !isReconcileTx(tx));
|
|
253
|
+
const toInvert = transactions.slice().reverse();
|
|
254
|
+
for (const tx of toInvert) {
|
|
255
|
+
const inverted = tx.changes.invert(tx.startState.doc);
|
|
256
|
+
selection = selection.map(inverted);
|
|
257
|
+
view.dispatch({
|
|
258
|
+
changes: inverted,
|
|
259
|
+
annotations: reconcileAnnotationType.of(true)
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
let newHeads = updateAutomerge(this._field, handle, transactions, view.state);
|
|
263
|
+
if (newHeads === null || newHeads === void 0) {
|
|
264
|
+
newHeads = automerge2.getHeads(handle.docSync());
|
|
265
|
+
}
|
|
266
|
+
const diff = automerge2.equals(oldHeads, newHeads) ? [] : automerge2.diff(handle.docSync(), oldHeads, newHeads);
|
|
267
|
+
updateCodeMirror(view, selection, path, diff);
|
|
268
|
+
view.dispatch({
|
|
269
|
+
effects: updateHeads(newHeads),
|
|
270
|
+
annotations: reconcileAnnotationType.of({})
|
|
271
|
+
});
|
|
272
|
+
this._inReconcile = false;
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
// packages/ui/react-ui-editor/src/util/cursor.ts
|
|
278
|
+
import { Facet } from "@codemirror/state";
|
|
279
|
+
var DEFAULT_CURSOR_CONVERTER = {
|
|
280
|
+
toCursor: (position) => position.toString(),
|
|
281
|
+
fromCursor: (cursor) => parseInt(cursor)
|
|
282
|
+
};
|
|
283
|
+
var CursorConverter = Facet.define({
|
|
284
|
+
combine: (providers) => providers[0] ?? DEFAULT_CURSOR_CONVERTER
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
// packages/ui/react-ui-editor/src/util/util.ts
|
|
288
|
+
import { log } from "@dxos/log";
|
|
289
|
+
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/util/util.ts";
|
|
290
|
+
var callbackWrapper = (fn) => (...args) => {
|
|
291
|
+
try {
|
|
292
|
+
return fn(...args);
|
|
293
|
+
} catch (error) {
|
|
294
|
+
log.catch(error, void 0, {
|
|
295
|
+
F: __dxlog_file,
|
|
296
|
+
L: 16,
|
|
297
|
+
S: void 0,
|
|
298
|
+
C: (f, a) => f(...a)
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
};
|
|
302
|
+
|
|
303
|
+
// packages/ui/react-ui-editor/src/extensions/automerge/automerge.ts
|
|
304
|
+
var semaphoreFacet = Facet2.define({
|
|
305
|
+
combine: (values) => values.at(-1)
|
|
306
|
+
});
|
|
307
|
+
var automerge3 = ({ handle, path }) => {
|
|
308
|
+
const stateField = StateField.define({
|
|
309
|
+
create: () => ({
|
|
310
|
+
lastHeads: A.getHeads(handle.docSync()),
|
|
311
|
+
unreconciledTransactions: [],
|
|
312
|
+
path: path.slice()
|
|
313
|
+
}),
|
|
314
|
+
update: (value, tr) => {
|
|
315
|
+
const result = {
|
|
316
|
+
lastHeads: value.lastHeads,
|
|
317
|
+
unreconciledTransactions: value.unreconciledTransactions.slice(),
|
|
318
|
+
path: path.slice()
|
|
319
|
+
};
|
|
320
|
+
let clearUnreconciled = false;
|
|
321
|
+
for (const effect of tr.effects) {
|
|
322
|
+
if (effect.is(effectType)) {
|
|
323
|
+
result.lastHeads = effect.value.newHeads;
|
|
324
|
+
clearUnreconciled = true;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
if (clearUnreconciled) {
|
|
328
|
+
result.unreconciledTransactions = [];
|
|
329
|
+
} else {
|
|
330
|
+
if (!isReconcileTx(tr)) {
|
|
331
|
+
result.unreconciledTransactions.push(tr);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
return result;
|
|
335
|
+
}
|
|
336
|
+
});
|
|
337
|
+
const semaphore = new PatchSemaphore(stateField);
|
|
338
|
+
const viewPlugin = ViewPlugin.fromClass(class AutomergeCodemirrorViewPlugin {
|
|
339
|
+
constructor(_view) {
|
|
340
|
+
this._view = _view;
|
|
341
|
+
this._handleChange = () => {
|
|
342
|
+
this._view.state.facet(semaphoreFacet).reconcile(handle, this._view);
|
|
343
|
+
};
|
|
344
|
+
handle.addListener("change", this._handleChange);
|
|
345
|
+
}
|
|
346
|
+
update(update2) {
|
|
347
|
+
if (update2.transactions.length > 0 && update2.transactions.some((tr) => !isReconcileTx(tr))) {
|
|
348
|
+
queueMicrotask(() => {
|
|
349
|
+
this._view.state.facet(semaphoreFacet).reconcile(handle, this._view);
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
destroy() {
|
|
354
|
+
handle.addListener("change", this._handleChange);
|
|
355
|
+
}
|
|
356
|
+
});
|
|
357
|
+
return {
|
|
358
|
+
extension: [
|
|
359
|
+
CursorConverter.of(cursorConverter(handle, path)),
|
|
360
|
+
semaphoreFacet.of(semaphore),
|
|
361
|
+
stateField,
|
|
362
|
+
viewPlugin
|
|
363
|
+
]
|
|
364
|
+
};
|
|
365
|
+
};
|
|
366
|
+
|
|
367
|
+
// packages/ui/react-ui-editor/src/extensions/awareness.ts
|
|
368
|
+
import { Annotation as Annotation2, Facet as Facet3, RangeSet } from "@codemirror/state";
|
|
369
|
+
import { Decoration, EditorView, ViewPlugin as ViewPlugin2, WidgetType } from "@codemirror/view";
|
|
370
|
+
import { Event } from "@dxos/async";
|
|
371
|
+
import { Context } from "@dxos/context";
|
|
372
|
+
var dummyProvider = {
|
|
373
|
+
remoteStateChange: new Event(),
|
|
374
|
+
open: () => {
|
|
375
|
+
},
|
|
376
|
+
close: () => {
|
|
377
|
+
},
|
|
378
|
+
update: () => {
|
|
379
|
+
},
|
|
380
|
+
getRemoteStates: () => []
|
|
381
|
+
};
|
|
382
|
+
var AwarenessProvider = Facet3.define({
|
|
383
|
+
combine: (providers) => providers[0] ?? dummyProvider
|
|
384
|
+
});
|
|
385
|
+
var RemoteSelectionChangedAnnotation = Annotation2.define();
|
|
386
|
+
var awareness = (provider = dummyProvider) => {
|
|
387
|
+
return [
|
|
388
|
+
AwarenessProvider.of(provider),
|
|
389
|
+
ViewPlugin2.fromClass(RemoteSelectionsDecorator, {
|
|
390
|
+
decorations: (value) => value.decorations
|
|
391
|
+
}),
|
|
392
|
+
styles
|
|
393
|
+
];
|
|
394
|
+
};
|
|
395
|
+
var RemoteSelectionsDecorator = class {
|
|
396
|
+
constructor(view) {
|
|
397
|
+
this.decorations = RangeSet.of([]);
|
|
398
|
+
this._ctx = new Context();
|
|
399
|
+
this._lastAnchor = void 0;
|
|
400
|
+
this._lastHead = void 0;
|
|
401
|
+
this._cursorConverter = view.state.facet(CursorConverter);
|
|
402
|
+
this._provider = view.state.facet(AwarenessProvider);
|
|
403
|
+
this._provider.open();
|
|
404
|
+
this._provider.remoteStateChange.on(this._ctx, () => {
|
|
405
|
+
view.dispatch({
|
|
406
|
+
annotations: [
|
|
407
|
+
RemoteSelectionChangedAnnotation.of([])
|
|
408
|
+
]
|
|
409
|
+
});
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
destroy() {
|
|
413
|
+
void this._ctx.dispose();
|
|
414
|
+
this._provider.close();
|
|
415
|
+
}
|
|
416
|
+
update(update2) {
|
|
417
|
+
this._updateLocalSelection(update2);
|
|
418
|
+
this._updateRemoteSelections(update2);
|
|
419
|
+
}
|
|
420
|
+
_updateLocalSelection(update2) {
|
|
421
|
+
const hasFocus = update2.view.hasFocus && update2.view.dom.ownerDocument.hasFocus();
|
|
422
|
+
const { anchor = void 0, head = void 0 } = hasFocus ? update2.state.selection.main : {};
|
|
423
|
+
if (this._lastAnchor === anchor && this._lastHead === head) {
|
|
424
|
+
return;
|
|
425
|
+
}
|
|
426
|
+
this._lastAnchor = anchor;
|
|
427
|
+
this._lastHead = head;
|
|
428
|
+
this._provider.update(anchor !== void 0 && head !== void 0 ? {
|
|
429
|
+
anchor: this._cursorConverter.toCursor(anchor),
|
|
430
|
+
head: this._cursorConverter.toCursor(head)
|
|
431
|
+
} : void 0);
|
|
432
|
+
}
|
|
433
|
+
_updateRemoteSelections(update2) {
|
|
434
|
+
const decorations = [];
|
|
435
|
+
const awarenessStates = this._provider.getRemoteStates();
|
|
436
|
+
for (const state of awarenessStates) {
|
|
437
|
+
const anchor = state.position?.anchor ? this._cursorConverter.fromCursor(state.position.anchor) : null;
|
|
438
|
+
const head = state.position?.head ? this._cursorConverter.fromCursor(state.position.head) : null;
|
|
439
|
+
if (anchor == null || head == null) {
|
|
440
|
+
continue;
|
|
441
|
+
}
|
|
442
|
+
const start = Math.min(Math.min(anchor, head), update2.view.state.doc.length);
|
|
443
|
+
const end = Math.min(Math.max(anchor, head), update2.view.state.doc.length);
|
|
444
|
+
const startLine = update2.view.state.doc.lineAt(start);
|
|
445
|
+
const endLine = update2.view.state.doc.lineAt(end);
|
|
446
|
+
const color = state.info.color ?? "#30bced";
|
|
447
|
+
const lightColor = state.info.lightColor ?? color + "33";
|
|
448
|
+
if (startLine.number === endLine.number) {
|
|
449
|
+
decorations.push({
|
|
450
|
+
from: start,
|
|
451
|
+
to: end,
|
|
452
|
+
value: Decoration.mark({
|
|
453
|
+
attributes: {
|
|
454
|
+
style: `background-color: ${lightColor}`
|
|
455
|
+
},
|
|
456
|
+
class: "cm-ySelection"
|
|
457
|
+
})
|
|
458
|
+
});
|
|
459
|
+
} else {
|
|
460
|
+
decorations.push({
|
|
461
|
+
from: start,
|
|
462
|
+
to: startLine.from + startLine.length,
|
|
463
|
+
value: Decoration.mark({
|
|
464
|
+
attributes: {
|
|
465
|
+
style: `background-color: ${color}`
|
|
466
|
+
},
|
|
467
|
+
class: "cm-ySelection"
|
|
468
|
+
})
|
|
469
|
+
});
|
|
470
|
+
decorations.push({
|
|
471
|
+
from: endLine.from,
|
|
472
|
+
to: end,
|
|
473
|
+
value: Decoration.mark({
|
|
474
|
+
attributes: {
|
|
475
|
+
style: `background-color: ${color}`
|
|
476
|
+
},
|
|
477
|
+
class: "cm-ySelection"
|
|
478
|
+
})
|
|
479
|
+
});
|
|
480
|
+
for (let i = startLine.number + 1; i < endLine.number; i++) {
|
|
481
|
+
const linePos = update2.view.state.doc.line(i).from;
|
|
482
|
+
decorations.push({
|
|
483
|
+
from: linePos,
|
|
484
|
+
to: linePos,
|
|
485
|
+
value: Decoration.line({
|
|
486
|
+
attributes: {
|
|
487
|
+
style: `background-color: ${color}`,
|
|
488
|
+
class: "cm-yLineSelection"
|
|
489
|
+
}
|
|
490
|
+
})
|
|
491
|
+
});
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
decorations.push({
|
|
495
|
+
from: head,
|
|
496
|
+
to: head,
|
|
497
|
+
value: Decoration.widget({
|
|
498
|
+
side: head - anchor > 0 ? -1 : 1,
|
|
499
|
+
block: false,
|
|
500
|
+
widget: new RemoteCaretWidget(state.info.displayName ?? "Anonymous", color)
|
|
501
|
+
})
|
|
502
|
+
});
|
|
503
|
+
}
|
|
504
|
+
this.decorations = Decoration.set(decorations, true);
|
|
505
|
+
}
|
|
506
|
+
};
|
|
507
|
+
var RemoteCaretWidget = class extends WidgetType {
|
|
508
|
+
constructor(name, color) {
|
|
509
|
+
super();
|
|
510
|
+
this.name = name;
|
|
511
|
+
this.color = color;
|
|
512
|
+
this.name = name;
|
|
513
|
+
this.color = color;
|
|
514
|
+
}
|
|
515
|
+
toDOM() {
|
|
516
|
+
const span = document.createElement("span");
|
|
517
|
+
span.className = "cm-ySelectionCaret";
|
|
518
|
+
span.style.backgroundColor = this.color;
|
|
519
|
+
span.style.borderColor = this.color;
|
|
520
|
+
const dot = document.createElement("div");
|
|
521
|
+
dot.className = "cm-ySelectionCaretDot";
|
|
522
|
+
const info = document.createElement("div");
|
|
523
|
+
info.className = "cm-ySelectionInfo";
|
|
524
|
+
info.innerText = this.name;
|
|
525
|
+
span.appendChild(document.createTextNode("\u2060"));
|
|
526
|
+
span.appendChild(dot);
|
|
527
|
+
span.appendChild(document.createTextNode("\u2060"));
|
|
528
|
+
span.appendChild(info);
|
|
529
|
+
span.appendChild(document.createTextNode("\u2060"));
|
|
530
|
+
return span;
|
|
531
|
+
}
|
|
532
|
+
eq(widget) {
|
|
533
|
+
return widget.color === this.color;
|
|
534
|
+
}
|
|
535
|
+
compare(widget) {
|
|
536
|
+
return widget.color === this.color;
|
|
537
|
+
}
|
|
538
|
+
updateDOM() {
|
|
539
|
+
return false;
|
|
540
|
+
}
|
|
541
|
+
get estimatedHeight() {
|
|
542
|
+
return -1;
|
|
543
|
+
}
|
|
544
|
+
ignoreEvent() {
|
|
545
|
+
return true;
|
|
546
|
+
}
|
|
547
|
+
};
|
|
548
|
+
var styles = EditorView.baseTheme({
|
|
549
|
+
".cm-ySelection": {},
|
|
550
|
+
".cm-yLineSelection": {
|
|
551
|
+
padding: 0,
|
|
552
|
+
margin: "0px 2px 0px 4px"
|
|
553
|
+
},
|
|
554
|
+
".cm-ySelectionCaret": {
|
|
555
|
+
position: "relative",
|
|
556
|
+
borderLeft: "1px solid black",
|
|
557
|
+
borderRight: "1px solid black",
|
|
558
|
+
marginLeft: "-1px",
|
|
559
|
+
marginRight: "-1px",
|
|
560
|
+
boxSizing: "border-box",
|
|
561
|
+
display: "inline"
|
|
562
|
+
},
|
|
563
|
+
".cm-ySelectionCaretDot": {
|
|
564
|
+
borderRadius: "50%",
|
|
565
|
+
position: "absolute",
|
|
566
|
+
width: ".4em",
|
|
567
|
+
height: ".4em",
|
|
568
|
+
top: "-.2em",
|
|
569
|
+
left: "-.2em",
|
|
570
|
+
backgroundColor: "inherit",
|
|
571
|
+
transition: "transform .3s ease-in-out",
|
|
572
|
+
boxSizing: "border-box"
|
|
573
|
+
},
|
|
574
|
+
".cm-ySelectionCaret:hover > .cm-ySelectionCaretDot": {
|
|
575
|
+
transformOrigin: "bottom center",
|
|
576
|
+
transform: "scale(0)"
|
|
577
|
+
},
|
|
578
|
+
".cm-ySelectionInfo": {
|
|
579
|
+
position: "absolute",
|
|
580
|
+
top: "-1.05em",
|
|
581
|
+
left: "-1px",
|
|
582
|
+
fontSize: ".75em",
|
|
583
|
+
fontFamily: "serif",
|
|
584
|
+
fontStyle: "normal",
|
|
585
|
+
fontWeight: "normal",
|
|
586
|
+
lineHeight: "normal",
|
|
587
|
+
userSelect: "none",
|
|
588
|
+
color: "white",
|
|
589
|
+
paddingLeft: "2px",
|
|
590
|
+
paddingRight: "2px",
|
|
591
|
+
zIndex: 101,
|
|
592
|
+
transition: "opacity .3s ease-in-out",
|
|
593
|
+
backgroundColor: "inherit",
|
|
594
|
+
// these should be separate
|
|
595
|
+
opacity: 0,
|
|
596
|
+
transitionDelay: "0s",
|
|
597
|
+
whiteSpace: "nowrap"
|
|
598
|
+
},
|
|
599
|
+
".cm-ySelectionCaret:hover > .cm-ySelectionInfo": {
|
|
600
|
+
opacity: 1,
|
|
601
|
+
transitionDelay: "0s"
|
|
602
|
+
}
|
|
603
|
+
});
|
|
604
|
+
|
|
605
|
+
// packages/ui/react-ui-editor/src/extensions/basic.ts
|
|
42
606
|
import { closeBrackets } from "@codemirror/autocomplete";
|
|
43
607
|
import { bracketMatching, defaultHighlightStyle, syntaxHighlighting } from "@codemirror/language";
|
|
44
608
|
import { oneDarkHighlightStyle } from "@codemirror/theme-one-dark";
|
|
45
|
-
import { drawSelection, EditorView, placeholder } from "@codemirror/view";
|
|
609
|
+
import { drawSelection, EditorView as EditorView2, placeholder } from "@codemirror/view";
|
|
46
610
|
var basicBundle = ({ readonly, themeMode, placeholder: _placeholder }) => [
|
|
47
|
-
|
|
611
|
+
EditorView2.lineWrapping,
|
|
48
612
|
// TODO(burdon): Compare with minimalSetup.
|
|
49
613
|
// https://codemirror.net/docs/ref/#codemirror.minimalSetup
|
|
50
614
|
bracketMatching(),
|
|
@@ -55,11 +619,11 @@ var basicBundle = ({ readonly, themeMode, placeholder: _placeholder }) => [
|
|
|
55
619
|
themeMode === "dark" ? syntaxHighlighting(oneDarkHighlightStyle) : syntaxHighlighting(defaultHighlightStyle)
|
|
56
620
|
].filter(Boolean);
|
|
57
621
|
|
|
58
|
-
// packages/ui/react-ui-editor/src/
|
|
59
|
-
import { EditorView as
|
|
622
|
+
// packages/ui/react-ui-editor/src/extensions/blast.ts
|
|
623
|
+
import { EditorView as EditorView3, keymap as keymap2 } from "@codemirror/view";
|
|
60
624
|
import defaultsDeep from "lodash.defaultsdeep";
|
|
61
625
|
import { invariant } from "@dxos/invariant";
|
|
62
|
-
var
|
|
626
|
+
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/extensions/blast.ts";
|
|
63
627
|
var defaultOptions = {
|
|
64
628
|
effect: 2,
|
|
65
629
|
maxParticles: 200,
|
|
@@ -104,12 +668,12 @@ var blast = (options = defaultOptions) => {
|
|
|
104
668
|
};
|
|
105
669
|
return [
|
|
106
670
|
// Cursor moved.
|
|
107
|
-
|
|
108
|
-
if (blaster?.node !==
|
|
671
|
+
EditorView3.updateListener.of((update2) => {
|
|
672
|
+
if (blaster?.node !== update2.view.scrollDOM) {
|
|
109
673
|
if (blaster) {
|
|
110
674
|
blaster.destroy();
|
|
111
675
|
}
|
|
112
|
-
blaster = new Blaster(
|
|
676
|
+
blaster = new Blaster(update2.view.scrollDOM, defaultsDeep({
|
|
113
677
|
particleGravity: 0.2,
|
|
114
678
|
particleShrinkRate: 0.995,
|
|
115
679
|
color: () => [
|
|
@@ -123,10 +687,10 @@ var blast = (options = defaultOptions) => {
|
|
|
123
687
|
} else {
|
|
124
688
|
blaster.resize();
|
|
125
689
|
}
|
|
126
|
-
const current =
|
|
690
|
+
const current = update2.state.selection.main.head;
|
|
127
691
|
if (current !== last) {
|
|
128
692
|
last = current;
|
|
129
|
-
const { element, point } = getPoint(
|
|
693
|
+
const { element, point } = getPoint(update2.view, current - 1);
|
|
130
694
|
if (element && point) {
|
|
131
695
|
blaster.spawn({
|
|
132
696
|
element,
|
|
@@ -186,7 +750,7 @@ var Blaster = class {
|
|
|
186
750
|
}
|
|
187
751
|
initialize() {
|
|
188
752
|
invariant(!this._canvas && !this._ctx, void 0, {
|
|
189
|
-
F:
|
|
753
|
+
F: __dxlog_file2,
|
|
190
754
|
L: 138,
|
|
191
755
|
S: this,
|
|
192
756
|
A: [
|
|
@@ -223,7 +787,7 @@ var Blaster = class {
|
|
|
223
787
|
}
|
|
224
788
|
start() {
|
|
225
789
|
invariant(this._canvas && this._ctx, void 0, {
|
|
226
|
-
F:
|
|
790
|
+
F: __dxlog_file2,
|
|
227
791
|
L: 177,
|
|
228
792
|
S: this,
|
|
229
793
|
A: [
|
|
@@ -338,441 +902,38 @@ function throttle(callback, limit) {
|
|
|
338
902
|
wait = false;
|
|
339
903
|
}, limit);
|
|
340
904
|
}
|
|
341
|
-
};
|
|
342
|
-
}
|
|
343
|
-
var getRGBComponents = (node, color) => {
|
|
344
|
-
if (typeof color === "function") {
|
|
345
|
-
return color();
|
|
346
|
-
}
|
|
347
|
-
const bgColor = getComputedStyle(node).color;
|
|
348
|
-
if (bgColor) {
|
|
349
|
-
const x = bgColor.match(/(\d+), (\d+), (\d+)/)?.slice(1);
|
|
350
|
-
if (x) {
|
|
351
|
-
return x;
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
return [
|
|
355
|
-
50,
|
|
356
|
-
50,
|
|
357
|
-
50
|
|
358
|
-
];
|
|
359
|
-
};
|
|
360
|
-
var random = (min, max) => {
|
|
361
|
-
if (!max) {
|
|
362
|
-
max = min;
|
|
363
|
-
min = 0;
|
|
364
|
-
}
|
|
365
|
-
return min + ~~(Math.random() * (max - min + 1));
|
|
366
|
-
};
|
|
367
|
-
|
|
368
|
-
// packages/ui/react-ui-editor/src/components/TextEditor/extensions/code.ts
|
|
369
|
-
import { ViewPlugin, EditorView as EditorView3, Decoration } from "@codemirror/view";
|
|
370
|
-
import get from "lodash.get";
|
|
371
|
-
import { mx as mx2 } from "@dxos/react-ui-theme";
|
|
372
|
-
|
|
373
|
-
// packages/ui/react-ui-editor/src/styles/markdown.ts
|
|
374
|
-
import { mx } from "@dxos/react-ui-theme";
|
|
375
|
-
var headings = {
|
|
376
|
-
1: [
|
|
377
|
-
"mbs-4 mbe-2 font-medium text-inherit no-underline text-4xl",
|
|
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
|
-
]
|
|
400
|
-
};
|
|
401
|
-
var heading = (level, readonly) => {
|
|
402
|
-
const [style, offset] = headings[level];
|
|
403
|
-
return mx(style, readonly && offset);
|
|
404
|
-
};
|
|
405
|
-
var light = "text-neutral-200 dark:text-neutral-800";
|
|
406
|
-
var mark = mx("!font-normal !no-underline !text-inherit opacity-40", light);
|
|
407
|
-
var bold = "font-bold";
|
|
408
|
-
var italic = "italic";
|
|
409
|
-
var strikethrough = "line-through";
|
|
410
|
-
var code = "font-mono !no-underline text-neutral-700 dark:text-neutral-300";
|
|
411
|
-
var codeMark = "font-mono text-primary-500";
|
|
412
|
-
var inlineUrl = mx(code, "px-1");
|
|
413
|
-
var blockquote = mx("pl-1 mr-1 border-is-4 border-primary-500/70 dark:border-primary-500/30", light);
|
|
414
|
-
|
|
415
|
-
// packages/ui/react-ui-editor/src/styles/tokens.ts
|
|
416
|
-
import { tailwindConfig } from "@dxos/react-ui-theme";
|
|
417
|
-
var tokens = tailwindConfig({}).theme;
|
|
418
|
-
|
|
419
|
-
// packages/ui/react-ui-editor/src/components/TextEditor/extensions/code.ts
|
|
420
|
-
var CODE_REGEX = /```[\s\S]*?```/gs;
|
|
421
|
-
var styles = EditorView3.baseTheme({
|
|
422
|
-
"& .cm-codeblock": {
|
|
423
|
-
fontFamily: get(tokens, "fontFamily.mono", []).join(",")
|
|
424
|
-
},
|
|
425
|
-
'&light [aria-readonly="true"] .cm-codeblock': {
|
|
426
|
-
background: get(tokens, "extend.colors.neutral.50")
|
|
427
|
-
},
|
|
428
|
-
'&dark [aria-readonly="true"] .cm-codeblock': {
|
|
429
|
-
background: get(tokens, "extend.colors.neutral.850")
|
|
430
|
-
},
|
|
431
|
-
'& [aria-readonly="true"] .cm-codeblock': {
|
|
432
|
-
display: "block",
|
|
433
|
-
paddingInline: "4px !important"
|
|
434
|
-
},
|
|
435
|
-
'& [aria-readonly="true"] .cm-codeblock-first': {
|
|
436
|
-
paddingTop: "4px !important",
|
|
437
|
-
borderTopLeftRadius: "4px",
|
|
438
|
-
borderTopRightRadius: "4px"
|
|
439
|
-
},
|
|
440
|
-
'& [aria-readonly="true"] .cm-codeblock-last': {
|
|
441
|
-
paddingBottom: "4px !important",
|
|
442
|
-
borderBottomLeftRadius: "4px",
|
|
443
|
-
borderBottomRightRadius: "4px"
|
|
444
|
-
}
|
|
445
|
-
});
|
|
446
|
-
var getLineRange = (lines, from, to) => {
|
|
447
|
-
const start = lines.findIndex((line) => line.from >= from);
|
|
448
|
-
const end = lines.findIndex((line) => line.to >= to);
|
|
449
|
-
return [
|
|
450
|
-
start,
|
|
451
|
-
end
|
|
452
|
-
];
|
|
453
|
-
};
|
|
454
|
-
var code2 = () => {
|
|
455
|
-
const getDecorations = (view) => {
|
|
456
|
-
const decorations = [];
|
|
457
|
-
if (view.state.readOnly) {
|
|
458
|
-
const text = view.state.doc.sliceString(0);
|
|
459
|
-
const matches = text.matchAll(CODE_REGEX);
|
|
460
|
-
const blocks = view.viewportLineBlocks;
|
|
461
|
-
for (const match of matches) {
|
|
462
|
-
const range = getLineRange(blocks, match.index, match.index + match[0].length);
|
|
463
|
-
for (let i = range[0]; i <= range[1]; i++) {
|
|
464
|
-
const block = blocks[i];
|
|
465
|
-
decorations.push(Decoration.line({
|
|
466
|
-
class: mx2("cm-codeblock", i === range[0] && "cm-codeblock-first", i === range[1] && "cm-codeblock-last")
|
|
467
|
-
}).range(block.from));
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
return Decoration.set(decorations);
|
|
472
|
-
};
|
|
473
|
-
return [
|
|
474
|
-
ViewPlugin.fromClass(class {
|
|
475
|
-
constructor(view) {
|
|
476
|
-
this.decorations = getDecorations(view);
|
|
477
|
-
}
|
|
478
|
-
update(update4) {
|
|
479
|
-
if (update4.docChanged || update4.viewportChanged) {
|
|
480
|
-
this.decorations = getDecorations(update4.view);
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
}, {
|
|
484
|
-
decorations: (value) => value.decorations
|
|
485
|
-
}),
|
|
486
|
-
styles
|
|
487
|
-
];
|
|
488
|
-
};
|
|
489
|
-
|
|
490
|
-
// packages/ui/react-ui-editor/src/components/TextEditor/extensions/comments.ts
|
|
491
|
-
import { StateEffect as StateEffect2, StateField as StateField3 } from "@codemirror/state";
|
|
492
|
-
import { hoverTooltip, keymap as keymap3, Decoration as Decoration2, EditorView as EditorView4, MatchDecorator, ViewPlugin as ViewPlugin3, WidgetType } from "@codemirror/view";
|
|
493
|
-
import sortBy from "lodash.sortby";
|
|
494
|
-
import { debounce } from "@dxos/async";
|
|
495
|
-
import { invariant as invariant3 } from "@dxos/invariant";
|
|
496
|
-
import { log as log3 } from "@dxos/log";
|
|
497
|
-
import { nonNullable } from "@dxos/util";
|
|
498
|
-
|
|
499
|
-
// packages/ui/react-ui-editor/src/components/TextEditor/extensions/util.ts
|
|
500
|
-
import { log } from "@dxos/log";
|
|
501
|
-
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/components/TextEditor/extensions/util.ts";
|
|
502
|
-
var callbackWrapper = (fn) => (...args) => {
|
|
503
|
-
try {
|
|
504
|
-
return fn(...args);
|
|
505
|
-
} catch (error) {
|
|
506
|
-
log.catch(error, void 0, {
|
|
507
|
-
F: __dxlog_file2,
|
|
508
|
-
L: 16,
|
|
509
|
-
S: void 0,
|
|
510
|
-
C: (f, a) => f(...a)
|
|
511
|
-
});
|
|
512
|
-
}
|
|
513
|
-
};
|
|
514
|
-
|
|
515
|
-
// packages/ui/react-ui-editor/src/hooks/useTextModel.ts
|
|
516
|
-
import { StateField as StateField2 } from "@codemirror/state";
|
|
517
|
-
import get2 from "lodash.get";
|
|
518
|
-
import { useEffect, useState } from "react";
|
|
519
|
-
import { yCollab } from "y-codemirror.next";
|
|
520
|
-
import * as Y from "yjs";
|
|
521
|
-
import { invariant as invariant2 } from "@dxos/invariant";
|
|
522
|
-
import { getRawDoc, isActualAutomergeObject } from "@dxos/react-client/echo";
|
|
523
|
-
import { arrayToString, stringToArray } from "@dxos/util";
|
|
524
|
-
|
|
525
|
-
// packages/ui/react-ui-editor/src/hooks/automerge/plugin.ts
|
|
526
|
-
import { Annotation, Facet, StateEffect, StateField } from "@codemirror/state";
|
|
527
|
-
import { ViewPlugin as ViewPlugin2 } from "@codemirror/view";
|
|
528
|
-
import * as automerge2 from "@dxos/automerge/automerge";
|
|
529
|
-
|
|
530
|
-
// packages/ui/react-ui-editor/src/hooks/automerge/semaphore.ts
|
|
531
|
-
import { next as automerge } from "@dxos/automerge/automerge";
|
|
532
|
-
|
|
533
|
-
// packages/ui/react-ui-editor/src/hooks/automerge/update-automerge.ts
|
|
534
|
-
import { next as am } from "@dxos/automerge/automerge";
|
|
535
|
-
var updateAutomerge = (field, handle, transactions, state) => {
|
|
536
|
-
const { lastHeads, path } = state.field(field);
|
|
537
|
-
let hasChanges = false;
|
|
538
|
-
for (const tr of transactions) {
|
|
539
|
-
tr.changes.iterChanges(() => {
|
|
540
|
-
hasChanges = true;
|
|
541
|
-
});
|
|
542
|
-
}
|
|
543
|
-
if (!hasChanges) {
|
|
544
|
-
return void 0;
|
|
545
|
-
}
|
|
546
|
-
const newHeads = handle.changeAt(lastHeads, (doc) => {
|
|
547
|
-
for (const tr of transactions) {
|
|
548
|
-
tr.changes.iterChanges((fromA, toA, _fromB, _toB, inserted) => {
|
|
549
|
-
am.splice(doc, path, fromA, toA - fromA, inserted.toString());
|
|
550
|
-
});
|
|
551
|
-
}
|
|
552
|
-
});
|
|
553
|
-
return newHeads ?? void 0;
|
|
554
|
-
};
|
|
555
|
-
|
|
556
|
-
// packages/ui/react-ui-editor/src/hooks/automerge/update-codemirror.ts
|
|
557
|
-
import { ChangeSet } from "@codemirror/state";
|
|
558
|
-
var updateCodeMirror = (view, selection, target, patches) => {
|
|
559
|
-
for (const patch of patches) {
|
|
560
|
-
const changeSpec = handlePatch(patch, target, view.state);
|
|
561
|
-
if (changeSpec != null) {
|
|
562
|
-
const changeSet = ChangeSet.of(changeSpec, view.state.doc.length, "\n");
|
|
563
|
-
selection = selection.map(changeSet, 1);
|
|
564
|
-
view.dispatch({
|
|
565
|
-
changes: changeSet,
|
|
566
|
-
annotations: reconcileAnnotationType.of({})
|
|
567
|
-
});
|
|
568
|
-
}
|
|
569
|
-
}
|
|
570
|
-
view.dispatch({
|
|
571
|
-
selection,
|
|
572
|
-
annotations: reconcileAnnotationType.of({})
|
|
573
|
-
});
|
|
574
|
-
};
|
|
575
|
-
var handlePatch = (patch, target, state) => {
|
|
576
|
-
if (patch.action === "insert") {
|
|
577
|
-
return handleInsert(target, patch);
|
|
578
|
-
} else if (patch.action === "splice") {
|
|
579
|
-
return handleSplice(target, patch);
|
|
580
|
-
} else if (patch.action === "del") {
|
|
581
|
-
return handleDel(target, patch);
|
|
582
|
-
} else if (patch.action === "put") {
|
|
583
|
-
return handlePut(target, patch, state);
|
|
584
|
-
} else {
|
|
585
|
-
return null;
|
|
586
|
-
}
|
|
587
|
-
};
|
|
588
|
-
var handleInsert = (target, patch) => {
|
|
589
|
-
const index = charPath(target, patch.path);
|
|
590
|
-
if (index == null) {
|
|
591
|
-
return [];
|
|
592
|
-
}
|
|
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
|
-
};
|
|
602
|
-
var handleSplice = (target, patch) => {
|
|
603
|
-
const index = charPath(target, patch.path);
|
|
604
|
-
if (index == null) {
|
|
605
|
-
return [];
|
|
606
|
-
}
|
|
607
|
-
return [
|
|
608
|
-
{
|
|
609
|
-
from: index,
|
|
610
|
-
insert: patch.value
|
|
611
|
-
}
|
|
612
|
-
];
|
|
613
|
-
};
|
|
614
|
-
var handleDel = (target, patch) => {
|
|
615
|
-
const index = charPath(target, patch.path);
|
|
616
|
-
if (index == null) {
|
|
617
|
-
return [];
|
|
905
|
+
};
|
|
906
|
+
}
|
|
907
|
+
var getRGBComponents = (node, color) => {
|
|
908
|
+
if (typeof color === "function") {
|
|
909
|
+
return color();
|
|
618
910
|
}
|
|
619
|
-
const
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
911
|
+
const bgColor = getComputedStyle(node).color;
|
|
912
|
+
if (bgColor) {
|
|
913
|
+
const x = bgColor.match(/(\d+), (\d+), (\d+)/)?.slice(1);
|
|
914
|
+
if (x) {
|
|
915
|
+
return x;
|
|
624
916
|
}
|
|
625
|
-
];
|
|
626
|
-
};
|
|
627
|
-
var handlePut = (target, patch, state) => {
|
|
628
|
-
const index = charPath(target, [
|
|
629
|
-
...patch.path,
|
|
630
|
-
0
|
|
631
|
-
]);
|
|
632
|
-
if (index == null) {
|
|
633
|
-
return [];
|
|
634
|
-
}
|
|
635
|
-
const length = state.doc.length;
|
|
636
|
-
if (typeof patch.value !== "string") {
|
|
637
|
-
return [];
|
|
638
917
|
}
|
|
639
918
|
return [
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
insert: patch.value
|
|
644
|
-
}
|
|
919
|
+
50,
|
|
920
|
+
50,
|
|
921
|
+
50
|
|
645
922
|
];
|
|
646
923
|
};
|
|
647
|
-
var
|
|
648
|
-
if (
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
for (let i = 0; i < textPath.length; i++) {
|
|
652
|
-
if (textPath[i] !== candidatePath[i]) {
|
|
653
|
-
return null;
|
|
654
|
-
}
|
|
655
|
-
}
|
|
656
|
-
const index = candidatePath[candidatePath.length - 1];
|
|
657
|
-
if (typeof index === "number") {
|
|
658
|
-
return index;
|
|
659
|
-
}
|
|
660
|
-
return null;
|
|
661
|
-
};
|
|
662
|
-
|
|
663
|
-
// packages/ui/react-ui-editor/src/hooks/automerge/semaphore.ts
|
|
664
|
-
var PatchSemaphore = class {
|
|
665
|
-
constructor(field) {
|
|
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
|
-
}
|
|
924
|
+
var random = (min, max) => {
|
|
925
|
+
if (!max) {
|
|
926
|
+
max = min;
|
|
927
|
+
min = 0;
|
|
701
928
|
}
|
|
929
|
+
return min + ~~(Math.random() * (max - min + 1));
|
|
702
930
|
};
|
|
703
931
|
|
|
704
|
-
// packages/ui/react-ui-editor/src/
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
newHeads
|
|
708
|
-
});
|
|
709
|
-
var getLastHeads = (state, field) => state.field(field).lastHeads;
|
|
710
|
-
var getPath = (state, field) => state.field(field).path;
|
|
711
|
-
var semaphoreFacet = Facet.define({
|
|
712
|
-
combine: (values) => values.at(-1)
|
|
713
|
-
});
|
|
714
|
-
var automergePlugin = (handle, path) => {
|
|
715
|
-
const stateField = StateField.define({
|
|
716
|
-
create: () => ({
|
|
717
|
-
lastHeads: automerge2.getHeads(handle.docSync()),
|
|
718
|
-
unreconciledTransactions: [],
|
|
719
|
-
path: path.slice()
|
|
720
|
-
}),
|
|
721
|
-
update: (value, tr) => {
|
|
722
|
-
const result = {
|
|
723
|
-
lastHeads: value.lastHeads,
|
|
724
|
-
unreconciledTransactions: value.unreconciledTransactions.slice(),
|
|
725
|
-
path: path.slice()
|
|
726
|
-
};
|
|
727
|
-
let clearUnreconciled = false;
|
|
728
|
-
for (const effect of tr.effects) {
|
|
729
|
-
if (effect.is(effectType)) {
|
|
730
|
-
result.lastHeads = effect.value.newHeads;
|
|
731
|
-
clearUnreconciled = true;
|
|
732
|
-
}
|
|
733
|
-
}
|
|
734
|
-
if (clearUnreconciled) {
|
|
735
|
-
result.unreconciledTransactions = [];
|
|
736
|
-
} else {
|
|
737
|
-
if (!isReconcileTx(tr)) {
|
|
738
|
-
result.unreconciledTransactions.push(tr);
|
|
739
|
-
}
|
|
740
|
-
}
|
|
741
|
-
return result;
|
|
742
|
-
}
|
|
743
|
-
});
|
|
744
|
-
const semaphore = new PatchSemaphore(stateField);
|
|
745
|
-
const viewPlugin = ViewPlugin2.fromClass(class AutomergeCodemirrorViewPlugin {
|
|
746
|
-
constructor(view) {
|
|
747
|
-
this._handleChange = () => {
|
|
748
|
-
this._view.state.facet(semaphoreFacet).reconcile(handle, this._view);
|
|
749
|
-
};
|
|
750
|
-
this._view = view;
|
|
751
|
-
handle.addListener("change", this._handleChange);
|
|
752
|
-
}
|
|
753
|
-
update(update4) {
|
|
754
|
-
if (update4.transactions.length > 0 && update4.transactions.some((t) => !isReconcileTx(t))) {
|
|
755
|
-
queueMicrotask(() => {
|
|
756
|
-
this._view.state.facet(semaphoreFacet).reconcile(handle, this._view);
|
|
757
|
-
});
|
|
758
|
-
}
|
|
759
|
-
}
|
|
760
|
-
destroy() {
|
|
761
|
-
handle.addListener("change", this._handleChange);
|
|
762
|
-
}
|
|
763
|
-
});
|
|
764
|
-
return {
|
|
765
|
-
extension: [
|
|
766
|
-
stateField,
|
|
767
|
-
semaphoreFacet.of(semaphore),
|
|
768
|
-
viewPlugin
|
|
769
|
-
]
|
|
770
|
-
};
|
|
771
|
-
};
|
|
772
|
-
var reconcileAnnotationType = Annotation.define();
|
|
773
|
-
var isReconcileTx = (tr) => !!tr.annotation(reconcileAnnotationType);
|
|
932
|
+
// packages/ui/react-ui-editor/src/extensions/code.ts
|
|
933
|
+
import { ViewPlugin as ViewPlugin3, EditorView as EditorView4, Decoration as Decoration2 } from "@codemirror/view";
|
|
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,135 @@ 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
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
void this._space.postMessage(this._channel, encoding.toUint8Array(encoderAwarenessState));
|
|
845
|
-
}
|
|
846
|
-
get awareness() {
|
|
847
|
-
return this._awareness;
|
|
848
|
-
}
|
|
849
|
-
_handleAwarenessUpdate({ added, updated, removed }, origin) {
|
|
850
|
-
log2("awareness update", {
|
|
851
|
-
added,
|
|
852
|
-
updated,
|
|
853
|
-
removed,
|
|
854
|
-
origin
|
|
855
|
-
}, {
|
|
856
|
-
F: __dxlog_file3,
|
|
857
|
-
L: 67,
|
|
858
|
-
S: this,
|
|
859
|
-
C: (f, a) => f(...a)
|
|
860
|
-
});
|
|
861
|
-
const changedClients = added.concat(updated).concat(removed);
|
|
862
|
-
const encoderAwareness = encoding.createEncoder();
|
|
863
|
-
encoding.writeVarUint(encoderAwareness, messageAwareness);
|
|
864
|
-
encoding.writeVarUint8Array(encoderAwareness, awarenessProtocol.encodeAwarenessUpdate(this._awareness, changedClients));
|
|
865
|
-
void this._space.postMessage(this._channel, encoding.toUint8Array(encoderAwareness));
|
|
866
|
-
}
|
|
867
|
-
_handleSpaceMessage({ payload }) {
|
|
868
|
-
log2("space message", payload, {
|
|
869
|
-
F: __dxlog_file3,
|
|
870
|
-
L: 79,
|
|
871
|
-
S: this,
|
|
872
|
-
C: (f, a) => f(...a)
|
|
873
|
-
});
|
|
874
|
-
const data = new Uint8Array(Array.from(Object.values(payload)));
|
|
875
|
-
const encoder = this._readMessage(data);
|
|
876
|
-
if (encoder) {
|
|
877
|
-
void this._space.postMessage(this._channel, encoding.toUint8Array(encoder));
|
|
878
|
-
}
|
|
879
|
-
}
|
|
880
|
-
_readMessage(message) {
|
|
881
|
-
const decoder = decoding.createDecoder(message);
|
|
882
|
-
const encoder = encoding.createEncoder();
|
|
883
|
-
const messageType = decoding.readVarUint(decoder);
|
|
884
|
-
let sendReply = false;
|
|
885
|
-
switch (messageType) {
|
|
886
|
-
case messageAwareness: {
|
|
887
|
-
awarenessProtocol.applyAwarenessUpdate(this._awareness, decoding.readVarUint8Array(decoder), this);
|
|
888
|
-
break;
|
|
889
|
-
}
|
|
890
|
-
case messageQueryAwareness: {
|
|
891
|
-
encoding.writeVarUint(encoder, messageAwareness);
|
|
892
|
-
encoding.writeVarUint8Array(encoder, awarenessProtocol.encodeAwarenessUpdate(this._awareness, Array.from(this._awareness.getStates().keys())));
|
|
893
|
-
sendReply = true;
|
|
894
|
-
break;
|
|
895
|
-
}
|
|
896
|
-
default: {
|
|
897
|
-
console.error("Invalid message:", messageType);
|
|
898
|
-
return encoder;
|
|
899
|
-
}
|
|
900
|
-
}
|
|
901
|
-
if (!sendReply) {
|
|
902
|
-
return null;
|
|
903
|
-
}
|
|
904
|
-
return encoder;
|
|
905
|
-
}
|
|
906
|
-
_handleBeforeUnload() {
|
|
907
|
-
awarenessProtocol.removeAwarenessStates(this._awareness, [
|
|
908
|
-
this._clientId
|
|
909
|
-
], "window unload");
|
|
910
|
-
}
|
|
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
|
+
]
|
|
1001
|
+
};
|
|
1002
|
+
var heading = (level, readonly) => {
|
|
1003
|
+
const [style, offset] = headings[level];
|
|
1004
|
+
return mx(style, readonly && offset);
|
|
911
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
|
-
|
|
916
|
-
|
|
917
|
-
|
|
1016
|
+
// packages/ui/react-ui-editor/src/styles/tokens.ts
|
|
1017
|
+
import get2 from "lodash.get";
|
|
1018
|
+
import { tailwindConfig } from "@dxos/react-ui-theme";
|
|
1019
|
+
var tokens = tailwindConfig({}).theme;
|
|
1020
|
+
var getToken = (path, defaultValue = void 0) => get2(tokens, path, defaultValue);
|
|
1021
|
+
|
|
1022
|
+
// packages/ui/react-ui-editor/src/extensions/code.ts
|
|
1023
|
+
var CODE_REGEX = /```[\s\S]*?```/gs;
|
|
1024
|
+
var styles2 = EditorView4.baseTheme({
|
|
1025
|
+
"& .cm-codeblock": {
|
|
1026
|
+
fontFamily: getToken("fontFamily.mono", []).join(",")
|
|
1027
|
+
},
|
|
1028
|
+
'&light [aria-readonly="true"] .cm-codeblock': {
|
|
1029
|
+
background: getToken("extend.colors.neutral.50")
|
|
1030
|
+
},
|
|
1031
|
+
'&dark [aria-readonly="true"] .cm-codeblock': {
|
|
1032
|
+
background: getToken("extend.colors.neutral.850")
|
|
1033
|
+
},
|
|
1034
|
+
'& [aria-readonly="true"] .cm-codeblock': {
|
|
1035
|
+
display: "block",
|
|
1036
|
+
paddingInline: "4px !important"
|
|
1037
|
+
},
|
|
1038
|
+
'& [aria-readonly="true"] .cm-codeblock-first': {
|
|
1039
|
+
paddingTop: "4px !important",
|
|
1040
|
+
borderTopLeftRadius: "4px",
|
|
1041
|
+
borderTopRightRadius: "4px"
|
|
1042
|
+
},
|
|
1043
|
+
'& [aria-readonly="true"] .cm-codeblock-last': {
|
|
1044
|
+
paddingBottom: "4px !important",
|
|
1045
|
+
borderBottomLeftRadius: "4px",
|
|
1046
|
+
borderBottomRightRadius: "4px"
|
|
1047
|
+
}
|
|
918
1048
|
});
|
|
919
|
-
var
|
|
920
|
-
const
|
|
921
|
-
const
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
]);
|
|
927
|
-
return model;
|
|
1049
|
+
var getLineRange = (lines, from, to) => {
|
|
1050
|
+
const start = lines.findIndex((line) => line.from >= from);
|
|
1051
|
+
const end = lines.findIndex((line) => line.to >= to);
|
|
1052
|
+
return [
|
|
1053
|
+
start,
|
|
1054
|
+
end
|
|
1055
|
+
];
|
|
928
1056
|
};
|
|
929
|
-
var
|
|
930
|
-
const
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
1057
|
+
var code2 = () => {
|
|
1058
|
+
const getDecorations = (view) => {
|
|
1059
|
+
const decorations = [];
|
|
1060
|
+
if (view.state.readOnly) {
|
|
1061
|
+
const text = view.state.doc.sliceString(0);
|
|
1062
|
+
const matches = text.matchAll(CODE_REGEX);
|
|
1063
|
+
const blocks = view.viewportLineBlocks;
|
|
1064
|
+
for (const match of matches) {
|
|
1065
|
+
const range = getLineRange(blocks, match.index, match.index + match[0].length);
|
|
1066
|
+
for (let i = range[0]; i <= range[1]; i++) {
|
|
1067
|
+
const block = blocks[i];
|
|
1068
|
+
decorations.push(Decoration2.line({
|
|
1069
|
+
class: mx2("cm-codeblock", i === range[0] && "cm-codeblock-first", i === range[1] && "cm-codeblock-last")
|
|
1070
|
+
}).range(block.from));
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
936
1073
|
}
|
|
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
|
|
1074
|
+
return Decoration2.set(decorations);
|
|
1007
1075
|
};
|
|
1008
|
-
return
|
|
1076
|
+
return [
|
|
1077
|
+
ViewPlugin3.fromClass(class {
|
|
1078
|
+
constructor(view) {
|
|
1079
|
+
this.decorations = getDecorations(view);
|
|
1080
|
+
}
|
|
1081
|
+
update(update2) {
|
|
1082
|
+
if (update2.docChanged || update2.viewportChanged) {
|
|
1083
|
+
this.decorations = getDecorations(update2.view);
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1086
|
+
}, {
|
|
1087
|
+
decorations: (value) => value.decorations
|
|
1088
|
+
}),
|
|
1089
|
+
styles2
|
|
1090
|
+
];
|
|
1009
1091
|
};
|
|
1010
1092
|
|
|
1011
|
-
// packages/ui/react-ui-editor/src/
|
|
1012
|
-
|
|
1013
|
-
|
|
1093
|
+
// packages/ui/react-ui-editor/src/extensions/comments.ts
|
|
1094
|
+
import { StateEffect as StateEffect2, StateField as StateField2 } from "@codemirror/state";
|
|
1095
|
+
import { hoverTooltip, keymap as keymap3, Decoration as Decoration3, EditorView as EditorView5, MatchDecorator, ViewPlugin as ViewPlugin4, WidgetType as WidgetType2 } from "@codemirror/view";
|
|
1096
|
+
import sortBy from "lodash.sortby";
|
|
1097
|
+
import { debounce } from "@dxos/async";
|
|
1098
|
+
import { invariant as invariant2 } from "@dxos/invariant";
|
|
1099
|
+
import { log as log2 } from "@dxos/log";
|
|
1100
|
+
import { nonNullable } from "@dxos/util";
|
|
1101
|
+
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/extensions/comments.ts";
|
|
1102
|
+
var styles3 = EditorView5.baseTheme({
|
|
1014
1103
|
"& .cm-bookmark": {
|
|
1015
1104
|
cursor: "pointer",
|
|
1016
1105
|
margin: "4px",
|
|
@@ -1021,28 +1110,44 @@ var styles2 = EditorView4.baseTheme({
|
|
|
1021
1110
|
backgroundColor: "orange"
|
|
1022
1111
|
},
|
|
1023
1112
|
"& .cm-comment": {
|
|
1024
|
-
backgroundColor: "yellow"
|
|
1113
|
+
backgroundColor: getToken("extend.colors.yellow.50")
|
|
1025
1114
|
},
|
|
1026
1115
|
"& .cm-comment-active": {
|
|
1027
|
-
backgroundColor: "
|
|
1116
|
+
backgroundColor: getToken("extend.colors.yellow.100")
|
|
1028
1117
|
}
|
|
1029
1118
|
});
|
|
1030
1119
|
var marks = {
|
|
1031
|
-
highlight:
|
|
1120
|
+
highlight: Decoration3.mark({
|
|
1032
1121
|
class: "cm-comment"
|
|
1033
1122
|
}),
|
|
1034
|
-
highlightActive:
|
|
1123
|
+
highlightActive: Decoration3.mark({
|
|
1035
1124
|
class: "cm-comment-active"
|
|
1036
1125
|
})
|
|
1037
1126
|
};
|
|
1127
|
+
var setFocus = (view, thread) => {
|
|
1128
|
+
const range = view.state.field(commentsStateField).ranges.find((range2) => range2.id === thread);
|
|
1129
|
+
if (!range) {
|
|
1130
|
+
return;
|
|
1131
|
+
}
|
|
1132
|
+
view.dispatch({
|
|
1133
|
+
effects: setSelection.of({
|
|
1134
|
+
active: thread
|
|
1135
|
+
}),
|
|
1136
|
+
selection: {
|
|
1137
|
+
anchor: range.from
|
|
1138
|
+
},
|
|
1139
|
+
scrollIntoView: true
|
|
1140
|
+
});
|
|
1141
|
+
};
|
|
1038
1142
|
var setCommentRange = StateEffect2.define();
|
|
1039
1143
|
var setSelection = StateEffect2.define();
|
|
1040
1144
|
var setCommentState = StateEffect2.define();
|
|
1041
|
-
var commentsStateField =
|
|
1145
|
+
var commentsStateField = StateField2.define({
|
|
1042
1146
|
create: () => ({
|
|
1043
1147
|
ranges: []
|
|
1044
1148
|
}),
|
|
1045
1149
|
update: (value, tr) => {
|
|
1150
|
+
const cursorConverter3 = tr.state.facet(CursorConverter);
|
|
1046
1151
|
for (const effect of tr.effects) {
|
|
1047
1152
|
if (effect.is(setSelection)) {
|
|
1048
1153
|
return {
|
|
@@ -1051,14 +1156,14 @@ var commentsStateField = StateField3.define({
|
|
|
1051
1156
|
};
|
|
1052
1157
|
}
|
|
1053
1158
|
if (effect.is(setCommentRange)) {
|
|
1054
|
-
const {
|
|
1159
|
+
const { comments: comments2 } = effect.value;
|
|
1055
1160
|
const ranges = comments2.map((comment) => {
|
|
1056
|
-
const range =
|
|
1057
|
-
return {
|
|
1161
|
+
const range = getRangeFromCursor(cursorConverter3, comment.cursor);
|
|
1162
|
+
return range && {
|
|
1058
1163
|
...comment,
|
|
1059
1164
|
...range
|
|
1060
1165
|
};
|
|
1061
|
-
});
|
|
1166
|
+
}).filter(nonNullable);
|
|
1062
1167
|
return {
|
|
1063
1168
|
...value,
|
|
1064
1169
|
ranges
|
|
@@ -1071,7 +1176,7 @@ var commentsStateField = StateField3.define({
|
|
|
1071
1176
|
return value;
|
|
1072
1177
|
}
|
|
1073
1178
|
});
|
|
1074
|
-
var highlightDecorations =
|
|
1179
|
+
var highlightDecorations = EditorView5.decorations.compute([
|
|
1075
1180
|
commentsStateField
|
|
1076
1181
|
], (state) => {
|
|
1077
1182
|
const { active, ranges } = state.field(commentsStateField);
|
|
@@ -1089,17 +1194,17 @@ var highlightDecorations = EditorView4.decorations.compute([
|
|
|
1089
1194
|
return marks.highlight.range(range.from, range.to);
|
|
1090
1195
|
}
|
|
1091
1196
|
}).filter(nonNullable) ?? [];
|
|
1092
|
-
return
|
|
1197
|
+
return Decoration3.set(decorations);
|
|
1093
1198
|
});
|
|
1094
|
-
var BookmarkWidget = class extends
|
|
1199
|
+
var BookmarkWidget = class extends WidgetType2 {
|
|
1095
1200
|
constructor(_anchor, _id, _handleClick) {
|
|
1096
1201
|
super();
|
|
1097
1202
|
this._anchor = _anchor;
|
|
1098
1203
|
this._id = _id;
|
|
1099
1204
|
this._handleClick = _handleClick;
|
|
1100
|
-
|
|
1101
|
-
F:
|
|
1102
|
-
L:
|
|
1205
|
+
invariant2(this._id, void 0, {
|
|
1206
|
+
F: __dxlog_file3,
|
|
1207
|
+
L: 168,
|
|
1103
1208
|
S: this,
|
|
1104
1209
|
A: [
|
|
1105
1210
|
"this._id",
|
|
@@ -1123,9 +1228,10 @@ var BookmarkWidget = class extends WidgetType {
|
|
|
1123
1228
|
var comments = (options = {}) => {
|
|
1124
1229
|
const handleSelect = debounce((state) => options.onSelect?.(state), 200);
|
|
1125
1230
|
const createCommentThread = (view) => {
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1231
|
+
const cursorConverter3 = view.state.facet(CursorConverter);
|
|
1232
|
+
invariant2(options.onCreate, void 0, {
|
|
1233
|
+
F: __dxlog_file3,
|
|
1234
|
+
L: 224,
|
|
1129
1235
|
S: void 0,
|
|
1130
1236
|
A: [
|
|
1131
1237
|
"options.onCreate",
|
|
@@ -1136,8 +1242,7 @@ var comments = (options = {}) => {
|
|
|
1136
1242
|
if (from === to) {
|
|
1137
1243
|
return false;
|
|
1138
1244
|
}
|
|
1139
|
-
const
|
|
1140
|
-
const relPos = model?.getCursorFromRange?.({
|
|
1245
|
+
const relPos = getCursorFromRange(cursorConverter3, {
|
|
1141
1246
|
from,
|
|
1142
1247
|
to
|
|
1143
1248
|
});
|
|
@@ -1169,7 +1274,7 @@ var comments = (options = {}) => {
|
|
|
1169
1274
|
}
|
|
1170
1275
|
return false;
|
|
1171
1276
|
};
|
|
1172
|
-
const bookmarksViewPlugin =
|
|
1277
|
+
const bookmarksViewPlugin = ViewPlugin4.fromClass(class BookmarkViewPlugin {
|
|
1173
1278
|
static {
|
|
1174
1279
|
// Match markdown footnotes (option).
|
|
1175
1280
|
// https://www.markdownguide.org/extended-syntax/#footnotes
|
|
@@ -1177,7 +1282,7 @@ var comments = (options = {}) => {
|
|
|
1177
1282
|
regexp: /\[\^(\w+)\]/g,
|
|
1178
1283
|
decoration: (match, view, pos) => {
|
|
1179
1284
|
const id = match[1];
|
|
1180
|
-
return
|
|
1285
|
+
return Decoration3.replace({
|
|
1181
1286
|
id,
|
|
1182
1287
|
widget: new BookmarkWidget(pos, id)
|
|
1183
1288
|
});
|
|
@@ -1187,27 +1292,27 @@ var comments = (options = {}) => {
|
|
|
1187
1292
|
constructor(view) {
|
|
1188
1293
|
this.bookmarks = BookmarkViewPlugin.bookmarkMatcher.createDeco(view);
|
|
1189
1294
|
}
|
|
1190
|
-
update(
|
|
1191
|
-
this.bookmarks = BookmarkViewPlugin.bookmarkMatcher.updateDeco(
|
|
1295
|
+
update(update2) {
|
|
1296
|
+
this.bookmarks = BookmarkViewPlugin.bookmarkMatcher.updateDeco(update2, this.bookmarks);
|
|
1192
1297
|
}
|
|
1193
1298
|
}, {
|
|
1194
1299
|
decorations: (instance) => instance.bookmarks,
|
|
1195
|
-
provide: (plugin) =>
|
|
1196
|
-
return view.plugin(plugin)?.bookmarks ||
|
|
1300
|
+
provide: (plugin) => EditorView5.atomicRanges.of((view) => {
|
|
1301
|
+
return view.plugin(plugin)?.bookmarks || Decoration3.none;
|
|
1197
1302
|
})
|
|
1198
1303
|
});
|
|
1199
1304
|
return [
|
|
1200
1305
|
bookmarksViewPlugin,
|
|
1201
1306
|
commentsStateField,
|
|
1202
1307
|
highlightDecorations,
|
|
1203
|
-
|
|
1308
|
+
styles3,
|
|
1204
1309
|
//
|
|
1205
1310
|
// Keymap.
|
|
1206
1311
|
//
|
|
1207
1312
|
options.onCreate ? keymap3.of([
|
|
1208
1313
|
{
|
|
1209
1314
|
key: options?.key ?? "meta-'",
|
|
1210
|
-
run: createCommentThread
|
|
1315
|
+
run: callbackWrapper(createCommentThread)
|
|
1211
1316
|
}
|
|
1212
1317
|
]) : [],
|
|
1213
1318
|
//
|
|
@@ -1243,37 +1348,28 @@ var comments = (options = {}) => {
|
|
|
1243
1348
|
// Monitor cursor movement and text updates.
|
|
1244
1349
|
// TODO(burdon): Is there a better (finer grained) way to do this?
|
|
1245
1350
|
//
|
|
1246
|
-
|
|
1351
|
+
EditorView5.updateListener.of(({ view, state, changes }) => {
|
|
1352
|
+
const cursorConverter3 = view.state.facet(CursorConverter);
|
|
1247
1353
|
{
|
|
1248
1354
|
let mod = false;
|
|
1249
|
-
const model = state.field(modelState);
|
|
1250
1355
|
const { active, ranges } = state.field(commentsStateField);
|
|
1251
1356
|
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
1357
|
ranges.forEach((range) => {
|
|
1262
1358
|
if (from2 === to2) {
|
|
1263
|
-
const newRange =
|
|
1264
|
-
if (newRange.to - newRange.from === 0) {
|
|
1265
|
-
|
|
1359
|
+
const newRange = getRangeFromCursor(cursorConverter3, range.cursor);
|
|
1360
|
+
if (!newRange || newRange.to - newRange.from === 0) {
|
|
1361
|
+
log2.info("deleted comment", {
|
|
1266
1362
|
thread: range.id
|
|
1267
1363
|
}, {
|
|
1268
|
-
F:
|
|
1269
|
-
L:
|
|
1364
|
+
F: __dxlog_file3,
|
|
1365
|
+
L: 358,
|
|
1270
1366
|
S: void 0,
|
|
1271
1367
|
C: (f, a) => f(...a)
|
|
1272
1368
|
});
|
|
1273
1369
|
}
|
|
1274
1370
|
}
|
|
1275
1371
|
if (from <= range.to) {
|
|
1276
|
-
const newRange =
|
|
1372
|
+
const newRange = getRangeFromCursor(cursorConverter3, range.cursor);
|
|
1277
1373
|
Object.assign(range, newRange);
|
|
1278
1374
|
mod = true;
|
|
1279
1375
|
}
|
|
@@ -1322,18 +1418,34 @@ var comments = (options = {}) => {
|
|
|
1322
1418
|
})
|
|
1323
1419
|
];
|
|
1324
1420
|
};
|
|
1421
|
+
var getCursorFromRange = (cursorConverter3, range) => {
|
|
1422
|
+
const from = cursorConverter3.toCursor(range.from);
|
|
1423
|
+
const to = cursorConverter3.toCursor(range.to, -1);
|
|
1424
|
+
return [
|
|
1425
|
+
from,
|
|
1426
|
+
to
|
|
1427
|
+
].join(":");
|
|
1428
|
+
};
|
|
1429
|
+
var getRangeFromCursor = (cursorConverter3, cursor) => {
|
|
1430
|
+
const parts = cursor.split(":");
|
|
1431
|
+
const from = cursorConverter3.fromCursor(parts[0]);
|
|
1432
|
+
const to = cursorConverter3.fromCursor(parts[1]);
|
|
1433
|
+
return from !== void 0 && to !== void 0 ? {
|
|
1434
|
+
from,
|
|
1435
|
+
to
|
|
1436
|
+
} : void 0;
|
|
1437
|
+
};
|
|
1325
1438
|
|
|
1326
|
-
// packages/ui/react-ui-editor/src/
|
|
1327
|
-
import { Decoration as
|
|
1328
|
-
|
|
1329
|
-
var styles3 = EditorView5.baseTheme({
|
|
1439
|
+
// packages/ui/react-ui-editor/src/extensions/hr.ts
|
|
1440
|
+
import { Decoration as Decoration4, EditorView as EditorView6, MatchDecorator as MatchDecorator2, ViewPlugin as ViewPlugin5, WidgetType as WidgetType3 } from "@codemirror/view";
|
|
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 ${getToken("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,67 +1657,71 @@ 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 (!view.hasFocus || 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
1686
|
}
|
|
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
|
-
});
|
|
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
|
-
import { markdownLanguage as
|
|
1712
|
+
import { markdownLanguage as markdownLanguage3, markdown } from "@codemirror/lang-markdown";
|
|
1527
1713
|
import { bracketMatching as bracketMatching2, defaultHighlightStyle as defaultHighlightStyle2, indentOnInput, syntaxHighlighting as syntaxHighlighting2 } from "@codemirror/language";
|
|
1528
1714
|
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/
|
|
1535
|
-
import { markdownLanguage } from "@codemirror/lang-markdown";
|
|
1720
|
+
// packages/ui/react-ui-editor/src/extensions/markdown/highlight.ts
|
|
1721
|
+
import { markdownLanguage as markdownLanguage2 } 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 get4 from "lodash.get";
|
|
1540
1725
|
var markdownTags = {
|
|
1541
1726
|
Blockquote: Tag.define(),
|
|
1542
1727
|
CodeMark: Tag.define(),
|
|
@@ -1720,19 +1905,19 @@ var markdownHighlightStyle = (readonly) => {
|
|
|
1720
1905
|
class: "font-mono"
|
|
1721
1906
|
}
|
|
1722
1907
|
], {
|
|
1723
|
-
scope:
|
|
1908
|
+
scope: markdownLanguage2,
|
|
1724
1909
|
all: {
|
|
1725
|
-
fontFamily:
|
|
1910
|
+
fontFamily: getToken("fontFamily.body", []).join(",")
|
|
1726
1911
|
}
|
|
1727
1912
|
});
|
|
1728
1913
|
};
|
|
1729
1914
|
|
|
1730
|
-
// packages/ui/react-ui-editor/src/
|
|
1915
|
+
// packages/ui/react-ui-editor/src/extensions/markdown/bundle.ts
|
|
1731
1916
|
var markdownBundle = ({ readonly, themeMode, placeholder: _placeholder }) => {
|
|
1732
1917
|
return [
|
|
1733
1918
|
EditorState.allowMultipleSelections.of(true),
|
|
1734
1919
|
EditorState.tabSize.of(2),
|
|
1735
|
-
|
|
1920
|
+
EditorView9.lineWrapping,
|
|
1736
1921
|
customKeymap(),
|
|
1737
1922
|
bracketMatching2(),
|
|
1738
1923
|
closeBrackets2(),
|
|
@@ -1752,7 +1937,7 @@ var markdownBundle = ({ readonly, themeMode, placeholder: _placeholder }) => {
|
|
|
1752
1937
|
// NOTE: This extends the parser; it doesn't affect rendering.
|
|
1753
1938
|
// https://github.github.com/gfm
|
|
1754
1939
|
// https://github.com/lezer-parser/markdown?tab=readme-ov-file#github-flavored-markdown
|
|
1755
|
-
base:
|
|
1940
|
+
base: markdownLanguage3,
|
|
1756
1941
|
// Languages for syntax highlighting fenced code blocks.
|
|
1757
1942
|
codeLanguages: languages,
|
|
1758
1943
|
// Parser extensions.
|
|
@@ -1780,7 +1965,7 @@ var customKeymap = () => keymap4.of([
|
|
|
1780
1965
|
...searchKeymap
|
|
1781
1966
|
]);
|
|
1782
1967
|
|
|
1783
|
-
// packages/ui/react-ui-editor/src/
|
|
1968
|
+
// packages/ui/react-ui-editor/src/extensions/mention.ts
|
|
1784
1969
|
import { autocompletion as autocompletion2 } from "@codemirror/autocomplete";
|
|
1785
1970
|
var mention = ({ onSearch }) => {
|
|
1786
1971
|
return autocompletion2({
|
|
@@ -1800,27 +1985,22 @@ var mention = ({ onSearch }) => {
|
|
|
1800
1985
|
};
|
|
1801
1986
|
}
|
|
1802
1987
|
]
|
|
1803
|
-
});
|
|
1804
|
-
};
|
|
1805
|
-
|
|
1806
|
-
// packages/ui/react-ui-editor/src/components/TextEditor/extensions/mermaid.ts
|
|
1807
|
-
var mermaid = () => {
|
|
1808
|
-
return [];
|
|
1988
|
+
});
|
|
1809
1989
|
};
|
|
1810
1990
|
|
|
1811
|
-
// packages/ui/react-ui-editor/src/
|
|
1991
|
+
// packages/ui/react-ui-editor/src/extensions/table.ts
|
|
1812
1992
|
import { syntaxTree as syntaxTree3 } from "@codemirror/language";
|
|
1813
|
-
import { RangeSetBuilder as
|
|
1814
|
-
import { Decoration as
|
|
1993
|
+
import { RangeSetBuilder as RangeSetBuilder2, StateField as StateField4 } from "@codemirror/state";
|
|
1994
|
+
import { Decoration as Decoration7, EditorView as EditorView10, WidgetType as WidgetType6 } from "@codemirror/view";
|
|
1815
1995
|
var table = (options = {}) => {
|
|
1816
|
-
return
|
|
1817
|
-
create: (state) =>
|
|
1818
|
-
update: (_, tr) =>
|
|
1819
|
-
provide: (field) =>
|
|
1996
|
+
return StateField4.define({
|
|
1997
|
+
create: (state) => update(state, options),
|
|
1998
|
+
update: (_, tr) => update(tr.state, options),
|
|
1999
|
+
provide: (field) => EditorView10.decorations.from(field)
|
|
1820
2000
|
});
|
|
1821
2001
|
};
|
|
1822
|
-
var
|
|
1823
|
-
const builder = new
|
|
2002
|
+
var update = (state, options) => {
|
|
2003
|
+
const builder = new RangeSetBuilder2();
|
|
1824
2004
|
const cursor = state.selection.main.head;
|
|
1825
2005
|
const tables = [];
|
|
1826
2006
|
const getTable = () => tables[tables.length - 1];
|
|
@@ -1860,23 +2040,22 @@ var update3 = (state, options) => {
|
|
|
1860
2040
|
});
|
|
1861
2041
|
tables.forEach((table2) => {
|
|
1862
2042
|
const hide = state.readOnly || cursor < table2.from || cursor > table2.to;
|
|
1863
|
-
hide && builder.add(table2.from, table2.to,
|
|
1864
|
-
block: true,
|
|
2043
|
+
hide && builder.add(table2.from, table2.to, Decoration7.replace({
|
|
1865
2044
|
widget: new TableWidget(table2)
|
|
1866
2045
|
}));
|
|
1867
|
-
builder.add(table2.from, table2.to,
|
|
2046
|
+
builder.add(table2.from, table2.to, Decoration7.mark({
|
|
1868
2047
|
class: "cm-table"
|
|
1869
2048
|
}));
|
|
1870
2049
|
});
|
|
1871
2050
|
return builder.finish();
|
|
1872
2051
|
};
|
|
1873
|
-
var TableWidget = class extends
|
|
2052
|
+
var TableWidget = class extends WidgetType6 {
|
|
1874
2053
|
constructor(_table) {
|
|
1875
2054
|
super();
|
|
1876
2055
|
this._table = _table;
|
|
1877
2056
|
}
|
|
1878
2057
|
eq(other) {
|
|
1879
|
-
return this._table.
|
|
2058
|
+
return this._table.header?.join() === other._table.header?.join() && this._table.rows?.join() === other._table.rows?.join();
|
|
1880
2059
|
}
|
|
1881
2060
|
toDOM(view) {
|
|
1882
2061
|
const table2 = document.createElement("table");
|
|
@@ -1902,26 +2081,28 @@ var TableWidget = class extends WidgetType5 {
|
|
|
1902
2081
|
}
|
|
1903
2082
|
return table2;
|
|
1904
2083
|
}
|
|
2084
|
+
ignoreEvent(e) {
|
|
2085
|
+
return !/^mouse/.test(e.type);
|
|
2086
|
+
}
|
|
1905
2087
|
};
|
|
1906
2088
|
|
|
1907
|
-
// packages/ui/react-ui-editor/src/
|
|
1908
|
-
import { EditorView as
|
|
1909
|
-
var
|
|
2089
|
+
// packages/ui/react-ui-editor/src/extensions/tasklist.ts
|
|
2090
|
+
import { EditorView as EditorView11, Decoration as Decoration8, WidgetType as WidgetType7, MatchDecorator as MatchDecorator3, ViewPlugin as ViewPlugin7 } from "@codemirror/view";
|
|
2091
|
+
var styles5 = EditorView11.baseTheme({
|
|
1910
2092
|
"& .cm-task-item": {
|
|
1911
2093
|
paddingLeft: "4px",
|
|
1912
2094
|
paddingRight: "8px"
|
|
1913
2095
|
}
|
|
1914
2096
|
});
|
|
1915
|
-
var CheckboxWidget = class extends
|
|
1916
|
-
constructor(
|
|
2097
|
+
var CheckboxWidget = class extends WidgetType7 {
|
|
2098
|
+
constructor(_checked, _indent, _onCheck) {
|
|
1917
2099
|
super();
|
|
1918
|
-
this._pos = _pos;
|
|
1919
2100
|
this._checked = _checked;
|
|
1920
2101
|
this._indent = _indent;
|
|
1921
2102
|
this._onCheck = _onCheck;
|
|
1922
2103
|
}
|
|
1923
2104
|
eq(other) {
|
|
1924
|
-
return this.
|
|
2105
|
+
return this._checked === other._checked && this._indent === other._indent;
|
|
1925
2106
|
}
|
|
1926
2107
|
toDOM(view) {
|
|
1927
2108
|
const wrap = document.createElement("span");
|
|
@@ -1952,8 +2133,8 @@ var tasklist = (options = {}) => {
|
|
|
1952
2133
|
decoration: (match, view, pos) => {
|
|
1953
2134
|
const indent = Math.floor(match[1].length / 2);
|
|
1954
2135
|
const checked = match[2] === "x" || match[2] === "X";
|
|
1955
|
-
return
|
|
1956
|
-
widget: new CheckboxWidget(
|
|
2136
|
+
return Decoration8.replace({
|
|
2137
|
+
widget: new CheckboxWidget(checked, indent, view.state.readOnly ? void 0 : (checked2) => {
|
|
1957
2138
|
const idx = pos + match[0].indexOf("[") + 1;
|
|
1958
2139
|
view.dispatch({
|
|
1959
2140
|
changes: {
|
|
@@ -1970,70 +2151,26 @@ var tasklist = (options = {}) => {
|
|
|
1970
2151
|
});
|
|
1971
2152
|
}
|
|
1972
2153
|
});
|
|
1973
|
-
const tasks =
|
|
2154
|
+
const tasks = ViewPlugin7.fromClass(class {
|
|
1974
2155
|
constructor(view) {
|
|
1975
2156
|
this.tasks = taskMatcher.createDeco(view);
|
|
1976
2157
|
}
|
|
1977
|
-
update(
|
|
1978
|
-
this.tasks = taskMatcher.updateDeco(
|
|
2158
|
+
update(update2) {
|
|
2159
|
+
this.tasks = taskMatcher.updateDeco(update2, this.tasks);
|
|
1979
2160
|
}
|
|
1980
2161
|
}, {
|
|
1981
2162
|
decorations: (value) => value.tasks,
|
|
1982
|
-
provide: (plugin) =>
|
|
1983
|
-
return view.plugin(plugin)?.tasks ||
|
|
2163
|
+
provide: (plugin) => EditorView11.atomicRanges.of((view) => {
|
|
2164
|
+
return view.plugin(plugin)?.tasks || Decoration8.none;
|
|
1984
2165
|
})
|
|
1985
2166
|
});
|
|
1986
2167
|
return [
|
|
1987
2168
|
tasks,
|
|
1988
|
-
|
|
2169
|
+
styles5
|
|
1989
2170
|
];
|
|
1990
2171
|
};
|
|
1991
2172
|
|
|
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
|
|
2173
|
+
// packages/ui/react-ui-editor/src/extensions/typewriter.ts
|
|
2037
2174
|
import { keymap as keymap5 } from "@codemirror/view";
|
|
2038
2175
|
var defaultItems = [
|
|
2039
2176
|
"hello world!",
|
|
@@ -2090,8 +2227,29 @@ var typewriter = ({ delay = 75, items = defaultItems } = {}) => {
|
|
|
2090
2227
|
];
|
|
2091
2228
|
};
|
|
2092
2229
|
|
|
2093
|
-
// packages/ui/react-ui-editor/src/
|
|
2094
|
-
import
|
|
2230
|
+
// packages/ui/react-ui-editor/src/extensions/yjs/yjs.ts
|
|
2231
|
+
import { yCollab } from "y-codemirror.next";
|
|
2232
|
+
|
|
2233
|
+
// packages/ui/react-ui-editor/src/extensions/yjs/cursor.ts
|
|
2234
|
+
import * as Y from "yjs";
|
|
2235
|
+
import { arrayToString, stringToArray } from "@dxos/util";
|
|
2236
|
+
var cursorConverter2 = (text) => ({
|
|
2237
|
+
toCursor: (index, assoc) => {
|
|
2238
|
+
return arrayToString(Y.encodeRelativePosition(Y.createRelativePositionFromTypeIndex(text, index, assoc)));
|
|
2239
|
+
},
|
|
2240
|
+
fromCursor: (cursor) => {
|
|
2241
|
+
return Y.createAbsolutePositionFromRelativePosition(Y.decodeRelativePosition(stringToArray(cursor)), text.doc)?.index ?? 0;
|
|
2242
|
+
}
|
|
2243
|
+
});
|
|
2244
|
+
|
|
2245
|
+
// packages/ui/react-ui-editor/src/extensions/yjs/yjs.ts
|
|
2246
|
+
var yjs = (content, awareness2) => [
|
|
2247
|
+
CursorConverter.of(cursorConverter2(content)),
|
|
2248
|
+
yCollab(content, awareness2)
|
|
2249
|
+
];
|
|
2250
|
+
|
|
2251
|
+
// packages/ui/react-ui-editor/src/themes/default.ts
|
|
2252
|
+
import get3 from "lodash.get";
|
|
2095
2253
|
var defaultTheme = {
|
|
2096
2254
|
//
|
|
2097
2255
|
// Main layout:
|
|
@@ -2120,21 +2278,21 @@ var defaultTheme = {
|
|
|
2120
2278
|
"&.cm-focused": {
|
|
2121
2279
|
outline: "none"
|
|
2122
2280
|
},
|
|
2123
|
-
"
|
|
2281
|
+
".cm-scroller": {
|
|
2124
2282
|
overflow: "visible",
|
|
2125
|
-
fontFamily:
|
|
2283
|
+
fontFamily: get3(tokens, "fontFamily.mono", []).join(",")
|
|
2126
2284
|
},
|
|
2127
|
-
"
|
|
2285
|
+
".cm-content": {
|
|
2128
2286
|
padding: 0,
|
|
2129
2287
|
// NOTE: Base font size (otherwise defined by HTML tag, which might be different for storybook).
|
|
2130
2288
|
fontSize: "16px"
|
|
2131
2289
|
},
|
|
2132
2290
|
"&light .cm-content": {
|
|
2133
|
-
color:
|
|
2291
|
+
color: get3(tokens, "extend.colors.neutral.900", "black"),
|
|
2134
2292
|
caretColor: "black"
|
|
2135
2293
|
},
|
|
2136
2294
|
"&dark .cm-content": {
|
|
2137
|
-
color:
|
|
2295
|
+
color: get3(tokens, "extend.colors.neutral.100", "white"),
|
|
2138
2296
|
caretColor: "white"
|
|
2139
2297
|
},
|
|
2140
2298
|
//
|
|
@@ -2146,41 +2304,41 @@ var defaultTheme = {
|
|
|
2146
2304
|
"&dark .cm-cursor, &dark .cm-dropCursor": {
|
|
2147
2305
|
borderLeft: "2px solid white"
|
|
2148
2306
|
},
|
|
2149
|
-
"
|
|
2307
|
+
".cm-placeholder": {
|
|
2150
2308
|
fontWeight: 100
|
|
2151
2309
|
},
|
|
2152
2310
|
//
|
|
2153
2311
|
// line
|
|
2154
2312
|
//
|
|
2155
|
-
"
|
|
2313
|
+
".cm-line": {
|
|
2156
2314
|
paddingInline: 0
|
|
2157
2315
|
},
|
|
2158
|
-
"
|
|
2316
|
+
".cm-activeLine": {
|
|
2159
2317
|
background: "inherit"
|
|
2160
2318
|
},
|
|
2161
2319
|
//
|
|
2162
2320
|
// Selection
|
|
2163
2321
|
//
|
|
2164
2322
|
"&light .cm-selectionBackground": {
|
|
2165
|
-
background:
|
|
2323
|
+
background: get3(tokens, "extend.colors.primary.100")
|
|
2166
2324
|
},
|
|
2167
2325
|
"&light.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground": {
|
|
2168
|
-
background:
|
|
2326
|
+
background: get3(tokens, "extend.colors.primary.200")
|
|
2169
2327
|
},
|
|
2170
2328
|
"&dark .cm-selectionBackground": {
|
|
2171
|
-
background:
|
|
2329
|
+
background: get3(tokens, "extend.colors.primary.700")
|
|
2172
2330
|
},
|
|
2173
2331
|
"&dark.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground": {
|
|
2174
|
-
background:
|
|
2332
|
+
background: get3(tokens, "extend.colors.primary.600")
|
|
2175
2333
|
},
|
|
2176
2334
|
//
|
|
2177
2335
|
// Search
|
|
2178
2336
|
//
|
|
2179
2337
|
"&light .cm-searchMatch": {
|
|
2180
|
-
backgroundColor:
|
|
2338
|
+
backgroundColor: get3(tokens, "extend.colors.yellow.100")
|
|
2181
2339
|
},
|
|
2182
2340
|
"&dark .cm-searchMatch": {
|
|
2183
|
-
backgroundColor:
|
|
2341
|
+
backgroundColor: get3(tokens, "extend.colors.yellow.700")
|
|
2184
2342
|
},
|
|
2185
2343
|
//
|
|
2186
2344
|
// collaboration
|
|
@@ -2192,95 +2350,101 @@ var defaultTheme = {
|
|
|
2192
2350
|
"&dark .cm-ySelection, &dark .cm-yLineSelection": {
|
|
2193
2351
|
mixBlendMode: "screen"
|
|
2194
2352
|
},
|
|
2195
|
-
"
|
|
2353
|
+
".cm-ySelectionInfo": {
|
|
2196
2354
|
padding: "2px 4px",
|
|
2197
2355
|
marginBlockStart: "-4px"
|
|
2198
2356
|
},
|
|
2199
|
-
"
|
|
2357
|
+
".cm-ySelection, & .cm-selectionMatch": {
|
|
2200
2358
|
paddingBlockStart: ".15em",
|
|
2201
2359
|
paddingBlockEnd: ".15em"
|
|
2202
2360
|
},
|
|
2203
|
-
"
|
|
2361
|
+
".cm-ySelectionCaret": {
|
|
2204
2362
|
display: "inline-block",
|
|
2205
2363
|
insetBlockStart: ".1em",
|
|
2206
2364
|
blockSize: "1.4em",
|
|
2207
2365
|
verticalAlign: "top"
|
|
2208
2366
|
},
|
|
2209
|
-
"
|
|
2367
|
+
".cm-yLineSelection": {
|
|
2210
2368
|
margin: 0
|
|
2211
2369
|
},
|
|
2212
2370
|
//
|
|
2213
2371
|
// link
|
|
2214
2372
|
//
|
|
2215
|
-
"
|
|
2216
|
-
color:
|
|
2373
|
+
".cm-link": {
|
|
2374
|
+
color: get3(tokens, "extend.colors.primary.500"),
|
|
2217
2375
|
textDecorationLine: "underline",
|
|
2218
2376
|
textDecorationThickness: "1px",
|
|
2219
2377
|
textUnderlineOffset: "2px",
|
|
2220
2378
|
borderRadius: ".125rem",
|
|
2221
|
-
fontFamily:
|
|
2379
|
+
fontFamily: get3(tokens, "fontFamily.body", []).join(",")
|
|
2222
2380
|
},
|
|
2223
2381
|
//
|
|
2224
2382
|
// tooltip
|
|
2225
2383
|
//
|
|
2226
|
-
"
|
|
2384
|
+
".cm-tooltip": {
|
|
2227
2385
|
border: "none"
|
|
2228
2386
|
},
|
|
2229
|
-
"
|
|
2387
|
+
".cm-tooltip-below": {},
|
|
2230
2388
|
//
|
|
2231
2389
|
// autocomplete
|
|
2232
2390
|
//
|
|
2233
|
-
"
|
|
2391
|
+
".cm-tooltip-autocomplete": {
|
|
2234
2392
|
marginTop: "4px",
|
|
2235
2393
|
marginLeft: "-3px"
|
|
2236
2394
|
},
|
|
2237
|
-
"
|
|
2238
|
-
"
|
|
2239
|
-
"
|
|
2395
|
+
".cm-tooltip-autocomplete ul li": {},
|
|
2396
|
+
".cm-tooltip-autocomplete ul li[aria-selected]": {},
|
|
2397
|
+
".cm-completionIcon": {
|
|
2240
2398
|
display: "none"
|
|
2241
2399
|
},
|
|
2242
|
-
"
|
|
2243
|
-
fontFamily:
|
|
2400
|
+
".cm-completionLabel": {
|
|
2401
|
+
fontFamily: get3(tokens, "fontFamily.body", []).join(",")
|
|
2244
2402
|
},
|
|
2245
|
-
"
|
|
2403
|
+
".cm-completionMatchedText": {
|
|
2246
2404
|
textDecoration: "none"
|
|
2247
2405
|
},
|
|
2248
2406
|
//
|
|
2249
2407
|
// widgets
|
|
2250
2408
|
//
|
|
2251
|
-
"
|
|
2409
|
+
".cm-widgetBuffer": {
|
|
2252
2410
|
display: "none",
|
|
2253
2411
|
height: 0
|
|
2254
2412
|
},
|
|
2255
2413
|
//
|
|
2256
2414
|
// table
|
|
2257
2415
|
//
|
|
2258
|
-
"
|
|
2259
|
-
fontFamily: `${
|
|
2416
|
+
".cm-table *": {
|
|
2417
|
+
fontFamily: `${get3(tokens, "fontFamily.mono", []).join(",")} !important`,
|
|
2260
2418
|
textDecoration: "none !important"
|
|
2261
2419
|
},
|
|
2262
|
-
"
|
|
2420
|
+
".cm-table-head": {
|
|
2263
2421
|
padding: "2px 16px 2px 0px",
|
|
2264
|
-
borderBottom: `1px solid ${
|
|
2422
|
+
borderBottom: `1px solid ${get3(tokens, "extend.colors.neutral.500")}`,
|
|
2265
2423
|
fontWeight: 100,
|
|
2266
2424
|
textAlign: "left",
|
|
2267
|
-
color:
|
|
2425
|
+
color: get3(tokens, "extend.colors.neutral.500")
|
|
2268
2426
|
},
|
|
2269
|
-
"
|
|
2427
|
+
".cm-table-cell": {
|
|
2270
2428
|
padding: "2px 16px 2px 0px"
|
|
2271
2429
|
},
|
|
2272
2430
|
//
|
|
2273
2431
|
// image
|
|
2274
2432
|
//
|
|
2275
|
-
"
|
|
2276
|
-
|
|
2433
|
+
".cm-image": {
|
|
2434
|
+
display: "block",
|
|
2435
|
+
height: "0"
|
|
2436
|
+
},
|
|
2437
|
+
".cm-image.cm-loaded-image": {
|
|
2438
|
+
height: "auto",
|
|
2439
|
+
borderTop: "0.5rem solid transparent",
|
|
2440
|
+
borderBottom: "0.5rem solid transparent"
|
|
2277
2441
|
},
|
|
2278
2442
|
//
|
|
2279
2443
|
// font size
|
|
2280
2444
|
// 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
2445
|
//
|
|
2282
|
-
...Object.keys(
|
|
2283
|
-
const height =
|
|
2446
|
+
...Object.keys(get3(tokens, "extend.fontSize", {})).reduce((acc, fontSize) => {
|
|
2447
|
+
const height = get3(tokens, [
|
|
2284
2448
|
"extend",
|
|
2285
2449
|
"fontSize",
|
|
2286
2450
|
fontSize,
|
|
@@ -2314,88 +2478,81 @@ var defaultTheme = {
|
|
|
2314
2478
|
* </div>
|
|
2315
2479
|
* </div
|
|
2316
2480
|
*/
|
|
2317
|
-
"
|
|
2318
|
-
border: `1px solid ${
|
|
2481
|
+
".cm-panels": {
|
|
2482
|
+
border: `1px solid ${get3(tokens, "extend.colors.neutral.200")}`
|
|
2319
2483
|
},
|
|
2320
|
-
"
|
|
2321
|
-
background:
|
|
2322
|
-
fontFamily:
|
|
2484
|
+
".cm-panel": {
|
|
2485
|
+
background: get3(tokens, "extend.colors.neutral.50"),
|
|
2486
|
+
fontFamily: get3(tokens, "fontFamily.body", []).join(",")
|
|
2323
2487
|
},
|
|
2324
|
-
"
|
|
2488
|
+
".cm-button": {
|
|
2325
2489
|
margin: "4px",
|
|
2326
|
-
fontFamily:
|
|
2327
|
-
background:
|
|
2490
|
+
fontFamily: get3(tokens, "fontFamily.body", []).join(","),
|
|
2491
|
+
background: get3(tokens, "extend.colors.neutral.100"),
|
|
2328
2492
|
backgroundImage: "none",
|
|
2329
2493
|
border: "none",
|
|
2330
2494
|
"&:hover": {
|
|
2331
|
-
background:
|
|
2495
|
+
background: get3(tokens, "extend.colors.neutral.200")
|
|
2332
2496
|
},
|
|
2333
2497
|
"&:active": {
|
|
2334
|
-
background:
|
|
2498
|
+
background: get3(tokens, "extend.colors.neutral.300"),
|
|
2335
2499
|
backgroundImage: "none"
|
|
2336
2500
|
}
|
|
2337
2501
|
},
|
|
2338
|
-
"
|
|
2502
|
+
".cm-panel input[type=checkbox]": {
|
|
2339
2503
|
marginRight: "0.4rem !important"
|
|
2340
2504
|
}
|
|
2341
2505
|
};
|
|
2342
2506
|
var textTheme = {
|
|
2343
|
-
"
|
|
2344
|
-
fontFamily:
|
|
2507
|
+
".cm-scroller": {
|
|
2508
|
+
fontFamily: get3(tokens, "fontFamily.body", []).join(",")
|
|
2345
2509
|
},
|
|
2346
|
-
"
|
|
2347
|
-
fontFamily:
|
|
2510
|
+
".cm-placeholder": {
|
|
2511
|
+
fontFamily: get3(tokens, "fontFamily.body", []).join(",")
|
|
2348
2512
|
}
|
|
2349
2513
|
};
|
|
2350
2514
|
var markdownTheme = {
|
|
2351
2515
|
// NOTE: Must leave base font family as is (i.e., monospace) due to fenced code blocks.
|
|
2352
|
-
"
|
|
2353
|
-
fontFamily:
|
|
2516
|
+
".cm-placeholder": {
|
|
2517
|
+
fontFamily: get3(tokens, "fontFamily.body", []).join(",")
|
|
2354
2518
|
}
|
|
2355
2519
|
};
|
|
2356
2520
|
var codeTheme = {
|
|
2357
|
-
"
|
|
2358
|
-
fontFamily:
|
|
2521
|
+
".cm-scroller": {
|
|
2522
|
+
fontFamily: get3(tokens, "fontFamily.mono", []).join(",")
|
|
2359
2523
|
},
|
|
2360
|
-
"
|
|
2361
|
-
fontFamily:
|
|
2524
|
+
".cm-placeholder": {
|
|
2525
|
+
fontFamily: get3(tokens, "fontFamily.mono", []).join(",")
|
|
2362
2526
|
}
|
|
2363
2527
|
};
|
|
2364
2528
|
|
|
2365
2529
|
// 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
2530
|
var EditorModes = [
|
|
2376
2531
|
"default",
|
|
2377
2532
|
"vim"
|
|
2378
2533
|
];
|
|
2379
|
-
var BaseTextEditor = /* @__PURE__ */ forwardRef(({ model,
|
|
2380
|
-
const { themeMode } = useThemeContext();
|
|
2534
|
+
var BaseTextEditor = /* @__PURE__ */ forwardRef(({ model, focus, readonly, comments: comments2, extensions = [], editorMode, slots = defaultSlots }, forwardedRef) => {
|
|
2381
2535
|
const tabsterDOMAttribute = useFocusableGroup({
|
|
2382
2536
|
tabBehavior: "limited"
|
|
2383
2537
|
});
|
|
2384
|
-
const
|
|
2385
|
-
const
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2538
|
+
const { themeMode } = useThemeContext();
|
|
2539
|
+
const rootRef = useRef(null);
|
|
2540
|
+
const [view, setView] = useState(null);
|
|
2541
|
+
useImperativeHandle(forwardedRef, () => view, [
|
|
2542
|
+
view
|
|
2543
|
+
]);
|
|
2544
|
+
useEffect(() => {
|
|
2545
|
+
if (focus && view) {
|
|
2546
|
+
view.focus();
|
|
2547
|
+
}
|
|
2548
|
+
}, [
|
|
2549
|
+
focus,
|
|
2389
2550
|
view
|
|
2390
|
-
}), [
|
|
2391
|
-
view,
|
|
2392
|
-
state,
|
|
2393
|
-
root
|
|
2394
2551
|
]);
|
|
2395
|
-
const { awareness, peer } = model;
|
|
2396
|
-
|
|
2397
|
-
if (
|
|
2398
|
-
|
|
2552
|
+
const { awareness: awareness2, peer } = model;
|
|
2553
|
+
useEffect(() => {
|
|
2554
|
+
if (awareness2 && peer) {
|
|
2555
|
+
awareness2.setLocalStateField("user", {
|
|
2399
2556
|
name: peer.name ?? generateName(peer.id),
|
|
2400
2557
|
color: getColorForValue({
|
|
2401
2558
|
value: peer.id,
|
|
@@ -2409,11 +2566,11 @@ var BaseTextEditor = /* @__PURE__ */ forwardRef(({ model, comments: comments2, r
|
|
|
2409
2566
|
});
|
|
2410
2567
|
}
|
|
2411
2568
|
}, [
|
|
2412
|
-
|
|
2569
|
+
awareness2,
|
|
2413
2570
|
peer,
|
|
2414
2571
|
themeMode
|
|
2415
2572
|
]);
|
|
2416
|
-
|
|
2573
|
+
useEffect(() => {
|
|
2417
2574
|
if (view && comments2?.length) {
|
|
2418
2575
|
view.dispatch({
|
|
2419
2576
|
effects: setCommentRange.of({
|
|
@@ -2426,11 +2583,11 @@ var BaseTextEditor = /* @__PURE__ */ forwardRef(({ model, comments: comments2, r
|
|
|
2426
2583
|
view,
|
|
2427
2584
|
comments2
|
|
2428
2585
|
]);
|
|
2429
|
-
|
|
2430
|
-
if (!
|
|
2586
|
+
useEffect(() => {
|
|
2587
|
+
if (!model || !rootRef.current) {
|
|
2431
2588
|
return;
|
|
2432
2589
|
}
|
|
2433
|
-
const
|
|
2590
|
+
const state = EditorState2.create({
|
|
2434
2591
|
doc: model.text(),
|
|
2435
2592
|
extensions: [
|
|
2436
2593
|
readonly && EditorState2.readOnly.of(readonly),
|
|
@@ -2438,9 +2595,9 @@ var BaseTextEditor = /* @__PURE__ */ forwardRef(({ model, comments: comments2, r
|
|
|
2438
2595
|
editorMode === "vim" && vim(),
|
|
2439
2596
|
// Theme.
|
|
2440
2597
|
// TODO(burdon): Make theme configurable.
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2598
|
+
EditorView12.baseTheme(defaultTheme),
|
|
2599
|
+
EditorView12.theme(slots?.editor?.theme ?? {}),
|
|
2600
|
+
EditorView12.darkTheme.of(themeMode === "dark"),
|
|
2444
2601
|
// Storage and replication.
|
|
2445
2602
|
model.extension,
|
|
2446
2603
|
// Custom.
|
|
@@ -2448,19 +2605,17 @@ var BaseTextEditor = /* @__PURE__ */ forwardRef(({ model, comments: comments2, r
|
|
|
2448
2605
|
].filter(Boolean)
|
|
2449
2606
|
});
|
|
2450
2607
|
view?.destroy();
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
state: state2,
|
|
2455
|
-
parent: root
|
|
2456
|
-
})
|
|
2608
|
+
const newView = new EditorView12({
|
|
2609
|
+
parent: rootRef.current,
|
|
2610
|
+
state
|
|
2457
2611
|
});
|
|
2612
|
+
setView(newView);
|
|
2458
2613
|
return () => {
|
|
2459
|
-
|
|
2460
|
-
|
|
2614
|
+
newView?.destroy();
|
|
2615
|
+
setView(null);
|
|
2461
2616
|
};
|
|
2462
2617
|
}, [
|
|
2463
|
-
|
|
2618
|
+
rootRef,
|
|
2464
2619
|
model,
|
|
2465
2620
|
readonly,
|
|
2466
2621
|
editorMode,
|
|
@@ -2469,12 +2624,8 @@ var BaseTextEditor = /* @__PURE__ */ forwardRef(({ model, comments: comments2, r
|
|
|
2469
2624
|
const handleKeyUp = useCallback((event) => {
|
|
2470
2625
|
const { key, altKey, shiftKey, metaKey, ctrlKey } = event;
|
|
2471
2626
|
switch (key) {
|
|
2472
|
-
case "Enter": {
|
|
2473
|
-
view?.contentDOM.focus();
|
|
2474
|
-
break;
|
|
2475
|
-
}
|
|
2476
2627
|
case "Escape": {
|
|
2477
|
-
editorMode === "vim" && (altKey || shiftKey || metaKey || ctrlKey) &&
|
|
2628
|
+
editorMode === "vim" && (altKey || shiftKey || metaKey || ctrlKey) && rootRef.current?.focus();
|
|
2478
2629
|
break;
|
|
2479
2630
|
}
|
|
2480
2631
|
}
|
|
@@ -2484,16 +2635,16 @@ var BaseTextEditor = /* @__PURE__ */ forwardRef(({ model, comments: comments2, r
|
|
|
2484
2635
|
]);
|
|
2485
2636
|
return /* @__PURE__ */ React.createElement("div", {
|
|
2486
2637
|
key: model.id,
|
|
2487
|
-
ref:
|
|
2638
|
+
ref: rootRef,
|
|
2488
2639
|
tabIndex: 0,
|
|
2489
2640
|
...slots?.root,
|
|
2490
2641
|
...editorMode !== "vim" && tabsterDOMAttribute,
|
|
2491
2642
|
onKeyUp: handleKeyUp
|
|
2492
2643
|
});
|
|
2493
2644
|
});
|
|
2494
|
-
var TextEditor = /* @__PURE__ */ forwardRef(({ readonly, extensions = [], slots
|
|
2645
|
+
var TextEditor = /* @__PURE__ */ forwardRef(({ readonly, extensions = [], slots, ...props }, forwardedRef) => {
|
|
2495
2646
|
const { themeMode } = useThemeContext();
|
|
2496
|
-
const
|
|
2647
|
+
const updatedSlots = defaultsDeep2({}, slots, defaultTextSlots);
|
|
2497
2648
|
return /* @__PURE__ */ React.createElement(BaseTextEditor, {
|
|
2498
2649
|
ref: forwardedRef,
|
|
2499
2650
|
readonly,
|
|
@@ -2501,17 +2652,17 @@ var TextEditor = /* @__PURE__ */ forwardRef(({ readonly, extensions = [], slots:
|
|
|
2501
2652
|
basicBundle({
|
|
2502
2653
|
readonly,
|
|
2503
2654
|
themeMode,
|
|
2504
|
-
placeholder:
|
|
2655
|
+
placeholder: updatedSlots?.editor?.placeholder
|
|
2505
2656
|
}),
|
|
2506
2657
|
...extensions
|
|
2507
2658
|
],
|
|
2508
|
-
slots,
|
|
2659
|
+
slots: updatedSlots,
|
|
2509
2660
|
...props
|
|
2510
2661
|
});
|
|
2511
2662
|
});
|
|
2512
|
-
var MarkdownEditor = /* @__PURE__ */ forwardRef(({ readonly, extensions = [], slots
|
|
2663
|
+
var MarkdownEditor = /* @__PURE__ */ forwardRef(({ readonly, extensions = [], slots, ...props }, forwardedRef) => {
|
|
2513
2664
|
const { themeMode } = useThemeContext();
|
|
2514
|
-
const
|
|
2665
|
+
const updatedSlots = defaultsDeep2({}, slots, defaultMarkdownSlots);
|
|
2515
2666
|
return /* @__PURE__ */ React.createElement(BaseTextEditor, {
|
|
2516
2667
|
ref: forwardedRef,
|
|
2517
2668
|
readonly,
|
|
@@ -2519,11 +2670,11 @@ var MarkdownEditor = /* @__PURE__ */ forwardRef(({ readonly, extensions = [], sl
|
|
|
2519
2670
|
markdownBundle({
|
|
2520
2671
|
readonly,
|
|
2521
2672
|
themeMode,
|
|
2522
|
-
placeholder:
|
|
2673
|
+
placeholder: updatedSlots?.editor?.placeholder
|
|
2523
2674
|
}),
|
|
2524
2675
|
...extensions
|
|
2525
2676
|
],
|
|
2526
|
-
slots,
|
|
2677
|
+
slots: updatedSlots,
|
|
2527
2678
|
...props
|
|
2528
2679
|
});
|
|
2529
2680
|
});
|
|
@@ -2544,28 +2695,379 @@ var defaultMarkdownSlots = {
|
|
|
2544
2695
|
theme: markdownTheme
|
|
2545
2696
|
}
|
|
2546
2697
|
};
|
|
2698
|
+
|
|
2699
|
+
// packages/ui/react-ui-editor/src/hooks/automerge.ts
|
|
2700
|
+
import get4 from "lodash.get";
|
|
2701
|
+
import { getRawDoc } from "@dxos/echo-schema";
|
|
2702
|
+
import { isNotNullOrUndefined } from "@dxos/util";
|
|
2703
|
+
|
|
2704
|
+
// packages/ui/react-ui-editor/src/hooks/awareness-provider.ts
|
|
2705
|
+
import { DeferredTask, Event as Event2, sleep } from "@dxos/async";
|
|
2706
|
+
import { Context as Context2 } from "@dxos/context";
|
|
2707
|
+
import { invariant as invariant3 } from "@dxos/invariant";
|
|
2708
|
+
import { log as log3 } from "@dxos/log";
|
|
2709
|
+
var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/hooks/awareness-provider.ts";
|
|
2710
|
+
var DEBOUNCE_INTERVAL = 100;
|
|
2711
|
+
var SpaceAwarenessProvider = class {
|
|
2712
|
+
constructor(params) {
|
|
2713
|
+
this.remoteStateChange = new Event2();
|
|
2714
|
+
this._remoteStates = /* @__PURE__ */ new Map();
|
|
2715
|
+
this._space = params.space;
|
|
2716
|
+
this._channel = params.channel;
|
|
2717
|
+
this._peerId = params.peerId;
|
|
2718
|
+
this._info = params.info;
|
|
2719
|
+
}
|
|
2720
|
+
open() {
|
|
2721
|
+
this._ctx = new Context2();
|
|
2722
|
+
this._postTask = new DeferredTask(this._ctx, async () => {
|
|
2723
|
+
if (this._localState) {
|
|
2724
|
+
await this._space.postMessage(this._channel, {
|
|
2725
|
+
kind: "post",
|
|
2726
|
+
state: this._localState
|
|
2727
|
+
});
|
|
2728
|
+
await sleep(DEBOUNCE_INTERVAL);
|
|
2729
|
+
}
|
|
2730
|
+
});
|
|
2731
|
+
const unsubscribe = this._space.listen(this._channel, (message) => {
|
|
2732
|
+
switch (message.payload.kind) {
|
|
2733
|
+
case "query": {
|
|
2734
|
+
this._handleQueryMessage();
|
|
2735
|
+
break;
|
|
2736
|
+
}
|
|
2737
|
+
case "post": {
|
|
2738
|
+
this._handlePostMessage(message.payload);
|
|
2739
|
+
break;
|
|
2740
|
+
}
|
|
2741
|
+
}
|
|
2742
|
+
});
|
|
2743
|
+
this._ctx.onDispose(unsubscribe);
|
|
2744
|
+
void this._space.postMessage(this._channel, {
|
|
2745
|
+
kind: "query"
|
|
2746
|
+
}).catch((err) => {
|
|
2747
|
+
log3.debug("failed to query awareness", {
|
|
2748
|
+
err
|
|
2749
|
+
}, {
|
|
2750
|
+
F: __dxlog_file4,
|
|
2751
|
+
L: 85,
|
|
2752
|
+
S: this,
|
|
2753
|
+
C: (f, a) => f(...a)
|
|
2754
|
+
});
|
|
2755
|
+
});
|
|
2756
|
+
}
|
|
2757
|
+
close() {
|
|
2758
|
+
void this._ctx?.dispose();
|
|
2759
|
+
this._ctx = void 0;
|
|
2760
|
+
this._postTask = void 0;
|
|
2761
|
+
}
|
|
2762
|
+
update(position) {
|
|
2763
|
+
invariant3(this._postTask, void 0, {
|
|
2764
|
+
F: __dxlog_file4,
|
|
2765
|
+
L: 96,
|
|
2766
|
+
S: this,
|
|
2767
|
+
A: [
|
|
2768
|
+
"this._postTask",
|
|
2769
|
+
""
|
|
2770
|
+
]
|
|
2771
|
+
});
|
|
2772
|
+
this._localState = {
|
|
2773
|
+
peerId: this._peerId,
|
|
2774
|
+
position,
|
|
2775
|
+
info: this._info
|
|
2776
|
+
};
|
|
2777
|
+
this._postTask.schedule();
|
|
2778
|
+
}
|
|
2779
|
+
getRemoteStates() {
|
|
2780
|
+
return Array.from(this._remoteStates.values());
|
|
2781
|
+
}
|
|
2782
|
+
_handleQueryMessage() {
|
|
2783
|
+
invariant3(this._postTask, void 0, {
|
|
2784
|
+
F: __dxlog_file4,
|
|
2785
|
+
L: 111,
|
|
2786
|
+
S: this,
|
|
2787
|
+
A: [
|
|
2788
|
+
"this._postTask",
|
|
2789
|
+
""
|
|
2790
|
+
]
|
|
2791
|
+
});
|
|
2792
|
+
this._postTask.schedule();
|
|
2793
|
+
}
|
|
2794
|
+
_handlePostMessage(message) {
|
|
2795
|
+
invariant3(message.kind === "post", void 0, {
|
|
2796
|
+
F: __dxlog_file4,
|
|
2797
|
+
L: 116,
|
|
2798
|
+
S: this,
|
|
2799
|
+
A: [
|
|
2800
|
+
"message.kind === 'post'",
|
|
2801
|
+
""
|
|
2802
|
+
]
|
|
2803
|
+
});
|
|
2804
|
+
this._remoteStates.set(message.state.peerId, message.state);
|
|
2805
|
+
this.remoteStateChange.emit();
|
|
2806
|
+
}
|
|
2807
|
+
};
|
|
2808
|
+
|
|
2809
|
+
// packages/ui/react-ui-editor/src/hooks/useTextModel.ts
|
|
2810
|
+
import { StateField as StateField5 } from "@codemirror/state";
|
|
2811
|
+
import { useEffect as useEffect2, useState as useState2 } from "react";
|
|
2812
|
+
import { isAutomergeObject } from "@dxos/react-client/echo";
|
|
2813
|
+
|
|
2814
|
+
// packages/ui/react-ui-editor/src/hooks/yjs.ts
|
|
2815
|
+
import * as decoding from "lib0/decoding";
|
|
2816
|
+
import * as encoding from "lib0/encoding";
|
|
2817
|
+
import { Observable } from "lib0/observable";
|
|
2818
|
+
import * as YP from "y-protocols/awareness";
|
|
2819
|
+
import * as Y2 from "yjs";
|
|
2820
|
+
import { invariant as invariant4 } from "@dxos/invariant";
|
|
2821
|
+
import { log as log4 } from "@dxos/log";
|
|
2822
|
+
import { arrayToString as arrayToString2, stringToArray as stringToArray2 } from "@dxos/util";
|
|
2823
|
+
var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/hooks/yjs.ts";
|
|
2824
|
+
var createYjsModel = ({ identity, space, text }) => {
|
|
2825
|
+
invariant4(text?.doc && text?.content, void 0, {
|
|
2826
|
+
F: __dxlog_file5,
|
|
2827
|
+
L: 23,
|
|
2828
|
+
S: void 0,
|
|
2829
|
+
A: [
|
|
2830
|
+
"text?.doc && text?.content",
|
|
2831
|
+
""
|
|
2832
|
+
]
|
|
2833
|
+
});
|
|
2834
|
+
const provider = space ? new YAwarenessProvider({
|
|
2835
|
+
space,
|
|
2836
|
+
doc: text.doc,
|
|
2837
|
+
channel: `yjs.awareness.${text.id}`
|
|
2838
|
+
}) : void 0;
|
|
2839
|
+
const model = {
|
|
2840
|
+
id: text.doc.guid,
|
|
2841
|
+
content: text.content,
|
|
2842
|
+
text: () => text.content.toString(),
|
|
2843
|
+
// https://github.com/yjs/yjs?tab=readme-ov-file#relative-positions
|
|
2844
|
+
// TODO(dmaretskyi): Refactor as cursor-converter.
|
|
2845
|
+
getCursorFromRange: (range) => {
|
|
2846
|
+
const from = Y2.encodeRelativePosition(Y2.createRelativePositionFromTypeIndex(text.content, range.from));
|
|
2847
|
+
const to = Y2.encodeRelativePosition(Y2.createRelativePositionFromTypeIndex(text.content, range.to, -1));
|
|
2848
|
+
return [
|
|
2849
|
+
arrayToString2(from),
|
|
2850
|
+
arrayToString2(to)
|
|
2851
|
+
].join(":");
|
|
2852
|
+
},
|
|
2853
|
+
getRangeFromCursor: (cursor) => {
|
|
2854
|
+
invariant4(text.doc, void 0, {
|
|
2855
|
+
F: __dxlog_file5,
|
|
2856
|
+
L: 40,
|
|
2857
|
+
S: void 0,
|
|
2858
|
+
A: [
|
|
2859
|
+
"text.doc",
|
|
2860
|
+
""
|
|
2861
|
+
]
|
|
2862
|
+
});
|
|
2863
|
+
const parts = cursor.split(":");
|
|
2864
|
+
const from = Y2.createAbsolutePositionFromRelativePosition(Y2.decodeRelativePosition(stringToArray2(parts[0])), text.doc);
|
|
2865
|
+
const to = Y2.createAbsolutePositionFromRelativePosition(Y2.decodeRelativePosition(stringToArray2(parts[1])), text.doc);
|
|
2866
|
+
return from && to ? {
|
|
2867
|
+
from: from.index,
|
|
2868
|
+
to: to.index
|
|
2869
|
+
} : void 0;
|
|
2870
|
+
},
|
|
2871
|
+
extension: [
|
|
2872
|
+
modelState.init(() => model),
|
|
2873
|
+
yjs(text.content, provider?.awareness)
|
|
2874
|
+
],
|
|
2875
|
+
awareness: provider?.awareness,
|
|
2876
|
+
peer: identity ? {
|
|
2877
|
+
id: identity.identityKey.toHex(),
|
|
2878
|
+
name: identity.profile?.displayName
|
|
2879
|
+
} : void 0
|
|
2880
|
+
};
|
|
2881
|
+
return model;
|
|
2882
|
+
};
|
|
2883
|
+
var messageAwareness = 1;
|
|
2884
|
+
var messageQueryAwareness = 3;
|
|
2885
|
+
var YAwarenessProvider = class extends Observable {
|
|
2886
|
+
constructor({ space, doc, channel, awareness: awareness2 }) {
|
|
2887
|
+
super();
|
|
2888
|
+
this._space = space;
|
|
2889
|
+
this._awareness = awareness2 ?? new YP.Awareness(doc);
|
|
2890
|
+
this._channel = channel;
|
|
2891
|
+
this._clientId = doc.clientID;
|
|
2892
|
+
this._awareness.on("update", this._handleAwarenessUpdate.bind(this));
|
|
2893
|
+
this._space.listen(this._channel, this._handleSpaceMessage.bind(this));
|
|
2894
|
+
if (typeof window !== "undefined") {
|
|
2895
|
+
window.addEventListener("beforeunload", this._handleBeforeUnload.bind(this));
|
|
2896
|
+
} else if (typeof process !== "undefined") {
|
|
2897
|
+
process.on("exit", this._handleBeforeUnload.bind(this));
|
|
2898
|
+
}
|
|
2899
|
+
const encoderAwarenessQuery = encoding.createEncoder();
|
|
2900
|
+
encoding.writeVarUint(encoderAwarenessQuery, messageQueryAwareness);
|
|
2901
|
+
void this._space.postMessage(this._channel, encoding.toUint8Array(encoderAwarenessQuery));
|
|
2902
|
+
const encoderAwarenessState = encoding.createEncoder();
|
|
2903
|
+
encoding.writeVarUint(encoderAwarenessState, messageAwareness);
|
|
2904
|
+
encoding.writeVarUint8Array(encoderAwarenessState, YP.encodeAwarenessUpdate(this.awareness, [
|
|
2905
|
+
this._clientId
|
|
2906
|
+
]));
|
|
2907
|
+
void this._space.postMessage(this._channel, encoding.toUint8Array(encoderAwarenessState));
|
|
2908
|
+
}
|
|
2909
|
+
get awareness() {
|
|
2910
|
+
return this._awareness;
|
|
2911
|
+
}
|
|
2912
|
+
_handleAwarenessUpdate({ added, updated, removed }, origin) {
|
|
2913
|
+
log4("awareness update", {
|
|
2914
|
+
added,
|
|
2915
|
+
updated,
|
|
2916
|
+
removed,
|
|
2917
|
+
origin
|
|
2918
|
+
}, {
|
|
2919
|
+
F: __dxlog_file5,
|
|
2920
|
+
L: 122,
|
|
2921
|
+
S: this,
|
|
2922
|
+
C: (f, a) => f(...a)
|
|
2923
|
+
});
|
|
2924
|
+
const changedClients = added.concat(updated).concat(removed);
|
|
2925
|
+
const encoderAwareness = encoding.createEncoder();
|
|
2926
|
+
encoding.writeVarUint(encoderAwareness, messageAwareness);
|
|
2927
|
+
encoding.writeVarUint8Array(encoderAwareness, YP.encodeAwarenessUpdate(this._awareness, changedClients));
|
|
2928
|
+
void this._space.postMessage(this._channel, encoding.toUint8Array(encoderAwareness));
|
|
2929
|
+
}
|
|
2930
|
+
_handleSpaceMessage({ payload }) {
|
|
2931
|
+
log4("space message", payload, {
|
|
2932
|
+
F: __dxlog_file5,
|
|
2933
|
+
L: 131,
|
|
2934
|
+
S: this,
|
|
2935
|
+
C: (f, a) => f(...a)
|
|
2936
|
+
});
|
|
2937
|
+
const data = new Uint8Array(Array.from(Object.values(payload)));
|
|
2938
|
+
const encoder = this._readMessage(data);
|
|
2939
|
+
if (encoder) {
|
|
2940
|
+
void this._space.postMessage(this._channel, encoding.toUint8Array(encoder));
|
|
2941
|
+
}
|
|
2942
|
+
}
|
|
2943
|
+
_readMessage(message) {
|
|
2944
|
+
const decoder = decoding.createDecoder(message);
|
|
2945
|
+
const encoder = encoding.createEncoder();
|
|
2946
|
+
const messageType = decoding.readVarUint(decoder);
|
|
2947
|
+
let sendReply = false;
|
|
2948
|
+
switch (messageType) {
|
|
2949
|
+
case messageAwareness: {
|
|
2950
|
+
YP.applyAwarenessUpdate(this._awareness, decoding.readVarUint8Array(decoder), this);
|
|
2951
|
+
break;
|
|
2952
|
+
}
|
|
2953
|
+
case messageQueryAwareness: {
|
|
2954
|
+
encoding.writeVarUint(encoder, messageAwareness);
|
|
2955
|
+
encoding.writeVarUint8Array(encoder, YP.encodeAwarenessUpdate(this._awareness, Array.from(this._awareness.getStates().keys())));
|
|
2956
|
+
sendReply = true;
|
|
2957
|
+
break;
|
|
2958
|
+
}
|
|
2959
|
+
default: {
|
|
2960
|
+
console.error("Invalid message:", messageType);
|
|
2961
|
+
return encoder;
|
|
2962
|
+
}
|
|
2963
|
+
}
|
|
2964
|
+
if (!sendReply) {
|
|
2965
|
+
return null;
|
|
2966
|
+
}
|
|
2967
|
+
return encoder;
|
|
2968
|
+
}
|
|
2969
|
+
_handleBeforeUnload() {
|
|
2970
|
+
YP.removeAwarenessStates(this._awareness, [
|
|
2971
|
+
this._clientId
|
|
2972
|
+
], "window unload");
|
|
2973
|
+
}
|
|
2974
|
+
};
|
|
2975
|
+
|
|
2976
|
+
// packages/ui/react-ui-editor/src/hooks/useTextModel.ts
|
|
2977
|
+
var modelState = StateField5.define({
|
|
2978
|
+
create: () => void 0,
|
|
2979
|
+
update: (model) => model
|
|
2980
|
+
});
|
|
2981
|
+
var useTextModel = (props) => {
|
|
2982
|
+
const { identity, space, text } = props;
|
|
2983
|
+
const [model, setModel] = useState2();
|
|
2984
|
+
useEffect2(() => setModel(createModel(props)), [
|
|
2985
|
+
identity,
|
|
2986
|
+
space,
|
|
2987
|
+
text
|
|
2988
|
+
]);
|
|
2989
|
+
return model;
|
|
2990
|
+
};
|
|
2991
|
+
var createModel = (props) => {
|
|
2992
|
+
const { text } = props;
|
|
2993
|
+
if (isAutomergeObject(text)) {
|
|
2994
|
+
return createAutomergeModel(props);
|
|
2995
|
+
} else if (text?.doc) {
|
|
2996
|
+
return createYjsModel(props);
|
|
2997
|
+
} else {
|
|
2998
|
+
return void 0;
|
|
2999
|
+
}
|
|
3000
|
+
};
|
|
3001
|
+
|
|
3002
|
+
// packages/ui/react-ui-editor/src/hooks/automerge.ts
|
|
3003
|
+
var createAutomergeModel = ({ space, identity, text }) => {
|
|
3004
|
+
const obj = text;
|
|
3005
|
+
const doc = getRawDoc(obj, [
|
|
3006
|
+
obj.field
|
|
3007
|
+
]);
|
|
3008
|
+
const awarenessProvider = space && new SpaceAwarenessProvider({
|
|
3009
|
+
space,
|
|
3010
|
+
channel: `automerge.awareness.${obj.id}`,
|
|
3011
|
+
info: {
|
|
3012
|
+
displayName: identity?.profile?.displayName ?? "",
|
|
3013
|
+
color: cursorColor.color,
|
|
3014
|
+
lightColor: cursorColor.light
|
|
3015
|
+
},
|
|
3016
|
+
peerId: identity?.identityKey.toHex() ?? "Anonymous"
|
|
3017
|
+
});
|
|
3018
|
+
const model = {
|
|
3019
|
+
id: obj.id,
|
|
3020
|
+
content: doc,
|
|
3021
|
+
text: () => get4(doc.handle.docSync(), doc.path),
|
|
3022
|
+
// TODO(burdon): https://automerge.org/automerge/api-docs/js/functions/next.getCursor.html
|
|
3023
|
+
extension: [
|
|
3024
|
+
modelState.init(() => model),
|
|
3025
|
+
automerge3({
|
|
3026
|
+
handle: doc.handle,
|
|
3027
|
+
path: doc.path
|
|
3028
|
+
}),
|
|
3029
|
+
awarenessProvider && AwarenessProvider.of(awarenessProvider),
|
|
3030
|
+
awareness()
|
|
3031
|
+
].filter(isNotNullOrUndefined),
|
|
3032
|
+
peer: identity ? {
|
|
3033
|
+
id: identity.identityKey.toHex(),
|
|
3034
|
+
name: identity.profile?.displayName
|
|
3035
|
+
} : void 0
|
|
3036
|
+
};
|
|
3037
|
+
return model;
|
|
3038
|
+
};
|
|
2547
3039
|
export {
|
|
3040
|
+
AwarenessProvider,
|
|
2548
3041
|
BaseTextEditor,
|
|
3042
|
+
CursorConverter,
|
|
2549
3043
|
Doc,
|
|
2550
3044
|
EditorModes,
|
|
2551
3045
|
MarkdownEditor,
|
|
3046
|
+
RemoteSelectionsDecorator,
|
|
2552
3047
|
SpaceAwarenessProvider,
|
|
2553
3048
|
TextEditor,
|
|
2554
3049
|
TextKind,
|
|
3050
|
+
YAwarenessProvider,
|
|
2555
3051
|
YText,
|
|
2556
3052
|
YXmlFragment,
|
|
2557
3053
|
autocomplete,
|
|
3054
|
+
automerge3 as automerge,
|
|
3055
|
+
awareness,
|
|
2558
3056
|
basicBundle,
|
|
2559
3057
|
blast,
|
|
3058
|
+
callbackWrapper,
|
|
2560
3059
|
code2 as code,
|
|
2561
3060
|
codeTheme,
|
|
2562
3061
|
comments,
|
|
2563
|
-
|
|
3062
|
+
createAutomergeModel,
|
|
3063
|
+
createYjsModel,
|
|
3064
|
+
cursorConverter,
|
|
2564
3065
|
defaultMarkdownSlots,
|
|
2565
3066
|
defaultOptions,
|
|
2566
3067
|
defaultSlots,
|
|
2567
3068
|
defaultTextSlots,
|
|
2568
3069
|
defaultTheme,
|
|
3070
|
+
getToken,
|
|
2569
3071
|
hr,
|
|
2570
3072
|
image,
|
|
2571
3073
|
link,
|
|
@@ -2576,15 +3078,16 @@ export {
|
|
|
2576
3078
|
markdownTagsExtensions,
|
|
2577
3079
|
markdownTheme,
|
|
2578
3080
|
mention,
|
|
2579
|
-
mermaid,
|
|
2580
3081
|
modelState,
|
|
2581
3082
|
setCommentRange,
|
|
3083
|
+
setFocus,
|
|
3084
|
+
setSelection,
|
|
2582
3085
|
table,
|
|
2583
3086
|
tags2 as tags,
|
|
2584
3087
|
tasklist,
|
|
2585
3088
|
textTheme,
|
|
2586
|
-
tooltip,
|
|
2587
3089
|
typewriter,
|
|
2588
|
-
useTextModel
|
|
3090
|
+
useTextModel,
|
|
3091
|
+
yjs
|
|
2589
3092
|
};
|
|
2590
3093
|
//# sourceMappingURL=index.mjs.map
|