0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-25 16:25:56 -05:00

Merge pull request #3078 from penpot/alotor-bugfixing-10

Alotor bugfixing 10
This commit is contained in:
Alejandro 2023-03-29 09:32:18 +02:00 committed by GitHub
commit f03def32fd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 95 additions and 47 deletions

View file

@ -64,6 +64,10 @@
- Fix dashboard left sidebar, the [x] overlaps the field [Taiga #5064](https://tree.taiga.io/project/penpot/issue/5064)
- Fix expanded typography on assets sidebar is moving [Taiga #5063](https://tree.taiga.io/project/penpot/issue/5063)
- Fix spelling mistake in confirmation after importing only 1 file [Taiga #5095](https://tree.taiga.io/project/penpot/issue/5095)
- Fix problem with selection colors and texts [Taiga #5079](https://tree.taiga.io/project/penpot/issue/5079)
- Remove "show in view mode" flag when moving frame to frame [Taiga #5091](https://tree.taiga.io/project/penpot/issue/5091)
- Fix problem creating files in project page [Taiga #5060](https://tree.taiga.io/project/penpot/issue/5060)
- Disable empty names on rename files [Taiga #5088](https://tree.taiga.io/project/penpot/issue/5088)
### :heart: Community contributions by (Thank you!)
- To @ondrejkonec: for contributing to the code with:

View file

@ -595,3 +595,25 @@
(d/enumerate)
(sort comparator-layout-z-index)
(mapv second)))
(defn common-parent-frame
"Search for the common frame for the selected shapes. Otherwise returns the root frame"
[objects selected]
(loop [frame-id (get-in objects [(first selected) :frame-id])
frame-parents (get-parent-ids objects frame-id)
selected (rest selected)]
(if (empty? selected)
frame-id
(let [current (first selected)
parent? (into #{} (get-parent-ids objects current))
[frame-id frame-parents]
(if (parent? frame-id)
[frame-id frame-parents]
(let [frame-id (d/seek parent? frame-parents)]
[frame-id (get-parent-ids objects frame-id)]))]
(recur frame-id frame-parents (rest selected))))))

View file

@ -663,6 +663,9 @@
(cond-> (not (ctl/any-layout? objects parent-id))
(pcb/update-shapes ordered-indexes ctl/remove-layout-item-data))
;; Remove the hide in viewer flag
(pcb/update-shapes ordered-indexes #(cond-> % (cph/frame-shape? %) (assoc :hide-in-viewer true)))
;; Move the shapes
(pcb/change-parent parent-id
shapes
@ -1301,8 +1304,8 @@
;; Prepare the shape object. Mainly needed for image shapes
;; for retrieve the image data and convert it to the
;; data-url.
(prepare-object [objects selected+children {:keys [type] :as obj}]
(let [obj (maybe-translate obj objects selected+children)]
(prepare-object [objects parent-frame-id {:keys [type] :as obj}]
(let [obj (maybe-translate obj objects parent-frame-id)]
(if (= type :image)
(let [url (cf/resolve-file-media (:metadata obj))]
(->> (http/send! {:method :get
@ -1325,20 +1328,11 @@
(update res :images conj img-part))
res)))
(maybe-translate [shape objects selected+children]
(let [frame-id (:frame-id shape)
root-frame-id (cph/get-shape-id-root-frame objects (:id shape))]
(cond
(cph/root-frame? shape) shape
(contains? selected+children root-frame-id) shape
(cph/frame-shape? shape)
(let [frame (get objects root-frame-id)]
(gsh/translate-to-frame shape frame))
:else
(let [frame (get objects frame-id)]
(gsh/translate-to-frame shape frame)))))
(maybe-translate [shape objects parent-frame-id]
(if (= parent-frame-id uuid/zero)
shape
(let [frame (get objects parent-frame-id)]
(gsh/translate-to-frame shape frame))))
(on-copy-error [error]
(js/console.error "Clipboard blocked:" error)
@ -1351,7 +1345,7 @@
selected (->> (wsh/lookup-selected state)
(cph/clean-loops objects))
selected+children (cph/selected-with-children objects selected)
parent-frame-id (cph/common-parent-frame objects selected)
pdata (reduce (partial collect-object-ids objects) {} selected)
initial {:type :copied-shapes
:file-id (:current-file-id state)
@ -1366,7 +1360,7 @@
(catch :default e
(on-copy-error e)))
(->> (rx/from (seq (vals pdata)))
(rx/merge-map (partial prepare-object objects selected+children))
(rx/merge-map (partial prepare-object objects parent-frame-id))
(rx/reduce collect-data initial)
(rx/map (partial sort-selected state))
(rx/map t/encode-str)

View file

@ -137,6 +137,7 @@
(pcb/with-objects objects)
(cond-> (not (ctl/any-layout? objects frame-id))
(pcb/update-shapes ordered-indexes ctl/remove-layout-item-data))
(pcb/update-shapes ordered-indexes #(cond-> % (cph/frame-shape? %) (assoc :hide-in-viewer true)))
(pcb/change-parent frame-id to-move-shapes 0)
(cond-> (ctl/grid-layout? objects frame-id)
(pcb/update-shapes [frame-id] ctl/assign-cells))))]

View file

@ -104,7 +104,7 @@
(defn start-resize
"Enter mouse resize mode, until mouse button is released."
[handler ids shape]
(letfn [(resize
(letfn [(resize
[shape initial layout [point lock? center? point-snap]]
(let [{:keys [width height]} (:selrect shape)
{:keys [rotation]} shape
@ -745,13 +745,16 @@
(remove (fn [shape]
(and (ctl/layout-absolute? shape)
(= frame-id (:parent-id shape))))))
moving-shapes-ids
(map :id moving-shapes)
changes
(-> (pcb/empty-changes it page-id)
(pcb/with-objects objects)
;; Remove layout-item properties when moving a shape outside a layout
(cond-> (not (ctl/any-layout? objects frame-id))
(pcb/update-shapes (map :id moving-shapes) ctl/remove-layout-item-data))
(pcb/update-shapes moving-shapes-ids ctl/remove-layout-item-data))
(pcb/update-shapes moving-shapes-ids #(cond-> % (cph/frame-shape? %) (assoc :hide-in-viewer true)))
(pcb/change-parent frame-id moving-shapes drop-index)
(pcb/remove-objects empty-parents))]

View file

@ -144,6 +144,7 @@
create-file
(mf/use-fn
(mf/deps project)
(fn [origin]
(st/emit! (with-meta (dd/create-file {:project-id (:id project)})
{::ev/origin origin}))))]

View file

@ -268,7 +268,9 @@
(mf/use-fn
(mf/deps file)
(fn [name]
(st/emit! (dd/rename-file (assoc file :name name)))
(let [name (str/trim name)]
(when (not= name "")
(st/emit! (dd/rename-file (assoc file :name name)))))
(swap! local assoc :edition false)))
on-edit

View file

@ -22,6 +22,7 @@
[app.util.keyboard :as kbd]
[app.util.webapi :as wapi]
[beicon.core :as rx]
[cuerdas.core :as str]
[potok.core :as ptk]
[rumext.v2 :as mf]))
@ -61,9 +62,11 @@
(->> files
(mapv
(fn [file]
(cond-> file
(= (:file-id file) file-id)
(assoc :name new-name))))))
(let [new-name (str/trim new-name)]
(cond-> file
(and (= (:file-id file) file-id)
(not= "" new-name))
(assoc :name new-name)))))))
(defn remove-file [files file-id]
(->> files

View file

@ -33,6 +33,7 @@
[app.util.keyboard :as kbd]
[app.util.router :as rt]
[beicon.core :as rx]
[cuerdas.core :as str]
[okulary.core :as l]
[potok.core :as ptk]
[rumext.v2 :as mf]))
@ -150,10 +151,12 @@
:on-accept #(st/emit! (dwl/set-file-shared (:id file) false))
:count-libraries 1}))))
handle-blur (fn [_]
(let [value (-> edit-input-ref mf/ref-val dom/get-value)]
(st/emit! (dw/rename-file (:id file) value)))
(reset! editing? false))
handle-blur
(fn [_]
(let [value (str/trim (-> edit-input-ref mf/ref-val dom/get-value))]
(when (not= value "")
(st/emit! (dw/rename-file (:id file) value))))
(reset! editing? false))
handle-name-keydown (fn [event]
(when (kbd/enter? event)

View file

@ -161,27 +161,37 @@
on-change
(mf/use-fn
(fn [new-color old-color]
(fn [new-color old-color from-picker?]
(let [old-color (-> old-color
(dissoc :name)
(dissoc :path)
(d/without-nils))
prev-color (-> @prev-color*
(dissoc :name)
(dissoc :path)
(d/without-nils))
prev-color (when @prev-color*
(-> @prev-color*
(dissoc :name)
(dissoc :path)
(d/without-nils)))
;; When dragging on the color picker sometimes all the shapes hasn't updated the color to the prev value so we need this extra calculation
shapes-by-old-color (get @grouped-colors* old-color)
shapes-by-prev-color (get @grouped-colors* prev-color)
shapes-by-color (or shapes-by-prev-color shapes-by-old-color)]
(reset! prev-color* new-color)
(st/emit! (dc/change-color-in-selected new-color shapes-by-color old-color)))))
on-open (mf/use-fn
(fn [color]
(reset! prev-color* color)))
(when from-picker?
(reset! prev-color* new-color))
(st/emit! (dc/change-color-in-selected new-color shapes-by-color (or prev-color old-color))))))
on-open
(mf/use-fn
(fn []
(reset! prev-color* nil)))
on-close
(mf/use-fn
(fn []
(reset! prev-color* nil)))
on-detach
(mf/use-fn
@ -212,8 +222,9 @@
:index index
:on-detach on-detach
:select-only select-only
:on-change #(on-change % color)
:on-open on-open}])
:on-change #(on-change %1 color %2)
:on-open on-open
:on-close on-close}])
(when (and (false? @expand-lib-color) (< 3 (count library-colors)))
[:div.expand-colors {:on-click #(reset! expand-lib-color true)}
[:span i/actions]
@ -225,8 +236,9 @@
:index index
:on-detach on-detach
:select-only select-only
:on-change #(on-change % color)
:on-open on-open}]))]
:on-change #(on-change %1 color %2)
:on-open on-open
:on-close on-close}]))]
[:div.selected-colors
(for [[index color] (d/enumerate (take 3 colors))]
@ -234,8 +246,9 @@
:color color
:index index
:select-only select-only
:on-change #(on-change % color)
:on-open on-open}])
:on-change #(on-change %1 color %2)
:on-open on-open
:on-close on-close}])
(when (and (false? @expand-color) (< 3 (count colors)))
[:div.expand-colors {:on-click #(reset! expand-color true)}
[:span i/actions]
@ -246,5 +259,6 @@
:color color
:index index
:select-only select-only
:on-change #(on-change % color)
:on-open on-open}]))]]])))
:on-change #(on-change %1 color %2)
:on-open on-open
:on-close on-close}]))]]])))

View file

@ -113,7 +113,8 @@
:y y
:disable-gradient disable-gradient
:disable-opacity disable-opacity
:on-change #(on-change (merge uc/empty-color %))
;; on-change second parameter means if the source is the color-picker
:on-change #(on-change (merge uc/empty-color %) true)
:on-close (fn [value opacity id file-id]
(when on-close
(on-close value opacity id file-id)))