Browse Source

Merge branch 'master' into feat/pdf

# Conflicts:
#	src/main/frontend/components/block.cljs
charlie 4 years ago
parent
commit
08bd253bb1

+ 1 - 1
resources/css/common.css

@@ -924,7 +924,7 @@ a.chosen {
 }
 
 a.warning,
-span.warning {
+span.warning, div.warning:not(.admonitionblock), p.warning {
   background: #f56565;
   padding: 0.1em 0.4em;
   border-radius: var(--ls-border-radius-low);

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

@@ -591,11 +591,13 @@
           repo (state/get-current-repo)]
       (if block
         [:div.block-ref-wrap.inline
+
          {:data-type (name (or block-type :default))
           :data-hl-type hl-type
           :on-mouse-down
           (fn [e]
             (util/stop e)
+
             (if (gobj/get e "shiftKey")
                 (state/sidebar-add-block!
                   (state/get-current-repo)
@@ -609,12 +611,15 @@
 
                   ;; default open block page
                   :else (route-handler/redirect! {:to          :page
-                                              :path-params {:name id}}))))}
-         (let [title (let [title (:block/title block)]
-                       [:span.block-ref
-                        (block-content (assoc config :block-ref? true)
-                                       block nil (:block/uuid block)
-                                       (:slide? config))])
+                                                  :path-params {:name id}}))))}
+
+         (let [title (let [title (:block/title block)
+                           block-content (block-content (assoc config :block-ref? true)
+                                                        block nil (:block/uuid block)
+                                                        (:slide? config))
+                           class (if (seq title) "block-ref" "block-ref-no-title")]
+                       [:span {:class class}
+                        block-content])
                inner (if label
                        (->elem
                         :span.block-ref

+ 7 - 2
src/main/frontend/components/block.css

@@ -152,11 +152,16 @@
   }
 }
 
+.block-ref-no-title {
+    cursor: alias;
+}
+
 .block-ref {
-  padding-bottom: 2px;
   border-bottom: 0.5px solid;
   border-bottom-color: var(--ls-block-ref-link-text-color);
   cursor: alias;
+  padding: 2px 5px;
+  display: inline;
 
   &:hover {
     color: var(--ls-link-text-hover-color);
@@ -486,4 +491,4 @@ span.cloze-revealed {
 
 .page-property-key {
   color: var(--ls-secondary-text-color);
-}
+}

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

@@ -149,5 +149,5 @@
 
      (ui/button (if @copied? "Copied to clipboard!" "Copy to clipboard")
                 :on-click (fn []
-                            (util/copy-to-clipboard! content)
+                            (util/copy-to-clipboard! content (= type :html))
                             (reset! copied? true)))]))

+ 9 - 7
src/main/frontend/components/page.cljs

@@ -63,13 +63,15 @@
 
 (defn- open-first-block!
   [state]
-  (let [blocks (nth (:rum/args state) 1)
-        block (first blocks)
-        preview? (nth (:rum/args state) 4)]
-    (when (and (= (count blocks) 1)
-               (string/blank? (:block/content block))
-               (not preview?))
-      (editor-handler/edit-block! block :max (:block/format block) (:block/uuid block))))
+  (let [[_ blocks _ sidebar? preview?](:rum/args state)]
+    (when (or sidebar?
+              preview?
+              (not (contains? #{:home :all-journals} (state/get-current-route))))
+      (let [block (first blocks)]
+        (when (and (= (count blocks) 1)
+                   (string/blank? (:block/content block))
+                   (not preview?))
+          (editor-handler/edit-block! block :max (:block/format block) (:block/uuid block))))))
   state)
 
 (rum/defc page-blocks-inner <

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

@@ -214,7 +214,7 @@
                                  (last
                                   (string/split repo-name #"/"))
                                  repo-name)]
-                 [:span#repo-name repo-name])
+                 [:span#repo-name {:title repo-name} repo-name])
                [:span.dropdown-caret.ml-1 {:style {:border-top-color "#6b7280"}}]]])
            (mapv
             (fn [{:keys [id url]}]

+ 4 - 0
src/main/frontend/config.cljs

@@ -385,3 +385,7 @@
    (when repo
      (get-file-path repo
                     (str app-name "/" custom-css-file)))))
+
+(defn get-block-hidden-properties
+  []
+  (get-in @state/state [:config (state/get-current-repo) :block-hidden-properties]))

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

@@ -352,6 +352,7 @@
       (when-let [file (:block/file page)]
         (when-let [path (:file/path (db-utils/entity (:db/id file)))]
           (format/get-format path)))))
+   (state/get-preferred-format)
    :markdown))
 
 (defn page-alias-set

+ 27 - 0
src/main/frontend/extensions/zotero.cljs

@@ -175,6 +175,17 @@
         "https://www.zotero.org/settings/keys"]
        " page, it's a number of digits"]))
 
