Skip to content

Commit

Permalink
updates layout rules as latest calcit-editor; bump 0.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
tiye committed Feb 20, 2021
1 parent 788d1dc commit 47e32f6
Show file tree
Hide file tree
Showing 7 changed files with 367 additions and 255 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Support several basic shortcuts from [Clacit Editor](https://github.com/Cirru/ca
[![Clojars Project](https://img.shields.io/clojars/v/cirru/editor.svg)](https://clojars.org/cirru/editor)

```clojure
[cirru/editor "0.3.0-a2"]
[cirru/editor "0.3.1"]
```

Import `comp-editor` like this:
Expand Down
234 changes: 170 additions & 64 deletions calcit.cirru

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "respo-cirru-editor",
"version": "0.3.0",
"version": "0.3.1",
"description": "Stack Workflow",
"main": "index.js",
"scripts": {
Expand All @@ -21,7 +21,7 @@
"author": "jiyinyiyong",
"license": "MIT",
"devDependencies": {
"shadow-cljs": "^2.11.5"
"shadow-cljs": "^2.11.18"
},
"dependencies": {
"shortid": "^2.2.16"
Expand Down
2 changes: 1 addition & 1 deletion release.edn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{:version "0.3.0",
{:version "0.3.1",
:group-id "cirru",
:artifact-id "editor",
:skip-tag true,
Expand Down
2 changes: 1 addition & 1 deletion shadow-cljs.edn
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
:dependencies [
[mvc-works/hsl "0.1.2"]
[mvc-works/shell-page "0.1.15"]
[respo "0.13.4"]
[respo "0.13.9"]
[respo/ui "0.3.16"]
[cumulo/util "0.1.12"]
[org.clojure/core.incubator "0.1.4"]
Expand Down
28 changes: 17 additions & 11 deletions src/cirru_editor/comp/expression.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@

(defcomp
comp-expression
(states expression modify! coord level tail? focus on-command head? after-expression?)
(states expression modify! coord level tail? focus on-command head? inline?)
(let [exp-size (count expression), state (or (:data states) false)]
(if state
(div
Expand All @@ -103,20 +103,25 @@
:class-name (if (= coord focus) "editor-focused cirru-expression" "cirru-expression"),
:style (merge
{}
(if (and (shallow? expression)
(not after-expression?)
(not tail?)
(pos? level)
(< (count expression) 5))
style-inline)
(if inline? style-inline)
(if (and tail? (not head?) (pos? level)) style-tail)
(if (= coord focus) {:border-color (hsl 0 0 100 0.6)})),
:on {:click (on-click modify! coord focus),
:keydown (on-keydown state modify! coord on-command)}}
(loop [acc [], idx 0, expr expression, child-after-expression? false]
(loop [acc [], idx 0, expr expression, prev-kind nil]
(if (empty? expr)
acc
(let [item (first expr)
kind (if (string? item)
:leaf
(if (and (<= (count item) 1) (string? (first item)))
:leaf
(case prev-kind
:expr :expr
:inline-expr (if (> (count item) 2) :expr :inline-expr)
:leaf (if (> (count item) 6) :expr :inline-expr)
nil (if (> (count item) 6) :expr :inline-expr)
:expr)))
pair [idx
(let [child-coord (conj coord idx)
child-focus (if (coord-contains? focus child-coord) focus nil)
Expand All @@ -135,13 +140,14 @@
modify!
child-coord
(inc level)
(and (or after-expression? (not tail?)) (= (dec exp-size) idx))
(and (not tail?) (= (dec exp-size) idx) (= prev-kind :leaf))
child-focus
on-command
child-head?
child-after-expression?)))]
(or (= kind :inline-expr) (= kind :leaf)))))]
next-acc (conj acc pair)]
(recur next-acc (inc idx) (rest expr) (vector? item)))))))))
(comment println "kinds:" prev-kind kind " at " item)
(recur next-acc (inc idx) (rest expr) kind))))))))

(def style-expression
{:border-style "solid",
Expand Down
Loading

0 comments on commit 47e32f6

Please sign in to comment.