fix: esc or click outside to exit new property

pull/10016/head
Tienson Qin 2023-08-14 12:27:41 +08:00
parent 11fc737290
commit 5895e06506
2 changed files with 41 additions and 26 deletions

View File

@ -156,7 +156,7 @@
(rum/defcs property-input < rum/reactive (rum/defcs property-input < rum/reactive
shortcut/disable-all-shortcuts shortcut/disable-all-shortcuts
[state entity *property-key *property-value {:keys [class-schema? page-configure?] [state entity *property-key *property-value {:keys [class-schema? page-configure? *configure-show?]
:as opts}] :as opts}]
(let [entity-properties (->> (keys (:block/properties entity)) (let [entity-properties (->> (keys (:block/properties entity))
(map #(:block/original-name (db/entity [:block/uuid %]))) (map #(:block/original-name (db/entity [:block/uuid %])))
@ -188,7 +188,19 @@
:on-chosen (fn [{:keys [value]}] :on-chosen (fn [{:keys [value]}]
(reset! *property-key value) (reset! *property-key value)
(add-property-from-dropdown entity value opts)) (add-property-from-dropdown entity value opts))
:input-opts {:on-blur pv/exit-edit-property}})]))) :input-opts {:on-blur (fn []
(when *configure-show?
(reset! *configure-show? false))
(pv/exit-edit-property))
:on-key-down
(fn [e]
(case (util/ekey e)
"Escape"
(do
(when *configure-show?
(reset! *configure-show? false))
(pv/exit-edit-property))
nil))}})])))
(rum/defcs new-property < rum/reactive (rum/defcs new-property < rum/reactive
(rum/local nil ::property-key) (rum/local nil ::property-key)

View File

@ -53,30 +53,33 @@
(js/Date. (date/journal-title->long title)) (js/Date. (date/journal-title->long title))
value) value)
value' (when-not (string/blank? value) value' (when-not (string/blank? value)
(tc/to-local-date value)) (tc/to-local-date value))]
open-modal! (fn [] (ui/dropdown
(state/set-modal! (fn [{:keys [toggle-fn]}]
#(ui/datepicker value' {:on-change (fn [_e date] [:a
(let [repo (state/get-current-repo) {:tabIndex "0"
journal (date/js-date->journal-title date)] :on-click toggle-fn
(when-not (db/entity [:block/name (util/page-name-sanity-lc journal)]) :on-key-down (fn [e]
(page-handler/create! journal {:redirect? false (when (= (util/ekey e) "Enter")
:create-first-block? false})) toggle-fn))}
(when-let [page (db/entity [:block/name (util/page-name-sanity-lc journal)])] [:span.inline-flex.items-center
(property-handler/set-block-property! repo (:block/uuid block) (ui/icon "calendar")
(:block/name property) [:span.ml-1 (or title "Pick a date")]]])
(:block/uuid page))) (fn [{:keys [toggle-fn]}]
(exit-edit-property) (ui/datepicker value' {:on-change (fn [_e date]
(state/close-modal!)))})))] (let [repo (state/get-current-repo)
[:a journal (date/js-date->journal-title date)]
{:tabIndex "0" (when-not (db/entity [:block/name (util/page-name-sanity-lc journal)])
:on-click open-modal! (page-handler/create! journal {:redirect? false
:on-key-down (fn [e] :create-first-block? false}))
(when (= (util/ekey e) "Enter") (when-let [page (db/entity [:block/name (util/page-name-sanity-lc journal)])]
(open-modal!)))} (property-handler/set-block-property! repo (:block/uuid block)
[:span.inline-flex.items-center (:block/name property)
(ui/icon "calendar") (:block/uuid page)))
[:span.ml-1 (or title "Pick a date")]]])) (exit-edit-property)
(toggle-fn)))}))
{:modal-class (util/hiccup->class
"origin-top-right.absolute.left-0.rounded-md.shadow-lg.mt-2")})))
(defn- select-page (defn- select-page
[block property opts] [block property opts]