mirror of https://github.com/logseq/logseq
commit
cc59296c93
|
@ -18,7 +18,8 @@
|
|||
[frontend.components.page :as page]
|
||||
[frontend.components.onboarding :as onboarding]
|
||||
[goog.object :as gobj]
|
||||
[clojure.string :as string]))
|
||||
[clojure.string :as string]
|
||||
[frontend.handler.block :as block-handler]))
|
||||
|
||||
(rum/defc blocks-inner < rum/static
|
||||
{:did-mount (fn [state]
|
||||
|
@ -56,7 +57,7 @@
|
|||
(let [raw-blocks (db/get-page-blocks repo page)
|
||||
document-mode? (state/sub :document/mode?)
|
||||
blocks (->>
|
||||
(db/with-dummy-block raw-blocks format nil {:journal? true})
|
||||
(block-handler/with-dummy-block raw-blocks format nil {:journal? true})
|
||||
(db/with-block-refs-count repo))]
|
||||
(blocks-inner blocks page document-mode?)))
|
||||
|
||||
|
|
|
@ -35,7 +35,8 @@
|
|||
[cljs-time.core :as t]
|
||||
[cljs.pprint :as pprint]
|
||||
[frontend.context.i18n :as i18n]
|
||||
[reitit.frontend.easy :as rfe]))
|
||||
[reitit.frontend.easy :as rfe]
|
||||
[frontend.handler.block :as block-handler]))
|
||||
|
||||
(defn- get-page-name
|
||||
[state]
|
||||
|
@ -55,7 +56,7 @@
|
|||
db-mixins/query
|
||||
[repo page file-path page-name page-original-name encoded-page-name sidebar? journal? block? block-id format]
|
||||
(let [raw-page-blocks (get-blocks repo page-name page-original-name block? block-id)
|
||||
page-blocks (db/with-dummy-block raw-page-blocks format
|
||||
page-blocks (block-handler/with-dummy-block raw-page-blocks format
|
||||
(if (empty? raw-page-blocks)
|
||||
(let [content (db/get-file repo file-path)]
|
||||
{:block/page {:db/id (:db/id page)}
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
|
||||
[frontend.db.model
|
||||
entity pull pull-many
|
||||
add-properties! add-q! add-query-component! block-and-children-transform blocks-count blocks-count-cache clean-export! clear-query-state! clear-query-state-without-refs-and-embeds! cloned? delete-blocks delete-file! delete-file-blocks! delete-file-pages! delete-file-tx delete-files delete-pages-by-files filter-only-public-pages-and-blocks get-alias-page get-all-block-contents get-all-tagged-pages get-all-tags get-all-templates get-block-and-children get-block-and-children-no-cache get-block-blocks-cache-atom get-block-by-uuid get-block-children get-block-children-ids get-block-content get-block-file get-block-immediate-children get-block-page get-block-page-end-pos get-block-parent get-block-parents get-block-referenced-blocks get-block-refs-count get-blocks-by-priority get-blocks-contents get-collapsed-blocks get-config get-custom-css get-date-scheduled-or-deadlines get-db-type get-empty-pages get-file get-file-after-blocks get-file-after-blocks-meta get-file-blocks get-file-contents get-file-last-modified-at get-file-no-sub get-file-page get-file-page-id get-file-pages get-files get-files-blocks get-files-full get-files-that-referenced-page get-journals-length get-key-value get-latest-journals get-marker-blocks get-matched-blocks get-page get-page-alias get-page-alias-names get-page-blocks get-page-blocks-cache-atom get-page-blocks-count get-page-blocks-no-cache get-page-file get-page-format get-page-name get-page-properties get-page-properties-content get-page-referenced-blocks get-page-referenced-pages get-page-unlinked-references get-pages get-pages-relation get-pages-that-mentioned-page get-pages-with-modified-at get-public-pages get-tag-pages journal-page? kv local-native-fs? mark-repo-as-cloned! page-alias-set page-blocks-transform pull-block q query-components query-entity-in-component query-state rebuild-page-blocks-children remove-custom-query! remove-key! remove-q! remove-query-component! reset-config! set-file-last-modified-at! set-new-result! sub-key-value template-exists? transact! transact-files-db! with-block-refs-count with-dummy-block with-latest-txs!]
|
||||
add-properties! add-q! add-query-component! block-and-children-transform blocks-count blocks-count-cache clean-export! clear-query-state! clear-query-state-without-refs-and-embeds! cloned? delete-blocks delete-file! delete-file-blocks! delete-file-pages! delete-file-tx delete-files delete-pages-by-files filter-only-public-pages-and-blocks get-alias-page get-all-block-contents get-all-tagged-pages get-all-tags get-all-templates get-block-and-children get-block-and-children-no-cache get-block-blocks-cache-atom get-block-by-uuid get-block-children get-block-children-ids get-block-content get-block-file get-block-immediate-children get-block-page get-block-page-end-pos get-block-parent get-block-parents get-block-referenced-blocks get-block-refs-count get-blocks-by-priority get-blocks-contents get-collapsed-blocks get-config get-custom-css get-date-scheduled-or-deadlines get-db-type get-empty-pages get-file get-file-after-blocks get-file-after-blocks-meta get-file-blocks get-file-contents get-file-last-modified-at get-file-no-sub get-file-page get-file-page-id get-file-pages get-files get-files-blocks get-files-full get-files-that-referenced-page get-journals-length get-key-value get-latest-journals get-marker-blocks get-matched-blocks get-page get-page-alias get-page-alias-names get-page-blocks get-page-blocks-cache-atom get-page-blocks-count get-page-blocks-no-cache get-page-file get-page-format get-page-name get-page-properties get-page-properties-content get-page-referenced-blocks get-page-referenced-pages get-page-unlinked-references get-pages get-pages-relation get-pages-that-mentioned-page get-pages-with-modified-at get-public-pages get-tag-pages journal-page? kv local-native-fs? mark-repo-as-cloned! page-alias-set page-blocks-transform pull-block q query-components query-entity-in-component query-state rebuild-page-blocks-children remove-custom-query! remove-key! remove-q! remove-query-component! reset-config! set-file-last-modified-at! set-new-result! sub-key-value template-exists? transact! transact-files-db! with-block-refs-count]
|
||||
|
||||
[frontend.db.react
|
||||
get-current-marker get-current-page get-current-priority get-handler-keys set-file-content! set-key-value transact-react!]
|
||||
|
|
|
@ -971,48 +971,6 @@
|
|||
(get-page-format page)])
|
||||
pages)))))
|
||||
|
||||
(defn with-dummy-block
|
||||
([blocks format]
|
||||
(with-dummy-block blocks format {} {}))
|
||||
([blocks format default-option {:keys [journal? page-name]
|
||||
:or {journal? false}}]
|
||||
(let [format (or format (state/get-preferred-format) :markdown)
|
||||
blocks (if (and journal?
|
||||
(seq blocks)
|
||||
(when-let [title (second (first (:block/title (first blocks))))]
|
||||
(date/valid-journal-title? title)))
|
||||
(rest blocks)
|
||||
blocks)
|
||||
blocks (vec blocks)]
|
||||
(cond
|
||||
(and (seq blocks)
|
||||
(or (and (> (count blocks) 1)
|
||||
(:block/pre-block? (first blocks)))
|
||||
(and (>= (count blocks) 1)
|
||||
(not (:block/pre-block? (first blocks))))))
|
||||
blocks
|
||||
|
||||
:else
|
||||
(let [last-block (last blocks)
|
||||
end-pos (get-in last-block [:block/meta :end-pos] 0)
|
||||
dummy (merge last-block
|
||||
(let [uuid (d/squuid)]
|
||||
{:block/uuid uuid
|
||||
:block/title ""
|
||||
:block/content (config/default-empty-block format)
|
||||
:block/format format
|
||||
:block/level 2
|
||||
:block/priority nil
|
||||
:block/anchor (str uuid)
|
||||
:block/meta {:start-pos end-pos
|
||||
:end-pos end-pos}
|
||||
:block/body nil
|
||||
:block/dummy? true
|
||||
:block/marker nil
|
||||
:block/pre-block? false})
|
||||
default-option)]
|
||||
(conj blocks dummy))))))
|
||||
|
||||
;; get pages that this page referenced
|
||||
(defn get-page-referenced-pages
|
||||
[repo page]
|
||||
|
@ -1254,14 +1212,6 @@
|
|||
(state/set-config! repo-url config)
|
||||
config)))
|
||||
|
||||
(defn with-latest-txs!
|
||||
[db repo file?]
|
||||
(let [txs (state/get-repo-latest-txs repo file?)
|
||||
tx-data (when (seq txs) (map :tx-data txs))]
|
||||
(if (seq tx-data)
|
||||
(d/db-with db tx-data)
|
||||
db)))
|
||||
|
||||
(defn get-db-type
|
||||
[repo]
|
||||
(get-key-value repo :db/type))
|
||||
|
|
|
@ -3,7 +3,10 @@
|
|||
[clojure.walk :as walk]
|
||||
[frontend.db :as db]
|
||||
[frontend.state :as state]
|
||||
[frontend.format.mldoc :as mldoc]))
|
||||
[frontend.format.mldoc :as mldoc]
|
||||
[frontend.date :as date]
|
||||
[frontend.config :as config]
|
||||
[datascript.core :as d]))
|
||||
|
||||
(defn blocks->vec-tree [col]
|
||||
(let [col (map (fn [h] (cond->
|
||||
|
@ -134,3 +137,45 @@
|
|||
(every? (fn [[[typ break-lines]] _]
|
||||
(and (= typ "Paragraph")
|
||||
(every? #(= % ["Break_Line"]) break-lines))) (rest ast))))))))
|
||||
|
||||
(defn with-dummy-block
|
||||
([blocks format]
|
||||
(with-dummy-block blocks format {} {}))
|
||||
([blocks format default-option {:keys [journal? page-name]
|
||||
:or {journal? false}}]
|
||||
(let [format (or format (state/get-preferred-format) :markdown)
|
||||
blocks (if (and journal?
|
||||
(seq blocks)
|
||||
(when-let [title (second (first (:block/title (first blocks))))]
|
||||
(date/valid-journal-title? title)))
|
||||
(rest blocks)
|
||||
blocks)
|
||||
blocks (vec blocks)]
|
||||
(cond
|
||||
(and (seq blocks)
|
||||
(or (and (> (count blocks) 1)
|
||||
(:block/pre-block? (first blocks)))
|
||||
(and (>= (count blocks) 1)
|
||||
(not (:block/pre-block? (first blocks))))))
|
||||
blocks
|
||||
|
||||
:else
|
||||
(let [last-block (last blocks)
|
||||
end-pos (get-in last-block [:block/meta :end-pos] 0)
|
||||
dummy (merge last-block
|
||||
(let [uuid (d/squuid)]
|
||||
{:block/uuid uuid
|
||||
:block/title ""
|
||||
:block/content (config/default-empty-block format)
|
||||
:block/format format
|
||||
:block/level 2
|
||||
:block/priority nil
|
||||
:block/anchor (str uuid)
|
||||
:block/meta {:start-pos end-pos
|
||||
:end-pos end-pos}
|
||||
:block/body nil
|
||||
:block/dummy? true
|
||||
:block/marker nil
|
||||
:block/pre-block? false})
|
||||
default-option)]
|
||||
(conj blocks dummy))))))
|
Loading…
Reference in New Issue