From 7eb4197ff4a702065eeb7d65f0986d09637e3df0 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Tue, 27 Aug 2024 22:21:26 +0800 Subject: [PATCH] fix: available choices --- .../frontend/components/db_based/page.cljs | 3 +- src/main/frontend/components/property.cljs | 297 ++---------------- .../components/property/closed_value.cljs | 263 ---------------- .../config.cljs} | 117 ++++--- 4 files changed, 104 insertions(+), 576 deletions(-) delete mode 100644 src/main/frontend/components/property/closed_value.cljs rename src/main/frontend/components/{property_v2.cljs => property/config.cljs} (79%) diff --git a/src/main/frontend/components/db_based/page.cljs b/src/main/frontend/components/db_based/page.cljs index fa881b12f..4e4e12c07 100644 --- a/src/main/frontend/components/db_based/page.cljs +++ b/src/main/frontend/components/db_based/page.cljs @@ -46,7 +46,8 @@ [:div.flex.flex-col.gap-1.pb-4 (case (:block/type page) "property" - (property-component/property-config page {:inline-text component-block/inline-text}) + [:div "Configure"] + ;; (property-component/property-config page {:inline-text component-block/inline-text}) "class" [:div.mt-2.flex.flex-col.gap-2 diff --git a/src/main/frontend/components/property.cljs b/src/main/frontend/components/property.cljs index 15f9999d1..9c79317c5 100644 --- a/src/main/frontend/components/property.cljs +++ b/src/main/frontend/components/property.cljs @@ -2,39 +2,38 @@ "Block properties management." (:require [clojure.set :as set] [clojure.string :as string] + [dommy.core :as d] + [frontend.components.dnd :as dnd] + [frontend.components.icon :as icon-component] + [frontend.components.property.config :as property-config] + [frontend.components.property.util :as components-pu] [frontend.components.property.value :as pv] [frontend.components.select :as select] [frontend.components.svg :as svg] [frontend.config :as config] [frontend.db :as db] - [frontend.db.async :as db-async] [frontend.db-mixins :as db-mixins] + [frontend.db.async :as db-async] [frontend.db.model :as model] - [logseq.outliner.property :as outliner-property] [frontend.handler.db-based.property :as db-property-handler] [frontend.handler.notification :as notification] - [frontend.handler.property :as property-handler] [frontend.handler.page :as page-handler] + [frontend.handler.property :as property-handler] + [frontend.handler.route :as route-handler] + [frontend.mixins :as mixins] [frontend.modules.shortcut.core :as shortcut] [frontend.state :as state] [frontend.ui :as ui] [frontend.util :as util] - [logseq.shui.ui :as shui] - [logseq.db.frontend.property :as db-property] - [logseq.db.frontend.property.type :as db-property-type] - [rum.core :as rum] - [frontend.handler.route :as route-handler] - [frontend.components.icon :as icon-component] - [frontend.components.dnd :as dnd] - [frontend.components.property.closed-value :as closed-value] - [frontend.components.property.util :as components-pu] - [frontend.components.property-v2 :as property-v2] - [promesa.core :as p] [logseq.db :as ldb] [logseq.db.frontend.order :as db-order] + [logseq.db.frontend.property :as db-property] + [logseq.db.frontend.property.type :as db-property-type] [logseq.outliner.core :as outliner-core] - [dommy.core :as d] - [frontend.mixins :as mixins])) + [logseq.outliner.property :as outliner-property] + [logseq.shui.ui :as shui] + [promesa.core :as p] + [rum.core :as rum])) (defn- {:disabled config/publishing? - :on-value-change (fn [v] - (swap! *property-schema assoc :position (keyword v)) - (save-property-fn))} - (keyword? position) - (assoc :default-value position)) - (shui/select-trigger - {:class "!px-2 !py-0 !h-8"} - (shui/select-value - {:placeholder "Select a position mode"})) - (shui/select-content - (shui/select-group - (for [{:keys [label value]} choices] - (shui/select-item {:value value} label)))))]])) - - (when (not tags?) - (let [hide? (:hide? @*property-schema)] - [:div.grid.grid-cols-5.gap-1.items-center.leading-8 - [:label.col-span-2 "Hide by default:"] - (shui/checkbox - {:checked hide? - :disabled config/publishing? - :on-checked-change (fn [] - (swap! *property-schema assoc :hide? (not hide?)) - (save-property-fn))})])) - - (let [description (or @*property-description "")] - [:div.grid.grid-cols-5.gap-1.items-start.leading-8 - [:label.col-span-2 "Description:"] - [:div.col-span-3 - [:div.mt-1 - (shui/textarea - {:on-change (fn [e] - (reset! *property-description (util/evalue e))) - :on-key-down (fn [e] - (when (= "Enter" (util/ekey e)) - (set-property-description property *property-description))) - :on-blur (fn [] - (set-property-description property *property-description)) - :disabled disabled? - :default-value description})]]])]])))) - (rum/defc property-select [exclude-properties select-opts] (let [[properties set-properties!] (rum/use-state nil) @@ -528,7 +320,7 @@ (rum/defcs property-key-cp < (rum/local false ::hover?) - [state block property {:keys [class-schema? page-cp inline-text other-position?]}] + [state block property {:keys [other-position?]}] (let [*hover? (::hover? state) icon (:logseq.property/icon property)] [:div.flex.flex-row.items-center.gap-1 @@ -551,9 +343,9 @@ (-> (when-not config/publishing? {:on-click (fn [^js e] (shui/popup-show! (.-target e) content-fn - {:as-dropdown? true :auto-focus? true - :content-props {:onEscapeKeyDown #(.preventDefault %)}}))}) - (assoc :class "flex items-center")) + {:as-dropdown? true :auto-focus? true + :content-props {:onEscapeKeyDown #(.preventDefault %)}}))}) + (assoc :class "flex items-center")) (if icon [:span.flex.items-center {:style {:color (or (some-> icon :color) "inherit")}} (icon-component/icon icon {:size 15})] @@ -573,49 +365,14 @@ (route-handler/redirect-to-page! (:block/uuid property)) (.preventDefault e))) :on-click (fn [^js/MouseEvent e] - (shui/popup-show! (.-target e) - (fn [{:keys [id]}] - (property-v2/dropdown-editor id property block - {:debug? (.-altKey e)})) - {:content-props - {:class "ls-property-dropdown-editor as-root"} - :align "start" - :as-dropdown? true})) - :on-context-menu (fn [^js e] - (util/stop e) - (shui/popup-show! - (.-target e) - (fn [{:keys [id]}] - [:div.p-2 - [:h2.text-lg.font-medium.mb-2.p-1 "Configure property"] - [:span.close.absolute.right-2.top-2 - (shui/button - {:variant :ghost :size :sm :class "!w-4 !h-6" - :on-click #(shui/popup-hide! id)} - (shui/tabler-icon "x" {:size 16}))] - - (property-config property - {:inline-text inline-text - :page-cp page-cp}) - - (when-not (ldb/built-in-class-property? block property) - [:div.mt-4.border-t.pt-3.px-3.-mx-4.-mb-1 - (shui/button - {:variant :ghost - :class "!text-red-rx-09 opacity-50 hover:opacity-100" - :size :sm - :on-click (fn [] - (handle-delete-property! block property {:class-schema? class-schema?}) - (shui/popup-hide!))} - "Delete property from this node")])]) - {:content-props {:class "property-configure-popup-content" - :collisionPadding {:bottom 10 :top 10} - :avoidCollisions true - :align "start"} - :align "start" - :auto-side? true - :auto-focus? true}))} - (:block/title property)))])) + (shui/popup-show! (.-target e) + (fn [] + (property-config/dropdown-editor property block {:debug? (.-altKey e)})) + {:content-props + {:class "ls-property-dropdown-editor as-root"} + :align "start" + :as-dropdown? true}))} + (:block/title property)))])) (rum/defcs property-input < rum/reactive (rum/local nil ::ref) diff --git a/src/main/frontend/components/property/closed_value.cljs b/src/main/frontend/components/property/closed_value.cljs deleted file mode 100644 index e4354c924..000000000 --- a/src/main/frontend/components/property/closed_value.cljs +++ /dev/null @@ -1,263 +0,0 @@ -(ns frontend.components.property.closed-value - "Enum property config" - (:require [rum.core :as rum] - [clojure.string :as string] - [frontend.modules.shortcut.core :as shortcut] - [frontend.util :as util] - [frontend.ui :as ui] - [logseq.shui.ui :as shui] - [frontend.components.dnd :as dnd] - [frontend.components.icon :as icon-component] - [frontend.handler.property :as property-handler] - [frontend.handler.db-based.property :as db-property-handler] - [frontend.config :as config] - [frontend.components.property.value :as property-value] - [frontend.db :as db] - [frontend.db.async :as db-async] - [frontend.state :as state] - [promesa.core :as p] - [logseq.db.frontend.property :as db-property] - [logseq.db.frontend.property.type :as db-property-type] - [logseq.db.frontend.order :as db-order] - [logseq.outliner.core :as outliner-core])) - -(defn- re-init-commands! - "Update commands after task status and priority's closed values has been changed" - [property] - (when (contains? #{:logseq.task/status :logseq.task/priority} (:db/ident property)) - (state/pub-event! [:init/commands]))) - -(defn- class - "origin-top-right.absolute.left-0.rounded-md.shadow-lg")}] - [:div.closed-values.flex.flex-col - (let [choice-items (doall - (keep (fn [value] - (when-let [block (db/sub-block (:db/id value))] - (let [id (:block/uuid block)] - {:id (str id) - :value id - :content (choice-item-content property block (merge opts dropdown-opts))}))) - values))] - (dnd/items choice-items - {:on-drag-end (fn [_ {:keys [active-id over-id direction]}] - (let [move-down? (= direction :down) - over (db/entity [:block/uuid (uuid over-id)]) - active (db/entity [:block/uuid (uuid active-id)]) - over-order (:block/order over) - new-order (if move-down? - (let [next-order (db-order/get-next-order (db/get-db) property (:db/id over))] - (db-order/gen-key over-order next-order)) - (let [prev-order (db-order/get-prev-order (db/get-db) property (:db/id over))] - (db-order/gen-key prev-order over-order)))] - - (db/transact! (state/get-current-repo) - [{:db/id (:db/id active) - :block/order new-order} - (outliner-core/block-with-updated-at - {:db/id (:db/id property)})] - {:outliner-op :save-block})))})) - (if config/publishing? - (constantly []) - (shui/button - {:variant :ghost - :class "justify-start px-0" - :size :sm - :on-click - (fn [e] - (p/let [values (db-async/> (if (contains? db-property-type/ref-property-types (get-in property [:block/schema :type])) - (map #(:block/uuid (db/entity %)) values) - values) - (remove string/blank?) - distinct)] - (if (seq values') - (add-existing-values property values' opts) - (item-config - property - nil - (assoc opts :on-save - (fn [value icon description] - (> (if (contains? db-property-type/ref-property-types (get-in property [:block/schema :type])) + (map #(:block/uuid (db/entity %)) values) + values) + (remove string/blank?) + distinct)] + (if (seq values') + (add-existing-values property values' opts) + (base-edit-form property {:create? true})))) + {:id :ls-base-edit-form + :align "start"})))}})])) (def position-labels {:properties {:icon :layout-distribute-horizontal :title "Block properties"} @@ -326,9 +360,8 @@ (remove!)))) (rum/defc dropdown-editor-impl - "popup-id: dropdown popup id - property: block entity" - [_popup-id property owner-block opts] + "property: block entity" + [property owner-block opts] (let [title (:block/title property) property-schema (:block/schema property) property-type (get property-schema :type) @@ -397,7 +430,7 @@ (dev-common-handler/show-entity-data (:db/id property)) (shui/popup-hide!))}})])])) -(rum/defc dropdown-editor < rum/reactive - [popup-id property owner-block opts] - (let [property1 (db/sub-block (:db/id property))] - (dropdown-editor-impl popup-id property1 owner-block opts))) +(rum/defc dropdown-editor < rum/reactive db-mixins/query + [property* owner-block opts] + (let [property (db/sub-block (:db/id property*))] + (dropdown-editor-impl property owner-block opts)))