mirror of https://github.com/logseq/logseq
fix: /query /calculator not works
We still need to save block content changes when exiting the editor, previously, we handled both :on-blur and :Escape, but not editor unmount. Also disabled /Zotero and /Draw for db graphs.experiment/tanstack-table
parent
33977ee836
commit
43bd6cacb5
|
@ -329,18 +329,20 @@
|
|||
[:editor/exit]]
|
||||
query-doc
|
||||
"ADVANCED"]
|
||||
["Zotero" (zotero-steps) "Import Zotero journal article"]
|
||||
(when-not db?
|
||||
["Zotero" (zotero-steps) "Import Zotero journal article"])
|
||||
["Query function" [[:editor/input "{{function }}" {:backward-pos 2}]] "Create a query function"]
|
||||
["Calculator" [[:editor/input "```calc\n\n```" {:type "block"
|
||||
:backward-pos 4}]
|
||||
[:codemirror/focus]] "Insert a calculator"]
|
||||
["Draw" (fn []
|
||||
(let [file (draw/file-name)
|
||||
path (str common-config/default-draw-directory "/" file)
|
||||
text (page-ref/->page-ref path)]
|
||||
(p/let [_ (draw/create-draw-with-default-content path)]
|
||||
(println "draw file created, " path))
|
||||
text)) "Draw a graph with Excalidraw"]
|
||||
(when-not db?
|
||||
["Draw" (fn []
|
||||
(let [file (draw/file-name)
|
||||
path (str common-config/default-draw-directory "/" file)
|
||||
text (page-ref/->page-ref path)]
|
||||
(p/let [_ (draw/create-draw-with-default-content path)]
|
||||
(println "draw file created, " path))
|
||||
text)) "Draw a graph with Excalidraw"])
|
||||
|
||||
(cond
|
||||
(and (util/electron?) (config/local-file-based-graph? (state/get-current-repo)))
|
||||
|
@ -360,8 +362,9 @@
|
|||
|
||||
["Embed Twitter tweet" [[:editor/input "{{tweet }}" {:last-pattern command-trigger
|
||||
:backward-pos 2}]]]
|
||||
["Add new property" [[:editor/clear-current-slash]
|
||||
[:editor/new-property]]]]
|
||||
(when db?
|
||||
["Add new property" [[:editor/clear-current-slash]
|
||||
[:editor/new-property]]])]
|
||||
|
||||
(let [commands (cond->> @*extend-slash-commands
|
||||
db?
|
||||
|
@ -814,9 +817,7 @@
|
|||
(.click input-file)))
|
||||
|
||||
(defmethod handle-step :editor/exit [[_]]
|
||||
(p/do!
|
||||
(state/pub-event! [:editor/save-current-block])
|
||||
(state/clear-edit!)))
|
||||
(state/clear-edit!))
|
||||
|
||||
(defmethod handle-step :editor/new-property [[_]]
|
||||
(state/pub-event! [:editor/new-property]))
|
||||
|
|
|
@ -2482,7 +2482,7 @@
|
|||
(when-let [container (gdom/getElement "app-container")]
|
||||
(dom/remove-class! container "blocks-selection-mode"))
|
||||
(p/do!
|
||||
(editor-handler/save-block! (editor-handler/get-state) value)
|
||||
(editor-handler/save-block! repo (:block/uuid block) value)
|
||||
(when-not (and edit-next-block? (not select?))
|
||||
(editor-handler/escape-editing select?))
|
||||
(some-> config :on-escape-editing
|
||||
|
|
|
@ -808,8 +808,10 @@
|
|||
nil)]))
|
||||
|
||||
(defn- editor-on-blur
|
||||
[^js e *ref]
|
||||
(when-not (= @*ref js/document.activeElement)
|
||||
[^js e *ref & {:keys [unmount? block *blur?]}]
|
||||
(when (or (not= @*ref js/document.activeElement) ; same activeElement when switching apps
|
||||
;; handle unmount if only on-blur and ESC not handled
|
||||
(and unmount? (and (:db/id block) (nil? (:db/id (state/get-edit-block))))))
|
||||
(cond
|
||||
(let [action (state/get-editor-action)]
|
||||
(or (contains?
|
||||
|
@ -829,12 +831,14 @@
|
|||
:else
|
||||
(let [{:keys [on-hide value]} (editor-handler/get-state)]
|
||||
(when on-hide
|
||||
(when *blur? (reset! *blur? true))
|
||||
(on-hide value :blur))))))
|
||||
|
||||
(rum/defcs box < rum/reactive
|
||||
{:init (fn [state]
|
||||
(assoc state ::id (str (random-uuid))
|
||||
::ref (atom nil)))
|
||||
::ref (atom nil)
|
||||
::blur? (atom false)))
|
||||
:did-mount (fn [state]
|
||||
(state/set-editor-args! (:rum/args state))
|
||||
state)}
|
||||
|
@ -842,8 +846,10 @@
|
|||
lifecycle/lifecycle
|
||||
[state {:keys [format block parent-block on-hide]} id config]
|
||||
(let [*ref (::ref state)
|
||||
*blur? (::blur? state)
|
||||
content (state/sub-edit-content (:block/uuid block))
|
||||
heading-class (get-editor-style-class block content format)
|
||||
on-blur (get config :on-blur editor-on-blur)
|
||||
opts (cond->
|
||||
{:id id
|
||||
:ref #(reset! *ref %)
|
||||
|
@ -854,14 +860,18 @@
|
|||
:on-change (editor-handler/editor-on-change! block id search-timeout)
|
||||
:on-paste (paste-handler/editor-on-paste! id)
|
||||
:on-blur (fn [e]
|
||||
(if-let [on-blur (:on-blur config)]
|
||||
(on-blur e)
|
||||
(editor-on-blur e *ref)))
|
||||
(on-blur e *ref {:*blur? *blur?}))
|
||||
:on-unmount (fn []
|
||||
(when-not @*blur?
|
||||
(on-blur nil *ref {:unmount? true
|
||||
:block block
|
||||
:*blur? *blur?})))
|
||||
:on-key-down (fn [e]
|
||||
(if-let [on-key-down (:on-key-down config)]
|
||||
(on-key-down e)
|
||||
(when (and (= (util/ekey e) "Escape") on-hide)
|
||||
(when-not (exist-editor-commands-popup?)
|
||||
(reset! *blur? true)
|
||||
(on-hide content :esc)))))
|
||||
:auto-focus true
|
||||
:class heading-class}
|
||||
|
|
|
@ -95,19 +95,23 @@
|
|||
(.setAttribute el "aria-label" "editing block")
|
||||
(doto el
|
||||
(.addEventListener "select"
|
||||
#(let [start (util/get-selection-start el)
|
||||
end (util/get-selection-end el)]
|
||||
(when (and start end)
|
||||
(when-let [e (and (not= start end)
|
||||
(let [caret-pos (cursor/get-caret-pos el)]
|
||||
{:caret caret-pos
|
||||
:start start :end end
|
||||
:text (. (.-value el) substring start end)
|
||||
:point (select-keys (or @*mouse-point caret-pos) [:x :y])}))]
|
||||
(plugin-handler/hook-plugin-editor :input-selection-end (bean/->js e))
|
||||
(vreset! *mouse-point nil)))))
|
||||
#(let [start (util/get-selection-start el)
|
||||
end (util/get-selection-end el)]
|
||||
(when (and start end)
|
||||
(when-let [e (and (not= start end)
|
||||
(let [caret-pos (cursor/get-caret-pos el)]
|
||||
{:caret caret-pos
|
||||
:start start :end end
|
||||
:text (. (.-value el) substring start end)
|
||||
:point (select-keys (or @*mouse-point caret-pos) [:x :y])}))]
|
||||
(plugin-handler/hook-plugin-editor :input-selection-end (bean/->js e))
|
||||
(vreset! *mouse-point nil)))))
|
||||
(.addEventListener "mouseup" #(vreset! *mouse-point {:x (.-x %) :y (.-y %)}))))
|
||||
state)}
|
||||
state)
|
||||
:will-unmount (fn [state]
|
||||
(when-let [on-unmount (:on-unmount (first (:rum/args state)))]
|
||||
(on-unmount))
|
||||
state)}
|
||||
[{:keys [on-change] :as props}]
|
||||
(let [skip-composition? (state/sub :editor/action)
|
||||
on-composition (fn [e]
|
||||
|
@ -119,11 +123,11 @@
|
|||
(on-change e))
|
||||
(state/set-editor-in-composition! true))))
|
||||
props (assoc props
|
||||
:on-change (fn [e] (when-not (state/editor-in-composition?)
|
||||
(on-change e)))
|
||||
:on-composition-start on-composition
|
||||
:on-composition-update on-composition
|
||||
:on-composition-end on-composition)]
|
||||
:on-change (fn [e] (when-not (state/editor-in-composition?)
|
||||
(on-change e)))
|
||||
:on-composition-start on-composition
|
||||
:on-composition-update on-composition
|
||||
:on-composition-end on-composition)]
|
||||
(textarea props)))
|
||||
|
||||
(rum/defc dropdown-content-wrapper
|
||||
|
|
Loading…
Reference in New Issue