Przeglądaj źródła

remove file based commands

Tienson Qin 3 dni temu
rodzic
commit
bbe6fa861e

+ 53 - 299
src/main/frontend/commands.cljs

@@ -1,29 +1,21 @@
 (ns frontend.commands
 (ns frontend.commands
   "Provides functionality for commands and advanced commands"
   "Provides functionality for commands and advanced commands"
   (:require [clojure.string :as string]
   (:require [clojure.string :as string]
-            [frontend.config :as config]
             [frontend.date :as date]
             [frontend.date :as date]
             [frontend.db :as db]
             [frontend.db :as db]
             [frontend.extensions.video.youtube :as youtube]
             [frontend.extensions.video.youtube :as youtube]
             [frontend.handler.db-based.property :as db-property-handler]
             [frontend.handler.db-based.property :as db-property-handler]
             [frontend.handler.db-based.property.util :as db-pu]
             [frontend.handler.db-based.property.util :as db-pu]
-            [frontend.handler.file-based.property :as file-property-handler]
-            [frontend.handler.file-based.status :as file-based-status]
             [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.file :as property-file]
             [frontend.search :as search]
             [frontend.search :as search]
             [frontend.state :as state]
             [frontend.state :as state]
             [frontend.util :as util]
             [frontend.util :as util]
             [frontend.util.cursor :as cursor]
             [frontend.util.cursor :as cursor]
-            [frontend.util.file-based.priority :as priority]
-            [frontend.util.ref :as ref]
             [goog.dom :as gdom]
             [goog.dom :as gdom]
             [goog.object :as gobj]
             [goog.object :as gobj]
-            [logseq.common.config :as common-config]
             [logseq.common.util :as common-util]
             [logseq.common.util :as common-util]
             [logseq.common.util.block-ref :as block-ref]
             [logseq.common.util.block-ref :as block-ref]
-            [logseq.common.util.macro :as macro-util]
             [logseq.common.util.page-ref :as page-ref]
             [logseq.common.util.page-ref :as page-ref]
             [logseq.graph-parser.property :as gp-property]
             [logseq.graph-parser.property :as gp-property]
             [promesa.core :as p]))
             [promesa.core :as p]))
@@ -75,10 +67,6 @@
                          :id :label
                          :id :label
                          :placeholder "Label"}]]])
                          :placeholder "Label"}]]])
 
 
-(defn zotero-steps []
-  [[:editor/input (str command-trigger "zotero")]
-   [:editor/show-zotero]])
-
 (def *extend-slash-commands (atom []))
 (def *extend-slash-commands (atom []))
 
 
 (defn register-slash-command [cmd]
 (defn register-slash-command [cmd]
@@ -103,36 +91,11 @@
     [[:editor/input template {:last-pattern command-trigger
     [[:editor/input template {:last-pattern command-trigger
                               :backward-pos 2}]]))
                               :backward-pos 2}]]))
 
 
-(defn file-based-embed-page
-  []
-  [[:editor/input "{{embed [[]]}}" {:last-pattern command-trigger
-                                    :backward-pos 4}]
-   [:editor/search-page :embed]])
-
-(defn file-based-embed-block
-  []
-  [[:editor/input "{{embed (())}}" {:last-pattern command-trigger
-                                    :backward-pos 4}]
-   [:editor/search-block :embed]])
-
-(defn file-based-statuses
-  []
-  (let [workflow (state/get-preferred-workflow)]
-    (if (= :now workflow)
-      ["LATER" "NOW" "TODO" "DOING" "DONE" "WAITING" "CANCELED"]
-      ["TODO" "DOING" "LATER" "NOW" "DONE" "WAITING" "CANCELED"])))
-
 (defn db-based-statuses
 (defn db-based-statuses
   []
   []
   (map (fn [e] (:block/title e))
   (map (fn [e] (:block/title e))
        (db-pu/get-closed-property-values :logseq.property/status)))
        (db-pu/get-closed-property-values :logseq.property/status)))
 
 
-(defn db-based-embed-page
-  []
-  [[:editor/input "[[]]" {:last-pattern command-trigger
-                          :backward-pos 2}]
-   [:editor/search-page :embed]])
-
 (defn db-based-embed-block
 (defn db-based-embed-block
   []
   []
   [[:editor/input "" {:last-pattern command-trigger}]
   [[:editor/input "" {:last-pattern command-trigger}]
@@ -143,64 +106,24 @@
   [[:editor/input "" {:last-pattern command-trigger}]
   [[:editor/input "" {:last-pattern command-trigger}]
    [:editor/run-query-command]])
    [:editor/run-query-command]])
 
 
-(defn file-based-query
-  []
-  [[:editor/input (str macro-util/query-macro " }}") {:backward-pos 2}]
-   [:editor/exit]])
-
 (defn query-steps
 (defn query-steps
   []
   []
-  (if (config/db-based-graph? (state/get-current-repo))
-    (db-based-query)
-    (file-based-query)))
+  (db-based-query))
 
 
 (defn- calc-steps
 (defn- calc-steps
   []
   []
-  (if (config/db-based-graph? (state/get-current-repo))
-    [[:editor/input "" {:last-pattern command-trigger}]
-     [:editor/upsert-type-block :code "calc"]
-     [:codemirror/focus]]
-    [[:editor/input "```calc\n\n```" {:type "block"
-                                      :backward-pos 4}]
-     [:codemirror/focus]]))
-
-(defn ->block
-  ([type]
-   (->block type nil))
-  ([type optional]
-   (let [format (get (state/get-edit-block) :block/format)
-         markdown-src? (and (= format :markdown)
-                            (= (string/lower-case type) "src"))
-         [left right] (cond
-                        markdown-src?
-                        ["```" "\n```"]
-
-                        :else
-                        (->> ["#+BEGIN_%s" "\n#+END_%s"]
-                             (map #(util/format %
-                                                (string/upper-case type)))))
-         template (str
-                   left
-                   (if optional (str " " optional) "")
-                   "\n"
-                   right)
-         backward-pos (if (= type "src")
-                        (+ 1 (count right))
-                        (count right))]
-     [[:editor/input template {:type "block"
-                               :last-pattern command-trigger
-                               :backward-pos backward-pos}]])))
+  [[:editor/input "" {:last-pattern command-trigger}]
+   [:editor/upsert-type-block :code "calc"]
+   [:codemirror/focus]])
 
 
 (defn- advanced-query-steps
 (defn- advanced-query-steps
   []
   []
-  (if (config/db-based-graph? (state/get-current-repo))
-    [[:editor/input "" {:last-pattern command-trigger}]
-     [:editor/set-property :block/tags :logseq.class/Query]
-     [:editor/set-property :logseq.property/query ""]
-     [:editor/set-property-on-block-property :logseq.property/query :logseq.property.node/display-type :code]
-     [:editor/set-property-on-block-property :logseq.property/query :logseq.property.code/lang "clojure"]
-     [:editor/exit]]
-    (->block "query")))
+  [[:editor/input "" {:last-pattern command-trigger}]
+   [:editor/set-property :block/tags :logseq.class/Query]
+   [:editor/set-property :logseq.property/query ""]
+   [:editor/set-property-on-block-property :logseq.property/query :logseq.property.node/display-type :code]
+   [:editor/set-property-on-block-property :logseq.property/query :logseq.property.code/lang "clojure"]
+   [:editor/exit]])
 
 
 (defn db-based-code-block
 (defn db-based-code-block
   []
   []
@@ -208,55 +131,33 @@
    [:editor/upsert-type-block :code]
    [:editor/upsert-type-block :code]
    [:editor/exit]])
    [:editor/exit]])
 
 
