0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-10 09:08:31 -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)))))) (.error js/console "ERROR" e))))))
(defn as-content [text] (defn as-content [text]
(let [paragraphs (->> (str/split text "\n") (let [paragraphs (->> (str/lines text)
(map str/trim) (map str/trim)
(mapv #(hash-map :type "paragraph" (mapv #(hash-map :type "paragraph"
:children [{:text %}])))] :children [{:text %}])))]

View file

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

View file

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

View file

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