Files
halo/ui/console-src/composables/use-entity-extension-points.ts
Ryan Wang ac88ee70cb Rename @halo-dev/console-shared to @halo-dev/ui-shared (#7926)
#### What type of PR is this?

/area ui
/kind api-change
/milestone 2.22.x

#### What this PR does / why we need it:

See #7925 

#### Which issue(s) this PR fixes:

Fixes #7925 

#### Special notes for your reviewer:

#### Does this PR introduce a user-facing change?

```release-note
将 `@halo-dev/console-shared` 重命名为 `@halo-dev/ui-shared`
```
2025-11-10 16:20:41 +00:00

56 lines
1.5 KiB
TypeScript

import { usePluginModuleStore } from "@/stores/plugin";
import type { EntityFieldItem } from "@halo-dev/ui-shared";
import { useQuery } from "@tanstack/vue-query";
import { computed, toValue, type ComputedRef, type Ref } from "vue";
export function useEntityFieldItemExtensionPoint<T>(
extensionPointName: string,
entity: Ref<T>,
presets: ComputedRef<EntityFieldItem[]>
) {
const { pluginModules } = usePluginModuleStore();
return useQuery({
queryKey: computed(() => [
"core:extension-points:list-item:fields",
extensionPointName,
toValue(entity),
]),
queryFn: async () => {
const itemsFromPlugins: EntityFieldItem[] = [];
for (const pluginModule of pluginModules) {
const { extensionPoints } = pluginModule;
if (!extensionPoints?.[extensionPointName]) {
continue;
}
const items = extensionPoints[extensionPointName](
entity
) as EntityFieldItem[];
itemsFromPlugins.push(...items);
}
const allItems = [...presets.value, ...itemsFromPlugins].sort(
(a, b) => a.priority - b.priority
);
const start: EntityFieldItem[] = [];
const end: EntityFieldItem[] = [];
for (const item of allItems) {
if (item.position === "start") {
start.push(item);
} else if (item.position === "end") {
end.push(item);
}
}
return {
start,
end,
};
},
enabled: computed(() => !!presets.value && !!entity.value),
});
}