fix: lint warnings

pull/10438/head
Tienson Qin 2023-10-08 19:13:17 +08:00
parent 7ed5b551d9
commit 307258343e
34 changed files with 168 additions and 209 deletions

View File

@ -49,6 +49,7 @@ frontend.mobile.util/get-idevice-statusbar-height
;; Used in macro
frontend.modules.outliner.datascript/transact!
frontend.modules.outliner.core/*transaction-opts*
frontend.modules.outliner.core/*transaction-args*
;; Referenced in comment
frontend.page/route-view
;; placeholder fn
@ -89,3 +90,5 @@ frontend.state/get-current-edit-block-and-position
frontend.db.model/get-all-classes
;; Repl fn
frontend.db.sync/export-as-blocks
;; Initial loaded
frontend.ui/_emoji-init-data

View File

@ -2,7 +2,6 @@
"System-component-like ns that defines listeners by event name to receive ipc
messages from electron's main process"
(:require [cljs-bean.core :as bean]
[datascript.core :as d]
[dommy.core :as dom]
[electron.ipc :as ipc]
[frontend.db :as db]

View File

@ -226,7 +226,7 @@
(remove nil?)
(util/distinct-by-last-wins first)))
(defn commands-map
(defn ^:large-vars/cleanup-todo commands-map
[get-page-ref-text]
(let [db? (config/db-based-graph? (state/get-current-repo))
embed-page (if db? db-based-embed-page file-based-embed-page)

View File

@ -63,7 +63,7 @@
[frontend.util.clock :as clock]
[frontend.util.drawer :as drawer]
[frontend.handler.file-based.property :as file-property]
[frontend.handler.file-based.property.util :as property]
[frontend.handler.file-based.property.util :as property-util]
[frontend.util.text :as text-util]
[goog.dom :as gdom]
[goog.object :as gobj]
@ -75,15 +75,13 @@
[logseq.graph-parser.util :as gp-util]
[logseq.graph-parser.util.block-ref :as block-ref]
[logseq.graph-parser.util.page-ref :as page-ref]
[logseq.graph-parser.whiteboard :as gp-whiteboard]
[logseq.shui.core :as shui]
[medley.core :as medley]
[promesa.core :as p]
[reitit.frontend.easy :as rfe]
[rum.core :as rum]
[shadow.loader :as loader]
[logseq.common.path :as path]
[clojure.data :as data]))
[logseq.common.path :as path]))
@ -1565,7 +1563,7 @@
(hiccups.core/html)
(security/sanitize-html))))
(defn inline
(defn ^:large-vars/cleanup-todo inline
[{:keys [html-export?] :as config} item]
(match item
[(:or "Plain" "Spaces") s]
@ -2064,7 +2062,7 @@
(rum/defc properties-cp
[config {:block/keys [pre-block?] :as block}]
(let [ordered-properties
(property/get-visible-ordered-properties (:block/properties block)
(property-util/get-visible-ordered-properties (:block/properties block)
(:block/properties-order block)
{:pre-block? pre-block?
:page-id (:db/id (:block/page block))})]
@ -2311,7 +2309,7 @@
[config {:block/keys [uuid content properties scheduled deadline format pre-block?] :as block} edit-input-id block-id slide? selected?]
(let [repo (state/get-current-repo)
content (or (:block/original-name block)
(property/remove-built-in-properties format content))
(property-util/remove-built-in-properties format content))
{:block/keys [title body] :as block} (if (:block/title block) block
(merge block (block/parse-title-and-body uuid format pre-block? content)))
collapsed? (util/collapsed? block)
@ -2777,7 +2775,8 @@
(= (:id config)
(str (:block/uuid block)))))
(defn- build-config [config block {:keys [navigating-block navigated?]}]
(defn- build-config
[config block {:keys [navigating-block navigated?]}]
(cond-> config
navigated?
(assoc :id (str navigating-block))
@ -2796,7 +2795,7 @@
(block-handler/attach-order-list-state block)
(nil? (:level config))
(assoc config :level 0)))
(assoc :level 0)))
(defn- build-block [config block* {:keys [navigating-block navigated?]}]
(let [linked-block (:block/link (db/entity (:db/id block*)))

View File

@ -3,14 +3,12 @@
[cljs-bean.core :as bean]
["@dnd-kit/sortable" :refer [useSortable arrayMove SortableContext sortableKeyboardCoordinates verticalListSortingStrategy] :as sortable]
["@dnd-kit/utilities" :refer [CSS]]
["@dnd-kit/core" :refer [DndContext closestCenter KeyboardSensor PointerSensor useSensor useSensors DragOverlay]]
["react-dom" :refer [createPortal]]
[frontend.rum :as r]
[frontend.util :as util]))
["@dnd-kit/core" :refer [DndContext closestCenter KeyboardSensor PointerSensor useSensor useSensors]]
[frontend.rum :as r]))
(def dnd-context (r/adapt-class DndContext))
(def sortable-context (r/adapt-class SortableContext))
(def drag-overlay (r/adapt-class DragOverlay))
;; (def drag-overlay (r/adapt-class DragOverlay))
(rum/defc sortable-item
[props children]

View File

@ -408,7 +408,7 @@
{:modal-class (util/hiccup->class
"origin-top-right.absolute.left-0.mt-2.rounded-md.shadow-lg")}))))
(rum/defcs page-title < rum/reactive
(rum/defcs ^:large-vars/cleanup-todo page-title < rum/reactive
(rum/local false ::edit?)
(rum/local "" ::input-value)
(rum/local false ::hover?)

View File

@ -276,7 +276,7 @@
(update-property! property @*property-name @*property-schema)))))))
dropdown-opts)]))
(rum/defcs property-config <
(rum/defcs ^:large-vars/cleanup-todo property-config <
rum/reactive
(rum/local nil ::property-name)
(rum/local nil ::property-schema)
@ -463,7 +463,7 @@
(rum/defcs property-input < rum/reactive
(rum/local false ::show-new-property-config?)
shortcut/disable-all-shortcuts
[state entity *property-key *property-value {:keys [class-schema? page-configure? in-block-container?]
[state entity *property-key *property-value {:keys [class-schema? _page-configure? in-block-container?]
:as opts}]
(let [*show-new-property-config? (::show-new-property-config? state)
entity-properties (->> (keys (:block/properties entity))
@ -533,7 +533,7 @@
state
:on-hide (fn [] (property-handler/set-editing-new-property! nil))
:node (js/document.getElementById "edit-new-property"))))
[state block edit-input-id properties new-property? opts]
[state block edit-input-id new-property? opts]
[:div.ls-new-property
(let [*property-key (::property-key state)
*property-value (::property-value state)]
@ -699,7 +699,7 @@
(when-not @*hide?
(properties-section block hidden-properties opts))]))
(rum/defcs properties-area < rum/reactive
(rum/defcs ^:large-vars/cleanup-todo properties-area < rum/reactive
(rum/local false ::hover?)
{:init (fn [state]
(assoc state ::blocks-container-id (or (:blocks-container-id (last (:rum/args state)))
@ -788,7 +788,7 @@
(hidden-properties block full-hidden-properties opts))
(when (or new-property? (not in-block-container?))
(new-property block edit-input-id properties new-property? opts))
(new-property block edit-input-id new-property? opts))
(when (and (seq class->properties) (not one-class?))
(let [page-cp (:page-cp opts)]

View File

@ -33,7 +33,7 @@
[:div.tip.flex
[:code.opacity-20.bg-transparent (:id result)]])]))
(rum/defcs select
(rum/defcs ^:large-vars/cleanup-todo select
"Provides a select dropdown powered by a fuzzy search. Takes the following options:
* :items - Vec of things to select from. Assumes a vec of maps with :value key by default. Required option
* :limit - Limit number of items to search. Default is 100

View File

@ -276,7 +276,6 @@
(page/page-title page-name
[:span.text-lg
(ui/icon "whiteboard" {:extension? true})]
(get-page-display-name page-name)
{:*configure-show? (atom false)})]
[:div.whiteboard-page-refs

View File

@ -64,9 +64,8 @@
(goog-define ENABLE-RTC-SYNC-PRODUCTION false)
(if ENABLE-RTC-SYNC-PRODUCTION
(do (def RTC-WS-URL "wss://ws.logseq.com/rtc-sync?useruuid=%s"))
(do (def RTC-WS-URL "wss://ws-dev.logseq.com/rtc-sync?useruuid=%s"))
)
(def RTC-WS-URL "wss://ws.logseq.com/rtc-sync?useruuid=%s")
(def RTC-WS-URL "wss://ws-dev.logseq.com/rtc-sync?useruuid=%s"))
;; Feature flags
;; =============
@ -311,13 +310,6 @@
(+ 3 (count label))]
["" 0]))
(defn properties-wrapper-pattern
[format]
(case format
:markdown
"---\n%s\n---"
"%s"))
(defn get-file-extension
[format]
(case (keyword format)

View File

@ -38,10 +38,9 @@
(do
(swap! *ids disj first-child-id)
[first-child-id])
(do
(let [id (first @*ids)]
(swap! *ids disj id)
[id]))))
[id])))
section-with-left (or
(when-let [left-id (:db/id (:block/left (db/entity (first current-section))))]
(swap! *ids disj left-id)

View File

@ -1533,7 +1533,7 @@ independent of format as format specific heading characters are stripped"
:in $ % ?parent
:where
(namespace ?parent ?c)
(or
(or-join [?object ?c]
[?object :block/tags ?parent]
[?object :block/tags ?c])]
(conn/get-db repo)

View File

@ -1,4 +1,5 @@
(ns frontend.db.rtc.const
"RTC constants/schema"
(:require [malli.util :as mu]
[malli.core :as m]
[malli.transform :as mt]))

View File

@ -285,7 +285,7 @@
(prn :push-data-from-ws push-data-from-ws)))
(def transit-w (transit/writer :json))
(defn- local-ops->remote-ops
(defn- ^:large-vars/cleanup-todo local-ops->remote-ops
"when verbose?, update ops will contain more attributes"
[repo sorted-ops _verbose?]
(let [[remove-block-uuid-set move-block-uuid-set update-page-uuid-set remove-page-uuid-set update-block-uuid->attrs]

View File

@ -5,7 +5,7 @@
(:require [frontend.ui :as ui]
[rum.core :as rum]
[frontend.db.rtc.core :as rtc-core]
[cljs.core.async :as async :refer [go <! chan go-loop]]
[cljs.core.async :as async :refer [go <!]]
[cljs.core.async.interop :refer [p->c]]
[frontend.db.rtc.op :as op]
[frontend.state :as state]
@ -16,7 +16,7 @@
[frontend.handler.notification :as notification]))
(defonce debug-state (atom nil))
(def debug-graph-uuid "c9d334d8-977a-428c-af53-25261de27db5")
;; (def debug-graph-uuid "c9d334d8-977a-428c-af53-25261de27db5")
(defn- <start-rtc

View File

@ -5,13 +5,11 @@
(:require [frontend.db.conn :as conn]
[datascript.core :as d]
[frontend.db.rtc.ws :refer [<send!]]
[frontend.state :as state]
[cljs.core.async :as async :refer [chan go <!]]
[cljs.core.async :as async :refer [go <!]]
[cljs.core.async.interop :refer [p->c]]
[cljs-http.client :as http]
[cognitect.transit :as transit]
[logseq.db.schema :as db-schema]
[logseq.db.sqlite.util :as sqlite-util]
[frontend.persist-db :as persist-db]
[frontend.db.rtc.op :as op]
[logseq.outliner.pipeline :as outliner-pipeline]))

View File

@ -1,4 +1,5 @@
(ns frontend.db.rtc.macro)
(ns frontend.db.rtc.macro
"Macros that are used for rtc")
(def ^:private magic-str "YBTFRD")

View File

@ -1,4 +1,5 @@
(ns frontend.db.rtc.op
"TODO" ; @zhiyuan
(:require [malli.core :as m]
[frontend.db.rtc.ops-idb-store :as op-store]
[promesa.core :as p]
@ -90,6 +91,7 @@
[repo]
(op-store/<get-graph-uuid repo))
(comment
(defn <get-local-tx
[repo]
(op-store/<get-local-tx repo))
(op-store/<get-local-tx repo)))

View File

@ -67,7 +67,8 @@
(p/let [store (ensure-store repo)]
(idb-keyval/get "graph-uuid" store)))
(comment
(defn <get-local-tx
[repo]
(p/let [store (ensure-store repo)]
(idb-keyval/get "local-tx" store)))
(idb-keyval/get "local-tx" store))))

View File

@ -1,11 +1,11 @@
(ns frontend.db.rtc.ws
"TODO" ; @zhiyuan
(:require-macros
[frontend.db.rtc.macro :refer [with-sub-data-from-ws get-req-id get-result-ch]])
(:require [frontend.config :as config]
[frontend.util :as util]
[frontend.db.rtc.const :as rtc-const]
[cljs.core.async :as async :refer [<! >! chan go go-loop offer!
poll! timeout]]))
[cljs.core.async :as async :refer [<! chan go offer!]]))
(def ws-addr config/RTC-WS-URL)

View File

@ -10,8 +10,7 @@
[logseq.graph-parser.util :as gp-util]
[logseq.graph-parser.text :as text]
[logseq.graph-parser.block :as gp-block]
[clojure.walk :as walk]
[frontend.util :as util]))
[clojure.walk :as walk]))
(defonce anchorLink (gobj/get Mldoc "anchorLink"))
(defonce parseOPML (gobj/get Mldoc "parseOPML"))
@ -99,8 +98,8 @@
(defn extract-plain
"Extract plain elements including page refs"
[content]
(let [ast (->edn content (gp-mldoc/default-config :markdown))]
(let [*result (atom [])]
(let [ast (->edn content (gp-mldoc/default-config :markdown))
*result (atom [])]
(walk/prewalk
(fn [f]
(cond
@ -132,7 +131,7 @@
f))
ast)
(-> (string/trim (apply str @*result))
text/page-ref-un-brackets!))))
text/page-ref-un-brackets!)))
(defn extract-tags
"Extract tags from content"
@ -156,15 +155,3 @@
(->> @*result
(remove string/blank?)
(distinct))))
(defn content-without-tags
"Remove tags from content"
[content tags]
(->
(reduce
(fn [content tag]
(let [tag' (str "#" tag)]
(string/replace content tag' "")))
content
tags)
(string/trim)))

View File

@ -45,7 +45,6 @@
[promesa.core :as p]
[frontend.mobile.core :as mobile]
[frontend.db.listener :as db-listener]
[frontend.db.rtc.core :as rtc-core]
[cljs-bean.core :as bean]))
(defn- set-global-error-notification!

View File

@ -37,7 +37,7 @@
(defn will-unmount
[state]
(let [{:keys [block value]} (get-state)]
(let [{:keys [value]} (get-state)]
(editor-handler/clear-when-saved!)
(when (and
(not (contains? #{:insert :indent-outdent :auto-save :undo :redo :delete} (state/get-editor-op)))

View File

@ -55,7 +55,6 @@
[frontend.handler.property :as property-handler]
[frontend.handler.whiteboard :as whiteboard-handler]
[frontend.handler.web.nfs :as nfs-handler]
[frontend.handler.editor :as editor-handler]
[frontend.mobile.core :as mobile]
[frontend.mobile.graph-picker :as graph-picker]
[frontend.mobile.util :as mobile-util]

View File

@ -301,7 +301,7 @@
@(:editor/create-page? @state/state))]
(when id
;; Retract attributes to prepare for tx which rewrites block attributes
(let [retract-attributes (if db-based?
(let [retract-attributes (when db-based?
(remove #{:block/properties :block/properties-order} db-schema/retract-attributes))]
(swap! txs-state (fn [txs]
(vec
@ -588,8 +588,8 @@
(defn- blocks-with-ordered-list-props
[blocks target-block sibling?]
(let [target-block (if sibling? target-block (some-> target-block :db/id db/pull block tree/-get-down :data))]
(let [list-type-fn (fn [block] (pu/get-property block :logseq.order-list-type))
(let [target-block (if sibling? target-block (some-> target-block :db/id db/pull block tree/-get-down :data))
list-type-fn (fn [block] (pu/get-property block :logseq.order-list-type))
k (if (config/db-based-graph? (state/get-current-repo))
(:block/uuid (db/entity [:block/name "logseq.order-list-type"]))
:logseq.order-list-type)]
@ -604,7 +604,7 @@
(not (config/db-based-graph? (state/get-current-repo)))
(assoc :block/content (property-util/insert-property format content :logseq.order-list-type list-type))))
blocks)
blocks))))
blocks)))
;;; ### insert-blocks, delete-blocks, move-blocks
@ -1099,7 +1099,7 @@
see also `frontend.modules.outliner.transaction/transact!`"
nil)
(def ^:private ^:dynamic *transaction-args*
(def ^:private ^:dynamic #_:clj-kondo/ignore *transaction-args*
"Stores transaction args which can be fetched in all op-transact functions."
nil)

View File

@ -78,7 +78,7 @@
txs))
(defn replace-ref-with-content
[txs repo opts]
[txs opts]
(if (and (= :delete-blocks (:outliner-op opts))
(empty? (:uuid-changed opts)))
(let [retracted-block-ids (->> (keep (fn [tx]
@ -153,7 +153,7 @@
(and (= :delete-blocks (:outliner-op opts))
(empty? (:uuid-changed opts)))
(replace-ref-with-content repo opts)
(replace-ref-with-content opts)
true
(distinct))]
@ -171,7 +171,7 @@
rs (db/transact! repo txs (assoc opts :outliner/transact? true))
tx-id (get-tx-id rs)]
;; TODO: disable this when db is stable
;; (when config/dev? (validate-db! rs))
(when config/dev? (validate-db! rs))
(state/update-state! :history/tx->editor-cursor
(fn [m] (assoc m tx-id before-editor-cursor)))

View File

@ -1,4 +1,5 @@
(ns frontend.persist-db.browser
"Browser db persist"
(:require ["comlink" :as Comlink]
[cljs-time.coerce :as tc]
[cljs-time.core :as t]

View File

@ -7,7 +7,7 @@
["react-tippy" :as react-tippy]
["react-transition-group" :refer [CSSTransition TransitionGroup]]
["@emoji-mart/data" :as emoji-data]
["@emoji-mart/react" :as Picker]
;; ["@emoji-mart/react" :as Picker]
["emoji-mart" :as emoji-mart]
[camel-snake-kebab.core :as csk]
[cljs-bean.core :as bean]
@ -17,11 +17,9 @@
[frontend.components.svg :as svg]
[frontend.config :as config]
[frontend.context.i18n :refer [t]]
[frontend.db :as db]
[frontend.db-mixins :as db-mixins]
[frontend.handler.notification :as notification]
[frontend.handler.plugin :as plugin-handler]
[frontend.handler.route :as route-handler]
[frontend.mixins :as mixins]
[frontend.mobile.util :as mobile-util]
[frontend.modules.shortcut.config :as shortcut-config]
@ -52,13 +50,7 @@
(def ReactTweetEmbed (r/adapt-class react-tweet-embed))
(def useInView (gobj/get react-intersection-observer "useInView"))
(defonce _emoji-init-data ((gobj/get emoji-mart "init") #js {:data emoji-data}))
(def EmojiPicker (r/adapt-class (gobj/get Picker "default")))
(defn reset-ios-whole-page-offset!
[]
(and (util/ios?)
(util/safari?)
(js/window.scrollTo 0 0)))
;; (def EmojiPicker (r/adapt-class (gobj/get Picker "default")))
(defonce icon-size (if (mobile-util/native-platform?) 26 20))
@ -1172,15 +1164,8 @@
inViewState (useInView #js {:initialInView initial-state
:rootMargin (str root-margin "px")
:triggerOnce trigger-once?
:onChange (fn [in-view? entry]
(set-visible! in-view?)
;; (let [self-top (.-top (.-boundingClientRect entry))]
;; (when (or (and (not visible?) in-view?)
;; ;; hide only the components below the current top for better ux
;; ;; visible?
;; (and visible? (not in-view?) (> self-top root-margin)))
;; (set-visible! in-view?)))
)})
:onChange (fn [in-view? _entry]
(set-visible! in-view?))})
ref (.-ref inViewState)]
(lazy-visible-inner visible? content-fn ref fade-in?))))
@ -1240,6 +1225,7 @@
:intent "link"
:small? true)]]))
(comment
(rum/defc emoji-picker
[opts]
(EmojiPicker. (assoc opts :data emoji-data)))
(EmojiPicker. (assoc opts :data emoji-data))))

View File

@ -68,6 +68,7 @@
#?(:cljs (defonce convert-to-letters utils/convertToLetters))
(defn string-join-path
#_:clj-kondo/ignore
"Replace all `strings/join` used to construct paths with this function to reduce lint output.
https://github.com/logseq/logseq/pull/8679"
[parts]

View File

@ -265,7 +265,6 @@
:settings-page/edit-global-config-edn "Modifier le fichier global config.edn"
:settings-page/edit-setting "Modifier"
:settings-page/enable-all-pages-public "Toutes les pages publiques lors de la publication"
:settings-page/enable-block-time "Horodatage de bloc"
:settings-page/enable-flashcards "Cartes mémoire"
:settings-page/enable-shortcut-tooltip "Activer les astuces sur les raccourcis"
:settings-page/enable-tooltip "Astuces"

View File

@ -309,7 +309,6 @@
:settings-page/enable-journals "Jurnal"
:settings-page/enable-all-pages-public "Semua halaman menjadi publik saat dipublikasikan"
:settings-page/home-default-page "Atur halaman beranda default"
:settings-page/enable-block-time "Waktu blok"
:settings-page/clear-cache "Hapus cache"
:settings-page/clear "Hapus"
:settings-page/clear-cache-warning "Menghapus cache akan menghapus grafik yang terbuka. Anda akan kehilangan perubahan yang belum disimpan."

View File

@ -3,13 +3,10 @@
[datascript.core :as d]
[frontend.core-test :as core-test]
[frontend.test.fixtures :as fixtures]
[frontend.db.fix :as db-fix]
[frontend.test.helper :as test-helper]))
[frontend.db.fix :as db-fix]))
(use-fixtures :each fixtures/reset-db)
(def test-db test-helper/test-db)
(defonce init-conflicts
[{:block/uuid "1"}
{:block/uuid "2"

View File

@ -2,7 +2,6 @@
(:require [clojure.test :refer [is use-fixtures testing deftest]]
[frontend.test.helper :as test-helper :include-macros true :refer [deftest-async]]
[frontend.test.node-helper :as test-node-helper]
[frontend.test.fixtures :as fixtures]
[frontend.test.node-fixtures :as node-fixtures]
[frontend.handler.plugin-config :as plugin-config-handler]
[frontend.handler.global-config :as global-config-handler]

View File

@ -1,17 +1,17 @@
(ns frontend.util.property-test
(:require [cljs.test :refer [are deftest testing]]
[frontend.handler.file-based.property.util :as property]))
[frontend.handler.file-based.property.util :as property-util]))
(deftest remove-id-property
(testing "org"
(are [x y] (= (property/remove-id-property :org x) y)
(are [x y] (= (property-util/remove-id-property :org x) y)
"hello\n:PROPERTIES:\n:id: f9873a81-07b9-4246-b910-53a6f5ec7e04\n:END:\n"
"hello\n:PROPERTIES:\n:END:"
"hello\n:PROPERTIES:\n:id: f9873a81-07b9-4246-b910-53a6f5ec7e04\na: b\n:END:\n"
"hello\n:PROPERTIES:\na: b\n:END:"))
(testing "markdown"
(are [x y] (= (property/remove-id-property :markdown x) y)
(are [x y] (= (property-util/remove-id-property :markdown x) y)
"hello\nid:: f9873a81-07b9-4246-b910-53a6f5ec7e04"
"hello"
@ -23,7 +23,7 @@
(deftest test-remove-empty-properties
(testing "remove properties if it is empty. Available in orgmode"
(are [x y] (= (property/remove-empty-properties x) y)
(are [x y] (= (property-util/remove-empty-properties x) y)
"* TODO properties demo\nabcd"
"* TODO properties demo\nabcd"
@ -39,142 +39,142 @@
(deftest test-remove-properties
(testing "properties with non-blank lines"
(are [x y] (= x y)
(property/remove-properties :org "** hello\n:PROPERTIES:\n:x: y\n:END:\n")
(property-util/remove-properties :org "** hello\n:PROPERTIES:\n:x: y\n:END:\n")
"** hello"
(property/remove-properties :org "** hello\n:PROPERTIES:\n:x: y\na:b\n:END:\n")
(property-util/remove-properties :org "** hello\n:PROPERTIES:\n:x: y\na:b\n:END:\n")
"** hello"
(property/remove-properties :markdown "** hello\nx:: y\na:: b\n")
(property-util/remove-properties :markdown "** hello\nx:: y\na:: b\n")
"** hello"
(property/remove-properties :markdown "** hello\nx:: y\na::b\n")
(property-util/remove-properties :markdown "** hello\nx:: y\na::b\n")
"** hello"))
(testing "properties with blank lines"
(are [x y] (= x y)
(property/remove-properties :org "** hello\n:PROPERTIES:\n\n:x: y\n:END:\n")
(property-util/remove-properties :org "** hello\n:PROPERTIES:\n\n:x: y\n:END:\n")
"** hello"
(property/remove-properties :org "** hello\n:PROPERTIES:\n:x: y\n\na:b\n:END:\n")
(property-util/remove-properties :org "** hello\n:PROPERTIES:\n:x: y\n\na:b\n:END:\n")
"** hello"))
(testing "invalid-properties"
(are [x y] (= x y)
(property/remove-properties :markdown "hello\nnice\nfoo:: bar")
(property-util/remove-properties :markdown "hello\nnice\nfoo:: bar")
"hello\nnice\nfoo:: bar"
(property/remove-properties :markdown "hello\nnice\nfoo:: bar\ntest")
(property-util/remove-properties :markdown "hello\nnice\nfoo:: bar\ntest")
"hello\nnice\nfoo:: bar\ntest"
(property/remove-properties :markdown "** hello\nx:: y\n\na:: b\n")
(property-util/remove-properties :markdown "** hello\nx:: y\n\na:: b\n")
"** hello\n\na:: b")))
(deftest test-get-property-keys
(testing "org mode"
(are [x y] (= x y)
(#'property/get-property-keys :org "hello\n:PROPERTIES:\n:x1: y1\n:x2: y2\n:END:\n")
(#'property-util/get-property-keys :org "hello\n:PROPERTIES:\n:x1: y1\n:x2: y2\n:END:\n")
["X1" "X2"]
(#'property/get-property-keys :org "hello\n:PROPERTIES:\n:END:\n")
(#'property-util/get-property-keys :org "hello\n:PROPERTIES:\n:END:\n")
nil))
(testing "markdown mode"
(are [x y] (= x y)
(#'property/get-property-keys :markdown "hello\nx1:: y1\nx2:: y2\n")
(#'property-util/get-property-keys :markdown "hello\nx1:: y1\nx2:: y2\n")
["X1" "X2"]
(#'property/get-property-keys :markdown "hello\n")
(#'property-util/get-property-keys :markdown "hello\n")
nil)))
(deftest test-insert-property
(are [x y] (= x y)
(property/insert-property :org "hello" "a" "b")
(property-util/insert-property :org "hello" "a" "b")
"hello\n:PROPERTIES:\n:a: b\n:END:"
(property/insert-property :org "hello" "a" false)
(property-util/insert-property :org "hello" "a" false)
"hello\n:PROPERTIES:\n:a: false\n:END:"
(property/insert-property :org "hello\n:PROPERTIES:\n:a: b\n:END:\n" "c" "d")
(property-util/insert-property :org "hello\n:PROPERTIES:\n:a: b\n:END:\n" "c" "d")
"hello\n:PROPERTIES:\n:a: b\n:c: d\n:END:"
(property/insert-property :org "hello\n:PROPERTIES:\n:a: b\n:END:\nworld\n" "c" "d")
(property-util/insert-property :org "hello\n:PROPERTIES:\n:a: b\n:END:\nworld\n" "c" "d")
"hello\n:PROPERTIES:\n:a: b\n:c: d\n:END:\nworld"
(property/insert-property :org "#+BEGIN_QUOTE
(property-util/insert-property :org "#+BEGIN_QUOTE
hello world
#+END_QUOTE" "c" "d")
":PROPERTIES:\n:c: d\n:END:\n#+BEGIN_QUOTE\n hello world\n #+END_QUOTE"
(property/insert-property :org "hello
(property-util/insert-property :org "hello
DEADLINE: <2021-10-25 Mon>
SCHEDULED: <2021-10-25 Mon>" "a" "b")
"hello\nSCHEDULED: <2021-10-25 Mon>\nDEADLINE: <2021-10-25 Mon>\n:PROPERTIES:\n:a: b\n:END:"
(property/insert-property :org "hello
(property-util/insert-property :org "hello
DEADLINE: <2021-10-25 Mon>
SCHEDULED: <2021-10-25 Mon>\n:PROPERTIES:\n:a: b\n:END:\n" "c" "d")
"hello\nDEADLINE: <2021-10-25 Mon>\nSCHEDULED: <2021-10-25 Mon>\n:PROPERTIES:\n:a: b\n:c: d\n:END:"
(property/insert-property :org "hello
(property-util/insert-property :org "hello
DEADLINE: <2021-10-25 Mon>
SCHEDULED: <2021-10-25 Mon>\n:PROPERTIES:\n:a: b\n:END:\nworld\n" "c" "d")
"hello\nDEADLINE: <2021-10-25 Mon>\nSCHEDULED: <2021-10-25 Mon>\n:PROPERTIES:\n:a: b\n:c: d\n:END:\nworld"
(property/insert-property :markdown "hello\na:: b\nworld\n" "c" "d")
(property-util/insert-property :markdown "hello\na:: b\nworld\n" "c" "d")
"hello\na:: b\nc:: d\nworld"
(property/insert-property :markdown "> quote" "c" "d")
(property-util/insert-property :markdown "> quote" "c" "d")
"c:: d\n> quote"
(property/insert-property :markdown "#+BEGIN_QUOTE
(property-util/insert-property :markdown "#+BEGIN_QUOTE
hello world
#+END_QUOTE" "c" "d")
"c:: d\n#+BEGIN_QUOTE\n hello world\n #+END_QUOTE"))
(deftest test-insert-properties
(are [x y] (= x y)
(property/insert-properties :markdown "" {:foo "bar"})
(property-util/insert-properties :markdown "" {:foo "bar"})
"foo:: bar"
(property/insert-properties :markdown "" {"foo" "bar"})
(property-util/insert-properties :markdown "" {"foo" "bar"})
"foo:: bar"
(property/insert-properties :markdown "" {"foo space" "bar"})
(property-util/insert-properties :markdown "" {"foo space" "bar"})
"foo-space:: bar"
(property/insert-properties :markdown "" {:foo #{"bar" "baz"}})
(property-util/insert-properties :markdown "" {:foo #{"bar" "baz"}})
"foo:: [[bar]], [[baz]]"
(property/insert-properties :markdown "" {:foo ["bar" "bar" "baz"]})
(property-util/insert-properties :markdown "" {:foo ["bar" "bar" "baz"]})
"foo:: [[bar]], [[baz]]"
(property/insert-properties :markdown "a\nb\n" {:foo ["bar" "bar" "baz"]})
(property-util/insert-properties :markdown "a\nb\n" {:foo ["bar" "bar" "baz"]})
"a\nfoo:: [[bar]], [[baz]]\nb"
(property/insert-properties :markdown "" {:foo "\"bar, baz\""})
(property-util/insert-properties :markdown "" {:foo "\"bar, baz\""})
"foo:: \"bar, baz\""
(property/insert-properties :markdown "abcd\nempty::" {:id "123" :foo "bar"})
(property-util/insert-properties :markdown "abcd\nempty::" {:id "123" :foo "bar"})
"abcd\nempty::\nid:: 123\nfoo:: bar"
(property/insert-properties :markdown "abcd\nempty:: " {:id "123" :foo "bar"})
(property-util/insert-properties :markdown "abcd\nempty:: " {:id "123" :foo "bar"})
"abcd\nempty:: \nid:: 123\nfoo:: bar"
(property/insert-properties :markdown "abcd\nempty::" {:id "123"})
(property-util/insert-properties :markdown "abcd\nempty::" {:id "123"})
"abcd\nempty::\nid:: 123"
(property/insert-properties :markdown "abcd\nempty::\nanother-empty::" {:id "123"})
(property-util/insert-properties :markdown "abcd\nempty::\nanother-empty::" {:id "123"})
"abcd\nempty::\nanother-empty::\nid:: 123"))
(deftest test-build-properties-str
(are [x y] (= (#'property/build-properties-str :mardown x) y)
(are [x y] (= (#'property-util/build-properties-str :mardown x) y)
{:title "a"}
"title:: a\n"
{:title "a/b/c"}
"title:: a/b/c\n"
{:title "a/b/c" :tags "d,e"}
"title:: a/b/c\ntags:: d,e\n")
(are [x y] (= (#'property/build-properties-str :org x) y)
(are [x y] (= (#'property-util/build-properties-str :org x) y)
{:title "a"}
":PROPERTIES:\n:title: a\n:END:"
{:title "a/b/c"}
@ -185,7 +185,7 @@ SCHEDULED: <2021-10-25 Mon>\n:PROPERTIES:\n:a: b\n:END:\nworld\n" "c" "d")
(deftest test-with-built-in-properties
(let [content "#+BEGIN_QUERY\n{:title \"cool NEXT\"\n :query [:find (pull ?h [*])\n :in $ ?start ?next\n :where\n [?h :block/marker ?marker]\n [(contains? #{\"NOW\" \"LATER\" \"TODO\"} ?marker)]\n [?h :block/ref-pages ?p]\n [?p :block/journal? true]\n [?p :block/journal-day ?d]\n [(> ?d ?start)]\n [(< ?d ?next)]]\n :inputs [:today :7d-after]\n :collapsed? false}\n#+END_QUERY"]
(let [md-property "query-table:: true"]
(are [x y] (= (property/with-built-in-properties {:query-table true} x :markdown) y)
(are [x y] (= (property-util/with-built-in-properties {:query-table true} x :markdown) y)
content
(str md-property "\n" content)
@ -199,7 +199,7 @@ SCHEDULED: <2021-10-25 Mon>\n:PROPERTIES:\n:a: b\n:END:\nworld\n" "c" "d")
(str md-property "\n1. list")))
(let [org-property ":PROPERTIES:\n:query-table: true\n:END:"]
(are [x y] (= (property/with-built-in-properties {:query-table true} x :org) y)
(are [x y] (= (property-util/with-built-in-properties {:query-table true} x :org) y)
content
(str org-property "\n" content)
@ -214,7 +214,7 @@ SCHEDULED: <2021-10-25 Mon>\n:PROPERTIES:\n:a: b\n:END:\nworld\n" "c" "d")
(deftest get-visible-ordered-properties
(testing "basic cases"
(are [x y expected] (= expected (property/get-visible-ordered-properties x y {}))
(are [x y expected] (= expected (property-util/get-visible-ordered-properties x y {}))
;; returns in property order
{:prop "val" :prop2 "val2"} [:prop2 :prop]
[[:prop2 "val2"] [:prop "val"]]
@ -226,7 +226,7 @@ SCHEDULED: <2021-10-25 Mon>\n:PROPERTIES:\n:a: b\n:END:\nworld\n" "c" "d")
nil))
(testing "hidden properties"
(are [x y z expected] (= expected (property/get-visible-ordered-properties x y z))
(are [x y z expected] (= expected (property-util/get-visible-ordered-properties x y z))
;; page block
{:logseq.order-list-type "number" :foo "bar"} [:logseq.order-list-type :foo] {:pre-block false}
[[:foo "bar"]]
@ -235,7 +235,7 @@ SCHEDULED: <2021-10-25 Mon>\n:PROPERTIES:\n:a: b\n:END:\nworld\n" "c" "d")
[[:foo "bar"]]))
(testing "hidden editable properties"
(are [x y z expected] (= expected (property/get-visible-ordered-properties x y z))
(are [x y z expected] (= expected (property-util/get-visible-ordered-properties x y z))
;; page block
{:title "foo"} [:title] {:pre-block? true}
'()