|
|
@@ -391,14 +391,19 @@
|
|
|
:on-mouse-down
|
|
|
(fn [e]
|
|
|
(util/stop e)
|
|
|
- (if (gobj/get e "shiftKey")
|
|
|
+ (cond
|
|
|
+ (gobj/get e "shiftKey")
|
|
|
(when-let [page-entity (db/entity [:block/name redirect-page-name])]
|
|
|
(state/sidebar-add-block!
|
|
|
(state/get-current-repo)
|
|
|
(:db/id page-entity)
|
|
|
- :page
|
|
|
- {:page page-entity}))
|
|
|
- (state/pub-event! [:page/create redirect-page-name]))
|
|
|
+ :page))
|
|
|
+
|
|
|
+ (not= redirect-page-name page-name)
|
|
|
+ (route-handler/redirect-to-page! redirect-page-name)
|
|
|
+
|
|
|
+ :else
|
|
|
+ (state/pub-event! [:page/create page-name-in-block]))
|
|
|
(when (and contents-page?
|
|
|
(util/mobile?)
|
|
|
(state/get-left-sidebar-open?))
|
|
|
@@ -642,7 +647,7 @@
|
|
|
|
|
|
(declare block-content)
|
|
|
(declare block-container)
|
|
|
-(declare block-parents)
|
|
|
+(declare breadcrumb)
|
|
|
|
|
|
(rum/defc block-reference < rum/reactive
|
|
|
db-mixins/query
|
|
|
@@ -684,8 +689,7 @@
|
|
|
(state/sidebar-add-block!
|
|
|
(state/get-current-repo)
|
|
|
(:db/id block)
|
|
|
- :block-ref
|
|
|
- {:block block})
|
|
|
+ :block-ref)
|
|
|
|
|
|
(match [block-type (util/electron?)]
|
|
|
;; pdf annotation
|
|
|
@@ -700,7 +704,7 @@
|
|
|
{:style {:width 735
|
|
|
:text-align "left"
|
|
|
:max-height 600}}
|
|
|
- [(block-parents config repo block-id {:indent? true})
|
|
|
+ [(breadcrumb config repo block-id {:indent? true})
|
|
|
(blocks-container
|
|
|
(db/get-block-and-children repo block-id)
|
|
|
(assoc config :id (str id) :preview? true))]])
|
|
|
@@ -1384,8 +1388,7 @@
|
|
|
(state/sidebar-add-block!
|
|
|
(state/get-current-repo)
|
|
|
(:db/id block)
|
|
|
- :block
|
|
|
- block)
|
|
|
+ :block)
|
|
|
(util/stop e))
|
|
|
(route-handler/redirect-to-page! uuid)))
|
|
|
|
|
|
@@ -1955,24 +1958,27 @@
|
|
|
nil)]]))
|
|
|
|
|
|
(rum/defc block-refs-count < rum/static
|
|
|
- [block]
|
|
|
+ [block *hide-block-refs?]
|
|
|
(let [block-refs-count (count (:block/_refs block))]
|
|
|
(when (> block-refs-count 0)
|
|
|
[:div
|
|
|
[:a.open-block-ref-link.bg-base-2.text-sm.ml-2.fade-link
|
|
|
{:title "Open block references"
|
|
|
:style {:margin-top -1}
|
|
|
- :on-click (fn []
|
|
|
- (state/sidebar-add-block!
|
|
|
- (state/get-current-repo)
|
|
|
- (:db/id block)
|
|
|
- :block-ref
|
|
|
- {:block block}))}
|
|
|
+ :on-click (fn [e]
|
|
|
+ (if (gobj/get e "shiftKey")
|
|
|
+ (state/sidebar-add-block!
|
|
|
+ (state/get-current-repo)
|
|
|
+ (:db/id block)
|
|
|
+ :block-ref)
|
|
|
+ (swap! *hide-block-refs? not)))}
|
|
|
block-refs-count]])))
|
|
|
|
|
|
-(rum/defc block-content-or-editor < rum/reactive
|
|
|
- [config {:block/keys [uuid format] :as block} edit-input-id block-id heading-level edit?]
|
|
|
- (let [editor-box (get config :editor-box)
|
|
|
+(rum/defcs block-content-or-editor < rum/reactive
|
|
|
+ (rum/local true :hide-block-refs?)
|
|
|
+ [state config {:block/keys [uuid format] :as block} edit-input-id block-id heading-level edit?]
|
|
|
+ (let [*hide-block-refs? (get state :hide-block-refs?)
|
|
|
+ editor-box (get config :editor-box)
|
|
|
editor-id (str "editor-" edit-input-id)
|
|
|
slide? (:slide? config)]
|
|
|
(if (and edit? editor-box)
|
|
|
@@ -1991,25 +1997,31 @@
|
|
|
(editor-handler/escape-editing select?))))}
|
|
|
edit-input-id
|
|
|
config))]
|
|
|
- [:div.flex.flex-row.block-content-wrapper
|
|
|
- [:div.flex-1.w-full {:style {:display (if (:slide? config) "block" "flex")}}
|
|
|
- (ui/catch-error
|
|
|
- (ui/block-error "Block Render Error:"
|
|
|
- {:content (:block/content block)
|
|
|
- :section-attrs
|
|
|
- {:on-click #(state/set-editing! edit-input-id (:block/content block) block "")}})
|
|
|
- (block-content config block edit-input-id block-id slide?))]
|
|
|
- [:div.flex.flex-row.items-center
|
|
|
- (when (and (:embed? config)
|
|
|
- (:embed-parent config))
|
|
|
- [:a.opacity-30.hover:opacity-100.svg-small.inline
|
|
|
- {:on-mouse-down (fn [e]
|
|
|
- (util/stop e)
|
|
|
- (when-let [block (:embed-parent config)]
|
|
|
- (editor-handler/edit-block! block :max (:block/uuid block))))}
|
|
|
- svg/edit])
|
|
|
-
|
|
|
- (block-refs-count block)]])))
|
|
|
+ (let [refs-count (count (:block/_refs block))]
|
|
|
+ [:div.flex.flex-col.block-content-wrapper
|
|
|
+ [:div.flex.flex-row
|
|
|
+ [:div.flex-1.w-full {:style {:display (if (:slide? config) "block" "flex")}}
|
|
|
+ (ui/catch-error
|
|
|
+ (ui/block-error "Block Render Error:"
|
|
|
+ {:content (:block/content block)
|
|
|
+ :section-attrs
|
|
|
+ {:on-click #(state/set-editing! edit-input-id (:block/content block) block "")}})
|
|
|
+ (block-content config block edit-input-id block-id slide?))]
|
|
|
+ [:div.flex.flex-row.items-center
|
|
|
+ (when (and (:embed? config)
|
|
|
+ (:embed-parent config))
|
|
|
+ [:a.opacity-30.hover:opacity-100.svg-small.inline
|
|
|
+ {:on-mouse-down (fn [e]
|
|
|
+ (util/stop e)
|
|
|
+ (when-let [block (:embed-parent config)]
|
|
|
+ (editor-handler/edit-block! block :max (:block/uuid block))))}
|
|
|
+ svg/edit])
|
|
|
+
|
|
|
+ (block-refs-count block *hide-block-refs?)]]
|
|
|
+
|
|
|
+ (when (and (not @*hide-block-refs?) (> refs-count 0))
|
|
|
+ (let [refs-cp (state/get-component :block/linked-references)]
|
|
|
+ (refs-cp uuid)))]))))
|
|
|
|
|
|
(defn non-dragging?
|
|
|
[e]
|
|
|
@@ -2019,30 +2031,43 @@
|
|
|
(not @*dragging?)))
|
|
|
|
|
|
(rum/defc breadcrumb-fragment
|
|
|
- [config block label]
|
|
|
- (if (= block :page) ; page
|
|
|
- (when label
|
|
|
- (let [page (db/entity [:block/name (util/page-name-sanity-lc label)])]
|
|
|
- (page-cp config page)))
|
|
|
- [:a {:on-mouse-down
|
|
|
- (fn [e]
|
|
|
- (if (gobj/get e "shiftKey")
|
|
|
- (do
|
|
|
- (util/stop e)
|
|
|
- (state/sidebar-add-block!
|
|
|
- (state/get-current-repo)
|
|
|
- (:db/id block)
|
|
|
- :block-ref
|
|
|
- {:block block}))
|
|
|
- (route-handler/redirect-to-page! (:block/uuid block))))}
|
|
|
- label]))
|
|
|
+ [config block label opts]
|
|
|
+ [:a {:on-mouse-down
|
|
|
+ (fn [e]
|
|
|
+ (cond
|
|
|
+ (gobj/get e "shiftKey")
|
|
|
+ (do
|
|
|
+ (util/stop e)
|
|
|
+ (state/sidebar-add-block!
|
|
|
+ (state/get-current-repo)
|
|
|
+ (:db/id block)
|
|
|
+ :block-ref))
|
|
|
+
|
|
|
+ (util/atom? (:navigating-block opts))
|
|
|
+ (do
|
|
|
+ (util/stop e)
|
|
|
+ (reset! (:navigating-block opts) (:block/uuid block)))
|
|
|
+
|
|
|
+ (some? (:sidebar-key config))
|
|
|
+ (do
|
|
|
+ (util/stop e)
|
|
|
+ (state/sidebar-replace-block!
|
|
|
+ (:sidebar-key config)
|
|
|
+ [(state/get-current-repo)
|
|
|
+ (:db/id block)
|
|
|
+ (if (:block/name block) :page :block)]))
|
|
|
+
|
|
|
+ :else
|
|
|
+ (route-handler/redirect-to-page! (:block/uuid block))))}
|
|
|
+ label])
|
|
|
|
|
|
(rum/defc breadcrumb-separator [] [:span.mx-2.opacity-50 "➤"])
|
|
|
|
|
|
-(defn block-parents
|
|
|
- [config repo block-id {:keys [show-page? indent? level-limit]
|
|
|
+(defn breadcrumb
|
|
|
+ [config repo block-id {:keys [show-page? indent? level-limit _navigating-block]
|
|
|
:or {show-page? true
|
|
|
- level-limit 3}}]
|
|
|
+ level-limit 3}
|
|
|
+ :as opts}]
|
|
|
(let [parents (db/get-block-parents repo block-id (inc level-limit))
|
|
|
page (db/get-block-page repo block-id)
|
|
|
page-name (:block/name page)
|
|
|
@@ -2055,7 +2080,7 @@
|
|
|
parents (if more? (take-last level-limit parents) parents)]
|
|
|
(when show?
|
|
|
(let [page-name-props (when show-page?
|
|
|
- [:page
|
|
|
+ [page
|
|
|
(or page-original-name page-name)])
|
|
|
parents-props (doall
|
|
|
(for [{:block/keys [uuid name content] :as block} parents]
|
|
|
@@ -2075,10 +2100,10 @@
|
|
|
(filterv identity)
|
|
|
(map (fn [x] (if (vector? x)
|
|
|
(let [[block label] x]
|
|
|
- (breadcrumb-fragment config block label))
|
|
|
+ (breadcrumb-fragment config block label opts))
|
|
|
[:span.opacity-70 "⋯"])))
|
|
|
(interpose (breadcrumb-separator)))]
|
|
|
- [:div.block-parents.flex-row.flex-1
|
|
|
+ [:div.breadcrumb.block-parents.flex-row.flex-1
|
|
|
{:class (when (seq breadcrumb)
|
|
|
(str (when-not (:search? config)
|
|
|
" my-2")
|
|
|
@@ -2214,7 +2239,9 @@
|
|
|
|
|
|
:else
|
|
|
nil)
|
|
|
- (assoc state ::control-show? (atom false))))
|
|
|
+ (assoc state
|
|
|
+ ::control-show? (atom false)
|
|
|
+ ::navigating-block (atom (:block/uuid block)))))
|
|
|
:should-update (fn [old-state new-state]
|
|
|
(let [compare-keys [:block/uuid :block/content :block/parent :block/collapsed?
|
|
|
:block/properties :block/left :block/children :block/_refs :ui/selected?]
|
|
|
@@ -2227,8 +2254,20 @@
|
|
|
(not= (select-keys (first (:rum/args old-state)) config-compare-keys)
|
|
|
(select-keys (first (:rum/args new-state)) config-compare-keys)))]
|
|
|
(boolean result)))}
|
|
|
- [state config {:block/keys [uuid children pre-block? top? refs heading-level level type format content] :as block}]
|
|
|
+ [state config block]
|
|
|
(let [repo (state/get-current-repo)
|
|
|
+ *navigating-block (get state ::navigating-block)
|
|
|
+ navigating-block (rum/react *navigating-block)
|
|
|
+ navigated? (and (not= (:block/uuid block) navigating-block) navigating-block)
|
|
|
+ block (if navigated?
|
|
|
+ (let [block (db/pull [:block/uuid navigating-block])
|
|
|
+ blocks (db/get-paginated-blocks repo (:db/id block)
|
|
|
+ {:scoped-block-id (:db/id block)})
|
|
|
+ tree (tree/blocks->vec-tree blocks (:block/uuid (first blocks)))]
|
|
|
+ (first tree))
|
|
|
+ block)
|
|
|
+ {:block/keys [uuid children pre-block? top? refs heading-level level type format content]} block
|
|
|
+ config (if navigated? (assoc config :id (str navigating-block)) config)
|
|
|
block (merge block (block/parse-title-and-body uuid format pre-block? content))
|
|
|
blocks-container-id (:blocks-container-id config)
|
|
|
config (update config :block merge block)
|
|
|
@@ -2295,8 +2334,9 @@
|
|
|
(assoc :data-query true))
|
|
|
|
|
|
(when (and ref? breadcrumb-show?)
|
|
|
- (block-parents config repo uuid {:show-page? false
|
|
|
- :indent? true}))
|
|
|
+ (breadcrumb config repo uuid {:show-page? false
|
|
|
+ :indent? true
|
|
|
+ :navigating-block *navigating-block}))
|
|
|
|
|
|
;; only render this for the first block in each container
|
|
|
(when top?
|
|
|
@@ -2956,7 +2996,8 @@
|
|
|
|
|
|
(rum/defcs blocks-container <
|
|
|
{:init (fn [state]
|
|
|
- (assoc state ::init-blocks-container-id (atom nil)))}
|
|
|
+ (assoc state
|
|
|
+ ::init-blocks-container-id (atom nil)))}
|
|
|
[state blocks config]
|
|
|
(let [*init-blocks-container-id (::init-blocks-container-id state)
|
|
|
blocks-container-id (if @*init-blocks-container-id
|
|
|
@@ -2974,6 +3015,29 @@
|
|
|
{:class (when doc-mode? "document-mode")}
|
|
|
(lazy-blocks config flat-blocks blocks->vec-tree)]))))
|
|
|
|
|
|
+(rum/defcs breadcrumb-with-container < rum/reactive
|
|
|
+ {:init (fn [state]
|
|
|
+ (assoc state ::navigating-block (atom (:block/uuid (ffirst (:rum/args state))))))}
|
|
|
+ [state blocks config]
|
|
|
+ (let [repo (state/get-current-repo)
|
|
|
+ *navigating-block (::navigating-block state)
|
|
|
+ navigating-block (rum/react *navigating-block)
|
|
|
+ block (first blocks)
|
|
|
+ navigated? (and (not= (:block/uuid block) navigating-block) navigating-block)
|
|
|
+ blocks (if navigated?
|
|
|
+ (let [block (db/pull [:block/uuid navigating-block])]
|
|
|
+ (db/get-paginated-blocks repo (:db/id block)
|
|
|
+ {:scoped-block-id (:db/id block)}))
|
|
|
+ blocks)]
|
|
|
+ [:div
|
|
|
+ (when (:breadcrumb-show? config)
|
|
|
+ (breadcrumb config (state/get-current-repo) navigating-block
|
|
|
+ {:show-page? false
|
|
|
+ :navigating-block *navigating-block}))
|
|
|
+ (blocks-container blocks (assoc config
|
|
|
+ :breadcrumb-show? false
|
|
|
+ :navigating-block *navigating-block))]))
|
|
|
+
|
|
|
;; headers to hiccup
|
|
|
(defn ->hiccup
|
|
|
[blocks config option]
|
|
|
@@ -2997,12 +3061,7 @@
|
|
|
(page-cp config page)
|
|
|
(when alias? [:span.text-sm.font-medium.opacity-50 " Alias"])]
|
|
|
(for [[_parent blocks] parent-blocks]
|
|
|
- (let [block (first blocks)]
|
|
|
- [:div
|
|
|
- (when (:breadcrumb-show? config)
|
|
|
- (block-parents config (state/get-current-repo) (:block/uuid block)
|
|
|
- {:show-page? false}))
|
|
|
- (blocks-container blocks (assoc config :breadcrumb-show? false))]))
|
|
|
+ (breadcrumb-with-container blocks config))
|
|
|
{})])))]
|
|
|
|
|
|
(and (:group-by-page? config)
|