Browse Source

Remove state dependency for outliner.core

Tienson Qin 1 year ago
parent
commit
292ba1b0b6

+ 1 - 1
deps/outliner/src/logseq/outliner/tree.cljs

@@ -13,7 +13,7 @@
   (-get-left [this conn])
   (-get-right [this conn])
   (-get-down [this conn])
-  (-save [this db conn repo])
+  (-save [this db conn repo date-formatter])
   (-del [this db children? conn])
   (-get-children [this conn]))
 

+ 16 - 30
src/main/frontend/components/editor.cljs

@@ -122,7 +122,7 @@
     (page-handler/on-chosen-handler input id q pos format)))
 
 (rum/defc page-search-aux
-  [id format embed? db-tag? create-page? q current-pos edit-content input pos]
+  [id format embed? db-tag? q current-pos input pos]
   (let [[matched-pages set-matched-pages!] (rum/use-state nil)]
     (rum/use-effect! (fn []
                        (when-not (string/blank? q)
@@ -158,29 +158,19 @@
                               (cons (first matched-pages)
                                     (cons q (rest matched-pages)))
                               (cons q matched-pages))))]
-      [:div
-       (when (and db-tag?
-                        ;; Don't display in heading
-                  (not (some->> edit-content (re-find #"^\s*#"))))
-         [:div.flex.flex-row.items-center.px-4.py-1.text-sm.opacity-70.gap-2
-          "Turn this block into a page:"
-          (ui/toggle create-page?
-                     (fn [_e]
-                       (swap! (:editor/create-page? @state/state) not))
-                     true)])
-       (ui/auto-complete
-        matched-pages
-        {:on-chosen   (page-on-chosen-handler embed? input id q pos format)
-         :on-enter    (fn []
-                        (page-handler/page-not-exists-handler input id q current-pos))
-         :item-render (fn [page-name _chosen?]
-                        [:div.flex
-                         (when (db-model/whiteboard-page? page-name) [:span.mr-1 (ui/icon "whiteboard" {:extension? true})])
-                         (search-handler/highlight-exact-query page-name q)])
-         :empty-placeholder [:div.text-gray-500.text-sm.px-4.py-2 (if db-tag?
-                                                                    "Search for a page or a class"
-                                                                    "Search for a page")]
-         :class       "black"})])))
+      (ui/auto-complete
+       matched-pages
+       {:on-chosen   (page-on-chosen-handler embed? input id q pos format)
+        :on-enter    (fn []
+                       (page-handler/page-not-exists-handler input id q current-pos))
+        :item-render (fn [page-name _chosen?]
+                       [:div.flex
+                        (when (db-model/whiteboard-page? page-name) [:span.mr-1 (ui/icon "whiteboard" {:extension? true})])
+                        (search-handler/highlight-exact-query page-name q)])
+        :empty-placeholder [:div.text-gray-500.text-sm.px-4.py-2 (if db-tag?
+                                                                   "Search for a page or a class"
+                                                                   "Search for a page")]
+        :class       "black"}))))
 
 (rum/defc page-search < rum/reactive
   {:will-unmount (fn [state]
@@ -192,8 +182,7 @@
         db? (config/db-based-graph? (state/get-current-repo))
         embed? (and db? (= @commands/*current-command "Page embed"))
         tag? (= action :page-search-hashtag)
-        db-tag? (and db? tag?)
-        create-page? (state/sub :editor/create-page?)]
+        db-tag? (and db? tag?)]
     (when (contains? #{:page-search :page-search-hashtag} action)
       (let [pos (state/get-editor-last-pos)
             input (gdom/getElement id)]
@@ -207,7 +196,7 @@
                    (when (> (count edit-content) current-pos)
                      (gp-util/safe-subs edit-content pos current-pos))
                    "")]
-            (page-search-aux id format embed? db-tag? create-page? q current-pos edit-content input pos)))))))
+            (page-search-aux id format embed? db-tag? q current-pos input pos)))))))
 
 (defn- search-blocks!
   [state result]
@@ -722,9 +711,6 @@
   {:init (fn [state]
            (assoc state
                   ::id (str (random-uuid))))
-   :will-unmount (fn [state]
-                   (reset! (:editor/create-page? @state/state) false)
-                   state)
    :did-mount (fn [state]
                 (state/set-editor-args! (:rum/args state))
                 state)}

+ 4 - 2
src/main/frontend/db/rtc/core.cljs

@@ -88,7 +88,9 @@
 (defmethod transact-db! :delete-blocks [_ & args]
   (outliner-tx/transact!
    {:persist-op? false}
-   (apply outliner-core/delete-blocks! (state/get-current-repo) (db/get-db false) args)))
+   (apply outliner-core/delete-blocks! (state/get-current-repo) (db/get-db false)
+     (state/get-date-formatter)
+     args)))
 
 (defmethod transact-db! :move-blocks [_ & args]
   (outliner-tx/transact!
@@ -103,7 +105,7 @@
 (defmethod transact-db! :save-block [_ & args]
   (outliner-tx/transact!
    {:persist-op? false}
-   (apply outliner-core/save-block! (state/get-current-repo) (db/get-db false) args)))
+   (apply outliner-core/save-block! (state/get-current-repo) (db/get-db false) (state/get-date-formatter) args)))
 
 (defmethod transact-db! :delete-whiteboard-blocks [_ repo block-uuids]
   (db/transact! repo

+ 12 - 10
src/main/frontend/handler/block.cljs

@@ -305,15 +305,16 @@
    (when-let [node (some-> (first (state/get-selection-blocks)))]
      (get-original-block-by-dom node))))
 
-(defn- get-last-block-original
-  [last-top-block]
-  (or
-   (get-current-editing-original-block)
-   (when-let [last-block-node (->> (state/get-selection-blocks)
-                                   (filter (fn [node]
-                                             (= (dom/attr node "blockid") (str (:block/uuid last-top-block)))))
-                                   last)]
-     (get-original-block-by-dom last-block-node))))
+(comment
+  (defn- get-last-block-original
+    [last-top-block]
+    (or
+     (get-current-editing-original-block)
+     (when-let [last-block-node (->> (state/get-selection-blocks)
+                                     (filter (fn [node]
+                                               (= (dom/attr node "blockid") (str (:block/uuid last-top-block)))))
+                                     last)]
+       (get-original-block-by-dom last-block-node)))))
 
 (defn indent-outdent-block!
   [block direction]
@@ -324,7 +325,8 @@
                                          (db/get-db false)
                                          (get-top-level-blocks [block])
                                          (= direction :right)
-                                         {:get-first-block-original get-first-block-original})))
+                                         {:get-first-block-original get-first-block-original
+                                          :logical-outdenting? (state/logical-outdenting?)})))
 
 (def *swipe (atom nil))
 

+ 1 - 1
src/main/frontend/handler/db_based/editor.cljs

@@ -153,5 +153,5 @@
   (ui-outliner-tx/transact!
    {:outliner-op :save-block}
    (doseq [block-tx (keep #(set-heading-aux! % heading) block-ids)]
-     (outliner-core/save-block! repo (db/get-db false) block-tx))
+     (outliner-core/save-block! repo (db/get-db false) (state/get-date-formatter) block-tx))
    (property-handler/batch-set-block-property! repo block-ids :heading heading)))

+ 11 - 5
src/main/frontend/handler/editor.cljs

@@ -79,7 +79,7 @@
   [block]
   (let [repo (state/get-current-repo)
         conn (db/get-db false)]
-    (outliner-core/save-block! repo conn block)))
+    (outliner-core/save-block! repo conn (state/get-date-formatter) block)))
 
 (defn get-block-own-order-list-type
   [block]
@@ -712,7 +712,9 @@
       (let [blocks (block-handler/get-top-level-blocks [block])]
         (ui-outliner-tx/transact!
          {:outliner-op :delete-blocks}
-         (outliner-core/delete-blocks! repo (db/get-db false) blocks
+         (outliner-core/delete-blocks! repo (db/get-db false)
+                                       (state/get-date-formatter)
+                                       blocks
                                        (merge
                                         delete-opts
                                         {:children? children?})))))))
@@ -875,7 +877,9 @@
           blocks' (block-handler/get-top-level-blocks blocks)]
       (ui-outliner-tx/transact!
        {:outliner-op :delete-blocks}
-       (outliner-core/delete-blocks! repo (db/get-db false) blocks' {}))
+       (outliner-core/delete-blocks! repo (db/get-db false)
+                                     (state/get-date-formatter)
+                                     blocks' {}))
       (when sibling-block
         (move-to-prev-block repo sibling-block
                             (:block/format block)
@@ -1804,7 +1808,8 @@
                                              (db/get-db false)
                                              (block-handler/get-top-level-blocks blocks)
                                              (= direction :right)
-                                             {:get-first-block-original block-handler/get-first-block-original})))))
+                                             {:get-first-block-original block-handler/get-first-block-original
+                                              :logical-outdenting? (state/logical-outdenting?)})))))
 
 (defn- get-link [format link label]
   (let [link (or link "")
@@ -2884,7 +2889,8 @@
                                              (db/get-db false)
                                              (block-handler/get-top-level-blocks [block])
                                              indent?
-                                             {:get-first-block-original block-handler/get-first-block-original})))
+                                             {:get-first-block-original block-handler/get-first-block-original
+                                              :logical-outdenting? (state/logical-outdenting?)})))
     (state/set-editor-op! :nil)))
 
 (defn keydown-tab-handler

+ 3 - 1
src/main/frontend/handler/file_based/editor.cljs

@@ -214,7 +214,9 @@
    {:outliner-op :save-block}
    (doseq [block-id block-ids]
      (when-let [block (set-heading-aux! block-id heading)]
-       (outliner-core/save-block! (state/get-current-repo) (db/get-db false) block)))))
+       (outliner-core/save-block! (state/get-current-repo) (db/get-db false)
+                                  (state/get-date-formatter)
+                                  block)))))
 
 (defn set-blocks-id!
   "Persist block uuid to file if the uuid is valid, and it's not persisted in file.

+ 3 - 1
src/main/frontend/handler/file_based/property.cljs

@@ -53,7 +53,9 @@
                         :block/properties-order property-ks
                         :block/properties-text-values properties-text-values
                         :block/content content}]
-             (outliner-core/save-block! (state/get-current-repo) (db/get-db false) block)))))))
+             (outliner-core/save-block! (state/get-current-repo) (db/get-db false)
+                                        (state/get-date-formatter)
+                                        block)))))))
   (let [block-id (ffirst col)
         block-id (if (string? block-id) (uuid block-id) block-id)
         input-pos (or (state/get-edit-pos) :max)]

+ 75 - 97
src/main/frontend/modules/outliner/core.cljs

@@ -11,15 +11,11 @@
             [cljs.spec.alpha :as s]
             [logseq.db :as ldb]
             [frontend.worker.mldoc :as mldoc]
-            [logseq.graph-parser.block :as gp-block]
             [frontend.worker.file.property-util :as wpu]
             [logseq.db.frontend.property :as db-property]
             [logseq.db.sqlite.util :as sqlite-util]
             [cljs.pprint :as pprint]
-            [frontend.worker.util :as util]
-
-            [frontend.state :as state]
-            ))
+            [frontend.worker.util :as util]))
 
 (s/def ::block-map (s/keys :opt [:db/id :block/uuid :block/page :block/left :block/parent]))
 
@@ -149,42 +145,43 @@
                                            (vector :db.fn/retractEntity (:db/id %)))
                                         (:block/macros block-entity)))))))
 
-(defn- create-linked-page-when-save
-  [repo conn db date-formatter txs-state block-entity m tags-has-class?]
-  (if tags-has-class?
-    (let [content (state/get-edit-content)
-          linked-page (some-> content #(mldoc/extract-plain repo %))
-          sanity-linked-page (some-> linked-page util/page-name-sanity-lc)
-          linking-page? (and (not (string/blank? sanity-linked-page))
-                             @(:editor/create-page? @state/state))]
-      (when linking-page?
-        (let [existing-ref-id (some (fn [r]
-                                      (when (= sanity-linked-page (:block/name r))
-                                        (:block/uuid r)))
-                                    (:block/refs m))
-              page-m (gp-block/page-name->map linked-page (or existing-ref-id true)
-                                              db true date-formatter)
-              _ (when-not (d/entity db [:block/uuid (:block/uuid page-m)])
-                  (d/transact! conn [page-m]))
-              merge-tx (let [children (:block/_parent block-entity)
-                             page (d/entity db [:block/uuid (:block/uuid page-m)])
-                             [target sibling?] (get-last-child-or-self db page)]
-                         (when (seq children)
-                           (:tx-data
-                            (move-blocks repo conn children target
-                                         {:sibling? sibling?
-                                          :outliner-op :move-blocks}))))]
-          (swap! txs-state (fn [txs]
-                             (concat txs
-                                     [(assoc page-m
-                                             :block/tags (:block/tags m)
-                                             :block/format :markdown)
-                                      {:db/id (:db/id block-entity)
-                                       :block/content ""
-                                       :block/refs []
-                                       :block/link [:block/uuid (:block/uuid page-m)]}]
-                                     merge-tx))))))
-    (reset! (:editor/create-page? @state/state) false)))
+(comment
+  (defn- create-linked-page-when-save
+   [repo conn db date-formatter txs-state block-entity m tags-has-class?]
+   (if tags-has-class?
+     (let [content (state/get-edit-content)
+           linked-page (some-> content #(mldoc/extract-plain repo %))
+           sanity-linked-page (some-> linked-page util/page-name-sanity-lc)
+           linking-page? (and (not (string/blank? sanity-linked-page))
+                              @(:editor/create-page? @state/state))]
+       (when linking-page?
+         (let [existing-ref-id (some (fn [r]
+                                       (when (= sanity-linked-page (:block/name r))
+                                         (:block/uuid r)))
+                                     (:block/refs m))
+               page-m (gp-block/page-name->map linked-page (or existing-ref-id true)
+                                               db true date-formatter)
+               _ (when-not (d/entity db [:block/uuid (:block/uuid page-m)])
+                   (d/transact! conn [page-m]))
+               merge-tx (let [children (:block/_parent block-entity)
+                              page (d/entity db [:block/uuid (:block/uuid page-m)])
+                              [target sibling?] (get-last-child-or-self db page)]
+                          (when (seq children)
+                            (:tx-data
+                             (move-blocks repo conn children target
+                                          {:sibling? sibling?
+                                           :outliner-op :move-blocks}))))]
+           (swap! txs-state (fn [txs]
+                              (concat txs
+                                      [(assoc page-m
+                                              :block/tags (:block/tags m)
+                                              :block/format :markdown)
+                                       {:db/id (:db/id block-entity)
+                                        :block/content ""
+                                        :block/refs []
+                                        :block/link [:block/uuid (:block/uuid page-m)]}]
+                                      merge-tx))))))
+     (reset! (:editor/create-page? @state/state) false))))
 
 (defn rebuild-block-refs
   [repo conn db date-formatter block new-properties & {:keys [skip-content-parsing?]}]
@@ -293,7 +290,7 @@
     (let [parent-id (otree/-get-id this conn)]
       (get-by-parent-&-left @conn parent-id parent-id)))
 
-  (-save [this txs-state conn repo]
+  (-save [this txs-state conn repo date-formatter]
     (assert (ds/outliner-txs-state? txs-state)
             "db should be satisfied outliner-tx-state?")
     (let [data (:data this)
@@ -307,16 +304,11 @@
                 block-with-updated-at
                 fix-tag-ids)
           db @conn
-          date-formatter (state/get-date-formatter)
           db-based? (sqlite-util/db-based-graph? repo)
           db-id (:db/id (:data this))
           block-uuid (:block/uuid (:data this))
           eid (or db-id (when block-uuid [:block/uuid block-uuid]))
-          block-entity (d/entity db eid)
-          tags-has-class? (and db-based?
-                               (some (fn [tag]
-                                       (contains? (:block/type (d/entity db [:block/uuid (:block/uuid tag)])) "class"))
-                                     (:block/tags m)))]
+          block-entity (d/entity db eid)]
 
       ;; Ensure block UUID never changes
       (when (and db-id block-uuid)
@@ -353,8 +345,6 @@
         (swap! txs-state conj
                (dissoc m :db/other-tx)))
 
-      (create-linked-page-when-save repo conn db (state/get-date-formatter) txs-state block-entity m tags-has-class?)
-
       (rebuild-refs repo conn db date-formatter txs-state block-entity m)
 
       this))
@@ -539,10 +529,10 @@
 
 (defn save-block
   "Save the `block`."
-  [repo conn block']
+  [repo conn date-formatter block']
   {:pre [(map? block')]}
   (let [txs-state (atom [])]
-    (otree/-save (block @conn block') txs-state conn repo)
+    (otree/-save (block @conn block') txs-state conn repo date-formatter)
     {:tx-data @txs-state}))
 
 (defn- get-right-siblings
@@ -769,38 +759,25 @@
                      :keep-uuid? keep-uuid?
                      :move? move?
                      :outliner-op outliner-op}
-        tx (insert-blocks-aux blocks' target-block' insert-opts)]
-    (if (some (fn [b] (or (nil? (:block/parent b)) (nil? (:block/left b)))) tx)
-      (do
-        (state/pub-event! [:capture-error {:error "Outliner invalid structure"
-                                           :payload {:type :outliner/invalid-structure
-                                                     :opt opts
-                                                     :data (mapv #(dissoc % :block/content) tx)}}])
-        (throw (ex-info "Invalid outliner data"
-                        {:opts insert-opts
-                         :tx (vec tx)
-                         :blocks (vec blocks)
-                         :target-block target-block'})))
-      (let [uuids-tx (->> (map :block/uuid tx)
-                          (remove nil?)
-                          (map (fn [uuid] {:block/uuid uuid})))
-            tx (if move?
-                 tx
-                 (assign-temp-id tx replace-empty-target? target-block'))
-            target-node (block @conn target-block')
-            next (if sibling?
-                   (otree/-get-right target-node conn)
-                   (otree/-get-down target-node conn))
-            next-tx (when (and next
-                               (if move? (not (contains? (set (map :db/id blocks)) (:db/id (:data next)))) true))
-                      (when-let [left (last (filter (fn [b] (= 1 (:block/level b))) tx))]
-                        [{:block/uuid (otree/-get-id next conn)
-                          :block/left (:db/id left)}]))
-            full-tx (util/concat-without-nil (if (and keep-uuid? replace-empty-target?) (rest uuids-tx) uuids-tx) tx next-tx)]
-        (when (and replace-empty-target? (state/editing?))
-          (state/set-edit-content! (state/get-edit-input-id) (:block/content (first blocks))))
-        {:tx-data full-tx
-         :blocks  tx}))))
+        tx' (insert-blocks-aux blocks' target-block' insert-opts)
+        uuids-tx (->> (map :block/uuid tx')
+                      (remove nil?)
+                      (map (fn [uuid] {:block/uuid uuid})))
+        tx (if move?
+             tx'
+             (assign-temp-id tx' replace-empty-target? target-block'))
+        target-node (block @conn target-block')
+        next (if sibling?
+               (otree/-get-right target-node conn)
+               (otree/-get-down target-node conn))
+        next-tx (when (and next
+                           (if move? (not (contains? (set (map :db/id blocks)) (:db/id (:data next)))) true))
+                  (when-let [left (last (filter (fn [b] (= 1 (:block/level b))) tx))]
+                    [{:block/uuid (otree/-get-id next conn)
+                      :block/left (:db/id left)}]))
+        full-tx (util/concat-without-nil (if (and keep-uuid? replace-empty-target?) (rest uuids-tx) uuids-tx) tx next-tx)]
+    {:tx-data full-tx
+     :blocks  tx}))
 
 (defn- build-move-blocks-next-tx
   [db target-block blocks {:keys [sibling? _non-consecutive-blocks?]}]
@@ -852,7 +829,7 @@
 
 (defn delete-block
   "Delete block from the tree."
-  [repo conn txs-state node {:keys [children? children-check?]
+  [repo conn txs-state node {:keys [children? children-check? date-formatter]
                         :or {children-check? true}}]
   (if (and children-check?
            (not children?)
@@ -864,16 +841,16 @@
       (when (otree/satisfied-inode? right-node)
         (let [left-node (otree/-get-left node conn)
               new-right-node (otree/-set-left-id right-node (otree/-get-id left-node conn) conn)]
-          (otree/-save new-right-node txs-state conn repo)))
+          (otree/-save new-right-node txs-state conn repo date-formatter)))
       @txs-state)))
 
 (defn- delete-blocks
   "Delete blocks from the tree.
    Args:
     `children?`: whether to replace `blocks'` children too. "
-  [repo conn blocks {:keys [children?]
-                     :or {children? true}
-                     :as delete-opts}]
+  [repo conn date-formatter blocks {:keys [children?]
+                                    :or {children? true}
+                                    :as delete-opts}]
   [:pre [(seq blocks)]]
   (let [txs-state (ds/new-outliner-txs-state)
         block-ids (map (fn [b] [:block/uuid (:block/uuid b)]) blocks)
@@ -893,7 +870,8 @@
          (= 1 (count blocks))
          (= start-node end-node)
          self-block?)
-      (delete-block repo conn txs-state start-node (assoc delete-opts :children? children?))
+      (delete-block repo conn txs-state start-node (assoc delete-opts :children? children?
+                                                          :date-formatter date-formatter))
       (let [sibling? (= (otree/-get-parent-id start-node conn)
                         (otree/-get-parent-id end-node conn))
             right-node (otree/-get-right end-node conn)]
@@ -922,7 +900,7 @@
                                     :right-node (d/entity @conn [:block/uuid (otree/-get-id right-node conn)])}))))
             (when left-node-id
               (let [new-right-node (otree/-set-left-id right-node left-node-id conn)]
-                (otree/-save new-right-node txs-state conn repo)))))
+                (otree/-save new-right-node txs-state conn repo date-formatter)))))
         (doseq [id block-ids]
           (let [node (block @conn (d/entity @conn id))]
             (otree/-del node txs-state true conn)))
@@ -1020,7 +998,7 @@
 
 (defn indent-outdent-blocks
   "Indent or outdent `blocks`."
-  [repo conn blocks indent? & {:keys [get-first-block-original]}]
+  [repo conn blocks indent? & {:keys [get-first-block-original logical-outdenting?]}]
   {:pre [(seq blocks) (boolean? indent?)]}
   (let [db @conn
         top-level-blocks blocks
@@ -1069,7 +1047,7 @@
                                                  (:db/id (:block/parent parent))))
                                          top-level-blocks)
                      result (move-blocks repo conn blocks' parent (merge opts {:sibling? true}))]
-                 (if (state/logical-outdenting?)
+                 (if logical-outdenting?
                    result
                   ;; direct outdenting (default behavior)
                    (let [last-top-block (d/entity db (:db/id (last blocks')))
@@ -1108,16 +1086,16 @@
     result))
 
 (defn save-block!
-  [repo conn block]
-  (op-transact! #'save-block repo conn block))
+  [repo conn date-formatter block]
+  (op-transact! #'save-block repo conn date-formatter block))
 
 (defn insert-blocks!
   [repo conn blocks target-block opts]
   (op-transact! #'insert-blocks repo conn blocks target-block (assoc opts :outliner-op :insert-blocks)))
 
 (defn delete-blocks!
-  [repo conn blocks opts]
-  (op-transact! #'delete-blocks repo conn blocks (assoc opts :outliner-op :delete-blocks)))
+  [repo conn date-formatter blocks opts]
+  (op-transact! #'delete-blocks repo conn date-formatter blocks (assoc opts :outliner-op :delete-blocks)))
 
 (defn move-blocks!
   [repo conn blocks target-block sibling?]

+ 4 - 3
src/main/frontend/modules/outliner/pipeline.cljs

@@ -27,11 +27,12 @@
                                 (->> db-content
                                      (property-util/remove-built-in-properties (or (:block/format entity) :markdown))
                                      drawer/remove-logbook))
-                    pos (cursor/pos input)]
+                    pos (cursor/pos input)
+                    pos (when pos (if (zero? pos) (count content) 0))]
                 (when (not= (string/trim content)
                             (string/trim (.-value input)))
-                  (state/set-edit-content! input content)
-                  (when pos (cursor/move-cursor-to input pos)))))))))))
+                  (state/set-edit-content! input content))
+                (when pos (cursor/move-cursor-to input pos))))))))))
 
 (defn store-undo-data!
   [{:keys [tx-meta] :as opts}]

+ 0 - 2
src/main/frontend/modules/shortcut/config.cljs

@@ -179,8 +179,6 @@
 
    :auto-complete/meta-complete             {:binding "mod+enter"
                                              :fn      (fn [state e]
-                                                        (when (= :page-search-hashtag (state/get-editor-action))
-                                                          (reset! (:editor/create-page? @state/state) true))
                                                         (ui-handler/auto-complete-complete state e))}
 
    :auto-complete/open-link                 {:binding "mod+o"

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

@@ -151,8 +151,6 @@
 
       :editor/code-block-context             {}
 
-      :editor/create-page?                   (atom false)
-
       :db/properties-changed-pages           {}
       :editor/cursor-range                   (atom nil)
 

+ 13 - 15
src/main/frontend/worker/db/fix.cljs

@@ -4,9 +4,10 @@
   1. Each block should has a unique [:block/parent :block/left] position.
   2. For any block, its children should be connected by :block/left (no broken chain, no circle, no left to self)."
   (:require [datascript.core :as d]
-            [frontend.util :as util]
+            [cljs.pprint :as pprint]
             [frontend.handler.notification :as notification]
-            [logseq.db :as ldb]))
+            [logseq.db :as ldb]
+            [frontend.worker.util :as util]))
 
 (defn- fix-parent-broken-chain
   [db parent-id]
@@ -26,12 +27,11 @@
                                                :block/content (:block/content b)
                                                :block/left (:db/id (:block/left b))}) blocks)}]
             (prn :debug "Broken chain:")
-            (util/pprint error-data)
-            (notification/show!
-             [:div
-              (str "Broken chain detected:\n" error-data)]
-             :error
-             false))
+            (pprint/pprint error-data)
+            (util/post-message :notification
+                               (pr-str [[:div
+                                         (str "Broken chain detected:\n" error-data)]
+                                        :error])))
           (let [first-child-id (:db/id (ldb/get-by-parent-&-left db parent-id parent-id))
                 *ids (atom children-ids)
                 sections (loop [sections []]
@@ -112,12 +112,10 @@
   [db conflicts]
   (when (seq conflicts)
     (prn :debug "Parent left id conflicts:")
-    (notification/show!
-     [:div
-      (str "Parent-left conflicts detected:\n"
-           conflicts)]
-     :error
-     false))
+    (util/post-message :notification (pr-str [[:div
+                                               (str "Parent-left conflicts detected:\n"
+                                                    conflicts)]
+                                              :error])))
   (mapcat
    (fn [[_parent-left blocks]]
      (let [items (sort-by :block/created-at blocks)
@@ -147,7 +145,7 @@
                            (fix-parent-left-conflicts db conflicts))]
     (when (seq fix-conflicts-tx)
       (prn :debug :conflicts-tx)
-      (util/pprint fix-conflicts-tx)
+      (pprint/pprint fix-conflicts-tx)
       (let [tx-data (:tx-data (d/transact! conn fix-conflicts-tx transact-opts))]
         (swap! *fix-tx-data (fn [old-data] (concat old-data tx-data))))
       (when (seq (get-conflicts @conn page-id))

+ 22 - 7
src/test/frontend/modules/outliner/core_test.cljs

@@ -125,7 +125,10 @@
     (transact-tree! tree)
     (let [block (get-block 6)]
       (outliner-tx/transact! {:graph test-db}
-                             (outliner-core/delete-blocks! test-db (db/get-db test-db false) [block] {:children? true}))
+                             (outliner-core/delete-blocks! test-db
+                                                           (db/get-db test-db false)
+                                                           (state/get-date-formatter)
+                                                           [block] {:children? true}))
       (is (= [3 9] (get-children 2))))))
 
 (deftest test-move-block-as-sibling
@@ -294,7 +297,9 @@
     (transact-tree! tree)
     (outliner-tx/transact!
       {:graph test-db}
-      (outliner-core/delete-blocks! test-db (db/get-db test-db false) [(get-block 6) (get-block 9)] {}))
+      (outliner-core/delete-blocks! test-db (db/get-db test-db false)
+                                    (state/get-date-formatter)
+                                    [(get-block 6) (get-block 9)] {}))
     (is (= [3] (get-children 2)))))
 
 (deftest test-delete-non-consecutive-blocks
@@ -313,7 +318,9 @@
     (transact-tree! tree)
     (outliner-tx/transact!
      {:graph test-db}
-      (outliner-core/delete-blocks! test-db (db/get-db test-db false) [(get-block 10) (get-block 13)] {}))
+     (outliner-core/delete-blocks! test-db (db/get-db test-db false)
+                                   (state/get-date-formatter)
+                                   [(get-block 10) (get-block 13)] {}))
     (is (= [11] (get-children 9)))
     (is (= [14 15] (get-children 12)))))
 
@@ -407,7 +414,9 @@
          (outliner-core/insert-blocks! test-db (db/get-db test-db false) new-blocks target-block {:sibling? false
                                                                                                   :keep-uuid? true
                                                                                                   :replace-empty-target? false})
-         (outliner-core/delete-blocks! test-db (db/get-db test-db false) [(get-block 3)] {}))
+         (outliner-core/delete-blocks! test-db (db/get-db test-db false)
+                                       (state/get-date-formatter)
+                                       [(get-block 3)] {}))
 
         (is (= [4] (get-children 2)))
 
@@ -478,7 +487,9 @@
 (defn- save-block!
   [block]
   (outliner-tx/transact! {:graph test-db}
-                         (outliner-core/save-block! test-db (db/get-db test-db false) block)))
+                         (outliner-core/save-block! test-db (db/get-db test-db false)
+                                                    (state/get-date-formatter)
+                                                    block)))
 
 (deftest save-test
   (load-test-files [{:file/path "pages/page1.md"
@@ -628,7 +639,9 @@ tags:: tag1, tag2
       (let [blocks (get-random-successive-blocks)]
         (when (seq blocks)
           (outliner-tx/transact! {:graph test-db}
-            (outliner-core/delete-blocks! test-db (db/get-db test-db false) blocks {})))))))
+                                 (outliner-core/delete-blocks! test-db (db/get-db test-db false)
+                                                               (state/get-date-formatter)
+                                                               blocks {})))))))
 
 (deftest ^:long random-moves
   (testing "Random moves"
@@ -705,7 +718,9 @@ tags:: tag1, tag2
                      (swap! *random-blocks (fn [old]
                                              (set/difference old (set (map :block/uuid blocks)))))
                      (outliner-tx/transact! {:graph test-db}
-                                            (outliner-core/delete-blocks! test-db (db/get-db test-db false) blocks {})))))
+                                            (outliner-core/delete-blocks! test-db (db/get-db test-db false)
+                                                                          (state/get-date-formatter)
+                                                                          blocks {})))))
 
                ;; move
                (fn []