Skip to content

Commit

Permalink
Merge pull request #16 from Zuoqiu-Yingyi/dev
Browse files Browse the repository at this point in the history
chore: release v0.2.1
  • Loading branch information
Zuoqiu-Yingyi authored Nov 18, 2023
2 parents 3198e84 + cff89ee commit 219dc00
Show file tree
Hide file tree
Showing 17 changed files with 308 additions and 47 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ permissions:

env:
PACKAGE_NAME: monaco-editor
PACKAGE_VERSION: 0.2.0
PACKAGE_VERSION: 0.2.1

jobs:
release-please:
Expand Down
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "monaco-editor",
"private": true,
"version": "0.2.0",
"version": "0.2.1",
"type": "module",
"scripts": {
"dev": "vite",
Expand All @@ -17,23 +17,23 @@
},
"devDependencies": {
"@monaco-editor/loader": "^1.4.0",
"@siyuan-community/vditor": "^3.9.5",
"@sveltejs/vite-plugin-svelte": "^2.4.6",
"@siyuan-community/vditor": "^3.9.6",
"@sveltejs/vite-plugin-svelte": "^3.0.0",
"@tsconfig/svelte": "^4.0.1",
"@types/node": "^20.8.2",
"@types/streamsaver": "^2.0.2",
"@types/node": "^20.9.1",
"@types/streamsaver": "^2.0.4",
"deepmerge": "^4.3.1",
"less": "^4.2.0",
"material-icon-theme": "^4.31.0",
"monaco-editor": "^0.41.0",
"monaco-editor": "^0.44.0",
"streamsaver": "^2.0.6",
"svelte": "^4.2.1",
"svelte-check": "^3.5.2",
"svelte": "^4.2.5",
"svelte-check": "^3.6.0",
"svelte-preprocess-less": "^0.4.0",
"ts-node": "^10.9.1",
"tslib": "^2.6.2",
"typescript": "^5.2.2",
"vite": "^4.4.11",
"vite": "^4.5.0",
"vite-plugin-static-copy": "^0.16.0",
"xml-js": "^1.6.11"
},
Expand Down
5 changes: 5 additions & 0 deletions public/i18n/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,11 @@
}
},
"menu": {
"charset": {
"label": "Character set",
"placeholder": "The name of the character set",
"text": "Open the file with encoding"
},
"confirm": {
"placeholder": "The full path to the resource",
"text": "Warning: You are operating on a protected resource ${1} !<br/>Your subsequent activities may lead to data loss or damage!<br/><br/>If you want to continue the operation, please enter the complete path of the resource ${2} in the text box below",
Expand Down
5 changes: 5 additions & 0 deletions public/i18n/zh_CHT.json
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,11 @@
}
},
"menu": {
"charset": {
"label": "字符集",
"placeholder": "字符集名稱",
"text": "使用編碼打開文件"
},
"confirm": {
"placeholder": "資源完整路徑",
"text": "警告:您正在操作受保護的資源 ${1} !<br/>您之後的活動可能導致資料丟失或損壞!<br/><br/>若繼續操作,請在下方文字框中輸入該資源的完整路徑 ${2}",
Expand Down
5 changes: 5 additions & 0 deletions public/i18n/zh_CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,11 @@
}
},
"menu": {
"charset": {
"label": "字符集",
"placeholder": "字符集名称",
"text": "使用编码打开文件"
},
"confirm": {
"placeholder": "资源完整路径",
"text": "警告:您正在操作受保护的资源 ${1} !<br/>您之后的活动可能导致数据丢失或损坏!<br/><br/>若继续操作,请在下方文本框中输入该资源的完整路径 ${2}",
Expand Down
2 changes: 1 addition & 1 deletion public/libs/monaco-editor/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.40.0
0.44.0
2 changes: 1 addition & 1 deletion public/libs/streamsaver/mitm.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
/* 👇避免与 service-worker.js 冲突👇 */
const swReg = swRegs.find(sw => globalThis.location.href.startsWith(sw.scope))
/* 👆避免与 service-worker.js 冲突👆 */
return swReg || navigator.serviceWorker.register('sw.js', { scope: './' })
return swReg || navigator.serviceWorker.register('streamsaver-service-worker.js', { scope: './' })
}).then(swReg => {
const swRegTmp = swReg.installing || swReg.waiting

Expand Down
40 changes: 38 additions & 2 deletions public/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,44 @@
"name": "monaco-editor",
"author": "Zuoqiu Yingyi",
"url": "https://github.com/Zuoqiu-Yingyi/siyuan-plugin-monaco-editor",
"version": "0.2.0",
"minAppVersion": "2.10.1",
"version": "0.2.1",
"minAppVersion": "2.10.10",
"keywords": [
"代码",
"代碼",
"程式碼",
"code",
"visual",
"studio",
"vscode",
"monaco",
"编辑器",
"編輯器",
"editor",
"vditor",
"文件",
"資料",
"file",
"文件夹",
"文件夾",
"資料夾",
"folder",
"管理",
"manage",
"资源管理器",
"資源管理器",
"explorer",
"markdown",
"所见即所得",
"所見即所得",
"wysiwyg",
"下载",
"下載",
"download",
"上传",
"上傳",
"upload"
],
"backends": [
"all"
],
Expand Down
1 change: 0 additions & 1 deletion src/breadcrumb/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import {
} from "svelte/store";
import type Tab from "@workspace/components/siyuan/tab/Tab.svelte";
import { TooltipsDirection } from "@workspace/components/siyuan/misc/tooltips";
import { uri2path } from "@workspace/utils/misc/url";

export interface INetworkStore extends IBaseStore {
fullscreen: Writable<ComponentProps<Tab>["fullscreen"]>; // 是否全屏显示
Expand Down
7 changes: 5 additions & 2 deletions src/components/Editor.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,11 @@
contextMenuOrder: 1, // 菜单分组内排序
run: () => {
// 点击后执行的操作
// Editor.EditorOption.wordWrap === 129
const word_wrap_status = editor.getOption(129) === "off" ? "on" : "off";
/**
* {@link Editor.EditorOption.wordWrap}
* Editor.EditorOption.wordWrap === 130
*/
const word_wrap_status = editor.getOption(130) === "off" ? "on" : "off";
updateOptions({ wordWrap: word_wrap_status });
},
});
Expand Down
12 changes: 7 additions & 5 deletions src/components/Vditor.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@
/* 思源静态文件服务 */
case isStaticPathname(src):
source = join(rootURL, src);
source = `${rootURL}/${src}`;
break;
/* 其他 */
Expand Down Expand Up @@ -317,10 +317,12 @@
}
}
if (element.src) {
element.src = source;
} else {
element.srcset = source;
if (src !== source) {
if (element.src) {
element.src = source;
} else {
element.srcset = source;
}
}
}
}
Expand Down
12 changes: 7 additions & 5 deletions src/explorer/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ export class ExplorerContextMenu {
folder: false,
file: true,
});

