Skip to content

Commit 6a2027a

Browse files
WhiteSevsCodFrmCopilot
authored
🐛 修复N个问题 (#710)
* ✨ 新增在编辑器对比页面自动隐藏未改变的代码 * 🐛 修复 Warning: Function components cannot be given refs. Attempts to access this ref will fail. Did you mean to use React.forwardRef()? * 🐛 修复 Warning: validateDOMNesting(...): <div> cannot appear as a child of <table>. * 🐛 fix: 修复 Error: Could not find source file: 'inmemory://model/1'. * ✨ feat: 新增部分metadata的悬停提示 * Update src/pkg/utils/monaco-editor/index.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: wangyizhi <i@xloli.top> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 49eb379 commit 6a2027a

5 files changed

Lines changed: 52 additions & 12 deletions

File tree

src/pages/components/CodeEditor/index.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ const CodeEditor: React.ForwardRefRenderFunction<{ editor: editor.IStandaloneCod
4545
// @ts-ignore
4646
if (diffCode) {
4747
edit = editor.createDiffEditor(inlineDiv, {
48+
hideUnchangedRegions: {
49+
enabled: true,
50+
},
4851
enableSplitViewResizing: false,
4952
renderSideBySide: false,
5053
folding: true,
@@ -77,9 +80,9 @@ const CodeEditor: React.ForwardRefRenderFunction<{ editor: editor.IStandaloneCod
7780
setEditor(edit);
7881
}
7982
return () => {
80-
if (edit) {
81-
edit.dispose();
82-
}
83+
// 目前会出现:Uncaught (in promise) Canceled: Canceled
84+
// 问题追踪:https://github.com/microsoft/monaco-editor/issues/4702
85+
edit?.dispose();
8386
};
8487
}, [div, code, diffCode, editable, id]);
8588

src/pages/install/main.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ import "@arco-design/web-react/dist/css/arco.css";
1111
import "@App/locales/locales";
1212
import "@App/index.css";
1313
import "./index.css";
14+
import registerEditor from "@App/pkg/utils/monaco-editor";
15+
16+
registerEditor();
1417

1518
// 初始化日志组件
1619
const loggerCore = new LoggerCore({

src/pages/options/routes/ScriptList.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ const DragHandle = () => {
162162
);
163163
};
164164

165-
const DraggableContainer = (props: any) => {
165+
const DraggableContainer = React.forwardRef((props: any, ref: any) => {
166166
const context = useContext(DraggableContext);
167167
if (!context) return <></>;
168168
const { sensors, dispatch, scriptList } = context;
@@ -171,6 +171,7 @@ const DraggableContainer = (props: any) => {
171171
sensors={sensors}
172172
collisionDetection={closestCenter}
173173
modifiers={[restrictToVerticalAxis]}
174+
accessibility={{ container: document.body }}
174175
onDragEnd={(event: DragEndEvent) => {
175176
const { active, over } = event;
176177
if (!over) {
@@ -182,11 +183,12 @@ const DraggableContainer = (props: any) => {
182183
}}
183184
>
184185
<SortableContext items={scriptList.map((s) => ({ ...s, id: s.uuid }))} strategy={verticalListSortingStrategy}>
185-
<tbody {...props} />
186+
<tbody {...props} ref={ref} />
186187
</SortableContext>
187188
</DndContext>
188189
);
189-
};
190+
});
191+
DraggableContainer.displayName = "DraggableContainer";
190192

191193
const EnableSwitch = React.memo(
192194
({

src/pkg/utils/monaco-editor/config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ const config = {
44
noSemanticValidation: true,
55
noSyntaxValidation: false,
66
onlyVisible: false,
7+
// 该配置用于修复 Error: Could not find source file: 'inmemory://model/1'.
8+
// https://github.com/microsoft/monaco-editor/issues/1842
9+
// https://github.com/suren-atoyan/monaco-react/issues/75#issuecomment-1890761086
10+
allowNonTsExtensions: true,
711
} as languages.typescript.CompilerOptions;
812

913
export const defaultConfig = JSON.stringify(config, null, 2);

src/pkg/utils/monaco-editor/index.ts

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,37 @@ export default function registerEditor() {
1818
// 悬停提示
1919
const prompt: { [key: string]: any } = {
2020
name: "脚本名称",
21-
description: "脚本描述",
22-
namespace: "脚本命名空间",
21+
copyright: "脚本的版权信息",
22+
license: "脚本的开源协议",
2323
version: "脚本版本",
24+
description: "脚本描述",
25+
icon: "脚本图标",
26+
iconURL: "脚本图标",
27+
defaulticon: "脚本图标",
28+
icon64: "64x64 大小的脚本图标",
29+
icon64URL: "64x64 大小的脚本图标",
30+
grant: "脚本特殊Api权限申请",
2431
author: "脚本作者",
32+
"run-at":
33+
"脚本的运行时间<br>`document-start`:在前端匹配到网址后,以最快的速度注入脚本到页面中<br>`document-end`:DOM 加载完成后注入脚本,此时页面脚本和图像等资源可能仍在加载<br>`document-idle`:所有内容加载完成后注入脚本<br>`document-body`:脚本只会在页面中有 body 元素时才会注入",
34+
"run-in": "脚本注入的环境",
35+
homepage: "脚本主页",
36+
homepageURL: "脚本主页",
37+
website: "脚本主页",
2538
background: "后台脚本",
39+
include: "脚本匹配url运行的页面",
40+
match: "脚本匹配url运行的页面",
41+
exclude: "脚本匹配url不运行的页面",
42+
connect: "获取网站的访问权限",
43+
resource: "引入资源文件",
44+
require: "引入外部 js 文件",
45+
noframes: "表示脚本不运行在`<frame>`中",
46+
definition: "ScriptCat特有功能:一个`.d.ts`文件的引用地址,能够自动补全编辑器的自动提示",
47+
antifeature: "这是与脚本市场有关的,不受欢迎的功能需要加上此描述值",
48+
updateURL: "脚本检查更新的url",
49+
downloadURL: "脚本更新的下载地址",
50+
supportURL: "支持站点,bug 反馈页面",
51+
source: "脚本源码页",
2652
crontab: `定时脚本 crontab 参考(不适用于云端脚本)
2753
* * * * * * 每秒运行一次
2854
* * * * * 每分钟运行一次
@@ -41,7 +67,7 @@ export default function registerEditor() {
4167
provideHover: (model, position) => {
4268
return new Promise((resolve) => {
4369
const line = model.getLineContent(position.lineNumber);
44-
const flag = /^\/\/\s*@(\w+?)(\s+(.*?)|)$/.exec(line);
70+
const flag = /^\/\/\s*@([\w-]+?)(\s+(.*?)|)$/.exec(line);
4571
if (flag) {
4672
resolve({
4773
contents: [{ value: prompt[flag[1]], supportHtml: true }],
@@ -167,9 +193,11 @@ export default function registerEditor() {
167193
Promise.all([systemConfig.getEditorConfig(), systemConfig.getEditorTypeDefinition()]).then(
168194
([editorConfig, typeDefinition]) => {
169195
// 设置编辑器设置
170-
languages.typescript.javascriptDefaults.setCompilerOptions(
171-
JSON.parse(editorConfig) as languages.typescript.CompilerOptions
172-
);
196+
const options = JSON.parse(editorConfig) as languages.typescript.CompilerOptions;
197+
languages.typescript.javascriptDefaults.setCompilerOptions({
198+
allowNonTsExtensions: true,
199+
...options,
200+
});
173201
// 注册类型定义
174202
languages.typescript.javascriptDefaults.addExtraLib(typeDefinition, "scriptcat.d.ts");
175203
}

0 commit comments

Comments
 (0)