Skip to content

Commit bbe6fa8

Browse files
committed
remove file based commands
1 parent 8d1fafb commit bbe6fa8

File tree

12 files changed

+128
-822
lines changed

12 files changed

+128
-822
lines changed

src/main/frontend/commands.cljs

Lines changed: 53 additions & 299 deletions
Large diffs are not rendered by default.

src/main/frontend/components/block.cljs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
[frontend.state :as state]
6161
[frontend.ui :as ui]
6262
[frontend.util :as util]
63-
[frontend.util.file-based.clock :as clock]
63+
[frontend.util.clock :as clock]
6464
[frontend.util.ref :as ref]
6565
[frontend.util.text :as text-util]
6666
[goog.dom :as gdom]

src/main/frontend/handler.cljs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
[frontend.persist-db.browser :as db-browser]
3939
[frontend.state :as state]
4040
[frontend.util :as util]
41-
[frontend.util.persist-var :as persist-var]
4241
[goog.object :as gobj]
4342
[lambdaisland.glogi :as log]
4443
[promesa.core :as p]))
@@ -193,10 +192,7 @@
193192
(reset! vector-search-flows/*infer-worker-ready true))))
194193
nil))))
195194

196-
(util/<app-wake-up-from-sleep-loop (atom false))
197-
198-
(when-not (util/mobile?)
199-
(persist-var/load-vars)))))
195+
(util/<app-wake-up-from-sleep-loop (atom false)))))
200196

201197
(defn stop! []
202198
(prn "stop!"))

src/main/frontend/handler/block.cljs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,14 @@
77
[frontend.db :as db]
88
[frontend.db.async :as db-async]
99
[frontend.db.model :as db-model]
10-
[frontend.handler.file-based.property.util :as property-util]
1110
[frontend.handler.property.util :as pu]
1211
[frontend.mobile.haptics :as haptics]
1312
[frontend.modules.outliner.op :as outliner-op]
1413
[frontend.modules.outliner.ui :as ui-outliner-tx]
1514
[frontend.state :as state]
1615
[frontend.util :as util]
17-
[frontend.util.file-based.drawer :as drawer]
1816
[goog.object :as gobj]
1917
[logseq.db :as ldb]
20-
[logseq.db.sqlite.util :as sqlite-util]
2118
[logseq.graph-parser.block :as gp-block]
2219
[logseq.outliner.core :as outliner-core]
2320
[logseq.outliner.op]
@@ -124,13 +121,6 @@
124121
:container-id container-id :direction direction :event event :pos pos}))
125122
(mark-last-input-time! repo)))
126123

127-
(defn sanity-block-content
128-
[repo format content]
129-
(if (sqlite-util/db-based-graph? repo)
130-
content
131-
(-> (property-util/remove-built-in-properties format content)
132-
(drawer/remove-logbook))))
133-
134124
(defn block-unique-title
135125
"Multiple pages/objects may have the same `:block/title`.
136126
Notice: this doesn't prevent for pages/objects that have the same tag or created by different clients."
@@ -205,8 +195,7 @@
205195
content
206196

207197
:else
208-
(subs content 0 pos))
209-
content (sanity-block-content repo (get block :block/format :markdown) content)]
198+
(subs content 0 pos))]
210199
(state/clear-selection!)
211200
(edit-block-aux repo block content text-range (assoc opts :pos pos))))))))
212201

src/main/frontend/handler/editor.cljs

Lines changed: 22 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
[frontend.template :as template]
4242
[frontend.util :as util]
4343
[frontend.util.cursor :as cursor]
44-
[frontend.util.file-based.drawer :as drawer]
4544
[frontend.util.keycode :as keycode]
4645
[frontend.util.list :as list]
4746
[frontend.util.ref :as ref]
@@ -66,7 +65,6 @@
6665
[logseq.graph-parser.block :as gp-block]
6766
[logseq.graph-parser.mldoc :as gp-mldoc]
6867
[logseq.graph-parser.property :as gp-property]
69-
[logseq.graph-parser.text :as text]
7068
[logseq.graph-parser.utf8 :as utf8]
7169
[logseq.outliner.core :as outliner-core]
7270
[logseq.outliner.property :as outliner-property]
@@ -287,17 +285,12 @@
287285
([block value
288286
{:keys [force?]
289287
:as opts}]
290-
(let [{:block/keys [uuid format repo title]} block
291-
format (or format :markdown)
288+
(let [{:block/keys [uuid format repo]} block
292289
repo (or repo (state/get-current-repo))
293-
format (or format (state/get-preferred-format))
294290
block-id (let [properties (:block/properties block)]
295291
(when (and (not (config/db-based-graph? repo)) (map? properties))
296292
(get properties :id)))
297-
content (if (config/db-based-graph? repo)
298-
(:block/title (db/entity (:db/id block)))
299-
(-> (property-file/remove-built-in-properties-when-file-based repo format title)
300-
(drawer/remove-logbook)))]
293+
content (:block/title (db/entity (:db/id block)))]
301294
(cond
302295
(another-block-with-same-id-exists? uuid block-id)
303296
(notification/show!
@@ -710,32 +703,11 @@
710703
(when-let [edit-block (state/get-edit-block)]
711704
(let [edit-input-id (state/get-edit-input-id)
712705
current-input (gdom/getElement edit-input-id)]
713-
(if (config/db-based-graph? (state/get-current-repo))
714-
(when-let [block (db/entity (:db/id edit-block))]
715-
(let [pos (state/get-edit-pos)]
716-
(p/do!
717-
(ui-outliner-tx/transact!
718-
{:outliner-op :cycle-todos}
719-
(db-based-cycle-todo! block))
720-
721-
;; FIXME: don't change current editor's position
722-
)))
723-
(let [content (state/get-edit-content)
724-
format (or (db/get-page-format (state/get-current-page))
725-
(state/get-preferred-format))
726-
[new-content marker] (status/cycle-marker content nil nil format (state/get-preferred-workflow))
727-
new-pos (commands/compute-pos-delta-when-change-marker
728-
content marker (cursor/pos current-input))]
729-
(state/set-edit-content! edit-input-id new-content)
730-
(cursor/move-cursor-to current-input new-pos))))))))
731-
732-
(defn set-priority
733-
[{:block/keys [priority title] :as block} new-priority]
734-
(when-not (config/db-based-graph? (state/get-current-repo))
735-
(let [new-content (string/replace-first title
736-
(util/format "[#%s]" priority)
737-
(util/format "[#%s]" new-priority))]
738-
(save-block-if-changed! block new-content))))
706+
(when-let [block (db/entity (:db/id edit-block))]
707+
(let [pos (state/get-edit-pos)]
708+
(ui-outliner-tx/transact!
709+
{:outliner-op :cycle-todos}
710+
(db-based-cycle-todo! block)))))))))
739711

740712
(defn delete-block-aux!
741713
[{:block/keys [uuid] :as _block}]
@@ -755,19 +727,10 @@
755727
{:prev-block sibling-entity
756728
:new-value (:block/title sibling-entity)
757729
:edit-block-f #(edit-block! sibling-entity :max)}
758-
(let [db? (config/db-based-graph? repo)
759-
original-content (if (= (:db/id sibling-entity) (:db/id (state/get-edit-block)))
730+
(let [original-content (if (= (:db/id sibling-entity) (:db/id (state/get-edit-block)))
760731
(state/get-edit-content)
761732
(:block/title sibling-entity))
762-
value' (if db?
763-
original-content
764-
(-> (property-file/remove-built-in-properties-when-file-based repo format original-content)
765-
(drawer/remove-logbook)))
766-
value (if db?
767-
value
768-
(->> value
769-
(property-file/remove-properties-when-file-based repo format)
770-
(drawer/remove-logbook)))
733+
value' original-content
771734
new-value (str value' value)
772735
tail-len (count value)
773736
pos (max
@@ -1453,15 +1416,6 @@
14531416
(js/console.error error)
14541417
(log/error :save-block-failed error)))))))
14551418

1456-
(defn- clean-content!
1457-
[repo format content]
1458-
(if (config/db-based-graph? repo)
1459-
content
1460-
(some->> (text/remove-level-spaces content format (config/get-block-pattern format))
1461-
(drawer/remove-logbook)
1462-
(property-file/remove-properties-when-file-based repo format)
1463-
string/trim)))
1464-
14651419
(defn delete-asset-of-block!
14661420
[{:keys [repo asset-block href full-text block-id local? delete-local?] :as _opts}]
14671421
(let [block (db-model/query-block-by-uuid block-id)
@@ -2629,8 +2583,7 @@
26292583
(when (and
26302584
uuid
26312585
(not (state/block-component-editing?))
2632-
(not= (clean-content! repo format title)
2633-
(string/trim value)))
2586+
(not= title (string/trim value)))
26342587
(save-block! repo uuid value))
26352588

26362589
(cond
@@ -2699,7 +2652,7 @@
26992652
(when sibling-block
27002653
(let [content (:block/title block)
27012654
value (state/get-edit-content)]
2702-
(when (and value (not= (clean-content! repo format content) (string/trim value)))
2655+
(when (and value (not= content (string/trim value)))
27032656
(save-block! repo uuid value)))
27042657
(let [sibling-block-id (dom/attr sibling-block "blockid")]
27052658
(cond
@@ -3869,19 +3822,15 @@
38693822

38703823
(defn replace-block-reference-with-content-at-point
38713824
[]
3872-
(let [repo (state/get-current-repo)]
3873-
(when-let [{:keys [start end link]} (thingatpt/block-ref-at-point)]
3874-
(when-let [block (db/entity [:block/uuid link])]
3875-
(let [block-content (:block/title block)
3876-
format (get block :block/format :markdown)
3877-
block-content-without-prop (-> (property-file/remove-properties-when-file-based repo format block-content)
3878-
(drawer/remove-logbook))]
3879-
(when-let [input (state/get-input)]
3880-
(when-let [current-block-content (gobj/get input "value")]
3881-
(let [block-content* (str (subs current-block-content 0 start)
3882-
block-content-without-prop
3883-
(subs current-block-content end))]
3884-
(state/set-block-content-and-last-pos! input block-content* 1)))))))))
3825+
(when-let [{:keys [start end link]} (thingatpt/block-ref-at-point)]
3826+
(when-let [block (db/entity [:block/uuid link])]
3827+
(let [block-content (:block/title block)]
3828+
(when-let [input (state/get-input)]
3829+
(when-let [current-block-content (gobj/get input "value")]
3830+
(let [block-content* (str (subs current-block-content 0 start)
3831+
block-content
3832+
(subs current-block-content end))]
3833+
(state/set-block-content-and-last-pos! input block-content* 1))))))))
38853834

38863835
(defn copy-current-ref
38873836
[block-id]
@@ -3903,13 +3852,9 @@
39033852
(defn replace-ref-with-text!
39043853
[block ref-id]
39053854
(when (and block ref-id)
3906-
(let [repo (state/get-current-repo)
3907-
match (ref/->block-ref ref-id)
3855+
(let [match (ref/->block-ref ref-id)
39083856
ref-block (db/entity [:block/uuid ref-id])
3909-
block-ref-content (->> (or (:block/title ref-block) "")
3910-
(property-file/remove-built-in-properties-when-file-based repo
3911-
(get ref-block :block/format :markdown))
3912-
(drawer/remove-logbook))
3857+
block-ref-content (or (:block/title ref-block) "")
39133858
content (string/replace-first (:block/title block) match
39143859
block-ref-content)]
39153860
(save-block! (state/get-current-repo)

src/main/frontend/util/clock.cljs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
(ns frontend.util.clock
2+
"Provides clock related functionality used by tasks"
3+
(:require [frontend.util :as util]))
4+
5+
(defn s->dhms-util
6+
"A function that returns the values for easier testing.
7+
Always in the order [days, hours, minutes, seconds]"
8+
[seconds]
9+
(let [days (quot (quot seconds 3600) 24)
10+
n (mod seconds (* 24 3600))
11+
hours (quot n 3600)
12+
n (mod n 3600)
13+
minutes (quot n 60)
14+
secs (mod n 60)]
15+
[days hours minutes secs]))
16+
17+
(defn seconds->days:hours:minutes:seconds
18+
[seconds]
19+
(let [[days hours minutes seconds] (s->dhms-util seconds)]
20+
(cond
21+
(> days 0)
22+
(util/format "%s%s"
23+
(if (zero? days) "" (str days "d"))
24+
(if (zero? hours) "" (str hours "h")))
25+
26+
(> minutes 0)
27+
(util/format "%s%s"
28+
(if (zero? hours) "" (str hours "h"))
29+
(if (zero? minutes) "" (str minutes "m")))
30+
:else
31+
(if (> seconds 0)
32+
(str seconds "s")
33+
""))))
34+
35+
(comment
36+
(defn minutes->hours:minutes
37+
[minutes]
38+
(let [hours (quot minutes 60)
39+
minutes (mod minutes 60)]
40+
(util/format "%02d:%02d" hours minutes)))
41+
42+
(defn seconds->hours:minutes:seconds
43+
[seconds]
44+
(let [hours (quot seconds 3600)
45+
minutes (quot (- seconds (* hours 3600)) 60)
46+
seconds (mod seconds 60)]
47+
(util/format "%02d:%02d:%02d" hours minutes seconds))))

0 commit comments

Comments
 (0)