@zhongguo168a/yxeditor-common 0.0.40 → 0.0.43

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.esm.js CHANGED
@@ -3475,94 +3475,37 @@ class Factory {
3475
3475
  }
3476
3476
  }
3477
3477
 
3478
- var ViewState;
3479
- (function (ViewState) {
3480
- /**
3481
- * 关闭
3482
- */
3483
- ViewState[ViewState["Closed"] = 0] = "Closed";
3484
- /**
3485
- * 正在打开
3486
- */
3487
- ViewState[ViewState["Opening"] = 1] = "Opening";
3488
- /**
3489
- * 已打开
3490
- */
3491
- ViewState[ViewState["Opened"] = 2] = "Opened";
3492
- /**
3493
- * 正在关闭
3494
- */
3495
- ViewState[ViewState["Closeing"] = 3] = "Closeing";
3496
- })(ViewState || (ViewState = {}));
3497
- var ViewEvent;
3498
- (function (ViewEvent) {
3499
- // 正在打开
3500
- ViewEvent["Opening"] = "opening";
3501
- // 已打开
3502
- ViewEvent["Opened"] = "opened";
3503
- // 正在打开
3504
- ViewEvent["Closeing"] = "closeing";
3505
- // 已关闭
3506
- ViewEvent["Closed"] = "closed";
3507
- // 停止
3508
- ViewEvent["Stop"] = "stop";
3509
- })(ViewEvent || (ViewEvent = {}));
3510
- class View extends EventDispatcher {
3511
- constructor(controller, route) {
3512
- super();
3513
- this._waitOpenComplete = false;
3514
- this._waitCloseComplete = false;
3515
- this.datas = {};
3516
- this.tags = {};
3517
- this.state = 0;
3518
- this._controller = controller;
3519
- this._route = route;
3520
- }
3521
- /**
3522
- * 等待发送的结果
3523
- * 如果返回 null,表示主动取消 [cancel]
3524
- */
3525
- wait() {
3526
- switch (this.state) {
3527
- case ViewState.Opening:
3528
- return new Promise((resolve, reject) => {
3529
- let opened = () => {
3530
- this.off("opened", this, opened);
3531
- this.off("canceled", this, opened);
3532
- resolve(this);
3533
- };
3534
- let canceled = () => {
3535
- this.off("opened", this, opened);
3536
- this.off("canceled", this, opened);
3537
- resolve(this);
3538
- };
3539
- this.on("opened", this, opened);
3540
- this.on("canceled", this, canceled);
3541
- });
3542
- case ViewState.Closeing:
3543
- return new Promise((resolve, reject) => {
3544
- let opened = () => {
3545
- this.off("closed", this, opened);
3546
- resolve(this);
3547
- };
3548
- this.on("closed", this, opened);
3549
- });
3550
- default:
3551
- return new Promise((resolve, reject) => {
3552
- resolve(this);
3553
- });
3554
- }
3555
- }
3556
- toString() {
3557
- return `View[${this.route.toString()}, ${this.id}]`;
3558
- }
3559
- get controller() {
3560
- return this._controller;
3561
- }
3562
- get route() {
3563
- return this._route;
3564
- }
3565
- }
3478
+ /******************************************************************************
3479
+ Copyright (c) Microsoft Corporation.
3480
+
3481
+ Permission to use, copy, modify, and/or distribute this software for any
3482
+ purpose with or without fee is hereby granted.
3483
+
3484
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
3485
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
3486
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
3487
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
3488
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
3489
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
3490
+ PERFORMANCE OF THIS SOFTWARE.
3491
+ ***************************************************************************** */
3492
+ /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
3493
+
3494
+
3495
+ function __awaiter(thisArg, _arguments, P, generator) {
3496
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3497
+ return new (P || (P = Promise))(function (resolve, reject) {
3498
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
3499
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
3500
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
3501
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
3502
+ });
3503
+ }
3504
+
3505
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
3506
+ var e = new Error(message);
3507
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
3508
+ };
3566
3509
 
