@dxos/react-ui-editor 0.3.10-next.ef70620 → 0.3.11-main.008b7c6
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 +2814 -1096
- 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 +63 -0
- package/dist/types/src/components/TextEditor/MarkdownEditor.stories.d.ts.map +1 -0
- package/dist/types/src/components/TextEditor/TextEditor.d.ts +9 -4
- package/dist/types/src/components/TextEditor/TextEditor.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/TextEditor.stories.d.ts +15 -4
- package/dist/types/src/components/TextEditor/TextEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/automerge.stories.d.ts +20 -0
- package/dist/types/src/components/TextEditor/automerge.stories.d.ts.map +1 -0
- package/dist/types/src/components/TextEditor/codemirror.stories.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/index.d.ts +1 -1
- package/dist/types/src/components/TextEditor/index.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/yjs.stories.d.ts +1 -0
- package/dist/types/src/components/TextEditor/yjs.stories.d.ts.map +1 -1
- package/dist/types/src/extensions/autocomplete.d.ts +10 -0
- package/dist/types/src/extensions/autocomplete.d.ts.map +1 -0
- package/dist/types/src/extensions/automerge/automerge.d.ts +9 -0
- package/dist/types/src/extensions/automerge/automerge.d.ts.map +1 -0
- package/dist/types/src/extensions/automerge/cursor.d.ts +5 -0
- package/dist/types/src/extensions/automerge/cursor.d.ts.map +1 -0
- package/dist/types/src/extensions/automerge/defs.d.ts +26 -0
- package/dist/types/src/extensions/automerge/defs.d.ts.map +1 -0
- package/dist/types/src/extensions/automerge/index.d.ts +3 -0
- package/dist/types/src/extensions/automerge/index.d.ts.map +1 -0
- package/dist/types/src/{automerge/automerge-plugin/PatchSemaphore.d.ts → extensions/automerge/semaphore.d.ts} +8 -5
- 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 +5 -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/{components/TextEditor/extensions/basic/bundle.d.ts → extensions/basic.d.ts} +3 -2
- package/dist/types/src/extensions/basic.d.ts.map +1 -0
- package/dist/types/src/extensions/blast.d.ts +25 -0
- package/dist/types/src/extensions/blast.d.ts.map +1 -0
- package/dist/types/src/extensions/code.d.ts +2 -0
- package/dist/types/src/extensions/code.d.ts.map +1 -0
- package/dist/types/src/extensions/comments.d.ts +50 -0
- package/dist/types/src/extensions/comments.d.ts.map +1 -0
- package/dist/types/src/extensions/hr.d.ts +2 -0
- package/dist/types/src/extensions/hr.d.ts.map +1 -0
- package/dist/types/src/extensions/image.d.ts +4 -0
- package/dist/types/src/extensions/image.d.ts.map +1 -0
- package/dist/types/src/extensions/index.d.ts +19 -0
- package/dist/types/src/extensions/index.d.ts.map +1 -0
- package/dist/types/src/extensions/link.d.ts +12 -0
- package/dist/types/src/extensions/link.d.ts.map +1 -0
- package/dist/types/src/extensions/listener.d.ts +10 -0
- package/dist/types/src/extensions/listener.d.ts.map +1 -0
- package/dist/types/src/extensions/markdown/bundle.d.ts +17 -0
- package/dist/types/src/extensions/markdown/bundle.d.ts.map +1 -0
- package/dist/types/src/extensions/markdown/highlight.d.ts +36 -0
- package/dist/types/src/extensions/markdown/highlight.d.ts.map +1 -0
- package/dist/types/src/extensions/markdown/index.d.ts +3 -0
- package/dist/types/src/extensions/markdown/index.d.ts.map +1 -0
- package/dist/types/src/extensions/mention.d.ts +6 -0
- package/dist/types/src/extensions/mention.d.ts.map +1 -0
- package/dist/types/src/extensions/mermaid.d.ts +3 -0
- package/dist/types/src/extensions/mermaid.d.ts.map +1 -0
- package/dist/types/src/extensions/table.d.ts +8 -0
- package/dist/types/src/extensions/table.d.ts.map +1 -0
- package/dist/types/src/extensions/tasklist.d.ts +3 -0
- package/dist/types/src/extensions/tasklist.d.ts.map +1 -0
- package/dist/types/src/extensions/typewriter.d.ts +10 -0
- package/dist/types/src/extensions/typewriter.d.ts.map +1 -0
- package/dist/types/src/extensions/yjs/cursor.d.ts +4 -0
- package/dist/types/src/extensions/yjs/cursor.d.ts.map +1 -0
- package/dist/types/src/extensions/yjs/index.d.ts +2 -0
- package/dist/types/src/extensions/yjs/index.d.ts.map +1 -0
- package/dist/types/src/extensions/yjs/yjs.d.ts +4 -0
- package/dist/types/src/extensions/yjs/yjs.d.ts.map +1 -0
- package/dist/types/src/extensions/yjs/yjs.test.d.ts +2 -0
- package/dist/types/src/extensions/yjs/yjs.test.d.ts.map +1 -0
- package/dist/types/src/hooks/automerge.d.ts +3 -0
- package/dist/types/src/hooks/automerge.d.ts.map +1 -0
- package/dist/types/src/hooks/awareness-provider.d.ts +28 -0
- package/dist/types/src/hooks/awareness-provider.d.ts.map +1 -0
- package/dist/types/src/hooks/index.d.ts +2 -1
- package/dist/types/src/hooks/index.d.ts.map +1 -1
- package/dist/types/src/hooks/useTextModel.d.ts +23 -8
- package/dist/types/src/hooks/useTextModel.d.ts.map +1 -1
- package/dist/types/src/hooks/{yjs/space-provider.d.ts → yjs.d.ts} +8 -8
- package/dist/types/src/hooks/yjs.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +3 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/styles/cursors.d.ts.map +1 -0
- package/dist/types/src/styles/index.d.ts +1 -0
- package/dist/types/src/styles/index.d.ts.map +1 -1
- package/dist/types/src/styles/markdown.d.ts +14 -11
- package/dist/types/src/styles/markdown.d.ts.map +1 -1
- package/dist/types/src/testing/replicator.d.ts +2 -2
- package/dist/types/src/testing/replicator.d.ts.map +1 -1
- package/dist/types/src/themes/default.d.ts +17 -0
- package/dist/types/src/themes/default.d.ts.map +1 -0
- package/dist/types/src/themes/index.d.ts +2 -0
- package/dist/types/src/themes/index.d.ts.map +1 -0
- package/dist/types/src/util/cursor.d.ts +17 -0
- package/dist/types/src/util/cursor.d.ts.map +1 -0
- package/dist/types/src/util/index.d.ts +3 -0
- package/dist/types/src/util/index.d.ts.map +1 -0
- package/dist/types/src/util/util.d.ts +5 -0
- package/dist/types/src/util/util.d.ts.map +1 -0
- package/package.json +29 -33
- package/src/components/TextEditor/MarkdownEditor.stories.tsx +426 -0
- package/src/components/TextEditor/TextEditor.stories.tsx +70 -43
- package/src/components/TextEditor/TextEditor.tsx +98 -52
- package/src/{automerge → components/TextEditor}/automerge.stories.tsx +69 -7
- package/src/components/TextEditor/codemirror.stories.ts +3 -2
- package/src/components/TextEditor/index.ts +1 -1
- package/src/components/TextEditor/yjs.stories.tsx +1 -0
- package/src/extensions/autocomplete.ts +59 -0
- package/src/extensions/automerge/automerge.ts +94 -0
- package/src/extensions/automerge/cursor.ts +51 -0
- package/src/extensions/automerge/defs.ts +62 -0
- package/src/extensions/automerge/index.ts +6 -0
- package/src/{automerge/automerge-plugin/PatchSemaphore.ts → extensions/automerge/semaphore.ts} +24 -18
- package/src/{automerge/automerge-plugin/codeMirrorToAm.ts → extensions/automerge/update-automerge.ts} +8 -6
- package/src/{automerge/automerge-plugin/amToCodemirror.ts → extensions/automerge/update-codemirror.ts} +15 -4
- package/src/extensions/awareness.ts +316 -0
- package/src/{components/TextEditor/extensions/basic/bundle.ts → extensions/basic.ts} +8 -4
- package/src/extensions/blast.ts +373 -0
- package/src/extensions/code.ts +99 -0
- package/src/extensions/comments.ts +421 -0
- package/src/extensions/hr.ts +74 -0
- package/src/extensions/image.ts +69 -0
- package/src/extensions/index.ts +22 -0
- package/src/extensions/link.ts +192 -0
- package/src/extensions/listener.ts +35 -0
- package/src/extensions/markdown/bundle.ts +106 -0
- package/src/extensions/markdown/highlight.ts +204 -0
- package/src/{components/TextEditor/extensions → extensions}/markdown/index.ts +1 -1
- package/src/extensions/mention.ts +31 -0
- package/src/extensions/mermaid.ts +11 -0
- package/src/extensions/table.ts +132 -0
- package/src/extensions/tasklist.ts +121 -0
- package/src/extensions/typewriter.ts +68 -0
- package/src/extensions/yjs/cursor.ts +21 -0
- package/src/extensions/yjs/index.ts +5 -0
- package/src/extensions/yjs/yjs.test.ts +35 -0
- package/src/extensions/yjs/yjs.ts +16 -0
- package/src/hooks/automerge.ts +52 -0
- package/src/hooks/awareness-provider.ts +120 -0
- package/src/hooks/index.ts +2 -1
- package/src/hooks/useTextModel.ts +53 -67
- package/src/hooks/{yjs/space-provider.ts → yjs.ts} +71 -19
- package/src/index.ts +3 -0
- package/src/styles/index.ts +1 -0
- package/src/styles/markdown.ts +33 -24
- package/src/testing/replicator.ts +16 -21
- package/src/themes/default.ts +302 -0
- package/src/themes/index.ts +5 -0
- package/src/util/cursor.ts +29 -0
- package/src/util/index.ts +6 -0
- package/src/util/util.ts +18 -0
- package/dist/types/src/automerge/automerge-plugin/PatchSemaphore.d.ts.map +0 -1
- package/dist/types/src/automerge/automerge-plugin/amToCodemirror.d.ts +0 -6
- package/dist/types/src/automerge/automerge-plugin/amToCodemirror.d.ts.map +0 -1
- package/dist/types/src/automerge/automerge-plugin/codeMirrorToAm.d.ts +0 -7
- package/dist/types/src/automerge/automerge-plugin/codeMirrorToAm.d.ts.map +0 -1
- package/dist/types/src/automerge/automerge-plugin/handle.d.ts +0 -9
- package/dist/types/src/automerge/automerge-plugin/handle.d.ts.map +0 -1
- package/dist/types/src/automerge/automerge-plugin/index.d.ts +0 -3
- package/dist/types/src/automerge/automerge-plugin/index.d.ts.map +0 -1
- package/dist/types/src/automerge/automerge-plugin/plugin.d.ts +0 -26
- package/dist/types/src/automerge/automerge-plugin/plugin.d.ts.map +0 -1
- package/dist/types/src/automerge/automerge.stories.d.ts +0 -9
- package/dist/types/src/automerge/automerge.stories.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/basic/bundle.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/basic/index.d.ts +0 -3
- package/dist/types/src/components/TextEditor/extensions/basic/index.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/basic/theme.d.ts +0 -10
- package/dist/types/src/components/TextEditor/extensions/basic/theme.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/change.d.ts +0 -7
- package/dist/types/src/components/TextEditor/extensions/change.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/hyperlink/hyperlinkDecoration.d.ts +0 -11
- package/dist/types/src/components/TextEditor/extensions/hyperlink/hyperlinkDecoration.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/hyperlink/hyperlinkTooltip.d.ts +0 -8
- package/dist/types/src/components/TextEditor/extensions/hyperlink/hyperlinkTooltip.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/hyperlink/hyperlinkWidget.d.ts +0 -10
- package/dist/types/src/components/TextEditor/extensions/hyperlink/hyperlinkWidget.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/hyperlink/index.d.ts +0 -4
- package/dist/types/src/components/TextEditor/extensions/hyperlink/index.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/index.d.ts +0 -5
- package/dist/types/src/components/TextEditor/extensions/index.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/markdown/bundle.d.ts +0 -8
- package/dist/types/src/components/TextEditor/extensions/markdown/bundle.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/markdown/tags.d.ts +0 -17
- package/dist/types/src/components/TextEditor/extensions/markdown/tags.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/markdown/theme.d.ts +0 -21
- package/dist/types/src/components/TextEditor/extensions/markdown/theme.d.ts.map +0 -1
- package/dist/types/src/hooks/useCollaboration.d.ts +0 -9
- package/dist/types/src/hooks/useCollaboration.d.ts.map +0 -1
- package/dist/types/src/hooks/yjs/cursors.d.ts.map +0 -1
- package/dist/types/src/hooks/yjs/index.d.ts +0 -3
- package/dist/types/src/hooks/yjs/index.d.ts.map +0 -1
- package/dist/types/src/hooks/yjs/space-provider.d.ts.map +0 -1
- package/src/automerge/automerge-plugin/handle.ts +0 -14
- package/src/automerge/automerge-plugin/index.ts +0 -6
- package/src/automerge/automerge-plugin/plugin.ts +0 -133
- package/src/components/TextEditor/extensions/basic/index.ts +0 -6
- package/src/components/TextEditor/extensions/basic/theme.ts +0 -49
- package/src/components/TextEditor/extensions/change.ts +0 -22
- package/src/components/TextEditor/extensions/hyperlink/hyperlinkDecoration.ts +0 -99
- package/src/components/TextEditor/extensions/hyperlink/hyperlinkTooltip.tsx +0 -61
- package/src/components/TextEditor/extensions/hyperlink/hyperlinkWidget.tsx +0 -119
- package/src/components/TextEditor/extensions/hyperlink/index.ts +0 -7
- package/src/components/TextEditor/extensions/index.ts +0 -8
- package/src/components/TextEditor/extensions/markdown/bundle.ts +0 -99
- package/src/components/TextEditor/extensions/markdown/tags.ts +0 -38
- package/src/components/TextEditor/extensions/markdown/theme.ts +0 -265
- package/src/hooks/useCollaboration.ts +0 -45
- package/src/hooks/yjs/index.ts +0 -6
- /package/dist/types/src/{hooks/yjs → styles}/cursors.d.ts +0 -0
- /package/src/{hooks/yjs → styles}/cursors.ts +0 -0
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { Extension } from '@codemirror/state';
|
|
2
|
-
import type { ThemeMode } from '@dxos/react-ui';
|
|
3
|
-
import type { EditorModel } from './useTextModel';
|
|
4
|
-
/**
|
|
5
|
-
* Replication and awareness (incl. remote selection).
|
|
6
|
-
* https://codemirror.net/docs/ref/#collab
|
|
7
|
-
*/
|
|
8
|
-
export declare const useCollaboration: (model: EditorModel, themeMode: ThemeMode) => Extension | undefined;
|
|
9
|
-
//# sourceMappingURL=useCollaboration.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useCollaboration.d.ts","sourceRoot":"","sources":["../../../../src/hooks/useCollaboration.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAMnD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAIhD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAGlD;;;GAGG;AACH,eAAO,MAAM,gBAAgB,UAAW,WAAW,aAAa,SAAS,KAAG,SAAS,GAAG,SAuBvF,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cursors.d.ts","sourceRoot":"","sources":["../../../../../src/hooks/yjs/cursors.ts"],"names":[],"mappings":"AAoBA,eAAO,MAAM,WAAW;;;CAAsD,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/hooks/yjs/index.ts"],"names":[],"mappings":"AAIA,cAAc,WAAW,CAAC;AAC1B,cAAc,kBAAkB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"space-provider.d.ts","sourceRoot":"","sources":["../../../../../src/hooks/yjs/space-provider.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,KAAK,iBAAiB,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,KAAK,GAAG,EAAE,MAAM,KAAK,CAAC;AAG/B,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAGrD,KAAK,SAAS,GAAG,iBAAiB,CAAC,SAAS,CAAC;AAO7C;;GAEG;AACH,qBAAa,sBAAuB,SAAQ,UAAU,CAAC,GAAG,CAAC;IACzD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAQ;IAC/B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAY;IACvC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;gBAEtB,EAAE,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,SAAS,EAAE,EAAE;QAAE,KAAK,EAAE,KAAK,CAAC;QAAC,GAAG,EAAE,GAAG,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,SAAS,CAAA;KAAE;IA+BlH,IAAI,SAAS,IAAI,SAAS,CAEzB;IAED,OAAO,CAAC,sBAAsB;IAY9B,OAAO,CAAC,mBAAmB;IAS3B,OAAO,CAAC,YAAY;IAoCpB,OAAO,CAAC,mBAAmB;CAG5B"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2023 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import type * as A from '@dxos/automerge/automerge';
|
|
6
|
-
|
|
7
|
-
export type IDocHandle<T = any> = {
|
|
8
|
-
docSync(): A.Doc<T> | undefined;
|
|
9
|
-
change(callback: A.ChangeFn<T>, options?: A.ChangeOptions<T>): void;
|
|
10
|
-
changeAt(heads: A.Heads, callback: A.ChangeFn<T>, options?: A.ChangeOptions<T>): string[] | undefined;
|
|
11
|
-
|
|
12
|
-
addListener(event: 'change', listener: () => void): void;
|
|
13
|
-
removeListener(event: 'change', listener: () => void): void;
|
|
14
|
-
};
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2023 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
Annotation,
|
|
7
|
-
type EditorState,
|
|
8
|
-
type Extension,
|
|
9
|
-
Facet,
|
|
10
|
-
StateEffect,
|
|
11
|
-
StateField,
|
|
12
|
-
type Transaction,
|
|
13
|
-
type TransactionSpec,
|
|
14
|
-
} from '@codemirror/state';
|
|
15
|
-
import { ViewPlugin, type EditorView, type PluginValue, type ViewUpdate } from '@codemirror/view';
|
|
16
|
-
|
|
17
|
-
import * as automerge from '@dxos/automerge/automerge';
|
|
18
|
-
import { type Heads, type Prop } from '@dxos/automerge/automerge';
|
|
19
|
-
|
|
20
|
-
import { PatchSemaphore } from './PatchSemaphore';
|
|
21
|
-
import { type IDocHandle } from './handle';
|
|
22
|
-
|
|
23
|
-
export type Value = {
|
|
24
|
-
lastHeads: Heads;
|
|
25
|
-
path: Prop[];
|
|
26
|
-
unreconciledTransactions: Transaction[];
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
type UpdateHeads = {
|
|
30
|
-
newHeads: Heads;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export const effectType = StateEffect.define<UpdateHeads>({});
|
|
34
|
-
|
|
35
|
-
export const updateHeads = (newHeads: Heads): StateEffect<UpdateHeads> => effectType.of({ newHeads });
|
|
36
|
-
|
|
37
|
-
export const getLastHeads = (state: EditorState, field: Field): Heads => state.field(field).lastHeads;
|
|
38
|
-
|
|
39
|
-
export const getPath = (state: EditorState, field: Field): Prop[] => state.field(field).path;
|
|
40
|
-
|
|
41
|
-
export type Field = StateField<Value>;
|
|
42
|
-
|
|
43
|
-
const semaphoreFacet = Facet.define<PatchSemaphore, PatchSemaphore>({
|
|
44
|
-
combine: (values) => values.at(-1)!, // Take last.
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
export type AutomergePlugin = {
|
|
48
|
-
extension: Extension;
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
export const automergePlugin = (handle: IDocHandle, path: Prop[]): AutomergePlugin => {
|
|
52
|
-
const stateField: StateField<Value> = StateField.define({
|
|
53
|
-
create: () => ({
|
|
54
|
-
lastHeads: automerge.getHeads(handle.docSync()!),
|
|
55
|
-
unreconciledTransactions: [],
|
|
56
|
-
path: path.slice(),
|
|
57
|
-
}),
|
|
58
|
-
update: (value: Value, tr: Transaction) => {
|
|
59
|
-
const result: Value = {
|
|
60
|
-
lastHeads: value.lastHeads,
|
|
61
|
-
unreconciledTransactions: value.unreconciledTransactions.slice(),
|
|
62
|
-
path: path.slice(),
|
|
63
|
-
};
|
|
64
|
-
let clearUnreconciled = false;
|
|
65
|
-
for (const effect of tr.effects) {
|
|
66
|
-
if (effect.is(effectType)) {
|
|
67
|
-
result.lastHeads = effect.value.newHeads;
|
|
68
|
-
clearUnreconciled = true;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
if (clearUnreconciled) {
|
|
72
|
-
result.unreconciledTransactions = [];
|
|
73
|
-
} else {
|
|
74
|
-
if (!isReconcileTx(tr)) {
|
|
75
|
-
result.unreconciledTransactions.push(tr);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
return result;
|
|
79
|
-
},
|
|
80
|
-
});
|
|
81
|
-
const semaphore = new PatchSemaphore(stateField);
|
|
82
|
-
|
|
83
|
-
const viewPlugin = ViewPlugin.fromClass(
|
|
84
|
-
class AutomergeCodemirrorViewPlugin implements PluginValue {
|
|
85
|
-
private _view: EditorView;
|
|
86
|
-
|
|
87
|
-
constructor(view: EditorView) {
|
|
88
|
-
this._view = view;
|
|
89
|
-
handle.addListener('change', this._handleChange);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
update(update: ViewUpdate) {
|
|
93
|
-
if (update.transactions.length > 0 && update.transactions.some((t) => !isReconcileTx(t))) {
|
|
94
|
-
queueMicrotask(() => {
|
|
95
|
-
this._view.state.facet(semaphoreFacet).reconcile(handle, this._view);
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
destroy() {
|
|
101
|
-
handle.addListener('change', this._handleChange);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
private _handleChange = () => {
|
|
105
|
-
this._view.state.facet(semaphoreFacet).reconcile(handle, this._view);
|
|
106
|
-
};
|
|
107
|
-
},
|
|
108
|
-
);
|
|
109
|
-
|
|
110
|
-
return {
|
|
111
|
-
extension: [stateField, semaphoreFacet.of(semaphore), viewPlugin],
|
|
112
|
-
};
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
export const reconcileAnnotationType = Annotation.define<unknown>();
|
|
116
|
-
|
|
117
|
-
export const isReconcileTx = (tr: Transaction): boolean => !!tr.annotation(reconcileAnnotationType);
|
|
118
|
-
|
|
119
|
-
export const makeReconcile = (tr: TransactionSpec) => {
|
|
120
|
-
if (tr.annotations != null) {
|
|
121
|
-
if (tr.annotations instanceof Array) {
|
|
122
|
-
tr.annotations = [...tr.annotations, reconcileAnnotationType.of({})];
|
|
123
|
-
} else {
|
|
124
|
-
tr.annotations = [tr.annotations, reconcileAnnotationType.of({})];
|
|
125
|
-
}
|
|
126
|
-
} else {
|
|
127
|
-
tr.annotations = [reconcileAnnotationType.of({})];
|
|
128
|
-
}
|
|
129
|
-
// return {
|
|
130
|
-
// ...tr,
|
|
131
|
-
// annotations: reconcileAnnotationType.of({})
|
|
132
|
-
// }
|
|
133
|
-
};
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2023 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import get from 'lodash.get';
|
|
6
|
-
import { type StyleSpec } from 'style-mod';
|
|
7
|
-
|
|
8
|
-
import { tokens } from '../../../../styles';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Minimal styles.
|
|
12
|
-
* NOTE: The '&' prefix denotes the CM editor root.
|
|
13
|
-
* https://codemirror.net/examples/styling
|
|
14
|
-
*/
|
|
15
|
-
// TODO(burdon): Remove?
|
|
16
|
-
export const basicTheme: {
|
|
17
|
-
[selector: string]: StyleSpec;
|
|
18
|
-
} = {
|
|
19
|
-
'&.cm-focused': {
|
|
20
|
-
outline: 'none',
|
|
21
|
-
},
|
|
22
|
-
'& .cm-line': {
|
|
23
|
-
paddingInline: 0,
|
|
24
|
-
lineHeight: 1.6,
|
|
25
|
-
minBlockSize: '1.6em',
|
|
26
|
-
},
|
|
27
|
-
'& .cm-line *': {
|
|
28
|
-
lineHeight: 1.6,
|
|
29
|
-
},
|
|
30
|
-
'& .cm-scroller': {
|
|
31
|
-
fontFamily: get(tokens, 'fontFamily.body', []).join(','),
|
|
32
|
-
overflow: 'visible',
|
|
33
|
-
},
|
|
34
|
-
'& .cm-content': {
|
|
35
|
-
padding: 0,
|
|
36
|
-
caretColor: 'black',
|
|
37
|
-
},
|
|
38
|
-
'.dark & .cm-content': {
|
|
39
|
-
caretColor: 'white',
|
|
40
|
-
},
|
|
41
|
-
'& .cm-tooltip': {
|
|
42
|
-
backgroundColor: 'transparent',
|
|
43
|
-
border: 'none',
|
|
44
|
-
},
|
|
45
|
-
'& .cm-link': {
|
|
46
|
-
color: get(tokens, 'extend.colors.primary.500'),
|
|
47
|
-
textDecoration: 'underline',
|
|
48
|
-
},
|
|
49
|
-
};
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2023 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { StateField } from '@codemirror/state';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Based on https://github.com/codemirror/dev/issues/44#issuecomment-789093799
|
|
9
|
-
* @param onChange
|
|
10
|
-
*/
|
|
11
|
-
// TODO(burdon): Name?
|
|
12
|
-
export const onChangeExtension = (onChange: (text: string) => void) =>
|
|
13
|
-
StateField.define({
|
|
14
|
-
create: () => null,
|
|
15
|
-
update: (_value, transaction) => {
|
|
16
|
-
if (transaction.docChanged && onChange) {
|
|
17
|
-
onChange(transaction.newDoc.toString());
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
return null;
|
|
21
|
-
},
|
|
22
|
-
});
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2023 DXOS.org
|
|
3
|
-
// Copyright CodeMirror
|
|
4
|
-
//
|
|
5
|
-
|
|
6
|
-
import { syntaxTree } from '@codemirror/language';
|
|
7
|
-
import { type EditorState, type RangeSet, RangeSetBuilder, StateField, type Transaction } from '@codemirror/state';
|
|
8
|
-
import { Decoration, EditorView, WidgetType } from '@codemirror/view';
|
|
9
|
-
|
|
10
|
-
// Adapted from:
|
|
11
|
-
// https://codemirror.net/try/?c=aW1wb3J0IHsgYmFzaWNTZXR1cCwgRWRpdG9yVmlldyB9IGZyb20gImNvZGVtaXJyb3IiCmltcG9ydCB7IG1hcmtkb3duIH0gZnJvbSAiQGNvZGVtaXJyb3IvbGFuZy1tYXJrZG93biIKaW1wb3J0IHsgc3ludGF4VHJlZSB9IGZyb20gIkBjb2RlbWlycm9yL2xhbmd1YWdlIjsKaW1wb3J0IHsgRWRpdG9yU3RhdGUsIFJhbmdlU2V0QnVpbGRlciwgU3RhdGVGaWVsZCB9IGZyb20gIkBjb2RlbWlycm9yL3N0YXRlIjsKaW1wb3J0IHsgRGVjb3JhdGlvbiwgV2lkZ2V0VHlwZSB9IGZyb20gIkBjb2RlbWlycm9yL3ZpZXciOwoKY2xhc3MgTGluayBleHRlbmRzIFdpZGdldFR5cGUgewogIGNvbnN0cnVjdG9yKHRleHQsIHVybCkgewogICAgc3VwZXIoKQogICAgdGhpcy50ZXh0ID0gdGV4dAogICAgdGhpcy51cmwgPSB1cmwKICB9CiAgZXEob3RoZXIpIHsgcmV0dXJuIHRoaXMudGV4dCA9PSBvdGhlci50ZXh0ICYmIHRoaXMudXJsID09IG90aGVyLnVybCB9CiAgdG9ET00oKSB7CiAgICBsZXQgbGluayA9IGRvY3VtZW50LmNyZWF0ZUVsZW1lbnQoImEiKQogICAgbGluay50ZXh0Q29udGVudCA9IHRoaXMudGV4dAogICAgbGluay5ocmVmID0gdGhpcy51cmwKICAgIHJldHVybiBsaW5rOwogIH0KfQoKbGV0IGRlY29yYXRpb25zRmllbGQgPSBTdGF0ZUZpZWxkLmRlZmluZSh7CiAgY3JlYXRlKCkgewogICAgcmV0dXJuIERlY29yYXRpb24ubm9uZTsKICB9LAogIHVwZGF0ZShfLCB0cikgewogICAgY29uc3QgYnVpbGRlciA9IG5ldyBSYW5nZVNldEJ1aWxkZXIoKTsKICAgIGxldCBjdXJzb3IgPSB0ci5zdGF0ZS5zZWxlY3Rpb24ubWFpbi5oZWFkOwogICAgc3ludGF4VHJlZSh0ci5zdGF0ZSkuaXRlcmF0ZSh7CiAgICAgIGVudGVyOiAobm9kZSkgPT4gewogICAgICAgIGlmICgoY3Vyc29yIDwgbm9kZS5mcm9tIHx8IGN1cnNvciA+IG5vZGUudG8pICYmIG5vZGUubmFtZSA9PSAiTGluayIpIHsKICAgICAgICAgIGxldCBtYXJrcyA9IG5vZGUubm9kZS5nZXRDaGlsZHJlbigiTGlua01hcmsiKTsKICAgICAgICAgIGxldCB0ZXh0ID0gbWFya3MubGVuZ3RoID49IDIgPyB0ci5zdGF0ZS5zbGljZURvYyhtYXJrc1swXS50bywgbWFya3NbMV0uZnJvbSkgOiAiIgoKICAgICAgICAgIGxldCB1cmxOb2RlID0gbm9kZS5ub2RlLmdldENoaWxkKCJVUkwiKTsKICAgICAgICAgIGxldCB1cmwgPSB1cmxOb2RlID8gdHIuc3RhdGUuc2xpY2VEb2ModXJsTm9kZS5mcm9tLCB1cmxOb2RlLnRvKSA6ICIiCiAgICAgICAgICBidWlsZGVyLmFkZChub2RlLmZyb20sIG5vZGUudG8sIERlY29yYXRpb24ucmVwbGFjZSh7CiAgICAgICAgICAgIHdpZGdldDogbmV3IExpbmsodGV4dCwgdXJsKSwKICAgICAgICAgIH0pLAogICAgICAgICAgICAgICAgICAgICApOwogICAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgICAgIH0KICAgICAgICByZXR1cm4gdHJ1ZTsKICAgICAgfSwKICAgIH0pOwogICAgcmV0dXJuIGJ1aWxkZXIuZmluaXNoKCk7CiAgfSwKICBwcm92aWRlOiAoZikgPT4gRWRpdG9yVmlldy5kZWNvcmF0aW9ucy5mcm9tKGYpLAp9KTsKCmxldCB2aWV3ID0gbmV3IEVkaXRvclZpZXcoewogIGRvYzogIiMgSGVsbG8gV29ybGRcblxuW1Rlc3RdKGh0dHBzOi8vZXhhbXBsZS5jb20pXG5cblxuIiwKICBleHRlbnNpb25zOiBbZGVjb3JhdGlvbnNGaWVsZCwgbWFya2Rvd24oKV0sCiAgcGFyZW50OiBkb2N1bWVudC5ib2R5LAp9KTsKCnZpZXcuZm9jdXMoKTs=
|
|
12
|
-
// https://discuss.codemirror.net/t/link-widget-is-clicked-only-if-editor-is-out-of-focus/7433
|
|
13
|
-
|
|
14
|
-
// TODO(burdon): Adapt to make all markdown editable?
|
|
15
|
-
|
|
16
|
-
// TODO(burdon): Research overlays.
|
|
17
|
-
// https://stackoverflow.com/questions/26933344/codemirror-detect-and-create-links-inside-editor
|
|
18
|
-
// https://codemirror.net/5/doc/manual.html#addOverlay
|
|
19
|
-
// https://codemirror.net/5/demo/simplemode.html
|
|
20
|
-
// https://codemirror.net/5/demo/search.html (Search dialog).
|
|
21
|
-
|
|
22
|
-
class Link extends WidgetType {
|
|
23
|
-
constructor(private readonly _anchor: number, private readonly _text: string, private readonly _url?: string) {
|
|
24
|
-
super();
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
override eq(other: any) {
|
|
28
|
-
return this._text === other.text && this._url === other.url;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
toDOM(view: EditorView) {
|
|
32
|
-
const link = document.createElement('a');
|
|
33
|
-
link.setAttribute('class', 'cm-link');
|
|
34
|
-
link.textContent = this._text;
|
|
35
|
-
if (this._url) {
|
|
36
|
-
link.setAttribute('target', '_blank');
|
|
37
|
-
link.href = this._url;
|
|
38
|
-
} else {
|
|
39
|
-
link.onclick = () => {
|
|
40
|
-
view.dispatch({
|
|
41
|
-
selection: {
|
|
42
|
-
anchor: this._anchor,
|
|
43
|
-
},
|
|
44
|
-
});
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return link;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
type HyperlinkDecorationConfig = {
|
|
53
|
-
link?: boolean;
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Creates a state field to replace AST elements with a hyperlink widget.
|
|
58
|
-
* https://codemirror.net/docs/ref/#state.StateField
|
|
59
|
-
*/
|
|
60
|
-
export const hyperlinkDecoration = ({ link }: HyperlinkDecorationConfig = {}) => {
|
|
61
|
-
return StateField.define<RangeSet<any>>({
|
|
62
|
-
create: (state) => update(state, link),
|
|
63
|
-
update: (_: RangeSet<any>, tr: Transaction) => update(tr.state, link),
|
|
64
|
-
provide: (field) => EditorView.decorations.from(field),
|
|
65
|
-
});
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
const update = (state: EditorState, link?: boolean) => {
|
|
69
|
-
const builder = new RangeSetBuilder();
|
|
70
|
-
const cursor = state.selection.main.head;
|
|
71
|
-
syntaxTree(state).iterate({
|
|
72
|
-
enter: (node) => {
|
|
73
|
-
// Check if cursor is inside text.
|
|
74
|
-
if (cursor < node.from || cursor > node.to) {
|
|
75
|
-
if (node.name === 'Link') {
|
|
76
|
-
const marks = node.node.getChildren('LinkMark');
|
|
77
|
-
const text = marks.length >= 2 ? state.sliceDoc(marks[0].to, marks[1].from) : '';
|
|
78
|
-
|
|
79
|
-
const urlNode = node.node.getChild('URL');
|
|
80
|
-
const url = urlNode ? state.sliceDoc(urlNode.from, urlNode.to) : '';
|
|
81
|
-
|
|
82
|
-
builder.add(
|
|
83
|
-
node.from,
|
|
84
|
-
node.to,
|
|
85
|
-
Decoration.replace({
|
|
86
|
-
widget: new Link(node.from, text, link ? url : undefined),
|
|
87
|
-
}),
|
|
88
|
-
);
|
|
89
|
-
|
|
90
|
-
return false;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
return true;
|
|
95
|
-
},
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
return builder.finish();
|
|
99
|
-
};
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2023 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { hoverTooltip } from '@codemirror/view';
|
|
6
|
-
|
|
7
|
-
import { tooltipContent } from '@dxos/react-ui-theme';
|
|
8
|
-
|
|
9
|
-
const markdownLinkRegexp = /\[([^\]]+)]\(([^)]+)\)/;
|
|
10
|
-
|
|
11
|
-
export type OnHyperlinkHover = (el: Element, url: string) => void;
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* https://codemirror.net/examples/tooltip
|
|
15
|
-
* https://codemirror.net/docs/ref/#view.hoverTooltip
|
|
16
|
-
* https://github.com/codemirror/view/blob/main/src/tooltip.ts
|
|
17
|
-
*/
|
|
18
|
-
// TODO(burdon): Create config object.
|
|
19
|
-
export const createHyperlinkTooltip = (onHover: OnHyperlinkHover, regexp = markdownLinkRegexp) =>
|
|
20
|
-
hoverTooltip((view, pos) => {
|
|
21
|
-
const { from, text } = view.state.doc.lineAt(pos);
|
|
22
|
-
const p = pos - from;
|
|
23
|
-
|
|
24
|
-
let idx = 0;
|
|
25
|
-
let match;
|
|
26
|
-
do {
|
|
27
|
-
match = text.substring(idx).match(regexp);
|
|
28
|
-
if (!match) {
|
|
29
|
-
match = undefined;
|
|
30
|
-
break;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
idx = text.indexOf(match[0]);
|
|
34
|
-
if (p >= idx && p < idx + match[0].length) {
|
|
35
|
-
break;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
idx += match[0].length;
|
|
39
|
-
} while (true);
|
|
40
|
-
|
|
41
|
-
if (!match) {
|
|
42
|
-
return null;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const [, , url] = match ?? [];
|
|
46
|
-
|
|
47
|
-
return {
|
|
48
|
-
pos: idx + from,
|
|
49
|
-
end: idx + from + match[0].length,
|
|
50
|
-
above: true,
|
|
51
|
-
create: () => {
|
|
52
|
-
const el = document.createElement('a');
|
|
53
|
-
el.innerText = '_'; // Required so doesn't collapse.
|
|
54
|
-
el.className = tooltipContent({}, 'mb-2 p-1');
|
|
55
|
-
el.setAttribute('target', '_blank');
|
|
56
|
-
el.setAttribute('href', url);
|
|
57
|
-
onHover(el, url);
|
|
58
|
-
return { dom: el };
|
|
59
|
-
},
|
|
60
|
-
};
|
|
61
|
-
});
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2023 DXOS.org
|
|
3
|
-
// Adapted from: https://github.com/uiwjs/react-codemirror/blob/master/extensions/hyper-link/src/index.ts
|
|
4
|
-
//
|
|
5
|
-
|
|
6
|
-
import { type Extension } from '@codemirror/state';
|
|
7
|
-
import {
|
|
8
|
-
Decoration,
|
|
9
|
-
type DecorationSet,
|
|
10
|
-
EditorView,
|
|
11
|
-
MatchDecorator,
|
|
12
|
-
ViewPlugin,
|
|
13
|
-
type ViewUpdate,
|
|
14
|
-
} from '@codemirror/view';
|
|
15
|
-
|
|
16
|
-
// Notes: Can't edit widget content (or cursor nav through them).
|
|
17
|
-
// - https://discuss.codemirror.net/t/focusing-inputs-within-widgets/5178/7
|
|
18
|
-
// Widgets intentionally always get set to contenteditable=false,
|
|
19
|
-
// or they would become part of CodeMirror’s editable content element.
|
|
20
|
-
// You should be able to introduce new contenteditable=true child elements inside of them.
|
|
21
|
-
|
|
22
|
-
const markdownLinkRegexp = /\[([^\]]+)]\(([^)]+)\)(!?)/gi;
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Custom link decorator.
|
|
26
|
-
* NOTE: The default markdown extension formats links by default.
|
|
27
|
-
* @deprecated
|
|
28
|
-
*/
|
|
29
|
-
const linkDecorator = () =>
|
|
30
|
-
new MatchDecorator({
|
|
31
|
-
regexp: markdownLinkRegexp,
|
|
32
|
-
decorate: (add, from, to, match, view) => {
|
|
33
|
-
const [_, label, url] = match;
|
|
34
|
-
const p0 = {
|
|
35
|
-
start: from,
|
|
36
|
-
end: from + 1,
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
const p1 = {
|
|
40
|
-
start: from + 1,
|
|
41
|
-
end: from + 1 + label.length,
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
const p2 = {
|
|
45
|
-
start: p1.end,
|
|
46
|
-
end: p1.end + 1,
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
const p3 = {
|
|
50
|
-
start: p1.end + 1,
|
|
51
|
-
end: p1.end + 1 + url.length + 2,
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
add(
|
|
55
|
-
p0.start,
|
|
56
|
-
p0.end,
|
|
57
|
-
Decoration.mark({ class: 'cm-hyperlink-bracket', _attributes: { style: 'display: none' } }),
|
|
58
|
-
);
|
|
59
|
-
add(p1.start, p1.end, Decoration.mark({ class: 'cm-hyperlink-label' }));
|
|
60
|
-
add(
|
|
61
|
-
p2.start,
|
|
62
|
-
p2.end,
|
|
63
|
-
Decoration.mark({ class: 'cm-hyperlink-bracket', _attributes: { style: 'display: none' } }),
|
|
64
|
-
);
|
|
65
|
-
add(p3.start, p3.end, Decoration.mark({ class: 'cm-hyperlink-url', _attributes: { style: 'display: none' } }));
|
|
66
|
-
},
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
export function hyperLinkExtension() {
|
|
70
|
-
return ViewPlugin.fromClass(
|
|
71
|
-
class HyperLinkView {
|
|
72
|
-
readonly decorator: MatchDecorator;
|
|
73
|
-
decorations: DecorationSet;
|
|
74
|
-
constructor(view: EditorView) {
|
|
75
|
-
this.decorator = linkDecorator();
|
|
76
|
-
this.decorations = this.decorator.createDeco(view);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
update(update: ViewUpdate) {
|
|
80
|
-
if (update.docChanged || update.viewportChanged) {
|
|
81
|
-
this.decorations = this.decorator.updateDeco(update, this.decorations);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
},
|
|
85
|
-
{
|
|
86
|
-
decorations: (view) => view.decorations,
|
|
87
|
-
eventHandlers: {
|
|
88
|
-
// TODO(burdon): CLick to expand link.
|
|
89
|
-
// https://discuss.codemirror.net/t/decorator-iteration-on-click-event/4226/2
|
|
90
|
-
mousedown: function (event, view) {
|
|
91
|
-
const pos = view.posAtDOM(event.target as Node);
|
|
92
|
-
if (pos !== 0) {
|
|
93
|
-
console.log(this);
|
|
94
|
-
}
|
|
95
|
-
},
|
|
96
|
-
// TODO(burdon): Hide when cursor moves away.
|
|
97
|
-
keydown: (event, view) => {
|
|
98
|
-
view.update([]);
|
|
99
|
-
},
|
|
100
|
-
},
|
|
101
|
-
},
|
|
102
|
-
);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
export const hyperlinkStyle = EditorView.baseTheme({
|
|
106
|
-
'.cm-hyperlink-label': {
|
|
107
|
-
cursor: 'pointer',
|
|
108
|
-
textDecoration: 'underline',
|
|
109
|
-
},
|
|
110
|
-
'.cm-hyperlink-bracket': {
|
|
111
|
-
opacity: 0.2,
|
|
112
|
-
},
|
|
113
|
-
'.cm-hyperlink-url': {
|
|
114
|
-
opacity: 0.5,
|
|
115
|
-
fontFamily: 'monospace',
|
|
116
|
-
},
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
export const hyperlinkWidget: Extension = [hyperLinkExtension(), hyperlinkStyle];
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2023 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { closeBrackets, closeBracketsKeymap } from '@codemirror/autocomplete';
|
|
6
|
-
import { defaultKeymap, history, historyKeymap, indentWithTab } from '@codemirror/commands';
|
|
7
|
-
import { markdownLanguage, markdown } from '@codemirror/lang-markdown';
|
|
8
|
-
import {
|
|
9
|
-
bracketMatching,
|
|
10
|
-
defaultHighlightStyle,
|
|
11
|
-
foldKeymap,
|
|
12
|
-
indentOnInput,
|
|
13
|
-
syntaxHighlighting,
|
|
14
|
-
} from '@codemirror/language';
|
|
15
|
-
import { languages } from '@codemirror/language-data';
|
|
16
|
-
import { lintKeymap } from '@codemirror/lint';
|
|
17
|
-
import { highlightSelectionMatches, searchKeymap } from '@codemirror/search';
|
|
18
|
-
import { EditorState, type Extension } from '@codemirror/state';
|
|
19
|
-
import { oneDarkHighlightStyle } from '@codemirror/theme-one-dark';
|
|
20
|
-
import {
|
|
21
|
-
crosshairCursor,
|
|
22
|
-
drawSelection,
|
|
23
|
-
dropCursor,
|
|
24
|
-
EditorView,
|
|
25
|
-
highlightActiveLine,
|
|
26
|
-
highlightActiveLineGutter,
|
|
27
|
-
highlightSpecialChars,
|
|
28
|
-
keymap,
|
|
29
|
-
placeholder,
|
|
30
|
-
rectangularSelection,
|
|
31
|
-
} from '@codemirror/view';
|
|
32
|
-
// import { GFM } from '@lezer/markdown';
|
|
33
|
-
|
|
34
|
-
import type { ThemeMode } from '@dxos/react-ui';
|
|
35
|
-
|
|
36
|
-
import { markdownTagsExtension } from './tags';
|
|
37
|
-
import { markdownHighlightStyle } from './theme';
|
|
38
|
-
|
|
39
|
-
export type MarkdownBundleOptions = {
|
|
40
|
-
themeMode?: ThemeMode;
|
|
41
|
-
placeholder?: string;
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
export const markdownBundle = ({ themeMode, placeholder: _placeholder }: MarkdownBundleOptions): Extension[] => {
|
|
45
|
-
// All of https://github.com/codemirror/basic-setup minus line numbers and fold gutter.
|
|
46
|
-
// https://codemirror.net/docs/ref/#codemirror.basicSetup
|
|
47
|
-
return [
|
|
48
|
-
bracketMatching(),
|
|
49
|
-
closeBrackets(),
|
|
50
|
-
_placeholder && placeholder(_placeholder),
|
|
51
|
-
|
|
52
|
-
EditorState.allowMultipleSelections.of(true),
|
|
53
|
-
EditorView.lineWrapping,
|
|
54
|
-
|
|
55
|
-
// autocompletion(),
|
|
56
|
-
crosshairCursor(),
|
|
57
|
-
dropCursor(),
|
|
58
|
-
drawSelection(),
|
|
59
|
-
highlightActiveLine(),
|
|
60
|
-
highlightActiveLineGutter(),
|
|
61
|
-
highlightSelectionMatches(),
|
|
62
|
-
highlightSpecialChars(),
|
|
63
|
-
history(),
|
|
64
|
-
indentOnInput(),
|
|
65
|
-
rectangularSelection(),
|
|
66
|
-
|
|
67
|
-
keymap.of([
|
|
68
|
-
...closeBracketsKeymap,
|
|
69
|
-
// ...completionKeymap,
|
|
70
|
-
...defaultKeymap,
|
|
71
|
-
...foldKeymap,
|
|
72
|
-
...historyKeymap,
|
|
73
|
-
...lintKeymap,
|
|
74
|
-
...searchKeymap,
|
|
75
|
-
indentWithTab,
|
|
76
|
-
]),
|
|
77
|
-
|
|
78
|
-
// Main extension.
|
|
79
|
-
// https://github.com/codemirror/lang-markdown
|
|
80
|
-
markdown({
|
|
81
|
-
base: markdownLanguage,
|
|
82
|
-
codeLanguages: languages,
|
|
83
|
-
extensions: [
|
|
84
|
-
// TODO(burdon): This seems to upgrade the parser.
|
|
85
|
-
// GitHub flavored markdown bundle: Table, TaskList, Strikethrough, and Autolink.
|
|
86
|
-
// https://github.com/lezer-parser/markdown?tab=readme-ov-file#github-flavored-markdown
|
|
87
|
-
// https://github.github.com/gfm
|
|
88
|
-
// GFM,
|
|
89
|
-
|
|
90
|
-
// Custom styling.
|
|
91
|
-
markdownTagsExtension,
|
|
92
|
-
],
|
|
93
|
-
}),
|
|
94
|
-
|
|
95
|
-
// TODO(thure): All but one rule here apply to both themes; rename or refactor.
|
|
96
|
-
syntaxHighlighting(markdownHighlightStyle),
|
|
97
|
-
themeMode === 'dark' ? syntaxHighlighting(oneDarkHighlightStyle) : syntaxHighlighting(defaultHighlightStyle),
|
|
98
|
-
].filter(Boolean) as Extension[];
|
|
99
|
-
};
|