mirror of
https://github.com/penpot/penpot.git
synced 2025-05-21 21:17:15 +02:00
🎉 Add generic file object thumbnail abstraction
As replacement to the file frame thumbnail mechanism
This commit is contained in:
parent
147f56749e
commit
20d3251a93
15 changed files with 399 additions and 212 deletions
|
@ -964,18 +964,23 @@
|
|||
(ptk/reify ::toggle-file-thumbnail-selected
|
||||
ptk/WatchEvent
|
||||
(watch [_ state _]
|
||||
(let [selected (wsh/lookup-selected state)
|
||||
pages (-> state :workspace-data :pages-index vals)
|
||||
extract (fn [{:keys [objects id] :as page}]
|
||||
(->> (cph/get-frames objects)
|
||||
(filter :file-thumbnail)
|
||||
(map :id)
|
||||
(remove selected)
|
||||
(map (fn [frame-id] [id frame-id]))))]
|
||||
(let [selected (wsh/lookup-selected state)
|
||||
pages (-> state :workspace-data :pages-index vals)
|
||||
get-frames (fn [{:keys [objects id] :as page}]
|
||||
(->> (cph/get-frames objects)
|
||||
(sequence
|
||||
(comp (filter :use-for-thumbnail?)
|
||||
(map :id)
|
||||
(remove selected)
|
||||
(map (partial vector id))))))]
|
||||
|
||||
(rx/concat
|
||||
(rx/from (for [[page-id frame-id] (mapcat extract pages)]
|
||||
(dch/update-shapes [frame-id] #(dissoc % :file-thumbnail) page-id nil)))
|
||||
(rx/of (dch/update-shapes selected #(assoc % :file-thumbnail true))))))))
|
||||
(rx/from
|
||||
(->> (mapcat get-frames pages)
|
||||
(d/group-by first second)
|
||||
(map (fn [[page-id frame-ids]]
|
||||
(dch/update-shapes frame-ids #(dissoc % :use-for-thumbnail?) {:page-id page-id})))))
|
||||
(rx/of (dch/update-shapes selected #(update % :use-for-thumbnail? not))))))))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Navigation
|
||||
|
|
|
@ -32,10 +32,9 @@
|
|||
(def commit-changes? (ptk/type? ::commit-changes))
|
||||
|
||||
(defn update-shapes
|
||||
([ids update-fn] (update-shapes ids update-fn nil nil))
|
||||
([ids update-fn keys] (update-shapes ids update-fn nil keys))
|
||||
([ids update-fn page-id {:keys [reg-objects? save-undo? attrs ignore-tree]
|
||||
:or {reg-objects? false save-undo? true attrs nil}}]
|
||||
([ids update-fn] (update-shapes ids update-fn nil))
|
||||
([ids update-fn {:keys [reg-objects? save-undo? attrs ignore-tree page-id]
|
||||
:or {reg-objects? false save-undo? true}}]
|
||||
|
||||
(us/assert ::coll-of-uuid ids)
|
||||
(us/assert fn? update-fn)
|
||||
|
|
|
@ -7,8 +7,6 @@
|
|||
(ns app.main.ui.viewer.shapes
|
||||
"The main container for a frame in viewer mode"
|
||||
(:require
|
||||
[app.common.geom.matrix :as gmt]
|
||||
[app.common.geom.point :as gpt]
|
||||
[app.common.geom.shapes :as geom]
|
||||
[app.common.pages.helpers :as cph]
|
||||
[app.common.spec.interactions :as cti]
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
"A workspace specific context menu (mouse right click)."
|
||||
(:require
|
||||
[app.common.data :as d]
|
||||
[app.common.pages.helpers :as cph]
|
||||
[app.common.spec.page :as csp]
|
||||
[app.main.data.events :as ev]
|
||||
[app.main.data.modal :as modal]
|
||||
|
@ -167,13 +168,12 @@
|
|||
|
||||
(mf/defc context-menu-thumbnail
|
||||
[{:keys [shapes]}]
|
||||
(let [single? (= (count shapes) 1)
|
||||
has-frame? (->> shapes (d/seek #(= :frame (:type %))))
|
||||
is-frame? (and single? has-frame?)
|
||||
(let [single? (= (count shapes) 1)
|
||||
has-frame? (some cph/frame-shape? shapes)
|
||||
do-toggle-thumbnail (st/emitf (dw/toggle-file-thumbnail-selected))]
|
||||
(when is-frame?
|
||||
(when (and single? has-frame?)
|
||||
[:*
|
||||
(if (every? :file-thumbnail shapes)
|
||||
(if (every? :use-for-thumbnail? shapes)
|
||||
[:& menu-entry {:title (tr "workspace.shape.menu.thumbnail-remove")
|
||||
:on-click do-toggle-thumbnail}]
|
||||
[:& menu-entry {:title (tr "workspace.shape.menu.thumbnail-set")
|
||||
|
|
|
@ -106,8 +106,7 @@
|
|||
(repo/query! :font-variants {:file-id file-id})
|
||||
(repo/query! :page {:file-id file-id
|
||||
:page-id page-id
|
||||
:object-id object-id
|
||||
:prune-thumbnails true}))
|
||||
:object-id object-id}))
|
||||
(rx/tap (fn [[fonts]]
|
||||
(when (seq fonts)
|
||||
(st/emit! (df/fonts-fetched fonts)))))
|
||||
|
@ -146,8 +145,7 @@
|
|||
(->> (rx/zip
|
||||
(repo/query! :font-variants {:file-id file-id})
|
||||
(repo/query! :page {:file-id file-id
|
||||
:page-id page-id
|
||||
:prune-thumbnails true}))
|
||||
:page-id page-id}))
|
||||
(rx/tap (fn [[fonts]]
|
||||
(when (seq fonts)
|
||||
(st/emit! (df/fonts-fetched fonts)))))
|
||||
|
|
|
@ -63,10 +63,12 @@
|
|||
|
||||
(defn- render-thumbnail
|
||||
[{:keys [page file-id revn] :as params}]
|
||||
(let [elem (if-let [frame (:thumbnail-frame page)]
|
||||
(mf/element render/frame-svg #js {:objects (:objects page) :frame frame})
|
||||
(mf/element render/page-svg #js {:data page :thumbnails? true}))]
|
||||
{:data (rds/renderToStaticMarkup elem)
|
||||
(let [objects (:objects page)
|
||||
frame (some->> page :thumbnail-frame-id (get objects))
|
||||
element (if frame
|
||||
(mf/element render/frame-svg #js {:objects objects :frame frame})
|
||||
(mf/element render/page-svg #js {:data page :thumbnails? true}))]
|
||||
{:data (rds/renderToStaticMarkup element)
|
||||
:fonts @fonts/loaded
|
||||
:file-id file-id
|
||||
:revn revn}))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue