Merge branch 'master' into disable-webview-resize

This commit is contained in:
llcc
2022-05-19 15:26:03 +08:00
committed by GitHub
35 changed files with 131 additions and 204 deletions

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)
@@ -315,8 +315,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

@@ -733,7 +733,7 @@
updates (state/all-available-coming-updates)]
[:div.cp__plugins-waiting-updates
[:h1.mb-4.text-2xl.p-1 (util/format "Found %s updates" (util/safe-parse-int (count updates)))]
[:h1.mb-4.text-2xl.p-1 (util/format "Found %s updates" (count updates))]
(if (seq updates)
;; lists

View File

@@ -12,7 +12,6 @@
[frontend.state :as state]
[frontend.ui :as ui]
[frontend.util :as util]
[medley.core :as medley]
[rum.core :as rum]))
(rum/defc filter-dialog-inner < rum/reactive
@@ -82,8 +81,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?
@@ -142,8 +140,8 @@
(db/get-block-referenced-blocks block-id)
(db/get-page-referenced-blocks page-name))
filters (when (seq filter-state)
(->> (group-by second filter-state)
(medley/map-vals #(map first %))))
(-> (group-by second filter-state)
(update-vals #(map first %))))
filtered-ref-blocks (block-handler/filter-blocks repo ref-blocks filters true)
n-ref (apply +
(for [[_ rfs] filtered-ref-blocks]

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

@@ -67,7 +67,7 @@
(date/journal-title->int input)))
:else
(let [duration (util/parse-int (subs input 0 (dec (count input))))
(let [duration (parse-long (subs input 0 (dec (count input))))
kind (last input)
tf (case kind
"y" t/years
@@ -99,7 +99,7 @@
(date/journal-title->long input)))
:else
(let [duration (util/parse-int (subs input 0 (dec (count input))))
(let [duration (parse-long (subs input 0 (dec (count input))))
kind (last input)
tf (case kind
"y" t/years

View File

@@ -33,12 +33,12 @@
(and (keyword? input)
(util/safe-re-find #"^\d+d(-before)?$" (name input)))
(let [input (name input)
days (util/parse-int (subs input 0 (dec (count input))))]
days (parse-long (subs input 0 (dec (count input))))]
(date->int (t/minus (t/today) (t/days days))))
(and (keyword? input)
(util/safe-re-find #"^\d+d(-after)?$" (name input)))
(let [input (name input)
days (util/parse-int (subs input 0 (dec (count input))))]
days (parse-long (subs input 0 (dec (count input))))]
(date->int (t/plus (t/today) (t/days days))))
(and (string? input) (text/page-ref? input))

View File

@@ -4,7 +4,6 @@
[frontend.state :as state]
[clojure.string :as string]
[datascript.transit :as dt]
[frontend.util :as util]
[frontend.date :as date]
[frontend.db.conn :as conn]
[frontend.config :as config]
@@ -46,7 +45,7 @@
(defn date->int
[date]
(util/parse-int
(parse-long
(string/replace (date/ymd date) "/" "")))
(defn entity

View File

@@ -1,6 +1,5 @@
(ns frontend.extensions.slide
(:require [rum.core :as rum]
[medley.core :as medley]
[cljs-bean.core :as bean]
[frontend.loader :as loader]
[frontend.ui :as ui]
@@ -20,11 +19,11 @@
(let [properties (:block/properties block)]
(if (seq properties)
(merge m
(medley/map-keys
(update-keys
properties
(fn [k]
(-> (str "data-" (name k))
(string/replace "data-data-" "data-")))
properties))
(string/replace "data-data-" "data-")))))
m)))
(defonce *loading? (atom false))

View File

@@ -123,9 +123,9 @@ Remember: You can paste a raw YouTube url as embedded video on mobile."
reg-number #"^\d+$"
timestamp (str timestamp)
total-seconds (-> (re-matches reg-number timestamp)
util/safe-parse-int)
parse-long)
[_ hours minutes seconds] (re-matches reg timestamp)
[hours minutes seconds] (map util/safe-parse-int [hours minutes seconds])]
[hours minutes seconds] (map parse-long [hours minutes seconds])]
(cond
total-seconds
total-seconds

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

@@ -52,7 +52,6 @@
[goog.dom.classes :as gdom-classes]
[goog.object :as gobj]
[lambdaisland.glogi :as log]
[medley.core :as medley]
[promesa.core :as p]
[logseq.graph-parser.util :as gp-util]
[logseq.graph-parser.mldoc :as gp-mldoc]
@@ -257,10 +256,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]
@@ -482,14 +480,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]}]
@@ -1176,10 +1169,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
@@ -2044,8 +2034,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)))))
@@ -3099,7 +3089,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)
@@ -3211,8 +3201,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))
@@ -3309,7 +3298,7 @@
(->> (get-selected-blocks)
(map (fn [dom]
(-> (dom/attr dom "blockid")
medley/uuid
uuid
expand-block!)))
doall)
(and clear-selection? (clear-selection!)))
@@ -3342,7 +3331,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

