halo/console/console-src/modules/contents/pages/SinglePageEditor.vue

482 lines
13 KiB
Vue
Raw Normal View History

<script lang="ts" setup>
import {
VPageHeader,
IconPages,
IconSettings,
IconSendPlaneFill,
VSpace,
VButton,
IconSave,
Toast,
feat: add editor extension point (halo-dev/console#781) #### What type of PR is this? /kind feature #### What this PR does / why we need it: 添加编辑器的扩展点,用于扩展集成其他编辑器。 定义一个扩展点的方式: ```ts export default definePlugin({ extensionPoints: { "editor:create": () => { return [ { name: "stackedit", displayName: "StackEdit", component: markRaw(StackEdit), rawType: "markdown", }, ]; }, }, }); ``` 其中 `component` 字段即编辑器组件对象,需要包含 `raw`、`content` 的 prop。 #### Which issue(s) this PR fixes: Fixes https://github.com/halo-dev/halo/issues/2881 #### Screenshots: <img width="1664" alt="image" src="https://user-images.githubusercontent.com/21301288/208406097-60258cba-cff6-436f-bd50-6d8c27ea9a53.png"> <img width="1662" alt="image" src="https://user-images.githubusercontent.com/21301288/208406174-d4649365-3448-4581-a452-f9781502eac6.png"> <img width="1920" alt="image" src="https://user-images.githubusercontent.com/21301288/208407570-db10e956-cd6a-4e0d-801e-b794ad0261bc.png"> <img width="1920" alt="image" src="https://user-images.githubusercontent.com/21301288/208407607-fd595957-5278-40c2-a3b5-fb73c1de429c.png"> #### Special notes for your reviewer: 目前可用于测试的插件: 1. [plugin-stackedit-1.0.0-SNAPSHOT.jar.zip](https://github.com/halo-dev/console/files/10258488/plugin-stackedit-1.0.0-SNAPSHOT.jar.zip) 2. [plugin-bytemd-1.0.0-SNAPSHOT.jar.zip](https://github.com/halo-dev/console/files/10258490/plugin-bytemd-1.0.0-SNAPSHOT.jar.zip) 测试方式: 1. Console 需要 `pnpm build:packages`。 2. 在 Console 的插件管理上传以上插件。 3. 新建若干文章,使用不同的编辑器。 4. 检查是否能够正常发布和编辑。 5. 检查编辑的时候,是否正确使用了之前的编辑器。 6. 检查主题端是否渲染正常。 一些实现细节: 1. 为了支持更新文章时能够选择发布时的编辑器,会在 post 的 `metadata.annotations` 添加一条 `content.halo.run/preferred-editor` 用于标记使用的什么编辑器。如果编辑器不存在,会使用 content 的 `rawType` 来匹配。 2. 目前没有全局默认编辑器设置,只能在新建文章的时候选择。 #### Does this PR introduce a user-facing change? ```release-note Console 端支持扩展集成其他编辑器 ```
2022-12-22 04:14:29 +00:00
Dialog,
IconEye,
} from "@halo-dev/components";
import SinglePageSettingModal from "./components/SinglePageSettingModal.vue";
import type { SinglePage, SinglePageRequest } from "@halo-dev/api-client";
feat: add editor extension point (halo-dev/console#781) #### What type of PR is this? /kind feature #### What this PR does / why we need it: 添加编辑器的扩展点,用于扩展集成其他编辑器。 定义一个扩展点的方式: ```ts export default definePlugin({ extensionPoints: { "editor:create": () => { return [ { name: "stackedit", displayName: "StackEdit", component: markRaw(StackEdit), rawType: "markdown", }, ]; }, }, }); ``` 其中 `component` 字段即编辑器组件对象,需要包含 `raw`、`content` 的 prop。 #### Which issue(s) this PR fixes: Fixes https://github.com/halo-dev/halo/issues/2881 #### Screenshots: <img width="1664" alt="image" src="https://user-images.githubusercontent.com/21301288/208406097-60258cba-cff6-436f-bd50-6d8c27ea9a53.png"> <img width="1662" alt="image" src="https://user-images.githubusercontent.com/21301288/208406174-d4649365-3448-4581-a452-f9781502eac6.png"> <img width="1920" alt="image" src="https://user-images.githubusercontent.com/21301288/208407570-db10e956-cd6a-4e0d-801e-b794ad0261bc.png"> <img width="1920" alt="image" src="https://user-images.githubusercontent.com/21301288/208407607-fd595957-5278-40c2-a3b5-fb73c1de429c.png"> #### Special notes for your reviewer: 目前可用于测试的插件: 1. [plugin-stackedit-1.0.0-SNAPSHOT.jar.zip](https://github.com/halo-dev/console/files/10258488/plugin-stackedit-1.0.0-SNAPSHOT.jar.zip) 2. [plugin-bytemd-1.0.0-SNAPSHOT.jar.zip](https://github.com/halo-dev/console/files/10258490/plugin-bytemd-1.0.0-SNAPSHOT.jar.zip) 测试方式: 1. Console 需要 `pnpm build:packages`。 2. 在 Console 的插件管理上传以上插件。 3. 新建若干文章,使用不同的编辑器。 4. 检查是否能够正常发布和编辑。 5. 检查编辑的时候,是否正确使用了之前的编辑器。 6. 检查主题端是否渲染正常。 一些实现细节: 1. 为了支持更新文章时能够选择发布时的编辑器,会在 post 的 `metadata.annotations` 添加一条 `content.halo.run/preferred-editor` 用于标记使用的什么编辑器。如果编辑器不存在,会使用 content 的 `rawType` 来匹配。 2. 目前没有全局默认编辑器设置,只能在新建文章的时候选择。 #### Does this PR introduce a user-facing change? ```release-note Console 端支持扩展集成其他编辑器 ```
2022-12-22 04:14:29 +00:00
import {
computed,
nextTick,
onMounted,
provide,
ref,
toRef,
type ComputedRef,
} from "vue";
import { apiClient } from "@/utils/api-client";
import { useRouteQuery } from "@vueuse/router";
import cloneDeep from "lodash.clonedeep";
import { useRouter } from "vue-router";
import { randomUUID } from "@/utils/id";
import { useContentCache } from "@console/composables/use-content-cache";
import { useEditorExtensionPoints } from "@/composables/use-editor-extension-points";
import type { EditorProvider } from "@halo-dev/console-shared";
import { useLocalStorage } from "@vueuse/core";
import EditorProviderSelector from "@/components/dropdown-selector/EditorProviderSelector.vue";
import { useI18n } from "vue-i18n";
import UrlPreviewModal from "@/components/preview/UrlPreviewModal.vue";
import { contentAnnotations } from "@/constants/annotations";
import { usePageUpdateMutate } from "./composables/use-page-update-mutate";
import { useAutoSaveContent } from "@console/composables/use-auto-save-content";
import { useContentSnapshot } from "@console/composables/use-content-snapshot";
import { useSaveKeybinding } from "@console/composables/use-save-keybinding";
import { useSessionKeepAlive } from "@/composables/use-session-keep-alive";
import { usePermission } from "@/utils/permission";
const router = useRouter();
const { t } = useI18n();
const { mutateAsync: singlePageUpdateMutate } = usePageUpdateMutate();
const { currentUserHasPermission } = usePermission();
// Editor providers
feat: add editor extension point (halo-dev/console#781) #### What type of PR is this? /kind feature #### What this PR does / why we need it: 添加编辑器的扩展点,用于扩展集成其他编辑器。 定义一个扩展点的方式: ```ts export default definePlugin({ extensionPoints: { "editor:create": () => { return [ { name: "stackedit", displayName: "StackEdit", component: markRaw(StackEdit), rawType: "markdown", }, ]; }, }, }); ``` 其中 `component` 字段即编辑器组件对象,需要包含 `raw`、`content` 的 prop。 #### Which issue(s) this PR fixes: Fixes https://github.com/halo-dev/halo/issues/2881 #### Screenshots: <img width="1664" alt="image" src="https://user-images.githubusercontent.com/21301288/208406097-60258cba-cff6-436f-bd50-6d8c27ea9a53.png"> <img width="1662" alt="image" src="https://user-images.githubusercontent.com/21301288/208406174-d4649365-3448-4581-a452-f9781502eac6.png"> <img width="1920" alt="image" src="https://user-images.githubusercontent.com/21301288/208407570-db10e956-cd6a-4e0d-801e-b794ad0261bc.png"> <img width="1920" alt="image" src="https://user-images.githubusercontent.com/21301288/208407607-fd595957-5278-40c2-a3b5-fb73c1de429c.png"> #### Special notes for your reviewer: 目前可用于测试的插件: 1. [plugin-stackedit-1.0.0-SNAPSHOT.jar.zip](https://github.com/halo-dev/console/files/10258488/plugin-stackedit-1.0.0-SNAPSHOT.jar.zip) 2. [plugin-bytemd-1.0.0-SNAPSHOT.jar.zip](https://github.com/halo-dev/console/files/10258490/plugin-bytemd-1.0.0-SNAPSHOT.jar.zip) 测试方式: 1. Console 需要 `pnpm build:packages`。 2. 在 Console 的插件管理上传以上插件。 3. 新建若干文章,使用不同的编辑器。 4. 检查是否能够正常发布和编辑。 5. 检查编辑的时候,是否正确使用了之前的编辑器。 6. 检查主题端是否渲染正常。 一些实现细节: 1. 为了支持更新文章时能够选择发布时的编辑器,会在 post 的 `metadata.annotations` 添加一条 `content.halo.run/preferred-editor` 用于标记使用的什么编辑器。如果编辑器不存在,会使用 content 的 `rawType` 来匹配。 2. 目前没有全局默认编辑器设置,只能在新建文章的时候选择。 #### Does this PR introduce a user-facing change? ```release-note Console 端支持扩展集成其他编辑器 ```
2022-12-22 04:14:29 +00:00
const { editorProviders } = useEditorExtensionPoints();
const currentEditorProvider = ref<EditorProvider>();
const storedEditorProviderName = useLocalStorage("editor-provider-name", "");
const handleChangeEditorProvider = async (provider: EditorProvider) => {
currentEditorProvider.value = provider;
storedEditorProviderName.value = provider.name;
formState.value.page.metadata.annotations = {
...formState.value.page.metadata.annotations,
[contentAnnotations.PREFERRED_EDITOR]: provider.name,
};
formState.value.content.rawType = provider.rawType;
if (isUpdateMode.value) {
const { data } = await singlePageUpdateMutate(formState.value.page);
formState.value.page = data;
}
};
feat: add editor extension point (halo-dev/console#781) #### What type of PR is this? /kind feature #### What this PR does / why we need it: 添加编辑器的扩展点,用于扩展集成其他编辑器。 定义一个扩展点的方式: ```ts export default definePlugin({ extensionPoints: { "editor:create": () => { return [ { name: "stackedit", displayName: "StackEdit", component: markRaw(StackEdit), rawType: "markdown", }, ]; }, }, }); ``` 其中 `component` 字段即编辑器组件对象,需要包含 `raw`、`content` 的 prop。 #### Which issue(s) this PR fixes: Fixes https://github.com/halo-dev/halo/issues/2881 #### Screenshots: <img width="1664" alt="image" src="https://user-images.githubusercontent.com/21301288/208406097-60258cba-cff6-436f-bd50-6d8c27ea9a53.png"> <img width="1662" alt="image" src="https://user-images.githubusercontent.com/21301288/208406174-d4649365-3448-4581-a452-f9781502eac6.png"> <img width="1920" alt="image" src="https://user-images.githubusercontent.com/21301288/208407570-db10e956-cd6a-4e0d-801e-b794ad0261bc.png"> <img width="1920" alt="image" src="https://user-images.githubusercontent.com/21301288/208407607-fd595957-5278-40c2-a3b5-fb73c1de429c.png"> #### Special notes for your reviewer: 目前可用于测试的插件: 1. [plugin-stackedit-1.0.0-SNAPSHOT.jar.zip](https://github.com/halo-dev/console/files/10258488/plugin-stackedit-1.0.0-SNAPSHOT.jar.zip) 2. [plugin-bytemd-1.0.0-SNAPSHOT.jar.zip](https://github.com/halo-dev/console/files/10258490/plugin-bytemd-1.0.0-SNAPSHOT.jar.zip) 测试方式: 1. Console 需要 `pnpm build:packages`。 2. 在 Console 的插件管理上传以上插件。 3. 新建若干文章,使用不同的编辑器。 4. 检查是否能够正常发布和编辑。 5. 检查编辑的时候,是否正确使用了之前的编辑器。 6. 检查主题端是否渲染正常。 一些实现细节: 1. 为了支持更新文章时能够选择发布时的编辑器,会在 post 的 `metadata.annotations` 添加一条 `content.halo.run/preferred-editor` 用于标记使用的什么编辑器。如果编辑器不存在,会使用 content 的 `rawType` 来匹配。 2. 目前没有全局默认编辑器设置,只能在新建文章的时候选择。 #### Does this PR introduce a user-facing change? ```release-note Console 端支持扩展集成其他编辑器 ```
2022-12-22 04:14:29 +00:00
// SinglePage form
const initialFormState: SinglePageRequest = {
page: {
spec: {
title: "",
slug: "",
template: "",
cover: "",
deleted: false,
publish: false,
publishTime: undefined,
pinned: false,
allowComment: true,
visible: "PUBLIC",
priority: 0,
excerpt: {
autoGenerate: true,
raw: "",
},
htmlMetas: [],
},
apiVersion: "content.halo.run/v1alpha1",
kind: "SinglePage",
metadata: {
name: randomUUID(),
feat: add editor extension point (halo-dev/console#781) #### What type of PR is this? /kind feature #### What this PR does / why we need it: 添加编辑器的扩展点,用于扩展集成其他编辑器。 定义一个扩展点的方式: ```ts export default definePlugin({ extensionPoints: { "editor:create": () => { return [ { name: "stackedit", displayName: "StackEdit", component: markRaw(StackEdit), rawType: "markdown", }, ]; }, }, }); ``` 其中 `component` 字段即编辑器组件对象,需要包含 `raw`、`content` 的 prop。 #### Which issue(s) this PR fixes: Fixes https://github.com/halo-dev/halo/issues/2881 #### Screenshots: <img width="1664" alt="image" src="https://user-images.githubusercontent.com/21301288/208406097-60258cba-cff6-436f-bd50-6d8c27ea9a53.png"> <img width="1662" alt="image" src="https://user-images.githubusercontent.com/21301288/208406174-d4649365-3448-4581-a452-f9781502eac6.png"> <img width="1920" alt="image" src="https://user-images.githubusercontent.com/21301288/208407570-db10e956-cd6a-4e0d-801e-b794ad0261bc.png"> <img width="1920" alt="image" src="https://user-images.githubusercontent.com/21301288/208407607-fd595957-5278-40c2-a3b5-fb73c1de429c.png"> #### Special notes for your reviewer: 目前可用于测试的插件: 1. [plugin-stackedit-1.0.0-SNAPSHOT.jar.zip](https://github.com/halo-dev/console/files/10258488/plugin-stackedit-1.0.0-SNAPSHOT.jar.zip) 2. [plugin-bytemd-1.0.0-SNAPSHOT.jar.zip](https://github.com/halo-dev/console/files/10258490/plugin-bytemd-1.0.0-SNAPSHOT.jar.zip) 测试方式: 1. Console 需要 `pnpm build:packages`。 2. 在 Console 的插件管理上传以上插件。 3. 新建若干文章,使用不同的编辑器。 4. 检查是否能够正常发布和编辑。 5. 检查编辑的时候,是否正确使用了之前的编辑器。 6. 检查主题端是否渲染正常。 一些实现细节: 1. 为了支持更新文章时能够选择发布时的编辑器,会在 post 的 `metadata.annotations` 添加一条 `content.halo.run/preferred-editor` 用于标记使用的什么编辑器。如果编辑器不存在,会使用 content 的 `rawType` 来匹配。 2. 目前没有全局默认编辑器设置,只能在新建文章的时候选择。 #### Does this PR introduce a user-facing change? ```release-note Console 端支持扩展集成其他编辑器 ```
2022-12-22 04:14:29 +00:00
annotations: {},
},
},
content: {
raw: "",
content: "",
rawType: "HTML",
},
};
const formState = ref<SinglePageRequest>(cloneDeep(initialFormState));
const saving = ref(false);
const publishing = ref(false);
const settingModal = ref(false);
const isUpdateMode = computed(() => {
return !!formState.value.page.metadata.creationTimestamp;
});
feat: add editor extension point (halo-dev/console#781) #### What type of PR is this? /kind feature #### What this PR does / why we need it: 添加编辑器的扩展点,用于扩展集成其他编辑器。 定义一个扩展点的方式: ```ts export default definePlugin({ extensionPoints: { "editor:create": () => { return [ { name: "stackedit", displayName: "StackEdit", component: markRaw(StackEdit), rawType: "markdown", }, ]; }, }, }); ``` 其中 `component` 字段即编辑器组件对象,需要包含 `raw`、`content` 的 prop。 #### Which issue(s) this PR fixes: Fixes https://github.com/halo-dev/halo/issues/2881 #### Screenshots: <img width="1664" alt="image" src="https://user-images.githubusercontent.com/21301288/208406097-60258cba-cff6-436f-bd50-6d8c27ea9a53.png"> <img width="1662" alt="image" src="https://user-images.githubusercontent.com/21301288/208406174-d4649365-3448-4581-a452-f9781502eac6.png"> <img width="1920" alt="image" src="https://user-images.githubusercontent.com/21301288/208407570-db10e956-cd6a-4e0d-801e-b794ad0261bc.png"> <img width="1920" alt="image" src="https://user-images.githubusercontent.com/21301288/208407607-fd595957-5278-40c2-a3b5-fb73c1de429c.png"> #### Special notes for your reviewer: 目前可用于测试的插件: 1. [plugin-stackedit-1.0.0-SNAPSHOT.jar.zip](https://github.com/halo-dev/console/files/10258488/plugin-stackedit-1.0.0-SNAPSHOT.jar.zip) 2. [plugin-bytemd-1.0.0-SNAPSHOT.jar.zip](https://github.com/halo-dev/console/files/10258490/plugin-bytemd-1.0.0-SNAPSHOT.jar.zip) 测试方式: 1. Console 需要 `pnpm build:packages`。 2. 在 Console 的插件管理上传以上插件。 3. 新建若干文章,使用不同的编辑器。 4. 检查是否能够正常发布和编辑。 5. 检查编辑的时候,是否正确使用了之前的编辑器。 6. 检查主题端是否渲染正常。 一些实现细节: 1. 为了支持更新文章时能够选择发布时的编辑器,会在 post 的 `metadata.annotations` 添加一条 `content.halo.run/preferred-editor` 用于标记使用的什么编辑器。如果编辑器不存在,会使用 content 的 `rawType` 来匹配。 2. 目前没有全局默认编辑器设置,只能在新建文章的时候选择。 #### Does this PR introduce a user-facing change? ```release-note Console 端支持扩展集成其他编辑器 ```
2022-12-22 04:14:29 +00:00
// provide some data to editor
provide<ComputedRef<string | undefined>>(
"owner",
computed(() => formState.value.page.spec.owner)
);
provide<ComputedRef<string | undefined>>(
"publishTime",
computed(() => formState.value.page.spec.publishTime)
);
provide<ComputedRef<string | undefined>>(
"permalink",
computed(() => formState.value.page.status?.permalink)
);
const routeQueryName = useRouteQuery<string>("name");
const handleSave = async (options?: { mute?: boolean }) => {
try {
if (!options?.mute) {
saving.value = true;
}
//Set default title and slug
if (!formState.value.page.spec.title) {
formState.value.page.spec.title = t("core.page_editor.untitled");
}
if (!formState.value.page.spec.slug) {
formState.value.page.spec.slug = new Date().getTime().toString();
}
if (isUpdateMode.value) {
const { data } = await apiClient.singlePage.updateSinglePageContent({
name: formState.value.page.metadata.name,
content: formState.value.content,
});
formState.value.page = data;
} else {
pref: optimize the caching functionality of content editing (#4458) #### What type of PR is this? /kind improvement #### What this PR does / why we need it: 本 PR 优化了文章、内容编辑时的本地缓存功能,之前内容对于本地缓存的依赖性非常强,因此导致了部分问题,如 #3820 ,本 PR 计划之后本地缓存将仅用于特殊情况下的内容恢复,因此尝试做了如下修改: 1. 当前正在编辑的文章,会在正常模式(切换路由、刷新页面、失去当前窗口焦点、停止编写一定时间均属于正常模式)下进行自动保存后删除本地缓存。 2. 若本地具有缓存,则会在进入编辑页面时,比对一次 content 的 version,若缓存 version 小于线上 version,则抛弃缓存,若一致,则使用缓存。 但经过测试,本 PR 无法解决如下问题: 1. 同时编辑一篇文章时,内容会被覆盖的问题。 2. 对比版本后会抛弃缓存,而实际上应当将本地缓存加入历史版本中。 #### How to test it? 1. 新建一篇文章,编写任意内容,返回文章页查看是否已经具有新的文章,且内容已被保存。 2. 修改一篇文章的内容,然后返回文章页,查看是否不是从缓存中加载。 3. 断网模式下修改一篇文章的内容,然后返回文章页,联网后,再次打开此文章,查看是否显示从缓存中加载。 4. 断网模式下修改一篇文章的内容,然后返回文章页。在另一个浏览器或页面修改此文章并保存后,回到断网页面联网后,查看是否更新为最新内容。 #### Which issue(s) this PR fixes: Fixes #3820 Fixes #4223 #### Does this PR introduce a user-facing change? ```release-note 减少内容编辑对本地缓存依赖,支持内容自动保存至服务端。 ```
2023-08-25 16:18:16 +00:00
// Clear new page content cache
handleClearCache();
const { data } = await apiClient.singlePage.draftSinglePage({
singlePageRequest: formState.value,
});
formState.value.page = data;
routeQueryName.value = data.metadata.name;
}
if (!options?.mute) {
Toast.success(t("core.common.toast.save_success"));
}
pref: optimize the caching functionality of content editing (#4458) #### What type of PR is this? /kind improvement #### What this PR does / why we need it: 本 PR 优化了文章、内容编辑时的本地缓存功能,之前内容对于本地缓存的依赖性非常强,因此导致了部分问题,如 #3820 ,本 PR 计划之后本地缓存将仅用于特殊情况下的内容恢复,因此尝试做了如下修改: 1. 当前正在编辑的文章,会在正常模式(切换路由、刷新页面、失去当前窗口焦点、停止编写一定时间均属于正常模式)下进行自动保存后删除本地缓存。 2. 若本地具有缓存,则会在进入编辑页面时,比对一次 content 的 version,若缓存 version 小于线上 version,则抛弃缓存,若一致,则使用缓存。 但经过测试,本 PR 无法解决如下问题: 1. 同时编辑一篇文章时,内容会被覆盖的问题。 2. 对比版本后会抛弃缓存,而实际上应当将本地缓存加入历史版本中。 #### How to test it? 1. 新建一篇文章,编写任意内容,返回文章页查看是否已经具有新的文章,且内容已被保存。 2. 修改一篇文章的内容,然后返回文章页,查看是否不是从缓存中加载。 3. 断网模式下修改一篇文章的内容,然后返回文章页,联网后,再次打开此文章,查看是否显示从缓存中加载。 4. 断网模式下修改一篇文章的内容,然后返回文章页。在另一个浏览器或页面修改此文章并保存后,回到断网页面联网后,查看是否更新为最新内容。 #### Which issue(s) this PR fixes: Fixes #3820 Fixes #4223 #### Does this PR introduce a user-facing change? ```release-note 减少内容编辑对本地缓存依赖,支持内容自动保存至服务端。 ```
2023-08-25 16:18:16 +00:00
handleClearCache(formState.value.page.metadata.name as string);
await handleFetchContent();
pref: optimize the caching functionality of content editing (#4458) #### What type of PR is this? /kind improvement #### What this PR does / why we need it: 本 PR 优化了文章、内容编辑时的本地缓存功能,之前内容对于本地缓存的依赖性非常强,因此导致了部分问题,如 #3820 ,本 PR 计划之后本地缓存将仅用于特殊情况下的内容恢复,因此尝试做了如下修改: 1. 当前正在编辑的文章,会在正常模式(切换路由、刷新页面、失去当前窗口焦点、停止编写一定时间均属于正常模式)下进行自动保存后删除本地缓存。 2. 若本地具有缓存,则会在进入编辑页面时,比对一次 content 的 version,若缓存 version 小于线上 version,则抛弃缓存,若一致,则使用缓存。 但经过测试,本 PR 无法解决如下问题: 1. 同时编辑一篇文章时,内容会被覆盖的问题。 2. 对比版本后会抛弃缓存,而实际上应当将本地缓存加入历史版本中。 #### How to test it? 1. 新建一篇文章,编写任意内容,返回文章页查看是否已经具有新的文章,且内容已被保存。 2. 修改一篇文章的内容,然后返回文章页,查看是否不是从缓存中加载。 3. 断网模式下修改一篇文章的内容,然后返回文章页,联网后,再次打开此文章,查看是否显示从缓存中加载。 4. 断网模式下修改一篇文章的内容,然后返回文章页。在另一个浏览器或页面修改此文章并保存后,回到断网页面联网后,查看是否更新为最新内容。 #### Which issue(s) this PR fixes: Fixes #3820 Fixes #4223 #### Does this PR introduce a user-facing change? ```release-note 减少内容编辑对本地缓存依赖,支持内容自动保存至服务端。 ```
2023-08-25 16:18:16 +00:00
await handleFetchSnapshot();
} catch (error) {
console.error("Failed to save single page", error);
Toast.error(t("core.common.toast.save_failed_and_retry"));
} finally {
saving.value = false;
}
};
const returnToView = useRouteQuery<string>("returnToView");
const handlePublish = async () => {
try {
publishing.value = true;
if (isUpdateMode.value) {
const { name: singlePageName } = formState.value.page.metadata;
const { permalink } = formState.value.page.status || {};
await apiClient.singlePage.updateSinglePageContent({
name: singlePageName,
content: formState.value.content,
});
await apiClient.singlePage.publishSinglePage({
name: singlePageName,
});
if (returnToView.value && permalink) {
window.location.href = permalink;
} else {
router.back();
}
} else {
formState.value.page.spec.publish = true;
await apiClient.singlePage.draftSinglePage({
singlePageRequest: formState.value,
});
// Clear new page content cache
handleClearCache();
router.push({ name: "SinglePages" });
}
Toast.success(t("core.common.toast.publish_success"));
handleClearCache(routeQueryName.value as string);
} catch (error) {
console.error("Failed to publish single page", error);
Toast.error(t("core.common.toast.publish_failed_and_retry"));
} finally {
publishing.value = false;
}
};
const handlePublishClick = () => {
if (isUpdateMode.value) {
handlePublish();
} else {
settingModal.value = true;
}
};
const handleFetchContent = async () => {
if (!formState.value.page.spec.headSnapshot) {
return;
}
const { data } = await apiClient.singlePage.fetchSinglePageHeadContent({
name: formState.value.page.metadata.name,
});
formState.value.content = Object.assign(formState.value.content, data);
feat: add editor extension point (halo-dev/console#781) #### What type of PR is this? /kind feature #### What this PR does / why we need it: 添加编辑器的扩展点,用于扩展集成其他编辑器。 定义一个扩展点的方式: ```ts export default definePlugin({ extensionPoints: { "editor:create": () => { return [ { name: "stackedit", displayName: "StackEdit", component: markRaw(StackEdit), rawType: "markdown", }, ]; }, }, }); ``` 其中 `component` 字段即编辑器组件对象,需要包含 `raw`、`content` 的 prop。 #### Which issue(s) this PR fixes: Fixes https://github.com/halo-dev/halo/issues/2881 #### Screenshots: <img width="1664" alt="image" src="https://user-images.githubusercontent.com/21301288/208406097-60258cba-cff6-436f-bd50-6d8c27ea9a53.png"> <img width="1662" alt="image" src="https://user-images.githubusercontent.com/21301288/208406174-d4649365-3448-4581-a452-f9781502eac6.png"> <img width="1920" alt="image" src="https://user-images.githubusercontent.com/21301288/208407570-db10e956-cd6a-4e0d-801e-b794ad0261bc.png"> <img width="1920" alt="image" src="https://user-images.githubusercontent.com/21301288/208407607-fd595957-5278-40c2-a3b5-fb73c1de429c.png"> #### Special notes for your reviewer: 目前可用于测试的插件: 1. [plugin-stackedit-1.0.0-SNAPSHOT.jar.zip](https://github.com/halo-dev/console/files/10258488/plugin-stackedit-1.0.0-SNAPSHOT.jar.zip) 2. [plugin-bytemd-1.0.0-SNAPSHOT.jar.zip](https://github.com/halo-dev/console/files/10258490/plugin-bytemd-1.0.0-SNAPSHOT.jar.zip) 测试方式: 1. Console 需要 `pnpm build:packages`。 2. 在 Console 的插件管理上传以上插件。 3. 新建若干文章,使用不同的编辑器。 4. 检查是否能够正常发布和编辑。 5. 检查编辑的时候,是否正确使用了之前的编辑器。 6. 检查主题端是否渲染正常。 一些实现细节: 1. 为了支持更新文章时能够选择发布时的编辑器,会在 post 的 `metadata.annotations` 添加一条 `content.halo.run/preferred-editor` 用于标记使用的什么编辑器。如果编辑器不存在,会使用 content 的 `rawType` 来匹配。 2. 目前没有全局默认编辑器设置,只能在新建文章的时候选择。 #### Does this PR introduce a user-facing change? ```release-note Console 端支持扩展集成其他编辑器 ```
2022-12-22 04:14:29 +00:00
// get editor provider
if (!currentEditorProvider.value) {
const preferredEditor = editorProviders.value.find(
(provider) =>
provider.name ===
formState.value.page.metadata.annotations?.[
contentAnnotations.PREFERRED_EDITOR
feat: add editor extension point (halo-dev/console#781) #### What type of PR is this? /kind feature #### What this PR does / why we need it: 添加编辑器的扩展点,用于扩展集成其他编辑器。 定义一个扩展点的方式: ```ts export default definePlugin({ extensionPoints: { "editor:create": () => { return [ { name: "stackedit", displayName: "StackEdit", component: markRaw(StackEdit), rawType: "markdown", }, ]; }, }, }); ``` 其中 `component` 字段即编辑器组件对象,需要包含 `raw`、`content` 的 prop。 #### Which issue(s) this PR fixes: Fixes https://github.com/halo-dev/halo/issues/2881 #### Screenshots: <img width="1664" alt="image" src="https://user-images.githubusercontent.com/21301288/208406097-60258cba-cff6-436f-bd50-6d8c27ea9a53.png"> <img width="1662" alt="image" src="https://user-images.githubusercontent.com/21301288/208406174-d4649365-3448-4581-a452-f9781502eac6.png"> <img width="1920" alt="image" src="https://user-images.githubusercontent.com/21301288/208407570-db10e956-cd6a-4e0d-801e-b794ad0261bc.png"> <img width="1920" alt="image" src="https://user-images.githubusercontent.com/21301288/208407607-fd595957-5278-40c2-a3b5-fb73c1de429c.png"> #### Special notes for your reviewer: 目前可用于测试的插件: 1. [plugin-stackedit-1.0.0-SNAPSHOT.jar.zip](https://github.com/halo-dev/console/files/10258488/plugin-stackedit-1.0.0-SNAPSHOT.jar.zip) 2. [plugin-bytemd-1.0.0-SNAPSHOT.jar.zip](https://github.com/halo-dev/console/files/10258490/plugin-bytemd-1.0.0-SNAPSHOT.jar.zip) 测试方式: 1. Console 需要 `pnpm build:packages`。 2. 在 Console 的插件管理上传以上插件。 3. 新建若干文章,使用不同的编辑器。 4. 检查是否能够正常发布和编辑。 5. 检查编辑的时候,是否正确使用了之前的编辑器。 6. 检查主题端是否渲染正常。 一些实现细节: 1. 为了支持更新文章时能够选择发布时的编辑器,会在 post 的 `metadata.annotations` 添加一条 `content.halo.run/preferred-editor` 用于标记使用的什么编辑器。如果编辑器不存在,会使用 content 的 `rawType` 来匹配。 2. 目前没有全局默认编辑器设置,只能在新建文章的时候选择。 #### Does this PR introduce a user-facing change? ```release-note Console 端支持扩展集成其他编辑器 ```
2022-12-22 04:14:29 +00:00
]
);
const provider =
preferredEditor ||
editorProviders.value.find(
(provider) => provider.rawType === data.rawType
);
if (provider) {
currentEditorProvider.value = provider;
formState.value.page.metadata.annotations = {
...formState.value.page.metadata.annotations,
[contentAnnotations.PREFERRED_EDITOR]: provider.name,
feat: add editor extension point (halo-dev/console#781) #### What type of PR is this? /kind feature #### What this PR does / why we need it: 添加编辑器的扩展点,用于扩展集成其他编辑器。 定义一个扩展点的方式: ```ts export default definePlugin({ extensionPoints: { "editor:create": () => { return [ { name: "stackedit", displayName: "StackEdit", component: markRaw(StackEdit), rawType: "markdown", }, ]; }, }, }); ``` 其中 `component` 字段即编辑器组件对象,需要包含 `raw`、`content` 的 prop。 #### Which issue(s) this PR fixes: Fixes https://github.com/halo-dev/halo/issues/2881 #### Screenshots: <img width="1664" alt="image" src="https://user-images.githubusercontent.com/21301288/208406097-60258cba-cff6-436f-bd50-6d8c27ea9a53.png"> <img width="1662" alt="image" src="https://user-images.githubusercontent.com/21301288/208406174-d4649365-3448-4581-a452-f9781502eac6.png"> <img width="1920" alt="image" src="https://user-images.githubusercontent.com/21301288/208407570-db10e956-cd6a-4e0d-801e-b794ad0261bc.png"> <img width="1920" alt="image" src="https://user-images.githubusercontent.com/21301288/208407607-fd595957-5278-40c2-a3b5-fb73c1de429c.png"> #### Special notes for your reviewer: 目前可用于测试的插件: 1. [plugin-stackedit-1.0.0-SNAPSHOT.jar.zip](https://github.com/halo-dev/console/files/10258488/plugin-stackedit-1.0.0-SNAPSHOT.jar.zip) 2. [plugin-bytemd-1.0.0-SNAPSHOT.jar.zip](https://github.com/halo-dev/console/files/10258490/plugin-bytemd-1.0.0-SNAPSHOT.jar.zip) 测试方式: 1. Console 需要 `pnpm build:packages`。 2. 在 Console 的插件管理上传以上插件。 3. 新建若干文章,使用不同的编辑器。 4. 检查是否能够正常发布和编辑。 5. 检查编辑的时候,是否正确使用了之前的编辑器。 6. 检查主题端是否渲染正常。 一些实现细节: 1. 为了支持更新文章时能够选择发布时的编辑器,会在 post 的 `metadata.annotations` 添加一条 `content.halo.run/preferred-editor` 用于标记使用的什么编辑器。如果编辑器不存在,会使用 content 的 `rawType` 来匹配。 2. 目前没有全局默认编辑器设置,只能在新建文章的时候选择。 #### Does this PR introduce a user-facing change? ```release-note Console 端支持扩展集成其他编辑器 ```
2022-12-22 04:14:29 +00:00
};
const { data } = await singlePageUpdateMutate(formState.value.page);
formState.value.page = data;
feat: add editor extension point (halo-dev/console#781) #### What type of PR is this? /kind feature #### What this PR does / why we need it: 添加编辑器的扩展点,用于扩展集成其他编辑器。 定义一个扩展点的方式: ```ts export default definePlugin({ extensionPoints: { "editor:create": () => { return [ { name: "stackedit", displayName: "StackEdit", component: markRaw(StackEdit), rawType: "markdown", }, ]; }, }, }); ``` 其中 `component` 字段即编辑器组件对象,需要包含 `raw`、`content` 的 prop。 #### Which issue(s) this PR fixes: Fixes https://github.com/halo-dev/halo/issues/2881 #### Screenshots: <img width="1664" alt="image" src="https://user-images.githubusercontent.com/21301288/208406097-60258cba-cff6-436f-bd50-6d8c27ea9a53.png"> <img width="1662" alt="image" src="https://user-images.githubusercontent.com/21301288/208406174-d4649365-3448-4581-a452-f9781502eac6.png"> <img width="1920" alt="image" src="https://user-images.githubusercontent.com/21301288/208407570-db10e956-cd6a-4e0d-801e-b794ad0261bc.png"> <img width="1920" alt="image" src="https://user-images.githubusercontent.com/21301288/208407607-fd595957-5278-40c2-a3b5-fb73c1de429c.png"> #### Special notes for your reviewer: 目前可用于测试的插件: 1. [plugin-stackedit-1.0.0-SNAPSHOT.jar.zip](https://github.com/halo-dev/console/files/10258488/plugin-stackedit-1.0.0-SNAPSHOT.jar.zip) 2. [plugin-bytemd-1.0.0-SNAPSHOT.jar.zip](https://github.com/halo-dev/console/files/10258490/plugin-bytemd-1.0.0-SNAPSHOT.jar.zip) 测试方式: 1. Console 需要 `pnpm build:packages`。 2. 在 Console 的插件管理上传以上插件。 3. 新建若干文章,使用不同的编辑器。 4. 检查是否能够正常发布和编辑。 5. 检查编辑的时候,是否正确使用了之前的编辑器。 6. 检查主题端是否渲染正常。 一些实现细节: 1. 为了支持更新文章时能够选择发布时的编辑器,会在 post 的 `metadata.annotations` 添加一条 `content.halo.run/preferred-editor` 用于标记使用的什么编辑器。如果编辑器不存在,会使用 content 的 `rawType` 来匹配。 2. 目前没有全局默认编辑器设置,只能在新建文章的时候选择。 #### Does this PR introduce a user-facing change? ```release-note Console 端支持扩展集成其他编辑器 ```
2022-12-22 04:14:29 +00:00
} else {
Dialog.warning({
title: t("core.common.dialog.titles.warning"),
description: t("core.common.dialog.descriptions.editor_not_found", {
raw_type: data.rawType,
}),
confirmText: t("core.common.buttons.confirm"),
showCancel: false,
feat: add editor extension point (halo-dev/console#781) #### What type of PR is this? /kind feature #### What this PR does / why we need it: 添加编辑器的扩展点,用于扩展集成其他编辑器。 定义一个扩展点的方式: ```ts export default definePlugin({ extensionPoints: { "editor:create": () => { return [ { name: "stackedit", displayName: "StackEdit", component: markRaw(StackEdit), rawType: "markdown", }, ]; }, }, }); ``` 其中 `component` 字段即编辑器组件对象,需要包含 `raw`、`content` 的 prop。 #### Which issue(s) this PR fixes: Fixes https://github.com/halo-dev/halo/issues/2881 #### Screenshots: <img width="1664" alt="image" src="https://user-images.githubusercontent.com/21301288/208406097-60258cba-cff6-436f-bd50-6d8c27ea9a53.png"> <img width="1662" alt="image" src="https://user-images.githubusercontent.com/21301288/208406174-d4649365-3448-4581-a452-f9781502eac6.png"> <img width="1920" alt="image" src="https://user-images.githubusercontent.com/21301288/208407570-db10e956-cd6a-4e0d-801e-b794ad0261bc.png"> <img width="1920" alt="image" src="https://user-images.githubusercontent.com/21301288/208407607-fd595957-5278-40c2-a3b5-fb73c1de429c.png"> #### Special notes for your reviewer: 目前可用于测试的插件: 1. [plugin-stackedit-1.0.0-SNAPSHOT.jar.zip](https://github.com/halo-dev/console/files/10258488/plugin-stackedit-1.0.0-SNAPSHOT.jar.zip) 2. [plugin-bytemd-1.0.0-SNAPSHOT.jar.zip](https://github.com/halo-dev/console/files/10258490/plugin-bytemd-1.0.0-SNAPSHOT.jar.zip) 测试方式: 1. Console 需要 `pnpm build:packages`。 2. 在 Console 的插件管理上传以上插件。 3. 新建若干文章,使用不同的编辑器。 4. 检查是否能够正常发布和编辑。 5. 检查编辑的时候,是否正确使用了之前的编辑器。 6. 检查主题端是否渲染正常。 一些实现细节: 1. 为了支持更新文章时能够选择发布时的编辑器,会在 post 的 `metadata.annotations` 添加一条 `content.halo.run/preferred-editor` 用于标记使用的什么编辑器。如果编辑器不存在,会使用 content 的 `rawType` 来匹配。 2. 目前没有全局默认编辑器设置,只能在新建文章的时候选择。 #### Does this PR introduce a user-facing change? ```release-note Console 端支持扩展集成其他编辑器 ```
2022-12-22 04:14:29 +00:00
onConfirm: () => {
router.back();
},
});
}
await nextTick();
}
};
// SinglePage settings
const handleOpenSettingModal = async () => {
const { data: latestSinglePage } =
await apiClient.extension.singlePage.getcontentHaloRunV1alpha1SinglePage({
name: formState.value.page.metadata.name,
});
formState.value.page = latestSinglePage;
settingModal.value = true;
};
const onSettingSaved = (page: SinglePage) => {
// Set route query parameter
if (!isUpdateMode.value) {
routeQueryName.value = page.metadata.name;
}
formState.value.page = page;
settingModal.value = false;
if (!isUpdateMode.value) {
handleSave();
}
};
const onSettingPublished = (singlePage: SinglePage) => {
formState.value.page = singlePage;
settingModal.value = false;
handlePublish();
};
onMounted(async () => {
if (routeQueryName.value) {
const { data: singlePage } =
await apiClient.extension.singlePage.getcontentHaloRunV1alpha1SinglePage({
name: routeQueryName.value,
});
formState.value.page = singlePage;
// fetch single page content
await handleFetchContent();
feat: add editor extension point (halo-dev/console#781) #### What type of PR is this? /kind feature #### What this PR does / why we need it: 添加编辑器的扩展点,用于扩展集成其他编辑器。 定义一个扩展点的方式: ```ts export default definePlugin({ extensionPoints: { "editor:create": () => { return [ { name: "stackedit", displayName: "StackEdit", component: markRaw(StackEdit), rawType: "markdown", }, ]; }, }, }); ``` 其中 `component` 字段即编辑器组件对象,需要包含 `raw`、`content` 的 prop。 #### Which issue(s) this PR fixes: Fixes https://github.com/halo-dev/halo/issues/2881 #### Screenshots: <img width="1664" alt="image" src="https://user-images.githubusercontent.com/21301288/208406097-60258cba-cff6-436f-bd50-6d8c27ea9a53.png"> <img width="1662" alt="image" src="https://user-images.githubusercontent.com/21301288/208406174-d4649365-3448-4581-a452-f9781502eac6.png"> <img width="1920" alt="image" src="https://user-images.githubusercontent.com/21301288/208407570-db10e956-cd6a-4e0d-801e-b794ad0261bc.png"> <img width="1920" alt="image" src="https://user-images.githubusercontent.com/21301288/208407607-fd595957-5278-40c2-a3b5-fb73c1de429c.png"> #### Special notes for your reviewer: 目前可用于测试的插件: 1. [plugin-stackedit-1.0.0-SNAPSHOT.jar.zip](https://github.com/halo-dev/console/files/10258488/plugin-stackedit-1.0.0-SNAPSHOT.jar.zip) 2. [plugin-bytemd-1.0.0-SNAPSHOT.jar.zip](https://github.com/halo-dev/console/files/10258490/plugin-bytemd-1.0.0-SNAPSHOT.jar.zip) 测试方式: 1. Console 需要 `pnpm build:packages`。 2. 在 Console 的插件管理上传以上插件。 3. 新建若干文章,使用不同的编辑器。 4. 检查是否能够正常发布和编辑。 5. 检查编辑的时候,是否正确使用了之前的编辑器。 6. 检查主题端是否渲染正常。 一些实现细节: 1. 为了支持更新文章时能够选择发布时的编辑器,会在 post 的 `metadata.annotations` 添加一条 `content.halo.run/preferred-editor` 用于标记使用的什么编辑器。如果编辑器不存在,会使用 content 的 `rawType` 来匹配。 2. 目前没有全局默认编辑器设置,只能在新建文章的时候选择。 #### Does this PR introduce a user-facing change? ```release-note Console 端支持扩展集成其他编辑器 ```
2022-12-22 04:14:29 +00:00
} else {
// Set default editor
const provider =
editorProviders.value.find(
(provider) => provider.name === storedEditorProviderName.value
feat: add editor extension point (halo-dev/console#781) #### What type of PR is this? /kind feature #### What this PR does / why we need it: 添加编辑器的扩展点,用于扩展集成其他编辑器。 定义一个扩展点的方式: ```ts export default definePlugin({ extensionPoints: { "editor:create": () => { return [ { name: "stackedit", displayName: "StackEdit", component: markRaw(StackEdit), rawType: "markdown", }, ]; }, }, }); ``` 其中 `component` 字段即编辑器组件对象,需要包含 `raw`、`content` 的 prop。 #### Which issue(s) this PR fixes: Fixes https://github.com/halo-dev/halo/issues/2881 #### Screenshots: <img width="1664" alt="image" src="https://user-images.githubusercontent.com/21301288/208406097-60258cba-cff6-436f-bd50-6d8c27ea9a53.png"> <img width="1662" alt="image" src="https://user-images.githubusercontent.com/21301288/208406174-d4649365-3448-4581-a452-f9781502eac6.png"> <img width="1920" alt="image" src="https://user-images.githubusercontent.com/21301288/208407570-db10e956-cd6a-4e0d-801e-b794ad0261bc.png"> <img width="1920" alt="image" src="https://user-images.githubusercontent.com/21301288/208407607-fd595957-5278-40c2-a3b5-fb73c1de429c.png"> #### Special notes for your reviewer: 目前可用于测试的插件: 1. [plugin-stackedit-1.0.0-SNAPSHOT.jar.zip](https://github.com/halo-dev/console/files/10258488/plugin-stackedit-1.0.0-SNAPSHOT.jar.zip) 2. [plugin-bytemd-1.0.0-SNAPSHOT.jar.zip](https://github.com/halo-dev/console/files/10258490/plugin-bytemd-1.0.0-SNAPSHOT.jar.zip) 测试方式: 1. Console 需要 `pnpm build:packages`。 2. 在 Console 的插件管理上传以上插件。 3. 新建若干文章,使用不同的编辑器。 4. 检查是否能够正常发布和编辑。 5. 检查编辑的时候,是否正确使用了之前的编辑器。 6. 检查主题端是否渲染正常。 一些实现细节: 1. 为了支持更新文章时能够选择发布时的编辑器,会在 post 的 `metadata.annotations` 添加一条 `content.halo.run/preferred-editor` 用于标记使用的什么编辑器。如果编辑器不存在,会使用 content 的 `rawType` 来匹配。 2. 目前没有全局默认编辑器设置,只能在新建文章的时候选择。 #### Does this PR introduce a user-facing change? ```release-note Console 端支持扩展集成其他编辑器 ```
2022-12-22 04:14:29 +00:00
) || editorProviders.value[0];
if (provider) {
currentEditorProvider.value = provider;
formState.value.content.rawType = provider.rawType;
}
formState.value.page.metadata.annotations = {
[contentAnnotations.PREFERRED_EDITOR]: provider.name,
feat: add editor extension point (halo-dev/console#781) #### What type of PR is this? /kind feature #### What this PR does / why we need it: 添加编辑器的扩展点,用于扩展集成其他编辑器。 定义一个扩展点的方式: ```ts export default definePlugin({ extensionPoints: { "editor:create": () => { return [ { name: "stackedit", displayName: "StackEdit", component: markRaw(StackEdit), rawType: "markdown", }, ]; }, }, }); ``` 其中 `component` 字段即编辑器组件对象,需要包含 `raw`、`content` 的 prop。 #### Which issue(s) this PR fixes: Fixes https://github.com/halo-dev/halo/issues/2881 #### Screenshots: <img width="1664" alt="image" src="https://user-images.githubusercontent.com/21301288/208406097-60258cba-cff6-436f-bd50-6d8c27ea9a53.png"> <img width="1662" alt="image" src="https://user-images.githubusercontent.com/21301288/208406174-d4649365-3448-4581-a452-f9781502eac6.png"> <img width="1920" alt="image" src="https://user-images.githubusercontent.com/21301288/208407570-db10e956-cd6a-4e0d-801e-b794ad0261bc.png"> <img width="1920" alt="image" src="https://user-images.githubusercontent.com/21301288/208407607-fd595957-5278-40c2-a3b5-fb73c1de429c.png"> #### Special notes for your reviewer: 目前可用于测试的插件: 1. [plugin-stackedit-1.0.0-SNAPSHOT.jar.zip](https://github.com/halo-dev/console/files/10258488/plugin-stackedit-1.0.0-SNAPSHOT.jar.zip) 2. [plugin-bytemd-1.0.0-SNAPSHOT.jar.zip](https://github.com/halo-dev/console/files/10258490/plugin-bytemd-1.0.0-SNAPSHOT.jar.zip) 测试方式: 1. Console 需要 `pnpm build:packages`。 2. 在 Console 的插件管理上传以上插件。 3. 新建若干文章,使用不同的编辑器。 4. 检查是否能够正常发布和编辑。 5. 检查编辑的时候,是否正确使用了之前的编辑器。 6. 检查主题端是否渲染正常。 一些实现细节: 1. 为了支持更新文章时能够选择发布时的编辑器,会在 post 的 `metadata.annotations` 添加一条 `content.halo.run/preferred-editor` 用于标记使用的什么编辑器。如果编辑器不存在,会使用 content 的 `rawType` 来匹配。 2. 目前没有全局默认编辑器设置,只能在新建文章的时候选择。 #### Does this PR introduce a user-facing change? ```release-note Console 端支持扩展集成其他编辑器 ```
2022-12-22 04:14:29 +00:00
};
}
feat: add editor extension point (halo-dev/console#781) #### What type of PR is this? /kind feature #### What this PR does / why we need it: 添加编辑器的扩展点,用于扩展集成其他编辑器。 定义一个扩展点的方式: ```ts export default definePlugin({ extensionPoints: { "editor:create": () => { return [ { name: "stackedit", displayName: "StackEdit", component: markRaw(StackEdit), rawType: "markdown", }, ]; }, }, }); ``` 其中 `component` 字段即编辑器组件对象,需要包含 `raw`、`content` 的 prop。 #### Which issue(s) this PR fixes: Fixes https://github.com/halo-dev/halo/issues/2881 #### Screenshots: <img width="1664" alt="image" src="https://user-images.githubusercontent.com/21301288/208406097-60258cba-cff6-436f-bd50-6d8c27ea9a53.png"> <img width="1662" alt="image" src="https://user-images.githubusercontent.com/21301288/208406174-d4649365-3448-4581-a452-f9781502eac6.png"> <img width="1920" alt="image" src="https://user-images.githubusercontent.com/21301288/208407570-db10e956-cd6a-4e0d-801e-b794ad0261bc.png"> <img width="1920" alt="image" src="https://user-images.githubusercontent.com/21301288/208407607-fd595957-5278-40c2-a3b5-fb73c1de429c.png"> #### Special notes for your reviewer: 目前可用于测试的插件: 1. [plugin-stackedit-1.0.0-SNAPSHOT.jar.zip](https://github.com/halo-dev/console/files/10258488/plugin-stackedit-1.0.0-SNAPSHOT.jar.zip) 2. [plugin-bytemd-1.0.0-SNAPSHOT.jar.zip](https://github.com/halo-dev/console/files/10258490/plugin-bytemd-1.0.0-SNAPSHOT.jar.zip) 测试方式: 1. Console 需要 `pnpm build:packages`。 2. 在 Console 的插件管理上传以上插件。 3. 新建若干文章,使用不同的编辑器。 4. 检查是否能够正常发布和编辑。 5. 检查编辑的时候,是否正确使用了之前的编辑器。 6. 检查主题端是否渲染正常。 一些实现细节: 1. 为了支持更新文章时能够选择发布时的编辑器,会在 post 的 `metadata.annotations` 添加一条 `content.halo.run/preferred-editor` 用于标记使用的什么编辑器。如果编辑器不存在,会使用 content 的 `rawType` 来匹配。 2. 目前没有全局默认编辑器设置,只能在新建文章的时候选择。 #### Does this PR introduce a user-facing change? ```release-note Console 端支持扩展集成其他编辑器 ```
2022-12-22 04:14:29 +00:00
handleResetCache();
});
pref: optimize the caching functionality of content editing (#4458) #### What type of PR is this? /kind improvement #### What this PR does / why we need it: 本 PR 优化了文章、内容编辑时的本地缓存功能,之前内容对于本地缓存的依赖性非常强,因此导致了部分问题,如 #3820 ,本 PR 计划之后本地缓存将仅用于特殊情况下的内容恢复,因此尝试做了如下修改: 1. 当前正在编辑的文章,会在正常模式(切换路由、刷新页面、失去当前窗口焦点、停止编写一定时间均属于正常模式)下进行自动保存后删除本地缓存。 2. 若本地具有缓存,则会在进入编辑页面时,比对一次 content 的 version,若缓存 version 小于线上 version,则抛弃缓存,若一致,则使用缓存。 但经过测试,本 PR 无法解决如下问题: 1. 同时编辑一篇文章时,内容会被覆盖的问题。 2. 对比版本后会抛弃缓存,而实际上应当将本地缓存加入历史版本中。 #### How to test it? 1. 新建一篇文章,编写任意内容,返回文章页查看是否已经具有新的文章,且内容已被保存。 2. 修改一篇文章的内容,然后返回文章页,查看是否不是从缓存中加载。 3. 断网模式下修改一篇文章的内容,然后返回文章页,联网后,再次打开此文章,查看是否显示从缓存中加载。 4. 断网模式下修改一篇文章的内容,然后返回文章页。在另一个浏览器或页面修改此文章并保存后,回到断网页面联网后,查看是否更新为最新内容。 #### Which issue(s) this PR fixes: Fixes #3820 Fixes #4223 #### Does this PR introduce a user-facing change? ```release-note 减少内容编辑对本地缓存依赖,支持内容自动保存至服务端。 ```
2023-08-25 16:18:16 +00:00
const headSnapshot = computed(() => {
return formState.value.page.spec.headSnapshot;
});
const { version, handleFetchSnapshot } = useContentSnapshot(headSnapshot);
// SinglePage content cache
pref: optimize the caching functionality of content editing (#4458) #### What type of PR is this? /kind improvement #### What this PR does / why we need it: 本 PR 优化了文章、内容编辑时的本地缓存功能,之前内容对于本地缓存的依赖性非常强,因此导致了部分问题,如 #3820 ,本 PR 计划之后本地缓存将仅用于特殊情况下的内容恢复,因此尝试做了如下修改: 1. 当前正在编辑的文章,会在正常模式(切换路由、刷新页面、失去当前窗口焦点、停止编写一定时间均属于正常模式)下进行自动保存后删除本地缓存。 2. 若本地具有缓存,则会在进入编辑页面时,比对一次 content 的 version,若缓存 version 小于线上 version,则抛弃缓存,若一致,则使用缓存。 但经过测试,本 PR 无法解决如下问题: 1. 同时编辑一篇文章时,内容会被覆盖的问题。 2. 对比版本后会抛弃缓存,而实际上应当将本地缓存加入历史版本中。 #### How to test it? 1. 新建一篇文章,编写任意内容,返回文章页查看是否已经具有新的文章,且内容已被保存。 2. 修改一篇文章的内容,然后返回文章页,查看是否不是从缓存中加载。 3. 断网模式下修改一篇文章的内容,然后返回文章页,联网后,再次打开此文章,查看是否显示从缓存中加载。 4. 断网模式下修改一篇文章的内容,然后返回文章页。在另一个浏览器或页面修改此文章并保存后,回到断网页面联网后,查看是否更新为最新内容。 #### Which issue(s) this PR fixes: Fixes #3820 Fixes #4223 #### Does this PR introduce a user-facing change? ```release-note 减少内容编辑对本地缓存依赖,支持内容自动保存至服务端。 ```
2023-08-25 16:18:16 +00:00
const {
currentCache,
handleSetContentCache,
handleResetCache,
handleClearCache,
} = useContentCache(
"singlePage-content-cache",
routeQueryName,
toRef(formState.value.content, "raw"),
version
);
useAutoSaveContent(currentCache, toRef(formState.value.content, "raw"), () => {
// Do not save when the setting modal is open
if (settingModal.value) {
return;
}
pref: optimize the caching functionality of content editing (#4458) #### What type of PR is this? /kind improvement #### What this PR does / why we need it: 本 PR 优化了文章、内容编辑时的本地缓存功能,之前内容对于本地缓存的依赖性非常强,因此导致了部分问题,如 #3820 ,本 PR 计划之后本地缓存将仅用于特殊情况下的内容恢复,因此尝试做了如下修改: 1. 当前正在编辑的文章,会在正常模式(切换路由、刷新页面、失去当前窗口焦点、停止编写一定时间均属于正常模式)下进行自动保存后删除本地缓存。 2. 若本地具有缓存,则会在进入编辑页面时,比对一次 content 的 version,若缓存 version 小于线上 version,则抛弃缓存,若一致,则使用缓存。 但经过测试,本 PR 无法解决如下问题: 1. 同时编辑一篇文章时,内容会被覆盖的问题。 2. 对比版本后会抛弃缓存,而实际上应当将本地缓存加入历史版本中。 #### How to test it? 1. 新建一篇文章,编写任意内容,返回文章页查看是否已经具有新的文章,且内容已被保存。 2. 修改一篇文章的内容,然后返回文章页,查看是否不是从缓存中加载。 3. 断网模式下修改一篇文章的内容,然后返回文章页,联网后,再次打开此文章,查看是否显示从缓存中加载。 4. 断网模式下修改一篇文章的内容,然后返回文章页。在另一个浏览器或页面修改此文章并保存后,回到断网页面联网后,查看是否更新为最新内容。 #### Which issue(s) this PR fixes: Fixes #3820 Fixes #4223 #### Does this PR introduce a user-facing change? ```release-note 减少内容编辑对本地缓存依赖,支持内容自动保存至服务端。 ```
2023-08-25 16:18:16 +00:00
handleSave({ mute: true });
});
// SinglePage preview
const previewModal = ref(false);
const previewPending = ref(false);
const handlePreview = async () => {
previewPending.value = true;
await handleSave({ mute: true });
previewModal.value = true;
previewPending.value = false;
};
useSaveKeybinding(handleSave);
// Keep session alive
useSessionKeepAlive();
// Upload image
async function handleUploadImage(file: File) {
if (!currentUserHasPermission(["uc:attachments:manage"])) {
return;
}
if (!isUpdateMode.value) {
await handleSave();
}
const { data } = await apiClient.uc.attachment.createAttachmentForPost({
file,
singlePageName: formState.value.page.metadata.name,
waitForPermalink: true,
});
return data;
}
</script>
<template>
<SinglePageSettingModal
v-model:visible="settingModal"
:single-page="formState.page"
:publish-support="!isUpdateMode"
:only-emit="!isUpdateMode"
@saved="onSettingSaved"
@published="onSettingPublished"
/>
<UrlPreviewModal
v-if="isUpdateMode"
v-model:visible="previewModal"
:title="formState.page.spec.title"
:url="`/preview/singlepages/${formState.page.metadata.name}`"
/>
<VPageHeader :title="$t('core.page.title')">
<template #icon>
<IconPages class="mr-2 self-center" />
</template>
<template #actions>
<VSpace>
<EditorProviderSelector
v-if="editorProviders.length > 1"
:provider="currentEditorProvider"
:allow-forced-select="!isUpdateMode"
@select="handleChangeEditorProvider"
/>
<VButton
size="sm"
type="default"
:loading="previewPending"
@click="handlePreview"
>
<template #icon>
<IconEye class="h-full w-full" />
</template>
{{ $t("core.common.buttons.preview") }}
</VButton>
<VButton :loading="saving" size="sm" type="default" @click="handleSave">
<template #icon>
<IconSave class="h-full w-full" />
</template>
{{ $t("core.common.buttons.save") }}
</VButton>
<VButton
v-if="isUpdateMode"
size="sm"
type="default"
@click="handleOpenSettingModal"
>
<template #icon>
<IconSettings class="h-full w-full" />
</template>
{{ $t("core.common.buttons.setting") }}
</VButton>
<VButton
type="secondary"
:loading="publishing"
@click="handlePublishClick"
>
<template #icon>
<IconSendPlaneFill class="h-full w-full" />
</template>
{{ $t("core.common.buttons.publish") }}
</VButton>
</VSpace>
</template>
</VPageHeader>
<div class="editor border-t" style="height: calc(100vh - 3.5rem)">
feat: add editor extension point (halo-dev/console#781) #### What type of PR is this? /kind feature #### What this PR does / why we need it: 添加编辑器的扩展点,用于扩展集成其他编辑器。 定义一个扩展点的方式: ```ts export default definePlugin({ extensionPoints: { "editor:create": () => { return [ { name: "stackedit", displayName: "StackEdit", component: markRaw(StackEdit), rawType: "markdown", }, ]; }, }, }); ``` 其中 `component` 字段即编辑器组件对象,需要包含 `raw`、`content` 的 prop。 #### Which issue(s) this PR fixes: Fixes https://github.com/halo-dev/halo/issues/2881 #### Screenshots: <img width="1664" alt="image" src="https://user-images.githubusercontent.com/21301288/208406097-60258cba-cff6-436f-bd50-6d8c27ea9a53.png"> <img width="1662" alt="image" src="https://user-images.githubusercontent.com/21301288/208406174-d4649365-3448-4581-a452-f9781502eac6.png"> <img width="1920" alt="image" src="https://user-images.githubusercontent.com/21301288/208407570-db10e956-cd6a-4e0d-801e-b794ad0261bc.png"> <img width="1920" alt="image" src="https://user-images.githubusercontent.com/21301288/208407607-fd595957-5278-40c2-a3b5-fb73c1de429c.png"> #### Special notes for your reviewer: 目前可用于测试的插件: 1. [plugin-stackedit-1.0.0-SNAPSHOT.jar.zip](https://github.com/halo-dev/console/files/10258488/plugin-stackedit-1.0.0-SNAPSHOT.jar.zip) 2. [plugin-bytemd-1.0.0-SNAPSHOT.jar.zip](https://github.com/halo-dev/console/files/10258490/plugin-bytemd-1.0.0-SNAPSHOT.jar.zip) 测试方式: 1. Console 需要 `pnpm build:packages`。 2. 在 Console 的插件管理上传以上插件。 3. 新建若干文章,使用不同的编辑器。 4. 检查是否能够正常发布和编辑。 5. 检查编辑的时候,是否正确使用了之前的编辑器。 6. 检查主题端是否渲染正常。 一些实现细节: 1. 为了支持更新文章时能够选择发布时的编辑器,会在 post 的 `metadata.annotations` 添加一条 `content.halo.run/preferred-editor` 用于标记使用的什么编辑器。如果编辑器不存在,会使用 content 的 `rawType` 来匹配。 2. 目前没有全局默认编辑器设置,只能在新建文章的时候选择。 #### Does this PR introduce a user-facing change? ```release-note Console 端支持扩展集成其他编辑器 ```
2022-12-22 04:14:29 +00:00
<component
:is="currentEditorProvider.component"
v-if="currentEditorProvider"
v-model:raw="formState.content.raw"
v-model:content="formState.content.content"
:upload-image="handleUploadImage"
feat: add editor extension point (halo-dev/console#781) #### What type of PR is this? /kind feature #### What this PR does / why we need it: 添加编辑器的扩展点,用于扩展集成其他编辑器。 定义一个扩展点的方式: ```ts export default definePlugin({ extensionPoints: { "editor:create": () => { return [ { name: "stackedit", displayName: "StackEdit", component: markRaw(StackEdit), rawType: "markdown", }, ]; }, }, }); ``` 其中 `component` 字段即编辑器组件对象,需要包含 `raw`、`content` 的 prop。 #### Which issue(s) this PR fixes: Fixes https://github.com/halo-dev/halo/issues/2881 #### Screenshots: <img width="1664" alt="image" src="https://user-images.githubusercontent.com/21301288/208406097-60258cba-cff6-436f-bd50-6d8c27ea9a53.png"> <img width="1662" alt="image" src="https://user-images.githubusercontent.com/21301288/208406174-d4649365-3448-4581-a452-f9781502eac6.png"> <img width="1920" alt="image" src="https://user-images.githubusercontent.com/21301288/208407570-db10e956-cd6a-4e0d-801e-b794ad0261bc.png"> <img width="1920" alt="image" src="https://user-images.githubusercontent.com/21301288/208407607-fd595957-5278-40c2-a3b5-fb73c1de429c.png"> #### Special notes for your reviewer: 目前可用于测试的插件: 1. [plugin-stackedit-1.0.0-SNAPSHOT.jar.zip](https://github.com/halo-dev/console/files/10258488/plugin-stackedit-1.0.0-SNAPSHOT.jar.zip) 2. [plugin-bytemd-1.0.0-SNAPSHOT.jar.zip](https://github.com/halo-dev/console/files/10258490/plugin-bytemd-1.0.0-SNAPSHOT.jar.zip) 测试方式: 1. Console 需要 `pnpm build:packages`。 2. 在 Console 的插件管理上传以上插件。 3. 新建若干文章,使用不同的编辑器。 4. 检查是否能够正常发布和编辑。 5. 检查编辑的时候,是否正确使用了之前的编辑器。 6. 检查主题端是否渲染正常。 一些实现细节: 1. 为了支持更新文章时能够选择发布时的编辑器,会在 post 的 `metadata.annotations` 添加一条 `content.halo.run/preferred-editor` 用于标记使用的什么编辑器。如果编辑器不存在,会使用 content 的 `rawType` 来匹配。 2. 目前没有全局默认编辑器设置,只能在新建文章的时候选择。 #### Does this PR introduce a user-facing change? ```release-note Console 端支持扩展集成其他编辑器 ```
2022-12-22 04:14:29 +00:00
class="h-full"
@update="handleSetContentCache"
/>
</div>
</template>