Skip to content

Commit 7d3797c

Browse files
committed
Merge branch 'release/3.55.0'
2 parents 7c06677 + bb5062e commit 7d3797c

14 files changed

Lines changed: 96 additions & 64 deletions

README.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,14 @@ For more information on how to use the following functions, please see [characte
7676

7777
## Changelogs
7878

79-
### [v3.54.0](https://github.com/purocean/yn/releases/tag/v3.54.0) 2023-06-08
79+
### [v3.55.0](https://github.com/purocean/yn/releases/tag/v3.55.0) 2023-07-12
8080

81-
[Windows](https://github.com/purocean/yn/releases/download/v3.54.0/Yank-Note-win-x64-3.54.0.exe) | [macOS arm64](https://github.com/purocean/yn/releases/download/v3.54.0/Yank-Note-mac-arm64-3.54.0.dmg) | [macOS x64](https://github.com/purocean/yn/releases/download/v3.54.0/Yank-Note-mac-x64-3.54.0.dmg) | [Linux AppImage](https://github.com/purocean/yn/releases/download/v3.54.0/Yank-Note-linux-x86_64-3.54.0.AppImage) | [Linux deb](https://github.com/purocean/yn/releases/download/v3.54.0/Yank-Note-linux-amd64-3.54.0.deb)
81+
[Windows](https://github.com/purocean/yn/releases/download/v3.55.0/Yank-Note-win-x64-3.55.0.exe) | [macOS arm64](https://github.com/purocean/yn/releases/download/v3.55.0/Yank-Note-mac-arm64-3.55.0.dmg) | [macOS x64](https://github.com/purocean/yn/releases/download/v3.55.0/Yank-Note-mac-x64-3.55.0.dmg) | [Linux AppImage](https://github.com/purocean/yn/releases/download/v3.55.0/Yank-Note-linux-x86_64-3.55.0.AppImage) | [Linux deb](https://github.com/purocean/yn/releases/download/v3.55.0/Yank-Note-linux-amd64-3.55.0.deb)
8282

83-
1. feat: add focus editor shortcut `Shift + Alt/Option + X`
84-
2. feat: editor menu supports Chinese
85-
3. feat: optimize the behavior of clicking preview to scroll to the editor position
86-
4. feat: optimize the behavior of batch checking to-do items (press `Cmd/Ctrl + O` after selecting)
87-
5. feat(plugin): add `needReloadWindowWhenChanged` field to setting item, support to define whether to reload page after value changes
88-
6. feat(plugin): `SETTING_CHANGED` hook adds `schema` parameter
83+
1. feat: upgrade Monaco editor to 0.40.0
84+
2. feat: support outputting HTML results when running js code blocks
85+
3. fix: fix the scope problem of running js code block
86+
4. fix: fix the problem that the startup `--readonly` parameter is invalid
8987

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

README_ZH-CN.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,14 @@
7676

7777
## 更新日志
7878

79-
### [v3.54.0](https://github.com/purocean/yn/releases/tag/v3.54.0) 2023-06-08
79+
### [v3.55.0](https://github.com/purocean/yn/releases/tag/v3.55.0) 2023-07-12
8080

81-
[Windows](https://github.com/purocean/yn/releases/download/v3.54.0/Yank-Note-win-x64-3.54.0.exe) | [macOS arm64](https://github.com/purocean/yn/releases/download/v3.54.0/Yank-Note-mac-arm64-3.54.0.dmg) | [macOS x64](https://github.com/purocean/yn/releases/download/v3.54.0/Yank-Note-mac-x64-3.54.0.dmg) | [Linux AppImage](https://github.com/purocean/yn/releases/download/v3.54.0/Yank-Note-linux-x86_64-3.54.0.AppImage) | [Linux deb](https://github.com/purocean/yn/releases/download/v3.54.0/Yank-Note-linux-amd64-3.54.0.deb)
81+
[Windows](https://github.com/purocean/yn/releases/download/v3.55.0/Yank-Note-win-x64-3.55.0.exe) | [macOS arm64](https://github.com/purocean/yn/releases/download/v3.55.0/Yank-Note-mac-arm64-3.55.0.dmg) | [macOS x64](https://github.com/purocean/yn/releases/download/v3.55.0/Yank-Note-mac-x64-3.55.0.dmg) | [Linux AppImage](https://github.com/purocean/yn/releases/download/v3.55.0/Yank-Note-linux-x86_64-3.55.0.AppImage) | [Linux deb](https://github.com/purocean/yn/releases/download/v3.55.0/Yank-Note-linux-amd64-3.55.0.deb)
8282

83-
1. feat: 增加聚焦编辑器快捷键 `Shift + Alt/Option + X`
84-
2. feat: 编辑器菜单支持中文
85-
3. feat: 优化点击预览滚动到编辑器位置的行为
86-
4. feat: 优化批量勾选待办(选中后按 `Cmd/Ctrl + O`)的行为
87-
5. feat(plugin): 设置项增加 `needReloadWindowWhenChanged` 字段,支持定义值变更后是否重载页面
88-
6. feat(plugin): `SETTING_CHANGED` 钩子增加 `schema` 参数
83+
1. feat: 升级 Monaco editor 到 0.40.0
84+
2. feat: 运行 js 代码块时支持输出 HTML 结果
85+
3. fix: 修复运行 js 代码块作用域问题
86+
4. fix: 修复启动 `--readonly` 参数无效问题
8987

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

help/FEATURES.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,11 @@ ctx.ui.useToast().show("info", "HELLOWORLD!")
265265
console.log('HELLOWORLD')
266266
```
267267

268+
```js
269+
// --run-- --output-html--
270+
console.log(`output <i>HTML</i>`)
271+
```
272+
268273
```node
269274
// --run--
270275
console.log('HELLOWORLD')

help/FEATURES_ZH-CN.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,11 @@ ctx.ui.useToast().show("info", "HELLOWORLD!")
266266
console.log('HELLOWORLD')
267267
```
268268

269+
```js
270+
// --run-- --output-html--
271+
console.log(`output <i>HTML</i>`)
272+
```
273+
269274
```node
270275
// --run--
271276
console.log('HELLOWORLD')

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "yank.note",
3-
"version": "3.54.0",
3+
"version": "3.55.0",
44
"description": "Yank Note: A highly extensible Markdown editor, designed for productivity.",
55
"main": "dist/main/app.js",
66
"license": "AGPL-3.0",
@@ -127,7 +127,7 @@
127127
"markdown-it-multimd-table": "^4.1.2",
128128
"markdown-it-sub": "^1.0.0",
129129
"markdown-it-sup": "^1.0.0",
130-
"monaco-editor": "^0.34.1",
130+
"monaco-editor": "^0.40.0",
131131
"normalize.css": "^8.0.1",
132132
"parse-author": "^2.0.0",
133133
"path-browserify": "^1.0.1",
@@ -142,7 +142,7 @@
142142
"typescript": "^4.3.2",
143143
"utility-types": "^3.10.0",
144144
"viewerjs": "^1.11.0",
145-
"vite": "^2.9.13",
145+
"vite": "^2.9.16",
146146
"vue": "^3.2.23",
147147
"vue-router": "^4.0.0-0",
148148
"vue-tsc": "^0.29.8",

src/renderer/components/DefaultEditor.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { registerHook, removeHook } from '@fe/core/hook'
1111
import { registerAction, removeAction } from '@fe/core/action'
1212
import { isEncrypted, isSameFile, saveDoc, toUri } from '@fe/services/document'
1313
import { getEditor, getIsDefault, setValue, whenEditorReady } from '@fe/services/editor'
14-
import { HELP_REPO_NAME } from '@fe/support/args'
14+
import { FLAG_READONLY, HELP_REPO_NAME } from '@fe/support/args'
1515
import { getSetting } from '@fe/services/setting'
1616
import { getCurrentLanguage } from '@fe/services/i18n'
1717
import type { Doc } from '@fe/types'
@@ -111,7 +111,7 @@ export default defineComponent({
111111
112112
await nextTick()
113113
getEditor().updateOptions({
114-
readOnly: !current || !current.plain
114+
readOnly: FLAG_READONLY || !current || !current.plain
115115
})
116116
117117
if (getIsDefault()) {

src/renderer/components/GetStarted.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<div class="desc">{{$t('slogan')}}</div>
77
</div>
88
<div class="section">
9-
<div class="start">
9+
<div v-if="!FLAG_READONLY" class="start">
1010
<h2>{{$t('get-started.start')}}</h2>
1111
<div class="list">
1212
<div class="item" v-if="!hasRepo">
@@ -71,7 +71,7 @@
7171
import dayjs from 'dayjs'
7272
import { computed } from 'vue'
7373
import { useStore } from 'vuex'
74-
import { URL_GITHUB } from '@fe/support/args'
74+
import { FLAG_READONLY, URL_GITHUB } from '@fe/support/args'
7575
import { useI18n } from '@fe/services/i18n'
7676
import type { AppState } from '@fe/support/store'
7777
import { showManager as showExtensionManager } from '@fe/others/extension'

src/renderer/components/TreeNode.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<div class="item-label" draggable="true" @dragstart="onDragStart">
2323
{{ itemNode.name }} <span class="count">({{itemNode.children ? itemNode.children.length : 0}})</span>
2424
</div>
25-
<div class="item-action">
25+
<div v-if="!FLAG_READONLY" class="item-action">
2626
<svg-icon class="icon" name="folder-plus-solid" @click.exact.stop.prevent="createFolder()" :title="$t('tree.context-menu.create-dir')"></svg-icon>
2727
<svg-icon class="icon" name="plus" @click.exact.stop.prevent="createFile()" :title="$t('tree.context-menu.create-doc')"></svg-icon>
2828
</div>
@@ -62,6 +62,7 @@ import { createDir, createDoc, deleteDoc, duplicateDoc, isMarkdownFile, isMarked
6262
import { useI18n } from '@fe/services/i18n'
6363
import { dirname, extname, isBelongTo, join } from '@fe/utils/path'
6464
import { useToast } from '@fe/support/ui/toast'
65+
import { FLAG_READONLY } from '@fe/support/args'
6566
import type { AppState } from '@fe/support/store'
6667
import SvgIcon from './SvgIcon.vue'
6768
@@ -345,6 +346,7 @@ export default defineComponent({
345346
onDrop,
346347
onDragStart,
347348
isMarkdownFile,
349+
FLAG_READONLY,
348350
}
349351
},
350352
})

src/renderer/others/setting-schema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { cloneDeep } from 'lodash-es'
22
import { DEFAULT_EXCLUDE_REGEX } from '@share/misc'
33
import { isMacOS, isWindows } from '@fe/support/env'
4-
import { FLAG_DISABLE_XTERM, FLAG_MAS, MONACO_EDITOR_NLS } from '@fe/support/args'
4+
import { FLAG_DISABLE_XTERM, FLAG_MAS } from '@fe/support/args'
55
import { SettingSchema } from '@fe/types'
66

77
const schema: SettingSchema = ({

src/renderer/plugins/code-runners.tsx

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,23 @@ class JavascriptExecutor implements ReadableStreamDefaultReader<string> {
2222
})
2323
}
2424

25+
private getIframeWindow () {
26+
const id = 'code-runner-javascript-vm'
27+
28+
// clean up
29+
document.getElementById(id)?.remove()
30+
31+
const iframe = document.createElement('iframe')
32+
iframe.id = id
33+
iframe.style.display = 'none'
34+
document.body.appendChild(iframe)
35+
const iframeWindow = iframe.contentWindow! as Window & typeof globalThis
36+
37+
iframeWindow.ctx = window.ctx
38+
39+
return iframeWindow
40+
}
41+
2542
private async runCode (): Promise<undefined> {
2643
const stringify = (args: any[]) => args.map((arg) => {
2744
if (['boolean', 'number', 'bigint', 'string', 'symbol', 'function'].includes(typeof arg)) {
@@ -37,18 +54,23 @@ class JavascriptExecutor implements ReadableStreamDefaultReader<string> {
3754
this._readResolve(str)
3855
}
3956

40-
// eslint-disable-next-line no-eval
41-
await eval(`(async () => {
42-
const console = new Proxy(window.console, {
43-
get: (obj, prop) => ['error', 'warn', 'info', 'log', 'debug'].includes(prop)
44-
? (...args) => {
45-
obj[prop](...args);
46-
${tick.name}(args);
57+
const iframeWindow = this.getIframeWindow()
58+
const xConsole = new Proxy(iframeWindow.console, {
59+
get: (obj: any, prop: any) => ['error', 'warn', 'info', 'log', 'debug'].includes(prop)
60+
? (...args: any[]) => {
61+
obj[prop](...args)
62+
if (prop === 'log') {
63+
tick(args)
64+
} else {
65+
tick([`${prop[0]}:`, ...args])
66+
}
4767
}
48-
: obj[prop]
49-
});
50-
${this.code}
51-
})()`)
68+
: obj[prop]
69+
})
70+
71+
const AsyncFunction = iframeWindow.eval('(async function(){}).constructor')
72+
const fn = new AsyncFunction('console', 'ctx', this.code)
73+
await fn.call(iframeWindow, xConsole, window.ctx)
5274

5375
await sleep(0)
5476
this._readResolve('')
@@ -87,16 +109,18 @@ export default {
87109
register: (ctx) => {
88110
ctx.runner.registerRunner({
89111
name: 'javascript',
90-
order: 255,
112+
order: 100,
91113
match (language) {
92114
return ['js', 'javascript'].includes(language.toLowerCase())
93115
},
94116
getTerminalCmd () {
95117
return null
96118
},
97119
async run (_, code) {
120+
const firstLine = code.split('\n')[0].trim()
121+
const outputHtml = firstLine.includes('--output-html--')
98122
return {
99-
type: 'html',
123+
type: outputHtml ? 'html' : 'plain',
100124
value: new JavascriptExecutor(code)
101125
}
102126
},

0 commit comments

Comments
 (0)