Skip to content

Commit b14735a

Browse files
committed
enhance(ux): show asset when editing asset title
1 parent fc7729d commit b14735a

File tree

1 file changed

+55
-46
lines changed

1 file changed

+55
-46
lines changed

src/main/frontend/components/block.cljs

Lines changed: 55 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2491,13 +2491,6 @@
24912491
(:raw-title? config)
24922492
(text-block-title (dissoc config :raw-title?) block)
24932493

2494-
(ldb/asset? block)
2495-
[:div.grid.grid-cols-1.justify-items-center.asset-block-wrap
2496-
(asset-cp config block)
2497-
(when (img-audio-video? block)
2498-
[:div.text-xs.opacity-60.mt-1
2499-
(text-block-title (dissoc config :raw-title?) block)])]
2500-
25012494
(= :code node-display-type)
25022495
[:div.flex.flex-1.w-full
25032496
(src-cp (assoc config :code-block block) {:language (:logseq.property.code/lang block)})]
@@ -3082,8 +3075,16 @@
30823075
(swap! *hide-block-refs? not)))}
30833076
[:span.text-sm block-refs-count'])]))
30843077

3078+
(defn- edit-block-content
3079+
[config block edit-input-id]
3080+
(let [content (:block/title block)]
3081+
(editor-handler/clear-selection!)
3082+
(editor-handler/unhighlight-blocks!)
3083+
(state/set-editing! edit-input-id content block content {:db (db/get-db)
3084+
:container-id (:container-id config)})))
3085+
30853086
(rum/defc block-content-with-error
3086-
[config block edit-input-id block-id *show-query? editor-box]
3087+
[config block edit-input-id block-id *show-query? editor-box custom-block-content]
30873088
(let [[editing? set-editing!] (hooks/use-state false)
30883089
query (:logseq.property/query block)]
30893090
(ui/catch-error
@@ -3106,12 +3107,8 @@
31063107
{:content (or (:block/title query)
31073108
(:block/title block))
31083109
:section-attrs
3109-
{:on-click #(let [content (:block/title block)]
3110-
(editor-handler/clear-selection!)
3111-
(editor-handler/unhighlight-blocks!)
3112-
(state/set-editing! edit-input-id content block "" {:db (db/get-db)
3113-
:container-id (:container-id config)}))}})])
3114-
(block-content config block edit-input-id block-id *show-query?))))
3110+
{:on-click #(edit-block-content config block edit-input-id)}})])
3111+
(or custom-block-content (block-content config block edit-input-id block-id *show-query?)))))
31153112

31163113
(rum/defcs ^:large-vars/cleanup-todo block-content-or-editor < rum/reactive
31173114
[state config {:block/keys [uuid] :as block} {:keys [edit-input-id block-id edit? hide-block-refs-count? refs-count *hide-block-refs? *show-query?]}]
@@ -3138,34 +3135,36 @@
31383135
(when (and db-based? (not table?)) (block-positioned-properties config block :block-left))
31393136
[:div.block-content-or-editor-inner
31403137
[:div.block-row.flex.flex-1.flex-row.gap-1.items-center
3141-
(let [content-cp [:div.flex.flex-1.w-full.block-content-wrapper
3142-
{:style {:display "flex"}}
3143-
(when-let [actions-cp (:page-title-actions-cp config)]
3144-
(actions-cp block))
3145-
(block-content-with-error config block edit-input-id block-id *show-query? editor-box)
3146-
3147-
(when (and (not hide-block-refs-count?)
3148-
(not named?)
3149-
(not (:table-block-title? config)))
3150-
[:div.flex.flex-row.items-center
3151-
(when (and (:embed? config)
3152-
(:embed-parent config))
3153-
[:a.opacity-70.hover:opacity-100.svg-small.inline
3154-
{:on-pointer-down (fn [e]
3155-
(util/stop e)
3156-
(when-let [block (:embed-parent config)]
3157-
(editor-handler/edit-block! block :max)))}
3158-
svg/edit])
3159-
3160-
(when block-reference-only?
3161-
[:a.opacity-70.hover:opacity-100.svg-small.inline
3162-
{:on-pointer-down (fn [e]
3163-
(util/stop e)
3164-
(editor-handler/edit-block! block :max))}
3165-
svg/edit])])
3166-
3167-
(when-not (or (:table? config) (:property? config) (:page-title? config))
3168-
(block-refs-count block refs-count *hide-block-refs?))]
3138+
(let [block-content-f (fn block-content-f
3139+
[{:keys [custom-block-content]}]
3140+
[:div.flex.flex-1.w-full.block-content-wrapper
3141+
{:style {:display "flex"}}
3142+
(when-let [actions-cp (:page-title-actions-cp config)]
3143+
(actions-cp block))
3144+
(block-content-with-error config block edit-input-id block-id *show-query? editor-box custom-block-content)
3145+
3146+
(when (and (not hide-block-refs-count?)
3147+
(not named?)
3148+
(not (:table-block-title? config)))
3149+
[:div.flex.flex-row.items-center
3150+
(when (and (:embed? config)
3151+
(:embed-parent config))
3152+
[:a.opacity-70.hover:opacity-100.svg-small.inline
3153+
{:on-pointer-down (fn [e]
3154+
(util/stop e)
3155+
(when-let [block (:embed-parent config)]
3156+
(editor-handler/edit-block! block :max)))}
3157+
svg/edit])
3158+
3159+
(when block-reference-only?
3160+
[:a.opacity-70.hover:opacity-100.svg-small.inline
3161+
{:on-pointer-down (fn [e]
3162+
(util/stop e)
3163+
(editor-handler/edit-block! block :max))}
3164+
svg/edit])])
3165+
3166+
(when-not (or (:table? config) (:property? config) (:page-title? config))
3167+
(block-refs-count block refs-count *hide-block-refs?))])
31693168
editor-cp [:div.editor-wrapper.flex.flex-1.w-full
31703169
{:id editor-id
31713170
:class (util/classnames [{:opacity-50 (boolean (or (ldb/built-in? block) (ldb/journal? block)))}])}
@@ -3176,10 +3175,20 @@
31763175
:block-parent-id block-id
31773176
:format format}
31783177
edit-input-id
3179-
config))]]
3180-
(if (and editor-box edit? (not type-block-editor?))
3181-
editor-cp
3182-
content-cp))
3178+
config))]
3179+
show-editor? (and editor-box edit? (not type-block-editor?))]
3180+
(if (ldb/asset? block)
3181+
[:div.flex.flex-col.asset-block-wrap.w-full
3182+
(block-content-f {:custom-block-content
3183+
[:div.flex.flex-1
3184+
(asset-cp config block)]})
3185+
(if show-editor?
3186+
[:div.mt-1 editor-cp]
3187+
(when (img-audio-video? block)
3188+
[:div.text-xs.opacity-60.mt-1.cursor-text
3189+
{:on-click #(edit-block-content config block edit-input-id)}
3190+
(text-block-title (dissoc config :raw-title?) block)]))]
3191+
(if show-editor? editor-cp (block-content-f {}))))
31833192

31843193
(when-not (:table-block-title? config)
31853194
[:div.ls-block-right.flex.flex-row.items-center.self-start.gap-1

0 commit comments

Comments
 (0)