From 47667393436013da4b9b4bf664a9cddd7e7d1d8d Mon Sep 17 00:00:00 2001 From: zhengyi Date: Wed, 27 Dec 2023 20:33:08 +0800 Subject: [PATCH 01/14] :arrow_up: Update halo requires version to 2.11.0 --- build.gradle | 2 +- console/package.json | 2 +- console/pnpm-lock.yaml | 2 +- gradle.properties | 2 +- src/main/resources/plugin.yaml | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/build.gradle b/build.gradle index 836edad..82fb07f 100644 --- a/build.gradle +++ b/build.gradle @@ -16,7 +16,7 @@ repositories { } dependencies { - implementation platform('run.halo.tools.platform:plugin:2.8.0-SNAPSHOT') + implementation platform('run.halo.tools.platform:plugin:2.11.0-SNAPSHOT') compileOnly 'run.halo.app:api' testImplementation 'run.halo.app:api' diff --git a/console/package.json b/console/package.json index f144bf7..1561783 100644 --- a/console/package.json +++ b/console/package.json @@ -12,7 +12,7 @@ }, "dependencies": { "@halo-dev/components": "^1.7.0", - "@halo-dev/console-shared": "^2.8.0", + "@halo-dev/console-shared": "^2.11.0", "canvas-confetti": "^1.6.0", "@zhengyi/vditor": "^3.9.8", "vue": "^3.3.4" diff --git a/console/pnpm-lock.yaml b/console/pnpm-lock.yaml index c546400..ef274d7 100644 --- a/console/pnpm-lock.yaml +++ b/console/pnpm-lock.yaml @@ -9,7 +9,7 @@ dependencies: specifier: ^1.7.0 version: 1.10.0(vue-router@4.2.5)(vue@3.3.12) '@halo-dev/console-shared': - specifier: ^2.8.0 + specifier: ^2.11.0 version: 2.11.0(vue-router@4.2.5)(vue@3.3.12) '@zhengyi/vditor': specifier: ^3.9.8 diff --git a/gradle.properties b/gradle.properties index 95ac233..f271e55 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1 +1 @@ -version=1.3.1-SNAPSHOT +version=1.4.0-SNAPSHOT diff --git a/src/main/resources/plugin.yaml b/src/main/resources/plugin.yaml index a77c6cb..671ae62 100644 --- a/src/main/resources/plugin.yaml +++ b/src/main/resources/plugin.yaml @@ -5,7 +5,7 @@ metadata: name: vditor-mde spec: enabled: true - requires: ">=2.8.0" + requires: ">=2.11.0" author: name: zhengyi59 website: https://github.com/justice2001/veditor-plugin From 78db09dc4b51827899f9c5beca56db6adb0c0c6c Mon Sep 17 00:00:00 2001 From: zhengyi Date: Wed, 27 Dec 2023 21:41:37 +0800 Subject: [PATCH 02/14] :sparkles: Support upload image via drag https://git.mczhengyi.top/zhengyi/halo-plugin-vditor/issues/26 https://github.com/justice2001/halo-plugin-vditor/issues/9 --- console/package.json | 2 +- console/pnpm-lock.yaml | 2 +- console/src/type/editor.d.ts | 1 + console/src/utils/vditor-utils.ts | 3 +++ console/src/views/Vditor.vue | 15 +++++++++++++++ 5 files changed, 21 insertions(+), 2 deletions(-) diff --git a/console/package.json b/console/package.json index 1561783..12e81bb 100644 --- a/console/package.json +++ b/console/package.json @@ -11,7 +11,7 @@ "lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore" }, "dependencies": { - "@halo-dev/components": "^1.7.0", + "@halo-dev/components": "^1.10.0", "@halo-dev/console-shared": "^2.11.0", "canvas-confetti": "^1.6.0", "@zhengyi/vditor": "^3.9.8", diff --git a/console/pnpm-lock.yaml b/console/pnpm-lock.yaml index ef274d7..6f2279a 100644 --- a/console/pnpm-lock.yaml +++ b/console/pnpm-lock.yaml @@ -6,7 +6,7 @@ settings: dependencies: '@halo-dev/components': - specifier: ^1.7.0 + specifier: ^1.10.0 version: 1.10.0(vue-router@4.2.5)(vue@3.3.12) '@halo-dev/console-shared': specifier: ^2.11.0 diff --git a/console/src/type/editor.d.ts b/console/src/type/editor.d.ts index 2c34734..1178b3f 100644 --- a/console/src/type/editor.d.ts +++ b/console/src/type/editor.d.ts @@ -15,4 +15,5 @@ export declare type Options = { showAttachment: () => void; language: string; codeBlockPreview: boolean; + uploadImage?: (files: File[]) => string | null | Promise; }; diff --git a/console/src/utils/vditor-utils.ts b/console/src/utils/vditor-utils.ts index d88da83..4d74e86 100644 --- a/console/src/utils/vditor-utils.ts +++ b/console/src/utils/vditor-utils.ts @@ -43,6 +43,9 @@ export function getOptions(options: Options): IOptions { fullscreen: { index: 1000, }, + upload: { + handler: options.uploadImage, + }, }; } diff --git a/console/src/views/Vditor.vue b/console/src/views/Vditor.vue index 0a3c85b..d70ae79 100644 --- a/console/src/views/Vditor.vue +++ b/console/src/views/Vditor.vue @@ -5,15 +5,18 @@ 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"; +import type { Attachment } from "@halo-dev/api-client"; const props = withDefaults( defineProps<{ raw?: string; content: string; + uploadImage?: (file: File) => Promise; }>(), { raw: "", content: "", + uploadImage: undefined, } ); @@ -87,6 +90,18 @@ onMounted(async () => { showAttachment: () => (attachmentSelectorModalShow.value = true), language: lang, codeBlockPreview: codeBlockPreview, + uploadImage: (files: File[]) => { + if (props.uploadImage) { + vditor.value.tip("正在上传图片...", 2000); + props.uploadImage(files[0]).then((res: Attachment) => { + console.log(res.status.permalink, res.spec.displayName); + vditor.value.insertValue( + `\n\n![${res.spec.displayName}](${res.status.permalink})\n\n` + ); + }); + } + return null; + }, }) ); }); From 6b23dbbf39f1c1bdab8b16e7d8b16d7aae4651b7 Mon Sep 17 00:00:00 2001 From: zhengyi Date: Thu, 28 Dec 2023 00:02:24 +0800 Subject: [PATCH 03/14] :arrow_up: Update vditor to 3.9.9-beta --- console/package.json | 2 +- console/pnpm-lock.yaml | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/console/package.json b/console/package.json index 12e81bb..b6da10e 100644 --- a/console/package.json +++ b/console/package.json @@ -14,7 +14,7 @@ "@halo-dev/components": "^1.10.0", "@halo-dev/console-shared": "^2.11.0", "canvas-confetti": "^1.6.0", - "@zhengyi/vditor": "^3.9.8", + "@zhengyi/vditor": "file:/Users/liuzhengyi/WebstormProjects/vditor", "vue": "^3.3.4" }, "devDependencies": { diff --git a/console/pnpm-lock.yaml b/console/pnpm-lock.yaml index 6f2279a..15e36d2 100644 --- a/console/pnpm-lock.yaml +++ b/console/pnpm-lock.yaml @@ -12,8 +12,8 @@ dependencies: specifier: ^2.11.0 version: 2.11.0(vue-router@4.2.5)(vue@3.3.12) '@zhengyi/vditor': - specifier: ^3.9.8 - version: 3.9.8 + specifier: file:/Users/liuzhengyi/WebstormProjects/vditor + version: file:../../WebstormProjects/vditor canvas-confetti: specifier: ^1.6.0 version: 1.9.2 @@ -1019,10 +1019,8 @@ packages: '@types/node': 16.18.68 dev: true - /@zhengyi/vditor@3.9.8: - resolution: {integrity: sha512-PjGtpoVOezS//hf567BEqg8p0cEmlptV9oxiCc8UsCg9sHaJ0EYvhvS0m6Wsg/L7ShRVZe6RrjKa9SDtRu0m6w==, tarball: https://git.mczhengyi.top/api/packages/zhengyi/npm/%40zhengyi%2Fvditor/-/3.9.8/vditor-3.9.8.tgz} - dependencies: - diff-match-patch: 1.0.5 + /@zhengyi/halo-render@1.1.0: + resolution: {integrity: sha512-r+aD7wvdXVRyFcw/yI/PbdIqSsC+Bnql2WSKZa8CK+ntpTvc2tybn6Wxsfw96C71QS+Q/MPe8ufwZBjtRd+hhg==, tarball: https://git.mczhengyi.top/api/packages/zhengyi/npm/%40zhengyi%2Fhalo-render/-/1.1.0/halo-render-1.1.0.tgz} dev: false /abab@2.0.6: @@ -3913,3 +3911,11 @@ packages: resolution: {integrity: sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==} engines: {node: '>=10'} dev: true + + file:../../WebstormProjects/vditor: + resolution: {directory: ../../WebstormProjects/vditor, type: directory} + name: '@zhengyi/vditor' + dependencies: + '@zhengyi/halo-render': 1.1.0 + diff-match-patch: 1.0.5 + dev: false From 663019f9ad1bcc550e702ff217e2ca42cfb69b99 Mon Sep 17 00:00:00 2001 From: zhengyi Date: Thu, 28 Dec 2023 00:04:27 +0800 Subject: [PATCH 04/14] :arrow_up: Update vditor to 3.9.9-build.0 --- console/package.json | 2 +- console/pnpm-lock.yaml | 19 +++++++++---------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/console/package.json b/console/package.json index b6da10e..dbc27ef 100644 --- a/console/package.json +++ b/console/package.json @@ -14,7 +14,7 @@ "@halo-dev/components": "^1.10.0", "@halo-dev/console-shared": "^2.11.0", "canvas-confetti": "^1.6.0", - "@zhengyi/vditor": "file:/Users/liuzhengyi/WebstormProjects/vditor", + "@zhengyi/vditor": "3.9.9-build.0", "vue": "^3.3.4" }, "devDependencies": { diff --git a/console/pnpm-lock.yaml b/console/pnpm-lock.yaml index 15e36d2..051a1eb 100644 --- a/console/pnpm-lock.yaml +++ b/console/pnpm-lock.yaml @@ -12,8 +12,8 @@ dependencies: specifier: ^2.11.0 version: 2.11.0(vue-router@4.2.5)(vue@3.3.12) '@zhengyi/vditor': - specifier: file:/Users/liuzhengyi/WebstormProjects/vditor - version: file:../../WebstormProjects/vditor + specifier: 3.9.9-build.0 + version: 3.9.9-build.0 canvas-confetti: specifier: ^1.6.0 version: 1.9.2 @@ -1023,6 +1023,13 @@ packages: resolution: {integrity: sha512-r+aD7wvdXVRyFcw/yI/PbdIqSsC+Bnql2WSKZa8CK+ntpTvc2tybn6Wxsfw96C71QS+Q/MPe8ufwZBjtRd+hhg==, tarball: https://git.mczhengyi.top/api/packages/zhengyi/npm/%40zhengyi%2Fhalo-render/-/1.1.0/halo-render-1.1.0.tgz} dev: false + /@zhengyi/vditor@3.9.9-build.0: + resolution: {integrity: sha512-lvI32FQNm8R+CKw9uSNOIeKXUhRQm71hOEd9bvqplKKTTQm4ToGAFMgkFxBeryCP8R2gzy0K/AH9rLfWMUnCZQ==, tarball: https://git.mczhengyi.top/api/packages/zhengyi/npm/%40zhengyi%2Fvditor/-/3.9.9-build.0/vditor-3.9.9-build.0.tgz} + dependencies: + '@zhengyi/halo-render': 1.1.0 + diff-match-patch: 1.0.5 + dev: false + /abab@2.0.6: resolution: {integrity: sha512-j2afSsaIENvHZN2B8GOpF566vZ5WVk5opAiMTvWgaQT8DkbOqsTfvNAvHoRGU2zzP8cPoqys+xHTRDWW8L+/BA==} deprecated: Use your platform's native atob() and btoa() methods instead @@ -3911,11 +3918,3 @@ packages: resolution: {integrity: sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==} engines: {node: '>=10'} dev: true - - file:../../WebstormProjects/vditor: - resolution: {directory: ../../WebstormProjects/vditor, type: directory} - name: '@zhengyi/vditor' - dependencies: - '@zhengyi/halo-render': 1.1.0 - diff-match-patch: 1.0.5 - dev: false From 8638d09e63efd1abc41c08386e57d8e4dcacdaa8 Mon Sep 17 00:00:00 2001 From: zhengyi Date: Fri, 29 Dec 2023 15:43:15 +0800 Subject: [PATCH 05/14] :sparkles: Add file type validate when upload image https://git.mczhengyi.top/zhengyi/halo-plugin-vditor/issues/26 --- console/src/views/Vditor.vue | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/console/src/views/Vditor.vue b/console/src/views/Vditor.vue index d70ae79..2da4bd1 100644 --- a/console/src/views/Vditor.vue +++ b/console/src/views/Vditor.vue @@ -91,10 +91,17 @@ onMounted(async () => { language: lang, codeBlockPreview: codeBlockPreview, uploadImage: (files: File[]) => { + const acceptType = ["png", "jpg", "jpeg", "bmp", "gif", "webp", "svg"]; + const extendName = files[0].name + .slice(files[0].name.lastIndexOf(".") + 1) + .toLowerCase(); + if (acceptType.indexOf(extendName) === -1) { + vditor.value.tip("不允许上传该类型图片!", 2000); + return null; + } if (props.uploadImage) { vditor.value.tip("正在上传图片...", 2000); props.uploadImage(files[0]).then((res: Attachment) => { - console.log(res.status.permalink, res.spec.displayName); vditor.value.insertValue( `\n\n![${res.spec.displayName}](${res.status.permalink})\n\n` ); From 5b6647e079380391ac4d86f32bd5e9edfbabca30 Mon Sep 17 00:00:00 2001 From: zhengyi Date: Fri, 29 Dec 2023 15:49:47 +0800 Subject: [PATCH 06/14] :heavy_plus_sign: Add @halo-dev/api-client Dependency --- console/package.json | 1 + console/pnpm-lock.yaml | 3 +++ 2 files changed, 4 insertions(+) diff --git a/console/package.json b/console/package.json index dbc27ef..6dbe8f5 100644 --- a/console/package.json +++ b/console/package.json @@ -11,6 +11,7 @@ "lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore" }, "dependencies": { + "@halo-dev/api-client": "^2.11.0", "@halo-dev/components": "^1.10.0", "@halo-dev/console-shared": "^2.11.0", "canvas-confetti": "^1.6.0", diff --git a/console/pnpm-lock.yaml b/console/pnpm-lock.yaml index 051a1eb..76f890e 100644 --- a/console/pnpm-lock.yaml +++ b/console/pnpm-lock.yaml @@ -5,6 +5,9 @@ settings: excludeLinksFromLockfile: false dependencies: + '@halo-dev/api-client': + specifier: ^2.11.0 + version: 2.11.0 '@halo-dev/components': specifier: ^1.10.0 version: 1.10.0(vue-router@4.2.5)(vue@3.3.12) From a4b7ad3e8ff36e5f8ed7266f95951fe4dc4b63b2 Mon Sep 17 00:00:00 2001 From: zhengyi Date: Fri, 29 Dec 2023 16:05:08 +0800 Subject: [PATCH 07/14] :sparkles: Add loading model when vditor do not ready Fix https://git.mczhengyi.top/zhengyi/halo-plugin-vditor/issues/28 --- console/src/views/Vditor.vue | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/console/src/views/Vditor.vue b/console/src/views/Vditor.vue index 2da4bd1..c516b0b 100644 --- a/console/src/views/Vditor.vue +++ b/console/src/views/Vditor.vue @@ -6,6 +6,7 @@ import type { EditorConfig } from "@/type/editor"; import { getOptions } from "@/utils/vditor-utils"; import type { AttachmentLike } from "@halo-dev/console-shared"; import type { Attachment } from "@halo-dev/api-client"; +import { VLoading } from "@halo-dev/components"; const props = withDefaults( defineProps<{ @@ -22,6 +23,7 @@ const props = withDefaults( const vditor = ref(); const vditorRef = ref(); +const vditorLoaded = ref(false); const attachmentSelectorModalShow = ref(false); const emit = defineEmits<{ @@ -57,6 +59,7 @@ onUnmounted(async () => { .querySelectorAll("script[id^='vditor']") .forEach((el) => el.remove()); document.querySelectorAll("link[id^='vditor']").forEach((el) => el.remove()); + vditorLoaded.value = false; }); onMounted(async () => { @@ -85,6 +88,7 @@ onMounted(async () => { typeWriterMode: typeWriterMode, after: () => { vditor.value.setValue(props.raw || "# Title Here"); + vditorLoaded.value = true; }, input: debounceOnUpdate, showAttachment: () => (attachmentSelectorModalShow.value = true), @@ -116,6 +120,7 @@ onMounted(async () => {