diff --git a/src/main/frontend/components/property.cljs b/src/main/frontend/components/property.cljs index 3cef2359ae..4652d47789 100644 --- a/src/main/frontend/components/property.cljs +++ b/src/main/frontend/components/property.cljs @@ -84,7 +84,7 @@ [:div.grid.grid-cols-4.gap-1.leading-8 [:label "Schema type:"] - (let [schema-types (->> (keys property-handler/builtin-schema-types) + (let [schema-types (->> property-handler/user-face-builtin-schema-types (remove property-handler/internal-builtin-schema-types) (map (comp string/capitalize name)) (map (fn [type] @@ -330,17 +330,25 @@ :on-key-down (fn [e] (let [new-value (util/evalue e) - blank? (string/blank? new-value)] - (when (and (contains? #{"Enter" "Escape"} (util/ekey e)) + blank? (string/blank? new-value) + enter? (= (util/ekey e) "Enter") + esc? (= (util/ekey e) "Escape") + meta? (util/meta-key? e) + create-another-one? (and meta? enter?)] + (when (and (or enter? esc? create-another-one?) (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)) + (when (not= (string/trim new-value) (string/trim value)) + (property-handler/set-block-property! repo (:block/uuid block) + (:block/original-name property) + new-value + :old-value value))) (exit-edit-property) (cond + esc? + (reset! editing-atom false) + (or blank? (and editing-atom (not= type :default))) @@ -348,7 +356,10 @@ (and editing-atom @editing-atom) (some-> (gdom/getElement editor-id) - (util/set-change-value ""))))))}}] + (util/set-change-value "")) + + (and (or enter? create-another-one?) editing-atom (not blank?)) + (reset! editing-atom true)))))}}] [:div.pl-1 (editor-box editor-args editor-id (cond-> config multiple-values? @@ -376,10 +387,19 @@ :block (if-let [block (db/entity [:block/uuid value])] - [:div.property-block-container.w-full - (block-cp [block] {:id (str value) - :editor-box editor-box - :in-property? true})] + (let [editor-opts {:on-key-down + (fn [e] + (let [meta? (util/meta-key? e) + enter? (= (util/ekey e) "Enter") + create-another-one? (and meta? enter?)] + (when create-another-one? + (util/stop e) + (reset! editing-atom true))))}] + [:div.property-block-container.w-full + (block-cp [block] {:id (str value) + :editor-box editor-box + :editor-opts editor-opts + :in-property? true})]) (if multiple-values? (property-handler/delete-property-value! repo block (:block/uuid property) value) (property-handler/remove-block-property! repo @@ -550,6 +570,7 @@ multiple-values? (= :many (:cardinality schema)) row? (and multiple-values? (contains? #{:page} (:type schema))) block? (= (:type schema) :block) + default? (= (:type schema) :default) editor-args {:block property :parent-block block :format :markdown}] @@ -573,7 +594,8 @@ {:dom-id dom-id' :editor-id editor-id' :editor-args editor-args - :row? row?})) + :row? row? + :editing-atom *editing?})) dom-id'))) (cond @@ -587,12 +609,17 @@ :editing? @*editing? :editing-atom *editing?})) + (and (or default? block?) (seq items)) + nil + :else [:div.rounded-sm.ml-1 {:on-click (fn [] (reset! *editing? true))} - [:div.flex.flex-row - [:a.add-button-link.inline-flex {:title "Add another value" - :style {:margin-left -3}} - (ui/icon "circle-plus")]]])]) + (if (or default? block?) + [:div.opacity-50.text-sm "Input something"] + [:div.flex.flex-row + [:a.add-button-link.inline-flex {:title "Add another value" + :style {:margin-left -3}} + (ui/icon "circle-plus")]])])]) :else [:div.flex.flex-1.items-center.property-value-content diff --git a/src/main/frontend/handler/db_based/property.cljs b/src/main/frontend/handler/db_based/property.cljs index cf4ffca900..48e4823cdf 100644 --- a/src/main/frontend/handler/db_based/property.cljs +++ b/src/main/frontend/handler/db_based/property.cljs @@ -64,14 +64,11 @@ :any some?}) (def internal-builtin-schema-types #{:keyword :map :coll :any}) +(def user-face-builtin-schema-types [:default :number :date :checkbox :url :page :block :object]) ;; schema -> type, cardinality, object's class ;; min, max -> string length, number range, cardinality size limit -;; TODO: Enable or delete if unused -#_(def builtin-schema->type - (set/map-invert builtin-schema-types)) - (defn- infer-schema-from-input-string [v-str] (try diff --git a/src/main/frontend/handler/property.cljs b/src/main/frontend/handler/property.cljs index 1ccde12784..6b4c599b8b 100644 --- a/src/main/frontend/handler/property.cljs +++ b/src/main/frontend/handler/property.cljs @@ -6,7 +6,7 @@ [frontend.state :as state] [frontend.db :as db])) -(def builtin-schema-types db-property/builtin-schema-types) +(def user-face-builtin-schema-types db-property/user-face-builtin-schema-types) (def internal-builtin-schema-types db-property/internal-builtin-schema-types) (defn remove-block-property!