feat: quick add (#11986)

* feat: quick add

* enhance(ux): auto open block for editing for quick add

* enhance(ux): show notification after quick add

* add migration for quick add page
This commit is contained in:
Tienson Qin
2025-07-07 16:18:53 +08:00
committed by GitHub
parent d63a5ffb6a
commit e259be0c51
19 changed files with 128 additions and 41 deletions

View File

@@ -73,6 +73,11 @@
(->> (future (run-tests 'logseq.e2e.rtc-extra-test))
(swap! *futures assoc :rtc-extra-test)))
(defn run-tag-basic-test
[]
(->> (future (run-tests 'logseq.e2e.tag-basic-test))
(swap! *futures assoc :tag-basic-test)))
(defn run-all-basic-test
[]
(run-tests 'logseq.e2e.commands-basic-test

View File

@@ -35,6 +35,7 @@
(defonce favorites-page-name "$$$favorites")
(defonce views-page-name "$$$views")
(defonce library-page-name "Library")
(defonce quick-add-page-name "Quick add")
(defn local-asset?
[s]

View File

@@ -262,11 +262,7 @@
(d/entity db [:block/uuid id])
(d/entity db (get-first-page-by-name db (name page-id-name-or-uuid)))))))
(defn get-built-in-page
[db title]
(when db
(let [id (common-uuid/gen-uuid :builtin-block-uuid title)]
(d/entity db [:block/uuid id]))))
(def get-built-in-page common-initial-data/get-built-in-page)
(defn library?
[page]

View File

@@ -6,6 +6,7 @@
[logseq.common.config :as common-config]
[logseq.common.util :as common-util]
[logseq.common.util.date-time :as date-time-util]
[logseq.common.uuid :as common-uuid]
[logseq.db.common.entity-plus :as entity-plus]
[logseq.db.common.entity-util :as common-entity-util]
[logseq.db.common.order :as db-order]
@@ -328,6 +329,12 @@
(d/datoms db :eavt (:e d)))
(d/datoms db :avet :logseq.property.user/email))))
(defn get-built-in-page
[db title]
(when db
(let [id (common-uuid/gen-uuid :builtin-block-uuid title)]
(d/entity db [:block/uuid id]))))
(defn get-initial-data
"Returns current database schema and initial data.
NOTE: This fn is called by DB and file graphs"
@@ -355,9 +362,10 @@
user-datoms (get-all-user-datoms db)
pages-datoms (if db-graph?
(let [contents-id (get-first-page-by-title db "Contents")
capture-page-id (:db/id (get-built-in-page db common-config/quick-add-page-name))
views-id (get-first-page-by-title db common-config/views-page-name)]
(mapcat #(d/datoms db :eavt %)
(remove nil? [contents-id views-id])))
(remove nil? [contents-id capture-page-id views-id])))
;; load all pages for file graphs
(->> (d/datoms db :avet :block/name)
(mapcat (fn [d] (d/datoms db :eavt (:e d))))))

View File

