Merge pull request 'Move vditor assets to local' (PR#14) from feat-local-asset into dev
Build Plugin JAR File / build (push) Failing after 35s Details
Build Plugin JAR File / github-release (push) Has been skipped Details

Reviewed-on: #14
This commit is contained in:
zhengyi 2023-12-19 01:03:40 +08:00
commit b81f9faaec
17 changed files with 1679 additions and 1514 deletions

View File

@ -38,6 +38,10 @@ jobs:
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/console/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Download Vditor assets
run: |
chmod a+x download_dist.sh
bash download_dist.sh
- name: Install Frontend Dependencies
run: |
./gradlew pnpmInstall

View File

@ -41,6 +41,10 @@ jobs:
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/console/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Download Vditor assets
run: |
chmod a+x download_dist.sh
bash download_dist.sh
- name: Install Frontend Dependencies
run: |
./gradlew pnpmInstall

View File

@ -96,6 +96,12 @@ git clone git@github.com:{your_github_id}/vditor-mde.git
cd path/to/plugin-starter
```
```bash
# 下载依赖包
chmod a+x download_dist.sh
./download_dist.sh
```
```bash
# macOS / Linux
./gradlew pnpmInstall

1
console/.npmrc Normal file
View File

@ -0,0 +1 @@
@zhengyi:registry=https://git.mczhengyi.top/api/packages/zhengyi/npm/

View File

@ -14,7 +14,7 @@
"@halo-dev/components": "^1.7.0",
"@halo-dev/console-shared": "^2.8.0",
"canvas-confetti": "^1.6.0",
"vditor": "^3.9.6",
"@zhengyi/vditor": "^3.9.7",
"vue": "^3.3.4"
},
"devDependencies": {

File diff suppressed because it is too large Load Diff

View File

@ -1,8 +1,7 @@
import type {I18nLang} from "@/type/i18n";
import type { I18nLang } from "@/type/i18n";
const lang: I18nLang = {
"insert_image": "Insert Image"
}
insert_image: "Insert Image",
};
export default lang
export default lang;

View File

@ -15,4 +15,4 @@ export declare type Options = {
showAttachment: () => void;
language: string;
codeBlockPreview: boolean;
}
};

View File

@ -1 +1 @@
export declare type I18nLang = {[key: string]: string}
export declare type I18nLang = { [key: string]: string };

View File

@ -1,13 +1,13 @@
import zhCN from "@/i18n/zh-CN";
import type {I18nLang} from "@/type/i18n";
import type { I18nLang } from "@/type/i18n";
import zhTW from "@/i18n/zh-TW";
import enUS from "@/i18n/en-US";
const langDict: {[key: string]: I18nLang} = {
"zh_CN": zhCN,
"zh_TW": zhTW,
"en_US": enUS
}
const langDict: { [key: string]: I18nLang } = {
zh_CN: zhCN,
zh_TW: zhTW,
en_US: enUS,
};
/**
*
@ -15,5 +15,5 @@ const langDict: {[key: string]: I18nLang} = {
* @param lang
*/
export function t(key: string, lang: keyof II18n): string {
return langDict[lang][key]
return langDict[lang][key];
}

View File

@ -1,2 +1 @@
export const mdiImage: string = `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path fill="currentColor" d="m8.5 13.5l2.5 3l3.5-4.5l4.5 6H5m16 1V5a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2"/></svg>`
export const mdiImage = `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path fill="currentColor" d="m8.5 13.5l2.5 3l3.5-4.5l4.5 6H5m16 1V5a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2"/></svg>`;

View File

