mirror of
https://github.com/heyman/heynote.git
synced 2024-11-28 19:03:45 +01:00
Create HeynoteEditor class and restructure init code
This commit is contained in:
parent
9aff278c80
commit
1695cc9d11
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,2 +1,2 @@
|
|||||||
node_modules
|
node_modules
|
||||||
editor.bundle.js
|
bundle.js
|
||||||
|
@ -4,10 +4,11 @@ import { nodeResolve } from "@rollup/plugin-node-resolve"
|
|||||||
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
input: "./src/editor.js",
|
input: "./src/index.js",
|
||||||
output: {
|
output: {
|
||||||
file: "./src/editor.bundle.js",
|
file: "./src/bundle.js",
|
||||||
format: "iife",
|
format: "iife",
|
||||||
|
//sourceMap: "inline",
|
||||||
//globals: {
|
//globals: {
|
||||||
// //
|
// //
|
||||||
//},
|
//},
|
||||||
|
@ -1,59 +1,72 @@
|
|||||||
import { Annotation, EditorState, Compartment } from "@codemirror/state"
|
import { Annotation, EditorState, Compartment } from "@codemirror/state"
|
||||||
import { EditorView, keymap, drawSelection } from "@codemirror/view"
|
import { EditorView, keymap, drawSelection } from "@codemirror/view"
|
||||||
import { indentUnit } from "@codemirror/language"
|
import { indentUnit, forceParsing } from "@codemirror/language"
|
||||||
|
|
||||||
import { indentWithTab, insertTab, indentLess, indentMore } from "@codemirror/commands"
|
import { indentWithTab, insertTab, indentLess, indentMore } from "@codemirror/commands"
|
||||||
import { nord } from "./theme/nord.mjs"
|
import { nord } from "./theme/nord.mjs"
|
||||||
import initialData from "./fixture.js"
|
|
||||||
import { customSetup } from "./setup.js"
|
import { customSetup } from "./setup.js"
|
||||||
import { heynoteLang } from "./lang-heynote/heynote.js"
|
import { heynoteLang } from "./lang-heynote/heynote.js"
|
||||||
import { noteBlockExtension } from "./note-block.js"
|
import { noteBlockExtension } from "./note-block.js"
|
||||||
import { heynoteEvent, INITIAL_DATA } from "./annotation.js"
|
|
||||||
|
|
||||||
|
|
||||||
let state = EditorState.create({
|
export class HeynoteEditor {
|
||||||
extensions: [
|
constructor({element, content, focus=true}) {
|
||||||
/*keymap.of([
|
this.state = EditorState.create({
|
||||||
{
|
doc: content || "",
|
||||||
key: "Shift-Tab",
|
extensions: [
|
||||||
preventDefault: true,
|
/*keymap.of([
|
||||||
run: () => {
|
{
|
||||||
console.log("debug:", syntaxTree(editor.state).toString())
|
key: "Shift-Tab",
|
||||||
},
|
preventDefault: true,
|
||||||
},
|
run: () => {
|
||||||
]),*/
|
console.log("debug:", syntaxTree(editor.state).toString())
|
||||||
customSetup,
|
},
|
||||||
//minimalSetup,
|
},
|
||||||
|
]),*/
|
||||||
|
customSetup,
|
||||||
|
//minimalSetup,
|
||||||
|
|
||||||
keymap.of([
|
keymap.of([
|
||||||
{
|
{
|
||||||
key: 'Tab',
|
key: 'Tab',
|
||||||
preventDefault: true,
|
preventDefault: true,
|
||||||
//run: insertTab,
|
//run: insertTab,
|
||||||
run: indentMore,
|
run: indentMore,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'Shift-Tab',
|
key: 'Shift-Tab',
|
||||||
preventDefault: true,
|
preventDefault: true,
|
||||||
run: indentLess,
|
run: indentLess,
|
||||||
},
|
},
|
||||||
]),
|
]),
|
||||||
nord,
|
nord,
|
||||||
indentUnit.of(" "),
|
indentUnit.of(" "),
|
||||||
heynoteLang(),
|
heynoteLang(),
|
||||||
noteBlockExtension(),
|
noteBlockExtension(),
|
||||||
|
|
||||||
// set cursor blink rate to 1 second
|
// set cursor blink rate to 1 second
|
||||||
drawSelection({cursorBlinkRate:1000}),
|
drawSelection({cursorBlinkRate:1000}),
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
|
|
||||||
let editor = new EditorView({
|
this.view = new EditorView({
|
||||||
state,
|
state: this.state,
|
||||||
parent: document.getElementById("editor"),
|
parent: element,
|
||||||
})
|
})
|
||||||
|
|
||||||
// set initial data
|
if (focus) {
|
||||||
|
this.view.dispatch({
|
||||||
|
selection: {anchor: this.view.state.doc.length, head: this.view.state.doc.length},
|
||||||
|
scrollIntoView: true,
|
||||||
|
})
|
||||||
|
this.view.focus()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*// set initial data
|
||||||
editor.update([
|
editor.update([
|
||||||
editor.state.update({
|
editor.state.update({
|
||||||
changes:{
|
changes:{
|
||||||
@ -63,20 +76,7 @@ editor.update([
|
|||||||
},
|
},
|
||||||
annotations: heynoteEvent.of(INITIAL_DATA),
|
annotations: heynoteEvent.of(INITIAL_DATA),
|
||||||
})
|
})
|
||||||
])
|
])*/
|
||||||
|
|
||||||
|
|
||||||
editor.dispatch({
|
|
||||||
selection: {anchor: editor.state.doc.length, head: editor.state.doc.length},
|
|
||||||
scrollIntoView: true,
|
|
||||||
})
|
|
||||||
editor.focus()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -10,6 +10,6 @@
|
|||||||
<body>
|
<body>
|
||||||
<div id="editor"></div>
|
<div id="editor"></div>
|
||||||
<!--<div id="syntaxTree"></div>-->
|
<!--<div id="syntaxTree"></div>-->
|
||||||
<script src="editor.bundle.js"></script>
|
<script src="bundle.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
7
heynote-codemirror/src/index.js
Normal file
7
heynote-codemirror/src/index.js
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
import { HeynoteEditor } from "./editor.js"
|
||||||
|
import initialData from "./fixture.js"
|
||||||
|
|
||||||
|
let editor = new HeynoteEditor({
|
||||||
|
element: document.getElementById("editor"),
|
||||||
|
content: initialData,
|
||||||
|
})
|
Loading…
Reference in New Issue
Block a user