0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-03-13 08:11:30 -05:00

Fix problems with export/import

This commit is contained in:
alonso.torres 2022-02-21 11:55:53 +01:00
parent 3228582cbe
commit 82c6b8daae
4 changed files with 68 additions and 53 deletions

View file

@ -109,7 +109,8 @@
(cond-> text? (cond-> text?
(-> (add! :grow-type) (-> (add! :grow-type)
(add! :content (comp json/encode uuid->string)))) (add! :content (comp json/encode uuid->string))
(add! :position-data (comp json/encode uuid->string))))
(cond-> mask? (cond-> mask?
(obj/set! "penpot:masked-group" "true")) (obj/set! "penpot:masked-group" "true"))
@ -138,6 +139,7 @@
(into {} (map prefix-entry) m))) (into {} (map prefix-entry) m)))
(defn- export-grid-data [{:keys [grids]}] (defn- export-grid-data [{:keys [grids]}]
(when (d/not-empty? grids)
(mf/html (mf/html
[:> "penpot:grids" #js {} [:> "penpot:grids" #js {}
(for [{:keys [type display params]} grids] (for [{:keys [type display params]} grids]
@ -150,7 +152,7 @@
(obj/set! "penpot:opacity" (get-in params [:color :opacity])) (obj/set! "penpot:opacity" (get-in params [:color :opacity]))
(obj/set! "penpot:type" (d/name type)) (obj/set! "penpot:type" (d/name type))
(cond-> (some? display) (cond-> (some? display)
(obj/set! "penpot:display" (str display))))]))])) (obj/set! "penpot:display" (str display))))]))])))
(mf/defc export-flows (mf/defc export-flows
[{:keys [flows]}] [{:keys [flows]}]

View file

@ -23,9 +23,15 @@
[props] [props]
(let [render-id (mf/use-ctx muc/render-ctx) (let [render-id (mf/use-ctx muc/render-ctx)
{:keys [position-data] :as shape} (obj/get props "shape") {:keys [x y width height position-data] :as shape} (obj/get props "shape")
transform (str (gsh/transform-matrix shape)) transform (str (gsh/transform-matrix shape))
group-props (-> #js {:transform transform}
;; These position attributes are not really necesary but they are convenient for for the export
group-props (-> #js {:transform transform
:x x
:y y
:width width
:height height}
(attrs/add-style-attrs shape render-id)) (attrs/add-style-attrs shape render-id))
get-gradient-id get-gradient-id
(fn [index] (fn [index]
@ -40,7 +46,6 @@
:attr :fill-color-gradient :attr :fill-color-gradient
:shape data}]))]) :shape data}]))])
[:& shape-custom-stroke {:shape shape}
[:> :g group-props [:> :g group-props
(for [[index data] (d/enumerate position-data)] (for [[index data] (d/enumerate position-data)]
(let [props (-> #js {:x (:x data) (let [props (-> #js {:x (:x data)
@ -55,6 +60,7 @@
:direction (if (:rtl? data) "rtl" "ltr") :direction (if (:rtl? data) "rtl" "ltr")
:whiteSpace "pre"} :whiteSpace "pre"}
(attrs/add-fill data (get-gradient-id index)))})] (attrs/add-fill data (get-gradient-id index)))})]
[:> :text props (:text data)]))]]])) [:& shape-custom-stroke {:shape shape}
[:> :text props (:text data)]]))]]))

View file

@ -178,7 +178,6 @@
(mf/use-layout-effect (mf/use-layout-effect
(mf/deps show-svg-text?) (mf/deps show-svg-text?)
(fn [] (fn []
(let []
(when-not show-svg-text? (when-not show-svg-text?
;; There is no position data we need to calculate it even if no change has happened ;; There is no position data we need to calculate it even if no change has happened
;; this usualy happens the first time a text is rendered ;; this usualy happens the first time a text is rendered
@ -197,7 +196,7 @@
(fn [] (fn []
(when-let [sid (mf/ref-val sid-ref)] (when-let [sid (mf/ref-val sid-ref)]
(rx/dispose! sid)))))) (rx/dispose! sid)))))
[:> shape-container {:shape shape} [:> shape-container {:shape shape}
;; We keep hidden the shape when we're editing so it keeps track of the size ;; We keep hidden the shape when we're editing so it keeps track of the size

View file

@ -185,7 +185,7 @@
(d/deep-mapm (d/deep-mapm
(fn [pair] (->> pair (mapv convert))))))) (fn [pair] (->> pair (mapv convert)))))))
(def search-data-node? #{:rect :image :path :text :circle}) (def search-data-node? #{:rect :image :path :circle})
(defn get-svg-data (defn get-svg-data
[type node] [type node]
@ -200,6 +200,13 @@
(map #(:attrs %)) (map #(:attrs %))
(reduce add-attrs node-attrs))) (reduce add-attrs node-attrs)))
(= type :text)
(->> node
(node-seq)
(filter #(contains? #{:g :foreignObject} (:tag %)))
(map #(:attrs %))
(reduce add-attrs node-attrs))
(= type :frame) (= type :frame)
(let [svg-node (->> node :content (d/seek #(= "frame-background" (get-in % [:attrs :class]))))] (let [svg-node (->> node :content (d/seek #(= "frame-background" (get-in % [:attrs :class]))))]
(merge (add-attrs {} (:attrs svg-node)) node-attrs)) (merge (add-attrs {} (:attrs svg-node)) node-attrs))
@ -482,7 +489,8 @@
[props node] [props node]
(-> props (-> props
(assoc :grow-type (get-meta node :grow-type keyword)) (assoc :grow-type (get-meta node :grow-type keyword))
(assoc :content (get-meta node :content (comp string->uuid json/decode))))) (assoc :content (get-meta node :content (comp string->uuid json/decode)))
(assoc :position-data (get-meta node :position-data (comp string->uuid json/decode)))))
(defn add-group-data (defn add-group-data
[props node] [props node]