fix: save block when editor unmounts is dangerous

The block content will be overwritten in those cases:
1. deleting a block
2. paste blocks to an empty target block
3. undo/redo
experiment/tanstack-table
Tienson Qin 2024-06-20 00:55:05 +08:00
parent 71dc122a75
commit b1d4fb3b81
2 changed files with 4 additions and 7 deletions

View File

@ -816,7 +816,9 @@
(.click input-file)))
(defmethod handle-step :editor/exit [[_]]
(state/clear-edit!))
(p/do!
(state/pub-event! [:editor/save-current-block])
(state/clear-edit!)))
(defmethod handle-step :editor/new-property [[_]]
(state/pub-event! [:editor/new-property]))

View File

@ -854,12 +854,7 @@
::ref (atom nil)))
:did-mount (fn [state]
(state/set-editor-args! (:rum/args state))
state)
:will-unmount (fn [state]
(let [{:keys [block value]} (editor-handler/get-state)]
(when-not (= (:block/uuid block) (:editor/deleting-block @state/state)) ; don't save deleting block
(editor-handler/save-block! (state/get-current-repo) (:block/uuid block) value)))
state)}
state)}
(mixins/event-mixin
(fn [state]
(mixins/hide-when-esc-or-outside