@zhongguo168a/yxeditor-common 0.0.16 → 0.0.17

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