Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(editor): drag and drop to dummy page #10292

Merged
merged 1 commit into from Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
44 changes: 33 additions & 11 deletions src/main/frontend/components/page.cljs
Expand Up @@ -2,14 +2,14 @@
(:require ["/frontend/utils" :as utils]
[clojure.string :as string]
[frontend.components.block :as component-block]
[frontend.components.query :as query]
[frontend.components.content :as content]
[frontend.components.editor :as editor]
[frontend.components.hierarchy :as hierarchy]
[frontend.components.plugins :as plugins]
[frontend.components.query :as query]
[frontend.components.reference :as reference]
[frontend.components.svg :as svg]
[frontend.components.scheduled-deadlines :as scheduled]
[frontend.components.svg :as svg]
[frontend.config :as config]
[frontend.context.i18n :refer [t]]
[frontend.date :as date]
Expand All @@ -21,6 +21,7 @@
[frontend.format.block :as block]
[frontend.handler.common :as common-handler]
[frontend.handler.config :as config-handler]
[frontend.handler.dnd :as dnd]
[frontend.handler.editor :as editor-handler]
[frontend.handler.graph :as graph-handler]
[frontend.handler.notification :as notification]
Expand All @@ -34,12 +35,13 @@
[frontend.util :as util]
[frontend.util.text :as text-util]
[goog.object :as gobj]
[logseq.graph-parser.mldoc :as gp-mldoc]
[logseq.graph-parser.util :as gp-util]
[logseq.graph-parser.util.page-ref :as page-ref]
[medley.core :as medley]
[promesa.core :as p]
[reitit.frontend.easy :as rfe]
[rum.core :as rum]
[logseq.graph-parser.util.page-ref :as page-ref]
[logseq.graph-parser.mldoc :as gp-mldoc]))
[rum.core :as rum]))

(defn- get-page-name
[state]
Expand Down Expand Up @@ -109,19 +111,39 @@

(rum/defc dummy-block
[page-name]
(let [handler-fn (fn []
(let [block (editor-handler/insert-first-page-block-if-not-exists! page-name {:redirect? false})]
(js/setTimeout #(editor-handler/edit-block! block :max (:block/uuid block)) 0)))]
[:div.ls-block.flex-1.flex-col.rounded-sm {:style {:width "100%"}}
(let [[hover set-hover!] (rum/use-state false)
click-handler-fn (fn []
(let [block (editor-handler/insert-first-page-block-if-not-exists! page-name {:redirect? false})]
(js/setTimeout #(editor-handler/edit-block! block :max (:block/uuid block)) 0)))
drop-handler-fn (fn [^js event]
(util/stop event)
(p/let [block-uuids (state/get-selection-block-ids)
lookup-refs (map (fn [id] [:block/uuid id]) block-uuids)
selected (db/pull-many (state/get-current-repo) '[*] lookup-refs)
blocks (if (seq selected) selected [@component-block/*dragging-block])
_ (editor-handler/insert-first-page-block-if-not-exists! page-name {:redirect? false})]
(js/setTimeout #(let [target-block (db/pull (:db/id (db/get-page page-name)))]
(dnd/move-blocks event blocks target-block :sibling))
0)))]
[:div.ls-block.flex-1.flex-col.rounded-sm
{:style {:width "100%"
;; The same as .dnd-separator
:border-top (if hover
"3px solid #ccc"
nil)}}
[:div.flex.flex-row
[:div.flex.flex-row.items-center.mr-2.ml-1 {:style {:height 24}}
[:span.bullet-container.cursor
[:span.bullet]]]
[:div.flex.flex-1 {:tabIndex 0
:on-key-press (fn [e]
(when (= "Enter" (util/ekey e))
(handler-fn)))
:on-click handler-fn}
(click-handler-fn)))
:on-click click-handler-fn
:on-drag-enter #(set-hover! true)
:on-drag-over #(util/stop %)
:on-drop drop-handler-fn
:on-drag-leave #(set-hover! false)}
[:span.opacity-70
"Click here to edit..."]]]]))

Expand Down
2 changes: 1 addition & 1 deletion src/main/frontend/handler/dnd.cljs
@@ -1,5 +1,5 @@
(ns frontend.handler.dnd
"Provides fns for drag n drop"
"Provides fns for drag and drop"
(:require [frontend.handler.editor :as editor-handler]
[frontend.handler.editor.property :as editor-property]
[frontend.modules.outliner.core :as outliner-core]
Expand Down