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

Merge remote-tracking branch 'upstream/master' into whiteboards

Peng Xiao 3 лет назад
Родитель
Сommit
26f04b073b

+ 2 - 2
android/app/build.gradle

@@ -6,8 +6,8 @@ android {
         applicationId "com.logseq.app"
         minSdkVersion rootProject.ext.minSdkVersion
         targetSdkVersion rootProject.ext.targetSdkVersion
-        versionCode 30
-        versionName "0.7.6"
+        versionCode 32
+        versionName "0.7.8"
         testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
         aaptOptions {
              // Files and dirs to omit from the packaged assets dir, modified to accommodate modern web apps.

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

@@ -33,7 +33,7 @@
 (defn editable-built-in-properties
   "Properties used by logseq that user can edit"
   []
-  (into #{:title :icon :template :template-including-parent :public :filters}
+  (into #{:title :icon :template :template-including-parent :public :filters :exclude-from-graph-view}
         editable-linkable-built-in-properties))
 
 (defn hidden-built-in-properties

+ 2 - 2
e2e-tests/flashcards.spec.ts

@@ -3,7 +3,7 @@ import { test } from './fixtures'
 import { createRandomPage } from './utils'
 
 
-test.skip('flashcard demo', async ({ page, block }) => {
+test('flashcard demo', async ({ page, block }) => {
   await createRandomPage(page)
 
   await block.mustFill('Why do you add cards? #card #logseq')
@@ -40,7 +40,7 @@ test.skip('flashcard demo', async ({ page, block }) => {
   await block.mustFill('{{cards [[logseq]]}}')
   await page.keyboard.press('Enter')
   const queryCards = page.locator('text="No matched cards"')
-  await queryCards.waitFor({ state: 'hidden', timeout: 1000 })
+  await queryCards.waitFor({ state: 'hidden', timeout: 6000 })
 
   const numberLabel = page.locator('.cards-title')
   await numberLabel.waitFor({ state: 'visible' })

+ 4 - 4
ios/App/App.xcodeproj/project.pbxproj

@@ -542,7 +542,7 @@
 				INFOPLIST_FILE = App/Info.plist;
 				IPHONEOS_DEPLOYMENT_TARGET = 13.0;
 				LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
-				MARKETING_VERSION = 0.7.6;
+				MARKETING_VERSION = 0.7.8;
 				OTHER_SWIFT_FLAGS = "$(inherited) \"-D\" \"COCOAPODS\" \"-DDEBUG\"";
 				PRODUCT_BUNDLE_IDENTIFIER = com.logseq.logseq;
 				PRODUCT_NAME = "$(TARGET_NAME)";
@@ -568,7 +568,7 @@
 				INFOPLIST_FILE = App/Info.plist;
 				IPHONEOS_DEPLOYMENT_TARGET = 13.0;
 				LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
-				MARKETING_VERSION = 0.7.6;
+				MARKETING_VERSION = 0.7.8;
 				PRODUCT_BUNDLE_IDENTIFIER = com.logseq.logseq;
 				PRODUCT_NAME = "$(TARGET_NAME)";
 				SWIFT_ACTIVE_COMPILATION_CONDITIONS = "";
@@ -593,7 +593,7 @@
 				INFOPLIST_KEY_NSHumanReadableCopyright = "";
 				IPHONEOS_DEPLOYMENT_TARGET = 13.0;
 				LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks";
-				MARKETING_VERSION = 0.7.6;
+				MARKETING_VERSION = 0.7.8;
 				MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
 				MTL_FAST_MATH = YES;
 				PRODUCT_BUNDLE_IDENTIFIER = com.logseq.logseq.ShareViewController;
@@ -620,7 +620,7 @@
 				INFOPLIST_KEY_NSHumanReadableCopyright = "";
 				IPHONEOS_DEPLOYMENT_TARGET = 13.0;
 				LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks";
-				MARKETING_VERSION = 0.7.6;
+				MARKETING_VERSION = 0.7.8;
 				MTL_FAST_MATH = YES;
 				PRODUCT_BUNDLE_IDENTIFIER = com.logseq.logseq.ShareViewController;
 				PRODUCT_NAME = "$(TARGET_NAME)";

+ 4 - 3
resources/package.json

@@ -1,6 +1,6 @@
 {
-  "name": "Logseq-123",
-  "version": "0.7.6",
+  "name": "Logseq-local-test-revert-me-back",
+  "version": "0.7.8",
   "main": "electron.js",
   "author": "Logseq",
   "license": "AGPL-3.0",
@@ -53,6 +53,7 @@
     "electron-rebuild": "3.2.5"
   },
   "resolutions": {
-    "**/electron": "15.1.2"
+    "**/electron": "15.1.2",
+    "**/node-gyp": "9.0.0"
   }
 }

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

@@ -1936,8 +1936,7 @@
    (and (util/sup? target)
         (dom/has-class? target "fn"))
    (dom/has-class? target "image-resize")
-   (dom/closest target "a")
-   (dom/closest target ".dsl-query")))
+   (dom/closest target "a")))
 
 (defn- block-content-on-mouse-down
   [e block block-id _content edit-input-id]
@@ -3199,6 +3198,7 @@
       (block-handler/load-more! db-id last-block-id))))
 
 (rum/defcs lazy-blocks < rum/reactive
+  (rum/local nil ::loading?)
   {:init (fn [state]
            (assoc state ::id (str (random-uuid))))}
   [state config flat-blocks blocks->vec-tree]
@@ -3208,13 +3208,16 @@
                       (map (fn [b]
                              (assoc b :ui/selected? (contains? selected-blocks (:block/uuid b)))) flat-blocks)
                       flat-blocks)
-        blocks (blocks->vec-tree flat-blocks)]
+        blocks (blocks->vec-tree flat-blocks)
+        *loading? (::loading? state)]
     (if-not db-id
       (block-list config blocks)
-      (let [bottom-reached (fn []
-                             ;; To prevent scrolling after inserting new blocks
-                             (when (> (- (util/time-ms) (:start-time config)) 100)
-                               (load-more-blocks! config flat-blocks)))
+      (let [loading-more-data! (fn []
+                                 ;; To prevent scrolling after inserting new blocks
+                                 (when (> (- (util/time-ms) (:start-time config)) 100)
+                                   (reset! *loading? true)
+                                   (load-more-blocks! config flat-blocks)
+                                   (reset! *loading? false)))
             has-more? (and
                        (>= (count flat-blocks) model/initial-blocks-length)
                        (some? (model/get-next-open-block (db/get-db) (last flat-blocks) db-id)))
@@ -3223,14 +3226,20 @@
          (ui/infinite-list
           "main-content-container"
           (block-list config blocks)
-          {:on-load bottom-reached
+          {:on-load loading-more-data!
            :bottom-reached (fn []
                              (when-let [node (gdom/getElement dom-id)]
-                               (ui/bottom-reached? node 1000)))
+                               (ui/bottom-reached? node 300)))
            :has-more has-more?
-           :more (if (or (:preview? config) (:sidebar? config))
+           :more (cond
+                   (or (:preview? config) (:sidebar? config))
                    "More"
-                   (ui/loading "Loading"))})]))))
+
+                   @*loading?
+                   (ui/lazy-loading-placeholder)
+
+                   :else
+                   "")})]))))
 
 (rum/defcs blocks-container <
   {:init (fn [state]

+ 13 - 1
src/main/frontend/components/page.cljs

@@ -443,17 +443,20 @@
 (defonce *journal? (atom nil))
 (defonce *orphan-pages? (atom true))
 (defonce *builtin-pages? (atom nil))
+(defonce *excluded-pages? (atom true))
 
 (rum/defc ^:large-vars/cleanup-todo graph-filters < rum/reactive
   [graph settings n-hops]
-  (let [{:keys [journal? orphan-pages? builtin-pages?]
+  (let [{:keys [journal? orphan-pages? builtin-pages? excluded-pages?]
          :or {orphan-pages? true}} settings
         journal?' (rum/react *journal?)
         orphan-pages?' (rum/react *orphan-pages?)
         builtin-pages?' (rum/react *builtin-pages?)
+        excluded-pages?' (rum/react *excluded-pages?)
         journal? (if (nil? journal?') journal? journal?')
         orphan-pages? (if (nil? orphan-pages?') orphan-pages? orphan-pages?')
         builtin-pages? (if (nil? builtin-pages?') builtin-pages? builtin-pages?')
+        excluded-pages? (if (nil? excluded-pages?') excluded-pages? excluded-pages?')
         set-setting! (fn [key value]
                        (let [new-settings (assoc settings key value)]
                          (config-handler/set-config! :graph/settings new-settings)))
@@ -519,6 +522,15 @@
                                (reset! *builtin-pages? value)
                                (set-setting! :builtin-pages? value)))
                            true)]]
+              [:div.flex.items-center.justify-between.mb-2
+               [:span "Excluded pages"]
+               [:div.mt-1
+                (ui/toggle excluded-pages?
+                           (fn []
+                             (let [value (not excluded-pages?)]
+                               (reset! *excluded-pages? value)
+                               (set-setting! :excluded-pages? value)))
+                           true)]]              
               (when (seq focus-nodes)
                 [:div.flex.flex-col.mb-2
                  [:p {:title "N hops from selected nodes"}

+ 1 - 6
src/main/frontend/db.cljs

@@ -141,15 +141,10 @@
                    (db-listener repo tx-report))))))
 
 (defn listen-and-persist!
-  [repo]
-  (when-let [conn (get-db repo false)]
-    (repo-listen-to-tx! repo conn)))
-
-(defn relisten-and-persist!
   [repo]
   (when-let [conn (get-db repo false)]
     (d/unlisten! conn :persistence)
-    (listen-and-persist! repo)))
+    (repo-listen-to-tx! repo conn)))
 
 (defn start-db-conn!
   ([repo]

+ 22 - 6
src/main/frontend/db/model.cljs

@@ -22,9 +22,9 @@
 
 ;; lazy loading
 
-(def initial-blocks-length 100)
+(def initial-blocks-length 50)
 
-(def step-loading-blocks 50)
+(def step-loading-blocks 25)
 
 
 ;; TODO: extract to specific models and move data transform logic to the
@@ -524,7 +524,7 @@
 
 (defn get-paginated-blocks-no-cache
   "Result should be sorted."
-  [db start-id {:keys [limit include-start? scoped-block-id]}]
+  [db start-id {:keys [limit include-start? scoped-block-id end-id]}]
   (when-let [start (d/entity db start-id)]
     (let [scoped-block-parents (when scoped-block-id
                                  (let [block (d/entity db scoped-block-id)]
@@ -537,9 +537,15 @@
                      result
                      (let [next-block (get-next-open-block db block scoped-block-id)]
                        (if next-block
-                         (if (and (seq scoped-block-parents)
-                                  (contains? scoped-block-parents (:db/id (:block/parent next-block))))
+                         (cond
+                           (and (seq scoped-block-parents)
+                                (contains? scoped-block-parents (:db/id (:block/parent next-block))))
                            result
+
+                           (and end-id (= end-id (:db/id next-block)))
+                           (conj result next-block)
+
+                           :else
                            (recur next-block (conj result next-block)))
                          result))))]
       (if include-start?
@@ -693,6 +699,14 @@
   (let [{:keys [tx-meta]} tx-report
         current-db (conn/get-db repo-url)]
     (cond
+      (and (or (:undo? tx-meta) (:redo? tx-meta)) @result)
+      (let [blocks-range (:pagination-blocks-range tx-meta)
+            [start-block-id end-block-id] (:new blocks-range)]
+        (get-paginated-blocks-no-cache current-db start-block-id
+                                       {:end-id end-block-id
+                                        :include-start? true
+                                        :scoped-block-id scoped-block-id}))
+
       (contains? #{:save-block :delete-blocks} outliner-op)
       @result
 
@@ -702,7 +716,9 @@
         (let [start-page? (:block/name (db-utils/entity start-id))]
           (when-not start-page?
             (let [previous-blocks (take-while (fn [b] (not= start-id (:db/id b))) @result)
-                  limit 25
+                  limit (-> (max (- initial-blocks-length (count previous-blocks))
+                                 (count tx-block-ids))
+                            (+ 25))
                   more (get-paginated-blocks-no-cache current-db start-id {:limit limit
                                                                            :include-start? true
                                                                            :scoped-block-id scoped-block-id})]

+ 19 - 4
src/main/frontend/db/react.cljs

@@ -70,15 +70,30 @@
 ;; component -> query-key
 (defonce query-components (atom {}))
 
+(defn- get-blocks-range
+  [result-atom new-result]
+  (let [block? (and (coll? new-result)
+                    (map? (first new-result))
+                    (:block/uuid (first new-result)))]
+    (when block?
+      {:old [(:db/id (first @result-atom))
+             (:db/id (last @result-atom))]
+       :new [(:db/id (first new-result))
+             (:db/id (last new-result))]})))
+
 (defn set-new-result!
-  [k new-result]
+  [k new-result tx-report]
   (when-let [result-atom (get-in @query-state [k :result])]
+    (when tx-report
+      (when-let [range (get-blocks-range result-atom new-result)]
+        (state/set-state! [:ui/pagination-blocks-range (get-in tx-report [:db-after :max-tx])] range)))
     (reset! result-atom new-result)))
 
 (defn swap-new-result!
   [k f]
   (when-let [result-atom (get-in @query-state [k :result])]
-    (swap! result-atom f)))
+    (let [new-result' (f @result-atom)]
+      (reset! result-atom new-result'))))
 
 (defn kv
   [key value]
@@ -89,7 +104,7 @@
 (defn remove-key!
   [repo-url key]
   (db-utils/transact! repo-url [[:db.fn/retractEntity [:db/ident key]]])
-  (set-new-result! [repo-url :kv key] nil))
+  (set-new-result! [repo-url :kv key] nil nil))
 
 (defn clear-query-state!
   []
@@ -282,7 +297,7 @@
                       (d/q query db))
                     transform-fn)]
     (when-not (= new-result result)
-      (set-new-result! k new-result))))
+      (set-new-result! k new-result tx))))
 
 (defn refresh!
   "Re-compute corresponding queries (from tx) and refresh the related react components."

+ 25 - 22
src/main/frontend/extensions/srs.cljs

@@ -400,16 +400,17 @@
 (def review-finished
   [:p.p-2 "Congrats, you've reviewed all the cards for this query, see you next time! 💯"])
 
-(defn- btn-with-shortcut [{:keys [shortcut id btn-text background on-click]}]
+(defn- btn-with-shortcut [{:keys [shortcut id btn-text background on-click class]}]
   (ui/button
-    [:span btn-text " " (ui/render-keyboard-shortcut shortcut)]
-    :id id
-    :class id
-    :background background
-    :on-click (fn [e]
-                (when-let [elem (gobj/get e "target")]
-                  (.add (.-classList elem) "opacity-25"))
-                (js/setTimeout #(on-click) 10))))
+   [:span btn-text (when-not (util/sm-breakpoint?)
+                     [" " (ui/render-keyboard-shortcut shortcut)])]
+   :id id
+   :class (str id " " class)
+   :background background
+   :on-click (fn [e]
+               (when-let [elem (gobj/get e "target")]
+                 (.add (.-classList elem) "opacity-25"))
+               (js/setTimeout #(on-click) 10))))
 
 (rum/defcs view
   < rum/reactive
@@ -455,20 +456,22 @@
          (if (or preview? modal?)
            [:div.flex.my-4.justify-between
             (when-not (and (not preview?) (= next-phase 1))
-              (ui/button
-                [:span (case next-phase
-                         1 "Hide answers"
-                         2 "Show answers"
-                         3 "Show clozes")
-                 (ui/render-keyboard-shortcut [:s])]
-                :class "mr-2 card-answers"
-                :on-click #(reset! phase next-phase)))
+              (btn-with-shortcut {:btn-text (case next-phase
+                                              1 "Hide answers"
+                                              2 "Show answers"
+                                              3 "Show clozes")
+                                  :shortcut  "s"
+                                  :id "card-answers"
+                                  :class "mr-2"
+                                  :on-click #(reset! phase next-phase)}))
             (when (and (> (count cards) 1) preview?)
-              (ui/button [:span "Next " (ui/render-keyboard-shortcut [:n])]
-                :class "mr-2 card-next"
-                :on-click (fn [e]
-                            (util/stop e)
-                            (skip-card card card-index cards phase review-records cb))))
+              (btn-with-shortcut {:btn-text "Next"
+                                  :shortcut "n"
+                                  :id       "card-next"
+                                  :class    "mr-2"
+                                  :on-click (fn [e]
+                                              (util/stop e)
+                                              (skip-card card card-index cards phase review-records cb))}))
 
             (when (and (not preview?) (= 1 next-phase))
               [:<>

+ 0 - 2
src/main/frontend/handler/block.cljs

@@ -298,5 +298,3 @@
   (reset! *show-left-menu? false)
   (reset! *show-right-menu? false)
   (reset! *swipe nil))
-
-

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

@@ -392,7 +392,7 @@
                 (catch :default e
                   (js/console.error e)))
               (state/set-current-repo! current-repo)
-              (db/relisten-and-persist! current-repo)
+              (db/listen-and-persist! current-repo)
               (db/persist-if-idle! current-repo)
               (file-handler/restore-config! current-repo false)
               (.watch mobile-util/fs-watcher #js {:path current-repo-dir})

+ 7 - 2
src/main/frontend/handler/graph.cljs

@@ -81,7 +81,7 @@
      :links links}))
 
 (defn build-global-graph
-  [theme {:keys [journal? orphan-pages? builtin-pages?]}]
+  [theme {:keys [journal? orphan-pages? builtin-pages? excluded-pages?]}]
   (let [dark? (= "dark" theme)
         current-page (or (:block/name (db/get-current-page)) "")]
     (when-let [repo (state/get-current-repo)]
@@ -95,12 +95,17 @@
             pages-after-journal-filter (if-not journal?
                                          (remove :block/journal? full-pages)
                                          full-pages)
+
+           pages-after-exclude-filter (cond->> pages-after-journal-filter
+                                        (not excluded-pages?)
+                                        (remove (fn [p] (=  true (:exclude-from-graph-view (:block/properties p))))))
+
             links (concat (seq relation)
                           (seq tagged-pages)
                           (seq namespaces))
             linked (set (flatten links))
             build-in-pages (set (map string/lower-case default-db/built-in-pages-names))
-            nodes (cond->> (map :block/name pages-after-journal-filter)
+            nodes (cond->> (map :block/name pages-after-exclude-filter)
                     (not builtin-pages?)
                     (remove (fn [p] (contains? build-in-pages (string/lower-case p))))
                     (not orphan-pages?)

+ 0 - 2
src/main/frontend/handler/history.cljs

@@ -1,7 +1,6 @@
 (ns frontend.handler.history
   (:require [frontend.db :as db]
             [frontend.handler.editor :as editor]
-            [frontend.handler.ui :as ui-handler]
             [frontend.modules.editor.undo-redo :as undo-redo]
             [frontend.state :as state]
             [frontend.util :as util]
@@ -9,7 +8,6 @@
 
 (defn restore-cursor!
   [{:keys [last-edit-block container pos]}]
-  (ui-handler/re-render-root!)
   (when (and container last-edit-block)
     #_:clj-kondo/ignore
     (when-let [container (gdom/getElement container)]

+ 12 - 10
src/main/frontend/modules/editor/undo_redo.cljs

@@ -2,8 +2,7 @@
   (:require [datascript.core :as d]
             [frontend.db.conn :as conn]
             [frontend.modules.datascript-report.core :as db-report]
-            [frontend.state :as state]
-            [frontend.modules.outliner.pipeline :as pipelines]))
+            [frontend.state :as state]))
 
 ;;;; APIs
 
@@ -92,10 +91,9 @@
 ;;;; Invokes
 
 (defn- transact!
-  [txs]
-  (let [conn (conn/get-db false)
-        db-report (d/transact! conn txs)]
-    (pipelines/invoke-hooks db-report)))
+  [txs tx-meta]
+  (let [conn (conn/get-db false)]
+    (d/transact! conn txs tx-meta)))
 
 (defn undo
   []
@@ -108,7 +106,8 @@
                             (:editor-cursor prev-e)
                             (:editor-cursor e))]
         (push-redo e)
-        (transact! new-txs)
+        (transact! new-txs (merge {:undo? true}
+                                  (select-keys e [:pagination-blocks-range])))
         (assoc e
                :txs-op new-txs
                :editor-cursor editor-cursor)))))
@@ -118,7 +117,8 @@
   (when-let [{:keys [txs]:as e} (pop-redo)]
     (let [new-txs (get-txs true txs)]
       (push-undo e)
-      (transact! new-txs)
+      (transact! new-txs (merge {:redo? true}
+                                (select-keys e [:pagination-blocks-range])))
       (assoc e :txs-op new-txs))))
 
 (defn listen-outliner-operation
@@ -126,6 +126,8 @@
   (when-not (empty? tx-data)
     (reset-redo)
     (let [updated-blocks (db-report/get-blocks tx-report)
-          entity {:blocks updated-blocks :txs tx-data
-                  :editor-cursor (:editor-cursor tx-meta)}]
+          entity {:blocks updated-blocks
+                  :txs tx-data
+                  :editor-cursor (:editor-cursor tx-meta)
+                  :pagination-blocks-range (get-in [:ui/pagination-blocks-range (get-in tx-report [:db-after :max-tx])] @state/state)}]
       (push-undo entity))))

+ 2 - 1
src/main/frontend/modules/outliner/datascript.cljc

@@ -63,7 +63,8 @@
                  conn (conn/get-db repo false)
                  editor-cursor (state/get-current-edit-block-and-position)
                  meta (merge opts {:editor-cursor editor-cursor})
-                 rs (d/transact! conn txs (assoc meta :outliner/transact? true))]
+                 rs (d/transact! conn txs (assoc meta
+                                                 :outliner/transact? true))]
              (when true                 ; TODO: add debug flag
                (let [eids (distinct (mapv first (:tx-data rs)))
                      left&parent-list (->>

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

@@ -900,6 +900,18 @@
      label-right]]
    (progress-bar width)])
 
+(rum/defc lazy-loading-placeholder
+  []
+  [:div.shadow.rounded-md.p-4.w-full.mx-auto.mb-5.fade-in {:style {:height 88}}
+   [:div.animate-pulse.flex.space-x-4
+    [:div.flex-1.space-y-3.py-1
+     [:div.h-2.bg-base-4.rounded]
+     [:div.space-y-3
+      [:div.grid.grid-cols-3.gap-4
+       [:div.h-2.bg-base-4.rounded.col-span-2]
+       [:div.h-2.bg-base-4.rounded.col-span-1]]
+      [:div.h-2.bg-base-4.rounded]]]]])
+
 (rum/defcs lazy-visible-inner
   [state visible? content-fn ref]
   [:div.lazy-visibility
@@ -911,15 +923,7 @@
         {:ref #(when-let [^js cls (and % (.-classList %))]
                  (.add cls "fade-enter-active"))}
         (content-fn)])
-     [:div.shadow.rounded-md.p-4.w-full.mx-auto.mb-5.fade-in {:style {:height 88}}
-      [:div.animate-pulse.flex.space-x-4
-       [:div.flex-1.space-y-3.py-1
-        [:div.h-2.bg-base-4.rounded]
-        [:div.space-y-3
-         [:div.grid.grid-cols-3.gap-4
-          [:div.h-2.bg-base-4.rounded.col-span-2]
-          [:div.h-2.bg-base-4.rounded.col-span-1]]
-         [:div.h-2.bg-base-4.rounded]]]]])])
+     (lazy-loading-placeholder))])
 
 (rum/defc lazy-visible
   ([content-fn]

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

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