瀏覽代碼

handle pdf annotation properties

Tienson Qin 2 年之前
父節點
當前提交
db5e0a6571

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

@@ -47,7 +47,7 @@
   "Properties used by logseq that user can edit and that can have linkable property values"
   "Properties used by logseq that user can edit and that can have linkable property values"
   #{:alias :aliases :tags})
   #{:alias :aliases :tags})
 
 
-;; file based graphs only
+;; file based graphs only (or maybe not for backward compatibility with markdown tables)
 (def editable-view-and-table-properties
 (def editable-view-and-table-properties
   "Properties used by view and table component"
   "Properties used by view and table component"
   #{;; view props
   #{;; view props

+ 4 - 3
deps/publishing/src/logseq/publishing/db.cljs

@@ -3,7 +3,8 @@
   (:require [datascript.core :as d]
   (:require [datascript.core :as d]
             [logseq.db.rules :as rules]
             [logseq.db.rules :as rules]
             [clojure.set :as set]
             [clojure.set :as set]
-            [clojure.string :as string]))
+            [clojure.string :as string]
+            [frontend.handler.property.util :as pu]))
 
 
 (defn ^:api get-area-block-asset-url
 (defn ^:api get-area-block-asset-url
   "Returns asset url for an area block used by pdf assets. This lives in this ns
   "Returns asset url for an area block used by pdf assets. This lives in this ns
@@ -11,9 +12,9 @@
   [block page]
   [block page]
   (when-some [props (and block page (:block/properties block))]
   (when-some [props (and block page (:block/properties block))]
     (when-some [uuid (:block/uuid block)]
     (when-some [uuid (:block/uuid block)]
-      (when-some [stamp (:hl-stamp props)]
+      (when-some [stamp (pu/lookup props :hl-stamp)]
         (let [group-key      (string/replace-first (:block/original-name page) #"^hls__" "")
         (let [group-key      (string/replace-first (:block/original-name page) #"^hls__" "")
-              hl-page        (:hl-page props)
+              hl-page        (pu/lookup props :hl-page)
               encoded-chars? (boolean (re-find #"(?i)%[0-9a-f]{2}" group-key))
               encoded-chars? (boolean (re-find #"(?i)%[0-9a-f]{2}" group-key))
               group-key      (if encoded-chars? (js/encodeURI group-key) group-key)]
               group-key      (if encoded-chars? (js/encodeURI group-key) group-key)]
           (str "./assets/" group-key "/" (str hl-page "_" uuid "_" stamp ".png")))))))
           (str "./assets/" group-key "/" (str hl-page "_" uuid "_" stamp ".png")))))))

+ 13 - 9
src/main/frontend/extensions/pdf/assets.cljs

@@ -10,6 +10,7 @@
             [frontend.handler.page :as page-handler]
             [frontend.handler.page :as page-handler]
             [frontend.handler.assets :as assets-handler]
             [frontend.handler.assets :as assets-handler]
             [frontend.handler.notification :as notification]
             [frontend.handler.notification :as notification]
+            [frontend.handler.property.util :as pu]
             [frontend.ui :as ui]
             [frontend.ui :as ui]
             [frontend.context.i18n :refer [t]]
             [frontend.context.i18n :refer [t]]
             [frontend.extensions.lightbox :as lightbox]
             [frontend.extensions.lightbox :as lightbox]
@@ -191,18 +192,21 @@
            ref-block)
            ref-block)
          (let [text       (:text content)
          (let [text       (:text content)
                wrap-props #(if-let [stamp (:image content)]
                wrap-props #(if-let [stamp (:image content)]
-                             (assoc % :hl-type "area" :hl-stamp stamp) %)]
-
+                             (assoc % :hl-type "area" :hl-stamp stamp)
+                             %)
+               properties (->>
+                           (wrap-props
+                            {:ls-type  "annotation"
+                             :hl-page  page
+                             :hl-color (:color properties)
+                             ;; force custom uuid
+                             :id       (str id)})
+                           (property-handler/replace-key-with-id! (state/get-current-repo)))]
            (when (string? text)
            (when (string? text)
              (editor-handler/api-insert-new-block!
              (editor-handler/api-insert-new-block!
               text (merge {:page        (:block/name ref-page)
               text (merge {:page        (:block/name ref-page)
                            :custom-uuid id
                            :custom-uuid id
-                           :properties  (wrap-props
-                                         {:ls-type  "annotation"
-                                          :hl-page  page
-                                          :hl-color (:color properties)
-                                          ;; force custom uuid
-                                          :id       (str id)})}
+                           :properties properties}
                           insert-opts)))))))))
                           insert-opts)))))))))
 
 
 (defn del-ref-block!
 (defn del-ref-block!
@@ -225,7 +229,7 @@
         page      (db-utils/pull (:db/id (:block/page block)))
         page      (db-utils/pull (:db/id (:block/page block)))
         page-name (:block/original-name page)
         page-name (:block/original-name page)
         file-path (:file-path (:block/properties page))
         file-path (:file-path (:block/properties page))
-        hl-page   (:hl-page (:block/properties block))]
+        hl-page   (pu/get-property block :hl-page)]
     (when-let [target-key (and page-name (subs page-name 5))]
     (when-let [target-key (and page-name (subs page-name 5))]
       (p/let [hls (resolve-hls-data-by-key$ target-key)
       (p/let [hls (resolve-hls-data-by-key$ target-key)
               hls (and hls (:highlights hls))]
               hls (and hls (:highlights hls))]

+ 26 - 8
src/main/frontend/handler/db_based/property.cljs

@@ -108,18 +108,20 @@
       :url
       :url
       v-str)))
       v-str)))
 
 
