Merge branch 'master' into feat/integration-plugins-core

pull/2085/head
charlie 2021-05-28 18:40:08 +08:00
commit 213630f277
5 changed files with 1023 additions and 64 deletions

File diff suppressed because one or more lines are too long

View File

@ -5,19 +5,312 @@
&-lang {
@apply absolute top-0 right-0 p-1 text-sm;
z-index: 1;
background: white;
background: rgba(255, 255, 255, .6);
}
> .CodeMirror {
z-index: 0;
height: auto;
padding: 6px 0 0 0;
padding: 4px 0;
margin-top: 4px;
margin-bottom: 6px;
font-family: Fira Code, Monaco, Menlo, Consolas, 'COURIER NEW', monospace;
max-width: 86vw;
border-radius: 2px;
line-height: 1.45em;
&:not(.CodeMirror-focused) {
.CodeMirror-activeline-background {
background: unset;
background: unset !important;
}
}
pre.CodeMirror-line {
box-shadow: none !important;
}
}
}
html[data-theme='dark'] {
.CodeMirror {
color: #839496;
background-color: var(--ls-secondary-background-color);
.CodeMirror-widget {
text-shadow: none;
}
.cm-keyword {
color: #cb4b16
}
.cm-atom {
color: #d33682;
}
.cm-number {
color: #d33682;
}
.cm-def {
color: #2aa198;
}
.cm-variable {
color: #268bd2;
}
.cm-variable-2 {
color: #b58900;
}
.cm-variable-3 {
color: #6c71c4;
}
.cm-property {
color: #2aa198;
}
.cm-operator {
color: #6c71c4;
}
.cm-comment {
color: #586e75;
font-style: italic;
}
.cm-string {
color: #859900;
}
.cm-string-2 {
color: #b58900;
}
.cm-meta {
color: #859900;
}
.cm-qualifier {
color: #b58900;
}
.cm-builtin {
color: #d33682;
}
.cm-bracket {
color: #cb4b16;
}
.CodeMirror-matchingbracket {
color: #859900;
}
.CodeMirror-nonmatchingbracket {
color: #dc322f;
}
.cm-tag {
color: #93a1a1
}
.cm-attribute {
color: #2aa198;
}
.cm-header {
color: #586e75;
}
.cm-quote {
color: #93a1a1;
}
.cm-hr {
color: transparent;
border-top: 1px solid #586e75;
display: block;
}
.cm-link {
color: #93a1a1;
cursor: pointer;
}
.cm-special {
color: #6c71c4;
}
.cm-em {
color: #999;
text-decoration: underline;
text-decoration-style: dotted;
}
.cm-strong {
color: #eee;
}
.cm-tab:before {
content: "➤"; /*visualize tab character*/
color: #586e75;
position: absolute;
}
.cm-error,
.cm-invalidchar {
color: #586e75;
border-bottom: 1px dotted #dc322f;
}
.CodeMirror-selected {
background: var(--ls-primary-background-color);
}
.CodeMirror-gutters {
border-right: 1px solid;
}
.CodeMirror-gutters {
background-color: var(--ls-secondary-background-color);
border-color: transparent;
}
pre.CodeMirror-line {
background-color: transparent !important;
}
.CodeMirror-linenumber {
text-shadow: #021014 0 -1px;
}
/* Common */
.CodeMirror-linenumber {
color: #586e75;
padding: 0 5px;
}
.CodeMirror-gutter .CodeMirror-gutter-text {
color: #586e75;
}
.CodeMirror-lines .CodeMirror-cursor {
border-left: 1px solid #819090;
}
/*
Active line. Negative margin compensates left padding of the text in the
view-port
*/
.CodeMirror-activeline-background {
background: rgba(255, 255, 255, 0.10);
}
}
.cp__right-sidebar .CodeMirror {
background-color: var(--ls-primary-background-color);
}
.cp__right-sidebar .CodeMirror .CodeMirror-gutters {
background-color: var(--ls-primary-background-color);
}
.cp__right-sidebar .CodeMirror .CodeMirror-selected {
background: var(--ls-secondary-background-color);
}
.extensions__code-lang {
background-color: rgba(0, 0, 0, .25);
}
}
html[data-theme='light'] {
.CodeMirror {
background: var(--ls-secondary-background-color);
color: #202020;
.CodeMirror-selected {
background: var(--ls-tertiary-background-color);
}
.CodeMirror-gutters {
background: #f5f5f5;
border-right: 0;
}
.CodeMirror-linenumber {
color: #b0b0b0;
}
.CodeMirror-cursor {
border-left: 1px solid #505050 !important;
}
span.cm-comment {
color: #8f5536;
}
span.cm-atom {
color: #aa759f;
}
span.cm-number {
color: #aa759f;
}
span.cm-property, span.cm-attribute {
color: #90a959;
}
span.cm-keyword {
color: #ac4142;
}
span.cm-string {
color: #eaaf5a;
}
span.cm-variable {
color: #8ca553;
}
span.cm-variable-2 {
color: #6a9fb5;
}
span.cm-def {
color: #d28445;
}
span.cm-bracket {
color: #202020;
}
span.cm-tag {
color: #ac4142;
}
span.cm-link {
color: #aa759f;
}
span.cm-error {
background: #ac4142;
color: #505050;
}
.CodeMirror-activeline-background {
background: var(--ls-tertiary-background-color) !important;
}
.CodeMirror-matchingbracket {
color: #1bff01 !important;
}
}
}

