Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance scaling and refactor #64

Merged
merged 32 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
5ee92cd
refactor handlers
sprocketc Nov 23, 2023
2e12903
fix fill tool
sprocketc Nov 23, 2023
0b5f675
introduce selected bounds fn
sprocketc Nov 23, 2023
5aee01a
wip: enhance scale and refactor handlers
sprocketc Nov 25, 2023
94ab066
maintain index and attrs on ungroup
sprocketc Nov 26, 2023
6b33881
remove update-selected-by fn
sprocketc Nov 26, 2023
50b271f
upgrade bcd
sprocketc Nov 26, 2023
d33b743
fix scale ratio locking
sprocketc Nov 26, 2023
5f77d36
hide bounding handlers on non-default states
sprocketc Nov 26, 2023
763a82b
fix selected bounds
sprocketc Nov 27, 2023
61c1333
fix scaling
sprocketc Nov 27, 2023
1e8a5a0
rename scale method
sprocketc Nov 27, 2023
bc813d3
fix box bounds
sprocketc Nov 27, 2023
6bf3ae1
refactor units
sprocketc Nov 27, 2023
349289b
fix align method
sprocketc Nov 27, 2023
d99b7b5
prevent default on group
sprocketc Nov 27, 2023
8b1de41
fix invert selection
sprocketc Nov 28, 2023
cc89ea2
restrict positive length
sprocketc Nov 28, 2023
ffd5651
fix bounding box display
sprocketc Nov 28, 2023
831f5e7
remove stroke from bounds calculations
sprocketc Nov 28, 2023
a19a1ce
fix line scale
sprocketc Nov 28, 2023
7a824c1
enhance style
sprocketc Nov 28, 2023
9998242
fix path scale
sprocketc Nov 28, 2023
9b96792
enhance zoom
sprocketc Nov 28, 2023
c0967c8
upgrade electron
sprocketc Nov 29, 2023
c122e49
remove unneeded requires
sprocketc Nov 29, 2023
45c1d18
refactor keyboard events
sprocketc Nov 29, 2023
03d7d71
enhance zoom input
sprocketc Nov 29, 2023
0727483
enhance zoom input
sprocketc Nov 29, 2023
80ed17a
fix scale of shapes
sprocketc Nov 29, 2023
73dede6
enhance namespaces
sprocketc Nov 29, 2023
908b4a7
fixe namespaces
sprocketc Nov 29, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ we use the following conventions
- el - element
- attr, attrs - attribute, attributes

We also use the following namespace aliases

- v - views
- e - events
- h - handlers
- s - subs

If the namespace belongs to a different module, we use `module.v`.

## App structure

Main structure
Expand All @@ -39,7 +48,6 @@ module\
├── db.cljs <--- schema, validation
├── views.cljs <--- reagent views
├── events.cljs <--- event handlers
├── effects.cljs <--- effectful handlers
├── subs.cljs <--- subscription handlers
├── handlers.cljs <--- helper functions for db transformations
├── styles.css <--- styles
Expand Down
28 changes: 14 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
},
"main": "resources/main.js",
"devDependencies": {
"@mdn/browser-compat-data": "5.4.0",
"@mdn/browser-compat-data": "5.4.1",
"@playwright/test": "^1.39.0",
"@radix-ui/react-context-menu": "2.1.5",
"@radix-ui/react-dropdown-menu": "2.0.6",
Expand All @@ -78,7 +78,7 @@
"cmdk": "0.2.0",
"codemirror": "5.65.15",
"create-react-class": "15.7.0",
"electron": "27.0.3",
"electron": "27.1.2",
"electron-builder": "24.9.1",
"element-to-path": "1.2.1",
"highlight.js": "11.7.0",
Expand Down
10 changes: 5 additions & 5 deletions src/renderer/attribute/angle.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
(:require
["@radix-ui/react-popover" :as Popover]
[renderer.attribute.hierarchy :as hierarchy]
[renderer.attribute.views :as views]
[renderer.attribute.views :as v]
[renderer.components :as comp]))

