@kerebron/extension-codemirror 0.1.3 → 0.2.0
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/assets/codemirror.css +80 -0
- package/package.json +6 -4
- package/esm/editor/src/CoreEditor.d.ts +0 -25
- package/esm/editor/src/CoreEditor.d.ts.map +0 -1
- package/esm/editor/src/CoreEditor.js +0 -194
- package/esm/editor/src/Extension.d.ts +0 -26
- package/esm/editor/src/Extension.d.ts.map +0 -1
- package/esm/editor/src/Extension.js +0 -33
- package/esm/editor/src/ExtensionManager.d.ts +0 -32
- package/esm/editor/src/ExtensionManager.d.ts.map +0 -1
- package/esm/editor/src/ExtensionManager.js +0 -253
- package/esm/editor/src/Mark.d.ts +0 -18
- package/esm/editor/src/Mark.d.ts.map +0 -1
- package/esm/editor/src/Mark.js +0 -34
- package/esm/editor/src/Node.d.ts +0 -27
- package/esm/editor/src/Node.d.ts.map +0 -1
- package/esm/editor/src/Node.js +0 -43
- package/esm/editor/src/commands/CommandManager.d.ts +0 -20
- package/esm/editor/src/commands/CommandManager.d.ts.map +0 -1
- package/esm/editor/src/commands/CommandManager.js +0 -60
- package/esm/editor/src/commands/createChainableState.d.ts +0 -3
- package/esm/editor/src/commands/createChainableState.d.ts.map +0 -1
- package/esm/editor/src/commands/createChainableState.js +0 -29
- package/esm/editor/src/commands/mod.d.ts +0 -49
- package/esm/editor/src/commands/mod.d.ts.map +0 -1
- package/esm/editor/src/commands/mod.js +0 -928
- package/esm/editor/src/mod.d.ts +0 -6
- package/esm/editor/src/mod.d.ts.map +0 -1
- package/esm/editor/src/mod.js +0 -5
- package/esm/editor/src/nodeToTreeString.d.ts +0 -4
- package/esm/editor/src/nodeToTreeString.d.ts.map +0 -1
- package/esm/editor/src/nodeToTreeString.js +0 -56
- package/esm/editor/src/plugins/input-rules/InputRulesPlugin.d.ts +0 -23
- package/esm/editor/src/plugins/input-rules/InputRulesPlugin.d.ts.map +0 -1
- package/esm/editor/src/plugins/input-rules/InputRulesPlugin.js +0 -163
- package/esm/editor/src/plugins/input-rules/mod.d.ts +0 -3
- package/esm/editor/src/plugins/input-rules/mod.d.ts.map +0 -1
- package/esm/editor/src/plugins/input-rules/mod.js +0 -2
- package/esm/editor/src/plugins/input-rules/rulebuilders.d.ts +0 -5
- package/esm/editor/src/plugins/input-rules/rulebuilders.d.ts.map +0 -1
- package/esm/editor/src/plugins/input-rules/rulebuilders.js +0 -50
- package/esm/editor/src/types.d.ts +0 -29
- package/esm/editor/src/types.d.ts.map +0 -1
- package/esm/editor/src/types.js +0 -1
- package/esm/editor/src/utilities/createNodeFromContent.d.ts +0 -8
- package/esm/editor/src/utilities/createNodeFromContent.d.ts.map +0 -1
- package/esm/editor/src/utilities/createNodeFromContent.js +0 -33
- package/esm/editor/src/utilities/getHtmlAttributes.d.ts +0 -4
- package/esm/editor/src/utilities/getHtmlAttributes.d.ts.map +0 -1
- package/esm/editor/src/utilities/getHtmlAttributes.js +0 -47
- package/esm/editor/src/utilities/mod.d.ts +0 -3
- package/esm/editor/src/utilities/mod.d.ts.map +0 -1
- package/esm/editor/src/utilities/mod.js +0 -2
- package/esm/extension-codemirror/src/ExtensionCodeMirror.d.ts +0 -5
- package/esm/extension-codemirror/src/ExtensionCodeMirror.d.ts.map +0 -1
- package/esm/extension-codemirror/src/ExtensionCodeMirror.js +0 -4
- package/esm/extension-codemirror/src/NodeCodeMirror.d.ts +0 -27
- package/esm/extension-codemirror/src/NodeCodeMirror.d.ts.map +0 -1
- package/esm/extension-codemirror/src/NodeCodeMirror.js +0 -187
- package/esm/extension-codemirror/src/NodeDocumentCode.d.ts +0 -7
- package/esm/extension-codemirror/src/NodeDocumentCode.d.ts.map +0 -1
- package/esm/extension-codemirror/src/NodeDocumentCode.js +0 -37
- package/esm/extension-codemirror/src/codeMirrorBlockNodeView.d.ts +0 -6
- package/esm/extension-codemirror/src/codeMirrorBlockNodeView.d.ts.map +0 -1
- package/esm/extension-codemirror/src/codeMirrorBlockNodeView.js +0 -265
- package/esm/extension-codemirror/src/defaults.d.ts +0 -6
- package/esm/extension-codemirror/src/defaults.d.ts.map +0 -1
- package/esm/extension-codemirror/src/defaults.js +0 -57
- package/esm/extension-codemirror/src/languageLoaders.d.ts +0 -5
- package/esm/extension-codemirror/src/languageLoaders.d.ts.map +0 -1
- package/esm/extension-codemirror/src/languageLoaders.js +0 -113
- package/esm/extension-codemirror/src/languages.d.ts +0 -109
- package/esm/extension-codemirror/src/languages.d.ts.map +0 -1
- package/esm/extension-codemirror/src/languages.js +0 -110
- package/esm/extension-codemirror/src/types.d.ts +0 -29
- package/esm/extension-codemirror/src/types.d.ts.map +0 -1
- package/esm/extension-codemirror/src/types.js +0 -1
- package/esm/extension-codemirror/src/utils.d.ts +0 -39
- package/esm/extension-codemirror/src/utils.d.ts.map +0 -1
- package/esm/extension-codemirror/src/utils.js +0 -199
- package/esm/extension-codemirror/src/y-remote-selections.d.ts +0 -15
- package/esm/extension-codemirror/src/y-remote-selections.d.ts.map +0 -1
- package/esm/extension-codemirror/src/y-remote-selections.js +0 -273
- package/esm/extension-codemirror/src/y-sync.d.ts +0 -11
- package/esm/extension-codemirror/src/y-sync.d.ts.map +0 -1
- package/esm/extension-codemirror/src/y-sync.js +0 -29
- package/esm/package.json +0 -3
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
import { Plugin, PluginKey, Selection } from 'prosemirror-state';
|
|
2
|
-
import { Node } from '../../editor/src/mod.js';
|
|
3
|
-
import { setBlockType, } from '../../editor/src/commands/mod.js';
|
|
4
|
-
import { textblockTypeInputRule, } from '../../editor/src/plugins/input-rules/mod.js';
|
|
5
|
-
import { codeMirrorBlockNodeView } from './codeMirrorBlockNodeView.js';
|
|
6
|
-
import { defaultSettings } from './defaults.js';
|
|
7
|
-
import languageLoaders, { legacyLanguageLoaders } from './languageLoaders.js';
|
|
8
|
-
import { dracula } from 'thememirror';
|
|
9
|
-
import { createNodeFromObject } from '../../editor/src/utilities/mod.js';
|
|
10
|
-
export const codeMirrorBlockKey = new PluginKey('codemirror-block');
|
|
11
|
-
function arrowHandler(dir) {
|
|
12
|
-
return (state, dispatch, view) => {
|
|
13
|
-
if (state.selection.empty && view.endOfTextblock(dir)) {
|
|
14
|
-
let side = dir == 'left' || dir == 'up' ? -1 : 1;
|
|
15
|
-
let $head = state.selection.$head;
|
|
16
|
-
let nextPos = Selection.near(state.doc.resolve(side > 0 ? $head.after() : $head.before()), side);
|
|
17
|
-
if (nextPos.$head && nextPos.$head.parent.type.name == 'code_block') {
|
|
18
|
-
dispatch(state.tr.setSelection(nextPos));
|
|
19
|
-
return true;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
return false;
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
export class NodeCodeMirror extends Node {
|
|
26
|
-
constructor() {
|
|
27
|
-
super(...arguments);
|
|
28
|
-
Object.defineProperty(this, "name", {
|
|
29
|
-
enumerable: true,
|
|
30
|
-
configurable: true,
|
|
31
|
-
writable: true,
|
|
32
|
-
value: 'code_block'
|
|
33
|
-
});
|
|
34
|
-
// requires = ['doc'];
|
|
35
|
-
Object.defineProperty(this, "automerge", {
|
|
36
|
-
enumerable: true,
|
|
37
|
-
configurable: true,
|
|
38
|
-
writable: true,
|
|
39
|
-
value: {
|
|
40
|
-
block: this.name,
|
|
41
|
-
attrParsers: {
|
|
42
|
-
fromAutomerge: (block) => ({ lang: block.attrs.lang }),
|
|
43
|
-
fromProsemirror: (node) => ({ lang: node.attrs.lang }),
|
|
44
|
-
},
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
getConverters(editor, schema) {
|
|
49
|
-
return {
|
|
50
|
-
'text/code-only': {
|
|
51
|
-
fromDoc(document) {
|
|
52
|
-
const retVal = [];
|
|
53
|
-
if (document.content) {
|
|
54
|
-
for (const node of document.content.toJSON()) {
|
|
55
|
-
if ('code_block' === node.type && Array.isArray(node.content)) {
|
|
56
|
-
for (const content of node.content) {
|
|
57
|
-
retVal.push(content.text);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
return retVal.join('');
|
|
63
|
-
},
|
|
64
|
-
toDoc(code) {
|
|
65
|
-
const content = {
|
|
66
|
-
'type': 'doc_code',
|
|
67
|
-
'content': [
|
|
68
|
-
{
|
|
69
|
-
'type': 'code_block',
|
|
70
|
-
'attrs': {
|
|
71
|
-
'lang': schema.topNodeType.spec.defaultAttrs?.lang,
|
|
72
|
-
},
|
|
73
|
-
'content': [
|
|
74
|
-
{
|
|
75
|
-
'type': 'text',
|
|
76
|
-
'text': code,
|
|
77
|
-
},
|
|
78
|
-
],
|
|
79
|
-
},
|
|
80
|
-
],
|
|
81
|
-
};
|
|
82
|
-
return createNodeFromObject(content, schema, {
|
|
83
|
-
slice: false,
|
|
84
|
-
errorOnInvalidContent: false,
|
|
85
|
-
});
|
|
86
|
-
},
|
|
87
|
-
},
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
getNodeSpec() {
|
|
91
|
-
return {
|
|
92
|
-
content: 'text*',
|
|
93
|
-
marks: '',
|
|
94
|
-
group: 'block',
|
|
95
|
-
code: true,
|
|
96
|
-
defining: true,
|
|
97
|
-
parseDOM: [
|
|
98
|
-
{
|
|
99
|
-
tag: 'pre',
|
|
100
|
-
preserveWhitespace: 'full',
|
|
101
|
-
getAttrs(dom) {
|
|
102
|
-
return {
|
|
103
|
-
lang: dom.getAttribute('lang'),
|
|
104
|
-
};
|
|
105
|
-
},
|
|
106
|
-
},
|
|
107
|
-
],
|
|
108
|
-
attrs: { lang: { default: null } },
|
|
109
|
-
toDOM(node) {
|
|
110
|
-
const { lang } = node.attrs;
|
|
111
|
-
return ['pre', { lang }, ['code', 0]];
|
|
112
|
-
},
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
getInputRules(type) {
|
|
116
|
-
/// Given a code block node type, returns an input rule that turns a
|
|
117
|
-
/// textblock starting with three backticks into a code block.
|
|
118
|
-
return [
|
|
119
|
-
textblockTypeInputRule(/^```$/, type),
|
|
120
|
-
];
|
|
121
|
-
}
|
|
122
|
-
getCommands(editor, type) {
|
|
123
|
-
return {
|
|
124
|
-
'setCodeBlock': (lang) => setBlockType(type, { lang }),
|
|
125
|
-
ArrowLeft: () => arrowHandler('left'),
|
|
126
|
-
ArrowRight: () => arrowHandler('right'),
|
|
127
|
-
ArrowUp: () => arrowHandler('up'),
|
|
128
|
-
ArrowDown: () => arrowHandler('down'),
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
getKeyboardShortcuts() {
|
|
132
|
-
return {
|
|
133
|
-
'Shift-Ctrl-"': 'setCodeBlock',
|
|
134
|
-
'ArrowLeft': 'ArrowLeft',
|
|
135
|
-
'ArrowRight': 'ArrowRight',
|
|
136
|
-
'ArrowUp': 'ArrowUp',
|
|
137
|
-
'ArrowDown': 'ArrowDown',
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
getProseMirrorPlugins(editor) {
|
|
141
|
-
const codeMirrorBlockPlugin = (settings) => new Plugin({
|
|
142
|
-
key: codeMirrorBlockKey,
|
|
143
|
-
props: {
|
|
144
|
-
nodeViews: {
|
|
145
|
-
[this.name]: codeMirrorBlockNodeView(settings),
|
|
146
|
-
},
|
|
147
|
-
},
|
|
148
|
-
});
|
|
149
|
-
const LANGS = [
|
|
150
|
-
'diff',
|
|
151
|
-
'dockerfile',
|
|
152
|
-
'http',
|
|
153
|
-
'nginx',
|
|
154
|
-
'properties',
|
|
155
|
-
'shell',
|
|
156
|
-
'toml',
|
|
157
|
-
'yaml',
|
|
158
|
-
'sql',
|
|
159
|
-
'javascript',
|
|
160
|
-
'cpp',
|
|
161
|
-
'css',
|
|
162
|
-
'xml',
|
|
163
|
-
'java',
|
|
164
|
-
'json',
|
|
165
|
-
'markdown',
|
|
166
|
-
'rust',
|
|
167
|
-
'html',
|
|
168
|
-
];
|
|
169
|
-
return [
|
|
170
|
-
codeMirrorBlockPlugin({
|
|
171
|
-
provider: this.config.provider,
|
|
172
|
-
languageWhitelist: this.config.languageWhitelist || LANGS,
|
|
173
|
-
...defaultSettings,
|
|
174
|
-
readOnly: this.config.readOnly,
|
|
175
|
-
languageLoaders: { ...languageLoaders, ...legacyLanguageLoaders },
|
|
176
|
-
undo: () => {
|
|
177
|
-
editor.chain().undo().run();
|
|
178
|
-
},
|
|
179
|
-
redo: () => {
|
|
180
|
-
editor.chain().redo().run();
|
|
181
|
-
},
|
|
182
|
-
theme: [dracula],
|
|
183
|
-
}),
|
|
184
|
-
// keymap(codeBlockKeymap),
|
|
185
|
-
];
|
|
186
|
-
}
|
|
187
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"NodeDocumentCode.d.ts","sourceRoot":"","sources":["../../../src/extension-codemirror/src/NodeDocumentCode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,OAAO,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAE/C,qBAAa,gBAAiB,SAAQ,IAAI;IAC/B,IAAI,SAAc;IAElB,WAAW,IAAI,QAAQ;CAyBjC"}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { Node } from '../../editor/src/mod.js';
|
|
2
|
-
export class NodeDocumentCode extends Node {
|
|
3
|
-
constructor() {
|
|
4
|
-
super(...arguments);
|
|
5
|
-
Object.defineProperty(this, "name", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
configurable: true,
|
|
8
|
-
writable: true,
|
|
9
|
-
value: 'doc_code'
|
|
10
|
-
});
|
|
11
|
-
}
|
|
12
|
-
getNodeSpec() {
|
|
13
|
-
return {
|
|
14
|
-
content: 'code_block',
|
|
15
|
-
defaultAttrs: {
|
|
16
|
-
'lang': this.config.lang || null,
|
|
17
|
-
},
|
|
18
|
-
EMPTY_DOC: {
|
|
19
|
-
'type': this.name,
|
|
20
|
-
'content': [
|
|
21
|
-
{
|
|
22
|
-
'type': 'code_block',
|
|
23
|
-
'attrs': {
|
|
24
|
-
'lang': this.config.lang || null,
|
|
25
|
-
},
|
|
26
|
-
'content': [
|
|
27
|
-
// {
|
|
28
|
-
// "type": "text",
|
|
29
|
-
// "text": ""
|
|
30
|
-
// }
|
|
31
|
-
],
|
|
32
|
-
},
|
|
33
|
-
],
|
|
34
|
-
},
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { Node } from 'prosemirror-model';
|
|
2
|
-
import { EditorView as PMEditorView, NodeView } from 'prosemirror-view';
|
|
3
|
-
import { CodeBlockSettings } from './types.js';
|
|
4
|
-
export declare const themeCallbacks: Array<(theme: string) => void>;
|
|
5
|
-
export declare const codeMirrorBlockNodeView: (settings: CodeBlockSettings) => (pmNode: Node, view: PMEditorView, getPos: (() => number) | boolean) => NodeView;
|
|
6
|
-
//# sourceMappingURL=codeMirrorBlockNodeView.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"codeMirrorBlockNodeView.d.ts","sourceRoot":"","sources":["../../../src/extension-codemirror/src/codeMirrorBlockNodeView.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzC,OAAO,EAEL,UAAU,IAAI,YAAY,EAC1B,QAAQ,EACT,MAAM,kBAAkB,CAAC;AA0C1B,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAO/C,eAAO,MAAM,cAAc,EAAE,KAAK,CAAC,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAM,CAAC;AAuQjE,eAAO,MAAM,uBAAuB,EAAE,CACpC,QAAQ,EAAE,iBAAiB,KACxB,CACH,MAAM,EAAE,IAAI,EACZ,IAAI,EAAE,YAAY,EAClB,MAAM,EAAE,CAAC,MAAM,MAAM,CAAC,GAAG,OAAO,KAC7B,QAQJ,CAAC"}
|
|
@@ -1,265 +0,0 @@
|
|
|
1
|
-
import { exitCode, selectAll } from '../../editor/src/commands/mod.js';
|
|
2
|
-
import { drawSelection, EditorView as CodeMirror, highlightActiveLine, highlightActiveLineGutter, keymap, lineNumbers, rectangularSelection, } from '@codemirror/view';
|
|
3
|
-
import { highlightSelectionMatches, selectNextOccurrence, } from '@codemirror/search';
|
|
4
|
-
import { bracketMatching, defaultHighlightStyle, foldGutter, foldKeymap, indentOnInput, syntaxHighlighting, } from '@codemirror/language';
|
|
5
|
-
import { autocompletion, closeBrackets, closeBracketsKeymap, completionKeymap, } from '@codemirror/autocomplete';
|
|
6
|
-
import { defaultKeymap, indentWithTab } from '@codemirror/commands';
|
|
7
|
-
import { Compartment, EditorState } from '@codemirror/state';
|
|
8
|
-
import { backspaceHandler, computeChange, forwardSelection, maybeEscape, setMode, setTheme, valueChanged, } from './utils.js';
|
|
9
|
-
import { YSyncConfig, ySyncFacet } from './y-sync.js';
|
|
10
|
-
import { yRemoteSelections, yRemoteSelectionsTheme, } from './y-remote-selections.js';
|
|
11
|
-
export const themeCallbacks = [];
|
|
12
|
-
class CodeMirrorBlockNodeView {
|
|
13
|
-
constructor(node, view, getPos, settings) {
|
|
14
|
-
Object.defineProperty(this, "node", {
|
|
15
|
-
enumerable: true,
|
|
16
|
-
configurable: true,
|
|
17
|
-
writable: true,
|
|
18
|
-
value: node
|
|
19
|
-
});
|
|
20
|
-
Object.defineProperty(this, "view", {
|
|
21
|
-
enumerable: true,
|
|
22
|
-
configurable: true,
|
|
23
|
-
writable: true,
|
|
24
|
-
value: view
|
|
25
|
-
});
|
|
26
|
-
Object.defineProperty(this, "getPos", {
|
|
27
|
-
enumerable: true,
|
|
28
|
-
configurable: true,
|
|
29
|
-
writable: true,
|
|
30
|
-
value: getPos
|
|
31
|
-
});
|
|
32
|
-
Object.defineProperty(this, "settings", {
|
|
33
|
-
enumerable: true,
|
|
34
|
-
configurable: true,
|
|
35
|
-
writable: true,
|
|
36
|
-
value: settings
|
|
37
|
-
});
|
|
38
|
-
Object.defineProperty(this, "dom", {
|
|
39
|
-
enumerable: true,
|
|
40
|
-
configurable: true,
|
|
41
|
-
writable: true,
|
|
42
|
-
value: void 0
|
|
43
|
-
});
|
|
44
|
-
Object.defineProperty(this, "codeMirrorView", {
|
|
45
|
-
enumerable: true,
|
|
46
|
-
configurable: true,
|
|
47
|
-
writable: true,
|
|
48
|
-
value: void 0
|
|
49
|
-
});
|
|
50
|
-
Object.defineProperty(this, "updating", {
|
|
51
|
-
enumerable: true,
|
|
52
|
-
configurable: true,
|
|
53
|
-
writable: true,
|
|
54
|
-
value: void 0
|
|
55
|
-
});
|
|
56
|
-
Object.defineProperty(this, "createCopyButtonCB", {
|
|
57
|
-
enumerable: true,
|
|
58
|
-
configurable: true,
|
|
59
|
-
writable: true,
|
|
60
|
-
value: void 0
|
|
61
|
-
});
|
|
62
|
-
Object.defineProperty(this, "selectDeleteCB", {
|
|
63
|
-
enumerable: true,
|
|
64
|
-
configurable: true,
|
|
65
|
-
writable: true,
|
|
66
|
-
value: void 0
|
|
67
|
-
});
|
|
68
|
-
Object.defineProperty(this, "languageConf", {
|
|
69
|
-
enumerable: true,
|
|
70
|
-
configurable: true,
|
|
71
|
-
writable: true,
|
|
72
|
-
value: void 0
|
|
73
|
-
});
|
|
74
|
-
this.updating = false;
|
|
75
|
-
const dom = document.createElement('div');
|
|
76
|
-
this.dom = dom;
|
|
77
|
-
dom.className = 'codeblock-root';
|
|
78
|
-
this.languageConf = new Compartment();
|
|
79
|
-
const themeConfig = new Compartment();
|
|
80
|
-
const yCollab = () => {
|
|
81
|
-
const plugins = [];
|
|
82
|
-
if (settings.provider?.awareness) {
|
|
83
|
-
const ySyncConfig = new YSyncConfig(() => this.node, getPos, settings.provider.awareness);
|
|
84
|
-
plugins.push(ySyncFacet.of(ySyncConfig));
|
|
85
|
-
plugins.push(yRemoteSelectionsTheme, yRemoteSelections);
|
|
86
|
-
}
|
|
87
|
-
return plugins;
|
|
88
|
-
};
|
|
89
|
-
const state = EditorState.create({
|
|
90
|
-
extensions: [
|
|
91
|
-
EditorState.readOnly.of(settings.readOnly),
|
|
92
|
-
CodeMirror.editable.of(!settings.readOnly),
|
|
93
|
-
lineNumbers(),
|
|
94
|
-
highlightActiveLineGutter(),
|
|
95
|
-
foldGutter(),
|
|
96
|
-
bracketMatching(),
|
|
97
|
-
closeBrackets(),
|
|
98
|
-
highlightSelectionMatches(),
|
|
99
|
-
autocompletion(),
|
|
100
|
-
rectangularSelection(),
|
|
101
|
-
drawSelection({ cursorBlinkRate: 1000 }), // broken focus
|
|
102
|
-
EditorState.allowMultipleSelections.of(true),
|
|
103
|
-
highlightActiveLine(),
|
|
104
|
-
syntaxHighlighting(defaultHighlightStyle, { fallback: true }),
|
|
105
|
-
this.languageConf.of([]),
|
|
106
|
-
indentOnInput(),
|
|
107
|
-
keymap.of([
|
|
108
|
-
{ key: 'Mod-d', run: selectNextOccurrence, preventDefault: true },
|
|
109
|
-
{
|
|
110
|
-
key: 'ArrowUp',
|
|
111
|
-
run: (cmView) => maybeEscape('line', -1, cmView, view, getPos),
|
|
112
|
-
},
|
|
113
|
-
{
|
|
114
|
-
key: 'ArrowLeft',
|
|
115
|
-
run: (cmView) => maybeEscape('char', -1, cmView, view, getPos),
|
|
116
|
-
},
|
|
117
|
-
{
|
|
118
|
-
key: 'ArrowDown',
|
|
119
|
-
run: (cmView) => maybeEscape('line', 1, cmView, view, getPos),
|
|
120
|
-
},
|
|
121
|
-
{
|
|
122
|
-
key: 'ArrowRight',
|
|
123
|
-
run: (cmView) => maybeEscape('char', 1, cmView, view, getPos),
|
|
124
|
-
},
|
|
125
|
-
{
|
|
126
|
-
key: 'Ctrl-Enter',
|
|
127
|
-
run: () => {
|
|
128
|
-
if (!exitCode(view.state, view.dispatch))
|
|
129
|
-
return false;
|
|
130
|
-
view.focus();
|
|
131
|
-
return true;
|
|
132
|
-
},
|
|
133
|
-
},
|
|
134
|
-
{
|
|
135
|
-
key: 'Mod-z',
|
|
136
|
-
run: () => settings.undo?.(view.state, view.dispatch) || true,
|
|
137
|
-
shift: () => settings.redo?.(view.state, view.dispatch) || true,
|
|
138
|
-
},
|
|
139
|
-
{
|
|
140
|
-
key: 'Mod-y',
|
|
141
|
-
run: () => settings.redo?.(view.state, view.dispatch) || true,
|
|
142
|
-
},
|
|
143
|
-
{ key: 'Backspace', run: (cmView) => backspaceHandler(view, cmView) },
|
|
144
|
-
{
|
|
145
|
-
key: 'Mod-Backspace',
|
|
146
|
-
run: (cmView) => backspaceHandler(view, cmView),
|
|
147
|
-
},
|
|
148
|
-
{
|
|
149
|
-
key: 'Mod-a',
|
|
150
|
-
run: () => {
|
|
151
|
-
const result = selectAll(view.state, view.dispatch);
|
|
152
|
-
view.focus();
|
|
153
|
-
return result;
|
|
154
|
-
},
|
|
155
|
-
},
|
|
156
|
-
{
|
|
157
|
-
key: 'Enter',
|
|
158
|
-
run: (cmView) => {
|
|
159
|
-
const sel = cmView.state.selection.main;
|
|
160
|
-
if (cmView.state.doc.line(cmView.state.doc.lines).text === '' &&
|
|
161
|
-
sel.from === sel.to &&
|
|
162
|
-
sel.from === cmView.state.doc.length) {
|
|
163
|
-
exitCode(view.state, view.dispatch);
|
|
164
|
-
view.focus();
|
|
165
|
-
return true;
|
|
166
|
-
}
|
|
167
|
-
return false;
|
|
168
|
-
},
|
|
169
|
-
},
|
|
170
|
-
...defaultKeymap,
|
|
171
|
-
...foldKeymap,
|
|
172
|
-
...closeBracketsKeymap,
|
|
173
|
-
...completionKeymap,
|
|
174
|
-
indentWithTab,
|
|
175
|
-
]),
|
|
176
|
-
...(settings.theme ? settings.theme : []),
|
|
177
|
-
themeConfig.of([]),
|
|
178
|
-
yCollab(),
|
|
179
|
-
],
|
|
180
|
-
doc: node.textContent,
|
|
181
|
-
});
|
|
182
|
-
this.codeMirrorView = new CodeMirror({
|
|
183
|
-
state,
|
|
184
|
-
dispatch: (tr) => {
|
|
185
|
-
this.codeMirrorView.update([tr]);
|
|
186
|
-
if (!this.updating) {
|
|
187
|
-
const textUpdate = tr.state.toJSON().doc;
|
|
188
|
-
valueChanged(textUpdate, this.node, getPos, view);
|
|
189
|
-
forwardSelection(this.codeMirrorView, view, getPos);
|
|
190
|
-
}
|
|
191
|
-
},
|
|
192
|
-
});
|
|
193
|
-
dom.append(this.codeMirrorView.dom);
|
|
194
|
-
if (!(Array.isArray(settings.languageWhitelist) &&
|
|
195
|
-
settings.languageWhitelist.length === 1)) {
|
|
196
|
-
this.selectDeleteCB = settings.createSelect(settings, dom, node, view, getPos);
|
|
197
|
-
}
|
|
198
|
-
this.createCopyButtonCB = settings.createCopyButton(settings, dom, node, view, this.codeMirrorView, getPos);
|
|
199
|
-
setMode(node.attrs.lang, this.codeMirrorView, settings, this.languageConf);
|
|
200
|
-
const currentTheme = settings.getCurrentTheme?.();
|
|
201
|
-
setTheme(this.codeMirrorView, themeConfig, [
|
|
202
|
-
settings.themes.find((t) => t.name === currentTheme),
|
|
203
|
-
]);
|
|
204
|
-
this.updateTheme = (theme) => {
|
|
205
|
-
setTheme(this.codeMirrorView, themeConfig, [
|
|
206
|
-
settings.themes.find((t) => t.name === theme),
|
|
207
|
-
]);
|
|
208
|
-
};
|
|
209
|
-
themeCallbacks.push(this.updateTheme);
|
|
210
|
-
}
|
|
211
|
-
updateTheme(updateTheme) {
|
|
212
|
-
throw new Error('Method not implemented.');
|
|
213
|
-
}
|
|
214
|
-
selectNode() {
|
|
215
|
-
this.codeMirrorView.focus();
|
|
216
|
-
}
|
|
217
|
-
stopEvent(e) {
|
|
218
|
-
return this.settings.stopEvent(e, this.node, this.getPos, this.view, this.dom);
|
|
219
|
-
}
|
|
220
|
-
setSelection(anchor, head) {
|
|
221
|
-
this.codeMirrorView.focus();
|
|
222
|
-
this.updating = true;
|
|
223
|
-
this.codeMirrorView.dispatch({ selection: { anchor, head } });
|
|
224
|
-
this.updating = false;
|
|
225
|
-
}
|
|
226
|
-
update(updateNode) {
|
|
227
|
-
if (updateNode.type.name !== this.node.type.name)
|
|
228
|
-
return false;
|
|
229
|
-
if (updateNode.attrs.lang !== this.node.attrs.lang) {
|
|
230
|
-
setMode(updateNode.attrs.lang, this.codeMirrorView, this.settings, this.languageConf);
|
|
231
|
-
}
|
|
232
|
-
const oldNode = this.node;
|
|
233
|
-
this.node = updateNode;
|
|
234
|
-
const change = computeChange(this.codeMirrorView.state.doc.toString(), this.node.textContent);
|
|
235
|
-
if (change) {
|
|
236
|
-
this.updating = true;
|
|
237
|
-
this.codeMirrorView.dispatch({
|
|
238
|
-
changes: {
|
|
239
|
-
from: change.from,
|
|
240
|
-
to: change.to,
|
|
241
|
-
insert: change.text,
|
|
242
|
-
},
|
|
243
|
-
selection: { anchor: change.from + change.text.length },
|
|
244
|
-
});
|
|
245
|
-
this.updating = false;
|
|
246
|
-
}
|
|
247
|
-
this.settings.updateSelect(this.settings, this.dom, updateNode, this.view, this.getPos, oldNode);
|
|
248
|
-
return true;
|
|
249
|
-
}
|
|
250
|
-
ignoreMutation() {
|
|
251
|
-
return true;
|
|
252
|
-
}
|
|
253
|
-
destroy() {
|
|
254
|
-
if (this.selectDeleteCB) {
|
|
255
|
-
this.selectDeleteCB();
|
|
256
|
-
}
|
|
257
|
-
this.createCopyButtonCB();
|
|
258
|
-
themeCallbacks.splice(themeCallbacks.indexOf(this.updateTheme), 1);
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
export const codeMirrorBlockNodeView = (settings) => {
|
|
262
|
-
return (pmNode, view, getPos) => {
|
|
263
|
-
return new CodeMirrorBlockNodeView(pmNode, view, getPos, settings);
|
|
264
|
-
};
|
|
265
|
-
};
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { Node } from 'prosemirror-model';
|
|
2
|
-
import { EditorView } from 'prosemirror-view';
|
|
3
|
-
import { CodeBlockSettings } from './types.js';
|
|
4
|
-
export declare const defaultCreateSelect: (settings: CodeBlockSettings, dom: HTMLElement, node: Node, view: EditorView, getPos: (() => number) | boolean) => () => void;
|
|
5
|
-
export declare const defaultSettings: CodeBlockSettings;
|
|
6
|
-
//# sourceMappingURL=defaults.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"defaults.d.ts","sourceRoot":"","sources":["../../../src/extension-codemirror/src/defaults.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAE/C,eAAO,MAAM,mBAAmB,aACpB,iBAAiB,OACtB,WAAW,QACV,IAAI,QACJ,UAAU,UACR,CAAC,MAAM,MAAM,CAAC,GAAG,OAAO,eAwCjC,CAAC;AAmBF,eAAO,MAAM,eAAe,EAAE,iBAS7B,CAAC"}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
export const defaultCreateSelect = (settings, dom, node, view, getPos) => {
|
|
2
|
-
if (!settings.languageLoaders)
|
|
3
|
-
return () => { };
|
|
4
|
-
const { languageLoaders } = settings;
|
|
5
|
-
const select = document.createElement('select');
|
|
6
|
-
select.className = 'codeblock-select';
|
|
7
|
-
const noneOption = document.createElement('option');
|
|
8
|
-
noneOption.value = 'none';
|
|
9
|
-
noneOption.textContent = settings.languageNameMap?.none || 'none';
|
|
10
|
-
select.append(noneOption);
|
|
11
|
-
Object.keys(languageLoaders)
|
|
12
|
-
.sort()
|
|
13
|
-
.forEach((lang) => {
|
|
14
|
-
if (settings.languageWhitelist &&
|
|
15
|
-
!settings.languageWhitelist.includes(lang)) {
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
const option = document.createElement('option');
|
|
19
|
-
option.value = lang;
|
|
20
|
-
option.textContent = settings.languageNameMap?.[lang] || lang;
|
|
21
|
-
select.append(option);
|
|
22
|
-
});
|
|
23
|
-
select.value = node.attrs.lang || 'none';
|
|
24
|
-
dom.prepend(select);
|
|
25
|
-
select.onchange = async (e) => {
|
|
26
|
-
if (!(e.target instanceof HTMLSelectElement))
|
|
27
|
-
return;
|
|
28
|
-
const lang = e.target.value;
|
|
29
|
-
if (typeof getPos === 'function') {
|
|
30
|
-
view.dispatch(view.state.tr.setNodeMarkup(getPos(), undefined, {
|
|
31
|
-
...node.attrs,
|
|
32
|
-
lang,
|
|
33
|
-
}));
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
// Delete code.
|
|
37
|
-
return () => { };
|
|
38
|
-
};
|
|
39
|
-
const defaultUpdateSelect = (settings, dom, node, view, getPos, oldNode) => {
|
|
40
|
-
if (oldNode.attrs.lang !== node.attrs.lang) {
|
|
41
|
-
const select = dom.querySelector('.codeblock-select');
|
|
42
|
-
if (!(select instanceof HTMLSelectElement))
|
|
43
|
-
return;
|
|
44
|
-
select.value = node.attrs.lang || 'none';
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
const defaultStopEvent = () => true;
|
|
48
|
-
export const defaultSettings = {
|
|
49
|
-
createSelect: defaultCreateSelect,
|
|
50
|
-
updateSelect: defaultUpdateSelect,
|
|
51
|
-
createCopyButton: () => {
|
|
52
|
-
return () => { };
|
|
53
|
-
},
|
|
54
|
-
stopEvent: defaultStopEvent,
|
|
55
|
-
readOnly: false,
|
|
56
|
-
themes: [],
|
|
57
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"languageLoaders.d.ts","sourceRoot":"","sources":["../../../src/extension-codemirror/src/languageLoaders.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE7C,QAAA,MAAM,eAAe,EAAE,eA6BtB,CAAC;AAEF,eAAO,MAAM,qBAAqB,EAAE,eAyWnC,CAAC;AAEF,eAAe,eAAe,CAAC"}
|