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

View File

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

View File

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

View File

@ -38,7 +38,10 @@
(draw-handler/save-draw! file s))) (draw-handler/save-draw! file s)))
:model data :model data
:onApp (fn [app] :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 (rum/defc tldraw-app
[option] [option]

View File

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

View File

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