@anov/cic-standard-sdk 0.0.20 → 0.0.21

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.
@@ -1,385 +0,0 @@
1
- /**
2
- * Adapter(生产层)接口
3
- *
4
- * 职责边界:
5
- * - Adapter:只负责“用什么渲染 & 怎么执行渲染动作”(创建上下文、注册、挂载、卸载、可选实例方法调用)
6
- * - 协调层(CICSDK/运行时):负责解析 CICConfig + Manifest,产出 ResolvedComponent、并决定调用顺序
7
- */
8
- import type { CICConfig } from './cic';
9
- import type { CICManifest } from './cic.manifest';
10
- export type EngineConfig = CICManifest['engine'];
11
- /**
12
- * 创建上下文选项
13
- */
14
- export interface CreateContextOptions<TContainer = any> {
15
- /**
16
- * CIC 配置
17
- */
18
- config: CICConfig;
19
- /**
20
- * Manifest 配置
21
- */
22
- manifest: CICManifest;
23
- /**
24
- * 容器元素
25
- */
26
- container?: TContainer;
27
- /**
28
- * 已解析的组件列表
29
- */
30
- resolvedComponents?: ResolvedComponent[];
31
- /**
32
- * 已加载的模块
33
- */
34
- loadedModules?: Map<string, any>;
35
- /**
36
- * 其他选项
37
- */
38
- [key: string]: any;
39
- }
40
- /**
41
- * 已解析的组件
42
- */
43
- export interface ResolvedComponent {
44
- /**
45
- * 组件 ID
46
- */
47
- id: string;
48
- /**
49
- * 组件类型
50
- */
51
- kind: 'component' | 'plugin' | 'module' | 'directive' | 'filter' | 'global';
52
- /**
53
- * 组件值(实际的组件/插件/模块)
54
- */
55
- value: any;
56
- /**
57
- * 注册配置
58
- */
59
- register?: {
60
- /**
61
- * 注册方法名(如 'install', 'init')
62
- */
63
- method?: string;
64
- /**
65
- * 注册选项
66
- */
67
- options?: any;
68
- };
69
- /**
70
- * 是否必需
71
- */
72
- required?: boolean;
73
- /**
74
- * 依赖项
75
- */
76
- dependencies?: string[];
77
- /**
78
- * 是否异步
79
- */
80
- async?: boolean;
81
- }
82
- /**
83
- * Adapter 上下文
84
- */
85
- export interface AdapterContext<TContainer = any, TApp = any> {
86
- /**
87
- * 应用实例(如 Vue app、React root)
88
- */
89
- app: TApp;
90
- /**
91
- * 容器元素
92
- */
93
- container: TContainer;
94
- /**
95
- * 引擎配置
96
- */
97
- runtime: EngineConfig;
98
- /**
99
- * CIC 配置
100
- */
101
- config: CICConfig;
102
- /**
103
- * Manifest 配置
104
- */
105
- manifest: CICManifest;
106
- /**
107
- * 已解析的组件
108
- */
109
- resolvedComponents: ResolvedComponent[];
110
- /**
111
- * 已加载的模块
112
- */
113
- loadedModules?: Map<string, any>;
114
- /**
115
- * 扩展数据
116
- */
117
- [key: string]: any;
118
- }
119
- /**
120
- * Adapter 接口(优化版)
121
- *
122
- * 完整生命周期:
123
- * 1. supports(engine) - 检查是否支持
124
- * 2. createContext(options) - 创建上下文
125
- * 3. prepare(context) - 准备阶段(可选)
126
- * 4. register(context) - 注册阶段
127
- * 5. mount(context) - 挂载阶段
128
- * 6. update(context, config) - 更新阶段(可选)
129
- * 7. unmount(context) - 卸载阶段
130
- *
131
- * @template TContainer 容器类型(如 HTMLElement)
132
- * @template TApp 应用实例类型(如 Vue App、React Root)
133
- * @template TMountedInstance 挂载后的实例类型
134
- * @template TContext 上下文类型
135
- */
136
- export interface Adapter<TContainer = any, TApp = any, TMountedInstance = any, TContext extends AdapterContext<TContainer, TApp> = AdapterContext<TContainer, TApp>> {
137
- /**
138
- * Adapter 唯一标识
139
- *
140
- * 命名规范:{platform}/{runtime}
141
- *
142
- * @example
143
- * "web/vue3"
144
- * "web/react"
145
- * "mobile/react-native"
146
- * "desktop/electron-vue"
147
- */
148
- id: string;
149
- /**
150
- * Adapter 版本(可选)
151
- */
152
- version?: string;
153
- /**
154
- * 描述(可选)
155
- */
156
- description?: string;
157
- /**
158
- * 1️⃣ 检查是否支持
159
- *
160
- * 在选择 Adapter 时调用,用于判断当前 Adapter 是否支持目标引擎
161
- *
162
- * @param engine 引擎配置
163
- * @returns 是否支持
164
- *
165
- * @example
166
- * supports: (engine) => {
167
- * return engine.platform === 'web' && engine.runtime === 'vue3';
168
- * }
169
- */
170
- supports: (engine: EngineConfig) => boolean;
171
- /**
172
- * 2️⃣ 创建上下文
173
- *
174
- * 在开始渲染前调用,创建必要的运行时环境
175
- *
176
- * 职责:
177
- * - 创建应用实例(如 createApp、createRoot)
178
- * - 初始化基础配置
179
- * - 准备上下文对象
180
- *
181
- * @param options 创建选项
182
- * @returns 上下文对象
183
- *
184
- * @example
185
- * createContext: async (options) => {
186
- * const app = createApp({
187
- * template: '<div id="cic-root"><router-view /></div>'
188
- * });
189
- *
190
- * return {
191
- * app,
192
- * container: options.container,
193
- * runtime: options.manifest.engine,
194
- * config: options.config,
195
- * manifest: options.manifest,
196
- * resolvedComponents: options.resolvedComponents || []
197
- * };
198
- * }
199
- */
200
- createContext: (options: CreateContextOptions<TContainer>) => Promise<TContext>;
201
- /**
202
- * 3️⃣ 准备阶段(可选)
203
- *
204
- * 在注册组件之前执行,用于安装插件和配置核心功能
205
- *
206
- * 职责:
207
- * - 安装框架插件(Vue Router、React Router)
208
- * - 配置状态管理(Pinia、Redux)
209
- * - 全局配置(errorHandler、warnHandler)
210
- * - 加载主题、国际化等全局资源
211
- *
212
- * @param context 上下文
213
- *
214
- * @example
215
- * prepare: async (context) => {
216
- * const { app, loadedModules } = context;
217
- *
218
- * // 安装路由
219
- * const router = loadedModules?.get('vue-router');
220
- * if (router) {
221
- * app.use(router);
222
- * }
223
- *
224
- * // 安装状态管理
225
- * const pinia = loadedModules?.get('pinia');
226
- * if (pinia) {
227
- * app.use(pinia);
228
- * }
229
- *
230
- * // 全局配置
231
- * app.config.errorHandler = (err) => {
232
- * console.error('Global error:', err);
233
- * };
234
- * }
235
- */
236
- prepare?: (context: TContext, config: CICConfig, manifest: CICManifest) => Promise<void>;
237
- /**
238
- * 4️⃣ 注册阶段
239
- *
240
- * 注册组件、指令、过滤器等
241
- *
242
- * 职责:
243
- * - 注册全局组件
244
- * - 注册指令
245
- * - 注册过滤器(Vue2)
246
- * - 注册公共组件(从 ComponentRegistry)
247
- *
248
- * @param context 上下文
249
- * @param config CIC 配置
250
- * @param manifest Manifest 配置
251
- *
252
- * @example
253
- * register: async (context, config, manifest) => {
254
- * const { app, resolvedComponents } = context;
255
- *
256
- * for (const comp of resolvedComponents) {
257
- * switch (comp.kind) {
258
- * case 'plugin':
259
- * app.use(comp.value, comp.register?.options);
260
- * break;
261
- *
262
- * case 'component':
263
- * const name = comp.register?.options?.name || comp.id;
264
- * app.component(name, comp.value);
265
- * break;
266
- *
267
- * case 'directive':
268
- * const directiveName = comp.register?.options?.name || comp.id;
269
- * app.directive(directiveName, comp.value);
270
- * break;
271
- * }
272
- * }
273
- * }
274
- */
275
- register: (context: TContext, config: CICConfig, manifest: CICManifest) => Promise<void>;
276
- /**
277
- * 5️⃣ 挂载阶段
278
- *
279
- * 将应用挂载到容器
280
- *
281
- * 职责:
282
- * - 执行挂载操作
283
- * - 返回挂载后的实例
284
- *
285
- * @param context 上下文
286
- * @returns 挂载后的实例
287
- *
288
- * @example
289
- * mount: async (context) => {
290
- * const { app, container } = context;
291
- * const instance = app.mount(container);
292
- * return instance;
293
- * }
294
- */
295
- mount: (context: TContext) => Promise<TMountedInstance>;
296
- /**
297
- * 6️⃣ 更新阶段(可选)
298
- *
299
- * 动态更新配置,支持热更新
300
- *
301
- * 职责:
302
- * - 更新组件配置
303
- * - 触发重新渲染
304
- *
305
- * @param context 上下文
306
- * @param newConfig 新配置(部分)
307
- *
308
- * @example
309
- * update: async (context, newConfig) => {
310
- * // 更新配置并重新渲染
311
- * Object.assign(context.config, newConfig);
312
- * // 触发更新逻辑...
313
- * }
314
- */
315
- update?: (context: TContext, newConfig: Partial<CICConfig>) => Promise<void>;
316
- /**
317
- * 7️⃣ 卸载阶段
318
- *
319
- * 清理资源,卸载应用
320
- *
321
- * 职责:
322
- * - 卸载应用
323
- * - 清理事件监听
324
- * - 释放内存
325
- *
326
- * @param context 上下文
327
- *
328
- * @example
329
- * unmount: async (context) => {
330
- * const { app } = context;
331
- * app.unmount();
332
- * }
333
- */
334
- unmount: (context: TContext) => Promise<void>;
335
- /**
336
- * 调用组件方法(可选)
337
- *
338
- * 用于调用已挂载组件的实例方法
339
- *
340
- * @param context 上下文
341
- * @param componentId 组件 ID
342
- * @param methodName 方法名
343
- * @param args 参数
344
- * @returns 方法返回值
345
- *
346
- * @example
347
- * callMethod: async (context, 'my-chart', 'updateData', [newData]) => {
348
- * const instance = findComponentInstance(context, 'my-chart');
349
- * return instance?.[methodName]?.(...args);
350
- * }
351
- */
352
- callMethod?: (context: TContext, componentId: string, methodName: string, args?: any[]) => Promise<any>;
353
- /**
354
- * 获取组件实例(可选)
355
- *
356
- * 用于获取已挂载组件的实例
357
- *
358
- * @param context 上下文
359
- * @param componentId 组件 ID
360
- * @returns 组件实例
361
- */
362
- getComponentInstance?: (context: TContext, componentId: string) => any;
363
- /**
364
- * 验证配置(可选)
365
- *
366
- * 在创建上下文前验证配置是否合法
367
- *
368
- * @param config CIC 配置
369
- * @param manifest Manifest 配置
370
- * @returns 验证结果
371
- */
372
- validate?: (config: CICConfig, manifest: CICManifest) => {
373
- valid: boolean;
374
- errors?: string[];
375
- };
376
- /**
377
- * 渲染阶段
378
- *
379
- * 渲染应用到容器
380
- *
381
- * @param config CIC 配置
382
- * @param manifest Manifest 配置
383
- */
384
- render: (context: TContext, config: CICConfig, manifest: CICManifest) => Promise<void>;
385
- }