mirror of https://github.com/logseq/logseq
simplify pipeline
parent
a81229576d
commit
96c9e8d7d5
|
@ -354,7 +354,7 @@
|
||||||
(defn insert!
|
(defn insert!
|
||||||
[id value
|
[id value
|
||||||
{:keys [last-pattern postfix-fn backward-pos end-pattern backward-truncate-number
|
{:keys [last-pattern postfix-fn backward-pos end-pattern backward-truncate-number
|
||||||
command only-breakline? skip-blank-value-check?]
|
command only-breakline?]
|
||||||
:as _option}]
|
:as _option}]
|
||||||
(when-let [input (gdom/getElement id)]
|
(when-let [input (gdom/getElement id)]
|
||||||
(let [last-pattern (when-not (= last-pattern :skip-check)
|
(let [last-pattern (when-not (= last-pattern :skip-check)
|
||||||
|
@ -420,8 +420,8 @@
|
||||||
(str prefix postfix))
|
(str prefix postfix))
|
||||||
new-pos (- (count prefix)
|
new-pos (- (count prefix)
|
||||||
(or backward-pos 0))]
|
(or backward-pos 0))]
|
||||||
(when (or (not (string/blank? new-value))
|
(when-not (and (not (string/blank? value))
|
||||||
skip-blank-value-check?)
|
(string/blank? new-value))
|
||||||
(state/set-block-content-and-last-pos! id new-value new-pos)
|
(state/set-block-content-and-last-pos! id new-value new-pos)
|
||||||
(cursor/move-cursor-to input new-pos)))))
|
(cursor/move-cursor-to input new-pos)))))
|
||||||
|
|
||||||
|
|
|
@ -718,8 +718,7 @@
|
||||||
|
|
||||||
(rum/defcs box < rum/reactive
|
(rum/defcs box < rum/reactive
|
||||||
{:init (fn [state]
|
{:init (fn [state]
|
||||||
(assoc state
|
(assoc state ::id (str (random-uuid))))
|
||||||
::id (str (random-uuid))))
|
|
||||||
:did-mount (fn [state]
|
:did-mount (fn [state]
|
||||||
(state/set-editor-args! (:rum/args state))
|
(state/set-editor-args! (:rum/args state))
|
||||||
state)}
|
state)}
|
||||||
|
|
|
@ -13,7 +13,6 @@
|
||||||
[goog.dom :as gdom]
|
[goog.dom :as gdom]
|
||||||
[logseq.graph-parser.block :as gp-block]
|
[logseq.graph-parser.block :as gp-block]
|
||||||
[frontend.config :as config]
|
[frontend.config :as config]
|
||||||
[frontend.util.drawer :as drawer]
|
|
||||||
[frontend.handler.file-based.property.util :as property-util]
|
[frontend.handler.file-based.property.util :as property-util]
|
||||||
[frontend.handler.property.util :as pu]
|
[frontend.handler.property.util :as pu]
|
||||||
[dommy.core :as dom]
|
[dommy.core :as dom]
|
||||||
|
@ -247,10 +246,7 @@
|
||||||
|
|
||||||
:else
|
:else
|
||||||
(subs content 0 pos))
|
(subs content 0 pos))
|
||||||
content (if db-graph?
|
content (property-util/sanity-block-content repo (:block/format block) content)]
|
||||||
content
|
|
||||||
(-> (property-util/remove-built-in-properties (:block/format block) content)
|
|
||||||
(drawer/remove-logbook)))]
|
|
||||||
(state/clear-selection!)
|
(state/clear-selection!)
|
||||||
(edit-block-aux repo block content block-node text-range opts)))))
|
(edit-block-aux repo block content block-node text-range opts)))))
|
||||||
|
|
||||||
|
|
|
@ -2222,7 +2222,8 @@
|
||||||
(ui-outliner-tx/transact!
|
(ui-outliner-tx/transact!
|
||||||
{:outliner-op :insert-blocks
|
{:outliner-op :insert-blocks
|
||||||
:created-from-journal-template? journal?}
|
: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'
|
(let [result (outliner-core/insert-blocks! repo (db/get-db false) blocks'
|
||||||
target
|
target
|
||||||
(assoc opts :sibling? sibling?'))]
|
(assoc opts :sibling? sibling?'))]
|
||||||
|
|
|
@ -5,7 +5,8 @@
|
||||||
[frontend.util :as util]
|
[frontend.util :as util]
|
||||||
[frontend.util.cursor :as cursor]
|
[frontend.util.cursor :as cursor]
|
||||||
[goog.dom :as gdom]
|
[goog.dom :as gdom]
|
||||||
[frontend.db :as db]))
|
[frontend.db :as db]
|
||||||
|
[frontend.handler.file-based.property.util :as property-util]))
|
||||||
|
|
||||||
(defn did-mount!
|
(defn did-mount!
|
||||||
[state]
|
[state]
|
||||||
|
@ -30,16 +31,22 @@
|
||||||
state)
|
state)
|
||||||
|
|
||||||
(defn will-remount!
|
(defn will-remount!
|
||||||
[_old-state state]
|
[old-state state]
|
||||||
(keyboards-handler/esc-save! 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
|
(defn will-unmount
|
||||||
[state]
|
[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!)
|
(editor-handler/clear-when-saved!)
|
||||||
(when (db/entity [:block/uuid (:block/uuid (:block state))]) ; block still exists
|
(when (db/entity [:block/uuid (:block/uuid block)]) ; block still exists
|
||||||
(editor-handler/save-block! state value)))
|
(editor-handler/save-block! state new-value)))
|
||||||
state)
|
state)
|
||||||
|
|
||||||
(def lifecycle
|
(def lifecycle
|
||||||
|
|
|
@ -8,7 +8,9 @@
|
||||||
[frontend.format.mldoc :as mldoc]
|
[frontend.format.mldoc :as mldoc]
|
||||||
[frontend.db :as db]
|
[frontend.db :as db]
|
||||||
[frontend.state :as state]
|
[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
|
(defn hidden-properties
|
||||||
"These are properties hidden from user including built-in ones and ones
|
"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)]))
|
(keep (fn [k] (when (contains? properties k) [k (get properties k)]))
|
||||||
(distinct properties-order))
|
(distinct properties-order))
|
||||||
properties*)))
|
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))))
|
||||||
|
|
|
@ -1,11 +1,8 @@
|
||||||
(ns frontend.modules.outliner.pipeline
|
(ns frontend.modules.outliner.pipeline
|
||||||
(:require [clojure.string :as string]
|
(:require [frontend.config :as config]
|
||||||
[frontend.config :as config]
|
|
||||||
[frontend.db :as db]
|
[frontend.db :as db]
|
||||||
[frontend.db.react :as react]
|
[frontend.db.react :as react]
|
||||||
[frontend.handler.file-based.property.util :as property-util]
|
|
||||||
[frontend.state :as state]
|
[frontend.state :as state]
|
||||||
[frontend.util.drawer :as drawer]
|
|
||||||
[frontend.modules.editor.undo-redo :as undo-redo]
|
[frontend.modules.editor.undo-redo :as undo-redo]
|
||||||
[datascript.core :as d]
|
[datascript.core :as d]
|
||||||
[frontend.handler.ui :as ui-handler]
|
[frontend.handler.ui :as ui-handler]
|
||||||
|
@ -13,27 +10,6 @@
|
||||||
[logseq.db :as ldb]
|
[logseq.db :as ldb]
|
||||||
[promesa.core :as p]))
|
[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!
|
(defn store-undo-data!
|
||||||
[{:keys [tx-meta] :as opts}]
|
[{:keys [tx-meta] :as opts}]
|
||||||
(when-not config/test?
|
(when-not config/test?
|
||||||
|
@ -94,12 +70,6 @@
|
||||||
(react/clear-query-state!)
|
(react/clear-query-state!)
|
||||||
(ui-handler/re-render-root!))
|
(ui-handler/re-render-root!))
|
||||||
(do
|
(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)
|
(when-not (:graph/importing @state/state)
|
||||||
(react/refresh! repo tx-report affected-keys)
|
(react/refresh! repo tx-report affected-keys)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue