Cirru Editor in Calcit-js Respo. Previous implemented in ClojureScript.
Demo http://repo.cirru.org/respo-cirru-editor/
Support several basic shortcuts from Clacit Editor.
Import comp-editor
like this:
ns app.ns
:require
cirru-editor.comp.editor :refer $ comp-editor
cirru-editor.util.dom :refer $ focus!
Arguments of comp-editor
:
defn on-update! (snapshot dispatch!)
dispatch! :update snapshot
defn on-command (snapshot dispatch! e)
defn schema $ {}
:snaphot $ {}
:tree ([])
:focus ([])
:clipboard []
; "states comes from Respo@4.x states management"
defn render (states snapshot)
div
{} (:style ({}))
comp-editor states snapshot on-update! on-command
focus!
is a side-effect. You have to make sure it's called only editor is changed.
Respo does not provide a didMount
hook, you have to handle it globally on you own.
Function cirru-editor.core/cirru-edit
for editing:
cirru-edit snapshot op op-data
with snapshot
in a structure:
{}
:tree $ []
:clipboard $ []
op | op-data | usage |
---|---|---|
:update-token |
[] coord new-token |
edit token |
:after-token |
coord |
insert empty token after current position |
:before-token |
coord |
add new token before of current token |
:fold-node |
coord |
increase indentation |
:unfold-expression |
coord |
decrease indentation |
:unfold-token |
coord |
decrease indentation from token |
:before-expression |
coord |
add new expression before current position |
:after-expression |
coord |
add new expression after current position |
:prepend-expression |
coord |
add new token at head of current expression |
:append-expression |
coord |
add new token at tail of current expression |
:remove-node |
coord |
remove at current position |
:focus-to |
coord |
focus to position |
:node-up |
coord |
move focus to parent |
:expression-down |
coord |
move focus to first child |
:node-left |
coord |
move focus to previous sibling |
:node-right |
coord |
move focus to next sibling |
:command-copy |
coord |
copy target to buffer |
:command-cut |
coord |
cut target to buffer |
:command-paste |
coord |
paste buffer at current position |
:tree-reset |
tree |
reset |
:duplicate-expression |
coord |
duplicate current expression |
returns structure:
{}
:tree $ []
:clipboard $ []
:focus $ []
https://github.com/calcit-lang/respo-calcit-workflow
MIT