-(defn file-based-code-block
-  []
-  [[:editor/input "```\n```\n" {:type "block"
-                                :backward-pos 5
-                                :only-breakline? true}]
-   [:editor/select-code-block-mode]])
-
 (defn code-block-steps
 (defn code-block-steps
   []
   []
-  (if (config/db-based-graph? (state/get-current-repo))
-    (db-based-code-block)
-    (file-based-code-block)))
+  (db-based-code-block))
 
 
 (defn quote-block-steps
 (defn quote-block-steps
   []
   []
-  (if (config/db-based-graph? (state/get-current-repo))
-    [[:editor/input "" {:last-pattern command-trigger}]
-     [:editor/set-property :logseq.property.node/display-type :quote]]
-    (->block "quote")))
+  [[:editor/input "" {:last-pattern command-trigger}]
+   [:editor/set-property :logseq.property.node/display-type :quote]])
 
 
 (defn math-block-steps
 (defn math-block-steps
   []
   []
-  (if (config/db-based-graph? (state/get-current-repo))
-    [[:editor/input "" {:last-pattern command-trigger}]
-     [:editor/set-property :logseq.property.node/display-type :math]]
-    (->block "export" "latex")))
+  [[:editor/input "" {:last-pattern command-trigger}]
+   [:editor/set-property :logseq.property.node/display-type :math]])
 
 
 (defn get-statuses
 (defn get-statuses
   []
   []
-  (let [db-based? (config/db-based-graph? (state/get-current-repo))
-        result (->>
-                (if db-based?
-                  (db-based-statuses)
-                  (file-based-statuses))
+  (let [result (->>
+                (db-based-statuses)
                 (mapv (fn [command]
                 (mapv (fn [command]
-                        (let [icon (if db-based?
-                                     (case command
-                                       "Canceled" "Cancelled"
-                                       "Doing" "InProgress50"
-                                       command)
-                                     "square-asterisk")]
+                        (let [icon (case command
+                                     "Canceled" "Cancelled"
+                                     "Doing" "InProgress50"
+                                     command)]
                           [command (->marker command) (str "Set status to " command) icon]))))]
                           [command (->marker command) (str "Set status to " command) icon]))))]
     (when (seq result)
     (when (seq result)
       (map (fn [v] (conj v "TASK STATUS")) result))))
       (map (fn [v] (conj v "TASK STATUS")) result))))
 
 
