enhance: property editing support shortcut

experiment/tanstack-table
Tienson Qin 2024-05-27 20:08:43 +08:00
parent 7f010697a0
commit 6ced3bff8f
5 changed files with 35 additions and 5 deletions

View File

@ -551,3 +551,9 @@
(d/pull-many db
'[:db/id :block/name :block/original-name]
ids)))))
(defn get-all-properties
[db]
(->> (d/datoms db :avet :block/type "property")
(map (fn [d]
(d/entity db (:e d))))))

View File

@ -34,6 +34,7 @@
[frontend.handler.user :as user-handler]
[frontend.handler.whiteboard :as whiteboard-handler]
[frontend.handler.recent :as recent-handler]
[frontend.handler.db-based.property :as db-property-handler]
[frontend.mixins :as mixins]
[frontend.mobile.action-bar :as action-bar]
[frontend.mobile.footer :as footer]
@ -875,7 +876,7 @@
[]
nil)
(rum/defcs ^:large-vars/cleanup-todo sidebar <
(rum/defcs ^:large-vars/cleanup-todo root-container <
(mixins/modal :modal/show?)
rum/reactive
(mixins/event-mixin
@ -883,7 +884,8 @@
(mixins/listen state js/window "pointerdown" hide-context-menu-and-clear-selection)
(mixins/listen state js/window "keydown"
(fn [e]
(when (= 27 (.-keyCode e))
(cond
(= 27 (.-keyCode e))
(if (and (state/modal-opened?)
(not
(and
@ -891,7 +893,13 @@
util/node-test?
(state/editing?))))
(state/close-modal!)
(hide-context-menu-and-clear-selection e)))))))
(hide-context-menu-and-clear-selection e))
(and (seq (state/get-selection-block-ids))
(not (or (.-ctrlKey e) (.-metaKey e) (.-altKey e))))
(let [shift? (.-shiftKey e)
shortcut (if shift? (str "shift+" (.-key e)) (.-key e))]
(db-property-handler/set-property-by-shortcut! shortcut)))))))
[state route-match main-content]
(let [{:keys [open-fn]} state
current-repo (state/sub :git/current-repo)
@ -958,7 +966,7 @@
(ui/focus-element (ui/main-node))))}
(t :accessibility/skip-to-main-content)]
[:div.#app-container (cond-> {} selection-mode?
(assoc :class "blocks-selection-mode"))
(assoc :class "blocks-selection-mode"))
[:div#left-container
{:class (if (state/sub :ui/sidebar-open?) "overflow-hidden" "w-full")}
(header/header {:open-fn open-fn

View File

@ -768,6 +768,13 @@ independent of format as format specific heading characters are stripped"
{:id (str uuid)
:nonce (:nonce shape)}))))))
(defn get-all-properties
[repo]
(when-let [db (conn/get-db repo)]
(->> (d/datoms db :avet :block/type "property")
(map (fn [d]
(d/entity db (:e d)))))))
(defn get-all-classes
[repo]
(d/q

View File

@ -97,3 +97,12 @@
(ui-outliner-tx/transact!
{:outliner-op :add-existing-values-to-closed-values}
(outliner-op/add-existing-values-to-closed-values! property-id values)))
(defn set-property-by-shortcut!
[shortcut]
;; TODO: support setting multiple blocks property
(let [properties (ldb/get-all-properties (db/get-db))
;; TODO: what if multiple properties have the same shortcut?
property (some (fn [p] (when (= shortcut (get-in p [:block/schema :shortcut])) p)) properties)]
(when property
(state/pub-event! [:editor/new-property {:property-key (:block/original-name property)}]))))

View File

@ -104,7 +104,7 @@
[:<>
(if (= :draw route-name)
(view route-match)
(container/sidebar
(container/root-container
route-match
(view route-match)))
(when config/lsp-enabled?