0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-06 14:50:20 -05:00

♻️ Rename workspace-libraries to libraries on state and refs

This commit is contained in:
Andrey Antukh 2024-12-10 14:45:56 +01:00
parent 969c6a2e2f
commit e5894ceea1
28 changed files with 64 additions and 71 deletions

View file

@ -79,7 +79,7 @@
(let [current-file-id (get state :current-file-id)
path (if (= file-id current-file-id)
[:workspace-data]
[:workspace-libraries file-id :data])
[:libraries file-id :data])
undo-changes (if pending
(->> pending
@ -159,14 +159,14 @@
(let [file (:workspace-file state)]
(if (= (:id file) file-id)
(:revn file)
(dm/get-in state [:workspace-libraries file-id :revn]))))
(dm/get-in state [:libraries file-id :revn]))))
(defn- resolve-file-vern
[state file-id]
(let [file (:workspace-file state)]
(if (= (:id file) file-id)
(:vern file)
(dm/get-in state [:workspace-libraries file-id :vern]))))
(dm/get-in state [:libraries file-id :vern]))))
(defn commit-changes
"Schedules a list of changes to execute now, and add the corresponding undo changes to

View file

@ -52,7 +52,7 @@
(if-let [current-file-id (:current-file-id state)]
(if (= file-id current-file-id)
(update-in state [:workspace-file :revn] max revn)
(d/update-in-when state [:workspace-libraries file-id :revn] max revn))
(d/update-in-when state [:libraries file-id :revn] max revn))
state))
ptk/EffectEvent

View file

