0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-08 16:18:11 -05:00

🔧 Some style enhancements and mini bug fix

This commit is contained in:
Andrés Moya 2022-07-28 15:10:11 +02:00
parent c108974ad2
commit 0667089833
11 changed files with 83 additions and 90 deletions

View file

@ -123,17 +123,13 @@
(db/with-atomic [conn pool]
(files/check-edition-permissions! conn profile-id id)
(when-not is-shared
(absorb-library conn params)
(unlink-files conn params))
(absorb-library conn params)
(unlink-files conn params))
(set-file-shared conn params)))
(def sql:unlink-files
"delete from file_library_rel
where library_file_id = ?")
(defn- unlink-files
[conn {:keys [id] :as params}]
(db/exec-one! conn [sql:unlink-files id]))
(db/delete! conn :file-library-rel {:library-file-id id}))
(defn- set-file-shared
[conn {:keys [id is-shared] :as params}]
@ -162,11 +158,6 @@
{:id id})
nil)
(def sql:find-files
"select file_id
from file_library_rel
where library_file_id=?")
(defn absorb-library
"Find all files using a shared library, and absorb all library assets
into the file local libraries"
@ -189,8 +180,7 @@
:modified-at ts}
{:id (:id file)})))]
(dorun (->> (db/exec! conn [sql:find-files id])
(map process-file)))))))
(run! process-file (db/query conn :file-library-rel {:library-file-id id}))))))
;; --- Mutation: Link file to library

View file

@ -52,12 +52,12 @@
; TODO: perhaps some day we want after transformations, but for the
; moment it's enough as is now.
[shape]
(get shape :x (:x (:selrect shape)))) ; Paths don't have :x attribute
(or (:x shape) (:x (:selrect shape)))) ; Paths don't have :x attribute
(defn top-bound
"Returns the lowest y coord of the shape BEFORE applying transformations."
[shape]
(get shape :y (:y (:selrect shape)))) ; Paths don't have :y attribute
(or (:y shape) (:y (:selrect shape)))) ; Paths don't have :y attribute
(defn fully-contained?
"Checks if one rect is fully inside the other"

View file

@ -477,9 +477,9 @@
(component-sync-attrs (:attr operation))))
any-sync? (some need-sync? operations)]
(when any-sync?
(into #{} (->> shape-and-parents
(filter #(:main-instance? %)) ; Select shapes that are main component instances
(map :id)))))))
(let [xform (comp (filter :main-instance?) ; Select shapes that are main component instances
(map :id))]
(into #{} xform shape-and-parents))))))
(defmethod components-changed :default
[_ _]

View file

@ -246,38 +246,38 @@
(defn- process-shape-colors
"Execute an update function on all colors of a shape."
[shape func]
[shape process-fn]
(let [process-fill (fn [shape [position fill]]
(func shape
position
(fill->shape-color fill)
set-fill-color
attach-fill-color
detach-fill-color))
(process-fn shape
position
(fill->shape-color fill)
set-fill-color
attach-fill-color
detach-fill-color))
process-stroke (fn [shape [position stroke]]
(func shape
position
(stroke->shape-color stroke)
set-stroke-color
attach-stroke-color
detach-stroke-color))
(process-fn shape
position
(stroke->shape-color stroke)
set-stroke-color
attach-stroke-color
detach-stroke-color))
process-shadow (fn [shape [position shadow]]
(func shape
position
(shadow->shape-color shadow)
set-shadow-color
attach-shadow-color
detach-shadow-color))
(process-fn shape
position
(shadow->shape-color shadow)
set-shadow-color
attach-shadow-color
detach-shadow-color))
process-grid (fn [shape [position grid]]
(func shape
position
(grid->shape-color grid)
set-grid-color
attach-grid-color
detach-grid-color))
(process-fn shape
position
(grid->shape-color grid)
set-grid-color
attach-grid-color
detach-grid-color))
process-text-node (fn [node]
(as-> node $
@ -302,13 +302,13 @@
"Change the shape so that any use of the given color now points to
the given library."
[shape library-id color]
(let [remap-color (fn [shape position shape-color _ attach-fn _]
(if (= (:ref-id shape-color) (:id color))
(attach-fn shape
position
(:id color)
library-id)
shape))]
(letfn [(remap-color [shape position shape-color _ attach-fn _]
(if (= (:ref-id shape-color) (:id color))
(attach-fn shape
position
(:id color)
library-id)
shape))]
(process-shape-colors shape remap-color)))
@ -316,17 +316,17 @@
"Look for usage of any color of the given library inside the shape,
and, in this case, copy the library color into the shape."
[shape library-id library-colors]
(let [sync-color (fn [shape position shape-color set-fn _ detach-fn]
(if (= (:ref-file shape-color) library-id)
(let [library-color (get library-colors (:ref-id shape-color))]
(if (some? library-color)
(set-fn shape
position
(:color library-color)
(:opacity library-color)
(:gradient library-color))
(detach-fn shape position)))
shape))]
(letfn [(sync-color [shape position shape-color set-fn _ detach-fn]
(if (= (:ref-file shape-color) library-id)
(let [library-color (get library-colors (:ref-id shape-color))]
(if (some? library-color)
(set-fn shape
position
(:color library-color)
(:opacity library-color)
(:gradient library-color))
(detach-fn shape position)))
shape))]
(process-shape-colors shape sync-color)))

View file

@ -24,9 +24,8 @@
:objects (d/index-by :id shapes)})
components-v2
(update-in [:components id] #(assoc %
:main-instance-id main-instance-id
:main-instance-page main-instance-page)))))
(update-in [:components id] assoc :main-instance-id main-instance-id
:main-instance-page main-instance-page))))
(defn get-component
[file-data component-id]

View file

@ -96,7 +96,7 @@
:component-file file-id
:component-root? true)
components-v2
(and (nil? (:parent-id new-shape)) components-v2)
(assoc :main-instance? true)
(some? (:parent-id new-shape))

