From 8e87913f1ff0db2658ff815cb1064c2b47d83285 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Wed, 9 Aug 2023 14:20:45 +0800 Subject: [PATCH] enhance(properties): Enter to create new value --- src/main/frontend/components/content.cljs | 2 +- src/main/frontend/components/property.cljs | 51 ++++++++++++++++------ 2 files changed, 39 insertions(+), 14 deletions(-) diff --git a/src/main/frontend/components/content.cljs b/src/main/frontend/components/content.cljs index a0d07e3714..69d4acbae3 100644 --- a/src/main/frontend/components/content.cljs +++ b/src/main/frontend/components/content.cljs @@ -372,7 +372,7 @@ (ui/menu-link {:key "Configure this property" :on-click (fn [] - (state/set-modal! #(property/property-config repo property)))} + (state/set-modal! #(property/property-config repo property {})))} (t :context-menu/configure-property) nil)) (ui/menu-link diff --git a/src/main/frontend/components/property.cljs b/src/main/frontend/components/property.cljs index 8b4d282296..3cef2359ae 100644 --- a/src/main/frontend/components/property.cljs +++ b/src/main/frontend/components/property.cljs @@ -314,20 +314,45 @@ [:div.h-6 (select-block block property select-opts)] (let [config {:editor-opts - {:on-key-down + {:on-blur (fn [e] - (when (and (contains? #{"Enter" "Escape"} (util/ekey e)) - (not (state/get-editor-action))) - (util/stop e) - (property-handler/set-block-property! repo (:block/uuid block) - (:block/original-name property) - (util/evalue e) - :old-value value) - (when editing-atom (reset! editing-atom false)) - (exit-edit-property)))}}] - [:div.pl-1 (editor-box editor-args editor-id (cond-> config - multiple-values? - (assoc :property-value value)))]))] + (let [new-value (util/evalue e) + blank? (string/blank? new-value)] + (when (not (state/get-editor-action)) + (util/stop e) + (when-not blank? + (property-handler/set-block-property! repo (:block/uuid block) + (:block/original-name property) + new-value + :old-value value)) + (exit-edit-property) + (when editing-atom (reset! editing-atom false))))) + :on-key-down + (fn [e] + (let [new-value (util/evalue e) + blank? (string/blank? new-value)] + (when (and (contains? #{"Enter" "Escape"} (util/ekey e)) + (not (state/get-editor-action))) + (util/stop e) + (when-not blank? + (property-handler/set-block-property! repo (:block/uuid block) + (:block/original-name property) + new-value + :old-value value)) + (exit-edit-property) + (cond + (or blank? + (and editing-atom + (not= type :default))) + (reset! editing-atom false) + + (and editing-atom @editing-atom) + (some-> (gdom/getElement editor-id) + (util/set-change-value ""))))))}}] + [:div.pl-1 + (editor-box editor-args editor-id (cond-> config + multiple-values? + (assoc :property-value value)))]))] (let [class (str (when-not row? "flex flex-1 ") (when multiple-values? "property-value-content"))] [:div {:id (or dom-id (random-uuid))