Skip to content

Commit

Permalink
Merge branch 'master' into enhance/marketplace-x
Browse files Browse the repository at this point in the history
  • Loading branch information
xyhp915 committed Jun 16, 2023
2 parents d2ace01 + 327d0ab commit 5e2fae5
Show file tree
Hide file tree
Showing 21 changed files with 680 additions and 154 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-desktop-release.yml
Expand Up @@ -122,7 +122,7 @@ jobs:
run: |
sed -i 's/defonce version ".*"/defonce version "${{ steps.ref.outputs.version }}"/g' src/main/frontend/version.cljs
- name: Set Build Environment Variables (only when workflow_dispath)
- name: Set Build Environment Variables (only when workflow_dispatch)
if: ${{ github.event_name == 'workflow_dispatch' }}
# if scheduled, use default settings
run: |
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Expand Up @@ -133,6 +133,7 @@ When submitting a Pull Request (PR) or expecting a subsequent review, please fol
* Unrelated refactoring or heavy refactoring
* Code or doc formatting changes including whitespace changes
* Dependency updates e.g. in package.json
* Changes that contain multiple unverified resources. This is risky for our users and is a lot of work to verify. A change with one resource that can be verified is acceptable.

### PR Additional Links

Expand Down
15 changes: 14 additions & 1 deletion deps/graph-parser/src/logseq/graph_parser/mldoc.cljc
Expand Up @@ -75,13 +75,26 @@
js/JSON.stringify))))

(defn remove-indentation-spaces
"Remove the indentation spaces from the content. Only for markdown.
level - ast level + 1 (2 for the first level, 3 for the second level, etc., as the non-first line of multi-line block has 2 more space
Ex.
- level 1 multiline block first line
level 1 multiline block second line
\t- level 2 multiline block first line
\t level 2 multiline block second line
remove-first-line? - apply the indentation removal to the first line or not"
[s level remove-first-line?]
(let [lines (string/split-lines s)
[f & r] lines
body (map (fn [line]
;; Check if the indentation area only contains white spaces
;; Level = ast level + 1, 1-based indentation level
;; For markdown in Logseq, the indentation area for the non-first line of multi-line block is (ast level - 1) * "\t" + 2 * "(space)"
(if (string/blank? (gp-util/safe-subs line 0 level))
;; If valid, then remove the indentation area spaces. Keep the rest of the line (might contain leading spaces)
(gp-util/safe-subs line level)
line))
;; Otherwise, trim these invalid spaces
(string/triml line)))
(if remove-first-line? lines r))
content (if remove-first-line? body (cons f body))]
(string/join "\n" content)))
Expand Down
18 changes: 18 additions & 0 deletions deps/graph-parser/test/logseq/graph_parser/mldoc_test.cljs
Expand Up @@ -119,6 +119,24 @@ body"
(is ["@tag" "tag1" "tag2"] (sort (:filetags props)))
(is ["@tag" "tag1" "tag2" "tag3"] (sort (:tags props))))))

(deftest remove-indentation-spaces
(testing "Remove indentations for every line"
(is (= "block 1.1\n line 1\n line 2\nline 3\nline 4"
(let [s "block 1.1
line 1
line 2
line 3
line 4"]
(gp-mldoc/remove-indentation-spaces s 2 false))))
(is (= "\t- block 1.1\n line 1\n line 2\nline 3\nline 4"
(let [s "\t- block 1.1
\t line 1
\t line 2
\t line 3
\tline 4"]
(gp-mldoc/remove-indentation-spaces s 3 false))))))


(deftest ^:integration test->edn
(let [graph-dir "test/docs-0.9.2"
_ (docs-graph-helper/clone-docs-repo-if-not-exists graph-dir "v0.9.2")
Expand Down
5 changes: 3 additions & 2 deletions scripts/src/logseq/tasks/lang.clj
Expand Up @@ -162,11 +162,12 @@
:de #{:graph :host :plugins :port :right-side-bar/whiteboards :search-item/block
:settings-of-plugins :search-item/whiteboard :shortcut.category/navigating
:settings-page/enable-tooltip :settings-page/enable-whiteboards :settings-page/plugin-system}
:es #{:settings-page/tab-general :settings-page/tab-editor}
:es #{:settings-page/tab-general :settings-page/tab-editor :whiteboard/color}
:it #{:plugins}
:nl #{:plugins :type :left-side-bar/nav-recent-pages :plugin/update}
:pl #{:port}
:pt-BR #{:plugins :right-side-bar/flashcards :settings-page/enable-flashcards}
:pt-BR #{:plugins :right-side-bar/flashcards :settings-page/enable-flashcards :page/backlinks
:host :settings-page/tab-editor :shortcut.category/plugins :whiteboard/link}
:pt-PT #{:plugins :settings-of-plugins :plugin/downloads :right-side-bar/flashcards
:settings-page/enable-flashcards :settings-page/plugin-system}
:nb-NO #{:port :type :whiteboard :right-side-bar/flashcards :right-side-bar/whiteboards
Expand Down
94 changes: 28 additions & 66 deletions src/main/frontend/components/block.cljs
Expand Up @@ -6,7 +6,6 @@
[cljs-bean.core :as bean]
[cljs.core.match :refer [match]]
[cljs.reader :as reader]
[clojure.set :as set]
[clojure.string :as string]
[clojure.walk :as walk]
[datascript.core :as d]
Expand Down Expand Up @@ -67,7 +66,6 @@
[logseq.graph-parser.block :as gp-block]
[logseq.graph-parser.config :as gp-config]
[logseq.graph-parser.mldoc :as gp-mldoc]
[logseq.graph-parser.property :as gp-property]
[logseq.graph-parser.text :as text]
[logseq.graph-parser.util :as gp-util]
[logseq.graph-parser.util.block-ref :as block-ref]
Expand Down Expand Up @@ -2047,66 +2045,25 @@
:else
(inline-text config (:block/format block) (str v)))]]))

