Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions docs/developer-guide/plugin/api-changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,20 @@ description: 记录每一个版本的插件 API 变更记录,方便开发者

## 2.22.0

### `@halo-dev/console-shared` 工具库
### `@halo-dev/console-shared` 改名

在 2.22.0 中,Halo 在 `@halo-dev/console-shared` 包中提供一些常用工具,用于减少部分业务的开发工作量,目前提供:
从 Halo 2.11 支持个人中心以后,插件的 UI 项目能同时扩展 Console 和 UC,所以为了避免歧义,我们在 Halo 2.22 中将 UI 的 `@halo-dev/console-shared` 依赖更名为 `@halo-dev/ui-shared`,虽然在 Halo 中兼容了旧版依赖,但仍然推荐使用新版依赖,迁移方案:

```bash
pnpm uninstall @halo-dev/console-shared
pnpm install @halo-dev/ui-shared
```

然后在插件项目全局搜索 `@halo-dev/console-shared` 并替换为 `@halo-dev/ui-shared` 即可,同时需要将 `plugin.yaml` 的 `spec.requires` 字段修改为 `>=2.22.0`。

### `@halo-dev/ui-shared` 工具库

在 2.22.0 中,Halo 在 `@halo-dev/ui-shared` 包中提供一些常用工具,用于减少部分业务的开发工作量,目前提供:

1. `stores`
1. `currentUser`:用于获取当前用户信息
Expand All @@ -29,7 +40,7 @@ description: 记录每一个版本的插件 API 变更记录,方便开发者
1. 升级依赖

```bash
pnpm install @halo-dev/console-shared@2.22.0
pnpm install @halo-dev/ui-shared@2.22.0
```