@ -1,12 +1,13 @@
import type {Options} from "@/type/editor";
import {mdiImage} from "@/utils/icon";
import {t} from "@/utils/i18n-utils";
import type { Options } from "@/type/editor";
import { mdiImage } from "@/utils/icon";
import { t } from "@/utils/i18n-utils";
export function getOptions(options: Options): IOptions {
return {
height: "calc(100vh - 56px)",
mode: options.defaultRenderMode,
typewriterMode: options.typeWriterMode,
cdn: "/plugins/vditor-mde/assets/static",
icon: "material",
lang: getLanguage(options.language),
toolbarConfig: {
@ -19,35 +20,43 @@ export function getOptions(options: Options): IOptions {
input: options.input,
toolbar: getToolbar(options.showAttachment, getLanguage(options.language)),
counter: {
enable: true
enable: true,
},
preview: {
markdown: {
toc: true,
codeBlockPreview: options.codeBlockPreview
}
codeBlockPreview: options.codeBlockPreview,
},
},
outline: {
enable: true,
position: "left"
position: "left",
},
fullscreen: {
index: 1000
}
}
index: 1000,
},
};
}
function getLanguage(lang="zh-CN"):keyof II18n {
function getLanguage(lang = "zh-CN"): keyof II18n {
switch (lang) {
case "zh-CN": return "zh_CN";
case "zh-TW": return "zh_TW";
case "en-US": return "en_US";
case "es": return "en_US";
default: return "zh_CN";
case "zh-CN":
return "zh_CN";
case "zh-TW":
return "zh_TW";
case "en-US":
return "en_US";
case "es":
return "en_US";
default:
return "zh_CN";
}
}
function getToolbar(showAttachmentCb: () => void, lang: keyof II18n): (string | IMenuItem)[] | undefined {
function getToolbar(
showAttachmentCb: () => void,
lang: keyof II18n
): (string | IMenuItem)[] | undefined {
return [
"emoji",
"headings",
@ -75,7 +84,7 @@ function getToolbar(showAttachmentCb: () => void, lang: keyof II18n): (string |
tip: t("insert_image", lang),
tipPosition: "n",
hotkey: "⇧⌘P",
click: showAttachmentCb
click: showAttachmentCb,
},
"table",
"|",
@ -86,12 +95,7 @@ function getToolbar(showAttachmentCb: () => void, lang: keyof II18n): (string |
"edit-mode",
{
name: "more",
toolbar: [
"both",
"export",
"outline",
"info",
"help"
],
},]
toolbar: ["both", "export", "outline", "info", "help"],
},
];
}

View File

@ -1,10 +1,10 @@
<script setup lang="ts">
import Vditor from "vditor";
import {onMounted, ref} from "vue";
import "vditor/dist/index.css"
import type {EditorConfig} from "@/type/editor";
import {getOptions} from "@/utils/vditor-utils";
import type {AttachmentLike} from "@halo-dev/console-shared";
import Vditor from "@zhengyi/vditor";
import { onMounted, ref } from "vue";
import "@zhengyi/vditor/dist/index.css";
import type { EditorConfig } from "@/type/editor";
import { getOptions } from "@/utils/vditor-utils";
import type { AttachmentLike } from "@halo-dev/console-shared";
const props = withDefaults(
defineProps<{
@ -17,9 +17,9 @@ const props = withDefaults(
}
);
const vditor = ref()
const vditorRef = ref()
const attachmentSelectorModalShow = ref(false)
const vditor = ref();
const vditorRef = ref();
const attachmentSelectorModalShow = ref(false);
const emit = defineEmits<{
(event: "update:raw", value: string): void;
@ -31,12 +31,12 @@ const debounceOnUpdate = () => {
emit("update:raw", vditor.value.getValue());
emit("update:content", vditor.value.getHTML() || "");
emit("update", vditor.value.getValue());
}
};
//
const attachmentSelect = (attachments: AttachmentLike[]) => {
// Reference https://github.com/guqing/willow-mde/blob/4b8e697132f8a8f4b08dd0f92cf10d070cb26793/console/src/components/toolbar/Toolbar.vue#L104
attachments.forEach(attachment => {
attachments.forEach((attachment) => {
if (typeof attachment === "string") {
vditor.value.insertValue(`![](${attachment})`);
} else if ("url" in attachment) {
@ -46,41 +46,43 @@ const attachmentSelect = (attachments: AttachmentLike[]) => {
const { permalink } = attachment.status || {};
vditor.value.insertValue(`![${displayName}](${permalink})`);
}
})
}
});
};
onMounted(async () => {
let mode: "ir" | "wysiwyg" | "sv" | undefined = "ir"
let typeWriterMode: boolean = false
let codeBlockPreview: boolean = true
let mode: "ir" | "wysiwyg" | "sv" | undefined = "ir";
let typeWriterMode = false;
let codeBlockPreview = true;
// :
const lang = localStorage.getItem("locale") || "zh-CN"
const lang = localStorage.getItem("locale") || "zh-CN";
try {
const response = await fetch(
"/apis/api.vditor.mczhengyi.top/editor-options"
);
const editorConfig: EditorConfig = await response.json();
mode = editorConfig.basic.defaultRenderMode
typeWriterMode = editorConfig.basic.typeWriterMode
codeBlockPreview = editorConfig.basic.codeBlockPreview
mode = editorConfig.basic.defaultRenderMode;
typeWriterMode = editorConfig.basic.typeWriterMode;
codeBlockPreview = editorConfig.basic.codeBlockPreview;
} catch (e) {
// ignore this
}
vditor.value = new Vditor(vditorRef.value, getOptions({
defaultRenderMode: mode,
typeWriterMode: typeWriterMode,
after: () => {
vditor.value.setValue(props.raw || "# Title Here")
},
input: debounceOnUpdate,
showAttachment: () => attachmentSelectorModalShow.value = true,
language: lang,
codeBlockPreview: codeBlockPreview
}))
})
vditor.value = new Vditor(
vditorRef.value,
getOptions({
defaultRenderMode: mode,
typeWriterMode: typeWriterMode,
after: () => {
vditor.value.setValue(props.raw || "# Title Here");
},
input: debounceOnUpdate,
showAttachment: () => (attachmentSelectorModalShow.value = true),
language: lang,
codeBlockPreview: codeBlockPreview,
})
);
});
</script>
<template>

