@singularsystems/neo-react 1.0.0-alpha.2 → 1.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (196) hide show
  1. package/CHANGELOG.md +98 -0
  2. package/README.md +4 -0
  3. package/dist/Modules/NeoReactModule.d.ts +4 -4
  4. package/dist/Modules/NeoReactModule.js +28 -26
  5. package/dist/Modules/ReactSetup.d.ts +2 -2
  6. package/dist/Modules/ReactSetup.js +17 -17
  7. package/dist/Modules/Types.d.ts +63 -61
  8. package/dist/Modules/Types.js +13 -12
  9. package/dist/React/AutoRunner.d.ts +5 -5
  10. package/dist/React/AutoRunner.js +94 -92
  11. package/dist/React/DataView.d.ts +6 -6
  12. package/dist/React/DataView.js +11 -11
  13. package/dist/React/ReactModelCreator.d.ts +11 -11
  14. package/dist/React/ReactModelCreator.js +165 -162
  15. package/dist/ReactComponents/Button.d.ts +24 -23
  16. package/dist/ReactComponents/Button.js +131 -123
  17. package/dist/ReactComponents/Card.d.ts +24 -23
  18. package/dist/ReactComponents/Card.js +56 -54
  19. package/dist/ReactComponents/Collapsable.d.ts +23 -23
  20. package/dist/ReactComponents/Collapsable.js +38 -38
  21. package/dist/ReactComponents/CollapsableBase.d.ts +13 -13
  22. package/dist/ReactComponents/CollapsableBase.js +42 -42
  23. package/dist/ReactComponents/ColorPicker.d.ts +26 -26
  24. package/dist/ReactComponents/ColorPicker.js +67 -67
  25. package/dist/ReactComponents/ComponentBase.d.ts +17 -17
  26. package/dist/ReactComponents/ComponentBase.js +33 -33
  27. package/dist/ReactComponents/ContextMenu/ContextMenu.d.ts +25 -24
  28. package/dist/ReactComponents/ContextMenu/ContextMenu.js +91 -88
  29. package/dist/ReactComponents/ContextMenu/ContextMenuContainer.d.ts +14 -14
  30. package/dist/ReactComponents/ContextMenu/ContextMenuContainer.js +48 -48
  31. package/dist/ReactComponents/ContextMenu/ContextMenuState.d.ts +8 -7
  32. package/dist/ReactComponents/ContextMenu/ContextMenuState.js +23 -23
  33. package/dist/ReactComponents/DatePicker.d.ts +19 -19
  34. package/dist/ReactComponents/DatePicker.js +53 -53
  35. package/dist/ReactComponents/DropDown/AutoCompleteDropDown.d.ts +93 -83
  36. package/dist/ReactComponents/DropDown/AutoCompleteDropDown.js +222 -188
  37. package/dist/ReactComponents/DropDown/DropDown.d.ts +44 -44
  38. package/dist/ReactComponents/DropDown/DropDown.js +138 -134
  39. package/dist/ReactComponents/DropDown/DropDownBase.d.ts +16 -15
  40. package/dist/ReactComponents/DropDown/DropDownBase.js +86 -108
  41. package/dist/ReactComponents/DropDown/LookupHelper.d.ts +13 -0
  42. package/dist/ReactComponents/DropDown/LookupHelper.js +45 -0
  43. package/dist/ReactComponents/ErrorHandler.d.ts +9 -8
  44. package/dist/ReactComponents/ErrorHandler.js +92 -91
  45. package/dist/ReactComponents/FileManager/FileBasicInput.d.ts +20 -20
  46. package/dist/ReactComponents/FileManager/FileBasicInput.js +70 -70
  47. package/dist/ReactComponents/FileManager/FileContext.d.ts +16 -16
  48. package/dist/ReactComponents/FileManager/FileContext.js +24 -24
  49. package/dist/ReactComponents/FileManager/FileDropArea.d.ts +19 -18
  50. package/dist/ReactComponents/FileManager/FileDropArea.js +66 -64
  51. package/dist/ReactComponents/FileManager/FileInput.d.ts +44 -42
  52. package/dist/ReactComponents/FileManager/FileInput.js +191 -189
  53. package/dist/ReactComponents/FileManager/FileUploadButton.d.ts +17 -17
  54. package/dist/ReactComponents/FileManager/FileUploadButton.js +49 -49
  55. package/dist/ReactComponents/FileManager/FileUploadProgress.d.ts +14 -14
  56. package/dist/ReactComponents/FileManager/FileUploadProgress.js +35 -35
  57. package/dist/ReactComponents/Form.d.ts +19 -18
  58. package/dist/ReactComponents/Form.js +90 -90
  59. package/dist/ReactComponents/FormContext.d.ts +33 -31
  60. package/dist/ReactComponents/FormContext.js +39 -40
  61. package/dist/ReactComponents/FormGroup/FormGroup.d.ts +37 -37
  62. package/dist/ReactComponents/FormGroup/FormGroup.js +83 -84
  63. package/dist/ReactComponents/FormGroup/FormGroupFloating.d.ts +19 -19
  64. package/dist/ReactComponents/FormGroup/FormGroupFloating.js +97 -97
  65. package/dist/ReactComponents/FormGroup/FormGroupInline.d.ts +11 -11
  66. package/dist/ReactComponents/FormGroup/FormGroupInline.js +43 -43
  67. package/dist/ReactComponents/Grid/ButtonColumn.d.ts +47 -47
  68. package/dist/ReactComponents/Grid/ButtonColumn.js +81 -82
  69. package/dist/ReactComponents/Grid/Column.d.ts +47 -47
  70. package/dist/ReactComponents/Grid/Column.js +205 -205
  71. package/dist/ReactComponents/Grid/ColumnHelper.d.ts +12 -12
  72. package/dist/ReactComponents/Grid/ColumnHelper.js +19 -19
  73. package/dist/ReactComponents/Grid/Grid.d.ts +87 -90
  74. package/dist/ReactComponents/Grid/Grid.js +203 -203
  75. package/dist/ReactComponents/Grid/Row.d.ts +81 -81
  76. package/dist/ReactComponents/Grid/Row.js +200 -201
  77. package/dist/ReactComponents/Grid/_Exports.d.ts +5 -5
  78. package/dist/ReactComponents/Grid/_Exports.js +5 -5
  79. package/dist/ReactComponents/GridLayout.d.ts +20 -20
  80. package/dist/ReactComponents/GridLayout.js +38 -38
  81. package/dist/ReactComponents/Icons/FontAwesomeIconFactory.d.ts +23 -0
  82. package/dist/ReactComponents/Icons/FontAwesomeIconFactory.js +43 -0
  83. package/dist/ReactComponents/Icons/IIconFactory.d.ts +21 -0
  84. package/dist/ReactComponents/Icons/IIconFactory.js +1 -0
  85. package/dist/ReactComponents/Icons/IconFactory.d.ts +9 -0
  86. package/dist/ReactComponents/Icons/IconFactory.js +45 -0
  87. package/dist/ReactComponents/Icons/index.d.ts +3 -0
  88. package/dist/ReactComponents/Icons/index.js +2 -0
  89. package/dist/ReactComponents/Input.d.ts +45 -45
  90. package/dist/ReactComponents/Input.js +153 -152
  91. package/dist/ReactComponents/InputHelpers.d.ts +6 -5
  92. package/dist/ReactComponents/InputHelpers.js +29 -33
  93. package/dist/ReactComponents/Link.d.ts +13 -13
  94. package/dist/ReactComponents/Link.js +28 -28
  95. package/dist/ReactComponents/Loader.d.ts +18 -18
  96. package/dist/ReactComponents/Loader.js +57 -57
  97. package/dist/ReactComponents/Misc.d.ts +15 -15
  98. package/dist/ReactComponents/Misc.js +28 -28
  99. package/dist/ReactComponents/Modal/Modal.d.ts +11 -11
  100. package/dist/ReactComponents/Modal/Modal.js +129 -129
  101. package/dist/ReactComponents/Modal/ModalContainer.d.ts +17 -17
  102. package/dist/ReactComponents/Modal/ModalContainer.js +37 -37
  103. package/dist/ReactComponents/Modal/ModalPortal.d.ts +16 -15
  104. package/dist/ReactComponents/Modal/ModalPortal.js +27 -27
  105. package/dist/ReactComponents/Notifications/Alert.d.ts +7 -6
  106. package/dist/ReactComponents/Notifications/Alert.js +38 -35
  107. package/dist/ReactComponents/Notifications/Toast.d.ts +9 -8
  108. package/dist/ReactComponents/Notifications/Toast.js +47 -45
  109. package/dist/ReactComponents/Notifications/ToastContainer.d.ts +8 -8
  110. package/dist/ReactComponents/Notifications/ToastContainer.js +18 -18
  111. package/dist/ReactComponents/NumberInput.d.ts +57 -50
  112. package/dist/ReactComponents/NumberInput.js +260 -246
  113. package/dist/ReactComponents/Paging/BasicPagerControls.d.ts +26 -25
  114. package/dist/ReactComponents/Paging/BasicPagerControls.js +57 -55
  115. package/dist/ReactComponents/Paging/PageSizeControl.d.ts +11 -11
  116. package/dist/ReactComponents/Paging/PageSizeControl.js +21 -21
  117. package/dist/ReactComponents/Paging/Pager.d.ts +24 -24
  118. package/dist/ReactComponents/Paging/Pager.js +41 -41
  119. package/dist/ReactComponents/ProgressBar.d.ts +19 -19
  120. package/dist/ReactComponents/ProgressBar.js +52 -52
  121. package/dist/ReactComponents/PropTypes.d.ts +161 -161
  122. package/dist/ReactComponents/PropTypes.js +253 -236
  123. package/dist/ReactComponents/RadioList.d.ts +29 -29
  124. package/dist/ReactComponents/RadioList.js +59 -77
  125. package/dist/ReactComponents/Slider.d.ts +28 -28
  126. package/dist/ReactComponents/Slider.js +76 -76
  127. package/dist/ReactComponents/StateObserver.d.ts +15 -15
  128. package/dist/ReactComponents/StateObserver.js +35 -35
  129. package/dist/ReactComponents/Tabs/Tab.d.ts +42 -41
  130. package/dist/ReactComponents/Tabs/Tab.js +71 -72
  131. package/dist/ReactComponents/Tabs/TabContainer.d.ts +44 -44
  132. package/dist/ReactComponents/Tabs/TabContainer.js +98 -98
  133. package/dist/ReactComponents/Tabs/TabManager.d.ts +62 -62
  134. package/dist/ReactComponents/Tabs/TabManager.js +154 -154
  135. package/dist/ReactComponents/Tooltip.d.ts +20 -19
  136. package/dist/ReactComponents/Tooltip.js +51 -51
  137. package/dist/ReactComponents/TooltipHelper.d.ts +8 -8
  138. package/dist/ReactComponents/TooltipHelper.js +84 -84
  139. package/dist/ReactComponents/TooltipProvider.d.ts +30 -30
  140. package/dist/ReactComponents/TooltipProvider.js +111 -111
  141. package/dist/ReactComponents/ValidationSummary.d.ts +23 -22
  142. package/dist/ReactComponents/ValidationSummary.js +46 -43
  143. package/dist/ReactComponents/_Exports.d.ts +41 -41
  144. package/dist/ReactComponents/_Exports.js +41 -41
  145. package/dist/ReactComponents/_Managers.d.ts +4 -4
  146. package/dist/ReactComponents/_Managers.js +4 -4
  147. package/dist/Routing/BreadCrumbItem.d.ts +14 -14
  148. package/dist/Routing/BreadCrumbItem.js +12 -12
  149. package/dist/Routing/IRouteChangedProps.d.ts +31 -31
  150. package/dist/Routing/IRouteChangedProps.js +1 -1
  151. package/dist/Routing/IRouteParameter.d.ts +22 -22
  152. package/dist/Routing/IRouteParameter.js +9 -9
  153. package/dist/Routing/MenuRoute.d.ts +25 -24
  154. package/dist/Routing/MenuRoute.js +24 -24
  155. package/dist/Routing/NavigationHelper.d.ts +41 -40
  156. package/dist/Routing/NavigationHelper.js +61 -61
  157. package/dist/Routing/PageLeaveHandler.d.ts +13 -13
  158. package/dist/Routing/PageLeaveHandler.js +74 -74
  159. package/dist/Routing/RouteProvider.d.ts +31 -31
  160. package/dist/Routing/RouteProvider.js +92 -92
  161. package/dist/Routing/RouteView.d.ts +50 -50
  162. package/dist/Routing/RouteView.js +143 -144
  163. package/dist/Routing/RoutingState.d.ts +18 -15
  164. package/dist/Routing/RoutingState.js +45 -40
  165. package/dist/Routing/ViewParameter.d.ts +80 -58
  166. package/dist/Routing/ViewParameter.js +116 -95
  167. package/dist/Routing/ViewParameterList.d.ts +53 -53
  168. package/dist/Routing/ViewParameterList.js +163 -145
  169. package/dist/Routing/index.d.ts +9 -9
  170. package/dist/Routing/index.js +6 -6
  171. package/dist/Services/DisposeHelper.d.ts +15 -15
  172. package/dist/Services/DisposeHelper.js +40 -41
  173. package/dist/Services/IDisposeHelper.d.ts +12 -12
  174. package/dist/Services/IDisposeHelper.js +1 -1
  175. package/dist/Views/EmptyViewModel.d.ts +5 -5
  176. package/dist/Views/EmptyViewModel.js +14 -14
  177. package/dist/Views/IViewModel.d.ts +16 -16
  178. package/dist/Views/IViewModel.js +1 -1
  179. package/dist/Views/PersistentViewBase.d.ts +10 -10
  180. package/dist/Views/PersistentViewBase.js +21 -21
  181. package/dist/Views/ViewBase.d.ts +70 -71
  182. package/dist/Views/ViewBase.js +166 -153
  183. package/dist/Views/ViewComponentBase.d.ts +19 -13
  184. package/dist/Views/ViewComponentBase.js +24 -21
  185. package/dist/Views/ViewModelBase.d.ts +57 -56
  186. package/dist/Views/ViewModelBase.js +122 -118
  187. package/dist/Views/ViewState.d.ts +13 -13
  188. package/dist/Views/ViewState.js +9 -9
  189. package/dist/Views/index.d.ts +5 -5
  190. package/dist/Views/index.js +5 -5
  191. package/dist/index.d.ts +11 -10
  192. package/dist/index.js +10 -9
  193. package/package.json +26 -26
  194. package/styles/DatePicker.scss +2 -2
  195. package/styles/Forms.scss +5 -0
  196. package/styles/Validation.scss +0 -9
