From a64f49dc6fca75e3c7f7aa9b64f4e7a04adefcbd Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Wed, 24 Jan 2024 01:52:55 +0800 Subject: [PATCH] Remove :block/marker and :block/priority from tx-data --- deps/common/src/logseq/common/marker.cljs | 13 ++++++ deps/outliner/src/logseq/outliner/core.cljs | 40 +++++++++++++++++-- .../frontend/handler/file_based/status.cljs | 8 ++-- 3 files changed, 53 insertions(+), 8 deletions(-) create mode 100644 deps/common/src/logseq/common/marker.cljs diff --git a/deps/common/src/logseq/common/marker.cljs b/deps/common/src/logseq/common/marker.cljs new file mode 100644 index 000000000..f6ce27927 --- /dev/null +++ b/deps/common/src/logseq/common/marker.cljs @@ -0,0 +1,13 @@ +(ns logseq.common.marker + "marker patterns" + (:require [clojure.string :as string])) + +(defn marker-pattern [format] + (re-pattern + (str "^" (if (= format :markdown) "(#+\\s+)?" "(\\*+\\s+)?") + "(NOW|LATER|TODO|DOING|DONE|WAITING|WAIT|CANCELED|CANCELLED|IN-PROGRESS)?\\s?"))) + + +(defn clean-marker + [content format] + (string/replace-first content (marker-pattern format) "")) diff --git a/deps/outliner/src/logseq/outliner/core.cljs b/deps/outliner/src/logseq/outliner/core.cljs index 017d02e7e..1bd69fb86 100644 --- a/deps/outliner/src/logseq/outliner/core.cljs +++ b/deps/outliner/src/logseq/outliner/core.cljs @@ -17,7 +17,8 @@ [logseq.db.frontend.property :as db-property] [logseq.db.sqlite.util :as sqlite-util] [cljs.pprint :as pprint] - [logseq.db.frontend.content :as db-content])) + [logseq.db.frontend.content :as db-content] + [logseq.common.marker :as common-marker])) (def ^:private block-map (mu/optional-keys @@ -257,6 +258,36 @@ ;; -get-id, -get-parent-id, -get-left-id return block-id ;; the :block/parent, :block/left should be datascript lookup ref +;; TODO: don't parse marker and deprecate typing marker to set status +(defn- db-marker-handle + [conn m] + (or + (let [marker (:block/marker m) + property (db-property/get-property @conn "status") + matched-status-id (when marker + (->> (get-in property [:block/schema :values]) + (some (fn [id] + (let [value-e (d/entity @conn [:block/uuid id]) + value (get-in value-e [:block/schema :value])] + (when (= (string/lower-case marker) (string/lower-case value)) + id))))))] + (cond-> m + matched-status-id + (update :block/properties assoc (:block/uuid property) matched-status-id) + + matched-status-id + (update :block/content (fn [content] + (common-marker/clean-marker content (get m :block/format :markdown)))) + matched-status-id + (update :db/other-tx (fn [tx] + (if-let [task (d/entity @conn [:block/name "task"])] + (conj tx [:db/add (:db/id m) :block/tags (:db/id task)]) + tx))) + + true + (dissoc :block/marker :block/priority))) + m)) + (extend-type Block otree/INode (-get-id [this conn] @@ -320,7 +351,7 @@ block-uuid (:block/uuid (:data this)) eid (or db-id (when block-uuid [:block/uuid block-uuid])) block-entity (d/entity db eid) - m (if (and (:block/content m) db-based?) + m' (if (and (:block/content m) db-based?) (update m :block/content (fn [content] (db-content/content-without-tags @@ -332,7 +363,10 @@ (str db-content/page-ref-special-chars (:block/uuid tag)))) (:block/tags m)) (remove nil?))))) - m)] + m) + m (cond->> m' + db-based? + (db-marker-handle conn))] ;; Ensure block UUID never changes (when (and db-id block-uuid) diff --git a/src/main/frontend/handler/file_based/status.cljs b/src/main/frontend/handler/file_based/status.cljs index 242e67388..1ffc5559a 100644 --- a/src/main/frontend/handler/file_based/status.cljs +++ b/src/main/frontend/handler/file_based/status.cljs @@ -1,12 +1,10 @@ (ns frontend.handler.file-based.status "Task (formerly todo) related util fns" (:require [clojure.string :as string] - [frontend.util :as util])) + [frontend.util :as util] + [logseq.common.marker :as common-marker])) -(defn marker-pattern [format] - (re-pattern - (str "^" (if (= format :markdown) "(#+\\s+)?" "(\\*+\\s+)?") - "(NOW|LATER|TODO|DOING|DONE|WAITING|WAIT|CANCELED|CANCELLED|IN-PROGRESS)?\\s?"))) +(def marker-pattern common-marker/marker-pattern) (def bare-marker-pattern #"(NOW|LATER|TODO|DOING|DONE|WAITING|WAIT|CANCELED|CANCELLED|IN-PROGRESS){1}\s+")