-(defn file-based-priorities
-  []
-  ["A" "B" "C"])
-
 (defn db-based-priorities
 (defn db-based-priorities
   []
   []
   (map (fn [e] (str "Priority " (:block/title e)))
   (map (fn [e] (str "Priority " (:block/title e)))
@@ -264,21 +165,16 @@
 
 
 (defn get-priorities
 (defn get-priorities
   []
   []
-  (let [db-based? (config/db-based-graph? (state/get-current-repo))
-        with-no-priority #(if db-based? (cons ["No priority" (->priority nil) "" :icon/priorityLvlNone] %) %)
+  (let [with-no-priority #(cons ["No priority" (->priority nil) "" :icon/priorityLvlNone] %)
         result (->>
         result (->>
-                (if db-based?
-                  (db-based-priorities)
-                  (file-based-priorities))
+                (db-based-priorities)
                 (mapv (fn [item]
                 (mapv (fn [item]
                         (let [command item
                         (let [command item
                               item (string/replace item #"^Priority " "")]
                               item (string/replace item #"^Priority " "")]
                           [command
                           [command
                            (->priority item)
                            (->priority item)
                            (str "Set priority to " item)
                            (str "Set priority to " item)
-                           (if db-based?
-                             (str "priorityLvl" item)
-                             (str "circle-letter-" (util/safe-lower-case item)))])))
+                           (str "priorityLvl" item)])))
                 (with-no-priority)
                 (with-no-priority)
                 (vec))]
                 (vec))]
     (when (seq result)
     (when (seq result)
@@ -302,35 +198,21 @@
 (defonce *matched-commands (atom nil))
 (defonce *matched-commands (atom nil))
 (defonce *initial-commands (atom nil))
 (defonce *initial-commands (atom nil))
 
 
-(defn ->properties
-  []
-  [[:editor/clear-current-slash]
-   [:editor/insert-properties]
-   [:editor/move-cursor-to-properties]])
-
 (defn ^:large-vars/cleanup-todo commands-map
 (defn ^:large-vars/cleanup-todo commands-map
   [get-page-ref-text]
   [get-page-ref-text]
-  (let [db? (config/db-based-graph? (state/get-current-repo))
-        embed-page (if db? db-based-embed-page file-based-embed-page)
-        embed-block (if db? db-based-embed-block file-based-embed-block)]
+  (let [embed-block db-based-embed-block]
     (->>
     (->>
      (concat
      (concat
         ;; basic
         ;; basic
-      [[(if db? "Node reference" "Page reference")
+      [["Node reference"
         [[:editor/input page-ref/left-and-right-brackets {:backward-pos 2}]
         [[:editor/input page-ref/left-and-right-brackets {:backward-pos 2}]
          [:editor/search-page]]
          [:editor/search-page]]
-        (if db? "Create a backlink to a node (a page or a block)"
-            "Create a backlink to a BLOCK")
+        "Create a backlink to a node (a page or a block)"
         :icon/pageRef
         :icon/pageRef
         "BASIC"]
         "BASIC"]
-       (when-not db? ["Page embed" (embed-page) "Embed a page here" :icon/pageEmbed])
-       (when-not db?
-         ["Block reference" [[:editor/input block-ref/left-and-right-parens {:backward-pos 2}]
-                             [:editor/search-block :reference]]
-          "Create a backlink to a block" :icon/blockRef])
-       [(if db? "Node embed" "Block embed")
+       ["Node embed"
         (embed-block)
         (embed-block)
-        (if db? "Embed a node here" "Embed a block here")
+        "Embed a node here"
         :icon/blockEmbed]]
         :icon/blockEmbed]]
 
 
         ;; format
         ;; format
@@ -399,33 +281,9 @@
         "Number children"
         "Number children"
         :icon/numberedChildren]]
         :icon/numberedChildren]]
 
 
-      ;; https://orgmode.org/manual/Structure-Templates.html
-      (when-not db?
-        (cond->
-         [;; Should this be replaced by "Code block"?
-          ["Src" (->block "src") "Create a code block"]
-          ["Math block" (->block "export" "latex") "Create a latex block"]
-          ["Note" (->block "note") "Create a note block"]
-          ["Tip" (->block "tip") "Create a tip block"]
-          ["Important" (->block "important") "Create an important block"]
-          ["Caution" (->block "caution") "Create a caution block"]
-          ["Pinned" (->block "pinned") "Create a pinned block"]
-          ["Warning" (->block "warning") "Create a warning block"]
-          ["Example" (->block "example") "Create an example block"]
-          ["Export" (->block "export") "Create an export block"]
-          ["Verse" (->block "verse") "Create a verse block"]
-          ["Ascii" (->block "export" "ascii") "Create an ascii block"]
-          ["Center" (->block "center") "Create a center block"]]
-
-        ;; FIXME: current page's format
-          (= :org (state/get-preferred-format))
-          (conj ["Properties" (->properties)])))
-
       ;; advanced
       ;; advanced
       [["Query" (query-steps) query-doc :icon/query "ADVANCED"]
       [["Query" (query-steps) query-doc :icon/query "ADVANCED"]
        ["Advanced Query" (advanced-query-steps) "Create an advanced query block" :icon/query]
        ["Advanced Query" (advanced-query-steps) "Create an advanced query block" :icon/query]
-       (when-not db?
-         ["Zotero" (zotero-steps) "Import Zotero journal article" :icon/circle-letter-z])
        ["Query function" [[:editor/input "{{function }}" {:backward-pos 2}]] "Create a query function" :icon/queryCode]
        ["Query function" [[:editor/input "{{function }}" {:backward-pos 2}]] "Create a query function" :icon/queryCode]
        ["Calculator"
        ["Calculator"
         (calc-steps)
         (calc-steps)
@@ -452,15 +310,13 @@
                                                             :backward-pos 2}]] ""
                                                             :backward-pos 2}]] ""
         :icon/xEmbed]
         :icon/xEmbed]
 
 
-       (when db?
-         ["Add new property" [[:editor/clear-current-slash]
-                              [:editor/new-property]] ""
-          :icon/cube-plus])]
+       ["Add new property" [[:editor/clear-current-slash]
+                            [:editor/new-property]] ""
+        :icon/cube-plus]]
 
 
-      (let [commands (cond->> @*extend-slash-commands
-                       db?
-                       (remove (fn [command] (when (map? (last command))
-                                               (false? (:db-graph? (last command)))))))]
+      (let [commands (->> @*extend-slash-commands
+                          (remove (fn [command] (when (map? (last command))
+                                                  (false? (:db-graph? (last command)))))))]
         commands)
         commands)
 
 
 ;; Allow user to modify or extend, should specify how to extend.
 ;; Allow user to modify or extend, should specify how to extend.
@@ -700,83 +556,28 @@
                                                new-value
                                                new-value
                                                (count prefix))))))
                                                (count prefix))))))
 
 
-(defn compute-pos-delta-when-change-marker
-  [edit-content marker pos]
-  (let [old-marker (some->> (first (util/safe-re-find file-based-status/bare-marker-pattern edit-content))
-                            (string/trim))
-        pos-delta (- (count marker)
-                     (count old-marker))
-        pos-delta (cond (string/blank? old-marker)
-                        (inc pos-delta)
-                        (string/blank? marker)
-                        (dec pos-delta)
-
-                        :else
-                        pos-delta)]
-    (max (+ pos pos-delta) 0)))
-
-(defn- file-based-set-status
-  [marker format]
-  (when-let [input-id (state/get-edit-input-id)]
-    (when-let [current-input (gdom/getElement input-id)]
-      (let [edit-content (gobj/get current-input "value")
-            slash-pos (:pos (:pos (state/get-editor-action-data)))
-            [re-pattern new-line-re-pattern] (if (= :org format)
-                                               [#"\*+\s" #"\n\*+\s"]
-                                               [#"#+\s" #"\n#+\s"])
-            pos (let [prefix (subs edit-content 0 (dec slash-pos))]
-                  (if-let [matches (seq (util/re-pos new-line-re-pattern prefix))]
-                    (let [[start-pos content] (last matches)]
-                      (+ start-pos (count content)))
-                    (count (util/safe-re-find re-pattern prefix))))
-            new-value (str (subs edit-content 0 pos)
-                           (string/replace-first (subs edit-content pos)
-                                                 (file-based-status/marker-pattern format)
-                                                 (str marker " ")))]
-        (state/set-edit-content! input-id new-value)
-        (let [new-pos (compute-pos-delta-when-change-marker
-                       edit-content marker (dec slash-pos))]
-          ;; TODO: any performance issue?
-          (js/setTimeout #(cursor/move-cursor-to current-input new-pos) 10))))))
-
 (defn- db-based-set-status
 (defn- db-based-set-status
   [status]
   [status]
   (when-let [block (state/get-edit-block)]
   (when-let [block (state/get-edit-block)]
     (db-property-handler/batch-set-property-closed-value! [(:block/uuid block)] :logseq.property/status status)))
     (db-property-handler/batch-set-property-closed-value! [(:block/uuid block)] :logseq.property/status status)))
 
 
-(defmethod handle-step :editor/set-status [[_ status] format]
-  (if (config/db-based-graph? (state/get-current-repo))
-    (db-based-set-status status)
-    (file-based-set-status status format)))
+(defmethod handle-step :editor/set-status [[_ status] _format]
+  (db-based-set-status status))
 
 
 (defmethod handle-step :editor/set-property [[_ property-id value]]
 (defmethod handle-step :editor/set-property [[_ property-id value]]
-  (when (config/db-based-graph? (state/get-current-repo))
-    (when-let [block (state/get-edit-block)]
-      (db-property-handler/set-block-property! (:db/id block) property-id value))))
+  (when-let [block (state/get-edit-block)]
+    (db-property-handler/set-block-property! (:db/id block) property-id value)))
 
 
 (defmethod handle-step :editor/set-property-on-block-property [[_ block-property-id property-id value]]
 (defmethod handle-step :editor/set-property-on-block-property [[_ block-property-id property-id value]]
-  (let [repo (state/get-current-repo)]
-    (when (config/db-based-graph? repo)
-      (let [updated-block (when-let [block-uuid (:block/uuid (state/get-edit-block))]
-                            (db/entity [:block/uuid block-uuid]))
-            block-property-value (get updated-block block-property-id)]
-        (when block-property-value
-          (db-property-handler/set-block-property! (:db/id block-property-value) property-id value))))))
+  (let [updated-block (when-let [block-uuid (:block/uuid (state/get-edit-block))]
+                        (db/entity [:block/uuid block-uuid]))
+        block-property-value (get updated-block block-property-id)]
+    (when block-property-value
+      (db-property-handler/set-block-property! (:db/id block-property-value) property-id value))))
 
 
 (defmethod handle-step :editor/upsert-type-block [[_ type lang]]
 (defmethod handle-step :editor/upsert-type-block [[_ type lang]]
-  (when (config/db-based-graph? (state/get-current-repo))
-    (when-let [block (state/get-edit-block)]
-      (state/pub-event! [:editor/upsert-type-block {:block block :type type :lang lang}]))))
-
-(defn- file-based-set-priority
-  [priority]
-  (when-let [input-id (state/get-edit-input-id)]
-    (when-let [current-input (gdom/getElement input-id)]
-      (let [format (or (db/get-page-format (state/get-current-page)) (state/get-preferred-format))
-            edit-content (gobj/get current-input "value")
-            new-priority (util/format "[#%s]" priority)
-            new-value (string/trim (priority/add-or-update-priority edit-content format new-priority))]
-        (state/set-edit-content! input-id new-value)))))
+  (when-let [block (state/get-edit-block)]
+    (state/pub-event! [:editor/upsert-type-block {:block block :type type :lang lang}])))
 
 
 (defn- db-based-set-priority
 (defn- db-based-set-priority
   [priority]
   [priority]
@@ -786,59 +587,24 @@
       (db-property-handler/batch-set-property-closed-value! [(:block/uuid block)] :logseq.property/priority priority))))
       (db-property-handler/batch-set-property-closed-value! [(:block/uuid block)] :logseq.property/priority priority))))
 
 
 (defmethod handle-step :editor/set-priority [[_ priority] _format]
 (defmethod handle-step :editor/set-priority [[_ priority] _format]
-  (if (config/db-based-graph? (state/get-current-repo))
-    (db-based-set-priority priority)
-    (file-based-set-priority priority)))
+  (db-based-set-priority priority))
 
 
 (defmethod handle-step :editor/set-scheduled [[_]]
 (defmethod handle-step :editor/set-scheduled [[_]]
-  (if (config/db-based-graph? (state/get-current-repo))
-    (state/pub-event! [:editor/new-property {:property-key "Scheduled"}])
-    (handle-step [:editor/show-date-picker :scheduled])))
+  (state/pub-event! [:editor/new-property {:property-key "Scheduled"}]))
 
 
 (defmethod handle-step :editor/set-deadline [[_]]
 (defmethod handle-step :editor/set-deadline [[_]]
-  (if (config/db-based-graph? (state/get-current-repo))
-    (state/pub-event! [:editor/new-property {:property-key "Deadline"}])
-    (handle-step [:editor/show-date-picker :deadline])))
+  (state/pub-event! [:editor/new-property {:property-key "Deadline"}]))
 
 
 (defmethod handle-step :editor/run-query-command [[_]]
 (defmethod handle-step :editor/run-query-command [[_]]
   (state/pub-event! [:editor/run-query-command]))
   (state/pub-event! [:editor/run-query-command]))
 
 
-(defmethod handle-step :editor/insert-properties [[_ _] _format]
-  (when-let [input-id (state/get-edit-input-id)]
-    (when-let [current-input (gdom/getElement input-id)]
-      (let [format (or (db/get-page-format (state/get-current-page)) (state/get-preferred-format))
-            edit-content (gobj/get current-input "value")
-            new-value (file-property-handler/insert-property format edit-content "" "")]
-        (state/set-edit-content! input-id new-value)))))
-
-(defmethod handle-step :editor/move-cursor-to-properties [[_]]
-  (when-let [input-id (state/get-edit-input-id)]
-    (when-let [current-input (gdom/getElement input-id)]
-      (let [format (or (db/get-page-format (state/get-current-page)) (state/get-preferred-format))]
-        (property-file/goto-properties-end-when-file-based format current-input)
-        (cursor/move-cursor-backward current-input 3)))))
-
-(defn file-based-set-markdown-heading
-  [content heading]
-  (let [heading-str (apply str (repeat heading "#"))]
-    (if (util/safe-re-find common-util/markdown-heading-pattern content)
-      (common-util/clear-markdown-heading content)
-      (str heading-str " " (string/triml content)))))
-
 (def clear-markdown-heading common-util/clear-markdown-heading)
 (def clear-markdown-heading common-util/clear-markdown-heading)
 
 
 (defmethod handle-step :editor/set-heading [[_ heading]]
 (defmethod handle-step :editor/set-heading [[_ heading]]
   (when-let [input-id (state/get-edit-input-id)]
   (when-let [input-id (state/get-edit-input-id)]
-    (when-let [current-input (gdom/getElement input-id)]
-      (let [current-block (state/get-edit-block)
-            format (get current-block :block/format :markdown)]
-        (if (config/db-based-graph?)
-          (state/pub-event! [:editor/set-heading current-block heading])
-          (if (= format :markdown)
-            (let [edit-content (gobj/get current-input "value")
-                  new-content (file-based-set-markdown-heading edit-content heading)]
-              (state/set-edit-content! input-id new-content))
-            (state/pub-event! [:editor/set-heading current-block heading])))))))
+    (when-let [_current-input (gdom/getElement input-id)]
+      (let [current-block (state/get-edit-block)]
+        (state/pub-event! [:editor/set-heading current-block heading])))))
 
 
 (defmethod handle-step :editor/search-page [_]
 (defmethod handle-step :editor/search-page [_]
   (state/set-editor-action! :page-search))
   (state/set-editor-action! :page-search))
@@ -847,7 +613,7 @@
   (state/set-editor-action! :page-search-hashtag))
   (state/set-editor-action! :page-search-hashtag))
 
 
 (defmethod handle-step :editor/search-block [[_ type]]
 (defmethod handle-step :editor/search-block [[_ type]]
-  (when (and (= type :embed) (config/db-based-graph? (state/get-current-repo)))
+  (when (= type :embed)
     (reset! *current-command "Block embed")
     (reset! *current-command "Block embed")
     (state/set-editor-action-data! {:pos (cursor/get-caret-pos (state/get-input))}))
     (state/set-editor-action-data! {:pos (cursor/get-caret-pos (state/get-input))}))
   (state/set-editor-action! :block-search))
   (state/set-editor-action! :block-search))
@@ -858,9 +624,6 @@
 (defmethod handle-step :editor/show-input [[_ option]]
 (defmethod handle-step :editor/show-input [[_ option]]
   (state/set-editor-show-input! option))
   (state/set-editor-show-input! option))
 
 
-(defmethod handle-step :editor/show-zotero [[_]]
-  (state/set-editor-action! :zotero))
-
 (defn insert-youtube-timestamp
 (defn insert-youtube-timestamp
   []
   []
   (let [input-id (state/get-edit-input-id)
   (let [input-id (state/get-edit-input-id)
@@ -897,15 +660,6 @@
       (state/set-timestamp-block! nil)
       (state/set-timestamp-block! nil)
       (state/set-editor-action! :datepicker))))
       (state/set-editor-action! :datepicker))))
 
 
-(defmethod handle-step :editor/select-code-block-mode [[_]]
-  (-> (p/delay 50)
-      (p/then
-       (fn []
-         (when-let [input (state/get-input)]
-            ;; update action cursor position
-           (state/set-editor-action-data! {:pos (cursor/get-caret-pos input)})
-           (state/set-editor-action! :select-code-block-mode))))))
-
 (defmethod handle-step :editor/click-hidden-file-input [[_ _input-id]]
 (defmethod handle-step :editor/click-hidden-file-input [[_ _input-id]]
   (when-let [input-file (gdom/getElement "upload-file")]
   (when-let [input-file (gdom/getElement "upload-file")]
     (.click input-file)))
     (.click input-file)))

+ 1 - 1
src/main/frontend/components/block.cljs

@@ -60,7 +60,7 @@
             [frontend.state :as state]
             [frontend.state :as state]
             [frontend.ui :as ui]
             [frontend.ui :as ui]
             [frontend.util :as util]
             [frontend.util :as util]
-            [frontend.util.file-based.clock :as clock]
+            [frontend.util.clock :as clock]
             [frontend.util.ref :as ref]
             [frontend.util.ref :as ref]
             [frontend.util.text :as text-util]
             [frontend.util.text :as text-util]
             [goog.dom :as gdom]
             [goog.dom :as gdom]

+ 1 - 5
src/main/frontend/handler.cljs

@@ -38,7 +38,6 @@
             [frontend.persist-db.browser :as db-browser]
             [frontend.persist-db.browser :as db-browser]
             [frontend.state :as state]
             [frontend.state :as state]
             [frontend.util :as util]
             [frontend.util :as util]
-            [frontend.util.persist-var :as persist-var]
             [goog.object :as gobj]
             [goog.object :as gobj]
             [lambdaisland.glogi :as log]
             [lambdaisland.glogi :as log]
             [promesa.core :as p]))
             [promesa.core :as p]))
@@ -193,10 +192,7 @@
                                    (reset! vector-search-flows/*infer-worker-ready true))))
                                    (reset! vector-search-flows/*infer-worker-ready true))))
                         nil))))
                         nil))))
 
 
-     (util/<app-wake-up-from-sleep-loop (atom false))
-
-     (when-not (util/mobile?)
-       (persist-var/load-vars)))))
+     (util/<app-wake-up-from-sleep-loop (atom false)))))
 
 
 (defn stop! []
 (defn stop! []
   (prn "stop!"))
   (prn "stop!"))

+ 1 - 12
src/main/frontend/handler/block.cljs

@@ -7,17 +7,14 @@
             [frontend.db :as db]
             [frontend.db :as db]
             [frontend.db.async :as db-async]
             [frontend.db.async :as db-async]
             [frontend.db.model :as db-model]
             [frontend.db.model :as db-model]
-            [frontend.handler.file-based.property.util :as property-util]
             [frontend.handler.property.util :as pu]
             [frontend.handler.property.util :as pu]
             [frontend.mobile.haptics :as haptics]
             [frontend.mobile.haptics :as haptics]
             [frontend.modules.outliner.op :as outliner-op]
             [frontend.modules.outliner.op :as outliner-op]
             [frontend.modules.outliner.ui :as ui-outliner-tx]
             [frontend.modules.outliner.ui :as ui-outliner-tx]
             [frontend.state :as state]
             [frontend.state :as state]
             [frontend.util :as util]
             [frontend.util :as util]
-            [frontend.util.file-based.drawer :as drawer]
             [goog.object :as gobj]
             [goog.object :as gobj]
             [logseq.db :as ldb]
             [logseq.db :as ldb]
-            [logseq.db.sqlite.util :as sqlite-util]
             [logseq.graph-parser.block :as gp-block]
             [logseq.graph-parser.block :as gp-block]
             [logseq.outliner.core :as outliner-core]
             [logseq.outliner.core :as outliner-core]
             [logseq.outliner.op]
             [logseq.outliner.op]
@@ -124,13 +121,6 @@
                            :container-id container-id :direction direction :event event :pos pos}))
                            :container-id container-id :direction direction :event event :pos pos}))
     (mark-last-input-time! repo)))
     (mark-last-input-time! repo)))
 
 
-(defn sanity-block-content
-  [repo format content]
-  (if (sqlite-util/db-based-graph? repo)
-    content
-    (-> (property-util/remove-built-in-properties format content)
-        (drawer/remove-logbook))))
-
 (defn block-unique-title
 (defn block-unique-title
   "Multiple pages/objects may have the same `:block/title`.
   "Multiple pages/objects may have the same `:block/title`.
    Notice: this doesn't prevent for pages/objects that have the same tag or created by different clients."
    Notice: this doesn't prevent for pages/objects that have the same tag or created by different clients."
@@ -205,8 +195,7 @@
                             content
                             content
 
 
                             :else
                             :else
-                            (subs content 0 pos))
-               content (sanity-block-content repo (get block :block/format :markdown) content)]
+                            (subs content 0 pos))]
            (state/clear-selection!)
            (state/clear-selection!)
            (edit-block-aux repo block content text-range (assoc opts :pos pos))))))))
            (edit-block-aux repo block content text-range (assoc opts :pos pos))))))))
 
 

+ 22 - 77
src/main/frontend/handler/editor.cljs

@@ -41,7 +41,6 @@
             [frontend.template :as template]
             [frontend.template :as template]
             [frontend.util :as util]
             [frontend.util :as util]
             [frontend.util.cursor :as cursor]
             [frontend.util.cursor :as cursor]
-            [frontend.util.file-based.drawer :as drawer]
             [frontend.util.keycode :as keycode]
             [frontend.util.keycode :as keycode]
             [frontend.util.list :as list]
             [frontend.util.list :as list]
             [frontend.util.ref :as ref]
             [frontend.util.ref :as ref]
@@ -66,7 +65,6 @@
             [logseq.graph-parser.block :as gp-block]
             [logseq.graph-parser.block :as gp-block]
             [logseq.graph-parser.mldoc :as gp-mldoc]
             [logseq.graph-parser.mldoc :as gp-mldoc]
             [logseq.graph-parser.property :as gp-property]
             [logseq.graph-parser.property :as gp-property]
-            [logseq.graph-parser.text :as text]
             [logseq.graph-parser.utf8 :as utf8]
             [logseq.graph-parser.utf8 :as utf8]
             [logseq.outliner.core :as outliner-core]
             [logseq.outliner.core :as outliner-core]
             [logseq.outliner.property :as outliner-property]
             [logseq.outliner.property :as outliner-property]
@@ -287,17 +285,12 @@
   ([block value
   ([block value
     {:keys [force?]
     {:keys [force?]
      :as opts}]
      :as opts}]
-   (let [{:block/keys [uuid format repo title]} block
-         format (or format :markdown)
+   (let [{:block/keys [uuid format repo]} block
          repo (or repo (state/get-current-repo))
          repo (or repo (state/get-current-repo))
-         format (or format (state/get-preferred-format))
          block-id (let [properties (:block/properties block)]
          block-id (let [properties (:block/properties block)]
                     (when (and (not (config/db-based-graph? repo)) (map? properties))
                     (when (and (not (config/db-based-graph? repo)) (map? properties))
                       (get properties :id)))
                       (get properties :id)))
-         content (if (config/db-based-graph? repo)
-                   (:block/title (db/entity (:db/id block)))
-                   (-> (property-file/remove-built-in-properties-when-file-based repo format title)
-                       (drawer/remove-logbook)))]
+         content (:block/title (db/entity (:db/id block)))]
      (cond
      (cond
        (another-block-with-same-id-exists? uuid block-id)
        (another-block-with-same-id-exists? uuid block-id)
        (notification/show!
        (notification/show!
@@ -710,32 +703,11 @@
       (when-let [edit-block (state/get-edit-block)]
       (when-let [edit-block (state/get-edit-block)]
         (let [edit-input-id (state/get-edit-input-id)
         (let [edit-input-id (state/get-edit-input-id)
               current-input (gdom/getElement edit-input-id)]
               current-input (gdom/getElement edit-input-id)]
-          (if (config/db-based-graph? (state/get-current-repo))
-            (when-let [block (db/entity (:db/id edit-block))]
-              (let [pos (state/get-edit-pos)]
-                (p/do!
-                 (ui-outliner-tx/transact!
-                  {:outliner-op :cycle-todos}
-                  (db-based-cycle-todo! block))
-
-                 ;; FIXME: don't change current editor's position
-                 )))
-            (let [content (state/get-edit-content)
-                  format (or (db/get-page-format (state/get-current-page))
-                             (state/get-preferred-format))
-                  [new-content marker] (status/cycle-marker content nil nil format (state/get-preferred-workflow))
-                  new-pos (commands/compute-pos-delta-when-change-marker
-                           content marker (cursor/pos current-input))]
-              (state/set-edit-content! edit-input-id new-content)
-              (cursor/move-cursor-to current-input new-pos))))))))
-
-(defn set-priority
-  [{:block/keys [priority title] :as block} new-priority]
-  (when-not (config/db-based-graph? (state/get-current-repo))
-    (let [new-content (string/replace-first title
-                                            (util/format "[#%s]" priority)
-                                            (util/format "[#%s]" new-priority))]
-      (save-block-if-changed! block new-content))))
+          (when-let [block (db/entity (:db/id edit-block))]
+            (let [pos (state/get-edit-pos)]
+              (ui-outliner-tx/transact!
+               {:outliner-op :cycle-todos}
+               (db-based-cycle-todo! block)))))))))
 
 
 (defn delete-block-aux!
 (defn delete-block-aux!
   [{:block/keys [uuid] :as _block}]
   [{:block/keys [uuid] :as _block}]
@@ -755,19 +727,10 @@
           {:prev-block sibling-entity
           {:prev-block sibling-entity
            :new-value (:block/title sibling-entity)
            :new-value (:block/title sibling-entity)
            :edit-block-f #(edit-block! sibling-entity :max)}
            :edit-block-f #(edit-block! sibling-entity :max)}
-          (let [db? (config/db-based-graph? repo)
-                original-content (if (= (:db/id sibling-entity) (:db/id (state/get-edit-block)))
+          (let [original-content (if (= (:db/id sibling-entity) (:db/id (state/get-edit-block)))
                                    (state/get-edit-content)
                                    (state/get-edit-content)
                                    (:block/title sibling-entity))
                                    (:block/title sibling-entity))
-                value' (if db?
-                         original-content
-                         (-> (property-file/remove-built-in-properties-when-file-based repo format original-content)
-                             (drawer/remove-logbook)))
-                value (if db?
-                        value
-                        (->> value
-                             (property-file/remove-properties-when-file-based repo format)
-                             (drawer/remove-logbook)))
+                value' original-content
                 new-value (str value' value)
                 new-value (str value' value)
                 tail-len (count value)
                 tail-len (count value)
                 pos (max
                 pos (max
@@ -1453,15 +1416,6 @@
            (js/console.error error)
            (js/console.error error)
            (log/error :save-block-failed error)))))))
            (log/error :save-block-failed error)))))))
 
 
-(defn- clean-content!
-  [repo format content]
-  (if (config/db-based-graph? repo)
-    content
-    (some->> (text/remove-level-spaces content format (config/get-block-pattern format))
-             (drawer/remove-logbook)
-             (property-file/remove-properties-when-file-based repo format)
-             string/trim)))
-
 (defn delete-asset-of-block!
 (defn delete-asset-of-block!
   [{:keys [repo asset-block href full-text block-id local? delete-local?] :as _opts}]
   [{:keys [repo asset-block href full-text block-id local? delete-local?] :as _opts}]
   (let [block (db-model/query-block-by-uuid block-id)
   (let [block (db-model/query-block-by-uuid block-id)
@@ -2629,8 +2583,7 @@
              (when (and
              (when (and
                     uuid
                     uuid
                     (not (state/block-component-editing?))
                     (not (state/block-component-editing?))
-                    (not= (clean-content! repo format title)
-                          (string/trim value)))
+                    (not= title (string/trim value)))
                (save-block! repo uuid value))
                (save-block! repo uuid value))
 
 
              (cond
              (cond
@@ -2699,7 +2652,7 @@
     (when sibling-block
     (when sibling-block
       (let [content (:block/title block)
       (let [content (:block/title block)
             value (state/get-edit-content)]
             value (state/get-edit-content)]
-        (when (and value (not= (clean-content! repo format content) (string/trim value)))
+        (when (and value (not= content (string/trim value)))
           (save-block! repo uuid value)))
           (save-block! repo uuid value)))
       (let [sibling-block-id (dom/attr sibling-block "blockid")]
       (let [sibling-block-id (dom/attr sibling-block "blockid")]
         (cond
         (cond
@@ -3869,19 +3822,15 @@
 
 
 (defn replace-block-reference-with-content-at-point
 (defn replace-block-reference-with-content-at-point
   []
   []
-  (let [repo (state/get-current-repo)]
-    (when-let [{:keys [start end link]} (thingatpt/block-ref-at-point)]
-      (when-let [block (db/entity [:block/uuid link])]
-        (let [block-content (:block/title block)
-              format (get block :block/format :markdown)
-              block-content-without-prop (-> (property-file/remove-properties-when-file-based repo format block-content)
-                                             (drawer/remove-logbook))]
-          (when-let [input (state/get-input)]
-            (when-let [current-block-content (gobj/get input "value")]
-              (let [block-content* (str (subs current-block-content 0 start)
-                                        block-content-without-prop
-                                        (subs current-block-content end))]
-                (state/set-block-content-and-last-pos! input block-content* 1)))))))))
+  (when-let [{:keys [start end link]} (thingatpt/block-ref-at-point)]
+    (when-let [block (db/entity [:block/uuid link])]
+      (let [block-content (:block/title block)]
+        (when-let [input (state/get-input)]
+          (when-let [current-block-content (gobj/get input "value")]
+            (let [block-content* (str (subs current-block-content 0 start)
+                                      block-content
+                                      (subs current-block-content end))]
+              (state/set-block-content-and-last-pos! input block-content* 1))))))))
 
 
 (defn copy-current-ref
 (defn copy-current-ref
   [block-id]
   [block-id]
@@ -3903,13 +3852,9 @@
 (defn replace-ref-with-text!
 (defn replace-ref-with-text!
   [block ref-id]
   [block ref-id]
   (when (and block ref-id)
   (when (and block ref-id)
-    (let [repo (state/get-current-repo)
-          match (ref/->block-ref ref-id)
+    (let [match (ref/->block-ref ref-id)
           ref-block (db/entity [:block/uuid ref-id])
           ref-block (db/entity [:block/uuid ref-id])
-          block-ref-content (->> (or (:block/title ref-block) "")
-                                 (property-file/remove-built-in-properties-when-file-based repo
-                                                                                           (get ref-block :block/format :markdown))
-                                 (drawer/remove-logbook))
+          block-ref-content (or (:block/title ref-block) "")
           content (string/replace-first (:block/title block) match
           content (string/replace-first (:block/title block) match
                                         block-ref-content)]
                                         block-ref-content)]
       (save-block! (state/get-current-repo)
       (save-block! (state/get-current-repo)

+ 47 - 0
src/main/frontend/util/clock.cljs

@@ -0,0 +1,47 @@
+(ns frontend.util.clock
+  "Provides clock related functionality used by tasks"
+  (:require [frontend.util :as util]))
+
+(defn s->dhms-util
+  "A function that returns the values for easier testing.
+   Always in the order [days, hours, minutes, seconds]"
+  [seconds]
+  (let [days (quot (quot seconds 3600) 24)
+        n (mod seconds (* 24 3600))
+        hours (quot n 3600)
+        n (mod n 3600)
+        minutes (quot n 60)
+        secs (mod n 60)]
+    [days hours minutes secs]))
+
+(defn seconds->days:hours:minutes:seconds
+  [seconds]
+  (let [[days hours minutes seconds] (s->dhms-util seconds)]
+    (cond
+      (> days 0)
+      (util/format "%s%s"
+                   (if (zero? days) "" (str days "d"))
+                   (if (zero? hours) "" (str hours "h")))
+
+      (> minutes 0)
+      (util/format "%s%s"
+                   (if (zero? hours) "" (str hours "h"))
+                   (if (zero? minutes) "" (str minutes "m")))
+      :else
+      (if (> seconds 0)
+        (str seconds "s")
+        ""))))
+
+(comment
+  (defn minutes->hours:minutes
+    [minutes]
+    (let [hours (quot minutes 60)
+          minutes (mod minutes 60)]
+      (util/format "%02d:%02d" hours minutes)))
+
+  (defn seconds->hours:minutes:seconds
+    [seconds]
+    (let [hours (quot seconds 3600)
+          minutes (quot (- seconds (* hours 3600)) 60)
+          seconds (mod seconds 60)]
+      (util/format "%02d:%02d:%02d" hours minutes seconds))))

+ 0 - 126
src/main/frontend/util/file_based/clock.cljs

@@ -1,126 +0,0 @@
-(ns frontend.util.file-based.clock
-  "Provides clock related functionality used by tasks"
-  (:require [cljs-time.core :as t]
-            [cljs-time.format :as tf]
-            [clojure.string :as string]
-            [frontend.date :as date]
-            [frontend.state :as state]
-            [frontend.util :as util]
-            [frontend.util.file-based.drawer :as drawer]))
-
-(defn minutes->hours:minutes
-  [minutes]
-  (let [hours (quot minutes 60)
-        minutes (mod minutes 60)]
-    (util/format "%02d:%02d" hours minutes)))
-
-(defn seconds->hours:minutes:seconds
-  [seconds]
-  (let [hours (quot seconds 3600)
-        minutes (quot (- seconds (* hours 3600)) 60)
-        seconds (mod seconds 60)]
-    (util/format "%02d:%02d:%02d" hours minutes seconds)))
-
-(defn s->dhms-util
-  "A function that returns the values for easier testing.
-   Always in the order [days, hours, minutes, seconds]"
-  [seconds]
-  (let [days (quot (quot seconds 3600) 24)
-        n (mod seconds (* 24 3600))
-        hours (quot n 3600)
-        n (mod n 3600)
-        minutes (quot n 60)
-        secs (mod n 60)]
-    [days hours minutes secs]))
-
-(defn seconds->days:hours:minutes:seconds
-  [seconds]
-  (let [[days hours minutes seconds] (s->dhms-util seconds)]
-    (cond
-      (> days 0)
-      (util/format "%s%s"
-                   (if (zero? days) "" (str days "d"))
-                   (if (zero? hours) "" (str hours "h")))
-
-      (> minutes 0)
-      (util/format "%s%s"
-                   (if (zero? hours) "" (str hours "h"))
-                   (if (zero? minutes) "" (str minutes "m")))
-      :else
-      (if (> seconds 0)
-        (str seconds "s")
-        ""))))
-
-(def support-seconds?
-  (get-in (state/get-config)
-          [:logbook/settings :with-second-support?] true))
-
-(defn- now []
-  (if support-seconds?
-    (date/get-date-time-string-4)
-    (date/get-date-time-string-3)))
-
-(defn- clock-interval
-  [stime etime]
-  (let [[stime etime] (map #(tf/parse
-                             (if support-seconds?
-                               date/custom-formatter-4
-                               date/custom-formatter-3)
-                             %)
-                           [stime etime])
-        interval (t/interval stime etime)
-        minutes (t/in-minutes interval)
-        seconds (t/in-seconds interval)]
-    (if support-seconds?
-      (seconds->hours:minutes:seconds seconds)
-      (minutes->hours:minutes minutes))))
-
-(defn clock-in
-  [format content]
-  (drawer/insert-drawer
-   format content "logbook"
-   (util/format "CLOCK: [%s]" (now))))
-
-(defn clock-out
-  [format content]
-  (try
-    (or
-     (when-let [clock-in-log (last (last (drawer/get-drawer-ast format content "logbook")))]
-       (let [clock-in-log (string/trim clock-in-log)]
-         (when (string/starts-with? clock-in-log "CLOCK:")
-           (let [clock-start (subs clock-in-log 8 (- (count clock-in-log) 1))
-                 clock-end (now)
-                 clock-span (clock-interval clock-start clock-end)
-                 clock-out-log (util/format "CLOCK: [%s]--[%s] =>  %s"
-                                            clock-start clock-end clock-span)]
-             (string/replace
-              content
-              (str clock-in-log "\n")
-              (str clock-out-log "\n"))))))
-     content)
-    (catch :default _e
-      content)))
-
-(defn clock-summary
-  [body string?']
-  (when-let [logbook (drawer/get-logbook body)]
-    (when-let [logbook-lines (last logbook)]
-      (when-let [clock-lines (seq (filter #(string/starts-with? % "CLOCK:") logbook-lines))]
-        (let [[hours minutes seconds] (apply map + (->> clock-lines
-                                                        (map #(string/split (string/trim (last (string/split % "=>"))) ":"))
-                                                        (map #(map int %))))
-              duration (t/period :hours hours
-                                 :minutes minutes
-                                 :seconds seconds)
-              duration-in-minutes (t/in-minutes duration)
-              zero-minutes? (zero? duration-in-minutes)]
-          (if string?'
-            (if zero-minutes?
-              (str seconds "s")
-              (-> (tf/unparse-duration duration)
-                  (string/replace #"\s+days?\s+" "d")
-                  (string/replace #"\s+hours?\s+" "h")
-                  (string/replace #"\s+minutes?$" "m")))
-            (if zero-minutes?
-              seconds
-              (* 60 duration-in-minutes))))))))

+ 0 - 139
src/main/frontend/util/file_based/drawer.cljs

@@ -1,139 +0,0 @@
-(ns ^:no-doc frontend.util.file-based.drawer
-  (:require [clojure.string :as string]
-            [frontend.util :as util]
-            [frontend.format.mldoc :as mldoc]
-            [logseq.graph-parser.property :as gp-property]))
-
-(defn drawer-start
-  [typ]
-  (util/format ":%s:" (string/upper-case typ)))
-
-(defonce drawer-end ":END:")
-
-(defonce logbook-start ":LOGBOOK:")
-
-(defn build-drawer-str
-  ([typ]
-   (build-drawer-str typ nil))
-  ([typ value]
-   (if value
-     (string/join "\n" [(drawer-start typ) value drawer-end])
-     (string/join "\n" [(drawer-start typ) drawer-end]))))
-
-(defn get-drawer-ast
-  [format content typ]
-  (let [ast (mldoc/->edn content format)
-        typ-drawer (ffirst (filter (fn [x]
-                                     (mldoc/typ-drawer? x typ)) ast))]
-    typ-drawer))
-
-(defn insert-drawer
-  [format content typ value]
-  (when (string? content)
-    (try
-      (let [ast (mldoc/->edn content format)
-            has-properties? (some (fn [x] (mldoc/properties? x)) ast)
-            has-typ-drawer? (some (fn [x] (mldoc/typ-drawer? x typ)) ast)
-            lines (string/split-lines content)
-            title (first lines)
-            body (rest lines)
-            scheduled (filter #(string/starts-with? % "SCHEDULED") lines)
-            deadline (filter #(string/starts-with? % "DEADLINE") lines)
-            body-without-timestamps (vec
-                                     (filter
-                                      #(not (or (string/starts-with? % "SCHEDULED")
-                                                (string/starts-with? % "DEADLINE")))
-                                      body))
-            start-idx (.indexOf body-without-timestamps (drawer-start typ))
-            end-idx (let [[before after] (split-at start-idx body-without-timestamps)]
-                      (+ (count before) (.indexOf after drawer-end)))
-            result  (cond
-                      (not has-typ-drawer?)
-                      (let [drawer (build-drawer-str typ value)]
-                        (if has-properties?
-                          (cond
-                            (= :org format)
-                            (let [prop-start-idx (.indexOf body-without-timestamps gp-property/properties-start)
-                                  prop-end-idx (.indexOf body-without-timestamps gp-property/properties-end)
-                                  properties (subvec body-without-timestamps prop-start-idx (inc prop-end-idx))
-                                  after (subvec body-without-timestamps (inc prop-end-idx))]
-                              (string/join "\n" (concat [title] scheduled deadline properties [drawer] after)))
-
-                            :else
-                            (let [properties-count (count (second (first (second ast))))
-                                  properties (subvec body-without-timestamps 0 properties-count)
-                                  after (subvec body-without-timestamps properties-count)]
-                              (string/join "\n" (concat [title] scheduled deadline properties [drawer] after))))
-                          (string/join "\n" (concat [title] scheduled deadline [drawer] body-without-timestamps))))
-
-                      (and has-typ-drawer?
-                           (>= start-idx 0) (> end-idx 0) (> end-idx start-idx))
-                      (let [before (subvec body-without-timestamps 0 start-idx)
-                            middle (conj
-                                    (subvec body-without-timestamps (inc start-idx) end-idx)
-                                    value)
-                            after (subvec body-without-timestamps (inc end-idx))
-                            lines (concat [title] scheduled deadline before
-                                          [(drawer-start typ)] middle [drawer-end] after)]
-                        (string/join "\n" lines))
-
-                      :else
-                      content)]
-        (string/trimr result))
-      (catch :default e
-        (js/console.error e)
-        content))))
-
-(defn contains-logbook?
-  [content]
-  (and (util/safe-re-find (re-pattern (str "(?i)" logbook-start)) content)
-       (util/safe-re-find (re-pattern (str "(?i)" drawer-end)) content)))
-
-;; TODO: DRY
-(defn remove-logbook
-  [content]
-  (when content
-    (if (contains-logbook? content)
-      (let [lines (string/split-lines content)
-            [title-lines body] (split-with (fn [l]
-                                             (not (string/starts-with? (string/upper-case (string/triml l)) ":LOGBOOK:")))
-                                           lines)
-            body (drop-while (fn [l]
-                               (let [l' (string/lower-case (string/trim l))]
-                                 (or
-                                  (not (string/starts-with? l' ":end:"))
-                                  (string/blank? l))))
-                             body)
-            body (if (and (seq body)
-                          (string/starts-with? (string/lower-case (string/triml (first body))) ":end:"))
-                   (let [line (string/replace (first body) #"(?i):end:\s?" "")]
-                     (if (string/blank? line)
-                       (rest body)
-                       (cons line (rest body))))
-                   body)]
-        (->> (concat title-lines body)
-             (string/join "\n")))
-      content)))
-
-(defn get-logbook
-  [body]
-  (-> (filter (fn [v] (and (vector? v)
-                          (= (first v) "Drawer")
-                          (= (second v) "logbook"))) body)
-      first))
-
-(defn with-logbook
-  [block content]
-  (let [new-clocks (last (get-drawer-ast (:block/format block) content "logbook"))
-        logbook (get-logbook (:block.temp/ast-body block))]
-    (if logbook
-      (let [content (remove-logbook content)
-            clocks (->> (concat new-clocks (when-not new-clocks (last logbook)))
-                        (distinct))
-            clocks (->> (map string/trim clocks)
-                        (remove string/blank?)
-                        (string/join "\n"))]
-        (if (:block.temp/ast-title block)
-          (insert-drawer (:block/format block) content "LOGBOOK" clocks)
-          content))
-      content)))

+ 0 - 31
src/main/frontend/util/file_based/priority.cljs

@@ -1,31 +0,0 @@
-(ns frontend.util.file-based.priority
-  "Util fns for task priorities e.g. A, B, C.
-   File graph only"
-  (:require [clojure.string :as string]
-            [frontend.util :as util]
-            [frontend.handler.file-based.status :as status]))
-
-(defn add-or-update-priority
-  [content format priority]
-  (let [priority-pattern  #"(\[#[ABC]\])?\s?"
-        [re-pattern new-line-re-pattern]
-        (if (= :org format)
-          [#"\*+\s" #"\n\*+\s"]
-          [#"#+\s" #"\n#+\s"])
-        skip-hash-pos
-        (if-let [matches (seq (util/re-pos new-line-re-pattern content))]
-          (let [[start-pos content] (last matches)]
-            (+ start-pos (count content)))
-          (count (util/safe-re-find re-pattern content)))
-        skip-marker-pos
-        (if-let [matches (seq (util/re-pos status/bare-marker-pattern (subs content skip-hash-pos)))]
-          (let [[start-pos content] (last matches)]
-            (+ start-pos (count content)))
-          0)
-        pos (+ skip-hash-pos skip-marker-pos)
-        new-content
-        (str (subs content 0 pos)
-             (string/replace-first (subs content pos)
-                                   priority-pattern
-                                   (str priority " ")))]
-    new-content))

+ 0 - 107
src/main/frontend/util/persist_var.cljs

@@ -1,107 +0,0 @@
-(ns frontend.util.persist-var
-  "System-component-like ns that provides an atom-like abstraction over an edn
-  file"
-  (:require [cljs.reader :as reader]
-            [frontend.config :as config]
-            [frontend.fs :as fs]
-            [frontend.state :as state]
-            [frontend.util :as util]
-            [promesa.core :as p]))
-
-(defn- load-rpath
-  "Returns the relative path to the file that stores the persist-var"
-  [location]
-  (str config/app-name "/" location ".edn"))
-
-(defprotocol ILoad
-  (-load [this])
-  (-loaded? [this]))
-
-(defprotocol ISave
-  (-save [this]))
-
-(defprotocol IResetValue
-  (-reset-value! [this new graph]))
-
-(deftype PersistVar [*value location]
-  IResetValue
-  (-reset-value! [_ new graph]
-    (reset! *value (assoc-in @*value [graph :value] new)))
-
-  ILoad
-  (-load [_]
-    (if (config/demo-graph?)
-      (p/resolved nil)
-      (let [repo (state/get-current-repo)
-            dir (config/get-repo-dir repo)
-            path (load-rpath location)]
-        (p/let [file-exists? (fs/file-exists? dir path)]
-          (when file-exists?
-            (-> (p/chain (fs/stat dir path)
-                         (fn [stat]
-                           (when stat
-                             (fs/read-file dir path)))
-                         (fn [content]
-                           (when (not-empty content)
-                             (try (reader/read-string content)
-                                  (catch :default e
-                                    (println (util/format "read persist-var failed: %s" (load-rpath location)))
-                                    (js/console.dir e)))))
-                         (fn [value]
-                           (when (some? value)
-                             (swap! *value (fn [o]
-                                             (-> o
-                                                 (assoc-in [repo :loaded?] true)
-                                                 (assoc-in [repo :value] value)))))))
-                (p/catch (fn [e]
-                           (println (util/format "load persist-var failed: %s: %s" (load-rpath location) e))))))))))
-  (-loaded? [_]
-    (get-in @*value [(state/get-current-repo) :loaded?]))
-
-  ISave
-  (-save [_]
-    (if (config/demo-graph?)
-      (p/resolved nil)
-      (let [path (load-rpath location)
-            repo (state/get-current-repo)
-            content (str (get-in @*value [repo :value]))
-            dir (config/get-repo-dir repo)]
-        (fs/write-plain-text-file! repo dir path content {:skip-compare? true}))))
-
-  IDeref
-  (-deref [_this]
-    (get-in @*value [(state/get-current-repo) :value]))
-
-  IReset
-  (-reset!
-    ;; "Deprecated - use (.reset-value! o) instead."
-    [_ new-value]
-    (swap! *value (fn [_] (assoc-in @*value [(state/get-current-repo) :value] new-value))))
-
-  IPrintWithWriter
-  (-pr-writer [_ w _opts]
-    (write-all w (str "#PersistVar[" @*value ", loc: " location "]"))))
-
-(def *all-persist-vars (atom []))
-
-(defn load-vars []
-  (p/all (mapv -load @*all-persist-vars)))
-
-(defn persist-var
-  "This var is stored at logseq/LOCATION.edn"
-  [init-value location]
-  (let [var (->PersistVar (atom {(state/get-current-repo)
-                                 {:value init-value
-                                  :loaded? false}})
-                          location)]
-    (swap! *all-persist-vars conj var)
-    var))
-
-(defn persist-save [v]
-  {:pre [(satisfies? ISave v)]}
-  (-save v))
-
-(comment
-  (do
-    (def bbb (persist-var 1 "aaa"))
-    (-save bbb)))

+ 3 - 4
src/test/frontend/util/file_based/clock_test.cljs → src/test/frontend/util/clock_test.cljs

@@ -1,7 +1,6 @@
-(ns frontend.util.file-based.clock-test
+(ns frontend.util.clock-test
   (:require [cljs.test :refer [deftest is]]
   (:require [cljs.test :refer [deftest is]]
-            [frontend.util.file-based.clock :as clock]))
-
+            [frontend.util.clock :as clock]))
 
 
 (deftest test-seconds->days:hours:minutes:seconds
 (deftest test-seconds->days:hours:minutes:seconds
   (let [inputs [0, 1, 10, 60, 123 ,5432, 63953, 484882, 2394503]
   (let [inputs [0, 1, 10, 60, 123 ,5432, 63953, 484882, 2394503]
@@ -14,4 +13,4 @@
                [0, 17, 45, 53],
                [0, 17, 45, 53],
                [5, 14, 41, 22],
                [5, 14, 41, 22],
                [27, 17, 8, 23]]]
                [27, 17, 8, 23]]]
-    (mapv #(is (= (clock/s->dhms-util %1) %2)) inputs want)))
+    (mapv #(is (= (clock/s->dhms-util %1) %2)) inputs want)))

+ 0 - 21
src/test/frontend/util/file_based/priority_test.cljs

@@ -1,21 +0,0 @@
-(ns frontend.util.file-based.priority-test
-  (:require [cljs.test :refer [are deftest]]
-            [frontend.util.file-based.priority :as priority]))
-
-(deftest add-or-update-priority-markdown
-  (are [content priority expect] (= expect (priority/add-or-update-priority content :markdown priority))
-    "test content" "[#A]" "[#A] test content"
-    "" "[#A]" "[#A] "
-    "[#A] xxx" "[#B]" "[#B] xxx"
-    "## xxx" "[#A]" "## [#A] xxx"
-    "## TODO xxx" "[#A]" "## TODO [#A] xxx"
-    "## TODO [#B] xxx" "[#A]" "## TODO [#A] xxx"
-    ))
-
-(deftest add-or-update-marker-org
-  (are [content priority expect] (= expect (priority/add-or-update-priority content :org priority))
-    "test content" "[#A]" "[#A] test content"
-    "" "[#A]" "[#A] "
-    "[#A] xxx" "[#B]" "[#B] xxx"))
-
-#_(cljs.test/run-tests)