@@ -1,153 +1,166 @@
1
- import { __decorate, __extends, __metadata } from "tslib";
2
- import React from 'react';
3
- import { observable } from 'mobx';
4
- import { Misc } from '@singularsystems/neo-core';
5
- import { ViewParameterList } from '../Routing/ViewParameterList';
6
- import { ViewState } from './ViewState';
7
- import { BreadCrumbItem } from '../Routing/BreadCrumbItem';
8
- import { NeoReactTypes } from '../Modules/Types';
9
- import ViewModelBase from './ViewModelBase';
10
- var ViewBase = /** @class */ (function (_super) {
11
- __extends(ViewBase, _super);
12
- /**
13
- * Creates a view
14
- * @param props React props.
15
- * @param viewName Name of the view.
16
- * @param viewModel Instance of view model, or view model type, or callback which returns a view model.
17
- */
18
- function ViewBase(viewName, viewModel, props) {
19
- var _this = _super.call(this, props) || this;
20
- _this.viewName = "";
21
- _this.routingState = Misc.Globals.appService.get(NeoReactTypes.Routing.GlobalRoutingState);
22
- _this.navigation = Misc.Globals.appService.get(NeoReactTypes.Routing.NavigationHelper);
23
- if (typeof viewName !== "string") {
24
- throw "Error: When inheriting ViewBase, you must pass the view name into the base constructor.";
25
- }
26
- _this.viewName = viewName;
27
- _this.viewState = _this.getStoredViewState(viewModel);
28
- ViewBase.currentView = _this;
29
- return _this;
30
- }
31
- Object.defineProperty(ViewBase.prototype, "viewModel", {
32
- get: function () {
33
- return this.viewState.viewModel;
34
- },
35
- enumerable: false,
36
- configurable: true
37
- });
38
- Object.defineProperty(ViewBase.prototype, "taskRunner", {
39
- get: function () {
40
- return this.viewModel.taskRunner;
41
- },
42
- enumerable: false,
43
- configurable: true
44
- });
45
- Object.defineProperty(ViewBase.prototype, "viewParams", {
46
- get: function () {
47
- return this.viewState.viewParams;
48
- },
49
- enumerable: false,
50
- configurable: true
51
- });
52
- ViewBase.prototype.getStoredViewState = function (viewModel) {
53
- return this.createViewState(viewModel);
54
- };
55
- ViewBase.prototype.createViewState = function (viewModel) {
56
- var params = this.constructor.params;
57
- var paramsList = new ViewParameterList(params, this);
58
- var viewModelInstance = ViewModelBase.create(viewModel);
59
- return new ViewState(paramsList, viewModelInstance);
60
- };
61
- ViewBase.prototype.componentDidMount = function () {
62
- var _this = this;
63
- var paramsUpdated = this.navigation.currentRouteProps ? this.viewState.viewParams.update(this.navigation.currentRouteProps.match) : false;
64
- var initPromise;
65
- if (!this.viewState.hasSetup) {
66
- this.viewState.hasSetup = true;
67
- initPromise = this.initialise();
68
- }
69
- if (paramsUpdated) {
70
- if (initPromise) {
71
- initPromise.then(function () { return _this.viewParamsUpdated(); });
72
- }
73
- else {
74
- this.viewParamsUpdated();
75
- }
76
- }
77
- };
78
- ViewBase.prototype.componentWillUnmount = function () {
79
- this.disposeViewModel();
80
- };
81
- ViewBase.prototype.updateViewParams = function (match) {
82
- if (this.viewState.viewParams.update(match)) {
83
- this.viewParamsUpdated();
84
- }
85
- };
86
- /**
87
- * viewParamsUpdated() is called when the component is mounted, and whenever a route parameter or query parameter gets a changed value.
88
- */
89
- ViewBase.prototype.viewParamsUpdated = function () {
90
- };
91
- /** Gets the parent breadcrumbs, and the breadcrumb for this view. */
92
- ViewBase.prototype.getBreadCrumbStart = function () {
93
- var _this = this;
94
- var items = [];
95
- // Get parent items
96
- var menuRoute = this.routingState.currentRoute;
97
- var parent = menuRoute.breadCrumbParent;
98
- while (parent) {
99
- items.splice(0, 0, new BreadCrumbItem(parent.name, parent.path));
100
- parent = parent.breadCrumbParent;
101
- }
102
- // Add view name
103
- var firstParam = this.viewState.viewParams.params[0];
104
- items.push(new BreadCrumbItem(function () { return _this.viewName; }, (firstParam === null || firstParam === void 0 ? void 0 : firstParam.routeParameter.required) ? "" : this.navigation.getCurrentViewPath()));
105
- return items;
106
- };
107
- /**
108
- * Initialise is called from componentDidMount().
109
- * Will only be called once per persistent view for the lifetime of the app.
110
- * If overridden, you must call super.initialise() to initialise the ViewModel.
111
- */
112
- ViewBase.prototype.initialise = function () {
113
- return this.viewModel.initialise();
114
- };
115
- ViewBase.prototype.disposeViewModel = function () {
116
- this.viewModel.dispose();
117
- };
118
- ViewBase.prototype.getBreadCrumbList = function () {
119
- var breadCrumbList = [];
120
- if (!this.breadCrumbStartItems) {
121
- this.breadCrumbStartItems = this.getBreadCrumbStart();
122
- }
123
- breadCrumbList.push.apply(breadCrumbList, this.breadCrumbStartItems);
124
- breadCrumbList.push.apply(breadCrumbList, this.viewParams.getBreadCrumbList());
125
- return breadCrumbList;
126
- };
127
- /**
128
- * Called when the user navigates to a new view, or when exiting the site.
129
- * Return a string to show to the user in a dialog.
130
- */
131
- ViewBase.prototype.onLeave = function () {
132
- return undefined;
133
- };
134
- /**
135
- * Called whenever the route changes. Including navigating to a new view, leaving the site, or changing a route parameter in this view.
136
- * Note: if props.leavePrompt is set, onLeave() will not be called.
137
- * @param props
138
- */
139
- ViewBase.prototype.beforeRouteChanged = function (props) {
140
- };
141
- /** Represents the view that is currently being displayed */
142
- ViewBase.currentView = null;
143
- __decorate([
144
- observable.ref,
145
- __metadata("design:type", String)
146
- ], ViewBase.prototype, "viewName", void 0);
147
- __decorate([
148
- observable.ref,
149
- __metadata("design:type", Object)
150
- ], ViewBase, "currentView", void 0);
151
- return ViewBase;
152
- }(React.Component));
153
- export default ViewBase;
1
+ import { __awaiter, __decorate, __extends, __generator, __metadata } from "tslib";
2
+ import React from 'react';
3
+ import { observable, runInAction } from 'mobx';
4
+ import { Misc } from '@singularsystems/neo-core';
5
+ import { ViewParameterList } from '../Routing/ViewParameterList';
6
+ import { ViewState } from './ViewState';
7
+ import { BreadCrumbItem } from '../Routing/BreadCrumbItem';
8
+ import { NeoReactTypes } from '../Modules/Types';
9
+ import ViewModelBase from './ViewModelBase';
10
+ var ViewBase = /** @class */ (function (_super) {
11
+ __extends(ViewBase, _super);
12
+ /**
13
+ * Creates a view
14
+ * @param props React props.
15
+ * @param viewName Name of the view.
16
+ * @param viewModel Instance of view model, or view model type, or callback which returns a view model.
17
+ */
18
+ function ViewBase(viewName, viewModel, props) {
19
+ var _this = _super.call(this, props) || this;
20
+ _this.viewName = "";
21
+ _this.routingState = Misc.Globals.appService.get(NeoReactTypes.Routing.GlobalRoutingState);
22
+ _this.navigation = Misc.Globals.appService.get(NeoReactTypes.Routing.NavigationHelper);
23
+ if (typeof viewName !== "string") {
24
+ throw "Error: When inheriting ViewBase, you must pass the view name into the base constructor.";
25
+ }
26
+ _this.viewName = viewName;
27
+ _this.viewState = _this.getStoredViewState(viewModel);
28
+ _this.routingState.currentView = _this;
29
+ return _this;
30
+ }
31
+ Object.defineProperty(ViewBase, "currentView", {
32
+ // For backwards compatibility
33
+ get: function () {
34
+ return Misc.Globals.appService.get(NeoReactTypes.Routing.GlobalRoutingState).currentView;
35
+ },
36
+ enumerable: false,
37
+ configurable: true
38
+ });
39
+ Object.defineProperty(ViewBase.prototype, "viewModel", {
40
+ get: function () {
41
+ return this.viewState.viewModel;
42
+ },
43
+ enumerable: false,
44
+ configurable: true
45
+ });
46
+ Object.defineProperty(ViewBase.prototype, "taskRunner", {
47
+ get: function () {
48
+ return this.viewModel.taskRunner;
49
+ },
50
+ enumerable: false,
51
+ configurable: true
52
+ });
53
+ Object.defineProperty(ViewBase.prototype, "viewParams", {
54
+ get: function () {
55
+ return this.viewState.viewParams;
56
+ },
57
+ enumerable: false,
58
+ configurable: true
59
+ });
60
+ ViewBase.prototype.getStoredViewState = function (viewModel) {
61
+ return this.createViewState(viewModel);
62
+ };
63
+ ViewBase.prototype.createViewState = function (viewModel) {
64
+ var params = this.constructor.params;
65
+ var paramsList = new ViewParameterList(params, this);
66
+ var viewModelInstance = ViewModelBase.create(viewModel);
67
+ return new ViewState(paramsList, viewModelInstance);
68
+ };
69
+ ViewBase.prototype.componentDidMount = function () {
70
+ var _this = this;
71
+ var paramsUpdated = this.navigation.currentRouteProps ? this.viewState.viewParams.update(this.navigation.currentRouteProps.match) : false;
72
+ var initPromise;
73
+ if (!this.viewState.hasSetup) {
74
+ this.viewState.hasSetup = true;
75
+ initPromise = this.initialise();
76
+ }
77
+ if (paramsUpdated) {
78
+ if (initPromise) {
79
+ initPromise.then(function () { return _this.viewParamsUpdated(); });
80
+ }
81
+ else {
82
+ this.viewParamsUpdated();
83
+ }
84
+ }
85
+ };
86
+ ViewBase.prototype.componentWillUnmount = function () {
87
+ this.disposeViewModel();
88
+ };
89
+ ViewBase.prototype.updateViewParams = function (match) {
90
+ var _this = this;
91
+ runInAction(function () { return __awaiter(_this, void 0, void 0, function () {
92
+ return __generator(this, function (_a) {
93
+ switch (_a.label) {
94
+ case 0:
95
+ if (!this.viewState.viewParams.update(match)) return [3 /*break*/, 2];
96
+ return [4 /*yield*/, Promise.resolve(this.viewParamsUpdated())];
97
+ case 1:
98
+ _a.sent();
99
+ _a.label = 2;
100
+ case 2: return [2 /*return*/];
101
+ }
102
+ });
103
+ }); });
104
+ };
105
+ /**
106
+ * viewParamsUpdated() is called when the component is mounted, and whenever a route parameter or query parameter gets a changed value.
107
+ */
108
+ ViewBase.prototype.viewParamsUpdated = function () {
109
+ };
110
+ /** Gets the parent breadcrumbs, and the breadcrumb for this view. */
111
+ ViewBase.prototype.getBreadCrumbStart = function () {
112
+ var _this = this;
113
+ var items = [];
114
+ // Get parent items
115
+ var menuRoute = this.routingState.currentRoute;
116
+ var parent = menuRoute.breadCrumbParent;
117
+ while (parent) {
118
+ items.splice(0, 0, new BreadCrumbItem(parent.name, parent.path));
119
+ parent = parent.breadCrumbParent;
120
+ }
121
+ // Add view name
122
+ var firstParam = this.viewState.viewParams.params[0];
123
+ items.push(new BreadCrumbItem(function () { return _this.viewName; }, (firstParam === null || firstParam === void 0 ? void 0 : firstParam.routeParameter.required) ? "" : this.navigation.getCurrentViewPath()));
124
+ return items;
125
+ };
126
+ /**
127
+ * Initialise is called from componentDidMount().
128
+ * Will only be called once per persistent view for the lifetime of the app.
129
+ * If overridden, you must call super.initialise() to initialise the ViewModel.
130
+ */
131
+ ViewBase.prototype.initialise = function () {
132
+ return this.viewModel.initialise();
133
+ };
134
+ ViewBase.prototype.disposeViewModel = function () {
135
+ this.viewModel.dispose();
136
+ };
137
+ ViewBase.prototype.getBreadCrumbList = function () {
138
+ var breadCrumbList = [];
139
+ if (!this.breadCrumbStartItems) {
140
+ this.breadCrumbStartItems = this.getBreadCrumbStart();
141
+ }
142
+ breadCrumbList.push.apply(breadCrumbList, this.breadCrumbStartItems);
143
+ breadCrumbList.push.apply(breadCrumbList, this.viewParams.getBreadCrumbList());
144
+ return breadCrumbList;
145
+ };
146
+ /**
147
+ * Called when the user navigates to a new view, or when exiting the site.
148
+ * Return a string to show to the user in a dialog.
149
+ */
150
+ ViewBase.prototype.onLeave = function () {
151
+ return undefined;
152
+ };
153
+ /**
154
+ * Called whenever the route changes. Including navigating to a new view, leaving the site, or changing a route parameter in this view.
155
+ * Note: if props.leavePrompt is set, onLeave() will not be called.
156
+ * @param props
157
+ */
158
+ ViewBase.prototype.beforeRouteChanged = function (props) {
159
+ };
160
+ __decorate([
161
+ observable.ref,
162
+ __metadata("design:type", String)
163
+ ], ViewBase.prototype, "viewName", void 0);
164
+ return ViewBase;
165
+ }(React.Component));
166
+ export default ViewBase;
@@ -1,13 +1,19 @@
1
- import React from 'react';
2
- import { ITaskRunner } from '@singularsystems/neo-core';
3
- import { IViewModel } from './IViewModel';
4
- interface IComponentProps {
5
- taskRunner?: ITaskRunner;
6
- }
7
- export default class ViewComponentBase<TProps extends IComponentProps, TViewModel extends IViewModel> extends React.Component<TProps> {
8
- constructor(props: TProps, viewModelType: new () => TViewModel);
9
- viewModel: TViewModel;
10
- componentDidMount(): void;
11
- componentWillUnmount(): void;
12
- }
13
- export {};
1
+ import React from 'react';
2
+ import { ITaskRunner } from '@singularsystems/neo-core';
3
+ import { IViewModel } from './IViewModel';
4
+ import { valueOrLazy } from './ViewModelBase';
5
+ interface IComponentProps {
6
+ taskRunner?: ITaskRunner;
7
+ }
8
+ export default class ViewComponentBase<TProps extends IComponentProps, TViewModel extends IViewModel> extends React.Component<TProps> {
9
+ /**
10
+ * Creates a view component.
11
+ * @param props Component props.
12
+ * @param viewModel Instance of view model, or view model type, or callback which returns a view model. Taskrunner will be set only if passing in VM type.
13
+ */
14
+ constructor(props: TProps, viewModel: valueOrLazy<TViewModel>);
15
+ viewModel: TViewModel;
16
+ componentDidMount(): void;
17
+ componentWillUnmount(): void;
18
+ }
19
+ export {};
@@ -1,21 +1,24 @@
1
- import { __extends } from "tslib";
2
- import React from 'react';
3
- var ViewComponentBase = /** @class */ (function (_super) {
4
- __extends(ViewComponentBase, _super);
5
- function ViewComponentBase(props, viewModelType) {
6
- var _this = _super.call(this, props) || this;
7
- _this.viewModel = new viewModelType();
8
- if (props.taskRunner) {
9
- _this.viewModel.taskRunner = props.taskRunner;
10
- }
11
- return _this;
12
- }
13
- ViewComponentBase.prototype.componentDidMount = function () {
14
- this.viewModel.initialise();
15
- };
16
- ViewComponentBase.prototype.componentWillUnmount = function () {
17
- this.viewModel.dispose();
18
- };
19
- return ViewComponentBase;
20
- }(React.Component));
21
- export default ViewComponentBase;
1
+ import { __extends } from "tslib";
2
+ import React from 'react';
3
+ import ViewModelBase from './ViewModelBase';
4
+ var ViewComponentBase = /** @class */ (function (_super) {
5
+ __extends(ViewComponentBase, _super);
6
+ /**
7
+ * Creates a view component.
8
+ * @param props Component props.
9
+ * @param viewModel Instance of view model, or view model type, or callback which returns a view model. Taskrunner will be set only if passing in VM type.
10
+ */
11
+ function ViewComponentBase(props, viewModel) {
12
+ var _this = _super.call(this, props) || this;
13
+ _this.viewModel = ViewModelBase.create(viewModel, props.taskRunner);
14
+ return _this;
15
+ }
16
+ ViewComponentBase.prototype.componentDidMount = function () {
17
+ this.viewModel.initialise();
18
+ };
19
+ ViewComponentBase.prototype.componentWillUnmount = function () {
20
+ this.viewModel.dispose();
21
+ };
22
+ return ViewComponentBase;
23
+ }(React.Component));
24
+ export default ViewComponentBase;
@@ -1,56 +1,57 @@
1
- import { ModelBase, Misc, Model, ITaskRunner } from '@singularsystems/neo-core';
2
- import { IViewModel } from './IViewModel';
3
- import { IReactionDisposer } from 'mobx';
4
- import { BindableBase } from '@singularsystems/neo-core/dist/Model/BindableBase';
5
- import { AxiosPromise } from 'axios';
6
- import { WaitForTaskRunnerOptions } from '@singularsystems/neo-core/dist/Components/TaskRunner/TaskRunner';
7
- export declare type valueOrLazy<T> = T | (() => T) | (new () => T);
8
- export default abstract class ViewModelBase extends ModelBase implements IViewModel {
9
- taskRunner: ITaskRunner;
10
- private disposeHelper;
11
- private trackedViewModels;
12
- constructor(taskRunner?: ITaskRunner, disposeHelper?: import("../Services/IDisposeHelper").IDisposeHelper);
13
- initialise(): void;
14
- /**
15
- * Registers a mobx reaction, which will be disposed in the dispose() method when the view is unmounted.
16
- * @param expression Expression to react to.
17
- * @param effect Callback to run when the result of the expression changes.
18
- */
19
- registerReaction<T>(expression: () => T, effect: (value: T) => void): IReactionDisposer;
20
- /**
21
- * Instantiates, and registers a child view model that will be disposed when this view model is disposed.
22
- * The task runner will be passed to the new vm from this one.
23
- * @param viewModel View model type.
24
- */
25
- registerViewModel<TViewModel extends IViewModel>(viewModel: new () => TViewModel, options?: {
26
- initialise: boolean;
27
- }): TViewModel;
28
- /**
29
- * Registers a child view model that will be disposed when this view model is disposed.
30
- */
31
- registerViewModel<TViewModel extends IViewModel>(viewModel: TViewModel): TViewModel;
32
- /**
33
- * Disposes a child view model and sets the property value to null.
34
- * Note: you will need to pass in the VM property like this: (this as MyVM).meta.vmProperty
35
- */
36
- protected disposeViewModel(vmProperty: Model.IPropertyInstance<IViewModel | null>): void;
37
- /**
38
- * Uses the task runner to call an api endpoint. The returned data is deserialised into an instance of the provided model type.
39
- */
40
- waitForModel<T extends BindableBase>(modelType: typeof BindableBase, task: AxiosPromise<Model.PlainTrackedObject<T>>, options?: Partial<WaitForTaskRunnerOptions<Model.PlainTrackedObject<T>>>): Promise<T>;
41
- /**
42
- * Registers the object for disposal when this viewmodel is disposed.
43
- */
44
- autoDispose<T extends Misc.IDisposable>(disposable: T): T;
45
- /**
46
- * Binds a list of functions to the viewmodel instance.
47
- */
48
- protected bindMethods(...fns: Function[]): void;
49
- dispose(): void;
50
- /**
51
- * Creates a view model instance.
52
- * @param viewModel ViewModel instance, callback which returns a ViewModel or ViewModel constructor.
53
- * @param taskRunner TaskRunner to set if a constructor is passed in.
54
- */
55
- static create<TViewModel extends IViewModel>(viewModel: valueOrLazy<TViewModel>, taskRunner?: ITaskRunner): TViewModel;
56
- }
1
+ import { ModelBase, Misc, Model, ITaskRunner } from '@singularsystems/neo-core';
2
+ import { IViewModel } from './IViewModel';
3
+ import { IReactionDisposer } from 'mobx';
4
+ import { BindableBase } from '@singularsystems/neo-core/dist/Model/BindableBase';
5
+ import { AxiosPromise } from 'axios';
6
+ import { WaitForTaskRunnerOptions } from '@singularsystems/neo-core/dist/Components/TaskRunner/TaskRunner';
7
+ export type valueOrLazy<T> = T | (() => T) | (new () => T);
8
+ export default abstract class ViewModelBase extends ModelBase implements IViewModel {
9
+ taskRunner: ITaskRunner;
10
+ private disposeHelper;
11
+ private trackedViewModels;
12
+ constructor(taskRunner?: ITaskRunner, disposeHelper?: import("../Services/IDisposeHelper").IDisposeHelper);
13
+ initialise(): void;
14
+ /**
15
+ * Registers a mobx reaction, which will be disposed in the dispose() method when the view is unmounted.
16
+ * @param expression Expression to react to.
17
+ * @param effect Callback to run when the result of the expression changes.
18
+ */
19
+ registerReaction<T>(expression: () => T, effect: (value: T) => void): IReactionDisposer;
20
+ /**
21
+ * Instantiates, and registers a child view model that will be disposed when this view model is disposed.
22
+ * The task runner will be passed to the new vm from this one.
23
+ * @param viewModel View model type.
24
+ */
25
+ registerViewModel<TViewModel extends IViewModel>(viewModel: new () => TViewModel, options?: {
26
+ initialise: boolean;
27
+ }): TViewModel;
28
+ /**
29
+ * Registers a child view model that will be disposed when this view model is disposed.
30
+ * You must manually pass the current VMs task runner to the new viewmodel instance.
31
+ */
32
+ registerViewModel<TViewModel extends IViewModel>(viewModel: TViewModel): TViewModel;
33
+ /**
34
+ * Disposes a child view model and sets the property value to null.
35
+ * Note: you will need to pass in the VM property like this: (this as MyVM).meta.vmProperty
36
+ */
37
+ protected disposeViewModel(vmProperty: Model.IPropertyInstance<IViewModel | null>): void;
38
+ /**
39
+ * Uses the task runner to call an api endpoint. The returned data is deserialised into an instance of the provided model type.
40
+ */
41
+ waitForModel<T extends BindableBase>(modelType: typeof BindableBase, task: AxiosPromise<Model.PlainTrackedObject<T>>, options?: Partial<WaitForTaskRunnerOptions<Model.PlainTrackedObject<T>>>): Promise<T>;
42
+ /**
43
+ * Registers the object for disposal when this viewmodel is disposed.
44
+ */
45
+ autoDispose<T extends Misc.IDisposable>(disposable: T): T;
46
+ /**
47
+ * Binds a list of functions to the viewmodel instance.
48
+ */
49
+ protected bindMethods(...fns: Function[]): void;
50
+ dispose(): void;
51
+ /**
52
+ * Creates a view model instance.
53
+ * @param viewModel ViewModel instance, callback which returns a ViewModel or ViewModel constructor.
54
+ * @param taskRunner TaskRunner to set if a constructor is passed in.
55
+ */
56
+ static create<TViewModel extends IViewModel>(viewModel: valueOrLazy<TViewModel>, taskRunner?: ITaskRunner): TViewModel;
57
+ }