Import components

This commit is contained in:
alonso.torres 2021-06-24 16:18:06 +02:00 committed by Andrés Moya
parent 7d14122746
commit 85a6edb1fd
5 changed files with 60 additions and 21 deletions

View file

@ -265,7 +265,11 @@
:id group-id :id group-id
:operations :operations
[{:type :set :attr :selrect :val (:selrect group')} [{:type :set :attr :selrect :val (:selrect group')}
{:type :set :attr :points :val (:points group')}]} {:type :set :attr :points :val (:points group')}
{:type :set :attr :x :val (-> group' :selrect :x)}
{:type :set :attr :y :val (-> group' :selrect :y)}
{:type :set :attr :width :val (-> group' :selrect :width)}
{:type :set :attr :height :val (-> group' :selrect :height)}]}
{:add-container? true})))] {:add-container? true})))]
@ -442,7 +446,11 @@
:id component-id :id component-id
:operations :operations
[{:type :set :attr :selrect :val (:selrect component')} [{:type :set :attr :selrect :val (:selrect component')}
{:type :set :attr :points :val (:points component')}]} {:type :set :attr :points :val (:points component')}
{:type :set :attr :x :val (-> component' :selrect :x)}
{:type :set :attr :y :val (-> component' :selrect :y)}
{:type :set :attr :width :val (-> component' :selrect :width)}
{:type :set :attr :height :val (-> component' :selrect :height)}]}
{:add-container? true})))] {:add-container? true})))]

View file

@ -40,7 +40,6 @@
(s/keys :req-un [::id (s/keys :req-un [::id
::name ::name
::team-id ::team-id
::profile-id
::created-at ::created-at
::modified-at ::modified-at
::is-pinned])) ::is-pinned]))

View file

