|
@@ -15,7 +15,6 @@
|
|
|
[frontend.handler.page :as page-handler]
|
|
|
[frontend.handler.property.util :as pu]
|
|
|
[frontend.handler.db-based.property.util :as db-pu]
|
|
|
- [frontend.mixins :as mixins]
|
|
|
[frontend.modules.shortcut.core :as shortcut]
|
|
|
[frontend.search :as search]
|
|
|
[frontend.state :as state]
|
|
@@ -27,7 +26,6 @@
|
|
|
[frontend.handler.route :as route-handler]
|
|
|
[frontend.components.icon :as icon-component]
|
|
|
[frontend.components.dnd :as dnd]
|
|
|
- [dommy.core :as dom]
|
|
|
[frontend.components.property.closed-value :as closed-value]
|
|
|
[frontend.components.property.util :as components-pu]
|
|
|
[promesa.core :as p]))
|
|
@@ -329,8 +327,7 @@
|
|
|
(defn- add-property-from-dropdown
|
|
|
"Adds an existing or new property from dropdown. Used from a block or page context.
|
|
|
For pages, used to add both schema properties or properties for a page"
|
|
|
- [entity property-name {:keys [class-schema? page-configure?
|
|
|
- *show-new-property-config?]}]
|
|
|
+ [entity property-name {:keys [class-schema? page-configure?]}]
|
|
|
(let [repo (state/get-current-repo)]
|
|
|
;; existing property selected or entered
|
|
|
(if-let [_property (get-property-from-db property-name)]
|
|
@@ -347,10 +344,9 @@
|
|
|
(if (db-property/valid-property-name? property-name)
|
|
|
(if (and (contains? (:block/type entity) "class") page-configure?)
|
|
|
(pv/<add-property! entity property-name "" {:class-schema? class-schema? :exit-edit? page-configure?})
|
|
|
- (do
|
|
|
+ (p/do!
|
|
|
(db-property-handler/upsert-property! repo property-name {} {})
|
|
|
- (when *show-new-property-config?
|
|
|
- (reset! *show-new-property-config? true))))
|
|
|
+ true))
|
|
|
(do (notification/show! "This is an invalid property name. A property name cannot start with page reference characters '#' or '[['." :error)
|
|
|
(pv/exit-edit-property))))))
|
|
|
|
|
@@ -398,35 +394,39 @@
|
|
|
[:div.ls-property-input.flex.flex-1.flex-row.items-center.flex-wrap.gap-1
|
|
|
(if in-block-container? {:style {:padding-left 22}} {})
|
|
|
(if @*property-key
|
|
|
- (when-let [property (get-property-from-db @*property-key)]
|
|
|
+ (let [property (get-property-from-db @*property-key)]
|
|
|
[:div.ls-property-add.grid.grid-cols-5.gap-1.flex.flex-1.flex-row.items-center
|
|
|
[:div.flex.flex-row.items-center.col-span-2
|
|
|
[:span.bullet-container.cursor [:span.bullet]]
|
|
|
[:div {:style {:padding-left 6}} @*property-key]]
|
|
|
- [:div.col-span-3.flex.flex-row {:on-mouse-down (fn [e] (util/stop-propagation e))}
|
|
|
- (when-not class-schema?
|
|
|
- (if @*show-new-property-config?
|
|
|
- (ui/dropdown
|
|
|
- (fn [_opts]
|
|
|
- (pv/property-value entity property @*property-value
|
|
|
- (assoc opts
|
|
|
- :editing? true
|
|
|
- :*show-new-property-config? *show-new-property-config?)))
|
|
|
- (fn [{:keys [toggle-fn]}]
|
|
|
- [:div.p-6
|
|
|
- (property-config entity property (merge opts {:toggle-fn toggle-fn
|
|
|
- :block entity
|
|
|
- :add-new-property? true
|
|
|
- :*show-new-property-config? *show-new-property-config?}))])
|
|
|
- {:initial-open? true
|
|
|
- :modal-class (util/hiccup->class
|
|
|
- "origin-top-right.absolute.left-0.rounded-md.shadow-lg.mt-2")})
|
|
|
- (pv/property-value entity property @*property-value (assoc opts :editing? true))))]])
|
|
|
+ (when property
|
|
|
+ [:div.col-span-3.flex.flex-row {:on-mouse-down (fn [e] (util/stop-propagation e))}
|
|
|
+ (when-not class-schema?
|
|
|
+ (if @*show-new-property-config?
|
|
|
+ (ui/dropdown
|
|
|
+ (fn [_opts]
|
|
|
+ (pv/property-value entity property @*property-value
|
|
|
+ (assoc opts
|
|
|
+ :editing? true
|
|
|
+ :*show-new-property-config? *show-new-property-config?)))
|
|
|
+ (fn [{:keys [toggle-fn]}]
|
|
|
+ [:div.p-6
|
|
|
+ (property-config entity property (merge opts {:toggle-fn toggle-fn
|
|
|
+ :block entity
|
|
|
+ :add-new-property? true
|
|
|
+ :*show-new-property-config? *show-new-property-config?}))])
|
|
|
+ {:initial-open? true
|
|
|
+ :modal-class (util/hiccup->class
|
|
|
+ "origin-top-right.absolute.left-0.rounded-md.shadow-lg.mt-2")})
|
|
|
+ (pv/property-value entity property @*property-value (assoc opts :editing? true))))])])
|
|
|
|
|
|
(let [on-chosen (fn [{:keys [value]}]
|
|
|
(reset! *property-key value)
|
|
|
- (add-property-from-dropdown entity value (assoc opts :*show-new-property-config? *show-new-property-config?)))
|
|
|
- input-opts {:on-blur (fn [] (pv/exit-edit-property))
|
|
|
+ (p/let [result (add-property-from-dropdown entity value opts)]
|
|
|
+ (when (and (true? result) *show-new-property-config?)
|
|
|
+ (reset! *show-new-property-config? true))))
|
|
|
+ input-opts {:on-blur (fn []
|
|
|
+ (pv/exit-edit-property))
|
|
|
:on-key-down
|
|
|
(fn [e]
|
|
|
(case (util/ekey e)
|
|
@@ -435,66 +435,38 @@
|
|
|
nil))}]
|
|
|
(property-select exclude-properties on-chosen input-opts)))]))
|
|
|
|
|
|
-(defonce *last-new-property-input-id (atom nil))
|
|
|
-(rum/defcs new-property < rum/reactive
|
|
|
+(rum/defcs new-property < rum/reactive rum/static
|
|
|
+ (rum/local false ::new-property?)
|
|
|
(rum/local nil ::property-key)
|
|
|
(rum/local nil ::property-value)
|
|
|
- (rum/local false ::enter-key-down-triggered?)
|
|
|
- (mixins/event-mixin
|
|
|
- (fn [state]
|
|
|
- (mixins/hide-when-esc-or-outside
|
|
|
- state
|
|
|
- :on-hide (fn []
|
|
|
- (when-not (:editor/property-configure? @state/state)
|
|
|
- (property-handler/set-editing-new-property! nil)))
|
|
|
- :node (js/document.getElementById "edit-new-property"))
|
|
|
- (mixins/on-key-down state
|
|
|
- ;; enter
|
|
|
- {13 (fn [_e]
|
|
|
- (reset! *last-new-property-input-id (:ui/new-property-input-id @state/state))
|
|
|
- (reset! (::enter-key-down-triggered? state) true))})
|
|
|
- (mixins/on-enter state
|
|
|
- {:on-enter (fn [e]
|
|
|
- (when-not (or (state/editing?)
|
|
|
- (state/selection?))
|
|
|
- (when (and
|
|
|
- @(::enter-key-down-triggered? state)
|
|
|
- (or (= "main-content-container" (.-id (.-target e)))
|
|
|
- (= (.-tagName (.-target e)) "BODY")))
|
|
|
- (let [nodes (dom/by-class "add-property")
|
|
|
- last-input-id @*last-new-property-input-id
|
|
|
- node (if last-input-id
|
|
|
- (some (fn [node]
|
|
|
- (when (dom/has-class? node last-input-id) node)) nodes)
|
|
|
- (first nodes))]
|
|
|
- (when node (.click node)))
|
|
|
- (reset! (::enter-key-down-triggered? state) false))))
|
|
|
- :node js/window})))
|
|
|
- [state block edit-input-id new-property? opts]
|
|
|
- [:div.ls-new-property
|
|
|
- (let [*property-key (::property-key state)
|
|
|
- *property-value (::property-value state)]
|
|
|
- (cond
|
|
|
- new-property?
|
|
|
- [:div#edit-new-property
|
|
|
- (property-input block *property-key *property-value opts)]
|
|
|
-
|
|
|
- (and (or (db-property-handler/block-has-viewable-properties? block)
|
|
|
- (:page-configure? opts))
|
|
|
- (not config/publishing?)
|
|
|
- (not (:in-block-container? opts)))
|
|
|
- [:a.fade-link.flex.add-property
|
|
|
- {:class edit-input-id
|
|
|
- :on-click (fn []
|
|
|
- (property-handler/set-editing-new-property! edit-input-id)
|
|
|
- (reset! *property-key nil)
|
|
|
- (reset! *property-value nil))}
|
|
|
- [:div.flex.flex-row.items-center {:style {:padding-left 1}}
|
|
|
- (ui/icon "plus" {:size 15})
|
|
|
- [:div.ml-1.text-sm {:style {:padding-left 2}} "Add property"]]]
|
|
|
-
|
|
|
- :else
|
|
|
- [:div {:style {:height 28}}]))])
|
|
|
+ [state block id opts]
|
|
|
+ (let [*new-property? (::new-property? state)
|
|
|
+ container-id (state/sub :editor/properties-container)
|
|
|
+ new-property? (and @*new-property? (= container-id id))]
|
|
|
+ [:div.ls-new-property
|
|
|
+ (let [*property-key (::property-key state)
|
|
|
+ *property-value (::property-value state)]
|
|
|
+ (cond
|
|
|
+ new-property?
|
|
|
+ (property-input block *property-key *property-value opts)
|
|
|
+
|
|
|
+ (and (or (db-property-handler/block-has-viewable-properties? block)
|
|
|
+ (:page-configure? opts))
|
|
|
+ (not config/publishing?)
|
|
|
+ (not (:in-block-container? opts)))
|
|
|
+ [:a.fade-link.flex.add-property
|
|
|
+ {:on-click (fn []
|
|
|
+ (state/set-state! :editor/block block)
|
|
|
+ (state/set-state! :editor/properties-container id)
|
|
|
+ (reset! *new-property? true)
|
|
|
+ (reset! *property-key nil)
|
|
|
+ (reset! *property-value nil))}
|
|
|
+ [:div.flex.flex-row.items-center {:style {:padding-left 1}}
|
|
|
+ (ui/icon "plus" {:size 15})
|
|
|
+ [:div.ml-1.text-sm {:style {:padding-left 2}} "Add property"]]]
|
|
|
+
|
|
|
+ :else
|
|
|
+ [:div {:style {:height 28}}]))]))
|
|
|
|
|
|
(defn- property-collapsed?
|
|
|
[block property]
|
|
@@ -652,8 +624,11 @@
|
|
|
|
|
|
;; TODO: Remove :page-configure? as it only ever seems to be set to true
|
|
|
(rum/defcs ^:large-vars/cleanup-todo properties-area < rum/reactive
|
|
|
- [state target-block edit-input-id {:keys [in-block-container? page-configure? class-schema?] :as opts}]
|
|
|
- (let [block (resolve-linked-block-if-exists target-block)
|
|
|
+ {:init (fn [state]
|
|
|
+ (assoc state ::id (str (random-uuid))))}
|
|
|
+ [state target-block _edit-input-id {:keys [in-block-container? page-configure? class-schema?] :as opts}]
|
|
|
+ (let [id (::id state)
|
|
|
+ block (resolve-linked-block-if-exists target-block)
|
|
|
block-properties (:block/properties block)
|
|
|
properties (if (and class-schema? page-configure?)
|
|
|
(let [properties (:properties (:block/schema block))]
|
|
@@ -703,7 +678,6 @@
|
|
|
(concat block-own-properties' class-own-properties)
|
|
|
block-own-properties'))
|
|
|
full-hidden-properties (concat block-hidden-properties class-hidden-properties)
|
|
|
- new-property? (= edit-input-id (state/sub :ui/new-property-input-id))
|
|
|
class->properties (loop [classes all-classes
|
|
|
properties #{}
|
|
|
result []]
|
|
@@ -717,11 +691,11 @@
|
|
|
result))]
|
|
|
(when-not (and (empty? block-own-properties)
|
|
|
(empty? class->properties)
|
|
|
- (not new-property?)
|
|
|
(not (:page-configure? opts)))
|
|
|
[:div.ls-properties-area (cond-> (if in-block-container?
|
|
|
- {}
|
|
|
- {:class (when class-schema? "class-properties")})
|
|
|
+ {:id id}
|
|
|
+ {:id id
|
|
|
+ :class (when class-schema? "class-properties")})
|
|
|
(:selected? opts)
|
|
|
(update :class conj "select-none"))
|
|
|
(properties-section block (if class-schema? properties own-properties) opts)
|
|
@@ -729,8 +703,8 @@
|
|
|
(when (and (seq full-hidden-properties) (not class-schema?) (not config/publishing?))
|
|
|
(hidden-properties block full-hidden-properties opts))
|
|
|
|
|
|
- (when (or new-property? (not in-block-container?))
|
|
|
- (new-property block edit-input-id new-property? opts))
|
|
|
+ (when (not in-block-container?)
|
|
|
+ (rum/with-key (new-property block id opts) (str id "-add-property")))
|
|
|
|
|
|
(when (and (seq class->properties) (not one-class?))
|
|
|
(let [page-cp (:page-cp opts)]
|