+   [:div.row
+    [:label.title
+     {:for "zotero_prefer_citekey"
+      :title "Make sure to install Better BibTeX and pin your item first"}
+     "Always prefer citekey as your page title?"]
+    [:div
+     [:div.rounded-md.sm:max-w-xs
+      (ui/toggle (setting/setting :prefer-citekey?)
+                 (fn [] (setting/set-setting! :prefer-citekey? (not (setting/setting :prefer-citekey?))))
+                 true)]]]
+
    [:div.row
     [:label.title
      {:for "zotero_include_attachment_links"}
@@ -228,6 +239,18 @@
        {:default-value (setting/setting :page-insert-prefix)
         :on-blur       (fn [e] (setting/set-setting! :page-insert-prefix (util/evalue e)))}]]]]
 
+   [:div.row
+    [:label.title
+     {:for "zotero_extra_tags"
+      :title "Extra tags to add for every imported page. Separate by comma, or leave it empty."}
+     "Extra tags to add:"]
+    [:div.mt-1.sm:mt-0.sm:col-span-2
+     [:div.max-w-lg.rounded-md
+      [:input.form-input.block
+       {:default-value (setting/setting :extra-tags)
+        :placeholder   "tag1,tag2,tag3"
+        :on-blur       (fn [e] (setting/set-setting! :extra-tags (util/evalue e)))}]]]]
+
    [:div.row
     [:label.title
      {:for "zotero_import_all"}
@@ -250,6 +273,10 @@
                 (reset! (::total state) false)
                 (notification/show! "Successfully added all items!" :success)))))))]]
 