(defmethod hierarchy/form-element ::angle
[k v disabled? initial]
[:<>
[views/form-input {:key k
:value v
:disabled? disabled?
:placeholder initial}]
[v/form-input {:key k
:value v
:disabled? disabled?
:placeholder initial}]
[:> Popover/Root {:modal true}
[:> Popover/Trigger {:asChild true}
[:button.button.ml-px.level-2.text-muted
Expand Down
10 changes: 5 additions & 5 deletions src/renderer/attribute/color.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
["@re-path/react-color" :refer [ChromePicker]]
[re-frame.core :as rf]
[renderer.attribute.hierarchy :as hierarchy]
[renderer.attribute.views :as views]))
[renderer.attribute.views :as v]))

(derive :stroke ::color)
(derive :fill ::color)
Expand All @@ -14,10 +14,10 @@
(defmethod hierarchy/form-element ::color
[k v disabled? initial]
[:<>
[views/form-input {:key k
:value v
:disabled? disabled?
:placeholder initial}]
[v/form-input {:key k
:value v
:disabled? disabled?
:placeholder initial}]
[:> Popover/Root {:modal true}
[:> Popover/Trigger {:asChild true}
[:button.color-drip.ml-px.inline-block
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/attribute/hierarchy.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
(defmulti form-element (fn [k _v _disabled? _initial] k))

(defmethod update-attr :default
[el attr f & args]
(update-in el [:attrs attr] f (first args)))
[el attr f & more]
(apply update-in el [:attrs attr] f more))

(defmethod description :d
[]
Expand Down
28 changes: 18 additions & 10 deletions src/renderer/attribute/length.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
(:require
[re-frame.core :as rf]
[renderer.attribute.hierarchy :as hierarchy]
[renderer.attribute.views :as views]
[renderer.attribute.views :as v]
[renderer.components :as comp]
[renderer.utils.units :as units]))

Expand All @@ -17,17 +17,20 @@
(derive :cy ::length)
(derive :dx ::length)
(derive :dy ::length)
(derive :width ::length)
(derive :height ::length)
(derive :stroke-width ::length)
(derive :r ::length)
(derive :rx ::length)
(derive :ry ::length)

(derive ::positive-length ::length)

(derive :width ::positive-length)
(derive :height ::positive-length)
(derive :stroke-width ::positive-length)
(derive :r ::positive-length)
(derive :rx ::positive-length)
(derive :ry ::positive-length)

(defmethod hierarchy/form-element ::length
[k v disabled? initial]
[:div.flex.w-full
[views/form-input
[v/form-input
{:key k
:value v
:disabled? disabled?
Expand All @@ -47,5 +50,10 @@
[comp/icon "plus" {:class "small"}]]]])

(defmethod hierarchy/update-attr ::length
[element attribute f & args]
(update-in element [:attrs attribute] #(units/transform f (first args) %)))
[element attribute f & more]
(update-in element [:attrs attribute] #(apply units/transform % f more)))

(defmethod hierarchy/update-attr ::positive-length
[element attribute f & more]
(update-in element [:attrs attribute]
#(units/transform % (fn [v] (max 0 (apply f v more))))))
4 changes: 2 additions & 2 deletions src/renderer/attribute/overflow.cljs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(ns renderer.attribute.overflow
(:require
[renderer.attribute.hierarchy :as hierarchy]
[renderer.attribute.views :as views]))
[renderer.attribute.views :as v]))

(defmethod hierarchy/description :overflow
[]
Expand All @@ -11,7 +11,7 @@

(defmethod hierarchy/form-element :overflow
[k v disabled? _initial]
[views/select-input
[v/select-input
{:key k
:value v
:disabled? disabled?
Expand Down
14 changes: 7 additions & 7 deletions src/renderer/attribute/points.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[re-frame.core :as rf]
[renderer.attribute.hierarchy :as hierarchy]
[renderer.attribute.utils :as utils]
[renderer.attribute.views :as views]
[renderer.attribute.views :as v]
[renderer.components :as comp]
[renderer.utils.vec :as vec]))

Expand All @@ -26,11 +26,11 @@
[k v disabled?]
(let [state-default? (= @(rf/subscribe [:state]) :default)]
[:<>
[views/form-input {:key k
:value (if state-default? v "waiting")
:disabled? (or disabled?
(not v)
(not state-default?))}]
[v/form-input {:key k
:value (if state-default? v "waiting")
:disabled? (or disabled?
(not v)
(not state-default?))}]
(when v
[:> Popover/Root {:modal true}
[:> Popover/Trigger {:asChild true}
Expand All @@ -43,7 +43,7 @@
:className "popover-content"
:align "end"}
(when state-default?
(let [points (utils/points-to-vec v)]
(let [points (utils/points->vec v)]
[:div.flex.flex-col.v-scroll.py-4.pr-2
{:style {:max-height "500px"}}
(map-indexed (fn [index [x y]]
Expand Down
10 changes: 5 additions & 5 deletions src/renderer/attribute/range.cljs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
(ns renderer.attribute.range
(:require
[renderer.attribute.hierarchy :as hierarchy]
[renderer.attribute.views :as views]))
[renderer.attribute.views :as v]))

(derive :opacity ::range)

(defmethod hierarchy/form-element ::range
[k v disabled? initial]
[views/range-input k v {:disabled disabled?
:min 0
:max 1
:step 0.01} initial])
[v/range-input k v {:disabled disabled?
:min 0
:max 1
:step 0.01} initial])
36 changes: 18 additions & 18 deletions src/renderer/attribute/stroke_linecap.cljs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(ns renderer.attribute.stroke-linecap
(:require
[renderer.attribute.hierarchy :as hierarchy]
[renderer.attribute.views :as views]))
[renderer.attribute.views :as v]))

(defmethod hierarchy/description :stroke-linecap
[]
Expand All @@ -10,20 +10,20 @@

(defmethod hierarchy/form-element :stroke-linecap
[k v disabled? initial]
[views/select-input {:key k
:value v
:disabled? disabled?
:initial initial
:default-value "butt"
:items [{:key :butt
:value "butt"
:label "Butt"
:icon "linecap-butt"}
{:key :round
:value "round"
:label "Round"
:icon "linecap-round"}
{:key :square
:value "square"
:label "Square"
:icon "linecap-square"}]}])
[v/select-input {:key k
:value v
:disabled? disabled?
:initial initial
:default-value "butt"
:items [{:key :butt
:value "butt"
:label "Butt"
:icon "linecap-butt"}
{:key :round
:value "round"
:label "Round"
:icon "linecap-round"}
{:key :square
:value "square"
:label "Square"
:icon "linecap-square"}]}])
30 changes: 15 additions & 15 deletions src/renderer/attribute/stroke_linejoin.cljs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(ns renderer.attribute.stroke-linejoin
(:require
[renderer.attribute.hierarchy :as hierarchy]
[renderer.attribute.views :as views]))
[renderer.attribute.views :as v]))

(defmethod hierarchy/description :stroke-linejoin
[]
Expand All @@ -10,17 +10,17 @@

(defmethod hierarchy/form-element :stroke-linejoin
[k v disabled? initial]
[views/select-input {:key k
:value v
:disabled? disabled?
:initial initial
:default-value "miter"
:items [{:key :bevel
:value "bevel"
:label "Bevel"}
{:key :miter
:value "miter"
:label "Miter"}
{:key :round
:value "round"
:label "Round"}]}])
[v/select-input {:key k
:value v
:disabled? disabled?
:initial initial
:default-value "miter"
:items [{:key :bevel
:value "bevel"
:label "Bevel"}
{:key :miter
:value "miter"
:label "Miter"}
{:key :round
:value "round"
:label "Round"}]}])
Loading
Loading