@das-fed/mframe 0.0.31 → 0.0.33

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.
Files changed (4) hide show
  1. package/es5.js +6168 -4953
  2. package/index.d.ts +253 -10
  3. package/index.js +5102 -4326
  4. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -74,7 +74,9 @@ declare const channelItem: {
74
74
  }>, opt?: {
75
75
  notMerge?: boolean;
76
76
  } | undefined) => void;
77
- get: (keys?: ("visible" | "frameVisible" | "navVisible" | "menuVisible" | "tabVisible" | "mountVisible" | "navRect" | "menuRect" | "tabRect" | "mountRect" | "microApps" | "activeMicroAppName" | "activeMicroAppItem" | "navItems" | "activeNavItem" | "menuItems" | "activeMenuItem" | "fullNavItems" | "tabItems" | "activeTabItem" | "microAppStickStatus" | "initOptions")[] | undefined) => {
77
+ get: (keys?: ("visible" | "frameVisible" | "navVisible" | "menuVisible" | "tabVisible" | "mountVisible" | "navRect" | "menuRect" | "tabRect" | "mountRect" | "microApps" | "activeMicroAppName" | "activeMicroAppItem" | "navItems" | "activeNavItem" | "menuItems" | "activeMenuItem" | "fullNavItems" | "tabItems" | "activeTabItem" | "microAppStickStatus" | "initOptions")[] | undefined, options?: {
78
+ clone?: boolean;
79
+ } | undefined) => {
78
80
  /** 整个容器是否显示,默认为true,包括内容区域 */
79
81
  visible: boolean | undefined;
80
82
  /** 外框是否显示,默认为true,外框包括顶部导航栏,左侧菜单栏,tab标签栏 */
@@ -284,16 +286,23 @@ declare const channelItem_2: {
284
286
  set: (payload: Partial<{}>, opt?: {
285
287
  notMerge?: boolean;
286
288
  } | undefined) => void;
287
- get: (keys?: never[] | undefined) => {};
289
+ get: (keys?: never[] | undefined, options?: {
290
+ clone?: boolean;
291
+ } | undefined) => {};
288
292
  watch: (cb: (newData: {}, oldData: {}) => any, watchKeys?: never[] | undefined) => () => void;
289
293
  };
290
294
  cors: {
291
- send: (microAppName: string, key: ChildernListener, data?: any) => Promise<any>;
292
- on: (name: ParentListener, opt1: any, opt2?: any) => any;
293
- once: (name: ParentListener, opt1: any, opt2?: any) => any;
295
+ send: (microAppName: string, key: ChildernListener, data?: any) => Promise<any[]>;
296
+ on: (name: ParentListener, opt1: any, opt2?: any) => {
297
+ cancel: () => void;
298
+ };
299
+ once: (name: ParentListener, opt1: any, opt2?: any) => {
300
+ cancel: () => void;
301
+ };
294
302
  };
295
303
  expose: {
296
304
  connectMicroApp: (opt: microAppsDataItem) => Promise<void>;
305
+ disconnectMicroApp: (microAppName: string) => void;
297
306
  };
298
307
  event: Emitter<Event_3>;
299
308
  };
@@ -305,7 +314,9 @@ declare const channelItem_3: {
305
314
  }>, opt?: {
306
315
  notMerge?: boolean;
307
316
  } | undefined) => void;
