Merge branch 'master' into feat/outliner-core

This commit is contained in:
Tienson Qin
2021-03-13 10:47:43 +08:00
155 changed files with 8925 additions and 4463 deletions

View File

@@ -8,6 +8,7 @@
#?(:cljs ["/frontend/caret_pos" :as caret-pos])
#?(:cljs ["/frontend/selection" :as selection])
#?(:cljs ["/frontend/utils" :as utils])
#?(:cljs ["path" :as nodePath])
#?(:cljs [goog.dom :as gdom])
#?(:cljs [goog.object :as gobj])
#?(:cljs [goog.string :as gstring])
@@ -30,8 +31,8 @@
(-pr-writer [sym writer _]
(-write writer (str "\"" (.toString sym) "\"")))))
;; doms
#?(:cljs (defn html-node [] js/document.documentElement))
#?(:cljs (defonce ^js node-path nodePath))
#?(:cljs (defn app-scroll-container-node [] js/document.documentElement))
#?(:cljs
(defn ios?
@@ -51,6 +52,18 @@
(when-not node-test?
(re-find #"Mobi" js/navigator.userAgent))))
#?(:cljs
(defn electron?
[]
(when (and js/window (gobj/get js/window "navigator"))
(let [ua (string/lower-case js/navigator.userAgent)]
(string/includes? ua " electron")))))
#?(:cljs
(defn file-protocol?
[]
(string/starts-with? js/window.location.href "file://")))
(defn format
[fmt & args]
#?(:cljs (apply gstring/format fmt args)
@@ -145,6 +158,10 @@
col)
(into {})))
(defn ext-of-image? [s]
(some #(string/ends-with? s %)
[".png" ".jpg" ".jpeg" ".bmp" ".gif" ".webp"]))
;; ".lg:absolute.lg:inset-y-0.lg:right-0.lg:w-1/2"
(defn hiccup->class
[class]
@@ -327,6 +344,12 @@
(string/split #"\?")
(first))))))
#?(:cljs
(defn fragment-with-anchor
[anchor]
(let [fragment (get-fragment)]
(str "#" fragment "?anchor=" anchor))))
;; (defn scroll-into-view
;; [element]
;; (let [scroll-top (gobj/get element "offsetTop")
@@ -353,8 +376,15 @@
(def moving-frequency 15)
#?(:cljs
(defn cur-doc-top []
(.. js/document -documentElement -scrollTop)))
(defn cur-doc-top []
(.. js/document -documentElement -scrollTop)))
#?(:cljs
(defn lock-global-scroll
([] (lock-global-scroll true))
([v] (js-invoke (.-classList (app-scroll-container-node))
(if v "add" "remove")
"locked-scroll"))))
#?(:cljs
(defn element-top [elem top]
@@ -371,26 +401,27 @@
(when-not (re-find #"^/\d+$" elem-id)
(when elem-id
(when-let [elem (gdom/getElement elem-id)]
(.scroll (html-node)
(.scroll (app-scroll-container-node)
#js {:top (let [top (element-top elem 0)]
(if (> top 68)
(- top 68)
top))
(if (< top 256)
0 top))
:behavior "smooth"}))))))
#?(:cljs
(defn scroll-to
([pos]
(scroll-to (html-node) pos))
([node pos]
(.scroll node
#js {:top pos
:behavior "smooth"}))))
(defn scroll-to
([pos]
(scroll-to (app-scroll-container-node) pos))
([node pos]
(scroll-to node pos true))
([node pos animate?]
(.scroll node
#js {:top pos
:behavior (if animate? "smooth" "auto")}))))
#?(:cljs
(defn scroll-to-top
[]
(scroll-to 0)))
(scroll-to (app-scroll-container-node) 0 false)))
(defn url-encode
[string]
@@ -443,7 +474,7 @@
(defn journal?
[path]
(starts-with? path "journals/"))
(string/includes? path "journals/"))
(defn drop-first-line
[s]
@@ -777,12 +808,6 @@
[]
#?(:cljs (tc/to-long (cljs-time.core/now))))
(defn get-repo-dir
[repo-url]
(str "/"
(->> (take-last 2 (string/split repo-url #"/"))
(string/join "_"))))
(defn d
[k f]
(let [result (atom nil)]
@@ -955,6 +980,9 @@
(defonce mac? #?(:cljs goog.userAgent/MAC
:clj nil))
(defonce win32? #?(:cljs goog.userAgent/WINDOWS
:clj nil))
(defn ->system-modifier
[keyboard-shortcut]
(if mac?
@@ -977,8 +1005,10 @@
new-block (case (name text-format)
"org"
"** "
"markdown"
"## "
"")]
(if contents?
new-block
@@ -995,7 +1025,6 @@
(defn page-name-sanity
[page-name]
(-> page-name
(string/replace #"\s+" "_")
;; Windows reserved path characters
(string/replace #"[\\/:\\*\\?\"<>|]+" "_")))
@@ -1102,6 +1131,27 @@
(string/replace "&quot;" "\"")
(string/replace "&apos;" "'")))
#?(:cljs
(defn system-locales
[]
(when-not node-test?
(when-let [navigator (and js/window (.-navigator js/window))]
;; https://zzz.buzz/2016/01/13/detect-browser-language-in-javascript/
(when navigator
(let [v (js->clj
(or
(.-languages navigator)
(.-language navigator)
(.-userLanguage navigator)
(.-browserLanguage navigator)
(.-systemLanguage navigator)))]
(if (string? v) [v] v)))))))
#?(:cljs
(defn zh-CN-supported?
[]
(contains? (set (system-locales)) "zh-CN")))
(comment
(= (get-relative-path "journals/2020_11_18.org" "pages/grant_ideas.org")
"../pages/grant_ideas.org")