feat: object type

pull/10016/head
Tienson Qin 2023-08-14 19:10:45 +08:00
parent debde5bdf6
commit 2181525bd8
9 changed files with 67 additions and 27 deletions

View File

@ -721,7 +721,7 @@
(state/clear-edit!))
(defmethod handle-step :editor/new-property [[_]]
(property-handler/editing-new-property!))
(state/pub-event! [:editor/new-property]))
(defmethod handle-step :default [[type & _args]]
(prn "No handler for step: " type))

View File

@ -5,6 +5,7 @@
[frontend.components.property.value :as pv]
[frontend.components.select :as select]
[frontend.db :as db]
[frontend.db.model :as db-model]
[frontend.handler.db-based.property :as db-property]
[frontend.handler.notification :as notification]
[frontend.handler.property :as property-handler]
@ -40,6 +41,17 @@
:id id}}}))
(toggle-fn))})))))
(rum/defc class-select
[*property-schema class]
(let [classes (db-model/get-all-classes (state/get-current-repo))
options (map (fn [[name id]] {:label name
:value id
:selected (= class id)})
classes)]
(ui/select options
(fn [_e value]
(swap! *property-schema assoc :class (str value))))))
(rum/defcs property-config <
rum/reactive
(rum/local nil ::property-name)
@ -89,6 +101,11 @@
(let [type (keyword (string/lower-case v))]
(swap! *property-schema assoc :type type)))))]
(when (= :object (:type @*property-schema))
[:div.grid.grid-cols-4.gap-1.leading-8
[:label "Choose class:"]
(class-select *property-schema (:class @*property-schema))])
(when-not (= (:type @*property-schema) :checkbox)
[:div.grid.grid-cols-4.gap-1.items-center.leading-8
[:label "Multiple values:"]

View File

@ -82,11 +82,15 @@
"origin-top-right.absolute.left-0.rounded-md.shadow-lg.mt-2")})))
(defn- select-page
[block property opts]
[block property {:keys [class] :as opts}]
(let [repo (state/get-current-repo)
pages (->> (model/get-all-page-original-names repo)
(map (fn [p] {:value p})))]
(select/select {:items pages
pages (if class
(some->> (:block/name (db/entity [:block/uuid (uuid class)]))
(db/get-tag-pages repo)
(map first))
(model/get-all-page-original-names repo))
options (map (fn [p] {:value p}) pages)]
(select/select {:items options
:dropdown? true
:on-chosen (fn [chosen]
(let [page (string/trim (:value chosen))
@ -282,8 +286,9 @@
:as opts}]
(let [property (model/sub-block (:db/id property))
repo (state/get-current-repo)
type (:type (:block/schema property))
multiple-values? (= :many (:cardinality (:block/schema property)))
schema (:block/schema property)
type (:type schema)
multiple-values? (= :many (:cardinality schema))
editor-id (or editor-id (str "ls-property-" blocks-container-id "-" (:db/id block) "-" (:db/id property)))
editing? (or editing? (state/sub [:editor/editing? editor-id]))
select-opts {:on-chosen (fn []
@ -309,6 +314,9 @@
(list :number :url)
[:div.h-6 (select block property select-opts)]
:object
[:div.h-6 (select-page block property (assoc select-opts :class (:class schema)))]
:page
[:div.h-6 (select-page block property select-opts)]
@ -326,9 +334,9 @@
:class class
:style {:min-height 24}
:on-click (fn []
(let [page-or-block? (contains? #{:page :block} type)]
(when (or (not page-or-block?)
(and (string/blank? value) page-or-block?))
(let [ref? (contains? #{:page :block :object} type)]
(when (or (not ref?)
(and (string/blank? value) ref?))
(set-editing! property editor-id dom-id value))))}
(let [type (if (and (= type :default) (uuid? value))
(if-let [e (db/entity [:block/uuid value])]
@ -338,6 +346,10 @@
(if (string/blank? value)
[:div.opacity-50.text-sm "Input something"]
(case type
:object
(when-let [object (db/entity [:block/uuid value])]
(page-cp {} object))
:page
(when-let [page (db/entity [:block/uuid value])]
(page-cp {} page))
@ -421,15 +433,14 @@
*add-new-item? (::add-new-item? state)
type (:type schema)
block? (= type :block)
page? (= type :page)
default? (= type :default)
row? (contains? #{:page} type)
row? (contains? #{:page :object} type)
items (if (coll? v) v (when v [v]))]
[:div.relative
{:class (cond
row?
(cond-> "flex flex-1 flex-row items-center flex-wrap"
page?
row?
(str " gap-2"))
block?
"grid"
@ -470,7 +481,7 @@
[:div.rounded-sm {:on-click (fn [] (reset! *add-new-item? true))}
[:div.opacity-50.text-sm "Input something"]]
(and @*show-add? page?)
(and @*show-add? row?)
[:a.add-button-link.flex
{:on-click (fn [] (reset! *add-new-item? true))}
(ui/icon "circle-plus")]

View File

@ -1505,11 +1505,12 @@ independent of format as format specific heading characters are stripped"
(defn get-all-classes
[repo]
(d/q
'[:find [?name ...]
:where
[?page :block/type ?t]
[(= ?t "class")]
[?page :block/original-name ?name]]
'[:find ?name ?id
:where
[?page :block/type ?t]
[(= ?t "class")]
[?page :block/original-name ?name]
[?page :block/uuid ?id]]
(conn/get-db repo)))
(comment

View File

@ -30,7 +30,7 @@
[id]
(and (uuid? id)
(when-let [e (db/entity [:block/uuid id])]
(seq (:block/class e)))))
(seq (:block/tags e)))))
(def builtin-schema-types
{:default string? ; refs/tags will not be extracted

View File

@ -3383,7 +3383,7 @@
(let [config (last (state/get-editor-args))]
(:ref? config)))
(defn- set-blocks-collapsed!
(defn set-blocks-collapsed!
[block-ids value]
(let [block-ids (map (fn [block-id] (if (string? block-id) (uuid block-id) block-id)) block-ids)
repo (state/get-current-repo)

View File

@ -25,7 +25,6 @@
[frontend.components.user.login :as login]
[frontend.components.shortcut :as shortcut]
[frontend.components.repo :as repo]
[frontend.components.page :as page]
[frontend.config :as config]
[frontend.context.i18n :refer [t]]
[frontend.db :as db]
@ -54,6 +53,7 @@
[frontend.handler.ui :as ui-handler]
[frontend.handler.user :as user-handler]
[frontend.handler.property.util :as pu]
[frontend.handler.property :as property-handler]
[frontend.handler.whiteboard :as whiteboard-handler]
[frontend.handler.web.nfs :as nfs-handler]
[frontend.mobile.core :as mobile]
@ -982,6 +982,16 @@
(when-let [blocks (and block (db-model/get-block-immediate-children (state/get-current-repo) (:block/uuid block)))]
(editor-handler/toggle-blocks-as-own-order-list! blocks)))
(defmethod handle :editor/new-property [[_]]
(when-let [edit-block (state/get-edit-block)]
(when-let [block-id (:block/uuid edit-block)]
(let [block (db/entity [:block/uuid block-id])
collapsed? (or (get-in @state/state [:ui/collapsed-blocks (state/get-current-repo) block-id])
(:block/collapsed? block))]
(when collapsed?
(editor-handler/set-blocks-collapsed! [block-id] false)))))
(property-handler/editing-new-property!))
(defn run!
[]
(let [chan (state/get-events-chan)]

View File

@ -4,7 +4,8 @@
[frontend.handler.file-based.property :as file-property]
[frontend.config :as config]
[frontend.state :as state]
[frontend.db :as db]))
[frontend.db :as db]
[frontend.modules.outliner.core :as outliner-core]))
(def user-face-builtin-schema-types db-property/user-face-builtin-schema-types)
(def internal-builtin-schema-types db-property/internal-builtin-schema-types)

View File

@ -896,10 +896,10 @@
[:option (cond->
{:key label
:value (or value label)} ;; NOTE: value might be an empty string, `or` is safe here
disabled
(assoc :disabled disabled)
selected
(assoc :selected selected))
disabled
(assoc :disabled disabled)
selected
(assoc :selected selected))
label])]))
(rum/defc radio-list