Jelajahi Sumber

enhance: back to edit mode after setting a property

Except if the editing property is :default type
Tienson Qin 1 tahun lalu
induk
melakukan
d432bb1f71

+ 4 - 2
deps/shui/src/logseq/shui/dialog/core.cljs

@@ -39,7 +39,7 @@
               (if (vector? v) (assoc config k (interpret v)) config)))
     config ks))
 
-;; {:id :title :description :content :footer :open? ...}
+;; {:id :title :description :content :footer :open? :on-close ...}
 (def ^:private *modals (atom []))
 (def ^:private *id (atom 0))
 (def ^:private gen-id #(reset! *id (inc @*id)))
@@ -57,7 +57,9 @@
           config (if (nil? val)
                    (medley/dissoc-in config ks)
                    (assoc-in config ks val))]
-      (swap! *modals assoc index config))))
+      (swap! *modals assoc index config)
+      (when (and (false? (:open? config)) (fn? (:on-close config)))
+        ((:on-close config) id)))))
 
 (defn upsert-modal!
   [config]

+ 2 - 2
src/main/frontend/components/property/value.cljs

@@ -75,12 +75,12 @@
              value
              {:new-block-id new-block-id})]
     (p/do!
-     (shui/dialog-close!)
      (exit-edit-property)
      (let [block (db/entity [:block/uuid new-block-id])]
        (when edit-block?
          (editor-handler/edit-block! block :max {:container-id :unknown-container}))
-       block))))
+       block)
+     (shui/dialog-close!))))
 
 (defn <add-property!
   "If a class and in a class schema context, add the property to its schema.

+ 12 - 6
src/main/frontend/handler/events.cljs

@@ -960,16 +960,22 @@
 (defmethod handle :editor/new-property [[_ {:keys [block] :as opts}]]
   (p/do!
    (editor-handler/save-current-block!)
-   (let [edit-block (if-let [block (state/get-edit-block)]
-                      block
-                      (db/entity [:block/uuid (first (state/get-selection-block-ids))]))
+   (let [editing-block (state/get-edit-block)
+         pos (state/get-edit-pos)
+         edit-block-or-selected (or editing-block
+                                    (db/entity [:block/uuid (first (state/get-selection-block-ids))]))
          current-block (when-let [s (state/get-current-page)]
                          (when (util/uuid-string? s)
                            (db/entity [:block/uuid (uuid s)])))
-         in-block-container? (boolean edit-block)
-         block (or block edit-block current-block)]
+         in-block-container? (boolean edit-block-or-selected)
+         block (or block edit-block-or-selected current-block)]
      (shui/dialog-open! #(property-dialog/dialog block (assoc opts :in-block-container? in-block-container?))
-                        {:align "start"}))))
+                        {:id :property-dialog
+                         :align "start"
+                         :on-close (fn [_id]
+                                     (when-not (= (:db/id editing-block)
+                                                  (:db/id (state/get-edit-block)))
+                                       (editor-handler/edit-block! editing-block (or pos :max))))}))))
 
 (rum/defc multi-tabs-dialog
   []