Simply editor save logic

Triggers save-current-block! on-blur instead of relying on react
lifecycle.
pull/10793/head
Tienson Qin 2024-01-10 23:05:48 +08:00
parent 5cad97c617
commit b50145be4e
5 changed files with 8 additions and 19 deletions

View File

@ -2496,9 +2496,9 @@
:format format
:on-hide (fn [value event]
(when (= event :esc)
(editor-handler/save-block! (editor-handler/get-state) value)
(let [select? (not (string/includes? value "```"))]
(editor-handler/escape-editing select?))))}
(p/let [_ (editor-handler/save-block! (editor-handler/get-state) value)]
(let [select? (not (string/includes? value "```"))]
(editor-handler/escape-editing select?)))))}
edit-input-id
config))]
(if (and named? (seq (:block/tags block)) db-based?)

View File

@ -736,6 +736,7 @@
:on-click (editor-handler/editor-on-click! id)
:on-change (editor-handler/editor-on-change! block id search-timeout)
:on-paste (paste-handler/editor-on-paste! id)
:on-blur (fn [] (editor-handler/save-current-block!))
:auto-focus false
:class heading-class}
(some? parent-block)

View File

@ -281,7 +281,6 @@
(when-not (and (:create-today-journal? tx-meta)
(:today-journal-name tx-meta)
(d/entity @conn [:block/name (:today-journal-name tx-meta)])) ; today journal created already
;; (prn :debug :transact :tx-data tx-data :tx-meta tx-meta')
(worker-util/profile "Worker db transact"
(ldb/transact! conn tx-data tx-meta')))
nil)

View File

@ -32,9 +32,7 @@
:else
(let [{:keys [on-hide value]} (editor-handler/get-state)]
(when on-hide
(on-hide value event))
(when (contains? #{:esc :visibilitychange :click} event)
(state/clear-edit!)))))
(on-hide value event)))))
:node (gdom/getElement id)
;; :visibilitychange? true
)))

View File

@ -1,11 +1,10 @@
(ns ^:no-doc frontend.handler.editor.lifecycle
(:require [frontend.handler.editor :as editor-handler :refer [get-state]]
(:require [frontend.handler.editor :as editor-handler]
[frontend.handler.editor.keyboards :as keyboards-handler]
[frontend.state :as state]
[frontend.util :as util]
[frontend.util.cursor :as cursor]
[goog.dom :as gdom]
[frontend.db :as db]))
[goog.dom :as gdom]))
(defn did-mount!
[state]
@ -38,15 +37,7 @@
(defn will-unmount
[state]
(let [{:keys [value]} (get-state)]
(editor-handler/clear-when-saved!)
(when (and
(not (contains? #{:insert :indent-outdent :auto-save :undo :redo :delete} (state/get-editor-op)))
;; Don't trigger auto-save if the latest op is undo or redo
(not (contains? #{:delete :undo :redo :paste-blocks} (state/get-editor-latest-op))))
(let [state (get-state)]
(when (db/entity [:block/uuid (:block/uuid (:block state))]) ; block still exists
(editor-handler/save-block! state value)))))
(editor-handler/clear-when-saved!)
state)
(def lifecycle