@zhongguo168a/yxeditor-common 0.0.17 → 0.0.19

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/dist/index.d.ts CHANGED
@@ -207,24 +207,6 @@ declare class Timer {
207
207
  }
208
208
  declare const timer: Timer;
209
209
 
210
- declare class ControllerSet {
211
- constructor(mod: IModule);
212
- has(name: string): boolean;
213
- add(controller: IController): void;
214
- createAndEnable(name: string, ...args: any[]): void;
215
- create(name: string, ...args: any[]): void;
216
- remove(name: string): void;
217
- disable(name: string): void;
218
- enable(name: string): void;
219
- enableAll(): void;
220
- disableAll(): void;
221
- dispose(): void;
222
- registerCreator(name: string, creator: (...args: any[]) => IController): void;
223
- protected _creator: {};
224
- protected _mod: IModule;
225
- private data;
226
- }
227
-
228
210
  /**
229
211
  * 事件
230
212
  */
@@ -367,605 +349,250 @@ declare class EventManager implements IEventManager {
367
349
  */
368
350
  declare const eventmgr: EventManager;
369
351
 
370
- /**
371
- * 一个简单的功能/库模块
372
- */
373
- interface IModuleSample {
374
- }
375
- interface IModule {
376
- controllers: ControllerSet;
377
- }
378
- declare class Module extends EventManager implements IModule {
379
- constructor();
380
- get controllers(): ControllerSet;
381
- private _controllers;
382
- }
383
-
384
- interface IController {
385
- get name(): string;
386
- get module(): IModule;
387
- init(core: IModule): any;
388
- enable(): any;
389
- disable(): any;
390
- dispose(): any;
391
- }
392
- declare class Controller {
393
- constructor(name: string);
394
- init(core: IModule): void;
395
- enable(): void;
396
- disable(): void;
397
- dispose(): void;
398
- get name(): string;
399
- get module(): IModule;
400
- get isEnable(): boolean;
401
- protected _module: IModule;
402
- protected _name: string;
403
- protected _enabled: boolean;
404
- }
405
-
406
- interface IModel {
407
- get module(): IModule;
408
- }
409
- declare class SimpleModel {
410
- constructor(mod: IModule);
411
- get core(): IModule;
412
- protected _mod: any;
413
- }
414
- declare class Model extends EventManager {
415
- constructor(core?: IModule);
416
- get module(): IModule;
417
- protected _module: any;
418
- }
419
-
420
- interface IExtend {
421
- get module(): IModule;
422
- }
423
-
424
- declare class Factory {
425
- _controllers: {
426
- [key: string]: (mod: IModule) => IController;
427
- };
428
- _extends: {
429
- [key: string]: (mod: IModule, ...args: any) => IExtend;
430
- };
431
- registerController(name: string, creator: (mod: IModule, ...args: any) => IController): void;
432
- registerExtend(name: string, creator: (mod: IModule, ...args: any) => IExtend): void;
433
- createController(name: string, mod: IModule): IController;
434
- createExtend(name: string, mod: IModule, ...args: any[]): IExtend;
352
+ declare class TreeIterator {
353
+ break(): void;
354
+ isBreak(): boolean;
355
+ protected _isBreak: any;
435
356
  }
436
-
437
- /**
438
- * 视图的路由值, 保存视图的信息
439
- * 规则: path/search
440
- * path = /a/b/c
441
- * search = ?key=val&key=val
442
- */
443
- declare class Route {
444
- constructor(route: string);
445
- recycle(): void;
357
+ interface ITreeListItem {
446
358
  /**
447
- * 获取调用链
448
- * 例如 a/b/c,返回 a/b/c -> a/b -> a
359
+ * 路径
449
360
  */
450
- getLink(): Route[];
451
- protected static data: any;
452
- static getData(route: string): Route;
453
- toLoaction(): Location;
361
+ path: string;
454
362
  /**
455
- * @constructor
363
+ * 自定义数据
456
364
  */
457
- NewRoute(): Route;
365
+ data?: any;
458
366
  /**
459
- * @constructor
367
+ * 功能性标签,用于开发组件时,记录组件的状态。例如title, icon, 显示树的组件,需要 expanded,selected标签
460
368
  */
461
- NewRoutePath(): Route;
369
+ tags?: {
370
+ [key: string]: any;
371
+ };
462
372
  /**
463
- * 新建一个带参数的路由
464
- * @param params
373
+ * 是否树叶
465
374
  */
466
- NewRouteParam(params: any): Route;
467
- toString(): string;
468
- get path(): string;
469
- get parentPath(): string;
470
- get params(): any;
471
- get search(): string;
472
- set search(value: string);
473
- get name(): string;
375
+ isLeaf: boolean;
376
+ }
377
+ declare class TreeNode<T = any> {
378
+ get root(): TreeRoot;
474
379
  /**
475
- * path/search
380
+ * 根节点
476
381
  */
477
- get key(): string;
478
- private _path;
479
- private _parentPath;
480
- private _search;
481
- private _name;
482
- private _params;
483
- protected _route: string;
484
- }
485
-
486
- declare class DictIterator {
487
- break(): void;
488
- isBreak(): boolean;
489
- protected _isBreak: any;
490
- }
491
- declare class Dictionary<K = string, V = any> {
492
- constructor(data?: any);
493
- reset(data: any): void;
494
- protected _reset(data: any, size?: number): void;
495
- getData(): any;
382
+ protected _root: TreeRoot;
496
383
  /**
497
- * 如果使用了 onSet or onDelete,需要注意清理
384
+ * 编号
498
385
  */
499
- clear(): void;
386
+ uuid: string;
500
387
  /**
501
- * 克隆自身所有项到【target】对象,并返回【target】对象
502
- * @param target
388
+ * 编号
503
389
  */
504
- clone(target: this): this;
505
- resetByDict(dict: Dictionary): void;
506
- onSet(caller: any, handler: (key: K, value: V) => void): void;
507
- onDelete(caller: any, handler: (key: K, value: V) => void): void;
390
+ id: string;
508
391
  /**
509
- * 设置键值对,如果没有发生变化,不会触发onSet函数
510
- * @param key
511
- * @param value
392
+ * 自定义数据
512
393
  */
513
- set(key: K, value: V): void;
514
- private setData;
515
- setByMap(m: any): void;
516
- addDictionary(other: Dictionary<K, V>): void;
517
- deleteDictionary(other: Dictionary<K, V>): void;
394
+ data: T;
518
395
  /**
519
- * 如果不存在,返回 undefined
520
- * @param key
396
+ * 是否树叶
521
397
  */
522
- get(key: K): V;
523
- exist(key: K): boolean;
524
- delete(key: K): void;
525
- private deleteData;
526
- exists(key: K): boolean;
527
- length(): number;
528
- pop(key: K): [V, boolean];
529
- isEmpty(): boolean;
530
- items(): V[];
531
- keys(): K[];
398
+ isLeaf: boolean;
532
399
  /**
533
- *
534
- * @param handler 可以使用【iterator】中断遍历
535
- * @return iterator 获取是否中断了
400
+ * 功能性标签,用于开发组件时,记录组件的状态。例如title, icon, 显示树的组件,需要 expanded,selected标签
536
401
  */
537
- forEach(handler: (key: K, val: V, iterator: DictIterator) => void): DictIterator;
402
+ tags: {
403
+ [key: string]: any;
404
+ };
538
405
  /**
406
+ * 深度
539
407
  */
540
- first(): V | undefined;
408
+ get depth(): number;
409
+ private _depth;
541
410
  /**
542
- * @param handler 返回true结束迭代
411
+ * 父节点
543
412
  */
544
- firstByCondition(handler: (key: K, val: V) => boolean): V | undefined;
413
+ parent: TreeNode;
545
414
  /**
546
- * 移除符合条件的项
547
- * @param cond 可以使用【iterator】中断遍历
415
+ * 子节点
548
416
  */
549
- removeByCondition(cond: (key: K, val: V, iterator: DictIterator) => boolean): void;
417
+ children: TreeNode[];
550
418
  /**
551
- * 查找符合条件的项保存到【target】对象中,并返回【target】对象
552
- * @param cond 可以使用【iterator】中断遍历
553
- * @param target 存到目标对象中
419
+ * 设置根
420
+ * @param val
554
421
  */
555
- findByCondition(cond: (key: K, val: V, iterator: DictIterator) => boolean, target: Dictionary): this;
556
- groupByCondition(createKey: (key: K, val: V) => string, ITEM_CLASS?: any): {
422
+ setRoot(val: TreeRoot): void;
423
+ getTags(): {
557
424
  [key: string]: any;
558
425
  };
559
- protected size: number;
560
- private _data;
561
- private _onSet;
562
- private _onDelete;
563
- private _onSetCaller;
564
- private _onDeleteCaller;
565
- }
566
-
567
- declare class ListIterator {
568
- break(): void;
569
- isBreak(): boolean;
570
- protected _isBreak: any;
571
- }
572
- declare class List<T = any> {
573
- constructor();
574
- onSet(caller: any, handler: (value: T) => void): void;
575
- onDelete(caller: any, handler: (value: T) => void): void;
576
- firstByCondition(conf: (index: number, item: T) => boolean): [number, T];
577
- lastByCondition(conf: (index: number, item: T) => boolean): [number, T];
578
- forEach(handler: (index: number, item: T, iterator: ListIterator) => void): ListIterator;
426
+ getTag(name: string): any;
427
+ removeTag(name: string): void;
428
+ setTag(name: string, value: any): void;
429
+ constructor(id: string, isLeaf?: boolean);
430
+ addChild(val: TreeNode): void;
431
+ getChildIndex(val: TreeNode): number;
432
+ insertChild(val: TreeNode, index: number): void;
433
+ removeChild(val: TreeNode): void;
434
+ removeChildren(): void;
435
+ get name(): string;
436
+ setDepth(val: number): void;
437
+ containsById(id: string): boolean;
579
438
  /**
580
- * 移除符合条件的项, 从后往前遍历
581
- * @param cond 可以使用【iterator】中断遍历
582
- * @param removedList 设置后,可获得被移除的项
439
+ * 通过编号获取子节点
440
+ * @param id
583
441
  */
584
- removeByCondition(cond: (index: number, val: T, iterator: ListIterator) => boolean, removedList?: List): this;
442
+ getChildById(id: string): TreeNode;
585
443
  /**
586
- * 查找符合条件的项保存到【target】对象中,并返回【target】对象
587
- * @param cond 可以使用【iterator】中断遍历
588
- * @param target 存到目标对象中
444
+ * 返回相邻的上一个节点
589
445
  */
590
- findByCondition(cond: (index: number, val: T, iterator: ListIterator) => boolean, target: List): this;
591
- pop(): T;
592
- shift(): T;
593
- first(): T;
594
- last(): T;
595
- removeAt(index: number): void;
596
- remove(item: T): void;
446
+ prevNode(): TreeNode;
597
447
  /**
598
- * 把【other】的项合并到自身
599
- * @param other
448
+ * 返回相邻的下一个节点
600
449
  */
601
- removeList(other: List<T>): void;
602
- sort(compareFn?: (a: T, b: T) => number): void;
603
- reverse(): void;
604
- clear(): void;
450
+ nextNode(): TreeNode;
605
451
  /**
606
- * 克隆自身所有项到【target】对象,并返回【target】对象
607
- * @param target
452
+ * 如果返回true则删除节点,包含当前节点
453
+ * @param f
608
454
  */
609
- clone(target: this): this;
610
- get length(): number;
611
- insertAt(index: number, ...item: T[]): void;
455
+ walkRemove(f: (node: TreeNode) => boolean): void;
456
+ private _walkRemove;
612
457
  /**
613
- * @param beforeItem
614
- * @param item
458
+ * 如果返回true则继续,包含当前节点
459
+ * @param f
460
+ * @param inChild
615
461
  */
616
- insertBefore(beforeItem: T, ...item: T[]): void;
462
+ walk(f: (node: TreeNode) => boolean, inChild?: (node: TreeNode) => boolean): void;
463
+ private _walk;
617
464
  /**
618
- * @param afterItem
619
- * @param item
465
+ * 从当前节点(包括)遍历父节点链,包含当前节点
466
+ * @param f
620
467
  */
621
- insertAfter(afterItem: T, ...item: T[]): void;
622
- at(index: number): T;
623
- set(index: number, item: T): void;
624
- indexOf(item: T): number;
625
- has(item: T): boolean;
626
- push(item: T): void;
468
+ walkParent(f: (node: TreeNode) => boolean): boolean;
627
469
  /**
628
- * 把【other】的项合并到自身
629
- * @param other
470
+ * 从当前节点往前遍历(深度),包含当前节点
471
+ * @param f
472
+ * @param inChild
630
473
  */
631
- pushList(other: List<T>): void;
632
- getData(): T[];
633
- resetData(val: T[]): void;
474
+ walkPrev(f: (node: TreeNode) => boolean, inChild?: (node: TreeNode) => boolean): any;
475
+ private _walkPrev;
476
+ dump(): void;
634
477
  /**
635
- * 随机获取【count】个项,并返回【target】对象
636
- * @param count
637
- * @param enableRepeat 允许重复
638
- * @param target
478
+ * 遍历节点,查找指定编号的节点
639
479
  */
640
- random(count: number, enableRepeat?: boolean, target?: List<T>): List<T>;
641
- protected callPush(value: any): void;
642
- protected callRemove(value: any): void;
643
- protected _data: any[];
644
- private _onSet;
645
- private _onDelete;
646
- private _onSetCaller;
647
- private _onDeleteCaller;
648
- }
649
-
650
- declare class UIObjectDict extends Dictionary<string, any | List> {
480
+ findById(id: string): TreeNode;
651
481
  /**
652
- * 获取唯一的
653
- * @param prefab
482
+ * 如果返回true则继续
483
+ * @param f
654
484
  */
655
- uniqueObject(prefab: Prefab): Node;
656
- removeObject(prefab: Prefab): void;
657
- popObject(prefab: Prefab): any;
658
- backObject(object: Node): void;
659
- protected getList(key: any): List;
660
- }
661
- declare var uidict: UIObjectDict;
662
-
663
- declare class ViewController {
664
- constructor(name: string);
665
- open(...args: any[]): void;
666
- close(): void;
667
- get objectDict(): UIObjectDict;
668
- get name(): string;
669
- protected _objectDict: UIObjectDict;
670
- private _name;
671
- }
672
-
673
- declare class PageController extends ViewController {
674
- constructor(routeName: string, config?: {
675
- layer?: string;
676
- tags?: string[];
677
- enableHistory?: boolean;
678
- });
679
- protected onOpening(page: Page): void;
680
- protected onOpened(page: Page): void;
681
- protected onClosing(page: Page): void;
682
- protected onClosed(page: Page): void;
683
- protected onRefresh(page: Page): void;
684
- openByRoute(route: Route): Page;
685
- private openPage;
686
- openComplete(page: Page): void;
687
- closeByRoute(route?: Route): Page;
688
- private closePage;
689
- closeComplete(page: Page): void;
690
- refresh(): void;
691
- get layer(): string;
692
- hasTags(tags: string[]): boolean;
693
- setLayer(name: string): this;
694
- setTags(tags: string[]): this;
695
- get lastPage(): Page;
696
- get route(): Route;
697
- get enableHistory(): boolean;
698
- protected _enableHistory: boolean;
699
- protected _route: Route;
700
- protected _lastPage: Page;
701
- protected _tags: {};
702
- protected _layer: string;
703
- }
704
- declare class PageControllerDict extends Dictionary<string, PageController> {
705
- getByName(name: string): PageController;
485
+ findOne(f: (node: TreeNode) => boolean): TreeNode;
486
+ private _findOne;
487
+ /**
488
+ * 通过路径获取节点
489
+ * 格式为 /path1/path2/...
490
+ * 如果 path == "/",则返回自身
491
+ * @param path
492
+ */
493
+ getNodeByPath(path: string): TreeNode;
494
+ protected getNodeByPathArr(pathArr: string[]): TreeNode;
495
+ getName(): string;
496
+ getPath(): string;
497
+ /**
498
+ * 如果返回true则继续
499
+ * @param f
500
+ */
501
+ find(f: (node: TreeNode) => boolean): TreeNode[];
502
+ private _find;
503
+ toRoot(): TreeRoot;
504
+ clone(): TreeNode;
505
+ protected cloneChildrenTo(node: TreeNode): void;
506
+ fixDepthAndRoot(depth: number, root: TreeRoot): void;
507
+ toString(): string;
706
508
  }
707
-
708
- declare enum PageState {
509
+ declare class TreeRoot<NODE = any> extends EventManager {
709
510
  /**
710
- * 关闭
511
+ * 添加数据节点
512
+ * dispatchParams = {node:TreeNode, parent:TreeNode|TreeRoot}
711
513
  */
712
- Closed = 0,
514
+ static EVENT_ADD: string;
713
515
  /**
714
- * 正在打开
516
+ * 移除数据节点
517
+ * dispatchParams = {node:TreeNode, parent:TreeNode|TreeRoot}
715
518
  */
716
- Opening = 1,
519
+ static EVENT_REMOVE: string;
717
520
  /**
718
- * 已打开
521
+ * 插入数据节点
522
+ * dispatchParams = {node:TreeNode, before:TreeNode}
719
523
  */
720
- Opened = 2,
524
+ static EVENT_INSERT: string;
721
525
  /**
722
- * 正在关闭
526
+ * 刷新数据节点
527
+ * dispatchParams = {node:TreeNode}
723
528
  */
724
- Closeing = 3
725
- }
726
- declare enum PageEvent {
727
- Opening = "opening",
728
- Opened = "opened",
729
- Closeing = "closeing",
730
- Closed = "closed",
731
- Stop = "stop"
732
- }
733
- declare class Page extends EventManager {
734
- constructor(controller: PageController, route: Route);
529
+ static EVENT_REFRESH: string;
735
530
  /**
736
- * 等待打开完成指令
531
+ * 设置数据时触发
532
+ * dispatchParams = {node:TreeNode}
737
533
  */
738
- waitOpenComplete(): void;
739
- waitCloseComplete(): void;
740
- openComplete(): void;
741
- closeComplete(): void;
742
- stop(reason: LinkError): void;
534
+ static EVENT_DATA_SET: string;
743
535
  /**
744
- * 等待发送的结果
745
- * 如果返回 null,表示主动取消 [cancel]
536
+ * 设置数据时触发
537
+ * dispatchParams = {node:TreeNode, tag:string, value:any}
746
538
  */
747
- wait(): Promise<this>;
748
- toString(): string;
749
- get objectDict(): UIObjectDict;
750
- protected _objectDict: UIObjectDict;
751
- protected _waitOpenComplete: boolean;
752
- protected _waitCloseComplete: boolean;
753
- get controller(): PageController;
754
- get route(): Route;
755
- cache: {};
756
- tags: {};
757
- layer: string;
758
- state: PageState;
759
- protected _controller: PageController;
760
- protected _route: Route;
761
- }
762
-
763
- /**
764
- * 视图管理器
765
- * 打开一个视图的时候,可能会听过加载资源,读取数据,调整布局,切换特效等处理,所以使用视图模式封装视图打开关闭的逻辑
766
- */
767
- declare class PageLayer {
768
- name: string;
769
- constructor(name: string);
770
- close(): void;
539
+ static EVENT_TAGS_SET: string;
540
+ static create(): TreeRoot<any>;
771
541
  /**
772
- * 当前的页面
542
+ * 通过列表生成一个树结构
543
+ * @param items
544
+ * @param existed 列表将添加的已经存在的树结构
773
545
  */
774
- currentPage: Page;
775
- }
776
-
777
- declare class PageList extends List<Page> {
778
- }
779
- declare class PageRepo extends PageList {
546
+ static createByList(items: ITreeListItem[], existed?: TreeRoot): TreeRoot;
547
+ static sortChildrenByName(node: TreeNode, des?: boolean): void;
780
548
  constructor();
781
- openByString(route: string): Page;
549
+ setNodeData(node: TreeNode, data: any): void;
550
+ setNodeTags(node: TreeNode, tag: string, value: any, force?: boolean): void;
551
+ getNodeByPath(path: string): TreeNode;
552
+ makeNodeByPath(path: string): TreeNode;
782
553
  /**
783
- * 打开页面
784
- * 一个路由代表一个页面
785
- * @param route
554
+ * 添加节点,按照 node.path 添加到正确的位置
555
+ * @param node
556
+ * @param parentPath 如果父节点路径为 "", 则添加到起源节点
557
+ * @param autoCreateParent 如果父节点不存在,自动创建
786
558
  */
787
- open(route: Route): Page;
788
- close(route: Route): void;
559
+ addNode(node: TreeNode, parentPath?: string, autoCreateParent?: boolean): void;
560
+ removeNode(node: TreeNode): void;
561
+ removeChildren(node: TreeNode): void;
562
+ insertNode(node: TreeNode, before: TreeNode, resetId?: boolean): void;
563
+ walk(f: (node: TreeNode) => boolean, inChild?: (node: TreeNode) => boolean): void;
564
+ walkPrev(f: (node: TreeNode) => boolean, inChild?: (node: TreeNode) => boolean): void;
789
565
  /**
790
- * 如果页面存在,则刷新
791
- * @param route
566
+ * 派发 refresh 消息
567
+ * @param node
792
568
  */
793
- refresh(route: Route): void;
569
+ refresh(node: TreeNode): void;
794
570
  /**
795
- * 历史记录
571
+ * 克隆当前的树结
572
+ * * 新的tags克隆旧的data
573
+ * * 新的data指向旧的data
796
574
  */
797
- getHistory(): Route[];
798
- back(): void;
799
- getByRoute(route: Route): Page;
800
- listByTags(tags: string[]): PageList;
801
- getLayerMain(): PageLayer;
575
+ clone(): TreeRoot;
576
+ toString(): string;
577
+ createNode(id: string, isLeaf?: boolean): TreeNode;
802
578
  /**
803
- * @param name
804
- */
805
- getLayer(name: string): PageLayer;
806
- protected getOrNewLayer(name: string): PageLayer;
807
- getController(route: Route): PageController;
808
- registerController(ctrl: PageController): void;
809
- get objectDict(): UIObjectDict;
810
- protected _objectDict: UIObjectDict;
811
- protected _indexLayer: {};
812
- protected _indexRoute: {};
813
- protected _history: Route[];
814
- protected _ctrlDict: PageControllerDict;
815
- }
816
- declare const pagerepo: PageRepo;
817
-
818
- /**
819
- * 事件字符串分隔符
820
- */
821
-
822
- /**
823
- * 回调列表
824
- */
825
- declare class CallbackList<PARAMS = any> {
826
- constructor();
827
- addListener(listener: Listener): void;
828
- removeListener(listener: Listener): void;
829
- /**
830
- */
831
- create(): Listener<PARAMS>;
832
- /**
833
- * 如果监听器已经不存在,则创建
834
- * @param ident
835
- */
836
- createByIdent(ident: any): Listener<PARAMS>;
837
- removeByIdent(ident: any): void;
838
- removeByCaller(caller: any): void;
839
- getByIdent(ident: any): Listener;
840
- /**
841
- * 派发事件
842
- * @param params 事件参数
843
- * @param subIdent
844
- */
845
- dispatch(params?: PARAMS, subIdent?: string): void;
846
- protected _data: List<Listener<any>>;
847
- protected _indexIdent: {};
848
- }
849
-
850
- declare class Listener<PARAMS = any> {
851
- static create(ident?: string): Listener<any>;
852
- constructor(ident?: string);
853
- getCaller(): any;
854
- setCaller(caller: any): this;
855
- setSubIdent(val: string): this;
856
- setCondition(condition: (listener: Listener<PARAMS>) => boolean): this;
857
- setHandler(handler: (listener: Listener<PARAMS>) => void): this;
858
- setOnParams(val: any): this;
859
- getIdent(): string;
860
- on(): this;
861
- off(): this;
862
- isOn(): boolean;
863
- remove(): void;
864
- /**
865
- * 内部使用
866
- * @param params
867
- * @param subIdent 子编号
868
- */
869
- _dispatch(params: PARAMS, subIdent?: string): void;
870
- getOnParams(): any;
871
- getParams(): PARAMS;
872
- protected onParams: any;
873
- protected params: PARAMS;
874
- protected ident: string;
875
- protected _subIdent: string;
876
- protected source: CallbackList;
877
- protected _handler: (any: any) => void;
878
- protected _condition: (any: any) => boolean;
879
- protected caller: any;
880
- protected _isOn: boolean;
881
- }
882
-
883
- /**
884
- * 事件字符串分隔符
885
- */
886
-
887
- /**
888
- * 事件派发器
889
- */
890
- declare class Dispatcher implements ISchedulable {
891
- constructor(name?: string);
892
- dispose(): void;
893
- create(type: string, listener: Listener): void;
894
- remove(type: string, listener: Listener): void;
895
- getByIdent(type: string, ident: string): Listener;
896
- /**
897
- * @param type
898
- * @param ident
899
- */
900
- createByIdent(type: string, ident: string): Listener;
901
- /**
902
- * 派发事件
903
- * @param eventType 事件类型
904
- * @param params 事件参数
905
- */
906
- dispatch(eventType: string, params?: any): void;
907
- protected getList(type: string): CallbackList;
908
- id?: string;
909
- uuid?: string;
910
- name: string;
911
- protected isDispose: boolean;
912
- protected typeToList: Dictionary<string, CallbackList<any>>;
913
- }
914
-
915
- declare class CallbackItem {
916
- listener: Function;
917
- caller: any;
918
- once: boolean;
919
- }
920
- declare class SampleCallbackList {
921
- constructor();
922
- dispose(): void;
923
- has(caller: any, listener: Function): boolean;
924
- protected getItem(caller: any, listener: Function): CallbackItem;
925
- /**
926
- * 监听事件,如果监听已经存在则返回
927
- * @param caller
928
- * @param listener 为了性能考虑, event使用了对象池处理。因此处理函数不应该保存event的引用。如有需要,可通过新建对象或Event.Clone()实现
929
- */
930
- on(caller: any, listener: (ctx: this, params?: any) => void): CallbackItem;
931
- once(caller: any, listener: (ctx: this, params?: any) => void): CallbackItem;
932
- protected offItem(item: CallbackItem): void;
933
- off(caller: any, listener: Function): void;
934
- offAll(type?: string): void;
935
- offAllCaller(caller: any): void;
936
- /**
937
- * 派发事件
938
- * @param params 事件参数
579
+ * origin的第一个child
939
580
  */
940
- dispatch(params?: any): void;
941
- protected _callbackItems: CallbackItem[];
581
+ get firstNode(): TreeNode;
582
+ origin: TreeNode;
942
583
  }
943
-
944
- declare class AssetURI {
945
- name: string;
946
- constructor(name: string);
947
- loadType: number;
948
- uuid: string;
949
- path: string;
950
- bundle: string;
584
+ declare class TreeRootPlugin {
585
+ root: TreeRoot;
951
586
  }
952
- declare class XAssetManager {
953
- getAsset(uri: string): any;
954
- getAssetByUUID(uuid: string): any;
955
- getRoot(): AssetManager;
587
+ declare class TreeNodePlugin {
588
+ node: TreeNode;
956
589
  }
957
- declare let assetx: XAssetManager;
958
590
 
959
- declare class TreeIterator {
960
- break(): void;
961
- isBreak(): boolean;
962
- protected _isBreak: any;
963
- }
964
- interface ITreeListItem {
591
+ interface IListItem {
965
592
  /**
966
- * 路径
593
+ * 编号
967
594
  */
968
- path: string;
595
+ id: string;
969
596
  /**
970
597
  * 自定义数据
971
598
  */
@@ -976,245 +603,182 @@ interface ITreeListItem {
976
603
  tags?: {
977
604
  [key: string]: any;
978
605
  };
979
- /**
980
- * 是否树叶
981
- */
982
- isLeaf: boolean;
983
606
  }
984
- declare class TreeNode<T = any> {
985
- get root(): TreeRoot;
607
+ declare class ListNode {
608
+ static create(id: string, data?: any): ListNode;
609
+ constructor();
610
+ root: ListSource;
611
+ uuid: string;
612
+ id: string;
613
+ data: any;
614
+ tags: {};
615
+ getTags(): {
616
+ [key: string]: any;
617
+ };
618
+ setTags(tags: {
619
+ [key: string]: any;
620
+ }): void;
621
+ getTag(name: string): any;
622
+ setTag(name: string, value: any): void;
623
+ }
624
+ declare class ListSource extends EventManager {
986
625
  /**
987
- * 根节点
626
+ * 通过数组创建 ListSource。ListSource的id自动生成。如果需要指定编号,可设置 idCreator
627
+ * @param arr
628
+ * @param idCreator
988
629
  */
989
- protected _root: TreeRoot;
630
+ static createByArray(arr: any[], idCreator?: (item: any) => string): ListSource;
631
+ static createByListItem(arr: IListItem[], target?: ListSource): any;
990
632
  /**
991
- * 编号
633
+ * 设置数据时触发
634
+ * dispatchParams = {node:ListNode}
992
635
  */
993
- uuid: string;
636
+ static EVENT_ADD: string;
994
637
  /**
995
- * 编号
638
+ * 设置数据时触发
639
+ * dispatchParams = {node:ListNode, index:number}
996
640
  */
997
- id: string;
641
+ static EVENT_REMOVE: string;
998
642
  /**
999
- * 自定义数据
643
+ * 设置数据时触发
1000
644
  */
1001
- data: T;
645
+ static EVENT_REMOVE_ALL: string;
1002
646
  /**
1003
- * 是否树叶
647
+ * 刷新数据节点
648
+ * dispatchParams = {node:ListNode}
1004
649
  */
1005
- isLeaf: boolean;
650
+ static EVENT_REFRESH: string;
1006
651
  /**
1007
- * 功能性标签,用于开发组件时,记录组件的状态。例如title, icon, 显示树的组件,需要 expanded,selected标签
652
+ * 设置数据时触发
653
+ * dispatchParams = nodes: [ListNode], indexs: [number]
1008
654
  */
1009
- tags: {
1010
- [key: string]: any;
1011
- };
655
+ static EVENT_SWAP: string;
1012
656
  /**
1013
- * 深度
657
+ * 设置数据时触发
658
+ * dispatchParams = {node:ListNode, data:any}
1014
659
  */
1015
- get depth(): number;
1016
- private _depth;
660
+ static EVENT_DATA_SET: string;
1017
661
  /**
1018
- * 父节点
662
+ * 设置数据时触发
663
+ * dispatchParams = {node:ListNode, tag:string, value:any}
1019
664
  */
1020
- parent: TreeNode;
665
+ static EVENT_TAGS_SET: string;
666
+ protected _identFunc: (node: ListNode) => boolean;
667
+ at(index: number): ListNode;
668
+ first(): ListNode;
669
+ last(): ListNode;
670
+ length(): number;
1021
671
  /**
1022
- * 子节点
672
+ * 添加项,无法添加相同的项
673
+ * @param node
674
+ * @param enableDispatch 默认为true
1023
675
  */
1024
- children: TreeNode[];
676
+ add(node: ListNode, enableDispatch?: boolean): void;
677
+ getById(id: string): ListNode;
678
+ remove(node: ListNode): void;
679
+ removeAll(): void;
680
+ swap(a: ListNode, b: ListNode): void;
681
+ contains(node: ListNode): boolean;
682
+ containsById(id: string): boolean;
683
+ indexOf(node: ListNode): number;
684
+ indexOfById(id: string): number;
685
+ setData(node: ListNode, data: any): void;
686
+ setNodeTags(node: ListNode, tag: string, value: any): void;
1025
687
  /**
1026
- * 设置根
1027
- * @param val
1028
- */
1029
- setRoot(val: TreeRoot): void;
1030
- getTags(): {
1031
- [key: string]: any;
1032
- };
1033
- getTag(name: string): any;
1034
- removeTag(name: string): void;
1035
- setTag(name: string, value: any): void;
1036
- constructor(id: string, isLeaf?: boolean);
1037
- addChild(val: TreeNode): void;
1038
- getChildIndex(val: TreeNode): number;
1039
- insertChild(val: TreeNode, index: number): void;
1040
- removeChild(val: TreeNode): void;
1041
- removeChildren(): void;
1042
- get name(): string;
1043
- setDepth(val: number): void;
1044
- containsById(id: string): boolean;
1045
- /**
1046
- * 通过编号获取子节点
1047
- * @param id
1048
- */
1049
- getChildById(id: string): TreeNode;
1050
- /**
1051
- * 返回相邻的上一个节点
1052
- */
1053
- prevNode(): TreeNode;
1054
- /**
1055
- * 返回相邻的下一个节点
1056
- */
1057
- nextNode(): TreeNode;
1058
- /**
1059
- * 如果返回true则删除节点,包含当前节点
1060
- * @param f
1061
- */
1062
- walkRemove(f: (node: TreeNode) => boolean): void;
1063
- private _walkRemove;
1064
- /**
1065
- * 如果返回true则继续,包含当前节点
1066
- * @param f
1067
- * @param inChild
1068
- */
1069
- walk(f: (node: TreeNode) => boolean, inChild?: (node: TreeNode) => boolean): void;
1070
- private _walk;
1071
- /**
1072
- * 从当前节点(包括)遍历父节点链,包含当前节点
1073
- * @param f
1074
- */
1075
- walkParent(f: (node: TreeNode) => boolean): boolean;
1076
- /**
1077
- * 从当前节点往前遍历(深度),包含当前节点
1078
- * @param f
1079
- * @param inChild
1080
- */
1081
- walkPrev(f: (node: TreeNode) => boolean, inChild?: (node: TreeNode) => boolean): any;
1082
- private _walkPrev;
1083
- dump(): void;
1084
- /**
1085
- * 遍历节点,查找指定编号的节点
1086
- */
1087
- findById(id: string): TreeNode;
1088
- /**
1089
- * 如果返回true则继续
1090
- * @param f
1091
- */
1092
- findOne(f: (node: TreeNode) => boolean): TreeNode;
1093
- private _findOne;
1094
- /**
1095
- * 通过路径获取节点
1096
- * 格式为 /path1/path2/...
1097
- * 如果 path == "/",则返回自身
1098
- * @param path
1099
- */
1100
- getNodeByPath(path: string): TreeNode;
1101
- protected getNodeByPathArr(pathArr: string[]): TreeNode;
1102
- getName(): string;
1103
- getPath(): string;
1104
- /**
1105
- * 如果返回true则继续
1106
- * @param f
688
+ * 派发 refresh 消息
689
+ * @param node
1107
690
  */
1108
- find(f: (node: TreeNode) => boolean): TreeNode[];
1109
- private _find;
1110
- toRoot(): TreeRoot;
1111
- clone(): TreeNode;
1112
- protected cloneChildrenTo(node: TreeNode): void;
1113
- fixDepthAndRoot(depth: number, root: TreeRoot): void;
1114
- toString(): string;
691
+ refresh(node: ListNode): void;
692
+ walk(f: (node: ListNode) => boolean): boolean;
693
+ walkPrev(node: ListNode, f: (node: ListNode) => boolean): boolean;
694
+ get data(): any[];
695
+ private _data;
1115
696
  }
1116
- declare class TreeRoot<NODE = any> extends EventManager {
1117
- /**
1118
- * 添加数据节点
1119
- * dispatchParams = {node:TreeNode, parent:TreeNode|TreeRoot}
1120
- */
1121
- static EVENT_ADD: string;
1122
- /**
1123
- * 移除数据节点
1124
- * dispatchParams = {node:TreeNode, parent:TreeNode|TreeRoot}
1125
- */
1126
- static EVENT_REMOVE: string;
1127
- /**
1128
- * 插入数据节点
1129
- * dispatchParams = {node:TreeNode, before:TreeNode}
1130
- */
1131
- static EVENT_INSERT: string;
1132
- /**
1133
- * 刷新数据节点
1134
- * dispatchParams = {node:TreeNode}
1135
- */
1136
- static EVENT_REFRESH: string;
1137
- /**
1138
- * 设置数据时触发
1139
- * dispatchParams = {node:TreeNode}
1140
- */
1141
- static EVENT_DATA_SET: string;
697
+
698
+ declare class DictIterator {
699
+ break(): void;
700
+ isBreak(): boolean;
701
+ protected _isBreak: any;
702
+ }
703
+ declare class Dictionary<K = string, V = any> {
704
+ constructor(data?: any);
705
+ reset(data: any): void;
706
+ protected _reset(data: any, size?: number): void;
707
+ getData(): any;
1142
708
  /**
1143
- * 设置数据时触发
1144
- * dispatchParams = {node:TreeNode, tag:string, value:any}
709
+ * 如果使用了 onSet or onDelete,需要注意清理
1145
710
  */
1146
- static EVENT_TAGS_SET: string;
1147
- static create(): TreeRoot<any>;
711
+ clear(): void;
1148
712
  /**
1149
- * 通过列表生成一个树结构
1150
- * @param items
1151
- * @param existed 列表将添加的已经存在的树结构
713
+ * 克隆自身所有项到【target】对象,并返回【target】对象
714
+ * @param target
1152
715
  */
1153
- static createByList(items: ITreeListItem[], existed?: TreeRoot): TreeRoot;
1154
- static sortChildrenByName(node: TreeNode, des?: boolean): void;
1155
- constructor();
1156
- setNodeData(node: TreeNode, data: any): void;
1157
- setNodeTags(node: TreeNode, tag: string, value: any, force?: boolean): void;
1158
- getNodeByPath(path: string): TreeNode;
1159
- makeNodeByPath(path: string): TreeNode;
716
+ clone(target: this): this;
717
+ resetByDict(dict: Dictionary): void;
718
+ onSet(caller: any, handler: (key: K, value: V) => void): void;
719
+ onDelete(caller: any, handler: (key: K, value: V) => void): void;
1160
720
  /**
1161
- * 添加节点,按照 node.path 添加到正确的位置
1162
- * @param node
1163
- * @param parentPath 如果父节点路径为 "", 则添加到起源节点
1164
- * @param autoCreateParent 如果父节点不存在,自动创建
721
+ * 设置键值对,如果没有发生变化,不会触发onSet函数
722
+ * @param key
723
+ * @param value
1165
724
  */
1166
- addNode(node: TreeNode, parentPath?: string, autoCreateParent?: boolean): void;
1167
- removeNode(node: TreeNode): void;
1168
- removeChildren(node: TreeNode): void;
1169
- insertNode(node: TreeNode, before: TreeNode, resetId?: boolean): void;
1170
- walk(f: (node: TreeNode) => boolean, inChild?: (node: TreeNode) => boolean): void;
1171
- walkPrev(f: (node: TreeNode) => boolean, inChild?: (node: TreeNode) => boolean): void;
725
+ set(key: K, value: V): void;
726
+ private setData;
727
+ setByMap(m: any): void;
728
+ addDictionary(other: Dictionary<K, V>): void;
729
+ deleteDictionary(other: Dictionary<K, V>): void;
1172
730
  /**
1173
- * 派发 refresh 消息
1174
- * @param node
731
+ * 如果不存在,返回 undefined
732
+ * @param key
1175
733
  */
1176
- refresh(node: TreeNode): void;
734
+ get(key: K): V;
735
+ exist(key: K): boolean;
736
+ delete(key: K): void;
737
+ private deleteData;
738
+ exists(key: K): boolean;
739
+ length(): number;
740
+ pop(key: K): [V, boolean];
741
+ isEmpty(): boolean;
742
+ items(): V[];
743
+ keys(): K[];
1177
744
  /**
1178
- * 克隆当前的树结
1179
- * * 新的tags克隆旧的data
1180
- * * 新的data指向旧的data
745
+ *
746
+ * @param handler 可以使用【iterator】中断遍历
747
+ * @return iterator 获取是否中断了
1181
748
  */
1182
- clone(): TreeRoot;
1183
- toString(): string;
1184
- createNode(id: string, isLeaf?: boolean): TreeNode;
749
+ forEach(handler: (key: K, val: V, iterator: DictIterator) => void): DictIterator;
1185
750
  /**
1186
- * origin的第一个child
1187
751
  */
1188
- get firstNode(): TreeNode;
1189
- origin: TreeNode;
1190
- }
1191
- declare class TreeRootPlugin {
1192
- root: TreeRoot;
1193
- }
1194
- declare class TreeNodePlugin {
1195
- node: TreeNode;
1196
- }
1197
-
1198
- interface IListItem {
752
+ first(): V | undefined;
1199
753
  /**
1200
- * 编号
754
+ * @param handler 返回true结束迭代
1201
755
  */
1202
- id: string;
756
+ firstByCondition(handler: (key: K, val: V) => boolean): V | undefined;
1203
757
  /**
1204
- * 自定义数据
758
+ * 移除符合条件的项
759
+ * @param cond 可以使用【iterator】中断遍历
1205
760
  */
1206
- data?: any;
761
+ removeByCondition(cond: (key: K, val: V, iterator: DictIterator) => boolean): void;
1207
762
  /**
1208
- * 功能性标签,用于开发组件时,记录组件的状态。例如title, icon, 显示树的组件,需要 expanded,selected标签
763
+ * 查找符合条件的项保存到【target】对象中,并返回【target】对象
764
+ * @param cond 可以使用【iterator】中断遍历
765
+ * @param target 存到目标对象中
1209
766
  */
1210
- tags?: {
767
+ findByCondition(cond: (key: K, val: V, iterator: DictIterator) => boolean, target: Dictionary): this;
768
+ groupByCondition(createKey: (key: K, val: V) => string, ITEM_CLASS?: any): {
1211
769
  [key: string]: any;
1212
770
  };
771
+ protected size: number;
772
+ private _data;
773
+ private _onSet;
774
+ private _onDelete;
775
+ private _onSetCaller;
776
+ private _onDeleteCaller;
1213
777
  }
1214
- declare class ListNode {
1215
- static create(id: string, data?: any): ListNode;
778
+
779
+ declare class DictNode {
780
+ static create(id: string, data?: any): DictNode;
1216
781
  constructor();
1217
- root: ListSource;
1218
782
  uuid: string;
1219
783
  id: string;
1220
784
  data: any;
@@ -1222,119 +786,524 @@ declare class ListNode {
1222
786
  getTags(): {
1223
787
  [key: string]: any;
1224
788
  };
1225
- setTags(tags: {
1226
- [key: string]: any;
1227
- }): void;
1228
789
  getTag(name: string): any;
1229
790
  setTag(name: string, value: any): void;
1230
- }
1231
- declare class ListSource extends EventManager {
1232
791
  /**
1233
- * 通过数组创建 ListSource。ListSource的id自动生成。如果需要指定编号,可设置 idCreator
1234
- * @param arr
1235
- * @param idCreator
792
+ * 清理【data】和【tags】
1236
793
  */
1237
- static createByArray(arr: any[], idCreator?: (item: any) => string): ListSource;
1238
- static createByListItem(arr: IListItem[], target?: ListSource): any;
794
+ clean(): void;
795
+ }
796
+ declare class DictSource extends Dictionary<string, DictNode> {
1239
797
  /**
1240
- * 设置数据时触发
798
+ * 刷新数据节点
1241
799
  * dispatchParams = {node:ListNode}
1242
800
  */
1243
- static EVENT_ADD: string;
801
+ static EVENT_REFRESH: string;
1244
802
  /**
1245
803
  * 设置数据时触发
1246
- * dispatchParams = {node:ListNode, index:number}
804
+ * dispatchParams = {node:ListNode, tag:string, value:any}
1247
805
  */
1248
- static EVENT_REMOVE: string;
806
+ static EVENT_TAGS_SET: string;
807
+ setNodeTags(node: DictNode, tag: string, value: any): void;
808
+ refreshNode(node: DictNode): void;
809
+ get dispatcher(): EventManager;
810
+ protected _dispatcher: EventManager;
811
+ }
812
+
813
+ declare class ListIterator {
814
+ break(): void;
815
+ isBreak(): boolean;
816
+ protected _isBreak: any;
817
+ }
818
+ declare class List<T = any> {
819
+ constructor();
820
+ onSet(caller: any, handler: (value: T) => void): void;
821
+ onDelete(caller: any, handler: (value: T) => void): void;
822
+ firstByCondition(conf: (index: number, item: T) => boolean): [number, T];
823
+ lastByCondition(conf: (index: number, item: T) => boolean): [number, T];
824
+ forEach(handler: (index: number, item: T, iterator: ListIterator) => void): ListIterator;
1249
825
  /**
1250
- * 设置数据时触发
826
+ * 移除符合条件的项, 从后往前遍历
827
+ * @param cond 可以使用【iterator】中断遍历
828
+ * @param removedList 设置后,可获得被移除的项
1251
829
  */
1252
- static EVENT_REMOVE_ALL: string;
830
+ removeByCondition(cond: (index: number, val: T, iterator: ListIterator) => boolean, removedList?: List): this;
1253
831
  /**
1254
- * 刷新数据节点
1255
- * dispatchParams = {node:ListNode}
832
+ * 查找符合条件的项保存到【target】对象中,并返回【target】对象
833
+ * @param cond 可以使用【iterator】中断遍历
834
+ * @param target 存到目标对象中
1256
835
  */
1257
- static EVENT_REFRESH: string;
836
+ findByCondition(cond: (index: number, val: T, iterator: ListIterator) => boolean, target: List): this;
837
+ pop(): T;
838
+ shift(): T;
839
+ first(): T;
840
+ last(): T;
841
+ removeAt(index: number): void;
842
+ remove(item: T): void;
1258
843
  /**
1259
- * 设置数据时触发
1260
- * dispatchParams = nodes: [ListNode], indexs: [number]
844
+ * 把【other】的项合并到自身
845
+ * @param other
1261
846
  */
1262
- static EVENT_SWAP: string;
847
+ removeList(other: List<T>): void;
848
+ sort(compareFn?: (a: T, b: T) => number): void;
849
+ reverse(): void;
850
+ clear(): void;
1263
851
  /**
1264
- * 设置数据时触发
1265
- * dispatchParams = {node:ListNode, data:any}
852
+ * 克隆自身所有项到【target】对象,并返回【target】对象
853
+ * @param target
1266
854
  */
1267
- static EVENT_DATA_SET: string;
855
+ clone(target: this): this;
856
+ get length(): number;
857
+ insertAt(index: number, ...item: T[]): void;
1268
858
  /**
1269
- * 设置数据时触发
1270
- * dispatchParams = {node:ListNode, tag:string, value:any}
859
+ * @param beforeItem
860
+ * @param item
1271
861
  */
1272
- static EVENT_TAGS_SET: string;
1273
- protected _identFunc: (node: ListNode) => boolean;
1274
- at(index: number): ListNode;
1275
- first(): ListNode;
1276
- last(): ListNode;
1277
- length(): number;
862
+ insertBefore(beforeItem: T, ...item: T[]): void;
1278
863
  /**
1279
- * 添加项,无法添加相同的项
1280
- * @param node
1281
- * @param enableDispatch 默认为true
864
+ * @param afterItem
865
+ * @param item
1282
866
  */
1283
- add(node: ListNode, enableDispatch?: boolean): void;
1284
- getById(id: string): ListNode;
1285
- remove(node: ListNode): void;
1286
- removeAll(): void;
1287
- swap(a: ListNode, b: ListNode): void;
1288
- contains(node: ListNode): boolean;
1289
- containsById(id: string): boolean;
1290
- indexOf(node: ListNode): number;
1291
- indexOfById(id: string): number;
1292
- setData(node: ListNode, data: any): void;
1293
- setNodeTags(node: ListNode, tag: string, value: any): void;
867
+ insertAfter(afterItem: T, ...item: T[]): void;
868
+ at(index: number): T;
869
+ set(index: number, item: T): void;
870
+ indexOf(item: T): number;
871
+ has(item: T): boolean;
872
+ push(item: T): void;
1294
873
  /**
1295
- * 派发 refresh 消息
1296
- * @param node
874
+ * 把【other】的项合并到自身
875
+ * @param other
1297
876
  */
1298
- refresh(node: ListNode): void;
1299
- walk(f: (node: ListNode) => boolean): boolean;
1300
- walkPrev(node: ListNode, f: (node: ListNode) => boolean): boolean;
1301
- get data(): any[];
1302
- private _data;
877
+ pushList(other: List<T>): void;
878
+ getData(): T[];
879
+ resetData(val: T[]): void;
880
+ /**
881
+ * 随机获取【count】个项,并返回【target】对象
882
+ * @param count
883
+ * @param enableRepeat 允许重复
884
+ * @param target
885
+ */
886
+ random(count: number, enableRepeat?: boolean, target?: List<T>): List<T>;
887
+ protected callPush(value: any): void;
888
+ protected callRemove(value: any): void;
889
+ protected _data: any[];
890
+ private _onSet;
891
+ private _onDelete;
892
+ private _onSetCaller;
893
+ private _onDeleteCaller;
1303
894
  }
1304
895
 
1305
- declare class DictNode {
1306
- static create(id: string, data?: any): DictNode;
896
+ interface IController {
897
+ get name(): string;
898
+ enable(): any;
899
+ disable(): any;
900
+ dispose(): any;
901
+ }
902
+ declare class Controller {
903
+ constructor(name: string);
904
+ enable(): void;
905
+ disable(): void;
906
+ dispose(): void;
907
+ get name(): string;
908
+ get isEnable(): boolean;
909
+ protected _name: string;
910
+ protected _enabled: boolean;
911
+ }
912
+ declare class ControllerDict extends Dictionary<string, IController> {
1307
913
  constructor();
1308
- uuid: string;
1309
- id: string;
1310
- data: any;
1311
- tags: {};
1312
- getTags(): {
1313
- [key: string]: any;
914
+ disable(name: string): void;
915
+ enable(name: string): void;
916
+ enableAll(): void;
917
+ disableAll(): void;
918
+ }
919
+ declare class ControllerRepo extends ControllerDict {
920
+ constructor();
921
+ add(controller: IController): void;
922
+ remove(name: string): void;
923
+ dispose(): void;
924
+ }
925
+
926
+ interface IModule {
927
+ }
928
+
929
+ interface IModel {
930
+ get module(): IModule;
931
+ }
932
+ declare class SimpleModel {
933
+ constructor(mod: IModule);
934
+ get core(): IModule;
935
+ protected _mod: any;
936
+ }
937
+ declare class Model extends EventManager {
938
+ constructor(core?: IModule);
939
+ get module(): IModule;
940
+ protected _module: any;
941
+ }
942
+
943
+ interface IExtend {
944
+ get module(): IModule;
945
+ }
946
+
947
+ declare class Factory {
948
+ _controllers: {
949
+ [key: string]: (mod: IModule) => IController;
1314
950
  };
1315
- getTag(name: string): any;
1316
- setTag(name: string, value: any): void;
951
+ _extends: {
952
+ [key: string]: (mod: IModule, ...args: any) => IExtend;
953
+ };
954
+ registerController(name: string, creator: (mod: IModule, ...args: any) => IController): void;
955
+ registerExtend(name: string, creator: (mod: IModule, ...args: any) => IExtend): void;
956
+ createController(name: string, mod: IModule): IController;
957
+ createExtend(name: string, mod: IModule, ...args: any[]): IExtend;
958
+ }
959
+
960
+ /**
961
+ * 视图的路由值, 保存视图的信息
962
+ * 规则: path/search
963
+ * path = /a/b/c
964
+ * search = ?key=val&key=val
965
+ */
966
+ declare class Route {
967
+ constructor(route: string);
968
+ recycle(): void;
1317
969
  /**
1318
- * 清理【data】和【tags】
970
+ * 获取调用链
971
+ * 例如 a/b/c,返回 a/b/c -> a/b -> a
1319
972
  */
1320
- clean(): void;
1321
- }
1322
- declare class DictSource extends Dictionary<string, DictNode> {
973
+ getLink(): Route[];
974
+ protected static data: any;
975
+ static getData(route: string): Route;
976
+ toLoaction(): Location;
1323
977
  /**
1324
- * 刷新数据节点
1325
- * dispatchParams = {node:ListNode}
978
+ * @constructor
1326
979
  */
1327
- static EVENT_REFRESH: string;
980
+ NewRoute(): Route;
1328
981
  /**
1329
- * 设置数据时触发
1330
- * dispatchParams = {node:ListNode, tag:string, value:any}
982
+ * @constructor
1331
983
  */
1332
- static EVENT_TAGS_SET: string;
1333
- setNodeTags(node: DictNode, tag: string, value: any): void;
1334
- refreshNode(node: DictNode): void;
1335
- get dispatcher(): EventManager;
1336
- protected _dispatcher: EventManager;
984
+ NewRoutePath(): Route;
985
+ /**
986
+ * 新建一个带参数的路由
987
+ * @param params
988
+ */
989
+ NewRouteParam(params: any): Route;
990
+ toString(): string;
991
+ get path(): string;
992
+ get parentPath(): string;
993
+ get params(): any;
994
+ get search(): string;
995
+ set search(value: string);
996
+ get name(): string;
997
+ /**
998
+ * path/search
999
+ */
1000
+ get key(): string;
1001
+ private _path;
1002
+ private _parentPath;
1003
+ private _search;
1004
+ private _name;
1005
+ private _params;
1006
+ protected _route: string;
1007
+ }
1008
+
1009
+ declare class UIObjectDict extends Dictionary<string, any | List> {
1010
+ /**
1011
+ * 获取唯一的
1012
+ * @param prefab
1013
+ */
1014
+ uniqueObject(prefab: Prefab): Node;
1015
+ removeObject(prefab: Prefab): void;
1016
+ popObject(prefab: Prefab): any;
1017
+ backObject(object: Node): void;
1018
+ protected getList(key: any): List;
1337
1019
  }
1020
+ declare var uidict: UIObjectDict;
1021
+
1022
+ /**
1023
+ * 视图管理器
1024
+ * 打开一个视图的时候,可能会听过加载资源,读取数据,调整布局,切换特效等处理,所以使用视图模式封装视图打开关闭的逻辑
1025
+ */
1026
+ declare class PageLayer {
1027
+ name: string;
1028
+ constructor(name: string);
1029
+ close(): void;
1030
+ /**
1031
+ * 当前的页面
1032
+ */
1033
+ currentPage: Page;
1034
+ }
1035
+
1036
+ declare class PageList extends List<Page> {
1037
+ }
1038
+ declare class PageRepo extends PageList {
1039
+ constructor();
1040
+ openByString(route: string): Page;
1041
+ /**
1042
+ * 打开页面
1043
+ * 一个路由代表一个页面
1044
+ * @param route
1045
+ */
1046
+ open(route: Route): Page;
1047
+ close(route: Route): void;
1048
+ /**
1049
+ * 如果页面存在,则刷新
1050
+ * @param route
1051
+ */
1052
+ refresh(route: Route): void;
1053
+ /**
1054
+ * 历史记录
1055
+ */
1056
+ getHistory(): Route[];
1057
+ back(): void;
1058
+ getByRoute(route: Route): Page;
1059
+ listByTags(tags: string[]): PageList;
1060
+ getLayerMain(): PageLayer;
1061
+ /**
1062
+ * @param name
1063
+ */
1064
+ getLayer(name: string): PageLayer;
1065
+ protected getOrNewLayer(name: string): PageLayer;
1066
+ getController(name: string): PageController;
1067
+ registerController(ctrl: PageController): void;
1068
+ get objectDict(): UIObjectDict;
1069
+ protected _objectDict: UIObjectDict;
1070
+ protected _indexLayer: {};
1071
+ protected _indexRoute: {};
1072
+ protected _history: Route[];
1073
+ protected _ctrlDict: ControllerDict;
1074
+ }
1075
+ declare const pageRepo: PageRepo;
1076
+
1077
+ declare class PageController extends Controller {
1078
+ constructor(routeName: string, config?: {
1079
+ layer?: string;
1080
+ tags?: string[];
1081
+ enableHistory?: boolean;
1082
+ });
1083
+ open(...args: any[]): void;
1084
+ close(): void;
1085
+ protected onOpening(page: Page): void;
1086
+ protected onOpened(page: Page): void;
1087
+ protected onClosing(page: Page): void;
1088
+ protected onClosed(page: Page): void;
1089
+ protected onRefresh(page: Page): void;
1090
+ openByRoute(route: Route): Page;
1091
+ private openPage;
1092
+ openComplete(page: Page): void;
1093
+ closeByRoute(route?: Route): Page;
1094
+ private closePage;
1095
+ closeComplete(page: Page): void;
1096
+ refresh(): void;
1097
+ get layer(): string;
1098
+ hasTags(tags: string[]): boolean;
1099
+ setLayer(name: string): this;
1100
+ setTags(tags: string[]): this;
1101
+ get lastPage(): Page;
1102
+ get route(): Route;
1103
+ get enableHistory(): boolean;
1104
+ protected _enableHistory: boolean;
1105
+ protected _route: Route;
1106
+ protected _lastPage: Page;
1107
+ protected _tags: {};
1108
+ protected _layer: string;
1109
+ protected _pagerepo: PageRepo;
1110
+ }
1111
+
1112
+ declare enum PageState {
1113
+ /**
1114
+ * 关闭
1115
+ */
1116
+ Closed = 0,
1117
+ /**
1118
+ * 正在打开
1119
+ */
1120
+ Opening = 1,
1121
+ /**
1122
+ * 已打开
1123
+ */
1124
+ Opened = 2,
1125
+ /**
1126
+ * 正在关闭
1127
+ */
1128
+ Closeing = 3
1129
+ }
1130
+ declare enum PageEvent {
1131
+ Opening = "opening",
1132
+ Opened = "opened",
1133
+ Closeing = "closeing",
1134
+ Closed = "closed",
1135
+ Stop = "stop"
1136
+ }
1137
+ declare class Page extends EventManager {
1138
+ constructor(controller: PageController, route: Route);
1139
+ /**
1140
+ * 等待打开完成指令
1141
+ */
1142
+ waitOpenComplete(): void;
1143
+ waitCloseComplete(): void;
1144
+ openComplete(): void;
1145
+ closeComplete(): void;
1146
+ stop(reason: LinkError): void;
1147
+ /**
1148
+ * 等待发送的结果
1149
+ * 如果返回 null,表示主动取消 [cancel]
1150
+ */
1151
+ wait(): Promise<this>;
1152
+ toString(): string;
1153
+ get objectDict(): UIObjectDict;
1154
+ protected _objectDict: UIObjectDict;
1155
+ protected _waitOpenComplete: boolean;
1156
+ protected _waitCloseComplete: boolean;
1157
+ get controller(): PageController;
1158
+ get route(): Route;
1159
+ datas: {};
1160
+ tags: {};
1161
+ layer: string;
1162
+ state: PageState;
1163
+ protected _controller: PageController;
1164
+ protected _route: Route;
1165
+ }
1166
+
1167
+ /**
1168
+ * 事件字符串分隔符
1169
+ */
1170
+
1171
+ /**
1172
+ * 回调列表
1173
+ */
1174
+ declare class CallbackList<PARAMS = any> {
1175
+ constructor();
1176
+ addListener(listener: Listener): void;
1177
+ removeListener(listener: Listener): void;
1178
+ /**
1179
+ */
1180
+ create(): Listener<PARAMS>;
1181
+ /**
1182
+ * 如果监听器已经不存在,则创建
1183
+ * @param ident
1184
+ */
1185
+ createByIdent(ident: any): Listener<PARAMS>;
1186
+ removeByIdent(ident: any): void;
1187
+ removeByCaller(caller: any): void;
1188
+ getByIdent(ident: any): Listener;
1189
+ /**
1190
+ * 派发事件
1191
+ * @param params 事件参数
1192
+ * @param subIdent
1193
+ */
1194
+ dispatch(params?: PARAMS, subIdent?: string): void;
1195
+ protected _data: List<Listener<any>>;
1196
+ protected _indexIdent: {};
1197
+ }
1198
+
1199
+ declare class Listener<PARAMS = any> {
1200
+ static create(ident?: string): Listener<any>;
1201
+ constructor(ident?: string);
1202
+ getCaller(): any;
1203
+ setCaller(caller: any): this;
1204
+ setSubIdent(val: string): this;
1205
+ setCondition(condition: (listener: Listener<PARAMS>) => boolean): this;
1206
+ setHandler(handler: (listener: Listener<PARAMS>) => void): this;
1207
+ setOnParams(val: any): this;
1208
+ getIdent(): string;
1209
+ on(): this;
1210
+ off(): this;
1211
+ isOn(): boolean;
1212
+ remove(): void;
1213
+ /**
1214
+ * 内部使用
1215
+ * @param params
1216
+ * @param subIdent 子编号
1217
+ */
1218
+ _dispatch(params: PARAMS, subIdent?: string): void;
1219
+ getOnParams(): any;
1220
+ getParams(): PARAMS;
1221
+ protected onParams: any;
1222
+ protected params: PARAMS;
1223
+ protected ident: string;
1224
+ protected _subIdent: string;
1225
+ protected source: CallbackList;
1226
+ protected _handler: (any: any) => void;
1227
+ protected _condition: (any: any) => boolean;
1228
+ protected caller: any;
1229
+ protected _isOn: boolean;
1230
+ }
1231
+
1232
+ /**
1233
+ * 事件字符串分隔符
1234
+ */
1235
+
1236
+ /**
1237
+ * 事件派发器
1238
+ */
1239
+ declare class Dispatcher implements ISchedulable {
1240
+ constructor(name?: string);
1241
+ dispose(): void;
1242
+ create(type: string, listener: Listener): void;
1243
+ remove(type: string, listener: Listener): void;
1244
+ getByIdent(type: string, ident: string): Listener;
1245
+ /**
1246
+ * @param type
1247
+ * @param ident
1248
+ */
1249
+ createByIdent(type: string, ident: string): Listener;
1250
+ /**
1251
+ * 派发事件
1252
+ * @param eventType 事件类型
1253
+ * @param params 事件参数
1254
+ */
1255
+ dispatch(eventType: string, params?: any): void;
1256
+ protected getList(type: string): CallbackList;
1257
+ id?: string;
1258
+ uuid?: string;
1259
+ name: string;
1260
+ protected isDispose: boolean;
1261
+ protected typeToList: Dictionary<string, CallbackList<any>>;
1262
+ }
1263
+
1264
+ declare class CallbackItem {
1265
+ listener: Function;
1266
+ caller: any;
1267
+ once: boolean;
1268
+ }
1269
+ declare class SampleCallbackList {
1270
+ constructor();
1271
+ dispose(): void;
1272
+ has(caller: any, listener: Function): boolean;
1273
+ protected getItem(caller: any, listener: Function): CallbackItem;
1274
+ /**
1275
+ * 监听事件,如果监听已经存在则返回
1276
+ * @param caller
1277
+ * @param listener 为了性能考虑, event使用了对象池处理。因此处理函数不应该保存event的引用。如有需要,可通过新建对象或Event.Clone()实现
1278
+ */
1279
+ on(caller: any, listener: (ctx: this, params?: any) => void): CallbackItem;
1280
+ once(caller: any, listener: (ctx: this, params?: any) => void): CallbackItem;
1281
+ protected offItem(item: CallbackItem): void;
1282
+ off(caller: any, listener: Function): void;
1283
+ offAll(type?: string): void;
1284
+ offAllCaller(caller: any): void;
1285
+ /**
1286
+ * 派发事件
1287
+ * @param params 事件参数
1288
+ */
1289
+ dispatch(params?: any): void;
1290
+ protected _callbackItems: CallbackItem[];
1291
+ }
1292
+
1293
+ declare class AssetURI {
1294
+ name: string;
1295
+ constructor(name: string);
1296
+ loadType: number;
1297
+ uuid: string;
1298
+ path: string;
1299
+ bundle: string;
1300
+ }
1301
+ declare class XAssetManager {
1302
+ getAsset(uri: string): any;
1303
+ getAssetByUUID(uuid: string): any;
1304
+ getRoot(): AssetManager;
1305
+ }
1306
+ declare let assetx: XAssetManager;
1338
1307
 
1339
1308
  declare class LoaderItem {
1340
1309
  onComplete?: (err: any, asset: any) => void;
@@ -2045,5 +2014,5 @@ declare class WidgetUtil {
2045
2014
  }
2046
2015
  declare var widgetutil: WidgetUtil;
2047
2016
 
2048
- export { ArrayUtil, AssetLoader, AssetURI, BitUtil, CallbackList, CameraUtil, CanvasUtil, Controller, ControllerSet, ConvertUtil, DictIterator, DictNode, DictSource, Dictionary, Dispatcher, DocUtil, ErrorUtil, EventItem, EventManager, EventUtil, Factory, FloatUtil, GeometryUtil, IdentUtil, LOGGER_EVENT, LinkError, List, ListIterator, ListNode, ListSource, Listener, LogLevel, LogManager, Logger, MapUtil, MathUtil, Model, Module, NetUtil, Page, PageController, PageControllerDict, PageEvent, PageLayer, PageList, PageRepo, PageState, PathUtil, Pool, RandUtil, Route, SampleCallbackList, SamplePool, SamplePoolSet, ScaleUtil, SimpleModel, StringUtil, TimeUtil, Timer, TreeIterator, TreeNode, TreeNodePlugin, TreeRoot, TreeRootPlugin, TreeUtil, UIManager, UIObjectDict, UIPoolConfig, UISingleConfig, UIUtil, ViewController, WidgetAlign, WidgetUtil, XAssetManager, XEvent, arrayutil, assetx, bitutil, camerautil, canvasutil, convertutil, docutil, errorutil, eventmgr, eventutil, floatutil, formatutil, geoutil, identutil, loadAtlas, logmgr, maputil, mathutil, netutil, pagerepo, parseAtlas, parsePlist, pathutil, randutil, resutil, scaleutil, stringutil, timer, timeutil, treeutil, uidict, uimgr, uiutil, widgetutil };
2049
- export type { CreatorFunction, DisposeFunction, IController, IError, IEventManager, IExtend, IListItem, IModel, IModule, IModuleSample, ITreeListItem, RecycleFunction };
2017
+ export { ArrayUtil, AssetLoader, AssetURI, BitUtil, CallbackList, CameraUtil, CanvasUtil, Controller, ControllerDict, ControllerRepo, ConvertUtil, DictIterator, DictNode, DictSource, Dictionary, Dispatcher, DocUtil, ErrorUtil, EventItem, EventManager, EventUtil, Factory, FloatUtil, GeometryUtil, IdentUtil, LOGGER_EVENT, LinkError, List, ListIterator, ListNode, ListSource, Listener, LogLevel, LogManager, Logger, MapUtil, MathUtil, Model, NetUtil, Page, PageController, PageEvent, PageLayer, PageList, PageRepo, PageState, PathUtil, Pool, RandUtil, Route, SampleCallbackList, SamplePool, SamplePoolSet, ScaleUtil, SimpleModel, StringUtil, TimeUtil, Timer, TreeIterator, TreeNode, TreeNodePlugin, TreeRoot, TreeRootPlugin, TreeUtil, UIManager, UIObjectDict, UIPoolConfig, UISingleConfig, UIUtil, WidgetAlign, WidgetUtil, XAssetManager, XEvent, arrayutil, assetx, bitutil, camerautil, canvasutil, convertutil, docutil, errorutil, eventmgr, eventutil, floatutil, formatutil, geoutil, identutil, loadAtlas, logmgr, maputil, mathutil, netutil, pageRepo, parseAtlas, parsePlist, pathutil, randutil, resutil, scaleutil, stringutil, timer, timeutil, treeutil, uidict, uimgr, uiutil, widgetutil };
2018
+ export type { CreatorFunction, DisposeFunction, IController, IError, IEventManager, IExtend, IListItem, IModel, IModule, ITreeListItem, RecycleFunction };