wip: shape links

pull/5775/head
Tienson Qin 2022-05-18 13:39:00 +08:00
parent 76d2282791
commit ce7133e39d
6 changed files with 76 additions and 39 deletions

View File

@ -116,43 +116,48 @@
[repo search-q {:keys [type data alias]}]
(search-handler/add-search-to-recent! repo search-q)
(search-handler/clear-search!)
(let [whiteboard? (whiteboard-handler/whiteboard-mode?)]
(let [whiteboard? (whiteboard-handler/whiteboard-mode?)
search-mode (:search/mode @state/state)]
(case type
:graph-add-filter
(state/add-graph-search-filter! search-q)
:graph-add-filter
(state/add-graph-search-filter! search-q)
:new-page
(do
(page-handler/create! search-q {:redirect? (not whiteboard?)})
(when whiteboard?
(whiteboard-handler/create-page! search-q)))
:new-page
(do
(page-handler/create! search-q {:redirect? (not whiteboard?)})
(when whiteboard?
(whiteboard-handler/create-page! search-q)))
:page
(let [data (or alias data)]
(if whiteboard?
(whiteboard-handler/create-page! data)
(route/redirect-to-page! data)))
:go-to-whiteboard
(route/redirect! {:to :whiteboard
:path-params {:name search-q}})
:file
(route/redirect! {:to :file
:path-params {:path data}})
:page
(let [data (or alias data)]
(if whiteboard?
(whiteboard-handler/create-page! data)
(route/redirect-to-page! data)))
:block
(let [block-uuid (uuid (:block/uuid data))
collapsed? (db/parents-collapsed? repo block-uuid)
page (:block/page (db/entity [:block/uuid block-uuid]))
long-page? (block-handler/long-page? repo (:db/id page))]
(if whiteboard?
(whiteboard-handler/create-page! (str block-uuid))
(if page
(if (or collapsed? long-page?)
(route/redirect-to-page! block-uuid)
(route/redirect-to-page! (:block/name page) (str "ls-block-" (:block/uuid data))))
;; search indice outdated
(println "[Error] Block page missing: "
{:block-id block-uuid
:block (db/pull [:block/uuid block-uuid])}))))
nil))
:file
(route/redirect! {:to :file
:path-params {:path data}})
:block
(let [block-uuid (uuid (:block/uuid data))
collapsed? (db/parents-collapsed? repo block-uuid)
page (:block/page (db/entity [:block/uuid block-uuid]))
long-page? (block-handler/long-page? repo (:db/id page))]
(if whiteboard?
(whiteboard-handler/create-page! (str block-uuid))
(if page
(if (or collapsed? long-page?)
(route/redirect-to-page! block-uuid)
(route/redirect-to-page! (:block/name page) (str "ls-block-" (:block/uuid data))))
;; search indice outdated
(println "[Error] Block page missing: "
{:block-id block-uuid
:block (db/pull [:block/uuid block-uuid])}))))
nil))
(state/close-modal!))
(defn- search-on-shift-chosen
@ -199,6 +204,11 @@
[:div.text.font-bold (str (t :new-page) ": ")
[:span.ml-1 (str "\"" search-q "\"")]]
:go-to-whiteboard
[:div.text.font-bold (str (t :go-to-whiteboard) ": ")
[:span.ml-1 (str "\"" search-q "\"")]]
:page
[:span {:data-page-ref data}
(when alias
@ -247,9 +257,16 @@
all?)
[]
[{:type :new-page}])
result (if config/publishing?
go-to-whiteboard [{:type :go-to-whiteboard}]
result (cond
config/publishing?
(concat pages files blocks)
(concat new-page pages files blocks))
(= :whiteboard/link search-mode)
(concat pages blocks)
:else
(concat new-page go-to-whiteboard pages files blocks))
result (if (= search-mode :graph)
[{:type :graph-add-filter}]
result)
@ -344,8 +361,17 @@
(search-result-item "Page" original-name))
nil))}))])
(def default-placeholder
(if config/publishing? (t :search/publishing) (t :search)))
(defn default-placeholder
[search-mode]
(cond
config/publishing?
(t :search/publishing)
(= search-mode :whiteboard/link)
(t :whiteboard/link-whiteboard-or-block)
:else
(t :search)))
(rum/defcs search-modal < rum/reactive
(shortcut/disable-all-shortcuts)
@ -371,7 +397,7 @@
(t :graph-search)
:page
(t :page-search)
default-placeholder)
(default-placeholder search-mode))
:auto-complete (if (util/chrome?) "chrome-off" "off") ; off not working here
:value search-q
:on-change (fn [e]

View File

@ -37,5 +37,6 @@
tldr-name (str "draws/" name ".tldr")]
[:div.absolute.w-full.h-full
;; makes sure the whiteboard will not cover the borders
{:style {:padding "0.5px"}}
{:key name
:style {:padding "0.5px"}}
(tldraw-app {:file tldr-name})]))

View File

@ -208,9 +208,11 @@
:unlink "unlink"
:search/publishing "Search"
:search "Search or create page"
:whiteboard/link-whiteboard-or-block "Link whiteboard/page/block"
:page-search "Search in the current page"
:graph-search "Search graph"
:new-page "New page"
:go-to-whiteboard "Go to whiteboard"
:new-file "New file"
:new-graph "Add new graph"
:graph "Graph"

View File

@ -38,7 +38,10 @@
(draw-handler/save-draw! file s)))
:model data
:onApp (fn [app]
(state/set-state! [:ui/whiteboards (::id state)] app))})])))
(state/set-state! [:ui/whiteboards (::id state)] app)
(gobj/set app "pubEvent"
(fn [type & args]
(state/pub-event! (cons (keyword type) args)))))})])))
(rum/defc tldraw-app
[option]

View File

@ -401,6 +401,10 @@
template
{:target page}))))))
(defmethod handle :tldraw-link [[_ shapes]]
(route-handler/go-to-search! :whiteboard/link)
(state/set-state! :whiteboard/linked-shapes shapes))
(defn run!
[]
(let [chan (state/get-events-chan)]

View File

@ -135,6 +135,7 @@ const _ContextBar: TLContextBarComponent<Shape> = ({
) : null}
</>
)}
<a class="shape-link" onClick={() => app.pubEvent("tldraw-link", shapes)}>Link</a>
</div>
</HTMLContainer>
)