mirror of
https://github.com/logseq/logseq.git
synced 2026-05-29 23:19:38 +00:00
refactor to pass lint:large-vars
This commit is contained in:
@@ -675,6 +675,60 @@
|
||||
(reset! (::highlighted-row-el state) nil))
|
||||
(apply-anchored-wheel-scroll! state e))
|
||||
|
||||
(defn- render-result-list-item
|
||||
[state group highlighted-item highlighted? *mouse-active? disable-lazy? item hls-page? text]
|
||||
(let [item (list-item/root
|
||||
(assoc item
|
||||
:group group
|
||||
:query (when-not (= group :create) @(::input state))
|
||||
:text (if hls-page? (pdf-utils/fix-local-asset-pagename text) text)
|
||||
:hls-page? hls-page?
|
||||
:compact true
|
||||
:rounded true
|
||||
:hoverable @*mouse-active?
|
||||
:highlighted highlighted?
|
||||
;; for some reason, the highlight effect does not always trigger on a
|
||||
;; boolean value change so manually pass in the dep
|
||||
:on-highlight-dep highlighted-item
|
||||
:on-click
|
||||
(fn [e]
|
||||
(util/stop-propagation e)
|
||||
(reset! (::highlighted-item state) item)
|
||||
(handle-action :default state item)
|
||||
(when-let [on-click (:on-click item)]
|
||||
(on-click e)))
|
||||
:on-mouse-enter
|
||||
(fn [_e]
|
||||
(when (and @*mouse-active?
|
||||
(= :mouse @(::focus-source state)))
|
||||
(when (not= item @(::highlighted-item state))
|
||||
(reset! (::highlighted-item state) item))))
|
||||
:component-opts
|
||||
{:on-mouse-move
|
||||
(fn [e]
|
||||
(let [dx (or (.-movementX e) 0)
|
||||
dy (or (.-movementY e) 0)
|
||||
real-pointer-move? (or (not (zero? dx))
|
||||
(not (zero? dy)))]
|
||||
(when real-pointer-move?
|
||||
(when-not @*mouse-active?
|
||||
(reset! *mouse-active? true))
|
||||
(when-not (= :mouse @(::focus-source state))
|
||||
(reset! (::focus-source state) :mouse))
|
||||
(when (not= item @(::highlighted-item state))
|
||||
(reset! (::highlighted-item state) item)))))}
|
||||
:on-highlight (fn [ref]
|
||||
(reset! (::highlighted-group state) group)
|
||||
(when (and ref (.-current ref))
|
||||
(let [row-el (.-current ref)]
|
||||
(reset! (::highlighted-row-el state) row-el)
|
||||
(when (= :keyboard @(::focus-source state))
|
||||
(ensure-focus-visible! state row-el))))))
|
||||
nil)]
|
||||
(if (and (= group :nodes) (not disable-lazy?))
|
||||
(ui/lazy-visible (fn [] item) {:trigger-once? true})
|
||||
item)))
|
||||
|
||||
(rum/defcs result-group
|
||||
< rum/reactive
|
||||
[state' state title group visible-items first-item sidebar?]
|
||||
@@ -742,57 +796,7 @@
|
||||
text (some-> item :text)
|
||||
source-block (some-> item :source-block)
|
||||
hls-page? (and page? (pdf-utils/hls-file? (:block/title source-block)))]]
|
||||
(let [item (list-item/root
|
||||
(assoc item
|
||||
:group group
|
||||
:query (when-not (= group :create) @(::input state))
|
||||
:text (if hls-page? (pdf-utils/fix-local-asset-pagename text) text)
|
||||
:hls-page? hls-page?
|
||||
:compact true
|
||||
:rounded true
|
||||
:hoverable @*mouse-active?
|
||||
:highlighted highlighted?
|
||||
;; for some reason, the highlight effect does not always trigger on a
|
||||
;; boolean value change so manually pass in the dep
|
||||
:on-highlight-dep highlighted-item
|
||||
:on-click
|
||||
(fn [e]
|
||||
(util/stop-propagation e)
|
||||
(reset! (::highlighted-item state) item)
|
||||
(handle-action :default state item)
|
||||
(when-let [on-click (:on-click item)]
|
||||
(on-click e)))
|
||||
:on-mouse-enter
|
||||
(fn [_e]
|
||||
(when (and @*mouse-active?
|
||||
(= :mouse @(::focus-source state)))
|
||||
(when (not= item @(::highlighted-item state))
|
||||
(reset! (::highlighted-item state) item))))
|
||||
:component-opts
|
||||
{:on-mouse-move
|
||||
(fn [e]
|
||||
(let [dx (or (.-movementX e) 0)
|
||||
dy (or (.-movementY e) 0)
|
||||
real-pointer-move? (or (not (zero? dx))
|
||||
(not (zero? dy)))]
|
||||
(when real-pointer-move?
|
||||
(when-not @*mouse-active?
|
||||
(reset! *mouse-active? true))
|
||||
(when-not (= :mouse @(::focus-source state))
|
||||
(reset! (::focus-source state) :mouse))
|
||||
(when (not= item @(::highlighted-item state))
|
||||
(reset! (::highlighted-item state) item)))))}
|
||||
:on-highlight (fn [ref]
|
||||
(reset! (::highlighted-group state) group)
|
||||
(when (and ref (.-current ref))
|
||||
(let [row-el (.-current ref)]
|
||||
(reset! (::highlighted-row-el state) row-el)
|
||||
(when (= :keyboard @(::focus-source state))
|
||||
(ensure-focus-visible! state row-el))))))
|
||||
nil)]
|
||||
(if (and (= group :nodes) (not disable-lazy?))
|
||||
(ui/lazy-visible (fn [] item) {:trigger-once? true})
|
||||
item)))]]))
|
||||
(render-result-list-item state group highlighted-item highlighted? *mouse-active? disable-lazy? item hls-page? text))]]))
|
||||
|
||||
(defn move-highlight [state n]
|
||||
(let [items (mapcat last (state->results-ordered state (:search/mode @state/state)))
|
||||
|
||||
@@ -520,6 +520,49 @@ DROP TRIGGER IF EXISTS blocks_au;
|
||||
(and code-class
|
||||
(ldb/class-instance? code-class block))))))
|
||||
|
||||
(defn- include-search-block?
|
||||
[conn block code-class {:keys [library-page-search? page-only? dev? built-in? code-only?]}]
|
||||
(and
|
||||
(not
|
||||
(or
|
||||
;; remove pages that already have parents
|
||||
(and library-page-search?
|
||||
(or (ldb/page-in-library? @conn block)
|
||||
(not (ldb/internal-page? block))))
|
||||
;; remove non-page blocks when asking for pages only
|
||||
(and page-only? (not (ldb/page? block)))))
|
||||
(if dev?
|
||||
true
|
||||
(if built-in?
|
||||
(or (not (ldb/built-in? block))
|
||||
(not (ldb/private-built-in-page? block))
|
||||
(ldb/class? block))
|
||||
(or (not (ldb/built-in? block))
|
||||
(ldb/class? block))))
|
||||
(or (not code-only?)
|
||||
(code-block? code-class block))))
|
||||
|
||||
(defn- search-result->block-result
|
||||
[conn q code-class option {:keys [id page title snippet]}]
|
||||
(let [block-id (uuid id)]
|
||||
(when-let [block (d/entity @conn [:block/uuid block-id])]
|
||||
(when (include-search-block? conn block code-class option)
|
||||
(let [display-title (or (block-search-title block) title)]
|
||||
{:db/id (:db/id block)
|
||||
:block/uuid (:block/uuid block)
|
||||
:block/title (ensure-highlighted-snippet snippet display-title q)
|
||||
:block.temp/original-title (:block/title block)
|
||||
:block/page (or
|
||||
(:block/uuid (:block/page block))
|
||||
(when (and page (common-util/uuid-string? page))
|
||||
(uuid page)))
|
||||
:block/parent (:db/id (:block/parent block))
|
||||
:block/tags (seq (map :db/id (:block/tags block)))
|
||||
:logseq.property/icon (:logseq.property/icon block)
|
||||
:page? (ldb/page? block)
|
||||
:alias (some-> (first (:block/_alias block))
|
||||
(select-keys [:block/uuid :block/title]))})))))
|
||||
|
||||
(defn search-blocks
|
||||
"Options:
|
||||
* :page - the page to specifically search on
|
||||
@@ -529,7 +572,7 @@ DROP TRIGGER IF EXISTS blocks_au;
|
||||
* :dev? - Allow all nodes to be seen for development. Defaults to false
|
||||
* :code-only? - Whether to return only code blocks. Defaults to false
|
||||
* :built-in? - Whether to return public built-in nodes for db graphs. Defaults to false"
|
||||
[repo conn search-db q {:keys [limit search-limit page enable-snippet? built-in? dev? page-only? library-page-search? code-only?]
|
||||
[repo conn search-db q {:keys [limit search-limit page enable-snippet? page-only? code-only?]
|
||||
:as option
|
||||
:or {enable-snippet? true}}]
|
||||
(m/sp
|
||||
@@ -585,44 +628,7 @@ DROP TRIGGER IF EXISTS blocks_au;
|
||||
(d/entity @conn :logseq.class/Code-block))
|
||||
result (->> combined-result
|
||||
(common-util/distinct-by :id)
|
||||
(keep (fn [search-result]
|
||||
(let [{:keys [id page title snippet]} search-result
|
||||
block-id (uuid id)]
|
||||
(when-let [block (d/entity @conn [:block/uuid block-id])]
|
||||
(when-not (or
|
||||
;; remove pages that already have parents
|
||||
(and library-page-search?
|
||||
(or (ldb/page-in-library? @conn block)
|
||||
(not (ldb/internal-page? block))))
|
||||
;; remove non-page blocks when asking for pages only
|
||||
(and page-only? (not (ldb/page? block))))
|
||||
(when (if dev?
|
||||
true
|
||||
(if built-in?
|
||||
(or (not (ldb/built-in? block))
|
||||
(not (ldb/private-built-in-page? block))
|
||||
(ldb/class? block))
|
||||
(or (not (ldb/built-in? block))
|
||||
(ldb/class? block))))
|
||||
(when (or (not code-only?)
|
||||
(code-block? code-class block))
|
||||
(let [display-title (or (block-search-title block) title)]
|
||||
{:db/id (:db/id block)
|
||||
:block/uuid (:block/uuid block)
|
||||
:block/title (ensure-highlighted-snippet snippet display-title q)
|
||||
:block.temp/original-title (:block/title block)
|
||||
:block/page (or
|
||||
(:block/uuid (:block/page block))
|
||||
(when page
|
||||
(if (common-util/uuid-string? page)
|
||||
(uuid page)
|
||||
nil)))
|
||||
:block/parent (:db/id (:block/parent block))
|
||||
:block/tags (seq (map :db/id (:block/tags block)))
|
||||
:logseq.property/icon (:logseq.property/icon block)
|
||||
:page? (ldb/page? block)
|
||||
:alias (some-> (first (:block/_alias block))
|
||||
(select-keys [:block/uuid :block/title]))})))))))))
|
||||
(keep #(search-result->block-result conn q code-class option %)))
|
||||
result (cond->> result
|
||||
search-limit
|
||||
(take limit))]
|
||||
|
||||
Reference in New Issue
Block a user