@@ -8,8 +8,7 @@
[frontend.state :as state]
[frontend.config :as config]
[logseq.graph-parser.util :as gp-util]
[lambdaisland.glogi :as log]
[medley.core :as medley])))
[lambdaisland.glogi :as log])))
#?(:cljs
(defn new-outliner-txs-state [] (atom [])))
@@ -33,9 +32,10 @@
(some->> (gp-util/remove-nils txs)
(map (fn [x]
(if (map? x)
(medley/map-vals (fn [v] (if (vector? v)
(remove nil? v)
v)) x)
(update-vals x (fn [v]
(if (vector? v)
(remove nil? v)
v)))
x))))))
#?(:cljs

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

@@ -659,9 +659,10 @@
(def category
"Active list of categories for docs purpose"
(medley/map-vals (fn [v]
(vec (remove #(:inactive (get all-default-keyboard-shortcuts %)) v)))
category*))
(update-vals
category*
(fn [v]
(vec (remove #(:inactive (get all-default-keyboard-shortcuts %)) v)))))
(defn add-shortcut!
[handler-id id shortcut-map]

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

@@ -1,10 +1,11 @@
(ns ^:bb-compatible frontend.modules.shortcut.dicts
"Provides dictionary entries for shortcuts"
(:require [medley.core :as medley]))
"Provides dictionary entries for shortcuts")
(defn- decorate-namespace [k]
(let [n (name k)
ns (namespace k)]
(keyword (str "command." ns) n)))
(def ^:large-vars/data-var all-default-keyboard-shortcuts
{:date-picker/complete "Date picker: Choose selected day"
:date-picker/prev-day "Date picker: Select previous day"
@@ -113,6 +114,7 @@
:editor/toggle-open-blocks "Toggle open blocks (collapse or expand all blocks)"
:ui/toggle-cards "Toggle cards"
:git/commit "Git commit message"})
(def category
{:shortcut.category/basics "Basics"
:shortcut.category/formatting "Formatting"
@@ -122,12 +124,13 @@
:shortcut.category/block-selection "Block selection (press Esc to quit selection)"
:shortcut.category/toggle "Toggle"
:shortcut.category/others "Others"})
(def ^:large-vars/data-var dicts
{:en (merge
;; Dynamically add this ns since command descriptions have to
;; stay in sync with shortcut.config command ids which do not
;; have a namespce
(medley/map-keys decorate-namespace all-default-keyboard-shortcuts)
(update-keys all-default-keyboard-shortcuts decorate-namespace)
category)
:zh-CN {:shortcut.category/formatting "格式化"
@@ -217,7 +220,7 @@
:command.ui/toggle-theme "“在暗色/亮色主題之間切換”"
:command.ui/toggle-right-sidebar "啟用/關閉右側欄"
:command.go/journals "跳轉到日記"}
:de {:shortcut.category/formatting "Formatierung"
:command.editor/indent "Block einrücken"
:command.editor/outdent "Block ausrücken"
@@ -264,7 +267,7 @@
:command.ui/toggle-theme "Intervertir le thème foncé/clair"
:command.ui/toggle-right-sidebar "Afficher/cacher la barre latérale"
:command.go/journals "Aller au Journal"}
:af {:shortcut.category/formatting "Formatering"
:command.editor/indent "Ingekeepte blok oortjie"
:command.editor/outdent "Oningekeepte blok"
@@ -288,7 +291,7 @@
:command.go/journals "Spring na joernale"
:command.ui/toggle-theme "Wissel tussen donker/lig temas"
:command.ui/toggle-right-sidebar "Wissel regter sybalk"}
:es {:shortcut.category/formatting "Formato"
:shortcut.category/basics "Básico"
:shortcut.category/navigating "Navegación"
@@ -352,7 +355,7 @@
:command.editor/open-edit "Editar bloque seleccionado"
:command.editor/delete-selection "Eliminar bloques seleccionados"
:command.editor/toggle-open-blocks "Alternar bloques abieros, (colapsar o expandir todos)"}
:ru {:shortcut.category/formatting "Форматирование"
:shortcut.category/basics "Базовые"
:shortcut.category/navigating "Навигация"
@@ -416,7 +419,7 @@
:command.editor/open-edit "Редактировать выбранный блок"
:command.editor/delete-selection "Удалить выбранные блоки"
:command.editor/toggle-open-blocks "Переключить открытые блоки (свернуть или развернуть все)"}
:nb-NO {:shortcut.category/formatting "Formatering"
:shortcut.category/basics "Basis"
:shortcut.category/navigating "Navigasjon"
@@ -481,7 +484,7 @@
:command.editor/open-edit "Rediger valgt blokk"
:command.editor/delete-selection "Slett valgte blokker"
:command.editor/toggle-open-blocks "Veksle åpne blokker (slå sammen eller utvid alle blokker)"}
:pt-PT {:shortcut.category/formatting "Formatação"
:shortcut.category/basics "Básico"
:shortcut.category/navigating "Navegação"
@@ -545,7 +548,7 @@
:command.editor/open-edit "Editar bloco selecionado"
:command.editor/delete-selection "Eliminar blocos selecionados"
:command.editor/toggle-open-blocks "Alternar blocos abertos (colapsar ou expandir todos)"}
:pt-BR {:shortcut.category/formatting "Formatação"
:shortcut.category/basics "Básico"
:shortcut.category/navigating "Navegação"
@@ -659,7 +662,7 @@
:command.misc/copy "Copiar (copiar seleção ou referência do bloco)"
:command.ui/goto-plugins "Ir para o painel de plugins"
:command.ui/open-new-window "Abra uma nova janela"}
:ja {:shortcut.category/formatting "フォーマット"
:shortcut.category/basics "基本操作"
:shortcut.category/navigating "ナビゲーション"

View File

@@ -1269,7 +1269,7 @@
[pid hook-or-all]
(when-let [pid (keyword pid)]
(if (nil? hook-or-all)
(swap! state update :plugin/installed-hooks #(medley/map-vals (fn [ids] (disj ids pid)) %))
(swap! state update :plugin/installed-hooks #(update-vals % (fn [ids] (disj ids pid))))
(when-let [coll (get-in @state [:plugin/installed-hooks hook-or-all])]
(set-state! [:plugin/installed-hooks hook-or-all] (disj coll pid))))
true))

View File

@@ -291,10 +291,12 @@
style)))
(defn apply-custom-theme-effect! [theme]
(when-let [custom-theme (state/sub [:ui/custom-theme (keyword theme)])]
(js/LSPluginCore.selectTheme (bean/->js custom-theme)
(bean/->js {:effect false :emit false}))
(state/set-state! :plugin/selected-theme (:url custom-theme))))
(when plugin-handler/lsp-enabled?
(when-let [custom-theme (state/sub [:ui/custom-theme (keyword theme)])]
(when-let [url (:url custom-theme)]
(js/LSPluginCore.selectTheme (bean/->js custom-theme)
(bean/->js {:effect false :emit false}))
(state/set-state! :plugin/selected-theme (:url url))))))
(defn setup-system-theme-effect!
[]

View File

@@ -217,39 +217,21 @@
(str "0" n)
(str n)))
(defn parse-int
[x]
#?(:cljs (if (string? x)
(js/parseInt x)
x)
:clj (if (string? x)
(Integer/parseInt x)
x)))
(defn safe-parse-int
[x]
#?(:cljs (let [result (parse-int x)]
(if (js/isNaN result)
nil
result))
:clj ((try
(parse-int x)
(catch Exception _
nil)))))
#?(:cljs
(defn parse-float
(defn safe-parse-int
"Use if arg could be an int or string. If arg is only a string, use `parse-long`."
[x]
(if (string? x)
(js/parseFloat x)
(parse-long x)
x)))
#?(:cljs
(defn safe-parse-float
"Use if arg could be a float or string. If arg is only a string, use `parse-double`"
[x]
(let [result (parse-float x)]
(if (js/isNaN result)
nil
result))))
(if (string? x)
(parse-double x)
x)))
#?(:cljs
(defn debounce

View File

@@ -1,8 +1,7 @@
(ns frontend.util.list
(:require [frontend.util.thingatpt :as thingatpt]
[frontend.util.cursor :as cursor]
[clojure.string :as string]
[frontend.util :as util]))
[clojure.string :as string]))
(defn get-prev-item [& [input]]
(when-not (cursor/textarea-cursor-first-row? input)
@@ -56,7 +55,7 @@
(map (fn [line] (if (newline? line) "" line)))
(string/join "\n"))
(let [[_ num-str] (re-find #"^(\d+){1}\." line)
num (if num-str (util/safe-parse-int num-str) nil)
num (if num-str (parse-long num-str) nil)
double-newlines?' (or double-newlines?
(and (newline? line) (seq others) (newline? (first others))))
[idx' result'] (if (and (not double-newlines?') num)

View File

@@ -4,7 +4,6 @@
[frontend.util :as util]
[clojure.set :as set]
[frontend.config :as config]
[medley.core :as medley]
[logseq.graph-parser.util :as gp-util]
[logseq.graph-parser.mldoc :as gp-mldoc]
[logseq.graph-parser.property :as gp-property :refer [properties-start properties-end]]
@@ -364,7 +363,7 @@
(defn add-page-properties
[page-format properties-content properties]
(let [properties (medley/map-keys name properties)
(let [properties (update-keys properties name)
lines (string/split-lines properties-content)
front-matter-format? (contains? #{:markdown} page-format)
lines (if front-matter-format?

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?
@@ -208,7 +207,7 @@
;; {"Deadline" {:date {:year 2020, :month 10, :day 20}, :wday "Tue", :time {:hour 8, :min 0}, :repetition [["DoublePlus"] ["Day"] 1], :active true}}
(defn timestamps->scheduled-and-deadline
[timestamps]
(let [timestamps (gp-util/map-keys (comp keyword string/lower-case) timestamps)
(let [timestamps (update-keys timestamps (comp keyword string/lower-case))
m (some->> (select-keys timestamps [:scheduled :deadline])
(map (fn [[k v]]
(let [{:keys [date repetition]} v
@@ -325,23 +324,21 @@
(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))))
(defn- block-keywordize
[block]
(gp-util/map-keys
(update-keys
block
(fn [k]
(if (namespace k)
k
(keyword "block" k)))
block))
(keyword "block" k)))))
(defn- sanity-blocks-data
[blocks]
@@ -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

@@ -37,7 +37,7 @@
(when journal-title
(let [journal-title (gp-util/capitalize-all journal-title)]
(journal-title-> journal-title
#(gp-util/parse-int (tf/unparse (tf/formatter "yyyyMMdd") %))
#(parse-long (tf/unparse (tf/formatter "yyyyMMdd") %))
formatters))))
(defn format

View File

@@ -350,7 +350,7 @@
false
(and (not= k "alias") (gp-util/safe-re-find #"^\d+$" v))
(gp-util/safe-parse-int v)
(parse-long v)
(gp-util/wrapped-by-quotes? v) ; wrapped in ""
v

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]
@@ -67,21 +59,6 @@
[v]
(and (string? v) (>= (count v) 2) (= "\"" (first v) (last v))))
(defn parse-int
"Copy of frontend.util/parse-int. Too basic to couple to main app"
[x]
(if (string? x)
(js/parseInt x)
x))
(defn safe-parse-int
"Copy of frontend.util/safe-parse-int. Too basic to couple to main app"
[x]
(let [result (parse-int x)]
(if (js/isNaN result)
nil
result)))
(defn url?
[s]
(and (string? s)
@@ -97,14 +74,6 @@
(js/JSON.parse)
(js->clj :keywordize-keys true)))
;; TODO: Use update-keys once its available in cljs and nbb
(defn map-keys
"Maps function `f` over the keys of map `m` to produce a new map."
[f m]
(reduce-kv
(fn [m_ k v]
(assoc m_ (f k) v)) {} m))
(defn zero-pad
"Copy of frontend.util/zero-pad. Too basic to couple to main app"
[n]