@ -172,7 +172,7 @@
(ptk/reify ::libraries-fetched
ptk/UpdateEvent
(update [_ state]
(assoc state :workspace-libraries (d/index-by :id libraries)))
(assoc state :libraries (d/index-by :id libraries)))
ptk/WatchEvent
(watch [_ state _]
@ -363,7 +363,7 @@
:workspace-data
:workspace-editor-state
:workspace-file
:workspace-libraries
:libraries
:workspace-media-objects
:workspace-persistence
:workspace-presence
@ -572,7 +572,7 @@
(let [file-data
(if (= file-id (:current-file-id state))
(:workspace-data state)
(get-in state [:workspace-libraries file-id :data]))
(get-in state [:libraries file-id :data]))
changes
(-> (pcb/empty-changes it)

View file

@ -59,11 +59,11 @@
;; Change this to :info :debug or :trace to debug this module, or :warn to reset to default
(log/set-level! :warn)
(defn- pretty-file
(defn- debug-pretty-file
[file-id state]
(if (= file-id (:current-file-id state))
"<local>"
(str "<" (get-in state [:workspace-libraries file-id :name]) ">")))
(str "<" (get-in state [:libraries file-id :name]) ">")))
(defn- log-changes
[changes file]
@ -760,9 +760,9 @@
ptk/UpdateEvent
(update [_ state]
(-> state
(update-in [:workspace-libraries library-id]
(update-in [:libraries library-id]
assoc :modified-at modified-at :revn revn)
(d/update-in-when [:workspace-libraries library-id :data]
(d/update-in-when [:libraries library-id :data]
ch/process-changes changes)))
ptk/WatchEvent
@ -898,7 +898,7 @@
current-file? (= current-file-id file-id)
data (if current-file?
(get state :workspace-data)
(get-in state [:workspace-libraries file-id :data]))
(get-in state [:libraries file-id :data]))
component (ctkl/get-component data component-id)
page-id (:main-instance-page component)
root-id (:main-instance-id component)]
@ -1022,7 +1022,7 @@
(watch [_ state _]
(let [undo-id (js/Symbol)]
(log/info :msg "COMPONENT-SWAP"
:file (pretty-file file-id state)
:file (debug-pretty-file file-id state)
:id-new-component id-new-component
:undo-id undo-id)
(rx/concat
@ -1068,15 +1068,15 @@
(update [_ state]
(if (and (not= library-id (:current-file-id state))
(nil? asset-id))
(d/assoc-in-when state [:workspace-libraries library-id :synced-at] (dt/now))
(d/assoc-in-when state [:libraries library-id :synced-at] (dt/now))
state))
ptk/WatchEvent
(watch [it state _]
(when (and (some? file-id) (some? library-id)) ; Prevent race conditions while navigating out of the file
(log/info :msg "SYNC-FILE"
:file (pretty-file file-id state)
:library (pretty-file library-id state)
:file (debug-pretty-file file-id state)
:library (debug-pretty-file library-id state)
:asset-type asset-type
:asset-id asset-id
:undo-group undo-group)
@ -1172,7 +1172,7 @@
(let [file-data (:workspace-data state)
ignore-until (dm/get-in state [:workspace-file :ignore-sync-until])
libraries-need-sync (filter #(seq (assets-need-sync % file-data ignore-until))
(vals (get state :workspace-libraries)))
(vals (get state :libraries)))
do-more-info #(modal/show! :libraries-dialog {:starting-tab "updates"})
do-update #(do (apply st/emit! (map (fn [library]
(sync-file (:current-file-id state)
@ -1359,7 +1359,7 @@
(let [libraries (:workspace-shared-files state)
library (d/seek #(= (:id %) library-id) libraries)]
(if library
(update state :workspace-libraries assoc library-id (dissoc library :library-summary))
(update state :libraries assoc library-id (dissoc library :library-summary))
state)))
ptk/WatchEvent
@ -1373,7 +1373,7 @@
(rx/merge-map fpmap/resolve-file)
(rx/map (fn [file]
(fn [state]
(assoc-in state [:workspace-libraries library-id] file)))))
(assoc-in state [:libraries library-id] file)))))
(->> (rp/cmd! :get-file-object-thumbnails {:file-id library-id :tag "component"})
(rx/map (fn [thumbnails]
(fn [state]
@ -1391,7 +1391,7 @@
ptk/UpdateEvent
(update [_ state]
(d/dissoc-in state [:workspace-libraries library-id]))
(d/dissoc-in state [:libraries library-id]))
ptk/WatchEvent
(watch [_ _ _]

View file

@ -314,6 +314,6 @@
(ptk/reify ::handle-library-change
ptk/WatchEvent
(watch [_ state _]
(when (contains? (:workspace-libraries state) file-id)
(when (contains? (:libraries state) file-id)
(rx/of (dwl/ext-library-changed file-id modified-at revn changes)
(dwl/notify-sync-file file-id))))))

View file

@ -29,7 +29,7 @@
(defn lookup-library-objects
[state file-id page-id]
(dm/get-in state [:workspace-libraries file-id :data :pages-index page-id :objects]))
(dm/get-in state [:libraries file-id :data :pages-index page-id :objects]))
(defn lookup-objects
[state file-id page-id]
@ -108,7 +108,7 @@
[state file-id]
(if (= file-id (:current-file-id state))
(get state :workspace-data)
(dm/get-in state [:workspace-libraries file-id :data])))
(dm/get-in state [:libraries file-id :data])))
(defn get-file-full
"Get the data content of the given file (it may be the current file
@ -117,13 +117,13 @@
(if (= file-id (:current-file-id state))
(-> (get state :workspace-file)
(assoc :data (get state :workspace-data)))
(dm/get-in state [:workspace-libraries file-id :data])))
(dm/get-in state [:libraries file-id :data])))
(defn get-libraries
"Retrieve all libraries, including the local file."
[state]
(let [{:keys [id] :as local} (:workspace-data state)]
(-> (:workspace-libraries state)
(-> (:libraries state)
(assoc id {:id id
:data local}))))

View file

@ -264,9 +264,6 @@
:components]))
st/state =))
(def workspace-libraries
(l/derived :workspace-libraries st/state))
(def workspace-presence
(l/derived :workspace-presence st/state))

View file

@ -39,7 +39,7 @@
mf/deref)
colors-library-ws (-> (mf/use-memo
(mf/deps (:file-id color))
#(make-colors-library-ref :workspace-libraries (:file-id color)))
#(make-colors-library-ref :libraries (:file-id color)))
mf/deref)]
(or colors-library-v colors-library-ws)))

View file

@ -59,7 +59,7 @@
file-typographies-viewer (mf/deref file-typographies-ref)
file-typographies-workspace (mf/deref refs/workspace-file-typography)
file-library-workspace (get (mf/deref refs/workspace-libraries) (:typography-ref-file style))
file-library-workspace (get (mf/deref refs/libraries) (:typography-ref-file style))
typography-external-lib (get-in file-library-workspace [:data :typographies (:typography-ref-id style)])
color-format (mf/use-state :hex)

