0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-12 18:18:24 -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] (db/with-atomic [conn pool]
(files/check-edition-permissions! conn profile-id id) (files/check-edition-permissions! conn profile-id id)
(when-not is-shared (when-not is-shared
(absorb-library conn params) (absorb-library conn params)
(unlink-files conn params)) (unlink-files conn params))
(set-file-shared conn params))) (set-file-shared conn params)))
(def sql:unlink-files
"delete from file_library_rel
where library_file_id = ?")
(defn- unlink-files (defn- unlink-files
[conn {:keys [id] :as params}] [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 (defn- set-file-shared
[conn {:keys [id is-shared] :as params}] [conn {:keys [id is-shared] :as params}]
@ -162,11 +158,6 @@
{:id id}) {:id id})
nil) nil)
(def sql:find-files
"select file_id
from file_library_rel
where library_file_id=?")
(defn absorb-library (defn absorb-library
"Find all files using a shared library, and absorb all library assets "Find all files using a shared library, and absorb all library assets
into the file local libraries" into the file local libraries"
@ -189,8 +180,7 @@
:modified-at ts} :modified-at ts}
{:id (:id file)})))] {:id (:id file)})))]
(dorun (->> (db/exec! conn [sql:find-files id]) (run! process-file (db/query conn :file-library-rel {:library-file-id id}))))))
(map process-file)))))))
;; --- Mutation: Link file to library ;; --- Mutation: Link file to library

View file

@ -52,12 +52,12 @@
; TODO: perhaps some day we want after transformations, but for the ; TODO: perhaps some day we want after transformations, but for the
; moment it's enough as is now. ; moment it's enough as is now.
[shape] [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 (defn top-bound
"Returns the lowest y coord of the shape BEFORE applying transformations." "Returns the lowest y coord of the shape BEFORE applying transformations."
[shape] [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? (defn fully-contained?
"Checks if one rect is fully inside the other" "Checks if one rect is fully inside the other"

View file

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

View file

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

View file

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

View file

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

View file

@ -165,10 +165,10 @@
assets-seq))) assets-seq)))
(defn get-or-add-library-page (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)." adding new components. If not, create it and start at (0, 0)."
[file-data grid-gap] [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) (if (some? library-page)
(let [compare-pos (fn [pos shape] (let [compare-pos (fn [pos shape]
(let [bounds (gsh/bounding-box shape)] (let [bounds (gsh/bounding-box shape)]
@ -180,11 +180,11 @@
(gpt/point 0 0) (gpt/point 0 0)
(ctn/shapes-seq library-page))] (ctn/shapes-seq library-page))]
[file-data (:id library-page) position]) [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)])))) [(ctpl/add-page file-data library-page) (:id library-page) (gpt/point 0 0)]))))
(defn migrate-to-components-v2 (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." main instances for all components there. Mark the file with the :comonents-v2 option."
[file-data] [file-data]
(let [components (ctkl/components-seq file-data)] (let [components (ctkl/components-seq file-data)]

View file

@ -104,7 +104,7 @@
(t/is (= (count pages) 2)) (t/is (= (count pages) 2))
(t/is (= (:name (first pages)) "Page-1")) (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)) (t/is (= (count components) 1))

View file

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

View file

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

View file

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