Skip to content

Commit

Permalink
enhance style
Browse files Browse the repository at this point in the history
  • Loading branch information
sprocketc committed Feb 5, 2024
1 parent e406b67 commit bbd3d63
Show file tree
Hide file tree
Showing 15 changed files with 52 additions and 53 deletions.
9 changes: 4 additions & 5 deletions src/renderer/document/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@
context' (-> (assoc context db-store-key new-db-store)
(assoc-coeffect :db original-db))
db (get-effect context :db ::not-found)]
(if (= db ::not-found)
context'
(->> (assoc-in original-db [:documents (:active-document original-db)] db)
(assoc-effect context' :db))))))))
(cond-> context'
(not= db ::not-found)
(assoc-effect :db (assoc-in original-db [:documents (:active-document original-db)] db))))))))

(rf/reg-event-db
:document/set-hovered-keys
Expand Down Expand Up @@ -142,7 +141,7 @@
:document/save
(fn [{:keys [db]} [_]]
(let [document (get-in db [:documents (:active-document db)])
duped (assoc document :history (dd/de-dupe (:history document)))]
duped (update-in document [:history] dd/de-dupe)]
{:send-to-main {:action "saveDocument" :data (pr-str duped)}})))

(rf/reg-event-fx
Expand Down
18 changes: 8 additions & 10 deletions src/renderer/element/handlers.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,23 @@
([db]
(get-in db (path db)))
([db keys]
(vals (select-keys (elements db) (vec keys)))))
((apply juxt keys) (elements db))))

(defn element
[db k]
(k (elements db)))

(defn active-page
[db]
(->> (get-in db [:documents (:active-document db) :active-page])
(element db)))
(element db (get-in db [:documents (:active-document db) :active-page])))

(defn selected
[db]
(filter :selected? (vals (elements db))))

