mirror of
https://github.com/penpot/penpot.git
synced 2026-05-19 14:14:05 -04:00
✨ Migrate svg-attrs, optimize set-shape-svg-attrs, filter invalid URLs (#9118)
* ✨ Add svg-attrs casing fix migration * ⚡ Optimize set-shape-svg-attrs by removing redundant operations - Remove backward compatibility for kebab-case SVG attribute keys (fill-rule, stroke-linecap, stroke-linejoin) since svg-attrs are already normalized to camelCase by the attrs->props migration. - Remove unnecessary select-keys filtering and intermediate map construction (dissoc :style + merge style). - Directly extract values from style and attrs using or, avoiding any intermediate map allocation. Signed-off-by: Andrey Antukh <niwi@niwi.nz> * 🐛 Filter non-http(s) URLs in upload-images to prevent invalid calls Skip upload for image items that are not data URIs and do not have an http:// or https:// URL, avoiding unnecessary RPC calls with invalid URLs to create-file-media-object-from-url. Signed-off-by: Andrey Antukh <niwi@niwi.nz> --------- Signed-off-by: Andrey Antukh <niwi@niwi.nz>
This commit is contained in:
@@ -1805,6 +1805,21 @@
|
||||
{})]
|
||||
(cfcp/sync-component-id-with-ref-shape data libraries)))
|
||||
|
||||
(defmethod migrate-data "0021-fix-shape-svg-attrs"
|
||||
[data _]
|
||||
(some-> cfeat/*new* (swap! conj "fdata/shape-data-type"))
|
||||
(letfn [(update-object [object]
|
||||
(-> object
|
||||
(d/update-when :svg-attrs csvg/attrs->props)
|
||||
(d/update-when :svg-viewbox grc/make-rect)))
|
||||
|
||||
(update-container [container]
|
||||
(d/update-when container :objects d/update-vals update-object))]
|
||||
|
||||
(-> data
|
||||
(update :pages-index d/update-vals update-container)
|
||||
(d/update-when :components d/update-vals update-container))))
|
||||
|
||||
(def available-migrations
|
||||
(into (d/ordered-set)
|
||||
["legacy-2"
|
||||
@@ -1882,4 +1897,5 @@
|
||||
"0017-fix-layout-flex-dir"
|
||||
"0018-remove-unneeded-objects-from-components"
|
||||
"0019-fix-missing-swap-slots"
|
||||
"0020-sync-component-id-with-near-main"]))
|
||||
"0020-sync-component-id-with-near-main"
|
||||
"0021-fix-shape-svg-attrs"]))
|
||||
|
||||
@@ -47,10 +47,12 @@
|
||||
(-> item
|
||||
(assoc :name (extract-name href))
|
||||
(assoc :url href))))))
|
||||
(rx/filter (fn [item]
|
||||
(or (contains? item :content)
|
||||
(let [url (:url item)]
|
||||
(or (str/starts-with? url "http://")
|
||||
(str/starts-with? url "https://"))))))
|
||||
(rx/mapcat (fn [item]
|
||||
;; TODO: :create-file-media-object-from-url is
|
||||
;; deprecated and this should be resolved in
|
||||
;; frontend
|
||||
(->> (rp/cmd! (if (contains? item :content)
|
||||
:upload-file-media-object
|
||||
:create-file-media-object-from-url)
|
||||
|
||||
@@ -762,16 +762,10 @@
|
||||
(defn set-shape-svg-attrs
|
||||
[attrs]
|
||||
(let [style (:style attrs)
|
||||
;; Filter to only supported attributes
|
||||
allowed-keys #{:fill :fillRule :fill-rule :strokeLinecap :stroke-linecap :strokeLinejoin :stroke-linejoin}
|
||||
attrs (-> attrs
|
||||
(dissoc :style)
|
||||
(merge style)
|
||||
(select-keys allowed-keys))
|
||||
fill-rule (-> (or (:fill-rule attrs) (:fillRule attrs)) sr/translate-fill-rule)
|
||||
stroke-linecap (-> (or (:stroke-linecap attrs) (:strokeLinecap attrs)) sr/translate-stroke-linecap)
|
||||
stroke-linejoin (-> (or (:stroke-linejoin attrs) (:strokeLinejoin attrs)) sr/translate-stroke-linejoin)
|
||||
fill-none (= "none" (-> attrs :fill))]
|
||||
fill-rule (-> (or (:fillRule style) (:fillRule attrs)) sr/translate-fill-rule)
|
||||
stroke-linecap (-> (or (:strokeLinecap style) (:strokeLinecap attrs)) sr/translate-stroke-linecap)
|
||||
stroke-linejoin (-> (or (:strokeLinejoin style) (:strokeLinejoin attrs)) sr/translate-stroke-linejoin)
|
||||
fill-none (= "none" (or (:fill style) (:fill attrs)))]
|
||||
(h/call wasm/internal-module "_set_shape_svg_attrs" fill-rule stroke-linecap stroke-linejoin fill-none)))
|
||||
|
||||
(defn set-shape-path-content
|
||||
|
||||
Reference in New Issue
Block a user