View File

@ -1903,7 +1903,7 @@
(util/cursor-move-forward input 2)))
(defn- get-block-tree-insert-pos-at-point
"return [target-block sibling?]"
"return [target-block sibling? delete-editing-block? editing-block]"
[]
(when-let [editing-block (or (db/pull (:db/id (state/get-edit-block)))
(when (:block/dummy? (state/get-edit-block)) (state/get-edit-block)))]
@ -1925,34 +1925,85 @@
(conj (match (mapv boolean [dummy? (seq fst-block-text) (seq snd-block-text)
block-self? has-children? (= parent left) collapsed?])
;; if editing-block is dummy, insert after page-block
[true false false _ _ _ _]
[parent-block false true]
[true _ _ _ _ _ _]
[parent-block false]
[parent-block false false]
;; when zoom at editing-block
[false _ _ true _ _ _]
[editing-block false]
[editing-block false false]
;; insert after editing-block
[false true _ false true _ false]
[editing-block false]
[editing-block false false]
[false true _ false true _ true]
[editing-block true]
[editing-block true false]
[false true _ false false _ _]
[editing-block true]
[editing-block true false]
[false false false false true _ false]
[editing-block false]
[editing-block false false]
[false false false false true _ true]
[editing-block true]
[editing-block true false]
[false false false false false _ _]
[editing-block true]
[editing-block true true]
;; insert before editing-block
[false false true false _ true _]
[parent-block false]
[parent-block false false]
[false false true false _ false _]
[left-block true])
[left-block true false])
editing-block))))
(defn- paste-block-tree-at-point-edit-aux
[uuid file page exclude-properties format content-update-fn]
(fn [block]
(outliner-core/block
(let [[new-content new-title]
(if content-update-fn
(let [new-content (content-update-fn (:block/content block))
new-title (or (->> (mldoc/->edn
(str (case format
:markdown "- "
:org "* ")
(if (seq (:block/title block)) "" "\n")
new-content)
(mldoc/default-config format))
(ffirst)
(second)
(:title))
(:block/title block))]
[new-content new-title])
[(:block/content block) (:block/title block)])
new-content
(->> new-content
(property/remove-property format "id")
(property/remove-property format "custom_id"))]
(conj {:block/uuid uuid
:block/page (select-keys page [:db/id])
:block/file (select-keys file [:db/id])
:block/format format
:block/properties (apply dissoc (:block/properties block)
(concat [:id :custom_id :custom-id]
exclude-properties))
:block/meta (dissoc (:block/meta block) :start-pos :end-pos)
:block/content new-content
:block/title new-title}
(dissoc block
:block/pre-block?
:block/uuid
:block/page
:block/file
:db/id
:block/left
:block/parent
:block/format
:block/properties
:block/meta
:block/content
:block/title))))))
(defn- paste-block-tree-at-point
([tree exclude-properties] (paste-block-tree-at-point tree exclude-properties nil))
([tree exclude-properties content-update-fn]
@ -1961,7 +2012,8 @@
(db/entity [:block/original-name (state/get-current-page)])
(:block/page (db/entity (:db/id (state/get-edit-block)))))
file (:block/file page)]
(when-let [[target-block sibling? editing-block] (get-block-tree-insert-pos-at-point)]
(when-let [[target-block sibling? delete-editing-block? editing-block]
(get-block-tree-insert-pos-at-point)]
(let [target-block (outliner-core/block target-block)
editing-block (outliner-core/block editing-block)
format (or (:block/format target-block) (state/get-preferred-format))
@ -1975,52 +2027,15 @@
(recur (zip/next loc))
(let [uuid (random-uuid)]
(swap! new-block-uuids (fn [acc uuid] (conj acc uuid)) uuid)
(recur (zip/next (zip/edit
loc
#(outliner-core/block
(let [[new-content new-title]
(if content-update-fn
(let [new-content (content-update-fn (:block/content %))
new-title (or (:title (second (ffirst
(mldoc/->edn (str (case format
:markdown "- "
:org "* ")
(if (seq (:block/title %)) "" "\n")
new-content)
(mldoc/default-config format)))))
(:block/title %))]
[new-content new-title])
[(:block/content %) (:block/title %)])
new-content
(->> new-content
(property/remove-property format "id")
(property/remove-property format "custom_id"))]
(conj {:block/uuid uuid
:block/page (select-keys page [:db/id])
:block/file (select-keys file [:db/id])
:block/format format
:block/properties (apply dissoc (:block/properties %)
(concat [:id :custom_id :custom-id]
exclude-properties))
:block/meta (dissoc (:block/meta %) :start-pos :end-pos)
:block/content new-content
:block/title new-title}
(dissoc %
:block/pre-block?
:block/uuid
:block/page
:block/file
:db/id
:block/left
:block/parent
:block/format
:block/properties
:block/meta
:block/content
:block/title))))))))))))
(paste-block-tree-at-point-edit-aux
uuid file page exclude-properties format content-update-fn)))))))))
_ (outliner-core/save-node editing-block)
_ (outliner-core/insert-nodes metadata-replaced-blocks target-block sibling?)
_ (when delete-editing-block?
(when-let [id (:db/id (outliner-core/get-data editing-block))]
(outliner-core/delete-node (outliner-core/block (db/pull id)) true)))
new-blocks (db/pull-many repo '[*] (map (fn [id] [:block/uuid id]) @new-block-uuids))]
(db/refresh! repo {:key :block/insert :data new-blocks}))))))
@ -2039,6 +2054,7 @@
sorted-blocks (tree/sort-blocks blocks-exclude-root root-block)
result-blocks (if including-parent? sorted-blocks (drop 1 sorted-blocks))
tree (blocks-vec->tree result-blocks)]
(insert-command! id "" format {})
(paste-block-tree-at-point tree [:template :including-parent]
(fn [content]
(->> content
@ -2046,7 +2062,6 @@
(property/remove-property format "including-parent")
template/resolve-dynamic-template!)))
(clear-when-saved!)
(insert-command! id "" format {})
(db/refresh! repo {:key :block/insert :data [(db/pull db-id)]}))
(when-let [input (gdom/getElement id)]
(.focus input))))

View File

@ -785,7 +785,7 @@
[theme-mode]
(if-not (= theme-mode "system")
(do
(set-theme! (if (= theme-mode "light") "white" "dark"))
(set-theme! (if (= theme-mode "light") "white" theme-mode))
(set-state! :ui/system-theme? false)
(storage/set :ui/system-theme? false))
(sync-system-theme!)))
@ -806,7 +806,7 @@
[]
(let [theme (:ui/theme @state)
theme' (if (= theme "dark") "white" "dark")]
(set-theme! theme')))
(use-theme-mode! theme')))
(defn- file-content-key
[repo path]

View File

@ -288,7 +288,7 @@
[]
(let [^js schemaMedia (js/window.matchMedia "(prefers-color-scheme: dark)")]
(.addEventListener schemaMedia "change" state/sync-system-theme!)
;; (state/sync-system-theme!)
(state/sync-system-theme!)
#(.removeEventListener schemaMedia "change" state/sync-system-theme!)))
(defn on-scroll