1
0
Эх сурвалжийг харах

Lint a good chunk of src/main/frontend

Left some TODOs to discuss with others and others for me to finish
Gabriel Horner 3 жил өмнө
parent
commit
7497d8b396
37 өөрчлөгдсөн 327 нэмэгдсэн , 366 устгасан
  1. 9 4
      .clj-kondo/config.edn
  2. 1 1
      .gitignore
  3. 1 1
      src/main/frontend/db/conn.cljs
  4. 1 2
      src/main/frontend/db/debug.cljs
  5. 10 18
      src/main/frontend/db/model.cljs
  6. 1 1
      src/main/frontend/db/outliner.cljs
  7. 0 1
      src/main/frontend/db/persist.cljs
  8. 2 4
      src/main/frontend/db/query_custom.cljs
  9. 28 29
      src/main/frontend/db/query_dsl.cljs
  10. 23 23
      src/main/frontend/db/query_react.cljs
  11. 6 8
      src/main/frontend/db/react.cljs
  12. 48 42
      src/main/frontend/external/roam.cljc
  13. 7 11
      src/main/frontend/format/adoc.cljs
  14. 44 43
      src/main/frontend/format/block.cljs
  15. 11 12
      src/main/frontend/format/mldoc.cljs
  16. 11 11
      src/main/frontend/fs/bfs.cljs
  17. 21 24
      src/main/frontend/fs/capacitor_fs.cljs
  18. 12 15
      src/main/frontend/fs/nfs.cljs
  19. 13 15
      src/main/frontend/fs/node.cljs
  20. 1 1
      src/main/frontend/handler/editor.cljs
  21. 5 6
      src/main/frontend/handler/repo.cljs
  22. 1 5
      src/main/frontend/mobile/core.cljs
  23. 1 1
      src/main/frontend/modules/datascript_report/core.cljs
  24. 2 3
      src/main/frontend/modules/editor/undo_redo.cljs
  25. 12 14
      src/main/frontend/modules/file/core.cljs
  26. 1 1
      src/main/frontend/modules/instrumentation/sentry.cljs
  27. 2 2
      src/main/frontend/modules/layout/core.cljs
  28. 23 33
      src/main/frontend/modules/outliner/core.cljs
  29. 1 2
      src/main/frontend/modules/outliner/datascript.cljc
  30. 1 3
      src/main/frontend/modules/outliner/file.cljs
  31. 2 2
      src/main/frontend/modules/outliner/pipeline.cljs
  32. 3 4
      src/main/frontend/modules/outliner/tree.cljs
  33. 4 4
      src/main/frontend/modules/shortcut/data_helper.cljs
  34. 7 8
      src/main/frontend/search/browser.cljs
  35. 2 1
      src/main/frontend/search/db.cljs
  36. 6 6
      src/main/frontend/search/node.cljs
  37. 4 5
      src/main/frontend/tools/html_export.cljs

+ 9 - 4
.clj-kondo/config.edn

@@ -1,9 +1,14 @@
-{:linters {:unresolved-symbol {:exclude [goog.DEBUG 
-                                         goog.string.unescapeEntities]}}
+{:linters
+ {:unresolved-symbol {:exclude [goog.DEBUG
+                                goog.string.unescapeEntities
+                                ;; TODO: Fix when fixing all type hints
+                                object]}}
+
  :hooks {:analyze-call {rum.core/defc hooks.rum/defc
-                        rum.core/defcs hooks.rum/defcs}}
+                         rum.core/defcs hooks.rum/defcs}}
  :lint-as {promesa.core/let clojure.core/let
            promesa.core/loop clojure.core/loop
+           promesa.core/recur clojure.core/recur
            garden.def/defstyles clojure.core/def
            garden.def/defkeyframes clojure.core/def
            rum.core/defcc rum.core/defc
@@ -17,4 +22,4 @@
            frontend.namespaces/import-vars potemkin/import-vars
            ;; src/test
            frontend.react/defc clojure.core/defn}
- :skip-comments true}
+ :skip-comments true}

+ 1 - 1
.gitignore

@@ -30,7 +30,7 @@ strings.csv
 
 .calva
 resources/electron.js
-.clj-kondo/
+.clj-kondo/.cache
 .lsp/
 /libs/dist/
 charlie/

+ 1 - 1
src/main/frontend/db/conn.cljs

@@ -46,7 +46,7 @@
   (swap! conns dissoc (datascript-db repo)))
 
 (defn me-tx
-  [db {:keys [name email avatar]}]
+  [_db {:keys [name email avatar]}]
   (util/remove-nils {:me/name name
                      :me/email email
                      :me/avatar avatar}))

+ 1 - 2
src/main/frontend/db/debug.cljs

@@ -23,8 +23,7 @@
                                 :block/parent (:db/id (:block/parent e))}))))
                     (remove nil?))
         count-1 (count blocks)
-        count-2 (count (distinct blocks))
-        result (filter #(> (second %) 1) (frequencies blocks))]
+        count-2 (count (distinct blocks))]
     (assert (= count-1 count-2) (util/format "Blocks count: %d, repeated blocks count: %d"
                                              count-1
                                              (- count-1 count-2)))))

+ 10 - 18
src/main/frontend/db/model.cljs

@@ -438,8 +438,7 @@
 (defn flatten-blocks-sort-by-left
   [blocks parent]
   (let [ids->blocks (zipmap (map (fn [b] [(:db/id (:block/parent b))
-                                         (:db/id (:block/left b))]) blocks) blocks)
-        top-block (get ids->blocks [(:db/id parent) (:db/id parent)])]
+                                         (:db/id (:block/left b))]) blocks) blocks)]
     (loop [node parent
            next-siblings '()
            result []]
@@ -461,7 +460,7 @@
     (when block-id
       (some->
       (react/q repo-url [:block/refs-count block-id]
-        {:query-fn (fn [db]
+        {:query-fn (fn [_db]
                      (count (:block/_refs (db-utils/entity repo-url [:block/uuid block-id]))))}
         nil)
       react))))
@@ -479,8 +478,7 @@
      (let [page (util/page-name-sanity-lc (string/trim page))
            page-entity (or (db-utils/entity repo-url [:block/name page])
                            (db-utils/entity repo-url [:block/original-name page]))
-           page-id (:db/id page-entity)
-           db (conn/get-conn repo-url)]
+           page-id (:db/id page-entity)]
        (when page-id
          (some->
           (react/q repo-url [:page/blocks page-id]
@@ -603,7 +601,7 @@
                               ids))))))
 
 (defn block-and-children-transform
-  [result repo-url block-uuid]
+  [result repo-url _block-uuid]
   (some->> result
            db-utils/seq-flatten
            (db-utils/with-repo repo-url)))
@@ -742,12 +740,6 @@
     (db-utils/entity [:block/uuid (uuid page-name)])
     (db-utils/entity [:block/name (util/page-name-sanity-lc page-name)])))
 
-(defn- heading-block?
-  [block]
-  (and
-   (vector? block)
-   (= "Heading" (first block))))
-
 (defn get-redirect-page-name
   "Accepts both sanitized or unsanitized"
   ([page-name] (get-redirect-page-name page-name false))
@@ -897,7 +889,7 @@
                                db-utils/seq-flatten)]
       (mapv (fn [page] [page (get-page-alias repo page)]) mentioned-pages))))
 
