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