Selaa lähdekoodia

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

Tienson Qin 1 vuosi sitten
vanhempi
sitoutus
00967481ad

+ 3 - 2
deps/db/src/logseq/db/frontend/malli_schema.cljs

@@ -172,7 +172,7 @@
      [:block/schema
       {:optional true}
       [:map
-       [:properties {:optional true} [:vector :uuid]]]]]
+       [:properties {:optional true} [:vector property-ident]]]]]
     class-attrs
     page-attrs
     page-or-block-attrs)))
@@ -330,7 +330,8 @@
   [[:db/type :string]
    [:schema/version :int]
    [:graph/uuid :string]
-   [:graph/local-tx :string]])
+   [:graph/local-tx :string]
+   [:editor/tx-batch-mode? :boolean]])
 
 (def db-ident-key-val
   "A key-val map consists of a :db/ident and a specific key val"

+ 5 - 5
scripts/src/logseq/tasks/lang.clj

@@ -161,19 +161,19 @@
   "Allows certain keys in a language to have the same translation
    as English. Happens more in romance languages but pretty rare otherwise"
   {:fr #{:port :type :help/docs :search-item/page :shortcut.category/navigating :text/image
-         :settings-of-plugins :code :on-boarding/section-pages :paginates/pages :right-side-bar/history-global
+         :settings-of-plugins :code :on-boarding/section-pages :paginates/pages
          :shortcut.category/plugins :whiteboard/rectangle :whiteboard/triangle}
    :de #{:graph :host :plugins :port :right-side-bar/whiteboards
          :settings-of-plugins :search-item/whiteboard :shortcut.category/navigating
          :settings-page/enable-tooltip :settings-page/enable-whiteboards :settings-page/plugin-system}
-   :es #{:settings-page/tab-general :settings-page/tab-editor :whiteboard/color :right-side-bar/history-global}
+   :es #{:settings-page/tab-general :settings-page/tab-editor :whiteboard/color}
    :it #{:home :handbook/home :host :help/awesome-logseq :on-boarding/section-computer
          :settings-page/tab-account :settings-page/tab-editor :whiteboard/link}
    :nl #{:plugins :type :left-side-bar/nav-recent-pages :plugin/update}
    :pl #{:port}
    :pt-BR #{:plugins :right-side-bar/flashcards :settings-page/enable-flashcards :page/backlinks
             :host :settings-page/tab-editor :shortcut.category/plugins :whiteboard/link :settings-of-plugins :whiteboard
-            :whiteboards :on-boarding/quick-tour-journal-page-desc-2 :plugin/downloads :right-side-bar/history-global
+            :whiteboards :on-boarding/quick-tour-journal-page-desc-2 :plugin/downloads
             :right-side-bar/whiteboards :search-item/whiteboard :settings-page/enable-whiteboards :settings-page/plugin-system
             :shortcut.category/whiteboard :command.whiteboard/zoom-in :command.whiteboard/zoom-out}
    :pt-PT #{:plugins :settings-of-plugins :plugin/downloads :right-side-bar/flashcards
@@ -181,9 +181,9 @@
    :nb-NO #{:port :type :whiteboard :right-side-bar/flashcards :right-side-bar/whiteboards
             :search-item/whiteboard :settings-page/enable-flashcards :settings-page/enable-whiteboards
             :settings-page/tab-editor :shortcut.category/whiteboard :whiteboard/medium
-            :whiteboard/twitter-url :whiteboard/youtube-url :right-side-bar/history-global :linked-references/filter-heading}
+            :whiteboard/twitter-url :whiteboard/youtube-url :linked-references/filter-heading}
    :tr #{:help/awesome-logseq}
