Skip to content

Commit

Permalink
🐛 Add settings for quick insert
Browse files Browse the repository at this point in the history
  • Loading branch information
justice2001 committed Jan 2, 2024
1 parent 921234a commit 89be498
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 10 deletions.
2 changes: 2 additions & 0 deletions console/src/type/editor.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ export declare type EditorConfig = {
defaultRenderMode: "ir" | "wysiwyg" | "sv" | undefined;
typeWriterMode: boolean;
codeBlockPreview: boolean;
enableQuickInsert: boolean;
quickInsertUrl: [];
};
};

Expand Down
20 changes: 12 additions & 8 deletions console/src/utils/fetch-utils.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import type {QuickInsert} from "@/type/editor";
import type { QuickInsert } from "@/type/editor";

export const fetchAllQuickInsert = async (): Promise<QuickInsert[]> => {
export const fetchAllQuickInsert = async (
quickInsertUrls: { url: string }[]
): Promise<QuickInsert[]> => {
const quickInsertList: QuickInsert[] = [];
// Get Default Path
try {
const response = await fetch("/plugins/vditor-mde/assets/static/test.json");
const quickInsertJson: QuickInsert = await response.json();
quickInsertList.push(quickInsertJson);
} catch (e) {
// ignore this
for (const qi of quickInsertUrls) {
try {
const response = await fetch(qi.url);
const quickInsertJson: QuickInsert = await response.json();
quickInsertList.push(quickInsertJson);
} catch (e) {
// ignore this
}
}
return quickInsertList;
};
8 changes: 6 additions & 2 deletions console/src/views/Vditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ onMounted(async () => {
let mode: "ir" | "wysiwyg" | "sv" | undefined = "ir";
let typeWriterMode = false;
let codeBlockPreview = true;
let enableQuickInsert = false;
let quickInsertUrls = [];
// 实验性功能: 获取当前语言
const lang = localStorage.getItem("locale") || "zh-CN";
Expand All @@ -96,11 +98,13 @@ onMounted(async () => {
mode = editorConfig.basic.defaultRenderMode;
typeWriterMode = editorConfig.basic.typeWriterMode;
codeBlockPreview = editorConfig.basic.codeBlockPreview;
enableQuickInsert = editorConfig.basic.enableQuickInsert;
quickInsertUrls = editorConfig.basic.quickInsertUrl;
} catch (e) {
// ignore this
}
const qil = await fetchAllQuickInsert();
const qil = await fetchAllQuickInsert(quickInsertUrls);
vditor.value = new Vditor(
vditorRef.value,
getOptions({
Expand Down Expand Up @@ -137,7 +141,7 @@ onMounted(async () => {
customInsertSchema.value = schema;
customInsertOpen.value = true;
},
enableQuickInsert: true,
enableQuickInsert: enableQuickInsert,
quickInsertList: qil,
})
);
Expand Down
17 changes: 17 additions & 0 deletions src/main/resources/extensions/settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,23 @@ spec:
label: 编辑器代码块渲染
help: 关闭后代码块(包括图表)在所见即所得和即时渲染模式下将不会被渲染
value: true
- $formkit: checkbox
id: enableQuickInsert
name: enableQuickInsert
label: 启用快速插入功能
help: 开启此选项后,将会加入插件或主题提供的快速插入按钮
value: false
- $formkit: repeater
if: "$enableQuickInsert"
name: quickInsertUrl
label: 快速插入链接
help: 在下面的选项框中填入主题或插件给出的配置地址,即可使用
value: [ ]
children:
- $formkit: text
name: url
label: URL
value: ""
- group: render
label: 渲染
formSchema:
Expand Down

0 comments on commit 89be498

Please sign in to comment.