0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-10 00:58:26 -05:00

Review fixes

This commit is contained in:
alonso.torres 2020-09-22 18:06:47 +02:00 committed by Andrey Antukh
parent cd151db5ee
commit 494cd1e96c
5 changed files with 33 additions and 36 deletions

View file

@ -1275,7 +1275,7 @@
(.error js/console "ERROR" e))))))
(defn as-content [text]
(let [paragraphs (->> (str/split text "\n")
(let [paragraphs (->> (str/lines text)
(map str/trim)
(mapv #(hash-map :type "paragraph"
:children [{:text %}])))]

View file

@ -297,13 +297,14 @@
(accumulate-undo-entry state entry)
(add-undo-entry state entry)))))
(defonce empty-tx {:undo-changes [] :redo-changes []})
(def start-undo-transaction
(ptk/reify ::start-undo-transaction
ptk/UpdateEvent
(update [_ state]
;; We commit the old transaction before starting the new one
(let [empty-tx {:undo-changes [] :redo-changes []}
current-tx (get-in state [:workspace-undo :transaction])]
(let [current-tx (get-in state [:workspace-undo :transaction])]
(cond-> state
(nil? current-tx) (assoc-in [:workspace-undo :transaction] empty-tx))))))

View file

@ -199,8 +199,7 @@
(ptk/reify ::start-edit-if-selected
ptk/UpdateEvent
(update [_ state]
(let [page-id (:current-page-id state)
objects (get-in state [:workspace-data :pages-index page-id :objects])
(let [objects (dwc/lookup-page-objects state)
selected (->> state :workspace-local :selected (map #(get objects %)))]
(cond-> state
(and (= 1 (count selected))

View file

@ -18,7 +18,8 @@
[app.util.dom :as dom]
[app.util.timers :as ts]
[app.common.data :as d]
[clojure.set :as set]))
[clojure.set :as set]
[app.util.object :as obj]))
(def google-fonts
(preload-gfonts "fonts/gfonts.2020.04.23.json"))
@ -152,4 +153,6 @@
(load-font (assoc font ::on-loaded on-loaded))
(swap! loaded conj id)))))
(defn ready [cb]
(-> (obj/get-in js/document ["fonts" "ready"])
(p/then cb)))

View file

@ -121,7 +121,7 @@
lh (obj/set! "lineHeight" lh))))
(defn- generate-text-styles
[data on-load-font]
[data]
(let [letter-spacing (obj/get data "letter-spacing")
text-decoration (obj/get data "text-decoration")
text-transform (obj/get data "text-transform")
@ -153,7 +153,6 @@
(when (and (string? font-id)
(pos? (alength font-id)))
(let [font (get fontsdb font-id)]
(fonts/ensure-loaded! font-id on-load-font)
(let [font-family (or (:family font)
(obj/get data "fontFamily"))
font-variant (d/seek #(= font-variant-id (:id %))
@ -215,8 +214,7 @@
(let [attrs (obj/get props "attributes")
childs (obj/get props "children")
data (obj/get props "leaf")
on-load-font (obj/get props "on-load-font")
style (generate-text-styles data on-load-font)
style (generate-text-styles data)
attrs (obj/set! attrs "style" style)]
[:> :span attrs childs]))
@ -232,10 +230,9 @@
nil))))
(defn- render-text
[on-load-font]
(fn [props]
(mf/html
[:> editor-text-node (obj/merge! props #js {:on-load-font on-load-font})])))
[props]
(mf/html
[:> editor-text-node props]))
;; --- Text Shape Edit
@ -337,10 +334,7 @@
content (first content)]
(st/emit! (dw/update-shape id {:content content}))
(reset! state val)
(reset! content-var content)))))
loaded-fonts (mf/use-var 0)
on-load-font #(swap! loaded-fonts inc)]
(reset! content-var content)))))]
(mf/use-effect on-mount)
@ -352,10 +346,10 @@
;; Checks the size of the wrapper to update if it were necesary
(mf/use-effect
(mf/deps shape @loaded-fonts)
(mf/deps shape)
(fn []
(timers/schedule
250 ;; We need to wait to the text to be rendered. Is there a better alternative?
(fonts/ready
#(let [self-node (mf/ref-val self-ref)
paragraph-node (when self-node (dom/query self-node ".paragraph-set"))]
(when paragraph-node
@ -367,23 +361,23 @@
(when (not undo-transaction) (st/emit! dwc/start-undo-transaction))
(when (or (not= (:width shape) width)
(not= (:height shape) height))
(cond
(and (:overflow-text shape) (not= :fixed (:grow-type shape)))
(st/emit! (dwt/update-overflow-text id false))
(cond
(and (:overflow-text shape) (not= :fixed (:grow-type shape)))
(st/emit! (dwt/update-overflow-text id false))
(and (= :fixed (:grow-type shape)) (not (:overflow-text shape)) (> height (:height shape)))
(st/emit! (dwt/update-overflow-text id true))
(and (= :fixed (:grow-type shape)) (not (:overflow-text shape)) (> height (:height shape)))
(st/emit! (dwt/update-overflow-text id true))
(and (= :fixed (:grow-type shape)) (:overflow-text shape) (<= height (:height shape)))
(st/emit! (dwt/update-overflow-text id false))
(and (= :fixed (:grow-type shape)) (:overflow-text shape) (<= height (:height shape)))
(st/emit! (dwt/update-overflow-text id false))
(= grow-type :auto-width)
(st/emit! (dw/update-dimensions [id] :width width)
(dw/update-dimensions [id] :height height))
(= grow-type :auto-width)
(st/emit! (dw/update-dimensions [id] :width width)
(dw/update-dimensions [id] :height height))
(= grow-type :auto-height)
(st/emit! (dw/update-dimensions [id] :height height))
))
(= grow-type :auto-height)
(st/emit! (dw/update-dimensions [id] :height height))
))
(when (not undo-transaction) (st/emit! dwc/discard-undo-transaction))))))))
[:foreignObject {:ref self-ref
@ -403,7 +397,7 @@
:style {:cursor cur/text
:width (:width shape)}
:render-element #(render-element shape %)
:render-leaf (render-text on-load-font)
:render-leaf render-text
:on-mouse-up on-mouse-up
:on-mouse-down on-mouse-down
:on-blur (fn [event]