🎉 Add support components managemente via library

This commit is contained in:
Alejandro Alonso 2022-11-30 06:25:21 +01:00
parent 4c1f2cfded
commit a19417417a
2 changed files with 71 additions and 7 deletions

View file

@ -661,6 +661,40 @@
shapes) shapes)
(dissoc $ :current-component-id)))) (dissoc $ :current-component-id))))
(defn create-component-instance
[file data]
(let [component-id (uuid/uuid (:component-id data))
x (:x data)
y (:y data)
file (assoc file :current-component-id component-id)
page-id (:current-page-id file)
page (ctpl/get-page (:data file) page-id)
component (ctkl/get-component (:data file) component-id)
;; main-instance-id (:main-instance-id component)
[shape shapes]
(ctn/make-component-instance page
component
(:id file)
(gpt/point x
y)
#_{:main-instance? true
:force-id main-instance-id})]
(as-> file $
(reduce #(commit-change %1
{:type :add-obj
:id (:id %2)
:page-id (:id page)
:parent-id (:parent-id %2)
:frame-id (:frame-id %2)
:obj %2})
$
shapes)
(assoc $ :last-id (:id shape))
(dissoc $ :current-component-id))))
(defn delete-object (defn delete-object
[file id] [file id]
(let [page-id (:current-page-id file)] (let [page-id (:current-page-id file)]
@ -687,7 +721,8 @@
{:type :mod-obj {:type :mod-obj
:operations (reduce generate-operation [] attrs) :operations (reduce generate-operation [] attrs)
:page-id page-id :page-id page-id
:id (:id old-obj)})))) :id (:id old-obj)})
(assoc :last-id (:id old-obj)))))
(defn get-current-page (defn get-current-page
[file] [file]

View file

@ -58,6 +58,12 @@
(rx/filter #(d/not-empty? (second %))) (rx/filter #(d/not-empty? (second %)))
(rx/map e/parse-library-color)) (rx/map e/parse-library-color))
components-stream
(->> files-stream
(rx/flat-map vals)
(rx/filter #(d/not-empty? (get-in % [:data :components])))
(rx/flat-map e/parse-library-components))
pages-stream pages-stream
(->> render-stream (->> render-stream
(rx/map e/collect-page))] (rx/map e/collect-page))]
@ -72,6 +78,7 @@
(->> (rx/merge (->> (rx/merge
manifest-stream manifest-stream
pages-stream pages-stream
components-stream
colors-stream) colors-stream)
(rx/reduce conj []) (rx/reduce conj [])
(rx/with-latest-from files-stream) (rx/with-latest-from files-stream)
@ -153,6 +160,28 @@
(set! file (fb/delete-library-color file (parse-data data))) (set! file (fb/delete-library-color file (parse-data data)))
(str (:last-id file))) (str (:last-id file)))
(startComponent [_ data]
(set! file (fb/start-component file (parse-data data)))
(str (:current-component-id file)))
(finishComponent [_]
(set! file (fb/finish-component file)))
(createComponentInstance [_ data]
(set! file (fb/create-component-instance file (parse-data data)))
(str (:last-id file)))
(lookupShape [_ shape-id]
(clj->js (fb/lookup-shape file (uuid/uuid shape-id))))
(updateObject [_ id new-obj]
(let [old-obj (fb/lookup-shape file (uuid/uuid id))
new-obj (d/deep-merge old-obj (parse-data new-obj))]
(set! file (fb/update-object file old-obj new-obj))))
(deleteObject [_ id]
(set! file (fb/delete-object file (uuid/uuid id))))
(asMap [_] (asMap [_]
(clj->js file)) (clj->js file))