Konstantinos Kaloutas преди 2 години
родител
ревизия
72277222d9
променени са 3 файла, в които са добавени 54 реда и са изтрити 3 реда
  1. 52 2
      src/main/frontend/components/right_sidebar.cljs
  2. 1 0
      src/main/frontend/dicts.cljc
  3. 1 1
      src/main/frontend/modules/editor/undo_redo.cljs

+ 52 - 2
src/main/frontend/components/right_sidebar.cljs

@@ -16,7 +16,9 @@
             [frontend.handler.ui :as ui-handler]
             [frontend.state :as state]
             [frontend.ui :as ui]
-            [frontend.util :as util]
+            [frontend.util :as util]            
+            [frontend.config :as config]
+            [frontend.modules.editor.undo-redo :as undo-redo]
             [goog.object :as gobj]
             [medley.core :as medley]
             [reitit.frontend.easy :as rfe]
@@ -66,6 +68,45 @@
      [:div.ml-2
       (block-cp repo idx block)]]))
 
+(rum/defc history-action-info
+  [[k v]]
+  (when v [:.ml-4 (ui/foldable
+                   [:div (str k)]
+                   [:.ml-4 (case k
+                             :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})]))
+
+(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})])
+
+(rum/defc history < rum/reactive
+  []
+  (let [state (undo-redo/get-state)]
+    [:div.ml-4
+     [:div.p-4 [:.ml-4.mb-2
+                (history-stack "Undos" (rum/react (:undo-stack state)))
+                (history-stack "Redos" (rum/react (:redo-stack state)))]]]))
+
 (defn build-sidebar-item
   [repo idx db-id block-type]
   (case block-type
@@ -80,6 +121,10 @@
     [(str (t :right-side-bar/page-graph))
      (page/page-graph)]
 
+    :history
+    [(str (t :right-side-bar/history))
+     (history)]
+
     :block-ref
     #_:clj-kondo/ignore
     (let [lookup (if (integer? db-id) db-id [:block/uuid db-id])]
@@ -281,7 +326,12 @@
         [:div.text-sm
          [:button.button.cp__right-sidebar-settings-btn {:on-click (fn [_e]
                                                          (state/sidebar-add-block! repo "help" :help))}
-          (t :right-side-bar/help)]]]
+          (t :right-side-bar/help)]]
+
+        (when config/dev? [: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)]])]
 
        (toggle)]
 

+ 1 - 0
src/main/frontend/dicts.cljc

@@ -65,6 +65,7 @@
         :right-side-bar/switch-theme "Theme modes"
         :right-side-bar/contents "Contents"
         :right-side-bar/page-graph "Page graph"
+        :right-side-bar/history "(Dev) Undo/Redo history"
         :right-side-bar/block-ref "Block references"
         :right-side-bar/graph-view "Graph view"
         :right-side-bar/all-pages "All pages"

+ 1 - 1
src/main/frontend/modules/editor/undo_redo.cljs

@@ -12,7 +12,7 @@
 (def ^:private undo-redo-states (atom {}))
 (def *pause-listener (atom false))
 
-(defn- get-state
+(defn get-state
   []
   (let [repo (state/get-current-repo)]
     (assert (string? repo) "Repo should satisfy string?")