readd codemirror
This commit is contained in:
parent
bfa3b7e3b1
commit
af634eeb91
5 changed files with 310 additions and 0 deletions
|
@ -22,6 +22,7 @@ module.exports = config => {
|
|||
);
|
||||
//config.setServerPassthroughCopyBehavior("passthrough"); // doesn't work
|
||||
config.addPassthroughCopy({ "assets": "/" });
|
||||
config.addWatchTarget("src/**/*.js");
|
||||
return {
|
||||
dir: {
|
||||
input,
|
||||
|
|
|
@ -6,6 +6,19 @@
|
|||
debug: "DEBUG=* eleventy --serve",
|
||||
},
|
||||
dependencies: {
|
||||
"@codemirror/commands": "^0.19.5",
|
||||
"@codemirror/comment": "^0.19.0",
|
||||
"@codemirror/fold": "^0.19.2",
|
||||
"@codemirror/highlight": "^0.19.6",
|
||||
"@codemirror/history": "^0.19.0",
|
||||
"@codemirror/lang-javascript": "^0.19.3",
|
||||
"@codemirror/language": "^0.19.7",
|
||||
"@codemirror/matchbrackets": "^0.19.3",
|
||||
"@codemirror/rectangular-selection": "^0.19.1",
|
||||
"@codemirror/search": "^0.19.4",
|
||||
"@codemirror/state": "^0.19.6",
|
||||
"@codemirror/view": "^0.19.26",
|
||||
|
||||
"@11ty/eleventy": "^2.0.1",
|
||||
"@jamshop/eleventy-plugin-esbuild": "^1.0.2",
|
||||
},
|
||||
|
|
243
pnpm-lock.yaml
243
pnpm-lock.yaml
|
@ -8,6 +8,42 @@ dependencies:
|
|||
'@11ty/eleventy':
|
||||
specifier: ^2.0.1
|
||||
version: 2.0.1
|
||||
'@codemirror/commands':
|
||||
specifier: ^0.19.5
|
||||
version: 0.19.8
|
||||
'@codemirror/comment':
|
||||
specifier: ^0.19.0
|
||||
version: 0.19.1
|
||||
'@codemirror/fold':
|
||||
specifier: ^0.19.2
|
||||
version: 0.19.4
|
||||
'@codemirror/highlight':
|
||||
specifier: ^0.19.6
|
||||
version: 0.19.8
|
||||
'@codemirror/history':
|
||||
specifier: ^0.19.0
|
||||
version: 0.19.2
|
||||
'@codemirror/lang-javascript':
|
||||
specifier: ^0.19.3
|
||||
version: 0.19.7
|
||||
'@codemirror/language':
|
||||
specifier: ^0.19.7
|
||||
version: 0.19.10
|
||||
'@codemirror/matchbrackets':
|
||||
specifier: ^0.19.3
|
||||
version: 0.19.4
|
||||
'@codemirror/rectangular-selection':
|
||||
specifier: ^0.19.1
|
||||
version: 0.19.2
|
||||
'@codemirror/search':
|
||||
specifier: ^0.19.4
|
||||
version: 0.19.10
|
||||
'@codemirror/state':
|
||||
specifier: ^0.19.6
|
||||
version: 0.19.9
|
||||
'@codemirror/view':
|
||||
specifier: ^0.19.26
|
||||
version: 0.19.48
|
||||
'@jamshop/eleventy-plugin-esbuild':
|
||||
specifier: ^1.0.2
|
||||
version: 1.0.2
|
||||
|
@ -128,6 +164,185 @@ packages:
|
|||
to-fast-properties: 2.0.0
|
||||
dev: false
|
||||
|
||||
/@codemirror/autocomplete@0.19.15:
|
||||
resolution: {integrity: sha512-GQWzvvuXxNUyaEk+5gawbAD8s51/v2Chb++nx0e2eGWrphWk42isBtzOMdc3DxrxrZtPZ55q2ldNp+6G8KJLIQ==}
|
||||
dependencies:
|
||||
'@codemirror/language': 0.19.10
|
||||
'@codemirror/state': 0.19.9
|
||||
'@codemirror/text': 0.19.6
|
||||
'@codemirror/tooltip': 0.19.16
|
||||
'@codemirror/view': 0.19.48
|
||||
'@lezer/common': 0.15.12
|
||||
dev: false
|
||||
|
||||
/@codemirror/commands@0.19.8:
|
||||
resolution: {integrity: sha512-65LIMSGUGGpY3oH6mzV46YWRrgao6NmfJ+AuC7jNz3K5NPnH6GCV1H5I6SwOFyVbkiygGyd0EFwrWqywTBD1aw==}
|
||||
dependencies:
|
||||
'@codemirror/language': 0.19.10
|
||||
'@codemirror/matchbrackets': 0.19.4
|
||||
'@codemirror/state': 0.19.9
|
||||
'@codemirror/text': 0.19.6
|
||||
'@codemirror/view': 0.19.48
|
||||
'@lezer/common': 0.15.12
|
||||
dev: false
|
||||
|
||||
/@codemirror/comment@0.19.1:
|
||||
resolution: {integrity: sha512-uGKteBuVWAC6fW+Yt8u27DOnXMT/xV4Ekk2Z5mRsiADCZDqYvryrJd6PLL5+8t64BVyocwQwNfz1UswYS2CtFQ==}
|
||||
deprecated: As of 0.20.0, this package has been merged into @codemirror/commands
|
||||
dependencies:
|
||||
'@codemirror/state': 0.19.9
|
||||
'@codemirror/text': 0.19.6
|
||||
'@codemirror/view': 0.19.48
|
||||
dev: false
|
||||
|
||||
/@codemirror/fold@0.19.4:
|
||||
resolution: {integrity: sha512-0SNSkRSOa6gymD6GauHa3sxiysjPhUC0SRVyTlvL52o0gz9GHdc8kNqNQskm3fBtGGOiSriGwF/kAsajRiGhVw==}
|
||||
deprecated: As of 0.20.0, this package has been merged into @codemirror/language
|
||||
dependencies:
|
||||
'@codemirror/gutter': 0.19.9
|
||||
'@codemirror/language': 0.19.10
|
||||
'@codemirror/rangeset': 0.19.9
|
||||
'@codemirror/state': 0.19.9
|
||||
'@codemirror/view': 0.19.48
|
||||
dev: false
|
||||
|
||||
/@codemirror/gutter@0.19.9:
|
||||
resolution: {integrity: sha512-PFrtmilahin1g6uL27aG5tM/rqR9DZzZYZsIrCXA5Uc2OFTFqx4owuhoU9hqfYxHp5ovfvBwQ+txFzqS4vog6Q==}
|
||||
deprecated: As of 0.20.0, this package has been merged into @codemirror/view
|
||||
dependencies:
|
||||
'@codemirror/rangeset': 0.19.9
|
||||
'@codemirror/state': 0.19.9
|
||||
'@codemirror/view': 0.19.48
|
||||
dev: false
|
||||
|
||||
/@codemirror/highlight@0.19.8:
|
||||
resolution: {integrity: sha512-v/lzuHjrYR8MN2mEJcUD6fHSTXXli9C1XGYpr+ElV6fLBIUhMTNKR3qThp611xuWfXfwDxeL7ppcbkM/MzPV3A==}
|
||||
deprecated: As of 0.20.0, this package has been split between @lezer/highlight and @codemirror/language
|
||||
dependencies:
|
||||
'@codemirror/language': 0.19.10
|
||||
'@codemirror/rangeset': 0.19.9
|
||||
'@codemirror/state': 0.19.9
|
||||
'@codemirror/view': 0.19.48
|
||||
'@lezer/common': 0.15.12
|
||||
style-mod: 4.1.0
|
||||
dev: false
|
||||
|
||||
/@codemirror/history@0.19.2:
|
||||
resolution: {integrity: sha512-unhP4t3N2smzmHoo/Yio6ueWi+il8gm9VKrvi6wlcdGH5fOfVDNkmjHQ495SiR+EdOG35+3iNebSPYww0vN7ow==}
|
||||
deprecated: As of 0.20.0, this package has been merged into @codemirror/commands
|
||||
dependencies:
|
||||
'@codemirror/state': 0.19.9
|
||||
'@codemirror/view': 0.19.48
|
||||
dev: false
|
||||
|
||||
/@codemirror/lang-javascript@0.19.7:
|
||||
resolution: {integrity: sha512-DL9f3JLqOEHH9cIwEqqjnP5bkjdVXeECksLtV+/MbPm+l4H+AG+PkwZaJQ2oR1GfPZKh8MVSIE94aGWNkJP8WQ==}
|
||||
dependencies:
|
||||
'@codemirror/autocomplete': 0.19.15
|
||||
'@codemirror/highlight': 0.19.8
|
||||
'@codemirror/language': 0.19.10
|
||||
'@codemirror/lint': 0.19.6
|
||||
'@codemirror/state': 0.19.9
|
||||
'@codemirror/view': 0.19.48
|
||||
'@lezer/javascript': 0.15.3
|
||||
dev: false
|
||||
|
||||
/@codemirror/language@0.19.10:
|
||||
resolution: {integrity: sha512-yA0DZ3RYn2CqAAGW62VrU8c4YxscMQn45y/I9sjBlqB1e2OTQLg4CCkMBuMSLXk4xaqjlsgazeOQWaJQOKfV8Q==}
|
||||
dependencies:
|
||||
'@codemirror/state': 0.19.9
|
||||
'@codemirror/text': 0.19.6
|
||||
'@codemirror/view': 0.19.48
|
||||
'@lezer/common': 0.15.12
|
||||
'@lezer/lr': 0.15.8
|
||||
dev: false
|
||||
|
||||
/@codemirror/lint@0.19.6:
|
||||
resolution: {integrity: sha512-Pbw1Y5kHVs2J+itQ0uez3dI4qY9ApYVap7eNfV81x1/3/BXgBkKfadaw0gqJ4h4FDG7OnJwb0VbPsjJQllHjaA==}
|
||||
dependencies:
|
||||
'@codemirror/gutter': 0.19.9
|
||||
'@codemirror/panel': 0.19.1
|
||||
'@codemirror/rangeset': 0.19.9
|
||||
'@codemirror/state': 0.19.9
|
||||
'@codemirror/tooltip': 0.19.16
|
||||
'@codemirror/view': 0.19.48
|
||||
crelt: 1.0.6
|
||||
dev: false
|
||||
|
||||
/@codemirror/matchbrackets@0.19.4:
|
||||
resolution: {integrity: sha512-VFkaOKPNudAA5sGP1zikRHCEKU0hjYmkKpr04pybUpQvfTvNJXlReCyP0rvH/1iEwAGPL990ZTT+QrLdu4MeEA==}
|
||||
deprecated: As of 0.20.0, this package has been merged into @codemirror/language
|
||||
dependencies:
|
||||
'@codemirror/language': 0.19.10
|
||||
'@codemirror/state': 0.19.9
|
||||
'@codemirror/view': 0.19.48
|
||||
'@lezer/common': 0.15.12
|
||||
dev: false
|
||||
|
||||
/@codemirror/panel@0.19.1:
|
||||
resolution: {integrity: sha512-sYeOCMA3KRYxZYJYn5PNlt9yNsjy3zTNTrbYSfVgjgL9QomIVgOJWPO5hZ2sTN8lufO6lw0vTBsIPL9MSidmBg==}
|
||||
deprecated: As of 0.20.0, this package has been merged into @codemirror/view
|
||||
dependencies:
|
||||
'@codemirror/state': 0.19.9
|
||||
'@codemirror/view': 0.19.48
|
||||
dev: false
|
||||
|
||||
/@codemirror/rangeset@0.19.9:
|
||||
resolution: {integrity: sha512-V8YUuOvK+ew87Xem+71nKcqu1SXd5QROMRLMS/ljT5/3MCxtgrRie1Cvild0G/Z2f1fpWxzX78V0U4jjXBorBQ==}
|
||||
deprecated: As of 0.20.0, this package has been merged into @codemirror/state
|
||||
dependencies:
|
||||
'@codemirror/state': 0.19.9
|
||||
dev: false
|
||||
|
||||
/@codemirror/rectangular-selection@0.19.2:
|
||||
resolution: {integrity: sha512-AXK/p5eGwFJ9GJcLfntqN4dgY+XiIF7eHfXNQJX5HhQLSped2wJE6WuC1rMEaOlcpOqlb9mrNi/ZdUjSIj9mbA==}
|
||||
deprecated: As of 0.20.0, this package has been merged into @codemirror/view
|
||||
dependencies:
|
||||
'@codemirror/state': 0.19.9
|
||||
'@codemirror/text': 0.19.6
|
||||
'@codemirror/view': 0.19.48
|
||||
dev: false
|
||||
|
||||
/@codemirror/search@0.19.10:
|
||||
resolution: {integrity: sha512-qjubm69HJixPBWzI6HeEghTWOOD8NXiHOTRNvdizqs8xWRuFChq9zkjD3XiAJ7GXSTzCuQJnAP9DBBGCLq4ZIA==}
|
||||
dependencies:
|
||||
'@codemirror/panel': 0.19.1
|
||||
'@codemirror/rangeset': 0.19.9
|
||||
'@codemirror/state': 0.19.9
|
||||
'@codemirror/text': 0.19.6
|
||||
'@codemirror/view': 0.19.48
|
||||
crelt: 1.0.6
|
||||
dev: false
|
||||
|
||||
/@codemirror/state@0.19.9:
|
||||
resolution: {integrity: sha512-psOzDolKTZkx4CgUqhBQ8T8gBc0xN5z4gzed109aF6x7D7umpDRoimacI/O6d9UGuyl4eYuDCZmDFr2Rq7aGOw==}
|
||||
dependencies:
|
||||
'@codemirror/text': 0.19.6
|
||||
dev: false
|
||||
|
||||
/@codemirror/text@0.19.6:
|
||||
resolution: {integrity: sha512-T9jnREMIygx+TPC1bOuepz18maGq/92q2a+n4qTqObKwvNMg+8cMTslb8yxeEDEq7S3kpgGWxgO1UWbQRij0dA==}
|
||||
deprecated: As of 0.20.0, this package has been merged into @codemirror/state
|
||||
dev: false
|
||||
|
||||
/@codemirror/tooltip@0.19.16:
|
||||
resolution: {integrity: sha512-zxKDHryUV5/RS45AQL+wOeN+i7/l81wK56OMnUPoTSzCWNITfxHn7BToDsjtrRKbzHqUxKYmBnn/4hPjpZ4WJQ==}
|
||||
deprecated: As of 0.20.0, this package has been merged into @codemirror/view
|
||||
dependencies:
|
||||
'@codemirror/state': 0.19.9
|
||||
'@codemirror/view': 0.19.48
|
||||
dev: false
|
||||
|
||||
/@codemirror/view@0.19.48:
|
||||
resolution: {integrity: sha512-0eg7D2Nz4S8/caetCTz61rK0tkHI17V/d15Jy0kLOT8dTLGGNJUponDnW28h2B6bERmPlVHKh8MJIr5OCp1nGw==}
|
||||
dependencies:
|
||||
'@codemirror/rangeset': 0.19.9
|
||||
'@codemirror/state': 0.19.9
|
||||
'@codemirror/text': 0.19.6
|
||||
style-mod: 4.1.0
|
||||
w3c-keyname: 2.2.8
|
||||
dev: false
|
||||
|
||||
/@iarna/toml@2.2.5:
|
||||
resolution: {integrity: sha512-trnsAYxU3xnS1gPHPyU961coFyLkh4gAD/0zQ5mymY4yOZ+CYvsPqUbOFSw0aDM4y0tV7tiFxL/1XfXPNC6IPg==}
|
||||
dev: false
|
||||
|
@ -138,6 +353,22 @@ packages:
|
|||
esbuild: 0.7.22
|
||||
dev: false
|
||||
|
||||
/@lezer/common@0.15.12:
|
||||
resolution: {integrity: sha512-edfwCxNLnzq5pBA/yaIhwJ3U3Kz8VAUOTRg0hhxaizaI1N+qxV7EXDv/kLCkLeq2RzSFvxexlaj5Mzfn2kY0Ig==}
|
||||
dev: false
|
||||
|
||||
/@lezer/javascript@0.15.3:
|
||||
resolution: {integrity: sha512-8jA2NpOfpWwSPZxRhd9BxK2ZPvGd7nLE3LFTJ5AbMhXAzMHeMjneV6GEVd7dAIee85dtap0jdb6bgOSO0+lfwA==}
|
||||
dependencies:
|
||||
'@lezer/lr': 0.15.8
|
||||
dev: false
|
||||
|
||||
/@lezer/lr@0.15.8:
|
||||
resolution: {integrity: sha512-bM6oE6VQZ6hIFxDNKk8bKPa14hqFrV07J/vHGOeiAbJReIaQXmkVb6xQu4MR+JBTLa5arGRyAAjJe1qaQt3Uvg==}
|
||||
dependencies:
|
||||
'@lezer/common': 0.15.12
|
||||
dev: false
|
||||
|
||||
/@nodelib/fs.scandir@2.1.5:
|
||||
resolution: {integrity: sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==}
|
||||
engines: {node: '>= 8'}
|
||||
|
@ -391,6 +622,10 @@ packages:
|
|||
'@babel/types': 7.23.6
|
||||
dev: false
|
||||
|
||||
/crelt@1.0.6:
|
||||
resolution: {integrity: sha512-VQ2MBenTq1fWZUH9DJNGti7kKv6EeAuYr3cLwxUWhIu1baTaXh4Ib5W2CqHVqib4/MqbYGJqiL3Zb8GJZr3l4g==}
|
||||
dev: false
|
||||
|
||||
/cross-spawn@7.0.3:
|
||||
resolution: {integrity: sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==}
|
||||
engines: {node: '>= 8'}
|
||||
|
@ -1348,6 +1583,10 @@ packages:
|
|||
engines: {node: '>=0.10.0'}
|
||||
dev: false
|
||||
|
||||
/style-mod@4.1.0:
|
||||
resolution: {integrity: sha512-Ca5ib8HrFn+f+0n4N4ScTIA9iTOQ7MaGS1ylHcoVqW9J7w2w8PzN6g9gKmTYgGEBH8e120+RCmhpje6jC5uGWA==}
|
||||
dev: false
|
||||
|
||||
/supports-color@7.2.0:
|
||||
resolution: {integrity: sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==}
|
||||
engines: {node: '>=8'}
|
||||
|
@ -1398,6 +1637,10 @@ packages:
|
|||
engines: {node: '>=0.10.0'}
|
||||
dev: false
|
||||
|
||||
/w3c-keyname@2.2.8:
|
||||
resolution: {integrity: sha512-dpojBhNsCNN7T82Tm7k26A6G9ML3NkhDsnw9n/eoxSRlVBB4CEtIQ/KTCLI2Fwf3ataSXRhYFkQi3SlnFwPvPQ==}
|
||||
dev: false
|
||||
|
||||
/which@2.0.2:
|
||||
resolution: {integrity: sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==}
|
||||
engines: {node: '>= 8'}
|
||||
|
|
|
@ -61,6 +61,7 @@ const bytebeat = Object.seal({
|
|||
this.initControls();
|
||||
await this.initTextarea(document.getElementById("code-editor"));
|
||||
|
||||
import("./codemirror.js").then(o => this.initCodemirror(o.default));
|
||||
if (globalThis.loadLibrary !== false)
|
||||
import("./load-library.js");
|
||||
|
||||
|
@ -736,6 +737,8 @@ const bytebeat = Object.seal({
|
|||
}
|
||||
});
|
||||
|
||||
// for easy debugging
|
||||
Object.defineProperty(globalThis, "bytebeat", { value: bytebeat });
|
||||
|
||||
bytebeat.init();
|
||||
export default bytebeat;
|
||||
|
|
50
src/codemirror.js
Normal file
50
src/codemirror.js
Normal file
|
@ -0,0 +1,50 @@
|
|||
import { defaultKeymap, insertNewline, indentLess } from "@codemirror/commands";
|
||||
import { commentKeymap } from "@codemirror/comment";
|
||||
import { classHighlightStyle } from "@codemirror/highlight";
|
||||
import { history, historyKeymap } from "@codemirror/history";
|
||||
import { javascript } from "@codemirror/lang-javascript";
|
||||
import { indentUnit } from "@codemirror/language";
|
||||
import { bracketMatching } from "@codemirror/matchbrackets";
|
||||
import { searchKeymap, highlightSelectionMatches } from "@codemirror/search";
|
||||
import { EditorState } from "@codemirror/state";
|
||||
import { EditorView, keymap, highlightSpecialChars } from "@codemirror/view";
|
||||
|
||||
export default function createCodemirror(inputListener) {
|
||||
const codeEditor = new EditorView({
|
||||
state: EditorState.create({
|
||||
extensions: [
|
||||
keymap.of([
|
||||
{ key: "Enter", run: insertNewline },
|
||||
{
|
||||
key: "Tab",
|
||||
run: ({ state, dispatch }) => (
|
||||
dispatch(state.replaceSelection("\t")), true
|
||||
),
|
||||
shift: indentLess,
|
||||
},
|
||||
...searchKeymap,
|
||||
...commentKeymap,
|
||||
...historyKeymap,
|
||||
...defaultKeymap,
|
||||
]),
|
||||
EditorView.lineWrapping,
|
||||
highlightSpecialChars(),
|
||||
history(),
|
||||
indentUnit.of("\t"),
|
||||
EditorState.tabSize.of(3),
|
||||
classHighlightStyle,
|
||||
bracketMatching(),
|
||||
highlightSelectionMatches(),
|
||||
javascript(),
|
||||
EditorView.updateListener.of(v => {
|
||||
if (v.docChanged && inputListener) inputListener();
|
||||
}),
|
||||
],
|
||||
}),
|
||||
});
|
||||
|
||||
codeEditor.dom.id = "code-editor";
|
||||
codeEditor.dom.ariaLabel = "Code editor";
|
||||
|
||||
return codeEditor;
|
||||
}
|
Loading…
Reference in a new issue