@dxos/react-ui-editor 0.3.10-main.ee543cf → 0.3.10-next.3e4f36f
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 +735 -731
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/types/src/automerge/automerge-plugin/PatchSemaphore.d.ts.map +1 -0
- package/dist/types/src/automerge/automerge-plugin/amToCodemirror.d.ts.map +1 -0
- package/dist/types/src/automerge/automerge-plugin/codeMirrorToAm.d.ts.map +1 -0
- package/dist/types/src/automerge/automerge-plugin/handle.d.ts.map +1 -0
- package/dist/types/src/automerge/automerge-plugin/index.d.ts.map +1 -0
- package/dist/types/src/automerge/automerge-plugin/plugin.d.ts.map +1 -0
- package/dist/types/src/automerge/automerge.stories.d.ts.map +1 -0
- package/dist/types/src/components/TextEditor/TextEditor.d.ts +2 -4
- package/dist/types/src/components/TextEditor/TextEditor.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/TextEditor.stories.d.ts +4 -9
- package/dist/types/src/components/TextEditor/TextEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/extensions/{basic.d.ts → basic/bundle.d.ts} +1 -1
- package/dist/types/src/components/TextEditor/extensions/basic/bundle.d.ts.map +1 -0
- package/dist/types/src/components/TextEditor/extensions/basic/index.d.ts +3 -0
- package/dist/types/src/components/TextEditor/extensions/basic/index.d.ts.map +1 -0
- package/dist/types/src/components/TextEditor/extensions/basic/theme.d.ts +10 -0
- package/dist/types/src/components/TextEditor/extensions/basic/theme.d.ts.map +1 -0
- package/dist/types/src/components/TextEditor/extensions/change.d.ts +7 -0
- package/dist/types/src/components/TextEditor/extensions/change.d.ts.map +1 -0
- package/dist/types/src/components/TextEditor/extensions/hyperlink/hyperlinkDecoration.d.ts +11 -0
- package/dist/types/src/components/TextEditor/extensions/hyperlink/hyperlinkDecoration.d.ts.map +1 -0
- package/dist/types/src/components/TextEditor/extensions/hyperlink/hyperlinkTooltip.d.ts +8 -0
- package/dist/types/src/components/TextEditor/extensions/hyperlink/hyperlinkTooltip.d.ts.map +1 -0
- package/dist/types/src/components/TextEditor/extensions/{experimental.d.ts → hyperlink/hyperlinkWidget.d.ts} +2 -2
- package/dist/types/src/components/TextEditor/extensions/hyperlink/hyperlinkWidget.d.ts.map +1 -0
- package/dist/types/src/components/TextEditor/extensions/hyperlink/index.d.ts +4 -0
- package/dist/types/src/components/TextEditor/extensions/hyperlink/index.d.ts.map +1 -0
- package/dist/types/src/components/TextEditor/extensions/index.d.ts +2 -5
- package/dist/types/src/components/TextEditor/extensions/index.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/extensions/markdown/bundle.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/extensions/markdown/index.d.ts +1 -1
- package/dist/types/src/components/TextEditor/extensions/markdown/index.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/extensions/markdown/tags.d.ts +17 -0
- package/dist/types/src/components/TextEditor/extensions/markdown/tags.d.ts.map +1 -0
- package/dist/types/src/components/TextEditor/extensions/markdown/theme.d.ts +21 -0
- package/dist/types/src/components/TextEditor/extensions/markdown/theme.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/TextEditor/yjs.stories.d.ts +0 -1
- package/dist/types/src/components/TextEditor/yjs.stories.d.ts.map +1 -1
- package/dist/types/src/hooks/index.d.ts +1 -0
- package/dist/types/src/hooks/index.d.ts.map +1 -1
- package/dist/types/src/hooks/useCollaboration.d.ts +9 -0
- package/dist/types/src/hooks/useCollaboration.d.ts.map +1 -0
- package/dist/types/src/hooks/useTextModel.d.ts +4 -4
- package/dist/types/src/hooks/useTextModel.d.ts.map +1 -1
- package/dist/types/src/styles/markdown.d.ts +10 -12
- package/dist/types/src/styles/markdown.d.ts.map +1 -1
- package/package.json +32 -20
- package/src/{hooks/automerge → automerge}/automerge.stories.tsx +1 -2
- package/src/components/TextEditor/TextEditor.stories.tsx +43 -46
- package/src/components/TextEditor/TextEditor.tsx +45 -59
- package/src/components/TextEditor/extensions/{basic.ts → basic/bundle.ts} +2 -4
- package/src/components/TextEditor/extensions/basic/index.ts +6 -0
- package/src/components/TextEditor/extensions/basic/theme.ts +49 -0
- package/src/components/TextEditor/extensions/{listener.ts → change.ts} +3 -3
- package/src/components/TextEditor/extensions/{link.ts → hyperlink/hyperlinkDecoration.ts} +31 -68
- package/src/components/TextEditor/extensions/{tooltip.tsx → hyperlink/hyperlinkTooltip.tsx} +9 -9
- package/src/components/TextEditor/extensions/{experimental.tsx → hyperlink/hyperlinkWidget.tsx} +2 -17
- package/src/components/TextEditor/extensions/hyperlink/index.ts +7 -0
- package/src/components/TextEditor/extensions/index.ts +2 -5
- package/src/components/TextEditor/extensions/markdown/bundle.ts +11 -15
- package/src/components/TextEditor/extensions/markdown/index.ts +1 -1
- package/src/components/TextEditor/extensions/markdown/tags.ts +38 -0
- package/src/components/TextEditor/extensions/markdown/theme.ts +265 -0
- package/src/components/TextEditor/index.ts +0 -3
- package/src/components/TextEditor/yjs.stories.tsx +0 -1
- package/src/hooks/index.ts +1 -0
- package/src/hooks/useCollaboration.ts +45 -0
- package/src/hooks/useTextModel.ts +40 -50
- package/src/styles/markdown.ts +24 -26
- package/src/testing/replicator.ts +2 -2
- package/dist/types/src/components/TextEditor/MarkdownEditor.stories.d.ts +0 -35
- package/dist/types/src/components/TextEditor/MarkdownEditor.stories.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/autocomplete.d.ts +0 -9
- package/dist/types/src/components/TextEditor/extensions/autocomplete.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/basic.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/experimental.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/link.d.ts +0 -11
- package/dist/types/src/components/TextEditor/extensions/link.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/listener.d.ts +0 -7
- package/dist/types/src/components/TextEditor/extensions/listener.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/markdown/highlight.d.ts +0 -31
- package/dist/types/src/components/TextEditor/extensions/markdown/highlight.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/tasklist.d.ts +0 -5
- 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/themes/default.d.ts +0 -17
- package/dist/types/src/components/TextEditor/themes/default.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/themes/index.d.ts +0 -2
- package/dist/types/src/components/TextEditor/themes/index.d.ts.map +0 -1
- package/dist/types/src/hooks/automerge/PatchSemaphore.d.ts.map +0 -1
- package/dist/types/src/hooks/automerge/amToCodemirror.d.ts.map +0 -1
- package/dist/types/src/hooks/automerge/automerge.stories.d.ts.map +0 -1
- package/dist/types/src/hooks/automerge/codeMirrorToAm.d.ts.map +0 -1
- package/dist/types/src/hooks/automerge/handle.d.ts.map +0 -1
- package/dist/types/src/hooks/automerge/index.d.ts.map +0 -1
- package/dist/types/src/hooks/automerge/plugin.d.ts.map +0 -1
- package/src/components/TextEditor/MarkdownEditor.stories.tsx +0 -242
- package/src/components/TextEditor/extensions/autocomplete.ts +0 -72
- package/src/components/TextEditor/extensions/markdown/highlight.ts +0 -166
- package/src/components/TextEditor/extensions/tasklist.ts +0 -113
- package/src/components/TextEditor/themes/default.ts +0 -170
- package/src/components/TextEditor/themes/index.ts +0 -5
- /package/dist/types/src/{hooks/automerge → automerge/automerge-plugin}/PatchSemaphore.d.ts +0 -0
- /package/dist/types/src/{hooks/automerge → automerge/automerge-plugin}/amToCodemirror.d.ts +0 -0
- /package/dist/types/src/{hooks/automerge → automerge/automerge-plugin}/codeMirrorToAm.d.ts +0 -0
- /package/dist/types/src/{hooks/automerge → automerge/automerge-plugin}/handle.d.ts +0 -0
- /package/dist/types/src/{hooks/automerge → automerge/automerge-plugin}/index.d.ts +0 -0
- /package/dist/types/src/{hooks/automerge → automerge/automerge-plugin}/plugin.d.ts +0 -0
- /package/dist/types/src/{hooks/automerge → automerge}/automerge.stories.d.ts +0 -0
- /package/src/{hooks/automerge → automerge/automerge-plugin}/PatchSemaphore.ts +0 -0
- /package/src/{hooks/automerge → automerge/automerge-plugin}/amToCodemirror.ts +0 -0
- /package/src/{hooks/automerge → automerge/automerge-plugin}/codeMirrorToAm.ts +0 -0
- /package/src/{hooks/automerge → automerge/automerge-plugin}/handle.ts +0 -0
- /package/src/{hooks/automerge → automerge/automerge-plugin}/index.ts +0 -0
- /package/src/{hooks/automerge → automerge/automerge-plugin}/plugin.ts +0 -0
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2023 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { markdownLanguage } from '@codemirror/lang-markdown';
|
|
6
|
-
import { HighlightStyle } from '@codemirror/language';
|
|
7
|
-
import { tags, styleTags, Tag } from '@lezer/highlight';
|
|
8
|
-
import { type MarkdownConfig } from '@lezer/markdown';
|
|
9
|
-
import get from 'lodash.get';
|
|
10
|
-
|
|
11
|
-
import {
|
|
12
|
-
blockquote,
|
|
13
|
-
bold,
|
|
14
|
-
code,
|
|
15
|
-
codeMark,
|
|
16
|
-
heading,
|
|
17
|
-
horizontalRule,
|
|
18
|
-
inlineUrl,
|
|
19
|
-
italic,
|
|
20
|
-
mark,
|
|
21
|
-
strikethrough,
|
|
22
|
-
tokens,
|
|
23
|
-
} from '../../../../styles';
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Custom tags defined and processed by the GFM lezer extension.
|
|
27
|
-
* https://github.com/lezer-parser/markdown
|
|
28
|
-
* https://github.com/lezer-parser/markdown/blob/main/src/markdown.ts
|
|
29
|
-
*/
|
|
30
|
-
export const markdownTags = {
|
|
31
|
-
Blockquote: Tag.define(),
|
|
32
|
-
CodeMark: Tag.define(),
|
|
33
|
-
CodeText: Tag.define(),
|
|
34
|
-
EmphasisMark: Tag.define(),
|
|
35
|
-
HeaderMark: Tag.define(),
|
|
36
|
-
HorizontalRule: Tag.define(),
|
|
37
|
-
InlineCode: Tag.define(),
|
|
38
|
-
LinkLabel: Tag.define(),
|
|
39
|
-
LinkReference: Tag.define(),
|
|
40
|
-
ListMark: Tag.define(),
|
|
41
|
-
QuoteMark: Tag.define(),
|
|
42
|
-
URL: Tag.define(),
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
export const markdownTagsExtension: MarkdownConfig = {
|
|
46
|
-
props: [styleTags(markdownTags)],
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Styling based on `lezer` parser tags.
|
|
51
|
-
* https://codemirror.net/examples/styling
|
|
52
|
-
* https://github.com/lezer-parser/highlight
|
|
53
|
-
* https://lezer.codemirror.net/docs/ref/#highlight (list of tags)
|
|
54
|
-
*/
|
|
55
|
-
export const markdownHighlightStyle = HighlightStyle.define(
|
|
56
|
-
[
|
|
57
|
-
{
|
|
58
|
-
tag: [
|
|
59
|
-
tags.keyword,
|
|
60
|
-
tags.name,
|
|
61
|
-
tags.deleted,
|
|
62
|
-
tags.character,
|
|
63
|
-
tags.propertyName,
|
|
64
|
-
tags.macroName,
|
|
65
|
-
tags.color,
|
|
66
|
-
tags.constant(tags.name),
|
|
67
|
-
tags.standard(tags.name),
|
|
68
|
-
tags.definition(tags.name),
|
|
69
|
-
tags.separator,
|
|
70
|
-
tags.typeName,
|
|
71
|
-
tags.className,
|
|
72
|
-
tags.number,
|
|
73
|
-
tags.changed,
|
|
74
|
-
tags.annotation,
|
|
75
|
-
tags.modifier,
|
|
76
|
-
tags.self,
|
|
77
|
-
tags.namespace,
|
|
78
|
-
tags.operator,
|
|
79
|
-
tags.operatorKeyword,
|
|
80
|
-
tags.escape,
|
|
81
|
-
tags.regexp,
|
|
82
|
-
tags.special(tags.string),
|
|
83
|
-
tags.meta,
|
|
84
|
-
tags.comment,
|
|
85
|
-
tags.atom,
|
|
86
|
-
tags.bool,
|
|
87
|
-
tags.special(tags.variableName),
|
|
88
|
-
tags.processingInstruction,
|
|
89
|
-
tags.string,
|
|
90
|
-
tags.inserted,
|
|
91
|
-
tags.invalid,
|
|
92
|
-
],
|
|
93
|
-
color: 'inherit !important',
|
|
94
|
-
},
|
|
95
|
-
|
|
96
|
-
// Markdown marks.
|
|
97
|
-
{
|
|
98
|
-
tag: [
|
|
99
|
-
tags.meta,
|
|
100
|
-
tags.processingInstruction,
|
|
101
|
-
markdownTags.CodeMark,
|
|
102
|
-
markdownTags.EmphasisMark,
|
|
103
|
-
markdownTags.HeaderMark,
|
|
104
|
-
markdownTags.LinkLabel,
|
|
105
|
-
markdownTags.LinkReference,
|
|
106
|
-
markdownTags.ListMark,
|
|
107
|
-
markdownTags.QuoteMark,
|
|
108
|
-
],
|
|
109
|
-
class: mark,
|
|
110
|
-
},
|
|
111
|
-
|
|
112
|
-
// Headings.
|
|
113
|
-
{ tag: tags.heading1, class: heading[1] },
|
|
114
|
-
{ tag: tags.heading2, class: heading[2] },
|
|
115
|
-
{ tag: tags.heading3, class: heading[3] },
|
|
116
|
-
{ tag: tags.heading4, class: heading[4] },
|
|
117
|
-
{ tag: tags.heading5, class: heading[5] },
|
|
118
|
-
{ tag: tags.heading6, class: heading[6] },
|
|
119
|
-
|
|
120
|
-
// Emphasis.
|
|
121
|
-
{ tag: tags.emphasis, class: italic },
|
|
122
|
-
{ tag: tags.strong, class: bold },
|
|
123
|
-
{ tag: tags.strikethrough, class: strikethrough },
|
|
124
|
-
|
|
125
|
-
// Naked URLs.
|
|
126
|
-
{
|
|
127
|
-
tag: [markdownTags.URL],
|
|
128
|
-
class: inlineUrl,
|
|
129
|
-
},
|
|
130
|
-
|
|
131
|
-
// E.g., code block language (after ```).
|
|
132
|
-
{
|
|
133
|
-
tag: [tags.function(tags.variableName), tags.labelName],
|
|
134
|
-
class: codeMark,
|
|
135
|
-
},
|
|
136
|
-
|
|
137
|
-
// The `markdown` extension configures extensions for `lezer` to parse markdown tokens (incl. below).
|
|
138
|
-
// However, since `codeLanguages` is also defined, the `lezer` will not parse fenced code blocks,
|
|
139
|
-
// when a language is specified. In this case, the syntax highlighting extensions will colorize
|
|
140
|
-
// the code, but all other CSS properties will be inherited.
|
|
141
|
-
{
|
|
142
|
-
tag: [markdownTags.CodeText, markdownTags.InlineCode],
|
|
143
|
-
class: code,
|
|
144
|
-
},
|
|
145
|
-
|
|
146
|
-
{
|
|
147
|
-
tag: [markdownTags.QuoteMark],
|
|
148
|
-
class: blockquote,
|
|
149
|
-
},
|
|
150
|
-
|
|
151
|
-
{
|
|
152
|
-
tag: [markdownTags.HorizontalRule],
|
|
153
|
-
class: horizontalRule,
|
|
154
|
-
},
|
|
155
|
-
|
|
156
|
-
// Main content, paragraphs, etc.
|
|
157
|
-
// {
|
|
158
|
-
// tag: [tags.content],
|
|
159
|
-
// fontFamily: get(tokens, 'fontFamily.body', []).join(','),
|
|
160
|
-
// },
|
|
161
|
-
],
|
|
162
|
-
{
|
|
163
|
-
scope: markdownLanguage,
|
|
164
|
-
all: { fontFamily: get(tokens, 'fontFamily.body', []).join(',') },
|
|
165
|
-
},
|
|
166
|
-
);
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2023 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { syntaxTree } from '@codemirror/language';
|
|
6
|
-
import {
|
|
7
|
-
type EditorState,
|
|
8
|
-
type Extension,
|
|
9
|
-
type RangeSet,
|
|
10
|
-
RangeSetBuilder,
|
|
11
|
-
StateField,
|
|
12
|
-
type Transaction,
|
|
13
|
-
} from '@codemirror/state';
|
|
14
|
-
import { EditorView, Decoration, WidgetType } from '@codemirror/view';
|
|
15
|
-
|
|
16
|
-
class CheckboxWidget extends WidgetType {
|
|
17
|
-
constructor(private readonly _pos: number, private readonly _getCursor: () => number, private _checked: boolean) {
|
|
18
|
-
super();
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
override eq(other: CheckboxWidget) {
|
|
22
|
-
// Uniqueness based on position; also checks state.
|
|
23
|
-
// TODO(burdon): Is this efficient? Check life-cycle.
|
|
24
|
-
return this._pos === other._pos && this._checked === other._checked;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
toDOM(view: EditorView) {
|
|
28
|
-
// console.log('toDom', this._pos);
|
|
29
|
-
const wrap = document.createElement('span');
|
|
30
|
-
wrap.setAttribute('aria-hidden', 'true');
|
|
31
|
-
wrap.className = 'cm-task-item';
|
|
32
|
-
|
|
33
|
-
const box = wrap.appendChild(document.createElement('input'));
|
|
34
|
-
box.type = 'checkbox';
|
|
35
|
-
box.checked = this._checked;
|
|
36
|
-
box.onclick = (event) => {
|
|
37
|
-
this._checked = !isChecked(view.state, this._pos);
|
|
38
|
-
view.dispatch({
|
|
39
|
-
changes: {
|
|
40
|
-
from: this._pos + 1,
|
|
41
|
-
to: this._pos + 2,
|
|
42
|
-
insert: this._checked ? 'x' : ' ',
|
|
43
|
-
},
|
|
44
|
-
// TODO(burdon): Restore cursor position? More useful to move to end of line (can indent).
|
|
45
|
-
selection: {
|
|
46
|
-
anchor: this._pos + 4,
|
|
47
|
-
// anchor: this._getCursor(),
|
|
48
|
-
},
|
|
49
|
-
});
|
|
50
|
-
return true;
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
return wrap;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// TODO(burdon): Remove listener?
|
|
57
|
-
// override destroy() {
|
|
58
|
-
// console.log('destroy', this._pos);
|
|
59
|
-
// }
|
|
60
|
-
|
|
61
|
-
override ignoreEvent() {
|
|
62
|
-
return false;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const isChecked = (state: EditorState, pos: number) => {
|
|
67
|
-
return state.sliceDoc(pos, pos + 3).toLowerCase() === '[x]';
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
export const statefield = (): Extension => {
|
|
71
|
-
let lastPosition: number = 0;
|
|
72
|
-
const listener = EditorView.updateListener.of((update) => {
|
|
73
|
-
lastPosition = update.startState.selection.main.head;
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
const checkbox = (state: EditorState) => {
|
|
77
|
-
const builder = new RangeSetBuilder();
|
|
78
|
-
syntaxTree(state).iterate({
|
|
79
|
-
enter: (node) => {
|
|
80
|
-
// console.log(node.name, node.from, node.to);
|
|
81
|
-
if (node.name === 'TaskMarker') {
|
|
82
|
-
builder.add(
|
|
83
|
-
node.from,
|
|
84
|
-
node.to,
|
|
85
|
-
Decoration.replace({
|
|
86
|
-
widget: new CheckboxWidget(node.from, () => lastPosition, isChecked(state, node.from)),
|
|
87
|
-
}),
|
|
88
|
-
);
|
|
89
|
-
}
|
|
90
|
-
},
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
return builder.finish();
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
return [
|
|
97
|
-
listener,
|
|
98
|
-
StateField.define<RangeSet<any>>({
|
|
99
|
-
create: (state) => checkbox(state),
|
|
100
|
-
update: (_: RangeSet<any>, tr: Transaction) => checkbox(tr.state),
|
|
101
|
-
provide: (field) => EditorView.decorations.from(field),
|
|
102
|
-
}),
|
|
103
|
-
];
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
// TODO(burdon): Reconcile with theme.
|
|
107
|
-
export const styles = EditorView.baseTheme({
|
|
108
|
-
'& .cm-task-item': {
|
|
109
|
-
padding: '0 4px',
|
|
110
|
-
},
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
export const tasklist = () => [statefield(), styles];
|
|
@@ -1,170 +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
|
-
* https://codemirror.net/examples/styling
|
|
13
|
-
* NOTE: Use one of '&', '&light', and '&dark' prefix to scope instance.
|
|
14
|
-
* NOTE: `light` and `dark` selectors are preprocessed by CodeMirror and can only be in the base theme.
|
|
15
|
-
*/
|
|
16
|
-
export const defaultTheme: {
|
|
17
|
-
[selector: string]: StyleSpec;
|
|
18
|
-
} = {
|
|
19
|
-
//
|
|
20
|
-
// Main layout:
|
|
21
|
-
// <div class=".cm-editor .cm-focused">
|
|
22
|
-
// <div class=".cm-scroller">
|
|
23
|
-
// <div class=".cm-content" role="textbox" contenteditable="true">
|
|
24
|
-
// <div class=".cm-line" />
|
|
25
|
-
// </div>
|
|
26
|
-
// </div>
|
|
27
|
-
// </div>
|
|
28
|
-
//
|
|
29
|
-
'&': {},
|
|
30
|
-
'&.cm-focused': {
|
|
31
|
-
outline: 'none',
|
|
32
|
-
},
|
|
33
|
-
'& .cm-scroller': {
|
|
34
|
-
overflow: 'visible',
|
|
35
|
-
},
|
|
36
|
-
'& .cm-content': {
|
|
37
|
-
padding: 0,
|
|
38
|
-
// Base font size (otherwise defined by HTML tag, which might be different for storybook).
|
|
39
|
-
fontSize: '16px',
|
|
40
|
-
},
|
|
41
|
-
'&light .cm-content': {
|
|
42
|
-
color: get(tokens, 'extend.colors.neutral.900', 'black'),
|
|
43
|
-
caretColor: 'black',
|
|
44
|
-
},
|
|
45
|
-
'&dark .cm-content': {
|
|
46
|
-
color: get(tokens, 'extend.colors.neutral.100', 'white'),
|
|
47
|
-
caretColor: 'white',
|
|
48
|
-
},
|
|
49
|
-
|
|
50
|
-
//
|
|
51
|
-
// Cursor
|
|
52
|
-
//
|
|
53
|
-
'&light .cm-cursor': {
|
|
54
|
-
borderLeft: '2px solid black',
|
|
55
|
-
},
|
|
56
|
-
'&dark .cm-cursor': {
|
|
57
|
-
borderLeft: '2px solid white',
|
|
58
|
-
},
|
|
59
|
-
'& .cm-placeholder': {
|
|
60
|
-
fontWeight: 100,
|
|
61
|
-
},
|
|
62
|
-
|
|
63
|
-
//
|
|
64
|
-
// line
|
|
65
|
-
//
|
|
66
|
-
'& .cm-line': {
|
|
67
|
-
paddingInline: 0,
|
|
68
|
-
},
|
|
69
|
-
'& .cm-line *': {},
|
|
70
|
-
'& .cm-activeLine': {
|
|
71
|
-
backgroundColor: 'transparent',
|
|
72
|
-
},
|
|
73
|
-
|
|
74
|
-
//
|
|
75
|
-
// selection
|
|
76
|
-
//
|
|
77
|
-
|
|
78
|
-
'&light .cm-selectionBackground, &light.cm-focused .cm-selectionBackground': {
|
|
79
|
-
background: get(tokens, 'extend.colors.primary.150', '#00ffff'),
|
|
80
|
-
},
|
|
81
|
-
'&dark .cm-selectionBackground, &dark.cm-focused .cm-selectionBackground': {
|
|
82
|
-
background: get(tokens, 'extend.colors.primary.850', '#00ffff'),
|
|
83
|
-
},
|
|
84
|
-
'&light .cm-selectionMatch': {
|
|
85
|
-
background: get(tokens, 'extend.colors.primary.250', '#00ffff') + '44',
|
|
86
|
-
},
|
|
87
|
-
'&dark .cm-selectionMatch': {
|
|
88
|
-
background: get(tokens, 'extend.colors.primary.600', '#00ffff') + '44',
|
|
89
|
-
},
|
|
90
|
-
|
|
91
|
-
//
|
|
92
|
-
// collaboration
|
|
93
|
-
// TODO(burdon): Review classnames (YJS dependent?)
|
|
94
|
-
//
|
|
95
|
-
|
|
96
|
-
'&light .cm-ySelection, &light .cm-yLineSelection': {
|
|
97
|
-
mixBlendMode: 'multiply',
|
|
98
|
-
},
|
|
99
|
-
'&dark .cm-ySelection, &dark .cm-yLineSelection': {
|
|
100
|
-
mixBlendMode: 'screen',
|
|
101
|
-
},
|
|
102
|
-
|
|
103
|
-
'& .cm-ySelectionInfo': {
|
|
104
|
-
padding: '2px 4px',
|
|
105
|
-
marginBlockStart: '-4px',
|
|
106
|
-
},
|
|
107
|
-
'& .cm-ySelection, & .cm-selectionMatch': {
|
|
108
|
-
paddingBlockStart: '.15em',
|
|
109
|
-
paddingBlockEnd: '.15em',
|
|
110
|
-
},
|
|
111
|
-
'& .cm-ySelectionCaret': {
|
|
112
|
-
display: 'inline-block',
|
|
113
|
-
insetBlockStart: '.1em',
|
|
114
|
-
blockSize: '1.4em',
|
|
115
|
-
verticalAlign: 'top',
|
|
116
|
-
},
|
|
117
|
-
'& .cm-yLineSelection': {
|
|
118
|
-
margin: 0,
|
|
119
|
-
},
|
|
120
|
-
|
|
121
|
-
//
|
|
122
|
-
// link
|
|
123
|
-
//
|
|
124
|
-
'& .cm-link': {
|
|
125
|
-
color: get(tokens, 'extend.colors.primary.500'),
|
|
126
|
-
textDecorationLine: 'underline',
|
|
127
|
-
textDecorationThickness: '1px',
|
|
128
|
-
textUnderlineOffset: '2px',
|
|
129
|
-
borderRadius: '.125rem',
|
|
130
|
-
fontFamily: get(tokens, 'fontFamily.body', []).join(','),
|
|
131
|
-
},
|
|
132
|
-
|
|
133
|
-
//
|
|
134
|
-
// tooltip
|
|
135
|
-
//
|
|
136
|
-
'& .cm-tooltip': {
|
|
137
|
-
border: 'none',
|
|
138
|
-
},
|
|
139
|
-
// '& .cm-tooltip-below': {},
|
|
140
|
-
// '& .cm-tooltip-autocomplete': {},
|
|
141
|
-
|
|
142
|
-
//
|
|
143
|
-
// font size
|
|
144
|
-
// TODO(thure): This appears to be the best or only way to set selection caret heights, but it's far more verbose than it needs to be.
|
|
145
|
-
//
|
|
146
|
-
...Object.keys(get(tokens, 'extend.fontSize', {})).reduce((acc: Record<string, any>, fontSize) => {
|
|
147
|
-
const height = get(tokens, ['extend', 'fontSize', fontSize, 1, 'lineHeight']);
|
|
148
|
-
|
|
149
|
-
acc[`& .text-${fontSize} + .cm-ySelectionCaret`] = { height };
|
|
150
|
-
acc[`& .text-${fontSize} + .cm-ySelection + .cm-ySelectionCaret`] = { height };
|
|
151
|
-
acc[`& .text-${fontSize} + .cm-widgetBuffer + .cm-ySelectionCaret`] = { height };
|
|
152
|
-
return acc;
|
|
153
|
-
}, {}),
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
export const textTheme: {
|
|
157
|
-
[selector: string]: StyleSpec;
|
|
158
|
-
} = {
|
|
159
|
-
'& .cm-scroller': {
|
|
160
|
-
fontFamily: get(tokens, 'fontFamily.body', []).join(','),
|
|
161
|
-
},
|
|
162
|
-
};
|
|
163
|
-
|
|
164
|
-
export const codeTheme: {
|
|
165
|
-
[selector: string]: StyleSpec;
|
|
166
|
-
} = {
|
|
167
|
-
'& .cm-scroller': {
|
|
168
|
-
fontFamily: get(tokens, 'fontFamily.mono', []).join(','),
|
|
169
|
-
},
|
|
170
|
-
};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|