enhance(ux): right click page property to open it in the main page

or sidebar.
This commit is contained in:
Tienson Qin
2025-04-26 18:09:31 +08:00
parent 35bf1b0865
commit 8bdfb4e2e8
2 changed files with 78 additions and 51 deletions

View File

@@ -655,7 +655,8 @@
All page-names are sanitized except page-name-in-block"
[state
{:keys [contents-page? whiteboard-page? html-export? meta-click? show-unique-title? stop-click-event?]
{:keys [contents-page? whiteboard-page? html-export? other-position? show-unique-title? stop-click-event?
on-context-menu]
:or {stop-click-event? true}
:as config}
page-entity children label]
@@ -669,44 +670,50 @@
untitled? (when page-name (model/untitled-page? (:block/title page-entity)))
show-icon? (:show-icon? config)]
[:a.relative
{:tabIndex "0"
:class (cond->
(if tag? "tag" "page-ref")
(:property? config) (str " page-property-key block-property")
untitled? (str " opacity-50"))
:data-ref page-name
:draggable true
:on-drag-start (fn [e]
(editor-handler/block->data-transfer! page-name e true))
:on-mouse-over #(reset! *hover? true)
:on-mouse-leave #(reset! *hover? false)
:on-click (fn [e]
(when stop-click-event? (util/stop e)))
:on-pointer-down (fn [^js e]
(cond
(and meta-click? (util/meta-key? e))
(reset! *mouse-down? true)
(cond->
{:tabIndex "0"
:class (cond->
(if tag? "tag" "page-ref")
(:property? config) (str " page-property-key block-property")
untitled? (str " opacity-50"))
:data-ref page-name
:draggable true
:on-drag-start (fn [e]
(editor-handler/block->data-transfer! page-name e true))
:on-mouse-over #(reset! *hover? true)
:on-mouse-leave #(reset! *hover? false)
:on-click (fn [e]
(when stop-click-event? (util/stop e)))
:on-pointer-down (fn [^js e]
(cond
(and on-context-menu (= 2 (.-button e)))
nil
(and meta-click? (not (util/shift-key? e)))
(some-> (.-target e) (.closest ".jtrigger") (.click))
(and other-position? (util/meta-key? e))
(reset! *mouse-down? true)
breadcrumb?
(.preventDefault e)
(and other-position? (not (util/shift-key? e)))
(some-> (.-target e) (.closest ".jtrigger") (.click))
:else
(do
(.preventDefault e)
(reset! *mouse-down? true))))
:on-pointer-up (fn [e]
(when @*mouse-down?
(state/clear-edit!)
(when-not (or (:disable-click? config)
(:disable-redirect? config))
(open-page-ref config page-entity e page-name contents-page?))
(reset! *mouse-down? false)))
:on-key-up (fn [e] (when (and e (= (.-key e) "Enter") (not meta-click?))
(state/clear-edit!)
(open-page-ref config page-entity e page-name contents-page?)))}
breadcrumb?
(.preventDefault e)
:else
(do
(.preventDefault e)
(reset! *mouse-down? true))))
:on-pointer-up (fn [e]
(when @*mouse-down?
(state/clear-edit!)
(when-not (or (:disable-click? config)
(:disable-redirect? config))
(open-page-ref config page-entity e page-name contents-page?))
(reset! *mouse-down? false)))
:on-key-up (fn [e] (when (and e (= (.-key e) "Enter") (not other-position?))
(state/clear-edit!)
(open-page-ref config page-entity e page-name contents-page?)))}
on-context-menu
(assoc :on-context-menu on-context-menu))
(when (and show-icon? (not tag?))
(let [own-icon (get page-entity (pu/get-pid :logseq.property/icon))
emoji? (and (map? own-icon) (= (:type own-icon) :emoji))]
@@ -2701,7 +2708,7 @@
(shui/dropdown-menu-item
{:key "Open tag in sidebar"
:on-click #(state/sidebar-add-block! (state/get-current-repo) (:db/id tag) :page)}
"Open tag in sidebar"
"Open in sidebar"
(shui/dropdown-menu-shortcut (shortcut-utils/decorate-binding "shift+click")))
(shui/dropdown-menu-item
{:key "Remove tag"

View File

@@ -1061,7 +1061,7 @@
(inline-text {} :markdown (str value'))))))
(rum/defc select-item
[property type value {:keys [page-cp inline-text other-position? property-position table-view? _icon?] :as opts}]
[property type value {:keys [page-cp inline-text other-position? property-position table-view? show-popup! _icon?] :as opts}]
(let [closed-values? (seq (:property/closed-values property))
tag? (or (:tag? opts) (= (:db/ident property) :block/tags))
inline-text-cp (fn [content]
@@ -1081,14 +1081,31 @@
;; support this case and maybe other complex cases.
(not (string/includes? (:block/title value) "[["))))
(when value
(rum/with-key
(page-cp {:disable-preview? true
(let [opts {:disable-preview? true
:tag? tag?
:property-position property-position
:meta-click? other-position?
:other-position? other-position?
:table-view? table-view?
:ignore-alias? (= :block/alias (:db/ident property))} value)
(:db/id value)))
:ignore-alias? (= :block/alias (:db/ident property))
:on-context-menu
(fn [e]
(util/stop e)
(shui/popup-show! (.-target e)
(fn []
[:<>
(shui/dropdown-menu-item
{:key "open"
:on-click #(route-handler/redirect-to-page! (:block/uuid value))}
(str "Open " (:block/title value)))
(shui/dropdown-menu-item
{:key "open sidebar"
:on-click #(state/sidebar-add-block! (state/get-current-repo) (:db/id value) :page)}
"Open in sidebar")])
{:as-dropdown? true
:content-props {:on-click (fn [] (shui/popup-hide!))}
:align "start"}))}]
(rum/with-key (page-cp opts value) (:db/id value))))
(contains? #{:node :class :property :page} type)
(when-let [reference (state/get-component :block/reference)]
@@ -1342,16 +1359,17 @@
(select-cp {})
(let [toggle-fn shui/popup-hide!
content-fn (fn [{:keys [_id content-props]}]
(select-cp {:content-props content-props}))]
(select-cp {:content-props content-props}))
show-popup! (fn [^js e]
(let [target (.-target e)]
(when-not (or (util/link? target) (.closest target "a") config/publishing?)
(shui/popup-show! (rum/deref *el) content-fn
{:as-dropdown? true :as-content? false
:align "start" :auto-focus? true}))))]
[:div.multi-values.jtrigger
{:tab-index "0"
:ref *el
:on-click (fn [^js e]
(let [target (.-target e)]
(when-not (or (util/link? target) (.closest target "a") config/publishing?)
(shui/popup-show! (rum/deref *el) content-fn
{:as-dropdown? true :as-content? false
:align "start" :auto-focus? true}))))
:on-click show-popup!
:on-key-down (fn [^js e]
(case (.-key e)
(" " "Enter")
@@ -1365,7 +1383,9 @@
(if (and (seq items) not-empty-value?)
(concat
(->> (for [item items]
(rum/with-key (select-item property type item opts) (or (:block/uuid item) (str item))))
(rum/with-key
(select-item property type item (assoc opts :show-popup! show-popup!))
(or (:block/uuid item) (str item))))
(interpose [:span.opacity-50.-ml-1 ","]))
(when date?
[(property-value-date-picker block property nil {:toggle-fn toggle-fn})]))