0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-03-18 18:51:29 -05:00

Merge remote-tracking branch 'origin/main' into develop

This commit is contained in:
alonso.torres 2021-05-07 13:34:48 +02:00
commit 6d5276c0c6
10 changed files with 100 additions and 83 deletions

View file

@ -11,6 +11,13 @@
### :boom: Breaking changes
### :heart: Community contributions by (Thank you!)
## 1.5.2-alpha
### :bug: Bugs fixed
- Fix problem with `close-path` command [#917](https://github.com/penpot/penpot/issues/917)
- Fix wrong query for obtain the profile default project-id
- Fix problems with empty paths and shortcuts [#923](https://github.com/penpot/penpot/issues/923)
## 1.5.1-alpha

View file

@ -65,9 +65,7 @@
"- detail: " (cfg/get :public-uri) "/dbg/error-by-id/" id "\n"
"- profile-id: `" (:profile-id cdata) "`\n"
"- host: `" host "`\n"
"- version: `" version "`\n"
(when error
(str "```\n" (:trace error) "\n```")))
"- version: `" version "`\n")
rsp (http/send! {:uri uri
:method :post
:headers {"content-type" "application/json"}

View file

@ -41,29 +41,27 @@
{:id uuid/zero
:fullname "Anonymous User"}))
;; NOTE: this query make the assumption that union all preserves the
;; order so the first id will always be the team id and the second the
;; project_id; this is a postgresql behavior because UNION ALL works
;; like APPEND operation.
(def ^:private sql:default-team-and-project
"select t.id
(def ^:private sql:default-profile-team
"select t.id, name
from team as t
inner join team_profile_rel as tp on (tp.team_id = t.id)
where tp.profile_id = ?
and tp.is_owner is true
and t.is_default is true
union all
select p.id
and t.is_default is true")
(def ^:private sql:default-profile-project
"select p.id, name
from project as p
inner join project_profile_rel as tp on (tp.project_id = p.id)
where tp.profile_id = ?
and tp.is_owner is true
and p.is_default is true")
and p.is_default is true
and p.team_id = ?")
(defn retrieve-additional-data
[conn id]
(let [[team project] (db/exec! conn [sql:default-team-and-project id id])]
(let [team (db/exec-one! conn [sql:default-profile-team id])
project (db/exec-one! conn [sql:default-profile-project id (:id team)])]
{:default-team-id (:id team)
:default-project-id (:id project)}))

View file

@ -240,10 +240,13 @@
(ptk/reify ::finalize-page
ptk/UpdateEvent
(update [_ state]
(let [local (:workspace-local state)]
(let [local (-> (:workspace-local state)
(dissoc :edition)
(dissoc :edit-path)
(dissoc :selected))]
(-> state
(assoc-in [:workspace-cache page-id] local)
(dissoc :current-page-id :workspace-local :trimmed-page))))))
(dissoc :current-page-id :workspace-local :trimmed-page :workspace-drawing))))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Workspace Page CRUD

View file

@ -9,6 +9,7 @@
[app.common.data :as d]
[app.common.geom.point :as gpt]
[app.common.math :as mth]
[app.main.data.workspace.common :as dwc]
[app.main.data.workspace.changes :as dch]
[app.main.data.workspace.path.changes :as changes]
[app.main.data.workspace.path.common :as common]
@ -63,9 +64,12 @@
[rch uch] (changes/generate-path-changes objects page-id shape (:content shape) new-content)]
(rx/of (dch/commit-changes rch uch {:commit-local? true})
(selection/update-selection point-change)
(fn [state] (update-in state [:workspace-local :edit-path id] dissoc :content-modifiers :moving-nodes :moving-handler)))))))
(if (empty? new-content)
(rx/of (dch/commit-changes rch uch {:commit-local? true})
dwc/clear-edition-mode)
(rx/of (dch/commit-changes rch uch {:commit-local? true})
(selection/update-selection point-change)
(fn [state] (update-in state [:workspace-local :edit-path id] dissoc :content-modifiers :moving-nodes :moving-handler))))))))
(defn modify-content-point
[content {dx :x dy :y} modifiers point]

View file

@ -21,6 +21,8 @@
(defn end-path-event? [{:keys [type shift] :as event}]
(or (= (ptk/type event) ::common/finish-path)
(= (ptk/type event) :esc-pressed)
(= :app.main.data.workspace.common/clear-edition-mode (ptk/type event))
(= :app.main.data.workspace/finalize-page (ptk/type event))
(= event :interrupt) ;; ESC
(and (ms/mouse-double-click? event))))

View file

@ -51,9 +51,9 @@
content (get-in state (st/get-path state :content))
selected-point? #(gsh/has-point-rect? selrect %)
selected-points (get-in state [:workspace-local :edit-path id :selected-points])
positions (into (if shift? selected-points #{})
(comp (map (comp gpt/point :params))
(comp (filter #(not (= (:command %) :close-path)))
(map (comp gpt/point :params))
(filter selected-point?))
content)]
(cond-> state

View file

@ -8,6 +8,7 @@
(:require
[app.common.geom.point :as gpt]
[app.main.data.workspace.changes :as dch]
[app.main.data.workspace.common :as dwc]
[app.main.data.workspace.path.changes :as changes]
[app.main.data.workspace.path.common :as common]
[app.main.data.workspace.path.state :as st]
@ -29,12 +30,16 @@
id (st/get-path-id state)
page-id (:current-page-id state)
shape (get-in state (st/get-path state))
selected-points (get-in state [:workspace-local :edit-path id :selected-points] #{})
points (or points selected-points)
new-content (-> (tool-fn (:content shape) points)
(ups/close-subpaths))
[rch uch] (changes/generate-path-changes objects page-id shape (:content shape) new-content)]
(rx/of (dch/commit-changes rch uch {:commit-local? true})))))))
points (or points selected-points)]
(when-not (empty? points)
(let [new-content (-> (tool-fn (:content shape) points)
(ups/close-subpaths))
[rch uch] (changes/generate-path-changes objects page-id shape (:content shape) new-content)]
(rx/of (dch/commit-changes rch uch {:commit-local? true})
(when (empty? new-content)
dwc/clear-edition-mode)))))))))
(defn make-corner
([]

View file

@ -124,7 +124,8 @@
dissoc :undo-lock :undo-stack)))))
(defn- stop-undo? [event]
(= :app.main.data.workspace.common/clear-edition-mode (ptk/type event)))
(or (= :app.main.data.workspace.common/clear-edition-mode (ptk/type event))
(= :app.main.data.workspace/finalize-page (ptk/type event))))
(def path-content-ref
(letfn [(selector [state]

View file

@ -8,14 +8,10 @@
(:require
[app.common.data :as d]
[app.common.geom.point :as gpt]
[app.common.geom.shapes.path :as gshp]
[app.util.svg :as usvg]
[cuerdas.core :as str]
[clojure.set :as set]
[app.common.math :as mth]
[app.util.path.commands :as upc]
[app.util.path.geom :as upg]
))
[clojure.set :as set]))
(defn remove-line-curves
"Remove all curves that have both handlers in the same position that the
@ -235,70 +231,73 @@
to keep everything consistent"
[content points]
(let [content (d/with-prev content)]
(if (empty? points)
content
(loop [result []
last-handler nil
[cur-cmd prev-cmd] (first content)
content (rest content)]
(let [content (d/with-prev content)]
(if (nil? cur-cmd)
;; The result with be an array of arrays were every entry is a subpath
(->> result
;; remove empty and only 1 node subpaths
(filter #(> (count %) 1))
;; flatten array-of-arrays plain array
(flatten)
(into []))
(loop [result []
last-handler nil
[cur-cmd prev-cmd] (first content)
content (rest content)]
(let [move? (= :move-to (:command cur-cmd))
curve? (= :curve-to (:command cur-cmd))
(if (nil? cur-cmd)
;; The result with be an array of arrays were every entry is a subpath
(->> result
;; remove empty and only 1 node subpaths
(filter #(> (count %) 1))
;; flatten array-of-arrays plain array
(flatten)
(into []))
;; When the old command was a move we start a subpath
result (if move? (conj result []) result)
(let [move? (= :move-to (:command cur-cmd))
curve? (= :curve-to (:command cur-cmd))
subpath (peek result)
;; When the old command was a move we start a subpath
result (if move? (conj result []) result)
point (upc/command->point cur-cmd)
old-prev-point (upc/command->point prev-cmd)
new-prev-point (upc/command->point (peek subpath))
subpath (peek result)
remove? (contains? points point)
point (upc/command->point cur-cmd)
;; We store the first handler for the first curve to be removed to
;; use it for the first handler of the regenerated path
cur-handler (cond
(and (not last-handler) remove? curve?)
(select-keys (:params cur-cmd) [:c1x :c1y])
old-prev-point (upc/command->point prev-cmd)
new-prev-point (upc/command->point (peek subpath))
(not remove?)
nil
remove? (contains? points point)
:else
last-handler)
cur-cmd (cond-> cur-cmd
;; If we're starting a subpath and it's not a move make it a move
(and (not move?) (empty? subpath))
(assoc :command :move-to
:params (select-keys (:params cur-cmd) [:x :y]))
;; We store the first handler for the first curve to be removed to
;; use it for the first handler of the regenerated path
cur-handler (cond
(and (not last-handler) remove? curve?)
(select-keys (:params cur-cmd) [:c1x :c1y])
;; If have a curve the first handler will be relative to the previous
;; point. We change the handler to the new previous point
(and curve? (not (empty? subpath)) (not= old-prev-point new-prev-point))
(update :params merge last-handler))
(not remove?)
nil
head-idx (dec (count result))
:else
last-handler)
result (cond-> result
(not remove?)
(update head-idx conj cur-cmd))]
(recur result
cur-handler
(first content)
(rest content)))))))
cur-cmd (cond-> cur-cmd
;; If we're starting a subpath and it's not a move make it a move
(and (not move?) (empty? subpath))
(assoc :command :move-to
:params (select-keys (:params cur-cmd) [:x :y]))
;; If have a curve the first handler will be relative to the previous
;; point. We change the handler to the new previous point
(and curve? (not (empty? subpath)) (not= old-prev-point new-prev-point))
(update :params merge last-handler))
head-idx (dec (count result))
result (cond-> result
(not remove?)
(update head-idx conj cur-cmd))]
(recur result
cur-handler
(first content)
(rest content))))))))
(defn join-nodes
"Creates new segments between points that weren't previously"