mirror of
https://github.com/penpot/penpot.git
synced 2025-05-13 02:56:38 +02:00
✨ Assets groups review
This commit is contained in:
parent
b03492e187
commit
fe36a9e958
9 changed files with 89 additions and 11 deletions
|
@ -281,3 +281,50 @@
|
||||||
{:id (:id file)})
|
{:id (:id file)})
|
||||||
|
|
||||||
(files/persist-pointers! h/*conn* (:id file)))))))
|
(files/persist-pointers! h/*conn* (:id file)))))))
|
||||||
|
|
||||||
|
(defn fix-main-shape-name
|
||||||
|
([file]
|
||||||
|
(prn (str "Updating " (:name file) " " (:id file)))
|
||||||
|
(if-not (contains? (:features file) "components/v2")
|
||||||
|
(do
|
||||||
|
(prn " This file is not v2")
|
||||||
|
file)
|
||||||
|
(let [libs (->> (files/get-file-libraries h/*conn* (:id file))
|
||||||
|
(cons file)
|
||||||
|
(map #(files/get-file h/*conn* (:id %) (:features file)))
|
||||||
|
(d/index-by :id))
|
||||||
|
|
||||||
|
update-shape
|
||||||
|
(fn [shape]
|
||||||
|
(if-not (ctk/instance-head? shape)
|
||||||
|
shape
|
||||||
|
(let [component (ctf/get-component libs (:component-file shape) (:component-id shape) {:include-deleted? true})
|
||||||
|
[_path name] (cph/parse-path-name (:name shape))
|
||||||
|
full-name (cph/clean-path (str (:path component) "/" (:name component)))]
|
||||||
|
(if (= name (:name component))
|
||||||
|
(assoc shape :name full-name)
|
||||||
|
shape))))
|
||||||
|
|
||||||
|
|
||||||
|
update-page
|
||||||
|
(fn [page]
|
||||||
|
(prn (str "Page " (:name page)))
|
||||||
|
(h/update-shapes page update-shape))]
|
||||||
|
|
||||||
|
(-> file
|
||||||
|
(update :data h/update-pages update-page)
|
||||||
|
(assoc ::updated true)))))
|
||||||
|
|
||||||
|
([file save?]
|
||||||
|
(let [file (-> file
|
||||||
|
(update :data blob/decode)
|
||||||
|
(fix-main-shape-name))]
|
||||||
|
(when (and save? (::updated file))
|
||||||
|
(let [data (blob/encode (:data file))]
|
||||||
|
(db/update! h/*conn* :file
|
||||||
|
{:data data
|
||||||
|
;; :revn (:revn file)
|
||||||
|
}
|
||||||
|
{:id (:id file)})
|
||||||
|
|
||||||
|
(files/persist-pointers! h/*conn* (:id file)))))))
|
||||||
|
|
|
@ -467,6 +467,12 @@
|
||||||
[path-vec]
|
[path-vec]
|
||||||
(str/join " / " path-vec))
|
(str/join " / " path-vec))
|
||||||
|
|
||||||
|
(defn clean-path
|
||||||
|
"Remove empty items from the path."
|
||||||
|
[path]
|
||||||
|
(->> (split-path path)
|
||||||
|
(join-path)))
|
||||||
|
|
||||||
(defn parse-path-name
|
(defn parse-path-name
|
||||||
"Parse a string in the form 'group / subgroup / name'.
|
"Parse a string in the form 'group / subgroup / name'.
|
||||||
Retrieve the path and the name in separated values, normalizing spaces."
|
Retrieve the path and the name in separated values, normalizing spaces."
|
||||||
|
|
|
@ -268,6 +268,9 @@ span.element-name {
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
flex: 1;
|
flex: 1;
|
||||||
|
&.left-ellipsis {
|
||||||
|
direction: rtl; // hack for getting the ellipsis on the left side
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.element-actions {
|
.element-actions {
|
||||||
|
|
|
@ -657,7 +657,8 @@
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state _]
|
(watch [_ state _]
|
||||||
(when-let [shape-id (dm/get-in state [:workspace-local :shape-for-rename])]
|
(when-let [shape-id (dm/get-in state [:workspace-local :shape-for-rename])]
|
||||||
(let [shape (wsh/lookup-shape state shape-id)]
|
(let [shape (wsh/lookup-shape state shape-id)
|
||||||
|
name (cph/clean-path name)]
|
||||||
(rx/concat
|
(rx/concat
|
||||||
;; Remove rename state from workspace local state
|
;; Remove rename state from workspace local state
|
||||||
(rx/of #(update % :workspace-local dissoc :shape-for-rename))
|
(rx/of #(update % :workspace-local dissoc :shape-for-rename))
|
||||||
|
|
|
@ -383,7 +383,8 @@
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state _]
|
(watch [_ state _]
|
||||||
(when-let [component (dm/get-in state [:workspace-data :components component-id])]
|
(when-let [component (dm/get-in state [:workspace-data :components component-id])]
|
||||||
(let [shape-id (:main-instance-id component)
|
(let [name (cph/clean-path name)
|
||||||
|
shape-id (:main-instance-id component)
|
||||||
page-id (:main-instance-page component)]
|
page-id (:main-instance-page component)]
|
||||||
(rx/concat
|
(rx/concat
|
||||||
(rx/of (rename-component component-id name))
|
(rx/of (rename-component component-id name))
|
||||||
|
|
|
@ -7,9 +7,12 @@
|
||||||
(ns app.main.ui.viewer.inspect.left-sidebar
|
(ns app.main.ui.viewer.inspect.left-sidebar
|
||||||
(:require
|
(:require
|
||||||
[app.common.data :as d]
|
[app.common.data :as d]
|
||||||
|
[app.common.data.macros :as dm]
|
||||||
[app.common.pages.helpers :as cph]
|
[app.common.pages.helpers :as cph]
|
||||||
|
[app.common.types.component :as ctk]
|
||||||
[app.common.types.shape.layout :as ctl]
|
[app.common.types.shape.layout :as ctl]
|
||||||
[app.main.data.viewer :as dv]
|
[app.main.data.viewer :as dv]
|
||||||
|
[app.main.refs :as refs]
|
||||||
[app.main.store :as st]
|
[app.main.store :as st]
|
||||||
[app.main.ui.components.shape-icon :as si]
|
[app.main.ui.components.shape-icon :as si]
|
||||||
[app.main.ui.icons :as i]
|
[app.main.ui.icons :as i]
|
||||||
|
@ -33,7 +36,11 @@
|
||||||
selected? (contains? selected id)
|
selected? (contains? selected id)
|
||||||
item-ref (mf/use-ref nil)
|
item-ref (mf/use-ref nil)
|
||||||
|
|
||||||
|
file (mf/deref refs/viewer-file)
|
||||||
|
components-v2 (dm/get-in file [:data :options :components-v2])
|
||||||
|
main-instance? (if components-v2
|
||||||
|
(ctk/main-instance? item)
|
||||||
|
true)
|
||||||
collapsed-iref (mf/use-memo
|
collapsed-iref (mf/use-memo
|
||||||
(mf/deps id)
|
(mf/deps id)
|
||||||
(make-collapsed-iref id))
|
(make-collapsed-iref id))
|
||||||
|
@ -77,7 +84,7 @@
|
||||||
[:div.icon
|
[:div.icon
|
||||||
(when absolute?
|
(when absolute?
|
||||||
[:div.absolute i/position-absolute])
|
[:div.absolute i/position-absolute])
|
||||||
[:& si/element-icon {:shape item}]]
|
[:& si/element-icon {:shape item :main-instance? main-instance?}]]
|
||||||
[:& layer-name {:shape-id id
|
[:& layer-name {:shape-id id
|
||||||
:shape-name name
|
:shape-name name
|
||||||
:shape-touched? touched?
|
:shape-touched? touched?
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
|
|
||||||
(ns app.main.ui.viewer.inspect.right-sidebar
|
(ns app.main.ui.viewer.inspect.right-sidebar
|
||||||
(:require
|
(:require
|
||||||
|
[app.common.data.macros :as dm]
|
||||||
|
[app.common.types.component :as ctk]
|
||||||
[app.main.refs :as refs]
|
[app.main.refs :as refs]
|
||||||
[app.main.ui.components.shape-icon :as si]
|
[app.main.ui.components.shape-icon :as si]
|
||||||
[app.main.ui.components.tabs-container :refer [tabs-container tabs-element]]
|
[app.main.ui.components.tabs-container :refer [tabs-container tabs-element]]
|
||||||
|
@ -48,6 +50,12 @@
|
||||||
|
|
||||||
libraries (get-libraries from)
|
libraries (get-libraries from)
|
||||||
|
|
||||||
|
file (mf/deref refs/viewer-file)
|
||||||
|
components-v2 (dm/get-in file [:data :options :components-v2])
|
||||||
|
main-instance? (if components-v2
|
||||||
|
(ctk/main-instance? first-shape)
|
||||||
|
true)
|
||||||
|
|
||||||
handle-change-tab
|
handle-change-tab
|
||||||
(mf/use-callback
|
(mf/use-callback
|
||||||
(mf/deps from on-change-section)
|
(mf/deps from on-change-section)
|
||||||
|
@ -79,7 +87,7 @@
|
||||||
[:span.tool-window-bar-title (tr "inspect.tabs.code.selected.multiple" (count shapes))]]
|
[:span.tool-window-bar-title (tr "inspect.tabs.code.selected.multiple" (count shapes))]]
|
||||||
[:*
|
[:*
|
||||||
[:span.tool-window-bar-icon
|
[:span.tool-window-bar-icon
|
||||||
[:& si/element-icon {:shape first-shape}]]
|
[:& si/element-icon {:shape first-shape :main-instance? main-instance?}]]
|
||||||
;; Execution time translation strings:
|
;; Execution time translation strings:
|
||||||
;; inspect.tabs.code.selected.circle
|
;; inspect.tabs.code.selected.circle
|
||||||
;; inspect.tabs.code.selected.component
|
;; inspect.tabs.code.selected.component
|
||||||
|
|
|
@ -98,7 +98,7 @@
|
||||||
(mf/deps component dragging* selected selected-full selected-paths)
|
(mf/deps component dragging* selected selected-full selected-paths)
|
||||||
(fn [event]
|
(fn [event]
|
||||||
(cmm/on-drop-asset event component dragging* selected selected-full
|
(cmm/on-drop-asset event component dragging* selected selected-full
|
||||||
selected-paths dwl/rename-component)))
|
selected-paths dwl/rename-component-and-main-instance)))
|
||||||
|
|
||||||
on-drag-enter
|
on-drag-enter
|
||||||
(mf/use-fn
|
(mf/use-fn
|
||||||
|
@ -236,7 +236,7 @@
|
||||||
(mf/use-fn
|
(mf/use-fn
|
||||||
(mf/deps dragging* prefix selected-paths selected-full)
|
(mf/deps dragging* prefix selected-paths selected-full)
|
||||||
(fn [event]
|
(fn [event]
|
||||||
(cmm/on-drop-asset-group event dragging* prefix selected-paths selected-full dwl/rename-component)))]
|
(cmm/on-drop-asset-group event dragging* prefix selected-paths selected-full dwl/rename-component-and-main-instance)))]
|
||||||
|
|
||||||
(if ^boolean new-css-system
|
(if ^boolean new-css-system
|
||||||
[:div {:class (dom/classnames (css :component-group) true)
|
[:div {:class (dom/classnames (css :component-group) true)
|
||||||
|
@ -504,7 +504,7 @@
|
||||||
(filter #(if multi-components?
|
(filter #(if multi-components?
|
||||||
(contains? selected (:id %))
|
(contains? selected (:id %))
|
||||||
(= current-component-id (:id %))))
|
(= current-component-id (:id %))))
|
||||||
(map #(dwl/rename-component
|
(map #(dwl/rename-component-and-main-instance
|
||||||
(:id %)
|
(:id %)
|
||||||
(cmm/add-group % group-name)))))
|
(cmm/add-group % group-name)))))
|
||||||
(st/emit! (dwu/commit-undo-transaction undo-id)))))
|
(st/emit! (dwu/commit-undo-transaction undo-id)))))
|
||||||
|
@ -519,7 +519,7 @@
|
||||||
(run! st/emit!
|
(run! st/emit!
|
||||||
(->> components
|
(->> components
|
||||||
(filter #(str/starts-with? (:path %) path))
|
(filter #(str/starts-with? (:path %) path))
|
||||||
(map #(dwl/rename-component
|
(map #(dwl/rename-component-and-main-instance
|
||||||
(:id %)
|
(:id %)
|
||||||
(cmm/rename-group % path last-path)))))
|
(cmm/rename-group % path last-path)))))
|
||||||
(st/emit! (dwu/commit-undo-transaction undo-id)))))
|
(st/emit! (dwu/commit-undo-transaction undo-id)))))
|
||||||
|
@ -550,7 +550,7 @@
|
||||||
(run! st/emit!
|
(run! st/emit!
|
||||||
(->> components
|
(->> components
|
||||||
(filter #(str/starts-with? (:path %) path))
|
(filter #(str/starts-with? (:path %) path))
|
||||||
(map #(dwl/rename-component (:id %) (cmm/ungroup % path)))))
|
(map #(dwl/rename-component-and-main-instance (:id %) (cmm/ungroup % path)))))
|
||||||
(st/emit! (dwu/commit-undo-transaction undo-id)))))
|
(st/emit! (dwu/commit-undo-transaction undo-id)))))
|
||||||
|
|
||||||
on-drag-start
|
on-drag-start
|
||||||
|
|
|
@ -39,6 +39,8 @@
|
||||||
shape-for-rename (mf/deref lens:shape-for-rename)
|
shape-for-rename (mf/deref lens:shape-for-rename)
|
||||||
new-css-system (mf/use-ctx ctx/new-css-system)
|
new-css-system (mf/use-ctx ctx/new-css-system)
|
||||||
|
|
||||||
|
has-path? (str/includes? shape-name "/")
|
||||||
|
|
||||||
start-edit
|
start-edit
|
||||||
(mf/use-fn
|
(mf/use-fn
|
||||||
(mf/deps disabled-double-click on-start-edit shape-id)
|
(mf/deps disabled-double-click on-start-edit shape-id)
|
||||||
|
@ -99,11 +101,14 @@
|
||||||
{:class (if ^boolean new-css-system
|
{:class (if ^boolean new-css-system
|
||||||
(stl/css-case
|
(stl/css-case
|
||||||
:element-name true
|
:element-name true
|
||||||
|
:left-ellipsis has-path?
|
||||||
:selected selected?
|
:selected selected?
|
||||||
:hidden hidden?
|
:hidden hidden?
|
||||||
:type-comp type-comp
|
:type-comp type-comp
|
||||||
:type-frame type-frame)
|
:type-frame type-frame)
|
||||||
(stl/css* :element-name))
|
(stl/css-case
|
||||||
|
"element-name" true
|
||||||
|
:left-ellipsis has-path?))
|
||||||
:style {"--depth" depth "--parent-size" parent-size}
|
:style {"--depth" depth "--parent-size" parent-size}
|
||||||
:ref ref
|
:ref ref
|
||||||
:on-double-click start-edit}
|
:on-double-click start-edit}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue