From 5c53b5494baf33fc570cb666061bbd735f08a18d Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Thu, 5 Nov 2020 14:43:30 +0800 Subject: [PATCH 01/46] fix: remove id property when copy block(s) text (#198) * fix: remove id property when copy block(s) text --- src/main/frontend/components/onboarding.cljs | 4 ++++ src/main/frontend/handler/common.cljs | 7 ++++++- src/main/frontend/handler/editor.cljs | 5 +++-- src/main/frontend/handler/export.cljs | 6 ++++-- src/main/frontend/text.cljs | 13 +++++++++++++ 5 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/main/frontend/components/onboarding.cljs b/src/main/frontend/components/onboarding.cljs index 70a7ce3baeb..7f1303caa5c 100644 --- a/src/main/frontend/components/onboarding.cljs +++ b/src/main/frontend/components/onboarding.cljs @@ -206,6 +206,10 @@ [:a {:href "https://logseq.github.io/page/changelog" :target "_blank"} (t :help/changelog)]] + [:li + [:a {:href "https://logseq.github.io/page/faq" + :target "_blank"} + "FAQ"]] [:li [:a {:href "https://logseq.github.io/" :target "_blank"} diff --git a/src/main/frontend/handler/common.cljs b/src/main/frontend/handler/common.cljs index 6bcd22f2bf5..73760e0f646 100644 --- a/src/main/frontend/handler/common.cljs +++ b/src/main/frontend/handler/common.cljs @@ -3,7 +3,8 @@ [frontend.state :as state] [cljs-bean.core :as bean] [promesa.core :as p] - [frontend.util :as util])) + [frontend.util :as util] + [frontend.text :as text])) (defn check-changed-files-status [] @@ -17,3 +18,7 @@ (state/set-changed-files! repo files))) (p/catch (fn [error] (js/console.dir error))))))) + +(defn copy-to-clipboard-without-id-property! + [content] + (util/copy-to-clipboard! (text/remove-id-property content))) diff --git a/src/main/frontend/handler/editor.cljs b/src/main/frontend/handler/editor.cljs index 7055bcd7c02..2340b727537 100644 --- a/src/main/frontend/handler/editor.cljs +++ b/src/main/frontend/handler/editor.cljs @@ -1,5 +1,6 @@ (ns frontend.handler.editor (:require [frontend.state :as state] + [frontend.handler.common :as common-handler] [frontend.handler.route :as route-handler] [frontend.handler.git :as git-handler] [frontend.handler.ui :as ui-handler] @@ -1146,7 +1147,7 @@ content (if (false? up?) (reverse content) content) content (string/join "" content)] (when-not (string/blank? content) - (util/copy-to-clipboard! content))))) + (common-handler/copy-to-clipboard-without-id-property! content))))) (defn cut-selection-blocks [] @@ -1242,7 +1243,7 @@ [block-id] (when-let [block (db/pull [:block/uuid block-id])] (let [content (:block/content block)] - (util/copy-to-clipboard! content) + (common-handler/copy-to-clipboard-without-id-property! content) (delete-block-aux! block false)))) (defonce select-start-block-state (atom nil)) diff --git a/src/main/frontend/handler/export.cljs b/src/main/frontend/handler/export.cljs index e7b5b5b9726..60b16579ccf 100644 --- a/src/main/frontend/handler/export.cljs +++ b/src/main/frontend/handler/export.cljs @@ -5,13 +5,15 @@ [cljs-bean.core :as bean] [clojure.string :as string] [goog.dom :as gdom] - [frontend.publishing.html :as html])) + [frontend.publishing.html :as html] + [frontend.text :as text] + [frontend.handler.common :as common-handler])) (defn copy-block! [block-id] (when-let [block (db/pull [:block/uuid block-id])] (let [content (:block/content block)] - (util/copy-to-clipboard! content)))) + (common-handler/copy-to-clipboard-without-id-property! content)))) (defn copy-block-as-json! [block-id] diff --git a/src/main/frontend/text.cljs b/src/main/frontend/text.cljs index 481043667d0..9af3b8975a3 100644 --- a/src/main/frontend/text.cljs +++ b/src/main/frontend/text.cljs @@ -61,6 +61,19 @@ (->> (concat title-lines body) (string/join "\n")))) +(defn remove-id-property + [content] + (let [lines (->> (string/split-lines content) + (remove #(let [s (string/lower-case (string/trim %))] + (and + (or (string/starts-with? s ":id:") + (string/starts-with? s ":custom_id:")) + (let [id (and + (> (count s) 36) + (subs s (- (count s) 36)))] + (and id (util/uuid-string? id)))))))] + (string/join "\n" lines))) + (defn build-properties-str [properties] (when (seq properties) From 4f53e43800b8be4463120bec0c358679b6b68b38 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Thu, 5 Nov 2020 15:02:34 +0800 Subject: [PATCH 02/46] chore: extract custom-query-aux --- src/main/frontend/db.cljs | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/main/frontend/db.cljs b/src/main/frontend/db.cljs index ecd3e6bba54..c52a407b395 100644 --- a/src/main/frontend/db.cljs +++ b/src/main/frontend/db.cljs @@ -491,6 +491,17 @@ (get refs (:db/id block)))) blocks))) +(defn custom-query-aux + [{:keys [query inputs result-transform] :as query'} query-opts] + (try + (let [inputs (map resolve-input inputs) + repo (state/get-current-repo) + k [:custom query']] + (apply q repo k query-opts query inputs)) + (catch js/Error e + (println "Custom query failed: ") + (js/console.dir e)))) + (defn custom-query ([query] (custom-query query {})) @@ -505,15 +516,7 @@ :else nil)] - (try - (let [{:keys [query inputs result-transform]} query' - inputs (map resolve-input inputs) - repo (state/get-current-repo) - k [:custom query']] - (apply q repo k query-opts query inputs)) - (catch js/Error e - (println "Query parsing failed: ") - (js/console.dir e)))))) + (custom-query-aux query' query-opts)))) (defn custom-query-result-transform [query-result remove-blocks q] From c707107ae17202f321fe307ab70248a0e46d5f74 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Thu, 5 Nov 2020 15:07:02 +0800 Subject: [PATCH 03/46] fix(editor): don't add properties for pre-blocks Resolved https://github.com/logseq/logseq/issues/614 --- src/main/frontend/handler/editor.cljs | 33 +++++++++++++++------------ 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/src/main/frontend/handler/editor.cljs b/src/main/frontend/handler/editor.cljs index 2340b727537..e92a30daf9f 100644 --- a/src/main/frontend/handler/editor.cljs +++ b/src/main/frontend/handler/editor.cljs @@ -1032,20 +1032,21 @@ key (string/lower-case (str key)) value (str value)] (when-let [block (db/pull [:block/uuid block-id])] - (let [{:block/keys [content properties]} block] - (cond - (and (get properties key) - (= (string/trim (get properties key)) value)) - nil - - :else - (let [properties (:block/properties block) - properties' (if (seq properties) - (assoc properties key value) - {key value})] - (save-block-if-changed! block content - {:custom-properties properties' - :rebuild-content? false}))))))) + (when-not (:block/pre-block? block) + (let [{:block/keys [content properties]} block] + (cond + (and (get properties key) + (= (string/trim (get properties key)) value)) + nil + + :else + (let [properties (:block/properties block) + properties' (if (seq properties) + (assoc properties key value) + {key value})] + (save-block-if-changed! block content + {:custom-properties properties' + :rebuild-content? false})))))))) (defn set-block-timestamp! [block-id key value] @@ -1093,7 +1094,9 @@ (defn copy-block-ref! [block-id] - (set-block-property! block-id "custom_id" (str block-id)) + (let [block (db/entity [:block/uuid block-id])] + (when-not (:block/pre-block? block) + (set-block-property! block-id "custom_id" (str block-id)))) (util/copy-to-clipboard! (str block-id))) (defn clear-selection! From 805f9bb722ea231c23b73292dbda7a4a33e6c4c9 Mon Sep 17 00:00:00 2001 From: Yukun Guo Date: Thu, 5 Nov 2020 15:22:43 +0800 Subject: [PATCH 04/46] fix: use lower case for marker comparison --- src/main/frontend/handler/editor.cljs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/frontend/handler/editor.cljs b/src/main/frontend/handler/editor.cljs index e92a30daf9f..cdc23740b0b 100644 --- a/src/main/frontend/handler/editor.cljs +++ b/src/main/frontend/handler/editor.cljs @@ -743,7 +743,7 @@ properties (into {} (:block/properties block))] (if (and new-marker - (not= new-marker (:block/marker block)) + (not= new-marker (string/lower-case (:block/marker block))) (state/enable-timetracking?)) (assoc properties new-marker (util/time-ms)) properties))) From 201ebf61a92aed9138acff95daaf03a45e12d2ba Mon Sep 17 00:00:00 2001 From: Yukun Guo Date: Thu, 5 Nov 2020 15:31:52 +0800 Subject: [PATCH 05/46] fix: remove content's properties when comparing with value --- src/main/frontend/handler/editor.cljs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/frontend/handler/editor.cljs b/src/main/frontend/handler/editor.cljs index cdc23740b0b..89eeaca0bdf 100644 --- a/src/main/frontend/handler/editor.cljs +++ b/src/main/frontend/handler/editor.cljs @@ -1342,7 +1342,10 @@ (let [state (get-state state) content (:block/content block) value (:value state)] - (when (not= (string/trim (text/remove-level-spaces content format)) + (when (not= (-> content + (text/remove-level-spaces format) + text/remove-properties! + string/trim) (string/trim value)) (save-block! state (:value state)))) (let [block (db/pull (state/get-current-repo) '[*] [:block/uuid (uuid sibling-block-id)])] From 0a5b88467b8ef82af424091e82e9c71227a24c2c Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Thu, 5 Nov 2020 16:52:07 +0800 Subject: [PATCH 06/46] fix: repeated tasks 1. Don't show repeat kinds selection (.+, ++, +) 2. Fixed wrong time (no zero padding) 3. Fixed `.+` and `++` behaviors --- src/main/frontend/components/datetime.cljs | 87 +++++++++++----------- src/main/frontend/date.cljs | 4 + src/main/frontend/format/block.cljs | 2 +- src/main/frontend/handler/editor.cljs | 20 +++-- src/main/frontend/handler/repeated.cljs | 26 ++++--- 5 files changed, 77 insertions(+), 62 deletions(-) diff --git a/src/main/frontend/components/datetime.cljs b/src/main/frontend/components/datetime.cljs index 78e1792e7bb..1c3f8709216 100644 --- a/src/main/frontend/components/datetime.cljs +++ b/src/main/frontend/components/datetime.cljs @@ -44,7 +44,9 @@ [{:keys [num duration kind]}] (let [show? (rum/react *show-repeater?)] (if (or show? (and num duration kind)) - [:div.flex.flex-row {:style {:height 32}} + [:div.flex.flex-row.justify-center {:style {:height 32}} + [:div.block.text-medium.mr-2.mt-1 {:style {:width 110}} + "Every"] [:input#repeater-num.form-input.mt-1 {:style {:width 48} :default-value num @@ -52,29 +54,29 @@ (let [value (util/evalue event)] (swap! *timestamp assoc-in [:repeater :num] value)))}] (ui/select - (mapv - (fn [item] - (if (= (:label item) duration) - (assoc item :selected "selected") - item)) - [{:label "h"} - {:label "d"} - {:label "w"} - {:label "m"} - {:label "y"}]) - (fn [value] - (swap! *timestamp assoc-in [:repeater :duration] value))) - (ui/select - (mapv - (fn [item] - (if (= (:label item) kind) - (assoc item :selected "selected") - item)) - [{:label ".+"} - {:label "+"} - {:label "++"}]) - (fn [value] - (swap! *timestamp assoc-in [:repeater :kind] value))) + (mapv + (fn [item] + (if (= (:label item) duration) + (assoc item :selected "selected") + item)) + [{:label "h"} + {:label "d"} + {:label "w"} + {:label "m"} + {:label "y"}]) + (fn [value] + (swap! *timestamp assoc-in [:repeater :duration] value))) + ;; (ui/select + ;; (mapv + ;; (fn [item] + ;; (if (= (:label item) kind) + ;; (assoc item :selected "selected") + ;; item)) + ;; [{:label "++"} + ;; {:label "+"} + ;; {:label ".+"}]) + ;; (fn [value] + ;; (swap! *timestamp assoc-in [:repeater :kind] value))) [:a.ml-2.self-center {:on-click (fn [] (reset! *show-repeater? false) @@ -85,7 +87,7 @@ (swap! *timestamp assoc :repeater {:kind ".+" :num 1 - :duration "h"}))} + :duration "d"}))} "Add repeater"]))) (defn clear-timestamp! @@ -100,6 +102,8 @@ timestamp (if date timestamp (assoc timestamp :date (t/today))) + kind (if (= "w" (:duration repeater)) "++" ".+") + timestamp (assoc-in timestamp [:repeater :kind] kind) text (repeated/timestamp-map->text timestamp)] [:div.py-1.px-4 {:style {:min-width 300}} [:p.text-sm.opacity-50.font-medium.mt-4 "Time:"] @@ -110,21 +114,21 @@ [:p.mt-4 (ui/button "Submit" - :on-click (fn [e] - (util/stop e) - (let [block-data (state/get-timestamp-block)] - (let [{:keys [block typ show?]} block-data - block-id (or (:block/uuid (state/get-edit-block)) - (:block/uuid block)) - typ (or typ @commands/*current-command)] - (editor-handler/set-block-timestamp! block-id - typ - text) - (state/clear-edit!) - (when show? - (reset! show? false)))) - (clear-timestamp!) - (state/set-editor-show-date-picker false)))]])) + :on-click (fn [e] + (util/stop e) + (let [block-data (state/get-timestamp-block)] + (let [{:keys [block typ show?]} block-data + block-id (or (:block/uuid (state/get-edit-block)) + (:block/uuid block)) + typ (or typ @commands/*current-command)] + (editor-handler/set-block-timestamp! block-id + typ + text) + (state/clear-edit!) + (when show? + (reset! show? false)))) + (clear-timestamp!) + (state/set-editor-show-date-picker false)))]])) (rum/defc date-picker < rum/reactive {:init (fn [state] @@ -163,8 +167,7 @@ (util/format "[[%s]]" journal) format nil) - (state/set-editor-show-date-picker false) -) + (state/set-editor-show-date-picker false)) (swap! *timestamp assoc :date date)))}) (when deadline-or-schedule? (time-repeater))]))) diff --git a/src/main/frontend/date.cljs b/src/main/frontend/date.cljs index 5ce4bed43f3..9e671e97006 100644 --- a/src/main/frontend/date.cljs +++ b/src/main/frontend/date.cljs @@ -39,6 +39,10 @@ (defn get-date-time-string [date-time] (tf/unparse custom-formatter date-time)) +(defn get-local-date-time-string + [] + (get-date-time-string (tl/local-now))) + (def custom-formatter-2 (tf/formatter "yyyy-MM-dd-HH-mm-ss")) (defn get-date-time-string-2 [] diff --git a/src/main/frontend/format/block.cljs b/src/main/frontend/format/block.cljs index 1957341bc8d..f886f02f7d0 100644 --- a/src/main/frontend/format/block.cljs +++ b/src/main/frontend/format/block.cljs @@ -132,7 +132,7 @@ (map (fn [[k v]] (let [{:keys [date repetition]} v {:keys [year month day]} date - day (js/parseInt (str year month day))] + day (js/parseInt (str year (util/zero-pad month) (util/zero-pad day)))] (cond-> (case k :scheduled diff --git a/src/main/frontend/handler/editor.cljs b/src/main/frontend/handler/editor.cljs index 89eeaca0bdf..98c09e6a0c6 100644 --- a/src/main/frontend/handler/editor.cljs +++ b/src/main/frontend/handler/editor.cljs @@ -811,13 +811,19 @@ (defn update-timestamps-content! [{:block/keys [repeated? scheduled-ast deadline-ast marker]} content] (if repeated? - (some->> (filter repeated/repeated? [scheduled-ast deadline-ast]) - (map (fn [ts] - [(repeated/timestamp->text ts) - (repeated/next-timestamp-text ts)])) - (reduce (fn [content [old new]] - (string/replace content old new)) - content)) + (let [content (some->> (filter repeated/repeated? [scheduled-ast deadline-ast]) + (map (fn [ts] + [(repeated/timestamp->text ts) + (repeated/next-timestamp-text ts)])) + (reduce (fn [content [old new]] + (string/replace content old new)) + content))] + (when content + (str (string/trimr content) + "\n" + (util/format "- %s -> DONE [%s]" + marker + (date/get-local-date-time-string))))) content)) (defn- with-marker-time diff --git a/src/main/frontend/handler/repeated.cljs b/src/main/frontend/handler/repeated.cljs index e13559785d8..ab7b27d9cb3 100644 --- a/src/main/frontend/handler/repeated.cljs +++ b/src/main/frontend/handler/repeated.cljs @@ -67,7 +67,8 @@ (defn- repeat-until-future-timestamp [datetime now delta keep-week?] - (let [result (loop [result datetime] + (let [datetime (t/plus datetime delta) + result (loop [result datetime] (if (t/after? result now) result (recur (t/plus result delta)))) @@ -80,29 +81,30 @@ (t/plus result (t/days (- w1 w2)))) result))) -;; Fro https://www.reddit.com/r/orgmode/comments/hr2ytg/difference_between_the_repeaters_orgzly/fy2izqx?utm_source=share&utm_medium=web2x&context=3 -;; I use these repeaters for habit tracking and it can get a little tricky to keep track. This is my short form understanding: -;; ".+X" = repeat in X d/w/m from the last time I marked it done -;; "++X" = repeat in at least X d/w/m from the last time I marked it done and keep it on the same day of the week move the due date into the future by increments of d/w/m. If the due date, after being moved forward X d/w/m is still in the past, adjust it by however many d/w/m needed to get it into the future. For the w, the day of the week is kept constant. -;; "+X" = repeat in X d/w/m from when I originally scheduled it, regardless of when I marked it done. Rarely used (as described by u/serendependy). A relevant case would be "paying rent" from the link. (defn next-timestamp-text [{:keys [date wday repetition time active] :as timestamp}] (let [{:keys [year month day]} date {:keys [hour min] :or {hour 0 min 0}} time [[kind] [duration] num] repetition + week? (or (= duration "Week") + (= duration "w")) [duration-f _] (get-duration-f-and-text duration) delta (duration-f num) today (date/get-local-date) start-time (t/local-date-time year month day hour min) - start-time' (if (or (= kind "Dotted") - (= kind "DoublePlus")) - (if (t/before? (tl/local-now) start-time) + now (tl/local-now) + start-time' (case kind + "Dotted" + (if (t/after? start-time now) start-time + (t/plus now delta)) - ;; Repeatedly add delta to make it a future timestamp - (repeat-until-future-timestamp start-time (tl/local-now) delta - (= kind "DoublePlus"))) + "DoublePlus" + ;; Repeatedly add delta to make it a future timestamp + (repeat-until-future-timestamp start-time now delta week?) + + ;; Dotted and Plus (t/plus start-time delta))] (timestamp->text timestamp start-time'))) From 053bd783d700a4f07abd8fa5060e1b411b7e2eb3 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Thu, 5 Nov 2020 17:05:33 +0800 Subject: [PATCH 07/46] Remove outdated comments --- src/main/frontend/handler/repeated.cljs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/frontend/handler/repeated.cljs b/src/main/frontend/handler/repeated.cljs index ab7b27d9cb3..eeffcf381b1 100644 --- a/src/main/frontend/handler/repeated.cljs +++ b/src/main/frontend/handler/repeated.cljs @@ -101,10 +101,9 @@ (t/plus now delta)) "DoublePlus" - ;; Repeatedly add delta to make it a future timestamp (repeat-until-future-timestamp start-time now delta week?) - ;; Dotted and Plus + ;; "Plus" (t/plus start-time delta))] (timestamp->text timestamp start-time'))) From 42f45f84b0cafaa64b27c6bbfb09ae90b35b5510 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Thu, 5 Nov 2020 17:31:40 +0800 Subject: [PATCH 08/46] Remove commented code --- src/main/frontend/components/datetime.cljs | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/main/frontend/components/datetime.cljs b/src/main/frontend/components/datetime.cljs index 1c3f8709216..b30109dd566 100644 --- a/src/main/frontend/components/datetime.cljs +++ b/src/main/frontend/components/datetime.cljs @@ -66,17 +66,6 @@ {:label "y"}]) (fn [value] (swap! *timestamp assoc-in [:repeater :duration] value))) - ;; (ui/select - ;; (mapv - ;; (fn [item] - ;; (if (= (:label item) kind) - ;; (assoc item :selected "selected") - ;; item)) - ;; [{:label "++"} - ;; {:label "+"} - ;; {:label ".+"}]) - ;; (fn [value] - ;; (swap! *timestamp assoc-in [:repeater :kind] value))) [:a.ml-2.self-center {:on-click (fn [] (reset! *show-repeater? false) From 5c06abdf4dc07af2a5bd4e8a39737c011000a9d7 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Thu, 5 Nov 2020 17:54:39 +0800 Subject: [PATCH 09/46] chore: bump minor version --- src/main/frontend/version.cljs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/frontend/version.cljs b/src/main/frontend/version.cljs index d601be9c927..8c820ce11cc 100644 --- a/src/main/frontend/version.cljs +++ b/src/main/frontend/version.cljs @@ -1,3 +1,3 @@ (ns frontend.version) -(defonce version "0.0.4.3-5") +(defonce version "0.0.4.3-6") From d23a3c983006531abf29e6d100687a23213049e8 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Thu, 5 Nov 2020 18:00:41 +0800 Subject: [PATCH 10/46] fix(editor): :black/marker might be empty --- src/main/frontend/handler/editor.cljs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/frontend/handler/editor.cljs b/src/main/frontend/handler/editor.cljs index 98c09e6a0c6..2651f2f9d4d 100644 --- a/src/main/frontend/handler/editor.cljs +++ b/src/main/frontend/handler/editor.cljs @@ -743,7 +743,7 @@ properties (into {} (:block/properties block))] (if (and new-marker - (not= new-marker (string/lower-case (:block/marker block))) + (not= new-marker (string/lower-case (or :block/marker block ""))) (state/enable-timetracking?)) (assoc properties new-marker (util/time-ms)) properties))) From 613c70a7b7da73f18763ee74ca10f224e5f1ee41 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Thu, 5 Nov 2020 18:04:49 +0800 Subject: [PATCH 11/46] fix(editor): fix empty :block/marker --- src/main/frontend/handler/editor.cljs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/frontend/handler/editor.cljs b/src/main/frontend/handler/editor.cljs index 2651f2f9d4d..defd6a07ce9 100644 --- a/src/main/frontend/handler/editor.cljs +++ b/src/main/frontend/handler/editor.cljs @@ -743,7 +743,7 @@ properties (into {} (:block/properties block))] (if (and new-marker - (not= new-marker (string/lower-case (or :block/marker block ""))) + (not= new-marker (string/lower-case (or (:block/marker block) ""))) (state/enable-timetracking?)) (assoc properties new-marker (util/time-ms)) properties))) From 36156f59766822cce6327a1ac371fe578aa9bcf1 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Thu, 5 Nov 2020 18:20:13 +0800 Subject: [PATCH 12/46] fix(editor): move scheduled and deadline to custom queries Resolved https://github.com/logseq/logseq/issues/514 --- src/main/frontend/db.cljs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/frontend/db.cljs b/src/main/frontend/db.cljs index c52a407b395..181259c5dd2 100644 --- a/src/main/frontend/db.cljs +++ b/src/main/frontend/db.cljs @@ -1742,15 +1742,15 @@ (when-let [date (date/journal-title->int journal-title)] (when-let [repo (state/get-current-repo)] (when-let [conn (get-conn repo)] - (->> (d/q - '[:find (pull ?block [*]) - :in $ ?day - :where - (or - [?block :block/scheduled ?day] - [?block :block/deadline ?day])] - conn - date) + (->> (q repo [:custom :scheduled-deadline journal-title] {} + '[:find (pull ?block [*]) + :in $ ?day + :where + (or + [?block :block/scheduled ?day] + [?block :block/deadline ?day])] + date) + react seq-flatten sort-blocks group-by-page From b549f036ea198065fa3709f26d754fe00010f391 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Thu, 5 Nov 2020 22:42:13 +0800 Subject: [PATCH 13/46] fix(editor): try to fix input lag Related to https://github.com/logseq/logseq/issues/572 --- src/main/frontend/mixins.cljs | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/src/main/frontend/mixins.cljs b/src/main/frontend/mixins.cljs index c43d6ea4141..c11522e1fbb 100644 --- a/src/main/frontend/mixins.cljs +++ b/src/main/frontend/mixins.cljs @@ -195,26 +195,16 @@ ([m enable-f target] (when (seq m) (let [target-fn (if (fn? target) target (fn [_] target))] - {:did-mount - (fn [state] - (if (enable-f state) - (let [keyboards (doall - (map - (fn [[key f]] - [key - (keyboard/install-shortcut! key - (fn [e] (f state e)) - false - (target-fn state))]) - m))] - (assoc state ::keyboards-listener keyboards)) - state)) - :will-unmount + {:init (fn [state] (when (enable-f state) - (doseq [[_k f] (get state ::keyboards-listener)] - (f))) - state)})))) + (doseq [[key f] m] + (keyboard/install-shortcut! key + (fn [e] (f state e)) + true + (target-fn state)) + m) + state))})))) ;; also, from https://github.com/tonsky/rum/blob/75174b9ea0cf4b7a761d9293929bd40c95d35f74/doc/useful-mixins.md (defn perf-measure-mixin From 2cc45fbf9dc466fac2c9cf2e19621317bec2049e Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Thu, 5 Nov 2020 23:15:23 +0800 Subject: [PATCH 14/46] fix: alias --- src/main/frontend/components/block.cljs | 10 ++++++---- src/main/frontend/components/page.cljs | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main/frontend/components/block.cljs b/src/main/frontend/components/block.cljs index b85edbcef0d..0f47872428d 100644 --- a/src/main/frontend/components/block.cljs +++ b/src/main/frontend/components/block.cljs @@ -935,8 +935,9 @@ (defn property-value [format v] - (let [inline-list (mldoc/inline->edn v (mldoc/default-config format))] - [:div.inline (map-inline {} inline-list)])) + (when (string? v) + (let [inline-list (mldoc/inline->edn v (mldoc/default-config format))] + [:div.inline.mr-1 (map-inline {} inline-list)]))) (rum/defc properties-cp [block] @@ -1525,7 +1526,8 @@ [:span.font-medium.mr-1 (string/upper-case (str (name k) ": "))] (if (coll? v) (for [item v] - (if (= k :tags) + (if (or (= k :tags) + (= k :alias)) (if (string/includes? item "[[") (property-value format item) (let [tag (-> item @@ -1534,7 +1536,7 @@ (string/replace "#" ""))] [:a.tag.mr-1 {:href (rfe/href :page {:name tag})} tag])) - (property-value format v))) + (property-value format item))) (property-value format v))])))] ["Paragraph" l] diff --git a/src/main/frontend/components/page.cljs b/src/main/frontend/components/page.cljs index 50b45851e33..661f4e57925 100644 --- a/src/main/frontend/components/page.cljs +++ b/src/main/frontend/components/page.cljs @@ -359,7 +359,7 @@ (when (seq alias) [:div.text-sm.ml-1.mb-4 {:key "page-file"} [:span.opacity-50 "Alias: "] - (for [item alias] + (for [item (reverse alias)] [:a.p-1.ml-1 {:href (str "/page/" (util/encode-str item))} item])]))) From 8edff5ec0ccf8623ba1dfebc9e7c7fb10f46b5d5 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Thu, 5 Nov 2020 23:37:45 +0800 Subject: [PATCH 15/46] fix: alias relationship --- src/main/frontend/db.cljs | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/main/frontend/db.cljs b/src/main/frontend/db.cljs index 181259c5dd2..bbd2bf492d5 100644 --- a/src/main/frontend/db.cljs +++ b/src/main/frontend/db.cljs @@ -748,13 +748,24 @@ :in $ ?page-name :where [?page :page/name ?page-name] - [?page :page/alias ?alias] - [?page :page/journal? false]] + [?page :page/alias ?alias]] conn page-name) seq-flatten distinct))) +(defn get-alias-page + [repo alias] + (when-let [conn (and repo (get-conn repo))] + (some->> (d/q '[:find ?page + :in $ ?alias + :where + [?page :page/alias ?alias]] + conn + alias) + seq-flatten + distinct))) + (defn get-page-alias-names [repo page-name] (let [alias-ids (get-page-alias repo page-name)] @@ -958,7 +969,13 @@ (defn page-alias-set [repo-url page] (when-let [page-id (:db/id (entity [:page/name page]))] - (let [aliases (get-page-alias repo-url page)] + (let [aliases (get-page-alias repo-url page) + aliases (if (seq aliases) + (set + (concat + (mapcat #(get-alias-page repo-url %) aliases) + aliases)) + aliases)] (set (conj aliases page-id))))) (defn page-blocks-transform From 87f31c1b9f68b1562d2a9cbfab37a4c0e4527e62 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Thu, 5 Nov 2020 23:46:05 +0800 Subject: [PATCH 16/46] fix: alias delete not working --- src/main/frontend/components/editor.cljs | 40 ++++++++++++------------ src/main/frontend/components/page.cljs | 9 ------ src/main/frontend/handler/file.cljs | 7 ++++- 3 files changed, 26 insertions(+), 30 deletions(-) diff --git a/src/main/frontend/components/editor.cljs b/src/main/frontend/components/editor.cljs index 33085c207f1..fab779427b5 100644 --- a/src/main/frontend/components/editor.cljs +++ b/src/main/frontend/components/editor.cljs @@ -302,21 +302,21 @@ [:input.form-input.block.w-full.pl-2.sm:text-sm.sm:leading-5 (merge (cond-> - {:key (str "modal-input-" (name id)) - :id (str "modal-input-" (name id)) - :type (or type "text") - :on-change (fn [e] - (swap! input-value assoc id (util/evalue e))) - :auto-complete (if (util/chrome?) "chrome-off" "off")} + {:key (str "modal-input-" (name id)) + :id (str "modal-input-" (name id)) + :type (or type "text") + :on-change (fn [e] + (swap! input-value assoc id (util/evalue e))) + :auto-complete (if (util/chrome?) "chrome-off" "off")} placeholder (assoc :placeholder placeholder)) (dissoc input-item :id))]]) (ui/button - "Submit" - :on-click - (fn [e] - (util/stop e) - (on-submit command @input-value pos)))]))))) + "Submit" + :on-click + (fn [e] + (util/stop e) + (on-submit command @input-value pos)))]))))) (rum/defc absolute-modal < rum/static [cp set-default-width? {:keys [top left]}] @@ -638,17 +638,17 @@ (let [target (.-target e)] (when-not (d/has-class? target "bottom-action") (let [{:keys [on-hide format value block id repo dummy?]} (get-state state)] - (when on-hide - (on-hide value event)) - (when - (or (= event :esc) - (= event :visibilitychange) - (and (= event :click) - (not (editor-handler/in-auto-complete? (gdom/getElement id))))) - (state/clear-edit!)))))) + (when on-hide + (on-hide value event)) + (when + (or (= event :esc) + (= event :visibilitychange) + (and (= event :click) + (not (editor-handler/in-auto-complete? (gdom/getElement id))))) + (state/clear-edit!)))))) :node (gdom/getElement id) ;; :visibilitychange? true - )) +)) 100) (when-let [element (gdom/getElement id)] diff --git a/src/main/frontend/components/page.cljs b/src/main/frontend/components/page.cljs index 661f4e57925..001c655267e 100644 --- a/src/main/frontend/components/page.cljs +++ b/src/main/frontend/components/page.cljs @@ -354,15 +354,6 @@ :href (str "/file/" (util/url-encode file-path))} file-path]])] - (when (and repo (not journal?) (not block?)) - (let [alias (db/get-page-alias-names repo page-name)] - (when (seq alias) - [:div.text-sm.ml-1.mb-4 {:key "page-file"} - [:span.opacity-50 "Alias: "] - (for [item (reverse alias)] - [:a.p-1.ml-1 {:href (str "/page/" (util/encode-str item))} - item])]))) - (when (and block? (not sidebar?)) [:div.mb-4 (block/block-parents repo block-id format)]) diff --git a/src/main/frontend/handler/file.cljs b/src/main/frontend/handler/file.cljs index 7edd4aeb6b7..190e4f78c05 100644 --- a/src/main/frontend/handler/file.cljs +++ b/src/main/frontend/handler/file.cljs @@ -111,7 +111,12 @@ update-status? false}}] (let [original-content (db/get-file-no-sub repo path)] (if reset? - (db/reset-file! repo path content) + (do + (when-let [page-id (db/get-file-page-id path)] + (db/transact! repo + [[:db/retract page-id :page/alias] + [:db/retract page-id :page/tags]])) + (db/reset-file! repo path content)) (db/set-file-content! repo path content)) (util/p-handle (fs/write-file (util/get-repo-dir repo) path content) From fdd3782ba2e3a296871530ae5b7ad125ca4da17f Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Thu, 5 Nov 2020 23:50:39 +0800 Subject: [PATCH 17/46] fix: alias support chinese comma --- src/main/frontend/format/mldoc.cljs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/frontend/format/mldoc.cljs b/src/main/frontend/format/mldoc.cljs index 0fcbe52959c..6107e69e01d 100644 --- a/src/main/frontend/format/mldoc.cljs +++ b/src/main/frontend/format/mldoc.cljs @@ -32,9 +32,9 @@ (defn- sep-by-quote-or-space-or-comma [s] (when s - (let [comma? (re-find #"," s)] + (let [comma? (re-find #"[,|,]+" s)] (some->> - (string/split s #"[\"|\,]{1}") + (string/split s #"[\"|\,|,]{1}") (remove string/blank?) (map (fn [s] (if (and (not comma?) From db412b0935e06248c557ac3262916c71b80103e6 Mon Sep 17 00:00:00 2001 From: Runjuu Date: Thu, 5 Nov 2020 16:39:20 +0800 Subject: [PATCH 18/46] fix(sidebar/main-content): mobile layout issues --- src/main/frontend/components/sidebar.cljs | 22 +++++++-------------- src/main/frontend/components/sidebar.css | 24 +++++++++++++++++++++++ 2 files changed, 31 insertions(+), 15 deletions(-) create mode 100644 src/main/frontend/components/sidebar.css diff --git a/src/main/frontend/components/sidebar.cljs b/src/main/frontend/components/sidebar.cljs index 58b8f2f0c71..3dec701dcdf 100644 --- a/src/main/frontend/components/sidebar.cljs +++ b/src/main/frontend/components/sidebar.cljs @@ -417,21 +417,13 @@ (if white? "#f0f8ff" "#073642"))}} (when (state/sub :ui/left-sidebar-open?) (sidebar-nav route-match nil))]) - [:div.flex.#main-content-container.justify-center - {:class (if global-graph-pages? - "initial" - (util/hiccup->class ".mx-6.my-12")) - :style {:position "relative" - :flex "1 1 65%" - :width "100vw"}} - [:div.flex-1 - {:style (cond-> - {:max-width 640} - (or global-graph-pages? - (and (not logged?) - home?) - (contains? #{:all-files :all-pages} route-name)) - (dissoc :max-width))} + [:div#main-content-container.cp__sidebar-main-content-container + [:div.cp__sidebar-main-content + {:data-is-global-graph-pages global-graph-pages? + :data-is-full-width (or global-graph-pages? + (and (not logged?) + home?) + (contains? #{:all-files :all-pages} route-name))} (cond (not indexeddb-support?) nil diff --git a/src/main/frontend/components/sidebar.css b/src/main/frontend/components/sidebar.css new file mode 100644 index 00000000000..e3a1fb56fb6 --- /dev/null +++ b/src/main/frontend/components/sidebar.css @@ -0,0 +1,24 @@ +.cp__sidebar-main-content-container { + position: relative; + flex: 1 1 65%; +} + +.cp__sidebar-main-content { + padding: 3rem 1.5rem; + margin: 0 auto; + max-width: 640px; +} + +@media (max-width: 640px) { + .cp__sidebar-main-content { + max-width: 100vw; + } +} + +.cp__sidebar-main-content[data-is-full-width="true"] { + max-width: 100vw; +} + +.cp__sidebar-main-content[data-is-global-graph-pages="true"] { + padding: 0; +} From ea44608ca4faaf05782c49319c58d897512f06a0 Mon Sep 17 00:00:00 2001 From: Runjuu Date: Thu, 5 Nov 2020 17:45:58 +0800 Subject: [PATCH 19/46] fix(component/diff): style issues - avoid header content overflow - make diff file scrollable --- src/main/frontend/components/diff.cljs | 26 +++++++++----------------- src/main/frontend/components/diff.css | 22 ++++++++++++++++++++++ 2 files changed, 31 insertions(+), 17 deletions(-) create mode 100644 src/main/frontend/components/diff.css diff --git a/src/main/frontend/components/diff.cljs b/src/main/frontend/components/diff.cljs index e04d047a9ab..c013610529a 100644 --- a/src/main/frontend/components/diff.cljs +++ b/src/main/frontend/components/diff.cljs @@ -53,22 +53,14 @@ [repo type path contents remote-oid component] (let [{:keys [collapse? resolved?]} (util/react (rum/cursor diff-state path)) edit? (util/react *edit?)] - [:div.mb-3 {:style {:border "1px solid #ddd" - :border-radius 3}} - [:div.flex.flex-row.items-center.justify-between.bg-base-2 - {:style {:padding "5px 10px" - :border-bottom "1px solid #e1e4e8" - :border-top-left-radius 3 - :border-top-right-radius 3}} - [:div.flex.flex-row.items-center - [:a.mr-2 {:on-click (fn [] (toggle-collapse? path))} - (if collapse? - (svg/arrow-right) - (svg/arrow-down))] - [:span - path - [:span.text-sm.font-medium.ml-2.border.rounded.px-1 - type]]] + [:div.cp__diff-file + [:div.cp__diff-file-header + [:a.mr-2 {:on-click (fn [] (toggle-collapse? path))} + (if collapse? + (svg/arrow-right) + (svg/arrow-down))] + [:span.cp__diff-file-header-content path] + [:span.cp__diff-file-header-type type] (when resolved? [:span.text-green-600 {:dangerouslySetInnerHTML @@ -82,7 +74,7 @@ (or added removed)) diff)] [:div.pre-line-white-space.p-2 {:class (if collapse? "hidden") - :style {:overflow "hidden"}} + :style {:overflow "auto"}} (if edit? [:div.grid.grid-cols-2.gap-1 (diff-cp diff) diff --git a/src/main/frontend/components/diff.css b/src/main/frontend/components/diff.css new file mode 100644 index 00000000000..d85fb271d06 --- /dev/null +++ b/src/main/frontend/components/diff.css @@ -0,0 +1,22 @@ +.cp__diff-file { + @apply mb-3; + border: 1px solid #ddd; + border-radius: 3px; +} + +.cp__diff-file-header { + background-color: var(--ls-secondary-background-color); + padding: 5px 10px; + border-bottom: 1px solid #e1e4e8; + border-radius: 3px 3px 0 0; + display: flex; + align-items: center; +} + +.cp__diff-file-header-content { + @apply truncate +} + +.cp__diff-file-header-type { + @apply text-sm font-medium ml-2 border rounded px-1; +} From e53d4cdd4785811428c90acc7ad90dc9c6355244 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Sat, 7 Nov 2020 14:12:21 +0800 Subject: [PATCH 20/46] feat: add embed pages to references and graph view Resolved https://github.com/logseq/logseq/issues/166. --- src/main/frontend/format/block.cljs | 80 +++++++++++++++++++---------- 1 file changed, 52 insertions(+), 28 deletions(-) diff --git a/src/main/frontend/format/block.cljs b/src/main/frontend/format/block.cljs index f886f02f7d0..8bae7df64eb 100644 --- a/src/main/frontend/format/block.cljs +++ b/src/main/frontend/format/block.cljs @@ -24,37 +24,61 @@ (defn get-page-reference [block] - (cond - (and (vector? block) (= "Link" (first block))) - (let [typ (first (:url (second block)))] - (or - (and - (= typ "Search") - (not (contains? #{\# \* \/ \( \[} (first (second (:url (second block)))))) - (let [page (second (:url (second block)))] - (when (and (not (util/starts-with? page "http")) - (not (util/starts-with? page "file")) - (not (string/ends-with? page ".html"))) - page))) - - (and - (= typ "Complex") - (= (:protocol (second (:url (second block)))) "file") - (:link (second (:url (second block))))))) - - (and (vector? block) (= "Nested_link" (first block))) - (let [content (:content (last block))] - (subs content 2 (- (count content) 2))) - - :else - nil)) + (let [page (cond + (and (vector? block) (= "Link" (first block))) + (let [typ (first (:url (second block)))] + (or + (and + (= typ "Search") + (not (contains? #{\# \* \/ \( \[} (first (second (:url (second block)))))) + (let [page (second (:url (second block)))] + (when (and (not (util/starts-with? page "http")) + (not (util/starts-with? page "file")) + (not (string/ends-with? page ".html"))) + page))) + + (and + (= typ "Complex") + (= (:protocol (second (:url (second block)))) "file") + (:link (second (:url (second block))))))) + + (and (vector? block) (= "Nested_link" (first block))) + (let [content (:content (last block))] + (subs content 2 (- (count content) 2))) + + (and (vector? block) + (= "Macro" (first block))) + (let [{:keys [name arguments]} (second block)] + (when (and (= name "embed") + (string? (first arguments)) + (string/starts-with? (first arguments) "[[") + (string/ends-with? (first arguments) "]]")) + (subs (first arguments) 2 (- (count (first arguments)) 2)))) + :else + nil)] + (when-not (string/blank? page) + (string/trim page)))) (defn get-block-reference [block] - (when-let [block-id (and (vector? block) - (= "Block_reference" (first block)) - (last block))] - (when (util/uuid-string? block-id) + (when-let [block-id (cond + (and (vector? block) + (= "Block_reference" (first block))) + (last block) + + (and (vector? block) + (= "Macro" (first block))) + (let [{:keys [name arguments]} (second block)] + (when (and (= name "embed") + (string? (first arguments)) + (string/starts-with? (first arguments) "((") + (string/ends-with? (first arguments) "))")) + (subs (first arguments) 2 (- (count (first arguments)) 2)))) + + :else + nil)] + (when (and block-id + (util/uuid-string? block-id)) block-id))) ;; FIXME: From 32e398a087e429724af6ee490b2b5201d0ddb1e6 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Sat, 7 Nov 2020 15:16:16 +0800 Subject: [PATCH 21/46] fix: get page references (trim) --- src/main/frontend/format/block.cljs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/frontend/format/block.cljs b/src/main/frontend/format/block.cljs index 8bae7df64eb..5f34771136e 100644 --- a/src/main/frontend/format/block.cljs +++ b/src/main/frontend/format/block.cljs @@ -56,7 +56,9 @@ (subs (first arguments) 2 (- (count (first arguments)) 2)))) :else nil)] - (when-not (string/blank? page) + (when (and + (string? page) + (not (string/blank? page))) (string/trim page)))) (defn get-block-reference From c88c1ee685148fd86a88d941f29cae15edcdc6c3 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Sat, 7 Nov 2020 15:16:42 +0800 Subject: [PATCH 22/46] chore: bump minor version --- src/main/frontend/version.cljs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/frontend/version.cljs b/src/main/frontend/version.cljs index 8c820ce11cc..690eb1e4605 100644 --- a/src/main/frontend/version.cljs +++ b/src/main/frontend/version.cljs @@ -1,3 +1,3 @@ (ns frontend.version) -(defonce version "0.0.4.3-6") +(defonce version "0.0.4.3-7") From 9488ee2e03a845e34d2fef3ddf45987f9d564fbe Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Sat, 7 Nov 2020 15:56:01 +0800 Subject: [PATCH 23/46] fix: try to address duplicated journals related to https://github.com/logseq/logseq/issues/595 --- src/main/frontend/db.cljs | 18 ++++++++++-------- src/main/frontend/handler.cljs | 9 +++++---- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/main/frontend/db.cljs b/src/main/frontend/db.cljs index bbd2bf492d5..4a17a3a66eb 100644 --- a/src/main/frontend/db.cljs +++ b/src/main/frontend/db.cljs @@ -1872,14 +1872,16 @@ (defn cloned? [repo-url] - (-> - (d/q '[:find ?cloned - :in $ ?repo-url - :where - [?repo :repo/url ?repo-url] - [?repo :repo/cloned? ?cloned]] - (get-conn repo-url) repo-url) - ffirst)) + (when-let [conn (get-conn repo-url)] + (-> + (d/q '[:find ?cloned + :in $ ?repo-url + :where + [?repo :repo/url ?repo-url] + [?repo :repo/cloned? ?cloned]] + conn + repo-url) + ffirst))) (defn reset-config! [repo-url content] diff --git a/src/main/frontend/handler.cljs b/src/main/frontend/handler.cljs index 58ae19b2cba..47c7167b530 100644 --- a/src/main/frontend/handler.cljs +++ b/src/main/frontend/handler.cljs @@ -19,9 +19,10 @@ (js/setInterval (fn [] (state/set-today! (date/today)) (when-let [repo (state/get-current-repo)] - (let [today-page (string/lower-case (date/today))] - (when (empty? (db/get-page-blocks-no-cache repo today-page)) - (repo-handler/create-today-journal-if-not-exists repo))))) + (when (db/cloned? repo) + (let [today-page (string/lower-case (date/today))] + (when (empty? (db/get-page-blocks-no-cache repo today-page)) + (repo-handler/create-today-journal-if-not-exists repo)))))) 1000)) (defn restore-and-setup! @@ -70,7 +71,7 @@ (or force? (and (state/get-edit-input-id) (> (- (util/time-ms) last-stored-at) (* 5 60 1000)) ; 5 minutes - ) +) (nil? (state/get-edit-input-id)))) (p/let [_ (repo-handler/persist-repo! repo)] (state/update-repo-last-stored-at! repo))))))) From 8d8f1b40a52ff4ac8455eae8faaa1f10e5b613d9 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Sat, 7 Nov 2020 16:02:13 +0800 Subject: [PATCH 24/46] chore: don't show project created when it's already existed --- src/main/frontend/handler/project.cljs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/frontend/handler/project.cljs b/src/main/frontend/handler/project.cljs index e23f61cdbc4..faff5593e92 100644 --- a/src/main/frontend/handler/project.cljs +++ b/src/main/frontend/handler/project.cljs @@ -24,11 +24,12 @@ (util/post (str config/api "projects") data (fn [result] - (swap! state/state - update-in [:me :projects] - (fn [projects] - (util/distinct-by :name (conj projects result)))) - (ok-handler project)) + (when-not (:message result) ; exists + (swap! state/state + update-in [:me :projects] + (fn [projects] + (util/distinct-by :name (conj projects result)))) + (ok-handler project))) (fn [error] (js/console.dir error) (notification/show! (util/format "Project \"%s\" already taken, please change to another name." project) :error)))))) From 303954feb206d3a52a9f05b525e9f5ade3d9bb44 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Sat, 7 Nov 2020 16:46:11 +0800 Subject: [PATCH 25/46] fix: close dropdown menu after clicking items Resolved https://github.com/logseq/logseq/issues/592 --- src/main/frontend/ui.cljs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/main/frontend/ui.cljs b/src/main/frontend/ui.cljs index 167af3dd05f..bc0a0bc2589 100644 --- a/src/main/frontend/ui.cljs +++ b/src/main/frontend/ui.cljs @@ -46,7 +46,7 @@ (dropdown-content-wrapper dropdown-state modal-content modal-class))))])) (rum/defc menu-link - [options child icon] + [options child] [:a.block.px-4.py-2.text-sm.text-gray-700.transition.ease-in-out.duration-150.cursor.menu-link.overflow-hidden options child]) @@ -70,10 +70,10 @@ [:div {:style {:margin-right "8px"}} title] ;; [:div {:style {:position "absolute" :right "8px"}} ;; icon] - ]] +]] (rum/with-key (menu-link new-options child) - (cljs.core/random-uuid))))]) + title)))]) opts)) (defn button @@ -172,7 +172,7 @@ :key (name k)} (fn [state] (notification-content state (:content v) (:status v) k))))) - contents))))) + contents))))) (defn checkbox [option] @@ -365,7 +365,8 @@ [] (let [modal-panel-content (state/sub :modal/panel-content) show? (boolean modal-panel-content) - close-fn #(state/close-modal!) + close-fn #(fn [] + (state/close-modal!)) modal-panel-content (or modal-panel-content (fn [close] [:div]))] [:div.fixed.bottom-0.inset-x-0.px-4.pb-4.sm:inset-0.sm:flex.sm:items-center.sm:justify-center {:style {:z-index (if show? 10 -1)}} @@ -462,8 +463,8 @@ (on-change value)))} (for [{:keys [label value selected]} options] [:option (cond-> - {:key label - :value (or value label)} + {:key label + :value (or value label)} selected (assoc :selected selected)) label])]) From 553b1079b1f71644cf96119a8503961c1dcf9d84 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Sat, 7 Nov 2020 19:11:39 +0800 Subject: [PATCH 26/46] fix: respect user's preferred format for a specific repo --- resources/css/style.css | 2 +- src/main/frontend/handler/repo.cljs | 107 +++++++++++++--------------- src/main/frontend/state.cljs | 16 +++-- 3 files changed, 60 insertions(+), 65 deletions(-) diff --git a/resources/css/style.css b/resources/css/style.css index f6a056af89a..a8911e32376 100644 --- a/resources/css/style.css +++ b/resources/css/style.css @@ -3,7 +3,7 @@ @import "./reveal.min.css"; @import "./reveal_black.min.css"; @import "./katex.min.css"; -@import "./tailwind.build.css"; /* Build by gulp. Check `_buildTailwind` for more detail */ +@import "../../static/css/tailwind.build.css"; /* Build by gulp. Check `_buildTailwind` for more detail */ @import "./common.css"; @import "./datepicker.css"; @import "./highlight.css"; diff --git a/src/main/frontend/handler/repo.cljs b/src/main/frontend/handler/repo.cljs index 3bfd5a26e2f..8dc14eb0125 100644 --- a/src/main/frontend/handler/repo.cljs +++ b/src/main/frontend/handler/repo.cljs @@ -29,59 +29,6 @@ ;; 1. User changes the config.edn directly in logseq.com (fn: alter-file) ;; 2. Git pulls the new change (fn: load-files) -(defn load-repo-to-db! - [repo-url diffs first-clone?] - (let [load-contents (fn [files delete-files delete-blocks re-render?] - (file-handler/load-files-contents! - repo-url - files - (fn [contents] - (state/set-state! :repo/loading-files? false) - (state/set-state! :repo/importing-to-db? true) - (let [parsed-files (filter - (fn [[file _]] - (let [format (format/get-format file)] - (contains? config/mldoc-support-formats format))) - contents) - blocks-pages (if (seq parsed-files) - (db/extract-all-blocks-pages repo-url parsed-files) - [])] - (db/reset-contents-and-blocks! repo-url contents blocks-pages delete-files delete-blocks) - (let [config-file (str config/app-name "/" config/config-file)] - (when (contains? (set files) config-file) - (when-let [content (get contents config-file)] - (file-handler/restore-config! repo-url content true)))) - ;; (let [metadata-file (str config/app-name "/" config/metadata-file)] - ;; (when (contains? (set files) metadata-file) - ;; (when-let [content (get contents metadata-file)] - ;; (let [{:keys [tx-data]} (reader/read-string content)] - ;; (db/transact! repo-url tx-data))))) - (state/set-state! :repo/importing-to-db? false) - (when re-render? - (ui-handler/re-render-root!))))))] - (if first-clone? - (-> - (p/let [files (file-handler/load-files repo-url)] - (load-contents files nil nil false)) - (p/catch (fn [error] - (println "loading files failed: ") - (js/console.dir error) - (state/set-state! :repo/loading-files? false)))) - (when (seq diffs) - (let [filter-diffs (fn [type] (->> (filter (fn [f] (= type (:type f))) diffs) - (map :path))) - remove-files (filter-diffs "remove") - modify-files (filter-diffs "modify") - add-files (filter-diffs "add") - delete-files (if (seq remove-files) - (db/delete-files remove-files)) - delete-blocks (db/delete-blocks repo-url (concat remove-files modify-files)) - delete-pages (if (seq remove-files) - (db/delete-pages-by-files remove-files) - []) - add-or-modify-files (util/remove-nils (concat add-files modify-files))] - (load-contents add-or-modify-files (concat delete-files delete-pages) delete-blocks true)))))) - (defn show-install-error! [repo-url title] (notification/show! @@ -196,7 +143,7 @@ (create-today-journal-if-not-exists repo-url nil)) ([repo-url content] (let [repo-dir (util/get-repo-dir repo-url) - format (state/get-preferred-format) + format (state/get-preferred-format repo-url) title (date/today) file-name (date/journal-title->default title) default-content (util/default-content-with-title format title false) @@ -240,6 +187,55 @@ (create-today-journal-if-not-exists repo-url) (create-contents-file repo-url))) +(defn load-repo-to-db! + [repo-url diffs first-clone?] + (let [load-contents (fn [files delete-files delete-blocks re-render?] + (file-handler/load-files-contents! + repo-url + files + (fn [contents] + (state/set-state! :repo/loading-files? false) + (state/set-state! :repo/importing-to-db? true) + (let [parsed-files (filter + (fn [[file _]] + (let [format (format/get-format file)] + (contains? config/mldoc-support-formats format))) + contents) + blocks-pages (if (seq parsed-files) + (db/extract-all-blocks-pages repo-url parsed-files) + [])] + (db/reset-contents-and-blocks! repo-url contents blocks-pages delete-files delete-blocks) + (let [config-file (str config/app-name "/" config/config-file)] + (if (contains? (set files) config-file) + (when-let [content (get contents config-file)] + (file-handler/restore-config! repo-url content true)))) + (when first-clone? (create-default-files! repo-url)) + (state/set-state! :repo/importing-to-db? false) + (when re-render? + (ui-handler/re-render-root!))))))] + (if first-clone? + (-> + (p/let [files (file-handler/load-files repo-url)] + (load-contents files nil nil false)) + (p/catch (fn [error] + (println "loading files failed: ") + (js/console.dir error) + (state/set-state! :repo/loading-files? false)))) + (when (seq diffs) + (let [filter-diffs (fn [type] (->> (filter (fn [f] (= type (:type f))) diffs) + (map :path))) + remove-files (filter-diffs "remove") + modify-files (filter-diffs "modify") + add-files (filter-diffs "add") + delete-files (if (seq remove-files) + (db/delete-files remove-files)) + delete-blocks (db/delete-blocks repo-url (concat remove-files modify-files)) + delete-pages (if (seq remove-files) + (db/delete-pages-by-files remove-files) + []) + add-or-modify-files (util/remove-nils (concat add-files modify-files))] + (load-contents add-or-modify-files (concat delete-files delete-pages) delete-blocks true)))))) + (defn persist-repo! [repo] (when-let [files-conn (db/get-files-conn repo)] @@ -251,9 +247,6 @@ [repo-url diffs first-clone?] (when (or diffs first-clone?) (p/let [_ (load-repo-to-db! repo-url diffs first-clone?)] - (when first-clone? - (create-default-files! repo-url)) - (when first-clone? (migration-handler/show!))))) diff --git a/src/main/frontend/state.cljs b/src/main/frontend/state.cljs index 28e566b0925..79e3ae534f5 100644 --- a/src/main/frontend/state.cljs +++ b/src/main/frontend/state.cljs @@ -167,13 +167,15 @@ (some? (:page (get-default-home)))) (defn get-preferred-format - [] - (keyword - (or - (when-let [fmt (:preferred-format (get-config))] - (string/lower-case (name fmt))) + ([] + (get-preferred-format (get-current-repo))) + ([repo-url] + (keyword + (or + (when-let [fmt (:preferred-format (get-config repo-url))] + (string/lower-case (name fmt))) - (get-in @state [:me :preferred_format] "markdown")))) + (get-in @state [:me :preferred_format] "markdown"))))) (defn get-preferred-workflow [] @@ -275,7 +277,7 @@ ;; (remove #(= leader-parent %)))] ;; (prn "followers: " (count followers)) ;; )) - )) +)) (defn get-edit-input-id [] From ccc88a37e2c2070a0f748dfd8650a523e9e26f6f Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Sat, 7 Nov 2020 19:25:53 +0800 Subject: [PATCH 27/46] fix: try to fix duplicated journals Relates to https://github.com/logseq/logseq/issues/595 --- src/main/frontend/handler/repo.cljs | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/main/frontend/handler/repo.cljs b/src/main/frontend/handler/repo.cljs index 8dc14eb0125..fa3cb323e49 100644 --- a/src/main/frontend/handler/repo.cljs +++ b/src/main/frontend/handler/repo.cljs @@ -154,6 +154,7 @@ content (cond content content + template (str default-content template) @@ -169,16 +170,10 @@ (p/let [_ (-> (fs/mkdir (str repo-dir "/" config/default-journals-directory)) (p/catch (fn [_e]))) file-exists? (fs/create-if-not-exists repo-dir file-path content)] - ;; TODO: why file exists but page not created - (p/let [resolved-content (if file-exists? - (file-handler/load-file repo-url path) - (p/resolved content))] - (let [content (if (string/blank? (string/trim resolved-content)) - content - resolved-content)] - (db/reset-file! repo-url path content) - (ui-handler/re-render-root!) - (git-handler/git-add repo-url path)))))))) + (when-not file-exists? + (db/reset-file! repo-url path content) + (ui-handler/re-render-root!) + (git-handler/git-add repo-url path))))))) (defn create-default-files! [repo-url] From b82ae3a4b5a5edce9c312de47692f1f37d071ec7 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Sat, 7 Nov 2020 19:36:21 +0800 Subject: [PATCH 28/46] chore: delay watch-for-date! --- src/main/frontend/handler.cljs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/frontend/handler.cljs b/src/main/frontend/handler.cljs index 47c7167b530..e5460b9062c 100644 --- a/src/main/frontend/handler.cljs +++ b/src/main/frontend/handler.cljs @@ -48,7 +48,7 @@ (not (seq (db/get-files config/local-repo)))) (repo-handler/setup-local-repo-if-not-exists!) (state/set-db-restoring! false)) - (watch-for-date!) + (js/setTimeout watch-for-date! 10000) (migration-handler/show!) (when (seq (:repos me)) ;; FIXME: handle error From 6918eb03c1dd1b3857dd1657598be98277d03d90 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Sat, 7 Nov 2020 19:39:52 +0800 Subject: [PATCH 29/46] chore: delay watch-for-date! for 1 minute --- src/main/frontend/handler.cljs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/frontend/handler.cljs b/src/main/frontend/handler.cljs index e5460b9062c..dcb299e42de 100644 --- a/src/main/frontend/handler.cljs +++ b/src/main/frontend/handler.cljs @@ -48,15 +48,16 @@ (not (seq (db/get-files config/local-repo)))) (repo-handler/setup-local-repo-if-not-exists!) (state/set-db-restoring! false)) - (js/setTimeout watch-for-date! 10000) (migration-handler/show!) - (when (seq (:repos me)) + (if (seq (:repos me)) ;; FIXME: handle error (repo-handler/request-app-tokens! (fn [] (repo-handler/clone-and-pull-repos me)) (fn [] - (js/console.error "Failed to request GitHub app tokens.")))))))))] + (js/console.error "Failed to request GitHub app tokens.")))) + + (js/setTimeout watch-for-date! 60000))))))] ;; clear this interval (let [interval-id (js/setInterval inner-fn 50)] (reset! interval interval-id)))) From ff80d85907c52026f35a097f42fe73cfe000d2d7 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Sat, 7 Nov 2020 21:40:36 +0800 Subject: [PATCH 30/46] fix: clear shortcut listeners when unmount Related to https://github.com/logseq/logseq/issues/572. --- src/main/frontend/components/content.cljs | 9 +- src/main/frontend/components/editor.cljs | 14 +-- src/main/frontend/handler/editor.cljs | 125 +++++++++++----------- src/main/frontend/keyboard.cljs | 22 ++-- src/main/frontend/keyboards.cljs | 5 +- src/main/frontend/mixins.cljs | 25 ++--- src/main/frontend/state.cljs | 9 ++ 7 files changed, 111 insertions(+), 98 deletions(-) diff --git a/src/main/frontend/components/content.cljs b/src/main/frontend/components/content.cljs index d4705444c9a..72f24361499 100644 --- a/src/main/frontend/components/content.cljs +++ b/src/main/frontend/components/content.cljs @@ -236,9 +236,12 @@ (fn [_] (editor-handler/copy-selection-blocks) (editor-handler/clear-selection! nil))) - (mixins/keyboard-mixin (util/->system-modifier "ctrl+x") cut-blocks-and-clear-selections!) - (mixins/keyboard-mixin "backspace" cut-blocks-and-clear-selections!) - (mixins/keyboard-mixin "delete" cut-blocks-and-clear-selections!) + (mixins/keyboard-mixin (util/->system-modifier "ctrl+x") + cut-blocks-and-clear-selections!) + (mixins/keyboard-mixin "backspace" + cut-blocks-and-clear-selections!) + (mixins/keyboard-mixin "delete" + cut-blocks-and-clear-selections!) [] [:div#selection.hidden]) diff --git a/src/main/frontend/components/editor.cljs b/src/main/frontend/components/editor.cljs index fab779427b5..587e342009f 100644 --- a/src/main/frontend/components/editor.cljs +++ b/src/main/frontend/components/editor.cljs @@ -229,11 +229,11 @@ svg/outdent-block] [:button.bottom-action {:style {:padding "5px"} - :on-click #(editor-handler/move-up-down parent-state % true)} + :on-click #(editor-handler/move-up-down % true)} svg/move-up-block] [:button.bottom-action {:style {:padding "5px"} - :on-click #(editor-handler/move-up-down parent-state % false)} + :on-click #(editor-handler/move-up-down % false)} svg/move-down-block] [:button.bottom-action {:style {:padding "5px"} @@ -363,12 +363,6 @@ *slash-caret-pos)))]) (rum/defcs box < rum/reactive - (mixins/keyboard-mixin (util/->system-modifier "ctrl+shift+a") editor-handler/select-all-blocks!) - (mixins/keyboard-mixin (if util/mac? "meta+shift+up" "alt+shift+up") - (fn [state e] - (editor-handler/move-up-down state e true))) - (mixins/keyboard-mixin (if util/mac? "meta+shift+down" "alt+shift+down") - (fn [state e] (editor-handler/move-up-down state e false))) (mixins/event-mixin (fn [state] (let [{:keys [id format block]} (get-state state) @@ -618,6 +612,8 @@ {:did-mount (fn [state] (let [[{:keys [dummy? format block-parent-id]} id] (:rum/args state) content (get-in @state/state [:editor/content id])] + (when block-parent-id + (state/set-editing-block-dom-id! block-parent-id)) (editor-handler/restore-cursor-pos! id content dummy?) (when-let [input (gdom/getElement id)] @@ -683,7 +679,7 @@ {:re-render-root? true})))) (editor-handler/save-block! (get-state state) value))) state)} - [state {:keys [on-hide dummy? node format block] + [state {:keys [on-hide dummy? node format block block-parent-id] :or {dummy? false} :as option} id config] (let [content (state/sub [:editor/content id])] diff --git a/src/main/frontend/handler/editor.cljs b/src/main/frontend/handler/editor.cljs index defd6a07ce9..dd3a6336025 100644 --- a/src/main/frontend/handler/editor.cljs +++ b/src/main/frontend/handler/editor.cljs @@ -738,7 +738,7 @@ (defn- with-timetracking-properties [block value] - (let [new-marker (first (re-find format/bare-marker-pattern value)) + (let [new-marker (first (re-find format/bare-marker-pattern (or value ""))) new-marker (if new-marker (string/lower-case (string/trim new-marker))) properties (into {} (:block/properties block))] (if (and @@ -1647,67 +1647,68 @@ string/join)) (defn move-up-down - [state e up?] - (let [{:keys [id block-id block block-parent-id dummy? value pos format] :as block-state} (get-state state) - block (db/entity [:block/uuid block-id]) - meta (:block/meta block) - page (:block/page block) - block-dom-node (gdom/getElement block-parent-id) - prev-block (get-prev-block-non-collapsed block-dom-node) - next-block (get-next-block-non-collapsed block-dom-node) - repo (state/get-current-repo) - move-upwards-to-parent? (and up? prev-block (< (d/attr prev-block "level") (:block/level block))) - move-down-to-higher-level? (and (not up?) next-block (< (d/attr next-block "level") (:block/level block)))] - (when-let [sibling-block (cond - move-upwards-to-parent? - prev-block - move-down-to-higher-level? - next-block - :else - (let [f (if up? util/get-prev-block-with-same-level util/get-next-block-with-same-level)] - (f block-dom-node)))] - (when-let [sibling-block-id (d/attr sibling-block "blockid")] - (when-let [sibling-block (db/pull-block (medley/uuid sibling-block-id))] - (let [sibling-meta (:block/meta sibling-block) - hc1 (db/get-block-and-children-no-cache repo (:block/uuid block)) - hc2 (if (or move-upwards-to-parent? move-down-to-higher-level?) - [sibling-block] - (db/get-block-and-children-no-cache repo (:block/uuid sibling-block)))] - ;; Same page and next to the other - (when (and - (= (:db/id (:block/page block)) - (:db/id (:block/page sibling-block))) - (or - (and up? (= (:end-pos (:block/meta (last hc2))) (:start-pos (:block/meta (first hc1))))) - (and (not up?) (= (:end-pos (:block/meta (last hc1))) (:start-pos (:block/meta (first hc2))))))) - (let [hc1-content (block-and-children-content hc1) - hc2-content (block-and-children-content hc2) - file (db/get-block-file (:block/uuid block)) - file-path (:file/path file) - old-file-content (db/get-file file-path) - [start-pos end-pos new-content blocks] (if up? - [(:start-pos sibling-meta) - (get-in (last hc1) [:block/meta :end-pos]) - (str hc1-content hc2-content) - (concat hc1 hc2)] - [(:start-pos meta) - (get-in (last hc2) [:block/meta :end-pos]) - (str hc2-content hc1-content) - (concat hc2 hc1)])] - (when (and start-pos end-pos) - (let [new-file-content (utf8/insert! old-file-content start-pos end-pos new-content) - modified-time (modified-time-tx page file) - blocks-meta (rebuild-blocks-meta start-pos blocks)] - (profile - (str "Move block " (if up? "up: " "down: ")) - (repo-handler/transact-react-and-alter-file! - repo - (concat - blocks-meta - modified-time) - {:key :block/change - :data (map (fn [block] (assoc block :block/page page)) blocks)} - [[file-path new-file-content]])))))))))))) + [e up?] + (when-let [block-id (:block/uuid (state/get-edit-block))] + (let [block-parent-id (state/get-editing-block-dom-id) + block (db/entity [:block/uuid block-id]) + meta (:block/meta block) + page (:block/page block) + block-dom-node (gdom/getElement block-parent-id) + prev-block (get-prev-block-non-collapsed block-dom-node) + next-block (get-next-block-non-collapsed block-dom-node) + repo (state/get-current-repo) + move-upwards-to-parent? (and up? prev-block (< (d/attr prev-block "level") (:block/level block))) + move-down-to-higher-level? (and (not up?) next-block (< (d/attr next-block "level") (:block/level block)))] + (when-let [sibling-block (cond + move-upwards-to-parent? + prev-block + move-down-to-higher-level? + next-block + :else + (let [f (if up? util/get-prev-block-with-same-level util/get-next-block-with-same-level)] + (f block-dom-node)))] + (when-let [sibling-block-id (d/attr sibling-block "blockid")] + (when-let [sibling-block (db/pull-block (medley/uuid sibling-block-id))] + (let [sibling-meta (:block/meta sibling-block) + hc1 (db/get-block-and-children-no-cache repo (:block/uuid block)) + hc2 (if (or move-upwards-to-parent? move-down-to-higher-level?) + [sibling-block] + (db/get-block-and-children-no-cache repo (:block/uuid sibling-block)))] + ;; Same page and next to the other + (when (and + (= (:db/id (:block/page block)) + (:db/id (:block/page sibling-block))) + (or + (and up? (= (:end-pos (:block/meta (last hc2))) (:start-pos (:block/meta (first hc1))))) + (and (not up?) (= (:end-pos (:block/meta (last hc1))) (:start-pos (:block/meta (first hc2))))))) + (let [hc1-content (block-and-children-content hc1) + hc2-content (block-and-children-content hc2) + file (db/get-block-file (:block/uuid block)) + file-path (:file/path file) + old-file-content (db/get-file file-path) + [start-pos end-pos new-content blocks] (if up? + [(:start-pos sibling-meta) + (get-in (last hc1) [:block/meta :end-pos]) + (str hc1-content hc2-content) + (concat hc1 hc2)] + [(:start-pos meta) + (get-in (last hc2) [:block/meta :end-pos]) + (str hc2-content hc1-content) + (concat hc2 hc1)])] + (when (and start-pos end-pos) + (let [new-file-content (utf8/insert! old-file-content start-pos end-pos new-content) + modified-time (modified-time-tx page file) + blocks-meta (rebuild-blocks-meta start-pos blocks)] + (profile + (str "Move block " (if up? "up: " "down: ")) + (repo-handler/transact-react-and-alter-file! + repo + (concat + blocks-meta + modified-time) + {:key :block/change + :data (map (fn [block] (assoc block :block/page page)) blocks)} + [[file-path new-file-content]]))))))))))))) (defn expand! [] diff --git a/src/main/frontend/keyboard.cljs b/src/main/frontend/keyboard.cljs index b8e7bdf37fd..e2128e11827 100644 --- a/src/main/frontend/keyboard.cljs +++ b/src/main/frontend/keyboard.cljs @@ -16,12 +16,16 @@ ([key trigger once? target] (let [handler (new KeyboardShortcutHandler target)] (.registerShortcut handler (str key once?) key) - (events/listen - handler - EventType/SHORTCUT_TRIGGERED - (fn [e] - (trigger e) - (when once? - (.unregisterShortcut handler keys)))) - (fn [] - (.unregisterShortcut handler key))))) + (let [f (fn [e] + (trigger e) + (when once? + (.unregisterShortcut handler key))) + listener (events/listen + handler + EventType/SHORTCUT_TRIGGERED + f) + unlisten-fn (fn [] + (.dispose handler))] + (fn [] + (.unregisterShortcut handler key) + (unlisten-fn)))))) diff --git a/src/main/frontend/keyboards.cljs b/src/main/frontend/keyboards.cljs index d28f15cae84..1b16fc28029 100644 --- a/src/main/frontend/keyboards.cljs +++ b/src/main/frontend/keyboards.cljs @@ -67,7 +67,10 @@ "ctrl+b" editor-handler/bold-format! "ctrl+i" editor-handler/italics-format! "ctrl+k" editor-handler/html-link-format! - "ctrl+h" editor-handler/highlight-format!} + "ctrl+h" editor-handler/highlight-format! + "ctrl+shift+a" editor-handler/select-all-blocks! + "alt+shift+up" (fn [state e] (editor-handler/move-up-down e true)) + "alt+shift+down" (fn [state e] (editor-handler/move-up-down e false))} (medley/map-keys util/->system-modifier))) (defonce chords diff --git a/src/main/frontend/mixins.cljs b/src/main/frontend/mixins.cljs index c11522e1fbb..9f0c843d3eb 100644 --- a/src/main/frontend/mixins.cljs +++ b/src/main/frontend/mixins.cljs @@ -169,25 +169,22 @@ If no target is given it is defaulted to js/window (global handler) Ex: (keyboard-mixin \"esc\" #(browse-to :home/home))" - ([key f] (keyboard-mixin key f (fn [_] true) js/window)) - ([key f enable-f] (keyboard-mixin key f enable-f js/window)) - ([key f enable-f target] + ([key f] (keyboard-mixin key f js/window)) + ([key f target] (let [target-fn (if (fn? target) target (fn [_] target))] {:did-mount (fn [state] - (if (enable-f state) - (assoc state (str (name ::keyboard-listener) key) - (keyboard/install-shortcut! key - (fn [e] (f state e)) - false - (target-fn state))) - state)) + (assoc state (str (name ::keyboard-listener) key) + (keyboard/install-shortcut! key + (fn [e] (f state e)) + false + (target-fn state)))) :will-unmount (fn [state] - (when (enable-f state) - (when-let [f (get state (str (name ::keyboard-listener) key))] - (f))) - state)}))) + (let [k (str (name ::keyboard-listener) key)] + (when-let [f (get state k)] + (f)) + (dissoc state k)))}))) (defn keyboards-mixin ([m] (keyboards-mixin m (fn [_] true) js/window)) diff --git a/src/main/frontend/state.cljs b/src/main/frontend/state.cljs index 79e3ae534f5..4a706b2287c 100644 --- a/src/main/frontend/state.cljs +++ b/src/main/frontend/state.cljs @@ -72,6 +72,7 @@ :editor/pos 0 :editor/content {} :editor/block nil + :editor/block-dom-id nil :editor/set-timestamp-block nil :cursor-range nil @@ -585,6 +586,14 @@ (set-state! :ui/theme theme) (storage/set :ui/theme theme)) +(defn set-editing-block-dom-id! + [block-dom-id] + (set-state! :editor/block-dom-id block-dom-id)) + +(defn get-editing-block-dom-id + [] + (:editor/block-dom-id @state)) + (defn toggle-theme! [] (let [theme (:ui/theme @state) From b5091b5c29e040556b58070e659796430520e92e Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Sat, 7 Nov 2020 21:42:41 +0800 Subject: [PATCH 31/46] chore: bump version --- src/main/frontend/version.cljs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/frontend/version.cljs b/src/main/frontend/version.cljs index 690eb1e4605..5a626f155f3 100644 --- a/src/main/frontend/version.cljs +++ b/src/main/frontend/version.cljs @@ -1,3 +1,3 @@ (ns frontend.version) -(defonce version "0.0.4.3-7") +(defonce version "0.0.4.4") From 54118e5ef948dde6e92c31782f276b0a4470f7a2 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Sat, 7 Nov 2020 21:48:41 +0800 Subject: [PATCH 32/46] fix: close-fn --- src/main/frontend/ui.cljs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/frontend/ui.cljs b/src/main/frontend/ui.cljs index bc0a0bc2589..5df75a373cf 100644 --- a/src/main/frontend/ui.cljs +++ b/src/main/frontend/ui.cljs @@ -365,8 +365,7 @@ [] (let [modal-panel-content (state/sub :modal/panel-content) show? (boolean modal-panel-content) - close-fn #(fn [] - (state/close-modal!)) + close-fn #(state/close-modal!) modal-panel-content (or modal-panel-content (fn [close] [:div]))] [:div.fixed.bottom-0.inset-x-0.px-4.pb-4.sm:inset-0.sm:flex.sm:items-center.sm:justify-center {:style {:z-index (if show? 10 -1)}} From 46a73c496abd0839403dbe25ac5cf17bb5cd3b50 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Sat, 7 Nov 2020 22:50:23 +0800 Subject: [PATCH 33/46] fix: publishing --- src/main/frontend/publishing/html.cljs | 90 +++++++++++++------------- 1 file changed, 45 insertions(+), 45 deletions(-) diff --git a/src/main/frontend/publishing/html.cljs b/src/main/frontend/publishing/html.cljs index b161bd65cd5..b0f9396f8e8 100644 --- a/src/main/frontend/publishing/html.cljs +++ b/src/main/frontend/publishing/html.cljs @@ -10,51 +10,51 @@ project (or alias name)] (str "\n" (hiccups.core/html - [:head - [:meta {:charset "utf-8"}] - [:meta - {:content - "minimum-scale=1, initial-scale=1, width=device-width, shrink-to-fit=no", - :name "viewport"}] - [:link {:type "text/css", :href "/static/style.css", :rel "stylesheet"}] - [:link - {:href icon - :type "image/png", - :rel "shortcut icon"}] - [:link - {:href icon - :sizes "192x192", - :rel "shortcut icon"}] - [:link - {:href icon - :rel "apple-touch-icon"}] + [:head + [:meta {:charset "utf-8"}] + [:meta + {:content + "minimum-scale=1, initial-scale=1, width=device-width, shrink-to-fit=no", + :name "viewport"}] + [:link {:type "text/css", :href "/static/css/style.css", :rel "stylesheet"}] + [:link + {:href icon + :type "image/png", + :rel "shortcut icon"}] + [:link + {:href icon + :sizes "192x192", + :rel "shortcut icon"}] + [:link + {:href icon + :rel "apple-touch-icon"}] - [:meta {:name "apple-mobile-web-app-title" :content project}] - [:meta {:name "apple-mobile-web-app-capable" :content "yes"}] - [:meta {:name "apple-touch-fullscreen" :content "yes"}] - [:meta {:name "apple-mobile-web-app-status-bar-style" :content "black-translucent"}] - [:meta {:name "mobile-web-app-capable" :content "yes"}] + [:meta {:name "apple-mobile-web-app-title" :content project}] + [:meta {:name "apple-mobile-web-app-capable" :content "yes"}] + [:meta {:name "apple-touch-fullscreen" :content "yes"}] + [:meta {:name "apple-mobile-web-app-status-bar-style" :content "black-translucent"}] + [:meta {:name "mobile-web-app-capable" :content "yes"}] - [:meta {:content title, :property "og:title"}] - [:meta {:content "site", :property "og:type"}] - (when url [:meta {:content url, :property "og:url"}]) - [:meta - {:content icon - :property "og:image"}] - [:meta - {:content description - :property "og:description"}] - [:title title] - [:meta {:content project, :property "og:site_name"}] - [:meta - {:description description}]] - [:body - [:div#root] - [:script (str "window.logseq_db=" transit-db)] - [:script (str "window.logseq_state=" (js/JSON.stringify app-state))] - [:script {:src "/static/js/mldoc.min.js"}] - [:script {:type "text/javascript"} - "// Single Page Apps for GitHub Pages + [:meta {:content title, :property "og:title"}] + [:meta {:content "site", :property "og:type"}] + (when url [:meta {:content url, :property "og:url"}]) + [:meta + {:content icon + :property "og:image"}] + [:meta + {:content description + :property "og:description"}] + [:title title] + [:meta {:content project, :property "og:site_name"}] + [:meta + {:description description}]] + [:body + [:div#root] + [:script (str "window.logseq_db=" transit-db)] + [:script (str "window.logseq_state=" (js/JSON.stringify app-state))] + [:script {:src "/static/js/mldoc.min.js"}] + [:script {:type "text/javascript"} + "// Single Page Apps for GitHub Pages // https://github.com/rafgraph/spa-github-pages // Copyright (c) 2016 Rafael Pedicini, licensed under the MIT License // ---------------------------------------------------------------------- @@ -82,5 +82,5 @@ } }(window.location))"] ;; TODO: should make this configurable - [:script {:src "/static/js/highlight.min.js"}] - [:script {:src "/static/js/publishing.js"}]])))) + [:script {:src "/static/js/highlight.min.js"}] + [:script {:src "/static/js/publishing/main.js"}]])))) From 07ec5b50eaaeb92e954a3254342d9e896885952e Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Sat, 7 Nov 2020 23:02:37 +0800 Subject: [PATCH 34/46] chore: add release-publishing command --- package.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/package.json b/package.json index 54f5f1175a3..49e6ce55bd3 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "release": "run-s cljs:release gulp:build", "watch-app": "run-p cljs:watch-app gulp:watch", "release-app": "run-s cljs:release-app gulp:build", + "release-publishing": "run-s cljs:release-publishing gulp:build", "dev-release-app": "run-s cljs:dev-release-app gulp:build", "clean": "gulp clean", "gulp:watch": "gulp watch", @@ -30,6 +31,7 @@ "cljs:release": "clojure -A:cljs release app publishing", "cljs:watch-app": "clojure -A:cljs watch app", "cljs:release-app": "clojure -A:cljs release app", + "cljs:release-publishing": "clojure -A:cljs release publishing", "cljs:dev-release-app": "clojure -A:cljs release app --config-merge '{:closure-defines {frontend.config/DEV-RELEASE true}}'", "cljs:debug": "clojure -A:cljs release app --debug", "cljs:report": "clojure -A:cljs run shadow.cljs.build-report app report.html" From 5d4168ef6c8fca5fd5f58f5e41860b622cd3d67e Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Sun, 8 Nov 2020 07:27:13 +0800 Subject: [PATCH 35/46] chore: create custom.css automatically Also, make it possible to create a file using the search box. --- deps.edn | 8 +++++--- src/main/frontend/components/search.cljs | 11 ++++++++++- src/main/frontend/dicts.cljs | 2 ++ src/main/frontend/handler/file.cljs | 13 +++++++++++++ src/main/frontend/handler/repo.cljs | 19 +++++++++++++++++-- 5 files changed, 47 insertions(+), 6 deletions(-) diff --git a/deps.edn b/deps.edn index c30de03b1fd..327232efd4c 100755 --- a/deps.edn +++ b/deps.edn @@ -4,11 +4,13 @@ rum {:mvn/version "0.12.3"} ;; rum {:local/root "/home/tienson/codes/source/clj/rum"} ;; persistent-sorted-set {:mvn/version "0.1.2"} - datascript {:git/url "https://github.com/tiensonqin/datascript", - :sha "7c2822565d9a114c7d8604c335af89de4640e2e5"} + ;; FIXME: doesn't work on my archlinux laptop (tienson) + ;; The required namespace "datascript.core" is not available, it was required by "frontend/db.cljs". + ;; datascript {:git/url "https://github.com/tiensonqin/datascript", + ;; :sha "7c2822565d9a114c7d8604c335af89de4640e2e5"} datascript-transit {:mvn/version "0.3.0" :exclusions [datascript]} - ;; datascript {:mvn/version "1.0.1"} + datascript {:mvn/version "1.0.1"} funcool/promesa {:mvn/version "4.0.2"} medley {:mvn/version "1.2.0"} metosin/reitit-frontend {:mvn/version "0.3.10"} diff --git a/src/main/frontend/components/search.cljs b/src/main/frontend/components/search.cljs index 9eafd24a931..f0cbe6e9f35 100644 --- a/src/main/frontend/components/search.cljs +++ b/src/main/frontend/components/search.cljs @@ -3,6 +3,7 @@ [frontend.util :as util] [frontend.handler.route :as route] [frontend.handler.page :as page-handler] + [frontend.handler.file :as file-handler] [frontend.db :as db] [frontend.handler.search :as search-handler] [frontend.ui :as ui] @@ -49,12 +50,13 @@ [{:keys [pages files blocks]} search-q] (rum/with-context [[t] i18n/*tongue-context*] (let [new-page [{:type :new-page}] + new-file [{:type :new-file}] pages (map (fn [page] {:type :page :data page}) pages) files (map (fn [file] {:type :file :data file}) files) blocks (map (fn [block] {:type :block :data block}) blocks) result (if config/publishing? (concat pages files blocks) - (concat new-page pages files blocks))] + (concat new-page pages new-file files blocks))] [:div.absolute.rounded-md.shadow-lg {:style (merge {:top 48 @@ -73,6 +75,9 @@ (route/redirect! {:to :page :path-params {:name data}}) + :new-file + (file-handler/create! search-q) + :file (route/redirect! {:to :file :path-params {:path data}}) @@ -107,6 +112,10 @@ [:div.text.font-bold (str (t :new-page) ": ") [:span.ml-1 (str "\"" search-q "\"")]] + :new-file + [:div.text.font-bold (str (t :new-file) ": ") + [:span.ml-1 (str "\"" search-q "\"")]] + :page [:div.text-sm.font-medium [:span.text-xs.rounded.border.mr-2.px-1 {:title "Page"} diff --git a/src/main/frontend/dicts.cljs b/src/main/frontend/dicts.cljs index 0a22ff15f6d..402655e5e6c 100644 --- a/src/main/frontend/dicts.cljs +++ b/src/main/frontend/dicts.cljs @@ -297,6 +297,7 @@ title: How to take dummy notes? "Search" "Search or Create Page") :new-page "New page" + :new-file "New file" :graph "Graph" :publishing "Publishing" :all-repos "All repos" @@ -543,6 +544,7 @@ title: How to take dummy notes? "搜索" "搜索或者创建新页面") :new-page "新页面" + :new-file "新文件" :graph "图谱" :publishing "发布/下载 HTML 文件" :all-repos "所有库" diff --git a/src/main/frontend/handler/file.cljs b/src/main/frontend/handler/file.cljs index 190e4f78c05..38f3a199636 100644 --- a/src/main/frontend/handler/file.cljs +++ b/src/main/frontend/handler/file.cljs @@ -9,6 +9,7 @@ [frontend.handler.common :as common-handler] [frontend.handler.git :as git-handler] [frontend.handler.ui :as ui-handler] + [frontend.handler.route :as route-handler] [cljs-bean.core :as bean] [frontend.config :as config] [frontend.format :as format] @@ -133,6 +134,18 @@ (println "Write file failed, path: " path ", content: " content) (js/console.error error))))) +(defn create! + ([path] + (create! path "")) + ([path content] + (when-let [repo (state/get-current-repo)] + (when (and path content) + (p/let [_ (alter-file repo path content {:reset? false + :re-render-root? false + :update-status? true})] + (route-handler/redirect! {:to :file + :path-params {:path path}}))))) ) + (defn alter-files ([repo files] (alter-files repo files {})) diff --git a/src/main/frontend/handler/repo.cljs b/src/main/frontend/handler/repo.cljs index fa3cb323e49..87fe26e5bc5 100644 --- a/src/main/frontend/handler/repo.cljs +++ b/src/main/frontend/handler/repo.cljs @@ -128,6 +128,19 @@ (db/reset-file! repo-url path default-content) (git-handler/git-add repo-url path))))) +(defn create-custom-theme + [repo-url] + (let [repo-dir (util/get-repo-dir repo-url) + path (str config/app-name "/" config/custom-css-file) + file-path (str "/" path) + default-content ""] + (p/let [_ (-> (fs/mkdir (str repo-dir "/" config/app-name)) + (p/catch (fn [_e]))) + file-exists? (fs/create-if-not-exists repo-dir file-path default-content)] + (when-not file-exists? + (db/reset-file! repo-url path default-content) + (git-handler/git-add repo-url path))))) + (defn create-dummy-notes-page [repo-url content] (let [repo-dir (util/get-repo-dir repo-url) @@ -180,7 +193,8 @@ (when-let [name (get-in @state/state [:me :name])] (create-config-file-if-not-exists repo-url) (create-today-journal-if-not-exists repo-url) - (create-contents-file repo-url))) + (create-contents-file repo-url) + (create-custom-theme repo-url))) (defn load-repo-to-db! [repo-url diffs first-clone?] @@ -516,7 +530,8 @@ tutorial (string/replace-first tutorial "$today" (date/today))] (create-today-journal-if-not-exists repo tutorial))) _ (create-config-file-if-not-exists repo) - _ (create-contents-file repo)] + _ (create-contents-file repo) + _ (create-custom-theme repo)] (state/set-db-restoring! false))) (js/setTimeout setup-local-repo-if-not-exists! 100))) From 7c3c2836709a40a8dfbf7bba1c41ab2b665c33a1 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Sun, 8 Nov 2020 07:27:56 +0800 Subject: [PATCH 36/46] chore: bump minor version --- src/main/frontend/version.cljs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/frontend/version.cljs b/src/main/frontend/version.cljs index 5a626f155f3..60ac6c6963a 100644 --- a/src/main/frontend/version.cljs +++ b/src/main/frontend/version.cljs @@ -1,3 +1,3 @@ (ns frontend.version) -(defonce version "0.0.4.4") +(defonce version "0.0.4.4-1") From bd08afe7a67d23a2941d3aa67f824e0a9f9d957a Mon Sep 17 00:00:00 2001 From: sly Date: Sat, 7 Nov 2020 19:02:30 -0800 Subject: [PATCH 37/46] Fix: better font display when editing a block. --- resources/css/common.css | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/resources/css/common.css b/resources/css/common.css index 2bdf03f8188..fae7a538f8b 100644 --- a/resources/css/common.css +++ b/resources/css/common.css @@ -10,6 +10,8 @@ --ls-primary-background-color: #002b36; --ls-secondary-background-color: #073642; --ls-tertiary-background-color: #0f4552; + --ls-alternative-background-color: #01313d; + --ls-block-properties-background-color: #02222a; --ls-search-background-color: var(--ls-primary-background-color); --ls-border-color: #0e5263; @@ -51,6 +53,9 @@ --ls-primary-background-color: white; --ls-secondary-background-color: #D8E1E8; --ls-tertiary-background-color: #f0f8ff; + --ls-alternative-background-color: #ced9e0; + + --ls-block-properties-background-color: var(--ls-tertiary-background-color); --ls-search-background-color: var(--ls-primary-background-color); --ls-border-color: #ccc; @@ -134,7 +139,7 @@ textarea { padding: 8px; border: 1px solid rgba(39,41,43,.15); border-radius: 4px; - font-size: 1rem; + font-size: 1em; line-height: 1.5; width: 100%; resize: none; From 91d7a37481754669309ff367dc99e9127ee18a08 Mon Sep 17 00:00:00 2001 From: sly Date: Sat, 7 Nov 2020 19:09:56 -0800 Subject: [PATCH 38/46] Update: remove alternative background variable added for a future feature. --- resources/css/common.css | 2 -- 1 file changed, 2 deletions(-) diff --git a/resources/css/common.css b/resources/css/common.css index fae7a538f8b..55b4b825318 100644 --- a/resources/css/common.css +++ b/resources/css/common.css @@ -10,7 +10,6 @@ --ls-primary-background-color: #002b36; --ls-secondary-background-color: #073642; --ls-tertiary-background-color: #0f4552; - --ls-alternative-background-color: #01313d; --ls-block-properties-background-color: #02222a; --ls-search-background-color: var(--ls-primary-background-color); @@ -53,7 +52,6 @@ --ls-primary-background-color: white; --ls-secondary-background-color: #D8E1E8; --ls-tertiary-background-color: #f0f8ff; - --ls-alternative-background-color: #ced9e0; --ls-block-properties-background-color: var(--ls-tertiary-background-color); From 7b640185f0571c27e37f265b63223a102c4fcd91 Mon Sep 17 00:00:00 2001 From: sly Date: Sat, 7 Nov 2020 19:11:01 -0800 Subject: [PATCH 39/46] Update: remove useless blank line --- resources/css/common.css | 1 - 1 file changed, 1 deletion(-) diff --git a/resources/css/common.css b/resources/css/common.css index 55b4b825318..c45e5b5fc2e 100644 --- a/resources/css/common.css +++ b/resources/css/common.css @@ -53,7 +53,6 @@ --ls-secondary-background-color: #D8E1E8; --ls-tertiary-background-color: #f0f8ff; - --ls-block-properties-background-color: var(--ls-tertiary-background-color); --ls-search-background-color: var(--ls-primary-background-color); --ls-border-color: #ccc; From f01d30967fb8a4c7638c9aa4c93aa1c2d1e76d2c Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Sun, 8 Nov 2020 11:55:05 +0800 Subject: [PATCH 40/46] fix: don't dispose the keyboard handler --- src/main/frontend/keyboard.cljs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/frontend/keyboard.cljs b/src/main/frontend/keyboard.cljs index e2128e11827..be551f7ca3b 100644 --- a/src/main/frontend/keyboard.cljs +++ b/src/main/frontend/keyboard.cljs @@ -24,8 +24,10 @@ handler EventType/SHORTCUT_TRIGGERED f) - unlisten-fn (fn [] - (.dispose handler))] + ;; unlisten-fn (fn [] + ;; (.dispose handler)) +] (fn [] (.unregisterShortcut handler key) - (unlisten-fn)))))) + ;; (unlisten-fn) +))))) From 570cdebd7d24cf252338783c4a324e28f6a1cc9a Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Sun, 8 Nov 2020 12:06:33 +0800 Subject: [PATCH 41/46] fix: shortcuts --- src/main/frontend/keyboard.cljs | 8 +++----- src/main/frontend/mixins.cljs | 28 ++++++++++++++++++++-------- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/main/frontend/keyboard.cljs b/src/main/frontend/keyboard.cljs index be551f7ca3b..e2128e11827 100644 --- a/src/main/frontend/keyboard.cljs +++ b/src/main/frontend/keyboard.cljs @@ -24,10 +24,8 @@ handler EventType/SHORTCUT_TRIGGERED f) - ;; unlisten-fn (fn [] - ;; (.dispose handler)) -] + unlisten-fn (fn [] + (.dispose handler))] (fn [] (.unregisterShortcut handler key) - ;; (unlisten-fn) -))))) + (unlisten-fn)))))) diff --git a/src/main/frontend/mixins.cljs b/src/main/frontend/mixins.cljs index 9f0c843d3eb..3ab9adb860f 100644 --- a/src/main/frontend/mixins.cljs +++ b/src/main/frontend/mixins.cljs @@ -192,18 +192,30 @@ ([m enable-f target] (when (seq m) (let [target-fn (if (fn? target) target (fn [_] target))] - {:init + {:did-mount + (fn [state] + (if (enable-f state) + (let [keyboards (doall + (map + (fn [[key f]] + [key + (keyboard/install-shortcut! key + (fn [e] (f state e)) + false + (target-fn state))]) + m))] + (assoc state ::keyboards-listener keyboards)) + state)) + :will-unmount (fn [state] (when (enable-f state) - (doseq [[key f] m] - (keyboard/install-shortcut! key - (fn [e] (f state e)) - true - (target-fn state)) - m) - state))})))) + (doseq [[_k f] (get state ::keyboards-listener)] + (f))) + state)})))) ;; also, from https://github.com/tonsky/rum/blob/75174b9ea0cf4b7a761d9293929bd40c95d35f74/doc/useful-mixins.md + + (defn perf-measure-mixin [desc] "Does performance measurements in development." From 8b3bde40a191d547b2f498bca8b66e43d09994ed Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Sun, 8 Nov 2020 12:29:37 +0800 Subject: [PATCH 42/46] feat: add `embed youtube video` command --- src/main/frontend/commands.cljs | 4 +++- src/main/frontend/components/block.cljs | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/main/frontend/commands.cljs b/src/main/frontend/commands.cljs index b73582cda5d..f9c16dc7566 100644 --- a/src/main/frontend/commands.cljs +++ b/src/main/frontend/commands.cljs @@ -100,7 +100,7 @@ ["Deadline" [[:editor/clear-current-slash] [:editor/show-date-picker]]] ["Scheduled" [[:editor/clear-current-slash] - [:editor/show-date-picker]]] + [:editor/show-date-picker]]] ["Draw" [[:editor/input "/draw "] [:editor/show-input [{:command :draw :id :title @@ -125,6 +125,8 @@ ["Image Link" link-steps] (when (state/logged?) ["Upload an image" [[:editor/click-hidden-file-input :id]]]) + ["Embed Youtube Video" [[:editor/input "{{{youtube }}}" {:last-pattern slash + :backward-pos 3}]]] ["Html Inline " (->inline "html")] ;; TODO: diff --git a/src/main/frontend/components/block.cljs b/src/main/frontend/components/block.cljs index 0f47872428d..c7b85a9ae0b 100644 --- a/src/main/frontend/components/block.cljs +++ b/src/main/frontend/components/block.cljs @@ -578,6 +578,27 @@ [title]) arguments)] (cond + (= name "youtube") + (let [url (first arguments)] + (when-let [youtube-id (cond + (string/starts-with? url "https://youtu.be/") + (string/replace url "https://youtu.be/" "") + + (string? url) + url + + :else + nil)] + (when-not (string/blank? youtube-id) + [:iframe + {:allowfullscreen "allowfullscreen" + :allow + "accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" + :frameborder "0" + :src (str "https://www.youtube.com/embed/" youtube-id) + :height "315" + :width "560"}]))) + (= name "embed") (let [a (first arguments)] (cond From 87fa2ff9dc1856c723b20313bbb64458551a92a8 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Sun, 8 Nov 2020 12:33:02 +0800 Subject: [PATCH 43/46] chore: bump minor version --- src/main/frontend/version.cljs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/frontend/version.cljs b/src/main/frontend/version.cljs index 60ac6c6963a..45471330b44 100644 --- a/src/main/frontend/version.cljs +++ b/src/main/frontend/version.cljs @@ -1,3 +1,3 @@ (ns frontend.version) -(defonce version "0.0.4.4-1") +(defonce version "0.0.4.4-2") From 9f9bd8a1b14f6552c7a281c2fa3976d7f9f20d38 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Sun, 8 Nov 2020 13:09:50 +0800 Subject: [PATCH 44/46] fix: doesn't create default files when first cloning --- src/main/frontend/handler/repo.cljs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/frontend/handler/repo.cljs b/src/main/frontend/handler/repo.cljs index 87fe26e5bc5..86993a9708a 100644 --- a/src/main/frontend/handler/repo.cljs +++ b/src/main/frontend/handler/repo.cljs @@ -229,6 +229,8 @@ (p/catch (fn [error] (println "loading files failed: ") (js/console.dir error) + ;; Empty repo + (create-default-files! repo-url) (state/set-state! :repo/loading-files? false)))) (when (seq diffs) (let [filter-diffs (fn [type] (->> (filter (fn [f] (= type (:type f))) diffs) From d17b12fddf6dc4c8c237357cb4b84fef91b853f3 Mon Sep 17 00:00:00 2001 From: samfundev Date: Sun, 8 Nov 2020 13:52:32 -0500 Subject: [PATCH 45/46] Update windows setup There have been some changes to how Logseq is setup so I've updated the documentation on how to setup Logseq on windows. I've also added some scripts to the repo instead of having them in a separate gist. --- clojure.bat | 2 ++ readme.org | 18 +++++++++++++----- start-windows.bat | 14 ++++++++++++++ 3 files changed, 29 insertions(+), 5 deletions(-) create mode 100644 clojure.bat create mode 100644 start-windows.bat diff --git a/clojure.bat b/clojure.bat new file mode 100644 index 00000000000..d470aaff070 --- /dev/null +++ b/clojure.bat @@ -0,0 +1,2 @@ +@echo off +cmd-clojure %* \ No newline at end of file diff --git a/readme.org b/readme.org index 7c530df1726..325f076bec0 100644 --- a/readme.org +++ b/readme.org @@ -63,11 +63,19 @@ If you're on Windows, use the [[#windows-setup][Windows setup]]. *** 1. Required software Install clojure through scoop-clojure: https://github.com/littleli/scoop-clojure. You can also install [[https://nodejs.org/en/][Node.js]], [[https://yarnpkg.com/][Yarn]] and [[https://www.postgresql.org/download/][PostgreSQL]] through scoop if you want to. -*** 2. Setup PostgreSQL +*** 2. Creating a GitHub app + Follow [[step #2][#2-creating-a-github-app]] above if you want Logseq to connect to GitHub. If not, skip this section. + The ~GITHUB_APP_PEM~ variable in the ~run-windows.bat~ needs to be set with the correct directory for your system. + +*** 3. Setup PostgreSQL Make sure you have PostgreSQL running. You can check if it's running with ~pg_ctl status~ and use ~pg_ctl start~ to start it up. You'll also need to make a logseq DB in PostgreSQL. Do that with ~createdb logseq~. -*** 3. Setup the server - Download [[https://gist.github.com/samfundev/98088dd76f67085f114c75493261aa3d][this little script]] that sets up the environment variables and runs ~cmd-clj -A:dev~. - The ~GITHUB_APP_PEM~ variable in the script needs to be set with the correct directory for your system. - Run that script in the repo and enter ~(go)~ into the interpreter. +*** 4. Download the clojure server + Go to https://github.com/logseq/logseq-internal/releases, download the logseq.jar and move into the root directory of repo. + +*** 5. Start Logseq + Run ~start-windows.bat~ which is located in the repo. This will open a second terminal that runs Logseq's backend server. + To completely stop Logseq, you'll need to also close that second terminal that was opened. + + ~start-windows.bat~ will try to start PostgreSQL for you if it's not already started. \ No newline at end of file diff --git a/start-windows.bat b/start-windows.bat new file mode 100644 index 00000000000..9f30ff31250 --- /dev/null +++ b/start-windows.bat @@ -0,0 +1,14 @@ +@echo off +SET ENVIRONMENT=dev +SET JWT_SECRET=4fa183cf1d28460498b13330835e80ad +SET COOKIE_SECRET=10a42ca724e34f4db6086a772d787034 +SET DATABASE_URL=postgres://localhost:5432/logseq +SET GITHUB_APP2_ID=78728 +SET GITHUB_APP2_KEY=xxxxxxxxxxxxxxxxxxxx +SET GITHUB_APP2_SECRET=xxxxxxxxxxxxxxxxxxxx +SET GITHUB_APP_PEM= +SET LOG_PATH=%AppData%\..\Local\Temp\logseq + +pg_ctl start +start cmd.exe /k "java -Duser.timezone=UTC -jar logseq.jar" +yarn && yarn watch \ No newline at end of file From 3ea34ded54d0c2b9ff307abfdf0a7faddd35122e Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Mon, 9 Nov 2020 09:21:45 +0800 Subject: [PATCH 46/46] chore: updated datascript version --- deps.edn | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/deps.edn b/deps.edn index 327232efd4c..315a6e17d1e 100755 --- a/deps.edn +++ b/deps.edn @@ -6,11 +6,11 @@ ;; persistent-sorted-set {:mvn/version "0.1.2"} ;; FIXME: doesn't work on my archlinux laptop (tienson) ;; The required namespace "datascript.core" is not available, it was required by "frontend/db.cljs". - ;; datascript {:git/url "https://github.com/tiensonqin/datascript", - ;; :sha "7c2822565d9a114c7d8604c335af89de4640e2e5"} + datascript {:git/url "https://github.com/tiensonqin/datascript", + :sha "7c2822565d9a114c7d8604c335af89de4640e2e5"} + ;; datascript {:mvn/version "1.0.1"} datascript-transit {:mvn/version "0.3.0" :exclusions [datascript]} - datascript {:mvn/version "1.0.1"} funcool/promesa {:mvn/version "4.0.2"} medley {:mvn/version "1.2.0"} metosin/reitit-frontend {:mvn/version "0.3.10"}