@@ -37,7 +37,7 @@
(map (juxt :major :minor)
[(parse-schema-version x) (parse-schema-version y)])))
(def version (parse-schema-version "65.6"))
(def version (parse-schema-version "65.7"))
(defn major-version
"Return a number.

View File

@@ -129,6 +129,7 @@
(def built-in-pages-names
#{common-config/library-page-name
common-config/quick-add-page-name
"Contents"})
(defn- validate-tx-for-duplicate-idents [tx]

View File

@@ -6,6 +6,7 @@
[datascript.core]
[datascript.impl.entity :as de]
[datascript.transit :as dt]
[logseq.common.config :as common-config]
[logseq.common.util :as common-util]
[logseq.common.uuid :as common-uuid]
[logseq.db.common.order :as db-order]
@@ -105,10 +106,13 @@
"Builds a basic page to be transacted. A minimal version of gp-block/page-name->map"
[title]
(block-with-timestamps
{:block/name (common-util/page-name-sanity-lc title)
:block/title title
:block/uuid (common-uuid/gen-uuid :builtin-block-uuid title)
:block/tags #{:logseq.class/Page}}))
(cond->
{:block/name (common-util/page-name-sanity-lc title)
:block/title title
:block/uuid (common-uuid/gen-uuid :builtin-block-uuid title)
:block/tags #{:logseq.class/Page}}
(contains? #{common-config/quick-add-page-name} title)
(assoc :logseq.property/hide? true))))
(defn kv
"Creates a key-value pair tx with the key and value respectively stored under

View File

@@ -697,6 +697,8 @@
;; built-in pages
{:page {:block/title "Library" :build/properties {:logseq.property/built-in? true}}
:blocks []}
{:page {:block/title "Quick add" :build/properties {:logseq.property/built-in? true
:logseq.property/hide? true}}, :blocks []}
{:page {:block/title "Contents" :build/properties {:logseq.property/built-in? true}}
:blocks [{:block/title "right sidebar"}]}
{:page {:block/title common-config/favorites-page-name

View File

@@ -4,14 +4,8 @@
&-main {
max-height: var(--palettle-container-height);
margin: -2rem;
overflow: hidden;
display: flex;
flex-direction: column;
@screen lg {
width: var(--ls-main-content-max-width);
}
width: fit-content;
.menu-link {
transition: none;
@@ -61,10 +55,6 @@
max-height: calc(var(--palettle-container-height) - var(--palettle-input-height));
}
.input-wrap {
height: var(--palettle-input-height);
}
.cp__palette-input {
color: var(--ls-secondary-text-color);
border: none;

View File

@@ -136,9 +136,6 @@
}
.cp__select-main {
width: fit-content;
margin: 0;
.ui__dropdown-trigger {
position: absolute;
@@ -241,9 +238,6 @@ input.simple-input:focus {
.page-add-tags, .page-tags, .property-select, .ls-property-add,
.property-configure, .ui__dropdown-menu-content {
.cp__select-main {
width: fit-content;
margin: 0;
.ui__dropdown-trigger {
position: absolute;

View File

@@ -9,11 +9,6 @@
}
}
.cp__select-main {
width: fit-content;
margin: 0;
}
.between-date {
min-width: 36em;
padding: 1em;

View File

@@ -0,0 +1,37 @@
(ns frontend.components.quick-add
"Quick add"
(:require [frontend.components.page :as page]
[frontend.date :as date]
[frontend.db :as db]
[frontend.handler.editor :as editor-handler]
[frontend.state :as state]
[logseq.common.config :as common-config]
[logseq.db :as ldb]
[logseq.shui.ui :as shui]
[rum.core :as rum]))
(rum/defc quick-add <
{:will-mount (fn [state]
(state/clear-selection!)
state)
:will-unmount (fn [state]
(state/clear-edit!)
(state/clear-selection!)
state)}
[]
(when (db/get-page (date/today))
(when-let [add-page (ldb/get-built-in-page (db/get-db) common-config/quick-add-page-name)]
[:div.ls-quick-capture.flex.flex-1.flex-col.w-full.gap-4
[:div.font-medium.text-xl.border-b.pb-4
"Quick add"]
[:div.block.-ml-6.content
(page/page-blocks-cp add-page {})]
[:div.flex.flex-row.gap-2.items-center
[:div
(shui/button
{:variant :outline
:size :sm
:on-click (fn [_e]
(editor-handler/quick-add-blocks!))}
(shui/shortcut ["mod" "e"])
"Add to today")]]])))

View File

@@ -60,7 +60,6 @@
[(hooks/use-debounced-value @*input 100)])
[:div.input-wrap
{:style {:margin-bottom "-2px"}}
[:input.cp__select-input.w-full
(merge {:type "text"
:class "!p-1.5"

View File

@@ -52,6 +52,7 @@
[goog.object :as gobj]
[goog.string :as gstring]
[lambdaisland.glogi :as log]
[logseq.common.config :as common-config]
[logseq.common.path :as path]
[logseq.common.util :as common-util]
[logseq.common.util.block-ref :as block-ref]
@@ -68,6 +69,7 @@
[logseq.graph-parser.utf8 :as utf8]
[logseq.outliner.core :as outliner-core]
[logseq.outliner.property :as outliner-property]
[logseq.shui.dialog.core :as shui-dialog]
[logseq.shui.popup.core :as shui-popup]
[promesa.core :as p]
[rum.core :as rum]))
@@ -3990,3 +3992,37 @@
(save-block-inner! block "" {})
(when query-block
(save-block-inner! query-block current-query {})))))))))
(defn show-quick-add
[]
(let [graph (state/get-current-repo)]
(p/do!
(db-async/<get-block graph (date/today))
(p/let [add-page (db-async/<get-block graph (:db/id (ldb/get-built-in-page (db/get-db) common-config/quick-add-page-name)))]
(if (:block/_parent add-page)
(let [block (last (ldb/sort-by-order (:block/_parent add-page)))]
(edit-block! block :max {:container-id :unknown-container}))
(api-insert-new-block! "" {:page (:block/uuid add-page)
:container-id :unknown-container})))
(state/pub-event! [:dialog/quick-add]))))
(defn quick-add-blocks!
[]
(let [today (db/get-page (date/today))
add-page (ldb/get-built-in-page (db/get-db) common-config/quick-add-page-name)]
(when (and today add-page)
(let [children (:block/_parent (db/entity (:db/id add-page)))]
(p/do!
(when (seq children)
(if-let [today-last-child (last (ldb/sort-by-order (:block/_parent today)))]
(move-blocks! children today-last-child true)
(move-blocks! children today false)))
(state/close-modal!)
(when (seq children)
(notification/show! "Blocks added to today!" :success)))))))
(defn quick-add
[]
(if (shui-dialog/get-modal :ls-dialog-quick-add)
(quick-add-blocks!)
(show-quick-add)))

View File

@@ -7,6 +7,7 @@
[frontend.components.page :as component-page]
[frontend.components.plugins :as plugin]
[frontend.components.property.dialog :as property-dialog]
[frontend.components.quick-add :as quick-add]
[frontend.components.repo :as repo]
[frontend.components.select :as select]
[frontend.components.selection :as selection]
@@ -346,3 +347,12 @@
:align :top
:content-props {:class "ls-dialog-block"}
:onEscapeKeyDown (fn [e] (.preventDefault e))}))
(defmethod events/handle :dialog/quick-add [_]
(shui/dialog-open!
[:div.w-full.h-full
(quick-add/quick-add)]
{:id :ls-dialog-quick-add
:align :top
:content-props {:class "ls-dialog-quick-add"}
:onEscapeKeyDown (fn [e] (.preventDefault e))}))

View File

@@ -261,7 +261,7 @@
:editor/replace-block-reference-at-point {:binding "mod+shift+r"
:fn editor-handler/replace-block-reference-with-content-at-point}
:editor/copy-embed {:binding "mod+e"
:editor/copy-embed {:binding "mod+shift+e"
:fn editor-handler/copy-current-block-embed}
:editor/paste-text-in-one-block-at-point {:binding "mod+shift+v"
@@ -539,6 +539,9 @@
:command/toggle-favorite {:binding "mod+shift+f"
:fn page-handler/toggle-favorite!}
:editor/quick-add {:binding (if mac? "mod+e" "mod+alt+e")
:db-graph? true
:fn editor-handler/quick-add}
:editor/jump {:binding "mod+j"
:fn jump-handler/jump-to}
:editor/open-file-in-default-app {:binding "mod+d mod+a"
@@ -811,6 +814,7 @@
:editor/toggle-number-list
:editor/undo
:editor/redo
:editor/quick-add
:ui/toggle-brackets
:go/search-in-page
:go/search
@@ -913,7 +917,8 @@
:editor/redo
:editor/copy
:editor/copy-text
:editor/cut]
:editor/cut
:editor/quick-add]
:shortcut.category/formatting
[:editor/bold

View File

@@ -337,10 +337,6 @@ input[type='range'] {
.ls-dialog-select {
@apply w-auto !max-w-fit p-0;
.cp__select-main {
@apply m-0;
}
.item-results-wrap {
@apply px-2;
}

View File

@@ -337,6 +337,12 @@
(let [extends (d/entity db :logseq.property.class/extends)]
[[:db/add (:db/id extends) :db/cardinality :db.cardinality/many]]))
(defn- add-quick-add-page
[_db]
(let [page (-> (-> (sqlite-util/build-new-page common-config/quick-add-page-name)
sqlite-create-graph/mark-block-as-built-in))]
[page]))
(def schema-version->updates
"A vec of tuples defining datascript migrations. Each tuple consists of the
schema version integer and a migration map. A migration map can have keys of :properties, :classes
@@ -347,7 +353,8 @@
["65.3" {:fix add-missing-db-ident-for-tags}]
["65.4" {:fix fix-using-properties-as-tags}]
["65.5" {:fix remove-block-order-for-tags}]
["65.6" {:fix update-extends-to-cardinality-many}]])
["65.6" {:fix update-extends-to-cardinality-many}]
["65.7" {:fix add-quick-add-page}]])
(let [[major minor] (last (sort (map (comp (juxt :major :minor) db-schema/parse-schema-version first)
schema-version->updates)))]

View File

@@ -680,6 +680,7 @@
:editor/cut "Cut"
:editor/undo "Undo"
:editor/redo "Redo"
:editor/quick-add "Quick add"
:editor/insert-link "HTML Link"
:editor/select-all-blocks "Select all blocks"
:editor/select-parent "Select parent block"