Skip to content

Commit ca59920

Browse files
committed
make demo a separate module
1 parent cf2c29c commit ca59920

File tree

5 files changed

+49
-48
lines changed

5 files changed

+49
-48
lines changed

demo/main.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import './style.css'
2+
import {EditorView, basicSetup} from 'codemirror'
3+
import {EditorState} from '@codemirror/state'
4+
import {clojure} from "../src/clojure"
5+
6+
let editorState = EditorState.create({
7+
doc: `(map inc (range 5))`,
8+
extensions: [basicSetup, clojure()]
9+
})
10+
11+
function isLinux() {
12+
if (navigator.userAgent.match(/(Linux)|(X11)/g) === null) {
13+
return false
14+
}
15+
return true
16+
}
17+
18+
function isMac() {
19+
if (!isLinux &&
20+
navigator.userAgent.match(/(Mac)|(iPhone)|(iPad)|(iPod)/g) != null) {
21+
return true
22+
}
23+
return false
24+
}
25+
26+
function modifier() {
27+
if (isMac()) {
28+
return "Cmd"
29+
} else {
30+
return "Ctrl"
31+
}
32+
}
33+
34+
new EditorView({
35+
state: editorState,
36+
parent: document.querySelector('#app')
37+
}).focus()
38+
39+
let topLevelText = "Alt+Enter = Eval top-level form"
40+
let keyBindings = "<strong>Key bindings:</strong>,Shift+Enter = Eval cell," +
41+
topLevelText + ",Ctrl/Cmd+Enter = Eval at cursor, Esc/Arrows = Clear result";
42+
keyBindings = keyBindings.split(',');
43+
for ( let i = 0; i < keyBindings.length; i++ )
44+
keyBindings[i] = "" + keyBindings[i] + "<br>";
45+
keyBindings = keyBindings.join('');
46+
document.getElementById("keymap").innerHTML = keyBindings;
47+
File renamed without changes.

vite.svg renamed to demo/vite.svg

File renamed without changes.

index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
<html lang="en">
33
<head>
44
<meta charset="UTF-8" />
5-
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
5+
<link rel="icon" type="image/svg+xml" href="/demo/vite.svg" />
66
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
77
<title>Vite App</title>
88
</head>
99
<body>
1010
<div id="app"></div>
1111
<p id="keymap"></p>
12-
<script type="module" src="/src/clojure.js"></script>
12+
<script type="module" src="/demo/main.js"></script>
1313
</body>
1414
</html>

src/clojure.js

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import '../style.css'
2-
import { EditorView, basicSetup } from 'codemirror'
31
import { EditorState } from '@codemirror/state'
42
import { parser, props } from "@nextjournal/lezer-clojure"
53
import { styleTags, tags } from "@lezer/highlight"
@@ -55,47 +53,3 @@ export const clojureLanguage = LRLanguage.define({
5553
export function clojure() {
5654
return new LanguageSupport(clojureLanguage, [evalExtension])
5755
}
58-
59-
let editorState = EditorState.create({
60-
doc: `(map inc (range 5))`,
61-
// disable active line highlighting, see https://github.com/codemirror/basic-setup/blob/b3be7cd30496ee578005bd11b1fa6a8b21fcbece/src/codemirror.ts#L66
62-
extensions: [basicSetup.slice(0, 15).concat(basicSetup.slice(16)), clojure()]
63-
})
64-
65-
function isLinux() {
66-
if (navigator.userAgent.match(/(Linux)|(X11)/g) === null) {
67-
return false
68-
}
69-
return true
70-
}
71-
72-
function isMac() {
73-
if (!isLinux &&
74-
navigator.userAgent.match(/(Mac)|(iPhone)|(iPad)|(iPod)/g) != null) {
75-
return true
76-
}
77-
return false
78-
}
79-
80-
function modifier() {
81-
if (isMac()) {
82-
return "Cmd"
83-
} else {
84-
return "Ctrl"
85-
}
86-
}
87-
88-
new EditorView({
89-
state: editorState,
90-
parent: document.querySelector('#app')
91-
}).focus()
92-
93-
let topLevelText = "Alt+Enter = Eval top-level form"
94-
let keyBindings = "<strong>Key bindings:</strong>,Shift+Enter = Eval cell," +
95-
topLevelText + "," + modifier() +
96-
"+Enter = Eval at cursor, Esc/Arrows = Clear result";
97-
keyBindings = keyBindings.split(',');
98-
for ( let i = 0; i < keyBindings.length; i++ )
99-
keyBindings[i] = "" + keyBindings[i] + "<br>";
100-
keyBindings = keyBindings.join('');
101-
document.getElementById("keymap").innerHTML = keyBindings;

0 commit comments

Comments
 (0)