0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-03-15 17:21:17 -05:00

Merge remote-tracking branch 'origin/main' into develop

This commit is contained in:
alonso.torres 2022-05-31 11:15:10 +02:00
commit 23d3e88214
15 changed files with 126 additions and 65 deletions

View file

@ -18,6 +18,14 @@
### :arrow_up: Deps updates
### :heart: Community contributions by (Thank you!)
## 1.13.2-beta
### :bug: Bugs fixed
- Improved performance when out of focus mode
- Improved performance for thumbnail generation
- Fix problem with out of sync thumbnails
## 1.13.1-beta
### :bug: Bugs fixed

View file

@ -119,7 +119,7 @@
(get-email info))]
{:backend (:name provider)
:email email
:fullname (get-name info)
:fullname (or (get-name info) email)
:props (->> (dissoc info :name :email)
(qualify-props provider))}))

View file

@ -400,7 +400,7 @@
(defn- create-team-invitation
[{:keys [conn tokens team profile role email] :as cfg}]
(let [member (profile/retrieve-profile-data-by-email conn email)
token-exp (dt/in-future "48h")
token-exp (dt/in-future "168h") ;; 7 days
itoken (tokens :generate
{:iss :team-invitation
:exp token-exp

View file

@ -28,3 +28,11 @@
[shape]
(gpr/points->selrect (position-data-points shape)))
(defn overlaps-position-data?
"Checks if the given position data is inside the shape"
[{:keys [points]} position-data]
(let [bounding-box (gpr/points->selrect points)
fix-rect #(assoc % :y (- (:y %) (:height %)))]
(->> position-data
(some #(gpr/overlaps-rects? bounding-box (fix-rect %)))
(boolean))))

View file

@ -9,7 +9,7 @@
[app.common.colors :as clr]
[app.common.uuid :as uuid]))
(def file-version 18)
(def file-version 19)
(def default-color clr/gray-20)
(def root uuid/zero)

View file

@ -10,6 +10,7 @@
[app.common.geom.matrix :as gmt]
[app.common.geom.shapes :as gsh]
[app.common.geom.shapes.path :as gsp]
[app.common.geom.shapes.text :as gsht]
[app.common.logging :as l]
[app.common.math :as mth]
[app.common.pages :as cp]
@ -415,5 +416,21 @@
(update :pages-index d/update-vals update-container)
(update :components d/update-vals update-container))))
(defmethod migrate 19
[data]
(letfn [(update-object [object]
(cond-> object
(and (cph/text-shape? object)
(d/not-empty? (:position-data object))
(not (gsht/overlaps-position-data? object (:position-data object))))
(dissoc :position-data)))
(update-container [container]
(update container :objects d/update-vals update-object))]
(-> data
(update :pages-index d/update-vals update-container)
(update :components d/update-vals update-container))))
;; TODO: pending to do a migration for delete already not used fill
;; and stroke props. This should be done for >1.14.x version.

View file

@ -28,6 +28,7 @@ RUN set -ex; \
libasound2 \
libatk1.0-0 \
libatk-bridge2.0-0 \
libatomic1 \
libcairo2 \
libcups2 \
libdbus-1-3 \

View file

@ -79,7 +79,8 @@
(dissoc :dashboard-shared-files)
(dissoc :dashboard-recent-files)
(dissoc :dashboard-team-members)
(dissoc :dashboard-team-stats)))))
(dissoc :dashboard-team-stats)
(update :workspace-global dissoc :default-font)))))
ptk/WatchEvent
(watch [_ state stream]

View file

@ -150,7 +150,11 @@
:workspace-undo {}
:workspace-project project
:workspace-file (assoc file :initialized true)
:workspace-data (:data file)
:workspace-data (-> (:data file)
;; DEBUG: Uncomment this to try out migrations in local without changing
;; the version number
#_(assoc :version 17)
#_(app.common.pages.migrations/migrate-data 19))
:workspace-libraries (d/index-by :id libraries)))
ptk/WatchEvent

View file

