Merge branch 'feat/db' into feat/capacitor-new

This commit is contained in:
charlie
2025-05-23 11:07:51 +08:00
13 changed files with 144 additions and 85 deletions

View File

@@ -526,7 +526,7 @@
.ls-page-title-container .block-content-wrapper {
.ls-page-title-actions {
@apply absolute -top-4 opacity-0;
@apply absolute -top-5 opacity-0;
left: -2px;
}

View File

@@ -55,7 +55,7 @@
}
#main-content-container {
@apply py-4 sm:pl-8 sm:pr-4;
@apply sm:py-8 py-2 sm:pl-8 sm:pr-4;
}
.left-sidebar-inner {

View File

@@ -602,7 +602,7 @@
(rum/defc sidebar-page-properties
[config page]
(let [[collapsed? set-collapsed!] (rum/use-state true)]
(let [[collapsed? set-collapsed!] (rum/use-state (not (ldb/class? page)))]
[:div.ls-sidebar-page-properties.flex.flex-col.gap-2.mt-2
[:div
(shui/button

View File

@@ -203,6 +203,7 @@
:datetime "calendar"
:checkbox "checkbox"
:url "link"
:property "letter-p"
:page "page"
:node "letter-n"
"letter-t"))]
@@ -423,7 +424,7 @@
(rum/defcs new-property < rum/reactive
[state block opts]
(when-not config/publishing?
[:div.ls-new-property {:style {:margin-left 6 :margin-top 1}}
[:div.ls-new-property {:style {:margin-left 7 :margin-top 1}}
[:a.fade-link.flex.jtrigger
{:tab-index 0
:on-click (fn [e]

View File

@@ -45,23 +45,29 @@
@apply focus-visible:outline-none focus-visible:bg-gray-03 focus-visible:rounded;
}
.jtrigger {
@apply relative;
&-id {
@apply absolute left-[-19px] top-[3px] rounded-full leading-none
flex items-center justify-center bg-primary text-primary-foreground border-none
text-xs min-w-[20px] min-h-[20px] scale-95;
}
}
.ls-new-property .jtrigger {
&-id {
@apply left-[-11px] top-[2px];
}
}
.ls-properties-area {
.property-pair {
@apply flex flex-row flex-wrap space-x-1;
.jtrigger {
@apply relative;
&-id {
@apply absolute left-[-22px] top-[2px] rounded-full leading-none
flex items-center justify-center bg-primary text-primary-foreground border-none
text-xs min-w-[20px] min-h-[20px] scale-95;
}
}
.jtrigger-view {
> .jtrigger-id {
@apply left-[-14px];
@apply left-[-11px];
}
&:has(> .jtrigger-id) {

View File

@@ -1174,6 +1174,7 @@
(if editing?
(popup-content nil)
(let [show! (fn [e]
(util/stop e)
(state/clear-selection!)
(let [target (when e (.-target e))]
(when-not (or config/publishing?
@@ -1189,7 +1190,7 @@
{:ref *el
:id trigger-id
:tabIndex 0
:on-pointer-down show!
:on-click show!
:on-key-down (fn [e]
(case (util/ekey e)
("Backspace" "Delete")

View File

@@ -260,12 +260,12 @@
(let [popup (fn []
(let [width (-> (max 160 width) (- 18))]
(if many?
[:div.ls-table-block.flex.flex-row.items-start
{:style {:width width :max-width width :margin-right "6px"}
[:div.ls-table-block
{:style {:width width :max-width width}
:on-click util/stop-propagation}
(pv/property-value row property {})]
[:div.ls-table-block.flex.flex-row.items-start
{:style {:width width :max-width width :margin-right "6px"}
[:div.ls-table-block
{:style {:width width :max-width width}
:on-click util/stop-propagation}
(block-container
{:popup? true

View File

@@ -15,3 +15,8 @@
.group-list-view div[data-testid='virtuoso-item-list'] div[data-testid='virtuoso-item-list'] {
@apply gap-0;
}
.ls-table-block {
@apply flex flex-row items-start text-sm;
margin-right: 6px;
}

View File

@@ -3339,6 +3339,11 @@
[]
(popup-exists? "editor.commands"))
(defn open-selected-blocks-in-sidebar!
[]
(doseq [id (state/get-selection-block-ids)]
(state/sidebar-add-block! (state/get-current-repo) id :block)))
(defn open-selected-block!
[direction e]
(let [selected-blocks (state/get-selection-blocks)

View File

@@ -1,12 +1,12 @@
(ns frontend.handler.jump
"Jump to property key/value"
(:require [frontend.state :as state]
(:require [clojure.string :as string]
[dommy.core :as d]
[clojure.string :as string]
[frontend.util :as util]
[frontend.handler.notification :as notification]
[frontend.db :as db]
[frontend.handler.editor :as editor-handler]
[frontend.db :as db]))
[frontend.handler.notification :as notification]
[frontend.state :as state]
[frontend.util :as util]))
(defonce *current-keys (atom nil))
(defonce *jump-data (atom {}))
@@ -88,53 +88,51 @@
(defn jump-to
[]
(let [current-block-id (or (:block/uuid (state/get-edit-block))
(first (state/get-selection-block-ids))
(:block/uuid (db/get-page (state/get-current-page))))]
(cond
current-block-id
(when (empty? (d/sel js/document ".jtrigger-id"))
(let [current-block (when (uuid? current-block-id)
(db/entity [:block/uuid current-block-id]))
collapsed? (or (state/get-block-collapsed current-block-id) (:block/collapsed? current-block))]
(when collapsed?
(editor-handler/expand-block! current-block-id))
(let [f #(let [selected-block-or-page (or (first (state/get-selection-blocks))
;; current edited block
(some-> (:block-parent-id (first (state/get-editor-args)))
js/document.getElementById)
;; current page
(d/sel1 js/document "#main-content-container .ls-properties-area"))
triggers (d/sel selected-block-or-page ".jtrigger")]
(when (seq triggers)
(reset! *jump-data {:mode :property
:triggers triggers})
(let [keys (generate-keys (count triggers))
key-down-handler (fn [e]
(let [k (util/ekey e)]
(if (= k "Escape")
(exit!)
(when (and (contains? full-start-keys k) (seq (:triggers @*jump-data)))
(swap! *jump-data update :chords (fn [s] (str s (util/ekey e))))
(let [chords (:chords @*jump-data)]
(trigger! chords e))))))]
(swap! *jump-data assoc :key-down-handler key-down-handler)
(reset! *current-keys keys)
(doall
(map-indexed
(fn [id dom]
(let [class (if (d/has-class? dom "ui__checkbox")
"jtrigger-id text-sm border rounded ml-4 px-1 shadow-xs"
"jtrigger-id text-sm border rounded ml-2 px-1 shadow-xs")
^js view (or (.closest dom ".jtrigger-view") dom)]
(d/append! view (-> (d/create-element :div)
(d/set-attr! :class class)
(d/set-text! (nth keys id))))))
(take (count keys) triggers)))
(.addEventListener js/window "keydown" key-down-handler))))]
(if collapsed?
(js/setTimeout f 100)
(f)))))
:else ; add block jump support
nil)))
(when (empty? (d/sel js/document ".jtrigger-id"))
(let [current-block-id (or (:block/uuid (state/get-edit-block))
(first (state/get-selection-block-ids))
(:block/uuid (db/get-page (state/get-current-page))))
current-block (when (uuid? current-block-id)
(db/entity [:block/uuid current-block-id]))
collapsed? (or (state/get-block-collapsed current-block-id) (:block/collapsed? current-block))]
(when collapsed?
(editor-handler/expand-block! current-block-id))
(let [f #(let [selected-block-or-editing-block (or (first (state/get-selection-blocks))
;; current editing block
(some-> (state/get-editing-block-dom-id)
js/document.getElementById
(util/rec-get-node ".ls-block")))
triggers (->> (if selected-block-or-editing-block
(d/sel selected-block-or-editing-block ".jtrigger")
(d/sel ".jtrigger"))
(remove (fn [^js n]
(some (fn [class] (.closest n class)) #{".positioned-properties" ".view-actions" ".ls-table-cell"}))))]
(when (seq triggers)
(reset! *jump-data {:mode :property
:triggers triggers})
(let [keys (generate-keys (count triggers))
key-down-handler (fn [e]
(let [k (util/ekey e)]
(if (= k "Escape")
(exit!)
(when (and (contains? full-start-keys k) (seq (:triggers @*jump-data)))
(swap! *jump-data update :chords (fn [s] (str s (util/ekey e))))
(let [chords (:chords @*jump-data)]
(trigger! chords e))))))]
(swap! *jump-data assoc :key-down-handler key-down-handler)
(reset! *current-keys keys)
(doall
(map-indexed
(fn [id dom]
(let [class (if (d/has-class? dom "ui__checkbox")
"jtrigger-id text-sm border rounded ml-4 px-1 shadow-xs"
"jtrigger-id text-sm border rounded ml-2 px-1 shadow-xs")
^js view (or (.closest dom ".jtrigger-view") dom)]
(d/append! view (-> (d/create-element :div)
(d/set-attr! :class class)
(d/set-text! (nth keys id))))))
(take (count keys) triggers)))
(.addEventListener js/window "keydown" key-down-handler))))]
(if collapsed?
(js/setTimeout f 100)
(f))))))

View File

@@ -291,9 +291,11 @@
:editor/move-block-down {:binding (if mac? "mod+shift+down" "alt+shift+down")
:fn (editor-handler/move-up-down false)}
;; FIXME: add open edit in non-selection mode
:editor/open-edit {:binding "enter"
:fn (partial editor-handler/open-selected-block! :right)}
:fn (fn [e]
(editor-handler/open-selected-block! :right e))}
:editor/open-selected-blocks-in-sidebar {:binding "shift+enter"
:fn editor-handler/open-selected-blocks-in-sidebar!}
:editor/select-block-up {:binding "alt+up"
:fn (editor-handler/on-select-block :up)}
@@ -782,6 +784,7 @@
:editor/move-block-up
:editor/move-block-down
:editor/open-edit
:editor/open-selected-blocks-in-sidebar
:editor/select-block-up
:editor/select-block-down
:editor/select-parent
@@ -974,6 +977,7 @@
:shortcut.category/block-selection
[:editor/open-edit
:editor/open-selected-blocks-in-sidebar
:editor/select-all-blocks
:editor/select-parent
:editor/select-block-up

View File

@@ -665,6 +665,7 @@
:editor/move-block-up "Move block up"
:editor/move-block-down "Move block down"
:editor/open-edit "Edit selected block"
:editor/open-selected-blocks-in-sidebar "Open selected block(s) in sidebar"
:editor/select-block-up "Select block above"
:editor/select-block-down "Select block below"
:editor/delete-selection "Delete selected blocks"