diff --git a/common/src/app/common/file_builder.cljc b/common/src/app/common/file_builder.cljc index a45d0d027..d4520fcb5 100644 --- a/common/src/app/common/file_builder.cljc +++ b/common/src/app/common/file_builder.cljc @@ -498,15 +498,30 @@ (defn add-library-color [file color] - (let [id (or (:id color) (uuid/next))] (-> file (commit-change {:type :add-color - :id id :color (assoc color :id id)}) (assoc :last-id id)))) +(defn update-library-color + [file color] + (let [id (uuid/uuid (:id color))] + (-> file + (commit-change + {:type :mod-color + :color (assoc color :id id)}) + (assoc :last-id (:id color))))) + +(defn delete-library-color + [file color-id] + (let [id (uuid/uuid color-id)] + (-> file + (commit-change + {:type :del-color + :id id})))) + (defn add-library-typography [file typography] (let [id (or (:id typography) (uuid/next))] diff --git a/frontend/src/app/libs/file_builder.cljs b/frontend/src/app/libs/file_builder.cljs index 1a4af9fb5..25aec3ffe 100644 --- a/frontend/src/app/libs/file_builder.cljs +++ b/frontend/src/app/libs/file_builder.cljs @@ -27,7 +27,6 @@ key (-> key d/name str/kebab keyword)] [key value])) $))) - (defn export-file [file] (let [file (assoc file @@ -51,6 +50,14 @@ (rx/observe-on :async) (rx/flat-map e/get-page-data) (rx/share)) + + colors-stream + (->> files-stream + (rx/flat-map vals) + (rx/map #(vector (:id %) (get-in % [:data :colors]))) + (rx/filter #(d/not-empty? (second %))) + (rx/map e/parse-library-color)) + pages-stream (->> render-stream (rx/map e/collect-page))] @@ -64,7 +71,8 @@ (->> (rx/merge manifest-stream - pages-stream) + pages-stream + colors-stream) (rx/reduce conj []) (rx/with-latest-from files-stream) (rx/flat-map (fn [[data _]] @@ -133,6 +141,18 @@ (closeSVG [_] (set! file (fb/close-svg-raw file))) + (addLibraryColor [_ data] + (set! file (fb/add-library-color file (parse-data data))) + (str (:last-id file))) + + (updateLibraryColor [_ data] + (set! file (fb/update-library-color file (parse-data data))) + (str (:last-id file))) + + (deleteLibraryColor [_ data] + (set! file (fb/delete-library-color file (parse-data data))) + (str (:last-id file))) + (asMap [_] (clj->js file))