Use core uuid fns where possible

No need for medley or personal util fns when core fns
are available. Also upgraded nbb-logseq to be 1.11.X cljs compatible

- uuid is the same as medley/uuid
- random-uuid is the same as medley/random-uuid
- uuid-string? and uuid is the same as parse-uuid
pull/5369/head
Gabriel Horner 2022-05-17 12:24:46 -04:00 committed by Tienson Qin
parent fec0b755a8
commit 6f68d985bd
17 changed files with 61 additions and 98 deletions

View File

@ -5,7 +5,8 @@
object
;; TODO: Remove parse-* when https://github.com/clj-kondo/clj-kondo/issues/1694 is done
parse-long
parse-double]}
parse-double
parse-uuid]}
;; 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

View File

@ -5,7 +5,7 @@
"main": "static/electron.js",
"devDependencies": {
"@capacitor/cli": "3.2.2",
"@logseq/nbb-logseq": "^0.3.99",
"@logseq/nbb-logseq": "^0.5.103",
"@playwright/test": "^1.19.2",
"@tailwindcss/ui": "0.7.2",
"@types/gulp": "^4.0.7",

View File

@ -707,11 +707,8 @@
(rum/defc block-reference < rum/reactive
db-mixins/query
[config id label]
(when (and
(not (string/blank? id))
(util/uuid-string? id))
(let [block-id (uuid id)
block (db/pull-block block-id)
(when-let [block-id (parse-uuid id)]
(let [block (db/pull-block block-id)
block-type (keyword (get-in block [:block/properties :ls-type]))
hl-type (get-in block [:block/properties :hl-type])
repo (state/get-current-repo)]
@ -1104,10 +1101,7 @@
(when-let [s (-> (string/replace a "((" "")
(string/replace "))" "")
string/trim)]
(when-let [id (and s
(let [s (string/trim s)]
(and (util/uuid-string? s)
(uuid s))))]
(when-let [id (some-> s string/trim parse-uuid)]
(block-embed (assoc config :link-depth (inc link-depth)) id)))
:else ;TODO: maybe collections?
@ -2817,7 +2811,7 @@
:else
(let [language (if (contains? #{"edn" "clj" "cljc" "cljs"} language) "clojure" language)]
(if (:slide? config)
(highlight/highlight (str (medley/random-uuid))
(highlight/highlight (str (random-uuid))
{:class (str "language-" language)
:data-lang language}
code)

View File

@ -363,13 +363,13 @@
e
(custom-context-menu-content))
(and block-id (util/uuid-string? block-id))
(and block-id (parse-uuid block-id))
(let [block (.closest target ".ls-block")]
(when block
(util/select-highlight! [block]))
(common-handler/show-custom-context-menu!
e
(block-context-menu-content target (cljs.core/uuid block-id))))
(block-context-menu-content target (uuid block-id))))
:else
nil))))))

View File

@ -122,8 +122,8 @@
(when page-e
(let [page-name (or (:block/name page-e)
(str (:block/uuid page-e)))
block? (util/uuid-string? page-name)
block-id (and block? (uuid page-name))
block-id (parse-uuid page-name)
block? (boolean block-id)
page-blocks (get-blocks repo page-name block-id)]
(if (empty? page-blocks)
(dummy-block page-name)
@ -317,8 +317,8 @@
(let [current-repo (state/sub :git/current-repo)
repo (or repo current-repo)
page-name (util/page-name-sanity-lc path-page-name)
block? (util/uuid-string? page-name)
block-id (and block? (uuid page-name))
block-id (parse-uuid page-name)
block? (boolean block-id)
format (let [page (if block-id
(:block/name (:block/page (db/entity [:block/uuid block-id])))
page-name)]

View File

@ -82,8 +82,7 @@
default-collapsed? (>= (count refed-blocks-ids) threshold)
filters-atom (get state ::filters)
filter-state (rum/react filters-atom)
block? (util/uuid-string? page-name)
block-id (and block? (uuid page-name))
block-id (parse-uuid page-name)
page-name (string/lower-case page-name)
journal? (date/valid-journal-title? (string/capitalize page-name))
scheduled-or-deadlines (when (and journal?

View File

@ -1,6 +1,5 @@
(ns frontend.db.debug
(:require [medley.core :as medley]
[frontend.db.utils :as db-utils]
(:require [frontend.db.utils :as db-utils]
[frontend.db :as db]
[datascript.core :as d]
[frontend.util :as util]))
@ -8,7 +7,7 @@
;; shortcut for query a block with string ref
(defn qb
[string-id]
(db-utils/pull [:block/uuid (medley/uuid string-id)]))
(db-utils/pull [:block/uuid (uuid string-id)]))
(defn check-left-id-conflicts
[]

View File

@ -916,8 +916,8 @@
(defn get-page
[page-name]
(if (util/uuid-string? page-name)
(db-utils/entity [:block/uuid (uuid page-name)])
(if-let [id (parse-uuid page-name)]
(db-utils/entity [:block/uuid id])
(db-utils/entity [:block/name (util/page-name-sanity-lc page-name)])))
(defn get-redirect-page-name
@ -1225,9 +1225,8 @@
(defn get-referenced-blocks-ids
[page-name-or-block-uuid]
(if (util/uuid-string? (str page-name-or-block-uuid))
(let [id (uuid page-name-or-block-uuid)]
(get-block-referenced-blocks-ids id))
(if-let [id (parse-uuid (str page-name-or-block-uuid))]
(get-block-referenced-blocks-ids id)
(get-page-referenced-blocks-ids page-name-or-block-uuid)))
(defn get-matched-blocks

View File

@ -2,7 +2,6 @@
(:require [cljs-bean.core :as bean]
[frontend.external.protocol :as protocol]
[frontend.date :as date]
[medley.core :as medley]
[clojure.walk :as walk]
[clojure.string :as string]
[frontend.util :as util]
@ -61,7 +60,7 @@
(set))]
(reset! all-refed-uids uids)
(doseq [uid uids]
(swap! uid->uuid assoc uid (medley/random-uuid))))))
(swap! uid->uuid assoc uid (random-uuid))))))
(defn transform
[text]
@ -76,7 +75,7 @@
(defn child->text
[{:keys [uid string children]} level]
(when-not (and (get @uid->uuid uid) uid)
(swap! uid->uuid assoc uid (medley/random-uuid)))
(swap! uid->uuid assoc uid (random-uuid)))
(let [children-text (children->text children (inc level))
level-pattern (str (apply str (repeat level "\t"))
(if (zero? level)

View File

@ -49,7 +49,6 @@
[goog.dom.classes :as gdom-classes]
[goog.object :as gobj]
[lambdaisland.glogi :as log]
[medley.core :as medley]
[promesa.core :as p]
[frontend.util.keycode :as keycode]
[logseq.graph-parser.util :as gp-util]
@ -256,10 +255,9 @@
(defn- another-block-with-same-id-exists?
[current-id block-id]
(and (string? block-id)
(util/uuid-string? block-id)
(not= current-id (cljs.core/uuid block-id))
(db/entity [:block/uuid (cljs.core/uuid block-id)])))
(when-let [id (and (string? block-id) (parse-uuid block-id))]
(and (not= current-id id)
(db/entity [:block/uuid id]))))
(defn- attach-page-properties-if-exists!
[block]
@ -481,14 +479,9 @@
(defn- block-self-alone-when-insert?
[config uuid]
(let [current-page (state/get-current-page)
block-id (or
(and (:id config)
(util/uuid-string? (:id config))
(:id config))
(and current-page
(util/uuid-string? current-page)
current-page))]
(= uuid (and block-id (medley/uuid block-id)))))
block-id (or (some-> (:id config) parse-uuid)
(some-> current-page parse-uuid))]
(= uuid block-id)))
(defn insert-new-block-before-block-aux!
[config block _value {:keys [ok-handler]}]
@ -1175,10 +1168,7 @@
[]
(if (state/editing?)
(let [page (state/get-current-page)
block-id (and
(string? page)
(util/uuid-string? page)
(medley/uuid page))]
block-id (and (string? page) (parse-uuid page))]
(when block-id
(let [block-parent (db/get-block-parent block-id)]
(if-let [id (and
@ -2042,8 +2032,8 @@
(defn- last-top-level-child?
[{:keys [id]} current-node]
(when id
(when-let [entity (if (util/uuid-string? (str id))
(db/entity [:block/uuid (uuid id)])
(when-let [entity (if-let [id' (parse-uuid (str id))]
(db/entity [:block/uuid id'])
(db/entity [:block/name (util/page-name-sanity-lc id)]))]
(= (:block/uuid entity) (tree/-get-parent-id current-node)))))
@ -3110,7 +3100,7 @@
(when-let [block-id (some-> (state/get-selection-blocks)
first
(dom/attr "blockid")
medley/uuid)]
uuid)]
(util/stop e)
(let [block {:block/uuid block-id}
block-id (-> (state/get-selection-blocks)
@ -3222,8 +3212,7 @@
:or {collapse? false expanded? false incremental? true root-block nil}}]
(when-let [page (or (state/get-current-page)
(date/today))]
(let [block? (util/uuid-string? page)
block-id (or root-block (and block? (uuid page)))
(let [block-id (or root-block (parse-uuid page))
blocks (if block-id
(db/get-block-and-children (state/get-current-repo) block-id)
(db/get-page-blocks-no-cache page))
@ -3320,7 +3309,7 @@
(->> (get-selected-blocks)
(map (fn [dom]
(-> (dom/attr dom "blockid")
medley/uuid
uuid
expand-block!)))
doall)
(and clear-selection? (clear-selection!)))
@ -3353,7 +3342,7 @@
(->> (get-selected-blocks)
(map (fn [dom]
(-> (dom/attr dom "blockid")
medley/uuid
uuid
collapse-block!)))
doall)
(and clear-selection? (clear-selection!)))

View File

@ -9,7 +9,6 @@
[frontend.state :as state]
[logseq.graph-parser.text :as text]
[frontend.util :as util]
[medley.core :as medley]
[reitit.frontend.easy :as rfe]))
(defn redirect!
@ -80,7 +79,7 @@
(let [name (:name path-params)
block? (util/uuid-string? name)]
(if block?
(if-let [block (db/entity [:block/uuid (medley/uuid name)])]
(if-let [block (db/entity [:block/uuid (uuid name)])]
(let [content (text/remove-level-spaces (:block/content block)
(:block/format block) (config/get-block-pattern (:block/format block)))]
(if (> (count content) 48)

View File

@ -1,6 +1,5 @@
(ns frontend.modules.outliner.tree
(:require [frontend.db :as db]
[frontend.util :as util]
[clojure.string :as string]
[frontend.state :as state]))
@ -45,8 +44,8 @@
(defn- get-root-and-page
[repo root-id]
(if (string? root-id)
(if (util/uuid-string? root-id)
[false (db/entity repo [:block/uuid (uuid root-id)])]
(if-let [id (parse-uuid root-id)]
[false (db/entity repo [:block/uuid id])]
[true (db/entity repo [:block/name (string/lower-case root-id)])])
[false root-id]))

View File

@ -8,8 +8,7 @@
[frontend.util :as util]
[goog.events :as events]
[goog.ui.KeyboardShortcutHandler.EventType :as EventType]
[lambdaisland.glogi :as log]
[medley.core :as medley])
[lambdaisland.glogi :as log])
(:import [goog.events KeyCodes KeyHandler KeyNames]
[goog.ui KeyboardShortcutHandler]))
@ -117,7 +116,7 @@
dispatch-fn (get shortcut-map (keyword (.-identifier e)))]
;; trigger fn
(when dispatch-fn (dispatch-fn e))))
install-id (medley/random-uuid)
install-id (random-uuid)
data {install-id
{:group handler-id
:dispatch-fn f

View File

@ -32,11 +32,9 @@
[frontend.loader :as loader]
[goog.dom :as gdom]
[lambdaisland.glogi :as log]
[medley.core :as medley]
[promesa.core :as p]
[reitit.frontend.easy :as rfe]
[sci.core :as sci]
[logseq.graph-parser.util :as gp-util]
[frontend.version :as fv]
[frontend.handler.shell :as shell]
[frontend.modules.layout.core]))
@ -442,11 +440,11 @@
(defn ^:export open_in_right_sidebar
[block-uuid]
(editor-handler/open-block-in-sidebar! (medley/uuid block-uuid)))
(editor-handler/open-block-in-sidebar! (uuid block-uuid)))
(def ^:export edit_block
(fn [block-uuid ^js opts]
(when-let [block-uuid (and block-uuid (medley/uuid block-uuid))]
(when-let [block-uuid (and block-uuid (uuid block-uuid))]
(when-let [block (db-model/query-block-by-uuid block-uuid)]
(let [{:keys [pos] :or {pos :max}} (bean/->clj opts)]
(editor-handler/edit-block! block pos block-uuid))))))
@ -455,7 +453,7 @@
(fn [block-uuid-or-page-name content ^js opts]
(let [{:keys [before sibling isPageBlock properties]} (bean/->clj opts)
page-name (and isPageBlock block-uuid-or-page-name)
block-uuid (if isPageBlock nil (medley/uuid block-uuid-or-page-name))
block-uuid (if isPageBlock nil (uuid block-uuid-or-page-name))
new-block (editor-handler/api-insert-new-block!
content
{:block-uuid block-uuid
@ -480,7 +478,7 @@
(let [includeChildren true
repo (state/get-current-repo)]
(editor-handler/delete-block-aux!
{:block/uuid (medley/uuid block-uuid) :repo repo} includeChildren)
{:block/uuid (uuid block-uuid) :repo repo} includeChildren)
nil)))
(def ^:export update_block
@ -490,7 +488,7 @@
editing? (and edit-input (string/ends-with? edit-input block-uuid))]
(if editing?
(state/set-edit-content! edit-input content)
(editor-handler/save-block! repo (medley/uuid block-uuid) content))
(editor-handler/save-block! repo (uuid block-uuid) content))
nil)))
(def ^:export move_block
@ -505,8 +503,8 @@
:else
nil)
src-block (db-model/query-block-by-uuid (medley/uuid src-block-uuid))
target-block (db-model/query-block-by-uuid (medley/uuid target-block-uuid))]
src-block (db-model/query-block-by-uuid (uuid src-block-uuid))
target-block (db-model/query-block-by-uuid (uuid target-block-uuid))]
(editor-dnd-handler/move-blocks nil [src-block] target-block move-to) nil)))
(def ^:export get_block
@ -565,11 +563,11 @@
(def ^:export upsert_block_property
(fn [block-uuid key value]
(editor-handler/set-block-property! (medley/uuid block-uuid) key value)))
(editor-handler/set-block-property! (uuid block-uuid) key value)))
(def ^:export remove_block_property
(fn [block-uuid key]
(editor-handler/remove-block-property! (medley/uuid block-uuid) key)))
(editor-handler/remove-block-property! (uuid block-uuid) key)))
(def ^:export get_block_property
(fn [block-uuid key]
@ -637,7 +635,7 @@
(defn ^:export prepend_block_in_page
[uuid-or-page-name content ^js opts]
(let [page? (not (gp-util/uuid-string? uuid-or-page-name))
(let [page? (not (util/uuid-string? uuid-or-page-name))
page-not-exist? (and page? (nil? (db-model/get-page uuid-or-page-name)))
_ (and page-not-exist? (page-handler/create! uuid-or-page-name
{:redirect? false
@ -653,7 +651,7 @@
(defn ^:export append_block_in_page
[uuid-or-page-name content ^js opts]
(let [page? (not (gp-util/uuid-string? uuid-or-page-name))
(let [page? (not (util/uuid-string? uuid-or-page-name))
page-not-exist? (and page? (nil? (db-model/get-page uuid-or-page-name)))
_ (and page-not-exist? (page-handler/create! uuid-or-page-name
{:redirect? false

View File

@ -129,8 +129,7 @@
:else
nil)]
(when (and block-id
(gp-util/uuid-string? block-id))
(when (some-> block-id parse-uuid)
block-id)))
(defn- paragraph-block?
@ -325,12 +324,10 @@
(swap! ref-blocks conj block))
form)
(concat title body))
(let [ref-blocks (->> @ref-blocks
(filter gp-util/uuid-string?))
ref-blocks (map
(fn [id]
[:block/uuid (uuid id)])
ref-blocks)
(let [ref-blocks (keep (fn [block]
(when-let [id (parse-uuid block)]
[:block/uuid id]))
@ref-blocks)
refs (distinct (concat (:refs block) ref-blocks))]
(assoc block :refs refs))))
@ -430,8 +427,7 @@
(get-in properties [:properties :custom_id])
(get-in properties [:properties :id]))]
(let [custom-id (and (string? custom-id) (string/trim custom-id))]
(when (and custom-id (gp-util/uuid-string? custom-id))
(uuid custom-id))))
(some-> custom-id parse-uuid)))
(d/squuid)))
(defn get-page-refs-from-properties

View File

@ -4,9 +4,6 @@
(:require [clojure.walk :as walk]
[clojure.string :as string]))
(def uuid-pattern "[0-9a-f]{8}-[0-9a-f]{4}-[0-5][0-9a-f]{3}-[089ab][0-9a-f]{3}-[0-9a-f]{12}")
(defonce exactly-uuid-pattern (re-pattern (str "(?i)^" uuid-pattern "$")))
(defn safe-re-find
"Copy of frontend.util/safe-re-find. Too basic to couple to main app"
[pattern s]
@ -16,11 +13,6 @@
(when (string? s)
(re-find pattern s)))
(defn uuid-string?
"Copy of frontend.util/uuid-string?. Too basic to couple to main app"
[s]
(safe-re-find exactly-uuid-pattern s))
(defn path-normalize
"Normalize file path (for reading paths from FS, not required by writting)"
[s]

View File

@ -721,10 +721,10 @@
resolved "https://registry.yarnpkg.com/@kanru/rage-wasm/-/rage-wasm-0.2.1.tgz#dd8fdd3133992c42bf68c0086d8cad40a13bc329"
integrity sha512-sYi4F2mL6Mpcz7zbS4myasw11xLBEbgZkDMRVg9jNxTKt6Ct/LT7/vCHDmEzAFcPcPqixD5De6Ql3bJijAX0/w==
"@logseq/nbb-logseq@^0.3.99":
version "0.3.99"
resolved "https://registry.yarnpkg.com/@logseq/nbb-logseq/-/nbb-logseq-0.3.99.tgz#cf6c05c559963e4e0fb92f214a63228972ef87d3"
integrity sha512-Msa6Ck6wqt7sYGExQZgUT/uUG/z5jGaPlytVdgGkCrVogZb2yaChbWeMOCfCsCTi6kbHo15hC3aOeDAXcfnFzw==
"@logseq/nbb-logseq@^0.5.103":
version "0.5.103"
resolved "https://registry.yarnpkg.com/@logseq/nbb-logseq/-/nbb-logseq-0.5.103.tgz#1084380cd54c92ca8cc94a8934cc777206e45cc0"
integrity sha512-V9UW0XrCaaadHUc6/Hp9wfGpQqkzqzoqnDGeSVZkWR6l3QwyqGi9mkhnhVcfTwAvxIfOgrfz93GcaeepV4pYNA==
dependencies:
import-meta-resolve "^1.1.1"