Просмотр исходного кода

Merge branch 'master' into feat/chrome-native-fs

Tienson Qin 5 лет назад
Родитель
Сommit
37f0f11a34

+ 7 - 0
resources/css/common.css

@@ -1455,3 +1455,10 @@ a.tag:hover {
 .hide-scrollbar::-webkit-scrollbar {
     display: none;
 }
+
+.left {
+    float: left;
+}
+.right {
+    float: right;
+}

+ 38 - 23
src/main/frontend/components/block.cljs

@@ -382,6 +382,28 @@
         [:span.warning.mr-1 {:title "Block ref invalid"}
          (util/format "((%s))" id)]))))
 
+(defn inline-text
+  [format v]
+  (when (string? v)
+    (let [inline-list (mldoc/inline->edn v (mldoc/default-config format))]
+      [:div.inline.mr-1 (map-inline {} inline-list)])))
+
+(defn- render-macro
+  [config name arguments macro-content format]
+  (if macro-content
+    (let [ast (->> (mldoc/->edn macro-content (mldoc/default-config format))
+                   (map first))
+          block? (contains? #{"Paragraph"
+                              "Raw_Html"
+                              "Hiccup"}
+                            (ffirst ast))]
+      (if block?
+        [:div
+         (markup-elements-cp (assoc config :block/format format) ast)]
+        (inline-text format macro-content)))
+    [:span.warning {:title (str "Unsupported macro name: " name)}
+     (macro->text name arguments)]))
+
 (defn inline
   [{:keys [html-export?] :as config} item]
   (match item
@@ -650,7 +672,8 @@
 
         :else
         (if-let [block-uuid (:block/uuid config)]
-          (let [macro-content (or
+          (let [format (get-in config [:block :block/format] :markdown)
+                macro-content (or
                                (-> (db/entity [:block/uuid block-uuid])
                                    (:block/page)
                                    (:db/id)
@@ -658,18 +681,16 @@
                                    :page/properties
                                    :macros
                                    (get name))
-                               (get-in (state/get-config) [:macros name])
-                               (get-in (state/get-config) [:macros (keyword name)]))]
-            [:span
-             (if (and (seq arguments) macro-content)
-               (block/macro-subs macro-content arguments)
-               (or
-                macro-content
-                [:span.warning {:title (str "Unsupported macro name: " name)}
-                 (macro->text name arguments)]))])
-
-          [:span
-           (macro->text name arguments)])))
+                               (get (state/get-macros) name)
+                               (get (state/get-macros) (keyword name)))
+                macro-content (if (and (seq arguments) macro-content)
+                                (block/macro-subs macro-content arguments)
+                                macro-content)]
+            (render-macro config name arguments macro-content format))
+
+          (when-let [macro-txt (macro->text name arguments)]
+            (let [format (get-in config [:block :block/format] :markdown)]
+              (render-macro config name arguments macro-txt format))))))
 
     :else
     ""))
@@ -978,12 +999,6 @@
     [:div.pre-block.bg-base-2.p-2
      (markup-elements-cp (assoc config :block/format format) ast)]))
 
-(defn property-value
-  [format v]
-  (when (string? v)
-    (let [inline-list (mldoc/inline->edn v (mldoc/default-config format))]
-      [:div.inline.mr-1 (map-inline {} inline-list)])))
-
 (rum/defc properties-cp
   [block]
   (let [properties (apply dissoc (:block/properties block) text/hidden-properties)]
@@ -993,7 +1008,7 @@
          [:div.my-1
           [:b k]
           [:span.mr-1 ":"]
-          (property-value (:block/format block) v)])])))
+          (inline-text (:block/format block) v)])])))
 
 (rum/defcs timestamp-cp < rum/reactive
   (rum/local false ::show?)
@@ -1580,14 +1595,14 @@
                   (if (or (= k :tags)
                           (= k :alias))
                     (if (string/includes? item "[[")
-                      (property-value format item)
+                      (inline-text format item)
                       (let [tag (-> item
                                     (string/replace "[" "")
                                     (string/replace "]" ""))]
                         [:a.tag.mr-1 {:href (rfe/href :page {:name tag})}
                          tag]))
-                    (property-value format item)))
-                (property-value format v))])))]
+                    (inline-text format item)))
+                (inline-text format v))])))]
 
       ["Paragraph" l]
       ;; TODO: speedup

