Skip to content

Commit 714ff91

Browse files
authored
Update attachment selector docs for mediaType support (#523)
1 parent ec157ca commit 714ff91

File tree

2 files changed

+34
-9
lines changed

2 files changed

+34
-9
lines changed

docs/developer-guide/plugin/api-changelog.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,16 @@ description: 记录每一个版本的插件 API 变更记录,方便开发者
2121
1. `core:plugin:configMap:updated`:用于监听插件配置变更
2222

2323
详细文档可查阅:[共享工具库](./api-reference/ui/shared.md)
24+
25+
### UI 扩展点 > 附件选择选项卡类型更新
26+
27+
在 2.22.0 中,我们为 `AttachmentLike` 复合类型添加了 `mediaType` 字段,用于区分文件类型,方便在插入到文章时显示正确的媒体类型,如不填写,所选择的文件将作为链接插入到编辑器,所以实现了此扩展点的插件都需要进行改动,具体步骤:
28+
29+
1. 升级依赖
30+
31+
```bash
32+
pnpm install @halo-dev/console-shared@2.22.0
33+
```
34+
35+
2. 提升 [plugin.yaml#spec.requires](./basics/manifest.md#字段详解) 版本为 `>=2.22.0`
36+
3. 按照[最新文档](./extension-points/ui/attachment-selector-create.md)修改插件代码

docs/developer-guide/plugin/extension-points/ui/attachment-selector-create.md

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ description: 扩展附件选择组件的选项卡 - attachment:selector:create
1010
## 定义方式
1111

1212
```ts
13+
import { definePlugin, type AttachmentSelectProvider } from "@halo-dev/console-shared"
14+
import { markRaw } from "vue"
15+
import FooComponent from "./src/FooComponent.vue"
1316
export default definePlugin({
1417
extensionPoints: {
1518
"attachment:selector:create": (): AttachmentSelectProvider[]| Promise<AttachmentSelectProvider[]> => {
@@ -56,14 +59,16 @@ export interface AttachmentSelectProvider {
5659
}>();
5760
```
5861

62+
`AttachmentLike` 是一个复合类型,可以是 Halo 附件模型数据、文件链接字符串、或者简单类型对象,类型定义:
63+
5964
```ts title="AttachmentLike"
60-
export type AttachmentLike =
61-
| Attachment
62-
| string
63-
| {
64-
url: string;
65-
type: string;
66-
};
65+
type AttachmentLike = Attachment | AttachmentSimple | string;
66+
interface AttachmentSimple {
67+
url: string; // 文件链接
68+
mediaType?: string; // 文件类型,如 image/png、video/*,如不填写,将被作为链接插入到文章
69+
alt?: string; // 代替文本
70+
caption?: string; // 说明文本
71+
}
6772
```
6873

6974
## 示例
@@ -97,6 +102,9 @@ export default definePlugin({
97102

98103
```vue title="StickerSelectorProvider.vue"
99104
<script lang="ts" setup>
105+
import type { AttachmentLike, AttachmentSimple } from '@halo-dev/console-shared';
106+
import { ref } from 'vue';
107+
100108
const props = withDefaults(
101109
defineProps<{
102110
selected: AttachmentLike[];
@@ -110,19 +118,22 @@ const emit = defineEmits<{
110118
(event: "update:selected", attachments: AttachmentLike[]): void;
111119
}>();
112120
113-
const stickers = [
121+
const stickers: AttachmentSimple[] = [
114122
{
115123
url: "https://picsum.photos/200?random=1",
124+
mediaType: "image/*"
116125
},
117126
{
118127
url: "https://picsum.photos/200?random=2",
128+
mediaType: "image/*"
119129
},
120130
{
121131
url: "https://picsum.photos/200?random=3",
132+
mediaType: "image/*"
122133
},
123134
];
124135
125-
const selectedStickers = ref<Set<String>>(new Set());
136+
const selectedStickers = ref<Set<string>>(new Set());
126137
127138
const handleSelect = async (url: string) => {
128139
if (selectedStickers.value.has(url)) {
@@ -143,4 +154,5 @@ const handleSelect = async (url: string) => {
143154

144155
## 实现案例
145156

157+
- [https://github.com/halo-sigs/plugin-image-stream](https://github.com/halo-sigs/plugin-image-stream)
146158
- [https://github.com/halo-sigs/plugin-unsplash](https://github.com/halo-sigs/plugin-unsplash)

0 commit comments

Comments
 (0)