3567
3510
  /**
3568
3511
  * 视图的路由值, 保存视图的信息
@@ -3693,60 +3636,6 @@ Route.data = {};
3693
3636
  class RouteList extends List {
3694
3637
  }
3695
3638
 
3696
- class UIObjectDict extends Dictionary {
3697
- /**
3698
- * 获取唯一的
3699
- * @param prefab
3700
- */
3701
- uniqueObject(prefab) {
3702
- if (!prefab) {
3703
- console.warn("未设置prefab");
3704
- return;
3705
- }
3706
- let key = prefab.data.uuid;
3707
- let object = this.get(key);
3708
- if (!object) {
3709
- object = instantiate(prefab);
3710
- this.set(key, object);
3711
- }
3712
- return object;
3713
- }
3714
- removeObject(prefab) {
3715
- if (!prefab) {
3716
- console.warn("未设置prefab");
3717
- return;
3718
- }
3719
- this.delete(prefab.data.uuid);
3720
- }
3721
- popObject(prefab) {
3722
- let object;
3723
- let key = prefab.data.uuid;
3724
- let list = this.getList(key);
3725
- if (list.length == 0) {
3726
- object = instantiate(prefab);
3727
- }
3728
- else {
3729
- object = list.pop();
3730
- }
3731
- return object;
3732
- }
3733
- backObject(object) {
3734
- // @ts-ignore
3735
- let key = object.prefab.asset.uuid;
3736
- let list = this.getList(key);
3737
- list.push(object);
3738
- }
3739
- getList(key) {
3740
- let list = this.get(key);
3741
- if (!list) {
3742
- list = new List();
3743
- this.set(key, list);
3744
- }
3745
- return list;
3746
- }
3747
- }
3748
- var uidict = new UIObjectDict();
3749
-
3750
3639
  class ViewList extends List {
3751
3640
  }
3752
3641
  /**
@@ -3773,14 +3662,38 @@ class ViewRepo extends ViewDict {
3773
3662
  if (!controller) {
3774
3663
  throw new Error("view controller no register: " + route.path);
3775
3664
  }
3776
- return controller.open(route);
3665
+ return controller.openByRoute(route);
3777
3666
  }
3778
3667
  close(route) {
3779
3668
  let controller = this.getController(route.path);
3780
3669
  if (!controller) {
3781
3670
  throw new Error("view controller no register: " + route.path);
3782
3671
  }
3783
- controller.close(route);
3672
+ controller.closeByRoute(route);
3673
+ }
3674
+ /**
3675
+ * 关闭相斥的视图对象
3676
+ * 1. 关闭同一层的所有视图对象
3677
+ * 2. 关闭符合相斥规则的视图对象
3678
+ * @param view
3679
+ * @param validFunc 符合条件的视图对象会被关闭
3680
+ * @returns 被关闭的视图
3681
+ */
3682
+ closeExclusion(validFunc = undefined) {
3683
+ if (!validFunc) {
3684
+ return;
3685
+ }
3686
+ let closedList = new ViewList();
3687
+ this.forEach((key, item, iterator) => {
3688
+ if (validFunc(item)) {
3689
+ closedList.push(item);
3690
+ }
3691
+ });
3692
+ closedList.forEach((index, item) => {
3693
+ item.controller;
3694
+ item.close();
3695
+ });
3696
+ return closedList;
3784
3697
  }
