diff --git a/frontend/src/app/main.cljs b/frontend/src/app/main.cljs index 522715331..3cbbe0d70 100644 --- a/frontend/src/app/main.cljs +++ b/frontend/src/app/main.cljs @@ -105,8 +105,7 @@ (rx/map deref) (rx/filter du/is-authenticated?) (rx/take 1) - (rx/map #(ws/initialize)) - (rx/tap #(plugins/init!))))))) + (rx/map #(ws/initialize))))))) (defn ^:export init [] @@ -116,7 +115,8 @@ (cur/init-styles) (thr/init!) (init-ui) - (st/emit! (initialize))) + (st/emit! (plugins/initialize) + (initialize))) (defn ^:export reinit ([] diff --git a/frontend/src/app/main/data/workspace/media.cljs b/frontend/src/app/main/data/workspace/media.cljs index 8abf32dd8..d97d0b803 100644 --- a/frontend/src/app/main/data/workspace/media.cljs +++ b/frontend/src/app/main/data/workspace/media.cljs @@ -131,7 +131,7 @@ (rx/merge-map svg->clj) (rx/tap on-svg))))) -(defn- process-blobs +(defn process-blobs [{:keys [file-id local? name blobs force-media on-image on-svg]}] (letfn [(svg-blob? [blob] (and (not force-media) diff --git a/frontend/src/app/plugins.cljs b/frontend/src/app/plugins.cljs index 551591b4a..36346de27 100644 --- a/frontend/src/app/plugins.cljs +++ b/frontend/src/app/plugins.cljs @@ -16,15 +16,20 @@ [beicon.v2.core :as rx] [potok.v2.core :as ptk])) -(defn init! +(defn init-plugins-runtime! [] - (->> st/stream - (rx/filter (ptk/type? ::features/initialize)) - (rx/take 1) - ;; We need to wait to the init event to finish - (rx/observe-on :async) - (rx/subs! - (fn [] - (when (features/active-feature? @st/state "plugins/runtime") - (when-let [init-runtime (obj/get global "initPluginsRuntime")] - (init-runtime (fn [plugin-id] (api/create-context plugin-id))))))))) + (when-let [init-runtime (obj/get global "initPluginsRuntime")] + (init-runtime (fn [plugin-id] (api/create-context plugin-id))))) + +(defn initialize + [] + (ptk/reify ::initialize + ptk/WatchEvent + (watch [_ _ stream] + (->> stream + (rx/filter (ptk/type? ::features/initialize)) + (rx/observe-on :async) + (rx/filter #(features/active-feature? @st/state "plugins/runtime")) + (rx/take 1) + (rx/tap init-plugins-runtime!) + (rx/ignore))))) diff --git a/frontend/src/app/plugins/api.cljs b/frontend/src/app/plugins/api.cljs index 790197e64..4de6700f8 100644 --- a/frontend/src/app/plugins/api.cljs +++ b/frontend/src/app/plugins/api.cljs @@ -124,6 +124,22 @@ (rx/take 1) (rx/subs! resolve reject))))))) + (uploadMediaData + [_ name data mime-type] + (let [file-id (:current-file-id @st/state)] + (p/create + (fn [resolve reject] + (->> (dwm/process-blobs + {:file-id file-id + :local? false + :name name + :blobs [(js/Blob. #js [data] #js {:type mime-type})] + :on-image identity + :on-svg identity}) + (rx/take 1) + (rx/map u/to-js) + (rx/subs! resolve reject)))))) + (group [_ shapes] (cond diff --git a/frontend/src/features.cljs b/frontend/src/features.cljs index 5b111096f..0fa5ec46b 100644 --- a/frontend/src/features.cljs +++ b/frontend/src/features.cljs @@ -27,6 +27,6 @@ (defn ^:export plugins [] (st/emit! (features/enable-feature "plugins/runtime")) - (plugins/init!) + (plugins/init-plugins-runtime!) nil)