308
- get: (keys?: "appInfo"[] | undefined) => {
317
+ get: (keys?: "appInfo"[] | undefined, options?: {
318
+ clone?: boolean;
319
+ } | undefined) => {
309
320
  appInfo: MicroAppItem;
310
321
  };
311
322
  watch: (cb: (newData: {
@@ -315,16 +326,25 @@ declare const channelItem_3: {
315
326
  }) => any, watchKeys?: "appInfo"[] | undefined) => () => void;
316
327
  };
317
328
  cors: {
318
- send: (key: ParentListener_2, data?: any) => Promise<any>;
319
- on: (name: ChildernListener_2, opt1?: any, opt2?: any) => any;
320
- once: (name: ChildernListener_2, opt1?: any, opt2?: any) => any;
329
+ send: (key: ParentListener_2, data?: any) => Promise<any[]>;
330
+ on: (name: ChildernListener_2, opt1?: any, opt2?: any) => {
331
+ cancel: () => void;
332
+ };
333
+ once: (name: ChildernListener_2, opt1?: any, opt2?: any) => {
334
+ cancel: () => void;
335
+ };
321
336
  };
322
337
  event: Emitter<Event_4>;
323
338
  };
324
339
 
325
340
  declare type ChildernListener = 'layoutDataChange' | 'syncRouter' | 'customEventFromMain';
326
341
 
327
- declare type ChildernListener_2 = 'layoutDataChange' | 'syncRouter' | 'customEventFromMain';
342
+ declare type ChildernListener_2 = 'layoutDataChange' | 'syncRouter' | 'customEventFromMain' | 'customEventFromMicro';
343
+
344
+ /**
345
+ * 清除实例的所有 bus 数据
346
+ */
347
+ export declare const clearInstanceBus: (instanceId: string) => void;
328
348
 
