mirror of
https://github.com/penpot/penpot.git
synced 2025-04-13 15:31:26 -05:00
✨ Add to plugins connect and fetch libraries
This commit is contained in:
parent
84ecb99400
commit
8ff0015458
2 changed files with 56 additions and 17 deletions
|
@ -1281,18 +1281,20 @@
|
|||
ptk/WatchEvent
|
||||
(watch [_ state _]
|
||||
(let [features (features/get-team-enabled-features state)]
|
||||
(rx/merge
|
||||
(->> (rp/cmd! :link-file-to-library {:file-id file-id :library-id library-id})
|
||||
(rx/ignore))
|
||||
(->> (rp/cmd! :get-file {:id library-id :features features})
|
||||
(rx/merge-map fpmap/resolve-file)
|
||||
(rx/map (fn [file]
|
||||
(fn [state]
|
||||
(assoc-in state [:workspace-libraries library-id] file)))))
|
||||
(->> (rp/cmd! :get-file-object-thumbnails {:file-id library-id :tag "component"})
|
||||
(rx/map (fn [thumbnails]
|
||||
(fn [state]
|
||||
(update state :workspace-thumbnails merge thumbnails))))))))))
|
||||
(rx/concat
|
||||
(rx/merge
|
||||
(->> (rp/cmd! :link-file-to-library {:file-id file-id :library-id library-id})
|
||||
(rx/ignore))
|
||||
(->> (rp/cmd! :get-file {:id library-id :features features})
|
||||
(rx/merge-map fpmap/resolve-file)
|
||||
(rx/map (fn [file]
|
||||
(fn [state]
|
||||
(assoc-in state [:workspace-libraries library-id] file)))))
|
||||
(->> (rp/cmd! :get-file-object-thumbnails {:file-id library-id :tag "component"})
|
||||
(rx/map (fn [thumbnails]
|
||||
(fn [state]
|
||||
(update state :workspace-thumbnails merge thumbnails))))))
|
||||
(rx/of (ptk/reify ::attach-library-finished)))))))
|
||||
|
||||
(defn unlink-file-from-library
|
||||
[file-id library-id]
|
||||
|
|
|
@ -20,10 +20,14 @@
|
|||
[app.main.data.workspace :as dw]
|
||||
[app.main.data.workspace.libraries :as dwl]
|
||||
[app.main.data.workspace.texts :as dwt]
|
||||
[app.main.repo :as rp]
|
||||
[app.main.store :as st]
|
||||
[app.plugins.shape :as shape]
|
||||
[app.plugins.utils :as u]
|
||||
[app.util.object :as obj]))
|
||||
[app.util.object :as obj]
|
||||
[beicon.v2.core :as rx]
|
||||
[potok.v2.core :as ptk]
|
||||
[promesa.core :as p]))
|
||||
|
||||
(declare lib-color-proxy)
|
||||
(declare lib-typography-proxy)
|
||||
|
@ -744,7 +748,7 @@
|
|||
(cr/add-properties!
|
||||
(Library. plugin-id file-id)
|
||||
{:name "$plugin" :enumerable false :get (constantly plugin-id)}
|
||||
{:name "$file" :enumerable false :get (constantly file-id)}
|
||||
{:name "$id" :enumerable false :get (constantly file-id)}
|
||||
|
||||
{:name "id"
|
||||
:get #(-> % u/proxy->file :id str)}
|
||||
|
@ -780,10 +784,43 @@
|
|||
|
||||
(deftype PenpotLibrarySubcontext [$plugin]
|
||||
Object
|
||||
(find
|
||||
[_ _name])
|
||||
(availableLibraries
|
||||
[_]
|
||||
(let [team-id (:current-team-id @st/state)]
|
||||
(p/create
|
||||
(fn [resolve reject]
|
||||
(let [current-libs (into #{} (map first) (get @st/state :workspace-libraries))]
|
||||
(->> (rp/cmd! :get-team-shared-files {:team-id team-id})
|
||||
(rx/map (fn [result]
|
||||
(->> result
|
||||
(filter #(not (contains? current-libs (:id %))))
|
||||
(map
|
||||
(fn [{:keys [id name library-summary]}]
|
||||
#js {:id (dm/str id)
|
||||
:name name
|
||||
:numColors (-> library-summary :colors :count)
|
||||
:numComponents (-> library-summary :components :count)
|
||||
:numTypographies (-> library-summary :typographies :count)}))
|
||||
(apply array))))
|
||||
(rx/subs! resolve reject)))))))
|
||||
|
||||
(find [_]))
|
||||
(connectLibrary
|
||||
[_ library-id]
|
||||
(p/create
|
||||
(fn [resolve reject]
|
||||
(cond
|
||||
(not (string? library-id))
|
||||
(do (u/display-not-valid :connectLibrary library-id)
|
||||
(reject nil))
|
||||
|
||||
:else
|
||||
(let [file-id (:current-file-id @st/state)
|
||||
library-id (uuid/uuid library-id)]
|
||||
(->> st/stream
|
||||
(rx/filter (ptk/type? ::dwl/attach-library-finished))
|
||||
(rx/take 1)
|
||||
(rx/subs! #(resolve (library-proxy $plugin library-id)) reject))
|
||||
(st/emit! (dwl/link-file-to-library file-id library-id))))))))
|
||||
|
||||
(defn library-subcontext
|
||||
[plugin-id]
|
||||
|
|
Loading…
Add table
Reference in a new issue