From 87a2d27172f40c3760eeaffd3b77b444569fb25c Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Sun, 3 May 2020 10:29:46 +0800 Subject: [PATCH] Commands wip --- web/src/main/frontend/commands.cljs | 29 ++++++++++++++ web/src/main/frontend/components/hiccup.cljs | 29 +++++++------- web/src/main/frontend/util.cljs | 40 +++++++++++++------- 3 files changed, 70 insertions(+), 28 deletions(-) create mode 100644 web/src/main/frontend/commands.cljs diff --git a/web/src/main/frontend/commands.cljs b/web/src/main/frontend/commands.cljs new file mode 100644 index 000000000..5ea1ab8d1 --- /dev/null +++ b/web/src/main/frontend/commands.cljs @@ -0,0 +1,29 @@ +(ns frontend.commands + (:require [frontend.util :as util] + [forntend.state :as state])) + +(defn ->page-reference + [page] + (util/format "[[%s]]" page)) + +;; Credits to roamresearch.com +(defn commands + [command-name] + (get + (merge + {"Today" (->page-reference (util/today)) + "Tomorrow" (->page-reference (util/tomorrow)) + "Yesterday" (->page-reference (util/tomorrow)) + "Current Time" (util/get-current-time) + "Date Picker" [[:date/pick] + ] + "Page Reference" [[:editor/input "[[]]"] + [:editor/cursor-back 2] + [:search :page] + [:insert] + [:cursor/move-to-end]] + "Link" nil + "Upload a image" nil} + ;; Allow user to modify or extend, should specify how to extend. + (:config @state/state)) + command-name)) diff --git a/web/src/main/frontend/components/hiccup.cljs b/web/src/main/frontend/components/hiccup.cljs index a9baa3f79..81c8f4244 100644 --- a/web/src/main/frontend/components/hiccup.cljs +++ b/web/src/main/frontend/components/hiccup.cljs @@ -420,20 +420,21 @@ [:span {:class name} name]]) tags))) - element (keyword (str "h" level)) - level-str [:a.control-level {:href (str "/page/" uuid)} - (str (apply str (repeat level "*")) " ")] - heading-part (->elem element - {:id anchor} - (remove-nils - (concat - [ - ;; (when-not agenda? level-str) - checkbox - marker - priority] - (map-inline title) - [tags])))] + heading-part (when level + (let [element (keyword (str "h" level)) + level-str [:a.control-level {:href (str "/page/" uuid)} + (str (apply str (repeat level "*")) " ")]] + (->elem element + {:id anchor} + (remove-nils + (concat + [ + ;; (when-not agenda? level-str) + checkbox + marker + priority] + (map-inline title) + [tags])))))] (heading-cp t heading-part config))) (defn list-element diff --git a/web/src/main/frontend/util.cljs b/web/src/main/frontend/util.cljs index 7b6e9ba11..07446cbe1 100644 --- a/web/src/main/frontend/util.cljs +++ b/web/src/main/frontend/util.cljs @@ -83,7 +83,7 @@ (defn span-raw-html [content] [:span {:dangerouslySetInnerHTML - {:__html content}}]) + {:__html content}}]) (defn json->clj [json-string] @@ -188,14 +188,6 @@ (let [{:keys [year month]} (get-date)] (journals-path year month))) -(defn today - [] - (.toLocaleDateString (js/Date.) "default" - (clj->js {:month "long" - :year "numeric" - :day "numeric" - :weekday "long"}))) - (defn zero-pad [n] (if (< n 10) @@ -231,6 +223,26 @@ ([date] (str (get-weekday date) ", " (mdy date)))) +(defn today + [] + (journal-name)) + +(defn tomorrow + [] + (let [d (js/Date.) + _ (.setDate d (inc (.getDate (js/Date.))))] + (journal-name d))) + +(defn get-current-time + [] + (let [d (js/Date.)] + (.toLocaleTimeString + d + (gobj/get js/window.navigator "language") + (bean/->js {:hour "2-digit" + :minute "2-digit" + :hour12 false})))) + (defn get-month-last-day [] (let [today (js/Date.) @@ -365,11 +377,11 @@ [input] (try (some-> input - (d/style) - (gobj/get "lineHeight") - ;; TODO: is this cross-platform? - (string/replace "px" "") - (parse-int)) + (d/style) + (gobj/get "lineHeight") + ;; TODO: is this cross-platform? + (string/replace "px" "") + (parse-int)) (catch js/Error _e 24)))