Skip to content

Commit

Permalink
Merge branch 'release/3.57.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
purocean committed Jul 31, 2023
2 parents cd5b36d + 2a9ce02 commit 701b8d7
Show file tree
Hide file tree
Showing 18 changed files with 305 additions and 204 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,16 @@ For more information on how to use the following functions, please see [characte

## Changelogs

### [v3.56.4](https://github.com/purocean/yn/releases/tag/v3.56.4) 2023-07-23
### [v3.57.0](https://github.com/purocean/yn/releases/tag/v3.57.0) 2023-07-31

[Windows](https://github.com/purocean/yn/releases/download/v3.56.4/Yank-Note-win-x64-3.56.4.exe) | [macOS arm64](https://github.com/purocean/yn/releases/download/v3.56.4/Yank-Note-mac-arm64-3.56.4.dmg) | [macOS x64](https://github.com/purocean/yn/releases/download/v3.56.4/Yank-Note-mac-x64-3.56.4.dmg) | [Linux AppImage](https://github.com/purocean/yn/releases/download/v3.56.4/Yank-Note-linux-x86_64-3.56.4.AppImage) | [Linux deb](https://github.com/purocean/yn/releases/download/v3.56.4/Yank-Note-linux-amd64-3.56.4.deb)
[Windows](https://github.com/purocean/yn/releases/download/v3.57.0/Yank-Note-win-x64-3.57.0.exe) | [macOS arm64](https://github.com/purocean/yn/releases/download/v3.57.0/Yank-Note-mac-arm64-3.57.0.dmg) | [macOS x64](https://github.com/purocean/yn/releases/download/v3.57.0/Yank-Note-mac-x64-3.57.0.dmg) | [Linux AppImage](https://github.com/purocean/yn/releases/download/v3.57.0/Yank-Note-linux-x86_64-3.57.0.AppImage) | [Linux deb](https://github.com/purocean/yn/releases/download/v3.57.0/Yank-Note-linux-amd64-3.57.0.deb)

1. feat: upgrade Electron to 22.3.17
2. feat: optimize the popup position of context menu when space is limited
3. feat: add file-related operations to the context menu of file tabs
4. feat: Prompt whether to create a new file when switching to a non-existent file
5. feat(plugin): add `file-tabs.close-tabs` Action
6. feat(plugin): add extension methods to the context menu of file tabs
1. feat: introducing the $seq method in the macro to generate sequential numbers like Figure-1, Figure-2.
2. feat: added configuration to hide the main window upon startup.
3. feat: implemented a configuration option to automatically add to-dos to the completion time.
4. feat: implemented size restriction for generated historical version files.
5. feat: enhanced scrolling behavior for the details tag when clicked.
6. fix: resolved the issue of extra blank lines at the end of copied code blocks.

[More release notes](https://github.com/purocean/yn/releases)

Expand Down
16 changes: 8 additions & 8 deletions README_ZH-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,16 @@

## 更新日志

### [v3.56.4](https://github.com/purocean/yn/releases/tag/v3.56.4) 2023-07-23
### [v3.57.0](https://github.com/purocean/yn/releases/tag/v3.57.0) 2023-07-31

[Windows](https://github.com/purocean/yn/releases/download/v3.56.4/Yank-Note-win-x64-3.56.4.exe) | [macOS arm64](https://github.com/purocean/yn/releases/download/v3.56.4/Yank-Note-mac-arm64-3.56.4.dmg) | [macOS x64](https://github.com/purocean/yn/releases/download/v3.56.4/Yank-Note-mac-x64-3.56.4.dmg) | [Linux AppImage](https://github.com/purocean/yn/releases/download/v3.56.4/Yank-Note-linux-x86_64-3.56.4.AppImage) | [Linux deb](https://github.com/purocean/yn/releases/download/v3.56.4/Yank-Note-linux-amd64-3.56.4.deb)
[Windows](https://github.com/purocean/yn/releases/download/v3.57.0/Yank-Note-win-x64-3.57.0.exe) | [macOS arm64](https://github.com/purocean/yn/releases/download/v3.57.0/Yank-Note-mac-arm64-3.57.0.dmg) | [macOS x64](https://github.com/purocean/yn/releases/download/v3.57.0/Yank-Note-mac-x64-3.57.0.dmg) | [Linux AppImage](https://github.com/purocean/yn/releases/download/v3.57.0/Yank-Note-linux-x86_64-3.57.0.AppImage) | [Linux deb](https://github.com/purocean/yn/releases/download/v3.57.0/Yank-Note-linux-amd64-3.57.0.deb)

1. feat: 升级 Electron 到 22.3.17
2. feat: 优化当空间不够时上下文菜单弹出位置
3. feat: 文件选项卡上下文菜单增加文件相关操作
4. feat: 切换到一个不存在的文件时,提示是否创建
5. feat(plugin): 增加 `file-tabs.close-tabs` Action
6. feat(plugin): 增加文件选项卡上下文菜单拓展方法
1. feat: 宏增加 `$seq` 方法,用于生成如 `图-1``图-2` 这样的序号
2. feat: 增加启动隐藏主窗口的配置
3. feat: 增加勾选待办是否自动添加完成时间的配置
4. feat: 限制生成历史版本文件的大小
5. feat: 优化点击 `details` 标签时滚动行为
6. fix: 修复拷贝代码块内容末尾有多余空行的问题

[更多发布说明](https://github.com/purocean/yn/releases)

Expand Down
2 changes: 2 additions & 0 deletions help/FEATURES.md
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,7 @@ If the expression needs to contain [\= or =\], please enter `[\=` or `=\]` to es
- application version: [= $ctx.version =]
- current document name: [= $doc.basename =]
- current time: [= $ctx.lib.dayjs().format('YYYY-MM-DD HH:mm') =]
- sequence: [= $seq`Figure-` =] | [= $seq`Figure-` =] | [= $seq`Figure-` =] | [= $seq`Table-` =] | [= $seq`Table-` =]
- qualifier escape: [= '[\= =\]' =]
- Arithmetic: [= (1 + 2) / 2 =]
- reference file (support 3 levels of nesting, you can use Front Matter variable defined in the target document):
Expand Down Expand Up @@ -680,6 +681,7 @@ variable name | type | description
`$afterMacro` | `(fn: (src: string) => string) => Result` | Define a macro-replaced callback function that can be used for further processing of the replaced text.
`$noop` | `() => Result` | no operation, Used for holding text space
`$doc` | `object` | Current document information
`$seq` | `(label: string) => Result` | Sequence
`$doc.basename` | `string` | File name of current document (no suffix)
`$doc.name` | `string` | File name of current document
`$doc.path` | `string` | Current document path
Expand Down
2 changes: 2 additions & 0 deletions help/FEATURES_ZH-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,7 @@ Front Matter 中的 `define` 字段可以定义一些文本替换映射。支持
- 应用版本:[= $ctx.version =]
- 当前文档名: [= $doc.basename =]
- 当前时间: [= $ctx.lib.dayjs().format('YYYY-MM-DD HH:mm') =]
- 计数器: [= $seq`图-` =] | [= $seq`图-` =] | [= $seq`图-` =] | [= $seq`表-` =] | [= $seq`表-` =]
- 限定符转义: [= '[\= =\]' =]
- 四则运算: [= (1 + 2) / 2 =]
- 引用文件(支持最多嵌套 3 层,可使用目标文档中定义的 Front Matter 变量)
Expand Down Expand Up @@ -679,6 +680,7 @@ Front Matter 中的 `define` 字段可以定义一些文本替换映射。支持
`$export` | `(key: string, val: any) => Result` | 定义一个本文档可以使用的变量
`$noop` | `() => Result` | 无操作函数,可用于文本占位使用
`$afterMacro` | `(fn: (src: string) => string) => Result` | 定义一个宏替换后的回调函数,可用于对替换后的文本进行进一步处理。
`$seq` | `(label: string) => Result` | 文档内部计数器
`$doc` | `object` | 当前文档信息
`$doc.basename` | `string` | 当前文档文件名(无后缀)
`$doc.name` | `string` | 当前文档文件名
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "yank.note",
"version": "3.56.4",
"version": "3.57.0",
"description": "Yank Note: A highly extensible Markdown editor, designed for productivity.",
"main": "dist/main/app.js",
"license": "AGPL-3.0",
Expand Down Expand Up @@ -103,7 +103,7 @@
"crypto-js": "^3.3.0",
"dom-to-image": "^2.6.0",
"electron": "22.3.17",
"electron-builder": "^24.4.0",
"electron-builder": "^23.6.0",
"electron-notarize": "^1.2.2",
"eslint": "^7.11.0",
"eslint-plugin-import": "^2.20.2",
Expand Down
6 changes: 5 additions & 1 deletion src/main/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,11 @@ const createWindow = () => {
win && win.loadURL(getUrl())
restoreWindowBounds()
win.on('ready-to-show', () => {
win!.show()
if (config.get('hide-main-window-on-startup', false)) {
hideWindow()
} else {
win!.show()
}
skipBeforeUnloadCheck = false
})

Expand Down
23 changes: 19 additions & 4 deletions src/main/server/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,23 @@ function writeHistoryZip (zip: AdmZip, zipFilePath: string) {
}

async function writeHistory (filePath: string, content: any) {
const limit = Math.min(10000, config.get('doc-history.number-limit', 500))
let limit = Math.min(10000, config.get('doc-history.number-limit', 500))
if (limit < 1) {
return
}

const historyFilePath = getHistoryFilePath(filePath)

let zip: AdmZip
let tooLarge = false

if ((await fs.pathExists(historyFilePath))) {
const stats = await fs.stat(historyFilePath)
if (stats.size > 1024 * 1024 * 5) { // 5M
console.log('history file too large, limit max versions.', historyFilePath, stats.size)
tooLarge = true
}

zip = readHistoryZip(historyFilePath)
} else {
zip = new AdmZip()
Expand All @@ -105,7 +112,12 @@ async function writeHistory (filePath: string, content: any) {

zip.addFile(dayjs().format('YYYY-MM-DD HH-mm-ss') + ext, content)

orderBy(zip.getEntries(), x => x.entryName, 'desc').slice(limit).forEach(entry => {
const entries = zip.getEntries()
if (tooLarge) {
limit = Math.min(limit, Math.floor(entries.length / 3 * 2))
}

orderBy(entries, x => x.entryName, 'desc').slice(limit).forEach(entry => {
if (!entry.comment) {
zip.deleteFile(entry)
}
Expand Down Expand Up @@ -376,14 +388,17 @@ export function historyList (repo: string, path: string) {
const historyFilePath = getHistoryFilePath(filePath)

if (!(await fs.pathExists(historyFilePath))) {
return []
return { list: [], size: 0 }
}

const stats = await fs.stat(historyFilePath)
const zip = readHistoryZip(historyFilePath)
return orderBy(zip.getEntries(), x => x.entryName, 'desc').map(x => ({
const list = orderBy(zip.getEntries(), x => x.entryName, 'desc').map(x => ({
name: x.entryName,
comment: x.comment
}))

return { list, size: stats.size }
}, path)
}

Expand Down
20 changes: 18 additions & 2 deletions src/renderer/components/DocHistory.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<div class="history-wrapper" v-if="currentDoc" @click.stop>
<div class="history">
<div class="versions-wrapper" v-if="versions && versions.length">
<div v-if="listType === 'all'" class="clear" @click="clearVersions">{{$t('doc-history.clear')}}</div>
<div v-if="listType === 'all'" class="clear" @click="clearVersions">{{$t('doc-history.clear')}}({{sizeText}})</div>
<GroupTabs class="tabs" :tabs="getListTypes()" v-model="listType" />
<div class="versions" v-if="xVersions && xVersions.length">
<div
Expand Down Expand Up @@ -100,6 +100,7 @@ const getListTypes = () => [
const currentDoc = ref<Doc | null>(null)
const currentVersion = ref<Version>()
const versions = ref<Version[] | null>([])
const size = ref(0)
const content = ref('')
const displayType = ref<'content' | 'diff'>('content')
const listType = ref<'all' | 'marked'>('all')
Expand All @@ -116,6 +117,11 @@ const xVersions = computed(() => {
return versions.value
})
const sizeText = computed(() => {
const val = Math.round(size.value / 1024)
return val > 1024 ? `${Math.round(val / 1024)}M` : `${val}K`
})
function show (doc?: Doc) {
doc ??= currentFile.value!
currentDoc.value = doc
Expand All @@ -133,12 +139,22 @@ function show (doc?: Doc) {
function hide () {
currentDoc.value = null
versions.value = null
size.value = 0
}
async function fetchVersions () {
try {
versions.value = null
versions.value = (currentDoc.value ? await fetchHistoryList(currentDoc.value) : []).map(({ name: value, comment }) => {
size.value = 0
let list: any[] = []
if (currentDoc.value) {
const data = await fetchHistoryList(currentDoc.value!)
list = data.list
size.value = data.size
}
versions.value = list.map(({ name: value, comment }) => {
const arr = value.split('.')
const name = arr[0]
const encrypted = isEncrypted({ type: 'file', path: value })
Expand Down
10 changes: 9 additions & 1 deletion src/renderer/others/setting-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,15 @@ const schema: SettingSchema = ({
},
'keep-running-after-closing-window': {
defaultValue: !isMacOS,
title: 'T_setting-panel.keep-running-after-closing-window',
title: 'T_setting-panel.schema.keep-running-after-closing-window',
type: 'boolean',
group: 'other',
format: 'checkbox',
required: true,
},
'hide-main-window-on-startup': {
defaultValue: false,
title: 'T_setting-panel.schema.hide-main-window-on-startup',
type: 'boolean',
group: 'other',
format: 'checkbox',
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/plugins/markdown-code-copy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export default {
h('div', { class: 'p-mcc-language' }, token.info),
h(
'div',
{ class: 'p-mcc-copy-btn copy-text', 'data-text': code, title: ctx.i18n.t('copy-code') },
{ class: 'p-mcc-copy-btn copy-text', 'data-text': code.replace(/\n$/, ''), title: ctx.i18n.t('copy-code') },
h(SvgIcon, { name: 'clipboard', style: 'pointer-events: none' })
),
]))
Expand Down
12 changes: 12 additions & 0 deletions src/renderer/plugins/markdown-macro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@ const globalVars = {
$noop: noop,
}

function createSeq () {
const counters: Record<string, number> = {}
return function (str = '') {
if (!counters[str]) {
counters[str] = 0
}
counters[str]++
return `${str}${counters[str]}`
}
}

function lineCount (str: string) {
let s = 1
const len = str.length
Expand Down Expand Up @@ -309,6 +320,7 @@ export default {
const vars: Record<string, any> = { ...globalVars, ...env.attributes }

vars.$include = include.bind(null, { ...options, belongDoc: file, count: 0, vars })
vars.$seq = createSeq()
vars.$doc = {
basename: file.name ? file.name.substring(0, file.name.lastIndexOf('.')) : '',
...ctx.lib.lodash.pick(env.file, 'name', 'repo', 'path', 'content', 'status')
Expand Down
17 changes: 16 additions & 1 deletion src/renderer/plugins/switch-todo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ export default {
checked = !lineText.match(/^\s*[-+*]\s+\[x\]/)
}

const doneStr = ctx.setting.getSetting('editor.todo-with-time', true)
? `[x] ~~${ctx.lib.dayjs().format('YYYY-MM-DD HH:mm')}~~`
: '[x]'

const value = checked
? lineText.replace('[ ]', `[x] ~~${ctx.lib.dayjs().format('YYYY-MM-DD HH:mm')}~~`)
? lineText.replace('[ ]', doneStr)
: lineText.replace(/(\[x\] ~~[\d-: ]+~~|\[x\])/, '[ ]')

if (value !== lineText) {
Expand Down Expand Up @@ -68,5 +72,16 @@ export default {

return false
})

ctx.setting.changeSchema(schema => {
schema.properties['editor.todo-with-time'] = {
defaultValue: true,
title: 'T_setting-panel.schema.editor.todo-with-time',
type: 'boolean',
format: 'checkbox',
group: 'editor',
required: true,
}
})
}
} as Plugin
2 changes: 1 addition & 1 deletion src/renderer/plugins/sync-scroll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export default {

function clickScroll (e: MouseEvent) {
const _target = e.target as HTMLElement
if (['button', 'div', 'img', 'input', 'canvas'].includes(_target.tagName.toLowerCase())) {
if (['button', 'div', 'img', 'input', 'canvas', 'details', 'summary'].includes(_target.tagName.toLowerCase())) {
return
}

Expand Down
2 changes: 1 addition & 1 deletion src/renderer/support/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ export async function deleteFile (file: FileItem): Promise<ApiResult<any>> {
return fetchHttp(`/api/file?path=${encodeURIComponent(path)}&repo=${encodeURIComponent(repo)}`, { method: 'DELETE' })
}

export async function fetchHistoryList (file: PathItem): Promise<{name: string, comment: string}[]> {
export async function fetchHistoryList (file: PathItem): Promise<{size: number, list: {name: string, comment: string}[]}> {
const { path, repo } = file
const { data } = await fetchHttp(`/api/history/list?path=${encodeURIComponent(path)}&repo=${encodeURIComponent(repo)}`)
return data
Expand Down
2 changes: 2 additions & 0 deletions src/renderer/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ export interface BuildInSettings {
'editor.enable-preview': boolean,
'editor.font-family': string,
'editor.complete-emoji': boolean,
'editor.todo-with-time': boolean,
'render.md-html': boolean,
'render.md-breaks': boolean,
'render.md-linkify': boolean,
Expand All @@ -325,6 +326,7 @@ export interface BuildInSettings {
'extension.registry': RegistryHostname,
'extension.auto-upgrade': boolean,
'keep-running-after-closing-window': boolean,
'hide-main-window-on-startup': boolean,
'plantuml-api': string,
}

Expand Down
4 changes: 3 additions & 1 deletion src/share/i18n/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,6 @@ const data = {
'add': 'Add %s',
'delete-warning': 'Are you sure you want to remove this node?',
'error-choose-repo-path': 'Please choose repository path',
'keep-running-after-closing-window': 'Keep Running after Closing Window',
'tabs': {
'repos': 'Repositories',
'appearance': 'Appearance',
Expand Down Expand Up @@ -378,6 +377,7 @@ const data = {
'enable-preview': 'Enable Preview - Open new files using temporary tabs, double click the tab to change',
'font-family': 'Font Family',
'complete-emoji': 'Complete Emoji - Input : to display emoji list',
'todo-with-time': 'Add time when checking todo',
},
'render': {
'md-html': 'Enable HTML',
Expand Down Expand Up @@ -431,6 +431,8 @@ const data = {
'match-placeholder': '%foo%',
'replace-placeholder': '%foo% -> BAR',
},
'hide-main-window-on-startup': 'Hide Main Window on Startup',
'keep-running-after-closing-window': 'Keep Running after Closing Window',
}
},
'quick-open': {
Expand Down
4 changes: 3 additions & 1 deletion src/share/i18n/languages/zh-CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,6 @@ const data: BaseLanguage = {
'add': '添加%s',
'delete-warning': '确定要删除吗?',
'error-choose-repo-path': '请选择储存位置',
'keep-running-after-closing-window': '关闭窗口后保持运行',
'schema': {
'repos': {
'repos': '仓库',
Expand All @@ -369,6 +368,7 @@ const data: BaseLanguage = {
'enable-preview': '开启预览 - 打开新文件使用临时标签,双击标签以更改',
'font-family': '字体',
'complete-emoji': '自动补全 Emoji - 输入 : 时显示 Emoji 列表',
'todo-with-time': '勾选待办事项时自动添加时间',
},
'render': {
'md-html': '启用 HTML',
Expand Down Expand Up @@ -422,6 +422,8 @@ const data: BaseLanguage = {
'match-placeholder': '%foo%',
'replace-placeholder': '%foo% -> BAR',
},
'keep-running-after-closing-window': '关闭窗口后保持运行',
'hide-main-window-on-startup': '启动时隐藏主窗口',
},
'tabs': {
'repos': '仓库',
Expand Down
Loading

1 comment on commit 701b8d7

@vercel
Copy link

@vercel vercel bot commented on 701b8d7 Jul 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

yn-api-doc – ./

yn-api-doc.vercel.app
yn-api-doc-purocean.vercel.app
yn-api-doc-git-master-purocean.vercel.app

Please sign in to comment.