View file

@ -7,7 +7,6 @@
(ns app.main.ui.viewer.inspect.right-sidebar
(:require-macros [app.main.style :as stl])
(:require
[app.common.data.macros :as dm]
[app.common.types.component :as ctk]
[app.main.data.event :as ev]
[app.main.refs :as refs]
@ -29,7 +28,7 @@
(if (= from :workspace)
(let [workspace-data (deref refs/workspace-data)
{:keys [id] :as local} workspace-data
libraries (deref refs/workspace-libraries)]
libraries (deref refs/libraries)]
(-> libraries
(assoc id {:id id
:data local})))
@ -54,8 +53,6 @@
file-id (or file-id (:id file))
libraries (get-libraries from)
file (mf/deref refs/viewer-file)
main-instance? (ctk/main-instance? first-shape)
handle-change-tab

View file

@ -157,7 +157,7 @@
[{:keys [size width selected] :as props}]
(let [recent-colors (mf/deref refs/workspace-recent-colors)
file-colors (mf/deref refs/workspace-file-colors)
shared-libs (mf/deref refs/workspace-libraries)
shared-libs (mf/deref refs/libraries)
colors (mf/use-state [])]
(mf/with-effect [selected shared-libs]

View file

@ -19,7 +19,7 @@
[{:keys [show-menu? close-menu on-select-palette selected]}]
(let [recent-colors (mf/deref refs/workspace-recent-colors)
file-colors (mf/deref refs/workspace-file-colors)
shared-libs (mf/deref refs/workspace-libraries)]
shared-libs (mf/deref refs/libraries)]
[:& dropdown {:show show-menu?
:on-close close-menu}
[:ul {:class (stl/css :palette-menu)}

View file

@ -30,7 +30,7 @@
(let [selected (h/use-shared-state mdc/colorpicker-selected-broadcast-key :recent)
current-colors (mf/use-state [])
shared-libs (mf/deref refs/workspace-libraries)
shared-libs (mf/deref refs/libraries)
file-colors (mf/deref refs/workspace-file-colors)
recent-colors (mf/deref refs/workspace-recent-colors)
recent-colors (h/use-equal-memo (filter #(or (:gradient %) (:color %) (:image %)) recent-colors))

View file

@ -62,7 +62,7 @@
(let [fdata (let [{:keys [id] :as wfile} (:workspace-data state)]
(if (= id library-id)
wfile
(dm/get-in state [:workspace-libraries library-id :data])))]
(dm/get-in state [:libraries library-id :data])))]
{:colors (-> fdata :colors vals)
:media (-> fdata :media vals)
:components (ctkl/components-seq fdata)
@ -557,7 +557,7 @@
file-id (:id file)
shared? (:is-shared file)
libraries (mf/deref refs/workspace-libraries)
libraries (mf/deref refs/libraries)
libraries (mf/with-memo [libraries]
(d/removem (fn [[_ val]] (:is-indirect val)) libraries))

View file

@ -31,7 +31,7 @@
::mf/props :obj
::mf/private true}
[{:keys [filters]}]
(let [libraries (mf/deref refs/workspace-libraries)
(let [libraries (mf/deref refs/libraries)
libraries (mf/with-memo [libraries]
(->> (vals libraries)
(remove :is-indirect)
@ -88,7 +88,7 @@
section (:section filters)
ordering (:ordering filters)
reverse-sort? (= :desc ordering)
num-libs (count (mf/deref refs/workspace-libraries))
num-libs (count (mf/deref refs/libraries))
toggle-ordering
(mf/use-fn

View file

@ -315,17 +315,17 @@
current-file-id (mf/use-ctx ctx/current-file-id)
objects (deref refs/workspace-page-objects)
workspace-data (deref refs/workspace-data)
workspace-libraries (deref refs/workspace-libraries)
libraries (deref refs/libraries)
current-file {:id current-file-id :data workspace-data}
find-component (fn [shape include-deleted?]
(ctf/resolve-component
shape current-file workspace-libraries {:include-deleted? include-deleted?}))
shape current-file libraries {:include-deleted? include-deleted?}))
local-or-exists (fn [shape]
(let [library-id (:component-file shape)]
(or (= library-id current-file-id)
(some? (get workspace-libraries library-id)))))
(some? (get libraries library-id)))))
restorable-copies (->> copies
(filter #(nil? (find-component % false)))

View file

@ -50,7 +50,7 @@
(if components-v2
(ctf/get-component-page data component)
component)])
(let [data (dm/get-in @refs/workspace-libraries [file-id :data])
(let [data (dm/get-in @refs/libraries [file-id :data])
root-shape (ctf/get-component-root data component)
container (if components-v2
(ctf/get-component-page data component)
@ -466,7 +466,7 @@
(fn [component event]
(let [file-data
(d/nilv (dm/get-in @refs/workspace-libraries [file-id :data]) @refs/workspace-data)
(d/nilv (dm/get-in @refs/libraries [file-id :data]) @refs/workspace-data)
shape-main
(ctf/get-component-root file-data component)]

View file

@ -78,7 +78,7 @@
[{:keys [selected objects page-id file-id selected-shapes shapes-with-children]}]
(let [sp-panel (mf/deref refs/specialized-panel)
drawing (mf/deref refs/workspace-drawing)
shared-libs (mf/deref refs/workspace-libraries)
shared-libs (mf/deref refs/libraries)
edition (mf/deref refs/selected-edition)
edit-grid? (ctl/grid-layout? objects edition)
grid-edition (mf/deref refs/workspace-grid-edition)

View file

@ -272,7 +272,7 @@
(letfn [(get-libraries [state]
(let [file (:workspace-file state)
data (:workspace-data state)
libs (:workspace-libraries state)]
libs (:libraries state)]
(assoc libs (:id file)
(assoc file :data data))))]
(l/derived get-libraries st/state)))
@ -524,7 +524,7 @@
(let [current-file-id (mf/use-ctx ctx/current-file-id)
components-v2 (mf/use-ctx ctx/components-v2)
workspace-data (deref refs/workspace-data)
workspace-libraries (deref refs/workspace-libraries)
libraries (deref refs/libraries)
state* (mf/use-state {:show-content true
:menu-open false})
@ -544,7 +544,7 @@
component (ctf/resolve-component shape
{:id current-file-id
:data workspace-data}
workspace-libraries
libraries
{:include-deleted? true})
main-instance? (if components-v2 (ctk/main-instance? shape) true)

View file

@ -184,7 +184,7 @@
(let [file-id (mf/use-ctx ctx/current-file-id)
typographies (mf/deref refs/workspace-file-typography)
shared-libs (mf/deref refs/workspace-libraries)
shared-libs (mf/deref refs/libraries)
label (case type
:multiple (tr "workspace.options.text-options.title-selection")
:group (tr "workspace.options.text-options.title-group")

View file

@ -51,7 +51,7 @@
disable-drag on-focus on-blur select-only select-on-focus]}]
(let [current-file-id (mf/use-ctx ctx/current-file-id)
file-colors (mf/deref refs/workspace-file-colors)
shared-libs (mf/deref refs/workspace-libraries)
shared-libs (mf/deref refs/libraries)
hover-detach (mf/use-state false)
on-change (h/use-ref-callback on-change)
src-colors (if (= (:file-id color) current-file-id)

View file

@ -53,7 +53,7 @@
(mf/deref refs/workspace-v2-editor-state)
(mf/deref refs/workspace-editor-state))
shared-libs (mf/deref refs/workspace-libraries)
shared-libs (mf/deref refs/libraries)
editor-state (when (not (features/active-feature? @st/state "text-editor/v2"))
(get state-map (:id shape)))

View file

@ -183,7 +183,7 @@
[{:keys [size width selected] :as props}]
(let [selected-ids (mf/deref refs/selected-shapes)
file-typographies (mf/deref refs/workspace-file-typography)
shared-libs (mf/deref refs/workspace-libraries)
shared-libs (mf/deref refs/libraries)
current-file-id (mf/use-ctx ctx/current-file-id)]
[:& palette {:current-file-id current-file-id
:selected-ids selected-ids

View file

@ -14,11 +14,10 @@
[app.util.i18n :refer [tr]]
[rumext.v2 :as mf]))
(mf/defc text-palette-ctx-menu
[{:keys [show-menu? close-menu on-select-palette selected]}]
(let [file-typographies (mf/deref refs/workspace-file-typography)
shared-libs (mf/deref refs/workspace-libraries)]
(let [typographies (mf/deref refs/workspace-file-typography)
shared-libs (mf/deref refs/libraries)]
[:& dropdown {:show show-menu?
:on-close close-menu}
[:ul {:class (stl/css :text-context-menu)}
@ -49,7 +48,7 @@
[:span {:class (stl/css :lib-name)}
(tr "workspace.libraries.colors.file-library")]
[:span {:class (stl/css :lib-num)}
(dm/str "(" (count file-typographies) ")")]]
(dm/str "(" (count typographies) ")")]]
(when (= selected :file)
[:span {:class (stl/css :icon-wrapper)}
i/tick])]]]))

View file

@ -160,7 +160,7 @@
(map #(obj/get % "$id"))
(mapcat #(cfh/get-children-with-self objects %)))
file-id (:current-file-id @st/state)
shared-libs (:workspace-libraries @st/state)]
shared-libs (:libraries @st/state)]
(->> (ctc/extract-all-colors shapes file-id shared-libs)
(group-by :attrs)
@ -182,7 +182,7 @@
:else
(let [file-id (:current-file-id @st/state)
shared-libs (:workspace-libraries @st/state)
shared-libs (:libraries @st/state)
objects (u/locate-objects)
shapes
(->> shapes

View file

@ -929,7 +929,7 @@
:connected
{:get
(fn []
(let [libraries (get @st/state :workspace-libraries)]
(let [libraries (get @st/state :libraries)]
(apply array (->> libraries keys (map (partial library-proxy plugin-id))))))}
:availableLibraries
@ -937,7 +937,7 @@
(let [team-id (:current-team-id @st/state)]
(js/Promise.
(fn [resolve reject]
(let [current-libs (into #{} (map first) (get @st/state :workspace-libraries))]
(let [current-libs (into #{} (map first) (get @st/state :libraries))]
(->> (rp/cmd! :get-team-shared-files {:team-id team-id})
(rx/map (fn [result]
(->> result

View file

@ -20,7 +20,7 @@
(if (= id (:current-file-id @st/state))
(-> (:workspace-file @st/state)
(assoc :data (:workspace-data @st/state)))
(dm/get-in @st/state [:workspace-libraries id])))
(dm/get-in @st/state [:libraries id])))
(defn locate-page
[file-id id]
@ -65,10 +65,10 @@
(defn locate-component
[objects shape]
(let [current-file-id (:current-file-id @st/state)
workspace-data (:workspace-data @st/state)
workspace-libraries (:workspace-libraries @st/state)
root (ctn/get-instance-root objects shape)]
[root (ctf/resolve-component root {:id current-file-id :data workspace-data} workspace-libraries {:include-deleted? true})]))
workspace-data (:workspace-data @st/state)
libraries (:libraries @st/state)
root (ctn/get-instance-root objects shape)]
[root (ctf/resolve-component root {:id current-file-id :data workspace-data} libraries {:include-deleted? true})]))
(defn proxy->file
[proxy]

View file

@ -248,7 +248,7 @@
(let [page-id (get state :current-page-id)
file (assoc (get state :workspace-file)
:data (get state :workspace-data))
libraries (get state :workspace-libraries)]
libraries (get state :libraries)]
(ctf/dump-tree file page-id libraries {:show-ids show-ids
:show-touched show-touched
:show-modified show-modified}))))
@ -266,7 +266,7 @@
(let [page-id (get state :current-page-id)
file (assoc (get state :workspace-file)
:data (get state :workspace-data))
libraries (get state :workspace-libraries)
libraries (get state :libraries)
shape-id (if (some? shape-id)
(uuid/uuid shape-id)
(let [objects (get-in state [:workspace-data :pages-index page-id :objects])
@ -383,7 +383,7 @@
([shape-id]
(let [file (assoc (get @st/state :workspace-file)
:data (get @st/state :workspace-data))
libraries (get @st/state :workspace-libraries)]
libraries (get @st/state :libraries)]
(try
(->> (if-let [shape-id (some-> shape-id parse-uuid)]
@ -417,7 +417,7 @@
fdata (get state :workspace-data)
file (assoc file :data fdata)
libs (get state :workspace-libraries)
libs (get state :libraries)
errors (cfv/validate-file file libs)
_ (l/dbg :hint "repair current file" :errors (count errors))