3785
3698
  /**
3786
3699
  * 如果页面存在,则刷新
@@ -3816,195 +3729,112 @@ class ViewRepo extends ViewDict {
3816
3729
  getController(name) {
3817
3730
  return ctrlrepo.get(name);
3818
3731
  }
3819
- get objectDict() {
3820
- let dict = this._objectDict;
3821
- if (!dict) {
3822
- dict = new UIObjectDict();
3823
- this._objectDict = dict;
3824
- }
3825
- return dict;
3826
- }
3827
3732
  }
3828
3733
  const viewrepo = new ViewRepo();
3829
3734
 
3830
- class ViewController extends Controller {
3831
- constructor(routeName) {
3832
- super(routeName);
3833
- this._enableHistory = false;
3834
- this._tags = {};
3835
- this._route = new Route(routeName);
3735
+ class ViewHistory extends RouteList {
3736
+ back() {
3737
+ if (viewhistorys.length == 0) {
3738
+ return;
3739
+ }
3740
+ viewrepo.close(viewhistorys.shift());
3741
+ if (viewhistorys.length == 0) {
3742
+ return;
3743
+ }
3744
+ viewrepo.open(viewhistorys.last());
3836
3745
  }
3837
- /**
3838
- * 当视图需要通过路由打开时,需要实现此方法
3839
- * @param route
3840
- */
3841
- open(route) {
3746
+ }
3747
+ const viewhistorys = new ViewHistory();
3748
+
3749
+ function OpenPageHandler(route) {
3750
+ return __awaiter(this, void 0, void 0, function* () {
3751
+ let view = viewrepo.getByRoute(route);
3752
+ if (view) { //
3753
+ this.refreshView(view);
3754
+ return;
3755
+ }
3756
+ // 关闭同一层的所有视图
3757
+ this.closeExclusion((existed) => {
3758
+ return existed.layer == this._layer;
3759
+ });
3760
+ if (this.enableHistory) {
3761
+ viewhistorys.push(route);
3762
+ }
3763
+ });
3764
+ }
3765
+ function OpenDialogHandler(route) {
3766
+ return __awaiter(this, void 0, void 0, function* () {
3842
3767
  if (!route) {
3843
3768
  route = this.route;
3844
3769
  }
3845
3770
  let oldView = viewrepo.getByRoute(route);
3846
3771
  if (oldView) {
3847
- this.closeView(oldView);
3772
+ oldView.close();
3848
3773
  }
3849
- let view = new View(this, route);
3850
- this.openView(view);
3851
- return view;
3852
- }
3853
- onOpening(view) {
3854
- }
3855
- onOpened(view) {
3856
- }
3857
- onClosing(view) {
3858
- }
3859
- onClosed(view) {
3774
+ });
3775
+ }
3776
+ function CloseDialogHandler(route) {
3777
+ if (!route) {
3778
+ route = this.route;
3860
3779
  }
3861
- refreshView(view) {
3780
+ let view = viewrepo.getByRoute(route);
3781
+ if (view) {
3782
+ view.close();
3862
3783
  }
3863
- openView(view) {
3864
- if (!view) {
3865
- return;
3866
- }
3867
- if (view.state != ViewState.Closed) {
3868
- return;
3869
- }
3870
- let route = view.route;
3871
- if (viewrepo.get(route.key)) {
3872
- throw `视图已存在: route=${route.key}`;
3873
- }
3874
- viewrepo.set(route.key, view);
3875
- this._lastView = view;
3876
- view.state = ViewState.Opening;
3877
- view.dispatch(ViewEvent.Opening);
3878
- //
3879
- try {
3880
- //
3881
- this.onOpening(view);
3882
- // @ts-ignore
3883
- if (!view._waitOpenComplete) {
3884
- // 没有被打断,打开完成
3885
- this.openComplete(view);
3886
- }
3887
- else {
3888
- // 被打断了,等待完成1
3784
+ return view;
3785
+ }
3786
+ /**
3787
+ * @param route
3788
+ * @returns
3789
+ */
3790
+ function ClosePageHandler(route) {
3791
+ return __awaiter(this, void 0, void 0, function* () {
3792
+ let lastview;
3793
+ if (lastview.layer) {
3794
+ if (lastview.enableHistory) {
3795
+ // 清空历史记录
3796
+ viewhistorys.clear();
3889
3797
  }
3890
3798
  }
3891
- catch (e) {
3892
- console.error(`open view ${view.route.key}`);
3893
- console.error(e.stack);
3894
- //
3895
- this.closeView(view);
3799
+ else {
3800
+ lastview = viewrepo.getByRoute(route);
3896
3801
  }
3802
+ lastview.close();
3803
+ return lastview;
3804
+ });
3805
+ }
3806
+ class RouteController extends Controller {
3807
+ constructor(routePath) {
3808
+ super(routePath);
3809
+ this._tags = {};
3810
+ this._route = new Route(routePath);
3811
+ }
3812
+ open() {
3813
+ this.openByRoute();
3897
3814
  }
3898
3815
  /**
3899
- * 等待打开完成指令
3900
- */
3901
- waitOpenComplete(view) {
3902
- // @ts-ignore
3903
- view._waitOpenComplete = true;
3816
+ * 当视图需要通过路由打开时,需要实现此方法
3817
+ * @param route
3818
+ */
3819
+ openByRoute(route) {
3820
+ throw "未实现 openByRoute";
3904
3821
  }
3905
- openComplete(view) {
3906
- if (!view) {
3907
- return;
3908
- }
3909
- this._lastView = view;
3910
- view.state = ViewState.Opened;
3911
- // @ts-ignore
3912
- view._waitOpenComplete = false;
3913
- this.onOpened(view);
3914
- view.dispatch(ViewEvent.Opened);
3822
+ refreshView(view) {
3823
+ }
3824
+ close() {
3825
+ this.closeByRoute();
3915
3826
  }
3916
3827
  /**
3917
3828
  * 当视图需要通过路由关闭时,需要实现此方法
3918
3829
  * @param route
3919
3830
  * @returns
3920
3831
  */
3921
- close(route) {
3922
- if (!route) {
3923
- route = this.route;
3924
- }
3925
- let view = viewrepo.getByRoute(route);
3926
- if (view) {
3927
- this.closeView(view);
3928
- }
3929
- return view;
3930
- }
3931
- /**
3932
- * 关闭相斥的视图对象
3933
- * 1. 关闭同一层的所有视图对象
3934
- * 2. 关闭符合相斥规则的视图对象
3935
- * @param view
3936
- * @param validFunc 符合条件的视图对象会被关闭
3937
- * @returns 被关闭的视图
3938
- */
3939
- closeExclusion(validFunc = undefined) {
3940
- if (!validFunc) {
3941
- return;
3942
- }
3943
- let closedList = new ViewList();
3944
- viewrepo.forEach((key, item, iterator) => {
3945
- if (validFunc(item)) {
3946
- closedList.push(item);
3947
- }
3948
- });
3949
- closedList.forEach((index, item) => {
3950
- let currentCtrl = item.controller;
3951
- currentCtrl.closeView(item);
3952
- });
3953
- return closedList;
3954
- }
3955
- closeView(view) {
3956
- if (!view) {
3957
- return;
3958
- }
3959
- if (view.state == ViewState.Closed) {
3960
- return;
3961
- }
3962
- this._lastView = view;
3963
- view.state = ViewState.Closeing;
3964
- view.dispatch(ViewEvent.Closeing);
3965
- try {
3966
- this.onClosing(view);
3967
- // @ts-ignore
3968
- if (!view._waitCloseComplete) {
3969
- // 没有被打断,关闭完成
3970
- this.closeComplete(view);
3971
- }
3972
- else {
3973
- // 被打断了,等待完成1
3974
- }
3975
- }
3976
- catch (e) {
3977
- console.error(`close view ${view.route.key}`);
3978
- console.error(e.stack);
3979
- }
3980
- }
3981
- waitCloseComplete(view) {
3982
- // @ts-ignore
3983
- view._waitCloseComplete = true;
3984
- }
3985
- closeComplete(view) {
3986
- if (!view) {
3987
- return;
3988
- }
3989
- viewrepo.delete(view.route.key);
3990
- this._lastView = view;
3991
- // @ts-ignore
3992
- view._waitCloseComplete = false;
3993
- // @ts-ignore
3994
- let objectDict = view._objectDict;
3995
- if (objectDict) {
3996
- objectDict.clear();
3997
- }
3998
- view.state = ViewState.Closed;
3999
- view.dispatch(ViewEvent.Closed);
4000
- this.onClosed(view);
3832
+ closeByRoute(route) {
3833
+ throw "未实现 closeByRoute";
4001
3834
  }
4002
3835
  refresh() {
4003
3836
  this.refreshView(this._lastView);
4004
3837
  }
4005
- get layer() {
4006
- return this._layer;
4007
- }
4008
3838
  hasTags(tags) {
4009
3839
  for (let i = 0; i < tags.length; i++) {
4010
3840
  let tag = tags[i];
@@ -4017,98 +3847,267 @@ class ViewController extends Controller {
4017
3847
  }
4018
3848
  return false;
4019
3849
  }
4020
- setLayer(name) {
4021
- this._layer = name;
4022
- return this;
4023
- }
4024
3850
  setTags(tags) {
4025
3851
  this._tags = tags;
4026
3852
  return this;
4027
3853
  }
4028
- useHistory() {
4029
- this._enableHistory = true;
4030
- return this;
4031
- }
4032
3854
  get lastView() {
4033
3855
  return this._lastView;
4034
3856
  }
4035
3857
  get route() {
4036
3858
  return this._route;
4037
3859
  }
4038
- get enableHistory() {
4039
- return this._enableHistory;
4040
- }
4041
3860
  }
4042
3861
 
4043
- class ViewHistory extends RouteList {
4044
- back() {
4045
- if (viewhistorys.length == 0) {
3862
+ class UIObjectRepo extends Dictionary {
3863
+ /**
3864
+ * 获取唯一的
3865
+ * @param prefab
3866
+ */
3867
+ uniqueObject(prefab) {
3868
+ if (!prefab) {
3869
+ console.warn("未设置prefab");
4046
3870
  return;
4047
3871
  }
4048
- viewrepo.close(viewhistorys.shift());
4049
- if (viewhistorys.length == 0) {
3872
+ let key = prefab.data.uuid;
3873
+ let object = this.get(key);
3874
+ if (!object) {
3875
+ object = instantiate(prefab);
3876
+ this.set(key, object);
3877
+ }
3878
+ return object;
3879
+ }
3880
+ removeObject(prefab) {
3881
+ if (!prefab) {
3882
+ console.warn("未设置prefab");
4050
3883
  return;
4051
3884
  }
4052
- viewrepo.open(viewhistorys.last());
3885
+ this.delete(prefab.data.uuid);
3886
+ }
3887
+ popObject(prefab) {
3888
+ let object;
3889
+ let key = prefab.data.uuid;
3890
+ let list = this.getList(key);
3891
+ if (list.length == 0) {
3892
+ object = instantiate(prefab);
3893
+ }
3894
+ else {
3895
+ object = list.pop();
3896
+ }
3897
+ return object;
3898
+ }
3899
+ backObject(object) {
3900
+ // @ts-ignore
3901
+ let key = object.prefab.asset.uuid;
3902
+ let list = this.getList(key);
3903
+ list.push(object);
3904
+ }
3905
+ getList(key) {
3906
+ let list = this.get(key);
3907
+ if (!list) {
3908
+ list = new List();
3909
+ this.set(key, list);
3910
+ }
3911
+ return list;
4053
3912
  }
4054
3913
  }
4055
- const viewhistorys = new ViewHistory();
3914
+ /**
3915
+ * 全局的UI对象库,用于管理一些常用的ui对象,例如主界面,背包
3916
+ */
3917
+ var uirepo = new UIObjectRepo();
4056
3918
 
4057
- class PageController extends ViewController {
4058
- constructor(routeName) {
4059
- super(routeName);
4060
- this._enableHistory = false;
4061
- this._layer = "";
4062
- }
3919
+ var ViewState;
3920
+ (function (ViewState) {
4063
3921
  /**
4064
- * 打开视图,如果视图已经存在则刷新视图
4065
- * @param route
3922
+ * 关闭
4066
3923
  */
4067
- open(route) {
4068
- let view = viewrepo.getByRoute(route);
4069
- if (view) { //
4070
- this.refreshView(view);
3924
+ ViewState[ViewState["Closed"] = 0] = "Closed";
3925
+ /**
3926
+ * 正在打开
3927
+ */
3928
+ ViewState[ViewState["Opening"] = 1] = "Opening";
3929
+ /**
3930
+ * 已打开
3931
+ */
3932
+ ViewState[ViewState["Opened"] = 2] = "Opened";
3933
+ /**
3934
+ * 正在关闭
3935
+ */
3936
+ ViewState[ViewState["Closeing"] = 3] = "Closeing";
3937
+ })(ViewState || (ViewState = {}));
3938
+ var ViewEvent;
3939
+ (function (ViewEvent) {
3940
+ // 正在打开
3941
+ ViewEvent["Opening"] = "opening";
3942
+ // 已打开
3943
+ ViewEvent["Opened"] = "opened";
3944
+ // 正在打开
3945
+ ViewEvent["Closeing"] = "closeing";
3946
+ // 已关闭
3947
+ ViewEvent["Closed"] = "closed";
3948
+ // 停止
3949
+ ViewEvent["Stop"] = "stop";
3950
+ })(ViewEvent || (ViewEvent = {}));
3951
+ class RouteView extends EventDispatcher {
3952
+ constructor(controller, route) {
3953
+ super();
3954
+ this._waitOpenComplete = false;
3955
+ this._waitCloseComplete = false;
3956
+ this.datas = {};
3957
+ this.tags = {};
3958
+ this.enableHistory = false;
3959
+ this.state = 0;
3960
+ this._controller = controller;
3961
+ this._route = route;
3962
+ }
3963
+ open() {
3964
+ if (this.state != ViewState.Closed) {
4071
3965
  return;
4072
3966
  }
4073
- // 关闭同一层的所有视图
4074
- this.closeExclusion((existed) => {
4075
- return existed.layer == this._layer;
4076
- });
4077
- if (this.enableHistory) {
4078
- viewhistorys.push(route);
3967
+ let route = this.route;
3968
+ if (viewrepo.get(route.key)) {
3969
+ throw `视图已存在: route=${route.key}`;
3970
+ }
3971
+ viewrepo.set(route.key, this);
3972
+ this.state = ViewState.Opening;
3973
+ this.dispatch(ViewEvent.Opening);
3974
+ //
3975
+ try {
3976
+ //
3977
+ if (this.onOpen) {
3978
+ this.onOpen.call(this);
3979
+ }
3980
+ // @ts-ignore
3981
+ if (!this._waitOpenComplete) {
3982
+ // 没有被打断,打开完成
3983
+ this.openComplete();
3984
+ }
3985
+ else {
3986
+ // 被打断了,等待完成1
3987
+ }
3988
+ }
3989
+ catch (e) {
3990
+ console.error(`open view ${this.route.key}`);
3991
+ console.error(e.stack);
3992
+ //
3993
+ this.close();
3994
+ }
3995
+ }
3996
+ close() {
3997
+ if (this.state == ViewState.Closed) {
3998
+ return;
3999
+ }
4000
+ this.state = ViewState.Closeing;
4001
+ this.dispatch(ViewEvent.Closeing);
4002
+ try {
4003
+ if (this.onClose) {
4004
+ this.onClose.call(this);
4005
+ }
4006
+ // @ts-ignore
4007
+ if (!this._waitCloseComplete) {
4008
+ // 没有被打断,关闭完成
4009
+ this.closeComplete();
4010
+ }
4011
+ else {
4012
+ // 被打断了,等待完成1
4013
+ }
4014
+ }
4015
+ catch (e) {
4016
+ console.error(`close view ${this.route.key}`);
4017
+ console.error(e.stack);
4018
+ }
4019
+ }
4020
+ refresh() {
4021
+ try {
4022
+ if (this.onRefresh) {
4023
+ this.onClose.call(this);
4024
+ }
4025
+ // @ts-ignore
4026
+ if (!this._waitCloseComplete) {
4027
+ // 没有被打断,关闭完成
4028
+ this.closeComplete();
4029
+ }
4030
+ else {
4031
+ // 被打断了,等待完成1
4032
+ }
4033
+ }
4034
+ catch (e) {
4035
+ console.error(`refresh view ${this.route.key}`);
4036
+ console.error(e.stack);
4079
4037
  }
4080
- view = new View(this, route);
4081
- this.openView(view);
4082
- return view;
4083
4038
  }
4084
4039
  /**
4085
- * @param route
4086
- * @returns
4040
+ * 等待发送的结果
4041
+ * 如果返回 null,表示主动取消 [cancel]
4087
4042
  */
4088
- close(route) {
4089
- let lastview;
4090
- if (this._layer) {
4091
- if (this._enableHistory) {
4092
- // 清空历史记录
4093
- viewhistorys.clear();
4094
- }
4043
+ wait() {
4044
+ switch (this.state) {
4045
+ case ViewState.Opening:
4046
+ return new Promise((resolve, reject) => {
4047
+ let opened = () => {
4048
+ this.off("opened", this, opened);
4049
+ this.off("canceled", this, opened);
4050
+ resolve(this);
4051
+ };
4052
+ let canceled = () => {
4053
+ this.off("opened", this, opened);
4054
+ this.off("canceled", this, opened);
4055
+ resolve(this);
4056
+ };
4057
+ this.on("opened", this, opened);
4058
+ this.on("canceled", this, canceled);
4059
+ });
4060
+ case ViewState.Closeing:
4061
+ return new Promise((resolve, reject) => {
4062
+ let opened = () => {
4063
+ this.off("closed", this, opened);
4064
+ resolve(this);
4065
+ };
4066
+ this.on("closed", this, opened);
4067
+ });
4068
+ default:
4069
+ return new Promise((resolve, reject) => {
4070
+ resolve(this);
4071
+ });
4095
4072
  }
4096
- else {
4097
- lastview = viewrepo.getByRoute(route);
4073
+ }
4074
+ toString() {
4075
+ return `View[${this.route.toString()}, ${this.id}]`;
4076
+ }
4077
+ /**
4078
+ * 等待打开完成指令
4079
+ */
4080
+ waitOpenComplete() {
4081
+ this._waitOpenComplete = true;
4082
+ }
4083
+ openComplete() {
4084
+ this.state = ViewState.Opened;
4085
+ // @ts-ignore
4086
+ this._waitOpenComplete = false;
4087
+ if (this.onOpened) {
4088
+ this.onOpened.call(this);
4098
4089
  }
4099
- this.closeView(lastview);
4100
- return lastview;
4090
+ this.dispatch(ViewEvent.Opened);
4101
4091
  }
4102
- useHistory() {
4103
- this._enableHistory = true;
4104
- return this;
4092
+ waitCloseComplete(view) {
4093
+ // @ts-ignore
4094
+ view._waitCloseComplete = true;
4095
+ }
4096
+ closeComplete() {
4097
+ viewrepo.delete(this.route.key);
4098
+ this._waitCloseComplete = false;
4099
+ this.state = ViewState.Closed;
4100
+ this.dispatch(ViewEvent.Closed);
4101
+ if (this.onClosed) {
4102
+ this.onClosed.call(this);
4103
+ }
4104
+ }
4105
+ get controller() {
4106
+ return this._controller;
4105
4107
  }
4106
4108
  get route() {
4107
4109
  return this._route;
4108
4110
  }
4109
- get enableHistory() {
4110
- return this._enableHistory;
4111
- }
4112
4111
  }
4113
4112
 
4114
4113
  class Listener {
@@ -6384,5 +6383,5 @@ class WidgetUtil {
6384
6383
  }
6385
6384
  var widgetutil = new WidgetUtil();
6386
6385
 
6387
- export { ArrayUtil, AssetLoader, AssetURI, BitUtil, CallbackList, CameraUtil, CanvasUtil, Controller, ControllerDict, ControllerRepo, ConvertUtil, DictIterator, DictNode, DictSource, Dictionary, Dispatcher, DocUtil, ErrorUtil, EventDispatcher, EventItem, EventUtil, Factory, FloatUtil, GeometryUtil, IdentUtil, LOGGER_EVENT, LinkError, List, ListIterator, ListNode, ListSource, Listener, LogLevel, LogManager, Logger, MapUtil, MathUtil, Model, NetUtil, PageController, PathUtil, Pool, RandUtil, Route, RouteList, SampleCallbackList, SamplePool, SamplePoolSet, ScaleUtil, SimpleModel, StringUtil, TimeUtil, Timer, TreeIterator, TreeNode, TreeNodePlugin, TreeRoot, TreeRootPlugin, TreeUtil, UIManager, UIObjectDict, UIPoolConfig, UISingleConfig, UIUtil, View, ViewController, ViewDict, ViewEvent, ViewHistory, ViewList, ViewRepo, ViewState, WidgetAlign, WidgetUtil, XAssetManager, XEvent, arrayutil, assetx, bitutil, camerautil, canvasutil, convertutil, ctrlrepo, docutil, errorutil, eventmgr, eventutil, floatutil, formatutil, geoutil, identutil, loadAtlas, logmgr, maputil, mathutil, netutil, parseAtlas, parsePlist, pathutil, randutil, resutil, scaleutil, stringutil, timer, timeutil, treeutil, uidict, uimgr, uiutil, viewhistorys, viewrepo, widgetutil };
6386
+ export { ArrayUtil, AssetLoader, AssetURI, BitUtil, CallbackList, CameraUtil, CanvasUtil, CloseDialogHandler, ClosePageHandler, Controller, ControllerDict, ControllerRepo, ConvertUtil, DictIterator, DictNode, DictSource, Dictionary, Dispatcher, DocUtil, ErrorUtil, EventDispatcher, EventItem, EventUtil, Factory, FloatUtil, GeometryUtil, IdentUtil, LOGGER_EVENT, LinkError, List, ListIterator, ListNode, ListSource, Listener, LogLevel, LogManager, Logger, MapUtil, MathUtil, Model, NetUtil, OpenDialogHandler, OpenPageHandler, PathUtil, Pool, RandUtil, Route, RouteController, RouteList, RouteView, SampleCallbackList, SamplePool, SamplePoolSet, ScaleUtil, SimpleModel, StringUtil, TimeUtil, Timer, TreeIterator, TreeNode, TreeNodePlugin, TreeRoot, TreeRootPlugin, TreeUtil, UIManager, UIObjectRepo, UIPoolConfig, UISingleConfig, UIUtil, ViewDict, ViewEvent, ViewHistory, ViewList, ViewRepo, ViewState, WidgetAlign, WidgetUtil, XAssetManager, XEvent, arrayutil, assetx, bitutil, camerautil, canvasutil, convertutil, ctrlrepo, docutil, errorutil, eventmgr, eventutil, floatutil, formatutil, geoutil, identutil, loadAtlas, logmgr, maputil, mathutil, netutil, parseAtlas, parsePlist, pathutil, randutil, resutil, scaleutil, stringutil, timer, timeutil, treeutil, uimgr, uirepo, uiutil, viewhistorys, viewrepo, widgetutil };
6388
6387
  //# sourceMappingURL=index.esm.js.map