-   :id #{:host :port :on-boarding/section-app :right-side-bar/history-global}})
+   :id #{:host :port :on-boarding/section-app}})
 
 (defn- validate-languages-dont-have-duplicates
   "Looks up duplicates for all languages"

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

@@ -467,7 +467,7 @@
               (db-async/<get-block (state/get-current-repo) page-name')
               (route-handler/update-page-title-and-label! (state/get-route-match)))
              (assoc state ::page-name page-name')))}
-  [state {:keys [repo page-name preview? sidebar?] :as option}]
+  [state {:keys [repo page-name preview? sidebar? linked-refs? unlinked-refs?] :as option}]
   (let [loading? (when (::page-name state)  (state/sub-async-query-loading (::page-name state)))]
     (when-let [path-page-name (get-path-page-name state page-name)]
       (let [current-repo (state/sub :git/current-repo)
@@ -563,7 +563,7 @@
 
                ;; referenced blocks
                (when-not block-or-whiteboard?
-                 (when page
+                 (when (and page (not (false? linked-refs?)))
                    [:div {:key "page-references"}
                     (rum/with-key
                       (reference/references page)
@@ -576,7 +576,8 @@
                  (when (and (not journal?) (not db-based?))
                    (hierarchy/structures route-page-name)))
 
-               (when-not (or block-or-whiteboard? sidebar? home?)
+               (when (and (not (false? unlinked-refs?))
+                       (not (or block-or-whiteboard? sidebar? home?)))
                  [:div {:key "page-unlinked-references"}
                   (reference/unlinked-references page)])])))))))
 

+ 36 - 31
src/main/frontend/components/property.cljs

@@ -139,39 +139,44 @@
                                   :value type})))]
     [:div {:class (if in-block-container? "flex flex-1" "flex items-center col-span-2")}
      (shui/select
-      {:default-open (boolean default-open?)
-       :disabled disabled?
-       :on-value-change
-       (fn [v]
-         (let [type (keyword (string/lower-case v))
-               update-schema-fn (apply comp
-                                       #(assoc % :type type)
+      (cond->
+       {:default-open (boolean default-open?)
+        :disabled disabled?
+        :on-value-change
+        (fn [v]
+          (let [type (keyword (string/lower-case v))
+                update-schema-fn (apply comp
+                                        #(assoc % :type type)
                                              ;; always delete previous closed values as they
                                              ;; are not valid for the new type
-                                       #(dissoc % :values)
-                                       (keep
-                                        (fn [attr]
-                                          (when-not (db-property-type/property-type-allows-schema-attribute? type attr)
-                                            #(dissoc % attr)))
-                                        [:cardinality :classes :position]))]
-           (when *property-schema
-             (swap! *property-schema update-schema-fn))
-           (let [schema (or (and *property-schema @*property-schema)
-                            (update-schema-fn property-schema))
-                 repo (state/get-current-repo)]
-             (p/do!
-              (when block
-                (pv/exit-edit-property))
-              (when *show-new-property-config?
-                (reset! *show-new-property-config? false))
-              (components-pu/update-property! property property-name schema)
-              (when block
-                (let [id (str "ls-property-" (:db/id block) "-" (:db/id property) "-editor")]
-                  (state/set-state! :editor/editing-property-value-id
-                                    {id true}))
-                (property-handler/set-block-property! repo (:block/uuid block)
-                                                      (:db/ident (db/entity [:block/original-name property-name]))
-                                                      (if (= type :default) "" :logseq.property/empty-placeholder)))))))}
+                                        #(dissoc % :values)
+                                        (keep
+                                         (fn [attr]
+                                           (when-not (db-property-type/property-type-allows-schema-attribute? type attr)
+                                             #(dissoc % attr)))
+                                         [:cardinality :classes :position]))]
+            (when *property-schema
+              (swap! *property-schema update-schema-fn))
+            (let [schema (or (and *property-schema @*property-schema)
+                             (update-schema-fn property-schema))
+                  repo (state/get-current-repo)]
+              (p/do!
+               (when block
+                 (pv/exit-edit-property))
+               (when *show-new-property-config?
+                 (reset! *show-new-property-config? false))
+               (components-pu/update-property! property property-name schema)
+               (when block
+                 (let [id (str "ls-property-" (:db/id block) "-" (:db/id property) "-editor")]
+                   (state/set-state! :editor/editing-property-value-id
+                                     {id true}))
+                 (property-handler/set-block-property! repo (:block/uuid block)
+                                                       (:db/ident (db/entity [:block/original-name property-name]))
+                                                       (if (= type :default) "" :logseq.property/empty-placeholder)))))))}
+
+        ;; only set when in property configure modal
+        (and *property-name (:type property-schema))
+        (assoc :default-value (name (:type property-schema))))
       (shui/select-trigger
        {:class "!px-2 !py-0 !h-8"}
        (shui/select-value

+ 1 - 60
src/main/frontend/components/right_sidebar.cljs

@@ -66,54 +66,6 @@
                          :sidebar-key sidebar-key} repo block-id {:indent? false})]
      (block-cp repo idx block)]))
 
-(comment
-  (rum/defc history-action-info
-   [[k v]]
-   (when v [:.ml-4 (ui/foldable
-                    [:div (str k)]
-                    [:.ml-4 (case k
-                              :tx-id
-                              [:.my-1 [:pre.code.pre-wrap-white-space.bg-base-4 (str v)]]
-
-                              :blocks
-                              (map (fn [block]
-                                     [:.my-1 [:pre.code.pre-wrap-white-space.bg-base-4 (str block)]]) v)
-
-                              :txs
-                              (map (fn [[_ key val]]
-                                     (when val
-                                       [:pre.code.pre-wrap-white-space.bg-base-4
-                                        [:span.font-bold (str key) " "] (str val)])) v)
-
-                              (map (fn [[key val]]
-                                     (when val
-                                       [:pre.code.pre-wrap-white-space.bg-base-4
-                                        [:span.font-bold (str key) " "] (str val)])) v))]
-                    {:default-collapsed? true})])))
-
-(comment
-  (rum/defc history-stack
-   [label stack]
-   [:.ml-4 (ui/foldable
-            [:div label " (" (count stack) ")"]
-            (map-indexed (fn [index item]
-                           [:.ml-4 (ui/foldable [:div (str index " " (-> item :tx-meta :outliner-op))]
-                                                (map history-action-info item)
-                                                {:default-collapsed? true})]) stack)
-            {:default-collapsed? true})]))
-
-(comment
-  (rum/defc history < rum/reactive
-   []
-  ;; (let [state (undo-redo/get-state)
-  ;;       page-only-mode? (state/sub :history/page-only-mode?)]
-  ;;   [:div.ml-4
-  ;;    [:div.ml-3.font-bold (if page-only-mode? (t :right-side-bar/history-pageonly) (t :right-side-bar/history-global))]
-  ;;    [:div.p-4 [:.ml-4.mb-2
-  ;;               (history-stack (t :right-side-bar/history-undos) (rum/react (:undo-stack state)))
-  ;;               (history-stack (t :right-side-bar/history-redos) (rum/react (:redo-stack state)))]]])
-   ))
-
 (defn build-sidebar-item
   [repo idx db-id block-type *db-id init-key]
   (case (keyword block-type)
@@ -128,10 +80,6 @@
     [[:.flex.items-center (ui/icon "hierarchy" {:class "text-md mr-2"}) (t :right-side-bar/page-graph)]
      (page/page-graph)]
 
-    ;; :history
-    ;; [[:.flex.items-center (ui/icon "history" {:class "text-md mr-2"}) (t :right-side-bar/history)]
-    ;;  (history)]
-
     :block-ref
     #_:clj-kondo/ignore
     (let [lookup (if (integer? db-id) db-id [:block/uuid db-id])]
@@ -457,14 +405,7 @@
           [:div.text-sm
            [:button.button.cp__right-sidebar-settings-btn {:on-click (fn [_e]
                                                                        (state/sidebar-add-block! repo "rtc" :rtc))}
-            "(Dev) RTC"]])
-
-        ;; (when (and config/dev? (state/sub [:ui/developer-mode?]))
-        ;;   [:div.text-sm
-        ;;    [:button.button.cp__right-sidebar-settings-btn {:on-click (fn [_e]
-        ;;                                                                (state/sidebar-add-block! repo "history" :history))}
-        ;;     (t :right-side-bar/history)]])
-        ]]
+            "(Dev) RTC"]])]]
 
       [:.sidebar-item-list.flex-1.scrollbar-spacing.px-2
        (if @*anim-finished?

+ 4 - 4
src/main/frontend/db_worker.cljs

@@ -692,15 +692,15 @@
    (transit/write transit-w (rtc-core/get-block-update-log (uuid block-uuid))))
 
   (undo
-   [_this repo]
+   [_this repo page-block-uuid-str]
    (when-let [conn (worker-state/get-datascript-conn repo)]
-     (undo-redo/undo repo conn))
+     (undo-redo/undo repo (uuid page-block-uuid-str) conn))
    nil)
 
   (redo
-   [_this repo]
+   [_this repo page-block-uuid-str]
    (when-let [conn (worker-state/get-datascript-conn repo)]
-     (undo-redo/redo repo conn)))
+     (undo-redo/redo repo (uuid page-block-uuid-str) conn)))
 
   (keep-alive
    [_this]

+ 35 - 20
src/main/frontend/handler/history.cljs

@@ -5,6 +5,7 @@
             [frontend.handler.route :as route-handler]
             [frontend.state :as state]
             [frontend.util :as util]
+            [frontend.util.page :as page-util]
             [goog.dom :as gdom]
             [promesa.core :as p]))
 
@@ -36,24 +37,38 @@
       (route-handler/redirect! prev-route-data))
     (swap! state/state merge state)))
 
