0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-23 23:18:48 -05:00

Merge branch 'main' into develop

This commit is contained in:
Andrey Antukh 2021-04-09 15:32:20 +02:00
commit 9a0f6018a7
9 changed files with 78 additions and 75 deletions

View file

@ -78,6 +78,12 @@
- Fix titles in viewer thumbnails too long [Taiga #1474](https://tree.taiga.io/project/penpot/issue/1474) - Fix titles in viewer thumbnails too long [Taiga #1474](https://tree.taiga.io/project/penpot/issue/1474)
- Fix when right click on a selected text shows artboard contextual menu [Taiga #1226](https://tree.taiga.io/project/penpot/issue/1226) - Fix when right click on a selected text shows artboard contextual menu [Taiga #1226](https://tree.taiga.io/project/penpot/issue/1226)
### :boom: Breaking changes
- The LDAP configuration variables interpolation starts using `:`
(example `:username`) instead of `$`. The main reason is avoid
unnecesary conflict with bash interpolation.
### :arrow_up: Deps updates ### :arrow_up: Deps updates

View file

@ -65,7 +65,7 @@
(defn ^boolean empty-path-element? (defn ^boolean empty-path-element?
[item] [item]
(and (= (get item "name") "path") (and (= (get item "name") "path")
(let [d (get item ["attributes" "d"])] (let [d (get-in item ["attributes" "d"])]
(or (str/blank? d) (or (str/blank? d)
(nil? d) (nil? d)
(str/empty? d))))) (str/empty? d)))))
@ -93,16 +93,7 @@
item)) item))
(process-element [item xform] (process-element [item xform]
(let [item (d/update-when item "elements" #(into [] xform %))] (d/update-when item "elements" #(into [] xform %)))]
(if (shape-element? item)
(update item "elements"
(fn [elements]
;; flatten content of a shape element
(into [] (mapcat (fn [item]
(if (group-element? item)
(get item "elements")
[item]))) elements)))
item)))]
(let [xform (comp (remove empty-defs-element?) (let [xform (comp (remove empty-defs-element?)
(remove empty-path-element?) (remove empty-path-element?)

View file

@ -105,6 +105,10 @@
%)))] %)))]
(attrs/get-attrs-multi nodes attrs))) (attrs/get-attrs-multi nodes attrs)))
(defn current-root-values
[{:keys [attrs shape]}]
(shape-current-values shape txt/is-root-node? attrs))
(defn current-paragraph-values (defn current-paragraph-values
[{:keys [editor-state attrs shape]}] [{:keys [editor-state attrs shape]}]
(if editor-state (if editor-state

View file

@ -234,17 +234,18 @@
:stroke-dasharray (/ select-guide-dasharray zoom)}}])]) :stroke-dasharray (/ select-guide-dasharray zoom)}}])])
(mf/defc measurement [{:keys [bounds frame selected-shapes hover-shape zoom]}] (mf/defc measurement [{:keys [bounds frame selected-shapes hover-shape zoom]}]
(let [selected-ids (into #{} (map :id) selected-shapes) (let [selected-ids (into #{} (map :id) selected-shapes)
selected-selrect (gsh/selection-rect selected-shapes) selected-selrect (gsh/selection-rect selected-shapes)
hover-selrect (:selrect hover-shape) hover-selrect (:selrect hover-shape)
bounds-selrect (bound->selrect bounds)] bounds-selrect (bound->selrect bounds)
hover-selected-shape? (not (contains? selected-ids (:id hover-shape)))]
(when (and (seq selected-shapes) (not (contains? selected-ids (:id hover-shape)))) (when (seq selected-shapes)
[:g.measurement-feedback {:pointer-events "none"} [:g.measurement-feedback {:pointer-events "none"}
[:& selection-guides {:selrect selected-selrect :bounds bounds :zoom zoom}] [:& selection-guides {:selrect selected-selrect :bounds bounds :zoom zoom}]
[:& size-display {:selrect selected-selrect :zoom zoom}] [:& size-display {:selrect selected-selrect :zoom zoom}]
(if (not hover-shape) (if (or (not hover-shape) (not hover-selected-shape?))
(when frame (when frame
[:g.hover-shapes [:g.hover-shapes
[:& distance-display {:from (:selrect frame) [:& distance-display {:from (:selrect frame)

View file

@ -31,6 +31,7 @@
") ")
;; -- Embed fonts into styles ;; -- Embed fonts into styles
(defn get-node-fonts (defn get-node-fonts
[node] [node]
(let [current-font (if (not (nil? (:font-id node))) (let [current-font (if (not (nil? (:font-id node)))
@ -39,35 +40,39 @@
children-font (map get-node-fonts (:children node))] children-font (map get-node-fonts (:children node))]
(reduce set/union (conj children-font current-font)))) (reduce set/union (conj children-font current-font))))
(defn get-local-font-css (defn get-font-css
[font-id font-variant-id] "Given a font and the variant-id, retrieves the style CSS for it."
(let [{:keys [family variants] :as font} (get @fonts/fontsdb font-id) [{:keys [id backend family variants] :as font} font-variant-id]
{:keys [name weight style suffix] :as variant} (d/seek #(= (:id %) font-variant-id) variants)] (if (= :google backend)
(-> (str/format font-face-template {:family family :suffix (or suffix font-variant-id) :width weight}) (-> (fonts/gfont-url family [{:id font-variant-id}])
(p/resolved)))) (js/fetch)
(p/then (fn [res] (.text res))))
(defn fetch-font-css (let [{:keys [name weight style suffix] :as variant} (d/seek #(= (:id %) font-variant-id) variants)
[font-id font-variant-id] result (str/fmt font-face-template {:family family
(let [{:keys [backend family] :as entry} (get @fonts/fontsdb font-id)] :style style
(if (= :google backend) :suffix (or suffix font-variant-id)
(-> (fonts/gfont-url family [{:id font-variant-id}]) :weight weight})]
(js/fetch) (p/resolved result))))
(p/then (fn [res] (.text res))))
(get-local-font-css font-id font-variant-id))))
(defn get-text-font-data [text] (defn get-font-data
(->> text "Parses the CSS and retrieves the font data as DataURI."
[^string css]
(->> css
(re-seq #"url\(([^)]+)\)") (re-seq #"url\(([^)]+)\)")
(map second) (map second)
(map df/fetch-as-data-uri) (map df/fetch-as-data-uri)
(p/all))) (p/all)))
(defn embed-font [{:keys [font-id font-variant-id] :or {font-variant-id "regular"}}] (defn embed-font
(let [{:keys [backend family]} (get @fonts/fontsdb font-id)] "Given a font-id and font-variant-id, retrieves the CSS for it and
(p/let [font-text (fetch-font-css font-id font-variant-id) convert all external urls to embedded data URI's."
url-to-data (get-text-font-data font-text) [{:keys [font-id font-variant-id] :or {font-variant-id "regular"}}]
(let [{:keys [backend family] :as font} (get @fonts/fontsdb font-id)]
(p/let [css (get-font-css font font-variant-id)
url-to-data (get-font-data css)
replace-text (fn [text [url data]] (str/replace text url data))] replace-text (fn [text [url data]] (str/replace text url data))]
(reduce replace-text font-text url-to-data)))) (reduce replace-text css url-to-data))))
(mf/defc embed-fontfaces-style (mf/defc embed-fontfaces-style
{::mf/wrap-props false} {::mf/wrap-props false}
@ -81,7 +86,9 @@
font-to-embed (if (empty? font-to-embed) #{txt/default-text-attrs} font-to-embed) font-to-embed (if (empty? font-to-embed) #{txt/default-text-attrs} font-to-embed)
embeded (map embed-font font-to-embed)] embeded (map embed-font font-to-embed)]
(-> (p/all embeded) (-> (p/all embeded)
(p/then (fn [result] (reset! style (str/join "\n" result)))))))) (p/then (fn [result]
(reset! style (str/join "\n" result))))))))
(when (some? @style) (when (some? @style)
[:style @style]))) [:style @style])))

View file

@ -67,8 +67,7 @@
(def shape-attrs (def shape-attrs
[:grow-type]) [:grow-type])
(def root-attrs (def root-attrs text-valign-attrs)
(d/concat text-valign-attrs text-align-attrs))
(def paragraph-attrs (def paragraph-attrs
(d/concat text-align-attrs (d/concat text-align-attrs

View file

@ -42,12 +42,11 @@
(:fill fill-values) (assoc :fill-color (:fill fill-values)) (:fill fill-values) (assoc :fill-color (:fill fill-values))
(:opacity fill-values) (assoc :fill-opacity (:fill fill-values))) (:opacity fill-values) (assoc :fill-opacity (:fill fill-values)))
text-values (merge text-values (d/merge
(select-keys shape [:grow-type :vertical-align :text-align]) (select-keys shape [:grow-type])
#_(dwt/current-root-values (dwt/current-root-values
{:editor-state editor-state {:shape shape
:shape shape :attrs root-attrs})
:attrs root-attrs})
(dwt/current-paragraph-values (dwt/current-paragraph-values
{:editor-state editor-state {:editor-state editor-state
:shape shape :shape shape

View file

@ -14,6 +14,7 @@
[app.main.refs :as refs] [app.main.refs :as refs]
[app.main.ui.context :as ctx] [app.main.ui.context :as ctx]
[app.main.ui.context :as muc] [app.main.ui.context :as muc]
[app.main.ui.measurements :as msr]
[app.main.ui.workspace.shapes :as shapes] [app.main.ui.workspace.shapes :as shapes]
[app.main.ui.workspace.shapes.text.editor :as editor] [app.main.ui.workspace.shapes.text.editor :as editor]
[app.main.ui.workspace.viewport.actions :as actions] [app.main.ui.workspace.viewport.actions :as actions]
@ -87,6 +88,11 @@
zoom (d/check-num zoom 1) zoom (d/check-num zoom 1)
drawing-tool (:tool drawing) drawing-tool (:tool drawing)
drawing-obj (:object drawing) drawing-obj (:object drawing)
selected-shapes (->> selected (mapv #(get objects %)))
selected-frames (into #{} (map :frame-id) selected-shapes)
;; Only when we have all the selected shapes in one frame
selected-frame (when (= (count selected-frames) 1) (get objects (first selected-frames)))
drawing-path? (or (and edition (= :draw (get-in edit-path [edition :edit-mode]))) drawing-path? (or (and edition (= :draw (get-in edit-path [edition :edit-mode])))
(and (some? drawing-obj) (= :path (:type drawing-obj)))) (and (some? drawing-obj) (= :path (:type drawing-obj))))
@ -213,10 +219,17 @@
{:selected selected {:selected selected
:zoom zoom :zoom zoom
:edition edition :edition edition
:show-distances (and (not transform) show-distances?)
:disable-handlers (or drawing-tool edition) :disable-handlers (or drawing-tool edition)
:on-move-selected on-move-selected}]) :on-move-selected on-move-selected}])
(when (and (not transform) show-distances?)
[:& msr/measurement
{:bounds vbox
:selected-shapes selected-shapes
:frame selected-frame
:hover-shape @hover
:zoom zoom}])
(when text-editing? (when text-editing?
[:& editor/text-shape-edit {:shape (get objects edition)}]) [:& editor/text-shape-edit {:shape (get objects edition)}])

View file

@ -22,7 +22,6 @@
[app.main.streams :as ms] [app.main.streams :as ms]
[app.main.ui.cursors :as cur] [app.main.ui.cursors :as cur]
[app.main.ui.hooks :as hooks] [app.main.ui.hooks :as hooks]
[app.main.ui.measurements :as msr]
[app.main.ui.workspace.viewport.outline :refer [outline]] [app.main.ui.workspace.viewport.outline :refer [outline]]
[app.main.ui.workspace.shapes.path.editor :refer [path-editor]] [app.main.ui.workspace.shapes.path.editor :refer [path-editor]]
[app.util.data :as d] [app.util.data :as d]
@ -295,7 +294,7 @@
:fill "transparent"}}]])) :fill "transparent"}}]]))
(mf/defc multiple-selection-handlers (mf/defc multiple-selection-handlers
[{:keys [shapes selected zoom color show-distances disable-handlers on-move-selected] :as props}] [{:keys [shapes selected zoom color disable-handlers on-move-selected] :as props}]
(let [shape (mf/use-memo (let [shape (mf/use-memo
(mf/deps shapes) (mf/deps shapes)
#(->> shapes #(->> shapes
@ -327,17 +326,11 @@
:on-resize on-resize :on-resize on-resize
:on-rotate on-rotate}] :on-rotate on-rotate}]
(when show-distances
[:& msr/measurement {:bounds vbox
:selected-shapes shapes
:hover-shape hover-shape
:zoom zoom}])
(when (debug? :selection-center) (when (debug? :selection-center)
[:circle {:cx (:x shape-center) :cy (:y shape-center) :r 5 :fill "yellow"}])])) [:circle {:cx (:x shape-center) :cy (:y shape-center) :r 5 :fill "yellow"}])]))
(mf/defc single-selection-handlers (mf/defc single-selection-handlers
[{:keys [shape zoom color show-distances disable-handlers on-move-selected] :as props}] [{:keys [shape zoom color disable-handlers on-move-selected] :as props}]
(let [shape-id (:id shape) (let [shape-id (:id shape)
shape (geom/transform-shape shape) shape (geom/transform-shape shape)
@ -357,25 +350,17 @@
on-rotate on-rotate
#(do (dom/stop-propagation %) #(do (dom/stop-propagation %)
(st/emit! (dw/start-rotate [shape])))] (st/emit! (dw/start-rotate [shape])))]
[:* [:& controls {:shape shape'
[:& controls {:shape shape' :zoom zoom
:zoom zoom :color color
:color color :on-rotate on-rotate
:on-rotate on-rotate :on-resize on-resize
:on-resize on-resize :disable-handlers disable-handlers
:disable-handlers disable-handlers :on-move-selected on-move-selected}]))
:on-move-selected on-move-selected}]
(when show-distances
[:& msr/measurement {:bounds vbox
:frame frame
:selected-shapes [shape]
:hover-shape hover-shape
:zoom zoom}])]))
(mf/defc selection-handlers (mf/defc selection-handlers
{::mf/wrap [mf/memo]} {::mf/wrap [mf/memo]}
[{:keys [selected edition zoom show-distances disable-handlers on-move-selected] :as props}] [{:keys [selected edition zoom disable-handlers on-move-selected] :as props}]
(let [;; We need remove posible nil values because on shape (let [;; We need remove posible nil values because on shape
;; deletion many shape will reamin selected and deleted ;; deletion many shape will reamin selected and deleted
;; in the same time for small instant of time ;; in the same time for small instant of time
@ -396,7 +381,6 @@
:selected selected :selected selected
:zoom zoom :zoom zoom
:color color :color color
:show-distances show-distances
:disable-handlers disable-handlers :disable-handlers disable-handlers
:on-move-selected on-move-selected}] :on-move-selected on-move-selected}]
@ -415,6 +399,5 @@
[:& single-selection-handlers {:shape shape [:& single-selection-handlers {:shape shape
:zoom zoom :zoom zoom
:color color :color color
:show-distances show-distances
:disable-handlers disable-handlers :disable-handlers disable-handlers
:on-move-selected on-move-selected}]))) :on-move-selected on-move-selected}])))