mirror of
https://github.com/penpot/penpot.git
synced 2025-05-08 05:35:54 +02:00
✨ Import/export folders in library elements
This commit is contained in:
parent
f312c122ca
commit
ddbdc2a27f
6 changed files with 48 additions and 23 deletions
|
@ -393,6 +393,7 @@
|
||||||
|
|
||||||
(let [selrect init/empty-selrect
|
(let [selrect init/empty-selrect
|
||||||
name (:name data)
|
name (:name data)
|
||||||
|
path (:path data)
|
||||||
obj (-> (init/make-minimal-group nil selrect name)
|
obj (-> (init/make-minimal-group nil selrect name)
|
||||||
(merge data)
|
(merge data)
|
||||||
(check-name file :group)
|
(check-name file :group)
|
||||||
|
@ -402,6 +403,7 @@
|
||||||
{:type :add-component
|
{:type :add-component
|
||||||
:id (:id obj)
|
:id (:id obj)
|
||||||
:name name
|
:name name
|
||||||
|
:path path
|
||||||
:shapes [obj]})
|
:shapes [obj]})
|
||||||
|
|
||||||
(assoc :last-id (:id obj))
|
(assoc :last-id (:id obj))
|
||||||
|
|
|
@ -247,7 +247,7 @@
|
||||||
(mf/defc component-symbol
|
(mf/defc component-symbol
|
||||||
[{:keys [id data] :as props}]
|
[{:keys [id data] :as props}]
|
||||||
|
|
||||||
(let [{:keys [name objects]} data
|
(let [{:keys [name path objects]} data
|
||||||
root (get objects id)
|
root (get objects id)
|
||||||
|
|
||||||
{:keys [width height]} (:selrect root)
|
{:keys [width height]} (:selrect root)
|
||||||
|
@ -267,8 +267,9 @@
|
||||||
(mf/deps objects)
|
(mf/deps objects)
|
||||||
#(group-wrapper-factory objects))]
|
#(group-wrapper-factory objects))]
|
||||||
|
|
||||||
[:symbol {:id (str id)
|
[:> "symbol" #js {:id (str id)
|
||||||
:viewBox vbox}
|
:viewBox vbox
|
||||||
|
"penpot:path" path}
|
||||||
[:title name]
|
[:title name]
|
||||||
[:> shape-container {:shape root}
|
[:> shape-container {:shape root}
|
||||||
[:& group-wrapper {:shape root :view-box vbox}]]]))
|
[:& group-wrapper {:shape root :view-box vbox}]]]))
|
||||||
|
|
|
@ -22,6 +22,8 @@
|
||||||
|
|
||||||
(log/set-level! :debug)
|
(log/set-level! :debug)
|
||||||
|
|
||||||
|
(def ^:const emit-delay 1000)
|
||||||
|
|
||||||
(defn use-import-file
|
(defn use-import-file
|
||||||
[project-id on-finish-import]
|
[project-id on-finish-import]
|
||||||
(mf/use-callback
|
(mf/use-callback
|
||||||
|
@ -201,7 +203,7 @@
|
||||||
(->> (uw/ask-many!
|
(->> (uw/ask-many!
|
||||||
{:cmd :analyze-import
|
{:cmd :analyze-import
|
||||||
:files (->> files (mapv :uri))})
|
:files (->> files (mapv :uri))})
|
||||||
(rx/delay-emit 1000)
|
(rx/delay-emit emit-delay)
|
||||||
(rx/subs
|
(rx/subs
|
||||||
(fn [{:keys [uri data error] :as msg}]
|
(fn [{:keys [uri data error] :as msg}]
|
||||||
(log/debug :msg msg)
|
(log/debug :msg msg)
|
||||||
|
@ -216,7 +218,7 @@
|
||||||
{:cmd :import-files
|
{:cmd :import-files
|
||||||
:project-id project-id
|
:project-id project-id
|
||||||
:files files})
|
:files files})
|
||||||
(rx/delay-emit 1000)
|
(rx/delay-emit emit-delay)
|
||||||
(rx/subs
|
(rx/subs
|
||||||
(fn [{:keys [file-id status] :as msg}]
|
(fn [{:keys [file-id status] :as msg}]
|
||||||
(log/debug :msg msg)
|
(log/debug :msg msg)
|
||||||
|
|
|
@ -73,8 +73,10 @@
|
||||||
|
|
||||||
(defn get-id
|
(defn get-id
|
||||||
[node]
|
[node]
|
||||||
(when-let [id (re-find uuid-regex (get-in node [:attrs :id]))]
|
(let [attr-id (get-in node [:attrs :id])
|
||||||
(uuid/uuid id)))
|
id (when (string? attr-id) (re-find uuid-regex attr-id))]
|
||||||
|
(when (some? id)
|
||||||
|
(uuid/uuid id))))
|
||||||
|
|
||||||
(defn str->bool
|
(defn str->bool
|
||||||
[val]
|
[val]
|
||||||
|
|
|
@ -82,14 +82,14 @@
|
||||||
[(-> k str/camel) v]))))))
|
[(-> k str/camel) v]))))))
|
||||||
|
|
||||||
(def ^:const color-keys
|
(def ^:const color-keys
|
||||||
[:name :color :opacity :gradient])
|
[:name :color :opacity :gradient :path])
|
||||||
|
|
||||||
(def ^:const typography-keys
|
(def ^:const typography-keys
|
||||||
[:name :font-family :font-id :font-size :font-style :font-variant-id :font-weight
|
[:name :font-family :font-id :font-size :font-style :font-variant-id :font-weight
|
||||||
:letter-spacing :line-height :text-transform])
|
:letter-spacing :line-height :text-transform :path])
|
||||||
|
|
||||||
(def ^:const media-keys
|
(def ^:const media-keys
|
||||||
[:name :mtype :width :height])
|
[:name :mtype :width :height :path])
|
||||||
|
|
||||||
(defn collect-color
|
(defn collect-color
|
||||||
[result color]
|
[result color]
|
||||||
|
|
|
@ -21,7 +21,10 @@
|
||||||
[app.worker.impl :as impl]
|
[app.worker.impl :as impl]
|
||||||
[beicon.core :as rx]
|
[beicon.core :as rx]
|
||||||
[cuerdas.core :as str]
|
[cuerdas.core :as str]
|
||||||
[tubax.core :as tubax]))
|
[tubax.core :as tubax]
|
||||||
|
[app.util.logging :as log]))
|
||||||
|
|
||||||
|
(log/set-level! :trace)
|
||||||
|
|
||||||
;; Upload changes batches size
|
;; Upload changes batches size
|
||||||
(def change-batch-size 100)
|
(def change-batch-size 100)
|
||||||
|
@ -46,20 +49,23 @@
|
||||||
(str file-id "/media/" id "." ext))
|
(str file-id "/media/" id "." ext))
|
||||||
:components (str file-id "/components.svg"))
|
:components (str file-id "/components.svg"))
|
||||||
|
|
||||||
svg? (str/ends-with? path "svg")
|
parse-svg? (and (not= type :media) (str/ends-with? path "svg"))
|
||||||
json? (str/ends-with? path "json")
|
parse-json? (and (not= type :media) (str/ends-with? path "json"))
|
||||||
other? (not (or svg? json?))
|
no-parse? (or (= type :media)
|
||||||
|
(not (or parse-svg? parse-json?)))
|
||||||
|
|
||||||
file-type (if other? "blob" "text")]
|
file-type (if (or parse-svg? parse-json?) "text" "blob")]
|
||||||
|
|
||||||
|
(log/debug :action "parsing" :path path)
|
||||||
|
|
||||||
(cond->> (uz/get-file (:zip context) path file-type)
|
(cond->> (uz/get-file (:zip context) path file-type)
|
||||||
svg?
|
parse-svg?
|
||||||
(rx/map (comp tubax/xml->clj :content))
|
(rx/map (comp tubax/xml->clj :content))
|
||||||
|
|
||||||
json?
|
parse-json?
|
||||||
(rx/map (comp json/decode :content))
|
(rx/map (comp json/decode :content))
|
||||||
|
|
||||||
other?
|
no-parse?
|
||||||
(rx/map :content)))))
|
(rx/map :content)))))
|
||||||
|
|
||||||
(defn resolve-factory
|
(defn resolve-factory
|
||||||
|
@ -138,6 +144,9 @@
|
||||||
(defn upload-media-files
|
(defn upload-media-files
|
||||||
"Upload a image to the backend and returns its id"
|
"Upload a image to the backend and returns its id"
|
||||||
[file-id name data-uri]
|
[file-id name data-uri]
|
||||||
|
|
||||||
|
(log/debug :action "uploading" :file-id file-id :name name)
|
||||||
|
|
||||||
(->> (http/send!
|
(->> (http/send!
|
||||||
{:uri data-uri
|
{:uri data-uri
|
||||||
:response-type :blob
|
:response-type :blob
|
||||||
|
@ -156,11 +165,18 @@
|
||||||
(->> node
|
(->> node
|
||||||
(ct/transform-nodes
|
(ct/transform-nodes
|
||||||
(fn [item]
|
(fn [item]
|
||||||
(-> item
|
(cond-> item
|
||||||
(d/update-when :fill-color-ref-id resolve)
|
(uuid? (get item :fill-color-ref-id))
|
||||||
(d/update-when :fill-color-ref-file resolve)
|
(d/update-when :fill-color-ref-id resolve)
|
||||||
(d/update-when :typography-ref-id resolve)
|
|
||||||
(d/update-when :typography-ref-file resolve)))))))
|
(uuid? (get item :fill-color-ref-file))
|
||||||
|
(d/update-when :fill-color-ref-file resolve)
|
||||||
|
|
||||||
|
(uuid? (get item :typography-ref-id))
|
||||||
|
(d/update-when :typography-ref-id resolve)
|
||||||
|
|
||||||
|
(uuid? (get item :typography-ref-file))
|
||||||
|
(d/update-when :typography-ref-file resolve)))))))
|
||||||
|
|
||||||
(defn resolve-data-ids
|
(defn resolve-data-ids
|
||||||
[data type context]
|
[data type context]
|
||||||
|
@ -273,7 +289,9 @@
|
||||||
file-id (:id file)
|
file-id (:id file)
|
||||||
old-id (cip/get-id node)
|
old-id (cip/get-id node)
|
||||||
id (resolve old-id)
|
id (resolve old-id)
|
||||||
|
path (get-in node [:attrs :penpot:path] "")
|
||||||
data (-> (cip/parse-data :group content)
|
data (-> (cip/parse-data :group content)
|
||||||
|
(assoc :path path)
|
||||||
(assoc :id id))
|
(assoc :id id))
|
||||||
|
|
||||||
file (-> file (fb/start-component data))
|
file (-> file (fb/start-component data))
|
||||||
|
|
Loading…
Add table
Reference in a new issue