Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into zotero/poc
Browse files Browse the repository at this point in the history
  • Loading branch information
Weihua Lu committed Jul 26, 2021
2 parents 6d1c092 + 105503f commit 2f7e3f5
Show file tree
Hide file tree
Showing 54 changed files with 1,480 additions and 444 deletions.
1 change: 1 addition & 0 deletions .projectile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
-/resources/static/js/sentry.min.js
-/resources/static/js/highlight.min.js
-/resources/static/js/katex.min.js
-/resources/static/js/mhchem.min.js
-/resources/static/js/mldoc.min.js
-/resources/static/js/reveal.min.js
-/resources/static/js/sci.min.js
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
"ignore": "^5.1.8",
"is-svg": "4.2.2",
"jszip": "^3.5.0",
"mldoc": "0.8.9",
"mldoc": "0.9.0",
"path": "^0.12.7",
"pixi-graph-fork": "^0.1.3",
"posthog-js": "^1.10.2",
Expand Down
10 changes: 2 additions & 8 deletions resources/css/common.css
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ html[data-theme='dark'] {
--ls-scrollbar-background-color: rgba(30, 60, 67, 0.1);
--ls-scrollbar-thumb-hover-color: rgba(255, 255, 255, 0.2);
--ls-head-text-color: var(--ls-link-text-color);
--ls-cloze-text-color: #8fbc8f;
--ls-icon-color: var(--ls-link-text-color);
--ls-search-icon-color: var(--ls-link-text-color);
--ls-a-chosen-bg: var(--ls-secondary-background-color);
Expand Down Expand Up @@ -126,6 +127,7 @@ html[data-theme='light'] {
--ls-scrollbar-background-color: rgba(0, 0, 0, 0.05);
--ls-scrollbar-thumb-hover-color: rgba(0, 0, 0, 0.2);
--ls-head-text-color: var(--ls-link-text-color);
--ls-cloze-text-color: #0000cd;
--ls-icon-color: #908e8b;
--ls-search-icon-color: var(--ls-icon-color);
--ls-a-chosen-bg: #f7f7f7;
Expand Down Expand Up @@ -724,14 +726,6 @@ li p:last-child,
overflow-y: scroll;
}

.loader-reverse {
-webkit-animation: spin 2s infinite linear reverse;
}

.loader {
-webkit-animation: spin 2s infinite linear;
}

.canceled,
.done {
text-decoration: line-through;
Expand Down
1 change: 1 addition & 0 deletions resources/js/mhchem.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion resources/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Logseq",
"version": "0.2.6",
"version": "0.2.8",
"main": "electron.js",
"author": "Logseq",
"description": "A privacy-first, open-source platform for knowledge management and collaboration.",
Expand Down
3 changes: 2 additions & 1 deletion src/electron/electron/fs_watcher.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
(when (fs/existsSync dir)
(let [watcher (.watch watcher dir
(clj->js
{:ignored (partial utils/ignored-path? dir)
{:ignored (fn [path]
(utils/ignored-path? dir path))
:ignoreInitial true
:ignorePermissionErrors true
:interval polling-interval
Expand Down
33 changes: 21 additions & 12 deletions src/electron/electron/utils.cljs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
(ns electron.utils
(:require [clojure.string :as string]
["fs" :as fs]))
["fs" :as fs]
["path" :as path]
[clojure.string :as string]))

(defonce mac? (= (.-platform js/process) "darwin"))
(defonce win32? (= (.-platform js/process) "win32"))
Expand All @@ -13,18 +15,24 @@
(defonce open (js/require "open"))
(defonce fetch (js/require "node-fetch"))

(defn get-file-ext
[file]
(last (string/split file #"\.")))

;; TODO: ignore according to mime types
(defn ignored-path?
[dir path]
(or
(some #(string/starts-with? path (str dir "/" %))
["." "assets" "node_modules"])
(some #(string/ends-with? path %)
[".swap" ".crswap" ".tmp" ".DS_Store"])))
(when (string? path)
(or
(some #(string/starts-with? path (str dir "/" %))
["." ".recycle" "assets" "node_modules"])
(some #(string/includes? path (str "/" % "/"))
["." ".recycle" "assets" "node_modules"])
(string/ends-with? path ".DS_Store")
;; hidden directory or file
(re-find #"/\.[^.]+" path)
(re-find #"^\.[^.]+" path)
(let [path (string/lower-case path)]
(and
(not (string/blank? (path/extname path)))
(not
(some #(string/ends-with? path %)
[".md" ".markdown" ".org" ".edn" ".css"])))))))

(defn fix-win-path!
[path]
Expand All @@ -35,4 +43,5 @@

(defn read-file
[path]
(.toString (fs/readFileSync path)))
(when (fs/existsSync path)
(.toString (fs/readFileSync path))))
11 changes: 9 additions & 2 deletions src/main/frontend/commands.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@
(def zotero-steps [[:editor/input (str slash "zotero")]
[:editor/show-zotero]])

(def *extend-slash-commands (atom []))

(defn register-slash-command [cmd]
(swap! *extend-slash-commands conj cmd))

(defn ->marker
[marker]
[[:editor/clear-current-slash]
Expand Down Expand Up @@ -270,7 +275,9 @@
["Embed Vimeo Video" [[:editor/input "{{vimeo }}" {:last-pattern slash
:backward-pos 2}]]]]

@*extend-slash-commands
;; Allow user to modify or extend, should specify how to extend.

(state/get-commands)
(state/get-plugins-commands))
(remove nil?)
Expand Down Expand Up @@ -428,8 +435,8 @@

(defmulti handle-step first)

(defmethod handle-step :editor/hook [[_ event {:keys [pid] :as payload}] format]
(plugin-handler/hook-plugin-editor event (merge payload {:format format :uuid (:block/uuid (state/get-edit-block))}) pid))
(defmethod handle-step :editor/hook [[_ event {:keys [pid uuid] :as payload}] format]
(plugin-handler/hook-plugin-editor event (merge payload {:format format :uuid (or uuid (:block/uuid (state/get-edit-block)))}) pid))

(defmethod handle-step :editor/input [[_ value option]]
(when-let [input-id (state/get-edit-input-id)]
Expand Down
127 changes: 72 additions & 55 deletions src/main/frontend/components/block.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
[frontend.components.datetime :as datetime-comp]
[frontend.components.lazy-editor :as lazy-editor]
[frontend.components.svg :as svg]
[frontend.components.macro :as macro]
[frontend.config :as config]
[frontend.context.i18n :as i18n]
[frontend.date :as date]
Expand Down Expand Up @@ -397,32 +398,34 @@

(rum/defc page-preview-trigger
[{:keys [children sidebar? tippy-position tippy-distance fixed-position? open? manual?] :as config} page-name]
(let [redirect-page-name (model/get-redirect-page-name page-name (:block/alias? config))
(let [redirect-page-name (or (model/get-redirect-page-name page-name (:block/alias? config))
page-name)
page-original-name (model/get-page-original-name redirect-page-name)
debounced-open? (use-delayed-open open? page-name)
html-template (fn []
[:div.tippy-wrapper.overflow-y-auto.p-4
{:style {:width 600
:text-align "left"
:font-weight 500
:max-height 600
:padding-bottom 64}}
(if (and (string? page-original-name) (string/includes? page-original-name "/"))
[:div.my-2
(->>
(for [page (string/split page-original-name #"/")]
(when (and (string? page) page)
(page-reference false page {} nil)))
(interpose [:span.mx-2.opacity-30 "/"]))]
[:h2.font-bold.text-lg (if (= page-name redirect-page-name)
page-original-name
[:span
[:span.text-sm.mr-2 "Alias:"]
page-original-name])])
(let [page (db/entity [:block/name (string/lower-case redirect-page-name)])]
(editor-handler/insert-first-page-block-if-not-exists! redirect-page-name)
(when-let [f (state/get-page-blocks-cp)]
(f (state/get-current-repo) page {:sidebar? sidebar? :preview? true})))])]
(when redirect-page-name
[:div.tippy-wrapper.overflow-y-auto.p-4
{:style {:width 600
:text-align "left"
:font-weight 500
:max-height 600
:padding-bottom 64}}
(if (and (string? page-original-name) (string/includes? page-original-name "/"))
[:div.my-2
(->>
(for [page (string/split page-original-name #"/")]
(when (and (string? page) page)
(page-reference false page {} nil)))
(interpose [:span.mx-2.opacity-30 "/"]))]
[:h2.font-bold.text-lg (if (= page-name redirect-page-name)
page-original-name
[:span
[:span.text-sm.mr-2 "Alias:"]
page-original-name])])
(let [page (db/entity [:block/name (string/lower-case redirect-page-name)])]
(editor-handler/insert-first-page-block-if-not-exists! redirect-page-name)
(when-let [f (state/get-page-blocks-cp)]
(f (state/get-current-repo) page {:sidebar? sidebar? :preview? true})))]))]
(if (or (not manual?) open?)
(ui/tippy {:html html-template
:interactive true
Expand Down Expand Up @@ -494,6 +497,7 @@
(.stopPropagation e))}
(excalidraw s)]
[:span.page-reference
{:data-ref s}
(when (and (or show-brackets? nested-link?)
(not html-export?)
(not contents-page?))
Expand Down Expand Up @@ -1102,6 +1106,9 @@
:else ;TODO: maybe collections?
nil))

(get @macro/macros name)
((get @macro/macros name) config options)

:else
(if-let [block-uuid (:block/uuid config)]
(let [format (get-in config [:block :block/format] :markdown)
Expand Down Expand Up @@ -1232,7 +1239,7 @@
(:block/uuid child)))))]))))

(rum/defcs block-control < rum/reactive
[state config block uuid block-id body children collapsed? *ref-collapsed? *control-show?]
[state config block uuid block-id body children collapsed? *ref-collapsed? *control-show? edit-input-id]
(let [has-children-blocks? (and (coll? children) (seq children))
has-child? (and
(not (:pre-block? block))
Expand All @@ -1245,7 +1252,9 @@
ref-collapsed? (util/react *ref-collapsed?)
dark? (= "dark" (state/sub :ui/theme))
ref? (:ref? config)
collapsed? (if ref? ref-collapsed? collapsed?)]
collapsed? (if ref? ref-collapsed? collapsed?)
empty-content? (string/blank? (:block/content block))
edit? (state/sub [:editor/editing? edit-input-id])]
[:div.mr-2.flex.flex-row.items-center
{:style {:height 24
:margin-top 0
Expand All @@ -1266,20 +1275,25 @@
(editor-handler/collapse-block! uuid)))))}
[:span {:class (if control-show? "control-show" "control-hide")}
(ui/rotating-arrow collapsed?)]]
[:a {:on-click (fn [e]
(bullet-on-click e block config uuid))}
[:span.bullet-container.cursor
{:id (str "dot-" uuid)
:draggable true
:on-drag-start (fn [event]
(bullet-drag-start event block uuid block-id))
:blockid (str uuid)
:class (str (when collapsed? "bullet-closed")
" "
(when (and (:document/mode? config)
(not collapsed?))
"hide-inner-bullet"))}
[:span.bullet {:blockid (str uuid)}]]]]))
(if (and empty-content? (not edit?)
(not (:block/top? block))
(not (:block/bottom? block)))
[:span.bullet-container]

[:a {:on-click (fn [e]
(bullet-on-click e block config uuid))}
[:span.bullet-container.cursor
{:id (str "dot-" uuid)
:draggable true
:on-drag-start (fn [event]
(bullet-drag-start event block uuid block-id))
:blockid (str uuid)
:class (str (when collapsed? "bullet-closed")
" "
(when (and (:document/mode? config)
(not collapsed?))
"hide-inner-bullet"))}
[:span.bullet {:blockid (str uuid)}]]])]))

(rum/defc dnd-separator
[block move-to block-content?]
Expand Down Expand Up @@ -1486,8 +1500,8 @@
[config block]
(let [properties (walk/keywordize-keys (:block/properties block))
properties-order (:block/properties-order block)
properties (apply dissoc properties property/built-in-properties)
properties-order (remove property/built-in-properties properties-order)
properties (apply dissoc properties (property/built-in-properties))
properties-order (remove (property/built-in-properties) properties-order)
pre-block? (:block/pre-block? block)
properties (if pre-block?
(let [repo (state/get-current-repo)
Expand Down Expand Up @@ -1569,7 +1583,7 @@
(and (util/sup? target)
(d/has-class? target "fn"))
(d/has-class? target "image-resize"))
(editor-handler/clear-selection! nil)
(editor-handler/clear-selection!)
(editor-handler/unhighlight-blocks!)
(let [block (or (db/pull [:block/uuid (:block/uuid block)]) block)
f #(let [cursor-range (util/caret-range (gdom/getElement block-id))
Expand Down Expand Up @@ -1843,11 +1857,7 @@
:on-drag-leave (fn [event]
(block-drag-leave *move-to))
:on-drop (fn [event]
(block-drop event uuid block *move-to))
:on-mouse-over (fn [e]
(block-mouse-over e has-child? *control-show? block-id doc-mode?))
:on-mouse-leave (fn [e]
(block-mouse-leave e has-child? *control-show? block-id doc-mode?))})
(block-drop event uuid block *move-to))})

(defn- build-refs-data-value
[block refs]
Expand Down Expand Up @@ -1882,7 +1892,7 @@
:should-update (fn [old-state new-state]
(not= (:block/content (second (:rum/args old-state)))
(:block/content (second (:rum/args new-state)))))}
[state config {:block/keys [uuid title body meta content page format repo children pre-block? top? properties refs path-refs heading-level level type] :as block}]
[state config {:block/keys [uuid title body meta content page format repo children pre-block? top? properties refs path-refs heading-level level type idx] :as block}]
(let [blocks-container-id (:blocks-container-id config)
config (update config :block merge block)

Expand All @@ -1893,7 +1903,8 @@
heading? (and (= type :heading) heading-level (<= heading-level 6))
*control-show? (get state ::control-show?)
*ref-collapsed? (get state ::ref-collapsed?)
collapsed? (or @*ref-collapsed? (get properties :collapsed))
collapsed? (or @*ref-collapsed?
(get properties :collapsed))
ref? (boolean (:ref? config))
breadcrumb-show? (:breadcrumb-show? config)
sidebar? (boolean (:sidebar? config))
Expand All @@ -1909,7 +1920,8 @@
(seq body))))
attrs (on-drag-and-mouse-attrs block uuid top? block-id *move-to has-child? *control-show? doc-mode?)
data-refs (build-refs-data-value block (remove (set refs) path-refs))
data-refs-self (build-refs-data-value block refs)]
data-refs-self (build-refs-data-value block refs)
edit-input-id (str "edit-block-" blocks-container-id "-" uuid)]
[:div.ls-block.flex.flex-col.rounded-sm
(cond->
{:id block-id
Expand Down Expand Up @@ -1940,12 +1952,16 @@
(when top?
(dnd-separator-wrapper block block-id slide? true false))

[:div.flex.flex-row.pr-2 {:class (if heading? "items-baseline" "")}
[:div.flex.flex-row.pr-2
{:class (if heading? "items-baseline" "")
:on-mouse-over (fn [e]
(block-mouse-over e has-child? *control-show? block-id doc-mode?))
:on-mouse-leave (fn [e]
(block-mouse-leave e has-child? *control-show? block-id doc-mode?))}
(when (not slide?)
(block-control config block uuid block-id body children collapsed? *ref-collapsed? *control-show?))
(block-control config block uuid block-id body children collapsed? *ref-collapsed? *control-show? edit-input-id))

(let [edit-input-id (str "edit-block-" blocks-container-id "-" uuid)]
(block-content-or-editor config block edit-input-id block-id slide? heading-level))]
(block-content-or-editor config block edit-input-id block-id slide? heading-level)]

(block-children config children collapsed? *ref-collapsed?)

Expand Down Expand Up @@ -2493,7 +2509,8 @@
(for [[idx item] (medley/indexed blocks)]
(let [item (->
(dissoc item :block/meta)
(assoc :block/top? (zero? idx)))
(assoc :block/top? (zero? idx)
:block/bottom? (= (count blocks) (inc idx))))
config (assoc config :block/uuid (:block/uuid item))]
(rum/with-key
(block-container config item)
Expand Down
Loading

0 comments on commit 2f7e3f5

Please sign in to comment.