Przeglądaj źródła

improve(pdf): open pdf viewer when click local pdf asset link

charlie 4 lat temu
rodzic
commit
922d5a5bce

+ 16 - 6
src/main/frontend/components/block.cljs

@@ -22,6 +22,7 @@
             [frontend.extensions.highlight :as highlight]
             [frontend.extensions.latex :as latex]
             [frontend.extensions.sci :as sci]
+            [frontend.extensions.pdf.assets :as pdf-assets]
             [frontend.format.block :as block]
             [frontend.format.mldoc :as mldoc]
             [frontend.handler.block :as block-handler]
@@ -455,14 +456,23 @@
   (let [repo-path (config/get-repo-dir (state/get-current-repo))
         full-path (.. util/node-path (join repo-path (config/get-local-asset-absolute-path path)))]
     [:div
-     [:a.asset-ref {:target "_blank" :href full-path} (or title path)]
+     (if (and (= "pdf" (util/get-file-ext full-path))
+              (string/ends-with? (util/node-path.dirname full-path) config/local-assets-dir))
+       [:a.asset-ref.is-pdf
+        {:href "javascript:;"
+         :on-click (fn [e]
+                     (when-let [current (pdf-assets/inflate-asset (util/node-path.basename full-path))]
+                       (state/set-state! :pdf/current current)
+                       (.preventDefault e)))}
+        (or title path)]
+       [:a.asset-ref {:target "_blank" :href full-path} (or title path)])
 
      (case (util/get-file-ext full-path)
-       "pdf"
-       [:iframe {:src full-path
-                 :class "pdf-preview"
-                 :fullscreen true
-                 :height 800}]
+       ;;"pdf"
+       ;;[:iframe {:src full-path
+       ;;          :class "pdf-preview"
+       ;;          :fullscreen true
+       ;;          :height 800}]
        ;; https://en.wikipedia.org/wiki/HTML5_video
        ("mp4" "ogg" "webm")
        [:video {:src full-path

+ 0 - 4
src/main/frontend/components/page.cljs

@@ -399,10 +399,6 @@
                                     "origin-top-right.absolute.right-0.top-10.mt-2.rounded-md.shadow-lg.whitespace-nowrap.dropdown-overflow-auto.page-drop-options")
                       :z-index     1})]))])
 
-            ;; related assets upload
-            (when (and (config/local-db? repo) (not block?))
-              (pdf-assets/uploader page-name))
-
             [:div
              (when (and block? (not sidebar?))
                (let [config {:id "block-parent"

+ 1 - 1
src/main/frontend/extensions/pdf/highlights.cljs

@@ -444,7 +444,7 @@
                        #(set-state! {:viewer viewer :bus event-bus :link link-service :el el})))
 
         ;;TODO: destroy
-        #())
+        #(.destroy pdf-document))
       [])
 
     ;; interaction events

+ 14 - 0
src/main/frontend/extensions/pdf/pdf.css

@@ -305,6 +305,20 @@
   }
 }
 
+.asset-ref {
+  &.is-pdf {
+    &:before {
+      content: "[[📙";
+      opacity: .4;
+    }
+
+    &:after {
+      content: "]]";
+      opacity: .4;
+    }
+  }
+}
+
 body[data-page] {
   #main-content-container {
     margin: 0 !important;