From 1f0e22275d42b113a20870659e914b68c94d1ad5 Mon Sep 17 00:00:00 2001 From: Gabriel Horner Date: Thu, 22 Sep 2022 21:13:06 -0400 Subject: [PATCH 01/10] Add ns docstrings for most ns in src/main - Added to CI now that it passes - Added no-doc for docstrings that don't add any more than what's in the ns name or for ones where I didn't know the ns that well --- .clj-kondo/config.edn | 42 +++++++++++++++---- .github/workflows/build.yml | 3 ++ bb.edn | 13 +++++- docs/dev-practices.md | 4 +- scripts/src/logseq/tasks/dev.clj | 3 +- src/main/electron/ipc.cljs | 1 + src/main/electron/listener.cljs | 2 + src/main/frontend/commands.cljs | 1 + src/main/frontend/components/file_sync.cljs | 4 +- src/main/frontend/components/repo.cljs | 4 +- src/main/frontend/config.cljs | 1 + src/main/frontend/core.cljs | 1 + src/main/frontend/date.cljs | 1 + src/main/frontend/db.cljs | 1 + src/main/frontend/db/debug.cljs | 2 +- src/main/frontend/db/migrate.cljs | 2 +- src/main/frontend/db/outliner.cljs | 1 + src/main/frontend/db/persist.cljs | 1 + src/main/frontend/db_mixins.cljs | 1 + src/main/frontend/debug.clj | 1 + src/main/frontend/debug.cljs | 1 + src/main/frontend/diff.cljs | 2 +- src/main/frontend/encrypt.cljs | 1 + src/main/frontend/error.cljs | 1 + src/main/frontend/extensions/pdf/utils.cljs | 6 +-- src/main/frontend/external.cljs | 1 + src/main/frontend/external/protocol.cljc | 3 +- src/main/frontend/external/roam.cljs | 1 + src/main/frontend/external/roam_export.cljs | 2 +- src/main/frontend/format.cljs | 2 + src/main/frontend/format/adoc.cljs | 1 + src/main/frontend/format/mldoc.cljs | 3 +- src/main/frontend/format/protocol.cljs | 2 +- src/main/frontend/fs.cljs | 6 ++- src/main/frontend/fs/bfs.cljs | 2 +- src/main/frontend/fs/capacitor_fs.cljs | 1 + src/main/frontend/fs/nfs.cljs | 2 +- src/main/frontend/fs/node.cljs | 1 + src/main/frontend/fs/protocol.cljs | 2 +- src/main/frontend/fs/sync.cljs | 1 + src/main/frontend/fs/watcher_handler.cljs | 1 + src/main/frontend/handler.cljs | 2 + src/main/frontend/handler/block.cljs | 2 +- .../frontend/handler/command_palette.cljs | 1 + src/main/frontend/handler/common.cljs | 1 + src/main/frontend/handler/dnd.cljs | 1 + src/main/frontend/handler/draw.cljs | 1 + src/main/frontend/handler/editor.cljs | 4 +- .../frontend/handler/editor/keyboards.cljs | 2 +- .../frontend/handler/editor/lifecycle.cljs | 2 +- src/main/frontend/handler/events.cljs | 11 +++-- src/main/frontend/handler/export.cljs | 2 +- src/main/frontend/handler/external.cljs | 19 +++++---- src/main/frontend/handler/file.cljs | 1 + src/main/frontend/handler/file_sync.cljs | 1 + src/main/frontend/handler/graph.cljs | 1 + src/main/frontend/handler/history.cljs | 2 +- src/main/frontend/handler/image.cljs | 2 +- src/main/frontend/handler/journal.cljs | 2 +- src/main/frontend/handler/metadata.cljs | 1 + src/main/frontend/handler/mobile/swipe.cljs | 2 +- src/main/frontend/handler/notification.cljs | 1 + src/main/frontend/handler/page.cljs | 1 + src/main/frontend/handler/paste.cljs | 2 +- src/main/frontend/handler/plugin.cljs | 11 ++--- src/main/frontend/handler/query.cljs | 1 + src/main/frontend/handler/recent.cljs | 1 + src/main/frontend/handler/repeated.cljs | 1 + src/main/frontend/handler/repo.cljs | 1 + src/main/frontend/handler/route.cljs | 2 +- src/main/frontend/handler/search.cljs | 7 ++-- src/main/frontend/handler/shell.cljs | 1 + src/main/frontend/handler/ui.cljs | 2 +- src/main/frontend/handler/user.cljs | 1 + src/main/frontend/idb.cljs | 1 + src/main/frontend/image.cljs | 1 + src/main/frontend/loader.cljs | 1 + src/main/frontend/log.cljs | 3 ++ src/main/frontend/mixins.cljs | 1 + src/main/frontend/mobile/core.cljs | 5 ++- src/main/frontend/namespaces.cljc | 2 +- src/main/frontend/page.cljs | 1 + src/main/frontend/publishing.cljs | 1 + src/main/frontend/publishing/html.cljs | 2 +- src/main/frontend/regex.cljc | 2 +- src/main/frontend/routes.cljs | 1 + src/main/frontend/rum.cljs | 2 + src/main/frontend/search.cljs | 2 + src/main/frontend/search/browser.cljs | 1 + src/main/frontend/search/db.cljs | 2 +- src/main/frontend/search/node.cljs | 1 + src/main/frontend/search/protocol.cljs | 2 +- src/main/frontend/security.cljs | 1 + src/main/frontend/spec.cljs | 1 + src/main/frontend/state.cljs | 2 + src/main/frontend/storage.cljs | 2 + src/main/frontend/template.cljs | 1 + src/main/frontend/ui.cljs | 7 ++-- src/main/frontend/ui/date_picker.cljs | 2 +- src/main/frontend/util.cljc | 1 + src/main/frontend/util/clock.cljs | 1 + src/main/frontend/util/cursor.cljs | 2 +- src/main/frontend/util/drawer.cljs | 2 +- src/main/frontend/util/fs.cljs | 1 + src/main/frontend/util/keycode.cljs | 3 +- src/main/frontend/util/list.cljs | 1 + src/main/frontend/util/marker.cljs | 1 + src/main/frontend/util/page_property.cljs | 2 +- src/main/frontend/util/persist_var.cljs | 2 + src/main/frontend/util/priority.cljs | 1 + src/main/frontend/util/text.cljs | 2 + src/main/frontend/util/thingatpt.cljs | 2 +- src/main/frontend/util/url.cljs | 1 + src/main/frontend/version.cljs | 2 +- src/{main => test}/frontend/state_test.cljs | 0 115 files changed, 212 insertions(+), 82 deletions(-) rename src/{main => test}/frontend/state_test.cljs (100%) diff --git a/.clj-kondo/config.edn b/.clj-kondo/config.edn index f770b65063..e21c286e18 100644 --- a/.clj-kondo/config.edn +++ b/.clj-kondo/config.edn @@ -22,25 +22,52 @@ {:aliases {datascript.core d datascript.transit dt datascript.db ddb - lambdaisland.glogi log - medley.core medley + electron.ipc ipc + frontend.commands commands + frontend.config config + frontend.date date + frontend.db db + frontend.db-mixins db-mixins frontend.db.query-dsl query-dsl frontend.db.react react frontend.db.query-react query-react - frontend.util util - frontend.util.property property - frontend.util.text text-util - frontend.config config + frontend.diff diff + frontend.encrypt encrypt frontend.format.mldoc mldoc frontend.format.block block + frontend.fs fs + frontend.fs.bfs bfs + frontend.fs.capacitor-fs capacitor-fs + frontend.fs.nfs nfs frontend.handler.extract extract frontend.handler.common common-handler frontend.handler.common.file file-common-handler frontend.handler.config config-handler + frontend.handler.events events frontend.handler.global-config global-config-handler + frontend.handler.ui ui-handler + frontend.handler.notification notification + frontend.handler.page page-handler + frontend.handler.repo repo-handler frontend.handler.repo-config repo-config-handler + frontend.handler.search search-handler + frontend.idb idb + frontend.loader loader + frontend.mixins mixins frontend.mobile.util mobile-util + frontend.page page + frontend.search search frontend.state state + frontend.template template + frontend.ui ui + frontend.util util + frontend.util.clock clock + frontend.util.property property + frontend.util.persist-var persist-var + frontend.util.text text-util + frontend.util.url url-util + frontend.util.thingatpt thingatpt + lambdaisland.glogi log logseq.graph-parser graph-parser logseq.graph-parser.text text logseq.graph-parser.block gp-block @@ -50,7 +77,8 @@ logseq.graph-parser.config gp-config logseq.graph-parser.util.page-ref page-ref logseq.graph-parser.util.block-ref block-ref - logseq.graph-parser.date-time-util date-time-util}} + logseq.graph-parser.date-time-util date-time-util + medley.core medley}} :namespace-name-mismatch {:level :warning} :used-underscored-binding {:level :warning}} diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0cf4fd42c2..14df37613e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -106,6 +106,9 @@ jobs: - name: Lint for vars that are too large run: bb lint:large-vars + - name: Lint for namespaces that aren't documented + run: bb lint:ns-docstrings + - name: Lint invalid translation entries run: bb lang:invalid-translations diff --git a/bb.edn b/bb.edn index d4f73bc2a1..e5ff62756d 100644 --- a/bb.edn +++ b/bb.edn @@ -6,7 +6,7 @@ logseq/bb-tasks #_{:local/root "../bb-tasks"} {:git/url "https://github.com/logseq/bb-tasks" - :git/sha "abb32ccd26405d56fd28a29d56f3cb902b8c4334"} + :git/sha "95e4fbdb7bbf1c720c6f8b58e3b3b96b3b487526"} logseq/graph-parser {:local/root "deps/graph-parser"} org.clj-commons/digest @@ -70,6 +70,9 @@ lint:carve logseq.bb-tasks.lint.carve/-main + lint:ns-docstrings + logseq.bb-tasks.lint.ns-docstrings/-main + nbb:watch logseq.bb-tasks.nbb.watch/watch @@ -98,4 +101,10 @@ ;; TODO: Address vars tagged with cleanup-todo. These ;; are left mostly because they are not high priority ;; or not well understood - :metadata-exceptions #{:large-vars/cleanup-todo}}}} + :metadata-exceptions #{:large-vars/cleanup-todo}} + + :ns-docstrings + {:paths ["src/main"] + ;; Ignore namespaces that won't be helpful to document initially + ;; e.g. frontend.components.onboarding -> "Onboarding fns" + :ignore-regex "^(frontend.components|frontend.extensions|frontend.modules|frontend.mobile)"}}} diff --git a/docs/dev-practices.md b/docs/dev-practices.md index 71c913b13d..733f25df5d 100644 --- a/docs/dev-practices.md +++ b/docs/dev-practices.md @@ -54,11 +54,13 @@ To configure the linter, see the `[:tasks/config :large-vars]` path of bb.edn. ### Document namespaces -Documentation helps teams share their knowledge and enables more individuals to contribute to the codebase. Documenting our namespaces is a good first step to improving our documentation. Currently this linter is only run on our deps/. To run this linter: +Documentation helps teams share their knowledge and enables more individuals to contribute to the codebase. Documenting our namespaces is a good first step to improving our documentation. To run this linter: ``` bb lint:ns-docstrings ``` +To skip documenting a ns, use the common `^:no-doc` metadata flag. + ### Datalog linting We use [datascript](https://github.com/tonsky/datascript)'s datalog to power our diff --git a/scripts/src/logseq/tasks/dev.clj b/scripts/src/logseq/tasks/dev.clj index 950bc3530c..998b6dc1ca 100644 --- a/scripts/src/logseq/tasks/dev.clj +++ b/scripts/src/logseq/tasks/dev.clj @@ -13,6 +13,7 @@ (doseq [cmd ["clojure -M:clj-kondo --parallel --lint src --cache false" "bb lint:carve" "bb lint:large-vars" - "bb lang:invalid-translations"]] + "bb lang:invalid-translations" + "bb lint:ns-docstrings"]] (println cmd) (shell cmd))) diff --git a/src/main/electron/ipc.cljs b/src/main/electron/ipc.cljs index e876597d79..9493e71af2 100644 --- a/src/main/electron/ipc.cljs +++ b/src/main/electron/ipc.cljs @@ -1,4 +1,5 @@ (ns electron.ipc + "Provides fns to send ipc messages to electron's main process" (:require [cljs-bean.core :as bean] [promesa.core :as p] [frontend.util :as util])) diff --git a/src/main/electron/listener.cljs b/src/main/electron/listener.cljs index c0d1793998..a5acf2bdca 100644 --- a/src/main/electron/listener.cljs +++ b/src/main/electron/listener.cljs @@ -1,4 +1,6 @@ (ns electron.listener + "System-component-like ns that defines listeners by event name to receive ipc + messages from electron's main process" (:require [frontend.state :as state] [frontend.context.i18n :refer [t]] [frontend.date :as date] diff --git a/src/main/frontend/commands.cljs b/src/main/frontend/commands.cljs index be516ee008..c071d0cb95 100644 --- a/src/main/frontend/commands.cljs +++ b/src/main/frontend/commands.cljs @@ -1,4 +1,5 @@ (ns frontend.commands + "Provides functionality for commands and advanced commands" (:require [clojure.string :as string] [frontend.config :as config] [frontend.date :as date] diff --git a/src/main/frontend/components/file_sync.cljs b/src/main/frontend/components/file_sync.cljs index aa758271c0..a778e3e6e4 100644 --- a/src/main/frontend/components/file_sync.cljs +++ b/src/main/frontend/components/file_sync.cljs @@ -13,7 +13,7 @@ [frontend.fs :as fs] [frontend.fs.sync :as fs-sync] [frontend.handler.file-sync :refer [*beta-unavailable?] :as file-sync-handler] - [frontend.handler.notification :as notifications] + [frontend.handler.notification :as notification] [frontend.handler.page :as page-handler] [frontend.handler.repo :as repo-handler] [frontend.handler.user :as user-handler] @@ -61,7 +61,7 @@ :else nil) (.then #(do - (notifications/show! (str "Cloned to => " dest-dir) :success) + (notification/show! (str "Cloned to => " dest-dir) :success) (web-nfs/ls-dir-files-with-path! dest-dir) (repo-handler/remove-repo! {:url repo}) (close-fn))) diff --git a/src/main/frontend/components/repo.cljs b/src/main/frontend/components/repo.cljs index 8de3d28cb3..32939150c3 100644 --- a/src/main/frontend/components/repo.cljs +++ b/src/main/frontend/components/repo.cljs @@ -18,7 +18,7 @@ [electron.ipc :as ipc] [goog.object :as gobj] [frontend.components.encryption :as encryption] - [frontend.encrypt :as e] + [frontend.encrypt :as encrypt] [cljs.core.async :as async :refer [go clj %)) its))) (defn gen-uuid [] - (front-db/new-block-id)) + (db/new-block-id)) (defn js-load$ [url] @@ -186,4 +186,4 @@ (fix-selection-text-breakline "he is 1\n8 years old") (fix-selection-text-breakline "这是一个\n\n段落") (fix-selection-text-breakline "これ\n\nは、段落") - (fix-selection-text-breakline "this is a te-\nst paragraph")) \ No newline at end of file + (fix-selection-text-breakline "this is a te-\nst paragraph")) diff --git a/src/main/frontend/external.cljs b/src/main/frontend/external.cljs index 0c8523d9b0..39e8524e85 100644 --- a/src/main/frontend/external.cljs +++ b/src/main/frontend/external.cljs @@ -1,4 +1,5 @@ (ns frontend.external + "Handles importing from external services" (:require [frontend.external.roam :refer [->Roam]] [frontend.external.protocol :as protocol])) diff --git a/src/main/frontend/external/protocol.cljc b/src/main/frontend/external/protocol.cljc index 894d2f0acc..388fe4e1f7 100644 --- a/src/main/frontend/external/protocol.cljc +++ b/src/main/frontend/external/protocol.cljc @@ -1,4 +1,4 @@ -(ns frontend.external.protocol) +(ns ^:no-doc frontend.external.protocol) (defprotocol External (toMarkdownFiles [this content config] @@ -7,4 +7,3 @@ ;; 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 index be1ca47b46..6e06429936 100644 --- a/src/main/frontend/external/roam.cljs +++ b/src/main/frontend/external/roam.cljs @@ -1,4 +1,5 @@ (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] diff --git a/src/main/frontend/external/roam_export.cljs b/src/main/frontend/external/roam_export.cljs index af03b7a648..f9ef2deba7 100644 --- a/src/main/frontend/external/roam_export.cljs +++ b/src/main/frontend/external/roam_export.cljs @@ -1,4 +1,4 @@ -(ns frontend.external.roam-export +(ns ^:no-doc frontend.external.roam-export (:require [clojure.set :as s] [clojure.string :as str] [clojure.walk :as walk] diff --git a/src/main/frontend/format.cljs b/src/main/frontend/format.cljs index dc8a89bdb5..e8671a79cc 100644 --- a/src/main/frontend/format.cljs +++ b/src/main/frontend/format.cljs @@ -1,4 +1,6 @@ (ns frontend.format + "Main ns for providing common operations on file content like conversion to html +and edn. Can handle org, markdown and adoc formats" (:require [frontend.format.mldoc :refer [->MldocMode] :as mldoc] [frontend.format.adoc :refer [->AdocMode]] [frontend.format.protocol :as protocol] diff --git a/src/main/frontend/format/adoc.cljs b/src/main/frontend/format/adoc.cljs index 1ab1cd4316..068ebb30bf 100644 --- a/src/main/frontend/format/adoc.cljs +++ b/src/main/frontend/format/adoc.cljs @@ -1,4 +1,5 @@ (ns frontend.format.adoc + "Partial implementation of format protocol for adoc that uses asciidoctor" (:require [frontend.format.protocol :as protocol] [frontend.loader :as loader])) diff --git a/src/main/frontend/format/mldoc.cljs b/src/main/frontend/format/mldoc.cljs index fd4b551e11..9ae43cb17f 100644 --- a/src/main/frontend/format/mldoc.cljs +++ b/src/main/frontend/format/mldoc.cljs @@ -1,5 +1,6 @@ (ns frontend.format.mldoc - "Mldoc code needed by app but not graph-parser" + "Contains any mldoc code needed by app but not graph-parser. Implements format + protocol for org and and markdown formats" (:require [clojure.string :as string] [frontend.format.protocol :as protocol] [goog.object :as gobj] diff --git a/src/main/frontend/format/protocol.cljs b/src/main/frontend/format/protocol.cljs index a7e2542077..9bb091dfca 100644 --- a/src/main/frontend/format/protocol.cljs +++ b/src/main/frontend/format/protocol.cljs @@ -1,4 +1,4 @@ -(ns frontend.format.protocol) +(ns ^:no-doc frontend.format.protocol) (defprotocol Format (toEdn [this content config]) diff --git a/src/main/frontend/fs.cljs b/src/main/frontend/fs.cljs index c5881f85cd..a87d0f5bfb 100644 --- a/src/main/frontend/fs.cljs +++ b/src/main/frontend/fs.cljs @@ -1,9 +1,11 @@ (ns frontend.fs + "System-component-like ns that provides common file operations for all + platforms by delegating to implementations of the fs protocol" (:require [cljs-bean.core :as bean] [frontend.config :as config] [frontend.fs.nfs :as nfs] [frontend.fs.node :as node] - [frontend.fs.capacitor-fs :as mobile] + [frontend.fs.capacitor-fs :as capacitor-fs] [frontend.fs.bfs :as bfs] [frontend.mobile.util :as mobile-util] [frontend.fs.protocol :as protocol] @@ -18,7 +20,7 @@ (defonce nfs-record (nfs/->Nfs)) (defonce bfs-record (bfs/->Bfs)) (defonce node-record (node/->Node)) -(defonce mobile-record (mobile/->Capacitorfs)) +(defonce mobile-record (capacitor-fs/->Capacitorfs)) (defn local-db? [dir] diff --git a/src/main/frontend/fs/bfs.cljs b/src/main/frontend/fs/bfs.cljs index 7e04a0ab40..30e3cb9e78 100644 --- a/src/main/frontend/fs/bfs.cljs +++ b/src/main/frontend/fs/bfs.cljs @@ -1,4 +1,4 @@ -(ns frontend.fs.bfs +(ns ^:no-doc frontend.fs.bfs (:require [frontend.fs.protocol :as protocol] [frontend.util :as util] [promesa.core :as p])) diff --git a/src/main/frontend/fs/capacitor_fs.cljs b/src/main/frontend/fs/capacitor_fs.cljs index 5c8f23ad41..b9d778e6ea 100644 --- a/src/main/frontend/fs/capacitor_fs.cljs +++ b/src/main/frontend/fs/capacitor_fs.cljs @@ -1,4 +1,5 @@ (ns frontend.fs.capacitor-fs + "Implementation of fs protocol for mobile" (:require ["@capacitor/filesystem" :refer [Encoding Filesystem]] [cljs-bean.core :as bean] [clojure.string :as string] diff --git a/src/main/frontend/fs/nfs.cljs b/src/main/frontend/fs/nfs.cljs index 453abc26e1..26bb9bd07f 100644 --- a/src/main/frontend/fs/nfs.cljs +++ b/src/main/frontend/fs/nfs.cljs @@ -1,4 +1,4 @@ -(ns frontend.fs.nfs +(ns ^:no-doc frontend.fs.nfs (:require [frontend.fs.protocol :as protocol] [frontend.util :as util] [clojure.string :as string] diff --git a/src/main/frontend/fs/node.cljs b/src/main/frontend/fs/node.cljs index a0a99a7f62..43b978d54c 100644 --- a/src/main/frontend/fs/node.cljs +++ b/src/main/frontend/fs/node.cljs @@ -1,4 +1,5 @@ (ns frontend.fs.node + "Implementation of fs protocol for desktop" (:require [clojure.string :as string] [electron.ipc :as ipc] [frontend.config :as config] diff --git a/src/main/frontend/fs/protocol.cljs b/src/main/frontend/fs/protocol.cljs index efc4fda703..305d770e21 100644 --- a/src/main/frontend/fs/protocol.cljs +++ b/src/main/frontend/fs/protocol.cljs @@ -1,4 +1,4 @@ -(ns frontend.fs.protocol +(ns ^:no-doc frontend.fs.protocol ;; namespace local config to suppress 'new-path' of 'rename!'. clj-kondo's bug? {:clj-kondo/config {:linters {:private-call {:level :off}}}}) diff --git a/src/main/frontend/fs/sync.cljs b/src/main/frontend/fs/sync.cljs index 966023a0ae..5f4f985b6d 100644 --- a/src/main/frontend/fs/sync.cljs +++ b/src/main/frontend/fs/sync.cljs @@ -1,4 +1,5 @@ (ns frontend.fs.sync + "Main ns for providing file sync functionality" (:require [cljs-http.client :as http] [cljs-time.core :as t] [cljs-time.format :as tf] diff --git a/src/main/frontend/fs/watcher_handler.cljs b/src/main/frontend/fs/watcher_handler.cljs index 2ef3daaad6..c6798813ec 100644 --- a/src/main/frontend/fs/watcher_handler.cljs +++ b/src/main/frontend/fs/watcher_handler.cljs @@ -1,4 +1,5 @@ (ns frontend.fs.watcher-handler + "Main ns that handles file watching events from electron's main process" (:require [clojure.string :as string] [frontend.config :as config] [frontend.db :as db] diff --git a/src/main/frontend/handler.cljs b/src/main/frontend/handler.cljs index cab5389fa1..c74a122f53 100644 --- a/src/main/frontend/handler.cljs +++ b/src/main/frontend/handler.cljs @@ -1,4 +1,6 @@ (ns frontend.handler + "Main ns that handles application startup. Closest ns that we have to a + system. Contains a couple of small system components" (:require [cljs.reader :refer [read-string]] [clojure.string :as string] [electron.ipc :as ipc] diff --git a/src/main/frontend/handler/block.cljs b/src/main/frontend/handler/block.cljs index 94e5add478..e10bab1fdd 100644 --- a/src/main/frontend/handler/block.cljs +++ b/src/main/frontend/handler/block.cljs @@ -1,4 +1,4 @@ -(ns frontend.handler.block +(ns ^:no-doc frontend.handler.block (:require [clojure.set :as set] [clojure.string :as string] diff --git a/src/main/frontend/handler/command_palette.cljs b/src/main/frontend/handler/command_palette.cljs index e391180423..02bf087e93 100644 --- a/src/main/frontend/handler/command_palette.cljs +++ b/src/main/frontend/handler/command_palette.cljs @@ -1,4 +1,5 @@ (ns frontend.handler.command-palette + "System-component-like ns for command palette's functionality" (:require [cljs.spec.alpha :as s] [frontend.modules.shortcut.data-helper :as shortcut-helper] [frontend.spec :as spec] diff --git a/src/main/frontend/handler/common.cljs b/src/main/frontend/handler/common.cljs index 791fb87e6b..f49622adfb 100644 --- a/src/main/frontend/handler/common.cljs +++ b/src/main/frontend/handler/common.cljs @@ -1,4 +1,5 @@ (ns frontend.handler.common + "Common fns for handlers" (:require [cljs-bean.core :as bean] [cljs.reader :as reader] [clojure.string :as string] diff --git a/src/main/frontend/handler/dnd.cljs b/src/main/frontend/handler/dnd.cljs index cb911650c1..ec8c35482a 100644 --- a/src/main/frontend/handler/dnd.cljs +++ b/src/main/frontend/handler/dnd.cljs @@ -1,4 +1,5 @@ (ns frontend.handler.dnd + "Provides fns for drag n drop" (:require [frontend.handler.editor :as editor-handler] [frontend.modules.outliner.core :as outliner-core] [frontend.modules.outliner.tree :as tree] diff --git a/src/main/frontend/handler/draw.cljs b/src/main/frontend/handler/draw.cljs index 43434e6a7d..88f2e6a361 100644 --- a/src/main/frontend/handler/draw.cljs +++ b/src/main/frontend/handler/draw.cljs @@ -1,4 +1,5 @@ (ns frontend.handler.draw + "Provides util handler fns for drawing" (:refer-clojure :exclude [load-file]) (:require [frontend.config :as config] [frontend.date :as date] diff --git a/src/main/frontend/handler/editor.cljs b/src/main/frontend/handler/editor.cljs index fd1021d7d7..96bbf18eb1 100644 --- a/src/main/frontend/handler/editor.cljs +++ b/src/main/frontend/handler/editor.cljs @@ -1,4 +1,4 @@ -(ns frontend.handler.editor +(ns ^:no-doc frontend.handler.editor (:require ["path" :as path] [clojure.set :as set] [clojure.string :as string] @@ -613,7 +613,7 @@ (when edit-block? (if (and replace-empty-target? (string/blank? (:block/content last-block))) - ;; 20ms of waiting for DOM to load the block, to avoid race condition. + ;; 20ms of waiting for DOM to load the block, to avoid race condition. ;; It's ensuring good response under M1 pro ;; Used to be 10ms before, but is causing occasional failure on M1 pro with a full page of blocks, ;; or failing E2E with a small number of blocks. diff --git a/src/main/frontend/handler/editor/keyboards.cljs b/src/main/frontend/handler/editor/keyboards.cljs index 036260dd7a..dc914863e0 100644 --- a/src/main/frontend/handler/editor/keyboards.cljs +++ b/src/main/frontend/handler/editor/keyboards.cljs @@ -1,4 +1,4 @@ -(ns frontend.handler.editor.keyboards +(ns ^:no-doc frontend.handler.editor.keyboards (:require [frontend.handler.editor :as editor-handler] [frontend.mixins :as mixins] [frontend.state :as state] diff --git a/src/main/frontend/handler/editor/lifecycle.cljs b/src/main/frontend/handler/editor/lifecycle.cljs index ee5eac10dd..ef57f3fdde 100644 --- a/src/main/frontend/handler/editor/lifecycle.cljs +++ b/src/main/frontend/handler/editor/lifecycle.cljs @@ -1,4 +1,4 @@ -(ns frontend.handler.editor.lifecycle +(ns ^:no-doc frontend.handler.editor.lifecycle (:require [frontend.handler.editor :as editor-handler :refer [get-state]] [frontend.handler.editor.keyboards :as keyboards-handler] [frontend.state :as state :refer [sub]] diff --git a/src/main/frontend/handler/events.cljs b/src/main/frontend/handler/events.cljs index 4b39d1a207..0bb2d18f33 100644 --- a/src/main/frontend/handler/events.cljs +++ b/src/main/frontend/handler/events.cljs @@ -1,4 +1,7 @@ (ns frontend.handler.events + "System-component-like ns that defines named events and listens on a + core.async channel to handle them. Any part of the system can dispatch + one of these events using state/pub-event!" (:refer-clojure :exclude [run!]) (:require ["@capacitor/filesystem" :refer [Directory Filesystem]] [clojure.core.async :as async] @@ -10,7 +13,7 @@ [frontend.components.diff :as diff] [frontend.components.git :as git-component] [frontend.components.plugins :as plugin] - [frontend.components.search :as search] + [frontend.components.search :as component-search] [frontend.components.shell :as shell] [frontend.config :as config] [frontend.context.i18n :refer [t]] @@ -43,7 +46,7 @@ [frontend.modules.instrumentation.posthog :as posthog] [frontend.modules.outliner.file :as outliner-file] [frontend.modules.shortcut.core :as st] - [frontend.search :as search-db] + [frontend.search :as search] [frontend.state :as state] [frontend.ui :as ui] [frontend.util :as util] @@ -330,7 +333,7 @@ (state/set-modal! shell/shell))) (defmethod handle :go/search [_] - (state/set-modal! search/search-modal + (state/set-modal! component-search/search-modal {:fullscreen? false :close-btn? false})) @@ -453,7 +456,7 @@ (try (update-file-path deprecated-repo current-repo deprecated-app-id current-app-id) (db-persist/delete-graph! deprecated-repo) - (search-db/remove-db! deprecated-repo) + (search/remove-db! deprecated-repo) (state/delete-repo! {:url deprecated-repo}) (state/add-repo! {:url current-repo :nfs? true}) (catch :default e diff --git a/src/main/frontend/handler/export.cljs b/src/main/frontend/handler/export.cljs index 89d7100148..f3bd101f71 100644 --- a/src/main/frontend/handler/export.cljs +++ b/src/main/frontend/handler/export.cljs @@ -1,4 +1,4 @@ -(ns frontend.handler.export +(ns ^:no-doc frontend.handler.export (:require ["@capacitor/filesystem" :refer [Encoding Filesystem]] [cljs.pprint :as pprint] [clojure.set :as s] diff --git a/src/main/frontend/handler/external.cljs b/src/main/frontend/handler/external.cljs index 756874eaa6..de5da1dd0c 100644 --- a/src/main/frontend/handler/external.cljs +++ b/src/main/frontend/handler/external.cljs @@ -1,4 +1,5 @@ (ns frontend.handler.external + "Fns related to import from external services" (:require [clojure.edn :as edn] [clojure.walk :as walk] [frontend.external :as external] @@ -14,7 +15,7 @@ [logseq.graph-parser.mldoc :as gp-mldoc] [logseq.graph-parser.util :as gp-util] [logseq.graph-parser.date-time-util :as date-time-util] - [frontend.handler.page :as page] + [frontend.handler.page :as page-handler] [frontend.handler.editor :as editor] [frontend.handler.notification :as notification] [frontend.util :as util] @@ -87,7 +88,7 @@ (mapv editor/wrap-parse-block)) page-name (:title headers)] (when (not (db/page-exists? page-name)) - (page/create! page-name {:redirect? false})) + (page-handler/create! page-name {:redirect? false})) (let [page-block (db/entity [:block/name (util/page-name-sanity-lc page-name)]) children (:block/_parent page-block) blocks (db/sort-by-left children page-block) @@ -115,13 +116,13 @@ [{:keys [uuid title children] :as tree}] (let [has-children? (seq children) page-format (some-> tree (:children) (first) (:format))] - (try (page/create! title {:redirect? false - :format page-format - :uuid uuid}) - (catch :default e - (notification/show! (str "Error happens when creating page " title ":\n" - e - "\nSkipped and continue the remaining import.") :error))) + (try (page-handler/create! title {:redirect? false + :format page-format + :uuid uuid}) + (catch :default e + (notification/show! (str "Error happens when creating page " title ":\n" + e + "\nSkipped and continue the remaining import.") :error))) (when has-children? (let [page-block (db/entity [:block/name (util/page-name-sanity-lc title)]) first-child (first (:block/_left page-block)) ] diff --git a/src/main/frontend/handler/file.cljs b/src/main/frontend/handler/file.cljs index 75aad4bed0..4f6b7aeac3 100644 --- a/src/main/frontend/handler/file.cljs +++ b/src/main/frontend/handler/file.cljs @@ -1,4 +1,5 @@ (ns frontend.handler.file + "Provides util handler fns for files" (:refer-clojure :exclude [load-file]) (:require [frontend.config :as config] [frontend.db :as db] diff --git a/src/main/frontend/handler/file_sync.cljs b/src/main/frontend/handler/file_sync.cljs index 335f36343f..b13c50529c 100644 --- a/src/main/frontend/handler/file_sync.cljs +++ b/src/main/frontend/handler/file_sync.cljs @@ -1,4 +1,5 @@ (ns frontend.handler.file-sync + "Provides util handler fns for file sync" (:require ["path" :as path] [cljs-time.format :as tf] [cljs.core.async :as async :refer [go js {:key id :url dst})) (fn [] (when theme (js/setTimeout #(select-a-plugin-theme id) 300)))) - (notifications/show! + (notification/show! (str (t :plugin/installed) (t :plugins) ": " name) :success))))) :error @@ -232,7 +233,7 @@ (state/consume-updates-coming-plugin payload true)) ;; notify human tips - (notifications/show! + (notification/show! (str (if (= :error type) "[Error]" "") (str "<" (:id payload) "> ") @@ -446,7 +447,7 @@ (state/set-state! :plugin/active-readme [content item]) (state/set-sub-modal! (fn [_] (display)))) (p/catch #(do (js/console.warn %) - (notifications/show! "No README content." :warn)))) + (notification/show! "No README content." :warn)))) ;; market (state/set-sub-modal! (fn [_] (display repo nil)))))) diff --git a/src/main/frontend/handler/query.cljs b/src/main/frontend/handler/query.cljs index 72e28fca7b..ab9165013d 100644 --- a/src/main/frontend/handler/query.cljs +++ b/src/main/frontend/handler/query.cljs @@ -1,4 +1,5 @@ (ns frontend.handler.query + "Provides util handler fns for query" (:require [clojure.walk :as walk])) (defn normalize-query-function diff --git a/src/main/frontend/handler/recent.cljs b/src/main/frontend/handler/recent.cljs index c6787703e2..07624390b7 100644 --- a/src/main/frontend/handler/recent.cljs +++ b/src/main/frontend/handler/recent.cljs @@ -1,4 +1,5 @@ (ns frontend.handler.recent + "Fns related to recent pages feature" (:require [frontend.db :as db])) (defn add-page-to-recent! diff --git a/src/main/frontend/handler/repeated.cljs b/src/main/frontend/handler/repeated.cljs index f7a94c66fe..99348d2a5d 100644 --- a/src/main/frontend/handler/repeated.cljs +++ b/src/main/frontend/handler/repeated.cljs @@ -1,4 +1,5 @@ (ns frontend.handler.repeated + "Provides fns related to schedule and deadline" (:require [cljs-time.core :as t] [cljs-time.local :as tl] [cljs-time.format :as tf] diff --git a/src/main/frontend/handler/repo.cljs b/src/main/frontend/handler/repo.cljs index 46821def09..fbc59bc27e 100644 --- a/src/main/frontend/handler/repo.cljs +++ b/src/main/frontend/handler/repo.cljs @@ -1,4 +1,5 @@ (ns frontend.handler.repo + "System-component-like ns that manages user's repos/graphs" (:refer-clojure :exclude [clone]) (:require [clojure.string :as string] [frontend.config :as config] diff --git a/src/main/frontend/handler/route.cljs b/src/main/frontend/handler/route.cljs index f40c13a9fd..a9fe158661 100644 --- a/src/main/frontend/handler/route.cljs +++ b/src/main/frontend/handler/route.cljs @@ -1,4 +1,4 @@ -(ns frontend.handler.route +(ns ^:no-doc frontend.handler.route (:require [clojure.string :as string] [frontend.config :as config] [frontend.date :as date] diff --git a/src/main/frontend/handler/search.cljs b/src/main/frontend/handler/search.cljs index 7abc944164..ca2f66db99 100644 --- a/src/main/frontend/handler/search.cljs +++ b/src/main/frontend/handler/search.cljs @@ -1,8 +1,9 @@ (ns frontend.handler.search + "Provides util handler fns for search" (:require [clojure.string :as string] [frontend.config :as config] [frontend.db :as db] - [frontend.handler.notification :as notification-handler] + [frontend.handler.notification :as notification] [frontend.search :as search] [frontend.state :as state] [frontend.util :as util] @@ -118,7 +119,7 @@ (println "Starting to rebuild search indices!") (p/let [_ (search/rebuild-indices!)] (when notice? - (notification-handler/show! + (notification/show! "Search indices rebuilt successfully!" :success))))) @@ -130,6 +131,6 @@ (when cache-stale? (js/console.log "cache stale: " repo) (p/let [_ (search/rebuild-indices! repo)] - (notification-handler/show! + (notification/show! "Stale search cache detected. Search indices rebuilt successfully!" :success)))))) diff --git a/src/main/frontend/handler/shell.cljs b/src/main/frontend/handler/shell.cljs index 5976b251a7..05ff667b1f 100644 --- a/src/main/frontend/handler/shell.cljs +++ b/src/main/frontend/handler/shell.cljs @@ -1,4 +1,5 @@ (ns frontend.handler.shell + "Git related handler fns" (:require [electron.ipc :as ipc] [clojure.string :as string] [logseq.graph-parser.util :as gp-util] diff --git a/src/main/frontend/handler/ui.cljs b/src/main/frontend/handler/ui.cljs index 0ed64b848a..894030faae 100644 --- a/src/main/frontend/handler/ui.cljs +++ b/src/main/frontend/handler/ui.cljs @@ -1,4 +1,4 @@ -(ns frontend.handler.ui +(ns ^:no-doc frontend.handler.ui (:require [cljs-time.core :refer [plus days weeks]] [dommy.core :as dom] [frontend.util :as util] diff --git a/src/main/frontend/handler/user.cljs b/src/main/frontend/handler/user.cljs index 077d3e0399..8fa5821bf8 100644 --- a/src/main/frontend/handler/user.cljs +++ b/src/main/frontend/handler/user.cljs @@ -1,4 +1,5 @@ (ns frontend.handler.user + "Provides user related handler fns like login and logout" (:require [frontend.config :as config] [frontend.handler.config :as config-handler] [frontend.state :as state] diff --git a/src/main/frontend/idb.cljs b/src/main/frontend/idb.cljs index 566a378bc9..271a5d6319 100644 --- a/src/main/frontend/idb.cljs +++ b/src/main/frontend/idb.cljs @@ -1,4 +1,5 @@ (ns frontend.idb + "System-component-like ns that provides indexedDB functionality" (:require ["/frontend/idbkv" :as idb-keyval :refer [Store]] [clojure.string :as string] [frontend.config :as config] diff --git a/src/main/frontend/image.cljs b/src/main/frontend/image.cljs index b1abe335c3..137329f936 100644 --- a/src/main/frontend/image.cljs +++ b/src/main/frontend/image.cljs @@ -1,4 +1,5 @@ (ns frontend.image + "Image related utility fns" (:require ["/frontend/exif" :as exif] [clojure.string :as string] [frontend.date :as date] diff --git a/src/main/frontend/loader.cljs b/src/main/frontend/loader.cljs index 6e2e147481..03b6aa7cb4 100644 --- a/src/main/frontend/loader.cljs +++ b/src/main/frontend/loader.cljs @@ -1,4 +1,5 @@ (ns frontend.loader + "Provides fns related to loading js assets" (:require [goog.net.jsloader :as jsloader] [goog.html.legacyconversions :as conv] [cljs-bean.core :as bean])) diff --git a/src/main/frontend/log.cljs b/src/main/frontend/log.cljs index 8e301128e6..409f0978ff 100644 --- a/src/main/frontend/log.cljs +++ b/src/main/frontend/log.cljs @@ -1,8 +1,11 @@ (ns frontend.log + "System-component-like ns that encapsulates logging functionality" (:require [lambdaisland.glogi :as log] [lambdaisland.glogi.console :as glogi-console] [frontend.config :as config])) +;; TODO: Move code below into a fn to behave like a system component +;; instead of having no control over its behavior at require time (glogi-console/install!) (if config/dev? diff --git a/src/main/frontend/mixins.cljs b/src/main/frontend/mixins.cljs index 338ff2036a..40fdc76bec 100644 --- a/src/main/frontend/mixins.cljs +++ b/src/main/frontend/mixins.cljs @@ -1,4 +1,5 @@ (ns frontend.mixins + "Rum mixins for use in components" (:require [rum.core :as rum] [goog.dom :as dom] [frontend.util :refer [profile] :as util] diff --git a/src/main/frontend/mobile/core.cljs b/src/main/frontend/mobile/core.cljs index 561ee3b623..c608bd5481 100644 --- a/src/main/frontend/mobile/core.cljs +++ b/src/main/frontend/mobile/core.cljs @@ -1,9 +1,10 @@ (ns frontend.mobile.core + "Main ns for handling mobile start" (:require ["@capacitor/app" :refer [^js App]] ["@capacitor/keyboard" :refer [^js Keyboard]] [clojure.string :as string] [promesa.core :as p] - [frontend.fs.capacitor-fs :as mobile-fs] + [frontend.fs.capacitor-fs :as capacitor-fs] [frontend.handler.editor :as editor-handler] [frontend.mobile.deeplink :as deeplink] [frontend.mobile.intent :as intent] @@ -22,7 +23,7 @@ (defn- ios-init "Initialize iOS-specified event listeners" [] - (p/let [path (mobile-fs/ios-ensure-documents!)] + (p/let [path (capacitor-fs/ios-ensure-documents!)] (println "iOS container path: " (js->clj path))) (state/pub-event! [:validate-appId]) diff --git a/src/main/frontend/namespaces.cljc b/src/main/frontend/namespaces.cljc index efc971028c..bbacda00de 100644 --- a/src/main/frontend/namespaces.cljc +++ b/src/main/frontend/namespaces.cljc @@ -1,4 +1,4 @@ -(ns frontend.namespaces +(ns ^:no-doc frontend.namespaces #?(:cljs (:require-macros [frontend.namespaces]))) ;; copy from https://github.com/clj-commons/potemkin/issues/31#issuecomment-110689951 diff --git a/src/main/frontend/page.cljs b/src/main/frontend/page.cljs index a73bf0da9d..1d388be234 100644 --- a/src/main/frontend/page.cljs +++ b/src/main/frontend/page.cljs @@ -1,4 +1,5 @@ (ns frontend.page + "Provides root component for both Logseq app and publishing build" (:require [rum.core :as rum] [frontend.state :as state] [frontend.ui :as ui] diff --git a/src/main/frontend/publishing.cljs b/src/main/frontend/publishing.cljs index b1f67d0e16..fae90dd3c3 100644 --- a/src/main/frontend/publishing.cljs +++ b/src/main/frontend/publishing.cljs @@ -1,4 +1,5 @@ (ns frontend.publishing + "Entry ns for publishing build. Handles primary publishing app behaviors" (:require [frontend.state :as state] [datascript.core :as d] [frontend.db :as db] diff --git a/src/main/frontend/publishing/html.cljs b/src/main/frontend/publishing/html.cljs index 4ee3411783..2432c9daeb 100644 --- a/src/main/frontend/publishing/html.cljs +++ b/src/main/frontend/publishing/html.cljs @@ -1,4 +1,4 @@ -(ns frontend.publishing.html +(ns ^:no-doc frontend.publishing.html (:require-macros [hiccups.core]) (:require [frontend.state :as state] [frontend.util :as util] diff --git a/src/main/frontend/regex.cljc b/src/main/frontend/regex.cljc index 5711afa932..2d8c9770b6 100644 --- a/src/main/frontend/regex.cljc +++ b/src/main/frontend/regex.cljc @@ -1,4 +1,4 @@ -(ns frontend.regex +(ns ^:no-doc frontend.regex (:require [clojure.string :as string])) (def re-specials #"([\-\/\\\^\$\*\+\?\.\(\)\|\[\]\{\}])") diff --git a/src/main/frontend/routes.cljs b/src/main/frontend/routes.cljs index 9d2d035166..e10c63713e 100644 --- a/src/main/frontend/routes.cljs +++ b/src/main/frontend/routes.cljs @@ -1,4 +1,5 @@ (ns frontend.routes + "Defines routes for use with reitit router" (:require [frontend.components.home :as home] [frontend.components.repo :as repo] [frontend.components.file :as file] diff --git a/src/main/frontend/rum.cljs b/src/main/frontend/rum.cljs index 09022fbbb4..05a1fadcd6 100644 --- a/src/main/frontend/rum.cljs +++ b/src/main/frontend/rum.cljs @@ -1,4 +1,5 @@ (ns frontend.rum + "Utility fns for rum" (:require [clojure.string :as s] [clojure.set :as set] [clojure.walk :as w] @@ -33,6 +34,7 @@ x)) data))) +;; TODO: Replace this with rum's built in rum.core/adapt-class ;; adapted from https://github.com/tonsky/rum/issues/20 (defn adapt-class ([react-class] diff --git a/src/main/frontend/search.cljs b/src/main/frontend/search.cljs index a8a4406b6f..3d6df542c8 100644 --- a/src/main/frontend/search.cljs +++ b/src/main/frontend/search.cljs @@ -1,4 +1,6 @@ (ns frontend.search + "Provides search functionality for a number of features including Cmd-K + search. Most of these fns depend on the search protocol" (:require [cljs-bean.core :as bean] [clojure.string :as string] [logseq.graph-parser.config :as gp-config] diff --git a/src/main/frontend/search/browser.cljs b/src/main/frontend/search/browser.cljs index ebbd552c7b..fe41d2f39c 100644 --- a/src/main/frontend/search/browser.cljs +++ b/src/main/frontend/search/browser.cljs @@ -1,4 +1,5 @@ (ns frontend.search.browser + "Browser implementation of search protocol" (:require [cljs-bean.core :as bean] [frontend.search.db :as search-db :refer [indices]] [frontend.search.protocol :as protocol] diff --git a/src/main/frontend/search/db.cljs b/src/main/frontend/search/db.cljs index f5b655d8bb..22c401574a 100644 --- a/src/main/frontend/search/db.cljs +++ b/src/main/frontend/search/db.cljs @@ -1,4 +1,4 @@ -(ns frontend.search.db +(ns ^:no-doc frontend.search.db (:require [cljs-bean.core :as bean] [clojure.string :as string] [frontend.db :as db] diff --git a/src/main/frontend/search/node.cljs b/src/main/frontend/search/node.cljs index 6c8d9cd2ac..a37927a47a 100644 --- a/src/main/frontend/search/node.cljs +++ b/src/main/frontend/search/node.cljs @@ -1,4 +1,5 @@ (ns frontend.search.node + "NodeJS implementation of search protocol" (:require [cljs-bean.core :as bean] [electron.ipc :as ipc] [frontend.search.db :as search-db] diff --git a/src/main/frontend/search/protocol.cljs b/src/main/frontend/search/protocol.cljs index 6489dcac35..30d874b30d 100644 --- a/src/main/frontend/search/protocol.cljs +++ b/src/main/frontend/search/protocol.cljs @@ -1,4 +1,4 @@ -(ns frontend.search.protocol) +(ns ^:no-doc frontend.search.protocol) (defprotocol Engine (query [this q option]) diff --git a/src/main/frontend/security.cljs b/src/main/frontend/security.cljs index 6936b5fb7b..1378f25dc4 100644 --- a/src/main/frontend/security.cljs +++ b/src/main/frontend/security.cljs @@ -1,4 +1,5 @@ (ns frontend.security + "Provide security focused fns like preventing XSS attacks" (:require [clojure.walk :as walk] [frontend.util :as util])) diff --git a/src/main/frontend/spec.cljs b/src/main/frontend/spec.cljs index 6876b8ddb1..b0a54f3192 100644 --- a/src/main/frontend/spec.cljs +++ b/src/main/frontend/spec.cljs @@ -1,4 +1,5 @@ (ns frontend.spec + "Clojure spec related setup and helpers" (:require [cljs.spec.alpha :as s] [frontend.config :as config] [lambdaisland.glogi :as log] diff --git a/src/main/frontend/state.cljs b/src/main/frontend/state.cljs index 673fed2061..ff50797d98 100644 --- a/src/main/frontend/state.cljs +++ b/src/main/frontend/state.cljs @@ -1,4 +1,6 @@ (ns frontend.state + "Provides main application state, fns associated to set and state based rum + cursors" (:require [cljs-bean.core :as bean] [cljs.core.async :as async] [clojure.string :as string] diff --git a/src/main/frontend/storage.cljs b/src/main/frontend/storage.cljs index e47f7957b6..52faf9fea9 100644 --- a/src/main/frontend/storage.cljs +++ b/src/main/frontend/storage.cljs @@ -1,4 +1,6 @@ (ns frontend.storage + "Provides fns for most common operations with localStorage. Assumes + localStorage values are edn" (:refer-clojure :exclude [get set remove]) (:require [cljs.reader :as reader] [datascript.transit :as dt] diff --git a/src/main/frontend/template.cljs b/src/main/frontend/template.cljs index 2217f7fef9..0cce099892 100644 --- a/src/main/frontend/template.cljs +++ b/src/main/frontend/template.cljs @@ -1,4 +1,5 @@ (ns frontend.template + "Provides template related functionality" (:require [clojure.string :as string] [frontend.date :as date] [frontend.state :as state] diff --git a/src/main/frontend/ui.cljs b/src/main/frontend/ui.cljs index cf2418e789..0ad6c4365c 100644 --- a/src/main/frontend/ui.cljs +++ b/src/main/frontend/ui.cljs @@ -1,8 +1,9 @@ (ns frontend.ui + "Main ns for reusable components" (:require [clojure.string :as string] [frontend.components.svg :as svg] [frontend.context.i18n :refer [t]] - [frontend.handler.notification :as notification-handler] + [frontend.handler.notification :as notification] [frontend.mixins :as mixins] [frontend.modules.shortcut.core :as shortcut] [frontend.rum :as r] @@ -275,7 +276,7 @@ [:div.ml-4.flex-shrink-0.flex [:button.inline-flex.text-gray-400.focus:outline-none.focus:text-gray-500.transition.ease-in-out.duration-150.notification-close-button {:on-click (fn [] - (notification-handler/clear! uid))} + (notification/clear! uid))} [:svg.h-5.w-5 {:fill "currentColor", :view-Box "0 0 20 20"} [:path @@ -781,7 +782,7 @@ < {:did-catch (fn [state error _info] (log/error :exception error) - (notification-handler/show! + (notification/show! (str "Error caught by UI!\n " error) :error) (assoc state ::error error))} diff --git a/src/main/frontend/ui/date_picker.cljs b/src/main/frontend/ui/date_picker.cljs index c959274d2e..c020fce9d0 100644 --- a/src/main/frontend/ui/date_picker.cljs +++ b/src/main/frontend/ui/date_picker.cljs @@ -1,4 +1,4 @@ -(ns frontend.ui.date-picker +(ns ^:no-doc frontend.ui.date-picker (:require [cljs-time.core :refer [after? before? day day-of-week days first-day-of-the-month minus month months plus year]] [cljs-time.format :refer [formatter unparse]] [frontend.modules.shortcut.core :as shortcut] diff --git a/src/main/frontend/util.cljc b/src/main/frontend/util.cljc index d3e2d59d33..c26f6fcf63 100644 --- a/src/main/frontend/util.cljc +++ b/src/main/frontend/util.cljc @@ -1,4 +1,5 @@ (ns frontend.util + "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 diff --git a/src/main/frontend/util/clock.cljs b/src/main/frontend/util/clock.cljs index 456f2a1dc7..4ccf161469 100644 --- a/src/main/frontend/util/clock.cljs +++ b/src/main/frontend/util/clock.cljs @@ -1,4 +1,5 @@ (ns frontend.util.clock + "Provides clock related functionality used by tasks" (:require [frontend.state :as state] [frontend.util.drawer :as drawer] [frontend.util :as util] diff --git a/src/main/frontend/util/cursor.cljs b/src/main/frontend/util/cursor.cljs index 58f610c12f..0e4a2282a6 100644 --- a/src/main/frontend/util/cursor.cljs +++ b/src/main/frontend/util/cursor.cljs @@ -1,4 +1,4 @@ -(ns frontend.util.cursor +(ns ^:no-doc frontend.util.cursor (:require [cljs-bean.core :as bean] [clojure.string :as string] [frontend.util :as util] diff --git a/src/main/frontend/util/drawer.cljs b/src/main/frontend/util/drawer.cljs index 7abc8c6d09..3977d2ec2b 100644 --- a/src/main/frontend/util/drawer.cljs +++ b/src/main/frontend/util/drawer.cljs @@ -1,4 +1,4 @@ -(ns frontend.util.drawer +(ns ^:no-doc frontend.util.drawer (:require [clojure.string :as string] [frontend.util :as util] [logseq.graph-parser.mldoc :as gp-mldoc] diff --git a/src/main/frontend/util/fs.cljs b/src/main/frontend/util/fs.cljs index b09a5952a8..1c9a581c9f 100644 --- a/src/main/frontend/util/fs.cljs +++ b/src/main/frontend/util/fs.cljs @@ -1,4 +1,5 @@ (ns frontend.util.fs + "Misc util fns built on top of frontend.fs" (:require ["path" :as path] [clojure.string :as string] [frontend.fs :as fs] diff --git a/src/main/frontend/util/keycode.cljs b/src/main/frontend/util/keycode.cljs index db38171b0a..91c19e1f46 100644 --- a/src/main/frontend/util/keycode.cljs +++ b/src/main/frontend/util/keycode.cljs @@ -1,4 +1,5 @@ -(ns frontend.util.keycode) +(ns frontend.util.keycode + "Provides names for common keycodes") ;; code / keycode should all be deprecated for non funcional keys ;; (def left-square-bracket 219) ;; deprecated diff --git a/src/main/frontend/util/list.cljs b/src/main/frontend/util/list.cljs index a7397db605..01499e41aa 100644 --- a/src/main/frontend/util/list.cljs +++ b/src/main/frontend/util/list.cljs @@ -1,4 +1,5 @@ (ns frontend.util.list + "High level list operations for use in editor" (:require [frontend.util.thingatpt :as thingatpt] [frontend.util.cursor :as cursor] [clojure.string :as string])) diff --git a/src/main/frontend/util/marker.cljs b/src/main/frontend/util/marker.cljs index 6fec52bec6..26f6bb994b 100644 --- a/src/main/frontend/util/marker.cljs +++ b/src/main/frontend/util/marker.cljs @@ -1,4 +1,5 @@ (ns frontend.util.marker + "Task (formerly todo) related util fns" (:require [clojure.string :as string] [frontend.util :as util])) diff --git a/src/main/frontend/util/page_property.cljs b/src/main/frontend/util/page_property.cljs index 2f04615a7a..8e33cdcf60 100644 --- a/src/main/frontend/util/page_property.cljs +++ b/src/main/frontend/util/page_property.cljs @@ -1,4 +1,4 @@ -(ns frontend.util.page-property +(ns ^:no-doc frontend.util.page-property (:require [clojure.string :as string] [frontend.db :as db] [frontend.modules.outliner.core :as outliner-core] diff --git a/src/main/frontend/util/persist_var.cljs b/src/main/frontend/util/persist_var.cljs index 22e0d92da9..35cb35bc24 100644 --- a/src/main/frontend/util/persist_var.cljs +++ b/src/main/frontend/util/persist_var.cljs @@ -1,4 +1,6 @@ (ns frontend.util.persist-var + "System-component-like ns that provides an atom-like abstraction over an edn + file" (:require [frontend.config :as config] [frontend.state :as state] [frontend.fs :as fs] diff --git a/src/main/frontend/util/priority.cljs b/src/main/frontend/util/priority.cljs index 106c468a7e..4f274ef721 100644 --- a/src/main/frontend/util/priority.cljs +++ b/src/main/frontend/util/priority.cljs @@ -1,4 +1,5 @@ (ns frontend.util.priority + "Util fns for task priorities e.g. A, B, C" (:require [clojure.string :as string] [frontend.util :as util] [frontend.util.marker :as marker])) diff --git a/src/main/frontend/util/text.cljs b/src/main/frontend/util/text.cljs index fea8a1a60d..dbc9ec21e8 100644 --- a/src/main/frontend/util/text.cljs +++ b/src/main/frontend/util/text.cljs @@ -1,4 +1,6 @@ (ns frontend.util.text + "Misc low-level utility text fns that are useful across features or don't have + a good ns to be in yet" (:require [clojure.string :as string] [goog.string :as gstring] [frontend.util :as util])) diff --git a/src/main/frontend/util/thingatpt.cljs b/src/main/frontend/util/thingatpt.cljs index 8dbcf043e2..f029970a79 100644 --- a/src/main/frontend/util/thingatpt.cljs +++ b/src/main/frontend/util/thingatpt.cljs @@ -1,4 +1,4 @@ -(ns frontend.util.thingatpt +(ns ^:no-doc frontend.util.thingatpt (:require [clojure.string :as string] [frontend.state :as state] [frontend.util.cursor :as cursor] diff --git a/src/main/frontend/util/url.cljs b/src/main/frontend/util/url.cljs index 3d31d3f6bc..14a8631b9a 100644 --- a/src/main/frontend/util/url.cljs +++ b/src/main/frontend/util/url.cljs @@ -1,4 +1,5 @@ (ns frontend.util.url + "Util fns related to protocol url" (:require [frontend.db.conn :as db-conn])) ;; Keep same as electron/electron.core diff --git a/src/main/frontend/version.cljs b/src/main/frontend/version.cljs index 19eaafcbc0..0da621f7dc 100644 --- a/src/main/frontend/version.cljs +++ b/src/main/frontend/version.cljs @@ -1,3 +1,3 @@ -(ns frontend.version) +(ns ^:no-doc frontend.version) (defonce version "0.8.7") diff --git a/src/main/frontend/state_test.cljs b/src/test/frontend/state_test.cljs similarity index 100% rename from src/main/frontend/state_test.cljs rename to src/test/frontend/state_test.cljs From 9c7b4ea2016fb28b16ee42a7136c73dd52d8ce4b Mon Sep 17 00:00:00 2001 From: Gabriel Horner Date: Thu, 22 Sep 2022 21:19:22 -0400 Subject: [PATCH 02/10] Delete unused ns Commented out a long time ago in 4e0f65a17fb1de5e38ed97cda6072e1a1111fb2d --- .carve/ignore | 3 +-- src/main/frontend/blob.cljs | 29 ----------------------------- src/main/frontend/image.cljs | 17 +---------------- 3 files changed, 2 insertions(+), 47 deletions(-) delete mode 100644 src/main/frontend/blob.cljs diff --git a/.carve/ignore b/.carve/ignore index 53fe35efa1..e6604ecc81 100644 --- a/.carve/ignore +++ b/.carve/ignore @@ -4,7 +4,6 @@ electron.core/start electron.core/stop ;; repl fn electron.search/query -frontend.blob/blob ;; Used by shadow-cljs frontend.core/stop ;; For repl @@ -79,4 +78,4 @@ frontend.test.frontend-node-test-runner/main logseq.graph-parser.nbb-test-runner/run-tests ;; For debugging frontend.fs.sync/debug-print-sync-events-loop -frontend.fs.sync/stop-debug-print-sync-events-loop \ No newline at end of file +frontend.fs.sync/stop-debug-print-sync-events-loop diff --git a/src/main/frontend/blob.cljs b/src/main/frontend/blob.cljs deleted file mode 100644 index 6232b91206..0000000000 --- a/src/main/frontend/blob.cljs +++ /dev/null @@ -1,29 +0,0 @@ -(ns frontend.blob) - -(defn- decode - "Decodes the data portion of a data url from base64" - [[media-type data]] - [media-type (js/atob data)]) - -(defn- uint8 - "Converts a base64 decoded data string to a Uint8Array" - [[media-type data]] - (->> (map #(.charCodeAt %1) data) - js/Uint8Array. - (vector media-type))) - -(defn- make-blob - "Creates a JS Blob object from a media type and a Uint8Array" - [[media-type uint8]] - (js/Blob. (array uint8) (js-obj "type" media-type))) - -(defn blob - "Converts a data-url into a JS Blob. This is useful for uploading - image data from JavaScript." - [data-url] - {:pre [(string? data-url)]} - (-> (re-find #"^data:([^;]+);base64,(.*)$" data-url) - rest - decode - uint8 - make-blob)) diff --git a/src/main/frontend/image.cljs b/src/main/frontend/image.cljs index 137329f936..20aaa30cba 100644 --- a/src/main/frontend/image.cljs +++ b/src/main/frontend/image.cljs @@ -85,19 +85,4 @@ (string/join "_")) file-name (str ymd "_" (gobj/get file "name"))] (when (= 0 (.indexOf file-type "image/")) - (file-handler file file-name file-type) - ;; (let [img (js/Image.)] - ;; (set! (.-onload img) - ;; (fn [] - ;; (get-orientation img - ;; (fn [^js off-canvas] - ;; (let [file-form-data ^js (js/FormData.) - ;; data-url (.toDataURL off-canvas) - ;; blob (blob/blob data-url)] - ;; (.append file-form-data "file" blob) - ;; (file-cb file file-form-data file-name file-type))) - ;; max-width - ;; max-height))) - ;; (set! (.-src img) - ;; (create-object-url file))) - )))) + (file-handler file file-name file-type))))) From 8b144269f7437d6bf50edfd6137d6cf41629b196 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Thu, 22 Sep 2022 18:10:46 +0800 Subject: [PATCH 03/10] refactor: unify heading UX for both markdown and org mode --- deps/db/src/logseq/db/schema.cljs | 4 -- .../src/logseq/graph_parser/block.cljs | 29 +++++++---- .../graph_parser/test/docs_graph_helper.cljs | 3 +- src/main/frontend/commands.cljs | 46 ++++++++++------ src/main/frontend/components/block.cljs | 22 +++----- src/main/frontend/components/content.cljs | 52 ++++++++++--------- src/main/frontend/components/editor.cljs | 2 +- src/main/frontend/db/model.cljs | 1 - src/main/frontend/handler/editor.cljs | 26 ++++++++-- src/main/frontend/handler/events.cljs | 4 ++ src/main/frontend/handler/export.cljs | 1 - src/main/frontend/mobile/action_bar.cljs | 7 --- src/main/frontend/modules/file/core.cljs | 19 +++---- src/main/frontend/ui.css | 4 +- 14 files changed, 124 insertions(+), 96 deletions(-) diff --git a/deps/db/src/logseq/db/schema.cljs b/deps/db/src/logseq/db/schema.cljs index 698a77be24..f110b150ff 100644 --- a/deps/db/src/logseq/db/schema.cljs +++ b/deps/db/src/logseq/db/schema.cljs @@ -62,9 +62,6 @@ ;; first block that's not a heading or unordered list :block/pre-block? {} - ;; heading's level (the block must be a heading) - :block/heading-level {} - ;; scheduled day :block/scheduled {} @@ -116,7 +113,6 @@ :block/deadline :block/repeated? :block/pre-block? - :block/heading-level :block/type :block/properties :block/properties-order diff --git a/deps/graph-parser/src/logseq/graph_parser/block.cljs b/deps/graph-parser/src/logseq/graph_parser/block.cljs index 27920beb12..accc1cd106 100644 --- a/deps/graph-parser/src/logseq/graph_parser/block.cljs +++ b/deps/graph-parser/src/logseq/graph_parser/block.cljs @@ -541,6 +541,16 @@ blocks)] (with-path-refs blocks))) +(defn- with-heading-property + [properties markdown-heading? size] + (let [properties (if markdown-heading? + (assoc properties :heading size) + properties)] + (if (true? (:heading properties)) + ;; default-level 2 + (assoc properties :heading 2) + properties))) + (defn- construct-block [block properties timestamps body encoded-content format pos-meta with-id? {:keys [block-pattern supported-formats db date-formatter]}] (let [id (get-custom-id-or-new-id properties) @@ -551,18 +561,17 @@ markdown-heading? (and (:size block) (= :markdown format)) block (if markdown-heading? (assoc block - :type :heading - :level (if unordered? (:level block) 1) - :heading-level (or (:size block) 6)) + :level (if unordered? (:level block) 1)) block) block (cond-> - (assoc block - :uuid id - :refs ref-pages-in-properties - :format format - :meta pos-meta) - (seq (:properties properties)) - (assoc :properties (:properties properties) + (-> (assoc block + :uuid id + :refs ref-pages-in-properties + :format format + :meta pos-meta) + (dissoc :size)) + (or (seq (:properties properties)) markdown-heading?) + (assoc :properties (with-heading-property (:properties properties) markdown-heading? (:size block)) :properties-text-values (:properties-text-values properties) :properties-order (vec (:properties-order properties))) diff --git a/deps/graph-parser/src/logseq/graph_parser/test/docs_graph_helper.cljs b/deps/graph-parser/src/logseq/graph_parser/test/docs_graph_helper.cljs index ac93c623cc..400d7c30f9 100644 --- a/deps/graph-parser/src/logseq/graph_parser/test/docs_graph_helper.cljs +++ b/deps/graph-parser/src/logseq/graph_parser/test/docs_graph_helper.cljs @@ -115,10 +115,9 @@ :block/priority 4 :block/deadline 1 :block/collapsed? 22 - :block/heading-level 60 :block/repeated? 1} (->> [:block/scheduled :block/priority :block/deadline :block/collapsed? - :block/heading-level :block/repeated?] + :block/repeated?] (map (fn [attr] [attr (ffirst (d/q [:find (list 'count '?b) :where ['?b attr]] diff --git a/src/main/frontend/commands.cljs b/src/main/frontend/commands.cljs index c071d0cb95..40d7b4f30b 100644 --- a/src/main/frontend/commands.cljs +++ b/src/main/frontend/commands.cljs @@ -132,13 +132,11 @@ [:editor/set-heading heading] [:editor/move-cursor-to-end]]) -(defn- markdown-headings +(defn- headings [] - (let [format (state/get-preferred-format)] - (when (= (name format) "markdown") - (mapv (fn [level] - (let [heading (str "h" level)] - [heading (->heading (apply str (repeat level "#")))])) (range 1 7))))) + (mapv (fn [level] + (let [heading (str "h" level)] + [heading (->heading level)])) (range 1 7))) (defonce *matched-commands (atom nil)) (defonce *initial-commands (atom nil)) @@ -241,7 +239,7 @@ ;; ["Upload an image" [[:editor/click-hidden-file-input :id]]] )] - (markdown-headings) + (headings) ;; time & date @@ -593,19 +591,33 @@ (property/goto-properties-end format current-input) (cursor/move-cursor-backward current-input 3))))) +(defonce markdown-heading-pattern #"^#+\s+") +(defn set-markdown-heading + [content heading] + (let [heading-str (apply str (repeat heading "#"))] + (if (util/safe-re-find markdown-heading-pattern content) + (string/replace-first content + markdown-heading-pattern + (str heading-str " ")) + (str heading-str " " (string/triml content))))) + +(defn clear-markdown-heading + [content] + [:pre (string? content)] + (string/replace-first content + markdown-heading-pattern + "")) + (defmethod handle-step :editor/set-heading [[_ heading]] (when-let [input-id (state/get-edit-input-id)] (when-let [current-input (gdom/getElement input-id)] - (let [edit-content (gobj/get current-input "value") - heading-pattern #"^#+\s+" - new-value (cond - (util/safe-re-find heading-pattern edit-content) - (string/replace-first edit-content - heading-pattern - (str heading " ")) - :else - (str heading " " (string/triml edit-content)))] - (state/set-edit-content! input-id new-value))))) + (let [current-block (state/get-edit-block) + format (:block/format current-block)] + (if (= format :markdown) + (let [edit-content (gobj/get current-input "value") + new-content (set-markdown-heading edit-content heading)] + (state/set-edit-content! input-id new-content)) + (state/pub-event! [:editor/set-org-mode-heading current-block heading])))))) (defmethod handle-step :editor/search-page [[_]] (state/set-editor-action! :page-search)) diff --git a/src/main/frontend/components/block.cljs b/src/main/frontend/components/block.cljs index 5b4df4ac15..b181b37d5a 100644 --- a/src/main/frontend/components/block.cljs +++ b/src/main/frontend/components/block.cljs @@ -1839,7 +1839,7 @@ (declare block-content) (defn build-block-title - [config {:block/keys [title marker pre-block? properties level heading-level] + [config {:block/keys [title marker pre-block? properties] :as t}] (let [config (assoc config :block t) slide? (boolean (:slide? config)) @@ -1856,14 +1856,9 @@ priority (priority-cp t) tags (block-tags-cp t) bg-color (:background-color properties) - heading-level (or (and heading-level - (<= heading-level 6) - heading-level) - (and (get properties :heading) - (<= level 6) - level)) - elem (if heading-level - (keyword (str "h" heading-level + heading (:heading properties) + elem (if heading + (keyword (str "h" heading (when block-ref? ".inline"))) :span.inline)] (->elem @@ -2289,7 +2284,7 @@ (rum/defcs block-content-or-editor < rum/reactive (rum/local true ::hide-block-refs?) - [state config {:block/keys [uuid format] :as block} edit-input-id block-id heading-level edit?] + [state config {:block/keys [uuid format] :as block} edit-input-id block-id edit?] (let [*hide-block-refs? (get state ::hide-block-refs?) hide-block-refs? @*hide-block-refs? editor-box (get config :editor-box) @@ -2307,7 +2302,6 @@ :block-id uuid :block-parent-id block-id :format format - :heading-level heading-level :on-hide (fn [value event] (when (= event :esc) (editor-handler/save-block! (editor-handler/get-state) value) @@ -2574,7 +2568,7 @@ block (if ref? (merge block (db/pull-block (:db/id block))) block) - {:block/keys [uuid children pre-block? top? refs heading-level level format content properties]} block + {:block/keys [uuid children pre-block? top? refs level format content properties]} block config (if navigated? (assoc config :id (str navigating-block)) config) block (merge block (block/parse-title-and-body uuid format pre-block? content)) blocks-container-id (:blocks-container-id config) @@ -2583,7 +2577,7 @@ config (if (nil? (:query-result config)) (assoc config :query-result (atom nil)) config) - heading? (or (:heading properties) (and heading-level (<= heading-level 6))) + heading? (:heading properties) *control-show? (get state ::control-show?) db-collapsed? (util/collapsed? block) collapsed? (cond @@ -2665,7 +2659,7 @@ (when @*show-left-menu? (block-left-menu config block)) - (block-content-or-editor config block edit-input-id block-id heading-level edit?) + (block-content-or-editor config block edit-input-id block-id edit?) (when @*show-right-menu? (block-right-menu config block edit?))] diff --git a/src/main/frontend/components/content.cljs b/src/main/frontend/components/content.cljs index 61d61ee22d..64a9e99484 100644 --- a/src/main/frontend/components/content.cljs +++ b/src/main/frontend/components/content.cljs @@ -84,7 +84,7 @@ :on-click editor-handler/copy-block-embeds} "Copy block embeds" nil) - + [:hr.menu-separator] (ui/menu-link @@ -100,8 +100,7 @@ "#787f97" "#978626" "#49767b" - "#264c9b" - "#793e3e"]) + "#264c9b"]) (defonce *template-including-parent? (atom nil)) @@ -163,22 +162,36 @@ (rum/defc ^:large-vars/cleanup-todo block-context-menu-content [_target block-id] (when-let [block (db/entity [:block/uuid block-id])] - (let [properties (:block/properties block) - heading? (true? (:heading properties))] + (let [format (:block/format block)] [:.menu-links-wrapper - [:div.flex-row.flex.justify-between.pb-2.pt-1.px-2 - [:div.flex-row.flex.justify-between + [:div.flex.flex-row.justify-between.pb-2.pt-1.px-2.items-center + [:div.flex.flex-row.justify-between.flex-1 (for [color block-background-colors] [:a.m-2.shadow-sm {:on-click (fn [_e] (editor-handler/set-block-property! block-id "background-color" color))} - [:div.heading-bg {:style {:background-color color}}]]) - [:a.m-2.shadow-sm - {:title (t :remove-background) - :on-click (fn [_e] - (editor-handler/remove-block-property! block-id "background-color"))} - [:div.heading-bg.remove "-"]]]] - + [:div.heading-bg {:style {:background-color color}}]])] + [:a.m-2.shadow-sm + {:title (t :remove-background) + :on-click (fn [_e] + (editor-handler/remove-block-property! block-id "background-color"))} + [:div.heading-bg.remove "-"]]] + + [:div.flex.flex-row.justify-between.pb-2.pt-1.px-2.items-center + [:div.flex.flex-row.justify-between.flex-1 + (for [i (range 1 7)] + (ui/button + (str "H" i) + :on-click (fn [_e] + (editor-handler/set-heading! block-id format i)) + :intent "link" + :small? true))] + [:a.m-2 + {:title (t :remove-heading) + :on-click (fn [_e] + (editor-handler/remove-heading! block-id format))} + [:div.heading-bg.remove "-"]]] + [:hr.menu-separator] (ui/menu-link @@ -232,17 +245,6 @@ [:hr.menu-separator] - (ui/menu-link - {:key "Convert heading" - :on-click (fn [_e] - (if heading? - (editor-handler/remove-block-property! block-id :heading) - (editor-handler/set-block-property! block-id :heading true)))} - (if heading? - "Convert back to a block" - "Convert to a heading") - nil) - (block-template block-id) (if (srs/card-block? block) diff --git a/src/main/frontend/components/editor.cljs b/src/main/frontend/components/editor.cljs index 31c94c62d5..b4b4dccd69 100644 --- a/src/main/frontend/components/editor.cljs +++ b/src/main/frontend/components/editor.cljs @@ -568,7 +568,7 @@ (rum/defcs box < rum/reactive {:init (fn [state] - (assoc state ::heading-level (:heading-level (first (:rum/args state))) + (assoc state ::id (str (random-uuid)))) :did-mount (fn [state] (state/set-editor-args! (:rum/args state)) diff --git a/src/main/frontend/db/model.cljs b/src/main/frontend/db/model.cljs index e5cdf8d783..01192481e9 100644 --- a/src/main/frontend/db/model.cljs +++ b/src/main/frontend/db/model.cljs @@ -54,7 +54,6 @@ :block/created-at :block/updated-at :block/file - :block/heading-level {:block/page [:db/id :block/name :block/original-name :block/journal-day]} {:block/_parent ...}]) diff --git a/src/main/frontend/handler/editor.cljs b/src/main/frontend/handler/editor.cljs index 96bbf18eb1..41db7f783a 100644 --- a/src/main/frontend/handler/editor.cljs +++ b/src/main/frontend/handler/editor.cljs @@ -316,9 +316,10 @@ (block/parse-title-and-body uuid format pre-block? (:block/content block))) properties (:block/properties block) real-content (:block/content block) - content (if (and (seq properties) real-content (not= real-content content)) - (property/with-built-in-properties properties content format) - content) + content (let [properties (if (= format :markdown) (dissoc properties :heading) properties)] + (if (and (seq properties) real-content (not= real-content content)) + (property/with-built-in-properties properties content format) + content)) content (drawer/with-logbook block content) content (with-timetracking block content) first-block? (= left page) @@ -1939,6 +1940,7 @@ (property/insert-properties format content props)) ast (mldoc/->edn content* (gp-mldoc/default-config format)) blocks (block/extract-blocks ast content* format {}) + _ (prn {:block (first blocks)}) fst-block (first blocks) fst-block (if (and keep-uuid? (uuid? (:uuid block))) (assoc fst-block :block/uuid (:uuid block)) @@ -3465,3 +3467,21 @@ ;; has children (first (:block/_parent (db/entity (:db/id block))))) (util/collapsed? block))) + +(defn set-heading! + [block-id format heading] + (if (= format :markdown) + (let [repo (state/get-current-repo) + block (db/entity [:block/uuid block-id]) + content' (commands/set-markdown-heading (:block/content block) heading)] + (save-block! repo block-id content')) + (set-block-property! block-id "heading" heading))) + +(defn remove-heading! + [block-id format] + (remove-block-property! block-id "heading") + (when (= format :markdown) + (let [repo (state/get-current-repo) + block (db/entity [:block/uuid block-id]) + content' (commands/clear-markdown-heading (:block/content block))] + (save-block! repo block-id content')))) diff --git a/src/main/frontend/handler/events.cljs b/src/main/frontend/handler/events.cljs index 0bb2d18f33..4f5421d697 100644 --- a/src/main/frontend/handler/events.cljs +++ b/src/main/frontend/handler/events.cljs @@ -611,6 +611,10 @@ template {:target page})))))) +(defmethod handle :editor/set-org-mode-heading [[_ block heading]] + (when-let [id (:block/uuid block)] + (editor-handler/set-heading! id :org heading))) + (defmethod handle :file-sync-graph/restore-file [[_ graph page-entity content]] (when (db/get-db graph) (let [file (:block/file page-entity)] diff --git a/src/main/frontend/handler/export.cljs b/src/main/frontend/handler/export.cljs index f3bd101f71..14aa177842 100644 --- a/src/main/frontend/handler/export.cljs +++ b/src/main/frontend/handler/export.cljs @@ -482,7 +482,6 @@ [:block/id :block/page-name :block/properties - :block/heading-level :block/format :block/children :block/content]))}) diff --git a/src/main/frontend/mobile/action_bar.cljs b/src/main/frontend/mobile/action_bar.cljs index e754fcaa58..ec3d540e45 100644 --- a/src/main/frontend/mobile/action_bar.cljs +++ b/src/main/frontend/mobile/action_bar.cljs @@ -52,13 +52,6 @@ (.scrollBy (util/app-scroll-container-node) #js {:top (- 10 delta)}))) [:div.action-bar [:div.action-bar-commands - (when-not (= (:block/format block) :org) - (action-command "heading" "Heading" - #(let [properties (:block/properties block) - heading? (true? (:heading properties))] - (if heading? - (editor-handler/remove-block-property! uuid :heading) - (editor-handler/set-block-property! uuid :heading true))))) (action-command "infinity" "Card" #(srs/make-block-a-card! (:block/uuid block))) (action-command "copy" "Copy" #(editor-handler/copy-selection-blocks false)) (action-command "cut" "Cut" #(editor-handler/cut-selection-blocks true)) diff --git a/src/main/frontend/modules/file/core.cljs b/src/main/frontend/modules/file/core.cljs index 04f285b562..ee07b8595e 100644 --- a/src/main/frontend/modules/file/core.cljs +++ b/src/main/frontend/modules/file/core.cljs @@ -29,13 +29,14 @@ content)) (defn transform-content - [{:block/keys [collapsed? format pre-block? unordered content heading-level left page parent]} level {:keys [heading-to-list?]}] - (let [content (or content "") + [{:block/keys [collapsed? format pre-block? unordered content left page parent properties]} level {:keys [heading-to-list?]}] + (let [heading (:heading properties) + markdown? (= :markdown format) + content (or content "") pre-block? (or pre-block? (and (= page parent left) ; first block - (= :markdown format) + markdown? (string/includes? (first (string/split-lines content)) ":: "))) - markdown? (= format :markdown) content (cond pre-block? (let [content (string/trim content)] @@ -45,7 +46,7 @@ (let [markdown-top-heading? (and markdown? (= parent page) (not unordered) - heading-level) + heading) [prefix spaces-tabs] (cond (= format :org) @@ -57,10 +58,10 @@ ["" ""] :else - (let [level (if (and heading-to-list? heading-level) - (if (> heading-level 1) - (dec heading-level) - heading-level) + (let [level (if (and heading-to-list? heading) + (if (> heading 1) + (dec heading) + heading) level) spaces-tabs (->> (repeat (dec level) (state/get-export-bullet-indentation)) diff --git a/src/main/frontend/ui.css b/src/main/frontend/ui.css index 0ac13b1e62..d86ee00fbc 100644 --- a/src/main/frontend/ui.css +++ b/src/main/frontend/ui.css @@ -245,7 +245,7 @@ html.is-mobile { .ui__button { @apply flex items-center px-3 py-2 border border-transparent text-sm leading-4 font-medium rounded-md text-white - focus:outline-none transition ease-in-out duration-150 mt-1; + focus:outline-none transition ease-in-out duration-150; &:disabled { opacity: 0.5; @@ -355,4 +355,4 @@ html.is-mobile { .ui__icon { display: inline-block; -} \ No newline at end of file +} From a27a270b04f3466e36bea36391ce263ba9d6c469 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Thu, 22 Sep 2022 22:09:37 +0800 Subject: [PATCH 04/10] fix: CI --- .../src/logseq/graph_parser/test/docs_graph_helper.cljs | 5 +++-- src/main/frontend/handler/editor.cljs | 1 - 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/deps/graph-parser/src/logseq/graph_parser/test/docs_graph_helper.cljs b/deps/graph-parser/src/logseq/graph_parser/test/docs_graph_helper.cljs index 400d7c30f9..9474895bbb 100644 --- a/deps/graph-parser/src/logseq/graph_parser/test/docs_graph_helper.cljs +++ b/deps/graph-parser/src/logseq/graph_parser/test/docs_graph_helper.cljs @@ -100,7 +100,8 @@ :updated-at 47 :created-at 47 :card-last-score 6 :card-repeats 6 :card-next-schedule 6 :card-last-interval 6 :card-ease-factor 6 :card-last-reviewed 6 - :alias 6 :logseq.macro-arguments 94 :logseq.macro-name 94} + :alias 6 :logseq.macro-arguments 94 :logseq.macro-name 94 + :heading 64} (get-top-block-properties db)) "Counts for top block properties") @@ -141,7 +142,7 @@ ;; only increase over time as the docs graph rarely has deletions (testing "Counts" (is (= 211 (count files)) "Correct file count") - (is (= 42070 (count (d/datoms db :eavt))) "Correct datoms count") + (is (= 42006 (count (d/datoms db :eavt))) "Correct datoms count") (is (= 3600 (ffirst diff --git a/src/main/frontend/handler/editor.cljs b/src/main/frontend/handler/editor.cljs index 41db7f783a..8ed1bda0ed 100644 --- a/src/main/frontend/handler/editor.cljs +++ b/src/main/frontend/handler/editor.cljs @@ -1940,7 +1940,6 @@ (property/insert-properties format content props)) ast (mldoc/->edn content* (gp-mldoc/default-config format)) blocks (block/extract-blocks ast content* format {}) - _ (prn {:block (first blocks)}) fst-block (first blocks) fst-block (if (and keep-uuid? (uuid? (:uuid block))) (assoc fst-block :block/uuid (:uuid block)) From 086bae51565cabf1e3cfcb137fe138a32739187d Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Fri, 23 Sep 2022 01:07:10 +0800 Subject: [PATCH 05/10] fix: use parsed level as heading level instead of default 2 --- deps/graph-parser/src/logseq/graph_parser/block.cljs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/deps/graph-parser/src/logseq/graph_parser/block.cljs b/deps/graph-parser/src/logseq/graph_parser/block.cljs index accc1cd106..2ac306a6a1 100644 --- a/deps/graph-parser/src/logseq/graph_parser/block.cljs +++ b/deps/graph-parser/src/logseq/graph_parser/block.cljs @@ -542,13 +542,12 @@ (with-path-refs blocks))) (defn- with-heading-property - [properties markdown-heading? size] + [properties markdown-heading? size level] (let [properties (if markdown-heading? (assoc properties :heading size) properties)] (if (true? (:heading properties)) - ;; default-level 2 - (assoc properties :heading 2) + (assoc properties :heading (min 6 level)) properties))) (defn- construct-block @@ -571,7 +570,7 @@ :meta pos-meta) (dissoc :size)) (or (seq (:properties properties)) markdown-heading?) - (assoc :properties (with-heading-property (:properties properties) markdown-heading? (:size block)) + (assoc :properties (with-heading-property (:properties properties) markdown-heading? (:size block) (:level block)) :properties-text-values (:properties-text-values properties) :properties-order (vec (:properties-order properties))) From 39a7ffb78900bc9b68805c68b72f6d7c3661c957 Mon Sep 17 00:00:00 2001 From: Konstantinos Kaloutas Date: Fri, 23 Sep 2022 11:52:55 +0300 Subject: [PATCH 06/10] chore: add translation --- src/main/frontend/dicts.cljc | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/frontend/dicts.cljc b/src/main/frontend/dicts.cljc index 03dac28dfd..743d1ca5ba 100644 --- a/src/main/frontend/dicts.cljc +++ b/src/main/frontend/dicts.cljc @@ -283,6 +283,7 @@ :white "Light" :dark "Dark" :remove-background "Remove background" + :remove-heading "Remove heading" :open "Open" :open-a-directory "Open a local directory" :user/delete-account "Delete account" From 68c876b1f921db9d51b0341a63474afb47181e10 Mon Sep 17 00:00:00 2001 From: Konstantinos Kaloutas Date: Fri, 23 Sep 2022 11:53:22 +0300 Subject: [PATCH 07/10] fix: spacings and remove heading button --- src/main/frontend/components/content.cljs | 32 ++++++++++++----------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/main/frontend/components/content.cljs b/src/main/frontend/components/content.cljs index 64a9e99484..9006095b53 100644 --- a/src/main/frontend/components/content.cljs +++ b/src/main/frontend/components/content.cljs @@ -170,27 +170,29 @@ [:a.m-2.shadow-sm {:on-click (fn [_e] (editor-handler/set-block-property! block-id "background-color" color))} - [:div.heading-bg {:style {:background-color color}}]])] - [:a.m-2.shadow-sm - {:title (t :remove-background) - :on-click (fn [_e] - (editor-handler/remove-block-property! block-id "background-color"))} - [:div.heading-bg.remove "-"]]] + [:div.heading-bg {:style {:background-color color}}]]) + [:a.m-2.shadow-sm + {:title (t :remove-background) + :on-click (fn [_e] + (editor-handler/remove-block-property! block-id "background-color"))} + [:div.heading-bg.remove "-"]]]] [:div.flex.flex-row.justify-between.pb-2.pt-1.px-2.items-center [:div.flex.flex-row.justify-between.flex-1 (for [i (range 1 7)] (ui/button - (str "H" i) - :on-click (fn [_e] - (editor-handler/set-heading! block-id format i)) - :intent "link" - :small? true))] - [:a.m-2 - {:title (t :remove-heading) + (str "H" i) + :on-click (fn [_e] + (editor-handler/set-heading! block-id format i)) + :intent "link" + :small? true)) + (ui/button + "H-" + :title (t :remove-heading) :on-click (fn [_e] - (editor-handler/remove-heading! block-id format))} - [:div.heading-bg.remove "-"]]] + (editor-handler/remove-heading! block-id format)) + :intent "link" + :small? true)]] [:hr.menu-separator] From 8677c74fa31d8134d39d1b6908353966445e6ec0 Mon Sep 17 00:00:00 2001 From: Kan-Ru Chen Date: Tue, 27 Sep 2022 17:14:56 +0900 Subject: [PATCH 08/10] chore(deps): update rage-wasm to 0.3.0 (#6808) Co-authored-by: Tienson Qin --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index a1953f915c..c889dc8a85 100644 --- a/package.json +++ b/package.json @@ -82,7 +82,7 @@ "@capacitor/splash-screen": "^4.0.0", "@capacitor/status-bar": "^4.0.0", "@excalidraw/excalidraw": "0.10.0", - "@kanru/rage-wasm": "0.2.1", + "@kanru/rage-wasm": "^0.3.0", "@logseq/capacitor-file-sync": "0.0.10", "@logseq/react-tweet-embed": "1.3.1-1", "@sentry/react": "^6.18.2", diff --git a/yarn.lock b/yarn.lock index a9c659ef48..c815466bd8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -475,10 +475,10 @@ "@jridgewell/resolve-uri" "^3.0.3" "@jridgewell/sourcemap-codec" "^1.4.10" -"@kanru/rage-wasm@0.2.1": - version "0.2.1" - resolved "https://registry.yarnpkg.com/@kanru/rage-wasm/-/rage-wasm-0.2.1.tgz#dd8fdd3133992c42bf68c0086d8cad40a13bc329" - integrity sha512-sYi4F2mL6Mpcz7zbS4myasw11xLBEbgZkDMRVg9jNxTKt6Ct/LT7/vCHDmEzAFcPcPqixD5De6Ql3bJijAX0/w== +"@kanru/rage-wasm@^0.3.0": + version "0.3.0" + resolved "https://registry.yarnpkg.com/@kanru/rage-wasm/-/rage-wasm-0.3.0.tgz#de96b1fda1f781ff401d43b50d0f95b7338c4399" + integrity sha512-2LMRS27nNJPqFNpRQL7kXG0kgBeIPo63KM6u0Xu6Es5XIS7LP4MFtdHkCg8Pt7IhMM7GuOa2YnzAZgKBxE1lcw== "@logseq/capacitor-file-sync@0.0.10": version "0.0.10" From c10b04b7156debfbdfc3337b29b10ddfd801e7f4 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Tue, 27 Sep 2022 23:24:42 +0800 Subject: [PATCH 09/10] fix: clear sync-state when stopping the current graph's sync --- src/main/frontend/fs/sync.cljs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/frontend/fs/sync.cljs b/src/main/frontend/fs/sync.cljs index 5f4f985b6d..6d7d46cb6c 100644 --- a/src/main/frontend/fs/sync.cljs +++ b/src/main/frontend/fs/sync.cljs @@ -2851,10 +2851,11 @@ (when-let [sm ^SyncManager (state/get-file-sync-manager)] (println "[SyncManager" (:graph-uuid sm) "]" "stopping") ( Date: Tue, 27 Sep 2022 23:54:33 +0800 Subject: [PATCH 10/10] fix: don't create a space between # and [[]] when auto-complete --- src/main/frontend/commands.cljs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/frontend/commands.cljs b/src/main/frontend/commands.cljs index 40d7b4f30b..9571398231 100644 --- a/src/main/frontend/commands.cljs +++ b/src/main/frontend/commands.cljs @@ -344,6 +344,7 @@ (or (string/starts-with? last-pattern block-ref/left-parens) (string/starts-with? last-pattern page-ref/left-brackets))) (and s (string/starts-with? s "{{embed")) + (and s (= (last s) \#) (string/starts-with? last-pattern "[[")) (and last-pattern (or (string/ends-with? last-pattern gp-property/colons) (string/starts-with? last-pattern gp-property/colons)))))))]