if (isMarkdown) {
url.searchParams.set("scheme", OpenScheme.Vditor);
const href_vditor = url.href;
Expand Down Expand Up @@ -607,7 +607,8 @@ export class ExplorerContextMenu {
});
}

const href_export = `siyuan://plugins/${this.plugin.name}/export/workspace/${relative}`;
const url_export = new URL(`siyuan://plugins/${this.plugin.name}/export/workspace/${relative}`);
const href_export = url_export.href;

/* 复制导出超链接 */
submenu.push({
Expand Down Expand Up @@ -644,8 +645,9 @@ export class ExplorerContextMenu {
if (accessible) {
const pathname = workspacePath2StaticPathname(relative);
const url = new URL(`${globalThis.document.baseURI}${pathname}`);
const href = url.href;
const link1 = `[${name}](<${pathname}>)`;
const link2 = `[${name}](<${url.href}>)`;
const link2 = `[${name}](<${href}>)`;

submenu.push(
/* 复制引用路径 */
Expand All @@ -669,9 +671,9 @@ export class ExplorerContextMenu {
options: {
icon: "iconLink",
label: this.i18n.menu.copyURL.label,
accelerator: escapeHTML(url.href),
accelerator: escapeHTML(href),
click: () => {
copyText(url.href);
copyText(href);
},
},
root: true,
Expand Down
74 changes: 70 additions & 4 deletions src/handlers/asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ import type { IEditorModel } from "@/types/editor";
import type { IMonacoEditorOptions } from "@/types/config";
import { staticPathname2WorkspacePath } from "@workspace/utils/siyuan/url";
import { extname } from "@workspace/utils/path/browserify";
import { UTF8_CHAR_SET, type TLabel, CHAR_SET_LIST, CHAR_SET } from "@workspace/utils/coder/text";
import { detect } from "@workspace/utils/coder/text/charset";
import { TextTranscoder } from "@workspace/utils/coder/text/transcoder";
import { fn__code } from "@workspace/utils/siyuan/text/span";
import type { IBlob } from "@siyuan-community/siyuan-sdk";
import { asyncPrompt } from "@workspace/components/siyuan/dialog/prompt";

export interface IAssetHandler extends IHandler {
path: string; // 相对于工作空间目录的路径
Expand Down Expand Up @@ -73,6 +79,52 @@ export class AssetHandler extends Handler {
};
}

protected async updateHandler(
blob: IBlob,
options: IAssetHandlerOptions,
handler: IAssetHandler,
): Promise<void> {
handler.modified.value = await blob.text();
if (options.updatable) {
handler.update = this.createUpdateFunction(handler.path);
}
}

protected async updateHandlerWithCharset(
charset: TLabel,
blob: IBlob,
options: IAssetHandlerOptions,
handler: IAssetHandler,
): Promise<void> {
try {
this.plugin.siyuan.showMessage(`${this.plugin.i18n.menu.charset.label}: ${fn__code(charset)}`);

const buffer = await blob.arrayBuffer();
const transcoder = new TextTranscoder(charset);
handler.modified.value = transcoder.decode(buffer);

if (options.updatable) {
handler.update = this.createUpdateFunction(
handler.path,
value => {
try {
const buffer = transcoder.encode(value);
return new Blob([buffer]);
} catch (error) {
this.plugin.siyuan.showMessage(error, -1, "error");
throw error;
}
},
);
}
} catch (error) {
new Error();
this.plugin.siyuan.showMessage(error, -1, "error");
this.plugin.logger.warn(error);
await this.updateHandler(blob, options, handler);
}
}

/**
* 生产一个块处理器
*/
Expand All @@ -92,11 +144,25 @@ export class AssetHandler extends Handler {

const response = await this.client.getFile(
{ path },
"text",
"blob",
);
handler.modified.value = response as string;
if (options.updatable) {
handler.update = this.createUpdateFunction(path);
const buffer = await response.arrayBuffer();
const charset = detect(response.contentType, buffer);
const flag_trans = !!charset && !UTF8_CHAR_SET.has(charset);

if (flag_trans) {
const input = await asyncPrompt(this.plugin.siyuan.Dialog, {
title: `${fn__code(this.plugin.name)}: ${this.plugin.i18n.menu.charset.label}`,
text: this.plugin.i18n.menu.charset.text,
placeholder: this.plugin.i18n.menu.charset.placeholder,
value: charset || "utf-8",
datalist: CHAR_SET_LIST,
confirm: value => CHAR_SET.has(value as TLabel),
}) as TLabel;
await this.updateHandlerWithCharset(input, response, options, handler);
}
else {
await this.updateHandler(response, options, handler);
}

return handler;
Expand Down
2 changes: 1 addition & 1 deletion src/iframes/vditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import { Client } from "@siyuan-community/siyuan-sdk";

const src2url = new Map<string, string>(); // 将 src 目标映射为 blob URL
const baseURL = "./../libs/vditor";
const rootURL = trimSuffix(location.pathname, `/plugins/${manifest.name}/iframes/vditor.html`);
const rootURL = trimSuffix(globalThis.location.pathname, `/plugins/${manifest.name}/iframes/vditor.html`);
const logger = new Logger(`${manifest.name}-vditor-${(() => {
switch (true) {
case FLAG_ELECTRON:
Expand Down
Loading

0 comments on commit 219dc00

Please sign in to comment.