Browse Source

enhance: auto focus on checkbox

Tienson Qin 1 year ago
parent
commit
9f405a8e83

+ 26 - 16
src/main/frontend/components/property.cljs

@@ -199,6 +199,10 @@
                    nil
                    add-class-property?
                    (shui/dialog-close!)
+                   (and block (= type :checkbox))
+                   (p/do!
+                    (shui/popup-hide-all!)
+                    (pv/<add-property! block (:db/ident property) false {:exit-edit? true}))
                    (and block (= type :default)
                         (not (seq (:property/closed-values property))))
                    (pv/<create-new-block! block property "")))))))}
@@ -454,22 +458,28 @@
         (let [add-class-property? (and (contains? (:block/type block) "class") class-schema?)
               type (get-in property [:block/schema :type])]
           (cond
-              add-class-property?
-              (p/do!
-               (pv/<add-property! block (:db/ident property) "" {:class-schema? class-schema?
-                                                                 :exit-edit? page-configure?})
-               (shui/dialog-close!))
-
-              (and (= :default type)
-                   (not (seq (:property/closed-values property))))
-              (p/do!
-               (pv/<create-new-block! block property "")
-               (shui/dialog-close!))
-
-              (or (not= :default type)
-                  (and (= :default type) (seq (:property/closed-values property))))
-              (p/do!
-               (reset! *show-new-property-config? false))))))))
+            add-class-property?
+            (p/do!
+             (pv/<add-property! block (:db/ident property) "" {:class-schema? class-schema?
+                                                               :exit-edit? page-configure?})
+             (shui/dialog-close!))
+
+            (= :checkbox type)
+            (p/do!
+             (shui/popup-hide-all!)
+             (shui/dialog-close!)
+             (pv/<add-property! block (:db/ident property) false {:exit-edit? true}))
+
+            (and (= :default type)
+                 (not (seq (:property/closed-values property))))
+            (p/do!
+             (pv/<create-new-block! block property "")
+             (shui/dialog-close!))
+
+            (or (not= :default type)
+                (and (= :default type) (seq (:property/closed-values property))))
+            (p/do!
+             (reset! *show-new-property-config? false))))))))
 
 (rum/defcs property-input < rum/reactive
   (rum/local nil ::ref)

+ 9 - 4
src/main/frontend/components/property/value.cljs

@@ -98,7 +98,8 @@
    (let [repo (state/get-current-repo)
          class? (contains? (:block/type block) "class")
          property (db/entity property-id)
-         many? (db-property/many? property)]
+         many? (db-property/many? property)
+         checkbox? (= :checkbox (get-in property [:block/schema :type]))]
      (assert (qualified-keyword? property-id) "property to add must be a keyword")
      (p/do!
       (if (and class? class-schema?)
@@ -110,9 +111,12 @@
       (when exit-edit?
         (shui/popup-hide-all!)
         (shui/dialog-close!))
-      (when-not many?
+      (when-not (or many? checkbox?)
         (when-let [input (state/get-input)]
-          (.focus input)))))))
+          (.focus input)))
+      (when checkbox?
+        (state/set-editor-action-data! {:type :focus-property-value
+                                        :property property}))))))
 
 (defn- add-or-remove-property-value
   [block property value selected?]
@@ -685,7 +689,8 @@
         schema (:block/schema property)
         type (get schema :type :default)
         editing? (or editing?
-                     (state/sub-editing? [container-id (:block/uuid block) (:block/uuid property)]))
+                     (and (state/sub-editing? [container-id (:block/uuid block)])
+                          (= (:db/id property) (:db/id (:property (state/get-editor-action-data))))))
         select-type? (select-type? property type)
         closed-values? (seq (:property/closed-values property))
         select-opts {:on-chosen on-chosen}