Browse Source

Merge branch 'feat/db' into refactor/db-remove-block-name-unique

Tienson Qin 1 year ago
parent
commit
0baba5c5f4

+ 1 - 0
.clj-kondo/config.edn

@@ -126,6 +126,7 @@
              frontend.worker.handler.page worker-page
              frontend.worker.handler.page.rename worker-page-rename
              frontend.worker.handler.file.util wfu
+             frontend.worker.batch-tx batch-tx
              lambdaisland.glogi log
              logseq.common.config common-config
              logseq.common.graph common-graph

+ 4 - 3
packages/ui/@/components/ui/input.tsx

@@ -6,14 +6,15 @@ import { cn } from '@/lib/utils'
 export interface InputProps
   extends React.InputHTMLAttributes<HTMLInputElement> {}
 
-const Input = React.forwardRef<HTMLInputElement, InputProps>(
-  ({ className, type, ...props }, ref) => {
+const Input = React.forwardRef<HTMLInputElement, InputProps & any>(
+  ({ className, type, small, ...props }, ref) => {
     return (
       <input
         type={type}
         className={cn(
           'ui__input',
-          'flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background ' +
+          (small ? 'h-8 py-1 px-2' : 'h-10 px-3 py-2'),
+          'flex w-full rounded-md border border-input bg-background text-sm ring-offset-background ' +
           'file:border-0 file:bg-transparent file:text-sm file:font-medium focus:border-input ' +
           'placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring ' +
           'focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50',

+ 2 - 2
src/main/frontend/components/container.css

@@ -602,8 +602,8 @@
   user-select: none;
 
   .resizer {
-    @apply absolute top-0 bottom-0 touch-none left-[1px] w-[3px] select-none !bg-primary;
-    @apply !cursor-col-resize hover:bg-primary/90 focus:bg-primary/90 active:bg-primary/90;
+    @apply absolute top-0 bottom-0 touch-none left-[1px] w-[3px] select-none;
+    @apply cursor-col-resize hover:bg-primary/90 focus:bg-primary/90 active:bg-primary/90;
     @apply z-[1000] delay-300 transition-[background-color] duration-300;
   }
 

+ 6 - 2
src/main/frontend/components/journal.css

@@ -6,10 +6,14 @@
   }
 
   .journal-item {
-    @apply border-t min-h-[250px];
+    @apply border-b min-h-[250px] pb-[64px] mb-[38px];
 
     &:first-child {
-      @apply pt-0 border-none min-h-[500px];
+      @apply pt-0 min-h-[500px];
+    }
+
+    &:last-child {
+      @apply border-none;
     }
   }
 }

+ 6 - 0
src/main/frontend/components/page.css

@@ -452,6 +452,12 @@ html.is-native-ios {
   .info-title {
     @apply relative min-h-[28px] flex items-center pl-1;
   }
+
+  .ls-properties-area {
+    &:has(.property-pair) {
+      @apply pt-2.5;
+    }
+  }
 }
 
 .page-info-title-placeholder {

+ 1 - 1
src/main/frontend/components/property.css

@@ -47,7 +47,7 @@
 }
 
 .ls-properties-area {
-    @apply grid gap-0.5 pt-2 pb-1.5;
+    @apply grid gap-0.5 pt-1.5 pb-1.5;
 
     .property-pair {
         @apply grid grid-cols-5 gap-1;

+ 8 - 7
src/main/frontend/components/reference.cljs

@@ -14,6 +14,7 @@
             [frontend.search :as search]
             [frontend.state :as state]
             [frontend.ui :as ui]
+            [logseq.shui.ui :as shui]
             [frontend.util :as util]
             [rum.core :as rum]
             [frontend.modules.outliner.tree :as tree]
@@ -77,12 +78,13 @@
         (when (seq excludes)
           [:div.flex.flex-row.flex-wrap
            [:div.mr-1.font-medium.py-1 (t :linked-references/filter-excludes)]
+
            (filtered-refs page-entity filters filters-atom excludes)])])
-     [:div.cp__filters-input-panel.flex
+     [:div.cp__filters-input-panel.flex.focus-within:bg-gray-03
       (ui/icon "search")
-      [:input.cp__filters-input.w-full
+      [:input.cp__filters-input.w-full.bg-transparent
        {:placeholder (t :linked-references/filter-search)
-        :auto-focus true
+        :autofocus true
         :on-change (fn [e]
                      (reset! filter-search (util/evalue e)))}]]
      (let [all-filters (set (keys filters))
@@ -150,10 +152,9 @@
                            ;; expand
                            (reset! @*collapsed? false)))
         :on-pointer-down (fn [e]
-                         (util/stop-propagation e))
-        :on-click (fn []
-                    (state/set-modal! (filter-dialog page-entity filters-atom *ref-pages)
-                                      {:center? true}))}
+                           (util/stop-propagation e)
+                           (shui/dialog-open!
+                             (filter-dialog page-entity filters-atom *ref-pages)))}
        (ui/icon "filter" {:class (cond
                                    (empty? filter-state)
                                    "opacity-60 hover:opacity-100"

+ 0 - 1
src/main/frontend/components/reference.css

@@ -1,5 +1,4 @@
 .cp__filters-input {
-  background-color: var(--ls-primary-background-color);
   padding: 0.5rem;
   outline: none;
 }

+ 3 - 5
src/main/frontend/ui.css

@@ -315,11 +315,9 @@ html.is-mobile {
 }
 
 .form-input {
-  @apply block w-full pl-2 sm:text-sm sm:leading-5 rounded bg-background border border-gray-07;
-
-  &:focus {
-    box-shadow: 0 0 0 2px var(--tw-shadow-color, rgba(164, 202, 254, 0.45));
-  }
+  @apply block w-full mt-1 pl-2 sm:text-sm sm:leading-5 rounded bg-background border border-gray-07;
+  @apply focus:border-input focus-visible:ring-ring focus-visible:outline-none focus-visible:ring-offset-2;
+  @apply focus-visible:ring-2 ring-offset-background;
 
   &.is-small {
     @apply py-1.5 sm:leading-4 sm:text-xs;

+ 18 - 0
src/main/frontend/worker/batch_tx.clj

@@ -0,0 +1,18 @@
+(ns frontend.worker.batch-tx
+  "Macro for batch-tx fns")
+
+(defmacro with-batch-tx-mode
+  "1. start batch-tx mode
+  2. run body
+  3. exit batch-tx mode
+  4. refresh-ui"
+  [conn & body]
+  `(do (frontend.worker.batch-tx/start-batch-tx-mode)
+       ~@body
+       (let [txs# (frontend.worker.batch-tx/get-batch-txs)]
+         (frontend.worker.batch-tx/exit-batch-tx-mode)
+         (when (seq txs#)
+           (when-let [affected-keys# (not-empty
+                                      (frontend.worker.react/get-affected-queries-keys
+                                       {:db-after @~conn :tx-data txs#}))]
+             (frontend.worker.util/post-message :refresh-ui {:affected-keys affected-keys#}))))))

+ 34 - 0
src/main/frontend/worker/batch_tx.cljs

@@ -0,0 +1,34 @@
+(ns frontend.worker.batch-tx
+  "Batch process multiple transactions.
+  When batch-processing, don't refresh ui."
+  (:require [frontend.worker.state :as worker-state]
+            [frontend.schema-register :include-macros true :as sr]))
+
+
+(sr/defkeyword :tx/batch-processing?
+  "will not sync worker-db-changes to UI when true")
+
+(sr/defkeyword :tx/batch-txs
+  "store all tx-data when batch-processing")
+
+
+(defn start-batch-tx-mode
+  []
+  (swap! worker-state/*state assoc :tx/batch-processing? true))
+
+(defn tx-batch-processing?
+  []
+  (:tx/batch-processing? @worker-state/*state))
+
+(defn get-batch-txs
+  []
+  (:tx/batch-txs @worker-state/*state))
+
+(defn conj-batch-txs!
+  [tx-data]
+  (swap! worker-state/*state update :tx/batch-txs (fn [data] (into data tx-data))))
+
+(defn exit-batch-tx-mode
+  []
+  (swap! worker-state/*state assoc :tx/batch-processing? false)
+  (swap! worker-state/*state assoc :tx/batch-txs nil))

+ 8 - 8
src/main/frontend/worker/pipeline.cljs

@@ -1,16 +1,16 @@
 (ns frontend.worker.pipeline
   "Pipeline work after transaction"
   (:require [datascript.core :as d]
-            [logseq.outliner.datascript-report :as ds-report]
-            [logseq.outliner.pipeline :as outliner-pipeline]
-            [frontend.worker.react :as worker-react]
+            [frontend.worker.batch-tx :as batch-tx]
+            [frontend.worker.db.fix :as db-fix]
             [frontend.worker.file :as file]
+            [frontend.worker.react :as worker-react]
             [frontend.worker.util :as worker-util]
-            [frontend.worker.state :as worker-state]
+            [logseq.db :as ldb]
             [logseq.db.frontend.validate :as db-validate]
             [logseq.db.sqlite.util :as sqlite-util]
-            [frontend.worker.db.fix :as db-fix]
-            [logseq.db :as ldb]))
+            [logseq.outliner.datascript-report :as ds-report]
+            [logseq.outliner.pipeline :as outliner-pipeline]))
 
 (defn- path-refs-need-recalculated?
   [tx-meta]
@@ -135,12 +135,12 @@
               final-tx-report (assoc tx-report'
                                      :tx-data full-tx-data
                                      :db-before (:db-before tx-report))
-              batch-processing? (worker-state/rtc-batch-processing?)
+              batch-processing? (batch-tx/tx-batch-processing?)
               affected-query-keys (when-not (or (:importing? context)
                                                 batch-processing?)
                                     (worker-react/get-affected-queries-keys final-tx-report))]
           (when batch-processing?
-            (worker-state/conj-batch-txs! full-tx-data))
+            (batch-tx/conj-batch-txs! full-tx-data))
           {:tx-report final-tx-report
            :affected-keys affected-query-keys
            :deleted-block-uuids deleted-block-uuids

+ 9 - 17
src/main/frontend/worker/rtc/core.cljs

@@ -10,10 +10,10 @@
             [cognitect.transit :as transit]
             [datascript.core :as d]
             [frontend.worker.async-util :include-macros true :refer [<? go-try]]
+            [frontend.worker.batch-tx :include-macros true :as batch-tx]
             [frontend.worker.db-metadata :as worker-db-metadata]
             [frontend.worker.handler.page :as worker-page]
             [frontend.worker.handler.page.db-based.rename :as worker-page-rename]
-            [frontend.worker.react :as worker-react]
             [frontend.worker.rtc.asset-sync :as asset-sync]
             [frontend.worker.rtc.const :as rtc-const]
             [frontend.worker.rtc.op-mem-layer :as op-mem-layer]
@@ -640,22 +640,14 @@
               update-page-ops (vals update-page-ops-map)
               remove-page-ops (vals remove-page-ops-map)]
 
-          (worker-state/start-batch-tx-mode!)
-          (js/console.groupCollapsed "rtc/apply-remote-ops-log")
-          (worker-util/profile :apply-remote-update-page-ops (apply-remote-update-page-ops repo conn date-formatter update-page-ops))
-          (worker-util/profile :apply-remote-remove-ops (apply-remote-remove-ops repo conn date-formatter remove-ops))
-          (worker-util/profile :apply-remote-move-ops (apply-remote-move-ops repo conn date-formatter sorted-move-ops))
-          (worker-util/profile :apply-remote-update-ops (apply-remote-update-ops repo conn date-formatter update-ops))
-          (worker-util/profile :apply-remote-remove-page-ops (apply-remote-remove-page-ops repo conn remove-page-ops))
-          (js/console.groupEnd)
-          (let [txs (worker-state/get-batch-txs)]
-            (worker-state/exit-batch-tx-mode!)
-            (when (seq txs)
-              (let [affected-keys (worker-react/get-affected-queries-keys {:db-after @conn
-                                                                           :tx-data txs})]
-                (when (seq affected-keys)
-                  (worker-util/post-message :refresh-ui
-                                            {:affected-keys affected-keys})))))
+          (batch-tx/with-batch-tx-mode conn
+            (js/console.groupCollapsed "rtc/apply-remote-ops-log")
+            (worker-util/profile :apply-remote-update-page-ops (apply-remote-update-page-ops repo conn date-formatter update-page-ops))
+            (worker-util/profile :apply-remote-remove-ops (apply-remote-remove-ops repo conn date-formatter remove-ops))
+            (worker-util/profile :apply-remote-move-ops (apply-remote-move-ops repo conn date-formatter sorted-move-ops))
+            (worker-util/profile :apply-remote-update-ops (apply-remote-update-ops repo conn date-formatter update-ops))
+            (worker-util/profile :apply-remote-remove-page-ops (apply-remote-remove-page-ops repo conn remove-page-ops))
+            (js/console.groupEnd))
 
           (op-mem-layer/update-local-tx! repo remote-t)
           (update-log state {:remote-update-map affected-blocks-map}))

+ 4 - 0
src/main/frontend/worker/rtc/db_listener.cljs

@@ -5,6 +5,7 @@
             [clojure.data :as data]
             [clojure.set :as set]
             [datascript.core :as d]
+            [frontend.schema-register :include-macros true :as sr]
             [frontend.worker.db-listener :as db-listener]
             [frontend.worker.rtc.op-mem-layer :as op-mem-layer]))
 
@@ -165,6 +166,9 @@
       (op-mem-layer/add-asset-ops! repo asset-ops*))))
 
 
+(sr/defkeyword :persist-op?
+  "tx-meta option, generate rtc ops when not nil (default true)")
+
 (defmethod db-listener/listen-db-changes :gen-rtc-ops
   [_ {:keys [_tx-data tx-meta db-before db-after
              repo id->attr->datom same-entity-datoms-coll]}]

+ 12 - 24
src/main/frontend/worker/state.cljs

@@ -1,7 +1,14 @@
 (ns frontend.worker.state
   "State hub for worker"
   (:require [logseq.common.util :as common-util]
-            [logseq.common.config :as common-config]))
+            [logseq.common.config :as common-config]
+            [frontend.schema-register :include-macros true :as sr]))
+
+(sr/defkeyword :undo/repo->undo-stack
+  "{repo [first-op, second-op, ...]}")
+
+(sr/defkeyword :undo/repo->undo-stack
+  "{repo [first-op, second-op, ...]}")
 
 (defonce *state (atom {:worker/object nil
 
@@ -11,8 +18,10 @@
                        ;; FIXME: this name :config is too general
                        :config {}
                        :git/current-repo nil
-                       :rtc/batch-processing? false
-                       :rtc/remote-batch-txs nil
+
+                       :tx/batch-processing? false
+                       :tx/batch-txs nil
+
                        :rtc/downloading-graph? false
 
                        :undo/repo->undo-stack (atom {})
@@ -98,24 +107,3 @@
 (defn rtc-downloading-graph?
   []
   (:rtc/downloading-graph? @*state))
-
-(defn start-batch-tx-mode!
-  []
-  (swap! *state assoc :rtc/batch-processing? true))
-
-(defn rtc-batch-processing?
-  []
-  (:rtc/batch-processing? @*state))
-
-(defn get-batch-txs
-  []
-  (:rtc/remote-batch-txs @*state))
-
-(defn conj-batch-txs!
-  [tx-data]
-  (swap! *state update :rtc/remote-batch-txs (fn [data] (into data tx-data))))
-
-(defn exit-batch-tx-mode!
-  []
-  (swap! *state assoc :rtc/batch-processing? false)
-  (swap! *state assoc :rtc/remote-batch-txs nil))

+ 13 - 10
src/main/frontend/worker/undo_redo.cljs

@@ -2,6 +2,7 @@
   "undo/redo related fns and op-schema"
   (:require [datascript.core :as d]
             [frontend.schema-register :include-macros true :as sr]
+            [frontend.worker.batch-tx :include-macros true :as batch-tx]
             [frontend.worker.db-listener :as db-listener]
             [frontend.worker.state :as worker-state]
             [logseq.common.config :as common-config]
@@ -250,26 +251,28 @@ when undo this op, this original entity-map will be transacted back into db")
   (if-let [ops (not-empty (pop-undo-ops repo))]
     (let [conn (worker-state/get-datascript-conn repo)
           redo-ops-to-push (transient [])]
-      (doseq [op ops]
-        (let [rev-op (reverse-op @conn op)]
-          (when (= :push-undo-redo (reverse-apply-op op conn repo))
-            (conj! redo-ops-to-push rev-op))))
+      (batch-tx/with-batch-tx-mode conn
+        (doseq [op ops]
+          (let [rev-op (reverse-op @conn op)]
+            (when (= :push-undo-redo (reverse-apply-op op conn repo))
+              (conj! redo-ops-to-push rev-op)))))
       (when-let [rev-ops (not-empty (persistent! redo-ops-to-push))]
         (push-redo-ops repo (cons boundary rev-ops))))
-    (prn "No further undo infomation")))
+    (prn "No further undo information")))
 
 (defn redo
   [repo]
   (if-let [ops (not-empty (pop-redo-ops repo))]
     (let [conn (worker-state/get-datascript-conn repo)
           undo-ops-to-push (transient [])]
-      (doseq [op ops]
-        (let [rev-op (reverse-op @conn op)]
-          (when (= :push-undo-redo (reverse-apply-op op conn repo))
-            (conj! undo-ops-to-push rev-op))))
+      (batch-tx/with-batch-tx-mode conn
+        (doseq [op ops]
+          (let [rev-op (reverse-op @conn op)]
+            (when (= :push-undo-redo (reverse-apply-op op conn repo))
+              (conj! undo-ops-to-push rev-op)))))
       (when-let [rev-ops (not-empty (persistent! undo-ops-to-push))]
         (push-undo-ops repo (cons boundary rev-ops))))
-    (prn "No further redo infomation")))
+    (prn "No further redo information")))
 
 
 ;;; listen db changes and push undo-ops

+ 0 - 2
src/test/frontend/worker/undo_redo_test.cljs

@@ -6,8 +6,6 @@
 
 (deftest reverse-op-test
   ;; TODO: add tests for undo-redo
-  #'undo-redo/undo-op-schema
-  #'undo-redo/reverse-op
   undo-redo/undo
   undo-redo/redo
   )