From ec7a325bcbd8692f5d87fe01f0486bb5ce1b94bc Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Fri, 26 Dec 2025 11:39:23 +0800 Subject: [PATCH] more cleanup --- .carve/ignore | 16 +- package.json | 3 - .../logseq/tasks/dev/db_and_file_graphs.clj | 5 - src/electron/electron/handler.cljs | 28 ---- src/main/frontend/components/container.cljs | 72 ++------- src/main/frontend/components/repo.cljs | 27 +++- src/main/frontend/components/settings.cljs | 3 +- src/main/frontend/components/svg.cljs | 5 - src/main/frontend/components/theme.cljs | 7 +- src/main/frontend/date.cljs | 43 ------ src/main/frontend/db/async.cljs | 16 -- src/main/frontend/db/model.cljs | 34 +--- src/main/frontend/diff.cljs | 14 +- src/main/frontend/extensions/fsrs.cljs | 4 + src/main/frontend/external.cljs | 18 --- src/main/frontend/external/protocol.cljc | 9 -- src/main/frontend/external/roam.cljs | 145 ------------------ src/main/frontend/external/roam_export.cljs | 86 ----------- src/main/frontend/format/mldoc.cljs | 32 ---- src/main/frontend/handler/assets.cljs | 26 ---- src/main/frontend/handler/block.cljs | 30 ---- .../frontend/handler/db_based/export.cljs | 1 - src/main/frontend/handler/db_based/rtc.cljs | 4 +- src/main/frontend/handler/editor.cljs | 74 --------- src/main/frontend/handler/export/common.cljs | 9 +- src/main/frontend/handler/global_config.cljs | 5 - src/main/frontend/handler/import.cljs | 35 ----- src/main/frontend/handler/page.cljs | 1 - src/main/frontend/handler/query/builder.cljs | 17 +- src/main/frontend/handler/repo.cljs | 45 ++---- src/main/frontend/handler/route.cljs | 4 - src/main/frontend/handler/user.cljs | 25 --- src/main/frontend/mobile/util.cljs | 8 - src/main/frontend/rum.cljs | 22 --- src/main/frontend/search.cljs | 19 --- src/main/frontend/spec/storage.cljc | 3 +- src/main/frontend/state.cljs | 134 +--------------- src/main/frontend/ui.cljs | 19 --- src/main/frontend/util.cljc | 114 +++----------- src/main/frontend/util/cursor.cljs | 38 ++--- src/main/frontend/util/fs.cljs | 23 +-- src/main/frontend/util/page.cljs | 6 - src/main/frontend/util/text.cljs | 8 - src/main/frontend/worker/state.cljs | 11 -- src/test/frontend/external/roam_test.cljs | 35 ----- 45 files changed, 119 insertions(+), 1164 deletions(-) delete mode 100644 src/main/frontend/external.cljs delete mode 100644 src/main/frontend/external/protocol.cljc delete mode 100644 src/main/frontend/external/roam.cljs delete mode 100644 src/main/frontend/external/roam_export.cljs delete mode 100644 src/test/frontend/external/roam_test.cljs diff --git a/.carve/ignore b/.carve/ignore index c5765c96c1..13f9fb9a25 100644 --- a/.carve/ignore +++ b/.carve/ignore @@ -11,29 +11,15 @@ frontend.debug/defn frontend.debug/print ;; Lazily loaded frontend.extensions.code/editor -;; Lazily loaded -frontend.extensions.age-encryption/keygen -frontend.extensions.age-encryption/encrypt-with-x25519 -frontend.extensions.age-encryption/decrypt-with-x25519 -frontend.extensions.age-encryption/encrypt-with-user-passphrase -frontend.extensions.age-encryption/decrypt-with-user-passphrase -;; Lazily loaded -frontend.extensions.excalidraw/draw -;; Lazily loaded -frontend.extensions.tldraw/tldraw-app -frontend.extensions.tldraw/generate-preview ;; Referenced in commented TODO frontend.extensions.pdf.utils/get-page-bounding ;; For repl -frontend.extensions.zotero.api/item -;; For repl -frontend.external.roam/reset-state! -;; For repl logseq.graph-parser.mldoc/ast-export-markdown ;; Protocol fn wrapper that could be used frontend.fs/readdir ;; Referenced in TODO frontend.handler.metadata/update-properties! +frontend.handler.user/ (if (seq graphs) - (for [{:keys [root] :as graph} graphs] - (if-let [sync-meta (read-txid-info! root)] - (assoc graph - :sync-meta sync-meta - :GraphUUID (second sync-meta)) - graph)) - []) - ldb/write-transit-str))) - -(defmethod handle :readGraphTxIdInfo [_win [_ root]] - (read-txid-info! root)) - (defmethod handle :deleteGraph [_window [_ graph graph-name _db-based?]] (when graph-name (db/unlink-graph! graph) diff --git a/src/main/frontend/components/container.cljs b/src/main/frontend/components/container.cljs index fba935d28c..63aa9ef941 100644 --- a/src/main/frontend/components/container.cljs +++ b/src/main/frontend/components/container.cljs @@ -31,7 +31,6 @@ [frontend.version :refer [version]] [goog.dom :as gdom] [goog.object :as gobj] - [logseq.common.path :as path] [logseq.shui.dialog.core :as shui-dialog] [logseq.shui.hooks :as hooks] [logseq.shui.popup.core :as shui-popup] @@ -106,30 +105,9 @@ margin-less-pages? 0 onboarding-and-home? 0 :else 120)}} - main-content]) - - (comment - (when onboarding-and-home? - (onboarding/intro onboarding-and-home?)))]]])) + main-content])]]])) (defonce sidebar-inited? (atom false)) -;; TODO: simplify logic - -(rum/defc parsing-progress < rum/static - [state] - (let [finished (or (:finished state) 0) - total (:total state) - width (js/Math.round (* (.toFixed (/ finished total) 2) 100)) - display-filename (some-> (:current-parsing-file state) - not-empty - path/filename) - left-label [:div.flex.flex-row.font-bold - (t :parsing-files) - [:div.hidden.md:flex.flex-row - [:span.mr-1 ": "] - [:div.text-ellipsis-wrapper {:style {:max-width 300}} - display-filename]]]] - (ui/progress-bar-with-label width left-label (str finished "/" total)))) (rum/defc main-content < rum/reactive db-mixins/query {:init (fn [state] @@ -150,38 +128,24 @@ state)} [] (let [default-home (app-left-sidebar/get-default-home-if-valid) - current-repo (state/sub :git/current-repo) - loading-files? (when current-repo (state/sub [:repo/loading-files? current-repo])) - graph-parsing-state (state/sub [:graph/parsing-state current-repo])] - (cond - (or - (:graph-loading? graph-parsing-state) - (not= (:total graph-parsing-state) (:finished graph-parsing-state))) - [:div.flex.items-center.justify-center.full-height-without-header - [:div.flex-1 - (parsing-progress graph-parsing-state)]] + current-repo (state/sub :git/current-repo)] + [:div + (cond + (and default-home + (= :home (state/get-current-route)) + (not (state/route-has-p?)) + (:page default-home)) + (route-handler/redirect-to-page! (:page default-home)) - :else - [:div - (cond - (and default-home - (= :home (state/get-current-route)) - (not (state/route-has-p?)) - (:page default-home)) - (route-handler/redirect-to-page! (:page default-home)) + (or (not (state/enable-journals? current-repo)) + (let [latest-journals (db/get-latest-journals (state/get-current-repo) 1)] + (and config/publishing? + (not default-home) + (empty? latest-journals)))) + (route-handler/redirect! {:to :all-pages}) - (or (not (state/enable-journals? current-repo)) - (let [latest-journals (db/get-latest-journals (state/get-current-repo) 1)] - (and config/publishing? - (not default-home) - (empty? latest-journals)))) - (route-handler/redirect! {:to :all-pages}) - - loading-files? - (ui/loading (t :loading-files)) - - :else - (journal/all-journals))]))) + :else + (journal/all-journals))])) (defn- hide-context-menu-and-clear-selection [e & {:keys [esc?]}] @@ -413,7 +377,6 @@ left-sidebar-open? (state/sub :ui/left-sidebar-open?) wide-mode? (state/sub :ui/wide-mode?) ls-block-hl-colored? (state/sub :pdf/block-highlight-colored?) - onboarding-state (state/sub :file-sync/onboarding-state) right-sidebar-blocks (state/sub-right-sidebar-blocks) route-name (get-in route-match [:data :name]) margin-less-pages? (boolean (#{:graph} route-name)) @@ -442,7 +405,6 @@ :settings-open? settings-open? :sidebar-blocks-len (count right-sidebar-blocks) :system-theme? system-theme? - :onboarding-state onboarding-state :preferred-language preferred-language :on-click (fn [e] (editor-handler/unhighlight-blocks!) diff --git a/src/main/frontend/components/repo.cljs b/src/main/frontend/components/repo.cljs index 2fb02924b9..c15058eafd 100644 --- a/src/main/frontend/components/repo.cljs +++ b/src/main/frontend/components/repo.cljs @@ -137,7 +137,28 @@ (p/do! (rtc-flows/trigger-rtc-start repo) (rtc-handler/ (shui/dialog-confirm! + [:p.font-medium.-my-4 prompt-str + [:span.my-2.flex.font-normal.opacity-75 + [:small "⚠️ Notice that we can't recover this graph after being deleted. Make sure you have backups before deleting it."]]]) + (p/then + (fn [] + (let [> @@ -295,7 +316,7 @@ repos (state/sub [:me :repos]) rtc-graphs (state/sub :rtc/graphs) downloading-graph-id (state/sub :rtc/downloading-graph-uuid) - remotes-loading? (state/sub [:file-sync/remote-graphs :loading]) + remotes-loading? (state/sub :rtc/loading-graphs?) repos (sort-repos-with-metadata-local repos) repos (distinct (if (and (seq rtc-graphs) login?) diff --git a/src/main/frontend/components/settings.cljs b/src/main/frontend/components/settings.cljs index 2d1985d71d..8671157bd2 100644 --- a/src/main/frontend/components/settings.cljs +++ b/src/main/frontend/components/settings.cljs @@ -19,7 +19,6 @@ [frontend.handler.notification :as notification] [frontend.handler.plugin :as plugin-handler] [frontend.handler.property :as property-handler] - [frontend.handler.route :as route-handler] [frontend.handler.ui :as ui-handler] [frontend.handler.user :as user-handler] [frontend.mobile.util :as mobile-util] @@ -722,7 +721,7 @@ (rum/defc ^:large-vars/cleanup-todo settings-account < rum/reactive [] - (let [graph-usage (state/get-remote-graph-usage) + (let [graph-usage [] logged-in? (user-handler/logged-in?) user-info (state/get-user-info) paid-user? (#{"active" "on_trial" "cancelled"} (:LemonStatus user-info)) diff --git a/src/main/frontend/components/svg.cljs b/src/main/frontend/components/svg.cljs index f6efead5fc..26450bfead 100644 --- a/src/main/frontend/components/svg.cljs +++ b/src/main/frontend/components/svg.cljs @@ -157,11 +157,6 @@ :ry "6.13006" :rx "7.78547"}]])) -(def page - [:svg.h-5.w-4 {:viewBox "0 0 24 24", :fill "none", :xmlns "http://www.w3.org/2000/svg"} - [:path {:d "M2 0.5H6.78272L13.5 7.69708V18C13.5 18.8284 12.8284 19.5 12 19.5H2C1.17157 19.5 0.5 18.8284 0.5 18V2C0.5 1.17157 1.17157 0.5 2 0.5Z", :fill "var(--ls-active-primary-color)"}] - [:path {:d "M7 5.5V0L14 7.5H9C7.89543 7.5 7 6.60457 7 5.5Z", :fill "var(--ls-active-secondary-color)"}]]) - (def clock [:svg.h-5.w-5 {:fill "currentColor", :viewBox "0 0 20 20"} diff --git a/src/main/frontend/components/theme.cljs b/src/main/frontend/components/theme.cljs index 1332e2fee6..8168390c25 100644 --- a/src/main/frontend/components/theme.cljs +++ b/src/main/frontend/components/theme.cljs @@ -11,7 +11,6 @@ [frontend.handler.ui :as ui-handler] [frontend.rum :refer [use-mounted]] [frontend.state :as state] - [frontend.storage :as storage] [frontend.ui :as ui] [frontend.util :as util] [logseq.shui.hooks :as hooks] @@ -38,7 +37,7 @@ (rum/defc ^:large-vars/cleanup-todo container < rum/static [{:keys [route theme accent-color editor-font on-click current-repo db-restoring? - settings-open? sidebar-open? system-theme? sidebar-blocks-len onboarding-state preferred-language]} child] + settings-open? sidebar-open? system-theme? sidebar-blocks-len preferred-language]} child] (let [mounted-fn (use-mounted) [restored-sidebar? set-restored-sidebar?] (rum/use-state false)] @@ -145,10 +144,6 @@ (shui/dialog-close! :app-settings))) [settings-open?]) - (hooks/use-effect! - #(storage/set :file-sync/onboarding-state onboarding-state) - [onboarding-state]) - [:div#root-container.theme-container {:on-click on-click :tab-index -1} diff --git a/src/main/frontend/date.cljs b/src/main/frontend/date.cljs index b38d6cc94d..d2ee3c1f2a 100644 --- a/src/main/frontend/date.cljs +++ b/src/main/frontend/date.cljs @@ -20,7 +20,6 @@ (def custom-formatter (tf/formatter "yyyy-MM-dd'T'HH:mm:ssZZ")) (def ^:private mmm-do-yyyy-formatter (tf/formatter "MMM do, yyyy")) -(def ^:private yyyy-MM-dd-formatter (tf/formatter "yyyy-MM-dd")) (def ^:private yyyy-MM-dd-HH-mm-formatter (tf/formatter "yyyy-MM-dd HH:mm")) (defn journal-title-formatters @@ -50,14 +49,6 @@ (defn get-date-time-string-2 [] (tf/unparse custom-formatter-2 (tl/local-now))) -(def custom-formatter-3 (tf/formatter "yyyy-MM-dd E HH:mm")) -(defn get-date-time-string-3 [] - (tf/unparse custom-formatter-3 (tl/local-now))) - -(def custom-formatter-4 (tf/formatter "yyyy-MM-dd E HH:mm:ss")) -(defn get-date-time-string-4 [] - (tf/unparse custom-formatter-4 (tl/local-now))) - (defn journal-name ([] (journal-name (tl/local-now))) @@ -71,14 +62,6 @@ :format formatter}) (throw e)))))) -(defn journal-name-s [s] - (try - (journal-name (tf/parse yyyy-MM-dd-formatter s)) - (catch :default _e - (log/error :parse-journal-date {:message "Unable to parse date to journal name, skipping." - :date-str s}) - nil))) - (defn start-of-day [date] (t/date-time (t/year date) (t/month date) (t/day date))) @@ -94,20 +77,6 @@ [] (journal-name (t/minus (start-of-day (tl/local-now)) (t/days 1)))) -(defn get-local-date - [] - (let [date (js/Date.) - year (.getFullYear date) - month (inc (.getMonth date)) - day (.getDate date) - hour (.getHours date) - minute (.getMinutes date)] - {:year year - :month month - :day day - :hour hour - :minute minute})) - (defn get-current-time [] (let [d (js/Date.)] @@ -150,18 +119,6 @@ (def default-journal-filename-formatter common-date/default-journal-filename-formatter) -(defn journal-title->default - "Journal title to filename format" - [journal-title] - (let [formatter (if-let [format (state/get-journal-file-name-format)] - (tf/formatter format) - (tf/formatter default-journal-filename-formatter))] - (journal-title-> journal-title #(tf/unparse formatter %)))) - -(defn journal-title->custom-format - [journal-title] - (journal-title-> journal-title #(date-time-util/format % (state/get-date-formatter)))) - (defn int->local-time-2 [n] (tf/unparse diff --git a/src/main/frontend/db/async.cljs b/src/main/frontend/db/async.cljs index df3b88d4f5..ebcb56589a 100644 --- a/src/main/frontend/db/async.cljs +++ b/src/main/frontend/db/async.cljs @@ -158,12 +158,6 @@ [?refed-b :block/uuid ?refed-uuid] [?referee-b :block/refs ?refed-b]])) -(defn int journal-title)] @@ -229,16 +223,6 @@ :db/id db/entity))) -(defn custom-format page-name)] - (util/page-name-sanity-lc journal-name) - page-name) - - :else - (let [source-page (get-alias-source-page (state/get-current-repo) (:db/id page-entity))] - (or (:block/name source-page) - (:block/name page-entity) - page-name))))))) - (defn get-latest-journals ([n] (get-latest-journals (state/get-current-repo) n)) diff --git a/src/main/frontend/diff.cljs b/src/main/frontend/diff.cljs index f0318e5157..a020e373e7 100644 --- a/src/main/frontend/diff.cljs +++ b/src/main/frontend/diff.cljs @@ -1,17 +1,9 @@ (ns ^:no-doc frontend.diff (:require [clojure.string :as string] - ["diff" :as jsdiff] - [goog.object :as gobj] - [lambdaisland.glogi :as log] - [cljs-bean.core :as bean] [frontend.util :as util] - [logseq.common.util :as common-util] - [frontend.util.text :as text-util])) - -(defn diff - [s1 s2] - (-> ((gobj/get jsdiff "diffLines") s1 s2 (clj->js {"newlineIsToken" true})) - bean/->clj)) + [frontend.util.text :as text-util] + [lambdaisland.glogi :as log] + [logseq.common.util :as common-util])) (def inline-special-chars #{\* \_ \/ \` \+ \^ \~ \$}) diff --git a/src/main/frontend/extensions/fsrs.cljs b/src/main/frontend/extensions/fsrs.cljs index e3b18215a4..f60ffd6f4f 100644 --- a/src/main/frontend/extensions/fsrs.cljs +++ b/src/main/frontend/extensions/fsrs.cljs @@ -1,6 +1,7 @@ (ns frontend.extensions.fsrs "Flashcards functions based on FSRS, only works in db-based graphs" (:require [clojure.string :as string] + [frontend.commands :as commands] [frontend.common.missionary :as c.m] [frontend.components.block :as component-block] [frontend.components.macro :as component-macro] @@ -25,6 +26,9 @@ [rum.core :as rum] [tick.core :as tick])) +(commands/register-slash-command ["Cloze" + [[:editor/input "{{cloze }}" {:backward-pos 2}]]]) + (def ^:private instant->inst-ms (comp inst-ms tick/inst)) (defn- inst-ms->instant [ms] (tick/instant (js/Date. ms))) diff --git a/src/main/frontend/external.cljs b/src/main/frontend/external.cljs deleted file mode 100644 index 39e8524e85..0000000000 --- a/src/main/frontend/external.cljs +++ /dev/null @@ -1,18 +0,0 @@ -(ns frontend.external - "Handles importing from external services" - (:require [frontend.external.roam :refer [->Roam]] - [frontend.external.protocol :as protocol])) - -(defonce roam-record (->Roam)) - -(defn get-record - [type] - (case type - :roam - roam-record - nil)) - -(defn to-markdown-files - [type content config] - (when-let [record (get-record (keyword type))] - (protocol/toMarkdownFiles record content config))) diff --git a/src/main/frontend/external/protocol.cljc b/src/main/frontend/external/protocol.cljc deleted file mode 100644 index 388fe4e1f7..0000000000 --- a/src/main/frontend/external/protocol.cljc +++ /dev/null @@ -1,9 +0,0 @@ -(ns ^:no-doc frontend.external.protocol) - -(defprotocol External - (toMarkdownFiles [this content config] - "Should return a map of markdown's file name to contents.")) - - ;; Long-term goal: - ;; (toMldocAst [this content]) - ;; (fromMldocAst [this ast]) diff --git a/src/main/frontend/external/roam.cljs b/src/main/frontend/external/roam.cljs deleted file mode 100644 index 8e772cf276..0000000000 --- a/src/main/frontend/external/roam.cljs +++ /dev/null @@ -1,145 +0,0 @@ -(ns frontend.external.roam - "Provides roam import by implementing the external protocol" - (:require [cljs-bean.core :as bean] - [frontend.external.protocol :as protocol] - [frontend.date :as date] - [clojure.walk :as walk] - [clojure.string :as string] - [goog.string :as gstring] - [logseq.common.util.block-ref :as block-ref] - [logseq.common.util :as common-util] - [logseq.graph-parser.text :as text])) - -(defonce all-refed-uids (atom #{})) -(defonce uid->uuid (atom {})) - -(defn reset-state! - [] - (reset! all-refed-uids #{}) - (reset! uid->uuid {})) - -;; DONE: 1. uid converted to a uuid -;; DONE: 2. merge pages with same names (case-sensitive) -;; DONE: 3. mldoc add support to roam research macros, or we can transform here. -;; DONE: 4. mldoc add support to nested links -;; DONE: 5. Roam attributes -> properties -;; TODO: 6. hiccup - -(defonce uid-pattern #"\(\(([a-zA-Z0-9_\\-]{6,24})\)\)") -(defonce macro-pattern #"\{\{([^{}]+)\}\}") - -(defn uid-transform - [text] - (string/replace text uid-pattern (fn [[_ uid]] - (let [id (get @uid->uuid uid uid)] - (block-ref/->block-ref id))))) - -(defn macro-transform - [text] - (string/replace text macro-pattern (fn [[original text]] - (let [[name arg] (common-util/split-first ":" text)] - (if name - (let [name (text/page-ref-un-brackets! name)] - (gstring/format "{{%s %s}}" name arg)) - original))))) - -(defn- fenced-code-transform - [text] - (string/replace text #"```" "\n```")) - -(defn load-all-refed-uids! - [data] - (let [full-text (atom "")] - (walk/postwalk - (fn [f] - (when (and (map? f) (:string f)) - (swap! full-text (fn [v] (str v (:string f))))) - f) - data) - (let [uids (->> (re-seq uid-pattern @full-text) - (map last) - (distinct) - (set))] - (reset! all-refed-uids uids) - (doseq [uid uids] - (swap! uid->uuid assoc uid (random-uuid)))))) - -(defn transform - [text] - (-> text - (string/replace "{{[[TODO]]}}" "TODO") - (string/replace "{{[[DONE]]}}" "DONE") - (uid-transform) - (macro-transform) - (fenced-code-transform))) - -(declare children->text) -(defn child->text - [{:keys [uid string children]} level] - (when-not (and (get @uid->uuid uid) uid) - (swap! uid->uuid assoc uid (random-uuid))) - (let [children-text (children->text children (inc level)) - level-pattern (str (apply str (repeat level "\t")) - (if (zero? level) - "-" - " -")) - properties (when (contains? @all-refed-uids uid) - (str - (gstring/format "id:: %s" - (str (get @uid->uuid uid))) - "\n"))] - (if string - (str level-pattern " " (string/triml string) "\n" properties children-text) - children-text))) - -(defn children->text - [children level] - (->> (map #(child->text % level) children) - (interpose "\n") - (apply str))) - -(defn json->edn - [raw-string] - (-> raw-string js/JSON.parse bean/->clj)) - -(defn ->file - [page-data] - (let [{:keys [create-time title children edit-time]} page-data - initial-level 1 - text (when (seq children) - (when-let [text (children->text children (dec initial-level))] - (let [journal? (date/valid-journal-title? title) - front-matter (if journal? - "" - (gstring/format "---\ntitle: %s\n---\n\n" title))] - (str front-matter (transform text)))))] - (when (and (not (string/blank? title)) - text) - {:title title - :created-at create-time - :last-modified-at edit-time - :text text}))) - -(defn ->files - [edn-data] - (load-all-refed-uids! edn-data) - (let [files (map ->file edn-data) - files (remove #(nil? (:title %)) files) - files (group-by (fn [f] (string/lower-case (:title f))) - files)] - (map - (fn [[_ [fst & others]]] - (assoc fst :text - (->> (map :text (cons fst others)) - (interpose "\n") - (apply str)))) - files))) - -(defrecord Roam [] - protocol/External - (toMarkdownFiles [_this content _config] - (-> content json->edn ->files))) - -(comment - (defonce test-roam-json (frontend.db/get-file "same.json")) - (defonce edn-data (bean/->clj (js/JSON.parse test-roam-json)))) diff --git a/src/main/frontend/external/roam_export.cljs b/src/main/frontend/external/roam_export.cljs deleted file mode 100644 index b9a316a6b5..0000000000 --- a/src/main/frontend/external/roam_export.cljs +++ /dev/null @@ -1,86 +0,0 @@ -(ns ^:no-doc frontend.external.roam-export - (:require [clojure.set :as s] - [clojure.string :as string] - [clojure.walk :as walk] - [frontend.db.async :as db-async] - [frontend.state :as state] - [promesa.core :as p])) - -(def todo-marker-regex - #"^(NOW|LATER|TODO|DOING|WAITING|WAIT|CANCELED|CANCELLED|STARTED|IN-PROGRESS)") - -(def done-marker-regex #"^DONE") - -(def nano-char-range "_-0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") - -(defn- nano-id-char [] - (rand-nth nano-char-range)) - -(defn nano-id [] - (->> (repeatedly 9 nano-id-char) - (string/join))) - -(defn uid-map [] - (let [repo (state/get-current-repo)] - (p/let [result (db-async/> result - (map (comp :block/uuid first)) - (distinct) - (map (fn [uuid] [uuid (nano-id)])) - (into {}))))) - -(defn update-content [content uuid->uid-map] - (when content ; page block doesn't have content - (let [uuids (keys uuid->uid-map)] - (reduce - (fn [acc uuid] - (if (string/includes? acc (str uuid)) - (string/replace acc (str uuid) (get uuid->uid-map uuid)) - acc)) - content - uuids)))) - -(defn update-uid [{:block/keys [uuid title] :as b} - uuid->uid-map] - (cond-> b - (contains? uuid->uid-map uuid) - (assoc :block/uid (get uuid->uid-map uuid)) - - (some (fn [id] (string/includes? (str title) (str id))) (keys uuid->uid-map)) - (update :block/title #(update-content % uuid->uid-map)))) - -(defn update-todo [{:block/keys [title] :as block}] - (if title - (update block :block/title - (fn [c] - (-> c - (string/replace todo-marker-regex "{{[[TODO]]}}") - (string/replace done-marker-regex "{{[[DONE]]}}") - (string/replace "{{embed " "{{embed: ") - (string/trim)))) - block)) - -(defn traverse - [keyseq vec-tree] - (p/let [uuid->uid-map (uid-map)] - (walk/postwalk - (fn [x] - (cond - (and (map? x) (contains? x :block/uuid)) - (-> x - - (update-uid uuid->uid-map) - - (update-todo) - - (s/rename-keys {:block/title :page/title}) - - (select-keys keyseq)) - - :else - x)) - vec-tree))) diff --git a/src/main/frontend/format/mldoc.cljs b/src/main/frontend/format/mldoc.cljs index d4f823103e..26d0871440 100644 --- a/src/main/frontend/format/mldoc.cljs +++ b/src/main/frontend/format/mldoc.cljs @@ -7,20 +7,13 @@ [frontend.format.protocol :as protocol] [frontend.state :as state] [goog.object :as gobj] - [lambdaisland.glogi :as log] - [logseq.common.util :as common-util] [logseq.graph-parser.mldoc :as gp-mldoc])) (defonce anchorLink (gobj/get Mldoc "anchorLink")) -(defonce parseOPML (gobj/get Mldoc "parseOPML")) (defonce parseAndExportMarkdown (gobj/get Mldoc "parseAndExportMarkdown")) (defonce parseAndExportOPML (gobj/get Mldoc "parseAndExportOPML")) (defonce export (gobj/get Mldoc "export")) -(defn parse-opml - [content] - (parseOPML content)) - (defn parse-export-markdown [content config references] (parseAndExportMarkdown content @@ -36,17 +29,6 @@ (def block-with-title? gp-mldoc/block-with-title?) -(defn opml->edn - [config content] - (try - (if (string/blank? content) - {} - (let [[headers blocks] (-> content (parse-opml) (common-util/json->clj))] - [headers (gp-mldoc/collect-page-properties blocks config)])) - (catch :default e - (log/error :edn/convert-failed e) - []))) - (defn get-default-config [format] (gp-mldoc/get-default-config (state/get-current-repo) format)) @@ -70,13 +52,6 @@ [plains] (string/join (map last plains))) -(def properties? gp-mldoc/properties?) - -(defn typ-drawer? - [ast typ] - (and (contains? #{"Drawer"} (ffirst ast)) - (= typ (second (first ast))))) - (defn extract-first-query-from-ast [ast] (let [*result (atom nil)] (walk/postwalk @@ -88,10 +63,3 @@ f)) ast) @*result)) - -(defn get-title&body - "parses content and returns [title body] - returns nil if no title" - [content format] - (when-let [repo (state/get-current-repo)] - (gp-mldoc/get-title&body repo content format))) diff --git a/src/main/frontend/handler/assets.cljs b/src/main/frontend/handler/assets.cljs index a71e62cc13..051f9919d8 100644 --- a/src/main/frontend/handler/assets.cljs +++ b/src/main/frontend/handler/assets.cljs @@ -94,32 +94,6 @@ (some-> (resolve-asset-real-path-url (state/get-current-repo) path) (common-util/safe-decode-uri-component))))) -(defn get-matched-alias-by-ext - [ext] - (when-let [ext (and (alias-enabled?) - (string? ext) - (not (string/blank? ext)) - (util/safe-lower-case ext))] - - (let [alias (medley/find-first - (fn [{:keys [exts]}] - (some #(string/ends-with? ext %) exts)) - (get-alias-dirs))] - alias))) - -(defn get-asset-file-link - "Link text for inserting to markdown/org" - [format url file-name image?] - (let [pdf? (and url (string/ends-with? (string/lower-case url) ".pdf")) - media? (and url (or (config/ext-of-audio? url) - (config/ext-of-video? url)))] - (case (keyword format) - :markdown (util/format (str (when (or image? media? pdf?) "!") "[%s](%s)") file-name url) - :org (if image? - (util/format "[[%s]]" url) - (util/format "[[%s][%s]]" url file-name)) - nil))) - (defn - (p/let [_ (state/set-state! [:file-sync/remote-graphs :loading] true) + (p/let [_ (state/set-state! :rtc/loading-graphs? true) _ (js/Promise. user-handler/task--ensure-id&access-token) token (state/get-auth-id-token) graphs (state/ (text-util/remove-timestamp content key) - (text-util/add-timestamp key value))] - (when (not= content new-content) - (let [input-id (state/get-edit-input-id)] - (if (and input-id - (string/ends-with? input-id (str block-id))) - (state/set-edit-content! input-id new-content) - (save-block-if-changed! block new-content)))))))) - -(defn set-editing-block-timestamp! - "Almost the same as set-block-timestamp! except for: - - it doesn't save the block - - it extracts current content from current input" - [key value] - (let [key (string/lower-case (str key)) - value (str value) - content (state/get-edit-content) - new-content (-> (text-util/remove-timestamp content key) - (text-util/add-timestamp key value))] - (when (not= content new-content) - (let [input-id (state/get-edit-input-id)] - (state/set-edit-content! input-id new-content))))) - (defn copy-block-ref! ([block-id] (copy-block-ref! block-id #(str %))) @@ -1582,10 +1550,6 @@ [q] (search/template-search q)) -(defn = end-index start-index)) - (subs value start-index end-index))})) - -(defn property-on-chosen-handler - [element-id q] - (fn [property] - (when-let [input (gdom/getElement element-id)] - (let [{:keys [end-index searching-property]} (get-searching-property input)] - (cursor/move-cursor-to input (+ end-index 2)) - (commands/insert! element-id (str (or property q) gp-property/colons " ") - {:last-pattern (str searching-property gp-property/colons)}) - (state/clear-editor-action!) - (js/setTimeout (fn [] - (let [pos (let [input (gdom/getElement element-id)] - (cursor/get-caret-pos input))] - (state/set-editor-action-data! {:property (or property q) - :pos pos}) - (state/set-editor-action! :property-value-search))) - 50))))) - -(defn property-value-on-chosen-handler - [element-id q] - (fn [property-value] - (commands/insert! element-id (str gp-property/colons " " (or property-value q)) - {:last-pattern (str gp-property/colons " " q)}) - (state/clear-editor-action!))) - (declare indent-outdent) (defn- last-top-level-child? diff --git a/src/main/frontend/handler/export/common.cljs b/src/main/frontend/handler/export/common.cljs index 4946ddaf63..75123e6697 100644 --- a/src/main/frontend/handler/export/common.cljs +++ b/src/main/frontend/handler/export/common.cljs @@ -31,9 +31,10 @@ (cli-export-common/get-page-content page-uuid))) ;; Utils -(defn edn config data) - ;; add empty pos metadata - parsed-blocks (map (fn [b] [b {}]) parsed-blocks) - page-name (:title headers) - parsed-blocks (->> - (block/extract-blocks parsed-blocks "" :markdown {:page-name page-name}) - (mapv editor/wrap-parse-block))] - (p/do! - (when (not (db/page-exists? page-name)) - (page-handler/clj nfs-dbs)))) + (p/let [dbs (db-persist/get-all-graphs)] + (map (fn [db] + (let [graph-name (:name db)] + {:url graph-name + :metadata (:metadata db) + :root (config/get-local-dir graph-name) + :nfs? true})) + dbs))) (defn combine-local-&-remote-graphs [local-repos remote-repos] @@ -126,23 +112,12 @@ (last (string/split (:root repo) #"/")))] [(:remote? repo) (string/lower-case graph-name)])) repos'')))) -(defn get-detail-graph-info - [url] - (when-let [graphs (seq (and url (combine-local-&-remote-graphs - (state/get-repos) - (state/get-remote-file-graphs))))] - (first (filter #(when-let [url' (:url %)] - (= url url')) graphs)))) - (defn refresh-repos! [] (p/let [repos (get-repos) repos' (combine-local-&-remote-graphs repos - (concat - (state/get-rtc-graphs) - (when-not (or (util/mobile?) util/web-platform?) - (state/get-remote-file-graphs))))] + (state/get-rtc-graphs))] (state/set-repos! repos') repos')) diff --git a/src/main/frontend/handler/route.cljs b/src/main/frontend/handler/route.cljs index b5843a86cb..2f873aaa77 100644 --- a/src/main/frontend/handler/route.cljs +++ b/src/main/frontend/handler/route.cljs @@ -50,10 +50,6 @@ [] (redirect! {:to :graphs})) -(defn redirect-to-whiteboard-dashboard! - [] - (redirect! {:to :whiteboards})) - ;; Named block links only works on web (and publishing) (if util/web-platform? (defn- default-page-route [page-name-or-block-uuid] diff --git a/src/main/frontend/handler/user.cljs b/src/main/frontend/handler/user.cljs index da0f6ce636..572faae0cc 100644 --- a/src/main/frontend/handler/user.cljs +++ b/src/main/frontend/handler/user.cljs @@ -11,7 +11,6 @@ [frontend.config :as config] [frontend.debug :as debug] [frontend.flows :as flows] - [frontend.handler.config :as config-handler] [frontend.handler.notification :as notification] [frontend.state :as state] [goog.crypt :as crypt] @@ -19,18 +18,6 @@ [goog.crypt.Sha256] [missionary.core :as m])) -(defn set-preferred-format! - [format] - (when format - (config-handler/set-config! :preferred-format format) - (state/set-preferred-format! format))) - -(defn set-preferred-workflow! - [workflow] - (when workflow - (config-handler/set-config! :preferred-workflow workflow) - (state/set-preferred-workflow! workflow))) - ;;; userinfo, token, login/logout, ... (defn- decode-username @@ -210,11 +197,6 @@ ;; refresh remote graph list by pub login event (when (user-uuid) (state/pub-event! [:user/fetch-info-and-graphs])))))) -(defn has-refresh-token? - "Has refresh-token" - [] - (boolean (js/localStorage.getItem "refresh-token"))) - (defn login-callback [session] (set-tokens! @@ -289,13 +271,6 @@ (-> (state/get-auth-id-token) parse-jwt expired?)) (throw (ex-info "empty or expired token and refresh failed" {:type :expired-token}))))))) -(defn breakpoint - "Converts a number to a breakpoint string - Values come from https://tailwindcss.com/docs/responsive-design" - [size] - (cond - (nil? size) :md - (<= size 640) :sm - (<= size 768) :md - (<= size 1024) :lg - (<= size 1280) :xl - (<= size 1536) :xl - :else :2xl)) - -(defn use-breakpoint - "Returns the current breakpoint - You can manually change the tick value, if you want to force refresh the value, you can manually change the tick value" - ([] (use-breakpoint nil)) - ([tick] - (let [[ref rect] (use-bounding-client-rect tick) - bp (->breakpoint (when (some? rect) (.-width rect)))] - [ref bp]))) diff --git a/src/main/frontend/search.cljs b/src/main/frontend/search.cljs index a62d97dfaa..52d8a1b9ba 100644 --- a/src/main/frontend/search.cljs +++ b/src/main/frontend/search.cljs @@ -54,20 +54,6 @@ (fuzzy/fuzzy-search templates q {:limit limit :extract-fn extract-fn})))))))) -(defn property-search - ([q] - (property-search q 100)) - ([q limit] - (when q - (p/let [q (fuzzy/clean-str q) - properties* (db-async/ state - :graph/parsing-state {} :copy/export-block-text-indent-style (or (storage/get :copy/export-block-text-indent-style) "dashes") @@ -288,24 +282,9 @@ :auth/access-token nil :auth/id-token nil - ;; file-sync - :file-sync/jstour-inst nil - :file-sync/onboarding-state (or (storage/get :file-sync/onboarding-state) - {:welcome false}) - :file-sync/remote-graphs {:loading false :graphs nil} - :file-sync/set-remote-graph-password-result {} - - ;; graph-uuid -> {:graphs-txid {} - ;; :file-sync/sync-manager {} - ;; :file-sync/sync-state {} - ;; ;; {file-path -> payload} - ;; :file-sync/progress {} - ;; :file-sync/start-time {} - ;; :file-sync/last-synced-at {}} - :file-sync/graph-state {:current-graph-uuid nil} ;; graph-uuid -> ... - :rtc/state (atom {}) + :rtc/loading-graphs? nil ;; only latest rtc-log stored here, when a log stream is needed, ;; use missionary to create a rtc-log-flow, use (missionary.core/watch ) :rtc/log (atom nil) @@ -323,9 +302,7 @@ :ui/container-id (atom 0) :ui/cached-key->container-id (atom {}) :feature/enable-sync? (storage/get :logseq-sync-enabled) - :feature/enable-sync-diff-merge? ((fnil identity true) (storage/get :logseq-sync-diff-merge-enabled)) - :file/rename-event-chan (async/chan 100) :ui/find-in-page nil :graph/importing nil :graph/importing-state {} @@ -470,12 +447,6 @@ should be done through this fn in order to get global config and config defaults [] (:custom-js-url (get-config))) -(defn get-default-journal-template - [] - (when-let [template (get-in (get-config) [:default-templates :journals])] - (when-not (string/blank? template) - (string/trim template)))) - (defn all-pages-public? [] (let [value (:publishing/all-pages-public? (get-config)) @@ -686,10 +657,6 @@ Similar to re-frame subscriptions" ([repo] (not (false? (:feature/enable-flashcards? (sub-config repo)))))) -(defn enable-git-auto-push? - [repo] - (not (false? (:git-auto-push (sub-config repo))))) - (defn graph-settings [] (:graph/settings (sub-config))) @@ -848,22 +815,14 @@ Similar to re-frame subscriptions" [] (:git/current-repo @state)) -(defn get-remote-file-graphs - [] - (get-in @state [:file-sync/remote-graphs :graphs])) - (defn get-rtc-graphs [] (:rtc/graphs @state)) -(defn get-remote-graph-info-by-uuid - [uuid] - (when-let [graphs (seq (get-in @state [:file-sync/remote-graphs :graphs]))] - (some #(when (= (:GraphUUID %) (str uuid)) %) graphs))) - -(defn get-remote-graph-usage - [] - (when-let [graphs (seq (get-in @state [:file-sync/remote-graphs :graphs]))] +;; TODO: rtc version +(comment + (defn get-remote-graph-usage + [graphs] (->> graphs (map #(hash-map :uuid (:GraphUUID %) :name (:GraphName %) @@ -873,24 +832,6 @@ Similar to re-frame subscriptions" (map #(assoc % :free-gbs (- (:limit-gbs %) (:used-gbs %)))) (vec)))) -(defn delete-remote-graph! - [repo] - (let [remove-repo! (fn [repos] - (remove #(and - (:GraphUUID repo) - (:GraphUUID %) - (= (:GraphUUID repo) (:GraphUUID %))) repos))] - (if (:rtc-graph? repo) - (swap! state update :rtc/graphs remove-repo!) - (swap! state update-in [:file-sync/remote-graphs :graphs] remove-repo!)))) - -(defn add-remote-graph! - [repo] - (swap! state update-in [:file-sync/remote-graphs :graphs] - (fn [repos] - (->> (conj repos repo) - (distinct))))) - (defn get-repos [] (get-in @state [:me :repos])) @@ -916,14 +857,6 @@ Similar to re-frame subscriptions" (storage/remove :git/current-repo)) (ipc/ipc "setCurrentGraph" repo)) -(defn set-preferred-format! - [format] - (swap! state assoc-in [:me :preferred_format] (name format))) - -(defn set-preferred-workflow! - [workflow] - (swap! state assoc-in [:me :preferred_workflow] (name workflow))) - (defn set-preferred-language! [language] (set-state! :preferred-language (name language)) @@ -1342,11 +1275,6 @@ Similar to re-frame subscriptions" (set-state! :editor/action-data nil) (set-state! :view/selected-blocks nil)) -(defn into-code-editor-mode! - [] - (set-state! :editor/cursor-range nil) - (swap! state assoc :editor/code-mode? true)) - (defn set-editor-last-pos! [new-pos] (update-state! :editor/last-saved-cursor @@ -1698,15 +1626,6 @@ Similar to re-frame subscriptions" [] (:editor/in-composition? @state)) -(defn set-loading-files! - [repo value] - (when repo - (set-state! [:repo/loading-files? repo] value))) - -(defn loading-files? - [repo] - (get-in @state [:repo/loading-files? repo])) - (defn set-editor-last-input-time! [repo time] (set-state! :editor/last-input-time time :path-in-sub-atom repo)) @@ -1725,14 +1644,6 @@ Similar to re-frame subscriptions" ;; not in editing mode (not (get-edit-input-id)))))) -(defn set-nfs-refreshing! - [value] - (set-state! :nfs/refreshing? value)) - -(defn nfs-refreshing? - [] - (:nfs/refreshing? @state)) - (defn set-search-result! [value] (set-state! :search/result value)) @@ -1924,14 +1835,6 @@ Similar to re-frame subscriptions" (when (mobile-util/native-platform?) (set-state! :mobile/show-action-bar? false)))))))) -(defn get-git-auto-commit-enabled? - [] - (false? (sub [:electron/user-cfgs :git/disable-auto-commit?]))) - -(defn get-git-commit-on-close-enabled? - [] - (sub [:electron/user-cfgs :git/commit-on-close?])) - (defn set-last-key-code! [key-code] (set-state! :editor/last-key-code key-code)) @@ -2077,11 +1980,8 @@ Similar to re-frame subscriptions" (defn get-auth-refresh-token [] (:auth/refresh-token @state)) -(defn reset-parsing-state! - [] - (set-state! [:graph/parsing-state (get-current-repo)] {})) - (defn set-parsing-state! + "Leave for tests" [m] (update-state! [:graph/parsing-state (get-current-repo)] (if (fn? m) m @@ -2093,28 +1993,6 @@ Similar to re-frame subscriptions" (every? not-empty (vals agent-opts))) (str protocol "://" host ":" port)))) -(defn get-sync-graph-by-id - [graph-uuid] - (when graph-uuid - (let [graph (first (filter #(= graph-uuid (:GraphUUID %)) - (get-repos)))] - (when (:url graph) - graph)))) - -(defn unlinked-dir? - [dir] - (contains? (:file/unlinked-dirs @state) dir)) - -(defn get-file-rename-event-chan - [] - (:file/rename-event-chan @state)) - -(defn offer-file-rename-event-chan! - [v] - {:pre [(map? v) - (= #{:repo :old-path :new-path} (set (keys v)))]} - (async/offer! (get-file-rename-event-chan) v)) - (defn get-current-pdf [] (:pdf/current @state)) diff --git a/src/main/frontend/ui.cljs b/src/main/frontend/ui.cljs index b10f8040be..6a89a5b08e 100644 --- a/src/main/frontend/ui.cljs +++ b/src/main/frontend/ui.cljs @@ -367,25 +367,6 @@ items (if clear-all (cons clear-all notifications) notifications)] (doall items))))) -(rum/defc humanity-time-ago - [input opts] - (let [time-fn (fn [] - (try - (util/human-time input) - (catch :default e - (js/console.error e) - input))) - [time set-time] (rum/use-state (time-fn))] - - (hooks/use-effect! - (fn [] - (let [timer (js/setInterval - #(set-time (time-fn)) (* 1000 30))] - #(js/clearInterval timer))) - []) - - [:span.ui__humanity-time (merge {} opts) time])) - (defn checkbox [option] (let [on-change' (:on-change option) diff --git a/src/main/frontend/util.cljc b/src/main/frontend/util.cljc index 358b2ddb87..524b4ba046 100644 --- a/src/main/frontend/util.cljc +++ b/src/main/frontend/util.cljc @@ -2,34 +2,30 @@ "Main ns for utility fns. This ns should be split up into more focused namespaces" #?(:clj (:refer-clojure :exclude [format])) #?(:cljs (:require-macros [frontend.util])) - #?(:cljs (:require - ["/frontend/selection" :as selection] - ["/frontend/utils" :as utils] - ["@capacitor/status-bar" :refer [^js StatusBar Style]] - ["@capacitor/core" :refer [Capacitor]] - ["@capacitor/clipboard" :as CapacitorClipboard] - ["grapheme-splitter" :as GraphemeSplitter] - ["sanitize-filename" :as sanitizeFilename] - ["check-password-strength" :refer [passwordStrength]] - ["path-complete-extname" :as pathCompleteExtname] - ["semver" :as semver] - [frontend.loader :refer [load]] - [cljs-bean.core :as bean] - [cljs-time.core :as t] - [clojure.pprint] - [dommy.core :as d] - [frontend.mobile.util :as mobile-util] - [logseq.common.util :as common-util] - [goog.dom :as gdom] - [goog.object :as gobj] - [goog.string :as gstring] - [goog.functions :as gfun] - [goog.userAgent] - [promesa.core :as p] - [rum.core :as rum] - [clojure.core.async :as async] - [datascript.impl.entity :as de] - [logseq.common.config :as common-config])) + #?(:cljs (:require ["/frontend/selection" :as selection] + ["/frontend/utils" :as utils] + ["@capacitor/clipboard" :as CapacitorClipboard] + ["@capacitor/core" :refer [Capacitor]] + ["@capacitor/status-bar" :refer [^js StatusBar Style]] + ["grapheme-splitter" :as GraphemeSplitter] + ["path-complete-extname" :as pathCompleteExtname] + ["semver" :as semver] + [cljs-bean.core :as bean] + [cljs-time.core :as t] + [clojure.pprint] + [datascript.impl.entity :as de] + [dommy.core :as d] + [frontend.loader :refer [load]] + [frontend.mobile.util :as mobile-util] + [goog.dom :as gdom] + [goog.functions :as gfun] + [goog.object :as gobj] + [goog.string :as gstring] + [goog.userAgent] + [logseq.common.config :as common-config] + [logseq.common.util :as common-util] + [promesa.core :as p] + [rum.core :as rum])) #?(:cljs (:import [goog.async Debouncer])) (:require [clojure.pprint] @@ -114,24 +110,7 @@ #?(:cljs (def string-join-path common-util/string-join-path)) #?(:cljs - (do - (def uuid-string? common-util/uuid-string?) - (defn check-password-strength - {:malli/schema [:=> [:cat :string] [:maybe - [:map - [:contains [:sequential :string]] - [:length :int] - [:id :int] - [:value :string]]]]} - [input] - (when-let [^js ret (and (string? input) - (not (string/blank? input)) - (passwordStrength input))] - (bean/->clj ret))) - (defn safe-sanitize-file-name - {:malli/schema [:=> [:cat :string] :string]} - [s] - (sanitizeFilename (str s))))) + (def uuid-string? common-util/uuid-string?)) #?(:cljs (do @@ -555,10 +534,6 @@ #?(:cljs (def distinct-by-last-wins common-util/distinct-by-last-wins)) -(defn get-git-owner-and-repo - [repo-url] - (take-last 2 (string/split repo-url #"/"))) - (defn safe-lower-case [s] (if (string? s) @@ -997,13 +972,6 @@ (d/set-attr! :media "all"))] (d/append! parent-node link)))))) -(defn remove-common-preceding - [col1 col2] - (if (and (= (first col1) (first col2)) - (seq col1)) - (recur (rest col1) (rest col2)) - [col1 col2])) - ;; fs #?(:cljs (defn get-file-ext @@ -1022,22 +990,6 @@ string-join-path)] [dir basename]))) -#?(:cljs - (defn get-relative-path - [current-file-path another-file-path] - (let [directories-f #(butlast (string/split % "/")) - parts-1 (directories-f current-file-path) - parts-2 (directories-f another-file-path) - [parts-1 parts-2] (remove-common-preceding parts-1 parts-2) - another-file-name (last (string/split another-file-path "/"))] - (->> (concat - (if (seq parts-1) - (repeat (count parts-1) "..") - ["."]) - parts-2 - [another-file-name]) - string-join-path)))) - #?(:clj (defmacro profile [k & body] @@ -1073,22 +1025,6 @@ (defn keyname [key] (str (namespace key) "/" (name key))) -;; FIXME: drain-chan was copied from frontend.worker-common.util due to shadow-cljs compile bug -#?(:cljs - (defn drain-chan - "drop all stuffs in CH, and return all of them" - [ch] - (->> (repeatedly #(async/poll! ch)) - (take-while identity)))) - -#?(:cljs - (defn trace! - [] - (js/console.trace))) - -#?(:cljs - (def remove-first common-util/remove-first)) - #?(:cljs (defn backward-kill-word [input] diff --git a/src/main/frontend/util/cursor.cljs b/src/main/frontend/util/cursor.cljs index 7faba60c81..1620c1467c 100644 --- a/src/main/frontend/util/cursor.cljs +++ b/src/main/frontend/util/cursor.cljs @@ -99,20 +99,6 @@ [(gobj/get input "value") (pos input)]) -(defn line-beginning-pos - [input] - (let [[content pos'] (get-input-content&pos input)] - (if (zero? pos') 0 - (let [last-newline-pos (string/last-index-of content \newline (dec pos'))] - (if (= nil last-newline-pos) 0 ;; no newline found (first line) - (inc last-newline-pos)))))) - -(defn line-end-pos - [input] - (let [[content pos'] (get-input-content&pos input)] - (or (string/index-of content \newline pos') - (count content)))) - (defn beginning-of-line? [input] (let [[content pos'] (get-input-content&pos input)] @@ -121,14 +107,20 @@ (when-let [pre-char (subs content (dec pos') pos')] (= pre-char \newline)))))) -(defn move-cursor-to-line-end - [input] - (move-cursor-to input (line-end-pos input))) - (comment + (defn line-end-pos + [input] + (let [[content pos'] (get-input-content&pos input)] + (or (string/index-of content \newline pos') + (count content)))) + (defn move-cursor-to-line-beginning [input] - (move-cursor-to input (line-beginning-pos input)))) + (move-cursor-to input (line-beginning-pos input))) + + (defn move-cursor-to-line-end + [input] + (move-cursor-to input (line-end-pos input)))) (defn move-cursor-to-start [input] @@ -139,14 +131,6 @@ (let [pos' (count (gobj/get input "value"))] (move-cursor-to input pos'))) -(defn move-cursor-to-thing - ([input thing] - (move-cursor-to-thing input thing (pos input))) - ([input thing from] - (let [[content _pos] (get-input-content&pos input) - pos' (string/index-of content thing from)] - (move-cursor-to input pos')))) - (defn move-cursor-forward-by-word [input] (let [val (.-value input) diff --git a/src/main/frontend/util/fs.cljs b/src/main/frontend/util/fs.cljs index ab3fc085ca..0b66f06d4b 100644 --- a/src/main/frontend/util/fs.cljs +++ b/src/main/frontend/util/fs.cljs @@ -3,12 +3,8 @@ (ns frontend.util.fs "Misc util fns built on top of frontend.fs" (:require ["path" :as node-path] - [cljs.reader :as reader] [clojure.string :as string] - [frontend.common.file.util :as wfu] - [frontend.config :as config] - [frontend.fs :as fs] - [promesa.core :as p])) + [frontend.common.file.util :as wfu])) ;; NOTE: This is not the same ignored-path? as src/electron/electron/utils.cljs. ;; The assets directory is ignored. @@ -41,23 +37,6 @@ (some #(string/ends-with? path %) [".md" ".markdown" ".org" ".js" ".edn" ".css"])))))))) -(defn read-graphs-txid-info - [root] - (when (string? root) - (p/let [exists? (fs/file-exists? root "logseq/graphs-txid.edn")] - (when exists? - (-> (p/let [txid-str (fs/read-file root "logseq/graphs-txid.edn") - txid-meta (and txid-str (reader/read-string txid-str))] - txid-meta) - (p/catch - (fn [^js e] - (js/console.error "[fs read txid data error]" e)))))))) - -(defn read-repo-file - [repo-url file-rpath] - (when-let [repo-dir (config/get-repo-dir repo-url)] - (fs/read-file repo-dir file-rpath))) - (def include-reserved-chars? wfu/include-reserved-chars?) (def windows-reserved-filebodies wfu/windows-reserved-filebodies) (defn file-name-sanity diff --git a/src/main/frontend/util/page.cljs b/src/main/frontend/util/page.cljs index ac77b71693..695799adc2 100644 --- a/src/main/frontend/util/page.cljs +++ b/src/main/frontend/util/page.cljs @@ -4,12 +4,6 @@ [frontend.state :as state] [frontend.util :as util])) -(defn get-current-page-name - "Fetch the current page's original name with same approach as get-current-page-id" - [] - (or (:block/title (db/get-page (state/get-current-page))) - (get-in (first (state/get-editor-args)) [:block :block/page :block/title]))) - (defn get-current-page-uuid "Fetch the current page's uuid with same approach as get-current-page-id" [] diff --git a/src/main/frontend/util/text.cljs b/src/main/frontend/util/text.cljs index e64c1050ac..3b2e9c312e 100644 --- a/src/main/frontend/util/text.cljs +++ b/src/main/frontend/util/text.cljs @@ -50,14 +50,6 @@ (rest new-lines))))] (string/join "\n" new-lines))) -(defn remove-timestamp - [content key] - (let [lines (string/split-lines content) - new-lines (filter (fn [line] - (not (string/starts-with? (string/lower-case line) key))) - lines)] - (string/join "\n" new-lines))) - (defn get-current-line-by-pos [s pos] (let [lines (string/split-lines s) diff --git a/src/main/frontend/worker/state.cljs b/src/main/frontend/worker/state.cljs index a76d1a4577..d66349e9e8 100644 --- a/src/main/frontend/worker/state.cljs +++ b/src/main/frontend/worker/state.cljs @@ -76,17 +76,6 @@ [repo] (get @*opfs-pools repo)) -(defn tx-idle? - [repo & {:keys [diff] - :or {diff 1000}}] - (when repo - (let [last-input-time (get-in @*state [:db/latest-transact-time repo])] - (or - (nil? last-input-time) - - (let [now (common-util/time-ms)] - (>= (- now last-input-time) diff)))))) - (defn set-db-latest-tx-time! [repo] (swap! *state assoc-in [:db/latest-transact-time repo] (common-util/time-ms))) diff --git a/src/test/frontend/external/roam_test.cljs b/src/test/frontend/external/roam_test.cljs deleted file mode 100644 index 393120ad0a..0000000000 --- a/src/test/frontend/external/roam_test.cljs +++ /dev/null @@ -1,35 +0,0 @@ -(ns frontend.external.roam-test - (:require [cljs.test :refer [is deftest]] - [frontend.external.roam :as roam] - [frontend.external :refer [to-markdown-files]])) - -(def minimal-json " -[ - { - \"create-email\": \"adam@example.com\", - \"create-time\": 1610708403162, - \"title\": \"Export JSON\", - \"children\": [ - { - \"string\": \"Hello, world!\", - \"create-email\": \"adam@example.com\", - \"create-time\": 1610708405787, - \"uid\": \"7c5um7hSz\", - \"edit-time\": 1610708415484, - \"edit-email\": \"adam@example.com\"} - ], - \"edit-time\": 1610708403169, - \"edit-email\": \"adam@example.com\"}] -") - -(deftest json->edn-test - (is (= [1 {:foo 42, :bar "baz"} 3] (roam/json->edn "[1, {\"foo\": 42, \"bar\": \"baz\"}, 3]")))) - -(deftest roam-import-test - (let [got (to-markdown-files :roam minimal-json {}) - md (first got)] - (is (= 1 (count got))) - (is (= "Export JSON" (:title md))) - (is (:created-at md)) - (is (:last-modified-at md)) - (is (= "---\ntitle: Export JSON\n---\n\n- Hello, world!\n" (:text md)))))