View file

@ -165,10 +165,10 @@
assets-seq)))
(defn get-or-add-library-page
"If exists a page named 'Library page', get the id and calculate the position to start
"If exists a page named 'Library backup', get the id and calculate the position to start
adding new components. If not, create it and start at (0, 0)."
[file-data grid-gap]
(let [library-page (d/seek #(= (:name %) "Library page") (ctpl/pages-seq file-data))]
(let [library-page (d/seek #(= (:name %) "Library backup") (ctpl/pages-seq file-data))]
(if (some? library-page)
(let [compare-pos (fn [pos shape]
(let [bounds (gsh/bounding-box shape)]
@ -180,11 +180,11 @@
(gpt/point 0 0)
(ctn/shapes-seq library-page))]
[file-data (:id library-page) position])
(let [library-page (ctp/make-empty-page (uuid/next) "Library page")]
(let [library-page (ctp/make-empty-page (uuid/next) "Library backup")]
[(ctpl/add-page file-data library-page) (:id library-page) (gpt/point 0 0)]))))
(defn migrate-to-components-v2
"If there is any component in the file library, add a new 'Library Page' and generate
"If there is any component in the file library, add a new 'Library backup' and generate
main instances for all components there. Mark the file with the :comonents-v2 option."
[file-data]
(let [components (ctkl/components-seq file-data)]

View file

@ -104,7 +104,7 @@
(t/is (= (count pages) 2))
(t/is (= (:name (first pages)) "Page-1"))
(t/is (= (:name (second pages)) "Library page"))
(t/is (= (:name (second pages)) "Library backup"))
(t/is (= (count components) 1))

View file

@ -770,12 +770,12 @@
(rx/filter #(or (= :app.main.data.workspace/finalize-page (ptk/type %))
(= ::watch-component-changes (ptk/type %)))))
workspace-data-str
workspace-data-s
(->> (rx/concat
(rx/of nil)
(rx/from-atom refs/workspace-data {:emit-current-value? true})))
change-str
change-s
(->> stream
(rx/filter #(or (dch/commit-changes? %)
(= (ptk/type %) :app.main.data.workspace.notifications/handle-file-change)))
@ -788,13 +788,13 @@
#{}
changes)]
(when (d/not-empty? components-changed)
(apply st/emit!
(run! st/emit!
(map #(update-component-sync % (:id data))
components-changed)))))]
(when components-v2
(->> change-str
(rx/with-latest-from workspace-data-str)
(->> change-s
(rx/with-latest-from workspace-data-s)
(rx/map check-changes)
(rx/take-until stopper)))))))
@ -844,12 +844,13 @@
[file-id library-id]
(ptk/reify ::attach-library
ptk/WatchEvent
(watch [_ _ _]
(let [fetched #(assoc-in %2 [:workspace-libraries (:id %1)] %1)
params {:file-id file-id
:library-id library-id}]
(watch [_ state _]
(let [components-v2 (features/active-feature? state :components-v2)
fetched #(assoc-in %2 [:workspace-libraries (:id %1)] %1)
params {:file-id file-id
:library-id library-id}]
(->> (rp/mutation :link-file-to-library params)
(rx/mapcat #(rp/query :file {:id library-id}))
(rx/mapcat #(rp/query :file {:id library-id :components-v2 components-v2}))
(rx/map #(partial fetched %)))))))
(defn unlink-file-from-library

View file

@ -8,6 +8,7 @@
(:require
[app.common.data :as d]
[app.main.data.modal :as modal]
[app.main.features :as features]
[app.main.store :as st]
[app.main.ui.icons :as i]
[app.main.worker :as uw]
@ -56,6 +57,8 @@
:files (->> files (mapv #(assoc % :loading? true)))})
selected-option (mf/use-state :all)
components-v2 (features/use-feature :components-v2)
start-export
(fn []
(swap! state assoc :status :exporting)
@ -64,7 +67,7 @@
:team-id team-id
:export-type @selected-option
:files files
})
:components-v2 components-v2})
(rx/delay-emit 1000)
(rx/subs
(fn [msg]

View file

@ -149,8 +149,8 @@
(->> (r/render-components (:data file))
(rx/map #(vector (str (:id file) "/components.svg") %))))
(defn fetch-file-with-libraries [file-id]
(->> (rx/zip (rp/query :file {:id file-id})
(defn fetch-file-with-libraries [file-id components-v2]
(->> (rx/zip (rp/query :file {:id file-id :components-v2 components-v2})
(rp/query :file-libraries {:file-id file-id}))
(rx/map
(fn [[file file-libraries]]
@ -351,7 +351,7 @@
(update file-id dissoc :libraries))))
(defn collect-files
[file-id export-type]
[file-id export-type components-v2]
(letfn [(fetch-dependencies [[files pending]]
(if (empty? pending)
@ -365,7 +365,7 @@
;; The file is already in the result
(rx/of [files pending])
(->> (fetch-file-with-libraries next)
(->> (fetch-file-with-libraries next components-v2)
(rx/map
(fn [file]
[(-> files
@ -381,9 +381,9 @@
(rx/map #(process-export file-id export-type %))))))
(defn export-file
[team-id file-id export-type]
[team-id file-id export-type components-v2]
(let [files-stream (->> (collect-files file-id export-type)
(let [files-stream (->> (collect-files file-id export-type components-v2)
(rx/share))
manifest-stream
@ -471,12 +471,12 @@
:file-id (:id file)}))))))))
(defmethod impl/handler :export-standard-file
[{:keys [team-id files export-type] :as message}]
[{:keys [team-id files export-type components-v2] :as message}]
(->> (rx/from files)
(rx/mapcat
(fn [file]
(->> (export-file team-id (:id file) export-type)
(->> (export-file team-id (:id file) export-type components-v2)
(rx/map
(fn [value]
(if (contains? value :type)