Pārlūkot izejas kodu

Migrate half the block deps to be nbb compatible

Gabriel Horner 3 gadi atpakaļ
vecāks
revīzija
b83f6bbd19

+ 2 - 0
.clj-kondo/config.edn

@@ -19,6 +19,7 @@
              frontend.db.react react
              frontend.db.react react
              frontend.db.query-react query-react
              frontend.db.query-react query-react
              frontend.util util
              frontend.util util
+             frontend.util.property property
              frontend.config config
              frontend.config config
              frontend.format.mldoc mldoc
              frontend.format.mldoc mldoc
              frontend.format.block block
              frontend.format.block block
@@ -26,6 +27,7 @@
              logseq.graph-parser.block gp-block
              logseq.graph-parser.block gp-block
              logseq.graph-parser.mldoc gp-mldoc
              logseq.graph-parser.mldoc gp-mldoc
              logseq.graph-parser.util gp-util
              logseq.graph-parser.util gp-util
+             logseq.graph-parser.property gp-property
              logseq.graph-parser.config gp-config}}}
              logseq.graph-parser.config gp-config}}}
 
 
  :hooks {:analyze-call {rum.core/defc hooks.rum/defc
  :hooks {:analyze-call {rum.core/defc hooks.rum/defc

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

@@ -499,7 +499,7 @@
   "Accepts {:block/name sanitized / unsanitized page-name}"
   "Accepts {:block/name sanitized / unsanitized page-name}"
   [{:keys [html-export? redirect-page-name label children contents-page? preview?] :as config} page]
   [{:keys [html-export? redirect-page-name label children contents-page? preview?] :as config} page]
   (when-let [page-name-in-block (:block/name page)]
   (when-let [page-name-in-block (:block/name page)]
-    (let [page-name-in-block (util/remove-boundary-slashes page-name-in-block)
+    (let [page-name-in-block (gp-util/remove-boundary-slashes page-name-in-block)
           page-name (util/page-name-sanity-lc page-name-in-block)
           page-name (util/page-name-sanity-lc page-name-in-block)
           page-entity (db/entity [:block/name page-name])
           page-entity (db/entity [:block/name page-name])
           redirect-page-name (or (and (= :org (state/get-preferred-format))
           redirect-page-name (or (and (= :org (state/get-preferred-format))

+ 2 - 2
src/main/frontend/format/block.cljs

@@ -6,7 +6,7 @@
             [frontend.db :as db]
             [frontend.db :as db]
             [frontend.format :as format]
             [frontend.format :as format]
             [frontend.state :as state]
             [frontend.state :as state]
-            [frontend.util.property :as property]
+            [logseq.graph-parser.property :as gp-property]
             [logseq.graph-parser.mldoc :as gp-mldoc]))
             [logseq.graph-parser.mldoc :as gp-mldoc]))
 
 
 (defn with-parent-and-left
 (defn with-parent-and-left
@@ -125,7 +125,7 @@
                title (when (gp-block/heading-block? (first ast))
                title (when (gp-block/heading-block? (first ast))
                        (:title (second (first ast))))
                        (:title (second (first ast))))
                body (vec (if title (rest ast) ast))
                body (vec (if title (rest ast) ast))
-               body (drop-while property/properties-ast? body)
+               body (drop-while gp-property/properties-ast? body)
                result (cond->
                result (cond->
                         (if (seq body) {:block/body body} {})
                         (if (seq body) {:block/body body} {})
                         title
                         title

+ 2 - 1
src/main/frontend/handler/external.cljs

@@ -9,6 +9,7 @@
             [frontend.db :as db]
             [frontend.db :as db]
             [frontend.format.mldoc :as mldoc]
             [frontend.format.mldoc :as mldoc]
             [logseq.graph-parser.block :as gp-block]
             [logseq.graph-parser.block :as gp-block]
+            [logseq.graph-parser.util :as gp-util]
             [frontend.handler.page :as page]
             [frontend.handler.page :as page]
             [frontend.handler.editor :as editor]
             [frontend.handler.editor :as editor]
             [frontend.util :as util]))
             [frontend.util :as util]))
@@ -26,7 +27,7 @@
                                       (when journal?
                                       (when journal?
                                         (date/journal-title->default title))
                                         (date/journal-title->default title))
                                       (string/replace title "/" "-"))
                                       (string/replace title "/" "-"))
-                               title (-> (util/page-name-sanity title)
+                               title (-> (gp-util/page-name-sanity title)
                                          (string/replace "\n" " "))
                                          (string/replace "\n" " "))
                                path (str (if journal?
                                path (str (if journal?
                                            (config/get-journals-directory)
                                            (config/get-journals-directory)

+ 3 - 3
src/main/frontend/handler/extract.cljs

@@ -14,7 +14,7 @@
             [logseq.graph-parser.util :as gp-util]
             [logseq.graph-parser.util :as gp-util]
             [logseq.graph-parser.mldoc :as gp-mldoc]
             [logseq.graph-parser.mldoc :as gp-mldoc]
             [logseq.graph-parser.block :as gp-block]
             [logseq.graph-parser.block :as gp-block]
-            [frontend.util.property :as property]
+            [logseq.graph-parser.property :as gp-property]
             [lambdaisland.glogi :as log]))
             [lambdaisland.glogi :as log]))
 
 
 (defn get-page-name
 (defn get-page-name
@@ -113,7 +113,7 @@
                                                  tags)))))
                                                  tags)))))
           namespace-pages (let [page (:block/original-name page-entity)]
           namespace-pages (let [page (:block/original-name page-entity)]
                             (when (text/namespace-page? page)
                             (when (text/namespace-page? page)
-                              (->> (util/split-namespace-pages page)
+                              (->> (gp-util/split-namespace-pages page)
                                    (map (fn [page]
                                    (map (fn [page]
                                           (-> (gp-block/page-name->map page true)
                                           (-> (gp-block/page-name->map page true)
                                               (assoc :block/format format)))))))
                                               (assoc :block/format format)))))))
