0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-03-12 07:41:43 -05:00
This commit is contained in:
Andrey Antukh 2024-12-27 11:51:13 +01:00
parent ce78471c7f
commit 2203ed13dc
16 changed files with 98 additions and 79 deletions

View file

@ -12,8 +12,8 @@
[app.common.geom.point :as gpt]
[app.common.types.shape :as cts]
[app.common.types.tokens-lib :as ctob]
[app.main.data.state-helpers :as dsh]
[app.main.data.changes :as dch]
[app.main.data.state-helpers :as dsh]
[app.main.data.workspace.shapes :as dwsh]
[app.main.refs :as refs]
[app.main.ui.workspace.tokens.token :as wtt]

View file

@ -216,23 +216,19 @@
(rx/map dwl/library-thumbnails-fetched))))))))))
(defn- workspace-initialized
[]
[file-id]
(ptk/reify ::workspace-initialized
ptk/UpdateEvent
(update [_ state]
(-> state
(assoc :workspace-undo {})
(assoc :workspace-ready true)))
(assoc :workspace-ready file-id)))
ptk/WatchEvent
(watch [_ state _]
(rx/of
(when (and (not (boolean (-> state :profile :props :v2-info-shown)))
(features/active-feature? state "components/v2"))
(modal/show :v2-info {}))
(dp/check-open-plugin)
(fdf/fix-deleted-fonts)
(fbs/fix-broken-shapes)))))
(rx/of (dp/check-open-plugin)
(fdf/fix-deleted-fonts)
(fbs/fix-broken-shapes)))))
(defn- bundle-fetched
[{:keys [features file thumbnails]}]
@ -322,8 +318,8 @@
(update [_ state]
(-> state
(dissoc :files)
(dissoc :workspace-ready)
(assoc :recent-colors (:recent-colors storage/user))
(assoc :workspace-ready false)
(assoc :current-file-id file-id)
(assoc :workspace-presence {})))
@ -345,7 +341,7 @@
(rx/map deref)
(rx/mapcat (fn [{:keys [file]}]
(rx/of (dpj/initialize-project (:project-id file))
(-> (workspace-initialized)
(-> (workspace-initialized file-id)
(with-meta {:file-id file-id}))))))
(when-let [component-id (some-> rparams :component-id parse-uuid)]

View file

@ -7,6 +7,7 @@
(ns app.main.data.workspace.fix-broken-shapes
(:require
[app.main.data.changes :as dch]
[app.main.data.state-helpers :as dsh]
[beicon.v2.core :as rx]
[potok.v2.core :as ptk]))
@ -39,12 +40,12 @@
(ptk/reify ::fix-broken-shapes
ptk/WatchEvent
(watch [it state _]
(let [data (get state :workspace-data)
(let [fdata (dsh/lookup-file-data state)
changes (concat
(mapcat (partial generate-broken-link-changes :page-id)
(vals (:pages-index data)))
(vals (:pages-index fdata)))
(mapcat (partial generate-broken-link-changes :component-id)
(vals (:components data))))]
(vals (:components fdata))))]
(if (seq changes)
(rx/of (dch/commit-changes

View file

@ -10,6 +10,7 @@
[app.common.files.helpers :as cfh]
[app.common.text :as txt]
[app.main.data.changes :as dwc]
[app.main.data.state-helpers :as dsh]
[app.main.fonts :as fonts]
[beicon.v2.core :as rx]
[potok.v2.core :as ptk]))
@ -91,7 +92,7 @@
objects))
(defn- generate-deleted-font-components-changes
[state]
[fdata]
(sequence
(comp (map val)
(filter should-fix-deleted-font-component?)
@ -99,27 +100,29 @@
{:type :mod-component
:id (:id component)
:objects (-> (fix-deleted-font-component component) :objects)})))
(dm/get-in state [:workspace-data :components])))
(:components fdata)))
(defn- generate-deleted-font-typography-changes
[state]
[fdata]
(sequence
(comp (map val)
(filter has-invalid-font-family?)
(map (fn [typography]
{:type :mod-typography
:typography (fix-deleted-font-typography typography)})))
(get-in state [:workspace-data :typographies])))
(:typographies fdata)))
(defn fix-deleted-fonts
[]
(ptk/reify ::fix-deleted-fonts
ptk/WatchEvent
(watch [it state _]
(let [data (get state :workspace-data)
shape-changes (mapcat generate-deleted-font-shape-changes (vals (:pages-index data)))
components-changes (generate-deleted-font-components-changes state)
typography-changes (generate-deleted-font-typography-changes state)
(let [fdata (dsh/lookup-file-data state)
pages (:pages-index fdata)
shape-changes (mapcat generate-deleted-font-shape-changes (vals pages))
components-changes (generate-deleted-font-components-changes fdata)
typography-changes (generate-deleted-font-typography-changes fdata)
changes (concat shape-changes
components-changes
typography-changes)]

View file

@ -26,8 +26,7 @@
(ptk/reify ::add-frame-grid
ptk/WatchEvent
(watch [_ state _]
(let [page-id (:current-page-id state)
page (dm/get-in state [:workspace-data :pages-index page-id])
(let [page (dsh/lookup-page state)
params (or (dm/get-in page [:default-grids :square])
(:square ctg/default-grid-params))
grid {:type :square

View file

@ -321,11 +321,10 @@
(ptk/reify ::start-draw-mode
ptk/UpdateEvent
(update [_ state]
(let [id (get-in state [:workspace-local :edition])
page-id (:current-page-id state)
old-content (get-in state [:workspace-data :pages-index page-id :objects id :content])]
(-> state
(assoc-in [:workspace-local :edit-path id :old-content] old-content))))
(let [id (dm/get-in state [:workspace-local :edition])
objects (dsh/lookup-page-objects state)
content (dm/get-in objects [id :content])]
(update-in state [:workspace-local :edit-path id] assoc :old-content content)))
ptk/WatchEvent
(watch [_ state stream]

View file

@ -51,22 +51,20 @@
(defn get-path-location
[state & ks]
(let [edit-id (get-in state [:workspace-local :edition])
page-id (:current-page-id state)]
(into (if edit-id
[:workspace-data :pages-index page-id :objects edit-id]
[:workspace-drawing :object])
ks)))
(if-let [edit-id (dm/get-in state [:workspace-local :edition])]
(let [page-id (:current-page-id state)
file-id (:current-file-id state)]
(into [:files file-id :data :pages-index page-id :objects edit-id] ks))
(into [:workspace-drawing :object] ks)))
(defn get-path
"Retrieves the location of the path object and additionally can pass
the arguments. This location can be used in get-in, assoc-in... functions"
[state & ks]
(let [path-loc (get-path-location state)
shape (-> (get-in state path-loc)
;; Empty map because we know the current shape will not have children
(upsp/convert-to-path {}))]
shape (-> (get-in state path-loc)
;; Empty map because we know the current shape will not have children
(upsp/convert-to-path {}))]
(if (empty? ks)
shape
(get-in shape ks))))
@ -74,5 +72,4 @@
(defn set-content
[state content]
(let [path-loc (get-path-location state :content)]
(-> state
(assoc-in path-loc content))))
(assoc-in state path-loc content)))

View file

@ -327,7 +327,8 @@
ptk/WatchEvent
(watch [_ state _]
(let [selected (dsh/lookup-selected state)
pages (-> state :workspace-data :pages-index vals)
fdata (dsh/lookup-file-data state)
pages (-> fdata :pages-index vals)
undo-id (js/Symbol)]
(rx/concat

View file

@ -53,7 +53,7 @@
(def exception
(l/derived :exception st/state))
(def threads-ref
(def threads
(l/derived :comment-threads st/state))
(def share-links

View file

@ -11,6 +11,7 @@
[app.main.data.common :as dcm]
[app.main.data.persistence :as dps]
[app.main.data.plugins :as dpl]
[app.main.data.state-helpers :as dsh]
[app.main.data.workspace :as dw]
[app.main.features :as features]
[app.main.refs :as refs]
@ -45,10 +46,8 @@
(defn- make-file-ready-ref
[file-id]
(l/derived (fn [state]
(let [data (:workspace-data state)]
(and (:workspace-ready state)
(= file-id (:current-file-id state))
(= file-id (:id data)))))
(and (= file-id (:workspace-ready state))
(some? (dsh/lookup-file-data state file-id))))
st/state))
(defn- make-page-ready-ref

View file

@ -73,7 +73,7 @@
(mf/defc comments-sidebar*
{::mf/props :obj}
[{:keys [profiles threads page-id from-viewer]}]
(let [threads-map (mf/deref refs/threads-ref)
(let [threads-map (mf/deref refs/threads)
profile (mf/deref refs/profile)
profiles' (mf/deref refs/profiles)
profiles (or profiles profiles')

View file

@ -1,17 +1,24 @@
(ns app.main.ui.workspace.tokens.token-set
(:require
[app.common.types.tokens-lib :as ctob]))
[app.common.types.tokens-lib :as ctob]
[app.main.data.state-helpers :as dsh]))
(defn get-workspace-tokens-lib [state]
(get-in state [:workspace-data :tokens-lib]))
(defn get-workspace-tokens-lib
[state]
(-> (dsh/lookup-file-data state)
(get :tokens-lib)))
;; Themes ----------------------------------------------------------------------
(defn get-active-theme-ids [state]
(get-in state [:workspace-data :token-active-themes] #{}))
(defn get-active-theme-ids
[state]
(-> (dsh/lookup-file-data state)
(get :token-active-themes #{})))
(defn get-temp-theme-id [state]
(get-in state [:workspace-data :token-theme-temporary-id]))
(defn get-temp-theme-id
[state]
(-> (dsh/lookup-file-data state)
(get :token-theme-temporary-id)))
(defn update-theme-id
[state]
@ -22,8 +29,11 @@
(= 1 (count active-themes)) (first active-themes)
:else temporary-theme-id)))
(defn get-workspace-token-theme [id state]
(get-in state [:workspace-data :token-themes-index id]))
(defn get-workspace-token-theme
[id state]
(-> (dsh/lookup-file-data state)
(get :token-themes-index)
(get id)))
(defn add-token-set-to-token-theme [token-set-id token-theme]
(update token-theme :sets conj token-set-id))

View file

@ -24,6 +24,12 @@
(assoc :frame-id (dm/get-in positions [id :frame-id])))
thread))
(defn make-positions-ref
[page-id]
(l/derived (fn [file]
(dm/get-in file [:data :pages-index page-id :comment-thread-positions]))
refs/file))
(mf/defc comments-layer
{::mf/props :obj}
[{:keys [vbox vport zoom file-id page-id drawing] :as props}]
@ -41,12 +47,10 @@
positions-ref
(mf/with-memo [page-id]
;; FIXME: use lookup helpers here
(-> (l/in [:workspace-data :pages-index page-id :comment-thread-positions])
(l/derived st/state)))
(make-positions-ref page-id))
positions (mf/deref positions-ref)
threads-map (mf/deref refs/threads-ref)
threads-map (mf/deref refs/threads)
threads
(mf/with-memo [threads-map positions local profile]

View file

@ -19,6 +19,7 @@
[app.common.uuid :as uuid]
[app.main.data.changes :as ch]
[app.main.data.common :as dcm]
[app.main.data.state-helpers :as dsh]
[app.main.data.workspace :as dw]
[app.main.data.workspace.bool :as dwb]
[app.main.data.workspace.colors :as dwc]
@ -48,15 +49,17 @@
;;
(defn create-shape
[plugin-id type]
(let [page-id (:current-page-id @st/state)
page (dm/get-in @st/state [:workspace-data :pages-index page-id])
(let [page (dsh/lookup-page @st/state)
shape (cts/setup-shape {:type type
:x 0 :y 0 :width 100 :height 100})
:x 0 :y 0
:width 100
:height 100})
changes
(-> (cb/empty-changes)
(cb/with-page page)
(cb/with-objects (:objects page))
(cb/add-object shape))]
(st/emit! (ch/commit-changes changes))
(shape/shape-proxy plugin-id (:id shape))))
@ -295,8 +298,7 @@
:createPath
(fn []
(let [page-id (:current-page-id @st/state)
page (dm/get-in @st/state [:workspace-data :pages-index page-id])
(let [page (dsh/lookup-page @st/state)
shape (cts/setup-shape
{:type :path
:content [{:command :move-to :params {:x 0 :y 0}}
@ -306,6 +308,7 @@
(cb/with-page page)
(cb/with-objects (:objects page))
(cb/add-object shape))]
(st/emit! (ch/commit-changes changes))
(shape/shape-proxy plugin-id (:id shape))))
@ -316,9 +319,7 @@
(u/display-not-valid :createText text)
:else
(let [file-id (:current-file-id @st/state)
page-id (:current-page-id @st/state)
page (dm/get-in @st/state [:workspace-data :pages-index page-id])
(let [page (dsh/lookup-page @st/state)
shape (-> (cts/setup-shape {:type :text :x 0 :y 0 :grow-type :auto-width})
(txt/change-text text)
(assoc :position-data nil))
@ -327,8 +328,9 @@
(cb/with-page page)
(cb/with-objects (:objects page))
(cb/add-object shape))]
(st/emit! (ch/commit-changes changes))
(shape/shape-proxy plugin-id file-id page-id (:id shape)))))
(shape/shape-proxy plugin-id (:id shape)))))
:createShapeFromSvg
(fn [svg-string]

View file

@ -61,13 +61,18 @@
(let [{:keys [profile-id]} (locate-presence session-id)]
(dm/get-in @st/state [:users profile-id])))
;; FIXME: the impl looks strange: objects is passed by parameters but
;; then the rest of the file is looked up directly from state.... (?)
(defn locate-component
[objects shape]
(let [current-file-id (:current-file-id @st/state)
workspace-data (:workspace-data @st/state)
libraries (:libraries @st/state)
(let [state (deref @st/state)
file (dsh/lookup-file state)
libraries (dsh/lookup-libraries state)
root (ctn/get-instance-root objects shape)]
[root (ctf/resolve-component root {:id current-file-id :data workspace-data} libraries {:include-deleted? true})]))
[root (ctf/resolve-component root file libraries {:include-deleted? true})]))
(defn proxy->file
[proxy]
@ -166,9 +171,12 @@
(defn get-state
([self attr]
(let [id (get-data self :id)
page-id (d/nilv (get-data self :page-id) (:current-page-id @st/state))]
(dm/get-in @st/state [:workspace-data :pages-index page-id :objects id attr])))
(let [id (get-data self :id)
page-id (or (get-data self :page-id)
(:current-page-id @st/state))]
(-> (dsh/lookup-page-objects @st/state page-id)
(dm/get-in [:objects id attr]))))
([self attr mapfn]
(-> (get-state self attr)
(mapfn))))

View file

@ -66,7 +66,7 @@
(t/is (= (:r1 (:applied-tokens rect-1')) (:name token))))
#_(t/testing "shape radius got update to the resolved token value."
(t/is (= (:r1 rect-1') 24))))))))))
(t/is (= (:r1 rect-1') 24))))))))))
;; (t/deftest test-apply-multiple-tokens
;; (t/testing "applying a token twice with the same attributes will override the previously applied tokens values"