Browse Source

Add :block/properties-text-values

Tienson Qin 3 years ago
parent
commit
1fbb364512

+ 4 - 0
deps/db/src/logseq/db/schema.cljs

@@ -55,6 +55,8 @@
    :block/properties {}
    ;; vector
    :block/properties-order {}
+   ;; map, key -> original property value's content
+   :block/properties-text-values {}
 
    ;; first block that's not a heading or unordered list
    :block/pre-block? {}
@@ -117,6 +119,7 @@
     :block/type
     :block/properties
     :block/properties-order
+    :block/properties-text-values
     :block/invalid-properties
     :block/created-at
     :block/updated-at
@@ -135,6 +138,7 @@
     :block/content
     :block/properties
     :block/properties-order
+    :block/properties-text-values
     :block/invalid-properties
     :block/alias
     :block/tags})

+ 9 - 6
deps/graph-parser/src/logseq/graph_parser/block.cljs

@@ -201,15 +201,18 @@
                                                  "id"
                                                  k))
                                            v' (text/parse-property k v mldoc-ast user-config)]
-                                       [k' v' mldoc-ast])
+                                       [k' v' mldoc-ast v])
                                      (do (swap! *invalid-properties conj k)
                                          nil)))))
                           (remove #(nil? (second %))))
           page-refs (get-page-ref-names-from-properties properties user-config)
+          properties-text-values (->> (map (fn [[k _v _refs original-text]] [k original-text]) properties)
+                                      (into {}))
           properties (map (fn [[k v _]] [k v]) properties)
           properties' (into {} properties)]
       {:properties properties'
        :properties-order (map first properties)
+       :properties-text-values properties-text-values
        :invalid-properties @*invalid-properties
        :page-refs page-refs})))
 
@@ -506,7 +509,7 @@
                  (cons
                   (merge
                    (let [content (utf8/substring encoded-content 0 first-block-start-pos)
-                         {:keys [properties properties-order invalid-properties]} pre-block-properties
+                         {:keys [properties properties-order properties-text-values invalid-properties]} pre-block-properties
                          id (get-custom-id-or-new-id {:properties properties})
                          property-refs (->> (get-page-refs-from-properties
                                              properties db date-formatter
@@ -521,6 +524,7 @@
                                 :level 1
                                 :properties properties
                                 :properties-order (vec properties-order)
+                                :properties-text-values properties-text-values
                                 :invalid-properties invalid-properties
                                 :refs property-refs
                                 :pre-block? true
@@ -555,10 +559,9 @@
                        :format format
                        :meta pos-meta)
                 (seq (:properties properties))
-                (assoc :properties (:properties properties))
-
-                (seq (:properties-order properties))
-                (assoc :properties-order (vec (:properties-order properties)))
+                (assoc :properties (:properties properties)
+                       :properties-text-values (:properties-text-values properties)
+                       :properties-order (vec (:properties-order properties)))
 
                 (seq (:invalid-properties properties))
                 (assoc :invalid-properties (:invalid-properties properties)))

+ 0 - 6
deps/graph-parser/src/logseq/graph_parser/property.cljs

@@ -15,12 +15,6 @@
        (map #(str (name (key %)) (str colons " ") (val %)))
        (string/join "\n")))
 
-(defn property-value-from-content
-  "Extracts full property value from block content"
-  [property content]
-  (second (re-find (re-pattern (str property colons "\\s+(.*)"))
-                   content)))
-
 (def valid-property-name? gp-util/valid-edn-keyword?)
 
 (defn properties-ast?

+ 6 - 13
deps/graph-parser/src/logseq/graph_parser/text.cljs

@@ -127,11 +127,11 @@
 
 (defn sep-by-comma
   [s]
-  (when s
-    (some->>
-     (string/split s #",")
-     (remove string/blank?)
-     (map string/trim))))
+  {:pre (string? s)}
+  (->>
+   (string/split s #",")
+   (remove string/blank?)
+   (map string/trim)))
 
 (defn separated-by-commas?
   [config-state k]
@@ -147,10 +147,7 @@
         property-separated-by-commas? (and (separated-by-commas? config-state k)
                                            (empty? refs))
         refs' (if property-separated-by-commas?
-                (set
-                 (if (string/includes? v ",")
-                   (distinct (sep-by-comma v))
-                   [(string/trim v)]))
+                (sep-by-comma v)
                 refs)
         k (if (or (symbol? k) (keyword? k)) (subs (str k) 1) k)
         v (subs (str v) 1)
@@ -177,9 +174,5 @@
       (some? non-string-property)
       non-string-property
 
-      (and (= k "file-path")
-           (string/starts-with? v "file:"))
-      v
-
       :else
       v)))

+ 0 - 13
deps/graph-parser/test/logseq/graph_parser/property_test.cljs

@@ -24,16 +24,3 @@
 
     "hello\n:PROPERTIES:\n:foo: bar\n:nice\n:END:\nnice"
     "hello\nfoo:: bar\n:nice\nnice"))
-
-(deftest property-value-from-content
-  (is (= "62b38254-4be7-4627-a2b7-6d9ee20999e5"
-         (gp-property/property-value-from-content
-          "id"
-          "type:: blog-posting\ndesc:: nice walkthrough on creating a blog with #nbb\nid:: 62b38254-4be7-4627-a2b7-6d9ee20999e5"))
-      "Pulls value from end of block content")
-
-  (is (= "nice walkthrough on creating a blog with #nbb"
-         (gp-property/property-value-from-content
-          "desc"
-          "type:: blog-posting\ndesc:: nice walkthrough on creating a blog with #nbb\nid:: 62b38254-4be7-4627-a2b7-6d9ee20999e5"))
-      "Pulls value from middle of block content"))

+ 5 - 4
src/main/frontend/components/block.cljs

@@ -1915,10 +1915,11 @@
         ;; When value is a set of refs, display full property text
         ;; because :block/properties value only contains refs but user wants to see text
         property-separated-by-commas? (text/separated-by-commas? (state/get-config) k)
-        v (if (and (coll? value) (seq value)
-                   (not property-separated-by-commas?))
-            (gp-property/property-value-from-content (name k) (:block/content block))
-            value)
+        v (or
+           (when (and (coll? value) (seq value)
+                      (not property-separated-by-commas?))
+             (get (:block/properties-text-values block) k))
+           value)
         property-pages-enabled? (contains? #{true nil} (:property-pages/enabled? user-config))]
     [:div
      (if property-pages-enabled?

+ 1 - 0
src/main/frontend/modules/outliner/core.cljs

@@ -212,6 +212,7 @@
                       (let [id (:db/id (:block/page block))]
                         [[:db/retract id :block/properties]
                          [:db/retract id :block/properties-order]
+                         [:db/retract id :block/properties-text-values]
                          [:db/retract id :block/alias]
                          [:db/retract id :block/tags]])))]
       (swap! txs-state concat txs page-tx)