@@ -149,7 +149,7 @@
                                                          ))]
                                                          ))]
       (println "Parsing finished : " file)
       (println "Parsing finished : " file)
       (let [first-block (ffirst ast)
       (let [first-block (ffirst ast)
-            properties (let [properties (and (property/properties-ast? first-block)
+            properties (let [properties (and (gp-property/properties-ast? first-block)
                                              (->> (last first-block)
                                              (->> (last first-block)
                                                   (map (fn [[x y]]
                                                   (map (fn [[x y]]
                                                          [x (if (string? y)
                                                          [x (if (string? y)

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

@@ -47,7 +47,7 @@
   [journal? title]
   [journal? title]
   (when-let [s (if journal?
   (when-let [s (if journal?
                  (date/journal-title->default title)
                  (date/journal-title->default title)
-                 (util/page-name-sanity (string/lower-case title)))]
+                 (gp-util/page-name-sanity (string/lower-case title)))]
     ;; Win10 file path has a length limit of 260 chars
     ;; Win10 file path has a length limit of 260 chars
     (gp-util/safe-subs s 0 200)))
     (gp-util/safe-subs s 0 200)))
 
 
@@ -118,12 +118,12 @@
                   properties          nil
                   properties          nil
                   split-namespace?    true}}]
                   split-namespace?    true}}]
    (let [title (string/trim title)
    (let [title (string/trim title)
-         title (util/remove-boundary-slashes title)
+         title (gp-util/remove-boundary-slashes title)
          page-name (util/page-name-sanity-lc title)
          page-name (util/page-name-sanity-lc title)
          repo (state/get-current-repo)]
          repo (state/get-current-repo)]
      (when (db/page-empty? repo page-name)
      (when (db/page-empty? repo page-name)
        (let [pages    (if split-namespace?
        (let [pages    (if split-namespace?
-                        (util/split-namespace-pages title)
+                        (gp-util/split-namespace-pages title)
                         [title])
                         [title])
              format   (or format (state/get-preferred-format))
              format   (or format (state/get-preferred-format))
              pages    (map (fn [page]
              pages    (map (fn [page]
@@ -170,7 +170,7 @@
 (defn- compute-new-file-path
 (defn- compute-new-file-path
   [old-path new-name]
   [old-path new-name]
   (let [result (string/split old-path "/")
   (let [result (string/split old-path "/")
-        file-name (util/page-name-sanity new-name true)
+        file-name (gp-util/page-name-sanity new-name true)
         ext (last (string/split (last result) "."))
         ext (last (string/split (last result) "."))
         new-file (str file-name "." ext)
         new-file (str file-name "." ext)
         parts (concat (butlast result) [new-file])]
         parts (concat (butlast result) [new-file])]
@@ -398,7 +398,7 @@
 
 
         ;; If page name changed after sanitization
         ;; If page name changed after sanitization
         (when (or (util/create-title-property? new-page-name)
         (when (or (util/create-title-property? new-page-name)
-                  (not= (util/page-name-sanity new-name false) new-name))
+                  (not= (gp-util/page-name-sanity new-name false) new-name))
           (page-property/add-property! new-page-name :title new-name))
           (page-property/add-property! new-page-name :title new-name))
 
 
         (when (and file (not journal?))
         (when (and file (not journal?))

+ 10 - 46
src/main/frontend/util.cljc

@@ -907,44 +907,18 @@
                 (string/includes? s "%")
                 (string/includes? s "%")
                 (string/includes? s "#"))))))
                 (string/includes? s "#"))))))
 
 
-(defn remove-boundary-slashes
-  [s]
-  (when (string? s)
-    (let [s (if (= \/ (first s))
-              (subs s 1)
-              s)]
-      (if (= \/ (last s))
-        (subs s 0 (dec (count s)))
-        s))))
-
-(defn normalize
-  [s]
-  (.normalize s "NFC"))
-
 #?(:cljs
 #?(:cljs
    (defn search-normalize
    (defn search-normalize
      "Normalize string for searching (loose)"
      "Normalize string for searching (loose)"
      [s]
      [s]
      (removeAccents (.normalize (string/lower-case s) "NFKC"))))
      (removeAccents (.normalize (string/lower-case s) "NFKC"))))
 
 
-(defn page-name-sanity
-  "Sanitize the page-name."
-  ([page-name]
-   (page-name-sanity page-name false))
-  ([page-name replace-slash?]
-   (let [page (some-> page-name
-                      (remove-boundary-slashes)
-                      (normalize))]
-     (if replace-slash?
-       (string/replace page #"/" "%2A")
-       page))))
-
 #?(:cljs
 #?(:cljs
    (defn file-name-sanity
    (defn file-name-sanity
      "Sanitize page-name for file name (strict), for file writing."
      "Sanitize page-name for file name (strict), for file writing."
      [page-name]
      [page-name]
      (some-> page-name
      (some-> page-name
-             page-name-sanity
+             gp-util/page-name-sanity
              ;; for android filesystem compatiblity
              ;; for android filesystem compatiblity
              (string/replace #"[\\#|%]+" url-encode)
              (string/replace #"[\\#|%]+" url-encode)
              ;; Windows reserved path characters
              ;; Windows reserved path characters
@@ -952,15 +926,16 @@
              (string/replace #"/" url-encode)
              (string/replace #"/" url-encode)
              (string/replace "*" "%2A"))))
              (string/replace "*" "%2A"))))
 
 
-(defn page-name-sanity-lc
-  "Sanitize the query string for a page name (mandate for :block/name)"
-  [s]
-  (page-name-sanity (string/lower-case s)))
+#?(:cljs
+   (def page-name-sanity-lc
+     "Delegate to gp-util to loosely couple app usages to graph-parser"
+     gp-util/page-name-sanity-lc))
 
 
-(defn safe-page-name-sanity-lc
-  [s]
-  (if (string? s)
-    (page-name-sanity-lc s) s))
+#?(:cljs
+ (defn safe-page-name-sanity-lc
+   [s]
+   (if (string? s)
+     (page-name-sanity-lc s) s)))
 
 
 (defn get-page-original-name
 (defn get-page-original-name
   [page]
   [page]
@@ -1240,17 +1215,6 @@
   [text]
   [text]
   (string/join (replace regex-char-esc-smap text)))
   (string/join (replace regex-char-esc-smap text)))
 
 
-(defn split-namespace-pages
-  [title]
-  (let [parts (string/split title "/")]
-    (loop [others (rest parts)
-           result [(first parts)]]
-      (if (seq others)
-        (let [prev (last result)]
-          (recur (rest others)
-                 (conj result (str prev "/" (first others)))))
-        result))))
-
 (comment
 (comment
   (re-matches (re-pattern (regex-escape "$u^8(d)+w.*[dw]d?")) "$u^8(d)+w.*[dw]d?"))
   (re-matches (re-pattern (regex-escape "$u^8(d)+w.*[dw]d?")) "$u^8(d)+w.*[dw]d?"))
 
 

+ 3 - 3
src/main/frontend/util/drawer.cljs

@@ -3,7 +3,7 @@
             [frontend.util :as util]
             [frontend.util :as util]
             [logseq.graph-parser.util :as gp-util]
             [logseq.graph-parser.util :as gp-util]
             [logseq.graph-parser.mldoc :as gp-mldoc]
             [logseq.graph-parser.mldoc :as gp-mldoc]
-            [frontend.util.property :as property]
+            [logseq.graph-parser.property :as gp-property]
             [frontend.format.mldoc :as mldoc]))
             [frontend.format.mldoc :as mldoc]))
 
 
 (defn drawer-start
 (defn drawer-start
@@ -55,8 +55,8 @@
                         (if has-properties?
                         (if has-properties?
                           (cond
                           (cond
                             (= :org format)
                             (= :org format)
-                            (let [prop-start-idx (.indexOf body-without-timestamps property/properties-start)
-                                  prop-end-idx (.indexOf body-without-timestamps property/properties-end)
+                            (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))
                                   properties (subvec body-without-timestamps prop-start-idx (inc prop-end-idx))
                                   after (subvec body-without-timestamps (inc prop-end-idx))]
                                   after (subvec body-without-timestamps (inc prop-end-idx))]
                               (string/join "\n" (concat [title] scheduled deadline properties [drawer] after)))
                               (string/join "\n" (concat [title] scheduled deadline properties [drawer] after)))

+ 6 - 47
src/main/frontend/util/property.cljs

@@ -1,4 +1,5 @@
 (ns frontend.util.property
 (ns frontend.util.property
+  "Property fns needed by the rest of the app and not graph-parser"
   (:require [clojure.string :as string]
   (:require [clojure.string :as string]
             [frontend.util :as util]
             [frontend.util :as util]
             [clojure.set :as set]
             [clojure.set :as set]
@@ -6,15 +7,11 @@
             [medley.core :as medley]
             [medley.core :as medley]
             [logseq.graph-parser.util :as gp-util]
             [logseq.graph-parser.util :as gp-util]
             [logseq.graph-parser.mldoc :as gp-mldoc]
             [logseq.graph-parser.mldoc :as gp-mldoc]
+            [logseq.graph-parser.property :as gp-property :refer [properties-start properties-end]]
             [frontend.format.mldoc :as mldoc]
             [frontend.format.mldoc :as mldoc]
             [logseq.graph-parser.text :as text]
             [logseq.graph-parser.text :as text]
             [frontend.util.cursor :as cursor]))
             [frontend.util.cursor :as cursor]))
 
 
-(defonce properties-start ":PROPERTIES:")
-(defonce properties-end ":END:")
-(defonce properties-end-pattern
-  (re-pattern (util/format "%s[\t\r ]*\n|(%s\\s*$)" properties-end properties-end)))
-
 (def built-in-extended-properties (atom #{}))
 (def built-in-extended-properties (atom #{}))
 (defn register-built-in-properties
 (defn register-built-in-properties
   [props]
   [props]
@@ -36,15 +33,9 @@
              built-in-properties-set (built-in-properties)]
              built-in-properties-set (built-in-properties)]
          (every? built-in-properties-set ks))))
          (every? built-in-properties-set ks))))
 
 
-(defn contains-properties?
-  [content]
-  (when content
-    (and (string/includes? content properties-start)
-         (gp-util/safe-re-find properties-end-pattern content))))
-
 (defn remove-empty-properties
 (defn remove-empty-properties
   [content]
   [content]
-  (if (contains-properties? content)
+  (if (gp-property/contains-properties? content)
     (string/replace content
     (string/replace content
                     (re-pattern ":PROPERTIES:\n+:END:\n*")
                     (re-pattern ":PROPERTIES:\n+:END:\n*")
                     "")
                     "")
@@ -114,7 +105,7 @@
 (defn get-property-keys
 (defn get-property-keys
   [format content]
   [format content]
   (cond
   (cond
-    (contains-properties? content)
+    (gp-property/contains-properties? content)
     (get-org-property-keys content)
     (get-org-property-keys content)
 
 
     (= :markdown format)
     (= :markdown format)
@@ -134,7 +125,7 @@
 (defn remove-properties
 (defn remove-properties
   [format content]
   [format content]
   (cond
   (cond
-    (contains-properties? content)
+    (gp-property/contains-properties? content)
     (let [lines (string/split-lines content)
     (let [lines (string/split-lines content)
           [title-lines properties&body] (split-with #(-> (string/triml %)
           [title-lines properties&body] (split-with #(-> (string/triml %)
                                                          string/upper-case
                                                          string/upper-case
@@ -348,7 +339,7 @@
      (let [format (or format :markdown)
      (let [format (or format :markdown)
            key (string/lower-case (name key))
            key (string/lower-case (name key))
            remove-f (if first? util/remove-first remove)]
            remove-f (if first? util/remove-first remove)]
-       (if (and (= format :org) (not (contains-properties? content)))
+       (if (and (= format :org) (not (gp-property/contains-properties? content)))
          content
          content
          (let [lines (->> (string/split-lines content)
          (let [lines (->> (string/split-lines content)
                           (remove-f (fn [line]
                           (remove-f (fn [line]
@@ -371,31 +362,6 @@
       (string/replace-first content (re-pattern ":PROPERTIES:\n:END:\n*") "")
       (string/replace-first content (re-pattern ":PROPERTIES:\n:END:\n*") "")
       content)))
       content)))
 
 
-(defn ->new-properties
-  "New syntax: key:: value"
-  [content]
-  (if (contains-properties? content)
-    (let [lines (string/split-lines content)
-          start-idx (.indexOf lines properties-start)
-          end-idx (.indexOf lines properties-end)]
-      (if (and (>= start-idx 0) (> end-idx 0) (> end-idx start-idx))
-        (let [before (subvec lines 0 start-idx)
-              middle (->> (subvec lines (inc start-idx) end-idx)
-                          (map (fn [text]
-                                 (let [[k v] (gp-util/split-first ":" (subs text 1))]
-                                   (if (and k v)
-                                     (let [k (string/replace k "_" "-")
-                                           compare-k (keyword (string/lower-case k))
-                                           k (if (contains? #{:id :custom_id :custom-id} compare-k) "id" k)
-                                           k (if (contains? #{:last-modified-at} compare-k) "updated-at" k)]
-                                       (str k ":: " (string/trim v)))
-                                     text)))))
-              after (subvec lines (inc end-idx))
-              lines (concat before middle after)]
-          (string/join "\n" lines))
-        content))
-    content))
-
 (defn add-page-properties
 (defn add-page-properties
   [page-format properties-content properties]
   [page-format properties-content properties]
   (let [properties (medley/map-keys name properties)
   (let [properties (medley/map-keys name properties)
@@ -435,10 +401,3 @@
     (util/format
     (util/format
      (config/properties-wrapper-pattern page-format)
      (config/properties-wrapper-pattern page-format)
      (string/join "\n" lines))))
      (string/join "\n" lines))))
-
-(defn properties-ast?
-  [block]
-  (and
-   (vector? block)
-   (contains? #{"Property_Drawer" "Properties"}
-              (first block))))

+ 3 - 3
src/main/frontend/util/thingatpt.cljs

@@ -1,10 +1,10 @@
 (ns frontend.util.thingatpt
 (ns frontend.util.thingatpt
   (:require [clojure.string :as string]
   (:require [clojure.string :as string]
             [frontend.state :as state]
             [frontend.state :as state]
-            [frontend.util.property :as property-util]
             [frontend.util.cursor :as cursor]
             [frontend.util.cursor :as cursor]
             [frontend.config :as config]
             [frontend.config :as config]
             [logseq.graph-parser.text :as text]
             [logseq.graph-parser.text :as text]
+            [logseq.graph-parser.property :as gp-property]
             [cljs.reader :as reader]
             [cljs.reader :as reader]
             [goog.object :as gobj]))
             [goog.object :as gobj]))
 
 
@@ -69,8 +69,8 @@
   (when-let [properties
   (when-let [properties
              (case (state/get-preferred-format) ;; TODO fix me to block's format
              (case (state/get-preferred-format) ;; TODO fix me to block's format
                :org (thing-at-point
                :org (thing-at-point
-                     [property-util/properties-start
-                      property-util/properties-end]
+                     [gp-property/properties-start
+                      gp-property/properties-end]
                      input)
                      input)
                (when-let [line (line-at-point input)]
                (when-let [line (line-at-point input)]
                  (when (re-matches #"^[^\s.]+:: .*$" (:raw-content line))
                  (when (re-matches #"^[^\s.]+:: .*$" (:raw-content line))

+ 35 - 35
src/main/logseq/graph_parser/block.cljs

@@ -5,16 +5,16 @@
             [frontend.config :as config]
             [frontend.config :as config]
             [frontend.date :as date]
             [frontend.date :as date]
             [frontend.db :as db]
             [frontend.db :as db]
+            [datascript.core :as d]
             [frontend.state :as state]
             [frontend.state :as state]
             [logseq.graph-parser.text :as text]
             [logseq.graph-parser.text :as text]
             [logseq.graph-parser.utf8 :as utf8]
             [logseq.graph-parser.utf8 :as utf8]
-            [frontend.util :as util]
-            [frontend.util.property :as property]
+            [logseq.graph-parser.property :as gp-property]
             [logseq.graph-parser.util :as gp-util]
             [logseq.graph-parser.util :as gp-util]
             [logseq.graph-parser.config :as gp-config]
             [logseq.graph-parser.config :as gp-config]
             [logseq.graph-parser.mldoc :as gp-mldoc]
             [logseq.graph-parser.mldoc :as gp-mldoc]
-            [lambdaisland.glogi :as log]
-            [medley.core :as medley]))
+            [logseq.graph-parser.date-time-util :as date-time-util]
+            [lambdaisland.glogi :as log]))
 
 
 (defn heading-block?
 (defn heading-block?
   [block]
   [block]
@@ -59,10 +59,10 @@
                   (and
                   (and
                    (= typ "Search")
                    (= typ "Search")
                    (not (contains? #{\# \* \/ \[} (first value)))
                    (not (contains? #{\# \* \/ \[} (first value)))
-                   (let [ext (some-> (util/get-file-ext value) keyword)]
-                     (when (and (not (util/starts-with? value "http:"))
-                                (not (util/starts-with? value "https:"))
-                                (not (util/starts-with? value "file:"))
+                   (let [ext (some-> (gp-util/get-file-ext value) keyword)]
+                     (when (and (not (string/starts-with? value "http:"))
+                                (not (string/starts-with? value "https:"))
+                                (not (string/starts-with? value "file:"))
                                 (not (gp-config/local-asset? value))
                                 (not (gp-config/local-asset? value))
                                 (or (= ext :excalidraw)
                                 (or (= ext :excalidraw)
                                     (not (contains? (config/supported-formats) ext))))
                                     (not (contains? (config/supported-formats) ext))))
@@ -97,7 +97,7 @@
                nil)]
                nil)]
     (text/block-ref-un-brackets! page)))
     (text/block-ref-un-brackets! page)))
 
 
-(defn get-block-reference
+(defn- get-block-reference
   [block]
   [block]
   (when-let [block-id (cond
   (when-let [block-id (cond
                         (and (vector? block)
                         (and (vector? block)
@@ -133,7 +133,7 @@
                (gp-util/uuid-string? block-id))
                (gp-util/uuid-string? block-id))
       block-id)))
       block-id)))
 
 
-(defn paragraph-block?
+(defn- paragraph-block?
   [block]
   [block]
   (and
   (and
    (vector? block)
    (vector? block)
@@ -197,7 +197,7 @@
        (or (timestamp-block? (first (second block)))
        (or (timestamp-block? (first (second block)))
            (timestamp-block? (second (second block))))))
            (timestamp-block? (second (second block))))))
 
 
-(defn extract-timestamps
+(defn- extract-timestamps
   [block]
   [block]
   (some->>
   (some->>
    (second block)
    (second block)
@@ -208,12 +208,12 @@
 ;; {"Deadline" {:date {:year 2020, :month 10, :day 20}, :wday "Tue", :time {:hour 8, :min 0}, :repetition [["DoublePlus"] ["Day"] 1], :active true}}
 ;; {"Deadline" {:date {:year 2020, :month 10, :day 20}, :wday "Tue", :time {:hour 8, :min 0}, :repetition [["DoublePlus"] ["Day"] 1], :active true}}
 (defn timestamps->scheduled-and-deadline
 (defn timestamps->scheduled-and-deadline
   [timestamps]
   [timestamps]
-  (let [timestamps (medley/map-keys (comp keyword string/lower-case) timestamps)
+  (let [timestamps (gp-util/map-keys (comp keyword string/lower-case) timestamps)
         m (some->> (select-keys timestamps [:scheduled :deadline])
         m (some->> (select-keys timestamps [:scheduled :deadline])
                    (map (fn [[k v]]
                    (map (fn [[k v]]
                           (let [{:keys [date repetition]} v
                           (let [{:keys [date repetition]} v
                                 {:keys [year month day]} date
                                 {:keys [year month day]} date
-                                day (js/parseInt (str year (util/zero-pad month) (util/zero-pad day)))]
+                                day (js/parseInt (str year (gp-util/zero-pad month) (gp-util/zero-pad day)))]
                             (cond->
                             (cond->
                              (case k
                              (case k
                                :scheduled
                                :scheduled
@@ -228,11 +228,11 @@
   "Convert journal file name to user' custom date format"
   "Convert journal file name to user' custom date format"
   [original-page-name]
   [original-page-name]
   (when original-page-name
   (when original-page-name
-    (let [page-name (util/page-name-sanity-lc original-page-name)
+    (let [page-name (gp-util/page-name-sanity-lc original-page-name)
           day (date/journal-title->int page-name)]
           day (date/journal-title->int page-name)]
      (if day
      (if day
        (let [original-page-name (date/int->journal-title day)]
        (let [original-page-name (date/int->journal-title day)]
-         [original-page-name (util/page-name-sanity-lc original-page-name) day])
+         [original-page-name (gp-util/page-name-sanity-lc original-page-name) day])
        [original-page-name page-name day]))))
        [original-page-name page-name day]))))
 
 
 (defn page-name->map
 (defn page-name->map
@@ -246,7 +246,7 @@
   ([original-page-name with-id? with-timestamp?]
   ([original-page-name with-id? with-timestamp?]
    (cond
    (cond
      (and original-page-name (string? original-page-name))
      (and original-page-name (string? original-page-name))
-     (let [original-page-name (util/remove-boundary-slashes original-page-name)
+     (let [original-page-name (gp-util/remove-boundary-slashes original-page-name)
            [original-page-name page-name journal-day] (convert-page-if-journal original-page-name)
            [original-page-name page-name journal-day] (convert-page-if-journal original-page-name)
            namespace? (and (not (boolean (text/get-nested-page-name original-page-name)))
            namespace? (and (not (boolean (text/get-nested-page-name original-page-name)))
                            (text/namespace-page? original-page-name))
                            (text/namespace-page? original-page-name))
@@ -258,13 +258,13 @@
         (when with-id?
         (when with-id?
           (if page-entity
           (if page-entity
             {:block/uuid (:block/uuid page-entity)}
             {:block/uuid (:block/uuid page-entity)}
-            {:block/uuid (db/new-block-id)}))
+            {:block/uuid (d/squuid)}))
         (when namespace?
         (when namespace?
           (let [namespace (first (gp-util/split-last "/" original-page-name))]
           (let [namespace (first (gp-util/split-last "/" original-page-name))]
             (when-not (string/blank? namespace)
             (when-not (string/blank? namespace)
-              {:block/namespace {:block/name (util/page-name-sanity-lc namespace)}})))
+              {:block/namespace {:block/name (gp-util/page-name-sanity-lc namespace)}})))
         (when (and with-timestamp? (not page-entity)) ;; Only assign timestamp on creating new entity
         (when (and with-timestamp? (not page-entity)) ;; Only assign timestamp on creating new entity
-          (let [current-ms (util/time-ms)]
+          (let [current-ms (date-time-util/time-ms)]
             {:block/created-at current-ms
             {:block/created-at current-ms
              :block/updated-at current-ms}))
              :block/updated-at current-ms}))
         (if journal-day
         (if journal-day
@@ -276,12 +276,12 @@
      original-page-name
      original-page-name
 
 
      (and (map? original-page-name) with-id?)
      (and (map? original-page-name) with-id?)
-     (assoc original-page-name :block/uuid (db/new-block-id))
+     (assoc original-page-name :block/uuid (d/squuid))
 
 
      :else
      :else
      nil)))
      nil)))
 
 
-(defn with-page-refs
+(defn- with-page-refs
   [{:keys [title body tags refs marker priority] :as block} with-id?]
   [{:keys [title body tags refs marker priority] :as block} with-id?]
   (let [refs (->> (concat tags refs [marker priority])
   (let [refs (->> (concat tags refs [marker priority])
                   (remove string/blank?)
                   (remove string/blank?)
@@ -309,7 +309,7 @@
                                           (when (string? p)
                                           (when (string? p)
                                             (let [p (or (text/get-nested-page-name p) p)]
                                             (let [p (or (text/get-nested-page-name p) p)]
                                               (when (text/namespace-page? p)
                                               (when (text/namespace-page? p)
-                                                (util/split-namespace-pages p))))))
+                                                (gp-util/split-namespace-pages p))))))
                                       refs)
                                       refs)
                               (remove string/blank?)
                               (remove string/blank?)
                               (distinct))
                               (distinct))
@@ -318,7 +318,7 @@
           refs (map (fn [ref] (page-name->map ref with-id?)) refs)]
           refs (map (fn [ref] (page-name->map ref with-id?)) refs)]
       (assoc block :refs refs))))
       (assoc block :refs refs))))
 
 
-(defn with-block-refs
+(defn- with-block-refs
   [{:keys [title body] :as block}]
   [{:keys [title body] :as block}]
   (let [ref-blocks (atom nil)]
   (let [ref-blocks (atom nil)]
     (walk/postwalk
     (walk/postwalk
@@ -331,14 +331,14 @@
                           (filter gp-util/uuid-string?))
                           (filter gp-util/uuid-string?))
           ref-blocks (map
           ref-blocks (map
                        (fn [id]
                        (fn [id]
-                         [:block/uuid (medley/uuid id)])
+                         [:block/uuid (uuid id)])
                        ref-blocks)
                        ref-blocks)
           refs (distinct (concat (:refs block) ref-blocks))]
           refs (distinct (concat (:refs block) ref-blocks))]
       (assoc block :refs refs))))
       (assoc block :refs refs))))
 
 
 (defn- block-keywordize
 (defn- block-keywordize
   [block]
   [block]
-  (medley/map-keys
+  (gp-util/map-keys
    (fn [k]
    (fn [k]
      (if (namespace k)
      (if (namespace k)
        k
        k
@@ -353,7 +353,7 @@
            block))
            block))
        blocks))
        blocks))
 
 
-(defn with-path-refs
+(defn- with-path-refs
   [blocks]
   [blocks]
   (loop [blocks blocks
   (loop [blocks blocks
          acc []
          acc []
@@ -391,7 +391,7 @@
                                 (remove string/blank?)
                                 (remove string/blank?)
                                 (map (fn [ref]
                                 (map (fn [ref]
                                        (if (string? ref)
                                        (if (string? ref)
-                                         {:block/name (util/page-name-sanity-lc ref)}
+                                         {:block/name (gp-util/page-name-sanity-lc ref)}
                                          ref)))
                                          ref)))
                                 (remove vector?)
                                 (remove vector?)
                                 (remove nil?)
                                 (remove nil?)
@@ -400,12 +400,12 @@
                (conj acc (assoc block :block/path-refs path-ref-pages))
                (conj acc (assoc block :block/path-refs path-ref-pages))
                parents)))))
                parents)))))
 
 
-(defn block-tags->pages
+(defn- block-tags->pages
   [{:keys [tags] :as block}]
   [{:keys [tags] :as block}]
   (if (seq tags)
   (if (seq tags)
     (assoc block :tags (map (fn [tag]
     (assoc block :tags (map (fn [tag]
                               (let [tag (text/page-ref-un-brackets! tag)]
                               (let [tag (text/page-ref-un-brackets! tag)]
-                                [:block/name (util/page-name-sanity-lc tag)])) tags))
+                                [:block/name (gp-util/page-name-sanity-lc tag)])) tags))
     block))
     block))
 
 
 (defn- get-block-content
 (defn- get-block-content
@@ -424,9 +424,9 @@
                       (gp-mldoc/remove-indentation-spaces content (inc (:level block)) false))))]
                       (gp-mldoc/remove-indentation-spaces content (inc (:level block)) false))))]
     (if (= format :org)
     (if (= format :org)
       content
       content
-      (property/->new-properties content))))
+      (gp-property/->new-properties content))))
 
 
-(defn get-custom-id-or-new-id
+(defn- get-custom-id-or-new-id
   [properties]
   [properties]
   (or (when-let [custom-id (or (get-in properties [:properties :custom-id])
   (or (when-let [custom-id (or (get-in properties [:properties :custom-id])
                                (get-in properties [:properties :custom_id])
                                (get-in properties [:properties :custom_id])
@@ -434,7 +434,7 @@
         (let [custom-id (and (string? custom-id) (string/trim custom-id))]
         (let [custom-id (and (string? custom-id) (string/trim custom-id))]
           (when (and custom-id (gp-util/uuid-string? custom-id))
           (when (and custom-id (gp-util/uuid-string? custom-id))
             (uuid custom-id))))
             (uuid custom-id))))
-      (db/new-block-id)))
+      (d/squuid)))
 
 
 (defn get-page-refs-from-properties
 (defn get-page-refs-from-properties
   [properties]
   [properties]
@@ -450,7 +450,7 @@
         page-refs (remove string/blank? page-refs)]
         page-refs (remove string/blank? page-refs)]
     (map (fn [page] (page-name->map page true)) page-refs)))
     (map (fn [page] (page-name->map page true)) page-refs)))
 
 
-(defn with-page-block-refs
+(defn- with-page-block-refs
   [block with-id?]
   [block with-id?]
   (some-> block
   (some-> block
           (with-page-refs with-id?)
           (with-page-refs with-id?)
@@ -458,7 +458,7 @@
           block-tags->pages
           block-tags->pages
           (update :refs (fn [col] (remove nil? col)))))
           (update :refs (fn [col] (remove nil? col)))))
 
 
-(defn with-pre-block-if-exists
+(defn- with-pre-block-if-exists
   [blocks body pre-block-properties encoded-content]
   [blocks body pre-block-properties encoded-content]
   (let [first-block (first blocks)
   (let [first-block (first blocks)
         first-block-start-pos (get-in first-block [:block/meta :start_pos])
         first-block-start-pos (get-in first-block [:block/meta :start_pos])
@@ -563,7 +563,7 @@
                         timestamps' (merge timestamps timestamps)]
                         timestamps' (merge timestamps timestamps)]
                     (recur headings (rest blocks) timestamps' properties body))
                     (recur headings (rest blocks) timestamps' properties body))
 
 
-                  (property/properties-ast? block)
+                  (gp-property/properties-ast? block)
                   (let [properties (extract-properties format (second block))]
                   (let [properties (extract-properties format (second block))]
                     (recur headings (rest blocks) timestamps properties body))
                     (recur headings (rest blocks) timestamps properties body))
 
 

+ 9 - 0
src/main/logseq/graph_parser/date_time_util.cljs

@@ -0,0 +1,9 @@
+(ns ^:nbb-compatible logseq.graph-parser.date-time-util
+  "cljs-time util fns for graph-parser"
+  (:require [cljs-time.coerce :as tc]
+            [cljs-time.core :as t]))
+
+(defn time-ms
+  "Copy of util/time-ms. Too basic to couple this to main app"
+  []
+  (tc/to-long (t/now)))

+ 48 - 0
src/main/logseq/graph_parser/property.cljs

@@ -0,0 +1,48 @@
+(ns logseq.graph-parser.property
+  "Property fns needed by graph-parser"
+  (:require [logseq.graph-parser.util :as gp-util]
+            [clojure.string :as string]
+            [goog.string :as gstring]))
+
+(defn properties-ast?
+  [block]
+  (and
+   (vector? block)
+   (contains? #{"Property_Drawer" "Properties"}
+              (first block))))
+
+(defonce properties-start ":PROPERTIES:")
+(defonce properties-end ":END:")
+(defonce properties-end-pattern
+  (re-pattern (gstring/format "%s[\t\r ]*\n|(%s\\s*$)" properties-end properties-end)))
+
+(defn contains-properties?
+  [content]
+  (when content
+    (and (string/includes? content properties-start)
+         (gp-util/safe-re-find properties-end-pattern content))))
+
+(defn ->new-properties
+  "New syntax: key:: value"
+  [content]
+  (if (contains-properties? content)
+    (let [lines (string/split-lines content)
+          start-idx (.indexOf lines properties-start)
+          end-idx (.indexOf lines properties-end)]
+      (if (and (>= start-idx 0) (> end-idx 0) (> end-idx start-idx))
+        (let [before (subvec lines 0 start-idx)
+              middle (->> (subvec lines (inc start-idx) end-idx)
+                          (map (fn [text]
+                                 (let [[k v] (gp-util/split-first ":" (subs text 1))]
+                                   (if (and k v)
+                                     (let [k (string/replace k "_" "-")
+                                           compare-k (keyword (string/lower-case k))
+                                           k (if (contains? #{:id :custom_id :custom-id} compare-k) "id" k)
+                                           k (if (contains? #{:last-modified-at} compare-k) "updated-at" k)]
+                                       (str k ":: " (string/trim v)))
+                                     text)))))
+              after (subvec lines (inc end-idx))
+              lines (concat before middle after)]
+          (string/join "\n" lines))
+        content))
+    content))

+ 63 - 2
src/main/logseq/graph_parser/util.cljs

@@ -66,14 +66,14 @@
   (and (string? v) (>= (count v) 2) (= "\"" (first v) (last v))))
   (and (string? v) (>= (count v) 2) (= "\"" (first v) (last v))))
 
 
 (defn parse-int
 (defn parse-int
-  "Copy of frontend.util/parse-int. Don't want to couple to main app too much"
+  "Copy of frontend.util/parse-int. Too basic to couple to main app"
   [x]
   [x]
   (if (string? x)
   (if (string? x)
     (js/parseInt x)
     (js/parseInt x)
     x))
     x))
 
 
 (defn safe-parse-int
 (defn safe-parse-int
-  "Copy of frontend.util/safe-parse-int. Don't want to couple to main app too much"
+  "Copy of frontend.util/safe-parse-int. Too basic to couple to main app"
   [x]
   [x]
   (let [result (parse-int x)]
   (let [result (parse-int x)]
     (if (js/isNaN result)
     (if (js/isNaN result)
@@ -94,3 +94,64 @@
   (-> json-string
   (-> json-string
       (js/JSON.parse)
       (js/JSON.parse)
       (js->clj :keywordize-keys true)))
       (js->clj :keywordize-keys true)))
+
+;; TODO: Use update-keys once its available in cljs and nbb
+(defn map-keys
+  "Maps function `f` over the keys of map `m` to produce a new map."
+  [f m]
+  (reduce-kv
+   (fn [m_ k v]
+     (assoc m_ (f k) v)) {} m))
+
+(defn zero-pad
+  "Copy of frontend.util/zero-pad. Too basic to couple to main app"
+  [n]
+  (if (< n 10)
+    (str "0" n)
+    (str n)))
+
+(defn get-file-ext
+  "Copy of frontend.util/get-file-ext. Too basic to couple to main app"
+  [file]
+  (and
+   (string? file)
+   (string/includes? file ".")
+   (some-> (last (string/split file #"\.")) string/lower-case)))
+
+(defn remove-boundary-slashes
+  [s]
+  (when (string? s)
+    (let [s (if (= \/ (first s))
+              (subs s 1)
+              s)]
+      (if (= \/ (last s))
+        (subs s 0 (dec (count s)))
+        s))))
+
+(defn split-namespace-pages
+  [title]
+  (let [parts (string/split title "/")]
+    (loop [others (rest parts)
+           result [(first parts)]]
+      (if (seq others)
+        (let [prev (last result)]
+          (recur (rest others)
+                 (conj result (str prev "/" (first others)))))
+        result))))
+
+(defn page-name-sanity
+  "Sanitize the page-name."
+  ([page-name]
+   (page-name-sanity page-name false))
+  ([page-name replace-slash?]
+   (let [page (some-> page-name
+                      (remove-boundary-slashes)
+                      (path-normalize))]
+     (if replace-slash?
+       (string/replace page #"/" "%2A")
+       page))))
+
+(defn page-name-sanity-lc
+  "Sanitize the query string for a page name (mandate for :block/name)"
+  [s]
+  (page-name-sanity (string/lower-case s)))

+ 1 - 1
src/test/frontend/test/docs_graph_helper.cljs

@@ -5,7 +5,7 @@
             [clojure.string :as string]))
             [clojure.string :as string]))
 
 
 
 
-(defn- slurp
+(defn slurp
   "Like clojure.core/slurp"
   "Like clojure.core/slurp"
   [file]
   [file]
   (str (fs/readFileSync file)))
   (str (fs/readFileSync file)))

+ 0 - 23
src/test/frontend/util/property_test.cljs

@@ -146,29 +146,6 @@ SCHEDULED: <2021-10-25 Mon>\n:PROPERTIES:\n:a: b\n:END:\nworld\n" "c" "d")
     (property/insert-properties :markdown "" {:foo "\"bar, baz\""})
     (property/insert-properties :markdown "" {:foo "\"bar, baz\""})
     "foo:: \"bar, baz\""))
     "foo:: \"bar, baz\""))
 
 
-(deftest test->new-properties
-  (are [x y] (= (property/->new-properties x) y)
-    ":PROPERTIES:\n:foo: bar\n:END:"
-    "foo:: bar"
-
-    "hello\n:PROPERTIES:\n:foo: bar\n:END:"
-    "hello\nfoo:: bar"
-
-    "hello\n:PROPERTIES:\n:foo: bar\n:nice: bingo\n:END:"
-    "hello\nfoo:: bar\nnice:: bingo"
-
-    "hello\n:PROPERTIES:\n:foo: bar\n:nice: bingo\n:END:"
-    "hello\nfoo:: bar\nnice:: bingo"
-
-    "hello\n:PROPERTIES:\n:foo: bar\n:nice: bingo\n:END:\nnice"
-    "hello\nfoo:: bar\nnice:: bingo\nnice"
-
-    "hello\n:PROPERTIES:\n:foo: bar\n:nice:\n:END:\nnice"
-    "hello\nfoo:: bar\nnice:: \nnice"
-
-    "hello\n:PROPERTIES:\n:foo: bar\n:nice\n:END:\nnice"
-    "hello\nfoo:: bar\n:nice\nnice"))
-
 (deftest test-build-properties-str
 (deftest test-build-properties-str
   (are [x y] (= (property/build-properties-str :mardown x) y)
   (are [x y] (= (property/build-properties-str :mardown x) y)
     {:title "a"}
     {:title "a"}

+ 4 - 3
src/test/logseq/graph_parser/nbb_test_runner.cljs

@@ -4,7 +4,8 @@
             [logseq.graph-parser.mldoc :as gp-mldoc]
             [logseq.graph-parser.mldoc :as gp-mldoc]
             [logseq.graph-parser.text :as text]
             [logseq.graph-parser.text :as text]
             [logseq.graph-parser.text-test]
             [logseq.graph-parser.text-test]
-            [logseq.graph-parser.mldoc-test]))
+            [logseq.graph-parser.mldoc-test]
+            [logseq.graph-parser.property-test]))
 
 
 (defmethod cljs.test/report [:cljs.test/default :end-run-tests] [m]
 (defmethod cljs.test/report [:cljs.test/default :end-run-tests] [m]
   (when-not (cljs.test/successful? m)
   (when-not (cljs.test/successful? m)
@@ -17,5 +18,5 @@
   #_:clj-kondo/ignore
   #_:clj-kondo/ignore
   (alter-var-root #'gp-mldoc/parse-property (constantly text/parse-property))
   (alter-var-root #'gp-mldoc/parse-property (constantly text/parse-property))
   (t/run-tests 'logseq.graph-parser.mldoc-test
   (t/run-tests 'logseq.graph-parser.mldoc-test
-               ;; TODO: Enable when https://github.com/babashka/nbb/issues/187 works
-               'logseq.graph-parser.text-test))
+               'logseq.graph-parser.text-test
+               'logseq.graph-parser.property-test))

+ 26 - 0
src/test/logseq/graph_parser/property_test.cljs

@@ -0,0 +1,26 @@
+(ns logseq.graph-parser.property-test
+  (:require [cljs.test :refer [are deftest]]
+            [logseq.graph-parser.property :as gp-property]))
+
+(deftest test->new-properties
+  (are [x y] (= (gp-property/->new-properties x) y)
+    ":PROPERTIES:\n:foo: bar\n:END:"
+    "foo:: bar"
+
+    "hello\n:PROPERTIES:\n:foo: bar\n:END:"
+    "hello\nfoo:: bar"
+
+    "hello\n:PROPERTIES:\n:foo: bar\n:nice: bingo\n:END:"
+    "hello\nfoo:: bar\nnice:: bingo"
+
+    "hello\n:PROPERTIES:\n:foo: bar\n:nice: bingo\n:END:"
+    "hello\nfoo:: bar\nnice:: bingo"
+
+    "hello\n:PROPERTIES:\n:foo: bar\n:nice: bingo\n:END:\nnice"
+    "hello\nfoo:: bar\nnice:: bingo\nnice"
+
+    "hello\n:PROPERTIES:\n:foo: bar\n:nice:\n:END:\nnice"
+    "hello\nfoo:: bar\nnice:: \nnice"
+
+    "hello\n:PROPERTIES:\n:foo: bar\n:nice\n:END:\nnice"
+    "hello\nfoo:: bar\n:nice\nnice"))