329
349
  declare type ContainerChannelType = {
330
350
  container: typeof channelItem;
@@ -349,6 +369,9 @@ declare type ContainerInitOptions = {
349
369
 
350
370
  /** 预加载配置 */
351
371
  preload?: PreloadConfig
372
+
373
+ /** 菜单宽度配置,可以是数字(像素)或字符串(如 '200px', '15rem')*/
374
+ menuWidth?: number | string
352
375
  }
353
376
 
354
377
  /** 容器初始化方法的结果 */
@@ -368,10 +391,78 @@ declare type ContainerResult = {
368
391
 
369
392
  export declare const createContainer: (opt?: ContainerInitOptions) => Promise<ContainerResult>;
370
393
 
394
+ /**
395
+ * 实例间通信
396
+ * 允许不同实例的应用之间通信
397
+ */
398
+ export declare const createCrossBus: () => {
399
+ /**
400
+ * 向指定实例发送消息
401
+ */
402
+ send: (targetInstanceId: string, targetChannel: string, eventName: string, data?: any) => void;
403
+ /**
404
+ * 监听来自其他实例的消息
405
+ */
406
+ on: (currentInstanceId: string, channelName: string, eventName: string, cb: Function) => () => void;
407
+ };
408
+
409
+ /**
410
+ * 创建带实例隔离的 bus
411
+ */
412
+ export declare const createInstanceBus: (instanceId: string) => <Data>(name: string, data?: Data) => {
413
+ data: {
414
+ set: (payload: Partial<any>, opt?: {
415
+ notMerge?: boolean;
416
+ } | undefined) => void;
417
+ get: (keys?: (string | number | symbol)[] | undefined) => any;
418
+ watch: (cb: (newData: any, oldData: any) => void, watchKeys?: (string | number | symbol)[] | undefined) => () => void;
419
+ };
420
+ event: {
421
+ on: (eventName: string, cb: Function) => void;
422
+ emit: (eventName: string, ...args: any[]) => void;
423
+ off: (eventName: string, cb?: Function) => void;
424
+ };
425
+ cors: {
426
+ send: (targetName: string, eventName: string, data?: any) => void;
427
+ on: (eventName: string, cb: Function) => () => void;
428
+ };
429
+ };
430
+
371
431
  export declare const createMainApp: (opt?: MainAppContainerInitOptions) => Promise<ContainerResult>;
372
432
 
373
433
  export declare const createMicroApp: (opt?: MicroAppContainerInitOptions) => Promise<MicroAppContainerResult>;
374
434
 
435
+ /**
436
+ * 创建嵌套应用
437
+ */
438
+ export declare const createNestedApp: (opt?: NestedAppOptions) => Promise<NestedAppResult>;
439
+
440
+ /**
441
+ * 创建嵌套实例专用的iframe管理器
442
+ * 每个嵌套实例都有独立的iframe管理器
443
+ */
444
+ export declare const createNestedIframeManager: (options: NestedIframeManagerOptions) => {
445
+ setMountDom: (ele: Element | null) => void;
446
+ registerIframe: (id: string, config: any) => void;
447
+ loadIframe: (id: string, opt?: any) => Promise<void>;
448
+ hideIframe: (iframeId?: string) => void;
449
+ destroyIframe: (id: string) => void;
450
+ destroyAll: (clearListeners?: boolean) => void;
451
+ getIframeInfo: (id: string) => NestedIframeInfo | undefined;
452
+ checkIframeStatus: (id: string, status: LifeCycleKeyType_2 | LifeCycleKeyType_2[]) => boolean;
453
+ iframeEvent: Emitter< {
454
+ loading: any;
455
+ error: any;
456
+ registered: any;
457
+ mounted: any;
458
+ unmounted: any;
459
+ activated: any;
460
+ deactivated: any;
461
+ destroy: any;
462
+ }>;
463
+ getAllIframes: () => NestedIframeInfo[];
464
+ };
465
+
375
466
  declare type Event_2 = {
376
467
  /** 容器组件onMounted生命周期 */
377
468
  onMounted: any;
@@ -406,6 +497,99 @@ declare type Event_4 = {
406
497
  };
407
498
  } & Record<string, any>;
408
499
 
500
+ /**
501
+ * MFrame 实例管理器
502
+ * 支持多实例场景,每个实例拥有独立的 bus、iframe 管理等
503
+ */
504
+ export declare interface InstanceConfig {
505
+ /** 实例 ID(自动生成或手动指定) */
506
+ id?: string;
507
+ /** 实例类型 */
508
+ type: 'main' | 'nested';
509
+ /** 父实例 ID(用于嵌套场景) */
510
+ parentId?: string;
511
+ /** 实例名称(可选,用于调试) */
512
+ name?: string;
513
+ }
514
+
515
+ export declare interface InstanceInfo extends Required<InstanceConfig> {
516
+ /** 创建时间 */
517
+ createdAt: number;
518
+ /** 子实例 ID 列表 */
519
+ children: string[];
520
+ /** 实例数据 */
521
+ data: Map<string, any>;
522
+ }
523
+
524
+ export declare class InstanceManager {
525
+ private instances;
526
+ private currentInstanceId;
527
+ /**
528
+ * 创建新实例
529
+ */
530
+ createInstance(config: InstanceConfig): string;
531
+ /**
532
+ * 获取实例信息
533
+ */
534
+ getInstance(id: string): InstanceInfo | undefined;
535
+ /**
536
+ * 销毁实例
537
+ */
538
+ destroyInstance(id: string): void;
539
+ /**
540
+ * 设置当前活动实例
541
+ */
542
+ setCurrentInstance(id: string): void;
543
+ /**
544
+ * 获取当前活动实例 ID
545
+ */
546
+ getCurrentInstanceId(): string | null;
547
+ /**
548
+ * 获取实例数据
549
+ */
550
+ getInstanceData<T = any>(id: string, key: string): T | undefined;
551
+ /**
552
+ * 设置实例数据
553
+ */
554
+ setInstanceData(id: string, key: string, value: any): void;
555
+ /**
556
+ * 获取实例的所有子实例
557
+ */
558
+ getChildren(id: string): string[];
559
+ /**
560
+ * 获取实例的父实例
561
+ */
562
+ getParent(id: string): string | undefined;
563
+ /**
564
+ * 获取所有实例
565
+ */
566
+ getAllInstances(): InstanceInfo[];
567
+ /**
568
+ * 获取实例树结构
569
+ */
570
+ getInstanceTree(rootId?: string): any;
571
+ /**
572
+ * 打印实例树
573
+ */
574
+ printInstanceTree(): void;
575
+ /**
576
+ * 生成实例 ID
577
+ */
578
+ private generateInstanceId;
579
+ /**
580
+ * 检查实例是否存在
581
+ */
582
+ hasInstance(id: string): boolean;
583
+ /**
584
+ * 获取实例数量
585
+ */
586
+ getInstanceCount(): number;
587
+ /**
588
+ * 清除所有实例
589
+ */
590
+ clearAll(): void;
591
+ }
592
+
409
593
  declare enum LifeCycleKey {
410
594
  'registered' = 0,
411
595
  'loading' = 1,
@@ -417,8 +601,25 @@ declare enum LifeCycleKey {
417
601
  'error' = 7
418
602
  }
419
603
 
604
+ /**
605
+ * 嵌套实例专用的 iframe 管理器
606
+ * 支持独立的生命周期管理和跨实例通信
607
+ */
608
+ declare enum LifeCycleKey_2 {
609
+ 'registered' = 0,
610
+ 'loading' = 1,
611
+ 'mounted' = 2,
612
+ 'unmounted' = 3,
613
+ 'activated' = 4,
614
+ 'deactivated' = 5,
615
+ 'destroy' = 6,
616
+ 'error' = 7
617
+ }
618
+
420
619
  declare type LifeCycleKeyType = keyof typeof LifeCycleKey;
421
620
 
621
+ declare type LifeCycleKeyType_2 = keyof typeof LifeCycleKey_2;
622
+
422
623
  declare type MainAppChannelType = {
423
624
  mainApp: typeof channelItem_2;
424
625
  };
@@ -487,6 +688,43 @@ declare type NavItem = {
487
688
  [key: string]: any
488
689
  }
489
690
 
691
+ export declare interface NestedAppOptions extends Omit<MainAppContainerInitOptions, 'type'> {
692
+ /** 父实例 ID(可选,自动检测) */
693
+ parentInstanceId?: string;
694
+ /** 嵌套实例名称 */
695
+ instanceName?: string;
696
+ /** 是否启用调试日志 */
697
+ debug?: boolean;
698
+ /** 是否隔离路由(true: 嵌套实例路由独立,不与浏览器URL同步;false: 路由同步到URL) */
699
+ isolateRouter?: boolean;
700
+ }
701
+
702
+ export declare interface NestedAppResult {
703
+ /** 实例 ID */
704
+ instanceId: string;
705
+ /** 实例 bus */
706
+ bus: ReturnType<typeof createInstanceBus>;
707
+ /** 内容区挂载点 */
708
+ mountDom: HTMLDivElement;
709
+ /** 销毁实例 */
710
+ destroy: () => void;
711
+ }
712
+
713
+ declare interface NestedIframeInfo {
714
+ id: string;
715
+ config: any;
716
+ status: LifeCycleKeyType_2;
717
+ element: HTMLIFrameElement | null;
718
+ instanceId: string;
719
+ }
720
+
721
+ declare interface NestedIframeManagerOptions {
722
+ instanceId: string;
723
+ debug?: boolean;
724
+ mountDom?: Element | null;
725
+ layoutData?: any;
726
+ }
727
+
490
728
  declare type ParentListener = 'getMicroFrameRect' | 'reportRouter' | 'microAppStickStatus' | 'customEventFromMicro';
491
729
 
492
730
  declare type ParentListener_2 = 'getMicroFrameRect' | 'reportRouter' | 'microAppStickStatus' | 'customEventFromMicro';
@@ -794,6 +1032,11 @@ export declare const useIframePreload: () => {
794
1032
  };
795
1033
  };
796
1034
 
1035
+ /**
1036
+ * 获取实例管理器
1037
+ */
1038
+ export declare const useInstanceManager: () => InstanceManager;
1039
+
797
1040
  /**
798
1041
  * 获取性能监控实例
799
1042
  */