-(defn undo!
-  [e]
-  (when-let [repo (state/get-current-repo)]
-    (when (db-transact/request-finished?)
-      (util/stop e)
-      (p/do!
-       (state/set-state! [:editor/last-replace-ref-content-tx repo] nil)
-       (editor/save-current-block!)
-       (state/clear-editor-action!)
-       (state/set-block-op-type! nil)
-       (let [^js worker @state/*db-worker]
-         (.undo worker repo))))))
+(let [*last-request (atom nil)]
+  (defn undo!
+    [e]
+    (p/do!
+     @*last-request
+     (when-let [repo (state/get-current-repo)]
+       (when-let [current-page-uuid-str (some->> (page-util/get-latest-edit-page-id)
+                                                 db/entity
+                                                 :block/uuid
+                                                 str)]
+         (when (db-transact/request-finished?)
+           (util/stop e)
+           (p/do!
+            (state/set-state! [:editor/last-replace-ref-content-tx repo] nil)
+            (editor/save-current-block!)
+            (state/clear-editor-action!)
+            (state/set-block-op-type! nil)
+            (let [^js worker @state/*db-worker]
+              (reset! *last-request (.undo worker repo current-page-uuid-str))))))))))
 
-(defn redo!
-  [e]
-  (when-let [repo (state/get-current-repo)]
-    (when (db-transact/request-finished?)
-      (util/stop e)
-      (state/clear-editor-action!)
-      (let [^js worker @state/*db-worker]
-        (.redo worker repo)))))
+(let [*last-request (atom nil)]
+  (defn redo!
+    [e]
+    (p/do!
+     @*last-request
+     (when-let [repo (state/get-current-repo)]
+       (when-let [current-page-uuid-str (some->> (page-util/get-latest-edit-page-id)
+                                                 db/entity
+                                                 :block/uuid
+                                                 str)]
+         (when (db-transact/request-finished?)
+           (util/stop e)
+           (state/clear-editor-action!)
+           (let [^js worker @state/*db-worker]
+             (reset! *last-request (.redo worker repo current-page-uuid-str)))))))))

+ 9 - 0
src/main/frontend/util/page.cljs

@@ -17,6 +17,15 @@
   (let [page-name (state/get-current-page)]
     (:db/id (db/get-page page-name))))
 
+(defn get-latest-edit-page-id
+  "Fetch the editing page id. If there is an edit-input-id set, we are probably still
+   on editing mode"
+  []
+  (or
+    (get-in (first (state/get-editor-args)) [:block :block/page :db/id])
+    ;; not found
+    (get-current-page-id)))
+
 (defn get-page-file-rpath
   "Gets the file path of a page. If no page is given, detects the current page.
 Returns nil if no file path is found or no page is detected or given"

+ 11 - 5
src/main/frontend/worker/batch_tx.clj

@@ -1,11 +1,17 @@
 (ns frontend.worker.batch-tx
-  "Macro for batch-tx fns")
+  "Macro for batch-tx fns"
+  (:require [datascript.core :as d]))
 
 (defmacro with-batch-tx-mode
   "1. start batch-tx mode
   2. run body
   3. exit batch-tx mode"
-  [& body]
-  `(do (frontend.worker.batch-tx/start-batch-tx-mode)
-       ~@body
-       (frontend.worker.batch-tx/exit-batch-tx-mode)))
+  [conn & body]
+  `(do
+     (d/transact! ~conn [{:db/ident :logseq.kv/tx-batch-mode? :editor/tx-batch-mode? true}]
+                  {:gen-undo-op? false})
+     (frontend.worker.batch-tx/set-batch-db-before! @~conn)
+     ~@body
+     (d/transact! ~conn [{:db/ident :logseq.kv/tx-batch-mode? :editor/tx-batch-mode? false}]
+                  {:gen-undo-op? false})
+     (frontend.worker.batch-tx/exit-batch-txs-mode!)))

+ 13 - 16
src/main/frontend/worker/batch_tx.cljs

@@ -5,30 +5,27 @@
             [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
+(sr/defkeyword :batch/txs
   "store all tx-data when batch-processing")
 
-
-(defn start-batch-tx-mode
+(defn get-batch-txs
   []
-  (swap! worker-state/*state assoc :tx/batch-processing? true))
+  (->> (:batch/txs @worker-state/*state)
+       (sort-by :tx)))
 
-(defn tx-batch-processing?
-  []
-  (:tx/batch-processing? @worker-state/*state))
+(defn set-batch-db-before!
+  [db]
+  (swap! worker-state/*state assoc :batch/db-before db))
 
-(defn get-batch-txs
+(defn get-batch-db-before
   []
-  (:tx/batch-txs @worker-state/*state))
+  (:batch/db-before @worker-state/*state))
 
 (defn conj-batch-txs!
   [tx-data]
-  (swap! worker-state/*state update :tx/batch-txs (fn [data] (into data tx-data))))
+  (swap! worker-state/*state update :batch/txs (fn [data] (into data tx-data))))
 
-(defn exit-batch-tx-mode
+(defn exit-batch-txs-mode!
   []
-  (swap! worker-state/*state assoc :tx/batch-processing? false)
-  (swap! worker-state/*state assoc :tx/batch-txs nil))
+  (swap! worker-state/*state assoc :batch/txs nil)
+  (swap! worker-state/*state assoc :batch/db-before nil))

+ 20 - 19
src/main/frontend/worker/db_listener.cljs

@@ -35,27 +35,28 @@
 
 (defmethod listen-db-changes :sync-db-to-main-thread
   [_ {:keys [tx-meta repo conn] :as tx-report}]
-  (let [{:keys [pipeline-replace? from-disk?]} tx-meta
-        result (worker-pipeline/invoke-hooks repo conn tx-report (worker-state/get-context))
-        tx-report' (or (:tx-report result) tx-report)]
+  (let [{:keys [pipeline-replace? from-disk?]} tx-meta]
     (when-not pipeline-replace?
-      (let [data (merge
-                  {:request-id (:request-id tx-meta)
-                   :repo repo
-                   :tx-data (:tx-data tx-report')
-                   :tx-meta tx-meta}
-                  (dissoc result :tx-report))]
-        (worker-util/post-message :sync-db-changes data))
+      (let [result (worker-pipeline/invoke-hooks repo conn tx-report (worker-state/get-context))
+            tx-report' (:tx-report result)]
+        (when result
+          (let [data (merge
+                      {:request-id (:request-id tx-meta)
+                       :repo repo
+                       :tx-data (:tx-data tx-report')
+                       :tx-meta tx-meta}
+                      (dissoc result :tx-report))]
+            (worker-util/post-message :sync-db-changes data))
 
-      (when-not from-disk?
-        (p/do!
-         (let [{:keys [blocks-to-remove-set blocks-to-add]} (search/sync-search-indice repo tx-report')
-               ^js wo (worker-state/get-worker-object)]
-           (when wo
-             (when (seq blocks-to-remove-set)
-               (.search-delete-blocks wo repo (bean/->js blocks-to-remove-set)))
-             (when (seq blocks-to-add)
-               (.search-upsert-blocks wo repo (bean/->js blocks-to-add))))))))))
+          (when-not from-disk?
+            (p/do!
+             (let [{:keys [blocks-to-remove-set blocks-to-add]} (search/sync-search-indice repo tx-report')
+                   ^js wo (worker-state/get-worker-object)]
+               (when wo
+                 (when (seq blocks-to-remove-set)
+                   (.search-delete-blocks wo repo (bean/->js blocks-to-remove-set)))
+                 (when (seq blocks-to-add)
+                   (.search-upsert-blocks wo repo (bean/->js blocks-to-add))))))))))))
 
 
 (defn listen-db-changes!

+ 46 - 33
src/main/frontend/worker/pipeline.cljs

@@ -75,13 +75,19 @@
     (fix-db! conn tx-report)))
 
 (defn invoke-hooks
-  [repo conn tx-report context]
-  (when-not (:pipeline-replace? (:tx-meta tx-report))
-    (let [tx-meta (:tx-meta tx-report)
-          {:keys [from-disk? new-graph?]} tx-meta
-          {:keys [pages blocks]} (ds-report/get-blocks-and-pages tx-report)]
-      (if (or from-disk? new-graph?)
-        (let [path-refs (set (compute-block-path-refs-tx tx-report blocks))
+  [repo conn {:keys [db-before db-after tx-meta] :as tx-report} context]
+  (let [{:keys [from-disk? new-graph?]} tx-meta
+        now-batch-processing? (:editor/tx-batch-mode? (d/entity db-after :logseq.kv/tx-batch-mode?))]
+    (when-not (:pipeline-replace? tx-meta)
+      (cond
+        now-batch-processing?
+        (do
+          (batch-tx/conj-batch-txs! (:tx-data tx-report))
+          nil)
+
+        (or from-disk? new-graph?)
+        (let [{:keys [blocks]} (ds-report/get-blocks-and-pages tx-report)
+              path-refs (set (compute-block-path-refs-tx tx-report blocks))
               tx-report' (or
                           (when (seq path-refs)
                             (ldb/transact! conn path-refs {:replace? true
@@ -95,53 +101,60 @@
                                      :tx-data full-tx-data
                                      :db-before (:db-before tx-report))]
           {:tx-report final-tx-report})
-        (let [_ (when (sqlite-util/local-file-based-graph? repo)
+
+        :else
+        (let [exiting-batch-mode? (:editor/tx-batch-mode? (d/entity db-before :logseq.kv/tx-batch-mode?))
+              db-before (if exiting-batch-mode?
+                          (batch-tx/get-batch-db-before)
+                          (:db-before tx-report))
+              tx-data (if exiting-batch-mode?
+                        (batch-tx/get-batch-txs)
+                        (:tx-data tx-report))
+              tx-report (assoc tx-report
+                               :db-before db-before
+                               :tx-data tx-data)
+              {:keys [pages blocks]} (ds-report/get-blocks-and-pages tx-report)
+              _ (when (sqlite-util/local-file-based-graph? repo)
                   (let [page-ids (distinct (map :db/id pages))]
                     (doseq [page-id page-ids]
                       (when (d/entity @conn page-id)
                         (file/sync-to-file repo page-id tx-meta)))))
               deleted-block-uuids (set (outliner-pipeline/filter-deleted-blocks (:tx-data tx-report)))
               replace-tx (concat
-                            ;; block path refs
+                        ;; block path refs
                           (set (compute-block-path-refs-tx tx-report blocks))
 
-                            ;; delete empty property parent block
+                        ;; delete empty property parent block
                           (when (seq deleted-block-uuids)
                             (delete-property-parent-block-if-empty tx-report deleted-block-uuids))
 
-                            ;; update block/tx-id
-                            (let [updated-blocks (remove (fn [b] (contains? (set deleted-block-uuids) (:block/uuid b)))
-                                                         (concat pages blocks))
-                                  tx-id (get-in tx-report [:tempids :db/current-tx])]
-                              (->>
-                               (map (fn [b]
-                                      (when-let [db-id (:db/id b)]
-                                        {:db/id db-id
-                                         :block/tx-id tx-id})) updated-blocks)
-                               (remove nil?))))
+                        ;; update block/tx-id
+                          (let [updated-blocks (remove (fn [b] (contains? (set deleted-block-uuids) (:block/uuid b)))
+                                                       (concat pages blocks))
+                                tx-id (get-in tx-report [:tempids :db/current-tx])]
+                            (->>
+                             (map (fn [b]
+                                    (when-let [db-id (:db/id b)]
+                                      {:db/id db-id
+                                       :block/tx-id tx-id})) updated-blocks)
+                             (remove nil?))))
               tx-report' (or
                           (when (seq replace-tx)
-                            ;; TODO: remove this since transact! is really slow
+                          ;; TODO: remove this since transact! is really slow
                             (ldb/transact! conn replace-tx {:replace? true
                                                             :pipeline-replace? true}))
                           (do
                             (when-not (exists? js/process) (d/store @conn))
                             tx-report))
               fix-tx-data (validate-and-fix-db! repo conn tx-report context)
-              batch-processing? (batch-tx/tx-batch-processing?)
-              batch-tx-data (batch-tx/get-batch-txs)
-              full-tx-data (concat (:tx-data tx-report)
-                                   fix-tx-data
-                                   (:tx-data tx-report')
-                                   (when (and (not batch-processing?) (seq batch-tx-data))
-                                     batch-tx-data))
-              final-tx-report (assoc tx-report'
-                                     :tx-data full-tx-data
-                                     :db-before (:db-before tx-report))
+              full-tx-data (if exiting-batch-mode?
+                             (:tx-data tx-report)
+                             (concat (:tx-data tx-report)
+                                     fix-tx-data
+                                     (:tx-data tx-report')))
+              final-tx-report (assoc tx-report' :tx-data full-tx-data)
               affected-query-keys (when-not (:importing? context)
                                     (worker-react/get-affected-queries-keys final-tx-report))]
-          (when batch-processing?
-            (batch-tx/conj-batch-txs! full-tx-data))
           {:tx-report final-tx-report
            :affected-keys affected-query-keys
            :deleted-block-uuids deleted-block-uuids

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

@@ -4,11 +4,11 @@
             [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->pege-block-uuid->undo-ops
+  "{repo {<page-block-uuid> [op1 op2 ...]}}")
 
-(sr/defkeyword :undo/repo->undo-stack
-  "{repo [first-op, second-op, ...]}")
+(sr/defkeyword :undo/repo->pege-block-uuid->redo-ops
+  "{repo {<page-block-uuid> [op1 op2 ...]}}")
 
 (defonce *state (atom {:worker/object nil
 
@@ -19,13 +19,13 @@
                        :config {}
                        :git/current-repo nil
 
-                       :tx/batch-processing? false
-                       :tx/batch-txs nil
+                       :batch/txs []
+                       :batch/db-before nil
 
                        :rtc/downloading-graph? false
 
-                       :undo/repo->undo-stack (atom {})
-                       :undo/repo->redo-stack (atom {})}))
+                       :undo/repo->pege-block-uuid->undo-ops (atom {})
+                       :undo/repo->pege-block-uuid->redo-ops (atom {})}))
 
 (defonce *rtc-ws-url (atom nil))
 

+ 56 - 32
src/main/frontend/worker/undo_redo.cljs

@@ -139,10 +139,18 @@ when undo this op, this original entity-map will be transacted back into db")
 
 (def ^:private apply-conj-vec (partial apply (fnil conj [])))
 
+(comment
+  (def ^:private op-count-hard-limit 3000)
+  (def ^:private op-count-limit 2000))
+
 (defn- push-undo-ops
-  [repo ops]
-  (assert (undo-ops-validator ops) ops)
-  (swap! (:undo/repo->undo-stack @worker-state/*state) update repo apply-conj-vec ops))
+  [repo page-block-uuid ops]
+  (assert (and (undo-ops-validator ops)
+               (uuid? page-block-uuid))
+          {:ops ops :page-block-uuid page-block-uuid})
+  (swap! (:undo/repo->pege-block-uuid->undo-ops @worker-state/*state)
+         update-in [repo page-block-uuid]
+         apply-conj-vec ops))
 
 (defn- pop-ops-helper
   [stack]
@@ -164,32 +172,38 @@ when undo this op, this original entity-map will be transacted back into db")
     [ops (subvec (vec stack) 0 i)]))
 
 (defn- pop-undo-ops
-  [repo]
-  (let [repo->undo-stack (:undo/repo->undo-stack @worker-state/*state)
-        undo-stack (@repo->undo-stack repo)
+  [repo page-block-uuid]
+  (assert (uuid? page-block-uuid) page-block-uuid)
+  (let [repo->pege-block-uuid->undo-ops (:undo/repo->pege-block-uuid->undo-ops @worker-state/*state)
+        undo-stack (get-in @repo->pege-block-uuid->undo-ops [repo page-block-uuid])
         [ops undo-stack*] (pop-ops-helper undo-stack)]
-    (swap! repo->undo-stack assoc repo undo-stack*)
+    (swap! repo->pege-block-uuid->undo-ops assoc-in [repo page-block-uuid] undo-stack*)
     ops))
 
 (defn- empty-undo-stack?
-  [repo]
-  (empty? (@(:undo/repo->undo-stack @worker-state/*state) repo)))
+  [repo page-block-uuid]
+  (empty? (get-in @(:undo/repo->pege-block-uuid->undo-ops @worker-state/*state) [repo page-block-uuid])))
 
 (defn- empty-redo-stack?
-  [repo]
-  (empty? (@(:undo/repo->redo-stack @worker-state/*state) repo)))
+  [repo page-block-uuid]
+  (empty? (get-in @(:undo/repo->pege-block-uuid->redo-ops @worker-state/*state) [repo page-block-uuid])))
 
 (defn- push-redo-ops
-  [repo ops]
-  (assert (undo-ops-validator ops) ops)
-  (swap! (:undo/repo->redo-stack @worker-state/*state) update repo apply-conj-vec ops))
+  [repo page-block-uuid ops]
+  (assert (and (undo-ops-validator ops)
+               (uuid? page-block-uuid))
+          {:ops ops :page-block-uuid page-block-uuid})
+  (swap! (:undo/repo->pege-block-uuid->redo-ops @worker-state/*state)
+         update-in [repo page-block-uuid]
+         apply-conj-vec ops))
 
 (defn- pop-redo-ops
-  [repo]
-  (let [repo->redo-stack (:undo/repo->redo-stack @worker-state/*state)
-        redo-stack (@repo->redo-stack repo)
-        [ops redo-stack*] (pop-ops-helper redo-stack)]
-    (swap! repo->redo-stack assoc repo redo-stack*)
+  [repo page-block-uuid]
+  (assert (uuid? page-block-uuid) page-block-uuid)
+  (let [repo->pege-block-uuid->redo-ops (:undo/repo->pege-block-uuid->redo-ops @worker-state/*state)
+        undo-stack (get-in @repo->pege-block-uuid->redo-ops [repo page-block-uuid])
+        [ops undo-stack*] (pop-ops-helper undo-stack)]
+    (swap! repo->pege-block-uuid->redo-ops assoc-in [repo page-block-uuid] undo-stack*)
     ops))
 
 (defn- normal-block?
@@ -277,8 +291,8 @@ when undo this op, this original entity-map will be transacted back into db")
            (conj [:push-undo-redo])))))))
 
 (defn undo
-  [repo conn]
-  (if-let [ops (not-empty (pop-undo-ops repo))]
+  [repo page-block-uuid conn]
+  (if-let [ops (not-empty (pop-undo-ops repo page-block-uuid))]
     (let [redo-ops-to-push (transient [])]
       (batch-tx/with-batch-tx-mode conn
         (doseq [op ops]
@@ -288,16 +302,16 @@ when undo this op, this original entity-map will be transacted back into db")
               (some-> *undo-redo-info-for-test* (reset! {:op op :tx (second r)}))
               (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)))
+        (push-redo-ops repo page-block-uuid (cons boundary rev-ops)))
       nil)
 
-    (when (empty-undo-stack? repo)
+    (when (empty-undo-stack? repo page-block-uuid)
       (prn "No further undo information")
       ::empty-undo-stack)))
 
 (defn redo
-  [repo conn]
-  (if-let [ops (not-empty (pop-redo-ops repo))]
+  [repo page-block-uuid conn]
+  (if-let [ops (not-empty (pop-redo-ops repo page-block-uuid))]
     (let [undo-ops-to-push (transient [])]
       (batch-tx/with-batch-tx-mode conn
         (doseq [op ops]
@@ -307,10 +321,10 @@ when undo this op, this original entity-map will be transacted back into db")
               (some-> *undo-redo-info-for-test* (reset! {:op op :tx (second r)}))
               (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)))
+        (push-undo-ops repo page-block-uuid (cons boundary rev-ops)))
       nil)
 
-    (when (empty-redo-stack? repo)
+    (when (empty-redo-stack? repo page-block-uuid)
       (prn "No further redo information")
       ::empty-redo-stack)))
 
@@ -368,11 +382,21 @@ when undo this op, this original entity-map will be transacted back into db")
               {:block-uuid (:block/uuid entity-after)
                :block-origin-content (:block/content entity-before)}]]))))))
 
+(defn- find-page-block-uuid
+  [db-before db-after same-entity-datoms-coll]
+  (some
+   (fn [entity-datoms]
+     (when-let [e (ffirst entity-datoms)]
+       (or (some-> (d/entity db-before e) :block/page :block/uuid)
+           (some-> (d/entity db-after e) :block/page :block/uuid))))
+   same-entity-datoms-coll))
+
 (defn- generate-undo-ops
   [repo db-before db-after same-entity-datoms-coll id->attr->datom gen-boundary-op?]
-  (let [ops (mapcat (partial entity-datoms=>ops db-before db-after id->attr->datom) same-entity-datoms-coll)]
-    (when (seq ops)
-      (push-undo-ops repo (if gen-boundary-op? (cons boundary ops) ops)))))
+  (when-let [page-block-uuid (find-page-block-uuid db-before db-after same-entity-datoms-coll)]
+    (let [ops (mapcat (partial entity-datoms=>ops db-before db-after id->attr->datom) same-entity-datoms-coll)]
+      (when (seq ops)
+        (push-undo-ops repo page-block-uuid (if gen-boundary-op? (cons boundary ops) ops))))))
 
 (defmethod db-listener/listen-db-changes :gen-undo-ops
   [_ {:keys [_tx-data tx-meta db-before db-after
@@ -385,8 +409,8 @@ when undo this op, this original entity-map will be transacted back into db")
 
 (defn clear-undo-redo-stack
   []
-  (reset! (:undo/repo->undo-stack @worker-state/*state) {})
-  (reset! (:undo/repo->redo-stack @worker-state/*state) {}))
+  (reset! (:undo/repo->pege-block-uuid->redo-ops @worker-state/*state) {})
+  (reset! (:undo/repo->pege-block-uuid->undo-ops @worker-state/*state) {}))
 
 (comment
 

+ 5 - 1
src/main/logseq/sdk/experiments.cljs

@@ -22,13 +22,17 @@
   [^js props]
   (let [props1 (jsx->clj props)
         page-name (some-> props1 :page)
-        config (some-> props1 (dissoc :page))]
+        linked-refs? (some-> props1 :include-linked-refs)
+        unlinked-refs? (some-> props1 :include-unlinked-refs)
+        config (some-> props1 (dissoc :page :include-linked-refs :include-unlinked-refs))]
     (when-let [_entity (page/get-page-entity page-name)]
       (page/page
         {:repo (state/get-current-repo)
          :page-name page-name
          :preview? false
          :sidebar? false
+         :linked-refs? (not (false? linked-refs?))
+         :unlinked-refs? (not (false? unlinked-refs?))
          :config config}))))
 
 (defn ^:export register_fenced_code_renderer

+ 0 - 6
src/resources/dicts/de.edn

@@ -354,11 +354,6 @@
  :right-side-bar/flashcards "Karteikarten"
  :right-side-bar/graph-view "Graph-Ansicht"
  :right-side-bar/help "Hilfe"
- :right-side-bar/history "(Dev) Verlauf rückgängig machen / wiederherstellen"
- :right-side-bar/history-global "Global"
- :right-side-bar/history-pageonly "Nur Seite"
- :right-side-bar/history-redos "Rückgängig gemacht"
- :right-side-bar/history-undos "Wiederhergestellt"
  :right-side-bar/new-page "Neue Seite"
  :right-side-bar/page-graph "Seiten-Graph"
  :right-side-bar/separator "Griff zur Größenänderung der rechten Seitenleiste"
@@ -656,7 +651,6 @@
  :command.editor/strike-through          "Durchgestrichen"
  :command.editor/toggle-number-list      "Nummeriert/Unnummeriert umschalten"
  :command.editor/toggle-open-blocks      "Öffnen von Blöcken umschalten (alle Blöcke ein- oder ausklappen)"
- :command.editor/toggle-undo-redo-mode   "Rückgängig / Wiederherstellen umschalten (global oder nur die Seite)"
  :command.editor/undo                    "Rückgängig"
  :command.editor/up                      "Cursor nach oben bewegen / Nach oben auswählen"
  :command.editor/zoom-in                 "Heranzoomen"

+ 0 - 5
src/resources/dicts/en.edn

@@ -133,11 +133,6 @@
  :right-side-bar/switch-theme "Theme"
  :right-side-bar/contents "Contents"
  :right-side-bar/page-graph "Page graph"
- :right-side-bar/history "(Dev) Undo/Redo history"
- :right-side-bar/history-undos "Undos"
- :right-side-bar/history-redos "Redos"
- :right-side-bar/history-global "global"
- :right-side-bar/history-pageonly "page only"
  :right-side-bar/block-ref "Block references"
  :right-side-bar/graph-view "Graph view"
  :right-side-bar/all-pages "All pages"

+ 0 - 6
src/resources/dicts/es.edn

@@ -183,7 +183,6 @@
  :command.editor/strike-through                     "Tachado"
  :command.editor/toggle-number-list                 "Alternar lista de números"
  :command.editor/toggle-open-blocks                 "Alternar bloques abiertos, (colapsar o expandir todos)"
- :command.editor/toggle-undo-redo-mode              "Alternar modo deshacer rehacer (global o solo en página)"
  :command.editor/undo                               "Deshacer"
  :command.editor/up                                 "Mover cursor arriba / Seleccionar arriba"
  :command.editor/zoom-in                            "Acercar / Adelante"
@@ -540,11 +539,6 @@
  :right-side-bar/flashcards                         "Tarjetas de memorización"
  :right-side-bar/graph-view                         "Vista de Grafo"
  :right-side-bar/help                               "Ayuda"
- :right-side-bar/history                            " (Dev) Deshacer/Rehacer history "
- :right-side-bar/history-global                     "global"
- :right-side-bar/history-pageonly                   "únicamente de página"
- :right-side-bar/history-redos                      "Rehacer"
- :right-side-bar/history-undos                      "Deshacer"
  :right-side-bar/new-page                           "Nueva página"
  :right-side-bar/page-graph                         "Grafo de página"
  :right-side-bar/pane-close                         "Cerrar"

+ 0 - 2
src/resources/dicts/fa.edn

@@ -104,8 +104,6 @@
  :right-side-bar/switch-theme         "پوسته"
  :right-side-bar/contents             "محتوا"
  :right-side-bar/page-graph           "گراف برگه"
- :right-side-bar/history-global       "سراسری"
- :right-side-bar/history-pageonly     "فقط برگه"
  :right-side-bar/block-ref            "ارجاعات بلوک"
  :right-side-bar/graph-view           "نمای گراف"
  :right-side-bar/all-pages            "همه برگه‌ها"

+ 0 - 6
src/resources/dicts/fr.edn

@@ -555,7 +555,6 @@
     :command.dev/show-page-data "(Dev) Montrer les données de la page"
     :command.editor/copy-page-url "Copier l'URL de la page"
     :command.editor/toggle-number-list "Activer la liste numérotée"
-    :command.editor/toggle-undo-redo-mode "Activer le mode défaire/refaire (global ou page seulement)"
     :command.misc/copy "Copier"
     :command.ui/clear-all-notifications "Effacer toutes les notifications"
     :command.whiteboard/bring-forward "Amener vers l'avant"
@@ -702,11 +701,6 @@
     :plugin/update-plugin "Mettre à jour l'extension : {1} - {2}"
     :plugin/updates-downloading "Téléchargement des extensions"
     :query/config-property-settings "Paramètres des propriétés pour cette requête :"
-    :right-side-bar/history "(Dev) Défaire/Refaire l'historique"
-    :right-side-bar/history-global "global"
-    :right-side-bar/history-pageonly "page seulement"
-    :right-side-bar/history-redos "Refabrications"
-    :right-side-bar/history-undos "Défabrications"
     :right-side-bar/toggle-right-sidebar "Activer le panneau latéral droit"
     :search-item/no-result "Aucun résultat correspondant"
     :select/default-select-multiple "Choisir un ou plusieurs"

+ 0 - 6
src/resources/dicts/id.edn

@@ -123,11 +123,6 @@
  :right-side-bar/switch-theme "Mode tema"
  :right-side-bar/contents "Konten"
  :right-side-bar/page-graph "Grafik halaman"
- :right-side-bar/history "(Dev) Urungkan/Ubah riwayat"
- :right-side-bar/history-undos "Urungkan"
- :right-side-bar/history-redos "Pengulangan"
- :right-side-bar/history-global "global"
- :right-side-bar/history-pageonly "halaman saja"
  :right-side-bar/block-ref "Referensi blok"
  :right-side-bar/graph-view "Tampilan grafik"
  :right-side-bar/all-pages "Semua halaman"
@@ -684,7 +679,6 @@
  :command.editor/strike-through "Coret"
  :command.editor/toggle-number-list "Hidupkan/matikan daftar angka"
  :command.editor/toggle-open-blocks "Hidupkan/matikan blok terbuka (perluas atau perkecil semua blok)"
- :command.editor/toggle-undo-redo-mode "Hidupkan/matikan mode undo redo (global atau hanya halaman)"
  :command.editor/undo "Batal"
  :command.editor/up "Geser kursor ke atas / Pilih ke atas"
  :command.editor/zoom-in "Perbesar blok yang sedang disunting / Maju sebaliknya"

+ 0 - 6
src/resources/dicts/it.edn

@@ -373,7 +373,6 @@
  :command.editor/new-whiteboard "Nuova lavagna"
  :command.editor/select-parent "Seleziona blocco genitore"
  :command.editor/toggle-number-list "Attiva/disattiva elenco numerato"
- :command.editor/toggle-undo-redo-mode "Attiva/disattiva modalità disfare/rifare (globalmente o solo per la pagina)"
  :command.go/all-graphs "Vai a tutti i grafi"
  :command.go/electron-find-in-page "Cerca testo nella pagina"
  :command.go/electron-jump-to-the-next "Vai al prossimo risultato nella ricerca"
@@ -584,11 +583,6 @@
  :plugin.install-from-file/title "Installa plugin da plugins.edn"
  :query/config-property-settings "Impostazioni per le proprietà di questa richiesta:"
  :right-side-bar/flashcards "Flashcard"
- :right-side-bar/history "(Dev) cronologia disfare/rifare"
- :right-side-bar/history-global "globale"
- :right-side-bar/history-pageonly "solo pagina corrente"
- :right-side-bar/history-redos "Rifai"
- :right-side-bar/history-undos "Rifare"
  :right-side-bar/pane-close "Chiudi"
  :right-side-bar/pane-close-all "Chiudi tutti"
  :right-side-bar/pane-close-others "Chiudi altri"

+ 0 - 6
src/resources/dicts/ja.edn

@@ -132,11 +132,6 @@
  :right-side-bar/switch-theme "テーマ"
  :right-side-bar/contents "目次"
  :right-side-bar/page-graph "ページグラフ"
- :right-side-bar/history "(開発) 「元に戻す/やり直し」の履歴"
- :right-side-bar/history-undos "元に戻す"
- :right-side-bar/history-redos "やり直し"
- :right-side-bar/history-global "全体"
- :right-side-bar/history-pageonly "ページのみ"
  :right-side-bar/block-ref "ブロック参照"
  :right-side-bar/graph-view "グラフビュー"
  :right-side-bar/all-pages "全ページ"
@@ -696,7 +691,6 @@
  :command.editor/select-parent "親ブロックを選択"
  :command.editor/zoom-in "ズームイン"
  :command.editor/zoom-out "ズームアウト"
- :command.editor/toggle-undo-redo-mode "「元に戻す/やり直し」の動作を切り替える (全体かページ毎か)"
  :command.editor/toggle-number-list "数字付きリスト/通常のリストへ切り替え"
  :command.whiteboard/select "選択ツール"
  :command.whiteboard/pan "画面移動ツール"

+ 0 - 6
src/resources/dicts/nb-no.edn

@@ -280,7 +280,6 @@
  :plugin.install-from-file/notice "Følgende utvidelser vil erstatte dine utvidelser:"
  :plugin.install-from-file/success "Alle utvidelser er installert!"
  :plugin.install-from-file/title "Installer utvidelser fra plugins.edn"
- :right-side-bar/history "(Dev) Angre/Gjør om logg"
  :search-item/page "Side"
  :select/default-select-multiple "Velg en eller flere"
  :settings-page/alpha-features "Alpha funksjoner"
@@ -419,7 +418,6 @@
  :command.editor/new-whiteboard "Nytt whiteboard"
  :command.editor/select-parent "Velg overordnet blokk"
  :command.editor/toggle-number-list "Veksle nummerliste"
- :command.editor/toggle-undo-redo-mode "Veksle angremodus (global eller kun side)"
  :command.go/whiteboards "Gå til whiteboards"
  :command.graph/export-as-html "Eksporter offentlig graf som html"
  :command.pdf/find "Pdf: Søk tekst i nåværende pdf doc"
@@ -716,10 +714,6 @@
  :bug-report/clipboard-inspector-title "Utklippstavle datainspektør"
  :page/slide-view-tip-go-fullscreen (fn [] [[:span.opacity-70 "Tips: trykk "] [:code "f"] [:span.opacity-70 " for fullskjerm"]])
  :query/config-property-settings "Egenskapsinnstillinger for denne spørringen:"
- :right-side-bar/history-global "global"
- :right-side-bar/history-pageonly "kun side"
- :right-side-bar/history-redos "Omgjøringer"
- :right-side-bar/history-undos "Angret"
  :search-item/no-result "Ingen matchende resultat"
  :settings-permission/start-granting "Gi tillatelse"
  :whiteboard/edit-pdf "Rediger PDF"

+ 0 - 6
src/resources/dicts/pt-br.edn

@@ -129,10 +129,6 @@
  :right-side-bar/switch-theme "Temas"
  :right-side-bar/contents "Conteúdo"
  :right-side-bar/page-graph "Grafo da página"
- :right-side-bar/history "(Dev) Histórico de desfazer/refazer"
- :right-side-bar/history-undos "Desfazer"
- :right-side-bar/history-redos "Refazer"
- :right-side-bar/history-pageonly "somente página"
  :right-side-bar/block-ref "Referências de bloco"
  :right-side-bar/graph-view "Visualização de grafo"
  :right-side-bar/all-pages "Todas as páginas"
@@ -687,7 +683,6 @@
  :command.editor/strike-through "Riscar"
  :command.editor/toggle-number-list "Alternar lista numerada"
  :command.editor/toggle-open-blocks "Alternar blocos abertos (contrair ou expandir todos os blocos)"
- :command.editor/toggle-undo-redo-mode "Alternar modo desfazer/refazer (global ou apenas nesta página)"
  :command.editor/undo "Desfazer"
  :command.editor/up "Mover cursor para cima / Selecionar para cima"
  :command.editor/zoom-in "Dar zoom no bloco em edição / Avançar caso contrário"
@@ -780,7 +775,6 @@
  :whiteboards "Whiteboards"
  :on-boarding/quick-tour-journal-page-desc-2 "[[link]]"
  :plugin/downloads "Downloads"
- :right-side-bar/history-global "global"
  :right-side-bar/whiteboards "Whiteboards"
  :search-item/whiteboard "Whiteboard"
  :settings-page/enable-whiteboards "Whiteboards"

+ 0 - 2
src/resources/dicts/ru.edn

@@ -57,7 +57,6 @@
  :right-side-bar/switch-theme                          "Тема"
  :right-side-bar/contents                              "Содержание"
  :right-side-bar/page-graph                            "Граф страницы"
- :right-side-bar/history                               "(Dev) Отменить/Повторить историю"
  :right-side-bar/block-ref                             "Ссылка на блок"
  :right-side-bar/graph-view                            "Визуальный граф"
  :right-side-bar/all-pages                             "Все страницы"
@@ -525,7 +524,6 @@
  :command.editor/select-parent                         "Выбрать родительский блок"
  :command.editor/zoom-in                               "Войти в редактируемый блок / Иначе вперёд"
  :command.editor/zoom-out                              "Выйти из редактируемого блока / Иначе назад"
- :command.editor/toggle-undo-redo-mode                 "Переключить режим Отменить/Повторить (глобально или только на странице)"
  :command.editor/toggle-number-list                    "Переключить формат нумерованного списка"
  :command.whiteboard/select                            "Инструмент 'Выделение'"
  :command.whiteboard/pan                               "Инструмент 'Рука'"

+ 0 - 6
src/resources/dicts/sk.edn

@@ -128,11 +128,6 @@
  :right-side-bar/switch-theme                      "Motívy"
  :right-side-bar/contents                          "Obsah"
  :right-side-bar/page-graph                        "Graf stránok"
- :right-side-bar/history                           "(Dev) Historia Späť/Znova"
- :right-side-bar/history-undos                     "Späť"
- :right-side-bar/history-redos                     "Znova"
- :right-side-bar/history-global                    "globálny"
- :right-side-bar/history-pageonly                  "len stránka"
  :right-side-bar/block-ref                         "Referencie bloku"
  :right-side-bar/graph-view                        "Zobrazenie grafu"
  :right-side-bar/all-pages                         "Všetky stránky"
@@ -681,7 +676,6 @@
  :command.editor/select-parent                     "Vybrať rodičovský blok"
  :command.editor/zoom-in                           "Priblížiť upravovaný blok/Inak vpred"
  :command.editor/zoom-out                          "Oddialiť upravaný blok/Inak dozadu"
- :command.editor/toggle-undo-redo-mode             "Prepnúť režim undo/redo (globálny alebo len na stránke)"
  :command.editor/toggle-number-list                "Prepnúť číslovaný zoznam"
  :command.whiteboard/select                        "Nástroj výberu"
  :command.whiteboard/pan                           "Nástroj posunu"

+ 0 - 6
src/resources/dicts/tr.edn

@@ -132,11 +132,6 @@
  :right-side-bar/switch-theme "Tema modları"
  :right-side-bar/contents "İçindekiler"
  :right-side-bar/page-graph "Sayfa grafı"
- :right-side-bar/history "(Dev) Geri Al / Yinele geçmişi"
- :right-side-bar/history-undos "Geri Alınanlar"
- :right-side-bar/history-redos "Yinelenenler"
- :right-side-bar/history-global "genel"
- :right-side-bar/history-pageonly "yalnızca sayfa"
  :right-side-bar/block-ref "Blok referansı"
  :right-side-bar/graph-view "Graf görünümü"
  :right-side-bar/all-pages "Bütün sayfalar"
@@ -712,7 +707,6 @@
  :command.editor/select-all-blocks       "Tüm blokları seç"
  :command.editor/zoom-in                 "Düzenlenen bloğu yakınlaştır / Aksi takdirde ileri git"
  :command.editor/zoom-out                "Düzenlenen bloğu uzaklaştır / Aksi takdirde geri git"
- :command.editor/toggle-undo-redo-mode   "Geri alma / yineleme modunu değiştir (yalnızca sayfa veya genel)"
  :command.editor/toggle-number-list      "Numaralı liste olarak değiştir"
  :command.whiteboard/select              "Seçim aracı"
  :command.whiteboard/pan                 "Kaydırma aracı"

+ 0 - 2
src/resources/dicts/uk.edn

@@ -52,7 +52,6 @@
  :right-side-bar/switch-theme "Режим теми"
  :right-side-bar/contents "Зміст"
  :right-side-bar/page-graph "Графік сторінки"
- :right-side-bar/history "(Dev) Скасувати/Повторити історію"
  :right-side-bar/block-ref "Посилання на блоки"
  :right-side-bar/graph-view "Вигляд графіка"
  :right-side-bar/all-pages "Всі сторінки"
@@ -388,7 +387,6 @@
  :command.editor/select-parent                             "Вибрати батьківський блок"
  :command.editor/zoom-in                                   "Збільшити"
  :command.editor/zoom-out                                  "Зменшити"
- :command.editor/toggle-undo-redo-mode                     "Переключити режим скасування/повтору (глобально чи лише на сторінці)"
  :command.editor/toggle-number-list                        "Переключити номерний список"
  :command.whiteboard/select                                "Вибрати інструмент"
  :command.whiteboard/pan                                   "Прокрутка"

+ 0 - 5
src/resources/dicts/zh-cn.edn

@@ -116,11 +116,6 @@
  :right-side-bar/new-page "新页面"
  :right-side-bar/separator "调整右侧边栏大小"
  :right-side-bar/whiteboards "白板"
- :right-side-bar/history "(开发人员工具) 撤销/重做 历史"
- :right-side-bar/history-undos "撤销"
- :right-side-bar/history-redos "重做"
- :right-side-bar/history-global "全局"
- :right-side-bar/history-pageonly "仅当前页"
  :left-side-bar/switch "切换到:"
  :left-side-bar/journals "日志"
  :left-side-bar/new-page "新页面"

+ 35 - 20
src/test/frontend/test/generators.cljs

@@ -5,26 +5,41 @@
 
 
 (defn gen-available-block-uuid
-  [db]
-  (gen/elements
-   (->> (d/q '[:find ?block-uuid
-               :where
-               [?block :block/parent]
-               [?block :block/left]
-               [?block :block/uuid ?block-uuid]]
-             db)
-        (apply concat))))
-
+  [db & {:keys [page-uuid]}]
+  (let [query (cond-> '[:find ?block-uuid]
+                page-uuid
+                (concat '[:in $ ?page-uuid])
+                true
+                (concat '[:where
+                          [?block :block/parent]
+                          [?block :block/left]
+                          [?block :block/uuid ?block-uuid]])
+                page-uuid
+                (concat '[[?block :block/page ?page]
+                          [?page :block/uuid ?page-uuid]]))]
+    (gen/elements
+     (->> (if page-uuid
+            (d/q query db page-uuid)
+            (d/q query db))
+          (apply concat)))))
 
 (defn gen-available-parent-left-pair
   "generate [<parent-uuid> <left-uuid>]"
-  [db]
-  (gen/elements
-   (d/q '[:find ?parent-uuid ?left-uuid
-          :where
-          [?b :block/uuid]
-          [?b :block/parent ?parent]
-          [?b :block/left ?left]
-          [?parent :block/uuid ?parent-uuid]
-          [?left :block/uuid ?left-uuid]]
-        db)))
+  [db & {:keys [page-uuid]}]
+  (let [query (cond-> '[:find ?parent-uuid ?left-uuid]
+                page-uuid
+                (concat '[:in $ ?page-uuid])
+                true
+                (concat '[:where
+                          [?b :block/uuid]
+                          [?b :block/parent ?parent]
+                          [?b :block/left ?left]
+                          [?parent :block/uuid ?parent-uuid]
+                          [?left :block/uuid ?left-uuid]])
+                page-uuid
+                (concat '[[?b :block/page ?page]
+                          [?page :block/uuid ?page-uuid]]))]
+    (gen/elements
+     (if page-uuid
+       (d/q query db page-uuid)
+       (d/q query db)))))

+ 2 - 2
src/test/frontend/test/helper.cljs

@@ -210,8 +210,8 @@ This can be called in synchronous contexts as no async fns should be invoked"
      {:re-render? false :verbose false :refresh? true})))
 
 (defn initial-test-page-and-blocks
-  []
-  (let [page-uuid (random-uuid)
+  [& {:keys [page-uuid]}]
+  (let [page-uuid (or page-uuid (random-uuid))
         first-block-uuid (random-uuid)
         second-block-uuid (random-uuid)
         page-id [:block/uuid page-uuid]]

+ 15 - 11
src/test/frontend/worker/undo_redo_test.cljs

@@ -7,7 +7,9 @@
             [frontend.test.helper :as test-helper]
             [frontend.worker.undo-redo :as undo-redo]))
 
-(def ^:private init-data (test-helper/initial-test-page-and-blocks))
+(def ^:private page-uuid (random-uuid))
+(def ^:private init-data (test-helper/initial-test-page-and-blocks {:page-uuid page-uuid}))
+
 (defn- start-and-destroy-db
   [f]
   (test-helper/db-based-start-and-destroy-db
@@ -20,11 +22,13 @@
 
 (defn- gen-block-uuid
   [db & {:keys [non-exist-frequency] :or {non-exist-frequency 1}}]
-  (gen/frequency [[9 (t.gen/gen-available-block-uuid db)] [non-exist-frequency gen-non-exist-block-uuid]]))
+  (gen/frequency [[9 (t.gen/gen-available-block-uuid db {:page-uuid page-uuid})]
+                  [non-exist-frequency gen-non-exist-block-uuid]]))
 
 (defn- gen-parent-left-pair
   [db]
-  (gen/frequency [[9 (t.gen/gen-available-parent-left-pair db)] [1 (gen/vector gen-non-exist-block-uuid 2)]]))
+  (gen/frequency [[9 (t.gen/gen-available-parent-left-pair db {:page-uuid page-uuid})]
+                  [1 (gen/vector gen-non-exist-block-uuid 2)]]))
 
 (defn- gen-move-block-op
   [db]
@@ -43,7 +47,7 @@
 
 (defn- gen-remove-block-op
   [db]
-  (gen/let [block-uuid (gen-block-uuid db {:non-exist-frequency 80})
+  (gen/let [block-uuid (gen-block-uuid db {:non-exist-frequency 90})
             [parent left] (gen-parent-left-pair db)
             content gen/string-alphanumeric]
     [:frontend.worker.undo-redo/remove-block
@@ -116,7 +120,7 @@
   [conn]
   (binding [undo-redo/*undo-redo-info-for-test* (atom nil)]
     (loop [i 0]
-      (let [r (undo-redo/undo test-helper/test-db-name-db-version conn)
+      (let [r (undo-redo/undo test-helper/test-db-name-db-version page-uuid conn)
             current-db @conn]
         (check-block-count @undo-redo/*undo-redo-info-for-test* current-db)
         (if (not= :frontend.worker.undo-redo/empty-undo-stack r)
@@ -124,7 +128,7 @@
           (prn :undo-count i))))
 
     (loop []
-      (let [r (undo-redo/redo test-helper/test-db-name-db-version conn)
+      (let [r (undo-redo/redo test-helper/test-db-name-db-version page-uuid conn)
             current-db @conn]
         (check-block-count @undo-redo/*undo-redo-info-for-test* current-db)
         (when (not= :frontend.worker.undo-redo/empty-redo-stack r)
@@ -132,12 +136,12 @@
 
 (deftest undo-redo-gen-test
   (let [conn (db/get-db false)
-        all-remove-ops (gen/generate (gen/vector (gen-op @conn {:remove-block-op 1000}) 20))]
-    (#'undo-redo/push-undo-ops test-helper/test-db-name-db-version all-remove-ops)
+        all-remove-ops (gen/generate (gen/vector (gen-op @conn {:remove-block-op 1000}) 100))]
+    (#'undo-redo/push-undo-ops test-helper/test-db-name-db-version page-uuid all-remove-ops)
     (prn :block-count-before-init (count (get-db-block-set @conn)))
     (loop [i 0]
       (when (not= :frontend.worker.undo-redo/empty-undo-stack
-                  (undo-redo/undo test-helper/test-db-name-db-version conn))
+                  (undo-redo/undo test-helper/test-db-name-db-version page-uuid conn))
         (recur (inc i))))
     (prn :block-count (count (get-db-block-set @conn)))
     (undo-redo/clear-undo-redo-stack)
@@ -145,7 +149,7 @@
       (let [origin-graph-block-set (get-db-block-set @conn)
             ops (gen/generate (gen/vector (gen-op @conn {:move-block-op 1000 :boundary-op 500}) 300))]
         (prn :ops (count ops))
-        (#'undo-redo/push-undo-ops test-helper/test-db-name-db-version ops)
+        (#'undo-redo/push-undo-ops test-helper/test-db-name-db-version page-uuid ops)
 
         (undo-all-then-redo-all conn)
         (undo-all-then-redo-all conn)
@@ -157,7 +161,7 @@
       (let [origin-graph-block-set (get-db-block-set @conn)
             ops (gen/generate (gen/vector (gen-op @conn) 1000))]
         (prn :ops (count ops))
-        (#'undo-redo/push-undo-ops test-helper/test-db-name-db-version ops)
+        (#'undo-redo/push-undo-ops test-helper/test-db-name-db-version page-uuid ops)
 
         (undo-all-then-redo-all conn)
         (undo-all-then-redo-all conn)