]> BookStack Code Mirror - bookstack/blob - resources/js/code/setups.js
CM6: Updated for popup editor, added new interface
[bookstack] / resources / js / code / setups.js
1 import {EditorView, keymap, drawSelection, highlightActiveLine, dropCursor,
2     rectangularSelection, lineNumbers, highlightActiveLineGutter} from "@codemirror/view"
3 import {bracketMatching} from "@codemirror/language"
4 import {defaultKeymap, history, historyKeymap} from "@codemirror/commands"
5 import {EditorState} from "@codemirror/state"
6 import {getTheme} from "./themes";
7
8 /**
9  * @param {Element} parentEl
10  * @return {(Extension[]|{extension: Extension}|readonly Extension[])[]}
11  */
12 function common(parentEl) {
13     return [
14         getTheme(parentEl),
15         lineNumbers(),
16         highlightActiveLineGutter(),
17         drawSelection(),
18         dropCursor(),
19         bracketMatching(),
20         rectangularSelection(),
21         highlightActiveLine(),
22     ];
23 }
24
25 /**
26  * @param {Element} parentEl
27  * @return {*[]}
28  */
29 export function viewerExtensions(parentEl) {
30     return [
31         ...common(parentEl),
32         keymap.of([
33             ...defaultKeymap,
34         ]),
35         EditorState.readOnly.of(true),
36     ];
37 }
38
39 /**
40  * @param {Element} parentEl
41  * @return {*[]}
42  */
43 export function editorExtensions(parentEl) {
44     return [
45         ...common(parentEl),
46         history(),
47         keymap.of([
48             ...defaultKeymap,
49             ...historyKeymap,
50         ]),
51         EditorView.lineWrapping,
52     ];
53 }