@ -56,49 +56,53 @@
attrs))
(defn add-fill
([attrs shape render-id]
(add-fill attrs shape render-id nil))
([attrs fill-data render-id type]
(add-fill attrs fill-data render-id nil type))
([attrs shape render-id index]
([attrs fill-data render-id index type]
(let [fill-attrs
(cond
(contains? shape :fill-image)
(contains? fill-data :fill-image)
(let [fill-image-id (str "fill-image-" render-id)]
{:fill (str "url(#" fill-image-id ")")})
(and (contains? shape :fill-color-gradient) (some? (:fill-color-gradient shape)))
(and (contains? fill-data :fill-color-gradient) (some? (:fill-color-gradient fill-data)))
(let [fill-color-gradient-id (str "fill-color-gradient_" render-id (if index (str "_" index) ""))]
{:fill (str "url(#" fill-color-gradient-id ")")})
(contains? shape :fill-color)
{:fill (:fill-color shape)}
(contains? fill-data :fill-color)
{:fill (:fill-color fill-data)}
:else
{:fill "none"})
fill-attrs (cond-> fill-attrs
(contains? shape :fill-opacity)
(assoc :fillOpacity (:fill-opacity shape)))]
(contains? fill-data :fill-opacity)
(assoc :fillOpacity (:fill-opacity fill-data))
;; Old texts with only an opacity set are black by default
(and (= type :text) (nil? (:fill-color-gradient fill-data)) (nil? (:fill-color fill-data)))
(assoc :fill "black"))]
(obj/merge! attrs (clj->js fill-attrs)))))
(defn add-stroke [attrs shape render-id index]
(let [stroke-style (:stroke-style shape :none)
(defn add-stroke [attrs stroke-data render-id index]
(let [stroke-style (:stroke-style stroke-data :none)
stroke-color-gradient-id (str "stroke-color-gradient_" render-id "_" index)
stroke-width (:stroke-width shape 1)]
stroke-width (:stroke-width stroke-data 1)]
(if (not= stroke-style :none)
(let [stroke-attrs
(cond-> {:strokeWidth stroke-width}
(:stroke-color-gradient shape)
(:stroke-color-gradient stroke-data)
(assoc :stroke (str/format "url(#%s)" stroke-color-gradient-id))
(and (not (:stroke-color-gradient shape))
(:stroke-color shape nil))
(assoc :stroke (:stroke-color shape nil))
(and (not (:stroke-color-gradient stroke-data))
(:stroke-color stroke-data nil))
(assoc :stroke (:stroke-color stroke-data nil))
(and (not (:stroke-color-gradient shape))
(:stroke-opacity shape nil))
(assoc :strokeOpacity (:stroke-opacity shape nil))
(and (not (:stroke-color-gradient stroke-data))
(:stroke-opacity stroke-data nil))
(assoc :strokeOpacity (:stroke-opacity stroke-data nil))
(not= stroke-style :svg)
(assoc :strokeDasharray (stroke-type->dasharray stroke-width stroke-style))
@ -106,29 +110,29 @@
;; For simple line caps we use svg stroke-line-cap attribute. This
;; only works if all caps are the same and we are not using the tricks
;; for inner or outer strokes.
(and (stroke-caps-line (:stroke-cap-start shape))
(= (:stroke-cap-start shape) (:stroke-cap-end shape))
(not (#{:inner :outer} (:stroke-alignment shape)))
(and (stroke-caps-line (:stroke-cap-start stroke-data))
(= (:stroke-cap-start stroke-data) (:stroke-cap-end stroke-data))
(not (#{:inner :outer} (:stroke-alignment stroke-data)))
(not= :dotted stroke-style))
(assoc :strokeLinecap (:stroke-cap-start shape))
(assoc :strokeLinecap (:stroke-cap-start stroke-data))
(= :dotted stroke-style)
(assoc :strokeLinecap "round")
;; For other cap types we use markers.
(and (or (stroke-caps-marker (:stroke-cap-start shape))
(and (stroke-caps-line (:stroke-cap-start shape))
(not= (:stroke-cap-start shape) (:stroke-cap-end shape))))
(not (#{:inner :outer} (:stroke-alignment shape))))
(and (or (stroke-caps-marker (:stroke-cap-start stroke-data))
(and (stroke-caps-line (:stroke-cap-start stroke-data))
(not= (:stroke-cap-start stroke-data) (:stroke-cap-end stroke-data))))
(not (#{:inner :outer} (:stroke-alignment stroke-data))))
(assoc :markerStart
(str/format "url(#marker-%s-%s)" render-id (name (:stroke-cap-start shape))))
(str/format "url(#marker-%s-%s)" render-id (name (:stroke-cap-start stroke-data))))
(and (or (stroke-caps-marker (:stroke-cap-end shape))
(and (stroke-caps-line (:stroke-cap-end shape))
(not= (:stroke-cap-start shape) (:stroke-cap-end shape))))
(not (#{:inner :outer} (:stroke-alignment shape))))
(and (or (stroke-caps-marker (:stroke-cap-end stroke-data))
(and (stroke-caps-line (:stroke-cap-end stroke-data))
(not= (:stroke-cap-start stroke-data) (:stroke-cap-end stroke-data))))
(not (#{:inner :outer} (:stroke-alignment stroke-data))))
(assoc :markerEnd
(str/format "url(#marker-%s-%s)" render-id (name (:stroke-cap-end shape)))))]
(str/format "url(#marker-%s-%s)" render-id (name (:stroke-cap-end stroke-data)))))]
(obj/merge! attrs (clj->js stroke-attrs)))
attrs)))
@ -195,7 +199,7 @@
(obj/set! "fill" (or (obj/get (:wrapper-styles shape) "fill") clr/black)))
(d/not-empty? (:fills shape))
(add-fill styles (d/without-nils (get-in shape [:fills 0])) render-id 0)
(add-fill styles (d/without-nils (get-in shape [:fills 0])) render-id 0 (:type shape))
:else
styles)]
@ -211,16 +215,16 @@
(add-style-attrs shape)))
(defn extract-fill-attrs
[shape render-id index]
(let [fill-styles (-> (obj/get shape "style" (obj/new))
(add-fill shape render-id index))]
[fill-data render-id index type]
(let [fill-styles (-> (obj/get fill-data "style" (obj/new))
(add-fill fill-data render-id index type))]
(-> (obj/new)
(obj/set! "style" fill-styles))))
(defn extract-stroke-attrs
[shape index render-id]
(let [stroke-styles (-> (obj/get shape "style" (obj/new))
(add-stroke shape render-id index))]
[stroke-data index render-id]
(let [stroke-styles (-> (obj/get stroke-data "style" (obj/new))
(add-stroke stroke-data render-id index))]
(-> (obj/new)
(obj/set! "style" stroke-styles))))

View file

@ -375,7 +375,7 @@
(d/not-empty? (:fills shape))
(let [fill-props
(attrs/extract-fill-attrs (get-in shape [:fills 0]) render-id 0)
(attrs/extract-fill-attrs (get-in shape [:fills 0]) render-id 0 (:type shape))
style (-> (obj/get props "style")
(obj/clone)

View file

@ -53,7 +53,8 @@
:width width
:data-loading loading?}
(= :path (:type shape))
(obj/set! "patternTransform" transform))]
(obj/set! "patternTransform" transform))
type (:type shape)]
(for [[shape-index shape] (d/enumerate (or (:position-data shape) [shape]))]
[:* {:key (dm/str shape-index)}
@ -73,7 +74,7 @@
(obj/set! "id" fill-id))
[:g
(for [[fill-index value] (-> (d/enumerate (:fills shape [])) reverse)]
[:> :rect (-> (attrs/extract-fill-attrs value render-id fill-index)
[:> :rect (-> (attrs/extract-fill-attrs value render-id fill-index type)
(obj/set! "key" (dm/str fill-index))
(obj/set! "width" width)
(obj/set! "height" height))])

View file

@ -84,7 +84,7 @@
disable-thumbnail? (d/not-empty? (dm/get-in modifiers [(:id shape) :modifiers]))
[on-load-frame-dom render-frame? thumbnail-renderer]
(ftr/use-render-thumbnail page-id shape node-ref rendered? disable-thumbnail?)
(ftr/use-render-thumbnail page-id shape node-ref rendered? disable-thumbnail? @force-render)
on-frame-load
(fns/use-node-store thumbnail? node-ref rendered? render-frame?)]
@ -129,5 +129,5 @@
[:g.frame-thumbnail-wrapper
{:id (dm/str "thumbnail-container-" (:id shape))
;; Hide the thumbnail when not displaying
:opacity (when (and @rendered? (not thumbnail?)) 0)}
:opacity (when (and @rendered? (not thumbnail?) (not render-frame?)) 0)}
thumbnail-renderer]]]))))

View file

@ -53,7 +53,7 @@
(defn use-render-thumbnail
"Hook that will create the thumbnail thata"
[page-id {:keys [id x y width height] :as shape} node-ref rendered? disable?]
[page-id {:keys [id x y width height] :as shape} node-ref rendered? disable? force-render]
(let [frame-canvas-ref (mf/use-ref nil)
frame-image-ref (mf/use-ref nil)
@ -85,12 +85,13 @@
img-node (mf/ref-val frame-image-ref)]
(when (draw-thumbnail-canvas! canvas-node img-node)
(reset! image-url nil)
(reset! render-frame? false))
;; If we don't have the thumbnail data saved (normaly the first load) we update the data
;; when available
(when (not @thumbnail-data-ref)
(st/emit! (dwt/update-thumbnail page-id id) ))))))
;; If we don't have the thumbnail data saved (normaly the first load) we update the data
;; when available
(when (not @thumbnail-data-ref)
(st/emit! (dwt/update-thumbnail page-id id) ))
(reset! render-frame? false))))))
generate-thumbnail
(mf/use-callback
@ -140,6 +141,18 @@
(.observe observer node #js {:childList true :attributes true :attributeOldValue true :characterData true :subtree true})
(reset! observer-ref observer)))))]
(mf/use-effect
(mf/deps @render-frame? thumbnail-data)
(fn []
(when (and (some? thumbnail-data) @render-frame?)
(reset! render-frame? false))))
(mf/use-effect
(mf/deps force-render)
(fn []
(when force-render
(rx/push! updates-str :update))))
(mf/use-effect
(fn []
(let [subid (->> updates-str
@ -190,7 +203,9 @@
:width fixed-width
:height fixed-height
;; DEBUG
:style {:filter (when (debug? :thumbnails) "invert(1)")}}]]
:style {:filter (when (debug? :thumbnails) "invert(1)")
:width "100%"
:height "100%"}}]]
(when (some? @image-url)
[:image {:ref frame-image-ref

View file

@ -9,6 +9,7 @@
[app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.geom.shapes :as gsh]
[app.common.geom.shapes.text :as gsht]
[app.common.math :as mth]
[app.common.pages.helpers :as cph]
[app.common.text :as txt]
@ -21,7 +22,7 @@
[app.util.dom :as dom]
[app.util.object :as obj]
[app.util.text-editor :as ted]
[app.util.text-svg-position :as utp]
[app.util.text-svg-position :as tsp]
[app.util.timers :as ts]
[promesa.core :as p]
[rumext.alpha :as mf]))
@ -62,11 +63,13 @@
(assoc :content (d/txt-merge content editor-content)))))
(defn- update-text-shape
[{:keys [grow-type id migrate]} node]
[{:keys [grow-type id migrate] :as shape} node]
;; Check if we need to update the size because it's auto-width or auto-height
;; Update the position-data of every text fragment
(p/let [position-data (utp/calc-position-data node)]
(st/emit! (dwt/update-position-data id position-data))
(p/let [position-data (tsp/calc-position-data node)]
;; At least one paragraph needs to be inside the bounding box
(when (gsht/overlaps-position-data? shape position-data)
(st/emit! (dwt/update-position-data id position-data)))
(when (contains? #{:auto-height :auto-width} grow-type)
(let [{:keys [width height]}
@ -77,13 +80,12 @@
(when (and (not (mth/almost-zero? width))
(not (mth/almost-zero? height))
(not migrate))
(st/emit! (dwt/resize-text id width height))))))
(st/emit! (dwt/clean-text-modifier id)))
(st/emit! (dwt/resize-text id width height)))))
(st/emit! (dwt/clean-text-modifier id))))
(defn- update-text-modifier
[{:keys [grow-type id]} node]
(p/let [position-data (utp/calc-position-data node)
(p/let [position-data (tsp/calc-position-data node)
props {:position-data position-data}
props