mirror of https://github.com/logseq/logseq
parent
03ec9580c3
commit
c8b88c9d8f
|
@ -9,7 +9,6 @@
|
||||||
[frontend.handler.draw :as draw]
|
[frontend.handler.draw :as draw]
|
||||||
[frontend.handler.notification :as notification]
|
[frontend.handler.notification :as notification]
|
||||||
[frontend.handler.plugin :as plugin-handler]
|
[frontend.handler.plugin :as plugin-handler]
|
||||||
[frontend.handler.property :as property-handler]
|
|
||||||
[frontend.search :as search]
|
[frontend.search :as search]
|
||||||
[frontend.state :as state]
|
[frontend.state :as state]
|
||||||
[frontend.util :as util]
|
[frontend.util :as util]
|
||||||
|
@ -218,101 +217,104 @@
|
||||||
|
|
||||||
(defn commands-map
|
(defn commands-map
|
||||||
[get-page-ref-text]
|
[get-page-ref-text]
|
||||||
(->>
|
(let [db? (config/db-based-graph? (state/get-current-repo))]
|
||||||
(concat
|
(->>
|
||||||
|
(concat
|
||||||
;; basic
|
;; basic
|
||||||
[["Page reference" [[:editor/input page-ref/left-and-right-brackets {:backward-pos 2}]
|
[["Page reference" [[:editor/input page-ref/left-and-right-brackets {:backward-pos 2}]
|
||||||
[:editor/search-page]] "Create a backlink to a page"]
|
[:editor/search-page]] "Create a backlink to a page"]
|
||||||
["Page embed" (embed-page) "Embed a page here"]
|
["Page embed" (embed-page) "Embed a page here"]
|
||||||
["Block reference" [[:editor/input block-ref/left-and-right-parens {:backward-pos 2}]
|
["Block reference" [[:editor/input block-ref/left-and-right-parens {:backward-pos 2}]
|
||||||
[:editor/search-block :reference]] "Create a backlink to a block"]
|
[:editor/search-block :reference]] "Create a backlink to a block"]
|
||||||
["Block embed" (embed-block) "Embed a block here" "Embed a block here"]
|
["Block embed" (embed-block) "Embed a block here" "Embed a block here"]
|
||||||
["Link" (link-steps) "Create a HTTP link"]
|
["Link" (link-steps) "Create a HTTP link"]
|
||||||
["Image link" (image-link-steps) "Create a HTTP link to a image"]
|
["Image link" (image-link-steps) "Create a HTTP link to a image"]
|
||||||
(when (state/markdown?)
|
(when (state/markdown?)
|
||||||
["Underline" [[:editor/input "<ins></ins>"
|
["Underline" [[:editor/input "<ins></ins>"
|
||||||
{:last-pattern command-trigger
|
{:last-pattern command-trigger
|
||||||
:backward-pos 6}]] "Create a underline text decoration"])
|
:backward-pos 6}]] "Create a underline text decoration"])
|
||||||
["Template" [[:editor/input command-trigger nil]
|
(when-not db?
|
||||||
[:editor/search-template]] "Insert a created template here"]
|
["Template" [[:editor/input command-trigger nil]
|
||||||
(cond
|
[:editor/search-template]] "Insert a created template here"])
|
||||||
(and (util/electron?) (config/local-file-based-graph? (state/get-current-repo)))
|
(cond
|
||||||
|
(and (util/electron?) (config/local-file-based-graph? (state/get-current-repo)))
|
||||||
|
|
||||||
["Upload an asset" [[:editor/click-hidden-file-input :id]] "Upload file types like image, pdf, docx, etc.)"])]
|
["Upload an asset" [[:editor/click-hidden-file-input :id]] "Upload file types like image, pdf, docx, etc.)"])]
|
||||||
|
|
||||||
;; ["Upload an image" [[:editor/click-hidden-file-input :id]]]
|
;; ["Upload an image" [[:editor/click-hidden-file-input :id]]]
|
||||||
|
|
||||||
(headings)
|
(headings)
|
||||||
|
|
||||||
;; time & date
|
;; time & date
|
||||||
|
|
||||||
[["Tomorrow" #(get-page-ref-text (date/tomorrow)) "Insert the date of tomorrow"]
|
[["Tomorrow" #(get-page-ref-text (date/tomorrow)) "Insert the date of tomorrow"]
|
||||||
["Yesterday" #(get-page-ref-text (date/yesterday)) "Insert the date of yesterday"]
|
["Yesterday" #(get-page-ref-text (date/yesterday)) "Insert the date of yesterday"]
|
||||||
["Today" #(get-page-ref-text (date/today)) "Insert the date of today"]
|
["Today" #(get-page-ref-text (date/today)) "Insert the date of today"]
|
||||||
["Current time" #(date/get-current-time) "Insert current time"]
|
["Current time" #(date/get-current-time) "Insert current time"]
|
||||||
["Date picker" [[:editor/show-date-picker]] "Pick a date and insert here"]]
|
["Date picker" [[:editor/show-date-picker]] "Pick a date and insert here"]]
|
||||||
|
|
||||||
;; order list
|
;; order list
|
||||||
[["Number list" [[:editor/clear-current-slash]
|
[["Number list" [[:editor/clear-current-slash]
|
||||||
[:editor/toggle-own-number-list]] "Number list"]
|
[:editor/toggle-own-number-list]] "Number list"]
|
||||||
["Number children" [[:editor/clear-current-slash]
|
["Number children" [[:editor/clear-current-slash]
|
||||||
[:editor/toggle-children-number-list]] "Number children"]]
|
[:editor/toggle-children-number-list]] "Number children"]]
|
||||||
|
|
||||||
;; task management
|
;; task management
|
||||||
(get-preferred-workflow)
|
(get-preferred-workflow)
|
||||||
[["DONE" (->marker "DONE")]
|
[["DONE" (->marker "DONE")]
|
||||||
["WAITING" (->marker "WAITING")]
|
["WAITING" (->marker "WAITING")]
|
||||||
["CANCELED" (->marker "CANCELED")]
|
["CANCELED" (->marker "CANCELED")]
|
||||||
["Deadline" [[:editor/clear-current-slash]
|
["Deadline" [[:editor/clear-current-slash]
|
||||||
[:editor/show-date-picker :deadline]]]
|
[:editor/show-date-picker :deadline]]]
|
||||||
["Scheduled" [[:editor/clear-current-slash]
|
["Scheduled" [[:editor/clear-current-slash]
|
||||||
[:editor/show-date-picker :scheduled]]]]
|
[:editor/show-date-picker :scheduled]]]]
|
||||||
|
|
||||||
;; priority
|
;; priority
|
||||||
[["A" (->priority "A")]
|
[["A" (->priority "A")]
|
||||||
["B" (->priority "B")]
|
["B" (->priority "B")]
|
||||||
["C" (->priority "C")]]
|
["C" (->priority "C")]]
|
||||||
|
|
||||||
;; advanced
|
;; advanced
|
||||||
|
|
||||||
[["Query" [[:editor/input "{{query }}" {:backward-pos 2}]
|
[["Query" [[:editor/input "{{query }}" {:backward-pos 2}]
|
||||||
[:editor/exit]] query-doc]
|
[:editor/exit]] query-doc]
|
||||||
["Zotero" (zotero-steps) "Import Zotero journal article"]
|
["Zotero" (zotero-steps) "Import Zotero journal article"]
|
||||||
["Query function" [[:editor/input "{{function }}" {:backward-pos 2}]] "Create a query function"]
|
["Query function" [[:editor/input "{{function }}" {:backward-pos 2}]] "Create a query function"]
|
||||||
["Calculator" [[:editor/input "```calc\n\n```" {:type "block"
|
["Calculator" [[:editor/input "```calc\n\n```" {:type "block"
|
||||||
:backward-pos 4}]
|
:backward-pos 4}]
|
||||||
[:codemirror/focus]] "Insert a calculator"]
|
[:codemirror/focus]] "Insert a calculator"]
|
||||||
["Draw" (fn []
|
["Draw" (fn []
|
||||||
(let [file (draw/file-name)
|
(let [file (draw/file-name)
|
||||||
path (str gp-config/default-draw-directory "/" file)
|
path (str gp-config/default-draw-directory "/" file)
|
||||||
text (page-ref/->page-ref path)]
|
text (page-ref/->page-ref path)]
|
||||||
(p/let [_ (draw/create-draw-with-default-content path)]
|
(p/let [_ (draw/create-draw-with-default-content path)]
|
||||||
(println "draw file created, " path))
|
(println "draw file created, " path))
|
||||||
text)) "Draw a graph with Excalidraw"]
|
text)) "Draw a graph with Excalidraw"]
|
||||||
["Embed HTML " (->inline "html")]
|
["Embed HTML " (->inline "html")]
|
||||||
|
|
||||||
["Embed Video URL" [[:editor/input "{{video }}" {:last-pattern command-trigger
|
["Embed Video URL" [[:editor/input "{{video }}" {:last-pattern command-trigger
|
||||||
:backward-pos 2}]]]
|
:backward-pos 2}]]]
|
||||||
|
|
||||||
["Embed Youtube timestamp" [[:youtube/insert-timestamp]]]
|
["Embed Youtube timestamp" [[:youtube/insert-timestamp]]]
|
||||||
|
|
||||||
["Embed Twitter tweet" [[:editor/input "{{tweet }}" {:last-pattern command-trigger
|
["Embed Twitter tweet" [[:editor/input "{{tweet }}" {:last-pattern command-trigger
|
||||||
:backward-pos 2}]]]
|
:backward-pos 2}]]]
|
||||||
["Add new property" [[:editor/clear-current-slash]
|
(when db?
|
||||||
[:editor/new-property]]]
|
["Add new property" [[:editor/clear-current-slash]
|
||||||
|
[:editor/new-property]]])
|
||||||
|
|
||||||
["Code block" [[:editor/input "```\n```\n" {:type "block"
|
["Code block" [[:editor/input "```\n```\n" {:type "block"
|
||||||
:backward-pos 5
|
:backward-pos 5
|
||||||
:only-breakline? true}]
|
:only-breakline? true}]
|
||||||
[:editor/select-code-block-mode]] "Insert code block"]]
|
[:editor/select-code-block-mode]] "Insert code block"]]
|
||||||
|
|
||||||
@*extend-slash-commands
|
@*extend-slash-commands
|
||||||
;; Allow user to modify or extend, should specify how to extend.
|
;; Allow user to modify or extend, should specify how to extend.
|
||||||
|
|
||||||
(state/get-commands)
|
(state/get-commands)
|
||||||
(state/get-plugins-slash-commands))
|
(state/get-plugins-slash-commands))
|
||||||
(remove nil?)
|
(remove nil?)
|
||||||
(util/distinct-by-last-wins first)))
|
(util/distinct-by-last-wins first))))
|
||||||
|
|
||||||
(defn init-commands!
|
(defn init-commands!
|
||||||
[get-page-ref-text]
|
[get-page-ref-text]
|
||||||
|
|
|
@ -174,11 +174,12 @@
|
||||||
(rum/defc ^:large-vars/cleanup-todo block-context-menu-content <
|
(rum/defc ^:large-vars/cleanup-todo block-context-menu-content <
|
||||||
shortcut/disable-all-shortcuts
|
shortcut/disable-all-shortcuts
|
||||||
[_target block-id]
|
[_target block-id]
|
||||||
|
(let [repo (state/get-current-repo)
|
||||||
|
db? (config/db-based-graph? repo)]
|
||||||
(when-let [block (db/entity [:block/uuid block-id])]
|
(when-let [block (db/entity [:block/uuid block-id])]
|
||||||
(let [properties (:block/properties block)
|
(let [properties (:block/properties block)
|
||||||
heading (or (pu/lookup properties :heading)
|
heading (or (pu/lookup properties :heading)
|
||||||
false)
|
false)]
|
||||||
repo (state/get-current-repo)]
|
|
||||||
[:.menu-links-wrapper
|
[:.menu-links-wrapper
|
||||||
(ui/menu-background-color #(property-handler/set-block-property! repo block-id :background-color %)
|
(ui/menu-background-color #(property-handler/set-block-property! repo block-id :background-color %)
|
||||||
#(property-handler/remove-block-property! repo block-id :background-color))
|
#(property-handler/remove-block-property! repo block-id :background-color))
|
||||||
|
@ -243,7 +244,8 @@
|
||||||
|
|
||||||
[:hr.menu-separator]
|
[:hr.menu-separator]
|
||||||
|
|
||||||
(block-template block-id)
|
(when-not db?
|
||||||
|
(block-template block-id))
|
||||||
|
|
||||||
(cond
|
(cond
|
||||||
(srs/card-block? block)
|
(srs/card-block? block)
|
||||||
|
@ -260,9 +262,9 @@
|
||||||
nil)
|
nil)
|
||||||
|
|
||||||
(ui/menu-link
|
(ui/menu-link
|
||||||
{:key "Toggle number list"
|
{:key "Toggle number list"
|
||||||
:on-click #(state/pub-event! [:editor/toggle-own-number-list (state/get-selection-block-ids)])}
|
:on-click #(state/pub-event! [:editor/toggle-own-number-list (state/get-selection-block-ids)])}
|
||||||
(t :context-menu/toggle-number-list))
|
(t :context-menu/toggle-number-list))
|
||||||
|
|
||||||
[:hr.menu-separator]
|
[:hr.menu-separator]
|
||||||
|
|
||||||
|
@ -302,7 +304,7 @@
|
||||||
:on-click (fn []
|
:on-click (fn []
|
||||||
(let [block (db/pull [:block/uuid block-id])]
|
(let [block (db/pull [:block/uuid block-id])]
|
||||||
(dev-common-handler/show-content-ast (:block/content block) (:block/format block))))}
|
(dev-common-handler/show-content-ast (:block/content block) (:block/format block))))}
|
||||||
(t :dev/show-block-ast)))])))
|
(t :dev/show-block-ast)))]))))
|
||||||
|
|
||||||
(rum/defc block-ref-custom-context-menu-content
|
(rum/defc block-ref-custom-context-menu-content
|
||||||
[block block-ref-id]
|
[block block-ref-id]
|
||||||
|
|
|
@ -2053,67 +2053,69 @@
|
||||||
([element-id db-id]
|
([element-id db-id]
|
||||||
(insert-template! element-id db-id {}))
|
(insert-template! element-id db-id {}))
|
||||||
([element-id db-id {:keys [target] :as opts}]
|
([element-id db-id {:keys [target] :as opts}]
|
||||||
(when-let [db-id (if (integer? db-id)
|
(let [repo (state/get-current-repo)
|
||||||
db-id
|
db? (config/db-based-graph? repo)]
|
||||||
(:db/id (db-model/get-template-by-name (name db-id))))]
|
(when-not db?
|
||||||
(let [journal? (:block/journal? target)
|
(when-let [db-id (if (integer? db-id)
|
||||||
repo (state/get-current-repo)
|
db-id
|
||||||
target (or target (state/get-edit-block))
|
(:db/id (db-model/get-template-by-name (name db-id))))]
|
||||||
block (db/entity db-id)
|
(let [journal? (:block/journal? target)
|
||||||
format (:block/format block)
|
target (or target (state/get-edit-block))
|
||||||
block-uuid (:block/uuid block)
|
block (db/entity db-id)
|
||||||
template-including-parent? (not (false? (:template-including-parent (:block/properties block))))
|
format (:block/format block)
|
||||||
blocks (db/get-block-and-children repo block-uuid)
|
block-uuid (:block/uuid block)
|
||||||
root-block (db/pull db-id)
|
template-including-parent? (not (false? (:template-including-parent (:block/properties block))))
|
||||||
blocks-exclude-root (remove (fn [b] (= (:db/id b) db-id)) blocks)
|
blocks (db/get-block-and-children repo block-uuid)
|
||||||
sorted-blocks (tree/sort-blocks blocks-exclude-root root-block)
|
root-block (db/pull db-id)
|
||||||
sorted-blocks (cons
|
blocks-exclude-root (remove (fn [b] (= (:db/id b) db-id)) blocks)
|
||||||
(-> (first sorted-blocks)
|
sorted-blocks (tree/sort-blocks blocks-exclude-root root-block)
|
||||||
(update :block/properties-text-values dissoc :template)
|
sorted-blocks (cons
|
||||||
(update :block/properties-order (fn [keys]
|
(-> (first sorted-blocks)
|
||||||
(vec (remove #{:template} keys)))))
|
(update :block/properties-text-values dissoc :template)
|
||||||
(rest sorted-blocks))
|
(update :block/properties-order (fn [keys]
|
||||||
blocks (if template-including-parent?
|
(vec (remove #{:template} keys)))))
|
||||||
sorted-blocks
|
(rest sorted-blocks))
|
||||||
(drop 1 sorted-blocks))]
|
blocks (if template-including-parent?
|
||||||
(when element-id
|
sorted-blocks
|
||||||
(insert-command! element-id "" format {:end-pattern commands/command-trigger}))
|
(drop 1 sorted-blocks))]
|
||||||
(let [exclude-properties [:id :template :template-including-parent]
|
(when element-id
|
||||||
content-update-fn (fn [content]
|
(insert-command! element-id "" format {:end-pattern commands/command-trigger}))
|
||||||
(->> content
|
(let [exclude-properties [:id :template :template-including-parent]
|
||||||
(file-property/remove-property-when-file-based repo format "template")
|
content-update-fn (fn [content]
|
||||||
(file-property/remove-property-when-file-based repo format "template-including-parent")
|
(->> content
|
||||||
template/resolve-dynamic-template!))
|
(file-property/remove-property-when-file-based repo format "template")
|
||||||
page (if (:block/name block) block
|
(file-property/remove-property-when-file-based repo format "template-including-parent")
|
||||||
(when target (:block/page (db/entity (:db/id target)))))
|
template/resolve-dynamic-template!))
|
||||||
blocks' (map (fn [block]
|
page (if (:block/name block) block
|
||||||
(paste-block-cleanup repo block page exclude-properties format content-update-fn false))
|
(when target (:block/page (db/entity (:db/id target)))))
|
||||||
blocks)
|
blocks' (map (fn [block]
|
||||||
sibling? (:sibling? opts)
|
(paste-block-cleanup repo block page exclude-properties format content-update-fn false))
|
||||||
sibling?' (cond
|
blocks)
|
||||||
(some? sibling?)
|
sibling? (:sibling? opts)
|
||||||
sibling?
|
sibling?' (cond
|
||||||
|
(some? sibling?)
|
||||||
|
sibling?
|
||||||
|
|
||||||
(db/has-children? (:block/uuid target))
|
(db/has-children? (:block/uuid target))
|
||||||
false
|
false
|
||||||
|
|
||||||
:else
|
:else
|
||||||
true)]
|
true)]
|
||||||
(try
|
(try
|
||||||
(outliner-tx/transact!
|
(outliner-tx/transact!
|
||||||
{:outliner-op :insert-blocks
|
{:outliner-op :insert-blocks
|
||||||
:created-from-journal-template? journal?}
|
:created-from-journal-template? journal?}
|
||||||
(save-current-block!)
|
(save-current-block!)
|
||||||
(let [result (outliner-core/insert-blocks! blocks'
|
(let [result (outliner-core/insert-blocks! blocks'
|
||||||
target
|
target
|
||||||
(assoc opts
|
(assoc opts
|
||||||
:sibling? sibling?'))]
|
:sibling? sibling?'))]
|
||||||
(edit-last-block-after-inserted! result)))
|
(edit-last-block-after-inserted! result)))
|
||||||
(catch :default ^js/Error e
|
(catch :default ^js/Error e
|
||||||
(notification/show!
|
(notification/show!
|
||||||
[:p.content
|
[:p.content
|
||||||
(util/format "Template insert error: %s" (.-message e))]
|
(util/format "Template insert error: %s" (.-message e))]
|
||||||
:error))))))))
|
:error))))))))))
|
||||||
|
|
||||||
(defn template-on-chosen-handler
|
(defn template-on-chosen-handler
|
||||||
[element-id]
|
[element-id]
|
||||||
|
|
Loading…
Reference in New Issue