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