+ 2 - 0
src/main/frontend/components/repo.cljs

@@ -177,6 +177,8 @@
             (fn [{:keys [id url]}]
               {:title (get-repo-name url)
                :options {:on-click (fn []
+                                     (repo-handler/push-if-auto-enabled! (state/get-current-repo))
+
                                      (state/set-current-repo! url)
                                      (when-not (= :draw (state/get-current-route))
                                        (route-handler/redirect-to-home!))

+ 1 - 3
src/main/frontend/config.cljs

@@ -39,9 +39,7 @@
 
 (defn git-pull-secs
   []
-  (if dev?
-    (* 60 5)
-    (or 60 (get-in @state/state [:config :git-pull-secs]))))
+  (or 60 (get-in @state/state [:config :git-pull-secs])))
 
 (defn git-push-secs
   []

+ 41 - 39
src/main/frontend/handler/repo.cljs

@@ -340,15 +340,17 @@
                       (log/error :git/pull-error error)))))))))))))
 
 (defn push
-  [repo-url {:keys [commit-message merge-push-no-diff?]
-             :or {commit-message "Logseq auto save"
+  [repo-url {:keys [commit-message merge-push-no-diff? custom-commit?]
+             :or {custom-commit false
+                  commit-message "Logseq auto save"
                   merge-push-no-diff? false}}]
   (spec/validate :repos/url repo-url)
   (let [status (db/get-key-value repo-url :git/status)]
     (if (and
          (db/cloned? repo-url)
          (state/input-idle? repo-url)
-         (not= status :pushing))
+         (or (not= status :pushing)
+             custom-commit?))
       (-> (p/let [files (js/window.workerThread.getChangedFiles (util/get-repo-dir (state/get-current-repo)))]
             (when (or (seq files) merge-push-no-diff?)
               ;; auto commit if there are any un-committed changes
@@ -358,7 +360,8 @@
                 (p/let [commit-oid (git/commit repo-url commit-message)
                         token (helper/get-github-token repo-url)
                         status (db/get-key-value repo-url :git/status)]
-                  (when (and token (not= status :pushing))
+                  (when (and token (or (not= status :pushing)
+                                       custom-commit?))
                     (git-handler/set-git-status! repo-url :pushing)
                     (util/p-handle
                      (git/push repo-url token merge-push-no-diff?)
@@ -474,27 +477,21 @@
              (state/set-db-restoring! false)))
     (js/setTimeout setup-local-repo-if-not-exists! 100)))
 
-(defn periodically-pull
-  [repo-url pull-now?]
-  (spec/validate :repos/url repo-url)
-  (p/let [token (helper/get-github-token repo-url)]
-    (when token
-      (when pull-now? (pull repo-url nil))
-      (js/setInterval #(pull repo-url nil)
-                      (* (config/git-pull-secs) 1000)))))
-
-(defn periodically-push-tasks
-  [repo-url]
-  (js/setInterval #(push-if-auto-enabled! repo-url)
+(defn periodically-pull-current-repo
+  []
+  (js/setInterval
+   (fn []
+     (p/let [repo-url (state/get-current-repo)
+             token (helper/get-github-token repo-url)]
+       (when token
+         (pull repo-url nil))))
+   (* (config/git-pull-secs) 1000)))
+
+(defn periodically-push-current-repo
+  []
+  (js/setInterval #(push-if-auto-enabled! (state/get-current-repo))
                   (* (config/git-push-secs) 1000)))
 
-(defn periodically-pull-and-push
-  [repo-url {:keys [pull-now?]
-             :or {pull-now? true}}]
-  (spec/validate :repos/url repo-url)
-  (periodically-pull repo-url pull-now?)
-  (periodically-push-tasks repo-url))
-
 (defn create-repo!
   [repo-url branch]
   (spec/validate :repos/url repo-url)
@@ -510,14 +507,13 @@
                (println "Something wrong!")
                (js/console.dir error))))
 
-(defn- clone-and-pull
+(defn- clone-and-load-db
   [repo-url]
   (spec/validate :repos/url repo-url)
   (->
    (p/let [_ (clone repo-url)
            _ (git-handler/git-set-username-email! repo-url (state/get-me))]
-     (load-db-and-journals! repo-url nil true)
-     (periodically-pull-and-push repo-url {:pull-now? false}))
+     (load-db-and-journals! repo-url nil true))
    (p/catch (fn [error]
               (js/console.error error)))))
 
@@ -525,17 +521,22 @@
   [me]
   (spec/validate :state/me me)
   (if (and js/window.git js/window.pfs)
-    (doseq [{:keys [id url]} (:repos me)]
-      (let [repo url]
-        (p/let [config-exists? (fs/file-exists?
-                                (util/get-repo-dir url)
-                                ".git/config")]
-          (if (and config-exists?
-                   (db/cloned? repo))
-            (do
-              (git-handler/git-set-username-email! repo me)
-              (periodically-pull-and-push repo {:pull-now? true}))
-            (clone-and-pull repo)))))
+    (do
+      (doseq [{:keys [id url]} (:repos me)]
+        (let [repo url]
+          (p/let [config-exists? (fs/file-exists?
+                                  (util/get-repo-dir url)
+                                  ".git/config")]
+            (if (and config-exists?
+                     (db/cloned? repo))
+              (do
+                (git-handler/git-set-username-email! repo me)
+                (pull repo nil))
+              (do
+                (clone-and-load-db repo))))))
+
+      (periodically-pull-current-repo)
+      (periodically-push-current-repo))
     (js/setTimeout (fn []
                      (clone-and-pull-repos me))
                    500)))
@@ -548,11 +549,12 @@
   (-> (p/do! (db/remove-db! url)
              (db/remove-files-db! url)
              (fs/rmdir (util/get-repo-dir url))
-             (clone-and-pull url))
+             (clone-and-load-db url))
       (p/catch (fn [error]
                  (prn "Delete repo failed, error: " error)))))
 
 (defn git-commit-and-push!
   [commit-message]
   (when-let [repo (state/get-current-repo)]
-    (push repo {:commit-message commit-message})))
+    (push repo {:commit-message commit-message
+                :custom-commit? true})))

+ 9 - 0
src/main/frontend/state.cljs

@@ -142,6 +142,15 @@
   ([repo-url]
    (get-in @state [:config repo-url])))
 
+(defonce built-in-macros
+  {"img" "[:img.$4 {:src \"$1\" :style {:width $2 :height $3}}]"})
+
+(defn get-macros
+  []
+  (merge
+   built-in-macros
+   (:macros (get-config))))
+
 (defn sub-config
   []
   (sub :config))

+ 13 - 6
src/main/frontend/ui.cljs

@@ -18,14 +18,21 @@
 (defonce css-transition (r/adapt-class CSSTransition))
 (defonce textarea (r/adapt-class (gobj/get TextareaAutosize "default")))
 
-(rum/defc ls-textarea [{:keys [on-change] :as -props}]
-  (let [composition? (atom false)
+(rum/defc ls-textarea < rum/reactive
+  [{:keys [on-change] :as props}]
+  (let [skip-composition? (or
+                           (state/sub :editor/show-page-search?)
+                           (state/sub :editor/show-block-search?)
+                           (state/sub :editor/show-template-search?))
+        composition? (atom false)
         set-composition? #(reset! composition? %)
         on-composition (fn [e]
-                         (case e.type
-                           "compositionend" (do (set-composition? false) (on-change e))
-                           (set-composition? true)))
-        props (assoc -props
+                         (if skip-composition?
+                           (on-change e)
+                           (case e.type
+                             "compositionend" (do (set-composition? false) (on-change e))
+                             (set-composition? true))))
+        props (assoc props
                      :on-change (fn [e] (when-not @composition?
                                           (on-change e)))
                      :on-composition-start on-composition

+ 1 - 1
src/main/frontend/version.cljs

@@ -1,3 +1,3 @@
 (ns frontend.version)
 
-(defonce version "0.0.4.7-1")
+(defonce version "0.0.4.7-3")