diff --git a/.clj-kondo/config.edn b/.clj-kondo/config.edn index f228418b90..484a9364d1 100644 --- a/.clj-kondo/config.edn +++ b/.clj-kondo/config.edn @@ -6,7 +6,8 @@ ;; TODO:lint: Remove node-path excludes once we have a cleaner api :unresolved-var {:exclude [frontend.util/node-path.basename frontend.util/node-path.dirname - frontend.util/node-path.join]}} + frontend.util/node-path.join + frontend.util/node-path.name]}} :hooks {:analyze-call {rum.core/defc hooks.rum/defc rum.core/defcs hooks.rum/defcs}} diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 450bb7e2ab..0f5ed3493c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -71,7 +71,7 @@ jobs: version: ${{ env.CLJ_KONDO_VERSION }} - name: Run clj-kondo lint - run: clj-kondo --lint src/workspaces src/electron src/test src/dev-cljs src/main/{electron,grammar,logseq} src/main/frontend/{worker,util,ui,tools,search,publishing,modules,mobile,fs,format,external,extensions,db,context,components} + run: clj-kondo --lint src - name: Fetch yarn deps run: yarn install diff --git a/src/main/frontend/commands.cljs b/src/main/frontend/commands.cljs index 67ad117c1e..e516933400 100644 --- a/src/main/frontend/commands.cljs +++ b/src/main/frontend/commands.cljs @@ -292,7 +292,7 @@ (p/let [_ (draw/create-draw-with-default-content path)] (println "draw file created, " path)) text)) "Draw a graph with Excalidraw"]) - + (when (util/zh-CN-supported?) ["Embed Bilibili video" [[:editor/input "{{bilibili }}" {:last-pattern (state/get-editor-command-trigger) :backward-pos 2}]]]) @@ -612,8 +612,7 @@ (defmethod handle-step :editor/move-cursor-to-properties [[_]] (when-let [input-id (state/get-edit-input-id)] (when-let [current-input (gdom/getElement input-id)] - (let [format (or (db/get-page-format (state/get-current-page)) (state/get-preferred-format)) - edit-content (gobj/get current-input "value")] + (let [format (or (db/get-page-format (state/get-current-page)) (state/get-preferred-format))] (property/goto-properties-end format current-input) (cursor/move-cursor-backward current-input 3))))) diff --git a/src/main/frontend/config.cljs b/src/main/frontend/config.cljs index 561aa56f04..f833837286 100644 --- a/src/main/frontend/config.cljs +++ b/src/main/frontend/config.cljs @@ -186,11 +186,11 @@ ""))) (defn get-subscript - [format] + [_format] "_") (defn get-superscript - [format] + [_format] "^") (defn get-empty-link-and-forward-pos diff --git a/src/main/frontend/date.cljs b/src/main/frontend/date.cljs index e52cdcf9ff..9b8490e618 100644 --- a/src/main/frontend/date.cljs +++ b/src/main/frontend/date.cljs @@ -74,7 +74,7 @@ (->> (tf/parse (tf/formatters :date-time-no-ms) s) (t/to-default-time-zone) (tf/unparse (tf/formatter "MMM do, yyyy"))) - (catch js/Error e + (catch js/Error _e nil))) (defn ISO-string @@ -128,7 +128,7 @@ (defn journal-name-s [s] (try (journal-name (tf/parse (tf/formatter "yyyy-MM-dd") s)) - (catch js/Error e + (catch js/Error _e (log/info :parse-journal-date {:message "Unable to parse date to journal name, skipping." :date-str s}) nil))) diff --git a/src/main/frontend/db.cljs b/src/main/frontend/db.cljs index 5f4056dc6b..6965001a53 100644 --- a/src/main/frontend/db.cljs +++ b/src/main/frontend/db.cljs @@ -8,12 +8,12 @@ [frontend.db.query-custom] [frontend.db.query-react] [frontend.db.react] + [frontend.db.utils] [frontend.db.persist :as db-persist] [frontend.namespaces :refer [import-vars]] [frontend.state :as state] [frontend.util :as util] [promesa.core :as p] - [frontend.config :as config] [electron.ipc :as ipc])) (import-vars @@ -90,10 +90,9 @@ (fn [] (if (and (state/input-idle? repo) (state/db-idle? repo)) - (do - (persist! repo) - ;; (state/set-db-persisted! repo true) -) + (persist! repo) + ;; (state/set-db-persisted! repo true) + (persist-if-idle! repo))) 3000)] (swap! persistent-jobs assoc repo job))) @@ -112,7 +111,7 @@ (p/let [graph-has-other-window? (ipc/ipc "graphHasOtherWindow" repo)] (when graph-has-other-window? (ipc/ipc "dbsync" repo {:data (db->string (:tx-data tx-report))})))) - (let [tx-id (get-tx-id tx-report)] + (do (state/set-last-transact-time! repo (util/time-ms)) (persist-if-idle! repo))) @@ -139,7 +138,7 @@ :listen-handler listen-and-persist!)))) (defn restore! - [{:keys [repos] :as me} old-db-schema restore-config-handler] + [{:keys [repos] :as me} _old-db-schema restore-config-handler] (let [logged? (:name me)] (doall (for [{:keys [url]} repos] diff --git a/src/main/frontend/debug.cljs b/src/main/frontend/debug.cljs index 24e29ce313..b36d689168 100644 --- a/src/main/frontend/debug.cljs +++ b/src/main/frontend/debug.cljs @@ -3,8 +3,7 @@ (:refer-clojure :exclude [print]) (:require [cljs.pprint :as pprint] [frontend.state :as state] - [frontend.util :as util] - [frontend.handler.notification :as notification])) + [frontend.util :as util])) (defn pprint [& xs] @@ -23,7 +22,7 @@ ;; For debugging file changes are not saved on disk. (defn wait-for-write-ack! - [page-title file-path] + [_page-title file-path] (when file-path (let [requested-at (util/time-ms)] (state/set-state! [:debug/write-acks file-path :last-requested-at] requested-at) diff --git a/src/main/frontend/diff.cljs b/src/main/frontend/diff.cljs index f6a29b24c7..1897b7c603 100644 --- a/src/main/frontend/diff.cljs +++ b/src/main/frontend/diff.cljs @@ -67,9 +67,9 @@ (recur r1 t2 (inc i1) i2)))) current-line (text/get-current-line-by-pos markup pos)] (cond - (and (= (util/nth-safe markup pos) - (util/nth-safe markup (inc pos)) - "]")) + (= (util/nth-safe markup pos) + (util/nth-safe markup (inc pos)) + "]") (+ pos 2) (contains? inline-special-chars (util/nth-safe markup pos)) diff --git a/src/main/frontend/external.cljc b/src/main/frontend/external.cljc index 0c8523d9b0..1a0d25c363 100644 --- a/src/main/frontend/external.cljc +++ b/src/main/frontend/external.cljc @@ -1,4 +1,6 @@ (ns frontend.external + ;; Wonky cljs detection + #_:clj-kondo/ignore (:require [frontend.external.roam :refer [->Roam]] [frontend.external.protocol :as protocol])) diff --git a/src/main/frontend/fs.cljs b/src/main/frontend/fs.cljs index a994f2e5db..d79662dfaa 100644 --- a/src/main/frontend/fs.cljs +++ b/src/main/frontend/fs.cljs @@ -163,7 +163,7 @@ (util/p-handle (stat dir nil) (fn [_stat]) - (fn [error] + (fn [_error] (mkdir! dir)))) (p/catch (fn [error] (js/console.error error))))) @@ -176,7 +176,7 @@ path (str "/" path)))] (-> - (p/let [stat (stat dir path)] + (p/let [_stat (stat dir path)] true) (p/catch (fn [_error] diff --git a/src/main/frontend/git.cljs b/src/main/frontend/git.cljs index 6b26d7bda5..2ec6520d50 100644 --- a/src/main/frontend/git.cljs +++ b/src/main/frontend/git.cljs @@ -14,6 +14,7 @@ (get-in @state/state [:me :name])) (defn get-cors-proxy + #_:clj-kondo/ignore [repo-url] (or (when-not (string/blank? (:cors_proxy (state/get-me))) diff --git a/src/main/frontend/github.cljs b/src/main/frontend/github.cljs index 86d4fb7f02..cbe3d5f161 100644 --- a/src/main/frontend/github.cljs +++ b/src/main/frontend/github.cljs @@ -46,5 +46,5 @@ :Content-Type "application/json" :Authorization token}}) (fn [result] (true-handler result)) - (fn [error] + (fn [_error] (false-handler))))) diff --git a/src/main/frontend/handler.cljs b/src/main/frontend/handler.cljs index 120d81e325..8191f9f817 100644 --- a/src/main/frontend/handler.cljs +++ b/src/main/frontend/handler.cljs @@ -37,7 +37,7 @@ (defn set-global-error-notification! [] (set! js/window.onerror - (fn [message, source, lineno, colno, error] + (fn [message, _source, _lineno, _colno, error] (when-not (error/ignored? message) (js/console.error error) ;; (notification/show! @@ -49,8 +49,8 @@ (defn- watch-for-date! [] - (let [cards-last-check-time (atom (util/time-ms)) - f (fn [] + (let [f (fn [] + #_:clj-kondo/ignore (let [repo (state/get-current-repo)] (when-not (state/nfs-refreshing?) ;; Don't create the journal file until user writes something @@ -135,10 +135,10 @@ ;; (state/pub-event! [:after-db-restore repos])) )) (p/catch (fn [error] - (log/error :db/restore-failed error))))))] + (log/error :db/restore-failed error)))))) + interval-id (js/setInterval inner-fn 50)] ;; clear this interval - (let [interval-id (js/setInterval inner-fn 50)] - (reset! interval interval-id)))) + (reset! interval interval-id))) (defn- handle-connection-change [e] @@ -213,7 +213,7 @@ [render] (set-global-error-notification!) (let [db-schema (storage/get :db-schema) - {:keys [me logged? repos]} (get-me-and-repos)] + {:keys [me logged?]} (get-me-and-repos)] (when me (state/set-state! :me me)) (register-components-fns!) (state/set-db-restoring! true) diff --git a/src/main/frontend/handler/common.cljs b/src/main/frontend/handler/common.cljs index 258f4ca542..132558abbe 100644 --- a/src/main/frontend/handler/common.cljs +++ b/src/main/frontend/handler/common.cljs @@ -140,7 +140,7 @@ config))) (defn read-metadata! - [repo-url content] + [content] (try (reader/read-string content) (catch js/Error e @@ -213,7 +213,7 @@ (defn fix-pages-timestamps [pages] - (map (fn [{:block/keys [name created-at updated-at journal-day] :as p}] + (map (fn [{:block/keys [created-at updated-at journal-day] :as p}] (cond-> p diff --git a/src/main/frontend/handler/editor.cljs b/src/main/frontend/handler/editor.cljs index cf62cdf877..1e270c5237 100644 --- a/src/main/frontend/handler/editor.cljs +++ b/src/main/frontend/handler/editor.cljs @@ -30,6 +30,7 @@ [frontend.handler.route :as route-handler] [frontend.handler.ui :as ui-handler] [frontend.image :as image] + [frontend.idb :as idb] [frontend.mobile.util :as mobile] [frontend.modules.outliner.core :as outliner-core] [frontend.modules.outliner.datascript :as ds] @@ -79,7 +80,7 @@ :input input}))))) (defn- format-new-selection - [{:keys [selection-start selection-end format value edit-id input]}] + [{:keys [selection-start selection-end value]}] (let [selected (subs value selection-start selection-end)] [(+ selection-start (count (take-while #(= " " %) selected))) (- selection-end (count (take-while #(= " " %) (reverse selected))))])) @@ -87,7 +88,7 @@ (defn- format-text! [pattern-fn] (when-let [m (get-selection-and-format)] - (let [{:keys [selection-start selection-end format value edit-id input]} m + (let [{:keys [format value edit-id input]} m [selection-start selection-end] (format-new-selection m) empty-selection? (= selection-start selection-end) pattern (pattern-fn format) @@ -548,7 +549,6 @@ (defn insert-new-block-before-block-aux! [config {:block/keys [repo] - db-id :db/id :as block} value {:keys [ok-handler] @@ -567,18 +567,16 @@ (wrap-parse-block)) left-block (db/pull (:db/id (:block/left block))) _ (outliner-core/save-node (outliner-core/block current-block)) - sibling? (not= (:db/id left-block) (:db/id (:block/parent block))) - {:keys [sibling? blocks]} (profile - "outliner insert block" - (outliner-insert-block! config left-block prev-block sibling?))] - + sibling? (not= (:db/id left-block) (:db/id (:block/parent block)))] + (profile + "outliner insert block" + (outliner-insert-block! config left-block prev-block sibling?)) (db/refresh! repo {:key :block/insert :data [prev-block left-block current-block]}) (profile "ok handler" (ok-handler prev-block)))) (defn insert-new-block-aux! [config {:block/keys [uuid repo] - db-id :db/id :as block} value {:keys [ok-handler] @@ -650,7 +648,7 @@ (defn insert-new-block! ([state] (insert-new-block! state nil)) - ([state block-value] + ([_state block-value] (when (and (not config/publishing?) (not= :insert (state/get-editor-op))) (state/set-editor-op! :insert) @@ -894,6 +892,7 @@ (defn cycle-todo! [] + #_:clj-kondo/ignore (if-let [blocks (seq (get-selected-blocks-with-children))] (cycle-todos!) (when (state/get-edit-block) @@ -1041,6 +1040,7 @@ (defn- batch-set-block-property! "col: a collection of [block-id property-key property-value]." [col] + #_:clj-kondo/ignore (when-let [repo (state/get-current-repo)] (ds/auto-transact! [txs-state (ds/new-outliner-txs-state)] @@ -1069,8 +1069,8 @@ block-id (if (string? block-id) (uuid block-id) block-id) input-pos (or (state/get-edit-pos) :max)] (db/refresh! (state/get-current-repo) - {:key :block/change - :data [(db/pull [:block/uuid block-id])]}) + {:key :block/change + :data [(db/pull [:block/uuid block-id])]}) ;; update editing input content (when-let [editing-block (state/get-edit-block)] (when (= (:block/uuid editing-block) block-id) @@ -1234,7 +1234,7 @@ adjusted-blocks (map-indexed (fn [index {:keys [id level]}] {:id id - :level (if (and (< index first-root-level-index)) + :level (if (< index first-root-level-index) (if (< level @root-level) (do (reset! root-level level) @@ -1405,7 +1405,6 @@ [block-id] (when-let [block (db/pull [:block/uuid block-id])] (let [repo (state/get-current-repo) - content (:block/content block) ;; TODO: support org mode [md-content _tree] (compose-copied-blocks-contents-&-block-tree repo [block-id])] (common-handler/copy-to-clipboard-without-id-property! (:block/format block) md-content) @@ -1578,7 +1577,7 @@ (fn [] [repo-dir assets-dir])))) (defn save-assets! - ([{block-id :block/uuid} repo files] + ([_ repo files] (p/let [[repo-dir assets-dir] (ensure-assets-dir! repo)] (save-assets! repo repo-dir assets-dir files (fn [index file-base] @@ -1633,7 +1632,7 @@ cached-url (get @*assets-url-cache (keyword handle-path))] (if cached-url (p/resolved cached-url) - (p/let [handle (frontend.idb/get-item handle-path) + (p/let [handle (idb/get-item handle-path) file (and handle (.getFile handle))] (when file (p/let [url (js/URL.createObjectURL file)] @@ -1749,9 +1748,7 @@ (keys delete-map))) (defn autopair - [input-id prefix format {:keys [restore?] - :or {restore? true} - :as _option}] + [input-id prefix _format _option] (let [value (get autopair-map prefix) selected (util/get-selected-text) postfix (str selected value) @@ -2095,7 +2092,7 @@ ;; TODO: is it cross-browser compatible? ;; (not= (gobj/get native-e "inputType") "insertFromPaste") - (if (= last-input-char (state/get-editor-command-trigger)) + (when (= last-input-char (state/get-editor-command-trigger)) (when (seq (get-matched-commands input)) (reset! commands/*slash-caret-pos (cursor/get-caret-pos input)) (reset! commands/*show-commands true))) @@ -2107,7 +2104,7 @@ nil))) (defn block-on-chosen-handler - [input id q format] + [_input id q format] (fn [chosen _click?] (state/set-editor-show-block-search! false) (let [uuid-string (str (:block/uuid chosen))] @@ -2451,7 +2448,7 @@ (insert "\n"))))))) (defn- dwim-in-list - [state] + [_state] (when-not (auto-complete?) (let [{:keys [block]} (get-state)] (when block @@ -2503,6 +2500,7 @@ index-of-current-item (inc (.indexOf items-without-bullet (last (string/split (:raw-content item) splitter-reg 2)))) numbers-length (->> (map-indexed + #_:clj-kondo/ignore #(str (inc %1) ". ") (subvec items-without-bullet 0 index-of-current-item)) string/join @@ -2542,7 +2540,7 @@ (let [selection (get-selection-and-format) {:keys [selection-start selection-end value]} selection] (if (not= selection-start selection-end) - (do (delete-and-update selection-start selection-end) + (do (delete-and-update input selection-start selection-end) (insert (util/format "[[%s]]" value))) (if-let [embed-ref (thingatpt/embed-macro-at-point input)] (let [{:keys [raw-content start end]} embed-ref] @@ -2551,7 +2549,7 @@ (page-ref-fn "[[]]" 2) (insert raw-content))) (if-let [page-ref (thingatpt/page-ref-at-point input)] - (let [{:keys [start end link full-content raw-content]} page-ref] + (let [{:keys [start end full-content raw-content]} page-ref] (delete-and-update input start end) (if (= raw-content "") (page-ref-fn "{{embed [[]]}}" 4) @@ -2800,7 +2798,7 @@ (cursor/move-cursor-to input current-pos))))) (defn keydown-delete-handler - [e] + [_e] (let [^js input (state/get-input) current-pos (cursor/pos input) value (gobj/get input "value") @@ -2938,7 +2936,7 @@ (defn keydown-not-matched-handler [format] - (fn [e key-code] + (fn [e _key-code] (let [input-id (state/get-edit-input-id) input (state/get-input) key (gobj/get e "key") @@ -2946,8 +2944,6 @@ ctrlKey (gobj/get e "ctrlKey") metaKey (gobj/get e "metaKey") pos (cursor/pos input) - shift? (.-shiftKey e) - code (gobj/getValueByKeys e "event_" "code") hashtag? (or (surround-by? input "#" " ") (surround-by? input "#" :end) (= key "#"))] @@ -3025,7 +3021,7 @@ nil)))) (defn keyup-handler - [state input input-id search-timeout] + [_state input input-id search-timeout] (fn [e key-code] (when-not (util/event-is-composing? e) (let [k (gobj/get e "key") @@ -3036,7 +3032,6 @@ c (util/nth-safe value (dec current-pos)) last-key-code (state/get-last-key-code) blank-selected? (string/blank? (util/get-selected-text)) - shift? (.-shiftKey e) is-processed? (util/event-is-composing? e true) ;; #3440 non-enter-processed? (and is-processed? ;; #3251 (not= code keycode/enter-code))] ;; #3459 @@ -3152,11 +3147,6 @@ timeout))) (edit-box-on-change! e block id)))) -(defn- get-current-page-format - [] - (when-let [page (state/get-current-page)] - (db/get-page-format page))) - (defn blocks->tree-by-level [blocks] (let [min-level (apply min (mapv :block/level blocks)) diff --git a/src/main/frontend/handler/editor/keyboards.cljs b/src/main/frontend/handler/editor/keyboards.cljs index ebfa2ad454..fcec3c8473 100644 --- a/src/main/frontend/handler/editor/keyboards.cljs +++ b/src/main/frontend/handler/editor/keyboards.cljs @@ -12,11 +12,11 @@ (mixins/hide-when-esc-or-outside state :on-hide - (fn [state e event] + (fn [_state e event] (let [target (.-target e)] (if (d/has-class? target "bottom-action") ;; FIXME: not particular case (.preventDefault e) - (let [{:keys [on-hide format value block id repo]} (editor-handler/get-state)] + (let [{:keys [on-hide value]} (editor-handler/get-state)] (when on-hide (on-hide value event)) (when (contains? #{:esc :visibilitychange :click} event) diff --git a/src/main/frontend/handler/editor/lifecycle.cljs b/src/main/frontend/handler/editor/lifecycle.cljs index 8e8a6b970d..b0b216af87 100644 --- a/src/main/frontend/handler/editor/lifecycle.cljs +++ b/src/main/frontend/handler/editor/lifecycle.cljs @@ -8,7 +8,7 @@ (defn did-mount! [state] - (let [[{:keys [format block-parent-id]} id] (:rum/args state) + (let [[{:keys [block-parent-id]} id] (:rum/args state) content (get-in @state/state [:editor/content id])] (when block-parent-id (state/set-editing-block-dom-id! block-parent-id)) @@ -33,8 +33,7 @@ (defn will-unmount [state] - (let [{:keys [id value format block repo config]} (get-state) - file? (:file? config)] + (let [{:keys [value]} (get-state)] (editor-handler/clear-when-saved!) ;; TODO: ugly (when-not (contains? #{:insert :indent-outdent :auto-save :undo :redo :delete} (state/get-editor-op)) diff --git a/src/main/frontend/handler/events.cljs b/src/main/frontend/handler/events.cljs index 559cc4b3bb..c9148efcb0 100644 --- a/src/main/frontend/handler/events.cljs +++ b/src/main/frontend/handler/events.cljs @@ -29,7 +29,6 @@ [frontend.util :as util] [rum.core :as rum] ["semver" :as semver] - [clojure.string :as string] [frontend.modules.instrumentation.posthog :as posthog] [frontend.mobile.util :as mobile-util] [frontend.encrypt :as encrypt] @@ -71,12 +70,13 @@ close-fn))) (defmethod handle :graph/added [[_ repo]] - ;; add ast/version to db - (let [conn (conn/get-conn repo false) - ast-version (d/datoms @conn :aevt :ast/version)] + ;; TODO: add ast/version to db + (let [_conn (conn/get-conn repo false) + ; ast-version (d/datoms @conn :aevt :ast/version) + ] (db/set-key-value repo :ast/version db-schema/ast-version))) -(defmethod handle :graph/migrated [[_ repo]] +(defmethod handle :graph/migrated [[_ _repo]] (js/alert "Graph migrated.")) (defn get-local-repo @@ -111,7 +111,7 @@ {:will-unmount (fn [state] (reset! *query-properties {}) state)} - [block shown-properties all-properties close-fn] + [block shown-properties all-properties _close-fn] (let [query-properties (rum/react *query-properties)] [:div.p-4 [:div.font-bold "Properties settings for this query:"] @@ -160,13 +160,13 @@ (defmethod handle :modal/show [[_ content]] (state/set-modal! #(modal-output content))) -(defmethod handle :modal/set-git-username-and-email [[_ content]] +(defmethod handle :modal/set-git-username-and-email [[_ _content]] (state/set-modal! git-component/set-git-username-and-email)) (defmethod handle :page/title-property-changed [[_ old-title new-title]] (page-handler/rename! old-title new-title)) -(defmethod handle :page/create-today-journal [[_ repo]] +(defmethod handle :page/create-today-journal [[_ _repo]] (p/let [_ (page-handler/create-today-journal!)] (ui-handler/re-render-root!))) @@ -221,7 +221,7 @@ (defmethod handle :instrument [[_ {:keys [type payload]}]] (posthog/capture type payload)) -(defmethod handle :exec-plugin-cmd [[_ {:keys [type key pid cmd action]}]] +(defmethod handle :exec-plugin-cmd [[_ {:keys [pid cmd action]}]] (commands/exec-plugin-simple-command! pid cmd action)) (defmethod handle :shortcut-handler-refreshed [[_]] diff --git a/src/main/frontend/handler/export.cljs b/src/main/frontend/handler/export.cljs index 74cef06d44..4395b4e2d5 100644 --- a/src/main/frontend/handler/export.cljs +++ b/src/main/frontend/handler/export.cljs @@ -26,12 +26,6 @@ (outliner-tree/blocks->vec-tree (db/get-page-blocks-no-cache repo page) page) {:init-level 1})) -(defn- get-page-content-debug - [repo page] - (outliner-file/tree->file-content - (outliner-tree/blocks->vec-tree - (db/get-page-blocks-no-cache repo page) page) {:init-level 1 - :heading-to-list? true})) (defn- get-file-content [repo file-path] (if-let [page-name @@ -81,12 +75,12 @@ (when-let [repo (state/get-current-repo)] (when-let [content (get-file-content repo file-path)] (let [data (js/Blob. ["\ufeff" (array content)] ; prepend BOM - (clj->js {:type "text/plain;charset=utf-8,"}))] - (let [anchor (gdom/getElement "download") - url (js/window.URL.createObjectURL data)] - (.setAttribute anchor "href" url) - (.setAttribute anchor "download" file-path) - (.click anchor)))))) + (clj->js {:type "text/plain;charset=utf-8,"})) + anchor (gdom/getElement "download") + url (js/window.URL.createObjectURL data)] + (.setAttribute anchor "href" url) + (.setAttribute anchor "download" file-path) + (.click anchor))))) (defn export-repo-as-html! [repo] @@ -163,6 +157,7 @@ (defn get-md-file-contents [repo] + #_:clj-kondo/ignore (let [conn (db/get-conn repo)] (filter (fn [[path _]] (let [path (string/lower-case path)] @@ -397,7 +392,7 @@ (js/JSON.stringify (clj->js %3))))) (defn- convert-md-files-unordered-list-or-heading - [repo files heading-to-list?] + [files heading-to-list?] (->> files (mapv (fn [{:keys [path content names format]}] (when (first names) @@ -443,28 +438,29 @@ (when-let [content (get-page-content repo page-name)] (let [names [page-name] format (f/get-format path) - files [{:path path :content content :names names :format format}]] - (let [files - (export-files-as-markdown repo files (state/export-heading-to-list?))] - (let [data (js/Blob. [(second (first files))] - (clj->js {:type "text/plain;charset=utf-8,"}))] - (let [anchor (gdom/getElement "export-page-as-markdown") - url (js/window.URL.createObjectURL data)] - (.setAttribute anchor "href" url) - (.setAttribute anchor "download" path) - (.click anchor)))))))))) + files [{:path path :content content :names names :format format}] + files + (export-files-as-markdown repo files (state/export-heading-to-list?)) + data (js/Blob. [(second (first files))] + (clj->js {:type "text/plain;charset=utf-8,"})) + anchor (gdom/getElement "export-page-as-markdown") + url (js/window.URL.createObjectURL data)] + (.setAttribute anchor "href" url) + (.setAttribute anchor "download" path) + (.click anchor))))))) (defn export-repo-as-opml! + #_:clj-kondo/ignore [repo] (when-let [repo (state/get-current-repo)] (when-let [files (get-file-contents-with-suffix repo)] (let [files (export-files-as-opml repo files) zip-file-name (str repo "_opml_" (quot (util/time-ms) 1000))] (p/let [zipfile (zip/make-zip zip-file-name files repo)] - (when-let [anchor (gdom/getElement "export-as-opml")] - (.setAttribute anchor "href" (js/window.URL.createObjectURL zipfile)) - (.setAttribute anchor "download" (.-name zipfile)) - (.click anchor))))))) + (when-let [anchor (gdom/getElement "export-as-opml")] + (.setAttribute anchor "href" (js/window.URL.createObjectURL zipfile)) + (.setAttribute anchor "download" (.-name zipfile)) + (.click anchor))))))) (defn export-page-as-opml! [page-name] @@ -474,16 +470,16 @@ (when-let [content (get-page-content repo page-name)] (let [names [page-name] format (f/get-format path) - files [{:path path :content content :names names :format format}]] - (let [files (export-files-as-opml repo files)] - (let [data (js/Blob. [(second (first files))] - (clj->js {:type "text/plain;charset=utf-8,"}))] - (let [anchor (gdom/getElement "export-page-as-opml") - url (js/window.URL.createObjectURL data) - opml-path (string/replace (string/lower-case path) #"(.+)\.(md|org|markdown)$" "$1.opml")] - (.setAttribute anchor "href" url) - (.setAttribute anchor "download" opml-path) - (.click anchor)))))))))) + files [{:path path :content content :names names :format format}] + files (export-files-as-opml repo files) + data (js/Blob. [(second (first files))] + (clj->js {:type "text/plain;charset=utf-8,"})) + anchor (gdom/getElement "export-page-as-opml") + url (js/window.URL.createObjectURL data) + opml-path (string/replace (string/lower-case path) #"(.+)\.(md|org|markdown)$" "$1.opml")] + (.setAttribute anchor "href" url) + (.setAttribute anchor "download" opml-path) + (.click anchor))))))) (defn convert-page-markdown-unordered-list-or-heading! [page-name] @@ -493,15 +489,15 @@ (when-let [content (get-page-content repo page-name)] (let [names [page-name] format (f/get-format path) - files [{:path path :content content :names names :format format}]] - (let [files (convert-md-files-unordered-list-or-heading repo files (state/export-heading-to-list?))] - (let [data (js/Blob. [(second (first files))] - (clj->js {:type "text/plain;charset=utf-8,"}))] - (let [anchor (gdom/getElement "convert-markdown-to-unordered-list-or-heading") - url (js/window.URL.createObjectURL data)] - (.setAttribute anchor "href" url) - (.setAttribute anchor "download" path) - (.click anchor)))))))))) + files [{:path path :content content :names names :format format}] + files (convert-md-files-unordered-list-or-heading files (state/export-heading-to-list?)) + data (js/Blob. [(second (first files))] + (clj->js {:type "text/plain;charset=utf-8,"})) + anchor (gdom/getElement "convert-markdown-to-unordered-list-or-heading") + url (js/window.URL.createObjectURL data)] + (.setAttribute anchor "href" url) + (.setAttribute anchor "download" path) + (.click anchor))))))) (defn- dissoc-properties [m ks] (if (:block/properties m) diff --git a/src/main/frontend/handler/external.cljs b/src/main/frontend/handler/external.cljs index 9cae9b1a6c..2a9d1f62d2 100644 --- a/src/main/frontend/handler/external.cljs +++ b/src/main/frontend/handler/external.cljs @@ -71,11 +71,12 @@ ;;; import OPML files (defn import-from-opml! [data finished-ok-handler] + #_:clj-kondo/ignore (when-let [repo (state/get-current-repo)] (let [[headers parsed-blocks] (mldoc/opml->edn data) parsed-blocks (->> - (block/extract-blocks parsed-blocks "" true :markdown) - (mapv editor/wrap-parse-block)) + (block/extract-blocks parsed-blocks "" true :markdown) + (mapv editor/wrap-parse-block)) page-name (:title headers)] (when (not (page/page-exists? page-name)) (page/create! page-name {:redirect? false})) diff --git a/src/main/frontend/handler/extract.cljs b/src/main/frontend/handler/extract.cljs index 40b5aece22..f2ca56d879 100644 --- a/src/main/frontend/handler/extract.cljs +++ b/src/main/frontend/handler/extract.cljs @@ -1,8 +1,6 @@ (ns frontend.handler.extract "Extract helper." - (:require [cljs-time.coerce :as tc] - [cljs-time.core :as t] - [clojure.set :as set] + (:require [clojure.set :as set] [clojure.string :as string] [clojure.walk :as walk] [frontend.config :as config] @@ -19,15 +17,6 @@ [promesa.core :as p] [frontend.mobile.util :as mobile])) -(defn- extract-page-list - [content] - (when-not (string/blank? content) - (->> (re-seq #"\[\[([^\]]+)]]" content) - (map last) - (remove nil?) - (map string/lower-case) - (distinct)))) - (defn get-page-name [file ast] ;; headline @@ -55,11 +44,11 @@ ;; TODO: performance improvement (defn- extract-pages-and-blocks - [repo-url format ast properties file content utf8-content journal?] + #_:clj-kondo/ignore + [repo-url format ast properties file content _utf8-content _journal?] (try - (let [now (tc/to-long (t/now)) - page (get-page-name file ast) - [original-page-name page-name journal-day] (block/convert-page-if-journal page) + (let [page (get-page-name file ast) + [_original-page-name page-name _journal-day] (block/convert-page-if-journal page) blocks (->> (block/extract-blocks ast content false format) (block/with-parent-and-left {:block/name page-name})) ref-pages (atom #{}) @@ -77,48 +66,48 @@ :block/page [:block/name page-name] :block/refs block-ref-pages :block/path-refs block-path-ref-pages)))) - blocks) + blocks) page-entity (let [alias (:alias properties) alias (if (string? alias) [alias] alias) aliases (and alias (seq (remove #(= page-name (util/page-name-sanity-lc %)) alias)))] (cond-> - (util/remove-nils - (assoc - (block/page-name->map page false) - :block/file {:file/path file})) - (seq properties) - (assoc :block/properties properties) + (util/remove-nils + (assoc + (block/page-name->map page false) + :block/file {:file/path file})) + (seq properties) + (assoc :block/properties properties) - aliases - (assoc :block/alias - (map - (fn [alias] - (let [page-name (util/page-name-sanity-lc alias) - aliases (distinct - (conj - (remove #{alias} aliases) - page)) - aliases (when (seq aliases) - (map - (fn [alias] - {:block/name (util/page-name-sanity-lc alias)}) - aliases))] - (if (seq aliases) - {:block/name page-name - :block/alias aliases} - {:block/name page-name}))) - aliases)) + aliases + (assoc :block/alias + (map + (fn [alias] + (let [page-name (util/page-name-sanity-lc alias) + aliases (distinct + (conj + (remove #{alias} aliases) + page)) + aliases (when (seq aliases) + (map + (fn [alias] + {:block/name (util/page-name-sanity-lc alias)}) + aliases))] + (if (seq aliases) + {:block/name page-name + :block/alias aliases} + {:block/name page-name}))) + aliases)) - (:tags properties) - (assoc :block/tags (let [tags (:tags properties) - tags (if (string? tags) [tags] tags) - tags (remove string/blank? tags)] - (swap! ref-tags set/union (set tags)) - (map (fn [tag] {:block/name (util/page-name-sanity-lc tag) + (:tags properties) + (assoc :block/tags (let [tags (:tags properties) + tags (if (string? tags) [tags] tags) + tags (remove string/blank? tags)] + (swap! ref-tags set/union (set tags)) + (map (fn [tag] {:block/name (util/page-name-sanity-lc tag) :block/original-name tag}) - tags))))) + tags))))) namespace-pages (let [page (:block/original-name page-entity)] (when (text/namespace-page? page) (->> (util/split-namespace-pages page) @@ -129,20 +118,15 @@ [page-entity] @ref-pages (map - (fn [page] - {:block/original-name page - :block/name (util/page-name-sanity-lc page)}) - @ref-tags) + (fn [page] + {:block/original-name page + :block/name (util/page-name-sanity-lc page)}) + @ref-tags) namespace-pages) ;; remove block references (remove vector?) (remove nil?)) pages (util/distinct-by :block/name pages) - block-ids (->> - (mapv (fn [block] - {:block/uuid (:block/uuid block)}) - (remove nil? blocks)) - (remove nil?)) pages (remove nil? pages) pages (map (fn [page] (assoc page :block/uuid (db/new-block-id))) pages) blocks (->> (remove nil? blocks) @@ -232,7 +216,7 @@ (p/then (fn [result] (let [result (remove empty? result)] (when (seq result) - (let [result (util/distinct-by (fn [[pages blocks]] + (let [result (util/distinct-by (fn [[pages _blocks]] (let [page (first pages)] (:block/name page))) result) [pages blocks] (apply map concat result) diff --git a/src/main/frontend/handler/file.cljs b/src/main/frontend/handler/file.cljs index 7e5e94be2b..870a53eeac 100644 --- a/src/main/frontend/handler/file.cljs +++ b/src/main/frontend/handler/file.cljs @@ -10,7 +10,6 @@ [clojure.string :as string] [frontend.config :as config] [frontend.db :as db] - [frontend.db.model :as model] [frontend.format :as format] [frontend.fs :as fs] [frontend.fs.nfs :as nfs] @@ -67,7 +66,7 @@ (defn restore-config! ([repo-url project-changed-check?] (restore-config! repo-url nil project-changed-check?)) - ([repo-url config-content project-changed-check?] + ([repo-url config-content _project-changed-check?] (let [config-content (if config-content config-content (common-handler/get-config repo-url))] (when config-content @@ -148,7 +147,7 @@ (and (mobile/native-android?) (not= "/" (first file))) (str (config/get-repo-dir repo-url) "/" file) - + (and (mobile/native-ios?) (not= "/" (first file))) file @@ -188,15 +187,12 @@ ;; TODO: Remove this function in favor of `alter-files` (defn alter-file - [repo path content {:keys [reset? re-render-root? add-history? update-status? from-disk? skip-compare?] + [repo path content {:keys [reset? re-render-root? from-disk? skip-compare?] :or {reset? true re-render-root? false - add-history? true - update-status? false from-disk? false skip-compare? false}}] - (let [edit-block (state/get-edit-block) - original-content (db/get-file-no-sub repo path) + (let [original-content (db/get-file-no-sub repo path) write-file! (if from-disk? #(p/resolved nil) #(fs/write-file! repo (config/get-repo-dir repo) path content @@ -239,10 +235,8 @@ :path-params {:path path}})))))) (defn alter-files - [repo files {:keys [add-history? update-status? finish-handler reset? update-db? chan chan-callback resolved-handler] - :or {add-history? true - update-status? true - reset? false + [repo files {:keys [reset? update-db?] + :or {reset? false update-db? true} :as opts}] ;; old file content @@ -379,9 +373,9 @@ (js/console.dir e) {})) ks (if (vector? k) k [k]) - new-result (rewrite/assoc-in result ks v)] - (let [new-content (str new-result)] - (set-file-content! repo path new-content)))))) + new-result (rewrite/assoc-in result ks v) + new-content (str new-result)] + (set-file-content! repo path new-content))))) ;; TODO: ;; (defn compare-latest-pages diff --git a/src/main/frontend/handler/git.cljs b/src/main/frontend/handler/git.cljs index 67ba5db823..b21be2d844 100644 --- a/src/main/frontend/handler/git.cljs +++ b/src/main/frontend/handler/git.cljs @@ -32,7 +32,7 @@ ([repo-url file update-status?] (when (and (not (config/local-db? repo-url)) (not (util/electron?))) - (-> (p/let [result (git/add repo-url file)] + (-> (p/let [_result (git/add repo-url file)] (when update-status? (common-handler/check-changed-files-status))) (p/catch (fn [error] @@ -45,9 +45,9 @@ (-> (p/let [remote-oid (common-handler/get-remote-ref repo) commit-oid (git/commit repo commit-message (array remote-oid)) - result (git/write-ref! repo commit-oid) + _result (git/write-ref! repo commit-oid) token (common-handler/get-github-token repo) - push-result (git/push repo token true)] + _push-result (git/push repo token true)] (reset! pushing? false) (notification/clear! nil) (route-handler/redirect-to-home!)) diff --git a/src/main/frontend/handler/graph.cljs b/src/main/frontend/handler/graph.cljs index aa3961fea2..510b35036e 100644 --- a/src/main/frontend/handler/graph.cljs +++ b/src/main/frontend/handler/graph.cljs @@ -13,13 +13,6 @@ :target to}) links)) -(defn- get-connections - [page links] - (count (filter (fn [{:keys [source target]}] - (or (= source page) - (= target page))) - links))) - (defn- build-nodes [dark? current-page page-links tags nodes namespaces] (let [parents (set (map last namespaces)) @@ -88,7 +81,7 @@ :links links})) (defn build-global-graph - [theme {:keys [journal? orphan-pages? builtin-pages?] :as settings}] + [theme {:keys [journal? orphan-pages? builtin-pages?]}] (let [dark? (= "dark" theme) current-page (or (:block/name (db/get-current-page)) "")] (when-let [repo (state/get-current-repo)] @@ -128,7 +121,6 @@ (when-let [repo (state/get-current-repo)] (let [page (util/page-name-sanity-lc page) page-entity (db/entity [:block/name page]) - original-page-name (:block/original-name page-entity) tags (:tags (:block/properties page-entity)) tags (remove #(= page %) tags) ref-pages (db/get-page-referenced-pages repo page) @@ -136,9 +128,9 @@ namespaces (db/get-all-namespace-relation repo) links (concat namespaces - (map (fn [[p aliases]] + (map (fn [[p _aliases]] [page p]) ref-pages) - (map (fn [[p aliases]] + (map (fn [[p _aliases]] [p page]) mentioned-pages) (map (fn [tag] [page tag]) @@ -189,7 +181,7 @@ (let [ref-blocks (db/get-block-referenced-blocks block) namespaces (db/get-all-namespace-relation repo) links (concat - (map (fn [[p aliases]] + (map (fn [[p _aliases]] [block p]) ref-blocks) namespaces) other-blocks (->> (concat (map first ref-blocks)) diff --git a/src/main/frontend/handler/history.cljs b/src/main/frontend/handler/history.cljs index ac015a20f3..7e63a55eb8 100644 --- a/src/main/frontend/handler/history.cljs +++ b/src/main/frontend/handler/history.cljs @@ -7,18 +7,11 @@ [frontend.util :as util] [goog.dom :as gdom])) -(defn- default-undo - [] - (js/document.execCommand "undo" false nil)) - -(defn- default-redo - [] - (js/document.execCommand "redo" false nil)) - (defn restore-cursor! - [{:keys [last-edit-block container pos] :as state}] + [{:keys [last-edit-block container pos]}] (ui-handler/re-render-root!) (when (and container last-edit-block) + #_:clj-kondo/ignore (when-let [container (gdom/getElement container)] (when-let [block-uuid (:block/uuid last-edit-block)] (when-let [block (db/pull [:block/uuid block-uuid])] diff --git a/src/main/frontend/handler/image.cljs b/src/main/frontend/handler/image.cljs index 4ed9d13280..5bfa247a87 100644 --- a/src/main/frontend/handler/image.cljs +++ b/src/main/frontend/handler/image.cljs @@ -49,7 +49,7 @@ (fn [error] (println "Can't read local image file: ") (js/console.dir error)))))) - (catch js/Error e + (catch js/Error _e nil)))) (defn request-presigned-url @@ -76,10 +76,9 @@ (fn [{:keys [signed-url]}] (reset! uploading? false) (if signed-url - (do - (url-handler signed-url)) + (url-handler signed-url) (prn "Something error, can't get a valid signed url."))) - (fn [error] + (fn [_error] (reset! uploading? false) (prn "Something error, can't get a valid signed url.")))) (fn [error] diff --git a/src/main/frontend/handler/page.cljs b/src/main/frontend/handler/page.cljs index 8133813597..b1266b75e5 100644 --- a/src/main/frontend/handler/page.cljs +++ b/src/main/frontend/handler/page.cljs @@ -34,7 +34,6 @@ [goog.object :as gobj] [lambdaisland.glogi :as log] [promesa.core :as p] - [frontend.mobile.util :as mobile] [frontend.mobile.util :as mobile-util])) (defn- get-directory @@ -656,10 +655,9 @@ (cursor/move-cursor-forward input (+ 2 (count current-selected)))))) (defn on-chosen-handler - [input id q pos format] + [input id _q pos format] (let [current-pos (cursor/pos input) edit-content (state/sub [:editor/content id]) - edit-block (state/sub :editor/block) q (or @editor-handler/*selected-text (when (state/sub :editor/show-page-search-hashtag?) @@ -711,7 +709,7 @@ (state/set-today! (date/today)) (when (or (db/cloned? repo) (config/local-db? repo) - (and (= "local" repo) (not (mobile/is-native-platform?)))) + (and (= "local" repo) (not (mobile-util/is-native-platform?)))) (let [title (date/today) today-page (util/page-name-sanity-lc title) template (state/get-default-journal-template) diff --git a/src/main/frontend/handler/plugin.cljs b/src/main/frontend/handler/plugin.cljs index 25993faaf8..e6a5ec696e 100644 --- a/src/main/frontend/handler/plugin.cljs +++ b/src/main/frontend/handler/plugin.cljs @@ -2,15 +2,12 @@ (:require [promesa.core :as p] [rum.core :as rum] [frontend.util :as util] - [frontend.fs :as fs] - [frontend.format.mldoc :refer [->MldocMode] :as mldoc] + [frontend.format.mldoc :as mldoc] [frontend.handler.notification :as notifications] - [frontend.storage :as storage] [camel-snake-kebab.core :as csk] [frontend.state :as state] [medley.core :as md] [electron.ipc :as ipc] - [reitit.frontend.easy :as rfe] [cljs-bean.core :as bean] [clojure.string :as string] [lambdaisland.glogi :as log] @@ -38,7 +35,7 @@ (defn pkg-asset [id asset] (if (and asset (string/starts-with? asset "http")) - asset (if-let [asset (and asset (string/replace asset #"^[./]+" ""))] + asset (when-let [asset (and asset (string/replace asset #"^[./]+" ""))] (str central-endpoint "packages/" id "/" asset)))) (defn load-marketplace-plugins @@ -80,7 +77,7 @@ (get-in @state/state [:plugin/installed-plugins (keyword id) :iir]))) (defn install-marketplace-plugin - [{:keys [repo id] :as mft}] + [{:keys [id] :as mft}] (when-not (and (:plugin/installing @state/state) (installed? id)) (p/create @@ -102,9 +99,8 @@ (state/reset-all-updates-state) (throw e)))) (fn [mfts] - (if-let [mft (some #(if (= (:id %) id) %) mfts)] - (do - (ipc/ipc "updateMarketPlugin" (merge (dissoc pkg :logger) mft))) + (when-let [mft (some #(when (= (:id %) id) %) mfts)] + (ipc/ipc "updateMarketPlugin" (merge (dissoc pkg :logger) mft)) (throw (js/Error. (str ":not-found-in-marketplace" id)))) true)) @@ -117,7 +113,7 @@ [id] (try (js/LSPluginCore.ensurePlugin id) - (catch js/Error e + (catch js/Error _e nil))) (defn open-updates-downloading @@ -147,7 +143,7 @@ (case (keyword status) :completed - (let [{:keys [id dst name title version theme]} payload + (let [{:keys [id dst name title theme]} payload name (or title name "Untitled")] (if only-check (state/consume-updates-coming-plugin payload false) @@ -164,7 +160,7 @@ (do ;; register new (p/then (js/LSPluginCore.register (bean/->js {:key id :url dst})) - (fn [] (if theme (js/setTimeout #(select-a-plugin-theme id) 300)))) + (fn [] (when theme (js/setTimeout #(select-a-plugin-theme id) 300)))) (notifications/show! (str (t :plugin/installed) (t :plugins) ": " name) :success))))) @@ -222,9 +218,9 @@ [pid [cmd actions]] (when-let [pid (keyword pid)] (when (contains? (:plugin/installed-plugins @state/state) pid) - (do (swap! state/state update-in [:plugin/installed-commands pid] - (fnil merge {}) (hash-map cmd (mapv #(conj % {:pid pid}) actions))) - true)))) + (swap! state/state update-in [:plugin/installed-commands pid] + (fnil merge {}) (hash-map cmd (mapv #(conj % {:pid pid}) actions))) + true))) (defn unregister-plugin-slash-command [pid] @@ -263,24 +259,24 @@ (defn register-plugin-simple-command ;; action => [:action-key :event-key] - [pid {:keys [key label type] :as cmd} action] + [pid {:keys [type] :as cmd} action] (when-let [pid (keyword pid)] (when (contains? (:plugin/installed-plugins @state/state) pid) - (do (swap! state/state update-in [:plugin/simple-commands pid] - (fnil conj []) [type cmd action pid]) - true)))) + (swap! state/state update-in [:plugin/simple-commands pid] + (fnil conj []) [type cmd action pid]) + true))) (defn unregister-plugin-simple-command [pid] (swap! state/state md/dissoc-in [:plugin/simple-commands (keyword pid)])) (defn register-plugin-ui-item - [pid {:keys [key type template] :as opts}] + [pid {:keys [type] :as opts}] (when-let [pid (keyword pid)] (when (contains? (:plugin/installed-plugins @state/state) pid) - (do (swap! state/state update-in [:plugin/installed-ui-items pid] - (fnil conj []) [type opts pid]) - true)))) + (swap! state/state update-in [:plugin/installed-ui-items pid] + (fnil conj []) [type opts pid]) + true))) (defn unregister-plugin-ui-items [pid] @@ -400,7 +396,7 @@ (rum/defc lsp-indicator < rum/reactive [] (let [text (state/sub :plugin/indicator-text)] - (if-not (= text "END") + (when-not (= text "END") [:div.flex.align-items.justify-center.h-screen.w-full.preboot-loading [:span.flex.items-center.justify-center.w-60.flex-col [:small.scale-250.opacity-70.mb-10.animate-pulse (svg/logo false)] diff --git a/src/main/frontend/handler/repeated.cljs b/src/main/frontend/handler/repeated.cljs index 56a8caf711..f7a94c66fe 100644 --- a/src/main/frontend/handler/repeated.cljs +++ b/src/main/frontend/handler/repeated.cljs @@ -2,7 +2,6 @@ (:require [cljs-time.core :as t] [cljs-time.local :as tl] [cljs-time.format :as tf] - [frontend.date :as date] [clojure.string :as string] [frontend.util :as util])) @@ -39,7 +38,7 @@ (defn timestamp->text ([timestamp] (timestamp->text timestamp nil)) - ([{:keys [date wday repetition time active]} start-time] + ([{:keys [date repetition time]} start-time] (let [{:keys [year month day]} date {:keys [hour min] :or {hour 0 min 0}} time @@ -49,7 +48,7 @@ [hour min]) [[kind] [duration] num] repetition start-time (or start-time (t/local-date-time year month day hour min)) - [duration-f d] (get-duration-f-and-text duration) + [_duration-f d] (get-duration-f-and-text duration) kind (get-repeater-symbol kind) repeater (when (and kind num d) (str kind num d)) @@ -82,7 +81,7 @@ result))) (defn next-timestamp-text - [{:keys [date wday repetition time active] :as timestamp}] + [{:keys [date repetition time] :as timestamp}] (let [{:keys [year month day]} date {:keys [hour min] :or {hour 0 min 0}} time @@ -91,7 +90,6 @@ (= duration "w")) [duration-f _] (get-duration-f-and-text duration) delta (duration-f num) - today (date/get-local-date) start-time (t/local-date-time year month day hour min) now (tl/local-now) start-time' (case kind @@ -126,7 +124,7 @@ (str " " time-repeater))))) (defn timestamp->map - [{:keys [date wday repetition time active]}] + [{:keys [date repetition time]}] (let [{:keys [year month day]} date {:keys [hour min]} time [[kind] [duration] num] repetition] diff --git a/src/main/frontend/handler/repo.cljs b/src/main/frontend/handler/repo.cljs index 126e15ead5..981b389236 100644 --- a/src/main/frontend/handler/repo.cljs +++ b/src/main/frontend/handler/repo.cljs @@ -244,21 +244,21 @@ :or {re-render? true}}] (state/set-loading-files! repo-url false) (when-not refresh? (state/set-importing-to-db! true)) - (let [file-paths (map :file/path files)] - (let [metadata-file (config/get-metadata-path) - metadata-content (some #(when (= (:file/path %) metadata-file) - (:file/content %)) files) - metadata (when metadata-content - (common-handler/read-metadata! repo-url metadata-content)) - db-encrypted? (:db/encrypted? metadata) - db-encrypted-secret (if db-encrypted? (:db/encrypted-secret metadata) nil)] - (if db-encrypted? - (let [close-fn #(parse-files-and-create-default-files! repo-url files delete-files delete-blocks file-paths first-clone? db-encrypted? re-render? re-render-opts metadata opts)] - (state/set-state! :encryption/graph-parsing? true) - (state/pub-event! [:modal/encryption-input-secret-dialog repo-url - db-encrypted-secret - close-fn])) - (parse-files-and-create-default-files! repo-url files delete-files delete-blocks file-paths first-clone? db-encrypted? re-render? re-render-opts metadata opts))))) + (let [file-paths (map :file/path files) + metadata-file (config/get-metadata-path) + metadata-content (some #(when (= (:file/path %) metadata-file) + (:file/content %)) files) + metadata (when metadata-content + (common-handler/read-metadata! metadata-content)) + db-encrypted? (:db/encrypted? metadata) + db-encrypted-secret (if db-encrypted? (:db/encrypted-secret metadata) nil)] + (if db-encrypted? + (let [close-fn #(parse-files-and-create-default-files! repo-url files delete-files delete-blocks file-paths first-clone? db-encrypted? re-render? re-render-opts metadata opts)] + (state/set-state! :encryption/graph-parsing? true) + (state/pub-event! [:modal/encryption-input-secret-dialog repo-url + db-encrypted-secret + close-fn])) + (parse-files-and-create-default-files! repo-url files delete-files delete-blocks file-paths first-clone? db-encrypted? re-render? re-render-opts metadata opts)))) (defn load-repo-to-db! [repo-url {:keys [first-clone? diffs nfs-files refresh?]}] diff --git a/src/main/frontend/handler/route.cljs b/src/main/frontend/handler/route.cljs index 2836467d42..2d08c079e4 100644 --- a/src/main/frontend/handler/route.cljs +++ b/src/main/frontend/handler/route.cljs @@ -8,7 +8,6 @@ [frontend.state :as state] [frontend.text :as text] [frontend.util :as util] - [goog.dom :as gdom] [medley.core :as medley] [reitit.frontend.easy :as rfe])) diff --git a/src/main/frontend/handler/search.cljs b/src/main/frontend/handler/search.cljs index be37670620..af5ee85b4b 100644 --- a/src/main/frontend/handler/search.cljs +++ b/src/main/frontend/handler/search.cljs @@ -5,8 +5,6 @@ [frontend.search :as search] [frontend.state :as state] [frontend.util :as util] - [goog.dom :as gdom] - [goog.object :as gobj] [promesa.core :as p])) (defn add-search-to-recent! diff --git a/src/main/frontend/handler/shell.cljs b/src/main/frontend/handler/shell.cljs index 1c736f402e..fd5025cae1 100644 --- a/src/main/frontend/handler/shell.cljs +++ b/src/main/frontend/handler/shell.cljs @@ -79,8 +79,8 @@ (defn set-git-username-and-email [username email] - (p/let [r1 (run-git-command! ["config" "--global" "user.name" username]) - r2 (run-git-command! ["config" "--global" "user.email" email])] + (p/let [_r1 (run-git-command! ["config" "--global" "user.name" username]) + _r2 (run-git-command! ["config" "--global" "user.email" email])] (state/close-modal!) (notification/show! [:div "git config successfully!"] diff --git a/src/main/frontend/handler/ui.cljs b/src/main/frontend/handler/ui.cljs index 406ca26372..5ebf83740a 100644 --- a/src/main/frontend/handler/ui.cljs +++ b/src/main/frontend/handler/ui.cljs @@ -13,7 +13,6 @@ [goog.object :as gobj] [clojure.string :as string] [rum.core :as rum] - [clojure.edn :as edn] [frontend.mobile.util :as mobile] [electron.ipc :as ipc])) @@ -149,11 +148,10 @@ (fs/read-file (if (util/electron?) "" (config/get-repo-dir (state/get-current-repo))) href) #(when-let [scripts (and % (string/trim %))] (when-not (string/blank? scripts) - (if (or (not should-ask?) (ask-allow)) + (when (or (not should-ask?) (ask-allow)) (try - (do - (js/eval scripts) - (execed)) + (js/eval scripts) + (execed) (catch js/Error e (js/console.error "[custom js]" e))))))))))))) @@ -287,6 +285,6 @@ (defn try-to-editing-input-into-viewport! [] (when-let [input (state/get-input)] - (if (or (mobile/is-native-platform?) + (when (or (mobile/is-native-platform?) (util/mobile?)) (util/make-el-into-viewport input)))) diff --git a/src/main/frontend/handler/user.cljs b/src/main/frontend/handler/user.cljs index 9d5d645b45..e38cd0b1d5 100644 --- a/src/main/frontend/handler/user.cljs +++ b/src/main/frontend/handler/user.cljs @@ -19,10 +19,10 @@ (when (email? email) (util/post (str config/api "email") {:email email} - (fn [result] + (fn [_result] (db/transact! [{:me/email email}]) (swap! state/state assoc-in [:me :email] email)) - (fn [error] + (fn [_error] (notification/show! "Email already exists!" :error))))) @@ -30,7 +30,7 @@ [cors-proxy] (util/post (str config/api "cors_proxy") {:cors-proxy cors-proxy} - (fn [result] + (fn [_result] (db/transact! [{:me/cors_proxy cors-proxy}]) (swap! state/state assoc-in [:me :cors_proxy] cors-proxy)) (fn [error] diff --git a/src/main/frontend/handler/web/nfs.cljs b/src/main/frontend/handler/web/nfs.cljs index ba8124b719..06aaf2c62a 100644 --- a/src/main/frontend/handler/web/nfs.cljs +++ b/src/main/frontend/handler/web/nfs.cljs @@ -15,7 +15,6 @@ [frontend.idb :as idb] [frontend.search :as search] [frontend.state :as state] - [frontend.storage :as storage] [frontend.util :as util] [goog.object :as gobj] [lambdaisland.glogi :as log] @@ -47,7 +46,7 @@ (->> (cond mobile-native? - (map (fn [{:keys [uri content type size mtime]}] + (map (fn [{:keys [uri content size mtime]}] {:file/path (string/replace uri "file://" "") :file/last-modified-at mtime :file/size size @@ -189,7 +188,7 @@ (log/error :exception error))))))) (p/catch (fn [error] (log/error :exception error) - (if (contains? #{"AbortError" "Error"} (gobj/get error "name")) + (when (contains? #{"AbortError" "Error"} (gobj/get error "name")) (when @*repo (state/set-loading-files! @*repo false)) ;; (log/error :nfs/open-dir-error error) )))))) @@ -226,7 +225,7 @@ (:file/last-modified-at file))) new-files)) get-file-f (fn [path files] (some #(when (= (:file/path %) path) %) files)) - {:keys [added modified deleted] :as diffs} (compute-diffs old-files new-files) + {:keys [added modified deleted]} (compute-diffs old-files new-files) ;; Use the same labels as isomorphic-git rename-f (fn [typ col] (mapv (fn [file] {:type typ :path file :last-modified-at (get-last-modified-at file)}) col)) _ (when (and nfs? (seq deleted)) diff --git a/src/main/frontend/image.cljs b/src/main/frontend/image.cljs index 9659ba8001..b1abe335c3 100644 --- a/src/main/frontend/image.cljs +++ b/src/main/frontend/image.cljs @@ -13,21 +13,21 @@ (let [[width height] (if (reverse? exif-orientation) [height width] - [width height])] - (let [ratio (/ width height) - to-width (if (> width max-width) max-width width) - to-height (if (> height max-height) max-height height) - new-ratio (/ to-width to-height)] - (let [[w h] (cond - (> new-ratio ratio) - [(* ratio to-height) to-height] + [width height]) + ratio (/ width height) + to-width (if (> width max-width) max-width width) + to-height (if (> height max-height) max-height height) + new-ratio (/ to-width to-height) + [w h] (cond + (> new-ratio ratio) + [(* ratio to-height) to-height] - (< new-ratio ratio) - [to-width (/ to-width ratio)] + (< new-ratio ratio) + [to-width (/ to-width ratio)] - :else - [to-width to-height])] - [(int w) (int h)])))) + :else + [to-width to-height])] + [(int w) (int h)])) (defn fix-orientation "Given image and exif orientation, ensure the photo is displayed @@ -76,10 +76,8 @@ ;; )) (defn upload - [files file-handler & {:keys [max-width max-height files-limit] - :or {max-width 1920 - max-height 1080 - files-limit 1}}] + [files file-handler & {:keys [files-limit] + :or {files-limit 1}}] (doseq [file (take files-limit (array-seq files))] (let [file-type (gobj/get file "type") ymd (->> (vals (date/year-month-day-padded)) diff --git a/src/main/frontend/mixins.cljs b/src/main/frontend/mixins.cljs index 61585ced51..c276af73da 100644 --- a/src/main/frontend/mixins.cljs +++ b/src/main/frontend/mixins.cljs @@ -73,14 +73,14 @@ (listen state js/window "visibilitychange" (fn [e] (on-hide state e :visibilitychange)))))) - (catch js/Error e + (catch js/Error _e ;; TODO: Unable to find node on an unmounted component. nil))) (defn resize-layout [state ref] (listen state js/window "resize" - (fn [e] + (fn [_e] (reset! ref [js/window.innerWidth js/window.innerHeight])))) (defn on-enter @@ -95,28 +95,26 @@ (defn on-key-up [state keycode-map all-handler] - (let [node (rum/dom-node state)] - (listen state js/window "keyup" - (fn [e] - (let [key-code (.-keyCode e)] - (when-let [f (get keycode-map key-code)] - (f state e)) - (when all-handler (all-handler e key-code))))))) + (listen state js/window "keyup" + (fn [e] + (let [key-code (.-keyCode e)] + (when-let [f (get keycode-map key-code)] + (f state e)) + (when all-handler (all-handler e key-code)))))) (defn on-key-down ([state keycode-map] (on-key-down state keycode-map {})) ([state keycode-map {:keys [not-matched-handler all-handler target]}] - (let [node (rum/dom-node state)] - (listen state (or target js/window) "keydown" - (fn [e] - (let [key-code (.-keyCode e)] - (if-let [f (get keycode-map key-code)] - (f state e) - (when (and not-matched-handler (fn? not-matched-handler)) - (not-matched-handler e key-code))) - (when (and all-handler (fn? all-handler)) - (all-handler e key-code)))))))) + (listen state (or target js/window) "keydown" + (fn [e] + (let [key-code (.-keyCode e)] + (if-let [f (get keycode-map key-code)] + (f state e) + (when (and not-matched-handler (fn? not-matched-handler)) + (not-matched-handler e key-code))) + (when (and all-handler (fn? all-handler)) + (all-handler e key-code))))))) (defn event-mixin ([attach-listeners] @@ -124,7 +122,7 @@ ([attach-listeners init-callback] (merge event-handler-mixin - {:init (fn [state props] + {:init (fn [state _props] (init-callback state)) :did-mount (fn [state] (attach-listeners state) @@ -176,8 +174,8 @@ state)}) (defn perf-measure-mixin - [desc] "Does performance measurements in development." + [desc] {:wrap-render (fn wrap-render [render-fn] (fn [state] diff --git a/src/main/frontend/page.cljs b/src/main/frontend/page.cljs index a71d33337b..25b4b6eea1 100644 --- a/src/main/frontend/page.cljs +++ b/src/main/frontend/page.cljs @@ -3,7 +3,7 @@ [frontend.state :as state] [frontend.ui :as ui] [frontend.components.sidebar :as sidebar] - [frontend.handler.plugin :refer [lsp-enabled?] :as plugin-handler] + [frontend.handler.plugin :as plugin-handler] [frontend.context.i18n :as i18n])) (rum/defc route-view @@ -34,7 +34,7 @@ (when-let [route-match (state/sub :route-match)] (i18n/tongue-provider (let [route-name (get-in route-match [:data :name])] - (if-let [view (:view (:data route-match))] + (when-let [view (:view (:data route-match))] (if (= :draw route-name) (view route-match) (sidebar/sidebar diff --git a/src/main/frontend/rum.cljs b/src/main/frontend/rum.cljs index 8dfbbd5a0b..6df7cc50e4 100644 --- a/src/main/frontend/rum.cljs +++ b/src/main/frontend/rum.cljs @@ -3,6 +3,7 @@ [clojure.set :as set] [clojure.walk :as w] [rum.core :refer [use-state use-effect!] :as rum] + [daiquiri.interpreter :as interpreter] [cljs-bean.core :as bean])) ;; copy from https://github.com/priornix/antizer/blob/35ba264cf48b84e6597743e28b3570d8aa473e74/src/antizer/core.cljs @@ -45,7 +46,7 @@ ;; we have to make sure to check if the children is sequential ;; as a list can be returned, eg: from a (for) new-children (if (sequential? type#) - (let [result (daiquiri.interpreter/interpret children)] + (let [result (interpreter/interpret children)] (if (sequential? result) result [result])) @@ -98,4 +99,4 @@ (rum/set-ref! *mounted true) #(rum/set-ref! *mounted false)) []) - #(rum/deref *mounted))) \ No newline at end of file + #(rum/deref *mounted))) diff --git a/src/main/frontend/search.cljs b/src/main/frontend/search.cljs index 0a6be3ce8a..298184bd35 100644 --- a/src/main/frontend/search.cljs +++ b/src/main/frontend/search.cljs @@ -61,7 +61,7 @@ (str-len-distance query str) (if (<= 0 (.indexOf ostr oquery)) MAX-STRING-LENGTH 0)) (empty? s) 0 - :default (if (= (first q) (first s)) + :else (if (= (first q) (first s)) (recur (rest q) (rest s) (inc mult) ;; increase the multiplier as more query chars are matched @@ -155,11 +155,11 @@ ([q] (template-search q 10)) ([q limit] - (let [q (clean-str q)] - (let [templates (db/get-all-templates)] - (when (seq templates) - (let [result (fuzzy-search (keys templates) q :limit limit)] - (vec (select-keys templates result)))))))) + (let [q (clean-str q) + templates (db/get-all-templates)] + (when (seq templates) + (let [result (fuzzy-search (keys templates) q :limit limit)] + (vec (select-keys templates result))))))) (defn sync-search-indice! [datoms] diff --git a/src/main/frontend/state.cljs b/src/main/frontend/state.cljs index 38af10fa0c..41b31ca2ad 100644 --- a/src/main/frontend/state.cljs +++ b/src/main/frontend/state.cljs @@ -13,10 +13,8 @@ [goog.dom :as gdom] [goog.object :as gobj] [lambdaisland.glogi :as log] - [medley.core :as medley] [promesa.core :as p] [rum.core :as rum] - [frontend.mobile.util :as mobile] [frontend.mobile.util :as mobile-util] [cljs.cache :as cache])) @@ -71,7 +69,7 @@ :ui/settings-open? false :ui/sidebar-open? false :ui/left-sidebar-open? (boolean (storage/get "ls-left-sidebar-open?")) - :ui/theme (or (storage/get :ui/theme) (if (mobile/is-native-platform?) "light" "dark")) + :ui/theme (or (storage/get :ui/theme) (if (mobile-util/is-native-platform?) "light" "dark")) :ui/system-theme? ((fnil identity (or util/mac? util/win32? false)) (storage/get :ui/system-theme?)) :ui/wide-mode? false ;; :show-all, :hide-block-body, :hide-block-children @@ -284,7 +282,7 @@ (defn get-current-repo [] (or (:git/current-repo @state) - (when-not (mobile/is-native-platform?) + (when-not (mobile-util/is-native-platform?) "local"))) (defn get-config @@ -682,7 +680,7 @@ (defn set-edit-input-id! [input-id] (swap! state update :editor/editing? - (fn [m] + (fn [_m] (and input-id {input-id true})))) (defn get-edit-pos @@ -990,10 +988,6 @@ theme' (if (= theme "dark") "white" "dark")] (use-theme-mode! theme'))) -(defn- file-content-key - [repo path] - (str "ls_file_content_" repo path)) - (defn update-sync-status! [status] (when (seq status) @@ -1445,11 +1439,11 @@ (not (get-edit-input-id))))) (defn set-last-persist-transact-id! - [repo files? id] + [_repo files? id] (swap! state assoc-in [:db/last-persist-transact-ids :repo files?] id)) (defn get-last-persist-transact-id - [repo files?] + [_repo files?] (get-in @state [:db/last-persist-transact-ids :repo files?])) (defn persist-transaction! @@ -1769,4 +1763,4 @@ (defn sub-collapsed [block-id] - (sub [:ui/collapsed-blocks (get-current-repo) block-id])) \ No newline at end of file + (sub [:ui/collapsed-blocks (get-current-repo) block-id])) diff --git a/src/main/frontend/ui.cljs b/src/main/frontend/ui.cljs index 81393be6b6..edf9faeefa 100644 --- a/src/main/frontend/ui.cljs +++ b/src/main/frontend/ui.cljs @@ -26,7 +26,6 @@ ["react-transition-group" :refer [CSSTransition TransitionGroup]] ["react-tweet-embed" :as react-tweet-embed] [rum.core :as rum] - [clojure.string :as str] [frontend.db-mixins :as db-mixins] [frontend.mobile.util :as mobile-util] [goog.functions :refer [debounce]])) @@ -99,9 +98,8 @@ (rum/defcs dropdown < (mixins/modal :open?) [state content-fn modal-content-fn & [{:keys [modal-class z-index] - :or {z-index 999} - :as opts}]] - (let [{:keys [open? toggle-fn]} state + :or {z-index 999}}]] + (let [{:keys [open?]} state modal-content (modal-content-fn state)] [:div.relative.ui__dropdown-trigger {:style {:z-index z-index}} (content-fn state) @@ -118,10 +116,10 @@ child]) (rum/defc dropdown-with-links - [content-fn links {:keys [modal-class links-header links-footer z-index] :as opts}] + [content-fn links {:keys [links-header links-footer] :as opts}] (dropdown content-fn - (fn [{:keys [close-fn] :as state}] + (fn [{:keys [close-fn]}] [:div.py-1.rounded-md.shadow-xs (when links-header links-header) (for [{:keys [options title icon hr hover-detail]} (if (fn? links) (links) links)] @@ -301,7 +299,7 @@ (defn setup-patch-ios-visual-viewport-state! [] - (if-let [^js vp (and (or (and (util/mobile?) (util/safari?)) + (when-let [^js vp (and (or (and (util/mobile?) (util/safari?)) (mobile-util/native-ios?)) js/window.visualViewport)] (let [raf-pending? (atom false) @@ -351,7 +349,7 @@ keystroke e.key] (swap! active-keystroke handler keystroke)) (when (contains? heads (keyword (util/safe-lower-case e.key))) - (set-global-active-keystroke (str/join "+" @active-keystroke)))) + (set-global-active-keystroke (string/join "+" @active-keystroke)))) keydown-handler (partial handle-global-keystroke true) keyup-handler (partial handle-global-keystroke false) clear-all #(do (set-global-active-keystroke "") @@ -401,8 +399,7 @@ (rum/defcs infinite-list < (mixins/event-mixin attach-listeners) "Render an infinite list." - [state list-element-id body {:keys [on-load on-top-reached threshold - has-more more more-class] + [state _list-element-id body {:keys [on-load has-more more more-class] :or {more-class "text-sm"}}] (rum/with-context [[t] i18n/*tongue-context*] [:div @@ -475,9 +472,9 @@ (defn render-keyboard-shortcut [sequence] (let [sequence (if (string? sequence) (-> sequence ;; turn string into sequence - (str/trim) - (str/lower-case) - (str/split #" |\+")) + (string/trim) + (string/lower-case) + (string/split #" |\+")) sequence)] [:span.keyboard-shortcut (map-indexed (fn [i key] @@ -551,7 +548,7 @@ (mixins/on-key-down state {;; enter - 13 (fn [state e] + 13 (fn [state _e] (some-> (.querySelector (rum/dom-node state) "button.ui__modal-enter") (.click)))}))) @@ -564,7 +561,7 @@ close-fn (fn [] (state/close-modal!) (state/close-settings!)) - modal-panel-content (or modal-panel-content (fn [close] [:div]))] + modal-panel-content (or modal-panel-content (fn [_close] [:div]))] [:div.ui__modal {:style {:z-index (if show? 999 -1)} :label label} @@ -579,8 +576,7 @@ (defn make-confirm-modal [{:keys [tag title sub-title sub-checkbox? on-cancel on-confirm] - :or {on-cancel #()} - :as opts}] + :or {on-cancel #()}}] (fn [close-fn] (rum/with-context [[t] i18n/*tongue-context*] (let [*sub-checkbox-selected (and sub-checkbox? (atom []))] @@ -636,7 +632,7 @@ label (:modal/label modal) close-fn (fn [] (state/close-sub-modal! id)) - modal-panel-content (or modal-panel-content (fn [close] [:div]))] + modal-panel-content (or modal-panel-content (fn [_close] [:div]))] [:div.ui__modal.is-sub-modal {:style {:z-index (if show? (+ 999 idx) -1)} :label label} @@ -669,7 +665,7 @@ (when (true? (:default-collapsed? (last args))) (reset! (get state ::collapsed?) true))) state)} - [state header content {:keys [default-collapsed? title-trigger?]}] + [state header content {:keys [title-trigger?]}] (let [control? (get state ::control?) collapsed? (get state ::collapsed?) on-mouse-down (fn [e] @@ -722,7 +718,7 @@ (rum/defcs catch-error < {:did-catch - (fn [state error info] + (fn [state error _info] (js/console.dir error) (assoc state ::error error))} [{error ::error, c :rum/react-component} error-view view] diff --git a/src/main/frontend/util.cljc b/src/main/frontend/util.cljc index 4afdd9a961..0711b14fd0 100644 --- a/src/main/frontend/util.cljc +++ b/src/main/frontend/util.cljc @@ -140,7 +140,7 @@ "Dissociates an entry from a nested associative structure returning a new nested structure. keys is a sequence of keys. Any empty maps that result will not be present in the new structure." - [m [k & ks :as keys]] + [m [k & ks]] (if ks (if-let [nextmap (get m k)] (let [newmap (dissoc-in nextmap ks)] @@ -253,27 +253,27 @@ on-progress)) (.send xhr file)))) -(defn post - [url body on-ok on-failed] - #?(:cljs +#?(:cljs + (defn post + [url body on-ok on-failed] (fetch url {:method "post" :headers {:Content-Type "application/json"} :body (js/JSON.stringify (clj->js body))} on-ok on-failed))) -(defn patch - [url body on-ok on-failed] - #?(:cljs +#?(:cljs + (defn patch + [url body on-ok on-failed] (fetch url {:method "patch" :headers {:Content-Type "application/json"} :body (js/JSON.stringify (clj->js body))} on-ok on-failed))) -(defn delete - [url on-ok on-failed] - #?(:cljs +#?(:cljs + (defn delete + [url on-ok on-failed] (fetch url {:method "delete" :headers {:Content-Type "application/json"}} on-ok @@ -464,13 +464,15 @@ (let [bottom (.-scrollHeight node)] (scroll-to node bottom false))))) -(defn url-encode - [string] - #?(:cljs (some-> string str (js/encodeURIComponent) (.replace "+" "%20")))) +#?(:cljs + (defn url-encode + [string] + (some-> string str (js/encodeURIComponent) (.replace "+" "%20")))) -(defn url-decode - [string] - #?(:cljs (some-> string str (js/decodeURIComponent)))) +#?(:cljs + (defn url-decode + [string] + (some-> string str (js/decodeURIComponent)))) #?(:cljs (defn link? @@ -522,9 +524,7 @@ (defn drop-first-line [s] - (let [lines (string/split-lines s) - others (some->> (next lines) - (string/join "\n"))] + (let [lines (string/split-lines s)] [(first lines)])) (defn distinct-by @@ -608,9 +608,9 @@ (when-not not-space? " ") (triml-without-newlines right))))) -(defn join-newline - [& col] - #?(:cljs +#?(:cljs + (defn join-newline + [& col] (let [col (remove nil? col)] (reduce (fn [acc s] (if (or (= acc "") (= "\n" (last acc))) @@ -778,8 +778,7 @@ (defn get-nodes-between-two-nodes [id1 id2 class] (when-let [nodes (array-seq (js/document.getElementsByClassName class))] - (let [id #(gobj/get % "id") - node-1 (gdom/getElement id1) + (let [node-1 (gdom/getElement id1) node-2 (gdom/getElement id2) idx-1 (.indexOf nodes node-1) idx-2 (.indexOf nodes node-2) @@ -1060,11 +1059,12 @@ (when (string? tag-name) (not (safe-re-find #"[# \t\r\n]+" tag-name)))) -(defn encode-str - [s] - (if (tag-valid? s) - s - (url-encode s))) +#?(:cljs + (defn encode-str + [s] + (if (tag-valid? s) + s + (url-encode s)))) #?(:cljs (defn get-clipboard-as-html @@ -1077,6 +1077,7 @@ [(.getData c "Text") (.getData c "Text")]))))) (defn pp-str [x] + #_:clj-kondo/ignore (with-out-str (clojure.pprint/pprint x))) (defn hiccup-keywordize @@ -1300,8 +1301,9 @@ (string/join "/")))) ;; Copied from https://github.com/tonsky/datascript-todo -(defmacro profile [k & body] - #?(:clj +#?(:clj + (defmacro profile + [k & body] `(if goog.DEBUG (let [k# ~k] (.time js/console k#) @@ -1518,8 +1520,7 @@ #?(:cljs (defn meta-key-name [] - (let [user-agent (.. js/navigator -userAgent)] - (if mac? "Cmd" "Ctrl")))) + (if mac? "Cmd" "Ctrl"))) ;; TODO: share with electron (defn ignored-path? @@ -1637,4 +1638,4 @@ (string/starts-with? url "#"))] (if (and (not route?) (electron?)) (js/window.apis.openExternal url) - (set! (.-href js/window.location) url))))) \ No newline at end of file + (set! (.-href js/window.location) url))))) diff --git a/src/main/frontend/util/thingatpt.cljs b/src/main/frontend/util/thingatpt.cljs index 6bfe0d373c..c22700f58c 100644 --- a/src/main/frontend/util/thingatpt.cljs +++ b/src/main/frontend/util/thingatpt.cljs @@ -122,7 +122,7 @@ (when-let [markup (get-markup-at-point input)] (assoc markup :type "markup"))) -(defn- org-admonition&src-at-point [& [input]] +(defn org-admonition&src-at-point [& [input]] (when-let [admonition&src (thing-at-point ["#+BEGIN_" "#+END_"] input)] (let [params (string/split (first (string/split-lines (:full-content admonition&src)))