(defn selected-keys
[db]
(into #{} (map :key (selected db))))
(set (map :key (selected db))))

(defn single? [coll]
(and (seq coll)
Expand All @@ -52,7 +51,7 @@
(defn siblings-selected?
[db]
(let [selected (selected db)
parents (into #{} (map :parent selected))]
parents (set (map :parent selected))]
(and (single? parents)
(= (count selected)
(count (:children (element db (first parents))))))))
Expand All @@ -79,7 +78,7 @@

(defn pages
[db]
(vals (select-keys (elements db) (-> (elements db) :canvas :children))))
((apply juxt (-> (elements db) :canvas :children)) (elements db)))

(defn page?
[el]
Expand Down Expand Up @@ -249,8 +248,7 @@

(defn selected-sorted
[db]
(->> (selected db)
(sort-by #(index-tree-path db %))))
(sort-by #(index-tree-path db %) (selected db)))

(defn select-up
([db multi?]
Expand Down Expand Up @@ -529,7 +527,7 @@
style-attrs (disj spec/presentation-attrs :transform)]
(reduce (fn [db attr]
(cond-> db
(-> attrs attr)
(attr attrs)
(update-attr el attr #(if % (-> attrs attr) disj))))
db style-attrs)) db)))

Expand All @@ -547,7 +545,7 @@
(defn set-parent-at-index
[db element-key parent-key index]
(let [siblings (:children (element db parent-key))
last-index (-> siblings count)]
last-index (count siblings)]
(-> db
(set-parent element-key parent-key)
(update-prop parent-key :children vec/move last-index index))))
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@
:wheel
(if (some (:modifiers e) [:ctrl :alt])
(let [delta-y (second delta)
factor (Math/pow (+ 1 (/ (- 1 (:zoom-sensitivity db)) 100))
factor (Math/pow (inc (/ (- 1 (:zoom-sensitivity db)) 100))
(- delta-y))]
(frame-h/zoom-in-pointer-position db factor))
(frame-h/pan db delta))
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/frame/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
(rf/reg-event-db
:frame/resize
(fn [{content-rect :content-rect :as db} [_ updated-content-rect]]
(let [offset (-> (merge-with - content-rect updated-content-rect)
(select-keys [:width :height]))
(let [offset (select-keys (merge-with - content-rect updated-content-rect)
[:width :height])
pan (mat/div [(:width offset) (:height offset)] 2)]
(-> db
(assoc :content-rect updated-content-rect)
Expand Down
12 changes: 4 additions & 8 deletions src/renderer/menubar/views.cljs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
(ns renderer.menubar.views
(:require
["@radix-ui/react-menubar" :as Menubar]
[i18n :refer [t]]
[re-frame.core :as rf]
[renderer.components :as comp]))

Expand Down Expand Up @@ -350,10 +349,7 @@

(defn root
[]
[:> Menubar/Root
{:class "menubar-root"
:onValueChange #(rf/dispatch [:set-backdrop (seq %)])}
(map (fn [item] ^{:key item} [menu-item item]) menu)
[:button.button.px-3.flex.items-center
{:on-click #(rf/dispatch [:cmdk/toggle])}
(t [:cmdk/search "Search…"])]])
(into [:> Menubar/Root
{:class "menubar-root"
:onValueChange #(rf/dispatch [:set-backdrop (seq %)])}]
(map menu-item menu)))
2 changes: 1 addition & 1 deletion src/renderer/overlay.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@
[x1 y1 x2 y2] bounds
[w h] (bounds/->dimensions bounds)]
[:g {:key :bounding-handlers}
(map (fn [handler] [scale-handler handler])
(map scale-handler
[{:x x1 :y y1 :key :top-left :cursor "nwse-resize"}
{:x x2 :y y1 :key :top-right :cursor "nesw-resize"}
{:x x1 :y y2 :key :bottom-left :cursor "nesw-resize"}
Expand Down
15 changes: 7 additions & 8 deletions src/renderer/reepl/completions.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
(def view (partial helpers/view styles))

(def canScrollIfNeeded
(not (nil? (.-scrollIntoViewIfNeeded js/document.body))))
(some? (.-scrollIntoViewIfNeeded js/document.body)))

(defn completion-item [_text _is-selected _is-active _set-active]
(let [ref (react/createRef)]
Expand All @@ -55,13 +55,12 @@
text])})))

(defn completion-list [{:keys [pos list active show-all]} set-active]
(let [items (->> list
(map-indexed
#(-> [completion-item
(get %2 2)
(= %1 pos)
active
(partial set-active %1)])))]
(let [items (map-indexed
#(-> [completion-item
(get %2 2)
(= %1 pos)
active
(partial set-active %1)]) list)]
(when show-all
(into [view :completion-show-all] items))
(into
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/reepl/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@
(do
(clear-items)
(set-text ""))
(when (< 0 (count (.trim text)))
(when (pos? (count (.trim text)))
(set-text text)
(add-input text)
(execute text #(add-result (not %1) %2)))))]
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/reepl/handlers.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
idx (- (count history) pos 1)]
(assoc db
:hist-pos 0
:history (if (= pos 0)
:history (if (zero? pos)
(assoc history idx text)
(if (= "" (last history))
(assoc history (dec (count history)) text)
Expand Down
6 changes: 3 additions & 3 deletions src/renderer/reepl/replumb.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ cljs.js/*load-fn*
(= text a) -1
(= text b) 1
:else
(let [a-starts (= 0 (.indexOf a text))
b-starts (= 0 (.indexOf b text))]
(let [a-starts (zero? (.indexOf a text))
b-starts (zero? (.indexOf b text))]
(cond
(and a-starts b-starts) 0
a-starts -1
Expand Down Expand Up @@ -284,7 +284,7 @@ cljs.js/*load-fn*
(filter matches? names))))))

(defn process-apropos [text]
(if (= 0 (.indexOf text "js/"))
(if (zero? (.indexOf text "js/"))
(js-completion (.slice text 3))
(cljs-completion text)))

Expand Down
5 changes: 3 additions & 2 deletions src/renderer/reepl/show_devtools.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,18 @@

;; see https://docs.google.com/document/d/1FTascZXT9cxfetuPRT2eXPQKXui4nWFivUnS_335T3U/preview
(defn show-devtools [val config show-value]
(if (var? val)
nil
(when-not (var? val)
(let [header (try
(devtools/header-api-call val config)
(catch js/Error e
e))]
(cond
(not header)
nil

(instance? js/Error header)
[:div.inline-flex "Error expanding lazy value"]

:else
(if-not (devtools/has-body-api-call val config)
[:div.inline-flex (show-el header show-value)]
Expand Down
6 changes: 3 additions & 3 deletions src/renderer/tools/canvas.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@
[overlay/bounding-box (tools/adjusted-bounds el elements)])
hovered-or-selected)

(when (> elements-area 0)
(when (pos? elements-area)
[overlay/area elements-area bounds])
(when (not-empty (filter (complement zero?) bounds))

(when (not-empty (remove zero? bounds))
[:<>
[overlay/size bounds]
[overlay/bounding-handlers bounds]])
Expand Down
14 changes: 7 additions & 7 deletions src/renderer/tools/polyshape.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@

(defmethod tools/activate ::tools/polyshape
[db]
(-> db
(handlers/set-message
[:div
[:div "Click to add points."]
[:div "Double click to finalize the shape."]])))
(handlers/set-message
db
[:div
[:div "Click to add points."]
[:div "Double click to finalize the shape."]]))

(defn create-polyline
[{:keys [active-document tool] :as db} points]
Expand Down Expand Up @@ -169,8 +169,8 @@
(defmethod tools/centroid ::tools/polyshape
[{{:keys [points]} :attrs}]
(let [points-v (attr.utils/points->px points)]
(-> (reduce mat/add [0 0] points-v)
(mat/div (count points-v)))))
(mat/div (reduce mat/add [0 0] points-v)
(count points-v))))

(defmethod tools/poi ::tools/polyshape
[{{:keys [points]} :attrs}]
Expand Down
4 changes: 3 additions & 1 deletion src/renderer/utils/vec.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
(let [el (nth coll index-1)]
(if (= index-1 index-2)
coll
(into [] (add (remove-by-index coll index-1) index-2 el)))))
(-> (remove-by-index coll index-1)
(add index-2 el)
vec))))

(defn swap
"Swaps the position of two elements by index."
Expand Down
4 changes: 4 additions & 0 deletions src/renderer/window/views.cljs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
(ns renderer.window.views
(:require
[i18n :refer [t]]
[platform :as platform]
[re-frame.core :as rf]
[renderer.components :as comp]
Expand Down Expand Up @@ -39,6 +40,9 @@
:style {:width "14px"
:height "14px"}}]]
[menubar/root]
[:button.button.px-3.flex.items-center
{:on-click #(rf/dispatch [:cmdk/toggle])}
(t [:cmdk/search "Search…"])]
[title-bar]
[:div.level-2
{:class (when-not platform/electron? "mr-1.5")}
Expand Down

0 comments on commit bbd3d63

Please sign in to comment.