mirror of
https://github.com/penpot/penpot.git
synced 2025-08-02 12:38:31 +02:00
205 lines
8 KiB
Clojure
205 lines
8 KiB
Clojure
;; This Source Code Form is subject to the terms of the Mozilla Public
|
|
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
;;
|
|
;; Copyright (c) KALEIDOS INC
|
|
|
|
(ns app.main.ui.workspace.sidebar
|
|
(:require-macros [app.main.style :refer [css]])
|
|
(:require
|
|
[app.common.data.macros :as dm]
|
|
[app.main.data.workspace :as dw]
|
|
[app.main.refs :as refs]
|
|
[app.main.store :as st]
|
|
[app.main.ui.components.tab-container :refer [tab-container tab-element]]
|
|
[app.main.ui.components.tabs-container :refer [tabs-container tabs-element]]
|
|
[app.main.ui.context :as ctx]
|
|
[app.main.ui.hooks.resize :refer [use-resize-hook]]
|
|
[app.main.ui.icons :as i]
|
|
[app.main.ui.workspace.comments :refer [comments-sidebar]]
|
|
[app.main.ui.workspace.left-header :refer [left-header]]
|
|
[app.main.ui.workspace.right-header :refer [right-header]]
|
|
[app.main.ui.workspace.sidebar.assets :refer [assets-toolbox]]
|
|
[app.main.ui.workspace.sidebar.debug :refer [debug-panel]]
|
|
[app.main.ui.workspace.sidebar.history :refer [history-toolbox]]
|
|
[app.main.ui.workspace.sidebar.layers :refer [layers-toolbox]]
|
|
[app.main.ui.workspace.sidebar.options :refer [options-toolbox]]
|
|
[app.main.ui.workspace.sidebar.shortcuts :refer [shortcuts-container]]
|
|
[app.main.ui.workspace.sidebar.sitemap :refer [sitemap]]
|
|
[app.util.dom :as dom]
|
|
[app.util.i18n :refer [tr]]
|
|
[app.util.object :as obj]
|
|
[rumext.v2 :as mf]))
|
|
|
|
;; --- Left Sidebar (Component)
|
|
|
|
(mf/defc left-sidebar
|
|
{::mf/wrap [mf/memo]
|
|
::mf/wrap-props false}
|
|
[{:keys [layout file page-id] :as props}]
|
|
(let [options-mode (mf/deref refs/options-mode-global)
|
|
mode-inspect? (= options-mode :inspect)
|
|
project (mf/deref refs/workspace-project)
|
|
|
|
section (cond (or mode-inspect? (contains? layout :layers)) :layers
|
|
(contains? layout :assets) :assets)
|
|
shortcuts? (contains? layout :shortcuts)
|
|
show-debug? (contains? layout :debug-panel)
|
|
new-css-system (mf/use-ctx ctx/new-css-system)
|
|
|
|
{:keys [on-pointer-down on-lost-pointer-capture on-pointer-move parent-ref size]}
|
|
(use-resize-hook :left-sidebar 275 275 500 :x false :left)
|
|
|
|
handle-collapse
|
|
(mf/use-fn #(st/emit! (dw/toggle-layout-flag :collapse-left-sidebar)))
|
|
|
|
on-tab-change
|
|
(mf/use-fn #(st/emit! (dw/go-to-layout %)))]
|
|
|
|
[:aside {:ref parent-ref
|
|
:id "left-sidebar-aside"
|
|
:data-size size
|
|
:class (if ^boolean new-css-system
|
|
(dom/classnames (css :left-settings-bar) true
|
|
:two-row (<= size 300)
|
|
:three-row (and (> size 300) (<= size 400))
|
|
:four-row (> size 400))
|
|
(dom/classnames :settings-bar true
|
|
:settings-bar-left true
|
|
:two-row (<= size 300)
|
|
:three-row (and (> size 300) (<= size 400))
|
|
:four-row (> size 400)))
|
|
:style #js {"--width" (dm/str size "px")}}
|
|
(when new-css-system
|
|
[:& left-header {:file file :layout layout :project project :page-id page-id}])
|
|
|
|
[:div {:on-pointer-down on-pointer-down
|
|
:on-lost-pointer-capture on-lost-pointer-capture
|
|
:on-pointer-move on-pointer-move
|
|
:class (if ^boolean new-css-system
|
|
(dom/classnames (css :resize-area) true)
|
|
(dom/classnames :resize-area true))}]
|
|
[:div {:class (if ^boolean new-css-system
|
|
(dom/classnames (css :settings-bar-inside) true)
|
|
(dom/classnames :settings-bar-inside true))}
|
|
(cond
|
|
(true? shortcuts?)
|
|
[:& shortcuts-container]
|
|
|
|
(true? show-debug?)
|
|
[:& debug-panel]
|
|
|
|
:else
|
|
(if ^boolean new-css-system
|
|
[:div {:class (dom/classnames (css :tabs-wrapper) true)}
|
|
[:& tab-container
|
|
{:on-change-tab on-tab-change
|
|
:selected section
|
|
:shortcuts? shortcuts?
|
|
:collapsable? true
|
|
:handle-collapse handle-collapse
|
|
:klass :tab-spacing}
|
|
[:& tab-element {:id :layers :title (tr "workspace.sidebar.layers")}
|
|
[:div {:class (dom/classnames (css :layers-tab) true)}
|
|
[:& sitemap {:layout layout}]
|
|
[:& layers-toolbox {:size-parent size}]]]
|
|
|
|
(when-not ^boolean mode-inspect?
|
|
[:& tab-element {:id :assets :title (tr "workspace.toolbar.assets")}
|
|
[:& assets-toolbox]])]]
|
|
|
|
[:*
|
|
[:button.collapse-sidebar
|
|
{:on-click handle-collapse
|
|
:aria-label (tr "workspace.sidebar.collapse")}
|
|
i/arrow-slide]
|
|
|
|
[:& tabs-container
|
|
{:on-change-tab on-tab-change
|
|
:selected section
|
|
:shortcuts? shortcuts?
|
|
:collapsable? true
|
|
:handle-collapse handle-collapse}
|
|
|
|
[:& tabs-element {:id :layers :title (tr "workspace.sidebar.layers")}
|
|
[:div {:class (dom/classnames :layers-tab true)}
|
|
[:& sitemap {:layout layout}]
|
|
[:& layers-toolbox {:size-parent size}]]]
|
|
|
|
(when-not ^boolean mode-inspect?
|
|
[:& tabs-element {:id :assets :title (tr "workspace.toolbar.assets")}
|
|
[:& assets-toolbox]])]]))]]))
|
|
|
|
;; --- Right Sidebar (Component)
|
|
|
|
(mf/defc right-sidebar
|
|
{::mf/wrap-props false
|
|
::mf/wrap [mf/memo]}
|
|
[{:keys [layout section file page-id ] :as props}]
|
|
(let [drawing-tool (:tool (mf/deref refs/workspace-drawing))
|
|
new-css-system (mf/use-ctx ctx/new-css-system)
|
|
|
|
is-comments? (= drawing-tool :comments)
|
|
is-history? (contains? layout :document-history)
|
|
is-inspect? (= section :inspect)
|
|
|
|
;;expanded? (mf/deref refs/inspect-expanded)
|
|
;;prev-expanded? (hooks/use-previous expanded?)
|
|
|
|
current-section* (mf/use-state :info)
|
|
current-section (deref current-section*)
|
|
|
|
can-be-expanded? (and (not is-comments?)
|
|
(not is-history?)
|
|
is-inspect?
|
|
(= current-section :code))
|
|
|
|
{:keys [on-pointer-down on-lost-pointer-capture on-pointer-move set-size size]}
|
|
(use-resize-hook :code 276 276 768 :x true :right)
|
|
|
|
handle-change-section
|
|
(mf/use-callback
|
|
(fn [section]
|
|
(reset! current-section* section)))
|
|
|
|
handle-expand
|
|
(mf/use-callback
|
|
(mf/deps size)
|
|
(fn []
|
|
(set-size (if (> size 276) 276 768))))
|
|
|
|
props
|
|
(-> props
|
|
(obj/clone)
|
|
(obj/set! "on-change-section" handle-change-section)
|
|
(obj/set! "on-expand" handle-expand))]
|
|
|
|
[:aside {:class (if ^boolean new-css-system
|
|
(dom/classnames (css :settings-bar) true
|
|
(css :right-settings-bar) true
|
|
(css :not-expand) (not can-be-expanded?)
|
|
(css :expanded) (> size 276))
|
|
(dom/classnames :settings-bar true
|
|
:settings-bar-right true
|
|
:not-expand (not can-be-expanded?)))
|
|
:id "right-sidebar-aside"
|
|
:data-size size
|
|
:style #js {"--width" (when can-be-expanded? (dm/str size "px"))}}
|
|
(when can-be-expanded?
|
|
[:div.resize-area
|
|
{:on-pointer-down on-pointer-down
|
|
:on-lost-pointer-capture on-lost-pointer-capture
|
|
:on-pointer-move on-pointer-move}])
|
|
(when new-css-system
|
|
[:& right-header {:file file :layout layout :page-id page-id}])
|
|
|
|
[:div.settings-bar-inside
|
|
(cond
|
|
(true? is-comments?)
|
|
[:& comments-sidebar]
|
|
|
|
(true? is-history?)
|
|
[:& history-toolbox]
|
|
|
|
:else
|
|
[:> options-toolbox props])]]))
|