web-extend-plugin-vue2 0.2.2 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +45 -192
- package/dist/index.cjs +477 -547
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +475 -546
- package/dist/index.mjs.map +1 -1
- package/index.d.ts +136 -16
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -1,7 +1,108 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* 公共 API 的 TypeScript 声明;IDE 补全以本文件为准。
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
+
/** 清单侧路由声明(PRD),需配合 `adaptRouteDeclarations` */
|
|
6
|
+
export type RouteDeclaration = {
|
|
7
|
+
path: string
|
|
8
|
+
name?: string
|
|
9
|
+
title?: string
|
|
10
|
+
meta?: Record<string, unknown>
|
|
11
|
+
children?: RouteDeclaration[]
|
|
12
|
+
/** 由宿主在 `adaptRouteDeclarations` 中解析为 Vue 组件 */
|
|
13
|
+
componentRef: string
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** `bootstrapPlugins` 调用 `activator` 时的第二参数 */
|
|
17
|
+
export type PluginActivateContext = {
|
|
18
|
+
/** 清单条目的浅拷贝且已 `Object.freeze`,请勿就地修改嵌套对象 */
|
|
19
|
+
pluginRecord: Readonly<Record<string, unknown>>
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* 与 `vue-router` RouteConfig 兼容的宽松对象形态(未安装 vue 类型时仍可用)。
|
|
24
|
+
* 安装 `vue` / `vue-router` 类型后可在业务代码中收窄。
|
|
25
|
+
*/
|
|
26
|
+
export type VueRouteConfig = Record<string, unknown>
|
|
27
|
+
|
|
28
|
+
/** 在合成 `name` / `meta.pluginId` 之前转换插件提交的 `RouteConfig` */
|
|
29
|
+
export type TransformRoutesFn = (ctx: {
|
|
30
|
+
pluginId: string
|
|
31
|
+
router: unknown
|
|
32
|
+
routes: ReadonlyArray<VueRouteConfig>
|
|
33
|
+
}) => VueRouteConfig[]
|
|
34
|
+
|
|
35
|
+
/** 接管路由注册;由宿主决定是否调用 `applyInternalRegister` */
|
|
36
|
+
export type InterceptRegisterRoutesFn = (ctx: {
|
|
37
|
+
pluginId: string
|
|
38
|
+
router: unknown
|
|
39
|
+
routes: ReadonlyArray<VueRouteConfig>
|
|
40
|
+
/** 与默认 `registerRoutes` 相同的包装 + `addRoute` / `addRoutes` */
|
|
41
|
+
applyInternalRegister: (routes: VueRouteConfig[]) => void
|
|
42
|
+
}) => void
|
|
43
|
+
|
|
44
|
+
/** PRD → `RouteConfig` */
|
|
45
|
+
export type AdaptRouteDeclarationsFn = (ctx: {
|
|
46
|
+
pluginId: string
|
|
47
|
+
router: unknown
|
|
48
|
+
declarations: ReadonlyArray<RouteDeclaration>
|
|
49
|
+
}) => VueRouteConfig[]
|
|
50
|
+
|
|
51
|
+
/** 宿主传入 `createHostApi` 的 `hostKit`(及 `resolveRuntimeOptions` 中同类字段) */
|
|
52
|
+
export type HostKitOptions = {
|
|
53
|
+
/** `getBridge().request` 允许的URL路径前缀,须以 `/` 开头 */
|
|
54
|
+
bridgeAllowedPathPrefixes?: string[]
|
|
55
|
+
/** 非空时子路由挂到该命名父路由下(需 vue-router ≥3.5 的 `addRoute`) */
|
|
56
|
+
pluginRoutesParentName?: string
|
|
57
|
+
transformRoutes?: TransformRoutesFn
|
|
58
|
+
interceptRegisterRoutes?: InterceptRegisterRoutesFn
|
|
59
|
+
adaptRouteDeclarations?: AdaptRouteDeclarationsFn
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** `resolveRuntimeOptions` 全量运行时选项(在默认字段基础上的扩展;未列字段见 README) */
|
|
63
|
+
export type WebExtendPluginRuntimeOptions = HostKitOptions &
|
|
64
|
+
Record<string, unknown> & {
|
|
65
|
+
manifestBase?: string
|
|
66
|
+
manifestListPath?: string
|
|
67
|
+
manifestFetchCredentials?: RequestCredentials
|
|
68
|
+
isDev?: boolean
|
|
69
|
+
webPluginDevOrigin?: string
|
|
70
|
+
webPluginDevIds?: string
|
|
71
|
+
webPluginDevMapJson?: string
|
|
72
|
+
webPluginDevEntryPath?: string
|
|
73
|
+
devPingPath?: string
|
|
74
|
+
devReloadSsePath?: string
|
|
75
|
+
devPingTimeoutMs?: number
|
|
76
|
+
defaultImplicitDevPluginIds?: string[]
|
|
77
|
+
allowedScriptHosts?: string[]
|
|
78
|
+
bootstrapSummary?: boolean
|
|
79
|
+
fetchManifest?: ManifestFetchFn
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** 插件 `activator` 收到的宿主 API */
|
|
83
|
+
export interface HostApi {
|
|
84
|
+
/** 宿主实现的 Host API 协议版本,与清单 `hostPluginApiVersion` 对齐 */
|
|
85
|
+
readonly hostPluginApiVersion: string
|
|
86
|
+
/**
|
|
87
|
+
* 动态注册路由。含 PRD 时使用 `componentRef` 树;否则传入 `RouteConfig` 数组。
|
|
88
|
+
* 流水线:`adaptRouteDeclarations` → `transformRoutes` → `interceptRegisterRoutes` 或默认注册。
|
|
89
|
+
*/
|
|
90
|
+
registerRoutes(routes: VueRouteConfig[] | RouteDeclaration[]): void
|
|
91
|
+
/** 写入全局菜单注册表,按 `order` 升序 */
|
|
92
|
+
registerMenuItems(items: Record<string, unknown>[]): void
|
|
93
|
+
registerSlotComponents(
|
|
94
|
+
pointId: string,
|
|
95
|
+
components: Array<{ component: unknown; priority?: number }>
|
|
96
|
+
): void
|
|
97
|
+
registerStylesheetUrls(urls?: string[]): void
|
|
98
|
+
registerScriptUrls(urls?: string[]): void
|
|
99
|
+
registerSanitizedHtmlSnippet(): void
|
|
100
|
+
getBridge(): {
|
|
101
|
+
request(path: string, init?: RequestInit): Promise<Response>
|
|
102
|
+
}
|
|
103
|
+
onTeardown(_pluginId: string, fn: () => void): void
|
|
104
|
+
}
|
|
105
|
+
|
|
5
106
|
export type ManifestFetchContext = { manifestUrl: string; credentials: RequestCredentials }
|
|
6
107
|
|
|
7
108
|
export type ManifestFetchResult = {
|
|
@@ -23,15 +124,17 @@ export type ManifestFetchCacheOptions = {
|
|
|
23
124
|
now?: () => number
|
|
24
125
|
}
|
|
25
126
|
|
|
127
|
+
/** 命名空间聚合对象,按领域分组 */
|
|
26
128
|
export const WebExtendPluginVue2: Readonly<{
|
|
27
|
-
install: (Vue: unknown, router: unknown, options?:
|
|
129
|
+
install: (Vue: unknown, router: unknown, options?: WebExtendPluginRuntimeOptions) => Promise<void>
|
|
28
130
|
runtime: Readonly<{
|
|
131
|
+
/** 拉取清单并依次 `activator(hostApi, { pluginRecord })` */
|
|
29
132
|
bootstrapPlugins: (
|
|
30
133
|
router: unknown,
|
|
31
|
-
createHostApiFactory: (id: string, r: unknown, kit?:
|
|
32
|
-
runtimeOptions?:
|
|
134
|
+
createHostApiFactory: (id: string, r: unknown, kit?: HostKitOptions) => HostApi,
|
|
135
|
+
runtimeOptions?: WebExtendPluginRuntimeOptions
|
|
33
136
|
) => Promise<void>
|
|
34
|
-
resolveRuntimeOptions: (user?:
|
|
137
|
+
resolveRuntimeOptions: (user?: WebExtendPluginRuntimeOptions) => WebExtendPluginRuntimeOptions
|
|
35
138
|
defaultFetchWebPluginManifest: (ctx: {
|
|
36
139
|
manifestUrl: string
|
|
37
140
|
credentials: RequestCredentials
|
|
@@ -44,7 +147,7 @@ export const WebExtendPluginVue2: Readonly<{
|
|
|
44
147
|
wrapManifestFetchWithCache: (inner: ManifestFetchFn, options?: ManifestFetchCacheOptions) => ManifestFetchFn
|
|
45
148
|
}>
|
|
46
149
|
host: Readonly<{
|
|
47
|
-
createHostApi: (pluginId: string, router: unknown, hostKit?:
|
|
150
|
+
createHostApi: (pluginId: string, router: unknown, hostKit?: HostKitOptions) => HostApi
|
|
48
151
|
disposeWebPlugin: (pluginId: string) => void
|
|
49
152
|
createRequestBridge: (config?: { allowedPathPrefixes?: string[] }) => {
|
|
50
153
|
request: (path: string, init?: RequestInit) => Promise<Response>
|
|
@@ -55,7 +158,7 @@ export const WebExtendPluginVue2: Readonly<{
|
|
|
55
158
|
defaultWebExtendPluginRuntime: Record<string, unknown>
|
|
56
159
|
setWebExtendPluginEnv: (env: Record<string, unknown> | null | undefined) => void
|
|
57
160
|
}>
|
|
58
|
-
constants: Readonly<{ HOST_PLUGIN_API_VERSION: string }>
|
|
161
|
+
constants: Readonly<{ HOST_PLUGIN_API_VERSION: string; RUNTIME_CONSOLE_LABEL: string }>
|
|
59
162
|
components: Readonly<{ ExtensionPoint: unknown }>
|
|
60
163
|
presets: Readonly<{
|
|
61
164
|
vueCliAxios: Readonly<{
|
|
@@ -72,43 +175,60 @@ export const WebExtendPluginVue2: Readonly<{
|
|
|
72
175
|
}>
|
|
73
176
|
|
|
74
177
|
export const defaultWebExtendPluginRuntime: Record<string, unknown>
|
|
178
|
+
|
|
179
|
+
/** 拉取清单并依次激活插件;浏览器环境执行 */
|
|
75
180
|
export function bootstrapPlugins(
|
|
76
181
|
router: unknown,
|
|
77
|
-
createHostApiFactory: (id: string, r: unknown, kit?:
|
|
78
|
-
runtimeOptions?:
|
|
182
|
+
createHostApiFactory: (id: string, r: unknown, kit?: HostKitOptions) => HostApi,
|
|
183
|
+
runtimeOptions?: WebExtendPluginRuntimeOptions
|
|
79
184
|
): Promise<void>
|
|
80
|
-
|
|
185
|
+
|
|
186
|
+
/** 合并默认配置、环境变量与显式传入字段 */
|
|
187
|
+
export function resolveRuntimeOptions(user?: WebExtendPluginRuntimeOptions): WebExtendPluginRuntimeOptions
|
|
188
|
+
|
|
81
189
|
export function defaultFetchWebPluginManifest(ctx: {
|
|
82
190
|
manifestUrl: string
|
|
83
191
|
credentials: RequestCredentials
|
|
84
192
|
}): Promise<{ ok: boolean; status?: number; data?: unknown; error?: unknown }>
|
|
85
|
-
|
|
193
|
+
|
|
194
|
+
/** 构造单个插件在宿主侧的 `hostApi`,供 `activator(hostApi, context)` 使用 */
|
|
195
|
+
export function createHostApi(pluginId: string, router: unknown, hostKit?: HostKitOptions): HostApi
|
|
196
|
+
|
|
86
197
|
export function disposeWebPlugin(pluginId: string): void
|
|
87
198
|
export const registries: unknown
|
|
199
|
+
|
|
88
200
|
export function createRequestBridge(config?: {
|
|
89
201
|
allowedPathPrefixes?: string[]
|
|
90
202
|
}): { request: (path: string, init?: RequestInit) => Promise<Response> }
|
|
203
|
+
|
|
91
204
|
export const HOST_PLUGIN_API_VERSION: string
|
|
205
|
+
/** 控制台日志前缀用的短名称 */
|
|
206
|
+
export const RUNTIME_CONSOLE_LABEL: string
|
|
92
207
|
export function setWebExtendPluginEnv(env: Record<string, unknown> | null | undefined): void
|
|
208
|
+
|
|
209
|
+
/** 注册全局 `ExtensionPoint` 并异步 `bootstrapPlugins` */
|
|
93
210
|
export function installWebExtendPluginVue2(
|
|
94
211
|
Vue: unknown,
|
|
95
212
|
router: unknown,
|
|
96
|
-
options?:
|
|
213
|
+
options?: WebExtendPluginRuntimeOptions
|
|
97
214
|
): Promise<void>
|
|
215
|
+
|
|
98
216
|
export const ExtensionPoint: unknown
|
|
99
217
|
|
|
100
218
|
export function createVueCliAxiosInstallOptions(
|
|
101
219
|
deps: { request: (config: Record<string, unknown>) => Promise<unknown> },
|
|
102
220
|
extra?: Record<string, unknown>
|
|
103
221
|
): Record<string, unknown>
|
|
104
|
-
|
|
105
|
-
export function
|
|
222
|
+
/** 将完整 manifest URL 转为相对 axios `baseURL` 的请求路径 */
|
|
223
|
+
export function resolveManifestPathUnderApiBase(manifestUrl: string, apiBase?: string): string
|
|
224
|
+
/** 解包裸清单或与 `{ data: { plugins } }` 包装的响应体 */
|
|
225
|
+
export function unwrapNestedManifestBody(body: unknown): object | null
|
|
106
226
|
export const presetVueCliAxios: Readonly<{
|
|
107
227
|
id: string
|
|
108
228
|
description: string
|
|
109
229
|
createInstallOptions: typeof createVueCliAxiosInstallOptions
|
|
110
|
-
manifestPathForApiBase: typeof
|
|
111
|
-
unwrapManifestBody: typeof
|
|
230
|
+
manifestPathForApiBase: typeof resolveManifestPathUnderApiBase
|
|
231
|
+
unwrapManifestBody: typeof unwrapNestedManifestBody
|
|
112
232
|
}>
|
|
113
233
|
|
|
114
234
|
export function composeManifestFetch(
|