+   (ui/admonition
+    :warning
+    "If you have a lot of items in Zotero, adding them all can slow down Logseq. You can type /zotero to import specific item on demand instead.")
+
    (when @(::total state)
      [:div.row
       [:div.bg-greenred-200.py-3.rounded-lg.col-span-full

+ 11 - 8
src/main/frontend/extensions/zotero/extractor.cljs

@@ -29,10 +29,6 @@
 (defn page-name [item]
   (let [page-title
         (case (item-type item)
-          "journalArticle"
-          (let [citation-key (citation-key item)
-                title        (title item)]
-            (or citation-key title))
           "case"
           (-> item :data :case-name)
           "email"
@@ -40,8 +36,12 @@
           "statute"
           (-> item :data :name-of-act)
           ;; default use title
-          (title item))]
-    (str (setting/setting :page-insert-prefix) page-title)))
+          (title item))
+        citekey (citation-key item)]
+    (if (and (setting/setting :prefer-citekey?)
+             (not (str/blank? citekey)))
+      (str (setting/setting :page-insert-prefix) citekey)
+      (str (setting/setting :page-insert-prefix) page-title))))
 
 (defn authors [item]
   (let [creators (-> item :data :creators)
@@ -58,8 +58,11 @@
   (let [tags
         (->> (-> item :data :tags)
              (mapv (fn [{:keys [tag]}] (string/trim tag)))
-             (mapcat #(string/split % #",\s?")))]
-    (distinct tags)))
+             (mapcat #(string/split % #",\s?")))
+        extra-tags (->> (str/split (setting/setting :extra-tags) #",")
+                        (map str/trim)
+                        (remove str/blank?))]
+    (distinct (concat tags extra-tags))))
 
 (defn date->journal [item]
   (if-let [date (-> item :meta :parsed-date

+ 2 - 0
src/main/frontend/extensions/zotero/setting.cljs

@@ -6,10 +6,12 @@
 
 (def default-settings
   {:type                   :user
+   :prefer-citekey?        true
    :include-attachments?   true
    :attachments-block-text "[[Attachments]]"
    :include-notes?         true
    :notes-block-text       "[[Notes]]"
+   :extra-tags             ""
    :page-insert-prefix     "@"})
 
 (defn api-key []

+ 6 - 3
src/main/frontend/format/block.cljs

@@ -197,14 +197,17 @@
     (let [properties (seq properties)
           properties-order (keys properties)
           page-refs (->>
+                     properties
+                     (remove (fn [[k _]]
+                               (contains? #{:background-color :background_color} (keyword k))))
+                     (map last)
                      (map (fn [v]
                             (when (string? v)
                               (let [v (string/trim v)
                                     result (text/split-page-refs-without-brackets v {:un-brackets? false})]
                                 (if (coll? result)
                                   (map text/page-ref-un-brackets! result)
-                                  []))))
-                       (map last properties))
+                                  [])))))
                      (apply concat)
                      (remove string/blank?))
           properties (->> properties
@@ -623,7 +626,7 @@
 (defn with-parent-and-left
   [page-id blocks]
   (loop [blocks (map (fn [block] (assoc block :block/level-spaces (:block/level block))) blocks)
-         parents [{:page/id page-id     ; db id or lookup ref [:block/name "xxx"]
+         parents [{:page/id page-id     ; db id or a map {:block/name "xxx"}
                    :block/level 0
                    :block/level-spaces 0}]
          sibling nil

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

@@ -652,7 +652,7 @@
               format (or
                       (:block/format block)
                       (db/get-page-format (:db/id block))
-                      :markdown)
+                      (state/get-preferred-format))
               content (if (seq properties)
                         (property/insert-properties format content properties)
                         content)
@@ -743,7 +743,7 @@
       (when (db/page-empty? (state/get-current-repo) (:db/id page))
         (let [title (or (:block/original-name page)
                         (:block/name page))
-              format (get page :block/format :markdown)
+              format (db/get-page-format page)
               create-title-property? (util/create-title-property? title)]
           (when create-title-property?
             (let [default-properties (default-properties-block title format (:db/id page))

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

@@ -60,7 +60,7 @@
           page (get-page-name file ast)
           [page page-name journal-day] (block/convert-page-if-journal page)
           blocks (->> (block/extract-blocks ast content false format)
-                      (block/with-parent-and-left [:block/name (string/lower-case page)]))
+                      (block/with-parent-and-left {:block/name (string/lower-case page)}))
           ref-pages (atom #{})
           ref-tags (atom #{})
           blocks (map (fn [block]

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

@@ -771,16 +771,11 @@
 #?(:cljs (def clear-selection! selection/clearSelection))
 
 #?(:cljs
-   (defn copy-to-clipboard! [s]
-     (let [el (js/document.createElement "textarea")]
-       (set! (.-value el) s)
-       (.setAttribute el "readonly" "")
-       (set! (-> el .-style .-position) "absolute")
-       (set! (-> el .-style .-left) "-9999px")
-       (js/document.body.appendChild el)
-       (.select el)
-       (js/document.execCommand "copy")
-       (js/document.body.removeChild el))))
+   (defn copy-to-clipboard!
+     ([s]
+      (utils/writeClipboard s false))
+     ([s html?]
+      (utils/writeClipboard s html?))))
 
 (def uuid-pattern "[0-9a-f]{8}-[0-9a-f]{4}-[0-5][0-9a-f]{3}-[089ab][0-9a-f]{3}-[0-9a-f]{12}")
 (defonce exactly-uuid-pattern (re-pattern (str "(?i)^" uuid-pattern "$")))

+ 1 - 0
src/main/frontend/util/property.cljs

@@ -22,6 +22,7 @@
   (set/union
    #{:id :custom-id :background-color :heading :collapsed :created-at :updated-at :last-modified-at :created_at :last_modified_at :query-table :query-properties :query-sort-by :query-sort-desc}
    (set (map keyword config/markers))
+   (set (config/get-block-hidden-properties))
    @built-in-extended-properties))
 
 (defn properties-built-in?

+ 19 - 0
src/main/frontend/utils.js

@@ -231,3 +231,22 @@ export const getClipText = function (cb, errorHandler) {
     }
   })
 }
+
+export const writeClipboard = function(text, isHtml) {
+    if (isHtml) {
+	var blob = new Blob([text], {type:["text/plain", "text/html"]})
+	var data = [new ClipboardItem({["text/plain"]: blob, ["text/html"]:blob})];
+    } else{
+	var blob = new Blob([text], {type:["text/plain"]})
+	var data = [new ClipboardItem({["text/plain"]: blob})];
+    }
+    navigator.permissions.query({ name: "clipboard-write" }).then((result) => {
+	if (result.state == "granted" || result.state == "prompt") {
+	    navigator.clipboard.write(data).then(function() {
+		/* success */
+	    }, function(e) {
+		console.log(e, "fail")
+	    })
+	}
+    })
+}

+ 4 - 0
templates/config.edn

@@ -165,4 +165,8 @@
 
  ;; the initial interval after the first successful review of a card (default 4)
  ;; :srs/initial-interval 4
+
+ ;; hide specific properties for blocks
+ ;; E.g. #{:created-at :updated-at}
+ ;; :block-hidden-properties #{}
  }

+ 1 - 1
templates/tutorial-en.md

@@ -1,7 +1,7 @@
 ## Hi, welcome to Logseq!
 - Logseq is a _privacy-first_, _open-source_ platform for _knowledge_ management and collaboration.
 - This is a 3 minute tutorial on how to use Logseq. Let's get started!
-- (Feel free to edit anything, no change will be saved at this moment. If you do want to persist your work, click the **top-right** corner of the screen to connect Logseq to either Github or local directory.)
+- [:div.warning "(Feel free to edit anything, no change will be saved at this moment. If you do want to persist your work, click the **top-right** corner of the screen to either open a local directory or connect Logseq to Github.)"]
 - Here are some tips might be useful.
 #+BEGIN_TIP
 Click to edit any block.