simplify pipeline

pull/10793/head
Tienson Qin 2024-01-11 20:17:11 +08:00
parent a81229576d
commit 96c9e8d7d5
7 changed files with 31 additions and 49 deletions

View File

@ -354,7 +354,7 @@
(defn insert!
[id value
{:keys [last-pattern postfix-fn backward-pos end-pattern backward-truncate-number
command only-breakline? skip-blank-value-check?]
command only-breakline?]
:as _option}]
(when-let [input (gdom/getElement id)]
(let [last-pattern (when-not (= last-pattern :skip-check)
@ -420,8 +420,8 @@
(str prefix postfix))
new-pos (- (count prefix)
(or backward-pos 0))]
(when (or (not (string/blank? new-value))
skip-blank-value-check?)
(when-not (and (not (string/blank? value))
(string/blank? new-value))
(state/set-block-content-and-last-pos! id new-value new-pos)
(cursor/move-cursor-to input new-pos)))))

View File

@ -718,8 +718,7 @@
(rum/defcs box < rum/reactive
{:init (fn [state]
(assoc state
::id (str (random-uuid))))
(assoc state ::id (str (random-uuid))))
:did-mount (fn [state]
(state/set-editor-args! (:rum/args state))
state)}

View File

@ -13,7 +13,6 @@
[goog.dom :as gdom]
[logseq.graph-parser.block :as gp-block]
[frontend.config :as config]
[frontend.util.drawer :as drawer]
[frontend.handler.file-based.property.util :as property-util]
[frontend.handler.property.util :as pu]
[dommy.core :as dom]
@ -247,10 +246,7 @@
:else
(subs content 0 pos))
content (if db-graph?
content
(-> (property-util/remove-built-in-properties (:block/format block) content)
(drawer/remove-logbook)))]
content (property-util/sanity-block-content repo (:block/format block) content)]
(state/clear-selection!)
(edit-block-aux repo block content block-node text-range opts)))))

View File

@ -2222,7 +2222,8 @@
(ui-outliner-tx/transact!
{:outliner-op :insert-blocks
:created-from-journal-template? journal?}
(save-current-block!)
(when-not (string/blank? (state/get-edit-content))
(save-current-block!))
(let [result (outliner-core/insert-blocks! repo (db/get-db false) blocks'
target
(assoc opts :sibling? sibling?'))]

View File

@ -5,7 +5,8 @@
[frontend.util :as util]
[frontend.util.cursor :as cursor]
[goog.dom :as gdom]
[frontend.db :as db]))
[frontend.db :as db]
[frontend.handler.file-based.property.util :as property-util]))
(defn did-mount!
[state]
@ -30,16 +31,22 @@
state)
(defn will-remount!
[_old-state state]
[old-state state]
(keyboards-handler/esc-save! state)
state)
(let [old-content (:block/content (:block (first (:rum/args old-state))))
new-content (:block/content (:block (first (:rum/args state))))
input (state/get-input)]
(when (and input (not= old-content new-content))
(set! (.-new-value input) new-content))
state))
(defn will-unmount
[state]
(let [{:keys [value] :as state} (editor-handler/get-state)]
(let [{:keys [value block node] :as state} (editor-handler/get-state)
new-value (or (and node (.-new-value node)) value)]
(editor-handler/clear-when-saved!)
(when (db/entity [:block/uuid (:block/uuid (:block state))]) ; block still exists
(editor-handler/save-block! state value)))
(when (db/entity [:block/uuid (:block/uuid block)]) ; block still exists
(editor-handler/save-block! state new-value)))
state)
(def lifecycle

View File

@ -8,7 +8,9 @@
[frontend.format.mldoc :as mldoc]
[frontend.db :as db]
[frontend.state :as state]
[frontend.util.cursor :as cursor]))
[frontend.util.cursor :as cursor]
[logseq.db.sqlite.util :as sqlite-util]
[frontend.util.drawer :as drawer]))
(defn hidden-properties
"These are properties hidden from user including built-in ones and ones
@ -236,3 +238,10 @@
(keep (fn [k] (when (contains? properties k) [k (get properties k)]))
(distinct properties-order))
properties*)))
(defn sanity-block-content
[repo format content]
(if (sqlite-util/db-based-graph? repo)
content
(-> (remove-built-in-properties format content)
(drawer/remove-logbook))))

View File

@ -1,11 +1,8 @@
(ns frontend.modules.outliner.pipeline
(:require [clojure.string :as string]
[frontend.config :as config]
(:require [frontend.config :as config]
[frontend.db :as db]
[frontend.db.react :as react]
[frontend.handler.file-based.property.util :as property-util]
[frontend.state :as state]
[frontend.util.drawer :as drawer]
[frontend.modules.editor.undo-redo :as undo-redo]
[datascript.core :as d]
[frontend.handler.ui :as ui-handler]
@ -13,27 +10,6 @@
[logseq.db :as ldb]
[promesa.core :as p]))
(defn- reset-editing-block-content!
[tx-data]
(let [repo (state/get-current-repo)
db? (config/db-based-graph? repo)]
(when-let [edit-block (state/get-edit-block)]
(when-let [last-datom (-> (filter (fn [datom]
(and (= :block/content (:a datom))
(= (:e datom) (:db/id edit-block)))) tx-data)
last)]
(when-let [input (state/get-input)]
(when (:added last-datom)
(let [entity (db/entity (:e last-datom))
db-content (:block/content entity)
content (if db? db-content
(->> db-content
(property-util/remove-built-in-properties (or (:block/format entity) :markdown))
drawer/remove-logbook))]
(when (not= (string/trim content)
(string/trim (.-value input)))
(state/set-edit-content! input content)))))))))
(defn store-undo-data!
[{:keys [tx-meta] :as opts}]
(when-not config/test?
@ -94,12 +70,6 @@
(react/clear-query-state!)
(ui-handler/re-render-root!))
(do
(try
(reset-editing-block-content! tx-data)
(catch :default e
(prn :reset-editing-block-content)
(js/console.error e)))
(when-not (:graph/importing @state/state)
(react/refresh! repo tx-report affected-keys)