enhance: add view action bar

This commit is contained in:
Tienson Qin
2025-02-28 18:58:20 +08:00
parent 3ba14c6051
commit d8c307bae0
5 changed files with 55 additions and 45 deletions

View File

@@ -1,7 +1,6 @@
(ns frontend.components.selection
"Block selection"
(:require [frontend.components.content :as cp-content]
[frontend.handler.editor :as editor-handler]
(:require [frontend.handler.editor :as editor-handler]
[frontend.state :as state]
[frontend.ui :as ui]
[frontend.util :as util]
@@ -9,8 +8,12 @@
[rum.core :as rum]))
(rum/defc action-bar
[]
(let [button-opts {:variant :outline
[& {:keys [on-cut on-copy selected-blocks]
:or {on-cut #(editor-handler/cut-selection-blocks true)}}]
(let [on-copy (if (and selected-blocks (nil? on-copy))
#(editor-handler/copy-selection-blocks true {:selected-blocks selected-blocks})
(or on-copy #(editor-handler/copy-selection-blocks true)))
button-opts {:variant :outline
:size :sm
:class "px-2 py-0 text-xs text-muted-foreground"}]
[:div.selection-action-bar
@@ -22,6 +25,7 @@
:on-pointer-down (fn [e]
(util/stop e)
(state/pub-event! [:editor/new-property {:target (.-target e)
:selected-blocks selected-blocks
:property-key "Tags"
:show-select-only? true
:hide-property-key? true
@@ -33,20 +37,21 @@
:on-pointer-down (fn [e]
(util/stop e)
(state/pub-event! [:editor/new-property {:target (.-target e)
:selected-blocks selected-blocks
:on-dialog-close #(state/pub-event! [:editor/hide-action-bar])}])))
"Set property")
(shui/button
(assoc button-opts
:on-pointer-down (fn [e]
(util/stop e)
(editor-handler/copy-selection-blocks true)
(on-copy)
(state/pub-event! [:editor/hide-action-bar])))
"Copy")
(shui/button
(assoc button-opts
:on-pointer-down (fn [e]
(util/stop e)
(editor-handler/cut-selection-blocks true)
(on-cut)
(state/pub-event! [:editor/hide-action-bar])))
"Cut")
(shui/button
@@ -56,7 +61,7 @@
(shui/popup-hide!)
(shui/popup-show! e
(fn []
(cp-content/custom-context-menu-content))
(state/get-component :selection/context-menu))
{:on-before-hide state/dom-clear-selection!
:on-after-hide state/state-clear-selection!
:content-props {:class "w-[280px] ls-context-menu-content"}

View File

@@ -13,6 +13,7 @@
[frontend.components.property.config :as property-config]
[frontend.components.property.value :as pv]
[frontend.components.select :as select]
[frontend.components.selection :as selection]
[frontend.config :as config]
[frontend.context.i18n :refer [t]]
[frontend.date :as date]
@@ -408,13 +409,9 @@
:class "h-8 !pl-4 !px-2 !py-0 hover:text-foreground w-full justify-start"
:disabled true}
(str (count selected-rows) " selected"))
(when (fn? on-delete-rows)
(shui/button
{:variant "ghost"
:class "h-8 !pl-0 !px-2 !py-0 text-muted-foreground hover:text-foreground w-full justify-start"
:on-click (fn []
(on-delete-rows table selected-rows))}
(ui/icon "trash")))))
(selection/action-bar
{:on-cut #(on-delete-rows table selected-rows)
:selected-blocks selected-rows})))
(rum/defc column-resizer
[_column on-sized!]

View File

@@ -5,6 +5,7 @@
[electron.ipc :as ipc]
[electron.listener :as el]
[frontend.components.block :as block]
[frontend.components.content :as cp-content]
[frontend.components.editor :as editor]
[frontend.components.page :as page]
[frontend.components.reference :as reference]
@@ -16,8 +17,8 @@
[frontend.error :as error]
[frontend.handler.command-palette :as command-palette]
[frontend.handler.events :as events]
[frontend.handler.file-based.file :as file-handler]
[frontend.handler.file-based.events]
[frontend.handler.file-based.file :as file-handler]
[frontend.handler.global-config :as global-config-handler]
[frontend.handler.notification :as notification]
[frontend.handler.page :as page-handler]
@@ -127,6 +128,7 @@
(state/set-component! :block/inline-text block/inline-text)
(state/set-component! :block/asset-cp block/asset-cp)
(state/set-component! :editor/box editor/box)
(state/set-component! :selection/context-menu cp-content/custom-context-menu-content)
(command-palette/register-global-shortcut-commands))
(defn- get-system-info

View File

@@ -947,35 +947,37 @@
result)))
(defn copy-selection-blocks
[html?]
(when-let [blocks (seq (state/get-selection-blocks))]
(let [repo (state/get-current-repo)
ids (distinct (keep #(when-let [id (dom/attr % "blockid")]
[html? & {:keys [selected-blocks]}]
(let [repo (state/get-current-repo)
blocks (seq (state/get-selection-blocks))
ids (if blocks
(distinct (keep #(when-let [id (dom/attr % "blockid")]
(uuid id)) blocks))
[top-level-block-uuids content] (compose-copied-blocks-contents repo ids)
block (db/entity [:block/uuid (first ids)])
db-based? (config/db-based-graph? repo)]
(when block
(let [html (export-html/export-blocks-as-html repo top-level-block-uuids nil)
copied-blocks (cond->> (get-all-blocks-by-ids repo top-level-block-uuids)
db-based?
(map (fn [block]
(let [b (db/entity (:db/id block))]
(->
(->> (map (fn [[k v]]
(let [v' (cond
(and (map? v) (:db/id v))
[:block/uuid (:block/uuid (db/entity (:db/id v)))]
(and (coll? v) (every? #(and (map? %) (:db/id %)) v))
(set (map (fn [i] [:block/uuid (:block/uuid (db/entity (:db/id i)))]) v))
:else
v)]
[k v'])) b)
(into {}))
(assoc :db/id (:db/id b)))))))]
(common-handler/copy-to-clipboard-without-id-property! repo (get block :block/format :markdown) content (when html? html) copied-blocks))
(state/set-block-op-type! :copy)
(notification/show! "Copied!" :success)))))
(map :block/uuid selected-blocks))
[top-level-block-uuids content] (compose-copied-blocks-contents repo ids)
block (db/entity [:block/uuid (first ids)])
db-based? (config/db-based-graph? repo)]
(when block
(let [html (export-html/export-blocks-as-html repo top-level-block-uuids nil)
copied-blocks (cond->> (get-all-blocks-by-ids repo top-level-block-uuids)
db-based?
(map (fn [block]
(let [b (db/entity (:db/id block))]
(->
(->> (map (fn [[k v]]
(let [v' (cond
(and (map? v) (:db/id v))
[:block/uuid (:block/uuid (db/entity (:db/id v)))]
(and (coll? v) (every? #(and (map? %) (:db/id %)) v))
(set (map (fn [i] [:block/uuid (:block/uuid (db/entity (:db/id i)))]) v))
:else
v)]
[k v'])) b)
(into {}))
(assoc :db/id (:db/id b)))))))]
(common-handler/copy-to-clipboard-without-id-property! repo (get block :block/format :markdown) content (when html? html) copied-blocks))
(state/set-block-op-type! :copy)
(notification/show! "Copied!" :success))))
(defn copy-block-refs
[]

View File

@@ -928,11 +928,15 @@
(when-let [blocks (and block (db-model/get-block-immediate-children (state/get-current-repo) (:block/uuid block)))]
(editor-handler/toggle-blocks-as-own-order-list! blocks)))
(defn- editor-new-property [block target opts]
(defn- editor-new-property [block target {:keys [selected-blocks] :as opts}]
(let [editing-block (state/get-edit-block)
pos (state/get-edit-pos)
edit-block-or-selected (if editing-block
edit-block-or-selected (cond
editing-block
[editing-block]
(seq selected-blocks)
selected-blocks
:else
(seq (keep #(db/entity [:block/uuid %]) (state/get-selection-block-ids))))
current-block (when-let [s (state/get-current-page)]
(when (util/uuid-string? s)