Merge branch 'master' into enhance/allow-edit-markup-files

pull/3870/head
Andelf 2022-01-12 09:23:31 +08:00 committed by GitHub
commit c3a9f0cb31
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
31 changed files with 219 additions and 251 deletions

View File

@ -44,6 +44,7 @@ jobs:
with:
java-version: 1.8
# This is the latest node version of we can run
- name: Set up Node
uses: actions/setup-node@v2
with:

View File

@ -82,7 +82,7 @@ We also have [a dedicated page](https://github.com/logseq/logseq/blob/master/COD
### 1. Requirements
- [Node.js](https://nodejs.org/en/download/) & [Yarn](https://classic.yarnpkg.com/en/docs/install/)
- [Node.js](https://nodejs.org/en/download/) (See [build.yml](.github/workflows/build.yml) for allowed version) & [Yarn](https://classic.yarnpkg.com/en/docs/install/)
- [Java & Clojure](https://clojure.org/guides/getting_started). (If you run into `Execution error (FileNotFoundException) at java.io.FileInputStream/open0 (FileInputStream.java:-2). -M:cljs (No such file or directory)`, it means you have a wrong Clojure version installed. Please uninstall it and follow the instructions linked.)
### 2. Compile to JavaScript

View File

@ -12,10 +12,9 @@
(defn- ensure-cfg
[]
(try
(do
(.ensureFileSync fs cfg-path)
(let [body (.toString (.readFileSync fs cfg-path))]
(if (seq body) (reader/read-string body) {})))
(.ensureFileSync fs cfg-path)
(let [body (.toString (.readFileSync fs cfg-path))]
(if (seq body) (reader/read-string body) {}))
(catch js/Error e
(js/console.error :cfg-error e)
{})))
@ -23,7 +22,7 @@
(defn- write-cfg!
[cfg]
(try
(do (.writeFileSync fs cfg-path (pr-str cfg)) cfg)
(.writeFileSync fs cfg-path (pr-str cfg)) cfg
(catch js/Error e
(js/console.error :cfg-error e))))

View File

@ -2,8 +2,7 @@
(:require [electron.handler :as handler]
[electron.search :as search]
[electron.updater :refer [init-updater]]
[electron.utils :refer [*win mac? win32? linux? prod? dev? logger open get-win-from-sender]]
[electron.configs :as cfgs]
[electron.utils :refer [*win mac? linux? logger get-win-from-sender]]
[clojure.string :as string]
[promesa.core :as p]
[cljs-bean.core :as bean]
@ -11,7 +10,7 @@
["fs-extra" :as fs]
["path" :as path]
["os" :as os]
["electron" :refer [BrowserWindow app protocol ipcMain dialog Menu MenuItem session] :as electron]
["electron" :refer [BrowserWindow app protocol ipcMain dialog] :as electron]
[clojure.core.async :as async]
[electron.state :as state]
[electron.git :as git]
@ -246,7 +245,7 @@
(.on app "before-quit" (fn [_e]
(reset! win/*quitting? true)))
(.on app "activate" #(if @*win (.show win)))))))))
(.on app "activate" #(when @*win (.show win)))))))))
(defn start []
(js/console.log "Main - start")

View File

@ -2,11 +2,8 @@
(:require [cljs-bean.core :as bean]
["fs" :as fs]
["chokidar" :as watcher]
[promesa.core :as p]
[clojure.string :as string]
[electron.utils :as utils]
["electron" :refer [app]]
[electron.window :as win]))
["electron" :refer [app]]))
;; TODO: explore different solutions for different platforms
;; 1. https://github.com/Axosoft/nsfw

View File

@ -43,7 +43,7 @@
(try
(let [p (.join path (state/get-graph-path) ".git")]
(.isDirectory (fs/statSync p)))
(catch js/Error e
(catch js/Error _e
nil)))
(defn remove-dot-git-file!
@ -148,8 +148,6 @@
(let [args (if (string? args)
(split-args args)
args)
ok-handler (fn [result]
(p/resolved result))
error-handler (fn [error]
;; TODO: why this happen?
(when-not (string/blank? error)

View File

@ -9,7 +9,6 @@
[electron.fs-watcher :as watcher]
[electron.configs :as cfgs]
[promesa.core :as p]
[goog.object :as gobj]
[clojure.string :as string]
[electron.utils :as utils]
[electron.state :as state]
@ -47,8 +46,7 @@
(readdir dir))
(defmethod handle :unlink [_window [_ repo path]]
(let [basename (path/basename path)
file-name (-> (string/replace path (str repo "/") "")
(let [file-name (-> (string/replace path (str repo "/") "")
(string/replace "/" "_")
(string/replace "\\" "_"))
recycle-dir (str repo "/logseq/.recycle")
@ -58,8 +56,7 @@
(defn backup-file
[repo path content]
(let [basename (path/basename path)
file-name (-> (string/replace path (str repo "/") "")
(let [file-name (-> (string/replace path (str repo "/") "")
(string/replace "/" "_")
(string/replace "\\" "_"))
bak-dir (str repo "/logseq/bak")
@ -105,9 +102,9 @@
" failed, "
e
(when backup-path
" A backup file was saved to "
backup-path
"."))}))))))
(str ". A backup file was saved to "
backup-path
".")))}))))))
(defmethod handle :rename [_window [_ old-path new-path]]
(fs/renameSync old-path new-path))
@ -145,13 +142,13 @@
result (get (js->clj result) "filePaths")]
(p/resolved (first result))))
(defmethod handle :openDir [^js window _messages]
(defmethod handle :openDir [^js _window _messages]
(p/let [path (open-dir-dialog)]
(if path
(p/resolved (bean/->js (get-files path)))
(p/rejected (js/Error "path empty")))))
(defmethod handle :getFiles [window [_ path]]
(defmethod handle :getFiles [_window [_ path]]
(get-files path))
(defn- sanitize-graph-name
@ -183,7 +180,7 @@
(map #(path/basename % ".transit"))
(map graph-name->path))))
(defmethod handle :getGraphs [window [_]]
(defmethod handle :getGraphs [_window [_]]
(get-graphs))
(defn- get-graph-path
@ -200,40 +197,40 @@
(when (fs/existsSync file-path)
(utils/read-file file-path)))))
(defmethod handle :getSerializedGraph [window [_ graph-name]]
(defmethod handle :getSerializedGraph [_window [_ graph-name]]
(get-serialized-graph graph-name))
(defmethod handle :saveGraph [window [_ graph-name value-str]]
(defmethod handle :saveGraph [_window [_ graph-name value-str]]
(when (and graph-name value-str)
(when-let [file-path (get-graph-path graph-name)]
(fs/writeFileSync file-path value-str))))
(defmethod handle :deleteGraph [window [_ graph-name]]
(defmethod handle :deleteGraph [_window [_ graph-name]]
(when graph-name
(when-let [file-path (get-graph-path graph-name)]
(when (fs/existsSync file-path)
(fs-extra/removeSync file-path)))))
(defmethod handle :openNewWindow [window [_]]
(defmethod handle :openNewWindow [_window [_]]
(let [win (win/create-main-window)]
(win/on-close-save! win)
(win/setup-window-listeners! win)
nil))
(defmethod handle :persistent-dbs-saved [window _]
(defmethod handle :persistent-dbs-saved [_window _]
(async/put! state/persistent-dbs-chan true)
true)
(defmethod handle :search-blocks [window [_ repo q opts]]
(defmethod handle :search-blocks [_window [_ repo q opts]]
(search/search-blocks repo q opts))
(defmethod handle :rebuild-blocks-indice [window [_ repo data]]
(defmethod handle :rebuild-blocks-indice [_window [_ repo data]]
(search/truncate-blocks-table! repo)
;; unneeded serialization
(search/upsert-blocks! repo (bean/->js data))
[])
(defmethod handle :transact-blocks [window [_ repo data]]
(defmethod handle :transact-blocks [_window [_ repo data]]
(let [{:keys [blocks-to-remove-set blocks-to-add]} data]
(when (seq blocks-to-remove-set)
(search/delete-blocks! repo blocks-to-remove-set))
@ -241,10 +238,10 @@
;; unneeded serialization
(search/upsert-blocks! repo (bean/->js blocks-to-add)))))
(defmethod handle :truncate-blocks [window [_ repo]]
(defmethod handle :truncate-blocks [_window [_ repo]]
(search/truncate-blocks-table! repo))
(defmethod handle :remove-db [window [_ repo]]
(defmethod handle :remove-db [_window [_ repo]]
(search/delete-db! repo))
(defn clear-cache!
@ -271,7 +268,7 @@
(when dir
(watcher/watch-dir! window dir)))
(defmethod handle :openDialog [^js window messages]
(defmethod handle :openDialog [^js _window _messages]
(open-dir-dialog))
(defmethod handle :getLogseqDotDirRoot []
@ -297,7 +294,7 @@
(defmethod handle :getDirname [_]
js/__dirname)
(defmethod handle :getAppBaseInfo [^js win [_ opts]]
(defmethod handle :getAppBaseInfo [^js win [_ _opts]]
{:isFullScreen (.isFullScreen win)})
(defmethod handle :setCurrentGraph [^js win [_ path]]
@ -325,11 +322,11 @@
(defmethod handle :quitAndInstall []
(.quitAndInstall autoUpdater))
(defmethod handle :graphUnlinked [^js win [_ repo]]
(defmethod handle :graphUnlinked [^js _win [_ repo]]
(doseq [window (win/get-all-windows)]
(utils/send-to-renderer window "graphUnlinked" (bean/->clj repo))))
(defmethod handle :dbsync [^js win [_ graph tx-data]]
(defmethod handle :dbsync [^js _win [_ graph tx-data]]
(let [dir (utils/get-graph-dir graph)]
(doseq [window (win/get-graph-all-windows dir)]
(utils/send-to-renderer window "dbsync"

View File

@ -6,10 +6,9 @@
["fs-extra" :as fs]
["path" :as path]
[clojure.string :as string]
[electron.utils :refer [logger]]
[electron.utils :refer [logger fetch extract-zip] :as utils]
[electron.configs :as cfgs]
[electron.window :refer [get-all-windows]]
[electron.utils :refer [*win fetch extract-zip] :as utils]))
[electron.window :refer [get-all-windows]]))
;; update & install
;;(def *installing-or-updating (atom nil))
@ -46,20 +45,14 @@
(emit :lsp-installed {:status :error :payload e})
(throw (js/Error. :release-network-issue)))))
(defn fetch-tag-release-asset
[repo tag])
(defn download-asset-zip
[{:keys [id repo title author description effect sponsors]} dl-url dl-version dot-extract-to]
(p/catch
(p/let [^js res (fetch dl-url #js {:timeout 30000})
_ (if-not (.-ok res) (throw (js/Error. :download-network-issue)))
_ (when-not (.-ok res) (throw (js/Error. :download-network-issue)))
frm-zip (p/create
(fn [resolve1 reject1]
(let [headers (. res -headers)
body (.-body res)
total-size (js/parseInt (.get headers "content-length"))
start-at (.now js/Date)
(let [body (.-body res)
*downloaded (atom 0)
dest-basename (path/basename dl-url)
dest-basename (if-not (string/ends-with? dest-basename ".zip")
@ -73,7 +66,7 @@
(reset! *downloaded downloaded))))
(.on "error" (fn [^js e]
(reject1 e)))
(.on "end" (fn [^js e]
(.on "end" (fn [^js _e]
(.close dest-file)
(let [dest-file (string/replace tmp-dest-file ".pending" "")]
(fs/renameSync tmp-dest-file dest-file)
@ -93,7 +86,7 @@
"."
(last (take-while #(pkg? (.join path zip-extracted-path %)) dirs))))
_ (if-not tmp-extracted-root
_ (when-not tmp-extracted-root
(throw (js/Error. :invalid-plugin-package)))
tmp-extracted-root (.join path zip-extracted-path tmp-extracted-root)
@ -133,7 +126,7 @@
(debug (if updating? "Updating:" "Installing:") repo)
(-> (p/create
(fn [resolve reject]
(fn [resolve _reject]
;;(reset! *installing-or-updating item)
;; get releases
(-> (p/let [[asset latest-version] (fetch-latest-release-asset item)
@ -157,7 +150,7 @@
(throw (js/Error. :release-asset-not-found)))
dest (.join path cfgs/dot-root "plugins" (:id item))
_ (if-not only-check (download-asset-zip item dl-url latest-version dest))
_ (when-not only-check (download-asset-zip item dl-url latest-version dest))
_ (debug "[" (if only-check "Checked" "Updated") "DONE] " latest-version)]
(emit :lsp-installed

View File

@ -1,5 +1,5 @@
(ns electron.updater
(:require [electron.utils :refer [mac? win32? prod? open fetch logger *win]]
(:require [electron.utils :refer [mac? prod? open fetch logger *win]]
[frontend.version :refer [version]]
[clojure.string :as string]
[promesa.core :as p]
@ -38,7 +38,7 @@
status (.-status res)
text (.text res)]
(if (.-ok res)
(let [info (if-not (string/blank? text) (js/JSON.parse text))]
(let [info (when-not (string/blank? text) (js/JSON.parse text))]
(bean/->clj info))
(throw (js/Error. (str "[" status "] " text)))))
(fn [e]
@ -59,15 +59,15 @@
[artifact (get-latest-artifact-info repo)
artifact (when-let [remote-version (and artifact (re-find #"\d+\.\d+\.\d+" (:url artifact)))]
(if (and (. semver valid remote-version)
(. semver lt electron-version remote-version)) artifact))
(when (and (. semver valid remote-version)
(. semver lt electron-version remote-version)) artifact))
url (if-not artifact (do (emit "update-not-available" nil) (throw nil)) (:url artifact))
_ (if url (emit "update-available" (bean/->js artifact)) (throw (js/Error. "download url not exists")))
;; start download FIXME: user's preference about auto download
_ (when-not auto-download (throw nil))
^js dl-res (fetch url)
_ (if-not (.-ok dl-res) (throw (js/Error. "download resource not available")))
_ (when-not (.-ok dl-res) (throw (js/Error. "download resource not available")))
dest-info (p/create
(fn [resolve1 reject1]
(let [headers (. dl-res -headers)
@ -91,7 +91,7 @@
(reset! *downloaded downloaded))))
(.on "error" (fn [e]
(reject1 e)))
(.on "end" (fn [e]
(.on "end" (fn [_e]
(.close dest-file)
(let [dest-file (string/replace tmp-dest-file ".pending" "")]
(fs/renameSync tmp-dest-file dest-file)
@ -137,17 +137,17 @@
(debug "Skip remote version [ahead of pre-release]" remote-version))))))
(defn init-updater
[{:keys [repo logger ^js win] :as opts}]
[{:keys [repo _logger ^js _win] :as opts}]
(and prod? (not= false (cfgs/get-item :auto-update)) (init-auto-updater repo))
(let [check-channel "check-for-updates"
install-channel "install-updates"
check-listener (fn [e & args]
check-listener (fn [_e & args]
(when-not @*update-pending
(reset! *update-pending true)
(p/finally
(check-for-updates (merge opts {:args args}))
#(reset! *update-pending nil))))
install-listener (fn [e quit-app?]
install-listener (fn [_e quit-app?]
(when-let [dest-file (:dest-file @*update-ready-to-install)]
(open dest-file)
(and quit-app? (js/setTimeout #(.quit app) 1000))))]

View File

@ -28,7 +28,7 @@
(defn get-ls-default-plugins
[]
(let [plugins-root (path/join (get-ls-dotdir-root) "plugins")
_ (if-not (fs/existsSync plugins-root)
_ (when-not (fs/existsSync plugins-root)
(fs/mkdirSync plugins-root))
dirs (js->clj (fs/readdirSync plugins-root #js{"withFileTypes" true}))
dirs (->> dirs

View File

@ -1,8 +1,8 @@
(ns electron.window
(:require ["electron-window-state" :as windowStateKeeper]
[electron.utils :refer [*win mac? win32? linux? prod? dev? logger open]]
[electron.utils :refer [mac? win32? linux? dev? logger open]]
[electron.configs :as cfgs]
["electron" :refer [BrowserWindow app protocol ipcMain dialog Menu MenuItem session shell] :as electron]
["electron" :refer [BrowserWindow app Menu MenuItem session shell] :as electron]
["path" :as path]
["url" :as URL]
[electron.state :as state]

View File

@ -375,7 +375,7 @@
(rum/defc page-inner
"The inner div of page reference component
page-name-in-block is the overridable name of the page (legacy)
All page-names are sanitized except page-name-in-block"
@ -2937,7 +2937,7 @@
"main-content-container"
(block-list config segment)
{:on-load bottom-reached
:threhold 1000
:threshold 1000
:has-more has-more?
:more (if (:preview? config) "More" (ui/loading "Loading"))})]))

View File

@ -82,7 +82,7 @@
alias (if (string? alias) [alias] alias)
aliases (and alias
(seq (remove #(= page-name (util/page-name-sanity-lc %))
alias)))]
alias)))]
(cond->
(util/remove-nils
(assoc
@ -146,7 +146,7 @@
pages (remove nil? pages)
pages (map (fn [page] (assoc page :block/uuid (db/new-block-id))) pages)
blocks (->> (remove nil? blocks)
(map (fn [b] (dissoc b :block/title :block/body :block/level))))]
(map (fn [b] (dissoc b :block/title :block/body))))]
[pages blocks])
(catch js/Error e
(log/error :exception e))))

View File

@ -376,12 +376,12 @@
down?))
(defn on-scroll
[node {:keys [on-load on-top-reached threhold]
:or {threhold 500}}]
[node {:keys [on-load on-top-reached threshold]
:or {threshold 500}}]
(let [full-height (gobj/get node "scrollHeight")
scroll-top (gobj/get node "scrollTop")
client-height (gobj/get node "clientHeight")
bottom-reached? (<= (- full-height scroll-top client-height) threhold)
bottom-reached? (<= (- full-height scroll-top client-height) threshold)
top-reached? (= scroll-top 0)
down? (scroll-down?)]
(when (and down? bottom-reached? on-load)
@ -401,7 +401,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 threhold
[state list-element-id body {:keys [on-load on-top-reached threshold
has-more more more-class]
:or {more-class "text-sm"}}]
(rum/with-context [[t] i18n/*tongue-context*]

View File

@ -1,5 +1,5 @@
(ns 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 weeks year]]
(: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 formatters parse unparse]]
[frontend.modules.shortcut.core :as shortcut]
[frontend.state :as state]
@ -32,8 +32,6 @@
(defn- inc-date [date n] (plus date (days n)))
(defn- inc-week [date n] (plus date (weeks n)))
(defn previous
"If date fails pred, subtract period until true, otherwise answer date"
;; date - a date object that satisfies cljs-time.core/DateTimeProtocol.
@ -181,9 +179,9 @@
(reset! *internal-model (first (:rum/args state)))
state)}
(shortcut/mixin :shortcut.handler/date-picker)
[model {:keys [on-change on-switch disabled? start-of-week class style attr]
:or {start-of-week (state/get-start-of-week)} ;; Default to Sunday
:as args}]
[_model {:keys [on-change disabled? start-of-week class style attr]
:or {start-of-week (state/get-start-of-week)} ;; Default to Sunday
:as args}]
(let [internal-model (util/react *internal-model)
display-month (first-day-of-the-month (or internal-model (now->utc)))
props-with-defaults (merge args {:start-of-week start-of-week})

View File

@ -77,7 +77,7 @@
(str clock-in-log "\n")
(str clock-out-log "\n"))))))
content)
(catch js/Error e
(catch js/Error _e
content)))
(defn clock-summary

View File

@ -1,9 +1,6 @@
(ns frontend.util.list
(:require [frontend.util.thingatpt :as thingatpt]
[frontend.util.cursor :as cursor]
[clojure.string :as string]
[frontend.state :as state]
[frontend.db :as db]))
[frontend.util.cursor :as cursor]))
(defn get-prev-item [& [input]]
(when-not (cursor/textarea-cursor-first-row? input)

View File

@ -4,9 +4,7 @@
[frontend.handler.ui :as ui-handler]
[frontend.modules.outliner.core :as outliner-core]
[frontend.modules.outliner.file :as outliner-file]
[frontend.format.mldoc :as mldoc]
[frontend.state :as state]
[frontend.util.property :as property]
[frontend.util :as util]))
(defn insert-property
@ -62,7 +60,6 @@
(let [properties (:block/properties pre-block)
new-properties (assoc properties key value)
content (:block/content pre-block)
front-matter? (property/front-matter? content)
new-content (insert-property format content key value)
block {:db/id (:db/id pre-block)
:block/properties new-properties

View File

@ -3,6 +3,7 @@
[frontend.state :as state]
[frontend.fs :as fs]
[frontend.util :as util]
[cljs.reader :as reader]
[promesa.core :as p]))
@ -19,7 +20,7 @@
ILoad
(-load [_]
(state/add-watch-state (keyword (str "persist-var/" location))
(fn [k r o n]
(fn [_k _r _o n]
(let [repo (state/get-current-repo)]
(when (and
(not (get-in @*value [repo :loaded?]))
@ -28,7 +29,7 @@
(config/get-repo-dir (state/get-current-repo))
(load-path location))]
(when-let [content (and (some? content)
(try (cljs.reader/read-string content)
(try (reader/read-string content)
(catch js/Error e
(println (util/format "load persist-var failed: %s" (load-path location)))
(js/console.dir e))))]
@ -46,15 +47,16 @@
(fs/write-file! repo dir path content nil)))
IDeref
(-deref [this]
(-deref [_this]
(get-in @*value [(state/get-current-repo) :value]))
IReset
(-reset! [o new-value]
(swap! *value (fn [o] (assoc-in @*value [(state/get-current-repo) :value] new-value)))))
(-reset! [_o new-value]
(swap! *value (fn [_o] (assoc-in @*value [(state/get-current-repo) :value] new-value)))))
(defn persist-var [init-value location]
(defn persist-var
"This var is stored at logseq/LOCATION.edn"
[init-value location]
(let [var (->PersistVar (atom {(state/get-current-repo)
{:value init-value
:loaded? false}})

View File

@ -124,12 +124,12 @@
(contains? (set (util/remove-first #{key} (get-property-keys format content))) key)))
(defn goto-properties-beginning
[format input]
[_format input]
(cursor/move-cursor-to-thing input properties-start 0)
(cursor/move-cursor-forward input (count properties-start)))
(defn goto-properties-end
[format input]
[_format input]
(cursor/move-cursor-to-thing input properties-start 0)
(let [from (cursor/pos input)]
(cursor/move-cursor-to-thing input properties-end from)))

View File

@ -5,6 +5,7 @@
[frontend.util.cursor :as cursor]
[frontend.config :as config]
[frontend.text :as text]
[cljs.reader :as reader]
[goog.object :as gobj]))
(defn thing-at-point
@ -83,7 +84,7 @@
(let [key (first (string/split line "::"))
line-beginning-pos (cursor/line-beginning-pos input)
pos-in-line (- (cursor/pos input) line-beginning-pos)]
(if (<= 0 pos-in-line (+ (count key) (count "::")))
(when (<= 0 pos-in-line (+ (count key) (count "::")))
{:full-content (str key "::")
:raw-content key
:start line-beginning-pos
@ -99,7 +100,7 @@
(when-let [line (line-at-point input)]
(when-let [[_ indent bullet checkbox]
(get-list-item-indent&bullet (:raw-content line))]
(let [bullet (cljs.reader/read-string bullet)]
(let [bullet (reader/read-string bullet)]
(assoc line
:type "list-item"
:indent indent

View File

@ -14,7 +14,6 @@
[frontend.db.query-dsl :as query-dsl]
[frontend.db.utils :as db-utils]
[frontend.fs :as fs]
[frontend.handler :as handler]
[frontend.handler.dnd :as editor-dnd-handler]
[frontend.handler.editor :as editor-handler]
[frontend.handler.export :as export-handler]
@ -119,7 +118,9 @@
_ (when-not exist? (fs/mkdir-recur! path))
user-path (util/node-path.join path file)
sub-dir? (string/starts-with? user-path path)
_ (when-not sub-dir? (do (log/info :debug user-path) (throw "write file denied")))
_ (when-not sub-dir?
(log/info :debug user-path)
(throw "write file denied"))
user-path-root (util/node-path.dirname user-path)
exist? (fs/file-exists? user-path-root "")
_ (when-not exist? (fs/mkdir-recur! user-path-root))
@ -128,8 +129,7 @@
(defn ^:private read_dotdir_file
[file sub-root]
(p/let [repo ""
path (plugin-handler/get-ls-dotdir-root)
(p/let [path (plugin-handler/get-ls-dotdir-root)
path (util/node-path.join path sub-root)
user-path (util/node-path.join path file)
sub-dir? (string/starts-with? user-path path)
@ -258,7 +258,7 @@
;; handle keybinding commands
(when-let [shortcut-args (and palette-cmd keybinding
(plugin-handler/simple-cmd-keybinding->shortcut-args pid key keybinding))]
(let [dispatch-cmd (fn [_ e] (palette-handler/invoke-command palette-cmd))
(let [dispatch-cmd (fn [_ _e] (palette-handler/invoke-command palette-cmd))
[handler-id id shortcut-map] (update shortcut-args 2 assoc :fn dispatch-cmd)]
(js/console.debug :shortcut/register-shortcut [handler-id id shortcut-map])
(st/register-shortcut! handler-id id shortcut-map)))))))
@ -469,16 +469,15 @@
nil)))))
(def ^:export remove_block
(fn [block-uuid ^js opts]
(fn [block-uuid ^js _opts]
(let [includeChildren true
repo (state/get-current-repo)]
(editor-handler/delete-block-aux!
{:block/uuid (medley/uuid block-uuid) :repo repo} includeChildren))))
(def ^:export update_block
(fn [block-uuid content ^js opts]
(let [opts (and opts (bean/->clj opts))
repo (state/get-current-repo)
(fn [block-uuid content ^js _opts]
(let [repo (state/get-current-repo)
edit-input (state/get-edit-input-id)
editing? (and edit-input (string/ends-with? edit-input block-uuid))]
(if editing?
@ -586,9 +585,8 @@
(defn ^:export q
[query-string]
(when-let [repo (state/get-current-repo)]
(when-let [conn (db/get-conn repo)]
(when-let [result (query-dsl/query repo query-string)]
(bean/->js (normalize-keyword-for-json (flatten @result)))))))
(when-let [result (query-dsl/query repo query-string)]
(bean/->js (normalize-keyword-for-json (flatten @result))))))
(defn ^:export datascript_query
[query & inputs]

View File

@ -1,6 +1,5 @@
(ns frontend.db.query-dsl-test
(:require [cljs.test :refer [are async deftest testing use-fixtures]]
[datascript.core :as d]
[frontend.db :as db]
[frontend.db.config :refer [test-db] :as config]
[frontend.db.query-dsl :as dsl]

View File

@ -1,6 +1,6 @@
(ns frontend.format.block-test
(:require [frontend.format.block :as block]
[cljs.test :refer [deftest is are testing use-fixtures run-tests]]))
[cljs.test :refer [deftest are]]))
(deftest test-extract-properties
(are [x y] (= (:properties (block/extract-properties x)) y)

View File

@ -1,13 +1,11 @@
(ns frontend.handler.export-test
;; namespace local config for private function tests
{:clj-kondo/config {:linters {:private-call {:level :off}}}}
(:require [cljs.test :refer [async deftest is testing use-fixtures are]]
(:require [cljs.test :refer [async deftest use-fixtures are]]
[frontend.handler.export :as export]
[frontend.db.config :refer [test-db] :as config]
[frontend.db.config :as config]
[frontend.handler.repo :as repo-handler]
[frontend.fixtures :as fixtures]
[frontend.state :as state]
[clojure.string :as string]
[promesa.core :as p]))
(def test-files

View File

@ -21,7 +21,7 @@
(p/then
(extract x)
(fn [v]
(is (= y))
(is (= y v))
(done)))))
(deftest test-extract-blocks-pages

View File

@ -1,8 +1,5 @@
(ns frontend.modules.outliner.core-test
(:require [cljs-run-test :refer [run-test]]
[cljs.test :refer [deftest is run-tests use-fixtures] :as test]
[datascript.core :as d]
[frontend.core-test :as core-test]
(:require [cljs.test :refer [deftest is use-fixtures testing] :as test]
[frontend.fixtures :as fixtures]
[frontend.modules.outliner.core :as outliner-core]
[frontend.modules.outliner.datascript :as outliner-ds]
@ -78,7 +75,7 @@
(prn (d/pull @(core-test/get-current-conn) '[*] [:block/uuid i])))))
(deftest test-insert-node-as-first-child
"
(testing "
Insert a node between 6 and 9.
[1 [[2 [[18] ;; add
[3 [[4]
@ -92,19 +89,19 @@
[15]]]
[16 [[17]]]]]
"
(build-db-records node-tree)
(let [new-node (build-block 18 nil nil)
parent-node (build-block 2 1 1)]
(outliner-ds/auto-transact!
[state (outliner-ds/new-outliner-txs-state)] nil
(outliner-core/insert-node-as-first-child state new-node parent-node))
(let [children-of-2 (->> (build-block 2 1 1)
(tree/-get-children)
(mapv #(-> % :data :block/uuid)))]
(is (= [18 3 6 9] children-of-2)))))
(build-db-records node-tree)
(let [new-node (build-block 18 nil nil)
parent-node (build-block 2 1 1)]
(outliner-ds/auto-transact!
[state (outliner-ds/new-outliner-txs-state)] nil
(outliner-core/insert-node-as-first-child state new-node parent-node))
(let [children-of-2 (->> (build-block 2 1 1)
(tree/-get-children)
(mapv #(-> % :data :block/uuid)))]
(is (= [18 3 6 9] children-of-2))))))
(deftest test-insert-node-as-sibling
"
(testing "
Insert a node between 6 and 9.
[1 [[2 [[3 [[4]
[5]]]
@ -117,20 +114,20 @@
[15]]]
[16 [[17]]]]]
"
(build-db-records node-tree)
(let [new-node (build-block 18 nil nil)
left-node (build-block 6 2 3)]
(outliner-ds/auto-transact!
[state (outliner-ds/new-outliner-txs-state)] nil
(outliner-core/insert-node-as-sibling state new-node left-node))
(let [children-of-2 (->> (build-block 2 1 1)
(tree/-get-children)
(mapv #(-> % :data :block/uuid)))]
(is (= [3 6 18 9] children-of-2)))))
(build-db-records node-tree)
(let [new-node (build-block 18 nil nil)
left-node (build-block 6 2 3)]
(outliner-ds/auto-transact!
[state (outliner-ds/new-outliner-txs-state)] nil
(outliner-core/insert-node-as-sibling state new-node left-node))
(let [children-of-2 (->> (build-block 2 1 1)
(tree/-get-children)
(mapv #(-> % :data :block/uuid)))]
(is (= [3 6 18 9] children-of-2))))))
(deftest test-delete-node
"
Inert a node between 6 and 9.
(testing "
Insert a node between 6 and 9.
[1 [[2 [[3 [[4]
[5]]]
[6 [[7 [[8]]]]] ;; delete 6
@ -141,17 +138,17 @@
[15]]]
[16 [[17]]]]]
"
(build-db-records node-tree)
(let [node (build-block 6 2 3)]
(outliner-core/delete-node node true)
(let [children-of-2 (->> (build-block 2 1 1)
(tree/-get-children)
(mapv #(-> % :data :block/uuid)))]
(is (= [3 9] children-of-2)))))
(build-db-records node-tree)
(let [node (build-block 6 2 3)]
(outliner-core/delete-node node true)
(let [children-of-2 (->> (build-block 2 1 1)
(tree/-get-children)
(mapv #(-> % :data :block/uuid)))]
(is (= [3 9] children-of-2))))))
(deftest test-move-subtree-as-sibling
"
(testing "
Move 3 between 14 and 15.
[1 [[2 [[6 [[7 [[8]]]]]
[9 [[10]
@ -163,21 +160,21 @@
[15]]]
[16 [[17]]]]]
"
(build-db-records node-tree)
(let [node (build-block 3 2 2)
target-node (build-block 14 12 13)]
(outliner-core/move-subtree node target-node true)
(let [old-parent's-children (->> (build-block 2 1 1)
(tree/-get-children)
(mapv #(-> % :data :block/uuid)))
new-parent's-children (->> (build-block 12 1 2)
(tree/-get-children)
(mapv #(-> % :data :block/uuid)))]
(is (= [6 9] old-parent's-children))
(is (= [13 14 3 15] new-parent's-children)))))
(build-db-records node-tree)
(let [node (build-block 3 2 2)
target-node (build-block 14 12 13)]
(outliner-core/move-subtree node target-node true)
(let [old-parent's-children (->> (build-block 2 1 1)
(tree/-get-children)
(mapv #(-> % :data :block/uuid)))
new-parent's-children (->> (build-block 12 1 2)
(tree/-get-children)
(mapv #(-> % :data :block/uuid)))]
(is (= [6 9] old-parent's-children))
(is (= [13 14 3 15] new-parent's-children)))))
(deftest test-move-subtree-as-first-child
"
(deftest test-move-subtree-as-first-child
(testing "
Move 3 as first child of 12.
[1 [[2 [[6 [[7 [[8]]]]]
@ -190,22 +187,22 @@
[15]]]
[16 [[17]]]]]
"
(build-db-records node-tree)
(let [node (build-block 3 2 2)
target-node (build-block 12 1 2)]
(outliner-core/move-subtree node target-node false)
(let [old-parent's-children (->> (build-block 2 1 1)
(tree/-get-children)
(mapv #(-> % :data :block/uuid)))
new-parent's-children (->> (build-block 12 1 2)
(tree/-get-children)
(mapv #(-> % :data :block/uuid)))]
(is (= [6 9] old-parent's-children))
(is (= [3 13 14 15] new-parent's-children)))))
(build-db-records node-tree)
(let [node (build-block 3 2 2)
target-node (build-block 12 1 2)]
(outliner-core/move-subtree node target-node false)
(let [old-parent's-children (->> (build-block 2 1 1)
(tree/-get-children)
(mapv #(-> % :data :block/uuid)))
new-parent's-children (->> (build-block 12 1 2)
(tree/-get-children)
(mapv #(-> % :data :block/uuid)))]
(is (= [6 9] old-parent's-children))
(is (= [3 13 14 15] new-parent's-children)))))))
(deftest test-indent-nodes
"
(testing "
[1 [[2 [[3
[[4]
[5]
@ -217,17 +214,17 @@
[15]]]
[16 [[17]]]]]
"
(build-db-records node-tree)
(let [nodes [(build-block 6 2 3)
(build-block 9 2 6)]]
(outliner-core/indent-outdent-nodes nodes true)
(let [children-of-3 (->> (build-block 3)
(tree/-get-children)
(mapv #(-> % :data :block/uuid)))]
(is (= [4 5 6 9] children-of-3)))))
(build-db-records node-tree)
(let [nodes [(build-block 6 2 3)
(build-block 9 2 6)]]
(outliner-core/indent-outdent-nodes nodes true)
(let [children-of-3 (->> (build-block 3)
(tree/-get-children)
(mapv #(-> % :data :block/uuid)))]
(is (= [4 5 6 9] children-of-3))))))
(deftest test-outdent-nodes
"
(testing "
[1 [[2 [[3]
[4] ;; outdent 6, 9
[5]
@ -239,20 +236,20 @@
[15]]]
[16 [[17]]]]]
"
(build-db-records node-tree)
(let [nodes [(build-block 4 3 3)
(build-block 5 3 4)]]
(outliner-core/indent-outdent-nodes nodes false)
(let [children-of-2 (->> (build-block 2)
(tree/-get-children)
(mapv #(-> % :data :block/uuid)))]
(is (= [3 4 5 6 9] children-of-2)))))
(build-db-records node-tree)
(let [nodes [(build-block 4 3 3)
(build-block 5 3 4)]]
(outliner-core/indent-outdent-nodes nodes false)
(let [children-of-2 (->> (build-block 2)
(tree/-get-children)
(mapv #(-> % :data :block/uuid)))]
(is (= [3 4 5 6 9] children-of-2))))))
(comment
(run-test test-outdent-nodes))
(deftest test-delete-nodes
"
(testing "
[1 [[2 [[3 [[4]
[5]]]
;[6 [[7 [[8]]]]] delete 6, 9
@ -264,21 +261,21 @@
[15]]]
[16 [[17]]]]]
"
(build-db-records node-tree)
(let [start-node (build-block 6 2 3)
end-node (build-block 11 9 10)
block-ids [7 8 9 10]]
(outliner-core/delete-nodes start-node end-node block-ids)
(let [children-of-2 (->> (build-block 2)
(tree/-get-children)
(mapv #(-> % :data :block/uuid)))]
(is (= [3] children-of-2)))))
(build-db-records node-tree)
(let [start-node (build-block 6 2 3)
end-node (build-block 11 9 10)
block-ids [7 8 9 10]]
(outliner-core/delete-nodes start-node end-node block-ids)
(let [children-of-2 (->> (build-block 2)
(tree/-get-children)
(mapv #(-> % :data :block/uuid)))]
(is (= [3] children-of-2))))))
(comment
(run-test test-delete-nodes))
(deftest test-move-node
"
(testing "
[1 [[2 [[3 [[4]
[5]]]
[9 [[10] ;; swap 6 and 9
@ -289,19 +286,19 @@
[15]]]
[16 [[17]]]]]
"
(build-db-records node-tree)
(let [node (build-block 9 2 6)]
(outliner-core/move-nodes [node] true)
(let [children-of-2 (->> (build-block 2)
(tree/-get-children)
(mapv #(-> % :data :block/uuid)))]
(is (= [3 9 6] children-of-2)))))
(build-db-records node-tree)
(let [node (build-block 9 2 6)]
(outliner-core/move-nodes [node] true)
(let [children-of-2 (->> (build-block 2)
(tree/-get-children)
(mapv #(-> % :data :block/uuid)))]
(is (= [3 9 6] children-of-2))))))
(comment
(run-test test-move-node))
(deftest test-insert-nodes
"
(testing "
add [18 [19 20] 21] after 6
[1 [[2 [[3 [[4]
@ -314,23 +311,23 @@
[15]]]
[16 [[17]]]]]
"
(build-db-records node-tree)
(let [new-nodes-tree [(build-block 18)
[(build-block 19)
(build-block 20)]
(build-block 21)]
target-node (build-block 6 2 3)]
(outliner-core/insert-nodes
new-nodes-tree target-node true)
(let [children-of-2 (->> (build-block 2)
(tree/-get-children)
(mapv #(-> % :data :block/uuid)))]
(is (= [3 6 18 21 9] children-of-2)))
(build-db-records node-tree)
(let [new-nodes-tree [(build-block 18)
[(build-block 19)
(build-block 20)]
(build-block 21)]
target-node (build-block 6 2 3)]
(outliner-core/insert-nodes
new-nodes-tree target-node true)
(let [children-of-2 (->> (build-block 2)
(tree/-get-children)
(mapv #(-> % :data :block/uuid)))]
(is (= [3 6 18 21 9] children-of-2)))
(let [children-of-18 (->> (build-block 18)
(tree/-get-children)
(mapv #(-> % :data :block/uuid)))]
(is (= [19 20] children-of-18)))))
(let [children-of-18 (->> (build-block 18)
(tree/-get-children)
(mapv #(-> % :data :block/uuid)))]
(is (= [19 20] children-of-18))))))
(comment
(run-test test-insert-nodes))

View File

@ -1,6 +1,5 @@
(ns frontend.modules.outliner.ds-test
(:require [cljs-run-test :refer [run-test]]
[cljs.test :refer [deftest is use-fixtures] :as test]
(:require [cljs.test :refer [deftest is use-fixtures] :as test]
[frontend.fixtures :as fixtures]
[frontend.modules.outliner.datascript :as ds]))

View File

@ -22,14 +22,14 @@
(let [new-component (update component :watches conj react-ref)]
(swap! react-components assoc comp-key new-component)
(add-watch react-ref comp-key
(fn [_key _atom old-state new-state]
(when-not (= old-state new-state)
(let [root-info (get-in @react-components [comp-key :root-info])]
(let [{:keys [f comp-key]} root-info]
(binding [*with-key* comp-key
*root-info* root-info]
(let [component (get @react-components comp-key)]
(reset! (:result component) (f)))))))))))
(fn [_key _atom old-state new-state]
(when-not (= old-state new-state)
(let [root-info (get-in @react-components [comp-key :root-info])
{:keys [f comp-key]} root-info]
(binding [*with-key* comp-key
*root-info* root-info]
(let [component (get @react-components comp-key)]
(reset! (:result component) (f))))))))))
@react-ref)
;; Sometime react is not used in component by accident, return the val.
@ -74,5 +74,3 @@
(let [result# ~@body]
(reset! react-components {})
result#))))

View File

@ -2,7 +2,7 @@
;; namespace local config for r/defc tests
{:clj-kondo/config {:linters {:inline-def {:level :off}}}}
(:require [frontend.react :as r]
[cljs.test :refer [deftest is are testing use-fixtures run-tests]]
[cljs.test :refer [deftest is use-fixtures]]
[frontend.fixtures :as fixtures]))
(use-fixtures :each
@ -62,4 +62,4 @@
(reset! b 4)
(is (= 10 @out-result)))))
(is (= 10 @out-result)))))

View File

@ -36,7 +36,7 @@
(ct.react/react-card
(graph)))
(defn- random-graph
(defn random-graph
[n]
(let [nodes (for [i (range 0 n)]
{:id (str i)