Skip to content

Commit

Permalink
# Conflicts:
Browse files Browse the repository at this point in the history
#	package.json
#	src/main/api.ts
#	src/renderer/src/components/Nav.tsx
  • Loading branch information
1943time committed Sep 11, 2023
1 parent fd4a384 commit c71fe87
Show file tree
Hide file tree
Showing 12 changed files with 88 additions and 27 deletions.
2 changes: 1 addition & 1 deletion electron-builder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ mac:
target:
- target: dmg
arch:
- x64
# - x64
- arm64
linux:
target:
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@
"electron-log": "^4.4.8",
"electron-store": "^8.1.0",
"electron-updater": "^5.3.0",
"form-data": "^4.0.0",
"got": "^11.8.6",
"mime-types": "^2.1.35",
"mkdirp": "^3.0.0",
"node-fetch": "^2.6.13",
"node-watch": "^0.7.4",
"shiki": "^0.14.1",
"upath": "^2.0.1"
Expand Down
6 changes: 6 additions & 0 deletions src/main/appMenus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,12 @@ export const createAppMenus = () => {
shell.openExternal(`https://pb.bluemd.me/official/book/docs`)
}
},
{
label: 'Bluestone Website',
click: () => {
shell.openExternal('https://www.bluemd.me')
}
},
{
label: 'Github',
click: () => {
Expand Down
4 changes: 3 additions & 1 deletion src/renderer/src/components/Nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const Nav = observer(() => {
const paths = useMemo(() => {
if (!treeStore.openNote) return ['']
return treeStore.getAbsolutePath(treeStore.openNote)
}, [treeStore.openNote])
}, [treeStore.openNote?.filename])
return (
<div
className={'fixed left-0 top-0 h-[40px] w-full b1 border-b nav z-50 duration-200 drag-nav select-none width-duration'}
Expand Down Expand Up @@ -66,6 +66,7 @@ export const Nav = observer(() => {
</div>
</div>
<div className={'flex items-center pr-3 dark:text-gray-400/70 space-x-1 text-gray-500'}>
{/*<Share/>*/}
<Update/>
<div
className={'flex items-center justify-center p-1 group'}
Expand All @@ -75,6 +76,7 @@ export const Nav = observer(() => {
className={'text-lg duration-200 dark:group-hover:text-gray-300 group-hover:text-gray-700'}
/>
</div>
{/*<User/>*/}
</div>
</div>
</div>
Expand Down
11 changes: 9 additions & 2 deletions src/renderer/src/editor/elements/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@ import {CodeCtx, CodeElement, CodeLine} from './code'
import {Blockquote} from './blockquote'
import {List, ListItem} from './list'
import {Head} from './head'
import {CSSProperties, useContext, useMemo} from 'react'
import React, {CSSProperties, useContext, useMemo} from 'react'
import {Paragraph} from './paragraph'
import {InlineChromiumBugfix} from '../utils/InlineChromiumBugfix'
import {Media} from './media'
import {useEditorStore} from '../store'
import {Point} from 'slate'
import {isAbsolute, join} from 'path'
import {treeStore} from '../../store/tree'

const dragStart = (e: React.DragEvent) => {
e.preventDefault()
e.stopPropagation()
}
export const MElement = (props: RenderElementProps) => {
switch (props.element.type) {
case 'blockquote':
Expand Down Expand Up @@ -77,6 +80,8 @@ export const MLeaf = (props: RenderLeafProps) => {
<span
style={style}
data-be={'link'}
draggable={false}
onDragStart={dragStart}
onClick={(e) => {
e.stopPropagation()
e.preventDefault()
Expand Down Expand Up @@ -106,6 +111,8 @@ export const MLeaf = (props: RenderLeafProps) => {
<span
{...props.attributes}
data-be={'text'}
draggable={false}
onDragStart={dragStart}
data-fnc={leaf.fnc ? 'fnc' : undefined}
data-fnd={leaf.fnd ? 'fnd' : undefined}
data-fnc-name={leaf.fnc ? leaf.text?.replace(/\[\^(.+)]:?/g, '$1') : undefined}
Expand Down
18 changes: 15 additions & 3 deletions src/renderer/src/editor/output/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,19 @@ export const outputCache = new WeakMap<object, string>()
export const isMix = (t: Text) => {
return Object.keys(t).filter(key => ['bold', 'code', 'italic', 'strikethrough'].includes(key)).length > 1
}

const textHtml = (t: Text) => {
let str = t.text || ''
if (t.highColor) str = `<span style="color:${t.highColor}">${str}</span>`
if (t.code) str = `<code>${str}</code>`
if (t.italic) str = `<i>${str}</i>`
if (t.bold) str = `<b>${str}</b>`
if (t.strikethrough) str = `<del>${str}</del>`
if (t.url) str = `<a href="${t.url}">${str}</a>`
return str
}
const textStyle = (t: Text) => {
if (!t.text) return ''
if (t.highColor) return `<span style="color:${t.highColor}" data-be>${t.text}</span>`
let str = t.text.replace(/(?<!\\)\\/g, '\\')
let preStr = '', afterStr = ''
if (t.code || t.bold || t.strikethrough || t.italic) {
Expand All @@ -25,10 +35,12 @@ const textStyle = (t: Text) => {
return `${preStr}${str}${afterStr}`
}
const composeText = (t: Text, parent: any[]) => {
if (!t.text) return ''
if (t.highColor) return textHtml(t)

const siblings = parent[parent.length -1]?.children
const index = siblings?.findIndex(n => n === t)
if (!t.text) return ''
let str = textStyle(t)
let str = textStyle(t)!
if (t.url) {
str = `[${str}](${encodeURI(t.url)})`
} else if (isMix(t) && index !== -1) {
Expand Down
54 changes: 41 additions & 13 deletions src/renderer/src/editor/parser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const parseTable = (table: Table) => {
type: 'table-cell',
align: aligns?.[i] || undefined,
title: l === 0,
children: c.children?.length ? parserBlock(c.children) : [{text: ''}]
children: c.children?.length ? parserBlock(c.children, false, c) : [{text: ''}]
}
})
}
Expand All @@ -51,8 +51,7 @@ const parserBlock = (nodes: Content[], top = false, parent?: Content) => {
let els:(Elements | Text) [] = []
let el:Element | null | Element[] = null
let preNode:null | Content = null
let colorTag = ''
let colorText = ''
let htmlTag:{tag: string, color?: string, url?: string}[] = []
for (let n of nodes) {
switch (n.type) {
case 'heading':
Expand All @@ -70,12 +69,34 @@ const parserBlock = (nodes: Content[], top = false, parent?: Content) => {
})
}
} else {
const colorMatch = n.value.match(/<span\s+style="color:\s*(#\w+)"\s+data-be>/)
if (colorMatch) {
colorTag = colorMatch[1]
} else if (/^\s*<\/span>\s*$/.test(n.value)) {
el = {text: colorText, highColor: colorTag}
colorTag = ''
// date-be will be removed in a few versions
const htmlMatch = n.value.match(/<\/?(b|i|del|code|span|a).*?>/)
if (htmlMatch) {
const [str, tag] = htmlMatch
if (str.startsWith('</') && htmlTag.length && htmlTag[htmlTag.length - 1].tag === tag) {
htmlTag.pop()
}
if (!str.startsWith('</')) {
if (tag === 'span') {
const color = str.match(/style="color:\s*(#\w+)"/)
if (color) {
htmlTag.push({
tag: tag,
color: color[1]
})
}
} else if (tag === 'a') {
const url = str.match(/href="([\w:.\/_\-#\\]+)"/)
if (url) {
htmlTag.push({
tag: tag,
url: url[1]
})
}
} else {
htmlTag.push({tag: tag})
}
}
} else {
el = {text: n.value}
}
Expand Down Expand Up @@ -147,11 +168,18 @@ const parserBlock = (nodes: Content[], top = false, parent?: Content) => {
el = parseTable(n)
break
default:
if (n.type === 'text' && colorTag) {
colorText = n.value
if (n.type === 'text' && htmlTag.length) {
el = {text: n.value}
for (let t of htmlTag) {
if (t.tag === 'code') el.code = true
if (t.tag === 'i') el.italic = true
if (t.tag === 'b' || t.tag === 'strong') el.bold = true
if (t.tag === 'del') el.strikethrough = true
if (t.tag === 'span' && t.color) el.highColor = t.color
if (t.tag === 'a' && t.url) el.url = t.url
}
break
}
if (['strong', 'link', 'text', 'emphasis', 'delete', 'inlineCode'].includes(n.type)) {
} else if (['strong', 'link', 'text', 'emphasis', 'delete', 'inlineCode'].includes(n.type)) {
if (n.type === 'text') {
el = {text: n.value}
} else {
Expand Down
2 changes: 0 additions & 2 deletions src/renderer/src/editor/tools/FloatBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ export const FloatBar = observer(() => {
EditorUtils.highColor(store.editor)
} else {
EditorUtils.highColor(store.editor, localStorage.getItem('high-color') || '#10b981')
EditorUtils.clearMarks(store.editor)
}
}}
>
Expand Down Expand Up @@ -255,7 +254,6 @@ export const FloatBar = observer(() => {
onClick={() => {
localStorage.setItem('high-color', c.color)
EditorUtils.highColor(store.editor, c.color)
EditorUtils.clearMarks(store.editor, true)
setState({openSelectColor: false})
resize()
}}
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/src/editor/utils/editorUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export class EditorUtils {
static toggleFormat(editor: Editor, format: any) {
const str = editor.selection ? Editor.string(editor, editor.selection) : ''
if (str) {
EditorUtils.highColor(editor)
// EditorUtils.highColor(editor)
const isActive = EditorUtils.isFormatActive(editor, format)
Transforms.setNodes(
editor,
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/src/share
Submodule share updated from 167df6 to 916d0b
9 changes: 8 additions & 1 deletion src/renderer/src/store/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,20 @@ class ConfigStore {
})
})
window.electron.ipcRenderer.on('changeConfig', action((e, key: any, value: any) => {
if (key === 'theme') {
this.setTheme(value, false)
}
this.config[key] = value
}))
}
async setTheme(theme: typeof this.config.theme) {
async setTheme(theme: typeof this.config.theme, broadcast = true) {
if (theme === this.config.theme) return
const dark = await MainApi.getSystemDark()
runInAction(() => {
this.config.theme = theme
if (broadcast) {
MainApi.sendToAll('changeConfig', 'theme', theme)
}
if (theme === 'dark') {
document.documentElement.classList.add('dark')
this.config.dark = true
Expand Down
3 changes: 1 addition & 2 deletions src/renderer/src/store/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ export class Watcher {
}

public onChange(e: 'remove' | 'update', path: string, node?: IFileItem) {
const base = basename(path)
if (path.split(sep).some(p => p.startsWith('.')) && base !== '.images') return
if (path.split(sep).some(p => p.startsWith('.') && p !== '.images')) return
const nodesMap = new Map(this.store.nodes.map(n => [n.filePath, n]))
const target = nodesMap.get(path)
const parent = nodesMap.get(join(path, '..'))!
Expand Down

0 comments on commit c71fe87

Please sign in to comment.