-(defn- remove-children!
+(defn remove-children!
   [blocks]
   (let [parents (->> (mapcat :block/parent blocks)
                      (map :db/id)
@@ -1135,7 +1127,7 @@
 (defn get-matched-blocks
   [match-fn limit]
   (when-let [repo (state/get-current-repo)]
-    (let [pred (fn [db content]
+    (let [pred (fn [_db content]
                  (match-fn content))]
       (->> (d/q
             '[:find ?block
@@ -1231,7 +1223,7 @@
 
 (defn get-all-templates
   []
-  (let [pred (fn [db properties]
+  (let [pred (fn [_db properties]
                (some? (:template properties)))]
     (->> (d/q
           '[:find ?b ?p
@@ -1315,7 +1307,7 @@
         non-public-datoms (get-public-false-block-ids db)
         non-public-datom-ids (set (concat non-public-pages non-public-datoms))
         filtered-db (d/filter db
-                              (fn [db datom]
+                              (fn [_db datom]
                                 (let [ns (namespace (:a datom))]
                                   (and (not (remove? ns))
                                        (not (contains? #{:block/file} (:a datom)))
@@ -1347,7 +1339,7 @@
         [@(d/conn-from-datoms datoms db-schema/schema) assets]))))
 
 (defn delete-blocks
-  [repo-url files delete-page?]
+  [repo-url files _delete-page?]
   (when (seq files)
     (let [blocks (get-files-blocks repo-url files)]
       (mapv (fn [eid] [:db.fn/retractEntity eid]) blocks))))
@@ -1535,7 +1527,7 @@
   ([repo] (remove-orphaned-pages! repo (get-orphaned-pages {})))
   ([repo orphaned-pages]
    (let [transaction (mapv (fn [page] [:db/retractEntity (:db/id page)]) orphaned-pages)]
-     (db-utils/transact! transaction))))
+     (db-utils/transact! repo transaction))))
 
 (defn get-block-last-direct-child
   [db-id]

+ 1 - 1
src/main/frontend/db/outliner.cljs

@@ -8,7 +8,7 @@
   [conn id]
   (try
     (d/pull @conn '[*] id)
-    (catch js/Error e nil)))
+    (catch js/Error _e nil)))
 
 (defn get-by-parent-&-left
   [conn parent-id left-id]

+ 0 - 1
src/main/frontend/db/persist.cljs

@@ -1,6 +1,5 @@
 (ns frontend.db.persist
   (:require [frontend.util :as util]
-            [frontend.mobile.util :as mobile]
             [frontend.idb :as idb]
             [frontend.config :as config]
             [electron.ipc :as ipc]

+ 2 - 4
src/main/frontend/db/query_custom.cljs

@@ -4,7 +4,6 @@
             [clojure.string :as string]
             [cljs.reader :as reader]
             [frontend.db.query-react :as react]
-            [frontend.template :as template]
             [frontend.db.query-dsl :as dsl]
             [frontend.db.model :as model]
             [clojure.walk :as walk]))
@@ -26,11 +25,10 @@
   ([query]
    (custom-query query {}))
   ([query query-opts]
-   (when-let [query' (cond
+   (when-let [_query' (cond
                        (and (string? query)
                             (not (string/blank? query)))
-                       (let [query-string (template/resolve-dynamic-template! query)]
-                         (reader/read-string query))
+                        (reader/read-string query)
 
                        (map? query)
                        query

+ 28 - 29
src/main/frontend/db/query_dsl.cljs

@@ -311,23 +311,23 @@
                      (keyword (string/lower-case (name order)))
                      :desc)
              k (-> (string/lower-case (name k))
-                   (string/replace "_" "-"))]
-         (let [get-value (cond
-                           (= k "created-at")
-                           :block/created-at
-
-                           (= k "updated-at")
-                           :block/updated-at
-
-                           :else
-                           #(get-in % [:block/properties k]))
-               comp (if (= order :desc) >= <=)]
-           (reset! sort-by
-                   (fn [result]
-                     (->> result
-                          flatten
-                          (clojure.core/sort-by get-value comp))))
-           nil))
+                   (string/replace "_" "-"))
+             get-value (cond
+                         (= k "created-at")
+                         :block/created-at
+
+                         (= k "updated-at")
+                         :block/updated-at
+
+                         :else
+                         #(get-in % [:block/properties k]))
+             comp (if (= order :desc) >= <=)]
+         (reset! sort-by
+                 (fn [result]
+                   (->> result
+                        flatten
+                        (clojure.core/sort-by get-value comp))))
+         nil)
 
        (= 'page fe)
        (let [page-name (text/page-ref-un-brackets! (str (first (rest e))))
@@ -362,18 +362,17 @@
             [true]]))
 
        (= 'page-tags fe)
-       (do
-         (let [tags (if (coll? (first (rest e)))
-                      (first (rest e))
-                      (rest e))
-               tags (map (comp string/lower-case name) tags)]
-           (when (seq tags)
-             (let [tags (set (map (comp text/page-ref-un-brackets! string/lower-case name) tags))]
-               (let [sym-1 (uniq-symbol counter "?t")
-                     sym-2 (uniq-symbol counter "?tag")]
-                 [['?p :block/tags sym-1]
-                  [sym-1 :block/name sym-2]
-                  [(list 'contains? tags sym-2)]])))))
+       (let [tags (if (coll? (first (rest e)))
+                    (first (rest e))
+                    (rest e))
+             tags (map (comp string/lower-case name) tags)]
+         (when (seq tags)
+           (let [tags (set (map (comp text/page-ref-un-brackets! string/lower-case name) tags))
+                 sym-1 (uniq-symbol counter "?t")
+                 sym-2 (uniq-symbol counter "?tag")]
+             [['?p :block/tags sym-1]
+              [sym-1 :block/name sym-2]
+              [(list 'contains? tags sym-2)]])))
 
        (= 'all-page-tags fe)
        [['?e :block/tags '?p]]

+ 23 - 23
src/main/frontend/db/query_react.cljs

@@ -61,29 +61,29 @@
   (try
     (let [repo (state/get-current-repo)
           result (db-utils/seq-flatten query-result)
-          block? (:block/uuid (first result))]
-      (let [result (if block?
-                     (let [result (if (seq remove-blocks)
-                                    (let [remove-blocks (set remove-blocks)]
-                                      (remove (fn [h]
-                                                (contains? remove-blocks (:block/uuid h)))
-                                              result))
-                                    result)]
-                       (some->> result
-                                remove-nested-children-blocks
-                                (model/sort-by-left-recursive)
-                                (db-utils/with-repo repo)
-                                (model/with-pages)))
-                     result)]
-        (if-let [result-transform (:result-transform q)]
-          (if-let [f (sci/eval-string (pr-str result-transform))]
-            (try
-              (sci/call-fn f result)
-              (catch js/Error e
-                (log/error :sci/call-error e)
-                result))
-            result)
-          result)))
+          block? (:block/uuid (first result))
+          result (if block?
+                   (let [result (if (seq remove-blocks)
+                                  (let [remove-blocks (set remove-blocks)]
+                                    (remove (fn [h]
+                                              (contains? remove-blocks (:block/uuid h)))
+                                            result))
+                                  result)]
+                     (some->> result
+                              remove-nested-children-blocks
+                              (model/sort-by-left-recursive)
+                              (db-utils/with-repo repo)
+                              (model/with-pages)))
+                   result)]
+      (if-let [result-transform (:result-transform q)]
+        (if-let [f (sci/eval-string (pr-str result-transform))]
+          (try
+            (sci/call-fn f result)
+            (catch js/Error e
+              (log/error :sci/call-error e)
+              result))
+          result)
+        result))
     (catch js/Error e
       (log/error :query/failed e))))
 

+ 6 - 8
src/main/frontend/db/react.cljs

@@ -11,7 +11,7 @@
             [frontend.db.conn :as conn]
             [frontend.db.utils :as db-utils]
             [frontend.state :as state]
-            [frontend.util :as util :refer [profile react]]
+            [frontend.util :as util :refer [react]]
             [frontend.util.marker :as marker]
             [frontend.db.rules :as rules]))
 
@@ -50,13 +50,13 @@
 (defn clear-query-state-without-refs-and-embeds!
   []
   (let [state @query-state
-        state (->> (filter (fn [[[_repo k] v]]
+        state (->> (filter (fn [[[_repo k] _v]]
                              (contains? #{:blocks :block/block :custom} k)) state)
                    (into {}))]
     (reset! query-state state)))
 
 (defn get-current-repo-refs-keys
-  [{:keys [key data]}]
+  [{:keys [data]}]
   (when-let [current-repo (state/get-current-repo)]
     (->>
      (map (fn [[repo k id]]
@@ -143,8 +143,7 @@
 (defn q
   [repo k {:keys [use-cache? transform-fn query-fn inputs-fn disable-reactive?]
            :or {use-cache? true
-                transform-fn identity}
-           :as opts} query & inputs]
+                transform-fn identity}} query & inputs]
   (let [kv? (and (vector? k) (= :kv (first k)))
         k (vec (cons repo k))]
     (when-let [conn (conn/get-conn repo)]
@@ -230,7 +229,6 @@
               current-priority (get-current-priority)
               current-marker (get-current-marker)
               current-page-id (:db/id (get-current-page))
-              {:block/keys [page]} (first blocks)
               related-keys (->>
                             (util/concat-without-nil
                              (mapcat
@@ -304,7 +302,7 @@
       [[key]])))
 
 (defn refresh!
-  [repo-url {:keys [key data] :as handler-opts}]
+  [repo-url handler-opts]
   (let [related-keys (get-related-keys handler-opts)
         db (conn/get-conn repo-url)]
     (doseq [related-key related-keys]
@@ -336,7 +334,7 @@
                 (set-new-result! related-key new-result)))))))))
 
 (defn transact-react!
-  [repo-url tx-data {:keys [key data] :as handler-opts}]
+  [repo-url tx-data handler-opts]
   (when-not config/publishing?
     (let [repo-url (or repo-url (state/get-current-repo))
           tx-data (->> (util/remove-nils tx-data)

+ 48 - 42
src/main/frontend/external/roam.cljc

@@ -1,19 +1,21 @@
 (ns frontend.external.roam
   (:require #?(:cljs [cljs-bean.core :as bean]
                :clj [cheshire.core :as json])
-            #?(:cljs ["/frontend/utils" :as utils])
+            ;; TODO: clj-kondo incorrectly thinks these requires are unused
+            #_:clj-kondo/ignore
             [frontend.external.protocol :as protocol]
+            #_:clj-kondo/ignore
+            [frontend.date :as date]
             [medley.core :as medley]
             [clojure.walk :as walk]
             [clojure.string :as string]
             [frontend.util :as util]
-            [frontend.text :as text]
-            [frontend.date :as date]))
+            [frontend.text :as text]))
 
 (defonce all-refed-uids (atom #{}))
 (defonce uid->uuid (atom {}))
 
-(defn- reset-state!
+(defn reset-state!
   []
   (reset! all-refed-uids #{})
   (reset! uid->uuid {}))
@@ -39,6 +41,8 @@
   (string/replace text macro-pattern (fn [[original text]]
                                        (let [[name arg] (util/split-first ":" text)]
                                          (if name
+                                           ;; TODO: Why unresolved var
+                                           #_:clj-kondo/ignore
                                            (let [name (text/page-ref-un-brackets! name)]
                                              (util/format "{{%s %s}}" name arg))
                                            original)))))
@@ -75,7 +79,7 @@
 
 (declare children->text)
 (defn child->text
-  [{:keys [uid string children] :as child} level]
+  [{:keys [uid string children]} level]
   (when-not (and (get @uid->uuid uid) uid)
     (swap! uid->uuid assoc uid (medley/random-uuid)))
   (let [children-text (children->text children (inc level))
@@ -98,48 +102,50 @@
        (interpose "\n")
        (apply str)))
 
-(defn ->file
-  [page-data]
-  (let [{:keys [create-time title children edit-time]} page-data
-        initial-level 1
-        text (when (seq children)
-               (when-let [text (children->text children (dec initial-level))]
-                 (let [journal? (date/valid-journal-title? title)
-                       front-matter (if journal?
-                                      ""
-                                      (util/format "---\ntitle: %s\n---\n\n" title))]
-                   (str front-matter (transform text)))))]
-    (when (and (not (string/blank? title))
-               text)
-      {:title title
-       :created-at create-time
-       :last-modified-at edit-time
-       :text text})))
-
-(defn ->files
-  [edn-data]
-  (load-all-refed-uids! edn-data)
-  (let [files (map ->file edn-data)
-        files (remove #(nil? (:title %)) files)
-        files (group-by (fn [f] (string/lower-case (:title f)))
-                        files)]
-    (map
-     (fn [[_ [fst & others]]]
-       (assoc fst :text
-              (->> (map :text (cons fst others))
-                   (interpose "\n")
-                   (apply str))))
-     files)))
-
 (defn json->edn
   [raw-string]
   #?(:cljs (-> raw-string js/JSON.parse bean/->clj)
      :clj (-> raw-string json/parse-string clojure.walk/keywordize-keys)))
 
-(defrecord Roam []
-  protocol/External
-  (toMarkdownFiles [this content _config]
-    (-> content json->edn ->files)))
+#?(:cljs
+   (do
+     (defn ->file
+      [page-data]
+      (let [{:keys [create-time title children edit-time]} page-data
+            initial-level 1
+            text (when (seq children)
+                   (when-let [text (children->text children (dec initial-level))]
+                     (let [journal? (date/valid-journal-title? title)
+                           front-matter (if journal?
+                                          ""
+                                          (util/format "---\ntitle: %s\n---\n\n" title))]
+                       (str front-matter (transform text)))))]
+        (when (and (not (string/blank? title))
+                   text)
+          {:title title
+           :created-at create-time
+           :last-modified-at edit-time
+           :text text})))
+
+     (defn ->files
+       [edn-data]
+       (load-all-refed-uids! edn-data)
+       (let [files (map ->file edn-data)
+             files (remove #(nil? (:title %)) files)
+             files (group-by (fn [f] (string/lower-case (:title f)))
+                             files)]
+         (map
+          (fn [[_ [fst & others]]]
+            (assoc fst :text
+                   (->> (map :text (cons fst others))
+                        (interpose "\n")
+                        (apply str))))
+          files)))
+
+     (defrecord Roam []
+       protocol/External
+       (toMarkdownFiles [_this content _config]
+                        (-> content json->edn ->files)))))
 
 (comment
   (defonce test-roam-json (frontend.db/get-file "same.json"))

+ 7 - 11
src/main/frontend/format/adoc.cljs

@@ -5,15 +5,11 @@
 (defn loaded? []
   js/window.Asciidoctor)
 
-(defn ->edn
-  [content config]
-  nil)
-
 (defrecord AdocMode []
   protocol/Format
-  (toEdn [this content config]
-    (->edn content config))
-  (toHtml [this content config references]
+  (toEdn [_this _content _config]
+    nil)
+  (toHtml [_this content _config _references]
     (when (loaded?)
       (let [config {:attributes {:showTitle false
                                  :hardbreaks true
@@ -21,13 +17,13 @@
                                  ;; :source-highlighter "pygments"
                                  }}]
         (.convert (js/window.Asciidoctor) content (clj->js config)))))
-  (loaded? [this]
+  (loaded? [_this]
     (some? (loaded?)))
-  (lazyLoad [this ok-handler]
+  (lazyLoad [_this ok-handler]
     (loader/load
      "https://cdnjs.cloudflare.com/ajax/libs/asciidoctor.js/1.5.9/asciidoctor.min.js"
      ok-handler))
-  (exportMarkdown [this content config references]
+  (exportMarkdown [_this _content _config _references]
     (throw "not support"))
-  (exportOPML [this content config title references]
+  (exportOPML [_this _content _config _title _references]
     (throw "not support")))

+ 44 - 43
src/main/frontend/format/block.cljs

@@ -176,7 +176,6 @@
   [properties]
   (when (seq properties)
     (let [properties (seq properties)
-          properties-order (keys properties)
           page-refs (->>
                      properties
                      (remove (fn [[k _]]
@@ -274,7 +273,7 @@
              {:block/name page-name
               :block/original-name original-page-name}
              (when with-id?
-               (if-let [block (db/entity [:block/name page-name])]
+               (if (db/entity [:block/name page-name])
                  {}
                  {:block/uuid (db/new-block-id)}))
              (when namespace?
@@ -437,16 +436,15 @@
                                       end-pos)
                       (utf8/substring utf8-content
                                       (:start-pos meta))))
-        content-orig content]
-    (let [content (when content
-                    (let [content (text/remove-level-spaces content format)]
-                      (if (or (:pre-block? block)
-                              (= (:format block) :org))
-                        content
-                        (text/remove-indentation-spaces content (inc (:level block)) false))))]
-      (if (= format :org)
-        content
-        (property/->new-properties content)))))
+        content (when content
+                  (let [content (text/remove-level-spaces content format)]
+                    (if (or (:pre-block? block)
+                            (= (:format block) :org))
+                      content
+                      (text/remove-indentation-spaces content (inc (:level block)) false))))]
+    (if (= format :org)
+      content
+      (property/->new-properties content))))
 
 (defn- remove-indentations
   [format level element]
@@ -500,6 +498,36 @@
           block-tags->pages
           (update :refs (fn [col] (remove nil? col)))))
 
+(defn extract-blocks*
+  [blocks pre-block-body pre-block-properties encoded-content]
+  (let [first-block (first blocks)
+        first-block-start-pos (get-in first-block [:block/meta :start-pos])
+        blocks (if (or (seq @pre-block-body)
+                       (seq @pre-block-properties))
+                 (cons
+                  (merge
+                   (let [content (utf8/substring encoded-content 0 first-block-start-pos)
+                         id (get-custom-id-or-new-id {:properties @pre-block-properties})
+                         block {:uuid id
+                                :content content
+                                :level 1
+                                :meta {:start-pos 0
+                                       :end-pos (or first-block-start-pos
+                                                    (utf8/length encoded-content))}
+                                :body @pre-block-body
+                                :properties @pre-block-properties
+                                :properties-order (keys @pre-block-properties)
+                                :refs (get-page-refs-from-properties @pre-block-properties)
+                                :pre-block? true
+                                :unordered true}
+                         block (with-page-block-refs block false)]
+                     (block-keywordize block))
+                   (select-keys first-block [:block/format :block/page]))
+                  blocks)
+                 blocks)
+        blocks (map (fn [block] (dissoc block :block/anchor)) blocks)]
+    (with-path-refs blocks)))
+
 (defn extract-blocks
   [blocks content with-id? format]
   (try
@@ -518,7 +546,7 @@
                  children []
                  block-all-content []]
             (if (seq blocks)
-              (let [[block {:keys [start_pos end_pos] :as block-content}] (first blocks)
+              (let [[block {:keys [start_pos _end_pos] :as block-content}] (first blocks)
                     block-content (when (string? block-content) block-content)
                     unordered? (:unordered (second block))
                     markdown-heading? (and (:size (second block)) (= :markdown format))]
@@ -609,33 +637,7 @@
                     (reset! pre-block-properties properties)))
                 (-> (reverse headings)
                     safe-blocks))))]
-      (let [first-block (first blocks)
-            first-block-start-pos (get-in first-block [:block/meta :start-pos])
-            blocks (if (or (seq @pre-block-body)
-                           (seq @pre-block-properties))
-                     (cons
-                      (merge
-                       (let [content (utf8/substring encoded-content 0 first-block-start-pos)
-                             id (get-custom-id-or-new-id {:properties @pre-block-properties})
-                             block {:uuid id
-                                    :content content
-                                    :level 1
-                                    :meta {:start-pos 0
-                                           :end-pos (or first-block-start-pos
-                                                        (utf8/length encoded-content))}
-                                    :body @pre-block-body
-                                    :properties @pre-block-properties
-                                    :properties-order (keys @pre-block-properties)
-                                    :refs (get-page-refs-from-properties @pre-block-properties)
-                                    :pre-block? true
-                                    :unordered true}
-                             block (with-page-block-refs block false)]
-                         (block-keywordize block))
-                       (select-keys first-block [:block/format :block/page]))
-                      blocks)
-                     blocks)
-            blocks (map (fn [block] (dissoc block :block/anchor)) blocks)]
-        (with-path-refs blocks)))
+      (extract-blocks* blocks pre-block-body pre-block-properties encoded-content))
     (catch js/Error e
       (js/console.error "extract-blocks-failed")
       (log/error :exception e))))
@@ -646,13 +648,13 @@
          parents [{:page/id page-id     ; db id or a map {:block/name "xxx"}
                    :block/level 0
                    :block/level-spaces 0}]
-         sibling nil
+         _sibling nil
          result []]
     (if (empty? blocks)
       (map #(dissoc % :block/level-spaces) result)
       (let [[block & others] blocks
             level-spaces (:block/level-spaces block)
-            {:block/keys [uuid level parent unordered] :as last-parent} (last parents)
+            {:block/keys [uuid level parent] :as last-parent} (last parents)
             parent-spaces (:block/level-spaces last-parent)
             [blocks parents sibling result]
             (cond
@@ -696,7 +698,6 @@
                 :else
                 (let [[f r] (split-with (fn [p] (<= (:block/level-spaces p) level-spaces)) parents)
                       left (first r)
-                      parents' (->> (concat f [left]) vec)
                       parent-id (if-let [block-id (:block/uuid (last f))]
                                   [:block/uuid block-id]
                                   page-id)

+ 11 - 12
src/main/frontend/format/mldoc.cljs

@@ -162,11 +162,10 @@
                    (->>
                     (map
                      (fn [[_ v]]
-                       (do
-                         (let [[k v] (util/split-first " " v)]
-                          (mapv
-                           string/trim
-                           [k v]))))
+                       (let [[k v] (util/split-first " " v)]
+                         (mapv
+                          string/trim
+                          [k v])))
                      macro-properties)
                     (into {}))
                    {})
@@ -200,7 +199,7 @@
                          (update :roam_alias ->vec)
                          (update :roam_tags (constantly roam-tags))
                          (update :filetags (constantly filetags)))
-          properties (medley/filter-kv (fn [k v] (not (empty? v))) properties)
+          properties (medley/filter-kv (fn [_k v] (seq v)) properties)
           properties (medley/map-vals util/unquote-string-if-wrapped properties)]
       (if (seq properties)
         (cons [["Properties" properties] nil] other-ast)
@@ -292,17 +291,17 @@
 
 (defrecord MldocMode []
   protocol/Format
-  (toEdn [this content config]
+  (toEdn [_this content config]
     (->edn content config))
-  (toHtml [this content config references]
+  (toHtml [_this content config references]
     (export "html" content config references))
-  (loaded? [this]
+  (loaded? [_this]
     true)
-  (lazyLoad [this ok-handler]
+  (lazyLoad [_this _ok-handler]
     true)
-  (exportMarkdown [this content config references]
+  (exportMarkdown [_this content config references]
     (parse-export-markdown content config references))
-  (exportOPML [this content config title references]
+  (exportOPML [_this content config title references]
     (parse-export-opml content config title references)))
 
 (defn plain->text

+ 11 - 11
src/main/frontend/fs/bfs.cljs

@@ -5,34 +5,34 @@
 
 (defrecord Bfs []
   protocol/Fs
-  (mkdir! [this dir]
+  (mkdir! [_this dir]
     (when (and js/window.pfs (not (util/electron?)))
       (->
        (js/window.pfs.mkdir dir)
        (p/catch (fn [error] (println "Mkdir error: " error))))))
-  (readdir [this dir]
+  (readdir [_this dir]
     (when js/window.pfs
       (js/window.pfs.readdir dir)))
-  (unlink! [this repo path opts]
+  (unlink! [_this _repo path opts]
     (when js/window.pfs
       (p/let [stat (js/window.pfs.stat path)]
         (if (= (.-type stat) "file")
           (js/window.pfs.unlink path opts)
           (p/rejected "Unlinking a directory is not allowed")))))
-  (rmdir! [this dir]
+  (rmdir! [_this dir]
     (js/window.workerThread.rimraf dir))
-  (read-file [this dir path options]
+  (read-file [_this dir path options]
     (js/window.pfs.readFile (str dir "/" path) (clj->js options)))
-  (write-file! [this repo dir path content opts]
+  (write-file! [_this _repo dir path content _opts]
     (when-not (util/electron?)
       (js/window.pfs.writeFile (str dir "/" path) content)))
-  (rename! [this repo old-path new-path]
+  (rename! [_this _repo old-path new-path]
     (js/window.pfs.rename old-path new-path))
-  (stat [this dir path]
+  (stat [_this dir path]
     (js/window.pfs.stat (str dir path)))
-  (open-dir [this ok-handler]
+  (open-dir [_this _ok-handler]
     nil)
-  (get-files [this path-or-handle ok-handler]
+  (get-files [_this _path-or-handle _ok-handler]
     nil)
-  (watch-dir! [this dir]
+  (watch-dir! [_this _dir]
     nil))

+ 21 - 24
src/main/frontend/fs/capacitor_fs.cljs

@@ -1,21 +1,18 @@
 (ns frontend.fs.capacitor-fs
   (:require [frontend.fs.protocol :as protocol]
             [lambdaisland.glogi :as log]
-            [cljs.core.async :as a]
-            [cljs.core.async.interop :refer [<p!]]
             [frontend.util :as futil]
             [frontend.config :as config]
             [cljs-bean.core :as bean]
-            ["@capacitor/filesystem" :refer [Filesystem Directory Encoding]]
-            [frontend.mobile.util :as util]
+            ["@capacitor/filesystem" :refer [Filesystem Encoding]]
             [promesa.core :as p]
             [clojure.string :as string]
             [frontend.mobile.util :as mobile-util]))
 
-(when (util/native-ios?)
+(when (mobile-util/native-ios?)
   (defn iOS-ensure-documents!
     []
-    (.ensureDocuments util/ios-file-container)))
+    (.ensureDocuments mobile-util/ios-file-container)))
 
 (defn check-permission-android []
   (p/let [permission (.checkPermissions Filesystem)
@@ -98,7 +95,7 @@
 
 (defrecord Capacitorfs []
   protocol/Fs
-  (mkdir! [this dir]
+  (mkdir! [_this dir]
     (p/let [result (.mkdir Filesystem
                            (clj->js
                             {:path dir
@@ -106,7 +103,7 @@
                              }))]
       (js/console.log result)
       result))
-  (mkdir-recur! [this dir]
+  (mkdir-recur! [_this dir]
     (p/let [result (.mkdir Filesystem
                            (clj->js
                             {:path dir
@@ -114,14 +111,14 @@
                              :recursive true}))]
       (js/console.log result)
       result))
-  (readdir [this dir]                   ; recursive
+  (readdir [_this dir]                   ; recursive
     (readdir dir))
-  (unlink! [this repo path _opts]
+  (unlink! [_this _repo _path _opts]
     nil)
-  (rmdir! [this dir]
+  (rmdir! [_this _dir]
     ;; Too dangerious!!! We'll never implement this.
     nil)
-  (read-file [this dir path _options]
+  (read-file [_this dir path _options]
     (let [path (str dir path)
           path (if (or (string/starts-with? path "file:")
                        (string/starts-with? path "content:"))
@@ -136,9 +133,9 @@
          content)
        (p/catch (fn [error]
                   (js/alert error))))))
-  (delete-file! [this repo dir path {:keys [ok-handler error-handler] :as opts}]
+  (delete-file! [_this repo dir path {:keys [ok-handler error-handler]}]
     (let [path (cond
-                 (= (util/platform) "ios")
+                 (= (mobile-util/platform) "ios")
                  (js/encodeURI (js/decodeURI path))
 
                  (string/starts-with? path (config/get-repo-dir repo))
@@ -157,9 +154,9 @@
          (if error-handler
            (error-handler error)
            (log/error :delete-file-failed error))))))
-  (write-file! [this repo dir path content {:keys [ok-handler error-handler] :as opts}]
+  (write-file! [_this repo dir path content {:keys [ok-handler error-handler]}]
     (let [path (cond
-                 (= (util/platform) "ios")
+                 (= (mobile-util/platform) "ios")
                  (js/encodeURI (js/decodeURI path))
 
                  (string/starts-with? path (config/get-repo-dir repo))
@@ -181,28 +178,28 @@
             (if error-handler
               (error-handler error)
               (log/error :write-file-failed error))))))
-  (rename! [this repo old-path new-path]
+  (rename! [_this _repo _old-path _new-path]
     nil)
-  (stat [this dir path]
+  (stat [_this dir path]
     (let [path (str dir path)]
       (p/let [result (.stat Filesystem (clj->js
                                         {:path path
                                          ;; :directory (.-ExternalStorage Directory)
                                          }))]
         result)))
-  (open-dir [this ok-handler]
-    (p/let [_    (when (= (util/platform) "android") (check-permission-android))
+  (open-dir [_this _ok-handler]
+    (p/let [_    (when (= (mobile-util/platform) "android") (check-permission-android))
             path (p/chain
-                  (.pickFolder util/folder-picker)
+                  (.pickFolder mobile-util/folder-picker)
                   #(js->clj % :keywordize-keys true)
                   :path)
-            _ (when (util/native-ios?) (.downloadFilesFromiCloud util/download-icloud-files))
+            _ (when (mobile-util/native-ios?) (.downloadFilesFromiCloud mobile-util/download-icloud-files))
             files (readdir path)
             files (js->clj files :keywordize-keys true)]
       (into [] (concat [{:path path}] files))))
-  (get-files [this path-or-handle _ok-handler]
+  (get-files [_this path-or-handle _ok-handler]
     (readdir path-or-handle))
-  (watch-dir! [this dir]
+  (watch-dir! [_this _dir]
     nil))
 
 

+ 12 - 15
src/main/frontend/fs/nfs.cljs

@@ -65,7 +65,7 @@
 
 (defrecord Nfs []
   protocol/Fs
-  (mkdir! [this dir]
+  (mkdir! [_this dir]
     (let [parts (->> (string/split dir "/")
                      (remove string/blank?))
           root (->> (butlast parts)
@@ -87,7 +87,7 @@
                   (js/console.debug "mkdir error: " error ", dir: " dir)
                   (throw error))))))
 
-  (readdir [this dir]
+  (readdir [_this dir]
     (let [prefix (str "handle/" dir)
           cached-files (keys @nfs-file-handles-cache)]
       (p/resolved
@@ -95,7 +95,7 @@
             (map (fn [path]
                    (string/replace path prefix "")))))))
 
-  (unlink! [this repo path opts]
+  (unlink! [this repo path _opts]
     (let [[dir basename] (util/get-dir-and-basename path)
           handle-path (str "handle" path)]
       (->
@@ -121,19 +121,18 @@
                   (log/error :unlink/path {:path path
                                            :error error}))))))
 
-  (rmdir! [this dir]
+  (rmdir! [_this _dir]
     ;; TOO dangerious, we should never implement this
     nil)
 
-  (read-file [this dir path options]
+  (read-file [_this dir path _options]
     (let [handle-path (str "handle" dir "/" path)]
       (p/let [handle (idb/get-item handle-path)
               local-file (and handle (.getFile handle))]
         (and local-file (.text local-file)))))
 
-  (write-file! [this repo dir path content opts]
-    (let [last-modified-at (db/get-file-last-modified-at repo path)
-          parts (string/split path "/")
+  (write-file! [_this repo dir path content opts]
+    (let [parts (string/split path "/")
           basename (last parts)
           sub-dir (->> (butlast parts)
                        (remove string/blank?)
@@ -212,9 +211,7 @@
                         (js/console.error error)))))))))
 
   (rename! [this repo old-path new-path]
-    (p/let [[dir basename] (util/get-dir-and-basename old-path)
-            [_ new-basename] (util/get-dir-and-basename new-path)
-            parts (->> (string/split new-path "/")
+    (p/let [parts (->> (string/split new-path "/")
                        (remove string/blank?))
             dir (str "/" (first parts))
             new-path (->> (rest parts)
@@ -224,7 +221,7 @@
             content (.text file)
             _ (protocol/write-file! this repo dir new-path content nil)]
       (protocol/unlink! this repo old-path nil)))
-  (stat [this dir path]
+  (stat [_this dir path]
     (if-let [file (get-nfs-file-handle (str "handle/"
                                             (string/replace-first dir "/" "")
                                             path))]
@@ -234,12 +231,12 @@
            :file/size (get-attr "size")
            :file/type (get-attr "type")}))
       (p/rejected "File not exists")))
-  (open-dir [this ok-handler]
+  (open-dir [_this ok-handler]
     (utils/openDirectory #js {:recursive true}
                          ok-handler))
-  (get-files [this path-or-handle ok-handler]
+  (get-files [_this path-or-handle ok-handler]
     (utils/getFiles path-or-handle true ok-handler))
 
   ;; TODO:
-  (watch-dir! [this dir]
+  (watch-dir! [_this _dir]
     nil))

+ 13 - 15
src/main/frontend/fs/node.cljs

@@ -35,7 +35,7 @@
       (p/resolved (= (string/trim disk-content) (string/trim db-content))))))
 
 (defn- write-file-impl!
-  [this repo dir path content {:keys [ok-handler error-handler skip-compare?] :as opts} stat]
+  [this repo dir path content {:keys [ok-handler error-handler skip-compare?]} stat]
   (if skip-compare?
     (p/catch
         (p/let [result (ipc/ipc "writeFile" repo path content)]
@@ -53,8 +53,6 @@
                                           nil))))
             disk-content (or disk-content "")
             ext (string/lower-case (util/get-file-ext path))
-            file-page (db/get-file-page-id path)
-            page-empty? (and file-page (db/page-empty? repo file-page))
             db-content (or (db/get-file repo path) "")
             contents-matched? (contents-matched? disk-content db-content)
             pending-writes (state/get-write-chan-length)]
@@ -101,23 +99,23 @@
 
 (defrecord Node []
   protocol/Fs
-  (mkdir! [this dir]
+  (mkdir! [_this dir]
     (ipc/ipc "mkdir" dir))
-  (mkdir-recur! [this dir]
+  (mkdir-recur! [_this dir]
     (ipc/ipc "mkdir-recur" dir))
-  (readdir [this dir]                   ; recursive
+  (readdir [_this dir]                   ; recursive
     (ipc/ipc "readdir" dir))
-  (unlink! [this repo path _opts]
+  (unlink! [_this repo path _opts]
     (ipc/ipc "unlink"
              (config/get-repo-dir repo)
              path))
-  (rmdir! [this dir]
+  (rmdir! [_this _dir]
     ;; Too dangerious!!! We'll never implement this.
     nil)
-  (read-file [this dir path _options]
+  (read-file [_this dir path _options]
     (let [path (concat-path dir path)]
       (ipc/ipc "readFile" path)))
-  (write-file! [this repo dir path content {:keys [ok-handler error-handler] :as opts}]
+  (write-file! [this repo dir path content opts]
     (let [path (concat-path dir path)]
       (p/let [stat (p/catch
                        (protocol/stat this dir path)
@@ -125,14 +123,14 @@
               sub-dir (first (util/get-dir-and-basename path))
               _ (protocol/mkdir-recur! this sub-dir)]
         (write-file-impl! this repo dir path content opts stat))))
-  (rename! [this repo old-path new-path]
+  (rename! [_this _repo old-path new-path]
     (ipc/ipc "rename" old-path new-path))
-  (stat [this dir path]
+  (stat [_this dir path]
     (let [path (concat-path dir path)]
       (ipc/ipc "stat" path)))
-  (open-dir [this ok-handler]
+  (open-dir [_this _ok-handler]
     (open-dir))
-  (get-files [this path-or-handle ok-handler]
+  (get-files [_this path-or-handle _ok-handler]
     (ipc/ipc "getFiles" path-or-handle))
-  (watch-dir! [this dir]
+  (watch-dir! [_this dir]
     (ipc/ipc "addDirWatcher" dir)))

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

@@ -1550,7 +1550,7 @@
                                      true)]
       (commands/restore-state restore-slash-caret-pos?))))
 
-(defn- get-asset-file-link
+(defn get-asset-file-link
   [format url file-name image?]
   (let [pdf? (and url (string/ends-with? url ".pdf"))]
     (case (keyword format)

+ 5 - 6
src/main/frontend/handler/repo.cljs

@@ -261,8 +261,7 @@
         (parse-files-and-create-default-files! repo-url files delete-files delete-blocks file-paths first-clone? db-encrypted? re-render? re-render-opts metadata opts)))))
 
 (defn load-repo-to-db!
-  [repo-url {:keys [first-clone? diffs nfs-files refresh?]
-             :as opts}]
+  [repo-url {:keys [first-clone? diffs nfs-files refresh?]}]
   (spec/validate :repos/url repo-url)
   (when (= :repos (state/get-current-route))
     (route-handler/redirect-to-home!))
@@ -380,9 +379,9 @@
                          result (git/fetch repo-url token)]
                    (let [{:keys [fetchHead]} (bean/->clj result)]
                      (-> (git/merge repo-url)
-                         (p/then (fn [result]
+                         (p/then (fn [_result]
                                    (-> (git/checkout repo-url)
-                                       (p/then (fn [result]
+                                       (p/then (fn [_result]
                                                  (git-handler/set-git-status! repo-url nil)
                                                  (git-handler/set-git-last-pulled-at! repo-url)
                                                  (when (and local-latest-commit fetchHead
@@ -503,7 +502,7 @@
        (do
          (state/set-cloning! true)
          (git/clone repo-url token))
-       (fn [result]
+       (fn [_result]
          (state/set-current-repo! repo-url)
          (db/start-db-conn! (state/get-me) repo-url)
          (db/mark-repo-as-cloned! repo-url))
@@ -603,7 +602,7 @@
   (spec/validate :state/me me)
   (if (and js/window.git js/window.pfs)
     (do
-      (doseq [{:keys [id url]} (:repos me)]
+      (doseq [{:keys [url]} (:repos me)]
         (let [repo url]
           (if (db/cloned? repo)
             (p/do!

+ 1 - 5
src/main/frontend/mobile/core.cljs

@@ -3,12 +3,8 @@
             [frontend.state :as state]
             ["@capacitor/app" :refer [^js App]]
             ["@capacitor/keyboard" :refer [^js Keyboard]]
-            [reitit.frontend.easy :as rfe]
             [clojure.string :as string]
-            [frontend.handler.notification :as notification]
             [frontend.fs.capacitor-fs :as fs]
-            [frontend.handler.page :as page-handler]
-            [frontend.modules.shortcut.core :as shortcut]
             [frontend.components.repo :as repo]
             [frontend.handler.web.nfs :as nfs-handler]))
 
@@ -44,7 +40,7 @@
                   #(state/pub-event! [:mobile/keyboard-will-show]))
     (.addListener Keyboard "keyboardDidShow"
                   #(state/pub-event! [:mobile/keyboard-did-show]))
-    
+
     (.addListener App "appStateChange"
                   #(when-let [repo (state/get-current-repo)]
                      (nfs-handler/refresh! repo repo/refresh-cb)

+ 1 - 1
src/main/frontend/modules/datascript_report/core.cljs

@@ -21,7 +21,7 @@
       r)))
 
 (defn get-blocks-and-pages
-  [{:keys [db-before db-after tx-data tx-meta] :as tx-report}]
+  [{:keys [db-before db-after tx-data tx-meta]}]
   (let [updated-db-ids (-> (mapv first tx-data) (set))
         result (reduce
                 (fn [acc x]

+ 2 - 3
src/main/frontend/modules/editor/undo_redo.cljs

@@ -4,7 +4,6 @@
             [frontend.modules.datascript-report.core :as db-report]
             [frontend.db :as db]
             [frontend.state :as state]
-            [frontend.debug :as debug]
             [frontend.db.outliner :as db-outliner]
             [frontend.modules.outliner.pipeline :as pipelines]))
 
@@ -83,7 +82,7 @@
 (defn get-txs
   [redo? txs]
   (let [txs (if redo? txs (reverse txs))]
-    (mapv (fn [[id attr value tx add? :as datom]]
+    (mapv (fn [[id attr value tx add?]]
             (let [op (cond
                        (and redo? add?) :db/add
                        (and (not redo?) add?) :db/retract
@@ -103,7 +102,7 @@
   [txs]
   (let [conn (conn/get-conn false)
         db-report (d/transact! conn txs)]
-    (do (pipelines/invoke-hooks db-report))))
+    (pipelines/invoke-hooks db-report)))
 
 (defn- refresh!
   [opts]

+ 12 - 14
src/main/frontend/modules/file/core.cljs

@@ -6,7 +6,7 @@
             [frontend.db :as db]
             [frontend.db.utils :as db-utils]
             [frontend.state :as state]
-            [frontend.util :as util :refer [profile]]
+            [frontend.util :as util]
             [frontend.debug :as debug]
             [frontend.format.block :as block]))
 
@@ -26,7 +26,9 @@
          (ffirst body)))))
 
 (defn transform-content
-  [{:block/keys [uuid format properties pre-block? unordered content heading-level left page scheduled deadline parent] :as block} level {:keys [heading-to-list?]}]
+  [{:block/keys [uuid format properties pre-block? unordered content heading-level left page parent]}
+   level
+   {:keys [heading-to-list?]}]
   (let [{:block/keys [title body]} (block/parse-title-and-body uuid format pre-block? content)
         content (or content "")
         heading-with-title? (seq title)
@@ -85,8 +87,7 @@
     content))
 
 (defn tree->file-content
-  [tree {:keys [init-level heading-to-list?]
-         :or {heading-to-list? false}
+  [tree {:keys [init-level]
          :as opts}]
   (loop [block-contents []
          [f & r] tree
@@ -133,16 +134,13 @@
                   (-> (or (:block/original-name page) (:block/name page))
                       (util/page-name-sanity true))) "."
                 (if (= format "markdown") "md" format))
-          file-path (str "/" path)
-          dir (config/get-repo-dir repo)]
-      (let [file-path (config/get-file-path repo path)
-            page-blocks (db/get-page-blocks-no-cache (:block/name page))
-            file {:file/path file-path}
-            tx [{:file/path file-path}
-                {:block/name (:block/name page)
-                 :block/file file}]]
-        (db/transact! tx)
-        (when ok-handler (ok-handler))))))
+          file-path (config/get-file-path repo path)
+          file {:file/path file-path}
+          tx [{:file/path file-path}
+              {:block/name (:block/name page)
+               :block/file file}]]
+      (db/transact! tx)
+      (when ok-handler (ok-handler)))))
 
 (defn save-tree-aux!
   [page-block tree]

+ 1 - 1
src/main/frontend/modules/instrumentation/sentry.cljs

@@ -17,4 +17,4 @@
 (defn init []
   (let [config (clj->js config)
         init-fn (if (util/electron?) Sentry-electron/init Sentry/init)]
-    (Sentry/init config)))
+    (init-fn config)))

+ 2 - 2
src/main/frontend/modules/layout/core.cljs

@@ -5,7 +5,7 @@
 (defonce *movable-containers (atom {}))
 
 (defn- calc-layout-data
-  [^js cnt ^js evt]
+  [^js cnt ^js _evt]
   (.toJSON (.getBoundingClientRect cnt)))
 
 (defn ^:export move-container-to-top
@@ -111,4 +111,4 @@
     ;; manager
     (swap! *movable-containers assoc identity el)
 
-    #(swap! *movable-containers dissoc identity el)))
+    #(swap! *movable-containers dissoc identity el)))

+ 23 - 33
src/main/frontend/modules/outliner/core.cljs

@@ -320,7 +320,7 @@
 (defn- walk-&-insert-nodes
   [loc target-node sibling? transact]
   (let [update-node-fn
-        (fn [node new-node] new-node)]
+        (fn [_node new-node] new-node)]
     (if (zip/end? loc)
       loc
       (if (vector? (zip/node loc))
@@ -351,44 +351,34 @@
       (zip/left result-loc-or-vec)
       result-loc-or-vec)))
 
-(defn- get-node-tree-sub-topmost-last-loc
-  [loc]
-  (let [topmost-last-loc (get-node-tree-topmost-last-loc loc)
-        result-vec-or-nil (zip/right topmost-last-loc)]
-    (when (and (some? result-vec-or-nil)
-               (vector? (zip/node result-vec-or-nil)))
-      (get-node-tree-topmost-last-loc result-vec-or-nil))))
-
 (defn insert-nodes
   "Insert nodes as children(or siblings) of target-node.
   new-nodes-tree is an vector of blocks, e.g [1 [2 3] 4 [5 [6 7]]]"
   [new-nodes-tree target-node sibling?]
   (ds/auto-transact!
    [txs-state (ds/new-outliner-txs-state)] {:outliner-op :insert-nodes}
-   (let [loc (zip/vector-zip new-nodes-tree)]
-     ;; TODO: validate new-nodes-tree structure
-     (let [updated-nodes (walk-&-insert-nodes loc target-node sibling? txs-state)
-           loc (zip/vector-zip (zip/root updated-nodes))
-           ;; topmost-last-loc=4, new-nodes-tree=[1 [2 3] 4 [5 [6 7]]]
-           topmost-last-loc (get-node-tree-topmost-last-loc loc)
-           ;; sub-topmost-last-loc=5, new-nodes-tree=[1 [2 3] 4 [5 [6 7]]]
-           sub-topmost-last-loc (get-node-tree-sub-topmost-last-loc loc)
-           right-node (tree/-get-right target-node)
-           down-node (tree/-get-down target-node)]
-       ;; update node's left&parent after inserted nodes
-       (cond
-         (and (not sibling?) (some? right-node) (nil? down-node))
-         nil            ;ignore
-         (and sibling? (some? right-node) topmost-last-loc) ;; right-node.left=N
-         (let [topmost-last-node (zip/node topmost-last-loc)
-               updated-node (tree/-set-left-id right-node (tree/-get-id topmost-last-node))]
-           (tree/-save updated-node txs-state))
-         (and (not sibling?) (some? down-node) topmost-last-loc) ;; down-node.left=N
-         (let [topmost-last-node (zip/node topmost-last-loc)
-               updated-node (tree/-set-left-id down-node (tree/-get-id topmost-last-node))]
-           (tree/-save updated-node txs-state))
-         (and sibling? (some? down-node)) ;; unchanged
-         nil)))))
+   ;; TODO: validate new-nodes-tree structure
+   (let [loc (zip/vector-zip new-nodes-tree)
+         updated-nodes (walk-&-insert-nodes loc target-node sibling? txs-state)
+         loc (zip/vector-zip (zip/root updated-nodes))
+         ;; topmost-last-loc=4, new-nodes-tree=[1 [2 3] 4 [5 [6 7]]]
+         topmost-last-loc (get-node-tree-topmost-last-loc loc)
+         right-node (tree/-get-right target-node)
+         down-node (tree/-get-down target-node)]
+     ;; update node's left&parent after inserted nodes
+     (cond
+       (and (not sibling?) (some? right-node) (nil? down-node))
+       nil            ;ignore
+       (and sibling? (some? right-node) topmost-last-loc) ;; right-node.left=N
+       (let [topmost-last-node (zip/node topmost-last-loc)
+             updated-node (tree/-set-left-id right-node (tree/-get-id topmost-last-node))]
+         (tree/-save updated-node txs-state))
+       (and (not sibling?) (some? down-node) topmost-last-loc) ;; down-node.left=N
+       (let [topmost-last-node (zip/node topmost-last-loc)
+             updated-node (tree/-set-left-id down-node (tree/-get-id topmost-last-node))]
+         (tree/-save updated-node txs-state))
+       (and sibling? (some? down-node)) ;; unchanged
+       nil))))
 
 (defn move-nodes
   "Move nodes up/down."

+ 1 - 2
src/main/frontend/modules/outliner/datascript.cljc

@@ -7,8 +7,7 @@
                      [frontend.modules.editor.undo-redo :as undo-redo]
                      [frontend.state :as state]
                      [frontend.config :as config]
-                     [lambdaisland.glogi :as log]
-                     [frontend.util :as util])))
+                     [lambdaisland.glogi :as log])))
 
 #?(:cljs
    (defn new-outliner-txs-state [] (atom [])))

+ 1 - 3
src/main/frontend/modules/outliner/file.cljs

@@ -7,11 +7,9 @@
             [frontend.handler.notification :as notification]
             [frontend.modules.file.core :as file]
             [frontend.modules.outliner.tree :as tree]
-            [frontend.state :as state]
             [frontend.util :as util]
             [goog.object :as gobj]
-            [lambdaisland.glogi :as log]
-            [frontend.debug :as debug]))
+            [lambdaisland.glogi :as log]))
 
 (def write-chan (async/chan))
 

+ 2 - 2
src/main/frontend/modules/outliner/pipeline.cljs

@@ -2,12 +2,12 @@
   (:require [frontend.modules.datascript-report.core :as ds-report]
             [frontend.modules.outliner.file :as file]
             [frontend.db :as db]
-            [frontend.state :as state]
             [frontend.util :as util]
             [frontend.debug :as debug]))
 
+;; TODO: Do something or remove
 (defn updated-block-hook
-  [block])
+  [_block])
 
 (defn updated-page-hook
   [page]

+ 3 - 4
src/main/frontend/modules/outliner/tree.cljs

@@ -23,9 +23,8 @@
   (satisfies? INode node))
 
 (defn- blocks->vec-tree-aux
-  [blocks root page?]
-  (let [*idx (atom (if page? 0 -1))
-        id-map (fn [m] {:db/id (:db/id m)})
+  [blocks root]
+  (let [id-map (fn [m] {:db/id (:db/id m)})
         root (id-map root)
         parent-blocks (group-by :block/parent blocks)
         sort-fn (fn [parent]
@@ -55,7 +54,7 @@
   (let [[page? root] (get-root-and-page (str root-id))]
     (if-not root ; custom query
       blocks
-      (let [result (blocks->vec-tree-aux blocks root page?)]
+      (let [result (blocks->vec-tree-aux blocks root)]
         (if page?
           result
           ;; include root block

+ 4 - 4
src/main/frontend/modules/shortcut/data_helper.cljs

@@ -149,10 +149,10 @@
             new-result (rewrite/update
                         result
                         :shortcuts
-                        #(dissoc (rewrite/sexpr %) k))]
-        (let [new-content (str new-result)]
-          (common-handler/reset-config! repo new-content)
-          (file/set-file-content! repo path new-content))))))
+                        #(dissoc (rewrite/sexpr %) k))
+            new-content (str new-result)]
+        (common-handler/reset-config! repo new-content)
+        (file/set-file-content! repo path new-content)))))
 
 (defn get-group
   "Given shortcut key, return handler group

+ 7 - 8
src/main/frontend/search/browser.cljs

@@ -9,8 +9,7 @@
 
 (defn search-blocks
   [repo q {:keys [limit page]
-            :or {limit 20}
-            :as option}]
+            :or {limit 20}}]
   (let [indice (or (get-in @indices [repo :blocks])
                    (search-db/make-blocks-indice! repo))
         result
@@ -22,7 +21,7 @@
         result (bean/->clj result)]
     (->>
      (map
-       (fn [{:keys [item matches] :as block}]
+       (fn [{:keys [item matches]}]
          (let [{:keys [content uuid page]} item]
            {:block/uuid uuid
             :block/content content
@@ -33,12 +32,12 @@
 
 (defrecord Browser [repo]
   protocol/Engine
-  (query [this q option]
+  (query [_this q option]
     (p/promise (search-blocks repo q option)))
-  (rebuild-blocks-indice! [this]
+  (rebuild-blocks-indice! [_this]
     (let [indice (search-db/make-blocks-indice! repo)]
       (p/promise indice)))
-  (transact-blocks! [this {:keys [blocks-to-remove-set
+  (transact-blocks! [_this {:keys [blocks-to-remove-set
                                   blocks-to-add]}]
     (swap! search-db/indices update-in [repo :blocks]
            (fn [indice]
@@ -51,7 +50,7 @@
                  (doseq [block blocks-to-add]
                    (.add indice (bean/->js block)))))
              indice)))
-  (truncate-blocks! [this]
+  (truncate-blocks! [_this]
     (swap! indices assoc-in [repo :blocks] nil))
-  (remove-db! [this]
+  (remove-db! [_this]
     nil))

+ 2 - 1
src/main/frontend/search/db.cljs

@@ -27,8 +27,9 @@
      :page page
      :content result}))
 
+;; TODO: Do we want to pass repo here?
 (defn build-blocks-indice
-  [repo]
+  [_repo]
   (->> (db/get-all-block-contents)
        (map block->index)
        (remove nil?)

+ 6 - 6
src/main/frontend/search/node.cljs

@@ -7,19 +7,19 @@
 
 (defrecord Node [repo]
   protocol/Engine
-  (query [this q opts]
+  (query [_this q opts]
     (p/let [result (ipc/ipc "search-blocks" repo q opts)
             result (bean/->clj result)]
-      (map (fn [{:keys [content id uuid page]}]
+      (map (fn [{:keys [content uuid page]}]
              {:block/uuid uuid
               :block/content content
               :block/page page}) result)))
-  (rebuild-blocks-indice! [this]
+  (rebuild-blocks-indice! [_this]
     (let [indice (search-db/build-blocks-indice repo)]
       (ipc/ipc "rebuild-blocks-indice" repo indice)))
-  (transact-blocks! [this data]
+  (transact-blocks! [_this data]
     (ipc/ipc "transact-blocks" repo (bean/->js data)))
-  (truncate-blocks! [this]
+  (truncate-blocks! [_this]
     (ipc/ipc "truncate-blocks" repo))
-  (remove-db! [this]
+  (remove-db! [_this]
     (ipc/ipc "remove-db" repo)))

+ 4 - 5
src/main/frontend/tools/html_export.cljs

@@ -6,7 +6,7 @@
             [frontend.db :as db]
             [frontend.extensions.slide :as slide]
             [medley.core :as medley]
-            [frontend.format.block :as block]))
+            [frontend.format.block :as format-block]))
 
 ;; Consider generate a db index so that search can still works
 
@@ -17,19 +17,18 @@
 
 (defn- build-block
   [config block]
-  (let [block (block/parse-title-and-body block)
+  (let [block (format-block/parse-title-and-body block)
         body (:block/body block)
         block (block/build-block-title config block)]
     [:div.block
      block
      (when (seq body)
        (for [child body]
-         (do
-           (block/markup-element-cp config child))))]))
+         (block/markup-element-cp config child)))]))
 
 (defn export-page
   [page-name blocks show-notification!]
-  (let [{:keys [slide] :as properties} (db/get-page-properties page-name)
+  (let [{:keys [slide]} (db/get-page-properties page-name)
         slide? slide
         blocks (if (:block/pre-block? (first blocks))
                  (rest blocks)