-(defn- upsert-property!
-  [repo property k-name property-uuid property-type]
-  (let [k-name (name k-name)]
+(defn upsert-property!
+  [repo k-name schema {:keys [property-uuid]}]
+  (let [property (db/entity [:block/name (gp-util/page-name-sanity-lc k-name)])
+        k-name (name k-name)
+        property-uuid (or (:block/uuid property) property-uuid (random-uuid))]
     (when (and property (nil? (:block/type property)))
     (when (and property (nil? (:block/type property)))
       (db/transact! repo [(outliner-core/block-with-updated-at
       (db/transact! repo [(outliner-core/block-with-updated-at
-                           {:block/schema {:type property-type}
+                           {:block/schema schema
                             :block/uuid property-uuid
                             :block/uuid property-uuid
                             :block/type "property"})]
                             :block/type "property"})]
         {:outliner-op :update-property}))
         {:outliner-op :update-property}))
     (when (nil? property) ;if property not exists yet
     (when (nil? property) ;if property not exists yet
       (db/transact! repo [(outliner-core/block-with-timestamps
       (db/transact! repo [(outliner-core/block-with-timestamps
-                           {:block/schema {:type property-type}
+                           {:block/schema schema
                             :block/original-name k-name
                             :block/original-name k-name
                             :block/name (util/page-name-sanity-lc k-name)
                             :block/name (util/page-name-sanity-lc k-name)
                             :block/uuid property-uuid
                             :block/uuid property-uuid
@@ -151,7 +153,8 @@
             (let [msg' (str "\"" k-name "\"" " " (if (coll? msg) (first msg) msg))]
             (let [msg' (str "\"" k-name "\"" " " (if (coll? msg) (first msg) msg))]
               (notification/show! msg' :warning))
               (notification/show! msg' :warning))
             (do
             (do
-              (upsert-property! repo property k-name property-uuid property-type)
+              (upsert-property! repo k-name {:type property-type}
+                                {:property-uuid property-uuid})
               (let [new-value (cond
               (let [new-value (cond
                                 (and multiple-values? old-value
                                 (and multiple-values? old-value
                                      (not= old-value :frontend.components.property/new-value-placeholder))
                                      (not= old-value :frontend.components.property/new-value-placeholder))
@@ -240,7 +243,8 @@
           property-uuid (or (:block/uuid property) (random-uuid))
           property-uuid (or (:block/uuid property) (random-uuid))
           property-type (get-in property [:block/schema :type] :default)
           property-type (get-in property [:block/schema :type] :default)
           {:keys [properties] :as class-schema} (:block/schema class)
           {:keys [properties] :as class-schema} (:block/schema class)
-          _ (upsert-property! repo property k-name property-uuid property-type)
+          _ (upsert-property! repo k-name {:type property-type}
+                              {:property-uuid property-uuid})
           new-properties (vec (distinct (conj properties property-uuid)))
           new-properties (vec (distinct (conj properties property-uuid)))
           class-new-schema (assoc class-schema :properties new-properties)]
           class-new-schema (assoc class-schema :properties new-properties)]
       (db/transact! repo
       (db/transact! repo
@@ -270,7 +274,8 @@
         infer-schema (when-not type (infer-schema-from-input-string v))
         infer-schema (when-not type (infer-schema-from-input-string v))
         property-type (or type infer-schema :default)
         property-type (or type infer-schema :default)
         _ (when (nil? property)
         _ (when (nil? property)
-            (upsert-property! repo property k-name property-uuid property-type))
+            (upsert-property! repo k-name {:type property-type}
+                              {:property-uuid property-uuid}))
         {:keys [type cardinality]} (:block/schema property)
         {:keys [type cardinality]} (:block/schema property)
         property (db/entity repo [:block/name (gp-util/page-name-sanity-lc k-name)])
         property (db/entity repo [:block/name (gp-util/page-name-sanity-lc k-name)])
         txs (mapcat
         txs (mapcat
@@ -317,3 +322,16 @@
 (defn remove-block-property!
 (defn remove-block-property!
   [repo block-id key]
   [repo block-id key]
   (batch-remove-property! repo [block-id] key))
   (batch-remove-property! repo [block-id] key))
+
+(defn replace-key-with-id!
+  "Notice: properties need to be created first"
+  [m]
+  (zipmap
+   (map (fn [k]
+          (let [property-id (:block/uuid (db/entity [:block/name (util/page-name-sanity-lc (name k))]))]
+            (when-not property-id
+              (throw (ex-info "Property not exists yet"
+                              {:key k})))
+            property-id))
+     (keys m))
+   (vals m)))

+ 6 - 0
src/main/frontend/handler/property.cljs

@@ -84,3 +84,9 @@
   [repo col]
   [repo col]
   (when-not (config/db-based-graph? repo)
   (when-not (config/db-based-graph? repo)
     (file-property/batch-set-block-property-aux! col)))
     (file-property/batch-set-block-property-aux! col)))
+
+(defn replace-key-with-id!
+  [repo m]
+  (if (config/db-based-graph? repo)
+    (db-property/replace-key-with-id! m)
+    m))