mirror of
https://github.com/penpot/penpot.git
synced 2025-03-11 23:31:21 -05:00
WIP
This commit is contained in:
parent
2203ed13dc
commit
1a05cd0238
11 changed files with 43 additions and 54 deletions
|
@ -86,12 +86,6 @@
|
|||
(apply-token-to-shape props)
|
||||
shape))
|
||||
|
||||
;; FIXME: this should never be here
|
||||
(defn get-token-data-from-token-id
|
||||
[id]
|
||||
(let [workspace-data (deref refs/workspace-data)]
|
||||
(get (:tokens workspace-data) id)))
|
||||
|
||||
(defn set-selected-token-set-id
|
||||
[id]
|
||||
(ptk/reify ::set-selected-token-set-id
|
||||
|
|
|
@ -78,10 +78,6 @@
|
|||
(get files file-id)))
|
||||
st/state))
|
||||
|
||||
;; (def workspace-file
|
||||
;; "A workspace specific file instance that does not holds the data"
|
||||
;; (l/derived (l/key :workspace-file) st/state))
|
||||
|
||||
(def shared-files
|
||||
"A derived state that points to the current list of shared
|
||||
files (without the content, only summary)"
|
||||
|
@ -231,10 +227,8 @@
|
|||
(l/derived #(contains? % :rulers) workspace-layout))
|
||||
|
||||
(def workspace-data
|
||||
(l/derived (fn [state]
|
||||
(let [file-id (:current-file-id state)]
|
||||
(dm/get-in state [:files file-id :data])))
|
||||
st/state))
|
||||
"Currently working file data on workspace"
|
||||
(l/derived dsh/lookup-file-data st/state))
|
||||
|
||||
(def workspace-file-colors
|
||||
(l/derived (fn [{:keys [id] :as data}]
|
||||
|
@ -261,13 +255,9 @@
|
|||
(def workspace-presence
|
||||
(l/derived :workspace-presence st/state))
|
||||
|
||||
;; FIXME: revisit the usage of this ref
|
||||
(def workspace-page
|
||||
(l/derived (fn [state]
|
||||
(let [page-id (:current-page-id state)
|
||||
file-id (:current-file-id state)]
|
||||
(dm/get-in state [:files file-id :pages-index page-id])))
|
||||
st/state))
|
||||
"Ref to currently active page on workspace"
|
||||
(l/derived dsh/lookup-page st/state))
|
||||
|
||||
(def workspace-page-flows
|
||||
(l/derived #(-> % :flows not-empty) workspace-page))
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
[app.common.types.file :as ctf]
|
||||
[app.config :as cf]
|
||||
[app.main.data.modal :as modal]
|
||||
[app.main.data.state-helpers :as dsh]
|
||||
[app.main.data.workspace :as dw]
|
||||
[app.main.data.workspace.libraries :as dwl]
|
||||
[app.main.data.workspace.undo :as dwu]
|
||||
|
@ -313,10 +314,13 @@
|
|||
copies (filter ctk/in-component-copy? shapes)
|
||||
|
||||
current-file-id (mf/use-ctx ctx/current-file-id)
|
||||
objects (deref refs/workspace-page-objects)
|
||||
workspace-data (deref refs/workspace-data)
|
||||
current-page-id (mf/use-ctx ctx/current-page-id)
|
||||
|
||||
libraries (deref refs/libraries)
|
||||
current-file {:id current-file-id :data workspace-data}
|
||||
current-file (get libraries current-file-id)
|
||||
|
||||
objects (-> (dsh/get-page (:data current-file) current-page-id)
|
||||
(get :objects))
|
||||
|
||||
find-component (fn [shape include-deleted?]
|
||||
(ctf/resolve-component
|
||||
|
|
|
@ -457,7 +457,7 @@
|
|||
(fn [component event]
|
||||
|
||||
(let [file-data
|
||||
(d/nilv (dm/get-in @refs/libraries [file-id :data]) @refs/workspace-data)
|
||||
(dm/get-in @refs/libraries [file-id :data])
|
||||
|
||||
shape-main
|
||||
(ctf/get-component-root file-data component)]
|
||||
|
|
|
@ -169,11 +169,12 @@
|
|||
(defn use-search
|
||||
[page objects]
|
||||
(let [state* (mf/use-state
|
||||
{:show-search false
|
||||
:show-menu false
|
||||
:search-text ""
|
||||
:filters #{}
|
||||
:num-items 100})
|
||||
#(do {:show-search false
|
||||
:show-menu false
|
||||
:search-text ""
|
||||
:filters #{}
|
||||
:num-items 100}))
|
||||
|
||||
state (deref state*)
|
||||
current-filters (:filters state)
|
||||
current-items (:num-items state)
|
||||
|
|
|
@ -512,12 +512,13 @@
|
|||
{::mf/props :obj}
|
||||
[{:keys [shapes swap-opened?]}]
|
||||
(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)
|
||||
libraries (deref refs/libraries)
|
||||
|
||||
state* (mf/use-state {:show-content true
|
||||
:menu-open false})
|
||||
libraries (deref refs/libraries)
|
||||
current-file (get libraries current-file-id)
|
||||
|
||||
state* (mf/use-state
|
||||
#(do {:show-content true
|
||||
:menu-open false}))
|
||||
state (deref state*)
|
||||
open? (:show-content state)
|
||||
menu-open? (:menu-open state)
|
||||
|
@ -525,18 +526,18 @@
|
|||
shapes (filter ctk/instance-head? shapes)
|
||||
multi (> (count shapes) 1)
|
||||
copies (filter ctk/in-component-copy? shapes)
|
||||
can-swap? (and components-v2 (seq copies))
|
||||
can-swap? (boolean (seq copies))
|
||||
|
||||
;; For when it's only one shape
|
||||
shape (first shapes)
|
||||
id (:id shape)
|
||||
shape-name (:name shape)
|
||||
|
||||
component (ctf/resolve-component shape
|
||||
{:id current-file-id
|
||||
:data workspace-data}
|
||||
current-file
|
||||
libraries
|
||||
{:include-deleted? true})
|
||||
main-instance? (if components-v2 (ctk/main-instance? shape) true)
|
||||
main-instance? (ctk/main-instance? shape)
|
||||
|
||||
toggle-content
|
||||
(mf/use-fn #(swap! state* update :show-content not))
|
||||
|
@ -575,7 +576,7 @@
|
|||
(fn []
|
||||
(swap! state* update :render inc)))
|
||||
|
||||
menu-entries (cmm/generate-components-menu-entries shapes components-v2)
|
||||
menu-entries (cmm/generate-components-menu-entries shapes true)
|
||||
show-menu? (seq menu-entries)
|
||||
path (->> component (:path) (cfh/split-path) (cfh/join-path-with-dot))]
|
||||
|
||||
|
@ -640,7 +641,7 @@
|
|||
(when swap-opened?
|
||||
[:& component-swap {:shapes copies}])
|
||||
|
||||
(when (and (not swap-opened?) (not multi) components-v2)
|
||||
(when (and (not swap-opened?) (not multi))
|
||||
[:& component-annotation {:id id :shape shape :component component :rerender-fn rerender-fn}])
|
||||
(when (dbg/enabled? :display-touched)
|
||||
[:div ":touched " (str (:touched shape))])])])))
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
[okulary.core :as l]
|
||||
[rumext.v2 :as mf]))
|
||||
|
||||
(def lens:background-color
|
||||
(def ^:private ref:background-color
|
||||
(-> (l/key :background)
|
||||
(l/derived refs/workspace-page)))
|
||||
|
||||
|
@ -28,7 +28,7 @@
|
|||
{::mf/wrap [mf/memo]
|
||||
::mf/wrap-props false}
|
||||
[]
|
||||
(let [background (mf/deref lens:background-color)
|
||||
(let [background (mf/deref ref:background-color)
|
||||
on-change (mf/use-fn #(st/emit! (dw/change-canvas-color %)))
|
||||
on-open (mf/use-fn #(st/emit! (dwu/start-undo-transaction :options)))
|
||||
on-close (mf/use-fn #(st/emit! (dwu/commit-undo-transaction :options)))]
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
[app.common.data.macros :as dm]
|
||||
[app.main.data.common :as dcm]
|
||||
[app.main.data.modal :as modal]
|
||||
[app.main.data.state-helpers :as dsh]
|
||||
[app.main.data.workspace :as dw]
|
||||
[app.main.refs :as refs]
|
||||
[app.main.store :as st]
|
||||
|
@ -44,9 +45,9 @@
|
|||
without including the page objects (mainly for avoid rerender on
|
||||
each object change)"
|
||||
[page-id]
|
||||
(l/derived (fn [data]
|
||||
(let [page (dm/get-in data [:pages-index page-id])]
|
||||
(dissoc page :objects)))
|
||||
(l/derived (fn [fdata]
|
||||
(-> (dsh/get-page fdata page-id)
|
||||
(dissoc :objects)))
|
||||
refs/workspace-data
|
||||
=))
|
||||
|
||||
|
|
|
@ -568,6 +568,7 @@
|
|||
[:> guides/viewport-guides*
|
||||
{:zoom zoom
|
||||
:vbox vbox
|
||||
:guides (:guides page)
|
||||
:hover-frame guide-frame
|
||||
:disabled-guides disabled-guides?
|
||||
:modifiers modifiers}])
|
||||
|
|
|
@ -448,18 +448,14 @@
|
|||
:is-hover true
|
||||
:hover-frame frame}])]))
|
||||
|
||||
(def ^:private lens:workspace-guides
|
||||
(-> (l/key :guides)
|
||||
(l/derived refs/workspace-page)))
|
||||
|
||||
(mf/defc viewport-guides*
|
||||
{::mf/wrap [mf/memo]
|
||||
::mf/props :obj}
|
||||
[{:keys [zoom vbox hover-frame disabled-guides modifiers]}]
|
||||
(let [guides (mf/deref lens:workspace-guides)
|
||||
guides (mf/with-memo [guides vbox]
|
||||
(->> (vals guides)
|
||||
(filter (partial guide-inside-vbox? zoom vbox))))
|
||||
[{:keys [zoom vbox hover-frame disabled-guides modifiers guides]}]
|
||||
(let [guides
|
||||
(mf/with-memo [guides vbox]
|
||||
(->> (vals guides)
|
||||
(filter (partial guide-inside-vbox? zoom vbox))))
|
||||
|
||||
focus (mf/deref refs/workspace-focus-selected)
|
||||
|
||||
|
|
|
@ -568,6 +568,7 @@
|
|||
[:> guides/viewport-guides*
|
||||
{:zoom zoom
|
||||
:vbox vbox
|
||||
:guides (:guides page)
|
||||
:hover-frame guide-frame
|
||||
:disabled-guides disabled-guides?
|
||||
:modifiers modifiers}])
|
||||
|
|
Loading…
Add table
Reference in a new issue