2. 提升 [plugin.yaml#spec.requires](./basics/manifest.md#字段详解) 版本为 `>=2.22.0`。
Expand Down
32 changes: 16 additions & 16 deletions docs/developer-guide/plugin/api-reference/ui/shared.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
---
title: 共享工具库
description: 介绍 @halo-dev/console-shared 包中的共享工具库
description: 介绍 @halo-dev/ui-shared 包中的共享工具库
---

从 Halo 2.22 开始,Halo 为插件的 UI 部分提供了共享的工具库并放置在了 `@halo-dev/console-shared` 中,利用这些工具,可以减少部分开发工作量。
从 Halo 2.22 开始,Halo 为插件的 UI 部分提供了共享的工具库并放置在了 `@halo-dev/ui-shared` 中,利用这些工具,可以减少部分开发工作量。

使用这些工具需要将插件项目的 `@halo-dev/console-shared` 依赖升级到 2.22.0。并在发布新版本插件时,将 [plugin.yaml#spec.requires](../../basics/manifest.md#字段详解) 提升到 `>=2.22.0`。
使用这些工具需要将插件项目的 `@halo-dev/ui-shared`(前 [@halo-dev/console-shared](../../api-changelog.md#halo-devconsole-shared-改名))依赖升级到 2.22.0。并在发布新版本插件时,将 [plugin.yaml#spec.requires](../../basics/manifest.md#字段详解) 提升到 `>=2.22.0`。

## stores

Expand All @@ -21,7 +21,7 @@ pnpm install pinia

```vue title="ui/src/MyComponent.vue"
<script lang="ts" setup>
import { stores } from "@halo-dev/console-shared"
import { stores } from "@halo-dev/ui-shared"
import { storeToRefs } from "pinia"

const userStore = stores.currentUser()
Expand Down Expand Up @@ -55,7 +55,7 @@ const { currentUser, isAnonymous } = storeToRefs(stores.currentUser())

```vue title="ui/src/MyComponent.vue"
<script lang="ts" setup>
import { stores } from "@halo-dev/console-shared"
import { stores } from "@halo-dev/ui-shared"
import { storeToRefs } from "pinia"

const globalInfoStore = stores.globalInfo()
Expand Down Expand Up @@ -116,7 +116,7 @@ const { globalInfo } = storeToRefs(stores.globalInfo())
**示例:**

```ts
import { utils } from "@halo-dev/console-shared"
import { utils } from "@halo-dev/ui-shared"

utils.date.format(new Date()) // "2025-11-05 14:30"
utils.date.format("2025-10-22", "YYYY/MM/DD") // "2025/10/22"
Expand All @@ -136,7 +136,7 @@ utils.date.format(null) // ""
**示例:**

```ts
import { utils } from "@halo-dev/console-shared"
import { utils } from "@halo-dev/ui-shared"

utils.date.toISOString(new Date("2025-10-22")) // "2025-10-22T00:00:00.000Z"
```
Expand All @@ -154,7 +154,7 @@ utils.date.toISOString(new Date("2025-10-22")) // "2025-10-22T00:00:00.000Z"
**示例:**

```ts
import { utils } from "@halo-dev/console-shared"
import { utils } from "@halo-dev/ui-shared"

utils.date.toDatetimeLocal(new Date("2025-10-22 14:30")) // "2025-10-22T14:30"
```
Expand All @@ -172,7 +172,7 @@ utils.date.toDatetimeLocal(new Date("2025-10-22 14:30")) // "2025-10-22T14:30"
**示例:**

```ts
import { utils } from "@halo-dev/console-shared"
import { utils } from "@halo-dev/ui-shared"

// 假设当前时间是 2025-10-22
utils.date.timeAgo("2025-10-23") // "1 天后"
Expand Down Expand Up @@ -210,7 +210,7 @@ utils.date.timeAgo("2025-11-22") // "1 个月后"
**示例:**

```ts
import { utils } from "@halo-dev/console-shared"
import { utils } from "@halo-dev/ui-shared"

// 检查是否拥有任意一个权限
utils.permission.has(["core:posts:manage"], true) // true
Expand All @@ -237,7 +237,7 @@ utils.permission.has([
**示例:**

```ts
import { utils } from "@halo-dev/console-shared"
import { utils } from "@halo-dev/ui-shared"

const permissions = utils.permission.getUserPermissions()
console.log(permissions) // ["core:posts:manage", "core:attachments:view"]
Expand Down Expand Up @@ -270,7 +270,7 @@ console.log(permissions) // ["core:posts:manage", "core:attachments:view"]
**示例:**

```ts
import { utils } from "@halo-dev/console-shared"
import { utils } from "@halo-dev/ui-shared"

// 本地图片
utils.attachment.getThumbnailUrl("/uploads/image.jpg", "M")
Expand All @@ -294,7 +294,7 @@ utils.attachment.getThumbnailUrl("https://example.com/image.jpg", "S")
**示例:**

```ts
import { utils } from "@halo-dev/console-shared"
import { utils } from "@halo-dev/ui-shared"

// 字符串 URL
utils.attachment.getUrl("https://example.com/image.jpg")
Expand Down Expand Up @@ -332,7 +332,7 @@ interface AttachmentSimple {
**示例:**

```ts
import { utils } from "@halo-dev/console-shared"
import { utils } from "@halo-dev/ui-shared"

// 字符串 URL
utils.attachment.convertToSimple("https://example.com/image.jpg")
Expand Down Expand Up @@ -373,7 +373,7 @@ ID 生成工具,用于生成唯一且可排序的标识符。基于 [uuid](htt
**示例:**

```ts
import { utils } from "@halo-dev/console-shared"
import { utils } from "@halo-dev/ui-shared"

const id = utils.id.uuid()
console.log(id) // "018f1c2e-4fcb-7d04-9f21-1a2b3c4d5e6f"
Expand All @@ -390,7 +390,7 @@ const resourceId = utils.id.uuid()

```vue title="ui/src/MyComponent.vue"
<script lang="ts" setup>
import { events } from "@halo-dev/console-shared"
import { events } from "@halo-dev/ui-shared"

// 监听事件
events.on("core:plugin:configMap:updated", (data) => {
Expand Down
2 changes: 1 addition & 1 deletion docs/developer-guide/plugin/basics/ui/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ Vite 和 Rsbuild 都是优秀的构建工具,但它们在不同的使用场景
**动态导入示例:**

```typescript
import { definePlugin } from '@halo-dev/console-shared';
import { definePlugin } from '@halo-dev/ui-shared';
import { defineAsyncComponent } from 'vue';
import { VLoading } from '@halo-dev/components';

Expand Down
2 changes: 1 addition & 1 deletion docs/developer-guide/plugin/basics/ui/entry.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ description: UI 扩展部分的入口文件
## 定义入口文件

```ts title="ui/src/index.ts"
import { definePlugin } from "@halo-dev/console-shared";
import { definePlugin } from "@halo-dev/ui-shared";

export default definePlugin({
components: {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import OperationItem from "./interface/OperationItem.md";
此示例将实现一个下载附件到本地的操作菜单项。

```ts
import { definePlugin, type OperationItem } from "@halo-dev/console-shared";
import { definePlugin, type OperationItem } from "@halo-dev/ui-shared";
import { Toast, VDropdownItem } from "@halo-dev/components";
import { markRaw, type Ref } from "vue";
import type { Attachment } from "@halo-dev/api-client";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ description: 扩展附件选择组件的选项卡 - attachment:selector:create
## 定义方式

```ts
import { definePlugin, type AttachmentSelectProvider } from "@halo-dev/console-shared"
import { definePlugin, type AttachmentSelectProvider } from "@halo-dev/ui-shared"
import { markRaw } from "vue"
import FooComponent from "./src/FooComponent.vue"
export default definePlugin({
Expand Down Expand Up @@ -79,7 +79,7 @@ interface AttachmentSimple {
import {
definePlugin,
type AttachmentSelectProvider,
} from "@halo-dev/console-shared";
} from "@halo-dev/ui-shared";
import { markRaw } from "vue";
import StickerSelectorProvider from "./components/StickerSelectorProvider.vue";

Expand All @@ -102,7 +102,7 @@ export default definePlugin({

```vue title="StickerSelectorProvider.vue"
<script lang="ts" setup>
import type { AttachmentLike, AttachmentSimple } from '@halo-dev/console-shared';
import type { AttachmentLike, AttachmentSimple } from '@halo-dev/ui-shared';
import { ref } from 'vue';

const props = withDefaults(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import OperationItem from "./interface/OperationItem.md";
```ts
import type { ListedComment } from "@halo-dev/api-client";
import { VDropdownItem } from "@halo-dev/components";
import { definePlugin } from "@halo-dev/console-shared";
import { definePlugin } from "@halo-dev/ui-shared";
import { markRaw } from "vue";

export default definePlugin({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export interface CommentSubjectRefResult {
import {
definePlugin,
type CommentSubjectRefResult,
} from "@halo-dev/console-shared";
} from "@halo-dev/ui-shared";
import { markRaw } from "vue";
import type { Moment } from "@/types";
import { formatDatetime } from "./utils/date";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ description: 扩展仪表盘小部件 - console:dashboard:widgets:create
### 定义方式

```ts
import { definePlugin } from "@halo-dev/console-shared";
import { definePlugin } from "@halo-dev/ui-shared";
import { markRaw } from "vue";
import MyCustomWidget from "./components/MyCustomWidget.vue";

Expand Down Expand Up @@ -173,7 +173,7 @@ const emit = defineEmits<{
### 定义方式

```ts
import { definePlugin } from "@halo-dev/console-shared";
import { definePlugin } from "@halo-dev/ui-shared";
import { markRaw } from "vue";
import { IconPlug } from "@halo-dev/components";
import { useRouter } from "vue-router";
Expand Down Expand Up @@ -237,7 +237,7 @@ export default definePlugin({
</template>

<script lang="ts" setup>
import type { DashboardWidgetQuickActionItem } from "@halo-dev/console-shared";
import type { DashboardWidgetQuickActionItem } from "@halo-dev/ui-shared";

defineProps<{
item: DashboardWidgetQuickActionItem;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export interface EditorProvider {
此示例将实现一个简单的 Markdown 编辑器。

```ts title="index.ts"
import { definePlugin } from "@halo-dev/console-shared";
import { definePlugin } from "@halo-dev/ui-shared";
import { markRaw } from "vue";
import MarkdownEditor from "./components/markdown-editor.vue";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export interface EntityFieldItem {
此示例将添加一个显示插件 requires(版本要求)的字段。

```ts
import { definePlugin } from "@halo-dev/console-shared";
import { definePlugin } from "@halo-dev/ui-shared";
import { markRaw, type Ref } from "vue";
import type { Plugin } from "@halo-dev/api-client";
import { VEntityField } from "@halo-dev/components";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export interface PluginTab {
此示例实现了一个自定义选项卡,用于获取插件的数据并显示名称。

```ts
import { definePlugin, PluginTab } from "@halo-dev/console-shared";
import { definePlugin, PluginTab } from "@halo-dev/ui-shared";
import MyComponent from "./views/my-component.vue";
import { markRaw } from "vue";
export default definePlugin({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export interface EntityFieldItem {
此示例将添加一个显示文章 slug(别名)的字段。

```ts
import { definePlugin } from "@halo-dev/console-shared";
import { definePlugin } from "@halo-dev/ui-shared";
import { markRaw, type Ref } from "vue";
import type { ListedPost } from "@halo-dev/api-client";
import { VEntityField } from "@halo-dev/components";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import OperationItem from "./interface/OperationItem.md";
```ts
import type { ListedPost } from "@halo-dev/api-client";
import { VDropdownItem } from "@halo-dev/components";
import { definePlugin } from "@halo-dev/console-shared";
import { definePlugin } from "@halo-dev/ui-shared";
import axios from "axios";
import { markRaw } from "vue";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import OperationItem from "./interface/OperationItem.md";
```ts
import type { ListedReply } from "@halo-dev/api-client";
import { VDropdownItem } from "@halo-dev/components";
import { definePlugin } from "@halo-dev/console-shared";
import { definePlugin } from "@halo-dev/ui-shared";
import { markRaw } from "vue";

export default definePlugin({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export interface EntityFieldItem {
此示例将添加一个显示页面 slug(别名)的字段。

```ts
import { definePlugin } from "@halo-dev/console-shared";
import { definePlugin } from "@halo-dev/ui-shared";
import { markRaw, type Ref } from "vue";
import type { ListedSinglePage } from "@halo-dev/api-client";
import { VEntityField } from "@halo-dev/components";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import OperationItem from "./interface/OperationItem.md";
```ts
import type { ListedSinglePage } from "@halo-dev/api-client";
import { VDropdownItem } from "@halo-dev/components";
import { definePlugin } from "@halo-dev/console-shared";
import { definePlugin } from "@halo-dev/ui-shared";
import axios from "axios";
import { markRaw } from "vue";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import OperationItem from "./interface/OperationItem.md";
此示例将实现一个跳转到前台预览主题的操作菜单项。

```ts
import { definePlugin, type OperationItem } from "@halo-dev/console-shared";
import { definePlugin, type OperationItem } from "@halo-dev/ui-shared";
import { VButton } from "@halo-dev/components";
import { markRaw, type Ref } from "vue";
import type { Theme } from "@halo-dev/api-client";
Expand Down