@das-fed/mframe 0.0.31 → 0.0.32

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