mirror of
https://github.com/penpot/penpot.git
synced 2025-02-10 17:18:21 -05:00
🐛 Fix problems with thumbnails
This commit is contained in:
parent
108291337d
commit
e0a1da6bca
5 changed files with 68 additions and 67 deletions
|
@ -190,7 +190,16 @@
|
||||||
(conj (:id shape))))]
|
(conj (:id shape))))]
|
||||||
(reduce-objects objects (complement frame-shape?) add-frame [])))
|
(reduce-objects objects (complement frame-shape?) add-frame [])))
|
||||||
|
|
||||||
|
(defn get-root-objects
|
||||||
|
"Get all the objects under the root object"
|
||||||
|
[objects]
|
||||||
|
(let [add-shape
|
||||||
|
(fn [result shape]
|
||||||
|
(conj result shape))]
|
||||||
|
(reduce-objects objects (complement frame-shape?) add-shape [])))
|
||||||
|
|
||||||
(defn get-root-shapes
|
(defn get-root-shapes
|
||||||
|
"Get all shapes that are not frames"
|
||||||
[objects]
|
[objects]
|
||||||
(let [add-shape
|
(let [add-shape
|
||||||
(fn [result shape]
|
(fn [result shape]
|
||||||
|
@ -688,11 +697,11 @@
|
||||||
|
|
||||||
(defn start-page-index
|
(defn start-page-index
|
||||||
[objects]
|
[objects]
|
||||||
(with-meta objects {::index-frames (get-frames objects)}))
|
(with-meta objects {::index-frames (get-frames (with-meta objects nil))}))
|
||||||
|
|
||||||
(defn update-page-index
|
(defn update-page-index
|
||||||
[objects]
|
[objects]
|
||||||
(with-meta objects {::index-frames (get-frames objects)}))
|
(with-meta objects {::index-frames (get-frames (with-meta objects nil))}))
|
||||||
|
|
||||||
(defn start-object-indices
|
(defn start-object-indices
|
||||||
[file]
|
[file]
|
||||||
|
|
|
@ -157,7 +157,7 @@
|
||||||
(->> (rx/from frame-updates)
|
(->> (rx/from frame-updates)
|
||||||
(rx/flat-map (fn [[page-id frames]]
|
(rx/flat-map (fn [[page-id frames]]
|
||||||
(->> frames (map #(vector page-id %)))))
|
(->> frames (map #(vector page-id %)))))
|
||||||
(rx/map (fn [[page-id frame-id]] (dwt/update-thumbnail page-id frame-id))))
|
(rx/map (fn [[page-id frame-id]] (dwt/update-thumbnail (:id file) page-id frame-id))))
|
||||||
(->> (rx/of lagged)
|
(->> (rx/of lagged)
|
||||||
(rx/mapcat seq)
|
(rx/mapcat seq)
|
||||||
(rx/map #(shapes-changes-persisted file-id %)))))))
|
(rx/map #(shapes-changes-persisted file-id %)))))))
|
||||||
|
|
|
@ -56,12 +56,15 @@
|
||||||
|
|
||||||
(defn update-thumbnail
|
(defn update-thumbnail
|
||||||
"Updates the thumbnail information for the given frame `id`"
|
"Updates the thumbnail information for the given frame `id`"
|
||||||
[page-id frame-id]
|
([page-id frame-id]
|
||||||
|
(update-thumbnail nil page-id frame-id))
|
||||||
|
|
||||||
|
([file-id page-id frame-id]
|
||||||
(ptk/reify ::update-thumbnail
|
(ptk/reify ::update-thumbnail
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state _]
|
(watch [_ state _]
|
||||||
(let [object-id (dm/str page-id frame-id)
|
(let [object-id (dm/str page-id frame-id)
|
||||||
file-id (:current-file-id state)
|
file-id (or file-id (:current-file-id state))
|
||||||
blob-result (thumbnail-stream object-id)]
|
blob-result (thumbnail-stream object-id)]
|
||||||
|
|
||||||
(->> blob-result
|
(->> blob-result
|
||||||
|
@ -73,13 +76,15 @@
|
||||||
|
|
||||||
(rx/merge-map
|
(rx/merge-map
|
||||||
(fn [data]
|
(fn [data]
|
||||||
(when (some? file-id)
|
(if (some? file-id)
|
||||||
(let [params {:file-id file-id :object-id object-id :data data}]
|
(let [params {:file-id file-id :object-id object-id :data data}]
|
||||||
(rx/merge
|
(rx/merge
|
||||||
;; Update the local copy of the thumbnails so we don't need to request it again
|
;; Update the local copy of the thumbnails so we don't need to request it again
|
||||||
(rx/of #(assoc-in % [:workspace-file :thumbnails object-id] data))
|
(rx/of #(assoc-in % [:workspace-file :thumbnails object-id] data))
|
||||||
(->> (rp/mutation! :upsert-file-object-thumbnail params)
|
(->> (rp/mutation! :upsert-file-object-thumbnail params)
|
||||||
(rx/ignore))))))))))))
|
(rx/ignore))))
|
||||||
|
|
||||||
|
(rx/empty))))))))))
|
||||||
|
|
||||||
(defn- extract-frame-changes
|
(defn- extract-frame-changes
|
||||||
"Process a changes set in a commit to extract the frames that are changing"
|
"Process a changes set in a commit to extract the frames that are changing"
|
||||||
|
|
|
@ -62,10 +62,10 @@
|
||||||
(defn- calculate-dimensions
|
(defn- calculate-dimensions
|
||||||
[objects]
|
[objects]
|
||||||
(let [rect
|
(let [rect
|
||||||
(->> (cph/get-immediate-children objects)
|
(->> (cph/get-root-objects objects)
|
||||||
(map #(if (some? (:children-bounds %))
|
(map #(if (some? (:children-bounds %))
|
||||||
(:children-bounds %)
|
(:children-bounds %)
|
||||||
(:selrect %)))
|
(gsh/points->selrect (:points %))))
|
||||||
(gsh/join-selrects))]
|
(gsh/join-selrects))]
|
||||||
(-> rect
|
(-> rect
|
||||||
(update :x mth/finite 0)
|
(update :x mth/finite 0)
|
||||||
|
@ -82,9 +82,10 @@
|
||||||
(mf/fnc frame-wrapper
|
(mf/fnc frame-wrapper
|
||||||
[{:keys [shape] :as props}]
|
[{:keys [shape] :as props}]
|
||||||
|
|
||||||
(let [childs (mapv #(get objects %) (:shapes shape))
|
(let [render-thumbnails? (mf/use-ctx muc/render-thumbnails)
|
||||||
|
childs (mapv #(get objects %) (:shapes shape))
|
||||||
shape (gsh/transform-shape shape)]
|
shape (gsh/transform-shape shape)]
|
||||||
(if (some? (:thumbnail shape))
|
(if (and render-thumbnails? (some? (:thumbnail shape)))
|
||||||
[:& frame/frame-thumbnail {:shape shape :bounds (:children-bounds shape)}]
|
[:& frame/frame-thumbnail {:shape shape :bounds (:children-bounds shape)}]
|
||||||
[:& frame-shape {:shape shape :childs childs}])))))
|
[:& frame-shape {:shape shape :childs childs}])))))
|
||||||
|
|
||||||
|
@ -221,16 +222,12 @@
|
||||||
vbox (format-viewbox dim)
|
vbox (format-viewbox dim)
|
||||||
bgcolor (dm/get-in data [:options :background] default-color)
|
bgcolor (dm/get-in data [:options :background] default-color)
|
||||||
|
|
||||||
frame-wrapper
|
|
||||||
(mf/use-memo
|
|
||||||
(mf/deps objects)
|
|
||||||
#(frame-wrapper-factory objects))
|
|
||||||
|
|
||||||
shape-wrapper
|
shape-wrapper
|
||||||
(mf/use-memo
|
(mf/use-memo
|
||||||
(mf/deps objects)
|
(mf/deps objects)
|
||||||
#(shape-wrapper-factory objects))]
|
#(shape-wrapper-factory objects))]
|
||||||
|
|
||||||
|
[:& (mf/provider muc/render-thumbnails) {:value thumbnails?}
|
||||||
[:& (mf/provider embed/context) {:value render-embed?}
|
[:& (mf/provider embed/context) {:value render-embed?}
|
||||||
[:& (mf/provider export/include-metadata-ctx) {:value include-metadata?}
|
[:& (mf/provider export/include-metadata-ctx) {:value include-metadata?}
|
||||||
[:svg {:view-box vbox
|
[:svg {:view-box vbox
|
||||||
|
@ -254,19 +251,8 @@
|
||||||
[:& ff/fontfaces-style {:fonts fonts}])
|
[:& ff/fontfaces-style {:fonts fonts}])
|
||||||
|
|
||||||
(for [item shapes]
|
(for [item shapes]
|
||||||
(let [frame? (= (:type item) :frame)]
|
|
||||||
(cond
|
|
||||||
(and frame? thumbnails? (some? (:thumbnail item)))
|
|
||||||
[:> shape-container {:shape item}
|
|
||||||
[:& frame/frame-thumbnail {:shape item :bounds (:children-bounds item)}]]
|
|
||||||
|
|
||||||
frame?
|
|
||||||
[:> shape-container {:shape item}
|
|
||||||
[:& frame-wrapper {:shape item
|
|
||||||
:key (:id item)}]]
|
|
||||||
:else
|
|
||||||
[:& shape-wrapper {:shape item
|
[:& shape-wrapper {:shape item
|
||||||
:key (:id item)}])))]]]))
|
:key (:id item)}])]]]]))
|
||||||
|
|
||||||
|
|
||||||
;; Component that serves for render frame thumbnails, mainly used in
|
;; Component that serves for render frame thumbnails, mainly used in
|
||||||
|
@ -278,7 +264,7 @@
|
||||||
(let [frame-id (:id frame)
|
(let [frame-id (:id frame)
|
||||||
include-metadata? (mf/use-ctx export/include-metadata-ctx)
|
include-metadata? (mf/use-ctx export/include-metadata-ctx)
|
||||||
|
|
||||||
bounds (or (:children-bounds frame) (:selrect frame))
|
bounds (or (:children-bounds frame) (gsh/points->rect (:points frame)))
|
||||||
|
|
||||||
modifier
|
modifier
|
||||||
(mf/with-memo [(:x bounds) (:y bounds)]
|
(mf/with-memo [(:x bounds) (:y bounds)]
|
||||||
|
|
|
@ -23,3 +23,4 @@
|
||||||
(def current-file-id (mf/create-context nil))
|
(def current-file-id (mf/create-context nil))
|
||||||
(def scroll-ctx (mf/create-context nil))
|
(def scroll-ctx (mf/create-context nil))
|
||||||
(def active-frames-ctx (mf/create-context nil))
|
(def active-frames-ctx (mf/create-context nil))
|
||||||
|
(def render-thumbnails (mf/create-context nil))
|
||||||
|
|
Loading…
Add table
Reference in a new issue