Commands wip

pull/645/head
Tienson Qin 2020-05-03 10:29:46 +08:00
parent 3a40f9c0fb
commit 87a2d27172
3 changed files with 70 additions and 28 deletions

View File

@ -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))

View File

@ -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

View File

@ -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)))