10
download_dist.sh Executable file
View File

@ -0,0 +1,10 @@
#!/bin/zsh
cd src/main/resources/static
pwd
curl -o vditor.tgz \
https://git.mczhengyi.top/zhengyi/-/packages/npm/@zhengyi%2Fvditor/3.9.7/files/248
tar -xzvf vditor.tgz
mv package/dist .
rm -rf package
rm -f vditor.tgz

View File

@ -14,7 +14,7 @@ public class ScriptUtils {
public static String basicScript(RenderConfig renderConfig) {
return """
<script src="/plugins/vditor-mde/assets/static/method.min.js"></script>
<script src="/plugins/vditor-mde/assets/static/dist/method.min.js"></script>
<script src="/plugins/vditor-mde/assets/static/render.js" id="render-script"
data-dark="%s" data-mediaRender="%s"></script>
""".formatted(renderConfig.getDarkMode(), renderConfig.getMediaRender());

File diff suppressed because one or more lines are too long

View File

@ -1,4 +1,5 @@
const THEME_PREFIX="https://unpkg.com/vditor@3.9.6/dist/css/content-theme"
const THEME_PREFIX="/plugins/vditor-mde/assets/static/dist/css/content-theme"
const CDN = "/plugins/vditor-mde/assets/static"
window.addEventListener("load", () => {
// 暗色模式初始化
@ -12,6 +13,7 @@ window.addEventListener("load", () => {
render("language-abc", Vditor.abcRender)
render("language-graphviz", Vditor.graphvizRender)
render("language-flowchart", Vditor.flowchartRender)
render("language-halo", Vditor.haloRender)
// Render Media
let mediaRenderOption = document.getElementById("render-script").dataset.mediarender
if (mediaRenderOption==="true") {
@ -77,9 +79,9 @@ function render(selector, callback, dark=null) {
for (let i = 0; i < mindmap.length;i++) {
const el = coverThis(mindmap[i])
if (dark) {
callback(el, "https://unpkg.com/vditor@3.9.6", dark?"dark":"classic")
callback(el, CDN, dark?"dark":"classic")
} else {
callback(el)
callback(el, CDN)
}
}
}