@ -74,11 +74,10 @@
(mf/fnc group-wrapper (mf/fnc group-wrapper
[{:keys [shape frame] :as props}] [{:keys [shape frame] :as props}]
(let [childs (mapv #(get objects %) (:shapes shape))] (let [childs (mapv #(get objects %) (:shapes shape))]
[:& shape-container {:shape shape}
[:& group-shape {:frame frame [:& group-shape {:frame frame
:shape shape :shape shape
:is-child-selected? true :is-child-selected? true
:childs childs}]])))) :childs childs}]))))
(defn svg-raw-wrapper-factory (defn svg-raw-wrapper-factory
[objects] [objects]
@ -87,7 +86,9 @@
(mf/fnc svg-raw-wrapper (mf/fnc svg-raw-wrapper
[{:keys [shape frame] :as props}] [{:keys [shape frame] :as props}]
(let [childs (mapv #(get objects %) (:shapes shape))] (let [childs (mapv #(get objects %) (:shapes shape))]
(if (and (contains? shape :svg-attrs) (map? (:content shape))) (if (and (contains? shape :svg-attrs)
(map? (:content shape))
(not= :svg (get-in shape [:content :tag])))
[:> shape-container {:shape shape} [:> shape-container {:shape shape}
[:& svg-raw-shape {:frame frame [:& svg-raw-shape {:frame frame
:shape shape :shape shape
@ -108,9 +109,8 @@
(let [shape (-> (gsh/transform-shape shape) (let [shape (-> (gsh/transform-shape shape)
(gsh/translate-to-frame frame)) (gsh/translate-to-frame frame))
opts #js {:shape shape} opts #js {:shape shape}
svg-element? (and (= :svg-raw (:type shape)) svg-raw? (= :svg-raw (:type shape))]
(not= :svg (get-in shape [:content :tag])))] (if-not svg-raw?
(if-not svg-element?
[:> shape-container {:shape shape} [:> shape-container {:shape shape}
(case (:type shape) (case (:type shape)
:text [:> text/text-shape opts] :text [:> text/text-shape opts]
@ -120,7 +120,6 @@
:circle [:> circle/circle-shape opts] :circle [:> circle/circle-shape opts]
:frame [:> frame-wrapper {:shape shape}] :frame [:> frame-wrapper {:shape shape}]
:group [:> group-wrapper {:shape shape :frame frame}] :group [:> group-wrapper {:shape shape :frame frame}]
:svg-raw [:> svg-raw-wrapper {:shape shape :frame frame}]
nil)] nil)]
;; Don't wrap svg elements inside a <g> otherwise some can break ;; Don't wrap svg elements inside a <g> otherwise some can break
@ -271,7 +270,8 @@
[:symbol {:id (str id) [:symbol {:id (str id)
:viewBox vbox} :viewBox vbox}
[:title name] [:title name]
[:& group-wrapper {:shape root :view-box vbox}]])) [:> shape-container {:shape root}
[:& group-wrapper {:shape root :view-box vbox}]]]))
(mf/defc components-sprite-svg (mf/defc components-sprite-svg
{::mf/wrap-props false} {::mf/wrap-props false}

View file

@ -173,6 +173,10 @@
(map #(:attrs %)) (map #(:attrs %))
(reduce add-attrs node-attrs))) (reduce add-attrs node-attrs)))
(= type :frame)
(let [svg-node (->> node :content (d/seek #(= "frame-background" (get-in % [:attrs :class]))))]
(merge (add-attrs {} (:attrs svg-node)) node-attrs))
(= type :svg-raw) (= type :svg-raw)
(->> node :content last) (->> node :content last)

View file

@ -18,7 +18,6 @@
[app.util.zip :as uz] [app.util.zip :as uz]
[app.worker.impl :as impl] [app.worker.impl :as impl]
[beicon.core :as rx] [beicon.core :as rx]
[cuerdas.core :as str]
[tubax.core :as tubax])) [tubax.core :as tubax]))
;; Upload changes batches size ;; Upload changes batches size
@ -141,10 +140,17 @@
(dissoc :id-mapping :interactions)))) (dissoc :id-mapping :interactions))))
(defn merge-reduce [f seed ob] (defn merge-reduce [f seed ob]
(let [current-acc (atom seed)]
(->> (rx/concat (->> (rx/concat
(rx/of seed) (rx/of seed)
(rx/merge-scan f seed ob)) (->> ob
(rx/last))) (rx/mapcat #(f @current-acc %))
(rx/tap #(reset! current-acc %))))
(rx/last))))
(defn skip-last
[n ob]
(.pipe ob (.skipLast js/rxjsOperators (int n))))
(defn resolve-media (defn resolve-media
[file-id node] [file-id node]
@ -233,7 +239,6 @@
(defn process-library-media (defn process-library-media
[file file-id file-desc zip] [file file-id file-desc zip]
(rx/of file)
(if (:has-media file-desc) (if (:has-media file-desc)
(let [add-media (let [add-media
(fn [file media] (fn [file media]
@ -263,9 +268,32 @@
(rx/of file))) (rx/of file)))
(defn add-component [file content]
(let [content (cip/find-node content :g)
data (cip/parse-data :group content)
file (-> file (fb/start-component data))
id (-> (get-in content [:attrs :id]) (uuid/uuid))
component-id (:last-id file)
file (assoc file [:library-mapping id] component-id)
nodes (cip/node-seq content)]
(->> (rx/from nodes)
(rx/filter cip/shape?)
(rx/skip 1)
(skip-last 1)
(rx/mapcat (partial resolve-media (:id file)))
(rx/reduce add-shape-file file)
(rx/map #(fb/finish-component %)))))
(defn process-library-components (defn process-library-components
[file file-id file-desc zip] [file file-id file-desc zip]
(rx/of file)) (if (:has-components file-desc)
(let [path (str (d/name file-id) "/components.svg")]
(->> (uz/get-file zip path)
(rx/map (comp tubax/xml->clj :content))
(rx/flat-map (fn [content] (->> (cip/node-seq content) (filter #(= :symbol (:tag %))))))
(merge-reduce add-component file)))
(rx/of file)))
(defn process-file (defn process-file
[file file-id file-desc zip] [file file-id file-desc zip]