mirror of
https://github.com/penpot/penpot.git
synced 2025-05-22 23:06:10 +02: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
|
ptk/WatchEvent
|
||||||
(watch [_ state _]
|
(watch [_ state _]
|
||||||
(let [features (features/get-team-enabled-features state)]
|
(let [features (features/get-team-enabled-features state)]
|
||||||
(rx/merge
|
(rx/concat
|
||||||
(->> (rp/cmd! :link-file-to-library {:file-id file-id :library-id library-id})
|
(rx/merge
|
||||||
(rx/ignore))
|
(->> (rp/cmd! :link-file-to-library {:file-id file-id :library-id library-id})
|
||||||
(->> (rp/cmd! :get-file {:id library-id :features features})
|
(rx/ignore))
|
||||||
(rx/merge-map fpmap/resolve-file)
|
(->> (rp/cmd! :get-file {:id library-id :features features})
|
||||||
(rx/map (fn [file]
|
(rx/merge-map fpmap/resolve-file)
|
||||||
(fn [state]
|
(rx/map (fn [file]
|
||||||
(assoc-in state [:workspace-libraries library-id] file)))))
|
(fn [state]
|
||||||
(->> (rp/cmd! :get-file-object-thumbnails {:file-id library-id :tag "component"})
|
(assoc-in state [:workspace-libraries library-id] file)))))
|
||||||
(rx/map (fn [thumbnails]
|
(->> (rp/cmd! :get-file-object-thumbnails {:file-id library-id :tag "component"})
|
||||||
(fn [state]
|
(rx/map (fn [thumbnails]
|
||||||
(update state :workspace-thumbnails merge thumbnails))))))))))
|
(fn [state]
|
||||||
|
(update state :workspace-thumbnails merge thumbnails))))))
|
||||||
|
(rx/of (ptk/reify ::attach-library-finished)))))))
|
||||||
|
|
||||||
(defn unlink-file-from-library
|
(defn unlink-file-from-library
|
||||||
[file-id library-id]
|
[file-id library-id]
|
||||||
|
|
|
@ -20,10 +20,14 @@
|
||||||
[app.main.data.workspace :as dw]
|
[app.main.data.workspace :as dw]
|
||||||
[app.main.data.workspace.libraries :as dwl]
|
[app.main.data.workspace.libraries :as dwl]
|
||||||
[app.main.data.workspace.texts :as dwt]
|
[app.main.data.workspace.texts :as dwt]
|
||||||
|
[app.main.repo :as rp]
|
||||||
[app.main.store :as st]
|
[app.main.store :as st]
|
||||||
[app.plugins.shape :as shape]
|
[app.plugins.shape :as shape]
|
||||||
[app.plugins.utils :as u]
|
[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-color-proxy)
|
||||||
(declare lib-typography-proxy)
|
(declare lib-typography-proxy)
|
||||||
|
@ -744,7 +748,7 @@
|
||||||
(cr/add-properties!
|
(cr/add-properties!
|
||||||
(Library. plugin-id file-id)
|
(Library. plugin-id file-id)
|
||||||
{:name "$plugin" :enumerable false :get (constantly plugin-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"
|
{:name "id"
|
||||||
:get #(-> % u/proxy->file :id str)}
|
:get #(-> % u/proxy->file :id str)}
|
||||||
|
@ -780,10 +784,43 @@
|
||||||
|
|
||||||
(deftype PenpotLibrarySubcontext [$plugin]
|
(deftype PenpotLibrarySubcontext [$plugin]
|
||||||
Object
|
Object
|
||||||
(find
|
(availableLibraries
|
||||||
[_ _name])
|
[_]
|
||||||
|
(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
|
(defn library-subcontext
|
||||||
[plugin-id]
|
[plugin-id]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue