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