(def hidden-editable-page-properties
"Properties that are hidden in the pre-block (page property)"
#{:title :filters :icon})

(assert (set/subset? hidden-editable-page-properties (gp-property/editable-built-in-properties))
"Hidden editable page properties must be valid editable properties")

(def hidden-editable-block-properties
"Properties that are hidden in a block (block property)"
(into #{:logseq.query/nlp-date}
gp-property/editable-view-and-table-properties))

(assert (set/subset? hidden-editable-block-properties (gp-property/editable-built-in-properties))
"Hidden editable page properties must be valid editable properties")

(defn- add-aliases-to-properties
[properties block]
(let [repo (state/get-current-repo)
aliases (db/get-page-alias-names repo
(:block/name (db/pull (:db/id (:block/page block)))))]
(if (seq aliases)
(if (:alias properties)
(update properties :alias (fn [c]
(util/distinct-by string/lower-case (concat c aliases))))
(assoc properties :alias aliases))
properties)))

(rum/defc properties-cp
[config {:block/keys [pre-block?] :as block}]
(let [dissoc-keys (fn [m keys] (apply dissoc m keys))
properties (cond-> (update-keys (:block/properties block) keyword)
true
(dissoc-keys (property/hidden-properties))
pre-block?
(dissoc-keys hidden-editable-page-properties)
(not pre-block?)
(dissoc-keys hidden-editable-block-properties)
pre-block?
(add-aliases-to-properties block))]
(let [ordered-properties
(property/get-visible-ordered-properties (:block/properties block)
(:block/properties-order block)
{:pre-block? pre-block?
:page-id (:db/id (:block/page block))})]
(cond
(seq properties)
(let [properties-order (cond->> (:block/properties-order block)
true
(remove (property/hidden-properties))
pre-block?
(remove hidden-editable-page-properties))
properties-order (distinct properties-order)
ordered-properties (if (seq properties-order)
(map (fn [k] [k (get properties k)]) properties-order)
properties)]
[:div.block-properties
{:class (when pre-block? "page-properties")
:title (if pre-block?
"Click to edit this page's properties"
"Click to edit this block's properties")}
(for [[k v] ordered-properties]
(rum/with-key (property-cp config block k v)
(str (:block/uuid block) "-" k)))])

(and pre-block? properties)
(seq ordered-properties)
[:div.block-properties
{:class (when pre-block? "page-properties")
:title (if pre-block?
"Click to edit this page's properties"
"Click to edit this block's properties")}
(for [[k v] ordered-properties]
(rum/with-key (property-cp config block k v)
(str (:block/uuid block) "-" k)))]

(and pre-block? ordered-properties)
[:span.opacity-50 "Properties"]

:else
Expand Down Expand Up @@ -3116,14 +3073,15 @@

:else
(let [language (if (contains? #{"edn" "clj" "cljc" "cljs"} language) "clojure" language)]
[:div {:ref (fn [el]
(set-inside-portal? (and el (whiteboard-handler/inside-portal? el))))}
[:div.ui-fenced-code-editor
{:ref (fn [el]
(set-inside-portal? (and el (whiteboard-handler/inside-portal? el))))}
(cond
(nil? inside-portal?) nil

(or (:slide? config) inside-portal?)
(highlight/highlight (str (random-uuid))
{:class (str "language-" language)
{:class (str "language-" language)
:data-lang language}
code)

Expand Down Expand Up @@ -3292,10 +3250,14 @@
[:sup.fn (str name "↩︎")]])]])

["Src" options]
[:div.cp__fenced-code-block
(if-let [opts (plugin-handler/hook-fenced-code-by-type (util/safe-lower-case (:language options)))]
(plugins/hook-ui-fenced-code (string/join "" (:lines options)) opts)
(src-cp config options html-export?))]
(let [lang (util/safe-lower-case (:language options))]
[:div.cp__fenced-code-block
{:data-lang lang}
(if-let [opts (plugin-handler/hook-fenced-code-by-type lang)]
[:div.ui-fenced-code-wrap
(src-cp config options html-export?)
(plugins/hook-ui-fenced-code (:block config) (string/join "" (:lines options)) opts)]
(src-cp config options html-export?))])

:else
"")
Expand Down
2 changes: 1 addition & 1 deletion src/main/frontend/components/block.css
@@ -1,7 +1,7 @@
.block-content-wrapper {
/* 38px is the width of block-control */
width: calc(100% - 22px);

user-select: text;
@screen sm {
width: calc(100% - 33px);
overflow-x: visible;
Expand Down
66 changes: 58 additions & 8 deletions src/main/frontend/components/plugins.cljs
Expand Up @@ -5,6 +5,7 @@
[frontend.context.i18n :refer [t]]
[frontend.ui :as ui]
[frontend.handler.ui :as ui-handler]
[frontend.handler.editor :as editor-handler]
[frontend.handler.plugin-config :as plugin-config-handler]
[frontend.handler.common.plugin :as plugin-common-handler]
[frontend.search :as search]
Expand Down Expand Up @@ -1137,14 +1138,61 @@
(let [updates-coming (state/sub :plugin/updates-coming)]
(toolbar-plugins-manager-list updates-coming items)))]]))))

(rum/defcs hook-ui-fenced-code < rum/reactive
[_state content {:keys [render edit] :as _opts}]
(rum/defc hook-ui-fenced-code
[block content {:keys [render edit] :as _opts}]

[:div
{:on-mouse-down (fn [e] (when (false? edit) (util/stop e)))
:class (util/classnames [{:not-edit (false? edit)}])}
(when (fn? render)
(js/React.createElement render #js {:content content}))])
(let [[content1 set-content1!] (rum/use-state content)
[editor-active? set-editor-active!] (rum/use-state (string/blank? content))
*cm (rum/use-ref nil)
*el (rum/use-ref nil)]

(rum/use-effect!
#(set-content1! content)
[content])

(rum/use-effect!
(fn []
(some-> (rum/deref *el)
(.closest ".ui-fenced-code-wrap")
(.-classList)
(#(if editor-active?
(.add % "is-active")
(.remove % "is-active"))))
(when-let [cm (rum/deref *cm)]
(.refresh cm)
(.focus cm)
(.setCursor cm (.lineCount cm) (count (.getLine cm (.lastLine cm))))))
[editor-active?])

(rum/use-effect!
(fn []
(let [t (js/setTimeout
#(when-let [^js cm (some-> (rum/deref *el)
(.closest ".ui-fenced-code-wrap")
(.querySelector ".CodeMirror")
(.-CodeMirror))]
(rum/set-ref! *cm cm)
(doto cm
(.on "change" (fn []
(some-> cm (.getDoc) (.getValue) (set-content1!))))))
;; wait for the cm loaded
1000)]
#(js/clearTimeout t)))
[])

[:div.ui-fenced-code-result
{:on-mouse-down (fn [e] (when (false? edit) (util/stop e)))
:class (util/classnames [{:not-edit (false? edit)}])
:ref *el}
[:<>
[:span.actions
{:on-mouse-down #(util/stop %)}
(ui/button (ui/icon "square-toggle-horizontal" {:size 14})
:on-click #(set-editor-active! (not editor-active?)))
(ui/button (ui/icon "source-code" {:size 14})
:on-click #(editor-handler/edit-block! block (count content1) (:block/uuid block)))]
(when (fn? render)
(js/React.createElement render #js {:content content1}))]]))

(rum/defc plugins-page
[]
Expand Down Expand Up @@ -1260,7 +1308,8 @@

[:div.cp__plugins-settings.cp__settings-main
[:header
[:h1.title (ui/icon "puzzle") (str " " (or title (t :settings-of-plugins)))]]
[:h1.title (ui/icon "puzzle" {:size 22})
[:strong (or title (t :settings-of-plugins))]]]

[:div.cp__settings-inner.md:flex
{:class (util/classnames [{:no-aside (not nav?)}])}
Expand Down Expand Up @@ -1355,4 +1404,5 @@
[:div.settings-modal.of-plugins
(focused-settings-content title)])
{:center? false
:label "plugin-settings-modal"
:id "ls-focused-settings-modal"}))

0 comments on commit 5e2fae5

Please sign in to comment.